From 0f1d6c8b51da94dec4c116da31d8fb6bda2cdc48 Mon Sep 17 00:00:00 2001 From: Victoria Brekenfeld Date: Thu, 26 Oct 2023 23:10:12 +0200 Subject: [PATCH] anvil: Fake color implementation --- Cargo.toml | 2 +- anvil/src/shell/mod.rs | 6 ++++ anvil/src/state.rs | 77 ++++++++++++++++++++++++++++++++++++++---- 3 files changed, 78 insertions(+), 7 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 732856936594..6a94af91f3da 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -102,7 +102,7 @@ renderer_glow = ["renderer_gl", "glow"] renderer_multi = ["backend_drm"] renderer_test = [] use_system_lib = ["wayland_frontend", "wayland-backend/server_system", "wayland-sys", "gbm?/import-wayland"] -wayland_frontend = ["wayland-server", "wayland-protocols", "wayland-protocols-wlr", "wayland-protocols-misc", "tempfile"] +wayland_frontend = ["wayland-server", "wayland-protocols", "wayland-protocols-wlr", "wayland-protocols-misc", "wayland-backend", "tempfile"] x11rb_event_source = ["x11rb"] xwayland = ["encoding_rs", "wayland_frontend", "x11rb/composite", "x11rb/xfixes", "x11rb_event_source", "scopeguard"] test_all_features = ["default", "use_system_lib", "renderer_glow", "libinput_1_19", "renderer_test"] diff --git a/anvil/src/shell/mod.rs b/anvil/src/shell/mod.rs index fa2f17c98d56..16fa46eecfc6 100644 --- a/anvil/src/shell/mod.rs +++ b/anvil/src/shell/mod.rs @@ -19,6 +19,7 @@ use smithay::{ utils::{Logical, Point, Rectangle, Size}, wayland::{ buffer::BufferHandler, + color::{management::get_surface_description, representation::get_color_representation}, compositor::{ add_blocker, add_pre_commit_hook, get_parent, is_sync_subsurface, with_states, with_surface_tree_upward, BufferAssignment, CompositorClientState, CompositorHandler, @@ -158,6 +159,11 @@ impl CompositorHandler for AnvilState { } self.popups.commit(surface); + if let (Some(desc), _) = get_surface_description(surface) { + let representation = get_color_representation(surface); + tracing::info!(?desc, ?representation, "Got Color Description from surface!"); + } + ensure_initial_configure(surface, &self.space, &mut self.popups) } } diff --git a/anvil/src/state.rs b/anvil/src/state.rs index c1ae5f9a053c..d3ce97fdf8e1 100644 --- a/anvil/src/state.rs +++ b/anvil/src/state.rs @@ -10,12 +10,13 @@ use smithay::{ backend::renderer::element::{ default_primary_scanout_output_compare, utils::select_dmabuf_feedback, RenderElementStates, }, - delegate_compositor, delegate_data_control, delegate_data_device, delegate_fractional_scale, - delegate_input_method_manager, delegate_keyboard_shortcuts_inhibit, delegate_layer_shell, - delegate_output, delegate_pointer_constraints, delegate_pointer_gestures, delegate_presentation, - delegate_primary_selection, delegate_relative_pointer, delegate_seat, delegate_security_context, - delegate_shm, delegate_tablet_manager, delegate_text_input_manager, delegate_viewporter, - delegate_virtual_keyboard_manager, delegate_xdg_activation, delegate_xdg_decoration, delegate_xdg_shell, + delegate_color_management, delegate_color_representation, delegate_compositor, delegate_data_control, + delegate_data_device, delegate_fractional_scale, delegate_input_method_manager, + delegate_keyboard_shortcuts_inhibit, delegate_layer_shell, delegate_output, delegate_pointer_constraints, + delegate_pointer_gestures, delegate_presentation, delegate_primary_selection, delegate_relative_pointer, + delegate_seat, delegate_security_context, delegate_shm, delegate_tablet_manager, + delegate_text_input_manager, delegate_viewporter, delegate_virtual_keyboard_manager, + delegate_xdg_activation, delegate_xdg_decoration, delegate_xdg_shell, desktop::{ space::SpaceElement, utils::{ @@ -43,6 +44,13 @@ use smithay::{ }, utils::{Clock, Monotonic, Rectangle}, wayland::{ + color::{ + management::{ + ColorManagementHandler, ColorManagementState, Feature, ImageDescription, + ImageDescriptionContents, Primaries, RenderIntent, TransferFunction, + }, + representation::{ColorRepresentationHandler, ColorRepresentationState}, + }, compositor::{get_parent, with_states, CompositorClientState, CompositorState}, dmabuf::DmabufFeedback, fractional_scale::{with_fractional_scale, FractionalScaleHandler, FractionalScaleManagerState}, @@ -144,6 +152,8 @@ pub struct AnvilState { pub xdg_shell_state: XdgShellState, pub presentation_state: PresentationState, pub fractional_scale_manager_state: FractionalScaleManagerState, + pub color_manager: ColorManagementState, + pub color_repr: ColorRepresentationState, pub dnd_icon: Option, @@ -503,6 +513,44 @@ impl XWaylandKeyboardGrabHandler for AnvilState< #[cfg(feature = "xwayland")] delegate_xwayland_keyboard_grab!(@ AnvilState); +impl ColorManagementHandler for AnvilState { + fn color_management_state(&mut self) -> &mut ColorManagementState { + &mut self.color_manager + } + + fn verify_icc(&mut self, _icc_data: &[u8]) -> bool { + false // not supported + } + + fn description_for_output(&mut self, _output: &Output) -> ImageDescription { + // doesn't matter, vk_hdr_layer never queries this + unreachable!() + } + + fn preferred_description_for_surface(&mut self, _surface: &WlSurface) -> ImageDescription { + // doesn't matter, vk_hdr_layer doesn't care for this + self.color_manager + .build_description(ImageDescriptionContents::Parametric { + tf: TransferFunction::CICP(0), + primaries: Primaries::CICP(0), + target_primaries: None, + target_luminance: None, + max_cll: None, + max_fall: None, + }) + } +} + +delegate_color_management!(@ AnvilState); + +impl ColorRepresentationHandler for AnvilState { + fn color_representation_state(&mut self) -> &mut ColorRepresentationState { + &mut self.color_repr + } +} + +delegate_color_representation!(@ AnvilState); + impl AnvilState { pub fn init( display: Display>, @@ -597,6 +645,21 @@ impl AnvilState { let keyboard_shortcuts_inhibit_state = KeyboardShortcutsInhibitState::new::(&dh); + let color_manager = ColorManagementState::new::( + &dh, + std::iter::once(RenderIntent::Perceptual), + [ + Feature::SetPrimaries, + Feature::SetMasteringDisplayPrimaries, + Feature::Parametric, + Feature::ExtendedTargetVolume, + ] + .into_iter(), + [8, 16].into_iter(), + [1, 9].into_iter(), + ); + let color_repr = ColorRepresentationState::new::(&dh, std::iter::empty(), std::iter::empty()); + #[cfg(feature = "xwayland")] let xwayland = { XWaylandKeyboardGrabState::new::(&dh); @@ -656,6 +719,8 @@ impl AnvilState { xdg_shell_state, presentation_state, fractional_scale_manager_state, + color_manager, + color_repr, dnd_icon: None, suppressed_keys: Vec::new(), cursor_status,