From 7da9ad186265ad7e53c294309cd109da421904d6 Mon Sep 17 00:00:00 2001 From: Jim Graham Date: Fri, 13 Sep 2024 14:49:09 -0700 Subject: [PATCH] Delete VolatilePathTracker in favor of Dispatch tracking (flutter/engine#55125) ui.Canvas and ui.SceneBuilder now use the DlPath object directly from the ui.Path object. This results in increased sharing of the wrapper objects which then increases the sharing of both the converted Impeller paths and Skia's volatile flag. The VolatilePathTracker mechanism is deleted and rather than count the number of frames that a path is stable for, instead we count the number of times it is used for rendering. If a path is used 100 times in a single frame, it will become non-volatile and start being cached almost immediately. The cached Impeller paths are now also tracked for all instances of the same path, rather than for each call site that originated from a DisplayList dispatch. --- .../ci/licenses_golden/licenses_flutter | 4 - .../display_list/display_list_unittests.cc | 2 +- .../src/flutter/display_list/dl_op_records.h | 9 +- .../flutter/display_list/geometry/dl_path.cc | 48 +++--- .../flutter/display_list/geometry/dl_path.h | 27 +++- .../geometry/dl_path_unittests.cc | 111 +++++++++++++- .../flutter/display_list/skia/dl_sk_canvas.h | 16 ++ .../display_list/skia/dl_sk_dispatcher.cc | 3 + .../display_list/testing/dl_test_snippets.cc | 36 ++--- .../flutter/flow/layers/clip_path_layer.cc | 8 +- .../src/flutter/flow/layers/clip_path_layer.h | 6 +- .../flow/layers/clip_path_layer_unittests.cc | 38 +++-- engine/src/flutter/lib/ui/BUILD.gn | 2 - engine/src/flutter/lib/ui/painting/path.cc | 138 +++++++++--------- engine/src/flutter/lib/ui/painting/path.h | 11 +- .../flutter/lib/ui/painting/path_measure.cc | 5 +- .../flutter/lib/ui/painting/path_unittests.cc | 102 ++++--------- engine/src/flutter/lib/ui/ui_benchmarks.cc | 48 ------ engine/src/flutter/lib/ui/ui_dart_state.cc | 13 +- engine/src/flutter/lib/ui/ui_dart_state.h | 12 +- .../flutter/lib/ui/volatile_path_tracker.cc | 50 ------- .../flutter/lib/ui/volatile_path_tracker.h | 79 ---------- .../flutter/runtime/dart_isolate_unittests.cc | 42 +++--- .../src/flutter/runtime/runtime_controller.cc | 2 +- .../src/flutter/runtime/runtime_controller.h | 1 - engine/src/flutter/shell/common/engine.cc | 10 +- engine/src/flutter/shell/common/engine.h | 2 - .../shell/common/engine_animator_unittests.cc | 1 - engine/src/flutter/shell/common/shell.cc | 37 ++--- engine/src/flutter/shell/common/shell.h | 4 - engine/src/flutter/shell/common/shell_test.cc | 9 -- engine/src/flutter/shell/common/shell_test.h | 4 - .../flutter/testing/dart_isolate_runner.cc | 5 +- .../src/flutter/testing/dart_isolate_runner.h | 2 - 34 files changed, 389 insertions(+), 498 deletions(-) delete mode 100644 engine/src/flutter/lib/ui/volatile_path_tracker.cc delete mode 100644 engine/src/flutter/lib/ui/volatile_path_tracker.h diff --git a/engine/src/flutter/ci/licenses_golden/licenses_flutter b/engine/src/flutter/ci/licenses_golden/licenses_flutter index cc12fd93b1..9c3e6867e3 100644 --- a/engine/src/flutter/ci/licenses_golden/licenses_flutter +++ b/engine/src/flutter/ci/licenses_golden/licenses_flutter @@ -43487,8 +43487,6 @@ ORIGIN: ../../../flutter/lib/ui/ui.dart + ../../../flutter/LICENSE ORIGIN: ../../../flutter/lib/ui/ui_benchmarks.cc + ../../../flutter/LICENSE ORIGIN: ../../../flutter/lib/ui/ui_dart_state.cc + ../../../flutter/LICENSE ORIGIN: ../../../flutter/lib/ui/ui_dart_state.h + ../../../flutter/LICENSE -ORIGIN: ../../../flutter/lib/ui/volatile_path_tracker.cc + ../../../flutter/LICENSE -ORIGIN: ../../../flutter/lib/ui/volatile_path_tracker.h + ../../../flutter/LICENSE ORIGIN: ../../../flutter/lib/ui/window.dart + ../../../flutter/LICENSE ORIGIN: ../../../flutter/lib/ui/window/key_data.cc + ../../../flutter/LICENSE ORIGIN: ../../../flutter/lib/ui/window/key_data.h + ../../../flutter/LICENSE @@ -46337,8 +46335,6 @@ FILE: ../../../flutter/lib/ui/ui.dart FILE: ../../../flutter/lib/ui/ui_benchmarks.cc FILE: ../../../flutter/lib/ui/ui_dart_state.cc FILE: ../../../flutter/lib/ui/ui_dart_state.h -FILE: ../../../flutter/lib/ui/volatile_path_tracker.cc -FILE: ../../../flutter/lib/ui/volatile_path_tracker.h FILE: ../../../flutter/lib/ui/window.dart FILE: ../../../flutter/lib/ui/window/key_data.cc FILE: ../../../flutter/lib/ui/window/key_data.h diff --git a/engine/src/flutter/display_list/display_list_unittests.cc b/engine/src/flutter/display_list/display_list_unittests.cc index 9838573cb1..56c560540b 100644 --- a/engine/src/flutter/display_list/display_list_unittests.cc +++ b/engine/src/flutter/display_list/display_list_unittests.cc @@ -1839,7 +1839,7 @@ TEST_F(DisplayListTest, FlutterSvgIssue661BoundsWereEmpty) { // This is the more practical result. The bounds are "almost" 0,0,100x100 EXPECT_EQ(display_list->bounds().roundOut(), SkIRect::MakeWH(100, 100)); EXPECT_EQ(display_list->op_count(), 19u); - EXPECT_EQ(display_list->bytes(), sizeof(DisplayList) + 424u); + EXPECT_EQ(display_list->bytes(), sizeof(DisplayList) + 392u); EXPECT_EQ(display_list->total_depth(), 3u); } diff --git a/engine/src/flutter/display_list/dl_op_records.h b/engine/src/flutter/display_list/dl_op_records.h index 1956b95a67..592c31e914 100644 --- a/engine/src/flutter/display_list/dl_op_records.h +++ b/engine/src/flutter/display_list/dl_op_records.h @@ -137,7 +137,7 @@ struct SetStrokeMiterOp final : DLOp { } }; -// 4 byte header + 4 byte payload packs into minimum 8 bytes +// 4 byte header + 20 byte payload packs into minimum 24 bytes struct SetColorOp final : DLOp { static constexpr auto kType = DisplayListOpType::kSetColor; @@ -490,6 +490,7 @@ DEFINE_CLIP_SHAPE_OP(Oval, DlRect, Difference) DEFINE_CLIP_SHAPE_OP(RRect, SkRRect, Difference) #undef DEFINE_CLIP_SHAPE_OP +// 4 byte header + 20 byte payload packs evenly into 24 bytes #define DEFINE_CLIP_PATH_OP(clipop) \ struct Clip##clipop##PathOp final : TransformClipOpBase { \ static constexpr auto kType = DisplayListOpType::kClip##clipop##Path; \ @@ -566,8 +567,8 @@ DEFINE_DRAW_1ARG_OP(Oval, DlRect, oval) DEFINE_DRAW_1ARG_OP(RRect, SkRRect, rrect) #undef DEFINE_DRAW_1ARG_OP -// 4 byte header + 128 byte payload uses 132 bytes but is rounded -// up to 136 bytes (4 bytes unused) +// 4 byte header + 16 byte payload uses 20 bytes but is rounded +// up to 24 bytes (4 bytes unused) struct DrawPathOp final : DrawOpBase { static constexpr auto kType = DisplayListOpType::kDrawPath; @@ -975,7 +976,7 @@ struct DrawTextFrameOp final : DrawOpBase { } }; -// 4 byte header + 140 byte payload packs evenly into 140 bytes +// 4 byte header + 44 byte payload packs evenly into 48 bytes #define DEFINE_DRAW_SHADOW_OP(name, transparent_occluder) \ struct Draw##name##Op final : DrawOpBase { \ static constexpr auto kType = DisplayListOpType::kDraw##name; \ diff --git a/engine/src/flutter/display_list/geometry/dl_path.cc b/engine/src/flutter/display_list/geometry/dl_path.cc index 4ab67aec64..38fea72130 100644 --- a/engine/src/flutter/display_list/geometry/dl_path.cc +++ b/engine/src/flutter/display_list/geometry/dl_path.cc @@ -10,61 +10,69 @@ namespace flutter { const SkPath& DlPath::GetSkPath() const { - return sk_path_; + return data_->sk_path; } impeller::Path DlPath::GetPath() const { - if (path_.IsEmpty() && !sk_path_.isEmpty()) { - path_ = ConvertToImpellerPath(sk_path_); + if (!data_->path.has_value()) { + data_->path = ConvertToImpellerPath(data_->sk_path); } - return path_; + // Covered by check above. + // NOLINTNEXTLINE(bugprone-unchecked-optional-access) + return data_->path.value(); +} + +void DlPath::WillRenderSkPath() const { + if (data_->render_count >= kMaxVolatileUses) { + data_->sk_path.setIsVolatile(false); + } else { + data_->render_count++; + } } bool DlPath::IsInverseFillType() const { - return sk_path_.isInverseFillType(); + return data_->sk_path.isInverseFillType(); } bool DlPath::IsRect(DlRect* rect, bool* is_closed) const { - return sk_path_.isRect(ToSkRect(rect), is_closed); + return data_->sk_path.isRect(ToSkRect(rect), is_closed); } bool DlPath::IsOval(DlRect* bounds) const { - return sk_path_.isOval(ToSkRect(bounds)); + return data_->sk_path.isOval(ToSkRect(bounds)); } bool DlPath::IsSkRect(SkRect* rect, bool* is_closed) const { - return sk_path_.isRect(rect, is_closed); + return data_->sk_path.isRect(rect, is_closed); } bool DlPath::IsSkOval(SkRect* bounds) const { - return sk_path_.isOval(bounds); + return data_->sk_path.isOval(bounds); } bool DlPath::IsSkRRect(SkRRect* rrect) const { - return sk_path_.isRRect(rrect); + return data_->sk_path.isRRect(rrect); } SkRect DlPath::GetSkBounds() const { - return sk_path_.getBounds(); + return data_->sk_path.getBounds(); } DlRect DlPath::GetBounds() const { - return ToDlRect(sk_path_.getBounds()); + return ToDlRect(data_->sk_path.getBounds()); } bool DlPath::operator==(const DlPath& other) const { - return sk_path_ == other.sk_path_; + return data_->sk_path == other.data_->sk_path; } bool DlPath::IsConverted() const { - if (!path_.IsEmpty()) { - return true; - } - if (sk_path_.isEmpty()) { - return true; - } - return false; + return data_->path.has_value(); +} + +bool DlPath::IsVolatile() const { + return data_->sk_path.isVolatile(); } using Path = impeller::Path; diff --git a/engine/src/flutter/display_list/geometry/dl_path.h b/engine/src/flutter/display_list/geometry/dl_path.h index 21f600650d..1bdcfcb192 100644 --- a/engine/src/flutter/display_list/geometry/dl_path.h +++ b/engine/src/flutter/display_list/geometry/dl_path.h @@ -13,8 +13,10 @@ namespace flutter { class DlPath { public: - DlPath() = default; - explicit DlPath(const SkPath& path) : sk_path_(path) {} + static constexpr uint32_t kMaxVolatileUses = 2; + + DlPath() : data_(std::make_shared(SkPath())) {} + explicit DlPath(const SkPath& path) : data_(std::make_shared(path)) {} DlPath(const DlPath& path) = default; DlPath(DlPath&& path) = default; @@ -22,6 +24,14 @@ class DlPath { const SkPath& GetSkPath() const; impeller::Path GetPath() const; + /// Intent to render an SkPath multiple times will make the path + /// non-volatile to enable caching in Skia. Calling this method + /// before every rendering call that uses the SkPath will count + /// down the uses and eventually reset the volatile flag. + /// + /// @see |kMaxVolatileUses| + void WillRenderSkPath() const; + bool IsInverseFillType() const; bool IsRect(DlRect* rect, bool* is_closed = nullptr) const; @@ -35,12 +45,21 @@ class DlPath { DlRect GetBounds() const; bool operator==(const DlPath& other) const; + bool operator!=(const DlPath& other) const { return !(*this == other); } bool IsConverted() const; + bool IsVolatile() const; private: - const SkPath sk_path_; - mutable impeller::Path path_; + struct Data { + explicit Data(const SkPath& path) : sk_path(path) {} + + SkPath sk_path; + std::optional path; + uint32_t render_count = 0u; + }; + + std::shared_ptr data_; static impeller::Path ConvertToImpellerPath(const SkPath& path, const DlPoint& shift = DlPoint()); diff --git a/engine/src/flutter/display_list/geometry/dl_path_unittests.cc b/engine/src/flutter/display_list/geometry/dl_path_unittests.cc index f0d42be83f..ea8735f3c9 100644 --- a/engine/src/flutter/display_list/geometry/dl_path_unittests.cc +++ b/engine/src/flutter/display_list/geometry/dl_path_unittests.cc @@ -17,8 +17,10 @@ TEST(DisplayListPath, DefaultConstruction) { EXPECT_EQ(path.GetSkPath(), SkPath()); EXPECT_FALSE(path.IsInverseFillType()); - // Empty/default paths are always "pre-converted" by default. + EXPECT_FALSE(path.IsConverted()); + EXPECT_TRUE(path.GetPath().IsEmpty()); EXPECT_TRUE(path.IsConverted()); + EXPECT_FALSE(path.IsVolatile()); bool is_closed = false; EXPECT_FALSE(path.IsRect(nullptr)); @@ -45,8 +47,10 @@ TEST(DisplayListPath, ConstructFromEmpty) { EXPECT_EQ(path.GetSkPath(), SkPath()); EXPECT_FALSE(path.IsInverseFillType()); - // Empty/default paths are always "pre-converted" by default. + EXPECT_FALSE(path.IsConverted()); + EXPECT_TRUE(path.GetPath().IsEmpty()); EXPECT_TRUE(path.IsConverted()); + EXPECT_FALSE(path.IsVolatile()); bool is_closed = false; EXPECT_FALSE(path.IsRect(nullptr)); @@ -76,6 +80,7 @@ TEST(DisplayListPath, CopyConstruct) { EXPECT_FALSE(path2.IsInverseFillType()); EXPECT_FALSE(path2.IsConverted()); + EXPECT_FALSE(path2.IsVolatile()); bool is_closed = false; EXPECT_FALSE(path2.IsRect(nullptr)); @@ -94,6 +99,106 @@ TEST(DisplayListPath, CopyConstruct) { EXPECT_EQ(path2.GetSkBounds(), SkRect::MakeLTRB(10, 10, 20, 20)); } +TEST(DisplayListPath, ConstructFromVolatile) { + SkPath sk_path; + sk_path.setIsVolatile(true); + DlPath path(sk_path); + + EXPECT_EQ(path, DlPath()); + EXPECT_EQ(path.GetSkPath(), SkPath()); + + EXPECT_FALSE(path.IsInverseFillType()); + EXPECT_FALSE(path.IsConverted()); + EXPECT_TRUE(path.GetPath().IsEmpty()); + EXPECT_TRUE(path.IsConverted()); + EXPECT_TRUE(path.IsVolatile()); + + bool is_closed = false; + EXPECT_FALSE(path.IsRect(nullptr)); + EXPECT_FALSE(path.IsRect(nullptr, &is_closed)); + EXPECT_FALSE(is_closed); + EXPECT_FALSE(path.IsOval(nullptr)); + + is_closed = false; + EXPECT_FALSE(path.IsSkRect(nullptr)); + EXPECT_FALSE(path.IsSkRect(nullptr, &is_closed)); + EXPECT_FALSE(is_closed); + EXPECT_FALSE(path.IsSkOval(nullptr)); + EXPECT_FALSE(path.IsSkRRect(nullptr)); + + EXPECT_EQ(path.GetBounds(), DlRect()); + EXPECT_EQ(path.GetSkBounds(), SkRect()); +} + +TEST(DisplayListPath, VolatileBecomesNonVolatile) { + SkPath sk_path; + sk_path.setIsVolatile(true); + DlPath path(sk_path); + + EXPECT_TRUE(path.IsVolatile()); + + for (int i = 0; i < 1000; i++) { + // grabbing the Impeller version of the path does not make it non-volatile + path.GetPath(); + } + EXPECT_TRUE(path.IsVolatile()); + + for (int i = 0; i < 1000; i++) { + // not specifying intent to render does not make it non-volatile + path.GetSkPath(); + } + EXPECT_TRUE(path.IsVolatile()); + + for (uint32_t i = 0; i < DlPath::kMaxVolatileUses; i++) { + // Expressing intent to render will only be volatile the first few times + path.WillRenderSkPath(); + path.GetSkPath(); + EXPECT_TRUE(path.IsVolatile()); + } + + for (int i = 0; i < 1000; i++) { + // further uses without expressing intent to render do not make it + // non-volatile + path.GetSkPath(); + } + EXPECT_TRUE(path.IsVolatile()); + + // One last time makes the path non-volatile + path.WillRenderSkPath(); + path.GetSkPath(); + EXPECT_FALSE(path.IsVolatile()); +} + +TEST(DisplayListPath, MultipleVolatileCopiesBecomeNonVolatileTogether) { + SkPath sk_path; + sk_path.setIsVolatile(true); + DlPath path(sk_path); + const DlPath paths[4] = { + path, + path, + path, + path, + }; + + EXPECT_TRUE(path.IsVolatile()); + + for (uint32_t i = 0; i < DlPath::kMaxVolatileUses; i++) { + // Expressing intent to render will only be volatile the first few times + paths[i].WillRenderSkPath(); + EXPECT_TRUE(path.IsVolatile()); + for (const auto& p : paths) { + EXPECT_TRUE(p.IsVolatile()); + } + } + + // One last time makes the path non-volatile + paths[3].WillRenderSkPath(); + EXPECT_FALSE(path.IsVolatile()); + for (const auto& p : paths) { + EXPECT_FALSE(p.IsVolatile()); + } +} + TEST(DisplayListPath, EmbeddingSharedReference) { SkPath sk_path = SkPath::Oval(SkRect::MakeLTRB(10, 10, 20, 20)); DlPath path(sk_path); @@ -140,7 +245,7 @@ TEST(DisplayListPath, EmbeddingSharedReference) { ConversionSharingTester before_tester(path); EXPECT_FALSE(before_tester.Test(path, "Before triggering conversion")); EXPECT_FALSE(path.GetPath().IsEmpty()); - EXPECT_FALSE(before_tester.Test(path, "After conversion of source object")); + EXPECT_TRUE(before_tester.Test(path, "After conversion of source object")); EXPECT_FALSE(before_tester.ConvertAndTestEmpty()); EXPECT_TRUE(before_tester.Test(path, "After conversion of captured object")); diff --git a/engine/src/flutter/display_list/skia/dl_sk_canvas.h b/engine/src/flutter/display_list/skia/dl_sk_canvas.h index 9a0865b1de..4c1c550c2c 100644 --- a/engine/src/flutter/display_list/skia/dl_sk_canvas.h +++ b/engine/src/flutter/display_list/skia/dl_sk_canvas.h @@ -75,6 +75,10 @@ class DlSkCanvasAdapter final : public virtual DlCanvas { void ClipOval(const SkRect& bounds, ClipOp clip_op, bool is_aa) override; void ClipRRect(const SkRRect& rrect, ClipOp clip_op, bool is_aa) override; void ClipPath(const SkPath& path, ClipOp clip_op, bool is_aa) override; + void ClipPath(const DlPath& path, ClipOp clip_op, bool is_aa) override { + path.WillRenderSkPath(); + ClipPath(path.GetSkPath(), clip_op, is_aa); + } /// Conservative estimate of the bounds of all outstanding clip operations /// measured in the coordinate space within which this DisplayList will @@ -110,6 +114,10 @@ class DlSkCanvasAdapter final : public virtual DlCanvas { const SkRRect& inner, const DlPaint& paint) override; void DrawPath(const SkPath& path, const DlPaint& paint) override; + void DrawPath(const DlPath& path, const DlPaint& paint) override { + path.WillRenderSkPath(); + DrawPath(path.GetSkPath(), paint); + } void DrawArc(const SkRect& bounds, SkScalar start, SkScalar sweep, @@ -162,6 +170,14 @@ class DlSkCanvasAdapter final : public virtual DlCanvas { const SkScalar elevation, bool transparent_occluder, SkScalar dpr) override; + void DrawShadow(const DlPath& path, + const DlColor color, + const SkScalar elevation, + bool transparent_occluder, + SkScalar dpr) override { + path.WillRenderSkPath(); + DrawShadow(path.GetSkPath(), color, elevation, transparent_occluder, dpr); + } void Flush() override; diff --git a/engine/src/flutter/display_list/skia/dl_sk_dispatcher.cc b/engine/src/flutter/display_list/skia/dl_sk_dispatcher.cc index 8a47d88643..a7a2be7ce2 100644 --- a/engine/src/flutter/display_list/skia/dl_sk_dispatcher.cc +++ b/engine/src/flutter/display_list/skia/dl_sk_dispatcher.cc @@ -136,6 +136,7 @@ void DlSkCanvasDispatcher::clipRRect(const SkRRect& rrect, void DlSkCanvasDispatcher::clipPath(const DlPath& path, ClipOp clip_op, bool is_aa) { + path.WillRenderSkPath(); canvas_->clipPath(path.GetSkPath(), ToSk(clip_op), is_aa); } @@ -185,6 +186,7 @@ void DlSkCanvasDispatcher::drawDRRect(const SkRRect& outer, canvas_->drawDRRect(outer, inner, paint()); } void DlSkCanvasDispatcher::drawPath(const DlPath& path) { + path.WillRenderSkPath(); canvas_->drawPath(path.GetSkPath(), paint()); } void DlSkCanvasDispatcher::drawArc(const DlRect& bounds, @@ -333,6 +335,7 @@ void DlSkCanvasDispatcher::drawShadow(const DlPath& path, const DlScalar elevation, bool transparent_occluder, DlScalar dpr) { + path.WillRenderSkPath(); DrawShadow(canvas_, path.GetSkPath(), color, elevation, transparent_occluder, dpr); } diff --git a/engine/src/flutter/display_list/testing/dl_test_snippets.cc b/engine/src/flutter/display_list/testing/dl_test_snippets.cc index 38cdc133f9..05ca54dbd3 100644 --- a/engine/src/flutter/display_list/testing/dl_test_snippets.cc +++ b/engine/src/flutter/display_list/testing/dl_test_snippets.cc @@ -508,27 +508,27 @@ std::vector CreateAllClipOps() { }}, {"ClipPath", { - {1, 40, 0, + {1, 24, 0, [](DlOpReceiver& r) { r.clipPath(kTestPath1, DlCanvas::ClipOp::kIntersect, true); }}, - {1, 40, 0, + {1, 24, 0, [](DlOpReceiver& r) { r.clipPath(kTestPath2, DlCanvas::ClipOp::kIntersect, true); }}, - {1, 40, 0, + {1, 24, 0, [](DlOpReceiver& r) { r.clipPath(kTestPath3, DlCanvas::ClipOp::kIntersect, true); }}, - {1, 40, 0, + {1, 24, 0, [](DlOpReceiver& r) { r.clipPath(kTestPath1, DlCanvas::ClipOp::kIntersect, false); }}, - {1, 40, 0, + {1, 24, 0, [](DlOpReceiver& r) { r.clipPath(kTestPath1, DlCanvas::ClipOp::kDifference, true); }}, - {1, 40, 0, + {1, 24, 0, [](DlOpReceiver& r) { r.clipPath(kTestPath1, DlCanvas::ClipOp::kDifference, false); }}, @@ -697,13 +697,13 @@ std::vector CreateAllRenderingOps() { }}, {"DrawPath", { - {1, 40, 1, [](DlOpReceiver& r) { r.drawPath(kTestPath1); }}, - {1, 40, 1, [](DlOpReceiver& r) { r.drawPath(kTestPath2); }}, - {1, 40, 1, [](DlOpReceiver& r) { r.drawPath(kTestPath3); }}, + {1, 24, 1, [](DlOpReceiver& r) { r.drawPath(kTestPath1); }}, + {1, 24, 1, [](DlOpReceiver& r) { r.drawPath(kTestPath2); }}, + {1, 24, 1, [](DlOpReceiver& r) { r.drawPath(kTestPath3); }}, // oval, rect and rrect paths are left as drawPath - {1, 40, 1, [](DlOpReceiver& r) { r.drawPath(kTestPathRect); }}, - {1, 40, 1, [](DlOpReceiver& r) { r.drawPath(kTestPathOval); }}, - {1, 40, 1, [](DlOpReceiver& r) { r.drawPath(kTestPathRRect); }}, + {1, 24, 1, [](DlOpReceiver& r) { r.drawPath(kTestPathRect); }}, + {1, 24, 1, [](DlOpReceiver& r) { r.drawPath(kTestPathOval); }}, + {1, 24, 1, [](DlOpReceiver& r) { r.drawPath(kTestPathRRect); }}, }}, {"DrawArc", { @@ -1029,27 +1029,27 @@ std::vector CreateAllRenderingOps() { }}, {"DrawShadow", { - {1, 64, 1, + {1, 48, 1, [](DlOpReceiver& r) { r.drawShadow(kTestPath1, DlColor(SK_ColorGREEN), 1.0, false, 1.0); }}, - {1, 64, 1, + {1, 48, 1, [](DlOpReceiver& r) { r.drawShadow(kTestPath2, DlColor(SK_ColorGREEN), 1.0, false, 1.0); }}, - {1, 64, 1, + {1, 48, 1, [](DlOpReceiver& r) { r.drawShadow(kTestPath1, DlColor(SK_ColorBLUE), 1.0, false, 1.0); }}, - {1, 64, 1, + {1, 48, 1, [](DlOpReceiver& r) { r.drawShadow(kTestPath1, DlColor(SK_ColorGREEN), 2.0, false, 1.0); }}, - {1, 64, 1, + {1, 48, 1, [](DlOpReceiver& r) { r.drawShadow(kTestPath1, DlColor(SK_ColorGREEN), 1.0, true, 1.0); }}, - {1, 64, 1, + {1, 48, 1, [](DlOpReceiver& r) { r.drawShadow(kTestPath1, DlColor(SK_ColorGREEN), 1.0, false, 2.5); }}, diff --git a/engine/src/flutter/flow/layers/clip_path_layer.cc b/engine/src/flutter/flow/layers/clip_path_layer.cc index acd633a707..a5fb684499 100644 --- a/engine/src/flutter/flow/layers/clip_path_layer.cc +++ b/engine/src/flutter/flow/layers/clip_path_layer.cc @@ -6,15 +6,17 @@ namespace flutter { -ClipPathLayer::ClipPathLayer(const SkPath& clip_path, Clip clip_behavior) +ClipPathLayer::ClipPathLayer(const DlPath& clip_path, Clip clip_behavior) : ClipShapeLayer(clip_path, clip_behavior) {} const SkRect& ClipPathLayer::clip_shape_bounds() const { - return clip_shape().getBounds(); + return clip_shape().GetSkPath().getBounds(); } void ClipPathLayer::ApplyClip(LayerStateStack::MutatorContext& mutator) const { - mutator.clipPath(clip_shape(), clip_behavior() != Clip::kHardEdge); + clip_shape().WillRenderSkPath(); + mutator.clipPath(clip_shape().GetSkPath(), + clip_behavior() != Clip::kHardEdge); } } // namespace flutter diff --git a/engine/src/flutter/flow/layers/clip_path_layer.h b/engine/src/flutter/flow/layers/clip_path_layer.h index e183a48fd8..d03c829fd1 100644 --- a/engine/src/flutter/flow/layers/clip_path_layer.h +++ b/engine/src/flutter/flow/layers/clip_path_layer.h @@ -7,11 +7,13 @@ #include "flutter/flow/layers/clip_shape_layer.h" +#include "flutter/display_list/geometry/dl_path.h" + namespace flutter { -class ClipPathLayer : public ClipShapeLayer { +class ClipPathLayer : public ClipShapeLayer { public: - explicit ClipPathLayer(const SkPath& clip_path, + explicit ClipPathLayer(const DlPath& clip_path, Clip clip_behavior = Clip::kAntiAlias); protected: diff --git a/engine/src/flutter/flow/layers/clip_path_layer_unittests.cc b/engine/src/flutter/flow/layers/clip_path_layer_unittests.cc index 62ce30ce91..a8589ac6ce 100644 --- a/engine/src/flutter/flow/layers/clip_path_layer_unittests.cc +++ b/engine/src/flutter/flow/layers/clip_path_layer_unittests.cc @@ -26,12 +26,12 @@ using ClipOp = DlCanvas::ClipOp; #ifndef NDEBUG TEST_F(ClipPathLayerTest, ClipNoneBehaviorDies) { EXPECT_DEATH_IF_SUPPORTED( - auto clip = std::make_shared(SkPath(), Clip::kNone), + auto clip = std::make_shared(DlPath(), Clip::kNone), "clip_behavior != Clip::kNone"); } TEST_F(ClipPathLayerTest, PaintingEmptyLayerDies) { - auto layer = std::make_shared(SkPath(), Clip::kHardEdge); + auto layer = std::make_shared(DlPath(), Clip::kHardEdge); layer->Preroll(preroll_context()); @@ -50,7 +50,8 @@ TEST_F(ClipPathLayerTest, PaintingEmptyLayerDies) { TEST_F(ClipPathLayerTest, PaintBeforePrerollDies) { const SkRect layer_bounds = SkRect::MakeXYWH(0.5, 1.0, 5.0, 6.0); const SkPath layer_path = SkPath().addRect(layer_bounds); - auto layer = std::make_shared(layer_path, Clip::kHardEdge); + auto layer = + std::make_shared(DlPath(layer_path), Clip::kHardEdge); EXPECT_EQ(layer->paint_bounds(), kEmptyRect); EXPECT_EQ(layer->child_paint_bounds(), kEmptyRect); EXPECT_FALSE(layer->needs_painting(paint_context())); @@ -67,7 +68,8 @@ TEST_F(ClipPathLayerTest, PaintingCulledLayerDies) { const SkPath child_path = SkPath().addRect(child_bounds); const SkPath layer_path = SkPath().addRect(layer_bounds); auto mock_layer = std::make_shared(child_path); - auto layer = std::make_shared(layer_path, Clip::kHardEdge); + auto layer = + std::make_shared(DlPath(layer_path), Clip::kHardEdge); layer->Add(mock_layer); // Cull these children @@ -107,7 +109,8 @@ TEST_F(ClipPathLayerTest, ChildOutsideBounds) { const SkPath clip_path = SkPath().addRect(clip_bounds); const DlPaint child_paint = DlPaint(DlColor::kYellow()); auto mock_layer = std::make_shared(child_path, child_paint); - auto layer = std::make_shared(clip_path, Clip::kHardEdge); + auto layer = + std::make_shared(DlPath(clip_path), Clip::kHardEdge); layer->Add(mock_layer); SkRect clip_cull_rect = local_cull_bounds; @@ -152,7 +155,8 @@ TEST_F(ClipPathLayerTest, FullyContainedChild) { SkPath().addRect(layer_bounds).addOval(layer_bounds.makeInset(0.1, 0.1)); const DlPaint child_paint = DlPaint(DlColor::kYellow()); auto mock_layer = std::make_shared(child_path, child_paint); - auto layer = std::make_shared(layer_path, Clip::kHardEdge); + auto layer = + std::make_shared(DlPath(layer_path), Clip::kHardEdge); layer->Add(mock_layer); preroll_context()->state_stack.set_preroll_delegate(initial_matrix); @@ -198,7 +202,8 @@ TEST_F(ClipPathLayerTest, PartiallyContainedChild) { SkPath().addRect(clip_bounds).addOval(clip_bounds.makeInset(0.1, 0.1)); const DlPaint child_paint = DlPaint(DlColor::kYellow()); auto mock_layer = std::make_shared(child_path, child_paint); - auto layer = std::make_shared(clip_path, Clip::kHardEdge); + auto layer = + std::make_shared(DlPath(clip_path), Clip::kHardEdge); layer->Add(mock_layer); SkRect clip_cull_rect = local_cull_bounds; @@ -248,7 +253,8 @@ static bool ReadbackResult(PrerollContext* context, bool before) { const SkRect layer_bounds = SkRect::MakeXYWH(0.5, 1.0, 5.0, 6.0); const SkPath layer_path = SkPath().addRect(layer_bounds); - auto layer = std::make_shared(layer_path, clip_behavior); + auto layer = + std::make_shared(DlPath(layer_path), clip_behavior); if (child != nullptr) { layer->Add(child); } @@ -309,7 +315,7 @@ TEST_F(ClipPathLayerTest, OpacityInheritance) { .addRect(SkRect::MakeLTRB(5, 5, 25, 25)) .addOval(SkRect::MakeLTRB(20, 20, 40, 50)); auto clip_path_layer = - std::make_shared(layer_clip, Clip::kHardEdge); + std::make_shared(DlPath(layer_clip), Clip::kHardEdge); clip_path_layer->Add(mock1); // ClipRectLayer will pass through compatibility from a compatible child @@ -340,7 +346,7 @@ TEST_F(ClipPathLayerTest, OpacityInheritance) { { // ClipRectLayer(aa with saveLayer) will always be compatible auto clip_path_savelayer = std::make_shared( - layer_clip, Clip::kAntiAliasWithSaveLayer); + DlPath(layer_clip), Clip::kAntiAliasWithSaveLayer); clip_path_savelayer->Add(mock1); clip_path_savelayer->Add(mock2); @@ -361,7 +367,7 @@ TEST_F(ClipPathLayerTest, OpacityInheritance) { { // ClipRectLayer with incompatible child will not be compatible auto clip_path_bad_child = - std::make_shared(layer_clip, Clip::kHardEdge); + std::make_shared(DlPath(layer_clip), Clip::kHardEdge); clip_path_bad_child->Add(mock1); clip_path_bad_child->Add(mock2); @@ -381,7 +387,7 @@ TEST_F(ClipPathLayerTest, OpacityInheritance) { { // ClipRectLayer(aa with saveLayer) will always be compatible auto clip_path_savelayer_bad_child = std::make_shared( - layer_clip, Clip::kAntiAliasWithSaveLayer); + DlPath(layer_clip), Clip::kAntiAliasWithSaveLayer); clip_path_savelayer_bad_child->Add(mock1); clip_path_savelayer_bad_child->Add(mock2); @@ -405,7 +411,7 @@ TEST_F(ClipPathLayerTest, OpacityInheritancePainting) { .addRect(SkRect::MakeLTRB(5, 5, 25, 25)) .addOval(SkRect::MakeLTRB(45, 45, 55, 55)); auto clip_path_layer = - std::make_shared(layer_clip, Clip::kAntiAlias); + std::make_shared(DlPath(layer_clip), Clip::kAntiAlias); clip_path_layer->Add(mock1); clip_path_layer->Add(mock2); @@ -458,7 +464,7 @@ TEST_F(ClipPathLayerTest, OpacityInheritanceSaveLayerPainting) { .addRect(SkRect::MakeLTRB(5, 5, 25, 25)) .addOval(SkRect::MakeLTRB(20, 20, 40, 50)); auto clip_path_layer = std::make_shared( - layer_clip, Clip::kAntiAliasWithSaveLayer); + DlPath(layer_clip), Clip::kAntiAliasWithSaveLayer); clip_path_layer->Add(mock1); clip_path_layer->Add(mock2); @@ -507,7 +513,7 @@ TEST_F(ClipPathLayerTest, LayerCached) { auto layer_clip = SkPath() .addRect(SkRect::MakeLTRB(5, 5, 25, 25)) .addOval(SkRect::MakeLTRB(20, 20, 40, 50)); - auto layer = std::make_shared(layer_clip, + auto layer = std::make_shared(DlPath(layer_clip), Clip::kAntiAliasWithSaveLayer); layer->Add(mock1); @@ -552,7 +558,7 @@ TEST_F(ClipPathLayerTest, EmptyClipDoesNotCullPlatformView) { std::make_shared(view_offset, view_size, view_id); auto layer_clip = SkPath().addRect(kEmptyRect); - auto clip = std::make_shared(layer_clip, + auto clip = std::make_shared(DlPath(layer_clip), Clip::kAntiAliasWithSaveLayer); clip->Add(platform_view); diff --git a/engine/src/flutter/lib/ui/BUILD.gn b/engine/src/flutter/lib/ui/BUILD.gn index d831d88d15..87d99beef8 100644 --- a/engine/src/flutter/lib/ui/BUILD.gn +++ b/engine/src/flutter/lib/ui/BUILD.gn @@ -132,8 +132,6 @@ source_set("ui") { "text/paragraph_builder.h", "ui_dart_state.cc", "ui_dart_state.h", - "volatile_path_tracker.cc", - "volatile_path_tracker.h", "window/key_data.cc", "window/key_data.h", "window/key_data_packet.cc", diff --git a/engine/src/flutter/lib/ui/painting/path.cc b/engine/src/flutter/lib/ui/painting/path.cc index ddf2ebaac1..e04004f77e 100644 --- a/engine/src/flutter/lib/ui/painting/path.cc +++ b/engine/src/flutter/lib/ui/painting/path.cc @@ -22,56 +22,50 @@ typedef CanvasPath Path; IMPLEMENT_WRAPPERTYPEINFO(ui, Path); -CanvasPath::CanvasPath() - : path_tracker_(UIDartState::Current()->GetVolatilePathTracker()), - tracked_path_(std::make_shared()) { - FML_DCHECK(path_tracker_); +CanvasPath::CanvasPath() { + sk_path_.setIsVolatile( + !UIDartState::Current()->IsDeterministicRenderingEnabled()); resetVolatility(); } CanvasPath::~CanvasPath() = default; void CanvasPath::resetVolatility() { - if (!tracked_path_->tracking_volatility) { - mutable_path().setIsVolatile(true); - tracked_path_->frame_count = 0; - tracked_path_->tracking_volatility = true; - path_tracker_->Track(tracked_path_); - } + dl_path_.reset(); } int CanvasPath::getFillType() { - return static_cast(path().getFillType()); + return static_cast(sk_path_.getFillType()); } void CanvasPath::setFillType(int fill_type) { - mutable_path().setFillType(static_cast(fill_type)); + sk_path_.setFillType(static_cast(fill_type)); resetVolatility(); } void CanvasPath::moveTo(double x, double y) { - mutable_path().moveTo(SafeNarrow(x), SafeNarrow(y)); + sk_path_.moveTo(SafeNarrow(x), SafeNarrow(y)); resetVolatility(); } void CanvasPath::relativeMoveTo(double x, double y) { - mutable_path().rMoveTo(SafeNarrow(x), SafeNarrow(y)); + sk_path_.rMoveTo(SafeNarrow(x), SafeNarrow(y)); resetVolatility(); } void CanvasPath::lineTo(double x, double y) { - mutable_path().lineTo(SafeNarrow(x), SafeNarrow(y)); + sk_path_.lineTo(SafeNarrow(x), SafeNarrow(y)); resetVolatility(); } void CanvasPath::relativeLineTo(double x, double y) { - mutable_path().rLineTo(SafeNarrow(x), SafeNarrow(y)); + sk_path_.rLineTo(SafeNarrow(x), SafeNarrow(y)); resetVolatility(); } void CanvasPath::quadraticBezierTo(double x1, double y1, double x2, double y2) { - mutable_path().quadTo(SafeNarrow(x1), SafeNarrow(y1), SafeNarrow(x2), - SafeNarrow(y2)); + sk_path_.quadTo(SafeNarrow(x1), SafeNarrow(y1), SafeNarrow(x2), + SafeNarrow(y2)); resetVolatility(); } @@ -79,8 +73,8 @@ void CanvasPath::relativeQuadraticBezierTo(double x1, double y1, double x2, double y2) { - mutable_path().rQuadTo(SafeNarrow(x1), SafeNarrow(y1), SafeNarrow(x2), - SafeNarrow(y2)); + sk_path_.rQuadTo(SafeNarrow(x1), SafeNarrow(y1), SafeNarrow(x2), + SafeNarrow(y2)); resetVolatility(); } @@ -90,8 +84,8 @@ void CanvasPath::cubicTo(double x1, double y2, double x3, double y3) { - mutable_path().cubicTo(SafeNarrow(x1), SafeNarrow(y1), SafeNarrow(x2), - SafeNarrow(y2), SafeNarrow(x3), SafeNarrow(y3)); + sk_path_.cubicTo(SafeNarrow(x1), SafeNarrow(y1), SafeNarrow(x2), + SafeNarrow(y2), SafeNarrow(x3), SafeNarrow(y3)); resetVolatility(); } @@ -101,14 +95,14 @@ void CanvasPath::relativeCubicTo(double x1, double y2, double x3, double y3) { - mutable_path().rCubicTo(SafeNarrow(x1), SafeNarrow(y1), SafeNarrow(x2), - SafeNarrow(y2), SafeNarrow(x3), SafeNarrow(y3)); + sk_path_.rCubicTo(SafeNarrow(x1), SafeNarrow(y1), SafeNarrow(x2), + SafeNarrow(y2), SafeNarrow(x3), SafeNarrow(y3)); resetVolatility(); } void CanvasPath::conicTo(double x1, double y1, double x2, double y2, double w) { - mutable_path().conicTo(SafeNarrow(x1), SafeNarrow(y1), SafeNarrow(x2), - SafeNarrow(y2), SafeNarrow(w)); + sk_path_.conicTo(SafeNarrow(x1), SafeNarrow(y1), SafeNarrow(x2), + SafeNarrow(y2), SafeNarrow(w)); resetVolatility(); } @@ -117,8 +111,8 @@ void CanvasPath::relativeConicTo(double x1, double x2, double y2, double w) { - mutable_path().rConicTo(SafeNarrow(x1), SafeNarrow(y1), SafeNarrow(x2), - SafeNarrow(y2), SafeNarrow(w)); + sk_path_.rConicTo(SafeNarrow(x1), SafeNarrow(y1), SafeNarrow(x2), + SafeNarrow(y2), SafeNarrow(w)); resetVolatility(); } @@ -129,11 +123,11 @@ void CanvasPath::arcTo(double left, double startAngle, double sweepAngle, bool forceMoveTo) { - mutable_path().arcTo( - SkRect::MakeLTRB(SafeNarrow(left), SafeNarrow(top), SafeNarrow(right), - SafeNarrow(bottom)), - SafeNarrow(startAngle) * 180.0f / static_cast(M_PI), - SafeNarrow(sweepAngle) * 180.0f / static_cast(M_PI), forceMoveTo); + sk_path_.arcTo(SkRect::MakeLTRB(SafeNarrow(left), SafeNarrow(top), + SafeNarrow(right), SafeNarrow(bottom)), + SafeNarrow(startAngle) * 180.0f / static_cast(M_PI), + SafeNarrow(sweepAngle) * 180.0f / static_cast(M_PI), + forceMoveTo); resetVolatility(); } @@ -149,9 +143,9 @@ void CanvasPath::arcToPoint(double arcEndX, const auto direction = isClockwiseDirection ? SkPathDirection::kCW : SkPathDirection::kCCW; - mutable_path().arcTo(SafeNarrow(radiusX), SafeNarrow(radiusY), - SafeNarrow(xAxisRotation), arcSize, direction, - SafeNarrow(arcEndX), SafeNarrow(arcEndY)); + sk_path_.arcTo(SafeNarrow(radiusX), SafeNarrow(radiusY), + SafeNarrow(xAxisRotation), arcSize, direction, + SafeNarrow(arcEndX), SafeNarrow(arcEndY)); resetVolatility(); } @@ -166,23 +160,21 @@ void CanvasPath::relativeArcToPoint(double arcEndDeltaX, : SkPath::ArcSize::kSmall_ArcSize; const auto direction = isClockwiseDirection ? SkPathDirection::kCW : SkPathDirection::kCCW; - mutable_path().rArcTo(SafeNarrow(radiusX), SafeNarrow(radiusY), - SafeNarrow(xAxisRotation), arcSize, direction, - SafeNarrow(arcEndDeltaX), SafeNarrow(arcEndDeltaY)); + sk_path_.rArcTo(SafeNarrow(radiusX), SafeNarrow(radiusY), + SafeNarrow(xAxisRotation), arcSize, direction, + SafeNarrow(arcEndDeltaX), SafeNarrow(arcEndDeltaY)); resetVolatility(); } void CanvasPath::addRect(double left, double top, double right, double bottom) { - mutable_path().addRect(SkRect::MakeLTRB(SafeNarrow(left), SafeNarrow(top), - SafeNarrow(right), - SafeNarrow(bottom))); + sk_path_.addRect(SkRect::MakeLTRB(SafeNarrow(left), SafeNarrow(top), + SafeNarrow(right), SafeNarrow(bottom))); resetVolatility(); } void CanvasPath::addOval(double left, double top, double right, double bottom) { - mutable_path().addOval(SkRect::MakeLTRB(SafeNarrow(left), SafeNarrow(top), - SafeNarrow(right), - SafeNarrow(bottom))); + sk_path_.addOval(SkRect::MakeLTRB(SafeNarrow(left), SafeNarrow(top), + SafeNarrow(right), SafeNarrow(bottom))); resetVolatility(); } @@ -192,22 +184,21 @@ void CanvasPath::addArc(double left, double bottom, double startAngle, double sweepAngle) { - mutable_path().addArc( - SkRect::MakeLTRB(SafeNarrow(left), SafeNarrow(top), SafeNarrow(right), - SafeNarrow(bottom)), - SafeNarrow(startAngle) * 180.0f / static_cast(M_PI), - SafeNarrow(sweepAngle) * 180.0f / static_cast(M_PI)); + sk_path_.addArc(SkRect::MakeLTRB(SafeNarrow(left), SafeNarrow(top), + SafeNarrow(right), SafeNarrow(bottom)), + SafeNarrow(startAngle) * 180.0f / static_cast(M_PI), + SafeNarrow(sweepAngle) * 180.0f / static_cast(M_PI)); resetVolatility(); } void CanvasPath::addPolygon(const tonic::Float32List& points, bool close) { - mutable_path().addPoly(reinterpret_cast(points.data()), - points.num_elements() / 2, close); + sk_path_.addPoly(reinterpret_cast(points.data()), + points.num_elements() / 2, close); resetVolatility(); } void CanvasPath::addRRect(const RRect& rrect) { - mutable_path().addRRect(rrect.sk_rrect); + sk_path_.addRRect(rrect.sk_rrect); resetVolatility(); } @@ -216,8 +207,8 @@ void CanvasPath::addPath(CanvasPath* path, double dx, double dy) { Dart_ThrowException(ToDart("Path.addPath called with non-genuine Path.")); return; } - mutable_path().addPath(path->path(), SafeNarrow(dx), SafeNarrow(dy), - SkPath::kAppend_AddPathMode); + sk_path_.addPath(path->sk_path_, SafeNarrow(dx), SafeNarrow(dy), + SkPath::kAppend_AddPathMode); resetVolatility(); } @@ -238,7 +229,7 @@ void CanvasPath::addPathWithMatrix(CanvasPath* path, matrix4.Release(); matrix.setTranslateX(matrix.getTranslateX() + SafeNarrow(dx)); matrix.setTranslateY(matrix.getTranslateY() + SafeNarrow(dy)); - mutable_path().addPath(path->path(), matrix, SkPath::kAppend_AddPathMode); + sk_path_.addPath(path->sk_path_, matrix, SkPath::kAppend_AddPathMode); resetVolatility(); } @@ -248,8 +239,8 @@ void CanvasPath::extendWithPath(CanvasPath* path, double dx, double dy) { ToDart("Path.extendWithPath called with non-genuine Path.")); return; } - mutable_path().addPath(path->path(), SafeNarrow(dx), SafeNarrow(dy), - SkPath::kExtend_AddPathMode); + sk_path_.addPath(path->sk_path_, SafeNarrow(dx), SafeNarrow(dy), + SkPath::kExtend_AddPathMode); resetVolatility(); } @@ -270,28 +261,28 @@ void CanvasPath::extendWithPathAndMatrix(CanvasPath* path, matrix4.Release(); matrix.setTranslateX(matrix.getTranslateX() + SafeNarrow(dx)); matrix.setTranslateY(matrix.getTranslateY() + SafeNarrow(dy)); - mutable_path().addPath(path->path(), matrix, SkPath::kExtend_AddPathMode); + sk_path_.addPath(path->sk_path_, matrix, SkPath::kExtend_AddPathMode); resetVolatility(); } void CanvasPath::close() { - mutable_path().close(); + sk_path_.close(); resetVolatility(); } void CanvasPath::reset() { - mutable_path().reset(); + sk_path_.reset(); resetVolatility(); } bool CanvasPath::contains(double x, double y) { - return path().contains(SafeNarrow(x), SafeNarrow(y)); + return sk_path_.contains(SafeNarrow(x), SafeNarrow(y)); } void CanvasPath::shift(Dart_Handle path_handle, double dx, double dy) { fml::RefPtr path = Create(path_handle); - auto& other_mutable_path = path->mutable_path(); - mutable_path().offset(SafeNarrow(dx), SafeNarrow(dy), &other_mutable_path); + auto& other_mutable_path = path->sk_path_; + sk_path_.offset(SafeNarrow(dx), SafeNarrow(dy), &other_mutable_path); resetVolatility(); } @@ -301,13 +292,13 @@ void CanvasPath::transform(Dart_Handle path_handle, auto sk_matrix = ToSkMatrix(matrix4); matrix4.Release(); fml::RefPtr path = Create(path_handle); - auto& other_mutable_path = path->mutable_path(); - mutable_path().transform(sk_matrix, &other_mutable_path); + auto& other_mutable_path = path->sk_path_; + sk_path_.transform(sk_matrix, &other_mutable_path); } tonic::Float32List CanvasPath::getBounds() { tonic::Float32List rect(Dart_NewTypedData(Dart_TypedData_kFloat32, 4)); - const SkRect& bounds = path().getBounds(); + const SkRect& bounds = sk_path_.getBounds(); rect[0] = bounds.left(); rect[1] = bounds.top(); rect[2] = bounds.right(); @@ -316,8 +307,8 @@ tonic::Float32List CanvasPath::getBounds() { } bool CanvasPath::op(CanvasPath* path1, CanvasPath* path2, int operation) { - bool result = Op(path1->path(), path2->path(), - static_cast(operation), &tracked_path_->path); + bool result = Op(path1->sk_path_, path2->sk_path_, + static_cast(operation), &sk_path_); resetVolatility(); return result; } @@ -326,7 +317,14 @@ void CanvasPath::clone(Dart_Handle path_handle) { fml::RefPtr path = Create(path_handle); // per Skia docs, this will create a fast copy // data is shared until the source path or dest path are mutated - path->mutable_path() = this->path(); + path->sk_path_ = this->sk_path_; +} + +const DlPath& CanvasPath::path() const { + if (!dl_path_.has_value()) { + dl_path_.emplace(sk_path_); + } + return dl_path_.value(); } } // namespace flutter diff --git a/engine/src/flutter/lib/ui/painting/path.h b/engine/src/flutter/lib/ui/painting/path.h index c1a30eb6d3..3cc2342d61 100644 --- a/engine/src/flutter/lib/ui/painting/path.h +++ b/engine/src/flutter/lib/ui/painting/path.h @@ -8,7 +8,6 @@ #include "flutter/lib/ui/dart_wrapper.h" #include "flutter/lib/ui/painting/rrect.h" #include "flutter/lib/ui/ui_dart_state.h" -#include "flutter/lib/ui/volatile_path_tracker.h" #include "third_party/skia/include/core/SkPath.h" #include "third_party/skia/include/pathops/SkPathOps.h" #include "third_party/tonic/typed_data/typed_list.h" @@ -25,7 +24,7 @@ class CanvasPath : public RefCountedDartWrappable { static void CreateFrom(Dart_Handle path_handle, const SkPath& src) { auto path = fml::MakeRefCounted(); path->AssociateWithDartWrapper(path_handle); - path->tracked_path_->path = src; + path->sk_path_ = src; } static fml::RefPtr Create(Dart_Handle wrapper) { @@ -114,18 +113,16 @@ class CanvasPath : public RefCountedDartWrappable { bool op(CanvasPath* path1, CanvasPath* path2, int operation); void clone(Dart_Handle path_handle); - const SkPath& path() const { return tracked_path_->path; } + const DlPath& path() const; private: CanvasPath(); - std::shared_ptr path_tracker_; - std::shared_ptr tracked_path_; + SkPath sk_path_; + mutable std::optional dl_path_; // Must be called whenever the path is created or mutated. void resetVolatility(); - - SkPath& mutable_path() { return tracked_path_->path; } }; } // namespace flutter diff --git a/engine/src/flutter/lib/ui/painting/path_measure.cc b/engine/src/flutter/lib/ui/painting/path_measure.cc index d6498fdf98..3229eb99e6 100644 --- a/engine/src/flutter/lib/ui/painting/path_measure.cc +++ b/engine/src/flutter/lib/ui/painting/path_measure.cc @@ -27,7 +27,7 @@ void CanvasPathMeasure::Create(Dart_Handle wrapper, fml::RefPtr pathMeasure = fml::MakeRefCounted(); if (path) { - const SkPath& skPath = path->path(); + const SkPath& skPath = path->path().GetSkPath(); SkScalar resScale = 1; pathMeasure->path_measure_ = std::make_unique(skPath, forceClosed, resScale); @@ -42,8 +42,7 @@ CanvasPathMeasure::CanvasPathMeasure() {} CanvasPathMeasure::~CanvasPathMeasure() {} void CanvasPathMeasure::setPath(const CanvasPath* path, bool isClosed) { - const SkPath& skPath = path->path(); - path_measure_->reset(skPath, isClosed); + path_measure_->reset(path->path().GetSkPath(), isClosed); } double CanvasPathMeasure::getLength(int contour_index) { diff --git a/engine/src/flutter/lib/ui/painting/path_unittests.cc b/engine/src/flutter/lib/ui/painting/path_unittests.cc index f02b72ff5a..f45d43105a 100644 --- a/engine/src/flutter/lib/ui/painting/path_unittests.cc +++ b/engine/src/flutter/lib/ui/painting/path_unittests.cc @@ -27,73 +27,37 @@ TEST_F(ShellTest, PathVolatilityOldPathsBecomeNonVolatile) { EXPECT_FALSE(Dart_IsError(result)); CanvasPath* path = reinterpret_cast(peer); EXPECT_TRUE(path); - EXPECT_TRUE(path->path().isVolatile()); - std::shared_ptr tracker = - UIDartState::Current()->GetVolatilePathTracker(); - EXPECT_TRUE(tracker); - for (int i = 0; i < VolatilePathTracker::kFramesOfVolatility; i++) { - EXPECT_TRUE(path->path().isVolatile()); - tracker->OnFrame(); + for (uint32_t i = 0; i <= DlPath::kMaxVolatileUses * 2; i++) { + EXPECT_TRUE(path->path().IsVolatile()); + EXPECT_TRUE(path->path().GetSkPath().isVolatile()); + // Getting the SkPath without expressing intent for rendering will not + // progress towards non-volatility } - EXPECT_FALSE(path->path().isVolatile()); - message_latch->Signal(); - }; + EXPECT_TRUE(path->path().IsVolatile()); + EXPECT_TRUE(path->path().GetSkPath().isVolatile()); - Settings settings = CreateSettingsForFixture(); - TaskRunners task_runners("test", // label - GetCurrentTaskRunner(), // platform - CreateNewThread(), // raster - CreateNewThread(), // ui - CreateNewThread() // io - ); + for (uint32_t i = 0; i < DlPath::kMaxVolatileUses; i++) { + path->path().WillRenderSkPath(); + EXPECT_TRUE(path->path().IsVolatile()); + EXPECT_TRUE(path->path().GetSkPath().isVolatile()); + } + // One last intent to render will make it non-volatile + path->path().WillRenderSkPath(); + EXPECT_FALSE(path->path().IsVolatile()); + EXPECT_FALSE(path->path().GetSkPath().isVolatile()); - AddNativeCallback("ValidatePath", CREATE_NATIVE_ENTRY(native_validate_path)); + DlPath saved_path = path->path(); + path->addOval(10, 10, 20, 20); - std::unique_ptr shell = CreateShell(settings, task_runners); + // Meanwhile if the path being constructed by the CanvasPath object + // is changed further, new paths extracted via path() are again volatile. + EXPECT_TRUE(path->path().IsVolatile()); + EXPECT_TRUE(path->path().GetSkPath().isVolatile()); - ASSERT_TRUE(shell->IsSetup()); - auto configuration = RunConfiguration::InferFromSettings(settings); - configuration.SetEntrypoint("createPath"); - - shell->RunEngine(std::move(configuration), [](auto result) { - ASSERT_EQ(result, Engine::RunStatus::Success); - }); - - message_latch->Wait(); - - DestroyShell(std::move(shell), task_runners); -} - -TEST_F(ShellTest, PathVolatilityGCRemovesPathFromTracker) { - static_assert(VolatilePathTracker::kFramesOfVolatility > 1); - auto message_latch = std::make_shared(); - - auto native_validate_path = [message_latch](Dart_NativeArguments args) { - auto handle = Dart_GetNativeArgument(args, 0); - intptr_t peer = 0; - Dart_Handle result = Dart_GetNativeInstanceField( - handle, tonic::DartWrappable::kPeerIndex, &peer); - EXPECT_FALSE(Dart_IsError(result)); - CanvasPath* path = reinterpret_cast(peer); - EXPECT_TRUE(path); - EXPECT_TRUE(path->path().isVolatile()); - std::shared_ptr tracker = - UIDartState::Current()->GetVolatilePathTracker(); - EXPECT_TRUE(tracker); - EXPECT_EQ(GetLiveTrackedPathCount(tracker), 1ul); - EXPECT_TRUE(path->path().isVolatile()); - - tracker->OnFrame(); - EXPECT_EQ(GetLiveTrackedPathCount(tracker), 1ul); - EXPECT_TRUE(path->path().isVolatile()); - - // simulate GC - path->Release(); - EXPECT_EQ(GetLiveTrackedPathCount(tracker), 0ul); - - tracker->OnFrame(); - EXPECT_EQ(GetLiveTrackedPathCount(tracker), 0ul); + // But the saved versions copied before the changes are still non-volatile + EXPECT_FALSE(saved_path.IsVolatile()); + EXPECT_FALSE(saved_path.GetSkPath().isVolatile()); message_latch->Signal(); }; @@ -139,17 +103,15 @@ TEST_F(ShellTest, DeterministicRenderingDisablesPathVolatility) { EXPECT_FALSE(Dart_IsError(result)); CanvasPath* path = reinterpret_cast(peer); EXPECT_TRUE(path); - EXPECT_FALSE(path->path().isVolatile()); - std::shared_ptr tracker = - UIDartState::Current()->GetVolatilePathTracker(); - EXPECT_TRUE(tracker); - EXPECT_FALSE(tracker->enabled()); - for (int i = 0; i < VolatilePathTracker::kFramesOfVolatility; i++) { - tracker->OnFrame(); - EXPECT_FALSE(path->path().isVolatile()); + for (uint32_t i = 0; i <= DlPath::kMaxVolatileUses * 2; i++) { + EXPECT_FALSE(path->path().IsVolatile()); + EXPECT_FALSE(path->path().GetSkPath().isVolatile()); + path->path().WillRenderSkPath(); } - EXPECT_FALSE(path->path().isVolatile()); + EXPECT_FALSE(path->path().IsVolatile()); + EXPECT_FALSE(path->path().GetSkPath().isVolatile()); + message_latch->Signal(); }; diff --git a/engine/src/flutter/lib/ui/ui_benchmarks.cc b/engine/src/flutter/lib/ui/ui_benchmarks.cc index 91d109c5e6..097fe908e9 100644 --- a/engine/src/flutter/lib/ui/ui_benchmarks.cc +++ b/engine/src/flutter/lib/ui/ui_benchmarks.cc @@ -4,7 +4,6 @@ #include "flutter/benchmarking/benchmarking.h" #include "flutter/common/settings.h" -#include "flutter/lib/ui/volatile_path_tracker.h" #include "flutter/lib/ui/window/platform_message_response_dart.h" #include "flutter/runtime/dart_vm_lifecycle.h" #include "flutter/shell/common/thread_host.h" @@ -67,54 +66,7 @@ static void BM_PlatformMessageResponseDartComplete(benchmark::State& state) { } } -static void BM_PathVolatilityTracker(benchmark::State& state) { - ThreadHost thread_host(ThreadHost::ThreadHostConfig( - "test", ThreadHost::Type::kPlatform | ThreadHost::Type::kRaster | - ThreadHost::Type::kIo | ThreadHost::Type::kUi)); - TaskRunners task_runners("test", thread_host.platform_thread->GetTaskRunner(), - thread_host.raster_thread->GetTaskRunner(), - thread_host.ui_thread->GetTaskRunner(), - thread_host.io_thread->GetTaskRunner()); - - VolatilePathTracker tracker(task_runners.GetUITaskRunner(), true); - - while (state.KeepRunning()) { - std::vector> paths; - constexpr int path_count = 1000; - for (int i = 0; i < path_count; i++) { - auto path = std::make_shared(); - path->path = SkPath(); - path->path.setIsVolatile(true); - paths.push_back(std::move(path)); - } - - fml::AutoResetWaitableEvent latch; - task_runners.GetUITaskRunner()->PostTask([&]() { - for (const auto& path : paths) { - tracker.Track(path); - } - latch.Signal(); - }); - - latch.Wait(); - - task_runners.GetUITaskRunner()->PostTask([&]() { tracker.OnFrame(); }); - - for (int i = 0; i < path_count - 10; ++i) { - paths[i].reset(); - } - - task_runners.GetUITaskRunner()->PostTask([&]() { tracker.OnFrame(); }); - - latch.Reset(); - task_runners.GetUITaskRunner()->PostTask([&]() { latch.Signal(); }); - latch.Wait(); - } -} - BENCHMARK(BM_PlatformMessageResponseDartComplete) ->Unit(benchmark::kMicrosecond); -BENCHMARK(BM_PathVolatilityTracker)->Unit(benchmark::kMillisecond); - } // namespace flutter diff --git a/engine/src/flutter/lib/ui/ui_dart_state.cc b/engine/src/flutter/lib/ui/ui_dart_state.cc index b9a3a9ecf8..7440a88b24 100644 --- a/engine/src/flutter/lib/ui/ui_dart_state.cc +++ b/engine/src/flutter/lib/ui/ui_dart_state.cc @@ -38,7 +38,7 @@ UIDartState::Context::Context( fml::WeakPtr image_generator_registry, std::string advisory_script_uri, std::string advisory_script_entrypoint, - std::shared_ptr volatile_path_tracker, + bool deterministic_rendering_enabled, std::shared_ptr concurrent_task_runner, bool enable_impeller, impeller::RuntimeStageBackend runtime_stage_backend) @@ -50,7 +50,7 @@ UIDartState::Context::Context( image_generator_registry(std::move(image_generator_registry)), advisory_script_uri(std::move(advisory_script_uri)), advisory_script_entrypoint(std::move(advisory_script_entrypoint)), - volatile_path_tracker(std::move(volatile_path_tracker)), + deterministic_rendering_enabled(deterministic_rendering_enabled), concurrent_task_runner(std::move(concurrent_task_runner)), enable_impeller(enable_impeller), runtime_stage_backend(runtime_stage_backend) {} @@ -83,6 +83,10 @@ const std::string& UIDartState::GetAdvisoryScriptURI() const { return context_.advisory_script_uri; } +bool UIDartState::IsDeterministicRenderingEnabled() const { + return context_.deterministic_rendering_enabled; +} + bool UIDartState::IsImpellerEnabled() const { return context_.enable_impeller; } @@ -148,11 +152,6 @@ fml::RefPtr UIDartState::GetSkiaUnrefQueue() const { return context_.unref_queue; } -std::shared_ptr UIDartState::GetVolatilePathTracker() - const { - return context_.volatile_path_tracker; -} - std::shared_ptr UIDartState::GetConcurrentTaskRunner() const { return context_.concurrent_task_runner; diff --git a/engine/src/flutter/lib/ui/ui_dart_state.h b/engine/src/flutter/lib/ui/ui_dart_state.h index bfeb053fbe..3ce014f44f 100644 --- a/engine/src/flutter/lib/ui/ui_dart_state.h +++ b/engine/src/flutter/lib/ui/ui_dart_state.h @@ -18,7 +18,6 @@ #include "flutter/lib/ui/isolate_name_server/isolate_name_server.h" #include "flutter/lib/ui/painting/image_decoder.h" #include "flutter/lib/ui/snapshot_delegate.h" -#include "flutter/lib/ui/volatile_path_tracker.h" #include "flutter/shell/common/platform_message_handler.h" #include "impeller/runtime_stage/runtime_stage.h" #include "third_party/dart/runtime/include/dart_api.h" @@ -53,7 +52,7 @@ class UIDartState : public tonic::DartState { fml::WeakPtr image_generator_registry, std::string advisory_script_uri, std::string advisory_script_entrypoint, - std::shared_ptr volatile_path_tracker, + bool deterministic_rendering_enabled, std::shared_ptr concurrent_task_runner, bool enable_impeller, impeller::RuntimeStageBackend runtime_stage_backend); @@ -92,8 +91,8 @@ class UIDartState : public tonic::DartState { /// transitioned to the running state explicitly by the caller. std::string advisory_script_entrypoint; - /// Cache for tracking path volatility. - std::shared_ptr volatile_path_tracker; + /// Whether deterministic rendering practices should be used. + bool deterministic_rendering_enabled = false; /// The task runner whose tasks may be executed concurrently on a pool /// of shared worker threads. @@ -135,8 +134,6 @@ class UIDartState : public tonic::DartState { fml::RefPtr GetSkiaUnrefQueue() const; - std::shared_ptr GetVolatilePathTracker() const; - std::shared_ptr GetConcurrentTaskRunner() const; fml::TaskRunnerAffineWeakPtr GetSnapshotDelegate() const; @@ -165,6 +162,9 @@ class UIDartState : public tonic::DartState { /// Returns `0` if called from a non-root isolate. int64_t GetRootIsolateToken() const; + /// Whether deterministic rendering practices are enabled for this application + bool IsDeterministicRenderingEnabled() const; + /// Whether Impeller is enabled for this application. bool IsImpellerEnabled() const; diff --git a/engine/src/flutter/lib/ui/volatile_path_tracker.cc b/engine/src/flutter/lib/ui/volatile_path_tracker.cc deleted file mode 100644 index ce2556ad66..0000000000 --- a/engine/src/flutter/lib/ui/volatile_path_tracker.cc +++ /dev/null @@ -1,50 +0,0 @@ -// Copyright 2013 The Flutter Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "flutter/lib/ui/volatile_path_tracker.h" - -#include - -namespace flutter { - -VolatilePathTracker::VolatilePathTracker( - fml::RefPtr ui_task_runner, - bool enabled) - : ui_task_runner_(std::move(ui_task_runner)), enabled_(enabled) {} - -void VolatilePathTracker::Track(const std::shared_ptr& path) { - FML_DCHECK(ui_task_runner_->RunsTasksOnCurrentThread()); - FML_DCHECK(path); - FML_DCHECK(path->path.isVolatile()); - if (!enabled_) { - path->path.setIsVolatile(false); - return; - } - paths_.push_back(path); -} - -void VolatilePathTracker::OnFrame() { - FML_DCHECK(ui_task_runner_->RunsTasksOnCurrentThread()); - if (!enabled_) { - return; - } - - paths_.erase(std::remove_if(paths_.begin(), paths_.end(), - [](const std::weak_ptr& weak_path) { - auto path = weak_path.lock(); - if (!path) { - return true; - } - path->frame_count++; - if (path->frame_count >= kFramesOfVolatility) { - path->path.setIsVolatile(false); - path->tracking_volatility = false; - return true; - } - return false; - }), - paths_.end()); -} - -} // namespace flutter diff --git a/engine/src/flutter/lib/ui/volatile_path_tracker.h b/engine/src/flutter/lib/ui/volatile_path_tracker.h deleted file mode 100644 index aadad44057..0000000000 --- a/engine/src/flutter/lib/ui/volatile_path_tracker.h +++ /dev/null @@ -1,79 +0,0 @@ -// Copyright 2013 The Flutter Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef FLUTTER_LIB_UI_VOLATILE_PATH_TRACKER_H_ -#define FLUTTER_LIB_UI_VOLATILE_PATH_TRACKER_H_ - -#include -#include -#include -#include - -#include "flutter/fml/macros.h" -#include "flutter/fml/task_runner.h" -#include "flutter/fml/trace_event.h" -#include "third_party/skia/include/core/SkPath.h" - -namespace flutter { - -namespace testing { -class ShellTest; -} // namespace testing - -/// A cache for paths drawn from dart:ui. -/// -/// Whenever a flutter::CanvasPath is created, it must Insert an entry into -/// this cache. Whenever a frame is drawn, the shell must call OnFrame. The -/// cache will flip the volatility bit on the SkPath and remove it from the -/// cache. If the Dart object is released, Erase must be called to avoid -/// tracking a path that is no longer referenced in Dart code. -/// -/// Enabling this cache may cause difficult to predict minor pixel differences -/// when paths are rendered. If deterministic rendering is needed, e.g. for a -/// screen diffing test, this class will not cache any paths and will -/// automatically set the volatility of the path to false. -class VolatilePathTracker { - public: - /// The fields of this struct must only accessed on the UI task runner. - struct TrackedPath { - bool tracking_volatility = false; - int frame_count = 0; - SkPath path; - }; - - VolatilePathTracker(fml::RefPtr ui_task_runner, - bool enabled); - - static constexpr int kFramesOfVolatility = 2; - - // Starts tracking a path. - // Must be called from the UI task runner. - // - // Callers should only insert paths that are currently volatile. - void Track(const std::shared_ptr& path); - - // Called by the shell at the end of a frame after notifying Dart about idle - // time. - // - // This method will flip the volatility bit to false for any paths that have - // survived the |kFramesOfVolatility|. - // - // Must be called from the UI task runner. - void OnFrame(); - - bool enabled() const { return enabled_; } - - private: - fml::RefPtr ui_task_runner_; - std::vector> paths_; - bool enabled_ = true; - - friend class testing::ShellTest; - - FML_DISALLOW_COPY_AND_ASSIGN(VolatilePathTracker); -}; - -} // namespace flutter - -#endif // FLUTTER_LIB_UI_VOLATILE_PATH_TRACKER_H_ diff --git a/engine/src/flutter/runtime/dart_isolate_unittests.cc b/engine/src/flutter/runtime/dart_isolate_unittests.cc index 845d7237d4..a030d99ddd 100644 --- a/engine/src/flutter/runtime/dart_isolate_unittests.cc +++ b/engine/src/flutter/runtime/dart_isolate_unittests.cc @@ -769,10 +769,9 @@ TEST_F(DartIsolateTest, PlatformIsolateCreationAndShutdown) { ui_thread, // ui ui_thread // io ); - auto isolate = - RunDartCodeInIsolate(vm_ref, settings, task_runners, "emptyMain", {}, - GetDefaultKernelFilePath(), {}, nullptr, - std::move(platform_configuration)); + auto isolate = RunDartCodeInIsolate( + vm_ref, settings, task_runners, "emptyMain", {}, + GetDefaultKernelFilePath(), {}, std::move(platform_configuration)); ASSERT_TRUE(isolate); auto root_isolate = isolate->get(); ASSERT_EQ(root_isolate->GetPhase(), DartIsolate::Phase::Running); @@ -842,10 +841,9 @@ TEST_F(DartIsolateTest, PlatformIsolateEarlyShutdown) { ui_thread, // ui ui_thread // io ); - auto isolate = - RunDartCodeInIsolate(vm_ref, settings, task_runners, "emptyMain", {}, - GetDefaultKernelFilePath(), {}, nullptr, - std::move(platform_configuration)); + auto isolate = RunDartCodeInIsolate( + vm_ref, settings, task_runners, "emptyMain", {}, + GetDefaultKernelFilePath(), {}, std::move(platform_configuration)); ASSERT_TRUE(isolate); auto root_isolate = isolate->get(); ASSERT_EQ(root_isolate->GetPhase(), DartIsolate::Phase::Running); @@ -925,10 +923,9 @@ TEST_F(DartIsolateTest, PlatformIsolateSendAndReceive) { ui_thread, // ui ui_thread // io ); - auto isolate = - RunDartCodeInIsolate(vm_ref, settings, task_runners, "emptyMain", {}, - GetDefaultKernelFilePath(), {}, nullptr, - std::move(platform_configuration)); + auto isolate = RunDartCodeInIsolate( + vm_ref, settings, task_runners, "emptyMain", {}, + GetDefaultKernelFilePath(), {}, std::move(platform_configuration)); ASSERT_TRUE(isolate); auto root_isolate = isolate->get(); ASSERT_EQ(root_isolate->GetPhase(), DartIsolate::Phase::Running); @@ -992,10 +989,9 @@ TEST_F(DartIsolateTest, PlatformIsolateCreationAfterManagerShutdown) { ui_thread, // ui ui_thread // io ); - auto isolate = - RunDartCodeInIsolate(vm_ref, settings, task_runners, "emptyMain", {}, - GetDefaultKernelFilePath(), {}, nullptr, - std::move(platform_configuration)); + auto isolate = RunDartCodeInIsolate( + vm_ref, settings, task_runners, "emptyMain", {}, + GetDefaultKernelFilePath(), {}, std::move(platform_configuration)); ASSERT_TRUE(isolate); auto root_isolate = isolate->get(); ASSERT_EQ(root_isolate->GetPhase(), DartIsolate::Phase::Running); @@ -1060,10 +1056,9 @@ TEST_F(DartIsolateTest, PlatformIsolateManagerShutdownBeforeMainRuns) { ui_thread, // ui ui_thread // io ); - auto isolate = - RunDartCodeInIsolate(vm_ref, settings, task_runners, "emptyMain", {}, - GetDefaultKernelFilePath(), {}, nullptr, - std::move(platform_configuration)); + auto isolate = RunDartCodeInIsolate( + vm_ref, settings, task_runners, "emptyMain", {}, + GetDefaultKernelFilePath(), {}, std::move(platform_configuration)); ASSERT_TRUE(isolate); auto root_isolate = isolate->get(); ASSERT_EQ(root_isolate->GetPhase(), DartIsolate::Phase::Running); @@ -1146,10 +1141,9 @@ TEST_F(DartIsolateTest, PlatformIsolateMainThrowsError) { ui_thread, // ui ui_thread // io ); - auto isolate = - RunDartCodeInIsolate(vm_ref, settings, task_runners, "emptyMain", {}, - GetDefaultKernelFilePath(), {}, nullptr, - std::move(platform_configuration)); + auto isolate = RunDartCodeInIsolate( + vm_ref, settings, task_runners, "emptyMain", {}, + GetDefaultKernelFilePath(), {}, std::move(platform_configuration)); ASSERT_TRUE(isolate); auto root_isolate = isolate->get(); ASSERT_EQ(root_isolate->GetPhase(), DartIsolate::Phase::Running); diff --git a/engine/src/flutter/runtime/runtime_controller.cc b/engine/src/flutter/runtime/runtime_controller.cc index 90e79b9eba..51613d6430 100644 --- a/engine/src/flutter/runtime/runtime_controller.cc +++ b/engine/src/flutter/runtime/runtime_controller.cc @@ -69,7 +69,7 @@ std::unique_ptr RuntimeController::Spawn( std::move(image_generator_registry), advisory_script_uri, advisory_script_entrypoint, - context_.volatile_path_tracker, + context_.deterministic_rendering_enabled, context_.concurrent_task_runner, context_.enable_impeller, context_.runtime_stage_backend}; diff --git a/engine/src/flutter/runtime/runtime_controller.h b/engine/src/flutter/runtime/runtime_controller.h index 3f68408ebf..c19f856644 100644 --- a/engine/src/flutter/runtime/runtime_controller.h +++ b/engine/src/flutter/runtime/runtime_controller.h @@ -17,7 +17,6 @@ #include "flutter/lib/ui/painting/image_generator_registry.h" #include "flutter/lib/ui/text/font_collection.h" #include "flutter/lib/ui/ui_dart_state.h" -#include "flutter/lib/ui/volatile_path_tracker.h" #include "flutter/lib/ui/window/platform_configuration.h" #include "flutter/lib/ui/window/pointer_data_packet.h" #include "flutter/lib/ui/window/pointer_data_packet_converter.h" diff --git a/engine/src/flutter/shell/common/engine.cc b/engine/src/flutter/shell/common/engine.cc index ac628eb929..e524230fb8 100644 --- a/engine/src/flutter/shell/common/engine.cc +++ b/engine/src/flutter/shell/common/engine.cc @@ -74,7 +74,6 @@ Engine::Engine(Delegate& delegate, fml::WeakPtr io_manager, const fml::RefPtr& unref_queue, fml::TaskRunnerAffineWeakPtr snapshot_delegate, - std::shared_ptr volatile_path_tracker, const std::shared_ptr& gpu_disabled_switch, impeller::RuntimeStageBackend runtime_stage_type) : Engine(delegate, @@ -105,10 +104,11 @@ Engine::Engine(Delegate& delegate, image_generator_registry_.GetWeakPtr(), // image generator registry settings_.advisory_script_uri, // advisory script uri settings_.advisory_script_entrypoint, // advisory script entrypoint - std::move(volatile_path_tracker), // volatile path tracker - vm.GetConcurrentWorkerTaskRunner(), // concurrent task runner - settings_.enable_impeller, // enable impeller - runtime_stage_type, // runtime stage type + settings_ + .skia_deterministic_rendering_on_cpu, // deterministic rendering + vm.GetConcurrentWorkerTaskRunner(), // concurrent task runner + settings_.enable_impeller, // enable impeller + runtime_stage_type, // runtime stage type }); } diff --git a/engine/src/flutter/shell/common/engine.h b/engine/src/flutter/shell/common/engine.h index 7819ed675c..2530b7cd29 100644 --- a/engine/src/flutter/shell/common/engine.h +++ b/engine/src/flutter/shell/common/engine.h @@ -19,7 +19,6 @@ #include "flutter/lib/ui/semantics/semantics_node.h" #include "flutter/lib/ui/snapshot_delegate.h" #include "flutter/lib/ui/text/font_collection.h" -#include "flutter/lib/ui/volatile_path_tracker.h" #include "flutter/lib/ui/window/platform_message.h" #include "flutter/lib/ui/window/viewport_metrics.h" #include "flutter/runtime/dart_vm.h" @@ -399,7 +398,6 @@ class Engine final : public RuntimeDelegate, PointerDataDispatcher::Delegate { fml::WeakPtr io_manager, const fml::RefPtr& unref_queue, fml::TaskRunnerAffineWeakPtr snapshot_delegate, - std::shared_ptr volatile_path_tracker, const std::shared_ptr& gpu_disabled_switch, impeller::RuntimeStageBackend runtime_stage_type = impeller::RuntimeStageBackend::kSkSL); diff --git a/engine/src/flutter/shell/common/engine_animator_unittests.cc b/engine/src/flutter/shell/common/engine_animator_unittests.cc index 12bea41da9..8d8261bc02 100644 --- a/engine/src/flutter/shell/common/engine_animator_unittests.cc +++ b/engine/src/flutter/shell/common/engine_animator_unittests.cc @@ -249,7 +249,6 @@ class EngineContext { /*io_manager=*/io_manager_, /*unref_queue=*/nullptr, /*snapshot_delegate=*/snapshot_delegate_, - /*volatile_path_tracker=*/nullptr, /*gpu_disabled_switch=*/std::make_shared()); }); } diff --git a/engine/src/flutter/shell/common/shell.cc b/engine/src/flutter/shell/common/shell.cc index 75276e49b2..453845b3b7 100644 --- a/engine/src/flutter/shell/common/shell.cc +++ b/engine/src/flutter/shell/common/shell.cc @@ -64,22 +64,20 @@ std::unique_ptr CreateEngine( const fml::WeakPtr& io_manager, const fml::RefPtr& unref_queue, const fml::TaskRunnerAffineWeakPtr& snapshot_delegate, - const std::shared_ptr& volatile_path_tracker, const std::shared_ptr& gpu_disabled_switch, impeller::RuntimeStageBackend runtime_stage_backend) { - return std::make_unique(delegate, // - dispatcher_maker, // - vm, // - isolate_snapshot, // - task_runners, // - platform_data, // - settings, // - std::move(animator), // - io_manager, // - unref_queue, // - snapshot_delegate, // - volatile_path_tracker, // - gpu_disabled_switch, // + return std::make_unique(delegate, // + dispatcher_maker, // + vm, // + isolate_snapshot, // + task_runners, // + platform_data, // + settings, // + std::move(animator), // + io_manager, // + unref_queue, // + snapshot_delegate, // + gpu_disabled_switch, // runtime_stage_backend); } @@ -232,11 +230,7 @@ std::unique_ptr Shell::CreateShellOnPlatformThread( auto shell = std::unique_ptr( new Shell(std::move(vm), task_runners, std::move(parent_merger), - resource_cache_limit_calculator, settings, - std::make_shared( - task_runners.GetUITaskRunner(), - !settings.skia_deterministic_rendering_on_cpu), - is_gpu_disabled)); + resource_cache_limit_calculator, settings, is_gpu_disabled)); // Create the platform view on the platform thread (this thread). auto platform_view = on_create_platform_view(*shell.get()); @@ -355,7 +349,6 @@ std::unique_ptr Shell::CreateShellOnPlatformThread( weak_io_manager_future.get(), // unref_queue_future.get(), // snapshot_delegate_future.get(), // - shell->volatile_path_tracker_, // shell->is_gpu_disabled_sync_switch_, // runtime_stage_backend // )); @@ -439,7 +432,6 @@ Shell::Shell(DartVMRef vm, const std::shared_ptr& resource_cache_limit_calculator, const Settings& settings, - std::shared_ptr volatile_path_tracker, bool is_gpu_disabled) : task_runners_(task_runners), parent_raster_thread_merger_(std::move(parent_merger)), @@ -447,7 +439,6 @@ Shell::Shell(DartVMRef vm, settings_(settings), vm_(std::move(vm)), is_gpu_disabled_sync_switch_(new fml::SyncSwitch(is_gpu_disabled)), - volatile_path_tracker_(std::move(volatile_path_tracker)), weak_factory_gpu_(nullptr), weak_factory_(this) { FML_CHECK(!settings.enable_software_rendering || !settings.enable_impeller) @@ -611,7 +602,6 @@ std::unique_ptr Shell::Spawn( const fml::WeakPtr& io_manager, const fml::RefPtr& unref_queue, fml::TaskRunnerAffineWeakPtr snapshot_delegate, - const std::shared_ptr& volatile_path_tracker, const std::shared_ptr& is_gpu_disabled_sync_switch, impeller::RuntimeStageBackend runtime_stage_backend) { return engine->Spawn( @@ -1278,7 +1268,6 @@ void Shell::OnAnimatorNotifyIdle(fml::TimeDelta deadline) { if (engine_) { engine_->NotifyIdle(deadline); - volatile_path_tracker_->OnFrame(); } } diff --git a/engine/src/flutter/shell/common/shell.h b/engine/src/flutter/shell/common/shell.h index fe5b2fc2f0..0032403dea 100644 --- a/engine/src/flutter/shell/common/shell.h +++ b/engine/src/flutter/shell/common/shell.h @@ -28,7 +28,6 @@ #include "flutter/lib/ui/painting/image_generator_registry.h" #include "flutter/lib/ui/semantics/custom_accessibility_action.h" #include "flutter/lib/ui/semantics/semantics_node.h" -#include "flutter/lib/ui/volatile_path_tracker.h" #include "flutter/lib/ui/window/platform_message.h" #include "flutter/runtime/dart_vm_lifecycle.h" #include "flutter/runtime/platform_data.h" @@ -130,7 +129,6 @@ class Shell final : public PlatformView::Delegate, fml::WeakPtr io_manager, fml::RefPtr unref_queue, fml::TaskRunnerAffineWeakPtr snapshot_delegate, - std::shared_ptr volatile_path_tracker, const std::shared_ptr& gpu_disabled_switch, impeller::RuntimeStageBackend runtime_stage_type)> EngineCreateCallback; @@ -451,7 +449,6 @@ class Shell final : public PlatformView::Delegate, std::unique_ptr rasterizer_; // on raster task runner std::shared_ptr io_manager_; // on IO task runner std::shared_ptr is_gpu_disabled_sync_switch_; - std::shared_ptr volatile_path_tracker_; std::shared_ptr platform_message_handler_; std::atomic route_messages_through_platform_thread_ = false; @@ -513,7 +510,6 @@ class Shell final : public PlatformView::Delegate, const std::shared_ptr& resource_cache_limit_calculator, const Settings& settings, - std::shared_ptr volatile_path_tracker, bool is_gpu_disabled); static std::unique_ptr CreateShellOnPlatformThread( diff --git a/engine/src/flutter/shell/common/shell_test.cc b/engine/src/flutter/shell/common/shell_test.cc index 197daaa456..48a18b830f 100644 --- a/engine/src/flutter/shell/common/shell_test.cc +++ b/engine/src/flutter/shell/common/shell_test.cc @@ -409,15 +409,6 @@ void ShellTest::DestroyShell(std::unique_ptr shell, latch.Wait(); } -size_t ShellTest::GetLiveTrackedPathCount( - const std::shared_ptr& tracker) { - return std::count_if( - tracker->paths_.begin(), tracker->paths_.end(), - [](const std::weak_ptr& path) { - return path.lock(); - }); -} - void ShellTest::TurnOffGPU(Shell* shell, bool value) { shell->is_gpu_disabled_sync_switch_->SetSwitch(value); } diff --git a/engine/src/flutter/shell/common/shell_test.h b/engine/src/flutter/shell/common/shell_test.h index fdf449ca8f..4fb758e55b 100644 --- a/engine/src/flutter/shell/common/shell_test.h +++ b/engine/src/flutter/shell/common/shell_test.h @@ -15,7 +15,6 @@ #include "flutter/fml/build_config.h" #include "flutter/fml/macros.h" #include "flutter/fml/time/time_point.h" -#include "flutter/lib/ui/volatile_path_tracker.h" #include "flutter/lib/ui/window/platform_message.h" #include "flutter/shell/common/run_configuration.h" #include "flutter/shell/common/shell_test_external_view_embedder.h" @@ -155,9 +154,6 @@ class ShellTest : public FixtureTest { // is unpredictive. static int UnreportedTimingsCount(Shell* shell); - static size_t GetLiveTrackedPathCount( - const std::shared_ptr& tracker); - static void TurnOffGPU(Shell* shell, bool value); private: diff --git a/engine/src/flutter/testing/dart_isolate_runner.cc b/engine/src/flutter/testing/dart_isolate_runner.cc index 1afbb78796..c0b42a3443 100644 --- a/engine/src/flutter/testing/dart_isolate_runner.cc +++ b/engine/src/flutter/testing/dart_isolate_runner.cc @@ -72,7 +72,6 @@ std::unique_ptr RunDartCodeInIsolateOnUITaskRunner( const std::vector& args, const std::string& kernel_file_path, fml::WeakPtr io_manager, - const std::shared_ptr& volatile_path_tracker, std::unique_ptr platform_configuration) { FML_CHECK(task_runners.GetUITaskRunner()->RunsTasksOnCurrentThread()); @@ -160,7 +159,6 @@ std::unique_ptr RunDartCodeInIsolate( const std::vector& args, const std::string& kernel_file_path, fml::WeakPtr io_manager, - std::shared_ptr volatile_path_tracker, std::unique_ptr platform_configuration) { std::unique_ptr result; fml::AutoResetWaitableEvent latch; @@ -168,8 +166,7 @@ std::unique_ptr RunDartCodeInIsolate( task_runners.GetUITaskRunner(), fml::MakeCopyable([&]() mutable { result = RunDartCodeInIsolateOnUITaskRunner( vm_ref, settings, task_runners, entrypoint, args, kernel_file_path, - io_manager, volatile_path_tracker, - std::move(platform_configuration)); + io_manager, std::move(platform_configuration)); latch.Signal(); })); latch.Wait(); diff --git a/engine/src/flutter/testing/dart_isolate_runner.h b/engine/src/flutter/testing/dart_isolate_runner.h index 25a0702ef0..a6dac4c316 100644 --- a/engine/src/flutter/testing/dart_isolate_runner.h +++ b/engine/src/flutter/testing/dart_isolate_runner.h @@ -54,7 +54,6 @@ void RunDartCodeInIsolate( const std::vector& args, const std::string& fixtures_path, fml::WeakPtr io_manager = {}, - std::shared_ptr volatile_path_tracker = nullptr, std::unique_ptr platform_configuration = nullptr); std::unique_ptr RunDartCodeInIsolate( @@ -65,7 +64,6 @@ std::unique_ptr RunDartCodeInIsolate( const std::vector& args, const std::string& fixtures_path, fml::WeakPtr io_manager = {}, - std::shared_ptr volatile_path_tracker = nullptr, std::unique_ptr platform_configuration = nullptr); } // namespace testing