[gnome-desktop] Add gamma api



commit 3bb827f0afb04b351413db0d6efd1157ca992ab9
Author: Matthias Clasen <mclasen redhat com>
Date:   Mon Nov 2 13:07:43 2009 -0500

    Add gamma api
    
    This is just a thin wrapper around the XRANDR 1.3 gamma handling.
    It will be used by gnome-screensaver for proper gamma fading.
    
    Patch by David Airlie. See bug 597874.

 libgnome-desktop/gnome-rr.c            |   76 ++++++++++++++++++++++++++++++++
 libgnome-desktop/libgnomeui/gnome-rr.h |   10 ++++
 2 files changed, 86 insertions(+), 0 deletions(-)
---
diff --git a/libgnome-desktop/gnome-rr.c b/libgnome-desktop/gnome-rr.c
index a64f8ae..6f23fbb 100644
--- a/libgnome-desktop/gnome-rr.c
+++ b/libgnome-desktop/gnome-rr.c
@@ -74,6 +74,7 @@ struct GnomeRRCrtc
     
     GnomeRRRotation	current_rotation;
     GnomeRRRotation	rotations;
+    int			gamma_size;
 };
 
 struct GnomeRRMode
@@ -1447,6 +1448,9 @@ crtc_initialize (GnomeRRCrtc        *crtc,
     
     XRRFreeCrtcInfo (info);
 
+    /* get an store gamma size */
+    crtc->gamma_size = XRRGetCrtcGammaSize (DISPLAY (crtc), crtc->id);
+
     return TRUE;
 }
 
@@ -1516,3 +1520,75 @@ mode_free (GnomeRRMode *mode)
     g_free (mode->name);
     g_free (mode);
 }
+
+void
+gnome_rr_crtc_set_gamma (GnomeRRCrtc *crtc, int size,
+			 unsigned short *red,
+			 unsigned short *green,
+			 unsigned short *blue)
+{
+    int copy_size;
+    XRRCrtcGamma *gamma;
+
+    g_return_if_fail (crtc != NULL);
+    g_return_if_fail (red != NULL);
+    g_return_if_fail (green != NULL);
+    g_return_if_fail (blue != NULL);
+
+    if (size != crtc->gamma_size)
+	return;
+
+    gamma = XRRAllocGamma (crtc->gamma_size);
+
+    copy_size = crtc->gamma_size * sizeof (unsigned short);
+    memcpy (gamma->red, red, copy_size);
+    memcpy (gamma->green, green, copy_size);
+    memcpy (gamma->blue, blue, copy_size);
+
+    XRRSetCrtcGamma (DISPLAY (crtc), crtc->id, gamma);
+    XRRFreeGamma (gamma);
+}
+
+gboolean
+gnome_rr_crtc_get_gamma (GnomeRRCrtc *crtc, int *size,
+			 unsigned short **red, unsigned short **green,
+			 unsigned short **blue)
+{
+    int copy_size;
+    unsigned short *r, *g, *b;
+    XRRCrtcGamma *gamma;
+
+    g_return_val_if_fail (crtc != NULL, FALSE);
+
+    gamma = XRRGetCrtcGamma (DISPLAY (crtc), crtc->id);
+    if (!gamma)
+	return FALSE;
+
+    copy_size = crtc->gamma_size * sizeof (unsigned short);
+
+    if (red) {
+	r = g_new0 (unsigned short, crtc->gamma_size);
+	memcpy (r, gamma->red, copy_size);
+	*red = r;
+    }
+
+    if (green) {
+	g = g_new0 (unsigned short, crtc->gamma_size);
+	memcpy (g, gamma->green, copy_size);
+	*green = g;
+    }
+
+    if (blue) {
+	b = g_new0 (unsigned short, crtc->gamma_size);
+	memcpy (b, gamma->blue, copy_size);
+	*blue = b;
+    }
+
+    XRRFreeGamma (gamma);
+
+    if (size)
+	*size = crtc->gamma_size;
+
+    return TRUE;
+}
+
diff --git a/libgnome-desktop/libgnomeui/gnome-rr.h b/libgnome-desktop/libgnomeui/gnome-rr.h
index 6eae3d0..c43bd8f 100644
--- a/libgnome-desktop/libgnomeui/gnome-rr.h
+++ b/libgnome-desktop/libgnomeui/gnome-rr.h
@@ -160,4 +160,14 @@ GnomeRRRotation gnome_rr_crtc_get_rotations        (GnomeRRCrtc           *crtc)
 gboolean        gnome_rr_crtc_supports_rotation    (GnomeRRCrtc           *crtc,
 						    GnomeRRRotation        rotation);
 
+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,
+						    int                    size,
+						    unsigned short        *red,
+						    unsigned short        *green,
+						    unsigned short        *blue);
 #endif



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