Skip to content

Commit

Permalink
fix: image
Browse files Browse the repository at this point in the history
  • Loading branch information
wash2 committed Oct 3, 2024
1 parent b27f2eb commit 363e95a
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 23 deletions.
20 changes: 9 additions & 11 deletions tiny_skia/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -393,18 +393,16 @@ impl core::image::Renderer for Renderer {
border_radius: [f32; 4],
) {
let (layer, transformation) = self.layers.current_mut();
layer.draw_image(
iced_graphics::Image::Raster {
handle: crate::core::Image {
handle,
filter_method,
rotation,
opacity,
snap: true,
border_radius,
},
bounds,
layer.draw_raster(
crate::core::Image {
handle,
filter_method,
rotation,
opacity,
snap: true,
border_radius,
},
bounds,
transformation,
);
}
Expand Down
10 changes: 8 additions & 2 deletions wgpu/src/geometry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -421,7 +421,10 @@ impl geometry::frame::Backend for Frame {

image.rotation += external_rotation;

self.images.push(Image::Raster(image, bounds));
self.images.push(Image::Raster {
handle: image,
bounds,
});
}

fn draw_svg(&mut self, bounds: Rectangle, svg: impl Into<Svg>) {
Expand All @@ -432,7 +435,10 @@ impl geometry::frame::Backend for Frame {

svg.rotation += external_rotation;

self.images.push(Image::Vector(svg, bounds));
self.images.push(Image::Vector {
handle: svg,
bounds,
});
}
}

Expand Down
12 changes: 6 additions & 6 deletions wgpu/src/image/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -222,18 +222,18 @@ impl Pipeline {
for image in images {
match &image {
#[cfg(feature = "image")]
Image::Raster(image, bounds) => {
Image::Raster { handle, bounds } => {
if let Some(atlas_entry) =
cache.upload_raster(device, encoder, &image.handle)
cache.upload_raster(device, encoder, &handle.handle)
{
add_instances(
[bounds.x, bounds.y],
[bounds.width, bounds.height],
f32::from(image.rotation),
image.opacity,
image.snap,
f32::from(handle.rotation),
handle.opacity,
handle.snap,
atlas_entry,
match image.filter_method {
match handle.filter_method {
crate::core::image::FilterMethod::Nearest => {
nearest_instances
}
Expand Down
27 changes: 23 additions & 4 deletions wgpu/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ pub use settings::Settings;
pub use geometry::Geometry;

use crate::core::{
Background, Color, Font, Pixels, Point, Rectangle, Size, Transformation,
Vector,
image::FilterMethod, Background, Color, Font, Pixels, Point, Radians,
Rectangle, Size, Transformation, Vector,
};
use crate::graphics::text::{Editor, Paragraph};
use crate::graphics::Viewport;
Expand Down Expand Up @@ -534,9 +534,28 @@ impl core::image::Renderer for Renderer {
self.image_cache.borrow_mut().measure_image(handle)
}

fn draw_image(&mut self, image: core::Image, bounds: Rectangle) {
fn draw_image(
&mut self,
handle: Self::Handle,
filter_method: FilterMethod,
bounds: Rectangle,
rotation: Radians,
opacity: f32,
border_radius: [f32; 4],
) {
let (layer, transformation) = self.layers.current_mut();
layer.draw_raster(image, bounds, transformation);
layer.draw_raster(
crate::core::Image {
handle,
filter_method,
rotation,
opacity,
snap: true,
border_radius,
},
bounds,
transformation,
);
}
}

Expand Down

0 comments on commit 363e95a

Please sign in to comment.