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