gtkwidget: cache where windowless containers draw
It's kept until allocation, mapping, parent or style change, so an expose doesn't walk every child of every container anymore.
This commit is contained in:
parent
c5e9ecb8e4
commit
42424722a5
1 changed files with 59 additions and 3 deletions
|
|
@ -367,6 +367,7 @@ static void gtk_widget_queue_tooltip_query (GtkWidget *widg
|
|||
static void gtk_widget_set_usize_internal (GtkWidget *widget,
|
||||
gint width,
|
||||
gint height);
|
||||
static void draw_rects_changed (void);
|
||||
static void gtk_widget_get_draw_rectangle (GtkWidget *widget,
|
||||
GdkRectangle *rect);
|
||||
|
||||
|
|
@ -3190,6 +3191,7 @@ gtk_widget_unparent (GtkWidget *widget)
|
|||
g_object_notify_queue_clear (G_OBJECT (widget), nqueue);
|
||||
g_object_notify_queue_thaw (G_OBJECT (widget), nqueue);
|
||||
g_object_unref (widget);
|
||||
draw_rects_changed ();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -3469,6 +3471,7 @@ gtk_widget_map (GtkWidget *widget)
|
|||
if (!gtk_widget_get_has_window (widget))
|
||||
gdk_window_invalidate_rect (widget->window, &widget->allocation, FALSE);
|
||||
}
|
||||
draw_rects_changed ();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -3490,6 +3493,7 @@ gtk_widget_unmap (GtkWidget *widget)
|
|||
_gtk_tooltip_hide (widget);
|
||||
g_signal_emit (widget, widget_signals[UNMAP], 0);
|
||||
}
|
||||
draw_rects_changed ();
|
||||
}
|
||||
|
||||
static void
|
||||
|
|
@ -3614,6 +3618,7 @@ gtk_widget_realize (GtkWidget *widget)
|
|||
if (mode != GDK_EXTENSION_EVENTS_NONE)
|
||||
gtk_widget_set_extension_events_internal (widget, mode, NULL);
|
||||
}
|
||||
draw_rects_changed ();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -3644,6 +3649,7 @@ gtk_widget_unrealize (GtkWidget *widget)
|
|||
gtk_widget_set_mapped (widget, FALSE);
|
||||
g_object_unref (widget);
|
||||
}
|
||||
draw_rects_changed ();
|
||||
}
|
||||
|
||||
/*****************************************
|
||||
|
|
@ -3757,6 +3763,28 @@ widget_add_child_draw_rectangle (GtkWidget *widget,
|
|||
gdk_rectangle_union (rect, &child_rect, rect);
|
||||
}
|
||||
|
||||
/* Where widgets without a window draw, with their children, is kept for
|
||||
* the containers among them, as long as nothing happened that may change
|
||||
* it: a new allocation, size or drawing asked for, a widget mapped,
|
||||
* realized, parented, styled or the like anywhere. An expose otherwise
|
||||
* walks through all children of each container away from the exposed
|
||||
* area, to find whether some of them draw in it after all, and through
|
||||
* the children of each one it passes on the expose to again. */
|
||||
typedef struct
|
||||
{
|
||||
guint serial;
|
||||
GdkRectangle rect;
|
||||
} DrawRectCache;
|
||||
|
||||
static guint draw_rects_serial = 1;
|
||||
static GQuark quark_draw_rect;
|
||||
|
||||
static void
|
||||
draw_rects_changed (void)
|
||||
{
|
||||
draw_rects_serial++;
|
||||
}
|
||||
|
||||
/* The allocation of a widget without a window, with its draw border */
|
||||
static void
|
||||
gtk_widget_get_own_draw_rectangle (GtkWidget *widget,
|
||||
|
|
@ -3815,15 +3843,33 @@ _gtk_widget_draws_in_area (GtkWidget *widget,
|
|||
{
|
||||
GdkRectangle rect;
|
||||
|
||||
DrawRectCache *cache;
|
||||
|
||||
gtk_widget_get_own_draw_rectangle (widget, &rect);
|
||||
if (gdk_rectangle_intersect (area, &rect, NULL))
|
||||
return TRUE;
|
||||
if (!GTK_IS_CONTAINER (widget))
|
||||
return FALSE;
|
||||
|
||||
gtk_container_forall (GTK_CONTAINER (widget),
|
||||
(GtkCallback)widget_add_child_draw_rectangle,
|
||||
&rect);
|
||||
/* only here, to leave out children: a stale rectangle (after a
|
||||
* change outside GTK's own calls) costs a needless expose at most
|
||||
* where the children stay within the container */
|
||||
if (!quark_draw_rect)
|
||||
quark_draw_rect = g_quark_from_static_string ("gtk-widget-draw-rectangle");
|
||||
cache = g_object_get_qdata (G_OBJECT (widget), quark_draw_rect);
|
||||
if (cache && cache->serial == draw_rects_serial)
|
||||
return gdk_rectangle_intersect (area, &cache->rect, NULL);
|
||||
|
||||
gtk_widget_get_draw_rectangle (widget, &rect);
|
||||
|
||||
if (!cache)
|
||||
{
|
||||
cache = g_new (DrawRectCache, 1);
|
||||
g_object_set_qdata_full (G_OBJECT (widget), quark_draw_rect, cache, g_free);
|
||||
}
|
||||
cache->serial = draw_rects_serial;
|
||||
cache->rect = rect;
|
||||
|
||||
return gdk_rectangle_intersect (area, &rect, NULL);
|
||||
}
|
||||
|
||||
|
|
@ -4182,6 +4228,8 @@ gtk_widget_size_allocate (GtkWidget *widget,
|
|||
if (!alloc_needed && !size_changed && !position_changed)
|
||||
return;
|
||||
|
||||
draw_rects_changed ();
|
||||
|
||||
g_signal_emit (widget, widget_signals[SIZE_ALLOCATE], 0, &real_allocation);
|
||||
|
||||
if (gtk_widget_get_mapped (widget))
|
||||
|
|
@ -4219,6 +4267,7 @@ gtk_widget_size_allocate (GtkWidget *widget,
|
|||
gtk_widget_invalidate_widget_windows (widget->parent, invalidate);
|
||||
gdk_region_destroy (invalidate);
|
||||
}
|
||||
draw_rects_changed ();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -6179,6 +6228,7 @@ gtk_widget_set_realized (GtkWidget *widget,
|
|||
GTK_OBJECT_FLAGS (widget) |= GTK_REALIZED;
|
||||
else
|
||||
GTK_OBJECT_FLAGS (widget) &= ~(GTK_REALIZED);
|
||||
draw_rects_changed ();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -6221,6 +6271,7 @@ gtk_widget_set_mapped (GtkWidget *widget,
|
|||
GTK_OBJECT_FLAGS (widget) |= GTK_MAPPED;
|
||||
else
|
||||
GTK_OBJECT_FLAGS (widget) &= ~(GTK_MAPPED);
|
||||
draw_rects_changed ();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -6546,6 +6597,7 @@ gtk_widget_set_parent (GtkWidget *widget,
|
|||
|
||||
gtk_widget_queue_resize (widget);
|
||||
}
|
||||
draw_rects_changed ();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -7097,6 +7149,7 @@ gtk_widget_set_style_internal (GtkWidget *widget,
|
|||
g_object_notify (G_OBJECT (widget), "style");
|
||||
g_object_thaw_notify (G_OBJECT (widget));
|
||||
g_object_unref (widget);
|
||||
draw_rects_changed ();
|
||||
}
|
||||
|
||||
typedef struct {
|
||||
|
|
@ -7642,6 +7695,7 @@ gtk_widget_set_child_visible (GtkWidget *widget,
|
|||
}
|
||||
|
||||
g_object_unref (widget);
|
||||
draw_rects_changed ();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -11416,6 +11470,7 @@ gtk_widget_set_allocation (GtkWidget *widget,
|
|||
g_return_if_fail (allocation != NULL);
|
||||
|
||||
widget->allocation = *allocation;
|
||||
draw_rects_changed ();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -11473,6 +11528,7 @@ gtk_widget_set_window (GtkWidget *widget,
|
|||
widget->window = window;
|
||||
g_object_notify (G_OBJECT (widget), "window");
|
||||
}
|
||||
draw_rects_changed ();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
Loading…
Reference in a new issue