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