[librsvg] Svg::lookup_image(): Return a SharedImageSurface
- From: Federico Mena Quintero <federico src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [librsvg] Svg::lookup_image(): Return a SharedImageSurface
- Date: Tue, 15 Jan 2019 17:00:40 +0000 (UTC)
commit 0df760de48aafdeb869666b8ffa93656919bd491
Author: Federico Mena Quintero <federico gnome org>
Date: Tue Jan 15 10:56:16 2019 -0600
Svg::lookup_image(): Return a SharedImageSurface
The idea is to keep only immutable surfaces around. This adds a
method SharedImageSurface::to_cairo_pattern(), since creating a
pattern requires access to the inner surface.
rsvg_internals/src/drawing_ctx.rs | 3 ++-
rsvg_internals/src/filters/image.rs | 12 ++++++------
rsvg_internals/src/image.rs | 8 ++++----
rsvg_internals/src/surface_utils/shared_surface.rs | 5 +++++
rsvg_internals/src/svg.rs | 9 +++------
5 files changed, 20 insertions(+), 17 deletions(-)
---
diff --git a/rsvg_internals/src/drawing_ctx.rs b/rsvg_internals/src/drawing_ctx.rs
index b961e5e6..1348fe04 100644
--- a/rsvg_internals/src/drawing_ctx.rs
+++ b/rsvg_internals/src/drawing_ctx.rs
@@ -29,6 +29,7 @@ use state::{
StrokeLinecap,
StrokeLinejoin,
};
+use surface_utils::shared_surface::SharedImageSurface;
use svg::Svg;
use unit_interval::UnitInterval;
use viewbox::ViewBox;
@@ -713,7 +714,7 @@ impl DrawingCtx {
}
}
- pub fn lookup_image(&self, href: &str) -> Option<cairo::ImageSurface> {
+ pub fn lookup_image(&self, href: &str) -> Option<SharedImageSurface> {
self.svg.lookup_image(href)
}
diff --git a/rsvg_internals/src/filters/image.rs b/rsvg_internals/src/filters/image.rs
index 262cb866..3dda5c7b 100644
--- a/rsvg_internals/src/filters/image.rs
+++ b/rsvg_internals/src/filters/image.rs
@@ -139,8 +139,8 @@ impl Image {
let render_bounds = bounds_builder.into_irect_without_clipping(draw_ctx);
let aspect = self.aspect.get();
let (x, y, w, h) = aspect.compute(
- f64::from(surface.get_width()),
- f64::from(surface.get_height()),
+ f64::from(surface.width()),
+ f64::from(surface.height()),
f64::from(render_bounds.x0),
f64::from(render_bounds.y0),
f64::from(render_bounds.x1 - render_bounds.x0),
@@ -148,12 +148,12 @@ impl Image {
);
if w != 0f64 && h != 0f64 {
- let ptn = cairo::SurfacePattern::create(&surface);
+ let ptn = surface.to_cairo_pattern();
let mut matrix = cairo::Matrix::new(
- w / f64::from(surface.get_width()),
+ w / f64::from(surface.width()),
0f64,
0f64,
- h / f64::from(surface.get_height()),
+ h / f64::from(surface.height()),
x,
y,
);
@@ -169,7 +169,7 @@ impl Image {
f64::from(bounds.y1 - bounds.y0),
);
cr.clip();
- cr.set_source(&cairo::Pattern::SurfacePattern(ptn));
+ cr.set_source(&ptn);
cr.paint();
}
diff --git a/rsvg_internals/src/image.rs b/rsvg_internals/src/image.rs
index 74041e07..60fa18bd 100644
--- a/rsvg_internals/src/image.rs
+++ b/rsvg_internals/src/image.rs
@@ -108,8 +108,8 @@ impl NodeTrait for NodeImage {
dc.clip(x, y, w, h);
}
- let width = surface.get_width();
- let height = surface.get_height();
+ let width = surface.width();
+ let height = surface.height();
if clipping || width == 0 || height == 0 {
return Ok(());
}
@@ -146,12 +146,12 @@ impl NodeTrait for NodeImage {
// For example, in svg1.1/filters-blend-01-b.svgthere's a completely
// opaque 100×1 image of a gradient scaled to 100×98 which ends up
// transparent almost everywhere without this fix (which it shouldn't).
- let ptn = cairo::SurfacePattern::create(&surface);
+ let ptn = surface.to_cairo_pattern();
let mut matrix = cairo::Matrix::identity();
matrix.translate(-x, -y);
ptn.set_matrix(matrix);
ptn.set_extend(cairo::Extend::Pad);
- cr.set_source(&cairo::Pattern::SurfacePattern(ptn));
+ cr.set_source(&ptn);
// Clip is needed due to extend being set to pad.
cr.rectangle(x, y, width, height);
diff --git a/rsvg_internals/src/surface_utils/shared_surface.rs
b/rsvg_internals/src/surface_utils/shared_surface.rs
index 05c6a57d..ad45c8fd 100644
--- a/rsvg_internals/src/surface_utils/shared_surface.rs
+++ b/rsvg_internals/src/surface_utils/shared_surface.rs
@@ -295,6 +295,11 @@ impl SharedImageSurface {
cr.set_source_surface(&self.surface, x, y);
}
+ /// Creates a Cairo surface pattern from the surface
+ pub fn to_cairo_pattern(&self) -> cairo::Pattern {
+ cairo::Pattern::SurfacePattern(cairo::SurfacePattern::create(&self.surface))
+ }
+
/// 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> {
diff --git a/rsvg_internals/src/svg.rs b/rsvg_internals/src/svg.rs
index 9d7abc11..a07222f0 100644
--- a/rsvg_internals/src/svg.rs
+++ b/rsvg_internals/src/svg.rs
@@ -1,4 +1,4 @@
-use cairo::{ImageSurface, Status};
+use cairo::Status;
use gdk_pixbuf::{PixbufLoader, PixbufLoaderExt};
use gio;
use glib::translate::*;
@@ -81,11 +81,8 @@ impl Svg {
self.ids.get(id).map(|n| (*n).clone())
}
- pub fn lookup_image(&self, href: &str) -> Option<ImageSurface> {
- self.images
- .borrow_mut()
- .lookup(&self.load_options, href)
- .and_then(|s| s.into_image_surface().ok())
+ pub fn lookup_image(&self, href: &str) -> Option<SharedImageSurface> {
+ self.images.borrow_mut().lookup(&self.load_options, href)
}
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]