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