summaryrefslogtreecommitdiffstats
path: root/wgpu
diff options
context:
space:
mode:
authorLibravatar Héctor Ramón Jiménez <hector@hecrj.dev>2024-08-04 04:52:55 +0200
committerLibravatar Héctor Ramón Jiménez <hector@hecrj.dev>2024-08-04 04:52:55 +0200
commitd4b08462e5a25929ec4df32f242898986902af56 (patch)
tree4c6aaf8519b416ebf075fd780e533543416cc81e /wgpu
parent8708101c892540ffc966cf7ee9d66ca5cd2e8ca6 (diff)
downloadiced-d4b08462e5a25929ec4df32f242898986902af56.tar.gz
iced-d4b08462e5a25929ec4df32f242898986902af56.tar.bz2
iced-d4b08462e5a25929ec4df32f242898986902af56.zip
Introduce `Svg` struct in `core::svg`
Diffstat (limited to 'wgpu')
-rw-r--r--wgpu/src/geometry.rs40
-rw-r--r--wgpu/src/image/mod.rs19
-rw-r--r--wgpu/src/layer.rs33
-rw-r--r--wgpu/src/lib.rs18
4 files changed, 31 insertions, 79 deletions
diff --git a/wgpu/src/geometry.rs b/wgpu/src/geometry.rs
index 6b1bb074..be65ba36 100644
--- a/wgpu/src/geometry.rs
+++ b/wgpu/src/geometry.rs
@@ -1,18 +1,17 @@
//! Build and draw geometry.
-use crate::core::svg;
use crate::core::text::LineHeight;
use crate::core::{
- Color, Pixels, Point, Radians, Rectangle, Size, Transformation, Vector,
+ self, Pixels, Point, Radians, Rectangle, Size, Svg, Transformation, Vector,
};
use crate::graphics::cache::{self, Cached};
use crate::graphics::color;
use crate::graphics::geometry::fill::{self, Fill};
use crate::graphics::geometry::{
- self, Image, LineCap, LineDash, LineJoin, Path, Stroke, Style,
+ self, LineCap, LineDash, LineJoin, Path, Stroke, Style,
};
use crate::graphics::gradient::{self, Gradient};
use crate::graphics::mesh::{self, Mesh};
-use crate::graphics::{self, Text};
+use crate::graphics::{Image, Text};
use crate::text;
use crate::triangle;
@@ -26,7 +25,7 @@ use std::sync::Arc;
pub enum Geometry {
Live {
meshes: Vec<Mesh>,
- images: Vec<graphics::Image>,
+ images: Vec<Image>,
text: Vec<Text>,
},
Cached(Cache),
@@ -35,7 +34,7 @@ pub enum Geometry {
#[derive(Debug, Clone)]
pub struct Cache {
pub meshes: Option<triangle::Cache>,
- pub images: Option<Arc<[graphics::Image]>>,
+ pub images: Option<Arc<[Image]>>,
pub text: Option<text::Cache>,
}
@@ -98,7 +97,7 @@ pub struct Frame {
clip_bounds: Rectangle,
buffers: BufferStack,
meshes: Vec<Mesh>,
- images: Vec<graphics::Image>,
+ images: Vec<Image>,
text: Vec<Text>,
transforms: Transforms,
fill_tessellator: tessellation::FillTessellator,
@@ -292,7 +291,7 @@ impl geometry::frame::Backend for Frame {
height: f32::INFINITY,
};
- self.text.push(graphics::Text::Cached {
+ self.text.push(Text::Cached {
content: text.content,
bounds,
color: text.color,
@@ -376,7 +375,7 @@ impl geometry::frame::Backend for Frame {
}
}
- fn draw_image(&mut self, bounds: Rectangle, image: impl Into<Image>) {
+ fn draw_image(&mut self, bounds: Rectangle, image: impl Into<core::Image>) {
let mut image = image.into();
let (bounds, external_rotation) =
@@ -384,27 +383,18 @@ impl geometry::frame::Backend for Frame {
image.rotation += external_rotation;
- self.images.push(graphics::Image::Raster(image, bounds));
+ self.images.push(Image::Raster(image, bounds));
}
- fn draw_svg(
- &mut self,
- handle: &svg::Handle,
- bounds: Rectangle,
- color: Option<Color>,
- rotation: Radians,
- opacity: f32,
- ) {
+ fn draw_svg(&mut self, bounds: Rectangle, svg: impl Into<Svg>) {
+ let mut svg = svg.into();
+
let (bounds, external_rotation) =
self.transforms.current.transform_rectangle(bounds);
- self.images.push(graphics::Image::Vector {
- handle: handle.clone(),
- color,
- bounds,
- rotation: rotation + external_rotation,
- opacity,
- });
+ svg.rotation += external_rotation;
+
+ self.images.push(Image::Vector(svg, bounds));
}
}
diff --git a/wgpu/src/image/mod.rs b/wgpu/src/image/mod.rs
index 2b0d6251..1b16022a 100644
--- a/wgpu/src/image/mod.rs
+++ b/wgpu/src/image/mod.rs
@@ -246,23 +246,22 @@ impl Pipeline {
Image::Raster { .. } => {}
#[cfg(feature = "svg")]
- Image::Vector {
- handle,
- color,
- bounds,
- rotation,
- opacity,
- } => {
+ Image::Vector(svg, bounds) => {
let size = [bounds.width, bounds.height];
if let Some(atlas_entry) = cache.upload_vector(
- device, encoder, handle, *color, size, scale,
+ device,
+ encoder,
+ &svg.handle,
+ svg.color,
+ size,
+ scale,
) {
add_instances(
[bounds.x, bounds.y],
size,
- f32::from(*rotation),
- *opacity,
+ f32::from(svg.rotation),
+ svg.opacity,
true,
atlas_entry,
nearest_instances,
diff --git a/wgpu/src/layer.rs b/wgpu/src/layer.rs
index 71fa0250..68d5a015 100644
--- a/wgpu/src/layer.rs
+++ b/wgpu/src/layer.rs
@@ -1,6 +1,5 @@
use crate::core::{
- self, renderer, Background, Color, Point, Radians, Rectangle,
- Transformation,
+ self, renderer, Background, Color, Point, Rectangle, Svg, Transformation,
};
use crate::graphics;
use crate::graphics::color;
@@ -118,21 +117,8 @@ impl Layer {
Image::Raster(image, bounds) => {
self.draw_raster(image, bounds, transformation);
}
- Image::Vector {
- handle,
- color,
- bounds,
- rotation,
- opacity,
- } => {
- self.draw_svg(
- handle.clone(),
- color,
- bounds,
- transformation,
- rotation,
- opacity,
- );
+ Image::Vector(svg, bounds) => {
+ self.draw_svg(svg, bounds, transformation);
}
}
}
@@ -150,20 +136,11 @@ impl Layer {
pub fn draw_svg(
&mut self,
- handle: crate::core::svg::Handle,
- color: Option<Color>,
+ svg: Svg,
bounds: Rectangle,
transformation: Transformation,
- rotation: Radians,
- opacity: f32,
) {
- let svg = Image::Vector {
- handle,
- color,
- bounds: bounds * transformation,
- rotation,
- opacity,
- };
+ let svg = Image::Vector(svg, bounds * transformation);
self.images.push(svg);
}
diff --git a/wgpu/src/lib.rs b/wgpu/src/lib.rs
index e5f45ad2..39167514 100644
--- a/wgpu/src/lib.rs
+++ b/wgpu/src/lib.rs
@@ -539,23 +539,9 @@ impl core::svg::Renderer for Renderer {
self.image_cache.borrow_mut().measure_svg(handle)
}
- fn draw_svg(
- &mut self,
- handle: core::svg::Handle,
- color_filter: Option<Color>,
- bounds: Rectangle,
- rotation: core::Radians,
- opacity: f32,
- ) {
+ fn draw_svg(&mut self, svg: core::Svg, bounds: Rectangle) {
let (layer, transformation) = self.layers.current_mut();
- layer.draw_svg(
- handle,
- color_filter,
- bounds,
- transformation,
- rotation,
- opacity,
- );
+ layer.draw_svg(svg, bounds, transformation);
}
}