Change TextContext handling of stages and draw targets; this allows us to
assert in GrContext::setPaint() that all stages are disabled every time
the paint is set.

Watch for possible performance implications.

http://codereview.appspot.com/6347043/



git-svn-id: http://skia.googlecode.com/svn/trunk@4531 2bbb7eff-a529-9590-31e7-b0007b416f81
diff --git a/src/gpu/GrTextContext.cpp b/src/gpu/GrTextContext.cpp
index daf48bf..5b61be2 100644
--- a/src/gpu/GrTextContext.cpp
+++ b/src/gpu/GrTextContext.cpp
@@ -23,8 +23,11 @@
 };
 
 void GrTextContext::flushGlyphs() {
+    if (NULL == fDrawTarget) {
+        return;
+    }
+    GrDrawState* drawState = fDrawTarget->drawState();
     if (fCurrVertex > 0) {
-        GrDrawState* drawState = fDrawTarget->drawState();
         // setup our sampler state for our text texture/atlas
         GrSamplerState::Filter filter;
         if (fExtMatrix.isIdentity()) {
@@ -68,8 +71,9 @@
         fMaxVertices = 0;
         fCurrVertex = 0;
         GrSafeSetNull(fCurrTexture);
-        drawState->disableStage(kGlyphMaskStage);
     }
+    drawState->disableStages();
+    fDrawTarget = NULL;
 }
 
 GrTextContext::GrTextContext(GrContext* context,
@@ -134,7 +138,7 @@
         }
     }
 
-    fDrawTarget = fContext->getTextTarget(fPaint);
+    fDrawTarget = NULL;
 
     fVertices = NULL;
     fMaxVertices = 0;
@@ -246,19 +250,20 @@
         // If we need to reserve vertices allow the draw target to suggest
         // a number of verts to reserve and whether to perform a flush.
         fMaxVertices = kMinRequestedVerts;
-        bool flush = fDrawTarget->geometryHints(fVertexLayout,
+        bool flush = (NULL != fDrawTarget) &&
+                     fDrawTarget->geometryHints(fVertexLayout,
                                                 &fMaxVertices,
                                                 NULL);
         if (flush) {
             this->flushGlyphs();
             fContext->flush();
-            fDrawTarget = fContext->getTextTarget(fPaint);
-            fMaxVertices = kDefaultRequestedVerts;
-            // ignore return, no point in flushing again.
-            fDrawTarget->geometryHints(fVertexLayout,
-                                       &fMaxVertices,
-                                       NULL);
         }
+        fDrawTarget = fContext->getTextTarget(fPaint);
+        fMaxVertices = kDefaultRequestedVerts;
+        // ignore return, no point in flushing again.
+        fDrawTarget->geometryHints(fVertexLayout,
+                                   &fMaxVertices,
+                                   NULL);
 
         int maxQuadVertices = 4 * fContext->getQuadIndexBuffer()->maxQuads();
         if (fMaxVertices < kMinRequestedVerts) {