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 | 0808ae6 | 2023-08-07 21:42:42 -0700 | [diff] [blame] | 20 | #include <gui/fake/BufferData.h> |
Vishnu Nair | 47b7bb4 | 2023-09-29 16:27:33 -0700 | [diff] [blame] | 21 | #include <renderengine/mock/FakeExternalTexture.h> |
Vishnu Nair | d9e4f46 | 2023-10-06 04:05:45 +0000 | [diff] [blame] | 22 | #include <ui/ShadowSettings.h> |
Vishnu Nair | 0808ae6 | 2023-08-07 21:42:42 -0700 | [diff] [blame] | 23 | |
Vishnu Nair | 1391de2 | 2023-03-05 19:56:14 -0800 | [diff] [blame] | 24 | #include "Client.h" // temporarily needed for LayerCreationArgs |
| 25 | #include "FrontEnd/LayerCreationArgs.h" |
Vishnu Nair | 8fc721b | 2022-12-22 20:06:32 +0000 | [diff] [blame] | 26 | #include "FrontEnd/LayerHierarchy.h" |
| 27 | #include "FrontEnd/LayerLifecycleManager.h" |
Vishnu Nair | 532d645 | 2024-07-14 22:05:12 -0700 | [diff] [blame] | 28 | #include "LayerLifecycleManagerHelper.h" |
| 29 | |
Vishnu Nair | 47b7bb4 | 2023-09-29 16:27:33 -0700 | [diff] [blame] | 30 | #include "FrontEnd/LayerSnapshotBuilder.h" |
Vishnu Nair | 8fc721b | 2022-12-22 20:06:32 +0000 | [diff] [blame] | 31 | |
| 32 | namespace android::surfaceflinger::frontend { |
| 33 | |
Vishnu Nair | 532d645 | 2024-07-14 22:05:12 -0700 | [diff] [blame] | 34 | class LayerHierarchyTestBase : public testing::Test, public LayerLifecycleManagerHelper { |
Vishnu Nair | 8fc721b | 2022-12-22 20:06:32 +0000 | [diff] [blame] | 35 | protected: |
Vishnu Nair | 532d645 | 2024-07-14 22:05:12 -0700 | [diff] [blame] | 36 | LayerHierarchyTestBase() : LayerLifecycleManagerHelper(mLifecycleManager) { |
Vishnu Nair | 8fc721b | 2022-12-22 20:06:32 +0000 | [diff] [blame] | 37 | // tree with 3 levels of children |
| 38 | // ROOT |
| 39 | // ├── 1 |
| 40 | // │ ├── 11 |
| 41 | // │ │ └── 111 |
| 42 | // │ ├── 12 |
| 43 | // │ │ ├── 121 |
| 44 | // │ │ └── 122 |
| 45 | // │ │ └── 1221 |
| 46 | // │ └── 13 |
| 47 | // └── 2 |
| 48 | |
| 49 | createRootLayer(1); |
| 50 | createRootLayer(2); |
| 51 | createLayer(11, 1); |
| 52 | createLayer(12, 1); |
| 53 | createLayer(13, 1); |
| 54 | createLayer(111, 11); |
| 55 | createLayer(121, 12); |
| 56 | createLayer(122, 12); |
| 57 | createLayer(1221, 122); |
| 58 | } |
| 59 | |
Vishnu Nair | 8fc721b | 2022-12-22 20:06:32 +0000 | [diff] [blame] | 60 | std::vector<uint32_t> getTraversalPath(const LayerHierarchy& hierarchy) const { |
| 61 | std::vector<uint32_t> layerIds; |
| 62 | hierarchy.traverse([&layerIds = layerIds](const LayerHierarchy& hierarchy, |
| 63 | const LayerHierarchy::TraversalPath&) -> bool { |
| 64 | layerIds.emplace_back(hierarchy.getLayer()->id); |
| 65 | return true; |
| 66 | }); |
| 67 | return layerIds; |
| 68 | } |
| 69 | |
| 70 | std::vector<uint32_t> getTraversalPathInZOrder(const LayerHierarchy& hierarchy) const { |
| 71 | std::vector<uint32_t> layerIds; |
| 72 | hierarchy.traverseInZOrder( |
| 73 | [&layerIds = layerIds](const LayerHierarchy& hierarchy, |
| 74 | const LayerHierarchy::TraversalPath&) -> bool { |
| 75 | layerIds.emplace_back(hierarchy.getLayer()->id); |
| 76 | return true; |
| 77 | }); |
| 78 | return layerIds; |
| 79 | } |
| 80 | |
Vishnu Nair | 8fc721b | 2022-12-22 20:06:32 +0000 | [diff] [blame] | 81 | void updateAndVerify(LayerHierarchyBuilder& hierarchyBuilder) { |
Vishnu Nair | a029228 | 2023-12-16 14:32:00 -0800 | [diff] [blame] | 82 | hierarchyBuilder.update(mLifecycleManager); |
Vishnu Nair | 8fc721b | 2022-12-22 20:06:32 +0000 | [diff] [blame] | 83 | mLifecycleManager.commitChanges(); |
| 84 | |
| 85 | // rebuild layer hierarchy from scratch and verify that it matches the updated state. |
Vishnu Nair | a029228 | 2023-12-16 14:32:00 -0800 | [diff] [blame] | 86 | LayerHierarchyBuilder newBuilder; |
| 87 | newBuilder.update(mLifecycleManager); |
Vishnu Nair | 8fc721b | 2022-12-22 20:06:32 +0000 | [diff] [blame] | 88 | EXPECT_EQ(getTraversalPath(hierarchyBuilder.getHierarchy()), |
| 89 | getTraversalPath(newBuilder.getHierarchy())); |
| 90 | EXPECT_EQ(getTraversalPathInZOrder(hierarchyBuilder.getHierarchy()), |
| 91 | getTraversalPathInZOrder(newBuilder.getHierarchy())); |
| 92 | EXPECT_FALSE( |
| 93 | mLifecycleManager.getGlobalChanges().test(RequestedLayerState::Changes::Hierarchy)); |
| 94 | } |
| 95 | |
Vishnu Nair | 8fc721b | 2022-12-22 20:06:32 +0000 | [diff] [blame] | 96 | LayerLifecycleManager mLifecycleManager; |
Vishnu Nair | 8fc721b | 2022-12-22 20:06:32 +0000 | [diff] [blame] | 97 | }; |
| 98 | |
Vishnu Nair | 47b7bb4 | 2023-09-29 16:27:33 -0700 | [diff] [blame] | 99 | class LayerSnapshotTestBase : public LayerHierarchyTestBase { |
| 100 | protected: |
| 101 | LayerSnapshotTestBase() : LayerHierarchyTestBase() {} |
| 102 | |
Vishnu Nair | 47b7bb4 | 2023-09-29 16:27:33 -0700 | [diff] [blame] | 103 | void update(LayerSnapshotBuilder& snapshotBuilder) { |
Vishnu Nair | a029228 | 2023-12-16 14:32:00 -0800 | [diff] [blame] | 104 | mHierarchyBuilder.update(mLifecycleManager); |
Vishnu Nair | 47b7bb4 | 2023-09-29 16:27:33 -0700 | [diff] [blame] | 105 | LayerSnapshotBuilder::Args args{.root = mHierarchyBuilder.getHierarchy(), |
| 106 | .layerLifecycleManager = mLifecycleManager, |
| 107 | .includeMetadata = false, |
| 108 | .displays = mFrontEndDisplayInfos, |
| 109 | .displayChanges = mHasDisplayChanges, |
| 110 | .globalShadowSettings = globalShadowSettings, |
| 111 | .supportsBlur = true, |
| 112 | .supportedLayerGenericMetadata = {}, |
| 113 | .genericLayerMetadataKeyMap = {}}; |
| 114 | snapshotBuilder.update(args); |
| 115 | |
| 116 | mLifecycleManager.commitChanges(); |
| 117 | } |
| 118 | |
Vishnu Nair | a029228 | 2023-12-16 14:32:00 -0800 | [diff] [blame] | 119 | LayerHierarchyBuilder mHierarchyBuilder; |
Vishnu Nair | 47b7bb4 | 2023-09-29 16:27:33 -0700 | [diff] [blame] | 120 | |
| 121 | DisplayInfos mFrontEndDisplayInfos; |
| 122 | bool mHasDisplayChanges = false; |
| 123 | |
Vishnu Nair | d9e4f46 | 2023-10-06 04:05:45 +0000 | [diff] [blame] | 124 | ShadowSettings globalShadowSettings; |
Vishnu Nair | 47b7bb4 | 2023-09-29 16:27:33 -0700 | [diff] [blame] | 125 | }; |
| 126 | |
Vishnu Nair | 8fc721b | 2022-12-22 20:06:32 +0000 | [diff] [blame] | 127 | } // namespace android::surfaceflinger::frontend |