From 48247a2956f34d5d709660869273e0f7356e42b6 Mon Sep 17 00:00:00 2001 From: John Reck Date: Fri, 22 Jan 2016 10:55:32 -0800 Subject: [PATCH] Fix mismatch in assumed defaults vs. actual defaults Bug: 26584230 Change-Id: Ia0271b097a40123c18f6b3540c1168cba109b5ce --- libs/hwui/Texture.cpp | 23 +++++++++++++---------- libs/hwui/Texture.h | 22 +++++++++------------- 2 files changed, 22 insertions(+), 23 deletions(-) diff --git a/libs/hwui/Texture.cpp b/libs/hwui/Texture.cpp index 0f02f4c0aba76..5046d37150fe2 100644 --- a/libs/hwui/Texture.cpp +++ b/libs/hwui/Texture.cpp @@ -41,9 +41,7 @@ static int bytesPerPixel(GLint glFormat) { 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::setWrapST(GLenum wrapS, GLenum wrapT, bool bindTexture, bool force 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 @@ bool Texture::updateSize(uint32_t width, uint32_t height, GLint format) { 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 @@ void Texture::upload(GLint internalformat, uint32_t width, uint32_t height, if (!mId) { glGenTextures(1, &mId); needsAlloc = true; + resetCachedParams(); } mCaches.textureState().bindTexture(GL_TEXTURE_2D, mId); if (needsAlloc) { @@ -206,10 +210,12 @@ void Texture::upload(const SkBitmap& bitmap) { // 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 @@ void Texture::upload(const SkBitmap& bitmap) { } } - 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 4e8e6dcf1a775..9749f734fd1fc 100644 --- a/libs/hwui/Texture.h +++ b/libs/hwui/Texture.h @@ -149,26 +149,22 @@ private: // 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