Skip to content

Commit

Permalink
WIP linux-dmabuf vesion 6 (target device)
Browse files Browse the repository at this point in the history
  • Loading branch information
ids1024 committed Jan 8, 2024
1 parent f6a33e4 commit 39591cd
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 8 deletions.
9 changes: 9 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -135,3 +135,12 @@ harness = false
[profile.release-with-debug]
inherits = "release"
debug = true

[patch.crates-io]
wayland-protocols = { git = "https://github.com/ids1024/wayland-rs", branch = "dmabuf-v6-wip" }
wayland-server = { git = "https://github.com/ids1024/wayland-rs", branch = "dmabuf-v6-wip" }
wayland-backend = { git = "https://github.com/ids1024/wayland-rs", branch = "dmabuf-v6-wip" }
wayland-sys = { git = "https://github.com/ids1024/wayland-rs", branch = "dmabuf-v6-wip" }
wayland-scanner = { git = "https://github.com/ids1024/wayland-rs", branch = "dmabuf-v6-wip" }
wayland-cursor = { git = "https://github.com/ids1024/wayland-rs", branch = "dmabuf-v6-wip" }
wayland-client = { git = "https://github.com/ids1024/wayland-rs", branch = "dmabuf-v6-wip" }
10 changes: 9 additions & 1 deletion src/backend/allocator/dmabuf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ pub(crate) struct DmabufInternal {
///
/// This is a bitflag, to be compared with the `Flags` enum re-exported by this module.
pub flags: DmabufFlags,

pub target_device: Option<libc::dev_t>,
}

#[derive(Debug)]
Expand Down Expand Up @@ -177,7 +179,7 @@ impl Dmabuf {
// The contents are determined by the provided file descriptors, which
// do not need to refer to the same buffer `src` does.
pub fn builder_from_buffer(src: &impl Buffer, flags: DmabufFlags) -> DmabufBuilder {
Self::builder(src.size(), src.format().code, src.format().modifier, flags)
Self::builder(src.size(), src.format().code, src.format().modifier, flags, None)
}

/// Create a new Dmabuf builder
Expand All @@ -186,6 +188,7 @@ impl Dmabuf {
format: Fourcc,
modifier: Modifier,
flags: DmabufFlags,
target_device: Option<libc::dev_t>,
) -> DmabufBuilder {
DmabufBuilder {
internal: DmabufInternal {
Expand All @@ -194,6 +197,7 @@ impl Dmabuf {
format,
modifier,
flags,
target_device,
},
}
}
Expand Down Expand Up @@ -228,6 +232,10 @@ impl Dmabuf {
self.0.flags.contains(DmabufFlags::Y_INVERT)
}

pub fn target_device(&self) -> Option<libc::dev_t> {
self.0.target_device
}

/// Create a weak reference to this dmabuf
pub fn weak(&self) -> WeakDmabuf {
WeakDmabuf(Arc::downgrade(&self.0))
Expand Down
1 change: 1 addition & 0 deletions src/backend/allocator/dumb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ impl AsDmabuf for DumbBuffer {
self.format.code,
self.format.modifier,
DmabufFlags::empty(),
None,
);
builder.add_plane(fd, 0, 0, self.handle.pitch());
builder.build().ok_or(rustix::io::Errno::INVAL.into())
Expand Down
1 change: 1 addition & 0 deletions src/backend/allocator/vulkan/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -441,6 +441,7 @@ impl AsDmabuf for VulkanImage {
self.format().code,
self.format().modifier,
DmabufFlags::empty(),
None,
);

for idx in 0..self.format_plane_count {
Expand Down
1 change: 1 addition & 0 deletions src/backend/egl/display.rs
Original file line number Diff line number Diff line change
Expand Up @@ -617,6 +617,7 @@ impl EGLDisplay {
} else {
DmabufFlags::empty()
},
None,
);
for i in 0..num_planes {
dma.add_plane(
Expand Down
8 changes: 8 additions & 0 deletions src/wayland/dmabuf/dispatch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ where
formats: data.formats.clone(),
modifier: Mutex::new(None),
planes: Mutex::new(Vec::with_capacity(MAX_PLANES)),
target_device: Mutex::new(None),
},
);
}
Expand Down Expand Up @@ -343,6 +344,13 @@ where
}
}

zwp_linux_buffer_params_v1::Request::SetTargetDevice { device } => {
if let Ok(bytes) = device.try_into() {
let dev = libc::dev_t::from_ne_bytes(bytes);
*data.target_device.lock().unwrap() = Some(dev);
}
}

_ => unreachable!(),
}
}
Expand Down
18 changes: 11 additions & 7 deletions src/wayland/dmabuf/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -444,13 +444,19 @@ impl PartialEq for DmabufFeedback {
impl DmabufFeedback {
/// Send this feedback to the provided [`ZwpLinuxDmabufFeedbackV1`](zwp_linux_dmabuf_feedback_v1::ZwpLinuxDmabufFeedbackV1)
pub fn send(&self, feedback: &zwp_linux_dmabuf_feedback_v1::ZwpLinuxDmabufFeedbackV1) {
feedback.main_device(self.0.main_device.to_ne_bytes().to_vec());
if feedback.version() < 6 {
feedback.main_device(self.0.main_device.to_ne_bytes().to_vec());
}
feedback.format_table(
self.0.format_table.file.as_fd(),
self.0.format_table.file.size() as u32,
);

for tranche in self.0.tranches.iter() {
let mut flags = tranche.flags;
if feedback.version() >= 6 && tranche.target_device == self.0.main_device {
flags |= zwp_linux_dmabuf_feedback_v1::TrancheFlags::Sampling;
}
feedback.tranche_target_device(tranche.target_device.to_ne_bytes().to_vec());
feedback.tranche_flags(tranche.flags);
feedback.tranche_formats(
Expand Down Expand Up @@ -709,12 +715,7 @@ impl DmabufState {
);

let formats = Arc::new(formats);
let version = if default_feedback.is_some() {
// TODO: Update to 5 when wayland-protocols is updated
4
} else {
3
};
let version = if default_feedback.is_some() { 6 } else { 3 };

let known_default_feedbacks = Arc::new(Mutex::new(Vec::new()));
let default_feedback = default_feedback.map(|f| Arc::new(Mutex::new(f.clone())));
Expand Down Expand Up @@ -833,6 +834,8 @@ pub struct DmabufParamsData {
/// Pending planes for the params.
modifier: Mutex<Option<Modifier>>,
planes: Mutex<Vec<Plane>>,

target_device: Mutex<Option<libc::dev_t>>,
}

/// A handle to a registered dmabuf global.
Expand Down Expand Up @@ -1195,6 +1198,7 @@ impl DmabufParamsData {
format,
modifier,
DmabufFlags::from_bits_truncate(flags.into()),
*self.target_device.lock().unwrap(),
);

for (i, plane) in planes.drain(..).enumerate() {
Expand Down

0 comments on commit 39591cd

Please sign in to comment.