Prep for GrDrawState as a class Part 2

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



git-svn-id: http://skia.googlecode.com/svn/trunk@2810 2bbb7eff-a529-9590-31e7-b0007b416f81
diff --git a/include/gpu/GrPaint.h b/include/gpu/GrPaint.h
index aadd648..ace11cc 100644
--- a/include/gpu/GrPaint.h
+++ b/include/gpu/GrPaint.h
@@ -239,14 +239,14 @@
     void resetTextures() {
         for (int i = 0; i < kMaxTextures; ++i) {
             this->setTexture(i, NULL);
-            fTextureSamplers[i].setClampNoFilter();
+            fTextureSamplers[i].reset();
         }
     }
 
     void resetMasks() {
         for (int i = 0; i < kMaxMasks; ++i) {
             this->setMask(i, NULL);
-            fMaskSamplers[i].setClampNoFilter();
+            fMaskSamplers[i].reset();
         }
     }
 };
diff --git a/include/gpu/GrSamplerState.h b/include/gpu/GrSamplerState.h
index 7c9bf13..42e9d0d 100644
--- a/include/gpu/GrSamplerState.h
+++ b/include/gpu/GrSamplerState.h
@@ -88,60 +88,15 @@
     : fRadial2CenterX1()
     , fRadial2Radius0()
     , fRadial2PosRoot() {
-        this->setClampNoFilter();
+        this->reset();
     }
 
-    explicit GrSamplerState(Filter filter)
+    GrSamplerState(WrapMode wrapXAndY,
+                   Filter filter)
     : fRadial2CenterX1()
     , fRadial2Radius0()
     , fRadial2PosRoot() {
-        fWrapX = kClamp_WrapMode;
-        fWrapY = kClamp_WrapMode;
-        fSampleMode = kNormal_SampleMode;
-        fFilter = filter;
-        fMatrix.setIdentity();
-        fTextureDomain.setEmpty();
-    }
-
-    GrSamplerState(WrapMode wx, WrapMode wy, Filter filter)
-    : fRadial2CenterX1()
-    , fRadial2Radius0()
-    , fRadial2PosRoot() {
-        fWrapX = wx;
-        fWrapY = wy;
-        fSampleMode = kNormal_SampleMode;
-        fFilter = filter;
-        fMatrix.setIdentity();
-        fSwapRAndB = false;
-        fTextureDomain.setEmpty();
-    }
-
-    GrSamplerState(WrapMode wx, WrapMode wy, 
-                   const GrMatrix& matrix, Filter filter)
-    : fRadial2CenterX1()
-    , fRadial2Radius0()
-    , fRadial2PosRoot() {
-        fWrapX = wx;
-        fWrapY = wy;
-        fSampleMode = kNormal_SampleMode;
-        fFilter = filter;
-        fMatrix = matrix;
-        fSwapRAndB = false;
-        fTextureDomain.setEmpty();
-    }
-
-    GrSamplerState(WrapMode wx, WrapMode wy, SampleMode sample, 
-                   const GrMatrix& matrix, Filter filter)
-    : fRadial2CenterX1()
-    , fRadial2Radius0()
-    , fRadial2PosRoot() {
-        fWrapX = wx;
-        fWrapY = wy;
-        fSampleMode = sample;
-        fMatrix = matrix;
-        fFilter = filter;
-        fSwapRAndB = false;
-        fTextureDomain.setEmpty();
+        this->reset(wrapXAndY, filter);
     }
 
     WrapMode getWrapX() const { return fWrapX; }
@@ -204,7 +159,7 @@
      */
     void setFilter(Filter filter) { fFilter = filter; }
 
-    void setClampNoFilter() {
+    void reset() {
         fWrapX = kClamp_WrapMode;
         fWrapY = kClamp_WrapMode;
         fSampleMode = kNormal_SampleMode;
@@ -214,6 +169,28 @@
         fSwapRAndB = false;
     }
 
+    void reset(WrapMode wrapXAndY,
+               Filter filter) {
+        fWrapX = wrapXAndY;
+        fWrapY = wrapXAndY;
+        fSampleMode = kNormal_SampleMode;
+        fFilter = filter;
+        fMatrix.setIdentity();
+        fTextureDomain.setEmpty();
+        fSwapRAndB = false;
+    }
+    void reset(WrapMode wrapXAndY,
+               Filter filter,
+               const GrMatrix& matrix) {
+        fWrapX = wrapXAndY;
+        fWrapY = wrapXAndY;
+        fSampleMode = kNormal_SampleMode;
+        fFilter = filter;
+        fMatrix = matrix;
+        fTextureDomain.setEmpty();
+        fSwapRAndB = false;
+    }
+
     GrScalar getRadial2CenterX1() const { return fRadial2CenterX1; }
     GrScalar getRadial2Radius0() const { return fRadial2Radius0; }
     bool     isRadial2PosRoot() const { return SkToBool(fRadial2PosRoot); }
@@ -247,9 +224,7 @@
         }
     }
 
-    static const GrSamplerState& ClampNoFilter() {
-        return gClampNoFilter;
-    }
+    static const GrSamplerState& ClampNearest() { return gClampNearest; }
 
 private:
     WrapMode    fWrapX : 8;
@@ -270,7 +245,7 @@
     float       fImageIncrement[2];
     float       fKernel[MAX_KERNEL_WIDTH];
 
-    static const GrSamplerState gClampNoFilter;
+    static const GrSamplerState gClampNearest;
 };
 
 #endif
diff --git a/src/gpu/GrContext.cpp b/src/gpu/GrContext.cpp
index 335b9f4..de80f65 100644
--- a/src/gpu/GrContext.cpp
+++ b/src/gpu/GrContext.cpp
@@ -330,11 +330,11 @@
     if (special) {
         TextureCacheEntry clampEntry = 
                             findAndLockTexture(key, desc.fWidth, desc.fHeight,
-                                               GrSamplerState::ClampNoFilter());
+                                               GrSamplerState::ClampNearest());
 
         if (NULL == clampEntry.texture()) {
             clampEntry = createAndLockTexture(key,
-                                              GrSamplerState::ClampNoFilter(),
+                                              GrSamplerState::ClampNearest(),
                                               desc, srcData, rowBytes);
             GrAssert(NULL != clampEntry.texture());
             if (NULL == clampEntry.texture()) {
@@ -367,7 +367,6 @@
                 filter = GrSamplerState::kBilinear_Filter;
             }
             GrSamplerState stretchSampler(GrSamplerState::kClamp_WrapMode,
-                                          GrSamplerState::kClamp_WrapMode,
                                           filter);
             fGpu->setSamplerState(0, stretchSampler);
 
@@ -434,7 +433,7 @@
                                     ((uint64_t) desc.fConfig << 32);
     // this code path isn't friendly to tiling with NPOT restricitons
     // We just pass ClampNoFilter()
-    gen_texture_key_values(gpu, GrSamplerState::ClampNoFilter(), descKey,
+    gen_texture_key_values(gpu, GrSamplerState::ClampNearest(), descKey,
                             desc.fWidth, desc.fHeight, true, v);
 }
 }
@@ -864,8 +863,7 @@
     }
 
     GrMatrix sampleM;
-    GrSamplerState sampler(GrSamplerState::kClamp_WrapMode, 
-                           GrSamplerState::kClamp_WrapMode, filter);
+    GrSamplerState sampler(GrSamplerState::kClamp_WrapMode, filter);
 
     GrTexture* src = record->fOffscreen0.texture();
     int scale;
@@ -1787,9 +1785,6 @@
 
         fGpu->setRenderTarget(target);
 
-        GrSamplerState sampler;
-        sampler.setClampNoFilter();
-        sampler.setRAndBSwap(swapRAndB);
         GrMatrix matrix;
         if (flipY) {
             matrix.setTranslate(SK_Scalar1 * left,
@@ -1799,7 +1794,11 @@
             matrix.setTranslate(SK_Scalar1 *left, SK_Scalar1 *top);
         }
         matrix.postIDiv(src->width(), src->height());
-        sampler.setMatrix(matrix);
+        GrSamplerState sampler;
+        sampler.reset(GrSamplerState::kClamp_WrapMode,
+                      GrSamplerState::kNearest_Filter,
+                      matrix);
+        sampler.setRAndBSwap(swapRAndB);
         fGpu->setSamplerState(0, sampler);
         fGpu->setTexture(0, src);
         GrRect rect;
@@ -1822,8 +1821,7 @@
     GrDrawTarget::AutoStateRestore asr(fGpu);
     reset_target_state(fGpu);
     fGpu->setRenderTarget(dst);
-    GrSamplerState sampler(GrSamplerState::kClamp_WrapMode, 
-                           GrSamplerState::kClamp_WrapMode,
+    GrSamplerState sampler(GrSamplerState::kClamp_WrapMode,
                            GrSamplerState::kNearest_Filter);
     GrMatrix sampleM;
     sampleM.setIDiv(src->width(), src->height());
@@ -1899,10 +1897,11 @@
     fGpu->setRenderTarget(target);
     fGpu->setTexture(0, texture);
 
-    GrSamplerState sampler;
-    sampler.setClampNoFilter();
     matrix.setIDiv(texture->width(), texture->height());
-    sampler.setMatrix(matrix);
+    GrSamplerState sampler;
+    sampler.reset(GrSamplerState::kClamp_WrapMode,
+                  GrSamplerState::kNearest_Filter,
+                  matrix);
     sampler.setRAndBSwap(swapRAndB);
     fGpu->setSamplerState(0, sampler);
 
@@ -2145,8 +2144,7 @@
 
     GrDrawTarget::AutoStateRestore asr(fGpu);
     GrMatrix sampleM;
-    GrSamplerState sampler(GrSamplerState::kClamp_WrapMode, 
-                           GrSamplerState::kClamp_WrapMode,
+    GrSamplerState sampler(GrSamplerState::kClamp_WrapMode,
                            GrSamplerState::kConvolution_Filter);
     sampler.setConvolutionParams(kernelWidth, kernel, imageIncrement);
     sampleM.setIDiv(texture->width(), texture->height());
diff --git a/src/gpu/GrGpu.cpp b/src/gpu/GrGpu.cpp
index 764ccd3..1583630 100644
--- a/src/gpu/GrGpu.cpp
+++ b/src/gpu/GrGpu.cpp
@@ -960,13 +960,5 @@
 }
 
 ////////////////////////////////////////////////////////////////////////////////
-const GrSamplerState GrSamplerState::gClampNoFilter(
-    GrSamplerState::kClamp_WrapMode,
-    GrSamplerState::kClamp_WrapMode,
-    GrSamplerState::kNormal_SampleMode,
-    GrMatrix::I(),
-    GrSamplerState::kNearest_Filter);
 
-
-
-
+const GrSamplerState GrSamplerState::gClampNearest;
diff --git a/src/gpu/GrTextContext.cpp b/src/gpu/GrTextContext.cpp
index 657841c..4b78d4a 100644
--- a/src/gpu/GrTextContext.cpp
+++ b/src/gpu/GrTextContext.cpp
@@ -34,7 +34,6 @@
             filter = GrSamplerState::kBilinear_Filter;
         }
         GrSamplerState sampler(GrSamplerState::kRepeat_WrapMode,
-                               GrSamplerState::kRepeat_WrapMode,
                                filter);
         fDrawTarget->setSamplerState(kGlyphMaskStage, sampler);
 
diff --git a/src/gpu/SkGpuDevice.cpp b/src/gpu/SkGpuDevice.cpp
index 0ad0a5c..5daf42c 100644
--- a/src/gpu/SkGpuDevice.cpp
+++ b/src/gpu/SkGpuDevice.cpp
@@ -195,7 +195,7 @@
     TexType type = (kSaveLayer_Usage == usage) ? 
                             kSaveLayerDeviceRenderTarget_TexType :
                             kDeviceRenderTarget_TexType;
-    fCache = this->lockCachedTexture(bm, GrSamplerState::ClampNoFilter(), type);
+    fCache = this->lockCachedTexture(bm, GrSamplerState::ClampNearest(), type);
     fTexture = fCache.texture();
     if (fTexture) {
         SkASSERT(NULL != fTexture->asRenderTarget());
@@ -969,7 +969,7 @@
     // we assume the last mask index is available for use
     GrAssert(NULL == grp->getMask(MASK_IDX));
     grp->setMask(MASK_IDX, blurTexture);
-    grp->maskSampler(MASK_IDX)->setClampNoFilter();
+    grp->maskSampler(MASK_IDX)->reset();
 
     GrMatrix m;
     m.setTranslate(-finalRect.fLeft, -finalRect.fTop);
@@ -1037,7 +1037,7 @@
     // we assume the last mask index is available for use
     GrAssert(NULL == grp->getMask(MASK_IDX));
     grp->setMask(MASK_IDX, texture);
-    grp->maskSampler(MASK_IDX)->setClampNoFilter();
+    grp->maskSampler(MASK_IDX)->reset();
 
     GrRect d;
     d.setLTRB(GrIntToScalar(dstM.fBounds.fLeft),
@@ -1465,7 +1465,7 @@
     GrSamplerState* sampler = grPaint.textureSampler(kBitmapTextureIdx);
 
     GrTexture* texture;
-    sampler->setClampNoFilter();
+    sampler->reset();
     SkAutoCachedTexture act(this, bitmap, *sampler, &texture);
 
     grPaint.setTexture(kBitmapTextureIdx, texture);
@@ -1497,7 +1497,7 @@
 
     GrAutoMatrix avm(fContext, GrMatrix::I());
 
-    grPaint.textureSampler(kBitmapTextureIdx)->setClampNoFilter();
+    grPaint.textureSampler(kBitmapTextureIdx)->reset();
 
     GrRect dstRect = GrRect::MakeXYWH(GrIntToScalar(x),
                                       GrIntToScalar(y),