Skip to main content

OffscreenRenderer

Struct OffscreenRenderer 

pub struct OffscreenRenderer {
    pub width: u32,
    pub height: u32,
    /* private fields */
}
Expand description

An offscreen wgpu + vello pipeline sized at width × height. Reuse one instance across renders: adapter and device creation is the expensive part.

Fields§

§width: u32§height: u32

Implementations§

§

impl OffscreenRenderer

pub fn memory_stats(&self) -> OffscreenMemoryStats

pub fn new(width: u32, height: u32) -> OffscreenRenderer

Do not soften that with std::panic::catch_unwind — the release profile sets panic = "abort", so a panic kills the process at its site. A soft-fail caller uses try_new.

§Panics

Whenever try_new returns an OffscreenError.

pub fn try_new( width: u32, height: u32, ) -> Result<OffscreenRenderer, OffscreenError>

For a code path that must survive a GPU-less machine, since catch_unwind can’t (see new).

§Errors

OffscreenError::NoAdapter with no wgpu adapter (a headless machine typically needs llvmpipe/lavapipe), Renderer when vello cannot build a renderer for it, [ContextPoisoned] when another thread poisoned the shared context, [CannotWait] on a thread that cannot wait for the GPU (a browser page).

§Panics

Panics if width or height is zero — a caller bug, not an environment failure.

The renderer is a capture’s: it sums segments in a fixed order, so one scene renders to the same pixels every time. Frames only shown, never kept or compared, use try_new_live.

pub fn try_new_live( width: u32, height: u32, ) -> Result<OffscreenRenderer, OffscreenError>

try_new for frames that are shown and replaced, as a headless desktop’s or a window preview’s: segments sum in the order tiles finish, which may move an antialiased edge by one unit. It builds no segment-ordering pipelines, which lavapipe keeps in the heap for the renderer’s lifetime — several MiB of an idle desktop.

§Errors

As try_new.

§Panics

On zero dimensions, as try_new.

pub fn try_new_with_cpu_preprocessing( width: u32, height: u32, ) -> Result<OffscreenRenderer, OffscreenError>

Stable CPU segment ordering with Vello’s production GPU fine rasterizer, per instance, so an exact pixel comparison changes no process-wide renderer setting.

§Errors

Returns the same adapter and renderer errors as Self::try_new.

§Panics

Panics on zero dimensions, as Self::try_new does.

pub fn set_backdrop(&mut self, backdrop: Option<Arc<BackdropFrame>>)

Draw the floating surfaces of scenes rendered from now on over backdrop, the frame their host recorded with them; None draws them opaque.

pub fn backdrop_stats(&self) -> BackdropStats

What the backdrop pass did for the last render: regions substituted, and how many of those came from the kept sample.

pub fn readback_into( &mut self, origin: (u32, u32), size: (u32, u32), into: &mut [u8], )

Copy size pixels at origin of the target as last drawn into into, packed as Self::readback_current returns them. Only that part leaves the GPU and nothing outside it in into is touched, so a frame that changed a part costs the part.

pub fn render(&mut self, scene: &Scene, bg: AlphaColor<Srgb>) -> Vec<u8> ⓘ

pub fn readback_current(&mut self) -> Vec<u8> ⓘ

Read the already-rendered retained target without submitting another Vello frame. Used to verify partial-damage composition pixel-for-pixel.

pub fn render_gpu_wait(&mut self, scene: &Scene, bg: AlphaColor<Srgb>)

Submit a render and wait for its GPU work without copying the target back, so a performance harness measures Vello rather than readback and row repacking. Screenshot and visual-regression callers use Self::render.

pub fn render_damage_gpu_wait( &mut self, scene: &Scene, bg: AlphaColor<Srgb>, damage: Rect, ) -> u64

Update one native-resolution rectangle in the retained target and wait for completion, keeping pixels outside damage exactly. Returns the number of pixels rasterized; an invalid or full-size rectangle falls back to a complete target render.

§Panics

Panics if the shared GPU context is unavailable or Vello rejects the render: a timing sample after either is invalid anyway.

pub fn render_damage_regions_gpu_wait( &mut self, scene: &Scene, bg: AlphaColor<Srgb>, damage: &[Rect], ) -> u64

Batched form of Self::render_damage_gpu_wait: render once at the scene’s own coordinates into a scratch target from the native origin through the damage bounds (keeping native coordinates preserves full-render text coverage), then copy only dirty regions. Damage or a scratch extent over half the output falls back to a full render to bound scratch memory.

§Panics

Panics under the same conditions as Self::render_damage_gpu_wait.

pub fn render_copies_and_damage_gpu_wait( &mut self, scene: &Scene, bg: AlphaColor<Srgb>, copies: &[DeviceCopy], damage: &[Rect], ) -> u64

Self::render_damage_regions_gpu_wait after moving pixels within the retained target by copies, in order, as a window presents a scroll (crate::scroll_copy). With no valid target, or a copy that would leave it, the frame renders whole.

§Panics

Panics under the same conditions as Self::render_damage_gpu_wait.

pub fn render_damage_regions_gpu_wait_profiled( &mut self, scene: &Scene, bg: AlphaColor<Srgb>, damage: &[Rect], ) -> (u64, OffscreenRenderTiming)

Profile the existing damage render without adding GPU work or readback. This opt-in path alone reads host clocks around submission and the existing final settle wait.

pub fn render_rgba(&mut self, scene: &Scene) -> Vec<u8> ⓘ

render with a transparent background.

pub fn render_resilient( &mut self, scene: &Scene, bg: AlphaColor<Srgb>, ) -> Vec<u8> ⓘ

Render until Vello confirms no bump-allocated geometry was dropped, up to a strict attempt limit: its GPU counters catch partially missing glyphs as reliably as a transparent frame.

§Panics

When Vello cannot produce two consecutive valid submissions within the bounded count: partial screenshot pixels would make visual-regression output silently untrustworthy.

pub fn try_render_resilient( &mut self, scene: &Scene, bg: AlphaColor<Srgb>, ) -> Result<Vec<u8>, String>

Self::render_resilient for a caller that can answer a failure instead of stopping: an app rendering a picture someone asked for.

pub fn render_rgba_resilient(&mut self, scene: &Scene) -> Vec<u8> ⓘ

Render a one-shot scene without accepting Vello’s transparent bump-buffer warm-up frame: an interactive renderer gets a next frame after the reservation grows, a screenshot does not.

pub fn render_png<P>(&mut self, scene: &Scene, bg: AlphaColor<Srgb>, path: P)
where P: AsRef<Path>,

Render scene and write it to path as a PNG, creating parent dirs.

§Panics

If the file cannot be created or PNG encoding fails — dev-environment problems this test-only helper has no action for.

pub fn sample(rgba: &[u8], width: u32, x: u32, y: u32) -> (u8, u8, u8, u8)

The (r, g, b, a) at (x, y) in a buffer packed at 4 * width bytes per row.

§Panics

If (x, y) is outside rgba: every caller is a test asserting known-valid coordinates, so an out-of-range sample is a test bug that should fail loudly, not read back 0.

pub fn pixels_differing_beyond_aa(a: &[u8], b: &[u8]) -> usize

Compare stored straight-alpha RGBA8 pixels with the module’s ±1 tolerance. RGB in fully transparent pixels is invisible; with either alpha nonzero every channel participates. Buffers of different lengths differ everywhere they do not overlap.

pub fn differing_beyond_aa( a: &[u8], b: &[u8], width: usize, ) -> (usize, Option<(usize, usize, usize, usize)>)

How many pixels differ and the rectangle they fall in, for frames width pixels wide: (left, top, right, bottom), far edges exclusive, or None. Frames of different lengths are compared where they overlap and the rest is counted.

pub fn positions_differing_beyond_aa( a: &[u8], b: &[u8], width: usize, ) -> Vec<(usize, usize)>

Where Self::pixels_differing_beyond_aa finds two equally long frames width pixels wide differ, as (x, y).

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
§

impl<T> AsAny for T
where T: 'static,

§

fn as_any(&self) -> &(dyn Any + 'static)

Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
§

impl<T> Downcast<T> for T

§

fn downcast(&self) -> &T

§

impl<T> Downcast for T
where T: Any,

§

fn into_any(self: Box<T>) -> Box<dyn Any>

Convert Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.
§

fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>

Convert Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be further downcast into Rc<ConcreteType> where ConcreteType implements Trait.
§

fn as_any(&self) -> &(dyn Any + 'static)

Convert &Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &Any’s vtable from &Trait’s.
§

fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)

Convert &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s.
§

impl<T> Downcast for T
where T: Any,

§

fn into_any(self: Box<T>) -> Box<dyn Any>

Converts Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>, which can then be downcast into Box<dyn ConcreteType> where ConcreteType implements Trait.
§

fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>

Converts Rc<Trait> (where Trait: Downcast) to Rc<Any>, which can then be further downcast into Rc<ConcreteType> where ConcreteType implements Trait.
§

fn as_any(&self) -> &(dyn Any + 'static)

Converts &Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &Any’s vtable from &Trait’s.
§

fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)

Converts &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s.
§

impl<T> DowncastSend for T
where T: Any + Send,

§

fn into_any_send(self: Box<T>) -> Box<dyn Any + Send>

Converts Box<Trait> (where Trait: DowncastSend) to Box<dyn Any + Send>, which can then be downcast into Box<ConcreteType> where ConcreteType implements Trait.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
§

impl<T> Pointable for T

§

const ALIGN: usize

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
§

impl<T> PolicyExt for T
where T: ?Sized,

§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns [Action::Follow] only if self and other return Action::Follow. Read more
§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns [Action::Follow] if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
§

impl<T, S> SimdFrom<T, S> for T
where S: Simd,

§

fn simd_from(_simd: S, value: T) -> T

§

impl<F, T, S> SimdInto<T, S> for F
where T: SimdFrom<F, S>, S: Simd,

§

fn simd_into(self, simd: S) -> T

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<T> Upcast<T> for T

§

fn upcast(&self) -> Option<&T>

§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

impl<T> ErasedDestructor for T
where T: 'static,

§

impl<T> Fruit for T
where T: Send + Downcast,

§

impl<T> WasmNotSend for T
where T: Send,