CE: Remove compositionengine::Layer
This was a mostly straightforward refactor that restructures the
interface between SurfaceFlinger and CompositionEngine.
1) Instead of each SurfaceFlinger Layer creating and owning a
compositionengine::Layer, each Layer instead creates and owns a
compositionengine::LayerFECompositionState structure. Containing this
state structure was the only real purpose for
compositionengine::Layer.
2) Use the compositionengine::LayerFE interface in CompositionEngine in
place of compositionengine::Layer. This includes passing a
std::vector for the layers when SurfaceFlinger calls into
CompositionEngine.
3) Alters the LayerFE interface to add the ability to get the state, as
well as changing the existing "latchCompositionState" calls taking a
state reference as the first argument into "prepareCompositionState"
calls that do not need it, as the target of the call owns the state.
4) Alters the SurfaceFlinger Layer implementations to match the LayerFE
interface changes.
Test: atest libcompositionengine_test libsurfaceflinger_unittest
Test: atest CtsColorModeTestCases
Test: atest CtsDisplayTestCases
Test: atest CtsGraphicsTestCases
Test: atest CtsUiRenderingTestCases
Test: atest CtsViewTestCases
Test: atest android.media.cts.EncodeVirtualDisplayWithCompositionTest
Test: go/wm-smoke
Bug: 144117494
Change-Id: Id45df7c9cc389c8fd834ba379bc0d6360a984dac
diff --git a/services/surfaceflinger/CompositionEngine/src/OutputLayer.cpp b/services/surfaceflinger/CompositionEngine/src/OutputLayer.cpp
index d92b7ef..b538d75 100644
--- a/services/surfaceflinger/CompositionEngine/src/OutputLayer.cpp
+++ b/services/surfaceflinger/CompositionEngine/src/OutputLayer.cpp
@@ -16,7 +16,6 @@
#include <android-base/stringprintf.h>
#include <compositionengine/DisplayColorProfile.h>
-#include <compositionengine/Layer.h>
#include <compositionengine/LayerFE.h>
#include <compositionengine/LayerFECompositionState.h>
#include <compositionengine/Output.h>
@@ -51,11 +50,9 @@
} // namespace
-std::unique_ptr<OutputLayer> createOutputLayer(
- const compositionengine::Output& output,
- const std::shared_ptr<compositionengine::Layer>& layer,
- const sp<compositionengine::LayerFE>& layerFE) {
- return createOutputLayerTemplated<OutputLayer>(output, layer, layerFE);
+std::unique_ptr<OutputLayer> createOutputLayer(const compositionengine::Output& output,
+ const sp<compositionengine::LayerFE>& layerFE) {
+ return createOutputLayerTemplated<OutputLayer>(output, layerFE);
}
OutputLayer::~OutputLayer() = default;
@@ -70,7 +67,7 @@
}
Rect OutputLayer::calculateInitialCrop() const {
- const auto& layerState = getLayer().getFEState();
+ const auto& layerState = *getLayerFE().getCompositionState();
// apply the projection's clipping to the window crop in
// layerstack space, and convert-back to layer space.
@@ -103,7 +100,7 @@
}
FloatRect OutputLayer::calculateOutputSourceCrop() const {
- const auto& layerState = getLayer().getFEState();
+ const auto& layerState = *getLayerFE().getCompositionState();
const auto& outputState = getOutput().getState();
if (!layerState.geomUsesSourceCrop) {
@@ -180,7 +177,7 @@
}
Rect OutputLayer::calculateOutputDisplayFrame() const {
- const auto& layerState = getLayer().getFEState();
+ const auto& layerState = *getLayerFE().getCompositionState();
const auto& outputState = getOutput().getState();
// apply the layer's transform, followed by the display's global transform
@@ -227,7 +224,7 @@
}
uint32_t OutputLayer::calculateOutputRelativeBufferTransform() const {
- const auto& layerState = getLayer().getFEState();
+ const auto& layerState = *getLayerFE().getCompositionState();
const auto& outputState = getOutput().getState();
/*
@@ -267,7 +264,11 @@
} // namespace impl
void OutputLayer::updateCompositionState(bool includeGeometry, bool forceClientComposition) {
- const auto& layerFEState = getLayer().getFEState();
+ const auto* layerFEState = getLayerFE().getCompositionState();
+ if (!layerFEState) {
+ return;
+ }
+
const auto& outputState = getOutput().getState();
const auto& profile = *getOutput().getDisplayColorProfile();
auto& state = editState();
@@ -285,7 +286,7 @@
state.bufferTransform =
static_cast<Hwc2::Transform>(calculateOutputRelativeBufferTransform());
- if ((layerFEState.isSecure && !outputState.isSecure) ||
+ if ((layerFEState->isSecure && !outputState.isSecure) ||
(state.bufferTransform & ui::Transform::ROT_INVALID)) {
state.forceClientComposition = true;
}
@@ -294,14 +295,14 @@
// Determine the output dependent dataspace for this layer. If it is
// colorspace agnostic, it just uses the dataspace chosen for the output to
// avoid the need for color conversion.
- state.dataspace = layerFEState.isColorspaceAgnostic &&
+ state.dataspace = layerFEState->isColorspaceAgnostic &&
outputState.targetDataspace != ui::Dataspace::UNKNOWN
? outputState.targetDataspace
- : layerFEState.dataspace;
+ : layerFEState->dataspace;
// These are evaluated every frame as they can potentially change at any
// time.
- if (layerFEState.forceClientComposition || !profile.isDataspaceSupported(state.dataspace) ||
+ if (layerFEState->forceClientComposition || !profile.isDataspaceSupported(state.dataspace) ||
forceClientComposition) {
state.forceClientComposition = true;
}
@@ -321,21 +322,25 @@
return;
}
- const auto& outputIndependentState = getLayer().getFEState();
- auto requestedCompositionType = outputIndependentState.compositionType;
+ const auto* outputIndependentState = getLayerFE().getCompositionState();
+ if (!outputIndependentState) {
+ return;
+ }
+
+ auto requestedCompositionType = outputIndependentState->compositionType;
if (includeGeometry) {
writeOutputDependentGeometryStateToHWC(hwcLayer.get(), requestedCompositionType);
- writeOutputIndependentGeometryStateToHWC(hwcLayer.get(), outputIndependentState);
+ writeOutputIndependentGeometryStateToHWC(hwcLayer.get(), *outputIndependentState);
}
writeOutputDependentPerFrameStateToHWC(hwcLayer.get());
- writeOutputIndependentPerFrameStateToHWC(hwcLayer.get(), outputIndependentState);
+ writeOutputIndependentPerFrameStateToHWC(hwcLayer.get(), *outputIndependentState);
writeCompositionTypeToHWC(hwcLayer.get(), requestedCompositionType);
// Always set the layer color after setting the composition type.
- writeSolidColorStateToHWC(hwcLayer.get(), outputIndependentState);
+ writeSolidColorStateToHWC(hwcLayer.get(), *outputIndependentState);
}
void OutputLayer::writeOutputDependentGeometryStateToHWC(
@@ -546,10 +551,14 @@
return;
}
- const auto& layerFEState = getLayer().getFEState();
+ const auto* layerFEState = getLayerFE().getCompositionState();
+ if (!layerFEState) {
+ return;
+ }
+
const auto& outputState = getOutput().getState();
- Rect frame = layerFEState.cursorFrame;
+ Rect frame = layerFEState->cursorFrame;
frame.intersect(outputState.viewport, &frame);
Rect position = outputState.transform.transform(frame);
@@ -646,8 +655,7 @@
void OutputLayer::dump(std::string& out) const {
using android::base::StringAppendF;
- StringAppendF(&out, " - Output Layer %p (Composition layer %p) (%s)\n", this, &getLayer(),
- getLayerFE().getDebugName());
+ StringAppendF(&out, " - Output Layer %p(%s)\n", this, getLayerFE().getDebugName());
dumpState(out);
}