[gtk+] Avoid creating trivial shadow nodes
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk+] Avoid creating trivial shadow nodes
- Date: Sat, 28 Oct 2017 20:12:51 +0000 (UTC)
commit 598d22d194a51304277fb2eb174576aaa8185b7d
Author: Matthias Clasen <mclasen redhat com>
Date: Sat Oct 28 16:10:46 2017 -0400
Avoid creating trivial shadow nodes
The Vulkan renderer creates a fallback surface for each shadow
node, even if we end up not rendering anything to it. Avoiding
this is a nice optimization.
gtk/gtkcssshadowsvalue.c | 27 +++++++++++++++++++++++++++
gtk/gtkcssshadowsvalueprivate.h | 2 ++
gtk/gtkcssshadowvalue.c | 6 ++++++
gtk/gtkcssshadowvalueprivate.h | 2 ++
gtk/gtkrendericon.c | 30 ++++++++----------------------
gtk/gtksnapshot.c | 14 +++-----------
6 files changed, 48 insertions(+), 33 deletions(-)
---
diff --git a/gtk/gtkcssshadowsvalue.c b/gtk/gtkcssshadowsvalue.c
index bd687dc..fcb6097 100644
--- a/gtk/gtkcssshadowsvalue.c
+++ b/gtk/gtkcssshadowsvalue.c
@@ -24,6 +24,7 @@
#include <math.h>
#include "gtkcssshadowvalueprivate.h"
+#include "gtksnapshot.h"
#include <string.h>
@@ -393,3 +394,29 @@ _gtk_css_shadows_value_get_extents (const GtkCssValue *shadows,
*border = b;
}
+
+gboolean
+gtk_css_shadows_value_push_snapshot (const GtkCssValue *value,
+ GtkSnapshot *snapshot)
+{
+ gboolean need_shadow = FALSE;
+ int i;
+
+ for (i = 0; i < value->len; i++)
+ {
+ if (!gtk_css_shadow_value_is_clear (value->values[i]))
+ {
+ need_shadow = TRUE;
+ break;
+ }
+ }
+
+ if (need_shadow)
+ {
+ GskShadow *shadows = g_newa (GskShadow, value->len);
+ gtk_css_shadows_value_get_shadows (value, shadows);
+ gtk_snapshot_push_shadow (snapshot, shadows, value->len, "Shadow<%u>", value->len);
+ }
+
+ return need_shadow;
+}
diff --git a/gtk/gtkcssshadowsvalueprivate.h b/gtk/gtkcssshadowsvalueprivate.h
index be2f6b4..5bd7861 100644
--- a/gtk/gtkcssshadowsvalueprivate.h
+++ b/gtk/gtkcssshadowsvalueprivate.h
@@ -61,6 +61,8 @@ void gtk_css_shadows_value_snapshot_inset (const GtkCssValue
void _gtk_css_shadows_value_get_extents (const GtkCssValue *shadows,
GtkBorder *border);
+gboolean gtk_css_shadows_value_push_snapshot (const GtkCssValue *shadows,
+ GtkSnapshot *snapshot);
G_END_DECLS
diff --git a/gtk/gtkcssshadowvalue.c b/gtk/gtkcssshadowvalue.c
index 3c7d116..c5f1db4 100644
--- a/gtk/gtkcssshadowvalue.c
+++ b/gtk/gtkcssshadowvalue.c
@@ -1090,3 +1090,9 @@ gtk_css_shadow_value_snapshot_inset (const GtkCssValue *shadow,
gsk_render_node_unref (node);
}
+gboolean
+gtk_css_shadow_value_is_clear (const GtkCssValue *shadow)
+{
+ return gdk_rgba_is_clear (_gtk_css_rgba_value_get_rgba (shadow->color));
+}
+
diff --git a/gtk/gtkcssshadowvalueprivate.h b/gtk/gtkcssshadowvalueprivate.h
index 2c139c8..e3113d1 100644
--- a/gtk/gtkcssshadowvalueprivate.h
+++ b/gtk/gtkcssshadowvalueprivate.h
@@ -59,6 +59,8 @@ void gtk_css_shadow_value_snapshot_inset (const GtkCssValue
GtkSnapshot *snapshot,
const GskRoundedRect *padding_box);
+gboolean gtk_css_shadow_value_is_clear (const GtkCssValue *shadow);
+
G_END_DECLS
#endif /* __GTK_SHADOW_H__ */
diff --git a/gtk/gtkrendericon.c b/gtk/gtkrendericon.c
index b028d77..a500db8 100644
--- a/gtk/gtkrendericon.c
+++ b/gtk/gtkrendericon.c
@@ -99,8 +99,7 @@ gtk_css_style_snapshot_icon (GtkCssStyle *style,
const GtkCssValue *shadows_value, *transform_value, *filter_value;
graphene_matrix_t transform_matrix;
GtkCssImage *image;
- GskShadow *shadows;
- gsize n_shadows;
+ gboolean has_shadow;
g_return_if_fail (GTK_IS_CSS_STYLE (style));
g_return_if_fail (snapshot != NULL);
@@ -121,13 +120,7 @@ gtk_css_style_snapshot_icon (GtkCssStyle *style,
gtk_css_filter_value_push_snapshot (filter_value, snapshot);
- n_shadows = gtk_css_shadows_value_get_n_shadows (shadows_value);
- if (n_shadows > 0)
- {
- shadows = g_newa (GskShadow, n_shadows);
- gtk_css_shadows_value_get_shadows (shadows_value, shadows);
- gtk_snapshot_push_shadow (snapshot, shadows, n_shadows, "IconShadow<%zu>", n_shadows);
- }
+ has_shadow = gtk_css_shadows_value_push_snapshot (shadows_value, snapshot);
if (graphene_matrix_is_identity (&transform_matrix))
{
@@ -150,9 +143,9 @@ gtk_css_style_snapshot_icon (GtkCssStyle *style,
gtk_snapshot_pop (snapshot);
}
- if (n_shadows > 0)
+ if (has_shadow)
gtk_snapshot_pop (snapshot);
-
+
gtk_css_filter_value_pop_snapshot (filter_value, snapshot);
}
@@ -282,8 +275,7 @@ gtk_css_style_snapshot_icon_texture (GtkCssStyle *style,
graphene_matrix_t transform_matrix;
graphene_rect_t bounds;
double width, height;
- GskShadow *shadows;
- gsize n_shadows;
+ gboolean has_shadow;
g_return_if_fail (GTK_IS_CSS_STYLE (style));
g_return_if_fail (snapshot != NULL);
@@ -301,13 +293,7 @@ gtk_css_style_snapshot_icon_texture (GtkCssStyle *style,
gtk_css_filter_value_push_snapshot (filter_value, snapshot);
- n_shadows = gtk_css_shadows_value_get_n_shadows (shadows_value);
- if (n_shadows > 0)
- {
- shadows = g_newa (GskShadow, n_shadows);
- gtk_css_shadows_value_get_shadows (shadows_value, shadows);
- gtk_snapshot_push_shadow (snapshot, shadows, n_shadows, "IconShadow<%zu>", n_shadows);
- }
+ has_shadow = gtk_css_shadows_value_push_snapshot (shadows_value, snapshot);
if (color_matrix)
gtk_snapshot_push_color_matrix (snapshot, color_matrix, color_offset, "Recoloring Icon");
@@ -339,8 +325,8 @@ gtk_css_style_snapshot_icon_texture (GtkCssStyle *style,
if (color_matrix)
gtk_snapshot_pop (snapshot);
- if (n_shadows > 0)
+ if (has_shadow)
gtk_snapshot_pop (snapshot);
-
+
gtk_css_filter_value_pop_snapshot (filter_value, snapshot);
}
diff --git a/gtk/gtksnapshot.c b/gtk/gtksnapshot.c
index d9d463a..4af505e 100644
--- a/gtk/gtksnapshot.c
+++ b/gtk/gtksnapshot.c
@@ -1460,8 +1460,7 @@ gtk_snapshot_render_layout (GtkSnapshot *snapshot,
{
const GdkRGBA *fg_color;
GtkCssValue *shadows_value;
- GskShadow *shadows;
- gsize n_shadows;
+ gboolean has_shadow;
g_return_if_fail (snapshot != NULL);
g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
@@ -1472,18 +1471,11 @@ gtk_snapshot_render_layout (GtkSnapshot *snapshot,
fg_color = _gtk_css_rgba_value_get_rgba (_gtk_style_context_peek_property (context,
GTK_CSS_PROPERTY_COLOR));
shadows_value = _gtk_style_context_peek_property (context, GTK_CSS_PROPERTY_TEXT_SHADOW);
- n_shadows = gtk_css_shadows_value_get_n_shadows (shadows_value);
-
- if (n_shadows > 0)
- {
- shadows = g_newa (GskShadow, n_shadows);
- gtk_css_shadows_value_get_shadows (shadows_value, shadows);
- gtk_snapshot_push_shadow (snapshot, shadows, n_shadows, "TextShadow<%zu>", n_shadows);
- }
+ has_shadow = gtk_css_shadows_value_push_snapshot (shadows_value, snapshot);
gsk_pango_show_layout (snapshot, fg_color, layout);
- if (n_shadows > 0)
+ if (has_shadow)
gtk_snapshot_pop (snapshot);
gtk_snapshot_offset (snapshot, -x, -y);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]