[gtk+] pixelcache: use GtkStyleContext to determine cairo_content_t for surface



commit d7eb90779f3f0b71d640c12ebcff632cf2af3974
Author: Christian Hergert <christian hergert me>
Date:   Tue Sep 8 14:48:40 2015 -0700

    pixelcache: use GtkStyleContext to determine cairo_content_t for surface
    
    We can take a fast path if the background for a widget is opaque by using
    a CAIRO_CONTENT_COLOR instead of a CAIRO_CONTENT_COLOR_ALPHA surface. Most
    blit'ing backends have a fast path for this, including Pixman and Quartz.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=754658

 gtk/gtkpixelcache.c        |   20 +++++++++++++++-----
 gtk/gtkpixelcacheprivate.h |    2 ++
 2 files changed, 17 insertions(+), 5 deletions(-)
---
diff --git a/gtk/gtkpixelcache.c b/gtk/gtkpixelcache.c
index 2c0873e..55d977e 100644
--- a/gtk/gtkpixelcache.c
+++ b/gtk/gtkpixelcache.c
@@ -45,6 +45,9 @@ struct _GtkPixelCache {
   /* may be null if not dirty */
   cairo_region_t *surface_dirty;
 
+  /* background tracking for rgb/rgba */
+  GtkStyleContext *style_context;
+
   guint timeout_tag;
 
   guint extra_width;
@@ -88,6 +91,8 @@ _gtk_pixel_cache_free (GtkPixelCache *cache)
   if (cache->surface_dirty != NULL)
     cairo_region_destroy (cache->surface_dirty);
 
+  g_clear_object (&cache->style_context);
+
   g_free (cache);
 }
 
@@ -193,11 +198,8 @@ _gtk_pixel_cache_create_surface_if_needed (GtkPixelCache         *cache,
   if (!content)
     {
       content = CAIRO_CONTENT_COLOR_ALPHA;
-      bg = gdk_window_get_background_pattern (window);
-      if (bg != NULL &&
-          cairo_pattern_get_type (bg) == CAIRO_PATTERN_TYPE_SOLID &&
-          cairo_pattern_get_rgba (bg, &red, &green, &blue, &alpha) == CAIRO_STATUS_SUCCESS &&
-          alpha == 1.0)
+      if (cache->style_context &&
+          _gtk_style_context_is_background_opaque (cache->style_context))
         content = CAIRO_CONTENT_COLOR;
     }
 
@@ -500,3 +502,11 @@ _gtk_pixel_cache_set_always_cache (GtkPixelCache *cache,
 {
   cache->always_cache = !!always_cache;
 }
+
+void
+_gtk_pixel_cache_set_style_context (GtkPixelCache   *cache,
+                                    GtkStyleContext *style_context)
+{
+  if (g_set_object (&cache->style_context, style_context))
+    _gtk_pixel_cache_invalidate (cache, NULL);
+}
diff --git a/gtk/gtkpixelcacheprivate.h b/gtk/gtkpixelcacheprivate.h
index 8e1122c..264717a 100644
--- a/gtk/gtkpixelcacheprivate.h
+++ b/gtk/gtkpixelcacheprivate.h
@@ -54,6 +54,8 @@ void           _gtk_pixel_cache_set_content      (GtkPixelCache         *cache,
 gboolean       _gtk_pixel_cache_get_always_cache (GtkPixelCache         *cache);
 void           _gtk_pixel_cache_set_always_cache (GtkPixelCache         *cache,
                                                   gboolean               always_cache);
+void           _gtk_pixel_cache_set_style_context(GtkPixelCache         *cache,
+                                                  GtkStyleContext       *style_context);
 
 
 G_END_DECLS


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