Skip to content

Commit a24dbd5

Browse files
Refactor text and runtime effect to separate skia and impeller implementations. (flutter#174219)
This makes two refactors to the display list architecture: * The concrete implementations of `DlRuntimeEffect` for skia and impeller are separated, and the impeller implementation put into the `impeller/display_list` target. This makes sure that a client can link against the main `display_list` library without actually pulling in all of impeller. (This is needed for flutter#172314) * The `DrawTextBlob` and `DrawTextFrame` methods are consolidated into one `DrawText` call, and that takes a `DlText` object. The `DlText` object has two implementations, one for skia and one for impeller, and the impeller one is moved into `impeller/display_list` for the same reason mentioned above.
1 parent 62ea199 commit a24dbd5

76 files changed

Lines changed: 820 additions & 564 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

engine/src/flutter/display_list/BUILD.gn

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,10 @@ source_set("display_list") {
6262
"dl_sampling_options.h",
6363
"dl_storage.cc",
6464
"dl_storage.h",
65+
"dl_text.cc",
66+
"dl_text.h",
67+
"dl_text_skia.cc",
68+
"dl_text_skia.h",
6569
"dl_tile_mode.h",
6670
"dl_types.cc",
6771
"dl_types.h",
@@ -100,6 +104,8 @@ source_set("display_list") {
100104
"effects/dl_mask_filter.h",
101105
"effects/dl_runtime_effect.cc",
102106
"effects/dl_runtime_effect.h",
107+
"effects/dl_runtime_effect_skia.cc",
108+
"effects/dl_runtime_effect_skia.h",
103109
"effects/image_filters/dl_blur_image_filter.cc",
104110
"effects/image_filters/dl_blur_image_filter.h",
105111
"effects/image_filters/dl_color_filter_image_filter.cc",
@@ -146,8 +152,6 @@ source_set("display_list") {
146152
public_deps = [
147153
":dl_path",
148154
"//flutter/fml",
149-
"//flutter/impeller/runtime_stage",
150-
"//flutter/impeller/typographer",
151155
"//flutter/skia",
152156
]
153157

engine/src/flutter/display_list/benchmarking/dl_benchmarks.cc

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#include "flutter/display_list/benchmarking/dl_benchmarks.h"
66
#include "flutter/display_list/dl_builder.h"
77
#include "flutter/display_list/dl_op_flags.h"
8+
#include "flutter/display_list/dl_text_skia.h"
89
#include "flutter/display_list/geometry/dl_path_builder.h"
910
#include "flutter/display_list/skia/dl_sk_canvas.h"
1011
#include "flutter/display_list/testing/dl_test_snippets.h"
@@ -1224,7 +1225,7 @@ void BM_DrawTextBlob(benchmark::State& state,
12241225
DisplayListBuilder builder;
12251226
DlPaint paint = GetPaintForRun(attributes);
12261227

1227-
AnnotateAttributes(attributes, state, DisplayListOpFlags::kDrawTextBlobFlags);
1228+
AnnotateAttributes(attributes, state, DisplayListOpFlags::kDrawTextFlags);
12281229

12291230
size_t draw_calls = state.range(0);
12301231
size_t canvas_size = kFixedCanvasSize;
@@ -1240,7 +1241,7 @@ void BM_DrawTextBlob(benchmark::State& state,
12401241
for (size_t i = 0; i < draw_calls; i++) {
12411242
character[0] = 'A' + (i % 26);
12421243
auto blob = SkTextBlob::MakeFromString(character, CreateTestFontOfSize(20));
1243-
builder.DrawTextBlob(blob, 50.0f, 50.0f, paint);
1244+
builder.DrawText(DlTextSkia::Make(blob), 50.0f, 50.0f, paint);
12441245
}
12451246

12461247
auto display_list = builder.Build();

engine/src/flutter/display_list/benchmarking/dl_complexity_gl.cc

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,12 @@ unsigned int DisplayListGLComplexityCalculator::GLHelper::BatchedComplexity() {
3737
}
3838

3939
unsigned int draw_text_blob_complexity;
40-
if (draw_text_blob_count_ == 0) {
40+
if (draw_text_count_ == 0) {
4141
draw_text_blob_complexity = 0;
4242
} else {
4343
// m = 1/240
4444
// c = 0.25
45-
draw_text_blob_complexity = (draw_text_blob_count_ + 60) * 2500 / 3;
45+
draw_text_blob_complexity = (draw_text_count_ + 60) * 2500 / 3;
4646
}
4747

4848
return save_layer_complexity + draw_text_blob_complexity;
@@ -643,8 +643,8 @@ void DisplayListGLComplexityCalculator::GLHelper::drawDisplayList(
643643
AccumulateComplexity(helper.ComplexityScore());
644644
}
645645

646-
void DisplayListGLComplexityCalculator::GLHelper::drawTextBlob(
647-
const sk_sp<SkTextBlob> blob,
646+
void DisplayListGLComplexityCalculator::GLHelper::drawText(
647+
const std::shared_ptr<DlText>& text,
648648
DlScalar x,
649649
DlScalar y) {
650650
if (IsComplex()) {
@@ -655,15 +655,10 @@ void DisplayListGLComplexityCalculator::GLHelper::drawTextBlob(
655655
// per frame, that fixed cost is greatly reduced per subsequent call. This
656656
// is likely because there is batching being done in SkCanvas.
657657

658-
// Increment draw_text_blob_count_ and calculate the cost at the end.
659-
draw_text_blob_count_++;
658+
// Increment draw_text_count_ and calculate the cost at the end.
659+
draw_text_count_++;
660660
}
661661

662-
void DisplayListGLComplexityCalculator::GLHelper::drawTextFrame(
663-
const std::shared_ptr<impeller::TextFrame>& text_frame,
664-
DlScalar x,
665-
DlScalar y) {}
666-
667662
void DisplayListGLComplexityCalculator::GLHelper::drawShadow(
668663
const DlPath& path,
669664
const DlColor color,

engine/src/flutter/display_list/benchmarking/dl_complexity_gl.h

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -73,12 +73,9 @@ class DisplayListGLComplexityCalculator
7373
bool render_with_attributes) override;
7474
void drawDisplayList(const sk_sp<DisplayList> display_list,
7575
DlScalar opacity) override;
76-
void drawTextBlob(const sk_sp<SkTextBlob> blob,
77-
DlScalar x,
78-
DlScalar y) override;
79-
void drawTextFrame(const std::shared_ptr<impeller::TextFrame>& text_frame,
80-
DlScalar x,
81-
DlScalar y) override;
76+
void drawText(const std::shared_ptr<DlText>& text,
77+
DlScalar x,
78+
DlScalar y) override;
8279
void drawShadow(const DlPath& path,
8380
const DlColor color,
8481
const DlScalar elevation,
@@ -95,7 +92,7 @@ class DisplayListGLComplexityCalculator
9592

9693
private:
9794
unsigned int save_layer_count_ = 0;
98-
unsigned int draw_text_blob_count_ = 0;
95+
unsigned int draw_text_count_ = 0;
9996
};
10097

10198
DisplayListGLComplexityCalculator()

engine/src/flutter/display_list/benchmarking/dl_complexity_metal.cc

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -51,12 +51,12 @@ DisplayListMetalComplexityCalculator::MetalHelper::BatchedComplexity() {
5151
}
5252

5353
unsigned int draw_text_blob_complexity;
54-
if (draw_text_blob_count_ == 0) {
54+
if (draw_text_count_ == 0) {
5555
draw_text_blob_complexity = 0;
5656
} else {
5757
// m = 1/240
5858
// c = 0.75
59-
draw_text_blob_complexity = (draw_text_blob_count_ + 180) * 2500 / 3;
59+
draw_text_blob_complexity = (draw_text_count_ + 180) * 2500 / 3;
6060
}
6161

6262
return save_layer_complexity + draw_text_blob_complexity;
@@ -585,8 +585,8 @@ void DisplayListMetalComplexityCalculator::MetalHelper::drawDisplayList(
585585
AccumulateComplexity(helper.ComplexityScore());
586586
}
587587

588-
void DisplayListMetalComplexityCalculator::MetalHelper::drawTextBlob(
589-
const sk_sp<SkTextBlob> blob,
588+
void DisplayListMetalComplexityCalculator::MetalHelper::drawText(
589+
const std::shared_ptr<DlText>& text,
590590
DlScalar x,
591591
DlScalar y) {
592592
if (IsComplex()) {
@@ -597,15 +597,10 @@ void DisplayListMetalComplexityCalculator::MetalHelper::drawTextBlob(
597597
// per frame, that fixed cost is greatly reduced per subsequent call. This
598598
// is likely because there is batching being done in SkCanvas.
599599

600-
// Increment draw_text_blob_count_ and calculate the cost at the end.
601-
draw_text_blob_count_++;
600+
// Increment draw_text_count_ and calculate the cost at the end.
601+
draw_text_count_++;
602602
}
603603

604-
void DisplayListMetalComplexityCalculator::MetalHelper::drawTextFrame(
605-
const std::shared_ptr<impeller::TextFrame>& text_frame,
606-
DlScalar x,
607-
DlScalar y) {}
608-
609604
void DisplayListMetalComplexityCalculator::MetalHelper::drawShadow(
610605
const DlPath& path,
611606
const DlColor color,

engine/src/flutter/display_list/benchmarking/dl_complexity_metal.h

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -73,12 +73,9 @@ class DisplayListMetalComplexityCalculator
7373
bool render_with_attributes) override;
7474
void drawDisplayList(const sk_sp<DisplayList> display_list,
7575
DlScalar opacity) override;
76-
void drawTextBlob(const sk_sp<SkTextBlob> blob,
77-
DlScalar x,
78-
DlScalar y) override;
79-
void drawTextFrame(const std::shared_ptr<impeller::TextFrame>& text_frame,
80-
DlScalar x,
81-
DlScalar y) override;
76+
void drawText(const std::shared_ptr<DlText>& text,
77+
DlScalar x,
78+
DlScalar y) override;
8279
void drawShadow(const DlPath& path,
8380
const DlColor color,
8481
const DlScalar elevation,
@@ -95,7 +92,7 @@ class DisplayListMetalComplexityCalculator
9592

9693
private:
9794
unsigned int save_layer_count_ = 0;
98-
unsigned int draw_text_blob_count_ = 0;
95+
unsigned int draw_text_count_ = 0;
9996
};
10097

10198
DisplayListMetalComplexityCalculator()

engine/src/flutter/display_list/benchmarking/dl_complexity_unittests.cc

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#include "flutter/display_list/display_list.h"
99
#include "flutter/display_list/dl_builder.h"
1010
#include "flutter/display_list/dl_sampling_options.h"
11+
#include "flutter/display_list/dl_text_skia.h"
1112
#include "flutter/display_list/geometry/dl_path_builder.h"
1213
#include "flutter/display_list/testing/dl_test_snippets.h"
1314
#include "flutter/testing/testing.h"
@@ -305,14 +306,14 @@ TEST(DisplayListComplexity, DrawVertices) {
305306
TEST(DisplayListComplexity, DrawTextBlob) {
306307
auto text_blob =
307308
GetTestTextBlob("The quick brown fox jumps over the lazy dog.", 20.0f);
308-
309+
auto text = DlTextSkia::Make(text_blob);
309310
DisplayListBuilder builder;
310-
builder.DrawTextBlob(text_blob, 0.0f, 0.0f, DlPaint());
311+
builder.DrawText(text, 0.0f, 0.0f, DlPaint());
311312
auto display_list = builder.Build();
312313

313314
DisplayListBuilder builder_multiple;
314-
builder_multiple.DrawTextBlob(text_blob, 0.0f, 0.0f, DlPaint());
315-
builder_multiple.DrawTextBlob(text_blob, 0.0f, 0.0f, DlPaint());
315+
builder_multiple.DrawText(text, 0.0f, 0.0f, DlPaint());
316+
builder_multiple.DrawText(text, 0.0f, 0.0f, DlPaint());
316317
auto display_list_multiple = builder_multiple.Build();
317318

318319
auto calculators = AccumulatorCalculators();

engine/src/flutter/display_list/display_list.cc

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -333,8 +333,7 @@ DisplayListOpCategory DisplayList::GetOpCategory(DisplayListOpType type) {
333333
case DisplayListOpType::kDrawImageNineWithAttr:
334334
case DisplayListOpType::kDrawAtlas:
335335
case DisplayListOpType::kDrawAtlasCulled:
336-
case DisplayListOpType::kDrawTextBlob:
337-
case DisplayListOpType::kDrawTextFrame:
336+
case DisplayListOpType::kDrawText:
338337
case DisplayListOpType::kDrawShadow:
339338
case DisplayListOpType::kDrawShadowTransparentOccluder:
340339
return DisplayListOpCategory::kRendering;

engine/src/flutter/display_list/display_list.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,8 +133,7 @@ namespace flutter {
133133
V(DrawAtlasCulled) \
134134
\
135135
V(DrawDisplayList) \
136-
V(DrawTextBlob) \
137-
V(DrawTextFrame) \
136+
V(DrawText) \
138137
\
139138
V(DrawShadow) \
140139
V(DrawShadowTransparentOccluder)

engine/src/flutter/display_list/display_list_unittests.cc

Lines changed: 34 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include "flutter/display_list/dl_blend_mode.h"
1313
#include "flutter/display_list/dl_builder.h"
1414
#include "flutter/display_list/dl_paint.h"
15+
#include "flutter/display_list/dl_text_skia.h"
1516
#include "flutter/display_list/effects/dl_image_filters.h"
1617
#include "flutter/display_list/geometry/dl_path_builder.h"
1718
#include "flutter/display_list/geometry/dl_rtree.h"
@@ -20,7 +21,12 @@
2021
#include "flutter/display_list/utils/dl_receiver_utils.h"
2122
#include "flutter/fml/logging.h"
2223
#include "flutter/fml/math.h"
23-
#include "flutter/impeller/typographer/backends/skia/text_frame_skia.h"
24+
25+
#if IMPELLER_SUPPORTS_RENDERING
26+
#include "flutter/impeller/display_list/dl_text_impeller.h" // nogncheck
27+
#include "flutter/impeller/typographer/backends/skia/text_frame_skia.h" //nogncheck
28+
#endif
29+
2430
#include "flutter/testing/assertions_skia.h"
2531
#include "flutter/testing/display_list_testing.h"
2632
#include "flutter/testing/testing.h"
@@ -1224,7 +1230,13 @@ TEST_F(DisplayListTest, SingleOpsMightSupportGroupOpacityBlendMode) {
12241230
static auto display_list = builder.Build();
12251231
RUN_TESTS2(canvas.DrawDisplayList(display_list);, false);
12261232
}
1227-
RUN_TESTS2(canvas.DrawTextBlob(GetTestTextBlob(1), 0, 0, paint);, false);
1233+
RUN_TESTS2(canvas.DrawText(DlTextSkia::Make(GetTestTextBlob(1)), 0, 0, paint);
1234+
, false);
1235+
#if IMPELLER_SUPPORTS_RENDERING
1236+
RUN_TESTS2(
1237+
canvas.DrawText(DlTextImpeller::Make(GetTestTextFrame(1)), 0, 0, paint);
1238+
, false);
1239+
#endif
12281240
RUN_TESTS2(canvas.DrawShadow(kTestPath1, DlColor::kBlack(), 1.0, false, 1.0);
12291241
, false);
12301242

@@ -3516,7 +3528,11 @@ TEST_F(DisplayListTest, NopOperationsOmittedFromRecords) {
35163528
builder.DrawAtlas(kTestImage1, xforms, rects, nullptr, 2,
35173529
DlBlendMode::kSrcOver, DlImageSampling::kLinear,
35183530
nullptr, &paint);
3519-
builder.DrawTextBlob(GetTestTextBlob(1), 10, 10, paint);
3531+
builder.DrawText(DlTextSkia::Make(GetTestTextBlob(1)), 10, 10, paint);
3532+
#if IMPELLER_SUPPORTS_RENDERING
3533+
builder.DrawText(DlTextImpeller::Make(GetTestTextFrame(1)), 10, 10,
3534+
paint);
3535+
#endif
35203536

35213537
// Dst mode eliminates most rendering ops except for
35223538
// the following two, so we'll prune those manually...
@@ -5489,29 +5505,33 @@ TEST_F(DisplayListTest, BoundedRenderOpsDoNotReportUnbounded) {
54895505
ASSERT_LT(blob->bounds().width(), draw_rect.GetWidth());
54905506
ASSERT_LT(blob->bounds().height(), draw_rect.GetHeight());
54915507

5508+
auto text = DlTextSkia::Make(blob);
54925509
// Draw once at upper left and again at lower right to fill the bounds.
5493-
builder.DrawTextBlob(blob, draw_rect.GetLeft() - blob->bounds().left(),
5494-
draw_rect.GetTop() - blob->bounds().top(), DlPaint());
5495-
builder.DrawTextBlob(blob, draw_rect.GetRight() - blob->bounds().right(),
5496-
draw_rect.GetBottom() - blob->bounds().bottom(),
5497-
DlPaint());
5510+
builder.DrawText(text, draw_rect.GetLeft() - blob->bounds().left(),
5511+
draw_rect.GetTop() - blob->bounds().top(), DlPaint());
5512+
builder.DrawText(text, draw_rect.GetRight() - blob->bounds().right(),
5513+
draw_rect.GetBottom() - blob->bounds().bottom(),
5514+
DlPaint());
54985515
});
54995516

5517+
#if IMPELLER_SUPPORTS_RENDERING
55005518
test_bounded("DrawTextFrame", [](DlCanvas& builder) {
55015519
auto blob = GetTestTextBlob("Hello");
5502-
auto frame = impeller::MakeTextFrameFromTextBlobSkia(blob);
55035520

55045521
// Make sure the blob fits within the draw_rect bounds.
55055522
ASSERT_LT(blob->bounds().width(), draw_rect.GetWidth());
55065523
ASSERT_LT(blob->bounds().height(), draw_rect.GetHeight());
55075524

5525+
auto text = DlTextImpeller::MakeFromBlob(blob);
5526+
55085527
// Draw once at upper left and again at lower right to fill the bounds.
5509-
builder.DrawTextFrame(frame, draw_rect.GetLeft() - blob->bounds().left(),
5510-
draw_rect.GetTop() - blob->bounds().top(), DlPaint());
5511-
builder.DrawTextFrame(frame, draw_rect.GetRight() - blob->bounds().right(),
5512-
draw_rect.GetBottom() - blob->bounds().bottom(),
5513-
DlPaint());
5528+
builder.DrawText(text, draw_rect.GetLeft() - blob->bounds().left(),
5529+
draw_rect.GetTop() - blob->bounds().top(), DlPaint());
5530+
builder.DrawText(text, draw_rect.GetRight() - blob->bounds().right(),
5531+
draw_rect.GetBottom() - blob->bounds().bottom(),
5532+
DlPaint());
55145533
});
5534+
#endif
55155535

55165536
test_bounded("DrawBoundedDisplayList", [](DlCanvas& builder) {
55175537
DisplayListBuilder nested_builder(root_cull);

0 commit comments

Comments
 (0)