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

Commit 6e90446

Browse files
authored
[Impeller] DlCanvas implementation wrapping Aiks canvas (#44248)
Fixes flutter/flutter#130141 The primary goal of this patch is to move dispatching of `dart:ui` `Canvas` commands to the UI thread. Before this patch, the architecture is something like: ## UI Thread - `dart:ui` talks to `DisplayListBuilder`, a `DlCanvas` implementation. - `DisplayListBuilder` does some clip/bounds tracking and creates a `DisplayList` object that is held by `dart:ui`'s `Picture` objects. - `DisplayList`s are added to `DisplayListLayer`s in `flow`. ## Raster Thread - `flow` flattens the various operations into a single `DisplayList` via another `DisplayListBuilder`. - A `DlOpReceiver`implementation converts that `DisplayList` into an `Aiks` `Canvas`/`Picture`. After this patch, the architecture instead looks like: ## UI Thread - No change for Skia. - If Impeller, use a new `DlCanvasImplementation` that talks to `Aiks`'s `Canvas`. - If Impeller, `dart:ui` Picture's now hold an `Aiks` `Picture`, which get shared into `AiksLayer`s in `flow`. ## Raster thread - No change for Skia, but some light refactoring for places that assumed a `DisplayListBuilder` where they really just needed a `DlCanvas`. - The `Aiks` `Picture`s are combined using new API on `DlCanvas` and still backed by `Aiks`. These changes show significant improvement on raster times on Android and only very small regressions on UI times in local testing, see https://gist.github.com/dnfield/26528090194c9f5abdbac13cdcbf4f79 for old gallery transition perf numbers. Many of the other changes in this patch are related to the following: - Making `DlRTree` usable for Impeller. - It would be nice to have a version of DlRTree that speaks `impeller::Rect`. - Creating the requisite classes to support `EmbeddedViews` so that Desktop works. This patch does not remove the `impeller::DlDispatcher`, which now would only be used in tests.
1 parent 5e51aa9 commit 6e90446

File tree

78 files changed

+2512
-403
lines changed

Some content is hidden

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

78 files changed

+2512
-403
lines changed

ci/licenses_golden/excluded_files

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
../../../flutter/display_list/benchmarking/dl_complexity_unittests.cc
3333
../../../flutter/display_list/display_list_unittests.cc
3434
../../../flutter/display_list/dl_color_unittests.cc
35+
../../../flutter/display_list/dl_op_spy_unittests.cc
3536
../../../flutter/display_list/dl_paint_unittests.cc
3637
../../../flutter/display_list/dl_vertices_unittests.cc
3738
../../../flutter/display_list/effects/dl_color_filter_unittests.cc
@@ -215,7 +216,6 @@
215216
../../../flutter/runtime/type_conversions_unittests.cc
216217
../../../flutter/shell/common/animator_unittests.cc
217218
../../../flutter/shell/common/context_options_unittests.cc
218-
../../../flutter/shell/common/dl_op_spy_unittests.cc
219219
../../../flutter/shell/common/engine_unittests.cc
220220
../../../flutter/shell/common/fixtures
221221
../../../flutter/shell/common/input_events_unittests.cc

ci/licenses_golden/licenses_flutter

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -731,6 +731,8 @@ ORIGIN: ../../../flutter/display_list/dl_op_receiver.cc + ../../../flutter/LICEN
731731
ORIGIN: ../../../flutter/display_list/dl_op_receiver.h + ../../../flutter/LICENSE
732732
ORIGIN: ../../../flutter/display_list/dl_op_records.cc + ../../../flutter/LICENSE
733733
ORIGIN: ../../../flutter/display_list/dl_op_records.h + ../../../flutter/LICENSE
734+
ORIGIN: ../../../flutter/display_list/dl_op_spy.cc + ../../../flutter/LICENSE
735+
ORIGIN: ../../../flutter/display_list/dl_op_spy.h + ../../../flutter/LICENSE
734736
ORIGIN: ../../../flutter/display_list/dl_paint.cc + ../../../flutter/LICENSE
735737
ORIGIN: ../../../flutter/display_list/dl_paint.h + ../../../flutter/LICENSE
736738
ORIGIN: ../../../flutter/display_list/dl_sampling_options.h + ../../../flutter/LICENSE
@@ -787,6 +789,8 @@ ORIGIN: ../../../flutter/flow/instrumentation.cc + ../../../flutter/LICENSE
787789
ORIGIN: ../../../flutter/flow/instrumentation.h + ../../../flutter/LICENSE
788790
ORIGIN: ../../../flutter/flow/layer_snapshot_store.cc + ../../../flutter/LICENSE
789791
ORIGIN: ../../../flutter/flow/layer_snapshot_store.h + ../../../flutter/LICENSE
792+
ORIGIN: ../../../flutter/flow/layers/aiks_layer.cc + ../../../flutter/LICENSE
793+
ORIGIN: ../../../flutter/flow/layers/aiks_layer.h + ../../../flutter/LICENSE
790794
ORIGIN: ../../../flutter/flow/layers/backdrop_filter_layer.cc + ../../../flutter/LICENSE
791795
ORIGIN: ../../../flutter/flow/layers/backdrop_filter_layer.h + ../../../flutter/LICENSE
792796
ORIGIN: ../../../flutter/flow/layers/cacheable_layer.cc + ../../../flutter/LICENSE
@@ -1153,6 +1157,8 @@ ORIGIN: ../../../flutter/impeller/core/texture_descriptor.cc + ../../../flutter/
11531157
ORIGIN: ../../../flutter/impeller/core/texture_descriptor.h + ../../../flutter/LICENSE
11541158
ORIGIN: ../../../flutter/impeller/core/vertex_buffer.cc + ../../../flutter/LICENSE
11551159
ORIGIN: ../../../flutter/impeller/core/vertex_buffer.h + ../../../flutter/LICENSE
1160+
ORIGIN: ../../../flutter/impeller/display_list/dl_aiks_canvas.cc + ../../../flutter/LICENSE
1161+
ORIGIN: ../../../flutter/impeller/display_list/dl_aiks_canvas.h + ../../../flutter/LICENSE
11561162
ORIGIN: ../../../flutter/impeller/display_list/dl_dispatcher.cc + ../../../flutter/LICENSE
11571163
ORIGIN: ../../../flutter/impeller/display_list/dl_dispatcher.h + ../../../flutter/LICENSE
11581164
ORIGIN: ../../../flutter/impeller/display_list/dl_image_impeller.cc + ../../../flutter/LICENSE
@@ -2210,8 +2216,6 @@ ORIGIN: ../../../flutter/shell/common/display.cc + ../../../flutter/LICENSE
22102216
ORIGIN: ../../../flutter/shell/common/display.h + ../../../flutter/LICENSE
22112217
ORIGIN: ../../../flutter/shell/common/display_manager.cc + ../../../flutter/LICENSE
22122218
ORIGIN: ../../../flutter/shell/common/display_manager.h + ../../../flutter/LICENSE
2213-
ORIGIN: ../../../flutter/shell/common/dl_op_spy.cc + ../../../flutter/LICENSE
2214-
ORIGIN: ../../../flutter/shell/common/dl_op_spy.h + ../../../flutter/LICENSE
22152219
ORIGIN: ../../../flutter/shell/common/engine.cc + ../../../flutter/LICENSE
22162220
ORIGIN: ../../../flutter/shell/common/engine.h + ../../../flutter/LICENSE
22172221
ORIGIN: ../../../flutter/shell/common/pipeline.cc + ../../../flutter/LICENSE
@@ -3441,6 +3445,8 @@ FILE: ../../../flutter/display_list/dl_op_receiver.cc
34413445
FILE: ../../../flutter/display_list/dl_op_receiver.h
34423446
FILE: ../../../flutter/display_list/dl_op_records.cc
34433447
FILE: ../../../flutter/display_list/dl_op_records.h
3448+
FILE: ../../../flutter/display_list/dl_op_spy.cc
3449+
FILE: ../../../flutter/display_list/dl_op_spy.h
34443450
FILE: ../../../flutter/display_list/dl_paint.cc
34453451
FILE: ../../../flutter/display_list/dl_paint.h
34463452
FILE: ../../../flutter/display_list/dl_sampling_options.h
@@ -3497,6 +3503,8 @@ FILE: ../../../flutter/flow/instrumentation.cc
34973503
FILE: ../../../flutter/flow/instrumentation.h
34983504
FILE: ../../../flutter/flow/layer_snapshot_store.cc
34993505
FILE: ../../../flutter/flow/layer_snapshot_store.h
3506+
FILE: ../../../flutter/flow/layers/aiks_layer.cc
3507+
FILE: ../../../flutter/flow/layers/aiks_layer.h
35003508
FILE: ../../../flutter/flow/layers/backdrop_filter_layer.cc
35013509
FILE: ../../../flutter/flow/layers/backdrop_filter_layer.h
35023510
FILE: ../../../flutter/flow/layers/cacheable_layer.cc
@@ -3863,6 +3871,8 @@ FILE: ../../../flutter/impeller/core/texture_descriptor.cc
38633871
FILE: ../../../flutter/impeller/core/texture_descriptor.h
38643872
FILE: ../../../flutter/impeller/core/vertex_buffer.cc
38653873
FILE: ../../../flutter/impeller/core/vertex_buffer.h
3874+
FILE: ../../../flutter/impeller/display_list/dl_aiks_canvas.cc
3875+
FILE: ../../../flutter/impeller/display_list/dl_aiks_canvas.h
38663876
FILE: ../../../flutter/impeller/display_list/dl_dispatcher.cc
38673877
FILE: ../../../flutter/impeller/display_list/dl_dispatcher.h
38683878
FILE: ../../../flutter/impeller/display_list/dl_image_impeller.cc
@@ -4925,8 +4935,6 @@ FILE: ../../../flutter/shell/common/display.cc
49254935
FILE: ../../../flutter/shell/common/display.h
49264936
FILE: ../../../flutter/shell/common/display_manager.cc
49274937
FILE: ../../../flutter/shell/common/display_manager.h
4928-
FILE: ../../../flutter/shell/common/dl_op_spy.cc
4929-
FILE: ../../../flutter/shell/common/dl_op_spy.h
49304938
FILE: ../../../flutter/shell/common/engine.cc
49314939
FILE: ../../../flutter/shell/common/engine.h
49324940
FILE: ../../../flutter/shell/common/pipeline.cc

display_list/BUILD.gn

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ source_set("display_list") {
3939
"dl_op_receiver.h",
4040
"dl_op_records.cc",
4141
"dl_op_records.h",
42+
"dl_op_spy.cc",
43+
"dl_op_spy.h",
4244
"dl_paint.cc",
4345
"dl_paint.h",
4446
"dl_sampling_options.h",
@@ -107,6 +109,7 @@ if (enable_unittests) {
107109
"benchmarking/dl_complexity_unittests.cc",
108110
"display_list_unittests.cc",
109111
"dl_color_unittests.cc",
112+
"dl_op_spy_unittests.cc",
110113
"dl_paint_unittests.cc",
111114
"dl_vertices_unittests.cc",
112115
"effects/dl_color_filter_unittests.cc",

display_list/display_list.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ DisplayList::DisplayList(DisplayListStorage&& storage,
3434
bool can_apply_group_opacity,
3535
bool is_ui_thread_safe,
3636
bool modifies_transparent_black,
37-
sk_sp<const DlRTree> rtree)
37+
std::shared_ptr<const DlRTree> rtree)
3838
: storage_(std::move(storage)),
3939
byte_count_(byte_count),
4040
op_count_(op_count),

display_list/display_list.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ class DisplayList : public SkRefCnt {
254254
const SkRect& bounds() const { return bounds_; }
255255

256256
bool has_rtree() const { return rtree_ != nullptr; }
257-
sk_sp<const DlRTree> rtree() const { return rtree_; }
257+
std::shared_ptr<const DlRTree> rtree() const { return rtree_; }
258258

259259
bool Equals(const DisplayList* other) const;
260260
bool Equals(const DisplayList& other) const { return Equals(&other); }
@@ -288,7 +288,7 @@ class DisplayList : public SkRefCnt {
288288
bool can_apply_group_opacity,
289289
bool is_ui_thread_safe,
290290
bool modifies_transparent_black,
291-
sk_sp<const DlRTree> rtree);
291+
std::shared_ptr<const DlRTree> rtree);
292292

293293
static uint32_t next_unique_id();
294294

@@ -308,7 +308,7 @@ class DisplayList : public SkRefCnt {
308308
const bool is_ui_thread_safe_;
309309
const bool modifies_transparent_black_;
310310

311-
const sk_sp<const DlRTree> rtree_;
311+
const std::shared_ptr<const DlRTree> rtree_;
312312

313313
void Dispatch(DlOpReceiver& ctx,
314314
uint8_t* ptr,

display_list/display_list_unittests.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2130,7 +2130,7 @@ TEST_F(DisplayListTest, FlatDrawPointsProducesBounds) {
21302130
}
21312131
}
21322132

2133-
static void test_rtree(const sk_sp<const DlRTree>& rtree,
2133+
static void test_rtree(const std::shared_ptr<const DlRTree>& rtree,
21342134
const SkRect& query,
21352135
std::vector<SkRect> expected_rects,
21362136
const std::vector<int>& expected_indices) {

display_list/dl_builder.cc

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1208,6 +1208,13 @@ void DisplayListBuilder::DrawAtlas(const sk_sp<DlImage>& atlas,
12081208
}
12091209
}
12101210

1211+
void DisplayListBuilder::DrawImpellerPicture(
1212+
const std::shared_ptr<const impeller::Picture>& picture,
1213+
SkScalar opacity) {
1214+
FML_LOG(ERROR) << "Cannot draw Impeller Picture in to a a display list.";
1215+
FML_DCHECK(false);
1216+
}
1217+
12111218
void DisplayListBuilder::DrawDisplayList(const sk_sp<DisplayList> display_list,
12121219
SkScalar opacity) {
12131220
if (!SkScalarIsFinite(opacity) || opacity <= SK_ScalarNearlyZero ||

display_list/dl_builder.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,12 @@ class DisplayListBuilder final : public virtual DlCanvas,
216216
DlImageSampling sampling,
217217
const SkRect* cullRect,
218218
const DlPaint* paint = nullptr) override;
219+
220+
// |DlCanvas|
221+
void DrawImpellerPicture(
222+
const std::shared_ptr<const impeller::Picture>& picture,
223+
SkScalar opacity = SK_Scalar1) override;
224+
219225
// |DlCanvas|
220226
void DrawDisplayList(const sk_sp<DisplayList> display_list,
221227
SkScalar opacity = SK_Scalar1) override;
@@ -701,7 +707,7 @@ class DisplayListBuilder final : public virtual DlCanvas,
701707
return accumulator_->bounds();
702708
}
703709

704-
sk_sp<DlRTree> rtree() {
710+
std::shared_ptr<DlRTree> rtree() {
705711
FML_DCHECK(layer_stack_.size() == 1);
706712
if (is_unbounded()) {
707713
FML_LOG(INFO) << "returning partial rtree for unbounded DisplayList";

display_list/dl_canvas.h

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@
1818
#include "third_party/skia/include/core/SkRect.h"
1919
#include "third_party/skia/include/core/SkTextBlob.h"
2020

21+
namespace impeller {
22+
struct Picture;
23+
} // namespace impeller
24+
2125
namespace flutter {
2226

2327
// The primary class used to express rendering operations in the
@@ -59,7 +63,12 @@ class DlCanvas {
5963
const DlImageFilter* backdrop = nullptr) = 0;
6064
virtual void Restore() = 0;
6165
virtual int GetSaveCount() const = 0;
62-
virtual void RestoreToCount(int restore_count) = 0;
66+
virtual void RestoreToCount(int restore_count) {
67+
FML_DCHECK(restore_count <= GetSaveCount());
68+
while (restore_count < GetSaveCount() && GetSaveCount() > 1) {
69+
Restore();
70+
}
71+
}
6372

6473
virtual void Translate(SkScalar tx, SkScalar ty) = 0;
6574
virtual void Scale(SkScalar sx, SkScalar sy) = 0;
@@ -199,6 +208,9 @@ class DlCanvas {
199208
const DlPaint* paint = nullptr) = 0;
200209
virtual void DrawDisplayList(const sk_sp<DisplayList> display_list,
201210
SkScalar opacity = SK_Scalar1) = 0;
211+
virtual void DrawImpellerPicture(
212+
const std::shared_ptr<const impeller::Picture>& picture,
213+
SkScalar opacity = SK_Scalar1) = 0;
202214
virtual void DrawTextBlob(const sk_sp<SkTextBlob>& blob,
203215
SkScalar x,
204216
SkScalar y,
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
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/shell/common/dl_op_spy.h"
5+
#include "flutter/display_list/dl_op_spy.h"
66

77
namespace flutter {
88

0 commit comments

Comments
 (0)