[sapwood] rewrite the remainder of the internal rendering to cairo



commit 1298ec1f6723698f08240c9bae02a7973f18c80b
Author: Sven Herzberg <herzi gnome-de org>
Date:   Thu Aug 5 18:58:52 2010 +0200

    rewrite the remainder of the internal rendering to cairo
    
    * engine/sapwood-pixmap.c: rewrite the rest of the rectangle rendering
      to cairo

 engine/sapwood-pixmap.c |   71 ++++++++++++++++++++++++++++------------------
 1 files changed, 43 insertions(+), 28 deletions(-)
---
diff --git a/engine/sapwood-pixmap.c b/engine/sapwood-pixmap.c
index 6bc2485..acd838d 100644
--- a/engine/sapwood-pixmap.c
+++ b/engine/sapwood-pixmap.c
@@ -137,6 +137,7 @@ sapwood_pixmap_get_for_file (const char *filename,
 	  {
 	    gdk_error_trap_push ();
 	    pixmap = gdk_pixmap_foreign_new (rep.pixmap[i][j]);
+            gdk_drawable_set_colormap (pixmap, gdk_screen_get_system_colormap (gdk_screen_get_default ()));
 
             if (sapwood_debug_xtraps)
               gdk_flush ();
@@ -287,8 +288,8 @@ sapwood_pixmap_render_rects_internal (SapwoodPixmap *self,
                                       gint           n_rect,
                                       SapwoodRect   *rect)
 {
-  static GdkGC *draw_gc = NULL;
-  GdkGCValues   values;
+  cairo_t     * mask_cr = NULL;
+  cairo_t     * cr;
   gint          xofs;
   gint          yofs;
   gint          n;
@@ -301,9 +302,9 @@ sapwood_pixmap_render_rects_internal (SapwoodPixmap *self,
 
   if (mask)
     {
-      cairo_t* cr = gdk_cairo_create (mask);
-      cairo_set_operator (cr, CAIRO_OPERATOR_SOURCE);
-      cairo_translate (cr, mask_x, mask_y);
+      mask_cr = gdk_cairo_create (mask);
+      cairo_set_operator (mask_cr, CAIRO_OPERATOR_SOURCE);
+      cairo_translate (mask_cr, -xofs, -yofs);
 
       for (n = 0; n < n_rect; n++)
 	{
@@ -320,28 +321,17 @@ sapwood_pixmap_render_rects_internal (SapwoodPixmap *self,
 
 	  if (rect[n].pixmap && rect[n].pixmask)
 	    {
-              gdk_cairo_set_source_pixmap (cr, rect[n].pixmask, area.x, area.y);
-              cairo_pattern_set_extend (cairo_get_source (cr), CAIRO_EXTEND_REPEAT);
-              gdk_cairo_rectangle (cr, &area);
-              cairo_fill (cr);
+              gdk_cairo_set_source_pixmap (mask_cr, rect[n].pixmask, area.x, area.y);
+              cairo_pattern_set_extend (cairo_get_source (mask_cr), CAIRO_EXTEND_REPEAT);
+              gdk_cairo_rectangle (mask_cr, &area);
+              cairo_fill (mask_cr);
 
 	      have_mask = TRUE;
 	    }
 	}
-      cairo_destroy (cr);
     }
 
-  if (!draw_gc)
-    {
-      values.fill = GDK_TILED;
-      draw_gc = gdk_gc_new_with_values (draw, &values, GDK_GC_FILL);
-    }
-
-  values.clip_mask = have_mask ? mask : NULL;
-  values.clip_x_origin = xofs;
-  values.clip_y_origin = yofs;
-  gdk_gc_set_values (draw_gc, &values, GDK_GC_CLIP_MASK|GDK_GC_CLIP_X_ORIGIN|GDK_GC_CLIP_Y_ORIGIN);
-
+  cr = gdk_cairo_create (draw);
   for (n = 0; n < n_rect; n++)
     {
       /* const */ GdkRectangle *dest = &rect[n].dest;
@@ -351,20 +341,45 @@ sapwood_pixmap_render_rects_internal (SapwoodPixmap *self,
 	{
 	  if (!gdk_rectangle_intersect (dest, clip_rect, &area))
 	    continue;
-	}	  
+	}
       else
 	area = *dest;
 
       if (rect[n].pixmap)
 	{
-	  values.tile = rect[n].pixmap;
-	  values.ts_x_origin = dest->x;
-	  values.ts_y_origin = dest->y;
-	  gdk_gc_set_values (draw_gc, &values, GDK_GC_TILE|GDK_GC_TS_X_ORIGIN|GDK_GC_TS_Y_ORIGIN);
-
-	  gdk_draw_rectangle (draw, draw_gc, TRUE, area.x, area.y, area.width, area.height);
+          cairo_save (cr);
+
+          gdk_cairo_set_source_pixmap (cr, rect[n].pixmap, dest->x, dest->y);
+          cairo_pattern_set_extend (cairo_get_source (cr), CAIRO_EXTEND_REPEAT);
+
+          gdk_cairo_rectangle (cr, &area);
+          cairo_clip (cr);
+          if (mask_cr)
+            {
+              cairo_pattern_t* pattern;
+              cairo_matrix_t   matrix;
+
+              cairo_matrix_init_identity (&matrix);
+              cairo_matrix_init_translate (&matrix, -xofs, -yofs);
+              pattern = cairo_pattern_create_for_surface (cairo_get_target (mask_cr));
+              cairo_pattern_set_matrix (pattern, &matrix);
+              cairo_mask (cr, pattern);
+              cairo_pattern_destroy (pattern);
+            }
+          else
+            {
+              cairo_paint (cr);
+            }
+
+          cairo_restore (cr);
 	}
     }
+  cairo_destroy (cr);
+
+  if (mask_cr)
+    {
+      cairo_destroy (mask_cr);
+    }
 }
 
 static void



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