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