ccpr: Calculate edge coverage in the coverage processor

Does the opposite-edge coverage calculation for curves in the coverage
processor, rather than the Shader class. This allows the vertex shader
implementation to do it more clean and directly, as well as allowing
the future sample mask implementation to disregard edge coverage
entirely.

Bug: skia:
Change-Id: Idaddfff8b22e3223f2a4e286900941969f975c6a
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/208990
Reviewed-by: Greg Daniel <egdaniel@google.com>
Commit-Queue: Chris Dalton <csmartdalton@google.com>
diff --git a/src/gpu/ccpr/GrCCCubicShader.cpp b/src/gpu/ccpr/GrCCCubicShader.cpp
index 7336bb0..7480b3e 100644
--- a/src/gpu/ccpr/GrCCCubicShader.cpp
+++ b/src/gpu/ccpr/GrCCCubicShader.cpp
@@ -13,8 +13,8 @@
 
 using Shader = GrCCCoverageProcessor::Shader;
 
-void GrCCCubicShader::emitSetupCode(GrGLSLVertexGeoBuilder* s, const char* pts,
-                                    const char* wind, const char** /*outHull4*/) const {
+void GrCCCubicShader::emitSetupCode(
+        GrGLSLVertexGeoBuilder* s, const char* pts, const char** /*outHull4*/) const {
     // Find the cubic's power basis coefficients.
     s->codeAppendf("float2x4 C = float4x4(-1,  3, -3,  1, "
                                          " 3, -6,  3,  0, "
@@ -79,28 +79,19 @@
     s->codeAppendf("%s *= float3x3(orientation[0] * orientation[1], 0, 0, "
                                   "0, orientation[0], 0, "
                                   "0, 0, orientation[1]);", fKLMMatrix.c_str());
-
-    // Determine the amount of additional coverage to subtract out for the flat edge (P3 -> P0).
-    s->declareGlobal(fEdgeDistanceEquation);
-    s->codeAppendf("int edgeidx0 = %s > 0 ? 3 : 0;", wind);
-    s->codeAppendf("float2 edgept0 = %s[edgeidx0];", pts);
-    s->codeAppendf("float2 edgept1 = %s[3 - edgeidx0];", pts);
-    Shader::EmitEdgeDistanceEquation(s, "edgept0", "edgept1", fEdgeDistanceEquation.c_str());
 }
 
-void GrCCCubicShader::onEmitVaryings(GrGLSLVaryingHandler* varyingHandler,
-                                     GrGLSLVarying::Scope scope, SkString* code,
-                                     const char* position, const char* coverage,
-                                     const char* cornerCoverage) {
+void GrCCCubicShader::onEmitVaryings(
+        GrGLSLVaryingHandler* varyingHandler, GrGLSLVarying::Scope scope, SkString* code,
+        const char* position, const char* coverage, const char* cornerCoverage, const char* wind) {
+    code->appendf("float3 klm = float3(%s, 1) * %s;", position, fKLMMatrix.c_str());
     fKLM_fEdge.reset(kFloat4_GrSLType, scope);
     varyingHandler->addVarying("klm_and_edge", &fKLM_fEdge);
-    code->appendf("float3 klm = float3(%s, 1) * %s;", position, fKLMMatrix.c_str());
-    // We give L & M both the same sign as wind, in order to pass this value to the fragment shader.
-    // (Cubics are pre-chopped such that L & M do not change sign within any individual segment.)
-    code->appendf("%s.xyz = klm * float3(1, %s, %s);",
-                  OutName(fKLM_fEdge), coverage, coverage); // coverage == wind on curves.
-    code->appendf("%s.w = dot(float3(%s, 1), %s);", // Flat edge opposite the curve.
-                  OutName(fKLM_fEdge), position, fEdgeDistanceEquation.c_str());
+    // Give L&M both the same sign as wind, in order to pass this value to the fragment shader.
+    // (Cubics are pre-chopped such that L&M do not change sign within any individual segment.)
+    code->appendf("%s.xyz = klm * float3(1, %s, %s);", OutName(fKLM_fEdge), wind, wind);
+    // Flat edge opposite the curve.
+    code->appendf("%s.w = %s;", OutName(fKLM_fEdge), coverage);
 
     fGradMatrix.reset(kFloat4_GrSLType, scope);
     varyingHandler->addVarying("grad_matrix", &fGradMatrix);
@@ -110,6 +101,7 @@
                     OutName(fGradMatrix), fKLMMatrix.c_str(), fKLMMatrix.c_str());
 
     if (cornerCoverage) {
+        SkASSERT(coverage);
         code->appendf("half hull_coverage; {");
         this->calcHullCoverage(code, OutName(fKLM_fEdge), OutName(fGradMatrix), "hull_coverage");
         code->appendf("}");
@@ -120,10 +112,10 @@
     }
 }
 
-void GrCCCubicShader::onEmitFragmentCode(GrGLSLFPFragmentBuilder* f,
-                                         const char* outputCoverage) const {
-    this->calcHullCoverage(&AccessCodeString(f), fKLM_fEdge.fsIn(), fGradMatrix.fsIn(),
-                           outputCoverage);
+void GrCCCubicShader::onEmitFragmentCode(
+        GrGLSLFPFragmentBuilder* f, const char* outputCoverage) const {
+    this->calcHullCoverage(
+            &AccessCodeString(f), fKLM_fEdge.fsIn(), fGradMatrix.fsIn(), outputCoverage);
 
     // Wind is the sign of both L and/or M. Take the sign of whichever has the larger magnitude.
     // (In reality, either would be fine because we chop cubics with more than a half pixel of