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: u32Width in pixels.
height: u32Height in pixels.
format: SourceFormatHow the payload’s pixels are laid out.
Implementations§
Source§impl SourceFrame
impl SourceFrame
Sourcepub fn new(
width: u32,
height: u32,
format: SourceFormat,
payload: SourcePayload,
) -> SourceFrame
pub fn new( width: u32, height: u32, format: SourceFormat, payload: SourcePayload, ) -> SourceFrame
A frame of the given extent and format over payload, with no release
callback.
Sourcepub fn rgba8(width: u32, height: u32, pixels: Arc<[u8]>) -> SourceFrame
pub fn rgba8(width: u32, height: u32, pixels: Arc<[u8]>) -> SourceFrame
A CPU frame of tightly packed premultiplied RGBA8 with no release callback.
Sourcepub fn on_release(self, release: impl FnOnce() + Send + 'static) -> SourceFrame
pub fn on_release(self, release: impl FnOnce() + Send + 'static) -> SourceFrame
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.
Sourcepub fn meta(&self) -> SourceMeta
pub fn meta(&self) -> SourceMeta
The extent and format.
Sourcepub fn payload(&self) -> &SourcePayload
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.
Sourcepub fn has_release(&self) -> bool
pub fn has_release(&self) -> bool
Whether a release callback is attached.
Sourcepub unsafe fn into_parts(
self,
) -> (SourceMeta, SourcePayload, Option<Box<dyn FnOnce() + Send>>)
pub unsafe fn into_parts( self, ) -> (SourceMeta, SourcePayload, Option<Box<dyn FnOnce() + Send>>)
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.
Trait Implementations§
Source§impl Debug for SourceFrame
impl Debug for SourceFrame
Auto Trait Implementations§
impl !RefUnwindSafe for SourceFrame
impl !Sync for SourceFrame
impl !UnwindSafe for SourceFrame
impl Freeze for SourceFrame
impl Send for SourceFrame
impl Unpin for SourceFrame
impl UnsafeUnpin for SourceFrame
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.