From 8d7030936c3d00030c7887839e56b6142f8e7d85 Mon Sep 17 00:00:00 2001 From: Federico Mena Quintero Date: Tue, 19 Jun 2018 17:36:17 -0500 Subject: with_discrete_layer(): Don't acquire the clip_node more than once --- rsvg_internals/src/drawing_ctx.rs | 50 +++++++++++++-------------------------- 1 file changed, 16 insertions(+), 34 deletions(-) diff --git a/rsvg_internals/src/drawing_ctx.rs b/rsvg_internals/src/drawing_ctx.rs index 495bb732..379d506f 100644 --- a/rsvg_internals/src/drawing_ctx.rs +++ b/rsvg_internals/src/drawing_ctx.rs @@ -238,14 +238,14 @@ pub fn with_discrete_layer( let current_affine = original_cr.get_matrix(); - if let Some(acquired) = + let clip_node = get_acquired_node_of_type(draw_ctx, clip_uri.map(String::as_ref), NodeType::ClipPath) - { - let node = acquired.get(); + .and_then(|acquired| Some(acquired.get())); - node.with_impl(|clip_path: &NodeClipPath| match clip_path.get_units() { + if let Some(ref clip_node) = clip_node { + clip_node.with_impl(|clip_path: &NodeClipPath| match clip_path.get_units() { ClipPathUnits(CoordUnits::UserSpaceOnUse) => { - clip_path.to_cairo_context(&node, ¤t_affine, draw_ctx); + late_clip = false; } ClipPathUnits(CoordUnits::ObjectBoundingBox) => { @@ -254,6 +254,14 @@ pub fn with_discrete_layer( }); } + if !late_clip { + if let Some(ref clip_node) = clip_node { + clip_node.with_impl(|clip_path: &NodeClipPath| { + clip_path.to_cairo_context(clip_node, ¤t_affine, draw_ctx); + }); + } + } + if !(opacity == 1.0 && filter.is_none() && mask.is_none() @@ -292,26 +300,6 @@ pub fn with_discrete_layer( draw_fn(&get_cairo_context(draw_ctx)); - if let Some(acquired) = - get_acquired_node_of_type(draw_ctx, clip_uri.map(String::as_ref), NodeType::ClipPath) - { - let mut clip_path_units = ClipPathUnits::default(); - - acquired.get().with_impl(|clip_path: &NodeClipPath| { - clip_path_units = clip_path.get_units(); - }); - - match clip_path_units { - ClipPathUnits(CoordUnits::UserSpaceOnUse) => { - late_clip = false; - } - - ClipPathUnits(CoordUnits::ObjectBoundingBox) => { - late_clip = true; - } - } - } - if !(opacity == 1.0 && filter.is_none() && mask.is_none() @@ -373,15 +361,9 @@ pub fn with_discrete_layer( cr.set_source_surface(&surface, xofs, yofs); if late_clip { - if let Some(acquired) = get_acquired_node_of_type( - draw_ctx, - clip_uri.map(String::as_ref), - NodeType::ClipPath, - ) { - let node = acquired.get(); - - node.with_impl(|clip_path: &NodeClipPath| { - clip_path.to_cairo_context(&node, ¤t_affine, draw_ctx); + if let Some(ref clip_node) = clip_node { + clip_node.with_impl(|clip_path: &NodeClipPath| { + clip_path.to_cairo_context(clip_node, ¤t_affine, draw_ctx); }); } } -- cgit v1.2.1