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