Remove posText system from GrTextContext

Remove the drawPosText code stack, and all supporting code.

Change-Id: Ie6ee64d012d390911faeb3c486d66cac40497744
Reviewed-on: https://skia-review.googlesource.com/145533
Reviewed-by: Mike Klein <mtklein@google.com>
Commit-Queue: Herb Derby <herb@google.com>
diff --git a/src/core/SkRemoteGlyphCache.cpp b/src/core/SkRemoteGlyphCache.cpp
index 9aa43ad..8a3c459 100644
--- a/src/core/SkRemoteGlyphCache.cpp
+++ b/src/core/SkRemoteGlyphCache.cpp
@@ -175,23 +175,18 @@
 }
 
 void add_glyph_to_cache(SkStrikeServer::SkGlyphCacheState* cache, SkTypeface* tf,
-                        const SkScalerContextEffects& effects, const char** text) {
+                        const SkScalerContextEffects& effects, SkGlyphID glyphID) {
     SkASSERT(cache != nullptr);
-    SkASSERT(text != nullptr);
 
-    const uint16_t* ptr = *(const uint16_t**)text;
-    unsigned glyphID = *ptr;
-    ptr += 1;
-    *text = (const char*)ptr;
     cache->addGlyph(tf, effects, SkPackedGlyphID(glyphID, 0, 0), false);
 }
 
-void add_fallback_text_to_cache(const GrTextContext::FallbackTextHelper& helper,
+void add_fallback_text_to_cache(const GrTextContext::FallbackGlyphRunHelper& helper,
                                 const SkSurfaceProps& props,
                                 const SkMatrix& matrix,
                                 const SkPaint& origPaint,
                                 SkStrikeServer* server) {
-    if (!helper.fallbackText().count()) return;
+    if (helper.fallbackText().empty()) return;
 
     TRACE_EVENT0("skia", "add_fallback_text_to_cache");
     SkPaint fallbackPaint{origPaint};
@@ -204,10 +199,8 @@
             server->getOrCreateCache(fallbackPaint, &props, &fallbackMatrix,
                                      SkScalerContextFlags::kFakeGammaAndBoostContrast, &effects);
 
-    const char* text = helper.fallbackText().begin();
-    const char* stop = text + helper.fallbackText().count();
-    while (text < stop) {
-        add_glyph_to_cache(glyphCacheState, fallbackPaint.getTypeface(), effects, &text);
+    for (auto glyphID : helper.fallbackText()) {
+        add_glyph_to_cache(glyphCacheState, fallbackPaint.getTypeface(), effects, glyphID);
     }
 }
 #endif
@@ -343,7 +336,7 @@
         SkPaint pathPaint(runPaint);
 #if SK_SUPPORT_GPU
         SkScalar matrixScale = pathPaint.setupForAsPaths();
-        GrTextContext::FallbackTextHelper fallbackTextHelper(
+        GrTextContext::FallbackGlyphRunHelper fallbackTextHelper(
                 runMatrix, runPaint, glyph_size_limit(fSettings), matrixScale);
         const SkPoint emptyPosition{0, 0};
 #else
@@ -359,18 +352,16 @@
                 SkScalerContextFlags::kFakeGammaAndBoostContrast, &effects);
 
         const bool asPath = true;
-        const SkIPoint subPixelPos{0, 0};
-        const uint16_t* glyphs = it.glyphs();
+        const SkGlyphID* glyphs = it.glyphs();
         for (uint32_t index = 0; index < it.glyphCount(); index++) {
-            auto glyphID = SkPackedGlyphID(glyphs[index], subPixelPos.x(), subPixelPos.y());
+            auto glyphID = glyphs[index];
 #if SK_SUPPORT_GPU
             const auto& glyph =
                     glyphCacheState->findGlyph(runPaint.getTypeface(), effects, 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.appendText(glyph, sizeof(uint16_t), (const char*)&glyphs[index],
-                                              emptyPosition);
+                fallbackTextHelper.appendGlyph(glyph, glyphID, emptyPosition);
             }
 #endif
             glyphCacheState->addGlyph(runPaint.getTypeface(), effects, glyphID, asPath);
@@ -407,27 +398,25 @@
         auto* glyphCacheState = fStrikeServer->getOrCreateCache(dfPaint, &this->surfaceProps(),
                                                                 nullptr, flags, &effects);
 
-        GrTextContext::FallbackTextHelper fallbackTextHelper(
+        GrTextContext::FallbackGlyphRunHelper fallbackTextHelper(
                 runMatrix, runPaint, glyph_size_limit(fSettings), textRatio);
         const bool asPath = false;
-        const SkIPoint subPixelPos{0, 0};
         const SkPoint emptyPosition{0, 0};
         const uint16_t* glyphs = it.glyphs();
         for (uint32_t index = 0; index < it.glyphCount(); index++) {
-            auto glyphID = SkPackedGlyphID(glyphs[index], subPixelPos.x(), subPixelPos.y());
+            auto glyphID = glyphs[index];
             const auto& glyph =
                     glyphCacheState->findGlyph(runPaint.getTypeface(), effects, glyphID);
             if (glyph.fMaskFormat != SkMask::kSDF_Format) {
                 // 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.appendText(glyph, sizeof(uint16_t), (const char*)&glyphs[index],
-                                              emptyPosition);
+                fallbackTextHelper.appendGlyph(glyph, glyphID, emptyPosition);
             }
 
             glyphCacheState->addGlyph(
                     runPaint.getTypeface(),
                     effects,
-                    SkPackedGlyphID(glyphs[index], subPixelPos.x(), subPixelPos.y()),
+                    SkPackedGlyphID(glyphs[index]),
                     asPath);
         }
 
diff --git a/src/gpu/GrRenderTargetContext.cpp b/src/gpu/GrRenderTargetContext.cpp
index fd515c7..8c743b8 100644
--- a/src/gpu/GrRenderTargetContext.cpp
+++ b/src/gpu/GrRenderTargetContext.cpp
@@ -233,22 +233,6 @@
     return this->getRTOpList();
 }
 
-void GrRenderTargetContext::drawPosText(const GrClip& clip, const SkPaint& paint,
-                                        const SkMatrix& viewMatrix, const char text[],
-                                        size_t byteLength, const SkScalar pos[],
-                                        int scalarsPerPosition, const SkPoint& offset,
-                                        const SkIRect& clipBounds) {
-    ASSERT_SINGLE_OWNER
-    RETURN_IF_ABANDONED
-    SkDEBUGCODE(this->validate();)
-    GR_CREATE_TRACE_MARKER_CONTEXT("GrRenderTargetContext", "drawPosText", fContext);
-
-    GrTextContext* atlasTextContext = this->drawingManager()->getTextContext();
-    atlasTextContext->drawPosText(fContext, fTextTarget.get(), clip, paint, viewMatrix,
-                                  fSurfaceProps, text, byteLength, pos, scalarsPerPosition, offset,
-                                  clipBounds);
-}
-
 void GrRenderTargetContext::drawGlyphRunList(
         const GrClip& clip, const SkMatrix& viewMatrix,
         const SkGlyphRunList& blob, const SkIRect& clipBounds) {
diff --git a/src/gpu/GrRenderTargetContext.h b/src/gpu/GrRenderTargetContext.h
index 602ecc3..06473bb 100644
--- a/src/gpu/GrRenderTargetContext.h
+++ b/src/gpu/GrRenderTargetContext.h
@@ -59,15 +59,6 @@
 public:
     ~GrRenderTargetContext() override;
 
-    // We use SkPaint rather than GrPaint here for two reasons:
-    //    * The SkPaint carries extra text settings. If these were extracted to a lighter object
-    //      we could use GrPaint except that
-    //    * SkPaint->GrPaint conversion depends upon whether the glyphs are color or grayscale and
-    //      this can vary within a text run.
-    virtual void drawPosText(const GrClip&, const SkPaint&, const SkMatrix& viewMatrix,
-                             const char text[], size_t byteLength, const SkScalar pos[],
-                             int scalarsPerPosition, const SkPoint& offset,
-                             const SkIRect& clipBounds);
     virtual void drawGlyphRunList(const GrClip&,
                                   const SkMatrix& viewMatrix, const SkGlyphRunList&,
                                   const SkIRect& clipBounds);
diff --git a/src/gpu/SkGpuDevice.cpp b/src/gpu/SkGpuDevice.cpp
index 0686d61..2b2f01d 100644
--- a/src/gpu/SkGpuDevice.cpp
+++ b/src/gpu/SkGpuDevice.cpp
@@ -1630,13 +1630,6 @@
                               const SkPoint& offset, const SkPaint& paint) {
 
     SK_ABORT("Oh no!!! There is not drawPosText for GPU device anymore!");
-    ASSERT_SINGLE_OWNER
-    GR_CREATE_TRACE_MARKER_CONTEXT("SkGpuDevice", "drawPosText", fContext.get());
-    SkDEBUGCODE(this->validate();)
-
-    fRenderTargetContext->drawPosText(this->clip(), paint, this->ctm(), (const char*)text,
-                                      byteLength, pos, scalarsPerPos, offset,
-                                      this->devClipBounds());
 }
 
 void SkGpuDevice::drawGlyphRunList(const SkGlyphRunList& glyphRunList) {
diff --git a/src/gpu/text/GrTextContext.cpp b/src/gpu/text/GrTextContext.cpp
index 93bd182..943ce8c 100644
--- a/src/gpu/text/GrTextContext.cpp
+++ b/src/gpu/text/GrTextContext.cpp
@@ -123,7 +123,7 @@
     SkPoint origin = glyphRunList.origin();
     cacheBlob->initReusableBlob(paint.luminanceColor(), viewMatrix, origin.x(), origin.y());
 
-    // Regenerate textblob
+    // Regenerate GrTextBlob
     GrTextUtils::RunPaint runPaint(&paint);
     int runIndex = 0;
     for (const auto& glyphRun : glyphRunList) {
@@ -186,13 +186,13 @@
 
                         } else {
                             // can't append non-SDF glyph to SDF batch, send to fallback
-                            fallbackTextHelper.appendText(glyph, glyphID, glyphPos);
+                            fallbackTextHelper.appendGlyph(glyph, glyphID, glyphPos);
                         }
                     }
                 }
             }
 
-            fallbackTextHelper.drawText(
+            fallbackTextHelper.drawGlyphs(
                     cacheBlob, runIndex, glyphCache, props, runPaint, scalerContextFlags);
 
         } else if (SkDraw::ShouldDrawTextAsPaths(runPaint, viewMatrix)) {
@@ -217,7 +217,7 @@
                     [&fallbackTextHelper, matrixScale, runIndex, cacheBlob]
                     (const SkPath* path, const SkGlyph& glyph, SkPoint position) {
                 if (glyph.fMaskFormat == SkMask::kARGB32_Format) {
-                    fallbackTextHelper.appendText(glyph, glyph.getGlyphID(), position);
+                    fallbackTextHelper.appendGlyph(glyph, glyph.getGlyphID(), position);
                 } else {
                     if (path != nullptr) {
                         cacheBlob->appendPathGlyph(
@@ -228,7 +228,7 @@
 
             glyphDrawer->drawUsingPaths(glyphRun, origin, cache.get(), drawOnePath);
 
-            fallbackTextHelper.drawText(
+            fallbackTextHelper.drawGlyphs(
                     cacheBlob, runIndex, glyphCache, props, runPaint, scalerContextFlags);
 
         } else {
@@ -387,156 +387,6 @@
                      clip, viewMatrix, clipBounds, origin.x(), origin.y());
 }
 
-inline sk_sp<GrTextBlob>
-GrTextContext::makeDrawPosTextBlob(GrTextBlobCache* blobCache,
-                                   GrGlyphCache* glyphCache,
-                                   const GrShaderCaps& shaderCaps,
-                                   const GrTextUtils::Paint& paint,
-                                   SkScalerContextFlags scalerContextFlags,
-                                   const SkMatrix& viewMatrix,
-                                   const SkSurfaceProps& props,
-                                   const char text[], size_t byteLength,
-                                   const SkScalar pos[], int scalarsPerPosition, const
-                                   SkPoint& offset) const {
-    int glyphCount = paint.skPaint().countText(text, byteLength);
-    if (!glyphCount) {
-        return nullptr;
-    }
-
-    sk_sp<GrTextBlob> blob = blobCache->makeBlob(glyphCount, 1);
-    blob->initThrowawayBlob(viewMatrix, offset.x(), offset.y());
-    blob->setRunPaintFlags(0, paint.skPaint().getFlags());
-
-    if (CanDrawAsDistanceFields(paint, viewMatrix, props, shaderCaps.supportsDistanceFieldText(),
-                                fOptions)) {
-        this->drawDFPosText(blob.get(), 0, glyphCache, props, paint, scalerContextFlags, viewMatrix,
-                            text, byteLength, pos, scalarsPerPosition, offset);
-    } else {
-        DrawBmpPosText(blob.get(), 0, glyphCache, props, paint, scalerContextFlags, viewMatrix,
-                       text, byteLength, pos, scalarsPerPosition, offset);
-    }
-    return blob;
-}
-
-void GrTextContext::drawPosText(GrContext* context, GrTextUtils::Target* target,
-                                const GrClip& clip, const SkPaint& skPaint,
-                                const SkMatrix& viewMatrix, const SkSurfaceProps& props,
-                                const char text[], size_t byteLength, const SkScalar pos[],
-                                int scalarsPerPosition, const SkPoint& offset,
-                                const SkIRect& regionClipBounds) {
-    GrTextUtils::Paint paint(&skPaint, &target->colorSpaceInfo());
-    if (context->abandoned()) {
-        return;
-    }
-
-    auto glyphCache = context->contextPriv().getGlyphCache();
-    auto textBlobCache = context->contextPriv().getTextBlobCache();
-
-    sk_sp<GrTextBlob> blob(this->makeDrawPosTextBlob(
-            textBlobCache, glyphCache, *context->contextPriv().caps()->shaderCaps(), paint,
-            ComputeScalerContextFlags(target->colorSpaceInfo()), viewMatrix, props, text,
-            byteLength, pos, scalarsPerPosition, offset));
-    if (blob) {
-        blob->flush(target, props, fDistanceAdjustTable.get(), paint,
-                    clip, viewMatrix, regionClipBounds, offset.fX, offset.fY);
-    }
-}
-
-void GrTextContext::DrawBmpPosText(GrTextBlob* blob, int runIndex,
-                                   GrGlyphCache* glyphCache, const SkSurfaceProps& props,
-                                   const GrTextUtils::Paint& paint,
-                                   SkScalerContextFlags scalerContextFlags,
-                                   const SkMatrix& viewMatrix,
-                                   const char text[], size_t byteLength, const SkScalar pos[],
-                                   int scalarsPerPosition, const SkPoint& offset) {
-    SkASSERT(byteLength == 0 || text != nullptr);
-    SkASSERT(1 == scalarsPerPosition || 2 == scalarsPerPosition);
-
-    // nothing to draw
-    if (text == nullptr || byteLength == 0) {
-        return;
-    }
-
-    // Ensure the blob is set for bitmaptext
-    blob->setHasBitmap();
-
-    if (SkDraw::ShouldDrawTextAsPaths(paint, viewMatrix)) {
-        DrawBmpPosTextAsPaths(blob, runIndex, glyphCache, props, paint, scalerContextFlags,
-                              viewMatrix, text, byteLength, pos, scalarsPerPosition, offset);
-        return;
-    }
-
-    sk_sp<GrTextStrike> currStrike;
-    auto cache = blob->setupCache(runIndex, props, scalerContextFlags, paint, &viewMatrix);
-    SkFindAndPlaceGlyph::ProcessPosText(
-            paint.skPaint().getTextEncoding(), text, byteLength, offset, viewMatrix, pos,
-            scalarsPerPosition, cache.get(),
-            [&](const SkGlyph& glyph, SkPoint position, SkPoint rounding) {
-                position += rounding;
-                AppendGlyph(blob, runIndex, glyphCache, &currStrike,
-                               glyph, GrGlyph::kCoverage_MaskStyle,
-                               SkScalarFloorToScalar(position.fX),
-                               SkScalarFloorToScalar(position.fY),
-                               paint.filteredPremulColor(), cache.get(), SK_Scalar1, false);
-            });
-}
-
-void GrTextContext::DrawBmpPosTextAsPaths(GrTextBlob* blob, int runIndex,
-                                          GrGlyphCache* glyphCache,
-                                          const SkSurfaceProps& props,
-                                          const GrTextUtils::Paint& origPaint,
-                                          SkScalerContextFlags scalerContextFlags,
-                                          const SkMatrix& viewMatrix,
-                                          const char text[], size_t byteLength,
-                                          const SkScalar pos[], int scalarsPerPosition,
-                                          const SkPoint& offset) {
-    SkASSERT(1 == scalarsPerPosition || 2 == scalarsPerPosition);
-
-    // nothing to draw
-    if (text == nullptr || byteLength == 0) {
-        return;
-    }
-
-    // setup our std paint, in hopes of getting hits in the cache
-    SkPaint pathPaint(origPaint);
-    SkScalar matrixScale = pathPaint.setupForAsPaths();
-    FallbackTextHelper fallbackTextHelper(viewMatrix, origPaint, glyphCache->getGlyphSizeLimit(),
-                                          matrixScale);
-
-    // Temporarily jam in kFill, so we only ever ask for the raw outline from the cache.
-    pathPaint.setStyle(SkPaint::kFill_Style);
-    pathPaint.setPathEffect(nullptr);
-
-    SkPaint::GlyphCacheProc glyphCacheProc = SkPaint::GetGlyphCacheProc(pathPaint.getTextEncoding(),
-                                                                        true);
-    auto cache = SkStrikeCache::FindOrCreateStrikeExclusive(
-            pathPaint, &props, SkScalerContextFlags::kFakeGammaAndBoostContrast, nullptr);
-
-    const char*        stop = text + byteLength;
-    const char*        lastText = text;
-    SkTextMapStateProc tmsProc(SkMatrix::I(), offset, scalarsPerPosition);
-
-    while (text < stop) {
-        const SkGlyph& glyph = glyphCacheProc(cache.get(), &text, stop);
-        if (glyph.fWidth) {
-            SkPoint loc;
-            tmsProc(pos, &loc);
-            if (SkMask::kARGB32_Format == glyph.fMaskFormat) {
-                fallbackTextHelper.appendText(glyph, text - lastText, lastText, loc);
-            } else {
-                const SkPath* path = cache->findPath(glyph);
-                if (path) {
-                    blob->appendPathGlyph(runIndex, *path, loc.fX, loc.fY, matrixScale, false);
-                }
-            }
-        }
-        lastText = text;
-        pos += scalarsPerPosition;
-    }
-
-    fallbackTextHelper.drawText(blob, runIndex, glyphCache, props, origPaint, scalerContextFlags);
-}
-
 void GrTextContext::SanitizeOptions(Options* options) {
     if (options->fMaxDistanceFieldFontSize < 0.f) {
         options->fMaxDistanceFieldFontSize = kDefaultMaxDistanceFieldFontSize;
@@ -653,152 +503,9 @@
     *flags = SkScalerContextFlags::kNone;
 }
 
-void GrTextContext::drawDFPosText(GrTextBlob* blob, int runIndex,
-                                  GrGlyphCache* glyphCache, const SkSurfaceProps& props,
-                                  const GrTextUtils::Paint& paint,
-                                  SkScalerContextFlags scalerContextFlags,
-                                  const SkMatrix& viewMatrix, const char text[],
-                                  size_t byteLength, const SkScalar pos[],
-                                  int scalarsPerPosition, const SkPoint& offset) const {
-    SkASSERT(byteLength == 0 || text != nullptr);
-    SkASSERT(1 == scalarsPerPosition || 2 == scalarsPerPosition);
-
-    // nothing to draw
-    if (text == nullptr || byteLength == 0) {
-        return;
-    }
-
-    bool hasWCoord = viewMatrix.hasPerspective() || fOptions.fDistanceFieldVerticesAlwaysHaveW;
-
-    // Setup distance field paint and text ratio
-    SkScalar textRatio;
-    SkPaint dfPaint(paint);
-    SkScalerContextFlags flags;
-    InitDistanceFieldPaint(blob, &dfPaint, viewMatrix, fOptions, &textRatio, &flags);
-    blob->setHasDistanceField();
-    blob->setSubRunHasDistanceFields(runIndex, paint.skPaint().isLCDRenderText(),
-                                     paint.skPaint().isAntiAlias(), hasWCoord);
-
-    FallbackTextHelper fallbackTextHelper(viewMatrix, paint, glyphCache->getGlyphSizeLimit(),
-                                          textRatio);
-
-    sk_sp<GrTextStrike> currStrike;
-
-    {
-        auto cache = blob->setupCache(runIndex, props, flags, dfPaint, nullptr);
-        SkPaint::GlyphCacheProc glyphCacheProc =
-            SkPaint::GetGlyphCacheProc(dfPaint.getTextEncoding(), true);
-
-        const char* stop = text + byteLength;
-
-        while (text < stop) {
-            const char* lastText = text;
-            // the last 2 parameters are ignored
-            const SkGlyph& glyph = glyphCacheProc(cache.get(), &text, stop);
-
-            if (glyph.fWidth) {
-                SkPoint glyphPos(offset);
-                glyphPos.fX += pos[0];
-                glyphPos.fY += (2 == scalarsPerPosition ? pos[1] : 0);
-
-                if (glyph.fMaskFormat == SkMask::kSDF_Format) {
-                    AppendGlyph(blob, runIndex, glyphCache, &currStrike,
-                                   glyph, GrGlyph::kDistance_MaskStyle,
-                                   glyphPos.fX, glyphPos.fY, paint.filteredPremulColor(),
-                                   cache.get(), textRatio, true);
-                } else {
-                    // can't append non-SDF glyph to SDF batch, send to fallback
-                    fallbackTextHelper.appendText(glyph, SkToInt(text - lastText), lastText,
-                                                  glyphPos);
-                }
-            }
-            pos += scalarsPerPosition;
-        }
-    }
-
-    fallbackTextHelper.drawText(blob, runIndex, glyphCache, props, paint, scalerContextFlags);
-}
-
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 
-void GrTextContext::FallbackTextHelper::appendText(const SkGlyph& glyph, int count,
-                                                        const char* text, SkPoint glyphPos) {
-    SkScalar maxDim = SkTMax(glyph.fWidth, glyph.fHeight)*fTextRatio;
-    if (SkScalarNearlyZero(maxDim)) return;
-
-    if (!fUseTransformedFallback) {
-        if (!fViewMatrix.isScaleTranslate() || maxDim*fMaxScale > fMaxTextSize) {
-            fUseTransformedFallback = true;
-            fMaxTextSize -= 2;    // Subtract 2 to account for the bilerp pad around the glyph
-        }
-    }
-
-    fFallbackTxt.append(count, text);
-    if (fUseTransformedFallback) {
-        // If there's a glyph in the font that's particularly large, it's possible
-        // that fScaledFallbackTextSize may end up minimizing too much. We'd rather skip
-        // that glyph than make the others blurry, so we set a minimum size of half the
-        // maximum text size to avoid this case.
-        SkScalar glyphTextSize = SkTMax(SkScalarFloorToScalar(fTextSize * fMaxTextSize/maxDim),
-                                        0.5f*fMaxTextSize);
-        fTransformedFallbackTextSize = SkTMin(glyphTextSize, fTransformedFallbackTextSize);
-    }
-    *fFallbackPos.append() = glyphPos;
-}
-
-void GrTextContext::FallbackTextHelper::drawText(GrTextBlob* blob, int runIndex,
-                                                 GrGlyphCache* glyphCache,
-                                                 const SkSurfaceProps& props,
-                                                 const GrTextUtils::Paint& paint,
-                                                 SkScalerContextFlags scalerContextFlags) {
-    if (fFallbackTxt.count()) {
-        blob->initOverride(runIndex);
-        blob->setHasBitmap();
-        blob->setSubRunHasW(runIndex, fViewMatrix.hasPerspective());
-        SkExclusiveStrikePtr cache;
-        const SkPaint& skPaint = paint.skPaint();
-        SkPaint::GlyphCacheProc glyphCacheProc =
-            SkPaint::GetGlyphCacheProc(skPaint.getTextEncoding(), true);
-        SkColor textColor = paint.filteredPremulColor();
-
-        SkScalar textRatio = SK_Scalar1;
-        SkPaint fallbackPaint(skPaint);
-        SkMatrix matrix = fViewMatrix;
-        this->initializeForDraw(&fallbackPaint, &textRatio, &matrix);
-        cache = blob->setupCache(runIndex, props, scalerContextFlags, fallbackPaint, &matrix);
-
-        sk_sp<GrTextStrike> currStrike;
-        const char* text = fFallbackTxt.begin();
-        const char* stop = text + fFallbackTxt.count();
-        SkPoint* glyphPos = fFallbackPos.begin();
-        while (text < stop) {
-            const SkGlyph& glyph = glyphCacheProc(cache.get(), &text, stop);
-            if (!fUseTransformedFallback) {
-                fViewMatrix.mapPoints(glyphPos, 1);
-                glyphPos->fX = SkScalarFloorToScalar(glyphPos->fX);
-                glyphPos->fY = SkScalarFloorToScalar(glyphPos->fY);
-            }
-            GrTextContext::AppendGlyph(blob, runIndex, glyphCache, &currStrike,
-                                          glyph, GrGlyph::kCoverage_MaskStyle,
-                                          glyphPos->fX, glyphPos->fY, textColor,
-                                          cache.get(), textRatio, fUseTransformedFallback);
-            glyphPos++;
-        }
-    }
-}
-
-void GrTextContext::FallbackTextHelper::initializeForDraw(SkPaint* paint, SkScalar* textRatio,
-                                                          SkMatrix* matrix) const {
-    if (!fUseTransformedFallback) return;
-
-    paint->setTextSize(fTransformedFallbackTextSize);
-    *textRatio = fTextSize / fTransformedFallbackTextSize;
-    *matrix = SkMatrix::I();
-}
-
-///////////////////////////////////////////////////////////////////////////////////////////////////
-
-void GrTextContext::FallbackGlyphRunHelper::appendText(
+void GrTextContext::FallbackGlyphRunHelper::appendGlyph(
         const SkGlyph& glyph, SkGlyphID glyphID, SkPoint glyphPos) {
     SkScalar maxDim = SkTMax(glyph.fWidth, glyph.fHeight)*fTextRatio;
     if (SkScalarNearlyZero(maxDim)) return;
@@ -823,7 +530,7 @@
     fFallbackPos.push_back(glyphPos);
 }
 
-void GrTextContext::FallbackGlyphRunHelper::drawText(
+void GrTextContext::FallbackGlyphRunHelper::drawGlyphs(
         GrTextBlob* blob, int runIndex, GrGlyphCache* glyphCache, const SkSurfaceProps& props,
         const GrTextUtils::Paint& paint, SkScalerContextFlags scalerContextFlags) {
     if (!fFallbackTxt.empty()) {
@@ -890,26 +597,22 @@
 
     GrTextUtils::Paint utilsPaint(&skPaint, &rtc->colorSpaceInfo());
 
-    // right now we don't handle textblobs, nor do we handle drawPosText. Since we only intend to
-    // test the text op with this unit test, that is okay.
-
     auto origin = SkPoint::Make(x, y);
     SkGlyphRunBuilder builder;
     builder.drawText(skPaint, text, textLen, origin);
-    sk_sp<GrTextBlob> blob;
+
 
     auto glyphRunList = builder.useGlyphRunList();
+    sk_sp<GrTextBlob> blob;
     if (!glyphRunList.empty()) {
-        auto glyphRun = glyphRunList[0];
+        blob = context->contextPriv().getTextBlobCache()->makeBlob(glyphRunList);
         // Use the text and textLen below, because we don't want to mess with the paint.
-        glyphRun.temporaryShuntToCallback(
-            [&](size_t runSize, const char* glyphIDs, const SkScalar* pos) {
-                blob = textContext->makeDrawPosTextBlob(
-                    context->contextPriv().getTextBlobCache(), glyphCache,
-                    *context->contextPriv().caps()->shaderCaps(), utilsPaint,
-                    GrTextContext::kTextBlobOpScalerContextFlags, viewMatrix, surfaceProps,
-                    text, textLen, pos, 2, origin);
-            });
+        SkScalerContextFlags scalerContextFlags =
+                ComputeScalerContextFlags(rtc->colorSpaceInfo());
+        textContext->regenerateGlyphRunList(
+                blob.get(), glyphCache, *context->contextPriv().caps()->shaderCaps(), utilsPaint,
+                scalerContextFlags, viewMatrix, surfaceProps, glyphRunList,
+                rtc->textTarget()->glyphDrawer());
     }
 
     return blob->test_makeOp(textLen, 0, 0, viewMatrix, x, y, utilsPaint, surfaceProps,
diff --git a/src/gpu/text/GrTextContext.h b/src/gpu/text/GrTextContext.h
index 860691f..109fc9c 100644
--- a/src/gpu/text/GrTextContext.h
+++ b/src/gpu/text/GrTextContext.h
@@ -44,10 +44,6 @@
 
     static std::unique_ptr<GrTextContext> Make(const Options& options);
 
-    void drawPosText(GrContext*, GrTextUtils::Target*, const GrClip&, const SkPaint&,
-                     const SkMatrix& viewMatrix, const SkSurfaceProps&, const char text[],
-                     size_t byteLength, const SkScalar pos[], int scalarsPerPosition,
-                     const SkPoint& offset, const SkIRect& regionClipBounds);
     void drawGlyphRunList(GrContext*, GrTextUtils::Target*, const GrClip&,
                           const SkMatrix& viewMatrix, const SkSurfaceProps&, const SkGlyphRunList&,
                           const SkIRect& clipBounds);
@@ -73,41 +69,6 @@
                                        SkScalar* textRatio,
                                        SkScalerContextFlags* flags);
 
-    class FallbackTextHelper {
-    public:
-        FallbackTextHelper(const SkMatrix& viewMatrix,
-                           const SkPaint& pathPaint,
-                           SkScalar maxTextSize,
-                           SkScalar textRatio)
-                : fViewMatrix(viewMatrix)
-                , fTextSize(pathPaint.getTextSize())
-                , fMaxTextSize(maxTextSize)
-                , fTextRatio(textRatio)
-                , fTransformedFallbackTextSize(fMaxTextSize)
-                , fUseTransformedFallback(false) {
-            fMaxScale = viewMatrix.getMaxScale();
-        }
-
-        void appendText(const SkGlyph& glyph, int count, const char* text, SkPoint glyphPos);
-        void drawText(GrTextBlob* blob, int runIndex, GrGlyphCache*, const SkSurfaceProps&,
-                      const GrTextUtils::Paint&, SkScalerContextFlags);
-
-        void initializeForDraw(SkPaint* paint, SkScalar* textRatio, SkMatrix* matrix) const;
-        const SkTDArray<char>& fallbackText() const { return fFallbackTxt; }
-
-    private:
-        SkTDArray<char> fFallbackTxt;
-        SkTDArray<SkPoint> fFallbackPos;
-
-        const SkMatrix& fViewMatrix;
-        SkScalar fTextSize;
-        SkScalar fMaxTextSize;
-        SkScalar fTextRatio;
-        SkScalar fTransformedFallbackTextSize;
-        SkScalar fMaxScale;
-        bool fUseTransformedFallback;
-    };
-
     class FallbackGlyphRunHelper {
     public:
         FallbackGlyphRunHelper(const SkMatrix& viewMatrix,
@@ -123,9 +84,11 @@
             fMaxScale = viewMatrix.getMaxScale();
         }
 
-        void appendText(const SkGlyph& glyph, SkGlyphID, SkPoint glyphPos);
-        void drawText(GrTextBlob* blob, int runIndex, GrGlyphCache*, const SkSurfaceProps&,
-                      const GrTextUtils::Paint&, SkScalerContextFlags);
+        void appendGlyph(const SkGlyph& glyph, SkGlyphID glyphID, SkPoint glyphPos);
+        void drawGlyphs(
+                GrTextBlob* blob, int runIndex, GrGlyphCache* cache,
+                const SkSurfaceProps& props, const GrTextUtils::Paint& flags,
+                SkScalerContextFlags scalerContextFlags);
 
         void initializeForDraw(SkPaint* paint, SkScalar* textRatio, SkMatrix* matrix) const;
         const std::vector<SkGlyphID>& fallbackText() const { return fFallbackTxt; }
@@ -161,42 +124,6 @@
                             const SkGlyphRunList& glyphRunList,
                             SkGlyphRunListDrawer* glyphDrawer);
 
-    sk_sp<GrTextBlob> makeDrawPosTextBlob(GrTextBlobCache*, GrGlyphCache*,
-                                               const GrShaderCaps&,
-                                               const GrTextUtils::Paint&,
-                                               SkScalerContextFlags scalerContextFlags,
-                                               const SkMatrix& viewMatrix,
-                                               const SkSurfaceProps&,
-                                               const char text[], size_t byteLength,
-                                               const SkScalar pos[],
-                                               int scalarsPerPosition,
-                                               const SkPoint& offset) const;
-
-    // Functions for appending BMP text to GrTextBlob
-    static void DrawBmpPosText(GrTextBlob*, int runIndex, GrGlyphCache*,
-                               const SkSurfaceProps&, const GrTextUtils::Paint& paint,
-                               SkScalerContextFlags scalerContextFlags, const SkMatrix& viewMatrix,
-                               const char text[], size_t byteLength, const SkScalar pos[],
-                               int scalarsPerPosition, const SkPoint& offset);
-
-
-
-    static void DrawBmpPosTextAsPaths(GrTextBlob*, int runIndex, GrGlyphCache*,
-                                      const SkSurfaceProps&, const GrTextUtils::Paint& paint,
-                                      SkScalerContextFlags scalerContextFlags,
-                                      const SkMatrix& viewMatrix,
-                                      const char text[], size_t byteLength,
-                                      const SkScalar pos[], int scalarsPerPosition,
-                                      const SkPoint& offset);
-
-    // functions for appending distance field text
-    void drawDFPosText(GrTextBlob* blob, int runIndex, GrGlyphCache*,
-                       const SkSurfaceProps&, const GrTextUtils::Paint& paint,
-                       SkScalerContextFlags scalerContextFlags,
-                       const SkMatrix& viewMatrix, const char text[],
-                       size_t byteLength, const SkScalar pos[], int scalarsPerPosition,
-                       const SkPoint& offset) const;
-
     static void AppendGlyph(GrTextBlob*, int runIndex, GrGlyphCache*,
                             sk_sp<GrTextStrike>*, const SkGlyph&, GrGlyph::MaskStyle maskStyle,
                             SkScalar sx, SkScalar sy,