Skip to main content

ReadbackSurface

Struct ReadbackSurface 

Source
pub struct ReadbackSurface { /* private fields */ }
Expand description

Reusable GPU-to-CPU color readback surface owning a staging buffer and a persistent pixel cache.

Handles 256-byte row-pitch unpadding, optional R/B channel swizzling, optional Y-axis flip, and optional unpremultiplication, while retaining Self::cached_pixels for zero-cost idle frames.

Implementations§

Source§

impl ReadbackSurface

Source

pub fn new(options: ReadbackOptions) -> Self

Source

pub fn options(&self) -> ReadbackOptions

Source

pub fn set_options(&mut self, options: ReadbackOptions)

Source

pub fn width(&self) -> u32

Source

pub fn height(&self) -> u32

Source

pub fn unpadded_row_pitch(&self) -> u32

Source

pub fn size_bytes(&self) -> usize

Source

pub fn cached_pixels(&self) -> &[u8] ⓘ

Source

pub fn ensure_dimensions( &mut self, device: &Device, width: u32, height: u32, ) -> bool

Ensures the staging buffer and CPU cache match (width, height), clamping to at least 1x1. Returns true if the staging buffer was allocated or reallocated.

Source

pub fn copy_from_texture( &self, encoder: &mut CommandEncoder, texture: &Texture, ) -> Result<(), ReadbackError>

Encodes a GPU texture-to-staging-buffer copy into encoder.

Source

pub fn map_and_repack( &mut self, device: &Device, ) -> Result<&[u8], ReadbackError>

Synchronously maps the staging buffer, unpacks rows into Self::cached_pixels, and unmaps.

Source

pub fn readback_sync( &mut self, device: &Device, queue: &Queue, texture: &Texture, ) -> Result<&[u8], ReadbackError>

Ensures dimensions match texture, submits a copy command, and reads back the pixels synchronously.

Auto Trait Implementations§

§

impl !RefUnwindSafe for ReadbackSurface

§

impl !UnwindSafe for ReadbackSurface

§

impl Forget for ReadbackSurface

§

impl Freeze for ReadbackSurface
where *const ArcInner<CoreBuffer> is !null: Freeze, PhantomData<ArcInner<CoreBuffer>>: Freeze, *const ArcInner<Mutex<MapContext>> is !null: Freeze, PhantomData<ArcInner<Mutex<MapContext>>>: Freeze, InternalBitFlags: Freeze, *const u8 is !null: Freeze, PhantomData<u8>: Freeze,

§

impl Move for ReadbackSurface

§

impl Send for ReadbackSurface
where Arc<CoreBuffer>: Send, Arc<Mutex<MapContext>>: Send, InternalBitFlags: Send, RawVecInner: Send,

§

impl Sync for ReadbackSurface
where Arc<CoreBuffer>: Sync, Arc<Mutex<MapContext>>: Sync, InternalBitFlags: Sync, RawVecInner: Sync,

§

impl Unpin for ReadbackSurface
where Arc<CoreBuffer>: Unpin, Arc<Mutex<MapContext>>: Unpin, InternalBitFlags: Unpin, *const u8 is !null: Unpin,

§

impl UnsafeUnpin for ReadbackSurface
where *const ArcInner<CoreBuffer> is !null: UnsafeUnpin, PhantomData<ArcInner<CoreBuffer>>: UnsafeUnpin, *const ArcInner<Mutex<MapContext>> is !null: UnsafeUnpin, PhantomData<ArcInner<Mutex<MapContext>>>: UnsafeUnpin, InternalBitFlags: UnsafeUnpin, *const u8 is !null: UnsafeUnpin, PhantomData<u8>: UnsafeUnpin,

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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> Downcast<T> for T

Source§

fn downcast(&self) -> &T

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> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

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

impl<T> Upcast<T> for T

Source§

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

Source§

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

Source§

impl<T> WasmNotSendSync for T

Source§

impl<T> WasmNotSync for T
where T: Sync,