Remove setting of alpha coverage in text ops when in LCD mode
authorGreg Daniel <egdaniel@google.com>
Mon, 22 May 2017 20:34:34 +0000 (16:34 -0400)
committerSkia Commit-Bot <skia-commit-bot@chromium.org>
Mon, 22 May 2017 21:03:37 +0000 (21:03 +0000)
Bug: skia:
Change-Id: I0e320497fe72a0edad7bda7ea1c34dc2f713fc56
Reviewed-on: https://skia-review.googlesource.com/17530
Reviewed-by: Brian Salomon <bsalomon@google.com>
Commit-Queue: Greg Daniel <egdaniel@google.com>

src/gpu/effects/GrBitmapTextGeoProc.cpp
src/gpu/effects/GrDistanceFieldGeoProc.cpp
src/gpu/glsl/GrGLSLXferProcessor.cpp

index 470af46..cd2fe56 100644 (file)
@@ -72,12 +72,6 @@ public:
             fragBuilder->codeAppendf("%s = ", args.fOutputCoverage);
             fragBuilder->appendTextureLookup(args.fTexSamplers[0], v.fsIn(), kVec2f_GrSLType);
             fragBuilder->codeAppend(";");
-            if (cte.maskFormat() == kA565_GrMaskFormat) {
-                // set alpha to be max of rgb coverage
-                fragBuilder->codeAppendf("%s.a = max(max(%s.r, %s.g), %s.b);",
-                                         args.fOutputCoverage, args.fOutputCoverage,
-                                         args.fOutputCoverage, args.fOutputCoverage);
-            }
         }
     }
 
index 96d322f..7d22ad3 100644 (file)
@@ -712,17 +712,14 @@ public:
         // doing gamma-correct rendering (to an sRGB or F16 buffer), then we actually want distance
         // mapped linearly to coverage, so use a linear step:
         if (isGammaCorrect) {
-            fragBuilder->codeAppend("vec4 val = "
-                "vec4(clamp((distance + vec3(afwidth)) / vec3(2.0 * afwidth), 0.0, 1.0), 1.0);");
+            fragBuilder->codeAppendf("%s = "
+                "vec4(clamp((distance + vec3(afwidth)) / vec3(2.0 * afwidth), 0.0, 1.0), 1.0);",
+                args.fOutputCoverage);
         } else {
-            fragBuilder->codeAppend(
-                "vec4 val = vec4(smoothstep(vec3(-afwidth), vec3(afwidth), distance), 1.0);");
+            fragBuilder->codeAppendf(
+                "%s = vec4(smoothstep(vec3(-afwidth), vec3(afwidth), distance), 1.0);",
+                args.fOutputCoverage);
         }
-
-        // set alpha to be max of rgb coverage
-        fragBuilder->codeAppend("val.a = max(max(val.r, val.g), val.b);");
-
-        fragBuilder->codeAppendf("%s = val;", args.fOutputCoverage);
     }
 
     void setData(const GrGLSLProgramDataManager& pdman, const GrPrimitiveProcessor& processor,
index ba5b5da..41a4677 100644 (file)
@@ -44,8 +44,14 @@ void GrGLSLXferProcessor::emitCode(const EmitArgs& args) {
 
         if (args.fInputCoverage) {
             // We don't think any shaders actually output negative coverage, but just as a safety
-            // check for floating point precision errors we compare with <= here
-            fragBuilder->codeAppendf("if (all(lessThanEqual(%s, vec4(0)))) {"
+            // check for floating point precision errors we compare with <= here. We just check the
+            // rgb values of the coverage since the alpha may not have been set when using lcd. If
+            // we are using single channel coverage alpha will equal to rgb anyways.
+            //
+            // The discard here also helps for batching text draws together which need to read from
+            // a dst copy for blends. Though this only helps the case where the outer bounding boxes
+            // of each letter overlap and not two actually parts of the text.
+            fragBuilder->codeAppendf("if (all(lessThanEqual(%s.rgb, vec3(0)))) {"
                                      "    discard;"
                                      "}", args.fInputCoverage);
         }