[librsvg: 15/90] Don't mutate the DrawingCtx's bbox in the clipping code



commit c3177591dac12f74f8c1fd1b6fd0c25ca2fc1312
Author: Federico Mena Quintero <federico gnome org>
Date:   Mon Mar 11 13:45:31 2019 -0600

    Don't mutate the DrawingCtx's bbox in the clipping code
    
    The idea is for now to keep the running bbox computation as part of
    the mutable DrawingCtx, but where the final bbox is *used* should just
    be immutable:  we'll pass the final bbox as an argument to whatever
    needs it.

 rsvg_internals/src/clip_path.rs   | 14 ++++----------
 rsvg_internals/src/drawing_ctx.rs | 20 +++++++++++++-------
 2 files changed, 17 insertions(+), 17 deletions(-)
---
diff --git a/rsvg_internals/src/clip_path.rs b/rsvg_internals/src/clip_path.rs
index 9b7a76b7..9c22c1a8 100644
--- a/rsvg_internals/src/clip_path.rs
+++ b/rsvg_internals/src/clip_path.rs
@@ -3,6 +3,7 @@ use std::cell::Cell;
 use cairo::{self, MatrixTrait};
 
 use crate::attributes::Attribute;
+use crate::bbox::BoundingBox;
 use crate::coord_units::CoordUnits;
 use crate::drawing_ctx::DrawingCtx;
 use crate::error::RenderingError;
@@ -32,21 +33,20 @@ impl NodeClipPath {
         node: &RsvgNode,
         affine_before_clip: &cairo::Matrix,
         draw_ctx: &mut DrawingCtx,
+        bbox: &BoundingBox,
     ) -> Result<(), RenderingError> {
         let cascaded = node.get_cascaded_values();
 
         let clip_units = self.units.get();
 
-        let orig_bbox = draw_ctx.get_bbox().clone();
-
         let child_matrix = if clip_units == ClipPathUnits(CoordUnits::ObjectBoundingBox) {
-            if orig_bbox.rect.is_none() {
+            if bbox.rect.is_none() {
                 // The node being clipped is empty / doesn't have a
                 // bounding box, so there's nothing to clip!
                 return Ok(());
             }
 
-            let rect = orig_bbox.rect.unwrap();
+            let rect = bbox.rect.as_ref().unwrap();
 
             let bbtransform = cairo::Matrix::new(rect.width, 0.0, 0.0, rect.height, rect.x, rect.y);
             cairo::Matrix::multiply(&bbtransform, affine_before_clip)
@@ -63,12 +63,6 @@ impl NodeClipPath {
 
         cr.set_matrix(save_affine);
 
-        // FIXME: this is an EPIC HACK to keep the clipping context from
-        // accumulating bounding boxes.  We'll remove this later, when we
-        // are able to extract bounding boxes from outside the
-        // general drawing loop.
-        draw_ctx.set_bbox(&orig_bbox);
-
         let cr = draw_ctx.get_cairo_context();
         cr.clip();
 
diff --git a/rsvg_internals/src/drawing_ctx.rs b/rsvg_internals/src/drawing_ctx.rs
index 3cbe3cfd..25906995 100644
--- a/rsvg_internals/src/drawing_ctx.rs
+++ b/rsvg_internals/src/drawing_ctx.rs
@@ -292,10 +292,6 @@ impl DrawingCtx {
         self.bbox.insert(bbox);
     }
 
-    pub fn set_bbox(&mut self, bbox: &BoundingBox) {
-        self.bbox = *bbox;
-    }
-
     pub fn get_bbox(&self) -> &BoundingBox {
         &self.bbox
     }
@@ -391,9 +387,19 @@ impl DrawingCtx {
         clip_node: Option<RsvgNode>,
     ) -> Result<(), RenderingError> {
         if let Some(clip_node) = clip_node {
-            clip_node.with_impl(|clip_path: &NodeClipPath| {
-                clip_path.to_cairo_context(&clip_node, affine, self)
-            })
+            let orig_bbox = self.bbox;
+
+            let res = clip_node.with_impl(|clip_path: &NodeClipPath| {
+                clip_path.to_cairo_context(&clip_node, affine, self, &orig_bbox)
+            });
+
+            // FIXME: this is an EPIC HACK to keep the clipping context from
+            // accumulating bounding boxes.  We'll remove this later, when we
+            // are able to extract bounding boxes from outside the
+            // general drawing loop.
+            self.bbox = orig_bbox;
+
+            res
         } else {
             Ok(())
         }


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