Keep animated image meshes and Android startup responsive

This commit is contained in:
waozi committed 2026-11-19 02:03:27 -03:00
1 parent a77c82bf0c
commit d2e537cc94
10 files changed
+168 -4

No files matched your search

+4
View File
@@ -2,6 +2,8 @@
## Unreleased
- Normal Android builds start when a previous UI test left its private
test-driver folder behind; only builds with the driver use that folder.
- Animated glTF material primitives skin and upload only their referenced
vertices, preserving the original triangles, expressions and pixels.
@@ -15,6 +17,8 @@
`ZIRAN_NATIVE_CACHE` at the app's `cache/ziran-native` folder unless it is
set, so a portable app's native code loads on later starts instead of
compiling again.
- Smooth image meshes use the ordinary image filter, avoiding stalls when
animated cells stretch a narrow source strip in opposing directions.
- Smooth pictures drawn without a prepared smooth copy, such as tiles cut
from one sheet, use Cairo's good filter again: 0.6.0's best filter reached
past the source rectangle and bled neighbouring tiles into the seams.
+10
View File
@@ -992,6 +992,11 @@ image-dimensions-host-test: project-toolchain
test: image-dimensions-host-test
.PHONY: android-runtime-test pixmap-camera-test android-image-services-test pixmap-typeface-test android-codec-artifact-test android-typefaces-link-test android-typefaces-device-test android-pictures-link-test android-pictures-device-test
.PHONY: android-process-test
android-process-test: project-toolchain
@sh tests/android_process_test.sh
test: android-process-test
android-runtime-test: project-toolchain
@sh tests/ziran_android_runtime_test.sh
pixmap-camera-test: project-toolchain
@@ -1018,6 +1023,11 @@ mirrored-image-test: project-toolchain
@sh tests/pixmap_mirrored_image_test.sh
test: mirrored-image-test
.PHONY: cairo-mesh-test
cairo-mesh-test: project-toolchain
@sh tests/ziran_cairo_mesh_test.sh
test: cairo-mesh-test
.PHONY: scene-skin-test scene-gltf-test scene-gltf-gpu-test watercolor-test practice-material-gpu-test image-pixels-resolver-test
scene-skin-test: project-toolchain
@ZIRAN_BIN="$(ZIRAN_BIN)" sh tests/scene_skin_test.sh
+2
View File
@@ -1350,6 +1350,8 @@ variable in the environment of `kryon build`. The program then obeys the
directory the same variable names when it runs. A program built without the
driver and started with the variable set stops at once and says how to build
it, so a test fails with the reason instead of waiting for a reply.
On Android, the private `kryon-test-driver` folder activates a compiled test
driver. Normal builds ignore a folder left by an earlier UI test.
A test captures what the app draws with `DriverCapture(driver, path)` (the
`capture path=` command): the desktop host writes its next finished frame to
+30 -1
View File
@@ -127,4 +127,33 @@ Each change needs a pixel-identical test and a benchmark.
- The main `.git/index` dates from 03:37 and doesn't match HEAD, so plain
`git status` and `git diff HEAD` show hundreds of false changes. Inspect and
commit through a private index: `GIT_INDEX_FILE=<file> git read-tree HEAD`.
- `origin` is Gitea. Run `build-queue -- make push-check` before pushing.
- `origin` is Gitea. Run `make push-check` through managed `desktop_run`
before pushing. Scope `GIT_INDEX_FILE` to individual Git commands; exporting
it through a build corrupts package-cache validation by supplying another
repository's index to its Git subprocesses.
## Cairo image-mesh freeze, 2026-11-19
The native Lumi integration exposed a separate Sun Salutation freeze. With
narration disabled, the main thread consumed a core inside Cairo's mask paint.
A breakpoint on `CairoMeshTriangle` captured the live figure's tiny 6×1 mask,
with a source strip only 0.045455 pixels tall stretched into opposing screen
directions. The ordinary image sampler already uses `CAIRO_FILTER_GOOD`, but
the mesh sampler still used `CAIRO_FILTER_BEST`.
For 32 copies of the captured triangle, the direct Cairo reproduction took
0.564553 seconds with BEST and 0.001037 seconds with GOOD. This microbenchmark
does not establish the requested fivefold full-app improvement on Moto.
The mesh sampler now uses GOOD when smooth, retaining nearest sampling,
geometry, clipping and tinting. The regression renders 128 frames of the real
cell and checks a tinted translucent pixel. It timed out against the old
sampler (`d3073f10075a94918bc2d4c9d65863c33b92`) and passed from source and saved
IR after the change (`04e3d49f80a62ac52ba72e8c8e44b5451d05`). Existing image
sampling and mirrored-image pixel tests passed
(`5f23d159649c5111e921eff237dde4de1d16`). `make push-check` passed
(`dbaa0855c67b29c36b8672afd256e205cd7f`). The actual rebuilt Breeze Lumi UI
test also passed its Sun Salutation start, ten frames and explicit exit, then
the complete chat/tool/preview flow (`a524fcc262205a5723288d62ff81b077cbe6`,
Lumi stage 0). Moto's new full-app measurements remain pending its separate
ARM32 Main native-image loading failure.
+3 -1
View File
@@ -12,7 +12,9 @@ AndroidMakeDirectory :: (path: *u8, mode: u32) -> s32 #foreign android_libc "mkd
AndroidProcessPrepare :: () {
AndroidTemporaryPrepare()
AndroidNativeCachePrepare()
AndroidTestDriverPrepare()
#if #defined(KRYON_TEST_DRIVER) {
AndroidTestDriverPrepare()
}
}
// Ziran keeps the native code it compiles for portable apps in a disk cache
+3 -1
View File
@@ -1436,7 +1436,9 @@ CairoMeshTriangle :: (image: *void, a: Vector2, a_source: Vector2,
print("Kryon: skipped image: invalid or unavailable picture\n")
return
}
PatternFilter(pattern, ifx CurrentPaintSmooth() then CAIRO_FILTER_BEST else CAIRO_FILTER_NEAREST)
// Use the same smooth filter as an ordinary image. BEST makes a tiny
// source strip stretched in opposing directions costly per triangle.
PatternFilter(pattern, ifx CurrentPaintSmooth() then CAIRO_FILTER_GOOD else CAIRO_FILTER_NEAREST)
PaintImagePattern(pattern, tint)
PatternDestroy(pattern)
Restore(paint)
+46
View File
@@ -0,0 +1,46 @@
#import "android_jni"
#import "android_native"
#import "android_native_test_host"
#import "android_process"
#import "std/byte_text_linux"
#import "std/c_string"
test_libc :: #system_library "c";
GetEnvironment :: (name: *u8) -> *u8 #foreign test_libc "getenv";
Environment :: (name: string) -> *u8 {
key: [64]u8
if !CopyCString(name, key[:]) {
return null
}
return GetEnvironment(*key[0])
}
#program_export
main :: () -> s32 {
private_files := Environment("KRYON_PROCESS_PRIVATE_FILES")
folder := TextFromCString(private_files)
if folder == "" {
return 1
}
activity: NativeActivity
activity.internal_data_path = private_files
app: NativeAndroidApp
app.activity = *activity
AndroidNativeStart(*app)
defer AndroidNativeClose()
AndroidProcessPrepare()
if TextFromCString(Environment("TMPDIR")) != TextFromCString(Environment("KRYON_PROCESS_EXPECT_TMPDIR")) {
return 2
}
expected := TextFromCString(Environment("KRYON_PROCESS_EXPECT_DRIVER"))
if TextFromCString(Environment("KRYON_TEST_DRIVER")) != expected {
return 3
}
// Repeated host preparation preserves the same process setup.
AndroidProcessPrepare()
if TextFromCString(Environment("KRYON_TEST_DRIVER")) != expected {
return 4
}
return 0
}
+45
View File
@@ -0,0 +1,45 @@
#!/bin/sh
set -eu
repo=$(CDPATH= cd -- "$(dirname -- "$0")/.." && pwd)
. "$repo/tests/toolchain.sh"
unset DISPLAY WAYLAND_DISPLAY XAUTHORITY DBUS_SESSION_BUS_ADDRESS SESSION_MANAGER
export HARMONY_DESKTOP_RECOVERY=0 YUE_DESKTOP_RECOVERY=0
output_root="$repo/build/scratch/android-process"
mkdir -p "$output_root/files-absent" "$output_root/files-present/kryon-test-driver"
test ! -e "$output_root/files-absent/kryon-test-driver"
for mode in normal driver; do
defines="--define ANDROID_BUILD --define __x86_64__"
if [ "$mode" = driver ]; then
defines="$defines --define KRYON_TEST_DRIVER"
fi
for form in source saved; do
input="$repo/tests/android_process_behavior.zi"
if [ "$form" = saved ]; then
# shellcheck disable=SC2086
"$ziran" ir $kryon_project_args $defines --root "$repo/tests" \
-o "$output_root/$mode/ir" "$input"
input="$output_root/$mode/ir/android_process_behavior.zir"
fi
output="$output_root/$mode/$form"
# shellcheck disable=SC2086
"$ziran" build $kryon_project_args $defines --target=c --root "$repo/tests" \
--prune-stale -o "$output" "$input"
includes=$(find "$output" -type d -printf ' -iquote %p')
# shellcheck disable=SC2046,SC2086
"${CC:-cc}" -std=c11 -O2 -ffunction-sections -fdata-sections \
-I"$ziran_root/include" $includes $(find "$output" -name '*.c') \
"$ziran_root/build/libziran.a" -Wl,--gc-sections -lm -lpthread -ldl \
-o "$output/test"
for folder in absent present; do
expected_driver=""
if [ "$mode" = driver ] && [ "$folder" = present ]; then
expected_driver="$output_root/files-$folder/kryon-test-driver"
fi
env -u KRYON_TEST_DRIVER -u TMPDIR \
KRYON_PROCESS_PRIVATE_FILES="$output_root/files-$folder" \
KRYON_PROCESS_EXPECT_TMPDIR="$output_root/files-$folder/tmp" \
KRYON_PROCESS_EXPECT_DRIVER="$expected_driver" "$output/test"
done
done
done
echo 'Android process: normal/driver builds with absent/leftover folders passed (source and saved IR)'
+23
View File
@@ -101,6 +101,29 @@ main :: (argc: s32, argv: **u8) -> s32 {
Raster.BeginRasterFrame()
Raster.RasterImage(path,0,.{0.0,0.0,2.0,2.0},full,full,.{0.0,0.0},0.0,0.0,.{255,255,255,255})
if !Raster.FinishRasterFrame() || !Is(48,48,white) { return 16 }
// A narrow source strip can be magnified in two almost opposing
// directions. This is a real animated-figure cell: Cairo's best filter
// spends milliseconds per triangle, freezing a frame containing many.
sampling_text: Vec(u8)
BuilderPrint(*sampling_text, "%/sampling.png", root)
sampling_path := BuilderFinish(sampling_text)
if Raster.ImageWidth(sampling_path) != 6 { return 17 }
points[0] = .{42.037, 58.228}
points[1] = .{46.695, 52.240}
points[2] = .{41.758, 46.400}
points[3] = .{46.416, 40.412}
emitting_smooth = true
for frame: cast(s32)0..127 {
Raster.BeginRasterFrame()
Raster.RasterImageMesh(sampling_path, 0, .{2.0, 0.454545, 2.0, 0.045455},
points[:], 2, 2, full, .{247, 196, 163, 255})
if !Raster.FinishRasterFrame() { return 18 }
}
emitting_smooth = false
// The optimization must still draw the tinted, translucent cell.
color := Pixel(44, 49)
if color == background || ((color >> 16) & cast(u32)255) <= ((color >> 8) & cast(u32)255) ||
((color >> 8) & cast(u32)255) <= (color & cast(u32)255) { return 19 }
print("Cairo draws meshes and polygon-clipped images without leaking clips\n")
return 0
}
+2 -1
View File
@@ -14,6 +14,7 @@ import sys
image = Image.new('RGBA', (2, 2))
image.putdata([(255, 0, 0, 255), (0, 255, 0, 255), (0, 0, 255, 255), (255, 255, 255, 255)])
image.save(Path(sys.argv[1]) / 'mesh.png')
Image.new('RGBA', (6, 1), (255, 255, 255, 128)).save(Path(sys.argv[1]) / 'sampling.png')
PY
libs="$(pkg-config --libs cairo freetype2 pangocairo fontconfig glib-2.0) -ldl -lm -lpthread"
source="$repo/tests/cairo_mesh_test.zi"
@@ -29,6 +30,6 @@ for form in source saved; do
printf '#include "cairo_mesh_test.%s"\nint main(int argc, char **argv) { return cairo_mesh_test_main(argc, (uint8_t **)argv); }\n' "$header" > "$output/entry.$suffix"
"$compiler" -std="$standard" -O2 -I"$ziran_root/include" -I"$output" \
"$output"/*."$suffix" $libs -o "$output/test"
"$output/test" "$work/fixtures"
timeout 3s "$output/test" "$work/fixtures"
done
done