Skip to content

Commit b57728c

Browse files
committed
Port the "basic" set of tests
1 parent d0d2e15 commit b57728c

File tree

10 files changed

+461
-28
lines changed

10 files changed

+461
-28
lines changed

sparse_strips/vello_api/src/painter.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
use core::any::Any;
55

66
use peniko::kurbo::{Affine, BezPath, Rect, Shape, Stroke};
7-
use peniko::{BlendMode, Brush, Color, Fill, ImageBrush};
7+
use peniko::{BlendMode, Brush, Color, Fill};
88

99
use crate::scene::{OurBrush, Scene};
1010

@@ -69,6 +69,7 @@ pub trait PaintScene: Any {
6969
// fn push_clip_path(&mut self, path: &kurbo::BezPath);
7070
// fn pop_clip_path(&mut self);
7171

72+
// TODO: We need to support a fill rule here for clip paths...
7273
fn push_layer(
7374
&mut self,
7475
clip_transform: Affine,
@@ -80,6 +81,7 @@ pub trait PaintScene: Any {
8081
);
8182

8283
// TODO: Do we need all of these?
84+
// TODO: We need to support a fill rule here...
8385
fn push_clip_layer(&mut self, clip_transform: Affine, path: impl Shape) {
8486
self.push_layer(clip_transform, Some(path), None, None);
8587
}

sparse_strips/vello_cpu/src/api.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -389,6 +389,9 @@ impl PaintScene for CPUScenePainter {
389389
opacity: Option<f32>,
390390
// mask: Option<Mask>,
391391
) {
392+
// We set the fill rule to nonzero for the clip path as a reasonable default.
393+
// We should make it user provided in the future
394+
self.render_context.set_fill_rule(Fill::NonZero);
392395
self.render_context.set_transform(clip_transform);
393396
self.render_context.push_layer(
394397
clip_path.map(|it| it.to_path(0.1)).as_ref(),
@@ -400,6 +403,7 @@ impl PaintScene for CPUScenePainter {
400403
}
401404

402405
fn push_clip_layer(&mut self, clip_transform: Affine, path: impl Shape) {
406+
self.render_context.set_fill_rule(Fill::NonZero);
403407
self.render_context.set_transform(clip_transform);
404408
self.render_context.push_clip_layer(
405409
// TODO: Not allocate

sparse_strips/vello_dev_macros/src/api_test.rs

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
// Copyright 2025 the Vello Authors
22
// SPDX-License-Identifier: Apache-2.0 OR MIT
33

4+
//! The [`vello_api_test`](crate::vello_api_test) macro, which automatically generates variations of tests for
5+
//! functions using Vello API.
6+
47
use crate::{
58
Attribute, AttributeInput, DEFAULT_CPU_F32_TOLERANCE, DEFAULT_CPU_U8_TOLERANCE,
69
DEFAULT_HYBRID_TOLERANCE, DEFAULT_SIMD_TOLERANCE, parse_int_lit, parse_string_lit,
@@ -39,6 +42,10 @@ struct Arguments {
3942
/// Whether no reference image should actually be created (for tests that only check
4043
/// for panics, but are not interested in the actual output).
4144
no_ref: bool,
45+
/// Whether a reference image should be used but not created for this test.
46+
///
47+
/// This is used for porting tests from the interim "API" to Vello API.
48+
existing_ref: bool,
4249
/// A reason for ignoring a test.
4350
ignore_reason: Option<String>,
4451
}
@@ -56,6 +63,7 @@ impl Default for Arguments {
5663
skip_hybrid: false,
5764
no_ref: false,
5865
diff_pixels: 0,
66+
existing_ref: false,
5967
ignore_reason: None,
6068
}
6169
}
@@ -147,16 +155,21 @@ pub(crate) fn vello_test_inner(attr: TokenStream, item: TokenStream) -> TokenStr
147155
width,
148156
height,
149157
cpu_u8_tolerance,
150-
mut hybrid_tolerance,
158+
hybrid_tolerance,
151159
transparent,
152160
skip_cpu,
153161
skip_multithreaded,
154162
mut skip_hybrid,
155163
ignore_reason,
156164
no_ref,
157165
diff_pixels,
166+
existing_ref,
158167
} = parse_args(&attrs);
159168

169+
if no_ref && existing_ref {
170+
panic!("Setting `no_ref` and `existing_ref` at the same time is meaningless.");
171+
}
172+
160173
let params_const = {
161174
let cpu_u8_scalar_tolerance = cpu_u8_tolerance + DEFAULT_CPU_U8_TOLERANCE;
162175
let cpu_u8_simd_tolerance =
@@ -322,7 +335,8 @@ pub(crate) fn vello_test_inner(attr: TokenStream, item: TokenStream) -> TokenStr
322335
f32_fn_name_scalar,
323336
f32_fn_name_str_scalar,
324337
&cpu_f32_tolerance_scalar,
325-
true,
338+
// Only make a reference image if there is already a reference image existing.
339+
!existing_ref,
326340
0,
327341
quote! {"fallback"},
328342
skip_cpu,
@@ -496,7 +510,6 @@ pub(crate) fn vello_test_inner(attr: TokenStream, item: TokenStream) -> TokenStr
496510
},
497511
#webgl_fn_name_str,
498512
#params_name.hybrid_tolerance,
499-
false,
500513
);
501514
}
502515
};
@@ -542,6 +555,7 @@ fn parse_args(attribute_input: &AttributeInput) -> Arguments {
542555
"skip_multithreaded" => args.skip_multithreaded = true,
543556
"skip_hybrid" => args.skip_hybrid = true,
544557
"no_ref" => args.no_ref = true,
558+
"existing_ref" => args.existing_ref = true,
545559
"ignore" => {
546560
args.skip_cpu = true;
547561
args.skip_multithreaded = true;
Lines changed: 1 addition & 1 deletion
Loading

0 commit comments

Comments
 (0)