Skip to main content

Renderer

Trait Renderer 

Source
pub trait Renderer {
    type Scene: RenderScene;
    type Error;

    // Required methods
    fn scene(&self) -> &Self::Scene;
    fn scene_mut(&mut self) -> &mut Self::Scene;
    fn rebuild_scene(
        &mut self,
        layout_tree: &LayoutTree,
        viewport: Size,
    ) -> Result<(), Self::Error>;
    fn rebuild_scene_from_applier(
        &mut self,
        applier: &mut MemoryApplier,
        root: NodeId,
        viewport: Size,
    ) -> Result<(), Self::Error>;

    // Provided methods
    fn attach_app_context_services(&mut self, _app_context: &AppContext) { ... }
    fn set_root_scale(&mut self, _scale: f32) { ... }
    fn update_scene_from_applier(
        &mut self,
        applier: &mut MemoryApplier,
        root: NodeId,
        viewport: Size,
        updates: SceneUpdates<'_>,
    ) -> Result<(), Self::Error> { ... }
    fn update_visual_scene_from_applier(
        &mut self,
        applier: &mut MemoryApplier,
        root: NodeId,
        viewport: Size,
        updates: SceneUpdates<'_>,
    ) -> Result<(), Self::Error> { ... }
    fn draw_dev_overlay(&mut self, _text: &str, _viewport: Size) { ... }
    fn set_inspector_overlay(&mut self, _graph: Option<RenderGraph>) { ... }
    fn needs_frame_warmup(&self) -> bool { ... }
    fn awaits_pipelines(&self) -> bool { ... }
}
Expand description

Abstraction implemented by concrete renderer backends.

Required Associated Types§

Required Methods§

Source

fn scene(&self) -> &Self::Scene

Source

fn scene_mut(&mut self) -> &mut Self::Scene

Source

fn rebuild_scene( &mut self, layout_tree: &LayoutTree, viewport: Size, ) -> Result<(), Self::Error>

Source

fn rebuild_scene_from_applier( &mut self, applier: &mut MemoryApplier, root: NodeId, viewport: Size, ) -> Result<(), Self::Error>

Rebuilds the scene by traversing the LayoutNode tree directly via Applier.

This is the new architecture that eliminates per-frame LayoutTree reconstruction. Implementors must read layout state from LayoutNode.layout_state() directly.

Provided Methods§

Source

fn attach_app_context_services(&mut self, _app_context: &AppContext)

Installs renderer-provided app services into the target AppContext.

AppShell calls this before the first composition pass. Renderers that provide text measurement or other per-app services should install them here rather than as constructor side effects.

Source

fn set_root_scale(&mut self, _scale: f32)

Sets how many device pixels the renderer draws for one logical unit.

AppShell sets its primary renderer’s scale to the density it lays out with, at construction and on every density change, so a host sets it only for the renderers of other surfaces. Renderers that take the scale with each draw ignore it.

Source

fn update_scene_from_applier( &mut self, applier: &mut MemoryApplier, root: NodeId, viewport: Size, updates: SceneUpdates<'_>, ) -> Result<(), Self::Error>

Source

fn update_visual_scene_from_applier( &mut self, applier: &mut MemoryApplier, root: NodeId, viewport: Size, updates: SceneUpdates<'_>, ) -> Result<(), Self::Error>

Source

fn draw_dev_overlay(&mut self, _text: &str, _viewport: Size)

Draw a development overlay (e.g., FPS counter) on top of the scene.

This is called after rebuild_scene when dev options are enabled. The text is drawn directly by the renderer without affecting composition.

Default implementation does nothing.

Source

fn set_inspector_overlay(&mut self, _graph: Option<RenderGraph>)

Replaces the developer inspector graph outside the application scene.

Passing None removes the inspector. Its primitives must not participate in application hit testing, layout, or accessibility.

Source

fn needs_frame_warmup(&self) -> bool

Returns whether renderer-side cache materialization needs a visible follow-up frame.

Source

fn awaits_pipelines(&self) -> bool

Returns whether the last frame drew a placeholder for an effect whose pipelines are still compiling, so its picture is not final yet; the renderer asks for the frame that replaces it once they land.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§