Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit 81ffbc6

Browse files
authored
Replace calls to SkFontMgr::RefDefault (#48179)
Skia is removing this API, so clients must track a default FontMgr if they want one. See https://issues.skia.org/issues/305780908 ## Pre-launch Checklist - [x] I read the [Contributor Guide] and followed the process outlined there for submitting PRs. - [x] I read the [Tree Hygiene] wiki page, which explains my responsibilities. - [x] I read and followed the [Flutter Style Guide] and the [C++, Objective-C, Java style guides]. - [x] I listed at least one issue that this PR fixes in the description above. - [x] I added new tests to check the change I am making or feature I am adding, or the PR is [test-exempt]. See [testing the engine] for instructions on writing and running engine tests. - [x] I updated/added relevant documentation (doc comments with `///`). - [x] I signed the [CLA]. - [x] All existing and new tests are passing. If you need help, consider asking for advice on the #hackers-new channel on [Discord]. <!-- Links --> [Contributor Guide]: https://github.com/flutter/flutter/wiki/Tree-hygiene#overview [Tree Hygiene]: https://github.com/flutter/flutter/wiki/Tree-hygiene [test-exempt]: https://github.com/flutter/flutter/wiki/Tree-hygiene#tests [Flutter Style Guide]: https://github.com/flutter/flutter/wiki/Style-guide-for-Flutter-repo [C++, Objective-C, Java style guides]: https://github.com/flutter/engine/blob/main/CONTRIBUTING.md#style [testing the engine]: https://github.com/flutter/flutter/wiki/Testing-the-engine [CLA]: https://cla.developers.google.com/ [flutter/tests]: https://github.com/flutter/tests [breaking change policy]: https://github.com/flutter/flutter/wiki/Tree-hygiene#handling-breaking-changes [Discord]: https://github.com/flutter/flutter/wiki/Chat
1 parent a93f20d commit 81ffbc6

File tree

7 files changed

+18
-9
lines changed

7 files changed

+18
-9
lines changed

impeller/typographer/BUILD.gn

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,5 +46,6 @@ impeller_component("typographer_unittests") {
4646
"../playground:playground_test",
4747
"backends/skia:typographer_skia_backend",
4848
"backends/stb:typographer_stb_backend",
49+
"//flutter/third_party/txt",
4950
]
5051
}

impeller/typographer/typographer_unittests.cc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include "third_party/skia/include/core/SkFontMgr.h"
1313
#include "third_party/skia/include/core/SkRect.h"
1414
#include "third_party/skia/include/core/SkTextBlob.h"
15+
#include "txt/platform.h"
1516

1617
// TODO(zanderso): https://github.com/flutter/flutter/issues/127701
1718
// NOLINTBEGIN(bugprone-unchecked-optional-access)
@@ -275,7 +276,7 @@ TEST_P(TypographerTest, GlyphAtlasTextureIsRecreatedIfTypeChanges) {
275276
}
276277

277278
TEST_P(TypographerTest, MaybeHasOverlapping) {
278-
sk_sp<SkFontMgr> font_mgr = SkFontMgr::RefDefault();
279+
sk_sp<SkFontMgr> font_mgr = txt::GetDefaultFontManager();
279280
sk_sp<SkTypeface> typeface =
280281
font_mgr->matchFamilyStyle("Arial", SkFontStyle::Normal());
281282
SkFont sk_font(typeface, 0.5f);

lib/web_ui/skwasm/fonts.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
#include "export.h"
66
#include "third_party/skia/include/core/SkFontMgr.h"
7+
#include "third_party/skia/include/ports/SkFontMgr_empty.h"
78
#include "third_party/skia/modules/skparagraph/include/FontCollection.h"
89
#include "third_party/skia/modules/skparagraph/include/TypefaceFontProvider.h"
910
#include "wrappers.h"
@@ -28,9 +29,13 @@ SKWASM_EXPORT void fontCollection_dispose(FlutterFontCollection* collection) {
2829
delete collection;
2930
}
3031

32+
static sk_sp<SkFontMgr> default_fontmgr() {
33+
static sk_sp<SkFontMgr> mgr = SkFontMgr_New_Custom_Empty();
34+
return mgr;
35+
}
36+
3137
SKWASM_EXPORT SkTypeface* typeface_create(SkData* fontData) {
32-
auto typeface =
33-
SkFontMgr::RefDefault()->makeFromData(sk_ref_sp<SkData>(fontData));
38+
auto typeface = default_fontmgr()->makeFromData(sk_ref_sp<SkData>(fontData));
3439
return typeface.release();
3540
}
3641

shell/platform/android/BUILD.gn

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,7 @@ source_set("flutter_shell_native_src") {
155155
"//flutter/shell/platform/android/surface",
156156
"//flutter/shell/platform/android/surface:native_window",
157157
"//flutter/skia",
158+
"//flutter/third_party/txt",
158159
"//flutter/vulkan",
159160
]
160161

shell/platform/android/flutter_main.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
#include "flutter/shell/common/shell.h"
2626
#include "flutter/shell/common/switches.h"
2727
#include "third_party/dart/runtime/include/dart_tools_api.h"
28-
#include "third_party/skia/include/core/SkFontMgr.h"
28+
#include "txt/platform.h"
2929

3030
namespace flutter {
3131

@@ -198,7 +198,7 @@ void FlutterMain::SetupDartVMServiceUriCallback(JNIEnv* env) {
198198

199199
static void PrefetchDefaultFontManager(JNIEnv* env, jclass jcaller) {
200200
// Initialize a singleton owned by Skia.
201-
SkFontMgr::RefDefault();
201+
txt::GetDefaultFontManager();
202202
}
203203

204204
bool FlutterMain::Register(JNIEnv* env) {

shell/platform/android/io/flutter/embedding/engine/FlutterJNI.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -151,9 +151,10 @@ public void loadLibrary() {
151151
private static native void nativePrefetchDefaultFontManager();
152152

153153
/**
154-
* Prefetch the default font manager provided by SkFontMgr::RefDefault() which is a process-wide
155-
* singleton owned by Skia. Note that, the first call to SkFontMgr::RefDefault() will take
156-
* noticeable time, but later calls will return a reference to the preexisting font manager.
154+
* Prefetch the default font manager provided by txt::GetDefaultFontManager() which is a
155+
* process-wide singleton owned by Skia. Note that, the first call to txt::GetDefaultFontManager()
156+
* will take noticeable time, but later calls will return a reference to the preexisting font
157+
* manager.
157158
*
158159
* <p>This method should only be called once across all FlutterJNI instances.
159160
*/

third_party/txt/src/txt/platform.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ namespace txt {
1515

1616
std::vector<std::string> GetDefaultFontFamilies();
1717

18-
sk_sp<SkFontMgr> GetDefaultFontManager(uint32_t font_initialization_data);
18+
sk_sp<SkFontMgr> GetDefaultFontManager(uint32_t font_initialization_data = 0);
1919

2020
} // namespace txt
2121

0 commit comments

Comments
 (0)