Skip to main content

SwapChain

Struct SwapChain 

Source
pub struct SwapChain<const W: usize, const H: usize, FB, B>
where FB: DMACapableFrameBufferBackend<Color = Rgb565>, B: DisplayBackend<W, H, FB>,
{ /* private fields */ }
Expand description

Double-buffered swap chain for tear-free rendering.

The back buffer is always available to the CPU via get_back_buffer. The front buffer moves into the backend’s DMA transfer token on each present call and is recovered (blocking) on the next one.

§Type Parameters

Implementations§

Source§

impl<const W: usize, const H: usize, B> SwapChain<W, H, EndianCorrectedBuffer<'static, Rgb565>, B>
where B: DisplayBackend<W, H, EndianCorrectedBuffer<'static, Rgb565>>,

Source

pub fn from_static_slices( front_data: &'static mut [Rgb565], back_data: &'static mut [Rgb565], big_endian: bool, backend: B, ) -> Self

Create a new swap chain from static slices.

§Arguments
  • front_data — Static mutable slice for the front framebuffer.
  • back_data — Static mutable slice for the back framebuffer.
  • big_endian — Byte order of pixel data sent to the display.
  • backend — Display backend used for DMA operations.
§Example
static mut FB0: [Rgb565; 240 * 135] = [Rgb565::BLACK; 240 * 135];
static mut FB1: [Rgb565; 240 * 135] = [Rgb565::BLACK; 240 * 135];

let swap_chain = unsafe {
    StandardSwapChain::<240, 135, _>::from_static_slices(
        &mut FB0,
        &mut FB1,
        false,
        MyHardwareBackend::new(),
    )
};
Source§

impl<const W: usize, const H: usize, FB, B> SwapChain<W, H, FB, B>
where FB: DMACapableFrameBufferBackend<Color = Rgb565>, B: DisplayBackend<W, H, FB>,

Source

pub fn get_back_buffer(&mut self) -> &mut FrameBuf<Rgb565, FB>

Get a mutable reference to the back buffer for rendering.

The back buffer is always available — DMA only ever touches the front buffer, which is kept separately.

Source

pub fn get_front_buffer(&self) -> Option<&FrameBuf<Rgb565, FB>>

Get a reference to the front buffer if it is currently idle.

Returns None while a DMA transfer is in progress.

Source

pub fn present(&mut self) -> Result<(), DisplayError>

Present the back buffer (blocking).

  1. Waits for any in-progress DMA transfer to complete.
  2. Swaps the front and back buffers.
  3. Starts a new DMA transfer of the new front buffer.

After this call returns, the CPU may immediately start rendering to the new back buffer while DMA reads from the new front buffer.

Source

pub fn try_present(&mut self) -> Result<(), DisplayError>

Present the back buffer without blocking.

Returns DisplayError::Busy immediately if a DMA transfer is still in progress, leaving both buffers unchanged.

Source

pub fn present_region( &mut self, region: DisplayRegion, ) -> Result<(), DisplayError>

Present only a sub-region of the back buffer (blocking).

Backends that do not support partial DMA automatically fall back to a full-frame transfer.

Source

pub fn try_present_region( &mut self, region: DisplayRegion, ) -> Result<(), DisplayError>

Non-blocking partial present.

Returns DisplayError::Busy if a transfer is still running.

Source

pub fn wait_for_vsync(&mut self)

Block until the current DMA transfer completes.

After this call the front buffer is in the idle state and the next present will not need to wait.

Source

pub async fn wait_for_vsync_async(&mut self)
where B::Transfer: AsyncDmaTransfer<Buffer = FrameBuf<Rgb565, FB>>,

Wait for the current DMA transfer to complete asynchronously.

Source

pub async fn present_async(&mut self) -> Result<(), DisplayError>
where B::Transfer: AsyncDmaTransfer<Buffer = FrameBuf<Rgb565, FB>>,

Present the back buffer asynchronously.

Source

pub async fn present_region_async( &mut self, region: DisplayRegion, ) -> Result<(), DisplayError>
where B::Transfer: AsyncDmaTransfer<Buffer = FrameBuf<Rgb565, FB>>,

Present only a sub-region of the back buffer asynchronously.

Source

pub fn is_ready(&self) -> bool

Returns true if no DMA transfer is running (or the hardware has signalled completion), so try_present would succeed.

Source

pub fn frame_count(&self) -> u64

Total number of frames presented since construction (or the last reset_frame_count call).

Source

pub fn reset_frame_count(&mut self)

Reset the frame counter to zero.

Source

pub fn dimensions(&self) -> (usize, usize)

Framebuffer dimensions (W, H).

Auto Trait Implementations§

§

impl<const W: usize, const H: usize, FB, B> Freeze for SwapChain<W, H, FB, B>
where B: Freeze, FB: Freeze, <B as DisplayBackend<W, H, FB>>::Transfer: Freeze,

§

impl<const W: usize, const H: usize, FB, B> RefUnwindSafe for SwapChain<W, H, FB, B>

§

impl<const W: usize, const H: usize, FB, B> Send for SwapChain<W, H, FB, B>
where B: Send, FB: Send, <B as DisplayBackend<W, H, FB>>::Transfer: Send,

§

impl<const W: usize, const H: usize, FB, B> Sync for SwapChain<W, H, FB, B>
where B: Sync, FB: Sync, <B as DisplayBackend<W, H, FB>>::Transfer: Sync,

§

impl<const W: usize, const H: usize, FB, B> Unpin for SwapChain<W, H, FB, B>
where B: Unpin, FB: Unpin, <B as DisplayBackend<W, H, FB>>::Transfer: Unpin,

§

impl<const W: usize, const H: usize, FB, B> UnsafeUnpin for SwapChain<W, H, FB, B>
where B: UnsafeUnpin, FB: UnsafeUnpin, <B as DisplayBackend<W, H, FB>>::Transfer: UnsafeUnpin,

§

impl<const W: usize, const H: usize, FB, B> UnwindSafe for SwapChain<W, H, FB, B>
where B: UnwindSafe, FB: UnwindSafe, <B as DisplayBackend<W, H, FB>>::Transfer: 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> Az for T

Source§

fn az<Dst>(self) -> Dst
where T: Cast<Dst>,

Casts the value.
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<Src, Dst> CastFrom<Src> for Dst
where Src: Cast<Dst>,

Source§

fn cast_from(src: Src) -> Dst

Casts the value.
Source§

impl<T> CheckedAs for T

Source§

fn checked_as<Dst>(self) -> Option<Dst>
where T: CheckedCast<Dst>,

Casts the value.
Source§

impl<Src, Dst> CheckedCastFrom<Src> for Dst
where Src: CheckedCast<Dst>,

Source§

fn checked_cast_from(src: Src) -> Option<Dst>

Casts the value.
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> OverflowingAs for T

Source§

fn overflowing_as<Dst>(self) -> (Dst, bool)
where T: OverflowingCast<Dst>,

Casts the value.
Source§

impl<Src, Dst> OverflowingCastFrom<Src> for Dst
where Src: OverflowingCast<Dst>,

Source§

fn overflowing_cast_from(src: Src) -> (Dst, bool)

Casts the value.
Source§

impl<T> SaturatingAs for T

Source§

fn saturating_as<Dst>(self) -> Dst
where T: SaturatingCast<Dst>,

Casts the value.
Source§

impl<Src, Dst> SaturatingCastFrom<Src> for Dst
where Src: SaturatingCast<Dst>,

Source§

fn saturating_cast_from(src: Src) -> Dst

Casts the value.
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.
Source§

impl<T> UnwrappedAs for T

Source§

fn unwrapped_as<Dst>(self) -> Dst
where T: UnwrappedCast<Dst>,

Casts the value.
Source§

impl<Src, Dst> UnwrappedCastFrom<Src> for Dst
where Src: UnwrappedCast<Dst>,

Source§

fn unwrapped_cast_from(src: Src) -> Dst

Casts the value.
Source§

impl<T> WrappingAs for T

Source§

fn wrapping_as<Dst>(self) -> Dst
where T: WrappingCast<Dst>,

Casts the value.
Source§

impl<Src, Dst> WrappingCastFrom<Src> for Dst
where Src: WrappingCast<Dst>,

Source§

fn wrapping_cast_from(src: Src) -> Dst

Casts the value.