Reduce scaling of large SDF glyphs on Mac.

It appears that the Mac glyph rasterizer doesn't work well with our
AA-based SDF generator -- the SDFs produced have more aliasing than
expected. This CL changes the Mac to use 256 as its highest SDF size,
and only scale down from there.

More work may need to be done -- the best solution may be to generate
the SDFs directly from the path rather than the rasterized glyph.

Bug: 1003270
Change-Id: I7f11620a5628b6c1095b02d588d5026bf5a924e8
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/254636
Reviewed-by: Herb Derby <herb@google.com>
Reviewed-by: Ben Wagner <bungeman@google.com>
Commit-Queue: Jim Van Verth <jvanverth@google.com>
diff --git a/gm/fontregen.cpp b/gm/fontregen.cpp
index 3addd80..8714815 100644
--- a/gm/fontregen.cpp
+++ b/gm/fontregen.cpp
@@ -17,6 +17,7 @@
 #include "include/core/SkCanvas.h"
 #include "include/core/SkColor.h"
 #include "include/core/SkFont.h"
+#include "include/core/SkFontMgr.h"
 #include "include/core/SkFontStyle.h"
 #include "include/core/SkFontTypes.h"
 #include "include/core/SkPaint.h"
@@ -109,3 +110,48 @@
 //////////////////////////////////////////////////////////////////////////////
 
 DEF_GM(return new FontRegenGM())
+
+///////////////////////////////////////////////////////////////////////////////
+
+class BadAppleGM : public skiagm::GpuGM {
+
+    SkString onShortName() override { return SkString("badapple"); }
+
+    SkISize onISize() override { return {kSize, kSize}; }
+
+    void onOnceBeforeDraw() override {
+        this->setBGColor(SK_ColorWHITE);
+        auto fm = SkFontMgr::RefDefault();
+
+        static const SkString kTexts[] = {
+                SkString("Meet"),
+                SkString("iPad Pro"),
+        };
+
+        SkFont font;
+        font.setEdging(SkFont::Edging::kSubpixelAntiAlias);
+        font.setSubpixel(true);
+        font.setSize(256);
+
+        fBlobs[0] = make_blob(kTexts[0], font);
+        fBlobs[1] = make_blob(kTexts[1], font);
+    }
+
+    void onDraw(GrContext* context, GrRenderTargetContext*, SkCanvas* canvas) override {
+        SkPaint paint;
+        paint.setColor(0xFF111111);
+        canvas->drawTextBlob(fBlobs[0], 10, 260, paint);
+        canvas->drawTextBlob(fBlobs[1], 10, 500, paint);
+        context->flush();
+    }
+
+private:
+    static constexpr int kSize = 512;
+
+    sk_sp<SkTextBlob> fBlobs[3];
+    typedef GM INHERITED;
+};
+
+//////////////////////////////////////////////////////////////////////////////
+
+DEF_GM(return new BadAppleGM())
diff --git a/src/gpu/text/GrTextContext.cpp b/src/gpu/text/GrTextContext.cpp
index f1ecef4..76fa383 100644
--- a/src/gpu/text/GrTextContext.cpp
+++ b/src/gpu/text/GrTextContext.cpp
@@ -32,10 +32,16 @@
 static const int kMediumDFFontSize = 72;
 static const int kMediumDFFontLimit = 72;
 static const int kLargeDFFontSize = 162;
+#ifdef SK_BUILD_FOR_MAC
+static const int kLargeDFFontLimit = 162;
+static const int kExtraLargeDFFontSize = 256;
+#endif
 
 static const int kDefaultMinDistanceFieldFontSize = 18;
-#ifdef SK_BUILD_FOR_ANDROID
+#if defined(SK_BUILD_FOR_ANDROID)
 static const int kDefaultMaxDistanceFieldFontSize = 384;
+#elif defined(SK_BUILD_FOR_MAC)
+static const int kDefaultMaxDistanceFieldFontSize = kExtraLargeDFFontSize;
 #else
 static const int kDefaultMaxDistanceFieldFontSize = 2 * kLargeDFFontSize;
 #endif
@@ -167,10 +173,20 @@
     } else if (scaledTextSize <= kMediumDFFontLimit) {
         *textRatio = textSize / kMediumDFFontSize;
         dfFont.setSize(SkIntToScalar(kMediumDFFontSize));
+#ifdef SK_BUILD_FOR_MAC
+    } else if (scaledTextSize <= kLargeDFFontLimit) {
+        *textRatio = textSize / kLargeDFFontSize;
+        dfFont.setSize(SkIntToScalar(kLargeDFFontSize));
+    } else {
+        *textRatio = textSize / kExtraLargeDFFontSize;
+        dfFont.setSize(SkIntToScalar(kExtraLargeDFFontSize));
+    }
+#else
     } else {
         *textRatio = textSize / kLargeDFFontSize;
         dfFont.setSize(SkIntToScalar(kLargeDFFontSize));
     }
+#endif
 
     dfFont.setEdging(SkFont::Edging::kAntiAlias);
     dfFont.setForceAutoHinting(false);