Fix for performance regression due to r3832

http://codereview.appspot.com/6188045/



git-svn-id: http://skia.googlecode.com/svn/trunk@3840 2bbb7eff-a529-9590-31e7-b0007b416f81
diff --git a/src/gpu/GrDrawState.h b/src/gpu/GrDrawState.h
index 6313408..386aebd 100644
--- a/src/gpu/GrDrawState.h
+++ b/src/gpu/GrDrawState.h
@@ -80,6 +80,7 @@
         fSrcBlend = kOne_BlendCoeff;
         fDstBlend = kZero_BlendCoeff;
         fViewMatrix.reset();
+        fBehaviorBits = 0;
 
         // ensure values that will be memcmp'ed in == but not memset in reset()
         // are tightly packed
@@ -170,7 +171,7 @@
     void setTexture(int stage, GrTexture* texture) {
         GrAssert((unsigned)stage < kNumStages);
 
-        if (isStateFlagEnabled(kTexturesNeedRef_StateBit)) {
+        if (isBehaviorEnabled(kTexturesNeedRef_BehaviorBit)) {
             // If we don't clear out the current texture before unreffing
             // it we can get into an infinite loop as the GrGLTexture's
             // onRelease method recursively calls setTexture
@@ -669,10 +670,6 @@
          * ignored.
          */
         kColorMatrix_StateBit   = 0x20,
-        /**
-         * Calls to setTexture will ref/unref the texture
-         */
-        kTexturesNeedRef_StateBit = 0x40,
 
         // Users of the class may add additional bits to the vector
         kDummyStateBit,
@@ -729,6 +726,28 @@
         fFlagBits = ds.fFlagBits;
     }
 
+    /**
+     *  Flags that do not affect rendering. 
+     */
+    enum GrBehaviorBits {
+        /**
+         * Calls to setTexture will ref/unref the texture
+         */
+        kTexturesNeedRef_BehaviorBit = 0x01,
+    };
+
+    void enableBehavior(uint32_t behaviorBits) {
+        fBehaviorBits |= behaviorBits;
+    }
+
+    void disableBehavior(uint32_t behaviorBits) {
+        fBehaviorBits &= ~(behaviorBits);
+    }
+
+    bool isBehaviorEnabled(uint32_t behaviorBits) const {
+        return 0 != (behaviorBits & fBehaviorBits);
+    }
+
     /// @}
 
     ///////////////////////////////////////////////////////////////////////////
@@ -771,6 +790,14 @@
             return false;
         }
 
+        // kTexturesNeedRef is an internal flag for altering the draw state's 
+        // behavior rather than a property that will impact drawing - ignore it
+        // here
+        if ((fBehaviorBits & ~kTexturesNeedRef_BehaviorBit) != 
+            (s.fBehaviorBits & ~kTexturesNeedRef_BehaviorBit)) {
+            return false;
+        }
+
         for (int i = 0; i < kNumStages; i++) {
             if (fTextures[i] &&
                 this->fSamplerStates[i] != s.fSamplerStates[i]) {
@@ -795,6 +822,7 @@
         memcpy(this->podStart(), s.podStart(), this->podSize());
 
         fViewMatrix = s.fViewMatrix;
+        fBehaviorBits = s.fBehaviorBits;
 
         GrAssert(0 == s.fEdgeAANumEdges);
         fEdgeAANumEdges = 0;
@@ -865,6 +893,7 @@
     };
     // @}
 
+    uint32_t            fBehaviorBits;
     GrMatrix            fViewMatrix;
 
     // @{ Data for GrTesselatedPathRenderer
diff --git a/src/gpu/GrInOrderDrawBuffer.cpp b/src/gpu/GrInOrderDrawBuffer.cpp
index de49e8c..553bacc 100644
--- a/src/gpu/GrInOrderDrawBuffer.cpp
+++ b/src/gpu/GrInOrderDrawBuffer.cpp
@@ -469,7 +469,7 @@
 
         // GrInOrderDrawBuffer is no longer managing the refs/unrefs 
         // for the stored GrDrawStates
-        fStates[i].disableState(GrDrawState::kTexturesNeedRef_StateBit);
+        fStates[i].disableBehavior(GrDrawState::kTexturesNeedRef_BehaviorBit);
     }
     int numDraws = fDraws.count();
     for (int d = 0; d < numDraws; ++d) {
@@ -789,7 +789,7 @@
 
     // Any textures that are added to the stored state need to be
     // reffed so the unref in reset doesn't inappropriately free them
-    fStates.back().enableState(GrDrawState::kTexturesNeedRef_StateBit);
+    fStates.back().enableBehavior(GrDrawState::kTexturesNeedRef_BehaviorBit);
  }
 
 bool GrInOrderDrawBuffer::needsNewClip() const {
diff --git a/src/gpu/gl/GrGpuGL.cpp b/src/gpu/gl/GrGpuGL.cpp
index a06b008..9aa9b31 100644
--- a/src/gpu/gl/GrGpuGL.cpp
+++ b/src/gpu/gl/GrGpuGL.cpp
@@ -2239,8 +2239,10 @@
     // relies on detecting when the kModifyStencilClip_StateBit state has
     // changed since the last draw.
     fHWDrawState.copyStateFlags(*drawState);
+
+    // TODO: may no longer need this
     // only GrInOrderDrawBuffer ever needs to ref/unref the textures
-    fHWDrawState.disableState(GrDrawState::kTexturesNeedRef_StateBit);
+    fHWDrawState.disableBehavior(GrDrawState::kTexturesNeedRef_BehaviorBit);
     return true;
 }