monitor-manager: Add NightLightSupported property to DisplayConfig

This checks whether it's possible to set a CRTC GAMMA_LUT, which is what
is necessary to implement night light.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2310>
This commit is contained in:
Jonas Ådahl 2022-02-24 12:32:27 +01:00 committed by Marge Bot
parent f64259ceae
commit 8fdb80a718
4 changed files with 100 additions and 21 deletions

View File

@ -297,6 +297,13 @@
-->
<property name="ApplyMonitorsConfigAllowed" type="b" access="read" />
<!--
NightLightSupported:
Whether night light is supported by this system.
-->
<property name="NightLightSupported" type="b" access="read" />
<!--
MonitorsChanged:

View File

@ -1165,11 +1165,65 @@ update_has_builtin_panel (MetaMonitorManager *manager)
obj_props[PROP_HAS_BUILTIN_PANEL]);
}
static void
meta_monitor_manager_get_crtc_gamma (MetaMonitorManager *manager,
MetaCrtc *crtc,
size_t *size,
unsigned short **red,
unsigned short **green,
unsigned short **blue)
{
MetaMonitorManagerClass *klass = META_MONITOR_MANAGER_GET_CLASS (manager);
if (klass->get_crtc_gamma)
{
klass->get_crtc_gamma (manager, crtc, size, red, green, blue);
}
else
{
if (size)
*size = 0;
if (red)
*red = NULL;
if (green)
*green = NULL;
if (blue)
*blue = NULL;
}
}
static gboolean
is_night_light_supported (MetaMonitorManager *manager)
{
GList *l;
for (l = meta_backend_get_gpus (manager->backend); l; l = l->next)
{
MetaGpu *gpu = l->data;
GList *l_crtc;
for (l_crtc = meta_gpu_get_crtcs (gpu); l_crtc; l_crtc = l_crtc->next)
{
MetaCrtc *crtc = l_crtc->data;
size_t gamma_lut_size;
meta_monitor_manager_get_crtc_gamma (manager, crtc,
&gamma_lut_size,
NULL, NULL, NULL);
if (gamma_lut_size > 0)
return TRUE;
}
}
return FALSE;
}
void
meta_monitor_manager_setup (MetaMonitorManager *manager)
{
MetaMonitorConfigStore *config_store;
const MetaMonitorConfigPolicy *policy;
gboolean night_light_supported;
manager->in_init = TRUE;
@ -1180,6 +1234,9 @@ meta_monitor_manager_setup (MetaMonitorManager *manager)
meta_dbus_display_config_set_apply_monitors_config_allowed (manager->display_config,
policy->enable_dbus);
night_light_supported = is_night_light_supported (manager);
meta_dbus_display_config_set_night_light_supported (manager->display_config,
night_light_supported);
meta_monitor_manager_read_current_state (manager);
@ -2811,7 +2868,6 @@ meta_monitor_manager_handle_get_crtc_gamma (MetaDBusDisplayConfig *skeleton,
guint crtc_id,
MetaMonitorManager *manager)
{
MetaMonitorManagerClass *klass;
GList *combined_crtcs;
MetaCrtc *crtc;
gsize size;
@ -2842,14 +2898,8 @@ meta_monitor_manager_handle_get_crtc_gamma (MetaDBusDisplayConfig *skeleton,
crtc = g_list_nth_data (combined_crtcs, crtc_id);
g_list_free (combined_crtcs);
klass = META_MONITOR_MANAGER_GET_CLASS (manager);
if (klass->get_crtc_gamma)
klass->get_crtc_gamma (manager, crtc, &size, &red, &green, &blue);
else
{
size = 0;
red = green = blue = NULL;
}
meta_monitor_manager_get_crtc_gamma (manager, crtc,
&size, &red, &green, &blue);
red_bytes = g_bytes_new_take (red, size * sizeof (unsigned short));
green_bytes = g_bytes_new_take (green, size * sizeof (unsigned short));

View File

@ -365,16 +365,31 @@ meta_monitor_manager_native_get_crtc_gamma (MetaMonitorManager *manager,
MetaKmsCrtc *kms_crtc;
const MetaKmsCrtcState *crtc_state;
g_return_if_fail (META_IS_CRTC_KMS (crtc));
if (!META_IS_CRTC_KMS (crtc))
{
if (size)
*size = 0;
if (red)
*red = NULL;
if (green)
*green = NULL;
if (blue)
*blue = NULL;
return;
}
crtc_gamma =
meta_monitor_manager_native_get_cached_crtc_gamma (manager_native,
crtc_kms);
if (crtc_gamma)
{
if (size)
*size = crtc_gamma->size;
if (red)
*red = g_memdup2 (crtc_gamma->red, *size * sizeof **red);
if (green)
*green = g_memdup2 (crtc_gamma->green, *size * sizeof **green);
if (blue)
*blue = g_memdup2 (crtc_gamma->blue, *size * sizeof **blue);
return;
}
@ -382,9 +397,13 @@ meta_monitor_manager_native_get_crtc_gamma (MetaMonitorManager *manager,
kms_crtc = meta_crtc_kms_get_kms_crtc (crtc_kms);
crtc_state = meta_kms_crtc_get_current_state (kms_crtc);
if (size)
*size = crtc_state->gamma.size;
if (red)
*red = g_memdup2 (crtc_state->gamma.red, *size * sizeof **red);
if (green)
*green = g_memdup2 (crtc_state->gamma.green, *size * sizeof **green);
if (blue)
*blue = g_memdup2 (crtc_state->gamma.blue, *size * sizeof **blue);
}

View File

@ -663,8 +663,11 @@ meta_monitor_manager_xrandr_get_crtc_gamma (MetaMonitorManager *manager,
(XID) meta_crtc_get_id (crtc));
*size = gamma->size;
if (red)
*red = g_memdup2 (gamma->red, sizeof (unsigned short) * gamma->size);
if (green)
*green = g_memdup2 (gamma->green, sizeof (unsigned short) * gamma->size);
if (blue)
*blue = g_memdup2 (gamma->blue, sizeof (unsigned short) * gamma->size);
XRRFreeGamma (gamma);