From 1f13a91361258a1607c71f4840a26a6437f88612 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Fri, 22 Mar 2024 05:27:31 +0100 Subject: Make `iced_tiny_skia` optional with a `tiny-skia` feature --- graphics/src/compositor.rs | 62 +++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 61 insertions(+), 1 deletion(-) (limited to 'graphics/src/compositor.rs') diff --git a/graphics/src/compositor.rs b/graphics/src/compositor.rs index 91951a8e..32cea46a 100644 --- a/graphics/src/compositor.rs +++ b/graphics/src/compositor.rs @@ -15,7 +15,7 @@ pub trait Compositor: Sized { type Settings: Default; /// The iced renderer of the backend. - type Renderer: iced_core::Renderer; + type Renderer; /// The surface of the backend. type Surface; @@ -122,3 +122,63 @@ pub struct Information { /// Contains the graphics backend. pub backend: String, } + +impl Compositor for () { + type Settings = (); + type Renderer = (); + type Surface = (); + + async fn new( + _settings: Self::Settings, + _compatible_window: W, + ) -> Result { + Ok(()) + } + + fn create_renderer(&self) -> Self::Renderer {} + + fn create_surface( + &mut self, + _window: W, + _width: u32, + _height: u32, + ) -> Self::Surface { + } + + fn configure_surface( + &mut self, + _surface: &mut Self::Surface, + _width: u32, + _height: u32, + ) { + } + + fn fetch_information(&self) -> Information { + Information { + adapter: String::from("Null Renderer"), + backend: String::from("Null"), + } + } + + fn present>( + &mut self, + _renderer: &mut Self::Renderer, + _surface: &mut Self::Surface, + _viewport: &Viewport, + _background_color: Color, + _overlay: &[T], + ) -> Result<(), SurfaceError> { + Ok(()) + } + + fn screenshot>( + &mut self, + _renderer: &mut Self::Renderer, + _surface: &mut Self::Surface, + _viewport: &Viewport, + _background_color: Color, + _overlay: &[T], + ) -> Vec { + vec![] + } +} -- cgit From 5137d655e6bbd29581fc1469d0385515113f2999 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Fri, 22 Mar 2024 07:09:51 +0100 Subject: Allow custom renderers in `Program` and `Application` --- graphics/src/compositor.rs | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) (limited to 'graphics/src/compositor.rs') diff --git a/graphics/src/compositor.rs b/graphics/src/compositor.rs index 32cea46a..4d548f30 100644 --- a/graphics/src/compositor.rs +++ b/graphics/src/compositor.rs @@ -1,9 +1,9 @@ //! A compositor is responsible for initializing a renderer and managing window //! surfaces. -use crate::{Error, Viewport}; - +use crate::core; use crate::core::Color; use crate::futures::{MaybeSend, MaybeSync}; +use crate::{Error, Settings, Viewport}; use raw_window_handle::{HasDisplayHandle, HasWindowHandle}; use std::future::Future; @@ -11,9 +11,6 @@ use thiserror::Error; /// A graphics compositor that can draw to windows. pub trait Compositor: Sized { - /// The settings of the backend. - type Settings: Default; - /// The iced renderer of the backend. type Renderer; @@ -22,7 +19,7 @@ pub trait Compositor: Sized { /// Creates a new [`Compositor`]. fn new( - settings: Self::Settings, + settings: Settings, compatible_window: W, ) -> impl Future>; @@ -93,6 +90,12 @@ impl Window for T where { } +/// A renderer that supports composition. +pub trait Renderer: core::Renderer { + /// The compositor of the renderer. + type Compositor: Compositor; +} + /// Result of an unsuccessful call to [`Compositor::present`]. #[derive(Clone, PartialEq, Eq, Debug, Error)] pub enum SurfaceError { @@ -123,13 +126,13 @@ pub struct Information { pub backend: String, } +#[cfg(debug_assertions)] impl Compositor for () { - type Settings = (); type Renderer = (); type Surface = (); async fn new( - _settings: Self::Settings, + _settings: Settings, _compatible_window: W, ) -> Result { Ok(()) @@ -182,3 +185,8 @@ impl Compositor for () { vec![] } } + +#[cfg(debug_assertions)] +impl Renderer for () { + type Compositor = (); +} -- cgit From 441e9237cd1c9c9b61d9b144b5b4dafa236ace28 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Fri, 22 Mar 2024 19:35:19 +0100 Subject: Rename `compositor::Renderer` to `Default` --- graphics/src/compositor.rs | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to 'graphics/src/compositor.rs') diff --git a/graphics/src/compositor.rs b/graphics/src/compositor.rs index 4d548f30..8c67cd16 100644 --- a/graphics/src/compositor.rs +++ b/graphics/src/compositor.rs @@ -1,6 +1,5 @@ //! A compositor is responsible for initializing a renderer and managing window //! surfaces. -use crate::core; use crate::core::Color; use crate::futures::{MaybeSend, MaybeSync}; use crate::{Error, Settings, Viewport}; @@ -90,8 +89,8 @@ impl Window for T where { } -/// A renderer that supports composition. -pub trait Renderer: core::Renderer { +/// Defines the default compositor of a renderer. +pub trait Default { /// The compositor of the renderer. type Compositor: Compositor; } @@ -187,6 +186,6 @@ impl Compositor for () { } #[cfg(debug_assertions)] -impl Renderer for () { +impl Default for () { type Compositor = (); } -- cgit From 4f5b63f1f4cd7d3ab72289c697f4abc767114eca Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Sun, 24 Mar 2024 08:04:28 +0100 Subject: Reintroduce backend selection through `ICED_BACKEND` env var --- graphics/src/compositor.rs | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) (limited to 'graphics/src/compositor.rs') diff --git a/graphics/src/compositor.rs b/graphics/src/compositor.rs index 8c67cd16..86472a58 100644 --- a/graphics/src/compositor.rs +++ b/graphics/src/compositor.rs @@ -20,6 +20,18 @@ pub trait Compositor: Sized { fn new( settings: Settings, compatible_window: W, + ) -> impl Future> { + Self::with_backend(settings, compatible_window, None) + } + + /// Creates a new [`Compositor`] with a backend preference. + /// + /// If the backend does not match the preference, it will return + /// [`Error::GraphicsAdapterNotFound`]. + fn with_backend( + _settings: Settings, + _compatible_window: W, + _backend: Option<&str>, ) -> impl Future>; /// Creates a [`Self::Renderer`] for the [`Compositor`]. @@ -130,9 +142,10 @@ impl Compositor for () { type Renderer = (); type Surface = (); - async fn new( + async fn with_backend( _settings: Settings, _compatible_window: W, + _preffered_backend: Option<&str>, ) -> Result { Ok(()) } -- cgit From 6ad5bb3597f640ac329801adf735d633bf0a512f Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Tue, 9 Apr 2024 22:25:16 +0200 Subject: Port `iced_tiny_skia` to new layering architecture --- graphics/src/compositor.rs | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) (limited to 'graphics/src/compositor.rs') diff --git a/graphics/src/compositor.rs b/graphics/src/compositor.rs index 86472a58..47521eb0 100644 --- a/graphics/src/compositor.rs +++ b/graphics/src/compositor.rs @@ -5,9 +5,11 @@ use crate::futures::{MaybeSend, MaybeSync}; use crate::{Error, Settings, Viewport}; use raw_window_handle::{HasDisplayHandle, HasWindowHandle}; -use std::future::Future; use thiserror::Error; +use std::borrow::Cow; +use std::future::Future; + /// A graphics compositor that can draw to windows. pub trait Compositor: Sized { /// The iced renderer of the backend. @@ -60,6 +62,14 @@ pub trait Compositor: Sized { /// Returns [`Information`] used by this [`Compositor`]. fn fetch_information(&self) -> Information; + /// Loads a font from its bytes. + fn load_font(&mut self, font: Cow<'static, [u8]>) { + crate::text::font_system() + .write() + .expect("Write to font system") + .load_font(font); + } + /// Presents the [`Renderer`] primitives to the next frame of the given [`Surface`]. /// /// [`Renderer`]: Self::Renderer @@ -168,6 +178,8 @@ impl Compositor for () { ) { } + fn load_font(&mut self, _font: Cow<'static, [u8]>) {} + fn fetch_information(&self) -> Information { Information { adapter: String::from("Null Renderer"), -- cgit