Vishnu Nair | 04f8969 | 2022-11-16 23:21:05 +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 | 04f8969 | 2022-11-16 23:21:05 +0000 | [diff] [blame] | 20 | #include "FrontEnd/LayerHierarchy.h" |
| 21 | #include "FrontEnd/LayerLifecycleManager.h" |
Vishnu Nair | 8fc721b | 2022-12-22 20:06:32 +0000 | [diff] [blame] | 22 | #include "LayerHierarchyTest.h" |
Vishnu Nair | 04f8969 | 2022-11-16 23:21:05 +0000 | [diff] [blame] | 23 | |
| 24 | #define UPDATE_AND_VERIFY(HIERARCHY) \ |
| 25 | ({ \ |
| 26 | SCOPED_TRACE(""); \ |
| 27 | updateAndVerify((HIERARCHY)); \ |
| 28 | }) |
| 29 | |
| 30 | namespace android::surfaceflinger::frontend { |
| 31 | |
Vishnu Nair | 04f8969 | 2022-11-16 23:21:05 +0000 | [diff] [blame] | 32 | // To run test: |
| 33 | /** |
| 34 | mp :libsurfaceflinger_unittest && adb sync; adb shell \ |
| 35 | /data/nativetest/libsurfaceflinger_unittest/libsurfaceflinger_unittest \ |
| 36 | --gtest_filter="LayerHierarchyTest.*" --gtest_repeat=100 \ |
| 37 | --gtest_shuffle \ |
| 38 | --gtest_brief=1 |
| 39 | */ |
| 40 | |
Vishnu Nair | 8fc721b | 2022-12-22 20:06:32 +0000 | [diff] [blame] | 41 | class LayerHierarchyTest : public LayerHierarchyTestBase { |
Vishnu Nair | 04f8969 | 2022-11-16 23:21:05 +0000 | [diff] [blame] | 42 | protected: |
Vishnu Nair | 8fc721b | 2022-12-22 20:06:32 +0000 | [diff] [blame] | 43 | LayerHierarchyTest() : LayerHierarchyTestBase() { mLifecycleManager.commitChanges(); } |
Vishnu Nair | 04f8969 | 2022-11-16 23:21:05 +0000 | [diff] [blame] | 44 | }; |
| 45 | |
| 46 | // reparenting tests |
| 47 | TEST_F(LayerHierarchyTest, addLayer) { |
Vishnu Nair | a029228 | 2023-12-16 14:32:00 -0800 | [diff] [blame] | 48 | LayerHierarchyBuilder hierarchyBuilder; |
| 49 | hierarchyBuilder.update(mLifecycleManager); |
Vishnu Nair | 04f8969 | 2022-11-16 23:21:05 +0000 | [diff] [blame] | 50 | std::vector<uint32_t> expectedTraversalPath = {1, 11, 111, 12, 121, 122, 1221, 13, 2}; |
| 51 | EXPECT_EQ(getTraversalPath(hierarchyBuilder.getHierarchy()), expectedTraversalPath); |
| 52 | EXPECT_EQ(getTraversalPathInZOrder(hierarchyBuilder.getHierarchy()), expectedTraversalPath); |
| 53 | expectedTraversalPath = {}; |
| 54 | EXPECT_EQ(getTraversalPath(hierarchyBuilder.getOffscreenHierarchy()), expectedTraversalPath); |
| 55 | |
| 56 | createRootLayer(3); |
| 57 | createLayer(112, 11); |
| 58 | createLayer(12211, 1221); |
| 59 | UPDATE_AND_VERIFY(hierarchyBuilder); |
| 60 | expectedTraversalPath = {1, 11, 111, 112, 12, 121, 122, 1221, 12211, 13, 2, 3}; |
| 61 | EXPECT_EQ(getTraversalPath(hierarchyBuilder.getHierarchy()), expectedTraversalPath); |
| 62 | EXPECT_EQ(getTraversalPathInZOrder(hierarchyBuilder.getHierarchy()), expectedTraversalPath); |
| 63 | expectedTraversalPath = {}; |
| 64 | EXPECT_EQ(getTraversalPath(hierarchyBuilder.getOffscreenHierarchy()), expectedTraversalPath); |
| 65 | } |
| 66 | |
| 67 | TEST_F(LayerHierarchyTest, reparentLayer) { |
Vishnu Nair | a029228 | 2023-12-16 14:32:00 -0800 | [diff] [blame] | 68 | LayerHierarchyBuilder hierarchyBuilder; |
| 69 | hierarchyBuilder.update(mLifecycleManager); |
Vishnu Nair | 04f8969 | 2022-11-16 23:21:05 +0000 | [diff] [blame] | 70 | reparentLayer(2, 11); |
| 71 | reparentLayer(111, 12); |
| 72 | reparentLayer(1221, 1); |
| 73 | reparentLayer(1221, 13); |
| 74 | UPDATE_AND_VERIFY(hierarchyBuilder); |
| 75 | |
| 76 | std::vector<uint32_t> expectedTraversalPath = {1, 11, 2, 12, 111, 121, 122, 13, 1221}; |
| 77 | EXPECT_EQ(getTraversalPath(hierarchyBuilder.getHierarchy()), expectedTraversalPath); |
| 78 | EXPECT_EQ(getTraversalPathInZOrder(hierarchyBuilder.getHierarchy()), expectedTraversalPath); |
| 79 | expectedTraversalPath = {}; |
| 80 | EXPECT_EQ(getTraversalPath(hierarchyBuilder.getOffscreenHierarchy()), expectedTraversalPath); |
| 81 | } |
| 82 | |
| 83 | TEST_F(LayerHierarchyTest, reparentLayerToNull) { |
Vishnu Nair | a029228 | 2023-12-16 14:32:00 -0800 | [diff] [blame] | 84 | LayerHierarchyBuilder hierarchyBuilder; |
| 85 | hierarchyBuilder.update(mLifecycleManager); |
Vishnu Nair | 04f8969 | 2022-11-16 23:21:05 +0000 | [diff] [blame] | 86 | |
| 87 | reparentLayer(2, UNASSIGNED_LAYER_ID); |
| 88 | reparentLayer(11, UNASSIGNED_LAYER_ID); |
| 89 | reparentLayer(1221, 13); |
| 90 | reparentLayer(1221, UNASSIGNED_LAYER_ID); |
| 91 | |
| 92 | UPDATE_AND_VERIFY(hierarchyBuilder); |
| 93 | |
| 94 | std::vector<uint32_t> expectedTraversalPath = {1, 12, 121, 122, 13}; |
| 95 | EXPECT_EQ(getTraversalPath(hierarchyBuilder.getHierarchy()), expectedTraversalPath); |
| 96 | EXPECT_EQ(getTraversalPathInZOrder(hierarchyBuilder.getHierarchy()), expectedTraversalPath); |
| 97 | expectedTraversalPath = {2, 11, 111, 1221}; |
| 98 | EXPECT_EQ(getTraversalPath(hierarchyBuilder.getOffscreenHierarchy()), expectedTraversalPath); |
| 99 | } |
| 100 | |
| 101 | TEST_F(LayerHierarchyTest, reparentLayerToNullAndDestroyHandles) { |
Vishnu Nair | a029228 | 2023-12-16 14:32:00 -0800 | [diff] [blame] | 102 | LayerHierarchyBuilder hierarchyBuilder; |
| 103 | hierarchyBuilder.update(mLifecycleManager); |
Vishnu Nair | 04f8969 | 2022-11-16 23:21:05 +0000 | [diff] [blame] | 104 | reparentLayer(2, UNASSIGNED_LAYER_ID); |
| 105 | reparentLayer(11, UNASSIGNED_LAYER_ID); |
| 106 | reparentLayer(1221, UNASSIGNED_LAYER_ID); |
| 107 | |
| 108 | destroyLayerHandle(2); |
| 109 | destroyLayerHandle(11); |
| 110 | destroyLayerHandle(1221); |
| 111 | |
| 112 | UPDATE_AND_VERIFY(hierarchyBuilder); |
| 113 | |
| 114 | std::vector<uint32_t> expectedTraversalPath = {1, 12, 121, 122, 13}; |
| 115 | EXPECT_EQ(getTraversalPath(hierarchyBuilder.getHierarchy()), expectedTraversalPath); |
| 116 | EXPECT_EQ(getTraversalPathInZOrder(hierarchyBuilder.getHierarchy()), expectedTraversalPath); |
| 117 | expectedTraversalPath = {111}; |
| 118 | EXPECT_EQ(getTraversalPath(hierarchyBuilder.getOffscreenHierarchy()), expectedTraversalPath); |
| 119 | } |
| 120 | |
| 121 | TEST_F(LayerHierarchyTest, destroyHandleThenDestroyParentLayer) { |
Vishnu Nair | a029228 | 2023-12-16 14:32:00 -0800 | [diff] [blame] | 122 | LayerHierarchyBuilder hierarchyBuilder; |
| 123 | hierarchyBuilder.update(mLifecycleManager); |
Vishnu Nair | 04f8969 | 2022-11-16 23:21:05 +0000 | [diff] [blame] | 124 | destroyLayerHandle(111); |
| 125 | UPDATE_AND_VERIFY(hierarchyBuilder); |
| 126 | |
| 127 | // handle is destroyed but layer is kept alive and reachable by parent |
| 128 | std::vector<uint32_t> expectedTraversalPath = {1, 11, 111, 12, 121, 122, 1221, 13, 2}; |
| 129 | EXPECT_EQ(getTraversalPath(hierarchyBuilder.getHierarchy()), expectedTraversalPath); |
| 130 | EXPECT_EQ(getTraversalPathInZOrder(hierarchyBuilder.getHierarchy()), expectedTraversalPath); |
| 131 | expectedTraversalPath = {}; |
| 132 | EXPECT_EQ(getTraversalPath(hierarchyBuilder.getOffscreenHierarchy()), expectedTraversalPath); |
| 133 | |
| 134 | // destroy parent layer and the child gets destroyed |
| 135 | reparentLayer(11, UNASSIGNED_LAYER_ID); |
| 136 | destroyLayerHandle(11); |
| 137 | UPDATE_AND_VERIFY(hierarchyBuilder); |
| 138 | |
| 139 | expectedTraversalPath = {1, 12, 121, 122, 1221, 13, 2}; |
| 140 | EXPECT_EQ(getTraversalPath(hierarchyBuilder.getHierarchy()), expectedTraversalPath); |
| 141 | EXPECT_EQ(getTraversalPathInZOrder(hierarchyBuilder.getHierarchy()), expectedTraversalPath); |
| 142 | expectedTraversalPath = {}; |
| 143 | EXPECT_EQ(getTraversalPath(hierarchyBuilder.getOffscreenHierarchy()), expectedTraversalPath); |
| 144 | } |
| 145 | |
| 146 | TEST_F(LayerHierarchyTest, layerSurvivesTemporaryReparentToNull) { |
Vishnu Nair | a029228 | 2023-12-16 14:32:00 -0800 | [diff] [blame] | 147 | LayerHierarchyBuilder hierarchyBuilder; |
| 148 | hierarchyBuilder.update(mLifecycleManager); |
Vishnu Nair | 04f8969 | 2022-11-16 23:21:05 +0000 | [diff] [blame] | 149 | reparentLayer(11, UNASSIGNED_LAYER_ID); |
| 150 | reparentLayer(11, 1); |
| 151 | |
| 152 | UPDATE_AND_VERIFY(hierarchyBuilder); |
| 153 | |
| 154 | std::vector<uint32_t> expectedTraversalPath = {1, 11, 111, 12, 121, 122, 1221, 13, 2}; |
| 155 | EXPECT_EQ(getTraversalPath(hierarchyBuilder.getHierarchy()), expectedTraversalPath); |
| 156 | EXPECT_EQ(getTraversalPathInZOrder(hierarchyBuilder.getHierarchy()), expectedTraversalPath); |
| 157 | expectedTraversalPath = {}; |
| 158 | EXPECT_EQ(getTraversalPath(hierarchyBuilder.getOffscreenHierarchy()), expectedTraversalPath); |
| 159 | } |
| 160 | |
| 161 | // offscreen tests |
| 162 | TEST_F(LayerHierarchyTest, layerMovesOnscreen) { |
Vishnu Nair | a029228 | 2023-12-16 14:32:00 -0800 | [diff] [blame] | 163 | LayerHierarchyBuilder hierarchyBuilder; |
| 164 | hierarchyBuilder.update(mLifecycleManager); |
Vishnu Nair | 04f8969 | 2022-11-16 23:21:05 +0000 | [diff] [blame] | 165 | |
| 166 | reparentLayer(11, UNASSIGNED_LAYER_ID); |
| 167 | UPDATE_AND_VERIFY(hierarchyBuilder); |
| 168 | |
| 169 | reparentLayer(11, 1); |
| 170 | UPDATE_AND_VERIFY(hierarchyBuilder); |
| 171 | |
| 172 | std::vector<uint32_t> expectedTraversalPath = {1, 11, 111, 12, 121, 122, 1221, 13, 2}; |
| 173 | EXPECT_EQ(getTraversalPath(hierarchyBuilder.getHierarchy()), expectedTraversalPath); |
| 174 | EXPECT_EQ(getTraversalPathInZOrder(hierarchyBuilder.getHierarchy()), expectedTraversalPath); |
| 175 | expectedTraversalPath = {}; |
| 176 | EXPECT_EQ(getTraversalPath(hierarchyBuilder.getOffscreenHierarchy()), expectedTraversalPath); |
| 177 | } |
| 178 | |
| 179 | TEST_F(LayerHierarchyTest, addLayerToOffscreenParent) { |
Vishnu Nair | a029228 | 2023-12-16 14:32:00 -0800 | [diff] [blame] | 180 | LayerHierarchyBuilder hierarchyBuilder; |
| 181 | hierarchyBuilder.update(mLifecycleManager); |
Vishnu Nair | 04f8969 | 2022-11-16 23:21:05 +0000 | [diff] [blame] | 182 | |
| 183 | reparentLayer(11, UNASSIGNED_LAYER_ID); |
| 184 | UPDATE_AND_VERIFY(hierarchyBuilder); |
| 185 | |
| 186 | createLayer(112, 11); |
| 187 | UPDATE_AND_VERIFY(hierarchyBuilder); |
| 188 | |
| 189 | std::vector<uint32_t> expectedTraversalPath = {1, 12, 121, 122, 1221, 13, 2}; |
| 190 | EXPECT_EQ(getTraversalPath(hierarchyBuilder.getHierarchy()), expectedTraversalPath); |
| 191 | EXPECT_EQ(getTraversalPathInZOrder(hierarchyBuilder.getHierarchy()), expectedTraversalPath); |
| 192 | expectedTraversalPath = {11, 111, 112}; |
| 193 | EXPECT_EQ(getTraversalPath(hierarchyBuilder.getOffscreenHierarchy()), expectedTraversalPath); |
| 194 | } |
| 195 | |
| 196 | // rel-z tests |
| 197 | TEST_F(LayerHierarchyTest, setRelativeParent) { |
Vishnu Nair | a029228 | 2023-12-16 14:32:00 -0800 | [diff] [blame] | 198 | LayerHierarchyBuilder hierarchyBuilder; |
| 199 | hierarchyBuilder.update(mLifecycleManager); |
Vishnu Nair | 04f8969 | 2022-11-16 23:21:05 +0000 | [diff] [blame] | 200 | reparentRelativeLayer(11, 2); |
| 201 | UPDATE_AND_VERIFY(hierarchyBuilder); |
| 202 | |
| 203 | std::vector<uint32_t> expectedTraversalPath = {1, 11, 111, 12, 121, 122, 1221, 13, 2, 11, 111}; |
| 204 | EXPECT_EQ(getTraversalPath(hierarchyBuilder.getHierarchy()), expectedTraversalPath); |
| 205 | expectedTraversalPath = {1, 12, 121, 122, 1221, 13, 2, 11, 111}; |
| 206 | EXPECT_EQ(getTraversalPathInZOrder(hierarchyBuilder.getHierarchy()), expectedTraversalPath); |
| 207 | expectedTraversalPath = {}; |
| 208 | EXPECT_EQ(getTraversalPath(hierarchyBuilder.getOffscreenHierarchy()), expectedTraversalPath); |
| 209 | } |
| 210 | |
| 211 | TEST_F(LayerHierarchyTest, reparentFromRelativeParentWithSetLayer) { |
Vishnu Nair | a029228 | 2023-12-16 14:32:00 -0800 | [diff] [blame] | 212 | LayerHierarchyBuilder hierarchyBuilder; |
| 213 | hierarchyBuilder.update(mLifecycleManager); |
Vishnu Nair | 04f8969 | 2022-11-16 23:21:05 +0000 | [diff] [blame] | 214 | reparentRelativeLayer(11, 2); |
| 215 | UPDATE_AND_VERIFY(hierarchyBuilder); |
| 216 | |
Vishnu Nair | 1391de2 | 2023-03-05 19:56:14 -0800 | [diff] [blame] | 217 | // This calls setLayer |
| 218 | removeRelativeZ(11); |
Vishnu Nair | 04f8969 | 2022-11-16 23:21:05 +0000 | [diff] [blame] | 219 | UPDATE_AND_VERIFY(hierarchyBuilder); |
| 220 | |
| 221 | std::vector<uint32_t> expectedTraversalPath = {1, 11, 111, 12, 121, 122, 1221, 13, 2}; |
| 222 | EXPECT_EQ(getTraversalPath(hierarchyBuilder.getHierarchy()), expectedTraversalPath); |
| 223 | EXPECT_EQ(getTraversalPathInZOrder(hierarchyBuilder.getHierarchy()), expectedTraversalPath); |
| 224 | expectedTraversalPath = {}; |
| 225 | EXPECT_EQ(getTraversalPath(hierarchyBuilder.getOffscreenHierarchy()), expectedTraversalPath); |
| 226 | } |
| 227 | |
| 228 | TEST_F(LayerHierarchyTest, reparentToRelativeParent) { |
Vishnu Nair | a029228 | 2023-12-16 14:32:00 -0800 | [diff] [blame] | 229 | LayerHierarchyBuilder hierarchyBuilder; |
| 230 | hierarchyBuilder.update(mLifecycleManager); |
Vishnu Nair | 04f8969 | 2022-11-16 23:21:05 +0000 | [diff] [blame] | 231 | reparentRelativeLayer(11, 2); |
| 232 | UPDATE_AND_VERIFY(hierarchyBuilder); |
| 233 | |
| 234 | reparentLayer(11, 2); |
| 235 | UPDATE_AND_VERIFY(hierarchyBuilder); |
| 236 | |
| 237 | std::vector<uint32_t> expectedTraversalPath = {1, 12, 121, 122, 1221, 13, 2, 11, 111}; |
| 238 | EXPECT_EQ(getTraversalPath(hierarchyBuilder.getHierarchy()), expectedTraversalPath); |
| 239 | EXPECT_EQ(getTraversalPathInZOrder(hierarchyBuilder.getHierarchy()), expectedTraversalPath); |
| 240 | expectedTraversalPath = {}; |
| 241 | EXPECT_EQ(getTraversalPath(hierarchyBuilder.getOffscreenHierarchy()), expectedTraversalPath); |
| 242 | } |
| 243 | |
| 244 | TEST_F(LayerHierarchyTest, setParentAsRelativeParent) { |
Vishnu Nair | a029228 | 2023-12-16 14:32:00 -0800 | [diff] [blame] | 245 | LayerHierarchyBuilder hierarchyBuilder; |
| 246 | hierarchyBuilder.update(mLifecycleManager); |
Vishnu Nair | 04f8969 | 2022-11-16 23:21:05 +0000 | [diff] [blame] | 247 | reparentLayer(11, 2); |
| 248 | UPDATE_AND_VERIFY(hierarchyBuilder); |
| 249 | |
| 250 | reparentRelativeLayer(11, 2); |
| 251 | UPDATE_AND_VERIFY(hierarchyBuilder); |
| 252 | |
| 253 | std::vector<uint32_t> expectedTraversalPath = {1, 12, 121, 122, 1221, 13, 2, 11, 111}; |
| 254 | EXPECT_EQ(getTraversalPath(hierarchyBuilder.getHierarchy()), expectedTraversalPath); |
| 255 | EXPECT_EQ(getTraversalPathInZOrder(hierarchyBuilder.getHierarchy()), expectedTraversalPath); |
| 256 | expectedTraversalPath = {}; |
| 257 | EXPECT_EQ(getTraversalPath(hierarchyBuilder.getOffscreenHierarchy()), expectedTraversalPath); |
| 258 | } |
| 259 | |
| 260 | TEST_F(LayerHierarchyTest, relativeChildMovesOffscreenIsNotTraversable) { |
Vishnu Nair | a029228 | 2023-12-16 14:32:00 -0800 | [diff] [blame] | 261 | LayerHierarchyBuilder hierarchyBuilder; |
| 262 | hierarchyBuilder.update(mLifecycleManager); |
Vishnu Nair | 04f8969 | 2022-11-16 23:21:05 +0000 | [diff] [blame] | 263 | reparentRelativeLayer(11, 2); |
| 264 | UPDATE_AND_VERIFY(hierarchyBuilder); |
| 265 | |
| 266 | reparentLayer(2, UNASSIGNED_LAYER_ID); |
| 267 | UPDATE_AND_VERIFY(hierarchyBuilder); |
| 268 | |
| 269 | std::vector<uint32_t> expectedTraversalPath = {1, 11, 111, 12, 121, 122, 1221, 13}; |
| 270 | EXPECT_EQ(getTraversalPath(hierarchyBuilder.getHierarchy()), expectedTraversalPath); |
| 271 | expectedTraversalPath = {1, 12, 121, 122, 1221, 13}; |
| 272 | EXPECT_EQ(getTraversalPathInZOrder(hierarchyBuilder.getHierarchy()), expectedTraversalPath); |
| 273 | expectedTraversalPath = {2, 11, 111}; |
| 274 | EXPECT_EQ(getTraversalPath(hierarchyBuilder.getOffscreenHierarchy()), expectedTraversalPath); |
| 275 | } |
| 276 | |
Vishnu Nair | fccd636 | 2023-02-24 23:39:53 +0000 | [diff] [blame] | 277 | TEST_F(LayerHierarchyTest, reparentRelativeLayer) { |
Vishnu Nair | a029228 | 2023-12-16 14:32:00 -0800 | [diff] [blame] | 278 | LayerHierarchyBuilder hierarchyBuilder; |
| 279 | hierarchyBuilder.update(mLifecycleManager); |
Vishnu Nair | fccd636 | 2023-02-24 23:39:53 +0000 | [diff] [blame] | 280 | reparentRelativeLayer(11, 2); |
| 281 | UPDATE_AND_VERIFY(hierarchyBuilder); |
| 282 | |
| 283 | std::vector<uint32_t> expectedTraversalPath = {1, 11, 111, 12, 121, 122, 1221, 13, 2, 11, 111}; |
| 284 | EXPECT_EQ(getTraversalPath(hierarchyBuilder.getHierarchy()), expectedTraversalPath); |
| 285 | expectedTraversalPath = {1, 12, 121, 122, 1221, 13, 2, 11, 111}; |
| 286 | EXPECT_EQ(getTraversalPathInZOrder(hierarchyBuilder.getHierarchy()), expectedTraversalPath); |
| 287 | expectedTraversalPath = {}; |
| 288 | EXPECT_EQ(getTraversalPath(hierarchyBuilder.getOffscreenHierarchy()), expectedTraversalPath); |
| 289 | |
| 290 | reparentLayer(11, 1); |
| 291 | UPDATE_AND_VERIFY(hierarchyBuilder); |
| 292 | expectedTraversalPath = {1, 11, 111, 12, 121, 122, 1221, 13, 2, 11, 111}; |
| 293 | EXPECT_EQ(getTraversalPath(hierarchyBuilder.getHierarchy()), expectedTraversalPath); |
| 294 | expectedTraversalPath = {1, 12, 121, 122, 1221, 13, 2, 11, 111}; |
| 295 | EXPECT_EQ(getTraversalPathInZOrder(hierarchyBuilder.getHierarchy()), expectedTraversalPath); |
| 296 | expectedTraversalPath = {}; |
| 297 | EXPECT_EQ(getTraversalPath(hierarchyBuilder.getOffscreenHierarchy()), expectedTraversalPath); |
| 298 | |
| 299 | setZ(11, 0); |
| 300 | UPDATE_AND_VERIFY(hierarchyBuilder); |
| 301 | expectedTraversalPath = {1, 11, 111, 12, 121, 122, 1221, 13, 2}; |
| 302 | EXPECT_EQ(getTraversalPath(hierarchyBuilder.getHierarchy()), expectedTraversalPath); |
| 303 | expectedTraversalPath = {1, 11, 111, 12, 121, 122, 1221, 13, 2}; |
| 304 | EXPECT_EQ(getTraversalPathInZOrder(hierarchyBuilder.getHierarchy()), expectedTraversalPath); |
| 305 | expectedTraversalPath = {}; |
| 306 | EXPECT_EQ(getTraversalPath(hierarchyBuilder.getOffscreenHierarchy()), expectedTraversalPath); |
| 307 | } |
| 308 | |
Vishnu Nair | 04f8969 | 2022-11-16 23:21:05 +0000 | [diff] [blame] | 309 | // mirror tests |
| 310 | TEST_F(LayerHierarchyTest, canTraverseMirrorLayer) { |
Vishnu Nair | a029228 | 2023-12-16 14:32:00 -0800 | [diff] [blame] | 311 | LayerHierarchyBuilder hierarchyBuilder; |
| 312 | hierarchyBuilder.update(mLifecycleManager); |
Vishnu Nair | 04f8969 | 2022-11-16 23:21:05 +0000 | [diff] [blame] | 313 | |
| 314 | mirrorLayer(/*layer*/ 14, /*parent*/ 1, /*layerToMirror*/ 11); |
| 315 | UPDATE_AND_VERIFY(hierarchyBuilder); |
| 316 | |
| 317 | std::vector<uint32_t> expectedTraversalPath = {1, 11, 111, 12, 121, 122, |
| 318 | 1221, 13, 14, 11, 111, 2}; |
| 319 | EXPECT_EQ(getTraversalPath(hierarchyBuilder.getHierarchy()), expectedTraversalPath); |
| 320 | EXPECT_EQ(getTraversalPathInZOrder(hierarchyBuilder.getHierarchy()), expectedTraversalPath); |
| 321 | expectedTraversalPath = {}; |
| 322 | EXPECT_EQ(getTraversalPath(hierarchyBuilder.getOffscreenHierarchy()), expectedTraversalPath); |
| 323 | } |
| 324 | |
| 325 | TEST_F(LayerHierarchyTest, canMirrorOffscreenLayer) { |
Vishnu Nair | a029228 | 2023-12-16 14:32:00 -0800 | [diff] [blame] | 326 | LayerHierarchyBuilder hierarchyBuilder; |
| 327 | hierarchyBuilder.update(mLifecycleManager); |
Vishnu Nair | 04f8969 | 2022-11-16 23:21:05 +0000 | [diff] [blame] | 328 | |
| 329 | reparentLayer(11, UNASSIGNED_LAYER_ID); |
| 330 | mirrorLayer(/*layer*/ 14, /*parent*/ 1, /*layerToMirror*/ 11); |
| 331 | UPDATE_AND_VERIFY(hierarchyBuilder); |
| 332 | |
| 333 | std::vector<uint32_t> expectedTraversalPath = {1, 12, 121, 122, 1221, 13, 14, 11, 111, 2}; |
| 334 | EXPECT_EQ(getTraversalPath(hierarchyBuilder.getHierarchy()), expectedTraversalPath); |
| 335 | EXPECT_EQ(getTraversalPathInZOrder(hierarchyBuilder.getHierarchy()), expectedTraversalPath); |
| 336 | expectedTraversalPath = {11, 111}; |
| 337 | EXPECT_EQ(getTraversalPath(hierarchyBuilder.getOffscreenHierarchy()), expectedTraversalPath); |
| 338 | } |
| 339 | |
| 340 | TEST_F(LayerHierarchyTest, newChildLayerIsUpdatedInMirrorHierarchy) { |
| 341 | mirrorLayer(/*layer*/ 14, /*parent*/ 1, /*layerToMirror*/ 11); |
| 342 | mLifecycleManager.commitChanges(); |
Vishnu Nair | a029228 | 2023-12-16 14:32:00 -0800 | [diff] [blame] | 343 | LayerHierarchyBuilder hierarchyBuilder; |
| 344 | hierarchyBuilder.update(mLifecycleManager); |
Vishnu Nair | 04f8969 | 2022-11-16 23:21:05 +0000 | [diff] [blame] | 345 | |
| 346 | createLayer(1111, 111); |
| 347 | createLayer(112, 11); |
| 348 | UPDATE_AND_VERIFY(hierarchyBuilder); |
| 349 | |
| 350 | std::vector<uint32_t> expectedTraversalPath = {1, 11, 111, 1111, 112, 12, 121, 122, |
| 351 | 1221, 13, 14, 11, 111, 1111, 112, 2}; |
| 352 | EXPECT_EQ(getTraversalPath(hierarchyBuilder.getHierarchy()), expectedTraversalPath); |
| 353 | EXPECT_EQ(getTraversalPathInZOrder(hierarchyBuilder.getHierarchy()), expectedTraversalPath); |
| 354 | expectedTraversalPath = {}; |
| 355 | EXPECT_EQ(getTraversalPath(hierarchyBuilder.getOffscreenHierarchy()), expectedTraversalPath); |
| 356 | } |
| 357 | |
| 358 | // mirror & relatives tests |
| 359 | TEST_F(LayerHierarchyTest, mirrorWithRelativeOutsideMirrorHierarchy) { |
Vishnu Nair | a029228 | 2023-12-16 14:32:00 -0800 | [diff] [blame] | 360 | LayerHierarchyBuilder hierarchyBuilder; |
| 361 | hierarchyBuilder.update(mLifecycleManager); |
Vishnu Nair | 04f8969 | 2022-11-16 23:21:05 +0000 | [diff] [blame] | 362 | reparentRelativeLayer(111, 12); |
| 363 | mirrorLayer(/*layer*/ 14, /*parent*/ 1, /*layerToMirror*/ 11); |
| 364 | |
| 365 | // ROOT |
| 366 | // ├── 1 |
| 367 | // │ ├── 11 |
| 368 | // │ │ └── 111 |
| 369 | // │ ├── 12 |
| 370 | // │ │ ├── 121 |
| 371 | // │ │ ├── 122 |
| 372 | // │ │ │ └── 1221 |
| 373 | // │ │ └ - 111 (relative) |
| 374 | // │ ├── 13 |
| 375 | // │ └── 14 |
| 376 | // │ └ * 11 (mirroring) |
| 377 | // └── 2 |
| 378 | |
| 379 | UPDATE_AND_VERIFY(hierarchyBuilder); |
| 380 | |
| 381 | std::vector<uint32_t> expectedTraversalPath = {1, 11, 111, 12, 111, 121, 122, |
| 382 | 1221, 13, 14, 11, 111, 2}; |
| 383 | EXPECT_EQ(getTraversalPath(hierarchyBuilder.getHierarchy()), expectedTraversalPath); |
| 384 | // 111 is not reachable in the mirror |
| 385 | expectedTraversalPath = {1, 11, 12, 111, 121, 122, 1221, 13, 14, 11, 2}; |
| 386 | EXPECT_EQ(getTraversalPathInZOrder(hierarchyBuilder.getHierarchy()), expectedTraversalPath); |
| 387 | expectedTraversalPath = {}; |
| 388 | EXPECT_EQ(getTraversalPath(hierarchyBuilder.getOffscreenHierarchy()), expectedTraversalPath); |
| 389 | } |
| 390 | |
| 391 | TEST_F(LayerHierarchyTest, mirrorWithRelativeInsideMirrorHierarchy) { |
Vishnu Nair | a029228 | 2023-12-16 14:32:00 -0800 | [diff] [blame] | 392 | LayerHierarchyBuilder hierarchyBuilder; |
| 393 | hierarchyBuilder.update(mLifecycleManager); |
Vishnu Nair | 04f8969 | 2022-11-16 23:21:05 +0000 | [diff] [blame] | 394 | reparentRelativeLayer(1221, 12); |
| 395 | mirrorLayer(/*layer*/ 14, /*parent*/ 1, /*layerToMirror*/ 12); |
| 396 | |
| 397 | // ROOT |
| 398 | // ├── 1 |
| 399 | // │ ├── 11 |
| 400 | // │ │ └── 111 |
| 401 | // │ ├── 12 |
| 402 | // │ │ ├── 121 |
| 403 | // │ │ ├── 122 |
| 404 | // │ │ │ └── 1221 |
| 405 | // │ │ └ - 1221 (relative) |
| 406 | // │ ├── 13 |
| 407 | // │ └── 14 |
| 408 | // │ └ * 12 (mirroring) |
| 409 | // └── 2 |
| 410 | |
| 411 | UPDATE_AND_VERIFY(hierarchyBuilder); |
| 412 | std::vector<uint32_t> expectedTraversalPath = {1, 11, 111, 12, 121, 122, 1221, 1221, |
| 413 | 13, 14, 12, 121, 122, 1221, 1221, 2}; |
| 414 | EXPECT_EQ(getTraversalPath(hierarchyBuilder.getHierarchy()), expectedTraversalPath); |
| 415 | // relative layer 1221 is traversable in the mirrored hierarchy as well |
| 416 | expectedTraversalPath = {1, 11, 111, 12, 121, 122, 1221, 13, 14, 12, 121, 122, 1221, 2}; |
| 417 | EXPECT_EQ(getTraversalPathInZOrder(hierarchyBuilder.getHierarchy()), expectedTraversalPath); |
| 418 | expectedTraversalPath = {}; |
| 419 | EXPECT_EQ(getTraversalPath(hierarchyBuilder.getOffscreenHierarchy()), expectedTraversalPath); |
| 420 | } |
| 421 | |
| 422 | TEST_F(LayerHierarchyTest, childMovesOffscreenWhenRelativeParentDies) { |
Vishnu Nair | a029228 | 2023-12-16 14:32:00 -0800 | [diff] [blame] | 423 | LayerHierarchyBuilder hierarchyBuilder; |
| 424 | hierarchyBuilder.update(mLifecycleManager); |
Vishnu Nair | 04f8969 | 2022-11-16 23:21:05 +0000 | [diff] [blame] | 425 | |
| 426 | reparentRelativeLayer(11, 2); |
| 427 | reparentLayer(2, UNASSIGNED_LAYER_ID); |
| 428 | destroyLayerHandle(2); |
| 429 | |
| 430 | UPDATE_AND_VERIFY(hierarchyBuilder); |
| 431 | std::vector<uint32_t> expectedTraversalPath = {1, 11, 111, 12, 121, 122, 1221, 13}; |
| 432 | EXPECT_EQ(getTraversalPath(hierarchyBuilder.getHierarchy()), expectedTraversalPath); |
| 433 | expectedTraversalPath = {1, 12, 121, 122, 1221, 13}; |
| 434 | EXPECT_EQ(getTraversalPathInZOrder(hierarchyBuilder.getHierarchy()), expectedTraversalPath); |
| 435 | expectedTraversalPath = {11, 111}; |
| 436 | EXPECT_EQ(getTraversalPath(hierarchyBuilder.getOffscreenHierarchy()), expectedTraversalPath); |
| 437 | |
| 438 | // remove relative parent so layer becomes onscreen again |
Vishnu Nair | 1391de2 | 2023-03-05 19:56:14 -0800 | [diff] [blame] | 439 | removeRelativeZ(11); |
Vishnu Nair | 04f8969 | 2022-11-16 23:21:05 +0000 | [diff] [blame] | 440 | UPDATE_AND_VERIFY(hierarchyBuilder); |
| 441 | |
| 442 | expectedTraversalPath = {1, 11, 111, 12, 121, 122, 1221, 13}; |
| 443 | EXPECT_EQ(getTraversalPath(hierarchyBuilder.getHierarchy()), expectedTraversalPath); |
| 444 | EXPECT_EQ(getTraversalPathInZOrder(hierarchyBuilder.getHierarchy()), expectedTraversalPath); |
| 445 | expectedTraversalPath = {}; |
| 446 | EXPECT_EQ(getTraversalPath(hierarchyBuilder.getOffscreenHierarchy()), expectedTraversalPath); |
| 447 | } |
| 448 | |
| 449 | TEST_F(LayerHierarchyTest, offscreenLayerCannotBeRelativeToOnscreenLayer) { |
Vishnu Nair | a029228 | 2023-12-16 14:32:00 -0800 | [diff] [blame] | 450 | LayerHierarchyBuilder hierarchyBuilder; |
| 451 | hierarchyBuilder.update(mLifecycleManager); |
Vishnu Nair | 04f8969 | 2022-11-16 23:21:05 +0000 | [diff] [blame] | 452 | reparentRelativeLayer(1221, 2); |
| 453 | UPDATE_AND_VERIFY(hierarchyBuilder); |
| 454 | |
| 455 | // verify relz path |
| 456 | std::vector<uint32_t> expectedTraversalPath = {1, 11, 111, 12, 121, 122, 1221, 13, 2, 1221}; |
| 457 | EXPECT_EQ(getTraversalPath(hierarchyBuilder.getHierarchy()), expectedTraversalPath); |
| 458 | expectedTraversalPath = {1, 11, 111, 12, 121, 122, 13, 2, 1221}; |
| 459 | EXPECT_EQ(getTraversalPathInZOrder(hierarchyBuilder.getHierarchy()), expectedTraversalPath); |
| 460 | expectedTraversalPath = {}; |
| 461 | EXPECT_EQ(getTraversalPath(hierarchyBuilder.getOffscreenHierarchy()), expectedTraversalPath); |
| 462 | |
| 463 | // offscreen layer cannot be reached as a relative child |
| 464 | reparentLayer(12, UNASSIGNED_LAYER_ID); |
| 465 | UPDATE_AND_VERIFY(hierarchyBuilder); |
| 466 | |
| 467 | expectedTraversalPath = {1, 11, 111, 13, 2}; |
| 468 | EXPECT_EQ(getTraversalPath(hierarchyBuilder.getHierarchy()), expectedTraversalPath); |
| 469 | EXPECT_EQ(getTraversalPathInZOrder(hierarchyBuilder.getHierarchy()), expectedTraversalPath); |
| 470 | expectedTraversalPath = {12, 121, 122, 1221}; |
| 471 | EXPECT_EQ(getTraversalPath(hierarchyBuilder.getOffscreenHierarchy()), expectedTraversalPath); |
| 472 | |
| 473 | // layer when onscreen can be reached as a relative child again |
| 474 | reparentLayer(12, 1); |
| 475 | UPDATE_AND_VERIFY(hierarchyBuilder); |
| 476 | |
| 477 | expectedTraversalPath = {1, 11, 111, 12, 121, 122, 1221, 13, 2, 1221}; |
| 478 | EXPECT_EQ(getTraversalPath(hierarchyBuilder.getHierarchy()), expectedTraversalPath); |
| 479 | expectedTraversalPath = {1, 11, 111, 12, 121, 122, 13, 2, 1221}; |
| 480 | EXPECT_EQ(getTraversalPathInZOrder(hierarchyBuilder.getHierarchy()), expectedTraversalPath); |
| 481 | expectedTraversalPath = {}; |
| 482 | EXPECT_EQ(getTraversalPath(hierarchyBuilder.getOffscreenHierarchy()), expectedTraversalPath); |
| 483 | } |
| 484 | |
| 485 | TEST_F(LayerHierarchyTest, backgroundLayersAreBehindParentLayer) { |
Vishnu Nair | a029228 | 2023-12-16 14:32:00 -0800 | [diff] [blame] | 486 | LayerHierarchyBuilder hierarchyBuilder; |
| 487 | hierarchyBuilder.update(mLifecycleManager); |
Vishnu Nair | 04f8969 | 2022-11-16 23:21:05 +0000 | [diff] [blame] | 488 | |
| 489 | updateBackgroundColor(1, 0.5); |
| 490 | UPDATE_AND_VERIFY(hierarchyBuilder); |
Vishnu Nair | 150065b | 2023-04-17 19:14:11 -0700 | [diff] [blame] | 491 | auto hierarchy = hierarchyBuilder.getPartialHierarchy(1, /*childrenOnly=*/true); |
| 492 | auto bgLayerId = hierarchy.mChildren.front().first->getLayer()->id; |
Vishnu Nair | d47bcee | 2023-02-24 18:08:51 +0000 | [diff] [blame] | 493 | std::vector<uint32_t> expectedTraversalPath = {1, bgLayerId, 11, 111, 12, |
| 494 | 121, 122, 1221, 13, 2}; |
Vishnu Nair | 04f8969 | 2022-11-16 23:21:05 +0000 | [diff] [blame] | 495 | EXPECT_EQ(getTraversalPath(hierarchyBuilder.getHierarchy()), expectedTraversalPath); |
Vishnu Nair | d47bcee | 2023-02-24 18:08:51 +0000 | [diff] [blame] | 496 | expectedTraversalPath = {bgLayerId, 1, 11, 111, 12, 121, 122, 1221, 13, 2}; |
Vishnu Nair | 04f8969 | 2022-11-16 23:21:05 +0000 | [diff] [blame] | 497 | EXPECT_EQ(getTraversalPathInZOrder(hierarchyBuilder.getHierarchy()), expectedTraversalPath); |
| 498 | expectedTraversalPath = {}; |
| 499 | EXPECT_EQ(getTraversalPath(hierarchyBuilder.getOffscreenHierarchy()), expectedTraversalPath); |
| 500 | } |
| 501 | |
| 502 | // cycle tests |
| 503 | TEST_F(LayerHierarchyTest, ParentBecomesTheChild) { |
| 504 | // remove default hierarchy |
| 505 | mLifecycleManager = LayerLifecycleManager(); |
| 506 | createRootLayer(1); |
| 507 | createLayer(11, 1); |
| 508 | reparentLayer(1, 11); |
| 509 | mLifecycleManager.commitChanges(); |
Vishnu Nair | a029228 | 2023-12-16 14:32:00 -0800 | [diff] [blame] | 510 | LayerHierarchyBuilder hierarchyBuilder; |
| 511 | hierarchyBuilder.update(mLifecycleManager); |
Vishnu Nair | 04f8969 | 2022-11-16 23:21:05 +0000 | [diff] [blame] | 512 | |
| 513 | std::vector<uint32_t> expectedTraversalPath = {}; |
| 514 | EXPECT_EQ(getTraversalPath(hierarchyBuilder.getHierarchy()), expectedTraversalPath); |
| 515 | EXPECT_EQ(getTraversalPathInZOrder(hierarchyBuilder.getHierarchy()), expectedTraversalPath); |
| 516 | expectedTraversalPath = {}; |
| 517 | EXPECT_EQ(getTraversalPath(hierarchyBuilder.getOffscreenHierarchy()), expectedTraversalPath); |
| 518 | } |
| 519 | |
| 520 | TEST_F(LayerHierarchyTest, RelativeLoops) { |
| 521 | // remove default hierarchy |
| 522 | mLifecycleManager = LayerLifecycleManager(); |
| 523 | createRootLayer(1); |
| 524 | createRootLayer(2); |
| 525 | createLayer(11, 1); |
| 526 | reparentRelativeLayer(11, 2); |
| 527 | reparentRelativeLayer(2, 11); |
Vishnu Nair | a029228 | 2023-12-16 14:32:00 -0800 | [diff] [blame] | 528 | LayerHierarchyBuilder hierarchyBuilder; |
| 529 | // this call is expected to fix the loop! |
| 530 | hierarchyBuilder.update(mLifecycleManager); |
| 531 | uint32_t unused; |
| 532 | EXPECT_FALSE(hierarchyBuilder.getHierarchy().hasRelZLoop(unused)); |
Vishnu Nair | 04f8969 | 2022-11-16 23:21:05 +0000 | [diff] [blame] | 533 | |
| 534 | std::vector<uint32_t> expectedTraversalPath = {1, 11, 2, 2}; |
| 535 | EXPECT_EQ(getTraversalPath(hierarchyBuilder.getHierarchy()), expectedTraversalPath); |
| 536 | expectedTraversalPath = {1}; |
| 537 | EXPECT_EQ(getTraversalPathInZOrder(hierarchyBuilder.getHierarchy()), expectedTraversalPath); |
| 538 | expectedTraversalPath = {11, 2}; |
| 539 | EXPECT_EQ(getTraversalPath(hierarchyBuilder.getOffscreenHierarchy()), expectedTraversalPath); |
| 540 | } |
| 541 | |
| 542 | TEST_F(LayerHierarchyTest, IndirectRelativeLoops) { |
| 543 | // remove default hierarchy |
| 544 | mLifecycleManager = LayerLifecycleManager(); |
| 545 | createRootLayer(1); |
| 546 | createRootLayer(2); |
| 547 | createLayer(11, 1); |
| 548 | createLayer(111, 11); |
| 549 | createLayer(21, 2); |
| 550 | createLayer(22, 2); |
| 551 | createLayer(221, 22); |
| 552 | reparentRelativeLayer(22, 111); |
| 553 | reparentRelativeLayer(11, 221); |
Vishnu Nair | a029228 | 2023-12-16 14:32:00 -0800 | [diff] [blame] | 554 | LayerHierarchyBuilder hierarchyBuilder; |
| 555 | // this call is expected to fix the loop! |
| 556 | hierarchyBuilder.update(mLifecycleManager); |
| 557 | uint32_t unused; |
| 558 | EXPECT_FALSE(hierarchyBuilder.getHierarchy().hasRelZLoop(unused)); |
Vishnu Nair | 04f8969 | 2022-11-16 23:21:05 +0000 | [diff] [blame] | 559 | |
| 560 | std::vector<uint32_t> expectedTraversalPath = {1, 11, 111, 22, 221, 2, 21, 22, 221}; |
| 561 | EXPECT_EQ(getTraversalPath(hierarchyBuilder.getHierarchy()), expectedTraversalPath); |
| 562 | expectedTraversalPath = {1, 2, 21}; |
| 563 | EXPECT_EQ(getTraversalPathInZOrder(hierarchyBuilder.getHierarchy()), expectedTraversalPath); |
| 564 | expectedTraversalPath = {11, 111, 22, 221}; |
| 565 | EXPECT_EQ(getTraversalPath(hierarchyBuilder.getOffscreenHierarchy()), expectedTraversalPath); |
| 566 | } |
| 567 | |
| 568 | TEST_F(LayerHierarchyTest, ReparentRootLayerToNull) { |
Vishnu Nair | a029228 | 2023-12-16 14:32:00 -0800 | [diff] [blame] | 569 | LayerHierarchyBuilder hierarchyBuilder; |
| 570 | hierarchyBuilder.update(mLifecycleManager); |
Vishnu Nair | 04f8969 | 2022-11-16 23:21:05 +0000 | [diff] [blame] | 571 | reparentLayer(1, UNASSIGNED_LAYER_ID); |
| 572 | UPDATE_AND_VERIFY(hierarchyBuilder); |
| 573 | |
| 574 | std::vector<uint32_t> expectedTraversalPath = {2}; |
| 575 | EXPECT_EQ(getTraversalPath(hierarchyBuilder.getHierarchy()), expectedTraversalPath); |
| 576 | EXPECT_EQ(getTraversalPathInZOrder(hierarchyBuilder.getHierarchy()), expectedTraversalPath); |
| 577 | expectedTraversalPath = {1, 11, 111, 12, 121, 122, 1221, 13}; |
| 578 | EXPECT_EQ(getTraversalPath(hierarchyBuilder.getOffscreenHierarchy()), expectedTraversalPath); |
| 579 | } |
| 580 | |
| 581 | TEST_F(LayerHierarchyTest, AddRemoveLayerInSameTransaction) { |
| 582 | // remove default hierarchy |
| 583 | mLifecycleManager = LayerLifecycleManager(); |
Vishnu Nair | a029228 | 2023-12-16 14:32:00 -0800 | [diff] [blame] | 584 | LayerHierarchyBuilder hierarchyBuilder; |
| 585 | hierarchyBuilder.update(mLifecycleManager); |
Vishnu Nair | 04f8969 | 2022-11-16 23:21:05 +0000 | [diff] [blame] | 586 | createRootLayer(1); |
| 587 | destroyLayerHandle(1); |
| 588 | UPDATE_AND_VERIFY(hierarchyBuilder); |
| 589 | |
| 590 | std::vector<uint32_t> expectedTraversalPath = {}; |
| 591 | EXPECT_EQ(getTraversalPath(hierarchyBuilder.getHierarchy()), expectedTraversalPath); |
| 592 | EXPECT_EQ(getTraversalPathInZOrder(hierarchyBuilder.getHierarchy()), expectedTraversalPath); |
| 593 | EXPECT_EQ(getTraversalPath(hierarchyBuilder.getOffscreenHierarchy()), expectedTraversalPath); |
| 594 | } |
| 595 | |
| 596 | // traversal path test |
| 597 | TEST_F(LayerHierarchyTest, traversalPathId) { |
| 598 | setZ(122, -1); |
Vishnu Nair | a029228 | 2023-12-16 14:32:00 -0800 | [diff] [blame] | 599 | LayerHierarchyBuilder hierarchyBuilder; |
| 600 | hierarchyBuilder.update(mLifecycleManager); |
Vishnu Nair | 04f8969 | 2022-11-16 23:21:05 +0000 | [diff] [blame] | 601 | auto checkTraversalPathIdVisitor = |
| 602 | [](const LayerHierarchy& hierarchy, |
| 603 | const LayerHierarchy::TraversalPath& traversalPath) -> bool { |
| 604 | EXPECT_EQ(hierarchy.getLayer()->id, traversalPath.id); |
| 605 | return true; |
| 606 | }; |
| 607 | hierarchyBuilder.getHierarchy().traverse(checkTraversalPathIdVisitor); |
| 608 | hierarchyBuilder.getHierarchy().traverseInZOrder(checkTraversalPathIdVisitor); |
| 609 | } |
| 610 | |
Vishnu Nair | cfb2d25 | 2023-01-19 04:44:02 +0000 | [diff] [blame] | 611 | TEST_F(LayerHierarchyTest, zorderRespectsLayerSequenceId) { |
| 612 | // remove default hierarchy |
| 613 | mLifecycleManager = LayerLifecycleManager(); |
| 614 | createRootLayer(1); |
| 615 | createRootLayer(2); |
| 616 | createRootLayer(4); |
| 617 | createRootLayer(5); |
| 618 | createLayer(11, 1); |
| 619 | createLayer(51, 5); |
| 620 | createLayer(53, 5); |
| 621 | |
| 622 | mLifecycleManager.commitChanges(); |
Vishnu Nair | a029228 | 2023-12-16 14:32:00 -0800 | [diff] [blame] | 623 | LayerHierarchyBuilder hierarchyBuilder; |
| 624 | hierarchyBuilder.update(mLifecycleManager); |
Vishnu Nair | cfb2d25 | 2023-01-19 04:44:02 +0000 | [diff] [blame] | 625 | UPDATE_AND_VERIFY(hierarchyBuilder); |
| 626 | std::vector<uint32_t> expectedTraversalPath = {1, 11, 2, 4, 5, 51, 53}; |
| 627 | EXPECT_EQ(getTraversalPath(hierarchyBuilder.getHierarchy()), expectedTraversalPath); |
| 628 | |
| 629 | EXPECT_EQ(getTraversalPathInZOrder(hierarchyBuilder.getHierarchy()), expectedTraversalPath); |
| 630 | expectedTraversalPath = {}; |
| 631 | EXPECT_EQ(getTraversalPath(hierarchyBuilder.getOffscreenHierarchy()), expectedTraversalPath); |
| 632 | |
| 633 | // A new layer is added with a smaller sequence id. Make sure its sorted correctly. While |
| 634 | // sequence ids are always incremented, this scenario can happen when a layer is reparented. |
| 635 | createRootLayer(3); |
| 636 | createLayer(52, 5); |
| 637 | |
| 638 | UPDATE_AND_VERIFY(hierarchyBuilder); |
| 639 | expectedTraversalPath = {1, 11, 2, 3, 4, 5, 51, 52, 53}; |
| 640 | EXPECT_EQ(getTraversalPath(hierarchyBuilder.getHierarchy()), expectedTraversalPath); |
| 641 | EXPECT_EQ(getTraversalPathInZOrder(hierarchyBuilder.getHierarchy()), expectedTraversalPath); |
| 642 | expectedTraversalPath = {}; |
| 643 | EXPECT_EQ(getTraversalPath(hierarchyBuilder.getOffscreenHierarchy()), expectedTraversalPath); |
| 644 | } |
| 645 | |
| 646 | TEST_F(LayerHierarchyTest, zorderRespectsLayerZ) { |
| 647 | // remove default hierarchy |
| 648 | mLifecycleManager = LayerLifecycleManager(); |
| 649 | createRootLayer(1); |
| 650 | createLayer(11, 1); |
| 651 | createLayer(12, 1); |
| 652 | createLayer(13, 1); |
| 653 | setZ(11, -1); |
| 654 | setZ(12, 2); |
| 655 | setZ(13, 1); |
| 656 | |
| 657 | mLifecycleManager.commitChanges(); |
Vishnu Nair | a029228 | 2023-12-16 14:32:00 -0800 | [diff] [blame] | 658 | LayerHierarchyBuilder hierarchyBuilder; |
| 659 | hierarchyBuilder.update(mLifecycleManager); |
Vishnu Nair | cfb2d25 | 2023-01-19 04:44:02 +0000 | [diff] [blame] | 660 | UPDATE_AND_VERIFY(hierarchyBuilder); |
| 661 | std::vector<uint32_t> expectedTraversalPath = {1, 11, 13, 12}; |
| 662 | EXPECT_EQ(getTraversalPath(hierarchyBuilder.getHierarchy()), expectedTraversalPath); |
| 663 | |
| 664 | expectedTraversalPath = {11, 1, 13, 12}; |
| 665 | EXPECT_EQ(getTraversalPathInZOrder(hierarchyBuilder.getHierarchy()), expectedTraversalPath); |
| 666 | expectedTraversalPath = {}; |
| 667 | EXPECT_EQ(getTraversalPath(hierarchyBuilder.getOffscreenHierarchy()), expectedTraversalPath); |
| 668 | } |
| 669 | |
| 670 | TEST_F(LayerHierarchyTest, zorderRespectsLayerStack) { |
| 671 | // remove default hierarchy |
| 672 | mLifecycleManager = LayerLifecycleManager(); |
| 673 | createRootLayer(1); |
| 674 | createRootLayer(2); |
| 675 | createLayer(11, 1); |
| 676 | createLayer(21, 2); |
| 677 | setLayerStack(1, 20); |
| 678 | setLayerStack(2, 10); |
| 679 | |
| 680 | mLifecycleManager.commitChanges(); |
Vishnu Nair | a029228 | 2023-12-16 14:32:00 -0800 | [diff] [blame] | 681 | LayerHierarchyBuilder hierarchyBuilder; |
| 682 | hierarchyBuilder.update(mLifecycleManager); |
Vishnu Nair | cfb2d25 | 2023-01-19 04:44:02 +0000 | [diff] [blame] | 683 | UPDATE_AND_VERIFY(hierarchyBuilder); |
Vishnu Nair | 444f395 | 2023-04-11 13:01:02 -0700 | [diff] [blame] | 684 | std::vector<uint32_t> expectedTraversalPath = {2, 21, 1, 11}; |
Vishnu Nair | cfb2d25 | 2023-01-19 04:44:02 +0000 | [diff] [blame] | 685 | EXPECT_EQ(getTraversalPath(hierarchyBuilder.getHierarchy()), expectedTraversalPath); |
| 686 | |
Vishnu Nair | cfb2d25 | 2023-01-19 04:44:02 +0000 | [diff] [blame] | 687 | EXPECT_EQ(getTraversalPathInZOrder(hierarchyBuilder.getHierarchy()), expectedTraversalPath); |
| 688 | expectedTraversalPath = {}; |
| 689 | EXPECT_EQ(getTraversalPath(hierarchyBuilder.getOffscreenHierarchy()), expectedTraversalPath); |
| 690 | } |
| 691 | |
Vishnu Nair | a9c4376 | 2023-01-27 19:10:25 +0000 | [diff] [blame] | 692 | TEST_F(LayerHierarchyTest, canMirrorDisplay) { |
Vishnu Nair | a029228 | 2023-12-16 14:32:00 -0800 | [diff] [blame] | 693 | LayerHierarchyBuilder hierarchyBuilder; |
| 694 | hierarchyBuilder.update(mLifecycleManager); |
Vishnu Nair | a9c4376 | 2023-01-27 19:10:25 +0000 | [diff] [blame] | 695 | setFlags(12, layer_state_t::eLayerSkipScreenshot, layer_state_t::eLayerSkipScreenshot); |
| 696 | createDisplayMirrorLayer(3, ui::LayerStack::fromValue(0)); |
| 697 | setLayerStack(3, 1); |
| 698 | UPDATE_AND_VERIFY(hierarchyBuilder); |
| 699 | |
Vishnu Nair | 444f395 | 2023-04-11 13:01:02 -0700 | [diff] [blame] | 700 | std::vector<uint32_t> expected = {1, 11, 111, 12, 121, 122, 1221, 13, 2, 3, |
| 701 | 1, 11, 111, 12, 121, 122, 1221, 13, 2}; |
Vishnu Nair | a9c4376 | 2023-01-27 19:10:25 +0000 | [diff] [blame] | 702 | EXPECT_EQ(getTraversalPath(hierarchyBuilder.getHierarchy()), expected); |
| 703 | EXPECT_EQ(getTraversalPathInZOrder(hierarchyBuilder.getHierarchy()), expected); |
| 704 | expected = {}; |
| 705 | EXPECT_EQ(getTraversalPath(hierarchyBuilder.getOffscreenHierarchy()), expected); |
| 706 | } |
| 707 | |
| 708 | TEST_F(LayerHierarchyTest, mirrorNonExistingDisplay) { |
Vishnu Nair | a029228 | 2023-12-16 14:32:00 -0800 | [diff] [blame] | 709 | LayerHierarchyBuilder hierarchyBuilder; |
| 710 | hierarchyBuilder.update(mLifecycleManager); |
Vishnu Nair | a9c4376 | 2023-01-27 19:10:25 +0000 | [diff] [blame] | 711 | setFlags(12, layer_state_t::eLayerSkipScreenshot, layer_state_t::eLayerSkipScreenshot); |
| 712 | createDisplayMirrorLayer(3, ui::LayerStack::fromValue(5)); |
| 713 | setLayerStack(3, 1); |
| 714 | UPDATE_AND_VERIFY(hierarchyBuilder); |
| 715 | |
Vishnu Nair | 444f395 | 2023-04-11 13:01:02 -0700 | [diff] [blame] | 716 | std::vector<uint32_t> expected = {1, 11, 111, 12, 121, 122, 1221, 13, 2, 3}; |
Vishnu Nair | a9c4376 | 2023-01-27 19:10:25 +0000 | [diff] [blame] | 717 | EXPECT_EQ(getTraversalPath(hierarchyBuilder.getHierarchy()), expected); |
| 718 | EXPECT_EQ(getTraversalPathInZOrder(hierarchyBuilder.getHierarchy()), expected); |
| 719 | expected = {}; |
| 720 | EXPECT_EQ(getTraversalPath(hierarchyBuilder.getOffscreenHierarchy()), expected); |
| 721 | } |
| 722 | |
| 723 | TEST_F(LayerHierarchyTest, newRootLayerIsMirrored) { |
Vishnu Nair | a029228 | 2023-12-16 14:32:00 -0800 | [diff] [blame] | 724 | LayerHierarchyBuilder hierarchyBuilder; |
| 725 | hierarchyBuilder.update(mLifecycleManager); |
Vishnu Nair | a9c4376 | 2023-01-27 19:10:25 +0000 | [diff] [blame] | 726 | setFlags(12, layer_state_t::eLayerSkipScreenshot, layer_state_t::eLayerSkipScreenshot); |
| 727 | createDisplayMirrorLayer(3, ui::LayerStack::fromValue(0)); |
| 728 | setLayerStack(3, 1); |
| 729 | UPDATE_AND_VERIFY(hierarchyBuilder); |
| 730 | |
| 731 | createRootLayer(4); |
| 732 | UPDATE_AND_VERIFY(hierarchyBuilder); |
| 733 | |
Vishnu Nair | 444f395 | 2023-04-11 13:01:02 -0700 | [diff] [blame] | 734 | std::vector<uint32_t> expected = {1, 11, 111, 12, 121, 122, 1221, 13, 2, 4, 3, |
| 735 | 1, 11, 111, 12, 121, 122, 1221, 13, 2, 4}; |
Vishnu Nair | a9c4376 | 2023-01-27 19:10:25 +0000 | [diff] [blame] | 736 | EXPECT_EQ(getTraversalPath(hierarchyBuilder.getHierarchy()), expected); |
| 737 | EXPECT_EQ(getTraversalPathInZOrder(hierarchyBuilder.getHierarchy()), expected); |
| 738 | expected = {}; |
| 739 | EXPECT_EQ(getTraversalPath(hierarchyBuilder.getOffscreenHierarchy()), expected); |
| 740 | } |
| 741 | |
| 742 | TEST_F(LayerHierarchyTest, removedRootLayerIsNoLongerMirrored) { |
Vishnu Nair | a029228 | 2023-12-16 14:32:00 -0800 | [diff] [blame] | 743 | LayerHierarchyBuilder hierarchyBuilder; |
| 744 | hierarchyBuilder.update(mLifecycleManager); |
Vishnu Nair | a9c4376 | 2023-01-27 19:10:25 +0000 | [diff] [blame] | 745 | setFlags(12, layer_state_t::eLayerSkipScreenshot, layer_state_t::eLayerSkipScreenshot); |
| 746 | createDisplayMirrorLayer(3, ui::LayerStack::fromValue(0)); |
| 747 | setLayerStack(3, 1); |
| 748 | UPDATE_AND_VERIFY(hierarchyBuilder); |
| 749 | |
| 750 | reparentLayer(1, UNASSIGNED_LAYER_ID); |
| 751 | destroyLayerHandle(1); |
| 752 | UPDATE_AND_VERIFY(hierarchyBuilder); |
| 753 | |
Vishnu Nair | 444f395 | 2023-04-11 13:01:02 -0700 | [diff] [blame] | 754 | std::vector<uint32_t> expected = {2, 3, 2}; |
Vishnu Nair | a9c4376 | 2023-01-27 19:10:25 +0000 | [diff] [blame] | 755 | EXPECT_EQ(getTraversalPath(hierarchyBuilder.getHierarchy()), expected); |
| 756 | EXPECT_EQ(getTraversalPathInZOrder(hierarchyBuilder.getHierarchy()), expected); |
| 757 | expected = {11, 111, 12, 121, 122, 1221, 13}; |
| 758 | EXPECT_EQ(getTraversalPath(hierarchyBuilder.getOffscreenHierarchy()), expected); |
| 759 | } |
| 760 | |
Vishnu Nair | 6f87831 | 2023-09-08 11:05:01 -0700 | [diff] [blame] | 761 | TEST_F(LayerHierarchyTest, canMirrorDisplayWithMirrors) { |
Vishnu Nair | a029228 | 2023-12-16 14:32:00 -0800 | [diff] [blame] | 762 | LayerHierarchyBuilder hierarchyBuilder; |
| 763 | hierarchyBuilder.update(mLifecycleManager); |
Vishnu Nair | 6f87831 | 2023-09-08 11:05:01 -0700 | [diff] [blame] | 764 | reparentLayer(12, UNASSIGNED_LAYER_ID); |
| 765 | mirrorLayer(/*layer*/ 14, /*parent*/ 1, /*layerToMirror*/ 11); |
| 766 | UPDATE_AND_VERIFY(hierarchyBuilder); |
| 767 | |
| 768 | createDisplayMirrorLayer(3, ui::LayerStack::fromValue(0)); |
| 769 | setLayerStack(3, 1); |
| 770 | UPDATE_AND_VERIFY(hierarchyBuilder); |
| 771 | |
| 772 | std::vector<uint32_t> expected = {1, 11, 111, 13, 14, 11, 111, 2, 3, |
| 773 | 1, 11, 111, 13, 14, 11, 111, 2}; |
| 774 | EXPECT_EQ(getTraversalPath(hierarchyBuilder.getHierarchy()), expected); |
| 775 | EXPECT_EQ(getTraversalPathInZOrder(hierarchyBuilder.getHierarchy()), expected); |
| 776 | expected = {12, 121, 122, 1221}; |
| 777 | EXPECT_EQ(getTraversalPath(hierarchyBuilder.getOffscreenHierarchy()), expected); |
| 778 | } |
| 779 | |
Vishnu Nair | 04f8969 | 2022-11-16 23:21:05 +0000 | [diff] [blame] | 780 | } // namespace android::surfaceflinger::frontend |