summaryrefslogtreecommitdiff
path: root/libs
diff options
context:
space:
mode:
author Seigo Nonaka <nona@google.com> 2021-05-27 15:49:37 -0700
committer Seigo Nonaka <nona@google.com> 2021-05-27 15:54:24 -0700
commitd5ecababb4c65db2c7f7fa2d7e5b8ddbbae94cf1 (patch)
tree323a089246f10dc0c335e7105b17ab8750aa9c41 /libs
parent433ba6df077c26ad1aa8455f1f87e7cf1ecda706 (diff)
Calculate set of available fonts in native
The previous attempt[1] of improving SystemFonts API is not good enough for users. To further improve the performance, calculate font uniqueness in native code. From Android S, the system font information is stored in native code and has more information for skipping duplication check. Bug: 188201287 Test: atest FontFamilyUpdateRequestTest Test: atest FontListParserTest Test: atest FontManagerTest Test: atest NativeSystemFontTest Test: atest PersistentSystemFontConfigTest Test: atest SystemFontsTest Test: atest SystemFontsUniqueNameTest Test: atest UpdatableFontDirTest Test: atest UpdatableSystemFontTest Test: minikin_tests Change-Id: Ib375dcda0f278c93ec8dd21636d7a22b4174f214
Diffstat (limited to 'libs')
-rw-r--r--libs/hwui/jni/fonts/Font.cpp20
1 files changed, 20 insertions, 0 deletions
diff --git a/libs/hwui/jni/fonts/Font.cpp b/libs/hwui/jni/fonts/Font.cpp
index 5a972f56ea87..bd3b7c93466c 100644
--- a/libs/hwui/jni/fonts/Font.cpp
+++ b/libs/hwui/jni/fonts/Font.cpp
@@ -35,6 +35,7 @@
#include <minikin/FontFamily.h>
#include <minikin/FontFileParser.h>
#include <minikin/LocaleList.h>
+#include <minikin/SystemFonts.h>
#include <ui/FatVector.h>
#include <memory>
@@ -282,6 +283,22 @@ static jint Font_getSourceId(CRITICAL_JNI_PARAMS_COMMA jlong fontPtr) {
return font->font->typeface()->GetSourceId();
}
+static jlongArray Font_getAvailableFontSet(JNIEnv* env, jobject) {
+ std::vector<jlong> refArray;
+ minikin::SystemFonts::getFontSet(
+ [&refArray](const std::vector<std::shared_ptr<minikin::Font>>& fontSet) {
+ refArray.reserve(fontSet.size());
+ for (const auto& font : fontSet) {
+ std::shared_ptr<minikin::Font> fontRef = font;
+ refArray.push_back(
+ reinterpret_cast<jlong>(new FontWrapper(std::move(fontRef))));
+ }
+ });
+ jlongArray r = env->NewLongArray(refArray.size());
+ env->SetLongArrayRegion(r, 0, refArray.size(), refArray.data());
+ return r;
+}
+
// Fast Native
static jlong FontFileUtil_getFontRevision(JNIEnv* env, jobject, jobject buffer, jint index) {
NPE_CHECK_RETURN_ZERO(env, buffer);
@@ -373,6 +390,9 @@ static const JNINativeMethod gFontMethods[] = {
{"nGetAxisCount", "(J)I", (void*)Font_getAxisCount},
{"nGetAxisInfo", "(JI)J", (void*)Font_getAxisInfo},
{"nGetSourceId", "(J)I", (void*)Font_getSourceId},
+
+ // System font accessors
+ {"nGetAvailableFontSet", "()[J", (void*)Font_getAvailableFontSet},
};
static const JNINativeMethod gFontFileUtilMethods[] = {