diff options
author | Alexander Larsson <alexl@redhat.com> | 2013-05-07 14:27:17 +0200 |
---|---|---|
committer | Alexander Larsson <alexl@redhat.com> | 2013-05-07 14:27:17 +0200 |
commit | 4ab2f28f8eb1f8ab1f00a13c4bd7e35417fab92e (patch) | |
tree | 218d343aa0898458dc0dfd770c7af5d232f1170e | |
parent | da0cf5fbffdb668ee342cd1c738978d4edbc5421 (diff) | |
download | gtk+-wip/simple-draw4.tar.gz |
GtkPixelCache: Free cache if not used in 20 secondswip/simple-draw4
No need to keep a performance enhancing cache around if its not
actually in use.
-rw-r--r-- | gtk/gtkpixelcache.c | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/gtk/gtkpixelcache.c b/gtk/gtkpixelcache.c index 91b9d8fb26..9b2f1d83a8 100644 --- a/gtk/gtkpixelcache.c +++ b/gtk/gtkpixelcache.c @@ -20,6 +20,8 @@ #include "gtkdebug.h" #include "gtkpixelcacheprivate.h" +#define BLOW_CACHE_TIMEOUT_SEC 20 + /* The extra size of the offscreen surface we allocate to make scrolling more efficient */ #define EXTRA_SIZE 64 @@ -39,6 +41,8 @@ struct _GtkPixelCache { /* may be null if not dirty */ cairo_region_t *surface_dirty; + + guint timeout_tag; }; GtkPixelCache * @@ -57,6 +61,9 @@ _gtk_pixel_cache_free (GtkPixelCache *cache) if (cache == NULL) return; + if (cache->timeout_tag) + g_source_remove (cache->timeout_tag); + if (cache->surface != NULL) cairo_surface_destroy (cache->surface); @@ -322,6 +329,26 @@ _gtk_pixel_cache_repaint (GtkPixelCache *cache, } } +static gboolean +blow_cache_cb (gpointer user_data) +{ + GtkPixelCache *cache = user_data; + + cache->timeout_tag = 0; + + if (cache->surface) + { + cairo_surface_destroy (cache->surface); + cache->surface = NULL; + if (cache->surface_dirty) + cairo_region_destroy (cache->surface_dirty); + cache->surface_dirty = NULL; + } + + return G_SOURCE_REMOVE; +} + + void _gtk_pixel_cache_draw (GtkPixelCache *cache, cairo_t *cr, @@ -333,6 +360,12 @@ _gtk_pixel_cache_draw (GtkPixelCache *cache, GtkPixelCacheDrawFunc draw, gpointer user_data) { + if (cache->timeout_tag) + g_source_remove (cache->timeout_tag); + + cache->timeout_tag = g_timeout_add_seconds (BLOW_CACHE_TIMEOUT_SEC, + blow_cache_cb, cache); + _gtk_pixel_cache_create_surface_if_needed (cache, window, view_rect, canvas_rect); _gtk_pixel_cache_set_position (cache, view_rect, canvas_rect); |