diff options
author | Benjamin Otte <otte@redhat.com> | 2012-11-13 22:02:53 +0100 |
---|---|---|
committer | Benjamin Otte <otte@redhat.com> | 2012-11-14 01:55:28 +0100 |
commit | c08efb2b3291692dd3ad12cc95d4daf3735a0630 (patch) | |
tree | 50c2559ae940c93c1376dba0b83ea0407cf505d6 /gtk | |
parent | c98ee1ec396ccd8cb4c87780ee08adad88fdf3e3 (diff) | |
download | gtk+-c08efb2b3291692dd3ad12cc95d4daf3735a0630.tar.gz |
sizerequest: Cache the request mode
... in the GtkSizeRequestCache. That way, we only need to query it once,
and can remove the caching code from GtkContainer.
Diffstat (limited to 'gtk')
-rw-r--r-- | gtk/gtkcontainer.c | 30 | ||||
-rw-r--r-- | gtk/gtksizegroup.c | 2 | ||||
-rw-r--r-- | gtk/gtksizerequest.c | 32 | ||||
-rw-r--r-- | gtk/gtksizerequestcacheprivate.h | 3 |
4 files changed, 28 insertions, 39 deletions
diff --git a/gtk/gtkcontainer.c b/gtk/gtkcontainer.c index 52eeae8b97..6f50359978 100644 --- a/gtk/gtkcontainer.c +++ b/gtk/gtkcontainer.c @@ -42,6 +42,7 @@ #include "gtkmain.h" #include "gtkmarshalers.h" #include "gtksizerequest.h" +#include "gtksizerequestcacheprivate.h" #include "gtkwidgetprivate.h" #include "gtkwindow.h" #include "gtkassistant.h" @@ -1755,6 +1756,7 @@ _gtk_container_queue_resize_internal (GtkContainer *container, _gtk_widget_set_alloc_needed (widget, TRUE); _gtk_widget_set_width_request_needed (widget, TRUE); _gtk_widget_set_height_request_needed (widget, TRUE); + _gtk_size_request_cache_clear (_gtk_widget_peek_request_cache (widget)); if (GTK_IS_RESIZE_CONTAINER (widget)) break; @@ -1968,27 +1970,17 @@ count_request_modes (GtkWidget *widget, static GtkSizeRequestMode gtk_container_get_request_mode (GtkWidget *widget) { - GtkContainer *container = GTK_CONTAINER (widget); - GtkContainerPrivate *priv = container->priv; - - /* Recalculate the request mode of the children by majority - * vote whenever the internal content changes */ - if (_gtk_widget_get_width_request_needed (widget) || - _gtk_widget_get_height_request_needed (widget)) - { - RequestModeCount count = { 0, 0 }; + GtkContainer *container = GTK_CONTAINER (widget); + RequestModeCount count = { 0, 0 }; - gtk_container_forall (container, (GtkCallback)count_request_modes, &count); + gtk_container_forall (container, (GtkCallback)count_request_modes, &count); - if (!count.hfw && !count.wfh) - priv->request_mode = GTK_SIZE_REQUEST_CONSTANT_SIZE; - else - priv->request_mode = count.wfh > count.hfw ? - GTK_SIZE_REQUEST_WIDTH_FOR_HEIGHT : - GTK_SIZE_REQUEST_HEIGHT_FOR_WIDTH; - } - - return priv->request_mode; + if (!count.hfw && !count.wfh) + return GTK_SIZE_REQUEST_CONSTANT_SIZE; + else + return count.wfh > count.hfw ? + GTK_SIZE_REQUEST_WIDTH_FOR_HEIGHT : + GTK_SIZE_REQUEST_HEIGHT_FOR_WIDTH; } /** diff --git a/gtk/gtksizegroup.c b/gtk/gtksizegroup.c index 39e4b92e06..bcd9255727 100644 --- a/gtk/gtksizegroup.c +++ b/gtk/gtksizegroup.c @@ -25,6 +25,7 @@ #include "gtktypebuiltins.h" #include "gtkprivate.h" #include "gtksizegroup-private.h" +#include "gtksizerequestcacheprivate.h" #include "gtkwidgetprivate.h" #include "gtkcontainerprivate.h" @@ -198,6 +199,7 @@ real_queue_resize (GtkWidget *widget, _gtk_widget_set_alloc_needed (widget, TRUE); _gtk_widget_set_width_request_needed (widget, TRUE); _gtk_widget_set_height_request_needed (widget, TRUE); + _gtk_size_request_cache_clear (_gtk_widget_peek_request_cache (widget)); container = gtk_widget_get_parent (widget); if (!container && diff --git a/gtk/gtksizerequest.c b/gtk/gtksizerequest.c index eff854f200..99191f5583 100644 --- a/gtk/gtksizerequest.c +++ b/gtk/gtksizerequest.c @@ -84,24 +84,6 @@ pop_recursion_check (GtkWidget *widget, } -/* This function checks if 'request_needed' flag is present - * and resets the cache state if a request is needed for - * a given orientation. - */ -static SizeRequestCache * -init_cache (GtkWidget *widget) -{ - SizeRequestCache *cache; - - cache = _gtk_widget_peek_request_cache (widget); - - if (_gtk_widget_get_width_request_needed (widget) || - _gtk_widget_get_height_request_needed (widget)) - _gtk_size_request_cache_clear (cache); - - return cache; -} - /* looks for a cached size request for this for_size. If not * found, returns the oldest entry so it can be overwritten * @@ -118,7 +100,7 @@ get_cached_size (GtkWidget *widget, SizeRequest **cached_sizes; guint i, n_sizes; - cache = init_cache (widget); + cache = _gtk_widget_peek_request_cache (widget); if (for_size < 0) { @@ -507,9 +489,19 @@ _gtk_widget_compute_size_for_orientation (GtkWidget *widget, GtkSizeRequestMode gtk_widget_get_request_mode (GtkWidget *widget) { + SizeRequestCache *cache; + g_return_val_if_fail (GTK_IS_WIDGET (widget), GTK_SIZE_REQUEST_CONSTANT_SIZE); - return GTK_WIDGET_GET_CLASS (widget)->get_request_mode (widget); + cache = _gtk_widget_peek_request_cache (widget); + + if (!cache->request_mode_valid) + { + cache->request_mode = GTK_WIDGET_GET_CLASS (widget)->get_request_mode (widget); + cache->request_mode_valid = TRUE; + } + + return cache->request_mode; } /** diff --git a/gtk/gtksizerequestcacheprivate.h b/gtk/gtksizerequestcacheprivate.h index 60c061bdfe..db15aa50e6 100644 --- a/gtk/gtksizerequestcacheprivate.h +++ b/gtk/gtksizerequestcacheprivate.h @@ -26,6 +26,7 @@ #define __GTK_SIZE_REQUEST_CACHE_PRIVATE_H__ #include <glib.h> +#include <gtk/gtkenums.h> G_BEGIN_DECLS @@ -56,6 +57,8 @@ typedef struct { CachedSize cached_width; CachedSize cached_height; + GtkSizeRequestMode request_mode: 3; + guint request_mode_valid : 1; guint cached_widths : 3; guint cached_heights : 3; guint last_cached_width : 3; |