diff options
author | Romain Guy <romainguy@google.com> | 2012-09-23 14:45:31 -0700 |
---|---|---|
committer | Romain Guy <romainguy@google.com> | 2012-09-23 14:45:31 -0700 |
commit | 574cf6070d34e66dfd6f2006937986eddd1f09e7 (patch) | |
tree | 112b68de9e9015c706cf04e7c0c461f5a57b382e | |
parent | 8e586f61dd4f7fa53b01e63ac779ffc7cde05bdd (diff) | |
download | frameworks_base-574cf6070d34e66dfd6f2006937986eddd1f09e7.zip frameworks_base-574cf6070d34e66dfd6f2006937986eddd1f09e7.tar.gz frameworks_base-574cf6070d34e66dfd6f2006937986eddd1f09e7.tar.bz2 |
Make sure we never bind to texture #0
Bug #7195815
Change-Id: Ibec4b2aa4c580419eb5eb61adae6c9c960694d0c
-rw-r--r-- | libs/hwui/font/CacheTexture.h | 44 |
1 files changed, 21 insertions, 23 deletions
diff --git a/libs/hwui/font/CacheTexture.h b/libs/hwui/font/CacheTexture.h index bf1f4a9..e9ebf94 100644 --- a/libs/hwui/font/CacheTexture.h +++ b/libs/hwui/font/CacheTexture.h @@ -77,12 +77,7 @@ public: } ~CacheTexture() { - if (mTexture) { - delete[] mTexture; - } - if (mTextureId) { - glDeleteTextures(1, &mTextureId); - } + releaseTexture(); reset(); } @@ -105,38 +100,40 @@ public: void releaseTexture() { if (mTexture) { - glDeleteTextures(1, &mTextureId); delete[] mTexture; mTexture = NULL; + } + if (mTextureId) { + glDeleteTextures(1, &mTextureId); mTextureId = 0; } + mDirty = false; } /** * This method assumes that the proper texture unit is active. */ void allocateTexture() { - int width = mWidth; - int height = mHeight; - - mTexture = new uint8_t[width * height]; + if (!mTexture) { + mTexture = new uint8_t[mWidth * mHeight]; + } if (!mTextureId) { glGenTextures(1, &mTextureId); - } - glBindTexture(GL_TEXTURE_2D, mTextureId); - glPixelStorei(GL_UNPACK_ALIGNMENT, 1); - // Initialize texture dimensions - glTexImage2D(GL_TEXTURE_2D, 0, GL_ALPHA, width, height, 0, - GL_ALPHA, GL_UNSIGNED_BYTE, 0); + glBindTexture(GL_TEXTURE_2D, mTextureId); + glPixelStorei(GL_UNPACK_ALIGNMENT, 1); + // Initialize texture dimensions + glTexImage2D(GL_TEXTURE_2D, 0, GL_ALPHA, mWidth, mHeight, 0, + GL_ALPHA, GL_UNSIGNED_BYTE, 0); - const GLenum filtering = getLinearFiltering() ? GL_LINEAR : GL_NEAREST; - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, filtering); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, filtering); + const GLenum filtering = getLinearFiltering() ? GL_LINEAR : GL_NEAREST; + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, filtering); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, filtering); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); + } } bool fitBitmap(const SkGlyph& glyph, uint32_t* retOriginX, uint32_t* retOriginY); @@ -153,7 +150,8 @@ public: return mTexture; } - inline GLuint getTextureId() const { + GLuint getTextureId() { + allocateTexture(); return mTextureId; } |