pub struct SwapChain<const W: usize, const H: usize, FB, B>{ /* 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
W,H: Framebuffer dimensions in pixels (const generics).FB: Framebuffer backend implementingDMACapableFrameBufferBackend.B: Display backend implementingDisplayBackend<W, H, FB>.
Implementations§
Source§impl<const W: usize, const H: usize, B> SwapChain<W, H, EndianCorrectedBuffer<'static, Rgb565>, B>
impl<const W: usize, const H: usize, B> SwapChain<W, H, EndianCorrectedBuffer<'static, Rgb565>, B>
Sourcepub fn from_static_slices(
front_data: &'static mut [Rgb565],
back_data: &'static mut [Rgb565],
big_endian: bool,
backend: B,
) -> Self
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>
impl<const W: usize, const H: usize, FB, B> SwapChain<W, H, FB, B>
Sourcepub fn get_back_buffer(&mut self) -> &mut FrameBuf<Rgb565, FB>
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.
Sourcepub fn get_front_buffer(&self) -> Option<&FrameBuf<Rgb565, FB>>
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.
Sourcepub fn present(&mut self) -> Result<(), DisplayError>
pub fn present(&mut self) -> Result<(), DisplayError>
Present the back buffer (blocking).
- Waits for any in-progress DMA transfer to complete.
- Swaps the front and back buffers.
- 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.
Sourcepub fn try_present(&mut self) -> Result<(), DisplayError>
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.
Sourcepub fn present_region(
&mut self,
region: DisplayRegion,
) -> Result<(), DisplayError>
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.
Sourcepub fn try_present_region(
&mut self,
region: DisplayRegion,
) -> Result<(), DisplayError>
pub fn try_present_region( &mut self, region: DisplayRegion, ) -> Result<(), DisplayError>
Non-blocking partial present.
Returns DisplayError::Busy if a transfer is still running.
Sourcepub fn wait_for_vsync(&mut self)
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.
Sourcepub async fn wait_for_vsync_async(&mut self)
pub async fn wait_for_vsync_async(&mut self)
Wait for the current DMA transfer to complete asynchronously.
Sourcepub async fn present_async(&mut self) -> Result<(), DisplayError>
pub async fn present_async(&mut self) -> Result<(), DisplayError>
Present the back buffer asynchronously.
Sourcepub async fn present_region_async(
&mut self,
region: DisplayRegion,
) -> Result<(), DisplayError>
pub async fn present_region_async( &mut self, region: DisplayRegion, ) -> Result<(), DisplayError>
Present only a sub-region of the back buffer asynchronously.
Sourcepub fn is_ready(&self) -> bool
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.
Sourcepub fn frame_count(&self) -> u64
pub fn frame_count(&self) -> u64
Total number of frames presented since construction (or the last
reset_frame_count call).
Sourcepub fn reset_frame_count(&mut self)
pub fn reset_frame_count(&mut self)
Reset the frame counter to zero.
Sourcepub fn dimensions(&self) -> (usize, usize)
pub fn dimensions(&self) -> (usize, usize)
Framebuffer dimensions (W, H).