From 5e5dcb0d419bad06ae2c7e1403a73a721a62c1af Mon Sep 17 00:00:00 2001 From: Tim Aschhoff Date: Tue, 14 Jan 2025 19:14:23 +0100 Subject: [PATCH 1/4] Examples: Replace Color::from_* and Color::new with palette::css wherever possible --- examples/scenes/src/mmark.rs | 15 +++++++------ examples/scenes/src/test_scenes.rs | 34 +++++++++++++++--------------- examples/simple/src/main.rs | 9 ++++---- examples/simple_sdl2/src/main.rs | 9 ++++---- examples/with_winit/src/stats.rs | 6 +++--- 5 files changed, 36 insertions(+), 37 deletions(-) diff --git a/examples/scenes/src/mmark.rs b/examples/scenes/src/mmark.rs index c0b6590a..74371d4f 100644 --- a/examples/scenes/src/mmark.rs +++ b/examples/scenes/src/mmark.rs @@ -14,6 +14,7 @@ use std::cmp::Ordering; use rand::seq::SliceRandom; use rand::Rng; use vello::kurbo::{Affine, BezPath, CubicBez, Line, ParamCurve, PathSeg, Point, QuadBez, Stroke}; +use vello::peniko::color::palette; use vello::peniko::Color; use vello::Scene; @@ -118,13 +119,13 @@ impl TestScene for MMark { } const COLORS: &[Color] = &[ - Color::from_rgba8(0x10, 0x10, 0x10, 0xff), - Color::from_rgba8(0x80, 0x80, 0x80, 0xff), - Color::from_rgba8(0xc0, 0xc0, 0xc0, 0xff), - Color::from_rgba8(0x10, 0x10, 0x10, 0xff), - Color::from_rgba8(0x80, 0x80, 0x80, 0xff), - Color::from_rgba8(0xc0, 0xc0, 0xc0, 0xff), - Color::from_rgba8(0xe0, 0x10, 0x40, 0xff), + palette::css::BLACK, + palette::css::GRAY, + palette::css::LIGHT_GRAY, + palette::css::BLACK, + palette::css::GRAY, + palette::css::LIGHT_GRAY, + palette::css::DEEP_PINK, ]; impl Element { diff --git a/examples/scenes/src/test_scenes.rs b/examples/scenes/src/test_scenes.rs index badc8d5f..7a180e44 100644 --- a/examples/scenes/src/test_scenes.rs +++ b/examples/scenes/src/test_scenes.rs @@ -169,10 +169,10 @@ mod impls { use PathEl::*; move |scene, params| { let colors = [ - Color::from_rgba8(140, 181, 236, 255), - Color::from_rgba8(246, 236, 202, 255), - Color::from_rgba8(201, 147, 206, 255), - Color::from_rgba8(150, 195, 160, 255), + palette::css::SKY_BLUE, + palette::css::LIGHT_SALMON, + palette::css::LAVENDER, + palette::css::PALE_GREEN, ]; let simple_stroke = [MoveTo((0., 0.).into()), LineTo((100., 0.).into())]; let join_stroke = [ @@ -346,10 +346,10 @@ mod impls { pub(super) fn tricky_strokes(scene: &mut Scene, params: &mut SceneParams<'_>) { use PathEl::*; let colors = [ - Color::from_rgba8(140, 181, 236, 255), - Color::from_rgba8(246, 236, 202, 255), - Color::from_rgba8(201, 147, 206, 255), - Color::from_rgba8(150, 195, 160, 255), + palette::css::SKY_BLUE, + palette::css::LIGHT_YELLOW, + palette::css::VIOLET, + palette::css::LIGHT_GREEN, ]; const CELL_SIZE: f64 = 200.; @@ -588,14 +588,14 @@ mod impls { scene.fill( rule.0, Affine::translate((0., 10.)) * t * Affine::rotate(0.06), - Color::new([0., 1., 0.7, 0.6]), + palette::css::TURQUOISE.with_alpha(0.6), None, &rule.2, ); scene.fill( rule.0, Affine::translate((0., 10.)) * t * Affine::rotate(-0.06), - Color::new([0.9, 0.7, 0.5, 0.6]), + palette::css::ORANGE.with_alpha(0.6), None, &rule.2, ); @@ -886,7 +886,7 @@ mod impls { let colors = [ palette::css::RED, palette::css::YELLOW, - Color::from_rgba8(6, 85, 186, 255), + palette::css::ROYAL_BLUE, ]; let width = 400_f64; let height = 200_f64; @@ -1231,9 +1231,9 @@ mod impls { .with_stops([palette::css::BLACK, palette::css::WHITE]); scene.fill(Fill::NonZero, transform, &linear, None, &rect); const GRADIENTS: &[(f64, f64, Color)] = &[ - (150., 0., Color::from_rgba8(255, 240, 64, 255)), - (175., 100., Color::from_rgba8(255, 96, 240, 255)), - (125., 200., Color::from_rgba8(64, 192, 255, 255)), + (150., 0., palette::css::YELLOW), + (175., 100., palette::css::PINK), + (125., 200., palette::css::CYAN), ]; for (x, y, c) in GRADIENTS { let color2 = c.with_alpha(0.); @@ -1279,8 +1279,8 @@ mod impls { let x = N + 0.5; // Fractional pixel offset reveals the problem on axis-aligned edges. let mut y = N; - let bg_color = Color::from_rgba8(255, 194, 19, 255); - let fg_color = Color::from_rgba8(12, 165, 255, 255); + let bg_color = palette::css::YELLOW; + let fg_color = palette::css::DODGER_BLUE; // Two adjacent triangles touching at diagonal edge with opposing winding numbers scene.fill( @@ -1430,7 +1430,7 @@ mod impls { scene.fill( Fill::NonZero, Affine::translate((20.5, 20.5)) * Affine::scale(80.0), - Color::from_rgba8(0x70, 0x80, 0x80, 0xff), + palette::css::SLATE_GRAY, None, &path, ); diff --git a/examples/simple/src/main.rs b/examples/simple/src/main.rs index 8a4a5159..1d4a0b6d 100644 --- a/examples/simple/src/main.rs +++ b/examples/simple/src/main.rs @@ -8,7 +8,6 @@ use std::num::NonZeroUsize; use std::sync::Arc; use vello::kurbo::{Affine, Circle, Ellipse, Line, RoundedRect, Stroke}; use vello::peniko::color::palette; -use vello::peniko::Color; use vello::util::{RenderContext, RenderSurface}; use vello::{AaConfig, Renderer, RendererOptions, Scene}; use winit::application::ApplicationHandler; @@ -211,12 +210,12 @@ fn add_shapes_to_scene(scene: &mut Scene) { // Draw an outlined rectangle let stroke = Stroke::new(6.0); let rect = RoundedRect::new(10.0, 10.0, 240.0, 240.0, 20.0); - let rect_stroke_color = Color::new([0.9804, 0.702, 0.5294, 1.]); + let rect_stroke_color = palette::css::ORANGE; scene.stroke(&stroke, Affine::IDENTITY, rect_stroke_color, None, &rect); // Draw a filled circle let circle = Circle::new((420.0, 200.0), 120.0); - let circle_fill_color = Color::new([0.9529, 0.5451, 0.6588, 1.]); + let circle_fill_color = palette::css::PALE_VIOLET_RED; scene.fill( vello::peniko::Fill::NonZero, Affine::IDENTITY, @@ -227,7 +226,7 @@ fn add_shapes_to_scene(scene: &mut Scene) { // Draw a filled ellipse let ellipse = Ellipse::new((250.0, 420.0), (100.0, 160.0), -90.0); - let ellipse_fill_color = Color::new([0.7961, 0.651, 0.9686, 1.]); + let ellipse_fill_color = palette::css::PURPLE; scene.fill( vello::peniko::Fill::NonZero, Affine::IDENTITY, @@ -238,6 +237,6 @@ fn add_shapes_to_scene(scene: &mut Scene) { // Draw a straight line let line = Line::new((260.0, 20.0), (620.0, 100.0)); - let line_stroke_color = Color::new([0.5373, 0.7059, 0.9804, 1.]); + let line_stroke_color = palette::css::SKY_BLUE; scene.stroke(&stroke, Affine::IDENTITY, line_stroke_color, None, &line); } diff --git a/examples/simple_sdl2/src/main.rs b/examples/simple_sdl2/src/main.rs index 125f0a7f..468c0a91 100644 --- a/examples/simple_sdl2/src/main.rs +++ b/examples/simple_sdl2/src/main.rs @@ -15,7 +15,6 @@ use std::num::NonZeroUsize; use vello::kurbo::{Affine, Circle, Ellipse, Line, RoundedRect, Stroke}; use vello::peniko::color::palette; -use vello::peniko::Color; use vello::util::{RenderContext, RenderSurface}; use vello::{AaConfig, Renderer, RendererOptions, Scene}; @@ -121,12 +120,12 @@ fn add_shapes_to_scene(scene: &mut Scene) { // Draw an outlined rectangle let stroke = Stroke::new(6.0); let rect = RoundedRect::new(10.0, 10.0, 240.0, 240.0, 20.0); - let rect_stroke_color = Color::new([0.9804, 0.702, 0.5294, 1.]); + let rect_stroke_color = palette::css::ORANGE; scene.stroke(&stroke, Affine::IDENTITY, rect_stroke_color, None, &rect); // Draw a filled circle let circle = Circle::new((420.0, 200.0), 120.0); - let circle_fill_color = Color::new([0.9529, 0.5451, 0.6588, 1.]); + let circle_fill_color = palette::css::PALE_VIOLET_RED; scene.fill( vello::peniko::Fill::NonZero, Affine::IDENTITY, @@ -137,7 +136,7 @@ fn add_shapes_to_scene(scene: &mut Scene) { // Draw a filled ellipse let ellipse = Ellipse::new((250.0, 420.0), (100.0, 160.0), -90.0); - let ellipse_fill_color = Color::new([0.7961, 0.651, 0.9686, 1.]); + let ellipse_fill_color = palette::css::PURPLE; scene.fill( vello::peniko::Fill::NonZero, Affine::IDENTITY, @@ -148,6 +147,6 @@ fn add_shapes_to_scene(scene: &mut Scene) { // Draw a straight line let line = Line::new((260.0, 20.0), (620.0, 100.0)); - let line_stroke_color = Color::new([0.5373, 0.7059, 0.9804, 1.]); + let line_stroke_color = palette::css::SKY_BLUE; scene.stroke(&stroke, Affine::IDENTITY, line_stroke_color, None, &line); } diff --git a/examples/with_winit/src/stats.rs b/examples/with_winit/src/stats.rs index 93ed9f3e..138247e2 100644 --- a/examples/with_winit/src/stats.rs +++ b/examples/with_winit/src/stats.rs @@ -135,9 +135,9 @@ impl Snapshot { let s = Affine::scale_non_uniform(1., -h); #[allow(clippy::match_overlapping_arm)] let color = match *sample { - ..=16_667 => Color::from_rgba8(100, 143, 255, 255), - ..=33_334 => Color::from_rgba8(255, 176, 0, 255), - _ => Color::from_rgba8(220, 38, 127, 255), + ..=16_667 => palette::css::ROYAL_BLUE, + ..=33_334 => palette::css::ORANGE, + _ => palette::css::PINK, }; scene.fill( Fill::NonZero, From c431413283d5dee78b16c524b56153ec43c9b214 Mon Sep 17 00:00:00 2001 From: Tim Aschhoff Date: Tue, 14 Jan 2025 20:10:12 +0100 Subject: [PATCH 2/4] Fix import being unused, if cfg flag is unset --- examples/with_winit/src/stats.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/examples/with_winit/src/stats.rs b/examples/with_winit/src/stats.rs index 138247e2..bdcc463a 100644 --- a/examples/with_winit/src/stats.rs +++ b/examples/with_winit/src/stats.rs @@ -6,7 +6,9 @@ use std::collections::VecDeque; #[cfg(feature = "wgpu-profiler")] use vello::kurbo::Line; use vello::kurbo::{Affine, PathEl, Rect, Stroke}; -use vello::peniko::{color::palette, Brush, Color, Fill}; +use vello::peniko::{color::palette, Brush, Fill}; +#[cfg(feature = "wgpu-profiler")] +use vello::peniko::Color; use vello::{low_level::BumpAllocators, AaConfig, Scene}; #[cfg(all(feature = "wgpu-profiler", not(target_arch = "wasm32")))] From c8873a5fa4093ec46fba1fd44343bf6d7dc443cd Mon Sep 17 00:00:00 2001 From: Tim Aschhoff Date: Tue, 14 Jan 2025 20:26:15 +0100 Subject: [PATCH 3/4] rustfmt --- examples/with_winit/src/stats.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/with_winit/src/stats.rs b/examples/with_winit/src/stats.rs index bdcc463a..25b95524 100644 --- a/examples/with_winit/src/stats.rs +++ b/examples/with_winit/src/stats.rs @@ -6,9 +6,9 @@ use std::collections::VecDeque; #[cfg(feature = "wgpu-profiler")] use vello::kurbo::Line; use vello::kurbo::{Affine, PathEl, Rect, Stroke}; -use vello::peniko::{color::palette, Brush, Fill}; #[cfg(feature = "wgpu-profiler")] use vello::peniko::Color; +use vello::peniko::{color::palette, Brush, Fill}; use vello::{low_level::BumpAllocators, AaConfig, Scene}; #[cfg(all(feature = "wgpu-profiler", not(target_arch = "wasm32")))] From d0d0a3126127bafa0dd3018f14c63c87de091eca Mon Sep 17 00:00:00 2001 From: Tim Aschhoff Date: Wed, 15 Jan 2025 21:38:11 +0100 Subject: [PATCH 4/4] Update snapshot test to use new colors --- vello_tests/snapshots/big_colr.png | 4 ++-- vello_tests/snapshots/fill_types.png | 4 ++-- vello_tests/snapshots/stroke_styles.png | 4 ++-- vello_tests/snapshots/stroke_styles_non_uniform.png | 4 ++-- vello_tests/snapshots/stroke_styles_skew.png | 4 ++-- vello_tests/snapshots/tricky_strokes.png | 4 ++-- 6 files changed, 12 insertions(+), 12 deletions(-) diff --git a/vello_tests/snapshots/big_colr.png b/vello_tests/snapshots/big_colr.png index c7bc7782..8484a063 100644 --- a/vello_tests/snapshots/big_colr.png +++ b/vello_tests/snapshots/big_colr.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:c43e1738715b4b4359bdda7831f4bedbac3db182884c78bdcabd44fc49fffd55 -size 15735 +oid sha256:ab53a8a4e769ba509cc63c4cae01c09a464d0049d05e7fe51830a4533beca136 +size 15750 diff --git a/vello_tests/snapshots/fill_types.png b/vello_tests/snapshots/fill_types.png index 1050437c..8a8c8b0a 100644 --- a/vello_tests/snapshots/fill_types.png +++ b/vello_tests/snapshots/fill_types.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:9e8e4396ee504ce60fb2b45a57a58eeff45008b3f78b612df858091752c4e06c -size 82101 +oid sha256:dd71e062700dd59b075fe6e580354ad03050bb9229766d3929be18f7e5bdf842 +size 84141 diff --git a/vello_tests/snapshots/stroke_styles.png b/vello_tests/snapshots/stroke_styles.png index 1f3c3963..819d533f 100644 --- a/vello_tests/snapshots/stroke_styles.png +++ b/vello_tests/snapshots/stroke_styles.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:144176c89e644116dcc211e0e4341ed99bc72ff21732a9af40cb9f7a0b32e7b5 -size 96014 +oid sha256:52c7605c6c270d8b7f595154fdf551457660a0d93c57ad0c9218c5a33baa3013 +size 95720 diff --git a/vello_tests/snapshots/stroke_styles_non_uniform.png b/vello_tests/snapshots/stroke_styles_non_uniform.png index 70707d8a..10443cb2 100644 --- a/vello_tests/snapshots/stroke_styles_non_uniform.png +++ b/vello_tests/snapshots/stroke_styles_non_uniform.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:17d592ab5fed53f2916e85f5d62d7ec7ff8b12ad8c4184b8ed7f09c6dc813068 -size 89907 +oid sha256:492e27af9036430606074db5261108d914820b8693a42b9550a0dcacf73aa6c5 +size 89716 diff --git a/vello_tests/snapshots/stroke_styles_skew.png b/vello_tests/snapshots/stroke_styles_skew.png index 6618d5ed..2eb28b08 100644 --- a/vello_tests/snapshots/stroke_styles_skew.png +++ b/vello_tests/snapshots/stroke_styles_skew.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:ebf82e0c7414f4f455eaa7e623b84beb05ba4abd377283b303461326c549af4a -size 100039 +oid sha256:ffdf9bcdd7f0dcb3b403074bafb07e862ba9b1cd76a522b0a3843860a6f1bdb3 +size 99825 diff --git a/vello_tests/snapshots/tricky_strokes.png b/vello_tests/snapshots/tricky_strokes.png index e4c20442..744fc1a0 100644 --- a/vello_tests/snapshots/tricky_strokes.png +++ b/vello_tests/snapshots/tricky_strokes.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:8d22d397f9a45be14784abe692e0b4fae16e555834876021d74e35d44f872043 -size 34733 +oid sha256:07e8711626e172564609e79beec0ba52dfb0a83509d604febc28b1967f119be3 +size 34712