wl-shm: add support for more formats
This commit is contained in:
parent
09a56edd47
commit
0570669af2
20 changed files with 114 additions and 81 deletions
|
|
@ -109,16 +109,13 @@ impl WlBuffer {
|
|||
format: &'static Format,
|
||||
mem: &Rc<ClientMem>,
|
||||
) -> Result<Self, WlBufferError> {
|
||||
let Some(shm_info) = &format.shm_info else {
|
||||
return Err(WlBufferError::UnsupportedShmFormat(format.name));
|
||||
};
|
||||
let bytes = stride as u64 * height as u64;
|
||||
let required = bytes + offset as u64;
|
||||
if required > mem.len() as u64 {
|
||||
return Err(WlBufferError::OutOfBounds);
|
||||
}
|
||||
let mem = Rc::new(mem.offset(offset));
|
||||
let min_row_size = width as u64 * shm_info.bpp as u64;
|
||||
let min_row_size = width as u64 * format.bpp as u64;
|
||||
if (stride as u64) < min_row_size {
|
||||
return Err(WlBufferError::StrideTooSmall);
|
||||
}
|
||||
|
|
@ -310,14 +307,15 @@ impl WlBuffer {
|
|||
}
|
||||
}
|
||||
};
|
||||
let hb = match ctx.create_dmabuf_buffer(&udmabuf, *udmabuf_offset, *udmabuf_size) {
|
||||
Ok(hb) => hb,
|
||||
Err(e) => {
|
||||
*host_buffer_impossible = true;
|
||||
log::debug!("Could not create gfx host buffer: {}", ErrorFmt(e));
|
||||
return Ok(None);
|
||||
}
|
||||
};
|
||||
let hb =
|
||||
match ctx.create_dmabuf_buffer(&udmabuf, *udmabuf_offset, *udmabuf_size, self.format) {
|
||||
Ok(hb) => hb,
|
||||
Err(e) => {
|
||||
*host_buffer_impossible = true;
|
||||
log::debug!("Could not create gfx host buffer: {}", ErrorFmt(e));
|
||||
return Ok(None);
|
||||
}
|
||||
};
|
||||
*host_buffer = Some(hb.clone());
|
||||
Ok(Some(hb))
|
||||
}
|
||||
|
|
@ -407,8 +405,6 @@ pub enum WlBufferError {
|
|||
GfxError(#[from] GfxError),
|
||||
#[error(transparent)]
|
||||
ClientError(Box<ClientError>),
|
||||
#[error("Buffer format {0} is not supported for shm buffers")]
|
||||
UnsupportedShmFormat(&'static str),
|
||||
}
|
||||
efrom!(WlBufferError, ClientMemError);
|
||||
efrom!(WlBufferError, ClientError);
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
use {
|
||||
crate::{
|
||||
client::{Client, ClientError},
|
||||
format::FORMATS,
|
||||
globals::{Global, GlobalName},
|
||||
ifs::wl_shm_pool::{WlShmPool, WlShmPoolError},
|
||||
leaks::Tracker,
|
||||
|
|
@ -44,12 +43,14 @@ impl WlShmGlobal {
|
|||
});
|
||||
track!(client, obj);
|
||||
client.add_client_obj(&obj)?;
|
||||
for format in FORMATS {
|
||||
if format.shm_info.is_some() {
|
||||
client.event(Format {
|
||||
self_id: id,
|
||||
format: format.wl_id.unwrap_or(format.drm),
|
||||
});
|
||||
if let Some(ctx) = client.state.render_ctx.get() {
|
||||
for format in ctx.formats().values() {
|
||||
if format.supports_shm {
|
||||
client.event(Format {
|
||||
self_id: id,
|
||||
format: format.format.wl_id.unwrap_or(format.format.drm),
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
|
|
|
|||
|
|
@ -53,10 +53,9 @@ impl WlShmPoolRequestHandler for WlShmPool {
|
|||
|
||||
fn create_buffer(&self, req: CreateBuffer, _slf: &Rc<Self>) -> Result<(), Self::Error> {
|
||||
let drm_format = map_wayland_format_id(req.format);
|
||||
let format = match formats().get(&drm_format) {
|
||||
Some(f) if f.shm_info.is_some() => *f,
|
||||
_ => return Err(WlShmPoolError::InvalidFormat(req.format)),
|
||||
};
|
||||
let format = formats()
|
||||
.get(&drm_format)
|
||||
.ok_or(WlShmPoolError::InvalidFormat(req.format))?;
|
||||
if req.height < 0 || req.width < 0 || req.stride < 0 || req.offset < 0 {
|
||||
return Err(WlShmPoolError::NegativeParameters);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue