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