hippo-canvas r7258 - in trunk: common/hippo linux/hippo



Author: otaylor
Date: Thu May  8 17:26:58 2008
New Revision: 7258
URL: http://svn.gnome.org/viewvc/hippo-canvas?rev=7258&view=rev

Log:
Fix resizing causing unnecessary repainting 
 (http://bugzilla.mugshot.org/show_bug.cgi?id=1194)

hippo-canvas-helper.c hippo-canvas.c: Avoid queueing a complete redraw
  at the GTK+ layer whenever we resize; we'll handle invalidatoins
  internally.

hippo-canvas-box.c: Queue repaints when items move or are resized.

hippo-canvas-box.c: hippo-canvas-image.c hippo-canvas-text.c:
  hippo_canvas_item_emit_request_painted() will no longer automatically
  trigger a redraw; use 


Modified:
   trunk/common/hippo/hippo-canvas-box.c
   trunk/common/hippo/hippo-canvas-image.c
   trunk/common/hippo/hippo-canvas-text.c
   trunk/linux/hippo/hippo-canvas-helper.c
   trunk/linux/hippo/hippo-canvas.c

Modified: trunk/common/hippo/hippo-canvas-box.c
==============================================================================
--- trunk/common/hippo/hippo-canvas-box.c	(original)
+++ trunk/common/hippo/hippo-canvas-box.c	Thu May  8 17:26:58 2008
@@ -149,6 +149,8 @@
 
     guint ref_count;
     
+    HippoCanvasBox *box; /* back-pointer to parent */
+
     /* allocated x, y */
     int              x;
     int              y;
@@ -829,11 +831,13 @@
                               GParamSpec      *pspec)
 {
     HippoCanvasBox *box;
+    gboolean need_repaint;
     gboolean need_resize;
     
     box = HIPPO_CANVAS_BOX(object);
 
     need_resize = TRUE; /* for most of them it's true */
+    need_repaint = TRUE; /* for most of them it's true */
     switch (prop_id) {
     case PROP_ID:
         {
@@ -867,6 +871,7 @@
         break;
     case PROP_ORIENTATION:
         box->orientation = g_value_get_enum(value);
+        need_repaint = FALSE;
         break;
     case PROP_PADDING_TOP:
         {
@@ -981,9 +986,11 @@
         break;        
     case PROP_BOX_WIDTH:
         box->box_width = g_value_get_int(value);
+        need_repaint = FALSE;
         break;
     case PROP_BOX_HEIGHT:
         box->box_height = g_value_get_int(value);
+        need_repaint = FALSE;
         break;
     case PROP_XALIGN:
         box->x_align = g_value_get_enum(value);
@@ -1017,6 +1024,7 @@
         break;
     case PROP_SPACING:
         box->spacing = g_value_get_int(value);
+        need_repaint = FALSE;
         break;
     case PROP_COLOR:
         box->color_rgba = g_value_get_uint(value);
@@ -1054,6 +1062,7 @@
             hippo_canvas_item_emit_tooltip_changed(HIPPO_CANVAS_ITEM(box));
         }
         need_resize = FALSE;
+        need_repaint = FALSE;
         break;
     case PROP_DEBUG_NAME:
         {
@@ -1066,12 +1075,15 @@
             box->debug_name = g_strdup(new_name);
         }
         need_resize = FALSE;
+        need_repaint = FALSE;
         break;
     default:
         G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
         break;
     }
 
+    if (need_repaint)
+        hippo_canvas_item_emit_paint_needed(HIPPO_CANVAS_ITEM(box), 0, 0, -1, -1);
     if (need_resize)
         hippo_canvas_item_emit_request_changed(HIPPO_CANVAS_ITEM(box));
 }
@@ -1337,8 +1349,8 @@
 
     if (resize_needed)
         hippo_canvas_item_emit_request_changed(HIPPO_CANVAS_ITEM(box));
-    else
-        hippo_canvas_item_emit_paint_needed(HIPPO_CANVAS_ITEM(box), 0, 0, -1, -1);
+
+    hippo_canvas_item_emit_paint_needed(HIPPO_CANVAS_ITEM(box), 0, 0, -1, -1);
 }
 
 static void
@@ -1467,6 +1479,7 @@
     clear_style(box);
     hippo_canvas_context_emit_style_changed(HIPPO_CANVAS_CONTEXT(box), TRUE);
     hippo_canvas_item_emit_request_changed(HIPPO_CANVAS_ITEM(box));
+    hippo_canvas_item_emit_paint_needed(HIPPO_CANVAS_ITEM(box), 0, 0, -1, -1);
 }
 
 static void
@@ -3110,15 +3123,28 @@
 {
     BoxChildPrivate *private = (BoxChildPrivate *)child;
     gboolean child_moved;
+    gboolean child_resized;
+    int old_width, old_height;
 
     if (child->item == NULL)
         return;
 
+    hippo_canvas_item_get_allocation(child->item, &old_width, &old_height);
+    
     child_moved = x != private->x || y != private->y;
+    child_resized = width != old_width || height != old_height;
+    
+    if ((child_moved || child_resized) && (old_width != 0 || old_height != 0))
+        hippo_canvas_item_emit_paint_needed(HIPPO_CANVAS_ITEM(private->box),
+                                            private->x, private->y, old_width, old_height);
 
     private->x = x;
     private->y = y;
 
+    if ((child_moved || child_resized) && (width != 0 || height != 0))
+        hippo_canvas_item_emit_paint_needed(HIPPO_CANVAS_ITEM(private->box),
+                                            x, y, width, height);
+
     hippo_canvas_item_allocate(child->item,
                                width, height,
                                origin_changed || child_moved);
@@ -3305,7 +3331,7 @@
         
         for (link = box->children; link != NULL; link = link->next) {
             HippoCanvasBoxChild *child = link->data;
-            hippo_canvas_item_allocate(child->item, 0, 0, FALSE);
+            hippo_canvas_box_child_allocate(child, 0, 0, 0, 0, origin_changed);
         }
     } else {
         /* Allocate fixed children their natural size and invisible
@@ -3314,11 +3340,12 @@
         for (link = box->children; link != NULL; link = link->next) {
             HippoCanvasBoxChild *child = link->data;
             if (!child->visible) {
-                hippo_canvas_item_allocate(child->item, 0, 0, FALSE);
+                hippo_canvas_box_child_allocate(child, 0, 0, 0, 0, origin_changed);
             } else if (child->fixed) {
+                BoxChildPrivate *private = (BoxChildPrivate *)child;
                 int width, height;
                 request_child_natural_size(child, &width, &height);
-                hippo_canvas_item_allocate(child->item, width, height, origin_changed);
+                hippo_canvas_box_child_allocate(child, private->x, private->y, width, height, origin_changed);
             } else {
                 continue;
             }
@@ -3939,6 +3966,7 @@
     c->public.item = child;
     set_flags(&c->public, flags);
     c->public.visible = TRUE;
+    c->box = box;
     c->min_width = -1;
     c->min_height = -1;
     c->height_request_for_width = -1;

Modified: trunk/common/hippo/hippo-canvas-image.c
==============================================================================
--- trunk/common/hippo/hippo-canvas-image.c	(original)
+++ trunk/common/hippo/hippo-canvas-image.c	Thu May  8 17:26:58 2008
@@ -285,6 +285,7 @@
             if (w != image->scale_width) {
                 image->scale_width = w;
                 hippo_canvas_item_emit_request_changed(HIPPO_CANVAS_ITEM(image));
+                hippo_canvas_item_emit_paint_needed(HIPPO_CANVAS_ITEM(image), 0, 0, -1, -1);
             } 
         }
         break;
@@ -294,6 +295,7 @@
             if (h != image->scale_height) {
                 image->scale_height = h;
                 hippo_canvas_item_emit_request_changed(HIPPO_CANVAS_ITEM(image));
+                hippo_canvas_item_emit_paint_needed(HIPPO_CANVAS_ITEM(image), 0, 0, -1, -1);
             }
         }
         break;

Modified: trunk/common/hippo/hippo-canvas-text.c
==============================================================================
--- trunk/common/hippo/hippo-canvas-text.c	(original)
+++ trunk/common/hippo/hippo-canvas-text.c	Thu May  8 17:26:58 2008
@@ -233,6 +233,7 @@
                 g_free(text->text);
                 text->text = g_strdup(new_text);
                 hippo_canvas_item_emit_request_changed(HIPPO_CANVAS_ITEM(text));
+                hippo_canvas_item_emit_paint_needed(HIPPO_CANVAS_ITEM(text), 0, 0, -1, -1);
             }
         }
         break;
@@ -245,6 +246,7 @@
                 pango_attr_list_unref(text->attributes);            
             text->attributes = attrs;
             hippo_canvas_item_emit_request_changed(HIPPO_CANVAS_ITEM(text));
+            hippo_canvas_item_emit_paint_needed(HIPPO_CANVAS_ITEM(text), 0, 0, -1, -1);
         }
         break;
     case PROP_MARKUP:
@@ -271,10 +273,12 @@
     case PROP_FONT_SCALE:
         text->font_scale = g_value_get_double(value);
         hippo_canvas_item_emit_request_changed(HIPPO_CANVAS_ITEM(text));
+        hippo_canvas_item_emit_paint_needed(HIPPO_CANVAS_ITEM(text), 0, 0, -1, -1);
         break;
     case PROP_SIZE_MODE:
         text->size_mode = g_value_get_enum(value);
         hippo_canvas_item_emit_request_changed(HIPPO_CANVAS_ITEM(text));
+        hippo_canvas_item_emit_paint_needed(HIPPO_CANVAS_ITEM(text), 0, 0, -1, -1);
         break;
     default:
         G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
@@ -326,8 +330,10 @@
      * so we have to queue a size change when the context
      * is set.
      */
-    if (changed)
+    if (changed) {
         hippo_canvas_item_emit_request_changed(HIPPO_CANVAS_ITEM(item));
+        hippo_canvas_item_emit_paint_needed(HIPPO_CANVAS_ITEM(item), 0, 0, -1, -1);
+    }
 }
 
 

Modified: trunk/linux/hippo/hippo-canvas-helper.c
==============================================================================
--- trunk/linux/hippo/hippo-canvas-helper.c	(original)
+++ trunk/linux/hippo/hippo-canvas-helper.c	Thu May  8 17:26:58 2008
@@ -95,6 +95,8 @@
     guint tooltip_timeout_id;
     int last_window_x;
     int last_window_y;
+
+    int last_allocated_border;
     
     GSList *widget_items;
 
@@ -427,10 +429,23 @@
     /* g_debug("gtk allocate on canvas root %p canvas %p", helper->root, canvas); */
 
     if (helper->root != NULL) {
+        int border_width = GTK_CONTAINER(helper->widget)->border_width;
+        int child_width = allocation->width - border_width * 2;
+        int child_height = allocation->height - border_width * 2;
+        int old_width, old_height;
+        gboolean border_changed;
+        
+        hippo_canvas_item_get_allocation(helper->root, &old_width, &old_height);
+
+        border_changed = border_width = helper->last_allocated_border;
+        helper->last_allocated_border = border_width;
+
+        if (child_width != old_width || child_height != old_height || border_changed)
+            gtk_widget_queue_draw(helper->widget);
+        
         hippo_canvas_item_allocate(helper->root,
-                                   allocation->width - GTK_CONTAINER(helper->widget)->border_width * 2,
-                                   allocation->height  - GTK_CONTAINER(helper->widget)->border_width * 2,
-                                   FALSE);
+                                   child_width, child_height,
+                                   border_changed);
 
         /* Tooltip might be in the wrong place now */
         update_tooltip(helper, FALSE);
@@ -1060,7 +1075,7 @@
     /* g_debug("queuing resize on canvas root %p canvas %p canvas container %p",
        root, canvas, helper->widget->parent); */
     if (!helper->fixing_up_resize_state)
-        gtk_widget_queue_resize(helper->widget);
+        gtk_widget_queue_resize_no_redraw(helper->widget);
 }
 
 static void
@@ -1193,7 +1208,7 @@
 
     helper->width = width;
 
-    gtk_widget_queue_resize(helper->widget);
+    gtk_widget_queue_resize_no_redraw(helper->widget);
 }
 
 /*

Modified: trunk/linux/hippo/hippo-canvas.c
==============================================================================
--- trunk/linux/hippo/hippo-canvas.c	(original)
+++ trunk/linux/hippo/hippo-canvas.c	Thu May  8 17:26:58 2008
@@ -91,6 +91,7 @@
     canvas->helper = hippo_canvas_helper_new(GTK_CONTAINER(canvas));
 
     gtk_widget_add_events(widget, HIPPO_CANVAS_EVENT_MASK);
+    gtk_widget_set_redraw_on_allocate(widget, FALSE);
 }
 
 static void



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