1
0
Fork 0
forked from wry/wry

video: always use correct modifiers

This commit is contained in:
Julian Orth 2023-11-04 14:06:18 +01:00
parent 283774ae4c
commit bf90204db6
17 changed files with 196 additions and 55 deletions

View file

@ -7,6 +7,7 @@ use {
video::{
drm::DrmError,
gbm::{GbmBo, GbmError, GBM_BO_USE_LINEAR, GBM_BO_USE_RENDERING},
INVALID_MODIFIER, LINEAR_MODIFIER,
},
},
std::{ops::Deref, rc::Rc},
@ -26,6 +27,10 @@ pub enum ScreenshooterError {
RenderError(#[from] GfxError),
#[error(transparent)]
DrmError(#[from] DrmError),
#[error("Render context does not support XRGB8888")]
XRGB8888,
#[error("Render context supports neither linear nor invalid modifier for XRGB8888 rendering")]
Linear,
}
pub struct Screenshot {
@ -42,13 +47,24 @@ pub fn take_screenshot(state: &State) -> Result<Screenshot, ScreenshooterError>
if extents.is_empty() {
return Err(ScreenshooterError::EmptyDisplay);
}
let formats = ctx.formats();
let mut usage = GBM_BO_USE_RENDERING;
let modifiers = match formats.get(&XRGB8888.drm) {
None => return Err(ScreenshooterError::XRGB8888),
Some(f) if f.write_modifiers.contains(&LINEAR_MODIFIER) => &[LINEAR_MODIFIER],
Some(f) if f.write_modifiers.contains(&INVALID_MODIFIER) => {
usage |= GBM_BO_USE_LINEAR;
&[INVALID_MODIFIER]
}
Some(_) => return Err(ScreenshooterError::Linear),
};
let gbm = ctx.gbm();
let bo = gbm.create_bo(
extents.width(),
extents.height(),
XRGB8888,
&[],
GBM_BO_USE_RENDERING | GBM_BO_USE_LINEAR,
modifiers,
usage,
)?;
let fb = ctx.clone().dmabuf_fb(bo.dmabuf())?;
fb.render_node(