mirror of
https://github.com/flutter/flutter.git
synced 2026-02-20 02:29:02 +08:00
Update DisplayList tests to explicitly select the Roboto font (flutter/engine#47493)
Skia is removing the API for constructing a default typeface (see https://issues.skia.org/issues/305780908) Fixes https://github.com/flutter/flutter/issues/137565
This commit is contained in:
parent
2abeacb556
commit
cd32fb6c82
@ -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",
|
||||
|
||||
@ -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);
|
||||
}
|
||||
|
||||
|
||||
@ -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());
|
||||
|
||||
@ -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...
|
||||
|
||||
@ -901,13 +901,21 @@ std::vector<DisplayListInvocationGroup> 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<DisplayListInvocationGroup> 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<SkTextBlob> GetTestTextBlob(int index) {
|
||||
static std::map<int, sk_sp<SkTextBlob>> 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<SkTextBlob> 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
|
||||
|
||||
@ -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<DisplayList> TestDisplayList1 =
|
||||
static sk_sp<DisplayList> TestDisplayList2 =
|
||||
MakeTestDisplayList(25, 25, SK_ColorBLUE);
|
||||
|
||||
static sk_sp<SkTextBlob> MakeTextBlob(std::string string) {
|
||||
return SkTextBlob::MakeFromText(string.c_str(), string.size(), SkFont(),
|
||||
SkTextEncoding::kUTF8);
|
||||
}
|
||||
static sk_sp<SkTextBlob> TestBlob1 = MakeTextBlob("TestBlob1");
|
||||
static sk_sp<SkTextBlob> TestBlob2 = MakeTextBlob("TestBlob2");
|
||||
SkFont CreateTestFontOfSize(SkScalar scalar);
|
||||
|
||||
sk_sp<SkTextBlob> GetTestTextBlob(int index);
|
||||
|
||||
struct DisplayListInvocation {
|
||||
unsigned int op_count_;
|
||||
|
||||
@ -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") {
|
||||
|
||||
@ -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"
|
||||
},
|
||||
]
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user