Make GrEffect::textureAccess non-virtual. Require subclasses to append their GrTAs.
Review URL: https://codereview.appspot.com/7062063

git-svn-id: http://skia.googlecode.com/svn/trunk@7129 2bbb7eff-a529-9590-31e7-b0007b416f81
diff --git a/src/effects/SkBlendImageFilter.cpp b/src/effects/SkBlendImageFilter.cpp
index 4e5e018..6dd5eab 100644
--- a/src/effects/SkBlendImageFilter.cpp
+++ b/src/effects/SkBlendImageFilter.cpp
@@ -153,8 +153,6 @@
     typedef GrGLBlendEffect GLEffect;
     static const char* Name() { return "Blend"; }
 
-    virtual const GrTextureAccess& textureAccess(int index) const SK_OVERRIDE;
-
 private:
     GrTextureAccess             fForegroundAccess;
     GrTextureAccess             fBackgroundAccess;
@@ -228,10 +226,11 @@
 GrBlendEffect::GrBlendEffect(SkBlendImageFilter::Mode mode,
                              GrTexture* foreground,
                              GrTexture* background)
-    : INHERITED(2)
-    , fForegroundAccess(foreground)
+    : fForegroundAccess(foreground)
     , fBackgroundAccess(background)
     , fMode(mode) {
+    this->addTextureAccess(&fForegroundAccess);
+    this->addTextureAccess(&fBackgroundAccess);
 }
 
 GrBlendEffect::~GrBlendEffect() {
@@ -246,11 +245,6 @@
     return GrTBackendEffectFactory<GrBlendEffect>::getInstance();
 }
 
-const GrTextureAccess& GrBlendEffect::textureAccess(int index) const {
-    SkASSERT(index >= 0 && index < 2);
-    return (0 == index) ? fForegroundAccess : fBackgroundAccess;
-}
-
 ///////////////////////////////////////////////////////////////////////////////
 
 GrGLBlendEffect::GrGLBlendEffect(const GrBackendEffectFactory& factory, const GrEffect& effect)
diff --git a/src/effects/SkColorMatrixFilter.cpp b/src/effects/SkColorMatrixFilter.cpp
index e460325..ed34f64 100644
--- a/src/effects/SkColorMatrixFilter.cpp
+++ b/src/effects/SkColorMatrixFilter.cpp
@@ -327,7 +327,7 @@
 public:
     static const char* Name() { return "Color Matrix"; }
 
-    ColorMatrixEffect(const SkColorMatrix& matrix) : GrEffect(0), fMatrix(matrix) {}
+    ColorMatrixEffect(const SkColorMatrix& matrix) : fMatrix(matrix) {}
 
     virtual const GrBackendEffectFactory& getFactory() const SK_OVERRIDE {
         return GrTBackendEffectFactory<ColorMatrixEffect>::getInstance();
diff --git a/src/effects/SkTableColorFilter.cpp b/src/effects/SkTableColorFilter.cpp
index ff30636..eb59425 100644
--- a/src/effects/SkTableColorFilter.cpp
+++ b/src/effects/SkTableColorFilter.cpp
@@ -233,8 +233,6 @@
     virtual const GrBackendEffectFactory& getFactory() const SK_OVERRIDE;
     virtual bool isEqual(const GrEffect&) const SK_OVERRIDE;
 
-    virtual const GrTextureAccess& textureAccess(int index) const SK_OVERRIDE;
-
     typedef GLColorTableEffect GLEffect;
 
 private:
@@ -324,8 +322,8 @@
 ///////////////////////////////////////////////////////////////////////////////
 
 ColorTableEffect::ColorTableEffect(GrTexture* texture)
-    : INHERITED(1)
-    , fTextureAccess(texture, "a") {
+    : fTextureAccess(texture, "a") {
+    this->addTextureAccess(&fTextureAccess);
 }
 
 ColorTableEffect::~ColorTableEffect() {
@@ -339,11 +337,6 @@
     return INHERITED::isEqual(sBase);
 }
 
-const GrTextureAccess& ColorTableEffect::textureAccess(int index) const {
-    GrAssert(0 == index);
-    return fTextureAccess;
-}
-
 ///////////////////////////////////////////////////////////////////////////////
 
 GR_DEFINE_EFFECT_TEST(ColorTableEffect);
diff --git a/src/effects/gradients/SkGradientShader.cpp b/src/effects/gradients/SkGradientShader.cpp
index 5b2a60e..8521bdb 100644
--- a/src/effects/gradients/SkGradientShader.cpp
+++ b/src/effects/gradients/SkGradientShader.cpp
@@ -742,8 +742,7 @@
 GrGradientEffect::GrGradientEffect(GrContext* ctx,
                                    const SkGradientShaderBase& shader,
                                    const SkMatrix& matrix,
-                                   SkShader::TileMode tileMode)
-    : INHERITED(1) {
+                                   SkShader::TileMode tileMode) {
     // TODO: check for simple cases where we don't need a texture:
     //GradientInfo info;
     //shader.asAGradient(&info);
@@ -783,6 +782,7 @@
         // the cache, but it'll still be ref'd until it's no longer being used.
         GrUnlockCachedBitmapTexture(texture);
     }
+    this->addTextureAccess(&fTextureAccess);
 }
 
 GrGradientEffect::~GrGradientEffect() {
@@ -791,11 +791,6 @@
     }
 }
 
-const GrTextureAccess& GrGradientEffect::textureAccess(int index) const {
-    GrAssert(0 == index);
-    return fTextureAccess;
-}
-
 int GrGradientEffect::RandomGradientParams(SkRandom* random,
                                            SkColor colors[],
                                            SkScalar** stops,
diff --git a/src/effects/gradients/SkGradientShaderPriv.h b/src/effects/gradients/SkGradientShaderPriv.h
index 1662188..552013e 100644
--- a/src/effects/gradients/SkGradientShaderPriv.h
+++ b/src/effects/gradients/SkGradientShaderPriv.h
@@ -233,8 +233,6 @@
 
     virtual ~GrGradientEffect();
 
-    virtual const GrTextureAccess& textureAccess(int index) const SK_OVERRIDE;
-
     bool useAtlas() const { return SkToBool(-1 != fRow); }
     SkScalar getYCoord() const { return fYCoord; };
     const SkMatrix& getMatrix() const { return fMatrix;}
diff --git a/src/gpu/GrEffect.cpp b/src/gpu/GrEffect.cpp
index d470c9c..dbfb6b0 100644
--- a/src/gpu/GrEffect.cpp
+++ b/src/gpu/GrEffect.cpp
@@ -58,12 +58,7 @@
 
 int32_t GrBackendEffectFactory::fCurrEffectClassID = GrBackendEffectFactory::kIllegalEffectClassID;
 
-GrEffect::GrEffect(int numTextures)
-    : fNumTextures(numTextures) {
-}
-
 GrEffect::~GrEffect() {
-
 }
 
 bool GrEffect::isOpaque(bool inputTextureIsOpaque) const {
@@ -74,7 +69,6 @@
     return this->getFactory().name();
 }
 
-
 bool GrEffect::isEqual(const GrEffect& s) const {
     if (this->numTextures() != s.numTextures()) {
         return false;
@@ -87,10 +81,8 @@
     return true;
 }
 
-const GrTextureAccess& GrEffect::textureAccess(int index) const {
-    GrCrash("We shouldn't be calling this function on the base class.");
-    static GrTextureAccess kDummy;
-    return kDummy;
+void GrEffect::addTextureAccess(const GrTextureAccess* access) {
+    fTextureAccesses.push_back(access);
 }
 
 void * GrEffect::operator new(size_t size) {
diff --git a/src/gpu/effects/GrSingleTextureEffect.cpp b/src/gpu/effects/GrSingleTextureEffect.cpp
index 05eff6b..14f5b64 100644
--- a/src/gpu/effects/GrSingleTextureEffect.cpp
+++ b/src/gpu/effects/GrSingleTextureEffect.cpp
@@ -58,51 +58,46 @@
 ///////////////////////////////////////////////////////////////////////////////
 
 GrSingleTextureEffect::GrSingleTextureEffect(GrTexture* texture)
-    : INHERITED(1)
-    , fTextureAccess(texture) {
+    : fTextureAccess(texture) {
     fMatrix.reset();
+    this->addTextureAccess(&fTextureAccess);
 }
 
 GrSingleTextureEffect::GrSingleTextureEffect(GrTexture* texture, bool bilerp)
-    : INHERITED(1)
-    , fTextureAccess(texture, bilerp) {
+    : fTextureAccess(texture, bilerp) {
     fMatrix.reset();
+    this->addTextureAccess(&fTextureAccess);
 }
 
 GrSingleTextureEffect::GrSingleTextureEffect(GrTexture* texture, const GrTextureParams& params)
-    : INHERITED(1)
-    , fTextureAccess(texture, params) {
+    : fTextureAccess(texture, params) {
     fMatrix.reset();
+    this->addTextureAccess(&fTextureAccess);
 }
 
 GrSingleTextureEffect::GrSingleTextureEffect(GrTexture* texture, const SkMatrix& m)
-    : INHERITED(1)
-    , fTextureAccess(texture)
+    : fTextureAccess(texture)
     , fMatrix(m) {
+    this->addTextureAccess(&fTextureAccess);
 }
 
 GrSingleTextureEffect::GrSingleTextureEffect(GrTexture* texture, const SkMatrix& m, bool bilerp)
-    : INHERITED(1)
-    , fTextureAccess(texture, bilerp)
+    : fTextureAccess(texture, bilerp)
     , fMatrix(m) {
+    this->addTextureAccess(&fTextureAccess);
 }
 
 GrSingleTextureEffect::GrSingleTextureEffect(GrTexture* texture,
                                              const SkMatrix& m,
                                              const GrTextureParams& params)
-    : INHERITED(1)
-    , fTextureAccess(texture, params)
+    : fTextureAccess(texture, params)
     , fMatrix(m) {
+    this->addTextureAccess(&fTextureAccess);
 }
 
 GrSingleTextureEffect::~GrSingleTextureEffect() {
 }
 
-const GrTextureAccess& GrSingleTextureEffect::textureAccess(int index) const {
-    GrAssert(0 == index);
-    return fTextureAccess;
-}
-
 const GrBackendEffectFactory& GrSingleTextureEffect::getFactory() const {
     return GrTBackendEffectFactory<GrSingleTextureEffect>::getInstance();
 }
diff --git a/src/gpu/effects/GrSingleTextureEffect.h b/src/gpu/effects/GrSingleTextureEffect.h
index a2f8bff..fca5e93 100644
--- a/src/gpu/effects/GrSingleTextureEffect.h
+++ b/src/gpu/effects/GrSingleTextureEffect.h
@@ -33,8 +33,6 @@
 
     virtual ~GrSingleTextureEffect();
 
-    virtual const GrTextureAccess& textureAccess(int index) const SK_OVERRIDE;
-
     static const char* Name() { return "Single Texture"; }
 
     const SkMatrix& getMatrix() const { return fMatrix; }