[sapwood] change the GdkPixmap to a cairo_surface_t



commit bb8d3cfad90f3480b0ea55c72016c32af78c417e
Author: Sven Herzberg <herzi gnome-de org>
Date:   Fri Aug 13 13:36:13 2010 +0200

    change the GdkPixmap to a cairo_surface_t
    
    * engine/sapwood-pixmap-priv.h,
    * engine/sapwood-pixmap.c,
    * engine/sapwood-pixmap.h: change the GdkPixmap for the source into a
      cairo_surface_t (to continue the cairo migration)
    * engine/theme-pixbuf.c,
    * tests/test-sapwood-pixmap.c: update to the new API
    * engine/sapwood-style.c: fix the warning about the uninitialized fields

 engine/sapwood-pixmap-priv.h |    8 ++++----
 engine/sapwood-pixmap.c      |   36 +++++++++++++-----------------------
 engine/sapwood-pixmap.h      |    6 +++---
 engine/sapwood-style.c       |    3 +++
 engine/theme-pixbuf.c        |    4 ++--
 tests/test-sapwood-pixmap.c  |    8 ++++----
 6 files changed, 29 insertions(+), 36 deletions(-)
---
diff --git a/engine/sapwood-pixmap-priv.h b/engine/sapwood-pixmap-priv.h
index 4a2d5bb..4d3713a 100644
--- a/engine/sapwood-pixmap-priv.h
+++ b/engine/sapwood-pixmap-priv.h
@@ -28,10 +28,10 @@
 
 struct _SapwoodPixmap
 {
-  guint32    id;
-  gint       width;
-  gint       height;
-  GdkPixmap *pixmap[3][3];
+  guint32          id;
+  gint             width;
+  gint             height;
+  cairo_surface_t* sources[3][3];
   cairo_surface_t* masks[3][3];
 };
 
diff --git a/engine/sapwood-pixmap.c b/engine/sapwood-pixmap.c
index 6c4cf0e..0113564 100644
--- a/engine/sapwood-pixmap.c
+++ b/engine/sapwood-pixmap.c
@@ -31,8 +31,6 @@
 #include <string.h>
 #include <unistd.h>
 
-static cairo_user_data_key_t  sapwood_pixmap_owner;
-
 gboolean sapwood_debug_scaling = FALSE;
 gboolean sapwood_debug_xtraps = FALSE;
 
@@ -185,8 +183,8 @@ sapwood_pixmap_get_for_file (const char *filename,
 	    g_warning ("%s: pixmask[%d][%d]: no pixmap", g_basename (filename), i, j);
 	  }
 
-        self->pixmap[i][j] = pixmap;
-        self->masks[i][j]  = mask;
+        self->sources[i][j] = sapwood_create_surface_and_unref (pixmap);
+        self->masks[i][j]   = mask;
       }
 
   return self;
@@ -214,30 +212,22 @@ pixbuf_proto_unref_pixmap (guint32 id)
 void
 sapwood_pixmap_free (SapwoodPixmap *self)
 {
-  GdkDisplay *display = NULL;
   int         i, j;
 
-  if (!self)
-    {
-      return;
-    }
+  g_return_if_fail (self);
 
   for (i = 0; i < 3; i++)
     for (j = 0; j < 3; j++)
-      if (self->pixmap[i][j])
+      if (self->sources[i][j])
         {
-          if (!display)
-            display = gdk_drawable_get_display (self->pixmap[i][j]);
-
-          g_object_unref (self->pixmap[i][j]);
+          cairo_surface_destroy (self->sources[i][j]);
           if (self->masks[i][j])
             cairo_surface_destroy (self->masks[i][j]);
         }
 
   /* need to make sure all our operations are processed before the pixmaps
    * are free'd by the server or we risk causing BadPixmap error */
-  if (display)
-    gdk_display_sync (display);
+  gdk_display_sync (gdk_display_get_default ());
 
   pixbuf_proto_unref_pixmap (self->id);
   g_free (self); /* FIXME: use g_slice() at least */
@@ -263,11 +253,11 @@ void
 sapwood_pixmap_get_pixmap (SapwoodPixmap  * self,
                            gint             x,
                            gint             y,
-                           GdkPixmap      **pixmap,
+                           cairo_surface_t**out_source,
                            cairo_surface_t**out_mask)
 {
-  *pixmap  = self->pixmap[y][x];
-  *out_mask = self->masks[y][x];
+  *out_source = self->sources[y][x];
+  *out_mask   = self->masks[y][x];
 }
 
 /*
@@ -328,7 +318,7 @@ sapwood_pixmap_render_rects_internal (SapwoodPixmap  * self,
 	  else
 	    area = *dest;
 
-	  if (rect[n].pixmap && rect[n].mask)
+	  if (rect[n].source && rect[n].mask)
 	    {
               cairo_set_source_surface (mask_cr, rect[n].mask, area.x, area.y);
               cairo_pattern_set_extend (cairo_get_source (mask_cr), CAIRO_EXTEND_REPEAT);
@@ -354,11 +344,11 @@ sapwood_pixmap_render_rects_internal (SapwoodPixmap  * self,
       else
 	area = *dest;
 
-      if (rect[n].pixmap)
+      if (rect[n].source)
 	{
           cairo_save (cr);
 
-          gdk_cairo_set_source_pixmap (cr, rect[n].pixmap, dest->x, dest->y);
+          cairo_set_source_surface (cr, rect[n].source, dest->x, dest->y);
           cairo_pattern_set_extend (cairo_get_source (cr), CAIRO_EXTEND_REPEAT);
 
           gdk_cairo_rectangle (cr, &area);
@@ -500,7 +490,7 @@ sapwood_pixmap_render_rects (SapwoodPixmap* self,
       SapwoodRect *r = &rect[n];
       r->dest.x -= draw_x;
       r->dest.y -= draw_y;
-      if (r->pixmap && r->mask)
+      if (r->source && r->mask)
 	need_tmp_mask = TRUE;
     }
 
diff --git a/engine/sapwood-pixmap.h b/engine/sapwood-pixmap.h
index d13a627..c7de371 100644
--- a/engine/sapwood-pixmap.h
+++ b/engine/sapwood-pixmap.h
@@ -33,9 +33,9 @@ typedef struct _SapwoodPixmap SapwoodPixmap;
 
 struct _SapwoodRect
 {
-    GdkPixmap *pixmap;
+  cairo_surface_t* source;
   cairo_surface_t* mask;
-    GdkRectangle dest;
+  GdkRectangle     dest;
 };
 
 SapwoodPixmap *sapwood_pixmap_get_for_file (const char *filename,
@@ -54,7 +54,7 @@ gboolean  sapwood_pixmap_get_geometry (SapwoodPixmap *self,
 void      sapwood_pixmap_get_pixmap   (SapwoodPixmap  * self,
                                        gint             x,
                                        gint             y,
-                                       GdkPixmap      **ret_pixmap,
+                                       cairo_surface_t**ret_pixmap,
                                        cairo_surface_t**out_mask) G_GNUC_INTERNAL;
 
 void      sapwood_pixmap_render_rects (SapwoodPixmap* self,
diff --git a/engine/sapwood-style.c b/engine/sapwood-style.c
index 4ceef2a..9f9d692 100644
--- a/engine/sapwood-style.c
+++ b/engine/sapwood-style.c
@@ -399,6 +399,9 @@ draw_gap_image (GtkStyle       *style,
 	  r3.width  = xthickness;
 	  r3.height = height - (gap_x + gap_width);
 	  break;
+        default:
+          g_assert_not_reached ();
+          break;
 	}
 
       if (image->background)
diff --git a/engine/theme-pixbuf.c b/engine/theme-pixbuf.c
index 1126064..fba4f7f 100644
--- a/engine/theme-pixbuf.c
+++ b/engine/theme-pixbuf.c
@@ -329,7 +329,7 @@ theme_pixbuf_render (ThemePixbuf  *theme_pb,
 	component_mask = (COMPONENT_ALL - 1) & ~component_mask;
 
 #define RENDER_COMPONENT(X,Y) do {			           \
-    sapwood_pixmap_get_pixmap (pixmap, X, Y, &rect[n_rect].pixmap, \
+    sapwood_pixmap_get_pixmap (pixmap, X, Y, &rect[n_rect].source, \
                                &rect[n_rect].mask);                \
 							           \
     rect[n_rect].dest.x = dest_x[X];			           \
@@ -433,7 +433,7 @@ theme_pixbuf_render (ThemePixbuf  *theme_pb,
       y += (height - draw_height) / 2;
 
       sapwood_pixmap_get_pixmap (pixmap, 1, 1,
-                                 &rect[0].pixmap, &rect[0].mask);
+                                 &rect[0].source, &rect[0].mask);
       rect[0].dest.x = x;
       rect[0].dest.y = y;
       rect[0].dest.width = pixbuf_width;
diff --git a/tests/test-sapwood-pixmap.c b/tests/test-sapwood-pixmap.c
index 49c1096..0f52324 100644
--- a/tests/test-sapwood-pixmap.c
+++ b/tests/test-sapwood-pixmap.c
@@ -62,7 +62,7 @@ test_larger (void)
       int row = i / 3;
 
       sapwood_pixmap_get_pixmap (pixmap, col, row,
-                                 &rects[i].pixmap, &rects[i].mask);
+                                 &rects[i].source, &rects[i].mask);
 
       rects[i].dest.x = col < 1 ? 0 : col < 2 ? 16 : 200 - 16;
       rects[i].dest.y = row < 1 ? 0 : row < 2 ? 16 : 200 - 16;
@@ -145,7 +145,7 @@ test_larger_masked (void)
       int row = i / 3;
 
       sapwood_pixmap_get_pixmap (pixmap, col, row,
-                                 &rects[i].pixmap, &rects[i].mask);
+                                 &rects[i].source, &rects[i].mask);
 
       rects[i].dest.x = col < 1 ? 0 : col < 2 ? 16 : 200 - 16;
       rects[i].dest.y = row < 1 ? 0 : row < 2 ? 16 : 200 - 16;
@@ -233,7 +233,7 @@ test_larger_masked_offset (void)
       int row = i / 3;
 
       sapwood_pixmap_get_pixmap (pixmap, col, row,
-                                 &rects[i].pixmap, &rects[i].mask);
+                                 &rects[i].source, &rects[i].mask);
 
       rects[i].dest.x = col < 1 ? 0 : col < 2 ? 16 : 200 - 16;
       rects[i].dest.y = row < 1 ? 0 : row < 2 ? 16 : 200 - 16;
@@ -322,7 +322,7 @@ test_crop (void)
       int row = i / 3;
 
       sapwood_pixmap_get_pixmap (pixmap, col, row,
-                                 &rects[i].pixmap, &rects[i].mask);
+                                 &rects[i].source, &rects[i].mask);
 
       rects[i].dest.x = col < 1 ? 0 : col < 2 ? 16 : 70 - 16;
       rects[i].dest.y = row < 1 ? 0 : row < 2 ? 16 : 70 - 16;



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