Skip to main content

RenderBackend

Trait RenderBackend 

Source
pub trait RenderBackend {
    // Required methods
    fn begin_frame(
        &mut self,
        width: u32,
        height: u32,
        scale_factor: f32,
        generation: u64,
    ) -> Result<(), RendererError>;
    fn render_frame(
        &mut self,
        commands: &[DrawCommand],
        clear_color: Option<Color>,
    ) -> Result<(), RendererError>;

    // Provided methods
    fn read_rgba(&self) -> Option<Vec<u8>> { ... }
    fn bind_to_render_thread(&mut self) { ... }
    fn idle_sweep_after(&self) -> Option<Duration> { ... }
    fn sweep_idle_caches(&mut self) { ... }
    fn applies_scale_factor(&self) -> bool { ... }
}

Required Methods§

Source

fn begin_frame( &mut self, width: u32, height: u32, scale_factor: f32, generation: u64, ) -> Result<(), RendererError>

Begin a new frame. Note: scale_factor and generation may be ignored by backends that receive pre-scaled commands (see SoftwareRenderer::begin_frame).

Source

fn render_frame( &mut self, commands: &[DrawCommand], clear_color: Option<Color>, ) -> Result<(), RendererError>

Process and present all draw commands for this frame. Must be called exactly once per frame after begin_frame.

Provided Methods§

Source

fn read_rgba(&self) -> Option<Vec<u8>>

The most recently rendered frame as premultiplied RGBA8888 ([R, G, B, A] per pixel, row-major), if this backend renders to an offscreen target. Windowed/on-screen backends present directly and return None. Used to read back pixels from a headless render pass.

Source

fn bind_to_render_thread(&mut self)

Called once on the thread that will drive this backend, before its first frame.

A backend built on the UI thread and then moved to a render thread has to re-establish whatever per-thread state its constructor set up there. The software rasteriser keeps its glyph shaper and shadow caches in a thread-local, so without this the render thread finds an empty slot and builds a default one — with no font config. On desktop that silently falls back to system fonts; on Android there are none to find and cosmic-text aborts the process with “no default font found”.

Source

fn idle_sweep_after(&self) -> Option<Duration>

How long the render thread should go without a frame before calling sweep_idle_caches. None (the default) means never.

Exists because a backend’s caches may be thread-local: they then belong to the render thread, and nothing on the UI thread can reach them — so the sweep has to be driven from the thread that owns them, and only that thread knows when it has been idle.

Source

fn sweep_idle_caches(&mut self)

Drops cache entries no frame has asked for within their idle horizon. Called once per idle stretch, on the render thread, after idle_sweep_after has elapsed with no frame.

Source

fn applies_scale_factor(&self) -> bool

Whether this backend applies begin_frame’s scale_factor itself — the hardware path folds it into the shader’s transform. A backend that returns false (the default, and what the software rasteriser does) must be handed commands already scaled into physical pixels, which is why the frame pipeline runs ScaleScratch for it.

Trait Implementations§

Source§

impl RenderBackend for Box<dyn RenderBackend + Send>

Source§

fn begin_frame( &mut self, width: u32, height: u32, scale_factor: f32, generation: u64, ) -> Result<(), RendererError>

Begin a new frame. Note: scale_factor and generation may be ignored by backends that receive pre-scaled commands (see SoftwareRenderer::begin_frame).
Source§

fn render_frame( &mut self, commands: &[DrawCommand], clear_color: Option<Color>, ) -> Result<(), RendererError>

Process and present all draw commands for this frame. Must be called exactly once per frame after begin_frame.
Source§

fn read_rgba(&self) -> Option<Vec<u8>>

The most recently rendered frame as premultiplied RGBA8888 ([R, G, B, A] per pixel, row-major), if this backend renders to an offscreen target. Windowed/on-screen backends present directly and return None. Used to read back pixels from a headless render pass.
Source§

fn bind_to_render_thread(&mut self)

Called once on the thread that will drive this backend, before its first frame. Read more
Source§

fn idle_sweep_after(&self) -> Option<Duration>

How long the render thread should go without a frame before calling sweep_idle_caches. None (the default) means never. Read more
Source§

fn sweep_idle_caches(&mut self)

Drops cache entries no frame has asked for within their idle horizon. Called once per idle stretch, on the render thread, after idle_sweep_after has elapsed with no frame.
Source§

fn applies_scale_factor(&self) -> bool

Whether this backend applies begin_frame’s scale_factor itself — the hardware path folds it into the shader’s transform. A backend that returns false (the default, and what the software rasteriser does) must be handed commands already scaled into physical pixels, which is why the frame pipeline runs ScaleScratch for it.

Dyn Compatibility§

This trait is dyn compatible.

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

Implementations on Foreign Types§

Source§

impl RenderBackend for Box<dyn RenderBackend + Send>

Source§

fn begin_frame( &mut self, width: u32, height: u32, scale_factor: f32, generation: u64, ) -> Result<(), RendererError>

Source§

fn render_frame( &mut self, commands: &[DrawCommand], clear_color: Option<Color>, ) -> Result<(), RendererError>

Source§

fn read_rgba(&self) -> Option<Vec<u8>>

Source§

fn bind_to_render_thread(&mut self)

Source§

fn idle_sweep_after(&self) -> Option<Duration>

Source§

fn sweep_idle_caches(&mut self)

Source§

fn applies_scale_factor(&self) -> bool

Implementors§