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