blob: 47b682059fed0bbbf14fedd335a4f1771df54516 [file] [log] [blame]
Alec Mourieb920d92021-03-01 17:48:30 -08001/*
2 * Copyright 2021 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#undef LOG_TAG
18#define LOG_TAG "LayerStateTest"
19
John Reckd77e1df2022-03-04 14:26:29 -050020#include <aidl/android/hardware/graphics/common/BufferUsage.h>
Alec Mourieb920d92021-03-01 17:48:30 -080021#include <compositionengine/impl/OutputLayer.h>
22#include <compositionengine/impl/planner/LayerState.h>
23#include <compositionengine/mock/LayerFE.h>
24#include <compositionengine/mock/OutputLayer.h>
25#include <gtest/gtest.h>
26#include <log/log.h>
27
Alec Mouri69114c72021-03-19 19:31:29 -070028#include "android/hardware_buffer.h"
29#include "compositionengine/LayerFECompositionState.h"
30
Leon Scroggins III2e1aa182021-12-01 17:33:12 -050031#include <aidl/android/hardware/graphics/composer3/Composition.h>
32
John Reckd77e1df2022-03-04 14:26:29 -050033using ::aidl::android::hardware::graphics::common::BufferUsage;
34using ::aidl::android::hardware::graphics::composer3::Composition;
Leon Scroggins III2e1aa182021-12-01 17:33:12 -050035
Alec Mourieb920d92021-03-01 17:48:30 -080036namespace android::compositionengine::impl::planner {
37namespace {
38
39using testing::Return;
40using testing::ReturnRef;
41
42const std::string sDebugName = std::string("Test LayerFE");
43const std::string sDebugNameTwo = std::string("Test LayerFE2");
44const constexpr int32_t sSequenceId = 12345;
45const constexpr int32_t sSequenceIdTwo = 123456;
46const Rect sRectOne = Rect(10, 20, 30, 40);
47const Rect sRectTwo = Rect(40, 30, 20, 10);
48const FloatRect sFloatRectOne = FloatRect(100.f, 200.f, 300.f, 400.f);
49const FloatRect sFloatRectTwo = FloatRect(400.f, 300.f, 200.f, 100.f);
Alec Mourieb920d92021-03-01 17:48:30 -080050const constexpr float sAlphaOne = 0.25f;
51const constexpr float sAlphaTwo = 0.5f;
52const Region sRegionOne = Region(sRectOne);
53const Region sRegionTwo = Region(sRectTwo);
54const mat4 sMat4One = mat4::scale(vec4(2.f, 3.f, 1.f, 1.f));
55native_handle_t* const sFakeSidebandStreamOne = reinterpret_cast<native_handle_t*>(10);
56native_handle_t* const sFakeSidebandStreamTwo = reinterpret_cast<native_handle_t*>(11);
57const half4 sHalf4One = half4(0.2f, 0.3f, 0.4f, 0.5f);
Alec Mouri69114c72021-03-19 19:31:29 -070058const half4 sHalf4Two = half4(0.5f, 0.4f, 0.3f, 0.2f);
59const std::string sMetadataKeyOne = std::string("Meta!");
60const std::string sMetadataKeyTwo = std::string("Data!");
61const GenericLayerMetadataEntry sMetadataValueOne = GenericLayerMetadataEntry{
62 .value = std::vector<uint8_t>({1, 2}),
63};
64const GenericLayerMetadataEntry sMetadataValueTwo = GenericLayerMetadataEntry{
65 .value = std::vector<uint8_t>({1, 3}),
66};
Alec Mouri97486062021-05-07 15:26:03 -070067const constexpr int32_t sBgBlurRadiusOne = 3;
68const constexpr int32_t sBgBlurRadiusTwo = 4;
69const BlurRegion sBlurRegionOne = BlurRegion{1, 2.f, 3.f, 4.f, 5.f, 6.f, 7, 8, 9, 10};
70const BlurRegion sBlurRegionTwo = BlurRegion{2, 3.f, 4.f, 5.f, 6.f, 7.f, 8, 9, 10, 11};
Alec Mourieb920d92021-03-01 17:48:30 -080071
72struct LayerStateTest : public testing::Test {
73 LayerStateTest() {
74 const ::testing::TestInfo* const test_info =
75 ::testing::UnitTest::GetInstance()->current_test_info();
76 ALOGD("**** Setting up for %s.%s\n", test_info->test_case_name(), test_info->name());
77 }
78
79 ~LayerStateTest() {
80 const ::testing::TestInfo* const test_info =
81 ::testing::UnitTest::GetInstance()->current_test_info();
82 ALOGD("**** Tearing down after %s.%s\n", test_info->test_case_name(), test_info->name());
83 }
84
85 void setupMocksForLayer(mock::OutputLayer& layer, mock::LayerFE& layerFE,
86 const OutputLayerCompositionState& outputLayerState,
87 const LayerFECompositionState& layerFEState,
88 int32_t sequenceId = sSequenceId,
89 const std::string& debugName = sDebugName) {
90 EXPECT_CALL(layer, getLayerFE()).WillRepeatedly(ReturnRef(layerFE));
91 EXPECT_CALL(layer, getState()).WillRepeatedly(ReturnRef(outputLayerState));
92 EXPECT_CALL(layerFE, getSequence()).WillRepeatedly(Return(sequenceId));
93 EXPECT_CALL(layerFE, getDebugName()).WillRepeatedly(Return(debugName.c_str()));
94 EXPECT_CALL(layerFE, getCompositionState()).WillRepeatedly(Return(&layerFEState));
95 }
96
Alec Mouri69114c72021-03-19 19:31:29 -070097 void verifyUniqueDifferingFields(const LayerState& lhs, const LayerState& rhs) {
98 EXPECT_EQ(lhs.getHash(), rhs.getHash());
99
Dominik Laskowski2f01d772022-03-23 16:01:29 -0700100 EXPECT_EQ(ftl::Flags<LayerStateField>(LayerStateField::None), lhs.getDifferingFields(rhs));
101 EXPECT_EQ(ftl::Flags<LayerStateField>(LayerStateField::None), rhs.getDifferingFields(lhs));
Alec Mouri69114c72021-03-19 19:31:29 -0700102 }
103
104 void verifyNonUniqueDifferingFields(const LayerState& lhs, const LayerState& rhs,
Dominik Laskowski2f01d772022-03-23 16:01:29 -0700105 ftl::Flags<LayerStateField> fields) {
Alec Mouri69114c72021-03-19 19:31:29 -0700106 EXPECT_NE(lhs.getHash(), rhs.getHash());
107
108 EXPECT_EQ(fields, lhs.getDifferingFields(rhs));
109 EXPECT_EQ(fields, rhs.getDifferingFields(lhs));
110 }
111
Ady Abrahame0eafa82022-02-02 19:30:47 -0800112 sp<mock::LayerFE> mLayerFE = sp<mock::LayerFE>::make();
Alec Mourieb920d92021-03-01 17:48:30 -0800113 mock::OutputLayer mOutputLayer;
114 std::unique_ptr<LayerState> mLayerState;
Ady Abrahamd11bade2022-08-01 16:18:03 -0700115
116 static constexpr auto kUsageFlags = static_cast<uint32_t>(
117 AHARDWAREBUFFER_USAGE_CPU_READ_OFTEN | AHARDWAREBUFFER_USAGE_CPU_WRITE_OFTEN);
Alec Mourieb920d92021-03-01 17:48:30 -0800118};
119
120TEST_F(LayerStateTest, getOutputLayer) {
121 OutputLayerCompositionState outputLayerCompositionState;
122 LayerFECompositionState layerFECompositionState;
Ady Abrahame0eafa82022-02-02 19:30:47 -0800123 setupMocksForLayer(mOutputLayer, *mLayerFE, outputLayerCompositionState,
Alec Mourieb920d92021-03-01 17:48:30 -0800124 layerFECompositionState);
125 mLayerState = std::make_unique<LayerState>(&mOutputLayer);
126 EXPECT_EQ(&mOutputLayer, mLayerState->getOutputLayer());
127}
128
Alec Mouri2f5addb2021-06-22 14:39:20 -0700129TEST_F(LayerStateTest, updateOutputLayer) {
130 OutputLayerCompositionState outputLayerCompositionState;
131 LayerFECompositionState layerFECompositionState;
Ady Abrahame0eafa82022-02-02 19:30:47 -0800132 setupMocksForLayer(mOutputLayer, *mLayerFE, outputLayerCompositionState,
Alec Mouri2f5addb2021-06-22 14:39:20 -0700133 layerFECompositionState);
134 mLayerState = std::make_unique<LayerState>(&mOutputLayer);
135 EXPECT_EQ(&mOutputLayer, mLayerState->getOutputLayer());
136
137 mock::OutputLayer newOutputLayer;
Ady Abrahame0eafa82022-02-02 19:30:47 -0800138 sp<mock::LayerFE> newLayerFE = sp<mock::LayerFE>::make();
139 setupMocksForLayer(newOutputLayer, *newLayerFE, outputLayerCompositionState,
Alec Mouri2f5addb2021-06-22 14:39:20 -0700140 layerFECompositionState);
141 mLayerState->update(&newOutputLayer);
142 EXPECT_EQ(&newOutputLayer, mLayerState->getOutputLayer());
143}
144
Alec Mourieb920d92021-03-01 17:48:30 -0800145TEST_F(LayerStateTest, getId) {
146 OutputLayerCompositionState outputLayerCompositionState;
147 LayerFECompositionState layerFECompositionState;
Ady Abrahame0eafa82022-02-02 19:30:47 -0800148 setupMocksForLayer(mOutputLayer, *mLayerFE, outputLayerCompositionState,
Alec Mourieb920d92021-03-01 17:48:30 -0800149 layerFECompositionState);
150 mLayerState = std::make_unique<LayerState>(&mOutputLayer);
151 EXPECT_EQ(sSequenceId, mLayerState->getId());
152}
153
154TEST_F(LayerStateTest, updateId) {
155 OutputLayerCompositionState outputLayerCompositionState;
156 LayerFECompositionState layerFECompositionState;
Ady Abrahame0eafa82022-02-02 19:30:47 -0800157 setupMocksForLayer(mOutputLayer, *mLayerFE, outputLayerCompositionState,
Alec Mourieb920d92021-03-01 17:48:30 -0800158 layerFECompositionState);
159 mLayerState = std::make_unique<LayerState>(&mOutputLayer);
160
161 mock::OutputLayer newOutputLayer;
Ady Abrahame0eafa82022-02-02 19:30:47 -0800162 sp<mock::LayerFE> newLayerFE = sp<mock::LayerFE>::make();
163 setupMocksForLayer(newOutputLayer, *newLayerFE, outputLayerCompositionState,
Alec Mourieb920d92021-03-01 17:48:30 -0800164 layerFECompositionState, sSequenceIdTwo);
Dominik Laskowski2f01d772022-03-23 16:01:29 -0700165 ftl::Flags<LayerStateField> updates = mLayerState->update(&newOutputLayer);
Alec Mourieb920d92021-03-01 17:48:30 -0800166 EXPECT_EQ(sSequenceIdTwo, mLayerState->getId());
Dominik Laskowski2f01d772022-03-23 16:01:29 -0700167 EXPECT_EQ(ftl::Flags<LayerStateField>(LayerStateField::Id), updates);
Alec Mourieb920d92021-03-01 17:48:30 -0800168}
169
170TEST_F(LayerStateTest, compareId) {
171 OutputLayerCompositionState outputLayerCompositionState;
172 LayerFECompositionState layerFECompositionState;
Ady Abrahame0eafa82022-02-02 19:30:47 -0800173 setupMocksForLayer(mOutputLayer, *mLayerFE, outputLayerCompositionState,
Alec Mourieb920d92021-03-01 17:48:30 -0800174 layerFECompositionState);
175 mLayerState = std::make_unique<LayerState>(&mOutputLayer);
176 mock::OutputLayer newOutputLayer;
Ady Abrahame0eafa82022-02-02 19:30:47 -0800177 sp<mock::LayerFE> newLayerFE = sp<mock::LayerFE>::make();
178 setupMocksForLayer(newOutputLayer, *newLayerFE, outputLayerCompositionState,
Alec Mourieb920d92021-03-01 17:48:30 -0800179 layerFECompositionState, sSequenceIdTwo);
180 auto otherLayerState = std::make_unique<LayerState>(&newOutputLayer);
181
182 EXPECT_NE(mLayerState->getId(), otherLayerState->getId());
183
184 // Id is a unique field, so it's not computed in the hash for a layer state.
Alec Mouri69114c72021-03-19 19:31:29 -0700185 verifyUniqueDifferingFields(*mLayerState, *otherLayerState);
Alec Mourieb920d92021-03-01 17:48:30 -0800186 EXPECT_FALSE(mLayerState->compare(*otherLayerState));
187 EXPECT_FALSE(otherLayerState->compare(*mLayerState));
188}
189
190TEST_F(LayerStateTest, getName) {
191 OutputLayerCompositionState outputLayerCompositionState;
192 LayerFECompositionState layerFECompositionState;
Ady Abrahame0eafa82022-02-02 19:30:47 -0800193 setupMocksForLayer(mOutputLayer, *mLayerFE, outputLayerCompositionState,
Alec Mourieb920d92021-03-01 17:48:30 -0800194 layerFECompositionState);
195 mLayerState = std::make_unique<LayerState>(&mOutputLayer);
196 EXPECT_EQ(sDebugName, mLayerState->getName());
197}
198
199TEST_F(LayerStateTest, updateName) {
200 OutputLayerCompositionState outputLayerCompositionState;
201 LayerFECompositionState layerFECompositionState;
Ady Abrahame0eafa82022-02-02 19:30:47 -0800202 setupMocksForLayer(mOutputLayer, *mLayerFE, outputLayerCompositionState,
Alec Mourieb920d92021-03-01 17:48:30 -0800203 layerFECompositionState);
204 mLayerState = std::make_unique<LayerState>(&mOutputLayer);
205
206 mock::OutputLayer newOutputLayer;
Ady Abrahame0eafa82022-02-02 19:30:47 -0800207 sp<mock::LayerFE> newLayerFE = sp<mock::LayerFE>::make();
208 setupMocksForLayer(newOutputLayer, *newLayerFE, outputLayerCompositionState,
Alec Mourieb920d92021-03-01 17:48:30 -0800209 layerFECompositionState, sSequenceId, sDebugNameTwo);
Dominik Laskowski2f01d772022-03-23 16:01:29 -0700210 ftl::Flags<LayerStateField> updates = mLayerState->update(&newOutputLayer);
Alec Mourieb920d92021-03-01 17:48:30 -0800211 EXPECT_EQ(sDebugNameTwo, mLayerState->getName());
Dominik Laskowski2f01d772022-03-23 16:01:29 -0700212 EXPECT_EQ(ftl::Flags<LayerStateField>(LayerStateField::Name), updates);
Alec Mourieb920d92021-03-01 17:48:30 -0800213}
214
215TEST_F(LayerStateTest, compareName) {
216 OutputLayerCompositionState outputLayerCompositionState;
217 LayerFECompositionState layerFECompositionState;
Ady Abrahame0eafa82022-02-02 19:30:47 -0800218 setupMocksForLayer(mOutputLayer, *mLayerFE, outputLayerCompositionState,
Alec Mourieb920d92021-03-01 17:48:30 -0800219 layerFECompositionState);
220 mLayerState = std::make_unique<LayerState>(&mOutputLayer);
221 mock::OutputLayer newOutputLayer;
Ady Abrahame0eafa82022-02-02 19:30:47 -0800222 sp<mock::LayerFE> newLayerFE = sp<mock::LayerFE>::make();
223 setupMocksForLayer(newOutputLayer, *newLayerFE, outputLayerCompositionState,
Alec Mourieb920d92021-03-01 17:48:30 -0800224 layerFECompositionState, sSequenceId, sDebugNameTwo);
225 auto otherLayerState = std::make_unique<LayerState>(&newOutputLayer);
226
227 EXPECT_NE(mLayerState->getName(), otherLayerState->getName());
228
229 // Name is a unique field, so it's not computed in the hash for a layer state.
Alec Mouri69114c72021-03-19 19:31:29 -0700230 verifyUniqueDifferingFields(*mLayerState, *otherLayerState);
Alec Mourieb920d92021-03-01 17:48:30 -0800231 EXPECT_FALSE(mLayerState->compare(*otherLayerState));
232 EXPECT_FALSE(otherLayerState->compare(*mLayerState));
233}
234
235TEST_F(LayerStateTest, getDisplayFrame) {
236 OutputLayerCompositionState outputLayerCompositionState;
237 outputLayerCompositionState.displayFrame = sRectOne;
238 LayerFECompositionState layerFECompositionState;
Ady Abrahame0eafa82022-02-02 19:30:47 -0800239 setupMocksForLayer(mOutputLayer, *mLayerFE, outputLayerCompositionState,
Alec Mourieb920d92021-03-01 17:48:30 -0800240 layerFECompositionState);
241 mLayerState = std::make_unique<LayerState>(&mOutputLayer);
242 EXPECT_EQ(sRectOne, mLayerState->getDisplayFrame());
243}
244
245TEST_F(LayerStateTest, updateDisplayFrame) {
246 OutputLayerCompositionState outputLayerCompositionState;
247 outputLayerCompositionState.displayFrame = sRectOne;
248 LayerFECompositionState layerFECompositionState;
Ady Abrahame0eafa82022-02-02 19:30:47 -0800249 setupMocksForLayer(mOutputLayer, *mLayerFE, outputLayerCompositionState,
Alec Mourieb920d92021-03-01 17:48:30 -0800250 layerFECompositionState);
251 mLayerState = std::make_unique<LayerState>(&mOutputLayer);
252
253 mock::OutputLayer newOutputLayer;
Ady Abrahame0eafa82022-02-02 19:30:47 -0800254 sp<mock::LayerFE> newLayerFE = sp<mock::LayerFE>::make();
Alec Mourieb920d92021-03-01 17:48:30 -0800255 OutputLayerCompositionState outputLayerCompositionStateTwo;
256 outputLayerCompositionStateTwo.displayFrame = sRectTwo;
Ady Abrahame0eafa82022-02-02 19:30:47 -0800257 setupMocksForLayer(newOutputLayer, *newLayerFE, outputLayerCompositionStateTwo,
Alec Mourieb920d92021-03-01 17:48:30 -0800258 layerFECompositionState);
Dominik Laskowski2f01d772022-03-23 16:01:29 -0700259 ftl::Flags<LayerStateField> updates = mLayerState->update(&newOutputLayer);
Alec Mourieb920d92021-03-01 17:48:30 -0800260 EXPECT_EQ(sRectTwo, mLayerState->getDisplayFrame());
Dominik Laskowski2f01d772022-03-23 16:01:29 -0700261 EXPECT_EQ(ftl::Flags<LayerStateField>(LayerStateField::DisplayFrame), updates);
Alec Mourieb920d92021-03-01 17:48:30 -0800262}
263
264TEST_F(LayerStateTest, compareDisplayFrame) {
265 OutputLayerCompositionState outputLayerCompositionState;
266 outputLayerCompositionState.displayFrame = sRectOne;
267 LayerFECompositionState layerFECompositionState;
Ady Abrahame0eafa82022-02-02 19:30:47 -0800268 setupMocksForLayer(mOutputLayer, *mLayerFE, outputLayerCompositionState,
Alec Mourieb920d92021-03-01 17:48:30 -0800269 layerFECompositionState);
270 mLayerState = std::make_unique<LayerState>(&mOutputLayer);
271 mock::OutputLayer newOutputLayer;
Ady Abrahame0eafa82022-02-02 19:30:47 -0800272 sp<mock::LayerFE> newLayerFE = sp<mock::LayerFE>::make();
Alec Mourieb920d92021-03-01 17:48:30 -0800273 OutputLayerCompositionState outputLayerCompositionStateTwo;
274 outputLayerCompositionStateTwo.displayFrame = sRectTwo;
Ady Abrahame0eafa82022-02-02 19:30:47 -0800275 setupMocksForLayer(newOutputLayer, *newLayerFE, outputLayerCompositionStateTwo,
Alec Mourieb920d92021-03-01 17:48:30 -0800276 layerFECompositionState);
277 auto otherLayerState = std::make_unique<LayerState>(&newOutputLayer);
278
279 EXPECT_NE(mLayerState->getDisplayFrame(), otherLayerState->getDisplayFrame());
280
Alec Mouri69114c72021-03-19 19:31:29 -0700281 verifyNonUniqueDifferingFields(*mLayerState, *otherLayerState, LayerStateField::DisplayFrame);
Alec Mourieb920d92021-03-01 17:48:30 -0800282 EXPECT_TRUE(mLayerState->compare(*otherLayerState));
283 EXPECT_TRUE(otherLayerState->compare(*mLayerState));
284}
285
286TEST_F(LayerStateTest, getCompositionType) {
287 OutputLayerCompositionState outputLayerCompositionState;
288 LayerFECompositionState layerFECompositionState;
Leon Scroggins III2e1aa182021-12-01 17:33:12 -0500289 layerFECompositionState.compositionType = Composition::DEVICE;
Ady Abrahame0eafa82022-02-02 19:30:47 -0800290 setupMocksForLayer(mOutputLayer, *mLayerFE, outputLayerCompositionState,
Alec Mourieb920d92021-03-01 17:48:30 -0800291 layerFECompositionState);
292 mLayerState = std::make_unique<LayerState>(&mOutputLayer);
Leon Scroggins III2e1aa182021-12-01 17:33:12 -0500293 EXPECT_EQ(Composition::DEVICE, mLayerState->getCompositionType());
Alec Mourieb920d92021-03-01 17:48:30 -0800294}
295
296TEST_F(LayerStateTest, getCompositionType_forcedClient) {
297 OutputLayerCompositionState outputLayerCompositionState;
298 outputLayerCompositionState.forceClientComposition = true;
299 LayerFECompositionState layerFECompositionState;
Leon Scroggins III2e1aa182021-12-01 17:33:12 -0500300 layerFECompositionState.compositionType = Composition::DEVICE;
Ady Abrahame0eafa82022-02-02 19:30:47 -0800301 setupMocksForLayer(mOutputLayer, *mLayerFE, outputLayerCompositionState,
Alec Mourieb920d92021-03-01 17:48:30 -0800302 layerFECompositionState);
303 mLayerState = std::make_unique<LayerState>(&mOutputLayer);
Leon Scroggins III2e1aa182021-12-01 17:33:12 -0500304 EXPECT_EQ(Composition::CLIENT, mLayerState->getCompositionType());
Alec Mourieb920d92021-03-01 17:48:30 -0800305}
306
307TEST_F(LayerStateTest, updateCompositionType) {
308 OutputLayerCompositionState outputLayerCompositionState;
309 LayerFECompositionState layerFECompositionState;
Leon Scroggins III2e1aa182021-12-01 17:33:12 -0500310 layerFECompositionState.compositionType = Composition::DEVICE;
Ady Abrahame0eafa82022-02-02 19:30:47 -0800311 setupMocksForLayer(mOutputLayer, *mLayerFE, outputLayerCompositionState,
Alec Mourieb920d92021-03-01 17:48:30 -0800312 layerFECompositionState);
313 mLayerState = std::make_unique<LayerState>(&mOutputLayer);
314
315 mock::OutputLayer newOutputLayer;
Ady Abrahame0eafa82022-02-02 19:30:47 -0800316 sp<mock::LayerFE> newLayerFE = sp<mock::LayerFE>::make();
Alec Mourieb920d92021-03-01 17:48:30 -0800317 LayerFECompositionState layerFECompositionStateTwo;
Leon Scroggins III2e1aa182021-12-01 17:33:12 -0500318 layerFECompositionStateTwo.compositionType = Composition::SOLID_COLOR;
Ady Abrahame0eafa82022-02-02 19:30:47 -0800319 setupMocksForLayer(newOutputLayer, *newLayerFE, outputLayerCompositionState,
Alec Mourieb920d92021-03-01 17:48:30 -0800320 layerFECompositionStateTwo);
Dominik Laskowski2f01d772022-03-23 16:01:29 -0700321 ftl::Flags<LayerStateField> updates = mLayerState->update(&newOutputLayer);
Leon Scroggins III2e1aa182021-12-01 17:33:12 -0500322 EXPECT_EQ(Composition::SOLID_COLOR, mLayerState->getCompositionType());
Dominik Laskowski2f01d772022-03-23 16:01:29 -0700323 EXPECT_EQ(ftl::Flags<LayerStateField>(LayerStateField::CompositionType), updates);
Alec Mourieb920d92021-03-01 17:48:30 -0800324}
325
326TEST_F(LayerStateTest, compareCompositionType) {
327 OutputLayerCompositionState outputLayerCompositionState;
328 LayerFECompositionState layerFECompositionState;
Leon Scroggins III2e1aa182021-12-01 17:33:12 -0500329 layerFECompositionState.compositionType = Composition::DEVICE;
Ady Abrahame0eafa82022-02-02 19:30:47 -0800330 setupMocksForLayer(mOutputLayer, *mLayerFE, outputLayerCompositionState,
Alec Mourieb920d92021-03-01 17:48:30 -0800331 layerFECompositionState);
332 mLayerState = std::make_unique<LayerState>(&mOutputLayer);
333 mock::OutputLayer newOutputLayer;
Ady Abrahame0eafa82022-02-02 19:30:47 -0800334 sp<mock::LayerFE> newLayerFE = sp<mock::LayerFE>::make();
Alec Mourieb920d92021-03-01 17:48:30 -0800335 LayerFECompositionState layerFECompositionStateTwo;
Leon Scroggins III2e1aa182021-12-01 17:33:12 -0500336 layerFECompositionStateTwo.compositionType = Composition::SOLID_COLOR;
Ady Abrahame0eafa82022-02-02 19:30:47 -0800337 setupMocksForLayer(newOutputLayer, *newLayerFE, outputLayerCompositionState,
Alec Mourieb920d92021-03-01 17:48:30 -0800338 layerFECompositionStateTwo);
339 auto otherLayerState = std::make_unique<LayerState>(&newOutputLayer);
340
341 EXPECT_NE(mLayerState->getCompositionType(), otherLayerState->getCompositionType());
342
Alec Mouri69114c72021-03-19 19:31:29 -0700343 verifyNonUniqueDifferingFields(*mLayerState, *otherLayerState,
344 LayerStateField::CompositionType);
Alec Mourieb920d92021-03-01 17:48:30 -0800345 EXPECT_TRUE(mLayerState->compare(*otherLayerState));
346 EXPECT_TRUE(otherLayerState->compare(*mLayerState));
347}
348
Alec Mourieb920d92021-03-01 17:48:30 -0800349TEST_F(LayerStateTest, updateBuffer) {
350 OutputLayerCompositionState outputLayerCompositionState;
351 LayerFECompositionState layerFECompositionState;
Ady Abrahamd11bade2022-08-01 16:18:03 -0700352 layerFECompositionState.buffer = sp<GraphicBuffer>::make();
Ady Abrahame0eafa82022-02-02 19:30:47 -0800353 setupMocksForLayer(mOutputLayer, *mLayerFE, outputLayerCompositionState,
Alec Mourieb920d92021-03-01 17:48:30 -0800354 layerFECompositionState);
355 mLayerState = std::make_unique<LayerState>(&mOutputLayer);
356
357 mock::OutputLayer newOutputLayer;
Ady Abrahame0eafa82022-02-02 19:30:47 -0800358 sp<mock::LayerFE> newLayerFE = sp<mock::LayerFE>::make();
Alec Mourieb920d92021-03-01 17:48:30 -0800359 LayerFECompositionState layerFECompositionStateTwo;
Ady Abrahamd11bade2022-08-01 16:18:03 -0700360 layerFECompositionStateTwo.buffer = sp<GraphicBuffer>::make();
Ady Abrahame0eafa82022-02-02 19:30:47 -0800361 setupMocksForLayer(newOutputLayer, *newLayerFE, outputLayerCompositionState,
Alec Mourieb920d92021-03-01 17:48:30 -0800362 layerFECompositionStateTwo);
Dominik Laskowski2f01d772022-03-23 16:01:29 -0700363 ftl::Flags<LayerStateField> updates = mLayerState->update(&newOutputLayer);
364 EXPECT_EQ(ftl::Flags<LayerStateField>(LayerStateField::Buffer), updates);
Alec Mourieb920d92021-03-01 17:48:30 -0800365}
366
John Reckbb409682022-03-04 16:03:37 -0500367TEST_F(LayerStateTest, updateBufferSingleBufferedLegacy) {
368 OutputLayerCompositionState outputLayerCompositionState;
369 LayerFECompositionState layerFECompositionState;
Ady Abrahamd11bade2022-08-01 16:18:03 -0700370 layerFECompositionState.buffer = sp<GraphicBuffer>::make();
John Reckbb409682022-03-04 16:03:37 -0500371 setupMocksForLayer(mOutputLayer, *mLayerFE, outputLayerCompositionState,
372 layerFECompositionState);
373 mLayerState = std::make_unique<LayerState>(&mOutputLayer);
374
375 mock::OutputLayer newOutputLayer;
376 sp<mock::LayerFE> newLayerFE = sp<mock::LayerFE>::make();
377 LayerFECompositionState layerFECompositionStateTwo;
Ady Abrahamd11bade2022-08-01 16:18:03 -0700378 layerFECompositionStateTwo.buffer = sp<GraphicBuffer>::make();
John Reckbb409682022-03-04 16:03:37 -0500379 setupMocksForLayer(newOutputLayer, *newLayerFE, outputLayerCompositionState,
380 layerFECompositionStateTwo);
381
382 for (uint64_t i = 0; i < 10; i++) {
383 layerFECompositionStateTwo.frameNumber = i;
384 setupMocksForLayer(newOutputLayer, *newLayerFE, outputLayerCompositionState,
385 layerFECompositionStateTwo);
Dominik Laskowski2f01d772022-03-23 16:01:29 -0700386 ftl::Flags<LayerStateField> updates = mLayerState->update(&newOutputLayer);
387 EXPECT_EQ(ftl::Flags<LayerStateField>(LayerStateField::Buffer), updates);
John Reckbb409682022-03-04 16:03:37 -0500388 }
389}
390
John Reckd77e1df2022-03-04 14:26:29 -0500391TEST_F(LayerStateTest, updateBufferSingleBufferedUsage) {
392 OutputLayerCompositionState outputLayerCompositionState;
393 LayerFECompositionState layerFECompositionState;
Ady Abrahamd11bade2022-08-01 16:18:03 -0700394 layerFECompositionState.buffer = sp<GraphicBuffer>::make();
John Reckd77e1df2022-03-04 14:26:29 -0500395 setupMocksForLayer(mOutputLayer, *mLayerFE, outputLayerCompositionState,
396 layerFECompositionState);
397 mLayerState = std::make_unique<LayerState>(&mOutputLayer);
398
399 mock::OutputLayer newOutputLayer;
400 sp<mock::LayerFE> newLayerFE = sp<mock::LayerFE>::make();
401 LayerFECompositionState layerFECompositionStateTwo;
Ady Abrahamd11bade2022-08-01 16:18:03 -0700402 layerFECompositionStateTwo.buffer = sp<GraphicBuffer>::make();
John Reckd77e1df2022-03-04 14:26:29 -0500403 layerFECompositionStateTwo.buffer->usage = static_cast<uint64_t>(BufferUsage::FRONT_BUFFER);
404 setupMocksForLayer(newOutputLayer, *newLayerFE, outputLayerCompositionState,
405 layerFECompositionStateTwo);
406
407 for (uint64_t i = 0; i < 10; i++) {
408 setupMocksForLayer(newOutputLayer, *newLayerFE, outputLayerCompositionState,
409 layerFECompositionStateTwo);
Dominik Laskowski2f01d772022-03-23 16:01:29 -0700410 ftl::Flags<LayerStateField> updates = mLayerState->update(&newOutputLayer);
411 EXPECT_EQ(ftl::Flags<LayerStateField>(LayerStateField::Buffer), updates);
John Reckd77e1df2022-03-04 14:26:29 -0500412 }
413}
414
Alec Mourieb920d92021-03-01 17:48:30 -0800415TEST_F(LayerStateTest, compareBuffer) {
416 OutputLayerCompositionState outputLayerCompositionState;
417 LayerFECompositionState layerFECompositionState;
Ady Abrahamd11bade2022-08-01 16:18:03 -0700418 layerFECompositionState.buffer = sp<GraphicBuffer>::make();
Ady Abrahame0eafa82022-02-02 19:30:47 -0800419 setupMocksForLayer(mOutputLayer, *mLayerFE, outputLayerCompositionState,
Alec Mourieb920d92021-03-01 17:48:30 -0800420 layerFECompositionState);
421 mLayerState = std::make_unique<LayerState>(&mOutputLayer);
422 mock::OutputLayer newOutputLayer;
Ady Abrahame0eafa82022-02-02 19:30:47 -0800423 sp<mock::LayerFE> newLayerFE = sp<mock::LayerFE>::make();
Alec Mourieb920d92021-03-01 17:48:30 -0800424 LayerFECompositionState layerFECompositionStateTwo;
Ady Abrahamd11bade2022-08-01 16:18:03 -0700425 layerFECompositionStateTwo.buffer = sp<GraphicBuffer>::make();
Ady Abrahame0eafa82022-02-02 19:30:47 -0800426 setupMocksForLayer(newOutputLayer, *newLayerFE, outputLayerCompositionState,
Alec Mourieb920d92021-03-01 17:48:30 -0800427 layerFECompositionStateTwo);
428 auto otherLayerState = std::make_unique<LayerState>(&newOutputLayer);
429
Alec Mouri69114c72021-03-19 19:31:29 -0700430 // A buffer is not a unique field, but the assertions are the same.
431 verifyUniqueDifferingFields(*mLayerState, *otherLayerState);
Alec Mourieb920d92021-03-01 17:48:30 -0800432
433 // Buffers are explicitly excluded from comparison
434 EXPECT_FALSE(mLayerState->compare(*otherLayerState));
435 EXPECT_FALSE(otherLayerState->compare(*mLayerState));
436}
437
438TEST_F(LayerStateTest, updateSourceCrop) {
439 OutputLayerCompositionState outputLayerCompositionState;
440 outputLayerCompositionState.sourceCrop = sFloatRectOne;
441 LayerFECompositionState layerFECompositionState;
Ady Abrahame0eafa82022-02-02 19:30:47 -0800442 setupMocksForLayer(mOutputLayer, *mLayerFE, outputLayerCompositionState,
Alec Mourieb920d92021-03-01 17:48:30 -0800443 layerFECompositionState);
444 mLayerState = std::make_unique<LayerState>(&mOutputLayer);
445
446 mock::OutputLayer newOutputLayer;
Ady Abrahame0eafa82022-02-02 19:30:47 -0800447 sp<mock::LayerFE> newLayerFE = sp<mock::LayerFE>::make();
Alec Mourieb920d92021-03-01 17:48:30 -0800448 OutputLayerCompositionState outputLayerCompositionStateTwo;
449 outputLayerCompositionStateTwo.sourceCrop = sFloatRectTwo;
Ady Abrahame0eafa82022-02-02 19:30:47 -0800450 setupMocksForLayer(newOutputLayer, *newLayerFE, outputLayerCompositionStateTwo,
Alec Mourieb920d92021-03-01 17:48:30 -0800451 layerFECompositionState);
Dominik Laskowski2f01d772022-03-23 16:01:29 -0700452 ftl::Flags<LayerStateField> updates = mLayerState->update(&newOutputLayer);
453 EXPECT_EQ(ftl::Flags<LayerStateField>(LayerStateField::SourceCrop), updates);
Alec Mourieb920d92021-03-01 17:48:30 -0800454}
455
456TEST_F(LayerStateTest, compareSourceCrop) {
457 OutputLayerCompositionState outputLayerCompositionState;
458 outputLayerCompositionState.sourceCrop = sFloatRectOne;
459 LayerFECompositionState layerFECompositionState;
Ady Abrahame0eafa82022-02-02 19:30:47 -0800460 setupMocksForLayer(mOutputLayer, *mLayerFE, outputLayerCompositionState,
Alec Mourieb920d92021-03-01 17:48:30 -0800461 layerFECompositionState);
462 mLayerState = std::make_unique<LayerState>(&mOutputLayer);
463 mock::OutputLayer newOutputLayer;
Ady Abrahame0eafa82022-02-02 19:30:47 -0800464 sp<mock::LayerFE> newLayerFE = sp<mock::LayerFE>::make();
Alec Mourieb920d92021-03-01 17:48:30 -0800465 OutputLayerCompositionState outputLayerCompositionStateTwo;
466 outputLayerCompositionStateTwo.sourceCrop = sFloatRectTwo;
Ady Abrahame0eafa82022-02-02 19:30:47 -0800467 setupMocksForLayer(newOutputLayer, *newLayerFE, outputLayerCompositionStateTwo,
Alec Mourieb920d92021-03-01 17:48:30 -0800468 layerFECompositionState);
469 auto otherLayerState = std::make_unique<LayerState>(&newOutputLayer);
470
Alec Mouri69114c72021-03-19 19:31:29 -0700471 verifyNonUniqueDifferingFields(*mLayerState, *otherLayerState, LayerStateField::SourceCrop);
Alec Mourieb920d92021-03-01 17:48:30 -0800472
473 EXPECT_TRUE(mLayerState->compare(*otherLayerState));
474 EXPECT_TRUE(otherLayerState->compare(*mLayerState));
475}
476
Alec Mourieb920d92021-03-01 17:48:30 -0800477TEST_F(LayerStateTest, updateBufferTransform) {
478 OutputLayerCompositionState outputLayerCompositionState;
479 outputLayerCompositionState.bufferTransform = Hwc2::Transform::FLIP_H;
480 LayerFECompositionState layerFECompositionState;
Ady Abrahame0eafa82022-02-02 19:30:47 -0800481 setupMocksForLayer(mOutputLayer, *mLayerFE, outputLayerCompositionState,
Alec Mourieb920d92021-03-01 17:48:30 -0800482 layerFECompositionState);
483 mLayerState = std::make_unique<LayerState>(&mOutputLayer);
484
485 mock::OutputLayer newOutputLayer;
Ady Abrahame0eafa82022-02-02 19:30:47 -0800486 sp<mock::LayerFE> newLayerFE = sp<mock::LayerFE>::make();
Alec Mourieb920d92021-03-01 17:48:30 -0800487 OutputLayerCompositionState outputLayerCompositionStateTwo;
488 outputLayerCompositionStateTwo.bufferTransform = Hwc2::Transform::FLIP_V;
Ady Abrahame0eafa82022-02-02 19:30:47 -0800489 setupMocksForLayer(newOutputLayer, *newLayerFE, outputLayerCompositionStateTwo,
Alec Mourieb920d92021-03-01 17:48:30 -0800490 layerFECompositionState);
Dominik Laskowski2f01d772022-03-23 16:01:29 -0700491 ftl::Flags<LayerStateField> updates = mLayerState->update(&newOutputLayer);
492 EXPECT_EQ(ftl::Flags<LayerStateField>(LayerStateField::BufferTransform), updates);
Alec Mourieb920d92021-03-01 17:48:30 -0800493}
494
495TEST_F(LayerStateTest, compareBufferTransform) {
496 OutputLayerCompositionState outputLayerCompositionState;
497 outputLayerCompositionState.bufferTransform = Hwc2::Transform::FLIP_H;
498 LayerFECompositionState layerFECompositionState;
Ady Abrahame0eafa82022-02-02 19:30:47 -0800499 setupMocksForLayer(mOutputLayer, *mLayerFE, outputLayerCompositionState,
Alec Mourieb920d92021-03-01 17:48:30 -0800500 layerFECompositionState);
501 mLayerState = std::make_unique<LayerState>(&mOutputLayer);
502 mock::OutputLayer newOutputLayer;
Ady Abrahame0eafa82022-02-02 19:30:47 -0800503 sp<mock::LayerFE> newLayerFE = sp<mock::LayerFE>::make();
Alec Mourieb920d92021-03-01 17:48:30 -0800504 OutputLayerCompositionState outputLayerCompositionStateTwo;
505 outputLayerCompositionStateTwo.bufferTransform = Hwc2::Transform::FLIP_V;
Ady Abrahame0eafa82022-02-02 19:30:47 -0800506 setupMocksForLayer(newOutputLayer, *newLayerFE, outputLayerCompositionStateTwo,
Alec Mourieb920d92021-03-01 17:48:30 -0800507 layerFECompositionState);
508 auto otherLayerState = std::make_unique<LayerState>(&newOutputLayer);
509
Alec Mouri69114c72021-03-19 19:31:29 -0700510 verifyNonUniqueDifferingFields(*mLayerState, *otherLayerState,
511 LayerStateField::BufferTransform);
Alec Mourieb920d92021-03-01 17:48:30 -0800512
513 EXPECT_TRUE(mLayerState->compare(*otherLayerState));
514 EXPECT_TRUE(otherLayerState->compare(*mLayerState));
515}
516
517TEST_F(LayerStateTest, updateBlendMode) {
518 OutputLayerCompositionState outputLayerCompositionState;
519 LayerFECompositionState layerFECompositionState;
520 layerFECompositionState.blendMode = hal::BlendMode::COVERAGE;
Ady Abrahame0eafa82022-02-02 19:30:47 -0800521 setupMocksForLayer(mOutputLayer, *mLayerFE, outputLayerCompositionState,
Alec Mourieb920d92021-03-01 17:48:30 -0800522 layerFECompositionState);
523 mLayerState = std::make_unique<LayerState>(&mOutputLayer);
524
525 mock::OutputLayer newOutputLayer;
Ady Abrahame0eafa82022-02-02 19:30:47 -0800526 sp<mock::LayerFE> newLayerFE = sp<mock::LayerFE>::make();
Alec Mourieb920d92021-03-01 17:48:30 -0800527 LayerFECompositionState layerFECompositionStateTwo;
528 layerFECompositionStateTwo.blendMode = hal::BlendMode::PREMULTIPLIED;
Ady Abrahame0eafa82022-02-02 19:30:47 -0800529 setupMocksForLayer(newOutputLayer, *newLayerFE, outputLayerCompositionState,
Alec Mourieb920d92021-03-01 17:48:30 -0800530 layerFECompositionStateTwo);
Dominik Laskowski2f01d772022-03-23 16:01:29 -0700531 ftl::Flags<LayerStateField> updates = mLayerState->update(&newOutputLayer);
532 EXPECT_EQ(ftl::Flags<LayerStateField>(LayerStateField::BlendMode), updates);
Alec Mourieb920d92021-03-01 17:48:30 -0800533}
534
535TEST_F(LayerStateTest, compareBlendMode) {
536 OutputLayerCompositionState outputLayerCompositionState;
537 LayerFECompositionState layerFECompositionState;
538 layerFECompositionState.blendMode = hal::BlendMode::COVERAGE;
Ady Abrahame0eafa82022-02-02 19:30:47 -0800539 setupMocksForLayer(mOutputLayer, *mLayerFE, outputLayerCompositionState,
Alec Mourieb920d92021-03-01 17:48:30 -0800540 layerFECompositionState);
541 mLayerState = std::make_unique<LayerState>(&mOutputLayer);
542 mock::OutputLayer newOutputLayer;
Ady Abrahame0eafa82022-02-02 19:30:47 -0800543 sp<mock::LayerFE> newLayerFE = sp<mock::LayerFE>::make();
Alec Mourieb920d92021-03-01 17:48:30 -0800544 LayerFECompositionState layerFECompositionStateTwo;
545 layerFECompositionStateTwo.blendMode = hal::BlendMode::PREMULTIPLIED;
Ady Abrahame0eafa82022-02-02 19:30:47 -0800546 setupMocksForLayer(newOutputLayer, *newLayerFE, outputLayerCompositionState,
Alec Mourieb920d92021-03-01 17:48:30 -0800547 layerFECompositionStateTwo);
548 auto otherLayerState = std::make_unique<LayerState>(&newOutputLayer);
549
Alec Mouri69114c72021-03-19 19:31:29 -0700550 verifyNonUniqueDifferingFields(*mLayerState, *otherLayerState, LayerStateField::BlendMode);
Alec Mourieb920d92021-03-01 17:48:30 -0800551
552 EXPECT_TRUE(mLayerState->compare(*otherLayerState));
553 EXPECT_TRUE(otherLayerState->compare(*mLayerState));
554}
555
556TEST_F(LayerStateTest, updateAlpha) {
557 OutputLayerCompositionState outputLayerCompositionState;
558 LayerFECompositionState layerFECompositionState;
559 layerFECompositionState.alpha = sAlphaOne;
Ady Abrahame0eafa82022-02-02 19:30:47 -0800560 setupMocksForLayer(mOutputLayer, *mLayerFE, outputLayerCompositionState,
Alec Mourieb920d92021-03-01 17:48:30 -0800561 layerFECompositionState);
562 mLayerState = std::make_unique<LayerState>(&mOutputLayer);
563
564 mock::OutputLayer newOutputLayer;
Ady Abrahame0eafa82022-02-02 19:30:47 -0800565 sp<mock::LayerFE> newLayerFE = sp<mock::LayerFE>::make();
Alec Mourieb920d92021-03-01 17:48:30 -0800566 LayerFECompositionState layerFECompositionStateTwo;
567 layerFECompositionStateTwo.alpha = sAlphaTwo;
Ady Abrahame0eafa82022-02-02 19:30:47 -0800568 setupMocksForLayer(newOutputLayer, *newLayerFE, outputLayerCompositionState,
Alec Mourieb920d92021-03-01 17:48:30 -0800569 layerFECompositionStateTwo);
Dominik Laskowski2f01d772022-03-23 16:01:29 -0700570 ftl::Flags<LayerStateField> updates = mLayerState->update(&newOutputLayer);
571 EXPECT_EQ(ftl::Flags<LayerStateField>(LayerStateField::Alpha), updates);
Alec Mourieb920d92021-03-01 17:48:30 -0800572}
573
574TEST_F(LayerStateTest, compareAlpha) {
575 OutputLayerCompositionState outputLayerCompositionState;
576 LayerFECompositionState layerFECompositionState;
577 layerFECompositionState.alpha = sAlphaOne;
Ady Abrahame0eafa82022-02-02 19:30:47 -0800578 setupMocksForLayer(mOutputLayer, *mLayerFE, outputLayerCompositionState,
Alec Mourieb920d92021-03-01 17:48:30 -0800579 layerFECompositionState);
580 mLayerState = std::make_unique<LayerState>(&mOutputLayer);
581 mock::OutputLayer newOutputLayer;
Ady Abrahame0eafa82022-02-02 19:30:47 -0800582 sp<mock::LayerFE> newLayerFE = sp<mock::LayerFE>::make();
Alec Mourieb920d92021-03-01 17:48:30 -0800583 LayerFECompositionState layerFECompositionStateTwo;
584 layerFECompositionStateTwo.alpha = sAlphaTwo;
Ady Abrahame0eafa82022-02-02 19:30:47 -0800585 setupMocksForLayer(newOutputLayer, *newLayerFE, outputLayerCompositionState,
Alec Mourieb920d92021-03-01 17:48:30 -0800586 layerFECompositionStateTwo);
587 auto otherLayerState = std::make_unique<LayerState>(&newOutputLayer);
588
Alec Mouri69114c72021-03-19 19:31:29 -0700589 verifyNonUniqueDifferingFields(*mLayerState, *otherLayerState, LayerStateField::Alpha);
Alec Mourieb920d92021-03-01 17:48:30 -0800590
Alec Mouri69114c72021-03-19 19:31:29 -0700591 EXPECT_TRUE(mLayerState->compare(*otherLayerState));
592 EXPECT_TRUE(otherLayerState->compare(*mLayerState));
593}
594
595TEST_F(LayerStateTest, updateLayerMetadata) {
596 OutputLayerCompositionState outputLayerCompositionState;
597 LayerFECompositionState layerFECompositionState;
598 layerFECompositionState.metadata[sMetadataKeyOne] = sMetadataValueOne;
Ady Abrahame0eafa82022-02-02 19:30:47 -0800599 setupMocksForLayer(mOutputLayer, *mLayerFE, outputLayerCompositionState,
Alec Mouri69114c72021-03-19 19:31:29 -0700600 layerFECompositionState);
601 mLayerState = std::make_unique<LayerState>(&mOutputLayer);
602
603 mock::OutputLayer newOutputLayer;
Ady Abrahame0eafa82022-02-02 19:30:47 -0800604 sp<mock::LayerFE> newLayerFE = sp<mock::LayerFE>::make();
Alec Mouri69114c72021-03-19 19:31:29 -0700605 LayerFECompositionState layerFECompositionStateTwo;
606 layerFECompositionStateTwo.metadata[sMetadataKeyTwo] = sMetadataValueTwo;
Ady Abrahame0eafa82022-02-02 19:30:47 -0800607 setupMocksForLayer(newOutputLayer, *newLayerFE, outputLayerCompositionState,
Alec Mouri69114c72021-03-19 19:31:29 -0700608 layerFECompositionStateTwo);
Dominik Laskowski2f01d772022-03-23 16:01:29 -0700609 ftl::Flags<LayerStateField> updates = mLayerState->update(&newOutputLayer);
610 EXPECT_EQ(ftl::Flags<LayerStateField>(LayerStateField::LayerMetadata), updates);
Alec Mouri69114c72021-03-19 19:31:29 -0700611}
612
613TEST_F(LayerStateTest, compareLayerMetadata) {
614 OutputLayerCompositionState outputLayerCompositionState;
615 LayerFECompositionState layerFECompositionState;
616 layerFECompositionState.metadata[sMetadataKeyOne] = sMetadataValueOne;
Ady Abrahame0eafa82022-02-02 19:30:47 -0800617 setupMocksForLayer(mOutputLayer, *mLayerFE, outputLayerCompositionState,
Alec Mouri69114c72021-03-19 19:31:29 -0700618 layerFECompositionState);
619 mLayerState = std::make_unique<LayerState>(&mOutputLayer);
620 mock::OutputLayer newOutputLayer;
Ady Abrahame0eafa82022-02-02 19:30:47 -0800621 sp<mock::LayerFE> newLayerFE = sp<mock::LayerFE>::make();
Alec Mouri69114c72021-03-19 19:31:29 -0700622 LayerFECompositionState layerFECompositionStateTwo;
623 layerFECompositionStateTwo.metadata[sMetadataKeyTwo] = sMetadataValueTwo;
Ady Abrahame0eafa82022-02-02 19:30:47 -0800624 setupMocksForLayer(newOutputLayer, *newLayerFE, outputLayerCompositionState,
Alec Mouri69114c72021-03-19 19:31:29 -0700625 layerFECompositionStateTwo);
626 auto otherLayerState = std::make_unique<LayerState>(&newOutputLayer);
627
628 verifyNonUniqueDifferingFields(*mLayerState, *otherLayerState, LayerStateField::LayerMetadata);
Alec Mourieb920d92021-03-01 17:48:30 -0800629
630 EXPECT_TRUE(mLayerState->compare(*otherLayerState));
631 EXPECT_TRUE(otherLayerState->compare(*mLayerState));
632}
633
Alec Mouri464352b2021-03-24 16:33:21 -0700634TEST_F(LayerStateTest, getVisibleRegion) {
635 OutputLayerCompositionState outputLayerCompositionState;
636 outputLayerCompositionState.visibleRegion = sRegionOne;
637 LayerFECompositionState layerFECompositionState;
Ady Abrahame0eafa82022-02-02 19:30:47 -0800638 setupMocksForLayer(mOutputLayer, *mLayerFE, outputLayerCompositionState,
Alec Mouri464352b2021-03-24 16:33:21 -0700639 layerFECompositionState);
640 mLayerState = std::make_unique<LayerState>(&mOutputLayer);
641 EXPECT_TRUE(mLayerState->getVisibleRegion().hasSameRects(sRegionOne));
642}
643
Alec Mourieb920d92021-03-01 17:48:30 -0800644TEST_F(LayerStateTest, updateVisibleRegion) {
645 OutputLayerCompositionState outputLayerCompositionState;
646 outputLayerCompositionState.visibleRegion = sRegionOne;
647 LayerFECompositionState layerFECompositionState;
Ady Abrahame0eafa82022-02-02 19:30:47 -0800648 setupMocksForLayer(mOutputLayer, *mLayerFE, outputLayerCompositionState,
Alec Mourieb920d92021-03-01 17:48:30 -0800649 layerFECompositionState);
650 mLayerState = std::make_unique<LayerState>(&mOutputLayer);
651
652 mock::OutputLayer newOutputLayer;
Ady Abrahame0eafa82022-02-02 19:30:47 -0800653 sp<mock::LayerFE> newLayerFE = sp<mock::LayerFE>::make();
Alec Mourieb920d92021-03-01 17:48:30 -0800654 OutputLayerCompositionState outputLayerCompositionStateTwo;
655 outputLayerCompositionStateTwo.visibleRegion = sRegionTwo;
Ady Abrahame0eafa82022-02-02 19:30:47 -0800656 setupMocksForLayer(newOutputLayer, *newLayerFE, outputLayerCompositionStateTwo,
Alec Mourieb920d92021-03-01 17:48:30 -0800657 layerFECompositionState);
Dominik Laskowski2f01d772022-03-23 16:01:29 -0700658 ftl::Flags<LayerStateField> updates = mLayerState->update(&newOutputLayer);
659 EXPECT_EQ(ftl::Flags<LayerStateField>(LayerStateField::VisibleRegion), updates);
Alec Mourieb920d92021-03-01 17:48:30 -0800660}
661
662TEST_F(LayerStateTest, compareVisibleRegion) {
663 OutputLayerCompositionState outputLayerCompositionState;
664 outputLayerCompositionState.visibleRegion = sRegionOne;
665 LayerFECompositionState layerFECompositionState;
Ady Abrahame0eafa82022-02-02 19:30:47 -0800666 setupMocksForLayer(mOutputLayer, *mLayerFE, outputLayerCompositionState,
Alec Mourieb920d92021-03-01 17:48:30 -0800667 layerFECompositionState);
668 mLayerState = std::make_unique<LayerState>(&mOutputLayer);
669 mock::OutputLayer newOutputLayer;
Ady Abrahame0eafa82022-02-02 19:30:47 -0800670 sp<mock::LayerFE> newLayerFE = sp<mock::LayerFE>::make();
Alec Mourieb920d92021-03-01 17:48:30 -0800671 OutputLayerCompositionState outputLayerCompositionStateTwo;
672 outputLayerCompositionStateTwo.visibleRegion = sRegionTwo;
Ady Abrahame0eafa82022-02-02 19:30:47 -0800673 setupMocksForLayer(newOutputLayer, *newLayerFE, outputLayerCompositionStateTwo,
Alec Mourieb920d92021-03-01 17:48:30 -0800674 layerFECompositionState);
675 auto otherLayerState = std::make_unique<LayerState>(&newOutputLayer);
676
Alec Mouri69114c72021-03-19 19:31:29 -0700677 verifyNonUniqueDifferingFields(*mLayerState, *otherLayerState, LayerStateField::VisibleRegion);
Alec Mourieb920d92021-03-01 17:48:30 -0800678
679 EXPECT_TRUE(mLayerState->compare(*otherLayerState));
680 EXPECT_TRUE(otherLayerState->compare(*mLayerState));
681}
682
683TEST_F(LayerStateTest, updateDataspace) {
684 OutputLayerCompositionState outputLayerCompositionState;
685 outputLayerCompositionState.dataspace = ui::Dataspace::SRGB;
686 LayerFECompositionState layerFECompositionState;
Ady Abrahame0eafa82022-02-02 19:30:47 -0800687 setupMocksForLayer(mOutputLayer, *mLayerFE, outputLayerCompositionState,
Alec Mourieb920d92021-03-01 17:48:30 -0800688 layerFECompositionState);
689 mLayerState = std::make_unique<LayerState>(&mOutputLayer);
690
691 mock::OutputLayer newOutputLayer;
Ady Abrahame0eafa82022-02-02 19:30:47 -0800692 sp<mock::LayerFE> newLayerFE = sp<mock::LayerFE>::make();
Alec Mourieb920d92021-03-01 17:48:30 -0800693 OutputLayerCompositionState outputLayerCompositionStateTwo;
694 outputLayerCompositionStateTwo.dataspace = ui::Dataspace::DISPLAY_P3;
Ady Abrahame0eafa82022-02-02 19:30:47 -0800695 setupMocksForLayer(newOutputLayer, *newLayerFE, outputLayerCompositionStateTwo,
Alec Mourieb920d92021-03-01 17:48:30 -0800696 layerFECompositionState);
Dominik Laskowski2f01d772022-03-23 16:01:29 -0700697 ftl::Flags<LayerStateField> updates = mLayerState->update(&newOutputLayer);
698 EXPECT_EQ(ftl::Flags<LayerStateField>(LayerStateField::Dataspace), updates);
Alec Mourieb920d92021-03-01 17:48:30 -0800699}
700
701TEST_F(LayerStateTest, compareDataspace) {
702 OutputLayerCompositionState outputLayerCompositionState;
703 outputLayerCompositionState.dataspace = ui::Dataspace::SRGB;
704 LayerFECompositionState layerFECompositionState;
Ady Abrahame0eafa82022-02-02 19:30:47 -0800705 setupMocksForLayer(mOutputLayer, *mLayerFE, outputLayerCompositionState,
Alec Mourieb920d92021-03-01 17:48:30 -0800706 layerFECompositionState);
707 mLayerState = std::make_unique<LayerState>(&mOutputLayer);
708 mock::OutputLayer newOutputLayer;
Ady Abrahame0eafa82022-02-02 19:30:47 -0800709 sp<mock::LayerFE> newLayerFE = sp<mock::LayerFE>::make();
Alec Mourieb920d92021-03-01 17:48:30 -0800710 OutputLayerCompositionState outputLayerCompositionStateTwo;
711 outputLayerCompositionStateTwo.dataspace = ui::Dataspace::DISPLAY_P3;
Ady Abrahame0eafa82022-02-02 19:30:47 -0800712 setupMocksForLayer(newOutputLayer, *newLayerFE, outputLayerCompositionStateTwo,
Alec Mourieb920d92021-03-01 17:48:30 -0800713 layerFECompositionState);
714 auto otherLayerState = std::make_unique<LayerState>(&newOutputLayer);
715
Alec Mouri69114c72021-03-19 19:31:29 -0700716 verifyNonUniqueDifferingFields(*mLayerState, *otherLayerState, LayerStateField::Dataspace);
Alec Mourieb920d92021-03-01 17:48:30 -0800717
Alec Mouri69114c72021-03-19 19:31:29 -0700718 EXPECT_TRUE(mLayerState->compare(*otherLayerState));
719 EXPECT_TRUE(otherLayerState->compare(*mLayerState));
720}
721
722TEST_F(LayerStateTest, updatePixelFormat) {
723 OutputLayerCompositionState outputLayerCompositionState;
724 LayerFECompositionState layerFECompositionState;
725 layerFECompositionState.buffer =
Ady Abrahamd11bade2022-08-01 16:18:03 -0700726 sp<GraphicBuffer>::make(1u, 1u, PIXEL_FORMAT_RGBA_8888, kUsageFlags, "buffer1");
Ady Abrahame0eafa82022-02-02 19:30:47 -0800727 setupMocksForLayer(mOutputLayer, *mLayerFE, outputLayerCompositionState,
Alec Mouri69114c72021-03-19 19:31:29 -0700728 layerFECompositionState);
729 mLayerState = std::make_unique<LayerState>(&mOutputLayer);
730
731 mock::OutputLayer newOutputLayer;
Ady Abrahame0eafa82022-02-02 19:30:47 -0800732 sp<mock::LayerFE> newLayerFE = sp<mock::LayerFE>::make();
Alec Mouri69114c72021-03-19 19:31:29 -0700733 LayerFECompositionState layerFECompositionStateTwo;
734 layerFECompositionStateTwo.buffer =
Ady Abrahamd11bade2022-08-01 16:18:03 -0700735 sp<GraphicBuffer>::make(1u, 1u, PIXEL_FORMAT_RGBX_8888, kUsageFlags, "buffer2");
Ady Abrahame0eafa82022-02-02 19:30:47 -0800736 setupMocksForLayer(newOutputLayer, *newLayerFE, outputLayerCompositionState,
Alec Mouri69114c72021-03-19 19:31:29 -0700737 layerFECompositionStateTwo);
Dominik Laskowski2f01d772022-03-23 16:01:29 -0700738 ftl::Flags<LayerStateField> updates = mLayerState->update(&newOutputLayer);
739 EXPECT_EQ(ftl::Flags<LayerStateField>(LayerStateField::Buffer) |
740 ftl::Flags<LayerStateField>(LayerStateField::PixelFormat),
Alec Mouri69114c72021-03-19 19:31:29 -0700741 updates);
742}
743
744TEST_F(LayerStateTest, comparePixelFormat) {
745 OutputLayerCompositionState outputLayerCompositionState;
746 LayerFECompositionState layerFECompositionState;
747 layerFECompositionState.buffer =
Ady Abrahamd11bade2022-08-01 16:18:03 -0700748 sp<GraphicBuffer>::make(1u, 1u, PIXEL_FORMAT_RGBA_8888, kUsageFlags, "buffer1");
Ady Abrahame0eafa82022-02-02 19:30:47 -0800749 setupMocksForLayer(mOutputLayer, *mLayerFE, outputLayerCompositionState,
Alec Mouri69114c72021-03-19 19:31:29 -0700750 layerFECompositionState);
751 mLayerState = std::make_unique<LayerState>(&mOutputLayer);
752 mock::OutputLayer newOutputLayer;
Ady Abrahame0eafa82022-02-02 19:30:47 -0800753 sp<mock::LayerFE> newLayerFE = sp<mock::LayerFE>::make();
Alec Mouri69114c72021-03-19 19:31:29 -0700754 LayerFECompositionState layerFECompositionStateTwo;
755 layerFECompositionStateTwo.buffer =
Ady Abrahamd11bade2022-08-01 16:18:03 -0700756 sp<GraphicBuffer>::make(1u, 1u, PIXEL_FORMAT_RGBX_8888, kUsageFlags, "buffer2");
Ady Abrahame0eafa82022-02-02 19:30:47 -0800757 setupMocksForLayer(newOutputLayer, *newLayerFE, outputLayerCompositionState,
Alec Mouri69114c72021-03-19 19:31:29 -0700758 layerFECompositionStateTwo);
759 auto otherLayerState = std::make_unique<LayerState>(&newOutputLayer);
760
761 verifyNonUniqueDifferingFields(*mLayerState, *otherLayerState,
Dominik Laskowski2f01d772022-03-23 16:01:29 -0700762 ftl::Flags<LayerStateField>(LayerStateField::PixelFormat));
Alec Mourieb920d92021-03-01 17:48:30 -0800763
764 EXPECT_TRUE(mLayerState->compare(*otherLayerState));
765 EXPECT_TRUE(otherLayerState->compare(*mLayerState));
766}
767
768TEST_F(LayerStateTest, updateColorTransform) {
769 OutputLayerCompositionState outputLayerCompositionState;
770 LayerFECompositionState layerFECompositionState;
771 layerFECompositionState.colorTransformIsIdentity = true;
772 layerFECompositionState.colorTransform = mat4();
Ady Abrahame0eafa82022-02-02 19:30:47 -0800773 setupMocksForLayer(mOutputLayer, *mLayerFE, outputLayerCompositionState,
Alec Mourieb920d92021-03-01 17:48:30 -0800774 layerFECompositionState);
775 mLayerState = std::make_unique<LayerState>(&mOutputLayer);
776
777 mock::OutputLayer newOutputLayer;
Ady Abrahame0eafa82022-02-02 19:30:47 -0800778 sp<mock::LayerFE> newLayerFE = sp<mock::LayerFE>::make();
Alec Mourieb920d92021-03-01 17:48:30 -0800779 LayerFECompositionState layerFECompositionStateTwo;
780 layerFECompositionStateTwo.colorTransformIsIdentity = false;
781 layerFECompositionStateTwo.colorTransform = sMat4One;
Ady Abrahame0eafa82022-02-02 19:30:47 -0800782 setupMocksForLayer(newOutputLayer, *newLayerFE, outputLayerCompositionState,
Alec Mourieb920d92021-03-01 17:48:30 -0800783 layerFECompositionStateTwo);
Dominik Laskowski2f01d772022-03-23 16:01:29 -0700784 ftl::Flags<LayerStateField> updates = mLayerState->update(&newOutputLayer);
785 EXPECT_EQ(ftl::Flags<LayerStateField>(LayerStateField::ColorTransform), updates);
Alec Mourieb920d92021-03-01 17:48:30 -0800786}
787
788TEST_F(LayerStateTest, compareColorTransform) {
789 OutputLayerCompositionState outputLayerCompositionState;
790 LayerFECompositionState layerFECompositionState;
791 layerFECompositionState.colorTransformIsIdentity = true;
792 layerFECompositionState.colorTransform = mat4();
Ady Abrahame0eafa82022-02-02 19:30:47 -0800793 setupMocksForLayer(mOutputLayer, *mLayerFE, outputLayerCompositionState,
Alec Mourieb920d92021-03-01 17:48:30 -0800794 layerFECompositionState);
795 mLayerState = std::make_unique<LayerState>(&mOutputLayer);
796 mock::OutputLayer newOutputLayer;
Ady Abrahame0eafa82022-02-02 19:30:47 -0800797 sp<mock::LayerFE> newLayerFE = sp<mock::LayerFE>::make();
Alec Mourieb920d92021-03-01 17:48:30 -0800798 LayerFECompositionState layerFECompositionStateTwo;
799 layerFECompositionStateTwo.colorTransformIsIdentity = false;
800 layerFECompositionStateTwo.colorTransform = sMat4One;
Ady Abrahame0eafa82022-02-02 19:30:47 -0800801 setupMocksForLayer(newOutputLayer, *newLayerFE, outputLayerCompositionState,
Alec Mourieb920d92021-03-01 17:48:30 -0800802 layerFECompositionStateTwo);
803 auto otherLayerState = std::make_unique<LayerState>(&newOutputLayer);
804
Alec Mouri69114c72021-03-19 19:31:29 -0700805 verifyNonUniqueDifferingFields(*mLayerState, *otherLayerState, LayerStateField::ColorTransform);
Alec Mourieb920d92021-03-01 17:48:30 -0800806
Alec Mouri69114c72021-03-19 19:31:29 -0700807 EXPECT_TRUE(mLayerState->compare(*otherLayerState));
808 EXPECT_TRUE(otherLayerState->compare(*mLayerState));
809}
810
Alec Mourieb920d92021-03-01 17:48:30 -0800811TEST_F(LayerStateTest, updateSidebandStream) {
812 OutputLayerCompositionState outputLayerCompositionState;
813 LayerFECompositionState layerFECompositionState;
814 layerFECompositionState.sidebandStream = NativeHandle::create(sFakeSidebandStreamOne, false);
Ady Abrahame0eafa82022-02-02 19:30:47 -0800815 setupMocksForLayer(mOutputLayer, *mLayerFE, outputLayerCompositionState,
Alec Mourieb920d92021-03-01 17:48:30 -0800816 layerFECompositionState);
817 mLayerState = std::make_unique<LayerState>(&mOutputLayer);
818
819 mock::OutputLayer newOutputLayer;
Ady Abrahame0eafa82022-02-02 19:30:47 -0800820 sp<mock::LayerFE> newLayerFE = sp<mock::LayerFE>::make();
Alec Mourieb920d92021-03-01 17:48:30 -0800821 LayerFECompositionState layerFECompositionStateTwo;
822 layerFECompositionStateTwo.sidebandStream = NativeHandle::create(sFakeSidebandStreamTwo, false);
Ady Abrahame0eafa82022-02-02 19:30:47 -0800823 setupMocksForLayer(newOutputLayer, *newLayerFE, outputLayerCompositionState,
Alec Mourieb920d92021-03-01 17:48:30 -0800824 layerFECompositionStateTwo);
Dominik Laskowski2f01d772022-03-23 16:01:29 -0700825 ftl::Flags<LayerStateField> updates = mLayerState->update(&newOutputLayer);
826 EXPECT_EQ(ftl::Flags<LayerStateField>(LayerStateField::SidebandStream), updates);
Alec Mourieb920d92021-03-01 17:48:30 -0800827}
828
829TEST_F(LayerStateTest, compareSidebandStream) {
830 OutputLayerCompositionState outputLayerCompositionState;
831 LayerFECompositionState layerFECompositionState;
832 layerFECompositionState.sidebandStream = NativeHandle::create(sFakeSidebandStreamOne, false);
Ady Abrahame0eafa82022-02-02 19:30:47 -0800833 setupMocksForLayer(mOutputLayer, *mLayerFE, outputLayerCompositionState,
Alec Mourieb920d92021-03-01 17:48:30 -0800834 layerFECompositionState);
835 mLayerState = std::make_unique<LayerState>(&mOutputLayer);
836 mock::OutputLayer newOutputLayer;
Ady Abrahame0eafa82022-02-02 19:30:47 -0800837 sp<mock::LayerFE> newLayerFE = sp<mock::LayerFE>::make();
Alec Mourieb920d92021-03-01 17:48:30 -0800838 LayerFECompositionState layerFECompositionStateTwo;
839 layerFECompositionStateTwo.sidebandStream = NativeHandle::create(sFakeSidebandStreamTwo, false);
Ady Abrahame0eafa82022-02-02 19:30:47 -0800840 setupMocksForLayer(newOutputLayer, *newLayerFE, outputLayerCompositionState,
Alec Mourieb920d92021-03-01 17:48:30 -0800841 layerFECompositionStateTwo);
842 auto otherLayerState = std::make_unique<LayerState>(&newOutputLayer);
843
Alec Mouri69114c72021-03-19 19:31:29 -0700844 verifyNonUniqueDifferingFields(*mLayerState, *otherLayerState, LayerStateField::SidebandStream);
Alec Mourieb920d92021-03-01 17:48:30 -0800845
846 EXPECT_TRUE(mLayerState->compare(*otherLayerState));
847 EXPECT_TRUE(otherLayerState->compare(*mLayerState));
848}
849
850TEST_F(LayerStateTest, updateSolidColor) {
851 OutputLayerCompositionState outputLayerCompositionState;
852 LayerFECompositionState layerFECompositionState;
853 layerFECompositionState.color = sHalf4One;
Ady Abrahame0eafa82022-02-02 19:30:47 -0800854 setupMocksForLayer(mOutputLayer, *mLayerFE, outputLayerCompositionState,
Alec Mourieb920d92021-03-01 17:48:30 -0800855 layerFECompositionState);
856 mLayerState = std::make_unique<LayerState>(&mOutputLayer);
857
858 mock::OutputLayer newOutputLayer;
Ady Abrahame0eafa82022-02-02 19:30:47 -0800859 sp<mock::LayerFE> newLayerFE = sp<mock::LayerFE>::make();
Alec Mourieb920d92021-03-01 17:48:30 -0800860 LayerFECompositionState layerFECompositionStateTwo;
861 layerFECompositionStateTwo.color = sHalf4Two;
Ady Abrahame0eafa82022-02-02 19:30:47 -0800862 setupMocksForLayer(newOutputLayer, *newLayerFE, outputLayerCompositionState,
Alec Mourieb920d92021-03-01 17:48:30 -0800863 layerFECompositionStateTwo);
Dominik Laskowski2f01d772022-03-23 16:01:29 -0700864 ftl::Flags<LayerStateField> updates = mLayerState->update(&newOutputLayer);
865 EXPECT_EQ(ftl::Flags<LayerStateField>(LayerStateField::SolidColor), updates);
Alec Mourieb920d92021-03-01 17:48:30 -0800866}
867
868TEST_F(LayerStateTest, compareSolidColor) {
869 OutputLayerCompositionState outputLayerCompositionState;
870 LayerFECompositionState layerFECompositionState;
871 layerFECompositionState.color = sHalf4One;
Ady Abrahame0eafa82022-02-02 19:30:47 -0800872 setupMocksForLayer(mOutputLayer, *mLayerFE, outputLayerCompositionState,
Alec Mourieb920d92021-03-01 17:48:30 -0800873 layerFECompositionState);
874 mLayerState = std::make_unique<LayerState>(&mOutputLayer);
875 mock::OutputLayer newOutputLayer;
Ady Abrahame0eafa82022-02-02 19:30:47 -0800876 sp<mock::LayerFE> newLayerFE = sp<mock::LayerFE>::make();
Alec Mourieb920d92021-03-01 17:48:30 -0800877 LayerFECompositionState layerFECompositionStateTwo;
878 layerFECompositionStateTwo.color = sHalf4Two;
Ady Abrahame0eafa82022-02-02 19:30:47 -0800879 setupMocksForLayer(newOutputLayer, *newLayerFE, outputLayerCompositionState,
Alec Mourieb920d92021-03-01 17:48:30 -0800880 layerFECompositionStateTwo);
881 auto otherLayerState = std::make_unique<LayerState>(&newOutputLayer);
882
Alec Mouri69114c72021-03-19 19:31:29 -0700883 verifyNonUniqueDifferingFields(*mLayerState, *otherLayerState, LayerStateField::SolidColor);
Alec Mourieb920d92021-03-01 17:48:30 -0800884
885 EXPECT_TRUE(mLayerState->compare(*otherLayerState));
886 EXPECT_TRUE(otherLayerState->compare(*mLayerState));
887}
888
Alec Mouri97486062021-05-07 15:26:03 -0700889TEST_F(LayerStateTest, updateBackgroundBlur) {
890 OutputLayerCompositionState outputLayerCompositionState;
891 LayerFECompositionState layerFECompositionState;
892 layerFECompositionState.backgroundBlurRadius = sBgBlurRadiusOne;
Ady Abrahame0eafa82022-02-02 19:30:47 -0800893 setupMocksForLayer(mOutputLayer, *mLayerFE, outputLayerCompositionState,
Alec Mouri97486062021-05-07 15:26:03 -0700894 layerFECompositionState);
895 mLayerState = std::make_unique<LayerState>(&mOutputLayer);
896
897 mock::OutputLayer newOutputLayer;
Ady Abrahame0eafa82022-02-02 19:30:47 -0800898 sp<mock::LayerFE> newLayerFE = sp<mock::LayerFE>::make();
Alec Mouri97486062021-05-07 15:26:03 -0700899 LayerFECompositionState layerFECompositionStateTwo;
900 layerFECompositionStateTwo.backgroundBlurRadius = sBgBlurRadiusTwo;
Ady Abrahame0eafa82022-02-02 19:30:47 -0800901 setupMocksForLayer(newOutputLayer, *newLayerFE, outputLayerCompositionState,
Alec Mouri97486062021-05-07 15:26:03 -0700902 layerFECompositionStateTwo);
Dominik Laskowski2f01d772022-03-23 16:01:29 -0700903 ftl::Flags<LayerStateField> updates = mLayerState->update(&newOutputLayer);
904 EXPECT_EQ(ftl::Flags<LayerStateField>(LayerStateField::BackgroundBlurRadius), updates);
Alec Mouri97486062021-05-07 15:26:03 -0700905}
906
907TEST_F(LayerStateTest, compareBackgroundBlur) {
908 OutputLayerCompositionState outputLayerCompositionState;
909 LayerFECompositionState layerFECompositionState;
910 layerFECompositionState.backgroundBlurRadius = sBgBlurRadiusOne;
Ady Abrahame0eafa82022-02-02 19:30:47 -0800911 setupMocksForLayer(mOutputLayer, *mLayerFE, outputLayerCompositionState,
Alec Mouri97486062021-05-07 15:26:03 -0700912 layerFECompositionState);
913 mLayerState = std::make_unique<LayerState>(&mOutputLayer);
914 mock::OutputLayer newOutputLayer;
Ady Abrahame0eafa82022-02-02 19:30:47 -0800915 sp<mock::LayerFE> newLayerFE = sp<mock::LayerFE>::make();
Alec Mouri97486062021-05-07 15:26:03 -0700916 LayerFECompositionState layerFECompositionStateTwo;
917 layerFECompositionStateTwo.backgroundBlurRadius = sBgBlurRadiusTwo;
Ady Abrahame0eafa82022-02-02 19:30:47 -0800918 setupMocksForLayer(newOutputLayer, *newLayerFE, outputLayerCompositionState,
Alec Mouri97486062021-05-07 15:26:03 -0700919 layerFECompositionStateTwo);
920 auto otherLayerState = std::make_unique<LayerState>(&newOutputLayer);
921
922 verifyNonUniqueDifferingFields(*mLayerState, *otherLayerState,
923 LayerStateField::BackgroundBlurRadius);
924
925 EXPECT_TRUE(mLayerState->compare(*otherLayerState));
926 EXPECT_TRUE(otherLayerState->compare(*mLayerState));
927}
928
929TEST_F(LayerStateTest, updateBlurRegions) {
930 OutputLayerCompositionState outputLayerCompositionState;
931 LayerFECompositionState layerFECompositionState;
932 layerFECompositionState.blurRegions.push_back(sBlurRegionOne);
Ady Abrahame0eafa82022-02-02 19:30:47 -0800933 setupMocksForLayer(mOutputLayer, *mLayerFE, outputLayerCompositionState,
Alec Mouri97486062021-05-07 15:26:03 -0700934 layerFECompositionState);
935 mLayerState = std::make_unique<LayerState>(&mOutputLayer);
936
937 mock::OutputLayer newOutputLayer;
Ady Abrahame0eafa82022-02-02 19:30:47 -0800938 sp<mock::LayerFE> newLayerFE = sp<mock::LayerFE>::make();
Alec Mouri97486062021-05-07 15:26:03 -0700939 LayerFECompositionState layerFECompositionStateTwo;
940 layerFECompositionStateTwo.blurRegions.push_back(sBlurRegionTwo);
Ady Abrahame0eafa82022-02-02 19:30:47 -0800941 setupMocksForLayer(newOutputLayer, *newLayerFE, outputLayerCompositionState,
Alec Mouri97486062021-05-07 15:26:03 -0700942 layerFECompositionStateTwo);
Dominik Laskowski2f01d772022-03-23 16:01:29 -0700943 ftl::Flags<LayerStateField> updates = mLayerState->update(&newOutputLayer);
944 EXPECT_EQ(ftl::Flags<LayerStateField>(LayerStateField::BlurRegions), updates);
Alec Mouri97486062021-05-07 15:26:03 -0700945}
946
947TEST_F(LayerStateTest, compareBlurRegions) {
948 OutputLayerCompositionState outputLayerCompositionState;
949 LayerFECompositionState layerFECompositionState;
950 layerFECompositionState.blurRegions.push_back(sBlurRegionOne);
Ady Abrahame0eafa82022-02-02 19:30:47 -0800951 setupMocksForLayer(mOutputLayer, *mLayerFE, outputLayerCompositionState,
Alec Mouri97486062021-05-07 15:26:03 -0700952 layerFECompositionState);
953 mLayerState = std::make_unique<LayerState>(&mOutputLayer);
954 mock::OutputLayer newOutputLayer;
Ady Abrahame0eafa82022-02-02 19:30:47 -0800955 sp<mock::LayerFE> newLayerFE = sp<mock::LayerFE>::make();
Alec Mouri97486062021-05-07 15:26:03 -0700956 LayerFECompositionState layerFECompositionStateTwo;
957 layerFECompositionStateTwo.blurRegions.push_back(sBlurRegionTwo);
Ady Abrahame0eafa82022-02-02 19:30:47 -0800958 setupMocksForLayer(newOutputLayer, *newLayerFE, outputLayerCompositionState,
Alec Mouri97486062021-05-07 15:26:03 -0700959 layerFECompositionStateTwo);
960 auto otherLayerState = std::make_unique<LayerState>(&newOutputLayer);
961
962 verifyNonUniqueDifferingFields(*mLayerState, *otherLayerState, LayerStateField::BlurRegions);
963
964 EXPECT_TRUE(mLayerState->compare(*otherLayerState));
965 EXPECT_TRUE(otherLayerState->compare(*mLayerState));
966}
967
968TEST_F(LayerStateTest, hasBlurBehind_noBlur_returnsFalse) {
969 OutputLayerCompositionState outputLayerCompositionState;
970 LayerFECompositionState layerFECompositionState;
Ady Abrahame0eafa82022-02-02 19:30:47 -0800971 setupMocksForLayer(mOutputLayer, *mLayerFE, outputLayerCompositionState,
Alec Mouri97486062021-05-07 15:26:03 -0700972 layerFECompositionState);
973 mLayerState = std::make_unique<LayerState>(&mOutputLayer);
974 EXPECT_FALSE(mLayerState->hasBlurBehind());
975}
976
977TEST_F(LayerStateTest, hasBlurBehind_withBackgroundBlur_returnsTrue) {
978 OutputLayerCompositionState outputLayerCompositionState;
979 LayerFECompositionState layerFECompositionState;
980 layerFECompositionState.backgroundBlurRadius = sBgBlurRadiusOne;
Ady Abrahame0eafa82022-02-02 19:30:47 -0800981 setupMocksForLayer(mOutputLayer, *mLayerFE, outputLayerCompositionState,
Alec Mouri97486062021-05-07 15:26:03 -0700982 layerFECompositionState);
983 mLayerState = std::make_unique<LayerState>(&mOutputLayer);
984 EXPECT_TRUE(mLayerState->hasBlurBehind());
985}
986
987TEST_F(LayerStateTest, hasBlurBehind_withBlurRegion_returnsTrue) {
988 OutputLayerCompositionState outputLayerCompositionState;
989 LayerFECompositionState layerFECompositionState;
990 layerFECompositionState.blurRegions.push_back(sBlurRegionOne);
Ady Abrahame0eafa82022-02-02 19:30:47 -0800991 setupMocksForLayer(mOutputLayer, *mLayerFE, outputLayerCompositionState,
Alec Mouri97486062021-05-07 15:26:03 -0700992 layerFECompositionState);
993 mLayerState = std::make_unique<LayerState>(&mOutputLayer);
994 EXPECT_TRUE(mLayerState->hasBlurBehind());
995}
996
Alec Mourieb920d92021-03-01 17:48:30 -0800997TEST_F(LayerStateTest, dumpDoesNotCrash) {
998 OutputLayerCompositionState outputLayerCompositionState;
999 LayerFECompositionState layerFECompositionState;
Ady Abrahame0eafa82022-02-02 19:30:47 -08001000 setupMocksForLayer(mOutputLayer, *mLayerFE, outputLayerCompositionState,
Alec Mourieb920d92021-03-01 17:48:30 -08001001 layerFECompositionState);
1002 mLayerState = std::make_unique<LayerState>(&mOutputLayer);
1003 std::string dump;
1004 mLayerState->dump(dump);
1005 EXPECT_TRUE(dump.size() > 0);
1006}
1007
1008TEST_F(LayerStateTest, framesSinceBufferUpdate) {
1009 OutputLayerCompositionState outputLayerCompositionState;
1010 LayerFECompositionState layerFECompositionState;
Ady Abrahame0eafa82022-02-02 19:30:47 -08001011 setupMocksForLayer(mOutputLayer, *mLayerFE, outputLayerCompositionState,
Alec Mourieb920d92021-03-01 17:48:30 -08001012 layerFECompositionState);
1013 mLayerState = std::make_unique<LayerState>(&mOutputLayer);
1014
1015 EXPECT_EQ(0, mLayerState->getFramesSinceBufferUpdate());
1016 mLayerState->incrementFramesSinceBufferUpdate();
1017 EXPECT_EQ(1, mLayerState->getFramesSinceBufferUpdate());
1018 mLayerState->resetFramesSinceBufferUpdate();
1019 EXPECT_EQ(0, mLayerState->getFramesSinceBufferUpdate());
1020}
1021
1022TEST_F(LayerStateTest, getNonBufferHash_doesNotCommute) {
1023 OutputLayerCompositionState outputLayerCompositionState;
1024 outputLayerCompositionState.displayFrame = sRectOne;
1025 LayerFECompositionState layerFECompositionState;
Ady Abrahame0eafa82022-02-02 19:30:47 -08001026 setupMocksForLayer(mOutputLayer, *mLayerFE, outputLayerCompositionState,
Alec Mourieb920d92021-03-01 17:48:30 -08001027 layerFECompositionState);
1028 mLayerState = std::make_unique<LayerState>(&mOutputLayer);
1029 mock::OutputLayer newOutputLayer;
Ady Abrahame0eafa82022-02-02 19:30:47 -08001030 sp<mock::LayerFE> newLayerFE = sp<mock::LayerFE>::make();
Alec Mourieb920d92021-03-01 17:48:30 -08001031 OutputLayerCompositionState outputLayerCompositionStateTwo;
1032 outputLayerCompositionStateTwo.displayFrame = sRectTwo;
Ady Abrahame0eafa82022-02-02 19:30:47 -08001033 setupMocksForLayer(newOutputLayer, *newLayerFE, outputLayerCompositionStateTwo,
Alec Mourieb920d92021-03-01 17:48:30 -08001034 layerFECompositionState);
1035 auto otherLayerState = std::make_unique<LayerState>(&newOutputLayer);
1036
1037 EXPECT_NE(getNonBufferHash({mLayerState.get(), otherLayerState.get()}),
1038 getNonBufferHash({otherLayerState.get(), mLayerState.get()}));
1039}
1040
1041TEST_F(LayerStateTest, getNonBufferHash_isIdempotent) {
1042 OutputLayerCompositionState outputLayerCompositionState;
1043 outputLayerCompositionState.displayFrame = sRectOne;
1044 LayerFECompositionState layerFECompositionState;
Ady Abrahame0eafa82022-02-02 19:30:47 -08001045 setupMocksForLayer(mOutputLayer, *mLayerFE, outputLayerCompositionState,
Alec Mourieb920d92021-03-01 17:48:30 -08001046 layerFECompositionState);
1047 mLayerState = std::make_unique<LayerState>(&mOutputLayer);
1048 mock::OutputLayer newOutputLayer;
Ady Abrahame0eafa82022-02-02 19:30:47 -08001049 sp<mock::LayerFE> newLayerFE = sp<mock::LayerFE>::make();
Alec Mourieb920d92021-03-01 17:48:30 -08001050 OutputLayerCompositionState outputLayerCompositionStateTwo;
1051 outputLayerCompositionStateTwo.displayFrame = sRectTwo;
Ady Abrahame0eafa82022-02-02 19:30:47 -08001052 setupMocksForLayer(newOutputLayer, *newLayerFE, outputLayerCompositionStateTwo,
Alec Mourieb920d92021-03-01 17:48:30 -08001053 layerFECompositionState);
1054 auto otherLayerState = std::make_unique<LayerState>(&newOutputLayer);
1055
1056 EXPECT_EQ(getNonBufferHash({mLayerState.get(), otherLayerState.get()}),
1057 getNonBufferHash({mLayerState.get(), otherLayerState.get()}));
1058}
1059
1060TEST_F(LayerStateTest, getNonBufferHash_filtersOutBuffers) {
1061 OutputLayerCompositionState outputLayerCompositionState;
1062 LayerFECompositionState layerFECompositionState;
Ady Abrahamd11bade2022-08-01 16:18:03 -07001063 layerFECompositionState.buffer = sp<GraphicBuffer>::make();
Ady Abrahame0eafa82022-02-02 19:30:47 -08001064 setupMocksForLayer(mOutputLayer, *mLayerFE, outputLayerCompositionState,
Alec Mourieb920d92021-03-01 17:48:30 -08001065 layerFECompositionState);
1066 mLayerState = std::make_unique<LayerState>(&mOutputLayer);
1067
1068 mock::OutputLayer newOutputLayer;
Ady Abrahame0eafa82022-02-02 19:30:47 -08001069 sp<mock::LayerFE> newLayerFE = sp<mock::LayerFE>::make();
Alec Mourieb920d92021-03-01 17:48:30 -08001070 LayerFECompositionState layerFECompositionStateTwo;
Ady Abrahamd11bade2022-08-01 16:18:03 -07001071 layerFECompositionStateTwo.buffer = sp<GraphicBuffer>::make();
Ady Abrahame0eafa82022-02-02 19:30:47 -08001072 setupMocksForLayer(newOutputLayer, *newLayerFE, outputLayerCompositionState,
Alec Mourieb920d92021-03-01 17:48:30 -08001073 layerFECompositionStateTwo);
1074 auto otherLayerState = std::make_unique<LayerState>(&newOutputLayer);
1075
1076 EXPECT_EQ(getNonBufferHash({mLayerState.get()}), getNonBufferHash({otherLayerState.get()}));
1077}
1078
1079} // namespace
Leon Scroggins IIIe2ee0402021-04-02 16:59:37 -04001080} // namespace android::compositionengine::impl::planner