Module smithay_client_toolkit::shm::multi
source · Expand description
A pool implementation which automatically manage buffers.
This pool is built on the RawPool
.
The MultiPool
takes a key which is used to identify buffers and tries to return the buffer associated to the key
if possible. If no buffer in the pool is associated to the key, it will create a new one.
§Example
use smithay_client_toolkit::reexports::client::{
QueueHandle,
protocol::wl_surface::WlSurface,
protocol::wl_shm::Format,
};
use smithay_client_toolkit::shm::multi::MultiPool;
struct WlFoo {
// The surface we'll draw on and the index of buffer associated to it
surface: (WlSurface, usize),
pool: MultiPool<(WlSurface, usize)>
}
impl WlFoo {
fn draw(&mut self, qh: &QueueHandle<WlFoo>) {
let surface = &self.surface.0;
// We'll increment "i" until the pool can create a new buffer
// if there's no buffer associated with our surface and "i" or if
// a buffer with the obuffer associated with our surface and "i" is free for use.
//
// There's no limit to the amount of buffers we can allocate to our surface but since
// shm buffers are released fairly fast, it's unlikely we'll need more than double buffering.
for i in 0..2 {
self.surface.1 = i;
if let Ok((offset, buffer, slice)) = self.pool.create_buffer(
100,
100 * 4,
100,
&self.surface,
Format::Argb8888,
) {
/*
insert drawing code here
*/
surface.attach(Some(buffer), 0, 0);
surface.commit();
// We exit the function after the draw.
return;
}
}
/*
If there's no buffer available we can for example request a frame callback
and trigger a redraw when it fires.
(not shown in this example)
*/
}
}
fn draw(slice: &mut [u8]) {
todo!()
}
Structs§
- This pool manages buffers associated with keys. Only one buffer can be attributed to a given key.