Have Renderer use combined path code

Currently, the GPU code uses the unified code path
in painter to draw. Have the remote glyph cache use it too.

Change-Id: Ibb1728a9602dbb3ace3a57781c5e7a20cdbe3cdf
Reviewed-on: https://skia-review.googlesource.com/157521
Reviewed-by: Mike Klein <mtklein@google.com>
Commit-Queue: Mike Klein <mtklein@google.com>
diff --git a/src/core/SkGlyphRunPainter.cpp b/src/core/SkGlyphRunPainter.cpp
index 5c147ec..3ac5ca4 100644
--- a/src/core/SkGlyphRunPainter.cpp
+++ b/src/core/SkGlyphRunPainter.cpp
@@ -595,10 +595,12 @@
             // Given a glyph that is not ARGB, draw it.
             auto perPath = [textScale, runIndex, cacheBlob, &pathCache]
                            (const SkGlyph& glyph, SkPoint position) {
-                const SkPath* path = pathCache->findPath(glyph);
-                if (path != nullptr) {
-                    cacheBlob->appendPathGlyph(
-                            runIndex, *path, position.fX, position.fY, textScale, false);
+                if (!glyph.isEmpty()) {
+                    const SkPath* path = pathCache->findPath(glyph);
+                    if (path != nullptr) {
+                        cacheBlob->appendPathGlyph(
+                                runIndex, *path, position.fX, position.fY, textScale, false);
+                    }
                 }
             };
 
diff --git a/src/core/SkGlyphRunPainter.h b/src/core/SkGlyphRunPainter.h
index 64f8444..2fd3126 100644
--- a/src/core/SkGlyphRunPainter.h
+++ b/src/core/SkGlyphRunPainter.h
@@ -175,15 +175,13 @@
             (SkGlyphID glyphID, SkPoint position) {
                 if (SkScalarsAreFinite(position.x(), position.y())) {
                     const SkGlyph& glyph = pathCache->getGlyphMetrics(glyphID, {0, 0});
-                    if (!glyph.isEmpty()) {
-                        if (glyph.fMaskFormat != SkMask::kARGB32_Format) {
-                            perPath(glyph, origin + position);
-                        } else {
-                            SkScalar largestDimension = std::max(glyph.fWidth, glyph.fHeight);
-                            maxFallbackDimension = std::max(maxFallbackDimension, largestDimension);
-                            fARGBGlyphsIDs.push_back(glyphID);
-                            fARGBPositions.push_back(position);
-                        }
+                    if (glyph.fMaskFormat != SkMask::kARGB32_Format) {
+                        perPath(glyph, origin + position);
+                    } else {
+                        SkScalar largestDimension = std::max(glyph.fWidth, glyph.fHeight);
+                        maxFallbackDimension = std::max(maxFallbackDimension, largestDimension);
+                        fARGBGlyphsIDs.push_back(glyphID);
+                        fARGBPositions.push_back(position);
                     }
                 }
             };
diff --git a/src/core/SkRemoteGlyphCache.cpp b/src/core/SkRemoteGlyphCache.cpp
index 24053ba..e28406e 100644
--- a/src/core/SkRemoteGlyphCache.cpp
+++ b/src/core/SkRemoteGlyphCache.cpp
@@ -182,7 +182,6 @@
     return cache->initializePath(glyph, path, pathSize);
 }
 
-#if SK_SUPPORT_GPU
 void add_glyph_to_cache(SkStrikeServer::SkGlyphCacheState* cache, SkTypeface* tf,
                         const SkScalerContextEffects& effects, SkGlyphID glyphID) {
     SkASSERT(cache != nullptr);
@@ -190,6 +189,7 @@
     cache->addGlyph(SkPackedGlyphID(glyphID, 0, 0), false);
 }
 
+#if SK_SUPPORT_GPU
 void add_fallback_text_to_cache(const GrTextContext::FallbackGlyphRunHelper& helper,
                                 const SkSurfaceProps& props,
                                 const SkMatrix& matrix,
@@ -272,7 +272,7 @@
     } else
     #endif
     if (SkDraw::ShouldDrawTextAsPaths(runPaint, runMatrix)) {
-        this->processGlyphRunForPaths(glyphRun, runMatrix);
+        this->processGlyphRunForPaths(glyphRun, runMatrix, origin);
     } else {
         this->processGlyphRunForMask(glyphRun, runMatrix, origin);
     }
@@ -306,43 +306,44 @@
 }
 
 void SkTextBlobCacheDiffCanvas::TrackLayerDevice::processGlyphRunForPaths(
-        const SkGlyphRun& glyphRun, const SkMatrix& runMatrix) {
+        const SkGlyphRun& glyphRun, const SkMatrix& runMatrix, SkPoint origin) {
     TRACE_EVENT0("skia", "SkTextBlobCacheDiffCanvas::processGlyphRunForPaths");
     const SkPaint& runPaint = glyphRun.paint();
+    SkPaint pathPaint{runPaint};
 
-    // The code below borrowed from GrTextContext::DrawBmpPosTextAsPaths.
-    SkPaint pathPaint(runPaint);
-#if SK_SUPPORT_GPU
-    SkScalar matrixScale = pathPaint.setupForAsPaths();
-    GrTextContext::FallbackGlyphRunHelper fallbackTextHelper(runMatrix, runPaint, matrixScale);
-#else
-    pathPaint.setupForAsPaths();
-#endif
+    SkScalar textScale = pathPaint.setupForAsPaths();
 
     SkScalerContextEffects effects;
     auto* glyphCacheState = fStrikeServer->getOrCreateCache(
             pathPaint, this->surfaceProps(), SkMatrix::I(),
             SkScalerContextFlags::kFakeGammaAndBoostContrast, &effects);
 
-    const bool asPath = true;
-    auto glyphs = glyphRun.shuntGlyphsIDs();
-    for (uint32_t index = 0; index < glyphRun.runSize(); index++) {
-        auto glyphID = glyphs[index];
-#if SK_SUPPORT_GPU
-        const auto& glyph = glyphCacheState->findGlyph(glyphID);
-        if (SkMask::kARGB32_Format == glyph.fMaskFormat) {
-            // Note that we send data for the original glyph even in the case of fallback
-            // since its glyph metrics will still be used on the client.
-            fallbackTextHelper.appendGlyph(glyph, glyphID, {0, 0});
-        }
-#endif
-        glyphCacheState->addGlyph(glyphID, asPath);
-    }
+    auto perPath = [glyphCacheState](const SkGlyph& glyph, SkPoint position) {
+        const bool asPath = true;
+        glyphCacheState->addGlyph(glyph.getGlyphID(), asPath);
+    };
 
-#if SK_SUPPORT_GPU
-    add_fallback_text_to_cache(fallbackTextHelper, this->surfaceProps(), runMatrix, runPaint,
-                               fStrikeServer);
-#endif
+    auto argbFallback = [this, &runMatrix]
+            (const SkPaint& fallbackPaint, SkSpan<const SkGlyphID> glyphIDs,
+             SkSpan<const SkPoint> positions, SkScalar textScale,
+             const SkMatrix& glyphCacheMatrix,
+             SkGlyphRunListPainter::NeedsTransform needsTransform) {
+        TRACE_EVENT0("skia", "argbFallback_path");
+        SkMatrix fallbackMatrix = runMatrix;
+
+        SkScalerContextEffects effects;
+        auto* glyphCacheState =
+                fStrikeServer->getOrCreateCache(
+                        fallbackPaint, surfaceProps(), fallbackMatrix,
+                        SkScalerContextFlags::kFakeGammaAndBoostContrast, &effects);
+
+        for (auto glyphID : glyphIDs) {
+            add_glyph_to_cache(glyphCacheState, fallbackPaint.getTypeface(), effects, glyphID);
+        }
+    };
+
+    fPainter.drawGlyphRunAsPathWithARGBFallback(
+            glyphCacheState, glyphRun, origin, runMatrix, textScale, perPath, argbFallback);
 }
 
 #if SK_SUPPORT_GPU
diff --git a/src/core/SkRemoteGlyphCacheImpl.h b/src/core/SkRemoteGlyphCacheImpl.h
index b5736c4..2800ca0 100644
--- a/src/core/SkRemoteGlyphCacheImpl.h
+++ b/src/core/SkRemoteGlyphCacheImpl.h
@@ -100,7 +100,8 @@
     void processGlyphRunForMask(
             const SkGlyphRun& glyphRun, const SkMatrix& runMatrix, SkPoint origin);
 
-    void processGlyphRunForPaths(const SkGlyphRun& glyphRun, const SkMatrix& runMatrix);
+    void processGlyphRunForPaths(
+            const SkGlyphRun& glyphRun, const SkMatrix& runMatrix, SkPoint origin);
 
 #if SK_SUPPORT_GPU
     bool maybeProcessGlyphRunForDFT(const SkGlyphRun& glyphRun, const SkMatrix& runMatrix);