diff --git a/src/backends/meta-monitor-manager-private.h b/src/backends/meta-monitor-manager-private.h index 1943e8150..57f02f25b 100644 --- a/src/backends/meta-monitor-manager-private.h +++ b/src/backends/meta-monitor-manager-private.h @@ -466,4 +466,11 @@ void meta_monitor_manager_get_crtc_gamma (MetaMonitorManager *manager, unsigned short **green, unsigned short **blue); +void meta_monitor_manager_set_crtc_gamma (MetaMonitorManager *manager, + MetaCrtc *crtc, + size_t size, + unsigned short *red, + unsigned short *green, + unsigned short *blue); + #endif /* META_MONITOR_MANAGER_PRIVATE_H */ diff --git a/src/backends/meta-monitor-manager.c b/src/backends/meta-monitor-manager.c index b58a05f2d..6bdd72be1 100644 --- a/src/backends/meta-monitor-manager.c +++ b/src/backends/meta-monitor-manager.c @@ -3971,3 +3971,17 @@ meta_monitor_manager_get_virtual_monitors (MetaMonitorManager *manager) return priv->virtual_monitors; } + +void +meta_monitor_manager_set_crtc_gamma (MetaMonitorManager *manager, + MetaCrtc *crtc, + size_t size, + unsigned short *red, + unsigned short *green, + unsigned short *blue) +{ + MetaMonitorManagerClass *manager_class = + META_MONITOR_MANAGER_GET_CLASS (manager); + + manager_class->set_crtc_gamma (manager, crtc, size, red, green, blue); +} diff --git a/src/backends/meta-monitor.c b/src/backends/meta-monitor.c index 120fa2e60..0dca085ea 100644 --- a/src/backends/meta-monitor.c +++ b/src/backends/meta-monitor.c @@ -648,6 +648,69 @@ meta_monitor_get_gamma_lut_size (MetaMonitor *monitor) return size; } +typedef struct +{ + uint16_t *red; + uint16_t *green; + uint16_t *blue; + size_t size; +} LutData; + +static gboolean +set_gamma_lut (MetaMonitor *monitor, + MetaMonitorMode *mode, + MetaMonitorCrtcMode *monitor_crtc_mode, + gpointer user_data, + GError **error) +{ + LutData *lut_data = user_data; + MetaBackend *backend = meta_monitor_get_backend (monitor); + MetaMonitorManager *monitor_manager = + meta_backend_get_monitor_manager (backend); + MetaCrtc *crtc; + + crtc = meta_output_get_assigned_crtc (monitor_crtc_mode->output); + + meta_monitor_manager_set_crtc_gamma (monitor_manager, + crtc, + lut_data->size, + lut_data->red, + lut_data->green, + lut_data->blue); + return TRUE; +} + +/** + * meta_monitor_set_gamma_lut: + * + * Set a new gamma look-up table (LUT) for the given monitor's CRTCs. + */ +void +meta_monitor_set_gamma_lut (MetaMonitor *monitor, + uint16_t *red, + uint16_t *green, + uint16_t *blue, + size_t size) +{ + MetaMonitorMode *current_mode; + LutData lut_data; + + current_mode = meta_monitor_get_current_mode (monitor); + g_return_if_fail (current_mode); + + lut_data = (LutData) { + .red = red, + .green = green, + .blue = blue, + .size = size, + }; + meta_monitor_mode_foreach_crtc (monitor, + current_mode, + set_gamma_lut, + &lut_data, + NULL); +} + static void meta_monitor_normal_generate_modes (MetaMonitorNormal *monitor_normal) { diff --git a/src/backends/meta-monitor.h b/src/backends/meta-monitor.h index cf0ffa99c..17c4ff3b3 100644 --- a/src/backends/meta-monitor.h +++ b/src/backends/meta-monitor.h @@ -297,4 +297,10 @@ gboolean meta_monitor_set_privacy_screen_enabled (MetaMonitor *monitor, size_t meta_monitor_get_gamma_lut_size (MetaMonitor *monitor); +void meta_monitor_set_gamma_lut (MetaMonitor *monitor, + uint16_t *red, + uint16_t *green, + uint16_t *blue, + size_t size); + #endif /* META_MONITOR_H */