Loading apct-tests/perftests/core/src/android/graphics/perftests/TypefaceSerializationPerfTest.java +3 −1 Original line number Diff line number Diff line Loading @@ -20,6 +20,7 @@ import android.graphics.Typeface; import android.os.SharedMemory; import android.perftests.utils.BenchmarkState; import android.perftests.utils.PerfStatusReporter; import android.util.ArrayMap; import androidx.test.filters.LargeTest; import androidx.test.runner.AndroidJUnit4; Loading Loading @@ -55,9 +56,10 @@ public class TypefaceSerializationPerfTest { ByteBuffer buffer = memory.mapReadOnly().order(ByteOrder.BIG_ENDIAN); BenchmarkState state = mPerfStatusReporter.getBenchmarkState(); ArrayMap<String, Typeface> out = new ArrayMap<>(); while (state.keepRunning()) { buffer.position(0); Typeface.deserializeFontMap(buffer); Typeface.deserializeFontMap(buffer, out); } } Loading core/api/test-current.txt +1 −1 Original line number Diff line number Diff line Loading @@ -999,7 +999,7 @@ package android.graphics { } public class Typeface { method @NonNull public static java.util.Map<java.lang.String,android.graphics.Typeface> deserializeFontMap(@NonNull java.nio.ByteBuffer) throws java.io.IOException; method @NonNull public static long[] deserializeFontMap(@NonNull java.nio.ByteBuffer, @NonNull java.util.Map<java.lang.String,android.graphics.Typeface>) throws java.io.IOException; method @Nullable public static android.os.SharedMemory getSystemFontMapSharedMemory(); method @NonNull public static android.os.SharedMemory serializeFontMap(@NonNull java.util.Map<java.lang.String,android.graphics.Typeface>) throws android.system.ErrnoException, java.io.IOException; } Loading core/tests/coretests/src/android/graphics/TypefaceTest.java +4 −2 Original line number Diff line number Diff line Loading @@ -27,6 +27,7 @@ import android.graphics.fonts.FontFamily; import android.graphics.fonts.SystemFonts; import android.os.SharedMemory; import android.text.FontConfig; import android.util.ArrayMap; import androidx.test.InstrumentationRegistry; import androidx.test.filters.LargeTest; Loading Loading @@ -200,8 +201,9 @@ public class TypefaceTest { Map<String, Typeface> systemFontMap = SystemFonts.buildSystemTypefaces(fontConfig, fallbackMap); SharedMemory sharedMemory = Typeface.serializeFontMap(systemFontMap); Map<String, Typeface> copiedFontMap = Typeface.deserializeFontMap(sharedMemory.mapReadOnly().order(ByteOrder.BIG_ENDIAN)); Map<String, Typeface> copiedFontMap = new ArrayMap<>(); Typeface.deserializeFontMap(sharedMemory.mapReadOnly().order(ByteOrder.BIG_ENDIAN), copiedFontMap); assertEquals(systemFontMap.size(), copiedFontMap.size()); for (String key : systemFontMap.keySet()) { assertTrue(copiedFontMap.containsKey(key)); Loading graphics/java/android/graphics/Typeface.java +16 −5 Original line number Diff line number Diff line Loading @@ -1259,20 +1259,21 @@ public class Typeface { * @hide */ @TestApi public static @NonNull Map<String, Typeface> deserializeFontMap(@NonNull ByteBuffer buffer) public static @NonNull long[] deserializeFontMap( @NonNull ByteBuffer buffer, @NonNull Map<String, Typeface> out) throws IOException { Map<String, Typeface> fontMap = new ArrayMap<>(); int typefacesBytesCount = buffer.getInt(); long[] nativePtrs = nativeReadTypefaces(buffer.slice()); if (nativePtrs == null) { throw new IOException("Could not read typefaces"); } out.clear(); buffer.position(buffer.position() + typefacesBytesCount); for (long nativePtr : nativePtrs) { String name = readString(buffer); fontMap.put(name, new Typeface(nativePtr)); out.put(name, new Typeface(nativePtr)); } return fontMap; return nativePtrs; } private static String readString(ByteBuffer buffer) { Loading Loading @@ -1330,7 +1331,14 @@ public class Typeface { return; } sSystemFontMapBuffer = sharedMemory.mapReadOnly().order(ByteOrder.BIG_ENDIAN); Map<String, Typeface> systemFontMap = deserializeFontMap(sSystemFontMapBuffer); Map<String, Typeface> systemFontMap = new ArrayMap<>(); long[] nativePtrs = deserializeFontMap(sSystemFontMapBuffer, systemFontMap); // Initialize native font APIs. The native font API will read fonts.xml by itself if // Typeface is initialized with loadPreinstalledSystemFontMap. for (long ptr : nativePtrs) { nativeAddFontCollections(ptr); } setSystemFontMap(systemFontMap); } finally { Trace.traceEnd(Trace.TRACE_TAG_GRAPHICS); Loading Loading @@ -1528,5 +1536,8 @@ public class Typeface { private static native void nativeForceSetStaticFinalField(String fieldName, Typeface typeface); @CriticalNative private static native void nativeAddFontCollections(long nativePtr); private static native void nativeWarmUpCache(String fileName); } libs/hwui/jni/Typeface.cpp +7 −0 Original line number Diff line number Diff line Loading @@ -373,6 +373,12 @@ static void Typeface_warmUpCache(JNIEnv* env, jobject, jstring jFilePath) { makeSkDataCached(filePath.c_str(), false /* fs verity */); } // Critical Native static void Typeface_addFontCollection(CRITICAL_JNI_PARAMS_COMMA jlong faceHandle) { std::shared_ptr<minikin::FontCollection> collection = toTypeface(faceHandle)->fFontCollection; minikin::SystemFonts::addFontMap(std::move(collection)); } /////////////////////////////////////////////////////////////////////////////// static const JNINativeMethod gTypefaceMethods[] = { Loading @@ -397,6 +403,7 @@ static const JNINativeMethod gTypefaceMethods[] = { {"nativeGetFamilySize", "(J)I", (void*)Typeface_getFamilySize}, {"nativeGetFamily", "(JI)J", (void*)Typeface_getFamily}, {"nativeWarmUpCache", "(Ljava/lang/String;)V", (void*)Typeface_warmUpCache}, {"nativeAddFontCollections", "(J)V", (void*)Typeface_addFontCollection}, }; int register_android_graphics_Typeface(JNIEnv* env) Loading Loading
apct-tests/perftests/core/src/android/graphics/perftests/TypefaceSerializationPerfTest.java +3 −1 Original line number Diff line number Diff line Loading @@ -20,6 +20,7 @@ import android.graphics.Typeface; import android.os.SharedMemory; import android.perftests.utils.BenchmarkState; import android.perftests.utils.PerfStatusReporter; import android.util.ArrayMap; import androidx.test.filters.LargeTest; import androidx.test.runner.AndroidJUnit4; Loading Loading @@ -55,9 +56,10 @@ public class TypefaceSerializationPerfTest { ByteBuffer buffer = memory.mapReadOnly().order(ByteOrder.BIG_ENDIAN); BenchmarkState state = mPerfStatusReporter.getBenchmarkState(); ArrayMap<String, Typeface> out = new ArrayMap<>(); while (state.keepRunning()) { buffer.position(0); Typeface.deserializeFontMap(buffer); Typeface.deserializeFontMap(buffer, out); } } Loading
core/api/test-current.txt +1 −1 Original line number Diff line number Diff line Loading @@ -999,7 +999,7 @@ package android.graphics { } public class Typeface { method @NonNull public static java.util.Map<java.lang.String,android.graphics.Typeface> deserializeFontMap(@NonNull java.nio.ByteBuffer) throws java.io.IOException; method @NonNull public static long[] deserializeFontMap(@NonNull java.nio.ByteBuffer, @NonNull java.util.Map<java.lang.String,android.graphics.Typeface>) throws java.io.IOException; method @Nullable public static android.os.SharedMemory getSystemFontMapSharedMemory(); method @NonNull public static android.os.SharedMemory serializeFontMap(@NonNull java.util.Map<java.lang.String,android.graphics.Typeface>) throws android.system.ErrnoException, java.io.IOException; } Loading
core/tests/coretests/src/android/graphics/TypefaceTest.java +4 −2 Original line number Diff line number Diff line Loading @@ -27,6 +27,7 @@ import android.graphics.fonts.FontFamily; import android.graphics.fonts.SystemFonts; import android.os.SharedMemory; import android.text.FontConfig; import android.util.ArrayMap; import androidx.test.InstrumentationRegistry; import androidx.test.filters.LargeTest; Loading Loading @@ -200,8 +201,9 @@ public class TypefaceTest { Map<String, Typeface> systemFontMap = SystemFonts.buildSystemTypefaces(fontConfig, fallbackMap); SharedMemory sharedMemory = Typeface.serializeFontMap(systemFontMap); Map<String, Typeface> copiedFontMap = Typeface.deserializeFontMap(sharedMemory.mapReadOnly().order(ByteOrder.BIG_ENDIAN)); Map<String, Typeface> copiedFontMap = new ArrayMap<>(); Typeface.deserializeFontMap(sharedMemory.mapReadOnly().order(ByteOrder.BIG_ENDIAN), copiedFontMap); assertEquals(systemFontMap.size(), copiedFontMap.size()); for (String key : systemFontMap.keySet()) { assertTrue(copiedFontMap.containsKey(key)); Loading
graphics/java/android/graphics/Typeface.java +16 −5 Original line number Diff line number Diff line Loading @@ -1259,20 +1259,21 @@ public class Typeface { * @hide */ @TestApi public static @NonNull Map<String, Typeface> deserializeFontMap(@NonNull ByteBuffer buffer) public static @NonNull long[] deserializeFontMap( @NonNull ByteBuffer buffer, @NonNull Map<String, Typeface> out) throws IOException { Map<String, Typeface> fontMap = new ArrayMap<>(); int typefacesBytesCount = buffer.getInt(); long[] nativePtrs = nativeReadTypefaces(buffer.slice()); if (nativePtrs == null) { throw new IOException("Could not read typefaces"); } out.clear(); buffer.position(buffer.position() + typefacesBytesCount); for (long nativePtr : nativePtrs) { String name = readString(buffer); fontMap.put(name, new Typeface(nativePtr)); out.put(name, new Typeface(nativePtr)); } return fontMap; return nativePtrs; } private static String readString(ByteBuffer buffer) { Loading Loading @@ -1330,7 +1331,14 @@ public class Typeface { return; } sSystemFontMapBuffer = sharedMemory.mapReadOnly().order(ByteOrder.BIG_ENDIAN); Map<String, Typeface> systemFontMap = deserializeFontMap(sSystemFontMapBuffer); Map<String, Typeface> systemFontMap = new ArrayMap<>(); long[] nativePtrs = deserializeFontMap(sSystemFontMapBuffer, systemFontMap); // Initialize native font APIs. The native font API will read fonts.xml by itself if // Typeface is initialized with loadPreinstalledSystemFontMap. for (long ptr : nativePtrs) { nativeAddFontCollections(ptr); } setSystemFontMap(systemFontMap); } finally { Trace.traceEnd(Trace.TRACE_TAG_GRAPHICS); Loading Loading @@ -1528,5 +1536,8 @@ public class Typeface { private static native void nativeForceSetStaticFinalField(String fieldName, Typeface typeface); @CriticalNative private static native void nativeAddFontCollections(long nativePtr); private static native void nativeWarmUpCache(String fileName); }
libs/hwui/jni/Typeface.cpp +7 −0 Original line number Diff line number Diff line Loading @@ -373,6 +373,12 @@ static void Typeface_warmUpCache(JNIEnv* env, jobject, jstring jFilePath) { makeSkDataCached(filePath.c_str(), false /* fs verity */); } // Critical Native static void Typeface_addFontCollection(CRITICAL_JNI_PARAMS_COMMA jlong faceHandle) { std::shared_ptr<minikin::FontCollection> collection = toTypeface(faceHandle)->fFontCollection; minikin::SystemFonts::addFontMap(std::move(collection)); } /////////////////////////////////////////////////////////////////////////////// static const JNINativeMethod gTypefaceMethods[] = { Loading @@ -397,6 +403,7 @@ static const JNINativeMethod gTypefaceMethods[] = { {"nativeGetFamilySize", "(J)I", (void*)Typeface_getFamilySize}, {"nativeGetFamily", "(JI)J", (void*)Typeface_getFamily}, {"nativeWarmUpCache", "(Ljava/lang/String;)V", (void*)Typeface_warmUpCache}, {"nativeAddFontCollections", "(J)V", (void*)Typeface_addFontCollection}, }; int register_android_graphics_Typeface(JNIEnv* env) Loading