[cairo] Pycairo and ImageSurface

Carl Worth cworth at cworth.org
Tue Feb 20 15:41:25 PST 2007


On Tue, 20 Feb 2007 16:03:05 -0600, "Glenn Murphy" wrote:
> When I added the rotation is when I first hit this problem. I was rendering
> everything on each refresh, so the application was sucking up a lot of CPU
> time. I changed it to draw everything to a ImageSurface the one time and
> then paint that to the screen when the expose-event was signaled. Whenever
> the expose-event signal is received, all it does is create a cairo context
> (using gtk.gdk.Window.cairo_create()), translate to the center, rotate 1
> degree and paints the ImageSurface. However, after doing all that, it still
> sucks up a lot of CPU time from redrawing the DrawingArea all the time.
> expose-event is getting signaled a lot (about 30 times a second) and each
> time it has to redraw the entire DrawingArea.

If you're painting an image surface every time, then you will be
transferring all of the image data from your application to the X
server every time.

So, better would be to have your intermediate surface as an xlib
surface, (or whatever surface type your destination is). You can
create one of those with cairo_surface_create_similar. Given a
cairo_t* cr from gdk_cairo_create that would be something like:

surface = cairo_surface_create_similar (cairo_get_target (cr),
					CAIRO_CONTENT_COLOR[_ALPHA],
					width, height);

Hopefully it's obvious to you how to translate that from C to python.

Now, if that's _still_ too slow, then the next thing to address is
perhaps in the X server itself, (ideally, it would be able to use the
video hardware for the rotation, and not require much CPU at all). So,
it's a question of how good the support is for rotated images in your
server's implementation of the Render extension.

> Another problem I've been having is from rotating the ImageSurface. Whenever
> I rotate it, the image created is moved outside of the clipping region.
> Every 90 degrees, it moves back to the correct position. I haven't been able
> to find anything about this problem. I have three images showing this
> problem:

Are you using a cairo snapshot between 1.3.2 and 1.3.12? That looks an
awful lot like a bug that was fixed in the 1.3.14 snapshot which was
described as follows in the release notes:

	Fix corrupted results when rendering a transformed source image
	surface to an xlib surface. This was a regression that had been
	present since the 1.3.2 snapshot.

	[http://cairographics.org/news/cairo-1.3.14]

I hope that helps. 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.freedesktop.org/archives/cairo/attachments/20070220/881be094/attachment.pgp


More information about the cairo mailing list