Edge antialiasing for convex shapes in Ganesh

This patch implements edge antialiasing for convex shapes, using the fragment
shader to compare against the edge equations for each triangle.  Currently, it
only works for flat shaded primitives (i.e., it was not integrated into the
"active stages" path).  The skia.gyp changes cause this code to be compiled into
SampleApp, but do not enable the tesselated path by default.

Notes:  the SkOSWindow_Unix.cpp change is to silence a valgrind warning about
memcpy() with overlapping regions.  The GrBinHashKey change is to avoid running
a two-pass hash (GrProgramDesc is now 52 bytes or so, exceeding the 32 byte
default size).

Review URL:  http://codereview.appspot.com/4519054/



git-svn-id: http://skia.googlecode.com/svn/trunk@1314 2bbb7eff-a529-9590-31e7-b0007b416f81
diff --git a/gpu/include/GrDrawTarget.h b/gpu/include/GrDrawTarget.h
index e8f1793..93b381d 100644
--- a/gpu/include/GrDrawTarget.h
+++ b/gpu/include/GrDrawTarget.h
@@ -66,18 +66,22 @@
      *  default to disabled.
      */
     enum StateBits {
-        kDither_StateBit          = 0x1,//<! Perform color dithering
-        kAntialias_StateBit       = 0x2,//<! Perform anti-aliasing. The render-
+        kDither_StateBit        = 0x01, //<! Perform color dithering
+        kAntialias_StateBit     = 0x02, //<! Perform anti-aliasing. The render-
                                         //   target must support some form of AA
                                         //   (msaa, coverage sampling, etc). For
                                         //   GrGpu-created rendertarget/textures
                                         //   this is controlled by parameters
                                         //   passed to createTexture.
-        kClip_StateBit            = 0x4,//<! Controls whether drawing is clipped
+        kClip_StateBit          = 0x04, //<! Controls whether drawing is clipped
                                         //   against the region specified by
                                         //   setClip.
-        kNoColorWrites_StateBit   = 0x8,//<! If set it disables writing colors.
-                                        //   Useful while performing stencil ops.
+        kNoColorWrites_StateBit = 0x08, //<! If set it disables writing colors.
+                                        //   Useful while performing stencil
+                                        //   ops.
+        kEdgeAA_StateBit        = 0x10, //<! Perform edge anti-aliasing.
+                                        //   Requires the edges to be passed in
+                                        //   setEdgeAAData().
 
         // subclass may use additional bits internally
         kDummyStateBit,
@@ -154,6 +158,7 @@
 
         GrStencilSettings       fStencilSettings;
         GrMatrix                fViewMatrix;
+        float                   fEdgeAAEdges[18];
         bool operator ==(const DrState& s) const {
             return 0 == memcmp(this, &s, sizeof(DrState));
         }
@@ -362,6 +367,10 @@
         return 0 != (fCurrDrawState.fFlagBits & kDither_StateBit);
     }
 
+    bool isAntialiasState() const {
+        return 0 != (fCurrDrawState.fFlagBits & kAntialias_StateBit);
+    }
+
     bool isClipState() const {
         return 0 != (fCurrDrawState.fFlagBits & kClip_StateBit);
     }
@@ -483,6 +492,14 @@
      */
     bool canDisableBlend() const;
 
+    /**
+     * Sets the edge data required for edge antialiasing.
+     *
+     * @param edges       3 * 6 float values, representing the edge
+     *                    equations in Ax + By + C form
+     */
+     void setEdgeAAData(const float edges[18]);
+
 private:
     static const int TEX_COORD_BIT_CNT = kNumStages*kMaxTexCoords;
 public: