Remove texture/mask setters on GrPaint

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



git-svn-id: http://skia.googlecode.com/svn/trunk@4790 2bbb7eff-a529-9590-31e7-b0007b416f81
diff --git a/gm/texdata.cpp b/gm/texdata.cpp
index c3c09fb..1d13177 100644
--- a/gm/texdata.cpp
+++ b/gm/texdata.cpp
@@ -7,6 +7,7 @@
  */
 #include "gm.h"
 #include "GrContext.h"
+#include "effects/GrSingleTextureEffect.h"
 #include "SkColorPriv.h"
 #include "SkDevice.h"
 
@@ -112,7 +113,9 @@
                 GrMatrix* sampleMat = paint.textureSampler(0)->matrix();
                 *sampleMat = vm;
                 sampleMat->postIDiv(2*S, 2*S);
-                paint.setTexture(0, texture);
+                paint.textureSampler(0)->setCustomStage(
+                    SkNEW_ARGS(GrSingleTextureEffect, (texture)))->unref();
+
 
                 ctx->drawRect(paint, GrRect::MakeWH(2*S, 2*S));
 
diff --git a/gyp/gm.gyp b/gyp/gm.gyp
index 0dc4d55..20fe09e 100644
--- a/gyp/gm.gyp
+++ b/gyp/gm.gyp
@@ -10,6 +10,7 @@
       'include_dirs' : [
         '../src/core',
         '../src/pipe/utils/',
+        '../src/gpu',
       ],
       'includes': [
         'gmslides.gypi',
diff --git a/include/gpu/GrPaint.h b/include/gpu/GrPaint.h
index f1dd202..90bd9a7 100644
--- a/include/gpu/GrPaint.h
+++ b/include/gpu/GrPaint.h
@@ -42,21 +42,6 @@
     SkXfermode::Mode            fColorFilterXfermode;
     float                       fColorMatrix[20];
 
-    void setTexture(int i, GrTexture* texture) {
-        GrAssert((unsigned)i < kMaxTextures);
-        GrSafeRef(texture);
-        GrSafeUnref(fTextures[i]);
-        fTextures[i] = texture;
-    }
-
-    GrTexture* getTexture(int i) const { 
-        GrAssert((unsigned)i < kMaxTextures);
-        //if (this->getTextureSampler(i).getCustomStage()) {
-            //return this->getTextureSampler(i).getCustomStage()->texture(i);
-        //}
-        return fTextures[i]; 
-    }
-
     GrSamplerState* textureSampler(int i) {
         GrAssert((unsigned)i < kMaxTextures);
         return fTextureSamplers + i;
@@ -69,26 +54,9 @@
 
     bool isTextureStageEnabled(int i) const {
         GrAssert((unsigned)i < kMaxTextures);
-        return (NULL != fTextures[i]) ||
-               (NULL != fTextureSamplers[i].getCustomStage());
+        return (NULL != fTextureSamplers[i].getCustomStage());
     }
 
-    // The mask can be alpha-only or per channel. It is applied
-    // after the colorfilter
-    void setMask(int i, GrTexture* mask) {
-        GrAssert((unsigned)i < kMaxMasks);
-        GrSafeRef(mask);
-        GrSafeUnref(fMaskTextures[i]);
-        fMaskTextures[i] = mask;
-    }
-
-    GrTexture* getMask(int i) const { 
-        GrAssert((unsigned)i < kMaxMasks);
-        //if (this->getMaskSampler(i).getCustomStage()) {
-            //return this->getMaskSampler(i).getCustomStage()->texture(i);
-        //}
-        return fMaskTextures[i]; 
-    }
 
     // mask's sampler matrix is always applied to the positions
     // (i.e. no explicit texture coordinates)
@@ -104,8 +72,7 @@
 
     bool isMaskStageEnabled(int i) const {
         GrAssert((unsigned)i < kMaxTextures);
-        return (NULL != fMaskTextures[i]) ||
-               (NULL != fMaskSamplers[i].getCustomStage());
+        return (NULL != fMaskSamplers[i].getCustomStage());
     }
 
     bool hasMask() const {
@@ -161,24 +128,14 @@
 
     // uninitialized
     GrPaint() {
-        for (int i = 0; i < kMaxTextures; ++i) {
-            fTextures[i] = NULL;
-        }
-        for (int i = 0; i < kMaxMasks; ++i) {
-            fMaskTextures[i] = NULL;
-        }
     }
 
     GrPaint(const GrPaint& paint) {
-        for (int i = 0; i < kMaxTextures; ++i) {
-            fTextures[i] = NULL;
-        }
-        for (int i = 0; i < kMaxMasks; ++i) {
-            fMaskTextures[i] = NULL;
-        }
         *this = paint;
     }
 
+    ~GrPaint() {}
+
     GrPaint& operator=(const GrPaint& paint) {
         fSrcBlendCoeff = paint.fSrcBlendCoeff;
         fDstBlendCoeff = paint.fDstBlendCoeff;
@@ -196,13 +153,11 @@
         }
         
         for (int i = 0; i < kMaxTextures; ++i) {
-            GrSafeAssign(fTextures[i], paint.fTextures[i]);
             if (paint.isTextureStageEnabled(i)) {
                 fTextureSamplers[i] = paint.fTextureSamplers[i];
             }
         }
         for (int i = 0; i < kMaxMasks; ++i) {
-            GrSafeAssign(fMaskTextures[i], paint.fMaskTextures[i]);
             if (paint.isMaskStageEnabled(i)) {
                 fMaskSamplers[i] = paint.fMaskSamplers[i];
             }
@@ -210,15 +165,6 @@
         return *this;
     }
 
-    ~GrPaint() {
-        for (int i = 0; i < kMaxTextures; ++i) {
-            GrSafeUnref(fTextures[i]);
-        }
-        for (int i = 0; i < kMaxMasks; ++i) {
-            GrSafeUnref(fMaskTextures[i]);
-        }
-    }
-
     // sets paint to src-over, solid white, no texture, no mask
     void reset() {
         this->resetBlend();
@@ -250,9 +196,6 @@
     GrSamplerState              fTextureSamplers[kMaxTextures];
     GrSamplerState              fMaskSamplers[kMaxMasks];
 
-    GrTexture*      fTextures[kMaxTextures];
-    GrTexture*      fMaskTextures[kMaxMasks];
-
     void resetBlend() {
         fSrcBlendCoeff = kOne_GrBlendCoeff;
         fDstBlendCoeff = kZero_GrBlendCoeff;
@@ -273,14 +216,12 @@
 
     void resetTextures() {
         for (int i = 0; i < kMaxTextures; ++i) {
-            this->setTexture(i, NULL);
             fTextureSamplers[i].reset();
         }
     }
 
     void resetMasks() {
         for (int i = 0; i < kMaxMasks; ++i) {
-            this->setMask(i, NULL);
             fMaskSamplers[i].reset();
         }
     }
diff --git a/src/gpu/GrContext.cpp b/src/gpu/GrContext.cpp
index e14456a..8e3fb09 100644
--- a/src/gpu/GrContext.cpp
+++ b/src/gpu/GrContext.cpp
@@ -1551,9 +1551,8 @@
 
     for (int i = 0; i < GrPaint::kMaxTextures; ++i) {
         int s = i + GrPaint::kFirstTextureStage;
-        ASSERT_OWNED_RESOURCE(paint.getTexture(i));
         if (paint.isTextureStageEnabled(i)) {
-            fDrawState->setTexture(s, paint.getTexture(i));
+            fDrawState->setTexture(s, NULL);
             *fDrawState->sampler(s) = paint.getTextureSampler(i);
         }
     }
@@ -1562,9 +1561,8 @@
 
     for (int i = 0; i < GrPaint::kMaxMasks; ++i) {
         int s = i + GrPaint::kFirstMaskStage;
-        ASSERT_OWNED_RESOURCE(paint.getMask(i));
         if (paint.isMaskStageEnabled(i)) {
-            fDrawState->setTexture(s, paint.getMask(i));
+            fDrawState->setTexture(s, NULL);
             *fDrawState->sampler(s) = paint.getMaskSampler(i);
         }
     }
diff --git a/src/gpu/SkGpuDevice.cpp b/src/gpu/SkGpuDevice.cpp
index cb33d76..1256285 100644
--- a/src/gpu/SkGpuDevice.cpp
+++ b/src/gpu/SkGpuDevice.cpp
@@ -482,13 +482,8 @@
 
 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();
+        paint->textureSampler(kBitmapTextureIdx)->setCustomStage(
+            SkNEW_ARGS(GrSingleTextureEffect, (fTexture)))->unref();
         return true;
     }
     return false;
@@ -549,7 +544,7 @@
         GrAssert(!constantColor);
     } else {
         grPaint->fColor = SkColor2GrColor(skPaint.getColor());
-        GrAssert(NULL == grPaint->getTexture(kShaderTextureIdx));
+        GrAssert(!grPaint->isTextureStageEnabled(kShaderTextureIdx));
     }
     SkColorFilter* colorFilter = skPaint.getColorFilter();
     SkColor color;
@@ -971,9 +966,9 @@
     static const int MASK_IDX = GrPaint::kMaxMasks - 1;
     // we assume the last mask index is available for use
     GrAssert(!grp->isMaskStageEnabled(MASK_IDX));
-    grp->setMask(MASK_IDX, blurTexture);
     grp->maskSampler(MASK_IDX)->reset();
-
+    grp->maskSampler(MASK_IDX)->setCustomStage(
+        SkNEW_ARGS(GrSingleTextureEffect, (blurTexture)))->unref();
     grp->maskSampler(MASK_IDX)->matrix()->setTranslate(-finalRect.fLeft,
                                                        -finalRect.fTop);
     grp->maskSampler(MASK_IDX)->matrix()->postIDiv(blurTexture->width(),
@@ -1034,9 +1029,9 @@
     static const int MASK_IDX = GrPaint::kMaxMasks - 1;
     // we assume the last mask index is available for use
     GrAssert(!grp->isMaskStageEnabled(MASK_IDX));
-    grp->setMask(MASK_IDX, texture);
     grp->maskSampler(MASK_IDX)->reset();
-
+    grp->maskSampler(MASK_IDX)->setCustomStage(
+        SkNEW_ARGS(GrSingleTextureEffect, (texture)))->unref();
     GrRect d;
     d.setLTRB(GrIntToScalar(dstM.fBounds.fLeft),
               GrIntToScalar(dstM.fBounds.fTop),
@@ -1628,25 +1623,23 @@
 
     GrPaint grPaint;
     SkAutoCachedTexture colorLutTexture;
+    grPaint.textureSampler(kBitmapTextureIdx)->reset();
     if (!dev->bindDeviceAsTexture(&grPaint) ||
         !skPaint2GrPaintNoShader(this, paint, true, false, &colorLutTexture, &grPaint)) {
         return;
     }
 
-    GrTexture* devTex = grPaint.getTexture(0);
+    GrTexture* devTex = grPaint.getTextureSampler(kBitmapTextureIdx).getCustomStage()->texture(0);
     SkASSERT(NULL != devTex);
 
     SkImageFilter* filter = paint.getImageFilter();
-    grPaint.textureSampler(kBitmapTextureIdx)->reset();
     if (NULL != filter) {
-        GrRect rect = GrRect::MakeWH(SkIntToScalar(devTex->width()), 
+        GrRect rect = GrRect::MakeWH(SkIntToScalar(devTex->width()),
                                      SkIntToScalar(devTex->height()));
-        GrTexture* filteredTexture = filter_texture(fContext, devTex, filter,
-                                                    rect);
+        GrTexture* filteredTexture = filter_texture(fContext, devTex, filter, rect);
         if (filteredTexture) {
             grPaint.textureSampler(kBitmapTextureIdx)->setCustomStage(SkNEW_ARGS
                 (GrSingleTextureEffect, (filteredTexture)))->unref();
-            grPaint.setTexture(kBitmapTextureIdx, NULL);
             devTex = filteredTexture;
             filteredTexture->unref();
         }