[librsvg] shared_surface: rework constructor methods
- From: Paolo Borelli <pborelli src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [librsvg] shared_surface: rework constructor methods
- Date: Sat, 11 Jan 2020 16:07:06 +0000 (UTC)
commit 4c3b51ad784f260812dfa5f8929e4a54d9b4d8d7
Author: Paolo Borelli <pborelli gnome org>
Date: Fri Jan 10 02:19:07 2020 +0100
shared_surface: rework constructor methods
Rename ::new() to ::wrap(), this is clearer since we take the cairo
surface as input. The ::copy_from_surface method does a copy
and it is moved here from mod.rs.
librsvg/c_api.rs | 2 +-
librsvg/pixbuf_utils.rs | 2 +-
librsvg_crate/tests/api.rs | 8 +--
librsvg_crate/tests/primitives.rs | 14 ++---
librsvg_crate/tests/render_to_viewport.rs | 10 ++--
librsvg_crate/tests/utils/compare_surfaces.rs | 2 +-
librsvg_crate/tests/utils/mod.rs | 4 +-
rsvg_internals/benches/box_blur.rs | 2 +-
rsvg_internals/benches/composite.rs | 4 +-
rsvg_internals/benches/lighting.rs | 32 ++++++-----
rsvg_internals/benches/pixel_iterators.rs | 4 +-
rsvg_internals/benches/srgb.rs | 2 +-
rsvg_internals/src/drawing_ctx.rs | 4 +-
rsvg_internals/src/filters/color_matrix.rs | 2 +-
rsvg_internals/src/filters/component_transfer.rs | 2 +-
rsvg_internals/src/filters/context.rs | 8 +--
rsvg_internals/src/filters/convolve_matrix.rs | 2 +-
rsvg_internals/src/filters/displacement_map.rs | 2 +-
rsvg_internals/src/filters/light/lighting.rs | 2 +-
rsvg_internals/src/filters/merge.rs | 2 +-
rsvg_internals/src/filters/mod.rs | 20 +------
rsvg_internals/src/filters/morphology.rs | 2 +-
rsvg_internals/src/filters/turbulence.rs | 2 +-
rsvg_internals/src/surface_utils/iterators.rs | 4 +-
rsvg_internals/src/surface_utils/shared_surface.rs | 63 ++++++++++++++++------
rsvg_internals/src/surface_utils/srgb.rs | 2 +-
26 files changed, 107 insertions(+), 96 deletions(-)
---
diff --git a/librsvg/c_api.rs b/librsvg/c_api.rs
index 9c96e396..6a6e78ef 100644
--- a/librsvg/c_api.rs
+++ b/librsvg/c_api.rs
@@ -730,7 +730,7 @@ impl CHandle {
.map_err(warn_on_invalid_id)?;
}
- let surface = SharedImageSurface::new(surface, SurfaceType::SRgb)?;
+ let surface = SharedImageSurface::wrap(surface, SurfaceType::SRgb)?;
pixbuf_from_surface(&surface)
}
diff --git a/librsvg/pixbuf_utils.rs b/librsvg/pixbuf_utils.rs
index 72f09718..ccc0546e 100644
--- a/librsvg/pixbuf_utils.rs
+++ b/librsvg/pixbuf_utils.rs
@@ -142,7 +142,7 @@ fn render_to_pixbuf_at_size(
handle.render_cairo_sub(&cr, None, dpi, &SizeCallback::default(), false)?;
}
- let shared_surface = SharedImageSurface::new(surface, SurfaceType::SRgb)?;
+ let shared_surface = SharedImageSurface::wrap(surface, SurfaceType::SRgb)?;
pixbuf_from_surface(&shared_surface)
}
diff --git a/librsvg_crate/tests/api.rs b/librsvg_crate/tests/api.rs
index b993003c..1052ff9e 100644
--- a/librsvg_crate/tests/api.rs
+++ b/librsvg_crate/tests/api.rs
@@ -69,7 +69,7 @@ fn render_layer() {
};
let output_surf = res
- .and_then(|_| Ok(SharedImageSurface::new(output, SurfaceType::SRgb).unwrap()))
+ .and_then(|_| Ok(SharedImageSurface::wrap(output, SurfaceType::SRgb).unwrap()))
.unwrap();
let reference_surf = cairo::ImageSurface::create(cairo::Format::ARgb32, 300, 300).unwrap();
@@ -84,7 +84,7 @@ fn render_layer() {
cr.fill();
}
- let reference_surf = SharedImageSurface::new(reference_surf, SurfaceType::SRgb).unwrap();
+ let reference_surf = SharedImageSurface::wrap(reference_surf, SurfaceType::SRgb).unwrap();
compare_to_surface(&output_surf, &reference_surf, "render_layer");
}
@@ -150,7 +150,7 @@ fn untransformed_element() {
};
let output_surf = res
- .and_then(|_| Ok(SharedImageSurface::new(output, SurfaceType::SRgb).unwrap()))
+ .and_then(|_| Ok(SharedImageSurface::wrap(output, SurfaceType::SRgb).unwrap()))
.unwrap();
let reference_surf = cairo::ImageSurface::create(cairo::Format::ARgb32, 300, 300).unwrap();
@@ -169,7 +169,7 @@ fn untransformed_element() {
cr.stroke();
}
- let reference_surf = SharedImageSurface::new(reference_surf, SurfaceType::SRgb).unwrap();
+ let reference_surf = SharedImageSurface::wrap(reference_surf, SurfaceType::SRgb).unwrap();
compare_to_surface(&output_surf, &reference_surf, "untransformed_element");
}
diff --git a/librsvg_crate/tests/primitives.rs b/librsvg_crate/tests/primitives.rs
index e1ab8e4b..47baf896 100644
--- a/librsvg_crate/tests/primitives.rs
+++ b/librsvg_crate/tests/primitives.rs
@@ -42,7 +42,7 @@ fn simple_opacity_with_transform() {
cr.fill();
}
- let reference_surf = SharedImageSurface::new(reference_surf, SurfaceType::SRgb).unwrap();
+ let reference_surf = SharedImageSurface::wrap(reference_surf, SurfaceType::SRgb).unwrap();
compare_to_surface(
&output_surf,
@@ -87,7 +87,7 @@ fn simple_opacity_with_offset_viewport() {
cr.fill();
}
- let reference_surf = SharedImageSurface::new(reference_surf, SurfaceType::SRgb).unwrap();
+ let reference_surf = SharedImageSurface::wrap(reference_surf, SurfaceType::SRgb).unwrap();
compare_to_surface(
&output_surf,
@@ -137,7 +137,7 @@ fn simple_opacity_with_scale() {
cr.fill();
}
- let reference_surf = SharedImageSurface::new(reference_surf, SurfaceType::SRgb).unwrap();
+ let reference_surf = SharedImageSurface::wrap(reference_surf, SurfaceType::SRgb).unwrap();
compare_to_surface(&output_surf, &reference_surf, "simple_opacity_with_scale");
}
@@ -195,7 +195,7 @@ fn markers_with_scale() {
}
}
- let reference_surf = SharedImageSurface::new(reference_surf, SurfaceType::SRgb).unwrap();
+ let reference_surf = SharedImageSurface::wrap(reference_surf, SurfaceType::SRgb).unwrap();
compare_to_surface(&output_surf, &reference_surf, "markers_with_scale");
}
@@ -236,7 +236,7 @@ fn opacity_inside_transformed_group() {
cr.fill();
}
- let reference_surf = SharedImageSurface::new(reference_surf, SurfaceType::SRgb).unwrap();
+ let reference_surf = SharedImageSurface::wrap(reference_surf, SurfaceType::SRgb).unwrap();
compare_to_surface(
&output_surf,
@@ -296,7 +296,7 @@ fn compound_opacity() {
cr.paint_with_alpha(0.5);
}
- let reference_surf = SharedImageSurface::new(reference_surf, SurfaceType::SRgb).unwrap();
+ let reference_surf = SharedImageSurface::wrap(reference_surf, SurfaceType::SRgb).unwrap();
compare_to_surface(&output_surf, &reference_surf, "compound_opacity");
}
@@ -363,7 +363,7 @@ fn nested_masks() {
cr.fill();
}
- let reference_surf = SharedImageSurface::new(reference_surf, SurfaceType::SRgb).unwrap();
+ let reference_surf = SharedImageSurface::wrap(reference_surf, SurfaceType::SRgb).unwrap();
compare_to_surface(&output_surf, &reference_surf, "nested_masks");
}
diff --git a/librsvg_crate/tests/render_to_viewport.rs b/librsvg_crate/tests/render_to_viewport.rs
index 4338c7ec..ee5c1a1b 100644
--- a/librsvg_crate/tests/render_to_viewport.rs
+++ b/librsvg_crate/tests/render_to_viewport.rs
@@ -41,7 +41,7 @@ fn render_to_viewport_with_different_size() {
cr.fill();
}
- let reference_surf = SharedImageSurface::new(reference_surf, SurfaceType::SRgb).unwrap();
+ let reference_surf = SharedImageSurface::wrap(reference_surf, SurfaceType::SRgb).unwrap();
compare_to_surface(
&output_surf,
@@ -85,7 +85,7 @@ fn render_to_offsetted_viewport() {
cr.fill();
}
- let reference_surf = SharedImageSurface::new(reference_surf, SurfaceType::SRgb).unwrap();
+ let reference_surf = SharedImageSurface::wrap(reference_surf, SurfaceType::SRgb).unwrap();
compare_to_surface(&output_surf, &reference_surf, "render_to_offseted_viewport");
}
@@ -128,7 +128,7 @@ fn render_to_viewport_with_transform() {
cr.fill();
}
- let reference_surf = SharedImageSurface::new(reference_surf, SurfaceType::SRgb).unwrap();
+ let reference_surf = SharedImageSurface::wrap(reference_surf, SurfaceType::SRgb).unwrap();
compare_to_surface(
&output_surf,
@@ -197,7 +197,7 @@ fn clip_on_transformed_viewport() {
cr.paint();
}
- let reference_surf = SharedImageSurface::new(reference_surf, SurfaceType::SRgb).unwrap();
+ let reference_surf = SharedImageSurface::wrap(reference_surf, SurfaceType::SRgb).unwrap();
compare_to_surface(
&output_surf,
@@ -266,7 +266,7 @@ fn mask_on_transformed_viewport() {
cr.paint();
}
- let reference_surf = SharedImageSurface::new(reference_surf, SurfaceType::SRgb).unwrap();
+ let reference_surf = SharedImageSurface::wrap(reference_surf, SurfaceType::SRgb).unwrap();
compare_to_surface(
&output_surf,
diff --git a/librsvg_crate/tests/utils/compare_surfaces.rs b/librsvg_crate/tests/utils/compare_surfaces.rs
index f5b5ada8..318aa4e2 100644
--- a/librsvg_crate/tests/utils/compare_surfaces.rs
+++ b/librsvg_crate/tests/utils/compare_surfaces.rs
@@ -120,7 +120,7 @@ pub fn compare_surfaces(
}
}
- let surface = SharedImageSurface::new(surf_diff, SurfaceType::SRgb)?;
+ let surface = SharedImageSurface::wrap(surf_diff, SurfaceType::SRgb)?;
Ok(BufferDiff::Diff(Diff {
num_pixels_changed,
diff --git a/librsvg_crate/tests/utils/mod.rs b/librsvg_crate/tests/utils/mod.rs
index d1f5aa52..1dadb167 100644
--- a/librsvg_crate/tests/utils/mod.rs
+++ b/librsvg_crate/tests/utils/mod.rs
@@ -49,7 +49,7 @@ pub fn render_document<F: FnOnce(&cairo::Context)>(
Ok(renderer.render_document(&cr, &viewport)?)
};
- res.and_then(|_| Ok(SharedImageSurface::new(output, SurfaceType::SRgb)?))
+ res.and_then(|_| Ok(SharedImageSurface::wrap(output, SurfaceType::SRgb)?))
}
pub fn output_dir() -> PathBuf {
@@ -100,7 +100,7 @@ pub fn compare_to_file(
let mut fixture_file = BufReader::new(file);
let expected = cairo::ImageSurface::create_from_png(&mut fixture_file).unwrap();
- let expected_surf = SharedImageSurface::new(expected, SurfaceType::SRgb).unwrap();
+ let expected_surf = SharedImageSurface::wrap(expected, SurfaceType::SRgb).unwrap();
let diff = compare_surfaces(output_surf, &expected_surf).unwrap();
diff --git a/rsvg_internals/benches/box_blur.rs b/rsvg_internals/benches/box_blur.rs
index 804b9729..cefd20ae 100644
--- a/rsvg_internals/benches/box_blur.rs
+++ b/rsvg_internals/benches/box_blur.rs
@@ -27,7 +27,7 @@ fn bench_box_blur(c: &mut Criterion) {
} else {
SurfaceType::SRgb
};
- let input_surface = SharedImageSurface::new(input_surface, surface_type).unwrap();
+ let input_surface = SharedImageSurface::wrap(input_surface, surface_type).unwrap();
let mut output_surface =
cairo::ImageSurface::create(cairo::Format::ARgb32, SURFACE_SIDE, SURFACE_SIDE)
diff --git a/rsvg_internals/benches/composite.rs b/rsvg_internals/benches/composite.rs
index 52639fc3..17bc0416 100644
--- a/rsvg_internals/benches/composite.rs
+++ b/rsvg_internals/benches/composite.rs
@@ -19,10 +19,10 @@ fn bench_composite(c: &mut Criterion) {
c.bench_function("composite arithmetic", |b| {
let input_surface =
cairo::ImageSurface::create(cairo::Format::ARgb32, SURFACE_SIDE, SURFACE_SIDE).unwrap();
- let input_surface = SharedImageSurface::new(input_surface, SurfaceType::SRgb).unwrap();
+ let input_surface = SharedImageSurface::wrap(input_surface, SurfaceType::SRgb).unwrap();
let input_2_surface =
cairo::ImageSurface::create(cairo::Format::ARgb32, SURFACE_SIDE, SURFACE_SIDE).unwrap();
- let input_2_surface = SharedImageSurface::new(input_2_surface, SurfaceType::SRgb).unwrap();
+ let input_2_surface = SharedImageSurface::wrap(input_2_surface, SurfaceType::SRgb).unwrap();
let mut output_surface =
cairo::ImageSurface::create(cairo::Format::ARgb32, SURFACE_SIDE, SURFACE_SIDE).unwrap();
diff --git a/rsvg_internals/benches/lighting.rs b/rsvg_internals/benches/lighting.rs
index bfeea330..c8630386 100644
--- a/rsvg_internals/benches/lighting.rs
+++ b/rsvg_internals/benches/lighting.rs
@@ -183,14 +183,13 @@ const BOUNDS: IRect = IRect {
fn bench_normal(c: &mut Criterion) {
c.bench_function("normal", |b| {
- let input_surface =
- cairo::ImageSurface::create(cairo::Format::ARgb32, SURFACE_SIDE, SURFACE_SIDE).unwrap();
- let input_surface = SharedImageSurface::new(input_surface, SurfaceType::SRgb).unwrap();
+ let surface =
+ SharedImageSurface::empty(SURFACE_SIDE, SURFACE_SIDE, SurfaceType::SRgb).unwrap();
b.iter(|| {
let mut z = 0;
- for (x, y, _pixel) in Pixels::within(&input_surface, BOUNDS) {
- let n = normal(&input_surface, BOUNDS, x, y);
+ for (x, y, _pixel) in Pixels::within(&surface, BOUNDS) {
+ let n = normal(&surface, BOUNDS, x, y);
z += n.normal.x;
}
z
@@ -198,65 +197,64 @@ fn bench_normal(c: &mut Criterion) {
});
c.bench_function("normal unrolled", |b| {
- let input_surface =
- cairo::ImageSurface::create(cairo::Format::ARgb32, SURFACE_SIDE, SURFACE_SIDE).unwrap();
- let input_surface = SharedImageSurface::new(input_surface, SurfaceType::SRgb).unwrap();
+ let surface =
+ SharedImageSurface::empty(SURFACE_SIDE, SURFACE_SIDE, SurfaceType::SRgb).unwrap();
b.iter(|| {
let mut z = 0;
// Top left.
{
- let n = top_left_normal(&input_surface, BOUNDS);
+ let n = top_left_normal(&surface, BOUNDS);
z += n.normal.x;
}
// Top right.
{
- let n = top_right_normal(&input_surface, BOUNDS);
+ let n = top_right_normal(&surface, BOUNDS);
z += n.normal.x;
}
// Bottom left.
{
- let n = bottom_left_normal(&input_surface, BOUNDS);
+ let n = bottom_left_normal(&surface, BOUNDS);
z += n.normal.x;
}
// Bottom right.
{
- let n = bottom_right_normal(&input_surface, BOUNDS);
+ let n = bottom_right_normal(&surface, BOUNDS);
z += n.normal.x;
}
// Top row.
for x in BOUNDS.x0 as u32 + 1..BOUNDS.x1 as u32 - 1 {
- let n = top_row_normal(&input_surface, BOUNDS, x);
+ let n = top_row_normal(&surface, BOUNDS, x);
z += n.normal.x;
}
// Bottom row.
for x in BOUNDS.x0 as u32 + 1..BOUNDS.x1 as u32 - 1 {
- let n = bottom_row_normal(&input_surface, BOUNDS, x);
+ let n = bottom_row_normal(&surface, BOUNDS, x);
z += n.normal.x;
}
// Left column.
for y in BOUNDS.y0 as u32 + 1..BOUNDS.y1 as u32 - 1 {
- let n = left_column_normal(&input_surface, BOUNDS, y);
+ let n = left_column_normal(&surface, BOUNDS, y);
z += n.normal.x;
}
// Right column.
for y in BOUNDS.y0 as u32 + 1..BOUNDS.y1 as u32 - 1 {
- let n = right_column_normal(&input_surface, BOUNDS, y);
+ let n = right_column_normal(&surface, BOUNDS, y);
z += n.normal.x;
}
// Interior pixels.
for y in BOUNDS.y0 as u32 + 1..BOUNDS.y1 as u32 - 1 {
for x in BOUNDS.x0 as u32 + 1..BOUNDS.x1 as u32 - 1 {
- let n = interior_normal(&input_surface, BOUNDS, x, y);
+ let n = interior_normal(&surface, BOUNDS, x, y);
z += n.normal.x;
}
}
diff --git a/rsvg_internals/benches/pixel_iterators.rs b/rsvg_internals/benches/pixel_iterators.rs
index a85c69a0..7c6be70a 100644
--- a/rsvg_internals/benches/pixel_iterators.rs
+++ b/rsvg_internals/benches/pixel_iterators.rs
@@ -49,7 +49,7 @@ fn bench_pixel_iterators(c: &mut Criterion) {
c.bench_function("pixel_iterators get_pixel", |b| {
let surface =
cairo::ImageSurface::create(cairo::Format::ARgb32, SURFACE_SIDE, SURFACE_SIDE).unwrap();
- let surface = SharedImageSurface::new(surface, SurfaceType::SRgb).unwrap();
+ let surface = SharedImageSurface::wrap(surface, SurfaceType::SRgb).unwrap();
let bounds = black_box(BOUNDS);
@@ -77,7 +77,7 @@ fn bench_pixel_iterators(c: &mut Criterion) {
c.bench_function("pixel_iterators pixels", |b| {
let surface =
cairo::ImageSurface::create(cairo::Format::ARgb32, SURFACE_SIDE, SURFACE_SIDE).unwrap();
- let data = SharedImageSurface::new(surface, SurfaceType::SRgb).unwrap();
+ let data = SharedImageSurface::wrap(surface, SurfaceType::SRgb).unwrap();
let bounds = black_box(BOUNDS);
diff --git a/rsvg_internals/benches/srgb.rs b/rsvg_internals/benches/srgb.rs
index c240d3a8..8e70ae47 100644
--- a/rsvg_internals/benches/srgb.rs
+++ b/rsvg_internals/benches/srgb.rs
@@ -45,7 +45,7 @@ fn bench_srgb_linearization(c: &mut Criterion) {
}
}
- let surface = SharedImageSurface::new(surface, SurfaceType::LinearRgb).unwrap();
+ let surface = SharedImageSurface::wrap(surface, SurfaceType::LinearRgb).unwrap();
let bounds = black_box(BOUNDS);
diff --git a/rsvg_internals/src/drawing_ctx.rs b/rsvg_internals/src/drawing_ctx.rs
index 0a17833b..4fe72161 100644
--- a/rsvg_internals/src/drawing_ctx.rs
+++ b/rsvg_internals/src/drawing_ctx.rs
@@ -441,7 +441,7 @@ impl DrawingCtx {
let Opacity(opacity) = values.opacity;
- let mask = SharedImageSurface::new(mask_content_surface, SurfaceType::SRgb)?
+ let mask = SharedImageSurface::wrap(mask_content_surface, SurfaceType::SRgb)?
.to_mask(opacity)?
.into_image_surface()?;
@@ -962,7 +962,7 @@ impl DrawingCtx {
self.cr = save_cr;
self.rect = save_rect;
- Ok(SharedImageSurface::new(surface, SurfaceType::SRgb)?)
+ Ok(SharedImageSurface::wrap(surface, SurfaceType::SRgb)?)
}
pub fn draw_node_from_stack(
diff --git a/rsvg_internals/src/filters/color_matrix.rs b/rsvg_internals/src/filters/color_matrix.rs
index 42cec296..6b2f53c2 100644
--- a/rsvg_internals/src/filters/color_matrix.rs
+++ b/rsvg_internals/src/filters/color_matrix.rs
@@ -211,7 +211,7 @@ impl FilterEffect for FeColorMatrix {
Ok(FilterResult {
name: self.base.result.clone(),
output: FilterOutput {
- surface: SharedImageSurface::new(output_surface, input.surface().surface_type())?,
+ surface: SharedImageSurface::wrap(output_surface, input.surface().surface_type())?,
bounds,
},
})
diff --git a/rsvg_internals/src/filters/component_transfer.rs
b/rsvg_internals/src/filters/component_transfer.rs
index c555fda2..ada08e62 100644
--- a/rsvg_internals/src/filters/component_transfer.rs
+++ b/rsvg_internals/src/filters/component_transfer.rs
@@ -381,7 +381,7 @@ impl FilterEffect for FeComponentTransfer {
Ok(FilterResult {
name: self.base.result.clone(),
output: FilterOutput {
- surface: SharedImageSurface::new(output_surface, input.surface().surface_type())?,
+ surface: SharedImageSurface::wrap(output_surface, input.surface().surface_type())?,
bounds,
},
})
diff --git a/rsvg_internals/src/filters/context.rs b/rsvg_internals/src/filters/context.rs
index 2b47806f..7f923786 100644
--- a/rsvg_internals/src/filters/context.rs
+++ b/rsvg_internals/src/filters/context.rs
@@ -206,7 +206,7 @@ impl FilterContext {
.map_err(FilterError::CairoError)
.and_then(|s| {
draw_ctx.get_snapshot(&s);
- SharedImageSurface::new(s, SurfaceType::SRgb).map_err(FilterError::CairoError)
+ SharedImageSurface::wrap(s, SurfaceType::SRgb).map_err(FilterError::CairoError)
}),
);
@@ -234,7 +234,7 @@ impl FilterContext {
self.source_surface.height(),
)?;
- Ok(SharedImageSurface::new(
+ Ok(SharedImageSurface::wrap(
empty_surface,
SurfaceType::AlphaOnly,
)?)
@@ -365,7 +365,7 @@ impl FilterContext {
.get_paint_server_surface(draw_ctx, &values.fill.0, values.fill_opacity.0)
.map_err(FilterError::CairoError)
.and_then(|surface| {
- SharedImageSurface::new(surface, SurfaceType::SRgb)
+ SharedImageSurface::wrap(surface, SurfaceType::SRgb)
.map_err(FilterError::CairoError)
})
.map(FilterInput::StandardInput),
@@ -374,7 +374,7 @@ impl FilterContext {
.get_paint_server_surface(draw_ctx, &values.stroke.0, values.stroke_opacity.0)
.map_err(FilterError::CairoError)
.and_then(|surface| {
- SharedImageSurface::new(surface, SurfaceType::SRgb)
+ SharedImageSurface::wrap(surface, SurfaceType::SRgb)
.map_err(FilterError::CairoError)
})
.map(FilterInput::StandardInput),
diff --git a/rsvg_internals/src/filters/convolve_matrix.rs b/rsvg_internals/src/filters/convolve_matrix.rs
index 870e6f66..df3d074b 100644
--- a/rsvg_internals/src/filters/convolve_matrix.rs
+++ b/rsvg_internals/src/filters/convolve_matrix.rs
@@ -303,7 +303,7 @@ impl FilterEffect for FeConvolveMatrix {
}
let mut output_surface =
- SharedImageSurface::new(output_surface, input.surface().surface_type())?;
+ SharedImageSurface::wrap(output_surface, input.surface().surface_type())?;
if let Some((ox, oy)) = scale {
// Scale the output surface back.
diff --git a/rsvg_internals/src/filters/displacement_map.rs b/rsvg_internals/src/filters/displacement_map.rs
index c61c0eb2..7588a228 100644
--- a/rsvg_internals/src/filters/displacement_map.rs
+++ b/rsvg_internals/src/filters/displacement_map.rs
@@ -131,7 +131,7 @@ impl FilterEffect for FeDisplacementMap {
Ok(FilterResult {
name: self.base.result.clone(),
output: FilterOutput {
- surface: SharedImageSurface::new(output_surface, input.surface().surface_type())?,
+ surface: SharedImageSurface::wrap(output_surface, input.surface().surface_type())?,
bounds,
},
})
diff --git a/rsvg_internals/src/filters/light/lighting.rs b/rsvg_internals/src/filters/light/lighting.rs
index be68ea76..97b39c33 100644
--- a/rsvg_internals/src/filters/light/lighting.rs
+++ b/rsvg_internals/src/filters/light/lighting.rs
@@ -443,7 +443,7 @@ macro_rules! impl_lighting_filter {
// The generated color values are in the color space determined by
// color-interpolation-filters.
let surface_type = SurfaceType::from(values.color_interpolation_filters);
- let mut output_surface = SharedImageSurface::new(output_surface, surface_type)?;
+ let mut output_surface = SharedImageSurface::wrap(output_surface, surface_type)?;
if let Some((ox, oy)) = scale {
// Scale the output surface back.
diff --git a/rsvg_internals/src/filters/merge.rs b/rsvg_internals/src/filters/merge.rs
index 88daf571..f650fa59 100644
--- a/rsvg_internals/src/filters/merge.rs
+++ b/rsvg_internals/src/filters/merge.rs
@@ -117,7 +117,7 @@ impl FilterEffect for FeMerge {
let output_surface = match output_surface {
Some(surface) => surface,
- None => SharedImageSurface::new(
+ None => SharedImageSurface::wrap(
cairo::ImageSurface::create(
cairo::Format::ARgb32,
ctx.source_graphic().width(),
diff --git a/rsvg_internals/src/filters/mod.rs b/rsvg_internals/src/filters/mod.rs
index 0ebde6d6..d3c3ca0f 100644
--- a/rsvg_internals/src/filters/mod.rs
+++ b/rsvg_internals/src/filters/mod.rs
@@ -235,24 +235,6 @@ 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,
@@ -267,7 +249,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 = copy_to_shared_surface(source)?;
+ let source_surface = SharedImageSurface::copy_from_surface(source)?;
let mut filter_ctx = FilterContext::new(
filter_node,
diff --git a/rsvg_internals/src/filters/morphology.rs b/rsvg_internals/src/filters/morphology.rs
index b602f9d5..046a8c30 100644
--- a/rsvg_internals/src/filters/morphology.rs
+++ b/rsvg_internals/src/filters/morphology.rs
@@ -145,7 +145,7 @@ impl FilterEffect for FeMorphology {
Ok(FilterResult {
name: self.base.result.clone(),
output: FilterOutput {
- surface: SharedImageSurface::new(output_surface, input.surface().surface_type())?,
+ surface: SharedImageSurface::wrap(output_surface, input.surface().surface_type())?,
bounds,
},
})
diff --git a/rsvg_internals/src/filters/turbulence.rs b/rsvg_internals/src/filters/turbulence.rs
index 031dabeb..348ae3f7 100644
--- a/rsvg_internals/src/filters/turbulence.rs
+++ b/rsvg_internals/src/filters/turbulence.rs
@@ -405,7 +405,7 @@ impl FilterEffect for FeTurbulence {
Ok(FilterResult {
name: self.base.result.clone(),
output: FilterOutput {
- surface: SharedImageSurface::new(output_surface, surface_type)?,
+ surface: SharedImageSurface::wrap(output_surface, surface_type)?,
bounds,
},
})
diff --git a/rsvg_internals/src/surface_utils/iterators.rs b/rsvg_internals/src/surface_utils/iterators.rs
index 7899e129..920da89b 100644
--- a/rsvg_internals/src/surface_utils/iterators.rs
+++ b/rsvg_internals/src/surface_utils/iterators.rs
@@ -201,7 +201,7 @@ mod tests {
const WIDTH: i32 = 32;
const HEIGHT: i32 = 64;
- let surface = SharedImageSurface::new(
+ let surface = SharedImageSurface::wrap(
cairo::ImageSurface::create(cairo::Format::ARgb32, WIDTH, HEIGHT).unwrap(),
SurfaceType::SRgb,
)
@@ -240,7 +240,7 @@ mod tests {
const WIDTH: i32 = 32;
const HEIGHT: i32 = 64;
- let surface = SharedImageSurface::new(
+ let surface = SharedImageSurface::wrap(
cairo::ImageSurface::create(cairo::Format::ARgb32, WIDTH, HEIGHT).unwrap(),
SurfaceType::SRgb,
)
diff --git a/rsvg_internals/src/surface_utils/shared_surface.rs
b/rsvg_internals/src/surface_utils/shared_surface.rs
index 6e978900..bcfc7f0e 100644
--- a/rsvg_internals/src/surface_utils/shared_surface.rs
+++ b/rsvg_internals/src/surface_utils/shared_surface.rs
@@ -130,7 +130,7 @@ impl SharedImageSurface {
/// Panics if the surface format isn't `ARgb32` and if the surface is not unique, that is, its
/// reference count isn't 1.
#[inline]
- pub fn new(surface: ImageSurface, surface_type: SurfaceType) -> Result<Self, cairo::Status> {
+ pub fn wrap(surface: ImageSurface, surface_type: SurfaceType) -> Result<Self, cairo::Status> {
// get_pixel() assumes ARgb32.
assert_eq!(surface.get_format(), cairo::Format::ARgb32);
@@ -166,6 +166,37 @@ impl SharedImageSurface {
})
}
+ /// Creates a `SharedImageSurface` copying from an `ImageSurface`, even if it
+ /// does not have a reference count of 1.
+ #[inline]
+ pub fn copy_from_surface(surface: &ImageSurface) -> Result<Self, 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::wrap(copy, SurfaceType::SRgb)
+ }
+
+ /// Creates an empty `SharedImageSurface` of the given size and `type`.
+ #[inline]
+ pub fn empty(
+ width: i32,
+ height: i32,
+ surface_type: SurfaceType,
+ ) -> Result<Self, cairo::Status> {
+ let s = cairo::ImageSurface::create(cairo::Format::ARgb32, width, height)?;
+
+ SharedImageSurface::wrap(s, surface_type)
+ }
+
/// Converts this `SharedImageSurface` back into a Cairo image surface.
#[inline]
pub fn into_image_surface(self) -> Result<ImageSurface, cairo::Status> {
@@ -256,7 +287,7 @@ impl SharedImageSurface {
(_, _) => (),
}
- Self::new(surf, SurfaceType::SRgb)
+ Self::wrap(surf, SurfaceType::SRgb)
}
/// Returns the surface width.
@@ -364,7 +395,7 @@ impl SharedImageSurface {
cr.paint();
}
- SharedImageSurface::new(output_surface, self.surface_type)
+ SharedImageSurface::wrap(output_surface, self.surface_type)
}
/// Returns a scaled version of a surface and bounds.
@@ -405,7 +436,7 @@ impl SharedImageSurface {
}
}
- SharedImageSurface::new(output_surface, SurfaceType::AlphaOnly)
+ SharedImageSurface::wrap(output_surface, SurfaceType::AlphaOnly)
}
/// Returns a surface whose alpha channel for each pixel is equal to the
@@ -430,7 +461,7 @@ impl SharedImageSurface {
}
}
- SharedImageSurface::new(output_surface, self.surface_type)
+ SharedImageSurface::wrap(output_surface, self.surface_type)
}
/// Returns a surface with pre-multiplication of color values undone.
@@ -455,7 +486,7 @@ impl SharedImageSurface {
}
}
- SharedImageSurface::new(output_surface, self.surface_type)
+ SharedImageSurface::wrap(output_surface, self.surface_type)
}
/// Converts the surface to the linear sRGB color space.
@@ -580,7 +611,7 @@ impl SharedImageSurface {
}
}
- SharedImageSurface::new(output_surface, self.surface_type)
+ SharedImageSurface::wrap(output_surface, self.surface_type)
}
/// Performs a horizontal or vertical box blur.
@@ -902,7 +933,7 @@ impl SharedImageSurface {
self.box_blur_loop::<B, NotAlphaOnly>(&mut output_surface, bounds, kernel_size, target);
}
- SharedImageSurface::new(output_surface, self.surface_type)
+ SharedImageSurface::wrap(output_surface, self.surface_type)
}
/// Fills the with a specified color.
@@ -931,7 +962,7 @@ impl SharedImageSurface {
cr.paint();
}
- SharedImageSurface::new(output_surface, self.surface_type)
+ SharedImageSurface::wrap(output_surface, self.surface_type)
}
/// Offsets the image of the specified amount.
@@ -960,7 +991,7 @@ impl SharedImageSurface {
cr.paint();
}
- SharedImageSurface::new(output_surface, self.surface_type)
+ SharedImageSurface::wrap(output_surface, self.surface_type)
}
/// Returns a new surface of the same size, with the contents of the
@@ -1000,7 +1031,7 @@ impl SharedImageSurface {
cr.paint();
}
- SharedImageSurface::new(output_surface, image.surface_type)
+ SharedImageSurface::wrap(output_surface, image.surface_type)
}
/// Creates a new surface with the size and content specified in `bounds`
@@ -1015,7 +1046,7 @@ impl SharedImageSurface {
cr.paint();
}
- SharedImageSurface::new(output_surface, self.surface_type)
+ SharedImageSurface::wrap(output_surface, self.surface_type)
}
/// Returns a new surface of the same size, with the contents of the specified
@@ -1048,7 +1079,7 @@ impl SharedImageSurface {
cr.paint();
}
- SharedImageSurface::new(output_surface, image.surface_type)
+ SharedImageSurface::wrap(output_surface, image.surface_type)
}
/// Performs the combination of two input surfaces using Porter-Duff
@@ -1076,7 +1107,7 @@ impl SharedImageSurface {
cr.paint();
}
- SharedImageSurface::new(
+ SharedImageSurface::wrap(
output_surface,
self.surface_type.combine(other.surface_type),
)
@@ -1104,7 +1135,7 @@ impl SharedImageSurface {
composite_arithmetic(self, other, &mut output_surface, bounds, k1, k2, k3, k4);
- SharedImageSurface::new(
+ SharedImageSurface::wrap(
output_surface,
self.surface_type.combine(other.surface_type),
)
@@ -1196,7 +1227,7 @@ mod tests {
}
}
- let surface = SharedImageSurface::new(surface, SurfaceType::SRgb).unwrap();
+ let surface = SharedImageSurface::wrap(surface, SurfaceType::SRgb).unwrap();
let alpha = surface.extract_alpha(bounds).unwrap();
for (x, y, p, pa) in
diff --git a/rsvg_internals/src/surface_utils/srgb.rs b/rsvg_internals/src/surface_utils/srgb.rs
index d637abb4..39ca2d31 100644
--- a/rsvg_internals/src/surface_utils/srgb.rs
+++ b/rsvg_internals/src/surface_utils/srgb.rs
@@ -78,7 +78,7 @@ fn map_unpremultiplied_components<F: Fn(u8) -> u8>(
let mut output_surface = cairo::ImageSurface::create(cairo::Format::ARgb32, width, height)?;
map_unpremultiplied_components_loop(surface, &mut output_surface, bounds, f);
- SharedImageSurface::new(output_surface, new_type)
+ SharedImageSurface::wrap(output_surface, new_type)
}
/// Converts an sRGB surface to a linear sRGB surface (undoes the gamma correction).
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]