diff options
Diffstat (limited to 'libs/hwui/font/CacheTexture.h')
-rw-r--r-- | libs/hwui/font/CacheTexture.h | 53 |
1 files changed, 30 insertions, 23 deletions
diff --git a/libs/hwui/font/CacheTexture.h b/libs/hwui/font/CacheTexture.h index bf1f4a9..fdd1623 100644 --- a/libs/hwui/font/CacheTexture.h +++ b/libs/hwui/font/CacheTexture.h @@ -24,6 +24,7 @@ #include <utils/Log.h> #include "FontUtil.h" +#include "Rect.h" namespace android { namespace uirenderer { @@ -77,12 +78,7 @@ public: } ~CacheTexture() { - if (mTexture) { - delete[] mTexture; - } - if (mTextureId) { - glDeleteTextures(1, &mTextureId); - } + releaseTexture(); reset(); } @@ -105,38 +101,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); @@ -149,11 +147,16 @@ public: return mHeight; } + inline const Rect* getDirtyRect() const { + return &mDirtyRect; + } + inline uint8_t* getTexture() const { return mTexture; } - inline GLuint getTextureId() const { + GLuint getTextureId() { + allocateTexture(); return mTextureId; } @@ -163,6 +166,9 @@ public: inline void setDirty(bool dirty) { mDirty = dirty; + if (!dirty) { + mDirtyRect.setEmpty(); + } } inline bool getLinearFiltering() const { @@ -196,6 +202,7 @@ private: bool mDirty; uint16_t mNumGlyphs; CacheBlock* mCacheBlocks; + Rect mDirtyRect; }; }; // namespace uirenderer |