Remove GrDrawState::setSampler, use direct access to sampler

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



git-svn-id: http://skia.googlecode.com/svn/trunk@2852 2bbb7eff-a529-9590-31e7-b0007b416f81
diff --git a/include/gpu/GrSamplerState.h b/include/gpu/GrSamplerState.h
index c0f7fd4..f1fc86d 100644
--- a/include/gpu/GrSamplerState.h
+++ b/include/gpu/GrSamplerState.h
@@ -91,14 +91,6 @@
         this->reset();
     }
 
-    GrSamplerState(WrapMode wrapXAndY,
-                   Filter filter)
-    : fRadial2CenterX1()
-    , fRadial2Radius0()
-    , fRadial2PosRoot() {
-        this->reset(wrapXAndY, filter);
-    }
-
     WrapMode getWrapX() const { return fWrapX; }
     WrapMode getWrapY() const { return fWrapY; }
     SampleMode getSampleMode() const { return fSampleMode; }
@@ -190,6 +182,15 @@
         fTextureDomain.setEmpty();
         fSwapRAndB = false;
     }
+    void reset(const GrMatrix& matrix) {
+        fWrapX = kClamp_WrapMode;
+        fWrapY = kClamp_WrapMode;
+        fSampleMode = kNormal_SampleMode;
+        fFilter = kNearest_Filter;
+        fMatrix = matrix;
+        fTextureDomain.setEmpty();
+        fSwapRAndB = false;
+    }
 
     GrScalar getRadial2CenterX1() const { return fRadial2CenterX1; }
     GrScalar getRadial2Radius0() const { return fRadial2Radius0; }
diff --git a/src/gpu/GrContext.cpp b/src/gpu/GrContext.cpp
index a798ec9..4e0e587 100644
--- a/src/gpu/GrContext.cpp
+++ b/src/gpu/GrContext.cpp
@@ -369,9 +369,8 @@
             } else {
                 filter = GrSamplerState::kBilinear_Filter;
             }
-            GrSamplerState stretchSampler(GrSamplerState::kClamp_WrapMode,
-                                          filter);
-            drawState->setSampler(0, stretchSampler);
+            drawState->sampler(0)->reset(GrSamplerState::kClamp_WrapMode,
+                                         filter);
 
             static const GrVertexLayout layout =
                                 GrDrawTarget::StageTexCoordVertexLayoutBit(0,0);
@@ -870,7 +869,6 @@
     }
 
     GrMatrix sampleM;
-    GrSamplerState sampler(GrSamplerState::kClamp_WrapMode, filter);
 
     GrTexture* src = record->fOffscreen0.texture();
     int scale;
@@ -892,8 +890,9 @@
         drawState->setViewMatrix(GrMatrix::I());
         sampleM.setScale(scale * GR_Scalar1 / src->width(),
                          scale * GR_Scalar1 / src->height());
-        sampler.setMatrix(sampleM);
-        drawState->setSampler(kOffscreenStage, sampler);
+        GrSamplerState* sampler = drawState->sampler(kOffscreenStage);
+        sampler->reset(GrSamplerState::kClamp_WrapMode, filter);
+        sampler->setMatrix(sampleM);
         GrRect rect = SkRect::MakeWH(SkIntToScalar(scale * tileRect.width()),
                                      SkIntToScalar(scale * tileRect.height()));
         target->drawSimpleRect(rect, NULL, 1 << kOffscreenStage);
@@ -929,13 +928,15 @@
     GrDrawState::AutoViewMatrixRestore avmr(drawState, GrMatrix::I());
 
     drawState->setTexture(kOffscreenStage, src);
+    GrSamplerState* sampler = drawState->sampler(kOffscreenStage);
+    sampler->reset(GrSamplerState::kClamp_WrapMode, filter);
     sampleM.setScale(scale * GR_Scalar1 / src->width(),
                      scale * GR_Scalar1 / src->height());
-    sampler.setMatrix(sampleM);
+    
+    sampler->setMatrix(sampleM);
     sampleM.setTranslate(SkIntToScalar(-tileRect.fLeft),
                          SkIntToScalar(-tileRect.fTop));
-    sampler.preConcatMatrix(sampleM);
-    drawState->setSampler(kOffscreenStage, sampler);
+    sampler->preConcatMatrix(sampleM);
 
     GrRect dstRect;
     int stages = (1 << kOffscreenStage) | stageMask;
@@ -1794,12 +1795,8 @@
             matrix.setTranslate(SK_Scalar1 *left, SK_Scalar1 *top);
         }
         matrix.postIDiv(src->width(), src->height());
-        GrSamplerState sampler;
-        sampler.reset(GrSamplerState::kClamp_WrapMode,
-                      GrSamplerState::kNearest_Filter,
-                      matrix);
-        sampler.setRAndBSwap(swapRAndB);
-        drawState->setSampler(0, sampler);
+        drawState->sampler(0)->reset(matrix);
+        drawState->sampler(0)->setRAndBSwap(swapRAndB);
         drawState->setTexture(0, src);
         GrRect rect;
         rect.setXYWH(0, 0, SK_Scalar1 * width, SK_Scalar1 * height);
@@ -1822,13 +1819,10 @@
     GrDrawState* drawState = fGpu->drawState();
     reset_draw_state(drawState);
     drawState->setRenderTarget(dst);
-    GrSamplerState sampler(GrSamplerState::kClamp_WrapMode,
-                           GrSamplerState::kNearest_Filter);
     GrMatrix sampleM;
     sampleM.setIDiv(src->width(), src->height());
-    sampler.setMatrix(sampleM);
     drawState->setTexture(0, src);
-    drawState->setSampler(0, sampler);
+    drawState->sampler(0)->reset(sampleM);
     SkRect rect = SkRect::MakeXYWH(0, 0, src->width(), src->height());
     fGpu->drawSimpleRect(rect, NULL, 1 << 0);
 }
@@ -1900,12 +1894,10 @@
     drawState->setTexture(0, texture);
 
     matrix.setIDiv(texture->width(), texture->height());
-    GrSamplerState sampler;
-    sampler.reset(GrSamplerState::kClamp_WrapMode,
-                  GrSamplerState::kNearest_Filter,
-                  matrix);
-    sampler.setRAndBSwap(swapRAndB);
-    drawState->setSampler(0, sampler);
+    drawState->sampler(0)->reset(GrSamplerState::kClamp_WrapMode,
+                                 GrSamplerState::kNearest_Filter,
+                                 matrix);
+    drawState->sampler(0)->setRAndBSwap(swapRAndB);
 
     GrVertexLayout layout = GrDrawTarget::StagePosAsTexCoordVertexLayoutBit(0);
     static const int VCOUNT = 4;
@@ -1927,7 +1919,7 @@
         int s = i + GrPaint::kFirstTextureStage;
         drawState->setTexture(s, paint.getTexture(i));
         ASSERT_OWNED_RESOURCE(paint.getTexture(i));
-        drawState->setSampler(s, paint.getTextureSampler(i));
+        *drawState->sampler(s) = paint.getTextureSampler(i);
     }
 
     drawState->setFirstCoverageStage(GrPaint::kFirstMaskStage);
@@ -1936,7 +1928,7 @@
         int s = i + GrPaint::kFirstMaskStage;
         drawState->setTexture(s, paint.getMask(i));
         ASSERT_OWNED_RESOURCE(paint.getMask(i));
-        drawState->setSampler(s, paint.getMaskSampler(i));
+        *drawState->sampler(s) = paint.getMaskSampler(i);
     }
 
     drawState->setColor(paint.fColor);
@@ -2146,14 +2138,16 @@
     ASSERT_OWNED_RESOURCE(texture);
 
     GrDrawTarget::AutoStateRestore asr(fGpu);
-    GrMatrix sampleM;
-    GrSamplerState sampler(GrSamplerState::kClamp_WrapMode,
-                           GrSamplerState::kConvolution_Filter);
-    sampler.setConvolutionParams(kernelWidth, kernel, imageIncrement);
-    sampleM.setIDiv(texture->width(), texture->height());
-    sampler.setMatrix(sampleM);
     GrDrawState* drawState = fGpu->drawState();
-    drawState->setSampler(0, sampler);
+    GrMatrix sampleM;
+    sampleM.setIDiv(texture->width(), texture->height());
+    drawState->sampler(0)->reset(GrSamplerState::kClamp_WrapMode,
+                                 GrSamplerState::kConvolution_Filter,
+                                 sampleM);
+    drawState->sampler(0)->setConvolutionParams(kernelWidth,
+                                                kernel,
+                                                imageIncrement);
+
     drawState->setViewMatrix(GrMatrix::I());
     drawState->setTexture(0, texture);
     drawState->setAlpha(0xFF);
diff --git a/src/gpu/GrDrawState.h b/src/gpu/GrDrawState.h
index 7526b9f..a119115 100644
--- a/src/gpu/GrDrawState.h
+++ b/src/gpu/GrDrawState.h
@@ -149,14 +149,6 @@
     }
 
     /**
-     * Sets the sampler. This will be removed soon in favor of direct access.
-     */
-    void setSampler(int stage, const GrSamplerState& sampler) {
-        GrAssert((unsigned)stage < kNumStages);
-        fSamplerStates[stage] = sampler;
-    }
-
-    /**
      * Writable pointer to a stage's sampler.
      */
     GrSamplerState* sampler(int stage) {
diff --git a/src/gpu/GrTextContext.cpp b/src/gpu/GrTextContext.cpp
index 48cddab..c22b203 100644
--- a/src/gpu/GrTextContext.cpp
+++ b/src/gpu/GrTextContext.cpp
@@ -33,9 +33,8 @@
         } else {
             filter = GrSamplerState::kBilinear_Filter;
         }
-        GrSamplerState sampler(GrSamplerState::kRepeat_WrapMode,
-                               filter);
-        drawState->setSampler(kGlyphMaskStage, sampler);
+        drawState->sampler(kGlyphMaskStage)->reset(
+            GrSamplerState::kRepeat_WrapMode,filter);
 
         GrAssert(GrIsALIGN4(fCurrVertex));
         int nIndices = fCurrVertex + (fCurrVertex >> 1);