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 | 8fc721b | 2022-12-22 20:06:32 +0000 | [diff] [blame] | 23 | #include "LayerHierarchyTest.h" |
| 24 | |
| 25 | #define UPDATE_AND_VERIFY(BUILDER, ...) \ |
| 26 | ({ \ |
| 27 | SCOPED_TRACE(""); \ |
| 28 | updateAndVerify((BUILDER), /*displayChanges=*/false, __VA_ARGS__); \ |
| 29 | }) |
| 30 | |
| 31 | #define UPDATE_AND_VERIFY_WITH_DISPLAY_CHANGES(BUILDER, ...) \ |
| 32 | ({ \ |
| 33 | SCOPED_TRACE(""); \ |
| 34 | updateAndVerify((BUILDER), /*displayChanges=*/true, __VA_ARGS__); \ |
| 35 | }) |
| 36 | |
| 37 | namespace android::surfaceflinger::frontend { |
| 38 | |
Vishnu Nair | cfb2d25 | 2023-01-19 04:44:02 +0000 | [diff] [blame] | 39 | using ftl::Flags; |
| 40 | using namespace ftl::flag_operators; |
| 41 | |
Vishnu Nair | 8fc721b | 2022-12-22 20:06:32 +0000 | [diff] [blame] | 42 | // To run test: |
| 43 | /** |
| 44 | mp :libsurfaceflinger_unittest && adb sync; adb shell \ |
| 45 | /data/nativetest/libsurfaceflinger_unittest/libsurfaceflinger_unittest \ |
| 46 | --gtest_filter="LayerSnapshotTest.*" --gtest_brief=1 |
| 47 | */ |
| 48 | |
| 49 | class LayerSnapshotTest : public LayerHierarchyTestBase { |
| 50 | protected: |
| 51 | LayerSnapshotTest() : LayerHierarchyTestBase() { |
| 52 | UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER); |
| 53 | } |
| 54 | |
| 55 | void createRootLayer(uint32_t id) override { |
| 56 | LayerHierarchyTestBase::createRootLayer(id); |
| 57 | setColor(id); |
| 58 | } |
| 59 | |
| 60 | void createLayer(uint32_t id, uint32_t parentId) override { |
| 61 | LayerHierarchyTestBase::createLayer(id, parentId); |
| 62 | setColor(parentId); |
| 63 | } |
| 64 | |
| 65 | void mirrorLayer(uint32_t id, uint32_t parent, uint32_t layerToMirror) override { |
| 66 | LayerHierarchyTestBase::mirrorLayer(id, parent, layerToMirror); |
| 67 | setColor(id); |
| 68 | } |
| 69 | |
| 70 | void updateAndVerify(LayerSnapshotBuilder& actualBuilder, bool hasDisplayChanges, |
| 71 | const std::vector<uint32_t> expectedVisibleLayerIdsInZOrder) { |
| 72 | if (mLifecycleManager.getGlobalChanges().test(RequestedLayerState::Changes::Hierarchy)) { |
| 73 | mHierarchyBuilder.update(mLifecycleManager.getLayers(), |
| 74 | mLifecycleManager.getDestroyedLayers()); |
| 75 | } |
Vishnu Nair | c765c6c | 2023-02-23 00:08:01 +0000 | [diff] [blame] | 76 | LayerSnapshotBuilder::Args args{.root = mHierarchyBuilder.getHierarchy(), |
| 77 | .layerLifecycleManager = mLifecycleManager, |
| 78 | .includeMetadata = false, |
| 79 | .displays = mFrontEndDisplayInfos, |
| 80 | .displayChanges = hasDisplayChanges, |
| 81 | .globalShadowSettings = globalShadowSettings, |
| 82 | .supportedLayerGenericMetadata = {}, |
| 83 | .genericLayerMetadataKeyMap = {}}; |
Vishnu Nair | 8fc721b | 2022-12-22 20:06:32 +0000 | [diff] [blame] | 84 | actualBuilder.update(args); |
| 85 | |
| 86 | // rebuild layer snapshots from scratch and verify that it matches the updated state. |
| 87 | LayerSnapshotBuilder expectedBuilder(args); |
| 88 | mLifecycleManager.commitChanges(); |
| 89 | ASSERT_TRUE(expectedBuilder.getSnapshots().size() > 0); |
| 90 | ASSERT_TRUE(actualBuilder.getSnapshots().size() > 0); |
| 91 | |
Vishnu Nair | 8fc721b | 2022-12-22 20:06:32 +0000 | [diff] [blame] | 92 | std::vector<uint32_t> actualVisibleLayerIdsInZOrder; |
Vishnu Nair | cfb2d25 | 2023-01-19 04:44:02 +0000 | [diff] [blame] | 93 | actualBuilder.forEachVisibleSnapshot( |
| 94 | [&actualVisibleLayerIdsInZOrder](const LayerSnapshot& snapshot) { |
| 95 | actualVisibleLayerIdsInZOrder.push_back(snapshot.path.id); |
| 96 | }); |
Vishnu Nair | 8fc721b | 2022-12-22 20:06:32 +0000 | [diff] [blame] | 97 | EXPECT_EQ(expectedVisibleLayerIdsInZOrder, actualVisibleLayerIdsInZOrder); |
| 98 | } |
| 99 | |
| 100 | LayerSnapshot* getSnapshot(uint32_t layerId) { return mSnapshotBuilder.getSnapshot(layerId); } |
Vishnu Nair | 92990e2 | 2023-02-24 20:01:05 +0000 | [diff] [blame] | 101 | LayerSnapshot* getSnapshot(const LayerHierarchy::TraversalPath path) { |
| 102 | return mSnapshotBuilder.getSnapshot(path); |
| 103 | } |
Vishnu Nair | 8fc721b | 2022-12-22 20:06:32 +0000 | [diff] [blame] | 104 | |
| 105 | LayerHierarchyBuilder mHierarchyBuilder{{}}; |
| 106 | LayerSnapshotBuilder mSnapshotBuilder; |
Vishnu Nair | 8fc721b | 2022-12-22 20:06:32 +0000 | [diff] [blame] | 107 | display::DisplayMap<ui::LayerStack, frontend::DisplayInfo> mFrontEndDisplayInfos; |
| 108 | renderengine::ShadowSettings globalShadowSettings; |
| 109 | static const std::vector<uint32_t> STARTING_ZORDER; |
| 110 | }; |
| 111 | const std::vector<uint32_t> LayerSnapshotTest::STARTING_ZORDER = {1, 11, 111, 12, 121, |
| 112 | 122, 1221, 13, 2}; |
| 113 | |
| 114 | TEST_F(LayerSnapshotTest, buildSnapshot) { |
Vishnu Nair | c765c6c | 2023-02-23 00:08:01 +0000 | [diff] [blame] | 115 | LayerSnapshotBuilder::Args args{.root = mHierarchyBuilder.getHierarchy(), |
| 116 | .layerLifecycleManager = mLifecycleManager, |
| 117 | .includeMetadata = false, |
| 118 | .displays = mFrontEndDisplayInfos, |
| 119 | .globalShadowSettings = globalShadowSettings, |
| 120 | .supportedLayerGenericMetadata = {}, |
| 121 | .genericLayerMetadataKeyMap = {}}; |
Vishnu Nair | 8fc721b | 2022-12-22 20:06:32 +0000 | [diff] [blame] | 122 | LayerSnapshotBuilder builder(args); |
| 123 | } |
| 124 | |
| 125 | TEST_F(LayerSnapshotTest, updateSnapshot) { |
Vishnu Nair | c765c6c | 2023-02-23 00:08:01 +0000 | [diff] [blame] | 126 | LayerSnapshotBuilder::Args args{.root = mHierarchyBuilder.getHierarchy(), |
| 127 | .layerLifecycleManager = mLifecycleManager, |
| 128 | .includeMetadata = false, |
| 129 | .displays = mFrontEndDisplayInfos, |
| 130 | .globalShadowSettings = globalShadowSettings, |
| 131 | .supportedLayerGenericMetadata = {}, |
| 132 | .genericLayerMetadataKeyMap = {} |
| 133 | |
Vishnu Nair | 8fc721b | 2022-12-22 20:06:32 +0000 | [diff] [blame] | 134 | }; |
| 135 | |
| 136 | LayerSnapshotBuilder builder; |
| 137 | builder.update(args); |
| 138 | } |
| 139 | |
| 140 | // update using parent snapshot data |
| 141 | TEST_F(LayerSnapshotTest, croppedByParent) { |
| 142 | /// MAKE ALL LAYERS VISIBLE BY DEFAULT |
| 143 | DisplayInfo info; |
| 144 | info.info.logicalHeight = 100; |
| 145 | info.info.logicalWidth = 200; |
| 146 | mFrontEndDisplayInfos.emplace_or_replace(ui::LayerStack::fromValue(1), info); |
| 147 | Rect layerCrop(0, 0, 10, 20); |
| 148 | setCrop(11, layerCrop); |
| 149 | EXPECT_TRUE(mLifecycleManager.getGlobalChanges().test(RequestedLayerState::Changes::Geometry)); |
| 150 | UPDATE_AND_VERIFY_WITH_DISPLAY_CHANGES(mSnapshotBuilder, STARTING_ZORDER); |
| 151 | EXPECT_EQ(getSnapshot(11)->geomCrop, layerCrop); |
| 152 | EXPECT_EQ(getSnapshot(111)->geomLayerBounds, layerCrop.toFloatRect()); |
| 153 | float maxHeight = static_cast<float>(info.info.logicalHeight * 10); |
| 154 | float maxWidth = static_cast<float>(info.info.logicalWidth * 10); |
| 155 | |
| 156 | FloatRect maxDisplaySize(-maxWidth, -maxHeight, maxWidth, maxHeight); |
| 157 | EXPECT_EQ(getSnapshot(1)->geomLayerBounds, maxDisplaySize); |
| 158 | } |
| 159 | |
| 160 | // visibility tests |
| 161 | TEST_F(LayerSnapshotTest, newLayerHiddenByPolicy) { |
| 162 | createLayer(112, 11); |
| 163 | hideLayer(112); |
| 164 | UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER); |
| 165 | |
| 166 | showLayer(112); |
| 167 | UPDATE_AND_VERIFY(mSnapshotBuilder, {1, 11, 111, 112, 12, 121, 122, 1221, 13, 2}); |
| 168 | } |
| 169 | |
| 170 | TEST_F(LayerSnapshotTest, hiddenByParent) { |
| 171 | hideLayer(11); |
| 172 | UPDATE_AND_VERIFY(mSnapshotBuilder, {1, 12, 121, 122, 1221, 13, 2}); |
| 173 | } |
| 174 | |
| 175 | TEST_F(LayerSnapshotTest, reparentShowsChild) { |
| 176 | hideLayer(11); |
| 177 | UPDATE_AND_VERIFY(mSnapshotBuilder, {1, 12, 121, 122, 1221, 13, 2}); |
| 178 | |
| 179 | showLayer(11); |
| 180 | UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER); |
| 181 | } |
| 182 | |
| 183 | TEST_F(LayerSnapshotTest, reparentHidesChild) { |
| 184 | hideLayer(11); |
| 185 | UPDATE_AND_VERIFY(mSnapshotBuilder, {1, 12, 121, 122, 1221, 13, 2}); |
| 186 | |
| 187 | reparentLayer(121, 11); |
| 188 | UPDATE_AND_VERIFY(mSnapshotBuilder, {1, 12, 122, 1221, 13, 2}); |
| 189 | } |
| 190 | |
| 191 | TEST_F(LayerSnapshotTest, unHidingUpdatesSnapshot) { |
| 192 | hideLayer(11); |
| 193 | Rect crop(1, 2, 3, 4); |
| 194 | setCrop(111, crop); |
| 195 | UPDATE_AND_VERIFY(mSnapshotBuilder, {1, 12, 121, 122, 1221, 13, 2}); |
| 196 | |
| 197 | showLayer(11); |
| 198 | UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER); |
| 199 | EXPECT_EQ(getSnapshot(111)->geomLayerBounds, crop.toFloatRect()); |
| 200 | } |
| 201 | |
| 202 | TEST_F(LayerSnapshotTest, childBehindParentCanBeHiddenByParent) { |
| 203 | setZ(111, -1); |
| 204 | UPDATE_AND_VERIFY(mSnapshotBuilder, {1, 111, 11, 12, 121, 122, 1221, 13, 2}); |
| 205 | |
| 206 | hideLayer(11); |
| 207 | UPDATE_AND_VERIFY(mSnapshotBuilder, {1, 12, 121, 122, 1221, 13, 2}); |
| 208 | } |
| 209 | |
| 210 | // relative tests |
| 211 | TEST_F(LayerSnapshotTest, RelativeParentCanHideChild) { |
| 212 | reparentRelativeLayer(13, 11); |
| 213 | UPDATE_AND_VERIFY(mSnapshotBuilder, {1, 11, 13, 111, 12, 121, 122, 1221, 2}); |
| 214 | |
| 215 | hideLayer(11); |
| 216 | UPDATE_AND_VERIFY(mSnapshotBuilder, {1, 12, 121, 122, 1221, 2}); |
| 217 | } |
| 218 | |
| 219 | TEST_F(LayerSnapshotTest, ReparentingToHiddenRelativeParentHidesChild) { |
| 220 | hideLayer(11); |
| 221 | UPDATE_AND_VERIFY(mSnapshotBuilder, {1, 12, 121, 122, 1221, 13, 2}); |
| 222 | reparentRelativeLayer(13, 11); |
| 223 | UPDATE_AND_VERIFY(mSnapshotBuilder, {1, 12, 121, 122, 1221, 2}); |
| 224 | } |
| 225 | |
| 226 | TEST_F(LayerSnapshotTest, AlphaInheritedByChildren) { |
| 227 | setAlpha(1, 0.5); |
| 228 | setAlpha(122, 0.5); |
| 229 | UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER); |
| 230 | EXPECT_EQ(getSnapshot(12)->alpha, 0.5f); |
| 231 | EXPECT_EQ(getSnapshot(1221)->alpha, 0.25f); |
| 232 | } |
| 233 | |
| 234 | // Change states |
| 235 | TEST_F(LayerSnapshotTest, UpdateClearsPreviousChangeStates) { |
| 236 | setCrop(1, Rect(1, 2, 3, 4)); |
| 237 | UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER); |
| 238 | EXPECT_TRUE(getSnapshot(1)->changes.get() != 0); |
| 239 | EXPECT_TRUE(getSnapshot(11)->changes.get() != 0); |
| 240 | setCrop(2, Rect(1, 2, 3, 4)); |
| 241 | UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER); |
| 242 | EXPECT_TRUE(getSnapshot(2)->changes.get() != 0); |
| 243 | EXPECT_TRUE(getSnapshot(1)->changes.get() == 0); |
| 244 | EXPECT_TRUE(getSnapshot(11)->changes.get() == 0); |
| 245 | } |
| 246 | |
| 247 | TEST_F(LayerSnapshotTest, FastPathClearsPreviousChangeStates) { |
| 248 | setColor(11, {1._hf, 0._hf, 0._hf}); |
| 249 | UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER); |
| 250 | EXPECT_TRUE(getSnapshot(11)->changes.get() != 0); |
| 251 | EXPECT_TRUE(getSnapshot(1)->changes.get() == 0); |
| 252 | UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER); |
| 253 | EXPECT_TRUE(getSnapshot(11)->changes.get() == 0); |
| 254 | } |
| 255 | |
| 256 | TEST_F(LayerSnapshotTest, FastPathSetsChangeFlagToContent) { |
| 257 | setColor(1, {1._hf, 0._hf, 0._hf}); |
| 258 | UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER); |
| 259 | EXPECT_EQ(getSnapshot(1)->changes, RequestedLayerState::Changes::Content); |
| 260 | } |
| 261 | |
Vishnu Nair | cfb2d25 | 2023-01-19 04:44:02 +0000 | [diff] [blame] | 262 | TEST_F(LayerSnapshotTest, GameMode) { |
| 263 | std::vector<TransactionState> transactions; |
| 264 | transactions.emplace_back(); |
| 265 | transactions.back().states.push_back({}); |
| 266 | transactions.back().states.front().state.what = layer_state_t::eMetadataChanged; |
| 267 | transactions.back().states.front().state.metadata = LayerMetadata(); |
| 268 | transactions.back().states.front().state.metadata.setInt32(METADATA_GAME_MODE, 42); |
Vishnu Nair | 1391de2 | 2023-03-05 19:56:14 -0800 | [diff] [blame] | 269 | transactions.back().states.front().layerId = 1; |
Vishnu Nair | cfb2d25 | 2023-01-19 04:44:02 +0000 | [diff] [blame] | 270 | transactions.back().states.front().state.layerId = static_cast<int32_t>(1); |
| 271 | mLifecycleManager.applyTransactions(transactions); |
| 272 | UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER); |
| 273 | EXPECT_EQ(static_cast<int32_t>(getSnapshot(1)->gameMode), 42); |
| 274 | EXPECT_EQ(static_cast<int32_t>(getSnapshot(11)->gameMode), 42); |
| 275 | } |
| 276 | |
| 277 | TEST_F(LayerSnapshotTest, NoLayerVoteForParentWithChildVotes) { |
| 278 | // ROOT |
| 279 | // ├── 1 |
| 280 | // │ ├── 11 (frame rate set) |
| 281 | // │ │ └── 111 |
| 282 | // │ ├── 12 |
| 283 | // │ │ ├── 121 |
| 284 | // │ │ └── 122 |
| 285 | // │ │ └── 1221 |
| 286 | // │ └── 13 |
| 287 | // └── 2 |
| 288 | |
| 289 | std::vector<TransactionState> transactions; |
| 290 | transactions.emplace_back(); |
| 291 | transactions.back().states.push_back({}); |
| 292 | transactions.back().states.front().state.what = layer_state_t::eFrameRateChanged; |
| 293 | transactions.back().states.front().state.frameRate = 90.0; |
| 294 | transactions.back().states.front().state.frameRateCompatibility = |
| 295 | ANATIVEWINDOW_FRAME_RATE_EXACT; |
| 296 | transactions.back().states.front().state.changeFrameRateStrategy = |
| 297 | ANATIVEWINDOW_CHANGE_FRAME_RATE_ALWAYS; |
Vishnu Nair | 1391de2 | 2023-03-05 19:56:14 -0800 | [diff] [blame] | 298 | transactions.back().states.front().layerId = 11; |
Vishnu Nair | cfb2d25 | 2023-01-19 04:44:02 +0000 | [diff] [blame] | 299 | mLifecycleManager.applyTransactions(transactions); |
| 300 | UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER); |
| 301 | |
| 302 | EXPECT_EQ(getSnapshot(11)->frameRate.rate.getIntValue(), 90); |
| 303 | EXPECT_EQ(getSnapshot(11)->frameRate.type, scheduler::LayerInfo::FrameRateCompatibility::Exact); |
| 304 | EXPECT_EQ(getSnapshot(111)->frameRate.rate.getIntValue(), 90); |
| 305 | EXPECT_EQ(getSnapshot(111)->frameRate.type, |
| 306 | scheduler::LayerInfo::FrameRateCompatibility::Exact); |
| 307 | EXPECT_EQ(getSnapshot(1)->frameRate.rate.getIntValue(), 0); |
| 308 | EXPECT_EQ(getSnapshot(1)->frameRate.type, scheduler::LayerInfo::FrameRateCompatibility::NoVote); |
| 309 | } |
| 310 | |
Vishnu Nair | 29354ec | 2023-03-28 18:51:28 -0700 | [diff] [blame^] | 311 | TEST_F(LayerSnapshotTest, canCropTouchableRegion) { |
| 312 | // ROOT |
| 313 | // ├── 1 |
| 314 | // │ ├── 11 |
| 315 | // │ │ └── 111 (touchregion set to touch but cropped by layer 13) |
| 316 | // │ ├── 12 |
| 317 | // │ │ ├── 121 |
| 318 | // │ │ └── 122 |
| 319 | // │ │ └── 1221 |
| 320 | // │ └── 13 (crop set to touchCrop) |
| 321 | // └── 2 |
| 322 | |
| 323 | Rect touchCrop{300, 300, 400, 500}; |
| 324 | setCrop(13, touchCrop); |
| 325 | Region touch{Rect{0, 0, 1000, 1000}}; |
| 326 | setTouchableRegionCrop(111, touch, /*touchCropId=*/13, /*replaceTouchableRegionWithCrop=*/true); |
| 327 | UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER); |
| 328 | EXPECT_EQ(getSnapshot({.id = 111})->inputInfo.touchableRegion.bounds(), touchCrop); |
| 329 | |
| 330 | Rect modifiedTouchCrop{100, 300, 400, 700}; |
| 331 | setCrop(13, modifiedTouchCrop); |
| 332 | UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER); |
| 333 | EXPECT_EQ(getSnapshot({.id = 111})->inputInfo.touchableRegion.bounds(), modifiedTouchCrop); |
| 334 | } |
| 335 | |
Vishnu Nair | a9c4376 | 2023-01-27 19:10:25 +0000 | [diff] [blame] | 336 | // Display Mirroring Tests |
| 337 | // tree with 3 levels of children |
| 338 | // ROOT (DISPLAY 0) |
| 339 | // ├── 1 |
| 340 | // │ ├── 11 |
| 341 | // │ │ └── 111 |
| 342 | // │ ├── 12 (has skip screenshot flag) |
| 343 | // │ │ ├── 121 |
| 344 | // │ │ └── 122 |
| 345 | // │ │ └── 1221 |
| 346 | // │ └── 13 |
| 347 | // └── 2 |
| 348 | // ROOT (DISPLAY 1) |
| 349 | // └── 3 (mirrors display 0) |
Vishnu Nair | 92990e2 | 2023-02-24 20:01:05 +0000 | [diff] [blame] | 350 | TEST_F(LayerSnapshotTest, displayMirrorRespectsLayerSkipScreenshotFlag) { |
Vishnu Nair | a9c4376 | 2023-01-27 19:10:25 +0000 | [diff] [blame] | 351 | setFlags(12, layer_state_t::eLayerSkipScreenshot, layer_state_t::eLayerSkipScreenshot); |
| 352 | createDisplayMirrorLayer(3, ui::LayerStack::fromValue(0)); |
| 353 | setLayerStack(3, 1); |
| 354 | |
| 355 | std::vector<uint32_t> expected = {3, 1, 11, 111, 13, 2, 1, 11, 111, 12, 121, 122, 1221, 13, 2}; |
| 356 | UPDATE_AND_VERIFY(mSnapshotBuilder, expected); |
| 357 | } |
| 358 | |
Vishnu Nair | 92990e2 | 2023-02-24 20:01:05 +0000 | [diff] [blame] | 359 | // ROOT (DISPLAY 0) |
| 360 | // ├── 1 |
| 361 | // │ ├── 11 |
| 362 | // │ │ └── 111 |
| 363 | // │ └── 13 |
| 364 | // └── 2 |
| 365 | // ROOT (DISPLAY 3) |
| 366 | // └── 3 (mirrors display 0) |
| 367 | TEST_F(LayerSnapshotTest, mirrorLayerGetsCorrectLayerStack) { |
| 368 | reparentLayer(12, UNASSIGNED_LAYER_ID); |
| 369 | createDisplayMirrorLayer(3, ui::LayerStack::fromValue(0)); |
| 370 | setLayerStack(3, 3); |
| 371 | createDisplayMirrorLayer(4, ui::LayerStack::fromValue(0)); |
| 372 | setLayerStack(4, 4); |
| 373 | |
| 374 | std::vector<uint32_t> expected = {4, 1, 11, 111, 13, 2, 3, 1, 11, |
| 375 | 111, 13, 2, 1, 11, 111, 13, 2}; |
| 376 | UPDATE_AND_VERIFY(mSnapshotBuilder, expected); |
| 377 | EXPECT_EQ(getSnapshot({.id = 111, .mirrorRootId = 3})->outputFilter.layerStack.id, 3u); |
| 378 | EXPECT_EQ(getSnapshot({.id = 111, .mirrorRootId = 4})->outputFilter.layerStack.id, 4u); |
| 379 | } |
| 380 | |
| 381 | // ROOT (DISPLAY 0) |
| 382 | // ├── 1 (crop 50x50) |
| 383 | // │ ├── 11 |
| 384 | // │ │ └── 111 |
| 385 | // │ └── 13 |
| 386 | // └── 2 |
| 387 | // ROOT (DISPLAY 3) |
| 388 | // └── 3 (mirrors display 0) (crop 100x100) |
| 389 | TEST_F(LayerSnapshotTest, mirrorLayerTouchIsCroppedByMirrorRoot) { |
| 390 | reparentLayer(12, UNASSIGNED_LAYER_ID); |
| 391 | createDisplayMirrorLayer(3, ui::LayerStack::fromValue(0)); |
| 392 | setLayerStack(3, 3); |
| 393 | setCrop(1, Rect{50, 50}); |
| 394 | setCrop(3, Rect{100, 100}); |
| 395 | setCrop(111, Rect{200, 200}); |
| 396 | Region touch{Rect{0, 0, 1000, 1000}}; |
| 397 | setTouchableRegion(111, touch); |
| 398 | std::vector<uint32_t> expected = {3, 1, 11, 111, 13, 2, 1, 11, 111, 13, 2}; |
| 399 | UPDATE_AND_VERIFY(mSnapshotBuilder, expected); |
| 400 | EXPECT_TRUE(getSnapshot({.id = 111})->inputInfo.touchableRegion.hasSameRects(touch)); |
| 401 | Region touchCroppedByMirrorRoot{Rect{0, 0, 50, 50}}; |
| 402 | EXPECT_TRUE(getSnapshot({.id = 111, .mirrorRootId = 3}) |
| 403 | ->inputInfo.touchableRegion.hasSameRects(touchCroppedByMirrorRoot)); |
| 404 | } |
| 405 | |
| 406 | TEST_F(LayerSnapshotTest, canRemoveDisplayMirror) { |
| 407 | setFlags(12, layer_state_t::eLayerSkipScreenshot, layer_state_t::eLayerSkipScreenshot); |
| 408 | createDisplayMirrorLayer(3, ui::LayerStack::fromValue(0)); |
| 409 | setLayerStack(3, 1); |
| 410 | std::vector<uint32_t> expected = {3, 1, 11, 111, 13, 2, 1, 11, 111, 12, 121, 122, 1221, 13, 2}; |
| 411 | UPDATE_AND_VERIFY(mSnapshotBuilder, expected); |
| 412 | destroyLayerHandle(3); |
| 413 | UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER); |
| 414 | } |
| 415 | |
Vishnu Nair | fccd636 | 2023-02-24 23:39:53 +0000 | [diff] [blame] | 416 | TEST_F(LayerSnapshotTest, cleanUpUnreachableSnapshotsAfterMirroring) { |
| 417 | size_t startingNumSnapshots = mSnapshotBuilder.getSnapshots().size(); |
| 418 | createDisplayMirrorLayer(3, ui::LayerStack::fromValue(0)); |
| 419 | setLayerStack(3, 1); |
| 420 | std::vector<uint32_t> expected = {3, 1, 11, 111, 12, 121, 122, 1221, 13, 2, |
| 421 | 1, 11, 111, 12, 121, 122, 1221, 13, 2}; |
| 422 | UPDATE_AND_VERIFY(mSnapshotBuilder, expected); |
| 423 | destroyLayerHandle(3); |
| 424 | UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER); |
| 425 | |
| 426 | EXPECT_EQ(startingNumSnapshots, mSnapshotBuilder.getSnapshots().size()); |
| 427 | } |
| 428 | |
| 429 | // Rel z doesn't create duplicate snapshots but this is for completeness |
| 430 | TEST_F(LayerSnapshotTest, cleanUpUnreachableSnapshotsAfterRelZ) { |
| 431 | size_t startingNumSnapshots = mSnapshotBuilder.getSnapshots().size(); |
| 432 | reparentRelativeLayer(13, 11); |
| 433 | UPDATE_AND_VERIFY(mSnapshotBuilder, {1, 11, 13, 111, 12, 121, 122, 1221, 2}); |
| 434 | setZ(13, 0); |
| 435 | UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER); |
| 436 | |
| 437 | EXPECT_EQ(startingNumSnapshots, mSnapshotBuilder.getSnapshots().size()); |
| 438 | } |
| 439 | |
| 440 | TEST_F(LayerSnapshotTest, cleanUpUnreachableSnapshotsAfterLayerDestruction) { |
| 441 | size_t startingNumSnapshots = mSnapshotBuilder.getSnapshots().size(); |
| 442 | destroyLayerHandle(2); |
| 443 | destroyLayerHandle(122); |
| 444 | |
| 445 | std::vector<uint32_t> expected = {1, 11, 111, 12, 121, 122, 1221, 13}; |
| 446 | UPDATE_AND_VERIFY(mSnapshotBuilder, expected); |
| 447 | |
| 448 | EXPECT_LE(startingNumSnapshots - 2, mSnapshotBuilder.getSnapshots().size()); |
| 449 | } |
| 450 | |
Vishnu Nair | 8fc721b | 2022-12-22 20:06:32 +0000 | [diff] [blame] | 451 | } // namespace android::surfaceflinger::frontend |