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> |
| 20 | |
Marissa Wall | 1be5a10 | 2019-01-18 16:14:04 -0800 | [diff] [blame] | 21 | #include <configstore/Utils.h> |
| 22 | |
| 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> |
| 28 | |
Marissa Wall | 1be5a10 | 2019-01-18 16:14:04 -0800 | [diff] [blame] | 29 | #include <ui/HdrCapabilities.h> |
| 30 | |
| 31 | #include <utils/Timers.h> |
| 32 | |
| 33 | using namespace android::hardware::configstore; |
| 34 | using namespace android::hardware::configstore::V1_0; |
Marissa Wall | f6a73fa | 2018-12-10 10:41:08 -0800 | [diff] [blame] | 35 | using namespace android; |
Marissa Wall | 1be5a10 | 2019-01-18 16:14:04 -0800 | [diff] [blame] | 36 | using android::hardware::configstore::V1_0::ISurfaceFlingerConfigs; |
Marissa Wall | f6a73fa | 2018-12-10 10:41:08 -0800 | [diff] [blame] | 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 | |
| 74 | HdrCapabilities hdrCapabilities; |
| 75 | status_t err = client->getHdrCapabilities(display, &hdrCapabilities); |
| 76 | if (err) { |
| 77 | ALOGE("unable to get hdr capabilities"); |
| 78 | return false; |
| 79 | } |
| 80 | |
| 81 | return !hdrCapabilities.getSupportedHdrTypes().empty(); |
| 82 | } |
| 83 | |
| 84 | static bool isDataSpaceValid(const sp<SurfaceControl>& surfaceControl, ADataSpace dataSpace) { |
| 85 | static_assert(static_cast<int>(ADATASPACE_UNKNOWN) == static_cast<int>(HAL_DATASPACE_UNKNOWN)); |
| 86 | static_assert(static_cast<int>(ADATASPACE_SCRGB_LINEAR) == static_cast<int>(HAL_DATASPACE_V0_SCRGB_LINEAR)); |
| 87 | static_assert(static_cast<int>(ADATASPACE_SRGB) == static_cast<int>(HAL_DATASPACE_V0_SRGB)); |
| 88 | static_assert(static_cast<int>(ADATASPACE_SCRGB) == static_cast<int>(HAL_DATASPACE_V0_SCRGB)); |
| 89 | static_assert(static_cast<int>(ADATASPACE_DISPLAY_P3) == static_cast<int>(HAL_DATASPACE_DISPLAY_P3)); |
| 90 | static_assert(static_cast<int>(ADATASPACE_BT2020_PQ) == static_cast<int>(HAL_DATASPACE_BT2020_PQ)); |
| 91 | |
| 92 | switch (static_cast<android_dataspace_t>(dataSpace)) { |
| 93 | case HAL_DATASPACE_UNKNOWN: |
| 94 | case HAL_DATASPACE_V0_SRGB: |
| 95 | return true; |
| 96 | // These data space need wide gamut support. |
| 97 | case HAL_DATASPACE_V0_SCRGB_LINEAR: |
| 98 | case HAL_DATASPACE_V0_SCRGB: |
| 99 | case HAL_DATASPACE_DISPLAY_P3: |
| 100 | return getWideColorSupport(surfaceControl); |
| 101 | // These data space need HDR support. |
| 102 | case HAL_DATASPACE_BT2020_PQ: |
Valerie Hau | 5e18c43 | 2019-08-26 12:48:49 -0700 | [diff] [blame] | 103 | if (!getHdrSupport(surfaceControl)) { |
| 104 | ALOGE("Invalid dataspace - device does not support hdr"); |
| 105 | return false; |
| 106 | } |
| 107 | return true; |
Valerie Hau | 5bbfd51 | 2019-01-22 17:39:43 -0800 | [diff] [blame] | 108 | default: |
| 109 | return false; |
| 110 | } |
| 111 | } |
| 112 | |
Marissa Wall | f6a73fa | 2018-12-10 10:41:08 -0800 | [diff] [blame] | 113 | Transaction* ASurfaceTransaction_to_Transaction(ASurfaceTransaction* aSurfaceTransaction) { |
| 114 | return reinterpret_cast<Transaction*>(aSurfaceTransaction); |
| 115 | } |
| 116 | |
| 117 | SurfaceControl* ASurfaceControl_to_SurfaceControl(ASurfaceControl* aSurfaceControl) { |
| 118 | return reinterpret_cast<SurfaceControl*>(aSurfaceControl); |
| 119 | } |
| 120 | |
| 121 | void SurfaceControl_acquire(SurfaceControl* surfaceControl) { |
| 122 | // incStrong/decStrong token must be the same, doesn't matter what it is |
| 123 | surfaceControl->incStrong((void*)SurfaceControl_acquire); |
| 124 | } |
| 125 | |
| 126 | void SurfaceControl_release(SurfaceControl* surfaceControl) { |
| 127 | // incStrong/decStrong token must be the same, doesn't matter what it is |
| 128 | surfaceControl->decStrong((void*)SurfaceControl_acquire); |
| 129 | } |
| 130 | |
| 131 | ASurfaceControl* ASurfaceControl_createFromWindow(ANativeWindow* window, const char* debug_name) { |
| 132 | CHECK_NOT_NULL(window); |
| 133 | CHECK_NOT_NULL(debug_name); |
| 134 | |
| 135 | sp<SurfaceComposerClient> client = new SurfaceComposerClient(); |
| 136 | if (client->initCheck() != NO_ERROR) { |
| 137 | return nullptr; |
| 138 | } |
| 139 | |
Vishnu Nair | ce1a648 | 2020-10-22 17:41:30 -0700 | [diff] [blame] | 140 | Surface* surface = static_cast<Surface*>(window); |
| 141 | sp<IBinder> parentHandle = surface->getSurfaceControlHandle(); |
| 142 | |
Marissa Wall | f6a73fa | 2018-12-10 10:41:08 -0800 | [diff] [blame] | 143 | uint32_t flags = ISurfaceComposerClient::eFXSurfaceBufferState; |
Vishnu Nair | ce1a648 | 2020-10-22 17:41:30 -0700 | [diff] [blame] | 144 | sp<SurfaceControl> surfaceControl; |
| 145 | if (parentHandle) { |
| 146 | surfaceControl = |
| 147 | client->createSurface(String8(debug_name), 0 /* width */, 0 /* height */, |
| 148 | // Format is only relevant for buffer queue layers. |
| 149 | PIXEL_FORMAT_UNKNOWN /* format */, flags, parentHandle); |
| 150 | } else { |
| 151 | surfaceControl = |
| 152 | client->createWithSurfaceParent(String8(debug_name), 0 /* width */, 0 /* height */, |
| 153 | // Format is only relevant for buffer queue layers. |
| 154 | PIXEL_FORMAT_UNKNOWN /* format */, flags, |
| 155 | static_cast<Surface*>(window)); |
| 156 | } |
| 157 | |
Marissa Wall | f6a73fa | 2018-12-10 10:41:08 -0800 | [diff] [blame] | 158 | if (!surfaceControl) { |
| 159 | return nullptr; |
| 160 | } |
| 161 | |
| 162 | SurfaceControl_acquire(surfaceControl.get()); |
| 163 | return reinterpret_cast<ASurfaceControl*>(surfaceControl.get()); |
| 164 | } |
| 165 | |
| 166 | ASurfaceControl* ASurfaceControl_create(ASurfaceControl* parent, const char* debug_name) { |
| 167 | CHECK_NOT_NULL(parent); |
| 168 | CHECK_NOT_NULL(debug_name); |
| 169 | |
| 170 | SurfaceComposerClient* client = ASurfaceControl_to_SurfaceControl(parent)->getClient().get(); |
| 171 | |
| 172 | SurfaceControl* surfaceControlParent = ASurfaceControl_to_SurfaceControl(parent); |
| 173 | |
| 174 | uint32_t flags = ISurfaceComposerClient::eFXSurfaceBufferState; |
| 175 | sp<SurfaceControl> surfaceControl = |
| 176 | client->createSurface(String8(debug_name), 0 /* width */, 0 /* height */, |
| 177 | // Format is only relevant for buffer queue layers. |
| 178 | PIXEL_FORMAT_UNKNOWN /* format */, flags, |
Vishnu Nair | ce1a648 | 2020-10-22 17:41:30 -0700 | [diff] [blame] | 179 | surfaceControlParent->getHandle()); |
Marissa Wall | f6a73fa | 2018-12-10 10:41:08 -0800 | [diff] [blame] | 180 | if (!surfaceControl) { |
| 181 | return nullptr; |
| 182 | } |
| 183 | |
| 184 | SurfaceControl_acquire(surfaceControl.get()); |
| 185 | return reinterpret_cast<ASurfaceControl*>(surfaceControl.get()); |
| 186 | } |
| 187 | |
Marissa Wall | 1be5a10 | 2019-01-18 16:14:04 -0800 | [diff] [blame] | 188 | void ASurfaceControl_release(ASurfaceControl* aSurfaceControl) { |
Marissa Wall | f6a73fa | 2018-12-10 10:41:08 -0800 | [diff] [blame] | 189 | sp<SurfaceControl> surfaceControl = ASurfaceControl_to_SurfaceControl(aSurfaceControl); |
| 190 | |
Marissa Wall | f6a73fa | 2018-12-10 10:41:08 -0800 | [diff] [blame] | 191 | SurfaceControl_release(surfaceControl.get()); |
| 192 | } |
| 193 | |
| 194 | ASurfaceTransaction* ASurfaceTransaction_create() { |
| 195 | Transaction* transaction = new Transaction; |
| 196 | return reinterpret_cast<ASurfaceTransaction*>(transaction); |
| 197 | } |
| 198 | |
| 199 | void ASurfaceTransaction_delete(ASurfaceTransaction* aSurfaceTransaction) { |
| 200 | Transaction* transaction = ASurfaceTransaction_to_Transaction(aSurfaceTransaction); |
| 201 | delete transaction; |
| 202 | } |
| 203 | |
| 204 | void ASurfaceTransaction_apply(ASurfaceTransaction* aSurfaceTransaction) { |
| 205 | CHECK_NOT_NULL(aSurfaceTransaction); |
| 206 | |
| 207 | Transaction* transaction = ASurfaceTransaction_to_Transaction(aSurfaceTransaction); |
| 208 | |
| 209 | transaction->apply(); |
| 210 | } |
| 211 | |
Marissa Wall | 1be5a10 | 2019-01-18 16:14:04 -0800 | [diff] [blame] | 212 | typedef struct ASurfaceControlStats { |
| 213 | int64_t acquireTime; |
| 214 | sp<Fence> previousReleaseFence; |
| 215 | } ASurfaceControlStats; |
| 216 | |
| 217 | struct ASurfaceTransactionStats { |
| 218 | std::unordered_map<ASurfaceControl*, ASurfaceControlStats> aSurfaceControlStats; |
| 219 | int64_t latchTime; |
| 220 | sp<Fence> presentFence; |
| 221 | }; |
| 222 | |
| 223 | int64_t ASurfaceTransactionStats_getLatchTime(ASurfaceTransactionStats* aSurfaceTransactionStats) { |
| 224 | CHECK_NOT_NULL(aSurfaceTransactionStats); |
| 225 | return aSurfaceTransactionStats->latchTime; |
| 226 | } |
| 227 | |
| 228 | int ASurfaceTransactionStats_getPresentFenceFd(ASurfaceTransactionStats* aSurfaceTransactionStats) { |
| 229 | CHECK_NOT_NULL(aSurfaceTransactionStats); |
| 230 | auto& presentFence = aSurfaceTransactionStats->presentFence; |
| 231 | return (presentFence) ? presentFence->dup() : -1; |
| 232 | } |
| 233 | |
| 234 | void ASurfaceTransactionStats_getASurfaceControls(ASurfaceTransactionStats* aSurfaceTransactionStats, |
| 235 | ASurfaceControl*** outASurfaceControls, |
| 236 | size_t* outASurfaceControlsSize) { |
| 237 | CHECK_NOT_NULL(aSurfaceTransactionStats); |
| 238 | CHECK_NOT_NULL(outASurfaceControls); |
| 239 | CHECK_NOT_NULL(outASurfaceControlsSize); |
| 240 | |
| 241 | size_t size = aSurfaceTransactionStats->aSurfaceControlStats.size(); |
| 242 | |
| 243 | SurfaceControl** surfaceControls = new SurfaceControl*[size]; |
| 244 | ASurfaceControl** aSurfaceControls = reinterpret_cast<ASurfaceControl**>(surfaceControls); |
| 245 | |
| 246 | size_t i = 0; |
| 247 | for (auto& [aSurfaceControl, aSurfaceControlStats] : aSurfaceTransactionStats->aSurfaceControlStats) { |
| 248 | aSurfaceControls[i] = aSurfaceControl; |
| 249 | i++; |
| 250 | } |
| 251 | |
| 252 | *outASurfaceControls = aSurfaceControls; |
| 253 | *outASurfaceControlsSize = size; |
| 254 | } |
| 255 | |
| 256 | int64_t ASurfaceTransactionStats_getAcquireTime(ASurfaceTransactionStats* aSurfaceTransactionStats, |
| 257 | ASurfaceControl* aSurfaceControl) { |
| 258 | CHECK_NOT_NULL(aSurfaceTransactionStats); |
| 259 | CHECK_NOT_NULL(aSurfaceControl); |
| 260 | |
| 261 | const auto& aSurfaceControlStats = |
| 262 | aSurfaceTransactionStats->aSurfaceControlStats.find(aSurfaceControl); |
| 263 | LOG_ALWAYS_FATAL_IF( |
| 264 | aSurfaceControlStats == aSurfaceTransactionStats->aSurfaceControlStats.end(), |
| 265 | "ASurfaceControl not found"); |
| 266 | |
| 267 | return aSurfaceControlStats->second.acquireTime; |
| 268 | } |
| 269 | |
| 270 | int ASurfaceTransactionStats_getPreviousReleaseFenceFd( |
| 271 | ASurfaceTransactionStats* aSurfaceTransactionStats, ASurfaceControl* aSurfaceControl) { |
| 272 | CHECK_NOT_NULL(aSurfaceTransactionStats); |
| 273 | CHECK_NOT_NULL(aSurfaceControl); |
| 274 | |
| 275 | const auto& aSurfaceControlStats = |
| 276 | aSurfaceTransactionStats->aSurfaceControlStats.find(aSurfaceControl); |
| 277 | LOG_ALWAYS_FATAL_IF( |
| 278 | aSurfaceControlStats == aSurfaceTransactionStats->aSurfaceControlStats.end(), |
| 279 | "ASurfaceControl not found"); |
| 280 | |
| 281 | auto& previousReleaseFence = aSurfaceControlStats->second.previousReleaseFence; |
| 282 | return (previousReleaseFence) ? previousReleaseFence->dup() : -1; |
| 283 | } |
| 284 | |
| 285 | void ASurfaceTransactionStats_releaseASurfaceControls(ASurfaceControl** aSurfaceControls) { |
| 286 | CHECK_NOT_NULL(aSurfaceControls); |
| 287 | |
| 288 | SurfaceControl** surfaceControls = reinterpret_cast<SurfaceControl**>(aSurfaceControls); |
| 289 | delete[] surfaceControls; |
| 290 | } |
| 291 | |
Marissa Wall | f6a73fa | 2018-12-10 10:41:08 -0800 | [diff] [blame] | 292 | void ASurfaceTransaction_setOnComplete(ASurfaceTransaction* aSurfaceTransaction, void* context, |
| 293 | ASurfaceTransaction_OnComplete func) { |
| 294 | CHECK_NOT_NULL(aSurfaceTransaction); |
| 295 | CHECK_NOT_NULL(context); |
| 296 | CHECK_NOT_NULL(func); |
| 297 | |
| 298 | TransactionCompletedCallbackTakesContext callback = [func](void* callback_context, |
Marissa Wall | 1be5a10 | 2019-01-18 16:14:04 -0800 | [diff] [blame] | 299 | nsecs_t latchTime, |
| 300 | const sp<Fence>& presentFence, |
| 301 | const std::vector<SurfaceControlStats>& surfaceControlStats) { |
| 302 | ASurfaceTransactionStats aSurfaceTransactionStats; |
| 303 | |
| 304 | aSurfaceTransactionStats.latchTime = latchTime; |
| 305 | aSurfaceTransactionStats.presentFence = presentFence; |
| 306 | |
| 307 | auto& aSurfaceControlStats = aSurfaceTransactionStats.aSurfaceControlStats; |
| 308 | |
Valerie Hau | d6a222e | 2020-01-29 14:27:09 -0800 | [diff] [blame] | 309 | for (const auto& [surfaceControl, latchTime, acquireTime, presentFence, previousReleaseFence, transformHint, frameEvents] : surfaceControlStats) { |
Marissa Wall | 1be5a10 | 2019-01-18 16:14:04 -0800 | [diff] [blame] | 310 | ASurfaceControl* aSurfaceControl = reinterpret_cast<ASurfaceControl*>(surfaceControl.get()); |
| 311 | aSurfaceControlStats[aSurfaceControl].acquireTime = acquireTime; |
| 312 | aSurfaceControlStats[aSurfaceControl].previousReleaseFence = previousReleaseFence; |
| 313 | } |
| 314 | |
| 315 | (*func)(callback_context, &aSurfaceTransactionStats); |
Marissa Wall | f6a73fa | 2018-12-10 10:41:08 -0800 | [diff] [blame] | 316 | }; |
| 317 | |
| 318 | Transaction* transaction = ASurfaceTransaction_to_Transaction(aSurfaceTransaction); |
| 319 | |
| 320 | transaction->addTransactionCompletedCallback(callback, context); |
| 321 | } |
| 322 | |
Marissa Wall | 1be5a10 | 2019-01-18 16:14:04 -0800 | [diff] [blame] | 323 | void ASurfaceTransaction_reparent(ASurfaceTransaction* aSurfaceTransaction, |
| 324 | ASurfaceControl* aSurfaceControl, |
| 325 | ASurfaceControl* newParentASurfaceControl) { |
| 326 | CHECK_NOT_NULL(aSurfaceTransaction); |
| 327 | CHECK_NOT_NULL(aSurfaceControl); |
| 328 | |
| 329 | sp<SurfaceControl> surfaceControl = ASurfaceControl_to_SurfaceControl(aSurfaceControl); |
| 330 | sp<SurfaceControl> newParentSurfaceControl = ASurfaceControl_to_SurfaceControl( |
| 331 | newParentASurfaceControl); |
Marissa Wall | 1be5a10 | 2019-01-18 16:14:04 -0800 | [diff] [blame] | 332 | Transaction* transaction = ASurfaceTransaction_to_Transaction(aSurfaceTransaction); |
| 333 | |
Pablo Gamito | 117040c | 2020-09-14 08:24:41 +0000 | [diff] [blame] | 334 | transaction->reparent(surfaceControl, newParentSurfaceControl); |
Marissa Wall | 1be5a10 | 2019-01-18 16:14:04 -0800 | [diff] [blame] | 335 | } |
| 336 | |
| 337 | void ASurfaceTransaction_setVisibility(ASurfaceTransaction* aSurfaceTransaction, |
| 338 | ASurfaceControl* aSurfaceControl, |
Marissa Wall | f6a73fa | 2018-12-10 10:41:08 -0800 | [diff] [blame] | 339 | int8_t visibility) { |
| 340 | CHECK_NOT_NULL(aSurfaceTransaction); |
| 341 | CHECK_NOT_NULL(aSurfaceControl); |
| 342 | |
| 343 | sp<SurfaceControl> surfaceControl = ASurfaceControl_to_SurfaceControl(aSurfaceControl); |
| 344 | Transaction* transaction = ASurfaceTransaction_to_Transaction(aSurfaceTransaction); |
| 345 | |
| 346 | switch (visibility) { |
| 347 | case ASURFACE_TRANSACTION_VISIBILITY_SHOW: |
| 348 | transaction->show(surfaceControl); |
| 349 | break; |
| 350 | case ASURFACE_TRANSACTION_VISIBILITY_HIDE: |
| 351 | transaction->hide(surfaceControl); |
| 352 | break; |
| 353 | default: |
| 354 | LOG_ALWAYS_FATAL("invalid visibility %d", visibility); |
| 355 | } |
| 356 | } |
| 357 | |
Marissa Wall | 1be5a10 | 2019-01-18 16:14:04 -0800 | [diff] [blame] | 358 | void ASurfaceTransaction_setZOrder(ASurfaceTransaction* aSurfaceTransaction, |
| 359 | ASurfaceControl* aSurfaceControl, |
Marissa Wall | f6a73fa | 2018-12-10 10:41:08 -0800 | [diff] [blame] | 360 | int32_t z_order) { |
| 361 | CHECK_NOT_NULL(aSurfaceTransaction); |
| 362 | CHECK_NOT_NULL(aSurfaceControl); |
| 363 | |
| 364 | sp<SurfaceControl> surfaceControl = ASurfaceControl_to_SurfaceControl(aSurfaceControl); |
| 365 | Transaction* transaction = ASurfaceTransaction_to_Transaction(aSurfaceTransaction); |
| 366 | |
| 367 | transaction->setLayer(surfaceControl, z_order); |
| 368 | } |
| 369 | |
Marissa Wall | 1be5a10 | 2019-01-18 16:14:04 -0800 | [diff] [blame] | 370 | void ASurfaceTransaction_setBuffer(ASurfaceTransaction* aSurfaceTransaction, |
| 371 | ASurfaceControl* aSurfaceControl, |
| 372 | AHardwareBuffer* buffer, int acquire_fence_fd) { |
Marissa Wall | f6a73fa | 2018-12-10 10:41:08 -0800 | [diff] [blame] | 373 | CHECK_NOT_NULL(aSurfaceTransaction); |
| 374 | CHECK_NOT_NULL(aSurfaceControl); |
| 375 | |
| 376 | sp<SurfaceControl> surfaceControl = ASurfaceControl_to_SurfaceControl(aSurfaceControl); |
| 377 | Transaction* transaction = ASurfaceTransaction_to_Transaction(aSurfaceTransaction); |
| 378 | |
| 379 | sp<GraphicBuffer> graphic_buffer(reinterpret_cast<GraphicBuffer*>(buffer)); |
| 380 | |
| 381 | transaction->setBuffer(surfaceControl, graphic_buffer); |
Marissa Wall | 1be5a10 | 2019-01-18 16:14:04 -0800 | [diff] [blame] | 382 | if (acquire_fence_fd != -1) { |
| 383 | sp<Fence> fence = new Fence(acquire_fence_fd); |
Marissa Wall | f6a73fa | 2018-12-10 10:41:08 -0800 | [diff] [blame] | 384 | transaction->setAcquireFence(surfaceControl, fence); |
| 385 | } |
| 386 | } |
| 387 | |
| 388 | void ASurfaceTransaction_setGeometry(ASurfaceTransaction* aSurfaceTransaction, |
| 389 | ASurfaceControl* aSurfaceControl, const ARect& source, |
| 390 | const ARect& destination, int32_t transform) { |
| 391 | CHECK_NOT_NULL(aSurfaceTransaction); |
| 392 | CHECK_NOT_NULL(aSurfaceControl); |
| 393 | CHECK_VALID_RECT(source); |
| 394 | CHECK_VALID_RECT(destination); |
| 395 | |
| 396 | sp<SurfaceControl> surfaceControl = ASurfaceControl_to_SurfaceControl(aSurfaceControl); |
| 397 | Transaction* transaction = ASurfaceTransaction_to_Transaction(aSurfaceTransaction); |
| 398 | |
| 399 | transaction->setCrop(surfaceControl, static_cast<const Rect&>(source)); |
| 400 | transaction->setFrame(surfaceControl, static_cast<const Rect&>(destination)); |
| 401 | transaction->setTransform(surfaceControl, transform); |
Vishnu Nair | 1ad6954 | 2019-05-23 16:27:45 +0800 | [diff] [blame] | 402 | bool transformToInverseDisplay = (NATIVE_WINDOW_TRANSFORM_INVERSE_DISPLAY & transform) == |
| 403 | NATIVE_WINDOW_TRANSFORM_INVERSE_DISPLAY; |
| 404 | transaction->setTransformToDisplayInverse(surfaceControl, transformToInverseDisplay); |
Marissa Wall | f6a73fa | 2018-12-10 10:41:08 -0800 | [diff] [blame] | 405 | } |
| 406 | |
| 407 | void ASurfaceTransaction_setBufferTransparency(ASurfaceTransaction* aSurfaceTransaction, |
| 408 | ASurfaceControl* aSurfaceControl, |
| 409 | int8_t transparency) { |
| 410 | CHECK_NOT_NULL(aSurfaceTransaction); |
| 411 | CHECK_NOT_NULL(aSurfaceControl); |
| 412 | |
| 413 | sp<SurfaceControl> surfaceControl = ASurfaceControl_to_SurfaceControl(aSurfaceControl); |
| 414 | Transaction* transaction = ASurfaceTransaction_to_Transaction(aSurfaceTransaction); |
| 415 | |
| 416 | uint32_t flags = (transparency == ASURFACE_TRANSACTION_TRANSPARENCY_OPAQUE) ? |
| 417 | layer_state_t::eLayerOpaque : 0; |
| 418 | transaction->setFlags(surfaceControl, flags, layer_state_t::eLayerOpaque); |
| 419 | } |
| 420 | |
Marissa Wall | 1be5a10 | 2019-01-18 16:14:04 -0800 | [diff] [blame] | 421 | void ASurfaceTransaction_setDamageRegion(ASurfaceTransaction* aSurfaceTransaction, |
| 422 | ASurfaceControl* aSurfaceControl, |
Marissa Wall | f6a73fa | 2018-12-10 10:41:08 -0800 | [diff] [blame] | 423 | const ARect rects[], uint32_t count) { |
| 424 | CHECK_NOT_NULL(aSurfaceTransaction); |
| 425 | CHECK_NOT_NULL(aSurfaceControl); |
| 426 | |
| 427 | sp<SurfaceControl> surfaceControl = ASurfaceControl_to_SurfaceControl(aSurfaceControl); |
| 428 | Transaction* transaction = ASurfaceTransaction_to_Transaction(aSurfaceTransaction); |
| 429 | |
| 430 | Region region; |
| 431 | for (uint32_t i = 0; i < count; ++i) { |
Marissa Wall | bb9b14f | 2019-04-23 14:10:15 -0700 | [diff] [blame] | 432 | region.orSelf(static_cast<const Rect&>(rects[i])); |
| 433 | } |
| 434 | |
| 435 | // Hardware composer interprets a DamageRegion with a single Rect of {0,0,0,0} to be an |
| 436 | // undamaged region and {0,0,-1,-1} to be a fully damaged buffer. This is a confusing |
| 437 | // distinction for a public api. Instead, default both cases to be a fully damaged buffer. |
| 438 | if (count == 1 && region.getBounds().isEmpty()) { |
| 439 | transaction->setSurfaceDamageRegion(surfaceControl, Region::INVALID_REGION); |
| 440 | return; |
Marissa Wall | f6a73fa | 2018-12-10 10:41:08 -0800 | [diff] [blame] | 441 | } |
| 442 | |
| 443 | transaction->setSurfaceDamageRegion(surfaceControl, region); |
| 444 | } |
Marissa Wall | 1be5a10 | 2019-01-18 16:14:04 -0800 | [diff] [blame] | 445 | |
| 446 | void ASurfaceTransaction_setDesiredPresentTime(ASurfaceTransaction* aSurfaceTransaction, |
| 447 | int64_t desiredPresentTime) { |
| 448 | CHECK_NOT_NULL(aSurfaceTransaction); |
| 449 | |
| 450 | Transaction* transaction = ASurfaceTransaction_to_Transaction(aSurfaceTransaction); |
| 451 | |
| 452 | transaction->setDesiredPresentTime(static_cast<nsecs_t>(desiredPresentTime)); |
| 453 | } |
| 454 | |
| 455 | void ASurfaceTransaction_setBufferAlpha(ASurfaceTransaction* aSurfaceTransaction, |
| 456 | ASurfaceControl* aSurfaceControl, |
| 457 | float alpha) { |
| 458 | CHECK_NOT_NULL(aSurfaceTransaction); |
| 459 | CHECK_NOT_NULL(aSurfaceControl); |
| 460 | |
| 461 | LOG_ALWAYS_FATAL_IF(alpha < 0.0 || alpha > 1.0, "invalid alpha"); |
| 462 | |
| 463 | sp<SurfaceControl> surfaceControl = ASurfaceControl_to_SurfaceControl(aSurfaceControl); |
| 464 | Transaction* transaction = ASurfaceTransaction_to_Transaction(aSurfaceTransaction); |
| 465 | |
| 466 | transaction->setAlpha(surfaceControl, alpha); |
| 467 | } |
| 468 | |
Marissa Wall | 7f24f79 | 2019-02-07 14:06:04 -0800 | [diff] [blame] | 469 | void ASurfaceTransaction_setBufferDataSpace(ASurfaceTransaction* aSurfaceTransaction, |
| 470 | ASurfaceControl* aSurfaceControl, |
| 471 | ADataSpace aDataSpace) { |
| 472 | CHECK_NOT_NULL(aSurfaceTransaction); |
| 473 | CHECK_NOT_NULL(aSurfaceControl); |
| 474 | |
| 475 | sp<SurfaceControl> surfaceControl = ASurfaceControl_to_SurfaceControl(aSurfaceControl); |
Valerie Hau | 5e18c43 | 2019-08-26 12:48:49 -0700 | [diff] [blame] | 476 | if (!isDataSpaceValid(surfaceControl, aDataSpace)) { |
| 477 | ALOGE("Failed to set buffer dataspace - invalid dataspace"); |
| 478 | return; |
| 479 | } |
Marissa Wall | 7f24f79 | 2019-02-07 14:06:04 -0800 | [diff] [blame] | 480 | Transaction* transaction = ASurfaceTransaction_to_Transaction(aSurfaceTransaction); |
Marissa Wall | 7f24f79 | 2019-02-07 14:06:04 -0800 | [diff] [blame] | 481 | transaction->setDataspace(surfaceControl, static_cast<ui::Dataspace>(aDataSpace)); |
| 482 | } |
| 483 | |
Marissa Wall | 1be5a10 | 2019-01-18 16:14:04 -0800 | [diff] [blame] | 484 | void ASurfaceTransaction_setHdrMetadata_smpte2086(ASurfaceTransaction* aSurfaceTransaction, |
| 485 | ASurfaceControl* aSurfaceControl, |
| 486 | struct AHdrMetadata_smpte2086* metadata) { |
| 487 | CHECK_NOT_NULL(aSurfaceTransaction); |
| 488 | CHECK_NOT_NULL(aSurfaceControl); |
| 489 | |
| 490 | sp<SurfaceControl> surfaceControl = ASurfaceControl_to_SurfaceControl(aSurfaceControl); |
| 491 | Transaction* transaction = ASurfaceTransaction_to_Transaction(aSurfaceTransaction); |
| 492 | |
| 493 | HdrMetadata hdrMetadata; |
| 494 | |
| 495 | if (metadata) { |
| 496 | hdrMetadata.smpte2086.displayPrimaryRed.x = metadata->displayPrimaryRed.x; |
| 497 | hdrMetadata.smpte2086.displayPrimaryRed.y = metadata->displayPrimaryRed.y; |
| 498 | hdrMetadata.smpte2086.displayPrimaryGreen.x = metadata->displayPrimaryGreen.x; |
| 499 | hdrMetadata.smpte2086.displayPrimaryGreen.y = metadata->displayPrimaryGreen.y; |
| 500 | hdrMetadata.smpte2086.displayPrimaryBlue.x = metadata->displayPrimaryBlue.x; |
| 501 | hdrMetadata.smpte2086.displayPrimaryBlue.y = metadata->displayPrimaryBlue.y; |
| 502 | hdrMetadata.smpte2086.whitePoint.x = metadata->whitePoint.x; |
| 503 | hdrMetadata.smpte2086.whitePoint.y = metadata->whitePoint.y; |
| 504 | hdrMetadata.smpte2086.minLuminance = metadata->minLuminance; |
| 505 | hdrMetadata.smpte2086.maxLuminance = metadata->maxLuminance; |
| 506 | |
| 507 | hdrMetadata.validTypes |= HdrMetadata::SMPTE2086; |
| 508 | } else { |
| 509 | hdrMetadata.validTypes &= ~HdrMetadata::SMPTE2086; |
| 510 | } |
| 511 | |
| 512 | transaction->setHdrMetadata(surfaceControl, hdrMetadata); |
| 513 | } |
| 514 | |
| 515 | void ASurfaceTransaction_setHdrMetadata_cta861_3(ASurfaceTransaction* aSurfaceTransaction, |
| 516 | ASurfaceControl* aSurfaceControl, |
| 517 | struct AHdrMetadata_cta861_3* metadata) { |
| 518 | CHECK_NOT_NULL(aSurfaceTransaction); |
| 519 | CHECK_NOT_NULL(aSurfaceControl); |
| 520 | |
| 521 | sp<SurfaceControl> surfaceControl = ASurfaceControl_to_SurfaceControl(aSurfaceControl); |
| 522 | Transaction* transaction = ASurfaceTransaction_to_Transaction(aSurfaceTransaction); |
| 523 | |
| 524 | HdrMetadata hdrMetadata; |
| 525 | |
| 526 | if (metadata) { |
| 527 | hdrMetadata.cta8613.maxContentLightLevel = metadata->maxContentLightLevel; |
| 528 | hdrMetadata.cta8613.maxFrameAverageLightLevel = metadata->maxFrameAverageLightLevel; |
| 529 | |
| 530 | hdrMetadata.validTypes |= HdrMetadata::CTA861_3; |
| 531 | } else { |
| 532 | hdrMetadata.validTypes &= ~HdrMetadata::CTA861_3; |
| 533 | } |
| 534 | |
| 535 | transaction->setHdrMetadata(surfaceControl, hdrMetadata); |
| 536 | } |
Valerie Hau | 5bbfd51 | 2019-01-22 17:39:43 -0800 | [diff] [blame] | 537 | |
| 538 | void ASurfaceTransaction_setColor(ASurfaceTransaction* aSurfaceTransaction, |
| 539 | ASurfaceControl* aSurfaceControl, |
| 540 | float r, float g, float b, float alpha, |
| 541 | ADataSpace dataspace) { |
| 542 | CHECK_NOT_NULL(aSurfaceTransaction); |
| 543 | CHECK_NOT_NULL(aSurfaceControl); |
| 544 | |
| 545 | sp<SurfaceControl> surfaceControl = ASurfaceControl_to_SurfaceControl(aSurfaceControl); |
Valerie Hau | 5e18c43 | 2019-08-26 12:48:49 -0700 | [diff] [blame] | 546 | if (!isDataSpaceValid(surfaceControl, dataspace)) { |
| 547 | ALOGE("Failed to set buffer dataspace - invalid dataspace"); |
| 548 | return; |
| 549 | } |
Valerie Hau | 5bbfd51 | 2019-01-22 17:39:43 -0800 | [diff] [blame] | 550 | Transaction* transaction = ASurfaceTransaction_to_Transaction(aSurfaceTransaction); |
| 551 | |
| 552 | half3 color; |
| 553 | color.r = r; |
| 554 | color.g = g; |
| 555 | color.b = b; |
| 556 | |
Valerie Hau | 6bc48231 | 2019-01-29 15:01:53 -0800 | [diff] [blame] | 557 | transaction->setBackgroundColor(surfaceControl, color, alpha, static_cast<ui::Dataspace>(dataspace)); |
Valerie Hau | 5bbfd51 | 2019-01-22 17:39:43 -0800 | [diff] [blame] | 558 | } |
Steven Thomas | 6cf051e | 2020-01-14 11:37:21 -0800 | [diff] [blame] | 559 | |
| 560 | void ASurfaceTransaction_setFrameRate(ASurfaceTransaction* aSurfaceTransaction, |
Steven Thomas | dd7bf2f | 2020-01-31 18:50:02 -0800 | [diff] [blame] | 561 | ASurfaceControl* aSurfaceControl, float frameRate, |
| 562 | int8_t compatibility) { |
Marin Shalamanov | 41ffa8d | 2020-10-13 12:35:20 +0200 | [diff] [blame^] | 563 | ASurfaceTransaction_setFrameRateWithSeamlessness(aSurfaceTransaction, aSurfaceControl, |
| 564 | frameRate, compatibility, |
| 565 | /*shouldBeSeamless*/ true); |
| 566 | } |
| 567 | |
| 568 | void ASurfaceTransaction_setFrameRateWithSeamlessness(ASurfaceTransaction* aSurfaceTransaction, |
| 569 | ASurfaceControl* aSurfaceControl, |
| 570 | float frameRate, int8_t compatibility, |
| 571 | bool shouldBeSeamless) { |
Steven Thomas | 6cf051e | 2020-01-14 11:37:21 -0800 | [diff] [blame] | 572 | CHECK_NOT_NULL(aSurfaceTransaction); |
| 573 | CHECK_NOT_NULL(aSurfaceControl); |
Steven Thomas | 6cf051e | 2020-01-14 11:37:21 -0800 | [diff] [blame] | 574 | Transaction* transaction = ASurfaceTransaction_to_Transaction(aSurfaceTransaction); |
Steven Thomas | dd7bf2f | 2020-01-31 18:50:02 -0800 | [diff] [blame] | 575 | sp<SurfaceControl> surfaceControl = ASurfaceControl_to_SurfaceControl(aSurfaceControl); |
Marin Shalamanov | 41ffa8d | 2020-10-13 12:35:20 +0200 | [diff] [blame^] | 576 | transaction->setFrameRate(surfaceControl, frameRate, compatibility, shouldBeSeamless); |
Steven Thomas | 6cf051e | 2020-01-14 11:37:21 -0800 | [diff] [blame] | 577 | } |