[librsvg] generate_cairo_mask(): Return the mask surface instead of masking here



commit 90742ad96d866ce79b2f90860f78da2c43c0c38b
Author: Federico Mena Quintero <federico gnome org>
Date:   Wed Oct 23 15:29:56 2019 -0500

    generate_cairo_mask(): Return the mask surface instead of masking here
    
    Have the calling DrawingCtx be the one who applies the mask to the cr.
    
    This gets rid of the last place where something outside of
    drawing_ctx.rs does set_matrix() on the draw_ctx's current cr.

 rsvg_internals/src/drawing_ctx.rs |  7 +++++++
 rsvg_internals/src/mask.rs        | 13 +++----------
 2 files changed, 10 insertions(+), 10 deletions(-)
---
diff --git a/rsvg_internals/src/drawing_ctx.rs b/rsvg_internals/src/drawing_ctx.rs
index 07275734..ad97c99a 100644
--- a/rsvg_internals/src/drawing_ctx.rs
+++ b/rsvg_internals/src/drawing_ctx.rs
@@ -496,6 +496,13 @@ impl DrawingCtx {
                                     .borrow()
                                     .get_impl::<NodeMask>()
                                     .generate_cairo_mask(&mask_node, &affines, dc, &bbox)
+                                    .and_then(|mask_surf| {
+                                        if let Some(surf) = mask_surf {
+                                            dc.cr.set_matrix(affines.compositing);
+                                            dc.cr.mask_surface(&surf, 0.0, 0.0);
+                                        }
+                                        Ok(())
+                                    })
                                     .map(|_: ()| bbox)
                             });
                         } else {
diff --git a/rsvg_internals/src/mask.rs b/rsvg_internals/src/mask.rs
index 8226d60b..550d2703 100644
--- a/rsvg_internals/src/mask.rs
+++ b/rsvg_internals/src/mask.rs
@@ -54,11 +54,11 @@ impl NodeMask {
         affines: &CompositingAffines,
         draw_ctx: &mut DrawingCtx,
         bbox: &BoundingBox,
-    ) -> Result<(), RenderingError> {
+    ) -> Result<Option<cairo::ImageSurface>, RenderingError> {
         if bbox.rect.is_none() {
             // The node being masked is empty / doesn't have a
             // bounding box, so there's nothing to mask!
-            return Ok(());
+            return Ok(None);
         }
 
         let bbox_rect = bbox.rect.as_ref().unwrap();
@@ -139,14 +139,7 @@ impl NodeMask {
         let mask_content_surface =
             SharedImageSurface::new(mask_content_surface, SurfaceType::SRgb)?;
 
-        let mask_surface = compute_luminance_to_alpha(&mask_content_surface, opacity)?;
-
-        let cr = draw_ctx.get_cairo_context();
-        cr.set_matrix(affines.compositing);
-
-        cr.mask_surface(&mask_surface, 0.0, 0.0);
-
-        Ok(())
+        Ok(Some(compute_luminance_to_alpha(&mask_content_surface, opacity)?))
     }
 }
 


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