[gtk+/rendering-cleanup: 61/140] ruler: Make the backing store use a surface



commit b824fb5642bd0b9d4057cc407808a584c3b4a1a6
Author: Benjamin Otte <otte redhat com>
Date:   Tue Aug 24 16:27:55 2010 +0200

    ruler: Make the backing store use a surface

 gtk/gtkruler.c |   90 ++++++++++++++++++++++++++------------------------------
 1 files changed, 42 insertions(+), 48 deletions(-)
---
diff --git a/gtk/gtkruler.c b/gtk/gtkruler.c
index 1e32dc6..ba001a8 100644
--- a/gtk/gtkruler.c
+++ b/gtk/gtkruler.c
@@ -46,7 +46,7 @@ struct _GtkRulerPriv
   GtkOrientation        orientation;
   GtkRulerMetric       *metric;
 
-  GdkPixmap            *backing_store;
+  cairo_surface_t      *backing_store;
 
   gint                  slider_size;
   gint                  xsrc;
@@ -500,7 +500,7 @@ gtk_ruler_unrealize (GtkWidget *widget)
 
   if (priv->backing_store)
     {
-      g_object_unref (priv->backing_store);
+      cairo_surface_destroy (priv->backing_store);
       priv->backing_store = NULL;
     }
 
@@ -531,6 +531,10 @@ gtk_ruler_size_allocate (GtkWidget     *widget,
 			 GtkAllocation *allocation)
 {
   GtkRuler *ruler = GTK_RULER (widget);
+  gboolean resized;
+
+  resized = (widget->allocation.width != allocation->width ||
+             widget->allocation.height != allocation->height);
 
   widget->allocation = *allocation;
 
@@ -540,7 +544,8 @@ gtk_ruler_size_allocate (GtkWidget     *widget,
 			      allocation->x, allocation->y,
 			      allocation->width, allocation->height);
 
-      gtk_ruler_make_pixmap (ruler);
+      if (resized)
+        gtk_ruler_make_pixmap (ruler);
     }
 }
 
@@ -584,8 +589,8 @@ gtk_ruler_expose (GtkWidget      *widget,
       gtk_ruler_draw_ticks (ruler);
       
       cr = gdk_cairo_create (widget->window);
-      gdk_cairo_set_source_pixmap (cr, priv->backing_store, 0, 0);
-      gdk_cairo_rectangle (cr, &event->area);
+      cairo_set_source_surface (cr, priv->backing_store, 0, 0);
+      gdk_cairo_region (cr, event->region);
       cairo_fill (cr);
       cairo_destroy (cr);
       
@@ -600,25 +605,16 @@ gtk_ruler_make_pixmap (GtkRuler *ruler)
 {
   GtkRulerPriv *priv = ruler->priv;
   GtkWidget *widget;
-  gint width;
-  gint height;
 
   widget = GTK_WIDGET (ruler);
 
   if (priv->backing_store)
-    {
-      gdk_drawable_get_size (priv->backing_store, &width, &height);
-      if ((width == widget->allocation.width) &&
-	  (height == widget->allocation.height))
-	return;
-
-      g_object_unref (priv->backing_store);
-    }
+    cairo_surface_destroy (priv->backing_store);
 
-  priv->backing_store = gdk_pixmap_new (widget->window,
-                                        widget->allocation.width,
-                                        widget->allocation.height,
-                                        -1);
+  priv->backing_store = gdk_window_create_similar_surface (widget->window,
+                                                           CAIRO_CONTENT_COLOR,
+                                                           widget->allocation.width,
+                                                           widget->allocation.height);
 
   priv->xsrc = 0;
   priv->ysrc = 0;
@@ -674,17 +670,17 @@ gtk_ruler_real_draw_ticks (GtkRuler *ruler)
 
 #define DETAILE(private) (priv->orientation == GTK_ORIENTATION_HORIZONTAL ? "hruler" : "vruler");
 
-  gtk_paint_box (widget->style, priv->backing_store,
-		 GTK_STATE_NORMAL, GTK_SHADOW_OUT,
-		 NULL, widget,
-                 priv->orientation == GTK_ORIENTATION_HORIZONTAL ?
-                 "hruler" : "vruler",
-		 0, 0,
-		 widget->allocation.width, widget->allocation.height);
-
-  cr = gdk_cairo_create (priv->backing_store);
+  cr = cairo_create (priv->backing_store);
   gdk_cairo_set_source_color (cr, &widget->style->fg[widget->state]);
 
+  gtk_cairo_paint_box (widget->style, cr,
+                       GTK_STATE_NORMAL, GTK_SHADOW_OUT,
+                       widget,
+                       priv->orientation == GTK_ORIENTATION_HORIZONTAL ?
+                       "hruler" : "vruler",
+                       0, 0,
+                       widget->allocation.width, widget->allocation.height);
+
   if (priv->orientation == GTK_ORIENTATION_HORIZONTAL)
     {
       cairo_rectangle (cr,
@@ -797,15 +793,14 @@ gtk_ruler_real_draw_ticks (GtkRuler *ruler)
                   pango_layout_set_text (layout, unit_str, -1);
                   pango_layout_get_extents (layout, &logical_rect, NULL);
 
-                  gtk_paint_layout (widget->style,
-                                    priv->backing_store,
-                                    gtk_widget_get_state (widget),
-                                    FALSE,
-                                    NULL,
-                                    widget,
-                                    "hruler",
-                                    pos + 2, ythickness + PANGO_PIXELS (logical_rect.y - digit_offset),
-                                    layout);
+                  gtk_cairo_paint_layout (widget->style,
+                                          cr,
+                                          gtk_widget_get_state (widget),
+                                          FALSE,
+                                          widget,
+                                          "hruler",
+                                          pos + 2, ythickness + PANGO_PIXELS (logical_rect.y - digit_offset),
+                                          layout);
                 }
               else
                 {
@@ -814,16 +809,15 @@ gtk_ruler_real_draw_ticks (GtkRuler *ruler)
                       pango_layout_set_text (layout, unit_str + j, 1);
                       pango_layout_get_extents (layout, NULL, &logical_rect);
 
-                      gtk_paint_layout (widget->style,
-                                        priv->backing_store,
-                                        gtk_widget_get_state (widget),
-                                        FALSE,
-                                        NULL,
-                                        widget,
-                                        "vruler",
-                                        xthickness + 1,
-                                        pos + digit_height * j + 2 + PANGO_PIXELS (logical_rect.y - digit_offset),
-                                        layout);
+                      gtk_cairo_paint_layout (widget->style,
+                                              cr,
+                                              gtk_widget_get_state (widget),
+                                              FALSE,
+                                              widget,
+                                              "vruler",
+                                              xthickness + 1,
+                                              pos + digit_height * j + 2 + PANGO_PIXELS (logical_rect.y - digit_offset),
+                                              layout);
                     }
                 }
 	    }
@@ -881,7 +875,7 @@ gtk_ruler_real_draw_pos (GtkRuler *ruler)
 	  if (priv->backing_store) {
             cairo_t *cr = gdk_cairo_create (widget->window);
 
-            gdk_cairo_set_source_pixmap (cr, priv->backing_store, 0, 0);
+            cairo_set_source_surface (cr, priv->backing_store, 0, 0);
             cairo_rectangle (cr, priv->xsrc, priv->ysrc, bs_width, bs_height);
             cairo_fill (cr);
 



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