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