From 9386034ac22c9916ca215a5d05f57a6e3850975e Mon Sep 17 00:00:00 2001 From: Kevin Lubick Date: Wed, 6 Dec 2023 13:02:34 -0500 Subject: [PATCH 1/2] Replace use of Fontmgr::RefDefault with explicit creation calls (#48571) In https://g-issues.skia.org/issues/305780908 Skia is removing the default SkFontMgr. Previous work consolidated all references to txt/platform.h and this replaces those last references. I attempted to mirror the existing functionality, which still responds to GN flags and the target platform. After this PR, Flutter should not be depending on the default fontmgr (and the defines in flutter_defines.gni) will maintain that behavior until the legacy functions/methods are deleted from Skia. There were a few tests that I missed on an earlier PR which relied on the default font (helper added in #47493). These tests were failing because they were making some assertions related to TextBlobs, which didn't work if the (now-empty) Typeface they loaded had no glyphs. Thus, I added a few extra asserts to make sure these textblobs *had* glyphs which make the failing tests less mysterious, should this issue crop up again. I cleaned up Flutter's BUILD.gn file for Skia a bit, deleting unused targets related to the font managers. This involved fixing an implicit dependency from //third_party/glfw/ to `Gdi32.lib` on Windows. ## 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. - [ ] 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]. [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 --- .../flutter/third_party/glfw/BUILD.gn | 2 + .../testing/dl_rendering_unittests.cc | 50 ++++---- flow/layers/performance_overlay_layer.cc | 9 +- impeller/entity/BUILD.gn | 1 + impeller/entity/entity_unittests.cc | 4 +- impeller/typographer/BUILD.gn | 1 + impeller/typographer/typographer_unittests.cc | 18 +-- shell/common/BUILD.gn | 2 + shell/common/dl_op_spy_unittests.cc | 6 +- shell/platform/fuchsia/flutter/BUILD.gn | 5 + skia/BUILD.gn | 108 +++--------------- skia/flutter_defines.gni | 6 + third_party/txt/src/txt/platform.cc | 11 +- third_party/txt/src/txt/platform_android.cc | 17 ++- third_party/txt/src/txt/platform_fuchsia.cc | 11 +- third_party/txt/src/txt/platform_linux.cc | 17 ++- third_party/txt/src/txt/platform_mac.mm | 4 +- 17 files changed, 132 insertions(+), 140 deletions(-) diff --git a/build/secondary/flutter/third_party/glfw/BUILD.gn b/build/secondary/flutter/third_party/glfw/BUILD.gn index 98c3fe43e7eda..cf6681051178a 100644 --- a/build/secondary/flutter/third_party/glfw/BUILD.gn +++ b/build/secondary/flutter/third_party/glfw/BUILD.gn @@ -55,6 +55,8 @@ source_set("glfw") { "$_checkout_dir/src/win32_window.c", ] + libs = [ "Gdi32.lib" ] + defines = [ "_GLFW_WIN32" ] } else if (is_linux) { sources += [ diff --git a/display_list/testing/dl_rendering_unittests.cc b/display_list/testing/dl_rendering_unittests.cc index e2b7707a20048..8e522643dc941 100644 --- a/display_list/testing/dl_rendering_unittests.cc +++ b/display_list/testing/dl_rendering_unittests.cc @@ -11,6 +11,7 @@ #include "flutter/display_list/skia/dl_sk_canvas.h" #include "flutter/display_list/skia/dl_sk_conversions.h" #include "flutter/display_list/skia/dl_sk_dispatcher.h" +#include "flutter/display_list/testing/dl_test_snippets.h" #include "flutter/display_list/testing/dl_test_surface_provider.h" #include "flutter/display_list/utils/dl_comparable.h" #include "flutter/fml/file.h" @@ -58,7 +59,7 @@ constexpr SkScalar kRenderRadius = std::min(kRenderWidth, kRenderHeight) / 2.0; constexpr SkScalar kRenderCornerRadius = kRenderRadius / 5.0; constexpr SkPoint kTestCenter = SkPoint::Make(kTestWidth / 2, kTestHeight / 2); -constexpr SkRect kTestBounds = SkRect::MakeWH(kTestWidth, kTestHeight); +constexpr SkRect kTestBounds2 = SkRect::MakeWH(kTestWidth, kTestHeight); constexpr SkRect kRenderBounds = SkRect::MakeLTRB(kRenderLeft, kRenderTop, kRenderRight, kRenderBottom); @@ -486,7 +487,7 @@ struct SkJobRenderer : public MatrixClipJobRenderer { sk_sp MakePicture(const RenderJobInfo& info) { SkPictureRecorder recorder; SkRTreeFactory rtree_factory; - SkCanvas* cv = recorder.beginRecording(kTestBounds, &rtree_factory); + SkCanvas* cv = recorder.beginRecording(kTestBounds2, &rtree_factory); Render(cv, info); return recorder.finishRecordingAsPicture(); } @@ -532,7 +533,7 @@ struct DlJobRenderer : public MatrixClipJobRenderer { } sk_sp MakeDisplayList(const RenderJobInfo& info) { - DisplayListBuilder builder(kTestBounds); + DisplayListBuilder builder(kTestBounds2); Render(&builder, info); return builder.Build(); } @@ -2750,9 +2751,10 @@ class CanvasCompareTester { static sk_sp MakeTextBlob(const std::string& string, SkScalar font_height) { - SkFont font(txt::GetDefaultFontManager()->matchFamilyStyle( - "ahem", SkFontStyle::Normal()), - font_height); + SkFont font = CreateTestFontOfSize(font_height); + sk_sp face = font.refTypeface(); + FML_CHECK(face); + FML_CHECK(face->countGlyphs() > 0) << "No glyphs in font"; return SkTextBlob::MakeFromText(string.c_str(), string.size(), font, SkTextEncoding::kUTF8); } @@ -3801,7 +3803,7 @@ TEST_F(DisplayListRendering, SaveLayerClippedContentStillFilters) { const SkRect draw_rect = SkRect::MakeLTRB( // kRenderRight + 1, // kRenderTop, // - kTestBounds.fRight, // + kTestBounds2.fRight, // kRenderBottom // ); TestParameters test_params( @@ -3812,7 +3814,7 @@ TEST_F(DisplayListRendering, SaveLayerClippedContentStillFilters) { layer_paint.setImageFilter(layer_filter); ctx.canvas->save(); ctx.canvas->clipRect(kRenderBounds, SkClipOp::kIntersect, false); - ctx.canvas->saveLayer(&kTestBounds, &layer_paint); + ctx.canvas->saveLayer(&kTestBounds2, &layer_paint); ctx.canvas->drawRect(draw_rect, ctx.paint); ctx.canvas->restore(); ctx.canvas->restore(); @@ -3824,7 +3826,7 @@ TEST_F(DisplayListRendering, SaveLayerClippedContentStillFilters) { layer_paint.setImageFilter(layer_filter); ctx.canvas->Save(); ctx.canvas->ClipRect(kRenderBounds, ClipOp::kIntersect, false); - ctx.canvas->SaveLayer(&kTestBounds, &layer_paint); + ctx.canvas->SaveLayer(&kTestBounds2, &layer_paint); ctx.canvas->DrawRect(draw_rect, ctx.paint); ctx.canvas->Restore(); ctx.canvas->Restore(); @@ -3906,19 +3908,19 @@ TEST_F(DisplayListRendering, SaveLayerConsolidation) { const std::string& desc1, const std::string& desc2, const RenderEnvironment* env) { DisplayListBuilder nested_builder; - nested_builder.SaveLayer(&kTestBounds, &paint1); - nested_builder.SaveLayer(&kTestBounds, &paint2); + nested_builder.SaveLayer(&kTestBounds2, &paint1); + nested_builder.SaveLayer(&kTestBounds2, &paint2); render_content(nested_builder); auto nested_results = env->getResult(nested_builder.Build()); DisplayListBuilder reverse_builder; - reverse_builder.SaveLayer(&kTestBounds, &paint2); - reverse_builder.SaveLayer(&kTestBounds, &paint1); + reverse_builder.SaveLayer(&kTestBounds2, &paint2); + reverse_builder.SaveLayer(&kTestBounds2, &paint1); render_content(reverse_builder); auto reverse_results = env->getResult(reverse_builder.Build()); DisplayListBuilder combined_builder; - combined_builder.SaveLayer(&kTestBounds, &paint_both); + combined_builder.SaveLayer(&kTestBounds2, &paint_both); render_content(combined_builder); auto combined_results = env->getResult(combined_builder.Build()); @@ -4056,7 +4058,7 @@ TEST_F(DisplayListRendering, MatrixColorFilterModifyTransparencyCheck) { builder2.Translate(kTestCenter.fX, kTestCenter.fY); builder2.Rotate(45); builder2.Translate(-kTestCenter.fX, -kTestCenter.fY); - builder2.SaveLayer(&kTestBounds, &filter_save_paint); + builder2.SaveLayer(&kTestBounds2, &filter_save_paint); builder2.DrawRect(kRenderBounds, paint); builder2.Restore(); auto display_list2 = builder2.Build(); @@ -4115,8 +4117,8 @@ TEST_F(DisplayListRendering, MatrixColorFilterOpacityCommuteCheck) { DlPaint filter_save_paint = DlPaint().setColorFilter(filter); DisplayListBuilder builder1; - builder1.SaveLayer(&kTestBounds, &opacity_save_paint); - builder1.SaveLayer(&kTestBounds, &filter_save_paint); + builder1.SaveLayer(&kTestBounds2, &opacity_save_paint); + builder1.SaveLayer(&kTestBounds2, &filter_save_paint); // builder1.DrawRect(kRenderBounds.makeOffset(20, 20), DlPaint()); builder1.DrawRect(kRenderBounds, paint); builder1.Restore(); @@ -4124,8 +4126,8 @@ TEST_F(DisplayListRendering, MatrixColorFilterOpacityCommuteCheck) { auto display_list1 = builder1.Build(); DisplayListBuilder builder2; - builder2.SaveLayer(&kTestBounds, &filter_save_paint); - builder2.SaveLayer(&kTestBounds, &opacity_save_paint); + builder2.SaveLayer(&kTestBounds2, &filter_save_paint); + builder2.SaveLayer(&kTestBounds2, &opacity_save_paint); // builder1.DrawRect(kRenderBounds.makeOffset(20, 20), DlPaint()); builder2.DrawRect(kRenderBounds, paint); builder2.Restore(); @@ -4232,7 +4234,7 @@ TEST_F(DisplayListRendering, BlendColorFilterModifyTransparencyCheck) { builder2.Translate(kTestCenter.fX, kTestCenter.fY); builder2.Rotate(45); builder2.Translate(-kTestCenter.fX, -kTestCenter.fY); - builder2.SaveLayer(&kTestBounds, &filter_save_paint); + builder2.SaveLayer(&kTestBounds2, &filter_save_paint); builder2.DrawRect(kRenderBounds, paint); builder2.Restore(); auto display_list2 = builder2.Build(); @@ -4284,8 +4286,8 @@ TEST_F(DisplayListRendering, BlendColorFilterOpacityCommuteCheck) { DlPaint filter_save_paint = DlPaint().setColorFilter(&filter); DisplayListBuilder builder1; - builder1.SaveLayer(&kTestBounds, &opacity_save_paint); - builder1.SaveLayer(&kTestBounds, &filter_save_paint); + builder1.SaveLayer(&kTestBounds2, &opacity_save_paint); + builder1.SaveLayer(&kTestBounds2, &filter_save_paint); // builder1.DrawRect(kRenderBounds.makeOffset(20, 20), DlPaint()); builder1.DrawRect(kRenderBounds, paint); builder1.Restore(); @@ -4293,8 +4295,8 @@ TEST_F(DisplayListRendering, BlendColorFilterOpacityCommuteCheck) { auto display_list1 = builder1.Build(); DisplayListBuilder builder2; - builder2.SaveLayer(&kTestBounds, &filter_save_paint); - builder2.SaveLayer(&kTestBounds, &opacity_save_paint); + builder2.SaveLayer(&kTestBounds2, &filter_save_paint); + builder2.SaveLayer(&kTestBounds2, &opacity_save_paint); // builder1.DrawRect(kRenderBounds.makeOffset(20, 20), DlPaint()); builder2.DrawRect(kRenderBounds, paint); builder2.Restore(); diff --git a/flow/layers/performance_overlay_layer.cc b/flow/layers/performance_overlay_layer.cc index e2bfd9e473f41..f88a77a433182 100644 --- a/flow/layers/performance_overlay_layer.cc +++ b/flow/layers/performance_overlay_layer.cc @@ -74,11 +74,12 @@ sk_sp PerformanceOverlayLayer::MakeStatisticsText( const std::string& label_prefix, const std::string& font_path) { SkFont font; - if (font_path != "") { - sk_sp font_mgr = txt::GetDefaultFontManager(); - font = SkFont(font_mgr->makeFromFile(font_path.c_str())); + sk_sp font_mgr = txt::GetDefaultFontManager(); + if (font_path == "") { + font = SkFont(font_mgr->matchFamilyStyle(nullptr, {}), 15); + } else { + font = SkFont(font_mgr->makeFromFile(font_path.c_str()), 15); } - font.setSize(15); double max_ms_per_frame = stopwatch.MaxDelta().ToMillisecondsF(); double average_ms_per_frame = stopwatch.AverageDelta().ToMillisecondsF(); diff --git a/impeller/entity/BUILD.gn b/impeller/entity/BUILD.gn index 24bc4670e94da..9d92ed95cc5ed 100644 --- a/impeller/entity/BUILD.gn +++ b/impeller/entity/BUILD.gn @@ -277,6 +277,7 @@ impeller_component("entity_unittests") { ":entity_test_helpers", "../geometry:geometry_asserts", "../playground:playground_test", + "//flutter/display_list/testing:display_list_testing", "//flutter/impeller/typographer/backends/skia:typographer_skia_backend", ] } diff --git a/impeller/entity/entity_unittests.cc b/impeller/entity/entity_unittests.cc index a067d3d455a8c..1607945b77e08 100644 --- a/impeller/entity/entity_unittests.cc +++ b/impeller/entity/entity_unittests.cc @@ -8,6 +8,7 @@ #include #include +#include "flutter/display_list/testing/dl_test_snippets.h" #include "fml/logging.h" #include "gtest/gtest.h" #include "impeller/core/formats.h" @@ -2192,8 +2193,7 @@ TEST_P(EntityTest, InheritOpacityTest) { // Text contents can accept opacity if the text frames do not // overlap - SkFont font; - font.setSize(30); + SkFont font = flutter::testing::CreateTestFontOfSize(30); auto blob = SkTextBlob::MakeFromString("A", font); auto frame = MakeTextFrameFromTextBlobSkia(blob); auto lazy_glyph_atlas = diff --git a/impeller/typographer/BUILD.gn b/impeller/typographer/BUILD.gn index 67b19de6ccfd5..90789a87a4582 100644 --- a/impeller/typographer/BUILD.gn +++ b/impeller/typographer/BUILD.gn @@ -46,6 +46,7 @@ impeller_component("typographer_unittests") { "../playground:playground_test", "backends/skia:typographer_skia_backend", "backends/stb:typographer_stb_backend", + "//flutter/display_list/testing:display_list_testing", "//flutter/third_party/txt", ] } diff --git a/impeller/typographer/typographer_unittests.cc b/impeller/typographer/typographer_unittests.cc index c1b2575e4478c..343c172b4121f 100644 --- a/impeller/typographer/typographer_unittests.cc +++ b/impeller/typographer/typographer_unittests.cc @@ -2,6 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +#include "flutter/display_list/testing/dl_test_snippets.h" #include "flutter/testing/testing.h" #include "impeller/playground/playground_test.h" #include "impeller/typographer/backends/skia/text_frame_skia.h" @@ -9,6 +10,7 @@ #include "impeller/typographer/lazy_glyph_atlas.h" #include "impeller/typographer/rectangle_packer.h" #include "third_party/skia/include/core/SkData.h" +#include "third_party/skia/include/core/SkFont.h" #include "third_party/skia/include/core/SkFontMgr.h" #include "third_party/skia/include/core/SkRect.h" #include "third_party/skia/include/core/SkTextBlob.h" @@ -38,7 +40,7 @@ static std::shared_ptr CreateGlyphAtlas( } TEST_P(TypographerTest, CanConvertTextBlob) { - SkFont font; + SkFont font = flutter::testing::CreateTestFontOfSize(12); auto blob = SkTextBlob::MakeFromString( "the quick brown fox jumped over the lazy dog.", font); ASSERT_TRUE(blob); @@ -59,7 +61,7 @@ TEST_P(TypographerTest, CanCreateGlyphAtlas) { auto context = TypographerContextSkia::Make(); auto atlas_context = context->CreateGlyphAtlasContext(); ASSERT_TRUE(context && context->IsValid()); - SkFont sk_font; + SkFont sk_font = flutter::testing::CreateTestFontOfSize(12); auto blob = SkTextBlob::MakeFromString("hello", sk_font); ASSERT_TRUE(blob); auto atlas = CreateGlyphAtlas( @@ -97,7 +99,7 @@ TEST_P(TypographerTest, LazyAtlasTracksColor) { ASSERT_TRUE(mapping); sk_sp font_mgr = txt::GetDefaultFontManager(); SkFont emoji_font(font_mgr->makeFromData(mapping), 50.0); - SkFont sk_font; + SkFont sk_font = flutter::testing::CreateTestFontOfSize(12); auto blob = SkTextBlob::MakeFromString("hello", sk_font); ASSERT_TRUE(blob); @@ -130,7 +132,7 @@ TEST_P(TypographerTest, GlyphAtlasWithOddUniqueGlyphSize) { auto context = TypographerContextSkia::Make(); auto atlas_context = context->CreateGlyphAtlasContext(); ASSERT_TRUE(context && context->IsValid()); - SkFont sk_font; + SkFont sk_font = flutter::testing::CreateTestFontOfSize(12); auto blob = SkTextBlob::MakeFromString("AGH", sk_font); ASSERT_TRUE(blob); auto atlas = CreateGlyphAtlas( @@ -147,7 +149,7 @@ TEST_P(TypographerTest, GlyphAtlasIsRecycledIfUnchanged) { auto context = TypographerContextSkia::Make(); auto atlas_context = context->CreateGlyphAtlasContext(); ASSERT_TRUE(context && context->IsValid()); - SkFont sk_font; + SkFont sk_font = flutter::testing::CreateTestFontOfSize(12); auto blob = SkTextBlob::MakeFromString("spooky skellingtons", sk_font); ASSERT_TRUE(blob); auto atlas = CreateGlyphAtlas( @@ -177,7 +179,7 @@ TEST_P(TypographerTest, GlyphAtlasWithLotsOfdUniqueGlyphSize) { "œ∑´®†¥¨ˆøπ““‘‘åß∂ƒ©˙∆˚¬…æ≈ç√∫˜µ≤≥≥≥≥÷¡™£¢∞§¶•ªº–≠⁄€‹›fifl‡°·‚—±Œ„´‰Á¨Ø∏”’/" "* Í˝ */¸˛Ç◊ı˜Â¯˘¿"; - SkFont sk_font; + SkFont sk_font = flutter::testing::CreateTestFontOfSize(12); auto blob = SkTextBlob::MakeFromString(test_string, sk_font); ASSERT_TRUE(blob); @@ -214,7 +216,7 @@ TEST_P(TypographerTest, GlyphAtlasTextureIsRecycledIfUnchanged) { auto context = TypographerContextSkia::Make(); auto atlas_context = context->CreateGlyphAtlasContext(); ASSERT_TRUE(context && context->IsValid()); - SkFont sk_font; + SkFont sk_font = flutter::testing::CreateTestFontOfSize(12); auto blob = SkTextBlob::MakeFromString("spooky 1", sk_font); ASSERT_TRUE(blob); auto atlas = CreateGlyphAtlas( @@ -247,7 +249,7 @@ TEST_P(TypographerTest, GlyphAtlasTextureIsRecreatedIfTypeChanges) { auto context = TypographerContextSkia::Make(); auto atlas_context = context->CreateGlyphAtlasContext(); ASSERT_TRUE(context && context->IsValid()); - SkFont sk_font; + SkFont sk_font = flutter::testing::CreateTestFontOfSize(12); auto blob = SkTextBlob::MakeFromString("spooky 1", sk_font); ASSERT_TRUE(blob); auto atlas = CreateGlyphAtlas( diff --git a/shell/common/BUILD.gn b/shell/common/BUILD.gn index cd49230765b55..6e3cff31b7b02 100644 --- a/shell/common/BUILD.gn +++ b/shell/common/BUILD.gn @@ -202,6 +202,7 @@ if (enable_unittests) { fixtures = [ "fixtures/shelltest_screenshot.png", "fixtures/hello_loop_2.gif", + "//flutter/third_party/txt/third_party/fonts/Roboto-Regular.ttf", ] } @@ -322,6 +323,7 @@ if (enable_unittests) { ":shell_unittests_fixtures", "//flutter/assets", "//flutter/common/graphics", + "//flutter/display_list/testing:display_list_testing", "//flutter/shell/common:base64", "//flutter/shell/profiling:profiling_unittests", "//flutter/shell/version", diff --git a/shell/common/dl_op_spy_unittests.cc b/shell/common/dl_op_spy_unittests.cc index 7aaac1cbe52a8..6aecb4b5dbf5e 100644 --- a/shell/common/dl_op_spy_unittests.cc +++ b/shell/common/dl_op_spy_unittests.cc @@ -4,9 +4,11 @@ #include "flutter/display_list/display_list.h" #include "flutter/display_list/dl_builder.h" +#include "flutter/display_list/testing/dl_test_snippets.h" #include "flutter/shell/common/dl_op_spy.h" #include "flutter/testing/testing.h" #include "third_party/skia/include/core/SkBitmap.h" +#include "third_party/skia/include/core/SkFont.h" #include "third_party/skia/include/core/SkRSXform.h" namespace flutter { @@ -545,7 +547,7 @@ TEST(DlOpSpy, DrawTextBlob) { DisplayListBuilder builder; DlPaint paint(DlColor::kBlack()); std::string string = "xx"; - SkFont font; + SkFont font = CreateTestFontOfSize(12); auto text_blob = SkTextBlob::MakeFromString(string.c_str(), font); builder.DrawTextBlob(text_blob, 1, 1, paint); sk_sp dl = builder.Build(); @@ -557,7 +559,7 @@ TEST(DlOpSpy, DrawTextBlob) { DisplayListBuilder builder; DlPaint paint(DlColor::kTransparent()); std::string string = "xx"; - SkFont font; + SkFont font = CreateTestFontOfSize(12); auto text_blob = SkTextBlob::MakeFromString(string.c_str(), font); builder.DrawTextBlob(text_blob, 1, 1, paint); sk_sp dl = builder.Build(); diff --git a/shell/platform/fuchsia/flutter/BUILD.gn b/shell/platform/fuchsia/flutter/BUILD.gn index a29a552ca2995..e6b9de7b2cc63 100644 --- a/shell/platform/fuchsia/flutter/BUILD.gn +++ b/shell/platform/fuchsia/flutter/BUILD.gn @@ -750,6 +750,11 @@ if (enable_unittests) { "$root_gen_dir/flutter/shell/common/assets/shelltest_screenshot.png" dest = "assets/shelltest_screenshot.png" }, + { + path = rebase_path( + "//flutter/third_party/txt/third_party/fonts/Roboto-Regular.ttf") + dest = "assets/Roboto-Regular.ttf" + }, ] libraries = vulkan_validation_libs diff --git a/skia/BUILD.gn b/skia/BUILD.gn index c67d24cffa535..d89ad1364f5af 100644 --- a/skia/BUILD.gn +++ b/skia/BUILD.gn @@ -208,17 +208,9 @@ template("optional") { } } -group("fontmgr_factory") { - public_deps = [ skia_fontmgr_factory ] -} - -optional("fontmgr_empty_factory") { - enabled = true - sources = [ "$_skia_root/src/ports/SkFontMgr_empty_factory.cpp" ] -} - optional("fontmgr_android") { enabled = skia_enable_fontmgr_android + public_defines = [ "SK_FONTMGR_ANDROID_AVAILABLE" ] deps = [ ":typeface_freetype", @@ -231,11 +223,6 @@ optional("fontmgr_android") { "$_skia_root/src/ports/SkFontMgr_android_parser.h", ] } -optional("fontmgr_android_factory") { - enabled = skia_enable_fontmgr_android - deps = [ ":fontmgr_android" ] - sources = [ "$_skia_root/src/ports/SkFontMgr_android_factory.cpp" ] -} optional("fontmgr_custom") { enabled = @@ -247,24 +234,9 @@ optional("fontmgr_custom") { sources = [ "$_skia_root/src/ports/SkFontMgr_custom.cpp" ] } -optional("fontmgr_custom_directory") { - enabled = skia_enable_fontmgr_custom_directory - - deps = [ - ":fontmgr_custom", - ":typeface_freetype", - ] - public = [ "$_skia_root/include/ports/SkFontMgr_directory.h" ] - sources = [ "$_skia_root/src/ports/SkFontMgr_custom_directory.cpp" ] -} -optional("fontmgr_custom_directory_factory") { - enabled = skia_enable_fontmgr_custom_directory - deps = [ ":fontmgr_custom_directory" ] - sources = [ "$_skia_root/src/ports/SkFontMgr_custom_directory_factory.cpp" ] -} - optional("fontmgr_custom_embedded") { enabled = skia_enable_fontmgr_custom_embedded + public_defines = [ "SK_FONTMGR_FREETYPE_EMBEDDED_AVAILABLE" ] deps = [ ":fontmgr_custom", @@ -272,14 +244,10 @@ optional("fontmgr_custom_embedded") { ] sources = [ "$_skia_root/src/ports/SkFontMgr_custom_embedded.cpp" ] } -optional("fontmgr_custom_embedded_factory") { - enabled = skia_enable_fontmgr_custom_embedded - deps = [ ":fontmgr_custom_embedded" ] - sources = [ "$_skia_root/src/ports/SkFontMgr_custom_embedded_factory.cpp" ] -} optional("fontmgr_custom_empty") { enabled = skia_enable_fontmgr_custom_empty + public_defines = [ "SK_FONTMGR_FREETYPE_EMPTY_AVAILABLE" ] deps = [ ":fontmgr_custom", @@ -288,14 +256,10 @@ optional("fontmgr_custom_empty") { public = [ "$_skia_root/include/ports/SkFontMgr_empty.h" ] sources = [ "$_skia_root/src/ports/SkFontMgr_custom_empty.cpp" ] } -optional("fontmgr_custom_empty_factory") { - enabled = skia_enable_fontmgr_custom_empty - deps = [ ":fontmgr_custom_empty" ] - sources = [ "$_skia_root/src/ports/SkFontMgr_custom_empty_factory.cpp" ] -} optional("fontmgr_fontconfig") { enabled = skia_enable_fontmgr_fontconfig + public_defines = [ "SK_FONTMGR_FONTCONFIG_AVAILABLE" ] # The public header includes fontconfig.h and uses FcConfig* public_deps = [ "//third_party:fontconfig" ] @@ -303,40 +267,10 @@ optional("fontmgr_fontconfig") { deps = [ ":typeface_freetype" ] sources = [ "$_skia_root/src/ports/SkFontMgr_fontconfig.cpp" ] } -optional("fontmgr_fontconfig_factory") { - enabled = skia_enable_fontmgr_fontconfig - deps = [ ":fontmgr_fontconfig" ] - sources = [ "$_skia_root/src/ports/SkFontMgr_fontconfig_factory.cpp" ] -} - -optional("fontmgr_FontConfigInterface") { - enabled = skia_enable_fontmgr_FontConfigInterface - - deps = [ - ":typeface_freetype", - "//third_party:fontconfig", - ] - public = [ - "$_skia_root/include/ports/SkFontConfigInterface.h", - "$_skia_root/include/ports/SkFontMgr_FontConfigInterface.h", - ] - sources = [ - "$_skia_root/src/ports/SkFontConfigInterface.cpp", - "$_skia_root/src/ports/SkFontConfigInterface_direct.cpp", - "$_skia_root/src/ports/SkFontConfigInterface_direct_factory.cpp", - "$_skia_root/src/ports/SkFontConfigTypeface.h", - "$_skia_root/src/ports/SkFontMgr_FontConfigInterface.cpp", - ] -} -optional("fontmgr_FontConfigInterface_factory") { - enabled = skia_enable_fontmgr_FontConfigInterface - deps = [ ":fontmgr_FontConfigInterface" ] - sources = - [ "$_skia_root/src/ports/SkFontMgr_FontConfigInterface_factory.cpp" ] -} optional("fontmgr_fuchsia") { enabled = skia_enable_fontmgr_fuchsia + public_defines = [ "SK_FONTMGR_FUCHSIA_AVAILABLE" ] deps = [] @@ -352,7 +286,10 @@ optional("fontmgr_fuchsia") { optional("fontmgr_mac_ct") { enabled = skia_use_fonthost_mac - public_defines = [ "SK_TYPEFACE_FACTORY_CORETEXT" ] + public_defines = [ + "SK_TYPEFACE_FACTORY_CORETEXT", + "SK_FONTMGR_CORETEXT_AVAILABLE", + ] public = [ "$_skia_root/include/ports/SkFontMgr_mac_ct.h", "$_skia_root/include/ports/SkTypeface_mac.h", @@ -384,16 +321,14 @@ optional("fontmgr_mac_ct") { ] } } -optional("fontmgr_mac_ct_factory") { - enabled = skia_use_fonthost_mac - deps = [ ":fontmgr_mac_ct" ] - sources = [ "$_skia_root/src/ports/SkFontMgr_mac_ct_factory.cpp" ] -} optional("fontmgr_win") { enabled = skia_enable_fontmgr_win - public_defines = [ "SK_TYPEFACE_FACTORY_DIRECTWRITE" ] + public_defines = [ + "SK_TYPEFACE_FACTORY_DIRECTWRITE", + "SK_FONTMGR_DIRECTWRITE_AVAILABLE", + ] public = [ "$_skia_root/include/ports/SkTypeface_win.h" ] sources = [ "$_skia_root/include/ports/SkFontMgr_indirect.h", @@ -422,19 +357,6 @@ optional("fontmgr_win") { } } } -optional("fontmgr_win_factory") { - enabled = skia_enable_fontmgr_win - deps = [ ":fontmgr_win" ] - sources = [ "$_skia_root/src/ports/SkFontMgr_win_dw_factory.cpp" ] -} - -optional("fontmgr_win_gdi") { - enabled = skia_enable_fontmgr_win_gdi - - public = [ "$_skia_root/include/ports/SkTypeface_win.h" ] - sources = [ "$_skia_root/src/ports/SkFontHost_win.cpp" ] - libs = [ "Gdi32.lib" ] -} optional("gpu_shared") { enabled = skia_enable_ganesh @@ -675,16 +597,13 @@ skia_component("skia") { check_includes = false public_deps = [ - ":fontmgr_FontConfigInterface", ":fontmgr_android", - ":fontmgr_custom_directory", ":fontmgr_custom_embedded", ":fontmgr_custom_empty", ":fontmgr_fontconfig", ":fontmgr_fuchsia", ":fontmgr_mac_ct", ":fontmgr_win", - ":fontmgr_win_gdi", ":gpu", ":jpeg_encode", ":png_encode", @@ -693,7 +612,6 @@ skia_component("skia") { ] deps = [ - ":fontmgr_factory", ":hsw", ":jpeg_decode", ":ndk_images", diff --git a/skia/flutter_defines.gni b/skia/flutter_defines.gni index 877a8503c5475..650046f712fdf 100644 --- a/skia/flutter_defines.gni +++ b/skia/flutter_defines.gni @@ -23,6 +23,12 @@ flutter_defines = [ # When running Metal, ensure that command buffers are scheduled before # returning from submit. "SK_METAL_WAIT_UNTIL_SCHEDULED", + + # Staging for b/305780908 + "SK_DEFAULT_TYPEFACE_IS_EMPTY", + "SK_DISABLE_LEGACY_DEFAULT_TYPEFACE", + "SK_DISABLE_LEGACY_FONTMGR_FACTORY", + "SK_DISABLE_LEGACY_FONTMGR_REFDEFAULT", ] if (!is_fuchsia) { diff --git a/third_party/txt/src/txt/platform.cc b/third_party/txt/src/txt/platform.cc index f1860efd7e9cf..1ab45ddc1da2c 100644 --- a/third_party/txt/src/txt/platform.cc +++ b/third_party/txt/src/txt/platform.cc @@ -4,6 +4,10 @@ #include "txt/platform.h" +#if defined(SK_FONTMGR_FREETYPE_EMPTY_AVAILABLE) +#include "third_party/skia/include/ports/SkFontMgr_empty.h" +#endif + namespace txt { std::vector GetDefaultFontFamilies() { @@ -11,7 +15,12 @@ std::vector GetDefaultFontFamilies() { } sk_sp GetDefaultFontManager(uint32_t font_initialization_data) { - return SkFontMgr::RefDefault(); +#if defined(SK_FONTMGR_FREETYPE_EMPTY_AVAILABLE) + static sk_sp mgr = SkFontMgr_New_Custom_Empty(); +#else + static sk_sp mgr = SkFontMgr::RefEmpty(); +#endif + return mgr; } } // namespace txt diff --git a/third_party/txt/src/txt/platform_android.cc b/third_party/txt/src/txt/platform_android.cc index 3af12dde3bf5f..19c07f0bf3341 100644 --- a/third_party/txt/src/txt/platform_android.cc +++ b/third_party/txt/src/txt/platform_android.cc @@ -4,6 +4,14 @@ #include "txt/platform.h" +#if defined(SK_FONTMGR_ANDROID_AVAILABLE) +#include "third_party/skia/include/ports/SkFontMgr_android.h" +#endif + +#if defined(SK_FONTMGR_FREETYPE_EMPTY_AVAILABLE) +#include "third_party/skia/include/ports/SkFontMgr_empty.h" +#endif + namespace txt { std::vector GetDefaultFontFamilies() { @@ -11,7 +19,14 @@ std::vector GetDefaultFontFamilies() { } sk_sp GetDefaultFontManager(uint32_t font_initialization_data) { - return SkFontMgr::RefDefault(); +#if defined(SK_FONTMGR_ANDROID_AVAILABLE) + static sk_sp mgr = SkFontMgr_New_Android(nullptr); +#elif defined(SK_FONTMGR_FREETYPE_EMPTY_AVAILABLE) + static sk_sp mgr = SkFontMgr_New_Custom_Empty(); +#else + static sk_sp mgr = SkFontMgr::RefEmpty(); +#endif + return mgr; } } // namespace txt diff --git a/third_party/txt/src/txt/platform_fuchsia.cc b/third_party/txt/src/txt/platform_fuchsia.cc index 85fd7849dbb2a..547ed6bedd466 100644 --- a/third_party/txt/src/txt/platform_fuchsia.cc +++ b/third_party/txt/src/txt/platform_fuchsia.cc @@ -7,6 +7,10 @@ #include "third_party/skia/include/ports/SkFontMgr_fuchsia.h" #include "txt/platform.h" +#if defined(SK_FONTMGR_FREETYPE_EMPTY_AVAILABLE) +#include "third_party/skia/include/ports/SkFontMgr_empty.h" +#endif + namespace txt { std::vector GetDefaultFontFamilies() { @@ -19,7 +23,12 @@ sk_sp GetDefaultFontManager(uint32_t font_initialization_data) { sync_font_provider.Bind(zx::channel(font_initialization_data)); return SkFontMgr_New_Fuchsia(std::move(sync_font_provider)); } else { - return SkFontMgr::RefDefault(); +#if defined(SK_FONTMGR_FREETYPE_EMPTY_AVAILABLE) + static sk_sp mgr = SkFontMgr_New_Custom_Empty(); +#else + static sk_sp mgr = SkFontMgr::RefEmpty(); +#endif + return mgr; } } diff --git a/third_party/txt/src/txt/platform_linux.cc b/third_party/txt/src/txt/platform_linux.cc index 072c6c15c91e5..7599fbb86f7fb 100644 --- a/third_party/txt/src/txt/platform_linux.cc +++ b/third_party/txt/src/txt/platform_linux.cc @@ -4,6 +4,14 @@ #include "txt/platform.h" +#if defined(SK_FONTMGR_FONTCONFIG_AVAILABLE) +#include "third_party/skia/include/ports/SkFontMgr_fontconfig.h" +#endif + +#if defined(SK_FONTMGR_FREETYPE_EMPTY_AVAILABLE) +#include "third_party/skia/include/ports/SkFontMgr_empty.h" +#endif + namespace txt { std::vector GetDefaultFontFamilies() { @@ -11,7 +19,14 @@ std::vector GetDefaultFontFamilies() { } sk_sp GetDefaultFontManager(uint32_t font_initialization_data) { - return SkFontMgr::RefDefault(); +#if defined(SK_FONTMGR_FONTCONFIG_AVAILABLE) + static sk_sp mgr = SkFontMgr_New_FontConfig(nullptr); +#elif defined(SK_FONTMGR_FREETYPE_EMPTY_AVAILABLE) + static sk_sp mgr = SkFontMgr_New_Custom_Empty(); +#else + static sk_sp mgr = SkFontMgr::RefEmpty(); +#endif + return mgr; } } // namespace txt diff --git a/third_party/txt/src/txt/platform_mac.mm b/third_party/txt/src/txt/platform_mac.mm index 3ab772ffb23e1..3a747d3304823 100644 --- a/third_party/txt/src/txt/platform_mac.mm +++ b/third_party/txt/src/txt/platform_mac.mm @@ -5,6 +5,7 @@ #include #include "flutter/fml/platform/darwin/platform_version.h" +#include "third_party/skia/include/ports/SkFontMgr_mac_ct.h" #include "third_party/skia/include/ports/SkTypeface_mac.h" #include "txt/platform.h" #include "txt/platform_mac.h" @@ -37,7 +38,8 @@ } sk_sp GetDefaultFontManager(uint32_t font_initialization_data) { - return SkFontMgr::RefDefault(); + static sk_sp mgr = SkFontMgr_New_CoreText(nullptr); + return mgr; } void RegisterSystemFonts(const DynamicFontManager& dynamic_font_manager) { From 573e3d3db8ccf3326ba01d9d920d989ded4616dc Mon Sep 17 00:00:00 2001 From: Jason Simmons Date: Thu, 7 Dec 2023 00:14:44 +0000 Subject: [PATCH 2/2] Use the directory-based SkFontMgr as a default font manager on Linux --- skia/BUILD.gn | 12 ++++++++++++ third_party/txt/src/txt/platform_linux.cc | 7 +++++++ 2 files changed, 19 insertions(+) diff --git a/skia/BUILD.gn b/skia/BUILD.gn index d89ad1364f5af..41f3f73763dde 100644 --- a/skia/BUILD.gn +++ b/skia/BUILD.gn @@ -234,6 +234,17 @@ optional("fontmgr_custom") { sources = [ "$_skia_root/src/ports/SkFontMgr_custom.cpp" ] } +optional("fontmgr_custom_directory") { + enabled = skia_enable_fontmgr_custom_directory + public_defines = [ "SK_FONTMGR_FREETYPE_DIRECTORY_AVAILABLE" ] + deps = [ + ":fontmgr_custom", + ":typeface_freetype", + ] + public = [ "$_skia_root/include/ports/SkFontMgr_directory.h" ] + sources = [ "$_skia_root/src/ports/SkFontMgr_custom_directory.cpp" ] +} + optional("fontmgr_custom_embedded") { enabled = skia_enable_fontmgr_custom_embedded public_defines = [ "SK_FONTMGR_FREETYPE_EMBEDDED_AVAILABLE" ] @@ -598,6 +609,7 @@ skia_component("skia") { public_deps = [ ":fontmgr_android", + ":fontmgr_custom_directory", ":fontmgr_custom_embedded", ":fontmgr_custom_empty", ":fontmgr_fontconfig", diff --git a/third_party/txt/src/txt/platform_linux.cc b/third_party/txt/src/txt/platform_linux.cc index 7599fbb86f7fb..e542d82e50477 100644 --- a/third_party/txt/src/txt/platform_linux.cc +++ b/third_party/txt/src/txt/platform_linux.cc @@ -8,6 +8,10 @@ #include "third_party/skia/include/ports/SkFontMgr_fontconfig.h" #endif +#if defined(SK_FONTMGR_FREETYPE_DIRECTORY_AVAILABLE) +#include "include/ports/SkFontMgr_directory.h" +#endif + #if defined(SK_FONTMGR_FREETYPE_EMPTY_AVAILABLE) #include "third_party/skia/include/ports/SkFontMgr_empty.h" #endif @@ -21,6 +25,9 @@ std::vector GetDefaultFontFamilies() { sk_sp GetDefaultFontManager(uint32_t font_initialization_data) { #if defined(SK_FONTMGR_FONTCONFIG_AVAILABLE) static sk_sp mgr = SkFontMgr_New_FontConfig(nullptr); +#elif defined(SK_FONTMGR_FREETYPE_DIRECTORY_AVAILABLE) + static sk_sp mgr = + SkFontMgr_New_Custom_Directory("/usr/share/fonts/"); #elif defined(SK_FONTMGR_FREETYPE_EMPTY_AVAILABLE) static sk_sp mgr = SkFontMgr_New_Custom_Empty(); #else