1
0
Fork 0
forked from wry/wry

dmabuf: add PlaneVec

This commit is contained in:
Julian Orth 2023-10-23 20:41:33 +02:00
parent 3e4bed66b0
commit d022d96fbf
9 changed files with 42 additions and 23 deletions

7
Cargo.lock generated
View file

@ -114,6 +114,12 @@ version = "1.0.75"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a4668cab20f66d8d020e1fbc0ebe47217433c1b6c8f2040faf858554e394ace6" checksum = "a4668cab20f66d8d020e1fbc0ebe47217433c1b6c8f2040faf858554e394ace6"
[[package]]
name = "arrayvec"
version = "0.7.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "96d30a06541fbafbc7f82ed10c06164cfbd2c401138f6addd8404629c4b16711"
[[package]] [[package]]
name = "autocfg" name = "autocfg"
version = "1.1.0" version = "1.1.0"
@ -428,6 +434,7 @@ dependencies = [
"ahash", "ahash",
"algorithms", "algorithms",
"anyhow", "anyhow",
"arrayvec",
"backtrace", "backtrace",
"bincode", "bincode",
"bitflags 2.4.1", "bitflags 2.4.1",

View file

@ -41,6 +41,7 @@ dirs = "5.0.1"
backtrace = "0.3.64" backtrace = "0.3.64"
chrono = "0.4.19" chrono = "0.4.19"
parking_lot = "0.12.1" parking_lot = "0.12.1"
arrayvec = "0.7.4"
[build-dependencies] [build-dependencies]
repc = "0.1.1" repc = "0.1.1"

View file

@ -5,7 +5,7 @@ use {
tools::tool_client::{with_tool_client, Handle, ToolClient}, tools::tool_client::{with_tool_client, Handle, ToolClient},
utils::{errorfmt::ErrorFmt, queue::AsyncQueue}, utils::{errorfmt::ErrorFmt, queue::AsyncQueue},
video::{ video::{
dmabuf::{DmaBuf, DmaBufPlane}, dmabuf::{DmaBuf, DmaBufPlane, PlaneVec},
drm::Drm, drm::Drm,
gbm::{GbmDevice, GBM_BO_USE_LINEAR, GBM_BO_USE_RENDERING}, gbm::{GbmDevice, GBM_BO_USE_LINEAR, GBM_BO_USE_RENDERING},
INVALID_MODIFIER, INVALID_MODIFIER,
@ -81,16 +81,18 @@ pub fn buf_to_qoi(buf: &Dmabuf) -> Vec<u8> {
fatal!("Could not create a gbm device: {}", ErrorFmt(e)); fatal!("Could not create a gbm device: {}", ErrorFmt(e));
} }
}; };
let mut planes = PlaneVec::new();
planes.push(DmaBufPlane {
offset: buf.offset,
stride: buf.stride,
fd: buf.fd.clone(),
});
let dmabuf = DmaBuf { let dmabuf = DmaBuf {
width: buf.width as _, width: buf.width as _,
height: buf.height as _, height: buf.height as _,
format: XRGB8888, format: XRGB8888,
modifier: INVALID_MODIFIER, modifier: INVALID_MODIFIER,
planes: vec![DmaBufPlane { planes,
offset: buf.offset,
stride: buf.stride,
fd: buf.fd.clone(),
}],
}; };
let bo = match gbm.import_dmabuf(&dmabuf, GBM_BO_USE_LINEAR | GBM_BO_USE_RENDERING) { let bo = match gbm.import_dmabuf(&dmabuf, GBM_BO_USE_LINEAR | GBM_BO_USE_RENDERING) {
Ok(bo) => Rc::new(bo), Ok(bo) => Rc::new(bo),

View file

@ -8,7 +8,7 @@ use {
object::Object, object::Object,
utils::buffd::{MsgParser, MsgParserError}, utils::buffd::{MsgParser, MsgParserError},
video::{ video::{
dmabuf::{DmaBuf, DmaBufPlane}, dmabuf::{DmaBuf, DmaBufPlane, PlaneVec},
INVALID_MODIFIER, INVALID_MODIFIER,
}, },
wire::{wl_drm::*, WlDrmId}, wire::{wl_drm::*, WlDrmId},
@ -123,7 +123,7 @@ impl WlDrm {
height: req.height, height: req.height,
format, format,
modifier: INVALID_MODIFIER, modifier: INVALID_MODIFIER,
planes: vec![], planes: PlaneVec::new(),
}; };
if req.stride0 > 0 { if req.stride0 > 0 {
dmabuf.planes.push(DmaBufPlane { dmabuf.planes.push(DmaBufPlane {

View file

@ -9,7 +9,7 @@ use {
buffd::{MsgParser, MsgParserError}, buffd::{MsgParser, MsgParserError},
errorfmt::ErrorFmt, errorfmt::ErrorFmt,
}, },
video::dmabuf::{DmaBuf, DmaBufPlane}, video::dmabuf::{DmaBuf, DmaBufPlane, PlaneVec, MAX_PLANES},
wire::{zwp_linux_buffer_params_v1::*, WlBufferId, ZwpLinuxBufferParamsV1Id}, wire::{zwp_linux_buffer_params_v1::*, WlBufferId, ZwpLinuxBufferParamsV1Id},
}, },
ahash::AHashMap, ahash::AHashMap,
@ -27,7 +27,7 @@ const INTERLACED: u32 = 2;
#[allow(dead_code)] #[allow(dead_code)]
const BOTTOM_FIRST: u32 = 4; const BOTTOM_FIRST: u32 = 4;
const MAX_PLANE: u32 = 3; const MAX_PLANE: u32 = MAX_PLANES as u32 - 1;
pub struct ZwpLinuxBufferParamsV1 { pub struct ZwpLinuxBufferParamsV1 {
pub id: ZwpLinuxBufferParamsV1Id, pub id: ZwpLinuxBufferParamsV1Id,
@ -118,7 +118,7 @@ impl ZwpLinuxBufferParamsV1 {
height, height,
format: format.format, format: format.format,
modifier, modifier,
planes: vec![], planes: PlaneVec::new(),
}; };
let mut planes: Vec<_> = self.planes.borrow_mut().drain().map(|v| v.1).collect(); let mut planes: Vec<_> = self.planes.borrow_mut().drain().map(|v| v.1).collect();
planes.sort_by_key(|a| a.plane_idx); planes.sort_by_key(|a| a.plane_idx);

View file

@ -22,7 +22,7 @@ use {
clonecell::{CloneCell, UnsafeCellCloneSafe}, clonecell::{CloneCell, UnsafeCellCloneSafe},
copyhashmap::CopyHashMap, copyhashmap::CopyHashMap,
}, },
video::dmabuf::DmaBuf, video::dmabuf::{DmaBuf, PlaneVec},
wire::jay_screencast::Ready, wire::jay_screencast::Ready,
wire_dbus::{ wire_dbus::{
org, org,
@ -86,7 +86,7 @@ pub struct StartedScreencast {
session: Rc<ScreencastSession>, session: Rc<ScreencastSession>,
node: Rc<PwClientNode>, node: Rc<PwClientNode>,
port: Rc<PwClientNodePort>, port: Rc<PwClientNodePort>,
buffers: RefCell<Vec<DmaBuf>>, buffers: RefCell<PlaneVec<DmaBuf>>,
dpy: Rc<PortalDisplay>, dpy: Rc<PortalDisplay>,
jay_screencast: Rc<UsrJayScreencast>, jay_screencast: Rc<UsrJayScreencast>,
} }
@ -276,7 +276,7 @@ impl ScreencastSession {
} }
impl UsrJayScreencastOwner for StartedScreencast { impl UsrJayScreencastOwner for StartedScreencast {
fn buffers(&self, buffers: Vec<DmaBuf>) { fn buffers(&self, buffers: PlaneVec<DmaBuf>) {
if buffers.len() == 0 { if buffers.len() == 0 {
return; return;
} }

View file

@ -1,4 +1,9 @@
use {crate::format::Format, std::rc::Rc, uapi::OwnedFd}; use {
crate::{format::Format, video::Modifier},
arrayvec::ArrayVec,
std::rc::Rc,
uapi::OwnedFd,
};
#[derive(Clone)] #[derive(Clone)]
pub struct DmaBufPlane { pub struct DmaBufPlane {
@ -12,6 +17,10 @@ pub struct DmaBuf {
pub width: i32, pub width: i32,
pub height: i32, pub height: i32,
pub format: &'static Format, pub format: &'static Format,
pub modifier: u64, pub modifier: Modifier,
pub planes: Vec<DmaBufPlane>, pub planes: PlaneVec<DmaBufPlane>,
} }
pub const MAX_PLANES: usize = 4;
pub type PlaneVec<T> = ArrayVec<T, MAX_PLANES>;

View file

@ -5,7 +5,7 @@ use {
format::formats, format::formats,
utils::oserror::OsError, utils::oserror::OsError,
video::{ video::{
dmabuf::{DmaBuf, DmaBufPlane}, dmabuf::{DmaBuf, DmaBufPlane, PlaneVec},
drm::{Drm, DrmError}, drm::{Drm, DrmError},
ModifiedFormat, INVALID_MODIFIER, ModifiedFormat, INVALID_MODIFIER,
}, },
@ -161,7 +161,7 @@ unsafe fn export_bo(bo: *mut Bo) -> Result<DmaBuf, GbmError> {
} }
}, },
planes: { planes: {
let mut planes = vec![]; let mut planes = PlaneVec::new();
for plane in 0..gbm_bo_get_plane_count(bo) { for plane in 0..gbm_bo_get_plane_count(bo) {
let offset = gbm_bo_get_offset(bo, plane); let offset = gbm_bo_get_offset(bo, plane);
let stride = gbm_bo_get_stride_for_plane(bo, plane); let stride = gbm_bo_get_stride_for_plane(bo, plane);

View file

@ -6,7 +6,7 @@ use {
buffd::{MsgParser, MsgParserError}, buffd::{MsgParser, MsgParserError},
clonecell::CloneCell, clonecell::CloneCell,
}, },
video::dmabuf::{DmaBuf, DmaBufPlane}, video::dmabuf::{DmaBuf, DmaBufPlane, PlaneVec},
wire::{jay_screencast::*, JayScreencastId}, wire::{jay_screencast::*, JayScreencastId},
wl_usr::{usr_ifs::usr_jay_output::UsrJayOutput, usr_object::UsrObject, UsrCon}, wl_usr::{usr_ifs::usr_jay_output::UsrJayOutput, usr_object::UsrObject, UsrCon},
}, },
@ -19,8 +19,8 @@ pub struct UsrJayScreencast {
pub con: Rc<UsrCon>, pub con: Rc<UsrCon>,
pub owner: CloneCell<Option<Rc<dyn UsrJayScreencastOwner>>>, pub owner: CloneCell<Option<Rc<dyn UsrJayScreencastOwner>>>,
pub pending_buffers: RefCell<Vec<DmaBuf>>, pub pending_buffers: RefCell<PlaneVec<DmaBuf>>,
pub pending_planes: RefCell<Vec<DmaBufPlane>>, pub pending_planes: RefCell<PlaneVec<DmaBufPlane>>,
pub pending_config: RefCell<UsrJayScreencastServerConfig>, pub pending_config: RefCell<UsrJayScreencastServerConfig>,
} }
@ -35,7 +35,7 @@ pub struct UsrJayScreencastServerConfig {
} }
pub trait UsrJayScreencastOwner { pub trait UsrJayScreencastOwner {
fn buffers(&self, buffers: Vec<DmaBuf>) { fn buffers(&self, buffers: PlaneVec<DmaBuf>) {
let _ = buffers; let _ = buffers;
} }