From d780199984dd3959935b987f4cfa47a9c79d1bef Mon Sep 17 00:00:00 2001 From: Laurenz Stampfl Date: Mon, 3 Mar 2025 10:12:55 +0100 Subject: [PATCH 01/11] 1 --- Cargo.lock | 3 ++ sparse_strips/vello_api/Cargo.toml | 4 +++ sparse_strips/vello_api/src/execute.rs | 44 ++++++++++++++++++++++++++ sparse_strips/vello_api/src/lib.rs | 9 ++++++ sparse_strips/vello_api/src/paint.rs | 16 ++++++++++ sparse_strips/vello_api/src/strip.rs | 16 ++++++++++ sparse_strips/vello_api/src/tiling.rs | 4 +++ 7 files changed, 96 insertions(+) create mode 100644 sparse_strips/vello_api/src/execute.rs create mode 100644 sparse_strips/vello_api/src/paint.rs create mode 100644 sparse_strips/vello_api/src/strip.rs create mode 100644 sparse_strips/vello_api/src/tiling.rs diff --git a/Cargo.lock b/Cargo.lock index cf700bbdae..d213d27318 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2595,6 +2595,9 @@ dependencies = [ [[package]] name = "vello_api" version = "0.4.0" +dependencies = [ + "peniko", +] [[package]] name = "vello_common" diff --git a/sparse_strips/vello_api/Cargo.toml b/sparse_strips/vello_api/Cargo.toml index 0af7b11dd4..72ed9858d9 100644 --- a/sparse_strips/vello_api/Cargo.toml +++ b/sparse_strips/vello_api/Cargo.toml @@ -12,6 +12,10 @@ repository.workspace = true publish = false [dependencies] +peniko = { workspace = true } + +[features] +simd = [] [lints] workspace = true diff --git a/sparse_strips/vello_api/src/execute.rs b/sparse_strips/vello_api/src/execute.rs new file mode 100644 index 0000000000..712e40b43a --- /dev/null +++ b/sparse_strips/vello_api/src/execute.rs @@ -0,0 +1,44 @@ +#[derive(Copy, Clone, Debug)] +/// The execution mode used for the rendering process. +pub enum ExecutionMode { + /// Only use scalar execution. This is recommended if you want to have + /// consistent results across different platforms and want to avoid unsafe code, + /// and is the only option if you disabled the `simd` feature. Performance will be + /// worse, though. + Scalar, + /// Select the best execution mode according to what is available on the host system. + /// This is the recommended option for highest performance. + #[cfg(feature = "simd")] + Auto, + /// Force the usage of neon SIMD instructions. This will lead to panics in case + /// the CPU doesn't support the target feature `neon`. + #[cfg(all(target_arch = "aarch64", feature = "simd"))] + Neon, + /// Force the usage of AVX2 SIMD instructions. This will lead to panics in case + /// the CPU doesn't support the target features `avx2` and `fma`. + #[cfg(all(target_arch = "x86_64", feature = "simd"))] + Avx2, +} + +#[cfg(feature = "simd")] +impl Default for ExecutionMode { + fn default() -> Self { + Self::Auto + } +} + +#[cfg(not(feature = "simd"))] +impl Default for ExecutionMode { + fn default() -> Self { + Self::Scalar + } +} + +/// Scalar execution mode. +pub struct Scalar; + +#[cfg(all(target_arch = "aarch64", feature = "simd"))] +pub struct Neon; + +#[cfg(all(target_arch = "x86_64", feature = "simd"))] +pub struct Avx2; \ No newline at end of file diff --git a/sparse_strips/vello_api/src/lib.rs b/sparse_strips/vello_api/src/lib.rs index 4050b450fe..3a8c2abf0a 100644 --- a/sparse_strips/vello_api/src/lib.rs +++ b/sparse_strips/vello_api/src/lib.rs @@ -4,3 +4,12 @@ //! This crate defines the public API types, providing a stable interface for CPU and hybrid //! CPU/GPU rendering implementations. It provides common interfaces and data structures used //! across different implementations + +#![forbid(unsafe_code)] + +pub use peniko::*; +pub mod execute; +pub mod paint; +pub mod strip; +mod tiling; + diff --git a/sparse_strips/vello_api/src/paint.rs b/sparse_strips/vello_api/src/paint.rs new file mode 100644 index 0000000000..ac1e6b9f04 --- /dev/null +++ b/sparse_strips/vello_api/src/paint.rs @@ -0,0 +1,16 @@ +use peniko::color::{AlphaColor, Srgb}; + +// TODO: Use `peniko::Brush` here? Though it will be tricky +// because `Image` might require a different implementation on GPU, and +// `Gradient` is also missing a `transform` attribute. +/// A paint used for filling or stroking paths. +#[derive(Debug, Clone)] +pub enum Paint { + Solid(AlphaColor), +} + +impl From> for Paint { + fn from(value: AlphaColor) -> Self { + Paint::Solid(value) + } +} \ No newline at end of file diff --git a/sparse_strips/vello_api/src/strip.rs b/sparse_strips/vello_api/src/strip.rs new file mode 100644 index 0000000000..1688c367ee --- /dev/null +++ b/sparse_strips/vello_api/src/strip.rs @@ -0,0 +1,16 @@ +// Note that this will probably disappear and be turned into a const generic in the future. +/// The height of a strip. +pub const STRIP_HEIGHT: usize = 4; + +/// A strip. +#[derive(Debug, Clone, Copy)] +pub struct Strip { + /// The x coordinate of the strip, in user coordinates. + pub x: i32, + /// The y coordinate of the strip, in user coordinates. + pub y: u16, + /// The index into the alpha buffer + pub col: u32, + /// The winding number at the start of the strip. + pub winding: i32, +} \ No newline at end of file diff --git a/sparse_strips/vello_api/src/tiling.rs b/sparse_strips/vello_api/src/tiling.rs new file mode 100644 index 0000000000..18085ccdd8 --- /dev/null +++ b/sparse_strips/vello_api/src/tiling.rs @@ -0,0 +1,4 @@ +/// The size of a tile. +pub const TILE_SIZE: u32 = 4; +pub const TILE_WIDTH: u32 = 4; +pub const TILE_HEIGHT: u32 = 4; \ No newline at end of file From e494e87f5d0ea2b175d6ff12f67cae1dbae4ec76 Mon Sep 17 00:00:00 2001 From: Laurenz Stampfl Date: Mon, 3 Mar 2025 10:14:26 +0100 Subject: [PATCH 02/11] 2 --- sparse_strips/vello_api/src/strip.rs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/sparse_strips/vello_api/src/strip.rs b/sparse_strips/vello_api/src/strip.rs index 1688c367ee..8a5895954e 100644 --- a/sparse_strips/vello_api/src/strip.rs +++ b/sparse_strips/vello_api/src/strip.rs @@ -13,4 +13,11 @@ pub struct Strip { pub col: u32, /// The winding number at the start of the strip. pub winding: i32, +} + +impl Strip { + /// Return the y coordinate of the strip, in strip units. + pub fn strip_y(&self) -> u16 { + self.y / STRIP_HEIGHT as u16 + } } \ No newline at end of file From b6d30c71815ef8700b77f8bfccab4d646c3be8a1 Mon Sep 17 00:00:00 2001 From: Laurenz Stampfl Date: Mon, 3 Mar 2025 10:21:05 +0100 Subject: [PATCH 03/11] 3 --- sparse_strips/vello_api/src/flatten.rs | 55 ++++++++++++++++++++++++++ sparse_strips/vello_api/src/lib.rs | 3 +- 2 files changed, 57 insertions(+), 1 deletion(-) create mode 100644 sparse_strips/vello_api/src/flatten.rs diff --git a/sparse_strips/vello_api/src/flatten.rs b/sparse_strips/vello_api/src/flatten.rs new file mode 100644 index 0000000000..526877a218 --- /dev/null +++ b/sparse_strips/vello_api/src/flatten.rs @@ -0,0 +1,55 @@ +/// A point. +#[derive(Clone, Copy, Debug, PartialEq)] +pub struct Point { + /// The x coordinate of the point. + pub x: f32, + /// The y coordinate of the point. + pub y: f32, +} + +impl Point { + /// Create a new point. + pub fn new(x: f32, y: f32) -> Self { + Point { x, y } + } +} + +impl std::ops::Add for Point { + type Output = Self; + + fn add(self, rhs: Point) -> Self { + Point::new(self.x + rhs.x, self.y + rhs.y) + } +} + +impl std::ops::Sub for Point { + type Output = Self; + + fn sub(self, rhs: Point) -> Self { + Point::new(self.x - rhs.x, self.y - rhs.y) + } +} + +impl std::ops::Mul for Point { + type Output = Self; + + fn mul(self, rhs: f32) -> Self { + Point::new(self.x * rhs, self.y * rhs) + } +} + +/// A flat line. +#[derive(Clone, Copy, Debug)] +pub struct FlatLine { + /// The start point of the line. + pub p0: Point, + /// The end point of the line. + pub p1: Point, +} + +impl FlatLine { + /// Create a new flat line. + pub fn new(p0: Point, p1: Point) -> Self { + Self { p0, p1 } + } +} \ No newline at end of file diff --git a/sparse_strips/vello_api/src/lib.rs b/sparse_strips/vello_api/src/lib.rs index 3a8c2abf0a..ab232af073 100644 --- a/sparse_strips/vello_api/src/lib.rs +++ b/sparse_strips/vello_api/src/lib.rs @@ -11,5 +11,6 @@ pub use peniko::*; pub mod execute; pub mod paint; pub mod strip; -mod tiling; +pub mod tiling; +pub mod flatten; From f451d8239d693c203a169b9adb4312fc24261d21 Mon Sep 17 00:00:00 2001 From: Laurenz Stampfl Date: Mon, 3 Mar 2025 10:21:21 +0100 Subject: [PATCH 04/11] 4 --- sparse_strips/vello_api/src/lib.rs | 2 +- sparse_strips/vello_api/src/{tiling.rs => tile.rs} | 0 2 files changed, 1 insertion(+), 1 deletion(-) rename sparse_strips/vello_api/src/{tiling.rs => tile.rs} (100%) diff --git a/sparse_strips/vello_api/src/lib.rs b/sparse_strips/vello_api/src/lib.rs index ab232af073..c4c7d32a72 100644 --- a/sparse_strips/vello_api/src/lib.rs +++ b/sparse_strips/vello_api/src/lib.rs @@ -11,6 +11,6 @@ pub use peniko::*; pub mod execute; pub mod paint; pub mod strip; -pub mod tiling; +pub mod tile; pub mod flatten; diff --git a/sparse_strips/vello_api/src/tiling.rs b/sparse_strips/vello_api/src/tile.rs similarity index 100% rename from sparse_strips/vello_api/src/tiling.rs rename to sparse_strips/vello_api/src/tile.rs From f139609c8e336944880b5016ba02cd84ba45ca1d Mon Sep 17 00:00:00 2001 From: Laurenz Stampfl Date: Mon, 3 Mar 2025 10:53:47 +0100 Subject: [PATCH 05/11] 5 --- sparse_strips/vello_api/src/execute.rs | 7 ++- sparse_strips/vello_api/src/flatten.rs | 4 +- sparse_strips/vello_api/src/lib.rs | 3 +- sparse_strips/vello_api/src/paint.rs | 15 +++++-- sparse_strips/vello_api/src/strip.rs | 4 +- sparse_strips/vello_api/src/tile.rs | 61 ++++++++++++++++++++++++-- 6 files changed, 82 insertions(+), 12 deletions(-) diff --git a/sparse_strips/vello_api/src/execute.rs b/sparse_strips/vello_api/src/execute.rs index 712e40b43a..70a9cf6502 100644 --- a/sparse_strips/vello_api/src/execute.rs +++ b/sparse_strips/vello_api/src/execute.rs @@ -1,3 +1,5 @@ +//! Different execution modes for kernels. + #[derive(Copy, Clone, Debug)] /// The execution mode used for the rendering process. pub enum ExecutionMode { @@ -35,10 +37,13 @@ impl Default for ExecutionMode { } /// Scalar execution mode. +#[derive(Debug)] pub struct Scalar; #[cfg(all(target_arch = "aarch64", feature = "simd"))] +#[derive(Debug)] pub struct Neon; #[cfg(all(target_arch = "x86_64", feature = "simd"))] -pub struct Avx2; \ No newline at end of file +#[derive(Debug)] +pub struct Avx2; diff --git a/sparse_strips/vello_api/src/flatten.rs b/sparse_strips/vello_api/src/flatten.rs index 526877a218..e473185b5c 100644 --- a/sparse_strips/vello_api/src/flatten.rs +++ b/sparse_strips/vello_api/src/flatten.rs @@ -1,3 +1,5 @@ +//! Types for flattening curves. + /// A point. #[derive(Clone, Copy, Debug, PartialEq)] pub struct Point { @@ -52,4 +54,4 @@ impl FlatLine { pub fn new(p0: Point, p1: Point) -> Self { Self { p0, p1 } } -} \ No newline at end of file +} diff --git a/sparse_strips/vello_api/src/lib.rs b/sparse_strips/vello_api/src/lib.rs index c4c7d32a72..970d38d030 100644 --- a/sparse_strips/vello_api/src/lib.rs +++ b/sparse_strips/vello_api/src/lib.rs @@ -9,8 +9,7 @@ pub use peniko::*; pub mod execute; +pub mod flatten; pub mod paint; pub mod strip; pub mod tile; -pub mod flatten; - diff --git a/sparse_strips/vello_api/src/paint.rs b/sparse_strips/vello_api/src/paint.rs index ac1e6b9f04..8f3e2c8308 100644 --- a/sparse_strips/vello_api/src/paint.rs +++ b/sparse_strips/vello_api/src/paint.rs @@ -1,16 +1,23 @@ +//! Types for paints. + use peniko::color::{AlphaColor, Srgb}; -// TODO: Use `peniko::Brush` here? Though it will be tricky -// because `Image` might require a different implementation on GPU, and -// `Gradient` is also missing a `transform` attribute. +// TODO: This will probably turn into a generic type where +// vello-hybrid and vello-cpu provide their own instantiations for +// a `Pattern` type. /// A paint used for filling or stroking paths. #[derive(Debug, Clone)] pub enum Paint { + /// A solid color. Solid(AlphaColor), + /// A gradient. + Gradient(()), + /// A pattern. + Pattern(()), } impl From> for Paint { fn from(value: AlphaColor) -> Self { Paint::Solid(value) } -} \ No newline at end of file +} diff --git a/sparse_strips/vello_api/src/strip.rs b/sparse_strips/vello_api/src/strip.rs index 8a5895954e..554707aa54 100644 --- a/sparse_strips/vello_api/src/strip.rs +++ b/sparse_strips/vello_api/src/strip.rs @@ -1,3 +1,5 @@ +//! Types for rendering strips. + // Note that this will probably disappear and be turned into a const generic in the future. /// The height of a strip. pub const STRIP_HEIGHT: usize = 4; @@ -20,4 +22,4 @@ impl Strip { pub fn strip_y(&self) -> u16 { self.y / STRIP_HEIGHT as u16 } -} \ No newline at end of file +} diff --git a/sparse_strips/vello_api/src/tile.rs b/sparse_strips/vello_api/src/tile.rs index 18085ccdd8..00866422e3 100644 --- a/sparse_strips/vello_api/src/tile.rs +++ b/sparse_strips/vello_api/src/tile.rs @@ -1,4 +1,59 @@ -/// The size of a tile. -pub const TILE_SIZE: u32 = 4; +//! Types for generating tiles. + +use crate::flatten::Point; + +/// The width of a tile. pub const TILE_WIDTH: u32 = 4; -pub const TILE_HEIGHT: u32 = 4; \ No newline at end of file +/// The height of a tile. +pub const TILE_HEIGHT: u32 = 4; + +/// A tile represents an aligned area on the pixmap, used to subdivide the viewport into sub-areas +/// (currently 4x4) and analyze line intersections inside each such area. +/// +/// Keep in mind that it is possible to have multiple tiles with the same index, +/// namely if we have multiple lines crossing the same 4x4 area! +#[derive(Debug, Clone)] +pub struct Tile { + /// The index of the tile in the x direction. + pub x: i32, + /// The index of the tile in the y direction. + pub y: u16, + /// The start point of the line in that tile. + pub p0: Point, + /// The end point of the line in that tile. + pub p1: Point, +} + +impl Tile { + /// Create a new tile. + pub fn new(x: i32, y: u16, p0: Point, p1: Point) -> Self { + Self { + // We don't need to store the exact negative location, just that it is negative, + // so that the winding number calculation is correct. + x: x.max(-1), + y, + p0, + p1, + } + } + + /// Check whether two tiles are at the same location. + pub fn same_loc(&self, other: &Tile) -> bool { + self.x == other.x && self.same_row(other) + } + + /// Check whether two tiles are on the same strip. + pub fn same_strip(&self, other: &Self) -> bool { + self.same_row(other) && (other.x - self.x).abs() <= 1 + } + + /// Check whether two tiles are on the same row. + pub fn same_row(&self, other: &Self) -> bool { + self.y == other.y + } + + /// Return the delta of the tile. + pub fn delta(&self) -> i32 { + (self.p1.y == 0.0) as i32 - (self.p0.y == 0.0) as i32 + } +} From ac870c29a6d2995b206d586c23b3b0a60d2137a5 Mon Sep 17 00:00:00 2001 From: Laurenz Stampfl Date: Mon, 3 Mar 2025 11:01:34 +0100 Subject: [PATCH 06/11] Make clippy happz --- sparse_strips/vello_api/src/flatten.rs | 12 ++++++------ sparse_strips/vello_api/src/paint.rs | 2 +- sparse_strips/vello_api/src/strip.rs | 2 +- sparse_strips/vello_api/src/tile.rs | 2 +- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/sparse_strips/vello_api/src/flatten.rs b/sparse_strips/vello_api/src/flatten.rs index e473185b5c..2bddf04538 100644 --- a/sparse_strips/vello_api/src/flatten.rs +++ b/sparse_strips/vello_api/src/flatten.rs @@ -12,23 +12,23 @@ pub struct Point { impl Point { /// Create a new point. pub fn new(x: f32, y: f32) -> Self { - Point { x, y } + Self { x, y } } } impl std::ops::Add for Point { type Output = Self; - fn add(self, rhs: Point) -> Self { - Point::new(self.x + rhs.x, self.y + rhs.y) + fn add(self, rhs: Self) -> Self { + Self::new(self.x + rhs.x, self.y + rhs.y) } } impl std::ops::Sub for Point { type Output = Self; - fn sub(self, rhs: Point) -> Self { - Point::new(self.x - rhs.x, self.y - rhs.y) + fn sub(self, rhs: Self) -> Self { + Self::new(self.x - rhs.x, self.y - rhs.y) } } @@ -36,7 +36,7 @@ impl std::ops::Mul for Point { type Output = Self; fn mul(self, rhs: f32) -> Self { - Point::new(self.x * rhs, self.y * rhs) + Self::new(self.x * rhs, self.y * rhs) } } diff --git a/sparse_strips/vello_api/src/paint.rs b/sparse_strips/vello_api/src/paint.rs index 8f3e2c8308..3924196e18 100644 --- a/sparse_strips/vello_api/src/paint.rs +++ b/sparse_strips/vello_api/src/paint.rs @@ -18,6 +18,6 @@ pub enum Paint { impl From> for Paint { fn from(value: AlphaColor) -> Self { - Paint::Solid(value) + Self::Solid(value) } } diff --git a/sparse_strips/vello_api/src/strip.rs b/sparse_strips/vello_api/src/strip.rs index 554707aa54..4b87ce0c26 100644 --- a/sparse_strips/vello_api/src/strip.rs +++ b/sparse_strips/vello_api/src/strip.rs @@ -20,6 +20,6 @@ pub struct Strip { impl Strip { /// Return the y coordinate of the strip, in strip units. pub fn strip_y(&self) -> u16 { - self.y / STRIP_HEIGHT as u16 + self.y / u16::try_from(STRIP_HEIGHT).unwrap() } } diff --git a/sparse_strips/vello_api/src/tile.rs b/sparse_strips/vello_api/src/tile.rs index 00866422e3..67657a0186 100644 --- a/sparse_strips/vello_api/src/tile.rs +++ b/sparse_strips/vello_api/src/tile.rs @@ -38,7 +38,7 @@ impl Tile { } /// Check whether two tiles are at the same location. - pub fn same_loc(&self, other: &Tile) -> bool { + pub fn same_loc(&self, other: &Self) -> bool { self.x == other.x && self.same_row(other) } From d52373729a3c7e5ea56e714378d2bb5a9662ed6c Mon Sep 17 00:00:00 2001 From: Laurenz Stampfl Date: Mon, 3 Mar 2025 11:02:42 +0100 Subject: [PATCH 07/11] Add vello_api to workspace dependencies --- Cargo.toml | 1 + 1 file changed, 1 insertion(+) diff --git a/Cargo.toml b/Cargo.toml index 6661c3c92f..d363e224e8 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -86,6 +86,7 @@ clippy.wildcard_dependencies = "warn" [workspace.dependencies] vello = { version = "0.4.0", path = "vello" } +vello_api = { path = "sparse_strips/vello_api" } vello_encoding = { version = "0.4.0", path = "vello_encoding" } vello_shaders = { version = "0.4.0", path = "vello_shaders" } bytemuck = { version = "1.21.0", features = ["derive"] } From 91e0d020fa20dd878fcd1d2f4b7e25a964732ee8 Mon Sep 17 00:00:00 2001 From: Laurenz Stampfl Date: Mon, 3 Mar 2025 11:03:26 +0100 Subject: [PATCH 08/11] Fix missing docs --- sparse_strips/vello_api/src/execute.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/sparse_strips/vello_api/src/execute.rs b/sparse_strips/vello_api/src/execute.rs index 70a9cf6502..b6cb61575b 100644 --- a/sparse_strips/vello_api/src/execute.rs +++ b/sparse_strips/vello_api/src/execute.rs @@ -42,8 +42,10 @@ pub struct Scalar; #[cfg(all(target_arch = "aarch64", feature = "simd"))] #[derive(Debug)] +/// Execute using NEON intrinsics. pub struct Neon; #[cfg(all(target_arch = "x86_64", feature = "simd"))] #[derive(Debug)] +/// Execute using AVX2 intrinsics. pub struct Avx2; From e9e8dfc5f58bb0f51d09abd7f7952cf5f4cec49b Mon Sep 17 00:00:00 2001 From: Laurenz Stampfl Date: Mon, 3 Mar 2025 11:05:16 +0100 Subject: [PATCH 09/11] Add copyright headers --- sparse_strips/vello_api/src/execute.rs | 3 +++ sparse_strips/vello_api/src/flatten.rs | 3 +++ sparse_strips/vello_api/src/paint.rs | 3 +++ sparse_strips/vello_api/src/strip.rs | 3 +++ sparse_strips/vello_api/src/tile.rs | 3 +++ 5 files changed, 15 insertions(+) diff --git a/sparse_strips/vello_api/src/execute.rs b/sparse_strips/vello_api/src/execute.rs index b6cb61575b..cac9043b14 100644 --- a/sparse_strips/vello_api/src/execute.rs +++ b/sparse_strips/vello_api/src/execute.rs @@ -1,3 +1,6 @@ +// Copyright 2025 the Vello Authors +// SPDX-License-Identifier: Apache-2.0 OR MIT + //! Different execution modes for kernels. #[derive(Copy, Clone, Debug)] diff --git a/sparse_strips/vello_api/src/flatten.rs b/sparse_strips/vello_api/src/flatten.rs index 2bddf04538..52be3d9b5e 100644 --- a/sparse_strips/vello_api/src/flatten.rs +++ b/sparse_strips/vello_api/src/flatten.rs @@ -1,3 +1,6 @@ +// Copyright 2025 the Vello Authors +// SPDX-License-Identifier: Apache-2.0 OR MIT + //! Types for flattening curves. /// A point. diff --git a/sparse_strips/vello_api/src/paint.rs b/sparse_strips/vello_api/src/paint.rs index 3924196e18..9ac3ccceda 100644 --- a/sparse_strips/vello_api/src/paint.rs +++ b/sparse_strips/vello_api/src/paint.rs @@ -1,3 +1,6 @@ +// Copyright 2025 the Vello Authors +// SPDX-License-Identifier: Apache-2.0 OR MIT + //! Types for paints. use peniko::color::{AlphaColor, Srgb}; diff --git a/sparse_strips/vello_api/src/strip.rs b/sparse_strips/vello_api/src/strip.rs index 4b87ce0c26..da286deddb 100644 --- a/sparse_strips/vello_api/src/strip.rs +++ b/sparse_strips/vello_api/src/strip.rs @@ -1,3 +1,6 @@ +// Copyright 2025 the Vello Authors +// SPDX-License-Identifier: Apache-2.0 OR MIT + //! Types for rendering strips. // Note that this will probably disappear and be turned into a const generic in the future. diff --git a/sparse_strips/vello_api/src/tile.rs b/sparse_strips/vello_api/src/tile.rs index 67657a0186..830d2a021c 100644 --- a/sparse_strips/vello_api/src/tile.rs +++ b/sparse_strips/vello_api/src/tile.rs @@ -1,3 +1,6 @@ +// Copyright 2025 the Vello Authors +// SPDX-License-Identifier: Apache-2.0 OR MIT + //! Types for generating tiles. use crate::flatten::Point; From 6c2356c6f71c500f72cd7e8810a805b563482cb4 Mon Sep 17 00:00:00 2001 From: Laurenz Stampfl Date: Mon, 3 Mar 2025 16:22:09 +0100 Subject: [PATCH 10/11] Remove flatten, tiling and strip --- sparse_strips/vello_api/src/flatten.rs | 60 ------------------------- sparse_strips/vello_api/src/lib.rs | 3 -- sparse_strips/vello_api/src/strip.rs | 28 ------------ sparse_strips/vello_api/src/tile.rs | 62 -------------------------- 4 files changed, 153 deletions(-) delete mode 100644 sparse_strips/vello_api/src/flatten.rs delete mode 100644 sparse_strips/vello_api/src/strip.rs delete mode 100644 sparse_strips/vello_api/src/tile.rs diff --git a/sparse_strips/vello_api/src/flatten.rs b/sparse_strips/vello_api/src/flatten.rs deleted file mode 100644 index 52be3d9b5e..0000000000 --- a/sparse_strips/vello_api/src/flatten.rs +++ /dev/null @@ -1,60 +0,0 @@ -// Copyright 2025 the Vello Authors -// SPDX-License-Identifier: Apache-2.0 OR MIT - -//! Types for flattening curves. - -/// A point. -#[derive(Clone, Copy, Debug, PartialEq)] -pub struct Point { - /// The x coordinate of the point. - pub x: f32, - /// The y coordinate of the point. - pub y: f32, -} - -impl Point { - /// Create a new point. - pub fn new(x: f32, y: f32) -> Self { - Self { x, y } - } -} - -impl std::ops::Add for Point { - type Output = Self; - - fn add(self, rhs: Self) -> Self { - Self::new(self.x + rhs.x, self.y + rhs.y) - } -} - -impl std::ops::Sub for Point { - type Output = Self; - - fn sub(self, rhs: Self) -> Self { - Self::new(self.x - rhs.x, self.y - rhs.y) - } -} - -impl std::ops::Mul for Point { - type Output = Self; - - fn mul(self, rhs: f32) -> Self { - Self::new(self.x * rhs, self.y * rhs) - } -} - -/// A flat line. -#[derive(Clone, Copy, Debug)] -pub struct FlatLine { - /// The start point of the line. - pub p0: Point, - /// The end point of the line. - pub p1: Point, -} - -impl FlatLine { - /// Create a new flat line. - pub fn new(p0: Point, p1: Point) -> Self { - Self { p0, p1 } - } -} diff --git a/sparse_strips/vello_api/src/lib.rs b/sparse_strips/vello_api/src/lib.rs index 970d38d030..d83eeab5be 100644 --- a/sparse_strips/vello_api/src/lib.rs +++ b/sparse_strips/vello_api/src/lib.rs @@ -9,7 +9,4 @@ pub use peniko::*; pub mod execute; -pub mod flatten; pub mod paint; -pub mod strip; -pub mod tile; diff --git a/sparse_strips/vello_api/src/strip.rs b/sparse_strips/vello_api/src/strip.rs deleted file mode 100644 index da286deddb..0000000000 --- a/sparse_strips/vello_api/src/strip.rs +++ /dev/null @@ -1,28 +0,0 @@ -// Copyright 2025 the Vello Authors -// SPDX-License-Identifier: Apache-2.0 OR MIT - -//! Types for rendering strips. - -// Note that this will probably disappear and be turned into a const generic in the future. -/// The height of a strip. -pub const STRIP_HEIGHT: usize = 4; - -/// A strip. -#[derive(Debug, Clone, Copy)] -pub struct Strip { - /// The x coordinate of the strip, in user coordinates. - pub x: i32, - /// The y coordinate of the strip, in user coordinates. - pub y: u16, - /// The index into the alpha buffer - pub col: u32, - /// The winding number at the start of the strip. - pub winding: i32, -} - -impl Strip { - /// Return the y coordinate of the strip, in strip units. - pub fn strip_y(&self) -> u16 { - self.y / u16::try_from(STRIP_HEIGHT).unwrap() - } -} diff --git a/sparse_strips/vello_api/src/tile.rs b/sparse_strips/vello_api/src/tile.rs deleted file mode 100644 index 830d2a021c..0000000000 --- a/sparse_strips/vello_api/src/tile.rs +++ /dev/null @@ -1,62 +0,0 @@ -// Copyright 2025 the Vello Authors -// SPDX-License-Identifier: Apache-2.0 OR MIT - -//! Types for generating tiles. - -use crate::flatten::Point; - -/// The width of a tile. -pub const TILE_WIDTH: u32 = 4; -/// The height of a tile. -pub const TILE_HEIGHT: u32 = 4; - -/// A tile represents an aligned area on the pixmap, used to subdivide the viewport into sub-areas -/// (currently 4x4) and analyze line intersections inside each such area. -/// -/// Keep in mind that it is possible to have multiple tiles with the same index, -/// namely if we have multiple lines crossing the same 4x4 area! -#[derive(Debug, Clone)] -pub struct Tile { - /// The index of the tile in the x direction. - pub x: i32, - /// The index of the tile in the y direction. - pub y: u16, - /// The start point of the line in that tile. - pub p0: Point, - /// The end point of the line in that tile. - pub p1: Point, -} - -impl Tile { - /// Create a new tile. - pub fn new(x: i32, y: u16, p0: Point, p1: Point) -> Self { - Self { - // We don't need to store the exact negative location, just that it is negative, - // so that the winding number calculation is correct. - x: x.max(-1), - y, - p0, - p1, - } - } - - /// Check whether two tiles are at the same location. - pub fn same_loc(&self, other: &Self) -> bool { - self.x == other.x && self.same_row(other) - } - - /// Check whether two tiles are on the same strip. - pub fn same_strip(&self, other: &Self) -> bool { - self.same_row(other) && (other.x - self.x).abs() <= 1 - } - - /// Check whether two tiles are on the same row. - pub fn same_row(&self, other: &Self) -> bool { - self.y == other.y - } - - /// Return the delta of the tile. - pub fn delta(&self) -> i32 { - (self.p1.y == 0.0) as i32 - (self.p0.y == 0.0) as i32 - } -} From ee4f55e2c6b5226a19b808adab55a4980eb69aa2 Mon Sep 17 00:00:00 2001 From: Laurenz Stampfl <47084093+LaurenzV@users.noreply.github.com> Date: Mon, 3 Mar 2025 16:49:43 +0100 Subject: [PATCH 11/11] Update sparse_strips/vello_api/src/lib.rs Co-authored-by: Tom Churchman --- sparse_strips/vello_api/src/lib.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/sparse_strips/vello_api/src/lib.rs b/sparse_strips/vello_api/src/lib.rs index d83eeab5be..c7ea3ff656 100644 --- a/sparse_strips/vello_api/src/lib.rs +++ b/sparse_strips/vello_api/src/lib.rs @@ -7,6 +7,8 @@ #![forbid(unsafe_code)] -pub use peniko::*; +pub use peniko; +pub use peniko::color; +pub use peniko::kurbo; pub mod execute; pub mod paint;