Improve inputColor handling in fragment processor implementations.
EmitArgs explicitly checks for null constructor arguments and uses
"half4(1)" for fInputColor to ensure its fields are non-null.
Cleans up accesses of fInputColor in existing fragment processors to no
longer check for null and hardcode a "half4(1)".
Updates .fp CPP generation to remove the null check for fInputArgs.
Updates the internals of emitChild() to emit an extra local variable
with a mangled variable name for storing the provided input expression.
Bug: skia:
Change-Id: Iad807f269655689dcb2e8d58f2eb506685ba2757
Reviewed-on: https://skia-review.googlesource.com/149231
Commit-Queue: Michael Ludwig <michaelludwig@google.com>
Reviewed-by: Ethan Nicholas <ethannicholas@google.com>
diff --git a/src/gpu/glsl/GrGLSLFragmentProcessor.h b/src/gpu/glsl/GrGLSLFragmentProcessor.h
index 591146e..357b80e 100644
--- a/src/gpu/glsl/GrGLSLFragmentProcessor.h
+++ b/src/gpu/glsl/GrGLSLFragmentProcessor.h
@@ -83,8 +83,9 @@
@param outputColor A predefined half4 in the FS in which the stage should place its
output color (or coverage).
@param inputColor A half4 that holds the input color to the stage in the FS. This may
- be nullptr in which case the implied input is solid white (all
- ones). TODO: Better system for communicating optimization info
+ be nullptr in which case the fInputColor is set to "half4(1.0)"
+ (solid white) so this is guaranteed non-null.
+ TODO: Better system for communicating optimization info
(e.g. input color is solid white, trans black, known to be opaque,
etc.) that allows the processor to communicate back similar known
info about its output.
@@ -108,7 +109,7 @@
, fShaderCaps(caps)
, fFp(fp)
, fOutputColor(outputColor)
- , fInputColor(inputColor)
+ , fInputColor(inputColor ? inputColor : "half4(1.0)")
, fTransformedCoords(transformedCoordVars)
, fTexSamplers(textureSamplers) {}
GrGLSLFPFragmentBuilder* fFragBuilder;
@@ -131,8 +132,9 @@
return fChildProcessors[index];
}
+ // Emit the child with the default input color (solid white)
inline void emitChild(int childIndex, SkString* outputColor, EmitArgs& parentArgs) {
- this->emitChild(childIndex, "half4(1.0)", outputColor, parentArgs);
+ this->emitChild(childIndex, nullptr, outputColor, parentArgs);
}
/** Will emit the code of a child proc in its own scope. Pass in the parent's EmitArgs and
@@ -146,8 +148,11 @@
void emitChild(int childIndex, const char* inputColor, SkString* outputColor,
EmitArgs& parentArgs);
+ // Use the parent's output color to hold child's output, and use the
+ // default input color of solid white
inline void emitChild(int childIndex, EmitArgs& args) {
- this->emitChild(childIndex, "half4(1.0)", args);
+ // null pointer cast required to disambiguate the function call
+ this->emitChild(childIndex, (const char*) nullptr, args);
}
/** Variation that uses the parent's output color variable to hold the child's output.*/