[librsvg] flood: move cairo implementation to surface_utils



commit ff867b58dcb58714b3902eee057b2f96e2c2c1a8
Author: Paolo Borelli <pborelli gnome org>
Date:   Mon Jan 6 12:23:59 2020 +0100

    flood: move cairo implementation to surface_utils

 rsvg_internals/src/filters/flood.rs                | 33 +++++-----------------
 rsvg_internals/src/surface_utils/shared_surface.rs | 29 +++++++++++++++++++
 2 files changed, 36 insertions(+), 26 deletions(-)
---
diff --git a/rsvg_internals/src/filters/flood.rs b/rsvg_internals/src/filters/flood.rs
index 824c30d8..463f76ed 100644
--- a/rsvg_internals/src/filters/flood.rs
+++ b/rsvg_internals/src/filters/flood.rs
@@ -1,7 +1,6 @@
 use crate::drawing_ctx::DrawingCtx;
 use crate::node::{CascadedValues, NodeResult, NodeTrait, RsvgNode};
 use crate::property_bag::PropertyBag;
-use crate::surface_utils::shared_surface::{SharedImageSurface, SurfaceType};
 
 use super::context::{FilterContext, FilterOutput, FilterResult};
 use super::{FilterEffect, FilterError, Primitive};
@@ -39,12 +38,6 @@ impl FilterEffect for FeFlood {
     ) -> Result<FilterResult, FilterError> {
         let bounds = self.base.get_bounds(ctx).into_irect(draw_ctx);
 
-        let output_surface = cairo::ImageSurface::create(
-            cairo::Format::ARgb32,
-            ctx.source_graphic().width(),
-            ctx.source_graphic().height(),
-        )?;
-
         let cascaded = CascadedValues::new_from_node(node);
         let values = cascaded.get();
 
@@ -52,29 +45,17 @@ impl FilterEffect for FeFlood {
             cssparser::Color::CurrentColor => values.color.0,
             cssparser::Color::RGBA(rgba) => rgba,
         };
-        let opacity = (values.flood_opacity.0).0;
-
-        if opacity > 0f64 {
-            let cr = cairo::Context::new(&output_surface);
-            let r = cairo::Rectangle::from(bounds);
-            cr.rectangle(r.x, r.y, r.width, r.height);
-            cr.clip();
+        let opacity = values.flood_opacity.0;
 
-            cr.set_source_rgba(
-                f64::from(color.red) / 255f64,
-                f64::from(color.green) / 255f64,
-                f64::from(color.blue) / 255f64,
-                opacity,
-            );
-            cr.paint();
-        }
+        let surface = ctx.source_graphic().flood(
+            bounds,
+            color,
+            opacity,
+        )?;
 
         Ok(FilterResult {
             name: self.base.result.clone(),
-            output: FilterOutput {
-                surface: SharedImageSurface::new(output_surface, SurfaceType::SRgb)?,
-                bounds,
-            },
+            output: FilterOutput { surface, bounds },
         })
     }
 
diff --git a/rsvg_internals/src/surface_utils/shared_surface.rs 
b/rsvg_internals/src/surface_utils/shared_surface.rs
index f96c5fcf..5dd53979 100644
--- a/rsvg_internals/src/surface_utils/shared_surface.rs
+++ b/rsvg_internals/src/surface_utils/shared_surface.rs
@@ -903,6 +903,35 @@ impl SharedImageSurface {
         SharedImageSurface::new(output_surface, self.surface_type)
     }
 
+    /// Fills the with a specified color.
+    #[inline]
+    pub fn flood(
+        &self,
+        bounds: IRect,
+        color: cssparser::RGBA,
+        opacity: UnitInterval,
+    ) -> Result<SharedImageSurface, cairo::Status> {
+        let output_surface =
+            cairo::ImageSurface::create(cairo::Format::ARgb32, self.width, self.height)?;
+
+        if opacity.0 > 0.0 {
+            let cr = cairo::Context::new(&output_surface);
+            let r = cairo::Rectangle::from(bounds);
+            cr.rectangle(r.x, r.y, r.width, r.height);
+            cr.clip();
+
+            cr.set_source_rgba(
+                f64::from(color.red) / 255f64,
+                f64::from(color.green) / 255f64,
+                f64::from(color.blue) / 255f64,
+                opacity.0,
+            );
+            cr.paint();
+        }
+
+        SharedImageSurface::new(output_surface, self.surface_type)
+    }
+
     /// Performs the combination of two input surfaces using Porter-Duff
     /// compositing operators
     ///


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