[cairo] Speeding up redrawing of (image) surfaces

Roman Kantor rkantor at tcd.ie
Thu Jun 28 03:23:55 PDT 2007


the drawing of the (compatible) surface by setting a surface as a source 
and using cairo_paint() is much faster when the transformation matrix 
(CMT) is an identity (apart from translation). For that reason I am 
speeding up  sub-sequent redrawing by performing a caching:

1 )Building a cache (once for many redraws)
- creating a cache surface using cairo_surface_create_similar();
- painting the image surface to the cache with matrix corresponding to 
the CTM (apart from translation) when image should be redrawn

and when redrawing image, i check first if the CMT did not change from 
last time (if so I am rebuilding it)

2) Redrawing
- saving the state(cairo_save())
- resetting the CMT to identity using cairo_identity_matrix()
- painting the cache at proper position
- restoring the state(cairo_restore())

This works great and the speedup in my situation is more than 40x when 
image is just scaled, but there is no speed improvement if some rotation 
is involved.
No additional clipping is involved (which of course could affect the 
speed) in my code.

Anybody got any idea why it is so? During the redraw in both situations 
the CMT is reset to identity (apart from translation) so it should not 
matter that some rotation was involved before redraw(), but it does. Any 

Thanks, Roman

More information about the cairo mailing list