[cairo] Repeatedly drawing the same object

Adam Richard adam.richard at caris.com
Wed Jun 24 09:25:13 PDT 2009


Hi,

I'm wondering what's the best way to draw a fixed shape many times at 
several different locations on the surface.  I don't want a repeated 
pattern filling up an area, as the CAIRO_EXTEND_REPEAT option allows; 
rather, I want to create a "stamp" which I can then use to draw the same 
image many times at various different positions, so that each "stamp" is 
as fast as possible.

The only approach I've been able to get working is to first create a 
temporary surface and context, draw one copy of the object on that, and 
then do something like:

for each location (x, y)
    set_source_surface(tmpSurface, x, y)
    paint()

But I fear this may be slow, because it's setting a new source each time 
through the loop.  Is there a better way?

I notice in the tutorial, where it discusses selecting a source:

http://cairographics.org/tutorial/#L2preparesource

there's a mention of using a surface as a source using 
cairo_push_group() and cairo_pop_group(), and it says you can save a 
source and then select it repeatedly with cairo_set_source.  So maybe 
that's the fastest way to do it?  I've tried setting the source once and 
then moving its position with translate() on each iteration, but that 
didn't seem to work.



More information about the cairo mailing list