gfx: move shared memory contract into types crate
This commit is contained in:
parent
37ec1a4a3f
commit
bf3859a026
4 changed files with 36 additions and 27 deletions
3
Cargo.lock
generated
3
Cargo.lock
generated
|
|
@ -855,6 +855,9 @@ dependencies = [
|
|||
[[package]]
|
||||
name = "jay-gfx-types"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"uapi",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "jay-io-uring"
|
||||
|
|
|
|||
|
|
@ -5,3 +5,4 @@ edition = "2024"
|
|||
license = "GPL-3.0-only"
|
||||
|
||||
[dependencies]
|
||||
uapi = "0.2.13"
|
||||
|
|
|
|||
|
|
@ -1,3 +1,8 @@
|
|||
use {
|
||||
std::{cell::Cell, error::Error, rc::Rc},
|
||||
uapi::OwnedFd,
|
||||
};
|
||||
|
||||
#[derive(Copy, Clone, Debug, Eq, PartialEq, Hash, Default)]
|
||||
pub enum AlphaMode {
|
||||
#[default]
|
||||
|
|
@ -5,3 +10,29 @@ pub enum AlphaMode {
|
|||
PremultipliedOptical,
|
||||
Straight,
|
||||
}
|
||||
|
||||
pub trait ShmMemory {
|
||||
fn len(&self) -> usize;
|
||||
fn safe_access(&self) -> ShmMemoryBacking;
|
||||
fn access(&self, f: &mut dyn FnMut(&[Cell<u8>])) -> Result<(), Box<dyn Error + Sync + Send>>;
|
||||
}
|
||||
|
||||
pub enum ShmMemoryBacking {
|
||||
Ptr(*const [Cell<u8>]),
|
||||
Fd(Rc<OwnedFd>, usize),
|
||||
}
|
||||
|
||||
impl ShmMemory for Vec<Cell<u8>> {
|
||||
fn len(&self) -> usize {
|
||||
self.len()
|
||||
}
|
||||
|
||||
fn safe_access(&self) -> ShmMemoryBacking {
|
||||
ShmMemoryBacking::Ptr(&**self)
|
||||
}
|
||||
|
||||
fn access(&self, f: &mut dyn FnMut(&[Cell<u8>])) -> Result<(), Box<dyn Error + Sync + Send>> {
|
||||
f(self);
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -47,7 +47,7 @@ use {
|
|||
uapi::{OwnedFd, c},
|
||||
};
|
||||
|
||||
pub use jay_gfx_types::AlphaMode;
|
||||
pub use jay_gfx_types::{AlphaMode, ShmMemory, ShmMemoryBacking};
|
||||
|
||||
#[derive(Copy, Clone, Debug, Hash, Eq, PartialEq, Linearize)]
|
||||
pub enum GfxApi {
|
||||
|
|
@ -798,32 +798,6 @@ pub struct PendingShmTransfer {
|
|||
id: u64,
|
||||
}
|
||||
|
||||
pub trait ShmMemory {
|
||||
fn len(&self) -> usize;
|
||||
fn safe_access(&self) -> ShmMemoryBacking;
|
||||
fn access(&self, f: &mut dyn FnMut(&[Cell<u8>])) -> Result<(), Box<dyn Error + Sync + Send>>;
|
||||
}
|
||||
|
||||
pub enum ShmMemoryBacking {
|
||||
Ptr(*const [Cell<u8>]),
|
||||
Fd(Rc<OwnedFd>, usize),
|
||||
}
|
||||
|
||||
impl ShmMemory for Vec<Cell<u8>> {
|
||||
fn len(&self) -> usize {
|
||||
self.len()
|
||||
}
|
||||
|
||||
fn safe_access(&self) -> ShmMemoryBacking {
|
||||
ShmMemoryBacking::Ptr(&**self)
|
||||
}
|
||||
|
||||
fn access(&self, f: &mut dyn FnMut(&[Cell<u8>])) -> Result<(), Box<dyn Error + Sync + Send>> {
|
||||
f(self);
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
pub trait AsyncShmGfxTexture: GfxTexture {
|
||||
fn staging_size(&self) -> usize {
|
||||
0
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue