Reland "Convert the CPU mask case to use prepareForDrawing"

This is a reland of c48879ed404c619adb59d5a1f10855042bf754b3

BUG=952629

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>

Change-Id: I382901e2a4cc186b206450cd4ae8058c6c0e2149
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/208042
Reviewed-by: Ben Wagner <bungeman@google.com>
Commit-Queue: Herb Derby <herb@google.com>
diff --git a/src/core/SkGlyph.h b/src/core/SkGlyph.h
index c2606d9..812b1c2 100644
--- a/src/core/SkGlyph.h
+++ b/src/core/SkGlyph.h
@@ -150,6 +150,11 @@
     // fImage, fPath, fID, fMaskFormat fields.
     void zeroMetrics();
 
+    bool hasImage() const {
+        SkASSERT(fMaskFormat != MASK_FORMAT_UNKNOWN);
+        return fImage != nullptr;
+    }
+
     SkMask mask() const;
 
     SkMask mask(SkPoint position) const;
diff --git a/src/core/SkGlyphRunPainter.cpp b/src/core/SkGlyphRunPainter.cpp
index 0d901cf..2708d6c 100644
--- a/src/core/SkGlyphRunPainter.cpp
+++ b/src/core/SkGlyphRunPainter.cpp
@@ -138,27 +138,6 @@
              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) {
@@ -237,30 +216,41 @@
                     SkSpan<const SkPathPos>{pathsAndPositions.begin(), pathsAndPositions.size()},
                     textScale, pathPaint);
         } else {
-            auto cache = SkStrikeCache::FindOrCreateStrikeExclusive(
-                                        runFont, runPaint, props,
-                                        fScalerContextFlags, deviceMatrix);
+            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);
 
             // Add rounding and origin.
             SkMatrix matrix = deviceMatrix;
             matrix.preTranslate(origin.x(), origin.y());
-            SkPoint rounding = cache->rounding();
+            SkPoint rounding = strike->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(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));
-                    }
+            masks.setReserve(glyphPosSpan.size());
+
+            for (const SkGlyphPos& glyphPos : glyphPosSpan) {
+                const SkGlyph& glyph = *glyphPos.glyph;
+                SkPoint position = glyphPos.position;
+                // The glyph could have dimensions (!isEmpty()), but still may have no bits if
+                // the width is too wide. So check that there really is an image.
+                if (check_glyph_position(position) && !glyph.isEmpty() && glyph.hasImage()) {
+                    masks.push_back(glyph.mask(position));
                 }
             }
+
             bitmapDevice->paintMasks(SkSpan<const SkMask>{masks.begin(), masks.size()}, runPaint);
         }
     }
diff --git a/src/core/SkStrike.cpp b/src/core/SkStrike.cpp
index 20bb221..f7919d3 100644
--- a/src/core/SkStrike.cpp
+++ b/src/core/SkStrike.cpp
@@ -248,11 +248,9 @@
             if (!glyph.isEmpty()) {
                 result[drawableGlyphCount++] = {i, &glyph, position};
                 if (glyph.maxDimension() <= maxDimension) {
-
                     // Glyph fits in the atlas, good to go.
                     this->findImage(glyph);
                 } else if (glyph.fMaskFormat != SkMask::kARGB32_Format) {
-
                     // The out of atlas glyph is not color so we can draw it using paths.
                     this->findPath(glyph);
                 } else {