@@ -124,8 +124,8 @@ TEST_F(PhysicalShapeLayerTest, ElevationSimple) {
124124 // The Fuchsia system compositor handles all elevated PhysicalShapeLayers and
125125 // their shadows , so we do not do any painting there.
126126 EXPECT_EQ (layer->paint_bounds (),
127- PhysicalShapeLayer::ComputeShadowBounds (layer_path. getBounds (),
128- initial_elevation, 1 .0f ));
127+ PhysicalShapeLayer::ComputeShadowBounds (
128+ layer_path, initial_elevation, 1 .0f , SkMatrix () ));
129129 EXPECT_TRUE (layer->needs_painting (paint_context ()));
130130 EXPECT_EQ (layer->elevation (), initial_elevation);
131131
@@ -174,8 +174,8 @@ TEST_F(PhysicalShapeLayerTest, ElevationComplex) {
174174 // there.
175175 EXPECT_EQ (layers[i]->paint_bounds (),
176176 (PhysicalShapeLayer::ComputeShadowBounds (
177- layer_path. getBounds () , initial_elevations[i],
178- 1 . 0f /* pixel_ratio */ )));
177+ layer_path, initial_elevations[i], 1 . 0f /* pixel_ratio */ ,
178+ SkMatrix () )));
179179 EXPECT_TRUE (layers[i]->needs_painting (paint_context ()));
180180 }
181181
@@ -200,6 +200,93 @@ TEST_F(PhysicalShapeLayerTest, ElevationComplex) {
200200 0 , MockCanvas::DrawPathData{layer_path, layer_paint}}}));
201201}
202202
203+ TEST_F (PhysicalShapeLayerTest, ShadowNotDependsCtm) {
204+ constexpr SkScalar elevations[] = {1 , 2 , 3 , 4 , 5 , 10 };
205+ constexpr SkScalar scales[] = {0.5 , 1 , 1.5 , 2 , 3 , 5 };
206+ constexpr SkScalar translates[] = {0 , 1 , -1 , 0.5 , 2 , 10 };
207+
208+ SkPath path;
209+ path.addRect (0 , 0 , 8 , 8 ).close ();
210+
211+ for (SkScalar elevation : elevations) {
212+ SkRect baseline_bounds = PhysicalShapeLayer::ComputeShadowBounds (
213+ path, elevation, 1 .0f , SkMatrix ());
214+ for (SkScalar scale : scales) {
215+ for (SkScalar translateX : translates) {
216+ for (SkScalar translateY : translates) {
217+ SkMatrix ctm;
218+ ctm.setScaleTranslate (scale, scale, translateX, translateY);
219+ SkRect bounds = PhysicalShapeLayer::ComputeShadowBounds (
220+ path, elevation, scale, ctm);
221+ EXPECT_FLOAT_EQ (bounds.fLeft , baseline_bounds.fLeft );
222+ EXPECT_FLOAT_EQ (bounds.fTop , baseline_bounds.fTop );
223+ EXPECT_FLOAT_EQ (bounds.fRight , baseline_bounds.fRight );
224+ EXPECT_FLOAT_EQ (bounds.fBottom , baseline_bounds.fBottom );
225+ }
226+ }
227+ }
228+ }
229+ }
230+
231+ static int RasterizedDifferenceInPixels (
232+ const std::function<void (SkCanvas*)>& actual_draw_function,
233+ const std::function<void(SkCanvas*)>& expected_draw_function,
234+ const SkSize& canvas_size) {
235+ sk_sp<SkSurface> actual_surface =
236+ SkSurface::MakeRasterN32Premul (canvas_size.width (), canvas_size.height ());
237+ sk_sp<SkSurface> expected_surface =
238+ SkSurface::MakeRasterN32Premul (canvas_size.width (), canvas_size.height ());
239+
240+ actual_surface->getCanvas ()->drawColor (SK_ColorWHITE);
241+ expected_surface->getCanvas ()->drawColor (SK_ColorWHITE);
242+
243+ actual_draw_function (actual_surface->getCanvas ());
244+ expected_draw_function (expected_surface->getCanvas ());
245+
246+ SkPixmap actual_pixels;
247+ EXPECT_TRUE (actual_surface->peekPixels (&actual_pixels));
248+
249+ SkPixmap expected_pixels;
250+ EXPECT_TRUE (expected_surface->peekPixels (&expected_pixels));
251+
252+ int different_pixels = 0 ;
253+ for (int y = 0 ; y < canvas_size.height (); y++) {
254+ const uint32_t * actual_row = actual_pixels.addr32 (0 , y);
255+ const uint32_t * expected_row = expected_pixels.addr32 (0 , y);
256+ for (int x = 0 ; x < canvas_size.width (); x++) {
257+ if (actual_row[x] != expected_row[x]) {
258+ different_pixels++;
259+ }
260+ }
261+ }
262+ return different_pixels;
263+ }
264+
265+ TEST_F (PhysicalShapeLayerTest, ShadowNotDependsPathSize) {
266+ constexpr SkRect test_cases[][2 ] = {
267+ {{20 , -100 , 80 , 80 }, {20 , -1000 , 80 , 80 }},
268+ {{20 , 20 , 80 , 200 }, {20 , 20 , 80 , 2000 }},
269+ };
270+
271+ for (const SkRect* test_case : test_cases) {
272+ EXPECT_EQ (RasterizedDifferenceInPixels (
273+ [=](SkCanvas* canvas) {
274+ SkPath path;
275+ path.addRect (test_case[0 ]).close ();
276+ PhysicalShapeLayer::DrawShadow (canvas, path, SK_ColorBLACK,
277+ 1 .0f , false , 1 .0f );
278+ },
279+ [=](SkCanvas* canvas) {
280+ SkPath path;
281+ path.addRect (test_case[1 ]).close ();
282+ PhysicalShapeLayer::DrawShadow (canvas, path, SK_ColorBLACK,
283+ 1 .0f , false , 1 .0f );
284+ },
285+ SkSize::Make (100 , 100 )),
286+ 0 );
287+ }
288+ }
289+
203290static bool ReadbackResult (PrerollContext* context,
204291 Clip clip_behavior,
205292 std::shared_ptr<Layer> child,
0 commit comments