1
0
Fork 0
forked from wry/wry

x: use modifier-aware buffer import

This commit is contained in:
Julian Orth 2024-02-19 18:35:45 +01:00
parent 0d296de53f
commit a02815253a
2 changed files with 45 additions and 22 deletions

View file

@ -19,12 +19,11 @@ use {
}, },
video::{ video::{
drm::{ConnectorType, Drm, DrmError, DrmVersion}, drm::{ConnectorType, Drm, DrmError, DrmVersion},
gbm::{GbmDevice, GbmError, GBM_BO_USE_LINEAR, GBM_BO_USE_RENDERING}, gbm::{GbmDevice, GbmError, GBM_BO_USE_RENDERING},
INVALID_MODIFIER, LINEAR_MODIFIER,
}, },
wire_xcon::{ wire_xcon::{
ChangeProperty, ChangeWindowAttributes, ConfigureNotify, CreateCursor, CreatePixmap, ChangeProperty, ChangeWindowAttributes, ConfigureNotify, CreateCursor, CreatePixmap,
CreateWindow, CreateWindowValues, DestroyNotify, Dri3Open, Dri3PixmapFromBuffer, CreateWindow, CreateWindowValues, DestroyNotify, Dri3Open, Dri3PixmapFromBuffers,
Dri3QueryVersion, Extension, FreePixmap, MapWindow, PresentCompleteNotify, Dri3QueryVersion, Extension, FreePixmap, MapWindow, PresentCompleteNotify,
PresentIdleNotify, PresentPixmap, PresentQueryVersion, PresentSelectInput, PresentIdleNotify, PresentPixmap, PresentQueryVersion, PresentSelectInput,
XiButtonPress, XiButtonRelease, XiDeviceInfo, XiEnter, XiEventMask, XiButtonPress, XiButtonRelease, XiDeviceInfo, XiEnter, XiEventMask,
@ -383,28 +382,16 @@ impl XBackend {
Some(f) => f, Some(f) => f,
None => return Err(XBackendError::XRGB8888), None => return Err(XBackendError::XRGB8888),
}; };
let mut usage = GBM_BO_USE_RENDERING;
let modifier = if format.write_modifiers.contains(&LINEAR_MODIFIER) {
&[LINEAR_MODIFIER]
} else if format.write_modifiers.contains(&INVALID_MODIFIER) {
usage |= GBM_BO_USE_LINEAR;
&[INVALID_MODIFIER]
} else {
panic!("Neither linear nor invalid modifier is supported");
};
for image in &mut images { for image in &mut images {
let bo = self.gbm.create_bo( let bo = self.gbm.create_bo(
&self.state.dma_buf_ids, &self.state.dma_buf_ids,
width, width,
height, height,
XRGB8888, XRGB8888,
modifier, &format.write_modifiers,
usage, GBM_BO_USE_RENDERING,
)?; )?;
let dma = bo.dmabuf(); let dma = bo.dmabuf();
assert!(dma.planes.len() == 1);
let plane = dma.planes.first().unwrap();
let size = plane.stride * dma.height as u32;
let img = match self.ctx.clone().dmabuf_img(dma) { let img = match self.ctx.clone().dmabuf_img(dma) {
Ok(f) => f, Ok(f) => f,
Err(e) => return Err(XBackendError::CreateImage(e)), Err(e) => return Err(XBackendError::CreateImage(e)),
@ -417,17 +404,31 @@ impl XBackend {
Ok(f) => f, Ok(f) => f,
Err(e) => return Err(XBackendError::CreateTexture(e)), Err(e) => return Err(XBackendError::CreateTexture(e)),
}; };
macro_rules! pp {
($num:expr, $field:ident) => {
dma.planes.get($num).map(|p| p.$field).unwrap_or(0) as _
};
}
let buffers: Vec<_> = dma.planes.iter().map(|p| p.fd.clone()).collect();
let pixmap = { let pixmap = {
let pfb = Dri3PixmapFromBuffer { let pfb = Dri3PixmapFromBuffers {
pixmap: self.c.generate_id()?, pixmap: self.c.generate_id()?,
drawable: window, window,
size, num_buffers: dma.planes.len() as _,
width: dma.width as _, width: dma.width as _,
height: dma.height as _, height: dma.height as _,
stride: plane.stride as _, stride0: pp!(0, stride),
offset0: pp!(0, offset),
stride1: pp!(1, stride),
offset1: pp!(1, offset),
stride2: pp!(2, stride),
offset2: pp!(2, offset),
stride3: pp!(3, stride),
offset3: pp!(3, offset),
depth: 24, depth: 24,
bpp: 32, bpp: 32,
pixmap_fd: plane.fd.clone(), modifier: dma.modifier,
buffers: buffers.into(),
}; };
if let Err(e) = self.c.call(&pfb).await { if let Err(e) = self.c.call(&pfb).await {
return Err(XBackendError::ImportBuffer(e)); return Err(XBackendError::ImportBuffer(e));

View file

@ -29,3 +29,25 @@ request Dri3PixmapFromBuffer = 2 (
bpp: u8, bpp: u8,
pixmap_fd: fd, pixmap_fd: fd,
); );
request Dri3PixmapFromBuffers = 7 (
pixmap: u32,
window: u32,
num_buffers: u8,
@pad 3,
width: u16,
height: u16,
stride0: u32,
offset0: u32,
stride1: u32,
offset1: u32,
stride2: u32,
offset2: u32,
stride3: u32,
offset3: u32,
depth: u8,
bpp: u8,
@pad 2,
modifier: u64,
buffers: list(fd, field(num_buffers)),
);