[gtk+/wip/pango-shadow-cache] pango shadow cache
- From: Jasper St. Pierre <jstpierre src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk+/wip/pango-shadow-cache] pango shadow cache
- Date: Fri, 29 Aug 2014 22:13:57 +0000 (UTC)
commit 6722379c69c96989568e7446a284646d09546630
Author: Jasper St. Pierre <jstpierre mecheye net>
Date: Fri Aug 29 13:51:30 2014 -0700
pango shadow cache
gtk/gtkcssshadowvalue.c | 58 ++++++++++++++++++++++++++++++++++++++++------
1 files changed, 50 insertions(+), 8 deletions(-)
---
diff --git a/gtk/gtkcssshadowvalue.c b/gtk/gtkcssshadowvalue.c
index 7e8e3b0..def3a5d 100644
--- a/gtk/gtkcssshadowvalue.c
+++ b/gtk/gtkcssshadowvalue.c
@@ -322,6 +322,17 @@ needs_blur (const GtkCssValue *shadow)
return TRUE;
}
+static void
+setup_cairo_for_shadow_apply (const GtkCssValue *shadow,
+ cairo_t *cr)
+{
+ gdk_cairo_set_source_rgba (cr, _gtk_css_rgba_value_get_rgba (shadow->color));
+
+ cairo_translate (cr,
+ _gtk_css_number_value_get (shadow->hoffset, 0),
+ _gtk_css_number_value_get (shadow->voffset, 0));
+}
+
static cairo_t *
gtk_css_shadow_value_start_drawing (const GtkCssValue *shadow,
cairo_t *cr)
@@ -331,11 +342,7 @@ gtk_css_shadow_value_start_drawing (const GtkCssValue *shadow,
cairo_t *blur_cr;
gdouble radius, clip_radius;
- gdk_cairo_set_source_rgba (cr, _gtk_css_rgba_value_get_rgba (shadow->color));
-
- cairo_translate (cr,
- _gtk_css_number_value_get (shadow->hoffset, 0),
- _gtk_css_number_value_get (shadow->voffset, 0));
+ setup_cairo_for_shadow_apply (shadow, cr);
if (!needs_blur (shadow))
return cr;
@@ -389,6 +396,17 @@ gtk_css_shadow_value_finish_drawing (const GtkCssValue *shadow,
return original_cr;
}
+static char *
+shadow_value_get_hash_string (const GtkCssValue *shadow)
+{
+ /* We use this for caching blurred layouts, and layouts don't
+ * support spread, so we don't need to add spread here. */
+ return g_strdup_printf ("gtk+ shadow blur radius=%d spread=%d %s",
+ (int) _gtk_css_number_value_get (shadow->radius, 0),
+ (int) _gtk_css_number_value_get (shadow->spread, 0),
+ shadow->inset ? "inset=y" : "inset=n");
+}
+
void
_gtk_css_shadow_value_paint_layout (const GtkCssValue *shadow,
cairo_t *cr,
@@ -400,9 +418,33 @@ _gtk_css_shadow_value_paint_layout (const GtkCssValue *shadow,
cairo_move_to (cr, 0, 0);
cairo_save (cr);
- cr = gtk_css_shadow_value_start_drawing (shadow, cr);
- _gtk_pango_fill_layout (cr, layout);
- cr = gtk_css_shadow_value_finish_drawing (shadow, cr);
+ if (needs_blur (shadow))
+ {
+ char *hash_string = shadow_value_get_hash_string (shadow);
+ cairo_surface_t *cached_surface = g_object_get_data (G_OBJECT (layout), hash_string);
+ if (cached_surface)
+ {
+ setup_cairo_for_shadow_apply (shadow, cr);
+ cairo_mask_surface (cr, cached_surface, 0, 0);
+ }
+ else
+ {
+ cr = gtk_css_shadow_value_start_drawing (shadow, cr);
+ _gtk_pango_fill_layout (cr, layout);
+ cached_surface = cairo_get_target (cr);
+ g_object_set_data_full (G_OBJECT (layout), hash_string,
+ cairo_surface_reference (cached_surface),
+ (GDestroyNotify) cairo_surface_destroy);
+ cr = gtk_css_shadow_value_finish_drawing (shadow, cr);
+ }
+ g_free (hash_string);
+ }
+ else
+ {
+ cr = gtk_css_shadow_value_start_drawing (shadow, cr);
+ _gtk_pango_fill_layout (cr, layout);
+ cr = gtk_css_shadow_value_finish_drawing (shadow, cr);
+ }
cairo_restore (cr);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]