1//!
2//! # DumbBuffer
3//!
4//! Memory-supported, slow, but easy & cross-platform buffer implementation
5//!
6
7use buffer;
8
9#[derive(Debug, Copy, Clone, PartialEq, Eq)]
10/// Slow, but generic [`buffer::Buffer`] implementation
11pub struct DumbBuffer {
12 pub(crate) size: (u32, u32),
13 pub(crate) length: usize,
14 pub(crate) format: buffer::DrmFourcc,
15 pub(crate) pitch: u32,
16 pub(crate) handle: buffer::Handle,
17}
18
19/// Mapping of a [`DumbBuffer`]
20pub struct DumbMapping<'a> {
21 pub(crate) _phantom: core::marker::PhantomData<&'a ()>,
22 pub(crate) map: &'a mut [u8],
23}
24
25impl<'a> AsMut<[u8]> for DumbMapping<'a> {
26 fn as_mut(&mut self) -> &mut [u8] {
27 self.map
28 }
29}
30
31impl<'a> Drop for DumbMapping<'a> {
32 fn drop(&mut self) {
33 use nix::sys::mman;
34
35 unsafe {
36 mman::munmap(self.map.as_mut_ptr() as *mut _, self.map.len()).expect(msg:"Unmap failed");
37 }
38 }
39}
40
41impl buffer::Buffer for DumbBuffer {
42 fn size(&self) -> (u32, u32) {
43 self.size
44 }
45 fn format(&self) -> buffer::DrmFourcc {
46 self.format
47 }
48 fn pitch(&self) -> u32 {
49 self.pitch
50 }
51 fn handle(&self) -> buffer::Handle {
52 self.handle
53 }
54}
55