Replace factory generation of TextContexts with persistent objects.

BUG=skia:2018
R=bsalomon@google.com

Author: jvanverth@google.com

Review URL: https://codereview.chromium.org/150743002

git-svn-id: http://skia.googlecode.com/svn/trunk@13249 2bbb7eff-a529-9590-31e7-b0007b416f81
diff --git a/src/gpu/GrBitmapTextContext.cpp b/src/gpu/GrBitmapTextContext.cpp
index 488aa13..c7beb14 100755
--- a/src/gpu/GrBitmapTextContext.cpp
+++ b/src/gpu/GrBitmapTextContext.cpp
@@ -29,15 +29,9 @@
 SK_CONF_DECLARE(bool, c_DumpFontCache, "gpu.dumpFontCache", false,
                 "Dump the contents of the font cache before every purge.");
 
-bool GrBitmapTextContext::CanDraw(const SkPaint& paint, const SkMatrix& ctm) {
-    return !SkDraw::ShouldDrawTextAsPaths(paint, ctm);
-}
-
 GrBitmapTextContext::GrBitmapTextContext(GrContext* context,
-                                         const GrPaint& grPaint,
-                                         const SkPaint& skPaint,
                                          const SkDeviceProperties& properties)
-                                       : GrTextContext(context, grPaint, skPaint, properties) {
+                                       : GrTextContext(context, properties) {
     fStrike = NULL;
 
     fCurrTexture = NULL;
@@ -51,6 +45,10 @@
     this->flushGlyphs();
 }
 
+bool GrBitmapTextContext::canDraw(const SkPaint& paint) {
+    return !SkDraw::ShouldDrawTextAsPaths(paint, fContext->getMatrix());
+}
+
 static inline GrColor skcolor_to_grcolor_nopremultiply(SkColor c) {
     unsigned r = SkColorGetR(c);
     unsigned g = SkColorGetG(c);
@@ -117,7 +115,26 @@
     }
 }
 
-void GrBitmapTextContext::drawText(const char text[], size_t byteLength,
+inline void GrBitmapTextContext::init(const GrPaint& paint, const SkPaint& skPaint) {
+    GrTextContext::init(paint, skPaint);
+
+    fStrike = NULL;
+
+    fCurrTexture = NULL;
+    fCurrVertex = 0;
+
+    fVertices = NULL;
+    fMaxVertices = 0;
+}
+
+inline void GrBitmapTextContext::finish() {
+    flushGlyphs();
+
+    GrTextContext::finish();
+}
+
+void GrBitmapTextContext::drawText(const GrPaint& paint, const SkPaint& skPaint, 
+                                   const char text[], size_t byteLength,
                                    SkScalar x, SkScalar y) {
     SkASSERT(byteLength == 0 || text != NULL);
 
@@ -126,6 +143,8 @@
         return;
     }
 
+    this->init(paint, skPaint);
+
     SkDrawCacheProc glyphCacheProc = fSkPaint.getDrawCacheProc();
 
     SkAutoGlyphCache    autoCache(fSkPaint, &fDeviceProperties, &fContext->getMatrix());
@@ -201,6 +220,8 @@
         fx += glyph.fAdvanceX;
         fy += glyph.fAdvanceY;
     }
+
+    this->finish();
 }
 
 ///////////////////////////////////////////////////////////////////////////////
@@ -295,7 +316,8 @@
 
 ///////////////////////////////////////////////////////////////////////////////
 
-void GrBitmapTextContext::drawPosText(const char text[], size_t byteLength,
+void GrBitmapTextContext::drawPosText(const GrPaint& paint, const SkPaint& skPaint, 
+                                      const char text[], size_t byteLength,
                                       const SkScalar pos[], SkScalar constY,
                                       int scalarsPerPosition) {
     SkASSERT(byteLength == 0 || text != NULL);
@@ -306,6 +328,8 @@
         return;
     }
 
+    this->init(paint, skPaint);
+
     SkDrawCacheProc glyphCacheProc = fSkPaint.getDrawCacheProc();
 
     SkAutoGlyphCache    autoCache(fSkPaint, &fDeviceProperties, &fContext->getMatrix());
@@ -439,6 +463,8 @@
             }
         }
     }
+
+    this->finish();
 }
 
 namespace {