[librsvg: 6/14] drawing_ctx: add mask_surface method



commit e73f0ada0f169f3893c3f48e9960706ab5c4a8a2
Author: Paolo Borelli <pborelli gnome org>
Date:   Sat Jan 5 12:00:53 2019 +0100

    drawing_ctx: add mask_surface method
    
    This allows to make get_offset private

 rsvg_internals/src/drawing_ctx.rs | 33 +++++++++++++++++++++------------
 rsvg_internals/src/mask.rs        |  9 +--------
 2 files changed, 22 insertions(+), 20 deletions(-)
---
diff --git a/rsvg_internals/src/drawing_ctx.rs b/rsvg_internals/src/drawing_ctx.rs
index c31fbc33..6a2e82b6 100644
--- a/rsvg_internals/src/drawing_ctx.rs
+++ b/rsvg_internals/src/drawing_ctx.rs
@@ -201,18 +201,6 @@ impl DrawingCtx {
         self.rect.height
     }
 
-    fn is_cairo_context_nested(&self, cr: &cairo::Context) -> bool {
-        cr.to_raw_none() != self.initial_cr.to_raw_none()
-    }
-
-    pub fn get_offset(&self) -> (f64, f64) {
-        if self.is_cairo_context_nested(&self.get_cairo_context()) {
-            (0.0, 0.0)
-        } else {
-            (self.rect.x, self.rect.y)
-        }
-    }
-
     /// Gets the viewport that was last pushed with `push_view_box()`.
     pub fn get_view_params(&self) -> ViewParams {
         let view_box_stack = self.view_box_stack.borrow();
@@ -320,6 +308,18 @@ impl DrawingCtx {
             })
     }
 
+    fn is_cairo_context_nested(&self, cr: &cairo::Context) -> bool {
+        cr.to_raw_none() != self.initial_cr.to_raw_none()
+    }
+
+    fn get_offset(&self) -> (f64, f64) {
+        if self.is_cairo_context_nested(&self.get_cairo_context()) {
+            (0.0, 0.0)
+        } else {
+            (self.rect.x, self.rect.y)
+        }
+    }
+
     pub fn with_discrete_layer(
         &mut self,
         node: &RsvgNode,
@@ -776,6 +776,15 @@ impl DrawingCtx {
         res
     }
 
+    pub fn mask_surface(&mut self, mask: &cairo::ImageSurface) {
+        let cr = self.get_cairo_context();
+
+        cr.identity_matrix();
+
+        let (xofs, yofs) = self.get_offset();
+        cr.mask_surface(&mask, xofs, yofs);
+    }
+
     pub fn add_node_and_ancestors_to_stack(&mut self, node: &RsvgNode) {
         self.drawsub_stack.push(node.clone());
         if let Some(ref parent) = node.get_parent() {
diff --git a/rsvg_internals/src/mask.rs b/rsvg_internals/src/mask.rs
index 7b70b9f2..dc67cea5 100644
--- a/rsvg_internals/src/mask.rs
+++ b/rsvg_internals/src/mask.rs
@@ -148,15 +148,8 @@ impl NodeMask {
         }?;
 
         let Opacity(opacity) = values.opacity;
-
         let mask_surface = compute_luminance_to_alpha(surface, opacity)?;
-
-        let cr = draw_ctx.get_cairo_context();
-
-        cr.identity_matrix();
-
-        let (xofs, yofs) = draw_ctx.get_offset();
-        cr.mask_surface(&mask_surface, xofs, yofs);
+        draw_ctx.mask_surface(&mask_surface);
 
         Ok(())
     }


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