diff --git a/engine/src/flutter/impeller/display_list/dl_dispatcher.cc b/engine/src/flutter/impeller/display_list/dl_dispatcher.cc index 9964e9e71e..9e71de28e1 100644 --- a/engine/src/flutter/impeller/display_list/dl_dispatcher.cc +++ b/engine/src/flutter/impeller/display_list/dl_dispatcher.cc @@ -1074,7 +1074,9 @@ void DlDispatcher::drawDisplayList( canvas_.SaveLayer(save_paint); } - if (display_list->has_rtree()) { + // TODO(131445): Remove this restriction if we can correctly cull with + // perspective transforms. + if (display_list->has_rtree() && !initial_matrix_.HasPerspective()) { // The canvas remembers the screen-space culling bounds clipped by // the surface and the history of clip calls. DisplayList can cull // the ops based on a rectangle expressed in its "destination bounds" diff --git a/engine/src/flutter/impeller/display_list/dl_unittests.cc b/engine/src/flutter/impeller/display_list/dl_unittests.cc index 98ddf75f7c..a902668baa 100644 --- a/engine/src/flutter/impeller/display_list/dl_unittests.cc +++ b/engine/src/flutter/impeller/display_list/dl_unittests.cc @@ -21,6 +21,7 @@ #include "impeller/display_list/dl_dispatcher.h" #include "impeller/display_list/dl_image_impeller.h" #include "impeller/display_list/dl_playground.h" +#include "impeller/entity/contents/solid_color_contents.h" #include "impeller/entity/contents/solid_rrect_blur_contents.h" #include "impeller/geometry/constants.h" #include "impeller/geometry/point.h" @@ -854,6 +855,42 @@ 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(); diff --git a/engine/src/flutter/impeller/geometry/matrix.h b/engine/src/flutter/impeller/geometry/matrix.h index 6938cf930f..119702f613 100644 --- a/engine/src/flutter/impeller/geometry/matrix.h +++ b/engine/src/flutter/impeller/geometry/matrix.h @@ -313,6 +313,10 @@ struct Matrix { m[9] == 0 && m[10] == 1 && m[11] == 0 && m[14] == 0 && m[15] == 1); } + constexpr bool HasPerspective() const { + return m[3] != 0 || m[7] != 0 || m[11] != 0 || m[15] != 1; + } + constexpr bool IsAligned(Scalar tolerance = 0) const { int v[] = {!ScalarNearlyZero(m[0], tolerance), // !ScalarNearlyZero(m[1], tolerance), //