[cairo] clipping output

Carl Worth cworth at cworth.org
Fri May 27 08:40:56 PDT 2005


On Fri, 27 May 2005 15:24:17 +0200, Buola Buola wrote:
> is it possible to do pixel-level, non-antialiased clipping with cairo,
> even if it is in a device-dependent way?

We don't have a separate API for it, but the implementation does take
advantage of pixel-based clipping interfaces, (such as X provides), if
your clipping path can be represented as a set of pixel-aligned
rectangles.

> I am using the xlib backend and i want to be able to redraw a certain
> part of a cairo-drawn widget, as for example when responding to an
> expose event. Is it possible to do so?

Yes. If you've got a set of pixel-aligned rectangles, your code to
clip to them might have something like the following structure:

	/* Use identity matrix to create pixel-aligned clip path */
	cairo_save (cr);
	cairo_identity_matrix (cr);
	for (each rectangle r)
	    cairo_rectangle (cr, r->x, r->y, r->width, r->height);
	cairo_restore (cr);

	/* Set the clip for future drawing operations */
	cairo_clip (cr);

The nice thing about this approach within cairo is that we don't have
to specify any non-antialiased clipping, and we don't have to provide
a device-dependent interface.

One not-so-nice thing is that it's not obvious from the interface that
cairo_clip will do one of two very different things, (depending on
whether the path is entirely pixel-aligned rectangles). This isn't so
bad since the semantics of both operations are the same, it's just
that the performance of the pixel-aligned clipping is a _lot_ better
than the generic mask-based clipping.

If we can improve the performance of the mask-based clipping
sufficiently, then the dual-nature of cairo_clip should be much less
of a problem for users.

> thanks in advance,

You're quite welcome. I hope that helps.

-Carl
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
Url : http://lists.freedesktop.org/archives/cairo/attachments/20050527/c421df21/attachment.pgp


More information about the cairo mailing list