[librsvg: 8/9] ImageSurface::compose - take our own Operator, not cairo::Operator




commit c04e08dd788dbb8b5b341aafa4b1da88cfdd82ac
Author: Federico Mena Quintero <federico gnome org>
Date:   Fri May 28 18:41:31 2021 -0500

    ImageSurface::compose - take our own Operator, not cairo::Operator
    
    This may seem superfluous, but it moves ImageSurface closer to being
    able to be ported away from Cairo.

 src/filters/blend.rs                | 45 +++++++++++++++++++------------------
 src/filters/composite.rs            | 28 ++++++++++++-----------
 src/filters/merge.rs                |  4 ++--
 src/surface_utils/shared_surface.rs |  6 ++---
 4 files changed, 43 insertions(+), 40 deletions(-)
---
diff --git a/src/filters/blend.rs b/src/filters/blend.rs
index 9169265c..512fc10f 100644
--- a/src/filters/blend.rs
+++ b/src/filters/blend.rs
@@ -9,6 +9,7 @@ use crate::node::{CascadedValues, Node};
 use crate::parsers::{Parse, ParseValue};
 use crate::property_defs::ColorInterpolationFilters;
 use crate::rect::IRect;
+use crate::surface_utils::shared_surface::Operator;
 use crate::xml::Attributes;
 
 use super::bounds::BoundsBuilder;
@@ -100,11 +101,9 @@ impl Blend {
             .clipped
             .into();
 
-        let surface = input_1.surface().compose(
-            input_2.surface(),
-            bounds,
-            cairo::Operator::from(self.mode),
-        )?;
+        let surface = input_1
+            .surface()
+            .compose(input_2.surface(), bounds, self.mode.into())?;
 
         Ok(FilterOutput { surface, bounds })
     }
@@ -153,26 +152,28 @@ impl Parse for Mode {
     }
 }
 
-impl From<Mode> for cairo::Operator {
+impl From<Mode> for Operator {
     #[inline]
     fn from(x: Mode) -> Self {
+        use Mode::*;
+
         match x {
-            Mode::Normal => cairo::Operator::Over,
-            Mode::Multiply => cairo::Operator::Multiply,
-            Mode::Screen => cairo::Operator::Screen,
-            Mode::Darken => cairo::Operator::Darken,
-            Mode::Lighten => cairo::Operator::Lighten,
-            Mode::Overlay => cairo::Operator::Overlay,
-            Mode::ColorDodge => cairo::Operator::ColorDodge,
-            Mode::ColorBurn => cairo::Operator::ColorBurn,
-            Mode::HardLight => cairo::Operator::HardLight,
-            Mode::SoftLight => cairo::Operator::SoftLight,
-            Mode::Difference => cairo::Operator::Difference,
-            Mode::Exclusion => cairo::Operator::Exclusion,
-            Mode::HslHue => cairo::Operator::HslHue,
-            Mode::HslSaturation => cairo::Operator::HslSaturation,
-            Mode::HslColor => cairo::Operator::HslColor,
-            Mode::HslLuminosity => cairo::Operator::HslLuminosity,
+            Normal => Operator::Over,
+            Multiply => Operator::Multiply,
+            Screen => Operator::Screen,
+            Darken => Operator::Darken,
+            Lighten => Operator::Lighten,
+            Overlay => Operator::Overlay,
+            ColorDodge => Operator::ColorDodge,
+            ColorBurn => Operator::ColorBurn,
+            HardLight => Operator::HardLight,
+            SoftLight => Operator::SoftLight,
+            Difference => Operator::Difference,
+            Exclusion => Operator::Exclusion,
+            HslHue => Operator::HslHue,
+            HslSaturation => Operator::HslSaturation,
+            HslColor => Operator::HslColor,
+            HslLuminosity => Operator::HslLuminosity,
         }
     }
 }
diff --git a/src/filters/composite.rs b/src/filters/composite.rs
index feae2cf1..7ffc6c1d 100644
--- a/src/filters/composite.rs
+++ b/src/filters/composite.rs
@@ -9,6 +9,7 @@ use crate::node::{CascadedValues, Node};
 use crate::parsers::{Parse, ParseValue};
 use crate::property_defs::ColorInterpolationFilters;
 use crate::rect::IRect;
+use crate::surface_utils::shared_surface::Operator as SurfaceOperator;
 use crate::xml::Attributes;
 
 use super::bounds::BoundsBuilder;
@@ -109,11 +110,9 @@ impl Composite {
                 self.k4,
             )?
         } else {
-            input_1.surface().compose(
-                input_2.surface(),
-                bounds,
-                cairo::Operator::from(self.operator),
-            )?
+            input_1
+                .surface()
+                .compose(input_2.surface(), bounds, self.operator.into())?
         };
 
         Ok(FilterOutput { surface, bounds })
@@ -153,16 +152,19 @@ impl Parse for Operator {
     }
 }
 
-impl From<Operator> for cairo::Operator {
+impl From<Operator> for SurfaceOperator {
     #[inline]
-    fn from(x: Operator) -> Self {
+    fn from(x: Operator) -> SurfaceOperator {
+        use Operator::*;
+
         match x {
-            Operator::Over => cairo::Operator::Over,
-            Operator::In => cairo::Operator::In,
-            Operator::Out => cairo::Operator::Out,
-            Operator::Atop => cairo::Operator::Atop,
-            Operator::Xor => cairo::Operator::Xor,
-            _ => panic!("can't convert Operator::Arithmetic to a cairo::Operator"),
+            Over => SurfaceOperator::Over,
+            In => SurfaceOperator::In,
+            Out => SurfaceOperator::Out,
+            Atop => SurfaceOperator::Atop,
+            Xor => SurfaceOperator::Xor,
+
+            _ => panic!("can't convert Operator::Arithmetic to a shared_surface::Operator"),
         }
     }
 }
diff --git a/src/filters/merge.rs b/src/filters/merge.rs
index 0e4ad8a4..e616c0ea 100644
--- a/src/filters/merge.rs
+++ b/src/filters/merge.rs
@@ -7,7 +7,7 @@ use crate::node::{CascadedValues, Node, NodeBorrow};
 use crate::parsers::ParseValue;
 use crate::property_defs::ColorInterpolationFilters;
 use crate::rect::IRect;
-use crate::surface_utils::shared_surface::{SharedImageSurface, SurfaceType};
+use crate::surface_utils::shared_surface::{Operator, SharedImageSurface, SurfaceType};
 use crate::xml::Attributes;
 
 use super::bounds::BoundsBuilder;
@@ -93,7 +93,7 @@ impl MergeNode {
 
         input
             .surface()
-            .compose(&output_surface.unwrap(), bounds, cairo::Operator::Over)
+            .compose(&output_surface.unwrap(), bounds, Operator::Over)
             .map_err(FilterError::CairoError)
     }
 }
diff --git a/src/surface_utils/shared_surface.rs b/src/surface_utils/shared_surface.rs
index 480e06f2..ed64dcdc 100644
--- a/src/surface_utils/shared_surface.rs
+++ b/src/surface_utils/shared_surface.rs
@@ -1125,7 +1125,7 @@ impl ImageSurface<Shared> {
     }
 
     /// Performs the combination of two input surfaces using Porter-Duff
-    /// compositing operators
+    /// compositing operators.
     ///
     /// # Panics
     /// Panics if the two surface types are not compatible.
@@ -1134,7 +1134,7 @@ impl ImageSurface<Shared> {
         &self,
         other: &SharedImageSurface,
         bounds: IRect,
-        operator: cairo::Operator,
+        operator: Operator,
     ) -> Result<SharedImageSurface, cairo::Error> {
         let output_surface = other.copy_surface(bounds)?;
 
@@ -1145,7 +1145,7 @@ impl ImageSurface<Shared> {
             cr.clip();
 
             self.set_as_source_surface(&cr, 0.0, 0.0);
-            cr.set_operator(operator);
+            cr.set_operator(operator.into());
             cr.paint();
         }
 


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