[cairo] Optimizing the fetching calls

Antoine Azar cairo at antoineazar.com
Mon Apr 28 12:46:42 PDT 2008


Hey Soeren,

> I think it may be worthwhile trying to get the fetch code 
> inline again. Ie., along the lines of:
> 
>    http://www.daimi.au.dk/~sandmann/faster-transform.patch
> 
> It's untested and the same things needs to be done in more 
> places, but the idea should be clear.
> 
> The idea of reusing the last sample if the coordinates are 
> the same is not a bad one, but I'd like to first see what, if 
> any, effect inlining has.

I tested your proposed modification, I'm getting around a 15% speed boost.
It's a good idea and I could work on applying it in all the other places and
building a patch out of it.
In any case I think it's independent of my previous optimization, so if you
don't have any objections to it, please go ahead and push it. We can add
your optimization on top of it later.

> Also, if you could attach your test application that would be helpful.

For testing my optimization, I used a slightly modified version of the paint
perf test (forcing the extend and filtering modes). I also built a small pet
application to check the visual results of the optim, and running Vtune on
it. The code is following (some unused variables, you can ignore them).

Thanks,
Antoine


#define LIBCAIRO_EXPORTS

#include <cairo.h>
#include <cairo-win32.h>

#define SIZE 900

int
main (int argc, char *argv[])
{
     cairo_surface_t *surface, *surface_small, *mask;
    cairo_t *cr, *cr_small, *cr_mask;
    cairo_pattern_t *radpat;
    int i=0;
    double scaleFactor = 1.0;
    
    surface_small = cairo_image_surface_create_from_png ("f:\\0-kanon.png");
    surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, SIZE, SIZE);
    cr = cairo_create (surface);
    cr_small = cairo_create(surface_small);
    
    cairo_set_source_rgba (cr, 1.0, 0.0, 0.0, 1.0);
    cairo_rectangle (cr, 0, 0, SIZE, SIZE);
    cairo_fill (cr);

    cairo_set_operator(cr, CAIRO_OPERATOR_OVER);

    cairo_translate (cr, SIZE/4.0, SIZE/4.0);
    cairo_scale(cr, 3.0, 3.0);
    cairo_set_source_surface (cr, surface_small, 0, 0);

    cairo_pattern_set_filter(cairo_get_source(cr), CAIRO_FILTER_BILINEAR);
    cairo_pattern_set_extend (cairo_get_source(cr), CAIRO_EXTEND_NONE);
        
    cairo_paint (cr);
    
    scaleFactor=0.9;
    for(i=0; i<10; i++)
    {
        cairo_scale(cr, scaleFactor, scaleFactor);
        cairo_rotate(cr, 10.0*3.141/180.0);
        cairo_set_source_surface (cr, surface_small, 0, 0);
        cairo_pattern_set_filter(cairo_get_source(cr),
CAIRO_FILTER_BILINEAR);
        cairo_pattern_set_extend (cairo_get_source(cr), CAIRO_EXTEND_NONE);
        cairo_paint (cr);
    }

    cairo_surface_write_to_png (surface, "scaled.png");

    cairo_destroy (cr_small);
    cairo_surface_destroy (surface_small);

    cairo_destroy (cr);
    cairo_surface_destroy (surface);

    return 0;
}
 




More information about the cairo mailing list