[cairo] Painting an image surface into itself in order to scroll it

Uli Schlachter psychon at znc.in
Sun Dec 30 06:54:56 PST 2012


Hi,

On 27.12.2012 09:26, Nicholas Allen wrote:
> If I create an image surface and then try to scroll it by painting it
> into itself then it works as long as I scroll it left, right, or up but
> not if I scroll it down.

Having the same surface as both target and source of a drawing operation in 
cairo is not allowed. This invokes undefined behavior and will not be supported. 
(However, I cannot find a reference for this right now)

So this is not a bug in cairo.

> It seems cairo has a bug that this is not possible with just one image
> surface if you scroll the contents downwards. I can work around it by
> creating 2 image surfaces and copying one to the other but I would
> expect cairo to be able to handle this with just one surface.

If you don't do the copy to an extra surface, cairo would have to do it for you. 
This means that the resulting performance is equally bad. Yes, there could be 
shortcuts for the image backend, but I think most other (raster) backends would 
have to do the extra copy.

So it is a good thing that this does not actually work. This way you notice that 
the results are wrong and can fix it in your code. For example, using two image 
surfaces which are swapped avoids one copy and thus saves time in a way that 
cairo wouldn't be able to do by itself.

Cheers,
Uli


More information about the cairo mailing list