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