[gtk+/picture: 22/22] image: Only redraw changed parts of the picture, not the full picture



commit 1c444548543720351f9674ec7cea3504d73cdad6
Author: Benjamin Otte <otte redhat com>
Date:   Mon Feb 14 19:11:00 2011 +0100

    image: Only redraw changed parts of the picture, not the full picture

 gtk/gtkimage.c |   58 +++++++++++++++++++++++++++++++++----------------------
 1 files changed, 35 insertions(+), 23 deletions(-)
---
diff --git a/gtk/gtkimage.c b/gtk/gtkimage.c
index 380c18c..fb2a77b 100644
--- a/gtk/gtkimage.c
+++ b/gtk/gtkimage.c
@@ -851,12 +851,45 @@ gtk_image_set_from_file   (GtkImage    *image,
 }
 
 static void
+gtk_image_compute_picture_offset (GtkImage *image,
+                                  int      *xoffset,
+                                  int      *yoffset)
+{
+  GtkImagePrivate *priv = image->priv;
+  GtkMisc *misc = GTK_MISC (image);
+  GtkWidget *widget = GTK_WIDGET (image);
+  gint xpad, ypad;
+  gfloat xalign, yalign;
+
+  gtk_misc_get_alignment (misc, &xalign, &yalign);
+  gtk_misc_get_padding (misc, &xpad, &ypad);
+
+  if (gtk_widget_get_direction (widget) != GTK_TEXT_DIR_LTR)
+    xalign = 1.0 - xalign;
+
+  *xoffset = floor (xpad + ((gtk_widget_get_allocated_width (widget) - gdk_picture_get_width (priv->picture)) * xalign));
+  *yoffset = floor (ypad + ((gtk_widget_get_allocated_height (widget) - gdk_picture_get_height (priv->picture)) * yalign));
+}
+
+static void
 gtk_image_picture_changed (GdkPicture           *picture,
                            const cairo_region_t *region,
                            GtkImage             *image)
 {
-  /* XXX: take region into account */
-  gtk_widget_queue_draw (GTK_WIDGET (image));
+  int x, y;
+
+  gtk_image_compute_picture_offset (image, &x, &y);
+
+  if (x || y)
+    {
+      cairo_region_t *copy = cairo_region_copy (region);
+
+      cairo_region_translate (copy, x, y);
+      gtk_widget_queue_draw_region (GTK_WIDGET (image), copy);
+      cairo_region_destroy (copy);
+    }
+  else
+    gtk_widget_queue_draw_region (GTK_WIDGET (image), region);
 }
 
 static void
@@ -1436,27 +1469,6 @@ gtk_image_unrealize (GtkWidget *widget)
   GTK_WIDGET_CLASS (gtk_image_parent_class)->unrealize (widget);
 }
 
-static void
-gtk_image_compute_picture_offset (GtkImage *image,
-                                  int      *xoffset,
-                                  int      *yoffset)
-{
-  GtkImagePrivate *priv = image->priv;
-  GtkMisc *misc = GTK_MISC (image);
-  GtkWidget *widget = GTK_WIDGET (image);
-  gint xpad, ypad;
-  gfloat xalign, yalign;
-
-  gtk_misc_get_alignment (misc, &xalign, &yalign);
-  gtk_misc_get_padding (misc, &xpad, &ypad);
-
-  if (gtk_widget_get_direction (widget) != GTK_TEXT_DIR_LTR)
-    xalign = 1.0 - xalign;
-
-  *xoffset = floor (xpad + ((gtk_widget_get_allocated_width (widget) - gdk_picture_get_width (priv->picture)) * xalign));
-  *yoffset = floor (ypad + ((gtk_widget_get_allocated_height (widget) - gdk_picture_get_height (priv->picture)) * yalign));
-}
-
 static gint
 gtk_image_draw (GtkWidget *widget,
                 cairo_t   *cr)



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