forked from AuroraMiddleware/gtk
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.
This commit is contained in:
parent
99d3d31314
commit
598d22d194
@ -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;
|
||||
}
|
||||
|
@ -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
|
||||
|
||||
|
@ -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));
|
||||
}
|
||||
|
||||
|
@ -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__ */
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user