[librsvg: 1/22] svg: store handle interally
- From: Federico Mena Quintero <federico src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [librsvg: 1/22] svg: store handle interally
- Date: Tue, 8 Jan 2019 17:53:17 +0000 (UTC)
commit 93f3dbbb25ef27a9bad3bb7b9a7fc03e4ba7ceff
Author: Paolo Borelli <pborelli gnome org>
Date: Sun Jan 6 13:01:40 2019 +0100
svg: store handle interally
Store the handle into the Svg object... this is a bit incestous
because handle in turns owns a Rc of svg. However this allows
us to make drawing_ctx not use handle anymore.
rsvg_internals/src/drawing_ctx.rs | 16 ++++++++++------
rsvg_internals/src/handle.rs | 26 +++++---------------------
rsvg_internals/src/svg.rs | 13 +++++++++++--
rsvg_internals/src/xml.rs | 1 +
4 files changed, 27 insertions(+), 29 deletions(-)
---
diff --git a/rsvg_internals/src/drawing_ctx.rs b/rsvg_internals/src/drawing_ctx.rs
index 6a2e82b6..fe3223f3 100644
--- a/rsvg_internals/src/drawing_ctx.rs
+++ b/rsvg_internals/src/drawing_ctx.rs
@@ -13,7 +13,6 @@ use dpi::Dpi;
use error::RenderingError;
use filters;
use gradient::NodeGradient;
-use handle::{self, RsvgHandle};
use length::Dasharray;
use mask::NodeMask;
use node::{CascadedValues, NodeType, RsvgNode};
@@ -31,6 +30,7 @@ use state::{
StrokeLinecap,
StrokeLinejoin,
};
+use svg::Svg;
use unit_interval::UnitInterval;
use viewbox::ViewBox;
@@ -92,7 +92,7 @@ impl Drop for ViewParams {
}
pub struct DrawingCtx {
- handle: *const RsvgHandle,
+ svg: Rc<Svg>,
rect: cairo::Rectangle,
dpi: Dpi,
@@ -123,17 +123,20 @@ pub struct DrawingCtx {
drawsub_stack: Vec<RsvgNode>,
acquired_nodes: Rc<RefCell<Vec<RsvgNode>>>,
+
+ testing: bool,
}
impl DrawingCtx {
pub fn new(
- handle: *const RsvgHandle,
+ svg: Rc<Svg>,
cr: &cairo::Context,
width: f64,
height: f64,
vb_width: f64,
vb_height: f64,
dpi: Dpi,
+ testing: bool,
) -> DrawingCtx {
let mut affine = cr.get_matrix();
let rect = cairo::Rectangle {
@@ -160,7 +163,7 @@ impl DrawingCtx {
view_box_stack.push(ViewBox::new(0.0, 0.0, vb_width, vb_height));
DrawingCtx {
- handle,
+ svg: svg.clone(),
rect,
dpi,
num_elements_rendered_through_use: 0,
@@ -173,11 +176,12 @@ impl DrawingCtx {
bbox_stack: Vec::new(),
drawsub_stack: Vec::new(),
acquired_nodes: Rc::new(RefCell::new(Vec::new())),
+ testing,
}
}
pub fn is_testing(&self) -> bool {
- handle::is_testing(self.handle)
+ self.testing
}
pub fn get_cairo_context(&self) -> cairo::Context {
@@ -259,7 +263,7 @@ impl DrawingCtx {
// acquire it again. If you acquire a node "#foo" and don't release it before
// trying to acquire "foo" again, you will obtain a %NULL the second time.
pub fn get_acquired_node(&mut self, fragment: &Fragment) -> Option<AcquiredNode> {
- if let Some(node) = handle::lookup_node(self.handle, fragment) {
+ if let Some(node) = self.svg.lookup_node(fragment) {
if !self.acquired_nodes_contains(&node) {
self.acquired_nodes.borrow_mut().push(node.clone());
let acq = AcquiredNode(self.acquired_nodes.clone(), node.clone());
diff --git a/rsvg_internals/src/handle.rs b/rsvg_internals/src/handle.rs
index 1015965f..45145239 100644
--- a/rsvg_internals/src/handle.rs
+++ b/rsvg_internals/src/handle.rs
@@ -101,7 +101,7 @@ pub struct Handle {
dpi: Dpi,
base_url: RefCell<Option<Url>>,
base_url_cstring: RefCell<Option<CString>>, // needed because the C api returns *const char
- svg: RefCell<Option<Svg>>,
+ svg: RefCell<Option<Rc<Svg>>>,
load_options: Cell<LoadOptions>,
load_state: Cell<LoadState>,
load: RefCell<Option<LoadContext>>,
@@ -184,7 +184,7 @@ impl Handle {
xml.validate_tree()?;
- *self.svg.borrow_mut() = Some(xml.steal_result());
+ *self.svg.borrow_mut() = Some(Rc::new(xml.steal_result()));
Ok(())
}
@@ -247,7 +247,7 @@ impl Handle {
xml.validate_tree()?;
- *self.svg.borrow_mut() = Some(xml.steal_result());
+ *self.svg.borrow_mut() = Some(Rc::new(xml.steal_result()));
Ok(())
}
@@ -266,13 +266,14 @@ impl Handle {
node: Option<&RsvgNode>,
) -> DrawingCtx {
let mut draw_ctx = DrawingCtx::new(
- handle,
+ self.svg.borrow().as_ref().unwrap().clone(),
cr,
f64::from(dimensions.width),
f64::from(dimensions.height),
dimensions.em,
dimensions.ex,
get_dpi(handle).clone(),
+ self.is_testing.get(),
);
if let Some(node) = node {
@@ -569,23 +570,6 @@ extern "C" {
fn rsvg_handle_get_dimensions(handle: *mut RsvgHandle, dimensions: *mut RsvgDimensionData);
}
-/// Whether we are being run from the test suite
-pub fn is_testing(handle: *const RsvgHandle) -> bool {
- let rhandle = get_rust_handle(handle);
-
- rhandle.is_testing.get()
-}
-
-pub fn lookup_node(handle: *const RsvgHandle, fragment: &Fragment) -> Option<Rc<Node>> {
- let rhandle = get_rust_handle(handle);
-
- let svg_ref = rhandle.svg.borrow();
- let svg = svg_ref.as_ref().unwrap();
- let mut defs_ref = svg.defs.borrow_mut();
-
- defs_ref.lookup(handle, fragment)
-}
-
// Looks up a node by its id.
//
// Note that this ignores the Fragment's url; it only uses the fragment identifier.
diff --git a/rsvg_internals/src/svg.rs b/rsvg_internals/src/svg.rs
index 2c823594..9774f6a2 100644
--- a/rsvg_internals/src/svg.rs
+++ b/rsvg_internals/src/svg.rs
@@ -1,7 +1,9 @@
use std::cell::RefCell;
use css::CssStyles;
-use defs::Defs;
+use defs::{Defs, Fragment};
+use handle::RsvgHandle;
+use node::RsvgNode;
use tree::Tree;
/// A loaded SVG file and its derived data
@@ -9,6 +11,8 @@ use tree::Tree;
/// This contains the tree of nodes (SVG elements), the mapping
/// of id to node, and the CSS styles defined for this SVG.
pub struct Svg {
+ handle: *mut RsvgHandle,
+
pub tree: Tree,
// This requires interior mutability because we load the extern
@@ -20,11 +24,16 @@ pub struct Svg {
}
impl Svg {
- pub fn new(tree: Tree, defs: Defs, css_styles: CssStyles) -> Svg {
+ pub fn new(handle: *mut RsvgHandle, tree: Tree, defs: Defs, css_styles: CssStyles) -> Svg {
Svg {
+ handle,
tree,
defs: RefCell::new(defs),
css_styles,
}
}
+
+ pub fn lookup_node(&self, fragment: &Fragment) -> Option<RsvgNode> {
+ self.defs.borrow_mut().lookup(self.handle, fragment)
+ }
}
diff --git a/rsvg_internals/src/xml.rs b/rsvg_internals/src/xml.rs
index 32e4213c..af22bd4d 100644
--- a/rsvg_internals/src/xml.rs
+++ b/rsvg_internals/src/xml.rs
@@ -127,6 +127,7 @@ impl XmlState {
pub fn steal_result(&mut self) -> Svg {
Svg::new(
+ self.handle,
self.tree.take().unwrap(),
self.defs.take().unwrap(),
self.css_styles.take().unwrap(),
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]