use { crate::{ format::Format, video::{ Modifier, dmabuf::{DmaBuf, DmaBufIds}, drm::Drm, }, }, std::{error::Error, rc::Rc}, thiserror::Error, }; #[derive(Debug, Error)] #[error(transparent)] pub struct AllocatorError(#[from] pub Box); bitflags! { BufferUsage: u32; BO_USE_SCANOUT, BO_USE_CURSOR, BO_USE_RENDERING, BO_USE_WRITE, BO_USE_LINEAR, BO_USE_PROTECTED, } pub trait Allocator { fn drm(&self) -> Option<&Drm>; fn create_bo( &self, dma_buf_ids: &DmaBufIds, width: i32, height: i32, format: &'static Format, modifiers: &[Modifier], usage: BufferUsage, ) -> Result, AllocatorError>; fn import_dmabuf( &self, dmabuf: &DmaBuf, usage: BufferUsage, ) -> Result, AllocatorError>; } pub trait BufferObject { fn dmabuf(&self) -> &DmaBuf; fn map_read(self: Rc) -> Result, AllocatorError>; fn map_write(self: Rc) -> Result, AllocatorError>; } pub trait MappedBuffer { unsafe fn data(&self) -> &[u8]; #[cfg_attr(not(feature = "it"), expect(dead_code))] fn data_ptr(&self) -> *mut u8; fn stride(&self) -> i32; }