diff --git a/display_list/BUILD.gn b/display_list/BUILD.gn index 1ec13109d0d83..0f261510ed17b 100644 --- a/display_list/BUILD.gn +++ b/display_list/BUILD.gn @@ -96,11 +96,12 @@ source_set("display_list") { } } -if (enable_unittests) { - test_fixtures("display_list_fixtures") { - fixtures = [] - } +test_fixtures("display_list_fixtures") { + fixtures = + [ "//flutter/third_party/txt/third_party/fonts/Roboto-Regular.ttf" ] +} +if (enable_unittests) { executable("display_list_unittests") { testonly = true @@ -201,10 +202,6 @@ if (enable_unittests) { } } -fixtures_location("display_list_benchmarks_fixtures") { - assets_dir = "$target_gen_dir/" -} - source_set("display_list_benchmarks_source") { testonly = true @@ -215,10 +212,11 @@ source_set("display_list_benchmarks_source") { deps = [ ":display_list", - ":display_list_benchmarks_fixtures", + ":display_list_fixtures", "//flutter/benchmarking", "//flutter/common/graphics", "//flutter/display_list/testing:display_list_surface_provider", + "//flutter/display_list/testing:display_list_testing", "//flutter/fml", "//flutter/testing:skia", "//flutter/testing:testing_lib", diff --git a/display_list/benchmarking/dl_benchmarks.cc b/display_list/benchmarking/dl_benchmarks.cc index 2a03b60c7a8e9..bb973d8d1ba43 100644 --- a/display_list/benchmarking/dl_benchmarks.cc +++ b/display_list/benchmarking/dl_benchmarks.cc @@ -6,6 +6,7 @@ #include "flutter/display_list/dl_builder.h" #include "flutter/display_list/dl_op_flags.h" #include "flutter/display_list/skia/dl_sk_canvas.h" +#include "flutter/display_list/testing/dl_test_snippets.h" #include "third_party/skia/include/core/SkBitmap.h" #include "third_party/skia/include/core/SkImage.h" @@ -1203,7 +1204,7 @@ void BM_DrawTextBlob(benchmark::State& state, for (size_t i = 0; i < draw_calls; i++) { character[0] = 'A' + (i % 26); - auto blob = SkTextBlob::MakeFromString(character, SkFont()); + auto blob = SkTextBlob::MakeFromString(character, CreateTestFontOfSize(20)); builder.DrawTextBlob(blob, 50.0f, 50.0f, paint); } diff --git a/display_list/benchmarking/dl_complexity_unittests.cc b/display_list/benchmarking/dl_complexity_unittests.cc index df4fc68497336..3e86622a76591 100644 --- a/display_list/benchmarking/dl_complexity_unittests.cc +++ b/display_list/benchmarking/dl_complexity_unittests.cc @@ -306,7 +306,7 @@ TEST(DisplayListComplexity, DrawVertices) { TEST(DisplayListComplexity, DrawTextBlob) { auto text_blob = SkTextBlob::MakeFromString( - "The quick brown fox jumps over the lazy dog.", SkFont()); + "The quick brown fox jumps over the lazy dog.", CreateTestFontOfSize(20)); DisplayListBuilder builder; builder.DrawTextBlob(text_blob, 0.0f, 0.0f, DlPaint()); diff --git a/display_list/display_list_unittests.cc b/display_list/display_list_unittests.cc index 27dc400d46776..0738a7201b558 100644 --- a/display_list/display_list_unittests.cc +++ b/display_list/display_list_unittests.cc @@ -1114,7 +1114,7 @@ TEST_F(DisplayListTest, SingleOpsMightSupportGroupOpacityBlendMode) { static auto display_list = builder.Build(); RUN_TESTS2(receiver.drawDisplayList(display_list);, false); } - RUN_TESTS2(receiver.drawTextBlob(TestBlob1, 0, 0);, false); + RUN_TESTS2(receiver.drawTextBlob(GetTestTextBlob(1), 0, 0);, false); RUN_TESTS2( receiver.drawShadow(kTestPath1, DlColor(SK_ColorBLACK), 1.0, false, 1.0); , false); @@ -3145,7 +3145,7 @@ TEST_F(DisplayListTest, NopOperationsOmittedFromRecords) { builder.DrawAtlas(TestImage1, xforms, rects, nullptr, 2, DlBlendMode::kSrcOver, DlImageSampling::kLinear, nullptr, &paint); - builder.DrawTextBlob(TestBlob1, 10, 10, paint); + builder.DrawTextBlob(GetTestTextBlob(1), 10, 10, paint); // Dst mode eliminates most rendering ops except for // the following two, so we'll prune those manually... diff --git a/display_list/testing/dl_test_snippets.cc b/display_list/testing/dl_test_snippets.cc index 3cbd39362b016..91c1a0e3c02cf 100644 --- a/display_list/testing/dl_test_snippets.cc +++ b/display_list/testing/dl_test_snippets.cc @@ -901,13 +901,21 @@ std::vector CreateAllRenderingOps() { {"DrawTextBlob", { {1, 24, 1, 24, - [](DlOpReceiver& r) { r.drawTextBlob(TestBlob1, 10, 10); }}, + [](DlOpReceiver& r) { + r.drawTextBlob(GetTestTextBlob(1), 10, 10); + }}, {1, 24, 1, 24, - [](DlOpReceiver& r) { r.drawTextBlob(TestBlob1, 20, 10); }}, + [](DlOpReceiver& r) { + r.drawTextBlob(GetTestTextBlob(1), 20, 10); + }}, {1, 24, 1, 24, - [](DlOpReceiver& r) { r.drawTextBlob(TestBlob1, 10, 20); }}, + [](DlOpReceiver& r) { + r.drawTextBlob(GetTestTextBlob(1), 10, 20); + }}, {1, 24, 1, 24, - [](DlOpReceiver& r) { r.drawTextBlob(TestBlob2, 10, 10); }}, + [](DlOpReceiver& r) { + r.drawTextBlob(GetTestTextBlob(2), 10, 10); + }}, }}, // The -1 op counts below are to indicate to the framework not to test // SkCanvas conversion of these ops as it converts the operation into a @@ -966,5 +974,26 @@ std::vector CreateAllGroups() { return result; } +SkFont CreateTestFontOfSize(SkScalar scalar) { + static constexpr const char* kTestFontFixture = "Roboto-Regular.ttf"; + auto mapping = flutter::testing::OpenFixtureAsSkData(kTestFontFixture); + FML_CHECK(mapping); + return SkFont{SkTypeface::MakeFromData(mapping), scalar}; +} + +sk_sp GetTestTextBlob(int index) { + static std::map> text_blobs; + auto it = text_blobs.find(index); + if (it != text_blobs.end()) { + return it->second; + } + std::string text = "TestBlob" + std::to_string(index); + sk_sp blob = + SkTextBlob::MakeFromText(text.c_str(), text.size(), + CreateTestFontOfSize(20), SkTextEncoding::kUTF8); + text_blobs.insert(std::make_pair(index, blob)); + return blob; +} + } // namespace testing } // namespace flutter diff --git a/display_list/testing/dl_test_snippets.h b/display_list/testing/dl_test_snippets.h index 64f54362cae7d..64c5e278d17fa 100644 --- a/display_list/testing/dl_test_snippets.h +++ b/display_list/testing/dl_test_snippets.h @@ -7,6 +7,7 @@ #include "flutter/display_list/display_list.h" #include "flutter/display_list/dl_builder.h" +#include "flutter/testing/testing.h" #include "third_party/skia/include/core/SkCanvas.h" #include "third_party/skia/include/core/SkSurface.h" @@ -222,12 +223,9 @@ static sk_sp TestDisplayList1 = static sk_sp TestDisplayList2 = MakeTestDisplayList(25, 25, SK_ColorBLUE); -static sk_sp MakeTextBlob(std::string string) { - return SkTextBlob::MakeFromText(string.c_str(), string.size(), SkFont(), - SkTextEncoding::kUTF8); -} -static sk_sp TestBlob1 = MakeTextBlob("TestBlob1"); -static sk_sp TestBlob2 = MakeTextBlob("TestBlob2"); +SkFont CreateTestFontOfSize(SkScalar scalar); + +sk_sp GetTestTextBlob(int index); struct DisplayListInvocation { unsigned int op_count_; diff --git a/flow/BUILD.gn b/flow/BUILD.gn index 492126c2a3086..0e37feb299461 100644 --- a/flow/BUILD.gn +++ b/flow/BUILD.gn @@ -108,7 +108,8 @@ source_set("flow") { if (enable_unittests) { test_fixtures("flow_fixtures") { - fixtures = [] + fixtures = + [ "//flutter/third_party/txt/third_party/fonts/Roboto-Regular.ttf" ] } source_set("flow_testing") { diff --git a/shell/platform/fuchsia/flutter/BUILD.gn b/shell/platform/fuchsia/flutter/BUILD.gn index 09dad6f9c4c0f..a29a552ca2995 100644 --- a/shell/platform/fuchsia/flutter/BUILD.gn +++ b/shell/platform/fuchsia/flutter/BUILD.gn @@ -657,12 +657,28 @@ if (enable_unittests) { deps = [ "//flutter/display_list:display_list_unittests" ] binary = "display_list_unittests" + + resources = [ + { + path = rebase_path( + "//flutter/third_party/txt/third_party/fonts/Roboto-Regular.ttf") + dest = "assets/Roboto-Regular.ttf" + }, + ] } fuchsia_test_archive("display_list_render_tests") { deps = [ "//flutter/display_list:display_list_rendertests" ] binary = "display_list_rendertests" + + resources = [ + { + path = rebase_path( + "//flutter/third_party/txt/third_party/fonts/Roboto-Regular.ttf") + dest = "assets/Roboto-Regular.ttf" + }, + ] } fuchsia_test_archive("flow_tests") { @@ -686,6 +702,11 @@ if (enable_unittests) { "//flutter/testing/resources/performance_overlay_gold_120fps.png") dest = "flutter/testing/resources/performance_overlay_gold_120fps.png" }, + { + path = rebase_path( + "//flutter/third_party/txt/third_party/fonts/Roboto-Regular.ttf") + dest = "assets/Roboto-Regular.ttf" + }, ] }