Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit f7a8076

Browse files
[canvaskit] Use DirectionalLight_Shadow flag for drawing shadows (#46292)
Use the DirectionalLight_Shadow flag when drawing shadows in CanvasKit. This fixes bugs with drawing shadows in tests with different device pixel ratios. ## Pre-launch Checklist - [x] I read the [Contributor Guide] and followed the process outlined there for submitting PRs. - [x] I read the [Tree Hygiene] wiki page, which explains my responsibilities. - [x] I read and followed the [Flutter Style Guide] and the [C++, Objective-C, Java style guides]. - [x] I listed at least one issue that this PR fixes in the description above. - [x] I added new tests to check the change I am making or feature I am adding, or the PR is [test-exempt]. See [testing the engine] for instructions on writing and running engine tests. - [x] I updated/added relevant documentation (doc comments with `///`). - [x] I signed the [CLA]. - [x] All existing and new tests are passing. If you need help, consider asking for advice on the #hackers-new channel on [Discord]. <!-- Links --> [Contributor Guide]: https://github.com/flutter/flutter/wiki/Tree-hygiene#overview [Tree Hygiene]: https://github.com/flutter/flutter/wiki/Tree-hygiene [test-exempt]: https://github.com/flutter/flutter/wiki/Tree-hygiene#tests [Flutter Style Guide]: https://github.com/flutter/flutter/wiki/Style-guide-for-Flutter-repo [C++, Objective-C, Java style guides]: https://github.com/flutter/engine/blob/main/CONTRIBUTING.md#style [testing the engine]: https://github.com/flutter/flutter/wiki/Testing-the-engine [CLA]: https://cla.developers.google.com/ [flutter/tests]: https://github.com/flutter/tests [breaking change policy]: https://github.com/flutter/flutter/wiki/Tree-hygiene#handling-breaking-changes [Discord]: https://github.com/flutter/flutter/wiki/Chat
1 parent 182739c commit f7a8076

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

lib/web_ui/lib/src/engine/canvaskit/util.dart

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -73,10 +73,10 @@ class SkiaShadowFlags {
7373
// material spec.
7474
const double ckShadowAmbientAlpha = 0.039;
7575
const double ckShadowSpotAlpha = 0.25;
76-
const double ckShadowLightRadius = 1.1;
77-
const double ckShadowLightHeight = 600.0;
7876
const double ckShadowLightXOffset = 0;
7977
const double ckShadowLightYOffset = -450;
78+
const double ckShadowLightHeight = 600;
79+
const double ckShadowLightRadius = 800;
8080
const double ckShadowLightXTangent = ckShadowLightXOffset / ckShadowLightHeight;
8181
const double ckShadowLightYTangent = ckShadowLightYOffset / ckShadowLightHeight;
8282

@@ -161,13 +161,15 @@ void drawSkShadow(
161161
bool transparentOccluder,
162162
double devicePixelRatio,
163163
) {
164-
final int flags = transparentOccluder
164+
int flags = transparentOccluder
165165
? SkiaShadowFlags.kTransparentOccluderShadowFlags
166166
: SkiaShadowFlags.kDefaultShadowFlags;
167+
flags |= SkiaShadowFlags.kDirectionalLight_ShadowFlag;
167168

168169
final ui.Color inAmbient =
169170
color.withAlpha((color.alpha * ckShadowAmbientAlpha).round());
170-
final ui.Color inSpot = color.withAlpha((color.alpha * ckShadowSpotAlpha).round());
171+
final ui.Color inSpot =
172+
color.withAlpha((color.alpha * ckShadowSpotAlpha).round());
171173

172174
final SkTonalColors inTonalColors = SkTonalColors(
173175
ambient: makeFreshSkColor(inAmbient),
@@ -180,10 +182,10 @@ void drawSkShadow(
180182
path.skiaObject,
181183
Float32List(3)..[2] = devicePixelRatio * elevation,
182184
Float32List(3)
183-
..[0] = ckShadowLightXOffset
184-
..[1] = ckShadowLightYOffset
185-
..[2] = devicePixelRatio * ckShadowLightHeight,
186-
devicePixelRatio * ckShadowLightRadius,
185+
..[0] = 0
186+
..[1] = -1
187+
..[2] = 1,
188+
ckShadowLightRadius / ckShadowLightHeight,
187189
tonalColors.ambient,
188190
tonalColors.spot,
189191
flags.toDouble(),

0 commit comments

Comments
 (0)