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