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