Fix comma operator support with matrices in Metal.

MetalCodeGen would incorrectly identify `(someMatrix, someScalar)` as a
math operation between `someMatrix` and `someScalar` and attempt to
convert `someScalar` to a matrix. If `someScalar` was a Boolean type,
this would lead to an assertion.

The binary expression is now checked more thoroughly before converting
the scalar into a matrix.

Change-Id: Id7e104d5533d8c43375927d4815b83e1a3c36be1
Bug: skia:11125
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/410682
Auto-Submit: John Stiles <johnstiles@google.com>
Commit-Queue: Brian Osman <brianosman@google.com>
Reviewed-by: Brian Osman <brianosman@google.com>
diff --git a/src/sksl/codegen/SkSLMetalCodeGenerator.cpp b/src/sksl/codegen/SkSLMetalCodeGenerator.cpp
index 864acfc..91a0e41 100644
--- a/src/sksl/codegen/SkSLMetalCodeGenerator.cpp
+++ b/src/sksl/codegen/SkSLMetalCodeGenerator.cpp
@@ -1437,7 +1437,8 @@
     if (needParens) {
         this->write("(");
     }
-    bool needMatrixSplatOnScalar = rightType.isMatrix() && leftType.isScalar() &&
+    bool needMatrixSplatOnScalar = rightType.isMatrix() && leftType.isNumber() &&
+                                   op.isValidForMatrixOrVector() &&
                                    op.removeAssignment().kind() != Token::Kind::TK_STAR;
     if (needMatrixSplatOnScalar) {
         this->writeNumberAsMatrix(left, rightType);
@@ -1461,7 +1462,8 @@
         this->write(String(" ") + OperatorName(op) + " ");
     }
 
-    needMatrixSplatOnScalar = leftType.isMatrix() && rightType.isScalar() &&
+    needMatrixSplatOnScalar = leftType.isMatrix() && rightType.isNumber() &&
+                              op.isValidForMatrixOrVector() &&
                               op.removeAssignment().kind() != Token::Kind::TK_STAR;
     if (needMatrixSplatOnScalar) {
         this->writeNumberAsMatrix(right, leftType);