@native-sdk/cli 0.5.4 → 0.6.1
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 +50 -1
- package/build.zig +588 -32
- package/build.zig.zon +7 -0
- package/native-sdk.d.ts +3 -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 +280 -8
- package/packages/core/sdk/core.ts +481 -2
- 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 +599 -3
- package/packages/core/src/typed_ast.ts +51 -4
- package/packages/core/src/types.ts +34 -1
- package/skill-data/native-ui/SKILL.md +39 -2
- package/skill-data/ts-core/SKILL.md +4 -2
- package/src/app_runner/root.zig +32 -10
- 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/ui_host.zig +13 -0
- package/src/platform/linux/gtk_host.c +527 -13
- package/src/platform/linux/gtk_host.h +25 -0
- package/src/platform/linux/root.zig +280 -7
- package/src/platform/macos/appkit_host.h +104 -6
- package/src/platform/macos/appkit_host.m +1368 -74
- package/src/platform/macos/cef_host.mm +110 -1
- package/src/platform/macos/root.zig +287 -7
- package/src/platform/null_platform.zig +398 -4
- package/src/platform/null_platform_tests.zig +35 -0
- package/src/platform/root.zig +9 -0
- package/src/platform/types.zig +386 -14
- package/src/platform/windows/root.zig +298 -9
- package/src/platform/windows/webview2_host.cpp +330 -5
- 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 +1 -0
- package/src/primitives/canvas/text_tests.zig +39 -4
- package/src/primitives/canvas/tokens.zig +115 -12
- package/src/primitives/canvas/ui.zig +524 -5
- package/src/primitives/canvas/ui_markup.zig +195 -2
- package/src/primitives/canvas/ui_markup_compiled.zig +172 -1
- package/src/primitives/canvas/ui_markup_compiled_tests.zig +133 -8
- package/src/primitives/canvas/ui_markup_contract.zig +88 -5
- package/src/primitives/canvas/ui_markup_contract_tests.zig +39 -1
- 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 +149 -0
- package/src/primitives/canvas/ui_markup_view.zig +191 -0
- package/src/primitives/canvas/ui_markup_view_tests.zig +403 -19
- package/src/primitives/canvas/ui_schema.zig +97 -17
- package/src/primitives/canvas/ui_schema_tests.zig +18 -11
- 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 +16 -0
- package/src/runtime/api.zig +76 -6
- 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 +1 -0
- 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_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 +268 -26
- 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 +73 -2
- package/src/runtime/effects.zig +6389 -54
- package/src/runtime/effects_channel_tests.zig +3519 -0
- package/src/runtime/effects_pty_tests.zig +1362 -0
- package/src/runtime/effects_tests.zig +14 -9
- package/src/runtime/effects_video_tests.zig +3609 -0
- package/src/runtime/flow.zig +25 -4
- package/src/runtime/gpu_surface_events.zig +475 -15
- 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 +25 -0
- package/src/runtime/runtime_event_tests.zig +20 -1
- package/src/runtime/session_journal.zig +367 -61
- package/src/runtime/session_record.zig +16 -0
- package/src/runtime/session_replay.zig +395 -11
- package/src/runtime/session_tests.zig +114 -19
- 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/tests.zig +6 -0
- package/src/runtime/ts_core_host.zig +980 -140
- package/src/runtime/ts_core_host_tests.zig +1059 -1
- package/src/runtime/ts_ui_app.zig +16 -5
- package/src/runtime/ui_app.zig +2338 -67
- 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 +268 -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_storage.zig +45 -2
- package/src/runtime/window_view_runtime.zig +34 -2
- package/src/runtime/window_views.zig +1 -0
- package/src/terminal_session_tests_root.zig +15 -0
- package/src/tooling/templates.zig +25 -7
|
@@ -16,6 +16,7 @@ pub const normalizedCanvasPresentationScale = canvas_frame_helpers.normalizedCan
|
|
|
16
16
|
pub const canvasFramePixelSize = canvas_frame_helpers.canvasFramePixelSize;
|
|
17
17
|
pub const canvasColorToRgba8 = canvas_frame_helpers.canvasColorToRgba8;
|
|
18
18
|
pub const clippedCanvasDirtyBounds = canvas_frame_helpers.clippedCanvasDirtyBounds;
|
|
19
|
+
pub const bleedAlignedCanvasDirtyBounds = canvas_frame_helpers.bleedAlignedCanvasDirtyBounds;
|
|
19
20
|
pub const unionRects = canvas_frame_helpers.unionRects;
|
|
20
21
|
pub const canvasWidgetPointerEventFromGpuInput = canvas_frame_helpers.canvasWidgetPointerEventFromGpuInput;
|
|
21
22
|
pub const canvasWidgetInputBatchesDisplayListRefresh = canvas_frame_helpers.canvasWidgetInputBatchesDisplayListRefresh;
|
|
@@ -23,6 +24,7 @@ pub const canvasWidgetKeyboardEventFromGpuInput = canvas_frame_helpers.canvasWid
|
|
|
23
24
|
pub const canvasWidgetTextInputEventFromGpuInput = canvas_frame_helpers.canvasWidgetTextInputEventFromGpuInput;
|
|
24
25
|
pub const canvasWidgetEscapeKey = canvas_frame_helpers.canvasWidgetEscapeKey;
|
|
25
26
|
pub const canvasWidgetKeyboardModifiers = canvas_frame_helpers.canvasWidgetKeyboardModifiers;
|
|
27
|
+
pub const gpuInputHasTextCommandModifier = canvas_frame_helpers.gpuInputHasTextCommandModifier;
|
|
26
28
|
pub const mergeCanvasRenderOverrides = canvas_frame_helpers.mergeCanvasRenderOverrides;
|
|
27
29
|
pub const findCanvasRenderOverrideIndex = canvas_frame_helpers.findCanvasRenderOverrideIndex;
|
|
28
30
|
pub const canvasRenderOverrideNoop = canvas_frame_helpers.canvasRenderOverrideNoop;
|
|
@@ -252,10 +254,14 @@ pub fn RuntimeCanvasFrames(comptime Runtime: type) type {
|
|
|
252
254
|
packet_json_buffer: []u8,
|
|
253
255
|
packet_scale: ?f32,
|
|
254
256
|
) anyerror!canvas.CanvasGpuPacket {
|
|
255
|
-
|
|
257
|
+
var canvas_frame = try self.nextCanvasFrame(window_id, label, options, storage);
|
|
256
258
|
recordCanvasClearColor(self, window_id, label, clear_color);
|
|
259
|
+
const presentation_scale = normalizedCanvasPresentationScale(packet_scale, canvas_frame.scale);
|
|
260
|
+
// Widen BEFORE the packet build so the scissor-culled
|
|
261
|
+
// command subset rides the widened scissor.
|
|
262
|
+
widenCanvasFrameDirtyForPresentationScale(&canvas_frame, presentation_scale);
|
|
257
263
|
var packet = try canvas_frame.gpuPacket(output);
|
|
258
|
-
packet.scale =
|
|
264
|
+
packet.scale = presentation_scale;
|
|
259
265
|
if (!packet.requiresRender()) return packet;
|
|
260
266
|
uploadCanvasPacketImages(self, packet) catch |err| {
|
|
261
267
|
if (err == error.UnsupportedService) {
|
|
@@ -300,11 +306,16 @@ pub fn RuntimeCanvasFrames(comptime Runtime: type) type {
|
|
|
300
306
|
clear_color: canvas.Color,
|
|
301
307
|
pixel_scale: ?f32,
|
|
302
308
|
) anyerror!CanvasPresentationResult {
|
|
303
|
-
|
|
309
|
+
var canvas_frame = try self.nextCanvasFrame(window_id, label, options, storage);
|
|
304
310
|
recordCanvasClearColor(self, window_id, label, clear_color);
|
|
305
311
|
if (!canvas_frame.requiresRender()) {
|
|
306
312
|
return .{ .frame = canvas_frame, .mode = .skipped };
|
|
307
313
|
}
|
|
314
|
+
const presentation_scale = normalizedCanvasPresentationScale(pixel_scale, canvas_frame.scale);
|
|
315
|
+
// Widen BEFORE the packet build (and the pixel fallback below)
|
|
316
|
+
// so the scissor-culled command subset rides the widened
|
|
317
|
+
// scissor.
|
|
318
|
+
widenCanvasFrameDirtyForPresentationScale(&canvas_frame, presentation_scale);
|
|
308
319
|
|
|
309
320
|
const services = self.options.platform.services;
|
|
310
321
|
const packet_service_available = services.present_gpu_surface_packet_fn != null or
|
|
@@ -312,7 +323,7 @@ pub fn RuntimeCanvasFrames(comptime Runtime: type) type {
|
|
|
312
323
|
if (gpu_commands.len > 0 and packet_json_buffer.len > 0) {
|
|
313
324
|
if (packet_service_available) {
|
|
314
325
|
var packet = try canvas_frame.gpuPacket(gpu_commands);
|
|
315
|
-
packet.scale =
|
|
326
|
+
packet.scale = presentation_scale;
|
|
316
327
|
const result = CanvasPresentationResult{
|
|
317
328
|
.frame = canvas_frame,
|
|
318
329
|
.mode = .gpu_packet,
|
|
@@ -1031,6 +1042,21 @@ pub fn RuntimeCanvasFrames(comptime Runtime: type) type {
|
|
|
1031
1042
|
const dirty_bounds = if (full_repaint)
|
|
1032
1043
|
canvasFullRepaintBounds(frame_options.surface_size, render_plan.bounds)
|
|
1033
1044
|
else dirty: {
|
|
1045
|
+
// Every incremental dirty rect leaves here through
|
|
1046
|
+
// `bleedAlignedCanvasDirtyBounds`: one whole device
|
|
1047
|
+
// pixel of AA bleed folded in on integer device
|
|
1048
|
+
// boundaries, then snapped outward onto the pixel grid
|
|
1049
|
+
// with edges whose stored-f32 round trip lands exactly
|
|
1050
|
+
// on those boundaries. The bleed covers the PAINTED
|
|
1051
|
+
// extent of what changed (host rasterizers ink up to a
|
|
1052
|
+
// device pixel past a command's bounds) so vacated
|
|
1053
|
+
// content cannot strand a stale fringe; the snap keeps
|
|
1054
|
+
// the cull region identical to the cleared pixels so a
|
|
1055
|
+
// fractional edge cannot erase an unchanged neighbor's
|
|
1056
|
+
// boundary coverage without repainting it. Applied to
|
|
1057
|
+
// the finalized rects (the refined union, each refined
|
|
1058
|
+
// cluster, and the summary fallback), which covers
|
|
1059
|
+
// every contribution: dilation distributes over union.
|
|
1034
1060
|
const overrides_dirty = unionRects(render_override_dirty_bounds, render_animation_dirty_bounds);
|
|
1035
1061
|
// Msg rebuilds: the presented summary records ids and
|
|
1036
1062
|
// bounds but not content, so a rebuild marks every keyed
|
|
@@ -1066,12 +1092,12 @@ pub fn RuntimeCanvasFrames(comptime Runtime: type) type {
|
|
|
1066
1092
|
if (canvasPacketPatchDirtyBounds(&self.views[index], current)) |patch_dirty| {
|
|
1067
1093
|
var refined = patch_dirty;
|
|
1068
1094
|
if (overrides_dirty) |overrides_rect| refined.add(overrides_rect);
|
|
1069
|
-
const clipped =
|
|
1095
|
+
const clipped = bleedAlignedCanvasDirtyBounds(refined.bounds, frame_options.scale, 1, frame_options.surface_size);
|
|
1070
1096
|
// A list of one rect adds nothing over the
|
|
1071
1097
|
// scissor; ship it only when it splits.
|
|
1072
1098
|
if (clipped != null and refined.rect_count > 1) {
|
|
1073
1099
|
for (refined.rects[0..refined.rect_count]) |rect| {
|
|
1074
|
-
const clipped_rect =
|
|
1100
|
+
const clipped_rect = bleedAlignedCanvasDirtyBounds(rect, frame_options.scale, 1, frame_options.surface_size) orelse continue;
|
|
1075
1101
|
dirty_rects[dirty_rect_count] = clipped_rect;
|
|
1076
1102
|
dirty_rect_count += 1;
|
|
1077
1103
|
}
|
|
@@ -1081,7 +1107,7 @@ pub fn RuntimeCanvasFrames(comptime Runtime: type) type {
|
|
|
1081
1107
|
}
|
|
1082
1108
|
}
|
|
1083
1109
|
}
|
|
1084
|
-
break :dirty
|
|
1110
|
+
break :dirty bleedAlignedCanvasDirtyBounds(unionRects(canvasDirtyBoundsFromChanges(changes), overrides_dirty), frame_options.scale, 1, frame_options.surface_size);
|
|
1085
1111
|
};
|
|
1086
1112
|
|
|
1087
1113
|
const canvas_frame = canvas.CanvasFrame{
|
|
@@ -1245,6 +1271,35 @@ pub fn RuntimeCanvasFrames(comptime Runtime: type) type {
|
|
|
1245
1271
|
};
|
|
1246
1272
|
}
|
|
1247
1273
|
|
|
1274
|
+
/// Rework a planned frame's incremental damage for the present's
|
|
1275
|
+
/// EFFECTIVE scale. Two obligations when the scales differ:
|
|
1276
|
+
/// - A COARSER presentation scale carries a larger device pixel than
|
|
1277
|
+
/// the plan's, so the plan's one-plan-pixel AA bleed allowance falls
|
|
1278
|
+
/// short of one PRESENTED pixel and the fringe reopens (planned at
|
|
1279
|
+
/// scale 2, presented at scale 1: half a point of allowance where
|
|
1280
|
+
/// the host's raster apron spans a full point).
|
|
1281
|
+
/// - ANY differing scale changes the pixel grid — the grids need not
|
|
1282
|
+
/// nest (plan 1, present 1.5: a plan-aligned edge at 11 points sits
|
|
1283
|
+
/// mid-pixel at 1.5×) — so the damage re-snaps outward on the
|
|
1284
|
+
/// presentation grid, keeping the cull region identical to the
|
|
1285
|
+
/// pixels the present clears.
|
|
1286
|
+
/// One re-run of the bleed+snap at the presentation scale settles
|
|
1287
|
+
/// both: a whole presented device pixel of allowance on presented
|
|
1288
|
+
/// boundaries. No-op for full repaints, matching scales, and frames
|
|
1289
|
+
/// with nothing dirty.
|
|
1290
|
+
fn widenCanvasFrameDirtyForPresentationScale(canvas_frame: *canvas.CanvasFrame, presentation_scale: f32) void {
|
|
1291
|
+
if (canvas_frame.full_repaint) return;
|
|
1292
|
+
if (presentation_scale == canvas_frame.scale) return;
|
|
1293
|
+
canvas_frame.dirty_bounds = bleedAlignedCanvasDirtyBounds(canvas_frame.dirty_bounds, presentation_scale, 1, canvas_frame.surface_size);
|
|
1294
|
+
var kept: usize = 0;
|
|
1295
|
+
for (canvas_frame.dirty_rects[0..canvas_frame.dirty_rect_count]) |rect| {
|
|
1296
|
+
const widened = bleedAlignedCanvasDirtyBounds(rect, presentation_scale, 1, canvas_frame.surface_size) orelse continue;
|
|
1297
|
+
canvas_frame.dirty_rects[kept] = widened;
|
|
1298
|
+
kept += 1;
|
|
1299
|
+
}
|
|
1300
|
+
canvas_frame.dirty_rect_count = if (kept < 2) 0 else kept;
|
|
1301
|
+
}
|
|
1302
|
+
|
|
1248
1303
|
/// What to record when a packet attempt fails: the reason plus the
|
|
1249
1304
|
/// overflow byte math or the offending command kind, whichever applies.
|
|
1250
1305
|
const CanvasPacketRefusal = struct {
|
|
@@ -127,8 +127,9 @@ test "runtime next canvas frame applies render override dirty regions" {
|
|
|
127
127
|
try std.testing.expectEqual(@as(usize, 0), moved_frame.changes.len);
|
|
128
128
|
try std.testing.expectEqual(@as(f32, 0.5), moved_frame.render_plan.commands[0].opacity);
|
|
129
129
|
try std.testing.expectEqualDeep(canvas.Affine.translate(10, 0), moved_frame.render_plan.commands[0].transform);
|
|
130
|
-
|
|
131
|
-
try std.testing.expectEqualDeep(geometry.RectF.init(0, 0,
|
|
130
|
+
// Override extent union, inflated by the AA bleed and clipped.
|
|
131
|
+
try std.testing.expectEqualDeep(geometry.RectF.init(0, 0, 21, 11), moved_frame.dirty_bounds.?);
|
|
132
|
+
try std.testing.expectEqualDeep(geometry.RectF.init(0, 0, 21, 11), harness.runtime.views[0].canvas_frame_dirty_bounds.?);
|
|
132
133
|
|
|
133
134
|
const clean_frame = try harness.runtime.nextCanvasFrame(1, "canvas", .{
|
|
134
135
|
.frame_index = 3,
|
|
@@ -246,7 +247,7 @@ test "runtime schedules canvas render animations without display list rebuild" {
|
|
|
246
247
|
try std.testing.expectEqual(@as(usize, 0), mid_frame.changes.len);
|
|
247
248
|
try std.testing.expectEqual(@as(f32, 0.5), mid_frame.render_plan.commands[0].opacity);
|
|
248
249
|
try std.testing.expectEqualDeep(canvas.Affine.translate(5, 0), mid_frame.render_plan.commands[0].transform);
|
|
249
|
-
try std.testing.expectEqualDeep(geometry.RectF.init(0, 0,
|
|
250
|
+
try std.testing.expectEqualDeep(geometry.RectF.init(0, 0, 16, 11), mid_frame.dirty_bounds.?);
|
|
250
251
|
try std.testing.expect(harness.runtime.invalidated);
|
|
251
252
|
|
|
252
253
|
harness.runtime.invalidated = false;
|
|
@@ -258,7 +259,7 @@ test "runtime schedules canvas render animations without display list rebuild" {
|
|
|
258
259
|
try std.testing.expect(final_frame.requiresRender());
|
|
259
260
|
try std.testing.expectEqual(@as(f32, 1), final_frame.render_plan.commands[0].opacity);
|
|
260
261
|
try std.testing.expectEqualDeep(canvas.Affine.identity(), final_frame.render_plan.commands[0].transform);
|
|
261
|
-
try std.testing.expectEqualDeep(geometry.RectF.init(0, 0,
|
|
262
|
+
try std.testing.expectEqualDeep(geometry.RectF.init(0, 0, 16, 11), final_frame.dirty_bounds.?);
|
|
262
263
|
try std.testing.expect(!harness.runtime.invalidated);
|
|
263
264
|
try std.testing.expectEqual(@as(usize, 0), (try harness.runtime.canvasRenderAnimations(1, "canvas")).len);
|
|
264
265
|
try std.testing.expectEqual(@as(usize, 0), runtimeViewCanvasFrameRenderOverrides(&harness.runtime.views[0]).len);
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
const std = @import("std");
|
|
2
|
+
const builtin = @import("builtin");
|
|
2
3
|
const geometry = @import("geometry");
|
|
3
4
|
const canvas = @import("canvas");
|
|
4
5
|
const platform = @import("../platform/root.zig");
|
|
@@ -112,6 +113,178 @@ pub fn clippedCanvasDirtyBounds(bounds: ?geometry.RectF, surface_size: geometry.
|
|
|
112
113
|
return if (normalized.isEmpty()) null else normalized;
|
|
113
114
|
}
|
|
114
115
|
|
|
116
|
+
/// Snap an incremental dirty rect OUTWARD to the device-pixel grid at
|
|
117
|
+
/// `scale`, folding in `bleed_pixels` whole device pixels of
|
|
118
|
+
/// anti-aliasing bleed allowance on every side. The allowance covers
|
|
119
|
+
/// the PAINTED extent of changed content — host rasterizers ink up to
|
|
120
|
+
/// a device pixel past a command's bounds (antialiased shape edges and
|
|
121
|
+
/// glyph overshoot; the packet host's raster cache carries a one-pixel
|
|
122
|
+
/// apron for exactly this) — so content that shrinks, moves, or
|
|
123
|
+
/// disappears cannot strand a stale fringe. The snap keeps the CULL
|
|
124
|
+
/// region identical to the CLEARED pixels: clears land on whole pixels
|
|
125
|
+
/// while culling tests the float rect, so a fractional dirty edge would
|
|
126
|
+
/// erase the boundary pixel's antialiased coverage without redrawing
|
|
127
|
+
/// the unchanged neighbor that painted it.
|
|
128
|
+
///
|
|
129
|
+
/// Which pixels are cleared is decided on INTEGER device boundaries
|
|
130
|
+
/// (floor/ceil of the input edges, moved by whole `bleed_pixels` —
|
|
131
|
+
/// never by a rounded `1/scale` in logical points, which can fall a
|
|
132
|
+
/// whole pixel short at fractional scales). The logical edges are then
|
|
133
|
+
/// chosen so the STORED rect (x, y, width, height in f32) hands
|
|
134
|
+
/// consumers back products that land exactly on those boundaries: the
|
|
135
|
+
/// min edges are the smallest representable values whose product
|
|
136
|
+
/// reaches their boundary, and the spans the largest whose
|
|
137
|
+
/// RECONSTRUCTED max edge (`x + width`, the f32 a stored rect yields)
|
|
138
|
+
/// stays on theirs — so consumers re-deriving pixels clear exactly the
|
|
139
|
+
/// pixels command culling admits, in both directions.
|
|
140
|
+
pub fn bleedAlignedCanvasDirtyBounds(bounds: ?geometry.RectF, scale: f32, bleed_pixels: f32, surface_size: geometry.SizeF) ?geometry.RectF {
|
|
141
|
+
const dirty = bounds orelse return null;
|
|
142
|
+
const normalized = dirty.normalized();
|
|
143
|
+
const device = if (std.math.isFinite(scale) and scale > 0) scale else 1;
|
|
144
|
+
// Surface clipping happens HERE, on the integer device boundaries,
|
|
145
|
+
// never on the finished rect: re-encoding an aligned rect through a
|
|
146
|
+
// rect intersection (even a no-op one) reconstructs its width and
|
|
147
|
+
// can push the stored edges' round trip off their boundaries by an
|
|
148
|
+
// ulp. A boundary interval that clips empty means the damage lies
|
|
149
|
+
// entirely off-surface.
|
|
150
|
+
const x_boundaries = surfaceClampedCanvasDirtyBoundaries(
|
|
151
|
+
@floor(normalized.minX() * device) - bleed_pixels,
|
|
152
|
+
@ceil(normalized.maxX() * device) + bleed_pixels,
|
|
153
|
+
surface_size.width,
|
|
154
|
+
device,
|
|
155
|
+
) orelse return null;
|
|
156
|
+
const y_boundaries = surfaceClampedCanvasDirtyBoundaries(
|
|
157
|
+
@floor(normalized.minY() * device) - bleed_pixels,
|
|
158
|
+
@ceil(normalized.maxY() * device) + bleed_pixels,
|
|
159
|
+
surface_size.height,
|
|
160
|
+
device,
|
|
161
|
+
) orelse return null;
|
|
162
|
+
const x_edges = canvasDirtyAxisEdges(x_boundaries.min, x_boundaries.max, device);
|
|
163
|
+
const y_edges = canvasDirtyAxisEdges(y_boundaries.min, y_boundaries.max, device);
|
|
164
|
+
if (x_edges.span <= 0 or y_edges.span <= 0) return null;
|
|
165
|
+
return geometry.RectF.init(x_edges.min, y_edges.min, x_edges.span, y_edges.span);
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
const CanvasDirtyBoundaries = struct { min: f32, max: f32 };
|
|
169
|
+
|
|
170
|
+
/// Clamp one axis' device boundaries to the surface's own device
|
|
171
|
+
/// boundaries (`[0, ceil(extent * device)]` — the pixels that actually
|
|
172
|
+
/// exist). A non-positive or non-finite surface extent leaves the axis
|
|
173
|
+
/// unbounded: callers with no clipping surface still need the damage
|
|
174
|
+
/// as a repaint region. Null when the interval clips empty.
|
|
175
|
+
fn surfaceClampedCanvasDirtyBoundaries(min_boundary: f32, max_boundary: f32, surface_extent: f32, device: f32) ?CanvasDirtyBoundaries {
|
|
176
|
+
var min_b = min_boundary;
|
|
177
|
+
var max_b = max_boundary;
|
|
178
|
+
if (std.math.isFinite(surface_extent) and surface_extent > 0) {
|
|
179
|
+
const surface_boundary = @ceil(surface_extent * device);
|
|
180
|
+
if (std.math.isFinite(surface_boundary)) {
|
|
181
|
+
min_b = std.math.clamp(min_b, 0, surface_boundary);
|
|
182
|
+
max_b = std.math.clamp(max_b, 0, surface_boundary);
|
|
183
|
+
if (!(max_b > min_b)) return null;
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
return .{ .min = min_b, .max = max_b };
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
const CanvasDirtyAxisEdges = struct { min: f32, span: f32 };
|
|
190
|
+
|
|
191
|
+
/// Logical edges for one axis of the bleed-aligned damage. Boundaries
|
|
192
|
+
/// within f32's exact-integer range (2^24 — presentable surfaces reach
|
|
193
|
+
/// at most `max_canvas_surface_extent_pixels`, far below it) take the
|
|
194
|
+
/// exact edge walks; anything beyond (a far off-screen change, an
|
|
195
|
+
/// overflowed product) keeps a finite, NON-COLLAPSED superset instead:
|
|
196
|
+
/// no host can ever clear a pixel out there, so cull/clear exactness is
|
|
197
|
+
/// moot, but the damage must survive as a repaint region for callers
|
|
198
|
+
/// with no clipping surface, and the walks must not start from
|
|
199
|
+
/// infinity (they would never terminate).
|
|
200
|
+
fn canvasDirtyAxisEdges(min_boundary: f32, max_boundary: f32, device: f32) CanvasDirtyAxisEdges {
|
|
201
|
+
const walk_limit: f32 = 16_777_216;
|
|
202
|
+
const walkable = min_boundary >= -walk_limit and min_boundary <= walk_limit and
|
|
203
|
+
max_boundary >= -walk_limit and max_boundary <= walk_limit;
|
|
204
|
+
if (!walkable) {
|
|
205
|
+
const min_edge = nudgedFiniteCanvasDirtyEdge(min_boundary / device, -2);
|
|
206
|
+
const max_edge = nudgedFiniteCanvasDirtyEdge(max_boundary / device, 2);
|
|
207
|
+
var span = @max(0, nudgedFiniteCanvasDirtyEdge(max_edge - min_edge, 2));
|
|
208
|
+
// The reconstructed max edge must stay finite at the f32 range
|
|
209
|
+
// edge; shave the span until the sum stops overflowing.
|
|
210
|
+
while (span > 0 and !std.math.isFinite(min_edge + span)) span = std.math.nextAfter(f32, span, -std.math.inf(f32));
|
|
211
|
+
return .{ .min = min_edge, .span = span };
|
|
212
|
+
}
|
|
213
|
+
const min_edge = canvasDirtyEdgeForFloorBoundary(min_boundary, device);
|
|
214
|
+
return .{ .min = min_edge, .span = canvasDirtySpanForCeilBoundary(min_edge, max_boundary, device) };
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
/// Finite value for the superset fallback: NaN degenerates to zero,
|
|
218
|
+
/// only INFINITIES clamp (to f32's largest finite value — any tighter
|
|
219
|
+
/// clamp would move the damage away from far-but-representable
|
|
220
|
+
/// content, breaking the superset a scale-overriding present relies
|
|
221
|
+
/// on), and `ulps` outward steps absorb the division/subtraction
|
|
222
|
+
/// rounding.
|
|
223
|
+
fn nudgedFiniteCanvasDirtyEdge(value: f32, ulps: i8) f32 {
|
|
224
|
+
if (std.math.isNan(value)) return 0;
|
|
225
|
+
const limit = std.math.floatMax(f32);
|
|
226
|
+
var result = std.math.clamp(value, -limit, limit);
|
|
227
|
+
var remaining: i8 = if (ulps < 0) -ulps else ulps;
|
|
228
|
+
const toward: f32 = if (ulps < 0) -std.math.inf(f32) else std.math.inf(f32);
|
|
229
|
+
while (remaining > 0) : (remaining -= 1) result = std.math.nextAfter(f32, result, toward);
|
|
230
|
+
return std.math.clamp(result, -limit, limit);
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
/// Smallest representable logical coordinate whose product with
|
|
234
|
+
/// `device` reaches `boundary`. Consumers floor the product to pick the
|
|
235
|
+
/// first cleared pixel — a product below the boundary clears one extra
|
|
236
|
+
/// pixel culling excludes — and culling must admit every command
|
|
237
|
+
/// painting into the cleared region, which the MINIMAL such edge
|
|
238
|
+
/// guarantees: anything smaller has a product below the boundary and
|
|
239
|
+
/// paints only uncleared pixels. Products are judged in f64, which is
|
|
240
|
+
/// EXACT for f32 operands: retained hosts recompute the wire rect in
|
|
241
|
+
/// double precision, so an edge whose f32 product merely rounds onto
|
|
242
|
+
/// the boundary while its exact product sits past it would still clear
|
|
243
|
+
/// an extra pixel host-side. Exactness in f64 implies the f32 result
|
|
244
|
+
/// too (the boundary is representable in both).
|
|
245
|
+
fn canvasDirtyEdgeForFloorBoundary(boundary: f32, device: f32) f32 {
|
|
246
|
+
const b: f64 = boundary;
|
|
247
|
+
const d: f64 = device;
|
|
248
|
+
var edge = boundary / device;
|
|
249
|
+
while (@as(f64, edge) * d >= b) edge = std.math.nextAfter(f32, edge, -std.math.inf(f32));
|
|
250
|
+
while (@as(f64, edge) * d < b) edge = std.math.nextAfter(f32, edge, std.math.inf(f32));
|
|
251
|
+
// The walk can settle on negative zero (a boundary of zero steps
|
|
252
|
+
// below and back); canonicalize so serialized rects never carry a
|
|
253
|
+
// signed zero.
|
|
254
|
+
return if (edge == 0) 0 else edge;
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
/// Largest span whose RECONSTRUCTED max edge (`min_edge + span`, the
|
|
258
|
+
/// f32 a stored rect hands back) keeps its product with `device` at or
|
|
259
|
+
/// under `boundary` — judged in f64 like the floor edge, since retained
|
|
260
|
+
/// hosts reconstruct `x + width` and scale it in double precision.
|
|
261
|
+
/// Consumers ceil that product to pick the last cleared pixel — one ulp
|
|
262
|
+
/// past the maximum clears a pixel culling refuses to repaint — and the
|
|
263
|
+
/// maximal such span admits every command painting into the cleared
|
|
264
|
+
/// region: anything larger has a product past the boundary. The walk
|
|
265
|
+
/// steps the EDGE value, never the span: an edge's ulp is proportional
|
|
266
|
+
/// to its magnitude so the walk is a few steps, while span steps can
|
|
267
|
+
/// crawl through denormals without moving the sum when the min edge
|
|
268
|
+
/// dominates it.
|
|
269
|
+
fn canvasDirtySpanForCeilBoundary(min_edge: f32, boundary: f32, device: f32) f32 {
|
|
270
|
+
const b: f64 = boundary;
|
|
271
|
+
const d: f64 = device;
|
|
272
|
+
var target = boundary / device;
|
|
273
|
+
while (@as(f64, target) * d <= b) target = std.math.nextAfter(f32, target, std.math.inf(f32));
|
|
274
|
+
while (@as(f64, target) * d > b) target = std.math.nextAfter(f32, target, -std.math.inf(f32));
|
|
275
|
+
if (target <= min_edge) return 0;
|
|
276
|
+
// Re-encode as the stored span; shrink while the exact
|
|
277
|
+
// reconstruction overshoots the target, giving up the sub-ulp
|
|
278
|
+
// sliver when a step no longer moves the sum.
|
|
279
|
+
var span = target - min_edge;
|
|
280
|
+
while (span > 0 and @as(f64, min_edge) + @as(f64, span) > @as(f64, target)) {
|
|
281
|
+
const next = std.math.nextAfter(f32, span, -std.math.inf(f32));
|
|
282
|
+
if (next == span) return 0;
|
|
283
|
+
span = next;
|
|
284
|
+
}
|
|
285
|
+
return if (span <= 0) 0 else span;
|
|
286
|
+
}
|
|
287
|
+
|
|
115
288
|
fn canvasSurfaceRect(surface_size: geometry.SizeF) ?geometry.RectF {
|
|
116
289
|
const rect = geometry.RectF.fromSize(surface_size).normalized();
|
|
117
290
|
return if (rect.isEmpty()) null else rect;
|
|
@@ -152,6 +325,8 @@ pub fn canvasWidgetPointerEventFromGpuInput(input_event: GpuSurfaceInputEvent) ?
|
|
|
152
325
|
.phase = phase,
|
|
153
326
|
.point = geometry.PointF.init(input_event.x, input_event.y),
|
|
154
327
|
.delta = geometry.OffsetF.init(input_event.delta_x, input_event.delta_y),
|
|
328
|
+
.pointer_id = input_event.pointer_id,
|
|
329
|
+
.button = input_event.button,
|
|
155
330
|
};
|
|
156
331
|
}
|
|
157
332
|
|
|
@@ -244,7 +419,21 @@ pub fn canvasWidgetEscapeKey(key: []const u8) bool {
|
|
|
244
419
|
return std.ascii.eqlIgnoreCase(key, "escape") or std.ascii.eqlIgnoreCase(key, "esc");
|
|
245
420
|
}
|
|
246
421
|
|
|
247
|
-
|
|
422
|
+
/// A text/IME input carrying a command chord (primary, command, or
|
|
423
|
+
/// control) is a SHORTCUT, not typing: focused text widgets refuse to
|
|
424
|
+
/// insert it (above), and the target-less `on_text` fallback applies the
|
|
425
|
+
/// same gate so a Ctrl/Cmd-chorded key never delivers both the shortcut
|
|
426
|
+
/// and a literal character. Alt stays out of the set on purpose — Option
|
|
427
|
+
/// composes text on macOS and AltGr produces it elsewhere — and on
|
|
428
|
+
/// WINDOWS ALONE Ctrl+Alt together is exempt too: that host represents
|
|
429
|
+
/// AltGr as Ctrl+Alt, so a text event carrying both is composed text
|
|
430
|
+
/// (AltGr+Q's `@`), not a chord. Linux reports AltGr as its own
|
|
431
|
+
/// level-3 shift and macOS composes on bare Option, so Ctrl+Alt there
|
|
432
|
+
/// is always a genuine chord and must keep gating.
|
|
433
|
+
pub fn gpuInputHasTextCommandModifier(input_event: GpuSurfaceInputEvent) bool {
|
|
434
|
+
if (comptime builtin.os.tag == .windows) {
|
|
435
|
+
if (input_event.modifiers.control and input_event.modifiers.option) return false;
|
|
436
|
+
}
|
|
248
437
|
return input_event.modifiers.primary or input_event.modifiers.command or input_event.modifiers.control;
|
|
249
438
|
}
|
|
250
439
|
|