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