[cairo] [cairo-commit] 6 commits - src/cairo-clip.c src/cairo-clip-private.h src/cairoint.h src/cairo-scaled-font.c src/cairo-surface.c src/cairo-xlib-screen.c src/cairo-xlib-surface.c src/cairo-xlib-surface-private.h test/big-line.c test/big-line.ps.argb32.ref.png test/big-line.ps.rgb24.ref.png test/big-line.quartz.ref.png test/big-line.quartz.rgb24.ref.png test/big-line.ref.png test/big-line.xlib-fallback.ref.png test/big-line.xlib.ref.png test/Makefile.am

Behdad Esfahbod behdad at behdad.org
Fri Sep 11 12:34:53 PDT 2009


On 09/11/2009 10:05 AM, Chris Wilson wrote:
> commit 6960162c5eae30e2d48992023be35e3dbf502a03
> Author: Chris Wilson<chris at chris-wilson.co.uk>
> Date:   Fri Sep 11 14:56:17 2009 +0100
>
>      [xlib] Discard clip if larger than glyph extents
>
>      Implement cheap calculation of glyph extents to see whether we can discard
>      the clip region. This is effective around 50% of the time for firefox (and
>      makes the xtrace so much neater).

See _cairo_gstate_transform_glyphs_to_backend().  We already drop all glyphs 
out of the clip boundaries.  So maybe these two optimizations can be merged. 
Also, see the comment there.  Your glyph_approximate_extents() may be too laxed.

behdad



> diff --git a/src/cairo-scaled-font.c b/src/cairo-scaled-font.c
> index 74a2c88..199ad39 100644
> --- a/src/cairo-scaled-font.c
> +++ b/src/cairo-scaled-font.c
> @@ -2021,6 +2021,42 @@ _cairo_scaled_font_glyph_device_extents (cairo_scaled_font_t	 *scaled_font,
>       return CAIRO_STATUS_SUCCESS;
>   }
>
> +void
> +_cairo_scaled_font_glyph_approximate_extents (cairo_scaled_font_t	 *scaled_font,
> +					      const cairo_glyph_t	 *glyphs,
> +					      int                      num_glyphs,
> +					      cairo_rectangle_int_t   *extents)
> +{
> +    double x0 = HUGE_VAL, x1 = -HUGE_VAL;
> +    double y0 = HUGE_VAL, y1 = -HUGE_VAL;
> +    int i;
> +
> +    for (i = 0; i<  num_glyphs; i++) {
> +	double g;
> +
> +	g = glyphs[i].x;
> +	if (g<  x0) x0 = g;
> +	if (g>  x1) x1 = g;
> +
> +	g = glyphs[i].y;
> +	if (g<  y0) y0 = g;
> +	if (g>  y1) y1 = g;
> +    }
> +
> +    if (x0<= x1&&  y0<= y1) {
> +	extents->x = floor (x0 - scaled_font->extents.max_x_advance);
> +	extents->width = ceil (x1 + scaled_font->extents.max_x_advance);
> +	extents->width -= extents->x;
> +
> +	extents->y = floor (y0 - scaled_font->extents.ascent);
> +	extents->height = ceil (y1 + scaled_font->extents.descent);
> +	extents->height -= extents->y;
> +    } else {
> +	extents->x = extents->y = 0;
> +	extents->width = extents->height = 0;
> +    }
> +}
> +
>   cairo_status_t
>   _cairo_scaled_font_show_glyphs (cairo_scaled_font_t	*scaled_font,
>   				cairo_operator_t	 op,


More information about the cairo mailing list