@@ -887,6 +887,7 @@ void SkiaRenderEngine::drawLayersInternal(
887887 const auto [bounds, roundRectClip] =
888888 getBoundsAndClip (layer.geometry .boundaries , layer.geometry .roundedCornersCrop ,
889889 layer.geometry .roundedCornersRadius );
890+
890891 if (mBlurFilter && layerHasBlur (layer, ctModifiesAlpha)) {
891892 std::unordered_map<uint32_t , sk_sp<SkImage>> cachedBlurs;
892893
@@ -963,66 +964,82 @@ void SkiaRenderEngine::drawLayersInternal(
963964 }
964965 }
965966
966- if (layer.shadow .length > 0 ) {
967- // This would require a new parameter/flag to SkShadowUtils::DrawShadow
968- LOG_ALWAYS_FATAL_IF (layer.disableBlending , " Cannot disableBlending with a shadow" );
969-
970- SkRRect shadowBounds, shadowClip;
971- if (layer.geometry .boundaries == layer.shadow .boundaries ) {
972- shadowBounds = bounds;
973- shadowClip = roundRectClip;
974- } else {
975- std::tie (shadowBounds, shadowClip) =
976- getBoundsAndClip (layer.shadow .boundaries , layer.geometry .roundedCornersCrop ,
977- layer.geometry .roundedCornersRadius );
967+ {
968+ SkRRect otherCrop;
969+ otherCrop.setRectXY (getSkRect (layer.geometry .otherCrop ),
970+ layer.geometry .otherRoundedCornersRadius .x ,
971+ layer.geometry .otherRoundedCornersRadius .y );
972+ // Outset rendering needs to be clipped by parent.
973+ SkAutoCanvasRestore acr (canvas, true );
974+ if (!otherCrop.isEmpty ()) {
975+ canvas->clipRRect (otherCrop, true );
978976 }
979977
980- // Technically, if bounds is a rect and roundRectClip is not empty,
981- // it means that the bounds and roundedCornersCrop were different
982- // enough that we should intersect them to find the proper shadow.
983- // In practice, this often happens when the two rectangles appear to
984- // not match due to rounding errors. Draw the rounded version, which
985- // looks more like the intent.
986- const auto & rrect =
987- shadowBounds.isRect () && !shadowClip.isEmpty () ? shadowClip : shadowBounds;
988- drawShadow (canvas, rrect, layer.shadow );
989- }
978+ if (layer.shadow .length > 0 ) {
979+ // This would require a new parameter/flag to SkShadowUtils::DrawShadow
980+ LOG_ALWAYS_FATAL_IF (layer.disableBlending , " Cannot disableBlending with a shadow" );
981+
982+ SkRRect shadowBounds, shadowClip;
983+ if (layer.geometry .boundaries == layer.shadow .boundaries ) {
984+ shadowBounds = bounds;
985+ shadowClip = roundRectClip;
986+ } else {
987+ std::tie (shadowBounds, shadowClip) =
988+ getBoundsAndClip (layer.shadow .boundaries ,
989+ layer.geometry .roundedCornersCrop ,
990+ layer.geometry .roundedCornersRadius );
991+ }
990992
991- // TODO(b/367464660): Move this code above and
992- // update elevation shadow rendering to use these bounds since they should be
993- // identical.
994- SkRRect originalBounds, originalClip;
995- std::tie (originalBounds, originalClip) =
996- getBoundsAndClip (layer.geometry .originalBounds , layer.geometry .roundedCornersCrop ,
997- layer.geometry .roundedCornersRadius );
998- const SkRRect& preferredOriginalBounds =
999- originalBounds.isRect () && !originalClip.isEmpty () ? originalClip : originalBounds;
993+ // Technically, if bounds is a rect and roundRectClip is not empty,
994+ // it means that the bounds and roundedCornersCrop were different
995+ // enough that we should intersect them to find the proper shadow.
996+ // In practice, this often happens when the two rectangles appear to
997+ // not match due to rounding errors. Draw the rounded version, which
998+ // looks more like the intent.
999+ const auto & rrect =
1000+ shadowBounds.isRect () && !shadowClip.isEmpty () ? shadowClip : shadowBounds;
1001+ drawShadow (canvas, rrect, layer.shadow );
1002+ }
10001003
1001- // Similar to shadows, do the rendering before the clip is applied because even when the
1002- // layer is occluded it should have an outline.
1003- if (layer.borderSettings .strokeWidth > 0 ) {
1004- SkRRect outlineRect = preferredOriginalBounds;
1005- outlineRect.outset (layer.borderSettings .strokeWidth , layer.borderSettings .strokeWidth );
1004+ // TODO(b/367464660): Move this code above and
1005+ // update elevation shadow rendering to use these bounds since they should be
1006+ // identical.
1007+ SkRRect originalBounds, originalClip;
1008+ std::tie (originalBounds, originalClip) =
1009+ getBoundsAndClip (layer.geometry .originalBounds ,
1010+ layer.geometry .roundedCornersCrop ,
1011+ layer.geometry .roundedCornersRadius );
1012+ const SkRRect& preferredOriginalBounds =
1013+ originalBounds.isRect () && !originalClip.isEmpty () ? originalClip
1014+ : originalBounds;
1015+
1016+ // Similar to shadows, do the rendering before the clip is applied because even when the
1017+ // layer is occluded it should have an outline.
1018+ if (layer.borderSettings .strokeWidth > 0 ) {
1019+ SkRRect outlineRect = preferredOriginalBounds;
1020+ outlineRect.outset (layer.borderSettings .strokeWidth ,
1021+ layer.borderSettings .strokeWidth );
10061022
1007- SkPaint paint;
1008- paint.setAntiAlias (true );
1009- paint.setColor (layer.borderSettings .color );
1010- paint.setStyle (SkPaint::kFill_Style );
1011- canvas->drawDRRect (outlineRect, preferredOriginalBounds, paint);
1012- }
1023+ SkPaint paint;
1024+ paint.setAntiAlias (true );
1025+ paint.setColor (layer.borderSettings .color );
1026+ paint.setStyle (SkPaint::kFill_Style );
1027+ canvas->drawDRRect (outlineRect, preferredOriginalBounds, paint);
1028+ }
10131029
1014- if (!layer.boxShadowSettings .boxShadows .empty ()) {
1015- for (const gui::BoxShadowSettings::BoxShadowParams& box :
1016- layer.boxShadowSettings .boxShadows ) {
1017- SkRRect boxRect = preferredOriginalBounds;
1018- boxRect.outset (box.spreadRadius , box.spreadRadius );
1019- boxRect.offset (box.offsetX , box.offsetY );
1020- float sigma = convertBlurUserRadiusToSigma (box.blurRadius );
1021- SkPaint blur;
1022- blur.setAntiAlias (true );
1023- blur.setColor (box.color );
1024- blur.setMaskFilter (SkMaskFilter::MakeBlur (kNormal_SkBlurStyle , sigma, false ));
1025- canvas->drawRRect (boxRect, blur);
1030+ if (!layer.boxShadowSettings .boxShadows .empty ()) {
1031+ for (const gui::BoxShadowSettings::BoxShadowParams& box :
1032+ layer.boxShadowSettings .boxShadows ) {
1033+ SkRRect boxRect = preferredOriginalBounds;
1034+ boxRect.outset (box.spreadRadius , box.spreadRadius );
1035+ boxRect.offset (box.offsetX , box.offsetY );
1036+ float sigma = convertBlurUserRadiusToSigma (box.blurRadius );
1037+ SkPaint blur;
1038+ blur.setAntiAlias (true );
1039+ blur.setColor (box.color );
1040+ blur.setMaskFilter (SkMaskFilter::MakeBlur (kNormal_SkBlurStyle , sigma, false ));
1041+ canvas->drawRRect (boxRect, blur);
1042+ }
10261043 }
10271044 }
10281045
0 commit comments