blob: 131187d5f433e85853d491a606dfd91ddaa287e2 [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
20#include <compositionengine/impl/OutputLayer.h>
21#include <compositionengine/impl/planner/LayerState.h>
22#include <compositionengine/mock/LayerFE.h>
23#include <compositionengine/mock/OutputLayer.h>
24#include <gtest/gtest.h>
25#include <log/log.h>
26
27namespace android::compositionengine::impl::planner {
28namespace {
29
30using testing::Return;
31using testing::ReturnRef;
32
33const std::string sDebugName = std::string("Test LayerFE");
34const std::string sDebugNameTwo = std::string("Test LayerFE2");
35const constexpr int32_t sSequenceId = 12345;
36const constexpr int32_t sSequenceIdTwo = 123456;
37const Rect sRectOne = Rect(10, 20, 30, 40);
38const Rect sRectTwo = Rect(40, 30, 20, 10);
39const FloatRect sFloatRectOne = FloatRect(100.f, 200.f, 300.f, 400.f);
40const FloatRect sFloatRectTwo = FloatRect(400.f, 300.f, 200.f, 100.f);
41const constexpr int32_t sZOne = 100;
42const constexpr int32_t sZTwo = 101;
43const constexpr float sAlphaOne = 0.25f;
44const constexpr float sAlphaTwo = 0.5f;
45const Region sRegionOne = Region(sRectOne);
46const Region sRegionTwo = Region(sRectTwo);
47const mat4 sMat4One = mat4::scale(vec4(2.f, 3.f, 1.f, 1.f));
48native_handle_t* const sFakeSidebandStreamOne = reinterpret_cast<native_handle_t*>(10);
49native_handle_t* const sFakeSidebandStreamTwo = reinterpret_cast<native_handle_t*>(11);
50const half4 sHalf4One = half4(0.2f, 0.3f, 0.4f, 0.5f);
51const half4 sHalf4Two = half4(0.5f, 0.4f, 0.43, 0.2f);
52
53struct LayerStateTest : public testing::Test {
54 LayerStateTest() {
55 const ::testing::TestInfo* const test_info =
56 ::testing::UnitTest::GetInstance()->current_test_info();
57 ALOGD("**** Setting up for %s.%s\n", test_info->test_case_name(), test_info->name());
58 }
59
60 ~LayerStateTest() {
61 const ::testing::TestInfo* const test_info =
62 ::testing::UnitTest::GetInstance()->current_test_info();
63 ALOGD("**** Tearing down after %s.%s\n", test_info->test_case_name(), test_info->name());
64 }
65
66 void setupMocksForLayer(mock::OutputLayer& layer, mock::LayerFE& layerFE,
67 const OutputLayerCompositionState& outputLayerState,
68 const LayerFECompositionState& layerFEState,
69 int32_t sequenceId = sSequenceId,
70 const std::string& debugName = sDebugName) {
71 EXPECT_CALL(layer, getLayerFE()).WillRepeatedly(ReturnRef(layerFE));
72 EXPECT_CALL(layer, getState()).WillRepeatedly(ReturnRef(outputLayerState));
73 EXPECT_CALL(layerFE, getSequence()).WillRepeatedly(Return(sequenceId));
74 EXPECT_CALL(layerFE, getDebugName()).WillRepeatedly(Return(debugName.c_str()));
75 EXPECT_CALL(layerFE, getCompositionState()).WillRepeatedly(Return(&layerFEState));
76 }
77
78 mock::LayerFE mLayerFE;
79 mock::OutputLayer mOutputLayer;
80 std::unique_ptr<LayerState> mLayerState;
81};
82
83TEST_F(LayerStateTest, getOutputLayer) {
84 OutputLayerCompositionState outputLayerCompositionState;
85 LayerFECompositionState layerFECompositionState;
86 setupMocksForLayer(mOutputLayer, mLayerFE, outputLayerCompositionState,
87 layerFECompositionState);
88 mLayerState = std::make_unique<LayerState>(&mOutputLayer);
89 EXPECT_EQ(&mOutputLayer, mLayerState->getOutputLayer());
90}
91
92TEST_F(LayerStateTest, getId) {
93 OutputLayerCompositionState outputLayerCompositionState;
94 LayerFECompositionState layerFECompositionState;
95 setupMocksForLayer(mOutputLayer, mLayerFE, outputLayerCompositionState,
96 layerFECompositionState);
97 mLayerState = std::make_unique<LayerState>(&mOutputLayer);
98 EXPECT_EQ(sSequenceId, mLayerState->getId());
99}
100
101TEST_F(LayerStateTest, updateId) {
102 OutputLayerCompositionState outputLayerCompositionState;
103 LayerFECompositionState layerFECompositionState;
104 setupMocksForLayer(mOutputLayer, mLayerFE, outputLayerCompositionState,
105 layerFECompositionState);
106 mLayerState = std::make_unique<LayerState>(&mOutputLayer);
107
108 mock::OutputLayer newOutputLayer;
109 mock::LayerFE newLayerFE;
110 setupMocksForLayer(newOutputLayer, newLayerFE, outputLayerCompositionState,
111 layerFECompositionState, sSequenceIdTwo);
112 Flags<LayerStateField> updates = mLayerState->update(&newOutputLayer);
113 EXPECT_EQ(sSequenceIdTwo, mLayerState->getId());
114 EXPECT_EQ(Flags<LayerStateField>(LayerStateField::Id), updates);
115}
116
117TEST_F(LayerStateTest, compareId) {
118 OutputLayerCompositionState outputLayerCompositionState;
119 LayerFECompositionState layerFECompositionState;
120 setupMocksForLayer(mOutputLayer, mLayerFE, outputLayerCompositionState,
121 layerFECompositionState);
122 mLayerState = std::make_unique<LayerState>(&mOutputLayer);
123 mock::OutputLayer newOutputLayer;
124 mock::LayerFE newLayerFE;
125 setupMocksForLayer(newOutputLayer, newLayerFE, outputLayerCompositionState,
126 layerFECompositionState, sSequenceIdTwo);
127 auto otherLayerState = std::make_unique<LayerState>(&newOutputLayer);
128
129 EXPECT_NE(mLayerState->getId(), otherLayerState->getId());
130
131 // Id is a unique field, so it's not computed in the hash for a layer state.
Alec Mouria19a8962021-03-30 14:19:31 -0700132 EXPECT_EQ(mLayerState->getHash(), otherLayerState->getHash());
Alec Mourieb920d92021-03-01 17:48:30 -0800133
134 // Similarly, Id cannot be included in differing fields.
135 EXPECT_EQ(Flags<LayerStateField>(LayerStateField::None),
Alec Mouria19a8962021-03-30 14:19:31 -0700136 mLayerState->getDifferingFields(*otherLayerState));
Alec Mourieb920d92021-03-01 17:48:30 -0800137 EXPECT_EQ(Flags<LayerStateField>(LayerStateField::None),
Alec Mouria19a8962021-03-30 14:19:31 -0700138 otherLayerState->getDifferingFields(*mLayerState));
Alec Mourieb920d92021-03-01 17:48:30 -0800139
140 EXPECT_FALSE(mLayerState->compare(*otherLayerState));
141 EXPECT_FALSE(otherLayerState->compare(*mLayerState));
142}
143
144TEST_F(LayerStateTest, getName) {
145 OutputLayerCompositionState outputLayerCompositionState;
146 LayerFECompositionState layerFECompositionState;
147 setupMocksForLayer(mOutputLayer, mLayerFE, outputLayerCompositionState,
148 layerFECompositionState);
149 mLayerState = std::make_unique<LayerState>(&mOutputLayer);
150 EXPECT_EQ(sDebugName, mLayerState->getName());
151}
152
153TEST_F(LayerStateTest, updateName) {
154 OutputLayerCompositionState outputLayerCompositionState;
155 LayerFECompositionState layerFECompositionState;
156 setupMocksForLayer(mOutputLayer, mLayerFE, outputLayerCompositionState,
157 layerFECompositionState);
158 mLayerState = std::make_unique<LayerState>(&mOutputLayer);
159
160 mock::OutputLayer newOutputLayer;
161 mock::LayerFE newLayerFE;
162 setupMocksForLayer(newOutputLayer, newLayerFE, outputLayerCompositionState,
163 layerFECompositionState, sSequenceId, sDebugNameTwo);
164 Flags<LayerStateField> updates = mLayerState->update(&newOutputLayer);
165 EXPECT_EQ(sDebugNameTwo, mLayerState->getName());
166 EXPECT_EQ(Flags<LayerStateField>(LayerStateField::Name), updates);
167}
168
169TEST_F(LayerStateTest, compareName) {
170 OutputLayerCompositionState outputLayerCompositionState;
171 LayerFECompositionState layerFECompositionState;
172 setupMocksForLayer(mOutputLayer, mLayerFE, outputLayerCompositionState,
173 layerFECompositionState);
174 mLayerState = std::make_unique<LayerState>(&mOutputLayer);
175 mock::OutputLayer newOutputLayer;
176 mock::LayerFE newLayerFE;
177 setupMocksForLayer(newOutputLayer, newLayerFE, outputLayerCompositionState,
178 layerFECompositionState, sSequenceId, sDebugNameTwo);
179 auto otherLayerState = std::make_unique<LayerState>(&newOutputLayer);
180
181 EXPECT_NE(mLayerState->getName(), otherLayerState->getName());
182
183 // Name is a unique field, so it's not computed in the hash for a layer state.
Alec Mouria19a8962021-03-30 14:19:31 -0700184 EXPECT_EQ(mLayerState->getHash(), otherLayerState->getHash());
Alec Mourieb920d92021-03-01 17:48:30 -0800185
186 // Similarly, Name cannot be included in differing fields.
187 EXPECT_EQ(Flags<LayerStateField>(LayerStateField::None),
Alec Mouria19a8962021-03-30 14:19:31 -0700188 mLayerState->getDifferingFields(*otherLayerState));
Alec Mourieb920d92021-03-01 17:48:30 -0800189 EXPECT_EQ(Flags<LayerStateField>(LayerStateField::None),
Alec Mouria19a8962021-03-30 14:19:31 -0700190 otherLayerState->getDifferingFields(*mLayerState));
Alec Mourieb920d92021-03-01 17:48:30 -0800191
192 EXPECT_FALSE(mLayerState->compare(*otherLayerState));
193 EXPECT_FALSE(otherLayerState->compare(*mLayerState));
194}
195
196TEST_F(LayerStateTest, getDisplayFrame) {
197 OutputLayerCompositionState outputLayerCompositionState;
198 outputLayerCompositionState.displayFrame = sRectOne;
199 LayerFECompositionState layerFECompositionState;
200 setupMocksForLayer(mOutputLayer, mLayerFE, outputLayerCompositionState,
201 layerFECompositionState);
202 mLayerState = std::make_unique<LayerState>(&mOutputLayer);
203 EXPECT_EQ(sRectOne, mLayerState->getDisplayFrame());
204}
205
206TEST_F(LayerStateTest, updateDisplayFrame) {
207 OutputLayerCompositionState outputLayerCompositionState;
208 outputLayerCompositionState.displayFrame = sRectOne;
209 LayerFECompositionState layerFECompositionState;
210 setupMocksForLayer(mOutputLayer, mLayerFE, outputLayerCompositionState,
211 layerFECompositionState);
212 mLayerState = std::make_unique<LayerState>(&mOutputLayer);
213
214 mock::OutputLayer newOutputLayer;
215 mock::LayerFE newLayerFE;
216 OutputLayerCompositionState outputLayerCompositionStateTwo;
217 outputLayerCompositionStateTwo.displayFrame = sRectTwo;
218 setupMocksForLayer(newOutputLayer, newLayerFE, outputLayerCompositionStateTwo,
219 layerFECompositionState);
220 Flags<LayerStateField> updates = mLayerState->update(&newOutputLayer);
221 EXPECT_EQ(sRectTwo, mLayerState->getDisplayFrame());
222 EXPECT_EQ(Flags<LayerStateField>(LayerStateField::DisplayFrame), updates);
223}
224
225TEST_F(LayerStateTest, compareDisplayFrame) {
226 OutputLayerCompositionState outputLayerCompositionState;
227 outputLayerCompositionState.displayFrame = sRectOne;
228 LayerFECompositionState layerFECompositionState;
229 setupMocksForLayer(mOutputLayer, mLayerFE, outputLayerCompositionState,
230 layerFECompositionState);
231 mLayerState = std::make_unique<LayerState>(&mOutputLayer);
232 mock::OutputLayer newOutputLayer;
233 mock::LayerFE newLayerFE;
234 OutputLayerCompositionState outputLayerCompositionStateTwo;
235 outputLayerCompositionStateTwo.displayFrame = sRectTwo;
236 setupMocksForLayer(newOutputLayer, newLayerFE, outputLayerCompositionStateTwo,
237 layerFECompositionState);
238 auto otherLayerState = std::make_unique<LayerState>(&newOutputLayer);
239
240 EXPECT_NE(mLayerState->getDisplayFrame(), otherLayerState->getDisplayFrame());
241
Alec Mouria19a8962021-03-30 14:19:31 -0700242 EXPECT_NE(mLayerState->getHash(), otherLayerState->getHash());
Alec Mourieb920d92021-03-01 17:48:30 -0800243
244 EXPECT_EQ(Flags<LayerStateField>(LayerStateField::DisplayFrame),
Alec Mouria19a8962021-03-30 14:19:31 -0700245 mLayerState->getDifferingFields(*otherLayerState));
Alec Mourieb920d92021-03-01 17:48:30 -0800246 EXPECT_EQ(Flags<LayerStateField>(LayerStateField::DisplayFrame),
Alec Mouria19a8962021-03-30 14:19:31 -0700247 otherLayerState->getDifferingFields(*mLayerState));
Alec Mourieb920d92021-03-01 17:48:30 -0800248
249 EXPECT_TRUE(mLayerState->compare(*otherLayerState));
250 EXPECT_TRUE(otherLayerState->compare(*mLayerState));
251}
252
253TEST_F(LayerStateTest, getCompositionType) {
254 OutputLayerCompositionState outputLayerCompositionState;
255 LayerFECompositionState layerFECompositionState;
256 layerFECompositionState.compositionType =
257 hardware::graphics::composer::hal::Composition::DEVICE;
258 setupMocksForLayer(mOutputLayer, mLayerFE, outputLayerCompositionState,
259 layerFECompositionState);
260 mLayerState = std::make_unique<LayerState>(&mOutputLayer);
261 EXPECT_EQ(hardware::graphics::composer::hal::Composition::DEVICE,
262 mLayerState->getCompositionType());
263}
264
265TEST_F(LayerStateTest, getCompositionType_forcedClient) {
266 OutputLayerCompositionState outputLayerCompositionState;
267 outputLayerCompositionState.forceClientComposition = true;
268 LayerFECompositionState layerFECompositionState;
269 layerFECompositionState.compositionType =
270 hardware::graphics::composer::hal::Composition::DEVICE;
271 setupMocksForLayer(mOutputLayer, mLayerFE, outputLayerCompositionState,
272 layerFECompositionState);
273 mLayerState = std::make_unique<LayerState>(&mOutputLayer);
274 EXPECT_EQ(hardware::graphics::composer::hal::Composition::CLIENT,
275 mLayerState->getCompositionType());
276}
277
278TEST_F(LayerStateTest, updateCompositionType) {
279 OutputLayerCompositionState outputLayerCompositionState;
280 LayerFECompositionState layerFECompositionState;
281 layerFECompositionState.compositionType =
282 hardware::graphics::composer::hal::Composition::DEVICE;
283 setupMocksForLayer(mOutputLayer, mLayerFE, outputLayerCompositionState,
284 layerFECompositionState);
285 mLayerState = std::make_unique<LayerState>(&mOutputLayer);
286
287 mock::OutputLayer newOutputLayer;
288 mock::LayerFE newLayerFE;
289 LayerFECompositionState layerFECompositionStateTwo;
290 layerFECompositionStateTwo.compositionType =
291 hardware::graphics::composer::hal::Composition::SOLID_COLOR;
292 setupMocksForLayer(newOutputLayer, newLayerFE, outputLayerCompositionState,
293 layerFECompositionStateTwo);
294 Flags<LayerStateField> updates = mLayerState->update(&newOutputLayer);
295 EXPECT_EQ(hardware::graphics::composer::hal::Composition::SOLID_COLOR,
296 mLayerState->getCompositionType());
297 EXPECT_EQ(Flags<LayerStateField>(LayerStateField::CompositionType), updates);
298}
299
300TEST_F(LayerStateTest, compareCompositionType) {
301 OutputLayerCompositionState outputLayerCompositionState;
302 LayerFECompositionState layerFECompositionState;
303 layerFECompositionState.compositionType =
304 hardware::graphics::composer::hal::Composition::DEVICE;
305 setupMocksForLayer(mOutputLayer, mLayerFE, outputLayerCompositionState,
306 layerFECompositionState);
307 mLayerState = std::make_unique<LayerState>(&mOutputLayer);
308 mock::OutputLayer newOutputLayer;
309 mock::LayerFE newLayerFE;
310 LayerFECompositionState layerFECompositionStateTwo;
311 layerFECompositionStateTwo.compositionType =
312 hardware::graphics::composer::hal::Composition::SOLID_COLOR;
313 setupMocksForLayer(newOutputLayer, newLayerFE, outputLayerCompositionState,
314 layerFECompositionStateTwo);
315 auto otherLayerState = std::make_unique<LayerState>(&newOutputLayer);
316
317 EXPECT_NE(mLayerState->getCompositionType(), otherLayerState->getCompositionType());
318
Alec Mouria19a8962021-03-30 14:19:31 -0700319 EXPECT_NE(mLayerState->getHash(), otherLayerState->getHash());
Alec Mourieb920d92021-03-01 17:48:30 -0800320
321 EXPECT_EQ(Flags<LayerStateField>(LayerStateField::CompositionType),
Alec Mouria19a8962021-03-30 14:19:31 -0700322 mLayerState->getDifferingFields(*otherLayerState));
Alec Mourieb920d92021-03-01 17:48:30 -0800323 EXPECT_EQ(Flags<LayerStateField>(LayerStateField::CompositionType),
Alec Mouria19a8962021-03-30 14:19:31 -0700324 otherLayerState->getDifferingFields(*mLayerState));
Alec Mourieb920d92021-03-01 17:48:30 -0800325
326 EXPECT_TRUE(mLayerState->compare(*otherLayerState));
327 EXPECT_TRUE(otherLayerState->compare(*mLayerState));
328}
329
Alec Mourieb920d92021-03-01 17:48:30 -0800330TEST_F(LayerStateTest, updateBuffer) {
331 OutputLayerCompositionState outputLayerCompositionState;
332 LayerFECompositionState layerFECompositionState;
333 layerFECompositionState.buffer = new GraphicBuffer();
334 setupMocksForLayer(mOutputLayer, mLayerFE, outputLayerCompositionState,
335 layerFECompositionState);
336 mLayerState = std::make_unique<LayerState>(&mOutputLayer);
337
338 mock::OutputLayer newOutputLayer;
339 mock::LayerFE newLayerFE;
340 LayerFECompositionState layerFECompositionStateTwo;
341 layerFECompositionStateTwo.buffer = new GraphicBuffer();
342 setupMocksForLayer(newOutputLayer, newLayerFE, outputLayerCompositionState,
343 layerFECompositionStateTwo);
344 Flags<LayerStateField> updates = mLayerState->update(&newOutputLayer);
Alec Mourieb920d92021-03-01 17:48:30 -0800345 EXPECT_EQ(Flags<LayerStateField>(LayerStateField::Buffer), updates);
346}
347
348TEST_F(LayerStateTest, compareBuffer) {
349 OutputLayerCompositionState outputLayerCompositionState;
350 LayerFECompositionState layerFECompositionState;
351 layerFECompositionState.buffer = new GraphicBuffer();
352 setupMocksForLayer(mOutputLayer, mLayerFE, outputLayerCompositionState,
353 layerFECompositionState);
354 mLayerState = std::make_unique<LayerState>(&mOutputLayer);
355 mock::OutputLayer newOutputLayer;
356 mock::LayerFE newLayerFE;
357 LayerFECompositionState layerFECompositionStateTwo;
358 layerFECompositionStateTwo.buffer = new GraphicBuffer();
359 setupMocksForLayer(newOutputLayer, newLayerFE, outputLayerCompositionState,
360 layerFECompositionStateTwo);
361 auto otherLayerState = std::make_unique<LayerState>(&newOutputLayer);
362
Alec Mouria19a8962021-03-30 14:19:31 -0700363 // Buffers are not included in differing fields or in hashes.
364 EXPECT_EQ(mLayerState->getHash(), otherLayerState->getHash());
Alec Mourieb920d92021-03-01 17:48:30 -0800365 EXPECT_EQ(Flags<LayerStateField>(LayerStateField::None),
Alec Mouria19a8962021-03-30 14:19:31 -0700366 mLayerState->getDifferingFields(*otherLayerState));
Alec Mourieb920d92021-03-01 17:48:30 -0800367 EXPECT_EQ(Flags<LayerStateField>(LayerStateField::None),
Alec Mouria19a8962021-03-30 14:19:31 -0700368 otherLayerState->getDifferingFields(*mLayerState));
Alec Mourieb920d92021-03-01 17:48:30 -0800369
370 // Buffers are explicitly excluded from comparison
371 EXPECT_FALSE(mLayerState->compare(*otherLayerState));
372 EXPECT_FALSE(otherLayerState->compare(*mLayerState));
373}
374
375TEST_F(LayerStateTest, updateSourceCrop) {
376 OutputLayerCompositionState outputLayerCompositionState;
377 outputLayerCompositionState.sourceCrop = sFloatRectOne;
378 LayerFECompositionState layerFECompositionState;
379 setupMocksForLayer(mOutputLayer, mLayerFE, outputLayerCompositionState,
380 layerFECompositionState);
381 mLayerState = std::make_unique<LayerState>(&mOutputLayer);
382
383 mock::OutputLayer newOutputLayer;
384 mock::LayerFE newLayerFE;
385 OutputLayerCompositionState outputLayerCompositionStateTwo;
386 outputLayerCompositionStateTwo.sourceCrop = sFloatRectTwo;
387 setupMocksForLayer(newOutputLayer, newLayerFE, outputLayerCompositionStateTwo,
388 layerFECompositionState);
389 Flags<LayerStateField> updates = mLayerState->update(&newOutputLayer);
390 EXPECT_EQ(Flags<LayerStateField>(LayerStateField::SourceCrop), updates);
391}
392
393TEST_F(LayerStateTest, compareSourceCrop) {
394 OutputLayerCompositionState outputLayerCompositionState;
395 outputLayerCompositionState.sourceCrop = sFloatRectOne;
396 LayerFECompositionState layerFECompositionState;
397 setupMocksForLayer(mOutputLayer, mLayerFE, outputLayerCompositionState,
398 layerFECompositionState);
399 mLayerState = std::make_unique<LayerState>(&mOutputLayer);
400 mock::OutputLayer newOutputLayer;
401 mock::LayerFE newLayerFE;
402 OutputLayerCompositionState outputLayerCompositionStateTwo;
403 outputLayerCompositionStateTwo.sourceCrop = sFloatRectTwo;
404 setupMocksForLayer(newOutputLayer, newLayerFE, outputLayerCompositionStateTwo,
405 layerFECompositionState);
406 auto otherLayerState = std::make_unique<LayerState>(&newOutputLayer);
407
Alec Mouria19a8962021-03-30 14:19:31 -0700408 EXPECT_NE(mLayerState->getHash(), otherLayerState->getHash());
Alec Mourieb920d92021-03-01 17:48:30 -0800409
410 EXPECT_EQ(Flags<LayerStateField>(LayerStateField::SourceCrop),
Alec Mouria19a8962021-03-30 14:19:31 -0700411 mLayerState->getDifferingFields(*otherLayerState));
Alec Mourieb920d92021-03-01 17:48:30 -0800412 EXPECT_EQ(Flags<LayerStateField>(LayerStateField::SourceCrop),
Alec Mouria19a8962021-03-30 14:19:31 -0700413 otherLayerState->getDifferingFields(*mLayerState));
Alec Mourieb920d92021-03-01 17:48:30 -0800414
415 EXPECT_TRUE(mLayerState->compare(*otherLayerState));
416 EXPECT_TRUE(otherLayerState->compare(*mLayerState));
417}
418
419TEST_F(LayerStateTest, updateZOrder) {
420 OutputLayerCompositionState outputLayerCompositionState;
421 outputLayerCompositionState.z = sZOne;
422 LayerFECompositionState layerFECompositionState;
423 setupMocksForLayer(mOutputLayer, mLayerFE, outputLayerCompositionState,
424 layerFECompositionState);
425 mLayerState = std::make_unique<LayerState>(&mOutputLayer);
426
427 mock::OutputLayer newOutputLayer;
428 mock::LayerFE newLayerFE;
429 OutputLayerCompositionState outputLayerCompositionStateTwo;
430 outputLayerCompositionStateTwo.z = sZTwo;
431 setupMocksForLayer(newOutputLayer, newLayerFE, outputLayerCompositionStateTwo,
432 layerFECompositionState);
433 Flags<LayerStateField> updates = mLayerState->update(&newOutputLayer);
434 EXPECT_EQ(Flags<LayerStateField>(LayerStateField::ZOrder), updates);
435}
436
437TEST_F(LayerStateTest, compareZOrder) {
438 OutputLayerCompositionState outputLayerCompositionState;
439 outputLayerCompositionState.z = sZOne;
440 LayerFECompositionState layerFECompositionState;
441 setupMocksForLayer(mOutputLayer, mLayerFE, outputLayerCompositionState,
442 layerFECompositionState);
443 mLayerState = std::make_unique<LayerState>(&mOutputLayer);
444 mock::OutputLayer newOutputLayer;
445 mock::LayerFE newLayerFE;
446 OutputLayerCompositionState outputLayerCompositionStateTwo;
447 outputLayerCompositionStateTwo.z = sZTwo;
448 setupMocksForLayer(newOutputLayer, newLayerFE, outputLayerCompositionStateTwo,
449 layerFECompositionState);
450 auto otherLayerState = std::make_unique<LayerState>(&newOutputLayer);
451
Alec Mouria19a8962021-03-30 14:19:31 -0700452 EXPECT_NE(mLayerState->getHash(), otherLayerState->getHash());
Alec Mourieb920d92021-03-01 17:48:30 -0800453
454 EXPECT_EQ(Flags<LayerStateField>(LayerStateField::ZOrder),
Alec Mouria19a8962021-03-30 14:19:31 -0700455 mLayerState->getDifferingFields(*otherLayerState));
Alec Mourieb920d92021-03-01 17:48:30 -0800456 EXPECT_EQ(Flags<LayerStateField>(LayerStateField::ZOrder),
Alec Mouria19a8962021-03-30 14:19:31 -0700457 otherLayerState->getDifferingFields(*mLayerState));
Alec Mourieb920d92021-03-01 17:48:30 -0800458
459 EXPECT_TRUE(mLayerState->compare(*otherLayerState));
460 EXPECT_TRUE(otherLayerState->compare(*mLayerState));
461}
462
463TEST_F(LayerStateTest, updateBufferTransform) {
464 OutputLayerCompositionState outputLayerCompositionState;
465 outputLayerCompositionState.bufferTransform = Hwc2::Transform::FLIP_H;
466 LayerFECompositionState layerFECompositionState;
467 setupMocksForLayer(mOutputLayer, mLayerFE, outputLayerCompositionState,
468 layerFECompositionState);
469 mLayerState = std::make_unique<LayerState>(&mOutputLayer);
470
471 mock::OutputLayer newOutputLayer;
472 mock::LayerFE newLayerFE;
473 OutputLayerCompositionState outputLayerCompositionStateTwo;
474 outputLayerCompositionStateTwo.bufferTransform = Hwc2::Transform::FLIP_V;
475 setupMocksForLayer(newOutputLayer, newLayerFE, outputLayerCompositionStateTwo,
476 layerFECompositionState);
477 Flags<LayerStateField> updates = mLayerState->update(&newOutputLayer);
478 EXPECT_EQ(Flags<LayerStateField>(LayerStateField::BufferTransform), updates);
479}
480
481TEST_F(LayerStateTest, compareBufferTransform) {
482 OutputLayerCompositionState outputLayerCompositionState;
483 outputLayerCompositionState.bufferTransform = Hwc2::Transform::FLIP_H;
484 LayerFECompositionState layerFECompositionState;
485 setupMocksForLayer(mOutputLayer, mLayerFE, outputLayerCompositionState,
486 layerFECompositionState);
487 mLayerState = std::make_unique<LayerState>(&mOutputLayer);
488 mock::OutputLayer newOutputLayer;
489 mock::LayerFE newLayerFE;
490 OutputLayerCompositionState outputLayerCompositionStateTwo;
491 outputLayerCompositionStateTwo.bufferTransform = Hwc2::Transform::FLIP_V;
492 setupMocksForLayer(newOutputLayer, newLayerFE, outputLayerCompositionStateTwo,
493 layerFECompositionState);
494 auto otherLayerState = std::make_unique<LayerState>(&newOutputLayer);
495
Alec Mouria19a8962021-03-30 14:19:31 -0700496 EXPECT_NE(mLayerState->getHash(), otherLayerState->getHash());
Alec Mourieb920d92021-03-01 17:48:30 -0800497
498 EXPECT_EQ(Flags<LayerStateField>(LayerStateField::BufferTransform),
Alec Mouria19a8962021-03-30 14:19:31 -0700499 mLayerState->getDifferingFields(*otherLayerState));
Alec Mourieb920d92021-03-01 17:48:30 -0800500 EXPECT_EQ(Flags<LayerStateField>(LayerStateField::BufferTransform),
Alec Mouria19a8962021-03-30 14:19:31 -0700501 otherLayerState->getDifferingFields(*mLayerState));
Alec Mourieb920d92021-03-01 17:48:30 -0800502
503 EXPECT_TRUE(mLayerState->compare(*otherLayerState));
504 EXPECT_TRUE(otherLayerState->compare(*mLayerState));
505}
506
507TEST_F(LayerStateTest, updateBlendMode) {
508 OutputLayerCompositionState outputLayerCompositionState;
509 LayerFECompositionState layerFECompositionState;
510 layerFECompositionState.blendMode = hal::BlendMode::COVERAGE;
511 setupMocksForLayer(mOutputLayer, mLayerFE, outputLayerCompositionState,
512 layerFECompositionState);
513 mLayerState = std::make_unique<LayerState>(&mOutputLayer);
514
515 mock::OutputLayer newOutputLayer;
516 mock::LayerFE newLayerFE;
517 LayerFECompositionState layerFECompositionStateTwo;
518 layerFECompositionStateTwo.blendMode = hal::BlendMode::PREMULTIPLIED;
519 setupMocksForLayer(newOutputLayer, newLayerFE, outputLayerCompositionState,
520 layerFECompositionStateTwo);
521 Flags<LayerStateField> updates = mLayerState->update(&newOutputLayer);
522 EXPECT_EQ(Flags<LayerStateField>(LayerStateField::BlendMode), updates);
523}
524
525TEST_F(LayerStateTest, compareBlendMode) {
526 OutputLayerCompositionState outputLayerCompositionState;
527 LayerFECompositionState layerFECompositionState;
528 layerFECompositionState.blendMode = hal::BlendMode::COVERAGE;
529 setupMocksForLayer(mOutputLayer, mLayerFE, outputLayerCompositionState,
530 layerFECompositionState);
531 mLayerState = std::make_unique<LayerState>(&mOutputLayer);
532 mock::OutputLayer newOutputLayer;
533 mock::LayerFE newLayerFE;
534 LayerFECompositionState layerFECompositionStateTwo;
535 layerFECompositionStateTwo.blendMode = hal::BlendMode::PREMULTIPLIED;
536 setupMocksForLayer(newOutputLayer, newLayerFE, outputLayerCompositionState,
537 layerFECompositionStateTwo);
538 auto otherLayerState = std::make_unique<LayerState>(&newOutputLayer);
539
Alec Mouria19a8962021-03-30 14:19:31 -0700540 EXPECT_NE(mLayerState->getHash(), otherLayerState->getHash());
Alec Mourieb920d92021-03-01 17:48:30 -0800541
542 EXPECT_EQ(Flags<LayerStateField>(LayerStateField::BlendMode),
Alec Mouria19a8962021-03-30 14:19:31 -0700543 mLayerState->getDifferingFields(*otherLayerState));
Alec Mourieb920d92021-03-01 17:48:30 -0800544 EXPECT_EQ(Flags<LayerStateField>(LayerStateField::BlendMode),
Alec Mouria19a8962021-03-30 14:19:31 -0700545 otherLayerState->getDifferingFields(*mLayerState));
Alec Mourieb920d92021-03-01 17:48:30 -0800546
547 EXPECT_TRUE(mLayerState->compare(*otherLayerState));
548 EXPECT_TRUE(otherLayerState->compare(*mLayerState));
549}
550
551TEST_F(LayerStateTest, updateAlpha) {
552 OutputLayerCompositionState outputLayerCompositionState;
553 LayerFECompositionState layerFECompositionState;
554 layerFECompositionState.alpha = sAlphaOne;
555 setupMocksForLayer(mOutputLayer, mLayerFE, outputLayerCompositionState,
556 layerFECompositionState);
557 mLayerState = std::make_unique<LayerState>(&mOutputLayer);
558
559 mock::OutputLayer newOutputLayer;
560 mock::LayerFE newLayerFE;
561 LayerFECompositionState layerFECompositionStateTwo;
562 layerFECompositionStateTwo.alpha = sAlphaTwo;
563 setupMocksForLayer(newOutputLayer, newLayerFE, outputLayerCompositionState,
564 layerFECompositionStateTwo);
565 Flags<LayerStateField> updates = mLayerState->update(&newOutputLayer);
566 EXPECT_EQ(Flags<LayerStateField>(LayerStateField::Alpha), updates);
567}
568
569TEST_F(LayerStateTest, compareAlpha) {
570 OutputLayerCompositionState outputLayerCompositionState;
571 LayerFECompositionState layerFECompositionState;
572 layerFECompositionState.alpha = sAlphaOne;
573 setupMocksForLayer(mOutputLayer, mLayerFE, outputLayerCompositionState,
574 layerFECompositionState);
575 mLayerState = std::make_unique<LayerState>(&mOutputLayer);
576 mock::OutputLayer newOutputLayer;
577 mock::LayerFE newLayerFE;
578 LayerFECompositionState layerFECompositionStateTwo;
579 layerFECompositionStateTwo.alpha = sAlphaTwo;
580 setupMocksForLayer(newOutputLayer, newLayerFE, outputLayerCompositionState,
581 layerFECompositionStateTwo);
582 auto otherLayerState = std::make_unique<LayerState>(&newOutputLayer);
583
Alec Mouria19a8962021-03-30 14:19:31 -0700584 EXPECT_NE(mLayerState->getHash(), otherLayerState->getHash());
Alec Mourieb920d92021-03-01 17:48:30 -0800585
586 EXPECT_EQ(Flags<LayerStateField>(LayerStateField::Alpha),
Alec Mouria19a8962021-03-30 14:19:31 -0700587 mLayerState->getDifferingFields(*otherLayerState));
Alec Mourieb920d92021-03-01 17:48:30 -0800588 EXPECT_EQ(Flags<LayerStateField>(LayerStateField::Alpha),
Alec Mouria19a8962021-03-30 14:19:31 -0700589 otherLayerState->getDifferingFields(*mLayerState));
Alec Mourieb920d92021-03-01 17:48:30 -0800590
591 EXPECT_TRUE(mLayerState->compare(*otherLayerState));
592 EXPECT_TRUE(otherLayerState->compare(*mLayerState));
593}
594
Alec Mouri464352b2021-03-24 16:33:21 -0700595TEST_F(LayerStateTest, getVisibleRegion) {
596 OutputLayerCompositionState outputLayerCompositionState;
597 outputLayerCompositionState.visibleRegion = sRegionOne;
598 LayerFECompositionState layerFECompositionState;
599 setupMocksForLayer(mOutputLayer, mLayerFE, outputLayerCompositionState,
600 layerFECompositionState);
601 mLayerState = std::make_unique<LayerState>(&mOutputLayer);
602 EXPECT_TRUE(mLayerState->getVisibleRegion().hasSameRects(sRegionOne));
603}
604
Alec Mourieb920d92021-03-01 17:48:30 -0800605TEST_F(LayerStateTest, updateVisibleRegion) {
606 OutputLayerCompositionState outputLayerCompositionState;
607 outputLayerCompositionState.visibleRegion = sRegionOne;
608 LayerFECompositionState layerFECompositionState;
609 setupMocksForLayer(mOutputLayer, mLayerFE, outputLayerCompositionState,
610 layerFECompositionState);
611 mLayerState = std::make_unique<LayerState>(&mOutputLayer);
612
613 mock::OutputLayer newOutputLayer;
614 mock::LayerFE newLayerFE;
615 OutputLayerCompositionState outputLayerCompositionStateTwo;
616 outputLayerCompositionStateTwo.visibleRegion = sRegionTwo;
617 setupMocksForLayer(newOutputLayer, newLayerFE, outputLayerCompositionStateTwo,
618 layerFECompositionState);
619 Flags<LayerStateField> updates = mLayerState->update(&newOutputLayer);
620 EXPECT_EQ(Flags<LayerStateField>(LayerStateField::VisibleRegion), updates);
621}
622
623TEST_F(LayerStateTest, compareVisibleRegion) {
624 OutputLayerCompositionState outputLayerCompositionState;
625 outputLayerCompositionState.visibleRegion = sRegionOne;
626 LayerFECompositionState layerFECompositionState;
627 setupMocksForLayer(mOutputLayer, mLayerFE, outputLayerCompositionState,
628 layerFECompositionState);
629 mLayerState = std::make_unique<LayerState>(&mOutputLayer);
630 mock::OutputLayer newOutputLayer;
631 mock::LayerFE newLayerFE;
632 OutputLayerCompositionState outputLayerCompositionStateTwo;
633 outputLayerCompositionStateTwo.visibleRegion = sRegionTwo;
634 setupMocksForLayer(newOutputLayer, newLayerFE, outputLayerCompositionStateTwo,
635 layerFECompositionState);
636 auto otherLayerState = std::make_unique<LayerState>(&newOutputLayer);
637
Alec Mouria19a8962021-03-30 14:19:31 -0700638 EXPECT_NE(mLayerState->getHash(), otherLayerState->getHash());
Alec Mourieb920d92021-03-01 17:48:30 -0800639
640 EXPECT_EQ(Flags<LayerStateField>(LayerStateField::VisibleRegion),
Alec Mouria19a8962021-03-30 14:19:31 -0700641 mLayerState->getDifferingFields(*otherLayerState));
Alec Mourieb920d92021-03-01 17:48:30 -0800642 EXPECT_EQ(Flags<LayerStateField>(LayerStateField::VisibleRegion),
Alec Mouria19a8962021-03-30 14:19:31 -0700643 otherLayerState->getDifferingFields(*mLayerState));
Alec Mourieb920d92021-03-01 17:48:30 -0800644
645 EXPECT_TRUE(mLayerState->compare(*otherLayerState));
646 EXPECT_TRUE(otherLayerState->compare(*mLayerState));
647}
648
649TEST_F(LayerStateTest, updateDataspace) {
650 OutputLayerCompositionState outputLayerCompositionState;
651 outputLayerCompositionState.dataspace = ui::Dataspace::SRGB;
652 LayerFECompositionState layerFECompositionState;
653 setupMocksForLayer(mOutputLayer, mLayerFE, outputLayerCompositionState,
654 layerFECompositionState);
655 mLayerState = std::make_unique<LayerState>(&mOutputLayer);
656
657 mock::OutputLayer newOutputLayer;
658 mock::LayerFE newLayerFE;
659 OutputLayerCompositionState outputLayerCompositionStateTwo;
660 outputLayerCompositionStateTwo.dataspace = ui::Dataspace::DISPLAY_P3;
661 setupMocksForLayer(newOutputLayer, newLayerFE, outputLayerCompositionStateTwo,
662 layerFECompositionState);
663 Flags<LayerStateField> updates = mLayerState->update(&newOutputLayer);
664 EXPECT_EQ(Flags<LayerStateField>(LayerStateField::Dataspace), updates);
665}
666
667TEST_F(LayerStateTest, compareDataspace) {
668 OutputLayerCompositionState outputLayerCompositionState;
669 outputLayerCompositionState.dataspace = ui::Dataspace::SRGB;
670 LayerFECompositionState layerFECompositionState;
671 setupMocksForLayer(mOutputLayer, mLayerFE, outputLayerCompositionState,
672 layerFECompositionState);
673 mLayerState = std::make_unique<LayerState>(&mOutputLayer);
674 mock::OutputLayer newOutputLayer;
675 mock::LayerFE newLayerFE;
676 OutputLayerCompositionState outputLayerCompositionStateTwo;
677 outputLayerCompositionStateTwo.dataspace = ui::Dataspace::DISPLAY_P3;
678 setupMocksForLayer(newOutputLayer, newLayerFE, outputLayerCompositionStateTwo,
679 layerFECompositionState);
680 auto otherLayerState = std::make_unique<LayerState>(&newOutputLayer);
681
Alec Mouria19a8962021-03-30 14:19:31 -0700682 EXPECT_NE(mLayerState->getHash(), otherLayerState->getHash());
Alec Mourieb920d92021-03-01 17:48:30 -0800683
684 EXPECT_EQ(Flags<LayerStateField>(LayerStateField::Dataspace),
Alec Mouria19a8962021-03-30 14:19:31 -0700685 mLayerState->getDifferingFields(*otherLayerState));
Alec Mourieb920d92021-03-01 17:48:30 -0800686 EXPECT_EQ(Flags<LayerStateField>(LayerStateField::Dataspace),
Alec Mouria19a8962021-03-30 14:19:31 -0700687 otherLayerState->getDifferingFields(*mLayerState));
Alec Mourieb920d92021-03-01 17:48:30 -0800688
689 EXPECT_TRUE(mLayerState->compare(*otherLayerState));
690 EXPECT_TRUE(otherLayerState->compare(*mLayerState));
691}
692
693TEST_F(LayerStateTest, updateColorTransform) {
694 OutputLayerCompositionState outputLayerCompositionState;
695 LayerFECompositionState layerFECompositionState;
696 layerFECompositionState.colorTransformIsIdentity = true;
697 layerFECompositionState.colorTransform = mat4();
698 setupMocksForLayer(mOutputLayer, mLayerFE, outputLayerCompositionState,
699 layerFECompositionState);
700 mLayerState = std::make_unique<LayerState>(&mOutputLayer);
701
702 mock::OutputLayer newOutputLayer;
703 mock::LayerFE newLayerFE;
704 LayerFECompositionState layerFECompositionStateTwo;
705 layerFECompositionStateTwo.colorTransformIsIdentity = false;
706 layerFECompositionStateTwo.colorTransform = sMat4One;
707 setupMocksForLayer(newOutputLayer, newLayerFE, outputLayerCompositionState,
708 layerFECompositionStateTwo);
709 Flags<LayerStateField> updates = mLayerState->update(&newOutputLayer);
710 EXPECT_EQ(Flags<LayerStateField>(LayerStateField::ColorTransform), updates);
711}
712
713TEST_F(LayerStateTest, compareColorTransform) {
714 OutputLayerCompositionState outputLayerCompositionState;
715 LayerFECompositionState layerFECompositionState;
716 layerFECompositionState.colorTransformIsIdentity = true;
717 layerFECompositionState.colorTransform = mat4();
718 setupMocksForLayer(mOutputLayer, mLayerFE, outputLayerCompositionState,
719 layerFECompositionState);
720 mLayerState = std::make_unique<LayerState>(&mOutputLayer);
721 mock::OutputLayer newOutputLayer;
722 mock::LayerFE newLayerFE;
723 LayerFECompositionState layerFECompositionStateTwo;
724 layerFECompositionStateTwo.colorTransformIsIdentity = false;
725 layerFECompositionStateTwo.colorTransform = sMat4One;
726 setupMocksForLayer(newOutputLayer, newLayerFE, outputLayerCompositionState,
727 layerFECompositionStateTwo);
728 auto otherLayerState = std::make_unique<LayerState>(&newOutputLayer);
729
Alec Mouria19a8962021-03-30 14:19:31 -0700730 EXPECT_NE(mLayerState->getHash(), otherLayerState->getHash());
Alec Mourieb920d92021-03-01 17:48:30 -0800731
732 EXPECT_EQ(Flags<LayerStateField>(LayerStateField::ColorTransform),
Alec Mouria19a8962021-03-30 14:19:31 -0700733 mLayerState->getDifferingFields(*otherLayerState));
Alec Mourieb920d92021-03-01 17:48:30 -0800734 EXPECT_EQ(Flags<LayerStateField>(LayerStateField::ColorTransform),
Alec Mouria19a8962021-03-30 14:19:31 -0700735 otherLayerState->getDifferingFields(*mLayerState));
Alec Mourieb920d92021-03-01 17:48:30 -0800736
737 EXPECT_TRUE(mLayerState->compare(*otherLayerState));
738 EXPECT_TRUE(otherLayerState->compare(*mLayerState));
739}
740
741TEST_F(LayerStateTest, updateSidebandStream) {
742 OutputLayerCompositionState outputLayerCompositionState;
743 LayerFECompositionState layerFECompositionState;
744 layerFECompositionState.sidebandStream = NativeHandle::create(sFakeSidebandStreamOne, false);
745 setupMocksForLayer(mOutputLayer, mLayerFE, outputLayerCompositionState,
746 layerFECompositionState);
747 mLayerState = std::make_unique<LayerState>(&mOutputLayer);
748
749 mock::OutputLayer newOutputLayer;
750 mock::LayerFE newLayerFE;
751 LayerFECompositionState layerFECompositionStateTwo;
752 layerFECompositionStateTwo.sidebandStream = NativeHandle::create(sFakeSidebandStreamTwo, false);
753 setupMocksForLayer(newOutputLayer, newLayerFE, outputLayerCompositionState,
754 layerFECompositionStateTwo);
755 Flags<LayerStateField> updates = mLayerState->update(&newOutputLayer);
756 EXPECT_EQ(Flags<LayerStateField>(LayerStateField::SidebandStream), updates);
757}
758
759TEST_F(LayerStateTest, compareSidebandStream) {
760 OutputLayerCompositionState outputLayerCompositionState;
761 LayerFECompositionState layerFECompositionState;
762 layerFECompositionState.sidebandStream = NativeHandle::create(sFakeSidebandStreamOne, false);
763 setupMocksForLayer(mOutputLayer, mLayerFE, outputLayerCompositionState,
764 layerFECompositionState);
765 mLayerState = std::make_unique<LayerState>(&mOutputLayer);
766 mock::OutputLayer newOutputLayer;
767 mock::LayerFE newLayerFE;
768 LayerFECompositionState layerFECompositionStateTwo;
769 layerFECompositionStateTwo.sidebandStream = NativeHandle::create(sFakeSidebandStreamTwo, false);
770 setupMocksForLayer(newOutputLayer, newLayerFE, outputLayerCompositionState,
771 layerFECompositionStateTwo);
772 auto otherLayerState = std::make_unique<LayerState>(&newOutputLayer);
773
Alec Mouria19a8962021-03-30 14:19:31 -0700774 EXPECT_NE(mLayerState->getHash(), otherLayerState->getHash());
Alec Mourieb920d92021-03-01 17:48:30 -0800775
776 EXPECT_EQ(Flags<LayerStateField>(LayerStateField::SidebandStream),
Alec Mouria19a8962021-03-30 14:19:31 -0700777 mLayerState->getDifferingFields(*otherLayerState));
Alec Mourieb920d92021-03-01 17:48:30 -0800778 EXPECT_EQ(Flags<LayerStateField>(LayerStateField::SidebandStream),
Alec Mouria19a8962021-03-30 14:19:31 -0700779 otherLayerState->getDifferingFields(*mLayerState));
Alec Mourieb920d92021-03-01 17:48:30 -0800780
781 EXPECT_TRUE(mLayerState->compare(*otherLayerState));
782 EXPECT_TRUE(otherLayerState->compare(*mLayerState));
783}
784
785TEST_F(LayerStateTest, updateSolidColor) {
786 OutputLayerCompositionState outputLayerCompositionState;
787 LayerFECompositionState layerFECompositionState;
788 layerFECompositionState.color = sHalf4One;
789 setupMocksForLayer(mOutputLayer, mLayerFE, outputLayerCompositionState,
790 layerFECompositionState);
791 mLayerState = std::make_unique<LayerState>(&mOutputLayer);
792
793 mock::OutputLayer newOutputLayer;
794 mock::LayerFE newLayerFE;
795 LayerFECompositionState layerFECompositionStateTwo;
796 layerFECompositionStateTwo.color = sHalf4Two;
797 setupMocksForLayer(newOutputLayer, newLayerFE, outputLayerCompositionState,
798 layerFECompositionStateTwo);
799 Flags<LayerStateField> updates = mLayerState->update(&newOutputLayer);
800 EXPECT_EQ(Flags<LayerStateField>(LayerStateField::SolidColor), updates);
801}
802
803TEST_F(LayerStateTest, compareSolidColor) {
804 OutputLayerCompositionState outputLayerCompositionState;
805 LayerFECompositionState layerFECompositionState;
806 layerFECompositionState.color = sHalf4One;
807 setupMocksForLayer(mOutputLayer, mLayerFE, outputLayerCompositionState,
808 layerFECompositionState);
809 mLayerState = std::make_unique<LayerState>(&mOutputLayer);
810 mock::OutputLayer newOutputLayer;
811 mock::LayerFE newLayerFE;
812 LayerFECompositionState layerFECompositionStateTwo;
813 layerFECompositionStateTwo.color = sHalf4Two;
814 setupMocksForLayer(newOutputLayer, newLayerFE, outputLayerCompositionState,
815 layerFECompositionStateTwo);
816 auto otherLayerState = std::make_unique<LayerState>(&newOutputLayer);
817
Alec Mouria19a8962021-03-30 14:19:31 -0700818 EXPECT_NE(mLayerState->getHash(), otherLayerState->getHash());
Alec Mourieb920d92021-03-01 17:48:30 -0800819
820 EXPECT_EQ(Flags<LayerStateField>(LayerStateField::SolidColor),
Alec Mouria19a8962021-03-30 14:19:31 -0700821 mLayerState->getDifferingFields(*otherLayerState));
Alec Mourieb920d92021-03-01 17:48:30 -0800822 EXPECT_EQ(Flags<LayerStateField>(LayerStateField::SolidColor),
Alec Mouria19a8962021-03-30 14:19:31 -0700823 otherLayerState->getDifferingFields(*mLayerState));
Alec Mourieb920d92021-03-01 17:48:30 -0800824
825 EXPECT_TRUE(mLayerState->compare(*otherLayerState));
826 EXPECT_TRUE(otherLayerState->compare(*mLayerState));
827}
828
829TEST_F(LayerStateTest, dumpDoesNotCrash) {
830 OutputLayerCompositionState outputLayerCompositionState;
831 LayerFECompositionState layerFECompositionState;
832 setupMocksForLayer(mOutputLayer, mLayerFE, outputLayerCompositionState,
833 layerFECompositionState);
834 mLayerState = std::make_unique<LayerState>(&mOutputLayer);
835 std::string dump;
836 mLayerState->dump(dump);
837 EXPECT_TRUE(dump.size() > 0);
838}
839
840TEST_F(LayerStateTest, framesSinceBufferUpdate) {
841 OutputLayerCompositionState outputLayerCompositionState;
842 LayerFECompositionState layerFECompositionState;
843 setupMocksForLayer(mOutputLayer, mLayerFE, outputLayerCompositionState,
844 layerFECompositionState);
845 mLayerState = std::make_unique<LayerState>(&mOutputLayer);
846
847 EXPECT_EQ(0, mLayerState->getFramesSinceBufferUpdate());
848 mLayerState->incrementFramesSinceBufferUpdate();
849 EXPECT_EQ(1, mLayerState->getFramesSinceBufferUpdate());
850 mLayerState->resetFramesSinceBufferUpdate();
851 EXPECT_EQ(0, mLayerState->getFramesSinceBufferUpdate());
852}
853
854TEST_F(LayerStateTest, getNonBufferHash_doesNotCommute) {
855 OutputLayerCompositionState outputLayerCompositionState;
856 outputLayerCompositionState.displayFrame = sRectOne;
857 LayerFECompositionState layerFECompositionState;
858 setupMocksForLayer(mOutputLayer, mLayerFE, outputLayerCompositionState,
859 layerFECompositionState);
860 mLayerState = std::make_unique<LayerState>(&mOutputLayer);
861 mock::OutputLayer newOutputLayer;
862 mock::LayerFE newLayerFE;
863 OutputLayerCompositionState outputLayerCompositionStateTwo;
864 outputLayerCompositionStateTwo.displayFrame = sRectTwo;
865 setupMocksForLayer(newOutputLayer, newLayerFE, outputLayerCompositionStateTwo,
866 layerFECompositionState);
867 auto otherLayerState = std::make_unique<LayerState>(&newOutputLayer);
868
869 EXPECT_NE(getNonBufferHash({mLayerState.get(), otherLayerState.get()}),
870 getNonBufferHash({otherLayerState.get(), mLayerState.get()}));
871}
872
873TEST_F(LayerStateTest, getNonBufferHash_isIdempotent) {
874 OutputLayerCompositionState outputLayerCompositionState;
875 outputLayerCompositionState.displayFrame = sRectOne;
876 LayerFECompositionState layerFECompositionState;
877 setupMocksForLayer(mOutputLayer, mLayerFE, outputLayerCompositionState,
878 layerFECompositionState);
879 mLayerState = std::make_unique<LayerState>(&mOutputLayer);
880 mock::OutputLayer newOutputLayer;
881 mock::LayerFE newLayerFE;
882 OutputLayerCompositionState outputLayerCompositionStateTwo;
883 outputLayerCompositionStateTwo.displayFrame = sRectTwo;
884 setupMocksForLayer(newOutputLayer, newLayerFE, outputLayerCompositionStateTwo,
885 layerFECompositionState);
886 auto otherLayerState = std::make_unique<LayerState>(&newOutputLayer);
887
888 EXPECT_EQ(getNonBufferHash({mLayerState.get(), otherLayerState.get()}),
889 getNonBufferHash({mLayerState.get(), otherLayerState.get()}));
890}
891
892TEST_F(LayerStateTest, getNonBufferHash_filtersOutBuffers) {
893 OutputLayerCompositionState outputLayerCompositionState;
894 LayerFECompositionState layerFECompositionState;
895 layerFECompositionState.buffer = new GraphicBuffer();
896 setupMocksForLayer(mOutputLayer, mLayerFE, outputLayerCompositionState,
897 layerFECompositionState);
898 mLayerState = std::make_unique<LayerState>(&mOutputLayer);
899
900 mock::OutputLayer newOutputLayer;
901 mock::LayerFE newLayerFE;
902 LayerFECompositionState layerFECompositionStateTwo;
903 layerFECompositionStateTwo.buffer = new GraphicBuffer();
904 setupMocksForLayer(newOutputLayer, newLayerFE, outputLayerCompositionState,
905 layerFECompositionStateTwo);
906 auto otherLayerState = std::make_unique<LayerState>(&newOutputLayer);
907
908 EXPECT_EQ(getNonBufferHash({mLayerState.get()}), getNonBufferHash({otherLayerState.get()}));
909}
910
911} // namespace
912} // namespace android::compositionengine::impl::planner