Revert of CL/192440 which would not reland cleanly.

This is a revert of the following revert...

This reverts commit b5c1a79b55cb1ac83e2eb8210135a7ceec2c5b44.

Reason for revert: Based on bad CL 192424

Original change's description:
> Calculate strike in path case
>
> Change-Id: I9036b23df7279003a41f6189117fb7dec784ee2a
> Reviewed-on: https://skia-review.googlesource.com/c/192440
> Reviewed-by: Mike Klein <mtklein@google.com>
> Commit-Queue: Herb Derby <herb@google.com>

Change-Id: I322c45b6deb9ffa4cde567f02c55fcd6971fefc1
Reviewed-on: https://skia-review.googlesource.com/c/192882
Commit-Queue: Herb Derby <herb@google.com>
Commit-Queue: Ben Wagner <bungeman@google.com>
Auto-Submit: Herb Derby <herb@google.com>
Reviewed-by: Ben Wagner <bungeman@google.com>
diff --git a/src/core/SkGlyphRunPainter.cpp b/src/core/SkGlyphRunPainter.cpp
index 485a46c..2dc69c35 100644
--- a/src/core/SkGlyphRunPainter.cpp
+++ b/src/core/SkGlyphRunPainter.cpp
@@ -332,60 +332,76 @@
 
 // Beware! The following code will end up holding two glyph caches at the same time, but they
 // will not be the same cache (which would cause two separate caches to be created).
-template <typename ProcessPathsT>
+template <typename ProcessPathsT, typename CreatorT>
 void SkGlyphRunListPainter::drawGlyphRunAsPathWithARGBFallback(
-        SkStrikeInterface* strike, const SkGlyphRun& glyphRun,
-        SkPoint origin, const SkPaint& runPaint, const SkMatrix& viewMatrix, SkScalar textScale,
+        const SkPaint& runPaint, const SkFont& runFont, CreatorT&& strikeCreator,
+        const SkGlyphRun& glyphRun, SkPoint origin, const SkMatrix& viewMatrix,
         ProcessPathsT&& processPaths, ARGBFallback&& argbFallback) {
     fARGBGlyphsIDs.clear();
     fARGBPositions.clear();
     ScopedBuffers _ = ensureBuffers(glyphRun);
     SkScalar maxFallbackDimension{-SK_ScalarInfinity};
 
-    // Four empty glyphs are expected; one for each horizontal subpixel position.
-    SkSTArray<4, const SkGlyph*> emptyGlyphs;
+    // setup our std runPaint, in hopes of getting hits in the cache
+    SkPaint pathPaint{runPaint};
+    SkFont pathFont{runFont};
 
-    int glyphCount = 0;
-    const SkPoint* positionCursor = glyphRun.positions().data();
-    for (auto glyphID : glyphRun.glyphsIDs()) {
-        SkPoint glyphPos = origin + *positionCursor++;
+    // The factor to get from the size stored in the strike to the size needed for the source.
+    SkScalar strikeToSourceRatio = pathFont.setupForAsPaths(&pathPaint);
 
-        if (std::any_of(emptyGlyphs.begin(), emptyGlyphs.end(),
-                        [glyphID](const SkGlyph* g) { return g->getGlyphID() == glyphID; })) {
-            continue;
-        }
+    SkAutoDescriptor ad;
+    SkScalerContextEffects effects;
+    SkScalerContext::CreateDescriptorAndEffectsUsingPaint(
+            pathFont, pathPaint, fDeviceProps, fScalerContextFlags, SkMatrix::I(), &ad, &effects);
 
-        // Use outline from {0, 0} because all transforms including subpixel translation happen
-        // during drawing.
-        const SkGlyph& glyph = strike->getGlyphMetrics(glyphID, {0, 0});
-        if (glyph.isEmpty()) {
-            emptyGlyphs.push_back(&glyph);
-        } else if (glyph.fMaskFormat != SkMask::kARGB32_Format) {
-            if (strike->decideCouldDrawFromPath(glyph)) {
-                fGlyphPos[glyphCount++] = {&glyph, glyphPos};
-            } else {
-                // This happens when a bitmap-only font is forced to scale very large. This
-                // doesn't happen in practice.
-                emptyGlyphs.push_back(&glyph);
+    {
+        SkScopedStrike strike = strikeCreator(*ad.getDesc(), effects,
+                                              *pathFont.getTypefaceOrDefault());
+
+        // Four empty glyphs are expected; one for each horizontal subpixel position.
+        SkSTArray<4, const SkGlyph*> emptyGlyphs;
+
+        int glyphCount = 0;
+        const SkPoint* positionCursor = glyphRun.positions().data();
+        for (auto glyphID : glyphRun.glyphsIDs()) {
+            SkPoint glyphPos = origin + *positionCursor++;
+
+            if (std::any_of(emptyGlyphs.begin(), emptyGlyphs.end(),
+                            [glyphID](const SkGlyph* g) { return g->getGlyphID() == glyphID; })) {
+                continue;
             }
-        } else {
-            SkScalar largestDimension = std::max(glyph.fWidth, glyph.fHeight);
-            maxFallbackDimension = std::max(maxFallbackDimension, largestDimension);
-            fARGBGlyphsIDs.push_back(glyphID);
-            fARGBPositions.push_back(glyphPos);
+
+            // Use outline from {0, 0} because all transforms including subpixel translation happen
+            // during drawing.
+            const SkGlyph& glyph = strike->getGlyphMetrics(glyphID, {0, 0});
+            if (glyph.isEmpty()) {
+                emptyGlyphs.push_back(&glyph);
+            } else if (glyph.fMaskFormat != SkMask::kARGB32_Format) {
+                if (strike->decideCouldDrawFromPath(glyph)) {
+                    fGlyphPos[glyphCount++] = {&glyph, glyphPos};
+                } else {
+                    // This happens when a bitmap-only font is forced to scale very large. This
+                    // doesn't happen in practice.
+                    emptyGlyphs.push_back(&glyph);
+                }
+            } else {
+                SkScalar largestDimension = std::max(glyph.fWidth, glyph.fHeight);
+                maxFallbackDimension = std::max(maxFallbackDimension, largestDimension);
+                fARGBGlyphsIDs.push_back(glyphID);
+                fARGBPositions.push_back(glyphPos);
+            }
+        }
+
+        if (glyphCount > 0) {
+            processPaths(SkSpan<const GlyphAndPos>{fGlyphPos, SkTo<size_t>(glyphCount)},
+                         strike.get(),
+                         strikeToSourceRatio);
         }
     }
 
-    if (glyphCount > 0) {
-        processPaths(SkSpan<const GlyphAndPos>{fGlyphPos, SkTo<size_t>(glyphCount)},
-                    strike,
-                    textScale);
-    }
-
-
     if (!fARGBGlyphsIDs.empty()) {
         this->processARGBFallback(
-                maxFallbackDimension, runPaint, glyphRun.font(), viewMatrix, textScale,
+                maxFallbackDimension, runPaint, glyphRun.font(), viewMatrix, strikeToSourceRatio,
                 std::move(argbFallback));
 
     }
@@ -825,15 +841,6 @@
             // Ensure the blob is set for bitmaptext
             this->setHasBitmap();
 
-            // setup our std runPaint, in hopes of getting hits in the cache
-            SkPaint pathPaint{runPaint};
-            SkFont pathFont{runFont};
-            SkScalar textScale = pathFont.setupForAsPaths(&pathPaint);
-
-            auto pathCache = SkStrikeCache::FindOrCreateStrikeExclusive(
-                                pathFont, pathPaint, props,
-                                scalerContextFlags, SkMatrix::I());
-
             // Given a glyph that is not ARGB, draw it.
             auto processPath = [run](
                     SkSpan<const SkGlyphRunListPainter::GlyphAndPos> paths,
@@ -848,9 +855,19 @@
 
             ARGBFallbackHelper argbFallback{this, run, props, scalerContextFlags, glyphCache};
 
+            auto strikeCache = SkStrikeCache::GlobalStrikeCache();
+
+            auto creator = [strikeCache]
+                    (const SkDescriptor& desc,
+                     SkScalerContextEffects effects,
+                     const SkTypeface& typeface) {
+                return strikeCache->findOrCreateScopedStrike(desc, effects, typeface);
+            };
+
             glyphPainter->drawGlyphRunAsPathWithARGBFallback(
-                pathCache.get(), glyphRun, origin, runPaint, viewMatrix, textScale,
-                std::move(processPath), std::move(argbFallback));
+                    runPaint, runFont, std::move(creator),
+                    glyphRun, origin, viewMatrix,
+                    std::move(processPath), std::move(argbFallback));
         } else {
             // Ensure the blob is set for bitmaptext
             this->setHasBitmap();
@@ -1025,14 +1042,10 @@
         SkPoint origin, const SkPaint& runPaint) {
     TRACE_EVENT0("skia", "SkTextBlobCacheDiffCanvas::processGlyphRunForPaths");
 
-    SkPaint pathPaint{runPaint};
-    SkFont pathFont{glyphRun.font()};
-    SkScalar textScale = SetupForPath(&pathPaint, &pathFont);
-
-    SkScalerContextEffects effects;
-    auto* glyphCacheState = fStrikeServer->getOrCreateCache(
-            pathPaint, pathFont, this->surfaceProps(), SkMatrix::I(),
-            SkScalerContextFlags::kFakeGammaAndBoostContrast, &effects);
+    auto creator = [this]
+            (const SkDescriptor& desc, SkScalerContextEffects effects, const SkTypeface& typeface) {
+        return SkScopedStrike{fStrikeServer->getOrCreateCache(desc, typeface, effects)};
+    };
 
     // This processor is empty because all changes to the cache are tracked through
     // getGlyphMetrics and decideCouldDrawFromPath.
@@ -1042,7 +1055,8 @@
     ARGBHelper argbFallback{runMatrix, surfaceProps(), fStrikeServer};
 
     fPainter.drawGlyphRunAsPathWithARGBFallback(
-            glyphCacheState, glyphRun, origin, runPaint, runMatrix, textScale,
+            runPaint, glyphRun.font(), std::move(creator),
+            glyphRun, origin, runMatrix,
             std::move(processPaths), std::move(argbFallback));
 }
 
diff --git a/src/core/SkGlyphRunPainter.h b/src/core/SkGlyphRunPainter.h
index f6417a6..ab9f000 100644
--- a/src/core/SkGlyphRunPainter.h
+++ b/src/core/SkGlyphRunPainter.h
@@ -131,10 +131,10 @@
     // For each glyph that is not ARGB call perPath. If the glyph is ARGB then store the glyphID
     // and the position in fallback vectors. After all the glyphs are processed, pass the
     // fallback glyphIDs and positions to fallbackARGB.
-    template <typename ProcessPathsT>
+    template <typename ProcessPathsT, typename CreatorT>
     void drawGlyphRunAsPathWithARGBFallback(
-            SkStrikeInterface* cache, const SkGlyphRun& glyphRun,
-            SkPoint origin, const SkPaint& paint, const SkMatrix& viewMatrix, SkScalar textScale,
+            const SkPaint& runPaint, const SkFont& runFont, CreatorT&& strikeCreator,
+            const SkGlyphRun& glyphRun, SkPoint origin, const SkMatrix& viewMatrix,
             ProcessPathsT&& processPaths, ARGBFallback&& fallbackARGB);
 
     template <typename PerEmptyT, typename PerSDFT, typename PerPathT>