diff --git a/impeller/typographer/BUILD.gn b/impeller/typographer/BUILD.gn index 32287b7d52f24..67b19de6ccfd5 100644 --- a/impeller/typographer/BUILD.gn +++ b/impeller/typographer/BUILD.gn @@ -46,5 +46,6 @@ impeller_component("typographer_unittests") { "../playground:playground_test", "backends/skia:typographer_skia_backend", "backends/stb:typographer_stb_backend", + "//flutter/third_party/txt", ] } diff --git a/impeller/typographer/typographer_unittests.cc b/impeller/typographer/typographer_unittests.cc index 6488783dd488a..f8fa84eb8fc91 100644 --- a/impeller/typographer/typographer_unittests.cc +++ b/impeller/typographer/typographer_unittests.cc @@ -12,6 +12,7 @@ #include "third_party/skia/include/core/SkFontMgr.h" #include "third_party/skia/include/core/SkRect.h" #include "third_party/skia/include/core/SkTextBlob.h" +#include "txt/platform.h" // TODO(zanderso): https://github.com/flutter/flutter/issues/127701 // NOLINTBEGIN(bugprone-unchecked-optional-access) @@ -275,7 +276,7 @@ TEST_P(TypographerTest, GlyphAtlasTextureIsRecreatedIfTypeChanges) { } TEST_P(TypographerTest, MaybeHasOverlapping) { - sk_sp font_mgr = SkFontMgr::RefDefault(); + sk_sp font_mgr = txt::GetDefaultFontManager(); sk_sp typeface = font_mgr->matchFamilyStyle("Arial", SkFontStyle::Normal()); SkFont sk_font(typeface, 0.5f); diff --git a/lib/web_ui/skwasm/fonts.cpp b/lib/web_ui/skwasm/fonts.cpp index 6209730032ed8..e8e3e4d5eab82 100644 --- a/lib/web_ui/skwasm/fonts.cpp +++ b/lib/web_ui/skwasm/fonts.cpp @@ -4,6 +4,7 @@ #include "export.h" #include "third_party/skia/include/core/SkFontMgr.h" +#include "third_party/skia/include/ports/SkFontMgr_empty.h" #include "third_party/skia/modules/skparagraph/include/FontCollection.h" #include "third_party/skia/modules/skparagraph/include/TypefaceFontProvider.h" #include "wrappers.h" @@ -28,9 +29,13 @@ SKWASM_EXPORT void fontCollection_dispose(FlutterFontCollection* collection) { delete collection; } +static sk_sp default_fontmgr() { + static sk_sp mgr = SkFontMgr_New_Custom_Empty(); + return mgr; +} + SKWASM_EXPORT SkTypeface* typeface_create(SkData* fontData) { - auto typeface = - SkFontMgr::RefDefault()->makeFromData(sk_ref_sp(fontData)); + auto typeface = default_fontmgr()->makeFromData(sk_ref_sp(fontData)); return typeface.release(); } diff --git a/shell/platform/android/BUILD.gn b/shell/platform/android/BUILD.gn index 5d8458973481f..0e440fd96d1bd 100644 --- a/shell/platform/android/BUILD.gn +++ b/shell/platform/android/BUILD.gn @@ -154,6 +154,7 @@ source_set("flutter_shell_native_src") { "//flutter/shell/platform/android/surface", "//flutter/shell/platform/android/surface:native_window", "//flutter/skia", + "//flutter/third_party/txt", "//flutter/vulkan", ] diff --git a/shell/platform/android/flutter_main.cc b/shell/platform/android/flutter_main.cc index 782b373c21d24..8b49f7e40b8a6 100644 --- a/shell/platform/android/flutter_main.cc +++ b/shell/platform/android/flutter_main.cc @@ -25,7 +25,7 @@ #include "flutter/shell/common/shell.h" #include "flutter/shell/common/switches.h" #include "third_party/dart/runtime/include/dart_tools_api.h" -#include "third_party/skia/include/core/SkFontMgr.h" +#include "txt/platform.h" namespace flutter { @@ -198,7 +198,7 @@ void FlutterMain::SetupDartVMServiceUriCallback(JNIEnv* env) { static void PrefetchDefaultFontManager(JNIEnv* env, jclass jcaller) { // Initialize a singleton owned by Skia. - SkFontMgr::RefDefault(); + txt::GetDefaultFontManager(); } bool FlutterMain::Register(JNIEnv* env) { diff --git a/shell/platform/android/io/flutter/embedding/engine/FlutterJNI.java b/shell/platform/android/io/flutter/embedding/engine/FlutterJNI.java index e4337e97b637d..0da57b73aa2dc 100644 --- a/shell/platform/android/io/flutter/embedding/engine/FlutterJNI.java +++ b/shell/platform/android/io/flutter/embedding/engine/FlutterJNI.java @@ -151,9 +151,10 @@ public void loadLibrary() { private static native void nativePrefetchDefaultFontManager(); /** - * Prefetch the default font manager provided by SkFontMgr::RefDefault() which is a process-wide - * singleton owned by Skia. Note that, the first call to SkFontMgr::RefDefault() will take - * noticeable time, but later calls will return a reference to the preexisting font manager. + * Prefetch the default font manager provided by txt::GetDefaultFontManager() which is a + * process-wide singleton owned by Skia. Note that, the first call to txt::GetDefaultFontManager() + * will take noticeable time, but later calls will return a reference to the preexisting font + * manager. * *

This method should only be called once across all FlutterJNI instances. */ diff --git a/third_party/txt/src/txt/platform.h b/third_party/txt/src/txt/platform.h index 7c29e1900121d..7ce2dd2e1c40e 100644 --- a/third_party/txt/src/txt/platform.h +++ b/third_party/txt/src/txt/platform.h @@ -15,7 +15,7 @@ namespace txt { std::vector GetDefaultFontFamilies(); -sk_sp GetDefaultFontManager(uint32_t font_initialization_data); +sk_sp GetDefaultFontManager(uint32_t font_initialization_data = 0); } // namespace txt