[cairo] cairo_t usage
Carl Worth
cworth at cworth.org
Sat Nov 11 09:17:23 PST 2006
On Sat, 11 Nov 2006 11:11:21 +0100, Ralf Stephan wrote:
> in an application that paints much pango text, I thought I could
> create a cairo context once and use it throughout the app lifetime.
> (the cairo_t was from Gdk::Drawable::create_cairo_context()).
This is really a GTK-specific issue. Within the expose event for your
drawable, GTK will have created a temporary surface for
double-buffering and create_cairo_context creates a cairo_t targeting
that intermediate surface. Then, after the expose event is finished
GTK copies the results to the actual surface.
> Now I'm getting CAIRO_STATUS_SURFACE_FINISHED errors and I'm not
> sure if I
Which makes sense when you understand the GTK double-buffering stuff
explained above.
> - should create/destroy the cairo_t every time I'm painting on
> the Drawable (e.g., on every expose event) instead of keeping
> the cairo_t indefinitely
For GTK, yes, you should create a new cairo context each time.
> 1. So, what's the recommended lifetime of a cairo_t?
As far as cairo is concerned you can make your cairo_t lifetime as
short or as long as you'd like, (though obviously no longer than their
target surfaces).
The GTK usage, (create a new context on every expose), is obviously
common, so we will always support that well in cairo, (ensure that
create/destroy for cairo_t is not expensive).
> 2. Does a cairo_t created from a Gdk::Drawable need another surface?
> If not, why could there be CAIRO_STATUS_SURFACE_FINISHED errors
> despite the Drawable not having died or been destroyed?
Hopefully that all makes sense now.
> I'll try to enhance the documentation with what I gain from your answers.
Presumably, the documentation needing enhancement here is that of
Gdk::Drawable::create_cairo_context().
Have fun with cairo!
-Carl
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
Url : http://lists.freedesktop.org/archives/cairo/attachments/20061111/03f3b568/attachment.pgp
More information about the cairo
mailing list