Remove GrDrawState::setTexture/getTexture

Review URL: http://codereview.appspot.com/6455051/



git-svn-id: http://skia.googlecode.com/svn/trunk@4826 2bbb7eff-a529-9590-31e7-b0007b416f81
diff --git a/src/gpu/GrDrawTarget.cpp b/src/gpu/GrDrawTarget.cpp
index 8afe5b9..f0f1864 100644
--- a/src/gpu/GrDrawTarget.cpp
+++ b/src/gpu/GrDrawTarget.cpp
@@ -707,6 +707,7 @@
 bool GrDrawTarget::checkDraw(GrPrimitiveType type, int startVertex,
                              int startIndex, int vertexCount,
                              int indexCount) const {
+    const GrDrawState& drawState = this->getDrawState();
 #if GR_DEBUG
     const GeometrySrcState& geoSrc = fGeoSrcStateStack.back();
     int maxVertex = startVertex + vertexCount;
@@ -744,15 +745,18 @@
         }
     }
 
-    GrAssert(NULL != this->getDrawState().getRenderTarget());
-    for (int i = 0; i < GrDrawState::kNumStages; ++i) {
-        if (this->getDrawState().getTexture(i)) {
-            GrAssert(this->getDrawState().getTexture(i)->asRenderTarget() != 
-                     this->getDrawState().getRenderTarget());
+    GrAssert(NULL != drawState.getRenderTarget());
+    for (int s = 0; s < GrDrawState::kNumStages; ++s) {
+        if (drawState.isStageEnabled(s)) {
+            const GrCustomStage* stage = drawState.getSampler(s).getCustomStage();
+            int numTextures = stage->numTextures();
+            for (int t = 0; t < numTextures; ++t) {
+                GrTexture* texture = stage->texture(t);
+                GrAssert(texture->asRenderTarget() != drawState.getRenderTarget());
+            }
         }
     }
 #endif
-    const GrDrawState& drawState = this->getDrawState();
     if (NULL == drawState.getRenderTarget()) {
         return false;
     }
@@ -762,15 +766,21 @@
             return false;
         }
     }
+    // We don't support using unpremultiplied textures with bilerp. Alpha-multiplication is not
+    // distributive with respect to filtering. We'd have to alpha-mul each texel before filtering.
+    // Until Skia itself supports unpremultiplied configs there is no pressure to implement this.
     for (int s = 0; s < GrDrawState::kNumStages; ++s) {
-        // We don't support using unpremultiplied textures with bilerp. Alpha-multiplication is not
-        // distributive with respect to filtering. We'd have to alpha-mul each texel before
-        // filtering. Until Skia itself supports unpremultiplied configs there is no pressure to
-        // implement this.
-        if (drawState.getTexture(s) &&
-            GrPixelConfigIsUnpremultiplied(drawState.getTexture(s)->config()) &&
-            drawState.getSampler(s).getTextureParams().isBilerp()) {
-            return false;
+        if (drawState.isStageEnabled(s)) {
+            const GrCustomStage* stage = drawState.getSampler(s).getCustomStage();
+            int numTextures = stage->numTextures();
+            for (int t = 0; t < numTextures; ++t) {
+                GrTexture* texture = stage->texture(t);
+                GrAssert(NULL != texture);
+                if (GrPixelConfigIsUnpremultiplied(texture->config()) &&
+                    drawState.getSampler(s).getTextureParams().isBilerp()) {
+                    return false;
+                }
+            }
         }
     }
     return true;
@@ -844,9 +854,11 @@
     // Check if a color stage could create a partial alpha
     for (int s = 0; s < drawState.getFirstCoverageStage(); ++s) {
         if (this->isStageEnabled(s)) {
-            GrAssert(NULL != drawState.getTexture(s));
-            GrPixelConfig config = drawState.getTexture(s)->config();
-            if (!GrPixelConfigIsOpaque(config)) {
+            const GrCustomStage* stage = drawState.getSampler(s).getCustomStage();
+            // FIXME: The param indicates whether the texture is opaque or not. However, the stage
+            // already controls its textures. It really needs to know whether the incoming color
+            // (from a uni, per-vertex colors, or previous stage) is opaque or not.
+            if (!stage->isOpaque(true)) {
                 return false;
             }
         }