@native-sdk/cli 0.5.1 → 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 +3 -2
- 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 +118 -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 +26 -0
- package/src/primitives/canvas/tokens.zig +170 -7
- package/src/primitives/canvas/ui.zig +62 -7
- package/src/primitives/canvas/ui_markup.zig +51 -4
- package/src/primitives/canvas/ui_markup_binary_tests.zig +25 -0
- package/src/primitives/canvas/ui_markup_compiled.zig +49 -4
- package/src/primitives/canvas/ui_markup_compiled_tests.zig +160 -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 +73 -0
- package/src/primitives/canvas/ui_markup_view.zig +63 -5
- package/src/primitives/canvas/ui_markup_view_tests.zig +151 -2
- package/src/primitives/canvas/ui_schema.zig +31 -1
- package/src/primitives/canvas/ui_schema_tests.zig +11 -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 +259 -0
- package/src/primitives/canvas/widget_layout.zig +13 -5
- package/src/primitives/canvas/widget_layout_tests.zig +82 -0
- 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/widget_tree.zig +14 -2
- package/src/primitives/canvas/widgets.zig +28 -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 +159 -28
- package/src/runtime/canvas_font_tests.zig +272 -3
- package/src/runtime/canvas_fonts.zig +60 -20
- package/src/runtime/canvas_frame.zig +15 -0
- 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_anchored_tests.zig +253 -65
- package/src/runtime/canvas_widget_clipboard_tests.zig +123 -0
- package/src/runtime/canvas_widget_context_menu.zig +3 -2
- package/src/runtime/canvas_widget_context_menu_tests.zig +55 -0
- package/src/runtime/canvas_widget_events.zig +1295 -7
- package/src/runtime/canvas_widget_floating_tests.zig +2801 -0
- package/src/runtime/canvas_widget_runtime.zig +24 -7
- package/src/runtime/canvas_widget_scroll_drivers.zig +1 -1
- package/src/runtime/canvas_widget_state.zig +88 -6
- package/src/runtime/canvas_widget_text_tests.zig +277 -0
- package/src/runtime/core.zig +112 -6
- package/src/runtime/flow.zig +51 -1
- package/src/runtime/gpu_surface_events.zig +51 -5
- 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 +52 -13
- package/src/runtime/session_record.zig +166 -0
- package/src/runtime/session_tests.zig +575 -0
- package/src/runtime/tests.zig +1 -0
- package/src/runtime/ts_ui_app.zig +56 -0
- package/src/runtime/ui_app.zig +64 -1
- package/src/runtime/ui_app_tests.zig +794 -0
- package/src/runtime/view.zig +86 -0
- package/src/runtime/view_widget_text.zig +18 -1
- package/src/runtime/view_widget_tree.zig +339 -20
- package/src/runtime/widget_bridge.zig +26 -0
- package/src/runtime/window_storage.zig +61 -15
- package/src/runtime/window_view_runtime.zig +13 -0
- package/src/runtime/window_views.zig +6 -0
|
@@ -7,12 +7,18 @@
|
|
|
7
7
|
//!
|
|
8
8
|
//! Validation is loud and registration-time only: the bytes must parse as
|
|
9
9
|
//! a TrueType face (`canvas.font_ttf.Face.parse`) under the registry
|
|
10
|
-
//! bounds
|
|
11
|
-
//!
|
|
10
|
+
//! bounds — including the glyph-outline budget gate on the face's
|
|
11
|
+
//! declared `maxp` maxima (`error.FontExceedsGlyphBudgets` when a face
|
|
12
|
+
//! declares denser glyphs than `canvas.font_ttf`'s budgets; the budgets
|
|
13
|
+
//! are sized from real CJK faces, so this refuses only outliers) — or
|
|
14
|
+
//! registration fails with a recoverable error. A registered id
|
|
15
|
+
//! therefore ALWAYS resolves at render time, and the only per-glyph
|
|
12
16
|
//! fallback is the same notdef block built-in faces use for codepoints a
|
|
13
17
|
//! face does not cover. `canvas.font_ttf.parseFailureReason` turns a
|
|
14
|
-
//! rejected file into a teaching sentence
|
|
15
|
-
//!
|
|
18
|
+
//! rejected file into a teaching sentence, and
|
|
19
|
+
//! `canvas.font_ttf.declaredGlyphMaxima` names a budget-refused face's
|
|
20
|
+
//! declared numbers, for callers that know the file's name (UiApp's
|
|
21
|
+
//! `fonts` option uses both).
|
|
16
22
|
//!
|
|
17
23
|
//! Both renderers resolve registered ids exactly like built-ins:
|
|
18
24
|
//! - The frame planner threads the registered set into
|
|
@@ -39,8 +45,19 @@
|
|
|
39
45
|
//! retained caches. Re-using a registered id fails with
|
|
40
46
|
//! `error.FontIdInUse`; there is deliberately no unregister.
|
|
41
47
|
//!
|
|
42
|
-
//!
|
|
43
|
-
//!
|
|
48
|
+
//! Byte storage is on-demand: registration copies the file into an
|
|
49
|
+
//! exact-size heap allocation from the runtime's init-frozen
|
|
50
|
+
//! `owned_allocator` (captured from `Options.allocator`), so
|
|
51
|
+
//! a runtime with no registered fonts carries zero font bytes (embedding
|
|
52
|
+
//! hosts create a Runtime per surface — a reservation-shaped pool at the
|
|
53
|
+
//! 24 MiB CJK bound would embed 192 MiB in every one). Permanence makes
|
|
54
|
+
//! ownership trivial: the bytes live until `Runtime.deinit`, and the
|
|
55
|
+
//! parsed `Face` views, the gpu-surface host copy, and the measure
|
|
56
|
+
//! provider all borrow them for exactly that lifetime.
|
|
57
|
+
//!
|
|
58
|
+
//! Capacities follow `canvas_limits` as VALIDATION bounds, not storage
|
|
59
|
+
//! reservations: at most `max_registered_canvas_fonts` registrations of
|
|
60
|
+
//! at most `max_registered_canvas_font_bytes` each, overflow is
|
|
44
61
|
//! `error.FontRegistryFull` / `error.FontTooLarge` — never silent.
|
|
45
62
|
|
|
46
63
|
const std = @import("std");
|
|
@@ -51,12 +68,13 @@ const canvas_limits = @import("canvas_limits.zig");
|
|
|
51
68
|
pub const max_registered_canvas_fonts = canvas_limits.max_registered_canvas_fonts;
|
|
52
69
|
pub const max_registered_canvas_font_bytes = canvas_limits.max_registered_canvas_font_bytes;
|
|
53
70
|
|
|
54
|
-
/// One registered font
|
|
55
|
-
///
|
|
56
|
-
///
|
|
71
|
+
/// One registered font: its id and the exact-size heap copy of its
|
|
72
|
+
/// TrueType bytes (owned by the runtime's init-frozen `owned_allocator`,
|
|
73
|
+
/// freed at `Runtime.deinit`); the parsed face view lives in the parallel
|
|
74
|
+
/// face array at the same index and points into these bytes.
|
|
57
75
|
pub const CanvasFontEntry = struct {
|
|
58
76
|
id: canvas.FontId = 0,
|
|
59
|
-
|
|
77
|
+
bytes: []const u8 = &.{},
|
|
60
78
|
};
|
|
61
79
|
|
|
62
80
|
/// Placeholder measure fn for the runtime's font-aware provider field
|
|
@@ -82,14 +100,18 @@ pub fn RuntimeCanvasFonts(comptime Runtime: type) type {
|
|
|
82
100
|
/// `error.InvalidFontId` (id 0 is the "inherit run font"
|
|
83
101
|
/// sentinel), `error.ReservedFontId` (below
|
|
84
102
|
/// `canvas.min_registered_font_id` — reserved for built-in
|
|
85
|
-
/// faces), `error.FontTooLarge` (over the per-
|
|
103
|
+
/// faces), `error.FontTooLarge` (over the per-font bound
|
|
86
104
|
/// `canvas_limits.max_registered_canvas_font_bytes`),
|
|
87
105
|
/// `error.FontIdInUse` (ids are permanent; see the module doc),
|
|
88
106
|
/// `error.FontRegistryFull` (all
|
|
89
|
-
/// `canvas_limits.max_registered_canvas_fonts`
|
|
90
|
-
/// ids), `error.FontParseFailed` (not a parseable TrueType face —
|
|
107
|
+
/// `canvas_limits.max_registered_canvas_fonts` registrations
|
|
108
|
+
/// hold other ids), `error.FontParseFailed` (not a parseable TrueType face —
|
|
91
109
|
/// `canvas.font_ttf.parseFailureReason(ttf)` names what is wrong),
|
|
92
|
-
/// `error.
|
|
110
|
+
/// `error.FontExceedsGlyphBudgets` (the face's `maxp` declares
|
|
111
|
+
/// glyphs denser than `canvas.font_ttf`'s outline budgets, so its
|
|
112
|
+
/// densest glyphs could not render as outlines —
|
|
113
|
+
/// `canvas.font_ttf.declaredGlyphMaxima(ttf)` names the declared
|
|
114
|
+
/// maxima), `error.FontHostRegistrationUnsupported` (the platform measures
|
|
93
115
|
/// and draws text host-side but has no font registration seam, so
|
|
94
116
|
/// the face could not be honored pixel-honestly).
|
|
95
117
|
pub fn registerCanvasFont(self: *Runtime, id: canvas.FontId, ttf: []const u8) anyerror!void {
|
|
@@ -100,9 +122,27 @@ pub fn RuntimeCanvasFonts(comptime Runtime: type) type {
|
|
|
100
122
|
if (self.canvas_font_count >= max_registered_canvas_fonts) return error.FontRegistryFull;
|
|
101
123
|
|
|
102
124
|
const index = self.canvas_font_count;
|
|
103
|
-
|
|
125
|
+
// Exact-size heap copy, owned by the runtime until deinit
|
|
126
|
+
// (registration is permanent — no unregister — so this is
|
|
127
|
+
// the only allocation and the only free the registry ever
|
|
128
|
+
// makes). On-demand allocation instead of a slot pool keeps
|
|
129
|
+
// a fontless Runtime at zero font bytes.
|
|
130
|
+
// Alloc and every free (the refusal paths below, the deinit
|
|
131
|
+
// free) go through the runtime's init-frozen ownership
|
|
132
|
+
// allocator: `options.allocator` is publicly mutable and a
|
|
133
|
+
// swap between registration and teardown must never split
|
|
134
|
+
// the alloc/free identity.
|
|
135
|
+
const pooled = try self.owned_allocator.alloc(u8, ttf.len);
|
|
136
|
+
errdefer self.owned_allocator.free(pooled);
|
|
104
137
|
@memcpy(pooled, ttf);
|
|
105
|
-
const face = canvas.font_ttf.Face.parse(pooled) catch
|
|
138
|
+
const face = canvas.font_ttf.Face.parse(pooled) catch |err| switch (err) {
|
|
139
|
+
// The registration-time glyph-budget gate: refusing the
|
|
140
|
+
// face here (loudly, with its declared numbers available
|
|
141
|
+
// via `declaredGlyphMaxima`) is what keeps render-time
|
|
142
|
+
// glyph resolution total for registered ids.
|
|
143
|
+
error.FontGlyphTooComplex => return error.FontExceedsGlyphBudgets,
|
|
144
|
+
else => return error.FontParseFailed,
|
|
145
|
+
};
|
|
106
146
|
|
|
107
147
|
// Host sync BEFORE committing the slot: platforms with
|
|
108
148
|
// host-side text (measure_text_fn) must learn the face or the
|
|
@@ -120,7 +160,7 @@ pub fn RuntimeCanvasFonts(comptime Runtime: type) type {
|
|
|
120
160
|
};
|
|
121
161
|
|
|
122
162
|
self.canvas_font_faces[index] = face;
|
|
123
|
-
self.canvas_font_entries[index] = .{ .id = id, .
|
|
163
|
+
self.canvas_font_entries[index] = .{ .id = id, .bytes = pooled };
|
|
124
164
|
self.canvas_font_count = index + 1;
|
|
125
165
|
// Bind the font-aware measure provider on first registration.
|
|
126
166
|
// The runtime address is stable from here on (registration
|
|
@@ -138,9 +178,9 @@ pub fn RuntimeCanvasFonts(comptime Runtime: type) type {
|
|
|
138
178
|
}
|
|
139
179
|
|
|
140
180
|
/// The registered set as the `ReferenceFont` slice both renderers
|
|
141
|
-
/// consume, rebuilt into runtime scratch (faces
|
|
142
|
-
///
|
|
143
|
-
/// runtime's lifetime).
|
|
181
|
+
/// consume, rebuilt into runtime scratch (faces borrow each
|
|
182
|
+
/// entry's heap-owned bytes; with no unregister they stay valid
|
|
183
|
+
/// for the runtime's lifetime).
|
|
144
184
|
pub fn registeredCanvasFonts(self: *Runtime) []const canvas.ReferenceFont {
|
|
145
185
|
for (self.canvas_font_entries[0..self.canvas_font_count], 0..) |entry, index| {
|
|
146
186
|
self.canvas_font_resources_scratch[index] = .{
|
|
@@ -1134,6 +1134,21 @@ pub fn RuntimeCanvasFrames(comptime Runtime: type) type {
|
|
|
1134
1134
|
if (self.views[index].canvasRenderAnimationsActive(frame_options.timestamp_ns)) {
|
|
1135
1135
|
self.invalidateFor(.state, self.views[index].frame);
|
|
1136
1136
|
}
|
|
1137
|
+
// An armed tooltip show delay — and a running anchor-gap
|
|
1138
|
+
// transit grace — only fire on a presented frame's
|
|
1139
|
+
// timestamp, so frames must keep coming while either is
|
|
1140
|
+
// pending: the render-animation pump's policy. This
|
|
1141
|
+
// per-frame leg takes over from the FIRST invalidation,
|
|
1142
|
+
// which the intent choke point kicks the moment any
|
|
1143
|
+
// deadline arms (reconcileCanvasTooltipIntent step 5 —
|
|
1144
|
+
// a deadline armed by an event that repainted nothing
|
|
1145
|
+
// would otherwise wait forever for a frame nothing
|
|
1146
|
+
// requested). Settled shown tooltips and the warm
|
|
1147
|
+
// window need no pump: both step on journaled input
|
|
1148
|
+
// timestamps.
|
|
1149
|
+
if (self.views[index].canvasTooltipIntentArmed()) {
|
|
1150
|
+
self.invalidateFor(.state, self.views[index].frame);
|
|
1151
|
+
}
|
|
1137
1152
|
} else {
|
|
1138
1153
|
self.views[index].recordCanvasFrame(canvas_frame);
|
|
1139
1154
|
}
|
|
@@ -140,6 +140,12 @@ pub fn canvasWidgetPointerEventFromGpuInput(input_event: GpuSurfaceInputEvent) ?
|
|
|
140
140
|
.ime_set_composition,
|
|
141
141
|
.ime_commit_composition,
|
|
142
142
|
.ime_cancel_composition,
|
|
143
|
+
// Pinch is not a widget pointer gesture: it reaches the app as
|
|
144
|
+
// the raw `gpu_surface_input` event (timeline/canvas zoom is an
|
|
145
|
+
// app-level concern, not a widget press/scroll).
|
|
146
|
+
.pinch_begin,
|
|
147
|
+
.pinch_change,
|
|
148
|
+
.pinch_end,
|
|
143
149
|
=> return null,
|
|
144
150
|
};
|
|
145
151
|
return .{
|
|
@@ -163,6 +169,9 @@ pub fn canvasWidgetInputBatchesDisplayListRefresh(kind: platform.GpuSurfaceInput
|
|
|
163
169
|
.ime_set_composition,
|
|
164
170
|
.ime_commit_composition,
|
|
165
171
|
.ime_cancel_composition,
|
|
172
|
+
.pinch_begin,
|
|
173
|
+
.pinch_change,
|
|
174
|
+
.pinch_end,
|
|
166
175
|
=> true,
|
|
167
176
|
};
|
|
168
177
|
}
|
|
@@ -181,6 +190,9 @@ pub fn canvasWidgetKeyboardEventFromGpuInput(input_event: GpuSurfaceInputEvent,
|
|
|
181
190
|
.ime_set_composition,
|
|
182
191
|
.ime_commit_composition,
|
|
183
192
|
.ime_cancel_composition,
|
|
193
|
+
.pinch_begin,
|
|
194
|
+
.pinch_change,
|
|
195
|
+
.pinch_end,
|
|
184
196
|
=> return null,
|
|
185
197
|
};
|
|
186
198
|
return .{
|
|
@@ -221,6 +233,9 @@ fn canvasWidgetTextEditEventFromGpuInput(input_event: GpuSurfaceInputEvent) ?can
|
|
|
221
233
|
.pointer_move,
|
|
222
234
|
.pointer_drag,
|
|
223
235
|
.scroll,
|
|
236
|
+
.pinch_begin,
|
|
237
|
+
.pinch_change,
|
|
238
|
+
.pinch_end,
|
|
224
239
|
=> null,
|
|
225
240
|
};
|
|
226
241
|
}
|
|
@@ -207,6 +207,32 @@ 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 "registerCanvasImageBytes refuses reserved media-surface ids before decoding" {
|
|
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 fixture = [_]u8{ 255, 0, 0, 255 };
|
|
218
|
+
var encoded_buffer: [1024]u8 = undefined;
|
|
219
|
+
var writer = std.Io.Writer.fixed(&encoded_buffer);
|
|
220
|
+
try canvas.png.writeRgba8(&writer, 1, 1, &fixture);
|
|
221
|
+
const encoded = writer.buffered();
|
|
222
|
+
|
|
223
|
+
// An id inside the reserved media-surface texture namespace is
|
|
224
|
+
// refused as an invalid id — not surfaced as a codec error — and
|
|
225
|
+
// the refusal happens before the platform decoder ever runs.
|
|
226
|
+
const reserved_id: canvas.ImageId = canvas.media_surface_image_id_bit | 9;
|
|
227
|
+
try std.testing.expectError(error.InvalidImageId, harness.runtime.registerCanvasImageBytes(reserved_id, encoded));
|
|
228
|
+
try std.testing.expectEqual(@as(usize, 0), harness.null_platform.image_decode_count);
|
|
229
|
+
try std.testing.expectEqual(@as(usize, 0), harness.runtime.registeredCanvasImageCount());
|
|
230
|
+
|
|
231
|
+
// The same bytes under an ordinary id decode and register fine.
|
|
232
|
+
_ = try harness.runtime.registerCanvasImageBytes(9, encoded);
|
|
233
|
+
try std.testing.expectEqual(@as(usize, 1), harness.null_platform.image_decode_count);
|
|
234
|
+
}
|
|
235
|
+
|
|
210
236
|
// ---------------------------------------------------------------- avatar app
|
|
211
237
|
|
|
212
238
|
const avatar_canvas_label = "avatar-canvas";
|
|
@@ -28,6 +28,7 @@ const canvas = @import("canvas");
|
|
|
28
28
|
const canvas_frame_module = @import("canvas_frame.zig");
|
|
29
29
|
const canvas_limits = @import("canvas_limits.zig");
|
|
30
30
|
const effects_mod = @import("effects.zig");
|
|
31
|
+
const runtime_media_surface = @import("media_surface.zig");
|
|
31
32
|
|
|
32
33
|
pub const max_registered_canvas_images = canvas_limits.max_registered_canvas_images;
|
|
33
34
|
pub const max_registered_canvas_image_pixel_bytes = canvas_limits.max_registered_canvas_image_pixel_bytes;
|
|
@@ -78,6 +79,12 @@ pub fn RuntimeCanvasImages(comptime Runtime: type) type {
|
|
|
78
79
|
/// `max_registered_canvas_images` slots hold other ids).
|
|
79
80
|
pub fn registerCanvasImage(self: *Runtime, id: canvas.ImageId, width: usize, height: usize, rgba8: []const u8) anyerror!void {
|
|
80
81
|
if (id == 0) return error.InvalidImageId;
|
|
82
|
+
// The high bit is the media-surface texture namespace
|
|
83
|
+
// (`canvas.media_surface_image_id_bit`): producer-pushed
|
|
84
|
+
// textures and registered images share one flat id space,
|
|
85
|
+
// so a registration inside the reserved namespace is
|
|
86
|
+
// refused loudly rather than shadowed silently.
|
|
87
|
+
if ((id & canvas.media_surface_image_id_bit) != 0) return error.InvalidImageId;
|
|
81
88
|
if (width == 0 or height == 0) return error.InvalidImageDimensions;
|
|
82
89
|
const row_len = std.math.mul(usize, width, 4) catch return error.InvalidImageDimensions;
|
|
83
90
|
const byte_len = std.math.mul(usize, row_len, height) catch return error.InvalidImageDimensions;
|
|
@@ -116,8 +123,17 @@ pub fn RuntimeCanvasImages(comptime Runtime: type) type {
|
|
|
116
123
|
/// `error.UnsupportedService` (platform has no codec),
|
|
117
124
|
/// `error.ImageDecodeFailed` (undecodable bytes),
|
|
118
125
|
/// `error.ImageTooLarge` (decoded pixels over the slot bound).
|
|
126
|
+
/// `error.InvalidImageId` covers the same ids
|
|
127
|
+
/// `registerCanvasImage` refuses (0 and the reserved
|
|
128
|
+
/// media-surface namespace) and fires before any decode work.
|
|
119
129
|
pub fn registerCanvasImageBytes(self: *Runtime, id: canvas.ImageId, bytes: []const u8) anyerror!RegisteredCanvasImage {
|
|
120
130
|
if (id == 0) return error.InvalidImageId;
|
|
131
|
+
// Same reserved-namespace refusal as `registerCanvasImage`
|
|
132
|
+
// (see the comment there), checked before the decode so an
|
|
133
|
+
// unusable id never reaches the platform codec — the caller
|
|
134
|
+
// gets `error.InvalidImageId`, not a codec error, and pays
|
|
135
|
+
// no decode cost for it.
|
|
136
|
+
if ((id & canvas.media_surface_image_id_bit) != 0) return error.InvalidImageId;
|
|
121
137
|
const decoded = try self.options.platform.services.decodeImage(bytes, &canvas_image_decode_scratch.get().bytes);
|
|
122
138
|
if (decoded.rgba8.len > max_registered_canvas_image_pixel_bytes) return error.ImageTooLarge;
|
|
123
139
|
try registerCanvasImage(self, id, decoded.width, decoded.height, decoded.rgba8);
|
|
@@ -153,7 +169,11 @@ pub fn RuntimeCanvasImages(comptime Runtime: type) type {
|
|
|
153
169
|
/// The registered set as the `ReferenceImage` slice both
|
|
154
170
|
/// renderers consume, rebuilt into runtime scratch (pixels are
|
|
155
171
|
/// borrowed from the slot pool, valid until the next
|
|
156
|
-
/// register/unregister)
|
|
172
|
+
/// register/unregister), with the adopted media-surface
|
|
173
|
+
/// textures appended as `presentation_only` entries — GPU and
|
|
174
|
+
/// packet hosts upload and composite those, the deterministic
|
|
175
|
+
/// reference renderer skips them by policy (the media surface's
|
|
176
|
+
/// id-derived placeholder is what it draws instead).
|
|
157
177
|
pub fn registeredCanvasImages(self: *Runtime) []const canvas.ReferenceImage {
|
|
158
178
|
for (self.canvas_image_entries[0..self.canvas_image_count], 0..) |entry, index| {
|
|
159
179
|
self.canvas_image_resources_scratch[index] = .{
|
|
@@ -163,7 +183,11 @@ pub fn RuntimeCanvasImages(comptime Runtime: type) type {
|
|
|
163
183
|
.pixels = self.canvas_image_pixels[index][0..entry.byte_len],
|
|
164
184
|
};
|
|
165
185
|
}
|
|
166
|
-
|
|
186
|
+
const media = runtime_media_surface.RuntimeMediaSurfaces(Runtime).adoptedMediaSurfaceTextures(
|
|
187
|
+
self,
|
|
188
|
+
self.canvas_image_resources_scratch[self.canvas_image_count..],
|
|
189
|
+
);
|
|
190
|
+
return self.canvas_image_resources_scratch[0 .. self.canvas_image_count + media.len];
|
|
167
191
|
}
|
|
168
192
|
|
|
169
193
|
/// Dimensions of a registered image, or null when `id` is not
|
|
@@ -213,11 +237,13 @@ pub fn RuntimeCanvasImages(comptime Runtime: type) type {
|
|
|
213
237
|
return null;
|
|
214
238
|
}
|
|
215
239
|
|
|
216
|
-
/// Registered pixels
|
|
217
|
-
///
|
|
218
|
-
///
|
|
219
|
-
///
|
|
220
|
-
|
|
240
|
+
/// Registered pixels (or adopted media-surface textures, which
|
|
241
|
+
/// ride the same resource set) changed: force every gpu_surface
|
|
242
|
+
/// view to re-render its next frame (an image swap with an
|
|
243
|
+
/// unchanged display list would otherwise take the skip path)
|
|
244
|
+
/// and request frames so the repaint is not gated on other
|
|
245
|
+
/// input. Pub for media_surface.zig's adoption path.
|
|
246
|
+
pub fn noteCanvasImagesChanged(self: *Runtime) void {
|
|
221
247
|
const frame_methods = canvas_frame_module.RuntimeCanvasFrames(Runtime);
|
|
222
248
|
for (self.views[0..self.view_count], 0..) |*view, index| {
|
|
223
249
|
if (!view.open or view.kind != .gpu_surface) continue;
|
|
@@ -105,6 +105,31 @@ pub const max_canvas_text_layout_lines_per_view: usize = 8192;
|
|
|
105
105
|
pub const max_registered_canvas_images: usize = 16;
|
|
106
106
|
pub const max_registered_canvas_image_pixel_bytes: usize = 1024 * 1024;
|
|
107
107
|
|
|
108
|
+
// Media-surface texture channels (media_surface.zig): producer-pushed
|
|
109
|
+
// dynamic textures composited by media_surface widgets. Sized at video
|
|
110
|
+
// scale, not avatar scale — one 1080p RGBA8 frame is ~7.9 MiB, so the
|
|
111
|
+
// per-channel bound fits it exactly (8 MiB) and refuses 4K until the
|
|
112
|
+
// format axis grows real zero-copy paths; 4 concurrent channels covers
|
|
113
|
+
// a player plus a camera preview plus headroom, and a fifth acquire
|
|
114
|
+
// fails loudly (`error.MediaSurfaceChannelsExhausted`). Both bounds are
|
|
115
|
+
// VALIDATION bounds plus per-USE allocation sizes, never Runtime-struct
|
|
116
|
+
// reservations: an ADOPTED texture's buffer is one lazy frame-budget
|
|
117
|
+
// allocation from the runtime's `owned_allocator` (frozen from
|
|
118
|
+
// `Options.allocator` at init) at the entry's first adoption (freed by
|
|
119
|
+
// `Runtime.deinit`), so a runtime with no
|
|
120
|
+
// media producers carries zero media-texture bytes — an embedded pool
|
|
121
|
+
// at this bound put 4 x 8 MiB = 32 MiB in EVERY Runtime, measured on
|
|
122
|
+
// the docs wasm preview host (one Runtime per component tile, wasm
|
|
123
|
+
// linear memory never overcommits) as 137.5 -> 169.5 MB per instance
|
|
124
|
+
// before any producer existed, the registered-font-pool regression's
|
|
125
|
+
// twin. The producer-side STAGING buffers are allocated at first claim
|
|
126
|
+
// into process-lived module state and kept for the process's life —
|
|
127
|
+
// the mailbox a producer thread may touch after its runtime died,
|
|
128
|
+
// which is why they can never be freed (the effects executor's
|
|
129
|
+
// process-lifetime doctrine).
|
|
130
|
+
pub const max_media_surface_channels: usize = 4;
|
|
131
|
+
pub const max_media_surface_pixel_bytes: usize = 8 * 1024 * 1024;
|
|
132
|
+
|
|
108
133
|
// Runtime-registered font faces: TrueType bytes apps register under a
|
|
109
134
|
// caller-chosen FontId (>= canvas.min_registered_font_id) so their own
|
|
110
135
|
// typefaces resolve everywhere a font id rides — token overrides, text
|
|
@@ -116,15 +141,26 @@ pub const max_registered_canvas_image_pixel_bytes: usize = 1024 * 1024;
|
|
|
116
141
|
// so re-registering an id with different bytes would serve stale glyphs —
|
|
117
142
|
// re-use of a registered id fails loudly instead (`error.FontIdInUse`).
|
|
118
143
|
// The slot count covers a real brand set (a text family in 2-3 weights
|
|
119
|
-
// plus a display and a mono face); the per-font bound fits full
|
|
120
|
-
//
|
|
121
|
-
//
|
|
122
|
-
//
|
|
123
|
-
//
|
|
124
|
-
//
|
|
125
|
-
//
|
|
144
|
+
// plus a display and a mono face); the per-font bound fits full CJK
|
|
145
|
+
// faces — the glyph pipeline is sized for them (canvas.font_ttf budgets)
|
|
146
|
+
// and the canonical Google Fonts TrueType builds measure 9.6 MB (Noto
|
|
147
|
+
// Sans JP), 10.4 (KR), 11.9 (TC), 13.6 (Noto Serif JP), and 17.8 (Noto
|
|
148
|
+
// Sans SC), so 24 MiB covers the largest measured with ~1.4x headroom.
|
|
149
|
+
// Latin UI faces stay a few hundred KB (the bundled faces are 71/116 KB).
|
|
150
|
+
// Both bounds are VALIDATION bounds, not storage reservations: the
|
|
151
|
+
// registry heap-allocates each font's exact file size from the
|
|
152
|
+
// allocator the runtime froze at init (`Options.allocator`, captured
|
|
153
|
+
// into `Runtime.owned_allocator`) at registration (canvas_fonts.zig), so
|
|
154
|
+
// a runtime with no registered fonts carries zero font bytes. An
|
|
155
|
+
// embedded slot pool at this bound would put 8 x 24 MiB = 192 MiB in
|
|
156
|
+
// EVERY Runtime — measured on the docs wasm preview host (one Runtime
|
|
157
|
+
// per component tile, wasm linear memory never overcommits) as 137.5 ->
|
|
158
|
+
// 313.5 MB per instance before any font registered. Oversized files and
|
|
159
|
+
// a ninth font fail loudly (`error.FontTooLarge` /
|
|
160
|
+
// `error.FontRegistryFull`). The gpu-surface registration side-channel
|
|
161
|
+
// bound (`platform.max_gpu_surface_font_bytes`) pins the same value.
|
|
126
162
|
pub const max_registered_canvas_fonts: usize = 8;
|
|
127
|
-
pub const max_registered_canvas_font_bytes: usize =
|
|
163
|
+
pub const max_registered_canvas_font_bytes: usize = 24 * 1024 * 1024;
|
|
128
164
|
|
|
129
165
|
// The retained widget-tree budgets (raised 256 -> 1024; see the header
|
|
130
166
|
// comment). `automation.snapshot.max_widgets_per_view`
|