1
0
Fork 0
forked from wry/wry

linux-dmabuf: intercept udmabuf buffers

This commit is contained in:
Julian Orth 2025-10-01 17:34:24 +02:00
parent 0570669af2
commit 410281b13e
5 changed files with 131 additions and 32 deletions

View file

@ -108,6 +108,7 @@ impl WlBuffer {
stride: i32,
format: &'static Format,
mem: &Rc<ClientMem>,
udmabuf: Option<(&Rc<OwnedFd>, usize)>,
) -> Result<Self, WlBufferError> {
let bytes = stride as u64 * height as u64;
let required = bytes + offset as u64;
@ -119,6 +120,26 @@ impl WlBuffer {
if (stride as u64) < min_row_size {
return Err(WlBufferError::StrideTooSmall);
}
let dmabuf_buffer_params = match udmabuf {
None => DmabufBufferParams {
size: bytes as usize,
udmabuf: None,
udmabuf_offset: 0,
udmabuf_size: 0,
udmabuf_impossible: !mem.pool().is_sealed_memfd(),
host_buffer: None,
host_buffer_impossible: !mem.pool().is_sealed_memfd(),
},
Some((udmabuf, size)) => DmabufBufferParams {
size,
udmabuf: Some(udmabuf.clone()),
udmabuf_offset: offset,
udmabuf_size: size,
udmabuf_impossible: false,
host_buffer: None,
host_buffer_impossible: false,
},
};
Ok(Self {
id,
destroyed: Cell::new(false),
@ -128,15 +149,7 @@ impl WlBuffer {
dmabuf: None,
render_ctx_version: Cell::new(client.state.render_ctx_version.get()),
storage: RefCell::new(Some(WlBufferStorage::Shm {
dmabuf_buffer_params: DmabufBufferParams {
size: bytes as usize,
udmabuf: None,
udmabuf_offset: 0,
udmabuf_size: 0,
udmabuf_impossible: !mem.pool().is_sealed_memfd(),
host_buffer: None,
host_buffer_impossible: !mem.pool().is_sealed_memfd(),
},
dmabuf_buffer_params,
mem,
stride,
})),
@ -191,9 +204,9 @@ impl WlBuffer {
};
let had_texture = match s {
WlBufferStorage::Shm {
mem,
dmabuf_buffer_params:
DmabufBufferParams {
udmabuf_impossible,
host_buffer,
host_buffer_impossible,
..
@ -201,7 +214,7 @@ impl WlBuffer {
..
} => {
host_buffer.take();
*host_buffer_impossible = !mem.pool().is_sealed_memfd();
*host_buffer_impossible = *udmabuf_impossible;
return match surface {
Some(s) => {
s.shm_staging.take();