[cairo] Using pre-existing textures

Carl Worth cworth at cworth.org
Fri Feb 8 07:58:54 PST 2008

On Fri, 8 Feb 2008 08:35:20 -0600, "Matt Hoosier" wrote:
> A small point about which I've never been sure: the normal idiom that
> one seems in example Gtk code which draws using Cairo, is
> gboolean
> expose_event (GtkWidget *w, GdkEventExpose *event)
>   {
>     cairo_t *cr = gdk_cairo_create (...);
>     /* draw */
>     cairo_destroy (cr);
>     ...
>   }

Yes, that's the right idiom.

> But that would require you to toss away any X backend state
> accumulated at the end of the expose handler.

No, not quite.

>                                                Is it legal to keep a
> cairo surface like the intermediate one returned by your function
> above, alive beyond the immediate expose cycle? E.g., is it referring
> to the double-buffered short-lived X pixmaps that back the GdkDrawable
> during expose cycles?

You're correct that the cairo_t* returned by gdk_cairo_create is
referring to a short-lived, double-buffering X pixmap. So, yes, you
cannot hold on to that.

But you can use that during the expose-event handling to create a
pixmap/cairo surface that you can hold on to for longer. So within the
"draw" part of the above you could use something like my
create_intermediate_surface function like so:

	cairo_surface_t *persistent;

	persistent = create_intermediate_surface (cairo_get_target (cr), ...);

And then you should be quite happy.

Make sense?

-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
Url : http://lists.cairographics.org/archives/cairo/attachments/20080208/7bf14367/attachment.pgp 

More information about the cairo mailing list