Specialize scale+translate transforms for explicitly sampled FPs.

This is to support using YUV->RGB in more places where we would incur a
full 3x3 matrix multiply for each plane in the fragment shader without
this.

Change-Id: I27c2a403429c36662eba91f61b08e5331ec678b5
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/278356
Reviewed-by: Brian Osman <brianosman@google.com>
Commit-Queue: Brian Salomon <bsalomon@google.com>
diff --git a/src/gpu/GrPrimitiveProcessor.cpp b/src/gpu/GrPrimitiveProcessor.cpp
index 9378c41..b2c75c0 100644
--- a/src/gpu/GrPrimitiveProcessor.cpp
+++ b/src/gpu/GrPrimitiveProcessor.cpp
@@ -11,12 +11,15 @@
 #include "src/gpu/GrFragmentProcessor.h"
 
 /**
- * We specialize the vertex code for each of these matrix types.
+ * We specialize the vertex or fragment coord transform code for these matrix types.
+ * Some specializations are only applied when the coord transform is applied in the fragment
+ * shader.
  */
 enum MatrixType {
-    kNone_MatrixType     = 0,
-    kNoPersp_MatrixType  = 1,
-    kGeneral_MatrixType  = 2,
+    kNone_MatrixType            = 0,  // Used only in FS for explicitly sampled FPs
+    kScaleTranslate_MatrixType  = 1,  // Used only in FS for explicitly sampled FPs
+    kNoPersp_MatrixType         = 2,
+    kGeneral_MatrixType         = 3,
 };
 
 GrPrimitiveProcessor::GrPrimitiveProcessor(ClassID classID) : GrProcessor(classID) {}
@@ -35,13 +38,15 @@
         const GrCoordTransform& coordTransform = fp.coordTransform(t);
         if (fp.isSampledWithExplicitCoords() && coordTransform.isNoOp()) {
             key = kNone_MatrixType;
-        } else if (coordTransform.matrix().hasPerspective()) {
+        } else if (fp.isSampledWithExplicitCoords() && coordTransform.matrix().isScaleTranslate()) {
+            key = kScaleTranslate_MatrixType;
+        } else if (!coordTransform.matrix().hasPerspective()) {
+            key = kNoPersp_MatrixType;
+        } else {
             // Note that we can also have homogeneous varyings as a result of a GP local matrix or
             // homogeneous local coords generated by GP. We're relying on the GP to include any
             // variability in those in its key.
             key = kGeneral_MatrixType;
-        } else {
-            key = kNoPersp_MatrixType;
         }
         key <<= 2*t;
         SkASSERT(0 == (totalKey & key)); // keys for each transform ought not to overlap