Stop using GrSamplerState to track the texture parameters for GL textures. It has become larger and now holds state that isn't tracked per-texture by GL. Also remove unused setSamplerStateImm from GrGpuGL


git-svn-id: http://skia.googlecode.com/svn/trunk@659 2bbb7eff-a529-9590-31e7-b0007b416f81
diff --git a/gpu/src/GrGLTexture.cpp b/gpu/src/GrGLTexture.cpp
index b75cad5..4e9d922 100644
--- a/gpu/src/GrGLTexture.cpp
+++ b/gpu/src/GrGLTexture.cpp
@@ -75,12 +75,14 @@
 
 GrGLTexture::GrGLTexture(const GLTextureDesc& textureDesc,
                          const GLRenderTargetIDs& rtIDs,
+                         const TexParams& initialTexParams,
                          GrGpuGL* gl) :
         INHERITED(textureDesc.fContentWidth, 
                   textureDesc.fContentHeight, 
                   textureDesc.fAllocWidth, 
                   textureDesc.fAllocHeight,
                   textureDesc.fFormat),
+        fTexParams(initialTexParams),
         fTextureID(textureDesc.fTextureID),
         fUploadFormat(textureDesc.fUploadFormat),
         fUploadByteCount(textureDesc.fUploadByteCount),
@@ -101,15 +103,6 @@
                      (int32_t)textureDesc.fContentHeight;
         fRenderTarget = new GrGLRenderTarget(rtIDs, vp, this, gl);
     }
-
-    fSamplerState.setClampNoFilter();
-    
-    GR_GL(BindTexture(GL_TEXTURE_2D, fTextureID));
-    gl->notifyTextureBind(this);
-    GR_GL(TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST));
-    GR_GL(TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST));
-    GR_GL(TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE));
-    GR_GL(TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE));
 }
 
 GrGLTexture::~GrGLTexture() {
@@ -124,7 +117,7 @@
 void GrGLTexture::abandon() {
     fTextureID = 0;
     if (NULL != fRenderTarget) {
-    	fRenderTarget->abandon();
+        fRenderTarget->abandon();
     }
 }
 
diff --git a/gpu/src/GrGpuGL.cpp b/gpu/src/GrGpuGL.cpp
index 7a73006..5198dbb 100644
--- a/gpu/src/GrGpuGL.cpp
+++ b/gpu/src/GrGpuGL.cpp
@@ -426,7 +426,7 @@
 #if GR_GL_DESKTOP
     GR_GL(Disable(GL_LINE_SMOOTH));
     GR_GL(Disable(GL_POINT_SMOOTH));
-	GR_GL(Disable(GL_MULTISAMPLE));
+    GR_GL(Disable(GL_MULTISAMPLE));
 #endif
 
     // we only ever use lines in hairline mode
@@ -533,6 +533,13 @@
 #if GR_COLLECT_STATS
     ++fStats.fTextureCreateCnt;
 #endif
+    
+    static const GrGLTexture::TexParams DEFAULT_PARAMS = {
+        GL_NEAREST,
+        GL_CLAMP_TO_EDGE,
+        GL_CLAMP_TO_EDGE
+    };
+    
     GrGLTexture::GLTextureDesc glDesc;
     GLenum internalFormat;
 
@@ -607,6 +614,18 @@
     }
 
     GR_GL(BindTexture(GL_TEXTURE_2D, glDesc.fTextureID));
+    GR_GL(TexParameteri(GL_TEXTURE_2D, 
+                        GL_TEXTURE_MAG_FILTER, 
+                        DEFAULT_PARAMS.fFilter));
+    GR_GL(TexParameteri(GL_TEXTURE_2D, 
+                        GL_TEXTURE_MIN_FILTER, 
+                        DEFAULT_PARAMS.fFilter));
+    GR_GL(TexParameteri(GL_TEXTURE_2D, 
+                        GL_TEXTURE_WRAP_S,
+                        DEFAULT_PARAMS.fWrapS));
+    GR_GL(TexParameteri(GL_TEXTURE_2D, 
+                        GL_TEXTURE_WRAP_T, 
+                        DEFAULT_PARAMS.fWrapT));
 #if GR_COLLECT_STATS
     ++fStats.fTextureChngCnt;
 #endif
@@ -898,7 +917,7 @@
     GrPrintf("--- new texture [%d] size=(%d %d) bpp=%d\n",
              tex->fTextureID, width, height, tex->fUploadByteCount);
 #endif
-    GrGLTexture* tex = new GrGLTexture(glDesc, rtIDs, this);
+    GrGLTexture* tex = new GrGLTexture(glDesc, rtIDs, DEFAULT_PARAMS, this);
 
     if (0 != rtIDs.fTexFBOID) {
         GrRenderTarget* rt = tex->asRenderTarget();
@@ -1014,18 +1033,6 @@
     }
 }
 
-void GrGpuGL::setSamplerStateImm(const GrSamplerState& state) {
-
-    GLenum filter = state.isFilter() ? GL_LINEAR : GL_NEAREST;
-    GR_GL(TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, filter));
-    GR_GL(TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, filter));
-    GR_GL(TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S,
-                        GrGLTexture::gWrapMode2GLWrap[state.getWrapX()]));
-    GR_GL(TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T,
-                        GrGLTexture::gWrapMode2GLWrap[state.getWrapY()]));
-
-}
-
 void GrGpuGL::eraseColor(GrColor color) {
     flushRenderTarget();
     if (fHWBounds.fScissorEnabled) {
@@ -1433,27 +1440,33 @@
                 //GrPrintf("---- bindtexture %d\n", nextTexture->textureID());
                 fHWDrawState.fTexture = nextTexture;
             }
-            const GrSamplerState& lastSampler = nextTexture->samplerState();
-            if (lastSampler.isFilter() != fCurrDrawState.fSamplerState.isFilter()) {
-                GLenum filter = fCurrDrawState.fSamplerState.isFilter() ?
-                                                                    GL_LINEAR :
-                                                                    GL_NEAREST;
-                GR_GL(TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER,
-                                    filter));
-                GR_GL(TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,
-                                    filter));
+            const GrGLTexture::TexParams& oldTexParams = nextTexture->getTexParams();
+            GrGLTexture::TexParams newTexParams;
+            newTexParams.fFilter = fCurrDrawState.fSamplerState.isFilter() ? 
+                                                                GL_LINEAR :
+                                                                GL_NEAREST;
+            newTexParams.fWrapS = GrGLTexture::gWrapMode2GLWrap[fCurrDrawState.fSamplerState.getWrapX()];
+            newTexParams.fWrapT = GrGLTexture::gWrapMode2GLWrap[fCurrDrawState.fSamplerState.getWrapY()];
+
+            if (newTexParams.fFilter != oldTexParams.fFilter) {
+                GR_GL(TexParameteri(GL_TEXTURE_2D, 
+                                    GL_TEXTURE_MAG_FILTER, 
+                                    newTexParams.fFilter));
+                GR_GL(TexParameteri(GL_TEXTURE_2D, 
+                                    GL_TEXTURE_MIN_FILTER, 
+                                    newTexParams.fFilter));
             }
-            if (lastSampler.getWrapX() != fCurrDrawState.fSamplerState.getWrapX()) {
-                GR_GL(TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S,
-                                    GrGLTexture::gWrapMode2GLWrap[
-                                             fCurrDrawState.fSamplerState.getWrapX()]));
+            if (newTexParams.fWrapS != oldTexParams.fWrapS) {
+                GR_GL(TexParameteri(GL_TEXTURE_2D, 
+                                    GL_TEXTURE_WRAP_S,
+                                    newTexParams.fWrapS));
             }
-            if (lastSampler.getWrapY() != fCurrDrawState.fSamplerState.getWrapY()) {
-                GR_GL(TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T,
-                                    GrGLTexture::gWrapMode2GLWrap[
-                                             fCurrDrawState.fSamplerState.getWrapY()]));
+            if (newTexParams.fWrapT != oldTexParams.fWrapT) {
+                GR_GL(TexParameteri(GL_TEXTURE_2D, 
+                                    GL_TEXTURE_WRAP_T, 
+                                    newTexParams.fWrapT));
             }
-            nextTexture->setSamplerState(fCurrDrawState.fSamplerState);
+            nextTexture->setTexParams(newTexParams);
         } else {
             GrAssert(!"Rendering with texture vert flag set but no texture");
             if (NULL != fHWDrawState.fTexture) {
diff --git a/gpu/src/GrGpuGL.h b/gpu/src/GrGpuGL.h
index bedb85a..7701df9 100644
--- a/gpu/src/GrGpuGL.h
+++ b/gpu/src/GrGpuGL.h
@@ -98,9 +98,6 @@
     // line width
     void flushGLStateCommon(PrimitiveType type);
 
-    // pushes the filtering and tiling modes to GL
-    void setSamplerStateImm(const GrSamplerState& samplerState);
-
     // set when this class changes the rendertarget.
     // Subclass should notice at flush time, take appropriate action,
     // and set false.