From bb49e17cabd45f3a21af98b4c5ecdddd507fd427 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Tue, 7 Mar 2023 05:06:26 +0100 Subject: Implement `raster` pipeline in `iced_tiny_skia` --- tiny_skia/src/backend.rs | 28 +++++++++++++++++++++++----- 1 file changed, 23 insertions(+), 5 deletions(-) (limited to 'tiny_skia/src/backend.rs') diff --git a/tiny_skia/src/backend.rs b/tiny_skia/src/backend.rs index d364e36a..d894ab95 100644 --- a/tiny_skia/src/backend.rs +++ b/tiny_skia/src/backend.rs @@ -11,6 +11,9 @@ pub struct Backend { default_font: Font, default_text_size: f32, text_pipeline: crate::text::Pipeline, + + #[cfg(feature = "image")] + raster_pipeline: crate::raster::Pipeline, } impl Backend { @@ -19,6 +22,9 @@ impl Backend { default_font: settings.default_font, default_text_size: settings.default_text_size, text_pipeline: crate::text::Pipeline::new(), + + #[cfg(feature = "image")] + raster_pipeline: crate::raster::Pipeline::new(), } } @@ -159,8 +165,21 @@ impl Backend { clip_bounds.map(|_| clip_mask as &_), ); } - Primitive::Image { .. } => { - // TODO + #[cfg(feature = "image")] + Primitive::Image { handle, bounds } => { + let transform = tiny_skia::Transform::from_translate( + translation.x, + translation.y, + ) + .post_scale(scale_factor, scale_factor); + + self.raster_pipeline.draw( + handle, + *bounds, + pixels, + transform, + clip_bounds.map(|_| clip_mask as &_), + ); } Primitive::Svg { .. } => { // TODO @@ -490,9 +509,8 @@ impl backend::Text for Backend { #[cfg(feature = "image")] impl backend::Image for Backend { - fn dimensions(&self, _handle: &crate::core::image::Handle) -> Size { - // TODO - Size::new(0, 0) + fn dimensions(&self, handle: &crate::core::image::Handle) -> Size { + self.raster_pipeline.dimensions(handle) } } -- cgit