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 | 0808ae6 | 2023-08-07 21:42:42 -0700 | [diff] [blame] | 22 | |
Vishnu Nair | 1391de2 | 2023-03-05 19:56:14 -0800 | [diff] [blame] | 23 | #include "Client.h" // temporarily needed for LayerCreationArgs |
| 24 | #include "FrontEnd/LayerCreationArgs.h" |
Vishnu Nair | 8fc721b | 2022-12-22 20:06:32 +0000 | [diff] [blame] | 25 | #include "FrontEnd/LayerHierarchy.h" |
| 26 | #include "FrontEnd/LayerLifecycleManager.h" |
Vishnu Nair | 47b7bb4 | 2023-09-29 16:27:33 -0700 | [diff] [blame^] | 27 | #include "FrontEnd/LayerSnapshotBuilder.h" |
Vishnu Nair | 8fc721b | 2022-12-22 20:06:32 +0000 | [diff] [blame] | 28 | |
| 29 | namespace android::surfaceflinger::frontend { |
| 30 | |
| 31 | class LayerHierarchyTestBase : public testing::Test { |
| 32 | protected: |
| 33 | LayerHierarchyTestBase() { |
| 34 | // tree with 3 levels of children |
| 35 | // ROOT |
| 36 | // ├── 1 |
| 37 | // │ ├── 11 |
| 38 | // │ │ └── 111 |
| 39 | // │ ├── 12 |
| 40 | // │ │ ├── 121 |
| 41 | // │ │ └── 122 |
| 42 | // │ │ └── 1221 |
| 43 | // │ └── 13 |
| 44 | // └── 2 |
| 45 | |
| 46 | createRootLayer(1); |
| 47 | createRootLayer(2); |
| 48 | createLayer(11, 1); |
| 49 | createLayer(12, 1); |
| 50 | createLayer(13, 1); |
| 51 | createLayer(111, 11); |
| 52 | createLayer(121, 12); |
| 53 | createLayer(122, 12); |
| 54 | createLayer(1221, 122); |
| 55 | } |
| 56 | |
Vishnu Nair | 1391de2 | 2023-03-05 19:56:14 -0800 | [diff] [blame] | 57 | LayerCreationArgs createArgs(uint32_t id, bool canBeRoot, uint32_t parentId, |
| 58 | uint32_t layerIdToMirror) { |
| 59 | LayerCreationArgs args(std::make_optional(id)); |
| 60 | args.name = "testlayer"; |
Vishnu Nair | 8fc721b | 2022-12-22 20:06:32 +0000 | [diff] [blame] | 61 | args.addToRoot = canBeRoot; |
Vishnu Nair | 1391de2 | 2023-03-05 19:56:14 -0800 | [diff] [blame] | 62 | args.parentId = parentId; |
| 63 | args.layerIdToMirror = layerIdToMirror; |
Vishnu Nair | 8fc721b | 2022-12-22 20:06:32 +0000 | [diff] [blame] | 64 | return args; |
| 65 | } |
| 66 | |
Vishnu Nair | 1391de2 | 2023-03-05 19:56:14 -0800 | [diff] [blame] | 67 | LayerCreationArgs createDisplayMirrorArgs(uint32_t id, ui::LayerStack layerStackToMirror) { |
| 68 | LayerCreationArgs args(std::make_optional(id)); |
| 69 | args.name = "testlayer"; |
Vishnu Nair | a9c4376 | 2023-01-27 19:10:25 +0000 | [diff] [blame] | 70 | args.addToRoot = true; |
Vishnu Nair | 1391de2 | 2023-03-05 19:56:14 -0800 | [diff] [blame] | 71 | args.layerStackToMirror = layerStackToMirror; |
Vishnu Nair | a9c4376 | 2023-01-27 19:10:25 +0000 | [diff] [blame] | 72 | return args; |
| 73 | } |
| 74 | |
Vishnu Nair | 8fc721b | 2022-12-22 20:06:32 +0000 | [diff] [blame] | 75 | std::vector<uint32_t> getTraversalPath(const LayerHierarchy& hierarchy) const { |
| 76 | std::vector<uint32_t> layerIds; |
| 77 | hierarchy.traverse([&layerIds = layerIds](const LayerHierarchy& hierarchy, |
| 78 | const LayerHierarchy::TraversalPath&) -> bool { |
| 79 | layerIds.emplace_back(hierarchy.getLayer()->id); |
| 80 | return true; |
| 81 | }); |
| 82 | return layerIds; |
| 83 | } |
| 84 | |
| 85 | std::vector<uint32_t> getTraversalPathInZOrder(const LayerHierarchy& hierarchy) const { |
| 86 | std::vector<uint32_t> layerIds; |
| 87 | hierarchy.traverseInZOrder( |
| 88 | [&layerIds = layerIds](const LayerHierarchy& hierarchy, |
| 89 | const LayerHierarchy::TraversalPath&) -> bool { |
| 90 | layerIds.emplace_back(hierarchy.getLayer()->id); |
| 91 | return true; |
| 92 | }); |
| 93 | return layerIds; |
| 94 | } |
| 95 | |
| 96 | virtual void createRootLayer(uint32_t id) { |
Vishnu Nair | 8fc721b | 2022-12-22 20:06:32 +0000 | [diff] [blame] | 97 | std::vector<std::unique_ptr<RequestedLayerState>> layers; |
| 98 | layers.emplace_back(std::make_unique<RequestedLayerState>( |
Vishnu Nair | 1391de2 | 2023-03-05 19:56:14 -0800 | [diff] [blame] | 99 | createArgs(/*id=*/id, /*canBeRoot=*/true, /*parent=*/UNASSIGNED_LAYER_ID, |
| 100 | /*mirror=*/UNASSIGNED_LAYER_ID))); |
Vishnu Nair | 8fc721b | 2022-12-22 20:06:32 +0000 | [diff] [blame] | 101 | mLifecycleManager.addLayers(std::move(layers)); |
| 102 | } |
| 103 | |
Vishnu Nair | a9c4376 | 2023-01-27 19:10:25 +0000 | [diff] [blame] | 104 | void createDisplayMirrorLayer(uint32_t id, ui::LayerStack layerStack) { |
Vishnu Nair | a9c4376 | 2023-01-27 19:10:25 +0000 | [diff] [blame] | 105 | std::vector<std::unique_ptr<RequestedLayerState>> layers; |
| 106 | layers.emplace_back(std::make_unique<RequestedLayerState>( |
| 107 | createDisplayMirrorArgs(/*id=*/id, layerStack))); |
| 108 | mLifecycleManager.addLayers(std::move(layers)); |
| 109 | } |
| 110 | |
Vishnu Nair | 8fc721b | 2022-12-22 20:06:32 +0000 | [diff] [blame] | 111 | virtual void createLayer(uint32_t id, uint32_t parentId) { |
Vishnu Nair | 8fc721b | 2022-12-22 20:06:32 +0000 | [diff] [blame] | 112 | std::vector<std::unique_ptr<RequestedLayerState>> layers; |
| 113 | layers.emplace_back(std::make_unique<RequestedLayerState>( |
Vishnu Nair | 1391de2 | 2023-03-05 19:56:14 -0800 | [diff] [blame] | 114 | createArgs(/*id=*/id, /*canBeRoot=*/false, /*parent=*/parentId, |
| 115 | /*mirror=*/UNASSIGNED_LAYER_ID))); |
Vishnu Nair | 8fc721b | 2022-12-22 20:06:32 +0000 | [diff] [blame] | 116 | mLifecycleManager.addLayers(std::move(layers)); |
| 117 | } |
| 118 | |
Vishnu Nair | 1391de2 | 2023-03-05 19:56:14 -0800 | [diff] [blame] | 119 | std::vector<TransactionState> reparentLayerTransaction(uint32_t id, uint32_t newParentId) { |
Vishnu Nair | 8fc721b | 2022-12-22 20:06:32 +0000 | [diff] [blame] | 120 | std::vector<TransactionState> transactions; |
| 121 | transactions.emplace_back(); |
| 122 | transactions.back().states.push_back({}); |
Vishnu Nair | 1391de2 | 2023-03-05 19:56:14 -0800 | [diff] [blame] | 123 | transactions.back().states.front().parentId = newParentId; |
Vishnu Nair | 8fc721b | 2022-12-22 20:06:32 +0000 | [diff] [blame] | 124 | transactions.back().states.front().state.what = layer_state_t::eReparent; |
Vishnu Nair | 1391de2 | 2023-03-05 19:56:14 -0800 | [diff] [blame] | 125 | transactions.back().states.front().relativeParentId = UNASSIGNED_LAYER_ID; |
| 126 | transactions.back().states.front().layerId = id; |
| 127 | return transactions; |
| 128 | } |
| 129 | |
| 130 | void reparentLayer(uint32_t id, uint32_t newParentId) { |
| 131 | mLifecycleManager.applyTransactions(reparentLayerTransaction(id, newParentId)); |
| 132 | } |
| 133 | |
| 134 | std::vector<TransactionState> relativeLayerTransaction(uint32_t id, uint32_t relativeParentId) { |
| 135 | std::vector<TransactionState> transactions; |
| 136 | transactions.emplace_back(); |
| 137 | transactions.back().states.push_back({}); |
| 138 | transactions.back().states.front().relativeParentId = relativeParentId; |
| 139 | transactions.back().states.front().state.what = layer_state_t::eRelativeLayerChanged; |
| 140 | transactions.back().states.front().layerId = id; |
| 141 | return transactions; |
Vishnu Nair | 8fc721b | 2022-12-22 20:06:32 +0000 | [diff] [blame] | 142 | } |
| 143 | |
| 144 | void reparentRelativeLayer(uint32_t id, uint32_t relativeParentId) { |
Vishnu Nair | 1391de2 | 2023-03-05 19:56:14 -0800 | [diff] [blame] | 145 | mLifecycleManager.applyTransactions(relativeLayerTransaction(id, relativeParentId)); |
| 146 | } |
| 147 | |
| 148 | void removeRelativeZ(uint32_t id) { |
Vishnu Nair | 8fc721b | 2022-12-22 20:06:32 +0000 | [diff] [blame] | 149 | std::vector<TransactionState> transactions; |
| 150 | transactions.emplace_back(); |
| 151 | transactions.back().states.push_back({}); |
Vishnu Nair | 1391de2 | 2023-03-05 19:56:14 -0800 | [diff] [blame] | 152 | transactions.back().states.front().state.what = layer_state_t::eLayerChanged; |
| 153 | transactions.back().states.front().layerId = id; |
Vishnu Nair | 8fc721b | 2022-12-22 20:06:32 +0000 | [diff] [blame] | 154 | mLifecycleManager.applyTransactions(transactions); |
| 155 | } |
| 156 | |
Vishnu Nair | 1391de2 | 2023-03-05 19:56:14 -0800 | [diff] [blame] | 157 | virtual void mirrorLayer(uint32_t id, uint32_t parentId, uint32_t layerIdToMirror) { |
Vishnu Nair | 8fc721b | 2022-12-22 20:06:32 +0000 | [diff] [blame] | 158 | std::vector<std::unique_ptr<RequestedLayerState>> layers; |
| 159 | layers.emplace_back(std::make_unique<RequestedLayerState>( |
Vishnu Nair | 1391de2 | 2023-03-05 19:56:14 -0800 | [diff] [blame] | 160 | createArgs(/*id=*/id, /*canBeRoot=*/false, /*parent=*/parentId, |
| 161 | /*mirror=*/layerIdToMirror))); |
Vishnu Nair | 8fc721b | 2022-12-22 20:06:32 +0000 | [diff] [blame] | 162 | mLifecycleManager.addLayers(std::move(layers)); |
| 163 | } |
| 164 | |
| 165 | void updateBackgroundColor(uint32_t id, half alpha) { |
| 166 | std::vector<TransactionState> transactions; |
| 167 | transactions.emplace_back(); |
| 168 | transactions.back().states.push_back({}); |
| 169 | transactions.back().states.front().state.what = layer_state_t::eBackgroundColorChanged; |
Vishnu Nair | d47bcee | 2023-02-24 18:08:51 +0000 | [diff] [blame] | 170 | transactions.back().states.front().state.bgColor.a = alpha; |
Vishnu Nair | 1391de2 | 2023-03-05 19:56:14 -0800 | [diff] [blame] | 171 | transactions.back().states.front().layerId = id; |
Vishnu Nair | 8fc721b | 2022-12-22 20:06:32 +0000 | [diff] [blame] | 172 | mLifecycleManager.applyTransactions(transactions); |
| 173 | } |
| 174 | |
Vishnu Nair | 606d9d0 | 2023-08-19 14:20:18 -0700 | [diff] [blame] | 175 | void destroyLayerHandle(uint32_t id) { mLifecycleManager.onHandlesDestroyed({{id, "test"}}); } |
Vishnu Nair | 8fc721b | 2022-12-22 20:06:32 +0000 | [diff] [blame] | 176 | |
| 177 | void updateAndVerify(LayerHierarchyBuilder& hierarchyBuilder) { |
| 178 | if (mLifecycleManager.getGlobalChanges().test(RequestedLayerState::Changes::Hierarchy)) { |
| 179 | hierarchyBuilder.update(mLifecycleManager.getLayers(), |
| 180 | mLifecycleManager.getDestroyedLayers()); |
| 181 | } |
| 182 | mLifecycleManager.commitChanges(); |
| 183 | |
| 184 | // rebuild layer hierarchy from scratch and verify that it matches the updated state. |
| 185 | LayerHierarchyBuilder newBuilder(mLifecycleManager.getLayers()); |
| 186 | EXPECT_EQ(getTraversalPath(hierarchyBuilder.getHierarchy()), |
| 187 | getTraversalPath(newBuilder.getHierarchy())); |
| 188 | EXPECT_EQ(getTraversalPathInZOrder(hierarchyBuilder.getHierarchy()), |
| 189 | getTraversalPathInZOrder(newBuilder.getHierarchy())); |
| 190 | EXPECT_FALSE( |
| 191 | mLifecycleManager.getGlobalChanges().test(RequestedLayerState::Changes::Hierarchy)); |
| 192 | } |
| 193 | |
Vishnu Nair | 1391de2 | 2023-03-05 19:56:14 -0800 | [diff] [blame] | 194 | std::vector<TransactionState> setZTransaction(uint32_t id, int32_t z) { |
Vishnu Nair | 8fc721b | 2022-12-22 20:06:32 +0000 | [diff] [blame] | 195 | std::vector<TransactionState> transactions; |
| 196 | transactions.emplace_back(); |
| 197 | transactions.back().states.push_back({}); |
| 198 | |
| 199 | transactions.back().states.front().state.what = layer_state_t::eLayerChanged; |
Vishnu Nair | 1391de2 | 2023-03-05 19:56:14 -0800 | [diff] [blame] | 200 | transactions.back().states.front().layerId = id; |
Vishnu Nair | 8fc721b | 2022-12-22 20:06:32 +0000 | [diff] [blame] | 201 | transactions.back().states.front().state.z = z; |
Vishnu Nair | 1391de2 | 2023-03-05 19:56:14 -0800 | [diff] [blame] | 202 | return transactions; |
| 203 | } |
| 204 | |
| 205 | void setZ(uint32_t id, int32_t z) { |
| 206 | mLifecycleManager.applyTransactions(setZTransaction(id, z)); |
Vishnu Nair | 8fc721b | 2022-12-22 20:06:32 +0000 | [diff] [blame] | 207 | } |
| 208 | |
| 209 | void setCrop(uint32_t id, const Rect& crop) { |
| 210 | std::vector<TransactionState> transactions; |
| 211 | transactions.emplace_back(); |
| 212 | transactions.back().states.push_back({}); |
| 213 | |
| 214 | transactions.back().states.front().state.what = layer_state_t::eCropChanged; |
Vishnu Nair | 1391de2 | 2023-03-05 19:56:14 -0800 | [diff] [blame] | 215 | transactions.back().states.front().layerId = id; |
Vishnu Nair | 8fc721b | 2022-12-22 20:06:32 +0000 | [diff] [blame] | 216 | transactions.back().states.front().state.crop = crop; |
| 217 | mLifecycleManager.applyTransactions(transactions); |
| 218 | } |
| 219 | |
| 220 | void setFlags(uint32_t id, uint32_t mask, uint32_t flags) { |
| 221 | std::vector<TransactionState> transactions; |
| 222 | transactions.emplace_back(); |
| 223 | transactions.back().states.push_back({}); |
| 224 | |
| 225 | transactions.back().states.front().state.what = layer_state_t::eFlagsChanged; |
| 226 | transactions.back().states.front().state.flags = flags; |
| 227 | transactions.back().states.front().state.mask = mask; |
Vishnu Nair | 1391de2 | 2023-03-05 19:56:14 -0800 | [diff] [blame] | 228 | transactions.back().states.front().layerId = id; |
Vishnu Nair | 8fc721b | 2022-12-22 20:06:32 +0000 | [diff] [blame] | 229 | mLifecycleManager.applyTransactions(transactions); |
| 230 | } |
| 231 | |
| 232 | void setAlpha(uint32_t id, float alpha) { |
| 233 | std::vector<TransactionState> transactions; |
| 234 | transactions.emplace_back(); |
| 235 | transactions.back().states.push_back({}); |
| 236 | |
| 237 | transactions.back().states.front().state.what = layer_state_t::eAlphaChanged; |
Vishnu Nair | 1391de2 | 2023-03-05 19:56:14 -0800 | [diff] [blame] | 238 | transactions.back().states.front().layerId = id; |
Vishnu Nair | 8fc721b | 2022-12-22 20:06:32 +0000 | [diff] [blame] | 239 | transactions.back().states.front().state.color.a = static_cast<half>(alpha); |
| 240 | mLifecycleManager.applyTransactions(transactions); |
| 241 | } |
| 242 | |
| 243 | void hideLayer(uint32_t id) { |
| 244 | setFlags(id, layer_state_t::eLayerHidden, layer_state_t::eLayerHidden); |
| 245 | } |
| 246 | |
| 247 | void showLayer(uint32_t id) { setFlags(id, layer_state_t::eLayerHidden, 0); } |
| 248 | |
| 249 | void setColor(uint32_t id, half3 rgb = half3(1._hf, 1._hf, 1._hf)) { |
| 250 | std::vector<TransactionState> transactions; |
| 251 | transactions.emplace_back(); |
| 252 | transactions.back().states.push_back({}); |
| 253 | transactions.back().states.front().state.what = layer_state_t::eColorChanged; |
| 254 | transactions.back().states.front().state.color.rgb = rgb; |
Vishnu Nair | 1391de2 | 2023-03-05 19:56:14 -0800 | [diff] [blame] | 255 | transactions.back().states.front().layerId = id; |
Vishnu Nair | 8fc721b | 2022-12-22 20:06:32 +0000 | [diff] [blame] | 256 | mLifecycleManager.applyTransactions(transactions); |
| 257 | } |
| 258 | |
Vishnu Nair | cfb2d25 | 2023-01-19 04:44:02 +0000 | [diff] [blame] | 259 | void setLayerStack(uint32_t id, int32_t layerStack) { |
| 260 | std::vector<TransactionState> transactions; |
| 261 | transactions.emplace_back(); |
| 262 | transactions.back().states.push_back({}); |
| 263 | |
| 264 | transactions.back().states.front().state.what = layer_state_t::eLayerStackChanged; |
Vishnu Nair | 1391de2 | 2023-03-05 19:56:14 -0800 | [diff] [blame] | 265 | transactions.back().states.front().layerId = id; |
Vishnu Nair | cfb2d25 | 2023-01-19 04:44:02 +0000 | [diff] [blame] | 266 | transactions.back().states.front().state.layerStack = ui::LayerStack::fromValue(layerStack); |
| 267 | mLifecycleManager.applyTransactions(transactions); |
| 268 | } |
| 269 | |
Vishnu Nair | 92990e2 | 2023-02-24 20:01:05 +0000 | [diff] [blame] | 270 | void setTouchableRegion(uint32_t id, Region region) { |
| 271 | std::vector<TransactionState> transactions; |
| 272 | transactions.emplace_back(); |
| 273 | transactions.back().states.push_back({}); |
| 274 | |
| 275 | transactions.back().states.front().state.what = layer_state_t::eInputInfoChanged; |
Vishnu Nair | 1391de2 | 2023-03-05 19:56:14 -0800 | [diff] [blame] | 276 | transactions.back().states.front().layerId = id; |
Vishnu Nair | 92990e2 | 2023-02-24 20:01:05 +0000 | [diff] [blame] | 277 | transactions.back().states.front().state.windowInfoHandle = |
| 278 | sp<gui::WindowInfoHandle>::make(); |
| 279 | auto inputInfo = transactions.back().states.front().state.windowInfoHandle->editInfo(); |
| 280 | inputInfo->touchableRegion = region; |
| 281 | inputInfo->token = sp<BBinder>::make(); |
| 282 | mLifecycleManager.applyTransactions(transactions); |
| 283 | } |
| 284 | |
Vishnu Nair | 29354ec | 2023-03-28 18:51:28 -0700 | [diff] [blame] | 285 | void setTouchableRegionCrop(uint32_t id, Region region, uint32_t touchCropId, |
| 286 | bool replaceTouchableRegionWithCrop) { |
| 287 | std::vector<TransactionState> transactions; |
| 288 | transactions.emplace_back(); |
| 289 | transactions.back().states.push_back({}); |
| 290 | |
| 291 | transactions.back().states.front().state.what = layer_state_t::eInputInfoChanged; |
| 292 | transactions.back().states.front().layerId = id; |
| 293 | transactions.back().states.front().state.windowInfoHandle = |
| 294 | sp<gui::WindowInfoHandle>::make(); |
| 295 | auto inputInfo = transactions.back().states.front().state.windowInfoHandle->editInfo(); |
| 296 | inputInfo->touchableRegion = region; |
| 297 | inputInfo->replaceTouchableRegionWithCrop = replaceTouchableRegionWithCrop; |
| 298 | transactions.back().states.front().touchCropId = touchCropId; |
| 299 | |
| 300 | inputInfo->token = sp<BBinder>::make(); |
| 301 | mLifecycleManager.applyTransactions(transactions); |
| 302 | } |
| 303 | |
Vishnu Nair | 444f395 | 2023-04-11 13:01:02 -0700 | [diff] [blame] | 304 | void setBackgroundBlurRadius(uint32_t id, uint32_t backgroundBlurRadius) { |
| 305 | std::vector<TransactionState> transactions; |
| 306 | transactions.emplace_back(); |
| 307 | transactions.back().states.push_back({}); |
| 308 | |
| 309 | transactions.back().states.front().state.what = layer_state_t::eBackgroundBlurRadiusChanged; |
| 310 | transactions.back().states.front().layerId = id; |
| 311 | transactions.back().states.front().state.backgroundBlurRadius = backgroundBlurRadius; |
| 312 | mLifecycleManager.applyTransactions(transactions); |
| 313 | } |
| 314 | |
Vishnu Nair | 3d8565a | 2023-06-30 07:23:24 +0000 | [diff] [blame] | 315 | void setFrameRateSelectionPriority(uint32_t id, int32_t priority) { |
| 316 | std::vector<TransactionState> transactions; |
| 317 | transactions.emplace_back(); |
| 318 | transactions.back().states.push_back({}); |
| 319 | |
| 320 | transactions.back().states.front().state.what = layer_state_t::eFrameRateSelectionPriority; |
| 321 | transactions.back().states.front().layerId = id; |
| 322 | transactions.back().states.front().state.frameRateSelectionPriority = priority; |
| 323 | mLifecycleManager.applyTransactions(transactions); |
| 324 | } |
| 325 | |
Vishnu Nair | 52d56fd | 2023-07-20 17:02:43 +0000 | [diff] [blame] | 326 | void setFrameRate(uint32_t id, float frameRate, int8_t compatibility, |
| 327 | int8_t changeFrameRateStrategy) { |
| 328 | std::vector<TransactionState> transactions; |
| 329 | transactions.emplace_back(); |
| 330 | transactions.back().states.push_back({}); |
| 331 | |
| 332 | transactions.back().states.front().state.what = layer_state_t::eFrameRateChanged; |
| 333 | transactions.back().states.front().layerId = id; |
| 334 | transactions.back().states.front().state.frameRate = frameRate; |
| 335 | transactions.back().states.front().state.frameRateCompatibility = compatibility; |
| 336 | transactions.back().states.front().state.changeFrameRateStrategy = changeFrameRateStrategy; |
| 337 | mLifecycleManager.applyTransactions(transactions); |
| 338 | } |
| 339 | |
Rachel Lee | ce6e004 | 2023-06-27 11:22:54 -0700 | [diff] [blame] | 340 | void setFrameRateCategory(uint32_t id, int8_t frameRateCategory) { |
| 341 | std::vector<TransactionState> transactions; |
| 342 | transactions.emplace_back(); |
| 343 | transactions.back().states.push_back({}); |
| 344 | |
| 345 | transactions.back().states.front().state.what = layer_state_t::eFrameRateCategoryChanged; |
| 346 | transactions.back().states.front().layerId = id; |
| 347 | transactions.back().states.front().state.frameRateCategory = frameRateCategory; |
| 348 | mLifecycleManager.applyTransactions(transactions); |
| 349 | } |
| 350 | |
Rachel Lee | 58cc90d | 2023-09-05 18:50:20 -0700 | [diff] [blame] | 351 | void setFrameRateSelectionStrategy(uint32_t id, int8_t strategy) { |
| 352 | std::vector<TransactionState> transactions; |
| 353 | transactions.emplace_back(); |
| 354 | transactions.back().states.push_back({}); |
| 355 | |
| 356 | transactions.back().states.front().state.what = |
| 357 | layer_state_t::eFrameRateSelectionStrategyChanged; |
| 358 | transactions.back().states.front().layerId = id; |
| 359 | transactions.back().states.front().state.frameRateSelectionStrategy = strategy; |
| 360 | mLifecycleManager.applyTransactions(transactions); |
| 361 | } |
| 362 | |
Vishnu Nair | 47b7bb4 | 2023-09-29 16:27:33 -0700 | [diff] [blame^] | 363 | void setDefaultFrameRateCompatibility(uint32_t id, int8_t defaultFrameRateCompatibility) { |
| 364 | std::vector<TransactionState> transactions; |
| 365 | transactions.emplace_back(); |
| 366 | transactions.back().states.push_back({}); |
| 367 | |
| 368 | transactions.back().states.front().state.what = |
| 369 | layer_state_t::eDefaultFrameRateCompatibilityChanged; |
| 370 | transactions.back().states.front().layerId = id; |
| 371 | transactions.back().states.front().state.defaultFrameRateCompatibility = |
| 372 | defaultFrameRateCompatibility; |
| 373 | mLifecycleManager.applyTransactions(transactions); |
| 374 | } |
| 375 | |
Vishnu Nair | 0808ae6 | 2023-08-07 21:42:42 -0700 | [diff] [blame] | 376 | void setRoundedCorners(uint32_t id, float radius) { |
| 377 | std::vector<TransactionState> transactions; |
| 378 | transactions.emplace_back(); |
| 379 | transactions.back().states.push_back({}); |
| 380 | |
| 381 | transactions.back().states.front().state.what = layer_state_t::eCornerRadiusChanged; |
| 382 | transactions.back().states.front().layerId = id; |
| 383 | transactions.back().states.front().state.cornerRadius = radius; |
| 384 | mLifecycleManager.applyTransactions(transactions); |
| 385 | } |
| 386 | |
| 387 | void setBuffer(uint32_t id, std::shared_ptr<renderengine::ExternalTexture> texture) { |
| 388 | std::vector<TransactionState> transactions; |
| 389 | transactions.emplace_back(); |
| 390 | transactions.back().states.push_back({}); |
| 391 | |
| 392 | transactions.back().states.front().state.what = layer_state_t::eBufferChanged; |
| 393 | transactions.back().states.front().layerId = id; |
| 394 | transactions.back().states.front().externalTexture = texture; |
| 395 | transactions.back().states.front().state.bufferData = |
| 396 | std::make_shared<fake::BufferData>(texture->getId(), texture->getWidth(), |
| 397 | texture->getHeight(), texture->getPixelFormat(), |
| 398 | texture->getUsage()); |
| 399 | mLifecycleManager.applyTransactions(transactions); |
| 400 | } |
| 401 | |
Vishnu Nair | 47b7bb4 | 2023-09-29 16:27:33 -0700 | [diff] [blame^] | 402 | void setBuffer(uint32_t id) { |
| 403 | static uint64_t sBufferId = 1; |
| 404 | setBuffer(id, |
| 405 | std::make_shared<renderengine::mock:: |
| 406 | FakeExternalTexture>(1U /*width*/, 1U /*height*/, |
| 407 | sBufferId++, |
| 408 | HAL_PIXEL_FORMAT_RGBA_8888, |
| 409 | GRALLOC_USAGE_PROTECTED /*usage*/)); |
| 410 | } |
| 411 | |
Chavi Weingarten | 0759734 | 2023-09-14 21:10:59 +0000 | [diff] [blame] | 412 | void setBufferCrop(uint32_t id, const Rect& bufferCrop) { |
| 413 | std::vector<TransactionState> transactions; |
| 414 | transactions.emplace_back(); |
| 415 | transactions.back().states.push_back({}); |
| 416 | |
| 417 | transactions.back().states.front().state.what = layer_state_t::eBufferCropChanged; |
| 418 | transactions.back().states.front().layerId = id; |
| 419 | transactions.back().states.front().state.bufferCrop = bufferCrop; |
| 420 | mLifecycleManager.applyTransactions(transactions); |
| 421 | } |
| 422 | |
Vishnu Nair | 3996ee3 | 2023-08-14 04:32:31 +0000 | [diff] [blame] | 423 | void setDataspace(uint32_t id, ui::Dataspace dataspace) { |
| 424 | std::vector<TransactionState> transactions; |
| 425 | transactions.emplace_back(); |
| 426 | transactions.back().states.push_back({}); |
| 427 | |
| 428 | transactions.back().states.front().state.what = layer_state_t::eDataspaceChanged; |
| 429 | transactions.back().states.front().layerId = id; |
| 430 | transactions.back().states.front().state.dataspace = dataspace; |
| 431 | mLifecycleManager.applyTransactions(transactions); |
| 432 | } |
| 433 | |
Vishnu Nair | 8fc721b | 2022-12-22 20:06:32 +0000 | [diff] [blame] | 434 | LayerLifecycleManager mLifecycleManager; |
Vishnu Nair | 8fc721b | 2022-12-22 20:06:32 +0000 | [diff] [blame] | 435 | }; |
| 436 | |
Vishnu Nair | 47b7bb4 | 2023-09-29 16:27:33 -0700 | [diff] [blame^] | 437 | class LayerSnapshotTestBase : public LayerHierarchyTestBase { |
| 438 | protected: |
| 439 | LayerSnapshotTestBase() : LayerHierarchyTestBase() {} |
| 440 | |
| 441 | void createRootLayer(uint32_t id) override { |
| 442 | LayerHierarchyTestBase::createRootLayer(id); |
| 443 | setColor(id); |
| 444 | } |
| 445 | |
| 446 | void createLayer(uint32_t id, uint32_t parentId) override { |
| 447 | LayerHierarchyTestBase::createLayer(id, parentId); |
| 448 | setColor(parentId); |
| 449 | } |
| 450 | |
| 451 | void mirrorLayer(uint32_t id, uint32_t parent, uint32_t layerToMirror) override { |
| 452 | LayerHierarchyTestBase::mirrorLayer(id, parent, layerToMirror); |
| 453 | setColor(id); |
| 454 | } |
| 455 | |
| 456 | void update(LayerSnapshotBuilder& snapshotBuilder) { |
| 457 | if (mLifecycleManager.getGlobalChanges().test(RequestedLayerState::Changes::Hierarchy)) { |
| 458 | mHierarchyBuilder.update(mLifecycleManager.getLayers(), |
| 459 | mLifecycleManager.getDestroyedLayers()); |
| 460 | } |
| 461 | LayerSnapshotBuilder::Args args{.root = mHierarchyBuilder.getHierarchy(), |
| 462 | .layerLifecycleManager = mLifecycleManager, |
| 463 | .includeMetadata = false, |
| 464 | .displays = mFrontEndDisplayInfos, |
| 465 | .displayChanges = mHasDisplayChanges, |
| 466 | .globalShadowSettings = globalShadowSettings, |
| 467 | .supportsBlur = true, |
| 468 | .supportedLayerGenericMetadata = {}, |
| 469 | .genericLayerMetadataKeyMap = {}}; |
| 470 | snapshotBuilder.update(args); |
| 471 | |
| 472 | mLifecycleManager.commitChanges(); |
| 473 | } |
| 474 | |
| 475 | LayerHierarchyBuilder mHierarchyBuilder{{}}; |
| 476 | |
| 477 | DisplayInfos mFrontEndDisplayInfos; |
| 478 | bool mHasDisplayChanges = false; |
| 479 | |
| 480 | renderengine::ShadowSettings globalShadowSettings; |
| 481 | }; |
| 482 | |
Vishnu Nair | 8fc721b | 2022-12-22 20:06:32 +0000 | [diff] [blame] | 483 | } // namespace android::surfaceflinger::frontend |