Skip to content

Commit

Permalink
it: don't require linear modifier for screenshots
Browse files Browse the repository at this point in the history
  • Loading branch information
mahkoh committed Jul 28, 2024
1 parent 0e98890 commit 1520232
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 16 deletions.
4 changes: 2 additions & 2 deletions src/cli/screenshot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use {
video::{
dmabuf::{DmaBuf, DmaBufIds, DmaBufPlane, PlaneVec},
drm::Drm,
gbm::{GbmDevice, GBM_BO_USE_LINEAR, GBM_BO_USE_RENDERING},
gbm::GbmDevice,
},
wire::{
jay_compositor::TakeScreenshot,
Expand Down Expand Up @@ -137,7 +137,7 @@ pub fn buf_to_bytes(dev: &Rc<OwnedFd>, buf: &DmaBuf, format: ScreenshotFormat) -
fatal!("Could not create a gbm device: {}", ErrorFmt(e));
}
};
let bo = match gbm.import_dmabuf(&buf, GBM_BO_USE_LINEAR | GBM_BO_USE_RENDERING) {
let bo = match gbm.import_dmabuf(&buf, 0) {
Ok(bo) => Rc::new(bo),
Err(e) => {
fatal!("Could not import screenshot dmabuf: {}", ErrorFmt(e));
Expand Down
4 changes: 2 additions & 2 deletions src/it/test_gfx_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use {
dmabuf::DmaBuf,
drm::{sync_obj::SyncObjCtx, Drm, DrmError},
gbm::{GbmBo, GbmDevice, GbmError},
LINEAR_MODIFIER,
INVALID_MODIFIER,
},
},
ahash::AHashMap,
Expand Down Expand Up @@ -65,7 +65,7 @@ impl TestGfxCtx {
let gbm = GbmDevice::new(drm).map_err(TestGfxError::CreateGbmDevice)?;
let ctx = Rc::new(SyncObjCtx::new(drm.fd()));
let mut modifiers = IndexSet::new();
modifiers.insert(LINEAR_MODIFIER);
modifiers.insert(INVALID_MODIFIER);
let mut formats = AHashMap::new();
for f in [XRGB8888, ARGB8888] {
formats.insert(
Expand Down
20 changes: 8 additions & 12 deletions src/screenshoter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@ use {
state::State,
video::{
drm::DrmError,
gbm::{GbmBo, GbmError, GBM_BO_USE_LINEAR, GBM_BO_USE_RENDERING},
INVALID_MODIFIER, LINEAR_MODIFIER,
gbm::{GbmBo, GbmError, GBM_BO_USE_RENDERING},
},
},
jay_config::video::Transform,
Expand All @@ -30,8 +29,8 @@ pub enum ScreenshooterError {
DrmError(#[from] DrmError),
#[error("Render context does not support XRGB8888")]
XRGB8888,
#[error("Render context supports neither linear nor invalid modifier for XRGB8888 rendering")]
Linear,
#[error("Render context cannot render to XRGB8888")]
NoModifiers,
}

pub struct Screenshot {
Expand All @@ -52,24 +51,21 @@ pub fn take_screenshot(
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),
Some(f) => &f.write_modifiers,
};
if modifiers.is_empty() {
return Err(ScreenshooterError::NoModifiers);
}
let gbm = ctx.gbm();
let bo = gbm.create_bo(
&state.dma_buf_ids,
extents.width(),
extents.height(),
XRGB8888,
modifiers,
usage,
GBM_BO_USE_RENDERING,
)?;
let fb = ctx.clone().dmabuf_fb(bo.dmabuf())?;
fb.render_node(
Expand Down

0 comments on commit 1520232

Please sign in to comment.