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

Commit 6d643cb

Browse files
Reland "Replace use of Fontmgr::RefDefault with explicit creation calls" (#48764)
Relands #48571 with a patch that uses the directory-based SkFontMgr as a default font manager on Linux
1 parent e0a6be9 commit 6d643cb

17 files changed

Lines changed: 140 additions & 129 deletions

File tree

build/secondary/flutter/third_party/glfw/BUILD.gn

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@ source_set("glfw") {
5555
"$_checkout_dir/src/win32_window.c",
5656
]
5757

58+
libs = [ "Gdi32.lib" ]
59+
5860
defines = [ "_GLFW_WIN32" ]
5961
} else if (is_linux) {
6062
sources += [

display_list/testing/dl_rendering_unittests.cc

Lines changed: 26 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include "flutter/display_list/skia/dl_sk_canvas.h"
1212
#include "flutter/display_list/skia/dl_sk_conversions.h"
1313
#include "flutter/display_list/skia/dl_sk_dispatcher.h"
14+
#include "flutter/display_list/testing/dl_test_snippets.h"
1415
#include "flutter/display_list/testing/dl_test_surface_provider.h"
1516
#include "flutter/display_list/utils/dl_comparable.h"
1617
#include "flutter/fml/file.h"
@@ -58,7 +59,7 @@ constexpr SkScalar kRenderRadius = std::min(kRenderWidth, kRenderHeight) / 2.0;
5859
constexpr SkScalar kRenderCornerRadius = kRenderRadius / 5.0;
5960

6061
constexpr SkPoint kTestCenter = SkPoint::Make(kTestWidth / 2, kTestHeight / 2);
61-
constexpr SkRect kTestBounds = SkRect::MakeWH(kTestWidth, kTestHeight);
62+
constexpr SkRect kTestBounds2 = SkRect::MakeWH(kTestWidth, kTestHeight);
6263
constexpr SkRect kRenderBounds =
6364
SkRect::MakeLTRB(kRenderLeft, kRenderTop, kRenderRight, kRenderBottom);
6465

@@ -486,7 +487,7 @@ struct SkJobRenderer : public MatrixClipJobRenderer {
486487
sk_sp<SkPicture> MakePicture(const RenderJobInfo& info) {
487488
SkPictureRecorder recorder;
488489
SkRTreeFactory rtree_factory;
489-
SkCanvas* cv = recorder.beginRecording(kTestBounds, &rtree_factory);
490+
SkCanvas* cv = recorder.beginRecording(kTestBounds2, &rtree_factory);
490491
Render(cv, info);
491492
return recorder.finishRecordingAsPicture();
492493
}
@@ -532,7 +533,7 @@ struct DlJobRenderer : public MatrixClipJobRenderer {
532533
}
533534

534535
sk_sp<DisplayList> MakeDisplayList(const RenderJobInfo& info) {
535-
DisplayListBuilder builder(kTestBounds);
536+
DisplayListBuilder builder(kTestBounds2);
536537
Render(&builder, info);
537538
return builder.Build();
538539
}
@@ -2750,9 +2751,10 @@ class CanvasCompareTester {
27502751

27512752
static sk_sp<SkTextBlob> MakeTextBlob(const std::string& string,
27522753
SkScalar font_height) {
2753-
SkFont font(txt::GetDefaultFontManager()->matchFamilyStyle(
2754-
"ahem", SkFontStyle::Normal()),
2755-
font_height);
2754+
SkFont font = CreateTestFontOfSize(font_height);
2755+
sk_sp<SkTypeface> face = font.refTypeface();
2756+
FML_CHECK(face);
2757+
FML_CHECK(face->countGlyphs() > 0) << "No glyphs in font";
27562758
return SkTextBlob::MakeFromText(string.c_str(), string.size(), font,
27572759
SkTextEncoding::kUTF8);
27582760
}
@@ -3801,7 +3803,7 @@ TEST_F(DisplayListRendering, SaveLayerClippedContentStillFilters) {
38013803
const SkRect draw_rect = SkRect::MakeLTRB( //
38023804
kRenderRight + 1, //
38033805
kRenderTop, //
3804-
kTestBounds.fRight, //
3806+
kTestBounds2.fRight, //
38053807
kRenderBottom //
38063808
);
38073809
TestParameters test_params(
@@ -3812,7 +3814,7 @@ TEST_F(DisplayListRendering, SaveLayerClippedContentStillFilters) {
38123814
layer_paint.setImageFilter(layer_filter);
38133815
ctx.canvas->save();
38143816
ctx.canvas->clipRect(kRenderBounds, SkClipOp::kIntersect, false);
3815-
ctx.canvas->saveLayer(&kTestBounds, &layer_paint);
3817+
ctx.canvas->saveLayer(&kTestBounds2, &layer_paint);
38163818
ctx.canvas->drawRect(draw_rect, ctx.paint);
38173819
ctx.canvas->restore();
38183820
ctx.canvas->restore();
@@ -3824,7 +3826,7 @@ TEST_F(DisplayListRendering, SaveLayerClippedContentStillFilters) {
38243826
layer_paint.setImageFilter(layer_filter);
38253827
ctx.canvas->Save();
38263828
ctx.canvas->ClipRect(kRenderBounds, ClipOp::kIntersect, false);
3827-
ctx.canvas->SaveLayer(&kTestBounds, &layer_paint);
3829+
ctx.canvas->SaveLayer(&kTestBounds2, &layer_paint);
38283830
ctx.canvas->DrawRect(draw_rect, ctx.paint);
38293831
ctx.canvas->Restore();
38303832
ctx.canvas->Restore();
@@ -3906,19 +3908,19 @@ TEST_F(DisplayListRendering, SaveLayerConsolidation) {
39063908
const std::string& desc1, const std::string& desc2,
39073909
const RenderEnvironment* env) {
39083910
DisplayListBuilder nested_builder;
3909-
nested_builder.SaveLayer(&kTestBounds, &paint1);
3910-
nested_builder.SaveLayer(&kTestBounds, &paint2);
3911+
nested_builder.SaveLayer(&kTestBounds2, &paint1);
3912+
nested_builder.SaveLayer(&kTestBounds2, &paint2);
39113913
render_content(nested_builder);
39123914
auto nested_results = env->getResult(nested_builder.Build());
39133915

39143916
DisplayListBuilder reverse_builder;
3915-
reverse_builder.SaveLayer(&kTestBounds, &paint2);
3916-
reverse_builder.SaveLayer(&kTestBounds, &paint1);
3917+
reverse_builder.SaveLayer(&kTestBounds2, &paint2);
3918+
reverse_builder.SaveLayer(&kTestBounds2, &paint1);
39173919
render_content(reverse_builder);
39183920
auto reverse_results = env->getResult(reverse_builder.Build());
39193921

39203922
DisplayListBuilder combined_builder;
3921-
combined_builder.SaveLayer(&kTestBounds, &paint_both);
3923+
combined_builder.SaveLayer(&kTestBounds2, &paint_both);
39223924
render_content(combined_builder);
39233925
auto combined_results = env->getResult(combined_builder.Build());
39243926

@@ -4056,7 +4058,7 @@ TEST_F(DisplayListRendering, MatrixColorFilterModifyTransparencyCheck) {
40564058
builder2.Translate(kTestCenter.fX, kTestCenter.fY);
40574059
builder2.Rotate(45);
40584060
builder2.Translate(-kTestCenter.fX, -kTestCenter.fY);
4059-
builder2.SaveLayer(&kTestBounds, &filter_save_paint);
4061+
builder2.SaveLayer(&kTestBounds2, &filter_save_paint);
40604062
builder2.DrawRect(kRenderBounds, paint);
40614063
builder2.Restore();
40624064
auto display_list2 = builder2.Build();
@@ -4115,17 +4117,17 @@ TEST_F(DisplayListRendering, MatrixColorFilterOpacityCommuteCheck) {
41154117
DlPaint filter_save_paint = DlPaint().setColorFilter(filter);
41164118

41174119
DisplayListBuilder builder1;
4118-
builder1.SaveLayer(&kTestBounds, &opacity_save_paint);
4119-
builder1.SaveLayer(&kTestBounds, &filter_save_paint);
4120+
builder1.SaveLayer(&kTestBounds2, &opacity_save_paint);
4121+
builder1.SaveLayer(&kTestBounds2, &filter_save_paint);
41204122
// builder1.DrawRect(kRenderBounds.makeOffset(20, 20), DlPaint());
41214123
builder1.DrawRect(kRenderBounds, paint);
41224124
builder1.Restore();
41234125
builder1.Restore();
41244126
auto display_list1 = builder1.Build();
41254127

41264128
DisplayListBuilder builder2;
4127-
builder2.SaveLayer(&kTestBounds, &filter_save_paint);
4128-
builder2.SaveLayer(&kTestBounds, &opacity_save_paint);
4129+
builder2.SaveLayer(&kTestBounds2, &filter_save_paint);
4130+
builder2.SaveLayer(&kTestBounds2, &opacity_save_paint);
41294131
// builder1.DrawRect(kRenderBounds.makeOffset(20, 20), DlPaint());
41304132
builder2.DrawRect(kRenderBounds, paint);
41314133
builder2.Restore();
@@ -4232,7 +4234,7 @@ TEST_F(DisplayListRendering, BlendColorFilterModifyTransparencyCheck) {
42324234
builder2.Translate(kTestCenter.fX, kTestCenter.fY);
42334235
builder2.Rotate(45);
42344236
builder2.Translate(-kTestCenter.fX, -kTestCenter.fY);
4235-
builder2.SaveLayer(&kTestBounds, &filter_save_paint);
4237+
builder2.SaveLayer(&kTestBounds2, &filter_save_paint);
42364238
builder2.DrawRect(kRenderBounds, paint);
42374239
builder2.Restore();
42384240
auto display_list2 = builder2.Build();
@@ -4284,17 +4286,17 @@ TEST_F(DisplayListRendering, BlendColorFilterOpacityCommuteCheck) {
42844286
DlPaint filter_save_paint = DlPaint().setColorFilter(&filter);
42854287

42864288
DisplayListBuilder builder1;
4287-
builder1.SaveLayer(&kTestBounds, &opacity_save_paint);
4288-
builder1.SaveLayer(&kTestBounds, &filter_save_paint);
4289+
builder1.SaveLayer(&kTestBounds2, &opacity_save_paint);
4290+
builder1.SaveLayer(&kTestBounds2, &filter_save_paint);
42894291
// builder1.DrawRect(kRenderBounds.makeOffset(20, 20), DlPaint());
42904292
builder1.DrawRect(kRenderBounds, paint);
42914293
builder1.Restore();
42924294
builder1.Restore();
42934295
auto display_list1 = builder1.Build();
42944296

42954297
DisplayListBuilder builder2;
4296-
builder2.SaveLayer(&kTestBounds, &filter_save_paint);
4297-
builder2.SaveLayer(&kTestBounds, &opacity_save_paint);
4298+
builder2.SaveLayer(&kTestBounds2, &filter_save_paint);
4299+
builder2.SaveLayer(&kTestBounds2, &opacity_save_paint);
42984300
// builder1.DrawRect(kRenderBounds.makeOffset(20, 20), DlPaint());
42994301
builder2.DrawRect(kRenderBounds, paint);
43004302
builder2.Restore();

flow/layers/performance_overlay_layer.cc

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,11 +74,12 @@ sk_sp<SkTextBlob> PerformanceOverlayLayer::MakeStatisticsText(
7474
const std::string& label_prefix,
7575
const std::string& font_path) {
7676
SkFont font;
77-
if (font_path != "") {
78-
sk_sp<SkFontMgr> font_mgr = txt::GetDefaultFontManager();
79-
font = SkFont(font_mgr->makeFromFile(font_path.c_str()));
77+
sk_sp<SkFontMgr> font_mgr = txt::GetDefaultFontManager();
78+
if (font_path == "") {
79+
font = SkFont(font_mgr->matchFamilyStyle(nullptr, {}), 15);
80+
} else {
81+
font = SkFont(font_mgr->makeFromFile(font_path.c_str()), 15);
8082
}
81-
font.setSize(15);
8283

8384
double max_ms_per_frame = stopwatch.MaxDelta().ToMillisecondsF();
8485
double average_ms_per_frame = stopwatch.AverageDelta().ToMillisecondsF();

impeller/entity/BUILD.gn

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,7 @@ impeller_component("entity_unittests") {
277277
":entity_test_helpers",
278278
"../geometry:geometry_asserts",
279279
"../playground:playground_test",
280+
"//flutter/display_list/testing:display_list_testing",
280281
"//flutter/impeller/typographer/backends/skia:typographer_skia_backend",
281282
]
282283
}

impeller/entity/entity_unittests.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#include <utility>
99
#include <vector>
1010

11+
#include "flutter/display_list/testing/dl_test_snippets.h"
1112
#include "fml/logging.h"
1213
#include "gtest/gtest.h"
1314
#include "impeller/core/formats.h"
@@ -2192,8 +2193,7 @@ TEST_P(EntityTest, InheritOpacityTest) {
21922193

21932194
// Text contents can accept opacity if the text frames do not
21942195
// overlap
2195-
SkFont font;
2196-
font.setSize(30);
2196+
SkFont font = flutter::testing::CreateTestFontOfSize(30);
21972197
auto blob = SkTextBlob::MakeFromString("A", font);
21982198
auto frame = MakeTextFrameFromTextBlobSkia(blob);
21992199
auto lazy_glyph_atlas =

impeller/typographer/BUILD.gn

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

impeller/typographer/typographer_unittests.cc

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,15 @@
22
// Use of this source code is governed by a BSD-style license that can be
33
// found in the LICENSE file.
44

5+
#include "flutter/display_list/testing/dl_test_snippets.h"
56
#include "flutter/testing/testing.h"
67
#include "impeller/playground/playground_test.h"
78
#include "impeller/typographer/backends/skia/text_frame_skia.h"
89
#include "impeller/typographer/backends/skia/typographer_context_skia.h"
910
#include "impeller/typographer/lazy_glyph_atlas.h"
1011
#include "impeller/typographer/rectangle_packer.h"
1112
#include "third_party/skia/include/core/SkData.h"
13+
#include "third_party/skia/include/core/SkFont.h"
1214
#include "third_party/skia/include/core/SkFontMgr.h"
1315
#include "third_party/skia/include/core/SkRect.h"
1416
#include "third_party/skia/include/core/SkTextBlob.h"
@@ -38,7 +40,7 @@ static std::shared_ptr<GlyphAtlas> CreateGlyphAtlas(
3840
}
3941

4042
TEST_P(TypographerTest, CanConvertTextBlob) {
41-
SkFont font;
43+
SkFont font = flutter::testing::CreateTestFontOfSize(12);
4244
auto blob = SkTextBlob::MakeFromString(
4345
"the quick brown fox jumped over the lazy dog.", font);
4446
ASSERT_TRUE(blob);
@@ -59,7 +61,7 @@ TEST_P(TypographerTest, CanCreateGlyphAtlas) {
5961
auto context = TypographerContextSkia::Make();
6062
auto atlas_context = context->CreateGlyphAtlasContext();
6163
ASSERT_TRUE(context && context->IsValid());
62-
SkFont sk_font;
64+
SkFont sk_font = flutter::testing::CreateTestFontOfSize(12);
6365
auto blob = SkTextBlob::MakeFromString("hello", sk_font);
6466
ASSERT_TRUE(blob);
6567
auto atlas = CreateGlyphAtlas(
@@ -97,7 +99,7 @@ TEST_P(TypographerTest, LazyAtlasTracksColor) {
9799
ASSERT_TRUE(mapping);
98100
sk_sp<SkFontMgr> font_mgr = txt::GetDefaultFontManager();
99101
SkFont emoji_font(font_mgr->makeFromData(mapping), 50.0);
100-
SkFont sk_font;
102+
SkFont sk_font = flutter::testing::CreateTestFontOfSize(12);
101103

102104
auto blob = SkTextBlob::MakeFromString("hello", sk_font);
103105
ASSERT_TRUE(blob);
@@ -130,7 +132,7 @@ TEST_P(TypographerTest, GlyphAtlasWithOddUniqueGlyphSize) {
130132
auto context = TypographerContextSkia::Make();
131133
auto atlas_context = context->CreateGlyphAtlasContext();
132134
ASSERT_TRUE(context && context->IsValid());
133-
SkFont sk_font;
135+
SkFont sk_font = flutter::testing::CreateTestFontOfSize(12);
134136
auto blob = SkTextBlob::MakeFromString("AGH", sk_font);
135137
ASSERT_TRUE(blob);
136138
auto atlas = CreateGlyphAtlas(
@@ -147,7 +149,7 @@ TEST_P(TypographerTest, GlyphAtlasIsRecycledIfUnchanged) {
147149
auto context = TypographerContextSkia::Make();
148150
auto atlas_context = context->CreateGlyphAtlasContext();
149151
ASSERT_TRUE(context && context->IsValid());
150-
SkFont sk_font;
152+
SkFont sk_font = flutter::testing::CreateTestFontOfSize(12);
151153
auto blob = SkTextBlob::MakeFromString("spooky skellingtons", sk_font);
152154
ASSERT_TRUE(blob);
153155
auto atlas = CreateGlyphAtlas(
@@ -177,7 +179,7 @@ TEST_P(TypographerTest, GlyphAtlasWithLotsOfdUniqueGlyphSize) {
177179
"œ∑´®†¥¨ˆøπ““‘‘åß∂ƒ©˙∆˚¬…æ≈ç√∫˜µ≤≥≥≥≥÷¡™£¢∞§¶•ªº–≠⁄€‹›fifl‡°·‚—±Œ„´‰Á¨Ø∏”’/"
178180
"* Í˝ */¸˛Ç◊ı˜Â¯˘¿";
179181

180-
SkFont sk_font;
182+
SkFont sk_font = flutter::testing::CreateTestFontOfSize(12);
181183
auto blob = SkTextBlob::MakeFromString(test_string, sk_font);
182184
ASSERT_TRUE(blob);
183185

@@ -214,7 +216,7 @@ TEST_P(TypographerTest, GlyphAtlasTextureIsRecycledIfUnchanged) {
214216
auto context = TypographerContextSkia::Make();
215217
auto atlas_context = context->CreateGlyphAtlasContext();
216218
ASSERT_TRUE(context && context->IsValid());
217-
SkFont sk_font;
219+
SkFont sk_font = flutter::testing::CreateTestFontOfSize(12);
218220
auto blob = SkTextBlob::MakeFromString("spooky 1", sk_font);
219221
ASSERT_TRUE(blob);
220222
auto atlas = CreateGlyphAtlas(
@@ -247,7 +249,7 @@ TEST_P(TypographerTest, GlyphAtlasTextureIsRecreatedIfTypeChanges) {
247249
auto context = TypographerContextSkia::Make();
248250
auto atlas_context = context->CreateGlyphAtlasContext();
249251
ASSERT_TRUE(context && context->IsValid());
250-
SkFont sk_font;
252+
SkFont sk_font = flutter::testing::CreateTestFontOfSize(12);
251253
auto blob = SkTextBlob::MakeFromString("spooky 1", sk_font);
252254
ASSERT_TRUE(blob);
253255
auto atlas = CreateGlyphAtlas(

shell/common/BUILD.gn

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,7 @@ if (enable_unittests) {
202202
fixtures = [
203203
"fixtures/shelltest_screenshot.png",
204204
"fixtures/hello_loop_2.gif",
205+
"//flutter/third_party/txt/third_party/fonts/Roboto-Regular.ttf",
205206
]
206207
}
207208

@@ -322,6 +323,7 @@ if (enable_unittests) {
322323
":shell_unittests_fixtures",
323324
"//flutter/assets",
324325
"//flutter/common/graphics",
326+
"//flutter/display_list/testing:display_list_testing",
325327
"//flutter/shell/common:base64",
326328
"//flutter/shell/profiling:profiling_unittests",
327329
"//flutter/shell/version",

shell/common/dl_op_spy_unittests.cc

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

55
#include "flutter/display_list/display_list.h"
66
#include "flutter/display_list/dl_builder.h"
7+
#include "flutter/display_list/testing/dl_test_snippets.h"
78
#include "flutter/shell/common/dl_op_spy.h"
89
#include "flutter/testing/testing.h"
910
#include "third_party/skia/include/core/SkBitmap.h"
11+
#include "third_party/skia/include/core/SkFont.h"
1012
#include "third_party/skia/include/core/SkRSXform.h"
1113

1214
namespace flutter {
@@ -545,7 +547,7 @@ TEST(DlOpSpy, DrawTextBlob) {
545547
DisplayListBuilder builder;
546548
DlPaint paint(DlColor::kBlack());
547549
std::string string = "xx";
548-
SkFont font;
550+
SkFont font = CreateTestFontOfSize(12);
549551
auto text_blob = SkTextBlob::MakeFromString(string.c_str(), font);
550552
builder.DrawTextBlob(text_blob, 1, 1, paint);
551553
sk_sp<DisplayList> dl = builder.Build();
@@ -557,7 +559,7 @@ TEST(DlOpSpy, DrawTextBlob) {
557559
DisplayListBuilder builder;
558560
DlPaint paint(DlColor::kTransparent());
559561
std::string string = "xx";
560-
SkFont font;
562+
SkFont font = CreateTestFontOfSize(12);
561563
auto text_blob = SkTextBlob::MakeFromString(string.c_str(), font);
562564
builder.DrawTextBlob(text_blob, 1, 1, paint);
563565
sk_sp<DisplayList> dl = builder.Build();

shell/platform/fuchsia/flutter/BUILD.gn

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -750,6 +750,11 @@ if (enable_unittests) {
750750
"$root_gen_dir/flutter/shell/common/assets/shelltest_screenshot.png"
751751
dest = "assets/shelltest_screenshot.png"
752752
},
753+
{
754+
path = rebase_path(
755+
"//flutter/third_party/txt/third_party/fonts/Roboto-Regular.ttf")
756+
dest = "assets/Roboto-Regular.ttf"
757+
},
753758
]
754759

755760
libraries = vulkan_validation_libs

0 commit comments

Comments
 (0)