ferroui_base/rendering/i_renderer.rs
1use super::composition::{Compositor, LocalFuture, RenderInterfaceFeature};
2use super::{RendererDiagnostics, SceneInvalidatedEventArgs};
3use crate::reactive::IDisposable;
4use crate::{Rect, Size, Visual};
5use std::any::TypeId;
6use std::rc::Rc;
7
8/// Defines the interface for a renderer.
9pub trait IRenderer {
10 /// A value controlling the renderer's diagnostics.
11 fn diagnostics(&self) -> Rc<RendererDiagnostics>;
12
13 /// Subscribes to the notification raised when a portion of the scene
14 /// has been invalidated.
15 ///
16 /// Indicates that the underlying low-level scene information has been
17 /// updated. Used to signal that an update to the current pointer-over
18 /// state may be required.
19 fn scene_invalidated(&self, handler: Rc<dyn Fn(&SceneInvalidatedEventArgs)>) -> Rc<dyn IDisposable>;
20
21 /// Mark a visual as dirty and needing re-rendering.
22 fn add_dirty(&self, visual: &Visual);
23
24 /// Informs the renderer that the z-ordering of a visual's children has
25 /// changed.
26 fn recalculate_children(&self, visual: &Visual);
27
28 /// Called when a resize notification is received by the control being
29 /// rendered.
30 fn resized(&self, size: Size);
31
32 /// Called when a paint notification is received by the control being
33 /// rendered.
34 fn paint(&self, rect: Rect);
35
36 /// Starts the renderer.
37 fn start(&self);
38
39 /// Stops the renderer.
40 fn stop(&self);
41
42 /// Attempts to query for a feature from the platform render interface:
43 /// a future awaited on the thread of the renderer, which completes with
44 /// the feature or `None` (see `Compositor::try_get_render_interface_feature`:
45 /// asynchronous because the render interface may live on the render
46 /// thread). The feature is an object of the server side: what is handed
47 /// out lends it inside the compositor lock.
48 fn try_get_render_interface_feature(&self, feature_type: TypeId) -> LocalFuture<Option<RenderInterfaceFeature>>;
49
50 /// The compositor of the renderer, if it renders through one
51 /// (upstream: the `IRendererWithCompositor` interface).
52 fn compositor(&self) -> Option<Rc<Compositor>> {
53 None
54 }
55
56 /// Releases the renderer's resources.
57 fn dispose(&self);
58}