1
0
Fork 0
forked from wry/wry

it: implement AsyncShmGfxTexture

This commit is contained in:
Julian Orth 2024-09-07 20:48:09 +02:00
parent 0a0caf3800
commit cf74756c34

View file

@ -1,14 +1,15 @@
use {
crate::{
allocator::{Allocator, AllocatorError, BufferObject, BufferUsage},
clientmem::{ClientMemError, ClientMemOffset},
cpu_worker::CpuWorker,
format::{Format, ARGB8888, XRGB8888},
gfx_api::{
AsyncShmGfxTexture, CopyTexture, FillRect, FramebufferRect, GfxApiOpt, GfxContext,
GfxError, GfxFormat, GfxFramebuffer, GfxImage, GfxTexture, GfxWriteModifier,
ResetStatus, ShmGfxTexture, SyncFile,
AsyncShmGfxTexture, AsyncShmGfxTextureCallback, CopyTexture, FillRect, FramebufferRect,
GfxApiOpt, GfxContext, GfxError, GfxFormat, GfxFramebuffer, GfxImage, GfxTexture,
GfxWriteModifier, PendingShmUpload, ResetStatus, ShmGfxTexture, SyncFile,
},
rect::Rect,
rect::{Rect, Region},
theme::Color,
video::{dmabuf::DmaBuf, drm::sync_obj::SyncObjCtx, LINEAR_MODIFIER},
},
@ -33,6 +34,8 @@ enum TestGfxError {
MapDmaBuf(#[source] AllocatorError),
#[error("Could not import dmabuf")]
ImportDmaBuf(#[source] AllocatorError),
#[error("Could not access the client memory")]
AccessFailed(#[source] ClientMemError),
}
impl From<TestGfxError> for GfxError {
@ -136,13 +139,21 @@ impl GfxContext for TestGfxCtx {
fn async_shmem_texture(
self: Rc<Self>,
_format: &'static Format,
_width: i32,
_height: i32,
_stride: i32,
format: &'static Format,
width: i32,
height: i32,
stride: i32,
_cpu_worker: &Rc<CpuWorker>,
) -> Result<Rc<dyn AsyncShmGfxTexture>, GfxError> {
todo!()
assert!(stride >= width * 4);
let size = (stride * height) as usize;
Ok(Rc::new(TestGfxImage::Shm(TestShmGfxImage {
data: RefCell::new(vec![0; size]),
width,
height,
stride,
format,
})))
}
fn allocator(&self) -> Rc<dyn Allocator> {
@ -320,6 +331,48 @@ impl ShmGfxTexture for TestGfxImage {
}
}
impl AsyncShmGfxTexture for TestGfxImage {
fn async_upload(
self: Rc<Self>,
_callback: Rc<dyn AsyncShmGfxTextureCallback>,
mem: &Rc<ClientMemOffset>,
damage: Region,
) -> Result<Option<PendingShmUpload>, GfxError> {
mem.access(|d| self.clone().sync_upload(d, damage))
.map_err(TestGfxError::AccessFailed)??;
Ok(None)
}
fn sync_upload(self: Rc<Self>, mem: &[Cell<u8>], _damage: Region) -> Result<(), GfxError> {
let TestGfxImage::Shm(shm) = &*self else {
unreachable!();
};
let data = &mut *shm.data.borrow_mut();
assert!(mem.len() >= data.len());
unsafe {
ptr::copy_nonoverlapping(mem.as_ptr() as _, data.as_mut_ptr(), data.len());
}
Ok(())
}
fn compatible_with(
&self,
format: &'static Format,
width: i32,
height: i32,
stride: i32,
) -> bool {
let TestGfxImage::Shm(shm) = &self else {
unreachable!();
};
shm.format == format && shm.width == width && shm.height == height && shm.stride == stride
}
fn into_texture(self: Rc<Self>) -> Rc<dyn GfxTexture> {
self
}
}
impl GfxImage for TestGfxImage {
fn to_framebuffer(self: Rc<Self>) -> Result<Rc<dyn GfxFramebuffer>, GfxError> {
Ok(Rc::new(TestGfxFb {