@@ -930,5 +930,89 @@ TEST_P(AiksTest,
930930 ASSERT_TRUE (OpenPlaygroundHere (dl));
931931}
932932
933+ TEST_P (AiksTest, CanDrawPerspectiveConvexShadow) {
934+ DisplayListBuilder builder;
935+ builder.Clear (DlColor::kWhite ());
936+ builder.Scale (GetContentScale ().x , GetContentScale ().y );
937+
938+ // The rect path should be optimized to a rect-specific shadow shader.
939+ DlPath rect_path = DlPath::MakeRectLTRB (-50 , -50 , 50 , 75 );
940+
941+ // The pentagon path should go through the general convex path shadow
942+ // tessellator.
943+ DlPathBuilder path_builder;
944+ path_builder.MoveTo (DlPoint (-50 , -50 ));
945+ path_builder.LineTo (DlPoint (50 , -50 ));
946+ path_builder.LineTo (DlPoint (50 , 50 ));
947+ path_builder.LineTo (DlPoint (0 , 75 ));
948+ path_builder.LineTo (DlPoint (-50 , 50 ));
949+ path_builder.Close ();
950+ DlPath pentagon_path = path_builder.TakePath ();
951+
952+ Matrix simple_y_rotate_matrix = Matrix::MakeRotationY (Degrees (45 ));
953+
954+ Matrix perspective_matrix;
955+ perspective_matrix.e [2 ][3 ] = 0 .0015f ;
956+ perspective_matrix = perspective_matrix * simple_y_rotate_matrix;
957+
958+ auto draw_paths_and_shadows = [&builder](const DlPath& path,
959+ const DlColor& color,
960+ const Matrix& matrix) {
961+ builder.Save ();
962+
963+ DlPaint paint;
964+ paint.setColor (color.withAlphaF (0 .25f ));
965+
966+ DlPaint shadow_paint;
967+ shadow_paint.setMaskFilter (
968+ DlBlurMaskFilter::Make (DlBlurStyle::kNormal , 10 .0f ));
969+
970+ builder.Save ();
971+ builder.Transform (matrix);
972+ builder.DrawPath (path, paint);
973+ builder.Restore ();
974+
975+ builder.Translate (150 , 0 );
976+
977+ builder.Save ();
978+ builder.Transform (matrix);
979+ builder.DrawPath (path, shadow_paint);
980+ builder.Restore ();
981+
982+ builder.Translate (150 , 0 );
983+
984+ builder.Save ();
985+ builder.Transform (matrix);
986+ builder.DrawPath (path, shadow_paint);
987+ builder.DrawPath (path, paint);
988+ builder.Restore ();
989+
990+ builder.Restore ();
991+ };
992+
993+ auto draw_test = [&](const DlPath& path) {
994+ builder.Save ();
995+
996+ builder.Translate (0 , 75 );
997+ builder.DrawPath (path, DlPaint (DlColor::kPurple ()));
998+
999+ builder.Translate (150 , -75 );
1000+ draw_paths_and_shadows (path, DlColor::kGreen (), simple_y_rotate_matrix);
1001+ builder.Translate (0 , 175 );
1002+ draw_paths_and_shadows (path, DlColor::kBlue (), perspective_matrix);
1003+
1004+ builder.Restore ();
1005+ };
1006+
1007+ builder.Translate (100 , 100 );
1008+
1009+ draw_test (rect_path);
1010+ builder.Translate (0 , 350 );
1011+ draw_test (pentagon_path);
1012+
1013+ auto dl = builder.Build ();
1014+ ASSERT_TRUE (OpenPlaygroundHere (dl));
1015+ }
1016+
9331017} // namespace testing
9341018} // namespace impeller
0 commit comments