Make GrDrawState a real class with getters and setters
Review URL: http://codereview.appspot.com/5448119/



git-svn-id: http://skia.googlecode.com/svn/trunk@2830 2bbb7eff-a529-9590-31e7-b0007b416f81
diff --git a/src/gpu/GrDrawTarget.cpp b/src/gpu/GrDrawTarget.cpp
index 7a84262..2d1563d 100644
--- a/src/gpu/GrDrawTarget.cpp
+++ b/src/gpu/GrDrawTarget.cpp
@@ -455,119 +455,6 @@
     return fClip;
 }
 
-void GrDrawTarget::setTexture(int stage, GrTexture* tex) {
-    GrAssert(stage >= 0 && stage < GrDrawState::kNumStages);
-    fCurrDrawState.fTextures[stage] = tex;
-}
-
-const GrTexture* GrDrawTarget::getTexture(int stage) const {
-    GrAssert(stage >= 0 && stage < GrDrawState::kNumStages);
-    return fCurrDrawState.fTextures[stage];
-}
-
-GrTexture* GrDrawTarget::getTexture(int stage) {
-    GrAssert(stage >= 0 && stage < GrDrawState::kNumStages);
-    return fCurrDrawState.fTextures[stage];
-}
-
-void GrDrawTarget::setRenderTarget(GrRenderTarget* target) {
-    fCurrDrawState.fRenderTarget = target;
-}
-
-const GrRenderTarget* GrDrawTarget::getRenderTarget() const {
-    return fCurrDrawState.fRenderTarget;
-}
-
-GrRenderTarget* GrDrawTarget::getRenderTarget() {
-    return fCurrDrawState.fRenderTarget;
-}
-
-void GrDrawTarget::setViewMatrix(const GrMatrix& m) {
-    fCurrDrawState.fViewMatrix = m;
-}
-
-void GrDrawTarget::preConcatViewMatrix(const GrMatrix& matrix) {
-    fCurrDrawState.fViewMatrix.preConcat(matrix);
-}
-
-void GrDrawTarget::postConcatViewMatrix(const GrMatrix& matrix) {
-    fCurrDrawState.fViewMatrix.postConcat(matrix);
-}
-
-const GrMatrix& GrDrawTarget::getViewMatrix() const {
-    return fCurrDrawState.fViewMatrix;
-}
-
-bool GrDrawTarget::getViewInverse(GrMatrix* matrix) const {
-    // Mike:  Can we cache this somewhere?
-    // Brian: Sure, do we use it often?
-
-    GrMatrix inverse;
-    if (fCurrDrawState.fViewMatrix.invert(&inverse)) {
-        if (matrix) {
-            *matrix = inverse;
-        }
-        return true;
-    }
-    return false;
-}
-
-void GrDrawTarget::setSamplerState(int stage, const GrSamplerState& state) {
-    GrAssert(stage >= 0 && stage < GrDrawState::kNumStages);
-    fCurrDrawState.fSamplerStates[stage] = state;
-}
-
-void GrDrawTarget::enableState(uint32_t bits) {
-    fCurrDrawState.fFlagBits |= bits;
-}
-
-void GrDrawTarget::disableState(uint32_t bits) {
-    fCurrDrawState.fFlagBits &= ~(bits);
-}
-
-void GrDrawTarget::setBlendFunc(GrBlendCoeff srcCoeff,
-                                GrBlendCoeff dstCoeff) {
-    fCurrDrawState.fSrcBlend = srcCoeff;
-    fCurrDrawState.fDstBlend = dstCoeff;
-#if GR_DEBUG
-    switch (dstCoeff) {
-    case kDC_BlendCoeff:
-    case kIDC_BlendCoeff:
-    case kDA_BlendCoeff:
-    case kIDA_BlendCoeff:
-        GrPrintf("Unexpected dst blend coeff. Won't work correctly with"
-                 "coverage stages.\n");
-        break;
-    default:
-        break;
-    }
-    switch (srcCoeff) {
-    case kSC_BlendCoeff:
-    case kISC_BlendCoeff:
-    case kSA_BlendCoeff:
-    case kISA_BlendCoeff:
-        GrPrintf("Unexpected src blend coeff. Won't work correctly with"
-                 "coverage stages.\n");
-        break;
-    default:
-        break;
-    }
-#endif
-}
-
-void GrDrawTarget::setColor(GrColor c) {
-    fCurrDrawState.fColor = c;
-}
-
-void GrDrawTarget::setColorFilter(GrColor c, SkXfermode::Mode mode) {
-    fCurrDrawState.fColorFilterColor = c;
-    fCurrDrawState.fColorFilterXfermode = mode;
-}
-
-void GrDrawTarget::setAlpha(uint8_t a) {
-    this->setColor((a << 24) | (a << 16) | (a << 8) | a);
-}
-
 void GrDrawTarget::saveCurrentDrawState(SavedDrawState* state) const {
     state->fState = fCurrDrawState;
 }
@@ -804,8 +691,8 @@
         return false;
     }
     if (GrPixelConfigIsUnpremultiplied(this->getRenderTarget()->config())) {
-        if (kOne_BlendCoeff != fCurrDrawState.fSrcBlend ||
-            kZero_BlendCoeff != fCurrDrawState.fDstBlend) {
+        if (kOne_BlendCoeff != getDrawState().getSrcBlendCoeff() ||
+            kZero_BlendCoeff != getDrawState().getDstBlendCoeff()) {
             return false;
         }
     }
@@ -817,8 +704,8 @@
         // a custom bilerp in the shader. Until Skia itself supports unpremul
         // configs there is no pressure to implement this.
         if (this->isStageEnabled(s) &&
-            GrPixelConfigIsUnpremultiplied(fCurrDrawState.fTextures[s]->config()) &&
-            GrSamplerState::kNearest_Filter != fCurrDrawState.fSamplerStates[s].getFilter()) {
+            GrPixelConfigIsUnpremultiplied(this->getTexture(s)->config()) &&
+            GrSamplerState::kNearest_Filter != this->getSampler(s).getFilter()) {
             return false;
         }
     }
@@ -861,9 +748,10 @@
      * for Cd we find that only 1, ISA, and ISC produce the correct depth
      * coeffecient in terms of S' and D.
      */
-    return kOne_BlendCoeff == fCurrDrawState.fDstBlend||
-           kISA_BlendCoeff == fCurrDrawState.fDstBlend ||
-           kISC_BlendCoeff == fCurrDrawState.fDstBlend;
+    GrBlendCoeff dstCoeff = this->getDrawState().getDstBlendCoeff();
+    return kOne_BlendCoeff == dstCoeff ||
+           kISA_BlendCoeff == dstCoeff ||
+           kISC_BlendCoeff == dstCoeff;
 }
 
 
@@ -872,20 +760,21 @@
 
     // Check if per-vertex or constant color may have partial alpha
     if ((layout & kColor_VertexLayoutBit) ||
-        0xff != GrColorUnpackA(fCurrDrawState.fColor)) {
+        0xff != GrColorUnpackA(this->getColor())) {
         return false;
     }
     // Check if color filter could introduce an alpha
     // (TODO: Consider being more aggressive with regards to detecting 0xff
     // final alpha from color filter).
-    if (SkXfermode::kDst_Mode != fCurrDrawState.fColorFilterXfermode) {
+    if (SkXfermode::kDst_Mode != this->getDrawState().getColorFilterMode()) {
         return false;
     }
     // Check if a color stage could create a partial alpha
-    for (int s = 0; s < fCurrDrawState.fFirstCoverageStage; ++s) {
+    int firstCoverageStage = this->getFirstCoverageStage();
+    for (int s = 0; s < firstCoverageStage; ++s) {
         if (StageWillBeUsed(s, layout, fCurrDrawState)) {
-            GrAssert(NULL != fCurrDrawState.fTextures[s]);
-            GrPixelConfig config = fCurrDrawState.fTextures[s]->config();
+            GrAssert(NULL != this->getTexture(s));
+            GrPixelConfig config = this->getTexture(s)->config();
             if (!GrPixelConfigIsOpaque(config)) {
                 return false;
             }
@@ -905,12 +794,12 @@
     if (NULL == srcCoeff) {
         srcCoeff = &bogusSrcCoeff;
     }
-    *srcCoeff = fCurrDrawState.fSrcBlend;
+    *srcCoeff = this->getDrawState().getSrcBlendCoeff();
 
     if (NULL == dstCoeff) {
         dstCoeff = &bogusDstCoeff;
     }
-    *dstCoeff = fCurrDrawState.fDstBlend;
+    *dstCoeff = this->getDrawState().getDstBlendCoeff();
 
     // We don't ever expect source coeffecients to reference the source
     GrAssert(kSA_BlendCoeff != *srcCoeff &&
@@ -923,7 +812,7 @@
              kDC_BlendCoeff != *dstCoeff &&
              kIDC_BlendCoeff != *dstCoeff);
 
-    if (SkToBool(kNoColorWrites_StateBit & fCurrDrawState.fFlagBits)) {
+    if (this->getDrawState().isColorWriteDisabled()) {
         *srcCoeff = kZero_BlendCoeff;
         *dstCoeff = kOne_BlendCoeff;
     }
@@ -939,7 +828,7 @@
     // stenciling is enabled. Having color writes disabled is effectively
     // (0,1).
     if ((kZero_BlendCoeff == *srcCoeff && dstCoeffIsOne)) {
-        if (fCurrDrawState.fStencilSettings.doesWrite()) {
+        if (this->getDrawState().getStencil().doesWrite()) {
             if (fCaps.fShaderSupport) {
                 return kDisableBlend_BlendOptFlag |
                        kEmitTransBlack_BlendOptFlag;
@@ -953,10 +842,10 @@
 
     // check for coverage due to edge aa or coverage texture stage
     bool hasCoverage = forceCoverage ||
-                       fCurrDrawState.fEdgeAANumEdges > 0 ||
+                       this->getDrawState().getNumAAEdges() > 0 ||
                        (layout & kCoverage_VertexLayoutBit) ||
                        (layout & kEdge_VertexLayoutBit);
-    for (int s = fCurrDrawState.fFirstCoverageStage;
+    for (int s = this->getFirstCoverageStage();
          !hasCoverage && s < GrDrawState::kNumStages;
          ++s) {
         if (StageWillBeUsed(s, layout, fCurrDrawState)) {
@@ -1023,7 +912,7 @@
     // but not in a premul-alpha way. So we only use them when our alpha
     // is 0xff and tweaking the color for partial coverage is OK
     if (!fCaps.fHWAALineSupport ||
-        !(kHWAntialias_StateBit & fCurrDrawState.fFlagBits)) {
+        !(this->getDrawState().isHWAntialiasState())) {
         return false;
     }
     BlendOptFlags opts = this->getBlendOpts();
@@ -1043,16 +932,6 @@
                     this->getBlendOpts());
 }
 
-///////////////////////////////////////////////////////////////////////////////
-
-void GrDrawTarget::setEdgeAAData(const GrDrawState::Edge* edges, int numEdges) {
-    GrAssert(numEdges <= GrDrawState::kMaxEdges);
-    memcpy(fCurrDrawState.fEdgeAAEdges, edges,
-           numEdges * sizeof(GrDrawState::Edge));
-    fCurrDrawState.fEdgeAANumEdges = numEdges;
-}
-
-
 ////////////////////////////////////////////////////////////////////////////////
 
 void GrDrawTarget::drawRect(const GrRect& rect, 
@@ -1068,13 +947,13 @@
         return;
     }
 
-    SetRectVertices(rect, matrix, srcRects, 
+    SetRectVertices(rect, matrix, srcRects,
                     srcMatrices, layout, geo.vertices());
 
     drawNonIndexed(kTriangleFan_PrimitiveType, 0, 4);
 }
 
-GrVertexLayout GrDrawTarget::GetRectVertexLayout(StageMask stageMask, 
+GrVertexLayout GrDrawTarget::GetRectVertexLayout(StageMask stageMask,
                                                  const GrRect* srcRects[]) {
     GrVertexLayout layout = 0;
 
@@ -1183,7 +1062,7 @@
         if (fViewMatrix.invert(&invVM)) {
             for (int s = 0; s < GrDrawState::kNumStages; ++s) {
                 if (fStageMask & (1 << s)) {
-                    fSamplerMatrices[s] = target->getSamplerMatrix(s);
+                    fSamplerMatrices[s] = target->getSampler(s).getMatrix();
                 }
             }
             target->preConcatSamplerMatrices(fStageMask, invVM);
@@ -1199,7 +1078,8 @@
     fDrawTarget->setViewMatrix(fViewMatrix);
     for (int s = 0; s < GrDrawState::kNumStages; ++s) {
         if (fStageMask & (1 << s)) {
-            fDrawTarget->setSamplerMatrix(s, fSamplerMatrices[s]);
+            GrSamplerState* sampler = fDrawTarget->drawState()->sampler(s);
+            sampler->setMatrix(fSamplerMatrices[s]);
         }
     }
 }