[librsvg] Move in_loop to CHandle
- From: Federico Mena Quintero <federico src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [librsvg] Move in_loop to CHandle
- Date: Tue, 9 Apr 2019 16:45:30 +0000 (UTC)
commit dac1a5ece1c10939b8c982e780fd826aba12ffc5
Author: Federico Mena Quintero <federico gnome org>
Date: Fri Apr 5 18:06:45 2019 -0600
Move in_loop to CHandle
rsvg_internals/src/c_api.rs | 66 ++++++++++++++++++++++++++++----------------
rsvg_internals/src/handle.rs | 27 ++++++++++++------
2 files changed, 61 insertions(+), 32 deletions(-)
---
diff --git a/rsvg_internals/src/c_api.rs b/rsvg_internals/src/c_api.rs
index 9d3e3cb3..546d53d7 100644
--- a/rsvg_internals/src/c_api.rs
+++ b/rsvg_internals/src/c_api.rs
@@ -158,6 +158,7 @@ pub struct SizeCallback {
size_func: RsvgSizeFunc,
user_data: glib_sys::gpointer,
destroy_notify: glib_sys::GDestroyNotify,
+ in_loop: Cell<bool>,
}
impl SizeCallback {
@@ -173,6 +174,20 @@ impl SizeCallback {
(w, h)
}
}
+
+ pub fn start_loop(&self) {
+ assert!(!self.in_loop.get());
+ self.in_loop.set(true);
+ }
+
+ pub fn end_loop(&self) {
+ assert!(self.in_loop.get());
+ self.in_loop.set(false);
+ }
+
+ pub fn get_in_loop(&self) -> bool {
+ self.in_loop.get()
+ }
}
impl Default for SizeCallback {
@@ -181,6 +196,7 @@ impl Default for SizeCallback {
size_func: None,
user_data: ptr::null_mut(),
destroy_notify: None,
+ in_loop: Cell::new(false),
}
}
}
@@ -484,9 +500,9 @@ impl CHandle {
size_func,
user_data,
destroy_notify,
+ in_loop: Cell::new(false),
};
}
-
}
pub fn get_rust_handle<'a>(handle: *const RsvgHandle) -> &'a CHandle {
@@ -674,8 +690,7 @@ pub unsafe extern "C" fn rsvg_rust_handle_set_size_callback(
) {
let rhandle = get_rust_handle(raw_handle);
- rhandle
- .set_size_callback(size_func, user_data, destroy_notify);
+ rhandle.set_size_callback(size_func, user_data, destroy_notify);
}
#[no_mangle]
@@ -780,10 +795,12 @@ pub unsafe extern "C" fn rsvg_rust_handle_render_cairo_sub(
let size_callback = rhandle.size_callback.borrow();
- match rhandle
- .handle
- .render_cairo_sub(&cr, id.as_ref().map(String::as_str), rhandle.dpi.get(), &*size_callback)
- {
+ match rhandle.handle.render_cairo_sub(
+ &cr,
+ id.as_ref().map(String::as_str),
+ rhandle.dpi.get(),
+ &*size_callback,
+ ) {
Ok(()) => true.to_glib(),
Err(_) => {
@@ -803,10 +820,11 @@ pub unsafe extern "C" fn rsvg_rust_handle_get_pixbuf_sub(
let size_callback = rhandle.size_callback.borrow();
- match rhandle
- .handle
- .get_pixbuf_sub(id.as_ref().map(String::as_str), rhandle.dpi.get(), &*size_callback)
- {
+ match rhandle.handle.get_pixbuf_sub(
+ id.as_ref().map(String::as_str),
+ rhandle.dpi.get(),
+ &*size_callback,
+ ) {
Ok(pixbuf) => pixbuf.to_glib_full(),
Err(_) => ptr::null_mut(),
}
@@ -821,7 +839,9 @@ pub unsafe extern "C" fn rsvg_rust_handle_get_dimensions(
let size_callback = rhandle.size_callback.borrow();
- *dimension_data = rhandle.handle.get_dimensions_no_error(rhandle.dpi.get(), &*size_callback);
+ *dimension_data = rhandle
+ .handle
+ .get_dimensions_no_error(rhandle.dpi.get(), &*size_callback);
}
#[no_mangle]
@@ -836,14 +856,11 @@ pub unsafe extern "C" fn rsvg_rust_handle_get_dimensions_sub(
let size_callback = rhandle.size_callback.borrow();
- match rhandle
- .handle
- .get_dimensions_sub(
- id.as_ref().map(String::as_str),
- rhandle.dpi.get(),
- &*size_callback,
- )
- {
+ match rhandle.handle.get_dimensions_sub(
+ id.as_ref().map(String::as_str),
+ rhandle.dpi.get(),
+ &*size_callback,
+ ) {
Ok(dimensions) => {
*dimension_data = dimensions;
true.to_glib()
@@ -875,10 +892,11 @@ pub unsafe extern "C" fn rsvg_rust_handle_get_position_sub(
let size_callback = rhandle.size_callback.borrow();
- match rhandle
- .handle
- .get_position_sub(id.as_ref().map(String::as_str), rhandle.dpi.get(), &*size_callback)
- {
+ match rhandle.handle.get_position_sub(
+ id.as_ref().map(String::as_str),
+ rhandle.dpi.get(),
+ &*size_callback,
+ ) {
Ok(position) => {
*position_data = position;
true.to_glib()
diff --git a/rsvg_internals/src/handle.rs b/rsvg_internals/src/handle.rs
index 01285f33..83b5e4c2 100644
--- a/rsvg_internals/src/handle.rs
+++ b/rsvg_internals/src/handle.rs
@@ -75,7 +75,6 @@ pub struct Handle {
svg: RefCell<Option<Rc<Svg>>>,
load_state: Cell<LoadState>,
buffer: RefCell<Vec<u8>>, // used by the legacy write() api
- in_loop: Cell<bool>,
is_testing: Cell<bool>,
}
@@ -85,7 +84,6 @@ impl Handle {
svg: RefCell::new(None),
load_state: Cell::new(LoadState::Start),
buffer: RefCell::new(Vec::new()),
- in_loop: Cell::new(false),
is_testing: Cell::new(false),
}
}
@@ -192,14 +190,18 @@ impl Handle {
}
}
- pub fn get_dimensions(&self, dpi: Dpi, size_callback: &SizeCallback) -> Result<RsvgDimensionData,
RenderingError> {
+ pub fn get_dimensions(
+ &self,
+ dpi: Dpi,
+ size_callback: &SizeCallback,
+ ) -> Result<RsvgDimensionData, RenderingError> {
self.check_is_loaded()?;
// This function is probably called from the cairo_render functions,
// or is being erroneously called within the size_func.
// To prevent an infinite loop we are saving the state, and
// returning a meaningless size.
- if self.in_loop.get() {
+ if size_callback.get_in_loop() {
return Ok(RsvgDimensionData {
width: 1,
height: 1,
@@ -208,16 +210,20 @@ impl Handle {
});
}
- self.in_loop.set(true);
+ size_callback.start_loop();
let res = self.get_dimensions_sub(None, dpi, size_callback);
- self.in_loop.set(false);
+ size_callback.end_loop();
res
}
- pub fn get_dimensions_no_error(&self, dpi: Dpi, size_callback: &SizeCallback) -> RsvgDimensionData {
+ pub fn get_dimensions_no_error(
+ &self,
+ dpi: Dpi,
+ size_callback: &SizeCallback,
+ ) -> RsvgDimensionData {
match self.get_dimensions(dpi, size_callback) {
Ok(dimensions) => dimensions,
@@ -472,7 +478,12 @@ impl Handle {
res
}
- pub fn get_pixbuf_sub(&self, id: Option<&str>, dpi: Dpi, size_callback: &SizeCallback) -> Result<Pixbuf,
RenderingError> {
+ pub fn get_pixbuf_sub(
+ &self,
+ id: Option<&str>,
+ dpi: Dpi,
+ size_callback: &SizeCallback,
+ ) -> Result<Pixbuf, RenderingError> {
self.check_is_loaded()?;
let dimensions = self.get_dimensions(dpi, size_callback)?;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]