[cairo] Cairo double buffer example

cu cairouser at yahoo.com
Sat Mar 14 16:14:16 PDT 2009

Depending on a system, another approach is to always draw into image
surface and then move image data to whatever screen API you may have.
That usually does involve at least one "direct copy" function (from
cairo image surface to whatever bitmap format is native to the system).

However, our application achieves somewhat high frame rates doing just
that (tested with the same cairo image repeatedly copied, frame rate
including drawing depends of course on complexity of drawing).

The easiest way to copy is to get access to raw surface image data and
copy directly into bitmap memory, if your system so permits (as an
example, you can do that with native Windows API or wxWidgets).


Carl Worth wrote:
> On Fri, 2009-03-13 at 17:33 +0100, David Björkevik wrote:
>> Not an example, but an outline and some pointers:
>> 1. Create a cairo image surface using cairo_image_surface_create
>> 2. Create a cairo context using cairo_create(surface)
>> 3. Do drawing to your new context
>> 4. Destroy the context
>> 5. Using your original (screen) context, use
>> cairo_set_source_surface(context,surface,0,0)
>> 6. Use cairo_paint(contxt) to transfer the thing
>> 7. cairo_surface_destroy(surface)
> That's a good outline, but one improvement would be to create a similar
> surface rather than an image surface.
>> For newer cairo you can also use cairo_push_group and
>> cairo_pop_group_to_source.
> And yes, this does make it much easier to follow your recipe, (and does
> create a similar surface rather than always creating an image surface).
> -Carl

More information about the cairo mailing list