From 20a91aa4e98ee237892f95d20792e6a38fc45273 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonas=20=C3=85dahl?= Date: Mon, 25 Oct 2021 10:50:02 +0200 Subject: [PATCH] backend: Add color manager skeleton Create a color manager type that eventually will be the high level manager of color related behavior, such as ICC profiles and color "temperature" a.k.a. night light. For now, it's only an empty shell. It's also constructed by the actual backend, as at a later point, the X11 and native color management implementations will differ. Part-of: --- src/backends/meta-backend-private.h | 3 + src/backends/meta-backend-types.h | 2 + src/backends/meta-backend.c | 21 ++++ src/backends/meta-color-manager-private.h | 28 +++++ src/backends/meta-color-manager.c | 144 ++++++++++++++++++++++ src/backends/meta-color-manager.h | 33 +++++ src/backends/native/meta-backend-native.c | 10 ++ src/backends/x11/meta-backend-x11.c | 10 ++ src/meson.build | 3 + 9 files changed, 254 insertions(+) create mode 100644 src/backends/meta-color-manager-private.h create mode 100644 src/backends/meta-color-manager.c create mode 100644 src/backends/meta-color-manager.h diff --git a/src/backends/meta-backend-private.h b/src/backends/meta-backend-private.h index ce703dfa3..f85ef1b60 100644 --- a/src/backends/meta-backend-private.h +++ b/src/backends/meta-backend-private.h @@ -67,6 +67,7 @@ struct _MetaBackendClass MetaMonitorManager * (* create_monitor_manager) (MetaBackend *backend, GError **error); + MetaColorManager * (* create_color_manager) (MetaBackend *backend); MetaCursorRenderer * (* get_cursor_renderer) (MetaBackend *backend, ClutterInputDevice *device); MetaCursorTracker * (* create_cursor_tracker) (MetaBackend *backend); @@ -130,6 +131,8 @@ MetaIdleMonitor * meta_backend_get_idle_monitor (MetaBackend *backend, MetaIdleManager * meta_backend_get_idle_manager (MetaBackend *backend); +MetaColorManager * meta_backend_get_color_manager (MetaBackend *backend); + META_EXPORT_TEST MetaOrientationManager * meta_backend_get_orientation_manager (MetaBackend *backend); META_EXPORT_TEST diff --git a/src/backends/meta-backend-types.h b/src/backends/meta-backend-types.h index 9f4341bb0..7b404060d 100644 --- a/src/backends/meta-backend-types.h +++ b/src/backends/meta-backend-types.h @@ -23,6 +23,8 @@ typedef struct _MetaBackend MetaBackend; +typedef struct _MetaColorManager MetaColorManager; + typedef struct _MetaMonitorManager MetaMonitorManager; typedef struct _MetaMonitorConfigManager MetaMonitorConfigManager; diff --git a/src/backends/meta-backend.c b/src/backends/meta-backend.c index 165a1fe4d..db3f75ae6 100644 --- a/src/backends/meta-backend.c +++ b/src/backends/meta-backend.c @@ -148,6 +148,7 @@ struct _MetaBackendPrivate MetaInputMapper *input_mapper; MetaIdleManager *idle_manager; MetaRenderer *renderer; + MetaColorManager *color_manager; #ifdef HAVE_EGL MetaEgl *egl; #endif @@ -222,6 +223,7 @@ meta_backend_dispose (GObject *object) g_clear_pointer (&priv->cursor_tracker, meta_cursor_tracker_destroy); g_clear_object (&priv->current_device); + g_clear_object (&priv->color_manager); g_clear_object (&priv->monitor_manager); g_clear_object (&priv->orientation_manager); #ifdef HAVE_REMOTE_DESKTOP @@ -954,6 +956,12 @@ meta_backend_create_monitor_manager (MetaBackend *backend, error); } +static MetaColorManager * +meta_backend_create_color_manager (MetaBackend *backend) +{ + return META_BACKEND_GET_CLASS (backend)->create_color_manager (backend); +} + static MetaRenderer * meta_backend_create_renderer (MetaBackend *backend, GError **error) @@ -1194,6 +1202,8 @@ meta_backend_initable_init (GInitable *initable, if (!priv->monitor_manager) return FALSE; + priv->color_manager = meta_backend_create_color_manager (backend); + priv->renderer = meta_backend_create_renderer (backend, error); if (!priv->renderer) return FALSE; @@ -1283,6 +1293,17 @@ meta_backend_get_monitor_manager (MetaBackend *backend) return priv->monitor_manager; } +/** + * meta_backend_get_color_manager: (skip) + */ +MetaColorManager * +meta_backend_get_color_manager (MetaBackend *backend) +{ + MetaBackendPrivate *priv = meta_backend_get_instance_private (backend); + + return priv->color_manager; +} + /** * meta_backend_get_orientation_manager: (skip) */ diff --git a/src/backends/meta-color-manager-private.h b/src/backends/meta-color-manager-private.h new file mode 100644 index 000000000..2e656ae41 --- /dev/null +++ b/src/backends/meta-color-manager-private.h @@ -0,0 +1,28 @@ +/* + * Copyright (C) 2021 Red Hat Inc. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see . + */ + +#ifndef META_COLOR_MANAGER_PRIVATE_H +#define META_COLOR_MANAGER_PRIVATE_H + +#include "backends/meta-color-manager.h" + +struct _MetaColorManagerClass +{ + GObjectClass parent_class; +}; + +#endif /* META_COLOR_MANAGER_PRIVATE_H */ diff --git a/src/backends/meta-color-manager.c b/src/backends/meta-color-manager.c new file mode 100644 index 000000000..3e9fdcfca --- /dev/null +++ b/src/backends/meta-color-manager.c @@ -0,0 +1,144 @@ +/* + * Copyright (C) 2021 Jeremy Cline + * Copyright (C) 2021 Red Hat Inc. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see . + */ + +/** + * SECTION:meta-color-manager + * @title: MetaColorManager + * @short_description: Interfaces for managing color-related properties like + * color look-up tables and color spaces. + * + * Each MetaBackend has a MetaColorManager which includes interfaces for querying + * and altering the color-related properties for displays associated with that + * backend. + * + * These tasks include configuring the hardware's lookup tables (LUTs) used to + * apply or remove transfer functions (traditionally called "gamma"), set up + * color space conversions (CSCs), and for determining or setting the output + * color space and transfer function. + * + * Mutter itself does not store and manage device ICC profiles; this task is + * handled by [colord](https://www.freedesktop.org/software/colord/). Colord + * maintains a database of devices (displays, printers, etc) and color profiles, + * including the default output profile for a device. Users configure colord + * with their preferred color profile for a device via an external application + * like GNOME Control Center or the colormgr CLI. + * + * Colord defines [a specification for device and profile names]( + * https://github.com/hughsie/colord/blob/1.4.5/doc/device-and-profile-naming-spec.txt) + * which is used to map Colord's devices to Mutter's #MetaMonitor. + */ + +#include "config.h" + +#include "backends/meta-color-manager-private.h" + +#include "backends/meta-backend-types.h" +#include "backends/meta-monitor.h" + +enum +{ + PROP_0, + + PROP_BACKEND, + + N_PROPS +}; + +static GParamSpec *obj_props[N_PROPS]; + +typedef struct _MetaColorManagerPrivate +{ + MetaBackend *backend; +} MetaColorManagerPrivate; + +G_DEFINE_TYPE_WITH_PRIVATE (MetaColorManager, meta_color_manager, G_TYPE_OBJECT) + +static void +meta_color_manager_set_property (GObject *object, + guint prop_id, + const GValue *value, + GParamSpec *pspec) +{ + MetaColorManager *color_manager = META_COLOR_MANAGER (object); + MetaColorManagerPrivate *priv = + meta_color_manager_get_instance_private (color_manager); + + switch (prop_id) + { + case PROP_BACKEND: + priv->backend = g_value_get_object (value); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + break; + } +} + +static void +meta_color_manager_get_property (GObject *object, + guint prop_id, + GValue *value, + GParamSpec *pspec) +{ + MetaColorManager *color_manager = META_COLOR_MANAGER (object); + MetaColorManagerPrivate *priv = + meta_color_manager_get_instance_private (color_manager); + + switch (prop_id) + { + case PROP_BACKEND: + g_value_set_object (value, priv->backend); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + break; + } +} + +static void +meta_color_manager_class_init (MetaColorManagerClass *klass) +{ + GObjectClass *object_class = G_OBJECT_CLASS (klass); + + object_class->set_property = meta_color_manager_set_property; + object_class->get_property = meta_color_manager_get_property; + + obj_props[PROP_BACKEND] = + g_param_spec_object ("backend", + "backend", + "MetaBackend", + META_TYPE_BACKEND, + G_PARAM_READWRITE | + G_PARAM_CONSTRUCT_ONLY | + G_PARAM_STATIC_STRINGS); + g_object_class_install_properties (object_class, N_PROPS, obj_props); +} + +static void +meta_color_manager_init (MetaColorManager *color_manager) +{ +} + +MetaBackend * +meta_color_manager_get_backend (MetaColorManager *color_manager) +{ + MetaColorManagerPrivate *priv = + meta_color_manager_get_instance_private (color_manager); + + return priv->backend; +} diff --git a/src/backends/meta-color-manager.h b/src/backends/meta-color-manager.h new file mode 100644 index 000000000..8053a6b2a --- /dev/null +++ b/src/backends/meta-color-manager.h @@ -0,0 +1,33 @@ +/* + * Copyright (C) 2021 Jeremy Cline + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see . + */ + +#ifndef META_COLOR_MANAGER_H +#define META_COLOR_MANAGER_H + +#include + +#include "backends/meta-backend-types.h" + +#define META_TYPE_COLOR_MANAGER (meta_color_manager_get_type ()) +G_DECLARE_DERIVABLE_TYPE (MetaColorManager, meta_color_manager, + META, COLOR_MANAGER, + GObject) + +MetaBackend * +meta_color_manager_get_backend (MetaColorManager *color_manager); + +#endif /* META_COLOR_MANAGER_H */ diff --git a/src/backends/native/meta-backend-native.c b/src/backends/native/meta-backend-native.c index ffbf0b252..86eccec2b 100644 --- a/src/backends/native/meta-backend-native.c +++ b/src/backends/native/meta-backend-native.c @@ -40,6 +40,7 @@ #include +#include "backends/meta-color-manager.h" #include "backends/meta-cursor-tracker-private.h" #include "backends/meta-idle-manager.h" #include "backends/meta-keymap-utils.h" @@ -279,6 +280,14 @@ meta_backend_native_create_monitor_manager (MetaBackend *backend, return manager; } +static MetaColorManager * +meta_backend_native_create_color_manager (MetaBackend *backend) +{ + return g_object_new (META_TYPE_COLOR_MANAGER, + "backend", backend, + NULL); +} + static MetaCursorRenderer * meta_backend_native_get_cursor_renderer (MetaBackend *backend, ClutterInputDevice *device) @@ -714,6 +723,7 @@ meta_backend_native_class_init (MetaBackendNativeClass *klass) backend_class->get_capabilities = meta_backend_native_get_capabilities; backend_class->create_monitor_manager = meta_backend_native_create_monitor_manager; + backend_class->create_color_manager = meta_backend_native_create_color_manager; backend_class->get_cursor_renderer = meta_backend_native_get_cursor_renderer; backend_class->create_renderer = meta_backend_native_create_renderer; backend_class->get_input_settings = meta_backend_native_get_input_settings; diff --git a/src/backends/x11/meta-backend-x11.c b/src/backends/x11/meta-backend-x11.c index da14cd73a..4d4a5da9c 100644 --- a/src/backends/x11/meta-backend-x11.c +++ b/src/backends/x11/meta-backend-x11.c @@ -42,6 +42,7 @@ #include #include +#include "backends/meta-color-manager.h" #include "backends/meta-idle-monitor-private.h" #include "backends/meta-keymap-utils.h" #include "backends/meta-stage-private.h" @@ -595,6 +596,14 @@ meta_backend_x11_create_clutter_backend (MetaBackend *backend) return CLUTTER_BACKEND (meta_clutter_backend_x11_new (backend)); } +static MetaColorManager * +meta_backend_x11_create_color_manager (MetaBackend *backend) +{ + return g_object_new (META_TYPE_COLOR_MANAGER, + "backend", backend, + NULL); +} + static ClutterSeat * meta_backend_x11_create_default_seat (MetaBackend *backend, GError **error) @@ -953,6 +962,7 @@ meta_backend_x11_class_init (MetaBackendX11Class *klass) object_class->dispose = meta_backend_x11_dispose; object_class->finalize = meta_backend_x11_finalize; backend_class->create_clutter_backend = meta_backend_x11_create_clutter_backend; + backend_class->create_color_manager = meta_backend_x11_create_color_manager; backend_class->create_default_seat = meta_backend_x11_create_default_seat; backend_class->post_init = meta_backend_x11_post_init; backend_class->grab_device = meta_backend_x11_grab_device; diff --git a/src/meson.build b/src/meson.build index 49a28137b..6a88f5d5c 100644 --- a/src/meson.build +++ b/src/meson.build @@ -181,6 +181,9 @@ mutter_sources = [ 'backends/meta-backend-private.h', 'backends/meta-barrier.c', 'backends/meta-barrier-private.h', + 'backends/meta-color-manager.c', + 'backends/meta-color-manager.h', + 'backends/meta-color-manager-private.h', 'backends/meta-crtc-mode.c', 'backends/meta-crtc-mode.h', 'backends/meta-crtc.c',