Change SampleMatrix to SampleUsage

It now tracks all sample calls of a child (matrix, explicit coords,
pass through). There is now just one registerChild() call, and the
sampling pattern of that child is fully determined by the SampleUsage
parameter.

Change-Id: Iaadcd325fca64a59f24192aadd06923c66362181
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/299875
Reviewed-by: Michael Ludwig <michaelludwig@google.com>
Commit-Queue: Brian Osman <brianosman@google.com>
diff --git a/src/gpu/glsl/GrGLSLFragmentProcessor.cpp b/src/gpu/glsl/GrGLSLFragmentProcessor.cpp
index 9b3b7b7..ad9b5ba 100644
--- a/src/gpu/glsl/GrGLSLFragmentProcessor.cpp
+++ b/src/gpu/glsl/GrGLSLFragmentProcessor.cpp
@@ -60,12 +60,12 @@
                                             inputColor ? inputColor : "half4(1)",
                                             skslCoords.c_str());
     } else {
-        // The child's function just takes a color; we should only get here for a call to
-        // sample(color) without explicit coordinates, so assert that the child has no sample matrix
-        // and skslCoords is _coords (a const/uniform sample call would go through
-        // invokeChildWithMatrix, and if a child was sampled with sample(matrix) and sample(), it
-        // should have been flagged as variable and hit the branch above).
-        SkASSERT(skslCoords == args.fSampleCoord && childProc.sampleMatrix().isNoOp());
+        // The child's function just takes a color. We should only get here for a call to sample
+        // without explicit coordinates. Assert that the child has no sample matrix and skslCoords
+        // is _coords (a uniform matrix sample call would go through invokeChildWithMatrix, and if
+        // a child was sampled with sample(matrix) and sample(), it should have been flagged as
+        // variable and hit the branch above).
+        SkASSERT(skslCoords == args.fSampleCoord && !childProc.sampleUsage().hasMatrix());
         return SkStringPrintf("%s(%s)", fFunctionNames[childIndex].c_str(),
                                         inputColor ? inputColor : "half4(1)");
     }
@@ -78,23 +78,23 @@
     this->emitChildFunction(childIndex, args);
 
     const GrFragmentProcessor& childProc = args.fFp.childProcessor(childIndex);
+    SkASSERT(childProc.sampleUsage().hasMatrix());
 
-    // Since this is const/uniform, the provided sksl expression should exactly match the
-    // expression stored on the FP, or it should match the mangled uniform name.
+    // Since this is uniform, the provided sksl expression should exactly match the expression
+    // stored on the FP, or it should match the mangled uniform name.
     if (skslMatrix.empty()) {
-        // Empty matrix expression replaces with the sampleMatrix expression stored on the FP, but
-        // that is only valid for const/uniform sampled FPs
-        SkASSERT(childProc.sampleMatrix().isConstUniform());
-        skslMatrix.assign(childProc.sampleMatrix().fExpression);
+        // Empty matrix expression replaces with the sample matrix expression stored on the FP, but
+        // that is only valid for uniform sampled FPs
+        SkASSERT(childProc.sampleUsage().hasUniformMatrix());
+        skslMatrix.assign(childProc.sampleUsage().fExpression);
     }
 
-    if (childProc.sampleMatrix().isConstUniform()) {
-        // Attempt to resolve the uniform name from the raw name that was stored in the sample
-        // matrix. Since this is const/uniform, the provided expression better match what was given
-        // to the FP.
-        SkASSERT(childProc.sampleMatrix().fExpression == skslMatrix);
+    if (childProc.sampleUsage().hasUniformMatrix()) {
+        // Attempt to resolve the uniform name from the raw name stored in the sample usage.
+        // Since this is uniform, the provided expression better match what was given to the FP.
+        SkASSERT(childProc.sampleUsage().fExpression == skslMatrix);
         GrShaderVar uniform = args.fUniformHandler->getUniformMapping(
-                args.fFp, SkString(childProc.sampleMatrix().fExpression));
+                args.fFp, SkString(childProc.sampleUsage().fExpression));
         if (uniform.getType() != kVoid_GrSLType) {
             // Found the uniform, so replace the expression with the actual uniform name
             SkASSERT(uniform.getType() == kFloat3x3_GrSLType);
@@ -104,18 +104,17 @@
 
     // Produce a string containing the call to the helper function. sample(matrix) is special where
     // the provided skslMatrix expression means that the child FP should be invoked with coords
-    // equal to matrix * parent coords. However, if matrix is a constant/uniform AND the parent
-    // coords were produced by const/uniform transforms, then this expression is lifted to a vertex
+    // equal to matrix * parent coords. However, if matrix is a uniform expression AND the parent
+    // coords were produced by uniform transforms, then this expression is lifted to a vertex
     // shader and is stored in a varying. In that case, childProc will not have a variable sample
     // matrix and will not be sampled explicitly, so its function signature will not take in coords.
     //
     // In all other cases, we need to insert sksl to compute matrix * parent coords and then invoke
     // the function.
     if (childProc.isSampledWithExplicitCoords()) {
-        SkASSERT(!childProc.sampleMatrix().isNoOp());
         // Only check perspective for this specific matrix transform, not the aggregate FP property.
         // Any parent perspective will have already been applied when evaluated in the FS.
-        if (childProc.sampleMatrix().fHasPerspective) {
+        if (childProc.sampleUsage().fHasPerspective) {
             return SkStringPrintf("%s(%s, proj((%s) * %s.xy1))", fFunctionNames[childIndex].c_str(),
                                   inputColor ? inputColor : "half4(1)", skslMatrix.c_str(),
                                   args.fSampleCoord);
@@ -128,10 +127,10 @@
     } else {
         // A variable matrix expression should mark the child as explicitly sampled. A no-op
         // matrix should match sample(color), not sample(color, matrix).
-        SkASSERT(childProc.sampleMatrix().isConstUniform());
+        SkASSERT(childProc.sampleUsage().hasUniformMatrix());
 
-        // Since this is const/uniform and not explicitly sampled, it's transform has been
-        // promoted to the vertex shader and the signature doesn't take a float2 coord.
+        // Since this is uniform and not explicitly sampled, it's transform has been promoted to
+        // the vertex shader and the signature doesn't take a float2 coord.
         return SkStringPrintf("%s(%s)", fFunctionNames[childIndex].c_str(),
                                         inputColor ? inputColor : "half4(1)");
     }