[librsvg: 6/23] feBlend - resolve and render separately




commit 3fbf45ed59bb4d45e93e9a8b6912f1882c25c883
Author: Federico Mena Quintero <federico gnome org>
Date:   Thu Mar 11 13:11:53 2021 -0600

    feBlend - resolve and render separately

 src/filters/blend.rs | 42 +++++++++++++++++++++++++++++++++---------
 src/filters/mod.rs   |  6 +++---
 2 files changed, 36 insertions(+), 12 deletions(-)
---
diff --git a/src/filters/blend.rs b/src/filters/blend.rs
index 5940dbad..cb36cc31 100755
--- a/src/filters/blend.rs
+++ b/src/filters/blend.rs
@@ -7,6 +7,7 @@ use crate::element::{ElementResult, SetAttributes};
 use crate::error::*;
 use crate::node::{CascadedValues, Node};
 use crate::parsers::{Parse, ParseValue};
+use crate::property_defs::ColorInterpolationFilters;
 use crate::xml::Attributes;
 
 use super::context::{FilterContext, FilterOutput, FilterResult};
@@ -43,6 +44,15 @@ pub struct FeBlend {
     mode: Mode,
 }
 
+/// Resolved `feBlend` primitive for rendering.
+pub struct Blend {
+    base: Primitive,
+    in1: Input,
+    in2: Input,
+    mode: Mode,
+    color_interpolation_filters: ColorInterpolationFilters,
+}
+
 impl Default for FeBlend {
     /// Constructs a new `Blend` with empty properties.
     #[inline]
@@ -72,20 +82,25 @@ impl SetAttributes for FeBlend {
     }
 }
 
-impl FeBlend {
+impl Blend {
     pub fn render(
         &self,
-        node: &Node,
         ctx: &FilterContext,
         acquired_nodes: &mut AcquiredNodes<'_>,
         draw_ctx: &mut DrawingCtx,
     ) -> Result<FilterResult, FilterError> {
-        let cascaded = CascadedValues::new_from_node(node);
-        let values = cascaded.get();
-        let cif = values.color_interpolation_filters();
-
-        let input_1 = ctx.get_input(acquired_nodes, draw_ctx, &self.in1, cif)?;
-        let input_2 = ctx.get_input(acquired_nodes, draw_ctx, &self.in2, cif)?;
+        let input_1 = ctx.get_input(
+            acquired_nodes,
+            draw_ctx,
+            &self.in1,
+            self.color_interpolation_filters,
+        )?;
+        let input_2 = ctx.get_input(
+            acquired_nodes,
+            draw_ctx,
+            &self.in2,
+            self.color_interpolation_filters,
+        )?;
         let bounds = self
             .base
             .get_bounds(ctx)?
@@ -108,7 +123,16 @@ impl FeBlend {
 
 impl FilterEffect for FeBlend {
     fn resolve(&self, node: &Node) -> Result<PrimitiveParams, FilterError> {
-        Ok(PrimitiveParams::Blend(node.clone()))
+        let cascaded = CascadedValues::new_from_node(node);
+        let values = cascaded.get();
+
+        Ok(PrimitiveParams::Blend(Blend {
+            base: self.base.clone(),
+            in1: self.in1.clone(),
+            in2: self.in2.clone(),
+            mode: self.mode.clone(),
+            color_interpolation_filters: values.color_interpolation_filters(),
+        }))
     }
 }
 
diff --git a/src/filters/mod.rs b/src/filters/mod.rs
index 66e364f9..4afd3b77 100644
--- a/src/filters/mod.rs
+++ b/src/filters/mod.rs
@@ -52,7 +52,6 @@ pub mod offset;
 pub mod tile;
 pub mod turbulence;
 
-use blend::FeBlend;
 use color_matrix::FeColorMatrix;
 use component_transfer::FeComponentTransfer;
 use composite::FeComposite;
@@ -75,7 +74,7 @@ use turbulence::FeTurbulence;
 /// and parameters extracted from the element's children (for example,
 /// `feMerge` gathers info from its `feMergNode` children).
 pub enum PrimitiveParams {
-    Blend(Node),
+    Blend(blend::Blend),
     ColorMatrix(Node),
     ComponentTransfer(Node),
     Composite(Node),
@@ -94,6 +93,7 @@ pub enum PrimitiveParams {
 }
 
 /// The base filter primitive node containing common properties.
+#[derive(Clone)]
 struct Primitive {
     x: Option<Length<Horizontal>>,
     y: Option<Length<Vertical>>,
@@ -325,7 +325,7 @@ fn render_primitive(
     let elt = &*elt;
 
     match (elt, params) {
-        (Element::FeBlend(ref inner), Blend(node))                         => 
FeBlend::render(&inner.element_impl, &node, ctx, acquired_nodes, draw_ctx),
+        (Element::FeBlend(_), Blend(p))                         => p.render(ctx, acquired_nodes, draw_ctx),
         (Element::FeColorMatrix(ref inner), ColorMatrix(node))             => 
FeColorMatrix::render(&inner.element_impl, &node, ctx, acquired_nodes, draw_ctx),
         (Element::FeComponentTransfer(ref inner), ComponentTransfer(node)) => 
FeComponentTransfer::render(&inner.element_impl, &node, ctx, acquired_nodes, draw_ctx),
         (Element::FeComposite(ref inner), Composite(node))                 => 
FeComposite::render(&inner.element_impl, &node, ctx, acquired_nodes, draw_ctx),


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