Skip to main content

ObservingRenderer

Struct ObservingRenderer 

Source
pub struct ObservingRenderer<R, F> { /* private fields */ }
Expand description

A renderer that hands every scene it is given to a closure before passing it on.

Observation belongs here rather than in a backend. It needs nothing from the platform, so a backend that learned about inspection would carry it once per API, and the scene is already an engine type: a scene optimiser, a culling pass, an assertion about what primitives a renderer is handed and in what order, are all statements about this layer.

What a window painted is observable one layer up, where the frame still holds the scene it built (Window::painted_quads), so this is for observing a renderer rather than a frame.

This wraps a renderer in another renderer, and the choices that make it useful are the forwarding ones: it observes draw and render_scene, and it does not override render_scene_to_image, so a readback is observed once through the render_scene it composes rather than twice.

Implementations§

Source§

impl<R, F> ObservingRenderer<R, F>

Source

pub fn new(inner: R, on_scene: F) -> Self

Wraps inner, calling on_scene with each scene it is asked to draw.

Source

pub fn inner(&self) -> &R

The renderer being observed.

Source

pub fn inner_mut(&mut self) -> &mut R

The renderer being observed.

Source

pub fn into_inner(self) -> R

Takes back the observed renderer.

Trait Implementations§

Source§

impl<R, F> SceneRenderer for ObservingRenderer<R, F>
where R: SceneRenderer, F: FnMut(&Scene) + 'static,

Source§

fn draw(&mut self, scene: &Scene) -> bool

Encodes and submits scene, returning whether it was presented. Read more
Source§

fn sprite_atlas(&self) -> Arc<dyn PlatformAtlas> ⓘ

Returns the sprite atlas used by this renderer.
Source§

fn set_viewport_size(&mut self, size: Size<DevicePixels>)

Sets the size of the target that draw renders into. Read more
Source§

fn render_scene( &mut self, scene: &Scene, size: Size<DevicePixels>, ) -> Result<()>

Renders scene into an offscreen target of size, without reading it back. Read more
Source§

fn read_pixels(&mut self) -> Result<PixelBuffer>

Reads the offscreen target of the last render_scene back. Read more
Source§

fn offscreen_surface_handle(&self) -> Option<Arc<dyn Any + Send + Sync>>

The offscreen target of the last render_scene, as a handle that may cross a thread boundary. Read more
Source§

fn render_scene_to_image( &mut self, scene: &Scene, size: Size<DevicePixels>, ) -> Result<PixelBuffer>

Renders scene offscreen and reads the result back.

Auto Trait Implementations§

§

impl<R, F> Freeze for ObservingRenderer<R, F>
where R: Freeze, F: Freeze,

§

impl<R, F> RefUnwindSafe for ObservingRenderer<R, F>

§

impl<R, F> Send for ObservingRenderer<R, F>
where R: Send, F: Send,

§

impl<R, F> Sync for ObservingRenderer<R, F>
where R: Sync, F: Sync,

§

impl<R, F> Unpin for ObservingRenderer<R, F>
where R: Unpin, F: Unpin,

§

impl<R, F> UnsafeUnpin for ObservingRenderer<R, F>
where R: UnsafeUnpin, F: UnsafeUnpin,

§

impl<R, F> UnwindSafe for ObservingRenderer<R, F>
where R: UnwindSafe, F: UnwindSafe,

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
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
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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.