Remove easily-removable uses of setTexture(), instead creating a GrSingleTextureEffect -
where feasible, through convenience function on GrDrawState.

http://codereview.appspot.com/6425055/



git-svn-id: http://skia.googlecode.com/svn/trunk@4694 2bbb7eff-a529-9590-31e7-b0007b416f81
diff --git a/src/gpu/SkGpuDevice.cpp b/src/gpu/SkGpuDevice.cpp
index 32d5883..1dc17fb 100644
--- a/src/gpu/SkGpuDevice.cpp
+++ b/src/gpu/SkGpuDevice.cpp
@@ -425,7 +425,13 @@
 
 bool SkGpuDevice::bindDeviceAsTexture(GrPaint* paint) {
     if (NULL != fTexture) {
+        // FIXME: cannot use GrSingleTextureEffect here: fails
+        // assert in line 1617: null != devTex; generalizing GrPaint::getTexture()
+        // to grab textures off of GrCustomStages breaks gms in various ways -
+        // particularly since table color filter requires multiple textures
         paint->setTexture(kBitmapTextureIdx, fTexture);
+        //paint->textureSampler(kBitmapTextureIdx)->setCustomStage(
+            //SkNEW_ARGS(GrSingleTextureEffect, (fTexture)))->unref();
         return true;
     }
     return false;
@@ -486,7 +492,7 @@
         GrAssert(!constantColor);
     } else {
         grPaint->fColor = SkColor2GrColor(skPaint.getColor());
-        grPaint->setTexture(kShaderTextureIdx, NULL);
+        GrAssert(NULL == grPaint->getTexture(kShaderTextureIdx));
     }
     SkColorFilter* colorFilter = skPaint.getColorFilter();
     SkColor color;
@@ -616,9 +622,7 @@
             } else {
                 sampler->setFilter(GrSamplerState::kNearest_Filter);
             }
-            // TODO - once we have a trivial GrCustomStage for texture drawing,
-            // create that here & get rid of the paint's texture
-            grPaint->setTexture(kShaderTextureIdx, texture);
+            sampler->setCustomStage(SkNEW_ARGS(GrSingleTextureEffect, (texture)))->unref();
             break;
     }
     sampler->setWrapX(sk_tile_mode_to_grwrap(tileModes[0]));
@@ -904,7 +908,8 @@
                                                    pathTexture->height());
         // Blend pathTexture over blurTexture.
         context->setRenderTarget(blurTexture->asRenderTarget());
-        paint.setTexture(0, pathTexture);
+        paint.textureSampler(0)->setCustomStage(SkNEW_ARGS
+            (GrSingleTextureEffect, (pathTexture)))->unref();
         if (SkMaskFilter::kInner_BlurType == blurType) {
             // inner:  dst = dst * src
             paint.fSrcBlendCoeff = kDC_GrBlendCoeff;
@@ -1409,7 +1414,8 @@
         return;
     }
 
-    grPaint->setTexture(kBitmapTextureIdx, texture);
+    grPaint->textureSampler(kBitmapTextureIdx)->setCustomStage(SkNEW_ARGS
+        (GrSingleTextureEffect, (texture)))->unref();
 
     GrRect dstRect = SkRect::MakeWH(GrIntToScalar(srcRect.width()),
                                     GrIntToScalar(srcRect.height()));
@@ -1558,14 +1564,16 @@
     GrTexture* texture;
     sampler->reset();
     SkAutoCachedTexture act(this, bitmap, sampler, &texture);
-    grPaint.setTexture(kBitmapTextureIdx, texture);
+    grPaint.textureSampler(kBitmapTextureIdx)->setCustomStage(SkNEW_ARGS
+        (GrSingleTextureEffect, (texture)))->unref();
 
     SkImageFilter* filter = paint.getImageFilter();
     if (NULL != filter) {
         GrTexture* filteredTexture = filter_texture(fContext, texture, filter,
                  GrRect::MakeWH(SkIntToScalar(w), SkIntToScalar(h)));
         if (filteredTexture) {
-            grPaint.setTexture(kBitmapTextureIdx, filteredTexture);
+            grPaint.textureSampler(kBitmapTextureIdx)->setCustomStage(SkNEW_ARGS
+                (GrSingleTextureEffect, (filteredTexture)))->unref();
             texture = filteredTexture;
             filteredTexture->unref();
         }
@@ -1608,7 +1616,8 @@
         GrTexture* filteredTexture = filter_texture(fContext, devTex, filter,
                                                     rect);
         if (filteredTexture) {
-            grPaint.setTexture(kBitmapTextureIdx, filteredTexture);
+            grPaint.textureSampler(kBitmapTextureIdx)->setCustomStage(SkNEW_ARGS
+                (GrSingleTextureEffect, (filteredTexture)))->unref();
             devTex = filteredTexture;
             filteredTexture->unref();
         }