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