@@ -29,6 +29,70 @@ TEST(DisplayListImageFilter, LocalImageSkiaNull) {
2929 ASSERT_EQ (ToSk (dl_local_matrix_filter), nullptr );
3030}
3131
32+ // This test exists just to confirm and demonstrate how to convert existing
33+ // SkMatrix construction code into the same operations using the replacement
34+ // DlMatrix/impeller::Matrix objects.
35+ //
36+ // To be clear, it verifies:
37+ // SkMatrix.pre<Op>(data) is the same as DlMatrix * DlMatrix::Make<Op>(data).
38+ // SkMatrix1.preConcat(SkMatrix2) is the same as DlMatrix1 * DlMatrix2.
39+ TEST (DisplayListSkConversions, OpOrderPreMethodsVsMatrixMultiply) {
40+ // If you have code like this...
41+ const SkMatrix sk_matrix =
42+ SkMatrix ().preTranslate (0 , 800 ).preRotate (-90 , 0 , 0 );
43+
44+ // Convert it to math like this (same order as the pre<Op>() calls)...
45+ const DlMatrix dl_matrix = DlMatrix::MakeTranslation ({0 , 800 }) *
46+ DlMatrix::MakeRotationZ (DlDegrees (-90 ));
47+ SkPoint sk_result = sk_matrix.mapPoint ({10 , 10 });
48+ DlPoint dl_result = dl_matrix * DlPoint (10 , 10 );
49+ EXPECT_FLOAT_EQ (sk_result.fX , dl_result.x );
50+ EXPECT_FLOAT_EQ (sk_result.fY , dl_result.y );
51+
52+ // Not like this...
53+ const DlMatrix dl_matrix_2 = DlMatrix::MakeRotationZ (DlDegrees (-90 )) *
54+ DlMatrix::MakeTranslation ({0 , 800 });
55+ DlPoint dl_result_2 = dl_matrix_2 * DlPoint (10 , 10 );
56+ EXPECT_FALSE (impeller::ScalarNearlyEqual (sk_result.fX , dl_result_2.x ));
57+ EXPECT_FALSE (impeller::ScalarNearlyEqual (sk_result.fY , dl_result_2.y ));
58+
59+ // -------------------------------------------------------------------
60+
61+ // And if you have this...
62+ SkMatrix sk_matrix_2;
63+ sk_matrix_2.preConcat (SkMatrix::Translate (0 , 800 ));
64+ sk_matrix_2.preConcat (SkMatrix::RotateDeg (-90 ));
65+
66+ // It's really the same as the above case, btw...
67+ SkPoint sk_result_2 = sk_matrix_2.mapPoint ({10 , 10 });
68+ EXPECT_FLOAT_EQ (sk_result.fX , sk_result_2.fX );
69+ EXPECT_FLOAT_EQ (sk_result.fY , sk_result_2.fY );
70+
71+ // Convert it to math like this (same order as the pre<Op>() calls)...
72+ DlMatrix dl_matrix_3;
73+ dl_matrix_3 = dl_matrix_3 * DlMatrix::MakeTranslation ({0 , 800 });
74+ dl_matrix_3 = dl_matrix_3 * DlMatrix::MakeRotationZ (DlDegrees (-90 ));
75+ DlPoint dl_result_3 = dl_matrix_3 * DlPoint (10 , 10 );
76+ EXPECT_FLOAT_EQ (sk_result_2.fX , dl_result_3.x );
77+ EXPECT_FLOAT_EQ (sk_result_2.fY , dl_result_3.y );
78+
79+ // Which is also the same result as the first case above...
80+ EXPECT_FLOAT_EQ (dl_result_3.x , dl_result.x );
81+ EXPECT_FLOAT_EQ (dl_result_3.y , dl_result.y );
82+
83+ // Not like this...
84+ DlMatrix dl_matrix_4;
85+ dl_matrix_4 = dl_matrix_4 * DlMatrix::MakeRotationZ (DlDegrees (-90 ));
86+ dl_matrix_4 = dl_matrix_4 * DlMatrix::MakeTranslation ({0 , 800 });
87+ DlPoint dl_result_4 = dl_matrix_4 * DlPoint (10 , 10 );
88+ EXPECT_FALSE (impeller::ScalarNearlyEqual (sk_result_2.fX , dl_result_4.x ));
89+ EXPECT_FALSE (impeller::ScalarNearlyEqual (sk_result_2.fY , dl_result_4.y ));
90+
91+ // Which is also the same result as the second case above...
92+ EXPECT_FLOAT_EQ (dl_result_4.x , dl_result_2.x );
93+ EXPECT_FLOAT_EQ (dl_result_4.y , dl_result_2.y );
94+ }
95+
3296TEST (DisplayListSkConversions, ToSkColor) {
3397 // Red
3498 ASSERT_EQ (ToSkColor (DlColor::kRed ()), SK_ColorRED);
0 commit comments