color: Create color profile for assigned profile

We created device profiles, that we manage the lifetime of in colord,
but color devices can be assigned profiles other than the ones it was
created for. For example, this can include the standard sRGB profile
provided by colord.

To achieve this, keep track of the default profile of the CdDevice as
the "assigned" color profile of the device. Given this profile
(CdProfile), construct a MetaColorProfile that can then be interacted
with as if it was generated by ourself.

The assigned profile (default profile in colord terms) does nothing
special so far, but will later be used to determine how to apply CRTC
gamma ramps etc.

The sRGB.icc file used in the tests was copied from colord. It was
stated in the repository that it has no known copyright restrictions.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2164>
This commit is contained in:
Jonas Ådahl
2021-12-01 18:57:52 +01:00
parent cc84a45b56
commit 0a0fb2fda9
9 changed files with 548 additions and 17 deletions

View File

@ -62,6 +62,10 @@ struct _MetaColorDevice
MetaColorProfile *device_profile;
gulong device_profile_ready_handler_id;
MetaColorProfile *assigned_profile;
gulong assigned_profile_ready_handler_id;
GCancellable *assigned_profile_cancellable;
GCancellable *cancellable;
PendingState pending_state;
@ -121,6 +125,77 @@ out:
return g_string_free (device_id, FALSE);
}
static void
ensure_default_profile_cb (GObject *source_object,
GAsyncResult *res,
gpointer user_data)
{
MetaColorStore *color_store = META_COLOR_STORE (source_object);
MetaColorDevice *color_device;
g_autoptr (MetaColorProfile) color_profile = NULL;
g_autoptr (GError) error = NULL;
color_profile = meta_color_store_ensure_colord_profile_finish (color_store,
res,
&error);
if (!color_profile)
{
if (g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED))
return;
g_warning ("Failed to create color profile from colord profile: %s",
error->message);
}
color_device = META_COLOR_DEVICE (user_data);
g_set_object (&color_device->assigned_profile, color_profile);
}
static void
update_assigned_profile (MetaColorDevice *color_device)
{
MetaColorManager *color_manager = color_device->color_manager;
MetaColorStore *color_store =
meta_color_manager_get_color_store (color_manager);
CdProfile *default_profile;
GCancellable *cancellable;
default_profile = cd_device_get_default_profile (color_device->cd_device);
if (color_device->assigned_profile &&
meta_color_profile_get_cd_profile (color_device->assigned_profile) ==
default_profile)
return;
if (color_device->assigned_profile_cancellable)
{
g_cancellable_cancel (color_device->assigned_profile_cancellable);
g_clear_object (&color_device->assigned_profile_cancellable);
}
if (!default_profile)
{
g_clear_object (&color_device->assigned_profile);
return;
}
cancellable = g_cancellable_new ();
color_device->assigned_profile_cancellable = cancellable;
meta_color_store_ensure_colord_profile (color_store,
default_profile,
cancellable,
ensure_default_profile_cb,
color_device);
}
static void
on_cd_device_changed (CdDevice *cd_device,
MetaColorDevice *color_device)
{
update_assigned_profile (color_device);
}
typedef struct
{
GMainLoop *loop;
@ -180,11 +255,18 @@ meta_color_device_dispose (GObject *object)
meta_topic (META_DEBUG_COLOR,
"Removing color device '%s'", color_device->cd_device_id);
if (color_device->assigned_profile_cancellable)
{
g_cancellable_cancel (color_device->assigned_profile_cancellable);
g_clear_object (&color_device->assigned_profile_cancellable);
}
g_cancellable_cancel (color_device->cancellable);
g_clear_object (&color_device->cancellable);
g_clear_signal_handler (&color_device->device_profile_ready_handler_id,
color_device->device_profile);
g_clear_object (&color_device->assigned_profile);
g_clear_object (&color_device->device_profile);
cd_device = color_device->cd_device;
@ -284,6 +366,10 @@ on_cd_device_connected (GObject *source_object,
color_device->pending_state &= ~PENDING_CONNECTED;
g_signal_connect (cd_device, "changed",
G_CALLBACK (on_cd_device_changed), color_device);
update_assigned_profile (color_device);
maybe_finish_setup (color_device);
}
@ -981,3 +1067,9 @@ meta_color_device_is_ready (MetaColorDevice *color_device)
{
return color_device->is_ready;
}
MetaColorProfile *
meta_color_device_get_assigned_profile (MetaColorDevice *color_device)
{
return color_device->assigned_profile;
}