[gnome-desktop/wip/wayland-display: 2/3] GnomeRR: restore support for gamma ramps



commit 34fb2dfdc0fa2edcfbb267ab44970bdcbc1ee256
Author: Giovanni Campagna <gcampagn redhat com>
Date:   Fri Jul 26 14:22:37 2013 +0200

    GnomeRR: restore support for gamma ramps
    
    The color panel of control center needs it.
    
    Note: the color panel and color g-s-d plugins will have different
    changes for wayland support, but they still need the code in the
    XRandR case.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=705510

 libgnome-desktop/gnome-rr.c |   79 +++++++++++++++++++++++++++++++++++++++++++
 libgnome-desktop/gnome-rr.h |    4 +--
 2 files changed, 80 insertions(+), 3 deletions(-)
---
diff --git a/libgnome-desktop/gnome-rr.c b/libgnome-desktop/gnome-rr.c
index a4f395c..39cda88 100644
--- a/libgnome-desktop/gnome-rr.c
+++ b/libgnome-desktop/gnome-rr.c
@@ -1680,3 +1680,82 @@ _gnome_rr_screen_apply_configuration (GnomeRRScreen  *screen,
                                                                 crtcs, outputs,
                                                                 NULL, error);
 }
+
+gboolean
+gnome_rr_crtc_set_gamma (GnomeRRCrtc    *crtc,
+                        int             size,
+                        unsigned short *red,
+                        unsigned short *green,
+                        unsigned short *blue)
+{
+  GBytes *red_bytes, *green_bytes, *blue_bytes;
+  GVariant *red_v, *green_v, *blue_v;
+  gboolean ok;
+
+  red_bytes = g_bytes_new (red, size * sizeof (unsigned short));
+  green_bytes = g_bytes_new (green, size * sizeof (unsigned short));
+  blue_bytes = g_bytes_new (blue, size * sizeof (unsigned short));
+
+  red_v = g_variant_new_from_bytes (G_VARIANT_TYPE ("aq"),
+                                   red_bytes, TRUE);
+  green_v = g_variant_new_from_bytes (G_VARIANT_TYPE ("aq"),
+                                     green_bytes, TRUE);
+  blue_v = g_variant_new_from_bytes (G_VARIANT_TYPE ("aq"),
+                                    blue_bytes, TRUE);
+
+  ok = meta_dbus_display_config_call_set_crtc_gamma_sync (crtc->info->screen->priv->proxy,
+                                                         crtc->info->serial,
+                                                         crtc->id,
+                                                         red_v,
+                                                         green_v,
+                                                         blue_v,
+                                                         NULL, NULL);
+
+  g_bytes_unref (red_bytes);
+  g_bytes_unref (green_bytes);
+  g_bytes_unref (blue_bytes);
+  /* The variant above are floating, no need to free them */
+
+  return ok;
+}
+
+gboolean
+gnome_rr_crtc_get_gamma (GnomeRRCrtc     *crtc,
+                        int             *size,
+                        unsigned short **red,
+                        unsigned short **green,
+                        unsigned short **blue)
+{
+  GBytes *red_bytes, *green_bytes, *blue_bytes;
+  GVariant *red_v, *green_v, *blue_v;
+  gboolean ok;
+  gsize dummy;
+
+  ok = meta_dbus_display_config_call_get_crtc_gamma_sync (crtc->info->screen->priv->proxy,
+                                                         crtc->info->serial,
+                                                         crtc->id,
+                                                         &red_v,
+                                                         &green_v,
+                                                         &blue_v,
+                                                         NULL, NULL);
+  if (!ok)
+    return FALSE;
+
+  red_bytes = g_variant_get_data_as_bytes (red_v);
+  green_bytes = g_variant_get_data_as_bytes (green_v);
+  blue_bytes = g_variant_get_data_as_bytes (blue_v);
+
+  /* Unref the variant early so that the bytes hold the only reference to
+     the data and we don't need to copy
+  */
+  g_variant_unref (red_v);
+  g_variant_unref (green_v);
+  g_variant_unref (blue_v);
+
+  *size = g_bytes_get_size (red_bytes) / sizeof (unsigned short);
+  *red = g_bytes_unref_to_data (red_bytes, &dummy);
+  *green = g_bytes_unref_to_data (green_bytes, &dummy);
+  *blue = g_bytes_unref_to_data (blue_bytes, &dummy);
+
+  return TRUE;
+}
diff --git a/libgnome-desktop/gnome-rr.h b/libgnome-desktop/gnome-rr.h
index a522480..39f452e 100644
--- a/libgnome-desktop/gnome-rr.h
+++ b/libgnome-desktop/gnome-rr.h
@@ -183,17 +183,15 @@ GnomeRRRotation gnome_rr_crtc_get_rotations        (GnomeRRCrtc           *crtc)
 gboolean        gnome_rr_crtc_supports_rotation    (GnomeRRCrtc           *crtc,
                                                    GnomeRRRotation        rotation);
 
-#if 0 /* gamma support */
 gboolean        gnome_rr_crtc_get_gamma            (GnomeRRCrtc           *crtc,
                                                    int                   *size,
                                                    unsigned short       **red,
                                                    unsigned short       **green,
                                                    unsigned short       **blue);
-void            gnome_rr_crtc_set_gamma            (GnomeRRCrtc           *crtc,
+gboolean        gnome_rr_crtc_set_gamma            (GnomeRRCrtc           *crtc,
                                                    int                    size,
                                                    unsigned short        *red,
                                                    unsigned short        *green,
                                                    unsigned short        *blue);
-#endif
 
 #endif /* GNOME_RR_H */


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