From 8b7101800fba7cb709ad59dafd363cee4c6655d1 Mon Sep 17 00:00:00 2001 From: Jonah Williams Date: Mon, 19 Aug 2024 12:37:17 -0700 Subject: [PATCH] [Impeller] finish experimental canvas changes. (flutter/engine#54569) Make sure the old dispatcher cannot be used if the new dispatcher is enabled. Migrate tests using old canvas to new canvas, mostly to make deleting the old one easier... --- .../testing/dl_test_surface_metal.cc | 13 + .../flutter/impeller/aiks/canvas_unittests.cc | 322 ++++++++++-------- .../display_list/aiks_dl_unittests.cc | 43 +++ .../impeller/display_list/dl_dispatcher.cc | 49 +++ .../impeller/display_list/dl_dispatcher.h | 8 + .../impeller/display_list/dl_unittests.cc | 108 +----- .../golden_playground_test_mac.cc | 54 +-- engine/src/flutter/shell/common/rasterizer.cc | 11 +- .../shell/gpu/gpu_surface_gl_impeller.cc | 26 +- .../embedder/embedder_external_view.cc | 2 +- .../testing/impeller_golden_tests_output.txt | 6 + 11 files changed, 332 insertions(+), 310 deletions(-) diff --git a/engine/src/flutter/display_list/testing/dl_test_surface_metal.cc b/engine/src/flutter/display_list/testing/dl_test_surface_metal.cc index def57908b4..5894c64a54 100644 --- a/engine/src/flutter/display_list/testing/dl_test_surface_metal.cc +++ b/engine/src/flutter/display_list/testing/dl_test_surface_metal.cc @@ -87,6 +87,11 @@ sk_sp DlMetalSurfaceProvider::ImpellerSnapshot( const sk_sp& list, int width, int height) const { +#if EXPERIMENTAL_CANVAS + auto texture = DisplayListToTexture(list, {width, height}, *aiks_context_); + return sk_make_sp( + snapshotter_->MakeScreenshot(*aiks_context_, texture)); +#else InitScreenShotter(); impeller::DlDispatcher dispatcher; dispatcher.drawColor(flutter::DlColor::kTransparent(), @@ -95,6 +100,8 @@ sk_sp DlMetalSurfaceProvider::ImpellerSnapshot( auto picture = dispatcher.EndRecordingAsPicture(); return sk_make_sp(snapshotter_->MakeScreenshot( *aiks_context_, picture, {width, height}, false)); + +#endif // EXPERIMENTAL_CANVAS } sk_sp DlMetalSurfaceProvider::MakeImpellerImage( @@ -102,6 +109,10 @@ sk_sp DlMetalSurfaceProvider::MakeImpellerImage( int width, int height) const { InitScreenShotter(); +#if EXPERIMENTAL_CANVAS + return impeller::DlImageImpeller::Make( + DisplayListToTexture(list, {width, height}, *aiks_context_)); +#else impeller::DlDispatcher dispatcher; dispatcher.drawColor(flutter::DlColor::kTransparent(), flutter::DlBlendMode::kSrc); @@ -111,6 +122,8 @@ sk_sp DlMetalSurfaceProvider::MakeImpellerImage( picture.ToImage(*aiks_context_, {width, height}); std::shared_ptr texture = image->GetTexture(); return impeller::DlImageImpeller::Make(texture); + +#endif // EXPERIMENTAL_CANVAS } void DlMetalSurfaceProvider::InitScreenShotter() const { diff --git a/engine/src/flutter/impeller/aiks/canvas_unittests.cc b/engine/src/flutter/impeller/aiks/canvas_unittests.cc index a2deabcb90..e05a92b903 100644 --- a/engine/src/flutter/impeller/aiks/canvas_unittests.cc +++ b/engine/src/flutter/impeller/aiks/canvas_unittests.cc @@ -3,8 +3,9 @@ // found in the LICENSE file. #include "flutter/testing/testing.h" -#include "impeller/aiks/canvas.h" -#include "impeller/aiks/image_filter.h" +#include "impeller/aiks/aiks_context.h" +#include "impeller/aiks/aiks_unittests.h" +#include "impeller/aiks/experimental_canvas.h" #include "impeller/geometry/path_builder.h" // TODO(zanderso): https://github.com/flutter/flutter/issues/127701 @@ -13,252 +14,285 @@ namespace impeller { namespace testing { -using AiksCanvasTest = ::testing::Test; +std::unique_ptr CreateTestCanvas( + ContentContext& context, + std::optional cull_rect = std::nullopt) { + RenderTarget render_target = context.GetRenderTargetCache()->CreateOffscreen( + *context.GetContext(), {1, 1}, 1); -TEST(AiksCanvasTest, EmptyCullRect) { - Canvas canvas; - - ASSERT_FALSE(canvas.GetCurrentLocalCullingBounds().has_value()); + if (cull_rect.has_value()) { + return std::make_unique(context, render_target, false, + cull_rect.value()); + } + return std::make_unique(context, render_target, false); } -TEST(AiksCanvasTest, InitialCullRect) { +TEST_P(AiksTest, EmptyCullRect) { + ContentContext context(GetContext(), nullptr); + auto canvas = CreateTestCanvas(context); + + ASSERT_FALSE(canvas->GetCurrentLocalCullingBounds().has_value()); +} + +TEST_P(AiksTest, InitialCullRect) { Rect initial_cull = Rect::MakeXYWH(0, 0, 10, 10); - Canvas canvas(initial_cull); + ContentContext context(GetContext(), nullptr); + auto canvas = CreateTestCanvas(context, initial_cull); - ASSERT_TRUE(canvas.GetCurrentLocalCullingBounds().has_value()); - ASSERT_EQ(canvas.GetCurrentLocalCullingBounds().value(), initial_cull); + ASSERT_TRUE(canvas->GetCurrentLocalCullingBounds().has_value()); + ASSERT_EQ(canvas->GetCurrentLocalCullingBounds().value(), initial_cull); } -TEST(AiksCanvasTest, TranslatedCullRect) { +TEST_P(AiksTest, TranslatedCullRect) { Rect initial_cull = Rect::MakeXYWH(5, 5, 10, 10); Rect translated_cull = Rect::MakeXYWH(0, 0, 10, 10); - Canvas canvas(initial_cull); - canvas.Translate(Vector3(5, 5, 0)); + ContentContext context(GetContext(), nullptr); + auto canvas = CreateTestCanvas(context, initial_cull); + canvas->Translate(Vector3(5, 5, 0)); - ASSERT_TRUE(canvas.GetCurrentLocalCullingBounds().has_value()); - ASSERT_EQ(canvas.GetCurrentLocalCullingBounds().value(), translated_cull); + ASSERT_TRUE(canvas->GetCurrentLocalCullingBounds().has_value()); + ASSERT_EQ(canvas->GetCurrentLocalCullingBounds().value(), translated_cull); } -TEST(AiksCanvasTest, ScaledCullRect) { +TEST_P(AiksTest, ScaledCullRect) { Rect initial_cull = Rect::MakeXYWH(5, 5, 10, 10); Rect scaled_cull = Rect::MakeXYWH(10, 10, 20, 20); - Canvas canvas(initial_cull); - canvas.Scale(Vector2(0.5, 0.5)); + ContentContext context(GetContext(), nullptr); + auto canvas = CreateTestCanvas(context, initial_cull); + canvas->Scale(Vector2(0.5, 0.5)); - ASSERT_TRUE(canvas.GetCurrentLocalCullingBounds().has_value()); - ASSERT_EQ(canvas.GetCurrentLocalCullingBounds().value(), scaled_cull); + ASSERT_TRUE(canvas->GetCurrentLocalCullingBounds().has_value()); + ASSERT_EQ(canvas->GetCurrentLocalCullingBounds().value(), scaled_cull); } -TEST(AiksCanvasTest, RectClipIntersectAgainstEmptyCullRect) { +TEST_P(AiksTest, RectClipIntersectAgainstEmptyCullRect) { Rect rect_clip = Rect::MakeXYWH(5, 5, 10, 10); - Canvas canvas; - canvas.ClipRect(rect_clip, Entity::ClipOperation::kIntersect); + ContentContext context(GetContext(), nullptr); + auto canvas = CreateTestCanvas(context); + canvas->ClipRect(rect_clip, Entity::ClipOperation::kIntersect); - ASSERT_TRUE(canvas.GetCurrentLocalCullingBounds().has_value()); - ASSERT_EQ(canvas.GetCurrentLocalCullingBounds().value(), rect_clip); + ASSERT_TRUE(canvas->GetCurrentLocalCullingBounds().has_value()); + ASSERT_EQ(canvas->GetCurrentLocalCullingBounds().value(), rect_clip); } -TEST(AiksCanvasTest, RectClipDiffAgainstEmptyCullRect) { +TEST_P(AiksTest, RectClipDiffAgainstEmptyCullRect) { Rect rect_clip = Rect::MakeXYWH(5, 5, 10, 10); - Canvas canvas; - canvas.ClipRect(rect_clip, Entity::ClipOperation::kDifference); + ContentContext context(GetContext(), nullptr); + auto canvas = CreateTestCanvas(context); + canvas->ClipRect(rect_clip, Entity::ClipOperation::kDifference); - ASSERT_FALSE(canvas.GetCurrentLocalCullingBounds().has_value()); + ASSERT_FALSE(canvas->GetCurrentLocalCullingBounds().has_value()); } -TEST(AiksCanvasTest, RectClipIntersectAgainstCullRect) { +TEST_P(AiksTest, RectClipIntersectAgainstCullRect) { Rect initial_cull = Rect::MakeXYWH(0, 0, 10, 10); Rect rect_clip = Rect::MakeXYWH(5, 5, 10, 10); Rect result_cull = Rect::MakeXYWH(5, 5, 5, 5); - Canvas canvas(initial_cull); - canvas.ClipRect(rect_clip, Entity::ClipOperation::kIntersect); + ContentContext context(GetContext(), nullptr); + auto canvas = CreateTestCanvas(context, initial_cull); + canvas->ClipRect(rect_clip, Entity::ClipOperation::kIntersect); - ASSERT_TRUE(canvas.GetCurrentLocalCullingBounds().has_value()); - ASSERT_EQ(canvas.GetCurrentLocalCullingBounds().value(), result_cull); + ASSERT_TRUE(canvas->GetCurrentLocalCullingBounds().has_value()); + ASSERT_EQ(canvas->GetCurrentLocalCullingBounds().value(), result_cull); } -TEST(AiksCanvasTest, RectClipDiffAgainstNonCoveredCullRect) { +TEST_P(AiksTest, RectClipDiffAgainstNonCoveredCullRect) { Rect initial_cull = Rect::MakeXYWH(0, 0, 10, 10); Rect rect_clip = Rect::MakeXYWH(5, 5, 10, 10); Rect result_cull = Rect::MakeXYWH(0, 0, 10, 10); - Canvas canvas(initial_cull); - canvas.ClipRect(rect_clip, Entity::ClipOperation::kDifference); + ContentContext context(GetContext(), nullptr); + auto canvas = CreateTestCanvas(context, initial_cull); + canvas->ClipRect(rect_clip, Entity::ClipOperation::kDifference); - ASSERT_TRUE(canvas.GetCurrentLocalCullingBounds().has_value()); - ASSERT_EQ(canvas.GetCurrentLocalCullingBounds().value(), result_cull); + ASSERT_TRUE(canvas->GetCurrentLocalCullingBounds().has_value()); + ASSERT_EQ(canvas->GetCurrentLocalCullingBounds().value(), result_cull); } -TEST(AiksCanvasTest, RectClipDiffAboveCullRect) { +TEST_P(AiksTest, RectClipDiffAboveCullRect) { Rect initial_cull = Rect::MakeXYWH(5, 5, 10, 10); Rect rect_clip = Rect::MakeXYWH(0, 0, 20, 4); Rect result_cull = Rect::MakeXYWH(5, 5, 10, 10); - Canvas canvas(initial_cull); - canvas.ClipRect(rect_clip, Entity::ClipOperation::kDifference); + ContentContext context(GetContext(), nullptr); + auto canvas = CreateTestCanvas(context, initial_cull); + canvas->ClipRect(rect_clip, Entity::ClipOperation::kDifference); - ASSERT_TRUE(canvas.GetCurrentLocalCullingBounds().has_value()); - ASSERT_EQ(canvas.GetCurrentLocalCullingBounds().value(), result_cull); + ASSERT_TRUE(canvas->GetCurrentLocalCullingBounds().has_value()); + ASSERT_EQ(canvas->GetCurrentLocalCullingBounds().value(), result_cull); } -TEST(AiksCanvasTest, RectClipDiffBelowCullRect) { +TEST_P(AiksTest, RectClipDiffBelowCullRect) { Rect initial_cull = Rect::MakeXYWH(5, 5, 10, 10); Rect rect_clip = Rect::MakeXYWH(0, 16, 20, 4); Rect result_cull = Rect::MakeXYWH(5, 5, 10, 10); - Canvas canvas(initial_cull); - canvas.ClipRect(rect_clip, Entity::ClipOperation::kDifference); + ContentContext context(GetContext(), nullptr); + auto canvas = CreateTestCanvas(context, initial_cull); + canvas->ClipRect(rect_clip, Entity::ClipOperation::kDifference); - ASSERT_TRUE(canvas.GetCurrentLocalCullingBounds().has_value()); - ASSERT_EQ(canvas.GetCurrentLocalCullingBounds().value(), result_cull); + ASSERT_TRUE(canvas->GetCurrentLocalCullingBounds().has_value()); + ASSERT_EQ(canvas->GetCurrentLocalCullingBounds().value(), result_cull); } -TEST(AiksCanvasTest, RectClipDiffLeftOfCullRect) { +TEST_P(AiksTest, RectClipDiffLeftOfCullRect) { Rect initial_cull = Rect::MakeXYWH(5, 5, 10, 10); Rect rect_clip = Rect::MakeXYWH(0, 0, 4, 20); Rect result_cull = Rect::MakeXYWH(5, 5, 10, 10); - Canvas canvas(initial_cull); - canvas.ClipRect(rect_clip, Entity::ClipOperation::kDifference); + ContentContext context(GetContext(), nullptr); + auto canvas = CreateTestCanvas(context, initial_cull); + canvas->ClipRect(rect_clip, Entity::ClipOperation::kDifference); - ASSERT_TRUE(canvas.GetCurrentLocalCullingBounds().has_value()); - ASSERT_EQ(canvas.GetCurrentLocalCullingBounds().value(), result_cull); + ASSERT_TRUE(canvas->GetCurrentLocalCullingBounds().has_value()); + ASSERT_EQ(canvas->GetCurrentLocalCullingBounds().value(), result_cull); } -TEST(AiksCanvasTest, RectClipDiffRightOfCullRect) { +TEST_P(AiksTest, RectClipDiffRightOfCullRect) { Rect initial_cull = Rect::MakeXYWH(5, 5, 10, 10); Rect rect_clip = Rect::MakeXYWH(16, 0, 4, 20); Rect result_cull = Rect::MakeXYWH(5, 5, 10, 10); - Canvas canvas(initial_cull); - canvas.ClipRect(rect_clip, Entity::ClipOperation::kDifference); + ContentContext context(GetContext(), nullptr); + auto canvas = CreateTestCanvas(context, initial_cull); + canvas->ClipRect(rect_clip, Entity::ClipOperation::kDifference); - ASSERT_TRUE(canvas.GetCurrentLocalCullingBounds().has_value()); - ASSERT_EQ(canvas.GetCurrentLocalCullingBounds().value(), result_cull); + ASSERT_TRUE(canvas->GetCurrentLocalCullingBounds().has_value()); + ASSERT_EQ(canvas->GetCurrentLocalCullingBounds().value(), result_cull); } -TEST(AiksCanvasTest, RectClipDiffAgainstVCoveredCullRect) { +TEST_P(AiksTest, RectClipDiffAgainstVCoveredCullRect) { Rect initial_cull = Rect::MakeXYWH(0, 0, 10, 10); Rect rect_clip = Rect::MakeXYWH(5, 0, 10, 10); Rect result_cull = Rect::MakeXYWH(0, 0, 5, 10); - Canvas canvas(initial_cull); - canvas.ClipRect(rect_clip, Entity::ClipOperation::kDifference); + ContentContext context(GetContext(), nullptr); + auto canvas = CreateTestCanvas(context, initial_cull); + canvas->ClipRect(rect_clip, Entity::ClipOperation::kDifference); - ASSERT_TRUE(canvas.GetCurrentLocalCullingBounds().has_value()); - ASSERT_EQ(canvas.GetCurrentLocalCullingBounds().value(), result_cull); + ASSERT_TRUE(canvas->GetCurrentLocalCullingBounds().has_value()); + ASSERT_EQ(canvas->GetCurrentLocalCullingBounds().value(), result_cull); } -TEST(AiksCanvasTest, RectClipDiffAgainstHCoveredCullRect) { +TEST_P(AiksTest, RectClipDiffAgainstHCoveredCullRect) { Rect initial_cull = Rect::MakeXYWH(0, 0, 10, 10); Rect rect_clip = Rect::MakeXYWH(0, 5, 10, 10); Rect result_cull = Rect::MakeXYWH(0, 0, 10, 5); - Canvas canvas(initial_cull); - canvas.ClipRect(rect_clip, Entity::ClipOperation::kDifference); + ContentContext context(GetContext(), nullptr); + auto canvas = CreateTestCanvas(context, initial_cull); + canvas->ClipRect(rect_clip, Entity::ClipOperation::kDifference); - ASSERT_TRUE(canvas.GetCurrentLocalCullingBounds().has_value()); - ASSERT_EQ(canvas.GetCurrentLocalCullingBounds().value(), result_cull); + ASSERT_TRUE(canvas->GetCurrentLocalCullingBounds().has_value()); + ASSERT_EQ(canvas->GetCurrentLocalCullingBounds().value(), result_cull); } -TEST(AiksCanvasTest, RRectClipIntersectAgainstEmptyCullRect) { +TEST_P(AiksTest, RRectClipIntersectAgainstEmptyCullRect) { Rect rect_clip = Rect::MakeXYWH(5, 5, 10, 10); - Canvas canvas; - canvas.ClipRRect(rect_clip, {1, 1}, Entity::ClipOperation::kIntersect); + ContentContext context(GetContext(), nullptr); + auto canvas = CreateTestCanvas(context); + canvas->ClipRRect(rect_clip, {1, 1}, Entity::ClipOperation::kIntersect); - ASSERT_TRUE(canvas.GetCurrentLocalCullingBounds().has_value()); - ASSERT_EQ(canvas.GetCurrentLocalCullingBounds().value(), rect_clip); + ASSERT_TRUE(canvas->GetCurrentLocalCullingBounds().has_value()); + ASSERT_EQ(canvas->GetCurrentLocalCullingBounds().value(), rect_clip); } -TEST(AiksCanvasTest, RRectClipDiffAgainstEmptyCullRect) { +TEST_P(AiksTest, RRectClipDiffAgainstEmptyCullRect) { Rect rect_clip = Rect::MakeXYWH(5, 5, 10, 10); - Canvas canvas; - canvas.ClipRRect(rect_clip, {1, 1}, Entity::ClipOperation::kDifference); + ContentContext context(GetContext(), nullptr); + auto canvas = CreateTestCanvas(context); + canvas->ClipRRect(rect_clip, {1, 1}, Entity::ClipOperation::kDifference); - ASSERT_FALSE(canvas.GetCurrentLocalCullingBounds().has_value()); + ASSERT_FALSE(canvas->GetCurrentLocalCullingBounds().has_value()); } -TEST(AiksCanvasTest, RRectClipIntersectAgainstCullRect) { +TEST_P(AiksTest, RRectClipIntersectAgainstCullRect) { Rect initial_cull = Rect::MakeXYWH(0, 0, 10, 10); Rect rect_clip = Rect::MakeXYWH(5, 5, 10, 10); Rect result_cull = Rect::MakeXYWH(5, 5, 5, 5); - Canvas canvas(initial_cull); - canvas.ClipRRect(rect_clip, {1, 1}, Entity::ClipOperation::kIntersect); + ContentContext context(GetContext(), nullptr); + auto canvas = CreateTestCanvas(context, initial_cull); + canvas->ClipRRect(rect_clip, {1, 1}, Entity::ClipOperation::kIntersect); - ASSERT_TRUE(canvas.GetCurrentLocalCullingBounds().has_value()); - ASSERT_EQ(canvas.GetCurrentLocalCullingBounds().value(), result_cull); + ASSERT_TRUE(canvas->GetCurrentLocalCullingBounds().has_value()); + ASSERT_EQ(canvas->GetCurrentLocalCullingBounds().value(), result_cull); } -TEST(AiksCanvasTest, RRectClipDiffAgainstNonCoveredCullRect) { +TEST_P(AiksTest, RRectClipDiffAgainstNonCoveredCullRect) { Rect initial_cull = Rect::MakeXYWH(0, 0, 10, 10); Rect rect_clip = Rect::MakeXYWH(5, 5, 10, 10); Rect result_cull = Rect::MakeXYWH(0, 0, 10, 10); - Canvas canvas(initial_cull); - canvas.ClipRRect(rect_clip, {1, 1}, Entity::ClipOperation::kDifference); + ContentContext context(GetContext(), nullptr); + auto canvas = CreateTestCanvas(context, initial_cull); + canvas->ClipRRect(rect_clip, {1, 1}, Entity::ClipOperation::kDifference); - ASSERT_TRUE(canvas.GetCurrentLocalCullingBounds().has_value()); - ASSERT_EQ(canvas.GetCurrentLocalCullingBounds().value(), result_cull); + ASSERT_TRUE(canvas->GetCurrentLocalCullingBounds().has_value()); + ASSERT_EQ(canvas->GetCurrentLocalCullingBounds().value(), result_cull); } -TEST(AiksCanvasTest, RRectClipDiffAgainstVPartiallyCoveredCullRect) { +TEST_P(AiksTest, RRectClipDiffAgainstVPartiallyCoveredCullRect) { Rect initial_cull = Rect::MakeXYWH(0, 0, 10, 10); Rect rect_clip = Rect::MakeXYWH(5, 0, 10, 10); Rect result_cull = Rect::MakeXYWH(0, 0, 6, 10); - Canvas canvas(initial_cull); - canvas.ClipRRect(rect_clip, {1, 1}, Entity::ClipOperation::kDifference); + ContentContext context(GetContext(), nullptr); + auto canvas = CreateTestCanvas(context, initial_cull); + canvas->ClipRRect(rect_clip, {1, 1}, Entity::ClipOperation::kDifference); - ASSERT_TRUE(canvas.GetCurrentLocalCullingBounds().has_value()); - ASSERT_EQ(canvas.GetCurrentLocalCullingBounds().value(), result_cull); + ASSERT_TRUE(canvas->GetCurrentLocalCullingBounds().has_value()); + ASSERT_EQ(canvas->GetCurrentLocalCullingBounds().value(), result_cull); } -TEST(AiksCanvasTest, RRectClipDiffAgainstVFullyCoveredCullRect) { +TEST_P(AiksTest, RRectClipDiffAgainstVFullyCoveredCullRect) { Rect initial_cull = Rect::MakeXYWH(0, 0, 10, 10); Rect rect_clip = Rect::MakeXYWH(5, -2, 10, 14); Rect result_cull = Rect::MakeXYWH(0, 0, 5, 10); - Canvas canvas(initial_cull); - canvas.ClipRRect(rect_clip, {1, 1}, Entity::ClipOperation::kDifference); + ContentContext context(GetContext(), nullptr); + auto canvas = CreateTestCanvas(context, initial_cull); + canvas->ClipRRect(rect_clip, {1, 1}, Entity::ClipOperation::kDifference); - ASSERT_TRUE(canvas.GetCurrentLocalCullingBounds().has_value()); - ASSERT_EQ(canvas.GetCurrentLocalCullingBounds().value(), result_cull); + ASSERT_TRUE(canvas->GetCurrentLocalCullingBounds().has_value()); + ASSERT_EQ(canvas->GetCurrentLocalCullingBounds().value(), result_cull); } -TEST(AiksCanvasTest, RRectClipDiffAgainstHPartiallyCoveredCullRect) { +TEST_P(AiksTest, RRectClipDiffAgainstHPartiallyCoveredCullRect) { Rect initial_cull = Rect::MakeXYWH(0, 0, 10, 10); Rect rect_clip = Rect::MakeXYWH(0, 5, 10, 10); Rect result_cull = Rect::MakeXYWH(0, 0, 10, 6); - Canvas canvas(initial_cull); - canvas.ClipRRect(rect_clip, {1, 1}, Entity::ClipOperation::kDifference); + ContentContext context(GetContext(), nullptr); + auto canvas = CreateTestCanvas(context, initial_cull); + canvas->ClipRRect(rect_clip, {1, 1}, Entity::ClipOperation::kDifference); - ASSERT_TRUE(canvas.GetCurrentLocalCullingBounds().has_value()); - ASSERT_EQ(canvas.GetCurrentLocalCullingBounds().value(), result_cull); + ASSERT_TRUE(canvas->GetCurrentLocalCullingBounds().has_value()); + ASSERT_EQ(canvas->GetCurrentLocalCullingBounds().value(), result_cull); } -TEST(AiksCanvasTest, RRectClipDiffAgainstHFullyCoveredCullRect) { +TEST_P(AiksTest, RRectClipDiffAgainstHFullyCoveredCullRect) { Rect initial_cull = Rect::MakeXYWH(0, 0, 10, 10); Rect rect_clip = Rect::MakeXYWH(-2, 5, 14, 10); Rect result_cull = Rect::MakeXYWH(0, 0, 10, 5); - Canvas canvas(initial_cull); - canvas.ClipRRect(rect_clip, {1, 1}, Entity::ClipOperation::kDifference); + ContentContext context(GetContext(), nullptr); + auto canvas = CreateTestCanvas(context, initial_cull); + canvas->ClipRRect(rect_clip, {1, 1}, Entity::ClipOperation::kDifference); - ASSERT_TRUE(canvas.GetCurrentLocalCullingBounds().has_value()); - ASSERT_EQ(canvas.GetCurrentLocalCullingBounds().value(), result_cull); + ASSERT_TRUE(canvas->GetCurrentLocalCullingBounds().has_value()); + ASSERT_EQ(canvas->GetCurrentLocalCullingBounds().value(), result_cull); } -TEST(AiksCanvasTest, PathClipIntersectAgainstEmptyCullRect) { +TEST_P(AiksTest, PathClipIntersectAgainstEmptyCullRect) { PathBuilder builder; builder.AddRect(Rect::MakeXYWH(5, 5, 1, 1)); builder.AddRect(Rect::MakeXYWH(5, 14, 1, 1)); @@ -267,14 +301,15 @@ TEST(AiksCanvasTest, PathClipIntersectAgainstEmptyCullRect) { Path path = builder.TakePath(); Rect rect_clip = Rect::MakeXYWH(5, 5, 10, 10); - Canvas canvas; - canvas.ClipPath(path, Entity::ClipOperation::kIntersect); + ContentContext context(GetContext(), nullptr); + auto canvas = CreateTestCanvas(context); + canvas->ClipPath(path, Entity::ClipOperation::kIntersect); - ASSERT_TRUE(canvas.GetCurrentLocalCullingBounds().has_value()); - ASSERT_EQ(canvas.GetCurrentLocalCullingBounds().value(), rect_clip); + ASSERT_TRUE(canvas->GetCurrentLocalCullingBounds().has_value()); + ASSERT_EQ(canvas->GetCurrentLocalCullingBounds().value(), rect_clip); } -TEST(AiksCanvasTest, PathClipDiffAgainstEmptyCullRect) { +TEST_P(AiksTest, PathClipDiffAgainstEmptyCullRect) { PathBuilder builder; builder.AddRect(Rect::MakeXYWH(5, 5, 1, 1)); builder.AddRect(Rect::MakeXYWH(5, 14, 1, 1)); @@ -282,13 +317,14 @@ TEST(AiksCanvasTest, PathClipDiffAgainstEmptyCullRect) { builder.AddRect(Rect::MakeXYWH(14, 14, 1, 1)); Path path = builder.TakePath(); - Canvas canvas; - canvas.ClipPath(path, Entity::ClipOperation::kDifference); + ContentContext context(GetContext(), nullptr); + auto canvas = CreateTestCanvas(context); + canvas->ClipPath(path, Entity::ClipOperation::kDifference); - ASSERT_FALSE(canvas.GetCurrentLocalCullingBounds().has_value()); + ASSERT_FALSE(canvas->GetCurrentLocalCullingBounds().has_value()); } -TEST(AiksCanvasTest, PathClipIntersectAgainstCullRect) { +TEST_P(AiksTest, PathClipIntersectAgainstCullRect) { Rect initial_cull = Rect::MakeXYWH(0, 0, 10, 10); PathBuilder builder; builder.AddRect(Rect::MakeXYWH(5, 5, 1, 1)); @@ -298,14 +334,15 @@ TEST(AiksCanvasTest, PathClipIntersectAgainstCullRect) { Path path = builder.TakePath(); Rect result_cull = Rect::MakeXYWH(5, 5, 5, 5); - Canvas canvas(initial_cull); - canvas.ClipPath(path, Entity::ClipOperation::kIntersect); + ContentContext context(GetContext(), nullptr); + auto canvas = CreateTestCanvas(context, initial_cull); + canvas->ClipPath(path, Entity::ClipOperation::kIntersect); - ASSERT_TRUE(canvas.GetCurrentLocalCullingBounds().has_value()); - ASSERT_EQ(canvas.GetCurrentLocalCullingBounds().value(), result_cull); + ASSERT_TRUE(canvas->GetCurrentLocalCullingBounds().has_value()); + ASSERT_EQ(canvas->GetCurrentLocalCullingBounds().value(), result_cull); } -TEST(AiksCanvasTest, PathClipDiffAgainstNonCoveredCullRect) { +TEST_P(AiksTest, PathClipDiffAgainstNonCoveredCullRect) { Rect initial_cull = Rect::MakeXYWH(0, 0, 10, 10); PathBuilder builder; builder.AddRect(Rect::MakeXYWH(5, 5, 1, 1)); @@ -315,14 +352,15 @@ TEST(AiksCanvasTest, PathClipDiffAgainstNonCoveredCullRect) { Path path = builder.TakePath(); Rect result_cull = Rect::MakeXYWH(0, 0, 10, 10); - Canvas canvas(initial_cull); - canvas.ClipPath(path, Entity::ClipOperation::kDifference); + ContentContext context(GetContext(), nullptr); + auto canvas = CreateTestCanvas(context, initial_cull); + canvas->ClipPath(path, Entity::ClipOperation::kDifference); - ASSERT_TRUE(canvas.GetCurrentLocalCullingBounds().has_value()); - ASSERT_EQ(canvas.GetCurrentLocalCullingBounds().value(), result_cull); + ASSERT_TRUE(canvas->GetCurrentLocalCullingBounds().has_value()); + ASSERT_EQ(canvas->GetCurrentLocalCullingBounds().value(), result_cull); } -TEST(AiksCanvasTest, PathClipDiffAgainstFullyCoveredCullRect) { +TEST_P(AiksTest, PathClipDiffAgainstFullyCoveredCullRect) { Rect initial_cull = Rect::MakeXYWH(5, 5, 10, 10); PathBuilder builder; builder.AddRect(Rect::MakeXYWH(0, 0, 100, 100)); @@ -330,28 +368,12 @@ TEST(AiksCanvasTest, PathClipDiffAgainstFullyCoveredCullRect) { // Diff clip of Paths is ignored due to complexity Rect result_cull = Rect::MakeXYWH(5, 5, 10, 10); - Canvas canvas(initial_cull); - canvas.ClipPath(path, Entity::ClipOperation::kDifference); + ContentContext context(GetContext(), nullptr); + auto canvas = CreateTestCanvas(context, initial_cull); + canvas->ClipPath(path, Entity::ClipOperation::kDifference); - ASSERT_TRUE(canvas.GetCurrentLocalCullingBounds().has_value()); - ASSERT_EQ(canvas.GetCurrentLocalCullingBounds().value(), result_cull); -} - -TEST(AiksCanvasTest, DisableLocalBoundsRectForFilteredSaveLayers) { - Rect initial_cull = Rect::MakeXYWH(0, 0, 10, 10); - - Canvas canvas(initial_cull); - ASSERT_TRUE(canvas.GetCurrentLocalCullingBounds().has_value()); - - canvas.Save(); - canvas.SaveLayer( - Paint{.image_filter = ImageFilter::MakeBlur( - Sigma(10), Sigma(10), FilterContents::BlurStyle::kNormal, - Entity::TileMode::kDecal)}); - ASSERT_FALSE(canvas.GetCurrentLocalCullingBounds().has_value()); - - canvas.Restore(); - ASSERT_TRUE(canvas.GetCurrentLocalCullingBounds().has_value()); + ASSERT_TRUE(canvas->GetCurrentLocalCullingBounds().has_value()); + ASSERT_EQ(canvas->GetCurrentLocalCullingBounds().value(), result_cull); } } // namespace testing diff --git a/engine/src/flutter/impeller/display_list/aiks_dl_unittests.cc b/engine/src/flutter/impeller/display_list/aiks_dl_unittests.cc index 911996ebe2..d87427ee83 100644 --- a/engine/src/flutter/impeller/display_list/aiks_dl_unittests.cc +++ b/engine/src/flutter/impeller/display_list/aiks_dl_unittests.cc @@ -847,5 +847,48 @@ TEST_P(AiksTest, CanDrawScaledPointsLargeScaleSmallRadius) { ASSERT_TRUE(OpenPlaygroundHere(builder.Build())); } +TEST_P(AiksTest, TransparentShadowProducesCorrectColor) { + DisplayListBuilder builder; + builder.Save(); + builder.Scale(1.618, 1.618); + SkPath path = SkPath{}.addRect(SkRect::MakeXYWH(0, 0, 200, 100)); + + builder.DrawShadow(path, flutter::DlColor::kTransparent(), 15, false, 1); + builder.Restore(); + + ASSERT_TRUE(OpenPlaygroundHere(builder.Build())); +} + +// Regression test for https://github.com/flutter/flutter/issues/130613 +TEST_P(AiksTest, DispatcherDoesNotCullPerspectiveTransformedChildDisplayLists) { + flutter::DisplayListBuilder sub_builder(true); + sub_builder.DrawRect(SkRect::MakeXYWH(0, 0, 50, 50), + flutter::DlPaint(flutter::DlColor::kRed())); + auto display_list = sub_builder.Build(); + + AiksContext context(GetContext(), nullptr); + RenderTarget render_target = + context.GetContentContext().GetRenderTargetCache()->CreateOffscreen( + *context.GetContext(), {2400, 1800}, 1); + + DisplayListBuilder builder; + + builder.Scale(2.0, 2.0); + builder.Translate(-93.0, 0.0); + + // clang-format off + builder.TransformFullPerspective( + 0.8, -0.2, -0.1, -0.0, + 0.0, 1.0, 0.0, 0.0, + 1.4, 1.3, 1.0, 0.0, + 63.2, 65.3, 48.6, 1.1 + ); + // clang-format on + builder.Translate(35.0, 75.0); + builder.DrawDisplayList(display_list, 1.0f); + + ASSERT_TRUE(OpenPlaygroundHere(builder.Build())); +} + } // namespace testing } // namespace impeller diff --git a/engine/src/flutter/impeller/display_list/dl_dispatcher.cc b/engine/src/flutter/impeller/display_list/dl_dispatcher.cc index 08ec303fee..f57b87a37b 100644 --- a/engine/src/flutter/impeller/display_list/dl_dispatcher.cc +++ b/engine/src/flutter/impeller/display_list/dl_dispatcher.cc @@ -1220,6 +1220,7 @@ Picture DlDispatcherBase::EndRecordingAsPicture() { /// Subclasses +#if !EXPERIMENTAL_CANVAS DlDispatcher::DlDispatcher() = default; DlDispatcher::DlDispatcher(IRect cull_rect) : canvas_(cull_rect) {} @@ -1229,6 +1230,7 @@ DlDispatcher::DlDispatcher(Rect cull_rect) : canvas_(cull_rect) {} Canvas& DlDispatcher::GetCanvas() { return canvas_; } +#endif // !EXPERIMENTAL_CANVAS static bool RequiresReadbackForBlends( const ContentContext& renderer, @@ -1415,4 +1417,51 @@ void TextFrameDispatcher::setStrokeJoin(flutter::DlStrokeJoin join) { } } +std::shared_ptr DisplayListToTexture( + const sk_sp& display_list, + ISize size, + AiksContext& context) { + // Do not use the render target cache as the lifecycle of this texture + // will outlive a particular frame. + impeller::RenderTargetAllocator render_target_allocator = + impeller::RenderTargetAllocator( + context.GetContext()->GetResourceAllocator()); + impeller::RenderTarget target; + if (context.GetContext()->GetCapabilities()->SupportsOffscreenMSAA()) { + target = render_target_allocator.CreateOffscreenMSAA( + *context.GetContext(), // context + size, // size + /*mip_count=*/1, + "Picture Snapshot MSAA", // label + impeller::RenderTarget:: + kDefaultColorAttachmentConfigMSAA // color_attachment_config + ); + } else { + target = render_target_allocator.CreateOffscreen( + *context.GetContext(), // context + size, // size + /*mip_count=*/1, + "Picture Snapshot", // label + impeller::RenderTarget:: + kDefaultColorAttachmentConfig // color_attachment_config + ); + } + + SkIRect sk_cull_rect = SkIRect::MakeWH(size.width, size.height); + impeller::TextFrameDispatcher collector(context.GetContentContext(), + impeller::Matrix()); + display_list->Dispatch(collector, sk_cull_rect); + impeller::ExperimentalDlDispatcher impeller_dispatcher( + context.GetContentContext(), target, + display_list->root_has_backdrop_filter(), + display_list->max_root_blend_mode(), impeller::IRect::MakeSize(size)); + display_list->Dispatch(impeller_dispatcher, sk_cull_rect); + impeller_dispatcher.FinishRecording(); + + context.GetContentContext().GetTransientsBuffer().Reset(); + context.GetContentContext().GetLazyGlyphAtlas()->ResetTextFrames(); + + return target.GetRenderTargetTexture(); +} + } // namespace impeller diff --git a/engine/src/flutter/impeller/display_list/dl_dispatcher.h b/engine/src/flutter/impeller/display_list/dl_dispatcher.h index 294616b748..38f2aaafce 100644 --- a/engine/src/flutter/impeller/display_list/dl_dispatcher.h +++ b/engine/src/flutter/impeller/display_list/dl_dispatcher.h @@ -261,6 +261,7 @@ class DlDispatcherBase : public flutter::DlOpReceiver { const Paint& paint); }; +#if !EXPERIMENTAL_CANVAS class DlDispatcher : public DlDispatcherBase { public: DlDispatcher(); @@ -297,6 +298,7 @@ class DlDispatcher : public DlDispatcherBase { Canvas& GetCanvas() override; }; +#endif // !EXPERIMENTAL_CANVAS class ExperimentalDlDispatcher : public DlDispatcherBase { public: @@ -403,6 +405,12 @@ class TextFrameDispatcher : public flutter::IgnoreAttributeDispatchHelper, Paint paint_; }; +/// Render the provided display list to a texture with the given size. +std::shared_ptr DisplayListToTexture( + const sk_sp& display_list, + ISize size, + AiksContext& context); + } // namespace impeller #endif // FLUTTER_IMPELLER_DISPLAY_LIST_DL_DISPATCHER_H_ diff --git a/engine/src/flutter/impeller/display_list/dl_unittests.cc b/engine/src/flutter/impeller/display_list/dl_unittests.cc index e3946c944e..7f3653ed28 100644 --- a/engine/src/flutter/impeller/display_list/dl_unittests.cc +++ b/engine/src/flutter/impeller/display_list/dl_unittests.cc @@ -18,6 +18,7 @@ #include "flutter/display_list/effects/dl_mask_filter.h" #include "flutter/testing/testing.h" #include "gtest/gtest.h" +#include "impeller/aiks/aiks_context.h" #include "impeller/display_list/dl_dispatcher.h" #include "impeller/display_list/dl_image_impeller.h" #include "impeller/display_list/dl_playground.h" @@ -910,69 +911,6 @@ TEST_P(DisplayListTest, CanDrawShadow) { ASSERT_TRUE(OpenPlaygroundHere(builder.Build())); } -TEST_P(DisplayListTest, - DispatcherDoesNotCullPerspectiveTransformedChildDisplayLists) { - // Regression test for https://github.com/flutter/flutter/issues/130613 - flutter::DisplayListBuilder sub_builder(true); - sub_builder.DrawRect(SkRect::MakeXYWH(0, 0, 50, 50), - flutter::DlPaint(flutter::DlColor::kRed())); - auto display_list = sub_builder.Build(); - - DlDispatcher dispatcher(Rect::MakeLTRB(0, 0, 2400, 1800)); - dispatcher.scale(2.0, 2.0); - dispatcher.translate(-93.0, 0.0); - // clang-format off - dispatcher.transformFullPerspective( - 0.8, -0.2, -0.1, -0.0, - 0.0, 1.0, 0.0, 0.0, - 1.4, 1.3, 1.0, 0.0, - 63.2, 65.3, 48.6, 1.1 - ); - // clang-format on - dispatcher.translate(35.0, 75.0); - dispatcher.drawDisplayList(display_list, 1.0f); - auto picture = dispatcher.EndRecordingAsPicture(); - - bool found = false; - picture.pass->IterateAllEntities([&found](Entity& entity) { - if (std::static_pointer_cast(entity.GetContents()) - ->GetColor() == Color::Red()) { - found = true; - return false; - } - - return true; - }); - EXPECT_TRUE(found); -} - -TEST_P(DisplayListTest, TransparentShadowProducesCorrectColor) { - DlDispatcher dispatcher; - dispatcher.save(); - dispatcher.scale(1.618, 1.618); - SkPath path = SkPath{}.addRect(SkRect::MakeXYWH(0, 0, 200, 100)); - flutter::DlOpReceiver::CacheablePath cache(path); - dispatcher.drawShadow(cache, flutter::DlColor::kTransparent(), 15, false, 1); - dispatcher.restore(); - auto picture = dispatcher.EndRecordingAsPicture(); - - std::shared_ptr rrect_blur; - picture.pass->IterateAllEntities([&rrect_blur](Entity& entity) { - if (ScalarNearlyEqual(entity.GetTransform().GetScale().x, 1.618f)) { - rrect_blur = std::static_pointer_cast( - entity.GetContents()); - return false; - } - return true; - }); - - ASSERT_NE(rrect_blur, nullptr); - ASSERT_EQ(rrect_blur->GetColor().red, 0); - ASSERT_EQ(rrect_blur->GetColor().green, 0); - ASSERT_EQ(rrect_blur->GetColor().blue, 0); - ASSERT_EQ(rrect_blur->GetColor().alpha, 0); -} - TEST_P(DisplayListTest, CanDrawZeroWidthLine) { flutter::DisplayListBuilder builder; std::vector caps = { @@ -1558,50 +1496,6 @@ static std::optional GetCoverageOfFirstEntity(const Picture& picture) { return coverage; } -TEST(DisplayListTest, RRectBoundsComputation) { - SkRRect rrect = SkRRect::MakeRectXY(SkRect::MakeLTRB(0, 0, 100, 100), 4, 4); - SkPath path = SkPath().addRRect(rrect); - - flutter::DlPaint paint; - flutter::DisplayListBuilder builder; - - builder.DrawPath(path, paint); - auto display_list = builder.Build(); - - DlDispatcher dispatcher; - display_list->Dispatch(dispatcher); - auto picture = dispatcher.EndRecordingAsPicture(); - - std::optional coverage = - GetCoverageOfFirstEntity(picture); - - // Validate that the RRect coverage is _exactly_ the same as the input rect. - ASSERT_TRUE(coverage.has_value()); - ASSERT_EQ(coverage.value_or(Rect::MakeMaximum()), - Rect::MakeLTRB(0, 0, 100, 100)); -} - -TEST(DisplayListTest, CircleBoundsComputation) { - SkPath path = SkPath().addCircle(0, 0, 5); - - flutter::DlPaint paint; - flutter::DisplayListBuilder builder; - - builder.DrawPath(path, paint); - auto display_list = builder.Build(); - - DlDispatcher dispatcher; - display_list->Dispatch(dispatcher); - auto picture = dispatcher.EndRecordingAsPicture(); - - std::optional coverage = - GetCoverageOfFirstEntity(picture); - - ASSERT_TRUE(coverage.has_value()); - ASSERT_EQ(coverage.value_or(Rect::MakeMaximum()), - Rect::MakeLTRB(-5, -5, 5, 5)); -} - #ifdef IMPELLER_ENABLE_3D TEST_P(DisplayListTest, SceneColorSource) { // Load up the scene. diff --git a/engine/src/flutter/impeller/golden_tests/golden_playground_test_mac.cc b/engine/src/flutter/impeller/golden_tests/golden_playground_test_mac.cc index 8893b4e784..7294cead6c 100644 --- a/engine/src/flutter/impeller/golden_tests/golden_playground_test_mac.cc +++ b/engine/src/flutter/impeller/golden_tests/golden_playground_test_mac.cc @@ -58,55 +58,6 @@ const std::unique_ptr& GetSharedVulkanPlayground( } } -#if EXPERIMENTAL_CANVAS -std::shared_ptr DisplayListToTexture( - sk_sp& display_list, - ISize size, - AiksContext& context) { - // Do not use the render target cache as the lifecycle of this texture - // will outlive a particular frame. - impeller::RenderTargetAllocator render_target_allocator = - impeller::RenderTargetAllocator( - context.GetContext()->GetResourceAllocator()); - impeller::RenderTarget target; - if (context.GetContext()->GetCapabilities()->SupportsOffscreenMSAA()) { - target = render_target_allocator.CreateOffscreenMSAA( - *context.GetContext(), // context - size, // size - /*mip_count=*/1, - "Picture Snapshot MSAA", // label - impeller::RenderTarget:: - kDefaultColorAttachmentConfigMSAA // color_attachment_config - ); - } else { - target = render_target_allocator.CreateOffscreen( - *context.GetContext(), // context - size, // size - /*mip_count=*/1, - "Picture Snapshot", // label - impeller::RenderTarget:: - kDefaultColorAttachmentConfig // color_attachment_config - ); - } - - SkIRect sk_cull_rect = SkIRect::MakeWH(size.width, size.height); - impeller::TextFrameDispatcher collector(context.GetContentContext(), - impeller::Matrix()); - display_list->Dispatch(collector, sk_cull_rect); - impeller::ExperimentalDlDispatcher impeller_dispatcher( - context.GetContentContext(), target, - display_list->root_has_backdrop_filter(), - display_list->max_root_blend_mode(), impeller::IRect::MakeSize(size)); - display_list->Dispatch(impeller_dispatcher, sk_cull_rect); - impeller_dispatcher.FinishRecording(); - - context.GetContentContext().GetTransientsBuffer().Reset(); - context.GetContentContext().GetLazyGlyphAtlas()->ResetTextFrames(); - - return target.GetRenderTargetTexture(); -} -#endif // EXPERIMENTAL_CANVAS - } // namespace #define IMP_AIKSTEST(name) \ @@ -399,6 +350,10 @@ std::unique_ptr GoldenPlaygroundTest::MakeScreenshot( const sk_sp& list) { AiksContext renderer(GetContext(), typographer_context_); +#if EXPERIMENTAL_CANVAS + return pimpl_->screenshotter->MakeScreenshot( + renderer, DisplayListToTexture(list, pimpl_->window_size, renderer)); +#else DlDispatcher dispatcher; list->Dispatch(dispatcher); Picture picture = dispatcher.EndRecordingAsPicture(); @@ -408,6 +363,7 @@ std::unique_ptr GoldenPlaygroundTest::MakeScreenshot( pimpl_->window_size); return screenshot; +#endif // EXPERIMENTAL_CANVAS } } // namespace impeller diff --git a/engine/src/flutter/shell/common/rasterizer.cc b/engine/src/flutter/shell/common/rasterizer.cc index 6239e22192..1a1623d285 100644 --- a/engine/src/flutter/shell/common/rasterizer.cc +++ b/engine/src/flutter/shell/common/rasterizer.cc @@ -925,13 +925,22 @@ ScreenshotLayerTreeAsImageImpeller( RenderFrameForScreenshot(compositor_context, &builder, tree, nullptr, aiks_context); + std::shared_ptr texture; +#if EXPERIMENTAL_CANVAS + texture = impeller::DisplayListToTexture( + builder.Build(), + impeller::ISize(tree->frame_size().fWidth, tree->frame_size().fHeight), + *aiks_context); +#else impeller::DlDispatcher dispatcher; builder.Build()->Dispatch(dispatcher); const auto& picture = dispatcher.EndRecordingAsPicture(); const auto& image = picture.ToImage( *aiks_context, impeller::ISize(tree->frame_size().fWidth, tree->frame_size().fHeight)); - const auto& texture = image->GetTexture(); + texture = image->GetTexture(); +#endif // EXPERIMENTAL_CANVAS + impeller::DeviceBufferDescriptor buffer_desc; buffer_desc.storage_mode = impeller::StorageMode::kHostVisible; buffer_desc.size = diff --git a/engine/src/flutter/shell/gpu/gpu_surface_gl_impeller.cc b/engine/src/flutter/shell/gpu/gpu_surface_gl_impeller.cc index 763956ebc4..da51753d00 100644 --- a/engine/src/flutter/shell/gpu/gpu_surface_gl_impeller.cc +++ b/engine/src/flutter/shell/gpu/gpu_surface_gl_impeller.cc @@ -98,7 +98,7 @@ std::unique_ptr GPUSurfaceGLImpeller::AcquireFrame( impeller::ISize{size.width(), size.height()} // fbo_size ); - const impeller::RenderTarget& render_target = + impeller::RenderTarget render_target = surface->GetTargetRenderPassDescriptor(); SurfaceFrame::EncodeCallback encode_calback = @@ -117,13 +117,35 @@ std::unique_ptr GPUSurfaceGLImpeller::AcquireFrame( auto cull_rect = render_target.GetRenderTargetSize(); impeller::Rect dl_cull_rect = impeller::Rect::MakeSize(cull_rect); + const bool reset_host_buffer = surface_frame.submit_info().frame_boundary; + +#if EXPERIMENTAL_CANVAS + auto skia_cull_rect = SkIRect::MakeWH(cull_rect.width, cull_rect.height); + impeller::TextFrameDispatcher collector(aiks_context->GetContentContext(), + impeller::Matrix()); + display_list->Dispatch(collector, skia_cull_rect); + + impeller::ExperimentalDlDispatcher impeller_dispatcher( + aiks_context->GetContentContext(), render_target, + display_list->root_has_backdrop_filter(), + display_list->max_root_blend_mode(), + impeller::IRect::MakeSize(cull_rect)); + display_list->Dispatch(impeller_dispatcher, skia_cull_rect); + impeller_dispatcher.FinishRecording(); + aiks_context->GetContentContext().GetLazyGlyphAtlas()->ResetTextFrames(); + if (reset_host_buffer) { + aiks_context->GetContentContext().GetTransientsBuffer().Reset(); + } + return true; +#else impeller::DlDispatcher impeller_dispatcher(dl_cull_rect); display_list->Dispatch(impeller_dispatcher, SkIRect::MakeWH(cull_rect.width, cull_rect.height)); auto picture = impeller_dispatcher.EndRecordingAsPicture(); - const bool reset_host_buffer = surface_frame.submit_info().frame_boundary; return aiks_context->Render(picture, render_target, reset_host_buffer); + +#endif // EXPERIMENTAL_CANVAS }; return std::make_unique( diff --git a/engine/src/flutter/shell/platform/embedder/embedder_external_view.cc b/engine/src/flutter/shell/platform/embedder/embedder_external_view.cc index 349f77fcc9..3541ca7c9c 100644 --- a/engine/src/flutter/shell/platform/embedder/embedder_external_view.cc +++ b/engine/src/flutter/shell/platform/embedder/embedder_external_view.cc @@ -129,7 +129,7 @@ bool EmbedderExternalView::Render(const EmbedderRenderTarget& render_target, slice_->render_into(&dl_builder); auto display_list = dl_builder.Build(); -#if ENABLE_EXPERIMENTAL_CANVAS +#if EXPERIMENTAL_CANVAS auto cull_rect = impeller::IRect::MakeSize(impeller_target->GetRenderTargetSize()); SkIRect sk_cull_rect = diff --git a/engine/src/flutter/testing/impeller_golden_tests_output.txt b/engine/src/flutter/testing/impeller_golden_tests_output.txt index 70fb554fb3..f1a7ce4f93 100644 --- a/engine/src/flutter/testing/impeller_golden_tests_output.txt +++ b/engine/src/flutter/testing/impeller_golden_tests_output.txt @@ -532,6 +532,9 @@ impeller_Play_AiksTest_CoordinateConversionsAreCorrect_Vulkan.png impeller_Play_AiksTest_CoverageOriginShouldBeAccountedForInSubpasses_Metal.png impeller_Play_AiksTest_CoverageOriginShouldBeAccountedForInSubpasses_OpenGLES.png impeller_Play_AiksTest_CoverageOriginShouldBeAccountedForInSubpasses_Vulkan.png +impeller_Play_AiksTest_DispatcherDoesNotCullPerspectiveTransformedChildDisplayLists_Metal.png +impeller_Play_AiksTest_DispatcherDoesNotCullPerspectiveTransformedChildDisplayLists_OpenGLES.png +impeller_Play_AiksTest_DispatcherDoesNotCullPerspectiveTransformedChildDisplayLists_Vulkan.png impeller_Play_AiksTest_DrawAdvancedBlendPartlyOffscreen_Metal.png impeller_Play_AiksTest_DrawAdvancedBlendPartlyOffscreen_OpenGLES.png impeller_Play_AiksTest_DrawAdvancedBlendPartlyOffscreen_Vulkan.png @@ -846,6 +849,9 @@ impeller_Play_AiksTest_TranslucentSaveLayerWithColorMatrixColorFilterDrawsCorrec impeller_Play_AiksTest_TranslucentSaveLayerWithColorMatrixImageFilterDrawsCorrectly_Metal.png impeller_Play_AiksTest_TranslucentSaveLayerWithColorMatrixImageFilterDrawsCorrectly_OpenGLES.png impeller_Play_AiksTest_TranslucentSaveLayerWithColorMatrixImageFilterDrawsCorrectly_Vulkan.png +impeller_Play_AiksTest_TransparentShadowProducesCorrectColor_Metal.png +impeller_Play_AiksTest_TransparentShadowProducesCorrectColor_OpenGLES.png +impeller_Play_AiksTest_TransparentShadowProducesCorrectColor_Vulkan.png impeller_Play_AiksTest_VerifyNonOptimizedGradient_Metal.png impeller_Play_AiksTest_VerifyNonOptimizedGradient_OpenGLES.png impeller_Play_AiksTest_VerifyNonOptimizedGradient_Vulkan.png