@native-sdk/cli 0.5.3 → 0.6.0
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 +91 -2
- package/build.zig +756 -5
- package/build.zig.zon +7 -0
- package/native-sdk.d.ts +19 -1
- package/package.json +9 -9
- package/packages/core/package-lock.json +2 -2
- package/packages/core/package.json +1 -1
- package/packages/core/rt/rt.zig +416 -9
- package/packages/core/sdk/core.ts +706 -5
- package/packages/core/sdk/events.ts +17 -8
- package/packages/core/src/checker.ts +305 -2
- package/packages/core/src/diagnostics.ts +12 -0
- package/packages/core/src/emitter.ts +3187 -264
- package/packages/core/src/typed_ast.ts +51 -4
- package/packages/core/src/types.ts +34 -1
- package/skill-data/native-ui/SKILL.md +42 -4
- package/skill-data/ts-core/SKILL.md +13 -3
- package/src/app_runner/root.zig +112 -10
- package/src/app_runner/ts_core_main.zig +4 -0
- package/src/automation/layout_fingerprint.zig +160 -0
- package/src/automation/protocol.zig +82 -33
- package/src/automation/root.zig +1 -0
- package/src/automation/server.zig +1 -1
- package/src/automation/snapshot.zig +68 -9
- package/src/automation/watcher.zig +1 -1
- package/src/embed/host.zig +5 -0
- package/src/embed/tests.zig +119 -1
- package/src/embed/ui_host.zig +13 -0
- package/src/platform/linux/gtk_host.c +639 -16
- package/src/platform/linux/gtk_host.h +25 -0
- package/src/platform/linux/root.zig +351 -7
- package/src/platform/macos/appkit_host.h +152 -8
- package/src/platform/macos/appkit_host.m +1816 -100
- package/src/platform/macos/cef_host.mm +372 -11
- package/src/platform/macos/root.zig +379 -11
- package/src/platform/null_platform.zig +696 -9
- package/src/platform/null_platform_tests.zig +35 -0
- package/src/platform/root.zig +42 -0
- package/src/platform/types.zig +524 -18
- package/src/platform/windows/root.zig +432 -9
- package/src/platform/windows/webview2_host.cpp +482 -45
- package/src/primitives/app_manifest/comptime_scene.zig +5 -0
- package/src/primitives/app_manifest/root.zig +1 -0
- package/src/primitives/app_manifest/types.zig +32 -0
- package/src/primitives/app_manifest/validation.zig +18 -0
- package/src/primitives/canvas/a11y_audit.zig +33 -11
- package/src/primitives/canvas/a11y_audit_tests.zig +20 -0
- package/src/primitives/canvas/drawing.zig +25 -0
- package/src/primitives/canvas/equality.zig +8 -0
- package/src/primitives/canvas/events.zig +103 -16
- package/src/primitives/canvas/frame.zig +125 -1
- package/src/primitives/canvas/layout_audit.zig +22 -5
- package/src/primitives/canvas/markdown_hostile_tests.zig +8 -4
- package/src/primitives/canvas/render_tests.zig +13 -10
- package/src/primitives/canvas/root.zig +48 -0
- package/src/primitives/canvas/terminal_box.zig +471 -0
- package/src/primitives/canvas/terminal_grid.zig +978 -0
- package/src/primitives/canvas/terminal_grid_tests.zig +1093 -0
- package/src/primitives/canvas/test_support.zig +1 -0
- package/src/primitives/canvas/tests.zig +2 -0
- package/src/primitives/canvas/text_tests.zig +39 -4
- package/src/primitives/canvas/tokens.zig +115 -12
- package/src/primitives/canvas/ui.zig +535 -12
- package/src/primitives/canvas/ui_markup.zig +253 -36
- package/src/primitives/canvas/ui_markup_binary.zig +4 -1
- package/src/primitives/canvas/ui_markup_compiled.zig +195 -9
- package/src/primitives/canvas/ui_markup_compiled_tests.zig +188 -8
- package/src/primitives/canvas/ui_markup_contract.zig +89 -6
- package/src/primitives/canvas/ui_markup_contract_tests.zig +65 -1
- package/src/primitives/canvas/ui_markup_huge_document_tests.zig +154 -0
- package/src/primitives/canvas/ui_markup_huge_model_tests.zig +1 -0
- package/src/primitives/canvas/ui_markup_reflect.zig +75 -24
- package/src/primitives/canvas/ui_markup_tests.zig +178 -9
- package/src/primitives/canvas/ui_markup_view.zig +220 -11
- package/src/primitives/canvas/ui_markup_view_tests.zig +553 -28
- package/src/primitives/canvas/ui_schema.zig +110 -17
- package/src/primitives/canvas/ui_schema_tests.zig +18 -10
- package/src/primitives/canvas/ui_tests.zig +141 -9
- package/src/primitives/canvas/widget_access.zig +28 -2
- package/src/primitives/canvas/widget_anchored_tests.zig +48 -0
- package/src/primitives/canvas/widget_invalidation.zig +81 -1
- package/src/primitives/canvas/widget_layout.zig +59 -11
- package/src/primitives/canvas/widget_layout_tests.zig +125 -4
- package/src/primitives/canvas/widget_render.zig +272 -18
- package/src/primitives/canvas/widget_render_scroll.zig +108 -27
- package/src/primitives/canvas/widget_routing.zig +59 -7
- package/src/primitives/canvas/widget_runtime.zig +23 -0
- package/src/primitives/canvas/widget_runtime_tests.zig +149 -0
- package/src/primitives/canvas/widget_semantics.zig +119 -11
- package/src/primitives/canvas/widget_semantics_tests.zig +409 -0
- package/src/primitives/canvas/widget_tree.zig +17 -0
- package/src/primitives/canvas/widgets.zig +132 -0
- package/src/root.zig +23 -0
- package/src/runtime/api.zig +76 -5
- package/src/runtime/automation_commands.zig +20 -1
- package/src/runtime/automation_snapshot.zig +25 -1
- package/src/runtime/automation_widget_dispatch.zig +73 -8
- package/src/runtime/bridge_payload.zig +8 -0
- package/src/runtime/bridge_responses.zig +5 -0
- package/src/runtime/builtin_bridge.zig +9 -4
- package/src/runtime/canvas_font_tests.zig +439 -2
- package/src/runtime/canvas_fonts.zig +61 -6
- package/src/runtime/canvas_frame.zig +62 -7
- package/src/runtime/canvas_frame_animation_tests.zig +5 -4
- package/src/runtime/canvas_frame_helpers.zig +190 -1
- package/src/runtime/canvas_frame_invalidation_tests.zig +531 -0
- package/src/runtime/canvas_frame_patch_tests.zig +161 -10
- package/src/runtime/canvas_frame_retained_tests.zig +5 -2
- package/src/runtime/canvas_image_tests.zig +195 -0
- package/src/runtime/canvas_images.zig +45 -12
- package/src/runtime/canvas_widget_accessibility_tests.zig +1 -1
- package/src/runtime/canvas_widget_clipboard_tests.zig +40 -0
- package/src/runtime/canvas_widget_context_menu.zig +269 -32
- package/src/runtime/canvas_widget_context_menu_tests.zig +640 -14
- package/src/runtime/canvas_widget_display.zig +1 -1
- package/src/runtime/canvas_widget_event_tests.zig +1823 -0
- package/src/runtime/canvas_widget_events.zig +240 -24
- package/src/runtime/canvas_widget_runtime.zig +213 -29
- package/src/runtime/canvas_widget_scroll_driver_tests.zig +170 -7
- package/src/runtime/canvas_widget_scroll_drivers.zig +151 -17
- package/src/runtime/canvas_widget_scroll_tests.zig +435 -23
- package/src/runtime/canvas_widget_state.zig +6 -0
- package/src/runtime/canvas_widget_text_tests.zig +1 -1
- package/src/runtime/core.zig +131 -13
- package/src/runtime/effects.zig +8136 -180
- package/src/runtime/effects_channel_tests.zig +3519 -0
- package/src/runtime/effects_fetch_tests.zig +89 -1
- package/src/runtime/effects_file_tests.zig +41 -1
- package/src/runtime/effects_image_tests.zig +1304 -0
- package/src/runtime/effects_pty_tests.zig +1362 -0
- package/src/runtime/effects_tests.zig +167 -9
- package/src/runtime/effects_video_tests.zig +3609 -0
- package/src/runtime/flow.zig +42 -4
- package/src/runtime/gpu_surface_events.zig +473 -13
- package/src/runtime/media_surface.zig +116 -11
- package/src/runtime/media_surface_tests.zig +61 -0
- package/src/runtime/pty.zig +1252 -0
- package/src/runtime/pty_windows.zig +1780 -0
- package/src/runtime/root.zig +36 -0
- package/src/runtime/runtime_event_tests.zig +20 -1
- package/src/runtime/session_blobs.zig +689 -0
- package/src/runtime/session_journal.zig +432 -62
- package/src/runtime/session_record.zig +43 -2
- package/src/runtime/session_replay.zig +556 -20
- package/src/runtime/session_tests.zig +2087 -1
- package/src/runtime/shell_layout.zig +7 -0
- package/src/runtime/terminal_session.zig +1569 -0
- package/src/runtime/terminal_session_tests.zig +450 -0
- package/src/runtime/terminal_vt_ghostty.zig +15 -0
- package/src/runtime/terminal_vt_stub.zig +13 -0
- package/src/runtime/testdata/fonts/NotoSansSC-Receipt.ttf +0 -0
- package/src/runtime/testdata/fonts/OFL.txt +93 -0
- package/src/runtime/tests.zig +8 -0
- package/src/runtime/ts_core_host.zig +1320 -45
- package/src/runtime/ts_core_host_tests.zig +1100 -1
- package/src/runtime/ts_ui_app.zig +23 -5
- package/src/runtime/ui_app.zig +2444 -69
- package/src/runtime/ui_app_tests.zig +3171 -744
- package/src/runtime/ui_app_virtual_variable_tests.zig +4 -2
- package/src/runtime/ui_app_window_tests.zig +736 -0
- package/src/runtime/view.zig +190 -2
- package/src/runtime/view_widget_scroll.zig +218 -68
- package/src/runtime/view_widget_text.zig +11 -2
- package/src/runtime/view_widget_tree.zig +111 -3
- package/src/runtime/window_command_bridge_tests.zig +117 -0
- package/src/runtime/window_storage.zig +77 -2
- package/src/runtime/window_view_runtime.zig +34 -2
- package/src/runtime/window_views.zig +62 -1
- package/src/terminal_session_tests_root.zig +15 -0
- package/src/tooling/manifest.zig +75 -0
- package/src/tooling/raw_manifest.zig +2 -0
- package/src/tooling/templates.zig +244 -8
|
@@ -511,23 +511,25 @@ test "rebuild dirty bounds derive from the patch edit script, not the window" {
|
|
|
511
511
|
try std.testing.expectEqual(CanvasPresentationMode.gpu_packet, baseline.mode);
|
|
512
512
|
try std.testing.expect(harness.runtime.views[0].canvas_packet_baseline_valid);
|
|
513
513
|
|
|
514
|
-
// Rebuild with ONE color change: dirty is that command's rect
|
|
515
|
-
//
|
|
514
|
+
// Rebuild with ONE color change: dirty is that command's rect plus
|
|
515
|
+
// the one-device-pixel AA bleed allowance, the present is a
|
|
516
|
+
// one-upsert patch, and the wire scissor matches.
|
|
516
517
|
rects[13].fill_rect.fill = .{ .color = canvas.Color.rgb8(37, 99, 235) };
|
|
517
518
|
_ = try harness.runtime.setCanvasDisplayList(1, "canvas", .{ .commands = &rects });
|
|
518
519
|
const toggled = try presentFrame(harness, &buffers, 61);
|
|
519
520
|
try std.testing.expectEqual(CanvasPresentationMode.gpu_packet, toggled.mode);
|
|
520
|
-
try std.testing.expectEqualDeep(buildGrid.rectAt(13), toggled.frame.dirty_bounds.?);
|
|
521
|
+
try std.testing.expectEqualDeep(buildGrid.rectAt(13).inflate(geometry.InsetsF.all(1)), toggled.frame.dirty_bounds.?);
|
|
521
522
|
try std.testing.expectEqual(platform.GpuPresentPacketMode.patch, harness.runtime.views[0].gpu_present_packet_mode);
|
|
522
523
|
try std.testing.expectEqual(@as(usize, 1), harness.runtime.views[0].gpu_present_patch_upsert_count);
|
|
523
524
|
|
|
524
|
-
// Rebuild that MOVES a command: dirty covers old and new extents
|
|
525
|
+
// Rebuild that MOVES a command: dirty covers old and new extents
|
|
526
|
+
// (plus the bleed).
|
|
525
527
|
const moved_from = buildGrid.rectAt(20);
|
|
526
528
|
const moved_to = geometry.RectF.init(moved_from.x + 60, moved_from.y + 30, 30, 18);
|
|
527
529
|
rects[20].fill_rect.rect = moved_to;
|
|
528
530
|
_ = try harness.runtime.setCanvasDisplayList(1, "canvas", .{ .commands = &rects });
|
|
529
531
|
const moved = try presentFrame(harness, &buffers, 62);
|
|
530
|
-
try std.testing.expectEqualDeep(geometry.RectF.unionWith(moved_from, moved_to), moved.frame.dirty_bounds.?);
|
|
532
|
+
try std.testing.expectEqualDeep(geometry.RectF.unionWith(moved_from, moved_to).inflate(geometry.InsetsF.all(1)), moved.frame.dirty_bounds.?);
|
|
531
533
|
|
|
532
534
|
// Identical rebuild (revision bumps, content does not): the edit
|
|
533
535
|
// script is empty, so nothing presents at all.
|
|
@@ -585,17 +587,166 @@ test "rebuild dirty bounds derive from the edit script on small command lists to
|
|
|
585
587
|
try std.testing.expectEqual(CanvasPresentationMode.gpu_packet, baseline.mode);
|
|
586
588
|
try std.testing.expect(harness.runtime.views[0].canvas_packet_baseline_valid);
|
|
587
589
|
|
|
588
|
-
// Rebuild with ONE color change: dirty is that command's rect
|
|
589
|
-
// the window, and the present is a one-upsert
|
|
590
|
+
// Rebuild with ONE color change: dirty is that command's rect plus
|
|
591
|
+
// the AA bleed, not the window, and the present is a one-upsert
|
|
592
|
+
// patch.
|
|
590
593
|
rects[7].fill_rect.fill = .{ .color = canvas.Color.rgb8(37, 99, 235) };
|
|
591
594
|
_ = try harness.runtime.setCanvasDisplayList(1, "canvas", .{ .commands = &rects });
|
|
592
595
|
const toggled = try presentFrame(harness, &buffers, 71);
|
|
593
596
|
try std.testing.expectEqual(CanvasPresentationMode.gpu_packet, toggled.mode);
|
|
594
|
-
try std.testing.expectEqualDeep(buildRow.rectAt(7), toggled.frame.dirty_bounds.?);
|
|
597
|
+
try std.testing.expectEqualDeep(buildRow.rectAt(7).inflate(geometry.InsetsF.all(1)), toggled.frame.dirty_bounds.?);
|
|
595
598
|
try std.testing.expectEqual(platform.GpuPresentPacketMode.patch, harness.runtime.views[0].gpu_present_packet_mode);
|
|
596
599
|
try std.testing.expectEqual(@as(usize, 1), harness.runtime.views[0].gpu_present_patch_upsert_count);
|
|
597
600
|
}
|
|
598
601
|
|
|
602
|
+
fn reflowPillCommand(id: canvas.ObjectId, rect: geometry.RectF) canvas.CanvasCommand {
|
|
603
|
+
return .{ .fill_rounded_rect = .{
|
|
604
|
+
.id = id,
|
|
605
|
+
.rect = rect,
|
|
606
|
+
.radius = canvas.Radius.all(rect.height * 0.5),
|
|
607
|
+
.fill = .{ .color = canvas.Color.rgb8(148, 163, 184) },
|
|
608
|
+
} };
|
|
609
|
+
}
|
|
610
|
+
|
|
611
|
+
fn expectDirtyCovers(dirty: geometry.RectF, painted: geometry.RectF) !void {
|
|
612
|
+
// The damage region must cover the painted extent of the rect plus
|
|
613
|
+
// the one-device-pixel AA bleed hosts can ink past its bounds.
|
|
614
|
+
const required = painted.normalized().inflate(geometry.InsetsF.all(1));
|
|
615
|
+
const epsilon: f32 = 1e-4;
|
|
616
|
+
try std.testing.expect(dirty.minX() <= required.minX() + epsilon);
|
|
617
|
+
try std.testing.expect(dirty.minY() <= required.minY() + epsilon);
|
|
618
|
+
try std.testing.expect(dirty.maxX() >= required.maxX() - epsilon);
|
|
619
|
+
try std.testing.expect(dirty.maxY() >= required.maxY() - epsilon);
|
|
620
|
+
}
|
|
621
|
+
|
|
622
|
+
fn expectDirtyRectsCover(rects: []const geometry.RectF, painted: geometry.RectF) !void {
|
|
623
|
+
// Refined dirty rect lists are what retained hosts CLEAR: at least
|
|
624
|
+
// one rect must cover the painted extent plus its AA bleed, or the
|
|
625
|
+
// vacated fringe survives the repaint.
|
|
626
|
+
const required = painted.normalized().inflate(geometry.InsetsF.all(1));
|
|
627
|
+
const epsilon: f32 = 1e-4;
|
|
628
|
+
for (rects) |rect| {
|
|
629
|
+
if (rect.minX() <= required.minX() + epsilon and
|
|
630
|
+
rect.minY() <= required.minY() + epsilon and
|
|
631
|
+
rect.maxX() >= required.maxX() - epsilon and
|
|
632
|
+
rect.maxY() >= required.maxY() - epsilon) return;
|
|
633
|
+
}
|
|
634
|
+
return error.DirtyRectsMissPaintedExtent;
|
|
635
|
+
}
|
|
636
|
+
|
|
637
|
+
test "reflow damage covers vacated pixels plus the anti-aliasing bleed" {
|
|
638
|
+
// The list-detail regression shape: a selection change reflows a
|
|
639
|
+
// row of rounded pills at fractional coordinates — pills get
|
|
640
|
+
// removed, shrunk, moved, and replaced under new keys. Each
|
|
641
|
+
// incremental present's damage must cover the OLD painted extent
|
|
642
|
+
// (bounds plus the one-device-pixel AA bleed host rasterizers ink
|
|
643
|
+
// past them) as well as the new one; anything less leaves stale
|
|
644
|
+
// fringes at the old pills' edges.
|
|
645
|
+
var app_state: PatchHarnessApp = .{};
|
|
646
|
+
const harness = try createPatchHarness(&app_state);
|
|
647
|
+
defer harness.destroy(std.testing.allocator);
|
|
648
|
+
var buffers = try PresentBuffers.init(std.testing.allocator);
|
|
649
|
+
defer buffers.deinit(std.testing.allocator);
|
|
650
|
+
|
|
651
|
+
const anchor = canvas.CanvasCommand{ .fill_rect = .{
|
|
652
|
+
.id = 100,
|
|
653
|
+
.rect = geometry.RectF.init(4, 4, 24, 12),
|
|
654
|
+
.fill = .{ .color = canvas.Color.rgb8(51, 65, 85) },
|
|
655
|
+
} };
|
|
656
|
+
const pill_wide = geometry.RectF.init(30.4, 60.6, 120.2, 24.8);
|
|
657
|
+
const pill_second = geometry.RectF.init(160.9, 60.6, 80.3, 24.8);
|
|
658
|
+
const pill_shrunk = geometry.RectF.init(30.4, 60.6, 70.1, 20.3);
|
|
659
|
+
const pill_moved = geometry.RectF.init(90.7, 130.2, 70.1, 20.3);
|
|
660
|
+
const pill_replacement = geometry.RectF.init(42.5, 132.9, 96.6, 22.4);
|
|
661
|
+
const pillAt = reflowPillCommand;
|
|
662
|
+
|
|
663
|
+
// Baseline: two pills; the first present is necessarily full.
|
|
664
|
+
_ = try harness.runtime.setCanvasDisplayList(1, "canvas", .{ .commands = &.{ anchor, pillAt(201, pill_wide), pillAt(202, pill_second) } });
|
|
665
|
+
const baseline = try presentFrame(harness, &buffers, 80);
|
|
666
|
+
try std.testing.expectEqual(CanvasPresentationMode.gpu_packet, baseline.mode);
|
|
667
|
+
try std.testing.expect(harness.runtime.views[0].canvas_packet_baseline_valid);
|
|
668
|
+
|
|
669
|
+
// Removed: the second pill's arm turns off. Damage must cover the
|
|
670
|
+
// vacated pill plus its bleed.
|
|
671
|
+
_ = try harness.runtime.setCanvasDisplayList(1, "canvas", .{ .commands = &.{ anchor, pillAt(201, pill_wide) } });
|
|
672
|
+
const removed = try presentFrame(harness, &buffers, 81);
|
|
673
|
+
try std.testing.expect(!removed.frame.full_repaint);
|
|
674
|
+
try expectDirtyCovers(removed.frame.dirty_bounds.?, pill_second);
|
|
675
|
+
|
|
676
|
+
// Shrunk: the surviving pill narrows and shortens. Damage must
|
|
677
|
+
// cover the OLD, larger extent.
|
|
678
|
+
_ = try harness.runtime.setCanvasDisplayList(1, "canvas", .{ .commands = &.{ anchor, pillAt(201, pill_shrunk) } });
|
|
679
|
+
const shrunk = try presentFrame(harness, &buffers, 82);
|
|
680
|
+
try std.testing.expect(!shrunk.frame.full_repaint);
|
|
681
|
+
try expectDirtyCovers(shrunk.frame.dirty_bounds.?, pill_wide);
|
|
682
|
+
try expectDirtyCovers(shrunk.frame.dirty_bounds.?, pill_shrunk);
|
|
683
|
+
|
|
684
|
+
// Moved: same pill, new position. Damage covers both poses.
|
|
685
|
+
_ = try harness.runtime.setCanvasDisplayList(1, "canvas", .{ .commands = &.{ anchor, pillAt(201, pill_moved) } });
|
|
686
|
+
const moved = try presentFrame(harness, &buffers, 83);
|
|
687
|
+
try std.testing.expect(!moved.frame.full_repaint);
|
|
688
|
+
try expectDirtyCovers(moved.frame.dirty_bounds.?, pill_shrunk);
|
|
689
|
+
try expectDirtyCovers(moved.frame.dirty_bounds.?, pill_moved);
|
|
690
|
+
|
|
691
|
+
// Keyed replacement: the subtree swaps — the old pill's key
|
|
692
|
+
// vanishes, a new key mounts elsewhere. Damage covers the evicted
|
|
693
|
+
// extent and the mounted one, and the refined rect list (what a
|
|
694
|
+
// retained host actually clears) covers each with its bleed.
|
|
695
|
+
_ = try harness.runtime.setCanvasDisplayList(1, "canvas", .{ .commands = &.{ anchor, pillAt(301, pill_replacement), pillAt(302, geometry.RectF.init(200.2, 20.7, 60.4, 18.6)) } });
|
|
696
|
+
const replaced = try presentFrame(harness, &buffers, 84);
|
|
697
|
+
try std.testing.expect(!replaced.frame.full_repaint);
|
|
698
|
+
try expectDirtyCovers(replaced.frame.dirty_bounds.?, pill_moved);
|
|
699
|
+
try expectDirtyCovers(replaced.frame.dirty_bounds.?, pill_replacement);
|
|
700
|
+
if (replaced.frame.dirtyRects().len > 0) {
|
|
701
|
+
try expectDirtyRectsCover(replaced.frame.dirtyRects(), pill_moved);
|
|
702
|
+
try expectDirtyRectsCover(replaced.frame.dirtyRects(), pill_replacement);
|
|
703
|
+
}
|
|
704
|
+
}
|
|
705
|
+
|
|
706
|
+
test "a coarser presentation scale widens reflow damage to its device pixel" {
|
|
707
|
+
// Frames plan at the surface scale, but a present may override the
|
|
708
|
+
// EFFECTIVE scale downward (`packet_scale`/`pixel_scale`). The AA
|
|
709
|
+
// bleed allowance was folded in at plan scale, so the present must
|
|
710
|
+
// widen the damage to the coarser scale's device pixel — half a
|
|
711
|
+
// point of allowance where the host's raster apron spans a full
|
|
712
|
+
// point reopens the stale fringe.
|
|
713
|
+
var app_state: PatchHarnessApp = .{};
|
|
714
|
+
const harness = try createPatchHarness(&app_state);
|
|
715
|
+
defer harness.destroy(std.testing.allocator);
|
|
716
|
+
var buffers = try PresentBuffers.init(std.testing.allocator);
|
|
717
|
+
defer buffers.deinit(std.testing.allocator);
|
|
718
|
+
|
|
719
|
+
const anchor = canvas.CanvasCommand{ .fill_rect = .{
|
|
720
|
+
.id = 100,
|
|
721
|
+
.rect = geometry.RectF.init(4, 4, 24, 12),
|
|
722
|
+
.fill = .{ .color = canvas.Color.rgb8(51, 65, 85) },
|
|
723
|
+
} };
|
|
724
|
+
const pill = geometry.RectF.init(30.4, 60.6, 120.2, 24.8);
|
|
725
|
+
const presentAtScaleOne = struct {
|
|
726
|
+
fn present(h: anytype, b: *PresentBuffers, frame_index: u64) !CanvasPresentationResult {
|
|
727
|
+
return h.runtime.presentNextCanvasFrame(1, "canvas", .{
|
|
728
|
+
.frame_index = frame_index,
|
|
729
|
+
.timestamp_ns = frame_index * 16_000,
|
|
730
|
+
.surface_size = geometry.SizeF.init(patch_surface_width, patch_surface_height),
|
|
731
|
+
.scale = 2,
|
|
732
|
+
}, canvasFrameScratchStorage(&h.runtime), b.gpu_commands, b.packet_buffer, b.pixels, b.scratch, canvas.Color.rgb8(15, 23, 42), 1);
|
|
733
|
+
}
|
|
734
|
+
}.present;
|
|
735
|
+
|
|
736
|
+
_ = try harness.runtime.setCanvasDisplayList(1, "canvas", .{ .commands = &.{ anchor, reflowPillCommand(401, pill) } });
|
|
737
|
+
const baseline = try presentAtScaleOne(harness, &buffers, 90);
|
|
738
|
+
try std.testing.expectEqual(CanvasPresentationMode.gpu_packet, baseline.mode);
|
|
739
|
+
|
|
740
|
+
// Removed pill: the damage must carry a FULL point of allowance —
|
|
741
|
+
// one device pixel at the presented scale (1), not the plan
|
|
742
|
+
// scale's (2) half point.
|
|
743
|
+
_ = try harness.runtime.setCanvasDisplayList(1, "canvas", .{ .commands = &.{anchor} });
|
|
744
|
+
const removed = try presentAtScaleOne(harness, &buffers, 91);
|
|
745
|
+
try std.testing.expectEqual(CanvasPresentationMode.gpu_packet, removed.mode);
|
|
746
|
+
try std.testing.expect(!removed.frame.full_repaint);
|
|
747
|
+
try expectDirtyCovers(removed.frame.dirty_bounds.?, pill);
|
|
748
|
+
}
|
|
749
|
+
|
|
599
750
|
test "a host that refuses patches gets a full resync in the same frame" {
|
|
600
751
|
var app_state: PatchHarnessApp = .{};
|
|
601
752
|
const harness = try createPatchHarness(&app_state);
|
|
@@ -1066,8 +1217,8 @@ test "pixel presents adopt a dirty-refinement baseline only for opted-in hosts a
|
|
|
1066
1217
|
.scale = 1,
|
|
1067
1218
|
}, canvasFrameScratchStorage(&harness.runtime), buffers.pixels, buffers.scratch, canvas.Color.rgb8(15, 23, 42));
|
|
1068
1219
|
try std.testing.expect(!toggled.full_repaint);
|
|
1069
|
-
try std.testing.expectEqualDeep(buildGrid.rectAt(13), toggled.dirty_bounds.?);
|
|
1070
|
-
try std.testing.expectEqualDeep(buildGrid.rectAt(13), harness.null_platform.gpu_surface_present_dirty_bounds.?);
|
|
1220
|
+
try std.testing.expectEqualDeep(buildGrid.rectAt(13).inflate(geometry.InsetsF.all(1)), toggled.dirty_bounds.?);
|
|
1221
|
+
try std.testing.expectEqualDeep(buildGrid.rectAt(13).inflate(geometry.InsetsF.all(1)), harness.null_platform.gpu_surface_present_dirty_bounds.?);
|
|
1071
1222
|
|
|
1072
1223
|
// A packet present against the pixel-adopted mirror resyncs FULL —
|
|
1073
1224
|
// the patch gate refuses it even though the baseline is valid.
|
|
@@ -308,7 +308,9 @@ test "runtime canvas frame plan computes incremental dirty from previous display
|
|
|
308
308
|
try std.testing.expectEqual(@as(usize, 1), frame.changes.len);
|
|
309
309
|
try std.testing.expectEqual(canvas.DiffKind.changed, frame.changes[0].kind);
|
|
310
310
|
try std.testing.expectEqual(@as(?canvas.ObjectId, 1), frame.changes[0].id);
|
|
311
|
-
|
|
311
|
+
// Old extent (0,0,40,40) union new (20,0,40,40), inflated by the
|
|
312
|
+
// one-device-pixel AA bleed and clipped to the surface.
|
|
313
|
+
try std.testing.expectEqualDeep(geometry.RectF.init(0, 0, 61, 41), frame.dirty_bounds.?);
|
|
312
314
|
}
|
|
313
315
|
|
|
314
316
|
test "runtime next canvas frame tracks presented state and resource cache" {
|
|
@@ -396,7 +398,8 @@ test "runtime next canvas frame tracks presented state and resource cache" {
|
|
|
396
398
|
try std.testing.expect(moved_frame.requiresRender());
|
|
397
399
|
try std.testing.expectEqual(@as(usize, 1), moved_frame.changes.len);
|
|
398
400
|
try std.testing.expectEqual(canvas.DiffKind.changed, moved_frame.changes[0].kind);
|
|
399
|
-
|
|
401
|
+
// Both extents' union, inflated by the AA bleed and surface-clipped.
|
|
402
|
+
try std.testing.expectEqualDeep(geometry.RectF.init(0, 0, 61, 41), moved_frame.dirty_bounds.?);
|
|
400
403
|
try std.testing.expectEqual(@as(usize, 1), moved_frame.resource_cache_plan.retainCount());
|
|
401
404
|
try std.testing.expectEqual(@as(u64, 2), harness.runtime.views[0].presented_canvas_revision);
|
|
402
405
|
}
|
|
@@ -233,6 +233,201 @@ test "registerCanvasImageBytes refuses reserved media-surface ids before decodin
|
|
|
233
233
|
try std.testing.expectEqual(@as(usize, 1), harness.null_platform.image_decode_count);
|
|
234
234
|
}
|
|
235
235
|
|
|
236
|
+
// ------------------------------------------------------ lazy slot buffers
|
|
237
|
+
|
|
238
|
+
/// A started GPU harness whose runtime froze `runtime_allocator` at
|
|
239
|
+
/// init. The runtime's `owned_allocator` captures `Options.allocator`
|
|
240
|
+
/// in `initAt` and mutating `options.allocator` on a live runtime
|
|
241
|
+
/// deliberately retargets nothing, so a test allocator must be injected
|
|
242
|
+
/// through the real capture site: re-initialize the runtime in place
|
|
243
|
+
/// with the harness's own platform and trace wiring (nothing is
|
|
244
|
+
/// heap-owned yet, so the re-init leaks nothing).
|
|
245
|
+
fn startedGpuHarnessWithRuntimeAllocator(gpa: std.mem.Allocator, runtime_allocator: std.mem.Allocator) !*TestHarness() {
|
|
246
|
+
const harness = try startedGpuHarness(gpa);
|
|
247
|
+
errdefer harness.destroy(gpa);
|
|
248
|
+
core.Runtime.initAt(&harness.runtime, .{
|
|
249
|
+
.platform = harness.null_platform.platform(),
|
|
250
|
+
.trace_sink = harness.trace_sink.sink(),
|
|
251
|
+
.allocator = runtime_allocator,
|
|
252
|
+
.environ = std.testing.environ,
|
|
253
|
+
});
|
|
254
|
+
// Match TestHarness().init: tests fail loud on handler/update errors.
|
|
255
|
+
harness.runtime.dispatch_error_policy = .propagate;
|
|
256
|
+
return harness;
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
/// The registered pixels for `id`, looked up through the same
|
|
260
|
+
/// `ReferenceImage` set the renderers consume — compaction correctness
|
|
261
|
+
/// is judged where the pixels are actually read.
|
|
262
|
+
fn registeredPixelsById(runtime: *core.Runtime, id: canvas.ImageId) ?[]const u8 {
|
|
263
|
+
for (runtime.registeredCanvasImages()) |resource| {
|
|
264
|
+
if (resource.id == id) return resource.pixels;
|
|
265
|
+
}
|
|
266
|
+
return null;
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
test "a fresh runtime allocates zero registered-image bytes until the first registration" {
|
|
270
|
+
// Count every runtime-allocator call: construction, startup, and
|
|
271
|
+
// view creation perform NONE — slot buffer storage is on-demand at
|
|
272
|
+
// a slot's first registration. (The regression pinned here: an
|
|
273
|
+
// embedded pool put 16 x 1 MiB = 16 MiB in every Runtime before
|
|
274
|
+
// any image existed; the media-texture-pool regression's twin.)
|
|
275
|
+
var counting = std.testing.FailingAllocator.init(std.testing.allocator, .{});
|
|
276
|
+
const harness = try startedGpuHarnessWithRuntimeAllocator(std.testing.allocator, counting.allocator());
|
|
277
|
+
defer harness.destroy(std.testing.allocator);
|
|
278
|
+
var app_state: RegistryApp = .{};
|
|
279
|
+
try harness.start(app_state.app());
|
|
280
|
+
_ = try harness.runtime.createView(.{
|
|
281
|
+
.window_id = 1,
|
|
282
|
+
.label = "canvas",
|
|
283
|
+
.kind = .gpu_surface,
|
|
284
|
+
.frame = geometry.RectF.init(0, 0, 240, 140),
|
|
285
|
+
});
|
|
286
|
+
try std.testing.expectEqual(@as(usize, 0), counting.allocations);
|
|
287
|
+
|
|
288
|
+
// The first registration is the first allocation: exactly one,
|
|
289
|
+
// exactly the slot budget (freed by Runtime.deinit through
|
|
290
|
+
// harness.destroy — the leak-checked test allocator backs it).
|
|
291
|
+
const red = [_]u8{ 255, 0, 0, 255 };
|
|
292
|
+
try harness.runtime.registerCanvasImage(1, 1, 1, &red);
|
|
293
|
+
try std.testing.expectEqual(@as(usize, 1), counting.allocations);
|
|
294
|
+
try std.testing.expectEqual(canvas_limits.max_registered_canvas_image_pixel_bytes, counting.allocated_bytes);
|
|
295
|
+
|
|
296
|
+
// Replacing an id's pixels reuses the slot buffer: the count stays
|
|
297
|
+
// one — the allocation is per used slot, not per registration.
|
|
298
|
+
const blue = [_]u8{ 0, 0, 255, 255 };
|
|
299
|
+
try harness.runtime.registerCanvasImage(1, 1, 1, &blue);
|
|
300
|
+
try std.testing.expectEqual(@as(usize, 1), counting.allocations);
|
|
301
|
+
|
|
302
|
+
// A second id claims a second slot: one more allocation.
|
|
303
|
+
try harness.runtime.registerCanvasImage(2, 1, 1, &red);
|
|
304
|
+
try std.testing.expectEqual(@as(usize, 2), counting.allocations);
|
|
305
|
+
|
|
306
|
+
// Unregister keeps vacated buffers for reuse (deinit is the only
|
|
307
|
+
// free), so churn never touches the allocator again: the footprint
|
|
308
|
+
// is bounded by the high-water slot count.
|
|
309
|
+
try std.testing.expect(harness.runtime.unregisterCanvasImage(1));
|
|
310
|
+
try std.testing.expect(harness.runtime.unregisterCanvasImage(2));
|
|
311
|
+
try harness.runtime.registerCanvasImage(3, 1, 1, &blue);
|
|
312
|
+
try harness.runtime.registerCanvasImage(4, 1, 1, &red);
|
|
313
|
+
try std.testing.expectEqual(@as(usize, 2), counting.allocations);
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
test "image slot buffer ownership freezes at init: a mutated options.allocator sees zero activity" {
|
|
317
|
+
// The hazard pinned here: `Runtime.options` is public and mutable,
|
|
318
|
+
// so if the lazy slot allocation and deinit's free both read
|
|
319
|
+
// `options.allocator` LIVE, swapping it between registration and
|
|
320
|
+
// deinit frees through the wrong allocator — silent UB. Ownership
|
|
321
|
+
// must freeze into `owned_allocator` at init instead.
|
|
322
|
+
var frozen = std.testing.FailingAllocator.init(std.testing.allocator, .{});
|
|
323
|
+
const harness = try startedGpuHarnessWithRuntimeAllocator(std.testing.allocator, frozen.allocator());
|
|
324
|
+
defer harness.destroy(std.testing.allocator);
|
|
325
|
+
var app_state: RegistryApp = .{};
|
|
326
|
+
try harness.start(app_state.app());
|
|
327
|
+
const red = [_]u8{ 255, 0, 0, 255 };
|
|
328
|
+
try harness.runtime.registerCanvasImage(7, 1, 1, &red);
|
|
329
|
+
try std.testing.expectEqual(@as(usize, 1), frozen.allocations);
|
|
330
|
+
|
|
331
|
+
// Sabotage: swap options.allocator AFTER the registration
|
|
332
|
+
// allocated. fail_index = 0 poisons the swapped-in allocator (any
|
|
333
|
+
// allocation through it refuses), and its counters pin that deinit
|
|
334
|
+
// routes NOTHING here — neither an alloc nor, critically, the free.
|
|
335
|
+
var poisoned = std.testing.FailingAllocator.init(std.testing.allocator, .{ .fail_index = 0 });
|
|
336
|
+
harness.runtime.options.allocator = poisoned.allocator();
|
|
337
|
+
|
|
338
|
+
harness.runtime.deinit();
|
|
339
|
+
try std.testing.expectEqual(@as(usize, 1), frozen.deallocations);
|
|
340
|
+
try std.testing.expectEqual(canvas_limits.max_registered_canvas_image_pixel_bytes, frozen.freed_bytes);
|
|
341
|
+
try std.testing.expectEqual(@as(usize, 0), poisoned.allocations);
|
|
342
|
+
try std.testing.expectEqual(@as(usize, 0), poisoned.deallocations);
|
|
343
|
+
try std.testing.expectEqual(@as(usize, 0), poisoned.freed_bytes);
|
|
344
|
+
// harness.destroy's second deinit finds the buffers already
|
|
345
|
+
// returned (deinit resets them to empty) — no double free through
|
|
346
|
+
// either allocator.
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
test "unregister compacts by pointer swap: surviving pixels stay intact and vacated buffers are reused" {
|
|
350
|
+
var counting = std.testing.FailingAllocator.init(std.testing.allocator, .{});
|
|
351
|
+
const harness = try startedGpuHarnessWithRuntimeAllocator(std.testing.allocator, counting.allocator());
|
|
352
|
+
defer harness.destroy(std.testing.allocator);
|
|
353
|
+
var app_state: RegistryApp = .{};
|
|
354
|
+
try harness.start(app_state.app());
|
|
355
|
+
|
|
356
|
+
const colors = [_][4]u8{
|
|
357
|
+
.{ 255, 0, 0, 255 },
|
|
358
|
+
.{ 0, 255, 0, 255 },
|
|
359
|
+
.{ 0, 0, 255, 255 },
|
|
360
|
+
.{ 255, 255, 0, 255 },
|
|
361
|
+
};
|
|
362
|
+
for (colors, 1..) |color, id| {
|
|
363
|
+
try harness.runtime.registerCanvasImage(id, 1, 1, &color);
|
|
364
|
+
}
|
|
365
|
+
try std.testing.expectEqual(@as(usize, 4), counting.allocations);
|
|
366
|
+
|
|
367
|
+
// Removing a middle id compacts the last entry into its slot; every
|
|
368
|
+
// survivor's pixels must read back exactly through the renderer set.
|
|
369
|
+
try std.testing.expect(harness.runtime.unregisterCanvasImage(2));
|
|
370
|
+
try std.testing.expectEqual(@as(usize, 3), harness.runtime.registeredCanvasImageCount());
|
|
371
|
+
try std.testing.expect(registeredPixelsById(&harness.runtime, 2) == null);
|
|
372
|
+
try std.testing.expectEqualSlices(u8, &colors[0], registeredPixelsById(&harness.runtime, 1).?);
|
|
373
|
+
try std.testing.expectEqualSlices(u8, &colors[2], registeredPixelsById(&harness.runtime, 3).?);
|
|
374
|
+
try std.testing.expectEqualSlices(u8, &colors[3], registeredPixelsById(&harness.runtime, 4).?);
|
|
375
|
+
|
|
376
|
+
// A second compaction swaps again: the moved entry from the first
|
|
377
|
+
// pass moves once more and its pixels still hold.
|
|
378
|
+
try std.testing.expect(harness.runtime.unregisterCanvasImage(1));
|
|
379
|
+
try std.testing.expectEqual(@as(usize, 2), harness.runtime.registeredCanvasImageCount());
|
|
380
|
+
try std.testing.expectEqualSlices(u8, &colors[2], registeredPixelsById(&harness.runtime, 3).?);
|
|
381
|
+
try std.testing.expectEqualSlices(u8, &colors[3], registeredPixelsById(&harness.runtime, 4).?);
|
|
382
|
+
|
|
383
|
+
// Re-registering into the vacated slots reuses their parked buffers:
|
|
384
|
+
// the allocation count never moves past the high-water mark, and the
|
|
385
|
+
// fresh pixels land next to the untouched survivors.
|
|
386
|
+
const teal = [_]u8{ 0, 128, 128, 255 };
|
|
387
|
+
const gray = [_]u8{ 90, 90, 90, 255 };
|
|
388
|
+
try harness.runtime.registerCanvasImage(5, 1, 1, &teal);
|
|
389
|
+
try harness.runtime.registerCanvasImage(6, 1, 1, &gray);
|
|
390
|
+
try std.testing.expectEqual(@as(usize, 4), counting.allocations);
|
|
391
|
+
try std.testing.expectEqual(@as(usize, 4), harness.runtime.registeredCanvasImageCount());
|
|
392
|
+
try std.testing.expectEqualSlices(u8, &teal, registeredPixelsById(&harness.runtime, 5).?);
|
|
393
|
+
try std.testing.expectEqualSlices(u8, &gray, registeredPixelsById(&harness.runtime, 6).?);
|
|
394
|
+
try std.testing.expectEqualSlices(u8, &colors[2], registeredPixelsById(&harness.runtime, 3).?);
|
|
395
|
+
try std.testing.expectEqualSlices(u8, &colors[3], registeredPixelsById(&harness.runtime, 4).?);
|
|
396
|
+
}
|
|
397
|
+
|
|
398
|
+
test "a failed slot-buffer allocation refuses cleanly and a retry succeeds after memory heals" {
|
|
399
|
+
var counting = std.testing.FailingAllocator.init(std.testing.allocator, .{});
|
|
400
|
+
const harness = try startedGpuHarnessWithRuntimeAllocator(std.testing.allocator, counting.allocator());
|
|
401
|
+
defer harness.destroy(std.testing.allocator);
|
|
402
|
+
var app_state: RegistryApp = .{};
|
|
403
|
+
try harness.start(app_state.app());
|
|
404
|
+
|
|
405
|
+
const red = [_]u8{ 255, 0, 0, 255 };
|
|
406
|
+
const blue = [_]u8{ 0, 0, 255, 255 };
|
|
407
|
+
try harness.runtime.registerCanvasImage(1, 1, 1, &red);
|
|
408
|
+
|
|
409
|
+
// The next slot's lazy allocation fails: the registration refuses
|
|
410
|
+
// with the honest allocator error and the registry is EXACTLY as it
|
|
411
|
+
// was — the earlier id intact, the failed id absent, no committed
|
|
412
|
+
// slot without pixels.
|
|
413
|
+
counting.fail_index = counting.alloc_index;
|
|
414
|
+
try std.testing.expectError(error.OutOfMemory, harness.runtime.registerCanvasImage(2, 1, 1, &blue));
|
|
415
|
+
try std.testing.expectEqual(@as(usize, 1), harness.runtime.registeredCanvasImageCount());
|
|
416
|
+
try std.testing.expect(harness.runtime.registeredCanvasImage(2) == null);
|
|
417
|
+
try std.testing.expectEqualSlices(u8, &red, registeredPixelsById(&harness.runtime, 1).?);
|
|
418
|
+
|
|
419
|
+
// Replacing an ALREADY-registered id needs no allocation, so it
|
|
420
|
+
// still succeeds while memory is exhausted.
|
|
421
|
+
try harness.runtime.registerCanvasImage(1, 1, 1, &blue);
|
|
422
|
+
try std.testing.expectEqualSlices(u8, &blue, registeredPixelsById(&harness.runtime, 1).?);
|
|
423
|
+
|
|
424
|
+
// Memory recovers: the same registration retries and lands.
|
|
425
|
+
counting.fail_index = std.math.maxInt(usize);
|
|
426
|
+
try harness.runtime.registerCanvasImage(2, 1, 1, &blue);
|
|
427
|
+
try std.testing.expectEqual(@as(usize, 2), harness.runtime.registeredCanvasImageCount());
|
|
428
|
+
try std.testing.expectEqualSlices(u8, &blue, registeredPixelsById(&harness.runtime, 2).?);
|
|
429
|
+
}
|
|
430
|
+
|
|
236
431
|
// ---------------------------------------------------------------- avatar app
|
|
237
432
|
|
|
238
433
|
const avatar_canvas_label = "avatar-canvas";
|
|
@@ -5,8 +5,12 @@
|
|
|
5
5
|
//!
|
|
6
6
|
//! The registry is the missing bridge between fetched/decoded bytes and
|
|
7
7
|
//! the canvas image pipeline, which was already id+fingerprint based end
|
|
8
|
-
//! to end: `registerCanvasImage` copies pixels into a bounded
|
|
9
|
-
//! runtime-owned
|
|
8
|
+
//! to end: `registerCanvasImage` copies pixels into a bounded set of
|
|
9
|
+
//! runtime-owned slot buffers (each one lazy slot-budget allocation
|
|
10
|
+
//! from the runtime's init-frozen `owned_allocator` at the slot's first
|
|
11
|
+
//! use, freed only by `Runtime.deinit` — a runtime that never registers
|
|
12
|
+
//! an image allocates nothing), and the frame planner threads the
|
|
13
|
+
//! registered set
|
|
10
14
|
//! into `CanvasFrameOptions.image_resources` for every view — the CPU
|
|
11
15
|
//! reference renderer (presentation, screenshots, goldens) and the GPU
|
|
12
16
|
//! packet planner (upload/retain/evict actions keyed by pixel
|
|
@@ -34,7 +38,7 @@ pub const max_registered_canvas_images = canvas_limits.max_registered_canvas_ima
|
|
|
34
38
|
pub const max_registered_canvas_image_pixel_bytes = canvas_limits.max_registered_canvas_image_pixel_bytes;
|
|
35
39
|
|
|
36
40
|
/// One registered image's metadata; pixels live in the runtime's slot
|
|
37
|
-
///
|
|
41
|
+
/// buffer at the same index.
|
|
38
42
|
pub const CanvasImageEntry = struct {
|
|
39
43
|
id: canvas.ImageId = 0,
|
|
40
44
|
width: usize = 0,
|
|
@@ -76,7 +80,11 @@ pub fn RuntimeCanvasImages(comptime Runtime: type) type {
|
|
|
76
80
|
/// dimensions or a pixel slice that is not exactly
|
|
77
81
|
/// `width * height * 4`), `error.ImageTooLarge` (over the
|
|
78
82
|
/// per-image slot bound), `error.ImageRegistryFull` (all
|
|
79
|
-
/// `max_registered_canvas_images` slots hold other ids)
|
|
83
|
+
/// `max_registered_canvas_images` slots hold other ids),
|
|
84
|
+
/// `error.OutOfMemory` (the slot's pixel buffer — one lazy
|
|
85
|
+
/// slot-budget heap allocation at the slot's first use — could
|
|
86
|
+
/// not be allocated; the registry is unchanged and the same
|
|
87
|
+
/// registration can be retried once memory recovers).
|
|
80
88
|
pub fn registerCanvasImage(self: *Runtime, id: canvas.ImageId, width: usize, height: usize, rgba8: []const u8) anyerror!void {
|
|
81
89
|
if (id == 0) return error.InvalidImageId;
|
|
82
90
|
// The high bit is the media-surface texture namespace
|
|
@@ -93,10 +101,26 @@ pub fn RuntimeCanvasImages(comptime Runtime: type) type {
|
|
|
93
101
|
|
|
94
102
|
const index = findCanvasImageIndex(self, id) orelse blk: {
|
|
95
103
|
if (self.canvas_image_count >= max_registered_canvas_images) return error.ImageRegistryFull;
|
|
96
|
-
|
|
97
|
-
self.canvas_image_count += 1;
|
|
98
|
-
break :blk index;
|
|
104
|
+
break :blk self.canvas_image_count;
|
|
99
105
|
};
|
|
106
|
+
if (self.canvas_image_pixels[index].len == 0) {
|
|
107
|
+
// The slot's pixel buffer, allocated LAZILY at the
|
|
108
|
+
// slot's first registration (one slot-budget block from
|
|
109
|
+
// the runtime's FROZEN `owned_allocator` — never the
|
|
110
|
+
// live `options.allocator`, which is public and mutable,
|
|
111
|
+
// so a swap between this allocation and `Runtime.deinit`'s
|
|
112
|
+
// free must not split the alloc/free pair across
|
|
113
|
+
// allocators). Re-registrations and unregister/register
|
|
114
|
+
// churn reuse slot buffers, so a runtime allocates at
|
|
115
|
+
// most once per high-water slot; a runtime that never
|
|
116
|
+
// registers an image allocates nothing — an embedded
|
|
117
|
+
// pool at the budget was 16 MiB in every Runtime, the
|
|
118
|
+
// media-texture-pool regression's twin. This is the only
|
|
119
|
+
// failable step past validation and it runs BEFORE any
|
|
120
|
+
// registry mutation, so an OOM refusal leaves the
|
|
121
|
+
// registry exactly as it was and the caller can retry.
|
|
122
|
+
self.canvas_image_pixels[index] = try self.owned_allocator.alloc(u8, max_registered_canvas_image_pixel_bytes);
|
|
123
|
+
}
|
|
100
124
|
@memcpy(self.canvas_image_pixels[index][0..byte_len], rgba8);
|
|
101
125
|
self.canvas_image_entries[index] = .{
|
|
102
126
|
.id = id,
|
|
@@ -104,6 +128,7 @@ pub fn RuntimeCanvasImages(comptime Runtime: type) type {
|
|
|
104
128
|
.height = height,
|
|
105
129
|
.byte_len = byte_len,
|
|
106
130
|
};
|
|
131
|
+
if (index == self.canvas_image_count) self.canvas_image_count += 1;
|
|
107
132
|
// No pixel push here: GPU packet hosts receive the bytes
|
|
108
133
|
// through the binary upload side-channel when a packet's
|
|
109
134
|
// upload cache action first references the new content
|
|
@@ -149,13 +174,21 @@ pub fn RuntimeCanvasImages(comptime Runtime: type) type {
|
|
|
149
174
|
const last = self.canvas_image_count - 1;
|
|
150
175
|
if (index != last) {
|
|
151
176
|
self.canvas_image_entries[index] = self.canvas_image_entries[last];
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
177
|
+
// Slot buffers are whole-budget heap blocks, so
|
|
178
|
+
// compaction swaps the POINTERS — the last entry's
|
|
179
|
+
// pixels move to `index` without copying a byte, and
|
|
180
|
+
// the freed id's buffer parks on the vacated last slot.
|
|
181
|
+
std.mem.swap([]u8, &self.canvas_image_pixels[index], &self.canvas_image_pixels[last]);
|
|
156
182
|
}
|
|
157
183
|
self.canvas_image_entries[last] = .{};
|
|
158
184
|
self.canvas_image_count = last;
|
|
185
|
+
// The vacated slot KEEPS its buffer for reuse: like the
|
|
186
|
+
// media-surface texture pool, `Runtime.deinit` is the only
|
|
187
|
+
// free — one ownership story for every buffer, no
|
|
188
|
+
// conditional lifetime to reason about. Unregister/register
|
|
189
|
+
// churn (avatar refresh loops) never touches the allocator
|
|
190
|
+
// again, and the footprint stays bounded by the high-water
|
|
191
|
+
// slot count, never lifetime registrations.
|
|
159
192
|
// Best-effort drop of the platform-side texture: platforms
|
|
160
193
|
// without the upload seam report UnsupportedService, and a
|
|
161
194
|
// failed removal only costs the host a stale (unreferenced)
|
|
@@ -168,7 +201,7 @@ pub fn RuntimeCanvasImages(comptime Runtime: type) type {
|
|
|
168
201
|
|
|
169
202
|
/// The registered set as the `ReferenceImage` slice both
|
|
170
203
|
/// renderers consume, rebuilt into runtime scratch (pixels are
|
|
171
|
-
/// borrowed from the slot
|
|
204
|
+
/// borrowed from the slot buffers, valid until the next
|
|
172
205
|
/// register/unregister), with the adopted media-surface
|
|
173
206
|
/// textures appended as `presentation_only` entries — GPU and
|
|
174
207
|
/// packet hosts upload and composite those, the deterministic
|
|
@@ -940,7 +940,7 @@ test "runtime publishes canvas widget accessibility snapshots to platform" {
|
|
|
940
940
|
} });
|
|
941
941
|
try std.testing.expect(runtime.dispatchErrors().len > errors_before_invalid);
|
|
942
942
|
try std.testing.expectEqualStrings("InvalidCommand", runtime.dispatchErrors()[runtime.dispatchErrors().len - 1].error_name);
|
|
943
|
-
try std.testing.expectEqualStrings("widget_accessibility_action", runtime.dispatchErrors()[runtime.dispatchErrors().len - 1].event);
|
|
943
|
+
try std.testing.expectEqualStrings("widget_accessibility_action", runtime.dispatchErrors()[runtime.dispatchErrors().len - 1].event());
|
|
944
944
|
try std.testing.expectEqualStrings("Search", platform_state.nodes[3].text_value);
|
|
945
945
|
|
|
946
946
|
try runtime.dispatchPlatformEvent(app_state.app(), .{ .widget_accessibility_action = .{
|
|
@@ -168,6 +168,46 @@ test "keyboard-only selection (shift+arrows) feeds copy" {
|
|
|
168
168
|
try std.testing.expectEqualStrings("ry", try harness.runtime.readClipboard(&clipboard_buffer));
|
|
169
169
|
}
|
|
170
170
|
|
|
171
|
+
test "a focused terminal copies its emulator selection" {
|
|
172
|
+
var app_state: ClipboardTestApp = .{};
|
|
173
|
+
const app = app_state.app();
|
|
174
|
+
const harness = try createClipboardHarness(app);
|
|
175
|
+
defer harness.destroy(std.testing.allocator);
|
|
176
|
+
|
|
177
|
+
var grid = canvas.TerminalGrid{
|
|
178
|
+
.background = canvas.Color.rgba(0, 0, 0, 1),
|
|
179
|
+
.foreground = canvas.Color.rgba(1, 1, 1, 1),
|
|
180
|
+
.cursor_color = canvas.Color.rgba(1, 1, 1, 1),
|
|
181
|
+
.selection_color = canvas.Color.rgba(0, 0.5, 1, 1),
|
|
182
|
+
.screen_text = "alpha beta",
|
|
183
|
+
.selection_text = "beta",
|
|
184
|
+
.selection_active = true,
|
|
185
|
+
};
|
|
186
|
+
const terminal = canvas.Widget{
|
|
187
|
+
.id = 2,
|
|
188
|
+
.kind = .terminal,
|
|
189
|
+
.frame = geometry.RectF.init(12, 16, 200, 80),
|
|
190
|
+
.terminal = .{ .pty = 7, .grid = &grid },
|
|
191
|
+
};
|
|
192
|
+
var nodes: [2]canvas.WidgetLayoutNode = undefined;
|
|
193
|
+
const layout = try canvas.layoutWidgetTree(.{ .kind = .stack, .children = &.{terminal} }, geometry.RectF.init(0, 0, 320, 200), &nodes);
|
|
194
|
+
_ = try harness.runtime.setCanvasWidgetLayout(1, "canvas", layout);
|
|
195
|
+
|
|
196
|
+
try harness.runtime.dispatchPlatformEvent(app, pointerInput(.pointer_down, 40, 40));
|
|
197
|
+
try harness.runtime.dispatchPlatformEvent(app, keyInput("c", cmd));
|
|
198
|
+
|
|
199
|
+
var clipboard_buffer: [64]u8 = undefined;
|
|
200
|
+
try std.testing.expectEqualStrings("beta", try harness.runtime.readClipboard(&clipboard_buffer));
|
|
201
|
+
|
|
202
|
+
// An active whitespace-only selection owns Copy too: its trimmed
|
|
203
|
+
// text is empty, so it clears rather than falling through to some
|
|
204
|
+
// unrelated selection in the view.
|
|
205
|
+
grid.selection_text = "";
|
|
206
|
+
try harness.runtime.writeClipboard("stale");
|
|
207
|
+
try harness.runtime.dispatchPlatformEvent(app, keyInput("c", cmd));
|
|
208
|
+
try std.testing.expectEqualStrings("", try harness.runtime.readClipboard(&clipboard_buffer));
|
|
209
|
+
}
|
|
210
|
+
|
|
171
211
|
test "a multi-line paste into a single-line field strips line breaks; a textarea keeps them" {
|
|
172
212
|
var app_state: ClipboardTestApp = .{};
|
|
173
213
|
const app = app_state.app();
|