[librsvg] cairo: reduce cost of measuring bounding boxes



commit eaaa3212b987748b6d5e9e1630a64d691292b8f0
Author: Ãyvind KolÃs <pippin gimp org>
Date:   Mon Sep 5 22:33:37 2011 +0100

    cairo: reduce cost of measuring bounding boxes
    
    Measuring the size of the stroke and fill bounding boxes is _very_ expensive
    (the flattened path is tesselated) when rendering zoomed in SVGs, this due to
    cairo subdividing until the tolerance value of cairo is met. This commit
    momentarily drops that precision to a precision of 1px during bounding box
    measurements.
    
    If these computations could be avoided, using the bounds of the path would be
    desirable. Some optimizations to further reduce edge case costs in cairo are to
    be expected.

 rsvg-cairo-draw.c |    9 +++++++++
 1 files changed, 9 insertions(+), 0 deletions(-)
---
diff --git a/rsvg-cairo-draw.c b/rsvg-cairo-draw.c
index 0f237eb..0b74e22 100644
--- a/rsvg-cairo-draw.c
+++ b/rsvg-cairo-draw.c
@@ -536,6 +536,7 @@ rsvg_cairo_render_path (RsvgDrawingCtx * ctx, const RsvgBpathDef * bpath_def)
     int i;
     int need_tmpbuf = 0;
     RsvgBbox bbox;
+    double backup_tolerance;
 
     if (state->fill == NULL && state->stroke == NULL)
         return;
@@ -583,6 +584,12 @@ rsvg_cairo_render_path (RsvgDrawingCtx * ctx, const RsvgBpathDef * bpath_def)
 
     rsvg_bbox_init (&bbox, state->affine);
 
+    backup_tolerance = cairo_get_tolerance (cr);
+    cairo_set_tolerance (cr, 1.0);
+    /* dropping the precision of cairo's bezier subdivision, yielding 2x
+       _rendering_ time speedups, are these rather expensive operations
+       really needed here? */
+
     if (state->fill != NULL) {
         RsvgBbox fb;
         rsvg_bbox_init (&fb, state->affine);
@@ -602,6 +609,8 @@ rsvg_cairo_render_path (RsvgDrawingCtx * ctx, const RsvgBpathDef * bpath_def)
         rsvg_bbox_insert (&bbox, &sb);
     }
 
+    cairo_set_tolerance (cr, backup_tolerance);
+
     rsvg_bbox_insert (&render->bbox, &bbox);
 
     if (state->fill != NULL) {



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]