[cairo] pycairo performance tips

Prashant Saxena animator333 at yahoo.com
Thu Aug 19 20:49:24 PDT 2010


I did a test and file is attached. First I am preparing a cairo svg surface and 
then drawing it on context. Before drawing I have doubled the context scale. It 
seems cached svg surface is no different then image surface. May be I did 
something wrong. Prior to this test I was assuming that svg surface is similar 
to display list of openGL, where instructions are cached and you can draw them 
without worrying about the scale.

Any pointers?


----- Original Message ----
From: Arjen Nienhuis <a.g.nienhuis at gmail.com>
To: Prashant Saxena <animator333 at yahoo.com>
Cc: cairo <cairo at cairographics.org>
Sent: Fri, 20 August, 2010 1:32:07 AM
Subject: Re: [cairo] pycairo performance tips

If you keep the SVG surface alive you can simply paint *from* that surface:

node_foo = SVGSurface(...)

Where ctx is the destination: either the screen or some cache.

Met vriendelijke groet,
Arjen Nienhuis

On Thu, Aug 19, 2010 at 7:47 PM, Prashant Saxena <animator333 at yahoo.com> wrote:
> Hi,
> Overall caching system is working fine and code is profiled. The problem is
> with the nodes that I am drawing on canvas. The draw function is complex and
> using couple of 'if-else' conditions.
> I am planning to use svg surface instead of image surface. In current
> implementation once node is drawn it's cached as image. When you zoom-in or
> zoom-out, node is drawn again and cached. You have to do it otherwise node
> will appear as blurry image. Instead of image surface
> you can create a svg surface and do the drawing, while zooming-in-out, you
> don't have to re-draw again because it's svg surface. Am I right here?
> The example here:
> http://cairographics.org/pyrsvg/
> shows how you can save cairo drawing to an .svg file.
> To render a svg surface you need 'rsvg' which is based on 'librsvg.dll' and
> list of dependencies is really huge, (10-15) extra files.
> Is there any easier method to render svg surface?
> I am using python 2.6.5, cairo-pycairo 1.8.10 and wxpython
> Cheers
> Prashant
> ________________________________
> From: Arjen Nienhuis <a.g.nienhuis at gmail.com>
> To: Prashant Saxena <animator333 at yahoo.com>
> Cc: cairo at cairographics.org
> Sent: Tue, 10 August, 2010 4:36:36 PM
> Subject: Re: [cairo] pycairo performance tips
> Hi,
> Did you use a profiler on your code? What code is responsible for the bad
> performance?
> For panning you can render the whole image (even outside the visible window)
> to an image and render that to the screen at the correct offset.
> For zooming you can scale the cached image while zooming and then render to
> the image again after the zooming is complete.
> For editing you can drag a outline of the node that is selected across the
> screen and render again at mouse-up.
> Groeten, Arjen
> On Tue, Aug 10, 2010 at 10:39 AM, Prashant Saxena <animator333 at yahoo.com>
> wrote:
>> Hi,
>> I am using cairo 1.8.6, wxpython and python 2.6. I have created a
>> custom OO based scene graph framework. I am using this frame work for a
>> visual
>> node based application. A similar screen shot can be found here:
>> From functionality point of view cairo is working great but from
>> performance
>> wise it's slightly lagging. Although I have implemented
>> a custom cache implementation to make it as fast as possible but still I
>> need
>> some tips to improve it.
>> Once a node is drawn it's cached as bitmap and instead of calling entire
>> drawing
>> operations, I am drawing it's bitmap.
>> The main area where I need speed-ups are related to view port navigation:
>> 1. When you select a node and move, you have to repeatedly call the main
>> 'draw'
>> to update the canvas and it's drawing all the nodes.
>> 2. When you zoom-in or zoom-out (scaling DCs), you have to re-cache the
>> node.
>> 3. When you scroll/pan the canvas you have to draw all the nodes for every
>> mouse-move call. This is much slower if you have already zoomed-in.(DC's
>> scale
>> is 5 or greater)
>> Overall, how do you take out most of cairo/pycairo when you are creating a
>> frame-work similar to the screen shot above?
>> Shall I try newer version? (if there are any performance based
>> improvements
>> rather then functionality)
>> Cheers
>> Prashant
>> --
>> cairo mailing list
>> cairo at cairographics.org
>> http://lists.cairographics.org/mailman/listinfo/cairo

-------------- next part --------------
A non-text attachment was scrubbed...
Name: svg_test.py
Type: application/octet-stream
Size: 3221 bytes
Desc: not available
URL: <http://lists.cairographics.org/archives/cairo/attachments/20100820/f745fe5f/attachment.obj>

More information about the cairo mailing list