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

Commit 7374822

Browse files
Update DisplayList tests to explicitly select the Roboto font (#47493)
Skia is removing the API for constructing a default typeface (see https://issues.skia.org/issues/305780908) Fixes flutter/flutter#137565
1 parent 4ba585b commit 7374822

8 files changed

Lines changed: 72 additions & 24 deletions

File tree

display_list/BUILD.gn

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -96,11 +96,12 @@ source_set("display_list") {
9696
}
9797
}
9898

99-
if (enable_unittests) {
100-
test_fixtures("display_list_fixtures") {
101-
fixtures = []
102-
}
99+
test_fixtures("display_list_fixtures") {
100+
fixtures =
101+
[ "//flutter/third_party/txt/third_party/fonts/Roboto-Regular.ttf" ]
102+
}
103103

104+
if (enable_unittests) {
104105
executable("display_list_unittests") {
105106
testonly = true
106107

@@ -201,10 +202,6 @@ if (enable_unittests) {
201202
}
202203
}
203204

204-
fixtures_location("display_list_benchmarks_fixtures") {
205-
assets_dir = "$target_gen_dir/"
206-
}
207-
208205
source_set("display_list_benchmarks_source") {
209206
testonly = true
210207

@@ -215,10 +212,11 @@ source_set("display_list_benchmarks_source") {
215212

216213
deps = [
217214
":display_list",
218-
":display_list_benchmarks_fixtures",
215+
":display_list_fixtures",
219216
"//flutter/benchmarking",
220217
"//flutter/common/graphics",
221218
"//flutter/display_list/testing:display_list_surface_provider",
219+
"//flutter/display_list/testing:display_list_testing",
222220
"//flutter/fml",
223221
"//flutter/testing:skia",
224222
"//flutter/testing:testing_lib",

display_list/benchmarking/dl_benchmarks.cc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#include "flutter/display_list/dl_builder.h"
77
#include "flutter/display_list/dl_op_flags.h"
88
#include "flutter/display_list/skia/dl_sk_canvas.h"
9+
#include "flutter/display_list/testing/dl_test_snippets.h"
910

1011
#include "third_party/skia/include/core/SkBitmap.h"
1112
#include "third_party/skia/include/core/SkImage.h"
@@ -1203,7 +1204,7 @@ void BM_DrawTextBlob(benchmark::State& state,
12031204

12041205
for (size_t i = 0; i < draw_calls; i++) {
12051206
character[0] = 'A' + (i % 26);
1206-
auto blob = SkTextBlob::MakeFromString(character, SkFont());
1207+
auto blob = SkTextBlob::MakeFromString(character, CreateTestFontOfSize(20));
12071208
builder.DrawTextBlob(blob, 50.0f, 50.0f, paint);
12081209
}
12091210

display_list/benchmarking/dl_complexity_unittests.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,7 @@ TEST(DisplayListComplexity, DrawVertices) {
306306

307307
TEST(DisplayListComplexity, DrawTextBlob) {
308308
auto text_blob = SkTextBlob::MakeFromString(
309-
"The quick brown fox jumps over the lazy dog.", SkFont());
309+
"The quick brown fox jumps over the lazy dog.", CreateTestFontOfSize(20));
310310

311311
DisplayListBuilder builder;
312312
builder.DrawTextBlob(text_blob, 0.0f, 0.0f, DlPaint());

display_list/display_list_unittests.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1114,7 +1114,7 @@ TEST_F(DisplayListTest, SingleOpsMightSupportGroupOpacityBlendMode) {
11141114
static auto display_list = builder.Build();
11151115
RUN_TESTS2(receiver.drawDisplayList(display_list);, false);
11161116
}
1117-
RUN_TESTS2(receiver.drawTextBlob(TestBlob1, 0, 0);, false);
1117+
RUN_TESTS2(receiver.drawTextBlob(GetTestTextBlob(1), 0, 0);, false);
11181118
RUN_TESTS2(
11191119
receiver.drawShadow(kTestPath1, DlColor(SK_ColorBLACK), 1.0, false, 1.0);
11201120
, false);
@@ -3145,7 +3145,7 @@ TEST_F(DisplayListTest, NopOperationsOmittedFromRecords) {
31453145
builder.DrawAtlas(TestImage1, xforms, rects, nullptr, 2,
31463146
DlBlendMode::kSrcOver, DlImageSampling::kLinear,
31473147
nullptr, &paint);
3148-
builder.DrawTextBlob(TestBlob1, 10, 10, paint);
3148+
builder.DrawTextBlob(GetTestTextBlob(1), 10, 10, paint);
31493149

31503150
// Dst mode eliminates most rendering ops except for
31513151
// the following two, so we'll prune those manually...

display_list/testing/dl_test_snippets.cc

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -901,13 +901,21 @@ std::vector<DisplayListInvocationGroup> CreateAllRenderingOps() {
901901
{"DrawTextBlob",
902902
{
903903
{1, 24, 1, 24,
904-
[](DlOpReceiver& r) { r.drawTextBlob(TestBlob1, 10, 10); }},
904+
[](DlOpReceiver& r) {
905+
r.drawTextBlob(GetTestTextBlob(1), 10, 10);
906+
}},
905907
{1, 24, 1, 24,
906-
[](DlOpReceiver& r) { r.drawTextBlob(TestBlob1, 20, 10); }},
908+
[](DlOpReceiver& r) {
909+
r.drawTextBlob(GetTestTextBlob(1), 20, 10);
910+
}},
907911
{1, 24, 1, 24,
908-
[](DlOpReceiver& r) { r.drawTextBlob(TestBlob1, 10, 20); }},
912+
[](DlOpReceiver& r) {
913+
r.drawTextBlob(GetTestTextBlob(1), 10, 20);
914+
}},
909915
{1, 24, 1, 24,
910-
[](DlOpReceiver& r) { r.drawTextBlob(TestBlob2, 10, 10); }},
916+
[](DlOpReceiver& r) {
917+
r.drawTextBlob(GetTestTextBlob(2), 10, 10);
918+
}},
911919
}},
912920
// The -1 op counts below are to indicate to the framework not to test
913921
// SkCanvas conversion of these ops as it converts the operation into a
@@ -966,5 +974,26 @@ std::vector<DisplayListInvocationGroup> CreateAllGroups() {
966974
return result;
967975
}
968976

977+
SkFont CreateTestFontOfSize(SkScalar scalar) {
978+
static constexpr const char* kTestFontFixture = "Roboto-Regular.ttf";
979+
auto mapping = flutter::testing::OpenFixtureAsSkData(kTestFontFixture);
980+
FML_CHECK(mapping);
981+
return SkFont{SkTypeface::MakeFromData(mapping), scalar};
982+
}
983+
984+
sk_sp<SkTextBlob> GetTestTextBlob(int index) {
985+
static std::map<int, sk_sp<SkTextBlob>> text_blobs;
986+
auto it = text_blobs.find(index);
987+
if (it != text_blobs.end()) {
988+
return it->second;
989+
}
990+
std::string text = "TestBlob" + std::to_string(index);
991+
sk_sp<SkTextBlob> blob =
992+
SkTextBlob::MakeFromText(text.c_str(), text.size(),
993+
CreateTestFontOfSize(20), SkTextEncoding::kUTF8);
994+
text_blobs.insert(std::make_pair(index, blob));
995+
return blob;
996+
}
997+
969998
} // namespace testing
970999
} // namespace flutter

display_list/testing/dl_test_snippets.h

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

88
#include "flutter/display_list/display_list.h"
99
#include "flutter/display_list/dl_builder.h"
10+
#include "flutter/testing/testing.h"
1011

1112
#include "third_party/skia/include/core/SkCanvas.h"
1213
#include "third_party/skia/include/core/SkSurface.h"
@@ -222,12 +223,9 @@ static sk_sp<DisplayList> TestDisplayList1 =
222223
static sk_sp<DisplayList> TestDisplayList2 =
223224
MakeTestDisplayList(25, 25, SK_ColorBLUE);
224225

225-
static sk_sp<SkTextBlob> MakeTextBlob(std::string string) {
226-
return SkTextBlob::MakeFromText(string.c_str(), string.size(), SkFont(),
227-
SkTextEncoding::kUTF8);
228-
}
229-
static sk_sp<SkTextBlob> TestBlob1 = MakeTextBlob("TestBlob1");
230-
static sk_sp<SkTextBlob> TestBlob2 = MakeTextBlob("TestBlob2");
226+
SkFont CreateTestFontOfSize(SkScalar scalar);
227+
228+
sk_sp<SkTextBlob> GetTestTextBlob(int index);
231229

232230
struct DisplayListInvocation {
233231
unsigned int op_count_;

flow/BUILD.gn

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,8 @@ source_set("flow") {
108108

109109
if (enable_unittests) {
110110
test_fixtures("flow_fixtures") {
111-
fixtures = []
111+
fixtures =
112+
[ "//flutter/third_party/txt/third_party/fonts/Roboto-Regular.ttf" ]
112113
}
113114

114115
source_set("flow_testing") {

shell/platform/fuchsia/flutter/BUILD.gn

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -657,12 +657,28 @@ if (enable_unittests) {
657657
deps = [ "//flutter/display_list:display_list_unittests" ]
658658

659659
binary = "display_list_unittests"
660+
661+
resources = [
662+
{
663+
path = rebase_path(
664+
"//flutter/third_party/txt/third_party/fonts/Roboto-Regular.ttf")
665+
dest = "assets/Roboto-Regular.ttf"
666+
},
667+
]
660668
}
661669

662670
fuchsia_test_archive("display_list_render_tests") {
663671
deps = [ "//flutter/display_list:display_list_rendertests" ]
664672

665673
binary = "display_list_rendertests"
674+
675+
resources = [
676+
{
677+
path = rebase_path(
678+
"//flutter/third_party/txt/third_party/fonts/Roboto-Regular.ttf")
679+
dest = "assets/Roboto-Regular.ttf"
680+
},
681+
]
666682
}
667683

668684
fuchsia_test_archive("flow_tests") {
@@ -686,6 +702,11 @@ if (enable_unittests) {
686702
"//flutter/testing/resources/performance_overlay_gold_120fps.png")
687703
dest = "flutter/testing/resources/performance_overlay_gold_120fps.png"
688704
},
705+
{
706+
path = rebase_path(
707+
"//flutter/third_party/txt/third_party/fonts/Roboto-Regular.ttf")
708+
dest = "assets/Roboto-Regular.ttf"
709+
},
689710
]
690711
}
691712

0 commit comments

Comments
 (0)