[librsvg: 5/8] Remove last use of with_cairo_context
- From: Federico Mena Quintero <federico src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [librsvg: 5/8] Remove last use of with_cairo_context
- Date: Thu, 6 May 2021 23:15:17 +0000 (UTC)
commit 37b1f986777d8a167d3d79c0ccd1593210b73ec6
Author: Federico Mena Quintero <federico gnome org>
Date: Wed May 5 20:13:04 2021 -0500
Remove last use of with_cairo_context
src/drawing_ctx.rs | 60 +++++++++++++++++++++++-------------------------------
1 file changed, 26 insertions(+), 34 deletions(-)
---
diff --git a/src/drawing_ctx.rs b/src/drawing_ctx.rs
index 03a346de..e0a889a2 100644
--- a/src/drawing_ctx.rs
+++ b/src/drawing_ctx.rs
@@ -309,22 +309,6 @@ impl DrawingCtx {
BoundingBox::new().with_transform(self.get_transform())
}
- // FIXME: Usage of this function is more less a hack...
- // It would be better to have an explicit push/pop for the cairo_t, or
- // pushing a temporary surface, or something that does not involve
- // monkeypatching the cr directly.
- fn with_cairo_context(
- &mut self,
- cr: &cairo::Context,
- draw_fn: &mut dyn FnMut(&mut DrawingCtx) -> Result<(), RenderingError>,
- ) -> Result<(), RenderingError> {
- let cr_save = self.cr.clone();
- self.cr = cr.clone();
- let res = draw_fn(self);
- self.cr = cr_save;
- res
- }
-
fn size_for_temporary_surface(&self) -> (i32, i32) {
let rect = self.toplevel_viewport();
@@ -1035,24 +1019,32 @@ impl DrawingCtx {
cr_pattern.set_matrix(caffine.into());
// Draw everything
- self.with_cairo_context(&cr_pattern, &mut |dc| {
- dc.with_alpha(pattern.opacity, &mut |dc| {
- let pattern_cascaded = CascadedValues::new_from_node(&pattern.node_with_children);
- let pattern_values = pattern_cascaded.get();
- dc.with_discrete_layer(
- &pattern.node_with_children,
- acquired_nodes,
- pattern_values,
- false,
- &mut |an, dc| {
- pattern
- .node_with_children
- .draw_children(an, &pattern_cascaded, dc, false)
- },
- )
- })
- .map(|_| ())
- })?;
+
+ {
+ let mut pattern_draw_ctx = self.nested(cr_pattern);
+
+ pattern_draw_ctx
+ .with_alpha(pattern.opacity, &mut |dc| {
+ let pattern_cascaded =
+ CascadedValues::new_from_node(&pattern.node_with_children);
+ let pattern_values = pattern_cascaded.get();
+ dc.with_discrete_layer(
+ &pattern.node_with_children,
+ acquired_nodes,
+ pattern_values,
+ false,
+ &mut |an, dc| {
+ pattern.node_with_children.draw_children(
+ an,
+ &pattern_cascaded,
+ dc,
+ false,
+ )
+ },
+ )
+ })
+ .map(|_| ())?;
+ }
// Set the final surface as a Cairo pattern into the Cairo context
let pattern = cairo::SurfacePattern::create(&surface);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]