diff options
author | 2024-01-19 20:41:52 +0100 | |
---|---|---|
committer | 2024-01-19 20:41:52 +0100 | |
commit | 1781068e1c3a65551db1e832fdbaddba99124051 (patch) | |
tree | 60e0b3854cc0541712572fbb0e56f14435951ea9 /graphics/src/compositor.rs | |
parent | 41dec5bd203ff5b1574a33a17d5f7358ae1beea2 (diff) | |
parent | 7ae7fcb89855002519bab752fd3686106ce448db (diff) | |
download | iced-1781068e1c3a65551db1e832fdbaddba99124051.tar.gz iced-1781068e1c3a65551db1e832fdbaddba99124051.tar.bz2 iced-1781068e1c3a65551db1e832fdbaddba99124051.zip |
Merge branch 'master' into remove-vertex-indexing
Diffstat (limited to '')
-rw-r--r-- | graphics/src/compositor.rs | 32 |
1 files changed, 25 insertions, 7 deletions
diff --git a/graphics/src/compositor.rs b/graphics/src/compositor.rs index 0222a80f..0188f4d8 100644 --- a/graphics/src/compositor.rs +++ b/graphics/src/compositor.rs @@ -2,9 +2,10 @@ //! surfaces. use crate::{Error, Viewport}; -use iced_core::Color; +use crate::core::Color; +use crate::futures::{MaybeSend, MaybeSync}; -use raw_window_handle::{HasRawDisplayHandle, HasRawWindowHandle}; +use raw_window_handle::{HasDisplayHandle, HasWindowHandle}; use thiserror::Error; /// A graphics compositor that can draw to windows. @@ -19,17 +20,20 @@ pub trait Compositor: Sized { type Surface; /// Creates a new [`Compositor`]. - fn new<W: HasRawWindowHandle + HasRawDisplayHandle>( + fn new<W: Window + Clone>( settings: Self::Settings, - compatible_window: Option<&W>, - ) -> Result<(Self, Self::Renderer), Error>; + compatible_window: W, + ) -> Result<Self, Error>; + + /// Creates a [`Self::Renderer`] for the [`Compositor`]. + fn create_renderer(&self) -> Self::Renderer; /// Crates a new [`Surface`] for the given window. /// /// [`Surface`]: Self::Surface - fn create_surface<W: HasRawWindowHandle + HasRawDisplayHandle>( + fn create_surface<W: Window + Clone>( &mut self, - window: &W, + window: W, width: u32, height: u32, ) -> Self::Surface; @@ -74,6 +78,20 @@ pub trait Compositor: Sized { ) -> Vec<u8>; } +/// A window that can be used in a [`Compositor`]. +/// +/// This is just a convenient super trait of the `raw-window-handle` +/// traits. +pub trait Window: + HasWindowHandle + HasDisplayHandle + MaybeSend + MaybeSync + 'static +{ +} + +impl<T> Window for T where + T: HasWindowHandle + HasDisplayHandle + MaybeSend + MaybeSync + 'static +{ +} + /// Result of an unsuccessful call to [`Compositor::present`]. #[derive(Clone, PartialEq, Eq, Debug, Error)] pub enum SurfaceError { |