[cairo] GTK+, Cairo, XLib integration for fast 2D graphics drawing

Alexander Larsson alexl at redhat.com
Thu Oct 11 07:38:44 PDT 2012


> > 1. In my expose_event function I do:
> > 
> > maincanvas_drawable = GTK_LAYOUT(maincanvas)->bin_window; //
> > drawable
> > layout window //
> > maincanvas_cs = gdk_cairo_create(maincanvas_drawable); //
> > corresponding
> > cairo state//
> > 
> > to get the Cairo State maincanvas_cs
> > 
> > 2. Next, I draw to maincanvas_cs:
> > 
> > ...
> > cairo_paint(maincanvas_cs);
> > ...
> > 
> > or
> > 
> > 3.  I create a similar surface and draw to that, for
> > double-buffering, like
> > this:
> > 
> > parent_sf = cairo_get_target(maincanvas_cs); // get parent surface
> > //
> > drawbuffer_sf = cairo_surface_create_similar(parent_sf,
> > CAIRO_CONTENT_COLOR_ALPHA, maincanvasWidth, maincanvasHeight);
> > 
> > All of the above exploit the GPU, correct?
> 
> Yes. I just feel a little nervous as GTK+ will also be doing some
> double-buffering magic as well around expose events, so accessing the
> GdkDrawables may be risky. But that looks like the right approach to
> use accelerated rendering in a backend agnostic fashion.

As long as you gdk_cairo_create() inside the expose event and don't keep
the result around over multiple expose events it will work fine. The
surface you will get back will be for the double buffer pixmap.


More information about the cairo mailing list