Skip to content

Commit

Permalink
dmabuf: Implement version v6
Browse files Browse the repository at this point in the history
  • Loading branch information
Drakulix committed May 15, 2024
1 parent 212fddb commit cf5fdbb
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 14 deletions.
18 changes: 14 additions & 4 deletions anvil/src/udev.rs
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,9 @@ impl DmabufHandler for AnvilState<UdevData> {
.and_then(|mut renderer| renderer.import_dmabuf(&dmabuf, None))
.is_ok()
{
dmabuf.set_node(self.backend_data.primary_gpu);
if dmabuf.node().is_none() {
dmabuf.set_node(self.backend_data.primary_gpu);
}
let _ = notifier.successful::<AnvilState<UdevData>>();
} else {
notifier.failed();
Expand Down Expand Up @@ -796,17 +798,25 @@ fn get_surface_dmabuf_feedback(
let builder = DmabufFeedbackBuilder::new(primary_gpu.dev_id(), primary_formats);
let render_feedback = builder
.clone()
.add_preference_tranche(render_node.dev_id(), None, render_formats.clone())
.add_preference_tranche(
render_node.dev_id(),
zwp_linux_dmabuf_feedback_v1::TrancheFlags::Sampling,
render_formats.clone(),
)
.build()
.unwrap();

let scanout_feedback = builder
.add_preference_tranche(
surface.device_fd().dev_id().unwrap(),
Some(zwp_linux_dmabuf_feedback_v1::TrancheFlags::Scanout),
zwp_linux_dmabuf_feedback_v1::TrancheFlags::Scanout,
planes_formats,
)
.add_preference_tranche(render_node.dev_id(), None, render_formats)
.add_preference_tranche(
render_node.dev_id(),
zwp_linux_dmabuf_feedback_v1::TrancheFlags::Sampling,
render_formats,
)
.build()
.unwrap();

Expand Down
13 changes: 11 additions & 2 deletions src/wayland/dmabuf/dispatch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ where
formats: data.formats.clone(),
modifier: Mutex::new(None),
planes: Mutex::new(Vec::with_capacity(MAX_PLANES)),
node: Mutex::new(None),
},
);
}
Expand Down Expand Up @@ -294,14 +295,20 @@ where
}
}

zwp_linux_buffer_params_v1::Request::SetTargetDevice { device } => {
*data.node.lock().unwrap() = device[0..8].try_into().ok().map(u64::from_ne_bytes);
}

zwp_linux_buffer_params_v1::Request::Create {
width,
height,
format,
flags,
} => {
// create_dmabuf performs an implicit ensure_unused function call.
if let Some(dmabuf) = data.create_dmabuf(params, width, height, format, flags, None) {
if let Some(dmabuf) =
data.create_dmabuf(params, width, height, format, flags, *data.node.lock().unwrap())
{
if state.dmabuf_state().globals.contains_key(&data.id) {
let notifier = ImportNotifier::new(
params.clone(),
Expand All @@ -326,7 +333,9 @@ where
} => {
// Client is killed if the if statement is not taken.
// create_dmabuf performs an implicit ensure_unused function call.
if let Some(dmabuf) = data.create_dmabuf(params, width, height, format, flags, None) {
if let Some(dmabuf) =
data.create_dmabuf(params, width, height, format, flags, *data.node.lock().unwrap())
{
if state.dmabuf_state().globals.contains_key(&data.id) {
// The buffer isn't technically valid during data_init, but the client is not allowed to use the buffer until ready.
let buffer = data_init.init(buffer_id, dmabuf.clone());
Expand Down
23 changes: 15 additions & 8 deletions src/wayland/dmabuf/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,8 @@ use indexmap::IndexSet;
use rustix::fs::{seek, SeekFrom};
use wayland_protocols::wp::linux_dmabuf::zv1::server::{
zwp_linux_buffer_params_v1::{self, ZwpLinuxBufferParamsV1},
zwp_linux_dmabuf_feedback_v1, zwp_linux_dmabuf_v1,
zwp_linux_dmabuf_feedback_v1::{self, TrancheFlags},
zwp_linux_dmabuf_v1,
};
use wayland_server::{
backend::{GlobalId, InvalidId},
Expand Down Expand Up @@ -315,7 +316,7 @@ impl DmabufFeedbackBuilder {
let feedback_formats: IndexSet<Format> = formats.into_iter().collect();
let format_indices: IndexSet<usize> = (0..feedback_formats.len()).collect();
let main_tranche = DmabufFeedbackTranche {
flags: zwp_linux_dmabuf_feedback_v1::TrancheFlags::empty(),
flags: zwp_linux_dmabuf_feedback_v1::TrancheFlags::Sampling,
indices: format_indices,
target_device: main_device,
};
Expand All @@ -340,11 +341,9 @@ impl DmabufFeedbackBuilder {
pub fn add_preference_tranche(
mut self,
target_device: libc::dev_t,
flags: Option<zwp_linux_dmabuf_feedback_v1::TrancheFlags>,
flags: zwp_linux_dmabuf_feedback_v1::TrancheFlags,
formats: impl IntoIterator<Item = Format>,
) -> Self {
let flags = flags.unwrap_or(zwp_linux_dmabuf_feedback_v1::TrancheFlags::empty());

let mut tranche = DmabufFeedbackTranche {
target_device,
flags,
Expand Down Expand Up @@ -445,15 +444,21 @@ 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() <= 5 {
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() {
feedback.tranche_target_device(tranche.target_device.to_ne_bytes().to_vec());
feedback.tranche_flags(tranche.flags);
if feedback.version() <= 5 && tranche.flags.contains(TrancheFlags::Scanout) {
feedback.tranche_flags(TrancheFlags::Scanout);
} else {
feedback.tranche_flags(tranche.flags);
}
feedback.tranche_formats(
tranche
.indices
Expand Down Expand Up @@ -710,7 +715,7 @@ impl DmabufState {
);

let formats = Arc::new(formats);
let version = if default_feedback.is_some() { 5 } 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 @@ -829,6 +834,8 @@ pub struct DmabufParamsData {
/// Pending planes for the params.
modifier: Mutex<Option<Modifier>>,
planes: Mutex<Vec<Plane>>,

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

/// A handle to a registered dmabuf global.
Expand Down

0 comments on commit cf5fdbb

Please sign in to comment.