Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit c2832239 authored by Kohsuke Yatoh's avatar Kohsuke Yatoh Committed by Android (Google) Code Review
Browse files

Merge "Preload minikin LocaleListCache in Zygote."

parents 00c545be bb4e06fd
Loading
Loading
Loading
Loading
+7 −0
Original line number Diff line number Diff line
@@ -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;

@@ -1406,6 +1407,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(
@@ -1568,4 +1572,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);
}
+12 −3
Original line number Diff line number Diff line
@@ -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)