Revert "Convert the CPU mask case to use prepareForDrawing"

This reverts commit c48879ed404c619adb59d5a1f10855042bf754b3.

Reason for revert: Regresses on fuzzer because it doesn't handle glyphs wider than 32K correctly

Original change's description:
> Convert the CPU mask case to use prepareForDrawing
>
> Change-Id: I3a36084544e12730f4815dbf5b6c78a1cd719f1b
> Reviewed-on: https://skia-review.googlesource.com/c/skia/+/207761
> Reviewed-by: Ben Wagner <bungeman@google.com>
> Commit-Queue: Herb Derby <herb@google.com>

TBR=bungeman@google.com,herb@google.com

Change-Id: I046f24fd541dd121b8fa65ff5811c3055a28215d
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/208041
Commit-Queue: Herb Derby <herb@google.com>
Reviewed-by: Herb Derby <herb@google.com>
diff --git a/src/core/SkGlyphRunPainter.cpp b/src/core/SkGlyphRunPainter.cpp
index 4dc8d8f..0d901cf 100644
--- a/src/core/SkGlyphRunPainter.cpp
+++ b/src/core/SkGlyphRunPainter.cpp
@@ -138,6 +138,27 @@
              lt(position.fY, INT_MIN - (INT16_MIN + 0 /*UINT16_MIN*/)));
 }
 
+static SkMask create_mask(const SkGlyph& glyph, SkPoint position, const void* image) {
+    SkMask mask;
+    int left = SkScalarFloorToInt(position.fX);
+    int top  = SkScalarFloorToInt(position.fY);
+
+    left += glyph.fLeft;
+    top  += glyph.fTop;
+
+    int right   = left + glyph.fWidth;
+    int bottom  = top  + glyph.fHeight;
+
+    mask.fBounds.set(left, top, right, bottom);
+    SkASSERT(!mask.fBounds.isEmpty());
+
+    mask.fImage    = (uint8_t*)image;
+    mask.fRowBytes = glyph.rowBytes();
+    mask.fFormat   = static_cast<SkMask::Format>(glyph.fMaskFormat);
+
+    return mask;
+}
+
 void SkGlyphRunListPainter::drawForBitmapDevice(
         const SkGlyphRunList& glyphRunList, const SkMatrix& deviceMatrix,
         const BitmapDevicePainter* bitmapDevice) {
@@ -216,39 +237,30 @@
                     SkSpan<const SkPathPos>{pathsAndPositions.begin(), pathsAndPositions.size()},
                     textScale, pathPaint);
         } else {
-            SkAutoDescriptor ad;
-            SkScalerContextEffects effects;
-
-            SkScalerContext::CreateDescriptorAndEffectsUsingPaint(
-                    runFont, runPaint, props, fScalerContextFlags, deviceMatrix, &ad,
-                    &effects);
-
-            SkTypeface* typeface = runFont.getTypefaceOrDefault();
-            SkScopedStrike strike =
-                    fStrikeCache->findOrCreateScopedStrike(*ad.getDesc(), effects, *typeface);
+            auto cache = SkStrikeCache::FindOrCreateStrikeExclusive(
+                                        runFont, runPaint, props,
+                                        fScalerContextFlags, deviceMatrix);
 
             // Add rounding and origin.
             SkMatrix matrix = deviceMatrix;
             matrix.preTranslate(origin.x(), origin.y());
-            SkPoint rounding = strike->rounding();
+            SkPoint rounding = cache->rounding();
             matrix.postTranslate(rounding.x(), rounding.y());
             matrix.mapPoints(fPositions, glyphRun.positions().data(), runSize);
 
-            SkSpan<const SkGlyphPos> glyphPosSpan = strike->prepareForDrawing(
-                    glyphRun.glyphsIDs().data(), fPositions, glyphRun.runSize(),
-                    std::numeric_limits<int>::max(), fGlyphPos);
-
             SkTDArray<SkMask> masks;
-            masks.setReserve(glyphPosSpan.size());
-
-            for (const SkGlyphPos& glyphPos : glyphPosSpan) {
-                const SkGlyph& glyph = *glyphPos.glyph;
-                SkPoint position = glyphPos.position;
-                if (check_glyph_position(position) && !glyph.isEmpty()) {
-                    masks.push_back(glyph.mask(position));
+            masks.setReserve(runSize);
+            const SkPoint* positionCursor = fPositions;
+            for (auto glyphID : glyphRun.glyphsIDs()) {
+                auto position = *positionCursor++;
+                if (check_glyph_position(position)) {
+                    const SkGlyph& glyph = cache->getGlyphMetrics(glyphID, position);
+                    const void* image;
+                    if (!glyph.isEmpty() && (image = cache->findImage(glyph))) {
+                        masks.push_back(create_mask(glyph, position, image));
+                    }
                 }
             }
-
             bitmapDevice->paintMasks(SkSpan<const SkMask>{masks.begin(), masks.size()}, runPaint);
         }
     }