summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFederico Mena Quintero <federico@gnome.org>2023-03-22 12:30:40 -0600
committerMarge Bot <marge-bot@gnome.org>2023-03-23 01:41:14 +0000
commitce3b71599a5fa077f85fc19204ebacb5d5e32bb6 (patch)
tree48429b850cc34df3629932d2801e9f80f12bfc86
parentdfa94acbff1e11bf3932368e113d151e961df0e2 (diff)
downloadlibrsvg-ce3b71599a5fa077f85fc19204ebacb5d5e32bb6.tar.gz
layout::Filter: new struct; move some of the filter-related fields here
Let's try to avoid passing so many arguments to the functions in drawing_ctx.rs. In the end this will also encapsulate all the gunk needed for resolving filters. Part-of: <https://gitlab.gnome.org/GNOME/librsvg/-/merge_requests/816>
-rw-r--r--src/drawing_ctx.rs22
-rw-r--r--src/layout.rs18
2 files changed, 26 insertions, 14 deletions
diff --git a/src/drawing_ctx.rs b/src/drawing_ctx.rs
index 5c5bc6fc..8ef328a6 100644
--- a/src/drawing_ctx.rs
+++ b/src/drawing_ctx.rs
@@ -765,7 +765,7 @@ impl DrawingCtx {
// Create temporary surface and its cr
- let cr = match stacking_ctx.filter {
+ let cr = match stacking_ctx.filter.filter {
Filter::None => cairo::Context::new(
&self
.create_similar_surface_for_toplevel_viewport(&self.cr.target())?,
@@ -790,7 +790,7 @@ impl DrawingCtx {
BoundingBox::new().with_transform(affines.for_temporary_surface)
};
- if let Filter::List(ref filter_list) = stacking_ctx.filter {
+ if let Filter::List(ref filter_list) = stacking_ctx.filter.filter {
let surface_to_filter = SharedImageSurface::copy_from_surface(
&cairo::ImageSurface::try_from(temporary_draw_ctx.cr.target())
.unwrap(),
@@ -808,7 +808,7 @@ impl DrawingCtx {
.resolve(
acquired_nodes,
values.stroke_opacity().0,
- stacking_ctx.current_color,
+ stacking_ctx.filter.current_color,
None,
None,
self.session(),
@@ -823,7 +823,7 @@ impl DrawingCtx {
.resolve(
acquired_nodes,
values.fill_opacity().0,
- stacking_ctx.current_color,
+ stacking_ctx.filter.current_color,
None,
None,
self.session(),
@@ -849,7 +849,7 @@ impl DrawingCtx {
&user_space_params,
stroke_paint_source,
fill_paint_source,
- stacking_ctx.current_color,
+ stacking_ctx.filter.current_color,
bbox,
)?
.into_image_surface()?;
@@ -1296,10 +1296,14 @@ impl DrawingCtx {
),
LayerKind::Text(text) => {
self.draw_text(&text, &layer.stacking_ctx, acquired_nodes, values, clipping)
- },
- LayerKind::Image(image) => {
- self.draw_image(&image, &layer.stacking_ctx, acquired_nodes, values, clipping)
- },
+ }
+ LayerKind::Image(image) => self.draw_image(
+ &image,
+ &layer.stacking_ctx,
+ acquired_nodes,
+ values,
+ clipping,
+ ),
}
}
diff --git a/src/layout.rs b/src/layout.rs
index 7f55b275..a65bc1cf 100644
--- a/src/layout.rs
+++ b/src/layout.rs
@@ -19,7 +19,7 @@ use crate::node::*;
use crate::paint_server::{PaintSource, UserSpacePaintSource};
use crate::path_builder::Path;
use crate::properties::{
- ClipRule, ComputedValues, Direction, FillRule, Filter, FontFamily, FontStretch, FontStyle,
+ self, ClipRule, ComputedValues, Direction, FillRule, FontFamily, FontStretch, FontStyle,
FontVariant, FontWeight, Isolation, MixBlendMode, Opacity, Overflow, PaintOrder,
ShapeRendering, StrokeDasharray, StrokeLinecap, StrokeLinejoin, StrokeMiterlimit,
TextDecoration, TextRendering, UnicodeBidi, VectorEffect, XmlLang,
@@ -48,7 +48,6 @@ pub struct StackingContext {
pub transform: Transform,
pub opacity: Opacity,
pub filter: Filter,
- pub current_color: RGBA,
pub clip_in_user_space: Option<Node>,
pub clip_in_object_space: Option<Node>,
pub mask: Option<Node>,
@@ -150,6 +149,11 @@ pub struct FontProperties {
pub text_decoration: TextDecoration,
}
+pub struct Filter {
+ pub filter: properties::Filter,
+ pub current_color: RGBA,
+}
+
impl StackingContext {
pub fn new(
session: &Session,
@@ -170,7 +174,7 @@ impl StackingContext {
// https://drafts.fxtf.org/css-masking-1/#MaskElement
ElementData::Mask(_) => {
opacity = Opacity(UnitInterval::clamp(1.0));
- filter = Filter::None;
+ filter = properties::Filter::None;
}
_ => {
@@ -179,6 +183,11 @@ impl StackingContext {
}
}
+ let filter = Filter {
+ filter,
+ current_color,
+ };
+
let clip_path = values.clip_path();
let clip_uri = clip_path.0.get();
let (clip_in_user_space, clip_in_object_space) = clip_uri
@@ -237,7 +246,6 @@ impl StackingContext {
transform,
opacity,
filter,
- current_color,
clip_in_user_space,
clip_in_object_space,
mask,
@@ -266,7 +274,7 @@ impl StackingContext {
Isolation::Auto => {
let is_opaque = approx_eq!(f64, opacity, 1.0);
!(is_opaque
- && self.filter == Filter::None
+ && self.filter.filter == properties::Filter::None
&& self.mask.is_none()
&& self.mix_blend_mode == MixBlendMode::Normal
&& self.clip_in_object_space.is_none())