Cleanup of r2830.



git-svn-id: http://skia.googlecode.com/svn/trunk@2841 2bbb7eff-a529-9590-31e7-b0007b416f81
diff --git a/src/gpu/GrGpuGL.cpp b/src/gpu/GrGpuGL.cpp
index 9f7e4ec..2a8634f 100644
--- a/src/gpu/GrGpuGL.cpp
+++ b/src/gpu/GrGpuGL.cpp
@@ -480,7 +480,7 @@
 
     GL_CALL(Disable(GR_GL_CULL_FACE));
     GL_CALL(FrontFace(GR_GL_CCW));
-    fHWDrawState.fDrawFace = GrDrawState::kBoth_DrawFace;
+    fHWDrawState.setDrawFace(GrDrawState::kBoth_DrawFace);
 
     GL_CALL(Disable(GR_GL_DITHER));
     if (kDesktop_GrGLBinding == this->glBinding()) {
@@ -492,7 +492,7 @@
     }
 
     GL_CALL(ColorMask(GR_GL_TRUE, GR_GL_TRUE, GR_GL_TRUE, GR_GL_TRUE));
-    fHWDrawState.fFlagBits = 0;
+    fHWDrawState.resetStateFlags();
 
     // we only ever use lines in hairline mode
     GL_CALL(LineWidth(1));
@@ -501,24 +501,22 @@
     fActiveTextureUnitIdx = -1;
 
     // illegal values
-    //fHWDrawState.fSrcBlend = (GrBlendCoeff)(uint8_t)-1;
-    fHWDrawState.fSrcBlend = (GrBlendCoeff)0xFF;
-    fHWDrawState.fDstBlend = (GrBlendCoeff)(uint8_t)-1;
+    fHWDrawState.setBlendFunc((GrBlendCoeff)0xFF, (GrBlendCoeff)0xFF);
 
-    fHWDrawState.fBlendConstant = 0x00000000;
+    fHWDrawState.setBlendConstant(0x00000000);
     GL_CALL(BlendColor(0,0,0,0));
 
-    fHWDrawState.fColor = GrColor_ILLEGAL;
+    fHWDrawState.setColor(GrColor_ILLEGAL);
 
-    fHWDrawState.fViewMatrix = GrMatrix::InvalidMatrix();
+    fHWDrawState.setViewMatrix(GrMatrix::InvalidMatrix());
 
     for (int s = 0; s < GrDrawState::kNumStages; ++s) {
-        fHWDrawState.fTextures[s] = NULL;
-        fHWDrawState.fSamplerStates[s].setRadial2Params(-GR_ScalarMax,
-                                                        -GR_ScalarMax,
-                                                        true);
-        fHWDrawState.fSamplerStates[s].setMatrix(GrMatrix::InvalidMatrix());
-        fHWDrawState.fSamplerStates[s].setConvolutionParams(0, NULL, NULL);
+        fHWDrawState.setTexture(s, NULL);
+        fHWDrawState.sampler(s)->setRadial2Params(-GR_ScalarMax,
+                                                  -GR_ScalarMax,
+                                                  true);
+        fHWDrawState.sampler(s)->setMatrix(GrMatrix::InvalidMatrix());
+        fHWDrawState.sampler(s)->setConvolutionParams(0, NULL, NULL);
     }
 
     fHWBounds.fScissorRect.invalidate();
@@ -526,7 +524,7 @@
     GL_CALL(Disable(GR_GL_SCISSOR_TEST));
     fHWBounds.fViewportRect.invalidate();
 
-    fHWDrawState.fStencilSettings.invalidate();
+    fHWDrawState.stencil()->invalidate();
     fHWStencilClip = false;
     fClipInStencil = false;
 
@@ -536,7 +534,7 @@
     fHWGeometryState.fArrayPtrsDirty = true;
 
     GL_CALL(ColorMask(GR_GL_TRUE, GR_GL_TRUE, GR_GL_TRUE, GR_GL_TRUE));
-    fHWDrawState.fRenderTarget = NULL;
+    fHWDrawState.setRenderTarget(NULL);
 
     // we assume these values
     if (this->glCaps().fUnpackRowLengthSupport) {
@@ -1191,7 +1189,7 @@
         GrGLStencilBuffer* glsb = (GrGLStencilBuffer*) sb;
         GrGLuint rb = glsb->renderbufferID();
 
-        fHWDrawState.fRenderTarget = NULL;
+        fHWDrawState.setRenderTarget(NULL);
         GL_CALL(BindFramebuffer(GR_GL_FRAMEBUFFER, fbo));
         GL_CALL(FramebufferRenderbuffer(GR_GL_FRAMEBUFFER,
                                       GR_GL_STENCIL_ATTACHMENT,
@@ -1276,9 +1274,12 @@
 }
 
 void GrGpuGL::flushScissor(const GrIRect* rect) {
-    GrAssert(NULL != fCurrDrawState.fRenderTarget);
-    const GrGLIRect& vp =
-            ((GrGLRenderTarget*)fCurrDrawState.fRenderTarget)->getViewport();
+    const GrDrawState& drawState = this->getDrawState();
+    const GrGLRenderTarget* rt =
+        static_cast<const GrGLRenderTarget*>(drawState.getRenderTarget());
+
+    GrAssert(NULL != rt);
+    const GrGLIRect& vp = rt->getViewport();
 
     GrGLIRect scissor;
     if (NULL != rect) {
@@ -1307,15 +1308,16 @@
 }
 
 void GrGpuGL::onClear(const GrIRect* rect, GrColor color) {
+    const GrDrawState& drawState = this->getDrawState();
+    const GrRenderTarget* rt = drawState.getRenderTarget();
     // parent class should never let us get here with no RT
-    GrAssert(NULL != fCurrDrawState.fRenderTarget);
+    GrAssert(NULL != rt);
 
     GrIRect clippedRect;
     if (NULL != rect) {
         // flushScissor expects rect to be clipped to the target.
         clippedRect = *rect;
-        GrIRect rtRect = SkIRect::MakeWH(fCurrDrawState.fRenderTarget->width(),
-                                         fCurrDrawState.fRenderTarget->height());
+        GrIRect rtRect = SkIRect::MakeWH(rt->width(), rt->height());
         if (clippedRect.intersect(rtRect)) {
             rect = &clippedRect;
         } else {
@@ -1329,7 +1331,7 @@
     static const GrGLfloat scale255 = 1.f / 255.f;
     a = GrColorUnpackA(color) * scale255;
     GrGLfloat scaleRGB = scale255;
-    if (GrPixelConfigIsUnpremultiplied(fCurrDrawState.fRenderTarget->config())) {
+    if (GrPixelConfigIsUnpremultiplied(rt->config())) {
         scaleRGB *= a;
     }
     r = GrColorUnpackR(color) * scaleRGB;
@@ -1337,13 +1339,13 @@
     b = GrColorUnpackB(color) * scaleRGB;
 
     GL_CALL(ColorMask(GR_GL_TRUE, GR_GL_TRUE, GR_GL_TRUE, GR_GL_TRUE));
-    fHWDrawState.fFlagBits &= ~kNoColorWrites_StateBit;
+    fHWDrawState.disableState(GrDrawState::kNoColorWrites_StateBit);
     GL_CALL(ClearColor(r, g, b, a));
     GL_CALL(Clear(GR_GL_COLOR_BUFFER_BIT));
 }
 
 void GrGpuGL::clearStencil() {
-    if (NULL == fCurrDrawState.fRenderTarget) {
+    if (NULL == this->getDrawState().getRenderTarget()) {
         return;
     }
     
@@ -1356,17 +1358,18 @@
     GL_CALL(StencilMask(0xffffffff));
     GL_CALL(ClearStencil(0));
     GL_CALL(Clear(GR_GL_STENCIL_BUFFER_BIT));
-    fHWDrawState.fStencilSettings.invalidate();
+    fHWDrawState.stencil()->invalidate();
 }
 
 void GrGpuGL::clearStencilClip(const GrIRect& rect, bool insideClip) {
-    GrAssert(NULL != fCurrDrawState.fRenderTarget);
+    const GrDrawState& drawState = this->getDrawState();
+    const GrRenderTarget* rt = drawState.getRenderTarget();
+    GrAssert(NULL != rt);
 
     // this should only be called internally when we know we have a
     // stencil buffer.
-    GrAssert(NULL != fCurrDrawState.fRenderTarget->getStencilBuffer());
-    GrGLint stencilBitCount = 
-        fCurrDrawState.fRenderTarget->getStencilBuffer()->bits();
+    GrAssert(NULL != rt->getStencilBuffer());
+    GrGLint stencilBitCount =  rt->getStencilBuffer()->bits();
 #if 0
     GrAssert(stencilBitCount > 0);
     GrGLint clipStencilMask  = (1 << (stencilBitCount - 1));
@@ -1389,7 +1392,7 @@
     GL_CALL(StencilMask(clipStencilMask));
     GL_CALL(ClearStencil(value));
     GL_CALL(Clear(GR_GL_STENCIL_BUFFER_BIT));
-    fHWDrawState.fStencilSettings.invalidate();
+    fHWDrawState.stencil()->invalidate();
 }
 
 void GrGpuGL::onForceRenderTargetFlush() {
@@ -1445,13 +1448,12 @@
 
     // resolve the render target if necessary
     GrGLRenderTarget* tgt = static_cast<GrGLRenderTarget*>(target);
-    GrAutoTPtrValueRestore<GrRenderTarget*> autoTargetRestore;
+    GrDrawState::AutoRenderTargetRestore artr;
     switch (tgt->getResolveType()) {
         case GrGLRenderTarget::kCantResolve_ResolveType:
             return false;
         case GrGLRenderTarget::kAutoResolves_ResolveType:
-            autoTargetRestore.save(&fCurrDrawState.fRenderTarget);
-            fCurrDrawState.fRenderTarget = target;
+            artr.set(this->drawState(), target);
             this->flushRenderTarget(&GrIRect::EmptyIRect());
             break;
         case GrGLRenderTarget::kCanResolve_ResolveType:
@@ -1549,10 +1551,11 @@
 
 void GrGpuGL::flushRenderTarget(const GrIRect* bound) {
 
-    GrAssert(NULL != fCurrDrawState.fRenderTarget);
+    GrGLRenderTarget* rt =
+        static_cast<GrGLRenderTarget*>(this->drawState()->getRenderTarget());
+    GrAssert(NULL != rt);
 
-    GrGLRenderTarget* rt = (GrGLRenderTarget*)fCurrDrawState.fRenderTarget;
-    if (fHWDrawState.fRenderTarget != fCurrDrawState.fRenderTarget) {
+    if (fHWDrawState.getRenderTarget() != rt) {
         GL_CALL(BindFramebuffer(GR_GL_FRAMEBUFFER, rt->renderFBOID()));
     #if GR_COLLECT_STATS
         ++fStats.fRenderTargetChngCnt;
@@ -1565,7 +1568,7 @@
         }
     #endif
         fDirtyFlags.fRenderTargetChanged = true;
-        fHWDrawState.fRenderTarget = fCurrDrawState.fRenderTarget;
+        fHWDrawState.setRenderTarget(rt);
         const GrGLIRect& vp = rt->getViewport();
         if (fHWBounds.fViewportRect != vp) {
             vp.pushToGLViewport(this->glInterface());
@@ -1682,7 +1685,7 @@
     #endif
         // make sure we go through flushRenderTarget() since we've modified
         // the bound DRAW FBO ID.
-        fHWDrawState.fRenderTarget = NULL;
+        fHWDrawState.setRenderTarget(NULL);
         const GrGLIRect& vp = rt->getViewport();
         const GrIRect dirtyRect = rt->getResolveRect();
         GrGLIRect r;
@@ -1754,21 +1757,25 @@
 GR_STATIC_ASSERT(7 == kInvert_StencilOp);
 
 void GrGpuGL::flushStencil() {
-    const GrStencilSettings* settings = &fCurrDrawState.fStencilSettings;
+    const GrDrawState& drawState = this->getDrawState();
+
+    const GrStencilSettings* settings = &drawState.getStencil();
 
     // use stencil for clipping if clipping is enabled and the clip
     // has been written into the stencil.
-    bool stencilClip = fClipInStencil &&
-                       (kClip_StateBit & fCurrDrawState.fFlagBits);
+    bool stencilClip = fClipInStencil && drawState.isClipState();
+    bool drawClipToStencil =
+        drawState.isStateFlagEnabled(kModifyStencilClip_StateBit);
     bool stencilChange = fHWStencilClip != stencilClip  ||
-                         fHWDrawState.fStencilSettings != *settings ||
-                         ((fHWDrawState.fFlagBits & kModifyStencilClip_StateBit) !=
-                          (fCurrDrawState.fFlagBits & kModifyStencilClip_StateBit));
+                         fHWDrawState.getStencil() != *settings ||
+                         (fHWDrawState.isStateFlagEnabled(kModifyStencilClip_StateBit) !=
+                          drawClipToStencil);
 
     if (stencilChange) {
 
-        // we can't simultaneously perform stencil-clipping and modify the stencil clip
-        GrAssert(!stencilClip || !(fCurrDrawState.fFlagBits & kModifyStencilClip_StateBit));
+        // we can't simultaneously perform stencil-clipping and 
+        // modify the stencil clip
+        GrAssert(!stencilClip || !drawClipToStencil);
 
         if (settings->isDisabled()) {
             if (stencilClip) {
@@ -1793,15 +1800,14 @@
             }
     #endif
             int stencilBits = 0;
-            GrStencilBuffer* stencilBuffer = 
-                            fCurrDrawState.fRenderTarget->getStencilBuffer();
+            GrStencilBuffer* stencilBuffer =
+                drawState.getRenderTarget()->getStencilBuffer();
             if (NULL != stencilBuffer) {
                 stencilBits = stencilBuffer->bits();
             }
             // TODO: dynamically attach a stencil buffer
             GrAssert(stencilBits ||
-                     (GrStencilSettings::gDisabled ==
-                      fCurrDrawState.fStencilSettings));
+                     (GrStencilSettings::gDisabled == *settings));
 
             GrGLuint clipStencilMask = 0;
             GrGLuint userStencilMask = ~0;
@@ -1815,8 +1821,7 @@
             unsigned int frontWriteMask = settings->fFrontWriteMask;
             GrGLenum frontFunc;
 
-            if (fCurrDrawState.fFlagBits & kModifyStencilClip_StateBit) {
-
+            if (drawClipToStencil) {
                 GrAssert(settings->fFrontFunc < kBasicStencilFuncCount);
                 frontFunc = grToGLStencilFunc[settings->fFrontFunc];
             } else {
@@ -1847,7 +1852,7 @@
                 unsigned int backWriteMask = settings->fBackWriteMask;
 
 
-                if (fCurrDrawState.fFlagBits & kModifyStencilClip_StateBit) {
+                if (drawClipToStencil) {
                     GrAssert(settings->fBackFunc < kBasicStencilFuncCount);
                     backFunc = grToGLStencilFunc[settings->fBackFunc];
                 } else {
@@ -1885,12 +1890,13 @@
                                 grToGLStencilOp[settings->fFrontPassOp]));
             }
         }
-        fHWDrawState.fStencilSettings = fCurrDrawState.fStencilSettings;
+        *fHWDrawState.stencil() = *settings;
         fHWStencilClip = stencilClip;
     }
 }
 
 void GrGpuGL::flushAAState(GrPrimitiveType type) {
+    const GrRenderTarget* rt = this->getDrawState().getRenderTarget();
     if (kDesktop_GrGLBinding == this->glBinding()) {
         // ES doesn't support toggling GL_MULTISAMPLE and doesn't have
         // smooth lines.
@@ -1906,13 +1912,13 @@
                 GL_CALL(Disable(GR_GL_LINE_SMOOTH));
                 fHWAAState.fSmoothLineEnabled = false;
             }
-            if (fCurrDrawState.fRenderTarget->isMultisampled() && 
+            if (rt->isMultisampled() && 
                 fHWAAState.fMSAAEnabled) {
                 GL_CALL(Disable(GR_GL_MULTISAMPLE));
                 fHWAAState.fMSAAEnabled = false;
             }
-        } else if (fCurrDrawState.fRenderTarget->isMultisampled() &&
-                   SkToBool(kHWAntialias_StateBit & fCurrDrawState.fFlagBits) !=
+        } else if (rt->isMultisampled() &&
+                   this->getDrawState().isHWAntialiasState() !=
                    fHWAAState.fMSAAEnabled) {
             if (fHWAAState.fMSAAEnabled) {
                 GL_CALL(Disable(GR_GL_MULTISAMPLE));
@@ -1933,12 +1939,11 @@
             GL_CALL(Enable(GR_GL_BLEND));
             fHWBlendDisabled = false;
         }
-        if (kSA_BlendCoeff != fHWDrawState.fSrcBlend ||
-            kISA_BlendCoeff != fHWDrawState.fDstBlend) {
+        if (kSA_BlendCoeff != fHWDrawState.getSrcBlendCoeff() ||
+            kISA_BlendCoeff != fHWDrawState.getDstBlendCoeff()) {
             GL_CALL(BlendFunc(gXfermodeCoeff2Blend[kSA_BlendCoeff],
                               gXfermodeCoeff2Blend[kISA_BlendCoeff]));
-            fHWDrawState.fSrcBlend = kSA_BlendCoeff;
-            fHWDrawState.fDstBlend = kISA_BlendCoeff;
+            fHWDrawState.setBlendFunc(kSA_BlendCoeff, kISA_BlendCoeff);
         }
     } else {
         // any optimization to disable blending should
@@ -1955,25 +1960,25 @@
             fHWBlendDisabled = blendOff;
         }
         if (!blendOff) {
-            if (fHWDrawState.fSrcBlend != srcCoeff ||
-                fHWDrawState.fDstBlend != dstCoeff) {
+            if (fHWDrawState.getSrcBlendCoeff() != srcCoeff ||
+                fHWDrawState.getDstBlendCoeff() != dstCoeff) {
                 GL_CALL(BlendFunc(gXfermodeCoeff2Blend[srcCoeff],
                                   gXfermodeCoeff2Blend[dstCoeff]));
-                fHWDrawState.fSrcBlend = srcCoeff;
-                fHWDrawState.fDstBlend = dstCoeff;
+                fHWDrawState.setBlendFunc(srcCoeff, dstCoeff);
             }
+            GrColor blendConst = fCurrDrawState.getBlendConstant();
             if ((BlendCoeffReferencesConstant(srcCoeff) ||
                  BlendCoeffReferencesConstant(dstCoeff)) &&
-                fHWDrawState.fBlendConstant != fCurrDrawState.fBlendConstant) {
+                fHWDrawState.getBlendConstant() != blendConst) {
 
                 float c[] = {
-                    GrColorUnpackR(fCurrDrawState.fBlendConstant) / 255.f,
-                    GrColorUnpackG(fCurrDrawState.fBlendConstant) / 255.f,
-                    GrColorUnpackB(fCurrDrawState.fBlendConstant) / 255.f,
-                    GrColorUnpackA(fCurrDrawState.fBlendConstant) / 255.f
+                    GrColorUnpackR(blendConst) / 255.f,
+                    GrColorUnpackG(blendConst) / 255.f,
+                    GrColorUnpackB(blendConst) / 255.f,
+                    GrColorUnpackA(blendConst) / 255.f
                 };
                 GL_CALL(BlendColor(c[0], c[1], c[2], c[3]));
-                fHWDrawState.fBlendConstant = fCurrDrawState.fBlendConstant;
+                fHWDrawState.setBlendConstant(blendConst);
             }
         }
     }
@@ -2031,14 +2036,16 @@
 
 bool GrGpuGL::flushGLStateCommon(GrPrimitiveType type) {
 
+    GrDrawState* drawState = this->drawState();
     // GrGpu::setupClipAndFlushState should have already checked this
     // and bailed if not true.
-    GrAssert(NULL != fCurrDrawState.fRenderTarget);
+    GrAssert(NULL != drawState->getRenderTarget());
 
     for (int s = 0; s < GrDrawState::kNumStages; ++s) {
         // bind texture and set sampler state
         if (this->isStageEnabled(s)) {
-            GrGLTexture* nextTexture = (GrGLTexture*)fCurrDrawState.fTextures[s];
+            GrGLTexture* nextTexture = 
+                static_cast<GrGLTexture*>(drawState->getTexture(s));
 
             // true for now, but maybe not with GrEffect.
             GrAssert(NULL != nextTexture);
@@ -2052,20 +2059,20 @@
                 resolveRenderTarget(texRT);
             }
 
-            if (fHWDrawState.fTextures[s] != nextTexture) {
+            if (fHWDrawState.getTexture(s) != nextTexture) {
                 setTextureUnit(s);
                 GL_CALL(BindTexture(GR_GL_TEXTURE_2D, nextTexture->textureID()));
             #if GR_COLLECT_STATS
                 ++fStats.fTextureChngCnt;
             #endif
                 //GrPrintf("---- bindtexture %d\n", nextTexture->textureID());
-                fHWDrawState.fTextures[s] = nextTexture;
+                fHWDrawState.setTexture(s, nextTexture);
                 // The texture matrix has to compensate for texture width/height
                 // and NPOT-embedded-in-POT
                 fDirtyFlags.fTextureChangedMask |= (1 << s);
             }
 
-            const GrSamplerState& sampler = fCurrDrawState.fSamplerStates[s];
+            const GrSamplerState& sampler = drawState->getSampler(s);
             ResetTimestamp timestamp;
             const GrGLTexture::TexParams& oldTexParams =
                                     nextTexture->getCachedTexParams(&timestamp);
@@ -2117,7 +2124,7 @@
 
     GrIRect* rect = NULL;
     GrIRect clipBounds;
-    if ((fCurrDrawState.fFlagBits & kClip_StateBit) &&
+    if (drawState->isClipState() &&
         fClip.hasConservativeBounds()) {
         fClip.getConservativeBounds().roundOut(&clipBounds);
         rect = &clipBounds;
@@ -2125,19 +2132,18 @@
     this->flushRenderTarget(rect);
     this->flushAAState(type);
     
-    if ((fCurrDrawState.fFlagBits & kDither_StateBit) !=
-        (fHWDrawState.fFlagBits & kDither_StateBit)) {
-        if (fCurrDrawState.fFlagBits & kDither_StateBit) {
+    if (drawState->isDitherState() != fHWDrawState.isDitherState()) {
+        if (drawState->isDitherState()) {
             GL_CALL(Enable(GR_GL_DITHER));
         } else {
             GL_CALL(Disable(GR_GL_DITHER));
         }
     }
 
-    if ((fCurrDrawState.fFlagBits & kNoColorWrites_StateBit) !=
-        (fHWDrawState.fFlagBits & kNoColorWrites_StateBit)) {
+    if (drawState->isColorWriteDisabled() !=
+        fHWDrawState.isColorWriteDisabled()) {
         GrGLenum mask;
-        if (fCurrDrawState.fFlagBits & kNoColorWrites_StateBit) {
+        if (drawState->isColorWriteDisabled()) {
             mask = GR_GL_FALSE;
         } else {
             mask = GR_GL_TRUE;
@@ -2145,8 +2151,8 @@
         GL_CALL(ColorMask(mask, mask, mask, mask));
     }
 
-    if (fHWDrawState.fDrawFace != fCurrDrawState.fDrawFace) {
-        switch (fCurrDrawState.fDrawFace) {
+    if (fHWDrawState.getDrawFace() != drawState->getDrawFace()) {
+        switch (fCurrDrawState.getDrawFace()) {
             case GrDrawState::kCCW_DrawFace:
                 GL_CALL(Enable(GR_GL_CULL_FACE));
                 GL_CALL(CullFace(GR_GL_BACK));
@@ -2161,24 +2167,26 @@
             default:
                 GrCrash("Unknown draw face.");
         }
-        fHWDrawState.fDrawFace = fCurrDrawState.fDrawFace;
+        fHWDrawState.setDrawFace(drawState->getDrawFace());
     }
 
 #if GR_DEBUG
     // check for circular rendering
     for (int s = 0; s < GrDrawState::kNumStages; ++s) {
         GrAssert(!this->isStageEnabled(s) ||
-                 NULL == fCurrDrawState.fRenderTarget ||
-                 NULL == fCurrDrawState.fTextures[s] ||
-                 fCurrDrawState.fTextures[s]->asRenderTarget() !=
-                    fCurrDrawState.fRenderTarget);
+                 NULL == drawState->getRenderTarget() ||
+                 NULL == drawState->getTexture(s) ||
+                 drawState->getTexture(s)->asRenderTarget() !=
+                    drawState->getRenderTarget());
     }
 #endif
 
-    flushStencil();
+    this->flushStencil();
 
-    // flushStencil may look at the private state bits, so keep it before this.
-    fHWDrawState.fFlagBits = fCurrDrawState.fFlagBits;
+    // This copy must happen after flushStencil() is called. flushStencil()
+    // relies on detecting when the kModifyStencilClip_StateBit state has
+    // changed since the last draw.
+    fHWDrawState.copyStateFlags(*drawState);
     return true;
 }
 
@@ -2210,22 +2218,24 @@
 
 void GrGpuGL::notifyRenderTargetDelete(GrRenderTarget* renderTarget) {
     GrAssert(NULL != renderTarget);
-    if (fCurrDrawState.fRenderTarget == renderTarget) {
-        fCurrDrawState.fRenderTarget = NULL;
+    GrDrawState* drawState = this->drawState();
+    if (drawState->getRenderTarget() == renderTarget) {
+        drawState->setRenderTarget(NULL);
     }
-    if (fHWDrawState.fRenderTarget == renderTarget) {
-        fHWDrawState.fRenderTarget = NULL;
+    if (fHWDrawState.getRenderTarget() == renderTarget) {
+        fHWDrawState.setRenderTarget(NULL);
     }
 }
 
 void GrGpuGL::notifyTextureDelete(GrGLTexture* texture) {
     for (int s = 0; s < GrDrawState::kNumStages; ++s) {
-        if (fCurrDrawState.fTextures[s] == texture) {
-            fCurrDrawState.fTextures[s] = NULL;
+        GrDrawState* drawState = this->drawState();
+        if (drawState->getTexture(s) == texture) {
+            fCurrDrawState.setTexture(s, NULL);
         }
-        if (fHWDrawState.fTextures[s] == texture) {
+        if (fHWDrawState.getTexture(s) == texture) {
             // deleting bound texture does implied bind to 0
-            fHWDrawState.fTextures[s] = NULL;
+            fHWDrawState.setTexture(s, NULL);
        }
     }
 }