[librsvg: 3/7] filter: mv computation of the effect region in the ctx
- From: Federico Mena Quintero <federico src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [librsvg: 3/7] filter: mv computation of the effect region in the ctx
- Date: Mon, 30 Nov 2020 17:51:57 +0000 (UTC)
commit 805704f660a9c547c4fd12fe8b769cb903069b6f
Author: Paolo Borelli <pborelli gnome org>
Date: Sun Nov 29 14:28:04 2020 +0000
filter: mv computation of the effect region in the ctx
src/filter.rs | 35 +++--------------------------------
src/filters/context.rs | 36 +++++++++++++++++++++++++-----------
2 files changed, 28 insertions(+), 43 deletions(-)
---
diff --git a/src/filter.rs b/src/filter.rs
index e5fc303c..4cbbe819 100644
--- a/src/filter.rs
+++ b/src/filter.rs
@@ -5,10 +5,9 @@ use markup5ever::{expanded_name, local_name, namespace_url, ns};
use std::slice::Iter;
use crate::attributes::Attributes;
-use crate::bbox::BoundingBox;
use crate::coord_units::CoordUnits;
use crate::document::AcquiredNodes;
-use crate::drawing_ctx::DrawingCtx;
+use crate::drawing_ctx::ViewParams;
use crate::element::{Draw, Element, ElementResult, SetAttributes};
use crate::error::ValueErrorKind;
use crate::iri::IRI;
@@ -17,7 +16,6 @@ use crate::node::{Node, NodeBorrow};
use crate::parsers::{Parse, ParseValue};
use crate::properties::ComputedValues;
use crate::rect::Rect;
-use crate::transform::Transform;
use crate::url_resolver::Fragment;
/// The <filter> node.
@@ -53,22 +51,7 @@ impl Filter {
self.primitiveunits
}
- /// Computes and returns the filter effects region.
- pub fn compute_effects_region(
- &self,
- computed_from_target_node: &ComputedValues,
- draw_ctx: &mut DrawingCtx,
- transform: Transform,
- width: f64,
- height: f64,
- ) -> BoundingBox {
- // Filters use the properties of the target node.
- let values = computed_from_target_node;
-
- let mut bbox = BoundingBox::new();
-
- let params = draw_ctx.push_coord_units(self.filterunits);
-
+ pub fn get_rect(&self, values: &ComputedValues, params: &ViewParams) -> Rect {
// With filterunits == ObjectBoundingBox, lengths represent fractions or percentages of the
// referencing node. No units are allowed (it's checked during attribute parsing).
let (x, y, w, h) = if self.filterunits == CoordUnits::ObjectBoundingBox {
@@ -87,19 +70,7 @@ impl Filter {
)
};
- let rect = Rect::new(x, y, x + w, y + h);
- let other_bbox = BoundingBox::new().with_transform(transform).with_rect(rect);
-
- // At this point all of the previous viewbox and matrix business gets converted to pixel
- // coordinates in the final surface, because bbox is created with an identity transform.
- bbox.insert(&other_bbox);
-
- // Finally, clip to the width and height of our surface.
- let rect = Rect::from_size(width, height);
- let other_bbox = BoundingBox::new().with_rect(rect);
- bbox.clip(&other_bbox);
-
- bbox
+ Rect::new(x, y, x + w, y + h)
}
}
diff --git a/src/filters/context.rs b/src/filters/context.rs
index 6a50a998..ab3996a9 100644
--- a/src/filters/context.rs
+++ b/src/filters/context.rs
@@ -9,7 +9,7 @@ use crate::drawing_ctx::{DrawingCtx, ViewParams};
use crate::node::{Node, NodeBorrow};
use crate::parsers::CustomIdent;
use crate::properties::ComputedValues;
-use crate::rect::IRect;
+use crate::rect::{IRect, Rect};
use crate::surface_utils::shared_surface::{SharedImageSurface, SurfaceType};
use crate::transform::Transform;
@@ -108,7 +108,8 @@ impl FilterContext {
let filter = borrow_element_as!(filter_node, Filter);
- let affine = match filter.get_filter_units() {
+ let filter_units = filter.get_filter_units();
+ let affine = match filter_units {
CoordUnits::UserSpaceOnUse => draw_transform,
CoordUnits::ObjectBoundingBox => Transform::new_unchecked(
bbox_rect.width(),
@@ -135,7 +136,27 @@ impl FilterContext {
.post_transform(&draw_transform),
};
- let (width, height) = (source_surface.width(), source_surface.height());
+ let effects_region = {
+ let params = draw_ctx.push_coord_units(filter_units);
+ let filter_rect = filter.get_rect(&computed_from_node_being_filtered, ¶ms);
+
+ let mut bbox = BoundingBox::new();
+ let other_bbox = BoundingBox::new()
+ .with_transform(affine)
+ .with_rect(filter_rect);
+
+ // At this point all of the previous viewbox and matrix business gets converted to pixel
+ // coordinates in the final surface, because bbox is created with an identity transform.
+ bbox.insert(&other_bbox);
+
+ // Finally, clip to the width and height of our surface.
+ let (width, height) = (source_surface.width(), source_surface.height());
+ let rect = Rect::from_size(f64::from(width), f64::from(height));
+ let other_bbox = BoundingBox::new().with_rect(rect);
+ bbox.clip(&other_bbox);
+
+ bbox
+ };
Self {
node_bbox,
@@ -145,13 +166,7 @@ impl FilterContext {
previous_results: HashMap::new(),
background_surface: RefCell::new(None),
primitive_units,
- effects_region: filter.compute_effects_region(
- computed_from_node_being_filtered,
- draw_ctx,
- affine,
- f64::from(width),
- f64::from(height),
- ),
+ effects_region,
processing_linear_rgb: false,
_affine: affine,
paffine,
@@ -251,7 +266,6 @@ impl FilterContext {
/// Pushes the viewport size based on the value of `primitiveUnits`.
pub fn get_view_params(&self, draw_ctx: &mut DrawingCtx) -> ViewParams {
- // See comments in compute_effects_region() for how this works.
draw_ctx.push_coord_units(self.primitive_units)
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]