diff options
Diffstat (limited to 'graphics/src')
-rw-r--r-- | graphics/src/backend.rs | 12 | ||||
-rw-r--r-- | graphics/src/compositor.rs | 15 | ||||
-rw-r--r-- | graphics/src/lib.rs | 1 | ||||
-rw-r--r-- | graphics/src/renderer.rs | 28 |
4 files changed, 23 insertions, 33 deletions
diff --git a/graphics/src/backend.rs b/graphics/src/backend.rs index ae89da06..6a082576 100644 --- a/graphics/src/backend.rs +++ b/graphics/src/backend.rs @@ -6,18 +6,6 @@ use iced_core::{Font, Point, Size}; use std::borrow::Cow; -/// The graphics backend of a [`Renderer`]. -/// -/// [`Renderer`]: crate::Renderer -pub trait Backend { - /// Trims the measurements cache. - /// - /// This method is currently necessary to properly trim the text cache in - /// `iced_wgpu` and `iced_glow` because of limitations in the text rendering - /// pipeline. It will be removed in the future. - fn trim_measurements(&mut self) {} -} - /// A graphics backend that supports text rendering. pub trait Text { /// The icon font of the backend. diff --git a/graphics/src/compositor.rs b/graphics/src/compositor.rs index d55e801a..f7b86045 100644 --- a/graphics/src/compositor.rs +++ b/graphics/src/compositor.rs @@ -59,6 +59,19 @@ pub trait Compositor: Sized { background_color: Color, overlay: &[T], ) -> Result<(), SurfaceError>; + + /// Screenshots the current [`Renderer`] primitives to an offscreen texture, and returns the bytes of + /// the texture ordered as `RGBA` in the sRGB color space. + /// + /// [`Renderer`]: Self::Renderer; + fn screenshot<T: AsRef<str>>( + &mut self, + renderer: &mut Self::Renderer, + surface: &mut Self::Surface, + viewport: &Viewport, + background_color: Color, + overlay: &[T], + ) -> Vec<u8>; } /// Result of an unsuccessful call to [`Compositor::present`]. @@ -82,7 +95,7 @@ pub enum SurfaceError { OutOfMemory, } -/// Contains informations about the graphics (e.g. graphics adapter, graphics backend). +/// Contains information about the graphics (e.g. graphics adapter, graphics backend). #[derive(Debug)] pub struct Information { /// Contains the graphics adapter. diff --git a/graphics/src/lib.rs b/graphics/src/lib.rs index f6bc87fb..226b245b 100644 --- a/graphics/src/lib.rs +++ b/graphics/src/lib.rs @@ -41,7 +41,6 @@ pub mod geometry; pub mod image; pub use antialiasing::Antialiasing; -pub use backend::Backend; pub use compositor::Compositor; pub use error::Error; pub use gradient::Gradient; diff --git a/graphics/src/renderer.rs b/graphics/src/renderer.rs index de905503..4241d45c 100644 --- a/graphics/src/renderer.rs +++ b/graphics/src/renderer.rs @@ -1,5 +1,5 @@ //! Create a renderer from a [`Backend`]. -use crate::backend::{self, Backend}; +use crate::backend; use crate::Primitive; use iced_core::image; @@ -16,13 +16,13 @@ use std::marker::PhantomData; /// A backend-agnostic renderer that supports all the built-in widgets. #[derive(Debug)] -pub struct Renderer<B: Backend, Theme> { +pub struct Renderer<B, Theme> { backend: B, primitives: Vec<Primitive>, theme: PhantomData<Theme>, } -impl<B: Backend, T> Renderer<B, T> { +impl<B, T> Renderer<B, T> { /// Creates a new [`Renderer`] from the given [`Backend`]. pub fn new(backend: B) -> Self { Self { @@ -52,10 +52,7 @@ impl<B: Backend, T> Renderer<B, T> { } } -impl<B, T> iced_core::Renderer for Renderer<B, T> -where - B: Backend, -{ +impl<B, T> iced_core::Renderer for Renderer<B, T> { type Theme = T; fn layout<Message>( @@ -63,11 +60,7 @@ where element: &Element<'_, Message, Self>, limits: &layout::Limits, ) -> layout::Node { - let layout = element.as_widget().layout(self, limits); - - self.backend.trim_measurements(); - - layout + element.as_widget().layout(self, limits) } fn with_layer(&mut self, bounds: Rectangle, f: impl FnOnce(&mut Self)) { @@ -116,7 +109,7 @@ where impl<B, T> text::Renderer for Renderer<B, T> where - B: Backend + backend::Text, + B: backend::Text, { type Font = Font; @@ -195,7 +188,7 @@ where impl<B, T> image::Renderer for Renderer<B, T> where - B: Backend + backend::Image, + B: backend::Image, { type Handle = image::Handle; @@ -210,7 +203,7 @@ where impl<B, T> svg::Renderer for Renderer<B, T> where - B: Backend + backend::Svg, + B: backend::Svg, { fn dimensions(&self, handle: &svg::Handle) -> Size<u32> { self.backend().viewport_dimensions(handle) @@ -231,10 +224,7 @@ where } #[cfg(feature = "geometry")] -impl<B, T> crate::geometry::Renderer for Renderer<B, T> -where - B: Backend, -{ +impl<B, T> crate::geometry::Renderer for Renderer<B, T> { fn draw(&mut self, layers: Vec<crate::Geometry>) { self.primitives .extend(layers.into_iter().map(crate::Geometry::into)); |