Introduces new SingleTextureEffect base class for GrCustomStage objects.
This class tracks the texture that the object uses. A future commit will get rid of the
GrTexture pointer currenty stored in the GrDrawState, allowing us to have CustomStages
*without* textures.

Requires gyp change on next roll.

http://codereview.appspot.com/6306097/



git-svn-id: http://skia.googlecode.com/svn/trunk@4576 2bbb7eff-a529-9590-31e7-b0007b416f81
diff --git a/src/gpu/SkGpuDevice.cpp b/src/gpu/SkGpuDevice.cpp
index 2a2bbcd..1154313 100644
--- a/src/gpu/SkGpuDevice.cpp
+++ b/src/gpu/SkGpuDevice.cpp
@@ -536,26 +536,36 @@
         }
         return false;
     }
+
     GrSamplerState* sampler = grPaint->textureSampler(kShaderTextureIdx);
+    GrTexture* texture = act->set(dev, bitmap, sampler);
+    if (NULL == texture) {
+        SkDebugf("Couldn't convert bitmap to texture.\n");
+        return false;
+    }
+    grPaint->setTexture(kShaderTextureIdx, texture);
+
     switch (bmptype) {
         case SkShader::kRadial_BitmapType:
-            sampler->setCustomStage(SkNEW(GrRadialGradient))->unref();
+            sampler->setCustomStage(SkNEW_ARGS(GrRadialGradient, (texture)))->unref();
             sampler->setFilter(GrSamplerState::kBilinear_Filter);
             break;
         case SkShader::kSweep_BitmapType:
-            sampler->setCustomStage(SkNEW(GrSweepGradient))->unref();
+            sampler->setCustomStage(SkNEW_ARGS(GrSweepGradient, (texture)))->unref();
             sampler->setFilter(GrSamplerState::kBilinear_Filter);
             break;
         case SkShader::kTwoPointRadial_BitmapType:
             sampler->setCustomStage(SkNEW_ARGS(GrRadial2Gradient,
-                         (twoPointParams[0],
+                         (texture,
+                          twoPointParams[0],
                           twoPointParams[1],
                           twoPointParams[2] < 0)))->unref();
             sampler->setFilter(GrSamplerState::kBilinear_Filter);
             break;
         case SkShader::kTwoPointConical_BitmapType:
             sampler->setCustomStage(SkNEW_ARGS(GrConical2Gradient,
-                                               (twoPointParams[0],
+                                               (texture,
+                                                twoPointParams[0],
                                                 twoPointParams[1],
                                                 twoPointParams[2])))->unref();
             sampler->setFilter(GrSamplerState::kBilinear_Filter);
@@ -571,13 +581,6 @@
     sampler->setWrapX(sk_tile_mode_to_grwrap(tileModes[0]));
     sampler->setWrapY(sk_tile_mode_to_grwrap(tileModes[1]));
 
-    GrTexture* texture = act->set(dev, bitmap, sampler);
-    if (NULL == texture) {
-        SkDebugf("Couldn't convert bitmap to texture.\n");
-        return false;
-    }
-    grPaint->setTexture(kShaderTextureIdx, texture);
-
     // since our texture coords will be in local space, we wack the texture
     // matrix to map them back into 0...1 before we load it
     SkMatrix localM;
@@ -1474,7 +1477,7 @@
     desc.fConfig = kRGBA_8888_PM_GrPixelConfig;
     GrCustomStage* stage;
 
-    if (filter->asNewCustomStage(&stage)) {
+    if (filter->asNewCustomStage(&stage, texture)) {
         GrAutoScratchTexture dst(context, desc);
         apply_custom_stage(context, texture, dst.texture(), rect, stage);
         texture = dst.detach();
@@ -1607,7 +1610,7 @@
     SkSize size;
     SkISize radius;
 
-    if (!filter->asNewCustomStage(NULL) &&
+    if (!filter->asNewCustomStage(NULL, NULL) &&
         !filter->asABlur(&size) &&
         !filter->asADilate(&radius) &&
         !filter->asAnErode(&radius)) {