-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #246 from mahkoh/jorth/udmabuf
video: add udmabuf allocator
- Loading branch information
Showing
33 changed files
with
882 additions
and
255 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
use { | ||
crate::{ | ||
format::Format, | ||
video::{ | ||
dmabuf::{DmaBuf, DmaBufIds}, | ||
drm::Drm, | ||
Modifier, | ||
}, | ||
}, | ||
std::{error::Error, rc::Rc}, | ||
thiserror::Error, | ||
}; | ||
|
||
#[derive(Debug, Error)] | ||
#[error(transparent)] | ||
pub struct AllocatorError(#[from] pub Box<dyn Error>); | ||
|
||
bitflags! { | ||
BufferUsage: u32; | ||
BO_USE_SCANOUT = 1 << 0, | ||
BO_USE_CURSOR = 1 << 1, | ||
BO_USE_RENDERING = 1 << 2, | ||
BO_USE_WRITE = 1 << 3, | ||
BO_USE_LINEAR = 1 << 4, | ||
BO_USE_PROTECTED = 1 << 5, | ||
} | ||
|
||
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<Rc<dyn BufferObject>, AllocatorError>; | ||
fn import_dmabuf( | ||
&self, | ||
dmabuf: &DmaBuf, | ||
usage: BufferUsage, | ||
) -> Result<Rc<dyn BufferObject>, AllocatorError>; | ||
} | ||
|
||
pub trait BufferObject { | ||
fn dmabuf(&self) -> &DmaBuf; | ||
fn map_read(self: Rc<Self>) -> Result<Box<dyn MappedBuffer>, AllocatorError>; | ||
fn map_write(self: Rc<Self>) -> Result<Box<dyn MappedBuffer>, AllocatorError>; | ||
} | ||
|
||
pub trait MappedBuffer { | ||
unsafe fn data(&self) -> &[u8]; | ||
#[cfg_attr(not(test), allow(dead_code))] | ||
fn data_ptr(&self) -> *mut u8; | ||
fn stride(&self) -> i32; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.