Merge "Expand the displayFrame for shadows" into sc-dev
diff --git a/services/surfaceflinger/CompositionEngine/src/OutputLayer.cpp b/services/surfaceflinger/CompositionEngine/src/OutputLayer.cpp
index e4e46a7..56e9d27 100644
--- a/services/surfaceflinger/CompositionEngine/src/OutputLayer.cpp
+++ b/services/surfaceflinger/CompositionEngine/src/OutputLayer.cpp
@@ -216,8 +216,18 @@
// reduce uses a FloatRect to provide more accuracy during the
// transformation. We then round upon constructing 'frame'.
- Rect frame{
- layerTransform.transform(reduce(layerState.geomLayerBounds, activeTransparentRegion))};
+ FloatRect geomLayerBounds = layerState.geomLayerBounds;
+
+ // Some HWCs may clip client composited input to its displayFrame. Make sure
+ // that this does not cut off the shadow.
+ if (layerState.forceClientComposition && layerState.shadowRadius > 0.0f) {
+ const auto outset = layerState.shadowRadius;
+ geomLayerBounds.left -= outset;
+ geomLayerBounds.top -= outset;
+ geomLayerBounds.right += outset;
+ geomLayerBounds.bottom += outset;
+ }
+ Rect frame{layerTransform.transform(reduce(geomLayerBounds, activeTransparentRegion))};
if (!frame.intersect(outputState.layerStackSpace.content, &frame)) {
frame.clear();
}
diff --git a/services/surfaceflinger/CompositionEngine/tests/OutputLayerTest.cpp b/services/surfaceflinger/CompositionEngine/tests/OutputLayerTest.cpp
index e9ecf3e..c8c6012 100644
--- a/services/surfaceflinger/CompositionEngine/tests/OutputLayerTest.cpp
+++ b/services/surfaceflinger/CompositionEngine/tests/OutputLayerTest.cpp
@@ -324,6 +324,27 @@
EXPECT_THAT(calculateOutputDisplayFrame(), expected);
}
+TEST_F(OutputLayerDisplayFrameTest, shadowExpandsDisplayFrame) {
+ const int kShadowRadius = 5;
+ mLayerFEState.shadowRadius = kShadowRadius;
+ mLayerFEState.forceClientComposition = true;
+
+ mLayerFEState.geomLayerBounds = FloatRect{100.f, 100.f, 200.f, 200.f};
+ Rect expected{mLayerFEState.geomLayerBounds};
+ expected.inset(-kShadowRadius, -kShadowRadius, -kShadowRadius, -kShadowRadius);
+ EXPECT_THAT(calculateOutputDisplayFrame(), expected);
+}
+
+TEST_F(OutputLayerDisplayFrameTest, shadowExpandsDisplayFrame_onlyIfForcingClientComposition) {
+ const int kShadowRadius = 5;
+ mLayerFEState.shadowRadius = kShadowRadius;
+ mLayerFEState.forceClientComposition = false;
+
+ mLayerFEState.geomLayerBounds = FloatRect{100.f, 100.f, 200.f, 200.f};
+ Rect expected{mLayerFEState.geomLayerBounds};
+ EXPECT_THAT(calculateOutputDisplayFrame(), expected);
+}
+
/*
* OutputLayer::calculateOutputRelativeBufferTransform()
*/