From 2e2ddaed8fbb2d68e15fccfe607a0191ee8a65ef Mon Sep 17 00:00:00 2001 From: Kevin Lubick Date: Fri, 17 Nov 2023 16:02:41 +0000 Subject: [PATCH 1/4] Replace RefDefault with txt::GetDefaultFontFamilies --- impeller/typographer/BUILD.gn | 3 ++- impeller/typographer/typographer_unittests.cc | 3 ++- lib/web_ui/skwasm/BUILD.gn | 1 + lib/web_ui/skwasm/fonts.cpp | 3 ++- shell/platform/android/BUILD.gn | 1 + shell/platform/android/flutter_main.cc | 4 ++-- .../android/io/flutter/embedding/engine/FlutterJNI.java | 4 ++-- third_party/txt/src/txt/platform.h | 2 +- 8 files changed, 13 insertions(+), 8 deletions(-) diff --git a/impeller/typographer/BUILD.gn b/impeller/typographer/BUILD.gn index 32287b7d52f24..a65e976f625bc 100644 --- a/impeller/typographer/BUILD.gn +++ b/impeller/typographer/BUILD.gn @@ -34,7 +34,7 @@ impeller_component("typographer") { "../renderer", ] - deps = [ "//flutter/fml" ] + deps = [ "//flutter/fml"] } impeller_component("typographer_unittests") { @@ -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/BUILD.gn b/lib/web_ui/skwasm/BUILD.gn index 0abf32c992611..895bb753d0108 100644 --- a/lib/web_ui/skwasm/BUILD.gn +++ b/lib/web_ui/skwasm/BUILD.gn @@ -70,5 +70,6 @@ wasm_lib("skwasm") { deps = [ "//flutter/skia", "//flutter/skia/modules/skparagraph", + "//flutter/third_party/txt", ] } diff --git a/lib/web_ui/skwasm/fonts.cpp b/lib/web_ui/skwasm/fonts.cpp index 6209730032ed8..81270ad749e1e 100644 --- a/lib/web_ui/skwasm/fonts.cpp +++ b/lib/web_ui/skwasm/fonts.cpp @@ -6,6 +6,7 @@ #include "third_party/skia/include/core/SkFontMgr.h" #include "third_party/skia/modules/skparagraph/include/FontCollection.h" #include "third_party/skia/modules/skparagraph/include/TypefaceFontProvider.h" +#include "third_party/txt/platform.h" #include "wrappers.h" #include @@ -30,7 +31,7 @@ SKWASM_EXPORT void fontCollection_dispose(FlutterFontCollection* collection) { SKWASM_EXPORT SkTypeface* typeface_create(SkData* fontData) { auto typeface = - SkFontMgr::RefDefault()->makeFromData(sk_ref_sp(fontData)); + txt::GetDefaultFontManager()->makeFromData(sk_ref_sp(fontData)); return typeface.release(); } diff --git a/shell/platform/android/BUILD.gn b/shell/platform/android/BUILD.gn index 5d8458973481f..db09fd9cb3524 100644 --- a/shell/platform/android/BUILD.gn +++ b/shell/platform/android/BUILD.gn @@ -155,6 +155,7 @@ source_set("flutter_shell_native_src") { "//flutter/shell/platform/android/surface:native_window", "//flutter/skia", "//flutter/vulkan", + "//flutter/third_party/txt", ] public_configs = [ "//flutter:config" ] diff --git a/shell/platform/android/flutter_main.cc b/shell/platform/android/flutter_main.cc index 782b373c21d24..baf2c8f31616f 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 "third_party/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..09aaa6ca86dd5 100644 --- a/shell/platform/android/io/flutter/embedding/engine/FlutterJNI.java +++ b/shell/platform/android/io/flutter/embedding/engine/FlutterJNI.java @@ -151,8 +151,8 @@ 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 + * 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 From d174216571896fa866f6740ff987d30c5dd83352 Mon Sep 17 00:00:00 2001 From: Kevin Lubick Date: Fri, 17 Nov 2023 16:03:46 +0000 Subject: [PATCH 2/4] format --- impeller/typographer/BUILD.gn | 4 ++-- lib/web_ui/skwasm/BUILD.gn | 2 +- shell/platform/android/BUILD.gn | 2 +- .../android/io/flutter/embedding/engine/FlutterJNI.java | 7 ++++--- 4 files changed, 8 insertions(+), 7 deletions(-) diff --git a/impeller/typographer/BUILD.gn b/impeller/typographer/BUILD.gn index a65e976f625bc..67b19de6ccfd5 100644 --- a/impeller/typographer/BUILD.gn +++ b/impeller/typographer/BUILD.gn @@ -34,7 +34,7 @@ impeller_component("typographer") { "../renderer", ] - deps = [ "//flutter/fml"] + deps = [ "//flutter/fml" ] } impeller_component("typographer_unittests") { @@ -46,6 +46,6 @@ impeller_component("typographer_unittests") { "../playground:playground_test", "backends/skia:typographer_skia_backend", "backends/stb:typographer_stb_backend", - "//flutter/third_party/txt", + "//flutter/third_party/txt", ] } diff --git a/lib/web_ui/skwasm/BUILD.gn b/lib/web_ui/skwasm/BUILD.gn index 895bb753d0108..596a001b300d2 100644 --- a/lib/web_ui/skwasm/BUILD.gn +++ b/lib/web_ui/skwasm/BUILD.gn @@ -70,6 +70,6 @@ wasm_lib("skwasm") { deps = [ "//flutter/skia", "//flutter/skia/modules/skparagraph", - "//flutter/third_party/txt", + "//flutter/third_party/txt", ] } diff --git a/shell/platform/android/BUILD.gn b/shell/platform/android/BUILD.gn index db09fd9cb3524..0e440fd96d1bd 100644 --- a/shell/platform/android/BUILD.gn +++ b/shell/platform/android/BUILD.gn @@ -154,8 +154,8 @@ 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", - "//flutter/third_party/txt", ] public_configs = [ "//flutter:config" ] diff --git a/shell/platform/android/io/flutter/embedding/engine/FlutterJNI.java b/shell/platform/android/io/flutter/embedding/engine/FlutterJNI.java index 09aaa6ca86dd5..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 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. + * 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. */ From 700b7fafb95120f7ffb7934e49f570e1bdaeda8a Mon Sep 17 00:00:00 2001 From: Kevin Lubick Date: Fri, 17 Nov 2023 20:13:37 +0000 Subject: [PATCH 3/4] try fixes --- lib/web_ui/skwasm/BUILD.gn | 1 - shell/platform/android/flutter_main.cc | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/lib/web_ui/skwasm/BUILD.gn b/lib/web_ui/skwasm/BUILD.gn index 596a001b300d2..0abf32c992611 100644 --- a/lib/web_ui/skwasm/BUILD.gn +++ b/lib/web_ui/skwasm/BUILD.gn @@ -70,6 +70,5 @@ wasm_lib("skwasm") { deps = [ "//flutter/skia", "//flutter/skia/modules/skparagraph", - "//flutter/third_party/txt", ] } diff --git a/shell/platform/android/flutter_main.cc b/shell/platform/android/flutter_main.cc index baf2c8f31616f..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/txt/platform.h" +#include "txt/platform.h" namespace flutter { From 0fd658c0126905759397e29f7b975b2f89864b8f Mon Sep 17 00:00:00 2001 From: Kevin Lubick Date: Fri, 17 Nov 2023 21:49:12 +0000 Subject: [PATCH 4/4] re-implement in skwasm --- lib/web_ui/skwasm/fonts.cpp | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/lib/web_ui/skwasm/fonts.cpp b/lib/web_ui/skwasm/fonts.cpp index 81270ad749e1e..e8e3e4d5eab82 100644 --- a/lib/web_ui/skwasm/fonts.cpp +++ b/lib/web_ui/skwasm/fonts.cpp @@ -4,9 +4,9 @@ #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 "third_party/txt/platform.h" #include "wrappers.h" #include @@ -29,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 = - txt::GetDefaultFontManager()->makeFromData(sk_ref_sp(fontData)); + auto typeface = default_fontmgr()->makeFromData(sk_ref_sp(fontData)); return typeface.release(); }