[cairo] drawing on and reusing an off-screen image surface

Carl Worth cworth at cworth.org
Mon Dec 3 14:05:15 PST 2007


On Mon, 3 Dec 2007 14:35:10 -0600, Peter Groves wrote:
> It's getting clearer. Somewhere I got it in my head that any time a cairo
> operation told gtk to display a surface, it would require the whole rasterized
> surface to be copied.

You probably did get an incorrect idea in your head, yes. But there's
never any time that cairo tells GTK+ anything, so I'm not sure exactly
what the incorrect idea was. ;-) But no matter.

> Why is the surface from surface_create_similar more efficient than
> an image surface?

The short answer is that that's exactly what create_similar is
designed for. By definition it returns a new surface of the most
efficient type for drawing back to the given surface. It might return
an image surface if there's nothing better it can do, but it shouldn't
ever give you anything that performs worse.

> Why would it matter when it's being used as an
> intermediate small image to be copied onto the image that will
> actually be displayed? Is it because translations between types of
> pixel representations won't be needed?

An image surface is a buffer of memory that your application can touch
directly, (it's basically just an array of pixels). A "similar"
surface will be of the best possible surface type for an intermediate
surface to be used with the given surface.

So, if you're using X, then gdk_cairo_create will return a cairo_t*
targeting an xlib surface, and cairo_surface_create_similar will also
return an xlib surface. When you draw to this surface, the contents
will be stored within the X server, (and might actually be stored
within video memory on your graphics device). So drawing from this
intermediate surface to the original surface, will generally perform
much better than drawing from an image surface.

Make sense?

-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/94aed461/attachment.pgp 


More information about the cairo mailing list