diff options
author | Chet Haase <chet@google.com> | 2011-12-16 15:44:59 -0800 |
---|---|---|
committer | Chet Haase <chet@google.com> | 2011-12-16 15:44:59 -0800 |
commit | 9a8245629d69d81e0b62e52970feaf9c02580e75 (patch) | |
tree | 3aa17c76e6a1b2d4abde5bfe75640c2dcc08d5d9 /libs/hwui/FontRenderer.cpp | |
parent | 6a6da2c9719c6942246d50833e04ee48f9fb2b03 (diff) | |
download | frameworks_base-9a8245629d69d81e0b62e52970feaf9c02580e75.zip frameworks_base-9a8245629d69d81e0b62e52970feaf9c02580e75.tar.gz frameworks_base-9a8245629d69d81e0b62e52970feaf9c02580e75.tar.bz2 |
De-allocate caches for large glyphs when trimming memory
Currently, font renderers eliminate some texture caches when
memory is trimmed. This change makes it go further by eliminating the
large-glyph caches for all font renderers. These caches are
only allocated as needed, but continue to consume large amounts of
memory (CPU and GPU) after that allocation. De-allocating this memory
on a trim operation should prevent background apps from holding onto
this memory in the possible case that they have allocated it by drawing
large glyphs.
Change-Id: Id7a3ab49b244e036b442d87252fb40aeca8fdb26
Diffstat (limited to 'libs/hwui/FontRenderer.cpp')
-rw-r--r-- | libs/hwui/FontRenderer.cpp | 41 |
1 files changed, 39 insertions, 2 deletions
diff --git a/libs/hwui/FontRenderer.cpp b/libs/hwui/FontRenderer.cpp index 34245b0..8462307 100644 --- a/libs/hwui/FontRenderer.cpp +++ b/libs/hwui/FontRenderer.cpp @@ -85,9 +85,12 @@ Font::~Font() { } } -void Font::invalidateTextureCache() { +void Font::invalidateTextureCache(CacheTextureLine *cacheLine) { for (uint32_t i = 0; i < mCachedGlyphs.size(); i++) { - mCachedGlyphs.valueAt(i)->mIsValid = false; + CachedGlyphInfo* cachedGlyph = mCachedGlyphs.valueAt(i); + if (cacheLine == NULL || cachedGlyph->mCachedTextureLine == cacheLine) { + cachedGlyph->mIsValid = false; + } } } @@ -414,6 +417,40 @@ void FontRenderer::flushAllAndInvalidate() { } } +void FontRenderer::deallocateTextureMemory(CacheTexture *cacheTexture) { + if (cacheTexture && cacheTexture->mTexture) { + glDeleteTextures(1, &cacheTexture->mTextureId); + delete cacheTexture->mTexture; + cacheTexture->mTexture = NULL; + } +} + +void FontRenderer::flushLargeCaches() { + if ((!mCacheTexture128 || !mCacheTexture128->mTexture) && + (!mCacheTexture256 || !mCacheTexture256->mTexture) && + (!mCacheTexture512 || !mCacheTexture512->mTexture)) { + // Typical case; no large glyph caches allocated + return; + } + + for (uint32_t i = 0; i < mCacheLines.size(); i++) { + CacheTextureLine* cacheLine = mCacheLines[i]; + if ((cacheLine->mCacheTexture == mCacheTexture128 || + cacheLine->mCacheTexture == mCacheTexture256 || + cacheLine->mCacheTexture == mCacheTexture512) && + cacheLine->mCacheTexture->mTexture != NULL) { + cacheLine->mCurrentCol = 0; + for (uint32_t i = 0; i < mActiveFonts.size(); i++) { + mActiveFonts[i]->invalidateTextureCache(cacheLine); + } + } + } + + deallocateTextureMemory(mCacheTexture128); + deallocateTextureMemory(mCacheTexture256); + deallocateTextureMemory(mCacheTexture512); +} + void FontRenderer::allocateTextureMemory(CacheTexture *cacheTexture) { int width = cacheTexture->mWidth; int height = cacheTexture->mHeight; |