@@ -581,49 +581,46 @@ class _CanvasPool extends _SaveStackTracking {
581
581
582
582
void drawShadow (ui.Path path, ui.Color color, double elevation,
583
583
bool transparentOccluder) {
584
- final List <CanvasShadow > shadows =
585
- ElevationShadow .computeCanvasShadows (elevation, color);
586
- if (shadows.isNotEmpty) {
587
- for (final CanvasShadow shadow in shadows) {
588
- // TODO(het): Shadows with transparent occluders are not supported
589
- // on webkit since filter is unsupported.
590
- if (transparentOccluder && browserEngine != BrowserEngine .webkit) {
591
- // We paint shadows using a path and a mask filter instead of the
592
- // built-in shadow* properties. This is because the color alpha of the
593
- // paint is added to the shadow. The effect we're looking for is to just
594
- // paint the shadow without the path itself, but if we use a non-zero
595
- // alpha for the paint the path is painted in addition to the shadow,
596
- // which is undesirable.
597
- context.save ();
598
- context.translate (shadow.offsetX, shadow.offsetY);
599
- context.filter = _maskFilterToCss (
600
- ui.MaskFilter .blur (ui.BlurStyle .normal, shadow.blur));
601
- context.strokeStyle = '' ;
602
- context.fillStyle = colorToCssString (shadow.color);
603
- _runPath (context, path);
604
- context.fill ();
605
- context.restore ();
606
- } else {
607
- // TODO(het): We fill the path with this paint, then later we clip
608
- // by the same path and fill it with a fully opaque color (we know
609
- // the color is fully opaque because `transparentOccluder` is false.
610
- // However, due to anti-aliasing of the clip, a few pixels of the
611
- // path we are about to paint may still be visible after we fill with
612
- // the opaque occluder. For that reason, we fill with the shadow color,
613
- // and set the shadow color to fully opaque. This way, the visible
614
- // pixels are less opaque and less noticeable.
615
- context.save ();
616
- context.filter = 'none' ;
617
- context.strokeStyle = '' ;
618
- context.fillStyle = colorToCssString (shadow.color);
619
- context.shadowBlur = shadow.blur;
620
- context.shadowColor = colorToCssString (shadow.color.withAlpha (0xff ));
621
- context.shadowOffsetX = shadow.offsetX;
622
- context.shadowOffsetY = shadow.offsetY;
623
- _runPath (context, path);
624
- context.fill ();
625
- context.restore ();
626
- }
584
+ final SurfaceShadowData shadow = computeShadow (path.getBounds (), elevation);
585
+ if (shadow != null ) {
586
+ // TODO(het): Shadows with transparent occluders are not supported
587
+ // on webkit since filter is unsupported.
588
+ if (transparentOccluder && browserEngine != BrowserEngine .webkit) {
589
+ // We paint shadows using a path and a mask filter instead of the
590
+ // built-in shadow* properties. This is because the color alpha of the
591
+ // paint is added to the shadow. The effect we're looking for is to just
592
+ // paint the shadow without the path itself, but if we use a non-zero
593
+ // alpha for the paint the path is painted in addition to the shadow,
594
+ // which is undesirable.
595
+ context.save ();
596
+ context.translate (shadow.offset.dx, shadow.offset.dy);
597
+ context.filter = _maskFilterToCss (
598
+ ui.MaskFilter .blur (ui.BlurStyle .normal, shadow.blurWidth));
599
+ context.strokeStyle = '' ;
600
+ context.fillStyle = colorToCssString (color);
601
+ _runPath (context, path);
602
+ context.fill ();
603
+ context.restore ();
604
+ } else {
605
+ // TODO(het): We fill the path with this paint, then later we clip
606
+ // by the same path and fill it with a fully opaque color (we know
607
+ // the color is fully opaque because `transparentOccluder` is false.
608
+ // However, due to anti-aliasing of the clip, a few pixels of the
609
+ // path we are about to paint may still be visible after we fill with
610
+ // the opaque occluder. For that reason, we fill with the shadow color,
611
+ // and set the shadow color to fully opaque. This way, the visible
612
+ // pixels are less opaque and less noticeable.
613
+ context.save ();
614
+ context.filter = 'none' ;
615
+ context.strokeStyle = '' ;
616
+ context.fillStyle = colorToCssString (color);
617
+ context.shadowBlur = shadow.blurWidth;
618
+ context.shadowColor = colorToCssString (color.withAlpha (0xff ));
619
+ context.shadowOffsetX = shadow.offset.dx;
620
+ context.shadowOffsetY = shadow.offset.dy;
621
+ _runPath (context, path);
622
+ context.fill ();
623
+ context.restore ();
627
624
}
628
625
}
629
626
}
0 commit comments