SF: Restructure OutputLayer creation to remove displayId argument
The existing code was explicitly passing the displayId when creating an
OutputLayer, so that a HWC2::Layer could be created if applicable.
This patch makes a quick adjustment to the code so that the
compositionengine::Display instance overrides the base createOutputLayer
logic to create the HWC2::Layer, as it knows the displayId itself.
This is a minor cleanup prior to moving computeVisibleLayers to the
Output class.
Test: atest libsurfaceflinger_unittest libcompositionengine_test
Test: go/wm-smoke
Bug: 121291683
Change-Id: Ic7224ba445084b833b8c344436397372b2153d42
diff --git a/services/surfaceflinger/CompositionEngine/tests/OutputLayerTest.cpp b/services/surfaceflinger/CompositionEngine/tests/OutputLayerTest.cpp
index 65691ff..b73c47b 100644
--- a/services/surfaceflinger/CompositionEngine/tests/OutputLayerTest.cpp
+++ b/services/surfaceflinger/CompositionEngine/tests/OutputLayerTest.cpp
@@ -36,8 +36,6 @@
using testing::ReturnRef;
using testing::StrictMock;
-constexpr DisplayId DEFAULT_DISPLAY_ID = DisplayId{42};
-
constexpr auto TR_IDENT = 0u;
constexpr auto TR_FLP_H = HAL_TRANSFORM_FLIP_H;
constexpr auto TR_FLP_V = HAL_TRANSFORM_FLIP_V;
@@ -83,35 +81,27 @@
TEST_F(OutputLayerTest, canInstantiateOutputLayer) {}
/*
- * OutputLayer::initialize()
+ * OutputLayer::setHwcLayer()
*/
-TEST_F(OutputLayerTest, initializingOutputLayerWithoutHwcDoesNothingInteresting) {
+TEST_F(OutputLayerTest, settingNullHwcLayerSetsEmptyHwcState) {
StrictMock<compositionengine::mock::CompositionEngine> compositionEngine;
- mOutputLayer.initialize(compositionEngine, std::nullopt);
+ mOutputLayer.setHwcLayer(nullptr);
EXPECT_FALSE(mOutputLayer.getState().hwc);
}
-TEST_F(OutputLayerTest, initializingOutputLayerWithHwcDisplayCreatesHwcLayer) {
- StrictMock<compositionengine::mock::CompositionEngine> compositionEngine;
- StrictMock<android::mock::HWComposer> hwc;
- StrictMock<HWC2::mock::Layer> hwcLayer;
+TEST_F(OutputLayerTest, settingHwcLayerSetsHwcState) {
+ auto hwcLayer = std::make_shared<StrictMock<HWC2::mock::Layer>>();
- EXPECT_CALL(compositionEngine, getHwComposer()).WillOnce(ReturnRef(hwc));
- EXPECT_CALL(hwc, createLayer(DEFAULT_DISPLAY_ID)).WillOnce(Return(&hwcLayer));
-
- mOutputLayer.initialize(compositionEngine, DEFAULT_DISPLAY_ID);
+ mOutputLayer.setHwcLayer(hwcLayer);
const auto& outputLayerState = mOutputLayer.getState();
ASSERT_TRUE(outputLayerState.hwc);
const auto& hwcState = *outputLayerState.hwc;
- EXPECT_EQ(&hwcLayer, hwcState.hwcLayer.get());
-
- EXPECT_CALL(hwc, destroyLayer(DEFAULT_DISPLAY_ID, &hwcLayer));
- mOutputLayer.editState().hwc.reset();
+ EXPECT_EQ(hwcLayer, hwcState.hwcLayer);
}
/*