Make text context responsible for setting GrPaint on GrDrawState.

R=robertphillips@google.com

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

git-svn-id: http://skia.googlecode.com/svn/trunk@9588 2bbb7eff-a529-9590-31e7-b0007b416f81
diff --git a/src/gpu/GrTextContext.cpp b/src/gpu/GrTextContext.cpp
index 804165b..19f18b5 100644
--- a/src/gpu/GrTextContext.cpp
+++ b/src/gpu/GrTextContext.cpp
@@ -27,7 +27,10 @@
     if (NULL == fDrawTarget) {
         return;
     }
+    GrDrawTarget::AutoStateRestore asr(fDrawTarget, GrDrawTarget::kPreserve_ASRInit);
     GrDrawState* drawState = fDrawTarget->drawState();
+    drawState->setFromPaint(fPaint, SkMatrix::I(), fContext->getRenderTarget());
+
     if (fCurrVertex > 0) {
         // setup our sampler state for our text texture/atlas
         GrAssert(GrIsALIGN4(fCurrVertex));
@@ -68,8 +71,6 @@
         fCurrVertex = 0;
         GrSafeSetNull(fCurrTexture);
     }
-    drawState->disableStages();
-    fDrawTarget = NULL;
 }
 
 GrTextContext::GrTextContext(GrContext* context, const GrPaint& paint) : fPaint(paint) {
@@ -93,7 +94,7 @@
 
     fAutoMatrix.setIdentity(fContext, &fPaint);
 
-    fDrawTarget = NULL;
+    fDrawTarget = fContext->getTextTarget();
 
     fVertices = NULL;
     fMaxVertices = 0;
@@ -101,9 +102,6 @@
 
 GrTextContext::~GrTextContext() {
     this->flushGlyphs();
-    if (fDrawTarget) {
-        fDrawTarget->drawState()->disableStages();
-    }
 }
 
 void GrTextContext::flush() {
@@ -123,6 +121,9 @@
 void GrTextContext::drawPackedGlyph(GrGlyph::PackedID packed,
                                     GrFixed vx, GrFixed vy,
                                     GrFontScaler* scaler) {
+    if (NULL == fDrawTarget) {
+        return;
+    }
     if (NULL == fStrike) {
         fStrike = fContext->getFontCache()->getStrike(scaler);
     }
@@ -205,18 +206,14 @@
        // 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 = false;
-        fDrawTarget = fContext->getTextTarget(fPaint);
-        if (NULL != fDrawTarget) {
-            fDrawTarget->drawState()->setVertexAttribs<gTextVertexAttribs>(SK_ARRAY_COUNT(gTextVertexAttribs));
-            flush = fDrawTarget->geometryHints(&fMaxVertices, NULL);
-        }
+        fDrawTarget->drawState()->setVertexAttribs<gTextVertexAttribs>(
+            SK_ARRAY_COUNT(gTextVertexAttribs));
+        bool flush = fDrawTarget->geometryHints(&fMaxVertices, NULL);
         if (flush) {
             this->flushGlyphs();
             fContext->flush();
-            // flushGlyphs() will reset fDrawTarget to NULL.
-            fDrawTarget = fContext->getTextTarget(fPaint);
-            fDrawTarget->drawState()->setVertexAttribs<gTextVertexAttribs>(SK_ARRAY_COUNT(gTextVertexAttribs));
+            fDrawTarget->drawState()->setVertexAttribs<gTextVertexAttribs>(
+                SK_ARRAY_COUNT(gTextVertexAttribs));
         }
         fMaxVertices = kDefaultRequestedVerts;
         // ignore return, no point in flushing again.
@@ -229,11 +226,10 @@
             // don't exceed the limit of the index buffer
             fMaxVertices = maxQuadVertices;
         }
-        bool success = fDrawTarget->reserveVertexAndIndexSpace(
-                                                   fMaxVertices,
-                                                   0,
-                                                   GrTCast<void**>(&fVertices),
-                                                   NULL);
+        bool success = fDrawTarget->reserveVertexAndIndexSpace(fMaxVertices,
+                                                               0,
+                                                               GrTCast<void**>(&fVertices),
+                                                               NULL);
         GrAlwaysAssert(success);
         GrAssert(2*sizeof(GrPoint) == fDrawTarget->getDrawState().getVertexSize());
     }