[gnome-screensaver] Drop GdkPixmap usage



commit 7a20b6647d404d166431f801763bca22f166121b
Author: Ray Strode <rstrode redhat com>
Date:   Wed Sep 29 23:52:52 2010 -0400

    Drop GdkPixmap usage
    
    It's obsolete

 src/gs-lock-plug.c  |  170 ++++++++++++++++++++++++++++++++++++++++-----------
 src/gs-manager.c    |   20 +++---
 src/gs-window-x11.c |  122 +++++++++---------------------------
 src/gs-window.h     |    4 +-
 4 files changed, 177 insertions(+), 139 deletions(-)
---
diff --git a/src/gs-lock-plug.c b/src/gs-lock-plug.c
index 080ab91..21033da 100644
--- a/src/gs-lock-plug.c
+++ b/src/gs-lock-plug.c
@@ -552,55 +552,143 @@ rounded_rectangle (cairo_t *cr,
         cairo_close_path (cr);
 }
 
+/* copied from gdm-user.c */
+
+/**
+ * go_cairo_convert_data_to_pixbuf:
+ * @src: a pointer to pixel data in cairo format
+ * @dst: a pointer to pixel data in pixbuf format
+ * @width: image width
+ * @height: image height
+ * @rowstride: data rowstride
+ *
+ * Converts the pixel data stored in @src in CAIRO_FORMAT_ARGB32 cairo format
+ * to GDK_COLORSPACE_RGB pixbuf format and move them
+ * to @dst. If @src == @dst, pixel are converted in place.
+ **/
+
 static void
-image_set_from_pixbuf (GtkImage  *image,
-                       GdkPixbuf *source)
+go_cairo_convert_data_to_pixbuf (unsigned char *dst,
+                                 unsigned char const *src,
+                                 int width,
+                                 int height,
+                                 int rowstride)
+{
+        int i,j;
+        unsigned int t;
+        unsigned char a, b, c;
+
+        g_return_if_fail (dst != NULL);
+
+#define MULT(d,c,a,t) G_STMT_START { t = (a)? c * 255 / a: 0; d = t;} G_STMT_END
+
+        if (src == dst || src == NULL) {
+                for (i = 0; i < height; i++) {
+                        for (j = 0; j < width; j++) {
+#if G_BYTE_ORDER == G_LITTLE_ENDIAN
+                                MULT(a, dst[2], dst[3], t);
+                                MULT(b, dst[1], dst[3], t);
+                                MULT(c, dst[0], dst[3], t);
+                                dst[0] = a;
+                                dst[1] = b;
+                                dst[2] = c;
+#else
+                                MULT(a, dst[1], dst[0], t);
+                                MULT(b, dst[2], dst[0], t);
+                                MULT(c, dst[3], dst[0], t);
+                                dst[3] = dst[0];
+                                dst[0] = a;
+                                dst[1] = b;
+                                dst[2] = c;
+#endif
+                                dst += 4;
+                        }
+                        dst += rowstride - width * 4;
+                }
+        } else {
+                for (i = 0; i < height; i++) {
+                        for (j = 0; j < width; j++) {
+#if G_BYTE_ORDER == G_LITTLE_ENDIAN
+                                MULT(dst[0], src[2], src[3], t);
+                                MULT(dst[1], src[1], src[3], t);
+                                MULT(dst[2], src[0], src[3], t);
+                                dst[3] = src[3];
+#else
+                                MULT(dst[0], src[1], src[0], t);
+                                MULT(dst[1], src[2], src[0], t);
+                                MULT(dst[2], src[3], src[0], t);
+                                dst[3] = src[0];
+#endif
+                                src += 4;
+                                dst += 4;
+                        }
+                        src += rowstride - width * 4;
+                        dst += rowstride - width * 4;
+                }
+        }
+#undef MULT
+}
+
+static void
+cairo_to_pixbuf (guint8    *src_data,
+                 GdkPixbuf *dst_pixbuf)
+{
+        unsigned char *src;
+        unsigned char *dst;
+        guint          w;
+        guint          h;
+        guint          rowstride;
+
+        w = gdk_pixbuf_get_width (dst_pixbuf);
+        h = gdk_pixbuf_get_height (dst_pixbuf);
+        rowstride = gdk_pixbuf_get_rowstride (dst_pixbuf);
+
+        dst = gdk_pixbuf_get_pixels (dst_pixbuf);
+        src = src_data;
+
+        go_cairo_convert_data_to_pixbuf (dst, src, w, h, rowstride);
+}
+
+static GdkPixbuf *
+frame_pixbuf (GdkPixbuf *source)
 {
+        GdkPixbuf       *dest;
         cairo_t         *cr;
-        cairo_t         *cr_mask;
         cairo_surface_t *surface;
-        GdkPixmap       *pixmap;
-        GdkPixmap       *bitmask;
-        int              w;
-        int              h;
+        guint            w;
+        guint            h;
+        guint            rowstride;
         int              frame_width;
         double           radius;
-        GdkColor         color;
-        double           r;
-        double           g;
-        double           b;
+        guint8          *data;
 
         frame_width = 5;
 
         w = gdk_pixbuf_get_width (source) + frame_width * 2;
         h = gdk_pixbuf_get_height (source) + frame_width * 2;
-
         radius = w / 10;
 
-        pixmap = gdk_pixmap_new (gtk_widget_get_window (GTK_WIDGET (image)), w, h, -1);
-        bitmask = gdk_pixmap_new (gtk_widget_get_window (GTK_WIDGET (image)), w, h, 1);
-
-        cr = gdk_cairo_create (pixmap);
-        cr_mask = gdk_cairo_create (bitmask);
+        dest = gdk_pixbuf_new (GDK_COLORSPACE_RGB,
+                               TRUE,
+                               8,
+                               w,
+                               h);
+        rowstride = gdk_pixbuf_get_rowstride (dest);
 
-        /* setup mask */
-        cairo_rectangle (cr_mask, 0, 0, w, h);
-        cairo_set_operator (cr_mask, CAIRO_OPERATOR_CLEAR);
-        cairo_fill (cr_mask);
 
-        rounded_rectangle (cr_mask, 1.0, 0.5, 0.5, radius, w - 1, h - 1);
-        cairo_set_operator (cr_mask, CAIRO_OPERATOR_OVER);
-        cairo_set_source_rgb (cr_mask, 1, 1, 1);
-        cairo_fill (cr_mask);
+        data = g_new0 (guint8, h * rowstride);
 
-        color = gtk_widget_get_style (GTK_WIDGET (image))->bg [GTK_STATE_NORMAL];
-        r = (float)color.red / 65535.0;
-        g = (float)color.green / 65535.0;
-        b = (float)color.blue / 65535.0;
+        surface = cairo_image_surface_create_for_data (data,
+                                                       CAIRO_FORMAT_ARGB32,
+                                                       w,
+                                                       h,
+                                                       rowstride);
+        cr = cairo_create (surface);
+        cairo_surface_destroy (surface);
 
         /* set up image */
         cairo_rectangle (cr, 0, 0, w, h);
-        cairo_set_source_rgb (cr, r, g, b);
+        cairo_set_source_rgba (cr, 1.0, 1.0, 1.0, 0.0);
         cairo_fill (cr);
 
         rounded_rectangle (cr,
@@ -616,18 +704,28 @@ image_set_from_pixbuf (GtkImage  *image,
         surface = surface_from_pixbuf (source);
         cairo_set_source_surface (cr, surface, frame_width, frame_width);
         cairo_fill (cr);
-
-        gtk_image_set_from_pixmap (image, pixmap, bitmask);
-
         cairo_surface_destroy (surface);
 
-        g_object_unref (bitmask);
-        g_object_unref (pixmap);
+        cairo_to_pixbuf (data, dest);
 
-        cairo_destroy (cr_mask);
         cairo_destroy (cr);
+        g_free (data);
+
+        return dest;
 }
 
+/* end copied from gdm-user.c */
+
+static void
+image_set_from_pixbuf (GtkImage  *image,
+                       GdkPixbuf *source)
+{
+        GdkPixbuf *pixbuf;
+
+        pixbuf = frame_pixbuf (source);
+        gtk_image_set_from_pixbuf (image, pixbuf);
+        g_object_unref (pixbuf);
+}
 
 static gboolean
 check_user_file (const gchar *filename,
diff --git a/src/gs-manager.c b/src/gs-manager.c
index 34ff403..a6b2404 100644
--- a/src/gs-manager.c
+++ b/src/gs-manager.c
@@ -1214,27 +1214,27 @@ static void
 apply_background_to_window (GSManager *manager,
                             GSWindow  *window)
 {
-        GdkPixmap       *pixmap;
+        cairo_surface_t *surface;
         GdkScreen       *screen;
         int              width;
         int              height;
 
         if (manager->priv->bg == NULL) {
                 gs_debug ("No background available");
-                gs_window_set_background_pixmap (window, NULL);
+                gs_window_set_background_surface (window, NULL);
         }
 
         screen = gs_window_get_screen (window);
         width = gdk_screen_get_width (screen);
         height = gdk_screen_get_height (screen);
-        gs_debug ("Creating pixmap background w:%d h:%d", width, height);
-        pixmap = gnome_bg_create_pixmap (manager->priv->bg,
-                                         gs_window_get_gdk_window (window),
-                                         width,
-                                         height,
-                                         FALSE);
-        gs_window_set_background_pixmap (window, pixmap);
-        g_object_unref (pixmap);
+        gs_debug ("Creating background w:%d h:%d", width, height);
+        surface = gnome_bg_create_surface (manager->priv->bg,
+                                           gs_window_get_gdk_window (window),
+                                           width,
+                                           height,
+                                           FALSE);
+        gs_window_set_background_surface (window, surface);
+        cairo_surface_destroy (surface);
 }
 
 static void
diff --git a/src/gs-window-x11.c b/src/gs-window-x11.c
index 2c9a63b..d0028ad 100644
--- a/src/gs-window-x11.c
+++ b/src/gs-window-x11.c
@@ -84,7 +84,7 @@ struct GSWindowPrivate
         GtkWidget *info_bar;
         GtkWidget *info_content;
 
-        GdkPixmap *background_pixmap;
+        cairo_surface_t *background_surface;
 
         guint      popup_dialog_idle_id;
 
@@ -255,120 +255,58 @@ widget_clear_all_children (GtkWidget *widget)
         gdk_error_trap_pop_ignored ();
 }
 
+static void
+gs_window_reset_background_surface (GSWindow *window)
+{
+        cairo_pattern_t *pattern;
+        pattern = cairo_pattern_create_for_surface (window->priv->background_surface);
+        gdk_window_set_background_pattern (gtk_widget_get_window (GTK_WIDGET (window)),
+                                           pattern);
+        cairo_pattern_destroy (pattern);
+        gtk_widget_queue_draw (GTK_WIDGET (window));
+}
+
 void
-gs_window_set_background_pixmap (GSWindow  *window,
-                                 GdkPixmap *pixmap)
+gs_window_set_background_surface (GSWindow        *window,
+                                  cairo_surface_t *surface)
 {
         g_return_if_fail (GS_IS_WINDOW (window));
 
-        if (window->priv->background_pixmap != NULL) {
-                g_object_unref (window->priv->background_pixmap);
+        if (window->priv->background_surface != NULL) {
+                cairo_surface_destroy (window->priv->background_surface);
         }
 
-        if (pixmap != NULL) {
-                window->priv->background_pixmap = g_object_ref (pixmap);
-                gdk_window_set_back_pixmap (gtk_widget_get_window (GTK_WIDGET (window)),
-                                            pixmap,
-                                            FALSE);
+        if (surface != NULL) {
+                window->priv->background_surface = cairo_surface_reference (surface);
+                gs_window_reset_background_surface (window);
         }
 }
 
 static void
-gs_window_clear_to_background_pixmap (GSWindow *window)
+gs_window_clear_to_background_surface (GSWindow *window)
 {
-        GtkStateType state;
-        GtkStyle    *style;
-
         g_return_if_fail (GS_IS_WINDOW (window));
 
         if (!gtk_widget_get_visible (GTK_WIDGET (window))) {
                 return;
         }
 
-        if (window->priv->background_pixmap == NULL) {
-                /* don't allow null pixmaps */
+        if (window->priv->background_surface == NULL) {
                 return;
         }
 
         gs_debug ("Clearing window to background pixmap");
-
-        style = gtk_style_copy (gtk_widget_get_style (GTK_WIDGET (window)));
-
-        state = (GtkStateType) 0;
-        while (state < (GtkStateType) G_N_ELEMENTS (gtk_widget_get_style (GTK_WIDGET (window))->bg_pixmap)) {
-
-                if (style->bg_pixmap[state] != NULL) {
-                        g_object_unref (style->bg_pixmap[state]);
-                }
-
-                style->bg_pixmap[state] = g_object_ref (window->priv->background_pixmap);
-                state++;
-        }
-
-        gtk_widget_set_style (GTK_WIDGET (window), style);
-        g_object_unref (style);
-
-        if (window->priv->background_pixmap != NULL) {
-                gdk_window_set_back_pixmap (gtk_widget_get_window (GTK_WIDGET (window)),
-                                            window->priv->background_pixmap,
-                                            FALSE);
-        }
-
-        gdk_window_clear (gtk_widget_get_window (GTK_WIDGET (window)));
-
-        gdk_flush ();
+        gs_window_reset_background_surface (window);
 }
 
 static void
 clear_widget (GtkWidget *widget)
 {
-        GdkColor     color = { 0, 0x0000, 0x0000, 0x0000 };
-        GdkColormap *colormap;
-        GdkWindow   *window;
-        GtkStateType state;
-        GtkStyle    *style;
-        GtkStyle    *widget_style;
-
-        if (!gtk_widget_get_visible (widget)) {
-                return;
-        }
-
-        gs_debug ("Clearing widget");
-
-        widget_style = gtk_widget_get_style (widget);
-        state = (GtkStateType) 0;
-        while (state < (GtkStateType) G_N_ELEMENTS (widget_style->bg)) {
-                gtk_widget_modify_bg (widget, state, &color);
-                state++;
-        }
-
-        style = gtk_style_copy (widget_style);
-
-        state = (GtkStateType) 0;
-        while (state < (GtkStateType) G_N_ELEMENTS (widget_style->bg_pixmap)) {
-
-                if (style->bg_pixmap[state] != NULL) {
-                        g_object_unref (style->bg_pixmap[state]);
-                }
-
-                style->bg_pixmap[state] = NULL;
-                state++;
-        }
-
-        window = gtk_widget_get_window (widget);
-        colormap = gdk_drawable_get_colormap (window);
-        gdk_colormap_alloc_color (colormap, &color, FALSE, TRUE);
-        gdk_window_set_background (window, &color);
-
-        gtk_widget_set_style (widget, style);
-        g_object_unref (style);
-
-        gdk_window_clear (window);
-
-        /* If a screensaver theme adds child windows we need to clear them too */
-        widget_clear_all_children (widget);
+        GdkColor color = { 0, 0x0000, 0x0000, 0x0000 };
 
-        gdk_flush ();
+        gdk_window_set_background (gtk_widget_get_window (widget),
+                                   &color);
+        gtk_widget_queue_draw (GTK_WIDGET (widget));
 }
 
 void
@@ -1703,7 +1641,7 @@ popup_dialog (GSWindow *window)
 
         gtk_widget_hide (window->priv->drawing_area);
 
-        gs_window_clear_to_background_pixmap (window);
+        gs_window_clear_to_background_surface (window);
 
         set_invisible_cursor (gtk_widget_get_window (GTK_WIDGET (window)), FALSE);
 
@@ -2403,6 +2341,7 @@ gs_window_init (GSWindow *window)
 
         window->priv->drawing_area = gtk_drawing_area_new ();
         gtk_widget_show (window->priv->drawing_area);
+        gtk_widget_set_app_paintable (window->priv->drawing_area, TRUE);
         gtk_box_pack_start (GTK_BOX (window->priv->vbox), window->priv->drawing_area, TRUE, TRUE, 0);
         create_info_bar (window);
 
@@ -2454,8 +2393,8 @@ gs_window_finalize (GObject *object)
 
         gs_window_dialog_finish (window);
 
-        if (window->priv->background_pixmap) {
-               g_object_unref (window->priv->background_pixmap);
+        if (window->priv->background_surface) {
+               cairo_surface_destroy (window->priv->background_surface);
         }
 
         G_OBJECT_CLASS (gs_window_parent_class)->finalize (object);
@@ -2473,6 +2412,7 @@ gs_window_new (GdkScreen *screen,
                                "screen", screen,
                                "monitor", monitor,
                                "lock-enabled", lock_enabled,
+                               "app-paintable", TRUE,
                                NULL);
 
         return GS_WINDOW (result);
diff --git a/src/gs-window.h b/src/gs-window.h
index db76d72..6ab6496 100644
--- a/src/gs-window.h
+++ b/src/gs-window.h
@@ -66,8 +66,8 @@ void        gs_window_set_monitor        (GSWindow  *window,
                                           int        monitor);
 int         gs_window_get_monitor        (GSWindow  *window);
 
-void        gs_window_set_background_pixmap (GSWindow  *window,
-                                             GdkPixmap *pixmap);
+void        gs_window_set_background_surface (GSWindow        *window,
+                                              cairo_surface_t *surface);
 void        gs_window_set_lock_enabled   (GSWindow  *window,
                                           gboolean   lock_enabled);
 void        gs_window_set_logout_enabled (GSWindow  *window,



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