[gtk+] pixelcache: allow widgets to always require cached content



commit 6a2143ab31beaa69fb685a3db6882831fc372cc2
Author: Christian Hergert <christian hergert me>
Date:   Tue Jun 16 16:46:24 2015 -0700

    pixelcache: allow widgets to always require cached content
    
    Some widgets have very expensive drawing paths. So caching the content
    can be useful even when not scrolling.
    
    This can help speed up widgets that are part of animation sequences and
    thereby go through spurious expose events.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=751082

 gtk/gtkpixelcache.c        |   23 +++++++++++++++++++--
 gtk/gtkpixelcacheprivate.h |   45 +++++++++++++++++++++++--------------------
 2 files changed, 44 insertions(+), 24 deletions(-)
---
diff --git a/gtk/gtkpixelcache.c b/gtk/gtkpixelcache.c
index 3e88302..a6a85cb 100644
--- a/gtk/gtkpixelcache.c
+++ b/gtk/gtkpixelcache.c
@@ -49,6 +49,8 @@ struct _GtkPixelCache {
 
   guint extra_width;
   guint extra_height;
+
+  guint always_cache : 1;
 };
 
 GtkPixelCache *
@@ -224,10 +226,12 @@ _gtk_pixel_cache_create_surface_if_needed (GtkPixelCache         *cache,
     }
 
   /* Don't allocate a surface if view >= canvas, as we won't
-     be scrolling then anyway */
+   * be scrolling then anyway, unless the widget requested it.
+   */
   if (cache->surface == NULL &&
-      (view_rect->width < canvas_rect->width ||
-       view_rect->height < canvas_rect->height))
+      (cache->always_cache ||
+       (view_rect->width < canvas_rect->width ||
+        view_rect->height < canvas_rect->height)))
     {
       cache->surface_x = -canvas_rect->x;
       cache->surface_y = -canvas_rect->y;
@@ -483,3 +487,16 @@ _gtk_pixel_cache_unmap (GtkPixelCache *cache)
 {
   gtk_pixel_cache_blow_cache (cache);
 }
+
+gboolean
+_gtk_pixel_cache_get_always_cache (GtkPixelCache *cache)
+{
+  return cache->always_cache;
+}
+
+void
+_gtk_pixel_cache_set_always_cache (GtkPixelCache *cache,
+                                   gboolean       always_cache)
+{
+  cache->always_cache = !!always_cache;
+}
diff --git a/gtk/gtkpixelcacheprivate.h b/gtk/gtkpixelcacheprivate.h
index c31693e..8e1122c 100644
--- a/gtk/gtkpixelcacheprivate.h
+++ b/gtk/gtkpixelcacheprivate.h
@@ -30,27 +30,30 @@ typedef struct _GtkPixelCache           GtkPixelCache;
 typedef void (*GtkPixelCacheDrawFunc) (cairo_t *cr,
                                       gpointer user_data);
 
-GtkPixelCache *_gtk_pixel_cache_new            (void);
-void           _gtk_pixel_cache_free           (GtkPixelCache         *cache);
-void           _gtk_pixel_cache_map            (GtkPixelCache         *cache);
-void           _gtk_pixel_cache_unmap          (GtkPixelCache         *cache);
-void           _gtk_pixel_cache_invalidate     (GtkPixelCache         *cache,
-                                                cairo_region_t        *region);
-void           _gtk_pixel_cache_draw           (GtkPixelCache         *cache,
-                                                cairo_t               *cr,
-                                                GdkWindow             *window,
-                                                cairo_rectangle_int_t *view_rect,
-                                                cairo_rectangle_int_t *canvas_rect,
-                                                GtkPixelCacheDrawFunc  draw,
-                                                gpointer               user_data);
-void           _gtk_pixel_cache_get_extra_size (GtkPixelCache         *cache,
-                                                guint                 *extra_width,
-                                                guint                 *extra_height);
-void           _gtk_pixel_cache_set_extra_size (GtkPixelCache         *cache,
-                                                guint                  extra_width,
-                                                guint                  extra_height);
-void           _gtk_pixel_cache_set_content    (GtkPixelCache         *cache,
-                                                cairo_content_t        content);
+GtkPixelCache *_gtk_pixel_cache_new              (void);
+void           _gtk_pixel_cache_free             (GtkPixelCache         *cache);
+void           _gtk_pixel_cache_map              (GtkPixelCache         *cache);
+void           _gtk_pixel_cache_unmap            (GtkPixelCache         *cache);
+void           _gtk_pixel_cache_invalidate       (GtkPixelCache         *cache,
+                                                  cairo_region_t        *region);
+void           _gtk_pixel_cache_draw             (GtkPixelCache         *cache,
+                                                  cairo_t               *cr,
+                                                  GdkWindow             *window,
+                                                  cairo_rectangle_int_t *view_rect,
+                                                  cairo_rectangle_int_t *canvas_rect,
+                                                  GtkPixelCacheDrawFunc  draw,
+                                                  gpointer               user_data);
+void           _gtk_pixel_cache_get_extra_size   (GtkPixelCache         *cache,
+                                                  guint                 *extra_width,
+                                                  guint                 *extra_height);
+void           _gtk_pixel_cache_set_extra_size   (GtkPixelCache         *cache,
+                                                  guint                  extra_width,
+                                                  guint                  extra_height);
+void           _gtk_pixel_cache_set_content      (GtkPixelCache         *cache,
+                                                  cairo_content_t        content);
+gboolean       _gtk_pixel_cache_get_always_cache (GtkPixelCache         *cache);
+void           _gtk_pixel_cache_set_always_cache (GtkPixelCache         *cache,
+                                                  gboolean               always_cache);
 
 
 G_END_DECLS


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