Struct LiveImageWriter
pub struct LiveImageWriter { /* private fields */ }Expand description
A producer’s handle on a LiveImageSource. Send + Sync; clones share
one session token, and the source frees its pixels and becomes
Disconnected when the session’s last token drops.
Writes happen in transactions: lock, any number of
writes, then commit. One commit is one
generation however many writes it holds. The helpers
(write_frame, swap_frame,
write_rect, resize,
clear) each run one transaction of their own.
A writer waits only while a renderer copies bytes out of the buffer, a fraction of a millisecond for a 1080p frame.
Implementations§
§impl LiveImageWriter
impl LiveImageWriter
pub fn try_lock(&self) -> Result<LiveImageWriteGuard<'_>, LiveImageError>
pub fn try_lock(&self) -> Result<LiveImageWriteGuard<'_>, LiveImageError>
As lock, without waiting: [LiveImageError::WouldBlock]
while another transaction or a renderer holds the lock, this thread’s
own transaction included.
pub fn write_frame(
&self,
width: u32,
height: u32,
src: &[u8],
src_stride: usize,
) -> Result<u64, LiveImageError>
pub fn write_frame( &self, width: u32, height: u32, src: &[u8], src_stride: usize, ) -> Result<u64, LiveImageError>
Replace the whole frame, resizing if needed, and commit: one copy of
src, whose rows are src_stride bytes apart. Returns the new
generation.
pub fn swap_frame(
&self,
width: u32,
height: u32,
stride: usize,
pixels: Vec<u8>,
) -> Result<Vec<u8>, RejectedFrame>
pub fn swap_frame( &self, width: u32, height: u32, stride: usize, pixels: Vec<u8>, ) -> Result<Vec<u8>, RejectedFrame>
Install pixels as the frame without copying it, commit, and return
the previous buffer for reuse: empty on the first call and after the
pixels were freed. Its rows are stride bytes apart, at least
width × 4. The previous buffer holds older content, which the
producer must rewrite in full before its next swap.
§Errors
A [RejectedFrame] carrying the error and pixels, untouched.
pub fn write_rect(
&self,
rect: PixelRect,
src: &[u8],
src_stride: usize,
) -> Result<u64, LiveImageError>
pub fn write_rect( &self, rect: PixelRect, src: &[u8], src_stride: usize, ) -> Result<u64, LiveImageError>
Copy one rect from src, whose row 0 is the rect’s top row and whose
rows are src_stride bytes apart, and commit.
pub fn resize(&self, width: u32, height: u32) -> Result<u64, LiveImageError>
pub fn resize(&self, width: u32, height: u32) -> Result<u64, LiveImageError>
Resize, zero-filled, and commit. A no-op at the current size. The
status is kept: a resize while Waiting stays Waiting.
pub fn clear(&self) -> Result<(), LiveImageError>
pub fn clear(&self) -> Result<(), LiveImageError>
Free the pixels and return to Waiting; their size becomes the size
hint. Every window frees its texture at its next render.
pub fn is_observed(&self) -> bool
pub fn is_observed(&self) -> bool
pub fn is_displayed(&self) -> bool
pub fn is_displayed(&self) -> bool
pub fn source(&self) -> LiveImageSource
pub fn stats(&self) -> LiveImageSourceStats
Trait Implementations§
§impl Clone for LiveImageWriter
impl Clone for LiveImageWriter
§fn clone(&self) -> LiveImageWriter
fn clone(&self) -> LiveImageWriter
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreAuto Trait Implementations§
impl !RefUnwindSafe for LiveImageWriter
impl !UnwindSafe for LiveImageWriter
impl Freeze for LiveImageWriter
impl Send for LiveImageWriter
impl Sync for LiveImageWriter
impl Unpin for LiveImageWriter
impl UnsafeUnpin for LiveImageWriter
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> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
§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.§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.§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.§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.§impl<T> DowncastSync for T
impl<T> DowncastSync for T
impl<T> ErasedDestructor for Twhere
T: 'static,
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more