[librsvg: 25/30] ImageSurface::draw is now generic on the error type
- From: Marge Bot <marge-bot src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [librsvg: 25/30] ImageSurface::draw is now generic on the error type
- Date: Wed, 23 Jun 2021 23:05:40 +0000 (UTC)
commit 68044cff571715b60b5dfbd38c7a9801aaa66887
Author: Federico Mena Quintero <federico gnome org>
Date: Mon Jun 21 20:42:11 2021 -0500
ImageSurface::draw is now generic on the error type
this-is-fine.gif
Part-of: <https://gitlab.gnome.org/GNOME/librsvg/-/merge_requests/516>
src/drawing_ctx.rs | 32 +++++++++++++++++++-------------
src/filters/context.rs | 28 ++++++++++++----------------
src/filters/displacement_map.rs | 2 +-
src/surface_utils/shared_surface.rs | 13 +++++++++----
4 files changed, 41 insertions(+), 34 deletions(-)
---
diff --git a/src/drawing_ctx.rs b/src/drawing_ctx.rs
index 67114d35..a196bc70 100644
--- a/src/drawing_ctx.rs
+++ b/src/drawing_ctx.rs
@@ -946,7 +946,10 @@ impl DrawingCtx {
Ok(surface)
}
- fn set_gradient(self: &mut DrawingCtx, gradient: &UserSpaceGradient) -> Result<(), cairo::Error> {
+ fn set_gradient(
+ self: &mut DrawingCtx,
+ gradient: &UserSpaceGradient,
+ ) -> Result<(), cairo::Error> {
let g = match gradient.variant {
GradientVariant::Linear { x1, y1, x2, y2 } => {
cairo::Gradient::clone(&cairo::LinearGradient::new(x1, y1, x2, y2))
@@ -1123,26 +1126,24 @@ impl DrawingCtx {
height: i32,
acquired_nodes: &mut AcquiredNodes<'_>,
paint_source: &UserSpacePaintSource,
- ) -> Result<SharedImageSurface, cairo::Error> {
+ ) -> Result<SharedImageSurface, RenderingError> {
let mut surface = ExclusiveImageSurface::new(width, height, SurfaceType::SRgb)?;
- surface.draw(&mut |cr| {
+ surface.draw::<RenderingError>(&mut |cr| {
let mut temporary_draw_ctx = self.nested(cr);
// FIXME: we are ignoring any error
- let _ = temporary_draw_ctx
- .set_paint_source(paint_source, acquired_nodes)
- .map(|had_paint_server| {
- if had_paint_server {
- temporary_draw_ctx.cr.paint();
- }
- });
+ let had_paint_server =
+ temporary_draw_ctx.set_paint_source(paint_source, acquired_nodes)?;
+ if had_paint_server {
+ temporary_draw_ctx.cr.paint()?;
+ }
Ok(())
})?;
- surface.share()
+ Ok(surface.share()?)
}
fn stroke(
@@ -1247,7 +1248,12 @@ impl DrawingCtx {
)
}
- fn paint_surface(&mut self, surface: &SharedImageSurface, width: f64, height: f64) -> Result<(),
cairo::Error> {
+ fn paint_surface(
+ &mut self,
+ surface: &SharedImageSurface,
+ width: f64,
+ height: f64,
+ ) -> Result<(), cairo::Error> {
let cr = self.cr.clone();
// We need to set extend appropriately, so can't use cr.set_source_surface().
@@ -1421,7 +1427,7 @@ impl DrawingCtx {
// https://www.w3.org/TR/compositing-1/#isolation
let mut surface = ExclusiveImageSurface::new(width, height, SurfaceType::SRgb)?;
- surface.draw(&mut |cr| {
+ surface.draw::<cairo::Error>(&mut |cr| {
// TODO: apparently DrawingCtx.cr_stack is just a way to store pairs of
// (surface, transform). Can we turn it into a DrawingCtx.surface_stack
// instead? See what CSS isolation would like to call that; are the pairs just
diff --git a/src/filters/context.rs b/src/filters/context.rs
index 5e778bb9..40cfdffa 100644
--- a/src/filters/context.rs
+++ b/src/filters/context.rs
@@ -204,14 +204,12 @@ impl FilterContext {
draw_ctx: &mut DrawingCtx,
) -> Result<SharedImageSurface, FilterError> {
let res = self.stroke_paint_surface.get_or_init(|| {
- draw_ctx
- .get_paint_source_surface(
- self.source_surface.width(),
- self.source_surface.height(),
- acquired_nodes,
- &self.stroke_paint,
- )
- .map_err(FilterError::CairoError)
+ Ok(draw_ctx.get_paint_source_surface(
+ self.source_surface.width(),
+ self.source_surface.height(),
+ acquired_nodes,
+ &self.stroke_paint,
+ )?)
});
res.as_ref().map(|s| s.clone()).map_err(|e| e.clone())
@@ -226,14 +224,12 @@ impl FilterContext {
draw_ctx: &mut DrawingCtx,
) -> Result<SharedImageSurface, FilterError> {
let res = self.fill_paint_surface.get_or_init(|| {
- draw_ctx
- .get_paint_source_surface(
- self.source_surface.width(),
- self.source_surface.height(),
- acquired_nodes,
- &self.fill_paint,
- )
- .map_err(FilterError::CairoError)
+ Ok(draw_ctx.get_paint_source_surface(
+ self.source_surface.width(),
+ self.source_surface.height(),
+ acquired_nodes,
+ &self.fill_paint,
+ )?)
});
res.as_ref().map(|s| s.clone()).map_err(|e| e.clone())
diff --git a/src/filters/displacement_map.rs b/src/filters/displacement_map.rs
index 0e51a945..b7aaf865 100644
--- a/src/filters/displacement_map.rs
+++ b/src/filters/displacement_map.rs
@@ -115,7 +115,7 @@ impl DisplacementMap {
input_1.surface().surface_type(),
)?;
- surface.draw(&mut |cr| {
+ surface.draw::<cairo::Error>(&mut |cr| {
for (x, y, displacement_pixel) in Pixels::within(&displacement_surface, bounds) {
let get_value = |channel| match channel {
ColorChannel::R => displacement_pixel.r,
diff --git a/src/surface_utils/shared_surface.rs b/src/surface_utils/shared_surface.rs
index abe91a27..1fec4f74 100644
--- a/src/surface_utils/shared_surface.rs
+++ b/src/surface_utils/shared_surface.rs
@@ -388,7 +388,12 @@ impl ImageSurface<Shared> {
/// Calls `set_source_surface()` on the given Cairo context.
#[inline]
- pub fn set_as_source_surface(&self, cr: &cairo::Context, x: f64, y: f64) -> Result<(), cairo::Error> {
+ pub fn set_as_source_surface(
+ &self,
+ cr: &cairo::Context,
+ x: f64,
+ y: f64,
+ ) -> Result<(), cairo::Error> {
cr.set_source_surface(&self.surface, x, y)
}
@@ -1345,10 +1350,10 @@ impl ImageSurface<Exclusive> {
/// Draw on the surface using cairo
#[inline]
- pub fn draw(
+ pub fn draw<E: From<cairo::Error>>(
&mut self,
- draw_fn: &mut dyn FnMut(cairo::Context) -> Result<(), cairo::Error>,
- ) -> Result<(), cairo::Error> {
+ draw_fn: &mut dyn FnMut(cairo::Context) -> Result<(), E>,
+ ) -> Result<(), E> {
let cr = cairo::Context::new(&self.surface)?;
draw_fn(cr)
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]