Clean up duplicate shadow lengths in layer snapshot
The shadow length is currently tracked in both the LayerFE
CompositionState and the shadow settings, which are used by the
RenderEngine. We can consolidate these fields and track shadow
settings in the LayerFE CompositionState. This makes sense because
we want the LayerFE CompositionState to contain all relevant
information that it can pass to the RenderEngine without calling
back into the frontend.
Bug: 302551905
Test: presubmit
Change-Id: I583c43993cf73784c6fec9ec2d40f2c76d21adeb
diff --git a/services/surfaceflinger/CompositionEngine/include/compositionengine/LayerFECompositionState.h b/services/surfaceflinger/CompositionEngine/include/compositionengine/LayerFECompositionState.h
index 35ca3a5..11759b8 100644
--- a/services/surfaceflinger/CompositionEngine/include/compositionengine/LayerFECompositionState.h
+++ b/services/surfaceflinger/CompositionEngine/include/compositionengine/LayerFECompositionState.h
@@ -26,6 +26,7 @@
#include <ui/LayerStack.h>
#include <ui/Rect.h>
#include <ui/Region.h>
+#include <ui/ShadowSettings.h>
#include <ui/Transform.h>
// TODO(b/129481165): remove the #pragma below and fix conversion issues
@@ -132,8 +133,7 @@
// The bounds of the layer in layer local coordinates
FloatRect geomLayerBounds;
- // length of the shadow in screen space
- float shadowRadius{0.f};
+ ShadowSettings shadowSettings;
// List of regions that require blur
std::vector<BlurRegion> blurRegions;
diff --git a/services/surfaceflinger/CompositionEngine/src/LayerFECompositionState.cpp b/services/surfaceflinger/CompositionEngine/src/LayerFECompositionState.cpp
index 426cc57..2d10866 100644
--- a/services/surfaceflinger/CompositionEngine/src/LayerFECompositionState.cpp
+++ b/services/surfaceflinger/CompositionEngine/src/LayerFECompositionState.cpp
@@ -68,7 +68,7 @@
dumpVal(out, "geomLayerBounds", geomLayerBounds);
out.append(" ");
- dumpVal(out, "shadowRadius", shadowRadius);
+ dumpVal(out, "shadowLength", shadowSettings.length);
out.append("\n ");
dumpVal(out, "blend", toString(blendMode), blendMode);
diff --git a/services/surfaceflinger/CompositionEngine/src/Output.cpp b/services/surfaceflinger/CompositionEngine/src/Output.cpp
index 775e6d5..fa3733b 100644
--- a/services/surfaceflinger/CompositionEngine/src/Output.cpp
+++ b/services/surfaceflinger/CompositionEngine/src/Output.cpp
@@ -588,10 +588,10 @@
const Rect visibleRect(tr.transform(layerFEState->geomLayerBounds));
visibleRegion.set(visibleRect);
- if (layerFEState->shadowRadius > 0.0f) {
+ if (layerFEState->shadowSettings.length > 0.0f) {
// if the layer casts a shadow, offset the layers visible region and
// calculate the shadow region.
- const auto inset = static_cast<int32_t>(ceilf(layerFEState->shadowRadius) * -1.0f);
+ const auto inset = static_cast<int32_t>(ceilf(layerFEState->shadowSettings.length) * -1.0f);
Rect visibleRectWithShadows(visibleRect);
visibleRectWithShadows.inset(inset, inset, inset, inset);
visibleRegion.set(visibleRectWithShadows);
diff --git a/services/surfaceflinger/CompositionEngine/src/OutputLayer.cpp b/services/surfaceflinger/CompositionEngine/src/OutputLayer.cpp
index fe56969..7fe3369 100644
--- a/services/surfaceflinger/CompositionEngine/src/OutputLayer.cpp
+++ b/services/surfaceflinger/CompositionEngine/src/OutputLayer.cpp
@@ -222,8 +222,8 @@
// 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;
+ if (layerState.forceClientComposition && layerState.shadowSettings.length > 0.0f) {
+ const auto outset = layerState.shadowSettings.length;
geomLayerBounds.left -= outset;
geomLayerBounds.top -= outset;
geomLayerBounds.right += outset;
diff --git a/services/surfaceflinger/CompositionEngine/tests/OutputLayerTest.cpp b/services/surfaceflinger/CompositionEngine/tests/OutputLayerTest.cpp
index 630906a..1c54469 100644
--- a/services/surfaceflinger/CompositionEngine/tests/OutputLayerTest.cpp
+++ b/services/surfaceflinger/CompositionEngine/tests/OutputLayerTest.cpp
@@ -334,7 +334,7 @@
TEST_F(OutputLayerDisplayFrameTest, shadowExpandsDisplayFrame) {
const int kShadowRadius = 5;
- mLayerFEState.shadowRadius = kShadowRadius;
+ mLayerFEState.shadowSettings.length = kShadowRadius;
mLayerFEState.forceClientComposition = true;
mLayerFEState.geomLayerBounds = FloatRect{100.f, 100.f, 200.f, 200.f};
@@ -345,7 +345,7 @@
TEST_F(OutputLayerDisplayFrameTest, shadowExpandsDisplayFrame_onlyIfForcingClientComposition) {
const int kShadowRadius = 5;
- mLayerFEState.shadowRadius = kShadowRadius;
+ mLayerFEState.shadowSettings.length = kShadowRadius;
mLayerFEState.forceClientComposition = false;
mLayerFEState.geomLayerBounds = FloatRect{100.f, 100.f, 200.f, 200.f};
diff --git a/services/surfaceflinger/CompositionEngine/tests/OutputTest.cpp b/services/surfaceflinger/CompositionEngine/tests/OutputTest.cpp
index ee6998a..cdcb68d 100644
--- a/services/surfaceflinger/CompositionEngine/tests/OutputTest.cpp
+++ b/services/surfaceflinger/CompositionEngine/tests/OutputTest.cpp
@@ -1830,7 +1830,7 @@
ui::Transform translate;
translate.set(50, 50);
mLayer.layerFEState.geomLayerTransform = translate;
- mLayer.layerFEState.shadowRadius = 10.0f;
+ mLayer.layerFEState.shadowSettings.length = 10.0f;
mCoverageState.dirtyRegion = Region(Rect(0, 0, 500, 500));
// half of the layer including the casting shadow is covered and opaque
@@ -1872,7 +1872,7 @@
ui::Transform translate;
translate.set(50, 50);
mLayer.layerFEState.geomLayerTransform = translate;
- mLayer.layerFEState.shadowRadius = 10.0f;
+ mLayer.layerFEState.shadowSettings.length = 10.0f;
mCoverageState.dirtyRegion = Region(Rect(0, 0, 500, 500));
// Casting layer is covered by an opaque region leaving only part of its shadow to be drawn
@@ -1897,7 +1897,7 @@
ui::Transform translate;
translate.set(50, 50);
mLayer.layerFEState.geomLayerTransform = translate;
- mLayer.layerFEState.shadowRadius = 10.0f;
+ mLayer.layerFEState.shadowSettings.length = 10.0f;
mCoverageState.dirtyRegion = Region(Rect(0, 0, 500, 500));
// Casting layer and its shadows are covered by an opaque region
diff --git a/services/surfaceflinger/FrontEnd/LayerSnapshot.cpp b/services/surfaceflinger/FrontEnd/LayerSnapshot.cpp
index f9c8e81..7a85da0 100644
--- a/services/surfaceflinger/FrontEnd/LayerSnapshot.cpp
+++ b/services/surfaceflinger/FrontEnd/LayerSnapshot.cpp
@@ -382,7 +382,6 @@
sidebandStream = requested.sidebandStream;
}
if (forceUpdate || requested.what & layer_state_t::eShadowRadiusChanged) {
- shadowRadius = requested.shadowRadius;
shadowSettings.length = requested.shadowRadius;
}
if (forceUpdate || requested.what & layer_state_t::eFrameRateSelectionPriority) {
diff --git a/services/surfaceflinger/FrontEnd/LayerSnapshot.h b/services/surfaceflinger/FrontEnd/LayerSnapshot.h
index a1c72a9..80a51ea 100644
--- a/services/surfaceflinger/FrontEnd/LayerSnapshot.h
+++ b/services/surfaceflinger/FrontEnd/LayerSnapshot.h
@@ -69,7 +69,6 @@
RoundedCornerState roundedCorner;
FloatRect transformedBounds;
Rect transformedBoundsWithoutTransparentRegion;
- renderengine::ShadowSettings shadowSettings;
bool premultipliedAlpha;
ui::Transform parentTransform;
Rect bufferSize;
diff --git a/services/surfaceflinger/FrontEnd/LayerSnapshotBuilder.cpp b/services/surfaceflinger/FrontEnd/LayerSnapshotBuilder.cpp
index a1796e1..03c0993 100644
--- a/services/surfaceflinger/FrontEnd/LayerSnapshotBuilder.cpp
+++ b/services/surfaceflinger/FrontEnd/LayerSnapshotBuilder.cpp
@@ -353,7 +353,7 @@
snapshot.isSecure = false;
snapshot.color.a = 1.0_hf;
snapshot.colorTransformIsIdentity = true;
- snapshot.shadowRadius = 0.f;
+ snapshot.shadowSettings.length = 0.f;
snapshot.layerMetadata.mMap.clear();
snapshot.relativeLayerMetadata.mMap.clear();
snapshot.inputInfo.touchOcclusionMode = gui::TouchOcclusionMode::BLOCK_UNTRUSTED;
@@ -990,9 +990,12 @@
}
void LayerSnapshotBuilder::updateShadows(LayerSnapshot& snapshot, const RequestedLayerState&,
- const renderengine::ShadowSettings& globalShadowSettings) {
- if (snapshot.shadowRadius > 0.f) {
- snapshot.shadowSettings = globalShadowSettings;
+ const ShadowSettings& globalShadowSettings) {
+ if (snapshot.shadowSettings.length > 0.f) {
+ snapshot.shadowSettings.ambientColor = globalShadowSettings.ambientColor;
+ snapshot.shadowSettings.spotColor = globalShadowSettings.spotColor;
+ snapshot.shadowSettings.lightPos = globalShadowSettings.lightPos;
+ snapshot.shadowSettings.lightRadius = globalShadowSettings.lightRadius;
// Note: this preserves existing behavior of shadowing the entire layer and not cropping
// it if transparent regions are present. This may not be necessary since shadows are
@@ -1006,7 +1009,6 @@
snapshot.shadowSettings.ambientColor *= snapshot.alpha;
snapshot.shadowSettings.spotColor *= snapshot.alpha;
}
- snapshot.shadowSettings.length = snapshot.shadowRadius;
}
void LayerSnapshotBuilder::updateInput(LayerSnapshot& snapshot,
diff --git a/services/surfaceflinger/FrontEnd/LayerSnapshotBuilder.h b/services/surfaceflinger/FrontEnd/LayerSnapshotBuilder.h
index 3d64b36..1506913 100644
--- a/services/surfaceflinger/FrontEnd/LayerSnapshotBuilder.h
+++ b/services/surfaceflinger/FrontEnd/LayerSnapshotBuilder.h
@@ -47,7 +47,7 @@
const DisplayInfos& displays;
// Set to true if there were display changes since last update.
bool displayChanges = false;
- const renderengine::ShadowSettings& globalShadowSettings;
+ const ShadowSettings& globalShadowSettings;
bool supportsBlur = true;
bool forceFullDamage = false;
std::optional<FloatRect> parentCrop = std::nullopt;
@@ -108,7 +108,7 @@
void updateLayerBounds(LayerSnapshot& snapshot, const RequestedLayerState& layerState,
const LayerSnapshot& parentSnapshot, uint32_t displayRotationFlags);
static void updateShadows(LayerSnapshot& snapshot, const RequestedLayerState& requested,
- const renderengine::ShadowSettings& globalShadowSettings);
+ const ShadowSettings& globalShadowSettings);
void updateInput(LayerSnapshot& snapshot, const RequestedLayerState& requested,
const LayerSnapshot& parentSnapshot, const LayerHierarchy::TraversalPath& path,
const Args& args);
diff --git a/services/surfaceflinger/Layer.cpp b/services/surfaceflinger/Layer.cpp
index 33d1eeb..2dc8758 100644
--- a/services/surfaceflinger/Layer.cpp
+++ b/services/surfaceflinger/Layer.cpp
@@ -572,7 +572,7 @@
snapshot->outputFilter = getOutputFilter();
snapshot->isVisible = isVisible();
snapshot->isOpaque = opaque && !usesRoundedCorners && alpha == 1.f;
- snapshot->shadowRadius = mEffectiveShadowRadius;
+ snapshot->shadowSettings.length = mEffectiveShadowRadius;
snapshot->contentDirty = contentDirty;
contentDirty = false;
diff --git a/services/surfaceflinger/LayerFE.cpp b/services/surfaceflinger/LayerFE.cpp
index 97c4145..48a9190 100644
--- a/services/surfaceflinger/LayerFE.cpp
+++ b/services/surfaceflinger/LayerFE.cpp
@@ -310,7 +310,7 @@
void LayerFE::prepareShadowClientComposition(LayerFE::LayerSettings& caster,
const Rect& layerStackRect) const {
- renderengine::ShadowSettings state = mSnapshot->shadowSettings;
+ ShadowSettings state = mSnapshot->shadowSettings;
if (state.length <= 0.f || (state.ambientColor.a <= 0.f && state.spotColor.a <= 0.f)) {
return;
}
diff --git a/services/surfaceflinger/LayerProtoHelper.cpp b/services/surfaceflinger/LayerProtoHelper.cpp
index 144e1f5..aa6026e 100644
--- a/services/surfaceflinger/LayerProtoHelper.cpp
+++ b/services/surfaceflinger/LayerProtoHelper.cpp
@@ -402,7 +402,7 @@
[&]() { return layerInfo->mutable_screen_bounds(); });
LayerProtoHelper::writeToProto(snapshot.roundedCorner.cropRect,
[&]() { return layerInfo->mutable_corner_radius_crop(); });
- layerInfo->set_shadow_radius(snapshot.shadowRadius);
+ layerInfo->set_shadow_radius(snapshot.shadowSettings.length);
layerInfo->set_id(snapshot.uniqueSequence);
layerInfo->set_original_id(snapshot.sequence);
diff --git a/services/surfaceflinger/SurfaceFlinger.h b/services/surfaceflinger/SurfaceFlinger.h
index 7b2d590..cbea312 100644
--- a/services/surfaceflinger/SurfaceFlinger.h
+++ b/services/surfaceflinger/SurfaceFlinger.h
@@ -419,7 +419,7 @@
bool colorMatrixChanged = true;
mat4 colorMatrix;
- renderengine::ShadowSettings globalShadowSettings;
+ ShadowSettings globalShadowSettings;
void traverse(const LayerVector::Visitor& visitor) const;
void traverseInZOrder(const LayerVector::Visitor& visitor) const;
diff --git a/services/surfaceflinger/Tracing/tools/LayerTraceGenerator.cpp b/services/surfaceflinger/Tracing/tools/LayerTraceGenerator.cpp
index 23fe8fa..c2d1954 100644
--- a/services/surfaceflinger/Tracing/tools/LayerTraceGenerator.cpp
+++ b/services/surfaceflinger/Tracing/tools/LayerTraceGenerator.cpp
@@ -56,7 +56,7 @@
frontend::LayerSnapshotBuilder snapshotBuilder;
ui::DisplayMap<ui::LayerStack, frontend::DisplayInfo> displayInfos;
- renderengine::ShadowSettings globalShadowSettings{.ambientColor = {1, 1, 1, 1}};
+ ShadowSettings globalShadowSettings{.ambientColor = {1, 1, 1, 1}};
char value[PROPERTY_VALUE_MAX];
property_get("ro.surface_flinger.supports_background_blur", value, "0");
bool supportsBlur = atoi(value);
diff --git a/services/surfaceflinger/tests/unittests/LayerHierarchyTest.h b/services/surfaceflinger/tests/unittests/LayerHierarchyTest.h
index c47b0fc..d319dcc 100644
--- a/services/surfaceflinger/tests/unittests/LayerHierarchyTest.h
+++ b/services/surfaceflinger/tests/unittests/LayerHierarchyTest.h
@@ -19,6 +19,7 @@
#include <gui/fake/BufferData.h>
#include <renderengine/mock/FakeExternalTexture.h>
+#include <ui/ShadowSettings.h>
#include "Client.h" // temporarily needed for LayerCreationArgs
#include "FrontEnd/LayerCreationArgs.h"
@@ -488,7 +489,7 @@
DisplayInfos mFrontEndDisplayInfos;
bool mHasDisplayChanges = false;
- renderengine::ShadowSettings globalShadowSettings;
+ ShadowSettings globalShadowSettings;
};
} // namespace android::surfaceflinger::frontend
diff --git a/services/surfaceflinger/tests/unittests/LayerSnapshotTest.cpp b/services/surfaceflinger/tests/unittests/LayerSnapshotTest.cpp
index 956c0eb..50dfcaa 100644
--- a/services/surfaceflinger/tests/unittests/LayerSnapshotTest.cpp
+++ b/services/surfaceflinger/tests/unittests/LayerSnapshotTest.cpp
@@ -859,7 +859,6 @@
setShadowRadius(1, SHADOW_RADIUS);
UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER);
EXPECT_EQ(getSnapshot(1)->shadowSettings.length, SHADOW_RADIUS);
- EXPECT_EQ(getSnapshot(1)->shadowRadius, SHADOW_RADIUS);
}
} // namespace android::surfaceflinger::frontend