@native-sdk/cli 0.9.1 → 0.9.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/app.zig +26 -9
- package/build.zig +124 -1
- package/package.json +9 -9
- package/packages/core/package-lock.json +2 -2
- package/packages/core/package.json +1 -1
- package/packages/core/sdk/core.ts +3 -1
- package/packages/core/sdk/events.d.ts +7 -0
- package/packages/core/sdk/events.ts +26 -5
- package/packages/core/sdk/text.d.ts +4 -0
- package/packages/core/sdk/text.ts +51 -0
- package/packages/core/src/checker.ts +58 -1
- package/packages/core/src/contract.ts +5 -4
- package/packages/core/src/devhost_journal.mjs +2 -2
- package/packages/core/src/diagnostics.ts +2 -2
- package/packages/core/src/service_contract.ts +10 -0
- package/packages/core/src/typed_ast.ts +9 -7
- package/packages/core/src/types.ts +28 -8
- package/skill-data/automation/SKILL.md +4 -3
- package/skill-data/native-ui/SKILL.md +10 -8
- package/skill-data/ts-core/SKILL.md +8 -5
- package/src/app_runner/root.zig +301 -12
- package/src/app_runner/ts_core_main.zig +6 -4
- package/src/app_runner/window_placement.zig +63 -0
- package/src/automation/protocol.zig +5 -1
- package/src/automation/snapshot.zig +119 -0
- package/src/embed/app_exports.zig +2 -1
- package/src/embed/conversions.zig +1 -0
- package/src/embed/host.zig +10 -3
- package/src/embed/root.zig +1 -0
- package/src/embed/tests.zig +13 -1
- package/src/embed/types.zig +2 -0
- package/src/embed/ui_host.zig +26 -2
- package/src/platform/android/NativeSdkActivity.java +49 -4
- package/src/platform/android/android_host.c +3 -3
- package/src/platform/android/native_sdk_app.h +1 -1
- package/src/platform/ios/apple_image_fit.h +38 -0
- package/src/platform/ios/files.zig +1 -0
- package/src/platform/ios/native_sdk_app.h +1 -1
- package/src/platform/ios/uikit_host.m +28 -5
- package/src/platform/linux/cef_host.cpp +10 -2
- package/src/platform/linux/gtk_host.c +43 -10
- package/src/platform/linux/gtk_host.h +3 -3
- package/src/platform/linux/root.zig +22 -7
- package/src/platform/macos/appkit_host.h +7 -4
- package/src/platform/macos/appkit_host.m +271 -52
- package/src/platform/macos/cef_host.mm +132 -34
- package/src/platform/macos/image_fit_test.m +44 -0
- package/src/platform/macos/root.zig +222 -14
- package/src/platform/null_platform.zig +17 -3
- package/src/platform/null_platform_tests.zig +58 -4
- package/src/platform/root.zig +2 -0
- package/src/platform/types.zig +69 -19
- package/src/platform/windows/root.zig +22 -7
- package/src/platform/windows/webview2_host.cpp +31 -6
- package/src/primitives/app_manifest/root.zig +3 -0
- package/src/primitives/app_manifest/tests.zig +24 -0
- package/src/primitives/app_manifest/types.zig +13 -0
- package/src/primitives/app_manifest/validation.zig +24 -0
- package/src/primitives/canvas/a11y_audit.zig +9 -7
- package/src/primitives/canvas/a11y_audit_tests.zig +24 -0
- package/src/primitives/canvas/events.zig +129 -1
- package/src/primitives/canvas/layout_audit.zig +6 -6
- package/src/primitives/canvas/markdown.zig +4 -0
- package/src/primitives/canvas/markdown_tests.zig +1 -0
- package/src/primitives/canvas/png.zig +138 -0
- package/src/primitives/canvas/root.zig +14 -2
- package/src/primitives/canvas/text_interaction.zig +23 -0
- package/src/primitives/canvas/text_span_tests.zig +5 -3
- package/src/primitives/canvas/text_spans.zig +2 -0
- package/src/primitives/canvas/text_tests.zig +65 -0
- package/src/primitives/canvas/ui.zig +66 -10
- package/src/primitives/canvas/ui_markup.zig +40 -13
- package/src/primitives/canvas/ui_markup_binary.zig +8 -6
- package/src/primitives/canvas/ui_markup_binary_tests.zig +14 -4
- package/src/primitives/canvas/ui_markup_compiled.zig +5 -1
- package/src/primitives/canvas/ui_markup_compiled_tests.zig +55 -0
- package/src/primitives/canvas/ui_markup_reflect.zig +6 -5
- package/src/primitives/canvas/ui_markup_tests.zig +11 -2
- package/src/primitives/canvas/ui_markup_view.zig +8 -2
- package/src/primitives/canvas/ui_markup_view_tests.zig +67 -6
- package/src/primitives/canvas/ui_schema.zig +17 -13
- package/src/primitives/canvas/ui_tests.zig +84 -0
- package/src/primitives/canvas/widget_access.zig +3 -3
- package/src/primitives/canvas/widget_anchored_tests.zig +106 -0
- package/src/primitives/canvas/widget_builtin_tests.zig +593 -32
- package/src/primitives/canvas/widget_invalidation.zig +33 -6
- package/src/primitives/canvas/widget_layout.zig +333 -126
- package/src/primitives/canvas/widget_layout_tests.zig +169 -0
- package/src/primitives/canvas/widget_metrics.zig +7 -8
- package/src/primitives/canvas/widget_render.zig +76 -44
- package/src/primitives/canvas/widget_render_controls.zig +110 -32
- package/src/primitives/canvas/widget_render_style.zig +58 -18
- package/src/primitives/canvas/widget_render_surfaces.zig +45 -14
- package/src/primitives/canvas/widget_routing.zig +40 -34
- package/src/primitives/canvas/widget_runtime.zig +11 -2
- package/src/primitives/canvas/widget_runtime_tests.zig +10 -14
- package/src/primitives/canvas/widget_semantics.zig +8 -3
- package/src/primitives/canvas/widget_semantics_tests.zig +6 -2
- package/src/primitives/canvas/widget_tree.zig +99 -5
- package/src/primitives/canvas/widgets.zig +20 -7
- package/src/root.zig +3 -0
- package/src/runtime/api.zig +6 -0
- package/src/runtime/automation_snapshot.zig +4 -0
- package/src/runtime/automation_widget_dispatch.zig +48 -6
- package/src/runtime/builtin_bridge.zig +5 -2
- package/src/runtime/canvas_frame_packet_tests.zig +22 -13
- package/src/runtime/canvas_image_tests.zig +146 -2
- package/src/runtime/canvas_images.zig +35 -16
- package/src/runtime/canvas_limits.zig +13 -3
- package/src/runtime/canvas_widget_accessibility_tests.zig +279 -4
- package/src/runtime/canvas_widget_anchored_tests.zig +54 -0
- package/src/runtime/canvas_widget_control_tests.zig +33 -1
- package/src/runtime/canvas_widget_events.zig +151 -26
- package/src/runtime/canvas_widget_floating_tests.zig +48 -0
- package/src/runtime/canvas_widget_runtime.zig +322 -102
- package/src/runtime/canvas_widget_scroll_driver_tests.zig +34 -0
- package/src/runtime/canvas_widget_scroll_drivers.zig +12 -10
- package/src/runtime/canvas_widget_scroll_tests.zig +193 -2
- package/src/runtime/canvas_widget_semantics_tests.zig +337 -3
- package/src/runtime/canvas_widget_split_tree_tests.zig +55 -0
- package/src/runtime/canvas_widget_state.zig +33 -7
- package/src/runtime/canvas_widget_text_tests.zig +124 -0
- package/src/runtime/core.zig +16 -0
- package/src/runtime/effects.zig +14 -14
- package/src/runtime/effects_image_tests.zig +91 -0
- package/src/runtime/gpu_surface_events.zig +25 -2
- package/src/runtime/native_command_event_tests.zig +29 -0
- package/src/runtime/root.zig +2 -0
- package/src/runtime/session_journal.zig +21 -2
- package/src/runtime/session_replay.zig +13 -8
- package/src/runtime/session_tests.zig +111 -4
- package/src/runtime/shell_layout_tests.zig +12 -0
- package/src/runtime/ts_core_host_tests.zig +47 -0
- package/src/runtime/ts_ui_app.zig +164 -1
- package/src/runtime/ui_app.zig +100 -21
- package/src/runtime/ui_app_tests.zig +351 -32
- package/src/runtime/ui_app_window_tests.zig +13 -1
- package/src/runtime/view.zig +3 -0
- package/src/runtime/view_widget_control.zig +18 -0
- package/src/runtime/view_widget_scroll.zig +112 -18
- package/src/runtime/view_widget_text.zig +1 -1
- package/src/runtime/view_widget_tree.zig +110 -13
- package/src/runtime/widget_bridge.zig +2 -0
- package/src/runtime/window_command_bridge_tests.zig +86 -0
- package/src/runtime/window_storage.zig +16 -1
- package/src/runtime/window_views.zig +1 -0
- package/src/tooling/ios.zig +3 -0
- package/src/tooling/manifest.zig +90 -2
- package/src/tooling/package.zig +67 -2
- package/src/tooling/raw_manifest.zig +10 -0
- package/src/tooling/templates.zig +128 -18
- package/src/tooling/verbs.zig +1 -0
- package/src/tooling/web_engine.zig +1 -1
- package/tools/corewire/emit.zig +31 -12
- package/tools/corewire/emit_facade.zig +57 -2
- package/tools/corewire/shim_rt.zig +20 -0
|
@@ -725,7 +725,9 @@ test "runtime pixel fallback honors presentation scale without invalidating reta
|
|
|
725
725
|
try std.testing.expect(!presented_frame.canvas_frame_requires_render);
|
|
726
726
|
}
|
|
727
727
|
|
|
728
|
-
test "runtime keeps
|
|
728
|
+
test "runtime keeps raised-budget registered images on the packet path" {
|
|
729
|
+
comptime std.debug.assert(platform.max_gpu_surface_image_pixel_bytes == runtime_module.max_registered_canvas_image_pixel_bytes_ceiling);
|
|
730
|
+
|
|
729
731
|
const TestApp = struct {
|
|
730
732
|
fn app(self: *@This()) App {
|
|
731
733
|
return .{ .context = self, .name = "gpu-canvas-image-packet", .source = platform.WebViewSource.html("<h1>Hello</h1>") };
|
|
@@ -735,6 +737,13 @@ test "runtime keeps frames with registered images on the packet path" {
|
|
|
735
737
|
const harness = try TestHarness().create(std.testing.allocator, .{});
|
|
736
738
|
defer harness.destroy(std.testing.allocator);
|
|
737
739
|
harness.null_platform.gpu_surfaces = true;
|
|
740
|
+
Runtime.initAt(&harness.runtime, .{
|
|
741
|
+
.platform = harness.null_platform.platform(),
|
|
742
|
+
.trace_sink = harness.trace_sink.sink(),
|
|
743
|
+
.max_image_pixel_bytes = platform.max_gpu_surface_image_pixel_bytes,
|
|
744
|
+
.environ = std.testing.environ,
|
|
745
|
+
});
|
|
746
|
+
harness.runtime.dispatch_error_policy = .propagate;
|
|
738
747
|
var app_state: TestApp = .{};
|
|
739
748
|
try harness.start(app_state.app());
|
|
740
749
|
|
|
@@ -745,14 +754,14 @@ test "runtime keeps frames with registered images on the packet path" {
|
|
|
745
754
|
.frame = geometry.RectF.init(0, 0, 256, 160),
|
|
746
755
|
});
|
|
747
756
|
|
|
748
|
-
// A
|
|
749
|
-
//
|
|
750
|
-
//
|
|
751
|
-
//
|
|
752
|
-
|
|
753
|
-
const
|
|
754
|
-
const
|
|
755
|
-
const avatar = try std.testing.allocator.alloc(u8,
|
|
757
|
+
// A 1024x512 image is 2 MiB: above the default registry tier and the
|
|
758
|
+
// upload seam's former fixed 1 MiB bound, but inside this runtime's
|
|
759
|
+
// declared budget. As an id + fingerprint reference over the binary
|
|
760
|
+
// side-channel it must upload and keep the frame on the packet path.
|
|
761
|
+
const image_width: usize = 1024;
|
|
762
|
+
const image_height: usize = 512;
|
|
763
|
+
const image_bytes = image_width * image_height * 4;
|
|
764
|
+
const avatar = try std.testing.allocator.alloc(u8, image_bytes);
|
|
756
765
|
defer std.testing.allocator.free(avatar);
|
|
757
766
|
var offset: usize = 0;
|
|
758
767
|
while (offset < avatar.len) : (offset += 4) {
|
|
@@ -761,7 +770,7 @@ test "runtime keeps frames with registered images on the packet path" {
|
|
|
761
770
|
avatar[offset + 2] = 32;
|
|
762
771
|
avatar[offset + 3] = 255;
|
|
763
772
|
}
|
|
764
|
-
try harness.runtime.registerCanvasImage(42,
|
|
773
|
+
try harness.runtime.registerCanvasImage(42, image_width, image_height, avatar);
|
|
765
774
|
|
|
766
775
|
const commands = [_]canvas.CanvasCommand{
|
|
767
776
|
.{ .fill_rect = .{
|
|
@@ -807,9 +816,9 @@ test "runtime keeps frames with registered images on the packet path" {
|
|
|
807
816
|
// The pixel bytes rode the binary side-channel instead.
|
|
808
817
|
try std.testing.expectEqual(@as(usize, 1), harness.null_platform.gpu_surface_image_upload_count);
|
|
809
818
|
try std.testing.expectEqual(@as(u64, 42), harness.null_platform.gpu_surface_image_upload_id);
|
|
810
|
-
try std.testing.expectEqual(
|
|
811
|
-
try std.testing.expectEqual(
|
|
812
|
-
try std.testing.expectEqual(
|
|
819
|
+
try std.testing.expectEqual(image_width, harness.null_platform.gpu_surface_image_upload_width);
|
|
820
|
+
try std.testing.expectEqual(image_height, harness.null_platform.gpu_surface_image_upload_height);
|
|
821
|
+
try std.testing.expectEqual(image_bytes, harness.null_platform.gpu_surface_image_upload_byte_len);
|
|
813
822
|
try std.testing.expectEqualDeep([4]u8{ 200, 64, 32, 255 }, harness.null_platform.gpuSurfaceImage(42).?.sample_rgba);
|
|
814
823
|
|
|
815
824
|
// A clean second frame retains the image (no re-upload) and skips.
|
|
@@ -109,8 +109,8 @@ test "registered images draw through the reference renderer screenshot" {
|
|
|
109
109
|
// Raw RGBA fixture: 2x2 quadrant colors drawn with nearest sampling,
|
|
110
110
|
// so each destination quadrant is one exact color.
|
|
111
111
|
const fixture = [_]u8{
|
|
112
|
-
255, 0,
|
|
113
|
-
0, 0,
|
|
112
|
+
255, 0, 0, 255, 0, 255, 0, 255,
|
|
113
|
+
0, 0, 255, 255, 255, 255, 0, 255,
|
|
114
114
|
};
|
|
115
115
|
try harness.runtime.registerCanvasImage(42, 2, 2, &fixture);
|
|
116
116
|
|
|
@@ -207,6 +207,128 @@ test "registerCanvasImageBytes decodes through the platform seam" {
|
|
|
207
207
|
try std.testing.expectError(error.InvalidImageId, harness.runtime.registerCanvasImageBytes(0, encoded));
|
|
208
208
|
}
|
|
209
209
|
|
|
210
|
+
test "direct encoded image registration enforces the source bound before decode" {
|
|
211
|
+
const harness = try startedGpuHarness(std.testing.allocator);
|
|
212
|
+
defer harness.destroy(std.testing.allocator);
|
|
213
|
+
var app_state: RegistryApp = .{};
|
|
214
|
+
try harness.start(app_state.app());
|
|
215
|
+
harness.null_platform.image_decode = true;
|
|
216
|
+
|
|
217
|
+
const oversized = try std.testing.allocator.alloc(u8, effects_mod.max_effect_image_source_bytes + 1);
|
|
218
|
+
defer std.testing.allocator.free(oversized);
|
|
219
|
+
@memset(oversized, 0x5A);
|
|
220
|
+
|
|
221
|
+
try std.testing.expectError(error.ImageTooLarge, harness.runtime.registerCanvasImageBytes(9, oversized));
|
|
222
|
+
try std.testing.expectEqual(@as(usize, 0), harness.null_platform.image_decode_count);
|
|
223
|
+
try std.testing.expectEqual(@as(usize, 0), harness.runtime.registeredCanvasImageCount());
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
fn encodedPng(allocator: std.mem.Allocator, width: usize, height: usize, pixels: []const u8) ![]u8 {
|
|
227
|
+
const capacity = try canvas.png.encodedRgba8ByteLen(width, height);
|
|
228
|
+
const encoded = try allocator.alloc(u8, capacity);
|
|
229
|
+
errdefer allocator.free(encoded);
|
|
230
|
+
var writer = std.Io.Writer.fixed(encoded);
|
|
231
|
+
try canvas.png.writeRgba8(&writer, width, height, pixels);
|
|
232
|
+
return encoded[0..writer.buffered().len];
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
test "null image codec fits oversized photos deterministically and preserves in-budget geometry" {
|
|
236
|
+
const harness = try startedGpuHarness(std.testing.allocator);
|
|
237
|
+
defer harness.destroy(std.testing.allocator);
|
|
238
|
+
var app_state: RegistryApp = .{};
|
|
239
|
+
try harness.start(app_state.app());
|
|
240
|
+
harness.null_platform.image_decode = true;
|
|
241
|
+
|
|
242
|
+
// No-op below the budget.
|
|
243
|
+
const tiny_pixels = [_]u8{
|
|
244
|
+
1, 2, 3, 255, 4, 5, 6, 255, 7, 8, 9, 255,
|
|
245
|
+
10, 11, 12, 255, 13, 14, 15, 255, 16, 17, 18, 255,
|
|
246
|
+
};
|
|
247
|
+
const tiny_encoded = try encodedPng(std.testing.allocator, 3, 2, &tiny_pixels);
|
|
248
|
+
defer std.testing.allocator.free(tiny_encoded);
|
|
249
|
+
const tiny = try harness.runtime.registerCanvasImageBytes(20, tiny_encoded);
|
|
250
|
+
try std.testing.expectEqual(@as(usize, 3), tiny.width);
|
|
251
|
+
try std.testing.expectEqual(@as(usize, 2), tiny.height);
|
|
252
|
+
try std.testing.expectEqualSlices(u8, &tiny_pixels, registeredPixelsById(&harness.runtime, 20).?);
|
|
253
|
+
|
|
254
|
+
// A wide exact-boundary image remains 1024x256; this proves the cap is
|
|
255
|
+
// pixel count, not a 512x512 box.
|
|
256
|
+
const wide_pixels = try std.testing.allocator.alloc(u8, 1024 * 256 * 4);
|
|
257
|
+
defer std.testing.allocator.free(wide_pixels);
|
|
258
|
+
@memset(wide_pixels, 0x5A);
|
|
259
|
+
const wide_encoded = try encodedPng(std.testing.allocator, 1024, 256, wide_pixels);
|
|
260
|
+
defer std.testing.allocator.free(wide_encoded);
|
|
261
|
+
const wide = try harness.runtime.registerCanvasImageBytes(21, wide_encoded);
|
|
262
|
+
try std.testing.expectEqual(@as(usize, 1024), wide.width);
|
|
263
|
+
try std.testing.expectEqual(@as(usize, 256), wide.height);
|
|
264
|
+
|
|
265
|
+
// 1024x512 is over budget and fits to the exact null-codec target.
|
|
266
|
+
// Uniform source pixels make the integer box-average golden exact.
|
|
267
|
+
const photo_pixels = try std.testing.allocator.alloc(u8, 1024 * 512 * 4);
|
|
268
|
+
defer std.testing.allocator.free(photo_pixels);
|
|
269
|
+
var index: usize = 0;
|
|
270
|
+
while (index < photo_pixels.len) : (index += 4) {
|
|
271
|
+
photo_pixels[index..][0..4].* = .{ 17, 91, 203, 247 };
|
|
272
|
+
}
|
|
273
|
+
const photo_encoded = try encodedPng(std.testing.allocator, 1024, 512, photo_pixels);
|
|
274
|
+
defer std.testing.allocator.free(photo_encoded);
|
|
275
|
+
const first = try harness.runtime.registerCanvasImageBytes(22, photo_encoded);
|
|
276
|
+
try std.testing.expectEqual(@as(usize, 724), first.width);
|
|
277
|
+
try std.testing.expectEqual(@as(usize, 362), first.height);
|
|
278
|
+
try std.testing.expect(first.width * first.height * 4 <= harness.runtime.max_image_pixel_bytes);
|
|
279
|
+
const first_pixels = registeredPixelsById(&harness.runtime, 22).?;
|
|
280
|
+
const fingerprint = std.hash.Wyhash.hash(0, first_pixels);
|
|
281
|
+
var probe: usize = 0;
|
|
282
|
+
while (probe < @min(first_pixels.len, 4096)) : (probe += 4) {
|
|
283
|
+
try std.testing.expectEqualSlices(u8, &[_]u8{ 17, 91, 203, 247 }, first_pixels[probe..][0..4]);
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
const second = try harness.runtime.registerCanvasImageBytes(23, photo_encoded);
|
|
287
|
+
try std.testing.expectEqual(first.width, second.width);
|
|
288
|
+
try std.testing.expectEqual(first.height, second.height);
|
|
289
|
+
try std.testing.expectEqual(fingerprint, std.hash.Wyhash.hash(0, registeredPixelsById(&harness.runtime, 23).?));
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
test "null image codec uses exact integer area weights for fractional boxes" {
|
|
293
|
+
const pixels = [_]u8{
|
|
294
|
+
0, 0, 0, 255, 60, 60, 60, 255, 120, 120, 120, 255,
|
|
295
|
+
};
|
|
296
|
+
const encoded = try encodedPng(std.testing.allocator, 3, 1, &pixels);
|
|
297
|
+
defer std.testing.allocator.free(encoded);
|
|
298
|
+
var output: [16]u8 = undefined;
|
|
299
|
+
const decoded = try canvas.png.decodeRgba8Fitted(encoded, &output, 2, platform.max_decoded_image_dimension);
|
|
300
|
+
try std.testing.expectEqual(@as(usize, 2), decoded.width);
|
|
301
|
+
try std.testing.expectEqual(@as(usize, 1), decoded.height);
|
|
302
|
+
try std.testing.expectEqualSlices(u8, &[_]u8{
|
|
303
|
+
20, 20, 20, 255,
|
|
304
|
+
100, 100, 100, 255,
|
|
305
|
+
}, decoded.rgba8);
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
test "null image codec fits a source panorama past the decoded-axis ceiling" {
|
|
309
|
+
const source_width = platform.max_decoded_image_dimension + 1;
|
|
310
|
+
const pixels = try std.testing.allocator.alloc(u8, source_width * 4);
|
|
311
|
+
defer std.testing.allocator.free(pixels);
|
|
312
|
+
var offset: usize = 0;
|
|
313
|
+
while (offset < pixels.len) : (offset += 4) pixels[offset..][0..4].* = .{ 41, 83, 127, 255 };
|
|
314
|
+
|
|
315
|
+
const encoded = try encodedPng(std.testing.allocator, source_width, 1, pixels);
|
|
316
|
+
defer std.testing.allocator.free(encoded);
|
|
317
|
+
const output = try std.testing.allocator.alloc(u8, platform.max_decoded_image_dimension * 4);
|
|
318
|
+
defer std.testing.allocator.free(output);
|
|
319
|
+
|
|
320
|
+
const decoded = try canvas.png.decodeRgba8Fitted(
|
|
321
|
+
encoded,
|
|
322
|
+
output,
|
|
323
|
+
platform.max_decoded_image_dimension,
|
|
324
|
+
platform.max_decoded_image_dimension,
|
|
325
|
+
);
|
|
326
|
+
try std.testing.expectEqual(platform.max_decoded_image_dimension, decoded.width);
|
|
327
|
+
try std.testing.expectEqual(@as(usize, 1), decoded.height);
|
|
328
|
+
try std.testing.expectEqualSlices(u8, &[_]u8{ 41, 83, 127, 255 }, decoded.rgba8[0..4]);
|
|
329
|
+
try std.testing.expectEqualSlices(u8, &[_]u8{ 41, 83, 127, 255 }, decoded.rgba8[decoded.rgba8.len - 4 ..]);
|
|
330
|
+
}
|
|
331
|
+
|
|
210
332
|
test "registerCanvasImageBytes refuses reserved media-surface ids before decoding" {
|
|
211
333
|
const harness = try startedGpuHarness(std.testing.allocator);
|
|
212
334
|
defer harness.destroy(std.testing.allocator);
|
|
@@ -313,6 +435,28 @@ test "a fresh runtime allocates zero registered-image bytes until the first regi
|
|
|
313
435
|
try std.testing.expectEqual(@as(usize, 2), counting.allocations);
|
|
314
436
|
}
|
|
315
437
|
|
|
438
|
+
test "raised registered-image budget stays lazy and sizes each used slot" {
|
|
439
|
+
var counting = std.testing.FailingAllocator.init(std.testing.allocator, .{});
|
|
440
|
+
const harness = try startedGpuHarness(std.testing.allocator);
|
|
441
|
+
defer harness.destroy(std.testing.allocator);
|
|
442
|
+
core.Runtime.initAt(&harness.runtime, .{
|
|
443
|
+
.platform = harness.null_platform.platform(),
|
|
444
|
+
.trace_sink = harness.trace_sink.sink(),
|
|
445
|
+
.allocator = counting.allocator(),
|
|
446
|
+
.max_image_pixel_bytes = canvas_limits.max_registered_canvas_image_pixel_bytes_ceiling,
|
|
447
|
+
.environ = std.testing.environ,
|
|
448
|
+
});
|
|
449
|
+
harness.runtime.dispatch_error_policy = .propagate;
|
|
450
|
+
var app_state: RegistryApp = .{};
|
|
451
|
+
try harness.start(app_state.app());
|
|
452
|
+
try std.testing.expectEqual(@as(usize, 0), counting.allocations);
|
|
453
|
+
|
|
454
|
+
const pixel = [_]u8{ 1, 2, 3, 255 };
|
|
455
|
+
try harness.runtime.registerCanvasImage(1, 1, 1, &pixel);
|
|
456
|
+
try std.testing.expectEqual(@as(usize, 1), counting.allocations);
|
|
457
|
+
try std.testing.expectEqual(canvas_limits.max_registered_canvas_image_pixel_bytes_ceiling, counting.allocated_bytes);
|
|
458
|
+
}
|
|
459
|
+
|
|
316
460
|
test "image slot buffer ownership freezes at init: a mutated options.allocator sees zero activity" {
|
|
317
461
|
// The hazard pinned here: `Runtime.options` is public and mutable,
|
|
318
462
|
// so if the lazy slot allocation and deinit's free both read
|
|
@@ -24,8 +24,9 @@
|
|
|
24
24
|
//! re-upload without any explicit invalidation call.
|
|
25
25
|
//!
|
|
26
26
|
//! Capacities follow `canvas_limits`: `max_registered_canvas_images`
|
|
27
|
-
//! slots of
|
|
28
|
-
//!
|
|
27
|
+
//! slots of the runtime-frozen image budget (the 1 MiB default through
|
|
28
|
+
//! the 8 MiB ceiling). Raw-pixel overflow is `error.ImageTooLarge`;
|
|
29
|
+
//! encoded inputs decode-to-fit — never silent.
|
|
29
30
|
|
|
30
31
|
const std = @import("std");
|
|
31
32
|
const canvas = @import("canvas");
|
|
@@ -36,6 +37,7 @@ const runtime_media_surface = @import("media_surface.zig");
|
|
|
36
37
|
|
|
37
38
|
pub const max_registered_canvas_images = canvas_limits.max_registered_canvas_images;
|
|
38
39
|
pub const max_registered_canvas_image_pixel_bytes = canvas_limits.max_registered_canvas_image_pixel_bytes;
|
|
40
|
+
pub const max_registered_canvas_image_pixel_bytes_ceiling = canvas_limits.max_registered_canvas_image_pixel_bytes_ceiling;
|
|
39
41
|
|
|
40
42
|
/// One registered image's metadata; pixels live in the runtime's slot
|
|
41
43
|
/// buffer at the same index.
|
|
@@ -53,19 +55,25 @@ pub const RegisteredCanvasImage = struct {
|
|
|
53
55
|
height: usize = 0,
|
|
54
56
|
};
|
|
55
57
|
|
|
56
|
-
///
|
|
57
|
-
///
|
|
58
|
-
///
|
|
59
|
-
/// byte per row: raw stream <= pixels + pixels/4 since a row is at least
|
|
60
|
-
/// 4 pixel bytes). Loop-thread only, like the frame scratch — and
|
|
61
|
-
/// lazily heap-allocated per thread (1.25 MiB) on the first decode, so
|
|
62
|
-
/// threads that never register image bytes never carry it in their
|
|
63
|
-
/// static TLS block.
|
|
58
|
+
/// Runtime-sized decode scratch for `registerCanvasImageBytes`. The TLS
|
|
59
|
+
/// slot itself is one pointer; its backing grows lazily to the largest app
|
|
60
|
+
/// budget used by this loop thread and lives for the thread's lifetime.
|
|
64
61
|
const CanvasImageDecodeScratch = struct {
|
|
65
|
-
bytes: [
|
|
62
|
+
bytes: []u8 = &.{},
|
|
66
63
|
};
|
|
67
64
|
const canvas_image_decode_scratch = canvas.lazy_tls.LazyTls(CanvasImageDecodeScratch);
|
|
68
65
|
|
|
66
|
+
fn imageDecodeScratch(required: usize) error{OutOfMemory}![]u8 {
|
|
67
|
+
const scratch = canvas_image_decode_scratch.get();
|
|
68
|
+
if (scratch.bytes.len < required) {
|
|
69
|
+
scratch.bytes = if (scratch.bytes.len == 0)
|
|
70
|
+
try std.heap.page_allocator.alloc(u8, required)
|
|
71
|
+
else
|
|
72
|
+
try std.heap.page_allocator.realloc(scratch.bytes, required);
|
|
73
|
+
}
|
|
74
|
+
return scratch.bytes[0..required];
|
|
75
|
+
}
|
|
76
|
+
|
|
69
77
|
pub fn RuntimeCanvasImages(comptime Runtime: type) type {
|
|
70
78
|
return struct {
|
|
71
79
|
/// Register (or replace) decoded pixels under `id`: tightly
|
|
@@ -97,7 +105,7 @@ pub fn RuntimeCanvasImages(comptime Runtime: type) type {
|
|
|
97
105
|
const row_len = std.math.mul(usize, width, 4) catch return error.InvalidImageDimensions;
|
|
98
106
|
const byte_len = std.math.mul(usize, row_len, height) catch return error.InvalidImageDimensions;
|
|
99
107
|
if (rgba8.len != byte_len) return error.InvalidImageDimensions;
|
|
100
|
-
if (byte_len >
|
|
108
|
+
if (byte_len > self.max_image_pixel_bytes) return error.ImageTooLarge;
|
|
101
109
|
|
|
102
110
|
const index = findCanvasImageIndex(self, id) orelse blk: {
|
|
103
111
|
if (self.canvas_image_count >= max_registered_canvas_images) return error.ImageRegistryFull;
|
|
@@ -119,7 +127,7 @@ pub fn RuntimeCanvasImages(comptime Runtime: type) type {
|
|
|
119
127
|
// failable step past validation and it runs BEFORE any
|
|
120
128
|
// registry mutation, so an OOM refusal leaves the
|
|
121
129
|
// registry exactly as it was and the caller can retry.
|
|
122
|
-
self.canvas_image_pixels[index] = try self.owned_allocator.alloc(u8,
|
|
130
|
+
self.canvas_image_pixels[index] = try self.owned_allocator.alloc(u8, self.max_image_pixel_bytes);
|
|
123
131
|
}
|
|
124
132
|
@memcpy(self.canvas_image_pixels[index][0..byte_len], rgba8);
|
|
125
133
|
self.canvas_image_entries[index] = .{
|
|
@@ -147,7 +155,10 @@ pub fn RuntimeCanvasImages(comptime Runtime: type) type {
|
|
|
147
155
|
/// id in the model. On top of `registerCanvasImage`'s errors:
|
|
148
156
|
/// `error.UnsupportedService` (platform has no codec),
|
|
149
157
|
/// `error.ImageDecodeFailed` (undecodable bytes),
|
|
150
|
-
///
|
|
158
|
+
/// Encoded images decode aspect-preservingly to fit the runtime's
|
|
159
|
+
/// frozen slot budget. `error.ImageTooLarge` means the encoded source
|
|
160
|
+
/// exceeded the fixed image-source bound or a platform codec violated
|
|
161
|
+
/// the decode cap, not an ordinary photo whose pixels need fitting.
|
|
151
162
|
/// `error.InvalidImageId` covers the same ids
|
|
152
163
|
/// `registerCanvasImage` refuses (0 and the reserved
|
|
153
164
|
/// media-surface namespace) and fires before any decode work.
|
|
@@ -159,8 +170,16 @@ pub fn RuntimeCanvasImages(comptime Runtime: type) type {
|
|
|
159
170
|
// gets `error.InvalidImageId`, not a codec error, and pays
|
|
160
171
|
// no decode cost for it.
|
|
161
172
|
if ((id & canvas.media_surface_image_id_bit) != 0) return error.InvalidImageId;
|
|
162
|
-
|
|
163
|
-
|
|
173
|
+
// Every encoded-registration entry point shares imageLoad's
|
|
174
|
+
// fixed source contract. Direct fx.registerImageBytes and
|
|
175
|
+
// Runtime.registerCanvasImageBytes calls must not hand an
|
|
176
|
+
// arbitrarily large allocation to a host codec merely because
|
|
177
|
+
// they bypassed the file/fetch executor.
|
|
178
|
+
if (bytes.len > effects_mod.max_effect_image_source_bytes) return error.ImageTooLarge;
|
|
179
|
+
const scratch_len = self.max_image_pixel_bytes + self.max_image_pixel_bytes / 4;
|
|
180
|
+
const scratch = try imageDecodeScratch(scratch_len);
|
|
181
|
+
const decoded = try self.options.platform.services.decodeImage(bytes, scratch, self.max_image_pixel_bytes / 4);
|
|
182
|
+
if (decoded.rgba8.len > self.max_image_pixel_bytes) return error.ImageTooLarge;
|
|
164
183
|
try registerCanvasImage(self, id, decoded.width, decoded.height, decoded.rgba8);
|
|
165
184
|
return .{ .width = decoded.width, .height = decoded.height };
|
|
166
185
|
}
|
|
@@ -101,11 +101,21 @@ pub const max_canvas_text_layout_lines_per_view: usize = 8192;
|
|
|
101
101
|
// avatar widgets. Slots are runtime-wide (all views share the registry;
|
|
102
102
|
// the frame planner threads it into every view's `image_resources`), and
|
|
103
103
|
// the runtime owns the pixel copies — the app's source buffer is free the
|
|
104
|
-
// moment registration returns. The per-image
|
|
105
|
-
//
|
|
106
|
-
//
|
|
104
|
+
// moment registration returns. The default per-image budget is
|
|
105
|
+
// 512x512 RGBA8, but encoded images decode-to-fit that budget instead of
|
|
106
|
+
// refusing photo-scale sources. Apps may raise the frozen per-runtime
|
|
107
|
+
// budget through app.zon; raw-pixel registration stays strict because
|
|
108
|
+
// that caller already owns the decoded pixels.
|
|
107
109
|
pub const max_registered_canvas_images: usize = 16;
|
|
108
110
|
pub const max_registered_canvas_image_pixel_bytes: usize = 1024 * 1024;
|
|
111
|
+
/// Hard ceiling for an app-declared registered-image budget. Deliberately
|
|
112
|
+
/// matches one media-surface channel: 8 MiB holds a 1080p RGBA8 image and
|
|
113
|
+
/// refuses 4K until the toolkit has real zero-copy paths. This is a
|
|
114
|
+
/// validation bound plus a per-USED-slot lazy allocation size, never a
|
|
115
|
+
/// Runtime reservation. At the ceiling, filling all 16 registry slots is
|
|
116
|
+
/// an app-declared 128 MiB high-water mark; an app using no slots allocates
|
|
117
|
+
/// zero registered-image pixel bytes.
|
|
118
|
+
pub const max_registered_canvas_image_pixel_bytes_ceiling: usize = 8 * 1024 * 1024;
|
|
109
119
|
|
|
110
120
|
// Media-surface texture channels (media_surface.zig): producer-pushed
|
|
111
121
|
// dynamic textures composited by media_surface widgets. Sized at video
|