pub struct CpuBytes { /* private fields */ }Expand description
Flat CPU byte buffer. The raw ptr is non-owning; keep_alive pins
whatever owns the backing allocation (an SDK decoder’s frame anchor,
an aligned-buffer pool slot, a boxed expand buffer, …) so the bytes
outlive every clone the caller hands off. Pass None only when the
caller guarantees the allocation’s lifetime by other means (e.g. a
test stack buffer that outlives the handle).
Implementations§
Source§impl CpuBytes
impl CpuBytes
Sourcepub unsafe fn try_from_raw(
ptr: *mut u8,
size: usize,
row_pitch: u32,
format: PixelFormat,
keep_alive: Option<KeepAlive>,
) -> Result<Self, InvalidHandleError>
pub unsafe fn try_from_raw( ptr: *mut u8, size: usize, row_pitch: u32, format: PixelFormat, keep_alive: Option<KeepAlive>, ) -> Result<Self, InvalidHandleError>
Wrap a flat CPU byte buffer. Borrowing: the handle is stored
non-owningly, this type has no Drop, and every obligation below
extends to each Clone.
§Safety
ptrmust point tosizebytes that are valid to read and write — upload paths read the whole range, readback paths write it. Bothptr == nullandsize == 0are rejected (InvalidHandleError::NullPointer/InvalidHandleError::ZeroSize) and are therefore not caller obligations; nothing else about the range is checkable here.row_pitchmust be the real row stride in bytes andformatthe real layout, such thatrow_pitch * <rows implied by format and the consumer's extent>fits insidesize. Consumers index rows byrow_pitch, so an over-stated pitch or format walks off the end of the allocation.- Aliasing. The pointer is stored as
*mut u8and handed to consumers that may write through it, whileClonehands out further copies. For the duration of this value and every clone the caller must not hold a&/&mutRust reference to the same bytes, and must not let two consumers write the same range concurrently —CpuBytesprovides no synchronisation of its own even though it isSend + Sync. - Lifetime. Nothing is retained and there is no
Drop: the backing allocation is neither freed nor kept alive here. It must outlive this value and every clone, pinned either by thekeep_aliveanchor (an SDK decoder’s frame anchor, an aligned-buffer pool slot, a boxed expand buffer) or, whenkeep_aliveisNone, by the caller directly. A pool slot recycled while a clone survives is a use-after-free.
pub fn ptr(&self) -> *mut u8
pub fn size(&self) -> usize
pub fn row_pitch(&self) -> u32
pub fn format(&self) -> PixelFormat
pub fn keep_alive(&self) -> Option<&KeepAlive>
Trait Implementations§
impl Send for CpuBytes
impl Sync for CpuBytes
Auto Trait Implementations§
impl !RefUnwindSafe for CpuBytes
impl !UnwindSafe for CpuBytes
impl Freeze for CpuBytes
impl Unpin for CpuBytes
impl UnsafeUnpin for CpuBytes
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more