[gtk+] stylecontext: add opaque background helper



commit c1691a49640026c4701f13c96ab914cd456310b7
Author: Christian Hergert <christian hergert me>
Date:   Tue Sep 8 14:45:51 2015 -0700

    stylecontext: add opaque background helper
    
    This new private API, _gtk_style_context_is_background_opaque(), is meant to
    be used by internal Gtk+ wigets to optimize fast paths for cases where
    applicable. One such use would be to use a CAIRO_CONTENT_COLOR surface
    instead of CAIRO_CONTENT_COLOR_ALPHA.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=754658

 gtk/gtkstylecontext.c        |   21 ++++++++++++++++-----
 gtk/gtkstylecontextprivate.h |    2 ++
 2 files changed, 18 insertions(+), 5 deletions(-)
---
diff --git a/gtk/gtkstylecontext.c b/gtk/gtkstylecontext.c
index ddc0d11..c795cc0 100644
--- a/gtk/gtkstylecontext.c
+++ b/gtk/gtkstylecontext.c
@@ -2504,11 +2504,7 @@ gtk_style_context_set_background (GtkStyleContext *context,
    */
   color = _gtk_css_rgba_value_get_rgba (_gtk_style_context_peek_property (context, 
GTK_CSS_PROPERTY_BACKGROUND_COLOR));
 
-  if (color->alpha >= 1.0 &&
-      corner_value_is_right_angle (_gtk_style_context_peek_property (context, 
GTK_CSS_PROPERTY_BORDER_TOP_LEFT_RADIUS)) &&
-      corner_value_is_right_angle (_gtk_style_context_peek_property (context, 
GTK_CSS_PROPERTY_BORDER_TOP_RIGHT_RADIUS)) &&
-      corner_value_is_right_angle (_gtk_style_context_peek_property (context, 
GTK_CSS_PROPERTY_BORDER_BOTTOM_RIGHT_RADIUS)) &&
-      corner_value_is_right_angle (_gtk_style_context_peek_property (context, 
GTK_CSS_PROPERTY_BORDER_BOTTOM_LEFT_RADIUS)))
+  if (_gtk_style_context_is_background_opaque (context))
     {
       gdk_window_set_background_rgba (window, color);
     }
@@ -3305,3 +3301,18 @@ gtk_gradient_resolve_for_context (GtkGradient     *gradient,
                                      priv->parent ? gtk_style_context_lookup_style (priv->parent) : NULL);
 }
 
+gboolean
+_gtk_style_context_is_background_opaque (GtkStyleContext *context)
+{
+  const GdkRGBA *color;
+
+  g_return_val_if_fail (context != NULL, FALSE);
+
+  color = _gtk_css_rgba_value_get_rgba (_gtk_style_context_peek_property (context, 
GTK_CSS_PROPERTY_BACKGROUND_COLOR));
+
+  return (color->alpha >= 1.0 &&
+          corner_value_is_right_angle (_gtk_style_context_peek_property (context, 
GTK_CSS_PROPERTY_BORDER_TOP_LEFT_RADIUS)) &&
+          corner_value_is_right_angle (_gtk_style_context_peek_property (context, 
GTK_CSS_PROPERTY_BORDER_TOP_RIGHT_RADIUS)) &&
+          corner_value_is_right_angle (_gtk_style_context_peek_property (context, 
GTK_CSS_PROPERTY_BORDER_BOTTOM_RIGHT_RADIUS)) &&
+          corner_value_is_right_angle (_gtk_style_context_peek_property (context, 
GTK_CSS_PROPERTY_BORDER_BOTTOM_LEFT_RADIUS)));
+}
diff --git a/gtk/gtkstylecontextprivate.h b/gtk/gtkstylecontextprivate.h
index 1ed7b21..4ba27fe 100644
--- a/gtk/gtkstylecontextprivate.h
+++ b/gtk/gtkstylecontextprivate.h
@@ -64,6 +64,8 @@ void           _gtk_style_context_get_icon_extents           (GtkStyleContext
                                                               gint                width,
                                                               gint                height);
 
+gboolean       _gtk_style_context_is_background_opaque       (GtkStyleContext *context);
+
 PangoAttrList *_gtk_style_context_get_pango_attributes       (GtkStyleContext *context);
 
 /* Accessibility support */


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