From 467d1fbc7f1892d622415955186b7654b05fa259 Mon Sep 17 00:00:00 2001 From: Netflate Date: Wed, 30 Sep 2026 04:32:30 +0100 Subject: [PATCH] image-copy: Prioritize ARGB/XRGB dmabuf formats Co-authored-by: back-design <271796486+back-design@users.noreply.github.com> --- .../handlers/image_copy_capture/mod.rs | 37 +++++++++++-------- 1 file changed, 21 insertions(+), 16 deletions(-) diff --git a/src/wayland/handlers/image_copy_capture/mod.rs b/src/wayland/handlers/image_copy_capture/mod.rs index 81f3a671..57ef9500 100644 --- a/src/wayland/handlers/image_copy_capture/mod.rs +++ b/src/wayland/handlers/image_copy_capture/mod.rs @@ -454,23 +454,28 @@ fn constraints_for_renderer( .ok() .and_then(|device| device.try_get_render_node().ok().flatten()) { - constraints.dma = Some(DmabufConstraints { - node, - formats: renderer - .egl_context() - .dmabuf_render_formats() - .iter() - .fold( - IndexMap::>::new(), - |mut map, format| { - map.entry(format.code).or_default().push(format.modifier); - map - }, - ) - .into_iter() - .collect::>(), - }); + let mut formats = renderer + .egl_context() + .dmabuf_render_formats() + .iter() + .fold( + IndexMap::>::new(), + |mut map, format| { + map.entry(format.code).or_default().push(format.modifier); + map + }, + ) + .into_iter() + .collect::>(); + formats.sort_by_key(|(code, _)| !is_preferred_capture_format(*code)); + constraints.dma = Some(DmabufConstraints { node, formats }); } constraints } + +/// Formats most screencast consumers handle natively, offered first. WebRTC, for +/// example, swaps RGBA frames to BGRA on the CPU for every captured frame. +fn is_preferred_capture_format(code: Fourcc) -> bool { + matches!(code, Fourcc::Argb8888 | Fourcc::Xrgb8888) +}