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
This commit is contained in:
@@ -96,6 +96,8 @@ class MinikinFontFreeType;
|
|||||||
|
|
||||||
class MinikinFont : public MinikinRefCounted {
|
class MinikinFont : public MinikinRefCounted {
|
||||||
public:
|
public:
|
||||||
|
virtual ~MinikinFont();
|
||||||
|
|
||||||
virtual float GetHorizontalAdvance(uint32_t glyph_id,
|
virtual float GetHorizontalAdvance(uint32_t glyph_id,
|
||||||
const MinikinPaint &paint) const = 0;
|
const MinikinPaint &paint) const = 0;
|
||||||
|
|
||||||
|
|||||||
@@ -32,6 +32,7 @@ minikin_src_files := \
|
|||||||
Measurement.cpp \
|
Measurement.cpp \
|
||||||
MinikinInternal.cpp \
|
MinikinInternal.cpp \
|
||||||
MinikinRefCounted.cpp \
|
MinikinRefCounted.cpp \
|
||||||
|
MinikinFont.cpp \
|
||||||
MinikinFontFreeType.cpp \
|
MinikinFontFreeType.cpp \
|
||||||
SparseBitSet.cpp \
|
SparseBitSet.cpp \
|
||||||
WordBreaker.cpp
|
WordBreaker.cpp
|
||||||
|
|||||||
@@ -75,6 +75,10 @@ public:
|
|||||||
mCache.clear();
|
mCache.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void remove(int32_t fontId) {
|
||||||
|
mCache.remove(fontId);
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static const size_t kMaxEntries = 100;
|
static const size_t kMaxEntries = 100;
|
||||||
|
|
||||||
@@ -95,6 +99,12 @@ void purgeHbFontCacheLocked() {
|
|||||||
getFontCacheLocked()->clear();
|
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) {
|
hb_font_t* getHbFontLocked(MinikinFont* minikinFont) {
|
||||||
assertMinikinLocked();
|
assertMinikinLocked();
|
||||||
static hb_font_t* nullFaceFont = nullptr;
|
static hb_font_t* nullFaceFont = nullptr;
|
||||||
|
|||||||
@@ -23,6 +23,7 @@ namespace android {
|
|||||||
class MinikinFont;
|
class MinikinFont;
|
||||||
|
|
||||||
void purgeHbFontCacheLocked();
|
void purgeHbFontCacheLocked();
|
||||||
|
void purgeHbFont(const MinikinFont* minikinFont);
|
||||||
hb_font_t* getHbFontLocked(MinikinFont* minikinFont);
|
hb_font_t* getHbFontLocked(MinikinFont* minikinFont);
|
||||||
|
|
||||||
} // namespace android
|
} // namespace android
|
||||||
|
|||||||
26
engine/src/flutter/libs/minikin/MinikinFont.cpp
Normal file
26
engine/src/flutter/libs/minikin/MinikinFont.cpp
Normal file
@@ -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
|
||||||
Reference in New Issue
Block a user