[librsvg] drawing_ctx: rework get_snapshot
- From: Paolo Borelli <pborelli src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [librsvg] drawing_ctx: rework get_snapshot
- Date: Sat, 11 Jan 2020 16:07:11 +0000 (UTC)
commit b0959e07bdd204392a309532da1e00212be96342
Author: Paolo Borelli <pborelli gnome org>
Date: Fri Jan 10 22:27:25 2020 +0100
drawing_ctx: rework get_snapshot
Return a SharedImageSurface, this makes the calling code cleaner
and independent from cairo.
rsvg_internals/src/drawing_ctx.rs | 35 +++++++++++++++++++++++------------
rsvg_internals/src/filters/context.rs | 13 +++----------
2 files changed, 26 insertions(+), 22 deletions(-)
---
diff --git a/rsvg_internals/src/drawing_ctx.rs b/rsvg_internals/src/drawing_ctx.rs
index 4fe72161..8409f3f2 100644
--- a/rsvg_internals/src/drawing_ctx.rs
+++ b/rsvg_internals/src/drawing_ctx.rs
@@ -899,7 +899,11 @@ impl DrawingCtx {
cr.clip();
}
- pub fn get_snapshot(&self, surface: &cairo::ImageSurface) {
+ pub fn get_snapshot(
+ &self,
+ width: i32,
+ height: i32,
+ ) -> Result<SharedImageSurface, cairo::Status> {
// TODO: as far as I can tell this should not render elements past the last (topmost) one
// with enable-background: new (because technically we shouldn't have been caching them).
// Right now there are no enable-background checks whatsoever.
@@ -915,18 +919,25 @@ impl DrawingCtx {
//
// CSS Compositing and Blending, "isolation" property:
// https://www.w3.org/TR/compositing-1/#isolation
- let cr = cairo::Context::new(&surface);
- for (depth, draw) in self.cr_stack.iter().enumerate() {
- let affines = CompositingAffines::new(
- draw.get_matrix(),
- self.initial_affine_with_offset(),
- depth,
- );
-
- cr.set_matrix(affines.for_snapshot);
- cr.set_source_surface(&draw.get_target(), 0.0, 0.0);
- cr.paint();
+ let surface = cairo::ImageSurface::create(cairo::Format::ARgb32, width, height)?;
+
+ {
+ let cr = cairo::Context::new(&surface);
+
+ for (depth, draw) in self.cr_stack.iter().enumerate() {
+ let affines = CompositingAffines::new(
+ draw.get_matrix(),
+ self.initial_affine_with_offset(),
+ depth,
+ );
+
+ cr.set_matrix(affines.for_snapshot);
+ cr.set_source_surface(&draw.get_target(), 0.0, 0.0);
+ cr.paint();
+ }
}
+
+ SharedImageSurface::wrap(surface, SurfaceType::SRgb)
}
pub fn lookup_image(&self, href: &str) -> Result<SharedImageSurface, RenderingError> {
diff --git a/rsvg_internals/src/filters/context.rs b/rsvg_internals/src/filters/context.rs
index 7f923786..4c242c8f 100644
--- a/rsvg_internals/src/filters/context.rs
+++ b/rsvg_internals/src/filters/context.rs
@@ -198,16 +198,9 @@ impl FilterContext {
let mut bg = self.background_surface.borrow_mut();
*bg = Some(
- cairo::ImageSurface::create(
- cairo::Format::ARgb32,
- self.source_surface.width(),
- self.source_surface.height(),
- )
- .map_err(FilterError::CairoError)
- .and_then(|s| {
- draw_ctx.get_snapshot(&s);
- SharedImageSurface::wrap(s, SurfaceType::SRgb).map_err(FilterError::CairoError)
- }),
+ draw_ctx
+ .get_snapshot(self.source_surface.width(), self.source_surface.height())
+ .map_err(FilterError::CairoError),
);
// Return the only existing reference as immutable.
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]