From 22e41754f6470ff1f4c0e0a56d01f7f555b59e21 Mon Sep 17 00:00:00 2001 From: Raph Levien Date: Wed, 25 Jun 2014 15:58:24 -0700 Subject: Add purgeCaches() method Expose a method to purge caches used for TextLayout, useful for low memory conditions. Change-Id: I92f41afe987b7be4af5ca0a0c50fb51be35a2758 --- include/minikin/Layout.h | 3 +++ libs/minikin/Layout.cpp | 8 ++++++++ 2 files changed, 11 insertions(+) diff --git a/include/minikin/Layout.h b/include/minikin/Layout.h index 1b91ad8..e30f2f2 100644 --- a/include/minikin/Layout.h +++ b/include/minikin/Layout.h @@ -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); diff --git a/libs/minikin/Layout.cpp b/libs/minikin/Layout.cpp index 762a7db..48db129 100644 --- a/libs/minikin/Layout.cpp +++ b/libs/minikin/Layout.cpp @@ -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 -- cgit v1.2.3