[cairo] Survey of polygon rasterization techniques

Jeff Muizelaar jeff at infidigm.net
Thu Aug 2 11:31:19 PDT 2007


On Tue, Jul 31, 2007 at 04:02:22AM -0400, Zack Rusin wrote:
> On Monday 30 July 2007 10:42:09 pm Jeff Muizelaar wrote:
> > qt
> >         - tessellate to trapezoids and then rasterize trapezoids
> 
> That's not really true. It's only the case for the native X11 engine where you 
> really want to be using XRender and for that you need to tessellate your 
> polygons. 
> Rendering to QImage (or just rendering on Qt/Windows) invokes software 
> rasterizer that is a mixture of freetype2/agg rasterization techniques and 
> should be faster than both. 
> And by default rendering in OpenGL invokes O(n) polygon rendering algorithm 
> that is based on stencil clipping and when "high quality antialiasing" flag 
> is set, fragment programs are used to directly anti-alias the rendering 
> shapes.


Zack,

I tried out the following change to qtrender.tar.bz2 to test the
software path. Hopefully, it's correct.

Interestingly, when I uncommented the commented part I saw a
noticeable decrease in quality and the image had some corruption when
displaying the polygon 3.

diff --git a/main.cpp b/main.cpp
index ce11023..cee5e88 100644
--- a/main.cpp
+++ b/main.cpp
@@ -26,14 +26,20 @@ public:
 protected:
     void paintEvent(QPaintEvent *)
     {
-        QPainter p(this);
+        QImage i(600, 600, QImage::Format_ARGB32_Premultiplied);
+        QPainter p(&i);
         p.setRenderHint(QPainter::Antialiasing);
         
         p.setPen(Qt::NoPen);
         p.setBrush(QColor(0, 0, 255));
         
         p.drawPath(path);
-        
+
+        /*
+        QPainter p2(this);
+        p2.drawImage(i.rect(), i);
+        */
+
         ++fps;
         QTimer::singleShot(0, this, SLOT(update()));
     }

Here are the performance results I got qt(sw). They too are interesting.
Do they make sense to you?

Some quick unscientific benchmarks
----------------------------
	1	2	3
--------------------------
libart	60	  1	 4
cairo	63	 22	 1
agg	94	 76	17	
qt(x11)	63	 63	 6
qt(sw)  34	166	 2	


-Jeff


More information about the cairo mailing list