[cairo] Best strategy for complex screen drawing
timothee.lecomte at ens.fr
Fri Nov 25 09:07:11 PST 2005
Vladimir Vukicevic wrote:
>On 11/21/05, Timothée Lecomte <timothee.lecomte at ens.fr> wrote:
>>Under X11 via gdk, I draw offscreen to a GdkPixmap thanks to
>>Then, I copy this pixmap to the screen with gdk_draw_drawable() when I
>>receive a "window-must-be-painted" event.
>>With such code, the initial drawing takes approximately 0.2 milliseconds
>>per polygon (pretty slow), and the copy to the screen is almost satisfying.
>That's pretty much what you should be doing; some future toolkits may
>allow you to directly draw into the back buffer of a widget and have
>the update happen automatically.(...)
> - Vlad
I have reviewed my code to see if there wasn't any bottleneck which
would not imply cairo, and ... I must conclude that cairo is slow even
with this implementation.
I have tried to compare the time needed to draw on a generic image
surface (cairo_image_surface_create_for_data), and on a GtkPixmap
surface obtained via gtk gdk_pixmap_new and gtk_cairo_create.
Here is a screenshot of what I am drawing :
The drawing is made of a few lines and pango text layouts, and 10000
4-corners polygons. Each polygon is drawn thanks to the following code :
/* eventually disabling anti-aliasing for testing purpose */
// cairo_set_antialias( cr, CAIRO_ANTIALIAS_NONE );
cairo_move_to(cr, device_x(corners.x), device_y(corners.y));
for (int i=1;i<n;i++)
cairo_line_to(cr, device_x(corners[i].x), device_y(corners[i].y));
wxt_cairo_fill( fillstyle, fillpar ); /*set color depending on args*/
The results are surprising :
"Generic" image surface :
* antialiasing enabled for the polygons = 1470 ms, or 0.15 ms per polygon
* antialiasing disabled for the polygons = 1200 ms, or 0.12 ms per polygon
GtkPixmap surface :
* antialiasing enabled for the polygons = 2200 ms, or 0.22 ms per polygon
* antialiasing disabled for the polygons = 1500 ms, or 0.15 ms per polygon
Yes, you've well read, the image surface is way more efficient !
I have verified in gtk sources to see if cairo_xlib_surface_create was
used, and yes, it's the case. So image surface are more efficient than
xlib ones !
Am I forgetting something ?
More information about the cairo