Preload minikin LocaleListCache in Zygote.
This saves ~31 KB per process on oriole. Bug: 174672300 Test: atest CtsGraphicsTestCases:android.graphics.cts.TypefaceTest Change-Id: Ic70ea842985a0aca441a31327e41980ed47bc961
This commit is contained in:
@@ -57,6 +57,7 @@ import com.android.internal.annotations.VisibleForTesting;
|
||||
import com.android.internal.util.Preconditions;
|
||||
|
||||
import dalvik.annotation.optimization.CriticalNative;
|
||||
import dalvik.annotation.optimization.FastNative;
|
||||
|
||||
import libcore.util.NativeAllocationRegistry;
|
||||
|
||||
@@ -1395,6 +1396,9 @@ public class Typeface {
|
||||
FontConfig config = SystemFonts.getSystemPreinstalledFontConfig();
|
||||
for (int i = 0; i < config.getFontFamilies().size(); ++i) {
|
||||
FontConfig.FontFamily family = config.getFontFamilies().get(i);
|
||||
if (!family.getLocaleList().isEmpty()) {
|
||||
nativeRegisterLocaleList(family.getLocaleList().toLanguageTags());
|
||||
}
|
||||
boolean loadFamily = false;
|
||||
for (int j = 0; j < family.getLocaleList().size(); ++j) {
|
||||
String fontScript = ULocale.addLikelySubtags(
|
||||
@@ -1541,4 +1545,7 @@ public class Typeface {
|
||||
private static native void nativeAddFontCollections(long nativePtr);
|
||||
|
||||
private static native void nativeWarmUpCache(String fileName);
|
||||
|
||||
@FastNative
|
||||
private static native void nativeRegisterLocaleList(String locales);
|
||||
}
|
||||
|
||||
@@ -20,18 +20,20 @@
|
||||
#include <minikin/FontCollection.h>
|
||||
#include <minikin/FontFamily.h>
|
||||
#include <minikin/FontFileParser.h>
|
||||
#include <minikin/LocaleList.h>
|
||||
#include <minikin/SystemFonts.h>
|
||||
#include <nativehelper/ScopedPrimitiveArray.h>
|
||||
#include <nativehelper/ScopedUtfChars.h>
|
||||
|
||||
#include <mutex>
|
||||
#include <unordered_map>
|
||||
|
||||
#include "FontUtils.h"
|
||||
#include "GraphicsJNI.h"
|
||||
#include "SkData.h"
|
||||
#include "SkTypeface.h"
|
||||
#include "fonts/Font.h"
|
||||
|
||||
#include <mutex>
|
||||
#include <unordered_map>
|
||||
|
||||
#ifdef __ANDROID__
|
||||
#include <sys/stat.h>
|
||||
#endif
|
||||
@@ -380,6 +382,12 @@ static void Typeface_addFontCollection(CRITICAL_JNI_PARAMS_COMMA jlong faceHandl
|
||||
minikin::SystemFonts::addFontMap(std::move(collection));
|
||||
}
|
||||
|
||||
// Fast Native
|
||||
static void Typeface_registerLocaleList(JNIEnv* env, jobject, jstring jLocales) {
|
||||
ScopedUtfChars locales(env, jLocales);
|
||||
minikin::registerLocaleList(locales.c_str());
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
static const JNINativeMethod gTypefaceMethods[] = {
|
||||
@@ -405,6 +413,7 @@ static const JNINativeMethod gTypefaceMethods[] = {
|
||||
{"nativeGetFamily", "(JI)J", (void*)Typeface_getFamily},
|
||||
{"nativeWarmUpCache", "(Ljava/lang/String;)V", (void*)Typeface_warmUpCache},
|
||||
{"nativeAddFontCollections", "(J)V", (void*)Typeface_addFontCollection},
|
||||
{"nativeRegisterLocaleList", "(Ljava/lang/String;)V", (void*)Typeface_registerLocaleList},
|
||||
};
|
||||
|
||||
int register_android_graphics_Typeface(JNIEnv* env)
|
||||
|
||||
Reference in New Issue
Block a user