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

Chris Wilson chris at chris-wilson.co.uk
Wed Oct 10 05:24:53 PDT 2012


On Wed, 10 Oct 2012 15:08:01 +0300, Christos Sotiriou <csotiriou at gmail.com> wrote:
> Chris, thanks for you reply. I clearly understand now the distinction
> between images and X Drawables.
> 
> So, to summarise, could you please confirm that my following GTK/Cairo
> interface functions correctly and always use the XServer:
> 
> 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.
-Chris

-- 
Chris Wilson, Intel Open Source Technology Centre


More information about the cairo mailing list