Vishnu Nair | 532d645 | 2024-07-14 22:05:12 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2024 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 | #pragma once |
| 18 | |
| 19 | #include <gui/fake/BufferData.h> |
| 20 | #include <renderengine/mock/FakeExternalTexture.h> |
| 21 | #include <ui/ShadowSettings.h> |
| 22 | |
| 23 | #include <Client.h> // temporarily needed for LayerCreationArgs |
| 24 | #include <FrontEnd/LayerCreationArgs.h> |
| 25 | #include <FrontEnd/LayerHierarchy.h> |
| 26 | #include <FrontEnd/LayerLifecycleManager.h> |
| 27 | #include <FrontEnd/LayerSnapshotBuilder.h> |
Vishnu Nair | 5c61a01 | 2024-08-05 21:14:39 -0700 | [diff] [blame] | 28 | #include <Layer.h> // needed for framerate |
Vishnu Nair | 532d645 | 2024-07-14 22:05:12 -0700 | [diff] [blame] | 29 | |
| 30 | namespace android::surfaceflinger::frontend { |
| 31 | |
| 32 | class LayerLifecycleManagerHelper { |
| 33 | public: |
| 34 | LayerLifecycleManagerHelper(LayerLifecycleManager& layerLifecycleManager) |
| 35 | : mLifecycleManager(layerLifecycleManager) {} |
| 36 | ~LayerLifecycleManagerHelper() = default; |
| 37 | |
| 38 | static LayerCreationArgs createArgs(uint32_t id, bool canBeRoot, uint32_t parentId, |
| 39 | uint32_t layerIdToMirror) { |
| 40 | LayerCreationArgs args(std::make_optional(id)); |
| 41 | args.name = "testlayer"; |
| 42 | args.addToRoot = canBeRoot; |
| 43 | args.parentId = parentId; |
| 44 | args.layerIdToMirror = layerIdToMirror; |
| 45 | return args; |
| 46 | } |
| 47 | |
| 48 | static LayerCreationArgs createDisplayMirrorArgs(uint32_t id, |
| 49 | ui::LayerStack layerStackToMirror) { |
| 50 | LayerCreationArgs args(std::make_optional(id)); |
| 51 | args.name = "testlayer"; |
| 52 | args.addToRoot = true; |
| 53 | args.layerStackToMirror = layerStackToMirror; |
| 54 | return args; |
| 55 | } |
| 56 | |
| 57 | static std::unique_ptr<RequestedLayerState> rootLayer(uint32_t id) { |
| 58 | return std::make_unique<RequestedLayerState>(createArgs(/*id=*/id, /*canBeRoot=*/true, |
| 59 | /*parent=*/UNASSIGNED_LAYER_ID, |
| 60 | /*mirror=*/UNASSIGNED_LAYER_ID)); |
| 61 | } |
| 62 | |
| 63 | static std::unique_ptr<RequestedLayerState> childLayer(uint32_t id, uint32_t parentId) { |
| 64 | return std::make_unique<RequestedLayerState>(createArgs(/*id=*/id, /*canBeRoot=*/false, |
| 65 | parentId, |
| 66 | /*mirror=*/UNASSIGNED_LAYER_ID)); |
| 67 | } |
| 68 | |
| 69 | static std::vector<TransactionState> setZTransaction(uint32_t id, int32_t z) { |
| 70 | std::vector<TransactionState> transactions; |
| 71 | transactions.emplace_back(); |
| 72 | transactions.back().states.push_back({}); |
| 73 | |
| 74 | transactions.back().states.front().state.what = layer_state_t::eLayerChanged; |
| 75 | transactions.back().states.front().layerId = id; |
| 76 | transactions.back().states.front().state.z = z; |
| 77 | return transactions; |
| 78 | } |
| 79 | |
| 80 | void createRootLayer(uint32_t id) { |
| 81 | std::vector<std::unique_ptr<RequestedLayerState>> layers; |
| 82 | layers.emplace_back(std::make_unique<RequestedLayerState>( |
| 83 | createArgs(/*id=*/id, /*canBeRoot=*/true, /*parent=*/UNASSIGNED_LAYER_ID, |
| 84 | /*mirror=*/UNASSIGNED_LAYER_ID))); |
| 85 | mLifecycleManager.addLayers(std::move(layers)); |
| 86 | } |
| 87 | |
Vishnu Nair | 5c61a01 | 2024-08-05 21:14:39 -0700 | [diff] [blame] | 88 | void createRootLayerWithUid(uint32_t id, gui::Uid uid) { |
| 89 | std::vector<std::unique_ptr<RequestedLayerState>> layers; |
| 90 | auto args = createArgs(/*id=*/id, /*canBeRoot=*/true, /*parent=*/UNASSIGNED_LAYER_ID, |
| 91 | /*mirror=*/UNASSIGNED_LAYER_ID); |
| 92 | args.ownerUid = uid.val(); |
| 93 | layers.emplace_back(std::make_unique<RequestedLayerState>(args)); |
| 94 | mLifecycleManager.addLayers(std::move(layers)); |
| 95 | } |
| 96 | |
Vishnu Nair | 532d645 | 2024-07-14 22:05:12 -0700 | [diff] [blame] | 97 | void createDisplayMirrorLayer(uint32_t id, ui::LayerStack layerStack) { |
| 98 | std::vector<std::unique_ptr<RequestedLayerState>> layers; |
| 99 | layers.emplace_back(std::make_unique<RequestedLayerState>( |
| 100 | createDisplayMirrorArgs(/*id=*/id, layerStack))); |
| 101 | mLifecycleManager.addLayers(std::move(layers)); |
| 102 | } |
| 103 | |
| 104 | void createLayer(uint32_t id, uint32_t parentId) { |
| 105 | std::vector<std::unique_ptr<RequestedLayerState>> layers; |
| 106 | layers.emplace_back(std::make_unique<RequestedLayerState>( |
| 107 | createArgs(/*id=*/id, /*canBeRoot=*/false, /*parent=*/parentId, |
| 108 | /*mirror=*/UNASSIGNED_LAYER_ID))); |
| 109 | mLifecycleManager.addLayers(std::move(layers)); |
| 110 | } |
| 111 | |
| 112 | std::vector<TransactionState> reparentLayerTransaction(uint32_t id, uint32_t newParentId) { |
| 113 | std::vector<TransactionState> transactions; |
| 114 | transactions.emplace_back(); |
| 115 | transactions.back().states.push_back({}); |
| 116 | transactions.back().states.front().parentId = newParentId; |
| 117 | transactions.back().states.front().state.what = layer_state_t::eReparent; |
| 118 | transactions.back().states.front().relativeParentId = UNASSIGNED_LAYER_ID; |
| 119 | transactions.back().states.front().layerId = id; |
| 120 | return transactions; |
| 121 | } |
| 122 | |
| 123 | void reparentLayer(uint32_t id, uint32_t newParentId) { |
| 124 | mLifecycleManager.applyTransactions(reparentLayerTransaction(id, newParentId)); |
| 125 | } |
| 126 | |
| 127 | std::vector<TransactionState> relativeLayerTransaction(uint32_t id, uint32_t relativeParentId) { |
| 128 | std::vector<TransactionState> transactions; |
| 129 | transactions.emplace_back(); |
| 130 | transactions.back().states.push_back({}); |
| 131 | transactions.back().states.front().relativeParentId = relativeParentId; |
| 132 | transactions.back().states.front().state.what = layer_state_t::eRelativeLayerChanged; |
| 133 | transactions.back().states.front().layerId = id; |
| 134 | return transactions; |
| 135 | } |
| 136 | |
| 137 | void reparentRelativeLayer(uint32_t id, uint32_t relativeParentId) { |
| 138 | mLifecycleManager.applyTransactions(relativeLayerTransaction(id, relativeParentId)); |
| 139 | } |
| 140 | |
| 141 | void removeRelativeZ(uint32_t id) { |
| 142 | std::vector<TransactionState> transactions; |
| 143 | transactions.emplace_back(); |
| 144 | transactions.back().states.push_back({}); |
| 145 | transactions.back().states.front().state.what = layer_state_t::eLayerChanged; |
| 146 | transactions.back().states.front().layerId = id; |
| 147 | mLifecycleManager.applyTransactions(transactions); |
| 148 | } |
| 149 | |
| 150 | void setPosition(uint32_t id, float x, float y) { |
| 151 | std::vector<TransactionState> transactions; |
| 152 | transactions.emplace_back(); |
| 153 | transactions.back().states.push_back({}); |
| 154 | transactions.back().states.front().state.what = layer_state_t::ePositionChanged; |
| 155 | transactions.back().states.front().state.x = x; |
| 156 | transactions.back().states.front().state.y = y; |
| 157 | transactions.back().states.front().layerId = id; |
| 158 | mLifecycleManager.applyTransactions(transactions); |
| 159 | } |
| 160 | |
| 161 | void mirrorLayer(uint32_t id, uint32_t parentId, uint32_t layerIdToMirror) { |
| 162 | std::vector<std::unique_ptr<RequestedLayerState>> layers; |
| 163 | layers.emplace_back(std::make_unique<RequestedLayerState>( |
| 164 | createArgs(/*id=*/id, /*canBeRoot=*/false, /*parent=*/parentId, |
| 165 | /*mirror=*/layerIdToMirror))); |
| 166 | mLifecycleManager.addLayers(std::move(layers)); |
| 167 | } |
| 168 | |
| 169 | void updateBackgroundColor(uint32_t id, half alpha) { |
| 170 | std::vector<TransactionState> transactions; |
| 171 | transactions.emplace_back(); |
| 172 | transactions.back().states.push_back({}); |
| 173 | transactions.back().states.front().state.what = layer_state_t::eBackgroundColorChanged; |
| 174 | transactions.back().states.front().state.bgColor.a = alpha; |
| 175 | transactions.back().states.front().layerId = id; |
| 176 | mLifecycleManager.applyTransactions(transactions); |
| 177 | } |
| 178 | |
| 179 | void destroyLayerHandle(uint32_t id) { mLifecycleManager.onHandlesDestroyed({{id, "test"}}); } |
| 180 | |
| 181 | void setZ(uint32_t id, int32_t z) { |
| 182 | mLifecycleManager.applyTransactions(setZTransaction(id, z)); |
| 183 | } |
| 184 | |
| 185 | void setCrop(uint32_t id, const Rect& crop) { |
| 186 | std::vector<TransactionState> transactions; |
| 187 | transactions.emplace_back(); |
| 188 | transactions.back().states.push_back({}); |
| 189 | |
| 190 | transactions.back().states.front().state.what = layer_state_t::eCropChanged; |
| 191 | transactions.back().states.front().layerId = id; |
| 192 | transactions.back().states.front().state.crop = crop; |
| 193 | mLifecycleManager.applyTransactions(transactions); |
| 194 | } |
| 195 | |
| 196 | void setFlags(uint32_t id, uint32_t mask, uint32_t flags) { |
| 197 | std::vector<TransactionState> transactions; |
| 198 | transactions.emplace_back(); |
| 199 | transactions.back().states.push_back({}); |
| 200 | |
| 201 | transactions.back().states.front().state.what = layer_state_t::eFlagsChanged; |
| 202 | transactions.back().states.front().state.flags = flags; |
| 203 | transactions.back().states.front().state.mask = mask; |
| 204 | transactions.back().states.front().layerId = id; |
| 205 | mLifecycleManager.applyTransactions(transactions); |
| 206 | } |
| 207 | |
| 208 | void setAlpha(uint32_t id, float alpha) { |
| 209 | std::vector<TransactionState> transactions; |
| 210 | transactions.emplace_back(); |
| 211 | transactions.back().states.push_back({}); |
| 212 | |
| 213 | transactions.back().states.front().state.what = layer_state_t::eAlphaChanged; |
| 214 | transactions.back().states.front().layerId = id; |
| 215 | transactions.back().states.front().state.color.a = static_cast<half>(alpha); |
| 216 | mLifecycleManager.applyTransactions(transactions); |
| 217 | } |
| 218 | |
| 219 | void hideLayer(uint32_t id) { |
| 220 | setFlags(id, layer_state_t::eLayerHidden, layer_state_t::eLayerHidden); |
| 221 | } |
| 222 | |
| 223 | void showLayer(uint32_t id) { setFlags(id, layer_state_t::eLayerHidden, 0); } |
| 224 | |
| 225 | void setColor(uint32_t id, half3 rgb = half3(1._hf, 1._hf, 1._hf)) { |
| 226 | std::vector<TransactionState> transactions; |
| 227 | transactions.emplace_back(); |
| 228 | transactions.back().states.push_back({}); |
| 229 | transactions.back().states.front().state.what = layer_state_t::eColorChanged; |
| 230 | transactions.back().states.front().state.color.rgb = rgb; |
| 231 | transactions.back().states.front().layerId = id; |
| 232 | mLifecycleManager.applyTransactions(transactions); |
| 233 | } |
| 234 | |
| 235 | void setLayerStack(uint32_t id, int32_t layerStack) { |
| 236 | std::vector<TransactionState> transactions; |
| 237 | transactions.emplace_back(); |
| 238 | transactions.back().states.push_back({}); |
| 239 | |
| 240 | transactions.back().states.front().state.what = layer_state_t::eLayerStackChanged; |
| 241 | transactions.back().states.front().layerId = id; |
| 242 | transactions.back().states.front().state.layerStack = ui::LayerStack::fromValue(layerStack); |
| 243 | mLifecycleManager.applyTransactions(transactions); |
| 244 | } |
| 245 | |
| 246 | void setTouchableRegion(uint32_t id, Region region) { |
| 247 | std::vector<TransactionState> transactions; |
| 248 | transactions.emplace_back(); |
| 249 | transactions.back().states.push_back({}); |
| 250 | |
| 251 | transactions.back().states.front().state.what = layer_state_t::eInputInfoChanged; |
| 252 | transactions.back().states.front().layerId = id; |
| 253 | transactions.back().states.front().state.windowInfoHandle = |
| 254 | sp<gui::WindowInfoHandle>::make(); |
| 255 | auto inputInfo = transactions.back().states.front().state.windowInfoHandle->editInfo(); |
| 256 | inputInfo->touchableRegion = region; |
| 257 | inputInfo->token = sp<BBinder>::make(); |
| 258 | mLifecycleManager.applyTransactions(transactions); |
| 259 | } |
| 260 | |
| 261 | void setInputInfo(uint32_t id, std::function<void(gui::WindowInfo&)> configureInput) { |
| 262 | std::vector<TransactionState> transactions; |
| 263 | transactions.emplace_back(); |
| 264 | transactions.back().states.push_back({}); |
| 265 | |
| 266 | transactions.back().states.front().state.what = layer_state_t::eInputInfoChanged; |
| 267 | transactions.back().states.front().layerId = id; |
| 268 | transactions.back().states.front().state.windowInfoHandle = |
| 269 | sp<gui::WindowInfoHandle>::make(); |
| 270 | auto inputInfo = transactions.back().states.front().state.windowInfoHandle->editInfo(); |
| 271 | if (!inputInfo->token) { |
| 272 | inputInfo->token = sp<BBinder>::make(); |
| 273 | } |
| 274 | configureInput(*inputInfo); |
| 275 | |
| 276 | mLifecycleManager.applyTransactions(transactions); |
| 277 | } |
| 278 | |
| 279 | void setTouchableRegionCrop(uint32_t id, Region region, uint32_t touchCropId, |
| 280 | bool replaceTouchableRegionWithCrop) { |
| 281 | std::vector<TransactionState> transactions; |
| 282 | transactions.emplace_back(); |
| 283 | transactions.back().states.push_back({}); |
| 284 | |
| 285 | transactions.back().states.front().state.what = layer_state_t::eInputInfoChanged; |
| 286 | transactions.back().states.front().layerId = id; |
| 287 | transactions.back().states.front().state.windowInfoHandle = |
| 288 | sp<gui::WindowInfoHandle>::make(); |
| 289 | auto inputInfo = transactions.back().states.front().state.windowInfoHandle->editInfo(); |
| 290 | inputInfo->touchableRegion = region; |
| 291 | inputInfo->replaceTouchableRegionWithCrop = replaceTouchableRegionWithCrop; |
| 292 | transactions.back().states.front().touchCropId = touchCropId; |
| 293 | |
| 294 | inputInfo->token = sp<BBinder>::make(); |
| 295 | mLifecycleManager.applyTransactions(transactions); |
| 296 | } |
| 297 | |
| 298 | void setBackgroundBlurRadius(uint32_t id, uint32_t backgroundBlurRadius) { |
| 299 | std::vector<TransactionState> transactions; |
| 300 | transactions.emplace_back(); |
| 301 | transactions.back().states.push_back({}); |
| 302 | |
| 303 | transactions.back().states.front().state.what = layer_state_t::eBackgroundBlurRadiusChanged; |
| 304 | transactions.back().states.front().layerId = id; |
| 305 | transactions.back().states.front().state.backgroundBlurRadius = backgroundBlurRadius; |
| 306 | mLifecycleManager.applyTransactions(transactions); |
| 307 | } |
| 308 | |
| 309 | void setFrameRateSelectionPriority(uint32_t id, int32_t priority) { |
| 310 | std::vector<TransactionState> transactions; |
| 311 | transactions.emplace_back(); |
| 312 | transactions.back().states.push_back({}); |
| 313 | |
| 314 | transactions.back().states.front().state.what = layer_state_t::eFrameRateSelectionPriority; |
| 315 | transactions.back().states.front().layerId = id; |
| 316 | transactions.back().states.front().state.frameRateSelectionPriority = priority; |
| 317 | mLifecycleManager.applyTransactions(transactions); |
| 318 | } |
| 319 | |
| 320 | void setFrameRate(uint32_t id, float frameRate, int8_t compatibility, |
| 321 | int8_t changeFrameRateStrategy) { |
| 322 | std::vector<TransactionState> transactions; |
| 323 | transactions.emplace_back(); |
| 324 | transactions.back().states.push_back({}); |
| 325 | |
| 326 | transactions.back().states.front().state.what = layer_state_t::eFrameRateChanged; |
| 327 | transactions.back().states.front().layerId = id; |
| 328 | transactions.back().states.front().state.frameRate = frameRate; |
| 329 | transactions.back().states.front().state.frameRateCompatibility = compatibility; |
| 330 | transactions.back().states.front().state.changeFrameRateStrategy = changeFrameRateStrategy; |
| 331 | mLifecycleManager.applyTransactions(transactions); |
| 332 | } |
| 333 | |
Vishnu Nair | 5c61a01 | 2024-08-05 21:14:39 -0700 | [diff] [blame] | 334 | void setFrameRate(uint32_t id, Layer::FrameRate framerate) { |
| 335 | std::vector<TransactionState> transactions; |
| 336 | transactions.emplace_back(); |
| 337 | transactions.back().states.push_back({}); |
| 338 | |
| 339 | transactions.back().states.front().state.what = layer_state_t::eFrameRateChanged; |
| 340 | transactions.back().states.front().layerId = id; |
| 341 | transactions.back().states.front().state.frameRate = framerate.vote.rate.getValue(); |
| 342 | transactions.back().states.front().state.frameRateCompatibility = 0; |
| 343 | transactions.back().states.front().state.changeFrameRateStrategy = 0; |
| 344 | mLifecycleManager.applyTransactions(transactions); |
| 345 | } |
| 346 | |
Vishnu Nair | 532d645 | 2024-07-14 22:05:12 -0700 | [diff] [blame] | 347 | void setFrameRateCategory(uint32_t id, int8_t frameRateCategory) { |
| 348 | std::vector<TransactionState> transactions; |
| 349 | transactions.emplace_back(); |
| 350 | transactions.back().states.push_back({}); |
| 351 | |
| 352 | transactions.back().states.front().state.what = layer_state_t::eFrameRateCategoryChanged; |
| 353 | transactions.back().states.front().layerId = id; |
| 354 | transactions.back().states.front().state.frameRateCategory = frameRateCategory; |
| 355 | mLifecycleManager.applyTransactions(transactions); |
| 356 | } |
| 357 | |
| 358 | void setFrameRateSelectionStrategy(uint32_t id, int8_t strategy) { |
| 359 | std::vector<TransactionState> transactions; |
| 360 | transactions.emplace_back(); |
| 361 | transactions.back().states.push_back({}); |
| 362 | |
| 363 | transactions.back().states.front().state.what = |
| 364 | layer_state_t::eFrameRateSelectionStrategyChanged; |
| 365 | transactions.back().states.front().layerId = id; |
| 366 | transactions.back().states.front().state.frameRateSelectionStrategy = strategy; |
| 367 | mLifecycleManager.applyTransactions(transactions); |
| 368 | } |
| 369 | |
| 370 | void setDefaultFrameRateCompatibility(uint32_t id, int8_t defaultFrameRateCompatibility) { |
| 371 | std::vector<TransactionState> transactions; |
| 372 | transactions.emplace_back(); |
| 373 | transactions.back().states.push_back({}); |
| 374 | |
| 375 | transactions.back().states.front().state.what = |
| 376 | layer_state_t::eDefaultFrameRateCompatibilityChanged; |
| 377 | transactions.back().states.front().layerId = id; |
| 378 | transactions.back().states.front().state.defaultFrameRateCompatibility = |
| 379 | defaultFrameRateCompatibility; |
| 380 | mLifecycleManager.applyTransactions(transactions); |
| 381 | } |
| 382 | |
| 383 | void setRoundedCorners(uint32_t id, float radius) { |
| 384 | std::vector<TransactionState> transactions; |
| 385 | transactions.emplace_back(); |
| 386 | transactions.back().states.push_back({}); |
| 387 | |
| 388 | transactions.back().states.front().state.what = layer_state_t::eCornerRadiusChanged; |
| 389 | transactions.back().states.front().layerId = id; |
| 390 | transactions.back().states.front().state.cornerRadius = radius; |
| 391 | mLifecycleManager.applyTransactions(transactions); |
| 392 | } |
| 393 | |
| 394 | void setBuffer(uint32_t id, std::shared_ptr<renderengine::ExternalTexture> texture) { |
| 395 | std::vector<TransactionState> transactions; |
| 396 | transactions.emplace_back(); |
| 397 | transactions.back().states.push_back({}); |
| 398 | |
| 399 | transactions.back().states.front().state.what = layer_state_t::eBufferChanged; |
| 400 | transactions.back().states.front().layerId = id; |
| 401 | transactions.back().states.front().externalTexture = texture; |
| 402 | transactions.back().states.front().state.bufferData = |
| 403 | std::make_shared<fake::BufferData>(texture->getId(), texture->getWidth(), |
| 404 | texture->getHeight(), texture->getPixelFormat(), |
| 405 | texture->getUsage()); |
| 406 | mLifecycleManager.applyTransactions(transactions); |
| 407 | } |
| 408 | |
| 409 | void setBuffer(uint32_t id) { |
| 410 | static uint64_t sBufferId = 1; |
| 411 | setBuffer(id, |
| 412 | std::make_shared<renderengine::mock:: |
| 413 | FakeExternalTexture>(1U /*width*/, 1U /*height*/, |
| 414 | sBufferId++, |
| 415 | HAL_PIXEL_FORMAT_RGBA_8888, |
| 416 | GRALLOC_USAGE_PROTECTED /*usage*/)); |
| 417 | } |
| 418 | |
Vishnu Nair | 5c61a01 | 2024-08-05 21:14:39 -0700 | [diff] [blame] | 419 | void setFrontBuffer(uint32_t id) { |
| 420 | static uint64_t sBufferId = 1; |
| 421 | setBuffer(id, |
| 422 | std::make_shared<renderengine::mock::FakeExternalTexture>( |
| 423 | 1U /*width*/, 1U /*height*/, sBufferId++, HAL_PIXEL_FORMAT_RGBA_8888, |
| 424 | GRALLOC_USAGE_PROTECTED | AHARDWAREBUFFER_USAGE_FRONT_BUFFER /*usage*/)); |
| 425 | } |
| 426 | |
Vishnu Nair | 532d645 | 2024-07-14 22:05:12 -0700 | [diff] [blame] | 427 | void setBufferCrop(uint32_t id, const Rect& bufferCrop) { |
| 428 | std::vector<TransactionState> transactions; |
| 429 | transactions.emplace_back(); |
| 430 | transactions.back().states.push_back({}); |
| 431 | |
| 432 | transactions.back().states.front().state.what = layer_state_t::eBufferCropChanged; |
| 433 | transactions.back().states.front().layerId = id; |
| 434 | transactions.back().states.front().state.bufferCrop = bufferCrop; |
| 435 | mLifecycleManager.applyTransactions(transactions); |
| 436 | } |
| 437 | |
| 438 | void setDamageRegion(uint32_t id, const Region& damageRegion) { |
| 439 | std::vector<TransactionState> transactions; |
| 440 | transactions.emplace_back(); |
| 441 | transactions.back().states.push_back({}); |
| 442 | |
| 443 | transactions.back().states.front().state.what = layer_state_t::eSurfaceDamageRegionChanged; |
| 444 | transactions.back().states.front().layerId = id; |
| 445 | transactions.back().states.front().state.surfaceDamageRegion = damageRegion; |
| 446 | mLifecycleManager.applyTransactions(transactions); |
| 447 | } |
| 448 | |
| 449 | void setDataspace(uint32_t id, ui::Dataspace dataspace) { |
| 450 | std::vector<TransactionState> transactions; |
| 451 | transactions.emplace_back(); |
| 452 | transactions.back().states.push_back({}); |
| 453 | |
| 454 | transactions.back().states.front().state.what = layer_state_t::eDataspaceChanged; |
| 455 | transactions.back().states.front().layerId = id; |
| 456 | transactions.back().states.front().state.dataspace = dataspace; |
| 457 | mLifecycleManager.applyTransactions(transactions); |
| 458 | } |
| 459 | |
| 460 | void setMatrix(uint32_t id, float dsdx, float dtdx, float dtdy, float dsdy) { |
| 461 | layer_state_t::matrix22_t matrix{dsdx, dtdx, dtdy, dsdy}; |
| 462 | |
| 463 | std::vector<TransactionState> transactions; |
| 464 | transactions.emplace_back(); |
| 465 | transactions.back().states.push_back({}); |
| 466 | |
| 467 | transactions.back().states.front().state.what = layer_state_t::eMatrixChanged; |
| 468 | transactions.back().states.front().layerId = id; |
| 469 | transactions.back().states.front().state.matrix = matrix; |
| 470 | mLifecycleManager.applyTransactions(transactions); |
| 471 | } |
| 472 | |
| 473 | void setShadowRadius(uint32_t id, float shadowRadius) { |
| 474 | std::vector<TransactionState> transactions; |
| 475 | transactions.emplace_back(); |
| 476 | transactions.back().states.push_back({}); |
| 477 | |
| 478 | transactions.back().states.front().state.what = layer_state_t::eShadowRadiusChanged; |
| 479 | transactions.back().states.front().layerId = id; |
| 480 | transactions.back().states.front().state.shadowRadius = shadowRadius; |
| 481 | mLifecycleManager.applyTransactions(transactions); |
| 482 | } |
| 483 | |
| 484 | void setTrustedOverlay(uint32_t id, gui::TrustedOverlay trustedOverlay) { |
| 485 | std::vector<TransactionState> transactions; |
| 486 | transactions.emplace_back(); |
| 487 | transactions.back().states.push_back({}); |
| 488 | |
| 489 | transactions.back().states.front().state.what = layer_state_t::eTrustedOverlayChanged; |
| 490 | transactions.back().states.front().layerId = id; |
| 491 | transactions.back().states.front().state.trustedOverlay = trustedOverlay; |
| 492 | mLifecycleManager.applyTransactions(transactions); |
| 493 | } |
| 494 | |
| 495 | void setDropInputMode(uint32_t id, gui::DropInputMode dropInputMode) { |
| 496 | std::vector<TransactionState> transactions; |
| 497 | transactions.emplace_back(); |
| 498 | transactions.back().states.push_back({}); |
| 499 | |
| 500 | transactions.back().states.front().state.what = layer_state_t::eDropInputModeChanged; |
| 501 | transactions.back().states.front().layerId = id; |
| 502 | transactions.back().states.front().state.dropInputMode = dropInputMode; |
| 503 | mLifecycleManager.applyTransactions(transactions); |
| 504 | } |
| 505 | |
Vishnu Nair | 39a74a9 | 2024-07-29 19:01:50 +0000 | [diff] [blame] | 506 | void setGameMode(uint32_t id, gui::GameMode gameMode) { |
| 507 | std::vector<TransactionState> transactions; |
| 508 | transactions.emplace_back(); |
| 509 | transactions.back().states.push_back({}); |
| 510 | transactions.back().states.front().state.what = layer_state_t::eMetadataChanged; |
| 511 | transactions.back().states.front().state.metadata = LayerMetadata(); |
| 512 | transactions.back().states.front().state.metadata.setInt32(METADATA_GAME_MODE, |
| 513 | static_cast<int32_t>(gameMode)); |
| 514 | transactions.back().states.front().layerId = id; |
| 515 | mLifecycleManager.applyTransactions(transactions); |
| 516 | } |
| 517 | |
Marzia Favaro | a763266 | 2024-05-24 16:42:54 +0000 | [diff] [blame] | 518 | void setEdgeExtensionEffect(uint32_t id, int edge) { |
| 519 | std::vector<TransactionState> transactions; |
| 520 | transactions.emplace_back(); |
| 521 | transactions.back().states.push_back({}); |
| 522 | |
| 523 | transactions.back().states.front().layerId = id; |
| 524 | transactions.back().states.front().state.what |= layer_state_t::eEdgeExtensionChanged; |
| 525 | transactions.back().states.front().state.edgeExtensionParameters = |
| 526 | gui::EdgeExtensionParameters(); |
| 527 | transactions.back().states.front().state.edgeExtensionParameters.extendLeft = edge & LEFT; |
| 528 | transactions.back().states.front().state.edgeExtensionParameters.extendRight = edge & RIGHT; |
| 529 | transactions.back().states.front().state.edgeExtensionParameters.extendTop = edge & TOP; |
| 530 | transactions.back().states.front().state.edgeExtensionParameters.extendBottom = |
| 531 | edge & BOTTOM; |
| 532 | mLifecycleManager.applyTransactions(transactions); |
| 533 | } |
| 534 | |
Vishnu Nair | 532d645 | 2024-07-14 22:05:12 -0700 | [diff] [blame] | 535 | private: |
| 536 | LayerLifecycleManager& mLifecycleManager; |
| 537 | }; |
| 538 | |
| 539 | } // namespace android::surfaceflinger::frontend |