Disable output swizzling from GrDisableColorXP
This makes sure the final shader does not output a color.
Bug: skia:
Change-Id: I1e5299bb63391d6ff72598ed72fe4fb80b18fa07
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/206352
Commit-Queue: Chris Dalton <csmartdalton@google.com>
Reviewed-by: Greg Daniel <egdaniel@google.com>
diff --git a/src/gpu/glsl/GrGLSLXferProcessor.cpp b/src/gpu/glsl/GrGLSLXferProcessor.cpp
index 012fce7..4af5303 100644
--- a/src/gpu/glsl/GrGLSLXferProcessor.cpp
+++ b/src/gpu/glsl/GrGLSLXferProcessor.cpp
@@ -31,77 +31,92 @@
if (!args.fXP.willReadDstColor()) {
adjust_for_lcd_coverage(args.fXPFragBuilder, args.fInputCoverage, args.fXP);
this->emitOutputsForBlendState(args);
- return;
- }
+ } else {
+ GrGLSLXPFragmentBuilder* fragBuilder = args.fXPFragBuilder;
+ GrGLSLUniformHandler* uniformHandler = args.fUniformHandler;
+ const char* dstColor = fragBuilder->dstColor();
- GrGLSLXPFragmentBuilder* fragBuilder = args.fXPFragBuilder;
- GrGLSLUniformHandler* uniformHandler = args.fUniformHandler;
- const char* dstColor = fragBuilder->dstColor();
+ bool needsLocalOutColor = false;
- bool needsLocalOutColor = false;
+ if (args.fDstTextureSamplerHandle.isValid()) {
+ bool flipY = kBottomLeft_GrSurfaceOrigin == args.fDstTextureOrigin;
- if (args.fDstTextureSamplerHandle.isValid()) {
- bool flipY = kBottomLeft_GrSurfaceOrigin == args.fDstTextureOrigin;
+ 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. 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, half3(0)))) {"
+ " discard;"
+ "}", args.fInputCoverage);
+ }
- 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. 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, half3(0)))) {"
- " discard;"
- "}", args.fInputCoverage);
+ const char* dstTopLeftName;
+ const char* dstCoordScaleName;
+
+ fDstTopLeftUni = uniformHandler->addUniform(kFragment_GrShaderFlag,
+ kHalf2_GrSLType,
+ "DstTextureUpperLeft",
+ &dstTopLeftName);
+ fDstScaleUni = uniformHandler->addUniform(kFragment_GrShaderFlag,
+ kHalf2_GrSLType,
+ "DstTextureCoordScale",
+ &dstCoordScaleName);
+
+ fragBuilder->codeAppend("// Read color from copy of the destination.\n");
+ fragBuilder->codeAppendf("half2 _dstTexCoord = (half2(sk_FragCoord.xy) - %s) * %s;",
+ dstTopLeftName, dstCoordScaleName);
+
+ if (flipY) {
+ fragBuilder->codeAppend("_dstTexCoord.y = 1.0 - _dstTexCoord.y;");
+ }
+
+ fragBuilder->codeAppendf("half4 %s = ", dstColor);
+ fragBuilder->appendTextureLookup(args.fDstTextureSamplerHandle, "_dstTexCoord",
+ kHalf2_GrSLType);
+ fragBuilder->codeAppend(";");
+ } else {
+ needsLocalOutColor = args.fShaderCaps->requiresLocalOutputColorForFBFetch();
}
- const char* dstTopLeftName;
- const char* dstCoordScaleName;
-
- fDstTopLeftUni = uniformHandler->addUniform(kFragment_GrShaderFlag,
- kHalf2_GrSLType,
- "DstTextureUpperLeft",
- &dstTopLeftName);
- fDstScaleUni = uniformHandler->addUniform(kFragment_GrShaderFlag,
- kHalf2_GrSLType,
- "DstTextureCoordScale",
- &dstCoordScaleName);
-
- fragBuilder->codeAppend("// Read color from copy of the destination.\n");
- fragBuilder->codeAppendf("half2 _dstTexCoord = (half2(sk_FragCoord.xy) - %s) * %s;",
- dstTopLeftName, dstCoordScaleName);
-
- if (flipY) {
- fragBuilder->codeAppend("_dstTexCoord.y = 1.0 - _dstTexCoord.y;");
+ const char* outColor = "_localColorOut";
+ if (!needsLocalOutColor) {
+ outColor = args.fOutputPrimary;
+ } else {
+ fragBuilder->codeAppendf("half4 %s;", outColor);
}
- fragBuilder->codeAppendf("half4 %s = ", dstColor);
- fragBuilder->appendTextureLookup(args.fDstTextureSamplerHandle, "_dstTexCoord",
- kHalf2_GrSLType);
- fragBuilder->codeAppend(";");
- } else {
- needsLocalOutColor = args.fShaderCaps->requiresLocalOutputColorForFBFetch();
+ this->emitBlendCodeForDstRead(fragBuilder,
+ uniformHandler,
+ args.fInputColor,
+ args.fInputCoverage,
+ dstColor,
+ outColor,
+ args.fOutputSecondary,
+ args.fXP);
+ if (needsLocalOutColor) {
+ fragBuilder->codeAppendf("%s = %s;", args.fOutputPrimary, outColor);
+ }
}
- const char* outColor = "_localColorOut";
- if (!needsLocalOutColor) {
- outColor = args.fOutputPrimary;
- } else {
- fragBuilder->codeAppendf("half4 %s;", outColor);
- }
+ // Swizzle the fragment shader outputs if necessary.
+ this->emitOutputSwizzle(
+ args.fXPFragBuilder, args.fOutputSwizzle, args.fOutputPrimary, args.fOutputSecondary);
+}
- this->emitBlendCodeForDstRead(fragBuilder,
- uniformHandler,
- args.fInputColor,
- args.fInputCoverage,
- dstColor,
- outColor,
- args.fOutputSecondary,
- args.fXP);
- if (needsLocalOutColor) {
- fragBuilder->codeAppendf("%s = %s;", args.fOutputPrimary, outColor);
+void GrGLSLXferProcessor::emitOutputSwizzle(
+ GrGLSLXPFragmentBuilder* x, const GrSwizzle& swizzle, const char* outColor,
+ const char* outColorSecondary) const {
+ if (GrSwizzle::RGBA() != swizzle) {
+ x->codeAppendf("%s = %s.%s;", outColor, outColor, swizzle.c_str());
+ if (outColorSecondary) {
+ x->codeAppendf("%s = %s.%s;", outColorSecondary, outColorSecondary, swizzle.c_str());
+ }
}
}