Monthly Archives: April 2007

Cairo slowness

I've been playing around with Cairo lately, and have hit a problem with drawing a repeated bitmap background onto a GtkDrawingArea (i.e. a GdkDrawable).

I've got some code which will do this, but it's slow to the point of being able to see each individual repetition of the bitmap being drawn. The bitmap I'm using isn't particularly big or complex (although I can't see what effect that should have), and there's not much I can remove from the code, so it's got to either be an X server setup problem, or a fundamental flaw with my approach. I favour the latter, since other Cairo applications draw blindingly fast on my machine.

cairo_t *cr;
cairo_surface_t *background_surface;
cairo_pattern_t *background_pattern;

background_surface = cairo_image_surface_create_from_png ("image.png");
background_pattern = cairo_pattern_create_for_surface (background_surface);
cairo_pattern_set_extend (background_pattern, CAIRO_EXTEND_REPEAT);

cr = gdk_cairo_create (GDK_DRAWABLE (my_gtk_drawing_area->window));

cairo_save (cr);
cairo_set_source (cr, background_pattern);
cairo_paint (cr);
cairo_restore (cr);

cairo_destroy (cr);
cairo_surface_destroy (background_surface);
cairo_pattern_destroy (background_pattern);

If anybody's got any idea what's wrong with this, I'd be grateful to know. :)

In other news, I apologise for my exceedingly prolonged absence from my own site. I couldn't think of anything to write about, and real life got in the way. :(