Replace calls to SkFontMgr::RefDefault (flutter/engine#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
This commit is contained in:
@@ -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",
|
||||
]
|
||||
}
|
||||
|
||||
@@ -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<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);
|
||||
|
||||
@@ -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<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();
|
||||
}
|
||||
|
||||
|
||||
@@ -155,6 +155,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",
|
||||
]
|
||||
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -151,9 +151,10 @@ public class FlutterJNI {
|
||||
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.
|
||||
*/
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user