Make GrTextContext no longer store a GrDrawContext

This, at least, makes GrTextContexts no longer bound to a single GrDrawContext. (Passing in a RenderTarget and praying it matched the DrawContext was always a bit fishy too).

Review URL: https://codereview.chromium.org/1320323004
diff --git a/src/gpu/GrStencilAndCoverTextContext.cpp b/src/gpu/GrStencilAndCoverTextContext.cpp
index 78c3a2a..047cd07 100644
--- a/src/gpu/GrStencilAndCoverTextContext.cpp
+++ b/src/gpu/GrStencilAndCoverTextContext.cpp
@@ -22,20 +22,18 @@
 #include "SkTextFormatParams.h"
 
 GrStencilAndCoverTextContext::GrStencilAndCoverTextContext(GrContext* context,
-                                                           GrDrawContext* drawContext,
                                                            const SkSurfaceProps& surfaceProps)
-    : GrTextContext(context, drawContext, surfaceProps)
+    : GrTextContext(context, surfaceProps)
     , fStroke(SkStrokeRec::kFill_InitStyle)
     , fQueuedGlyphCount(0)
     , fFallbackGlyphsIdx(kGlyphBufferSize) {
 }
 
 GrStencilAndCoverTextContext*
-GrStencilAndCoverTextContext::Create(GrContext* context, GrDrawContext* drawContext,
-                                     const SkSurfaceProps& surfaceProps) {
-    GrStencilAndCoverTextContext* textContext =
-            new GrStencilAndCoverTextContext(context, drawContext, surfaceProps);
-    textContext->fFallbackTextContext = GrAtlasTextContext::Create(context, drawContext, surfaceProps);
+GrStencilAndCoverTextContext::Create(GrContext* context, const SkSurfaceProps& surfaceProps) {
+    GrStencilAndCoverTextContext* textContext = 
+        new GrStencilAndCoverTextContext(context, surfaceProps);
+    textContext->fFallbackTextContext = GrAtlasTextContext::Create(context, surfaceProps);
 
     return textContext;
 }
@@ -73,7 +71,7 @@
     return rec.getFormat() != SkMask::kARGB32_Format;
 }
 
-void GrStencilAndCoverTextContext::onDrawText(GrRenderTarget* rt,
+void GrStencilAndCoverTextContext::onDrawText(GrDrawContext* dc, GrRenderTarget* rt,
                                               const GrClip& clip,
                                               const GrPaint& paint,
                                               const SkPaint& skPaint,
@@ -156,17 +154,17 @@
         const SkGlyph& glyph = glyphCacheProc(fGlyphCache, &text, 0, 0);
         fx += SkFixedMul(autokern.adjust(glyph), fixedSizeRatio);
         if (glyph.fWidth) {
-            this->appendGlyph(glyph, SkPoint::Make(SkFixedToScalar(fx), SkFixedToScalar(fy)));
+            this->appendGlyph(dc, glyph, SkPoint::Make(SkFixedToScalar(fx), SkFixedToScalar(fy)));
         }
 
         fx += SkFixedMul(glyph.fAdvanceX, fixedSizeRatio);
         fy += SkFixedMul(glyph.fAdvanceY, fixedSizeRatio);
     }
 
-    this->finish();
+    this->finish(dc);
 }
 
-void GrStencilAndCoverTextContext::onDrawPosText(GrRenderTarget* rt,
+void GrStencilAndCoverTextContext::onDrawPosText(GrDrawContext* dc, GrRenderTarget* rt,
                                                  const GrClip& clip,
                                                  const GrPaint& paint,
                                                  const SkPaint& skPaint,
@@ -210,12 +208,12 @@
             SkPoint loc;
             alignProc(tmsLoc, glyph, &loc);
 
-            this->appendGlyph(glyph, loc);
+            this->appendGlyph(dc, glyph, loc);
         }
         pos += scalarsPerPosition;
     }
 
-    this->finish();
+    this->finish(dc);
 }
 
 static GrPathRange* get_gr_glyphs(GrContext* ctx,
@@ -400,10 +398,12 @@
     return true;
 }
 
-inline void GrStencilAndCoverTextContext::appendGlyph(const SkGlyph& glyph, const SkPoint& pos) {
+inline void GrStencilAndCoverTextContext::appendGlyph(GrDrawContext* dc,
+                                                      const SkGlyph& glyph,
+                                                      const SkPoint& pos) {
     if (fQueuedGlyphCount >= fFallbackGlyphsIdx) {
         SkASSERT(fQueuedGlyphCount == fFallbackGlyphsIdx);
-        this->flush();
+        this->flush(dc);
     }
 
     // Stick the glyphs we can't draw at the end of the buffer, growing backwards.
@@ -421,7 +421,7 @@
     return &pointArray[0].fX;
 }
 
-void GrStencilAndCoverTextContext::flush() {
+void GrStencilAndCoverTextContext::flush(GrDrawContext* dc) {
     if (fQueuedGlyphCount > 0) {
         SkAutoTUnref<GrPathProcessor> pp(GrPathProcessor::Create(fPaint.getColor(),
                                                                  fViewMatrix,
@@ -446,11 +446,11 @@
         SkASSERT(0 == fQueuedGlyphCount);
         SkASSERT(kGlyphBufferSize == fFallbackGlyphsIdx);
 
-        fDrawContext->drawPaths(&pipelineBuilder, pp, fGlyphs,
-                                fGlyphIndices, GrPathRange::kU16_PathIndexType,
-                                get_xy_scalar_array(fGlyphPositions),
-                                GrPathRendering::kTranslate_PathTransformType,
-                                fQueuedGlyphCount, GrPathRendering::kWinding_FillType);
+        dc->drawPaths(&pipelineBuilder, pp, fGlyphs,
+                      fGlyphIndices, GrPathRange::kU16_PathIndexType,
+                      get_xy_scalar_array(fGlyphPositions),
+                      GrPathRendering::kTranslate_PathTransformType,
+                      fQueuedGlyphCount, GrPathRendering::kWinding_FillType);
 
         fQueuedGlyphCount = 0;
     }
@@ -472,7 +472,7 @@
             inverse.mapPoints(&fGlyphPositions[fFallbackGlyphsIdx], fallbackGlyphCount);
         }
 
-        fFallbackTextContext->drawPosText(fRenderTarget, fClip, paintFallback, skPaintFallback,
+        fFallbackTextContext->drawPosText(dc, fRenderTarget, fClip, paintFallback, skPaintFallback,
                                           fViewMatrix, (char*)&fGlyphIndices[fFallbackGlyphsIdx],
                                           2 * fallbackGlyphCount,
                                           get_xy_scalar_array(&fGlyphPositions[fFallbackGlyphsIdx]),
@@ -482,8 +482,8 @@
     }
 }
 
-void GrStencilAndCoverTextContext::finish() {
-    this->flush();
+void GrStencilAndCoverTextContext::finish(GrDrawContext* dc) {
+    this->flush(dc);
 
     fGlyphs->unref();
     fGlyphs = nullptr;