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