[cairo] drawing on and reusing an off-screen image surface
Carl Worth
cworth at cworth.org
Mon Dec 3 09:00:37 PST 2007
On Mon, 3 Dec 2007 01:31:52 -0600, Peter Groves wrote:
> I'm new to cairo (and gtk for that matter), and am having some trouble
> understanding how to draw on and re-use an image buffer in a custom gtk
> widget. Generally, what my widget will do is create a complex cairo
> drawing, rasterize it in some kind of image buffer, and then reuse the
> rasterized image buffer as a background while some simple foreground
> drawings are made in response to mouse movements. The widget will
> therefore be repainted very quickly as the mouse moves across it, and
> I don't want to repaint the background from scratch each time.
Hi Peter,
Welcome to cairo development. We hope you have a lot of fun using
cairo, and we're glad you felt comfortable coming here to ask
questions.
The one comment I'll share is that for "some kind of image buffer" you
might not want a cairo "image surface". For example, if you are using
a cairo with an X server, then every time you cairo_paint with an
image-surface pattern, cairo will have to upload the image from your X
client to the X server.
Instead, you can use a "similar surface", which in the case of X will
give you server-side storage so the cairo_paint operation can be much
faster. This should be as simple as doing cairo_surface_create_similar
instead of cairo_image_surface_create.
The only trick will be that you will have to get some surface to your
startup() function to let cairo_surface_create_similar know what kind
of surface to create. GTK+ hides the target surface from you just a
little bit, but you can get at it easily enough by calling
cairo_get_target after gdk_cairo_create.
Anyway, if none of the above made any sense, then don't worry about it
for now, and just get your application later. But keep this in mind as
an optimization you can make later at least.
Again, welcome, and 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.cairographics.org/archives/cairo/attachments/20071203/d4c5ae7e/attachment.pgp
More information about the cairo
mailing list