Draw shadows when the casting layer is occluded or transparent
Ignore transparent region when generating the composition layer for shadows. Client may
provide transparent region hints but the shadow should be drawn over the entire layer.
Solves an issue with YouTube in PiP which sets a transparent region where the
SurfaceView is shown causing a shadow of incorrect size to be drawn.
Draw shadows even if the layer is completely occluded by another layer. The layer will
not be composed in this case causing the shadow to not be drawn either. So extend its
visible region by the shadow length so we can check if the shadows will be occluded as
well.
Bug: 136561771
Test: atest libcompositionengine_test
Test: manual tests with pip overriding shadows to be drawn by sf
Change-Id: I4c6cae1716caebe46119ebd1643d8b5e3eda56c3
diff --git a/services/surfaceflinger/Layer.cpp b/services/surfaceflinger/Layer.cpp
index 35fc4be..8185775 100644
--- a/services/surfaceflinger/Layer.cpp
+++ b/services/surfaceflinger/Layer.cpp
@@ -430,6 +430,7 @@
compositionState.internalOnly = getPrimaryDisplayOnly();
compositionState.isVisible = isVisible();
compositionState.isOpaque = opaque && !usesRoundedCorners && alpha == 1.f;
+ compositionState.shadowRadius = mEffectiveShadowRadius;
compositionState.contentDirty = contentDirty;
contentDirty = false;
@@ -585,6 +586,7 @@
renderengine::LayerSettings shadowLayer = casterLayerSettings;
shadowLayer.shadow = shadow;
+ shadowLayer.geometry.boundaries = mBounds; // ignore transparent region
// If the casting layer is translucent, we need to fill in the shadow underneath the layer.
// Otherwise the generated shadow will only be shown around the casting layer.