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