1
0
Fork 0
forked from wry/wry

dmabuf: cache is_disjoint property

This commit is contained in:
Julian Orth 2025-10-01 23:30:49 +02:00
parent f00202f149
commit 0884a5c656
9 changed files with 27 additions and 14 deletions

View file

@ -69,6 +69,7 @@ async fn run(screenshot: Rc<Screenshot>) {
format: XRGB8888,
modifier: ev.modifier,
planes,
is_disjoint: Default::default(),
};
res.push(Ok((buf, Some(ev.drm_dev))));
});
@ -96,6 +97,7 @@ async fn run(screenshot: Rc<Screenshot>) {
format: XRGB8888,
modifier: ev.modifier,
planes: planes.take(),
is_disjoint: Default::default(),
};
res.push(Ok((buf, dev.take())))
},

View file

@ -230,6 +230,7 @@ impl VulkanBoAllocator {
format: format.format,
modifier: modifier.modifier,
planes,
is_disjoint: Default::default(),
};
unsafe {
let cmd = data.command_buffer.buffer;

View file

@ -142,6 +142,7 @@ impl WlDrmRequestHandler for WlDrm {
format,
modifier: INVALID_MODIFIER,
planes: PlaneVec::new(),
is_disjoint: Default::default(),
};
if req.stride0 > 0 {
dmabuf.planes.push(DmaBufPlane {

View file

@ -93,6 +93,7 @@ impl ZwpLinuxBufferParamsV1 {
format: format.format,
modifier,
planes: PlaneVec::new(),
is_disjoint: Default::default(),
};
let mut planes: Vec<_> = self.planes.borrow_mut().drain_values().collect();
planes.sort_by_key(|a| a.plane_idx);

View file

@ -38,6 +38,7 @@ impl TestJayScreenshot {
format: XRGB8888,
modifier: ev.modifier,
planes,
is_disjoint: Default::default(),
})));
Ok(())
}
@ -73,6 +74,7 @@ impl TestJayScreenshot {
format: XRGB8888,
modifier: ev.modifier,
planes: self.planes.take(),
is_disjoint: Default::default(),
})));
Ok(())
}

View file

@ -162,6 +162,7 @@ impl Allocator for Udmabuf {
format,
modifier: LINEAR_MODIFIER,
planes,
is_disjoint: Default::default(),
};
Ok(Rc::new(UdmabufBo {
buf: dmabuf,

View file

@ -5,7 +5,7 @@ use {
video::{LINEAR_MODIFIER, Modifier},
},
arrayvec::ArrayVec,
std::{rc::Rc, sync::OnceLock},
std::{cell::OnceCell, rc::Rc, sync::OnceLock},
uapi::{
_IOW, _IOWR, OwnedFd,
c::{self, dev_t, ioctl},
@ -30,6 +30,7 @@ pub struct DmaBuf {
pub format: &'static Format,
pub modifier: Modifier,
pub planes: PlaneVec<DmaBufPlane>,
pub is_disjoint: OnceCell<bool>,
}
pub const MAX_PLANES: usize = 4;
@ -38,23 +39,25 @@ pub type PlaneVec<T> = ArrayVec<T, MAX_PLANES>;
impl DmaBuf {
pub fn is_disjoint(&self) -> bool {
if self.planes.len() <= 1 {
return false;
}
let stat = match uapi::fstat(self.planes[0].fd.raw()) {
Ok(s) => s,
_ => return true,
};
for plane in &self.planes[1..] {
let stat2 = match uapi::fstat(plane.fd.raw()) {
*self.is_disjoint.get_or_init(|| {
if self.planes.len() <= 1 {
return false;
}
let stat = match uapi::fstat(self.planes[0].fd.raw()) {
Ok(s) => s,
_ => return true,
};
if stat2.st_ino != stat.st_ino {
return true;
for plane in &self.planes[1..] {
let stat2 = match uapi::fstat(plane.fd.raw()) {
Ok(s) => s,
_ => return true,
};
if stat2.st_ino != stat.st_ino {
return true;
}
}
}
false
false
})
}
pub fn udmabuf_size(&self) -> Option<usize> {

View file

@ -202,6 +202,7 @@ unsafe fn export_bo(dmabuf_ids: &DmaBufIds, bo: *mut Bo) -> Result<DmaBuf, GbmEr
}
planes
},
is_disjoint: Default::default(),
})
}
}

View file

@ -155,6 +155,7 @@ impl JayScreencastEventHandler for UsrJayScreencast {
format,
modifier: ev.modifier,
planes: mem::take(self.pending_planes.borrow_mut().deref_mut()),
is_disjoint: Default::default(),
});
Ok(())
}