@native-sdk/cli 0.5.2 → 0.5.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.zig +41 -0
- package/package.json +9 -9
- package/packages/core/package-lock.json +2 -2
- package/packages/core/package.json +1 -1
- package/packages/core/sdk/events.ts +39 -2
- package/packages/core/src/checker.ts +1 -1
- package/packages/core/src/emitter.ts +39 -3
- package/packages/core/src/infer.ts +53 -7
- package/skill-data/automation/SKILL.md +7 -4
- package/skill-data/core/references/app-model-runtime.md +3 -0
- package/skill-data/native-ui/SKILL.md +1 -0
- package/src/app_runner/root.zig +25 -0
- package/src/automation/protocol.zig +20 -1
- package/src/embed/host.zig +27 -0
- package/src/embed/tests.zig +69 -0
- package/src/embed/ui_host.zig +4 -0
- package/src/platform/macos/appkit_host.h +11 -0
- package/src/platform/macos/appkit_host.m +130 -0
- package/src/platform/macos/root.zig +34 -0
- package/src/platform/null_platform_tests.zig +39 -0
- package/src/platform/root.zig +3 -0
- package/src/platform/types.zig +109 -4
- package/src/primitives/canvas/chart.zig +7 -7
- package/src/primitives/canvas/chart_tests.zig +66 -0
- package/src/primitives/canvas/commands.zig +48 -0
- package/src/primitives/canvas/events.zig +161 -0
- package/src/primitives/canvas/font_ttf.zig +155 -8
- package/src/primitives/canvas/font_ttf_tests.zig +686 -0
- package/src/primitives/canvas/reference.zig +67 -8
- package/src/primitives/canvas/render_fingerprints.zig +8 -0
- package/src/primitives/canvas/root.zig +25 -0
- package/src/primitives/canvas/ui.zig +35 -2
- package/src/primitives/canvas/ui_markup.zig +24 -0
- package/src/primitives/canvas/ui_markup_binary_tests.zig +25 -0
- package/src/primitives/canvas/ui_markup_compiled.zig +40 -3
- package/src/primitives/canvas/ui_markup_compiled_tests.zig +33 -0
- package/src/primitives/canvas/ui_markup_contract.zig +9 -0
- package/src/primitives/canvas/ui_markup_contract_tests.zig +24 -0
- package/src/primitives/canvas/ui_markup_tests.zig +26 -0
- package/src/primitives/canvas/ui_markup_view.zig +53 -4
- package/src/primitives/canvas/ui_markup_view_tests.zig +73 -2
- package/src/primitives/canvas/ui_schema.zig +16 -0
- package/src/primitives/canvas/ui_schema_tests.zig +10 -11
- package/src/primitives/canvas/ui_tests.zig +31 -0
- package/src/primitives/canvas/vector.zig +258 -141
- package/src/primitives/canvas/widget_access.zig +1 -1
- package/src/primitives/canvas/widget_builtin_tests.zig +129 -0
- package/src/primitives/canvas/widget_layout.zig +9 -4
- package/src/primitives/canvas/widget_render.zig +78 -40
- package/src/primitives/canvas/widget_render_controls.zig +15 -4
- package/src/primitives/canvas/widget_semantics.zig +6 -1
- package/src/primitives/canvas/widget_semantics_tests.zig +168 -0
- package/src/primitives/canvas/widget_text_input.zig +118 -10
- package/src/primitives/canvas/widgets.zig +16 -0
- package/src/root.zig +5 -0
- package/src/runtime/api.zig +13 -0
- package/src/runtime/automation_commands.zig +33 -0
- package/src/runtime/automation_widget_dispatch.zig +64 -0
- package/src/runtime/canvas_font_tests.zig +272 -3
- package/src/runtime/canvas_fonts.zig +60 -20
- package/src/runtime/canvas_frame_helpers.zig +15 -0
- package/src/runtime/canvas_image_tests.zig +26 -0
- package/src/runtime/canvas_images.zig +33 -7
- package/src/runtime/canvas_limits.zig +44 -8
- package/src/runtime/canvas_widget_clipboard_tests.zig +123 -0
- package/src/runtime/canvas_widget_context_menu_tests.zig +55 -0
- package/src/runtime/canvas_widget_events.zig +24 -4
- package/src/runtime/canvas_widget_runtime.zig +24 -7
- package/src/runtime/canvas_widget_state.zig +6 -1
- package/src/runtime/canvas_widget_text_tests.zig +277 -0
- package/src/runtime/core.zig +98 -6
- package/src/runtime/flow.zig +27 -0
- package/src/runtime/gpu_surface_events.zig +7 -0
- package/src/runtime/media_surface.zig +726 -0
- package/src/runtime/media_surface_tests.zig +1476 -0
- package/src/runtime/root.zig +9 -0
- package/src/runtime/session_journal.zig +30 -3
- package/src/runtime/session_tests.zig +126 -4
- package/src/runtime/tests.zig +1 -0
- package/src/runtime/ts_ui_app.zig +56 -0
- package/src/runtime/ui_app.zig +58 -0
- package/src/runtime/ui_app_tests.zig +334 -0
|
@@ -65,6 +65,18 @@ const builtinBridgeErrorMessage = support.builtinBridgeErrorMessage;
|
|
|
65
65
|
const testViewByLabel = support.testViewByLabel;
|
|
66
66
|
const testCanvasWidgetPartId = support.testCanvasWidgetPartId;
|
|
67
67
|
|
|
68
|
+
test "the builder's presented-text store mirrors the per-view draw-text budget" {
|
|
69
|
+
// The chart path-element lockstep's sibling: presented single-line
|
|
70
|
+
// bytes persist into `Builder.text_bytes`, and the store can only
|
|
71
|
+
// overflow (falling back to raw bytes under the forced clip) on a
|
|
72
|
+
// frame the runtime's per-view display-list copy would refuse
|
|
73
|
+
// anyway. Keep the two budgets from drifting.
|
|
74
|
+
try std.testing.expectEqual(
|
|
75
|
+
@import("canvas_limits.zig").max_canvas_text_bytes_per_view,
|
|
76
|
+
canvas.max_display_list_text_bytes,
|
|
77
|
+
);
|
|
78
|
+
}
|
|
79
|
+
|
|
68
80
|
test "runtime exposes retained canvas widget text geometry" {
|
|
69
81
|
const TestApp = struct {
|
|
70
82
|
fn app(self: *@This()) App {
|
|
@@ -588,6 +600,271 @@ test "plain Enter inserts a newline in a canvas textarea; chorded Enter never ed
|
|
|
588
600
|
try std.testing.expectEqualStrings("First\n", retained.nodes[1].widget.text);
|
|
589
601
|
}
|
|
590
602
|
|
|
603
|
+
test "Enter in a single-line input never inserts, even when the host stuffs a newline into the key event" {
|
|
604
|
+
const TestApp = struct {
|
|
605
|
+
fn app(self: *@This()) App {
|
|
606
|
+
return .{ .context = self, .name = "gpu-widget-input-enter", .source = platform.WebViewSource.html("<h1>Hello</h1>") };
|
|
607
|
+
}
|
|
608
|
+
};
|
|
609
|
+
|
|
610
|
+
const harness = try TestHarness().create(std.testing.allocator, .{});
|
|
611
|
+
defer harness.destroy(std.testing.allocator);
|
|
612
|
+
harness.null_platform.gpu_surfaces = true;
|
|
613
|
+
var app_state: TestApp = .{};
|
|
614
|
+
const app = app_state.app();
|
|
615
|
+
try harness.start(app);
|
|
616
|
+
|
|
617
|
+
_ = try harness.runtime.createView(.{
|
|
618
|
+
.window_id = 1,
|
|
619
|
+
.label = "canvas",
|
|
620
|
+
.kind = .gpu_surface,
|
|
621
|
+
.frame = geometry.RectF.init(0, 0, 260, 160),
|
|
622
|
+
});
|
|
623
|
+
|
|
624
|
+
const input = canvas.Widget{
|
|
625
|
+
.id = 2,
|
|
626
|
+
.kind = .input,
|
|
627
|
+
.frame = geometry.RectF.init(12, 16, 180, 32),
|
|
628
|
+
.text = "Draft",
|
|
629
|
+
.semantics = .{ .label = "Title" },
|
|
630
|
+
};
|
|
631
|
+
var nodes: [2]canvas.WidgetLayoutNode = undefined;
|
|
632
|
+
const layout = try canvas.layoutWidgetTree(.{ .kind = .stack, .children = &.{input} }, geometry.RectF.init(0, 0, 260, 160), &nodes);
|
|
633
|
+
_ = try harness.runtime.setCanvasWidgetLayout(1, "canvas", layout);
|
|
634
|
+
|
|
635
|
+
try harness.runtime.dispatchPlatformEvent(app, .{ .gpu_surface_input = .{
|
|
636
|
+
.window_id = 1,
|
|
637
|
+
.label = "canvas",
|
|
638
|
+
.kind = .pointer_down,
|
|
639
|
+
.x = 100,
|
|
640
|
+
.y = 30,
|
|
641
|
+
} });
|
|
642
|
+
try std.testing.expectEqual(@as(canvas.ObjectId, 2), harness.runtime.views[0].canvas_widget_focused_id);
|
|
643
|
+
try harness.runtime.dispatchPlatformEvent(app, .{ .gpu_surface_input = .{
|
|
644
|
+
.window_id = 1,
|
|
645
|
+
.label = "canvas",
|
|
646
|
+
.kind = .key_down,
|
|
647
|
+
.key = "a",
|
|
648
|
+
.modifiers = .{ .primary = true, .command = true },
|
|
649
|
+
} });
|
|
650
|
+
|
|
651
|
+
// The macOS-host shape: Return as a bare `enter` keydown. Enter in a
|
|
652
|
+
// single-line field submits; it is NOT an edit.
|
|
653
|
+
try harness.runtime.dispatchPlatformEvent(app, .{ .gpu_surface_input = .{
|
|
654
|
+
.window_id = 1,
|
|
655
|
+
.label = "canvas",
|
|
656
|
+
.kind = .key_down,
|
|
657
|
+
.key = "enter",
|
|
658
|
+
} });
|
|
659
|
+
var retained = try harness.runtime.canvasWidgetLayout(1, "canvas");
|
|
660
|
+
try std.testing.expectEqualStrings("Draft", retained.nodes[1].widget.text);
|
|
661
|
+
try std.testing.expectEqualDeep(canvas.TextSelection{ .anchor = 0, .focus = 5 }, retained.nodes[1].widget.text_selection.?);
|
|
662
|
+
|
|
663
|
+
// A host that stuffs the newline into the key event's text payload
|
|
664
|
+
// still edits nothing: the sanitized insert strips to empty and
|
|
665
|
+
// suppresses — the live selection is not deleted.
|
|
666
|
+
try harness.runtime.dispatchPlatformEvent(app, .{ .gpu_surface_input = .{
|
|
667
|
+
.window_id = 1,
|
|
668
|
+
.label = "canvas",
|
|
669
|
+
.kind = .key_down,
|
|
670
|
+
.key = "enter",
|
|
671
|
+
.text = "\n",
|
|
672
|
+
} });
|
|
673
|
+
try harness.runtime.dispatchPlatformEvent(app, .{ .gpu_surface_input = .{
|
|
674
|
+
.window_id = 1,
|
|
675
|
+
.label = "canvas",
|
|
676
|
+
.kind = .key_down,
|
|
677
|
+
.key = "enter",
|
|
678
|
+
.text = "\r",
|
|
679
|
+
} });
|
|
680
|
+
retained = try harness.runtime.canvasWidgetLayout(1, "canvas");
|
|
681
|
+
try std.testing.expectEqualStrings("Draft", retained.nodes[1].widget.text);
|
|
682
|
+
try std.testing.expectEqualDeep(canvas.TextSelection{ .anchor = 0, .focus = 5 }, retained.nodes[1].widget.text_selection.?);
|
|
683
|
+
}
|
|
684
|
+
|
|
685
|
+
test "automation set_text with line breaks lands sanitized in single-line fields and raw in textareas" {
|
|
686
|
+
const TestApp = struct {
|
|
687
|
+
fn app(self: *@This()) App {
|
|
688
|
+
return .{ .context = self, .name = "gpu-widget-set-text-breaks", .source = platform.WebViewSource.html("<h1>Hello</h1>") };
|
|
689
|
+
}
|
|
690
|
+
};
|
|
691
|
+
|
|
692
|
+
const harness = try TestHarness().create(std.testing.allocator, .{});
|
|
693
|
+
defer harness.destroy(std.testing.allocator);
|
|
694
|
+
harness.null_platform.gpu_surfaces = true;
|
|
695
|
+
var app_state: TestApp = .{};
|
|
696
|
+
const app = app_state.app();
|
|
697
|
+
try harness.start(app);
|
|
698
|
+
|
|
699
|
+
_ = try harness.runtime.createView(.{
|
|
700
|
+
.window_id = 1,
|
|
701
|
+
.label = "canvas",
|
|
702
|
+
.kind = .gpu_surface,
|
|
703
|
+
.frame = geometry.RectF.init(0, 0, 320, 220),
|
|
704
|
+
});
|
|
705
|
+
|
|
706
|
+
const children = [_]canvas.Widget{
|
|
707
|
+
.{
|
|
708
|
+
.id = 2,
|
|
709
|
+
.kind = .search_field,
|
|
710
|
+
.frame = geometry.RectF.init(12, 16, 200, 36),
|
|
711
|
+
.text = "",
|
|
712
|
+
.semantics = .{ .label = "Query" },
|
|
713
|
+
},
|
|
714
|
+
.{
|
|
715
|
+
.id = 3,
|
|
716
|
+
.kind = .textarea,
|
|
717
|
+
.frame = geometry.RectF.init(12, 64, 280, 100),
|
|
718
|
+
.text = "",
|
|
719
|
+
.semantics = .{ .label = "Notes" },
|
|
720
|
+
},
|
|
721
|
+
};
|
|
722
|
+
var nodes: [3]canvas.WidgetLayoutNode = undefined;
|
|
723
|
+
const layout = try canvas.layoutWidgetTree(.{ .kind = .stack, .children = &children }, geometry.RectF.init(0, 0, 320, 220), &nodes);
|
|
724
|
+
_ = try harness.runtime.setCanvasWidgetLayout(1, "canvas", layout);
|
|
725
|
+
|
|
726
|
+
// Automation set_text rides the REAL text-input event path, so its
|
|
727
|
+
// line breaks sanitize at the same seam a paste does.
|
|
728
|
+
try dispatchAutomationWidgetAction(&harness.runtime, app, .{ .view_label = "canvas", .id = 2, .action = .set_text, .value = "edge\ncustomers\r\nfirst" });
|
|
729
|
+
var retained = try harness.runtime.canvasWidgetLayout(1, "canvas");
|
|
730
|
+
try std.testing.expectEqualStrings("edgecustomersfirst", retained.nodes[1].widget.text);
|
|
731
|
+
|
|
732
|
+
// The textarea takes the same payload verbatim.
|
|
733
|
+
try dispatchAutomationWidgetAction(&harness.runtime, app, .{ .view_label = "canvas", .id = 3, .action = .set_text, .value = "edge\ncustomers\r\nfirst" });
|
|
734
|
+
retained = try harness.runtime.canvasWidgetLayout(1, "canvas");
|
|
735
|
+
try std.testing.expectEqualStrings("edge\ncustomers\r\nfirst", retained.nodes[2].widget.text);
|
|
736
|
+
}
|
|
737
|
+
|
|
738
|
+
test "ime composition with a newline sanitizes into single-line fields before commit" {
|
|
739
|
+
const TestApp = struct {
|
|
740
|
+
fn app(self: *@This()) App {
|
|
741
|
+
return .{ .context = self, .name = "gpu-widget-ime-newline", .source = platform.WebViewSource.html("<h1>Hello</h1>") };
|
|
742
|
+
}
|
|
743
|
+
};
|
|
744
|
+
|
|
745
|
+
const harness = try TestHarness().create(std.testing.allocator, .{});
|
|
746
|
+
defer harness.destroy(std.testing.allocator);
|
|
747
|
+
harness.null_platform.gpu_surfaces = true;
|
|
748
|
+
var app_state: TestApp = .{};
|
|
749
|
+
const app = app_state.app();
|
|
750
|
+
try harness.start(app);
|
|
751
|
+
|
|
752
|
+
_ = try harness.runtime.createView(.{
|
|
753
|
+
.window_id = 1,
|
|
754
|
+
.label = "canvas",
|
|
755
|
+
.kind = .gpu_surface,
|
|
756
|
+
.frame = geometry.RectF.init(0, 0, 260, 120),
|
|
757
|
+
});
|
|
758
|
+
|
|
759
|
+
const text_field = canvas.Widget{
|
|
760
|
+
.id = 2,
|
|
761
|
+
.kind = .text_field,
|
|
762
|
+
.frame = geometry.RectF.init(12, 16, 180, 36),
|
|
763
|
+
.text = "Cafe",
|
|
764
|
+
.semantics = .{ .label = "Name" },
|
|
765
|
+
};
|
|
766
|
+
var nodes: [2]canvas.WidgetLayoutNode = undefined;
|
|
767
|
+
const layout = try canvas.layoutWidgetTree(.{ .kind = .stack, .children = &.{text_field} }, geometry.RectF.init(0, 0, 260, 120), &nodes);
|
|
768
|
+
_ = try harness.runtime.setCanvasWidgetLayout(1, "canvas", layout);
|
|
769
|
+
|
|
770
|
+
try harness.runtime.dispatchPlatformEvent(app, .{ .gpu_surface_input = .{
|
|
771
|
+
.window_id = 1,
|
|
772
|
+
.label = "canvas",
|
|
773
|
+
.kind = .pointer_down,
|
|
774
|
+
.x = 100,
|
|
775
|
+
.y = 30,
|
|
776
|
+
} });
|
|
777
|
+
try std.testing.expectEqual(@as(canvas.ObjectId, 2), harness.runtime.views[0].canvas_widget_focused_id);
|
|
778
|
+
|
|
779
|
+
// A composition PREVIEW carrying a newline sanitizes at the same
|
|
780
|
+
// seam every insert does — the preview in the retained editor holds
|
|
781
|
+
// the stripped bytes, so the COMMIT (which lands whatever the
|
|
782
|
+
// preview holds) can never commit a line break.
|
|
783
|
+
try harness.runtime.dispatchPlatformEvent(app, .{ .gpu_surface_input = .{
|
|
784
|
+
.window_id = 1,
|
|
785
|
+
.label = "canvas",
|
|
786
|
+
.kind = .ime_set_composition,
|
|
787
|
+
.text = " au\nlait",
|
|
788
|
+
.composition_cursor = 8,
|
|
789
|
+
} });
|
|
790
|
+
var retained = try harness.runtime.canvasWidgetLayout(1, "canvas");
|
|
791
|
+
try std.testing.expectEqualStrings("Cafe aulait", retained.nodes[1].widget.text);
|
|
792
|
+
try std.testing.expectEqualDeep(canvas.TextRange.init(4, 11), retained.nodes[1].widget.text_composition.?);
|
|
793
|
+
|
|
794
|
+
try harness.runtime.dispatchPlatformEvent(app, .{ .gpu_surface_input = .{
|
|
795
|
+
.window_id = 1,
|
|
796
|
+
.label = "canvas",
|
|
797
|
+
.kind = .ime_commit_composition,
|
|
798
|
+
} });
|
|
799
|
+
retained = try harness.runtime.canvasWidgetLayout(1, "canvas");
|
|
800
|
+
try std.testing.expectEqualStrings("Cafe aulait", retained.nodes[1].widget.text);
|
|
801
|
+
try std.testing.expect(retained.nodes[1].widget.text_composition == null);
|
|
802
|
+
}
|
|
803
|
+
|
|
804
|
+
test "a model-set single-line value with a newline paints one line inside the field" {
|
|
805
|
+
const TestApp = struct {
|
|
806
|
+
fn app(self: *@This()) App {
|
|
807
|
+
return .{ .context = self, .name = "gpu-widget-value-newline", .source = platform.WebViewSource.html("<h1>Hello</h1>") };
|
|
808
|
+
}
|
|
809
|
+
};
|
|
810
|
+
|
|
811
|
+
const harness = try TestHarness().create(std.testing.allocator, .{});
|
|
812
|
+
defer harness.destroy(std.testing.allocator);
|
|
813
|
+
harness.null_platform.gpu_surfaces = true;
|
|
814
|
+
var app_state: TestApp = .{};
|
|
815
|
+
const app = app_state.app();
|
|
816
|
+
try harness.start(app);
|
|
817
|
+
|
|
818
|
+
_ = try harness.runtime.createView(.{
|
|
819
|
+
.window_id = 1,
|
|
820
|
+
.label = "canvas",
|
|
821
|
+
.kind = .gpu_surface,
|
|
822
|
+
.frame = geometry.RectF.init(0, 0, 320, 120),
|
|
823
|
+
});
|
|
824
|
+
|
|
825
|
+
// A Zig core can put a newline into a field's VALUE today; the
|
|
826
|
+
// sanitize seam only guards EDITS. The retained value keeps the raw
|
|
827
|
+
// bytes (semantics and automation report honestly), but the painted
|
|
828
|
+
// text presents the breaks as spaces on ONE line, under a forced
|
|
829
|
+
// content-rect clip — nothing escapes the rounded border.
|
|
830
|
+
const input = canvas.Widget{
|
|
831
|
+
.id = 2,
|
|
832
|
+
.kind = .input,
|
|
833
|
+
.frame = geometry.RectF.init(12, 16, 200, 32),
|
|
834
|
+
.text = "one\ntwo",
|
|
835
|
+
.semantics = .{ .label = "Title" },
|
|
836
|
+
};
|
|
837
|
+
var nodes: [2]canvas.WidgetLayoutNode = undefined;
|
|
838
|
+
const layout = try canvas.layoutWidgetTree(.{ .kind = .stack, .children = &.{input} }, geometry.RectF.init(0, 0, 320, 120), &nodes);
|
|
839
|
+
_ = try harness.runtime.setCanvasWidgetLayout(1, "canvas", layout);
|
|
840
|
+
_ = try harness.runtime.emitCanvasWidgetDisplayList(1, "canvas", .{});
|
|
841
|
+
|
|
842
|
+
const display_list = try harness.runtime.canvasDisplayList(1, "canvas");
|
|
843
|
+
var saw_presented_text = false;
|
|
844
|
+
var saw_clip = false;
|
|
845
|
+
for (display_list.commands) |command| {
|
|
846
|
+
switch (command) {
|
|
847
|
+
.draw_text => |text| {
|
|
848
|
+
if (text.id == testCanvasWidgetPartId(2, 3)) {
|
|
849
|
+
try std.testing.expectEqualStrings("one two", text.text);
|
|
850
|
+
saw_presented_text = true;
|
|
851
|
+
}
|
|
852
|
+
},
|
|
853
|
+
.push_clip => |clip| {
|
|
854
|
+
if (clip.id == testCanvasWidgetPartId(2, 16)) saw_clip = true;
|
|
855
|
+
},
|
|
856
|
+
else => {},
|
|
857
|
+
}
|
|
858
|
+
}
|
|
859
|
+
try std.testing.expect(saw_presented_text);
|
|
860
|
+
try std.testing.expect(saw_clip);
|
|
861
|
+
|
|
862
|
+
// Semantics (and therefore automation and assistive tech) still read
|
|
863
|
+
// the RAW model value: presentation never rewrites the model.
|
|
864
|
+
const snapshot = harness.runtime.automationSnapshot("Widgets");
|
|
865
|
+
try std.testing.expectEqualStrings("one\ntwo", snapshot.widgets[0].text_value);
|
|
866
|
+
}
|
|
867
|
+
|
|
591
868
|
test "runtime applies ime composition edits to canvas text fields" {
|
|
592
869
|
const TestApp = struct {
|
|
593
870
|
fn app(self: *@This()) App {
|
package/src/runtime/core.zig
CHANGED
|
@@ -15,6 +15,7 @@ const shell_layout = @import("shell_layout.zig");
|
|
|
15
15
|
const canvas_frame_helpers = @import("canvas_frame.zig");
|
|
16
16
|
const canvas_limits = @import("canvas_limits.zig");
|
|
17
17
|
const runtime_canvas_images = @import("canvas_images.zig");
|
|
18
|
+
const runtime_media_surface = @import("media_surface.zig");
|
|
18
19
|
const runtime_canvas_fonts = @import("canvas_fonts.zig");
|
|
19
20
|
const runtime_canvas_widget_context_menu = @import("canvas_widget_context_menu.zig");
|
|
20
21
|
const runtime_canvas_widget_display = @import("canvas_widget_display.zig");
|
|
@@ -178,6 +179,18 @@ pub const DispatchErrorPolicy = enum { degrade, propagate };
|
|
|
178
179
|
|
|
179
180
|
pub const Runtime = struct {
|
|
180
181
|
options: Options,
|
|
182
|
+
/// The allocator that owns every runtime-lifetime heap allocation
|
|
183
|
+
/// (registered canvas font bytes, adopted media-surface texture
|
|
184
|
+
/// buffers). Captured from `Options.allocator` at init precisely
|
|
185
|
+
/// because `options` is public and mutable: allocation and free of
|
|
186
|
+
/// owned storage can be a whole runtime lifetime apart, and they
|
|
187
|
+
/// must resolve through ONE allocator identity. Mutating
|
|
188
|
+
/// `options.allocator` on a live runtime does not retarget this —
|
|
189
|
+
/// bytes are always returned to the allocator that made them. Every
|
|
190
|
+
/// on-demand owner (registration and adoption allocs, refusal-path
|
|
191
|
+
/// frees, the `deinit` frees) goes through this field, never
|
|
192
|
+
/// through `options.allocator`.
|
|
193
|
+
owned_allocator: std.mem.Allocator,
|
|
181
194
|
surface: platform.Surface,
|
|
182
195
|
appearance: platform.Appearance = .{},
|
|
183
196
|
windows: [platform.max_windows]RuntimeWindow = undefined,
|
|
@@ -353,15 +366,39 @@ pub const Runtime = struct {
|
|
|
353
366
|
canvas_image_entries: [canvas_limits.max_registered_canvas_images]runtime_canvas_images.CanvasImageEntry = [_]runtime_canvas_images.CanvasImageEntry{.{}} ** canvas_limits.max_registered_canvas_images,
|
|
354
367
|
canvas_image_count: usize = 0,
|
|
355
368
|
canvas_image_pixels: [canvas_limits.max_registered_canvas_images][canvas_limits.max_registered_canvas_image_pixel_bytes]u8 = undefined,
|
|
356
|
-
|
|
369
|
+
/// `ReferenceImage` scratch the frame planner hands to renderers
|
|
370
|
+
/// each plan: the registered images plus the adopted media-surface
|
|
371
|
+
/// textures (appended as `presentation_only` entries).
|
|
372
|
+
canvas_image_resources_scratch: [canvas_limits.max_registered_canvas_images + canvas_limits.max_media_surface_channels]canvas.ReferenceImage = undefined,
|
|
373
|
+
/// Adopted media-surface textures (see media_surface.zig): entry
|
|
374
|
+
/// metadata and the per-channel pixel buffers the loop thread owns.
|
|
375
|
+
/// Each buffer is ONE lazy frame-budget allocation from the frozen
|
|
376
|
+
/// `owned_allocator` at the entry's first adoption (freed only by
|
|
377
|
+
/// `deinit`) — zero media use costs zero bytes, where an embedded
|
|
378
|
+
/// pool at the budget would put 4 x 8 MiB = 32 MiB in EVERY Runtime
|
|
379
|
+
/// (the registered-font-pool regression's twin, measured on the
|
|
380
|
+
/// docs wasm preview host as +32 MB per component tile before any
|
|
381
|
+
/// producer existed). The cross-thread mailbox producers push into
|
|
382
|
+
/// is process-lived module state, deliberately NOT here — a
|
|
383
|
+
/// producer outliving this runtime must never reach runtime memory.
|
|
384
|
+
media_surface_entries: [canvas_limits.max_media_surface_channels]runtime_media_surface.MediaSurfaceTextureEntry = [_]runtime_media_surface.MediaSurfaceTextureEntry{.{}} ** canvas_limits.max_media_surface_channels,
|
|
385
|
+
media_surface_count: usize = 0,
|
|
386
|
+
media_surface_pixels: [canvas_limits.max_media_surface_channels][]u8 = [_][]u8{&.{}} ** canvas_limits.max_media_surface_channels,
|
|
387
|
+
/// Process-unique tag stamped on mailbox slots this runtime claims
|
|
388
|
+
/// (0 until the first acquire): slot ownership survives allocator
|
|
389
|
+
/// address reuse across runtimes in one process.
|
|
390
|
+
media_surface_runtime_tag: u64 = 0,
|
|
357
391
|
/// Runtime-registered canvas fonts (see canvas_fonts.zig): entry
|
|
358
|
-
/// metadata
|
|
359
|
-
///
|
|
360
|
-
///
|
|
361
|
-
///
|
|
392
|
+
/// metadata carrying each face's heap-owned TrueType bytes (exact
|
|
393
|
+
/// file size, allocated from the init-frozen `owned_allocator` at
|
|
394
|
+
/// registration —
|
|
395
|
+
/// zero fonts cost zero bytes; freed only by `deinit`, registration
|
|
396
|
+
/// being permanent), parsed face views over those bytes, the
|
|
397
|
+
/// `ReferenceFont` scratch the frame planner hands to renderers, and
|
|
398
|
+
/// the font-aware measure provider installed on first registration
|
|
399
|
+
/// for platforms without host-side text measurement.
|
|
362
400
|
canvas_font_entries: [canvas_limits.max_registered_canvas_fonts]runtime_canvas_fonts.CanvasFontEntry = [_]runtime_canvas_fonts.CanvasFontEntry{.{}} ** canvas_limits.max_registered_canvas_fonts,
|
|
363
401
|
canvas_font_count: usize = 0,
|
|
364
|
-
canvas_font_bytes: [canvas_limits.max_registered_canvas_fonts][canvas_limits.max_registered_canvas_font_bytes]u8 = undefined,
|
|
365
402
|
canvas_font_faces: [canvas_limits.max_registered_canvas_fonts]canvas.font_ttf.Face = undefined,
|
|
366
403
|
canvas_font_resources_scratch: [canvas_limits.max_registered_canvas_fonts]canvas.ReferenceFont = undefined,
|
|
367
404
|
canvas_font_measure_provider: canvas.TextMeasureProvider = .{ .measure_fn = runtime_canvas_fonts.unboundCanvasFontMeasure },
|
|
@@ -388,6 +425,10 @@ pub const Runtime = struct {
|
|
|
388
425
|
}
|
|
389
426
|
}
|
|
390
427
|
self.options = options;
|
|
428
|
+
// Freeze the ownership allocator now (see the field doc):
|
|
429
|
+
// `options` stays publicly mutable, but the identity that owns
|
|
430
|
+
// on-demand storage must not move under live allocations.
|
|
431
|
+
self.owned_allocator = options.allocator;
|
|
391
432
|
self.surface = options.platform.surface();
|
|
392
433
|
// The profile rings exceed the small-default copy bound above;
|
|
393
434
|
// assign explicitly so the disabled state is never undefined.
|
|
@@ -409,6 +450,36 @@ pub const Runtime = struct {
|
|
|
409
450
|
canvas.bumpTextMeasureGeneration();
|
|
410
451
|
}
|
|
411
452
|
|
|
453
|
+
/// Release the runtime's heap-owned on-demand storage (registered
|
|
454
|
+
/// canvas font bytes and adopted media-surface texture buffers,
|
|
455
|
+
/// allocated from the init-frozen `owned_allocator`) and disarm the
|
|
456
|
+
/// media-surface wake bindings (a producer thread must never wake a
|
|
457
|
+
/// dead host). Ends the runtime's life: parsed faces, atlas keys,
|
|
458
|
+
/// measure providers, adopted textures, and the resource slices
|
|
459
|
+
/// built over them are invalid past this point. Process-lifetime
|
|
460
|
+
/// embeddings (the app runner) may skip it — the default
|
|
461
|
+
/// allocator's pages die with the process, and the run loop's exit
|
|
462
|
+
/// defer already disarms the wakes — but embedders that create and
|
|
463
|
+
/// destroy runtimes in one process (tests, the docs wasm preview
|
|
464
|
+
/// host) call it to return the storage.
|
|
465
|
+
pub fn deinit(self: *Runtime) void {
|
|
466
|
+
self.disarmMediaSurfaceWakes();
|
|
467
|
+
for (self.canvas_font_entries[0..self.canvas_font_count]) |entry| {
|
|
468
|
+
// Through the frozen identity, never `options.allocator`:
|
|
469
|
+
// an embedder may have swapped the public option since these
|
|
470
|
+
// bytes were made, and a free must hit the allocator that
|
|
471
|
+
// allocated.
|
|
472
|
+
self.owned_allocator.free(entry.bytes);
|
|
473
|
+
}
|
|
474
|
+
self.canvas_font_count = 0;
|
|
475
|
+
for (&self.media_surface_pixels) |*buffer| {
|
|
476
|
+
if (buffer.len != 0) self.owned_allocator.free(buffer.*);
|
|
477
|
+
buffer.* = &.{};
|
|
478
|
+
}
|
|
479
|
+
self.media_surface_entries = [_]runtime_media_surface.MediaSurfaceTextureEntry{.{}} ** canvas_limits.max_media_surface_channels;
|
|
480
|
+
self.media_surface_count = 0;
|
|
481
|
+
}
|
|
482
|
+
|
|
412
483
|
fn fieldHasSmallDefault(comptime field: std.builtin.Type.StructField) bool {
|
|
413
484
|
// Large fixed-capacity arrays default to undefined; skip writing
|
|
414
485
|
// them so construction touches kilobytes, not megabytes.
|
|
@@ -716,6 +787,13 @@ pub const Runtime = struct {
|
|
|
716
787
|
pub const registeredCanvasImageCount = CanvasImageMethods.registeredCanvasImageCount;
|
|
717
788
|
pub const canvasImageRegistryBinding = CanvasImageMethods.canvasImageRegistryBinding;
|
|
718
789
|
|
|
790
|
+
const MediaSurfaceMethods = runtime_media_surface.RuntimeMediaSurfaces(Runtime);
|
|
791
|
+
pub const acquireMediaSurfaceProducer = MediaSurfaceMethods.acquireMediaSurfaceProducer;
|
|
792
|
+
pub const adoptMediaSurfaceFrames = MediaSurfaceMethods.adoptMediaSurfaceFrames;
|
|
793
|
+
pub const disarmMediaSurfaceWakes = MediaSurfaceMethods.disarmMediaSurfaceWakes;
|
|
794
|
+
pub const adoptedMediaSurfaceTexture = MediaSurfaceMethods.adoptedMediaSurfaceTexture;
|
|
795
|
+
const adoptedMediaSurfaceTextures = MediaSurfaceMethods.adoptedMediaSurfaceTextures;
|
|
796
|
+
|
|
719
797
|
const CanvasFontMethods = runtime_canvas_fonts.RuntimeCanvasFonts(Runtime);
|
|
720
798
|
pub const registerCanvasFont = CanvasFontMethods.registerCanvasFont;
|
|
721
799
|
pub const registeredCanvasFonts = CanvasFontMethods.registeredCanvasFonts;
|
|
@@ -837,6 +915,14 @@ pub fn TestHarness() type {
|
|
|
837
915
|
}
|
|
838
916
|
|
|
839
917
|
pub fn destroy(self: *Self, gpa: std.mem.Allocator) void {
|
|
918
|
+
// The harness embeds the runtime's platform: deinit both
|
|
919
|
+
// returns the runtime's heap-owned storage (registered font
|
|
920
|
+
// bytes, lazily allocated media buffers) to the leak-checked
|
|
921
|
+
// test allocator AND disarms the wake bindings, so a
|
|
922
|
+
// producer handle a test keeps past destroy (the orphan
|
|
923
|
+
// tests) can never wake the freed host — the run loop's exit
|
|
924
|
+
// defer for real apps, this line for harness-driven ones.
|
|
925
|
+
self.runtime.deinit();
|
|
840
926
|
gpa.destroy(self);
|
|
841
927
|
}
|
|
842
928
|
|
|
@@ -846,6 +932,12 @@ pub fn TestHarness() type {
|
|
|
846
932
|
Runtime.initAt(&self.runtime, .{
|
|
847
933
|
.platform = self.null_platform.platform(),
|
|
848
934
|
.trace_sink = self.trace_sink.sink(),
|
|
935
|
+
// On-demand runtime storage (registered font bytes,
|
|
936
|
+
// adopted media-surface texture buffers) routes through
|
|
937
|
+
// the leak-checked test allocator (freed by `destroy`
|
|
938
|
+
// via Runtime.deinit), so a registration or adoption
|
|
939
|
+
// that leaks fails the test that made it.
|
|
940
|
+
.allocator = if (builtin.is_test) std.testing.allocator else std.heap.page_allocator,
|
|
849
941
|
// Real-executor effect tests spawn processes that must
|
|
850
942
|
// see the parent environment (HOME, PATH), exactly as
|
|
851
943
|
// the app runner threads it from `std.process.Init`.
|
package/src/runtime/flow.zig
CHANGED
|
@@ -39,6 +39,7 @@ const parseAutomationProvenanceTarget = automation_commands.parseAutomationProve
|
|
|
39
39
|
const parseAutomationWidgetWheel = automation_commands.parseAutomationWidgetWheel;
|
|
40
40
|
const parseAutomationWidgetContextMenuItem = automation_commands.parseAutomationWidgetContextMenuItem;
|
|
41
41
|
const parseAutomationWidgetKey = automation_commands.parseAutomationWidgetKey;
|
|
42
|
+
const parseAutomationWidgetPinch = automation_commands.parseAutomationWidgetPinch;
|
|
42
43
|
const parseAutomationWidgetPointerDrag = automation_commands.parseAutomationWidgetPointerDrag;
|
|
43
44
|
const parseAutomationResizeCommand = automation_commands.parseAutomationResizeCommand;
|
|
44
45
|
const parseAutomationTrayItemId = automation_commands.parseAutomationTrayItemId;
|
|
@@ -135,6 +136,16 @@ pub fn RuntimeFlow(comptime Runtime: type) type {
|
|
|
135
136
|
// away, so the watcher can never call into a dead host.
|
|
136
137
|
defer if (command_watcher_running) command_watcher.stop();
|
|
137
138
|
|
|
139
|
+
// Media-surface wake teardown: producers a slow app forgot
|
|
140
|
+
// to release may push (and try to wake this platform) at
|
|
141
|
+
// any later time from their own threads. Disarm their wake
|
|
142
|
+
// bindings before the caller's later-declared defers tear
|
|
143
|
+
// the host down — declared BEFORE the app-stop defer below
|
|
144
|
+
// so it runs AFTER the stop hook (LIFO), letting the hook
|
|
145
|
+
// join producer threads first. The same run-exit ordering
|
|
146
|
+
// that stops the automation arrival watcher.
|
|
147
|
+
defer self.disarmMediaSurfaceWakes();
|
|
148
|
+
|
|
138
149
|
// Teardown ordering contract: everything the app must do
|
|
139
150
|
// against the live platform — silencing an active audio
|
|
140
151
|
// player, disarming platform timers, joining effect workers
|
|
@@ -523,6 +534,18 @@ pub fn RuntimeFlow(comptime Runtime: type) type {
|
|
|
523
534
|
|
|
524
535
|
pub fn frame(self: *Runtime, app: App) anyerror!void {
|
|
525
536
|
const start_ns = nowNanoseconds();
|
|
537
|
+
// A media-surface producer's wake arrives as THIS event (the
|
|
538
|
+
// platform's cross-thread frame request): adopt staged
|
|
539
|
+
// frames here so an idle app's push reaches the runtime —
|
|
540
|
+
// adoption's invalidation then arms the prompt gpu-surface
|
|
541
|
+
// frame that composites it (`noteCanvasImagesChanged` ->
|
|
542
|
+
// `requestCanvasFrameForView`). Runs before the invalidation
|
|
543
|
+
// check below because adoption IS an invalidation source; a
|
|
544
|
+
// busy app pays one fenced flag check per idle channel, and
|
|
545
|
+
// the gpu-surface frame dispatch's own adoption call keeps
|
|
546
|
+
// pacing consumption for hosts whose frame events do not
|
|
547
|
+
// pass through here.
|
|
548
|
+
self.adoptMediaSurfaceFrames();
|
|
526
549
|
try consumeAutomationCommand(self, app);
|
|
527
550
|
if (!self.invalidated) return;
|
|
528
551
|
|
|
@@ -816,6 +839,7 @@ pub fn RuntimeFlow(comptime Runtime: type) type {
|
|
|
816
839
|
.widget_drag => "automation.widget_drag",
|
|
817
840
|
.widget_wheel => "automation.widget_wheel",
|
|
818
841
|
.widget_key => "automation.widget_key",
|
|
842
|
+
.widget_pinch => "automation.widget_pinch",
|
|
819
843
|
.tray_action => "automation.tray_action",
|
|
820
844
|
.provenance => "automation.provenance",
|
|
821
845
|
else => "automation.command",
|
|
@@ -877,6 +901,9 @@ pub fn RuntimeFlow(comptime Runtime: type) type {
|
|
|
877
901
|
.widget_key => {
|
|
878
902
|
try AutomationWidgetMethods().dispatchAutomationWidgetKeyInput(self, app, try parseAutomationWidgetKey(command.value));
|
|
879
903
|
},
|
|
904
|
+
.widget_pinch => {
|
|
905
|
+
try AutomationWidgetMethods().dispatchAutomationWidgetPinch(self, app, try parseAutomationWidgetPinch(command.value));
|
|
906
|
+
},
|
|
880
907
|
.menu_command => {
|
|
881
908
|
try dispatchPlatformEvent(self, app, .{ .menu_command = .{
|
|
882
909
|
.name = try parseAutomationCommandName(command.value),
|
|
@@ -17,6 +17,13 @@ const sizesEqual = canvas_frame_helpers.sizesEqual;
|
|
|
17
17
|
pub fn RuntimeGpuSurfaceEvents(comptime Runtime: type) type {
|
|
18
18
|
return struct {
|
|
19
19
|
pub fn dispatchGpuSurfaceFrame(self: *Runtime, app: runtime_api.App(Runtime), frame_event: platform.GpuSurfaceFrameEvent) anyerror!void {
|
|
20
|
+
// Media-surface adoption rides the compositor's
|
|
21
|
+
// presented-frame clock: staged producer frames (latest
|
|
22
|
+
// wins) are sampled once per frame event, BEFORE view state
|
|
23
|
+
// and the app dispatch, so a changed texture invalidates
|
|
24
|
+
// the very frame this event is about to present. Idle
|
|
25
|
+
// channels cost one fenced flag check each.
|
|
26
|
+
self.adoptMediaSurfaceFrames();
|
|
20
27
|
var enriched_frame_event = frame_event;
|
|
21
28
|
var had_pending_input = false;
|
|
22
29
|
if (runtimeFindViewIndex(self, frame_event.window_id, frame_event.label)) |index| {
|