From a3d68af95053ca8072e27a5b7258018e7635788f Mon Sep 17 00:00:00 2001 From: Benjamin Otte Date: Wed, 8 Oct 2014 05:19:07 +0200 Subject: [PATCH] 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 f3c319c3b3..314d3dd0ce 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 e85f9ae5e2..acc830f331 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; + 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);