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/sksl/SkSLHCodeGenerator.cpp b/src/sksl/SkSLHCodeGenerator.cpp
index f7c324b..3f5f2f3 100644
--- a/src/sksl/SkSLHCodeGenerator.cpp
+++ b/src/sksl/SkSLHCodeGenerator.cpp
@@ -7,7 +7,7 @@
 
 #include "src/sksl/SkSLHCodeGenerator.h"
 
-#include "include/private/SkSLSampleMatrix.h"
+#include "include/private/SkSLSampleUsage.h"
 #include "src/sksl/SkSLAnalysis.h"
 #include "src/sksl/SkSLParser.h"
 #include "src/sksl/SkSLUtil.h"
@@ -276,53 +276,24 @@
                 this->writef("        SkASSERT(%s);", String(param->fName).c_str());
             }
 
-            bool explicitCoords = Analysis::IsExplicitlySampled(fProgram, *param);
-            SampleMatrix matrix = Analysis::GetSampleMatrix(fProgram, *param);
+            SampleUsage usage = Analysis::GetSampleUsage(fProgram, *param);
 
-            String registerFunc;
-            String matrixArg;
-            String explicitArg;
-
-            if (explicitCoords && matrix.fKind == SampleMatrix::Kind::kNone) {
-                registerFunc = "registerExplicitlySampledChild";
-            } else {
-                registerFunc = "registerChild";
-                if (explicitCoords) {
-                    explicitArg = ", true";
-                }
-                switch(matrix.fKind) {
-                    case SampleMatrix::Kind::kVariable:
-                        // FIXME As it stands, matrix.fHasPerspective will always be true. Ideally
-                        // we could build an expression from all const/uniform sample matrices used
-                        // in the sksl, e.g. m1.hasPerspective() || m2.hasPerspective(), where each
-                        // term was the type expression for the original const/uniform sample
-                        // matrices before they were merged during sksl analysis.
-                        matrixArg.appendf(", SkSL::SampleMatrix::MakeVariable(%s)",
-                                          matrix.fHasPerspective ? "true" : "false");
+            std::string perspExpression;
+            if (usage.hasUniformMatrix()) {
+                for (const Variable* p : fSectionAndParameterHelper.getParameters()) {
+                    if ((p->fModifiers.fFlags & Modifiers::kIn_Flag) &&
+                        usage.fExpression == String(p->fName)) {
+                        perspExpression = usage.fExpression + ".hasPerspective()";
                         break;
-                    case SampleMatrix::Kind::kConstantOrUniform: {
-                        std::string perspExpression = matrix.fHasPerspective ? "true" : "false";
-                        for (const Variable* p : fSectionAndParameterHelper.getParameters()) {
-                            if ((p->fModifiers.fFlags & Modifiers::kIn_Flag) &&
-                                matrix.fExpression == String(p->fName)) {
-                                perspExpression = matrix.fExpression + ".hasPerspective()";
-                                break;
-                            }
-                        }
-                        matrixArg.appendf(", SkSL::SampleMatrix::MakeConstUniform(\"%s\", %s)",
-                                          matrix.fExpression.c_str(), perspExpression.c_str());
-                        break; }
-                    case SampleMatrix::Kind::kNone:
-                        break;
+                    }
                 }
             }
+            std::string usageArg = usage.constructor(std::move(perspExpression));
 
-            this->writef("            %s_index = this->%s(std::move(%s)%s%s);",
+            this->writef("            %s_index = this->registerChild(std::move(%s), %s);",
                          FieldName(String(param->fName).c_str()).c_str(),
-                         registerFunc.c_str(),
                          String(param->fName).c_str(),
-                         matrixArg.c_str(),
-                         explicitArg.c_str());
+                         usageArg.c_str());
 
             if (param->fType.kind() == Type::kNullable_Kind) {
                 this->writef("       }");