From 22f44c18b6b6dd90a685b459d09af072e9ff2d31 Mon Sep 17 00:00:00 2001 From: Christian Meissl Date: Wed, 19 Jun 2024 13:55:23 +0200 Subject: [PATCH] wayland: keep dmabuf formats in order --- src/wayland/dmabuf/mod.rs | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/src/wayland/dmabuf/mod.rs b/src/wayland/dmabuf/mod.rs index 3a5fccd55b..b2c23b29e9 100644 --- a/src/wayland/dmabuf/mod.rs +++ b/src/wayland/dmabuf/mod.rs @@ -188,7 +188,7 @@ mod dispatch; use std::{ - collections::{HashMap, HashSet}, + collections::HashMap, ffi::CString, ops::Sub, os::unix::io::AsFd, @@ -198,7 +198,7 @@ use std::{ }, }; -use indexmap::IndexSet; +use indexmap::{IndexMap, IndexSet}; use rustix::fs::{seek, SeekFrom}; use wayland_protocols::wp::linux_dmabuf::zv1::server::{ zwp_linux_buffer_params_v1::{self, ZwpLinuxBufferParamsV1}, @@ -596,7 +596,11 @@ impl DmabufState { /// /// Note: This function will create a version 3 dmabuf global and thus not call [`DmabufHandler::new_surface_feedback`], /// if you want to create a version 4 global you need to call [`DmabufState::create_global_with_default_feedback`]. - pub fn create_global(&mut self, display: &DisplayHandle, formats: Vec) -> DmabufGlobal + pub fn create_global( + &mut self, + display: &DisplayHandle, + formats: impl IntoIterator, + ) -> DmabufGlobal where D: GlobalDispatch + BufferHandler @@ -617,7 +621,7 @@ impl DmabufState { pub fn create_global_with_filter( &mut self, display: &DisplayHandle, - formats: Vec, + formats: impl IntoIterator, filter: F, ) -> DmabufGlobal where @@ -627,6 +631,7 @@ impl DmabufState { + 'static, F: for<'c> Fn(&'c Client) -> bool + Send + Sync + 'static, { + let formats = formats.into_iter().collect::>(); self.create_global_with_filter_and_optional_default_feedback::( display, Some(formats), @@ -701,12 +706,12 @@ impl DmabufState { .unwrap() .into_iter() .fold( - HashMap::>::new(), + IndexMap::>::new(), |mut formats, format| { if let Some(modifiers) = formats.get_mut(&format.code) { modifiers.insert(format.modifier); } else { - formats.insert(format.code, HashSet::from_iter(std::iter::once(format.modifier))); + formats.insert(format.code, IndexSet::from_iter(std::iter::once(format.modifier))); } formats }, @@ -792,7 +797,7 @@ impl DmabufState { #[allow(missing_debug_implementations)] pub struct DmabufGlobalData { filter: Box Fn(&'c Client) -> bool + Send + Sync>, - formats: Arc>>, + formats: Arc>>, default_feedback: Option>>, known_default_feedbacks: Arc>>>, @@ -802,7 +807,7 @@ pub struct DmabufGlobalData { /// Data associated with a dmabuf global protocol object. #[derive(Debug)] pub struct DmabufData { - formats: Arc>>, + formats: Arc>>, id: usize, default_feedback: Option>>, @@ -827,7 +832,7 @@ pub struct DmabufParamsData { /// Whether the params protocol object has been used before to create a wl_buffer. used: AtomicBool, - formats: Arc>>, + formats: Arc>>, /// Pending planes for the params. modifier: Mutex>,