summaryrefslogtreecommitdiffstats
path: root/wgpu
diff options
context:
space:
mode:
authorLibravatar Héctor Ramón Jiménez <hector@hecrj.dev>2024-08-04 04:30:12 +0200
committerLibravatar Héctor Ramón Jiménez <hector@hecrj.dev>2024-08-04 04:30:12 +0200
commit92bd3ecd6b4a6618f0fc725dea3694c3b40e5314 (patch)
tree8040fe0f758eb41cbf587119c5d972f5ebaa8567 /wgpu
parent974ae6d1e7cd9df6967762a6d308106f4fe03edc (diff)
downloadiced-92bd3ecd6b4a6618f0fc725dea3694c3b40e5314.tar.gz
iced-92bd3ecd6b4a6618f0fc725dea3694c3b40e5314.tar.bz2
iced-92bd3ecd6b4a6618f0fc725dea3694c3b40e5314.zip
Introduce `Image` struct in `core::image`
Diffstat (limited to 'wgpu')
-rw-r--r--wgpu/src/geometry.rs35
-rw-r--r--wgpu/src/image/mod.rs19
-rw-r--r--wgpu/src/layer.rs51
-rw-r--r--wgpu/src/lib.rs23
4 files changed, 33 insertions, 95 deletions
diff --git a/wgpu/src/geometry.rs b/wgpu/src/geometry.rs
index cb629b3e..6b1bb074 100644
--- a/wgpu/src/geometry.rs
+++ b/wgpu/src/geometry.rs
@@ -1,5 +1,4 @@
//! Build and draw geometry.
-use crate::core::image;
use crate::core::svg;
use crate::core::text::LineHeight;
use crate::core::{
@@ -9,11 +8,11 @@ use crate::graphics::cache::{self, Cached};
use crate::graphics::color;
use crate::graphics::geometry::fill::{self, Fill};
use crate::graphics::geometry::{
- self, LineCap, LineDash, LineJoin, Path, Stroke, Style,
+ self, Image, LineCap, LineDash, LineJoin, Path, Stroke, Style,
};
use crate::graphics::gradient::{self, Gradient};
use crate::graphics::mesh::{self, Mesh};
-use crate::graphics::{self, Image, Text};
+use crate::graphics::{self, Text};
use crate::text;
use crate::triangle;
@@ -27,7 +26,7 @@ use std::sync::Arc;
pub enum Geometry {
Live {
meshes: Vec<Mesh>,
- images: Vec<Image>,
+ images: Vec<graphics::Image>,
text: Vec<Text>,
},
Cached(Cache),
@@ -36,7 +35,7 @@ pub enum Geometry {
#[derive(Debug, Clone)]
pub struct Cache {
pub meshes: Option<triangle::Cache>,
- pub images: Option<Arc<[Image]>>,
+ pub images: Option<Arc<[graphics::Image]>>,
pub text: Option<text::Cache>,
}
@@ -99,7 +98,7 @@ pub struct Frame {
clip_bounds: Rectangle,
buffers: BufferStack,
meshes: Vec<Mesh>,
- images: Vec<Image>,
+ images: Vec<graphics::Image>,
text: Vec<Text>,
transforms: Transforms,
fill_tessellator: tessellation::FillTessellator,
@@ -377,25 +376,15 @@ impl geometry::frame::Backend for Frame {
}
}
- fn draw_image(
- &mut self,
- handle: &image::Handle,
- bounds: Rectangle,
- filter_method: image::FilterMethod,
- rotation: Radians,
- opacity: f32,
- ) {
+ fn draw_image(&mut self, bounds: Rectangle, image: impl Into<Image>) {
+ let mut image = image.into();
+
let (bounds, external_rotation) =
self.transforms.current.transform_rectangle(bounds);
- self.images.push(Image::Raster {
- handle: handle.clone(),
- filter_method,
- bounds,
- rotation: rotation + external_rotation,
- opacity,
- snap: false,
- });
+ image.rotation += external_rotation;
+
+ self.images.push(graphics::Image::Raster(image, bounds));
}
fn draw_svg(
@@ -409,7 +398,7 @@ impl geometry::frame::Backend for Frame {
let (bounds, external_rotation) =
self.transforms.current.transform_rectangle(bounds);
- self.images.push(Image::Vector {
+ self.images.push(graphics::Image::Vector {
handle: handle.clone(),
color,
bounds,
diff --git a/wgpu/src/image/mod.rs b/wgpu/src/image/mod.rs
index ea34e4ec..2b0d6251 100644
--- a/wgpu/src/image/mod.rs
+++ b/wgpu/src/image/mod.rs
@@ -220,25 +220,18 @@ impl Pipeline {
for image in images {
match &image {
#[cfg(feature = "image")]
- Image::Raster {
- handle,
- filter_method,
- bounds,
- rotation,
- opacity,
- snap,
- } => {
+ Image::Raster(image, bounds) => {
if let Some(atlas_entry) =
- cache.upload_raster(device, encoder, handle)
+ cache.upload_raster(device, encoder, &image.handle)
{
add_instances(
[bounds.x, bounds.y],
[bounds.width, bounds.height],
- f32::from(*rotation),
- *opacity,
- *snap,
+ f32::from(image.rotation),
+ image.opacity,
+ image.snap,
atlas_entry,
- match filter_method {
+ match image.filter_method {
crate::core::image::FilterMethod::Nearest => {
nearest_instances
}
diff --git a/wgpu/src/layer.rs b/wgpu/src/layer.rs
index e714e281..71fa0250 100644
--- a/wgpu/src/layer.rs
+++ b/wgpu/src/layer.rs
@@ -1,5 +1,6 @@
use crate::core::{
- renderer, Background, Color, Point, Radians, Rectangle, Transformation,
+ self, renderer, Background, Color, Point, Radians, Rectangle,
+ Transformation,
};
use crate::graphics;
use crate::graphics::color;
@@ -112,29 +113,10 @@ impl Layer {
self.pending_text.push(text);
}
- pub fn draw_image(
- &mut self,
- image: &Image,
- transformation: Transformation,
- ) {
+ pub fn draw_image(&mut self, image: Image, transformation: Transformation) {
match image {
- Image::Raster {
- handle,
- filter_method,
- bounds,
- rotation,
- opacity,
- snap,
- } => {
- self.draw_raster(
- handle.clone(),
- *filter_method,
- *bounds,
- transformation,
- *rotation,
- *opacity,
- *snap,
- );
+ Image::Raster(image, bounds) => {
+ self.draw_raster(image, bounds, transformation);
}
Image::Vector {
handle,
@@ -145,11 +127,11 @@ impl Layer {
} => {
self.draw_svg(
handle.clone(),
- *color,
- *bounds,
+ color,
+ bounds,
transformation,
- *rotation,
- *opacity,
+ rotation,
+ opacity,
);
}
}
@@ -157,22 +139,11 @@ impl Layer {
pub fn draw_raster(
&mut self,
- handle: crate::core::image::Handle,
- filter_method: crate::core::image::FilterMethod,
+ image: core::Image,
bounds: Rectangle,
transformation: Transformation,
- rotation: Radians,
- opacity: f32,
- snap: bool,
) {
- let image = Image::Raster {
- handle,
- filter_method,
- bounds: bounds * transformation,
- rotation,
- opacity,
- snap,
- };
+ let image = Image::Raster(image, bounds * transformation);
self.images.push(image);
}
diff --git a/wgpu/src/lib.rs b/wgpu/src/lib.rs
index 24e60979..e5f45ad2 100644
--- a/wgpu/src/lib.rs
+++ b/wgpu/src/lib.rs
@@ -527,24 +527,9 @@ impl core::image::Renderer for Renderer {
self.image_cache.borrow_mut().measure_image(handle)
}
- fn draw_image(
- &mut self,
- handle: Self::Handle,
- filter_method: core::image::FilterMethod,
- bounds: Rectangle,
- rotation: core::Radians,
- opacity: f32,
- ) {
+ fn draw_image(&mut self, image: core::Image, bounds: Rectangle) {
let (layer, transformation) = self.layers.current_mut();
- layer.draw_raster(
- handle,
- filter_method,
- bounds,
- transformation,
- rotation,
- opacity,
- true,
- );
+ layer.draw_raster(image, bounds, transformation);
}
}
@@ -602,7 +587,7 @@ impl graphics::geometry::Renderer for Renderer {
layer.draw_mesh_group(meshes, transformation);
for image in images {
- layer.draw_image(&image, transformation);
+ layer.draw_image(image, transformation);
}
layer.draw_text_group(text, transformation);
@@ -613,7 +598,7 @@ impl graphics::geometry::Renderer for Renderer {
}
if let Some(images) = cache.images {
- for image in images.iter() {
+ for image in images.iter().cloned() {
layer.draw_image(image, transformation);
}
}