[cairo] Pycairo and ImageSurface

Glenn Murphy gyrmnix at gmail.com
Tue Feb 20 14:03:05 PST 2007

Hi, this is my first time posting here. I've been working with pygtk and
pycairo on a project for about a month now (just learning both of them).
Everything has been going fine until a week ago.

I have a window with some buttons and a large DrawingArea (approximately
950x768 for the drawing area). I'm using the DrawingArea for all of my
drawing. Basically, inside the DrawingArea, I draw a circle. Around the
circle are rectangles drawn every 10 degrees. Then, I rotate all of that
around the center of the DrawingArea.

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. Looking through all the
examples I can find, the only thing helpful that I've found in this regard
is only redrawing the parts that have changed. But, for what I'm trying to
do, I have to redraw almost the entire area. Is this slowdown from pycairo?
Should I expect this problem if this project were written in C/C++?

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

In that demo, the image is painted using cairo.Context.set_source_surface().
The origin is translated to the center of the window, rotated, translated
back to the top-left, and paints the ImageSource at 0,0. The full source for
this demo I wrote is at

I also put a demo up at that
shows the CPU problem I'm having (the image problem as well).

If anybody can show me what I'm doing wrong or point me in the right
direction, I'd appreciate it.

Glenn Murphy
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.freedesktop.org/archives/cairo/attachments/20070220/c6a46844/attachment.html

More information about the cairo mailing list