| Alec Mouri | eb920d9 | 2021-03-01 17:48:30 -0800 | [diff] [blame] | 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 | namespace android::compositionengine::impl::planner { |
| 28 | namespace { |
| 29 | |
| 30 | using testing::Return; |
| 31 | using testing::ReturnRef; |
| 32 | |
| 33 | const std::string sDebugName = std::string("Test LayerFE"); |
| 34 | const std::string sDebugNameTwo = std::string("Test LayerFE2"); |
| 35 | const constexpr int32_t sSequenceId = 12345; |
| 36 | const constexpr int32_t sSequenceIdTwo = 123456; |
| 37 | const Rect sRectOne = Rect(10, 20, 30, 40); |
| 38 | const Rect sRectTwo = Rect(40, 30, 20, 10); |
| 39 | const FloatRect sFloatRectOne = FloatRect(100.f, 200.f, 300.f, 400.f); |
| 40 | const FloatRect sFloatRectTwo = FloatRect(400.f, 300.f, 200.f, 100.f); |
| 41 | const constexpr int32_t sZOne = 100; |
| 42 | const constexpr int32_t sZTwo = 101; |
| 43 | const constexpr float sAlphaOne = 0.25f; |
| 44 | const constexpr float sAlphaTwo = 0.5f; |
| 45 | const Region sRegionOne = Region(sRectOne); |
| 46 | const Region sRegionTwo = Region(sRectTwo); |
| 47 | const mat4 sMat4One = mat4::scale(vec4(2.f, 3.f, 1.f, 1.f)); |
| 48 | native_handle_t* const sFakeSidebandStreamOne = reinterpret_cast<native_handle_t*>(10); |
| 49 | native_handle_t* const sFakeSidebandStreamTwo = reinterpret_cast<native_handle_t*>(11); |
| 50 | const half4 sHalf4One = half4(0.2f, 0.3f, 0.4f, 0.5f); |
| 51 | const half4 sHalf4Two = half4(0.5f, 0.4f, 0.43, 0.2f); |
| 52 | |
| 53 | struct 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 | |
| 83 | TEST_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 | |
| 92 | TEST_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 | |
| 101 | TEST_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 | |
| 117 | TEST_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 Mouri | a19a896 | 2021-03-30 14:19:31 -0700 | [diff] [blame] | 132 | EXPECT_EQ(mLayerState->getHash(), otherLayerState->getHash()); |
| Alec Mouri | eb920d9 | 2021-03-01 17:48:30 -0800 | [diff] [blame] | 133 | |
| 134 | // Similarly, Id cannot be included in differing fields. |
| 135 | EXPECT_EQ(Flags<LayerStateField>(LayerStateField::None), |
| Alec Mouri | a19a896 | 2021-03-30 14:19:31 -0700 | [diff] [blame] | 136 | mLayerState->getDifferingFields(*otherLayerState)); |
| Alec Mouri | eb920d9 | 2021-03-01 17:48:30 -0800 | [diff] [blame] | 137 | EXPECT_EQ(Flags<LayerStateField>(LayerStateField::None), |
| Alec Mouri | a19a896 | 2021-03-30 14:19:31 -0700 | [diff] [blame] | 138 | otherLayerState->getDifferingFields(*mLayerState)); |
| Alec Mouri | eb920d9 | 2021-03-01 17:48:30 -0800 | [diff] [blame] | 139 | |
| 140 | EXPECT_FALSE(mLayerState->compare(*otherLayerState)); |
| 141 | EXPECT_FALSE(otherLayerState->compare(*mLayerState)); |
| 142 | } |
| 143 | |
| 144 | TEST_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 | |
| 153 | TEST_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 | |
| 169 | TEST_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 Mouri | a19a896 | 2021-03-30 14:19:31 -0700 | [diff] [blame] | 184 | EXPECT_EQ(mLayerState->getHash(), otherLayerState->getHash()); |
| Alec Mouri | eb920d9 | 2021-03-01 17:48:30 -0800 | [diff] [blame] | 185 | |
| 186 | // Similarly, Name cannot be included in differing fields. |
| 187 | EXPECT_EQ(Flags<LayerStateField>(LayerStateField::None), |
| Alec Mouri | a19a896 | 2021-03-30 14:19:31 -0700 | [diff] [blame] | 188 | mLayerState->getDifferingFields(*otherLayerState)); |
| Alec Mouri | eb920d9 | 2021-03-01 17:48:30 -0800 | [diff] [blame] | 189 | EXPECT_EQ(Flags<LayerStateField>(LayerStateField::None), |
| Alec Mouri | a19a896 | 2021-03-30 14:19:31 -0700 | [diff] [blame] | 190 | otherLayerState->getDifferingFields(*mLayerState)); |
| Alec Mouri | eb920d9 | 2021-03-01 17:48:30 -0800 | [diff] [blame] | 191 | |
| 192 | EXPECT_FALSE(mLayerState->compare(*otherLayerState)); |
| 193 | EXPECT_FALSE(otherLayerState->compare(*mLayerState)); |
| 194 | } |
| 195 | |
| 196 | TEST_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 | |
| 206 | TEST_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 | |
| 225 | TEST_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 Mouri | a19a896 | 2021-03-30 14:19:31 -0700 | [diff] [blame] | 242 | EXPECT_NE(mLayerState->getHash(), otherLayerState->getHash()); |
| Alec Mouri | eb920d9 | 2021-03-01 17:48:30 -0800 | [diff] [blame] | 243 | |
| 244 | EXPECT_EQ(Flags<LayerStateField>(LayerStateField::DisplayFrame), |
| Alec Mouri | a19a896 | 2021-03-30 14:19:31 -0700 | [diff] [blame] | 245 | mLayerState->getDifferingFields(*otherLayerState)); |
| Alec Mouri | eb920d9 | 2021-03-01 17:48:30 -0800 | [diff] [blame] | 246 | EXPECT_EQ(Flags<LayerStateField>(LayerStateField::DisplayFrame), |
| Alec Mouri | a19a896 | 2021-03-30 14:19:31 -0700 | [diff] [blame] | 247 | otherLayerState->getDifferingFields(*mLayerState)); |
| Alec Mouri | eb920d9 | 2021-03-01 17:48:30 -0800 | [diff] [blame] | 248 | |
| 249 | EXPECT_TRUE(mLayerState->compare(*otherLayerState)); |
| 250 | EXPECT_TRUE(otherLayerState->compare(*mLayerState)); |
| 251 | } |
| 252 | |
| 253 | TEST_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 | |
| 265 | TEST_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 | |
| 278 | TEST_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 | |
| 300 | TEST_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 Mouri | a19a896 | 2021-03-30 14:19:31 -0700 | [diff] [blame] | 319 | EXPECT_NE(mLayerState->getHash(), otherLayerState->getHash()); |
| Alec Mouri | eb920d9 | 2021-03-01 17:48:30 -0800 | [diff] [blame] | 320 | |
| 321 | EXPECT_EQ(Flags<LayerStateField>(LayerStateField::CompositionType), |
| Alec Mouri | a19a896 | 2021-03-30 14:19:31 -0700 | [diff] [blame] | 322 | mLayerState->getDifferingFields(*otherLayerState)); |
| Alec Mouri | eb920d9 | 2021-03-01 17:48:30 -0800 | [diff] [blame] | 323 | EXPECT_EQ(Flags<LayerStateField>(LayerStateField::CompositionType), |
| Alec Mouri | a19a896 | 2021-03-30 14:19:31 -0700 | [diff] [blame] | 324 | otherLayerState->getDifferingFields(*mLayerState)); |
| Alec Mouri | eb920d9 | 2021-03-01 17:48:30 -0800 | [diff] [blame] | 325 | |
| 326 | EXPECT_TRUE(mLayerState->compare(*otherLayerState)); |
| 327 | EXPECT_TRUE(otherLayerState->compare(*mLayerState)); |
| 328 | } |
| 329 | |
| Alec Mouri | eb920d9 | 2021-03-01 17:48:30 -0800 | [diff] [blame] | 330 | TEST_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 Mouri | eb920d9 | 2021-03-01 17:48:30 -0800 | [diff] [blame] | 345 | EXPECT_EQ(Flags<LayerStateField>(LayerStateField::Buffer), updates); |
| 346 | } |
| 347 | |
| 348 | TEST_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 Mouri | a19a896 | 2021-03-30 14:19:31 -0700 | [diff] [blame] | 363 | // Buffers are not included in differing fields or in hashes. |
| 364 | EXPECT_EQ(mLayerState->getHash(), otherLayerState->getHash()); |
| Alec Mouri | eb920d9 | 2021-03-01 17:48:30 -0800 | [diff] [blame] | 365 | EXPECT_EQ(Flags<LayerStateField>(LayerStateField::None), |
| Alec Mouri | a19a896 | 2021-03-30 14:19:31 -0700 | [diff] [blame] | 366 | mLayerState->getDifferingFields(*otherLayerState)); |
| Alec Mouri | eb920d9 | 2021-03-01 17:48:30 -0800 | [diff] [blame] | 367 | EXPECT_EQ(Flags<LayerStateField>(LayerStateField::None), |
| Alec Mouri | a19a896 | 2021-03-30 14:19:31 -0700 | [diff] [blame] | 368 | otherLayerState->getDifferingFields(*mLayerState)); |
| Alec Mouri | eb920d9 | 2021-03-01 17:48:30 -0800 | [diff] [blame] | 369 | |
| 370 | // Buffers are explicitly excluded from comparison |
| 371 | EXPECT_FALSE(mLayerState->compare(*otherLayerState)); |
| 372 | EXPECT_FALSE(otherLayerState->compare(*mLayerState)); |
| 373 | } |
| 374 | |
| 375 | TEST_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 | |
| 393 | TEST_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 Mouri | a19a896 | 2021-03-30 14:19:31 -0700 | [diff] [blame] | 408 | EXPECT_NE(mLayerState->getHash(), otherLayerState->getHash()); |
| Alec Mouri | eb920d9 | 2021-03-01 17:48:30 -0800 | [diff] [blame] | 409 | |
| 410 | EXPECT_EQ(Flags<LayerStateField>(LayerStateField::SourceCrop), |
| Alec Mouri | a19a896 | 2021-03-30 14:19:31 -0700 | [diff] [blame] | 411 | mLayerState->getDifferingFields(*otherLayerState)); |
| Alec Mouri | eb920d9 | 2021-03-01 17:48:30 -0800 | [diff] [blame] | 412 | EXPECT_EQ(Flags<LayerStateField>(LayerStateField::SourceCrop), |
| Alec Mouri | a19a896 | 2021-03-30 14:19:31 -0700 | [diff] [blame] | 413 | otherLayerState->getDifferingFields(*mLayerState)); |
| Alec Mouri | eb920d9 | 2021-03-01 17:48:30 -0800 | [diff] [blame] | 414 | |
| 415 | EXPECT_TRUE(mLayerState->compare(*otherLayerState)); |
| 416 | EXPECT_TRUE(otherLayerState->compare(*mLayerState)); |
| 417 | } |
| 418 | |
| 419 | TEST_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 | |
| 437 | TEST_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 Mouri | a19a896 | 2021-03-30 14:19:31 -0700 | [diff] [blame] | 452 | EXPECT_NE(mLayerState->getHash(), otherLayerState->getHash()); |
| Alec Mouri | eb920d9 | 2021-03-01 17:48:30 -0800 | [diff] [blame] | 453 | |
| 454 | EXPECT_EQ(Flags<LayerStateField>(LayerStateField::ZOrder), |
| Alec Mouri | a19a896 | 2021-03-30 14:19:31 -0700 | [diff] [blame] | 455 | mLayerState->getDifferingFields(*otherLayerState)); |
| Alec Mouri | eb920d9 | 2021-03-01 17:48:30 -0800 | [diff] [blame] | 456 | EXPECT_EQ(Flags<LayerStateField>(LayerStateField::ZOrder), |
| Alec Mouri | a19a896 | 2021-03-30 14:19:31 -0700 | [diff] [blame] | 457 | otherLayerState->getDifferingFields(*mLayerState)); |
| Alec Mouri | eb920d9 | 2021-03-01 17:48:30 -0800 | [diff] [blame] | 458 | |
| 459 | EXPECT_TRUE(mLayerState->compare(*otherLayerState)); |
| 460 | EXPECT_TRUE(otherLayerState->compare(*mLayerState)); |
| 461 | } |
| 462 | |
| 463 | TEST_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 | |
| 481 | TEST_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 Mouri | a19a896 | 2021-03-30 14:19:31 -0700 | [diff] [blame] | 496 | EXPECT_NE(mLayerState->getHash(), otherLayerState->getHash()); |
| Alec Mouri | eb920d9 | 2021-03-01 17:48:30 -0800 | [diff] [blame] | 497 | |
| 498 | EXPECT_EQ(Flags<LayerStateField>(LayerStateField::BufferTransform), |
| Alec Mouri | a19a896 | 2021-03-30 14:19:31 -0700 | [diff] [blame] | 499 | mLayerState->getDifferingFields(*otherLayerState)); |
| Alec Mouri | eb920d9 | 2021-03-01 17:48:30 -0800 | [diff] [blame] | 500 | EXPECT_EQ(Flags<LayerStateField>(LayerStateField::BufferTransform), |
| Alec Mouri | a19a896 | 2021-03-30 14:19:31 -0700 | [diff] [blame] | 501 | otherLayerState->getDifferingFields(*mLayerState)); |
| Alec Mouri | eb920d9 | 2021-03-01 17:48:30 -0800 | [diff] [blame] | 502 | |
| 503 | EXPECT_TRUE(mLayerState->compare(*otherLayerState)); |
| 504 | EXPECT_TRUE(otherLayerState->compare(*mLayerState)); |
| 505 | } |
| 506 | |
| 507 | TEST_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 | |
| 525 | TEST_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 Mouri | a19a896 | 2021-03-30 14:19:31 -0700 | [diff] [blame] | 540 | EXPECT_NE(mLayerState->getHash(), otherLayerState->getHash()); |
| Alec Mouri | eb920d9 | 2021-03-01 17:48:30 -0800 | [diff] [blame] | 541 | |
| 542 | EXPECT_EQ(Flags<LayerStateField>(LayerStateField::BlendMode), |
| Alec Mouri | a19a896 | 2021-03-30 14:19:31 -0700 | [diff] [blame] | 543 | mLayerState->getDifferingFields(*otherLayerState)); |
| Alec Mouri | eb920d9 | 2021-03-01 17:48:30 -0800 | [diff] [blame] | 544 | EXPECT_EQ(Flags<LayerStateField>(LayerStateField::BlendMode), |
| Alec Mouri | a19a896 | 2021-03-30 14:19:31 -0700 | [diff] [blame] | 545 | otherLayerState->getDifferingFields(*mLayerState)); |
| Alec Mouri | eb920d9 | 2021-03-01 17:48:30 -0800 | [diff] [blame] | 546 | |
| 547 | EXPECT_TRUE(mLayerState->compare(*otherLayerState)); |
| 548 | EXPECT_TRUE(otherLayerState->compare(*mLayerState)); |
| 549 | } |
| 550 | |
| 551 | TEST_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 | |
| 569 | TEST_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 Mouri | a19a896 | 2021-03-30 14:19:31 -0700 | [diff] [blame] | 584 | EXPECT_NE(mLayerState->getHash(), otherLayerState->getHash()); |
| Alec Mouri | eb920d9 | 2021-03-01 17:48:30 -0800 | [diff] [blame] | 585 | |
| 586 | EXPECT_EQ(Flags<LayerStateField>(LayerStateField::Alpha), |
| Alec Mouri | a19a896 | 2021-03-30 14:19:31 -0700 | [diff] [blame] | 587 | mLayerState->getDifferingFields(*otherLayerState)); |
| Alec Mouri | eb920d9 | 2021-03-01 17:48:30 -0800 | [diff] [blame] | 588 | EXPECT_EQ(Flags<LayerStateField>(LayerStateField::Alpha), |
| Alec Mouri | a19a896 | 2021-03-30 14:19:31 -0700 | [diff] [blame] | 589 | otherLayerState->getDifferingFields(*mLayerState)); |
| Alec Mouri | eb920d9 | 2021-03-01 17:48:30 -0800 | [diff] [blame] | 590 | |
| 591 | EXPECT_TRUE(mLayerState->compare(*otherLayerState)); |
| 592 | EXPECT_TRUE(otherLayerState->compare(*mLayerState)); |
| 593 | } |
| 594 | |
| Alec Mouri | 464352b | 2021-03-24 16:33:21 -0700 | [diff] [blame^] | 595 | TEST_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 Mouri | eb920d9 | 2021-03-01 17:48:30 -0800 | [diff] [blame] | 605 | TEST_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 | |
| 623 | TEST_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 Mouri | a19a896 | 2021-03-30 14:19:31 -0700 | [diff] [blame] | 638 | EXPECT_NE(mLayerState->getHash(), otherLayerState->getHash()); |
| Alec Mouri | eb920d9 | 2021-03-01 17:48:30 -0800 | [diff] [blame] | 639 | |
| 640 | EXPECT_EQ(Flags<LayerStateField>(LayerStateField::VisibleRegion), |
| Alec Mouri | a19a896 | 2021-03-30 14:19:31 -0700 | [diff] [blame] | 641 | mLayerState->getDifferingFields(*otherLayerState)); |
| Alec Mouri | eb920d9 | 2021-03-01 17:48:30 -0800 | [diff] [blame] | 642 | EXPECT_EQ(Flags<LayerStateField>(LayerStateField::VisibleRegion), |
| Alec Mouri | a19a896 | 2021-03-30 14:19:31 -0700 | [diff] [blame] | 643 | otherLayerState->getDifferingFields(*mLayerState)); |
| Alec Mouri | eb920d9 | 2021-03-01 17:48:30 -0800 | [diff] [blame] | 644 | |
| 645 | EXPECT_TRUE(mLayerState->compare(*otherLayerState)); |
| 646 | EXPECT_TRUE(otherLayerState->compare(*mLayerState)); |
| 647 | } |
| 648 | |
| 649 | TEST_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 | |
| 667 | TEST_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 Mouri | a19a896 | 2021-03-30 14:19:31 -0700 | [diff] [blame] | 682 | EXPECT_NE(mLayerState->getHash(), otherLayerState->getHash()); |
| Alec Mouri | eb920d9 | 2021-03-01 17:48:30 -0800 | [diff] [blame] | 683 | |
| 684 | EXPECT_EQ(Flags<LayerStateField>(LayerStateField::Dataspace), |
| Alec Mouri | a19a896 | 2021-03-30 14:19:31 -0700 | [diff] [blame] | 685 | mLayerState->getDifferingFields(*otherLayerState)); |
| Alec Mouri | eb920d9 | 2021-03-01 17:48:30 -0800 | [diff] [blame] | 686 | EXPECT_EQ(Flags<LayerStateField>(LayerStateField::Dataspace), |
| Alec Mouri | a19a896 | 2021-03-30 14:19:31 -0700 | [diff] [blame] | 687 | otherLayerState->getDifferingFields(*mLayerState)); |
| Alec Mouri | eb920d9 | 2021-03-01 17:48:30 -0800 | [diff] [blame] | 688 | |
| 689 | EXPECT_TRUE(mLayerState->compare(*otherLayerState)); |
| 690 | EXPECT_TRUE(otherLayerState->compare(*mLayerState)); |
| 691 | } |
| 692 | |
| 693 | TEST_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 | |
| 713 | TEST_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 Mouri | a19a896 | 2021-03-30 14:19:31 -0700 | [diff] [blame] | 730 | EXPECT_NE(mLayerState->getHash(), otherLayerState->getHash()); |
| Alec Mouri | eb920d9 | 2021-03-01 17:48:30 -0800 | [diff] [blame] | 731 | |
| 732 | EXPECT_EQ(Flags<LayerStateField>(LayerStateField::ColorTransform), |
| Alec Mouri | a19a896 | 2021-03-30 14:19:31 -0700 | [diff] [blame] | 733 | mLayerState->getDifferingFields(*otherLayerState)); |
| Alec Mouri | eb920d9 | 2021-03-01 17:48:30 -0800 | [diff] [blame] | 734 | EXPECT_EQ(Flags<LayerStateField>(LayerStateField::ColorTransform), |
| Alec Mouri | a19a896 | 2021-03-30 14:19:31 -0700 | [diff] [blame] | 735 | otherLayerState->getDifferingFields(*mLayerState)); |
| Alec Mouri | eb920d9 | 2021-03-01 17:48:30 -0800 | [diff] [blame] | 736 | |
| 737 | EXPECT_TRUE(mLayerState->compare(*otherLayerState)); |
| 738 | EXPECT_TRUE(otherLayerState->compare(*mLayerState)); |
| 739 | } |
| 740 | |
| 741 | TEST_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 | |
| 759 | TEST_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 Mouri | a19a896 | 2021-03-30 14:19:31 -0700 | [diff] [blame] | 774 | EXPECT_NE(mLayerState->getHash(), otherLayerState->getHash()); |
| Alec Mouri | eb920d9 | 2021-03-01 17:48:30 -0800 | [diff] [blame] | 775 | |
| 776 | EXPECT_EQ(Flags<LayerStateField>(LayerStateField::SidebandStream), |
| Alec Mouri | a19a896 | 2021-03-30 14:19:31 -0700 | [diff] [blame] | 777 | mLayerState->getDifferingFields(*otherLayerState)); |
| Alec Mouri | eb920d9 | 2021-03-01 17:48:30 -0800 | [diff] [blame] | 778 | EXPECT_EQ(Flags<LayerStateField>(LayerStateField::SidebandStream), |
| Alec Mouri | a19a896 | 2021-03-30 14:19:31 -0700 | [diff] [blame] | 779 | otherLayerState->getDifferingFields(*mLayerState)); |
| Alec Mouri | eb920d9 | 2021-03-01 17:48:30 -0800 | [diff] [blame] | 780 | |
| 781 | EXPECT_TRUE(mLayerState->compare(*otherLayerState)); |
| 782 | EXPECT_TRUE(otherLayerState->compare(*mLayerState)); |
| 783 | } |
| 784 | |
| 785 | TEST_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 | |
| 803 | TEST_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 Mouri | a19a896 | 2021-03-30 14:19:31 -0700 | [diff] [blame] | 818 | EXPECT_NE(mLayerState->getHash(), otherLayerState->getHash()); |
| Alec Mouri | eb920d9 | 2021-03-01 17:48:30 -0800 | [diff] [blame] | 819 | |
| 820 | EXPECT_EQ(Flags<LayerStateField>(LayerStateField::SolidColor), |
| Alec Mouri | a19a896 | 2021-03-30 14:19:31 -0700 | [diff] [blame] | 821 | mLayerState->getDifferingFields(*otherLayerState)); |
| Alec Mouri | eb920d9 | 2021-03-01 17:48:30 -0800 | [diff] [blame] | 822 | EXPECT_EQ(Flags<LayerStateField>(LayerStateField::SolidColor), |
| Alec Mouri | a19a896 | 2021-03-30 14:19:31 -0700 | [diff] [blame] | 823 | otherLayerState->getDifferingFields(*mLayerState)); |
| Alec Mouri | eb920d9 | 2021-03-01 17:48:30 -0800 | [diff] [blame] | 824 | |
| 825 | EXPECT_TRUE(mLayerState->compare(*otherLayerState)); |
| 826 | EXPECT_TRUE(otherLayerState->compare(*mLayerState)); |
| 827 | } |
| 828 | |
| 829 | TEST_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 | |
| 840 | TEST_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 | |
| 854 | TEST_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 | |
| 873 | TEST_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 | |
| 892 | TEST_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 |