[mutter] color-device: Add API to update gamma LUTs



commit baef39e603f232f5ce3c2ce79c443383cd6a1f67
Author: Jonas Ã…dahl <jadahl gmail com>
Date:   Sat Dec 4 00:49:25 2021 +0100

    color-device: Add API to update gamma LUTs
    
    This will generate a gamma LUT from the profile and apply it to the
    monitor.
    
    Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2165>

 src/backends/meta-color-device.c | 33 +++++++++++++++++++++++++++++++++
 src/backends/meta-color-device.h |  3 +++
 2 files changed, 36 insertions(+)
---
diff --git a/src/backends/meta-color-device.c b/src/backends/meta-color-device.c
index a935723ff5..5192a7b1fd 100644
--- a/src/backends/meta-color-device.c
+++ b/src/backends/meta-color-device.c
@@ -1085,3 +1085,36 @@ meta_color_device_get_assigned_profile (MetaColorDevice *color_device)
 {
   return color_device->assigned_profile;
 }
+
+void
+meta_color_device_update_gamma (MetaColorDevice *color_device,
+                                unsigned int     temperature)
+{
+  MetaColorProfile *color_profile;
+  MetaMonitor *monitor;
+  size_t lut_size;
+  g_autoptr (MetaGammaLut) lut = NULL;
+
+  color_profile = meta_color_device_get_assigned_profile (color_device);
+  if (!color_profile)
+    return;
+
+  monitor = color_device->monitor;
+  if (!meta_monitor_is_active (monitor))
+    return;
+
+  meta_topic (META_DEBUG_COLOR,
+              "Updating device '%s' (%s) using color profile '%s' "
+              "and temperature %uK",
+              meta_color_device_get_id (color_device),
+              meta_monitor_get_connector (monitor),
+              meta_color_profile_get_id (color_profile),
+              temperature);
+
+  lut_size = meta_monitor_get_gamma_lut_size (monitor);
+  lut = meta_color_profile_generate_gamma_lut (color_profile,
+                                               temperature,
+                                               lut_size);
+
+  meta_monitor_set_gamma_lut (monitor, lut);
+}
diff --git a/src/backends/meta-color-device.h b/src/backends/meta-color-device.h
index 6f03750ff7..450513e51d 100644
--- a/src/backends/meta-color-device.h
+++ b/src/backends/meta-color-device.h
@@ -62,4 +62,7 @@ MetaColorProfile * meta_color_device_generate_profile_finish (MetaColorDevice  *
 META_EXPORT_TEST
 gboolean meta_color_device_is_ready (MetaColorDevice *color_device);
 
+void meta_color_device_update_gamma (MetaColorDevice *color_device,
+                                     unsigned int     temperature);
+
 #endif /* META_COLOR_DEVICE_H */


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]