Struct smithay_client_toolkit::shm::AutoMemPool
source · [−]pub struct AutoMemPool { /* private fields */ }
Expand description
A wrapper handling an SHM memory pool backed by a shared memory file
This wrapper handles the creation of the shared memory file, its synchronization with the protocol, and the allocation of buffers within the pool.
AutoMemPool internally tracks the release of the buffers by the compositor. As such, creating a buffer that is not committed to a surface (and then never released by the server) would result in that memory being unavailable for the rest of the pool’s lifetime.
AutoMemPool will also handle the destruction of buffers; do not call destroy() on the returned WlBuffer objects.
The default alignment of returned buffers is 16 bytes; this can be changed by using the explicit with_min_align constructor.
Implementations
sourceimpl AutoMemPool
impl AutoMemPool
sourcepub fn new(shm: Attached<WlShm>) -> Result<AutoMemPool>
pub fn new(shm: Attached<WlShm>) -> Result<AutoMemPool>
Create a new memory pool associated with the given shm
sourcepub fn with_min_align(shm: Attached<WlShm>, align: usize) -> Result<AutoMemPool>
pub fn with_min_align(shm: Attached<WlShm>, align: usize) -> Result<AutoMemPool>
Create a new memory pool associated with the given shm.
All buffers will be aligned to at least the value of (align), which must be a power of two not greater than 4096.
sourcepub fn resize(&mut self, new_size: usize) -> Result<()>
pub fn resize(&mut self, new_size: usize) -> Result<()>
Resize the memory pool
This is normally done automatically, but can be used to avoid multiple resizes.
sourcepub fn buffer(
&mut self,
width: i32,
height: i32,
stride: i32,
format: Format
) -> Result<(&mut [u8], WlBuffer)>
pub fn buffer(
&mut self,
width: i32,
height: i32,
stride: i32,
format: Format
) -> Result<(&mut [u8], WlBuffer)>
Create a new buffer in this pool
The parameters are:
width
: the width of this buffer (in pixels)height
: the height of this buffer (in pixels)stride
: distance (in bytes) between the beginning of a row and the next oneformat
: the encoding format of the pixels. Using a format that was not advertised to thewl_shm
global by the server is a protocol error and will terminate your connection
sourcepub fn try_draw<F, E>(
&mut self,
width: i32,
height: i32,
stride: i32,
format: Format,
draw: F
) -> Result<WlBuffer, E> where
F: FnOnce(&mut [u8]) -> Result<(), E>,
E: From<Error>,
pub fn try_draw<F, E>(
&mut self,
width: i32,
height: i32,
stride: i32,
format: Format,
draw: F
) -> Result<WlBuffer, E> where
F: FnOnce(&mut [u8]) -> Result<(), E>,
E: From<Error>,
Try drawing with the given closure
This is identical to buffer(), but will only actually create the WlBuffer if the draw closure succeeds. Otherwise, the buffer is freed immediately instead of waiting for a Release event that will never be sent if the WlBuffer is not used.
Trait Implementations
Auto Trait Implementations
impl !RefUnwindSafe for AutoMemPool
impl !Send for AutoMemPool
impl !Sync for AutoMemPool
impl Unpin for AutoMemPool
impl !UnwindSafe for AutoMemPool
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more