use super::{From, FromOpt, Buffer, Shm, ShmFormat};
use ffi::interfaces::shm::wl_shm_create_pool;
use ffi::interfaces::shm_pool::{wl_shm_pool, wl_shm_pool_destroy};
use ffi::FFI;
pub struct ShmPool {
_shm: Shm,
ptr: *mut wl_shm_pool
}
unsafe impl Send for ShmPool {}
unsafe impl Sync for ShmPool {}
impl ShmPool {
pub fn create_buffer<'b>(&self, offset: i32, width: i32, height: i32, stride: i32, format: ShmFormat)
-> Option<Buffer> {
FromOpt::from((self, offset, width, height, stride, format as u32))
}
}
impl From<(Shm, i32, i32)> for ShmPool {
fn from((shm, fd, size): (Shm, i32, i32)) -> ShmPool {
let ptr = unsafe { wl_shm_create_pool(shm.ptr_mut(), fd, size) };
ShmPool {
_shm: shm,
ptr: ptr
}
}
}
impl Drop for ShmPool {
fn drop(&mut self) {
unsafe { wl_shm_pool_destroy(self.ptr) };
}
}
impl FFI for ShmPool {
type Ptr = wl_shm_pool;
fn ptr(&self) -> *const wl_shm_pool {
self.ptr as *const wl_shm_pool
}
unsafe fn ptr_mut(&self) -> *mut wl_shm_pool {
self.ptr
}
}