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/src/GrGpuGLShaders.cpp b/gpu/src/GrGpuGLShaders.cpp
index 937c8ed..8965b06 100644
--- a/gpu/src/GrGpuGLShaders.cpp
+++ b/gpu/src/GrGpuGLShaders.cpp
@@ -36,7 +36,7 @@
 #if GR_DEBUG
     typedef GrBinHashKey<Entry, 4> ProgramHashKey; // Flex the dynamic allocation muscle in debug
 #else
-    typedef GrBinHashKey<Entry, 32> ProgramHashKey;
+    typedef GrBinHashKey<Entry, 64> ProgramHashKey;
 #endif
 
     class Entry : public ::GrNoncopyable {
@@ -396,6 +396,22 @@
     }
 }
 
+void GrGpuGLShaders::flushEdgeAAData() {
+    const int& uni = fProgramData->fUniLocations.fEdgesUni;
+    if (GrGLProgram::kUnusedUniform != uni) {
+        float edges[18];
+        memcpy(edges, fCurrDrawState.fEdgeAAEdges, sizeof(edges));
+        // Flip the edges in Y
+        float height = fCurrDrawState.fRenderTarget->height();
+        for (int i = 0; i < 6; ++i) {
+            float b = edges[i * 3 + 1];
+            edges[i * 3 + 1] = -b;
+            edges[i * 3 + 2] += b * height;
+        }
+        GR_GL(Uniform3fv(uni, 6, edges));
+    }
+}
+
 static const float ONE_OVER_255 = 1.f / 255.f;
 
 #define GR_COLOR_TO_VEC4(color) {\
@@ -500,6 +516,7 @@
 
         this->flushTexelSize(s);
     }
+    this->flushEdgeAAData();
     resetDirtyFlags();
     return true;
 }
@@ -632,6 +649,8 @@
         desc.fColorType = GrGLProgram::ProgramDesc::kAttribute_ColorType;
     }
 
+    desc.fUsesEdgeAA = fCurrDrawState.fFlagBits & kEdgeAA_StateBit;
+
     for (int s = 0; s < kNumStages; ++s) {
         GrGLProgram::ProgramDesc::StageDesc& stage = desc.fStages[s];