[librsvg: 3/31] Put the clip-path in StackingContext
- From: Federico Mena Quintero <federico src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [librsvg: 3/31] Put the clip-path in StackingContext
- Date: Thu, 3 Jun 2021 02:27:09 +0000 (UTC)
commit e4115999cfcb1c726accb4ea08c607daf1ef9330
Author: Federico Mena Quintero <federico gnome org>
Date: Wed Jun 2 15:23:06 2021 -0500
Put the clip-path in StackingContext
Don't obtain it until with_discrete_layer().
src/drawing_ctx.rs | 44 +++++++-------------------------------------
src/layout.rs | 26 ++++++++++++++++++++++++++
2 files changed, 33 insertions(+), 37 deletions(-)
---
diff --git a/src/drawing_ctx.rs b/src/drawing_ctx.rs
index 4905f607..c6125d4b 100644
--- a/src/drawing_ctx.rs
+++ b/src/drawing_ctx.rs
@@ -645,24 +645,17 @@ impl DrawingCtx {
} else {
let saved_cr = SavedCr::new(self);
- let clip_path_value = values.clip_path();
-
- let clip_uri = clip_path_value.0.get();
-
let Opacity(UnitInterval(opacity)) = stacking_ctx.opacity;
let affine_at_start = saved_cr.draw_ctx.get_transform();
- let (clip_in_user_space, clip_in_object_space) =
- get_clip_in_user_and_object_space(acquired_nodes, clip_uri);
-
if let Some(rect) = clip_rect {
clip_to_rectangle(&saved_cr.draw_ctx.cr, &rect);
}
// Here we are clipping in user space, so the bbox doesn't matter
saved_cr.draw_ctx.clip_to_node(
- &clip_in_user_space,
+ &stacking_ctx.clip_in_user_space,
acquired_nodes,
&saved_cr.draw_ctx.empty_bbox(),
)?;
@@ -672,7 +665,7 @@ impl DrawingCtx {
&& stacking_ctx.filter == Filter::None
&& stacking_ctx.mask.is_none()
&& values.mix_blend_mode() == MixBlendMode::Normal
- && clip_in_object_space.is_none());
+ && stacking_ctx.clip_in_object_space.is_none());
if needs_temporary_surface {
// Compute our assortment of affines
@@ -744,9 +737,11 @@ impl DrawingCtx {
.draw_ctx
.cr
.set_matrix(affines.outside_temporary_surface.into());
- saved_cr
- .draw_ctx
- .clip_to_node(&clip_in_object_space, acquired_nodes, &bbox)?;
+ saved_cr.draw_ctx.clip_to_node(
+ &stacking_ctx.clip_in_object_space,
+ acquired_nodes,
+ &bbox,
+ )?;
// Mask
@@ -1743,31 +1738,6 @@ impl CompositingAffines {
}
}
-// Returns (clip_in_user_space, clip_in_object_space), both Option<Node>
-fn get_clip_in_user_and_object_space(
- acquired_nodes: &mut AcquiredNodes<'_>,
- clip_uri: Option<&NodeId>,
-) -> (Option<Node>, Option<Node>) {
- clip_uri
- .and_then(|node_id| {
- acquired_nodes
- .acquire(node_id)
- .ok()
- .filter(|a| is_element_of_type!(*a.get(), ClipPath))
- })
- .map(|acquired| {
- let clip_node = acquired.get().clone();
-
- let units = borrow_element_as!(clip_node, ClipPath).get_units();
-
- match units {
- CoordUnits::UserSpaceOnUse => (Some(clip_node), None),
- CoordUnits::ObjectBoundingBox => (None, Some(clip_node)),
- }
- })
- .unwrap_or((None, None))
-}
-
fn compute_stroke_and_fill_box(
cr: &cairo::Context,
values: &ComputedValues,
diff --git a/src/layout.rs b/src/layout.rs
index fd05f558..4570c876 100644
--- a/src/layout.rs
+++ b/src/layout.rs
@@ -2,6 +2,7 @@
//!
//! The idea is to take the DOM tree and produce a layout tree with SVG concepts.
+use crate::coord_units::CoordUnits;
use crate::dasharray::Dasharray;
use crate::document::AcquiredNodes;
use crate::element::Element;
@@ -32,6 +33,8 @@ pub struct StackingContext {
pub transform: Transform,
pub opacity: Opacity,
pub filter: Filter,
+ pub clip_in_user_space: Option<Node>,
+ pub clip_in_object_space: Option<Node>,
pub mask: Option<Node>,
}
@@ -71,6 +74,27 @@ impl StackingContext {
}
}
+ let clip_path = values.clip_path();
+ let clip_uri = clip_path.0.get();
+ let (clip_in_user_space, clip_in_object_space) = clip_uri
+ .and_then(|node_id| {
+ acquired_nodes
+ .acquire(node_id)
+ .ok()
+ .filter(|a| is_element_of_type!(*a.get(), ClipPath))
+ })
+ .map(|acquired| {
+ let clip_node = acquired.get().clone();
+
+ let units = borrow_element_as!(clip_node, ClipPath).get_units();
+
+ match units {
+ CoordUnits::UserSpaceOnUse => (Some(clip_node), None),
+ CoordUnits::ObjectBoundingBox => (None, Some(clip_node)),
+ }
+ })
+ .unwrap_or((None, None));
+
let mask = values.mask().0.get().and_then(|mask_id| {
if let Ok(acquired) = acquired_nodes.acquire(mask_id) {
let node = acquired.get();
@@ -103,6 +127,8 @@ impl StackingContext {
transform,
opacity,
filter,
+ clip_in_user_space,
+ clip_in_object_space,
mask,
}
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]