From 6bd25a9256f53cc7210b597259e9b9c19df441ad Mon Sep 17 00:00:00 2001 From: Jason Simmons Date: Fri, 26 May 2023 07:31:26 -0700 Subject: [PATCH] Apply the drawShadow bounds workaround to the Web HTML backend (flutter/engine#42304) Previously the Flutter framework had been inflating the rectangle computed for the bounds of a drawShadow operation in order to work around potential inaccuracies in the SkPicture's bounds calculation. That workaround is now obsolete for most platforms and was removed from the framework (see https://github.com/flutter/flutter/pull/127052). But the Web HTML backend is using different code for computing shadow bounds. This PR restores the workaround for Web HTML for consistency with the old behavior. --- engine/src/flutter/lib/web_ui/lib/src/engine/shadow.dart | 9 ++++++++- .../web_ui/test/html/recording_canvas_golden_test.dart | 2 +- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/engine/src/flutter/lib/web_ui/lib/src/engine/shadow.dart b/engine/src/flutter/lib/web_ui/lib/src/engine/shadow.dart index 7096d18f25c..f083d0e962d 100644 --- a/engine/src/flutter/lib/web_ui/lib/src/engine/shadow.dart +++ b/engine/src/flutter/lib/web_ui/lib/src/engine/shadow.dart @@ -73,12 +73,19 @@ ui.Rect computePenumbraBounds(ui.Rect shape, double elevation) { final double dx = elevation * tx; final double dy = elevation * ty; final ui.Offset offset = computeShadowOffset(elevation); - return ui.Rect.fromLTRB( + final ui.Rect bounds = ui.Rect.fromLTRB( shape.left - dx, shape.top - dy, shape.right + dx, shape.bottom + dy, ).shift(offset); + + // Expand the bounds rectangle to compensate for inaccuracy in the shadow + // calculation. This is similar to a workaround that had previously been + // used in the Flutter framework to adjust the bounds for shadows drawn + // by Skia. + // (See https://github.com/flutter/flutter/pull/127052) + return bounds.inflate(20); } /// Information needed to render a shadow using CSS or canvas. diff --git a/engine/src/flutter/lib/web_ui/test/html/recording_canvas_golden_test.dart b/engine/src/flutter/lib/web_ui/test/html/recording_canvas_golden_test.dart index 47fa8dabd0f..8326648b4b0 100644 --- a/engine/src/flutter/lib/web_ui/test/html/recording_canvas_golden_test.dart +++ b/engine/src/flutter/lib/web_ui/test/html/recording_canvas_golden_test.dart @@ -416,7 +416,7 @@ Future testMain() async { expect( rc.pictureBounds, within( - distance: 0.05, from: const Rect.fromLTRB(17.9, 28.5, 103.5, 114.1)), + distance: 0.05, from: const Rect.fromLTRB(0.0, 8.5, 123.5, 134.1)), ); await checkScreenshot(rc, 'path_with_shadow'); });