[gtk+/rendering-cleanup: 51/89] image: Use Cairo instead of gdk_draw_drawable()



commit b4c84dc443376576e8dd1b7541c19cec86681615
Author: Benjamin Otte <otte redhat com>
Date:   Wed Jul 14 19:46:58 2010 +0200

    image: Use Cairo instead of gdk_draw_drawable()

 gtk/gtkimage.c |   43 +++++++++++++++++++++++++------------------
 1 files changed, 25 insertions(+), 18 deletions(-)
---
diff --git a/gtk/gtkimage.c b/gtk/gtkimage.c
index 0ce785a..2e047eb 100644
--- a/gtk/gtkimage.c
+++ b/gtk/gtkimage.c
@@ -1917,12 +1917,6 @@ gtk_image_expose (GtkWidget      *widget,
           break;
         }
 
-      if (mask)
-	{
-	  gdk_gc_set_clip_mask (widget->style->black_gc, mask);
-	  gdk_gc_set_clip_origin (widget->style->black_gc, mask_x, mask_y);
-	}
-
       if (rectangle_intersect_even (&area, &image_bound))
         {
           if (pixbuf)
@@ -1968,15 +1962,34 @@ gtk_image_expose (GtkWidget      *widget,
             }
           else
             {
+              cairo_t *cr;
+              cairo_pattern_t *mask_pattern;
+
               switch (image->storage_type)
                 {
                 case GTK_IMAGE_PIXMAP:
-                  gdk_draw_drawable (widget->window,
-                                     widget->style->black_gc,
-                                     image->data.pixmap.pixmap,
-                                     image_bound.x - x, image_bound.y - y,
-                                     image_bound.x, image_bound.y,
-                                     image_bound.width, image_bound.height);
+                  cr = gdk_cairo_create (widget->window);
+
+                  if (mask)
+                    {
+                      /* hack to get the mask pattern */
+                      gdk_cairo_set_source_pixmap (cr, mask, mask_x, mask_y);
+                      mask_pattern = cairo_get_source (cr);
+                      cairo_pattern_reference (mask_pattern);
+
+                      gdk_cairo_set_source_pixmap (cr, image->data.pixmap.pixmap, x, y);
+                      gdk_cairo_rectangle (cr, &image_bound);
+                      cairo_clip (cr);
+                      cairo_mask (cr, mask_pattern);
+                    }
+                  else 
+                    {
+                      gdk_cairo_set_source_pixmap (cr, image->data.pixmap.pixmap, x, y);
+                      gdk_cairo_rectangle (cr, &image_bound);
+                      cairo_fill (cr);
+                    }
+
+                  cairo_destroy (cr);
                   break;
               
                 case GTK_IMAGE_PIXBUF:
@@ -1992,12 +2005,6 @@ gtk_image_expose (GtkWidget      *widget,
             }
         } /* if rectangle intersects */      
 
-      if (mask)
-        {
-          gdk_gc_set_clip_mask (widget->style->black_gc, NULL);
-          gdk_gc_set_clip_origin (widget->style->black_gc, 0, 0);
-        }
-      
       if (pixbuf)
 	g_object_unref (pixbuf);
 



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