Revert "Reland "Reland "Revert "Use OpenGL sampler objects when available.""""

This reverts commit 327955b1ba194eb010ff5a3ef1f32a913d52dd5c.

Bug: skia:8471
Change-Id: I56eb9509f0e2d5c4aa9e2a110a73a09723f77c4a
Reviewed-on: https://skia-review.googlesource.com/c/164617
Reviewed-by: Greg Daniel <egdaniel@google.com>
Commit-Queue: Brian Salomon <bsalomon@google.com>
diff --git a/src/gpu/gl/GrGLTexture.h b/src/gpu/gl/GrGLTexture.h
index cb029cc..5f662e0 100644
--- a/src/gpu/gl/GrGLTexture.h
+++ b/src/gpu/gl/GrGLTexture.h
@@ -17,14 +17,37 @@
 
 class GrGLTexture : public GrTexture {
 public:
-    struct TexParams {
-        GrGLenum fMinFilter;
-        GrGLenum fMagFilter;
-        GrGLenum fWrapS;
-        GrGLenum fWrapT;
-        GrGLenum fMaxMipMapLevel;
-        GrGLenum fSwizzleRGBA[4];
-        void invalidate() { memset(this, 0xff, sizeof(TexParams)); }
+    // Texture state that overlaps with sampler object state. We don't need to track this if we
+    // are using sampler objects.
+    struct SamplerParams {
+        // These are the OpenGL defaults.
+        GrGLenum fMinFilter = GR_GL_NEAREST_MIPMAP_LINEAR;
+        GrGLenum fMagFilter = GR_GL_LINEAR;
+        GrGLenum fWrapS = GR_GL_REPEAT;
+        GrGLenum fWrapT = GR_GL_REPEAT;
+        GrGLfloat fMinLOD = -1000.f;
+        GrGLfloat fMaxLOD = 1000.f;
+        void invalidate() {
+            fMinFilter = ~0U;
+            fMagFilter = ~0U;
+            fWrapS = ~0U;
+            fWrapT = ~0U;
+            fMinLOD = SK_ScalarNaN;
+            fMaxLOD = SK_ScalarNaN;
+        }
+    };
+
+    // Texture state that does not overlap with sampler object state.
+    struct NonSamplerParams {
+        // These are the OpenGL defaults.
+        uint32_t fSwizzleKey = GrSwizzle::RGBA().asKey();
+        GrGLint fBaseMipMapLevel = 0;
+        GrGLint fMaxMipMapLevel = 1000;
+        void invalidate() {
+            fSwizzleKey = ~0U;
+            fBaseMipMapLevel = ~0;
+            fMaxMipMapLevel = ~0;
+        }
     };
 
     struct IDDesc {
@@ -43,22 +66,28 @@
 
     GrBackendTexture getBackendTexture() const override;
 
-    void textureParamsModified() override { fTexParams.invalidate(); }
+    void textureParamsModified() override {
+        fSamplerParams.invalidate();
+        fNonSamplerParams.invalidate();
+    }
 
     void setRelease(sk_sp<GrReleaseProcHelper> releaseHelper) override {
         fReleaseHelper = std::move(releaseHelper);
     }
 
     // These functions are used to track the texture parameters associated with the texture.
-    const TexParams& getCachedTexParams(GrGpu::ResetTimestamp* timestamp) const {
-        *timestamp = fTexParamsTimestamp;
-        return fTexParams;
-    }
+    GrGpu::ResetTimestamp getCachedParamsTimestamp() const { return fParamsTimestamp; }
+    const SamplerParams& getCachedSamplerParams() const { return fSamplerParams; }
+    const NonSamplerParams& getCachedNonSamplerParams() const { return fNonSamplerParams; }
 
-    void setCachedTexParams(const TexParams& texParams,
-                            GrGpu::ResetTimestamp timestamp) {
-        fTexParams = texParams;
-        fTexParamsTimestamp = timestamp;
+    void setCachedParams(const SamplerParams* samplerParams,
+                         const NonSamplerParams& nonSamplerParams,
+                         GrGpu::ResetTimestamp currTimestamp) {
+        if (samplerParams) {
+            fSamplerParams = *samplerParams;
+        }
+        fNonSamplerParams = nonSamplerParams;
+        fParamsTimestamp = currTimestamp;
     }
 
     GrGLuint textureID() const { return fID; }
@@ -97,14 +126,14 @@
         }
     }
 
-    TexParams                       fTexParams;
-    GrGpu::ResetTimestamp           fTexParamsTimestamp;
-    GrGLuint                        fID;
-    GrGLenum                        fFormat;
-    GrBackendObjectOwnership        fTextureIDOwnership;
-    bool                            fBaseLevelHasBeenBoundToFBO = false;
-
-    sk_sp<GrReleaseProcHelper>      fReleaseHelper;
+    SamplerParams fSamplerParams;
+    NonSamplerParams fNonSamplerParams;
+    GrGpu::ResetTimestamp fParamsTimestamp;
+    sk_sp<GrReleaseProcHelper> fReleaseHelper;
+    GrGLuint fID;
+    GrGLenum fFormat;
+    GrBackendObjectOwnership fTextureIDOwnership;
+    bool fBaseLevelHasBeenBoundToFBO = false;
 
     typedef GrTexture INHERITED;
 };