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: |
| 103 | return getHdrSupport(surfaceControl); |
| 104 | default: |
| 105 | return false; |
| 106 | } |
| 107 | } |
| 108 | |
Marissa Wall | f6a73fa | 2018-12-10 10:41:08 -0800 | [diff] [blame] | 109 | Transaction* ASurfaceTransaction_to_Transaction(ASurfaceTransaction* aSurfaceTransaction) { |
| 110 | return reinterpret_cast<Transaction*>(aSurfaceTransaction); |
| 111 | } |
| 112 | |
| 113 | SurfaceControl* ASurfaceControl_to_SurfaceControl(ASurfaceControl* aSurfaceControl) { |
| 114 | return reinterpret_cast<SurfaceControl*>(aSurfaceControl); |
| 115 | } |
| 116 | |
| 117 | void SurfaceControl_acquire(SurfaceControl* surfaceControl) { |
| 118 | // incStrong/decStrong token must be the same, doesn't matter what it is |
| 119 | surfaceControl->incStrong((void*)SurfaceControl_acquire); |
| 120 | } |
| 121 | |
| 122 | void SurfaceControl_release(SurfaceControl* surfaceControl) { |
| 123 | // incStrong/decStrong token must be the same, doesn't matter what it is |
| 124 | surfaceControl->decStrong((void*)SurfaceControl_acquire); |
| 125 | } |
| 126 | |
| 127 | ASurfaceControl* ASurfaceControl_createFromWindow(ANativeWindow* window, const char* debug_name) { |
| 128 | CHECK_NOT_NULL(window); |
| 129 | CHECK_NOT_NULL(debug_name); |
| 130 | |
| 131 | sp<SurfaceComposerClient> client = new SurfaceComposerClient(); |
| 132 | if (client->initCheck() != NO_ERROR) { |
| 133 | return nullptr; |
| 134 | } |
| 135 | |
| 136 | uint32_t flags = ISurfaceComposerClient::eFXSurfaceBufferState; |
| 137 | sp<SurfaceControl> surfaceControl = |
| 138 | client->createWithSurfaceParent(String8(debug_name), 0 /* width */, 0 /* height */, |
| 139 | // Format is only relevant for buffer queue layers. |
| 140 | PIXEL_FORMAT_UNKNOWN /* format */, flags, |
| 141 | static_cast<Surface*>(window)); |
| 142 | if (!surfaceControl) { |
| 143 | return nullptr; |
| 144 | } |
| 145 | |
| 146 | SurfaceControl_acquire(surfaceControl.get()); |
| 147 | return reinterpret_cast<ASurfaceControl*>(surfaceControl.get()); |
| 148 | } |
| 149 | |
| 150 | ASurfaceControl* ASurfaceControl_create(ASurfaceControl* parent, const char* debug_name) { |
| 151 | CHECK_NOT_NULL(parent); |
| 152 | CHECK_NOT_NULL(debug_name); |
| 153 | |
| 154 | SurfaceComposerClient* client = ASurfaceControl_to_SurfaceControl(parent)->getClient().get(); |
| 155 | |
| 156 | SurfaceControl* surfaceControlParent = ASurfaceControl_to_SurfaceControl(parent); |
| 157 | |
| 158 | uint32_t flags = ISurfaceComposerClient::eFXSurfaceBufferState; |
| 159 | sp<SurfaceControl> surfaceControl = |
| 160 | client->createSurface(String8(debug_name), 0 /* width */, 0 /* height */, |
| 161 | // Format is only relevant for buffer queue layers. |
| 162 | PIXEL_FORMAT_UNKNOWN /* format */, flags, |
| 163 | surfaceControlParent); |
| 164 | if (!surfaceControl) { |
| 165 | return nullptr; |
| 166 | } |
| 167 | |
| 168 | SurfaceControl_acquire(surfaceControl.get()); |
| 169 | return reinterpret_cast<ASurfaceControl*>(surfaceControl.get()); |
| 170 | } |
| 171 | |
Marissa Wall | 1be5a10 | 2019-01-18 16:14:04 -0800 | [diff] [blame] | 172 | void ASurfaceControl_release(ASurfaceControl* aSurfaceControl) { |
Marissa Wall | f6a73fa | 2018-12-10 10:41:08 -0800 | [diff] [blame] | 173 | sp<SurfaceControl> surfaceControl = ASurfaceControl_to_SurfaceControl(aSurfaceControl); |
| 174 | |
Marissa Wall | f6a73fa | 2018-12-10 10:41:08 -0800 | [diff] [blame] | 175 | SurfaceControl_release(surfaceControl.get()); |
| 176 | } |
| 177 | |
| 178 | ASurfaceTransaction* ASurfaceTransaction_create() { |
| 179 | Transaction* transaction = new Transaction; |
| 180 | return reinterpret_cast<ASurfaceTransaction*>(transaction); |
| 181 | } |
| 182 | |
| 183 | void ASurfaceTransaction_delete(ASurfaceTransaction* aSurfaceTransaction) { |
| 184 | Transaction* transaction = ASurfaceTransaction_to_Transaction(aSurfaceTransaction); |
| 185 | delete transaction; |
| 186 | } |
| 187 | |
| 188 | void ASurfaceTransaction_apply(ASurfaceTransaction* aSurfaceTransaction) { |
| 189 | CHECK_NOT_NULL(aSurfaceTransaction); |
| 190 | |
| 191 | Transaction* transaction = ASurfaceTransaction_to_Transaction(aSurfaceTransaction); |
| 192 | |
| 193 | transaction->apply(); |
| 194 | } |
| 195 | |
Marissa Wall | 1be5a10 | 2019-01-18 16:14:04 -0800 | [diff] [blame] | 196 | typedef struct ASurfaceControlStats { |
| 197 | int64_t acquireTime; |
| 198 | sp<Fence> previousReleaseFence; |
| 199 | } ASurfaceControlStats; |
| 200 | |
| 201 | struct ASurfaceTransactionStats { |
| 202 | std::unordered_map<ASurfaceControl*, ASurfaceControlStats> aSurfaceControlStats; |
| 203 | int64_t latchTime; |
| 204 | sp<Fence> presentFence; |
| 205 | }; |
| 206 | |
| 207 | int64_t ASurfaceTransactionStats_getLatchTime(ASurfaceTransactionStats* aSurfaceTransactionStats) { |
| 208 | CHECK_NOT_NULL(aSurfaceTransactionStats); |
| 209 | return aSurfaceTransactionStats->latchTime; |
| 210 | } |
| 211 | |
| 212 | int ASurfaceTransactionStats_getPresentFenceFd(ASurfaceTransactionStats* aSurfaceTransactionStats) { |
| 213 | CHECK_NOT_NULL(aSurfaceTransactionStats); |
| 214 | auto& presentFence = aSurfaceTransactionStats->presentFence; |
| 215 | return (presentFence) ? presentFence->dup() : -1; |
| 216 | } |
| 217 | |
| 218 | void ASurfaceTransactionStats_getASurfaceControls(ASurfaceTransactionStats* aSurfaceTransactionStats, |
| 219 | ASurfaceControl*** outASurfaceControls, |
| 220 | size_t* outASurfaceControlsSize) { |
| 221 | CHECK_NOT_NULL(aSurfaceTransactionStats); |
| 222 | CHECK_NOT_NULL(outASurfaceControls); |
| 223 | CHECK_NOT_NULL(outASurfaceControlsSize); |
| 224 | |
| 225 | size_t size = aSurfaceTransactionStats->aSurfaceControlStats.size(); |
| 226 | |
| 227 | SurfaceControl** surfaceControls = new SurfaceControl*[size]; |
| 228 | ASurfaceControl** aSurfaceControls = reinterpret_cast<ASurfaceControl**>(surfaceControls); |
| 229 | |
| 230 | size_t i = 0; |
| 231 | for (auto& [aSurfaceControl, aSurfaceControlStats] : aSurfaceTransactionStats->aSurfaceControlStats) { |
| 232 | aSurfaceControls[i] = aSurfaceControl; |
| 233 | i++; |
| 234 | } |
| 235 | |
| 236 | *outASurfaceControls = aSurfaceControls; |
| 237 | *outASurfaceControlsSize = size; |
| 238 | } |
| 239 | |
| 240 | int64_t ASurfaceTransactionStats_getAcquireTime(ASurfaceTransactionStats* aSurfaceTransactionStats, |
| 241 | ASurfaceControl* aSurfaceControl) { |
| 242 | CHECK_NOT_NULL(aSurfaceTransactionStats); |
| 243 | CHECK_NOT_NULL(aSurfaceControl); |
| 244 | |
| 245 | const auto& aSurfaceControlStats = |
| 246 | aSurfaceTransactionStats->aSurfaceControlStats.find(aSurfaceControl); |
| 247 | LOG_ALWAYS_FATAL_IF( |
| 248 | aSurfaceControlStats == aSurfaceTransactionStats->aSurfaceControlStats.end(), |
| 249 | "ASurfaceControl not found"); |
| 250 | |
| 251 | return aSurfaceControlStats->second.acquireTime; |
| 252 | } |
| 253 | |
| 254 | int ASurfaceTransactionStats_getPreviousReleaseFenceFd( |
| 255 | ASurfaceTransactionStats* aSurfaceTransactionStats, ASurfaceControl* aSurfaceControl) { |
| 256 | CHECK_NOT_NULL(aSurfaceTransactionStats); |
| 257 | CHECK_NOT_NULL(aSurfaceControl); |
| 258 | |
| 259 | const auto& aSurfaceControlStats = |
| 260 | aSurfaceTransactionStats->aSurfaceControlStats.find(aSurfaceControl); |
| 261 | LOG_ALWAYS_FATAL_IF( |
| 262 | aSurfaceControlStats == aSurfaceTransactionStats->aSurfaceControlStats.end(), |
| 263 | "ASurfaceControl not found"); |
| 264 | |
| 265 | auto& previousReleaseFence = aSurfaceControlStats->second.previousReleaseFence; |
| 266 | return (previousReleaseFence) ? previousReleaseFence->dup() : -1; |
| 267 | } |
| 268 | |
| 269 | void ASurfaceTransactionStats_releaseASurfaceControls(ASurfaceControl** aSurfaceControls) { |
| 270 | CHECK_NOT_NULL(aSurfaceControls); |
| 271 | |
| 272 | SurfaceControl** surfaceControls = reinterpret_cast<SurfaceControl**>(aSurfaceControls); |
| 273 | delete[] surfaceControls; |
| 274 | } |
| 275 | |
Marissa Wall | f6a73fa | 2018-12-10 10:41:08 -0800 | [diff] [blame] | 276 | void ASurfaceTransaction_setOnComplete(ASurfaceTransaction* aSurfaceTransaction, void* context, |
| 277 | ASurfaceTransaction_OnComplete func) { |
| 278 | CHECK_NOT_NULL(aSurfaceTransaction); |
| 279 | CHECK_NOT_NULL(context); |
| 280 | CHECK_NOT_NULL(func); |
| 281 | |
| 282 | TransactionCompletedCallbackTakesContext callback = [func](void* callback_context, |
Marissa Wall | 1be5a10 | 2019-01-18 16:14:04 -0800 | [diff] [blame] | 283 | nsecs_t latchTime, |
| 284 | const sp<Fence>& presentFence, |
| 285 | const std::vector<SurfaceControlStats>& surfaceControlStats) { |
| 286 | ASurfaceTransactionStats aSurfaceTransactionStats; |
| 287 | |
| 288 | aSurfaceTransactionStats.latchTime = latchTime; |
| 289 | aSurfaceTransactionStats.presentFence = presentFence; |
| 290 | |
| 291 | auto& aSurfaceControlStats = aSurfaceTransactionStats.aSurfaceControlStats; |
| 292 | |
| 293 | for (const auto& [surfaceControl, acquireTime, previousReleaseFence] : surfaceControlStats) { |
| 294 | ASurfaceControl* aSurfaceControl = reinterpret_cast<ASurfaceControl*>(surfaceControl.get()); |
| 295 | aSurfaceControlStats[aSurfaceControl].acquireTime = acquireTime; |
| 296 | aSurfaceControlStats[aSurfaceControl].previousReleaseFence = previousReleaseFence; |
| 297 | } |
| 298 | |
| 299 | (*func)(callback_context, &aSurfaceTransactionStats); |
Marissa Wall | f6a73fa | 2018-12-10 10:41:08 -0800 | [diff] [blame] | 300 | }; |
| 301 | |
| 302 | Transaction* transaction = ASurfaceTransaction_to_Transaction(aSurfaceTransaction); |
| 303 | |
| 304 | transaction->addTransactionCompletedCallback(callback, context); |
| 305 | } |
| 306 | |
Marissa Wall | 1be5a10 | 2019-01-18 16:14:04 -0800 | [diff] [blame] | 307 | void ASurfaceTransaction_reparent(ASurfaceTransaction* aSurfaceTransaction, |
| 308 | ASurfaceControl* aSurfaceControl, |
| 309 | ASurfaceControl* newParentASurfaceControl) { |
| 310 | CHECK_NOT_NULL(aSurfaceTransaction); |
| 311 | CHECK_NOT_NULL(aSurfaceControl); |
| 312 | |
| 313 | sp<SurfaceControl> surfaceControl = ASurfaceControl_to_SurfaceControl(aSurfaceControl); |
| 314 | sp<SurfaceControl> newParentSurfaceControl = ASurfaceControl_to_SurfaceControl( |
| 315 | newParentASurfaceControl); |
| 316 | sp<IBinder> newParentHandle = (newParentSurfaceControl)? newParentSurfaceControl->getHandle() : nullptr; |
| 317 | Transaction* transaction = ASurfaceTransaction_to_Transaction(aSurfaceTransaction); |
| 318 | |
| 319 | transaction->reparent(surfaceControl, newParentHandle); |
| 320 | } |
| 321 | |
| 322 | void ASurfaceTransaction_setVisibility(ASurfaceTransaction* aSurfaceTransaction, |
| 323 | ASurfaceControl* aSurfaceControl, |
Marissa Wall | f6a73fa | 2018-12-10 10:41:08 -0800 | [diff] [blame] | 324 | int8_t visibility) { |
| 325 | CHECK_NOT_NULL(aSurfaceTransaction); |
| 326 | CHECK_NOT_NULL(aSurfaceControl); |
| 327 | |
| 328 | sp<SurfaceControl> surfaceControl = ASurfaceControl_to_SurfaceControl(aSurfaceControl); |
| 329 | Transaction* transaction = ASurfaceTransaction_to_Transaction(aSurfaceTransaction); |
| 330 | |
| 331 | switch (visibility) { |
| 332 | case ASURFACE_TRANSACTION_VISIBILITY_SHOW: |
| 333 | transaction->show(surfaceControl); |
| 334 | break; |
| 335 | case ASURFACE_TRANSACTION_VISIBILITY_HIDE: |
| 336 | transaction->hide(surfaceControl); |
| 337 | break; |
| 338 | default: |
| 339 | LOG_ALWAYS_FATAL("invalid visibility %d", visibility); |
| 340 | } |
| 341 | } |
| 342 | |
Marissa Wall | 1be5a10 | 2019-01-18 16:14:04 -0800 | [diff] [blame] | 343 | void ASurfaceTransaction_setZOrder(ASurfaceTransaction* aSurfaceTransaction, |
| 344 | ASurfaceControl* aSurfaceControl, |
Marissa Wall | f6a73fa | 2018-12-10 10:41:08 -0800 | [diff] [blame] | 345 | int32_t z_order) { |
| 346 | CHECK_NOT_NULL(aSurfaceTransaction); |
| 347 | CHECK_NOT_NULL(aSurfaceControl); |
| 348 | |
| 349 | sp<SurfaceControl> surfaceControl = ASurfaceControl_to_SurfaceControl(aSurfaceControl); |
| 350 | Transaction* transaction = ASurfaceTransaction_to_Transaction(aSurfaceTransaction); |
| 351 | |
| 352 | transaction->setLayer(surfaceControl, z_order); |
| 353 | } |
| 354 | |
Marissa Wall | 1be5a10 | 2019-01-18 16:14:04 -0800 | [diff] [blame] | 355 | void ASurfaceTransaction_setBuffer(ASurfaceTransaction* aSurfaceTransaction, |
| 356 | ASurfaceControl* aSurfaceControl, |
| 357 | AHardwareBuffer* buffer, int acquire_fence_fd) { |
Marissa Wall | f6a73fa | 2018-12-10 10:41:08 -0800 | [diff] [blame] | 358 | CHECK_NOT_NULL(aSurfaceTransaction); |
| 359 | CHECK_NOT_NULL(aSurfaceControl); |
| 360 | |
| 361 | sp<SurfaceControl> surfaceControl = ASurfaceControl_to_SurfaceControl(aSurfaceControl); |
| 362 | Transaction* transaction = ASurfaceTransaction_to_Transaction(aSurfaceTransaction); |
| 363 | |
| 364 | sp<GraphicBuffer> graphic_buffer(reinterpret_cast<GraphicBuffer*>(buffer)); |
| 365 | |
| 366 | transaction->setBuffer(surfaceControl, graphic_buffer); |
Marissa Wall | 1be5a10 | 2019-01-18 16:14:04 -0800 | [diff] [blame] | 367 | if (acquire_fence_fd != -1) { |
| 368 | sp<Fence> fence = new Fence(acquire_fence_fd); |
Marissa Wall | f6a73fa | 2018-12-10 10:41:08 -0800 | [diff] [blame] | 369 | transaction->setAcquireFence(surfaceControl, fence); |
| 370 | } |
| 371 | } |
| 372 | |
| 373 | void ASurfaceTransaction_setGeometry(ASurfaceTransaction* aSurfaceTransaction, |
| 374 | ASurfaceControl* aSurfaceControl, const ARect& source, |
| 375 | const ARect& destination, int32_t transform) { |
| 376 | CHECK_NOT_NULL(aSurfaceTransaction); |
| 377 | CHECK_NOT_NULL(aSurfaceControl); |
| 378 | CHECK_VALID_RECT(source); |
| 379 | CHECK_VALID_RECT(destination); |
| 380 | |
| 381 | sp<SurfaceControl> surfaceControl = ASurfaceControl_to_SurfaceControl(aSurfaceControl); |
| 382 | Transaction* transaction = ASurfaceTransaction_to_Transaction(aSurfaceTransaction); |
| 383 | |
| 384 | transaction->setCrop(surfaceControl, static_cast<const Rect&>(source)); |
| 385 | transaction->setFrame(surfaceControl, static_cast<const Rect&>(destination)); |
| 386 | transaction->setTransform(surfaceControl, transform); |
| 387 | } |
| 388 | |
| 389 | void ASurfaceTransaction_setBufferTransparency(ASurfaceTransaction* aSurfaceTransaction, |
| 390 | ASurfaceControl* aSurfaceControl, |
| 391 | int8_t transparency) { |
| 392 | CHECK_NOT_NULL(aSurfaceTransaction); |
| 393 | CHECK_NOT_NULL(aSurfaceControl); |
| 394 | |
| 395 | sp<SurfaceControl> surfaceControl = ASurfaceControl_to_SurfaceControl(aSurfaceControl); |
| 396 | Transaction* transaction = ASurfaceTransaction_to_Transaction(aSurfaceTransaction); |
| 397 | |
| 398 | uint32_t flags = (transparency == ASURFACE_TRANSACTION_TRANSPARENCY_OPAQUE) ? |
| 399 | layer_state_t::eLayerOpaque : 0; |
| 400 | transaction->setFlags(surfaceControl, flags, layer_state_t::eLayerOpaque); |
| 401 | } |
| 402 | |
Marissa Wall | 1be5a10 | 2019-01-18 16:14:04 -0800 | [diff] [blame] | 403 | void ASurfaceTransaction_setDamageRegion(ASurfaceTransaction* aSurfaceTransaction, |
| 404 | ASurfaceControl* aSurfaceControl, |
Marissa Wall | f6a73fa | 2018-12-10 10:41:08 -0800 | [diff] [blame] | 405 | const ARect rects[], uint32_t count) { |
| 406 | CHECK_NOT_NULL(aSurfaceTransaction); |
| 407 | CHECK_NOT_NULL(aSurfaceControl); |
| 408 | |
| 409 | sp<SurfaceControl> surfaceControl = ASurfaceControl_to_SurfaceControl(aSurfaceControl); |
| 410 | Transaction* transaction = ASurfaceTransaction_to_Transaction(aSurfaceTransaction); |
| 411 | |
| 412 | Region region; |
| 413 | for (uint32_t i = 0; i < count; ++i) { |
| 414 | region.merge(static_cast<const Rect&>(rects[i])); |
| 415 | } |
| 416 | |
| 417 | transaction->setSurfaceDamageRegion(surfaceControl, region); |
| 418 | } |
Marissa Wall | 1be5a10 | 2019-01-18 16:14:04 -0800 | [diff] [blame] | 419 | |
| 420 | void ASurfaceTransaction_setDesiredPresentTime(ASurfaceTransaction* aSurfaceTransaction, |
| 421 | int64_t desiredPresentTime) { |
| 422 | CHECK_NOT_NULL(aSurfaceTransaction); |
| 423 | |
| 424 | Transaction* transaction = ASurfaceTransaction_to_Transaction(aSurfaceTransaction); |
| 425 | |
| 426 | transaction->setDesiredPresentTime(static_cast<nsecs_t>(desiredPresentTime)); |
| 427 | } |
| 428 | |
| 429 | void ASurfaceTransaction_setBufferAlpha(ASurfaceTransaction* aSurfaceTransaction, |
| 430 | ASurfaceControl* aSurfaceControl, |
| 431 | float alpha) { |
| 432 | CHECK_NOT_NULL(aSurfaceTransaction); |
| 433 | CHECK_NOT_NULL(aSurfaceControl); |
| 434 | |
| 435 | LOG_ALWAYS_FATAL_IF(alpha < 0.0 || alpha > 1.0, "invalid alpha"); |
| 436 | |
| 437 | sp<SurfaceControl> surfaceControl = ASurfaceControl_to_SurfaceControl(aSurfaceControl); |
| 438 | Transaction* transaction = ASurfaceTransaction_to_Transaction(aSurfaceTransaction); |
| 439 | |
| 440 | transaction->setAlpha(surfaceControl, alpha); |
| 441 | } |
| 442 | |
| 443 | void ASurfaceTransaction_setHdrMetadata_smpte2086(ASurfaceTransaction* aSurfaceTransaction, |
| 444 | ASurfaceControl* aSurfaceControl, |
| 445 | struct AHdrMetadata_smpte2086* metadata) { |
| 446 | CHECK_NOT_NULL(aSurfaceTransaction); |
| 447 | CHECK_NOT_NULL(aSurfaceControl); |
| 448 | |
| 449 | sp<SurfaceControl> surfaceControl = ASurfaceControl_to_SurfaceControl(aSurfaceControl); |
| 450 | Transaction* transaction = ASurfaceTransaction_to_Transaction(aSurfaceTransaction); |
| 451 | |
| 452 | HdrMetadata hdrMetadata; |
| 453 | |
| 454 | if (metadata) { |
| 455 | hdrMetadata.smpte2086.displayPrimaryRed.x = metadata->displayPrimaryRed.x; |
| 456 | hdrMetadata.smpte2086.displayPrimaryRed.y = metadata->displayPrimaryRed.y; |
| 457 | hdrMetadata.smpte2086.displayPrimaryGreen.x = metadata->displayPrimaryGreen.x; |
| 458 | hdrMetadata.smpte2086.displayPrimaryGreen.y = metadata->displayPrimaryGreen.y; |
| 459 | hdrMetadata.smpte2086.displayPrimaryBlue.x = metadata->displayPrimaryBlue.x; |
| 460 | hdrMetadata.smpte2086.displayPrimaryBlue.y = metadata->displayPrimaryBlue.y; |
| 461 | hdrMetadata.smpte2086.whitePoint.x = metadata->whitePoint.x; |
| 462 | hdrMetadata.smpte2086.whitePoint.y = metadata->whitePoint.y; |
| 463 | hdrMetadata.smpte2086.minLuminance = metadata->minLuminance; |
| 464 | hdrMetadata.smpte2086.maxLuminance = metadata->maxLuminance; |
| 465 | |
| 466 | hdrMetadata.validTypes |= HdrMetadata::SMPTE2086; |
| 467 | } else { |
| 468 | hdrMetadata.validTypes &= ~HdrMetadata::SMPTE2086; |
| 469 | } |
| 470 | |
| 471 | transaction->setHdrMetadata(surfaceControl, hdrMetadata); |
| 472 | } |
| 473 | |
| 474 | void ASurfaceTransaction_setHdrMetadata_cta861_3(ASurfaceTransaction* aSurfaceTransaction, |
| 475 | ASurfaceControl* aSurfaceControl, |
| 476 | struct AHdrMetadata_cta861_3* metadata) { |
| 477 | CHECK_NOT_NULL(aSurfaceTransaction); |
| 478 | CHECK_NOT_NULL(aSurfaceControl); |
| 479 | |
| 480 | sp<SurfaceControl> surfaceControl = ASurfaceControl_to_SurfaceControl(aSurfaceControl); |
| 481 | Transaction* transaction = ASurfaceTransaction_to_Transaction(aSurfaceTransaction); |
| 482 | |
| 483 | HdrMetadata hdrMetadata; |
| 484 | |
| 485 | if (metadata) { |
| 486 | hdrMetadata.cta8613.maxContentLightLevel = metadata->maxContentLightLevel; |
| 487 | hdrMetadata.cta8613.maxFrameAverageLightLevel = metadata->maxFrameAverageLightLevel; |
| 488 | |
| 489 | hdrMetadata.validTypes |= HdrMetadata::CTA861_3; |
| 490 | } else { |
| 491 | hdrMetadata.validTypes &= ~HdrMetadata::CTA861_3; |
| 492 | } |
| 493 | |
| 494 | transaction->setHdrMetadata(surfaceControl, hdrMetadata); |
| 495 | } |
Valerie Hau | 5bbfd51 | 2019-01-22 17:39:43 -0800 | [diff] [blame] | 496 | |
| 497 | void ASurfaceTransaction_setColor(ASurfaceTransaction* aSurfaceTransaction, |
| 498 | ASurfaceControl* aSurfaceControl, |
| 499 | float r, float g, float b, float alpha, |
| 500 | ADataSpace dataspace) { |
| 501 | CHECK_NOT_NULL(aSurfaceTransaction); |
| 502 | CHECK_NOT_NULL(aSurfaceControl); |
| 503 | |
| 504 | sp<SurfaceControl> surfaceControl = ASurfaceControl_to_SurfaceControl(aSurfaceControl); |
| 505 | LOG_ALWAYS_FATAL_IF(!isDataSpaceValid(surfaceControl, dataspace), "invalid dataspace"); |
| 506 | Transaction* transaction = ASurfaceTransaction_to_Transaction(aSurfaceTransaction); |
| 507 | |
| 508 | half3 color; |
| 509 | color.r = r; |
| 510 | color.g = g; |
| 511 | color.b = b; |
| 512 | |
| 513 | transaction->setColor(surfaceControl, color) |
| 514 | .setColorAlpha(surfaceControl, alpha) |
| 515 | .setColorDataspace(surfaceControl, static_cast<ui::Dataspace>(dataspace)); |
| 516 | } |