[sapwood] sapwood_render_rects() expects a cairo_surface_t*



commit a4d5cff931fb2320315a4c3eb557b7f29c886672
Author: Sven Herzberg <herzi gnome-de org>
Date:   Fri Aug 13 11:22:30 2010 +0200

    sapwood_render_rects() expects a cairo_surface_t*
    
    * engine/sapwood-pixmap.c,
    * engine/sapwood-pixmap.h: as a part of the move to cairo,
      sapwood_render_rects() now expects the mask to be passed as a
      cairo_surface_t* instead of a GdkBitmap
    * engine/theme-pixbuf.c: updated to the new API
    * tests/Makefile.am: make sure the new helper code is available to the
      tests
    * tests/test-sapwood-pixmap.c: updated to the new API

 engine/sapwood-pixmap.c     |    6 +--
 engine/sapwood-pixmap.h     |    4 ++-
 engine/theme-pixbuf.c       |   22 ++++++++----
 tests/Makefile.am           |    2 +-
 tests/test-sapwood-pixmap.c |   78 ++++++++++++++++++++++++-------------------
 5 files changed, 65 insertions(+), 47 deletions(-)
---
diff --git a/engine/sapwood-pixmap.c b/engine/sapwood-pixmap.c
index 85aee17..3b1db39 100644
--- a/engine/sapwood-pixmap.c
+++ b/engine/sapwood-pixmap.c
@@ -463,7 +463,7 @@ sapwood_pixmap_render_rects (SapwoodPixmap* self,
                              gint           draw_y,
                              gint           width,
                              gint           height,
-                             GdkBitmap     *mask,
+                             cairo_surface_t     *mask,
                              gint           mask_x,
                              gint           mask_y,
                              gboolean       mask_required,
@@ -489,9 +489,7 @@ sapwood_pixmap_render_rects (SapwoodPixmap* self,
    */
   if (mask_required || (width >= self->width && height >= self->height))
     {
-      cairo_surface_t* mask_surface = mask ? sapwood_create_surface (mask) : NULL;
-      sapwood_pixmap_render_rects_internal (self, cr, draw_x, draw_y, mask_surface, mask_x, mask_y, mask_required, clip_rect, n_rect, rect);
-      cairo_surface_destroy (mask_surface);
+      sapwood_pixmap_render_rects_internal (self, cr, draw_x, draw_y, mask, mask_x, mask_y, mask_required, clip_rect, n_rect, rect);
       cairo_destroy (cr);
       return;
     }
diff --git a/engine/sapwood-pixmap.h b/engine/sapwood-pixmap.h
index 39abf5a..015c55f 100644
--- a/engine/sapwood-pixmap.h
+++ b/engine/sapwood-pixmap.h
@@ -62,7 +62,7 @@ void      sapwood_pixmap_render_rects (SapwoodPixmap* self,
 				      gint          draw_y,
 				      gint          width,
 				      gint          height,
-				      GdkBitmap    *mask,
+				      cairo_surface_t    *mask,
 				      gint          mask_x,
 				      gint          mask_y,
 				      gboolean      mask_required,
@@ -76,3 +76,5 @@ G_GNUC_INTERNAL extern gboolean sapwood_debug_xtraps;
 G_END_DECLS
 
 #endif
+
+/* vim:set et sw=2 cino=t0,f0,(0,{s,>2s,n-1s,^-1s,e2s: */
diff --git a/engine/theme-pixbuf.c b/engine/theme-pixbuf.c
index a94dceb..549fdf3 100644
--- a/engine/theme-pixbuf.c
+++ b/engine/theme-pixbuf.c
@@ -29,6 +29,7 @@
 #include <string.h>
 #include <gdk-pixbuf/gdk-pixbuf.h>
 
+#include "sapwood-cairo.h"
 #include "sapwood-debug.h"
 #include "theme-pixbuf.h"
 
@@ -305,6 +306,8 @@ theme_pixbuf_render (ThemePixbuf  *theme_pb,
 
   if (theme_pb->stretch)
     {
+      cairo_surface_t* mask_surface = NULL;
+
       /* if we do scaling we want to draw at least the whole pixmap */
       draw_width  = MAX(width, pixbuf_width);
       draw_height = MAX(height, pixbuf_height);
@@ -401,21 +404,24 @@ theme_pixbuf_render (ThemePixbuf  *theme_pb,
 	}
       else
 	{
-	  g_object_ref (mask);
+          g_object_ref (mask);
 	  mask_x = x;
 	  mask_y = y;
 	  mask_required = TRUE;
 	}
 
+      mask_surface = sapwood_create_surface (mask);
       sapwood_pixmap_render_rects (pixmap, widget_type,
                                    window, x, y, width, height,
-                                   mask, mask_x, mask_y, mask_required,
+                                   mask_surface, mask_x, mask_y, mask_required,
                                    clip_rect, n_rect, rect);
-
+      cairo_surface_destroy (mask_surface);
       g_object_unref (mask);
     }
   else if (center)
     {
+      cairo_surface_t* mask_surface = NULL;
+
       /* when centering don't expand beyond pixbuf size */
       draw_width = MIN(width, pixbuf_width);
       draw_height = MIN(height, pixbuf_height);
@@ -438,17 +444,19 @@ theme_pixbuf_render (ThemePixbuf  *theme_pb,
 	  mask = gdk_pixmap_new (NULL, pixbuf_width, pixbuf_height, 1);
 	  mask_x = 0;
 	  mask_y = 0;
+          mask_surface = sapwood_create_surface (mask);
+          g_object_unref (mask);
 	}
       else if (mask)
-	g_object_ref (mask);
+        mask_surface = sapwood_create_surface (mask);
 
       sapwood_pixmap_render_rects (pixmap, widget_type,
                                    window, x, y, draw_width, draw_height,
-                                   mask, mask_x, mask_y, FALSE,
+                                   mask_surface, mask_x, mask_y, FALSE,
                                    clip_rect, 1, rect);
 
-      if (mask)
-	g_object_unref (mask);
+      if (mask_surface)
+        cairo_surface_destroy (mask_surface);
     }
   else /* tile? */
     {
diff --git a/tests/Makefile.am b/tests/Makefile.am
index bb9bfce..734d20c 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -1,6 +1,6 @@
 include $(top_srcdir)/Makefile.decl
 
-AM_CPPFLAGS=-I$(top_srcdir)/protocol $(GTK_CFLAGS) $(WARN_CFLAGS)
+AM_CPPFLAGS=-I$(top_srcdir)/protocol -I$(top_srcdir)/sapwood $(GTK_CFLAGS) $(WARN_CFLAGS)
 LDADD=$(top_builddir)/engine/libsapwood-client.la
 
 check: large-window.gtkrc
diff --git a/tests/test-sapwood-pixmap.c b/tests/test-sapwood-pixmap.c
index 40f6ce0..5bfcbe8 100644
--- a/tests/test-sapwood-pixmap.c
+++ b/tests/test-sapwood-pixmap.c
@@ -27,6 +27,7 @@
 #include <gdk/gdkx.h>       /* GDK_DISPLAY_XDISPLAY() */
 #include <sapwood-pixmap.h>
 
+#include "sapwood-cairo.h"
 #include "test-framework.h"
 
 static void
@@ -110,16 +111,17 @@ test_larger (void)
 static void
 test_larger_masked (void)
 {
-  SapwoodPixmap* pixmap;
-  SapwoodRect    rects[9];
-  GdkDrawable  * drawable = NULL;
-  GdkPixbuf    * result;
-  GdkPixbuf    * expected;
-  GdkBitmap    * mask;
-  GError       * error = NULL;
-  char           abspath[PATH_MAX + 1];
-  int            code;
-  int            i;
+  cairo_surface_t* mask_surface;
+  SapwoodPixmap  * pixmap;
+  SapwoodRect      rects[9];
+  GdkDrawable    * drawable = NULL;
+  GdkPixbuf      * result;
+  GdkPixbuf      * expected;
+  GdkBitmap      * mask;
+  GError         * error = NULL;
+  char             abspath[PATH_MAX + 1];
+  int              code;
+  int              i;
 
   if (!realpath (TOP_SRCDIR G_DIR_SEPARATOR_S "tests" G_DIR_SEPARATOR_S "test-source-alpha75.png", abspath))
     {
@@ -151,6 +153,8 @@ test_larger_masked (void)
 
   mask = gdk_pixmap_new (NULL, 200, 200, 1);
   g_test_queue_unref (mask);
+  mask_surface = sapwood_create_surface (mask);
+  g_test_queue_destroy ((GFreeFunc) cairo_surface_destroy, mask_surface);
 
   gdk_error_trap_push ();
 
@@ -159,7 +163,7 @@ test_larger_masked (void)
                                drawable,
                                0, 0,
                                200, 200,
-                               mask,
+                               mask_surface,
                                0, 0,
                                TRUE,
                                NULL,
@@ -192,16 +196,17 @@ test_larger_masked (void)
 static void
 test_larger_masked_offset (void)
 {
-  SapwoodPixmap* pixmap;
-  SapwoodRect    rects[9];
-  GdkDrawable  * drawable = NULL;
-  GdkPixbuf    * result;
-  GdkPixbuf    * expected;
-  GdkBitmap    * mask;
-  GError       * error = NULL;
-  char           abspath[PATH_MAX + 1];
-  int            code;
-  int            i;
+  cairo_surface_t* mask_surface;
+  SapwoodPixmap  * pixmap;
+  SapwoodRect      rects[9];
+  GdkDrawable    * drawable = NULL;
+  GdkPixbuf      * result;
+  GdkPixbuf      * expected;
+  GdkBitmap      * mask;
+  GError         * error = NULL;
+  char             abspath[PATH_MAX + 1];
+  int              code;
+  int              i;
 
   if (!realpath (TOP_SRCDIR G_DIR_SEPARATOR_S "tests" G_DIR_SEPARATOR_S "test-source-alpha75.png", abspath))
     {
@@ -233,6 +238,8 @@ test_larger_masked_offset (void)
 
   mask = gdk_pixmap_new (NULL, 100, 100, 1);
   g_test_queue_unref (mask);
+  mask_surface = sapwood_create_surface (mask);
+  g_test_queue_destroy ((GFreeFunc) cairo_surface_destroy, mask_surface);
 
   gdk_error_trap_push ();
 
@@ -241,7 +248,7 @@ test_larger_masked_offset (void)
                                drawable,
                                0, 0,
                                200, 200,
-                               mask,
+                               mask_surface,
                                -100, -100,
                                TRUE,
                                NULL,
@@ -274,17 +281,18 @@ test_larger_masked_offset (void)
 static void
 test_crop (void)
 {
-  SapwoodPixmap* pixmap;
-  SapwoodRect    rects[9];
-  GdkRectangle   clip_rect = {0, 0, 50, 50};
-  GdkDrawable  * drawable = NULL;
-  GdkPixbuf    * result;
-  GdkPixbuf    * expected;
-  GdkBitmap    * mask;
-  GError       * error = NULL;
-  char           abspath[PATH_MAX + 1];
-  int            code;
-  int            i;
+  cairo_surface_t* mask_surface;
+  SapwoodPixmap  * pixmap;
+  SapwoodRect      rects[9];
+  GdkRectangle     clip_rect = {0, 0, 50, 50};
+  GdkDrawable    * drawable = NULL;
+  GdkPixbuf      * result;
+  GdkPixbuf      * expected;
+  GdkBitmap      * mask;
+  GError         * error = NULL;
+  char             abspath[PATH_MAX + 1];
+  int              code;
+  int              i;
 
   if (!realpath (TOP_SRCDIR G_DIR_SEPARATOR_S "tests" G_DIR_SEPARATOR_S "test-source-alpha75.png", abspath))
     {
@@ -316,6 +324,8 @@ test_crop (void)
 
   mask = gdk_pixmap_new (NULL, 50, 50, 1);
   g_test_queue_unref (mask);
+  mask_surface = sapwood_create_surface (mask);
+  g_test_queue_destroy ((GFreeFunc) cairo_surface_destroy, mask_surface);
 
   gdk_error_trap_push ();
 
@@ -324,7 +334,7 @@ test_crop (void)
                                drawable,
                                0, 0,
                                50, 50,
-                               mask,
+                               mask_surface,
                                0, 0,
                                FALSE,
                                &clip_rect,



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