[librsvg: 1/9] filters::render() - handle errors in a single place
- From: Federico Mena Quintero <federico src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [librsvg: 1/9] filters::render() - handle errors in a single place
- Date: Tue, 27 Apr 2021 17:54:45 +0000 (UTC)
commit 5745137523ad6e0743fc20bc8f27cb9c64b8222e
Author: Federico Mena Quintero <federico gnome org>
Date: Mon Apr 19 12:48:43 2021 -0500
filters::render() - handle errors in a single place
src/filters/mod.rs | 123 ++++++++++++++++++++++++++---------------------------
1 file changed, 60 insertions(+), 63 deletions(-)
---
diff --git a/src/filters/mod.rs b/src/filters/mod.rs
index a8d2b0f3..ed2961aa 100644
--- a/src/filters/mod.rs
+++ b/src/filters/mod.rs
@@ -324,74 +324,71 @@ pub fn render(
transform: Transform,
node_bbox: BoundingBox,
) -> Result<SharedImageSurface, RenderingError> {
- let filter = match extract_filter_from_filter_node(filter_node, draw_ctx) {
- Err(FilterError::CairoError(status)) => {
- // Exit early on Cairo errors
- return Err(RenderingError::from(status));
- }
-
- Err(_) => {
- // ignore other filter errors and just return an empty surface
- return Ok(SharedImageSurface::empty(
- source_surface.width(),
- source_surface.height(),
- SurfaceType::AlphaOnly,
- )?);
- }
-
- Ok(f) => f,
- };
-
- if let Ok(mut filter_ctx) = FilterContext::new(
- &filter.user_space_filter,
- stroke_paint_source,
- fill_paint_source,
- &source_surface,
- transform,
- node_bbox,
- ) {
- for user_space_primitive in &filter.primitives {
- let start = Instant::now();
-
- match render_primitive(&user_space_primitive, &filter_ctx, acquired_nodes, draw_ctx) {
- Ok(output) => {
- let elapsed = start.elapsed();
- rsvg_log!(
- "(rendered filter primitive {} in\n {} seconds)",
- user_space_primitive.params.name(),
- elapsed.as_secs() as f64 + f64::from(elapsed.subsec_nanos()) / 1e9
- );
-
- filter_ctx.store_result(FilterResult {
- name: user_space_primitive.result.clone(),
- output,
- });
- }
-
- Err(err) => {
- rsvg_log!(
- "(filter primitive {} returned an error: {})",
- user_space_primitive.params.name(),
- err
- );
+ extract_filter_from_filter_node(filter_node, draw_ctx)
+ .and_then(|filter| {
+ let filter_ctx = FilterContext::new(
+ &filter.user_space_filter,
+ stroke_paint_source,
+ fill_paint_source,
+ &source_surface,
+ transform,
+ node_bbox,
+ )?;
+
+ Ok((filter, filter_ctx))
+ })
+ .and_then(|(filter, mut filter_ctx)| {
+ for user_space_primitive in &filter.primitives {
+ let start = Instant::now();
+
+ match render_primitive(&user_space_primitive, &filter_ctx, acquired_nodes, draw_ctx)
+ {
+ Ok(output) => {
+ let elapsed = start.elapsed();
+ rsvg_log!(
+ "(rendered filter primitive {} in\n {} seconds)",
+ user_space_primitive.params.name(),
+ elapsed.as_secs() as f64 + f64::from(elapsed.subsec_nanos()) / 1e9
+ );
+
+ filter_ctx.store_result(FilterResult {
+ name: user_space_primitive.result.clone(),
+ output,
+ });
+ }
- // Exit early on Cairo errors. Continue rendering otherwise.
- if let FilterError::CairoError(status) = err {
- return Err(RenderingError::from(status));
+ Err(err) => {
+ rsvg_log!(
+ "(filter primitive {} returned an error: {})",
+ user_space_primitive.params.name(),
+ err
+ );
+
+ // Exit early on Cairo errors. Continue rendering otherwise.
+ if let FilterError::CairoError(status) = err {
+ return Err(FilterError::CairoError(status));
+ }
}
}
}
- }
- Ok(filter_ctx.into_output()?)
- } else {
- // Ignore errors that happened when creating the FilterContext
- Ok(SharedImageSurface::empty(
- source_surface.width(),
- source_surface.height(),
- SurfaceType::AlphaOnly,
- )?)
- }
+ Ok(filter_ctx.into_output()?)
+ })
+ .or_else(|err| match err {
+ FilterError::CairoError(status) => {
+ // Exit early on Cairo errors
+ Err(RenderingError::from(status))
+ }
+
+ _ => {
+ // ignore other filter errors and just return an empty surface
+ Ok(SharedImageSurface::empty(
+ source_surface.width(),
+ source_surface.height(),
+ SurfaceType::AlphaOnly,
+ )?)
+ }
+ })
}
#[rustfmt::skip]
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]