pub struct SoftwareRenderer<const MAX_BUFFER_AGE: usize> { /* private fields */ }
Expand description

A Renderer that do the rendering in software

The renderer can remember what items needs to be redrawn from the previous iteration.

There are two kind of possible rendering

  1. Using render() to render the window in a buffer
  2. Using render_by_line() to render the window line by line. This is only useful if the device does not have enough memory to render the whole window in one single buffer

MAX_BUFFER_AGE

The MAX_BUFFER_AGE parameter specifies how many buffers are being re-used. This means that the buffer passed to the render functions still contains a rendering of the window that was refreshed as least that amount of frame ago. It will impact how much of the screen needs to be redrawn.

Typical value can be:

  • 0: No attempt at tracking dirty items will be made. The full screen is always redrawn.
  • 1: Only redraw the parts that have changed since the previous call to render. This is assuming that the same buffer is passed on every call to render.
  • 2: Redraw the part that have changed during the two last frames. This is assuming double buffering and swapping of the buffers.

Implementations§

Create a new Renderer for a given window.

The window parameter can be coming from Rc::new_cyclic() since the WindowAdapter most likely own the Renderer

Render the window to the given frame buffer.

The renderer uses a cache internally and will only render the part of the window which are dirty. The extra_draw_region is an extra regin which will also be rendered. (eg: the previous dirty region in case of double buffering)

returns the dirty region for this frame (not including the extra_draw_region)

Render the window, line by line, into the line buffer provided by the line_callback function.

The renderer uses a cache internally and will only render the part of the window which are dirty, depending on the dirty tracking policy set in SoftwareRenderer::new

The line callback will be called for each line and should provide a buffer to draw into.

As an example, let’s imagine we want to render into a plain buffer. (You wouldn’t normally use render_by_line for that because the Self::render would then be more efficient)

struct FrameBuffer<'a>{ frame_buffer: &'a mut [Rgb565Pixel], stride: usize }
impl<'a> LineBufferProvider for FrameBuffer<'a> {
    type TargetPixel = Rgb565Pixel;
    fn process_line(
        &mut self,
        line: usize,
        range: core::ops::Range<usize>,
        render_fn: impl FnOnce(&mut [Self::TargetPixel]),
    ) {
        let line_begin = line * self.stride;
        render_fn(&mut self.frame_buffer[line_begin..][range]);
        // The line has been rendered and there could be code here to
        // send the pixel to the display
    }
}
renderer.render_by_line(FrameBuffer{ frame_buffer: the_frame_buffer, stride: display_width });

Auto Trait Implementations§

Blanket Implementations§

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

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

Calls U::from(self).

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

The alignment of pointer.
The type for initializers.
Initializes a with the given initializer. Read more
Dereferences the given pointer. Read more
Mutably dereferences the given pointer. Read more
Drops the object pointed to by the given pointer. Read more
Should always be Self
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.
Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more