This repository was archived by the owner on Feb 25, 2025. It is now read-only.
File tree 3 files changed +28
-0
lines changed
io/flutter/embedding/engine 3 files changed +28
-0
lines changed Original file line number Diff line number Diff line change 21
21
#include " flutter/shell/common/shell.h"
22
22
#include " flutter/shell/common/switches.h"
23
23
#include " third_party/dart/runtime/include/dart_tools_api.h"
24
+ #include " third_party/skia/include/core/SkFontMgr.h"
24
25
25
26
namespace flutter {
26
27
@@ -155,6 +156,10 @@ void FlutterMain::SetupObservatoryUriCallback(JNIEnv* env) {
155
156
});
156
157
}
157
158
159
+ static void CreateDefaultFontManager (JNIEnv* env, jclass jcaller) {
160
+ sk_sp<SkFontMgr> font_mgr (SkFontMgr::RefDefault ());
161
+ }
162
+
158
163
bool FlutterMain::Register (JNIEnv* env) {
159
164
static const JNINativeMethod methods[] = {
160
165
{
@@ -163,6 +168,11 @@ bool FlutterMain::Register(JNIEnv* env) {
163
168
" lang/String;Ljava/lang/String;Ljava/lang/String;J)V" ,
164
169
.fnPtr = reinterpret_cast <void *>(&Init),
165
170
},
171
+ {
172
+ .name = " nativeCreateDefaultFontManager" ,
173
+ .signature = " ()V" ,
174
+ .fnPtr = reinterpret_cast <void *>(&CreateDefaultFontManager),
175
+ },
166
176
};
167
177
168
178
jclass clazz = env->FindClass (" io/flutter/embedding/engine/FlutterJNI" );
Original file line number Diff line number Diff line change @@ -106,6 +106,13 @@ public static native void nativeInit(
106
106
@ NonNull String engineCachesPath ,
107
107
long initTimeMillis );
108
108
109
+ /**
110
+ * Create the default font manager provided by SkFontMgr::RefDefault() which is a process-wide
111
+ * singleton owned by Skia. Note that, the first call to SkFontMgr::RefDefault() will take
112
+ * noticeable time, but later calls will return a reference to the preexisting font manager.
113
+ */
114
+ public static native void nativeCreateDefaultFontManager ();
115
+
109
116
// TODO(mattcarroll): add javadocs
110
117
@ UiThread
111
118
public native boolean nativeGetIsSoftwareRenderingEnabled ();
Original file line number Diff line number Diff line change @@ -144,6 +144,17 @@ public InitResult call() {
144
144
145
145
System .loadLibrary ("flutter" );
146
146
147
+ // Pre-warm the default font manager as soon as possible on a background thread.
148
+ // It helps to reduce time cost of engine setup that blocks the platform thread.
149
+ new Thread (
150
+ new Runnable () {
151
+ @ Override
152
+ public void run () {
153
+ FlutterJNI .nativeCreateDefaultFontManager ();
154
+ }
155
+ })
156
+ .start ();
157
+
147
158
if (resourceExtractor != null ) {
148
159
resourceExtractor .waitForCompletion ();
149
160
}
You can’t perform that action at this time.
0 commit comments