[cairo] Cairo + Python + OpenGL = Unacceptable performance?

Clemens Nylandsted Klokmose clemensklokmose at gmail.com
Thu Oct 11 04:41:59 PDT 2007

Hello,I have been fiddling some time with implementing a prototype for a
research project in Cairo in combination with Python and OpenGL.
I have finally got it running, but the performance is very poor.
I have a (changing) XML structure (in elementtree) that I need
re-rendered continuously.

I have a thread creating a new cairo image all the time, looking something
like below, where Tree is the structure I draw and ViewManger.draw() does
the drawing.

def redraw():
    global Tree
    global surface
    global surfacedata
    global writing_texture

    while 1:
        surface1 = cairo.ImageSurface(cairo.FORMAT_ARGB32,
        ctx = cairo.Context(surface1)
        ctx.set_source_rgba(0, 0, 0, 1)

        ViewManager.draw (Tree.getroot(), ctx)

        surface = ctx.get_target()
        surfacedata = str(surface.get_data())


I then in my OpenGL draw function have the texture generation:

glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB8, int( surface.get_width()), int(
surface.get_height()), 0, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, surfacedata)

The overall problem is that the operation str(surface.get.data ()) takes
something around 300ms on my computer (Powerbook 1.67ghz), but it seems I
have to do this conversion in order to get glTexImage2D to eat the data. If
I just feed it with surface.get_data() (which would be the pointer to the
data, and the most natural way to do it) I get a segmentation fault.

Are there anyone who have tried to do something similar, and have found a
way to get around converting the data in memory to a string?

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.cairographics.org/archives/cairo/attachments/20071011/4aae3acd/attachment.html 

More information about the cairo mailing list