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

View file

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

View file

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

View file

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

View file

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

View file

@ -22,7 +22,7 @@ use {
clonecell::{CloneCell, UnsafeCellCloneSafe},
copyhashmap::CopyHashMap,
},
video::dmabuf::DmaBuf,
video::dmabuf::{DmaBuf, PlaneVec},
wire::jay_screencast::Ready,
wire_dbus::{
org,
@ -86,7 +86,7 @@ pub struct StartedScreencast {
session: Rc<ScreencastSession>,
node: Rc<PwClientNode>,
port: Rc<PwClientNodePort>,
buffers: RefCell<Vec<DmaBuf>>,
buffers: RefCell<PlaneVec<DmaBuf>>,
dpy: Rc<PortalDisplay>,
jay_screencast: Rc<UsrJayScreencast>,
}
@ -276,7 +276,7 @@ impl ScreencastSession {
}
impl UsrJayScreencastOwner for StartedScreencast {
fn buffers(&self, buffers: Vec<DmaBuf>) {
fn buffers(&self, buffers: PlaneVec<DmaBuf>) {
if buffers.len() == 0 {
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)]
pub struct DmaBufPlane {
@ -12,6 +17,10 @@ pub struct DmaBuf {
pub width: i32,
pub height: i32,
pub format: &'static Format,
pub modifier: u64,
pub planes: Vec<DmaBufPlane>,
pub modifier: Modifier,
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,
utils::oserror::OsError,
video::{
dmabuf::{DmaBuf, DmaBufPlane},
dmabuf::{DmaBuf, DmaBufPlane, PlaneVec},
drm::{Drm, DrmError},
ModifiedFormat, INVALID_MODIFIER,
},
@ -161,7 +161,7 @@ unsafe fn export_bo(bo: *mut Bo) -> Result<DmaBuf, GbmError> {
}
},
planes: {
let mut planes = vec![];
let mut planes = PlaneVec::new();
for plane in 0..gbm_bo_get_plane_count(bo) {
let offset = gbm_bo_get_offset(bo, plane);
let stride = gbm_bo_get_stride_for_plane(bo, plane);

View file

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