From 5575e6ea0897e406674e7e4239808fbf9daa07c3 Mon Sep 17 00:00:00 2001 From: Ian Douglas Scott Date: Mon, 24 Oct 2022 17:06:02 -0700 Subject: Add image/svg support to `iced_glow` https://github.com/iced-rs/iced/issues/674 Uses image/svg support in `iced_graphics`. The is not currently using an atlas, and uses one texture/draw per image. This should be good enough for now; supporting images with glow is better than not supporting them, and if something else performs better, that improvement can be made without any change to the public API. --- glow/src/backend.rs | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) (limited to 'glow/src/backend.rs') diff --git a/glow/src/backend.rs b/glow/src/backend.rs index 21af2ecf..1ba70a49 100644 --- a/glow/src/backend.rs +++ b/glow/src/backend.rs @@ -1,3 +1,5 @@ +#[cfg(any(feature = "image_rs", feature = "svg"))] +use crate::image; use crate::quad; use crate::text; use crate::{program, triangle}; @@ -15,6 +17,8 @@ use iced_native::{Font, Size}; /// [`iced`]: https://github.com/iced-rs/iced #[derive(Debug)] pub struct Backend { + #[cfg(any(feature = "image_rs", feature = "svg"))] + image_pipeline: image::Pipeline, quad_pipeline: quad::Pipeline, text_pipeline: text::Pipeline, triangle_pipeline: triangle::Pipeline, @@ -32,10 +36,14 @@ impl Backend { let shader_version = program::Version::new(gl); + #[cfg(any(feature = "image_rs", feature = "svg"))] + let image_pipeline = image::Pipeline::new(gl, &shader_version); let quad_pipeline = quad::Pipeline::new(gl, &shader_version); let triangle_pipeline = triangle::Pipeline::new(gl, &shader_version); Self { + #[cfg(any(feature = "image_rs", feature = "svg"))] + image_pipeline, quad_pipeline, text_pipeline, triangle_pipeline, @@ -70,6 +78,9 @@ impl Backend { viewport_size.height, ); } + + #[cfg(any(feature = "image_rs", feature = "svg"))] + self.image_pipeline.trim_cache(gl); } fn flush( @@ -112,6 +123,15 @@ impl Backend { ); } + #[cfg(any(feature = "image_rs", feature = "svg"))] + if !layer.images.is_empty() { + let scaled = transformation + * Transformation::scale(scale_factor, scale_factor); + + self.image_pipeline + .draw(gl, scaled, scale_factor, &layer.images); + } + if !layer.text.is_empty() { for text in layer.text.iter() { // Target physical coordinates directly to avoid blurry text @@ -236,10 +256,10 @@ impl backend::Text for Backend { } } -#[cfg(feature = "image")] +#[cfg(feature = "image_rs")] impl backend::Image for Backend { - fn dimensions(&self, _handle: &iced_native::image::Handle) -> (u32, u32) { - (50, 50) + fn dimensions(&self, handle: &iced_native::image::Handle) -> (u32, u32) { + self.image_pipeline.dimensions(handle) } } -- cgit From 8ce8d374b1e8d1d394a42a5ee2bca8af790f0b71 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Sat, 5 Nov 2022 03:13:04 +0100 Subject: Refactor some `image` traits a bit - Use `Size` were applicable. - Rename `TextureStore` to `image::Storage`. - Rename `TextureStoreEntry` to `image::storage::Entry`. - Wire up `viewport_dimensions` to `iced_glow` for `Svg`. --- glow/src/backend.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'glow/src/backend.rs') diff --git a/glow/src/backend.rs b/glow/src/backend.rs index 1ba70a49..35a82c0f 100644 --- a/glow/src/backend.rs +++ b/glow/src/backend.rs @@ -258,7 +258,7 @@ impl backend::Text for Backend { #[cfg(feature = "image_rs")] impl backend::Image for Backend { - fn dimensions(&self, handle: &iced_native::image::Handle) -> (u32, u32) { + fn dimensions(&self, handle: &iced_native::image::Handle) -> Size { self.image_pipeline.dimensions(handle) } } @@ -267,8 +267,8 @@ impl backend::Image for Backend { impl backend::Svg for Backend { fn viewport_dimensions( &self, - _handle: &iced_native::svg::Handle, - ) -> (u32, u32) { - (50, 50) + handle: &iced_native::svg::Handle, + ) -> Size { + self.image_pipeline.viewport_dimensions(handle) } } -- cgit From 0a23f518c70d27f2e44af38e5d3be2a0ab1a9bc1 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Sat, 5 Nov 2022 03:26:19 +0100 Subject: Remove redundant features in `iced_wgpu` and `iced_glow` --- glow/src/backend.rs | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'glow/src/backend.rs') diff --git a/glow/src/backend.rs b/glow/src/backend.rs index 35a82c0f..1a41d540 100644 --- a/glow/src/backend.rs +++ b/glow/src/backend.rs @@ -1,4 +1,4 @@ -#[cfg(any(feature = "image_rs", feature = "svg"))] +#[cfg(any(feature = "image", feature = "svg"))] use crate::image; use crate::quad; use crate::text; @@ -17,7 +17,7 @@ use iced_native::{Font, Size}; /// [`iced`]: https://github.com/iced-rs/iced #[derive(Debug)] pub struct Backend { - #[cfg(any(feature = "image_rs", feature = "svg"))] + #[cfg(any(feature = "image", feature = "svg"))] image_pipeline: image::Pipeline, quad_pipeline: quad::Pipeline, text_pipeline: text::Pipeline, @@ -36,13 +36,13 @@ impl Backend { let shader_version = program::Version::new(gl); - #[cfg(any(feature = "image_rs", feature = "svg"))] + #[cfg(any(feature = "image", feature = "svg"))] let image_pipeline = image::Pipeline::new(gl, &shader_version); let quad_pipeline = quad::Pipeline::new(gl, &shader_version); let triangle_pipeline = triangle::Pipeline::new(gl, &shader_version); Self { - #[cfg(any(feature = "image_rs", feature = "svg"))] + #[cfg(any(feature = "image", feature = "svg"))] image_pipeline, quad_pipeline, text_pipeline, @@ -79,7 +79,7 @@ impl Backend { ); } - #[cfg(any(feature = "image_rs", feature = "svg"))] + #[cfg(any(feature = "image", feature = "svg"))] self.image_pipeline.trim_cache(gl); } @@ -123,7 +123,7 @@ impl Backend { ); } - #[cfg(any(feature = "image_rs", feature = "svg"))] + #[cfg(any(feature = "image", feature = "svg"))] if !layer.images.is_empty() { let scaled = transformation * Transformation::scale(scale_factor, scale_factor); @@ -256,7 +256,7 @@ impl backend::Text for Backend { } } -#[cfg(feature = "image_rs")] +#[cfg(feature = "image")] impl backend::Image for Backend { fn dimensions(&self, handle: &iced_native::image::Handle) -> Size { self.image_pipeline.dimensions(handle) -- cgit From 751ffb590053d713ea376893a1d9050514b8ffe1 Mon Sep 17 00:00:00 2001 From: Ashley Wulber Date: Wed, 23 Nov 2022 13:37:59 -0500 Subject: fix: scissor layout bounds for images --- glow/src/backend.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'glow/src/backend.rs') diff --git a/glow/src/backend.rs b/glow/src/backend.rs index 1a41d540..c663869e 100644 --- a/glow/src/backend.rs +++ b/glow/src/backend.rs @@ -129,7 +129,7 @@ impl Backend { * Transformation::scale(scale_factor, scale_factor); self.image_pipeline - .draw(gl, scaled, scale_factor, &layer.images); + .draw(gl, scaled, scale_factor, &layer.images, bounds); } if !layer.text.is_empty() { -- cgit From 84c5ee7fb2d716e1d3c35a53a2cd33fcc6fafc3a Mon Sep 17 00:00:00 2001 From: Ashley Wulber Date: Wed, 23 Nov 2022 13:40:06 -0500 Subject: cargo fmt --- glow/src/backend.rs | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'glow/src/backend.rs') diff --git a/glow/src/backend.rs b/glow/src/backend.rs index c663869e..645c5faf 100644 --- a/glow/src/backend.rs +++ b/glow/src/backend.rs @@ -128,8 +128,13 @@ impl Backend { let scaled = transformation * Transformation::scale(scale_factor, scale_factor); - self.image_pipeline - .draw(gl, scaled, scale_factor, &layer.images, bounds); + self.image_pipeline.draw( + gl, + scaled, + scale_factor, + &layer.images, + bounds, + ); } if !layer.text.is_empty() { -- cgit From efc00b2f412865b975088002cbe3c927ef662e10 Mon Sep 17 00:00:00 2001 From: Ashley Wulber Date: Wed, 23 Nov 2022 14:46:57 -0500 Subject: fix: adjust y position of scissor rectangle --- glow/src/backend.rs | 1 + 1 file changed, 1 insertion(+) (limited to 'glow/src/backend.rs') diff --git a/glow/src/backend.rs b/glow/src/backend.rs index 645c5faf..416c3b94 100644 --- a/glow/src/backend.rs +++ b/glow/src/backend.rs @@ -130,6 +130,7 @@ impl Backend { self.image_pipeline.draw( gl, + target_height, scaled, scale_factor, &layer.images, -- cgit