Revert 3503


git-svn-id: http://skia.googlecode.com/svn/trunk@3504 2bbb7eff-a529-9590-31e7-b0007b416f81
diff --git a/src/gpu/GrDrawTarget.cpp b/src/gpu/GrDrawTarget.cpp
index 5cce435..6d52c2a 100644
--- a/src/gpu/GrDrawTarget.cpp
+++ b/src/gpu/GrDrawTarget.cpp
@@ -474,9 +474,6 @@
 #if GR_DEBUG
     VertexLayoutUnitTest();
 #endif
-    fDrawState = &fDefaultDrawState;
-    // We assume that fDrawState always owns a ref to the object it points at.
-    fDefaultDrawState.ref();
     GeometrySrcState& geoSrc = fGeoSrcStateStack.push_back();
 #if GR_DEBUG
     geoSrc.fVertexCount = DEBUG_INVAL_START_IDX;
@@ -493,7 +490,6 @@
     GeometrySrcState& geoSrc = fGeoSrcStateStack.back();
     GrAssert(kNone_GeometrySrcType == geoSrc.fIndexSrc);
     GrAssert(kNone_GeometrySrcType == geoSrc.fVertexSrc);
-    fDrawState->unref();
 }
 
 void GrDrawTarget::releaseGeometry() {
@@ -515,28 +511,16 @@
     return fClip;
 }
 
-void GrDrawTarget::setDrawState(GrDrawState*  drawState) {
-    GrAssert(NULL != fDrawState);
-    if (NULL == drawState) {
-        drawState = &fDefaultDrawState;
-    }
-    if (fDrawState != drawState) {
-        fDrawState->unref();
-        drawState->ref();
-        fDrawState = drawState;
-    }
-}
-
 void GrDrawTarget::saveCurrentDrawState(SavedDrawState* state) const {
-    state->fState.set(this->getDrawState());
+    state->fState.set(fCurrDrawState);
 }
 
 void GrDrawTarget::restoreDrawState(const SavedDrawState& state) {
-    *fDrawState = *state.fState.get();
+    fCurrDrawState = *state.fState.get();
 }
 
 void GrDrawTarget::copyDrawState(const GrDrawTarget& srcTarget) {
-    *fDrawState = srcTarget.getDrawState();
+    fCurrDrawState = srcTarget.fCurrDrawState;
 }
 
 bool GrDrawTarget::reserveVertexSpace(GrVertexLayout vertexLayout,
@@ -871,7 +855,7 @@
     }
     // Check if a color stage could create a partial alpha
     for (int s = 0; s < drawState.getFirstCoverageStage(); ++s) {
-        if (StageWillBeUsed(s, layout, this->getDrawState())) {
+        if (StageWillBeUsed(s, layout, fCurrDrawState)) {
             GrAssert(NULL != drawState.getTexture(s));
             GrPixelConfig config = drawState.getTexture(s)->config();
             if (!GrPixelConfigIsOpaque(config)) {
@@ -948,7 +932,7 @@
     for (int s = drawState.getFirstCoverageStage();
          !hasCoverage && s < GrDrawState::kNumStages;
          ++s) {
-        if (StageWillBeUsed(s, layout, this->getDrawState())) {
+        if (StageWillBeUsed(s, layout, fCurrDrawState)) {
             hasCoverage = true;
         }
     }
diff --git a/src/gpu/GrDrawTarget.h b/src/gpu/GrDrawTarget.h
index 731cae5..3a85767 100644
--- a/src/gpu/GrDrawTarget.h
+++ b/src/gpu/GrDrawTarget.h
@@ -86,24 +86,8 @@
      */
     const GrClip& getClip() const;
 
-    /**
-     * Sets the draw state object for the draw target. Note that this does not
-     * make a copy. The GrDrawTarget will take a reference to passed object.
-     * Passing NULL will cause the GrDrawTarget to use its own internal draw
-     * state object rather than an externally provided one.
-     */
-    void setDrawState(GrDrawState*  drawState);
-
-    /**
-     * Read-only access to the GrDrawTarget's current draw state.
-     */
-    const GrDrawState& getDrawState() const { return *fDrawState; }
-
-    /**
-     * Read-write access to the GrDrawTarget's current draw state. Note that
-     * this doesn't ref.
-     */
-    GrDrawState* drawState() { return fDrawState; }
+    const GrDrawState& getDrawState() const { return fCurrDrawState; }
+    GrDrawState* drawState() { return &fCurrDrawState; }
 
     /**
      * Shortcut for drawState()->preConcatSamplerMatrices() on all enabled
@@ -978,7 +962,7 @@
 
     bool isStageEnabled(int stage) const {
         return StageWillBeUsed(stage, this->getGeomSrc().fVertexLayout, 
-                               this->getDrawState());
+                               fCurrDrawState);
     }
 
     StageMask enabledStages() const {
@@ -1057,8 +1041,7 @@
 
     GrClip fClip;
 
-    GrDrawState* fDrawState;
-    GrDrawState fDefaultDrawState;
+    GrDrawState fCurrDrawState;
 
     Caps fCaps;
 
diff --git a/src/gpu/GrInOrderDrawBuffer.cpp b/src/gpu/GrInOrderDrawBuffer.cpp
index 37cac0f..05f9a3f 100644
--- a/src/gpu/GrInOrderDrawBuffer.cpp
+++ b/src/gpu/GrInOrderDrawBuffer.cpp
@@ -509,10 +509,9 @@
     fVertexPool.unlock();
     fIndexPool.unlock();
 
+    GrDrawTarget::AutoStateRestore asr(target);
     GrDrawTarget::AutoClipRestore acr(target);
     AutoGeometryPush agp(target);
-    GrDrawState* prevDrawState = target->drawState();
-    prevDrawState->ref();
 
     int currState = ~0;
     int currClip  = ~0;
@@ -528,8 +527,7 @@
         const Draw& draw = fDraws[i];
         if (draw.fStateChanged) {
             ++currState;
-            GrDrawState* ds = &GrDrawTarget::accessSavedDrawState(fStates[currState]);
-            target->setDrawState(ds);
+            target->restoreDrawState(fStates[currState]);
         }
         if (draw.fClipChanged) {
             ++currClip;
@@ -559,8 +557,6 @@
         target->clear(&fClears[currClear].fRect, fClears[currClear].fColor);
         ++currClear;
     }
-    target->setDrawState(prevDrawState);
-    prevDrawState->unref();
 }
 
 void GrInOrderDrawBuffer::setAutoFlushTarget(GrDrawTarget* target) {
@@ -780,7 +776,7 @@
         return true;
      } else {
         const GrDrawState& old = this->accessSavedDrawState(fStates.back());
-        return old != this->getDrawState();
+        return old != fCurrDrawState;
      }
 }
 
diff --git a/src/gpu/gl/GrGpuGL.cpp b/src/gpu/gl/GrGpuGL.cpp
index 8754ac3..10b42c0 100644
--- a/src/gpu/gl/GrGpuGL.cpp
+++ b/src/gpu/gl/GrGpuGL.cpp
@@ -1911,7 +1911,7 @@
                                   gXfermodeCoeff2Blend[dstCoeff]));
                 fHWDrawState.setBlendFunc(srcCoeff, dstCoeff);
             }
-            GrColor blendConst = this->getDrawState().getBlendConstant();
+            GrColor blendConst = fCurrDrawState.getBlendConstant();
             if ((BlendCoeffReferencesConstant(srcCoeff) ||
                  BlendCoeffReferencesConstant(dstCoeff)) &&
                 fHWDrawState.getBlendConstant() != blendConst) {
@@ -2099,7 +2099,7 @@
     }
 
     if (fHWDrawState.getDrawFace() != drawState->getDrawFace()) {
-        switch (this->getDrawState().getDrawFace()) {
+        switch (fCurrDrawState.getDrawFace()) {
             case GrDrawState::kCCW_DrawFace:
                 GL_CALL(Enable(GR_GL_CULL_FACE));
                 GL_CALL(CullFace(GR_GL_BACK));
@@ -2178,7 +2178,7 @@
     for (int s = 0; s < GrDrawState::kNumStages; ++s) {
         GrDrawState* drawState = this->drawState();
         if (drawState->getTexture(s) == texture) {
-            this->drawState()->setTexture(s, NULL);
+            fCurrDrawState.setTexture(s, NULL);
         }
         if (fHWDrawState.getTexture(s) == texture) {
             // deleting bound texture does implied bind to 0