[gtk+] themingbackground: Add a quick exit for default case



commit a3d68af95053ca8072e27a5b7258018e7635788f
Author: Benjamin Otte <otte redhat com>
Date:   Wed Oct 8 05:19:07 2014 +0200

    themingbackground: Add a quick exit for default case
    
    In the case where the background is completely transparent, exit the
    rendering functions before doing any expensive calculations.

 gtk/gtkcsstypesprivate.h   |    3 +++
 gtk/gtkthemingbackground.c |   16 +++++++++++-----
 2 files changed, 14 insertions(+), 5 deletions(-)
---
diff --git a/gtk/gtkcsstypesprivate.h b/gtk/gtkcsstypesprivate.h
index f3c319c..314d3dd 100644
--- a/gtk/gtkcsstypesprivate.h
+++ b/gtk/gtkcsstypesprivate.h
@@ -280,6 +280,9 @@ GtkCssChange            _gtk_css_change_for_child                (GtkCssChange
 GtkCssDependencies      _gtk_css_dependencies_union              (GtkCssDependencies first,
                                                                   GtkCssDependencies second);
 
+/* for lack of better place to put it */
+/* mirror what cairo does */
+#define gtk_rgba_is_clear(rgba) ((rgba)->alpha < ((double)0x00ff / (double)0xffff))
 
 G_END_DECLS
 
diff --git a/gtk/gtkthemingbackground.c b/gtk/gtkthemingbackground.c
index e85f9ae..acc830f 100644
--- a/gtk/gtkthemingbackground.c
+++ b/gtk/gtkthemingbackground.c
@@ -305,14 +305,20 @@ gtk_theming_background_render (GtkStyleContext      *context,
   GtkCssValue *box_shadow;
   const GdkRGBA *bg_color;
 
-  bg.context = context;
+  background_image = _gtk_style_context_peek_property (context, GTK_CSS_PROPERTY_BACKGROUND_IMAGE);
+  bg_color = _gtk_css_rgba_value_get_rgba (_gtk_style_context_peek_property (context, 
GTK_CSS_PROPERTY_BACKGROUND_COLOR));
+  box_shadow = _gtk_style_context_peek_property (context, GTK_CSS_PROPERTY_BOX_SHADOW);
+
+  /* This is the common default case of no background */
+  if (gtk_rgba_is_clear (bg_color) &&
+      _gtk_css_array_value_get_n_values (background_image) == 1 &&
+      _gtk_css_image_value_get_image (_gtk_css_array_value_get_nth (background_image, 0)) == NULL &&
+      _gtk_css_shadows_value_is_none (box_shadow))
+    return;
 
+  bg.context = context;
   _gtk_theming_background_init_context (&bg, width, height, junction);
 
-  background_image = _gtk_style_context_peek_property (bg.context, GTK_CSS_PROPERTY_BACKGROUND_IMAGE);
-  bg_color = _gtk_css_rgba_value_get_rgba (_gtk_style_context_peek_property (bg.context, 
GTK_CSS_PROPERTY_BACKGROUND_COLOR));
-  box_shadow = _gtk_style_context_peek_property (bg.context, GTK_CSS_PROPERTY_BOX_SHADOW);
-
   cairo_save (cr);
   cairo_translate (cr, x, y);
 


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