diff options
author | 2022-11-05 04:37:59 +0100 | |
---|---|---|
committer | 2022-11-05 04:37:59 +0100 | |
commit | 370fa14efb8d41bcf81e4a0ead6a9ab7ab750bee (patch) | |
tree | 6a434e6bc8c3a95065faafa533cf1d5e2318cc06 /glow/src/backend.rs | |
parent | 7b129917281baaa6688158c303922f94341ab69f (diff) | |
parent | 078cadfed0e67560d9047d84435e87b8671c5992 (diff) | |
download | iced-370fa14efb8d41bcf81e4a0ead6a9ab7ab750bee.tar.gz iced-370fa14efb8d41bcf81e4a0ead6a9ab7ab750bee.tar.bz2 iced-370fa14efb8d41bcf81e4a0ead6a9ab7ab750bee.zip |
Merge pull request #1485 from ids1024/glow-image
Glow image rendering support; move image/svg code to iced_graphics
Diffstat (limited to 'glow/src/backend.rs')
-rw-r--r-- | glow/src/backend.rs | 30 |
1 files changed, 25 insertions, 5 deletions
diff --git a/glow/src/backend.rs b/glow/src/backend.rs index 21af2ecf..1a41d540 100644 --- a/glow/src/backend.rs +++ b/glow/src/backend.rs @@ -1,3 +1,5 @@ +#[cfg(any(feature = "image", 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", 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", 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", feature = "svg"))] + image_pipeline, quad_pipeline, text_pipeline, triangle_pipeline, @@ -70,6 +78,9 @@ impl Backend { viewport_size.height, ); } + + #[cfg(any(feature = "image", feature = "svg"))] + self.image_pipeline.trim_cache(gl); } fn flush( @@ -112,6 +123,15 @@ impl Backend { ); } + #[cfg(any(feature = "image", 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 @@ -238,8 +258,8 @@ impl backend::Text for Backend { #[cfg(feature = "image")] 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) -> Size<u32> { + self.image_pipeline.dimensions(handle) } } @@ -247,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<u32> { + self.image_pipeline.viewport_dimensions(handle) } } |