Start removing calls to GrDrawState::setTexture() (and GrPaint::setTexture()?) when there's
a GrSingleTextureEffect involved holding the texture.

http://codereview.appspot.com/6353094/



git-svn-id: http://skia.googlecode.com/svn/trunk@4608 2bbb7eff-a529-9590-31e7-b0007b416f81
diff --git a/src/gpu/GrDrawState.h b/src/gpu/GrDrawState.h
index c07001c..3de33d8 100644
--- a/src/gpu/GrDrawState.h
+++ b/src/gpu/GrDrawState.h
@@ -209,10 +209,22 @@
      */
     const GrTexture* getTexture(int stage) const {
         GrAssert((unsigned)stage < kNumStages);
+        GrAssert(!this->getSampler(stage).getCustomStage() ||
+                 !fTextures[stage] ||
+                 fTextures[stage] == this->getSampler(stage).getCustomStage()->texture(0));
+        if (this->getSampler(stage).getCustomStage()) {
+            return this->getSampler(stage).getCustomStage()->texture(0);
+        }
         return fTextures[stage];
     }
     GrTexture* getTexture(int stage) {
         GrAssert((unsigned)stage < kNumStages);
+        GrAssert(!this->getSampler(stage).getCustomStage() ||
+                 !fTextures[stage] ||
+                 fTextures[stage] == this->getSampler(stage).getCustomStage()->texture(0));
+        if (this->getSampler(stage).getCustomStage()) {
+            return this->getSampler(stage).getCustomStage()->texture(0);
+        }
         return fTextures[stage];
     }
 
@@ -811,7 +823,7 @@
 
         for (int i = 0; i < kNumStages; i++) {
             SkSafeRef(fTextures[i]);            // already copied by memcpy
-            if (s.fTextures[i]) {
+            if (s.isStageEnabled(i)) {
                 this->fSamplerStates[i] = s.fSamplerStates[i];
             }
         }