drm: add unique identifiers to dmabufs
This commit is contained in:
parent
3635ae0104
commit
fed2ceb8b5
17 changed files with 72 additions and 25 deletions
|
|
@ -1692,9 +1692,14 @@ impl MetalBackend {
|
|||
if cursor {
|
||||
usage |= GBM_BO_USE_LINEAR;
|
||||
};
|
||||
let dev_bo = dev
|
||||
.gbm
|
||||
.create_bo(width, height, format, &possible_modifiers, usage);
|
||||
let dev_bo = dev.gbm.create_bo(
|
||||
&self.state.dma_buf_ids,
|
||||
width,
|
||||
height,
|
||||
format,
|
||||
&possible_modifiers,
|
||||
usage,
|
||||
);
|
||||
let dev_bo = match dev_bo {
|
||||
Ok(b) => b,
|
||||
Err(e) => return Err(MetalError::ScanoutBuffer(e)),
|
||||
|
|
@ -1740,11 +1745,14 @@ impl MetalBackend {
|
|||
return Err(MetalError::MissingRenderModifier(format.name));
|
||||
}
|
||||
usage = GBM_BO_USE_RENDERING | GBM_BO_USE_LINEAR;
|
||||
let render_bo =
|
||||
render_ctx
|
||||
.gfx
|
||||
.gbm()
|
||||
.create_bo(width, height, format, &possible_modifiers, usage);
|
||||
let render_bo = render_ctx.gfx.gbm().create_bo(
|
||||
&self.state.dma_buf_ids,
|
||||
width,
|
||||
height,
|
||||
format,
|
||||
&possible_modifiers,
|
||||
usage,
|
||||
);
|
||||
let render_bo = match render_bo {
|
||||
Ok(b) => b,
|
||||
Err(e) => return Err(MetalError::ScanoutBuffer(e)),
|
||||
|
|
|
|||
|
|
@ -393,9 +393,14 @@ impl XBackend {
|
|||
panic!("Neither linear nor invalid modifier is supported");
|
||||
};
|
||||
for image in &mut images {
|
||||
let bo = self
|
||||
.gbm
|
||||
.create_bo(width, height, XRGB8888, modifier, usage)?;
|
||||
let bo = self.gbm.create_bo(
|
||||
&self.state.dma_buf_ids,
|
||||
width,
|
||||
height,
|
||||
XRGB8888,
|
||||
modifier,
|
||||
usage,
|
||||
)?;
|
||||
let dma = bo.dmabuf();
|
||||
assert!(dma.planes.len() == 1);
|
||||
let plane = dma.planes.first().unwrap();
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ use {
|
|||
tools::tool_client::{with_tool_client, Handle, ToolClient},
|
||||
utils::{errorfmt::ErrorFmt, queue::AsyncQueue},
|
||||
video::{
|
||||
dmabuf::{DmaBuf, DmaBufPlane, PlaneVec},
|
||||
dmabuf::{DmaBuf, DmaBufIds, DmaBufPlane, PlaneVec},
|
||||
drm::Drm,
|
||||
gbm::{GbmDevice, GBM_BO_USE_LINEAR, GBM_BO_USE_RENDERING},
|
||||
},
|
||||
|
|
@ -55,7 +55,7 @@ async fn run(screenshot: Rc<Screenshot>) {
|
|||
fatal!("Could not take a screenshot: {}", e);
|
||||
}
|
||||
};
|
||||
let data = buf_to_qoi(&buf);
|
||||
let data = buf_to_qoi(&DmaBufIds::default(), &buf);
|
||||
let filename = screenshot
|
||||
.args
|
||||
.filename
|
||||
|
|
@ -67,7 +67,7 @@ async fn run(screenshot: Rc<Screenshot>) {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn buf_to_qoi(buf: &Dmabuf) -> Vec<u8> {
|
||||
pub fn buf_to_qoi(dma_buf_ids: &DmaBufIds, buf: &Dmabuf) -> Vec<u8> {
|
||||
let drm = match Drm::reopen(buf.drm_dev.raw(), false) {
|
||||
Ok(drm) => drm,
|
||||
Err(e) => {
|
||||
|
|
@ -87,6 +87,7 @@ pub fn buf_to_qoi(buf: &Dmabuf) -> Vec<u8> {
|
|||
fd: buf.fd.clone(),
|
||||
});
|
||||
let dmabuf = DmaBuf {
|
||||
id: dma_buf_ids.next(),
|
||||
width: buf.width as _,
|
||||
height: buf.height as _,
|
||||
format: XRGB8888,
|
||||
|
|
|
|||
|
|
@ -201,6 +201,7 @@ fn start_compositor2(
|
|||
default_gfx_api: Cell::new(GfxApi::OpenGl),
|
||||
activation_tokens: Default::default(),
|
||||
toplevel_lists: Default::default(),
|
||||
dma_buf_ids: Default::default(),
|
||||
});
|
||||
state.tracker.register(ClientId::from_raw(0));
|
||||
create_dummy_output(&state);
|
||||
|
|
|
|||
|
|
@ -236,9 +236,14 @@ impl JayScreencast {
|
|||
}
|
||||
false => &format.write_modifiers,
|
||||
};
|
||||
let buffer =
|
||||
ctx.gbm()
|
||||
.create_bo(mode.width, mode.height, XRGB8888, modifiers, usage)?;
|
||||
let buffer = ctx.gbm().create_bo(
|
||||
&self.client.state.dma_buf_ids,
|
||||
mode.width,
|
||||
mode.height,
|
||||
XRGB8888,
|
||||
modifiers,
|
||||
usage,
|
||||
)?;
|
||||
let fb = ctx.clone().dmabuf_img(buffer.dmabuf())?.to_framebuffer()?;
|
||||
buffers.push(ScreencastBuffer {
|
||||
dmabuf: buffer.dmabuf().clone(),
|
||||
|
|
|
|||
|
|
@ -119,6 +119,7 @@ impl WlDrm {
|
|||
None => return Err(WlDrmError::InvalidFormat(req.format)),
|
||||
};
|
||||
let mut dmabuf = DmaBuf {
|
||||
id: self.client.state.dma_buf_ids.next(),
|
||||
width: req.width,
|
||||
height: req.height,
|
||||
format,
|
||||
|
|
|
|||
|
|
@ -114,6 +114,7 @@ impl ZwpLinuxBufferParamsV1 {
|
|||
return Err(ZwpLinuxBufferParamsV1Error::InvalidModifier(modifier));
|
||||
}
|
||||
let mut dmabuf = DmaBuf {
|
||||
id: self.parent.client.state.dma_buf_ids.next(),
|
||||
width,
|
||||
height,
|
||||
format: format.format,
|
||||
|
|
|
|||
|
|
@ -85,7 +85,7 @@ impl TestClient {
|
|||
|
||||
pub async fn take_screenshot(&self) -> Result<Vec<u8>, TestError> {
|
||||
let dmabuf = self.jc.take_screenshot().await?;
|
||||
let qoi = buf_to_qoi(&dmabuf);
|
||||
let qoi = buf_to_qoi(&self.server.state.dma_buf_ids, &dmabuf);
|
||||
Ok(qoi)
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -23,6 +23,7 @@ use {
|
|||
copyhashmap::CopyHashMap, errorfmt::ErrorFmt, numcell::NumCell,
|
||||
run_toplevel::RunToplevel, xrd::xrd,
|
||||
},
|
||||
video::dmabuf::DmaBufIds,
|
||||
wheel::Wheel,
|
||||
wire_dbus::org,
|
||||
},
|
||||
|
|
@ -84,6 +85,7 @@ async fn run_async(eng: Rc<AsyncEngine>, ring: Rc<IoUring>) {
|
|||
screencasts: Default::default(),
|
||||
next_id: NumCell::new(1),
|
||||
render_ctxs: Default::default(),
|
||||
dma_buf_ids: Default::default(),
|
||||
});
|
||||
let _root = {
|
||||
let obj = state
|
||||
|
|
@ -143,6 +145,7 @@ struct PortalState {
|
|||
screencasts: CopyHashMap<String, Rc<ScreencastSession>>,
|
||||
next_id: NumCell<u32>,
|
||||
render_ctxs: CopyHashMap<c::dev_t, Weak<PortalRenderCtx>>,
|
||||
dma_buf_ids: Rc<DmaBufIds>,
|
||||
}
|
||||
|
||||
impl PortalState {
|
||||
|
|
|
|||
|
|
@ -247,7 +247,16 @@ async fn maybe_add_display(state: &Rc<PortalState>, name: &str) {
|
|||
_ => return,
|
||||
};
|
||||
let path = format!("{}/{}", state.xrd, name);
|
||||
let con = match UsrCon::new(&state.ring, &state.wheel, &state.eng, &path, num).await {
|
||||
let con = match UsrCon::new(
|
||||
&state.ring,
|
||||
&state.wheel,
|
||||
&state.eng,
|
||||
&state.dma_buf_ids,
|
||||
&path,
|
||||
num,
|
||||
)
|
||||
.await
|
||||
{
|
||||
Ok(c) => c,
|
||||
Err(e) => {
|
||||
log::error!(
|
||||
|
|
|
|||
|
|
@ -710,6 +710,7 @@ impl WindowData {
|
|||
}
|
||||
for _ in 0..NUM_BUFFERS {
|
||||
let bo = match ctx.ctx.gbm().create_bo(
|
||||
&self.dpy.state.dma_buf_ids,
|
||||
width,
|
||||
height,
|
||||
ARGB8888,
|
||||
|
|
|
|||
|
|
@ -60,6 +60,7 @@ pub fn take_screenshot(state: &State) -> Result<Screenshot, ScreenshooterError>
|
|||
};
|
||||
let gbm = ctx.gbm();
|
||||
let bo = gbm.create_bo(
|
||||
&state.dma_buf_ids,
|
||||
extents.width(),
|
||||
extents.height(),
|
||||
XRGB8888,
|
||||
|
|
|
|||
|
|
@ -50,7 +50,7 @@ use {
|
|||
linkedlist::LinkedList, numcell::NumCell, queue::AsyncQueue, refcounted::RefCounted,
|
||||
run_toplevel::RunToplevel,
|
||||
},
|
||||
video::drm::Drm,
|
||||
video::{dmabuf::DmaBufIds, drm::Drm},
|
||||
wheel::Wheel,
|
||||
wire::{
|
||||
ExtForeignToplevelListV1Id, JayRenderCtxId, JaySeatEventsId, JayWorkspaceWatcherId,
|
||||
|
|
@ -142,6 +142,7 @@ pub struct State {
|
|||
pub activation_tokens: CopyHashMap<ActivationToken, ()>,
|
||||
pub toplevel_lists:
|
||||
CopyHashMap<(ClientId, ExtForeignToplevelListV1Id), Rc<ExtForeignToplevelListV1>>,
|
||||
pub dma_buf_ids: DmaBufIds,
|
||||
}
|
||||
|
||||
// impl Drop for State {
|
||||
|
|
|
|||
|
|
@ -5,15 +5,18 @@ use {
|
|||
uapi::{c::ioctl, OwnedFd, _IOW, _IOWR},
|
||||
};
|
||||
|
||||
#[derive(Clone)]
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct DmaBufPlane {
|
||||
pub offset: u32,
|
||||
pub stride: u32,
|
||||
pub fd: Rc<OwnedFd>,
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
linear_ids!(DmaBufIds, DmaBufId);
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct DmaBuf {
|
||||
pub id: DmaBufId,
|
||||
pub width: i32,
|
||||
pub height: i32,
|
||||
pub format: &'static Format,
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ use {
|
|||
format::{formats, Format},
|
||||
utils::oserror::OsError,
|
||||
video::{
|
||||
dmabuf::{DmaBuf, DmaBufPlane, PlaneVec},
|
||||
dmabuf::{DmaBuf, DmaBufIds, DmaBufPlane, PlaneVec},
|
||||
drm::{Drm, DrmError},
|
||||
Modifier, INVALID_MODIFIER,
|
||||
},
|
||||
|
|
@ -150,8 +150,9 @@ impl GbmBoMap {
|
|||
}
|
||||
}
|
||||
|
||||
unsafe fn export_bo(bo: *mut Bo) -> Result<DmaBuf, GbmError> {
|
||||
unsafe fn export_bo(dmabuf_ids: &DmaBufIds, bo: *mut Bo) -> Result<DmaBuf, GbmError> {
|
||||
Ok(DmaBuf {
|
||||
id: dmabuf_ids.next(),
|
||||
width: gbm_bo_get_width(bo) as _,
|
||||
height: gbm_bo_get_height(bo) as _,
|
||||
modifier: gbm_bo_get_modifier(bo),
|
||||
|
|
@ -199,6 +200,7 @@ impl GbmDevice {
|
|||
|
||||
pub fn create_bo<'a>(
|
||||
&self,
|
||||
dma_buf_ids: &DmaBufIds,
|
||||
width: i32,
|
||||
height: i32,
|
||||
format: &Format,
|
||||
|
|
@ -229,7 +231,7 @@ impl GbmDevice {
|
|||
return Err(GbmError::CreateBo(OsError::default()));
|
||||
}
|
||||
let bo = BoHolder { bo };
|
||||
let dma = export_bo(bo.bo)?;
|
||||
let dma = export_bo(dma_buf_ids, bo.bo)?;
|
||||
Ok(GbmBo { bo, dmabuf: dma })
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -20,6 +20,7 @@ use {
|
|||
oserror::OsError,
|
||||
vec_ext::VecExt,
|
||||
},
|
||||
video::dmabuf::DmaBufIds,
|
||||
wheel::Wheel,
|
||||
wire::wl_display,
|
||||
wl_usr::{
|
||||
|
|
@ -77,6 +78,7 @@ pub struct UsrCon {
|
|||
outgoing: Cell<Option<SpawnedFuture<()>>>,
|
||||
pub owner: CloneCell<Option<Rc<dyn UsrConOwner>>>,
|
||||
dead: Cell<bool>,
|
||||
dma_buf_ids: Rc<DmaBufIds>,
|
||||
}
|
||||
|
||||
pub trait UsrConOwner {
|
||||
|
|
@ -88,6 +90,7 @@ impl UsrCon {
|
|||
ring: &Rc<IoUring>,
|
||||
wheel: &Rc<Wheel>,
|
||||
eng: &Rc<AsyncEngine>,
|
||||
dma_buf_ids: &Rc<DmaBufIds>,
|
||||
path: &str,
|
||||
server_id: u32,
|
||||
) -> Result<Rc<Self>, UsrConError> {
|
||||
|
|
@ -122,6 +125,7 @@ impl UsrCon {
|
|||
outgoing: Default::default(),
|
||||
owner: Default::default(),
|
||||
dead: Cell::new(false),
|
||||
dma_buf_ids: dma_buf_ids.clone(),
|
||||
});
|
||||
slf.objects.set(
|
||||
WL_DISPLAY_ID.into(),
|
||||
|
|
|
|||
|
|
@ -123,6 +123,7 @@ impl UsrJayScreencast {
|
|||
_ => return Err(UsrJayScreencastError::UnknownFormat(ev.format)),
|
||||
};
|
||||
self.pending_buffers.borrow_mut().push(DmaBuf {
|
||||
id: self.con.dma_buf_ids.next(),
|
||||
width: ev.width,
|
||||
height: ev.height,
|
||||
format,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue