1 /*
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
27 #include "android/hardware_buffer.h"
28 #include "compositionengine/LayerFECompositionState.h"
29
30 namespace android::compositionengine::impl::planner {
31 namespace {
32
33 using testing::Return;
34 using testing::ReturnRef;
35
36 const std::string sDebugName = std::string("Test LayerFE");
37 const std::string sDebugNameTwo = std::string("Test LayerFE2");
38 const constexpr int32_t sSequenceId = 12345;
39 const constexpr int32_t sSequenceIdTwo = 123456;
40 const Rect sRectOne = Rect(10, 20, 30, 40);
41 const Rect sRectTwo = Rect(40, 30, 20, 10);
42 const FloatRect sFloatRectOne = FloatRect(100.f, 200.f, 300.f, 400.f);
43 const FloatRect sFloatRectTwo = FloatRect(400.f, 300.f, 200.f, 100.f);
44 const constexpr float sAlphaOne = 0.25f;
45 const constexpr float sAlphaTwo = 0.5f;
46 const Region sRegionOne = Region(sRectOne);
47 const Region sRegionTwo = Region(sRectTwo);
48 const mat4 sMat4One = mat4::scale(vec4(2.f, 3.f, 1.f, 1.f));
49 native_handle_t* const sFakeSidebandStreamOne = reinterpret_cast<native_handle_t*>(10);
50 native_handle_t* const sFakeSidebandStreamTwo = reinterpret_cast<native_handle_t*>(11);
51 const half4 sHalf4One = half4(0.2f, 0.3f, 0.4f, 0.5f);
52 const half4 sHalf4Two = half4(0.5f, 0.4f, 0.3f, 0.2f);
53 const std::string sMetadataKeyOne = std::string("Meta!");
54 const std::string sMetadataKeyTwo = std::string("Data!");
55 const GenericLayerMetadataEntry sMetadataValueOne = GenericLayerMetadataEntry{
56 .value = std::vector<uint8_t>({1, 2}),
57 };
58 const GenericLayerMetadataEntry sMetadataValueTwo = GenericLayerMetadataEntry{
59 .value = std::vector<uint8_t>({1, 3}),
60 };
61 const constexpr int32_t sBgBlurRadiusOne = 3;
62 const constexpr int32_t sBgBlurRadiusTwo = 4;
63 const BlurRegion sBlurRegionOne = BlurRegion{1, 2.f, 3.f, 4.f, 5.f, 6.f, 7, 8, 9, 10};
64 const BlurRegion sBlurRegionTwo = BlurRegion{2, 3.f, 4.f, 5.f, 6.f, 7.f, 8, 9, 10, 11};
65
66 struct LayerStateTest : public testing::Test {
LayerStateTestandroid::compositionengine::impl::planner::__anon36dd0cc70111::LayerStateTest67 LayerStateTest() {
68 const ::testing::TestInfo* const test_info =
69 ::testing::UnitTest::GetInstance()->current_test_info();
70 ALOGD("**** Setting up for %s.%s\n", test_info->test_case_name(), test_info->name());
71 }
72
~LayerStateTestandroid::compositionengine::impl::planner::__anon36dd0cc70111::LayerStateTest73 ~LayerStateTest() {
74 const ::testing::TestInfo* const test_info =
75 ::testing::UnitTest::GetInstance()->current_test_info();
76 ALOGD("**** Tearing down after %s.%s\n", test_info->test_case_name(), test_info->name());
77 }
78
setupMocksForLayerandroid::compositionengine::impl::planner::__anon36dd0cc70111::LayerStateTest79 void setupMocksForLayer(mock::OutputLayer& layer, mock::LayerFE& layerFE,
80 const OutputLayerCompositionState& outputLayerState,
81 const LayerFECompositionState& layerFEState,
82 int32_t sequenceId = sSequenceId,
83 const std::string& debugName = sDebugName) {
84 EXPECT_CALL(layer, getLayerFE()).WillRepeatedly(ReturnRef(layerFE));
85 EXPECT_CALL(layer, getState()).WillRepeatedly(ReturnRef(outputLayerState));
86 EXPECT_CALL(layerFE, getSequence()).WillRepeatedly(Return(sequenceId));
87 EXPECT_CALL(layerFE, getDebugName()).WillRepeatedly(Return(debugName.c_str()));
88 EXPECT_CALL(layerFE, getCompositionState()).WillRepeatedly(Return(&layerFEState));
89 }
90
verifyUniqueDifferingFieldsandroid::compositionengine::impl::planner::__anon36dd0cc70111::LayerStateTest91 void verifyUniqueDifferingFields(const LayerState& lhs, const LayerState& rhs) {
92 EXPECT_EQ(lhs.getHash(), rhs.getHash());
93
94 EXPECT_EQ(Flags<LayerStateField>(LayerStateField::None), lhs.getDifferingFields(rhs));
95 EXPECT_EQ(Flags<LayerStateField>(LayerStateField::None), rhs.getDifferingFields(lhs));
96 }
97
verifyNonUniqueDifferingFieldsandroid::compositionengine::impl::planner::__anon36dd0cc70111::LayerStateTest98 void verifyNonUniqueDifferingFields(const LayerState& lhs, const LayerState& rhs,
99 Flags<LayerStateField> fields) {
100 EXPECT_NE(lhs.getHash(), rhs.getHash());
101
102 EXPECT_EQ(fields, lhs.getDifferingFields(rhs));
103 EXPECT_EQ(fields, rhs.getDifferingFields(lhs));
104 }
105
106 mock::LayerFE mLayerFE;
107 mock::OutputLayer mOutputLayer;
108 std::unique_ptr<LayerState> mLayerState;
109 };
110
TEST_F(LayerStateTest,getOutputLayer)111 TEST_F(LayerStateTest, getOutputLayer) {
112 OutputLayerCompositionState outputLayerCompositionState;
113 LayerFECompositionState layerFECompositionState;
114 setupMocksForLayer(mOutputLayer, mLayerFE, outputLayerCompositionState,
115 layerFECompositionState);
116 mLayerState = std::make_unique<LayerState>(&mOutputLayer);
117 EXPECT_EQ(&mOutputLayer, mLayerState->getOutputLayer());
118 }
119
TEST_F(LayerStateTest,updateOutputLayer)120 TEST_F(LayerStateTest, updateOutputLayer) {
121 OutputLayerCompositionState outputLayerCompositionState;
122 LayerFECompositionState layerFECompositionState;
123 setupMocksForLayer(mOutputLayer, mLayerFE, outputLayerCompositionState,
124 layerFECompositionState);
125 mLayerState = std::make_unique<LayerState>(&mOutputLayer);
126 EXPECT_EQ(&mOutputLayer, mLayerState->getOutputLayer());
127
128 mock::OutputLayer newOutputLayer;
129 mock::LayerFE newLayerFE;
130 setupMocksForLayer(newOutputLayer, newLayerFE, outputLayerCompositionState,
131 layerFECompositionState);
132 mLayerState->update(&newOutputLayer);
133 EXPECT_EQ(&newOutputLayer, mLayerState->getOutputLayer());
134 }
135
TEST_F(LayerStateTest,getId)136 TEST_F(LayerStateTest, getId) {
137 OutputLayerCompositionState outputLayerCompositionState;
138 LayerFECompositionState layerFECompositionState;
139 setupMocksForLayer(mOutputLayer, mLayerFE, outputLayerCompositionState,
140 layerFECompositionState);
141 mLayerState = std::make_unique<LayerState>(&mOutputLayer);
142 EXPECT_EQ(sSequenceId, mLayerState->getId());
143 }
144
TEST_F(LayerStateTest,updateId)145 TEST_F(LayerStateTest, updateId) {
146 OutputLayerCompositionState outputLayerCompositionState;
147 LayerFECompositionState layerFECompositionState;
148 setupMocksForLayer(mOutputLayer, mLayerFE, outputLayerCompositionState,
149 layerFECompositionState);
150 mLayerState = std::make_unique<LayerState>(&mOutputLayer);
151
152 mock::OutputLayer newOutputLayer;
153 mock::LayerFE newLayerFE;
154 setupMocksForLayer(newOutputLayer, newLayerFE, outputLayerCompositionState,
155 layerFECompositionState, sSequenceIdTwo);
156 Flags<LayerStateField> updates = mLayerState->update(&newOutputLayer);
157 EXPECT_EQ(sSequenceIdTwo, mLayerState->getId());
158 EXPECT_EQ(Flags<LayerStateField>(LayerStateField::Id), updates);
159 }
160
TEST_F(LayerStateTest,compareId)161 TEST_F(LayerStateTest, compareId) {
162 OutputLayerCompositionState outputLayerCompositionState;
163 LayerFECompositionState layerFECompositionState;
164 setupMocksForLayer(mOutputLayer, mLayerFE, outputLayerCompositionState,
165 layerFECompositionState);
166 mLayerState = std::make_unique<LayerState>(&mOutputLayer);
167 mock::OutputLayer newOutputLayer;
168 mock::LayerFE newLayerFE;
169 setupMocksForLayer(newOutputLayer, newLayerFE, outputLayerCompositionState,
170 layerFECompositionState, sSequenceIdTwo);
171 auto otherLayerState = std::make_unique<LayerState>(&newOutputLayer);
172
173 EXPECT_NE(mLayerState->getId(), otherLayerState->getId());
174
175 // Id is a unique field, so it's not computed in the hash for a layer state.
176 verifyUniqueDifferingFields(*mLayerState, *otherLayerState);
177 EXPECT_FALSE(mLayerState->compare(*otherLayerState));
178 EXPECT_FALSE(otherLayerState->compare(*mLayerState));
179 }
180
TEST_F(LayerStateTest,getName)181 TEST_F(LayerStateTest, getName) {
182 OutputLayerCompositionState outputLayerCompositionState;
183 LayerFECompositionState layerFECompositionState;
184 setupMocksForLayer(mOutputLayer, mLayerFE, outputLayerCompositionState,
185 layerFECompositionState);
186 mLayerState = std::make_unique<LayerState>(&mOutputLayer);
187 EXPECT_EQ(sDebugName, mLayerState->getName());
188 }
189
TEST_F(LayerStateTest,updateName)190 TEST_F(LayerStateTest, updateName) {
191 OutputLayerCompositionState outputLayerCompositionState;
192 LayerFECompositionState layerFECompositionState;
193 setupMocksForLayer(mOutputLayer, mLayerFE, outputLayerCompositionState,
194 layerFECompositionState);
195 mLayerState = std::make_unique<LayerState>(&mOutputLayer);
196
197 mock::OutputLayer newOutputLayer;
198 mock::LayerFE newLayerFE;
199 setupMocksForLayer(newOutputLayer, newLayerFE, outputLayerCompositionState,
200 layerFECompositionState, sSequenceId, sDebugNameTwo);
201 Flags<LayerStateField> updates = mLayerState->update(&newOutputLayer);
202 EXPECT_EQ(sDebugNameTwo, mLayerState->getName());
203 EXPECT_EQ(Flags<LayerStateField>(LayerStateField::Name), updates);
204 }
205
TEST_F(LayerStateTest,compareName)206 TEST_F(LayerStateTest, compareName) {
207 OutputLayerCompositionState outputLayerCompositionState;
208 LayerFECompositionState layerFECompositionState;
209 setupMocksForLayer(mOutputLayer, mLayerFE, outputLayerCompositionState,
210 layerFECompositionState);
211 mLayerState = std::make_unique<LayerState>(&mOutputLayer);
212 mock::OutputLayer newOutputLayer;
213 mock::LayerFE newLayerFE;
214 setupMocksForLayer(newOutputLayer, newLayerFE, outputLayerCompositionState,
215 layerFECompositionState, sSequenceId, sDebugNameTwo);
216 auto otherLayerState = std::make_unique<LayerState>(&newOutputLayer);
217
218 EXPECT_NE(mLayerState->getName(), otherLayerState->getName());
219
220 // Name is a unique field, so it's not computed in the hash for a layer state.
221 verifyUniqueDifferingFields(*mLayerState, *otherLayerState);
222 EXPECT_FALSE(mLayerState->compare(*otherLayerState));
223 EXPECT_FALSE(otherLayerState->compare(*mLayerState));
224 }
225
TEST_F(LayerStateTest,getDisplayFrame)226 TEST_F(LayerStateTest, getDisplayFrame) {
227 OutputLayerCompositionState outputLayerCompositionState;
228 outputLayerCompositionState.displayFrame = sRectOne;
229 LayerFECompositionState layerFECompositionState;
230 setupMocksForLayer(mOutputLayer, mLayerFE, outputLayerCompositionState,
231 layerFECompositionState);
232 mLayerState = std::make_unique<LayerState>(&mOutputLayer);
233 EXPECT_EQ(sRectOne, mLayerState->getDisplayFrame());
234 }
235
TEST_F(LayerStateTest,updateDisplayFrame)236 TEST_F(LayerStateTest, updateDisplayFrame) {
237 OutputLayerCompositionState outputLayerCompositionState;
238 outputLayerCompositionState.displayFrame = sRectOne;
239 LayerFECompositionState layerFECompositionState;
240 setupMocksForLayer(mOutputLayer, mLayerFE, outputLayerCompositionState,
241 layerFECompositionState);
242 mLayerState = std::make_unique<LayerState>(&mOutputLayer);
243
244 mock::OutputLayer newOutputLayer;
245 mock::LayerFE newLayerFE;
246 OutputLayerCompositionState outputLayerCompositionStateTwo;
247 outputLayerCompositionStateTwo.displayFrame = sRectTwo;
248 setupMocksForLayer(newOutputLayer, newLayerFE, outputLayerCompositionStateTwo,
249 layerFECompositionState);
250 Flags<LayerStateField> updates = mLayerState->update(&newOutputLayer);
251 EXPECT_EQ(sRectTwo, mLayerState->getDisplayFrame());
252 EXPECT_EQ(Flags<LayerStateField>(LayerStateField::DisplayFrame), updates);
253 }
254
TEST_F(LayerStateTest,compareDisplayFrame)255 TEST_F(LayerStateTest, compareDisplayFrame) {
256 OutputLayerCompositionState outputLayerCompositionState;
257 outputLayerCompositionState.displayFrame = sRectOne;
258 LayerFECompositionState layerFECompositionState;
259 setupMocksForLayer(mOutputLayer, mLayerFE, outputLayerCompositionState,
260 layerFECompositionState);
261 mLayerState = std::make_unique<LayerState>(&mOutputLayer);
262 mock::OutputLayer newOutputLayer;
263 mock::LayerFE newLayerFE;
264 OutputLayerCompositionState outputLayerCompositionStateTwo;
265 outputLayerCompositionStateTwo.displayFrame = sRectTwo;
266 setupMocksForLayer(newOutputLayer, newLayerFE, outputLayerCompositionStateTwo,
267 layerFECompositionState);
268 auto otherLayerState = std::make_unique<LayerState>(&newOutputLayer);
269
270 EXPECT_NE(mLayerState->getDisplayFrame(), otherLayerState->getDisplayFrame());
271
272 verifyNonUniqueDifferingFields(*mLayerState, *otherLayerState, LayerStateField::DisplayFrame);
273 EXPECT_TRUE(mLayerState->compare(*otherLayerState));
274 EXPECT_TRUE(otherLayerState->compare(*mLayerState));
275 }
276
TEST_F(LayerStateTest,getCompositionType)277 TEST_F(LayerStateTest, getCompositionType) {
278 OutputLayerCompositionState outputLayerCompositionState;
279 LayerFECompositionState layerFECompositionState;
280 layerFECompositionState.compositionType =
281 hardware::graphics::composer::hal::Composition::DEVICE;
282 setupMocksForLayer(mOutputLayer, mLayerFE, outputLayerCompositionState,
283 layerFECompositionState);
284 mLayerState = std::make_unique<LayerState>(&mOutputLayer);
285 EXPECT_EQ(hardware::graphics::composer::hal::Composition::DEVICE,
286 mLayerState->getCompositionType());
287 }
288
TEST_F(LayerStateTest,getCompositionType_forcedClient)289 TEST_F(LayerStateTest, getCompositionType_forcedClient) {
290 OutputLayerCompositionState outputLayerCompositionState;
291 outputLayerCompositionState.forceClientComposition = true;
292 LayerFECompositionState layerFECompositionState;
293 layerFECompositionState.compositionType =
294 hardware::graphics::composer::hal::Composition::DEVICE;
295 setupMocksForLayer(mOutputLayer, mLayerFE, outputLayerCompositionState,
296 layerFECompositionState);
297 mLayerState = std::make_unique<LayerState>(&mOutputLayer);
298 EXPECT_EQ(hardware::graphics::composer::hal::Composition::CLIENT,
299 mLayerState->getCompositionType());
300 }
301
TEST_F(LayerStateTest,updateCompositionType)302 TEST_F(LayerStateTest, updateCompositionType) {
303 OutputLayerCompositionState outputLayerCompositionState;
304 LayerFECompositionState layerFECompositionState;
305 layerFECompositionState.compositionType =
306 hardware::graphics::composer::hal::Composition::DEVICE;
307 setupMocksForLayer(mOutputLayer, mLayerFE, outputLayerCompositionState,
308 layerFECompositionState);
309 mLayerState = std::make_unique<LayerState>(&mOutputLayer);
310
311 mock::OutputLayer newOutputLayer;
312 mock::LayerFE newLayerFE;
313 LayerFECompositionState layerFECompositionStateTwo;
314 layerFECompositionStateTwo.compositionType =
315 hardware::graphics::composer::hal::Composition::SOLID_COLOR;
316 setupMocksForLayer(newOutputLayer, newLayerFE, outputLayerCompositionState,
317 layerFECompositionStateTwo);
318 Flags<LayerStateField> updates = mLayerState->update(&newOutputLayer);
319 EXPECT_EQ(hardware::graphics::composer::hal::Composition::SOLID_COLOR,
320 mLayerState->getCompositionType());
321 EXPECT_EQ(Flags<LayerStateField>(LayerStateField::CompositionType), updates);
322 }
323
TEST_F(LayerStateTest,compareCompositionType)324 TEST_F(LayerStateTest, compareCompositionType) {
325 OutputLayerCompositionState outputLayerCompositionState;
326 LayerFECompositionState layerFECompositionState;
327 layerFECompositionState.compositionType =
328 hardware::graphics::composer::hal::Composition::DEVICE;
329 setupMocksForLayer(mOutputLayer, mLayerFE, outputLayerCompositionState,
330 layerFECompositionState);
331 mLayerState = std::make_unique<LayerState>(&mOutputLayer);
332 mock::OutputLayer newOutputLayer;
333 mock::LayerFE newLayerFE;
334 LayerFECompositionState layerFECompositionStateTwo;
335 layerFECompositionStateTwo.compositionType =
336 hardware::graphics::composer::hal::Composition::SOLID_COLOR;
337 setupMocksForLayer(newOutputLayer, newLayerFE, outputLayerCompositionState,
338 layerFECompositionStateTwo);
339 auto otherLayerState = std::make_unique<LayerState>(&newOutputLayer);
340
341 EXPECT_NE(mLayerState->getCompositionType(), otherLayerState->getCompositionType());
342
343 verifyNonUniqueDifferingFields(*mLayerState, *otherLayerState,
344 LayerStateField::CompositionType);
345 EXPECT_TRUE(mLayerState->compare(*otherLayerState));
346 EXPECT_TRUE(otherLayerState->compare(*mLayerState));
347 }
348
TEST_F(LayerStateTest,updateBuffer)349 TEST_F(LayerStateTest, updateBuffer) {
350 OutputLayerCompositionState outputLayerCompositionState;
351 LayerFECompositionState layerFECompositionState;
352 layerFECompositionState.buffer = new GraphicBuffer();
353 setupMocksForLayer(mOutputLayer, mLayerFE, outputLayerCompositionState,
354 layerFECompositionState);
355 mLayerState = std::make_unique<LayerState>(&mOutputLayer);
356
357 mock::OutputLayer newOutputLayer;
358 mock::LayerFE newLayerFE;
359 LayerFECompositionState layerFECompositionStateTwo;
360 layerFECompositionStateTwo.buffer = new GraphicBuffer();
361 setupMocksForLayer(newOutputLayer, newLayerFE, outputLayerCompositionState,
362 layerFECompositionStateTwo);
363 Flags<LayerStateField> updates = mLayerState->update(&newOutputLayer);
364 EXPECT_EQ(Flags<LayerStateField>(LayerStateField::Buffer), updates);
365 }
366
TEST_F(LayerStateTest,compareBuffer)367 TEST_F(LayerStateTest, compareBuffer) {
368 OutputLayerCompositionState outputLayerCompositionState;
369 LayerFECompositionState layerFECompositionState;
370 layerFECompositionState.buffer = new GraphicBuffer();
371 setupMocksForLayer(mOutputLayer, mLayerFE, outputLayerCompositionState,
372 layerFECompositionState);
373 mLayerState = std::make_unique<LayerState>(&mOutputLayer);
374 mock::OutputLayer newOutputLayer;
375 mock::LayerFE newLayerFE;
376 LayerFECompositionState layerFECompositionStateTwo;
377 layerFECompositionStateTwo.buffer = new GraphicBuffer();
378 setupMocksForLayer(newOutputLayer, newLayerFE, outputLayerCompositionState,
379 layerFECompositionStateTwo);
380 auto otherLayerState = std::make_unique<LayerState>(&newOutputLayer);
381
382 // A buffer is not a unique field, but the assertions are the same.
383 verifyUniqueDifferingFields(*mLayerState, *otherLayerState);
384
385 // Buffers are explicitly excluded from comparison
386 EXPECT_FALSE(mLayerState->compare(*otherLayerState));
387 EXPECT_FALSE(otherLayerState->compare(*mLayerState));
388 }
389
TEST_F(LayerStateTest,updateSourceCrop)390 TEST_F(LayerStateTest, updateSourceCrop) {
391 OutputLayerCompositionState outputLayerCompositionState;
392 outputLayerCompositionState.sourceCrop = sFloatRectOne;
393 LayerFECompositionState layerFECompositionState;
394 setupMocksForLayer(mOutputLayer, mLayerFE, outputLayerCompositionState,
395 layerFECompositionState);
396 mLayerState = std::make_unique<LayerState>(&mOutputLayer);
397
398 mock::OutputLayer newOutputLayer;
399 mock::LayerFE newLayerFE;
400 OutputLayerCompositionState outputLayerCompositionStateTwo;
401 outputLayerCompositionStateTwo.sourceCrop = sFloatRectTwo;
402 setupMocksForLayer(newOutputLayer, newLayerFE, outputLayerCompositionStateTwo,
403 layerFECompositionState);
404 Flags<LayerStateField> updates = mLayerState->update(&newOutputLayer);
405 EXPECT_EQ(Flags<LayerStateField>(LayerStateField::SourceCrop), updates);
406 }
407
TEST_F(LayerStateTest,compareSourceCrop)408 TEST_F(LayerStateTest, compareSourceCrop) {
409 OutputLayerCompositionState outputLayerCompositionState;
410 outputLayerCompositionState.sourceCrop = sFloatRectOne;
411 LayerFECompositionState layerFECompositionState;
412 setupMocksForLayer(mOutputLayer, mLayerFE, outputLayerCompositionState,
413 layerFECompositionState);
414 mLayerState = std::make_unique<LayerState>(&mOutputLayer);
415 mock::OutputLayer newOutputLayer;
416 mock::LayerFE newLayerFE;
417 OutputLayerCompositionState outputLayerCompositionStateTwo;
418 outputLayerCompositionStateTwo.sourceCrop = sFloatRectTwo;
419 setupMocksForLayer(newOutputLayer, newLayerFE, outputLayerCompositionStateTwo,
420 layerFECompositionState);
421 auto otherLayerState = std::make_unique<LayerState>(&newOutputLayer);
422
423 verifyNonUniqueDifferingFields(*mLayerState, *otherLayerState, LayerStateField::SourceCrop);
424
425 EXPECT_TRUE(mLayerState->compare(*otherLayerState));
426 EXPECT_TRUE(otherLayerState->compare(*mLayerState));
427 }
428
TEST_F(LayerStateTest,updateBufferTransform)429 TEST_F(LayerStateTest, updateBufferTransform) {
430 OutputLayerCompositionState outputLayerCompositionState;
431 outputLayerCompositionState.bufferTransform = Hwc2::Transform::FLIP_H;
432 LayerFECompositionState layerFECompositionState;
433 setupMocksForLayer(mOutputLayer, mLayerFE, outputLayerCompositionState,
434 layerFECompositionState);
435 mLayerState = std::make_unique<LayerState>(&mOutputLayer);
436
437 mock::OutputLayer newOutputLayer;
438 mock::LayerFE newLayerFE;
439 OutputLayerCompositionState outputLayerCompositionStateTwo;
440 outputLayerCompositionStateTwo.bufferTransform = Hwc2::Transform::FLIP_V;
441 setupMocksForLayer(newOutputLayer, newLayerFE, outputLayerCompositionStateTwo,
442 layerFECompositionState);
443 Flags<LayerStateField> updates = mLayerState->update(&newOutputLayer);
444 EXPECT_EQ(Flags<LayerStateField>(LayerStateField::BufferTransform), updates);
445 }
446
TEST_F(LayerStateTest,compareBufferTransform)447 TEST_F(LayerStateTest, compareBufferTransform) {
448 OutputLayerCompositionState outputLayerCompositionState;
449 outputLayerCompositionState.bufferTransform = Hwc2::Transform::FLIP_H;
450 LayerFECompositionState layerFECompositionState;
451 setupMocksForLayer(mOutputLayer, mLayerFE, outputLayerCompositionState,
452 layerFECompositionState);
453 mLayerState = std::make_unique<LayerState>(&mOutputLayer);
454 mock::OutputLayer newOutputLayer;
455 mock::LayerFE newLayerFE;
456 OutputLayerCompositionState outputLayerCompositionStateTwo;
457 outputLayerCompositionStateTwo.bufferTransform = Hwc2::Transform::FLIP_V;
458 setupMocksForLayer(newOutputLayer, newLayerFE, outputLayerCompositionStateTwo,
459 layerFECompositionState);
460 auto otherLayerState = std::make_unique<LayerState>(&newOutputLayer);
461
462 verifyNonUniqueDifferingFields(*mLayerState, *otherLayerState,
463 LayerStateField::BufferTransform);
464
465 EXPECT_TRUE(mLayerState->compare(*otherLayerState));
466 EXPECT_TRUE(otherLayerState->compare(*mLayerState));
467 }
468
TEST_F(LayerStateTest,updateBlendMode)469 TEST_F(LayerStateTest, updateBlendMode) {
470 OutputLayerCompositionState outputLayerCompositionState;
471 LayerFECompositionState layerFECompositionState;
472 layerFECompositionState.blendMode = hal::BlendMode::COVERAGE;
473 setupMocksForLayer(mOutputLayer, mLayerFE, outputLayerCompositionState,
474 layerFECompositionState);
475 mLayerState = std::make_unique<LayerState>(&mOutputLayer);
476
477 mock::OutputLayer newOutputLayer;
478 mock::LayerFE newLayerFE;
479 LayerFECompositionState layerFECompositionStateTwo;
480 layerFECompositionStateTwo.blendMode = hal::BlendMode::PREMULTIPLIED;
481 setupMocksForLayer(newOutputLayer, newLayerFE, outputLayerCompositionState,
482 layerFECompositionStateTwo);
483 Flags<LayerStateField> updates = mLayerState->update(&newOutputLayer);
484 EXPECT_EQ(Flags<LayerStateField>(LayerStateField::BlendMode), updates);
485 }
486
TEST_F(LayerStateTest,compareBlendMode)487 TEST_F(LayerStateTest, compareBlendMode) {
488 OutputLayerCompositionState outputLayerCompositionState;
489 LayerFECompositionState layerFECompositionState;
490 layerFECompositionState.blendMode = hal::BlendMode::COVERAGE;
491 setupMocksForLayer(mOutputLayer, mLayerFE, outputLayerCompositionState,
492 layerFECompositionState);
493 mLayerState = std::make_unique<LayerState>(&mOutputLayer);
494 mock::OutputLayer newOutputLayer;
495 mock::LayerFE newLayerFE;
496 LayerFECompositionState layerFECompositionStateTwo;
497 layerFECompositionStateTwo.blendMode = hal::BlendMode::PREMULTIPLIED;
498 setupMocksForLayer(newOutputLayer, newLayerFE, outputLayerCompositionState,
499 layerFECompositionStateTwo);
500 auto otherLayerState = std::make_unique<LayerState>(&newOutputLayer);
501
502 verifyNonUniqueDifferingFields(*mLayerState, *otherLayerState, LayerStateField::BlendMode);
503
504 EXPECT_TRUE(mLayerState->compare(*otherLayerState));
505 EXPECT_TRUE(otherLayerState->compare(*mLayerState));
506 }
507
TEST_F(LayerStateTest,updateAlpha)508 TEST_F(LayerStateTest, updateAlpha) {
509 OutputLayerCompositionState outputLayerCompositionState;
510 LayerFECompositionState layerFECompositionState;
511 layerFECompositionState.alpha = sAlphaOne;
512 setupMocksForLayer(mOutputLayer, mLayerFE, outputLayerCompositionState,
513 layerFECompositionState);
514 mLayerState = std::make_unique<LayerState>(&mOutputLayer);
515
516 mock::OutputLayer newOutputLayer;
517 mock::LayerFE newLayerFE;
518 LayerFECompositionState layerFECompositionStateTwo;
519 layerFECompositionStateTwo.alpha = sAlphaTwo;
520 setupMocksForLayer(newOutputLayer, newLayerFE, outputLayerCompositionState,
521 layerFECompositionStateTwo);
522 Flags<LayerStateField> updates = mLayerState->update(&newOutputLayer);
523 EXPECT_EQ(Flags<LayerStateField>(LayerStateField::Alpha), updates);
524 }
525
TEST_F(LayerStateTest,compareAlpha)526 TEST_F(LayerStateTest, compareAlpha) {
527 OutputLayerCompositionState outputLayerCompositionState;
528 LayerFECompositionState layerFECompositionState;
529 layerFECompositionState.alpha = sAlphaOne;
530 setupMocksForLayer(mOutputLayer, mLayerFE, outputLayerCompositionState,
531 layerFECompositionState);
532 mLayerState = std::make_unique<LayerState>(&mOutputLayer);
533 mock::OutputLayer newOutputLayer;
534 mock::LayerFE newLayerFE;
535 LayerFECompositionState layerFECompositionStateTwo;
536 layerFECompositionStateTwo.alpha = sAlphaTwo;
537 setupMocksForLayer(newOutputLayer, newLayerFE, outputLayerCompositionState,
538 layerFECompositionStateTwo);
539 auto otherLayerState = std::make_unique<LayerState>(&newOutputLayer);
540
541 verifyNonUniqueDifferingFields(*mLayerState, *otherLayerState, LayerStateField::Alpha);
542
543 EXPECT_TRUE(mLayerState->compare(*otherLayerState));
544 EXPECT_TRUE(otherLayerState->compare(*mLayerState));
545 }
546
TEST_F(LayerStateTest,updateLayerMetadata)547 TEST_F(LayerStateTest, updateLayerMetadata) {
548 OutputLayerCompositionState outputLayerCompositionState;
549 LayerFECompositionState layerFECompositionState;
550 layerFECompositionState.metadata[sMetadataKeyOne] = sMetadataValueOne;
551 setupMocksForLayer(mOutputLayer, mLayerFE, outputLayerCompositionState,
552 layerFECompositionState);
553 mLayerState = std::make_unique<LayerState>(&mOutputLayer);
554
555 mock::OutputLayer newOutputLayer;
556 mock::LayerFE newLayerFE;
557 LayerFECompositionState layerFECompositionStateTwo;
558 layerFECompositionStateTwo.metadata[sMetadataKeyTwo] = sMetadataValueTwo;
559 setupMocksForLayer(newOutputLayer, newLayerFE, outputLayerCompositionState,
560 layerFECompositionStateTwo);
561 Flags<LayerStateField> updates = mLayerState->update(&newOutputLayer);
562 EXPECT_EQ(Flags<LayerStateField>(LayerStateField::LayerMetadata), updates);
563 }
564
TEST_F(LayerStateTest,compareLayerMetadata)565 TEST_F(LayerStateTest, compareLayerMetadata) {
566 OutputLayerCompositionState outputLayerCompositionState;
567 LayerFECompositionState layerFECompositionState;
568 layerFECompositionState.metadata[sMetadataKeyOne] = sMetadataValueOne;
569 setupMocksForLayer(mOutputLayer, mLayerFE, outputLayerCompositionState,
570 layerFECompositionState);
571 mLayerState = std::make_unique<LayerState>(&mOutputLayer);
572 mock::OutputLayer newOutputLayer;
573 mock::LayerFE newLayerFE;
574 LayerFECompositionState layerFECompositionStateTwo;
575 layerFECompositionStateTwo.metadata[sMetadataKeyTwo] = sMetadataValueTwo;
576 setupMocksForLayer(newOutputLayer, newLayerFE, outputLayerCompositionState,
577 layerFECompositionStateTwo);
578 auto otherLayerState = std::make_unique<LayerState>(&newOutputLayer);
579
580 verifyNonUniqueDifferingFields(*mLayerState, *otherLayerState, LayerStateField::LayerMetadata);
581
582 EXPECT_TRUE(mLayerState->compare(*otherLayerState));
583 EXPECT_TRUE(otherLayerState->compare(*mLayerState));
584 }
585
TEST_F(LayerStateTest,getVisibleRegion)586 TEST_F(LayerStateTest, getVisibleRegion) {
587 OutputLayerCompositionState outputLayerCompositionState;
588 outputLayerCompositionState.visibleRegion = sRegionOne;
589 LayerFECompositionState layerFECompositionState;
590 setupMocksForLayer(mOutputLayer, mLayerFE, outputLayerCompositionState,
591 layerFECompositionState);
592 mLayerState = std::make_unique<LayerState>(&mOutputLayer);
593 EXPECT_TRUE(mLayerState->getVisibleRegion().hasSameRects(sRegionOne));
594 }
595
TEST_F(LayerStateTest,updateVisibleRegion)596 TEST_F(LayerStateTest, updateVisibleRegion) {
597 OutputLayerCompositionState outputLayerCompositionState;
598 outputLayerCompositionState.visibleRegion = sRegionOne;
599 LayerFECompositionState layerFECompositionState;
600 setupMocksForLayer(mOutputLayer, mLayerFE, outputLayerCompositionState,
601 layerFECompositionState);
602 mLayerState = std::make_unique<LayerState>(&mOutputLayer);
603
604 mock::OutputLayer newOutputLayer;
605 mock::LayerFE newLayerFE;
606 OutputLayerCompositionState outputLayerCompositionStateTwo;
607 outputLayerCompositionStateTwo.visibleRegion = sRegionTwo;
608 setupMocksForLayer(newOutputLayer, newLayerFE, outputLayerCompositionStateTwo,
609 layerFECompositionState);
610 Flags<LayerStateField> updates = mLayerState->update(&newOutputLayer);
611 EXPECT_EQ(Flags<LayerStateField>(LayerStateField::VisibleRegion), updates);
612 }
613
TEST_F(LayerStateTest,compareVisibleRegion)614 TEST_F(LayerStateTest, compareVisibleRegion) {
615 OutputLayerCompositionState outputLayerCompositionState;
616 outputLayerCompositionState.visibleRegion = sRegionOne;
617 LayerFECompositionState layerFECompositionState;
618 setupMocksForLayer(mOutputLayer, mLayerFE, outputLayerCompositionState,
619 layerFECompositionState);
620 mLayerState = std::make_unique<LayerState>(&mOutputLayer);
621 mock::OutputLayer newOutputLayer;
622 mock::LayerFE newLayerFE;
623 OutputLayerCompositionState outputLayerCompositionStateTwo;
624 outputLayerCompositionStateTwo.visibleRegion = sRegionTwo;
625 setupMocksForLayer(newOutputLayer, newLayerFE, outputLayerCompositionStateTwo,
626 layerFECompositionState);
627 auto otherLayerState = std::make_unique<LayerState>(&newOutputLayer);
628
629 verifyNonUniqueDifferingFields(*mLayerState, *otherLayerState, LayerStateField::VisibleRegion);
630
631 EXPECT_TRUE(mLayerState->compare(*otherLayerState));
632 EXPECT_TRUE(otherLayerState->compare(*mLayerState));
633 }
634
TEST_F(LayerStateTest,updateDataspace)635 TEST_F(LayerStateTest, updateDataspace) {
636 OutputLayerCompositionState outputLayerCompositionState;
637 outputLayerCompositionState.dataspace = ui::Dataspace::SRGB;
638 LayerFECompositionState layerFECompositionState;
639 setupMocksForLayer(mOutputLayer, mLayerFE, outputLayerCompositionState,
640 layerFECompositionState);
641 mLayerState = std::make_unique<LayerState>(&mOutputLayer);
642
643 mock::OutputLayer newOutputLayer;
644 mock::LayerFE newLayerFE;
645 OutputLayerCompositionState outputLayerCompositionStateTwo;
646 outputLayerCompositionStateTwo.dataspace = ui::Dataspace::DISPLAY_P3;
647 setupMocksForLayer(newOutputLayer, newLayerFE, outputLayerCompositionStateTwo,
648 layerFECompositionState);
649 Flags<LayerStateField> updates = mLayerState->update(&newOutputLayer);
650 EXPECT_EQ(Flags<LayerStateField>(LayerStateField::Dataspace), updates);
651 }
652
TEST_F(LayerStateTest,compareDataspace)653 TEST_F(LayerStateTest, compareDataspace) {
654 OutputLayerCompositionState outputLayerCompositionState;
655 outputLayerCompositionState.dataspace = ui::Dataspace::SRGB;
656 LayerFECompositionState layerFECompositionState;
657 setupMocksForLayer(mOutputLayer, mLayerFE, outputLayerCompositionState,
658 layerFECompositionState);
659 mLayerState = std::make_unique<LayerState>(&mOutputLayer);
660 mock::OutputLayer newOutputLayer;
661 mock::LayerFE newLayerFE;
662 OutputLayerCompositionState outputLayerCompositionStateTwo;
663 outputLayerCompositionStateTwo.dataspace = ui::Dataspace::DISPLAY_P3;
664 setupMocksForLayer(newOutputLayer, newLayerFE, outputLayerCompositionStateTwo,
665 layerFECompositionState);
666 auto otherLayerState = std::make_unique<LayerState>(&newOutputLayer);
667
668 verifyNonUniqueDifferingFields(*mLayerState, *otherLayerState, LayerStateField::Dataspace);
669
670 EXPECT_TRUE(mLayerState->compare(*otherLayerState));
671 EXPECT_TRUE(otherLayerState->compare(*mLayerState));
672 }
673
TEST_F(LayerStateTest,updatePixelFormat)674 TEST_F(LayerStateTest, updatePixelFormat) {
675 OutputLayerCompositionState outputLayerCompositionState;
676 LayerFECompositionState layerFECompositionState;
677 layerFECompositionState.buffer =
678 new GraphicBuffer(1, 1, PIXEL_FORMAT_RGBA_8888,
679 AHARDWAREBUFFER_USAGE_CPU_READ_OFTEN |
680 AHARDWAREBUFFER_USAGE_CPU_WRITE_OFTEN,
681 "buffer1");
682 setupMocksForLayer(mOutputLayer, mLayerFE, outputLayerCompositionState,
683 layerFECompositionState);
684 mLayerState = std::make_unique<LayerState>(&mOutputLayer);
685
686 mock::OutputLayer newOutputLayer;
687 mock::LayerFE newLayerFE;
688 LayerFECompositionState layerFECompositionStateTwo;
689 layerFECompositionStateTwo.buffer =
690 new GraphicBuffer(1, 1, PIXEL_FORMAT_RGBX_8888,
691 AHARDWAREBUFFER_USAGE_CPU_READ_OFTEN |
692 AHARDWAREBUFFER_USAGE_CPU_WRITE_OFTEN,
693 "buffer2");
694 setupMocksForLayer(newOutputLayer, newLayerFE, outputLayerCompositionState,
695 layerFECompositionStateTwo);
696 Flags<LayerStateField> updates = mLayerState->update(&newOutputLayer);
697 EXPECT_EQ(Flags<LayerStateField>(LayerStateField::Buffer) |
698 Flags<LayerStateField>(LayerStateField::PixelFormat),
699 updates);
700 }
701
TEST_F(LayerStateTest,comparePixelFormat)702 TEST_F(LayerStateTest, comparePixelFormat) {
703 OutputLayerCompositionState outputLayerCompositionState;
704 LayerFECompositionState layerFECompositionState;
705 layerFECompositionState.buffer =
706 new GraphicBuffer(1, 1, PIXEL_FORMAT_RGBA_8888,
707 AHARDWAREBUFFER_USAGE_CPU_READ_OFTEN |
708 AHARDWAREBUFFER_USAGE_CPU_WRITE_OFTEN,
709 "buffer1");
710 setupMocksForLayer(mOutputLayer, mLayerFE, outputLayerCompositionState,
711 layerFECompositionState);
712 mLayerState = std::make_unique<LayerState>(&mOutputLayer);
713 mock::OutputLayer newOutputLayer;
714 mock::LayerFE newLayerFE;
715 LayerFECompositionState layerFECompositionStateTwo;
716 layerFECompositionStateTwo.buffer =
717 new GraphicBuffer(1, 1, PIXEL_FORMAT_RGBX_8888,
718 AHARDWAREBUFFER_USAGE_CPU_READ_OFTEN |
719 AHARDWAREBUFFER_USAGE_CPU_WRITE_OFTEN,
720 "buffer2");
721 setupMocksForLayer(newOutputLayer, newLayerFE, outputLayerCompositionState,
722 layerFECompositionStateTwo);
723 auto otherLayerState = std::make_unique<LayerState>(&newOutputLayer);
724
725 verifyNonUniqueDifferingFields(*mLayerState, *otherLayerState,
726 Flags<LayerStateField>(LayerStateField::PixelFormat));
727
728 EXPECT_TRUE(mLayerState->compare(*otherLayerState));
729 EXPECT_TRUE(otherLayerState->compare(*mLayerState));
730 }
731
TEST_F(LayerStateTest,updateColorTransform)732 TEST_F(LayerStateTest, updateColorTransform) {
733 OutputLayerCompositionState outputLayerCompositionState;
734 LayerFECompositionState layerFECompositionState;
735 layerFECompositionState.colorTransformIsIdentity = true;
736 layerFECompositionState.colorTransform = mat4();
737 setupMocksForLayer(mOutputLayer, mLayerFE, outputLayerCompositionState,
738 layerFECompositionState);
739 mLayerState = std::make_unique<LayerState>(&mOutputLayer);
740
741 mock::OutputLayer newOutputLayer;
742 mock::LayerFE newLayerFE;
743 LayerFECompositionState layerFECompositionStateTwo;
744 layerFECompositionStateTwo.colorTransformIsIdentity = false;
745 layerFECompositionStateTwo.colorTransform = sMat4One;
746 setupMocksForLayer(newOutputLayer, newLayerFE, outputLayerCompositionState,
747 layerFECompositionStateTwo);
748 Flags<LayerStateField> updates = mLayerState->update(&newOutputLayer);
749 EXPECT_EQ(Flags<LayerStateField>(LayerStateField::ColorTransform), updates);
750 }
751
TEST_F(LayerStateTest,compareColorTransform)752 TEST_F(LayerStateTest, compareColorTransform) {
753 OutputLayerCompositionState outputLayerCompositionState;
754 LayerFECompositionState layerFECompositionState;
755 layerFECompositionState.colorTransformIsIdentity = true;
756 layerFECompositionState.colorTransform = mat4();
757 setupMocksForLayer(mOutputLayer, mLayerFE, outputLayerCompositionState,
758 layerFECompositionState);
759 mLayerState = std::make_unique<LayerState>(&mOutputLayer);
760 mock::OutputLayer newOutputLayer;
761 mock::LayerFE newLayerFE;
762 LayerFECompositionState layerFECompositionStateTwo;
763 layerFECompositionStateTwo.colorTransformIsIdentity = false;
764 layerFECompositionStateTwo.colorTransform = sMat4One;
765 setupMocksForLayer(newOutputLayer, newLayerFE, outputLayerCompositionState,
766 layerFECompositionStateTwo);
767 auto otherLayerState = std::make_unique<LayerState>(&newOutputLayer);
768
769 verifyNonUniqueDifferingFields(*mLayerState, *otherLayerState, LayerStateField::ColorTransform);
770
771 EXPECT_TRUE(mLayerState->compare(*otherLayerState));
772 EXPECT_TRUE(otherLayerState->compare(*mLayerState));
773 }
774
TEST_F(LayerStateTest,updateSidebandStream)775 TEST_F(LayerStateTest, updateSidebandStream) {
776 OutputLayerCompositionState outputLayerCompositionState;
777 LayerFECompositionState layerFECompositionState;
778 layerFECompositionState.sidebandStream = NativeHandle::create(sFakeSidebandStreamOne, false);
779 setupMocksForLayer(mOutputLayer, mLayerFE, outputLayerCompositionState,
780 layerFECompositionState);
781 mLayerState = std::make_unique<LayerState>(&mOutputLayer);
782
783 mock::OutputLayer newOutputLayer;
784 mock::LayerFE newLayerFE;
785 LayerFECompositionState layerFECompositionStateTwo;
786 layerFECompositionStateTwo.sidebandStream = NativeHandle::create(sFakeSidebandStreamTwo, false);
787 setupMocksForLayer(newOutputLayer, newLayerFE, outputLayerCompositionState,
788 layerFECompositionStateTwo);
789 Flags<LayerStateField> updates = mLayerState->update(&newOutputLayer);
790 EXPECT_EQ(Flags<LayerStateField>(LayerStateField::SidebandStream), updates);
791 }
792
TEST_F(LayerStateTest,compareSidebandStream)793 TEST_F(LayerStateTest, compareSidebandStream) {
794 OutputLayerCompositionState outputLayerCompositionState;
795 LayerFECompositionState layerFECompositionState;
796 layerFECompositionState.sidebandStream = NativeHandle::create(sFakeSidebandStreamOne, false);
797 setupMocksForLayer(mOutputLayer, mLayerFE, outputLayerCompositionState,
798 layerFECompositionState);
799 mLayerState = std::make_unique<LayerState>(&mOutputLayer);
800 mock::OutputLayer newOutputLayer;
801 mock::LayerFE newLayerFE;
802 LayerFECompositionState layerFECompositionStateTwo;
803 layerFECompositionStateTwo.sidebandStream = NativeHandle::create(sFakeSidebandStreamTwo, false);
804 setupMocksForLayer(newOutputLayer, newLayerFE, outputLayerCompositionState,
805 layerFECompositionStateTwo);
806 auto otherLayerState = std::make_unique<LayerState>(&newOutputLayer);
807
808 verifyNonUniqueDifferingFields(*mLayerState, *otherLayerState, LayerStateField::SidebandStream);
809
810 EXPECT_TRUE(mLayerState->compare(*otherLayerState));
811 EXPECT_TRUE(otherLayerState->compare(*mLayerState));
812 }
813
TEST_F(LayerStateTest,updateSolidColor)814 TEST_F(LayerStateTest, updateSolidColor) {
815 OutputLayerCompositionState outputLayerCompositionState;
816 LayerFECompositionState layerFECompositionState;
817 layerFECompositionState.color = sHalf4One;
818 setupMocksForLayer(mOutputLayer, mLayerFE, outputLayerCompositionState,
819 layerFECompositionState);
820 mLayerState = std::make_unique<LayerState>(&mOutputLayer);
821
822 mock::OutputLayer newOutputLayer;
823 mock::LayerFE newLayerFE;
824 LayerFECompositionState layerFECompositionStateTwo;
825 layerFECompositionStateTwo.color = sHalf4Two;
826 setupMocksForLayer(newOutputLayer, newLayerFE, outputLayerCompositionState,
827 layerFECompositionStateTwo);
828 Flags<LayerStateField> updates = mLayerState->update(&newOutputLayer);
829 EXPECT_EQ(Flags<LayerStateField>(LayerStateField::SolidColor), updates);
830 }
831
TEST_F(LayerStateTest,compareSolidColor)832 TEST_F(LayerStateTest, compareSolidColor) {
833 OutputLayerCompositionState outputLayerCompositionState;
834 LayerFECompositionState layerFECompositionState;
835 layerFECompositionState.color = sHalf4One;
836 setupMocksForLayer(mOutputLayer, mLayerFE, outputLayerCompositionState,
837 layerFECompositionState);
838 mLayerState = std::make_unique<LayerState>(&mOutputLayer);
839 mock::OutputLayer newOutputLayer;
840 mock::LayerFE newLayerFE;
841 LayerFECompositionState layerFECompositionStateTwo;
842 layerFECompositionStateTwo.color = sHalf4Two;
843 setupMocksForLayer(newOutputLayer, newLayerFE, outputLayerCompositionState,
844 layerFECompositionStateTwo);
845 auto otherLayerState = std::make_unique<LayerState>(&newOutputLayer);
846
847 verifyNonUniqueDifferingFields(*mLayerState, *otherLayerState, LayerStateField::SolidColor);
848
849 EXPECT_TRUE(mLayerState->compare(*otherLayerState));
850 EXPECT_TRUE(otherLayerState->compare(*mLayerState));
851 }
852
TEST_F(LayerStateTest,updateBackgroundBlur)853 TEST_F(LayerStateTest, updateBackgroundBlur) {
854 OutputLayerCompositionState outputLayerCompositionState;
855 LayerFECompositionState layerFECompositionState;
856 layerFECompositionState.backgroundBlurRadius = sBgBlurRadiusOne;
857 setupMocksForLayer(mOutputLayer, mLayerFE, outputLayerCompositionState,
858 layerFECompositionState);
859 mLayerState = std::make_unique<LayerState>(&mOutputLayer);
860
861 mock::OutputLayer newOutputLayer;
862 mock::LayerFE newLayerFE;
863 LayerFECompositionState layerFECompositionStateTwo;
864 layerFECompositionStateTwo.backgroundBlurRadius = sBgBlurRadiusTwo;
865 setupMocksForLayer(newOutputLayer, newLayerFE, outputLayerCompositionState,
866 layerFECompositionStateTwo);
867 Flags<LayerStateField> updates = mLayerState->update(&newOutputLayer);
868 EXPECT_EQ(Flags<LayerStateField>(LayerStateField::BackgroundBlurRadius), updates);
869 }
870
TEST_F(LayerStateTest,compareBackgroundBlur)871 TEST_F(LayerStateTest, compareBackgroundBlur) {
872 OutputLayerCompositionState outputLayerCompositionState;
873 LayerFECompositionState layerFECompositionState;
874 layerFECompositionState.backgroundBlurRadius = sBgBlurRadiusOne;
875 setupMocksForLayer(mOutputLayer, mLayerFE, outputLayerCompositionState,
876 layerFECompositionState);
877 mLayerState = std::make_unique<LayerState>(&mOutputLayer);
878 mock::OutputLayer newOutputLayer;
879 mock::LayerFE newLayerFE;
880 LayerFECompositionState layerFECompositionStateTwo;
881 layerFECompositionStateTwo.backgroundBlurRadius = sBgBlurRadiusTwo;
882 setupMocksForLayer(newOutputLayer, newLayerFE, outputLayerCompositionState,
883 layerFECompositionStateTwo);
884 auto otherLayerState = std::make_unique<LayerState>(&newOutputLayer);
885
886 verifyNonUniqueDifferingFields(*mLayerState, *otherLayerState,
887 LayerStateField::BackgroundBlurRadius);
888
889 EXPECT_TRUE(mLayerState->compare(*otherLayerState));
890 EXPECT_TRUE(otherLayerState->compare(*mLayerState));
891 }
892
TEST_F(LayerStateTest,updateBlurRegions)893 TEST_F(LayerStateTest, updateBlurRegions) {
894 OutputLayerCompositionState outputLayerCompositionState;
895 LayerFECompositionState layerFECompositionState;
896 layerFECompositionState.blurRegions.push_back(sBlurRegionOne);
897 setupMocksForLayer(mOutputLayer, mLayerFE, outputLayerCompositionState,
898 layerFECompositionState);
899 mLayerState = std::make_unique<LayerState>(&mOutputLayer);
900
901 mock::OutputLayer newOutputLayer;
902 mock::LayerFE newLayerFE;
903 LayerFECompositionState layerFECompositionStateTwo;
904 layerFECompositionStateTwo.blurRegions.push_back(sBlurRegionTwo);
905 setupMocksForLayer(newOutputLayer, newLayerFE, outputLayerCompositionState,
906 layerFECompositionStateTwo);
907 Flags<LayerStateField> updates = mLayerState->update(&newOutputLayer);
908 EXPECT_EQ(Flags<LayerStateField>(LayerStateField::BlurRegions), updates);
909 }
910
TEST_F(LayerStateTest,compareBlurRegions)911 TEST_F(LayerStateTest, compareBlurRegions) {
912 OutputLayerCompositionState outputLayerCompositionState;
913 LayerFECompositionState layerFECompositionState;
914 layerFECompositionState.blurRegions.push_back(sBlurRegionOne);
915 setupMocksForLayer(mOutputLayer, mLayerFE, outputLayerCompositionState,
916 layerFECompositionState);
917 mLayerState = std::make_unique<LayerState>(&mOutputLayer);
918 mock::OutputLayer newOutputLayer;
919 mock::LayerFE newLayerFE;
920 LayerFECompositionState layerFECompositionStateTwo;
921 layerFECompositionStateTwo.blurRegions.push_back(sBlurRegionTwo);
922 setupMocksForLayer(newOutputLayer, newLayerFE, outputLayerCompositionState,
923 layerFECompositionStateTwo);
924 auto otherLayerState = std::make_unique<LayerState>(&newOutputLayer);
925
926 verifyNonUniqueDifferingFields(*mLayerState, *otherLayerState, LayerStateField::BlurRegions);
927
928 EXPECT_TRUE(mLayerState->compare(*otherLayerState));
929 EXPECT_TRUE(otherLayerState->compare(*mLayerState));
930 }
931
TEST_F(LayerStateTest,hasBlurBehind_noBlur_returnsFalse)932 TEST_F(LayerStateTest, hasBlurBehind_noBlur_returnsFalse) {
933 OutputLayerCompositionState outputLayerCompositionState;
934 LayerFECompositionState layerFECompositionState;
935 setupMocksForLayer(mOutputLayer, mLayerFE, outputLayerCompositionState,
936 layerFECompositionState);
937 mLayerState = std::make_unique<LayerState>(&mOutputLayer);
938 EXPECT_FALSE(mLayerState->hasBlurBehind());
939 }
940
TEST_F(LayerStateTest,hasBlurBehind_withBackgroundBlur_returnsTrue)941 TEST_F(LayerStateTest, hasBlurBehind_withBackgroundBlur_returnsTrue) {
942 OutputLayerCompositionState outputLayerCompositionState;
943 LayerFECompositionState layerFECompositionState;
944 layerFECompositionState.backgroundBlurRadius = sBgBlurRadiusOne;
945 setupMocksForLayer(mOutputLayer, mLayerFE, outputLayerCompositionState,
946 layerFECompositionState);
947 mLayerState = std::make_unique<LayerState>(&mOutputLayer);
948 EXPECT_TRUE(mLayerState->hasBlurBehind());
949 }
950
TEST_F(LayerStateTest,hasBlurBehind_withBlurRegion_returnsTrue)951 TEST_F(LayerStateTest, hasBlurBehind_withBlurRegion_returnsTrue) {
952 OutputLayerCompositionState outputLayerCompositionState;
953 LayerFECompositionState layerFECompositionState;
954 layerFECompositionState.blurRegions.push_back(sBlurRegionOne);
955 setupMocksForLayer(mOutputLayer, mLayerFE, outputLayerCompositionState,
956 layerFECompositionState);
957 mLayerState = std::make_unique<LayerState>(&mOutputLayer);
958 EXPECT_TRUE(mLayerState->hasBlurBehind());
959 }
960
TEST_F(LayerStateTest,dumpDoesNotCrash)961 TEST_F(LayerStateTest, dumpDoesNotCrash) {
962 OutputLayerCompositionState outputLayerCompositionState;
963 LayerFECompositionState layerFECompositionState;
964 setupMocksForLayer(mOutputLayer, mLayerFE, outputLayerCompositionState,
965 layerFECompositionState);
966 mLayerState = std::make_unique<LayerState>(&mOutputLayer);
967 std::string dump;
968 mLayerState->dump(dump);
969 EXPECT_TRUE(dump.size() > 0);
970 }
971
TEST_F(LayerStateTest,framesSinceBufferUpdate)972 TEST_F(LayerStateTest, framesSinceBufferUpdate) {
973 OutputLayerCompositionState outputLayerCompositionState;
974 LayerFECompositionState layerFECompositionState;
975 setupMocksForLayer(mOutputLayer, mLayerFE, outputLayerCompositionState,
976 layerFECompositionState);
977 mLayerState = std::make_unique<LayerState>(&mOutputLayer);
978
979 EXPECT_EQ(0, mLayerState->getFramesSinceBufferUpdate());
980 mLayerState->incrementFramesSinceBufferUpdate();
981 EXPECT_EQ(1, mLayerState->getFramesSinceBufferUpdate());
982 mLayerState->resetFramesSinceBufferUpdate();
983 EXPECT_EQ(0, mLayerState->getFramesSinceBufferUpdate());
984 }
985
TEST_F(LayerStateTest,getNonBufferHash_doesNotCommute)986 TEST_F(LayerStateTest, getNonBufferHash_doesNotCommute) {
987 OutputLayerCompositionState outputLayerCompositionState;
988 outputLayerCompositionState.displayFrame = sRectOne;
989 LayerFECompositionState layerFECompositionState;
990 setupMocksForLayer(mOutputLayer, mLayerFE, outputLayerCompositionState,
991 layerFECompositionState);
992 mLayerState = std::make_unique<LayerState>(&mOutputLayer);
993 mock::OutputLayer newOutputLayer;
994 mock::LayerFE newLayerFE;
995 OutputLayerCompositionState outputLayerCompositionStateTwo;
996 outputLayerCompositionStateTwo.displayFrame = sRectTwo;
997 setupMocksForLayer(newOutputLayer, newLayerFE, outputLayerCompositionStateTwo,
998 layerFECompositionState);
999 auto otherLayerState = std::make_unique<LayerState>(&newOutputLayer);
1000
1001 EXPECT_NE(getNonBufferHash({mLayerState.get(), otherLayerState.get()}),
1002 getNonBufferHash({otherLayerState.get(), mLayerState.get()}));
1003 }
1004
TEST_F(LayerStateTest,getNonBufferHash_isIdempotent)1005 TEST_F(LayerStateTest, getNonBufferHash_isIdempotent) {
1006 OutputLayerCompositionState outputLayerCompositionState;
1007 outputLayerCompositionState.displayFrame = sRectOne;
1008 LayerFECompositionState layerFECompositionState;
1009 setupMocksForLayer(mOutputLayer, mLayerFE, outputLayerCompositionState,
1010 layerFECompositionState);
1011 mLayerState = std::make_unique<LayerState>(&mOutputLayer);
1012 mock::OutputLayer newOutputLayer;
1013 mock::LayerFE newLayerFE;
1014 OutputLayerCompositionState outputLayerCompositionStateTwo;
1015 outputLayerCompositionStateTwo.displayFrame = sRectTwo;
1016 setupMocksForLayer(newOutputLayer, newLayerFE, outputLayerCompositionStateTwo,
1017 layerFECompositionState);
1018 auto otherLayerState = std::make_unique<LayerState>(&newOutputLayer);
1019
1020 EXPECT_EQ(getNonBufferHash({mLayerState.get(), otherLayerState.get()}),
1021 getNonBufferHash({mLayerState.get(), otherLayerState.get()}));
1022 }
1023
TEST_F(LayerStateTest,getNonBufferHash_filtersOutBuffers)1024 TEST_F(LayerStateTest, getNonBufferHash_filtersOutBuffers) {
1025 OutputLayerCompositionState outputLayerCompositionState;
1026 LayerFECompositionState layerFECompositionState;
1027 layerFECompositionState.buffer = new GraphicBuffer();
1028 setupMocksForLayer(mOutputLayer, mLayerFE, outputLayerCompositionState,
1029 layerFECompositionState);
1030 mLayerState = std::make_unique<LayerState>(&mOutputLayer);
1031
1032 mock::OutputLayer newOutputLayer;
1033 mock::LayerFE newLayerFE;
1034 LayerFECompositionState layerFECompositionStateTwo;
1035 layerFECompositionStateTwo.buffer = new GraphicBuffer();
1036 setupMocksForLayer(newOutputLayer, newLayerFE, outputLayerCompositionState,
1037 layerFECompositionStateTwo);
1038 auto otherLayerState = std::make_unique<LayerState>(&newOutputLayer);
1039
1040 EXPECT_EQ(getNonBufferHash({mLayerState.get()}), getNonBufferHash({otherLayerState.get()}));
1041 }
1042
1043 } // namespace
1044 } // namespace android::compositionengine::impl::planner
1045