[librsvg] drawing_ctx: pass SharedImageSurface as param to run_filter
- From: Paolo Borelli <pborelli src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [librsvg] drawing_ctx: pass SharedImageSurface as param to run_filter
- Date: Sat, 11 Jan 2020 16:07:16 +0000 (UTC)
commit 2fe7c1ecff4393de51fe1dd85e14b965343986f4
Author: Paolo Borelli <pborelli gnome org>
Date: Sat Jan 11 00:43:37 2020 +0100
drawing_ctx: pass SharedImageSurface as param to run_filter
rsvg_internals/src/drawing_ctx.rs | 29 ++++++++++++++++++-----------
rsvg_internals/src/filters/mod.rs | 12 ++++--------
2 files changed, 22 insertions(+), 19 deletions(-)
---
diff --git a/rsvg_internals/src/drawing_ctx.rs b/rsvg_internals/src/drawing_ctx.rs
index 8409f3f2..f7cbbe9d 100644
--- a/rsvg_internals/src/drawing_ctx.rs
+++ b/rsvg_internals/src/drawing_ctx.rs
@@ -520,11 +520,18 @@ impl DrawingCtx {
// Filter
let source_surface = if let Some(filter_uri) = filter {
- let child_surface =
- cairo::ImageSurface::try_from(dc.cr.get_target()).unwrap();
- let img_surface =
- dc.run_filter(filter_uri, node, values, &child_surface, bbox)?;
- // turn into a Surface
+ // The target surface has multiple references.
+ // We need to copy it to a new surface to have a unique
+ // reference to be able to safely access the pixel data.
+ let child_surface = SharedImageSurface::copy_from_surface(
+ &cairo::ImageSurface::try_from(dc.cr.get_target()).unwrap(),
+ )?;
+
+ let img_surface = dc
+ .run_filter(filter_uri, node, values, child_surface, bbox)?
+ .into_image_surface()?;
+
+ // turn ImageSurface into a Surface
(*img_surface).clone()
} else {
dc.cr.get_target()
@@ -666,9 +673,9 @@ impl DrawingCtx {
filter_uri: &Fragment,
node: &RsvgNode,
values: &ComputedValues,
- child_surface: &cairo::ImageSurface,
+ child_surface: SharedImageSurface,
node_bbox: BoundingBox,
- ) -> Result<cairo::ImageSurface, RenderingError> {
+ ) -> Result<SharedImageSurface, RenderingError> {
match self.acquire_node(filter_uri, &[NodeType::Filter]) {
Ok(acquired) => {
let filter_node = acquired.get();
@@ -690,10 +697,10 @@ impl DrawingCtx {
// Non-existing filters must act as null filters (that is, an
// empty surface is returned).
- Ok(cairo::ImageSurface::create(
- cairo::Format::ARgb32,
- child_surface.get_width(),
- child_surface.get_height(),
+ Ok(SharedImageSurface::empty(
+ child_surface.width(),
+ child_surface.height(),
+ child_surface.surface_type(),
)?)
}
}
diff --git a/rsvg_internals/src/filters/mod.rs b/rsvg_internals/src/filters/mod.rs
index d3c3ca0f..b627fb27 100644
--- a/rsvg_internals/src/filters/mod.rs
+++ b/rsvg_internals/src/filters/mod.rs
@@ -239,18 +239,14 @@ impl Deref for PrimitiveWithInput {
pub fn render(
filter_node: &RsvgNode,
computed_from_node_being_filtered: &ComputedValues,
- source: &cairo::ImageSurface,
+ source_surface: SharedImageSurface,
draw_ctx: &mut DrawingCtx,
node_bbox: BoundingBox,
-) -> Result<cairo::ImageSurface, RenderingError> {
+) -> Result<SharedImageSurface, RenderingError> {
let filter_node = &*filter_node;
assert_eq!(filter_node.borrow().get_type(), NodeType::Filter);
assert!(!filter_node.borrow().is_in_error());
- // The source surface has multiple references. We need to copy it to a new surface to have a
- // unique reference to be able to safely access the pixel data.
- let source_surface = SharedImageSurface::copy_from_surface(source)?;
-
let mut filter_ctx = FilterContext::new(
filter_node,
computed_from_node_being_filtered,
@@ -262,7 +258,7 @@ pub fn render(
// If paffine is non-invertible, we won't draw anything. Also bbox combining in bounds
// computations will panic due to non-invertible martrix.
if filter_ctx.paffine().try_invert().is_err() {
- return Ok(filter_ctx.into_output()?.into_image_surface()?);
+ return Ok(filter_ctx.into_output()?);
}
let primitives = filter_node
@@ -327,7 +323,7 @@ pub fn render(
);
}
- Ok(filter_ctx.into_output()?.into_image_surface()?)
+ Ok(filter_ctx.into_output()?)
}
impl From<ColorInterpolationFilters> for SurfaceType {
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]