Skip to main content

ferroui_base/platform/surfaces/
i_platform_render_surface.rs

1use crate::platform::PlatformRenderTargetState;
2use std::any::Any;
3
4/// A surface that a render backend can create a render target for.
5///
6/// Backends recognise the surface kinds they support by downcasting through
7/// [`as_any`](Self::as_any) or the typed accessors.
8pub trait IPlatformRenderSurface: Send + Sync {
9    /// Whether the surface is ready to be rendered to.
10    fn is_ready(&self) -> bool {
11        true
12    }
13
14    /// The surface as a framebuffer surface, if it is one.
15    fn as_framebuffer_surface(&self) -> Option<&dyn super::IFramebufferPlatformSurface> {
16        None
17    }
18
19    /// The surface viewed as a surface kind defined outside this crate: for
20    /// `TypeId::of::<dyn IFoo>()` the result holds an `Rc<dyn IFoo>`.
21    fn try_get_surface_kind(&self, _kind: std::any::TypeId) -> Option<std::rc::Rc<dyn Any>> {
22        None
23    }
24
25    /// The text rendering settings of the platform for this surface, when
26    /// the platform knows them: the render backend asks for them every
27    /// frame (they follow the settings of the system and the display the
28    /// surface is on). A backend asks every surface of a top-level and
29    /// takes the first answer; `None` from all of them gives the defaults
30    /// of the backend (docs/porting/text-rendering.md).
31    fn text_rendering_parameters(&self) -> Option<super::PlatformTextRenderingParameters> {
32        None
33    }
34
35    /// Lets the backend recover the concrete surface type.
36    fn as_any(&self) -> &dyn Any;
37}
38
39/// A render target created for a platform render surface.
40pub trait IPlatformRenderSurfaceRenderTarget {
41    /// The state of the platform render target.
42    fn state(&self) -> PlatformRenderTargetState {
43        PlatformRenderTargetState::READY
44    }
45}