Move flush logic into GrAtlasTextBlob

TBR=bsalomon@google.com
BUG=skia:

Review URL: https://codereview.chromium.org/1518763002
diff --git a/include/gpu/GrDrawContext.h b/include/gpu/GrDrawContext.h
index dac9183..6418247 100644
--- a/include/gpu/GrDrawContext.h
+++ b/include/gpu/GrDrawContext.h
@@ -277,7 +277,7 @@
     GrRenderTarget* accessRenderTarget() { return fRenderTarget; }
 
 private:
-    friend class GrAtlasTextContext; // for access to drawBatch
+    friend class GrAtlasTextBlob; // for access to drawBatch
     friend class GrDrawingManager; // for ctor
 
     SkDEBUGCODE(void validate() const;)
diff --git a/src/gpu/GrAtlasTextBlob.cpp b/src/gpu/GrAtlasTextBlob.cpp
index aa50cbf..50ce0f8 100644
--- a/src/gpu/GrAtlasTextBlob.cpp
+++ b/src/gpu/GrAtlasTextBlob.cpp
@@ -7,6 +7,14 @@
 
 #include "GrAtlasTextBlob.h"
 
+#include "GrBlurUtils.h"
+#include "GrContext.h"
+#include "GrDrawContext.h"
+#include "SkColorFilter.h"
+#include "SkDrawFilter.h"
+#include "SkTextBlobRunIterator.h"
+#include "batches/GrAtlasTextBatch.h"
+
 void GrAtlasTextBlob::appendGlyph(int runIndex,
                                   const SkRect& positions,
                                   GrColor color,
@@ -207,6 +215,189 @@
     return false;
 }
 
+GrDrawBatch* GrAtlasTextBlob::createBatch(const Run::SubRunInfo& info,
+                                          int glyphCount, int run, int subRun,
+                                          GrColor color, SkScalar transX, SkScalar transY,
+                                          const SkPaint& skPaint, const SkSurfaceProps& props,
+                                          const GrDistanceFieldAdjustTable* distanceAdjustTable,
+                                          GrBatchFontCache* cache) {
+    GrMaskFormat format = info.maskFormat();
+    GrColor subRunColor;
+    if (kARGB_GrMaskFormat == format) {
+        uint8_t paintAlpha = skPaint.getAlpha();
+        subRunColor = SkColorSetARGB(paintAlpha, paintAlpha, paintAlpha, paintAlpha);
+    } else {
+        subRunColor = color;
+    }
+
+    GrAtlasTextBatch* batch;
+    if (info.drawAsDistanceFields()) {
+        SkColor filteredColor;
+        SkColorFilter* colorFilter = skPaint.getColorFilter();
+        if (colorFilter) {
+            filteredColor = colorFilter->filterColor(skPaint.getColor());
+        } else {
+            filteredColor = skPaint.getColor();
+        }
+        bool useBGR = SkPixelGeometryIsBGR(props.pixelGeometry());
+        batch = GrAtlasTextBatch::CreateDistanceField(glyphCount, cache,
+                                                      distanceAdjustTable, filteredColor,
+                                                      info.hasUseLCDText(), useBGR);
+    } else {
+        batch = GrAtlasTextBatch::CreateBitmap(format, glyphCount, cache);
+    }
+    GrAtlasTextBatch::Geometry& geometry = batch->geometry();
+    geometry.fBlob = SkRef(this);
+    geometry.fRun = run;
+    geometry.fSubRun = subRun;
+    geometry.fColor = subRunColor;
+    geometry.fTransX = transX;
+    geometry.fTransY = transY;
+    batch->init();
+
+    return batch;
+}
+
+inline
+void GrAtlasTextBlob::flushRun(GrDrawContext* dc, GrPipelineBuilder* pipelineBuilder,
+                               int run, GrColor color,
+                               SkScalar transX, SkScalar transY,
+                               const SkPaint& skPaint, const SkSurfaceProps& props,
+                               const GrDistanceFieldAdjustTable* distanceAdjustTable,
+                               GrBatchFontCache* cache) {
+    for (int subRun = 0; subRun < fRuns[run].fSubRunInfo.count(); subRun++) {
+        const Run::SubRunInfo& info = fRuns[run].fSubRunInfo[subRun];
+        int glyphCount = info.glyphCount();
+        if (0 == glyphCount) {
+            continue;
+        }
+
+        SkAutoTUnref<GrDrawBatch> batch(this->createBatch(info, glyphCount, run,
+                                                          subRun, color, transX, transY,
+                                                          skPaint, props,
+                                                          distanceAdjustTable, cache));
+        dc->drawBatch(pipelineBuilder, batch);
+    }
+}
+
+void GrAtlasTextBlob::flushBigGlyphs(GrContext* context, GrDrawContext* dc,
+                                     const GrClip& clip, const SkPaint& skPaint,
+                                     SkScalar transX, SkScalar transY,
+                                     const SkIRect& clipBounds) {
+    for (int i = 0; i < fBigGlyphs.count(); i++) {
+        GrAtlasTextBlob::BigGlyph& bigGlyph = fBigGlyphs[i];
+        bigGlyph.fVx += transX;
+        bigGlyph.fVy += transY;
+        SkMatrix ctm;
+        ctm.setScale(bigGlyph.fScale, bigGlyph.fScale);
+        ctm.postTranslate(bigGlyph.fVx, bigGlyph.fVy);
+        if (bigGlyph.fApplyVM) {
+            ctm.postConcat(fViewMatrix);
+        }
+
+        GrBlurUtils::drawPathWithMaskFilter(context, dc, clip, bigGlyph.fPath,
+                                            skPaint, ctm, nullptr, clipBounds, false);
+    }
+}
+
+void GrAtlasTextBlob::flushRunAsPaths(GrDrawContext* dc,
+                                      GrTextContext* textContext,
+                                      const SkSurfaceProps& props,
+                                      const SkTextBlobRunIterator& it,
+                                      const GrClip& clip, const SkPaint& skPaint,
+                                      SkDrawFilter* drawFilter, const SkMatrix& viewMatrix,
+                                      const SkIRect& clipBounds, SkScalar x, SkScalar y) {
+    SkPaint runPaint = skPaint;
+
+    size_t textLen = it.glyphCount() * sizeof(uint16_t);
+    const SkPoint& offset = it.offset();
+
+    it.applyFontToPaint(&runPaint);
+
+    if (drawFilter && !drawFilter->filter(&runPaint, SkDrawFilter::kText_Type)) {
+        return;
+    }
+
+    runPaint.setFlags(GrTextContext::FilterTextFlags(props, runPaint));
+
+    switch (it.positioning()) {
+        case SkTextBlob::kDefault_Positioning:
+            textContext->drawTextAsPath(dc, clip, runPaint, viewMatrix,
+                                        (const char *)it.glyphs(),
+                                        textLen, x + offset.x(), y + offset.y(), clipBounds);
+            break;
+        case SkTextBlob::kHorizontal_Positioning:
+            textContext->drawPosTextAsPath(dc, clip, runPaint, viewMatrix,
+                                           (const char*)it.glyphs(),
+                                           textLen, it.pos(), 1, SkPoint::Make(x, y + offset.y()),
+                                           clipBounds);
+            break;
+        case SkTextBlob::kFull_Positioning:
+            textContext->drawPosTextAsPath(dc, clip, runPaint, viewMatrix,
+                                           (const char*)it.glyphs(),
+                                           textLen, it.pos(), 2, SkPoint::Make(x, y), clipBounds);
+            break;
+    }
+}
+
+void GrAtlasTextBlob::flushCached(const SkTextBlob* blob,
+                                  GrContext* context,
+                                  GrDrawContext* dc,
+                                  GrTextContext* textContext,
+                                  const SkSurfaceProps& props,
+                                  const GrDistanceFieldAdjustTable* distanceAdjustTable,
+                                  const SkPaint& skPaint,
+                                  const GrPaint& grPaint,
+                                  SkDrawFilter* drawFilter,
+                                  const GrClip& clip,
+                                  const SkMatrix& viewMatrix,
+                                  const SkIRect& clipBounds,
+                                  SkScalar x, SkScalar y,
+                                  SkScalar transX, SkScalar transY) {
+    // We loop through the runs of the blob, flushing each.  If any run is too large, then we flush
+    // it as paths
+    GrPipelineBuilder pipelineBuilder(grPaint, dc->accessRenderTarget(), clip);
+
+    GrColor color = grPaint.getColor();
+
+    SkTextBlobRunIterator it(blob);
+    for (int run = 0; !it.done(); it.next(), run++) {
+        if (fRuns[run].fDrawAsPaths) {
+            this->flushRunAsPaths(dc, textContext, props, it, clip, skPaint,
+                                  drawFilter, viewMatrix, clipBounds, x, y);
+            continue;
+        }
+        fRuns[run].fVertexBounds.offset(transX, transY);
+        this->flushRun(dc, &pipelineBuilder, run, color,
+                       transX, transY, skPaint, props,
+                       distanceAdjustTable, context->getBatchFontCache());
+    }
+
+    // Now flush big glyphs
+    this->flushBigGlyphs(context, dc, clip, skPaint, transX, transY, clipBounds);
+}
+
+void GrAtlasTextBlob::flushThrowaway(GrContext* context,
+                                     GrDrawContext* dc,
+                                     const SkSurfaceProps& props,
+                                     const GrDistanceFieldAdjustTable* distanceAdjustTable,
+                                     const SkPaint& skPaint,
+                                     const GrPaint& grPaint,
+                                     const GrClip& clip,
+                                     const SkIRect& clipBounds) {
+    GrPipelineBuilder pipelineBuilder(grPaint, dc->accessRenderTarget(), clip);
+
+    GrColor color = grPaint.getColor();
+    for (int run = 0; run < fRunCount; run++) {
+        this->flushRun(dc, &pipelineBuilder, run, color, 0, 0, skPaint, props,
+                       distanceAdjustTable, context->getBatchFontCache());
+    }
+
+    // Now flush big glyphs
+    this->flushBigGlyphs(context, dc, clip, skPaint, 0, 0, clipBounds);
+}
+
+
 // TODO get this code building again
 #ifdef CACHE_SANITY_CHECK
 void GrAtlasTextBlob::AssertEqual(const GrAtlasTextBlob& l, const GrAtlasTextBlob& r) {
diff --git a/src/gpu/GrAtlasTextBlob.h b/src/gpu/GrAtlasTextBlob.h
index 35f6428..0f99576 100644
--- a/src/gpu/GrAtlasTextBlob.h
+++ b/src/gpu/GrAtlasTextBlob.h
@@ -11,12 +11,18 @@
 #include "GrBatchAtlas.h"
 #include "GrBatchFontCache.h"
 #include "GrColor.h"
+#include "GrMemoryPool.h"
 #include "SkDescriptor.h"
 #include "SkMaskFilter.h"
-#include "GrMemoryPool.h"
 #include "SkSurfaceProps.h"
 #include "SkTInternalLList.h"
 
+struct GrDistanceFieldAdjustTable;
+class GrTextContext;
+class SkDrawFilter;
+class SkTextBlob;
+class SkTextBlobRunIterator;
+
 // With this flag enabled, the GrAtlasTextContext will, as a sanity check, regenerate every blob
 // that comes in to verify the integrity of its cache
 //#define CACHE_SANITY_CHECK // VERY SLOW
@@ -35,7 +41,8 @@
  *
  * *WARNING* If you add new fields to this struct, then you may need to to update AssertEqual
  */
-struct GrAtlasTextBlob : public SkNVRefCnt<GrAtlasTextBlob> {
+class GrAtlasTextBlob : public SkNVRefCnt<GrAtlasTextBlob> {
+public:
     SK_DECLARE_INTERNAL_LLIST_INTERFACE(GrAtlasTextBlob);
 
     /*
@@ -308,6 +315,32 @@
                         GrColor color, const SkMaskFilter::BlurRec& blurRec,
                         const SkMatrix& viewMatrix, SkScalar x, SkScalar y);
 
+    // flush a GrAtlasTextBlob associated with a SkTextBlob
+    void flushCached(const SkTextBlob* blob,
+                     GrContext* context,
+                     GrDrawContext* dc,
+                     GrTextContext* textContext,
+                     const SkSurfaceProps& props,
+                     const GrDistanceFieldAdjustTable* distanceAdjustTable,
+                     const SkPaint& skPaint,
+                     const GrPaint& grPaint,
+                     SkDrawFilter* drawFilter,
+                     const GrClip& clip,
+                     const SkMatrix& viewMatrix,
+                     const SkIRect& clipBounds,
+                     SkScalar x, SkScalar y,
+                     SkScalar transX, SkScalar transY);
+
+    // flush a throwaway GrAtlasTextBlob *not* associated with an SkTextBlob
+    void flushThrowaway(GrContext* context,
+                        GrDrawContext* dc,
+                        const SkSurfaceProps& props,
+                        const GrDistanceFieldAdjustTable* distanceAdjustTable,
+                        const SkPaint& skPaint,
+                        const GrPaint& grPaint,
+                        const GrClip& clip,
+                        const SkIRect& clipBounds);
+
     // position + local coord
     static const size_t kColorTextVASize = sizeof(SkPoint) + sizeof(SkIPoint16);
     static const size_t kGrayTextVASize = sizeof(SkPoint) + sizeof(GrColor) + sizeof(SkIPoint16);
@@ -318,9 +351,39 @@
     static void AssertEqual(const GrAtlasTextBlob&, const GrAtlasTextBlob&);
     size_t fSize;
 #endif
+
+    // We'd like to inline this and make it private, but there is some test code which calls it.
+    // TODO refactor this
+    GrDrawBatch* createBatch(const Run::SubRunInfo& info,
+                             int glyphCount, int run, int subRun,
+                             GrColor color, SkScalar transX, SkScalar transY,
+                             const SkPaint& skPaint, const SkSurfaceProps& props,
+                             const GrDistanceFieldAdjustTable* distanceAdjustTable,
+                             GrBatchFontCache* cache);
+
 private:
     void appendLargeGlyph(GrGlyph* glyph, GrFontScaler* scaler, const SkGlyph& skGlyph,
                           SkScalar x, SkScalar y, SkScalar scale, bool applyVM);
+
+    inline void flushRun(GrDrawContext* dc, GrPipelineBuilder* pipelineBuilder,
+                         int run, GrColor color,
+                         SkScalar transX, SkScalar transY,
+                         const SkPaint& skPaint, const SkSurfaceProps& props,
+                         const GrDistanceFieldAdjustTable* distanceAdjustTable,
+                         GrBatchFontCache* cache);
+
+    void flushBigGlyphs(GrContext* context, GrDrawContext* dc,
+                        const GrClip& clip, const SkPaint& skPaint,
+                        SkScalar transX, SkScalar transY,
+                        const SkIRect& clipBounds);
+
+    void flushRunAsPaths(GrDrawContext* dc,
+                         GrTextContext* textContext,
+                         const SkSurfaceProps& props,
+                         const SkTextBlobRunIterator& it,
+                         const GrClip& clip, const SkPaint& skPaint,
+                         SkDrawFilter* drawFilter, const SkMatrix& viewMatrix,
+                         const SkIRect& clipBounds, SkScalar x, SkScalar y);
 };
 
 #endif
diff --git a/src/gpu/GrAtlasTextContext.cpp b/src/gpu/GrAtlasTextContext.cpp
index 38b9c04..5e11eb5 100644
--- a/src/gpu/GrAtlasTextContext.cpp
+++ b/src/gpu/GrAtlasTextContext.cpp
@@ -6,7 +6,6 @@
  */
 #include "GrAtlasTextContext.h"
 
-#include "GrBlurUtils.h"
 #include "GrDrawContext.h"
 #include "GrDrawTarget.h"
 #include "GrFontScaler.h"
@@ -204,8 +203,8 @@
                                  blob, x, y, drawFilter, clip);
     }
 
-    this->flush(blob, cacheBlob, dc, skPaint, grPaint, drawFilter,
-                clip, viewMatrix, clipBounds, x, y, transX, transY);
+    cacheBlob->flushCached(blob, fContext, dc, this, fSurfaceProps, fDistanceAdjustTable, skPaint,
+                           grPaint, drawFilter, clip, viewMatrix, clipBounds, x, y, transX, transY);
 }
 
 inline bool GrAtlasTextContext::canDrawAsDistanceFields(const SkPaint& skPaint,
@@ -536,7 +535,8 @@
     SkAutoTUnref<GrAtlasTextBlob> blob(
         this->createDrawTextBlob(clip, paint, skPaint, viewMatrix,
                                  text, byteLength, x, y, regionClipBounds));
-    this->flush(blob, dc, skPaint, paint, clip, regionClipBounds);
+    blob->flushThrowaway(fContext, dc, fSurfaceProps, fDistanceAdjustTable, skPaint, paint,
+                         clip, regionClipBounds);
 }
 
 void GrAtlasTextContext::onDrawPosText(GrDrawContext* dc,
@@ -552,7 +552,8 @@
                                     pos, scalarsPerPosition,
                                     offset, regionClipBounds));
 
-    this->flush(blob, dc, skPaint, paint, clip, regionClipBounds);
+    blob->flushThrowaway(fContext, dc, fSurfaceProps, fDistanceAdjustTable, skPaint, paint, clip,
+                         regionClipBounds);
 }
 
 void GrAtlasTextContext::internalDrawBMPText(GrAtlasTextBlob* blob, int runIndex,
@@ -858,179 +859,6 @@
     return true;
 }
 
-void GrAtlasTextContext::flushRunAsPaths(GrDrawContext* dc,
-                                         const SkTextBlobRunIterator& it,
-                                         const GrClip& clip, const SkPaint& skPaint,
-                                         SkDrawFilter* drawFilter, const SkMatrix& viewMatrix,
-                                         const SkIRect& clipBounds, SkScalar x, SkScalar y) {
-    SkPaint runPaint = skPaint;
-
-    size_t textLen = it.glyphCount() * sizeof(uint16_t);
-    const SkPoint& offset = it.offset();
-
-    it.applyFontToPaint(&runPaint);
-
-    if (drawFilter && !drawFilter->filter(&runPaint, SkDrawFilter::kText_Type)) {
-        return;
-    }
-
-    runPaint.setFlags(FilterTextFlags(fSurfaceProps, runPaint));
-
-    switch (it.positioning()) {
-        case SkTextBlob::kDefault_Positioning:
-            this->drawTextAsPath(dc, clip, runPaint, viewMatrix,
-                                 (const char *)it.glyphs(),
-                                 textLen, x + offset.x(), y + offset.y(), clipBounds);
-            break;
-        case SkTextBlob::kHorizontal_Positioning:
-            this->drawPosTextAsPath(dc, clip, runPaint, viewMatrix,
-                                    (const char*)it.glyphs(),
-                                    textLen, it.pos(), 1, SkPoint::Make(x, y + offset.y()),
-                                    clipBounds);
-            break;
-        case SkTextBlob::kFull_Positioning:
-            this->drawPosTextAsPath(dc, clip, runPaint, viewMatrix,
-                                    (const char*)it.glyphs(),
-                                    textLen, it.pos(), 2, SkPoint::Make(x, y), clipBounds);
-            break;
-    }
-}
-
-inline GrDrawBatch*
-GrAtlasTextContext::createBatch(GrAtlasTextBlob* cacheBlob, const PerSubRunInfo& info,
-                                int glyphCount, int run, int subRun,
-                                GrColor color, SkScalar transX, SkScalar transY,
-                                const SkPaint& skPaint) {
-    GrMaskFormat format = info.maskFormat();
-    GrColor subRunColor;
-    if (kARGB_GrMaskFormat == format) {
-        uint8_t paintAlpha = skPaint.getAlpha();
-        subRunColor = SkColorSetARGB(paintAlpha, paintAlpha, paintAlpha, paintAlpha);
-    } else {
-        subRunColor = color;
-    }
-
-    GrAtlasTextBatch* batch;
-    if (info.drawAsDistanceFields()) {
-        SkColor filteredColor;
-        SkColorFilter* colorFilter = skPaint.getColorFilter();
-        if (colorFilter) {
-            filteredColor = colorFilter->filterColor(skPaint.getColor());
-        } else {
-            filteredColor = skPaint.getColor();
-        }
-        bool useBGR = SkPixelGeometryIsBGR(fSurfaceProps.pixelGeometry());
-        batch = GrAtlasTextBatch::CreateDistanceField(glyphCount, fContext->getBatchFontCache(),
-                                                      fDistanceAdjustTable, filteredColor,
-                                                      info.hasUseLCDText(), useBGR);
-    } else {
-        batch = GrAtlasTextBatch::CreateBitmap(format, glyphCount, fContext->getBatchFontCache());
-    }
-    GrAtlasTextBatch::Geometry& geometry = batch->geometry();
-    geometry.fBlob = SkRef(cacheBlob);
-    geometry.fRun = run;
-    geometry.fSubRun = subRun;
-    geometry.fColor = subRunColor;
-    geometry.fTransX = transX;
-    geometry.fTransY = transY;
-    batch->init();
-
-    return batch;
-}
-
-inline void GrAtlasTextContext::flushRun(GrDrawContext* dc, GrPipelineBuilder* pipelineBuilder,
-                                         GrAtlasTextBlob* cacheBlob, int run, GrColor color,
-                                         SkScalar transX, SkScalar transY,
-                                         const SkPaint& skPaint) {
-    for (int subRun = 0; subRun < cacheBlob->fRuns[run].fSubRunInfo.count(); subRun++) {
-        const PerSubRunInfo& info = cacheBlob->fRuns[run].fSubRunInfo[subRun];
-        int glyphCount = info.glyphCount();
-        if (0 == glyphCount) {
-            continue;
-        }
-
-        SkAutoTUnref<GrDrawBatch> batch(this->createBatch(cacheBlob, info, glyphCount, run,
-                                                          subRun, color, transX, transY,
-                                                          skPaint));
-        dc->drawBatch(pipelineBuilder, batch);
-    }
-}
-
-inline void GrAtlasTextContext::flushBigGlyphs(GrAtlasTextBlob* cacheBlob,
-                                               GrDrawContext* dc,
-                                               const GrClip& clip, const SkPaint& skPaint,
-                                               SkScalar transX, SkScalar transY,
-                                               const SkIRect& clipBounds) {
-    if (!cacheBlob->fBigGlyphs.count()) {
-        return;
-    }
-
-    for (int i = 0; i < cacheBlob->fBigGlyphs.count(); i++) {
-        GrAtlasTextBlob::BigGlyph& bigGlyph = cacheBlob->fBigGlyphs[i];
-        bigGlyph.fVx += transX;
-        bigGlyph.fVy += transY;
-        SkMatrix ctm;
-        ctm.setScale(bigGlyph.fScale, bigGlyph.fScale);
-        ctm.postTranslate(bigGlyph.fVx, bigGlyph.fVy);
-        if (bigGlyph.fApplyVM) {
-            ctm.postConcat(cacheBlob->fViewMatrix);
-        }
-
-        GrBlurUtils::drawPathWithMaskFilter(fContext, dc, clip, bigGlyph.fPath,
-                                            skPaint, ctm, nullptr, clipBounds, false);
-    }
-}
-
-void GrAtlasTextContext::flush(const SkTextBlob* blob,
-                               GrAtlasTextBlob* cacheBlob,
-                               GrDrawContext* dc,
-                               const SkPaint& skPaint,
-                               const GrPaint& grPaint,
-                               SkDrawFilter* drawFilter,
-                               const GrClip& clip,
-                               const SkMatrix& viewMatrix,
-                               const SkIRect& clipBounds,
-                               SkScalar x, SkScalar y,
-                               SkScalar transX, SkScalar transY) {
-    // We loop through the runs of the blob, flushing each.  If any run is too large, then we flush
-    // it as paths
-    GrPipelineBuilder pipelineBuilder(grPaint, dc->accessRenderTarget(), clip);
-
-    GrColor color = grPaint.getColor();
-
-    SkTextBlobRunIterator it(blob);
-    for (int run = 0; !it.done(); it.next(), run++) {
-        if (cacheBlob->fRuns[run].fDrawAsPaths) {
-            this->flushRunAsPaths(dc, it, clip, skPaint,
-                                  drawFilter, viewMatrix, clipBounds, x, y);
-            continue;
-        }
-        cacheBlob->fRuns[run].fVertexBounds.offset(transX, transY);
-        this->flushRun(dc, &pipelineBuilder, cacheBlob, run, color,
-                       transX, transY, skPaint);
-    }
-
-    // Now flush big glyphs
-    this->flushBigGlyphs(cacheBlob, dc, clip, skPaint, transX, transY, clipBounds);
-}
-
-void GrAtlasTextContext::flush(GrAtlasTextBlob* cacheBlob,
-                               GrDrawContext* dc,
-                               const SkPaint& skPaint,
-                               const GrPaint& grPaint,
-                               const GrClip& clip,
-                               const SkIRect& clipBounds) {
-    GrPipelineBuilder pipelineBuilder(grPaint, dc->accessRenderTarget(), clip);
-
-    GrColor color = grPaint.getColor();
-    for (int run = 0; run < cacheBlob->fRunCount; run++) {
-        this->flushRun(dc, &pipelineBuilder, cacheBlob, run, color, 0, 0, skPaint);
-    }
-
-    // Now flush big glyphs
-    this->flushBigGlyphs(cacheBlob, dc, clip, skPaint, 0, 0, clipBounds);
-}
-
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 
 #ifdef GR_TEST_UTILS
@@ -1080,7 +908,9 @@
     SkScalar transX = static_cast<SkScalar>(random->nextU());
     SkScalar transY = static_cast<SkScalar>(random->nextU());
     const GrAtlasTextBlob::Run::SubRunInfo& info = blob->fRuns[0].fSubRunInfo[0];
-    return gTextContext->createBatch(blob, info, textLen, 0, 0, color, transX, transY, skPaint);
+    return blob->createBatch(info, textLen, 0, 0, color, transX, transY, skPaint,
+                             gSurfaceProps, gTextContext->dfAdjustTable(),
+                             context->getBatchFontCache());
 }
 
 #endif
diff --git a/src/gpu/GrAtlasTextContext.h b/src/gpu/GrAtlasTextContext.h
index 82283bc..fb132c2 100644
--- a/src/gpu/GrAtlasTextContext.h
+++ b/src/gpu/GrAtlasTextContext.h
@@ -64,29 +64,6 @@
                        GrColor color, GrFontScaler*, SkScalar textRatio,
                        const SkMatrix& viewMatrix);
 
-    inline void flushRunAsPaths(GrDrawContext*,
-                                const SkTextBlobRunIterator&, const GrClip& clip,
-                                const SkPaint&, SkDrawFilter*,
-                                const SkMatrix& viewMatrix, const SkIRect& clipBounds, SkScalar x,
-                                SkScalar y);
-    inline GrDrawBatch* createBatch(GrAtlasTextBlob*, const PerSubRunInfo&,
-                                    int glyphCount, int run, int subRun,
-                                    GrColor, SkScalar transX, SkScalar transY,
-                                    const SkPaint&);
-    inline void flushRun(GrDrawContext*, GrPipelineBuilder*, GrAtlasTextBlob*, int run, GrColor,
-                         SkScalar transX, SkScalar transY, const SkPaint&);
-    inline void flushBigGlyphs(GrAtlasTextBlob* cacheBlob, GrDrawContext*,
-                               const GrClip& clip, const SkPaint& skPaint,
-                               SkScalar transX, SkScalar transY, const SkIRect& clipBounds);
-
-    // We have to flush SkTextBlobs differently from drawText / drawPosText
-    void flush(const SkTextBlob*, GrAtlasTextBlob*, GrDrawContext*,
-               const SkPaint&, const GrPaint&, SkDrawFilter*, const GrClip&,
-               const SkMatrix& viewMatrix, const SkIRect& clipBounds, SkScalar x, SkScalar y,
-               SkScalar transX, SkScalar transY);
-    void flush(GrAtlasTextBlob*, GrDrawContext*, const SkPaint&,
-               const GrPaint&, const GrClip&, const SkIRect& clipBounds);
-
     // A helper for drawing BitmapText in a run of distance fields
     inline void fallbackDrawPosText(GrAtlasTextBlob*, int runIndex,
                                     const GrClip&, GrColor color,
@@ -148,6 +125,7 @@
                                                   const SkScalar pos[], int scalarsPerPosition,
                                                   const SkPoint& offset,
                                                   const SkIRect& regionClipBounds);
+    const GrDistanceFieldAdjustTable* dfAdjustTable() const { return fDistanceAdjustTable; }
 
     GrBatchTextStrike* fCurrStrike;
     GrTextBlobCache* fCache;
diff --git a/src/gpu/GrTextContext.h b/src/gpu/GrTextContext.h
index 842979c..387717c 100644
--- a/src/gpu/GrTextContext.h
+++ b/src/gpu/GrTextContext.h
@@ -82,6 +82,7 @@
     static uint32_t FilterTextFlags(const SkSurfaceProps& surfaceProps, const SkPaint& paint);
 
     friend class GrAtlasTextBatch;
+    friend class GrAtlasTextBlob; // for drawTextAsPath
 };
 
 #endif