From c9b0e86bf54c017dd0d8739180e4009ab4d3bb20 Mon Sep 17 00:00:00 2001 From: Julian Orth Date: Tue, 22 Apr 2025 16:13:49 +0200 Subject: [PATCH] wp-color-management-v1: allocate description ids linearly --- src/cmm/cmm_description.rs | 27 ++----------------- src/cmm/cmm_manager.rs | 6 ++--- ...wp_color_management_surface_feedback_v1.rs | 2 +- .../wp_image_description_v1.rs | 2 +- src/macros.rs | 1 + src/utils/free_list.rs | 2 ++ 6 files changed, 10 insertions(+), 30 deletions(-) diff --git a/src/cmm/cmm_description.rs b/src/cmm/cmm_description.rs index bb6bb2eb..abb015d3 100644 --- a/src/cmm/cmm_description.rs +++ b/src/cmm/cmm_description.rs @@ -7,35 +7,13 @@ use { cmm_transfer_function::TransferFunction, cmm_transform::{ColorMatrix, Local, Xyz, bradford_adjustment}, }, - utils::{free_list::FreeList, ordered_float::F64}, + utils::ordered_float::F64, }, std::rc::Rc, }; linear_ids!(LinearColorDescriptionIds, LinearColorDescriptionId, u64); - -pub type ColorDescriptionIds = FreeList; - -#[derive(Copy, Clone, Debug, Eq, PartialEq, Hash)] -pub struct ColorDescriptionId(u32); - -impl ColorDescriptionId { - pub fn raw(self) -> u32 { - self.0 - } -} - -impl From for ColorDescriptionId { - fn from(value: u32) -> Self { - Self(value) - } -} - -impl From for u32 { - fn from(value: ColorDescriptionId) -> Self { - value.0 - } -} +linear_ids!(ColorDescriptionIds, ColorDescriptionId, u64); #[derive(Debug)] pub struct LinearColorDescription { @@ -102,6 +80,5 @@ impl Drop for LinearColorDescription { impl Drop for ColorDescription { fn drop(&mut self) { self.shared.dead_complete.fetch_add(1); - self.shared.complete_ids.release(self.id); } } diff --git a/src/cmm/cmm_manager.rs b/src/cmm/cmm_manager.rs index 4e81f8ca..c4e36e11 100644 --- a/src/cmm/cmm_manager.rs +++ b/src/cmm/cmm_manager.rs @@ -54,7 +54,7 @@ impl ColorManager { let linear_descriptions = CopyHashMap::default(); let complete_descriptions = CopyHashMap::default(); let shared = Rc::new(Shared::default()); - let _ = shared.complete_ids.acquire(); + let _ = shared.complete_ids.next(); let srgb_srgb = get_description( &shared, &linear_descriptions, @@ -219,7 +219,7 @@ fn get_description( transfer_function, }; let d = Rc::new(ColorDescription { - id: shared.complete_ids.acquire(), + id: shared.complete_ids.next(), linear: d, named_primaries, transfer_function, @@ -248,7 +248,7 @@ fn get_description2( shared.dead_complete.fetch_sub(1); } let d = Rc::new(ColorDescription { - id: shared.complete_ids.acquire(), + id: shared.complete_ids.next(), linear: ld.clone(), named_primaries, transfer_function, diff --git a/src/ifs/color_management/wp_color_management_surface_feedback_v1.rs b/src/ifs/color_management/wp_color_management_surface_feedback_v1.rs index a6779b5b..04abbd39 100644 --- a/src/ifs/color_management/wp_color_management_surface_feedback_v1.rs +++ b/src/ifs/color_management/wp_color_management_surface_feedback_v1.rs @@ -45,7 +45,7 @@ impl WpColorManagementSurfaceFeedbackV1 { pub fn send_preferred_changed(&self, cd: &ColorDescription) { self.client.event(PreferredChanged { self_id: self.id, - identity: cd.id.raw(), + identity: cd.id.raw() as u32, }); } } diff --git a/src/ifs/color_management/wp_image_description_v1.rs b/src/ifs/color_management/wp_image_description_v1.rs index 93b53cbb..1813404c 100644 --- a/src/ifs/color_management/wp_image_description_v1.rs +++ b/src/ifs/color_management/wp_image_description_v1.rs @@ -31,7 +31,7 @@ impl WpImageDescriptionV1 { pub fn send_ready(&self) { self.client.event(Ready { self_id: self.id, - identity: self.description.as_ref().unwrap().id.raw(), + identity: self.description.as_ref().unwrap().id.raw() as u32, }); } } diff --git a/src/macros.rs b/src/macros.rs index ad0d6121..53ada9a6 100644 --- a/src/macros.rs +++ b/src/macros.rs @@ -185,6 +185,7 @@ macro_rules! linear_ids { linear_ids!($(#[$attr1])* $ids, $id, u32); }; ($(#[$attr1:meta])* $ids:ident, $id:ident, $ty:ty $(,)?) => { + #[derive(Debug)] pub struct $ids { next: crate::utils::numcell::NumCell<$ty>, } diff --git a/src/utils/free_list.rs b/src/utils/free_list.rs index 129e58f6..63d17529 100644 --- a/src/utils/free_list.rs +++ b/src/utils/free_list.rs @@ -41,6 +41,7 @@ impl FreeList { unsafe { self.levels.get().deref_mut() } } + #[cfg_attr(not(test), expect(dead_code))] pub fn release(&self, n: T) where T: Into, @@ -58,6 +59,7 @@ impl FreeList { } } + #[cfg_attr(not(test), expect(dead_code))] pub fn acquire(&self) -> T where u32: Into,