Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions impeller/typographer/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -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",
]
}
3 changes: 2 additions & 1 deletion impeller/typographer/typographer_unittests.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -275,7 +276,7 @@ TEST_P(TypographerTest, GlyphAtlasTextureIsRecreatedIfTypeChanges) {
}

TEST_P(TypographerTest, MaybeHasOverlapping) {
sk_sp<SkFontMgr> font_mgr = SkFontMgr::RefDefault();
sk_sp<SkFontMgr> font_mgr = txt::GetDefaultFontManager();
sk_sp<SkTypeface> typeface =
font_mgr->matchFamilyStyle("Arial", SkFontStyle::Normal());
SkFont sk_font(typeface, 0.5f);
Expand Down
9 changes: 7 additions & 2 deletions lib/web_ui/skwasm/fonts.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -28,9 +29,13 @@ SKWASM_EXPORT void fontCollection_dispose(FlutterFontCollection* collection) {
delete collection;
}

static sk_sp<SkFontMgr> default_fontmgr() {
static sk_sp<SkFontMgr> mgr = SkFontMgr_New_Custom_Empty();
return mgr;
}

SKWASM_EXPORT SkTypeface* typeface_create(SkData* fontData) {
auto typeface =
SkFontMgr::RefDefault()->makeFromData(sk_ref_sp<SkData>(fontData));
auto typeface = default_fontmgr()->makeFromData(sk_ref_sp<SkData>(fontData));
return typeface.release();
}

Expand Down
1 change: 1 addition & 0 deletions shell/platform/android/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -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",
]

Expand Down
4 changes: 2 additions & 2 deletions shell/platform/android/flutter_main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand Down Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
* <p>This method should only be called once across all FlutterJNI instances.
*/
Expand Down
2 changes: 1 addition & 1 deletion third_party/txt/src/txt/platform.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ namespace txt {

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

sk_sp<SkFontMgr> GetDefaultFontManager(uint32_t font_initialization_data);
sk_sp<SkFontMgr> GetDefaultFontManager(uint32_t font_initialization_data = 0);

} // namespace txt

Expand Down