diff options
Diffstat (limited to 'rsvg_internals/src/surface_utils/shared_surface.rs')
-rw-r--r-- | rsvg_internals/src/surface_utils/shared_surface.rs | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/rsvg_internals/src/surface_utils/shared_surface.rs b/rsvg_internals/src/surface_utils/shared_surface.rs index 20de1886..b8737598 100644 --- a/rsvg_internals/src/surface_utils/shared_surface.rs +++ b/rsvg_internals/src/surface_utils/shared_surface.rs @@ -6,6 +6,8 @@ use cairo::{self, ImageSurface}; use cairo_sys; use glib::translate::{Stash, ToGlibPtr}; +use filters::context::IRect; + use super::Pixel; /// Wrapper for a Cairo image surface that allows shared access. @@ -125,6 +127,26 @@ impl SharedImageSurface { cr.set_source_surface(&self.surface, x, y); } + /// Returns a new `ImageSurface` with the same contents as the one stored in this + /// `SharedImageSurface` within the given bounds. + pub fn copy_surface(&self, bounds: IRect) -> Result<ImageSurface, cairo::Status> { + let output_surface = ImageSurface::create(cairo::Format::ARgb32, self.width, self.height)?; + + let cr = cairo::Context::new(&output_surface); + cr.rectangle( + bounds.x0 as f64, + bounds.y0 as f64, + (bounds.x1 - bounds.x0) as f64, + (bounds.y1 - bounds.y0) as f64, + ); + cr.clip(); + + cr.set_source_surface(&self.surface, 0f64, 0f64); + cr.paint(); + + Ok(output_surface) + } + /// Returns a raw pointer to the underlying surface. /// /// # Safety |