Skip to main content

SourceFrame

Struct SourceFrame 

Source
pub struct SourceFrame {
    pub width: u32,
    pub height: u32,
    pub format: SourceFormat,
    /* private fields */
}
Expand description

One frame a source hands the bus.

The extent and format are plain public fields; the payload and the release callback are private, so they stay together. Build a frame with Self::new or Self::rgba8 and attach a callback with Self::on_release; read the payload in place with Self::payload.

Dropping a frame that still holds its release callback runs it: the bus runs it for every frame it is handed (see the module docs), and a frame nobody released — dropped by a holder that never passed it on, or lost to a panic in the source or the pass — still releases, exactly once. Because the type implements Drop, it cannot be destructured; the bus splits it with the unsafe Self::into_parts. A release callback must not panic: the guard around it only applies to panic=unwind builds (see [run_release]).

Fields§

§width: u32

Width in pixels.

§height: u32

Height in pixels.

§format: SourceFormat

How the payload’s pixels are laid out.

Implementations§

Source§

impl SourceFrame

Source

pub fn new( width: u32, height: u32, format: SourceFormat, payload: SourcePayload, ) -> Self

A frame of the given extent and format over payload, with no release callback.

Source

pub fn rgba8(width: u32, height: u32, pixels: Arc<[u8]>) -> Self

A CPU frame of tightly packed premultiplied RGBA8 with no release callback.

Source

pub fn on_release(self, release: impl FnOnce() + Send + 'static) -> Self

Attaches the callback run once the bus is done with the frame. A callback already attached runs first (through the same guard as every other release), so no callback is ever dropped unrun.

Source

pub fn meta(&self) -> SourceMeta

The extent and format.

Source

pub fn payload(&self) -> &SourcePayload

The pixels, or the platform buffer holding them, borrowed in place. The frame still owns the payload and its release callback.

Source

pub fn has_release(&self) -> bool

Whether a release callback is attached.

Source

pub unsafe fn into_parts( self, ) -> (SourceMeta, SourcePayload, Option<ReleaseCallback>)

Consumes the frame, handing over its extent and format, its payload and its release callback, and disarms the drop guard — the one way to move a native handle out of a frame. A caller that only needs to read the frame uses Self::meta and Self::payload instead.

§Safety

The caller must run the returned release callback exactly once, after the last use of the payload’s native handle (or move it, with the handle, into a holder that does), and must not place that handle into another frame without it. The callback gives the producer’s reference to the buffer back; a handle used after it ran points at a buffer the producer no longer keeps alive.

Source

pub fn release(self)

Runs the release callback, if any, consuming the frame — the same as dropping it, spelled out.

Trait Implementations§

Source§

impl Debug for SourceFrame

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Drop for SourceFrame

Source§

fn drop(&mut self)

A frame dropped still holding its callback was released by no one, so it releases itself; one whose callback already ran or was taken on (into a held import) is None here.

Source§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. Read more

Auto Trait Implementations§

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> 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, S> SimdFrom<T, S> for T
where S: Simd,

Source§

fn simd_from(_simd: S, value: T) -> T

Source§

impl<F, T, S> SimdInto<T, S> for F
where T: SimdFrom<F, S>, S: Simd,

Source§

fn simd_into(self, simd: S) -> T

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> WasmNotSend for T
where T: Send,