Marissa Wall | f6a73fa | 2018-12-10 10:41:08 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2018 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 | |
Marissa Wall | 1be5a10 | 2019-01-18 16:14:04 -0800 | [diff] [blame] | 17 | #include <android/hardware/configstore/1.0/ISurfaceFlingerConfigs.h> |
Marissa Wall | f6a73fa | 2018-12-10 10:41:08 -0800 | [diff] [blame] | 18 | #include <android/native_window.h> |
| 19 | #include <android/surface_control.h> |
Jorim Jaggi | 71db889 | 2021-02-03 23:19:29 +0100 | [diff] [blame] | 20 | #include <surface_control_private.h> |
Marissa Wall | f6a73fa | 2018-12-10 10:41:08 -0800 | [diff] [blame] | 21 | |
Marissa Wall | 1be5a10 | 2019-01-18 16:14:04 -0800 | [diff] [blame] | 22 | #include <configstore/Utils.h> |
| 23 | |
| 24 | #include <gui/HdrMetadata.h> |
| 25 | #include <gui/ISurfaceComposer.h> |
Marissa Wall | f6a73fa | 2018-12-10 10:41:08 -0800 | [diff] [blame] | 26 | #include <gui/Surface.h> |
| 27 | #include <gui/SurfaceComposerClient.h> |
| 28 | #include <gui/SurfaceControl.h> |
| 29 | |
Marin Shalamanov | 463ad8e | 2021-01-28 22:58:37 +0100 | [diff] [blame] | 30 | #include <ui/DynamicDisplayInfo.h> |
Marissa Wall | 1be5a10 | 2019-01-18 16:14:04 -0800 | [diff] [blame] | 31 | |
| 32 | #include <utils/Timers.h> |
| 33 | |
| 34 | using namespace android::hardware::configstore; |
| 35 | using namespace android::hardware::configstore::V1_0; |
Marissa Wall | f6a73fa | 2018-12-10 10:41:08 -0800 | [diff] [blame] | 36 | using namespace android; |
| 37 | |
| 38 | using Transaction = SurfaceComposerClient::Transaction; |
| 39 | |
| 40 | #define CHECK_NOT_NULL(name) \ |
| 41 | LOG_ALWAYS_FATAL_IF(name == nullptr, "nullptr passed as " #name " argument"); |
| 42 | |
| 43 | #define CHECK_VALID_RECT(name) \ |
| 44 | LOG_ALWAYS_FATAL_IF(!static_cast<const Rect&>(name).isValid(), \ |
| 45 | "invalid arg passed as " #name " argument"); |
| 46 | |
John Reck | 2b2ba93 | 2021-07-12 21:51:09 -0400 | [diff] [blame] | 47 | static_assert(static_cast<int>(ADATASPACE_UNKNOWN) == static_cast<int>(HAL_DATASPACE_UNKNOWN)); |
| 48 | static_assert(static_cast<int>(ADATASPACE_SCRGB_LINEAR) == |
| 49 | static_cast<int>(HAL_DATASPACE_V0_SCRGB_LINEAR)); |
| 50 | static_assert(static_cast<int>(ADATASPACE_SRGB) == static_cast<int>(HAL_DATASPACE_V0_SRGB)); |
| 51 | static_assert(static_cast<int>(ADATASPACE_SCRGB) == static_cast<int>(HAL_DATASPACE_V0_SCRGB)); |
| 52 | static_assert(static_cast<int>(ADATASPACE_DISPLAY_P3) == |
| 53 | static_cast<int>(HAL_DATASPACE_DISPLAY_P3)); |
| 54 | static_assert(static_cast<int>(ADATASPACE_BT2020_PQ) == static_cast<int>(HAL_DATASPACE_BT2020_PQ)); |
Valerie Hau | 5bbfd51 | 2019-01-22 17:39:43 -0800 | [diff] [blame] | 55 | |
Marissa Wall | f6a73fa | 2018-12-10 10:41:08 -0800 | [diff] [blame] | 56 | Transaction* ASurfaceTransaction_to_Transaction(ASurfaceTransaction* aSurfaceTransaction) { |
| 57 | return reinterpret_cast<Transaction*>(aSurfaceTransaction); |
| 58 | } |
| 59 | |
| 60 | SurfaceControl* ASurfaceControl_to_SurfaceControl(ASurfaceControl* aSurfaceControl) { |
| 61 | return reinterpret_cast<SurfaceControl*>(aSurfaceControl); |
| 62 | } |
| 63 | |
| 64 | void SurfaceControl_acquire(SurfaceControl* surfaceControl) { |
| 65 | // incStrong/decStrong token must be the same, doesn't matter what it is |
| 66 | surfaceControl->incStrong((void*)SurfaceControl_acquire); |
| 67 | } |
| 68 | |
| 69 | void SurfaceControl_release(SurfaceControl* surfaceControl) { |
| 70 | // incStrong/decStrong token must be the same, doesn't matter what it is |
| 71 | surfaceControl->decStrong((void*)SurfaceControl_acquire); |
| 72 | } |
| 73 | |
| 74 | ASurfaceControl* ASurfaceControl_createFromWindow(ANativeWindow* window, const char* debug_name) { |
| 75 | CHECK_NOT_NULL(window); |
| 76 | CHECK_NOT_NULL(debug_name); |
| 77 | |
| 78 | sp<SurfaceComposerClient> client = new SurfaceComposerClient(); |
| 79 | if (client->initCheck() != NO_ERROR) { |
| 80 | return nullptr; |
| 81 | } |
| 82 | |
Vishnu Nair | ce1a648 | 2020-10-22 17:41:30 -0700 | [diff] [blame] | 83 | Surface* surface = static_cast<Surface*>(window); |
| 84 | sp<IBinder> parentHandle = surface->getSurfaceControlHandle(); |
| 85 | |
Marissa Wall | f6a73fa | 2018-12-10 10:41:08 -0800 | [diff] [blame] | 86 | uint32_t flags = ISurfaceComposerClient::eFXSurfaceBufferState; |
Vishnu Nair | ce1a648 | 2020-10-22 17:41:30 -0700 | [diff] [blame] | 87 | sp<SurfaceControl> surfaceControl; |
| 88 | if (parentHandle) { |
| 89 | surfaceControl = |
| 90 | client->createSurface(String8(debug_name), 0 /* width */, 0 /* height */, |
| 91 | // Format is only relevant for buffer queue layers. |
| 92 | PIXEL_FORMAT_UNKNOWN /* format */, flags, parentHandle); |
| 93 | } else { |
| 94 | surfaceControl = |
| 95 | client->createWithSurfaceParent(String8(debug_name), 0 /* width */, 0 /* height */, |
| 96 | // Format is only relevant for buffer queue layers. |
| 97 | PIXEL_FORMAT_UNKNOWN /* format */, flags, |
| 98 | static_cast<Surface*>(window)); |
| 99 | } |
| 100 | |
Marissa Wall | f6a73fa | 2018-12-10 10:41:08 -0800 | [diff] [blame] | 101 | if (!surfaceControl) { |
| 102 | return nullptr; |
| 103 | } |
| 104 | |
| 105 | SurfaceControl_acquire(surfaceControl.get()); |
| 106 | return reinterpret_cast<ASurfaceControl*>(surfaceControl.get()); |
| 107 | } |
| 108 | |
| 109 | ASurfaceControl* ASurfaceControl_create(ASurfaceControl* parent, const char* debug_name) { |
| 110 | CHECK_NOT_NULL(parent); |
| 111 | CHECK_NOT_NULL(debug_name); |
| 112 | |
| 113 | SurfaceComposerClient* client = ASurfaceControl_to_SurfaceControl(parent)->getClient().get(); |
| 114 | |
| 115 | SurfaceControl* surfaceControlParent = ASurfaceControl_to_SurfaceControl(parent); |
| 116 | |
| 117 | uint32_t flags = ISurfaceComposerClient::eFXSurfaceBufferState; |
| 118 | sp<SurfaceControl> surfaceControl = |
| 119 | client->createSurface(String8(debug_name), 0 /* width */, 0 /* height */, |
| 120 | // Format is only relevant for buffer queue layers. |
| 121 | PIXEL_FORMAT_UNKNOWN /* format */, flags, |
Vishnu Nair | ce1a648 | 2020-10-22 17:41:30 -0700 | [diff] [blame] | 122 | surfaceControlParent->getHandle()); |
Marissa Wall | f6a73fa | 2018-12-10 10:41:08 -0800 | [diff] [blame] | 123 | if (!surfaceControl) { |
| 124 | return nullptr; |
| 125 | } |
| 126 | |
| 127 | SurfaceControl_acquire(surfaceControl.get()); |
| 128 | return reinterpret_cast<ASurfaceControl*>(surfaceControl.get()); |
| 129 | } |
| 130 | |
Huihong Luo | 91697e1 | 2021-01-28 15:24:19 -0800 | [diff] [blame] | 131 | void ASurfaceControl_acquire(ASurfaceControl* aSurfaceControl) { |
| 132 | SurfaceControl* surfaceControl = ASurfaceControl_to_SurfaceControl(aSurfaceControl); |
Marissa Wall | f6a73fa | 2018-12-10 10:41:08 -0800 | [diff] [blame] | 133 | |
Huihong Luo | 91697e1 | 2021-01-28 15:24:19 -0800 | [diff] [blame] | 134 | SurfaceControl_acquire(surfaceControl); |
| 135 | } |
| 136 | |
| 137 | void ASurfaceControl_release(ASurfaceControl* aSurfaceControl) { |
| 138 | SurfaceControl* surfaceControl = ASurfaceControl_to_SurfaceControl(aSurfaceControl); |
| 139 | |
| 140 | SurfaceControl_release(surfaceControl); |
Marissa Wall | f6a73fa | 2018-12-10 10:41:08 -0800 | [diff] [blame] | 141 | } |
| 142 | |
Jorim Jaggi | 71db889 | 2021-02-03 23:19:29 +0100 | [diff] [blame] | 143 | struct ASurfaceControlStats { |
| 144 | int64_t acquireTime; |
| 145 | sp<Fence> previousReleaseFence; |
| 146 | uint64_t frameNumber; |
| 147 | }; |
| 148 | |
| 149 | void ASurfaceControl_registerSurfaceStatsListener(ASurfaceControl* control, void* context, |
| 150 | ASurfaceControl_SurfaceStatsListener func) { |
| 151 | SurfaceStatsCallback callback = [func](void* callback_context, |
| 152 | nsecs_t, |
| 153 | const sp<Fence>&, |
| 154 | const SurfaceStats& surfaceStats) { |
| 155 | |
| 156 | ASurfaceControlStats aSurfaceControlStats; |
| 157 | |
| 158 | ASurfaceControl* aSurfaceControl = |
| 159 | reinterpret_cast<ASurfaceControl*>(surfaceStats.surfaceControl.get()); |
| 160 | aSurfaceControlStats.acquireTime = surfaceStats.acquireTime; |
| 161 | aSurfaceControlStats.previousReleaseFence = surfaceStats.previousReleaseFence; |
| 162 | aSurfaceControlStats.frameNumber = surfaceStats.eventStats.frameNumber; |
| 163 | |
| 164 | (*func)(callback_context, aSurfaceControl, &aSurfaceControlStats); |
| 165 | }; |
| 166 | TransactionCompletedListener::getInstance()->addSurfaceStatsListener(context, |
| 167 | reinterpret_cast<void*>(func), ASurfaceControl_to_SurfaceControl(control), callback); |
| 168 | } |
| 169 | |
| 170 | |
| 171 | void ASurfaceControl_unregisterSurfaceStatsListener(void* context, |
| 172 | ASurfaceControl_SurfaceStatsListener func) { |
| 173 | TransactionCompletedListener::getInstance()->removeSurfaceStatsListener(context, |
| 174 | reinterpret_cast<void*>(func)); |
| 175 | } |
| 176 | |
| 177 | int64_t ASurfaceControlStats_getAcquireTime(ASurfaceControlStats* stats) { |
| 178 | return stats->acquireTime; |
| 179 | } |
| 180 | |
| 181 | uint64_t ASurfaceControlStats_getFrameNumber(ASurfaceControlStats* stats) { |
| 182 | return stats->frameNumber; |
| 183 | } |
| 184 | |
Marissa Wall | f6a73fa | 2018-12-10 10:41:08 -0800 | [diff] [blame] | 185 | ASurfaceTransaction* ASurfaceTransaction_create() { |
| 186 | Transaction* transaction = new Transaction; |
| 187 | return reinterpret_cast<ASurfaceTransaction*>(transaction); |
| 188 | } |
| 189 | |
| 190 | void ASurfaceTransaction_delete(ASurfaceTransaction* aSurfaceTransaction) { |
| 191 | Transaction* transaction = ASurfaceTransaction_to_Transaction(aSurfaceTransaction); |
| 192 | delete transaction; |
| 193 | } |
| 194 | |
| 195 | void ASurfaceTransaction_apply(ASurfaceTransaction* aSurfaceTransaction) { |
| 196 | CHECK_NOT_NULL(aSurfaceTransaction); |
| 197 | |
| 198 | Transaction* transaction = ASurfaceTransaction_to_Transaction(aSurfaceTransaction); |
| 199 | |
| 200 | transaction->apply(); |
| 201 | } |
| 202 | |
Marissa Wall | 1be5a10 | 2019-01-18 16:14:04 -0800 | [diff] [blame] | 203 | struct ASurfaceTransactionStats { |
| 204 | std::unordered_map<ASurfaceControl*, ASurfaceControlStats> aSurfaceControlStats; |
| 205 | int64_t latchTime; |
| 206 | sp<Fence> presentFence; |
Vishnu Nair | beb3b48 | 2021-04-21 08:31:27 -0700 | [diff] [blame] | 207 | bool transactionCompleted; |
Marissa Wall | 1be5a10 | 2019-01-18 16:14:04 -0800 | [diff] [blame] | 208 | }; |
| 209 | |
| 210 | int64_t ASurfaceTransactionStats_getLatchTime(ASurfaceTransactionStats* aSurfaceTransactionStats) { |
| 211 | CHECK_NOT_NULL(aSurfaceTransactionStats); |
| 212 | return aSurfaceTransactionStats->latchTime; |
| 213 | } |
| 214 | |
| 215 | int ASurfaceTransactionStats_getPresentFenceFd(ASurfaceTransactionStats* aSurfaceTransactionStats) { |
| 216 | CHECK_NOT_NULL(aSurfaceTransactionStats); |
Vishnu Nair | beb3b48 | 2021-04-21 08:31:27 -0700 | [diff] [blame] | 217 | LOG_ALWAYS_FATAL_IF(!aSurfaceTransactionStats->transactionCompleted, |
| 218 | "ASurfaceTransactionStats queried from an incomplete transaction callback"); |
| 219 | |
Marissa Wall | 1be5a10 | 2019-01-18 16:14:04 -0800 | [diff] [blame] | 220 | auto& presentFence = aSurfaceTransactionStats->presentFence; |
| 221 | return (presentFence) ? presentFence->dup() : -1; |
| 222 | } |
| 223 | |
| 224 | void ASurfaceTransactionStats_getASurfaceControls(ASurfaceTransactionStats* aSurfaceTransactionStats, |
| 225 | ASurfaceControl*** outASurfaceControls, |
| 226 | size_t* outASurfaceControlsSize) { |
| 227 | CHECK_NOT_NULL(aSurfaceTransactionStats); |
| 228 | CHECK_NOT_NULL(outASurfaceControls); |
| 229 | CHECK_NOT_NULL(outASurfaceControlsSize); |
| 230 | |
| 231 | size_t size = aSurfaceTransactionStats->aSurfaceControlStats.size(); |
| 232 | |
| 233 | SurfaceControl** surfaceControls = new SurfaceControl*[size]; |
| 234 | ASurfaceControl** aSurfaceControls = reinterpret_cast<ASurfaceControl**>(surfaceControls); |
| 235 | |
| 236 | size_t i = 0; |
| 237 | for (auto& [aSurfaceControl, aSurfaceControlStats] : aSurfaceTransactionStats->aSurfaceControlStats) { |
| 238 | aSurfaceControls[i] = aSurfaceControl; |
| 239 | i++; |
| 240 | } |
| 241 | |
| 242 | *outASurfaceControls = aSurfaceControls; |
| 243 | *outASurfaceControlsSize = size; |
| 244 | } |
| 245 | |
| 246 | int64_t ASurfaceTransactionStats_getAcquireTime(ASurfaceTransactionStats* aSurfaceTransactionStats, |
| 247 | ASurfaceControl* aSurfaceControl) { |
| 248 | CHECK_NOT_NULL(aSurfaceTransactionStats); |
| 249 | CHECK_NOT_NULL(aSurfaceControl); |
| 250 | |
| 251 | const auto& aSurfaceControlStats = |
| 252 | aSurfaceTransactionStats->aSurfaceControlStats.find(aSurfaceControl); |
| 253 | LOG_ALWAYS_FATAL_IF( |
| 254 | aSurfaceControlStats == aSurfaceTransactionStats->aSurfaceControlStats.end(), |
| 255 | "ASurfaceControl not found"); |
| 256 | |
| 257 | return aSurfaceControlStats->second.acquireTime; |
| 258 | } |
| 259 | |
| 260 | int ASurfaceTransactionStats_getPreviousReleaseFenceFd( |
| 261 | ASurfaceTransactionStats* aSurfaceTransactionStats, ASurfaceControl* aSurfaceControl) { |
| 262 | CHECK_NOT_NULL(aSurfaceTransactionStats); |
| 263 | CHECK_NOT_NULL(aSurfaceControl); |
Vishnu Nair | beb3b48 | 2021-04-21 08:31:27 -0700 | [diff] [blame] | 264 | LOG_ALWAYS_FATAL_IF(!aSurfaceTransactionStats->transactionCompleted, |
| 265 | "ASurfaceTransactionStats queried from an incomplete transaction callback"); |
Marissa Wall | 1be5a10 | 2019-01-18 16:14:04 -0800 | [diff] [blame] | 266 | |
| 267 | const auto& aSurfaceControlStats = |
| 268 | aSurfaceTransactionStats->aSurfaceControlStats.find(aSurfaceControl); |
| 269 | LOG_ALWAYS_FATAL_IF( |
| 270 | aSurfaceControlStats == aSurfaceTransactionStats->aSurfaceControlStats.end(), |
| 271 | "ASurfaceControl not found"); |
| 272 | |
| 273 | auto& previousReleaseFence = aSurfaceControlStats->second.previousReleaseFence; |
| 274 | return (previousReleaseFence) ? previousReleaseFence->dup() : -1; |
| 275 | } |
| 276 | |
| 277 | void ASurfaceTransactionStats_releaseASurfaceControls(ASurfaceControl** aSurfaceControls) { |
| 278 | CHECK_NOT_NULL(aSurfaceControls); |
| 279 | |
| 280 | SurfaceControl** surfaceControls = reinterpret_cast<SurfaceControl**>(aSurfaceControls); |
| 281 | delete[] surfaceControls; |
| 282 | } |
| 283 | |
Marissa Wall | f6a73fa | 2018-12-10 10:41:08 -0800 | [diff] [blame] | 284 | void ASurfaceTransaction_setOnComplete(ASurfaceTransaction* aSurfaceTransaction, void* context, |
| 285 | ASurfaceTransaction_OnComplete func) { |
| 286 | CHECK_NOT_NULL(aSurfaceTransaction); |
Marissa Wall | f6a73fa | 2018-12-10 10:41:08 -0800 | [diff] [blame] | 287 | CHECK_NOT_NULL(func); |
| 288 | |
| 289 | TransactionCompletedCallbackTakesContext callback = [func](void* callback_context, |
Marissa Wall | 1be5a10 | 2019-01-18 16:14:04 -0800 | [diff] [blame] | 290 | nsecs_t latchTime, |
| 291 | const sp<Fence>& presentFence, |
| 292 | const std::vector<SurfaceControlStats>& surfaceControlStats) { |
| 293 | ASurfaceTransactionStats aSurfaceTransactionStats; |
| 294 | |
| 295 | aSurfaceTransactionStats.latchTime = latchTime; |
| 296 | aSurfaceTransactionStats.presentFence = presentFence; |
Vishnu Nair | beb3b48 | 2021-04-21 08:31:27 -0700 | [diff] [blame] | 297 | aSurfaceTransactionStats.transactionCompleted = true; |
Marissa Wall | 1be5a10 | 2019-01-18 16:14:04 -0800 | [diff] [blame] | 298 | |
| 299 | auto& aSurfaceControlStats = aSurfaceTransactionStats.aSurfaceControlStats; |
| 300 | |
Valerie Hau | d6a222e | 2020-01-29 14:27:09 -0800 | [diff] [blame] | 301 | for (const auto& [surfaceControl, latchTime, acquireTime, presentFence, previousReleaseFence, transformHint, frameEvents] : surfaceControlStats) { |
Marissa Wall | 1be5a10 | 2019-01-18 16:14:04 -0800 | [diff] [blame] | 302 | ASurfaceControl* aSurfaceControl = reinterpret_cast<ASurfaceControl*>(surfaceControl.get()); |
| 303 | aSurfaceControlStats[aSurfaceControl].acquireTime = acquireTime; |
| 304 | aSurfaceControlStats[aSurfaceControl].previousReleaseFence = previousReleaseFence; |
| 305 | } |
| 306 | |
| 307 | (*func)(callback_context, &aSurfaceTransactionStats); |
Marissa Wall | f6a73fa | 2018-12-10 10:41:08 -0800 | [diff] [blame] | 308 | }; |
| 309 | |
| 310 | Transaction* transaction = ASurfaceTransaction_to_Transaction(aSurfaceTransaction); |
| 311 | |
| 312 | transaction->addTransactionCompletedCallback(callback, context); |
| 313 | } |
| 314 | |
Marissa Wall | 1be5a10 | 2019-01-18 16:14:04 -0800 | [diff] [blame] | 315 | void ASurfaceTransaction_reparent(ASurfaceTransaction* aSurfaceTransaction, |
| 316 | ASurfaceControl* aSurfaceControl, |
| 317 | ASurfaceControl* newParentASurfaceControl) { |
| 318 | CHECK_NOT_NULL(aSurfaceTransaction); |
| 319 | CHECK_NOT_NULL(aSurfaceControl); |
| 320 | |
| 321 | sp<SurfaceControl> surfaceControl = ASurfaceControl_to_SurfaceControl(aSurfaceControl); |
| 322 | sp<SurfaceControl> newParentSurfaceControl = ASurfaceControl_to_SurfaceControl( |
| 323 | newParentASurfaceControl); |
Marissa Wall | 1be5a10 | 2019-01-18 16:14:04 -0800 | [diff] [blame] | 324 | Transaction* transaction = ASurfaceTransaction_to_Transaction(aSurfaceTransaction); |
| 325 | |
Pablo Gamito | 117040c | 2020-09-14 08:24:41 +0000 | [diff] [blame] | 326 | transaction->reparent(surfaceControl, newParentSurfaceControl); |
Marissa Wall | 1be5a10 | 2019-01-18 16:14:04 -0800 | [diff] [blame] | 327 | } |
| 328 | |
| 329 | void ASurfaceTransaction_setVisibility(ASurfaceTransaction* aSurfaceTransaction, |
| 330 | ASurfaceControl* aSurfaceControl, |
Marissa Wall | f6a73fa | 2018-12-10 10:41:08 -0800 | [diff] [blame] | 331 | int8_t visibility) { |
| 332 | CHECK_NOT_NULL(aSurfaceTransaction); |
| 333 | CHECK_NOT_NULL(aSurfaceControl); |
| 334 | |
| 335 | sp<SurfaceControl> surfaceControl = ASurfaceControl_to_SurfaceControl(aSurfaceControl); |
| 336 | Transaction* transaction = ASurfaceTransaction_to_Transaction(aSurfaceTransaction); |
| 337 | |
| 338 | switch (visibility) { |
| 339 | case ASURFACE_TRANSACTION_VISIBILITY_SHOW: |
| 340 | transaction->show(surfaceControl); |
| 341 | break; |
| 342 | case ASURFACE_TRANSACTION_VISIBILITY_HIDE: |
| 343 | transaction->hide(surfaceControl); |
| 344 | break; |
| 345 | default: |
| 346 | LOG_ALWAYS_FATAL("invalid visibility %d", visibility); |
| 347 | } |
| 348 | } |
| 349 | |
Marissa Wall | 1be5a10 | 2019-01-18 16:14:04 -0800 | [diff] [blame] | 350 | void ASurfaceTransaction_setZOrder(ASurfaceTransaction* aSurfaceTransaction, |
| 351 | ASurfaceControl* aSurfaceControl, |
Marissa Wall | f6a73fa | 2018-12-10 10:41:08 -0800 | [diff] [blame] | 352 | int32_t z_order) { |
| 353 | CHECK_NOT_NULL(aSurfaceTransaction); |
| 354 | CHECK_NOT_NULL(aSurfaceControl); |
| 355 | |
| 356 | sp<SurfaceControl> surfaceControl = ASurfaceControl_to_SurfaceControl(aSurfaceControl); |
| 357 | Transaction* transaction = ASurfaceTransaction_to_Transaction(aSurfaceTransaction); |
| 358 | |
| 359 | transaction->setLayer(surfaceControl, z_order); |
| 360 | } |
| 361 | |
Marissa Wall | 1be5a10 | 2019-01-18 16:14:04 -0800 | [diff] [blame] | 362 | void ASurfaceTransaction_setBuffer(ASurfaceTransaction* aSurfaceTransaction, |
| 363 | ASurfaceControl* aSurfaceControl, |
| 364 | AHardwareBuffer* buffer, int acquire_fence_fd) { |
Marissa Wall | f6a73fa | 2018-12-10 10:41:08 -0800 | [diff] [blame] | 365 | CHECK_NOT_NULL(aSurfaceTransaction); |
| 366 | CHECK_NOT_NULL(aSurfaceControl); |
| 367 | |
| 368 | sp<SurfaceControl> surfaceControl = ASurfaceControl_to_SurfaceControl(aSurfaceControl); |
| 369 | Transaction* transaction = ASurfaceTransaction_to_Transaction(aSurfaceTransaction); |
| 370 | |
| 371 | sp<GraphicBuffer> graphic_buffer(reinterpret_cast<GraphicBuffer*>(buffer)); |
| 372 | |
| 373 | transaction->setBuffer(surfaceControl, graphic_buffer); |
Marissa Wall | 1be5a10 | 2019-01-18 16:14:04 -0800 | [diff] [blame] | 374 | if (acquire_fence_fd != -1) { |
| 375 | sp<Fence> fence = new Fence(acquire_fence_fd); |
Marissa Wall | f6a73fa | 2018-12-10 10:41:08 -0800 | [diff] [blame] | 376 | transaction->setAcquireFence(surfaceControl, fence); |
| 377 | } |
| 378 | } |
| 379 | |
| 380 | void ASurfaceTransaction_setGeometry(ASurfaceTransaction* aSurfaceTransaction, |
| 381 | ASurfaceControl* aSurfaceControl, const ARect& source, |
| 382 | const ARect& destination, int32_t transform) { |
| 383 | CHECK_NOT_NULL(aSurfaceTransaction); |
| 384 | CHECK_NOT_NULL(aSurfaceControl); |
chaviw | 87a07ea | 2021-04-29 09:04:41 -0500 | [diff] [blame] | 385 | CHECK_VALID_RECT(source); |
Marissa Wall | f6a73fa | 2018-12-10 10:41:08 -0800 | [diff] [blame] | 386 | CHECK_VALID_RECT(destination); |
| 387 | |
| 388 | sp<SurfaceControl> surfaceControl = ASurfaceControl_to_SurfaceControl(aSurfaceControl); |
| 389 | Transaction* transaction = ASurfaceTransaction_to_Transaction(aSurfaceTransaction); |
| 390 | |
chaviw | 87a07ea | 2021-04-29 09:04:41 -0500 | [diff] [blame] | 391 | Rect sourceRect = static_cast<const Rect&>(source); |
| 392 | Rect destRect = static_cast<const Rect&>(destination); |
| 393 | // Adjust the source so its top and left are not negative |
| 394 | sourceRect.left = std::max(sourceRect.left, 0); |
| 395 | sourceRect.top = std::max(sourceRect.top, 0); |
| 396 | |
| 397 | if (!sourceRect.isValid()) { |
| 398 | sourceRect.makeInvalid(); |
| 399 | } |
chaviw | 9b2ac24 | 2021-04-27 15:52:09 -0500 | [diff] [blame] | 400 | transaction->setBufferCrop(surfaceControl, sourceRect); |
Vishnu Nair | 0d7aff7 | 2021-05-10 15:01:20 -0700 | [diff] [blame] | 401 | transaction->setDestinationFrame(surfaceControl, destRect); |
Marissa Wall | f6a73fa | 2018-12-10 10:41:08 -0800 | [diff] [blame] | 402 | transaction->setTransform(surfaceControl, transform); |
Vishnu Nair | 1ad6954 | 2019-05-23 16:27:45 +0800 | [diff] [blame] | 403 | bool transformToInverseDisplay = (NATIVE_WINDOW_TRANSFORM_INVERSE_DISPLAY & transform) == |
| 404 | NATIVE_WINDOW_TRANSFORM_INVERSE_DISPLAY; |
| 405 | transaction->setTransformToDisplayInverse(surfaceControl, transformToInverseDisplay); |
Marissa Wall | f6a73fa | 2018-12-10 10:41:08 -0800 | [diff] [blame] | 406 | } |
| 407 | |
chaviw | ccf3e8b | 2021-03-25 15:28:44 -0500 | [diff] [blame] | 408 | void ASurfaceTransaction_setCrop(ASurfaceTransaction* aSurfaceTransaction, |
| 409 | ASurfaceControl* aSurfaceControl, const ARect& crop) { |
Vasiliy Telezhnikov | 5ead3aa | 2021-03-13 19:55:00 -0500 | [diff] [blame] | 410 | CHECK_NOT_NULL(aSurfaceTransaction); |
| 411 | CHECK_NOT_NULL(aSurfaceControl); |
chaviw | ccf3e8b | 2021-03-25 15:28:44 -0500 | [diff] [blame] | 412 | CHECK_VALID_RECT(crop); |
Vasiliy Telezhnikov | 5ead3aa | 2021-03-13 19:55:00 -0500 | [diff] [blame] | 413 | |
| 414 | sp<SurfaceControl> surfaceControl = ASurfaceControl_to_SurfaceControl(aSurfaceControl); |
| 415 | Transaction* transaction = ASurfaceTransaction_to_Transaction(aSurfaceTransaction); |
| 416 | |
chaviw | ccf3e8b | 2021-03-25 15:28:44 -0500 | [diff] [blame] | 417 | transaction->setCrop(surfaceControl, static_cast<const Rect&>(crop)); |
Vasiliy Telezhnikov | 5ead3aa | 2021-03-13 19:55:00 -0500 | [diff] [blame] | 418 | } |
| 419 | |
chaviw | ccf3e8b | 2021-03-25 15:28:44 -0500 | [diff] [blame] | 420 | void ASurfaceTransaction_setPosition(ASurfaceTransaction* aSurfaceTransaction, |
| 421 | ASurfaceControl* aSurfaceControl, int32_t x, int32_t y) { |
| 422 | CHECK_NOT_NULL(aSurfaceTransaction); |
Vasiliy Telezhnikov | 5ead3aa | 2021-03-13 19:55:00 -0500 | [diff] [blame] | 423 | CHECK_NOT_NULL(aSurfaceControl); |
Vasiliy Telezhnikov | 5ead3aa | 2021-03-13 19:55:00 -0500 | [diff] [blame] | 424 | |
| 425 | sp<SurfaceControl> surfaceControl = ASurfaceControl_to_SurfaceControl(aSurfaceControl); |
| 426 | Transaction* transaction = ASurfaceTransaction_to_Transaction(aSurfaceTransaction); |
| 427 | |
chaviw | ccf3e8b | 2021-03-25 15:28:44 -0500 | [diff] [blame] | 428 | transaction->setPosition(surfaceControl, x, y); |
Vasiliy Telezhnikov | 5ead3aa | 2021-03-13 19:55:00 -0500 | [diff] [blame] | 429 | } |
| 430 | |
chaviw | ccf3e8b | 2021-03-25 15:28:44 -0500 | [diff] [blame] | 431 | void ASurfaceTransaction_setBufferTransform(ASurfaceTransaction* aSurfaceTransaction, |
| 432 | ASurfaceControl* aSurfaceControl, int32_t transform) { |
Vasiliy Telezhnikov | 5ead3aa | 2021-03-13 19:55:00 -0500 | [diff] [blame] | 433 | CHECK_NOT_NULL(aSurfaceTransaction); |
| 434 | CHECK_NOT_NULL(aSurfaceControl); |
| 435 | |
| 436 | sp<SurfaceControl> surfaceControl = ASurfaceControl_to_SurfaceControl(aSurfaceControl); |
| 437 | Transaction* transaction = ASurfaceTransaction_to_Transaction(aSurfaceTransaction); |
| 438 | |
| 439 | transaction->setTransform(surfaceControl, transform); |
| 440 | bool transformToInverseDisplay = (NATIVE_WINDOW_TRANSFORM_INVERSE_DISPLAY & transform) == |
| 441 | NATIVE_WINDOW_TRANSFORM_INVERSE_DISPLAY; |
| 442 | transaction->setTransformToDisplayInverse(surfaceControl, transformToInverseDisplay); |
| 443 | } |
| 444 | |
chaviw | ccf3e8b | 2021-03-25 15:28:44 -0500 | [diff] [blame] | 445 | void ASurfaceTransaction_setScale(ASurfaceTransaction* aSurfaceTransaction, |
| 446 | ASurfaceControl* aSurfaceControl, float xScale, float yScale) { |
| 447 | CHECK_NOT_NULL(aSurfaceTransaction); |
| 448 | CHECK_NOT_NULL(aSurfaceControl); |
| 449 | LOG_ALWAYS_FATAL_IF(xScale < 0, "negative value passed in for xScale"); |
| 450 | LOG_ALWAYS_FATAL_IF(yScale < 0, "negative value passed in for yScale"); |
| 451 | |
| 452 | sp<SurfaceControl> surfaceControl = ASurfaceControl_to_SurfaceControl(aSurfaceControl); |
| 453 | Transaction* transaction = ASurfaceTransaction_to_Transaction(aSurfaceTransaction); |
| 454 | |
| 455 | transaction->setMatrix(surfaceControl, xScale, 0, 0, yScale); |
| 456 | } |
| 457 | |
Marissa Wall | f6a73fa | 2018-12-10 10:41:08 -0800 | [diff] [blame] | 458 | void ASurfaceTransaction_setBufferTransparency(ASurfaceTransaction* aSurfaceTransaction, |
| 459 | ASurfaceControl* aSurfaceControl, |
| 460 | int8_t transparency) { |
| 461 | CHECK_NOT_NULL(aSurfaceTransaction); |
| 462 | CHECK_NOT_NULL(aSurfaceControl); |
| 463 | |
| 464 | sp<SurfaceControl> surfaceControl = ASurfaceControl_to_SurfaceControl(aSurfaceControl); |
| 465 | Transaction* transaction = ASurfaceTransaction_to_Transaction(aSurfaceTransaction); |
| 466 | |
| 467 | uint32_t flags = (transparency == ASURFACE_TRANSACTION_TRANSPARENCY_OPAQUE) ? |
| 468 | layer_state_t::eLayerOpaque : 0; |
| 469 | transaction->setFlags(surfaceControl, flags, layer_state_t::eLayerOpaque); |
| 470 | } |
| 471 | |
Marissa Wall | 1be5a10 | 2019-01-18 16:14:04 -0800 | [diff] [blame] | 472 | void ASurfaceTransaction_setDamageRegion(ASurfaceTransaction* aSurfaceTransaction, |
| 473 | ASurfaceControl* aSurfaceControl, |
Marissa Wall | f6a73fa | 2018-12-10 10:41:08 -0800 | [diff] [blame] | 474 | const ARect rects[], uint32_t count) { |
| 475 | CHECK_NOT_NULL(aSurfaceTransaction); |
| 476 | CHECK_NOT_NULL(aSurfaceControl); |
| 477 | |
| 478 | sp<SurfaceControl> surfaceControl = ASurfaceControl_to_SurfaceControl(aSurfaceControl); |
| 479 | Transaction* transaction = ASurfaceTransaction_to_Transaction(aSurfaceTransaction); |
| 480 | |
| 481 | Region region; |
| 482 | for (uint32_t i = 0; i < count; ++i) { |
Marissa Wall | bb9b14f | 2019-04-23 14:10:15 -0700 | [diff] [blame] | 483 | region.orSelf(static_cast<const Rect&>(rects[i])); |
| 484 | } |
| 485 | |
| 486 | // Hardware composer interprets a DamageRegion with a single Rect of {0,0,0,0} to be an |
| 487 | // undamaged region and {0,0,-1,-1} to be a fully damaged buffer. This is a confusing |
| 488 | // distinction for a public api. Instead, default both cases to be a fully damaged buffer. |
| 489 | if (count == 1 && region.getBounds().isEmpty()) { |
| 490 | transaction->setSurfaceDamageRegion(surfaceControl, Region::INVALID_REGION); |
| 491 | return; |
Marissa Wall | f6a73fa | 2018-12-10 10:41:08 -0800 | [diff] [blame] | 492 | } |
| 493 | |
| 494 | transaction->setSurfaceDamageRegion(surfaceControl, region); |
| 495 | } |
Marissa Wall | 1be5a10 | 2019-01-18 16:14:04 -0800 | [diff] [blame] | 496 | |
| 497 | void ASurfaceTransaction_setDesiredPresentTime(ASurfaceTransaction* aSurfaceTransaction, |
| 498 | int64_t desiredPresentTime) { |
| 499 | CHECK_NOT_NULL(aSurfaceTransaction); |
| 500 | |
| 501 | Transaction* transaction = ASurfaceTransaction_to_Transaction(aSurfaceTransaction); |
| 502 | |
| 503 | transaction->setDesiredPresentTime(static_cast<nsecs_t>(desiredPresentTime)); |
| 504 | } |
| 505 | |
| 506 | void ASurfaceTransaction_setBufferAlpha(ASurfaceTransaction* aSurfaceTransaction, |
| 507 | ASurfaceControl* aSurfaceControl, |
| 508 | float alpha) { |
| 509 | CHECK_NOT_NULL(aSurfaceTransaction); |
| 510 | CHECK_NOT_NULL(aSurfaceControl); |
| 511 | |
| 512 | LOG_ALWAYS_FATAL_IF(alpha < 0.0 || alpha > 1.0, "invalid alpha"); |
| 513 | |
| 514 | sp<SurfaceControl> surfaceControl = ASurfaceControl_to_SurfaceControl(aSurfaceControl); |
| 515 | Transaction* transaction = ASurfaceTransaction_to_Transaction(aSurfaceTransaction); |
| 516 | |
| 517 | transaction->setAlpha(surfaceControl, alpha); |
| 518 | } |
| 519 | |
Marissa Wall | 7f24f79 | 2019-02-07 14:06:04 -0800 | [diff] [blame] | 520 | void ASurfaceTransaction_setBufferDataSpace(ASurfaceTransaction* aSurfaceTransaction, |
| 521 | ASurfaceControl* aSurfaceControl, |
| 522 | ADataSpace aDataSpace) { |
| 523 | CHECK_NOT_NULL(aSurfaceTransaction); |
| 524 | CHECK_NOT_NULL(aSurfaceControl); |
| 525 | |
| 526 | sp<SurfaceControl> surfaceControl = ASurfaceControl_to_SurfaceControl(aSurfaceControl); |
Marissa Wall | 7f24f79 | 2019-02-07 14:06:04 -0800 | [diff] [blame] | 527 | Transaction* transaction = ASurfaceTransaction_to_Transaction(aSurfaceTransaction); |
Marissa Wall | 7f24f79 | 2019-02-07 14:06:04 -0800 | [diff] [blame] | 528 | transaction->setDataspace(surfaceControl, static_cast<ui::Dataspace>(aDataSpace)); |
| 529 | } |
| 530 | |
Marissa Wall | 1be5a10 | 2019-01-18 16:14:04 -0800 | [diff] [blame] | 531 | void ASurfaceTransaction_setHdrMetadata_smpte2086(ASurfaceTransaction* aSurfaceTransaction, |
| 532 | ASurfaceControl* aSurfaceControl, |
| 533 | struct AHdrMetadata_smpte2086* metadata) { |
| 534 | CHECK_NOT_NULL(aSurfaceTransaction); |
| 535 | CHECK_NOT_NULL(aSurfaceControl); |
| 536 | |
| 537 | sp<SurfaceControl> surfaceControl = ASurfaceControl_to_SurfaceControl(aSurfaceControl); |
| 538 | Transaction* transaction = ASurfaceTransaction_to_Transaction(aSurfaceTransaction); |
| 539 | |
| 540 | HdrMetadata hdrMetadata; |
| 541 | |
| 542 | if (metadata) { |
| 543 | hdrMetadata.smpte2086.displayPrimaryRed.x = metadata->displayPrimaryRed.x; |
| 544 | hdrMetadata.smpte2086.displayPrimaryRed.y = metadata->displayPrimaryRed.y; |
| 545 | hdrMetadata.smpte2086.displayPrimaryGreen.x = metadata->displayPrimaryGreen.x; |
| 546 | hdrMetadata.smpte2086.displayPrimaryGreen.y = metadata->displayPrimaryGreen.y; |
| 547 | hdrMetadata.smpte2086.displayPrimaryBlue.x = metadata->displayPrimaryBlue.x; |
| 548 | hdrMetadata.smpte2086.displayPrimaryBlue.y = metadata->displayPrimaryBlue.y; |
| 549 | hdrMetadata.smpte2086.whitePoint.x = metadata->whitePoint.x; |
| 550 | hdrMetadata.smpte2086.whitePoint.y = metadata->whitePoint.y; |
| 551 | hdrMetadata.smpte2086.minLuminance = metadata->minLuminance; |
| 552 | hdrMetadata.smpte2086.maxLuminance = metadata->maxLuminance; |
| 553 | |
| 554 | hdrMetadata.validTypes |= HdrMetadata::SMPTE2086; |
| 555 | } else { |
| 556 | hdrMetadata.validTypes &= ~HdrMetadata::SMPTE2086; |
| 557 | } |
| 558 | |
| 559 | transaction->setHdrMetadata(surfaceControl, hdrMetadata); |
| 560 | } |
| 561 | |
| 562 | void ASurfaceTransaction_setHdrMetadata_cta861_3(ASurfaceTransaction* aSurfaceTransaction, |
| 563 | ASurfaceControl* aSurfaceControl, |
| 564 | struct AHdrMetadata_cta861_3* metadata) { |
| 565 | CHECK_NOT_NULL(aSurfaceTransaction); |
| 566 | CHECK_NOT_NULL(aSurfaceControl); |
| 567 | |
| 568 | sp<SurfaceControl> surfaceControl = ASurfaceControl_to_SurfaceControl(aSurfaceControl); |
| 569 | Transaction* transaction = ASurfaceTransaction_to_Transaction(aSurfaceTransaction); |
| 570 | |
| 571 | HdrMetadata hdrMetadata; |
| 572 | |
| 573 | if (metadata) { |
| 574 | hdrMetadata.cta8613.maxContentLightLevel = metadata->maxContentLightLevel; |
| 575 | hdrMetadata.cta8613.maxFrameAverageLightLevel = metadata->maxFrameAverageLightLevel; |
| 576 | |
| 577 | hdrMetadata.validTypes |= HdrMetadata::CTA861_3; |
| 578 | } else { |
| 579 | hdrMetadata.validTypes &= ~HdrMetadata::CTA861_3; |
| 580 | } |
| 581 | |
| 582 | transaction->setHdrMetadata(surfaceControl, hdrMetadata); |
| 583 | } |
Valerie Hau | 5bbfd51 | 2019-01-22 17:39:43 -0800 | [diff] [blame] | 584 | |
| 585 | void ASurfaceTransaction_setColor(ASurfaceTransaction* aSurfaceTransaction, |
| 586 | ASurfaceControl* aSurfaceControl, |
| 587 | float r, float g, float b, float alpha, |
| 588 | ADataSpace dataspace) { |
| 589 | CHECK_NOT_NULL(aSurfaceTransaction); |
| 590 | CHECK_NOT_NULL(aSurfaceControl); |
| 591 | |
| 592 | sp<SurfaceControl> surfaceControl = ASurfaceControl_to_SurfaceControl(aSurfaceControl); |
Valerie Hau | 5bbfd51 | 2019-01-22 17:39:43 -0800 | [diff] [blame] | 593 | Transaction* transaction = ASurfaceTransaction_to_Transaction(aSurfaceTransaction); |
| 594 | |
| 595 | half3 color; |
| 596 | color.r = r; |
| 597 | color.g = g; |
| 598 | color.b = b; |
| 599 | |
Marin Shalamanov | 511f914 | 2021-03-16 18:03:30 +0100 | [diff] [blame] | 600 | transaction->setBackgroundColor(surfaceControl, color, alpha, |
| 601 | static_cast<ui::Dataspace>(dataspace)); |
Valerie Hau | 5bbfd51 | 2019-01-22 17:39:43 -0800 | [diff] [blame] | 602 | } |
Steven Thomas | 6cf051e | 2020-01-14 11:37:21 -0800 | [diff] [blame] | 603 | |
| 604 | void ASurfaceTransaction_setFrameRate(ASurfaceTransaction* aSurfaceTransaction, |
Steven Thomas | dd7bf2f | 2020-01-31 18:50:02 -0800 | [diff] [blame] | 605 | ASurfaceControl* aSurfaceControl, float frameRate, |
| 606 | int8_t compatibility) { |
Marin Shalamanov | 511f914 | 2021-03-16 18:03:30 +0100 | [diff] [blame] | 607 | ASurfaceTransaction_setFrameRateWithChangeStrategy( |
| 608 | aSurfaceTransaction, aSurfaceControl, frameRate, compatibility, |
| 609 | ANATIVEWINDOW_CHANGE_FRAME_RATE_ONLY_IF_SEAMLESS); |
Marin Shalamanov | 41ffa8d | 2020-10-13 12:35:20 +0200 | [diff] [blame] | 610 | } |
| 611 | |
Marin Shalamanov | 511f914 | 2021-03-16 18:03:30 +0100 | [diff] [blame] | 612 | void ASurfaceTransaction_setFrameRateWithChangeStrategy(ASurfaceTransaction* aSurfaceTransaction, |
| 613 | ASurfaceControl* aSurfaceControl, |
| 614 | float frameRate, int8_t compatibility, |
| 615 | int8_t changeFrameRateStrategy) { |
Steven Thomas | 6cf051e | 2020-01-14 11:37:21 -0800 | [diff] [blame] | 616 | CHECK_NOT_NULL(aSurfaceTransaction); |
| 617 | CHECK_NOT_NULL(aSurfaceControl); |
Steven Thomas | 6cf051e | 2020-01-14 11:37:21 -0800 | [diff] [blame] | 618 | Transaction* transaction = ASurfaceTransaction_to_Transaction(aSurfaceTransaction); |
Steven Thomas | dd7bf2f | 2020-01-31 18:50:02 -0800 | [diff] [blame] | 619 | sp<SurfaceControl> surfaceControl = ASurfaceControl_to_SurfaceControl(aSurfaceControl); |
Marin Shalamanov | 511f914 | 2021-03-16 18:03:30 +0100 | [diff] [blame] | 620 | transaction->setFrameRate(surfaceControl, frameRate, compatibility, changeFrameRateStrategy); |
Steven Thomas | 6cf051e | 2020-01-14 11:37:21 -0800 | [diff] [blame] | 621 | } |
Robert Carr | f57c016 | 2021-03-24 15:48:25 -0700 | [diff] [blame] | 622 | |
| 623 | void ASurfaceTransaction_setEnableBackPressure(ASurfaceTransaction* aSurfaceTransaction, |
| 624 | ASurfaceControl* aSurfaceControl, |
| 625 | bool enableBackpressure) { |
| 626 | CHECK_NOT_NULL(aSurfaceControl); |
| 627 | CHECK_NOT_NULL(aSurfaceTransaction); |
| 628 | |
| 629 | sp<SurfaceControl> surfaceControl = ASurfaceControl_to_SurfaceControl(aSurfaceControl); |
| 630 | Transaction* transaction = ASurfaceTransaction_to_Transaction(aSurfaceTransaction); |
| 631 | |
| 632 | const uint32_t flags = enableBackpressure ? |
| 633 | layer_state_t::eEnableBackpressure : 0; |
| 634 | transaction->setFlags(surfaceControl, flags, layer_state_t::eEnableBackpressure); |
| 635 | } |
Vishnu Nair | beb3b48 | 2021-04-21 08:31:27 -0700 | [diff] [blame] | 636 | |
| 637 | void ASurfaceTransaction_setOnCommit(ASurfaceTransaction* aSurfaceTransaction, void* context, |
| 638 | ASurfaceTransaction_OnCommit func) { |
| 639 | CHECK_NOT_NULL(aSurfaceTransaction); |
| 640 | CHECK_NOT_NULL(func); |
| 641 | |
| 642 | TransactionCompletedCallbackTakesContext callback = |
| 643 | [func](void* callback_context, nsecs_t latchTime, const sp<Fence>& /* presentFence */, |
| 644 | const std::vector<SurfaceControlStats>& surfaceControlStats) { |
| 645 | ASurfaceTransactionStats aSurfaceTransactionStats; |
| 646 | aSurfaceTransactionStats.latchTime = latchTime; |
| 647 | aSurfaceTransactionStats.transactionCompleted = false; |
| 648 | |
| 649 | auto& aSurfaceControlStats = aSurfaceTransactionStats.aSurfaceControlStats; |
| 650 | for (const auto& |
| 651 | [surfaceControl, latchTime, acquireTime, presentFence, |
| 652 | previousReleaseFence, transformHint, |
| 653 | frameEvents] : surfaceControlStats) { |
| 654 | ASurfaceControl* aSurfaceControl = |
| 655 | reinterpret_cast<ASurfaceControl*>(surfaceControl.get()); |
| 656 | aSurfaceControlStats[aSurfaceControl].acquireTime = acquireTime; |
| 657 | } |
| 658 | |
| 659 | (*func)(callback_context, &aSurfaceTransactionStats); |
| 660 | }; |
| 661 | |
| 662 | Transaction* transaction = ASurfaceTransaction_to_Transaction(aSurfaceTransaction); |
| 663 | |
| 664 | transaction->addTransactionCommittedCallback(callback, context); |
Pablo Gamito | 88660d7 | 2021-08-09 14:37:56 +0000 | [diff] [blame^] | 665 | } |