use smithay::backend::renderer::element::solid::SolidColorRenderElement; use smithay::backend::renderer::element::surface::WaylandSurfaceRenderElement; use smithay::backend::renderer::Renderer; #[thin_delegate::external_trait_def(with_uses = true)] mod external_trait_def { use smithay::backend::renderer::element::{Id, Kind, UnderlyingStorage}; use smithay::backend::renderer::utils::CommitCounter; use smithay::backend::renderer::{ImportAll, ImportMem, Renderer}; use smithay::utils::{ Buffer as BufferCoords, Physical, Point, Rectangle, Scale, Transform, }; #[thin_delegate::register] pub trait Element { /// Get the unique id of this element fn id(&self) -> &Id; /// Get the current commit position of this element fn current_commit(&self) -> CommitCounter; /// Get the location relative to the output fn location(&self, scale: Scale) -> Point { self.geometry(scale).loc } /// Get the src of the underlying buffer fn src(&self) -> Rectangle; /// Get the transform of the underlying buffer fn transform(&self) -> Transform { Transform::Normal } /// Get the geometry relative to the output fn geometry(&self, scale: Scale) -> Rectangle; /// Get the damage since the provided commit relative to the element fn damage_since( &self, scale: Scale, commit: Option, ) -> Vec> { if commit != Some(self.current_commit()) { vec![Rectangle::from_loc_and_size( (0, 0), self.geometry(scale).size, )] } else { vec![] } } /// Get the opaque regions of the element relative to the element fn opaque_regions(&self, _scale: Scale) -> Vec> { vec![] } /// Returns an alpha value the element should be drawn with regardless of any /// already encoded alpha in it's underlying representation. fn alpha(&self) -> f32 { 1.0 } /// Returns the [`Kind`] for this element fn kind(&self) -> Kind { Kind::default() } } #[thin_delegate::register] pub trait RenderElement: Element { /// Draw this element fn draw( &self, frame: &mut ::Frame<'_>, src: Rectangle, dst: Rectangle, damage: &[Rectangle], ) -> Result<(), R::Error>; /// Get the underlying storage of this element, may be used to optimize rendering (eg. drm planes) fn underlying_storage(&self, renderer: &mut R) -> Option { let _ = renderer; None } } } #[derive(derive_more::From)] #[thin_delegate::register] pub enum WindowRenderElement where R: Renderer, { Window(WaylandSurfaceRenderElement), Decoration(SolidColorRenderElement), } #[thin_delegate::derive_delegate(external_trait_def = external_trait_def)] impl smithay::backend::renderer::element::Element for WindowRenderElement where R: smithay::backend::renderer::Renderer, ::TextureId: 'static, R: ImportAll + ImportMem, { } #[thin_delegate::derive_delegate(external_trait_def = external_trait_def)] impl smithay::backend::renderer::element::RenderElement for WindowRenderElement where R: smithay::backend::renderer::Renderer, ::TextureId: 'static, R: ImportAll + ImportMem, { } fn main() {}