From d0fe7b57ea343665905933cdf206d8206be462b9 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Tue, 5 Jan 2021 00:00:36 +0100 Subject: Update `lyon` to `0.17` in `iced_graphics` --- graphics/Cargo.toml | 2 +- graphics/src/widget/canvas/frame.rs | 44 ++++++++++++++---------------- graphics/src/widget/canvas/path.rs | 2 +- graphics/src/widget/canvas/path/builder.rs | 4 +-- 4 files changed, 24 insertions(+), 28 deletions(-) diff --git a/graphics/Cargo.toml b/graphics/Cargo.toml index ea9471c6..15aac4ed 100644 --- a/graphics/Cargo.toml +++ b/graphics/Cargo.toml @@ -36,7 +36,7 @@ version = "0.3" path = "../style" [dependencies.lyon] -version = "0.16" +version = "0.17" optional = true [dependencies.qrcode] diff --git a/graphics/src/widget/canvas/frame.rs b/graphics/src/widget/canvas/frame.rs index 5af9d11f..dd9986af 100644 --- a/graphics/src/widget/canvas/frame.rs +++ b/graphics/src/widget/canvas/frame.rs @@ -108,7 +108,10 @@ impl Frame { size: Size, fill: impl Into, ) { - use lyon::tessellation::{BuffersBuilder, FillOptions}; + use lyon::path::builder::PathBuilder; + use lyon::tessellation::{ + BuffersBuilder, FillOptions, FillTessellator, + }; let Fill { color, rule } = fill.into(); @@ -127,12 +130,17 @@ impl Frame { lyon::math::Vector::new(size.width, size.height), ); - let _ = lyon::tessellation::basic_shapes::fill_rectangle( + let mut tessellator = FillTessellator::new(); + let options = FillOptions::default().with_fill_rule(rule.into()); + + let mut builder = tessellator.builder(&options, &mut buffers); + + builder.add_rectangle( &lyon::math::Rect::new(top_left, size.into()), - &FillOptions::default().with_fill_rule(rule.into()), - &mut buffers, - ) - .expect("Fill rectangle"); + lyon::path::Winding::Positive, + ); + + let _ = builder.build().expect("Fill rectangle"); } /// Draws the stroke of the given [`Path`] on the [`Frame`] with the @@ -282,28 +290,15 @@ impl Frame { struct FillVertex([f32; 4]); -impl lyon::tessellation::BasicVertexConstructor - for FillVertex -{ - fn new_vertex( - &mut self, - position: lyon::math::Point, - ) -> triangle::Vertex2D { - triangle::Vertex2D { - position: [position.x, position.y], - color: self.0, - } - } -} - impl lyon::tessellation::FillVertexConstructor for FillVertex { fn new_vertex( &mut self, - position: lyon::math::Point, - _attributes: lyon::tessellation::FillAttributes<'_>, + vertex: lyon::tessellation::FillVertex<'_>, ) -> triangle::Vertex2D { + let position = vertex.position(); + triangle::Vertex2D { position: [position.x, position.y], color: self.0, @@ -318,9 +313,10 @@ impl lyon::tessellation::StrokeVertexConstructor { fn new_vertex( &mut self, - position: lyon::math::Point, - _attributes: lyon::tessellation::StrokeAttributes<'_, '_>, + vertex: lyon::tessellation::StrokeVertex<'_, '_>, ) -> triangle::Vertex2D { + let position = vertex.position(); + triangle::Vertex2D { position: [position.x, position.y], color: self.0, diff --git a/graphics/src/widget/canvas/path.rs b/graphics/src/widget/canvas/path.rs index 6de19321..4e4fd734 100644 --- a/graphics/src/widget/canvas/path.rs +++ b/graphics/src/widget/canvas/path.rs @@ -62,7 +62,7 @@ impl Path { transform: &lyon::math::Transform, ) -> Path { Path { - raw: self.raw.transformed(transform), + raw: self.raw.clone().transformed(transform), } } } diff --git a/graphics/src/widget/canvas/path/builder.rs b/graphics/src/widget/canvas/path/builder.rs index 5ce0e02c..d04dbdde 100644 --- a/graphics/src/widget/canvas/path/builder.rs +++ b/graphics/src/widget/canvas/path/builder.rs @@ -1,14 +1,14 @@ use crate::canvas::path::{arc, Arc, Path}; use iced_native::{Point, Size}; -use lyon::path::builder::{Build, FlatPathBuilder, PathBuilder, SvgBuilder}; +use lyon::path::builder::SvgPathBuilder; /// A [`Path`] builder. /// /// Once a [`Path`] is built, it can no longer be mutated. #[allow(missing_debug_implementations)] pub struct Builder { - raw: lyon::path::builder::SvgPathBuilder, + raw: lyon::path::builder::WithSvg, } impl Builder { -- cgit From 82d967c04f3b928cd8977d5665a4773e8a7b2587 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Thu, 26 Aug 2021 15:41:12 +0700 Subject: Avoid reallocating tessellators in `Frame` methods --- graphics/src/widget/canvas/frame.rs | 63 +++++++++++++++++++++---------------- 1 file changed, 36 insertions(+), 27 deletions(-) diff --git a/graphics/src/widget/canvas/frame.rs b/graphics/src/widget/canvas/frame.rs index dd9986af..2eaa2274 100644 --- a/graphics/src/widget/canvas/frame.rs +++ b/graphics/src/widget/canvas/frame.rs @@ -5,15 +5,19 @@ use crate::{ triangle, Primitive, }; +use lyon::tessellation; + /// The frame of a [`Canvas`]. /// /// [`Canvas`]: crate::widget::Canvas -#[derive(Debug)] +#[allow(missing_debug_implementations)] pub struct Frame { size: Size, buffers: lyon::tessellation::VertexBuffers, primitives: Vec, transforms: Transforms, + fill_tessellator: tessellation::FillTessellator, + stroke_tessellator: tessellation::StrokeTessellator, } #[derive(Debug)] @@ -45,6 +49,8 @@ impl Frame { is_identity: true, }, }, + fill_tessellator: tessellation::FillTessellator::new(), + stroke_tessellator: tessellation::StrokeTessellator::new(), } } @@ -75,26 +81,30 @@ impl Frame { /// Draws the given [`Path`] on the [`Frame`] by filling it with the /// provided style. pub fn fill(&mut self, path: &Path, fill: impl Into) { - use lyon::tessellation::{ - BuffersBuilder, FillOptions, FillTessellator, - }; - let Fill { color, rule } = fill.into(); - let mut buffers = BuffersBuilder::new( + let mut buffers = tessellation::BuffersBuilder::new( &mut self.buffers, FillVertex(color.into_linear()), ); - let mut tessellator = FillTessellator::new(); - let options = FillOptions::default().with_fill_rule(rule.into()); + let options = + tessellation::FillOptions::default().with_fill_rule(rule.into()); let result = if self.transforms.current.is_identity { - tessellator.tessellate_path(path.raw(), &options, &mut buffers) + self.fill_tessellator.tessellate_path( + path.raw(), + &options, + &mut buffers, + ) } else { let path = path.transformed(&self.transforms.current.raw); - tessellator.tessellate_path(path.raw(), &options, &mut buffers) + self.fill_tessellator.tessellate_path( + path.raw(), + &options, + &mut buffers, + ) }; let _ = result.expect("Tessellate path"); @@ -109,13 +119,10 @@ impl Frame { fill: impl Into, ) { use lyon::path::builder::PathBuilder; - use lyon::tessellation::{ - BuffersBuilder, FillOptions, FillTessellator, - }; let Fill { color, rule } = fill.into(); - let mut buffers = BuffersBuilder::new( + let mut buffers = tessellation::BuffersBuilder::new( &mut self.buffers, FillVertex(color.into_linear()), ); @@ -130,10 +137,10 @@ impl Frame { lyon::math::Vector::new(size.width, size.height), ); - let mut tessellator = FillTessellator::new(); - let options = FillOptions::default().with_fill_rule(rule.into()); + let options = + tessellation::FillOptions::default().with_fill_rule(rule.into()); - let mut builder = tessellator.builder(&options, &mut buffers); + let mut builder = self.fill_tessellator.builder(&options, &mut buffers); builder.add_rectangle( &lyon::math::Rect::new(top_left, size.into()), @@ -146,31 +153,33 @@ impl Frame { /// Draws the stroke of the given [`Path`] on the [`Frame`] with the /// provided style. pub fn stroke(&mut self, path: &Path, stroke: impl Into) { - use lyon::tessellation::{ - BuffersBuilder, StrokeOptions, StrokeTessellator, - }; - let stroke = stroke.into(); - let mut buffers = BuffersBuilder::new( + let mut buffers = tessellation::BuffersBuilder::new( &mut self.buffers, StrokeVertex(stroke.color.into_linear()), ); - let mut tessellator = StrokeTessellator::new(); - - let mut options = StrokeOptions::default(); + let mut options = tessellation::StrokeOptions::default(); options.line_width = stroke.width; options.start_cap = stroke.line_cap.into(); options.end_cap = stroke.line_cap.into(); options.line_join = stroke.line_join.into(); let result = if self.transforms.current.is_identity { - tessellator.tessellate_path(path.raw(), &options, &mut buffers) + self.stroke_tessellator.tessellate_path( + path.raw(), + &options, + &mut buffers, + ) } else { let path = path.transformed(&self.transforms.current.raw); - tessellator.tessellate_path(path.raw(), &options, &mut buffers) + self.stroke_tessellator.tessellate_path( + path.raw(), + &options, + &mut buffers, + ) }; let _ = result.expect("Stroke path"); -- cgit From 59b3d724edd171c3439c8996a186e53795e51fa5 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Thu, 26 Aug 2021 15:44:32 +0700 Subject: Use `FillTessellator::tessellate_rectangle` in `Frame` --- graphics/src/widget/canvas/frame.rs | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/graphics/src/widget/canvas/frame.rs b/graphics/src/widget/canvas/frame.rs index 2eaa2274..4873e7fb 100644 --- a/graphics/src/widget/canvas/frame.rs +++ b/graphics/src/widget/canvas/frame.rs @@ -118,8 +118,6 @@ impl Frame { size: Size, fill: impl Into, ) { - use lyon::path::builder::PathBuilder; - let Fill { color, rule } = fill.into(); let mut buffers = tessellation::BuffersBuilder::new( @@ -140,14 +138,14 @@ impl Frame { let options = tessellation::FillOptions::default().with_fill_rule(rule.into()); - let mut builder = self.fill_tessellator.builder(&options, &mut buffers); - - builder.add_rectangle( - &lyon::math::Rect::new(top_left, size.into()), - lyon::path::Winding::Positive, - ); - - let _ = builder.build().expect("Fill rectangle"); + let _ = self + .fill_tessellator + .tessellate_rectangle( + &lyon::math::Rect::new(top_left, size.into()), + &options, + &mut buffers, + ) + .expect("Fill rectangle"); } /// Draws the stroke of the given [`Path`] on the [`Frame`] with the -- cgit From 30ce60109eb5020df6ba121c868eebd49af4c037 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Mon, 30 Aug 2021 13:24:30 +0700 Subject: Rely on new fast paths for basic shapes in `lyon` See [1] for more details. [1]: https://github.com/nical/lyon/pull/696 --- graphics/Cargo.toml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/graphics/Cargo.toml b/graphics/Cargo.toml index 15aac4ed..2ff05e1b 100644 --- a/graphics/Cargo.toml +++ b/graphics/Cargo.toml @@ -37,6 +37,8 @@ path = "../style" [dependencies.lyon] version = "0.17" +git = "https://github.com/nical/lyon.git" +rev = "7cf55e76786602e1af767aeec0eccacc783d9d4b" optional = true [dependencies.qrcode] -- cgit From 61dc9defada9a001bfd177b8e67c64add555d96a Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Wed, 1 Sep 2021 13:35:52 +0700 Subject: Rely on latest release of `lyon_tessellation` --- graphics/Cargo.toml | 2 -- 1 file changed, 2 deletions(-) diff --git a/graphics/Cargo.toml b/graphics/Cargo.toml index 2ff05e1b..15aac4ed 100644 --- a/graphics/Cargo.toml +++ b/graphics/Cargo.toml @@ -37,8 +37,6 @@ path = "../style" [dependencies.lyon] version = "0.17" -git = "https://github.com/nical/lyon.git" -rev = "7cf55e76786602e1af767aeec0eccacc783d9d4b" optional = true [dependencies.qrcode] -- cgit