SkScalerContextRec::computeMatrices to return status.

When computing the matricies for a scaler context, there is a special
case when the matrix is determined to be singular. No port properly
handles zero sized text, so we detect this case and return a 'normal'
text size and a zero matrix for all computed transformations. This
CL causes computeMatricies to return 'false' in this case.

This is used in the constructor of SkScalerContext_Mac in order to
avoid calling CGAffineTransformInvert on non-invertible transformations.
CGAffineTransformInvert documents that if the transform is
non-invertible it will return the passed transform unchanged. It does
so, but then also prints a message to stdout. Since the information is
already available to avoid this chatty behavior, use it to keep things
quiet.

BUG=skia:3231,chromium:630169
GOLD_TRYBOT_URL= https://gold.skia.org/search?issue=2276583003

Review-Url: https://codereview.chromium.org/2276583003
diff --git a/src/core/SkScalerContext.cpp b/src/core/SkScalerContext.cpp
index 85e8994..ecac82a 100644
--- a/src/core/SkScalerContext.cpp
+++ b/src/core/SkScalerContext.cpp
@@ -687,7 +687,7 @@
     m->postConcat(deviceMatrix);
 }
 
-void SkScalerContextRec::computeMatrices(PreMatrixScale preMatrixScale, SkVector* s, SkMatrix* sA,
+bool SkScalerContextRec::computeMatrices(PreMatrixScale preMatrixScale, SkVector* s, SkMatrix* sA,
                                          SkMatrix* GsA, SkMatrix* G_inv, SkMatrix* A_out)
 {
     // A is the 'total' matrix.
@@ -723,7 +723,7 @@
         if (G_inv) {
             G_inv->reset();
         }
-        return;
+        return false;
     }
 
     // GA is the matrix A with rotation removed.
@@ -803,6 +803,8 @@
          // G is rotational so reorders with the scale.
         GsA->preScale(SkScalarInvert(s->fX), SkScalarInvert(s->fY));
     }
+
+    return true;
 }
 
 SkAxisAlignment SkScalerContext::computeAxisAlignmentForHText() {
diff --git a/src/core/SkScalerContext.h b/src/core/SkScalerContext.h
index ffde83c..87d022a 100644
--- a/src/core/SkScalerContext.h
+++ b/src/core/SkScalerContext.h
@@ -146,8 +146,9 @@
      *  @param remainingWithoutRotation apply after scale to apply the total matrix sans rotation.
      *  @param remainingRotation apply after remainingWithoutRotation to apply the total matrix.
      *  @param total the total matrix.
+     *  @return false if the matrix was singular. The output will be valid but not invertable.
      */
-    void computeMatrices(PreMatrixScale preMatrixScale,
+    bool computeMatrices(PreMatrixScale preMatrixScale,
                          SkVector* scale, SkMatrix* remaining,
                          SkMatrix* remainingWithoutRotation = nullptr,
                          SkMatrix* remainingRotation = nullptr,
diff --git a/src/ports/SkFontHost_mac.cpp b/src/ports/SkFontHost_mac.cpp
index 842c5e6..93255df 100644
--- a/src/ports/SkFontHost_mac.cpp
+++ b/src/ports/SkFontHost_mac.cpp
@@ -807,10 +807,16 @@
     // As a result, it is necessary to know the actual device size and request that.
     SkVector scale;
     SkMatrix skTransform;
-    fRec.computeMatrices(SkScalerContextRec::kVertical_PreMatrixScale, &scale, &skTransform,
-                         nullptr, nullptr, &fFUnitMatrix);
+    bool invertable = fRec.computeMatrices(SkScalerContextRec::kVertical_PreMatrixScale,
+                                           &scale, &skTransform, nullptr, nullptr, &fFUnitMatrix);
     fTransform = MatrixToCGAffineTransform(skTransform);
-    fInvTransform = CGAffineTransformInvert(fTransform);
+    // CGAffineTransformInvert documents that if the transform is non-invertible it will return the
+    // passed transform unchanged. It does so, but then also prints a message to stdout. Avoid this.
+    if (invertable) {
+        fInvTransform = CGAffineTransformInvert(fTransform);
+    } else {
+        fInvTransform = fTransform;
+    }
 
     // The transform contains everything except the requested text size.
     // Some properties, like 'trak', are based on the text size (before applying the matrix).