[librsvg] offset: move cairo implementation to surface_utils
- From: Paolo Borelli <pborelli src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [librsvg] offset: move cairo implementation to surface_utils
- Date: Mon, 6 Jan 2020 11:42:47 +0000 (UTC)
commit 444f32240db9db72b5ac391572301f2ff485f495
Author: Paolo Borelli <pborelli gnome org>
Date: Mon Jan 6 12:40:40 2020 +0100
offset: move cairo implementation to surface_utils
rsvg_internals/src/filters/offset.rs | 29 +++-------------------
rsvg_internals/src/surface_utils/shared_surface.rs | 29 ++++++++++++++++++++++
2 files changed, 32 insertions(+), 26 deletions(-)
---
diff --git a/rsvg_internals/src/filters/offset.rs b/rsvg_internals/src/filters/offset.rs
index 69647cf5..b7c3389b 100644
--- a/rsvg_internals/src/filters/offset.rs
+++ b/rsvg_internals/src/filters/offset.rs
@@ -4,7 +4,6 @@ use crate::drawing_ctx::DrawingCtx;
use crate::node::{NodeResult, NodeTrait, RsvgNode};
use crate::parsers::ParseValue;
use crate::property_bag::PropertyBag;
-use crate::surface_utils::shared_surface::SharedImageSurface;
use super::context::{FilterContext, FilterOutput, FilterResult};
use super::{FilterEffect, FilterError, PrimitiveWithInput};
@@ -60,35 +59,13 @@ impl FilterEffect for FeOffset {
.add_input(&input)
.into_irect(draw_ctx);
- let (ox, oy) = ctx.paffine().transform_distance(self.dx, self.dy);
+ let (dx, dy) = ctx.paffine().transform_distance(self.dx, self.dy);
- let output_surface = cairo::ImageSurface::create(
- cairo::Format::ARgb32,
- ctx.source_graphic().width(),
- ctx.source_graphic().height(),
- )?;
-
- // output_bounds contains all pixels within bounds,
- // for which (x - ox) and (y - oy) also lie within bounds.
- if let Some(output_bounds) = bounds
- .translate((ox as i32, oy as i32))
- .intersection(&bounds)
- {
- let cr = cairo::Context::new(&output_surface);
- let r = cairo::Rectangle::from(output_bounds);
- cr.rectangle(r.x, r.y, r.width, r.height);
- cr.clip();
-
- input.surface().set_as_source_surface(&cr, ox, oy);
- cr.paint();
- }
+ let surface = input.surface().offset(bounds, dx, dy)?;
Ok(FilterResult {
name: self.base.result.clone(),
- output: FilterOutput {
- surface: SharedImageSurface::new(output_surface, input.surface().surface_type())?,
- bounds,
- },
+ output: FilterOutput { surface, bounds },
})
}
diff --git a/rsvg_internals/src/surface_utils/shared_surface.rs
b/rsvg_internals/src/surface_utils/shared_surface.rs
index 5dd53979..4454109d 100644
--- a/rsvg_internals/src/surface_utils/shared_surface.rs
+++ b/rsvg_internals/src/surface_utils/shared_surface.rs
@@ -932,6 +932,35 @@ impl SharedImageSurface {
SharedImageSurface::new(output_surface, self.surface_type)
}
+ /// Offsets the image of the specified amount.
+ #[inline]
+ pub fn offset(
+ &self,
+ bounds: IRect,
+ dx: f64,
+ dy: f64
+ ) -> Result<SharedImageSurface, cairo::Status> {
+ let output_surface =
+ cairo::ImageSurface::create(cairo::Format::ARgb32, self.width, self.height)?;
+
+ // output_bounds contains all pixels within bounds,
+ // for which (x - ox) and (y - oy) also lie within bounds.
+ if let Some(output_bounds) = bounds
+ .translate((dx as i32, dy as i32))
+ .intersection(&bounds)
+ {
+ let cr = cairo::Context::new(&output_surface);
+ let r = cairo::Rectangle::from(output_bounds);
+ cr.rectangle(r.x, r.y, r.width, r.height);
+ cr.clip();
+
+ self.set_as_source_surface(&cr, dx, dy);
+ cr.paint();
+ }
+
+ SharedImageSurface::new(output_surface, self.surface_type)
+ }
+
/// Performs the combination of two input surfaces using Porter-Duff
/// compositing operators
///
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]