[cairo] How to efficiently clear a surface

Carl Worth cworth at east.isi.edu
Mon Aug 16 12:12:16 PDT 2004

On Tue, 3 Aug 2004 21:20:00 +0200 (CEST), =?iso-8859-1?q?Jost=20Boekemeier?= wrote:
> I've tried to re-use surfaces and clear them, but none
> of the methods I've used was faster than simply
> creating a new surface.

We don't have a special fast path in cairo for this yet.

One option would be to notice when the user is filling a path that is
pixel-aligned rectangle and then be sure to use a more accellerated path
for the fill. We already have the rectangle detection code for our fast
clipping path, so this should be easy to hook up.

Another option, (that I don't like as much), is to add a call for
filling a rectangle, separate from the general path-based
cairo_fill. PostScript has such an operator, rectfill, but it always
seemed like a wart in the API to me.

I could be convinced to put warts like that in, but only after we're
sure we can't get near equivalent performance through the cleaner,
general API.

In the meantime, looking through some of the demo code we've got so far,
it looks like I've been doing the initial erase of the surface manually
before handing it to cairo, (eg. with XFillRectangle for a drawable and
with memset for an image buffer). But down the road I plan to make cairo
assume that surface contents are not written to through non-cairo
channels, so we will probably want a fast way to clear the surface
through cairo.


More information about the cairo mailing list