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