wp-color-management-v1: allocate description ids linearly
This commit is contained in:
parent
401e8bb0be
commit
c9b0e86bf5
6 changed files with 10 additions and 30 deletions
|
|
@ -7,35 +7,13 @@ use {
|
||||||
cmm_transfer_function::TransferFunction,
|
cmm_transfer_function::TransferFunction,
|
||||||
cmm_transform::{ColorMatrix, Local, Xyz, bradford_adjustment},
|
cmm_transform::{ColorMatrix, Local, Xyz, bradford_adjustment},
|
||||||
},
|
},
|
||||||
utils::{free_list::FreeList, ordered_float::F64},
|
utils::ordered_float::F64,
|
||||||
},
|
},
|
||||||
std::rc::Rc,
|
std::rc::Rc,
|
||||||
};
|
};
|
||||||
|
|
||||||
linear_ids!(LinearColorDescriptionIds, LinearColorDescriptionId, u64);
|
linear_ids!(LinearColorDescriptionIds, LinearColorDescriptionId, u64);
|
||||||
|
linear_ids!(ColorDescriptionIds, ColorDescriptionId, u64);
|
||||||
pub type ColorDescriptionIds = FreeList<ColorDescriptionId, 3>;
|
|
||||||
|
|
||||||
#[derive(Copy, Clone, Debug, Eq, PartialEq, Hash)]
|
|
||||||
pub struct ColorDescriptionId(u32);
|
|
||||||
|
|
||||||
impl ColorDescriptionId {
|
|
||||||
pub fn raw(self) -> u32 {
|
|
||||||
self.0
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl From<u32> for ColorDescriptionId {
|
|
||||||
fn from(value: u32) -> Self {
|
|
||||||
Self(value)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl From<ColorDescriptionId> for u32 {
|
|
||||||
fn from(value: ColorDescriptionId) -> Self {
|
|
||||||
value.0
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct LinearColorDescription {
|
pub struct LinearColorDescription {
|
||||||
|
|
@ -102,6 +80,5 @@ impl Drop for LinearColorDescription {
|
||||||
impl Drop for ColorDescription {
|
impl Drop for ColorDescription {
|
||||||
fn drop(&mut self) {
|
fn drop(&mut self) {
|
||||||
self.shared.dead_complete.fetch_add(1);
|
self.shared.dead_complete.fetch_add(1);
|
||||||
self.shared.complete_ids.release(self.id);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -54,7 +54,7 @@ impl ColorManager {
|
||||||
let linear_descriptions = CopyHashMap::default();
|
let linear_descriptions = CopyHashMap::default();
|
||||||
let complete_descriptions = CopyHashMap::default();
|
let complete_descriptions = CopyHashMap::default();
|
||||||
let shared = Rc::new(Shared::default());
|
let shared = Rc::new(Shared::default());
|
||||||
let _ = shared.complete_ids.acquire();
|
let _ = shared.complete_ids.next();
|
||||||
let srgb_srgb = get_description(
|
let srgb_srgb = get_description(
|
||||||
&shared,
|
&shared,
|
||||||
&linear_descriptions,
|
&linear_descriptions,
|
||||||
|
|
@ -219,7 +219,7 @@ fn get_description(
|
||||||
transfer_function,
|
transfer_function,
|
||||||
};
|
};
|
||||||
let d = Rc::new(ColorDescription {
|
let d = Rc::new(ColorDescription {
|
||||||
id: shared.complete_ids.acquire(),
|
id: shared.complete_ids.next(),
|
||||||
linear: d,
|
linear: d,
|
||||||
named_primaries,
|
named_primaries,
|
||||||
transfer_function,
|
transfer_function,
|
||||||
|
|
@ -248,7 +248,7 @@ fn get_description2(
|
||||||
shared.dead_complete.fetch_sub(1);
|
shared.dead_complete.fetch_sub(1);
|
||||||
}
|
}
|
||||||
let d = Rc::new(ColorDescription {
|
let d = Rc::new(ColorDescription {
|
||||||
id: shared.complete_ids.acquire(),
|
id: shared.complete_ids.next(),
|
||||||
linear: ld.clone(),
|
linear: ld.clone(),
|
||||||
named_primaries,
|
named_primaries,
|
||||||
transfer_function,
|
transfer_function,
|
||||||
|
|
|
||||||
|
|
@ -45,7 +45,7 @@ impl WpColorManagementSurfaceFeedbackV1 {
|
||||||
pub fn send_preferred_changed(&self, cd: &ColorDescription) {
|
pub fn send_preferred_changed(&self, cd: &ColorDescription) {
|
||||||
self.client.event(PreferredChanged {
|
self.client.event(PreferredChanged {
|
||||||
self_id: self.id,
|
self_id: self.id,
|
||||||
identity: cd.id.raw(),
|
identity: cd.id.raw() as u32,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -31,7 +31,7 @@ impl WpImageDescriptionV1 {
|
||||||
pub fn send_ready(&self) {
|
pub fn send_ready(&self) {
|
||||||
self.client.event(Ready {
|
self.client.event(Ready {
|
||||||
self_id: self.id,
|
self_id: self.id,
|
||||||
identity: self.description.as_ref().unwrap().id.raw(),
|
identity: self.description.as_ref().unwrap().id.raw() as u32,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -185,6 +185,7 @@ macro_rules! linear_ids {
|
||||||
linear_ids!($(#[$attr1])* $ids, $id, u32);
|
linear_ids!($(#[$attr1])* $ids, $id, u32);
|
||||||
};
|
};
|
||||||
($(#[$attr1:meta])* $ids:ident, $id:ident, $ty:ty $(,)?) => {
|
($(#[$attr1:meta])* $ids:ident, $id:ident, $ty:ty $(,)?) => {
|
||||||
|
#[derive(Debug)]
|
||||||
pub struct $ids {
|
pub struct $ids {
|
||||||
next: crate::utils::numcell::NumCell<$ty>,
|
next: crate::utils::numcell::NumCell<$ty>,
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -41,6 +41,7 @@ impl<T, const N: usize> FreeList<T, N> {
|
||||||
unsafe { self.levels.get().deref_mut() }
|
unsafe { self.levels.get().deref_mut() }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg_attr(not(test), expect(dead_code))]
|
||||||
pub fn release(&self, n: T)
|
pub fn release(&self, n: T)
|
||||||
where
|
where
|
||||||
T: Into<u32>,
|
T: Into<u32>,
|
||||||
|
|
@ -58,6 +59,7 @@ impl<T, const N: usize> FreeList<T, N> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg_attr(not(test), expect(dead_code))]
|
||||||
pub fn acquire(&self) -> T
|
pub fn acquire(&self) -> T
|
||||||
where
|
where
|
||||||
u32: Into<T>,
|
u32: Into<T>,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue