[librsvg] state: Resolve filters lazily



commit 9fc56102ca1861e3868fd6dcbcc3cc0f3c240f3e
Author: Benjamin Otte <otte redhat com>
Date:   Wed Oct 7 10:37:22 2015 +0200

    state: Resolve filters lazily
    
    We're almost there resolving everything lazily...

 rsvg-cairo-draw.c |   17 +++++++++++------
 rsvg-filter.c     |   27 ---------------------------
 rsvg-filter.h     |    2 --
 rsvg-styles.c     |   12 ++++++++----
 rsvg-styles.h     |    2 +-
 5 files changed, 20 insertions(+), 40 deletions(-)
---
diff --git a/rsvg-cairo-draw.c b/rsvg-cairo-draw.c
index 0d00f9f..fd77fff 100644
--- a/rsvg-cairo-draw.c
+++ b/rsvg-cairo-draw.c
@@ -827,17 +827,22 @@ rsvg_cairo_pop_render_stack (RsvgDrawingCtx * ctx)
         && (state->enable_background == RSVG_ENABLE_BACKGROUND_ACCUMULATE))
         return;
 
+    surface = cairo_get_target (child_cr);
+
     if (state->filter) {
+        RsvgNode *filter;
         cairo_surface_t *output;
 
-        output = render->surfaces_stack->data;
-        render->surfaces_stack = g_list_delete_link (render->surfaces_stack, render->surfaces_stack);
+        filter = rsvg_acquire_node (ctx, state->filter);
+        if (filter && RSVG_NODE_TYPE (filter) == RSVG_NODE_TYPE_FILTER) {
+            output = render->surfaces_stack->data;
+            render->surfaces_stack = g_list_delete_link (render->surfaces_stack, render->surfaces_stack);
 
-        surface = rsvg_filter_render (state->filter, output, ctx, &render->bbox, "2103");
+            surface = rsvg_filter_render ((RsvgFilter *) filter, output, ctx, &render->bbox, "2103");
+            /* Don't destroy the output surface, it's owned by child_cr */
+        }
 
-        /* Don't destroy the output surface, it's owned by child_cr */
-    } else {
-        surface = cairo_get_target (child_cr);
+        rsvg_release_node (ctx, filter);
     }
 
     render->cr = (cairo_t *) render->cr_stack->data;
diff --git a/rsvg-filter.c b/rsvg-filter.c
index a8f6a27..db6e21f 100644
--- a/rsvg-filter.c
+++ b/rsvg-filter.c
@@ -720,33 +720,6 @@ rsvg_filter_get_in (GString * name, RsvgFilterContext * ctx)
     return rsvg_filter_get_result (name, ctx).surface;
 }
 
-/**
- * rsvg_filter_parse:
- * @defs: a pointer to the hash of definitions
- * @str: a string with the name of the filter to be looked up
- *
- * Looks up an allready created filter.
- *
- * Returns: (nullable): a pointer to the filter that the name refers to, or %NULL
- * if none was found
- **/
-RsvgFilter *
-rsvg_filter_parse (const RsvgDefs * defs, const char *str)
-{
-    char *name;
-
-    name = rsvg_get_url_string (str);
-    if (name) {
-        RsvgNode *val;
-        val = rsvg_defs_lookup (defs, name);
-        g_free (name);
-
-        if (val && RSVG_NODE_TYPE (val) == RSVG_NODE_TYPE_FILTER)
-            return (RsvgFilter *) val;
-    }
-    return NULL;
-}
-
 static void
 rsvg_filter_set_args (RsvgNode * self, RsvgHandle * ctx, RsvgPropertyBag * atts)
 {
diff --git a/rsvg-filter.h b/rsvg-filter.h
index 0c87a09..12038fe 100644
--- a/rsvg-filter.h
+++ b/rsvg-filter.h
@@ -54,8 +54,6 @@ cairo_surface_t *rsvg_filter_render (RsvgFilter *self,
 G_GNUC_INTERNAL
 RsvgNode    *rsvg_new_filter       (void);
 G_GNUC_INTERNAL
-RsvgFilter  *rsvg_filter_parse     (const RsvgDefs * defs, const char *str);
-G_GNUC_INTERNAL
 RsvgNode    *rsvg_new_filter_primitive_blend                (void);
 G_GNUC_INTERNAL
 RsvgNode    *rsvg_new_filter_primitive_convolve_matrix      (void);
diff --git a/rsvg-styles.c b/rsvg-styles.c
index 6966cba..b6197a4 100644
--- a/rsvg-styles.c
+++ b/rsvg-styles.c
@@ -221,6 +221,7 @@ rsvg_state_clone (RsvgState * dst, const RsvgState * src)
 
     *dst = *src;
     dst->parent = parent;
+    dst->filter = g_strdup (src->filter);
     dst->mask = g_strdup (src->mask);
     dst->clip_path = g_strdup (src->clip_path);
     dst->font_family = g_strdup (src->font_family);
@@ -361,10 +362,11 @@ rsvg_state_inherit_run (RsvgState * dst, const RsvgState * src,
         dst->clip_path = g_strdup (src->clip_path);
         g_free (dst->mask);
         dst->mask = g_strdup (src->mask);
+        g_free (dst->filter);
+        dst->filter = g_strdup (src->filter);
         dst->enable_background = src->enable_background;
         dst->adobe_blend = src->adobe_blend;
         dst->opacity = src->opacity;
-        dst->filter = src->filter;
         dst->comp_op = src->comp_op;
     }
 }
@@ -448,6 +450,7 @@ rsvg_state_inherit (RsvgState * dst, const RsvgState * src)
 void
 rsvg_state_finalize (RsvgState * state)
 {
+    g_free (state->filter);
     g_free (state->mask);
     g_free (state->clip_path);
     g_free (state->font_family);
@@ -494,9 +497,10 @@ rsvg_parse_style_pair (RsvgHandle * ctx,
     else if (g_str_equal (name, "flood-opacity")) {
         state->flood_opacity = rsvg_css_parse_opacity (value);
         state->has_flood_opacity = TRUE;
-    } else if (g_str_equal (name, "filter"))
-        state->filter = rsvg_filter_parse (ctx->priv->defs, value);
-    else if (g_str_equal (name, "a:adobe-blending-mode")) {
+    } else if (g_str_equal (name, "filter")) {
+        g_free (state->filter);
+        state->filter = rsvg_get_url_string (value);
+    } else if (g_str_equal (name, "a:adobe-blending-mode")) {
         if (g_str_equal (value, "normal"))
             state->adobe_blend = 0;
         else if (g_str_equal (value, "multiply"))
diff --git a/rsvg-styles.h b/rsvg-styles.h
index 92cc48f..300cbee 100644
--- a/rsvg-styles.h
+++ b/rsvg-styles.h
@@ -79,7 +79,7 @@ struct _RsvgState {
     cairo_matrix_t affine;
     cairo_matrix_t personal_affine;
 
-    RsvgFilter *filter;
+    char *filter;
     char *mask;
     char *clip_path;
     guint8 adobe_blend;         /* 0..11 */


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