[gtk+] pixelcache: Don't have a style context argument



commit 4e8fb33f5677e086e1ba9f5a5650a12be99da99c
Author: Benjamin Otte <otte redhat com>
Date:   Thu Feb 25 16:14:37 2016 +0100

    pixelcache: Don't have a style context argument
    
    That would imply the pixelcache monitors the style context for changes
    and it doesn't do that.
    
    Its only use case was opacity checks, so add
    gtk_pixel_cache_se_is_opaque() instead.

 gtk/gtkpixelcache.c        |   23 +++++++++++------------
 gtk/gtkpixelcacheprivate.h |    4 ++--
 gtk/gtktextview.c          |   11 +++++++++--
 gtk/gtkviewport.c          |   31 ++++++++++++++++++++++++-------
 4 files changed, 46 insertions(+), 23 deletions(-)
---
diff --git a/gtk/gtkpixelcache.c b/gtk/gtkpixelcache.c
index 34a710b..9448401 100644
--- a/gtk/gtkpixelcache.c
+++ b/gtk/gtkpixelcache.c
@@ -47,15 +47,13 @@ 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;
   guint extra_height;
 
   guint always_cache : 1;
+  guint is_opaque : 1;
 };
 
 GtkPixelCache *
@@ -93,8 +91,6 @@ _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);
 }
 
@@ -197,10 +193,10 @@ _gtk_pixel_cache_create_surface_if_needed (GtkPixelCache         *cache,
   content = cache->content;
   if (!content)
     {
-      content = CAIRO_CONTENT_COLOR_ALPHA;
-      if (cache->style_context &&
-          gtk_css_style_render_background_is_opaque (gtk_style_context_lookup_style (cache->style_context)))
+      if (cache->is_opaque)
         content = CAIRO_CONTENT_COLOR;
+      else
+        content = CAIRO_CONTENT_COLOR_ALPHA;
     }
 
   surface_w = view_rect->width;
@@ -504,9 +500,12 @@ _gtk_pixel_cache_set_always_cache (GtkPixelCache *cache,
 }
 
 void
-_gtk_pixel_cache_set_style_context (GtkPixelCache   *cache,
-                                    GtkStyleContext *style_context)
+gtk_pixel_cache_set_is_opaque (GtkPixelCache *cache,
+                               gboolean       is_opaque)
 {
-  if (g_set_object (&cache->style_context, style_context))
-    _gtk_pixel_cache_invalidate (cache, NULL);
+  if (cache->is_opaque == is_opaque)
+    return;
+
+  cache->is_opaque = is_opaque;
+  _gtk_pixel_cache_invalidate (cache, NULL);
 }
diff --git a/gtk/gtkpixelcacheprivate.h b/gtk/gtkpixelcacheprivate.h
index 264717a..6ab3090 100644
--- a/gtk/gtkpixelcacheprivate.h
+++ b/gtk/gtkpixelcacheprivate.h
@@ -54,8 +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);
+void           gtk_pixel_cache_set_is_opaque     (GtkPixelCache         *cache,
+                                                  gboolean               is_opaque);
 
 
 G_END_DECLS
diff --git a/gtk/gtktextview.c b/gtk/gtktextview.c
index b79a892..3424c47 100644
--- a/gtk/gtktextview.c
+++ b/gtk/gtktextview.c
@@ -37,6 +37,7 @@
 #include "gtkmarshalers.h"
 #include "gtkmenu.h"
 #include "gtkmenuitem.h"
+#include "gtkrenderbackgroundprivate.h"
 #include "gtkseparatormenuitem.h"
 #include "gtksettings.h"
 #include "gtkselectionprivate.h"
@@ -51,7 +52,6 @@
 #include "gtkscrollable.h"
 #include "gtktypebuiltins.h"
 #include "gtktexthandleprivate.h"
-#include "gtkstylecontextprivate.h"
 #include "gtkcssstylepropertyprivate.h"
 #include "gtkpopover.h"
 #include "gtktoolbar.h"
@@ -1685,7 +1685,6 @@ gtk_text_view_init (GtkTextView *text_view)
 
   context = gtk_widget_get_style_context (GTK_WIDGET (text_view));
   gtk_style_context_add_class (context, GTK_STYLE_CLASS_VIEW);
-  _gtk_pixel_cache_set_style_context (priv->pixel_cache, context);
 
   /* Set up default style */
   priv->wrap_mode = GTK_WRAP_NONE;
@@ -9775,10 +9774,18 @@ node_style_changed_cb (GtkCssNode        *node,
                        GtkCssStyleChange *change,
                        GtkWidget         *widget)
 {
+  GtkTextViewPrivate *priv = GTK_TEXT_VIEW (widget)->priv;
+
   if (gtk_css_style_change_affects (change, GTK_CSS_AFFECTS_SIZE | GTK_CSS_AFFECTS_CLIP))
     gtk_widget_queue_resize (widget);
   else
     gtk_widget_queue_draw (widget);
+
+  if (node == priv->text_window->css_node)
+    {
+      GtkCssStyle *style = gtk_css_style_change_get_new_style (change);
+      gtk_pixel_cache_set_is_opaque (priv->pixel_cache, gtk_css_style_render_background_is_opaque (style));
+    }
 }
 
 static void
diff --git a/gtk/gtkviewport.c b/gtk/gtkviewport.c
index 368374c..0889514 100644
--- a/gtk/gtkviewport.c
+++ b/gtk/gtkviewport.c
@@ -33,7 +33,8 @@
 #include "gtkpixelcacheprivate.h"
 #include "gtkprivate.h"
 #include "gtkscrollable.h"
-#include "gtkrender.h"
+#include "gtkrenderbackgroundprivate.h"
+#include "gtkstylecontextprivate.h"
 #include "gtktypebuiltins.h"
 #include "gtkwidgetprivate.h"
 
@@ -938,16 +939,32 @@ gtk_viewport_draw (GtkWidget *widget,
 }
 
 static void
+gtk_viewport_update_pixelcache_opacity (GtkWidget   *child,
+                                        GtkViewport *viewport)
+{
+  GtkViewportPrivate *priv = viewport->priv;
+
+  gtk_pixel_cache_set_is_opaque (priv->pixel_cache,
+                                 gtk_css_style_render_background_is_opaque (
+                                   gtk_style_context_lookup_style (
+                                     gtk_widget_get_style_context (child))));
+}
+
+static void
 gtk_viewport_remove (GtkContainer *container,
                     GtkWidget    *child)
 {
   GtkViewport *viewport = GTK_VIEWPORT (container);
   GtkViewportPrivate *priv = viewport->priv;
 
-  GTK_CONTAINER_CLASS (gtk_viewport_parent_class)->remove (container, child);
+  if (g_signal_handlers_disconnect_by_func (child, gtk_viewport_update_pixelcache_opacity, viewport) != 1)
+    {
+      g_assert_not_reached ();
+    }
 
-  _gtk_pixel_cache_set_style_context (priv->pixel_cache, NULL);
+  GTK_CONTAINER_CLASS (gtk_viewport_parent_class)->remove (container, child);
 
+  gtk_pixel_cache_set_is_opaque (priv->pixel_cache, FALSE);
 }
 
 static void
@@ -961,11 +978,11 @@ gtk_viewport_add (GtkContainer *container,
   g_return_if_fail (gtk_bin_get_child (bin) == NULL);
 
   gtk_widget_set_parent_window (child, priv->bin_window);
-
-  _gtk_pixel_cache_set_style_context (priv->pixel_cache,
-                                      gtk_widget_get_style_context (child));
-
+  
   GTK_CONTAINER_CLASS (gtk_viewport_parent_class)->add (container, child);
+
+  g_signal_connect (child, "style-updated", G_CALLBACK (gtk_viewport_update_pixelcache_opacity), viewport);
+  gtk_viewport_update_pixelcache_opacity (child, viewport);
 }
 
 static void


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