1
0
Fork 0
forked from wry/wry

render: add support for more formats

This commit is contained in:
Julian Orth 2024-04-03 21:18:44 +02:00
parent 9d78231cac
commit 551dafcce8
13 changed files with 348 additions and 491 deletions

View file

@ -90,13 +90,16 @@ 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 = mem.offset(offset);
let min_row_size = width as u64 * format.bpp as u64;
let min_row_size = width as u64 * shm_info.bpp as u64;
if (stride as u64) < min_row_size {
return Err(WlBufferError::StrideTooSmall);
}
@ -270,6 +273,8 @@ pub enum WlBufferError {
MsgParserError(#[source] Box<MsgParserError>),
#[error(transparent)]
ClientError(Box<ClientError>),
#[error("Buffer format {0} is not supported for shm buffers")]
UnsupportedShmFormat(&'static str),
}
efrom!(WlBufferError, ClientMemError);
efrom!(WlBufferError, MsgParserError);

View file

@ -46,7 +46,7 @@ impl WlShmGlobal {
track!(client, obj);
client.add_client_obj(&obj)?;
for format in FORMATS {
if format.shm_supported {
if format.shm_info.is_some() {
client.event(Format {
self_id: id,
format: format.wl_id.unwrap_or(format.drm),

View file

@ -45,7 +45,7 @@ impl WlShmPool {
let req: CreateBuffer = self.client.parse(self, parser)?;
let drm_format = map_wayland_format_id(req.format);
let format = match formats().get(&drm_format) {
Some(f) if f.shm_supported => *f,
Some(f) if f.shm_info.is_some() => *f,
_ => return Err(WlShmPoolError::InvalidFormat(req.format)),
};
if req.height < 0 || req.width < 0 || req.stride < 0 || req.offset < 0 {