[cairo] new trapezoid code in glitz

David Reveman davidr at novell.com
Thu Jan 27 04:21:43 PST 2005


I've now committed the new trapezoid code I've been working on for
glitz.

Here's a short description of how this new code works:

An implicit mask surface for a single anti-aliased edge that intersect a
rectangle in any direction, can be represented accurately and
consistently with a set of one-dimensional texture coordinates in a
fixed size texture. By using linear texture filtering this allows us to
render perfectly anti-aliased geometry on a wide range of hardware.

Each trapezoid needs to be slit up into a set of rectangles along with
appropriate horizontal texture coordinates for the specified mask
surface. In general the mask is a 2x1 surface with pixel 0,0 "clear
black" and pixel 1,0 "solid white". It could also be a Nx1 surface
containing a pre-computed gamma curve with resolution N for gamma
corrected anti-aliasing.

The algorithm that I've come up with, and the current implementation
that will do this "trapezoid -> rectangles/texcoords" conversion can be
found in glitz_trapimp.h. The current implementation is far from
perfect, it could probably be a lot more efficient, and it's all in
floating point arithmetics right now. However, the performance of the
current implementation is still pretty good.

Rendering non-intersecting trapezoids this way is very fast. For
intersecting trapezoids we need to use an intermediate mask and that
really kills performance, but this is a completely different problem
that should be solved by upcoming extensions to OpenGL.

However, non-intersecting trapezoids are always going to be faster. I'd
like to see a trapezoid attribute in cairo that will indicate to the
backends that the trapezoids are not intersecting. I shouldn't be too
hard for the tessellator to keep track of this, right? 

How about making the tessellator snap intersection points to the pixel
grid and produce non-intersecting trapezoids if the tolerance is greater
than half a device unit?


This new trapezoid code is not currently used by cairo's glitz backend.
Xgl is using it and it works quite well in there. I'd like to switch to
using this new trapezoid code in the glitz backend as well. However,
until we have a good render-texture extension in OpenGL, I'm going to
let libpixman handle trapezoid rasterization when trapezoids are
intersecting. This will of course be a lot slower than the current glitz
backend but the output quality will instead be perfect, and I think
that's a lot more useful. If someone thinks this is a bad idea let me
know.

-David




More information about the cairo mailing list