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]]
|
[[package]]
|
||||||
name = "jay-gfx-types"
|
name = "jay-gfx-types"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
|
dependencies = [
|
||||||
|
"uapi",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "jay-io-uring"
|
name = "jay-io-uring"
|
||||||
|
|
|
||||||
|
|
@ -5,3 +5,4 @@ edition = "2024"
|
||||||
license = "GPL-3.0-only"
|
license = "GPL-3.0-only"
|
||||||
|
|
||||||
[dependencies]
|
[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)]
|
#[derive(Copy, Clone, Debug, Eq, PartialEq, Hash, Default)]
|
||||||
pub enum AlphaMode {
|
pub enum AlphaMode {
|
||||||
#[default]
|
#[default]
|
||||||
|
|
@ -5,3 +10,29 @@ pub enum AlphaMode {
|
||||||
PremultipliedOptical,
|
PremultipliedOptical,
|
||||||
Straight,
|
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},
|
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)]
|
#[derive(Copy, Clone, Debug, Hash, Eq, PartialEq, Linearize)]
|
||||||
pub enum GfxApi {
|
pub enum GfxApi {
|
||||||
|
|
@ -798,32 +798,6 @@ pub struct PendingShmTransfer {
|
||||||
id: u64,
|
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 {
|
pub trait AsyncShmGfxTexture: GfxTexture {
|
||||||
fn staging_size(&self) -> usize {
|
fn staging_size(&self) -> usize {
|
||||||
0
|
0
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue