Stop flattening GrCoordTransforms in parent GrFragmentProcessors.

This changes moves to a model that iterates over GrCTs in a GrFP hierarchy when inserting transformations by GrGLSLPrimitiveProcessors.
GOLD_TRYBOT_URL= https://gold.skia.org/search?issue=2339203002

Committed: https://skia.googlesource.com/skia/+/d91237ee051523f439238042674ade99207fe4a6
Review-Url: https://codereview.chromium.org/2339203002
diff --git a/src/gpu/glsl/GrGLSLGeometryProcessor.cpp b/src/gpu/glsl/GrGLSLGeometryProcessor.cpp
index ddbe8e1..bea49e5 100644
--- a/src/gpu/glsl/GrGLSLGeometryProcessor.cpp
+++ b/src/gpu/glsl/GrGLSLGeometryProcessor.cpp
@@ -29,73 +29,84 @@
                                              const GrShaderVar& posVar,
                                              const char* localCoords,
                                              const SkMatrix& localMatrix,
-                                             const TransformsIn& tin,
-                                             TransformsOut* tout) {
-    tout->push_back_n(tin.count());
-    fInstalledTransforms.push_back_n(tin.count());
-    for (int i = 0; i < tin.count(); i++) {
-        const ProcCoords& coordTransforms = tin[i];
-        fInstalledTransforms[i].push_back_n(coordTransforms.count());
-        for (int t = 0; t < coordTransforms.count(); t++) {
-            SkString strUniName("StageMatrix");
-            strUniName.appendf("_%i_%i", i, t);
-            GrSLType varyingType;
+                                             FPCoordTransformHandler* handler) {
+    int i = 0;
+    while (const GrCoordTransform* coordTransform = handler->nextCoordTransform()) {
+        SkString strUniName;
+        strUniName.printf("CoordTransformMatrix_%d", i);
+        GrSLType varyingType;
 
-            GrCoordSet coordType = coordTransforms[t]->sourceCoords();
-            uint32_t type = coordTransforms[t]->getMatrix().getType();
-            if (kLocal_GrCoordSet == coordType) {
-                type |= localMatrix.getType();
-            }
-            varyingType = SkToBool(SkMatrix::kPerspective_Mask & type) ? kVec3f_GrSLType :
-                                                                         kVec2f_GrSLType;
-            GrSLPrecision precision = coordTransforms[t]->precision();
+        GrCoordSet coordType = coordTransform->sourceCoords();
+        uint32_t type = coordTransform->getMatrix().getType();
+        if (kLocal_GrCoordSet == coordType) {
+            type |= localMatrix.getType();
+        }
+        varyingType = SkToBool(SkMatrix::kPerspective_Mask & type) ? kVec3f_GrSLType :
+                                                                     kVec2f_GrSLType;
+        GrSLPrecision precision = coordTransform->precision();
 
-            const char* uniName;
-            fInstalledTransforms[i][t].fHandle =
-                    uniformHandler->addUniform(kVertex_GrShaderFlag,
-                                               kMat33f_GrSLType, precision,
-                                               strUniName.c_str(),
-                                               &uniName).toIndex();
+        const char* uniName;
 
-            SkString strVaryingName("MatrixCoord");
-            strVaryingName.appendf("_%i_%i", i, t);
 
-            GrGLSLVertToFrag v(varyingType);
-            varyingHandler->addVarying(strVaryingName.c_str(), &v, precision);
+        fInstalledTransforms.push_back().fHandle = uniformHandler->addUniform(kVertex_GrShaderFlag,
+                                                                              kMat33f_GrSLType,
+                                                                              precision,
+                                                                              strUniName.c_str(),
+                                                                              &uniName).toIndex();
+        SkString strVaryingName;
+        strVaryingName.printf("TransformedCoords_%d", i);
 
-            SkASSERT(kVec2f_GrSLType == varyingType || kVec3f_GrSLType == varyingType);
-            (*tout)[i].emplace_back(SkString(v.fsIn()), varyingType);
+        GrGLSLVertToFrag v(varyingType);
+        varyingHandler->addVarying(strVaryingName.c_str(), &v, precision);
 
-            // varying = matrix * coords (logically)
-            if (kDevice_GrCoordSet == coordType) {
-                if (kVec2f_GrSLType == varyingType) {
-                    if (kVec2f_GrSLType == posVar.getType()) {
-                        vb->codeAppendf("%s = (%s * vec3(%s, 1)).xy;",
-                                        v.vsOut(), uniName, posVar.c_str());
-                    } else {
-                        // The brackets here are just to scope the temp variable
-                        vb->codeAppendf("{ vec3 temp = %s * %s;", uniName, posVar.c_str());
-                        vb->codeAppendf("%s = vec2(temp.x/temp.z, temp.y/temp.z); }", v.vsOut());
-                    }
+        SkASSERT(kVec2f_GrSLType == varyingType || kVec3f_GrSLType == varyingType);
+        handler->specifyCoordsForCurrCoordTransform(SkString(v.fsIn()), varyingType);
+
+        // varying = matrix * coords (logically)
+        if (kDevice_GrCoordSet == coordType) {
+            if (kVec2f_GrSLType == varyingType) {
+                if (kVec2f_GrSLType == posVar.getType()) {
+                    vb->codeAppendf("%s = (%s * vec3(%s, 1)).xy;",
+                                    v.vsOut(), uniName, posVar.c_str());
                 } else {
-                    if (kVec2f_GrSLType == posVar.getType()) {
-                        vb->codeAppendf("%s = %s * vec3(%s, 1);",
-                                        v.vsOut(), uniName, posVar.c_str());
-                    } else {
-                        vb->codeAppendf("%s = %s * %s;", v.vsOut(), uniName, posVar.c_str());
-                    }
+                    // The brackets here are just to scope the temp variable
+                    vb->codeAppendf("{ vec3 temp = %s * %s;", uniName, posVar.c_str());
+                    vb->codeAppendf("%s = vec2(temp.x/temp.z, temp.y/temp.z); }", v.vsOut());
                 }
             } else {
-                if (kVec2f_GrSLType == varyingType) {
-                    vb->codeAppendf("%s = (%s * vec3(%s, 1)).xy;", v.vsOut(), uniName, localCoords);
+                if (kVec2f_GrSLType == posVar.getType()) {
+                    vb->codeAppendf("%s = %s * vec3(%s, 1);",
+                                    v.vsOut(), uniName, posVar.c_str());
                 } else {
-                    vb->codeAppendf("%s = %s * vec3(%s, 1);", v.vsOut(), uniName, localCoords);
+                    vb->codeAppendf("%s = %s * %s;", v.vsOut(), uniName, posVar.c_str());
                 }
             }
+        } else {
+            if (kVec2f_GrSLType == varyingType) {
+                vb->codeAppendf("%s = (%s * vec3(%s, 1)).xy;", v.vsOut(), uniName, localCoords);
+            } else {
+                vb->codeAppendf("%s = %s * vec3(%s, 1);", v.vsOut(), uniName, localCoords);
+            }
         }
+        ++i;
     }
 }
 
+void GrGLSLGeometryProcessor::setTransformDataHelper(const SkMatrix& localMatrix,
+                                                     const GrGLSLProgramDataManager& pdman,
+                                                     FPCoordTransformIter* transformIter) {
+    int i = 0;
+    while (const GrCoordTransform* coordTransform = transformIter->next()) {
+        const SkMatrix& m = GetTransformMatrix(localMatrix, *coordTransform);
+        if (!fInstalledTransforms[i].fCurrentValue.cheapEqualTo(m)) {
+            pdman.setSkMatrix(fInstalledTransforms[i].fHandle.toIndex(), m);
+            fInstalledTransforms[i].fCurrentValue = m;
+        }
+        ++i;
+    }
+    SkASSERT(i == fInstalledTransforms.count());
+}
+
 void GrGLSLGeometryProcessor::setupPosition(GrGLSLVertexBuilder* vertBuilder,
                                             GrGPArgs* gpArgs,
                                             const char* posName) {