Add purgeCaches() method

Expose a method to purge caches used for TextLayout, useful for low
memory conditions.

Change-Id: I92f41afe987b7be4af5ca0a0c50fb51be35a2758
This commit is contained in:
Raph Levien 2014-06-25 15:58:24 -07:00
parent e8bed5d3cc
commit 69f3585cf6
2 changed files with 11 additions and 0 deletions

View File

@ -100,6 +100,9 @@ public:
void getBounds(MinikinRect* rect);
// Purge all caches, useful in low memory conditions
static void purgeCaches();
private:
// Find a face in the mFaces vector, or create a new entry
int findFace(FakedFont face, LayoutContext* ctx);

View File

@ -799,4 +799,12 @@ void Layout::getBounds(MinikinRect* bounds) {
bounds->set(mBounds);
}
void Layout::purgeCaches() {
AutoMutex _l(gMinikinLock);
LayoutCache& layoutCache = LayoutEngine::getInstance().layoutCache;
layoutCache.mCache.clear();
HbFaceCache& hbCache = LayoutEngine::getInstance().hbFaceCache;
hbCache.mCache.clear();
}
} // namespace android