[cairo] Scrolling/Panning Demo -- howto increase speed
Maarten Bosmans
mkbosmans at gmail.com
Mon Dec 13 02:45:57 PST 2010
2010/12/11 Peter Groves <pdgroves at gmail.com>:
> On Sat, 11 Dec 2010 17:20:33 +0100
> Stefan Salewski <mail at ssalewski.de> wrote:
>> Is there an not too complicated way to increase performance?
>> Maybe copying part of the picture contents and redrawing only the
>> changed area? (First I intended to always draw to a large buffer area
>> and to copy only the visible zoomed in rectangle to the GTK drawing
>> area. That would make panning really fast, but may introduce overhead
>> for other operations.)
>
> I have recently spent some time implementing custom scrolling with
> cairo (and not using gtk's), and I found drawing to a large buffer
> and then copying the visible portion not to work very well. It seems
> (and I could be misinterpreting what I observed) that even an offscreen
> very large cairo image surface is very slow to manipulate or copy from.
> It seems very large single images need to be avoided even if they are
> offscreen.
This can possibly be made to perform better by using tiled images. So
instead of drawing to one big image surface, you construct several
tiled images. Then you only need to draw on screen the tiles that are
visible. The main benefit of this approach is that the memory acces to
the prerendered image is much more localized.
I'd say that the tile size needs to be around your viewport size, but
may be others have some suggestions based on their experience.
Maarten
More information about the cairo
mailing list