1
0
Fork 0

color-device: Derive color space from monitor calibration

This ignores the white point calibration for now because our color state
isn't expressive enough, yet.

Co-authored-by: Joan Torres <joan.torres@suse.com>
Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/3904>
This commit is contained in:
Sebastian Wick 2024-06-10 18:47:25 +02:00
parent 357e5c92f2
commit dc6632f19b
3 changed files with 70 additions and 5 deletions

View file

@ -623,19 +623,64 @@ on_manager_ready (MetaColorManager *color_manager,
create_cd_device (color_device);
}
static ClutterColorspace
get_color_space_from_monitor (MetaMonitor *monitor)
{
switch (meta_monitor_get_color_space (monitor))
{
case META_OUTPUT_COLORSPACE_DEFAULT:
case META_OUTPUT_COLORSPACE_UNKNOWN:
return CLUTTER_COLORSPACE_DEFAULT;
case META_OUTPUT_COLORSPACE_BT2020:
return CLUTTER_COLORSPACE_BT2020;
}
g_assert_not_reached ();
}
static ClutterTransferFunction
get_transfer_function_from_monitor (MetaMonitor *monitor)
{
const MetaOutputHdrMetadata *hdr_metadata =
meta_monitor_get_hdr_metadata (monitor);
if (!hdr_metadata->active)
return CLUTTER_TRANSFER_FUNCTION_DEFAULT;
switch (hdr_metadata->eotf)
{
case META_OUTPUT_HDR_METADATA_EOTF_PQ:
return CLUTTER_TRANSFER_FUNCTION_PQ;
case META_OUTPUT_HDR_METADATA_EOTF_TRADITIONAL_GAMMA_SDR:
return CLUTTER_TRANSFER_FUNCTION_DEFAULT;
case META_OUTPUT_HDR_METADATA_EOTF_TRADITIONAL_GAMMA_HDR:
g_warning ("Unhandled HDR EOTF (traditional gamma hdr)");
return CLUTTER_TRANSFER_FUNCTION_DEFAULT;
case META_OUTPUT_HDR_METADATA_EOTF_HLG:
g_warning ("Unhandled HDR EOTF (HLG)");
return CLUTTER_TRANSFER_FUNCTION_DEFAULT;
}
g_assert_not_reached ();
}
static UpdateResult
update_color_state (MetaColorDevice *color_device)
{
MetaMonitor *monitor = color_device->monitor;
MetaBackend *backend =
meta_color_manager_get_backend (color_device->color_manager);
ClutterContext *clutter_context = meta_backend_get_clutter_context (backend);
ClutterColorManager *clutter_color_manager =
clutter_context_get_color_manager (clutter_context);
ClutterColorState *color_state;
g_autoptr (ClutterColorState) color_state = NULL;
ClutterColorspace colorspace;
ClutterTransferFunction transfer_function;
UpdateResult result = 0;
color_state =
clutter_color_manager_get_default_color_state (clutter_color_manager);
colorspace = get_color_space_from_monitor (monitor);
transfer_function = get_transfer_function_from_monitor (monitor);
color_state = clutter_color_state_new (clutter_context,
colorspace,
transfer_function);
if (!color_device->color_state ||
!clutter_color_state_equals (color_device->color_state, color_state))

View file

@ -2276,6 +2276,14 @@ meta_monitor_get_min_refresh_rate (MetaMonitor *monitor,
min_refresh_rate);
}
MetaOutputColorspace
meta_monitor_get_color_space (MetaMonitor *monitor)
{
MetaOutput *output = meta_monitor_get_main_output (monitor);
return meta_output_peek_color_space (output);
}
gboolean
meta_monitor_set_color_space (MetaMonitor *monitor,
MetaOutputColorspace color_space,
@ -2307,6 +2315,14 @@ meta_monitor_set_color_space (MetaMonitor *monitor,
return TRUE;
}
MetaOutputHdrMetadata *
meta_monitor_get_hdr_metadata (MetaMonitor *monitor)
{
MetaOutput *output = meta_monitor_get_main_output (monitor);
return meta_output_peek_hdr_metadata (output);
}
gboolean
meta_monitor_set_hdr_metadata (MetaMonitor *monitor,
MetaOutputHdrMetadata *metadata,

View file

@ -312,10 +312,14 @@ size_t meta_monitor_get_gamma_lut_size (MetaMonitor *monitor);
void meta_monitor_set_gamma_lut (MetaMonitor *monitor,
const MetaGammaLut *lut);
MetaOutputColorspace meta_monitor_get_color_space (MetaMonitor *monitor);
gboolean meta_monitor_set_color_space (MetaMonitor *monitor,
MetaOutputColorspace color_space,
GError **error);
MetaOutputHdrMetadata * meta_monitor_get_hdr_metadata (MetaMonitor *monitor);
gboolean meta_monitor_set_hdr_metadata (MetaMonitor *monitor,
MetaOutputHdrMetadata *metadata,
GError **error);