diff options
author | Raph Levien <raph@google.com> | 2016-04-07 12:20:12 -0700 |
---|---|---|
committer | Raph Levien <raph@google.com> | 2016-04-07 13:43:15 -0700 |
commit | 9afcc6e2bd4d89e4e1deb6e18c3c4daca4e114fd (patch) | |
tree | 09e961b82c26cc1b76b2f1a613b788ad7635d983 | |
parent | f3afe92def0fff022889fd036d68451223aac146 (diff) | |
download | android_frameworks_minikin-9afcc6e2bd4d89e4e1deb6e18c3c4daca4e114fd.tar.gz android_frameworks_minikin-9afcc6e2bd4d89e4e1deb6e18c3c4daca4e114fd.tar.bz2 android_frameworks_minikin-9afcc6e2bd4d89e4e1deb6e18c3c4daca4e114fd.zip |
Purge hb font on Minikin font destruction
This patch eagerly purges the corresponding hb_font_t object from
the HbFontCache when the underlying MinikinFont is destroyed. After
that, the key will no longer be accessed, so having the entry is
wastes memory.
Bug: 27251075
Bug: 27860101
Change-Id: I1b98016133fe3baf6525ac37d970a65ddccadb4f
-rw-r--r-- | include/minikin/MinikinFont.h | 2 | ||||
-rw-r--r-- | libs/minikin/Android.mk | 1 | ||||
-rw-r--r-- | libs/minikin/HbFontCache.cpp | 10 | ||||
-rw-r--r-- | libs/minikin/HbFontCache.h | 1 | ||||
-rw-r--r-- | libs/minikin/MinikinFont.cpp | 26 |
5 files changed, 40 insertions, 0 deletions
diff --git a/include/minikin/MinikinFont.h b/include/minikin/MinikinFont.h index 2ad2151..5c0ab0f 100644 --- a/include/minikin/MinikinFont.h +++ b/include/minikin/MinikinFont.h @@ -96,6 +96,8 @@ class MinikinFontFreeType; class MinikinFont : public MinikinRefCounted { public: + virtual ~MinikinFont(); + virtual float GetHorizontalAdvance(uint32_t glyph_id, const MinikinPaint &paint) const = 0; diff --git a/libs/minikin/Android.mk b/libs/minikin/Android.mk index 7cd6f68..2b5ff06 100644 --- a/libs/minikin/Android.mk +++ b/libs/minikin/Android.mk @@ -32,6 +32,7 @@ minikin_src_files := \ Measurement.cpp \ MinikinInternal.cpp \ MinikinRefCounted.cpp \ + MinikinFont.cpp \ MinikinFontFreeType.cpp \ SparseBitSet.cpp \ WordBreaker.cpp diff --git a/libs/minikin/HbFontCache.cpp b/libs/minikin/HbFontCache.cpp index 73308ef..7a6b3c1 100644 --- a/libs/minikin/HbFontCache.cpp +++ b/libs/minikin/HbFontCache.cpp @@ -75,6 +75,10 @@ public: mCache.clear(); } + void remove(int32_t fontId) { + mCache.remove(fontId); + } + private: static const size_t kMaxEntries = 100; @@ -95,6 +99,12 @@ void purgeHbFontCacheLocked() { getFontCacheLocked()->clear(); } +void purgeHbFont(const MinikinFont* minikinFont) { + AutoMutex _l(gMinikinLock); + const int32_t fontId = minikinFont->GetUniqueId(); + getFontCacheLocked()->remove(fontId); +} + hb_font_t* getHbFontLocked(MinikinFont* minikinFont) { assertMinikinLocked(); static hb_font_t* nullFaceFont = nullptr; diff --git a/libs/minikin/HbFontCache.h b/libs/minikin/HbFontCache.h index 62564d3..92e465a 100644 --- a/libs/minikin/HbFontCache.h +++ b/libs/minikin/HbFontCache.h @@ -23,6 +23,7 @@ namespace android { class MinikinFont; void purgeHbFontCacheLocked(); +void purgeHbFont(const MinikinFont* minikinFont); hb_font_t* getHbFontLocked(MinikinFont* minikinFont); } // namespace android diff --git a/libs/minikin/MinikinFont.cpp b/libs/minikin/MinikinFont.cpp new file mode 100644 index 0000000..d56ec9c --- /dev/null +++ b/libs/minikin/MinikinFont.cpp @@ -0,0 +1,26 @@ +/* + * Copyright (C) 2016 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include <minikin/MinikinFont.h> +#include "HbFontCache.h" + +namespace android { + +MinikinFont::~MinikinFont() { + purgeHbFont(this); +} + +} // namespace android |