[cairo] performance difference between image and win32 surface?

Danilo Gulamhussene danilo at impara.de
Fri Oct 19 02:33:21 PDT 2007


Vladimir Vukicevic schrieb:
> Hi Danilo,
>
> Danilo Gulamhussene wrote:
>> Hi,
>>
>> i have experimented a little with Cairo, cause we plan to use it for 
>> rendering in a larger project.
>> Some performance tests stated, that using a Win32 Surface is about 5 
>> times slower than using an Image Surface on my system (Windows XP).
>> (I wrote the small tests on my own, cause I did not manage yet to 
>> build the performance tests included in Cairo.)
>>
>> Could these results be correct, or am I doing something wrong?
>> When yes, what is the reason for this performance difference? I would 
>> find it much more straight forward to render directly into a Win32 
>> Surface instead of rendering in an Image Surface and then copying it 
>> into the window.
>
> Could you give some examples of the kinds of operations that you're 
> finding slower?
>
>     - Vlad
I tested basic drawing including text on a surface with size 400x400:

void draw (cairo_t *cr){
    //arc
    cairo_arc (cr, 200.0, 200.0, 200.0, 0.0, 3.62);
    cairo_set_source_rgb (cr, 1.0, 1.0, 0.0);
    cairo_fill (cr);
    cairo_arc (cr, 200.0, 200.0, 200.0, 0.0, 3.62);
    cairo_set_source_rgb (cr, 0.0, 1.0, 0.0);
    cairo_stroke (cr);
    //text
    cairo_select_font_face (cr, "serif", CAIRO_FONT_SLANT_NORMAL, 
CAIRO_FONT_WEIGHT_BOLD);
    cairo_set_font_size (cr, 32.0);
    cairo_set_source_rgb (cr, 0.0, 0.0, 1.0);
    cairo_move_to (cr, 10.0, 50.0);
    cairo_show_text (cr, "Hello, world");
}

iterated 1000 times.
Creating the surface and cairo context was not part of the loop.

Owens advise to use cairo_push_group() on win32 surface fixed the 
performance difference for this test completely.

The costs of cairo_push_group(), which implicitly creates a new surface 
(as far as I understood), on what do they depend? Do they depend on the 
size of the original surface, the current clip region, or the space used 
by the objects, i draw inside the group?

By the way, we plan to use Cairo for the rendering part of a new 
UI-Framework implemented in Squeak(Smalltalk).

- Danilo


More information about the cairo mailing list