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