Vishnu Nair | 8fc721b | 2022-12-22 20:06:32 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2022 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 | #include <gmock/gmock.h> |
| 18 | #include <gtest/gtest.h> |
| 19 | |
Vishnu Nair | 8fc721b | 2022-12-22 20:06:32 +0000 | [diff] [blame] | 20 | #include "FrontEnd/LayerHierarchy.h" |
| 21 | #include "FrontEnd/LayerLifecycleManager.h" |
| 22 | #include "FrontEnd/LayerSnapshotBuilder.h" |
Vishnu Nair | 3d8565a | 2023-06-30 07:23:24 +0000 | [diff] [blame] | 23 | #include "Layer.h" |
Vishnu Nair | 8fc721b | 2022-12-22 20:06:32 +0000 | [diff] [blame] | 24 | #include "LayerHierarchyTest.h" |
| 25 | |
| 26 | #define UPDATE_AND_VERIFY(BUILDER, ...) \ |
| 27 | ({ \ |
| 28 | SCOPED_TRACE(""); \ |
| 29 | updateAndVerify((BUILDER), /*displayChanges=*/false, __VA_ARGS__); \ |
| 30 | }) |
| 31 | |
| 32 | #define UPDATE_AND_VERIFY_WITH_DISPLAY_CHANGES(BUILDER, ...) \ |
| 33 | ({ \ |
| 34 | SCOPED_TRACE(""); \ |
| 35 | updateAndVerify((BUILDER), /*displayChanges=*/true, __VA_ARGS__); \ |
| 36 | }) |
| 37 | |
| 38 | namespace android::surfaceflinger::frontend { |
| 39 | |
Vishnu Nair | cfb2d25 | 2023-01-19 04:44:02 +0000 | [diff] [blame] | 40 | using ftl::Flags; |
| 41 | using namespace ftl::flag_operators; |
| 42 | |
Vishnu Nair | 8fc721b | 2022-12-22 20:06:32 +0000 | [diff] [blame] | 43 | // To run test: |
| 44 | /** |
| 45 | mp :libsurfaceflinger_unittest && adb sync; adb shell \ |
| 46 | /data/nativetest/libsurfaceflinger_unittest/libsurfaceflinger_unittest \ |
| 47 | --gtest_filter="LayerSnapshotTest.*" --gtest_brief=1 |
| 48 | */ |
| 49 | |
| 50 | class LayerSnapshotTest : public LayerHierarchyTestBase { |
| 51 | protected: |
| 52 | LayerSnapshotTest() : LayerHierarchyTestBase() { |
| 53 | UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER); |
| 54 | } |
| 55 | |
| 56 | void createRootLayer(uint32_t id) override { |
| 57 | LayerHierarchyTestBase::createRootLayer(id); |
| 58 | setColor(id); |
| 59 | } |
| 60 | |
| 61 | void createLayer(uint32_t id, uint32_t parentId) override { |
| 62 | LayerHierarchyTestBase::createLayer(id, parentId); |
| 63 | setColor(parentId); |
| 64 | } |
| 65 | |
| 66 | void mirrorLayer(uint32_t id, uint32_t parent, uint32_t layerToMirror) override { |
| 67 | LayerHierarchyTestBase::mirrorLayer(id, parent, layerToMirror); |
| 68 | setColor(id); |
| 69 | } |
| 70 | |
| 71 | void updateAndVerify(LayerSnapshotBuilder& actualBuilder, bool hasDisplayChanges, |
| 72 | const std::vector<uint32_t> expectedVisibleLayerIdsInZOrder) { |
| 73 | if (mLifecycleManager.getGlobalChanges().test(RequestedLayerState::Changes::Hierarchy)) { |
| 74 | mHierarchyBuilder.update(mLifecycleManager.getLayers(), |
| 75 | mLifecycleManager.getDestroyedLayers()); |
| 76 | } |
Vishnu Nair | c765c6c | 2023-02-23 00:08:01 +0000 | [diff] [blame] | 77 | LayerSnapshotBuilder::Args args{.root = mHierarchyBuilder.getHierarchy(), |
| 78 | .layerLifecycleManager = mLifecycleManager, |
| 79 | .includeMetadata = false, |
| 80 | .displays = mFrontEndDisplayInfos, |
| 81 | .displayChanges = hasDisplayChanges, |
| 82 | .globalShadowSettings = globalShadowSettings, |
Vishnu Nair | 444f395 | 2023-04-11 13:01:02 -0700 | [diff] [blame] | 83 | .supportsBlur = true, |
Vishnu Nair | c765c6c | 2023-02-23 00:08:01 +0000 | [diff] [blame] | 84 | .supportedLayerGenericMetadata = {}, |
| 85 | .genericLayerMetadataKeyMap = {}}; |
Vishnu Nair | 8fc721b | 2022-12-22 20:06:32 +0000 | [diff] [blame] | 86 | actualBuilder.update(args); |
| 87 | |
| 88 | // rebuild layer snapshots from scratch and verify that it matches the updated state. |
| 89 | LayerSnapshotBuilder expectedBuilder(args); |
| 90 | mLifecycleManager.commitChanges(); |
| 91 | ASSERT_TRUE(expectedBuilder.getSnapshots().size() > 0); |
| 92 | ASSERT_TRUE(actualBuilder.getSnapshots().size() > 0); |
| 93 | |
Vishnu Nair | 8fc721b | 2022-12-22 20:06:32 +0000 | [diff] [blame] | 94 | std::vector<uint32_t> actualVisibleLayerIdsInZOrder; |
Vishnu Nair | cfb2d25 | 2023-01-19 04:44:02 +0000 | [diff] [blame] | 95 | actualBuilder.forEachVisibleSnapshot( |
| 96 | [&actualVisibleLayerIdsInZOrder](const LayerSnapshot& snapshot) { |
| 97 | actualVisibleLayerIdsInZOrder.push_back(snapshot.path.id); |
| 98 | }); |
Vishnu Nair | 8fc721b | 2022-12-22 20:06:32 +0000 | [diff] [blame] | 99 | EXPECT_EQ(expectedVisibleLayerIdsInZOrder, actualVisibleLayerIdsInZOrder); |
| 100 | } |
| 101 | |
| 102 | LayerSnapshot* getSnapshot(uint32_t layerId) { return mSnapshotBuilder.getSnapshot(layerId); } |
Vishnu Nair | 92990e2 | 2023-02-24 20:01:05 +0000 | [diff] [blame] | 103 | LayerSnapshot* getSnapshot(const LayerHierarchy::TraversalPath path) { |
| 104 | return mSnapshotBuilder.getSnapshot(path); |
| 105 | } |
Vishnu Nair | 8fc721b | 2022-12-22 20:06:32 +0000 | [diff] [blame] | 106 | |
| 107 | LayerHierarchyBuilder mHierarchyBuilder{{}}; |
| 108 | LayerSnapshotBuilder mSnapshotBuilder; |
Dominik Laskowski | 6b049ff | 2023-01-29 15:46:45 -0500 | [diff] [blame] | 109 | DisplayInfos mFrontEndDisplayInfos; |
Vishnu Nair | 8fc721b | 2022-12-22 20:06:32 +0000 | [diff] [blame] | 110 | renderengine::ShadowSettings globalShadowSettings; |
| 111 | static const std::vector<uint32_t> STARTING_ZORDER; |
| 112 | }; |
| 113 | const std::vector<uint32_t> LayerSnapshotTest::STARTING_ZORDER = {1, 11, 111, 12, 121, |
| 114 | 122, 1221, 13, 2}; |
| 115 | |
| 116 | TEST_F(LayerSnapshotTest, buildSnapshot) { |
Vishnu Nair | c765c6c | 2023-02-23 00:08:01 +0000 | [diff] [blame] | 117 | LayerSnapshotBuilder::Args args{.root = mHierarchyBuilder.getHierarchy(), |
| 118 | .layerLifecycleManager = mLifecycleManager, |
| 119 | .includeMetadata = false, |
| 120 | .displays = mFrontEndDisplayInfos, |
| 121 | .globalShadowSettings = globalShadowSettings, |
| 122 | .supportedLayerGenericMetadata = {}, |
| 123 | .genericLayerMetadataKeyMap = {}}; |
Vishnu Nair | 8fc721b | 2022-12-22 20:06:32 +0000 | [diff] [blame] | 124 | LayerSnapshotBuilder builder(args); |
| 125 | } |
| 126 | |
| 127 | TEST_F(LayerSnapshotTest, updateSnapshot) { |
Vishnu Nair | c765c6c | 2023-02-23 00:08:01 +0000 | [diff] [blame] | 128 | LayerSnapshotBuilder::Args args{.root = mHierarchyBuilder.getHierarchy(), |
| 129 | .layerLifecycleManager = mLifecycleManager, |
| 130 | .includeMetadata = false, |
| 131 | .displays = mFrontEndDisplayInfos, |
| 132 | .globalShadowSettings = globalShadowSettings, |
| 133 | .supportedLayerGenericMetadata = {}, |
| 134 | .genericLayerMetadataKeyMap = {} |
| 135 | |
Vishnu Nair | 8fc721b | 2022-12-22 20:06:32 +0000 | [diff] [blame] | 136 | }; |
| 137 | |
| 138 | LayerSnapshotBuilder builder; |
| 139 | builder.update(args); |
| 140 | } |
| 141 | |
| 142 | // update using parent snapshot data |
| 143 | TEST_F(LayerSnapshotTest, croppedByParent) { |
| 144 | /// MAKE ALL LAYERS VISIBLE BY DEFAULT |
| 145 | DisplayInfo info; |
| 146 | info.info.logicalHeight = 100; |
| 147 | info.info.logicalWidth = 200; |
| 148 | mFrontEndDisplayInfos.emplace_or_replace(ui::LayerStack::fromValue(1), info); |
| 149 | Rect layerCrop(0, 0, 10, 20); |
| 150 | setCrop(11, layerCrop); |
| 151 | EXPECT_TRUE(mLifecycleManager.getGlobalChanges().test(RequestedLayerState::Changes::Geometry)); |
| 152 | UPDATE_AND_VERIFY_WITH_DISPLAY_CHANGES(mSnapshotBuilder, STARTING_ZORDER); |
| 153 | EXPECT_EQ(getSnapshot(11)->geomCrop, layerCrop); |
| 154 | EXPECT_EQ(getSnapshot(111)->geomLayerBounds, layerCrop.toFloatRect()); |
| 155 | float maxHeight = static_cast<float>(info.info.logicalHeight * 10); |
| 156 | float maxWidth = static_cast<float>(info.info.logicalWidth * 10); |
| 157 | |
| 158 | FloatRect maxDisplaySize(-maxWidth, -maxHeight, maxWidth, maxHeight); |
| 159 | EXPECT_EQ(getSnapshot(1)->geomLayerBounds, maxDisplaySize); |
| 160 | } |
| 161 | |
| 162 | // visibility tests |
| 163 | TEST_F(LayerSnapshotTest, newLayerHiddenByPolicy) { |
| 164 | createLayer(112, 11); |
| 165 | hideLayer(112); |
| 166 | UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER); |
| 167 | |
| 168 | showLayer(112); |
| 169 | UPDATE_AND_VERIFY(mSnapshotBuilder, {1, 11, 111, 112, 12, 121, 122, 1221, 13, 2}); |
| 170 | } |
| 171 | |
| 172 | TEST_F(LayerSnapshotTest, hiddenByParent) { |
| 173 | hideLayer(11); |
| 174 | UPDATE_AND_VERIFY(mSnapshotBuilder, {1, 12, 121, 122, 1221, 13, 2}); |
| 175 | } |
| 176 | |
| 177 | TEST_F(LayerSnapshotTest, reparentShowsChild) { |
| 178 | hideLayer(11); |
| 179 | UPDATE_AND_VERIFY(mSnapshotBuilder, {1, 12, 121, 122, 1221, 13, 2}); |
| 180 | |
| 181 | showLayer(11); |
| 182 | UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER); |
| 183 | } |
| 184 | |
| 185 | TEST_F(LayerSnapshotTest, reparentHidesChild) { |
| 186 | hideLayer(11); |
| 187 | UPDATE_AND_VERIFY(mSnapshotBuilder, {1, 12, 121, 122, 1221, 13, 2}); |
| 188 | |
| 189 | reparentLayer(121, 11); |
| 190 | UPDATE_AND_VERIFY(mSnapshotBuilder, {1, 12, 122, 1221, 13, 2}); |
| 191 | } |
| 192 | |
| 193 | TEST_F(LayerSnapshotTest, unHidingUpdatesSnapshot) { |
| 194 | hideLayer(11); |
| 195 | Rect crop(1, 2, 3, 4); |
| 196 | setCrop(111, crop); |
| 197 | UPDATE_AND_VERIFY(mSnapshotBuilder, {1, 12, 121, 122, 1221, 13, 2}); |
| 198 | |
| 199 | showLayer(11); |
| 200 | UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER); |
| 201 | EXPECT_EQ(getSnapshot(111)->geomLayerBounds, crop.toFloatRect()); |
| 202 | } |
| 203 | |
| 204 | TEST_F(LayerSnapshotTest, childBehindParentCanBeHiddenByParent) { |
| 205 | setZ(111, -1); |
| 206 | UPDATE_AND_VERIFY(mSnapshotBuilder, {1, 111, 11, 12, 121, 122, 1221, 13, 2}); |
| 207 | |
| 208 | hideLayer(11); |
| 209 | UPDATE_AND_VERIFY(mSnapshotBuilder, {1, 12, 121, 122, 1221, 13, 2}); |
| 210 | } |
| 211 | |
| 212 | // relative tests |
| 213 | TEST_F(LayerSnapshotTest, RelativeParentCanHideChild) { |
| 214 | reparentRelativeLayer(13, 11); |
| 215 | UPDATE_AND_VERIFY(mSnapshotBuilder, {1, 11, 13, 111, 12, 121, 122, 1221, 2}); |
| 216 | |
| 217 | hideLayer(11); |
| 218 | UPDATE_AND_VERIFY(mSnapshotBuilder, {1, 12, 121, 122, 1221, 2}); |
| 219 | } |
| 220 | |
| 221 | TEST_F(LayerSnapshotTest, ReparentingToHiddenRelativeParentHidesChild) { |
| 222 | hideLayer(11); |
| 223 | UPDATE_AND_VERIFY(mSnapshotBuilder, {1, 12, 121, 122, 1221, 13, 2}); |
| 224 | reparentRelativeLayer(13, 11); |
| 225 | UPDATE_AND_VERIFY(mSnapshotBuilder, {1, 12, 121, 122, 1221, 2}); |
| 226 | } |
| 227 | |
| 228 | TEST_F(LayerSnapshotTest, AlphaInheritedByChildren) { |
| 229 | setAlpha(1, 0.5); |
| 230 | setAlpha(122, 0.5); |
| 231 | UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER); |
Vishnu Nair | a02943f | 2023-06-03 13:44:46 -0700 | [diff] [blame] | 232 | EXPECT_EQ(getSnapshot(1)->alpha, 0.5f); |
Vishnu Nair | 8fc721b | 2022-12-22 20:06:32 +0000 | [diff] [blame] | 233 | EXPECT_EQ(getSnapshot(12)->alpha, 0.5f); |
| 234 | EXPECT_EQ(getSnapshot(1221)->alpha, 0.25f); |
| 235 | } |
| 236 | |
| 237 | // Change states |
| 238 | TEST_F(LayerSnapshotTest, UpdateClearsPreviousChangeStates) { |
| 239 | setCrop(1, Rect(1, 2, 3, 4)); |
| 240 | UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER); |
Vishnu Nair | a02943f | 2023-06-03 13:44:46 -0700 | [diff] [blame] | 241 | EXPECT_TRUE(getSnapshot(1)->changes.test(RequestedLayerState::Changes::Geometry)); |
| 242 | EXPECT_TRUE(getSnapshot(11)->changes.test(RequestedLayerState::Changes::Geometry)); |
Vishnu Nair | 8fc721b | 2022-12-22 20:06:32 +0000 | [diff] [blame] | 243 | setCrop(2, Rect(1, 2, 3, 4)); |
| 244 | UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER); |
Vishnu Nair | a02943f | 2023-06-03 13:44:46 -0700 | [diff] [blame] | 245 | EXPECT_TRUE(getSnapshot(2)->changes.test(RequestedLayerState::Changes::Geometry)); |
| 246 | EXPECT_FALSE(getSnapshot(1)->changes.test(RequestedLayerState::Changes::Geometry)); |
| 247 | EXPECT_FALSE(getSnapshot(11)->changes.test(RequestedLayerState::Changes::Geometry)); |
Vishnu Nair | 8fc721b | 2022-12-22 20:06:32 +0000 | [diff] [blame] | 248 | } |
| 249 | |
| 250 | TEST_F(LayerSnapshotTest, FastPathClearsPreviousChangeStates) { |
| 251 | setColor(11, {1._hf, 0._hf, 0._hf}); |
| 252 | UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER); |
Vishnu Nair | a02943f | 2023-06-03 13:44:46 -0700 | [diff] [blame] | 253 | EXPECT_EQ(getSnapshot(11)->changes, RequestedLayerState::Changes::Content); |
| 254 | EXPECT_EQ(getSnapshot(11)->clientChanges, layer_state_t::eColorChanged); |
| 255 | EXPECT_EQ(getSnapshot(1)->changes.get(), 0u); |
Vishnu Nair | 8fc721b | 2022-12-22 20:06:32 +0000 | [diff] [blame] | 256 | UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER); |
Vishnu Nair | a02943f | 2023-06-03 13:44:46 -0700 | [diff] [blame] | 257 | EXPECT_EQ(getSnapshot(11)->changes.get(), 0u); |
Vishnu Nair | 8fc721b | 2022-12-22 20:06:32 +0000 | [diff] [blame] | 258 | } |
| 259 | |
| 260 | TEST_F(LayerSnapshotTest, FastPathSetsChangeFlagToContent) { |
| 261 | setColor(1, {1._hf, 0._hf, 0._hf}); |
| 262 | UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER); |
| 263 | EXPECT_EQ(getSnapshot(1)->changes, RequestedLayerState::Changes::Content); |
Vishnu Nair | a02943f | 2023-06-03 13:44:46 -0700 | [diff] [blame] | 264 | EXPECT_EQ(getSnapshot(1)->clientChanges, layer_state_t::eColorChanged); |
Vishnu Nair | 8fc721b | 2022-12-22 20:06:32 +0000 | [diff] [blame] | 265 | } |
| 266 | |
Vishnu Nair | cfb2d25 | 2023-01-19 04:44:02 +0000 | [diff] [blame] | 267 | TEST_F(LayerSnapshotTest, GameMode) { |
| 268 | std::vector<TransactionState> transactions; |
| 269 | transactions.emplace_back(); |
| 270 | transactions.back().states.push_back({}); |
| 271 | transactions.back().states.front().state.what = layer_state_t::eMetadataChanged; |
| 272 | transactions.back().states.front().state.metadata = LayerMetadata(); |
| 273 | transactions.back().states.front().state.metadata.setInt32(METADATA_GAME_MODE, 42); |
Vishnu Nair | 1391de2 | 2023-03-05 19:56:14 -0800 | [diff] [blame] | 274 | transactions.back().states.front().layerId = 1; |
Vishnu Nair | cfb2d25 | 2023-01-19 04:44:02 +0000 | [diff] [blame] | 275 | transactions.back().states.front().state.layerId = static_cast<int32_t>(1); |
| 276 | mLifecycleManager.applyTransactions(transactions); |
Vishnu Nair | a02943f | 2023-06-03 13:44:46 -0700 | [diff] [blame] | 277 | EXPECT_EQ(mLifecycleManager.getGlobalChanges(), RequestedLayerState::Changes::GameMode); |
Vishnu Nair | cfb2d25 | 2023-01-19 04:44:02 +0000 | [diff] [blame] | 278 | UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER); |
Vishnu Nair | a02943f | 2023-06-03 13:44:46 -0700 | [diff] [blame] | 279 | EXPECT_EQ(getSnapshot(1)->clientChanges, layer_state_t::eMetadataChanged); |
Vishnu Nair | cfb2d25 | 2023-01-19 04:44:02 +0000 | [diff] [blame] | 280 | EXPECT_EQ(static_cast<int32_t>(getSnapshot(1)->gameMode), 42); |
| 281 | EXPECT_EQ(static_cast<int32_t>(getSnapshot(11)->gameMode), 42); |
| 282 | } |
| 283 | |
| 284 | TEST_F(LayerSnapshotTest, NoLayerVoteForParentWithChildVotes) { |
| 285 | // ROOT |
| 286 | // ├── 1 |
| 287 | // │ ├── 11 (frame rate set) |
| 288 | // │ │ └── 111 |
| 289 | // │ ├── 12 |
| 290 | // │ │ ├── 121 |
| 291 | // │ │ └── 122 |
| 292 | // │ │ └── 1221 |
| 293 | // │ └── 13 |
| 294 | // └── 2 |
| 295 | |
| 296 | std::vector<TransactionState> transactions; |
| 297 | transactions.emplace_back(); |
| 298 | transactions.back().states.push_back({}); |
| 299 | transactions.back().states.front().state.what = layer_state_t::eFrameRateChanged; |
| 300 | transactions.back().states.front().state.frameRate = 90.0; |
| 301 | transactions.back().states.front().state.frameRateCompatibility = |
| 302 | ANATIVEWINDOW_FRAME_RATE_EXACT; |
| 303 | transactions.back().states.front().state.changeFrameRateStrategy = |
| 304 | ANATIVEWINDOW_CHANGE_FRAME_RATE_ALWAYS; |
Vishnu Nair | 1391de2 | 2023-03-05 19:56:14 -0800 | [diff] [blame] | 305 | transactions.back().states.front().layerId = 11; |
Vishnu Nair | cfb2d25 | 2023-01-19 04:44:02 +0000 | [diff] [blame] | 306 | mLifecycleManager.applyTransactions(transactions); |
| 307 | UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER); |
| 308 | |
| 309 | EXPECT_EQ(getSnapshot(11)->frameRate.rate.getIntValue(), 90); |
| 310 | EXPECT_EQ(getSnapshot(11)->frameRate.type, scheduler::LayerInfo::FrameRateCompatibility::Exact); |
| 311 | EXPECT_EQ(getSnapshot(111)->frameRate.rate.getIntValue(), 90); |
| 312 | EXPECT_EQ(getSnapshot(111)->frameRate.type, |
| 313 | scheduler::LayerInfo::FrameRateCompatibility::Exact); |
| 314 | EXPECT_EQ(getSnapshot(1)->frameRate.rate.getIntValue(), 0); |
| 315 | EXPECT_EQ(getSnapshot(1)->frameRate.type, scheduler::LayerInfo::FrameRateCompatibility::NoVote); |
| 316 | } |
| 317 | |
Vishnu Nair | a02943f | 2023-06-03 13:44:46 -0700 | [diff] [blame] | 318 | TEST_F(LayerSnapshotTest, CanCropTouchableRegion) { |
Vishnu Nair | 29354ec | 2023-03-28 18:51:28 -0700 | [diff] [blame] | 319 | // ROOT |
| 320 | // ├── 1 |
| 321 | // │ ├── 11 |
| 322 | // │ │ └── 111 (touchregion set to touch but cropped by layer 13) |
| 323 | // │ ├── 12 |
| 324 | // │ │ ├── 121 |
| 325 | // │ │ └── 122 |
| 326 | // │ │ └── 1221 |
| 327 | // │ └── 13 (crop set to touchCrop) |
| 328 | // └── 2 |
| 329 | |
| 330 | Rect touchCrop{300, 300, 400, 500}; |
| 331 | setCrop(13, touchCrop); |
| 332 | Region touch{Rect{0, 0, 1000, 1000}}; |
| 333 | setTouchableRegionCrop(111, touch, /*touchCropId=*/13, /*replaceTouchableRegionWithCrop=*/true); |
| 334 | UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER); |
| 335 | EXPECT_EQ(getSnapshot({.id = 111})->inputInfo.touchableRegion.bounds(), touchCrop); |
| 336 | |
| 337 | Rect modifiedTouchCrop{100, 300, 400, 700}; |
| 338 | setCrop(13, modifiedTouchCrop); |
| 339 | UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER); |
| 340 | EXPECT_EQ(getSnapshot({.id = 111})->inputInfo.touchableRegion.bounds(), modifiedTouchCrop); |
| 341 | } |
| 342 | |
Vishnu Nair | 444f395 | 2023-04-11 13:01:02 -0700 | [diff] [blame] | 343 | TEST_F(LayerSnapshotTest, blurUpdatesWhenAlphaChanges) { |
| 344 | static constexpr int blurRadius = 42; |
| 345 | setBackgroundBlurRadius(1221, blurRadius); |
| 346 | |
| 347 | UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER); |
| 348 | EXPECT_EQ(getSnapshot({.id = 1221})->backgroundBlurRadius, blurRadius); |
| 349 | |
| 350 | static constexpr float alpha = 0.5; |
| 351 | setAlpha(12, alpha); |
| 352 | UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER); |
| 353 | EXPECT_EQ(getSnapshot({.id = 1221})->backgroundBlurRadius, blurRadius * alpha); |
| 354 | } |
| 355 | |
Vishnu Nair | a9c4376 | 2023-01-27 19:10:25 +0000 | [diff] [blame] | 356 | // Display Mirroring Tests |
| 357 | // tree with 3 levels of children |
| 358 | // ROOT (DISPLAY 0) |
| 359 | // ├── 1 |
| 360 | // │ ├── 11 |
| 361 | // │ │ └── 111 |
| 362 | // │ ├── 12 (has skip screenshot flag) |
| 363 | // │ │ ├── 121 |
| 364 | // │ │ └── 122 |
| 365 | // │ │ └── 1221 |
| 366 | // │ └── 13 |
| 367 | // └── 2 |
| 368 | // ROOT (DISPLAY 1) |
| 369 | // └── 3 (mirrors display 0) |
Vishnu Nair | 92990e2 | 2023-02-24 20:01:05 +0000 | [diff] [blame] | 370 | TEST_F(LayerSnapshotTest, displayMirrorRespectsLayerSkipScreenshotFlag) { |
Vishnu Nair | a9c4376 | 2023-01-27 19:10:25 +0000 | [diff] [blame] | 371 | setFlags(12, layer_state_t::eLayerSkipScreenshot, layer_state_t::eLayerSkipScreenshot); |
| 372 | createDisplayMirrorLayer(3, ui::LayerStack::fromValue(0)); |
| 373 | setLayerStack(3, 1); |
| 374 | |
Vishnu Nair | 444f395 | 2023-04-11 13:01:02 -0700 | [diff] [blame] | 375 | std::vector<uint32_t> expected = {1, 11, 111, 12, 121, 122, 1221, 13, 2, 3, 1, 11, 111, 13, 2}; |
Vishnu Nair | a9c4376 | 2023-01-27 19:10:25 +0000 | [diff] [blame] | 376 | UPDATE_AND_VERIFY(mSnapshotBuilder, expected); |
| 377 | } |
| 378 | |
Vishnu Nair | 92990e2 | 2023-02-24 20:01:05 +0000 | [diff] [blame] | 379 | // ROOT (DISPLAY 0) |
| 380 | // ├── 1 |
| 381 | // │ ├── 11 |
| 382 | // │ │ └── 111 |
| 383 | // │ └── 13 |
| 384 | // └── 2 |
| 385 | // ROOT (DISPLAY 3) |
| 386 | // └── 3 (mirrors display 0) |
| 387 | TEST_F(LayerSnapshotTest, mirrorLayerGetsCorrectLayerStack) { |
| 388 | reparentLayer(12, UNASSIGNED_LAYER_ID); |
| 389 | createDisplayMirrorLayer(3, ui::LayerStack::fromValue(0)); |
| 390 | setLayerStack(3, 3); |
| 391 | createDisplayMirrorLayer(4, ui::LayerStack::fromValue(0)); |
| 392 | setLayerStack(4, 4); |
| 393 | |
Vishnu Nair | 444f395 | 2023-04-11 13:01:02 -0700 | [diff] [blame] | 394 | std::vector<uint32_t> expected = {1, 11, 111, 13, 2, 3, 1, 11, 111, |
| 395 | 13, 2, 4, 1, 11, 111, 13, 2}; |
Vishnu Nair | 92990e2 | 2023-02-24 20:01:05 +0000 | [diff] [blame] | 396 | UPDATE_AND_VERIFY(mSnapshotBuilder, expected); |
| 397 | EXPECT_EQ(getSnapshot({.id = 111, .mirrorRootId = 3})->outputFilter.layerStack.id, 3u); |
| 398 | EXPECT_EQ(getSnapshot({.id = 111, .mirrorRootId = 4})->outputFilter.layerStack.id, 4u); |
| 399 | } |
| 400 | |
| 401 | // ROOT (DISPLAY 0) |
| 402 | // ├── 1 (crop 50x50) |
| 403 | // │ ├── 11 |
| 404 | // │ │ └── 111 |
| 405 | // │ └── 13 |
| 406 | // └── 2 |
| 407 | // ROOT (DISPLAY 3) |
| 408 | // └── 3 (mirrors display 0) (crop 100x100) |
| 409 | TEST_F(LayerSnapshotTest, mirrorLayerTouchIsCroppedByMirrorRoot) { |
| 410 | reparentLayer(12, UNASSIGNED_LAYER_ID); |
| 411 | createDisplayMirrorLayer(3, ui::LayerStack::fromValue(0)); |
| 412 | setLayerStack(3, 3); |
| 413 | setCrop(1, Rect{50, 50}); |
| 414 | setCrop(3, Rect{100, 100}); |
| 415 | setCrop(111, Rect{200, 200}); |
| 416 | Region touch{Rect{0, 0, 1000, 1000}}; |
| 417 | setTouchableRegion(111, touch); |
Vishnu Nair | 444f395 | 2023-04-11 13:01:02 -0700 | [diff] [blame] | 418 | std::vector<uint32_t> expected = {1, 11, 111, 13, 2, 3, 1, 11, 111, 13, 2}; |
Vishnu Nair | 92990e2 | 2023-02-24 20:01:05 +0000 | [diff] [blame] | 419 | UPDATE_AND_VERIFY(mSnapshotBuilder, expected); |
| 420 | EXPECT_TRUE(getSnapshot({.id = 111})->inputInfo.touchableRegion.hasSameRects(touch)); |
| 421 | Region touchCroppedByMirrorRoot{Rect{0, 0, 50, 50}}; |
| 422 | EXPECT_TRUE(getSnapshot({.id = 111, .mirrorRootId = 3}) |
| 423 | ->inputInfo.touchableRegion.hasSameRects(touchCroppedByMirrorRoot)); |
| 424 | } |
| 425 | |
| 426 | TEST_F(LayerSnapshotTest, canRemoveDisplayMirror) { |
| 427 | setFlags(12, layer_state_t::eLayerSkipScreenshot, layer_state_t::eLayerSkipScreenshot); |
| 428 | createDisplayMirrorLayer(3, ui::LayerStack::fromValue(0)); |
| 429 | setLayerStack(3, 1); |
Vishnu Nair | 444f395 | 2023-04-11 13:01:02 -0700 | [diff] [blame] | 430 | std::vector<uint32_t> expected = {1, 11, 111, 12, 121, 122, 1221, 13, 2, 3, 1, 11, 111, 13, 2}; |
Vishnu Nair | 92990e2 | 2023-02-24 20:01:05 +0000 | [diff] [blame] | 431 | UPDATE_AND_VERIFY(mSnapshotBuilder, expected); |
| 432 | destroyLayerHandle(3); |
| 433 | UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER); |
| 434 | } |
| 435 | |
Vishnu Nair | fccd636 | 2023-02-24 23:39:53 +0000 | [diff] [blame] | 436 | TEST_F(LayerSnapshotTest, cleanUpUnreachableSnapshotsAfterMirroring) { |
| 437 | size_t startingNumSnapshots = mSnapshotBuilder.getSnapshots().size(); |
| 438 | createDisplayMirrorLayer(3, ui::LayerStack::fromValue(0)); |
| 439 | setLayerStack(3, 1); |
Vishnu Nair | 444f395 | 2023-04-11 13:01:02 -0700 | [diff] [blame] | 440 | std::vector<uint32_t> expected = {1, 11, 111, 12, 121, 122, 1221, 13, 2, 3, |
| 441 | 1, 11, 111, 12, 121, 122, 1221, 13, 2}; |
Vishnu Nair | fccd636 | 2023-02-24 23:39:53 +0000 | [diff] [blame] | 442 | UPDATE_AND_VERIFY(mSnapshotBuilder, expected); |
| 443 | destroyLayerHandle(3); |
| 444 | UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER); |
| 445 | |
| 446 | EXPECT_EQ(startingNumSnapshots, mSnapshotBuilder.getSnapshots().size()); |
| 447 | } |
| 448 | |
| 449 | // Rel z doesn't create duplicate snapshots but this is for completeness |
| 450 | TEST_F(LayerSnapshotTest, cleanUpUnreachableSnapshotsAfterRelZ) { |
| 451 | size_t startingNumSnapshots = mSnapshotBuilder.getSnapshots().size(); |
| 452 | reparentRelativeLayer(13, 11); |
| 453 | UPDATE_AND_VERIFY(mSnapshotBuilder, {1, 11, 13, 111, 12, 121, 122, 1221, 2}); |
| 454 | setZ(13, 0); |
| 455 | UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER); |
| 456 | |
| 457 | EXPECT_EQ(startingNumSnapshots, mSnapshotBuilder.getSnapshots().size()); |
| 458 | } |
| 459 | |
| 460 | TEST_F(LayerSnapshotTest, cleanUpUnreachableSnapshotsAfterLayerDestruction) { |
| 461 | size_t startingNumSnapshots = mSnapshotBuilder.getSnapshots().size(); |
| 462 | destroyLayerHandle(2); |
| 463 | destroyLayerHandle(122); |
| 464 | |
| 465 | std::vector<uint32_t> expected = {1, 11, 111, 12, 121, 122, 1221, 13}; |
| 466 | UPDATE_AND_VERIFY(mSnapshotBuilder, expected); |
| 467 | |
| 468 | EXPECT_LE(startingNumSnapshots - 2, mSnapshotBuilder.getSnapshots().size()); |
| 469 | } |
| 470 | |
Vishnu Nair | 3d8565a | 2023-06-30 07:23:24 +0000 | [diff] [blame] | 471 | TEST_F(LayerSnapshotTest, snashotContainsMetadataFromLayerCreationArgs) { |
| 472 | LayerCreationArgs args(std::make_optional<uint32_t>(200)); |
| 473 | args.name = "testlayer"; |
| 474 | args.addToRoot = true; |
| 475 | args.metadata.setInt32(42, 24); |
| 476 | |
| 477 | std::vector<std::unique_ptr<RequestedLayerState>> layers; |
| 478 | layers.emplace_back(std::make_unique<RequestedLayerState>(args)); |
| 479 | EXPECT_TRUE(layers.back()->metadata.has(42)); |
| 480 | EXPECT_EQ(layers.back()->metadata.getInt32(42, 0), 24); |
| 481 | mLifecycleManager.addLayers(std::move(layers)); |
| 482 | |
| 483 | std::vector<uint32_t> expected = STARTING_ZORDER; |
| 484 | expected.push_back(200); |
| 485 | UPDATE_AND_VERIFY(mSnapshotBuilder, expected); |
| 486 | |
| 487 | EXPECT_TRUE(mSnapshotBuilder.getSnapshot(200)->layerMetadata.has(42)); |
| 488 | EXPECT_EQ(mSnapshotBuilder.getSnapshot(200)->layerMetadata.getInt32(42, 0), 24); |
| 489 | } |
| 490 | |
| 491 | TEST_F(LayerSnapshotTest, frameRateSelectionPriorityPassedToChildLayers) { |
| 492 | setFrameRateSelectionPriority(11, 1); |
| 493 | |
| 494 | setFrameRateSelectionPriority(12, 2); |
| 495 | |
| 496 | UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER); |
| 497 | EXPECT_EQ(getSnapshot({.id = 1})->frameRateSelectionPriority, Layer::PRIORITY_UNSET); |
| 498 | EXPECT_EQ(getSnapshot({.id = 11})->frameRateSelectionPriority, 1); |
| 499 | EXPECT_EQ(getSnapshot({.id = 12})->frameRateSelectionPriority, 2); |
| 500 | EXPECT_EQ(getSnapshot({.id = 122})->frameRateSelectionPriority, 2); |
| 501 | EXPECT_EQ(getSnapshot({.id = 1221})->frameRateSelectionPriority, 2); |
| 502 | |
| 503 | // reparent and verify the child gets the new parent's framerate selection priority |
| 504 | reparentLayer(122, 11); |
| 505 | |
| 506 | std::vector<uint32_t> expected = {1, 11, 111, 122, 1221, 12, 121, 13, 2}; |
| 507 | UPDATE_AND_VERIFY(mSnapshotBuilder, expected); |
| 508 | EXPECT_EQ(getSnapshot({.id = 1})->frameRateSelectionPriority, Layer::PRIORITY_UNSET); |
| 509 | EXPECT_EQ(getSnapshot({.id = 11})->frameRateSelectionPriority, 1); |
| 510 | EXPECT_EQ(getSnapshot({.id = 12})->frameRateSelectionPriority, 2); |
| 511 | EXPECT_EQ(getSnapshot({.id = 122})->frameRateSelectionPriority, 1); |
| 512 | EXPECT_EQ(getSnapshot({.id = 1221})->frameRateSelectionPriority, 1); |
| 513 | } |
| 514 | |
Vishnu Nair | 52d56fd | 2023-07-20 17:02:43 +0000 | [diff] [blame^] | 515 | TEST_F(LayerSnapshotTest, framerate) { |
| 516 | setFrameRate(11, 244.f, 0, 0); |
| 517 | |
| 518 | UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER); |
| 519 | // verify parent is gets no vote |
| 520 | EXPECT_FALSE(getSnapshot({.id = 1})->frameRate.rate.isValid()); |
| 521 | EXPECT_EQ(getSnapshot({.id = 1})->frameRate.type, |
| 522 | scheduler::LayerInfo::FrameRateCompatibility::NoVote); |
| 523 | EXPECT_TRUE(getSnapshot({.id = 1})->changes.test(RequestedLayerState::Changes::FrameRate)); |
| 524 | |
| 525 | // verify layer and children get the requested votes |
| 526 | EXPECT_TRUE(getSnapshot({.id = 11})->frameRate.rate.isValid()); |
| 527 | EXPECT_EQ(getSnapshot({.id = 11})->frameRate.rate.getValue(), 244.f); |
| 528 | EXPECT_EQ(getSnapshot({.id = 11})->frameRate.type, |
| 529 | scheduler::LayerInfo::FrameRateCompatibility::Default); |
| 530 | EXPECT_TRUE(getSnapshot({.id = 11})->changes.test(RequestedLayerState::Changes::FrameRate)); |
| 531 | |
| 532 | EXPECT_TRUE(getSnapshot({.id = 111})->frameRate.rate.isValid()); |
| 533 | EXPECT_EQ(getSnapshot({.id = 111})->frameRate.rate.getValue(), 244.f); |
| 534 | EXPECT_EQ(getSnapshot({.id = 111})->frameRate.type, |
| 535 | scheduler::LayerInfo::FrameRateCompatibility::Default); |
| 536 | EXPECT_TRUE(getSnapshot({.id = 111})->changes.test(RequestedLayerState::Changes::FrameRate)); |
| 537 | |
| 538 | // reparent and verify the child gets the new parent's framerate |
| 539 | reparentLayer(122, 11); |
| 540 | |
| 541 | std::vector<uint32_t> expected = {1, 11, 111, 122, 1221, 12, 121, 13, 2}; |
| 542 | UPDATE_AND_VERIFY(mSnapshotBuilder, expected); |
| 543 | // verify parent is gets no vote |
| 544 | EXPECT_FALSE(getSnapshot({.id = 1})->frameRate.rate.isValid()); |
| 545 | EXPECT_EQ(getSnapshot({.id = 1})->frameRate.type, |
| 546 | scheduler::LayerInfo::FrameRateCompatibility::NoVote); |
| 547 | |
| 548 | // verify layer and children get the requested votes |
| 549 | EXPECT_TRUE(getSnapshot({.id = 11})->frameRate.rate.isValid()); |
| 550 | EXPECT_EQ(getSnapshot({.id = 11})->frameRate.rate.getValue(), 244.f); |
| 551 | EXPECT_EQ(getSnapshot({.id = 11})->frameRate.type, |
| 552 | scheduler::LayerInfo::FrameRateCompatibility::Default); |
| 553 | |
| 554 | EXPECT_TRUE(getSnapshot({.id = 111})->frameRate.rate.isValid()); |
| 555 | EXPECT_EQ(getSnapshot({.id = 111})->frameRate.rate.getValue(), 244.f); |
| 556 | EXPECT_EQ(getSnapshot({.id = 111})->frameRate.type, |
| 557 | scheduler::LayerInfo::FrameRateCompatibility::Default); |
| 558 | |
| 559 | EXPECT_TRUE(getSnapshot({.id = 122})->frameRate.rate.isValid()); |
| 560 | EXPECT_EQ(getSnapshot({.id = 122})->frameRate.rate.getValue(), 244.f); |
| 561 | EXPECT_EQ(getSnapshot({.id = 122})->frameRate.type, |
| 562 | scheduler::LayerInfo::FrameRateCompatibility::Default); |
| 563 | EXPECT_TRUE(getSnapshot({.id = 122})->changes.test(RequestedLayerState::Changes::FrameRate)); |
| 564 | |
| 565 | // reparent and verify the new parent gets no vote |
| 566 | reparentLayer(11, 2); |
| 567 | expected = {1, 12, 121, 13, 2, 11, 111, 122, 1221}; |
| 568 | UPDATE_AND_VERIFY(mSnapshotBuilder, expected); |
| 569 | |
| 570 | // verify old parent has invalid framerate (default) |
| 571 | EXPECT_FALSE(getSnapshot({.id = 1})->frameRate.rate.isValid()); |
| 572 | EXPECT_EQ(getSnapshot({.id = 1})->frameRate.type, |
| 573 | scheduler::LayerInfo::FrameRateCompatibility::Default); |
| 574 | EXPECT_TRUE(getSnapshot({.id = 1})->changes.test(RequestedLayerState::Changes::FrameRate)); |
| 575 | |
| 576 | // verify new parent get no vote |
| 577 | EXPECT_FALSE(getSnapshot({.id = 2})->frameRate.rate.isValid()); |
| 578 | EXPECT_EQ(getSnapshot({.id = 2})->frameRate.type, |
| 579 | scheduler::LayerInfo::FrameRateCompatibility::NoVote); |
| 580 | EXPECT_TRUE(getSnapshot({.id = 2})->changes.test(RequestedLayerState::Changes::FrameRate)); |
| 581 | |
| 582 | // verify layer and children get the requested votes (unchanged) |
| 583 | EXPECT_TRUE(getSnapshot({.id = 11})->frameRate.rate.isValid()); |
| 584 | EXPECT_EQ(getSnapshot({.id = 11})->frameRate.rate.getValue(), 244.f); |
| 585 | EXPECT_EQ(getSnapshot({.id = 11})->frameRate.type, |
| 586 | scheduler::LayerInfo::FrameRateCompatibility::Default); |
| 587 | |
| 588 | EXPECT_TRUE(getSnapshot({.id = 111})->frameRate.rate.isValid()); |
| 589 | EXPECT_EQ(getSnapshot({.id = 111})->frameRate.rate.getValue(), 244.f); |
| 590 | EXPECT_EQ(getSnapshot({.id = 111})->frameRate.type, |
| 591 | scheduler::LayerInfo::FrameRateCompatibility::Default); |
| 592 | |
| 593 | EXPECT_TRUE(getSnapshot({.id = 122})->frameRate.rate.isValid()); |
| 594 | EXPECT_EQ(getSnapshot({.id = 122})->frameRate.rate.getValue(), 244.f); |
| 595 | EXPECT_EQ(getSnapshot({.id = 122})->frameRate.type, |
| 596 | scheduler::LayerInfo::FrameRateCompatibility::Default); |
| 597 | } |
| 598 | |
Vishnu Nair | 8fc721b | 2022-12-22 20:06:32 +0000 | [diff] [blame] | 599 | } // namespace android::surfaceflinger::frontend |