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