Fix mismatch in assumed defaults vs. actual defaults

Bug: 26584230
Change-Id: Ia0271b097a40123c18f6b3540c1168cba109b5ce
diff --git a/libs/hwui/Texture.cpp b/libs/hwui/Texture.cpp
index 0f02f4c..5046d37 100644
--- a/libs/hwui/Texture.cpp
+++ b/libs/hwui/Texture.cpp
@@ -41,9 +41,7 @@
 void Texture::setWrapST(GLenum wrapS, GLenum wrapT, bool bindTexture, bool force,
         GLenum renderTarget) {
 
-    if (mFirstWrap || force || wrapS != mWrapS || wrapT != mWrapT) {
-        mFirstWrap = false;
-
+    if (force || wrapS != mWrapS || wrapT != mWrapT) {
         mWrapS = wrapS;
         mWrapT = wrapT;
 
@@ -59,9 +57,7 @@
 void Texture::setFilterMinMag(GLenum min, GLenum mag, bool bindTexture, bool force,
         GLenum renderTarget) {
 
-    if (mFirstFilter || force || min != mMinFilter || mag != mMagFilter) {
-        mFirstFilter = false;
-
+    if (force || min != mMinFilter || mag != mMagFilter) {
         mMinFilter = min;
         mMagFilter = mag;
 
@@ -92,6 +88,13 @@
     return true;
 }
 
+void Texture::resetCachedParams() {
+    mWrapS = GL_REPEAT;
+    mWrapT = GL_REPEAT;
+    mMinFilter = GL_NEAREST_MIPMAP_LINEAR;
+    mMagFilter = GL_LINEAR;
+}
+
 void Texture::upload(GLint internalformat, uint32_t width, uint32_t height,
         GLenum format, GLenum type, const void* pixels) {
     GL_CHECKPOINT();
@@ -99,6 +102,7 @@
     if (!mId) {
         glGenTextures(1, &mId);
         needsAlloc = true;
+        resetCachedParams();
     }
     mCaches.textureState().bindTexture(GL_TEXTURE_2D, mId);
     if (needsAlloc) {
@@ -206,10 +210,12 @@
     // If the texture had mipmap enabled but not anymore,
     // force a glTexImage2D to discard the mipmap levels
     bool needsAlloc = canMipMap && mipMap && !bitmap.hasHardwareMipMap();
+    bool setDefaultParams = false;
 
     if (!mId) {
         glGenTextures(1, &mId);
         needsAlloc = true;
+        setDefaultParams = true;
     }
 
     GLint format, type;
@@ -244,11 +250,8 @@
         }
     }
 
-    if (mFirstFilter) {
+    if (setDefaultParams) {
         setFilter(GL_NEAREST);
-    }
-
-    if (mFirstWrap) {
         setWrap(GL_CLAMP_TO_EDGE);
     }
 }
diff --git a/libs/hwui/Texture.h b/libs/hwui/Texture.h
index 4e8e6dc..9749f73 100644
--- a/libs/hwui/Texture.h
+++ b/libs/hwui/Texture.h
@@ -149,26 +149,22 @@
 
     // Returns true if the size changed, false if it was the same
     bool updateSize(uint32_t width, uint32_t height, GLint format);
+    void resetCachedParams();
 
     GLuint mId = 0;
     uint32_t mWidth = 0;
     uint32_t mHeight = 0;
     GLint mFormat = 0;
 
-    /**
-     * Last wrap modes set on this texture.
+    /* See GLES spec section 3.8.14
+     * "In the initial state, the value assigned to TEXTURE_MIN_FILTER is
+     * NEAREST_MIPMAP_LINEAR and the value for TEXTURE_MAG_FILTER is LINEAR.
+     * s, t, and r wrap modes are all set to REPEAT."
      */
-    GLenum mWrapS = GL_CLAMP_TO_EDGE;
-    GLenum mWrapT = GL_CLAMP_TO_EDGE;
-
-    /**
-     * Last filters set on this texture.
-     */
-    GLenum mMinFilter = GL_NEAREST;
-    GLenum mMagFilter = GL_NEAREST;
-
-    bool mFirstFilter = true;
-    bool mFirstWrap = true;
+    GLenum mWrapS = GL_REPEAT;
+    GLenum mWrapT = GL_REPEAT;
+    GLenum mMinFilter = GL_NEAREST_MIPMAP_LINEAR;
+    GLenum mMagFilter = GL_LINEAR;
 
     Caches& mCaches;
 }; // struct Texture