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 | 5951b11 | 2024-08-05 09:44:27 -0600 | [diff] [blame] | 552 | HwcLayerWrapper layer_wrapper{command.layer, layer}; |
| 553 | if (command.buffer) { |
| 554 | ExecuteSetLayerBuffer(display_id, layer_wrapper, *command.buffer); |
| 555 | } |
Drew Davenport | 1b0d8b7 | 2024-09-24 15:31:38 -0600 | [diff] [blame] | 556 | |
Drew Davenport | a241a77 | 2024-09-24 11:26:30 -0600 | [diff] [blame] | 557 | HwcLayer::LayerProperties properties; |
| 558 | properties.blend_mode = AidlToBlendMode(command.blendMode); |
Drew Davenport | ac9681e | 2024-09-24 12:17:34 -0600 | [diff] [blame] | 559 | properties.color_space = AidlToColorSpace(command.dataspace); |
| 560 | properties.sample_range = AidlToSampleRange(command.dataspace); |
Drew Davenport | 1b0d8b7 | 2024-09-24 15:31:38 -0600 | [diff] [blame] | 561 | properties.composition_type = AidlToCompositionType(command.composition); |
Drew Davenport | 22d66b4 | 2024-09-24 15:34:57 -0600 | [diff] [blame] | 562 | properties.display_frame = AidlToRect(command.displayFrame); |
Drew Davenport | 07b96f0 | 2024-09-24 15:37:12 -0600 | [diff] [blame] | 563 | properties.alpha = AidlToAlpha(command.planeAlpha); |
Drew Davenport | 7ab8c18 | 2024-09-24 17:04:26 -0600 | [diff] [blame] | 564 | properties.source_crop = AidlToFRect(command.sourceCrop); |
Drew Davenport | 51c61e4 | 2024-09-24 17:13:39 -0600 | [diff] [blame] | 565 | properties.transform = AidlToLayerTransform(command.transform); |
Drew Davenport | 5d679b0 | 2024-09-25 10:15:58 -0600 | [diff] [blame] | 566 | properties.z_order = AidlToZOrder(command.z); |
Drew Davenport | 7ab8c18 | 2024-09-24 17:04:26 -0600 | [diff] [blame] | 567 | |
Drew Davenport | a241a77 | 2024-09-24 11:26:30 -0600 | [diff] [blame] | 568 | layer->SetLayerProperties(properties); |
| 569 | |
Drew Davenport | 5951b11 | 2024-08-05 09:44:27 -0600 | [diff] [blame] | 570 | // Some unsupported functionality returns kUnsupported, and others |
| 571 | // are just a no-op. |
| 572 | // TODO: Audit whether some of these should actually return kUnsupported |
| 573 | // instead. |
| 574 | if (command.sidebandStream) { |
| 575 | cmd_result_writer_->AddError(hwc3::Error::kUnsupported); |
| 576 | } |
| 577 | // TODO: Blocking region handling missing. |
| 578 | // TODO: Layer surface damage. |
| 579 | // TODO: Layer visible region. |
| 580 | // TODO: Per-frame metadata. |
| 581 | // TODO: Layer color transform. |
| 582 | // TODO: Layer cursor position. |
| 583 | // TODO: Layer color. |
| 584 | } |
| 585 | |
| 586 | void ComposerClient::ExecuteDisplayCommand(const DisplayCommand& command) { |
| 587 | const int64_t display_id = command.display; |
| 588 | if (hwc_->GetDisplay(display_id) == nullptr) { |
| 589 | cmd_result_writer_->AddError(hwc3::Error::kBadDisplay); |
| 590 | return; |
| 591 | } |
| 592 | |
| 593 | for (const auto& layer_cmd : command.layers) { |
| 594 | DispatchLayerCommand(command.display, layer_cmd); |
| 595 | } |
| 596 | |
| 597 | if (command.brightness) { |
| 598 | ExecuteSetDisplayBrightness(command.display, *command.brightness); |
| 599 | } |
| 600 | if (command.colorTransformMatrix) { |
| 601 | ExecuteSetDisplayColorTransform(command.display, |
| 602 | *command.colorTransformMatrix); |
| 603 | } |
| 604 | if (command.clientTarget) { |
| 605 | ExecuteSetDisplayClientTarget(command.display, *command.clientTarget); |
| 606 | } |
| 607 | if (command.virtualDisplayOutputBuffer) { |
| 608 | ExecuteSetDisplayOutputBuffer(command.display, |
| 609 | *command.virtualDisplayOutputBuffer); |
| 610 | } |
| 611 | if (command.validateDisplay) { |
| 612 | ExecuteValidateDisplay(command.display, command.expectedPresentTime); |
| 613 | } |
| 614 | if (command.acceptDisplayChanges) { |
| 615 | ExecuteAcceptDisplayChanges(command.display); |
| 616 | } |
| 617 | if (command.presentDisplay) { |
| 618 | ExecutePresentDisplay(command.display); |
| 619 | } |
| 620 | if (command.presentOrValidateDisplay) { |
| 621 | ExecutePresentOrValidateDisplay(command.display, |
| 622 | command.expectedPresentTime); |
| 623 | } |
Dennis Tsiang | 33f0ece | 2023-11-29 12:45:04 +0000 | [diff] [blame] | 624 | } |
| 625 | |
| 626 | ndk::ScopedAStatus ComposerClient::executeCommands( |
Drew Davenport | 5951b11 | 2024-08-05 09:44:27 -0600 | [diff] [blame] | 627 | const std::vector<DisplayCommand>& commands, |
| 628 | std::vector<CommandResultPayload>* results) { |
Drew Davenport | 4996585 | 2024-09-05 10:59:40 -0600 | [diff] [blame] | 629 | const std::unique_lock lock(hwc_->GetResMan().GetMainLock()); |
| 630 | DEBUG_FUNC(); |
Drew Davenport | 5951b11 | 2024-08-05 09:44:27 -0600 | [diff] [blame] | 631 | cmd_result_writer_ = std::make_unique<CommandResultWriter>(results); |
| 632 | for (const auto& cmd : commands) { |
| 633 | ExecuteDisplayCommand(cmd); |
| 634 | cmd_result_writer_->IncrementCommand(); |
| 635 | } |
| 636 | cmd_result_writer_.reset(); |
| 637 | |
Dennis Tsiang | 33f0ece | 2023-11-29 12:45:04 +0000 | [diff] [blame] | 638 | return ndk::ScopedAStatus::ok(); |
| 639 | } |
| 640 | |
Drew Davenport | 5951b11 | 2024-08-05 09:44:27 -0600 | [diff] [blame] | 641 | ndk::ScopedAStatus ComposerClient::getActiveConfig(int64_t display_id, |
| 642 | int32_t* config) { |
Dennis Tsiang | 33f0ece | 2023-11-29 12:45:04 +0000 | [diff] [blame] | 643 | DEBUG_FUNC(); |
Drew Davenport | 5951b11 | 2024-08-05 09:44:27 -0600 | [diff] [blame] | 644 | const std::unique_lock lock(hwc_->GetResMan().GetMainLock()); |
| 645 | HwcDisplay* display = GetDisplay(display_id); |
| 646 | if (display == nullptr) { |
| 647 | return ToBinderStatus(hwc3::Error::kBadDisplay); |
| 648 | } |
| 649 | |
| 650 | uint32_t hwc2_config = 0; |
| 651 | const hwc3::Error error = Hwc2toHwc3Error( |
| 652 | display->GetActiveConfig(&hwc2_config)); |
| 653 | if (error != hwc3::Error::kNone) { |
| 654 | return ToBinderStatus(error); |
| 655 | } |
| 656 | *config = Hwc2ConfigIdToHwc3(hwc2_config); |
Dennis Tsiang | 33f0ece | 2023-11-29 12:45:04 +0000 | [diff] [blame] | 657 | return ndk::ScopedAStatus::ok(); |
| 658 | } |
| 659 | |
| 660 | ndk::ScopedAStatus ComposerClient::getColorModes( |
Drew Davenport | 5951b11 | 2024-08-05 09:44:27 -0600 | [diff] [blame] | 661 | int64_t display_id, std::vector<ColorMode>* color_modes) { |
Dennis Tsiang | 33f0ece | 2023-11-29 12:45:04 +0000 | [diff] [blame] | 662 | DEBUG_FUNC(); |
Drew Davenport | 5951b11 | 2024-08-05 09:44:27 -0600 | [diff] [blame] | 663 | const std::unique_lock lock(hwc_->GetResMan().GetMainLock()); |
| 664 | HwcDisplay* display = GetDisplay(display_id); |
| 665 | if (display == nullptr) { |
| 666 | return ToBinderStatus(hwc3::Error::kBadDisplay); |
| 667 | } |
| 668 | |
| 669 | uint32_t num_modes = 0; |
| 670 | auto error = Hwc2toHwc3Error(display->GetColorModes(&num_modes, nullptr)); |
| 671 | if (error != hwc3::Error::kNone) { |
| 672 | return ToBinderStatus(error); |
| 673 | } |
| 674 | |
| 675 | std::vector<int32_t> hwc2_color_modes(num_modes); |
| 676 | error = Hwc2toHwc3Error( |
| 677 | display->GetColorModes(&num_modes, hwc2_color_modes.data())); |
| 678 | if (error != hwc3::Error::kNone) { |
| 679 | return ToBinderStatus(error); |
| 680 | } |
| 681 | |
| 682 | for (const auto& mode : hwc2_color_modes) { |
| 683 | color_modes->push_back(Hwc2ColorModeToHwc3(mode)); |
| 684 | } |
| 685 | |
Dennis Tsiang | 33f0ece | 2023-11-29 12:45:04 +0000 | [diff] [blame] | 686 | return ndk::ScopedAStatus::ok(); |
| 687 | } |
| 688 | |
| 689 | ndk::ScopedAStatus ComposerClient::getDataspaceSaturationMatrix( |
Drew Davenport | 5951b11 | 2024-08-05 09:44:27 -0600 | [diff] [blame] | 690 | common::Dataspace dataspace, std::vector<float>* matrix) { |
Dennis Tsiang | 33f0ece | 2023-11-29 12:45:04 +0000 | [diff] [blame] | 691 | DEBUG_FUNC(); |
Drew Davenport | 5951b11 | 2024-08-05 09:44:27 -0600 | [diff] [blame] | 692 | if (dataspace != common::Dataspace::SRGB_LINEAR) { |
| 693 | return ToBinderStatus(hwc3::Error::kBadParameter); |
| 694 | } |
| 695 | |
| 696 | matrix->clear(); |
| 697 | matrix->insert(matrix->begin(), kIdentityMatrix.begin(), |
| 698 | kIdentityMatrix.end()); |
| 699 | |
Dennis Tsiang | 33f0ece | 2023-11-29 12:45:04 +0000 | [diff] [blame] | 700 | return ndk::ScopedAStatus::ok(); |
| 701 | } |
| 702 | |
| 703 | ndk::ScopedAStatus ComposerClient::getDisplayAttribute( |
Drew Davenport | 1afb579 | 2024-09-24 12:53:22 -0600 | [diff] [blame] | 704 | int64_t display_id, int32_t config_id, DisplayAttribute attribute, |
Drew Davenport | 5951b11 | 2024-08-05 09:44:27 -0600 | [diff] [blame] | 705 | int32_t* value) { |
Dennis Tsiang | 33f0ece | 2023-11-29 12:45:04 +0000 | [diff] [blame] | 706 | DEBUG_FUNC(); |
Drew Davenport | 5951b11 | 2024-08-05 09:44:27 -0600 | [diff] [blame] | 707 | const std::unique_lock lock(hwc_->GetResMan().GetMainLock()); |
| 708 | HwcDisplay* display = GetDisplay(display_id); |
| 709 | if (display == nullptr) { |
| 710 | return ToBinderStatus(hwc3::Error::kBadDisplay); |
| 711 | } |
| 712 | |
Drew Davenport | 1afb579 | 2024-09-24 12:53:22 -0600 | [diff] [blame] | 713 | const HwcDisplayConfigs& configs = display->GetDisplayConfigs(); |
| 714 | auto config = configs.hwc_configs.find(config_id); |
| 715 | if (config == configs.hwc_configs.end()) { |
| 716 | return ToBinderStatus(hwc3::Error::kBadConfig); |
| 717 | } |
| 718 | |
| 719 | DisplayConfiguration |
| 720 | aidl_configuration = HwcDisplayConfigToAidlConfiguration(configs, |
| 721 | config->second); |
| 722 | // Legacy API for querying DPI uses units of dots per 1000 inches. |
| 723 | static const int kLegacyDpiUnit = 1000; |
| 724 | switch (attribute) { |
| 725 | case DisplayAttribute::WIDTH: |
| 726 | *value = aidl_configuration.width; |
| 727 | break; |
| 728 | case DisplayAttribute::HEIGHT: |
| 729 | *value = aidl_configuration.height; |
| 730 | break; |
| 731 | case DisplayAttribute::VSYNC_PERIOD: |
| 732 | *value = aidl_configuration.vsyncPeriod; |
| 733 | break; |
| 734 | case DisplayAttribute::DPI_X: |
| 735 | *value = aidl_configuration.dpi |
| 736 | ? static_cast<int>(aidl_configuration.dpi->x * |
| 737 | kLegacyDpiUnit) |
| 738 | : -1; |
| 739 | break; |
| 740 | case DisplayAttribute::DPI_Y: |
| 741 | *value = aidl_configuration.dpi |
| 742 | ? static_cast<int>(aidl_configuration.dpi->y * |
| 743 | kLegacyDpiUnit) |
| 744 | : -1; |
| 745 | break; |
| 746 | case DisplayAttribute::CONFIG_GROUP: |
| 747 | *value = aidl_configuration.configGroup; |
| 748 | break; |
| 749 | case DisplayAttribute::INVALID: |
| 750 | return ToBinderStatus(hwc3::Error::kUnsupported); |
| 751 | } |
| 752 | return ndk::ScopedAStatus::ok(); |
Dennis Tsiang | 33f0ece | 2023-11-29 12:45:04 +0000 | [diff] [blame] | 753 | } |
| 754 | |
| 755 | ndk::ScopedAStatus ComposerClient::getDisplayCapabilities( |
Drew Davenport | 5951b11 | 2024-08-05 09:44:27 -0600 | [diff] [blame] | 756 | int64_t display_id, std::vector<DisplayCapability>* caps) { |
Dennis Tsiang | 33f0ece | 2023-11-29 12:45:04 +0000 | [diff] [blame] | 757 | DEBUG_FUNC(); |
Drew Davenport | 5951b11 | 2024-08-05 09:44:27 -0600 | [diff] [blame] | 758 | const std::unique_lock lock(hwc_->GetResMan().GetMainLock()); |
| 759 | HwcDisplay* display = GetDisplay(display_id); |
| 760 | if (display == nullptr) { |
| 761 | return ToBinderStatus(hwc3::Error::kBadDisplay); |
| 762 | } |
Dennis Tsiang | 33f0ece | 2023-11-29 12:45:04 +0000 | [diff] [blame] | 763 | |
Drew Davenport | 5951b11 | 2024-08-05 09:44:27 -0600 | [diff] [blame] | 764 | uint32_t num_capabilities = 0; |
| 765 | hwc3::Error error = Hwc2toHwc3Error( |
| 766 | display->GetDisplayCapabilities(&num_capabilities, nullptr)); |
| 767 | if (error != hwc3::Error::kNone) { |
| 768 | return ToBinderStatus(error); |
| 769 | } |
| 770 | |
| 771 | std::vector<uint32_t> out_caps(num_capabilities); |
| 772 | error = Hwc2toHwc3Error( |
| 773 | display->GetDisplayCapabilities(&num_capabilities, out_caps.data())); |
| 774 | if (error != hwc3::Error::kNone) { |
| 775 | return ToBinderStatus(error); |
| 776 | } |
| 777 | |
| 778 | caps->reserve(num_capabilities); |
| 779 | for (const auto cap : out_caps) { |
| 780 | caps->emplace_back(Hwc2DisplayCapabilityToHwc3(cap)); |
| 781 | } |
Dennis Tsiang | 33f0ece | 2023-11-29 12:45:04 +0000 | [diff] [blame] | 782 | return ndk::ScopedAStatus::ok(); |
| 783 | } |
| 784 | |
| 785 | ndk::ScopedAStatus ComposerClient::getDisplayConfigs( |
Drew Davenport | 1afb579 | 2024-09-24 12:53:22 -0600 | [diff] [blame] | 786 | int64_t display_id, std::vector<int32_t>* out_configs) { |
Dennis Tsiang | 33f0ece | 2023-11-29 12:45:04 +0000 | [diff] [blame] | 787 | DEBUG_FUNC(); |
Drew Davenport | 5951b11 | 2024-08-05 09:44:27 -0600 | [diff] [blame] | 788 | const std::unique_lock lock(hwc_->GetResMan().GetMainLock()); |
| 789 | HwcDisplay* display = GetDisplay(display_id); |
| 790 | if (display == nullptr) { |
| 791 | return ToBinderStatus(hwc3::Error::kBadDisplay); |
| 792 | } |
| 793 | |
Drew Davenport | 1afb579 | 2024-09-24 12:53:22 -0600 | [diff] [blame] | 794 | const HwcDisplayConfigs& configs = display->GetDisplayConfigs(); |
| 795 | for (const auto& [id, config] : configs.hwc_configs) { |
| 796 | out_configs->push_back(static_cast<int32_t>(id)); |
Drew Davenport | 5951b11 | 2024-08-05 09:44:27 -0600 | [diff] [blame] | 797 | } |
Dennis Tsiang | 33f0ece | 2023-11-29 12:45:04 +0000 | [diff] [blame] | 798 | return ndk::ScopedAStatus::ok(); |
| 799 | } |
| 800 | |
| 801 | ndk::ScopedAStatus ComposerClient::getDisplayConnectionType( |
Drew Davenport | 5951b11 | 2024-08-05 09:44:27 -0600 | [diff] [blame] | 802 | int64_t display_id, DisplayConnectionType* type) { |
Dennis Tsiang | 33f0ece | 2023-11-29 12:45:04 +0000 | [diff] [blame] | 803 | DEBUG_FUNC(); |
Drew Davenport | 5951b11 | 2024-08-05 09:44:27 -0600 | [diff] [blame] | 804 | const std::unique_lock lock(hwc_->GetResMan().GetMainLock()); |
| 805 | HwcDisplay* display = GetDisplay(display_id); |
| 806 | if (display == nullptr) { |
| 807 | return ToBinderStatus(hwc3::Error::kBadDisplay); |
| 808 | } |
| 809 | |
| 810 | uint32_t out_type = 0; |
| 811 | const hwc3::Error error = Hwc2toHwc3Error( |
| 812 | display->GetDisplayConnectionType(&out_type)); |
| 813 | if (error != hwc3::Error::kNone) { |
| 814 | return ToBinderStatus(error); |
| 815 | } |
| 816 | |
| 817 | *type = Hwc2DisplayConnectionTypeToHwc3(out_type); |
Dennis Tsiang | 33f0ece | 2023-11-29 12:45:04 +0000 | [diff] [blame] | 818 | return ndk::ScopedAStatus::ok(); |
| 819 | } |
| 820 | |
| 821 | ndk::ScopedAStatus ComposerClient::getDisplayIdentificationData( |
Drew Davenport | 5951b11 | 2024-08-05 09:44:27 -0600 | [diff] [blame] | 822 | int64_t display_id, DisplayIdentification* id) { |
Dennis Tsiang | 33f0ece | 2023-11-29 12:45:04 +0000 | [diff] [blame] | 823 | DEBUG_FUNC(); |
Drew Davenport | 5951b11 | 2024-08-05 09:44:27 -0600 | [diff] [blame] | 824 | const std::unique_lock lock(hwc_->GetResMan().GetMainLock()); |
| 825 | HwcDisplay* display = GetDisplay(display_id); |
| 826 | if (display == nullptr) { |
| 827 | return ToBinderStatus(hwc3::Error::kBadDisplay); |
| 828 | } |
| 829 | |
| 830 | uint8_t port = 0; |
| 831 | uint32_t data_size = 0; |
| 832 | hwc3::Error error = Hwc2toHwc3Error( |
| 833 | display->GetDisplayIdentificationData(&port, &data_size, nullptr)); |
| 834 | if (error != hwc3::Error::kNone) { |
| 835 | return ToBinderStatus(error); |
| 836 | } |
| 837 | |
| 838 | id->data.resize(data_size); |
| 839 | error = Hwc2toHwc3Error( |
| 840 | display->GetDisplayIdentificationData(&port, &data_size, |
| 841 | id->data.data())); |
| 842 | if (error != hwc3::Error::kNone) { |
| 843 | return ToBinderStatus(error); |
| 844 | } |
| 845 | |
| 846 | id->port = static_cast<int8_t>(port); |
Dennis Tsiang | 33f0ece | 2023-11-29 12:45:04 +0000 | [diff] [blame] | 847 | return ndk::ScopedAStatus::ok(); |
| 848 | } |
| 849 | |
Drew Davenport | 5951b11 | 2024-08-05 09:44:27 -0600 | [diff] [blame] | 850 | ndk::ScopedAStatus ComposerClient::getDisplayName(int64_t display_id, |
| 851 | std::string* name) { |
Dennis Tsiang | 33f0ece | 2023-11-29 12:45:04 +0000 | [diff] [blame] | 852 | DEBUG_FUNC(); |
Drew Davenport | 5951b11 | 2024-08-05 09:44:27 -0600 | [diff] [blame] | 853 | const std::unique_lock lock(hwc_->GetResMan().GetMainLock()); |
| 854 | HwcDisplay* display = GetDisplay(display_id); |
| 855 | if (display == nullptr) { |
| 856 | return ToBinderStatus(hwc3::Error::kBadDisplay); |
| 857 | } |
| 858 | |
| 859 | uint32_t size = 0; |
| 860 | auto error = Hwc2toHwc3Error(display->GetDisplayName(&size, nullptr)); |
| 861 | if (error != hwc3::Error::kNone) { |
| 862 | return ToBinderStatus(error); |
| 863 | } |
| 864 | |
| 865 | name->resize(size); |
| 866 | error = Hwc2toHwc3Error(display->GetDisplayName(&size, name->data())); |
| 867 | return ToBinderStatus(error); |
Dennis Tsiang | 33f0ece | 2023-11-29 12:45:04 +0000 | [diff] [blame] | 868 | } |
| 869 | |
| 870 | ndk::ScopedAStatus ComposerClient::getDisplayVsyncPeriod( |
Drew Davenport | 5951b11 | 2024-08-05 09:44:27 -0600 | [diff] [blame] | 871 | int64_t display_id, int32_t* vsync_period) { |
Dennis Tsiang | 33f0ece | 2023-11-29 12:45:04 +0000 | [diff] [blame] | 872 | DEBUG_FUNC(); |
Drew Davenport | 5951b11 | 2024-08-05 09:44:27 -0600 | [diff] [blame] | 873 | const std::unique_lock lock(hwc_->GetResMan().GetMainLock()); |
| 874 | HwcDisplay* display = GetDisplay(display_id); |
| 875 | if (display == nullptr) { |
| 876 | return ToBinderStatus(hwc3::Error::kBadDisplay); |
| 877 | } |
| 878 | |
| 879 | uint32_t hwc2_vsync_period = 0; |
| 880 | auto error = Hwc2toHwc3Error( |
| 881 | display->GetDisplayVsyncPeriod(&hwc2_vsync_period)); |
| 882 | if (error != hwc3::Error::kNone) { |
| 883 | return ToBinderStatus(error); |
| 884 | } |
| 885 | |
| 886 | *vsync_period = static_cast<int32_t>(hwc2_vsync_period); |
Dennis Tsiang | 33f0ece | 2023-11-29 12:45:04 +0000 | [diff] [blame] | 887 | return ndk::ScopedAStatus::ok(); |
| 888 | } |
| 889 | |
| 890 | ndk::ScopedAStatus ComposerClient::getDisplayedContentSample( |
Drew Davenport | 5951b11 | 2024-08-05 09:44:27 -0600 | [diff] [blame] | 891 | int64_t /*display_id*/, int64_t /*max_frames*/, int64_t /*timestamp*/, |
Dennis Tsiang | 33f0ece | 2023-11-29 12:45:04 +0000 | [diff] [blame] | 892 | DisplayContentSample* /*samples*/) { |
| 893 | DEBUG_FUNC(); |
Drew Davenport | 5951b11 | 2024-08-05 09:44:27 -0600 | [diff] [blame] | 894 | return ToBinderStatus(hwc3::Error::kUnsupported); |
Dennis Tsiang | 33f0ece | 2023-11-29 12:45:04 +0000 | [diff] [blame] | 895 | } |
| 896 | |
| 897 | ndk::ScopedAStatus ComposerClient::getDisplayedContentSamplingAttributes( |
Drew Davenport | 5951b11 | 2024-08-05 09:44:27 -0600 | [diff] [blame] | 898 | int64_t /*display_id*/, DisplayContentSamplingAttributes* /*attrs*/) { |
Dennis Tsiang | 33f0ece | 2023-11-29 12:45:04 +0000 | [diff] [blame] | 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::getDisplayPhysicalOrientation( |
Drew Davenport | 5951b11 | 2024-08-05 09:44:27 -0600 | [diff] [blame] | 904 | int64_t display_id, common::Transform* orientation) { |
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 | const std::unique_lock lock(hwc_->GetResMan().GetMainLock()); |
| 907 | HwcDisplay* display = GetDisplay(display_id); |
| 908 | if (display == nullptr) { |
| 909 | return ToBinderStatus(hwc3::Error::kBadDisplay); |
| 910 | } |
| 911 | |
| 912 | *orientation = common::Transform::NONE; |
Dennis Tsiang | 33f0ece | 2023-11-29 12:45:04 +0000 | [diff] [blame] | 913 | return ndk::ScopedAStatus::ok(); |
| 914 | } |
| 915 | |
Drew Davenport | 5951b11 | 2024-08-05 09:44:27 -0600 | [diff] [blame] | 916 | ndk::ScopedAStatus ComposerClient::getHdrCapabilities(int64_t display_id, |
| 917 | HdrCapabilities* caps) { |
Dennis Tsiang | 33f0ece | 2023-11-29 12:45:04 +0000 | [diff] [blame] | 918 | DEBUG_FUNC(); |
Drew Davenport | 5951b11 | 2024-08-05 09:44:27 -0600 | [diff] [blame] | 919 | const std::unique_lock lock(hwc_->GetResMan().GetMainLock()); |
| 920 | HwcDisplay* display = GetDisplay(display_id); |
| 921 | if (display == nullptr) { |
| 922 | return ToBinderStatus(hwc3::Error::kBadDisplay); |
| 923 | } |
| 924 | |
| 925 | /* No HDR capabilities */ |
| 926 | caps->types.clear(); |
Dennis Tsiang | 33f0ece | 2023-11-29 12:45:04 +0000 | [diff] [blame] | 927 | return ndk::ScopedAStatus::ok(); |
| 928 | } |
| 929 | |
Drew Davenport | 5951b11 | 2024-08-05 09:44:27 -0600 | [diff] [blame] | 930 | ndk::ScopedAStatus ComposerClient::getMaxVirtualDisplayCount(int32_t* count) { |
Dennis Tsiang | 33f0ece | 2023-11-29 12:45:04 +0000 | [diff] [blame] | 931 | DEBUG_FUNC(); |
Drew Davenport | 5951b11 | 2024-08-05 09:44:27 -0600 | [diff] [blame] | 932 | const std::unique_lock lock(hwc_->GetResMan().GetMainLock()); |
| 933 | *count = static_cast<int32_t>(hwc_->GetMaxVirtualDisplayCount()); |
Dennis Tsiang | 33f0ece | 2023-11-29 12:45:04 +0000 | [diff] [blame] | 934 | return ndk::ScopedAStatus::ok(); |
| 935 | } |
| 936 | |
| 937 | ndk::ScopedAStatus ComposerClient::getPerFrameMetadataKeys( |
Drew Davenport | 5951b11 | 2024-08-05 09:44:27 -0600 | [diff] [blame] | 938 | int64_t /*display_id*/, std::vector<PerFrameMetadataKey>* /*keys*/) { |
Dennis Tsiang | 33f0ece | 2023-11-29 12:45:04 +0000 | [diff] [blame] | 939 | DEBUG_FUNC(); |
Drew Davenport | 5951b11 | 2024-08-05 09:44:27 -0600 | [diff] [blame] | 940 | return ToBinderStatus(hwc3::Error::kUnsupported); |
Dennis Tsiang | 33f0ece | 2023-11-29 12:45:04 +0000 | [diff] [blame] | 941 | } |
| 942 | |
| 943 | ndk::ScopedAStatus ComposerClient::getReadbackBufferAttributes( |
Drew Davenport | 5951b11 | 2024-08-05 09:44:27 -0600 | [diff] [blame] | 944 | int64_t /*display_id*/, ReadbackBufferAttributes* /*attrs*/) { |
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::getReadbackBufferFence( |
Drew Davenport | 5951b11 | 2024-08-05 09:44:27 -0600 | [diff] [blame] | 950 | int64_t /*display_id*/, ndk::ScopedFileDescriptor* /*acquireFence*/) { |
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::getRenderIntents( |
Drew Davenport | 5951b11 | 2024-08-05 09:44:27 -0600 | [diff] [blame] | 956 | int64_t display_id, ColorMode mode, std::vector<RenderIntent>* intents) { |
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 | const std::unique_lock lock(hwc_->GetResMan().GetMainLock()); |
| 959 | HwcDisplay* display = GetDisplay(display_id); |
| 960 | if (display == nullptr) { |
| 961 | return ToBinderStatus(hwc3::Error::kBadDisplay); |
| 962 | } |
| 963 | |
| 964 | const int32_t hwc2_color_mode = Hwc3ColorModeToHwc2(mode); |
| 965 | uint32_t out_num_intents = 0; |
| 966 | auto error = Hwc2toHwc3Error( |
| 967 | display->GetRenderIntents(hwc2_color_mode, &out_num_intents, nullptr)); |
| 968 | if (error != hwc3::Error::kNone) { |
| 969 | return ToBinderStatus(error); |
| 970 | } |
| 971 | |
| 972 | std::vector<int32_t> out_intents(out_num_intents); |
| 973 | error = Hwc2toHwc3Error(display->GetRenderIntents(hwc2_color_mode, |
| 974 | &out_num_intents, |
| 975 | out_intents.data())); |
| 976 | if (error != hwc3::Error::kNone) { |
| 977 | return ToBinderStatus(error); |
| 978 | } |
| 979 | |
| 980 | intents->reserve(out_num_intents); |
| 981 | for (const auto intent : out_intents) { |
| 982 | intents->emplace_back(Hwc2RenderIntentToHwc3(intent)); |
| 983 | } |
Dennis Tsiang | 33f0ece | 2023-11-29 12:45:04 +0000 | [diff] [blame] | 984 | return ndk::ScopedAStatus::ok(); |
| 985 | } |
| 986 | |
| 987 | ndk::ScopedAStatus ComposerClient::getSupportedContentTypes( |
Drew Davenport | 5951b11 | 2024-08-05 09:44:27 -0600 | [diff] [blame] | 988 | int64_t display_id, std::vector<ContentType>* types) { |
Dennis Tsiang | 33f0ece | 2023-11-29 12:45:04 +0000 | [diff] [blame] | 989 | DEBUG_FUNC(); |
Drew Davenport | 5951b11 | 2024-08-05 09:44:27 -0600 | [diff] [blame] | 990 | const std::unique_lock lock(hwc_->GetResMan().GetMainLock()); |
| 991 | HwcDisplay* display = GetDisplay(display_id); |
| 992 | if (display == nullptr) { |
| 993 | return ToBinderStatus(hwc3::Error::kBadDisplay); |
| 994 | } |
| 995 | |
Drew Davenport | 8d38dc7 | 2024-09-24 12:26:07 -0600 | [diff] [blame] | 996 | // Support for ContentType is not implemented. |
| 997 | types->clear(); |
Dennis Tsiang | 33f0ece | 2023-11-29 12:45:04 +0000 | [diff] [blame] | 998 | return ndk::ScopedAStatus::ok(); |
| 999 | } |
| 1000 | |
| 1001 | ndk::ScopedAStatus ComposerClient::getDisplayDecorationSupport( |
Drew Davenport | 5951b11 | 2024-08-05 09:44:27 -0600 | [diff] [blame] | 1002 | int64_t /*display_id*/, |
| 1003 | std::optional<common::DisplayDecorationSupport>* /*support_struct*/) { |
Dennis Tsiang | 33f0ece | 2023-11-29 12:45:04 +0000 | [diff] [blame] | 1004 | DEBUG_FUNC(); |
Drew Davenport | 5951b11 | 2024-08-05 09:44:27 -0600 | [diff] [blame] | 1005 | return ToBinderStatus(hwc3::Error::kUnsupported); |
Dennis Tsiang | 33f0ece | 2023-11-29 12:45:04 +0000 | [diff] [blame] | 1006 | } |
| 1007 | |
| 1008 | ndk::ScopedAStatus ComposerClient::registerCallback( |
Drew Davenport | 5951b11 | 2024-08-05 09:44:27 -0600 | [diff] [blame] | 1009 | const std::shared_ptr<IComposerCallback>& callback) { |
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 | const std::unique_lock lock(hwc_->GetResMan().GetMainLock()); |
| 1012 | // This function is specified to be called exactly once. |
| 1013 | hwc_->Init(callback); |
Dennis Tsiang | 33f0ece | 2023-11-29 12:45:04 +0000 | [diff] [blame] | 1014 | return ndk::ScopedAStatus::ok(); |
| 1015 | } |
| 1016 | |
Drew Davenport | 5951b11 | 2024-08-05 09:44:27 -0600 | [diff] [blame] | 1017 | ndk::ScopedAStatus ComposerClient::setActiveConfig(int64_t display_id, |
| 1018 | int32_t config) { |
Dennis Tsiang | 33f0ece | 2023-11-29 12:45:04 +0000 | [diff] [blame] | 1019 | DEBUG_FUNC(); |
Drew Davenport | 5951b11 | 2024-08-05 09:44:27 -0600 | [diff] [blame] | 1020 | const std::unique_lock lock(hwc_->GetResMan().GetMainLock()); |
| 1021 | HwcDisplay* display = GetDisplay(display_id); |
| 1022 | if (display == nullptr) { |
| 1023 | return ToBinderStatus(hwc3::Error::kBadDisplay); |
| 1024 | } |
| 1025 | |
| 1026 | return ToBinderStatus(Hwc2toHwc3Error(display->SetActiveConfig(config))); |
Dennis Tsiang | 33f0ece | 2023-11-29 12:45:04 +0000 | [diff] [blame] | 1027 | } |
| 1028 | |
| 1029 | ndk::ScopedAStatus ComposerClient::setActiveConfigWithConstraints( |
Drew Davenport | 5951b11 | 2024-08-05 09:44:27 -0600 | [diff] [blame] | 1030 | int64_t display_id, int32_t config, |
| 1031 | const VsyncPeriodChangeConstraints& constraints, |
| 1032 | VsyncPeriodChangeTimeline* timeline) { |
Dennis Tsiang | 33f0ece | 2023-11-29 12:45:04 +0000 | [diff] [blame] | 1033 | DEBUG_FUNC(); |
Drew Davenport | 5951b11 | 2024-08-05 09:44:27 -0600 | [diff] [blame] | 1034 | const std::unique_lock lock(hwc_->GetResMan().GetMainLock()); |
| 1035 | HwcDisplay* display = GetDisplay(display_id); |
| 1036 | if (display == nullptr) { |
| 1037 | return ToBinderStatus(hwc3::Error::kBadDisplay); |
| 1038 | } |
| 1039 | |
| 1040 | hwc_vsync_period_change_constraints_t hwc2_constraints; |
| 1041 | hwc2_constraints.desiredTimeNanos = constraints.desiredTimeNanos; |
| 1042 | hwc2_constraints.seamlessRequired = static_cast<uint8_t>( |
| 1043 | constraints.seamlessRequired); |
| 1044 | |
| 1045 | hwc_vsync_period_change_timeline_t hwc2_timeline{}; |
| 1046 | auto error = Hwc2toHwc3Error( |
| 1047 | display->SetActiveConfigWithConstraints(config, &hwc2_constraints, |
| 1048 | &hwc2_timeline)); |
| 1049 | if (error != hwc3::Error::kNone) { |
| 1050 | return ToBinderStatus(error); |
| 1051 | } |
| 1052 | |
| 1053 | timeline->refreshTimeNanos = hwc2_timeline.refreshTimeNanos; |
| 1054 | timeline->newVsyncAppliedTimeNanos = hwc2_timeline.newVsyncAppliedTimeNanos; |
| 1055 | timeline->refreshRequired = static_cast<bool>(hwc2_timeline.refreshRequired); |
Dennis Tsiang | 33f0ece | 2023-11-29 12:45:04 +0000 | [diff] [blame] | 1056 | return ndk::ScopedAStatus::ok(); |
| 1057 | } |
| 1058 | |
Drew Davenport | 5951b11 | 2024-08-05 09:44:27 -0600 | [diff] [blame] | 1059 | ndk::ScopedAStatus ComposerClient::setBootDisplayConfig(int64_t /*display_id*/, |
Dennis Tsiang | 33f0ece | 2023-11-29 12:45:04 +0000 | [diff] [blame] | 1060 | int32_t /*config*/) { |
| 1061 | DEBUG_FUNC(); |
Drew Davenport | 5951b11 | 2024-08-05 09:44:27 -0600 | [diff] [blame] | 1062 | return ToBinderStatus(hwc3::Error::kUnsupported); |
Dennis Tsiang | 33f0ece | 2023-11-29 12:45:04 +0000 | [diff] [blame] | 1063 | } |
| 1064 | |
Drew Davenport | 5951b11 | 2024-08-05 09:44:27 -0600 | [diff] [blame] | 1065 | ndk::ScopedAStatus ComposerClient::clearBootDisplayConfig( |
| 1066 | int64_t /*display_id*/) { |
Dennis Tsiang | 33f0ece | 2023-11-29 12:45:04 +0000 | [diff] [blame] | 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 | |
| 1071 | ndk::ScopedAStatus ComposerClient::getPreferredBootDisplayConfig( |
Drew Davenport | 5951b11 | 2024-08-05 09:44:27 -0600 | [diff] [blame] | 1072 | int64_t /*display_id*/, int32_t* /*config*/) { |
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 | |
Drew Davenport | 5951b11 | 2024-08-05 09:44:27 -0600 | [diff] [blame] | 1077 | ndk::ScopedAStatus ComposerClient::setAutoLowLatencyMode(int64_t display_id, |
| 1078 | bool on) { |
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 | const std::unique_lock lock(hwc_->GetResMan().GetMainLock()); |
| 1081 | HwcDisplay* display = GetDisplay(display_id); |
| 1082 | if (display == nullptr) { |
| 1083 | return ToBinderStatus(hwc3::Error::kBadDisplay); |
| 1084 | } |
| 1085 | |
| 1086 | auto error = Hwc2toHwc3Error(display->SetAutoLowLatencyMode(on)); |
| 1087 | return ToBinderStatus(error); |
Dennis Tsiang | 33f0ece | 2023-11-29 12:45:04 +0000 | [diff] [blame] | 1088 | } |
| 1089 | |
Drew Davenport | 5951b11 | 2024-08-05 09:44:27 -0600 | [diff] [blame] | 1090 | ndk::ScopedAStatus ComposerClient::setClientTargetSlotCount(int64_t display_id, |
| 1091 | int32_t count) { |
Dennis Tsiang | 33f0ece | 2023-11-29 12:45:04 +0000 | [diff] [blame] | 1092 | DEBUG_FUNC(); |
Drew Davenport | 5951b11 | 2024-08-05 09:44:27 -0600 | [diff] [blame] | 1093 | return ToBinderStatus( |
| 1094 | composer_resources_->SetDisplayClientTargetCacheSize(display_id, count)); |
Dennis Tsiang | 33f0ece | 2023-11-29 12:45:04 +0000 | [diff] [blame] | 1095 | } |
| 1096 | |
Drew Davenport | 5951b11 | 2024-08-05 09:44:27 -0600 | [diff] [blame] | 1097 | ndk::ScopedAStatus ComposerClient::setColorMode(int64_t display_id, |
| 1098 | ColorMode mode, |
| 1099 | RenderIntent intent) { |
Dennis Tsiang | 33f0ece | 2023-11-29 12:45:04 +0000 | [diff] [blame] | 1100 | DEBUG_FUNC(); |
Drew Davenport | 5951b11 | 2024-08-05 09:44:27 -0600 | [diff] [blame] | 1101 | const std::unique_lock lock(hwc_->GetResMan().GetMainLock()); |
| 1102 | HwcDisplay* display = GetDisplay(display_id); |
| 1103 | if (display == nullptr) { |
| 1104 | return ToBinderStatus(hwc3::Error::kBadDisplay); |
| 1105 | } |
| 1106 | |
| 1107 | auto error = display->SetColorModeWithIntent(Hwc3ColorModeToHwc2(mode), |
| 1108 | Hwc3RenderIntentToHwc2(intent)); |
| 1109 | return ToBinderStatus(Hwc2toHwc3Error(error)); |
Dennis Tsiang | 33f0ece | 2023-11-29 12:45:04 +0000 | [diff] [blame] | 1110 | } |
| 1111 | |
Drew Davenport | 5951b11 | 2024-08-05 09:44:27 -0600 | [diff] [blame] | 1112 | ndk::ScopedAStatus ComposerClient::setContentType(int64_t display_id, |
| 1113 | ContentType type) { |
Dennis Tsiang | 33f0ece | 2023-11-29 12:45:04 +0000 | [diff] [blame] | 1114 | DEBUG_FUNC(); |
Drew Davenport | 5951b11 | 2024-08-05 09:44:27 -0600 | [diff] [blame] | 1115 | const std::unique_lock lock(hwc_->GetResMan().GetMainLock()); |
| 1116 | HwcDisplay* display = GetDisplay(display_id); |
| 1117 | if (display == nullptr) { |
| 1118 | return ToBinderStatus(hwc3::Error::kBadDisplay); |
| 1119 | } |
| 1120 | |
Drew Davenport | 8d38dc7 | 2024-09-24 12:26:07 -0600 | [diff] [blame] | 1121 | if (type == ContentType::NONE) { |
| 1122 | return ndk::ScopedAStatus::ok(); |
| 1123 | } |
| 1124 | return ToBinderStatus(hwc3::Error::kUnsupported); |
Dennis Tsiang | 33f0ece | 2023-11-29 12:45:04 +0000 | [diff] [blame] | 1125 | } |
| 1126 | |
| 1127 | ndk::ScopedAStatus ComposerClient::setDisplayedContentSamplingEnabled( |
Drew Davenport | 5951b11 | 2024-08-05 09:44:27 -0600 | [diff] [blame] | 1128 | int64_t /*display_id*/, bool /*enable*/, |
Dennis Tsiang | 33f0ece | 2023-11-29 12:45:04 +0000 | [diff] [blame] | 1129 | FormatColorComponent /*componentMask*/, int64_t /*maxFrames*/) { |
| 1130 | DEBUG_FUNC(); |
Drew Davenport | 5951b11 | 2024-08-05 09:44:27 -0600 | [diff] [blame] | 1131 | return ToBinderStatus(hwc3::Error::kUnsupported); |
Dennis Tsiang | 33f0ece | 2023-11-29 12:45:04 +0000 | [diff] [blame] | 1132 | } |
| 1133 | |
Drew Davenport | 5951b11 | 2024-08-05 09:44:27 -0600 | [diff] [blame] | 1134 | ndk::ScopedAStatus ComposerClient::setPowerMode(int64_t display_id, |
| 1135 | PowerMode mode) { |
Dennis Tsiang | 33f0ece | 2023-11-29 12:45:04 +0000 | [diff] [blame] | 1136 | DEBUG_FUNC(); |
Drew Davenport | 5951b11 | 2024-08-05 09:44:27 -0600 | [diff] [blame] | 1137 | const std::unique_lock lock(hwc_->GetResMan().GetMainLock()); |
| 1138 | HwcDisplay* display = GetDisplay(display_id); |
| 1139 | if (display == nullptr) { |
| 1140 | return ToBinderStatus(hwc3::Error::kBadDisplay); |
| 1141 | } |
| 1142 | |
Dennis Tsiang | 1a96620 | 2024-01-24 12:46:33 +0000 | [diff] [blame] | 1143 | if (mode == PowerMode::ON_SUSPEND) { |
| 1144 | return ToBinderStatus(hwc3::Error::kUnsupported); |
| 1145 | } |
| 1146 | |
Drew Davenport | 5951b11 | 2024-08-05 09:44:27 -0600 | [diff] [blame] | 1147 | auto error = display->SetPowerMode(Hwc3PowerModeToHwc2(mode)); |
| 1148 | return ToBinderStatus(Hwc2toHwc3Error(error)); |
Dennis Tsiang | 33f0ece | 2023-11-29 12:45:04 +0000 | [diff] [blame] | 1149 | } |
| 1150 | |
| 1151 | ndk::ScopedAStatus ComposerClient::setReadbackBuffer( |
Drew Davenport | 5951b11 | 2024-08-05 09:44:27 -0600 | [diff] [blame] | 1152 | int64_t /*display_id*/, const AidlNativeHandle& /*aidlBuffer*/, |
Dennis Tsiang | 33f0ece | 2023-11-29 12:45:04 +0000 | [diff] [blame] | 1153 | const ndk::ScopedFileDescriptor& /*releaseFence*/) { |
| 1154 | DEBUG_FUNC(); |
Drew Davenport | 5951b11 | 2024-08-05 09:44:27 -0600 | [diff] [blame] | 1155 | return ToBinderStatus(hwc3::Error::kUnsupported); |
Dennis Tsiang | 33f0ece | 2023-11-29 12:45:04 +0000 | [diff] [blame] | 1156 | } |
| 1157 | |
Drew Davenport | 5951b11 | 2024-08-05 09:44:27 -0600 | [diff] [blame] | 1158 | ndk::ScopedAStatus ComposerClient::setVsyncEnabled(int64_t display_id, |
| 1159 | bool enabled) { |
Dennis Tsiang | 33f0ece | 2023-11-29 12:45:04 +0000 | [diff] [blame] | 1160 | DEBUG_FUNC(); |
Drew Davenport | 5951b11 | 2024-08-05 09:44:27 -0600 | [diff] [blame] | 1161 | const std::unique_lock lock(hwc_->GetResMan().GetMainLock()); |
| 1162 | HwcDisplay* display = GetDisplay(display_id); |
| 1163 | if (display == nullptr) { |
| 1164 | return ToBinderStatus(hwc3::Error::kBadDisplay); |
| 1165 | } |
| 1166 | |
| 1167 | auto error = display->SetVsyncEnabled(static_cast<int32_t>(enabled)); |
| 1168 | return ToBinderStatus(Hwc2toHwc3Error(error)); |
Dennis Tsiang | 33f0ece | 2023-11-29 12:45:04 +0000 | [diff] [blame] | 1169 | } |
| 1170 | |
Drew Davenport | 5951b11 | 2024-08-05 09:44:27 -0600 | [diff] [blame] | 1171 | ndk::ScopedAStatus ComposerClient::setIdleTimerEnabled(int64_t /*display_id*/, |
Dennis Tsiang | 33f0ece | 2023-11-29 12:45:04 +0000 | [diff] [blame] | 1172 | int32_t /*timeout*/) { |
| 1173 | DEBUG_FUNC(); |
Drew Davenport | 5951b11 | 2024-08-05 09:44:27 -0600 | [diff] [blame] | 1174 | return ToBinderStatus(hwc3::Error::kUnsupported); |
| 1175 | } |
| 1176 | |
Drew Davenport | 7f1761b | 2024-08-20 10:09:43 -0600 | [diff] [blame] | 1177 | ndk::ScopedAStatus ComposerClient::getOverlaySupport( |
| 1178 | OverlayProperties* /*out_overlay_properties*/) { |
| 1179 | return ToBinderStatus(hwc3::Error::kUnsupported); |
| 1180 | } |
| 1181 | |
| 1182 | ndk::ScopedAStatus ComposerClient::getHdrConversionCapabilities( |
| 1183 | std::vector<common::HdrConversionCapability>* /*out_capabilities*/) { |
| 1184 | return ToBinderStatus(hwc3::Error::kUnsupported); |
| 1185 | } |
| 1186 | |
| 1187 | ndk::ScopedAStatus ComposerClient::setHdrConversionStrategy( |
| 1188 | const common::HdrConversionStrategy& /*conversion_strategy*/, |
| 1189 | common::Hdr* /*out_hdr*/) { |
| 1190 | return ToBinderStatus(hwc3::Error::kUnsupported); |
| 1191 | } |
| 1192 | |
| 1193 | ndk::ScopedAStatus ComposerClient::setRefreshRateChangedCallbackDebugEnabled( |
| 1194 | int64_t /*display*/, bool /*enabled*/) { |
| 1195 | return ToBinderStatus(hwc3::Error::kUnsupported); |
| 1196 | } |
| 1197 | |
Roman Stratiienko | 71a8f02 | 2024-10-16 23:17:33 +0300 | [diff] [blame^] | 1198 | #if __ANDROID_API__ >= 35 |
| 1199 | |
Drew Davenport | 7f1761b | 2024-08-20 10:09:43 -0600 | [diff] [blame] | 1200 | ndk::ScopedAStatus ComposerClient::getDisplayConfigurations( |
Drew Davenport | f7e8833 | 2024-09-06 12:54:38 -0600 | [diff] [blame] | 1201 | int64_t display_id, int32_t /*max_frame_interval_ns*/, |
Drew Davenport | 7f1761b | 2024-08-20 10:09:43 -0600 | [diff] [blame] | 1202 | std::vector<DisplayConfiguration>* configurations) { |
Drew Davenport | f7e8833 | 2024-09-06 12:54:38 -0600 | [diff] [blame] | 1203 | DEBUG_FUNC(); |
| 1204 | const std::unique_lock lock(hwc_->GetResMan().GetMainLock()); |
| 1205 | HwcDisplay* display = GetDisplay(display_id); |
| 1206 | if (display == nullptr) { |
| 1207 | return ToBinderStatus(hwc3::Error::kBadDisplay); |
| 1208 | } |
| 1209 | |
| 1210 | const HwcDisplayConfigs& configs = display->GetDisplayConfigs(); |
| 1211 | for (const auto& [id, config] : configs.hwc_configs) { |
Drew Davenport | 1afb579 | 2024-09-24 12:53:22 -0600 | [diff] [blame] | 1212 | configurations->push_back( |
| 1213 | HwcDisplayConfigToAidlConfiguration(configs, config)); |
Drew Davenport | f7e8833 | 2024-09-06 12:54:38 -0600 | [diff] [blame] | 1214 | } |
| 1215 | return ndk::ScopedAStatus::ok(); |
Drew Davenport | 7f1761b | 2024-08-20 10:09:43 -0600 | [diff] [blame] | 1216 | } |
| 1217 | |
| 1218 | ndk::ScopedAStatus ComposerClient::notifyExpectedPresent( |
| 1219 | int64_t /*display*/, const ClockMonotonicTimestamp& /*expected_present_time*/, |
| 1220 | int32_t /*frame_interval_ns*/) { |
| 1221 | return ToBinderStatus(hwc3::Error::kUnsupported); |
| 1222 | } |
| 1223 | |
Roman Stratiienko | 71a8f02 | 2024-10-16 23:17:33 +0300 | [diff] [blame^] | 1224 | #endif |
| 1225 | |
Drew Davenport | 5951b11 | 2024-08-05 09:44:27 -0600 | [diff] [blame] | 1226 | std::string ComposerClient::Dump() { |
| 1227 | uint32_t size = 0; |
| 1228 | hwc_->Dump(&size, nullptr); |
| 1229 | |
| 1230 | std::string buffer(size, '\0'); |
| 1231 | hwc_->Dump(&size, &buffer.front()); |
| 1232 | return buffer; |
Dennis Tsiang | 33f0ece | 2023-11-29 12:45:04 +0000 | [diff] [blame] | 1233 | } |
| 1234 | |
| 1235 | ::ndk::SpAIBinder ComposerClient::createBinder() { |
| 1236 | auto binder = BnComposerClient::createBinder(); |
| 1237 | AIBinder_setInheritRt(binder.get(), true); |
| 1238 | return binder; |
| 1239 | } |
| 1240 | |
Drew Davenport | 5951b11 | 2024-08-05 09:44:27 -0600 | [diff] [blame] | 1241 | void ComposerClient::ExecuteSetLayerBuffer(int64_t display_id, |
| 1242 | HwcLayerWrapper& layer, |
| 1243 | const Buffer& buffer) { |
| 1244 | buffer_handle_t imported_buffer = nullptr; |
| 1245 | |
| 1246 | auto releaser = composer_resources_->CreateResourceReleaser(true); |
| 1247 | auto err = composer_resources_->GetLayerBuffer(display_id, layer.layer_id, |
| 1248 | buffer, &imported_buffer, |
| 1249 | releaser.get()); |
| 1250 | if (err != hwc3::Error::kNone) { |
| 1251 | cmd_result_writer_->AddError(err); |
| 1252 | return; |
| 1253 | } |
| 1254 | |
| 1255 | // NOLINTNEXTLINE(cppcoreguidelines-pro-type-const-cast) |
| 1256 | auto fence_fd = const_cast<ndk::ScopedFileDescriptor&>(buffer.fence) |
| 1257 | .release(); |
| 1258 | err = Hwc2toHwc3Error(layer.layer->SetLayerBuffer(imported_buffer, fence_fd)); |
| 1259 | if (err != hwc3::Error::kNone) { |
| 1260 | cmd_result_writer_->AddError(err); |
| 1261 | } |
| 1262 | } |
| 1263 | |
Drew Davenport | 5951b11 | 2024-08-05 09:44:27 -0600 | [diff] [blame] | 1264 | void ComposerClient::ExecuteSetDisplayBrightness( |
| 1265 | uint64_t display_id, const DisplayBrightness& command) { |
| 1266 | auto* display = GetDisplay(display_id); |
| 1267 | if (display == nullptr) { |
| 1268 | cmd_result_writer_->AddError(hwc3::Error::kBadDisplay); |
| 1269 | return; |
| 1270 | } |
| 1271 | |
| 1272 | auto error = Hwc2toHwc3Error( |
| 1273 | display->SetDisplayBrightness(command.brightness)); |
| 1274 | if (error != hwc3::Error::kNone) { |
| 1275 | cmd_result_writer_->AddError(error); |
| 1276 | } |
| 1277 | } |
| 1278 | void ComposerClient::ExecuteSetDisplayColorTransform( |
| 1279 | uint64_t display_id, const std::vector<float>& matrix) { |
| 1280 | auto* display = GetDisplay(display_id); |
| 1281 | if (display == nullptr) { |
| 1282 | cmd_result_writer_->AddError(hwc3::Error::kBadDisplay); |
| 1283 | return; |
| 1284 | } |
| 1285 | |
| 1286 | auto almost_equal = [](auto a, auto b) { |
| 1287 | const float epsilon = 0.001F; |
| 1288 | return std::abs(a - b) < epsilon; |
| 1289 | }; |
| 1290 | const bool is_identity = std::equal(matrix.begin(), matrix.end(), |
| 1291 | kIdentityMatrix.begin(), almost_equal); |
| 1292 | |
| 1293 | const int32_t hint = is_identity ? HAL_COLOR_TRANSFORM_IDENTITY |
| 1294 | : HAL_COLOR_TRANSFORM_ARBITRARY_MATRIX; |
| 1295 | |
| 1296 | auto error = Hwc2toHwc3Error(display->SetColorTransform(matrix.data(), hint)); |
| 1297 | if (error != hwc3::Error::kNone) { |
| 1298 | cmd_result_writer_->AddError(error); |
| 1299 | } |
| 1300 | } |
| 1301 | void ComposerClient::ExecuteSetDisplayClientTarget( |
| 1302 | uint64_t display_id, const ClientTarget& command) { |
| 1303 | auto* display = GetDisplay(display_id); |
| 1304 | if (display == nullptr) { |
| 1305 | cmd_result_writer_->AddError(hwc3::Error::kBadDisplay); |
| 1306 | return; |
| 1307 | } |
| 1308 | |
| 1309 | hwc_region_t damage_regions; |
| 1310 | damage_regions.numRects = command.damage.size(); |
| 1311 | |
| 1312 | std::vector<hwc_rect_t> regions(command.damage.size()); |
| 1313 | for (const auto& region : command.damage) { |
| 1314 | regions.push_back({region.left, region.top, region.right, region.bottom}); |
| 1315 | } |
| 1316 | damage_regions.rects = regions.data(); |
| 1317 | |
| 1318 | buffer_handle_t imported_buffer = nullptr; |
| 1319 | auto buf_releaser = composer_resources_->CreateResourceReleaser(true); |
| 1320 | |
| 1321 | auto error = composer_resources_->GetDisplayClientTarget(display_id, |
| 1322 | command.buffer, |
| 1323 | &imported_buffer, |
| 1324 | buf_releaser.get()); |
| 1325 | if (error != hwc3::Error::kNone) { |
| 1326 | cmd_result_writer_->AddError(error); |
| 1327 | return; |
| 1328 | } |
| 1329 | |
| 1330 | // NOLINTNEXTLINE(cppcoreguidelines-pro-type-const-cast) |
| 1331 | auto fence = const_cast<::ndk::ScopedFileDescriptor&>(command.buffer.fence) |
| 1332 | .release(); |
| 1333 | error = Hwc2toHwc3Error( |
| 1334 | display->SetClientTarget(imported_buffer, fence, |
| 1335 | Hwc3DataspaceToHwc2(command.dataspace), |
| 1336 | damage_regions)); |
| 1337 | if (error != hwc3::Error::kNone) { |
| 1338 | cmd_result_writer_->AddError(error); |
| 1339 | } |
| 1340 | } |
| 1341 | |
| 1342 | void ComposerClient::ExecuteSetDisplayOutputBuffer(uint64_t display_id, |
| 1343 | const Buffer& buffer) { |
| 1344 | auto* display = GetDisplay(display_id); |
| 1345 | if (display == nullptr) { |
| 1346 | cmd_result_writer_->AddError(hwc3::Error::kBadDisplay); |
| 1347 | return; |
| 1348 | } |
| 1349 | |
| 1350 | buffer_handle_t imported_buffer = nullptr; |
| 1351 | auto buf_releaser = composer_resources_->CreateResourceReleaser(true); |
| 1352 | |
| 1353 | auto error = composer_resources_->GetDisplayOutputBuffer(display_id, buffer, |
| 1354 | &imported_buffer, |
| 1355 | buf_releaser.get()); |
| 1356 | if (error != hwc3::Error::kNone) { |
| 1357 | cmd_result_writer_->AddError(error); |
| 1358 | return; |
| 1359 | } |
| 1360 | |
| 1361 | // NOLINTNEXTLINE(cppcoreguidelines-pro-type-const-cast) |
| 1362 | auto fence = const_cast<::ndk::ScopedFileDescriptor&>(buffer.fence).release(); |
| 1363 | error = Hwc2toHwc3Error(display->SetOutputBuffer(imported_buffer, fence)); |
| 1364 | if (error != hwc3::Error::kNone) { |
| 1365 | cmd_result_writer_->AddError(error); |
| 1366 | return; |
| 1367 | } |
| 1368 | } |
| 1369 | void ComposerClient::ExecuteValidateDisplay( |
| 1370 | int64_t display_id, |
| 1371 | std::optional<ClockMonotonicTimestamp> /*expected_present_time*/ |
| 1372 | ) { |
| 1373 | auto* display = GetDisplay(display_id); |
| 1374 | if (display == nullptr) { |
| 1375 | cmd_result_writer_->AddError(hwc3::Error::kBadDisplay); |
| 1376 | return; |
| 1377 | } |
| 1378 | |
| 1379 | /* TODO: Handle expectedPresentTime */ |
Normunds Rieksts | 4282095 | 2024-03-12 15:42:06 +0000 | [diff] [blame] | 1380 | /* This can be implemented in multiple ways. For example, the expected present |
| 1381 | * time property can be implemented by the DRM driver directly as a CRTC |
| 1382 | * property. See: |
| 1383 | * https://cs.android.com/android/platform/superproject/main/+/b8b3b1646e64d0235f77b9e717a3e4082e26f2a8:hardware/google/graphics/common/libhwc2.1/libdrmresource/drm/drmcrtc.cpp;drc=468f6172546ab98983de18210222f231f16b21e1;l=88 |
| 1384 | * Unfortunately there doesn't seem to be a standardised way of delaying |
| 1385 | * presentation with a timestamp in the DRM API. What we can do alternatively |
| 1386 | * is to spawn a separate presentation thread that could handle the VBlank |
| 1387 | * events by using DRM_MODE_PAGE_FLIP_EVENT and schedule them appropriately. |
| 1388 | */ |
Drew Davenport | 5951b11 | 2024-08-05 09:44:27 -0600 | [diff] [blame] | 1389 | |
| 1390 | std::vector<int64_t> changed_layers; |
| 1391 | std::vector<Composition> composition_types; |
| 1392 | int32_t display_request_mask = 0; |
| 1393 | std::vector<int64_t> requested_layers; |
| 1394 | std::vector<int32_t> request_masks; |
| 1395 | |
| 1396 | const hwc3::Error error = ValidateDisplayInternal(*display, &changed_layers, |
| 1397 | &composition_types, |
| 1398 | &display_request_mask, |
| 1399 | &requested_layers, |
| 1400 | &request_masks, nullptr, |
| 1401 | nullptr); |
| 1402 | |
| 1403 | if (error != hwc3::Error::kNone) { |
| 1404 | cmd_result_writer_->AddError(error); |
| 1405 | } |
| 1406 | |
| 1407 | // If a CommandError has been been set for the current DisplayCommand, then |
| 1408 | // no other results should be returned besides the error. |
| 1409 | if (cmd_result_writer_->HasError()) { |
| 1410 | return; |
| 1411 | } |
| 1412 | |
| 1413 | DisplayChanges changes{}; |
| 1414 | for (size_t i = 0; i < composition_types.size(); i++) { |
| 1415 | changes.AddLayerCompositionChange(display_id, changed_layers[i], |
| 1416 | composition_types[i]); |
| 1417 | } |
| 1418 | |
| 1419 | std::vector<DisplayRequest::LayerRequest> layer_requests; |
| 1420 | for (size_t i = 0; i < requested_layers.size(); i++) { |
| 1421 | layer_requests.push_back({requested_layers[i], request_masks[i]}); |
| 1422 | } |
| 1423 | |
| 1424 | const DisplayRequest request_changes{display_id, display_request_mask, |
| 1425 | layer_requests}; |
| 1426 | changes.display_request_changes = request_changes; |
| 1427 | |
| 1428 | cmd_result_writer_->AddChanges(changes); |
| 1429 | composer_resources_->SetDisplayMustValidateState(display_id, false); |
| 1430 | } |
| 1431 | |
| 1432 | void ComposerClient::ExecuteAcceptDisplayChanges(int64_t display_id) { |
| 1433 | auto* display = GetDisplay(display_id); |
| 1434 | if (display == nullptr) { |
| 1435 | cmd_result_writer_->AddError(hwc3::Error::kBadDisplay); |
| 1436 | return; |
| 1437 | } |
| 1438 | |
| 1439 | auto error = Hwc2toHwc3Error(display->AcceptDisplayChanges()); |
| 1440 | if (error != hwc3::Error::kNone) { |
| 1441 | cmd_result_writer_->AddError(error); |
| 1442 | return; |
| 1443 | } |
| 1444 | } |
| 1445 | |
| 1446 | void ComposerClient::ExecutePresentDisplay(int64_t display_id) { |
| 1447 | auto* display = GetDisplay(display_id); |
| 1448 | if (display == nullptr) { |
| 1449 | cmd_result_writer_->AddError(hwc3::Error::kBadDisplay); |
| 1450 | return; |
| 1451 | } |
| 1452 | |
| 1453 | ::android::base::unique_fd display_fence; |
| 1454 | std::unordered_map<int64_t, ::android::base::unique_fd> release_fences; |
| 1455 | auto error = PresentDisplayInternal(display_id, display_fence, |
| 1456 | release_fences); |
| 1457 | if (error != hwc3::Error::kNone) { |
| 1458 | cmd_result_writer_->AddError(error); |
| 1459 | } |
| 1460 | if (cmd_result_writer_->HasError()) { |
| 1461 | return; |
| 1462 | } |
| 1463 | |
| 1464 | cmd_result_writer_->AddPresentFence(display_id, std::move(display_fence)); |
| 1465 | cmd_result_writer_->AddReleaseFence(display_id, release_fences); |
| 1466 | } |
| 1467 | |
| 1468 | void ComposerClient::ExecutePresentOrValidateDisplay( |
| 1469 | int64_t display_id, |
| 1470 | std::optional<ClockMonotonicTimestamp> expected_present_time) { |
| 1471 | auto* display = GetDisplay(display_id); |
| 1472 | if (display == nullptr) { |
| 1473 | cmd_result_writer_->AddError(hwc3::Error::kBadDisplay); |
| 1474 | return; |
| 1475 | } |
| 1476 | |
| 1477 | /* TODO: Handle expectedPresentTime */ |
Normunds Rieksts | 4282095 | 2024-03-12 15:42:06 +0000 | [diff] [blame] | 1478 | /* This can be implemented in multiple ways. For example, the expected present |
| 1479 | * time property can be implemented by the DRM driver directly as a CRTC |
| 1480 | * property. See: |
| 1481 | * https://cs.android.com/android/platform/superproject/main/+/b8b3b1646e64d0235f77b9e717a3e4082e26f2a8:hardware/google/graphics/common/libhwc2.1/libdrmresource/drm/drmcrtc.cpp;drc=468f6172546ab98983de18210222f231f16b21e1;l=88 |
| 1482 | * Unfortunately there doesn't seem to be a standardised way of delaying |
| 1483 | * presentation with a timestamp in the DRM API. What we can do alternatively |
| 1484 | * is to spawn a separate presentation thread that could handle the VBlank |
| 1485 | * events by using DRM_MODE_PAGE_FLIP_EVENT and schedule them appropriately. |
| 1486 | */ |
| 1487 | |
Drew Davenport | 5951b11 | 2024-08-05 09:44:27 -0600 | [diff] [blame] | 1488 | /* TODO: Add check if it's possible to skip display validation */ |
| 1489 | ExecuteValidateDisplay(display_id, expected_present_time); |
| 1490 | cmd_result_writer_ |
| 1491 | ->AddPresentOrValidateResult(display_id, |
| 1492 | PresentOrValidate::Result::Validated); |
| 1493 | } |
| 1494 | |
Dennis Tsiang | 33f0ece | 2023-11-29 12:45:04 +0000 | [diff] [blame] | 1495 | } // namespace aidl::android::hardware::graphics::composer3::impl |