Dennis Tsiang | 33f0ece | 2023-11-29 12:45:04 +0000 | [diff] [blame] | 1 | /* |
Drew Davenport | 5951b11 | 2024-08-05 09:44:27 -0600 | [diff] [blame] | 2 | * Copyright (C) 2024 The Android Open Source Project |
Dennis Tsiang | 33f0ece | 2023-11-29 12:45:04 +0000 | [diff] [blame] | 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 | |
Drew Davenport | 5951b11 | 2024-08-05 09:44:27 -0600 | [diff] [blame] | 17 | #define LOG_TAG "drmhwc" |
Dennis Tsiang | 33f0ece | 2023-11-29 12:45:04 +0000 | [diff] [blame] | 18 | #define ATRACE_TAG (ATRACE_TAG_GRAPHICS | ATRACE_TAG_HAL) |
| 19 | |
| 20 | #include "ComposerClient.h" |
| 21 | |
Drew Davenport | 5951b11 | 2024-08-05 09:44:27 -0600 | [diff] [blame] | 22 | #include <cinttypes> |
Dennis Tsiang | 1a96620 | 2024-01-24 12:46:33 +0000 | [diff] [blame] | 23 | #include <cmath> |
Drew Davenport | 5951b11 | 2024-08-05 09:44:27 -0600 | [diff] [blame] | 24 | #include <memory> |
| 25 | #include <unordered_map> |
| 26 | #include <vector> |
| 27 | |
Drew Davenport | a241a77 | 2024-09-24 11:26:30 -0600 | [diff] [blame] | 28 | #include <aidl/android/hardware/graphics/common/Transform.h> |
| 29 | #include <aidl/android/hardware/graphics/composer3/ClientTarget.h> |
| 30 | #include <aidl/android/hardware/graphics/composer3/Composition.h> |
| 31 | #include <aidl/android/hardware/graphics/composer3/DisplayRequest.h> |
| 32 | #include <aidl/android/hardware/graphics/composer3/IComposerClient.h> |
| 33 | #include <aidl/android/hardware/graphics/composer3/PowerMode.h> |
| 34 | #include <aidl/android/hardware/graphics/composer3/PresentOrValidate.h> |
| 35 | #include <aidl/android/hardware/graphics/composer3/RenderIntent.h> |
| 36 | #include <aidlcommonsupport/NativeHandle.h> |
| 37 | #include <android-base/logging.h> |
| 38 | #include <android/binder_auto_utils.h> |
| 39 | #include <android/binder_ibinder_platform.h> |
| 40 | #include <cutils/native_handle.h> |
| 41 | #include <hardware/hwcomposer2.h> |
| 42 | #include <hardware/hwcomposer_defs.h> |
| 43 | |
| 44 | #include "bufferinfo/BufferInfo.h" |
Drew Davenport | 5951b11 | 2024-08-05 09:44:27 -0600 | [diff] [blame] | 45 | #include "hwc2_device/HwcDisplay.h" |
Drew Davenport | f7e8833 | 2024-09-06 12:54:38 -0600 | [diff] [blame] | 46 | #include "hwc2_device/HwcDisplayConfigs.h" |
Drew Davenport | 5951b11 | 2024-08-05 09:44:27 -0600 | [diff] [blame] | 47 | #include "hwc2_device/HwcLayer.h" |
| 48 | #include "hwc3/DrmHwcThree.h" |
| 49 | #include "hwc3/Utils.h" |
| 50 | |
| 51 | using ::android::HwcDisplay; |
Drew Davenport | 1afb579 | 2024-09-24 12:53:22 -0600 | [diff] [blame] | 52 | using ::android::HwcDisplayConfig; |
Drew Davenport | f7e8833 | 2024-09-06 12:54:38 -0600 | [diff] [blame] | 53 | using ::android::HwcDisplayConfigs; |
Drew Davenport | a241a77 | 2024-09-24 11:26:30 -0600 | [diff] [blame] | 54 | using ::android::HwcLayer; |
Drew Davenport | 51c61e4 | 2024-09-24 17:13:39 -0600 | [diff] [blame] | 55 | using ::android::LayerTransform; |
Dennis Tsiang | 33f0ece | 2023-11-29 12:45:04 +0000 | [diff] [blame] | 56 | |
| 57 | #include "utils/log.h" |
| 58 | |
| 59 | namespace aidl::android::hardware::graphics::composer3::impl { |
Drew Davenport | 5951b11 | 2024-08-05 09:44:27 -0600 | [diff] [blame] | 60 | namespace { |
Dennis Tsiang | 33f0ece | 2023-11-29 12:45:04 +0000 | [diff] [blame] | 61 | |
Drew Davenport | 5951b11 | 2024-08-05 09:44:27 -0600 | [diff] [blame] | 62 | // clang-format off |
| 63 | constexpr std::array<float, 16> kIdentityMatrix = { |
| 64 | 1.0F, 0.0F, 0.0F, 0.0F, |
| 65 | 0.0F, 1.0F, 0.0F, 0.0F, |
| 66 | 0.0F, 0.0F, 1.0F, 0.0F, |
| 67 | 0.0F, 0.0F, 0.0F, 1.0F, |
| 68 | }; |
| 69 | // clang-format on |
Dennis Tsiang | 33f0ece | 2023-11-29 12:45:04 +0000 | [diff] [blame] | 70 | |
Drew Davenport | a241a77 | 2024-09-24 11:26:30 -0600 | [diff] [blame] | 71 | std::optional<BufferBlendMode> AidlToBlendMode( |
| 72 | const std::optional<ParcelableBlendMode>& aidl_blend_mode) { |
| 73 | if (!aidl_blend_mode) { |
| 74 | return std::nullopt; |
| 75 | } |
| 76 | |
| 77 | switch (aidl_blend_mode->blendMode) { |
| 78 | case common::BlendMode::NONE: |
| 79 | return BufferBlendMode::kNone; |
| 80 | case common::BlendMode::PREMULTIPLIED: |
| 81 | return BufferBlendMode::kPreMult; |
| 82 | case common::BlendMode::COVERAGE: |
| 83 | return BufferBlendMode::kCoverage; |
| 84 | case common::BlendMode::INVALID: |
| 85 | ALOGE("Invalid BlendMode"); |
| 86 | return std::nullopt; |
| 87 | } |
| 88 | } |
| 89 | |
Drew Davenport | ac9681e | 2024-09-24 12:17:34 -0600 | [diff] [blame] | 90 | std::optional<BufferColorSpace> AidlToColorSpace( |
| 91 | const std::optional<ParcelableDataspace>& dataspace) { |
| 92 | if (!dataspace) { |
| 93 | return std::nullopt; |
| 94 | } |
| 95 | |
| 96 | int32_t standard = static_cast<int32_t>(dataspace->dataspace) & |
| 97 | static_cast<int32_t>(common::Dataspace::STANDARD_MASK); |
| 98 | switch (standard) { |
| 99 | case static_cast<int32_t>(common::Dataspace::STANDARD_BT709): |
| 100 | return BufferColorSpace::kItuRec709; |
| 101 | case static_cast<int32_t>(common::Dataspace::STANDARD_BT601_625): |
| 102 | case static_cast<int32_t>(common::Dataspace::STANDARD_BT601_625_UNADJUSTED): |
| 103 | case static_cast<int32_t>(common::Dataspace::STANDARD_BT601_525): |
| 104 | case static_cast<int32_t>(common::Dataspace::STANDARD_BT601_525_UNADJUSTED): |
| 105 | return BufferColorSpace::kItuRec601; |
| 106 | case static_cast<int32_t>(common::Dataspace::STANDARD_BT2020): |
| 107 | case static_cast<int32_t>( |
| 108 | common::Dataspace::STANDARD_BT2020_CONSTANT_LUMINANCE): |
| 109 | return BufferColorSpace::kItuRec2020; |
| 110 | default: |
| 111 | ALOGE("Unsupported standard: %d", standard); |
| 112 | return std::nullopt; |
| 113 | } |
| 114 | } |
| 115 | |
| 116 | std::optional<BufferSampleRange> AidlToSampleRange( |
| 117 | const std::optional<ParcelableDataspace>& dataspace) { |
| 118 | if (!dataspace) { |
| 119 | return std::nullopt; |
| 120 | } |
| 121 | |
| 122 | int32_t sample_range = static_cast<int32_t>(dataspace->dataspace) & |
| 123 | static_cast<int32_t>(common::Dataspace::RANGE_MASK); |
| 124 | switch (sample_range) { |
| 125 | case static_cast<int32_t>(common::Dataspace::RANGE_FULL): |
| 126 | return BufferSampleRange::kFullRange; |
| 127 | case static_cast<int32_t>(common::Dataspace::RANGE_LIMITED): |
| 128 | return BufferSampleRange::kLimitedRange; |
| 129 | default: |
| 130 | ALOGE("Unsupported sample range: %d", sample_range); |
| 131 | return std::nullopt; |
| 132 | } |
| 133 | } |
| 134 | |
Drew Davenport | 1b0d8b7 | 2024-09-24 15:31:38 -0600 | [diff] [blame] | 135 | bool IsSupportedCompositionType( |
| 136 | const std::optional<ParcelableComposition> composition) { |
| 137 | if (!composition) { |
| 138 | return true; |
| 139 | } |
| 140 | switch (composition->composition) { |
| 141 | case Composition::INVALID: |
| 142 | case Composition::CLIENT: |
| 143 | case Composition::DEVICE: |
| 144 | case Composition::SOLID_COLOR: |
| 145 | case Composition::CURSOR: |
| 146 | return true; |
| 147 | |
| 148 | // Unsupported composition types. Set an error for the current |
| 149 | // DisplayCommand and return. |
| 150 | case Composition::DISPLAY_DECORATION: |
| 151 | case Composition::SIDEBAND: |
| 152 | case Composition::REFRESH_RATE_INDICATOR: |
| 153 | return false; |
| 154 | } |
| 155 | } |
| 156 | |
Drew Davenport | 9c6f7e5 | 2024-09-25 14:58:18 -0600 | [diff] [blame] | 157 | bool ValidateLayerBrightness(const std::optional<LayerBrightness>& brightness) { |
| 158 | if (!brightness) { |
| 159 | return true; |
| 160 | } |
| 161 | return !(std::signbit(brightness->brightness) || |
| 162 | std::isnan(brightness->brightness)); |
| 163 | } |
| 164 | |
Drew Davenport | 1b0d8b7 | 2024-09-24 15:31:38 -0600 | [diff] [blame] | 165 | std::optional<HWC2::Composition> AidlToCompositionType( |
| 166 | const std::optional<ParcelableComposition> composition) { |
| 167 | if (!composition) { |
| 168 | return std::nullopt; |
| 169 | } |
| 170 | |
| 171 | switch (composition->composition) { |
| 172 | case Composition::INVALID: |
| 173 | return HWC2::Composition::Invalid; |
| 174 | case Composition::CLIENT: |
| 175 | return HWC2::Composition::Client; |
| 176 | case Composition::DEVICE: |
| 177 | return HWC2::Composition::Device; |
| 178 | case Composition::SOLID_COLOR: |
| 179 | return HWC2::Composition::SolidColor; |
| 180 | case Composition::CURSOR: |
| 181 | return HWC2::Composition::Cursor; |
| 182 | |
| 183 | // Unsupported composition types. |
| 184 | case Composition::DISPLAY_DECORATION: |
| 185 | case Composition::SIDEBAND: |
| 186 | case Composition::REFRESH_RATE_INDICATOR: |
| 187 | ALOGE("Unsupported composition type: %s", |
| 188 | toString(composition->composition).c_str()); |
| 189 | return std::nullopt; |
| 190 | } |
| 191 | } |
| 192 | |
Roman Stratiienko | 71a8f02 | 2024-10-16 23:17:33 +0300 | [diff] [blame] | 193 | #if __ANDROID_API__ < 35 |
| 194 | |
| 195 | class DisplayConfiguration { |
| 196 | public: |
| 197 | class Dpi { |
| 198 | public: |
| 199 | float x = 0.000000F; |
| 200 | float y = 0.000000F; |
| 201 | }; |
| 202 | // NOLINTNEXTLINE(readability-identifier-naming) |
| 203 | int32_t configId = 0; |
| 204 | int32_t width = 0; |
| 205 | int32_t height = 0; |
| 206 | std::optional<Dpi> dpi; |
| 207 | // NOLINTNEXTLINE(readability-identifier-naming) |
| 208 | int32_t configGroup = 0; |
| 209 | // NOLINTNEXTLINE(readability-identifier-naming) |
| 210 | int32_t vsyncPeriod = 0; |
| 211 | }; |
| 212 | |
| 213 | #endif |
| 214 | |
Drew Davenport | 1afb579 | 2024-09-24 12:53:22 -0600 | [diff] [blame] | 215 | DisplayConfiguration HwcDisplayConfigToAidlConfiguration( |
| 216 | const HwcDisplayConfigs& configs, const HwcDisplayConfig& config) { |
| 217 | DisplayConfiguration aidl_configuration = |
| 218 | {.configId = static_cast<int32_t>(config.id), |
| 219 | .width = config.mode.GetRawMode().hdisplay, |
| 220 | .height = config.mode.GetRawMode().vdisplay, |
| 221 | .configGroup = static_cast<int32_t>(config.group_id), |
| 222 | .vsyncPeriod = config.mode.GetVSyncPeriodNs()}; |
| 223 | |
| 224 | if (configs.mm_width != 0) { |
| 225 | // ideally this should be vdisplay/mm_heigth, however mm_height |
| 226 | // comes from edid parsing and is highly unreliable. Viewing the |
| 227 | // rarity of anisotropic displays, falling back to a single value |
| 228 | // for dpi yield more correct output. |
| 229 | static const float kMmPerInch = 25.4; |
| 230 | float dpi = float(config.mode.GetRawMode().hdisplay) * kMmPerInch / |
| 231 | float(configs.mm_width); |
| 232 | aidl_configuration.dpi = {.x = dpi, .y = dpi}; |
| 233 | } |
| 234 | // TODO: Populate vrrConfig. |
| 235 | return aidl_configuration; |
| 236 | } |
| 237 | |
Drew Davenport | 22d66b4 | 2024-09-24 15:34:57 -0600 | [diff] [blame] | 238 | std::optional<hwc_rect> AidlToRect(const std::optional<common::Rect>& rect) { |
| 239 | if (!rect) { |
| 240 | return std::nullopt; |
| 241 | } |
| 242 | return hwc_rect{rect->left, rect->top, rect->right, rect->bottom}; |
| 243 | } |
| 244 | |
Drew Davenport | 7ab8c18 | 2024-09-24 17:04:26 -0600 | [diff] [blame] | 245 | std::optional<hwc_frect> AidlToFRect(const std::optional<common::FRect>& rect) { |
| 246 | if (!rect) { |
| 247 | return std::nullopt; |
| 248 | } |
| 249 | return hwc_frect{rect->left, rect->top, rect->right, rect->bottom}; |
| 250 | } |
| 251 | |
Drew Davenport | 07b96f0 | 2024-09-24 15:37:12 -0600 | [diff] [blame] | 252 | std::optional<float> AidlToAlpha(const std::optional<PlaneAlpha>& alpha) { |
| 253 | if (!alpha) { |
| 254 | return std::nullopt; |
| 255 | } |
| 256 | return alpha->alpha; |
| 257 | } |
| 258 | |
Drew Davenport | 5d679b0 | 2024-09-25 10:15:58 -0600 | [diff] [blame] | 259 | std::optional<uint32_t> AidlToZOrder(const std::optional<ZOrder>& z_order) { |
| 260 | if (!z_order) { |
| 261 | return std::nullopt; |
| 262 | } |
| 263 | return z_order->z; |
| 264 | } |
| 265 | |
Drew Davenport | 51c61e4 | 2024-09-24 17:13:39 -0600 | [diff] [blame] | 266 | std::optional<LayerTransform> AidlToLayerTransform( |
| 267 | const std::optional<ParcelableTransform>& aidl_transform) { |
| 268 | if (!aidl_transform) { |
| 269 | return std::nullopt; |
| 270 | } |
| 271 | |
| 272 | uint32_t transform = LayerTransform::kIdentity; |
| 273 | // 270* and 180* cannot be combined with flips. More specifically, they |
| 274 | // already contain both horizontal and vertical flips, so those fields are |
| 275 | // redundant in this case. 90* rotation can be combined with either horizontal |
| 276 | // flip or vertical flip, so treat it differently |
| 277 | if (aidl_transform->transform == common::Transform::ROT_270) { |
| 278 | transform = LayerTransform::kRotate270; |
| 279 | } else if (aidl_transform->transform == common::Transform::ROT_180) { |
| 280 | transform = LayerTransform::kRotate180; |
| 281 | } else { |
| 282 | auto aidl_transform_bits = static_cast<uint32_t>(aidl_transform->transform); |
| 283 | if ((aidl_transform_bits & |
| 284 | static_cast<uint32_t>(common::Transform::FLIP_H)) != 0) |
| 285 | transform |= LayerTransform::kFlipH; |
| 286 | if ((aidl_transform_bits & |
| 287 | static_cast<uint32_t>(common::Transform::FLIP_V)) != 0) |
| 288 | transform |= LayerTransform::kFlipV; |
| 289 | if ((aidl_transform_bits & |
| 290 | static_cast<uint32_t>(common::Transform::ROT_90)) != 0) |
| 291 | transform |= LayerTransform::kRotate90; |
| 292 | } |
| 293 | return static_cast<LayerTransform>(transform); |
| 294 | } |
| 295 | |
Drew Davenport | 5951b11 | 2024-08-05 09:44:27 -0600 | [diff] [blame] | 296 | } // namespace |
| 297 | |
| 298 | ComposerClient::ComposerClient() { |
| 299 | DEBUG_FUNC(); |
| 300 | } |
| 301 | |
| 302 | bool ComposerClient::Init() { |
| 303 | DEBUG_FUNC(); |
| 304 | composer_resources_ = ComposerResources::Create(); |
| 305 | if (composer_resources_) { |
| 306 | hwc_ = std::make_unique<DrmHwcThree>(composer_resources_.get()); |
| 307 | } |
| 308 | return composer_resources_ != nullptr; |
| 309 | } |
| 310 | |
Dennis Tsiang | 33f0ece | 2023-11-29 12:45:04 +0000 | [diff] [blame] | 311 | ComposerClient::~ComposerClient() { |
| 312 | DEBUG_FUNC(); |
Drew Davenport | 1ac3b62 | 2024-09-05 10:59:16 -0600 | [diff] [blame] | 313 | { |
| 314 | // First Deinit the displays to start shutting down the Display's dependent |
| 315 | // threads such as VSyncWorker. |
| 316 | const std::unique_lock lock(hwc_->GetResMan().GetMainLock()); |
| 317 | hwc_->DeinitDisplays(); |
| 318 | } |
| 319 | // Sleep to wait for threads to complete and exit. |
| 320 | const int time_for_threads_to_exit_us = 200000; |
| 321 | usleep(time_for_threads_to_exit_us); |
| 322 | { |
| 323 | // Hold the lock while destructing the hwc_ and the objects that it owns. |
| 324 | const std::unique_lock lock(hwc_->GetResMan().GetMainLock()); |
| 325 | hwc_.reset(); |
| 326 | } |
Dennis Tsiang | 33f0ece | 2023-11-29 12:45:04 +0000 | [diff] [blame] | 327 | LOG(DEBUG) << "removed composer client"; |
| 328 | } |
| 329 | |
Drew Davenport | 5951b11 | 2024-08-05 09:44:27 -0600 | [diff] [blame] | 330 | ndk::ScopedAStatus ComposerClient::createLayer(int64_t display_id, |
| 331 | int32_t buffer_slot_count, |
| 332 | int64_t* layer_id) { |
Dennis Tsiang | 33f0ece | 2023-11-29 12:45:04 +0000 | [diff] [blame] | 333 | DEBUG_FUNC(); |
Drew Davenport | 5951b11 | 2024-08-05 09:44:27 -0600 | [diff] [blame] | 334 | const std::unique_lock lock(hwc_->GetResMan().GetMainLock()); |
| 335 | |
| 336 | HwcDisplay* display = GetDisplay(display_id); |
| 337 | if (display == nullptr) { |
| 338 | return ToBinderStatus(hwc3::Error::kBadDisplay); |
| 339 | } |
| 340 | |
| 341 | hwc2_layer_t hwc2_layer_id = 0; |
| 342 | auto err = Hwc2toHwc3Error(display->CreateLayer(&hwc2_layer_id)); |
| 343 | if (err != hwc3::Error::kNone) { |
| 344 | return ToBinderStatus(err); |
| 345 | } |
| 346 | |
| 347 | const int64_t created_layer_id = Hwc2LayerToHwc3(hwc2_layer_id); |
| 348 | err = composer_resources_->AddLayer(display_id, created_layer_id, |
| 349 | buffer_slot_count); |
| 350 | if (err != hwc3::Error::kNone) { |
| 351 | destroyLayer(display_id, created_layer_id); |
| 352 | return ToBinderStatus(err); |
| 353 | } |
| 354 | |
| 355 | *layer_id = created_layer_id; |
Dennis Tsiang | 33f0ece | 2023-11-29 12:45:04 +0000 | [diff] [blame] | 356 | return ndk::ScopedAStatus::ok(); |
| 357 | } |
| 358 | |
| 359 | ndk::ScopedAStatus ComposerClient::createVirtualDisplay( |
Drew Davenport | 5951b11 | 2024-08-05 09:44:27 -0600 | [diff] [blame] | 360 | int32_t width, int32_t height, AidlPixelFormat format_hint, |
| 361 | int32_t output_buffer_slot_count, VirtualDisplay* out_display) { |
Dennis Tsiang | 33f0ece | 2023-11-29 12:45:04 +0000 | [diff] [blame] | 362 | DEBUG_FUNC(); |
Drew Davenport | 5951b11 | 2024-08-05 09:44:27 -0600 | [diff] [blame] | 363 | const std::unique_lock lock(hwc_->GetResMan().GetMainLock()); |
| 364 | |
| 365 | hwc2_display_t hwc2_display_id = 0; |
| 366 | // TODO: Format is currently not used in drm_hwcomposer. |
| 367 | int32_t hwc2_format = 0; |
| 368 | auto err = Hwc2toHwc3Error(hwc_->CreateVirtualDisplay(width, height, |
| 369 | &hwc2_format, |
| 370 | &hwc2_display_id)); |
| 371 | if (err != hwc3::Error::kNone) { |
| 372 | return ToBinderStatus(err); |
| 373 | } |
| 374 | |
| 375 | const int64_t created_display_id = Hwc2DisplayToHwc3(hwc2_display_id); |
| 376 | err = composer_resources_->AddVirtualDisplay(hwc2_display_id, |
| 377 | output_buffer_slot_count); |
| 378 | if (err != hwc3::Error::kNone) { |
| 379 | hwc_->DestroyVirtualDisplay(hwc2_display_id); |
| 380 | return ToBinderStatus(err); |
| 381 | } |
| 382 | |
| 383 | out_display->display = created_display_id; |
| 384 | out_display->format = format_hint; |
Dennis Tsiang | 33f0ece | 2023-11-29 12:45:04 +0000 | [diff] [blame] | 385 | return ndk::ScopedAStatus::ok(); |
| 386 | } |
| 387 | |
Drew Davenport | 5951b11 | 2024-08-05 09:44:27 -0600 | [diff] [blame] | 388 | ndk::ScopedAStatus ComposerClient::destroyLayer(int64_t display_id, |
| 389 | int64_t layer_id) { |
Dennis Tsiang | 33f0ece | 2023-11-29 12:45:04 +0000 | [diff] [blame] | 390 | DEBUG_FUNC(); |
Drew Davenport | 5951b11 | 2024-08-05 09:44:27 -0600 | [diff] [blame] | 391 | const std::unique_lock lock(hwc_->GetResMan().GetMainLock()); |
| 392 | HwcDisplay* display = GetDisplay(display_id); |
| 393 | if (display == nullptr) { |
| 394 | return ToBinderStatus(hwc3::Error::kBadDisplay); |
| 395 | } |
| 396 | |
| 397 | auto err = Hwc2toHwc3Error(display->DestroyLayer(Hwc3LayerToHwc2(layer_id))); |
| 398 | if (err != hwc3::Error::kNone) { |
| 399 | return ToBinderStatus(err); |
| 400 | } |
| 401 | |
| 402 | err = composer_resources_->RemoveLayer(display_id, layer_id); |
| 403 | return ToBinderStatus(err); |
Dennis Tsiang | 33f0ece | 2023-11-29 12:45:04 +0000 | [diff] [blame] | 404 | } |
| 405 | |
Drew Davenport | 5951b11 | 2024-08-05 09:44:27 -0600 | [diff] [blame] | 406 | ndk::ScopedAStatus ComposerClient::destroyVirtualDisplay(int64_t display_id) { |
Dennis Tsiang | 33f0ece | 2023-11-29 12:45:04 +0000 | [diff] [blame] | 407 | DEBUG_FUNC(); |
Drew Davenport | 5951b11 | 2024-08-05 09:44:27 -0600 | [diff] [blame] | 408 | const std::unique_lock lock(hwc_->GetResMan().GetMainLock()); |
| 409 | auto err = Hwc2toHwc3Error(hwc_->DestroyVirtualDisplay(display_id)); |
| 410 | return ToBinderStatus(err); |
| 411 | } |
| 412 | |
| 413 | hwc3::Error ComposerClient::ValidateDisplayInternal( |
| 414 | HwcDisplay& display, std::vector<int64_t>* out_changed_layers, |
| 415 | std::vector<Composition>* out_composition_types, |
| 416 | int32_t* out_display_request_mask, |
| 417 | std::vector<int64_t>* out_requested_layers, |
| 418 | std::vector<int32_t>* out_request_masks, |
| 419 | ClientTargetProperty* /*out_client_target_property*/, |
| 420 | DimmingStage* /*out_dimming_stage*/) { |
| 421 | DEBUG_FUNC(); |
| 422 | |
| 423 | uint32_t num_types = 0; |
| 424 | uint32_t num_requests = 0; |
| 425 | const HWC2::Error hwc2_error = display.ValidateDisplay(&num_types, |
| 426 | &num_requests); |
| 427 | |
| 428 | /* Check if display has pending changes and no errors */ |
| 429 | if (hwc2_error != HWC2::Error::None && |
| 430 | hwc2_error != HWC2::Error::HasChanges) { |
| 431 | return Hwc2toHwc3Error(hwc2_error); |
| 432 | } |
| 433 | |
Drew Davenport | 3f4469f | 2024-10-03 10:01:51 -0600 | [diff] [blame] | 434 | hwc3::Error error = Hwc2toHwc3Error( |
| 435 | display.GetChangedCompositionTypes(&num_types, nullptr, nullptr)); |
| 436 | if (error != hwc3::Error::kNone) { |
| 437 | return error; |
| 438 | } |
| 439 | |
Drew Davenport | 5951b11 | 2024-08-05 09:44:27 -0600 | [diff] [blame] | 440 | std::vector<hwc2_layer_t> hwc_changed_layers(num_types); |
| 441 | std::vector<int32_t> hwc_composition_types(num_types); |
Drew Davenport | 3f4469f | 2024-10-03 10:01:51 -0600 | [diff] [blame] | 442 | error = Hwc2toHwc3Error( |
Drew Davenport | 5951b11 | 2024-08-05 09:44:27 -0600 | [diff] [blame] | 443 | display.GetChangedCompositionTypes(&num_types, hwc_changed_layers.data(), |
| 444 | hwc_composition_types.data())); |
| 445 | if (error != hwc3::Error::kNone) { |
| 446 | return error; |
| 447 | } |
| 448 | |
| 449 | int32_t display_reqs = 0; |
| 450 | out_request_masks->resize(num_requests); |
| 451 | std::vector<hwc2_layer_t> hwc_requested_layers(num_requests); |
| 452 | error = Hwc2toHwc3Error( |
| 453 | display.GetDisplayRequests(&display_reqs, &num_requests, |
| 454 | hwc_requested_layers.data(), |
| 455 | out_request_masks->data())); |
| 456 | if (error != hwc3::Error::kNone) { |
| 457 | return error; |
| 458 | } |
| 459 | |
| 460 | for (const auto& layer : hwc_changed_layers) { |
| 461 | out_changed_layers->emplace_back(Hwc2LayerToHwc3(layer)); |
| 462 | } |
| 463 | for (const auto& type : hwc_composition_types) { |
| 464 | out_composition_types->emplace_back(Hwc2CompositionTypeToHwc3(type)); |
| 465 | } |
| 466 | for (const auto& layer : hwc_requested_layers) { |
| 467 | out_requested_layers->emplace_back(Hwc2LayerToHwc3(layer)); |
| 468 | } |
| 469 | *out_display_request_mask = display_reqs; |
| 470 | |
| 471 | /* Client target property/dimming stage unsupported */ |
| 472 | return hwc3::Error::kNone; |
| 473 | } |
| 474 | |
| 475 | hwc3::Error ComposerClient::PresentDisplayInternal( |
| 476 | uint64_t display_id, ::android::base::unique_fd& out_display_fence, |
| 477 | std::unordered_map<int64_t, ::android::base::unique_fd>& |
| 478 | out_release_fences) { |
| 479 | DEBUG_FUNC(); |
| 480 | auto* display = GetDisplay(display_id); |
| 481 | if (display == nullptr) { |
| 482 | return hwc3::Error::kBadDisplay; |
| 483 | } |
| 484 | |
| 485 | if (composer_resources_->MustValidateDisplay(display_id)) { |
| 486 | return hwc3::Error::kNotValidated; |
| 487 | } |
| 488 | |
| 489 | int32_t present_fence = -1; |
| 490 | auto error = Hwc2toHwc3Error(display->PresentDisplay(&present_fence)); |
| 491 | if (error != hwc3::Error::kNone) { |
| 492 | return error; |
| 493 | } |
| 494 | out_display_fence.reset(present_fence); |
| 495 | |
| 496 | uint32_t release_fence_count = 0; |
| 497 | error = Hwc2toHwc3Error( |
| 498 | display->GetReleaseFences(&release_fence_count, nullptr, nullptr)); |
| 499 | if (error != hwc3::Error::kNone) { |
| 500 | return error; |
| 501 | } |
| 502 | |
| 503 | std::vector<hwc2_layer_t> hwc_layers(release_fence_count); |
| 504 | std::vector<int32_t> hwc_fences(release_fence_count); |
| 505 | error = Hwc2toHwc3Error(display->GetReleaseFences(&release_fence_count, |
| 506 | hwc_layers.data(), |
| 507 | hwc_fences.data())); |
| 508 | if (error != hwc3::Error::kNone) { |
| 509 | return error; |
| 510 | } |
| 511 | |
| 512 | for (size_t i = 0; i < hwc_layers.size(); i++) { |
| 513 | auto layer = Hwc2LayerToHwc3(hwc_layers[i]); |
| 514 | out_release_fences[layer] = ::android::base::unique_fd{hwc_fences[i]}; |
| 515 | } |
| 516 | |
| 517 | return hwc3::Error::kNone; |
| 518 | } |
| 519 | |
| 520 | ::android::HwcDisplay* ComposerClient::GetDisplay(uint64_t display_id) { |
| 521 | return hwc_->GetDisplay(display_id); |
| 522 | } |
| 523 | |
| 524 | void ComposerClient::DispatchLayerCommand(int64_t display_id, |
| 525 | const LayerCommand& command) { |
| 526 | auto* display = GetDisplay(display_id); |
| 527 | if (display == nullptr) { |
| 528 | cmd_result_writer_->AddError(hwc3::Error::kBadDisplay); |
| 529 | return; |
| 530 | } |
| 531 | |
| 532 | auto* layer = display->get_layer(command.layer); |
| 533 | if (layer == nullptr) { |
| 534 | cmd_result_writer_->AddError(hwc3::Error::kBadLayer); |
| 535 | return; |
| 536 | } |
| 537 | |
Drew Davenport | 1b0d8b7 | 2024-09-24 15:31:38 -0600 | [diff] [blame] | 538 | // If the requested composition type is not supported, the HWC should return |
| 539 | // an error and not process any further commands. |
| 540 | if (!IsSupportedCompositionType(command.composition)) { |
| 541 | cmd_result_writer_->AddError(hwc3::Error::kUnsupported); |
| 542 | return; |
| 543 | } |
| 544 | |
Drew Davenport | 9c6f7e5 | 2024-09-25 14:58:18 -0600 | [diff] [blame] | 545 | // For some invalid parameters, the HWC should return an error and not process |
| 546 | // any further commands. |
| 547 | if (!ValidateLayerBrightness(command.brightness)) { |
| 548 | cmd_result_writer_->AddError(hwc3::Error::kBadParameter); |
| 549 | return; |
| 550 | } |
| 551 | |
Drew Davenport | e5fbbbb | 2024-10-14 15:49:27 -0600 | [diff] [blame] | 552 | HwcLayer::LayerProperties properties; |
Drew Davenport | 5951b11 | 2024-08-05 09:44:27 -0600 | [diff] [blame] | 553 | if (command.buffer) { |
Drew Davenport | e5fbbbb | 2024-10-14 15:49:27 -0600 | [diff] [blame] | 554 | HwcLayer::Buffer buffer; |
| 555 | auto err = ImportLayerBuffer(display_id, command.layer, *command.buffer, |
| 556 | &buffer.buffer_handle); |
| 557 | if (err != hwc3::Error::kNone) { |
| 558 | cmd_result_writer_->AddError(err); |
| 559 | return; |
| 560 | } |
| 561 | buffer.acquire_fence = ::android::MakeSharedFd( |
| 562 | command.buffer->fence.dup().release()); |
| 563 | properties.buffer.emplace(buffer); |
Drew Davenport | 5951b11 | 2024-08-05 09:44:27 -0600 | [diff] [blame] | 564 | } |
Drew Davenport | 1b0d8b7 | 2024-09-24 15:31:38 -0600 | [diff] [blame] | 565 | |
Drew Davenport | a241a77 | 2024-09-24 11:26:30 -0600 | [diff] [blame] | 566 | properties.blend_mode = AidlToBlendMode(command.blendMode); |
Drew Davenport | ac9681e | 2024-09-24 12:17:34 -0600 | [diff] [blame] | 567 | properties.color_space = AidlToColorSpace(command.dataspace); |
| 568 | properties.sample_range = AidlToSampleRange(command.dataspace); |
Drew Davenport | 1b0d8b7 | 2024-09-24 15:31:38 -0600 | [diff] [blame] | 569 | properties.composition_type = AidlToCompositionType(command.composition); |
Drew Davenport | 22d66b4 | 2024-09-24 15:34:57 -0600 | [diff] [blame] | 570 | properties.display_frame = AidlToRect(command.displayFrame); |
Drew Davenport | 07b96f0 | 2024-09-24 15:37:12 -0600 | [diff] [blame] | 571 | properties.alpha = AidlToAlpha(command.planeAlpha); |
Drew Davenport | 7ab8c18 | 2024-09-24 17:04:26 -0600 | [diff] [blame] | 572 | properties.source_crop = AidlToFRect(command.sourceCrop); |
Drew Davenport | 51c61e4 | 2024-09-24 17:13:39 -0600 | [diff] [blame] | 573 | properties.transform = AidlToLayerTransform(command.transform); |
Drew Davenport | 5d679b0 | 2024-09-25 10:15:58 -0600 | [diff] [blame] | 574 | properties.z_order = AidlToZOrder(command.z); |
Drew Davenport | 7ab8c18 | 2024-09-24 17:04:26 -0600 | [diff] [blame] | 575 | |
Drew Davenport | a241a77 | 2024-09-24 11:26:30 -0600 | [diff] [blame] | 576 | layer->SetLayerProperties(properties); |
| 577 | |
Drew Davenport | 5951b11 | 2024-08-05 09:44:27 -0600 | [diff] [blame] | 578 | // Some unsupported functionality returns kUnsupported, and others |
| 579 | // are just a no-op. |
| 580 | // TODO: Audit whether some of these should actually return kUnsupported |
| 581 | // instead. |
| 582 | if (command.sidebandStream) { |
| 583 | cmd_result_writer_->AddError(hwc3::Error::kUnsupported); |
| 584 | } |
| 585 | // TODO: Blocking region handling missing. |
| 586 | // TODO: Layer surface damage. |
| 587 | // TODO: Layer visible region. |
| 588 | // TODO: Per-frame metadata. |
| 589 | // TODO: Layer color transform. |
| 590 | // TODO: Layer cursor position. |
| 591 | // TODO: Layer color. |
| 592 | } |
| 593 | |
| 594 | void ComposerClient::ExecuteDisplayCommand(const DisplayCommand& command) { |
| 595 | const int64_t display_id = command.display; |
| 596 | if (hwc_->GetDisplay(display_id) == nullptr) { |
| 597 | cmd_result_writer_->AddError(hwc3::Error::kBadDisplay); |
| 598 | return; |
| 599 | } |
| 600 | |
| 601 | for (const auto& layer_cmd : command.layers) { |
| 602 | DispatchLayerCommand(command.display, layer_cmd); |
| 603 | } |
| 604 | |
Drew Davenport | 8891e91 | 2024-10-15 15:05:45 -0600 | [diff] [blame] | 605 | // TODO: Implement support for display brightness. |
Drew Davenport | 5951b11 | 2024-08-05 09:44:27 -0600 | [diff] [blame] | 606 | if (command.colorTransformMatrix) { |
| 607 | ExecuteSetDisplayColorTransform(command.display, |
| 608 | *command.colorTransformMatrix); |
| 609 | } |
| 610 | if (command.clientTarget) { |
| 611 | ExecuteSetDisplayClientTarget(command.display, *command.clientTarget); |
| 612 | } |
| 613 | if (command.virtualDisplayOutputBuffer) { |
| 614 | ExecuteSetDisplayOutputBuffer(command.display, |
| 615 | *command.virtualDisplayOutputBuffer); |
| 616 | } |
| 617 | if (command.validateDisplay) { |
| 618 | ExecuteValidateDisplay(command.display, command.expectedPresentTime); |
| 619 | } |
| 620 | if (command.acceptDisplayChanges) { |
| 621 | ExecuteAcceptDisplayChanges(command.display); |
| 622 | } |
| 623 | if (command.presentDisplay) { |
| 624 | ExecutePresentDisplay(command.display); |
| 625 | } |
| 626 | if (command.presentOrValidateDisplay) { |
| 627 | ExecutePresentOrValidateDisplay(command.display, |
| 628 | command.expectedPresentTime); |
| 629 | } |
Dennis Tsiang | 33f0ece | 2023-11-29 12:45:04 +0000 | [diff] [blame] | 630 | } |
| 631 | |
| 632 | ndk::ScopedAStatus ComposerClient::executeCommands( |
Drew Davenport | 5951b11 | 2024-08-05 09:44:27 -0600 | [diff] [blame] | 633 | const std::vector<DisplayCommand>& commands, |
| 634 | std::vector<CommandResultPayload>* results) { |
Drew Davenport | 4996585 | 2024-09-05 10:59:40 -0600 | [diff] [blame] | 635 | const std::unique_lock lock(hwc_->GetResMan().GetMainLock()); |
| 636 | DEBUG_FUNC(); |
Drew Davenport | 5951b11 | 2024-08-05 09:44:27 -0600 | [diff] [blame] | 637 | cmd_result_writer_ = std::make_unique<CommandResultWriter>(results); |
| 638 | for (const auto& cmd : commands) { |
| 639 | ExecuteDisplayCommand(cmd); |
| 640 | cmd_result_writer_->IncrementCommand(); |
| 641 | } |
| 642 | cmd_result_writer_.reset(); |
| 643 | |
Dennis Tsiang | 33f0ece | 2023-11-29 12:45:04 +0000 | [diff] [blame] | 644 | return ndk::ScopedAStatus::ok(); |
| 645 | } |
| 646 | |
Drew Davenport | 5951b11 | 2024-08-05 09:44:27 -0600 | [diff] [blame] | 647 | ndk::ScopedAStatus ComposerClient::getActiveConfig(int64_t display_id, |
| 648 | int32_t* config) { |
Dennis Tsiang | 33f0ece | 2023-11-29 12:45:04 +0000 | [diff] [blame] | 649 | DEBUG_FUNC(); |
Drew Davenport | 5951b11 | 2024-08-05 09:44:27 -0600 | [diff] [blame] | 650 | const std::unique_lock lock(hwc_->GetResMan().GetMainLock()); |
| 651 | HwcDisplay* display = GetDisplay(display_id); |
| 652 | if (display == nullptr) { |
| 653 | return ToBinderStatus(hwc3::Error::kBadDisplay); |
| 654 | } |
| 655 | |
| 656 | uint32_t hwc2_config = 0; |
| 657 | const hwc3::Error error = Hwc2toHwc3Error( |
| 658 | display->GetActiveConfig(&hwc2_config)); |
| 659 | if (error != hwc3::Error::kNone) { |
| 660 | return ToBinderStatus(error); |
| 661 | } |
| 662 | *config = Hwc2ConfigIdToHwc3(hwc2_config); |
Dennis Tsiang | 33f0ece | 2023-11-29 12:45:04 +0000 | [diff] [blame] | 663 | return ndk::ScopedAStatus::ok(); |
| 664 | } |
| 665 | |
| 666 | ndk::ScopedAStatus ComposerClient::getColorModes( |
Drew Davenport | 5951b11 | 2024-08-05 09:44:27 -0600 | [diff] [blame] | 667 | int64_t display_id, std::vector<ColorMode>* color_modes) { |
Dennis Tsiang | 33f0ece | 2023-11-29 12:45:04 +0000 | [diff] [blame] | 668 | DEBUG_FUNC(); |
Drew Davenport | 5951b11 | 2024-08-05 09:44:27 -0600 | [diff] [blame] | 669 | const std::unique_lock lock(hwc_->GetResMan().GetMainLock()); |
| 670 | HwcDisplay* display = GetDisplay(display_id); |
| 671 | if (display == nullptr) { |
| 672 | return ToBinderStatus(hwc3::Error::kBadDisplay); |
| 673 | } |
| 674 | |
| 675 | uint32_t num_modes = 0; |
| 676 | auto error = Hwc2toHwc3Error(display->GetColorModes(&num_modes, nullptr)); |
| 677 | if (error != hwc3::Error::kNone) { |
| 678 | return ToBinderStatus(error); |
| 679 | } |
| 680 | |
| 681 | std::vector<int32_t> hwc2_color_modes(num_modes); |
| 682 | error = Hwc2toHwc3Error( |
| 683 | display->GetColorModes(&num_modes, hwc2_color_modes.data())); |
| 684 | if (error != hwc3::Error::kNone) { |
| 685 | return ToBinderStatus(error); |
| 686 | } |
| 687 | |
| 688 | for (const auto& mode : hwc2_color_modes) { |
| 689 | color_modes->push_back(Hwc2ColorModeToHwc3(mode)); |
| 690 | } |
| 691 | |
Dennis Tsiang | 33f0ece | 2023-11-29 12:45:04 +0000 | [diff] [blame] | 692 | return ndk::ScopedAStatus::ok(); |
| 693 | } |
| 694 | |
| 695 | ndk::ScopedAStatus ComposerClient::getDataspaceSaturationMatrix( |
Drew Davenport | 5951b11 | 2024-08-05 09:44:27 -0600 | [diff] [blame] | 696 | common::Dataspace dataspace, std::vector<float>* matrix) { |
Dennis Tsiang | 33f0ece | 2023-11-29 12:45:04 +0000 | [diff] [blame] | 697 | DEBUG_FUNC(); |
Drew Davenport | 5951b11 | 2024-08-05 09:44:27 -0600 | [diff] [blame] | 698 | if (dataspace != common::Dataspace::SRGB_LINEAR) { |
| 699 | return ToBinderStatus(hwc3::Error::kBadParameter); |
| 700 | } |
| 701 | |
| 702 | matrix->clear(); |
| 703 | matrix->insert(matrix->begin(), kIdentityMatrix.begin(), |
| 704 | kIdentityMatrix.end()); |
| 705 | |
Dennis Tsiang | 33f0ece | 2023-11-29 12:45:04 +0000 | [diff] [blame] | 706 | return ndk::ScopedAStatus::ok(); |
| 707 | } |
| 708 | |
| 709 | ndk::ScopedAStatus ComposerClient::getDisplayAttribute( |
Drew Davenport | 1afb579 | 2024-09-24 12:53:22 -0600 | [diff] [blame] | 710 | int64_t display_id, int32_t config_id, DisplayAttribute attribute, |
Drew Davenport | 5951b11 | 2024-08-05 09:44:27 -0600 | [diff] [blame] | 711 | int32_t* value) { |
Dennis Tsiang | 33f0ece | 2023-11-29 12:45:04 +0000 | [diff] [blame] | 712 | DEBUG_FUNC(); |
Drew Davenport | 5951b11 | 2024-08-05 09:44:27 -0600 | [diff] [blame] | 713 | const std::unique_lock lock(hwc_->GetResMan().GetMainLock()); |
| 714 | HwcDisplay* display = GetDisplay(display_id); |
| 715 | if (display == nullptr) { |
| 716 | return ToBinderStatus(hwc3::Error::kBadDisplay); |
| 717 | } |
| 718 | |
Drew Davenport | 1afb579 | 2024-09-24 12:53:22 -0600 | [diff] [blame] | 719 | const HwcDisplayConfigs& configs = display->GetDisplayConfigs(); |
| 720 | auto config = configs.hwc_configs.find(config_id); |
| 721 | if (config == configs.hwc_configs.end()) { |
| 722 | return ToBinderStatus(hwc3::Error::kBadConfig); |
| 723 | } |
| 724 | |
| 725 | DisplayConfiguration |
| 726 | aidl_configuration = HwcDisplayConfigToAidlConfiguration(configs, |
| 727 | config->second); |
| 728 | // Legacy API for querying DPI uses units of dots per 1000 inches. |
| 729 | static const int kLegacyDpiUnit = 1000; |
| 730 | switch (attribute) { |
| 731 | case DisplayAttribute::WIDTH: |
| 732 | *value = aidl_configuration.width; |
| 733 | break; |
| 734 | case DisplayAttribute::HEIGHT: |
| 735 | *value = aidl_configuration.height; |
| 736 | break; |
| 737 | case DisplayAttribute::VSYNC_PERIOD: |
| 738 | *value = aidl_configuration.vsyncPeriod; |
| 739 | break; |
| 740 | case DisplayAttribute::DPI_X: |
| 741 | *value = aidl_configuration.dpi |
| 742 | ? static_cast<int>(aidl_configuration.dpi->x * |
| 743 | kLegacyDpiUnit) |
| 744 | : -1; |
| 745 | break; |
| 746 | case DisplayAttribute::DPI_Y: |
| 747 | *value = aidl_configuration.dpi |
| 748 | ? static_cast<int>(aidl_configuration.dpi->y * |
| 749 | kLegacyDpiUnit) |
| 750 | : -1; |
| 751 | break; |
| 752 | case DisplayAttribute::CONFIG_GROUP: |
| 753 | *value = aidl_configuration.configGroup; |
| 754 | break; |
| 755 | case DisplayAttribute::INVALID: |
| 756 | return ToBinderStatus(hwc3::Error::kUnsupported); |
| 757 | } |
| 758 | return ndk::ScopedAStatus::ok(); |
Dennis Tsiang | 33f0ece | 2023-11-29 12:45:04 +0000 | [diff] [blame] | 759 | } |
| 760 | |
| 761 | ndk::ScopedAStatus ComposerClient::getDisplayCapabilities( |
Drew Davenport | 5951b11 | 2024-08-05 09:44:27 -0600 | [diff] [blame] | 762 | int64_t display_id, std::vector<DisplayCapability>* caps) { |
Dennis Tsiang | 33f0ece | 2023-11-29 12:45:04 +0000 | [diff] [blame] | 763 | DEBUG_FUNC(); |
Drew Davenport | 5951b11 | 2024-08-05 09:44:27 -0600 | [diff] [blame] | 764 | const std::unique_lock lock(hwc_->GetResMan().GetMainLock()); |
| 765 | HwcDisplay* display = GetDisplay(display_id); |
| 766 | if (display == nullptr) { |
| 767 | return ToBinderStatus(hwc3::Error::kBadDisplay); |
| 768 | } |
Dennis Tsiang | 33f0ece | 2023-11-29 12:45:04 +0000 | [diff] [blame] | 769 | |
Drew Davenport | 5951b11 | 2024-08-05 09:44:27 -0600 | [diff] [blame] | 770 | uint32_t num_capabilities = 0; |
| 771 | hwc3::Error error = Hwc2toHwc3Error( |
| 772 | display->GetDisplayCapabilities(&num_capabilities, nullptr)); |
| 773 | if (error != hwc3::Error::kNone) { |
| 774 | return ToBinderStatus(error); |
| 775 | } |
| 776 | |
| 777 | std::vector<uint32_t> out_caps(num_capabilities); |
| 778 | error = Hwc2toHwc3Error( |
| 779 | display->GetDisplayCapabilities(&num_capabilities, out_caps.data())); |
| 780 | if (error != hwc3::Error::kNone) { |
| 781 | return ToBinderStatus(error); |
| 782 | } |
| 783 | |
| 784 | caps->reserve(num_capabilities); |
| 785 | for (const auto cap : out_caps) { |
| 786 | caps->emplace_back(Hwc2DisplayCapabilityToHwc3(cap)); |
| 787 | } |
Dennis Tsiang | 33f0ece | 2023-11-29 12:45:04 +0000 | [diff] [blame] | 788 | return ndk::ScopedAStatus::ok(); |
| 789 | } |
| 790 | |
| 791 | ndk::ScopedAStatus ComposerClient::getDisplayConfigs( |
Drew Davenport | 1afb579 | 2024-09-24 12:53:22 -0600 | [diff] [blame] | 792 | int64_t display_id, std::vector<int32_t>* out_configs) { |
Dennis Tsiang | 33f0ece | 2023-11-29 12:45:04 +0000 | [diff] [blame] | 793 | DEBUG_FUNC(); |
Drew Davenport | 5951b11 | 2024-08-05 09:44:27 -0600 | [diff] [blame] | 794 | const std::unique_lock lock(hwc_->GetResMan().GetMainLock()); |
| 795 | HwcDisplay* display = GetDisplay(display_id); |
| 796 | if (display == nullptr) { |
| 797 | return ToBinderStatus(hwc3::Error::kBadDisplay); |
| 798 | } |
| 799 | |
Drew Davenport | 1afb579 | 2024-09-24 12:53:22 -0600 | [diff] [blame] | 800 | const HwcDisplayConfigs& configs = display->GetDisplayConfigs(); |
| 801 | for (const auto& [id, config] : configs.hwc_configs) { |
| 802 | out_configs->push_back(static_cast<int32_t>(id)); |
Drew Davenport | 5951b11 | 2024-08-05 09:44:27 -0600 | [diff] [blame] | 803 | } |
Dennis Tsiang | 33f0ece | 2023-11-29 12:45:04 +0000 | [diff] [blame] | 804 | return ndk::ScopedAStatus::ok(); |
| 805 | } |
| 806 | |
| 807 | ndk::ScopedAStatus ComposerClient::getDisplayConnectionType( |
Drew Davenport | 5951b11 | 2024-08-05 09:44:27 -0600 | [diff] [blame] | 808 | int64_t display_id, DisplayConnectionType* type) { |
Dennis Tsiang | 33f0ece | 2023-11-29 12:45:04 +0000 | [diff] [blame] | 809 | DEBUG_FUNC(); |
Drew Davenport | 5951b11 | 2024-08-05 09:44:27 -0600 | [diff] [blame] | 810 | const std::unique_lock lock(hwc_->GetResMan().GetMainLock()); |
| 811 | HwcDisplay* display = GetDisplay(display_id); |
| 812 | if (display == nullptr) { |
| 813 | return ToBinderStatus(hwc3::Error::kBadDisplay); |
| 814 | } |
| 815 | |
| 816 | uint32_t out_type = 0; |
| 817 | const hwc3::Error error = Hwc2toHwc3Error( |
| 818 | display->GetDisplayConnectionType(&out_type)); |
| 819 | if (error != hwc3::Error::kNone) { |
| 820 | return ToBinderStatus(error); |
| 821 | } |
| 822 | |
| 823 | *type = Hwc2DisplayConnectionTypeToHwc3(out_type); |
Dennis Tsiang | 33f0ece | 2023-11-29 12:45:04 +0000 | [diff] [blame] | 824 | return ndk::ScopedAStatus::ok(); |
| 825 | } |
| 826 | |
| 827 | ndk::ScopedAStatus ComposerClient::getDisplayIdentificationData( |
Drew Davenport | 5951b11 | 2024-08-05 09:44:27 -0600 | [diff] [blame] | 828 | int64_t display_id, DisplayIdentification* id) { |
Dennis Tsiang | 33f0ece | 2023-11-29 12:45:04 +0000 | [diff] [blame] | 829 | DEBUG_FUNC(); |
Drew Davenport | 5951b11 | 2024-08-05 09:44:27 -0600 | [diff] [blame] | 830 | const std::unique_lock lock(hwc_->GetResMan().GetMainLock()); |
| 831 | HwcDisplay* display = GetDisplay(display_id); |
| 832 | if (display == nullptr) { |
| 833 | return ToBinderStatus(hwc3::Error::kBadDisplay); |
| 834 | } |
| 835 | |
| 836 | uint8_t port = 0; |
| 837 | uint32_t data_size = 0; |
| 838 | hwc3::Error error = Hwc2toHwc3Error( |
| 839 | display->GetDisplayIdentificationData(&port, &data_size, nullptr)); |
| 840 | if (error != hwc3::Error::kNone) { |
| 841 | return ToBinderStatus(error); |
| 842 | } |
| 843 | |
| 844 | id->data.resize(data_size); |
| 845 | error = Hwc2toHwc3Error( |
| 846 | display->GetDisplayIdentificationData(&port, &data_size, |
| 847 | id->data.data())); |
| 848 | if (error != hwc3::Error::kNone) { |
| 849 | return ToBinderStatus(error); |
| 850 | } |
| 851 | |
| 852 | id->port = static_cast<int8_t>(port); |
Dennis Tsiang | 33f0ece | 2023-11-29 12:45:04 +0000 | [diff] [blame] | 853 | return ndk::ScopedAStatus::ok(); |
| 854 | } |
| 855 | |
Drew Davenport | 5951b11 | 2024-08-05 09:44:27 -0600 | [diff] [blame] | 856 | ndk::ScopedAStatus ComposerClient::getDisplayName(int64_t display_id, |
| 857 | std::string* name) { |
Dennis Tsiang | 33f0ece | 2023-11-29 12:45:04 +0000 | [diff] [blame] | 858 | DEBUG_FUNC(); |
Drew Davenport | 5951b11 | 2024-08-05 09:44:27 -0600 | [diff] [blame] | 859 | const std::unique_lock lock(hwc_->GetResMan().GetMainLock()); |
| 860 | HwcDisplay* display = GetDisplay(display_id); |
| 861 | if (display == nullptr) { |
| 862 | return ToBinderStatus(hwc3::Error::kBadDisplay); |
| 863 | } |
| 864 | |
| 865 | uint32_t size = 0; |
| 866 | auto error = Hwc2toHwc3Error(display->GetDisplayName(&size, nullptr)); |
| 867 | if (error != hwc3::Error::kNone) { |
| 868 | return ToBinderStatus(error); |
| 869 | } |
| 870 | |
| 871 | name->resize(size); |
| 872 | error = Hwc2toHwc3Error(display->GetDisplayName(&size, name->data())); |
| 873 | return ToBinderStatus(error); |
Dennis Tsiang | 33f0ece | 2023-11-29 12:45:04 +0000 | [diff] [blame] | 874 | } |
| 875 | |
| 876 | ndk::ScopedAStatus ComposerClient::getDisplayVsyncPeriod( |
Drew Davenport | 5951b11 | 2024-08-05 09:44:27 -0600 | [diff] [blame] | 877 | int64_t display_id, int32_t* vsync_period) { |
Dennis Tsiang | 33f0ece | 2023-11-29 12:45:04 +0000 | [diff] [blame] | 878 | DEBUG_FUNC(); |
Drew Davenport | 5951b11 | 2024-08-05 09:44:27 -0600 | [diff] [blame] | 879 | const std::unique_lock lock(hwc_->GetResMan().GetMainLock()); |
| 880 | HwcDisplay* display = GetDisplay(display_id); |
| 881 | if (display == nullptr) { |
| 882 | return ToBinderStatus(hwc3::Error::kBadDisplay); |
| 883 | } |
| 884 | |
| 885 | uint32_t hwc2_vsync_period = 0; |
| 886 | auto error = Hwc2toHwc3Error( |
| 887 | display->GetDisplayVsyncPeriod(&hwc2_vsync_period)); |
| 888 | if (error != hwc3::Error::kNone) { |
| 889 | return ToBinderStatus(error); |
| 890 | } |
| 891 | |
| 892 | *vsync_period = static_cast<int32_t>(hwc2_vsync_period); |
Dennis Tsiang | 33f0ece | 2023-11-29 12:45:04 +0000 | [diff] [blame] | 893 | return ndk::ScopedAStatus::ok(); |
| 894 | } |
| 895 | |
| 896 | ndk::ScopedAStatus ComposerClient::getDisplayedContentSample( |
Drew Davenport | 5951b11 | 2024-08-05 09:44:27 -0600 | [diff] [blame] | 897 | int64_t /*display_id*/, int64_t /*max_frames*/, int64_t /*timestamp*/, |
Dennis Tsiang | 33f0ece | 2023-11-29 12:45:04 +0000 | [diff] [blame] | 898 | DisplayContentSample* /*samples*/) { |
| 899 | DEBUG_FUNC(); |
Drew Davenport | 5951b11 | 2024-08-05 09:44:27 -0600 | [diff] [blame] | 900 | return ToBinderStatus(hwc3::Error::kUnsupported); |
Dennis Tsiang | 33f0ece | 2023-11-29 12:45:04 +0000 | [diff] [blame] | 901 | } |
| 902 | |
| 903 | ndk::ScopedAStatus ComposerClient::getDisplayedContentSamplingAttributes( |
Drew Davenport | 5951b11 | 2024-08-05 09:44:27 -0600 | [diff] [blame] | 904 | int64_t /*display_id*/, DisplayContentSamplingAttributes* /*attrs*/) { |
Dennis Tsiang | 33f0ece | 2023-11-29 12:45:04 +0000 | [diff] [blame] | 905 | DEBUG_FUNC(); |
Drew Davenport | 5951b11 | 2024-08-05 09:44:27 -0600 | [diff] [blame] | 906 | return ToBinderStatus(hwc3::Error::kUnsupported); |
Dennis Tsiang | 33f0ece | 2023-11-29 12:45:04 +0000 | [diff] [blame] | 907 | } |
| 908 | |
| 909 | ndk::ScopedAStatus ComposerClient::getDisplayPhysicalOrientation( |
Drew Davenport | 5951b11 | 2024-08-05 09:44:27 -0600 | [diff] [blame] | 910 | int64_t display_id, common::Transform* orientation) { |
Dennis Tsiang | 33f0ece | 2023-11-29 12:45:04 +0000 | [diff] [blame] | 911 | DEBUG_FUNC(); |
Drew Davenport | 5951b11 | 2024-08-05 09:44:27 -0600 | [diff] [blame] | 912 | const std::unique_lock lock(hwc_->GetResMan().GetMainLock()); |
| 913 | HwcDisplay* display = GetDisplay(display_id); |
| 914 | if (display == nullptr) { |
| 915 | return ToBinderStatus(hwc3::Error::kBadDisplay); |
| 916 | } |
| 917 | |
| 918 | *orientation = common::Transform::NONE; |
Dennis Tsiang | 33f0ece | 2023-11-29 12:45:04 +0000 | [diff] [blame] | 919 | return ndk::ScopedAStatus::ok(); |
| 920 | } |
| 921 | |
Drew Davenport | 5951b11 | 2024-08-05 09:44:27 -0600 | [diff] [blame] | 922 | ndk::ScopedAStatus ComposerClient::getHdrCapabilities(int64_t display_id, |
| 923 | HdrCapabilities* caps) { |
Dennis Tsiang | 33f0ece | 2023-11-29 12:45:04 +0000 | [diff] [blame] | 924 | DEBUG_FUNC(); |
Drew Davenport | 5951b11 | 2024-08-05 09:44:27 -0600 | [diff] [blame] | 925 | const std::unique_lock lock(hwc_->GetResMan().GetMainLock()); |
| 926 | HwcDisplay* display = GetDisplay(display_id); |
| 927 | if (display == nullptr) { |
| 928 | return ToBinderStatus(hwc3::Error::kBadDisplay); |
| 929 | } |
| 930 | |
| 931 | /* No HDR capabilities */ |
| 932 | caps->types.clear(); |
Dennis Tsiang | 33f0ece | 2023-11-29 12:45:04 +0000 | [diff] [blame] | 933 | return ndk::ScopedAStatus::ok(); |
| 934 | } |
| 935 | |
Drew Davenport | 5951b11 | 2024-08-05 09:44:27 -0600 | [diff] [blame] | 936 | ndk::ScopedAStatus ComposerClient::getMaxVirtualDisplayCount(int32_t* count) { |
Dennis Tsiang | 33f0ece | 2023-11-29 12:45:04 +0000 | [diff] [blame] | 937 | DEBUG_FUNC(); |
Drew Davenport | 5951b11 | 2024-08-05 09:44:27 -0600 | [diff] [blame] | 938 | const std::unique_lock lock(hwc_->GetResMan().GetMainLock()); |
| 939 | *count = static_cast<int32_t>(hwc_->GetMaxVirtualDisplayCount()); |
Dennis Tsiang | 33f0ece | 2023-11-29 12:45:04 +0000 | [diff] [blame] | 940 | return ndk::ScopedAStatus::ok(); |
| 941 | } |
| 942 | |
| 943 | ndk::ScopedAStatus ComposerClient::getPerFrameMetadataKeys( |
Drew Davenport | 5951b11 | 2024-08-05 09:44:27 -0600 | [diff] [blame] | 944 | int64_t /*display_id*/, std::vector<PerFrameMetadataKey>* /*keys*/) { |
Dennis Tsiang | 33f0ece | 2023-11-29 12:45:04 +0000 | [diff] [blame] | 945 | DEBUG_FUNC(); |
Drew Davenport | 5951b11 | 2024-08-05 09:44:27 -0600 | [diff] [blame] | 946 | return ToBinderStatus(hwc3::Error::kUnsupported); |
Dennis Tsiang | 33f0ece | 2023-11-29 12:45:04 +0000 | [diff] [blame] | 947 | } |
| 948 | |
| 949 | ndk::ScopedAStatus ComposerClient::getReadbackBufferAttributes( |
Drew Davenport | 5951b11 | 2024-08-05 09:44:27 -0600 | [diff] [blame] | 950 | int64_t /*display_id*/, ReadbackBufferAttributes* /*attrs*/) { |
Dennis Tsiang | 33f0ece | 2023-11-29 12:45:04 +0000 | [diff] [blame] | 951 | DEBUG_FUNC(); |
Drew Davenport | 5951b11 | 2024-08-05 09:44:27 -0600 | [diff] [blame] | 952 | return ToBinderStatus(hwc3::Error::kUnsupported); |
Dennis Tsiang | 33f0ece | 2023-11-29 12:45:04 +0000 | [diff] [blame] | 953 | } |
| 954 | |
| 955 | ndk::ScopedAStatus ComposerClient::getReadbackBufferFence( |
Drew Davenport | 5951b11 | 2024-08-05 09:44:27 -0600 | [diff] [blame] | 956 | int64_t /*display_id*/, ndk::ScopedFileDescriptor* /*acquireFence*/) { |
Dennis Tsiang | 33f0ece | 2023-11-29 12:45:04 +0000 | [diff] [blame] | 957 | DEBUG_FUNC(); |
Drew Davenport | 5951b11 | 2024-08-05 09:44:27 -0600 | [diff] [blame] | 958 | return ToBinderStatus(hwc3::Error::kUnsupported); |
Dennis Tsiang | 33f0ece | 2023-11-29 12:45:04 +0000 | [diff] [blame] | 959 | } |
| 960 | |
| 961 | ndk::ScopedAStatus ComposerClient::getRenderIntents( |
Drew Davenport | 5951b11 | 2024-08-05 09:44:27 -0600 | [diff] [blame] | 962 | int64_t display_id, ColorMode mode, std::vector<RenderIntent>* intents) { |
Dennis Tsiang | 33f0ece | 2023-11-29 12:45:04 +0000 | [diff] [blame] | 963 | DEBUG_FUNC(); |
Drew Davenport | 5951b11 | 2024-08-05 09:44:27 -0600 | [diff] [blame] | 964 | const std::unique_lock lock(hwc_->GetResMan().GetMainLock()); |
| 965 | HwcDisplay* display = GetDisplay(display_id); |
| 966 | if (display == nullptr) { |
| 967 | return ToBinderStatus(hwc3::Error::kBadDisplay); |
| 968 | } |
| 969 | |
| 970 | const int32_t hwc2_color_mode = Hwc3ColorModeToHwc2(mode); |
| 971 | uint32_t out_num_intents = 0; |
| 972 | auto error = Hwc2toHwc3Error( |
| 973 | display->GetRenderIntents(hwc2_color_mode, &out_num_intents, nullptr)); |
| 974 | if (error != hwc3::Error::kNone) { |
| 975 | return ToBinderStatus(error); |
| 976 | } |
| 977 | |
| 978 | std::vector<int32_t> out_intents(out_num_intents); |
| 979 | error = Hwc2toHwc3Error(display->GetRenderIntents(hwc2_color_mode, |
| 980 | &out_num_intents, |
| 981 | out_intents.data())); |
| 982 | if (error != hwc3::Error::kNone) { |
| 983 | return ToBinderStatus(error); |
| 984 | } |
| 985 | |
| 986 | intents->reserve(out_num_intents); |
| 987 | for (const auto intent : out_intents) { |
| 988 | intents->emplace_back(Hwc2RenderIntentToHwc3(intent)); |
| 989 | } |
Dennis Tsiang | 33f0ece | 2023-11-29 12:45:04 +0000 | [diff] [blame] | 990 | return ndk::ScopedAStatus::ok(); |
| 991 | } |
| 992 | |
| 993 | ndk::ScopedAStatus ComposerClient::getSupportedContentTypes( |
Drew Davenport | 5951b11 | 2024-08-05 09:44:27 -0600 | [diff] [blame] | 994 | int64_t display_id, std::vector<ContentType>* types) { |
Dennis Tsiang | 33f0ece | 2023-11-29 12:45:04 +0000 | [diff] [blame] | 995 | DEBUG_FUNC(); |
Drew Davenport | 5951b11 | 2024-08-05 09:44:27 -0600 | [diff] [blame] | 996 | const std::unique_lock lock(hwc_->GetResMan().GetMainLock()); |
| 997 | HwcDisplay* display = GetDisplay(display_id); |
| 998 | if (display == nullptr) { |
| 999 | return ToBinderStatus(hwc3::Error::kBadDisplay); |
| 1000 | } |
| 1001 | |
Drew Davenport | 8d38dc7 | 2024-09-24 12:26:07 -0600 | [diff] [blame] | 1002 | // Support for ContentType is not implemented. |
| 1003 | types->clear(); |
Dennis Tsiang | 33f0ece | 2023-11-29 12:45:04 +0000 | [diff] [blame] | 1004 | return ndk::ScopedAStatus::ok(); |
| 1005 | } |
| 1006 | |
| 1007 | ndk::ScopedAStatus ComposerClient::getDisplayDecorationSupport( |
Drew Davenport | 5951b11 | 2024-08-05 09:44:27 -0600 | [diff] [blame] | 1008 | int64_t /*display_id*/, |
| 1009 | std::optional<common::DisplayDecorationSupport>* /*support_struct*/) { |
Dennis Tsiang | 33f0ece | 2023-11-29 12:45:04 +0000 | [diff] [blame] | 1010 | DEBUG_FUNC(); |
Drew Davenport | 5951b11 | 2024-08-05 09:44:27 -0600 | [diff] [blame] | 1011 | return ToBinderStatus(hwc3::Error::kUnsupported); |
Dennis Tsiang | 33f0ece | 2023-11-29 12:45:04 +0000 | [diff] [blame] | 1012 | } |
| 1013 | |
| 1014 | ndk::ScopedAStatus ComposerClient::registerCallback( |
Drew Davenport | 5951b11 | 2024-08-05 09:44:27 -0600 | [diff] [blame] | 1015 | const std::shared_ptr<IComposerCallback>& callback) { |
Dennis Tsiang | 33f0ece | 2023-11-29 12:45:04 +0000 | [diff] [blame] | 1016 | DEBUG_FUNC(); |
Drew Davenport | 5951b11 | 2024-08-05 09:44:27 -0600 | [diff] [blame] | 1017 | const std::unique_lock lock(hwc_->GetResMan().GetMainLock()); |
| 1018 | // This function is specified to be called exactly once. |
| 1019 | hwc_->Init(callback); |
Dennis Tsiang | 33f0ece | 2023-11-29 12:45:04 +0000 | [diff] [blame] | 1020 | return ndk::ScopedAStatus::ok(); |
| 1021 | } |
| 1022 | |
Drew Davenport | 5951b11 | 2024-08-05 09:44:27 -0600 | [diff] [blame] | 1023 | ndk::ScopedAStatus ComposerClient::setActiveConfig(int64_t display_id, |
| 1024 | int32_t config) { |
Dennis Tsiang | 33f0ece | 2023-11-29 12:45:04 +0000 | [diff] [blame] | 1025 | DEBUG_FUNC(); |
Drew Davenport | 5951b11 | 2024-08-05 09:44:27 -0600 | [diff] [blame] | 1026 | const std::unique_lock lock(hwc_->GetResMan().GetMainLock()); |
| 1027 | HwcDisplay* display = GetDisplay(display_id); |
| 1028 | if (display == nullptr) { |
| 1029 | return ToBinderStatus(hwc3::Error::kBadDisplay); |
| 1030 | } |
| 1031 | |
| 1032 | return ToBinderStatus(Hwc2toHwc3Error(display->SetActiveConfig(config))); |
Dennis Tsiang | 33f0ece | 2023-11-29 12:45:04 +0000 | [diff] [blame] | 1033 | } |
| 1034 | |
| 1035 | ndk::ScopedAStatus ComposerClient::setActiveConfigWithConstraints( |
Drew Davenport | 5951b11 | 2024-08-05 09:44:27 -0600 | [diff] [blame] | 1036 | int64_t display_id, int32_t config, |
| 1037 | const VsyncPeriodChangeConstraints& constraints, |
| 1038 | VsyncPeriodChangeTimeline* timeline) { |
Dennis Tsiang | 33f0ece | 2023-11-29 12:45:04 +0000 | [diff] [blame] | 1039 | DEBUG_FUNC(); |
Drew Davenport | 5951b11 | 2024-08-05 09:44:27 -0600 | [diff] [blame] | 1040 | const std::unique_lock lock(hwc_->GetResMan().GetMainLock()); |
| 1041 | HwcDisplay* display = GetDisplay(display_id); |
| 1042 | if (display == nullptr) { |
| 1043 | return ToBinderStatus(hwc3::Error::kBadDisplay); |
| 1044 | } |
| 1045 | |
| 1046 | hwc_vsync_period_change_constraints_t hwc2_constraints; |
| 1047 | hwc2_constraints.desiredTimeNanos = constraints.desiredTimeNanos; |
| 1048 | hwc2_constraints.seamlessRequired = static_cast<uint8_t>( |
| 1049 | constraints.seamlessRequired); |
| 1050 | |
| 1051 | hwc_vsync_period_change_timeline_t hwc2_timeline{}; |
| 1052 | auto error = Hwc2toHwc3Error( |
| 1053 | display->SetActiveConfigWithConstraints(config, &hwc2_constraints, |
| 1054 | &hwc2_timeline)); |
| 1055 | if (error != hwc3::Error::kNone) { |
| 1056 | return ToBinderStatus(error); |
| 1057 | } |
| 1058 | |
| 1059 | timeline->refreshTimeNanos = hwc2_timeline.refreshTimeNanos; |
| 1060 | timeline->newVsyncAppliedTimeNanos = hwc2_timeline.newVsyncAppliedTimeNanos; |
| 1061 | timeline->refreshRequired = static_cast<bool>(hwc2_timeline.refreshRequired); |
Dennis Tsiang | 33f0ece | 2023-11-29 12:45:04 +0000 | [diff] [blame] | 1062 | return ndk::ScopedAStatus::ok(); |
| 1063 | } |
| 1064 | |
Drew Davenport | 5951b11 | 2024-08-05 09:44:27 -0600 | [diff] [blame] | 1065 | ndk::ScopedAStatus ComposerClient::setBootDisplayConfig(int64_t /*display_id*/, |
Dennis Tsiang | 33f0ece | 2023-11-29 12:45:04 +0000 | [diff] [blame] | 1066 | int32_t /*config*/) { |
| 1067 | DEBUG_FUNC(); |
Drew Davenport | 5951b11 | 2024-08-05 09:44:27 -0600 | [diff] [blame] | 1068 | return ToBinderStatus(hwc3::Error::kUnsupported); |
Dennis Tsiang | 33f0ece | 2023-11-29 12:45:04 +0000 | [diff] [blame] | 1069 | } |
| 1070 | |
Drew Davenport | 5951b11 | 2024-08-05 09:44:27 -0600 | [diff] [blame] | 1071 | ndk::ScopedAStatus ComposerClient::clearBootDisplayConfig( |
| 1072 | int64_t /*display_id*/) { |
Dennis Tsiang | 33f0ece | 2023-11-29 12:45:04 +0000 | [diff] [blame] | 1073 | DEBUG_FUNC(); |
Drew Davenport | 5951b11 | 2024-08-05 09:44:27 -0600 | [diff] [blame] | 1074 | return ToBinderStatus(hwc3::Error::kUnsupported); |
Dennis Tsiang | 33f0ece | 2023-11-29 12:45:04 +0000 | [diff] [blame] | 1075 | } |
| 1076 | |
| 1077 | ndk::ScopedAStatus ComposerClient::getPreferredBootDisplayConfig( |
Drew Davenport | 5951b11 | 2024-08-05 09:44:27 -0600 | [diff] [blame] | 1078 | int64_t /*display_id*/, int32_t* /*config*/) { |
Dennis Tsiang | 33f0ece | 2023-11-29 12:45:04 +0000 | [diff] [blame] | 1079 | DEBUG_FUNC(); |
Drew Davenport | 5951b11 | 2024-08-05 09:44:27 -0600 | [diff] [blame] | 1080 | return ToBinderStatus(hwc3::Error::kUnsupported); |
Dennis Tsiang | 33f0ece | 2023-11-29 12:45:04 +0000 | [diff] [blame] | 1081 | } |
| 1082 | |
Drew Davenport | 5951b11 | 2024-08-05 09:44:27 -0600 | [diff] [blame] | 1083 | ndk::ScopedAStatus ComposerClient::setAutoLowLatencyMode(int64_t display_id, |
| 1084 | bool on) { |
Dennis Tsiang | 33f0ece | 2023-11-29 12:45:04 +0000 | [diff] [blame] | 1085 | DEBUG_FUNC(); |
Drew Davenport | 5951b11 | 2024-08-05 09:44:27 -0600 | [diff] [blame] | 1086 | const std::unique_lock lock(hwc_->GetResMan().GetMainLock()); |
| 1087 | HwcDisplay* display = GetDisplay(display_id); |
| 1088 | if (display == nullptr) { |
| 1089 | return ToBinderStatus(hwc3::Error::kBadDisplay); |
| 1090 | } |
| 1091 | |
| 1092 | auto error = Hwc2toHwc3Error(display->SetAutoLowLatencyMode(on)); |
| 1093 | return ToBinderStatus(error); |
Dennis Tsiang | 33f0ece | 2023-11-29 12:45:04 +0000 | [diff] [blame] | 1094 | } |
| 1095 | |
Drew Davenport | 5951b11 | 2024-08-05 09:44:27 -0600 | [diff] [blame] | 1096 | ndk::ScopedAStatus ComposerClient::setClientTargetSlotCount(int64_t display_id, |
| 1097 | int32_t count) { |
Dennis Tsiang | 33f0ece | 2023-11-29 12:45:04 +0000 | [diff] [blame] | 1098 | DEBUG_FUNC(); |
Drew Davenport | 5951b11 | 2024-08-05 09:44:27 -0600 | [diff] [blame] | 1099 | return ToBinderStatus( |
| 1100 | composer_resources_->SetDisplayClientTargetCacheSize(display_id, count)); |
Dennis Tsiang | 33f0ece | 2023-11-29 12:45:04 +0000 | [diff] [blame] | 1101 | } |
| 1102 | |
Drew Davenport | 5951b11 | 2024-08-05 09:44:27 -0600 | [diff] [blame] | 1103 | ndk::ScopedAStatus ComposerClient::setColorMode(int64_t display_id, |
| 1104 | ColorMode mode, |
| 1105 | RenderIntent intent) { |
Dennis Tsiang | 33f0ece | 2023-11-29 12:45:04 +0000 | [diff] [blame] | 1106 | DEBUG_FUNC(); |
Drew Davenport | 5951b11 | 2024-08-05 09:44:27 -0600 | [diff] [blame] | 1107 | const std::unique_lock lock(hwc_->GetResMan().GetMainLock()); |
| 1108 | HwcDisplay* display = GetDisplay(display_id); |
| 1109 | if (display == nullptr) { |
| 1110 | return ToBinderStatus(hwc3::Error::kBadDisplay); |
| 1111 | } |
| 1112 | |
| 1113 | auto error = display->SetColorModeWithIntent(Hwc3ColorModeToHwc2(mode), |
| 1114 | Hwc3RenderIntentToHwc2(intent)); |
| 1115 | return ToBinderStatus(Hwc2toHwc3Error(error)); |
Dennis Tsiang | 33f0ece | 2023-11-29 12:45:04 +0000 | [diff] [blame] | 1116 | } |
| 1117 | |
Drew Davenport | 5951b11 | 2024-08-05 09:44:27 -0600 | [diff] [blame] | 1118 | ndk::ScopedAStatus ComposerClient::setContentType(int64_t display_id, |
| 1119 | ContentType type) { |
Dennis Tsiang | 33f0ece | 2023-11-29 12:45:04 +0000 | [diff] [blame] | 1120 | DEBUG_FUNC(); |
Drew Davenport | 5951b11 | 2024-08-05 09:44:27 -0600 | [diff] [blame] | 1121 | const std::unique_lock lock(hwc_->GetResMan().GetMainLock()); |
| 1122 | HwcDisplay* display = GetDisplay(display_id); |
| 1123 | if (display == nullptr) { |
| 1124 | return ToBinderStatus(hwc3::Error::kBadDisplay); |
| 1125 | } |
| 1126 | |
Drew Davenport | 8d38dc7 | 2024-09-24 12:26:07 -0600 | [diff] [blame] | 1127 | if (type == ContentType::NONE) { |
| 1128 | return ndk::ScopedAStatus::ok(); |
| 1129 | } |
| 1130 | return ToBinderStatus(hwc3::Error::kUnsupported); |
Dennis Tsiang | 33f0ece | 2023-11-29 12:45:04 +0000 | [diff] [blame] | 1131 | } |
| 1132 | |
| 1133 | ndk::ScopedAStatus ComposerClient::setDisplayedContentSamplingEnabled( |
Drew Davenport | 5951b11 | 2024-08-05 09:44:27 -0600 | [diff] [blame] | 1134 | int64_t /*display_id*/, bool /*enable*/, |
Dennis Tsiang | 33f0ece | 2023-11-29 12:45:04 +0000 | [diff] [blame] | 1135 | FormatColorComponent /*componentMask*/, int64_t /*maxFrames*/) { |
| 1136 | DEBUG_FUNC(); |
Drew Davenport | 5951b11 | 2024-08-05 09:44:27 -0600 | [diff] [blame] | 1137 | return ToBinderStatus(hwc3::Error::kUnsupported); |
Dennis Tsiang | 33f0ece | 2023-11-29 12:45:04 +0000 | [diff] [blame] | 1138 | } |
| 1139 | |
Drew Davenport | 5951b11 | 2024-08-05 09:44:27 -0600 | [diff] [blame] | 1140 | ndk::ScopedAStatus ComposerClient::setPowerMode(int64_t display_id, |
| 1141 | PowerMode mode) { |
Dennis Tsiang | 33f0ece | 2023-11-29 12:45:04 +0000 | [diff] [blame] | 1142 | DEBUG_FUNC(); |
Drew Davenport | 5951b11 | 2024-08-05 09:44:27 -0600 | [diff] [blame] | 1143 | const std::unique_lock lock(hwc_->GetResMan().GetMainLock()); |
| 1144 | HwcDisplay* display = GetDisplay(display_id); |
| 1145 | if (display == nullptr) { |
| 1146 | return ToBinderStatus(hwc3::Error::kBadDisplay); |
| 1147 | } |
| 1148 | |
Dennis Tsiang | 1a96620 | 2024-01-24 12:46:33 +0000 | [diff] [blame] | 1149 | if (mode == PowerMode::ON_SUSPEND) { |
| 1150 | return ToBinderStatus(hwc3::Error::kUnsupported); |
| 1151 | } |
| 1152 | |
Drew Davenport | 5951b11 | 2024-08-05 09:44:27 -0600 | [diff] [blame] | 1153 | auto error = display->SetPowerMode(Hwc3PowerModeToHwc2(mode)); |
| 1154 | return ToBinderStatus(Hwc2toHwc3Error(error)); |
Dennis Tsiang | 33f0ece | 2023-11-29 12:45:04 +0000 | [diff] [blame] | 1155 | } |
| 1156 | |
| 1157 | ndk::ScopedAStatus ComposerClient::setReadbackBuffer( |
Drew Davenport | 5951b11 | 2024-08-05 09:44:27 -0600 | [diff] [blame] | 1158 | int64_t /*display_id*/, const AidlNativeHandle& /*aidlBuffer*/, |
Dennis Tsiang | 33f0ece | 2023-11-29 12:45:04 +0000 | [diff] [blame] | 1159 | const ndk::ScopedFileDescriptor& /*releaseFence*/) { |
| 1160 | DEBUG_FUNC(); |
Drew Davenport | 5951b11 | 2024-08-05 09:44:27 -0600 | [diff] [blame] | 1161 | return ToBinderStatus(hwc3::Error::kUnsupported); |
Dennis Tsiang | 33f0ece | 2023-11-29 12:45:04 +0000 | [diff] [blame] | 1162 | } |
| 1163 | |
Drew Davenport | 5951b11 | 2024-08-05 09:44:27 -0600 | [diff] [blame] | 1164 | ndk::ScopedAStatus ComposerClient::setVsyncEnabled(int64_t display_id, |
| 1165 | bool enabled) { |
Dennis Tsiang | 33f0ece | 2023-11-29 12:45:04 +0000 | [diff] [blame] | 1166 | DEBUG_FUNC(); |
Drew Davenport | 5951b11 | 2024-08-05 09:44:27 -0600 | [diff] [blame] | 1167 | const std::unique_lock lock(hwc_->GetResMan().GetMainLock()); |
| 1168 | HwcDisplay* display = GetDisplay(display_id); |
| 1169 | if (display == nullptr) { |
| 1170 | return ToBinderStatus(hwc3::Error::kBadDisplay); |
| 1171 | } |
| 1172 | |
| 1173 | auto error = display->SetVsyncEnabled(static_cast<int32_t>(enabled)); |
| 1174 | return ToBinderStatus(Hwc2toHwc3Error(error)); |
Dennis Tsiang | 33f0ece | 2023-11-29 12:45:04 +0000 | [diff] [blame] | 1175 | } |
| 1176 | |
Drew Davenport | 5951b11 | 2024-08-05 09:44:27 -0600 | [diff] [blame] | 1177 | ndk::ScopedAStatus ComposerClient::setIdleTimerEnabled(int64_t /*display_id*/, |
Dennis Tsiang | 33f0ece | 2023-11-29 12:45:04 +0000 | [diff] [blame] | 1178 | int32_t /*timeout*/) { |
| 1179 | DEBUG_FUNC(); |
Drew Davenport | 5951b11 | 2024-08-05 09:44:27 -0600 | [diff] [blame] | 1180 | return ToBinderStatus(hwc3::Error::kUnsupported); |
| 1181 | } |
| 1182 | |
Drew Davenport | 7f1761b | 2024-08-20 10:09:43 -0600 | [diff] [blame] | 1183 | ndk::ScopedAStatus ComposerClient::getOverlaySupport( |
| 1184 | OverlayProperties* /*out_overlay_properties*/) { |
| 1185 | return ToBinderStatus(hwc3::Error::kUnsupported); |
| 1186 | } |
| 1187 | |
| 1188 | ndk::ScopedAStatus ComposerClient::getHdrConversionCapabilities( |
| 1189 | std::vector<common::HdrConversionCapability>* /*out_capabilities*/) { |
| 1190 | return ToBinderStatus(hwc3::Error::kUnsupported); |
| 1191 | } |
| 1192 | |
| 1193 | ndk::ScopedAStatus ComposerClient::setHdrConversionStrategy( |
| 1194 | const common::HdrConversionStrategy& /*conversion_strategy*/, |
| 1195 | common::Hdr* /*out_hdr*/) { |
| 1196 | return ToBinderStatus(hwc3::Error::kUnsupported); |
| 1197 | } |
| 1198 | |
| 1199 | ndk::ScopedAStatus ComposerClient::setRefreshRateChangedCallbackDebugEnabled( |
| 1200 | int64_t /*display*/, bool /*enabled*/) { |
| 1201 | return ToBinderStatus(hwc3::Error::kUnsupported); |
| 1202 | } |
| 1203 | |
Roman Stratiienko | 71a8f02 | 2024-10-16 23:17:33 +0300 | [diff] [blame] | 1204 | #if __ANDROID_API__ >= 35 |
| 1205 | |
Drew Davenport | 7f1761b | 2024-08-20 10:09:43 -0600 | [diff] [blame] | 1206 | ndk::ScopedAStatus ComposerClient::getDisplayConfigurations( |
Drew Davenport | f7e8833 | 2024-09-06 12:54:38 -0600 | [diff] [blame] | 1207 | int64_t display_id, int32_t /*max_frame_interval_ns*/, |
Drew Davenport | 7f1761b | 2024-08-20 10:09:43 -0600 | [diff] [blame] | 1208 | std::vector<DisplayConfiguration>* configurations) { |
Drew Davenport | f7e8833 | 2024-09-06 12:54:38 -0600 | [diff] [blame] | 1209 | DEBUG_FUNC(); |
| 1210 | const std::unique_lock lock(hwc_->GetResMan().GetMainLock()); |
| 1211 | HwcDisplay* display = GetDisplay(display_id); |
| 1212 | if (display == nullptr) { |
| 1213 | return ToBinderStatus(hwc3::Error::kBadDisplay); |
| 1214 | } |
| 1215 | |
| 1216 | const HwcDisplayConfigs& configs = display->GetDisplayConfigs(); |
| 1217 | for (const auto& [id, config] : configs.hwc_configs) { |
Drew Davenport | 1afb579 | 2024-09-24 12:53:22 -0600 | [diff] [blame] | 1218 | configurations->push_back( |
| 1219 | HwcDisplayConfigToAidlConfiguration(configs, config)); |
Drew Davenport | f7e8833 | 2024-09-06 12:54:38 -0600 | [diff] [blame] | 1220 | } |
| 1221 | return ndk::ScopedAStatus::ok(); |
Drew Davenport | 7f1761b | 2024-08-20 10:09:43 -0600 | [diff] [blame] | 1222 | } |
| 1223 | |
| 1224 | ndk::ScopedAStatus ComposerClient::notifyExpectedPresent( |
| 1225 | int64_t /*display*/, const ClockMonotonicTimestamp& /*expected_present_time*/, |
| 1226 | int32_t /*frame_interval_ns*/) { |
| 1227 | return ToBinderStatus(hwc3::Error::kUnsupported); |
| 1228 | } |
| 1229 | |
Roman Stratiienko | 71a8f02 | 2024-10-16 23:17:33 +0300 | [diff] [blame] | 1230 | #endif |
| 1231 | |
Drew Davenport | 5951b11 | 2024-08-05 09:44:27 -0600 | [diff] [blame] | 1232 | std::string ComposerClient::Dump() { |
| 1233 | uint32_t size = 0; |
| 1234 | hwc_->Dump(&size, nullptr); |
| 1235 | |
| 1236 | std::string buffer(size, '\0'); |
| 1237 | hwc_->Dump(&size, &buffer.front()); |
| 1238 | return buffer; |
Dennis Tsiang | 33f0ece | 2023-11-29 12:45:04 +0000 | [diff] [blame] | 1239 | } |
| 1240 | |
| 1241 | ::ndk::SpAIBinder ComposerClient::createBinder() { |
| 1242 | auto binder = BnComposerClient::createBinder(); |
| 1243 | AIBinder_setInheritRt(binder.get(), true); |
| 1244 | return binder; |
| 1245 | } |
| 1246 | |
Drew Davenport | e5fbbbb | 2024-10-14 15:49:27 -0600 | [diff] [blame] | 1247 | hwc3::Error ComposerClient::ImportLayerBuffer( |
| 1248 | int64_t display_id, int64_t layer_id, const Buffer& buffer, |
| 1249 | buffer_handle_t* out_imported_buffer) { |
| 1250 | *out_imported_buffer = nullptr; |
Drew Davenport | 5951b11 | 2024-08-05 09:44:27 -0600 | [diff] [blame] | 1251 | |
| 1252 | auto releaser = composer_resources_->CreateResourceReleaser(true); |
Drew Davenport | e5fbbbb | 2024-10-14 15:49:27 -0600 | [diff] [blame] | 1253 | auto err = composer_resources_->GetLayerBuffer(display_id, layer_id, buffer, |
| 1254 | out_imported_buffer, |
Drew Davenport | 5951b11 | 2024-08-05 09:44:27 -0600 | [diff] [blame] | 1255 | releaser.get()); |
Drew Davenport | e5fbbbb | 2024-10-14 15:49:27 -0600 | [diff] [blame] | 1256 | return err; |
Drew Davenport | 5951b11 | 2024-08-05 09:44:27 -0600 | [diff] [blame] | 1257 | } |
| 1258 | |
Drew Davenport | 5951b11 | 2024-08-05 09:44:27 -0600 | [diff] [blame] | 1259 | void ComposerClient::ExecuteSetDisplayColorTransform( |
| 1260 | uint64_t display_id, const std::vector<float>& matrix) { |
| 1261 | auto* display = GetDisplay(display_id); |
| 1262 | if (display == nullptr) { |
| 1263 | cmd_result_writer_->AddError(hwc3::Error::kBadDisplay); |
| 1264 | return; |
| 1265 | } |
| 1266 | |
| 1267 | auto almost_equal = [](auto a, auto b) { |
| 1268 | const float epsilon = 0.001F; |
| 1269 | return std::abs(a - b) < epsilon; |
| 1270 | }; |
| 1271 | const bool is_identity = std::equal(matrix.begin(), matrix.end(), |
| 1272 | kIdentityMatrix.begin(), almost_equal); |
| 1273 | |
| 1274 | const int32_t hint = is_identity ? HAL_COLOR_TRANSFORM_IDENTITY |
| 1275 | : HAL_COLOR_TRANSFORM_ARBITRARY_MATRIX; |
| 1276 | |
| 1277 | auto error = Hwc2toHwc3Error(display->SetColorTransform(matrix.data(), hint)); |
| 1278 | if (error != hwc3::Error::kNone) { |
| 1279 | cmd_result_writer_->AddError(error); |
| 1280 | } |
| 1281 | } |
| 1282 | void ComposerClient::ExecuteSetDisplayClientTarget( |
| 1283 | uint64_t display_id, const ClientTarget& command) { |
| 1284 | auto* display = GetDisplay(display_id); |
| 1285 | if (display == nullptr) { |
| 1286 | cmd_result_writer_->AddError(hwc3::Error::kBadDisplay); |
| 1287 | return; |
| 1288 | } |
| 1289 | |
| 1290 | hwc_region_t damage_regions; |
| 1291 | damage_regions.numRects = command.damage.size(); |
| 1292 | |
| 1293 | std::vector<hwc_rect_t> regions(command.damage.size()); |
| 1294 | for (const auto& region : command.damage) { |
| 1295 | regions.push_back({region.left, region.top, region.right, region.bottom}); |
| 1296 | } |
| 1297 | damage_regions.rects = regions.data(); |
| 1298 | |
| 1299 | buffer_handle_t imported_buffer = nullptr; |
| 1300 | auto buf_releaser = composer_resources_->CreateResourceReleaser(true); |
| 1301 | |
| 1302 | auto error = composer_resources_->GetDisplayClientTarget(display_id, |
| 1303 | command.buffer, |
| 1304 | &imported_buffer, |
| 1305 | buf_releaser.get()); |
| 1306 | if (error != hwc3::Error::kNone) { |
| 1307 | cmd_result_writer_->AddError(error); |
| 1308 | return; |
| 1309 | } |
| 1310 | |
| 1311 | // NOLINTNEXTLINE(cppcoreguidelines-pro-type-const-cast) |
| 1312 | auto fence = const_cast<::ndk::ScopedFileDescriptor&>(command.buffer.fence) |
| 1313 | .release(); |
| 1314 | error = Hwc2toHwc3Error( |
| 1315 | display->SetClientTarget(imported_buffer, fence, |
| 1316 | Hwc3DataspaceToHwc2(command.dataspace), |
| 1317 | damage_regions)); |
| 1318 | if (error != hwc3::Error::kNone) { |
| 1319 | cmd_result_writer_->AddError(error); |
| 1320 | } |
| 1321 | } |
| 1322 | |
| 1323 | void ComposerClient::ExecuteSetDisplayOutputBuffer(uint64_t display_id, |
| 1324 | const Buffer& buffer) { |
| 1325 | auto* display = GetDisplay(display_id); |
| 1326 | if (display == nullptr) { |
| 1327 | cmd_result_writer_->AddError(hwc3::Error::kBadDisplay); |
| 1328 | return; |
| 1329 | } |
| 1330 | |
| 1331 | buffer_handle_t imported_buffer = nullptr; |
| 1332 | auto buf_releaser = composer_resources_->CreateResourceReleaser(true); |
| 1333 | |
| 1334 | auto error = composer_resources_->GetDisplayOutputBuffer(display_id, buffer, |
| 1335 | &imported_buffer, |
| 1336 | buf_releaser.get()); |
| 1337 | if (error != hwc3::Error::kNone) { |
| 1338 | cmd_result_writer_->AddError(error); |
| 1339 | return; |
| 1340 | } |
| 1341 | |
| 1342 | // NOLINTNEXTLINE(cppcoreguidelines-pro-type-const-cast) |
| 1343 | auto fence = const_cast<::ndk::ScopedFileDescriptor&>(buffer.fence).release(); |
| 1344 | error = Hwc2toHwc3Error(display->SetOutputBuffer(imported_buffer, fence)); |
| 1345 | if (error != hwc3::Error::kNone) { |
| 1346 | cmd_result_writer_->AddError(error); |
| 1347 | return; |
| 1348 | } |
| 1349 | } |
| 1350 | void ComposerClient::ExecuteValidateDisplay( |
| 1351 | int64_t display_id, |
| 1352 | std::optional<ClockMonotonicTimestamp> /*expected_present_time*/ |
| 1353 | ) { |
| 1354 | auto* display = GetDisplay(display_id); |
| 1355 | if (display == nullptr) { |
| 1356 | cmd_result_writer_->AddError(hwc3::Error::kBadDisplay); |
| 1357 | return; |
| 1358 | } |
| 1359 | |
| 1360 | /* TODO: Handle expectedPresentTime */ |
Normunds Rieksts | 4282095 | 2024-03-12 15:42:06 +0000 | [diff] [blame] | 1361 | /* This can be implemented in multiple ways. For example, the expected present |
| 1362 | * time property can be implemented by the DRM driver directly as a CRTC |
| 1363 | * property. See: |
| 1364 | * https://cs.android.com/android/platform/superproject/main/+/b8b3b1646e64d0235f77b9e717a3e4082e26f2a8:hardware/google/graphics/common/libhwc2.1/libdrmresource/drm/drmcrtc.cpp;drc=468f6172546ab98983de18210222f231f16b21e1;l=88 |
| 1365 | * Unfortunately there doesn't seem to be a standardised way of delaying |
| 1366 | * presentation with a timestamp in the DRM API. What we can do alternatively |
| 1367 | * is to spawn a separate presentation thread that could handle the VBlank |
| 1368 | * events by using DRM_MODE_PAGE_FLIP_EVENT and schedule them appropriately. |
| 1369 | */ |
Drew Davenport | 5951b11 | 2024-08-05 09:44:27 -0600 | [diff] [blame] | 1370 | |
| 1371 | std::vector<int64_t> changed_layers; |
| 1372 | std::vector<Composition> composition_types; |
| 1373 | int32_t display_request_mask = 0; |
| 1374 | std::vector<int64_t> requested_layers; |
| 1375 | std::vector<int32_t> request_masks; |
| 1376 | |
| 1377 | const hwc3::Error error = ValidateDisplayInternal(*display, &changed_layers, |
| 1378 | &composition_types, |
| 1379 | &display_request_mask, |
| 1380 | &requested_layers, |
| 1381 | &request_masks, nullptr, |
| 1382 | nullptr); |
| 1383 | |
| 1384 | if (error != hwc3::Error::kNone) { |
| 1385 | cmd_result_writer_->AddError(error); |
| 1386 | } |
| 1387 | |
| 1388 | // If a CommandError has been been set for the current DisplayCommand, then |
| 1389 | // no other results should be returned besides the error. |
| 1390 | if (cmd_result_writer_->HasError()) { |
| 1391 | return; |
| 1392 | } |
| 1393 | |
| 1394 | DisplayChanges changes{}; |
| 1395 | for (size_t i = 0; i < composition_types.size(); i++) { |
| 1396 | changes.AddLayerCompositionChange(display_id, changed_layers[i], |
| 1397 | composition_types[i]); |
| 1398 | } |
| 1399 | |
| 1400 | std::vector<DisplayRequest::LayerRequest> layer_requests; |
| 1401 | for (size_t i = 0; i < requested_layers.size(); i++) { |
| 1402 | layer_requests.push_back({requested_layers[i], request_masks[i]}); |
| 1403 | } |
| 1404 | |
| 1405 | const DisplayRequest request_changes{display_id, display_request_mask, |
| 1406 | layer_requests}; |
| 1407 | changes.display_request_changes = request_changes; |
| 1408 | |
| 1409 | cmd_result_writer_->AddChanges(changes); |
| 1410 | composer_resources_->SetDisplayMustValidateState(display_id, false); |
| 1411 | } |
| 1412 | |
| 1413 | void ComposerClient::ExecuteAcceptDisplayChanges(int64_t display_id) { |
| 1414 | auto* display = GetDisplay(display_id); |
| 1415 | if (display == nullptr) { |
| 1416 | cmd_result_writer_->AddError(hwc3::Error::kBadDisplay); |
| 1417 | return; |
| 1418 | } |
| 1419 | |
| 1420 | auto error = Hwc2toHwc3Error(display->AcceptDisplayChanges()); |
| 1421 | if (error != hwc3::Error::kNone) { |
| 1422 | cmd_result_writer_->AddError(error); |
| 1423 | return; |
| 1424 | } |
| 1425 | } |
| 1426 | |
| 1427 | void ComposerClient::ExecutePresentDisplay(int64_t display_id) { |
| 1428 | auto* display = GetDisplay(display_id); |
| 1429 | if (display == nullptr) { |
| 1430 | cmd_result_writer_->AddError(hwc3::Error::kBadDisplay); |
| 1431 | return; |
| 1432 | } |
| 1433 | |
| 1434 | ::android::base::unique_fd display_fence; |
| 1435 | std::unordered_map<int64_t, ::android::base::unique_fd> release_fences; |
| 1436 | auto error = PresentDisplayInternal(display_id, display_fence, |
| 1437 | release_fences); |
| 1438 | if (error != hwc3::Error::kNone) { |
| 1439 | cmd_result_writer_->AddError(error); |
| 1440 | } |
| 1441 | if (cmd_result_writer_->HasError()) { |
| 1442 | return; |
| 1443 | } |
| 1444 | |
| 1445 | cmd_result_writer_->AddPresentFence(display_id, std::move(display_fence)); |
| 1446 | cmd_result_writer_->AddReleaseFence(display_id, release_fences); |
| 1447 | } |
| 1448 | |
| 1449 | void ComposerClient::ExecutePresentOrValidateDisplay( |
| 1450 | int64_t display_id, |
| 1451 | std::optional<ClockMonotonicTimestamp> expected_present_time) { |
| 1452 | auto* display = GetDisplay(display_id); |
| 1453 | if (display == nullptr) { |
| 1454 | cmd_result_writer_->AddError(hwc3::Error::kBadDisplay); |
| 1455 | return; |
| 1456 | } |
| 1457 | |
| 1458 | /* TODO: Handle expectedPresentTime */ |
Normunds Rieksts | 4282095 | 2024-03-12 15:42:06 +0000 | [diff] [blame] | 1459 | /* This can be implemented in multiple ways. For example, the expected present |
| 1460 | * time property can be implemented by the DRM driver directly as a CRTC |
| 1461 | * property. See: |
| 1462 | * https://cs.android.com/android/platform/superproject/main/+/b8b3b1646e64d0235f77b9e717a3e4082e26f2a8:hardware/google/graphics/common/libhwc2.1/libdrmresource/drm/drmcrtc.cpp;drc=468f6172546ab98983de18210222f231f16b21e1;l=88 |
| 1463 | * Unfortunately there doesn't seem to be a standardised way of delaying |
| 1464 | * presentation with a timestamp in the DRM API. What we can do alternatively |
| 1465 | * is to spawn a separate presentation thread that could handle the VBlank |
| 1466 | * events by using DRM_MODE_PAGE_FLIP_EVENT and schedule them appropriately. |
| 1467 | */ |
| 1468 | |
Drew Davenport | 5951b11 | 2024-08-05 09:44:27 -0600 | [diff] [blame] | 1469 | /* TODO: Add check if it's possible to skip display validation */ |
| 1470 | ExecuteValidateDisplay(display_id, expected_present_time); |
| 1471 | cmd_result_writer_ |
| 1472 | ->AddPresentOrValidateResult(display_id, |
| 1473 | PresentOrValidate::Result::Validated); |
| 1474 | } |
| 1475 | |
Dennis Tsiang | 33f0ece | 2023-11-29 12:45:04 +0000 | [diff] [blame] | 1476 | } // namespace aidl::android::hardware::graphics::composer3::impl |