@native-sdk/cli 0.4.0 → 0.4.2
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/README.md +4 -4
- package/assets/icon.icns +0 -0
- package/assets/icon.ico +0 -0
- package/assets/icon.png +0 -0
- package/assets/icon.svg +15 -0
- package/assets/native-sdk.entitlements +10 -0
- package/assets/native-sdk.manifest +28 -0
- package/build/app.zig +40 -1
- package/build.zig +50 -4
- package/package.json +13 -11
- package/src/platform/macos/appkit_host.m +21 -6
- package/src/platform/windows/webview2_host.cpp +377 -72
- package/src/primitives/canvas/chart.zig +8 -7
- package/src/primitives/canvas/chart_tests.zig +2 -2
- package/src/primitives/canvas/commands.zig +27 -0
- package/src/primitives/canvas/gpu.zig +8 -0
- package/src/primitives/canvas/markdown_tests.zig +1 -1
- package/src/primitives/canvas/reference.zig +82 -3
- package/src/primitives/canvas/reference_tests.zig +155 -1
- package/src/primitives/canvas/serialization.zig +16 -3
- package/src/primitives/canvas/themes/geist.zig +6 -0
- package/src/primitives/canvas/tokens.zig +7 -0
- package/src/primitives/canvas/widget_builtin_tests.zig +191 -0
- package/src/primitives/canvas/widget_render.zig +29 -41
- package/src/primitives/canvas/widget_render_controls.zig +55 -42
- package/src/primitives/canvas/widget_render_style.zig +53 -0
- package/src/primitives/canvas/widget_render_surfaces.zig +19 -18
- package/src/primitives/canvas/widget_runtime_tests.zig +20 -21
- package/src/runtime/canvas_frame_packet_tests.zig +9 -1
- package/src/runtime/canvas_frame_patch_tests.zig +39 -1
- package/src/runtime/canvas_widget_control_tests.zig +4 -4
- package/src/runtime/ui_app.zig +78 -10
- package/src/runtime/ui_app_tests.zig +111 -2
- package/src/runtime/ui_app_window_tests.zig +93 -0
- package/src/tooling/cef.zig +1 -1
- package/src/tooling/package.zig +45 -0
- package/src/tooling/templates.zig +46 -5
- package/third_party/webview2/LICENSE.txt +27 -0
- package/third_party/webview2/README.md +19 -0
- package/third_party/webview2/arm64/WebView2Loader.dll +0 -0
- package/third_party/webview2/include/EventToken.h +12 -0
- package/third_party/webview2/include/WebView2.h +60636 -0
- package/third_party/webview2/x64/WebView2Loader.dll +0 -0
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
//! Budgets: series points are bounded at `max_chart_points_per_series`
|
|
15
15
|
//! per series (the `Ui.chart` builder downsamples anything longer, so a
|
|
16
16
|
//! 10k-point star-history series renders instead of erroring), and the
|
|
17
|
-
//!
|
|
17
|
+
//! display-list builder's path-element store is bounded at
|
|
18
18
|
//! `max_chart_path_elements_per_frame`, mirroring the runtime's per-view
|
|
19
19
|
//! `max_canvas_path_elements_per_view` budget (a lockstep test keeps the
|
|
20
20
|
//! two from drifting).
|
|
@@ -32,9 +32,10 @@ pub const ChartSeriesColor = text_spans_model.TextSpanColor;
|
|
|
32
32
|
/// pass through verbatim.
|
|
33
33
|
pub const max_chart_points_per_series: usize = 256;
|
|
34
34
|
|
|
35
|
-
///
|
|
36
|
-
/// renderer builds line/band
|
|
37
|
-
///
|
|
35
|
+
/// Path-element budget for the display-list builder's own element store
|
|
36
|
+
/// (the widget renderer builds chart line/band elements — and the
|
|
37
|
+
/// spinner's and checkbox's — directly into the builder, so the emitted
|
|
38
|
+
/// commands own their geometry for the builder's lifetime). Mirrors the
|
|
38
39
|
/// runtime's `canvas_limits.max_canvas_path_elements_per_view`: a frame
|
|
39
40
|
/// that would exceed this fails loudly with `ChartPathElementListFull`,
|
|
40
41
|
/// exactly when the per-view path budget would have refused the copy
|
|
@@ -44,9 +45,9 @@ pub const max_chart_points_per_series: usize = 256;
|
|
|
44
45
|
pub const max_chart_path_elements_per_frame: usize = 2048;
|
|
45
46
|
|
|
46
47
|
/// Per-frame byte budget for the formatted tick/tooltip label scratch
|
|
47
|
-
/// (
|
|
48
|
-
///
|
|
49
|
-
///
|
|
48
|
+
/// (threadlocal frame-lifetime storage: the emitted `drawText` commands
|
|
49
|
+
/// slice into it until the runtime copies the display list). A y axis
|
|
50
|
+
/// labels at most a handful of ticks and a
|
|
50
51
|
/// hover tooltip a row per series, each `max_chart_value_label_bytes`
|
|
51
52
|
/// long, so 2 KiB holds dozens of charts per frame; overflow fails
|
|
52
53
|
/// loudly with `ChartLabelBytesFull`.
|
|
@@ -722,8 +722,8 @@ test "chart golden: line + bar + band render byte-identically in light and dark"
|
|
|
722
722
|
// category labels (q1, q3) under the bars. Both themes clear with their
|
|
723
723
|
// background token. Update deliberately when chart rendering changes,
|
|
724
724
|
// reviewing the dumped pixels first.
|
|
725
|
-
const golden_light_signature: u64 =
|
|
726
|
-
const golden_dark_signature: u64 =
|
|
725
|
+
const golden_light_signature: u64 = 11237334215963301158;
|
|
726
|
+
const golden_dark_signature: u64 = 4053146140543071333;
|
|
727
727
|
|
|
728
728
|
fn goldenDumpRequested() bool {
|
|
729
729
|
if (comptime !@import("builtin").link_libc) return false;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
const std = @import("std");
|
|
2
2
|
const geometry = @import("geometry");
|
|
3
3
|
const canvas = @import("root.zig");
|
|
4
|
+
const chart_model = @import("chart.zig");
|
|
4
5
|
const drawing_model = @import("drawing.zig");
|
|
5
6
|
const text_model = @import("text.zig");
|
|
6
7
|
const render_model = @import("render.zig");
|
|
@@ -365,6 +366,20 @@ fn nonNegative(value: f32) f32 {
|
|
|
365
366
|
pub const Builder = struct {
|
|
366
367
|
commands: []CanvasCommand,
|
|
367
368
|
len: usize = 0,
|
|
369
|
+
/// Builder-owned storage for path elements built at emit time (the
|
|
370
|
+
/// checkbox mark, chart polylines and bands, the spinner arc and
|
|
371
|
+
/// segments). Emitters allocate from here via `allocPathElements`,
|
|
372
|
+
/// so their commands' element slices share the builder's lifetime:
|
|
373
|
+
/// a display list accumulated across several emit calls — or held
|
|
374
|
+
/// while another builder emits — keeps every path's geometry
|
|
375
|
+
/// intact. Comptime-static elements (the icon registry) bypass the
|
|
376
|
+
/// store and stay zero-copy. Sized to the chart frame budget, which
|
|
377
|
+
/// a lockstep test keeps equal to the runtime's per-view
|
|
378
|
+
/// path-element budget, so overflow fails loudly by budget name
|
|
379
|
+
/// exactly where the runtime's per-view copy would have refused
|
|
380
|
+
/// anyway.
|
|
381
|
+
path_elements: [chart_model.max_chart_path_elements_per_frame]drawing_model.PathElement = undefined,
|
|
382
|
+
path_element_len: usize = 0,
|
|
368
383
|
|
|
369
384
|
pub fn init(commands: []CanvasCommand) Builder {
|
|
370
385
|
return .{ .commands = commands };
|
|
@@ -372,6 +387,18 @@ pub const Builder = struct {
|
|
|
372
387
|
|
|
373
388
|
pub fn reset(self: *Builder) void {
|
|
374
389
|
self.len = 0;
|
|
390
|
+
self.path_element_len = 0;
|
|
391
|
+
}
|
|
392
|
+
|
|
393
|
+
/// Reserve `count` path elements in the builder-owned store. The
|
|
394
|
+
/// returned slice is caller-filled and stays valid for the life of
|
|
395
|
+
/// the builder (until `reset`), so commands built over it survive
|
|
396
|
+
/// later emissions into this or any other builder.
|
|
397
|
+
pub fn allocPathElements(self: *Builder, count: usize) error{ChartPathElementListFull}![]drawing_model.PathElement {
|
|
398
|
+
if (self.path_element_len + count > self.path_elements.len) return error.ChartPathElementListFull;
|
|
399
|
+
const start = self.path_element_len;
|
|
400
|
+
self.path_element_len += count;
|
|
401
|
+
return self.path_elements[start..self.path_element_len];
|
|
375
402
|
}
|
|
376
403
|
|
|
377
404
|
pub fn displayList(self: *const Builder) DisplayList {
|
|
@@ -13,6 +13,7 @@ const Color = drawing_model.Color;
|
|
|
13
13
|
const Radius = drawing_model.Radius;
|
|
14
14
|
const LinearGradient = drawing_model.LinearGradient;
|
|
15
15
|
const Fill = drawing_model.Fill;
|
|
16
|
+
const LineCap = drawing_model.LineCap;
|
|
16
17
|
const PathElement = drawing_model.PathElement;
|
|
17
18
|
const ImageFit = drawing_model.ImageFit;
|
|
18
19
|
const ImageSampling = drawing_model.ImageSampling;
|
|
@@ -201,6 +202,12 @@ pub const CanvasGpuCommand = struct {
|
|
|
201
202
|
shape: CanvasGpuShape = .none,
|
|
202
203
|
paint: CanvasGpuPaint = .none,
|
|
203
204
|
stroke_width: f32 = 0,
|
|
205
|
+
/// Stroke end-cap shape for `stroke_path` commands (butt for every
|
|
206
|
+
/// other kind, matching the display-list model where only path
|
|
207
|
+
/// strokes carry a cap channel). Rides the wire so packet hosts
|
|
208
|
+
/// stroke open subpaths with the same ends the reference renderer
|
|
209
|
+
/// rasterizes.
|
|
210
|
+
cap: LineCap = .butt,
|
|
204
211
|
image: ?CanvasGpuImage = null,
|
|
205
212
|
text: ?CanvasGpuText = null,
|
|
206
213
|
effect: CanvasGpuEffect = .none,
|
|
@@ -525,6 +532,7 @@ pub fn canvasGpuCommandFromRenderCommand(command: RenderCommand, command_index:
|
|
|
525
532
|
packet_command.shape = .{ .path = value.elements };
|
|
526
533
|
packet_command.paint = canvasGpuPaint(value.stroke.fill);
|
|
527
534
|
packet_command.stroke_width = value.stroke.width;
|
|
535
|
+
packet_command.cap = value.cap;
|
|
528
536
|
packet_command.uses_path_geometry = true;
|
|
529
537
|
packet_command.uses_resource = canvasGpuFillUsesResource(value.stroke.fill);
|
|
530
538
|
},
|
|
@@ -405,7 +405,7 @@ test "the README-shaped fixture renders through the mapper and the reference ren
|
|
|
405
405
|
// separators, fenced-code panels, and near-black underlined links.
|
|
406
406
|
// Update deliberately when markdown rendering changes, reviewing the
|
|
407
407
|
// rendered pixels first (see reference_tests.zig conventions).
|
|
408
|
-
const markdown_document_reference_signature: u64 =
|
|
408
|
+
const markdown_document_reference_signature: u64 = 6015448079037287912;
|
|
409
409
|
|
|
410
410
|
|
|
411
411
|
test "bare URLs autolink at word boundaries with trailing punctuation trimmed" {
|
|
@@ -295,12 +295,21 @@ pub const ReferenceRenderSurface = struct {
|
|
|
295
295
|
// so no apron rows join the key.
|
|
296
296
|
const probe = self.memoProbe(pixel_rect, 0, referenceMemoParamsHash(2, command, value));
|
|
297
297
|
if (self.memoReplay(probe, pixel_rect)) return;
|
|
298
|
+
// Square-cornered fills keep the legacy binary pixel-center
|
|
299
|
+
// test (bit-identical on integer bounds); rounded fills take
|
|
300
|
+
// the anti-aliased signed-distance coverage.
|
|
301
|
+
const binary = referenceRadiusIsZero(radius);
|
|
298
302
|
var y = pixel_rect.y;
|
|
299
303
|
while (y < pixel_rect.y + pixel_rect.height) : (y += 1) {
|
|
300
304
|
var x = pixel_rect.x;
|
|
301
305
|
while (x < pixel_rect.x + pixel_rect.width) : (x += 1) {
|
|
302
306
|
const point = referencePixelCenter(x, y);
|
|
303
|
-
if (
|
|
307
|
+
if (binary) {
|
|
308
|
+
if (referencePointInRoundedRect(point, rect, radius)) self.blendPixel(@intCast(x), @intCast(y), referenceSampleFill(value.fill, command.transform, point), command.opacity);
|
|
309
|
+
continue;
|
|
310
|
+
}
|
|
311
|
+
const coverage = referenceRoundedRectCoverage(point, rect, radius);
|
|
312
|
+
if (coverage > 0) self.blendPixel(@intCast(x), @intCast(y), referenceScaleColorAlpha(referenceSampleFill(value.fill, command.transform, point), coverage), command.opacity);
|
|
304
313
|
}
|
|
305
314
|
}
|
|
306
315
|
self.memoStore(probe, pixel_rect);
|
|
@@ -323,13 +332,28 @@ pub const ReferenceRenderSurface = struct {
|
|
|
323
332
|
// blends into, so no apron rows join the key.
|
|
324
333
|
const probe = self.memoProbe(pixel_rect, 0, referenceMemoParamsHash(5, command, value));
|
|
325
334
|
if (self.memoReplay(probe, pixel_rect)) return;
|
|
335
|
+
// Square-cornered borders keep the legacy binary ring test
|
|
336
|
+
// (bit-identical on integer bounds). Rounded borders derive
|
|
337
|
+
// BOTH ring edges from the same signed-distance field —
|
|
338
|
+
// coverage is outer-edge coverage minus inner-edge coverage —
|
|
339
|
+
// so the border weight stays uniform around the whole shape
|
|
340
|
+
// (the inner edge stays in the field even when the inset
|
|
341
|
+
// radius bottoms out at a square corner).
|
|
342
|
+
const binary = referenceRadiusIsZero(radius);
|
|
326
343
|
var y = pixel_rect.y;
|
|
327
344
|
while (y < pixel_rect.y + pixel_rect.height) : (y += 1) {
|
|
328
345
|
var x = pixel_rect.x;
|
|
329
346
|
while (x < pixel_rect.x + pixel_rect.width) : (x += 1) {
|
|
330
347
|
const point = referencePixelCenter(x, y);
|
|
331
|
-
if (
|
|
332
|
-
|
|
348
|
+
if (binary) {
|
|
349
|
+
if (referencePointInRoundedRect(point, outer, outer_radius) and !referencePointInRoundedRect(point, inner, inner_radius)) {
|
|
350
|
+
self.blendPixel(@intCast(x), @intCast(y), referenceSampleFill(value.stroke.fill, command.transform, point), command.opacity);
|
|
351
|
+
}
|
|
352
|
+
continue;
|
|
353
|
+
}
|
|
354
|
+
const coverage = std.math.clamp(referenceRoundedRectCoverage(point, outer, outer_radius) - referenceRoundedRectCoverage(point, inner, inner_radius), 0, 1);
|
|
355
|
+
if (coverage > 0) {
|
|
356
|
+
self.blendPixel(@intCast(x), @intCast(y), referenceScaleColorAlpha(referenceSampleFill(value.stroke.fill, command.transform, point), coverage), command.opacity);
|
|
333
357
|
}
|
|
334
358
|
}
|
|
335
359
|
}
|
|
@@ -1359,6 +1383,61 @@ fn referencePointInRoundedRect(point: geometry.PointF, rect: geometry.RectF, rad
|
|
|
1359
1383
|
return true;
|
|
1360
1384
|
}
|
|
1361
1385
|
|
|
1386
|
+
/// True when every corner is square — the gate for the legacy binary
|
|
1387
|
+
/// pixel-center rasterization, which keeps radius-0 rects on integer
|
|
1388
|
+
/// bounds bit-identical to their historical bytes.
|
|
1389
|
+
fn referenceRadiusIsZero(radius: Radius) bool {
|
|
1390
|
+
return radius.top_left <= 0 and radius.top_right <= 0 and
|
|
1391
|
+
radius.bottom_right <= 0 and radius.bottom_left <= 0;
|
|
1392
|
+
}
|
|
1393
|
+
|
|
1394
|
+
/// Fractional coverage of the pixel centered at `point` against a
|
|
1395
|
+
/// rounded rect: `clamp(0.5 - d, 0, 1)` of the EXACT signed distance to
|
|
1396
|
+
/// the shape boundary. One closed form serves arcs and straight
|
|
1397
|
+
/// segments alike, so coverage is a continuous function around the
|
|
1398
|
+
/// whole perimeter — a per-region model (arc ramp here, binary edge
|
|
1399
|
+
/// there) disagrees with itself about where the boundary is at the
|
|
1400
|
+
/// hand-off points and grows nubs or notches into the silhouette.
|
|
1401
|
+
///
|
|
1402
|
+
/// The distance is the classic rounded-rect field: with `q = |p - c| -
|
|
1403
|
+
/// (half_extent - r)` for the corner radius `r` of the quadrant `p`
|
|
1404
|
+
/// lies in, `d = length(max(q, 0)) + min(max(q.x, q.y), 0) - r`. It is
|
|
1405
|
+
/// exact for any per-corner radii, including square (r = 0) corners,
|
|
1406
|
+
/// and along a straight segment it reduces to the plain axis distance
|
|
1407
|
+
/// (the selected radius cancels), so the field is continuous where
|
|
1408
|
+
/// quadrants with different radii meet. Cheap fully-inside/outside
|
|
1409
|
+
/// short circuits keep the square root off interior and far-apron
|
|
1410
|
+
/// pixels; the exact form runs only near the boundary band.
|
|
1411
|
+
fn referenceRoundedRectCoverage(point: geometry.PointF, rect: geometry.RectF, radius: Radius) f32 {
|
|
1412
|
+
const normalized = rect.normalized();
|
|
1413
|
+
if (normalized.isEmpty()) return 0;
|
|
1414
|
+
const max_radius = @min(normalized.width, normalized.height) * 0.5;
|
|
1415
|
+
|
|
1416
|
+
const half_width = normalized.width * 0.5;
|
|
1417
|
+
const half_height = normalized.height * 0.5;
|
|
1418
|
+
const dx = point.x - (normalized.x + half_width);
|
|
1419
|
+
const dy = point.y - (normalized.y + half_height);
|
|
1420
|
+
const corner_radius = std.math.clamp(nonNegative(if (dx < 0)
|
|
1421
|
+
(if (dy < 0) radius.top_left else radius.bottom_left)
|
|
1422
|
+
else
|
|
1423
|
+
(if (dy < 0) radius.top_right else radius.bottom_right)), 0, max_radius);
|
|
1424
|
+
|
|
1425
|
+
const qx = @abs(dx) - half_width + corner_radius;
|
|
1426
|
+
const qy = @abs(dy) - half_height + corner_radius;
|
|
1427
|
+
// Fully inside: with both components non-positive the distance is
|
|
1428
|
+
// `max(qx, qy) - r`, so anything at least half a pixel inside the
|
|
1429
|
+
// radius-inset cross is full coverage.
|
|
1430
|
+
if (@max(qx, qy) <= -0.5) return 1;
|
|
1431
|
+
// Fully outside: the distance is at least `qx - r` (and `qy - r`),
|
|
1432
|
+
// so anything at least half a pixel beyond the bounding box is
|
|
1433
|
+
// zero coverage.
|
|
1434
|
+
if (qx - corner_radius >= 0.5 or qy - corner_radius >= 0.5) return 0;
|
|
1435
|
+
const mx = @max(qx, 0);
|
|
1436
|
+
const my = @max(qy, 0);
|
|
1437
|
+
const distance = @sqrt(mx * mx + my * my) + @min(@max(qx, qy), 0) - corner_radius;
|
|
1438
|
+
return std.math.clamp(0.5 - distance, 0, 1);
|
|
1439
|
+
}
|
|
1440
|
+
|
|
1362
1441
|
fn referencePointInCorner(point: geometry.PointF, center: geometry.PointF, radius: f32) bool {
|
|
1363
1442
|
if (radius <= 0) return false;
|
|
1364
1443
|
const dx = point.x - center.x;
|
|
@@ -628,12 +628,166 @@ test "reference renderer captures Phase 2 primitive signature" {
|
|
|
628
628
|
const surface = (try ReferenceRenderSurface.initWithScratch(32, 24, &pixels, &scratch)).withImages(&images);
|
|
629
629
|
try surface.renderPass(frame.renderPass(), Color.rgb8(0, 0, 0));
|
|
630
630
|
|
|
631
|
-
try std.testing.expectEqual(@as(u64,
|
|
631
|
+
try std.testing.expectEqual(@as(u64, 8143217197410062006), referenceSurfaceSignature(&pixels));
|
|
632
632
|
try expectVisiblePixel(surface.pixelRgba8(6, 6));
|
|
633
633
|
try expectVisiblePixel(surface.pixelRgba8(20, 8));
|
|
634
634
|
try expectVisiblePixel(surface.pixelRgba8(6, 16));
|
|
635
635
|
}
|
|
636
636
|
|
|
637
|
+
// ---------------------------------------------------------------------------
|
|
638
|
+
// Rounded-rect coverage shape fidelity.
|
|
639
|
+
//
|
|
640
|
+
// The anti-aliased rounded-rect rasterization derives per-pixel coverage
|
|
641
|
+
// from one continuous signed-distance field of the whole shape. These
|
|
642
|
+
// tests hold that coverage against ground truth — 16x16 supersampling of
|
|
643
|
+
// the exact point-in-shape predicate per pixel — with two assertions:
|
|
644
|
+
//
|
|
645
|
+
// 1. NO PROTRUSION: any pixel the supersampled shape leaves empty must
|
|
646
|
+
// stay empty. A coverage model that treats perimeter regions
|
|
647
|
+
// differently (an arc ramp handing off to a binary straight edge)
|
|
648
|
+
// disagrees with itself about where the boundary is and pushes
|
|
649
|
+
// nubs outside the silhouette; this catches that class of bug
|
|
650
|
+
// exactly.
|
|
651
|
+
// 2. BOUNDED DEVIATION: the worst per-pixel difference stays within
|
|
652
|
+
// the intrinsic error of distance-ramp coverage. A half-pixel
|
|
653
|
+
// linear ramp reproduces box-filter coverage exactly on straight
|
|
654
|
+
// edges; on arcs it deviates more as curvature tightens, and at a
|
|
655
|
+
// sharp concave ring corner the distance-to-coverage mapping has a
|
|
656
|
+
// known worst case of ~1/4 at the single corner pixel. The
|
|
657
|
+
// per-case bounds encode those regimes with a small margin; the
|
|
658
|
+
// discontinuous-coverage bug class lands far outside them (2-4x).
|
|
659
|
+
|
|
660
|
+
const roundedRectCoverageFidelityCase = struct {
|
|
661
|
+
kind: enum { fill, stroke },
|
|
662
|
+
rect: geometry.RectF,
|
|
663
|
+
radius: Radius,
|
|
664
|
+
stroke_width: f32 = 0,
|
|
665
|
+
/// Max per-pixel |rendered - supersampled| in 1/255 levels.
|
|
666
|
+
tolerance: i32,
|
|
667
|
+
};
|
|
668
|
+
|
|
669
|
+
fn fidelityClampRadius(value: f32, max_radius: f32) f32 {
|
|
670
|
+
return std.math.clamp(@max(0, value), 0, max_radius);
|
|
671
|
+
}
|
|
672
|
+
|
|
673
|
+
fn fidelityInCorner(x: f32, y: f32, cx: f32, cy: f32, r: f32) bool {
|
|
674
|
+
if (r <= 0) return false;
|
|
675
|
+
const dx = x - cx;
|
|
676
|
+
const dy = y - cy;
|
|
677
|
+
return dx * dx + dy * dy <= r * r;
|
|
678
|
+
}
|
|
679
|
+
|
|
680
|
+
/// The exact rounded-rect interior predicate the supersampled ground
|
|
681
|
+
/// truth integrates: the rect with each corner replaced by a quarter
|
|
682
|
+
/// disc of its (clamped) radius.
|
|
683
|
+
fn fidelityInRoundedRect(x: f32, y: f32, rect: geometry.RectF, radius: Radius) bool {
|
|
684
|
+
if (rect.width <= 0 or rect.height <= 0) return false;
|
|
685
|
+
if (x < rect.x or x > rect.x + rect.width or y < rect.y or y > rect.y + rect.height) return false;
|
|
686
|
+
const max_radius = @min(rect.width, rect.height) * 0.5;
|
|
687
|
+
const top_left = fidelityClampRadius(radius.top_left, max_radius);
|
|
688
|
+
const top_right = fidelityClampRadius(radius.top_right, max_radius);
|
|
689
|
+
const bottom_right = fidelityClampRadius(radius.bottom_right, max_radius);
|
|
690
|
+
const bottom_left = fidelityClampRadius(radius.bottom_left, max_radius);
|
|
691
|
+
const max_x = rect.x + rect.width;
|
|
692
|
+
const max_y = rect.y + rect.height;
|
|
693
|
+
if (x < rect.x + top_left and y < rect.y + top_left) return fidelityInCorner(x, y, rect.x + top_left, rect.y + top_left, top_left);
|
|
694
|
+
if (x >= max_x - top_right and y < rect.y + top_right) return fidelityInCorner(x, y, max_x - top_right, rect.y + top_right, top_right);
|
|
695
|
+
if (x >= max_x - bottom_right and y >= max_y - bottom_right) return fidelityInCorner(x, y, max_x - bottom_right, max_y - bottom_right, bottom_right);
|
|
696
|
+
if (x < rect.x + bottom_left and y >= max_y - bottom_left) return fidelityInCorner(x, y, rect.x + bottom_left, max_y - bottom_left, bottom_left);
|
|
697
|
+
return true;
|
|
698
|
+
}
|
|
699
|
+
|
|
700
|
+
fn fidelityOutsetRadius(radius: Radius, outset: f32) Radius {
|
|
701
|
+
return .{
|
|
702
|
+
.top_left = @max(0, radius.top_left + outset),
|
|
703
|
+
.top_right = @max(0, radius.top_right + outset),
|
|
704
|
+
.bottom_right = @max(0, radius.bottom_right + outset),
|
|
705
|
+
.bottom_left = @max(0, radius.bottom_left + outset),
|
|
706
|
+
};
|
|
707
|
+
}
|
|
708
|
+
|
|
709
|
+
/// Ground-truth alpha of one pixel: the fraction of a 16x16 subsample
|
|
710
|
+
/// grid inside the case's shape (the stroke ring is outer minus inner,
|
|
711
|
+
/// derived exactly as the renderer derives them), quantized to a byte
|
|
712
|
+
/// like the renderer's blend quantizes coverage.
|
|
713
|
+
fn fidelityTruthAlpha(case: roundedRectCoverageFidelityCase, px: usize, py: usize) u8 {
|
|
714
|
+
const half = case.stroke_width * 0.5;
|
|
715
|
+
const outer = case.rect.inflate(geometry.InsetsF.all(half));
|
|
716
|
+
const inner = case.rect.deflate(geometry.InsetsF.all(@min(half, @min(case.rect.width, case.rect.height) * 0.5)));
|
|
717
|
+
const outer_radius = fidelityOutsetRadius(case.radius, half);
|
|
718
|
+
const inner_radius = fidelityOutsetRadius(case.radius, -half);
|
|
719
|
+
var covered: usize = 0;
|
|
720
|
+
var sub_y: usize = 0;
|
|
721
|
+
while (sub_y < 16) : (sub_y += 1) {
|
|
722
|
+
var sub_x: usize = 0;
|
|
723
|
+
while (sub_x < 16) : (sub_x += 1) {
|
|
724
|
+
const x = @as(f32, @floatFromInt(px)) + (@as(f32, @floatFromInt(sub_x)) + 0.5) / 16.0;
|
|
725
|
+
const y = @as(f32, @floatFromInt(py)) + (@as(f32, @floatFromInt(sub_y)) + 0.5) / 16.0;
|
|
726
|
+
const in = switch (case.kind) {
|
|
727
|
+
.fill => fidelityInRoundedRect(x, y, case.rect, case.radius),
|
|
728
|
+
.stroke => fidelityInRoundedRect(x, y, outer, outer_radius) and !fidelityInRoundedRect(x, y, inner, inner_radius),
|
|
729
|
+
};
|
|
730
|
+
if (in) covered += 1;
|
|
731
|
+
}
|
|
732
|
+
}
|
|
733
|
+
return @intFromFloat(@round(@as(f32, @floatFromInt(covered)) / 256.0 * 255.0));
|
|
734
|
+
}
|
|
735
|
+
|
|
736
|
+
test "rounded-rect coverage matches supersampled ground truth with no silhouette protrusion" {
|
|
737
|
+
const fidelity_width: usize = 48;
|
|
738
|
+
const fidelity_height: usize = 40;
|
|
739
|
+
const white = Color{ .r = 1, .g = 1, .b = 1, .a = 1 };
|
|
740
|
+
const cases = [_]roundedRectCoverageFidelityCase{
|
|
741
|
+
// Button-shaped fills: smooth arcs, integer and fractional bounds.
|
|
742
|
+
.{ .kind = .fill, .rect = geometry.RectF.init(6, 5, 30, 22), .radius = Radius.all(8), .tolerance = 16 },
|
|
743
|
+
.{ .kind = .fill, .rect = geometry.RectF.init(6.3, 5.7, 29.4, 21.6), .radius = Radius.all(8), .tolerance = 16 },
|
|
744
|
+
// Pill: the radius clamps to the half-height.
|
|
745
|
+
.{ .kind = .fill, .rect = geometry.RectF.init(4, 6, 40, 20), .radius = Radius.all(22), .tolerance = 16 },
|
|
746
|
+
// Tight curvature and mixed per-corner radii (one square corner).
|
|
747
|
+
.{ .kind = .fill, .rect = geometry.RectF.init(10.2, 8.6, 21.7, 14.3), .radius = Radius.all(0.75), .tolerance = 32 },
|
|
748
|
+
.{ .kind = .fill, .rect = geometry.RectF.init(7.6, 6.2, 30.8, 24.9), .radius = .{ .top_left = 0, .top_right = 6, .bottom_right = 12, .bottom_left = 2 }, .tolerance = 32 },
|
|
749
|
+
// Thin borders: both ring edges from the same field.
|
|
750
|
+
.{ .kind = .stroke, .rect = geometry.RectF.init(8, 7, 28, 20), .radius = Radius.all(6), .stroke_width = 1, .tolerance = 20 },
|
|
751
|
+
.{ .kind = .stroke, .rect = geometry.RectF.init(8.4, 7.8, 27.3, 19.5), .radius = Radius.all(6), .stroke_width = 2, .tolerance = 20 },
|
|
752
|
+
.{ .kind = .stroke, .rect = geometry.RectF.init(9.1, 8.3, 25.6, 17.2), .radius = Radius.all(0.75), .stroke_width = 1, .tolerance = 32 },
|
|
753
|
+
// Thick border whose inset radius bottoms out: the ring's inner
|
|
754
|
+
// corners go sharp and concave, the distance-ramp worst case.
|
|
755
|
+
.{ .kind = .stroke, .rect = geometry.RectF.init(8, 7, 28, 20), .radius = Radius.all(1), .stroke_width = 3, .tolerance = 72 },
|
|
756
|
+
};
|
|
757
|
+
|
|
758
|
+
for (cases) |case| {
|
|
759
|
+
var pixels: [fidelity_width * fidelity_height * 4]u8 = undefined;
|
|
760
|
+
const surface = try ReferenceRenderSurface.init(fidelity_width, fidelity_height, &pixels);
|
|
761
|
+
const bounds = geometry.RectF.init(0, 0, fidelity_width, fidelity_height);
|
|
762
|
+
const command = RenderCommand{
|
|
763
|
+
.command = switch (case.kind) {
|
|
764
|
+
.fill => .{ .fill_rounded_rect = .{ .rect = case.rect, .radius = case.radius, .fill = .{ .color = white } } },
|
|
765
|
+
.stroke => .{ .stroke_rect = .{ .rect = case.rect, .radius = case.radius, .stroke = .{ .fill = .{ .color = white }, .width = case.stroke_width } } },
|
|
766
|
+
},
|
|
767
|
+
.local_bounds = bounds,
|
|
768
|
+
.bounds = bounds,
|
|
769
|
+
};
|
|
770
|
+
const pass = CanvasRenderPass{
|
|
771
|
+
.surface_size = geometry.SizeF.init(fidelity_width, fidelity_height),
|
|
772
|
+
.scale = 1,
|
|
773
|
+
.full_repaint = true,
|
|
774
|
+
.commands = &.{command},
|
|
775
|
+
};
|
|
776
|
+
try surface.renderPass(pass, Color{ .r = 0, .g = 0, .b = 0, .a = 0 });
|
|
777
|
+
|
|
778
|
+
var y: usize = 0;
|
|
779
|
+
while (y < fidelity_height) : (y += 1) {
|
|
780
|
+
var x: usize = 0;
|
|
781
|
+
while (x < fidelity_width) : (x += 1) {
|
|
782
|
+
const rendered: i32 = surface.pixelRgba8(x, y)[3];
|
|
783
|
+
const truth: i32 = fidelityTruthAlpha(case, x, y);
|
|
784
|
+
if (truth == 0) try std.testing.expectEqual(@as(i32, 0), rendered);
|
|
785
|
+
try std.testing.expect(@max(rendered - truth, truth - rendered) <= case.tolerance);
|
|
786
|
+
}
|
|
787
|
+
}
|
|
788
|
+
}
|
|
789
|
+
}
|
|
790
|
+
|
|
637
791
|
test "reference renderer applies clip transform and opacity" {
|
|
638
792
|
const commands = [_]CanvasCommand{
|
|
639
793
|
.{ .push_clip = .{ .rect = geometry.RectF.init(1, 1, 2, 2) } },
|
|
@@ -348,6 +348,8 @@ fn writeCanvasGpuCommandJson(command: CanvasGpuCommand, writer: anytype) !void {
|
|
|
348
348
|
try writer.writeAll(",\"paint\":");
|
|
349
349
|
try writeCanvasGpuPaintJson(command.paint, writer);
|
|
350
350
|
try writer.print(",\"strokeWidth\":{d}", .{command.stroke_width});
|
|
351
|
+
try writer.writeAll(",\"cap\":");
|
|
352
|
+
try json.writeString(writer, @tagName(command.cap));
|
|
351
353
|
try writer.writeAll(",\"image\":");
|
|
352
354
|
try writeCanvasGpuImageJson(command.image, writer);
|
|
353
355
|
try writer.writeAll(",\"text\":");
|
|
@@ -974,7 +976,7 @@ fn writeGlyphsJson(glyphs: []const Glyph, writer: anytype) !void {
|
|
|
974
976
|
}
|
|
975
977
|
|
|
976
978
|
// ---------------------------------------------------------------------------
|
|
977
|
-
// Compact binary gpu-surface packet encoding (wire format
|
|
979
|
+
// Compact binary gpu-surface packet encoding (wire format v4).
|
|
978
980
|
//
|
|
979
981
|
// The version this comment names, the `binary_packet_version` constant
|
|
980
982
|
// below, and the host decoder's spec comment (appkit_host.m) must agree;
|
|
@@ -1006,6 +1008,11 @@ fn writeGlyphsJson(glyphs: []const Glyph, writer: anytype) !void {
|
|
|
1006
1008
|
// scissor stays the union of the list (hosts may honor either; pixels
|
|
1007
1009
|
// outside every rect are unchanged by construction).
|
|
1008
1010
|
//
|
|
1011
|
+
// v4 (from v3): every command carries a stroke end-cap code (u8, 0 butt
|
|
1012
|
+
// / 1 round) after stroke_width, so packet hosts stroke open subpaths
|
|
1013
|
+
// (the checkbox mark, the spinner arc) with the same cap the reference
|
|
1014
|
+
// renderer rasterizes instead of their engine default.
|
|
1015
|
+
//
|
|
1009
1016
|
// Layout:
|
|
1010
1017
|
// "NSGP" u8[4] | version u8 | load_action u8 (1 load / 2 clear /
|
|
1011
1018
|
// 3 patch) | flags u8 (bit0 scissor, bit1 dirty rect list) | reserved u8
|
|
@@ -1023,7 +1030,7 @@ fn writeGlyphsJson(glyphs: []const Glyph, writer: anytype) !void {
|
|
|
1023
1030
|
// | order_count u32 | order keys u64[]
|
|
1024
1031
|
|
|
1025
1032
|
pub const binary_packet_magic = "NSGP";
|
|
1026
|
-
pub const binary_packet_version: u8 =
|
|
1033
|
+
pub const binary_packet_version: u8 = 4;
|
|
1027
1034
|
|
|
1028
1035
|
/// Most dirty rects a patch header carries: enough to keep far-apart
|
|
1029
1036
|
/// small changes (a switch plus a status line) from fusing into a
|
|
@@ -1054,6 +1061,7 @@ pub fn canvasGpuCommandFingerprint(command: CanvasGpuCommand) u64 {
|
|
|
1054
1061
|
h = hash.resourceHashRect(h, command.bounds);
|
|
1055
1062
|
h = hash.resourceHashF32(h, command.opacity);
|
|
1056
1063
|
h = hash.resourceHashF32(h, command.stroke_width);
|
|
1064
|
+
h = hash.resourceHashEnum(h, @intFromEnum(command.cap));
|
|
1057
1065
|
h = hash.resourceHashOptionalObjectId(h, command.id);
|
|
1058
1066
|
h = hash.resourceHashOptionalRect(h, command.clip);
|
|
1059
1067
|
h = hash.resourceHashAffine(h, command.transform);
|
|
@@ -1254,7 +1262,8 @@ const binary_command_flag_text: u8 = 0x40;
|
|
|
1254
1262
|
const binary_command_flag_effect: u8 = 0x80;
|
|
1255
1263
|
|
|
1256
1264
|
/// Command layout: kind u8 | flags u8 | bounds f32[4] | opacity f32
|
|
1257
|
-
/// | stroke_width f32 |
|
|
1265
|
+
/// | stroke_width f32 | cap u8 (0 butt / 1 round) | [id u64]
|
|
1266
|
+
/// | [clip f32[4]] | [transform f32[6]]
|
|
1258
1267
|
/// | [shape] | [paint] | [image] | [text] | [effect] — each optional
|
|
1259
1268
|
/// section present exactly when its flag bit is set. The identity
|
|
1260
1269
|
/// transform is elided (the flag doubles as "non-identity").
|
|
@@ -1276,6 +1285,10 @@ fn writeCanvasGpuCommandBinary(command: CanvasGpuCommand, writer: anytype) !void
|
|
|
1276
1285
|
try writeBinaryRect(command.bounds, writer);
|
|
1277
1286
|
try writeBinaryF32(command.opacity, writer);
|
|
1278
1287
|
try writeBinaryF32(command.stroke_width, writer);
|
|
1288
|
+
try writer.writeByte(switch (command.cap) {
|
|
1289
|
+
.butt => 0,
|
|
1290
|
+
.round => 1,
|
|
1291
|
+
});
|
|
1279
1292
|
if (command.id) |id| try writer.writeInt(u64, id, .little);
|
|
1280
1293
|
if (command.clip) |clip| try writeBinaryRect(clip, writer);
|
|
1281
1294
|
if (!identity_transform) try writeBinaryAffine(command.transform, writer);
|
|
@@ -54,6 +54,12 @@ pub fn designTokens(color_scheme: ColorScheme, contrast: ColorContrast) DesignTo
|
|
|
54
54
|
// then a 2px blue ring — the stroke defaults already carry that
|
|
55
55
|
// geometry, restated here so the pack is explicit about it.
|
|
56
56
|
.stroke = .{ .hairline = 1, .regular = 1, .focus = 2, .focus_offset = 2 },
|
|
57
|
+
// Crisp 1px lines are core to this register: geometry pixel
|
|
58
|
+
// snapping lands hairline borders on whole device columns. The
|
|
59
|
+
// runtime stamps the live surface scale on top; apps opt out
|
|
60
|
+
// through the token override (`.pixel_snap = .{ .geometry =
|
|
61
|
+
// false }`).
|
|
62
|
+
.pixel_snap = .{ .geometry = true },
|
|
57
63
|
// Shadows are quiet: a 2px settle under raised cards, one
|
|
58
64
|
// dominant 16/24 layer under overlays. Buttons stay flat.
|
|
59
65
|
.shadow = .{
|
|
@@ -1478,6 +1478,13 @@ pub const DesignTokens = struct {
|
|
|
1478
1478
|
.house => .{
|
|
1479
1479
|
.colors = ColorTokens.theme(options.color_scheme, options.contrast),
|
|
1480
1480
|
.controls = ControlTokens.theme(options.color_scheme, options.contrast),
|
|
1481
|
+
// Geometry pixel snapping is part of the house register:
|
|
1482
|
+
// hairline borders land on whole device columns (crisp
|
|
1483
|
+
// 1px lines) and intrinsic boxes round to the device
|
|
1484
|
+
// grid. The runtime stamps the live surface scale on
|
|
1485
|
+
// top; apps opt out through the token override
|
|
1486
|
+
// (`.pixel_snap = .{ .geometry = false }`).
|
|
1487
|
+
.pixel_snap = .{ .geometry = true },
|
|
1481
1488
|
},
|
|
1482
1489
|
.geist => geist_theme.designTokens(options.color_scheme, options.contrast),
|
|
1483
1490
|
};
|