[librsvg: 69/90] Extract function to copy a surface to a SharedImageSurface
- From: Federico Mena Quintero <federico src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [librsvg: 69/90] Extract function to copy a surface to a SharedImageSurface
- Date: Tue, 26 Mar 2019 19:17:52 +0000 (UTC)
commit be320659469520eb81fd75487907ac91820d4cde
Author: Federico Mena Quintero <federico gnome org>
Date: Thu Mar 21 17:14:43 2019 -0600
Extract function to copy a surface to a SharedImageSurface
rsvg_internals/src/filters/mod.rs | 30 +++++++++++++++++++-----------
1 file changed, 19 insertions(+), 11 deletions(-)
---
diff --git a/rsvg_internals/src/filters/mod.rs b/rsvg_internals/src/filters/mod.rs
index 7b3137ce..32c08ac3 100644
--- a/rsvg_internals/src/filters/mod.rs
+++ b/rsvg_internals/src/filters/mod.rs
@@ -228,6 +228,24 @@ impl Deref for PrimitiveWithInput {
}
}
+/// Creates a `SharedImageSurface` from an `ImageSurface`, even if the former
+/// does not have a reference count of 1.
+fn copy_to_shared_surface(
+ surface: &cairo::ImageSurface,
+) -> Result<SharedImageSurface, cairo::Status> {
+ let copy = cairo::ImageSurface::create(
+ cairo::Format::ARgb32,
+ surface.get_width(),
+ surface.get_height(),
+ )?;
+ {
+ let cr = cairo::Context::new(©);
+ cr.set_source_surface(surface, 0f64, 0f64);
+ cr.paint();
+ }
+ SharedImageSurface::new(copy, SurfaceType::SRgb)
+}
+
/// Applies a filter and returns the resulting surface.
pub fn render(
filter_node: &RsvgNode,
@@ -242,17 +260,7 @@ pub fn render(
// 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 = cairo::ImageSurface::create(
- cairo::Format::ARgb32,
- source.get_width(),
- source.get_height(),
- )?;
- {
- let cr = cairo::Context::new(&source_surface);
- cr.set_source_surface(source, 0f64, 0f64);
- cr.paint();
- }
- let source_surface = SharedImageSurface::new(source_surface, SurfaceType::SRgb)?;
+ let source_surface = copy_to_shared_surface(source)?;
let mut filter_ctx = FilterContext::new(
filter_node,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]