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