Draw perspective text as paths.

Perspective glyphs can vary in screen size so it's unclear which SDF
level is best, and even if we choose one for an entire subrun it's
possible that a given glyph will have artifacts if it's too big.
Instead we fall back to paths.

Bug: skia:9515
Change-Id: I88f03b25651df0222459f5dbd03eee9465b97487
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/247437
Commit-Queue: Herb Derby <herb@google.com>
Reviewed-by: Jim Van Verth <jvanverth@google.com>
diff --git a/src/core/SkStrikeSpec.cpp b/src/core/SkStrikeSpec.cpp
index 65adf83..79ff872 100644
--- a/src/core/SkStrikeSpec.cpp
+++ b/src/core/SkStrikeSpec.cpp
@@ -181,6 +181,7 @@
                        const SkSurfaceProps& surfaceProps, const SkMatrix& deviceMatrix,
                        const GrTextContext::Options& options) {
     SkStrikeSpec storage;
+    SkASSERT(!deviceMatrix.hasPerspective());
 
     SkPaint dfPaint = GrTextContext::InitDistanceFieldPaint(paint);
     SkFont dfFont = GrTextContext::InitDistanceFieldFont(
diff --git a/src/gpu/text/GrTextContext.cpp b/src/gpu/text/GrTextContext.cpp
index 6d8151c..2f7b5bf 100644
--- a/src/gpu/text/GrTextContext.cpp
+++ b/src/gpu/text/GrTextContext.cpp
@@ -95,24 +95,8 @@
                                             const SkSurfaceProps& props,
                                             bool contextSupportsDistanceFieldText,
                                             const Options& options) {
-    if (!viewMatrix.hasPerspective()) {
-        SkScalar maxScale = viewMatrix.getMaxScale();
-        SkScalar scaledTextSize = maxScale * font.getSize();
-        // Hinted text looks far better at small resolutions
-        // Scaling up beyond 2x yields undesireable artifacts
-        if (scaledTextSize < options.fMinDistanceFieldFontSize ||
-            scaledTextSize > options.fMaxDistanceFieldFontSize) {
-            return false;
-        }
-
-        bool useDFT = props.isUseDeviceIndependentFonts();
-#if SK_FORCE_DISTANCE_FIELD_TEXT
-        useDFT = true;
-#endif
-
-        if (!useDFT && scaledTextSize < kLargeDFFontSize) {
-            return false;
-        }
+    if (viewMatrix.hasPerspective()) {
+        return false;
     }
 
     // mask filters modify alpha, which doesn't translate well to distance
@@ -125,24 +109,38 @@
         return false;
     }
 
+    SkScalar maxScale = viewMatrix.getMaxScale();
+    SkScalar scaledTextSize = maxScale * font.getSize();
+    // Hinted text looks far better at small resolutions
+    // Scaling up beyond 2x yields undesirable artifacts
+    if (scaledTextSize < options.fMinDistanceFieldFontSize ||
+        scaledTextSize > options.fMaxDistanceFieldFontSize) {
+        return false;
+    }
+
+    bool useDFT = props.isUseDeviceIndependentFonts();
+#if SK_FORCE_DISTANCE_FIELD_TEXT
+    useDFT = true;
+#endif
+
+    if (!useDFT && scaledTextSize < kLargeDFFontSize) {
+        return false;
+    }
+
     return true;
 }
 
 SkScalar scaled_text_size(const SkScalar textSize, const SkMatrix& viewMatrix) {
+    SkASSERT(!viewMatrix.hasPerspective());
+
     SkScalar scaledTextSize = textSize;
 
-    if (viewMatrix.hasPerspective()) {
-        // for perspective, we simply force to the medium size
-        // TODO: compute a size based on approximate screen area
-        scaledTextSize = kMediumDFFontLimit;
-    } else {
-        SkScalar maxScale = viewMatrix.getMaxScale();
-        // if we have non-unity scale, we need to choose our base text size
-        // based on the SkPaint's text size multiplied by the max scale factor
-        // TODO: do we need to do this if we're scaling down (i.e. maxScale < 1)?
-        if (maxScale > 0 && !SkScalarNearlyEqual(maxScale, SK_Scalar1)) {
-            scaledTextSize *= maxScale;
-        }
+    SkScalar maxScale = viewMatrix.getMaxScale();
+    // if we have non-unity scale, we need to choose our base text size
+    // based on the SkPaint's text size multiplied by the max scale factor
+    // TODO: do we need to do this if we're scaling down (i.e. maxScale < 1)?
+    if (maxScale > 0 && !SkScalarNearlyEqual(maxScale, SK_Scalar1)) {
+        scaledTextSize *= maxScale;
     }
 
     return scaledTextSize;
diff --git a/tests/SkRemoteGlyphCacheTest.cpp b/tests/SkRemoteGlyphCacheTest.cpp
index 92e1fec..7ffc68a 100644
--- a/tests/SkRemoteGlyphCacheTest.cpp
+++ b/tests/SkRemoteGlyphCacheTest.cpp
@@ -678,10 +678,8 @@
     SkPaint paint;
     SkFont font;
 
-    // A perspective transform forces fallback to dft.
-    SkMatrix matrix = SkMatrix::I();
-    matrix[SkMatrix::kMPersp0] = 0.5f;
-    REPORTER_ASSERT(reporter, matrix.hasPerspective());
+    // A scale transform forces fallback to dft.
+    SkMatrix matrix = SkMatrix::MakeScale(16);
     SkSurfaceProps surfaceProps(0, kUnknown_SkPixelGeometry);
     GrTextContext::Options options;
     GrTextContext::SanitizeOptions(&options);