Trait Recordable

Source
pub trait Recordable {
    // Required methods
    fn prepare_recording(&mut self, recording: &mut Recording);
    fn execute_recording(&mut self, recording: &Recording);

    // Provided method
    fn record<F>(&mut self, recording: &mut Recording, f: F)
       where F: FnOnce(&mut Recorder<'_>) { ... }
}
Expand description

Trait for rendering contexts that support recording and replaying operations.

§State Modification During Replay

Important: When replaying recordings using methods like execute_recording(), the renderer’s state (transform, paint, fill rule, stroke settings, etc.) will be modified to match the state changes captured in the recording. The renderer will be left in the final state after all commands have been executed.

§Multithreading Limitation

Note: Recording and replay functionality is not currently implemented for vello_cpu when multithreading is enabled. This limitation only affects vello_cpu in multithreaded mode; single-threaded vello_cpu and vello_hybrid work correctly with recordings.

§Usage Pattern

A consumer needs to do the following to render:

let mut recording = Recording::new();
scene.record(&mut recording, |ctx| { ... });
scene.prepare_recording(&mut recording);
scene.execute_recording(&recording);

Or to prepare for later rendering:

let mut recording = Recording::new();
scene.record(&mut recording, |ctx| { ... });
scene.prepare_recording(&mut recording);

// sometime later
scene.execute_recording(&recording);

Required Methods§

Source

fn prepare_recording(&mut self, recording: &mut Recording)

Generate sparse strips for a recording.

This method processes the recorded commands and generates cached sparse strips without executing the rendering. This allows you to pre-generate strips for better control over when the expensive computation happens.

§Example
let mut recording = Recording::new();
scene.record(&mut recording, |ctx| {
    ctx.fill_rect(&Rect::new(0.0, 0.0, 100.0, 100.0));
});

// Generate strips explicitly
scene.prepare_recording(&mut recording);
Source

fn execute_recording(&mut self, recording: &Recording)

Execute a recording directly without preparation.

This method executes the rendering commands from a recording, using any cached sparse strips that have been previously generated. If the recording has not been prepared (no cached strips), this will result in empty rendering.

Use this method when you have a recording that has already been prepared via prepare_recording(), or when you want to execute commands immediately without explicit preparation.

§Example
let mut recording = Recording::new();
scene.record(&mut recording, |ctx| {
    ctx.fill_rect(&Rect::new(0.0, 0.0, 100.0, 100.0));
});

// Prepare strips first
scene.prepare_recording(&mut recording);

// Then execute with cached strips
scene.execute_recording(&recording);

Provided Methods§

Source

fn record<F>(&mut self, recording: &mut Recording, f: F)
where F: FnOnce(&mut Recorder<'_>),

Record rendering commands into a recording.

This method allows you to capture a sequence of rendering operations in a Recording that can be cached and replayed later.

§Example
let mut recording = Recording::new();
scene.record(&mut recording, |ctx| {
    ctx.fill_rect(&Rect::new(0.0, 0.0, 100.0, 100.0));
    ctx.set_paint(Color::RED);
    ctx.stroke_path(&some_path);
});

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§