pub struct AutoMemPool {
    inner: Inner,
    align: usize,
    free_list: Rc<RefCell<Vec<(usize, usize)>>>,
}
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.

Fields§

§inner: Inner§align: usize§free_list: Rc<RefCell<Vec<(usize, usize)>>>

Implementations§

source§

impl AutoMemPool

source

pub fn new(shm: Attached<WlShm>) -> Result<AutoMemPool>

Create a new memory pool associated with the given shm

source

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.

source

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.

source

fn alloc(&mut self, size: usize) -> Result<usize>

source

fn free(free_list: &RefCell<Vec<(usize, usize)>>, offset: usize, len: usize)

source

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 one
  • format: the encoding format of the pixels. Using a format that was not advertised to the wl_shm global by the server is a protocol error and will terminate your connection
source

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§

source§

impl Debug for AutoMemPool

source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere 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, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

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.