summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChet Haase <chet@google.com>2011-12-16 15:44:59 -0800
committerChet Haase <chet@google.com>2011-12-16 15:44:59 -0800
commit9a8245629d69d81e0b62e52970feaf9c02580e75 (patch)
tree3aa17c76e6a1b2d4abde5bfe75640c2dcc08d5d9
parent6a6da2c9719c6942246d50833e04ee48f9fb2b03 (diff)
downloadframeworks_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
-rw-r--r--libs/hwui/FontRenderer.cpp41
-rw-r--r--libs/hwui/FontRenderer.h4
-rw-r--r--libs/hwui/GammaFontRenderer.cpp7
3 files changed, 49 insertions, 3 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;
diff --git a/libs/hwui/FontRenderer.h b/libs/hwui/FontRenderer.h
index 9f32747..005cdde 100644
--- a/libs/hwui/FontRenderer.h
+++ b/libs/hwui/FontRenderer.h
@@ -180,7 +180,7 @@ protected:
// Cache of glyphs
DefaultKeyedVector<glyph_t, CachedGlyphInfo*> mCachedGlyphs;
- void invalidateTextureCache();
+ void invalidateTextureCache(CacheTextureLine *cacheLine = NULL);
CachedGlyphInfo* cacheGlyph(SkPaint* paint, glyph_t glyph);
void updateGlyphCache(SkPaint* paint, const SkGlyph& skiaGlyph, CachedGlyphInfo *glyph);
@@ -219,6 +219,7 @@ public:
void init();
void deinit();
+ void flushLargeCaches();
void setGammaTable(const uint8_t* gammaTable) {
mGammaTable = gammaTable;
@@ -286,6 +287,7 @@ protected:
const uint8_t* mGammaTable;
void allocateTextureMemory(CacheTexture* cacheTexture);
+ void deallocateTextureMemory(CacheTexture* cacheTexture);
void initTextTexture();
CacheTexture *createCacheTexture(int width, int height, bool allocate);
void cacheBitmap(const SkGlyph& glyph, CachedGlyphInfo* cachedGlyph,
diff --git a/libs/hwui/GammaFontRenderer.cpp b/libs/hwui/GammaFontRenderer.cpp
index eb863e9..1be957f 100644
--- a/libs/hwui/GammaFontRenderer.cpp
+++ b/libs/hwui/GammaFontRenderer.cpp
@@ -113,6 +113,13 @@ void GammaFontRenderer::flush() {
delete mRenderers[min];
mRenderers[min] = NULL;
+
+ // Also eliminate the caches for large glyphs, as they consume significant memory
+ for (int i = 0; i < kGammaCount; ++i) {
+ if (mRenderers[i]) {
+ mRenderers[i]->flushLargeCaches();
+ }
+ }
}
FontRenderer* GammaFontRenderer::getRenderer(Gamma gamma) {