Skip to content

Commit

Permalink
anvil: Fake color implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
Drakulix committed Oct 26, 2023
1 parent 6584e00 commit 0f1d6c8
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 7 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down
6 changes: 6 additions & 0 deletions anvil/src/shell/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -158,6 +159,11 @@ impl<BackendData: Backend> CompositorHandler for AnvilState<BackendData> {
}
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)
}
}
Expand Down
77 changes: 71 additions & 6 deletions anvil/src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::{
Expand Down Expand Up @@ -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},
Expand Down Expand Up @@ -144,6 +152,8 @@ pub struct AnvilState<BackendData: Backend + 'static> {
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<WlSurface>,

Expand Down Expand Up @@ -503,6 +513,44 @@ impl<BackendData: Backend + 'static> XWaylandKeyboardGrabHandler for AnvilState<
#[cfg(feature = "xwayland")]
delegate_xwayland_keyboard_grab!(@<BackendData: Backend + 'static> AnvilState<BackendData>);

impl<BackendData: Backend + 'static> ColorManagementHandler for AnvilState<BackendData> {
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!(@<BackendData: Backend + 'static> AnvilState<BackendData>);

impl<BackendData: Backend + 'static> ColorRepresentationHandler for AnvilState<BackendData> {
fn color_representation_state(&mut self) -> &mut ColorRepresentationState {
&mut self.color_repr
}
}

delegate_color_representation!(@<BackendData: Backend + 'static> AnvilState<BackendData>);

impl<BackendData: Backend + 'static> AnvilState<BackendData> {
pub fn init(
display: Display<AnvilState<BackendData>>,
Expand Down Expand Up @@ -597,6 +645,21 @@ impl<BackendData: Backend + 'static> AnvilState<BackendData> {

let keyboard_shortcuts_inhibit_state = KeyboardShortcutsInhibitState::new::<Self>(&dh);

let color_manager = ColorManagementState::new::<Self>(
&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::<Self>(&dh, std::iter::empty(), std::iter::empty());

#[cfg(feature = "xwayland")]
let xwayland = {
XWaylandKeyboardGrabState::new::<Self>(&dh);
Expand Down Expand Up @@ -656,6 +719,8 @@ impl<BackendData: Backend + 'static> AnvilState<BackendData> {
xdg_shell_state,
presentation_state,
fractional_scale_manager_state,
color_manager,
color_repr,
dnd_icon: None,
suppressed_keys: Vec::new(),
cursor_status,
Expand Down

0 comments on commit 0f1d6c8

Please sign in to comment.