add font parameter to CanDrawAsDistanceFields

Bug: skia:
Change-Id: Ibb8ae6bcd43ffc768d5e1bf15790def6132739b0
Reviewed-on: https://skia-review.googlesource.com/c/174067
Reviewed-by: Mike Reed <reed@google.com>
Reviewed-by: Herb Derby <herb@google.com>
Commit-Queue: Mike Reed <reed@google.com>
diff --git a/src/core/SkGlyphRunPainter.cpp b/src/core/SkGlyphRunPainter.cpp
index 7c7fcd6..44337a8 100644
--- a/src/core/SkGlyphRunPainter.cpp
+++ b/src/core/SkGlyphRunPainter.cpp
@@ -710,7 +710,8 @@
 
         run->setRunFontAntiAlias(runPaint.isAntiAlias());
 
-        if (GrTextContext::CanDrawAsDistanceFields(runPaint, viewMatrix, props,
+        if (GrTextContext::CanDrawAsDistanceFields(runPaint,
+                                   SkFont::LEGACY_ExtractFromPaint(runPaint), viewMatrix, props,
                                     shaderCaps.supportsDistanceFieldText(), options)) {
             bool hasWCoord = viewMatrix.hasPerspective()
                              || options.fDistanceFieldVerticesAlwaysHaveW;
@@ -987,7 +988,8 @@
     options.fMinDistanceFieldFontSize = fSettings.fMinDistanceFieldFontSize;
     options.fMaxDistanceFieldFontSize = fSettings.fMaxDistanceFieldFontSize;
     GrTextContext::SanitizeOptions(&options);
-    if (!GrTextContext::CanDrawAsDistanceFields(runPaint, runMatrix, this->surfaceProps(),
+    if (!GrTextContext::CanDrawAsDistanceFields(runPaint, SkFont::LEGACY_ExtractFromPaint(runPaint),
+                                                runMatrix, this->surfaceProps(),
                                                 fSettings.fContextSupportsDistanceFieldText,
                                                 options)) {
         return false;
diff --git a/src/gpu/text/GrTextContext.cpp b/src/gpu/text/GrTextContext.cpp
index acb01d7..4e9b42b 100644
--- a/src/gpu/text/GrTextContext.cpp
+++ b/src/gpu/text/GrTextContext.cpp
@@ -91,13 +91,14 @@
     }
 }
 
-bool GrTextContext::CanDrawAsDistanceFields(const SkPaint& skPaint, const SkMatrix& viewMatrix,
+bool GrTextContext::CanDrawAsDistanceFields(const SkPaint& paint, const SkFont& font,
+                                            const SkMatrix& viewMatrix,
                                             const SkSurfaceProps& props,
                                             bool contextSupportsDistanceFieldText,
                                             const Options& options) {
     if (!viewMatrix.hasPerspective()) {
         SkScalar maxScale = viewMatrix.getMaxScale();
-        SkScalar scaledTextSize = maxScale * skPaint.getTextSize();
+        SkScalar scaledTextSize = maxScale * font.getSize();
         // Hinted text looks far better at small resolutions
         // Scaling up beyond 2x yields undesireable artifacts
         if (scaledTextSize < options.fMinDistanceFieldFontSize ||
@@ -116,12 +117,12 @@
     }
 
     // mask filters modify alpha, which doesn't translate well to distance
-    if (skPaint.getMaskFilter() || !contextSupportsDistanceFieldText) {
+    if (paint.getMaskFilter() || !contextSupportsDistanceFieldText) {
         return false;
     }
 
     // TODO: add some stroking support
-    if (skPaint.getStyle() != SkPaint::kFill_Style) {
+    if (paint.getStyle() != SkPaint::kFill_Style) {
         return false;
     }
 
diff --git a/src/gpu/text/GrTextContext.h b/src/gpu/text/GrTextContext.h
index 9e3819b..604f168 100644
--- a/src/gpu/text/GrTextContext.h
+++ b/src/gpu/text/GrTextContext.h
@@ -57,7 +57,7 @@
                                                    int y);
 
     static void SanitizeOptions(Options* options);
-    static bool CanDrawAsDistanceFields(const SkPaint& skPaint, const SkMatrix& viewMatrix,
+    static bool CanDrawAsDistanceFields(const SkPaint&, const SkFont&, const SkMatrix& viewMatrix,
                                         const SkSurfaceProps& props,
                                         bool contextSupportsDistanceFieldText,
                                         const Options& options);
diff --git a/tests/SkRemoteGlyphCacheTest.cpp b/tests/SkRemoteGlyphCacheTest.cpp
index 77b39ec..5127224 100644
--- a/tests/SkRemoteGlyphCacheTest.cpp
+++ b/tests/SkRemoteGlyphCacheTest.cpp
@@ -553,6 +553,7 @@
     SkStrikeServer server(discardableManager.get());
     SkStrikeClient client(discardableManager, false);
     SkPaint paint;
+    SkFont font;
 
     // A perspective transform forces fallback to dft.
     SkMatrix matrix = SkMatrix::I();
@@ -562,7 +563,7 @@
     GrTextContext::Options options;
     GrTextContext::SanitizeOptions(&options);
     REPORTER_ASSERT(reporter, GrTextContext::CanDrawAsDistanceFields(
-                                      paint, matrix, surfaceProps, true, options));
+                                      paint, font, matrix, surfaceProps, true, options));
 
     // Server.
     auto serverTf = SkTypeface::MakeFromName("monospace", SkFontStyle());