[librsvg/librsvg-2.44] DrawingCtx: store the view_box_stack in a RefCell
- From: Federico Mena Quintero <federico src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [librsvg/librsvg-2.44] DrawingCtx: store the view_box_stack in a RefCell
- Date: Fri, 21 Sep 2018 17:38:41 +0000 (UTC)
commit 1fb88338176564ea5662acbbd417b26c54c18742
Author: Federico Mena Quintero <federico gnome org>
Date: Tue Sep 4 17:01:51 2018 -0500
DrawingCtx: store the view_box_stack in a RefCell
So that push_view_box()/pop_view_box() don't need a mutable draw_ctx.
This should help with the Drop impl next.
rsvg_internals/src/drawing_ctx.rs | 24 ++++++++++++++----------
1 file changed, 14 insertions(+), 10 deletions(-)
---
diff --git a/rsvg_internals/src/drawing_ctx.rs b/rsvg_internals/src/drawing_ctx.rs
index 943fd0e3..3046e646 100644
--- a/rsvg_internals/src/drawing_ctx.rs
+++ b/rsvg_internals/src/drawing_ctx.rs
@@ -103,7 +103,7 @@ pub struct DrawingCtx<'a> {
surfaces_stack: Vec<cairo::ImageSurface>,
- view_box_stack: Vec<ViewBox>,
+ view_box_stack: RefCell<Vec<ViewBox>>,
bbox: BoundingBox,
bbox_stack: Vec<BoundingBox>,
@@ -160,7 +160,7 @@ impl<'a> DrawingCtx<'a> {
cr: cr.clone(),
initial_cr: cr.clone(),
surfaces_stack: Vec::new(),
- view_box_stack,
+ view_box_stack: RefCell::new(view_box_stack),
bbox: BoundingBox::new(&affine),
bbox_stack: Vec::new(),
drawsub_stack: Vec::new(),
@@ -215,25 +215,29 @@ impl<'a> DrawingCtx<'a> {
// push_view_box() / pop_view_box() pair. How do we make this
// safe?
pub fn get_view_params(&self) -> ViewParams {
- let last = self.view_box_stack.len() - 1;
+ let view_box_stack = self.view_box_stack.borrow();
+ let last = view_box_stack.len() - 1;
ViewParams {
dpi_x: self.dpi_x,
dpi_y: self.dpi_y,
- view_box_width: self.view_box_stack[last].0.width,
- view_box_height: self.view_box_stack[last].0.height,
+ view_box_width: view_box_stack[last].0.width,
+ view_box_height: view_box_stack[last].0.height,
}
}
- pub fn push_view_box(&mut self, width: f64, height: f64) -> ViewParams {
- self.view_box_stack
- .push(ViewBox::new(0.0, 0.0, width, height));
+ pub fn push_view_box(&self, width: f64, height: f64) -> ViewParams {
+ {
+ let mut view_box_stack = self.view_box_stack.borrow_mut();
+
+ view_box_stack.push(ViewBox::new(0.0, 0.0, width, height));
+ }
self.get_view_params()
}
- pub fn pop_view_box(&mut self) {
- self.view_box_stack.pop();
+ pub fn pop_view_box(&self) {
+ self.view_box_stack.borrow_mut().pop();
}
pub fn insert_bbox(&mut self, bbox: &BoundingBox) {
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]