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 | |
Roman Stratiienko | 0c36d56 | 2025-01-26 16:11:33 +0200 | [diff] [blame^] | 428 | [[maybe_unused]] |
| 429 | auto HandleClearSlot(int32_t slot_id) |
| 430 | -> std::optional<HwcLayer::LayerProperties> { |
| 431 | if (slots_.count(slot_id) == 0) { |
| 432 | return std::nullopt; |
| 433 | } |
| 434 | |
| 435 | slots_.erase(slot_id); |
| 436 | |
| 437 | auto lp = HwcLayer::LayerProperties{}; |
| 438 | lp.slot_buffer = { |
| 439 | .slot_id = slot_id, |
| 440 | .bi = std::nullopt, |
| 441 | }; |
| 442 | |
| 443 | return lp; |
| 444 | } |
| 445 | |
Roman Stratiienko | 7c8cc4e | 2025-01-25 22:41:53 +0200 | [diff] [blame] | 446 | private: |
| 447 | std::map<int32_t /*slot*/, std::shared_ptr<Hwc3BufferHandle>> slots_; |
| 448 | }; |
| 449 | |
| 450 | static auto GetHwc3Layer(HwcLayer& layer) -> std::shared_ptr<Hwc3Layer> { |
| 451 | auto frontend_private_data = layer.GetFrontendPrivateData(); |
| 452 | if (!frontend_private_data) { |
| 453 | frontend_private_data = std::make_shared<Hwc3Layer>(); |
| 454 | layer.SetFrontendPrivateData(frontend_private_data); |
| 455 | } |
| 456 | return std::static_pointer_cast<Hwc3Layer>(frontend_private_data); |
| 457 | } |
| 458 | |
Drew Davenport | 5951b11 | 2024-08-05 09:44:27 -0600 | [diff] [blame] | 459 | ComposerClient::ComposerClient() { |
| 460 | DEBUG_FUNC(); |
| 461 | } |
| 462 | |
Roman Stratiienko | e501a97 | 2025-01-26 14:10:31 +0200 | [diff] [blame] | 463 | void ComposerClient::Init() { |
Drew Davenport | 5951b11 | 2024-08-05 09:44:27 -0600 | [diff] [blame] | 464 | DEBUG_FUNC(); |
Roman Stratiienko | e501a97 | 2025-01-26 14:10:31 +0200 | [diff] [blame] | 465 | hwc_ = std::make_unique<DrmHwcThree>(); |
Drew Davenport | 5951b11 | 2024-08-05 09:44:27 -0600 | [diff] [blame] | 466 | } |
| 467 | |
Dennis Tsiang | 33f0ece | 2023-11-29 12:45:04 +0000 | [diff] [blame] | 468 | ComposerClient::~ComposerClient() { |
| 469 | DEBUG_FUNC(); |
Roman Stratiienko | c184bc1 | 2025-01-21 01:33:46 +0200 | [diff] [blame] | 470 | if (hwc_) { |
Drew Davenport | 1ac3b62 | 2024-09-05 10:59:16 -0600 | [diff] [blame] | 471 | const std::unique_lock lock(hwc_->GetResMan().GetMainLock()); |
| 472 | hwc_->DeinitDisplays(); |
Drew Davenport | 1ac3b62 | 2024-09-05 10:59:16 -0600 | [diff] [blame] | 473 | hwc_.reset(); |
| 474 | } |
Dennis Tsiang | 33f0ece | 2023-11-29 12:45:04 +0000 | [diff] [blame] | 475 | LOG(DEBUG) << "removed composer client"; |
| 476 | } |
| 477 | |
Drew Davenport | 5951b11 | 2024-08-05 09:44:27 -0600 | [diff] [blame] | 478 | ndk::ScopedAStatus ComposerClient::createLayer(int64_t display_id, |
Roman Stratiienko | e501a97 | 2025-01-26 14:10:31 +0200 | [diff] [blame] | 479 | int32_t /*buffer_slot_count*/, |
Drew Davenport | 5951b11 | 2024-08-05 09:44:27 -0600 | [diff] [blame] | 480 | int64_t* layer_id) { |
Dennis Tsiang | 33f0ece | 2023-11-29 12:45:04 +0000 | [diff] [blame] | 481 | DEBUG_FUNC(); |
Drew Davenport | 5951b11 | 2024-08-05 09:44:27 -0600 | [diff] [blame] | 482 | const std::unique_lock lock(hwc_->GetResMan().GetMainLock()); |
| 483 | |
| 484 | HwcDisplay* display = GetDisplay(display_id); |
| 485 | if (display == nullptr) { |
| 486 | return ToBinderStatus(hwc3::Error::kBadDisplay); |
| 487 | } |
| 488 | |
| 489 | hwc2_layer_t hwc2_layer_id = 0; |
| 490 | auto err = Hwc2toHwc3Error(display->CreateLayer(&hwc2_layer_id)); |
| 491 | if (err != hwc3::Error::kNone) { |
| 492 | return ToBinderStatus(err); |
| 493 | } |
| 494 | |
Roman Stratiienko | e501a97 | 2025-01-26 14:10:31 +0200 | [diff] [blame] | 495 | *layer_id = Hwc2LayerToHwc3(hwc2_layer_id); |
Dennis Tsiang | 33f0ece | 2023-11-29 12:45:04 +0000 | [diff] [blame] | 496 | return ndk::ScopedAStatus::ok(); |
| 497 | } |
| 498 | |
| 499 | ndk::ScopedAStatus ComposerClient::createVirtualDisplay( |
Drew Davenport | 5951b11 | 2024-08-05 09:44:27 -0600 | [diff] [blame] | 500 | int32_t width, int32_t height, AidlPixelFormat format_hint, |
Roman Stratiienko | e501a97 | 2025-01-26 14:10:31 +0200 | [diff] [blame] | 501 | int32_t /*output_buffer_slot_count*/, VirtualDisplay* out_display) { |
Dennis Tsiang | 33f0ece | 2023-11-29 12:45:04 +0000 | [diff] [blame] | 502 | DEBUG_FUNC(); |
Drew Davenport | 5951b11 | 2024-08-05 09:44:27 -0600 | [diff] [blame] | 503 | const std::unique_lock lock(hwc_->GetResMan().GetMainLock()); |
| 504 | |
| 505 | hwc2_display_t hwc2_display_id = 0; |
| 506 | // TODO: Format is currently not used in drm_hwcomposer. |
| 507 | int32_t hwc2_format = 0; |
| 508 | auto err = Hwc2toHwc3Error(hwc_->CreateVirtualDisplay(width, height, |
| 509 | &hwc2_format, |
| 510 | &hwc2_display_id)); |
| 511 | if (err != hwc3::Error::kNone) { |
| 512 | return ToBinderStatus(err); |
| 513 | } |
| 514 | |
Roman Stratiienko | e501a97 | 2025-01-26 14:10:31 +0200 | [diff] [blame] | 515 | out_display->display = Hwc2DisplayToHwc3(hwc2_display_id); |
Drew Davenport | 5951b11 | 2024-08-05 09:44:27 -0600 | [diff] [blame] | 516 | out_display->format = format_hint; |
Dennis Tsiang | 33f0ece | 2023-11-29 12:45:04 +0000 | [diff] [blame] | 517 | return ndk::ScopedAStatus::ok(); |
| 518 | } |
| 519 | |
Drew Davenport | 5951b11 | 2024-08-05 09:44:27 -0600 | [diff] [blame] | 520 | ndk::ScopedAStatus ComposerClient::destroyLayer(int64_t display_id, |
| 521 | int64_t layer_id) { |
Dennis Tsiang | 33f0ece | 2023-11-29 12:45:04 +0000 | [diff] [blame] | 522 | DEBUG_FUNC(); |
Drew Davenport | 5951b11 | 2024-08-05 09:44:27 -0600 | [diff] [blame] | 523 | const std::unique_lock lock(hwc_->GetResMan().GetMainLock()); |
| 524 | HwcDisplay* display = GetDisplay(display_id); |
| 525 | if (display == nullptr) { |
| 526 | return ToBinderStatus(hwc3::Error::kBadDisplay); |
| 527 | } |
| 528 | |
| 529 | auto err = Hwc2toHwc3Error(display->DestroyLayer(Hwc3LayerToHwc2(layer_id))); |
| 530 | if (err != hwc3::Error::kNone) { |
| 531 | return ToBinderStatus(err); |
| 532 | } |
| 533 | |
Drew Davenport | 5951b11 | 2024-08-05 09:44:27 -0600 | [diff] [blame] | 534 | return ToBinderStatus(err); |
Dennis Tsiang | 33f0ece | 2023-11-29 12:45:04 +0000 | [diff] [blame] | 535 | } |
| 536 | |
Drew Davenport | 5951b11 | 2024-08-05 09:44:27 -0600 | [diff] [blame] | 537 | ndk::ScopedAStatus ComposerClient::destroyVirtualDisplay(int64_t display_id) { |
Dennis Tsiang | 33f0ece | 2023-11-29 12:45:04 +0000 | [diff] [blame] | 538 | DEBUG_FUNC(); |
Drew Davenport | 5951b11 | 2024-08-05 09:44:27 -0600 | [diff] [blame] | 539 | const std::unique_lock lock(hwc_->GetResMan().GetMainLock()); |
| 540 | auto err = Hwc2toHwc3Error(hwc_->DestroyVirtualDisplay(display_id)); |
| 541 | return ToBinderStatus(err); |
| 542 | } |
| 543 | |
Drew Davenport | 5951b11 | 2024-08-05 09:44:27 -0600 | [diff] [blame] | 544 | ::android::HwcDisplay* ComposerClient::GetDisplay(uint64_t display_id) { |
| 545 | return hwc_->GetDisplay(display_id); |
| 546 | } |
| 547 | |
| 548 | void ComposerClient::DispatchLayerCommand(int64_t display_id, |
| 549 | const LayerCommand& command) { |
| 550 | auto* display = GetDisplay(display_id); |
| 551 | if (display == nullptr) { |
| 552 | cmd_result_writer_->AddError(hwc3::Error::kBadDisplay); |
| 553 | return; |
| 554 | } |
| 555 | |
| 556 | auto* layer = display->get_layer(command.layer); |
| 557 | if (layer == nullptr) { |
| 558 | cmd_result_writer_->AddError(hwc3::Error::kBadLayer); |
| 559 | return; |
| 560 | } |
| 561 | |
Drew Davenport | 1b0d8b7 | 2024-09-24 15:31:38 -0600 | [diff] [blame] | 562 | // If the requested composition type is not supported, the HWC should return |
| 563 | // an error and not process any further commands. |
| 564 | if (!IsSupportedCompositionType(command.composition)) { |
| 565 | cmd_result_writer_->AddError(hwc3::Error::kUnsupported); |
| 566 | return; |
| 567 | } |
| 568 | |
Drew Davenport | 9c6f7e5 | 2024-09-25 14:58:18 -0600 | [diff] [blame] | 569 | // For some invalid parameters, the HWC should return an error and not process |
| 570 | // any further commands. |
| 571 | if (!ValidateLayerBrightness(command.brightness)) { |
| 572 | cmd_result_writer_->AddError(hwc3::Error::kBadParameter); |
| 573 | return; |
| 574 | } |
| 575 | |
Roman Stratiienko | 0c36d56 | 2025-01-26 16:11:33 +0200 | [diff] [blame^] | 576 | #if __ANDROID_API__ >= 34 |
| 577 | /* https://source.android.com/docs/core/graphics/reduce-consumption */ |
| 578 | if (command.bufferSlotsToClear) { |
| 579 | auto hwc3_layer = GetHwc3Layer(*layer); |
| 580 | for (const auto& slot : *command.bufferSlotsToClear) { |
| 581 | auto lp = hwc3_layer->HandleClearSlot(slot); |
| 582 | if (!lp) { |
| 583 | cmd_result_writer_->AddError(hwc3::Error::kBadLayer); |
| 584 | return; |
| 585 | } |
| 586 | |
| 587 | layer->SetLayerProperties(lp.value()); |
| 588 | } |
| 589 | } |
| 590 | #endif |
| 591 | |
Drew Davenport | e5fbbbb | 2024-10-14 15:49:27 -0600 | [diff] [blame] | 592 | HwcLayer::LayerProperties properties; |
Drew Davenport | 5951b11 | 2024-08-05 09:44:27 -0600 | [diff] [blame] | 593 | if (command.buffer) { |
Roman Stratiienko | 7c8cc4e | 2025-01-25 22:41:53 +0200 | [diff] [blame] | 594 | auto hwc3_layer = GetHwc3Layer(*layer); |
| 595 | std::optional<buffer_handle_t> buffer_handle = std::nullopt; |
| 596 | if (command.buffer->handle) { |
| 597 | buffer_handle = ::android::makeFromAidl(*command.buffer->handle); |
| 598 | } |
| 599 | |
| 600 | // NOLINTNEXTLINE(cppcoreguidelines-pro-type-const-cast) |
| 601 | auto fence = const_cast<::ndk::ScopedFileDescriptor&>(command.buffer->fence) |
| 602 | .release(); |
| 603 | |
| 604 | auto lp = hwc3_layer->HandleNextBuffer(buffer_handle, |
| 605 | ::android::MakeSharedFd(fence), |
| 606 | command.buffer->slot); |
| 607 | |
| 608 | if (!lp) { |
| 609 | cmd_result_writer_->AddError(hwc3::Error::kBadLayer); |
Drew Davenport | e5fbbbb | 2024-10-14 15:49:27 -0600 | [diff] [blame] | 610 | return; |
| 611 | } |
Roman Stratiienko | 7c8cc4e | 2025-01-25 22:41:53 +0200 | [diff] [blame] | 612 | |
| 613 | properties = lp.value(); |
Drew Davenport | 5951b11 | 2024-08-05 09:44:27 -0600 | [diff] [blame] | 614 | } |
Drew Davenport | 1b0d8b7 | 2024-09-24 15:31:38 -0600 | [diff] [blame] | 615 | |
Drew Davenport | a241a77 | 2024-09-24 11:26:30 -0600 | [diff] [blame] | 616 | properties.blend_mode = AidlToBlendMode(command.blendMode); |
Drew Davenport | ac9681e | 2024-09-24 12:17:34 -0600 | [diff] [blame] | 617 | properties.color_space = AidlToColorSpace(command.dataspace); |
| 618 | properties.sample_range = AidlToSampleRange(command.dataspace); |
Drew Davenport | 1b0d8b7 | 2024-09-24 15:31:38 -0600 | [diff] [blame] | 619 | properties.composition_type = AidlToCompositionType(command.composition); |
Drew Davenport | 22d66b4 | 2024-09-24 15:34:57 -0600 | [diff] [blame] | 620 | properties.display_frame = AidlToRect(command.displayFrame); |
Drew Davenport | 07b96f0 | 2024-09-24 15:37:12 -0600 | [diff] [blame] | 621 | properties.alpha = AidlToAlpha(command.planeAlpha); |
Drew Davenport | 7ab8c18 | 2024-09-24 17:04:26 -0600 | [diff] [blame] | 622 | properties.source_crop = AidlToFRect(command.sourceCrop); |
Drew Davenport | 51c61e4 | 2024-09-24 17:13:39 -0600 | [diff] [blame] | 623 | properties.transform = AidlToLayerTransform(command.transform); |
Drew Davenport | 5d679b0 | 2024-09-25 10:15:58 -0600 | [diff] [blame] | 624 | properties.z_order = AidlToZOrder(command.z); |
Drew Davenport | 7ab8c18 | 2024-09-24 17:04:26 -0600 | [diff] [blame] | 625 | |
Drew Davenport | a241a77 | 2024-09-24 11:26:30 -0600 | [diff] [blame] | 626 | layer->SetLayerProperties(properties); |
| 627 | |
Drew Davenport | 5951b11 | 2024-08-05 09:44:27 -0600 | [diff] [blame] | 628 | // Some unsupported functionality returns kUnsupported, and others |
| 629 | // are just a no-op. |
| 630 | // TODO: Audit whether some of these should actually return kUnsupported |
| 631 | // instead. |
| 632 | if (command.sidebandStream) { |
| 633 | cmd_result_writer_->AddError(hwc3::Error::kUnsupported); |
| 634 | } |
| 635 | // TODO: Blocking region handling missing. |
| 636 | // TODO: Layer surface damage. |
| 637 | // TODO: Layer visible region. |
| 638 | // TODO: Per-frame metadata. |
| 639 | // TODO: Layer color transform. |
| 640 | // TODO: Layer cursor position. |
| 641 | // TODO: Layer color. |
| 642 | } |
| 643 | |
| 644 | void ComposerClient::ExecuteDisplayCommand(const DisplayCommand& command) { |
| 645 | const int64_t display_id = command.display; |
Drew Davenport | 76c17a8 | 2025-01-15 15:02:45 -0700 | [diff] [blame] | 646 | HwcDisplay* display = hwc_->GetDisplay(display_id); |
| 647 | if (display == nullptr) { |
Drew Davenport | 5951b11 | 2024-08-05 09:44:27 -0600 | [diff] [blame] | 648 | cmd_result_writer_->AddError(hwc3::Error::kBadDisplay); |
| 649 | return; |
| 650 | } |
| 651 | |
Drew Davenport | 9a2e2f6 | 2024-11-12 15:01:37 -0700 | [diff] [blame] | 652 | if (command.brightness) { |
| 653 | // TODO: Implement support for display brightness. |
| 654 | cmd_result_writer_->AddError(hwc3::Error::kUnsupported); |
| 655 | return; |
| 656 | } |
| 657 | |
Drew Davenport | 76c17a8 | 2025-01-15 15:02:45 -0700 | [diff] [blame] | 658 | hwc3::Error error = ValidateColorTransformMatrix( |
| 659 | command.colorTransformMatrix); |
| 660 | if (error != hwc3::Error::kNone) { |
| 661 | ALOGE("Invalid color transform matrix."); |
| 662 | cmd_result_writer_->AddError(error); |
| 663 | return; |
| 664 | } |
| 665 | |
Drew Davenport | 5951b11 | 2024-08-05 09:44:27 -0600 | [diff] [blame] | 666 | for (const auto& layer_cmd : command.layers) { |
| 667 | DispatchLayerCommand(command.display, layer_cmd); |
| 668 | } |
| 669 | |
Drew Davenport | 7f356c8 | 2025-01-17 16:32:06 -0700 | [diff] [blame] | 670 | if (cmd_result_writer_->HasError()) { |
| 671 | return; |
| 672 | } |
| 673 | |
Drew Davenport | 5951b11 | 2024-08-05 09:44:27 -0600 | [diff] [blame] | 674 | if (command.clientTarget) { |
| 675 | ExecuteSetDisplayClientTarget(command.display, *command.clientTarget); |
| 676 | } |
| 677 | if (command.virtualDisplayOutputBuffer) { |
| 678 | ExecuteSetDisplayOutputBuffer(command.display, |
| 679 | *command.virtualDisplayOutputBuffer); |
| 680 | } |
Drew Davenport | 76c17a8 | 2025-01-15 15:02:45 -0700 | [diff] [blame] | 681 | |
| 682 | std::optional<std::array<float, kCtmSize>> ctm = AidlToColorTransformMatrix( |
| 683 | command.colorTransformMatrix); |
| 684 | if (ctm) { |
| 685 | display->SetColorTransformMatrix(ctm.value()); |
| 686 | } |
| 687 | |
Drew Davenport | 7f356c8 | 2025-01-17 16:32:06 -0700 | [diff] [blame] | 688 | if (command.validateDisplay || command.presentOrValidateDisplay) { |
| 689 | std::vector<HwcDisplay::ChangedLayer> |
| 690 | changed_layers = display->ValidateStagedComposition(); |
| 691 | DisplayChanges changes{}; |
| 692 | for (auto [layer_id, composition_type] : changed_layers) { |
| 693 | changes.AddLayerCompositionChange(command.display, |
| 694 | Hwc2LayerToHwc3(layer_id), |
| 695 | static_cast<Composition>( |
| 696 | composition_type)); |
| 697 | } |
| 698 | cmd_result_writer_->AddChanges(changes); |
Roman Stratiienko | e501a97 | 2025-01-26 14:10:31 +0200 | [diff] [blame] | 699 | auto hwc3_display = DrmHwcThree::GetHwc3Display(*display); |
| 700 | hwc3_display->must_validate = false; |
Drew Davenport | 7f356c8 | 2025-01-17 16:32:06 -0700 | [diff] [blame] | 701 | |
| 702 | // TODO: DisplayRequests are not implemented. |
| 703 | |
| 704 | /* TODO: Add check if it's possible to skip display validation for |
| 705 | * presentOrValidateDisplay */ |
| 706 | if (command.presentOrValidateDisplay) { |
| 707 | cmd_result_writer_ |
| 708 | ->AddPresentOrValidateResult(display_id, |
| 709 | PresentOrValidate::Result::Validated); |
| 710 | } |
Drew Davenport | 5951b11 | 2024-08-05 09:44:27 -0600 | [diff] [blame] | 711 | } |
Drew Davenport | 7f356c8 | 2025-01-17 16:32:06 -0700 | [diff] [blame] | 712 | |
Drew Davenport | 5951b11 | 2024-08-05 09:44:27 -0600 | [diff] [blame] | 713 | if (command.acceptDisplayChanges) { |
Drew Davenport | b864ccf | 2025-01-22 14:57:36 -0700 | [diff] [blame] | 714 | display->AcceptDisplayChanges(); |
Drew Davenport | 5951b11 | 2024-08-05 09:44:27 -0600 | [diff] [blame] | 715 | } |
Drew Davenport | b864ccf | 2025-01-22 14:57:36 -0700 | [diff] [blame] | 716 | |
Drew Davenport | 5951b11 | 2024-08-05 09:44:27 -0600 | [diff] [blame] | 717 | if (command.presentDisplay) { |
Roman Stratiienko | e501a97 | 2025-01-26 14:10:31 +0200 | [diff] [blame] | 718 | auto hwc3_display = DrmHwcThree::GetHwc3Display(*display); |
| 719 | if (hwc3_display->must_validate) { |
Drew Davenport | b864ccf | 2025-01-22 14:57:36 -0700 | [diff] [blame] | 720 | cmd_result_writer_->AddError(hwc3::Error::kNotValidated); |
| 721 | return; |
| 722 | } |
Roman Stratiienko | 16d3a2d | 2025-01-27 17:09:22 +0200 | [diff] [blame] | 723 | ::android::SharedFd present_fence; |
Drew Davenport | b864ccf | 2025-01-22 14:57:36 -0700 | [diff] [blame] | 724 | std::vector<HwcDisplay::ReleaseFence> release_fences; |
Roman Stratiienko | 16d3a2d | 2025-01-27 17:09:22 +0200 | [diff] [blame] | 725 | bool ret = display->PresentStagedComposition(present_fence, release_fences); |
| 726 | |
| 727 | if (!ret) { |
| 728 | cmd_result_writer_->AddError(hwc3::Error::kBadDisplay); |
Drew Davenport | b864ccf | 2025-01-22 14:57:36 -0700 | [diff] [blame] | 729 | return; |
| 730 | } |
Roman Stratiienko | 16d3a2d | 2025-01-27 17:09:22 +0200 | [diff] [blame] | 731 | |
| 732 | using ::android::base::unique_fd; |
| 733 | cmd_result_writer_->AddPresentFence( // |
| 734 | display_id, unique_fd(::android::DupFd(present_fence))); |
| 735 | |
| 736 | std::unordered_map<int64_t, unique_fd> hal_release_fences; |
| 737 | for (const auto& [layer_id, release_fence] : release_fences) { |
| 738 | hal_release_fences[Hwc2LayerToHwc3(layer_id)] = // |
| 739 | unique_fd(::android::DupFd(release_fence)); |
| 740 | } |
| 741 | cmd_result_writer_->AddReleaseFence(display_id, hal_release_fences); |
Drew Davenport | 5951b11 | 2024-08-05 09:44:27 -0600 | [diff] [blame] | 742 | } |
Dennis Tsiang | 33f0ece | 2023-11-29 12:45:04 +0000 | [diff] [blame] | 743 | } |
| 744 | |
| 745 | ndk::ScopedAStatus ComposerClient::executeCommands( |
Drew Davenport | 5951b11 | 2024-08-05 09:44:27 -0600 | [diff] [blame] | 746 | const std::vector<DisplayCommand>& commands, |
| 747 | std::vector<CommandResultPayload>* results) { |
Drew Davenport | 4996585 | 2024-09-05 10:59:40 -0600 | [diff] [blame] | 748 | const std::unique_lock lock(hwc_->GetResMan().GetMainLock()); |
| 749 | DEBUG_FUNC(); |
Drew Davenport | 5951b11 | 2024-08-05 09:44:27 -0600 | [diff] [blame] | 750 | cmd_result_writer_ = std::make_unique<CommandResultWriter>(results); |
| 751 | for (const auto& cmd : commands) { |
| 752 | ExecuteDisplayCommand(cmd); |
| 753 | cmd_result_writer_->IncrementCommand(); |
| 754 | } |
| 755 | cmd_result_writer_.reset(); |
| 756 | |
Dennis Tsiang | 33f0ece | 2023-11-29 12:45:04 +0000 | [diff] [blame] | 757 | return ndk::ScopedAStatus::ok(); |
| 758 | } |
| 759 | |
Drew Davenport | 5951b11 | 2024-08-05 09:44:27 -0600 | [diff] [blame] | 760 | ndk::ScopedAStatus ComposerClient::getActiveConfig(int64_t display_id, |
Drew Davenport | 85be25d | 2024-10-23 10:26:34 -0600 | [diff] [blame] | 761 | int32_t* config_id) { |
Dennis Tsiang | 33f0ece | 2023-11-29 12:45:04 +0000 | [diff] [blame] | 762 | DEBUG_FUNC(); |
Drew Davenport | 5951b11 | 2024-08-05 09:44:27 -0600 | [diff] [blame] | 763 | const std::unique_lock lock(hwc_->GetResMan().GetMainLock()); |
| 764 | HwcDisplay* display = GetDisplay(display_id); |
| 765 | if (display == nullptr) { |
| 766 | return ToBinderStatus(hwc3::Error::kBadDisplay); |
| 767 | } |
| 768 | |
Drew Davenport | 85be25d | 2024-10-23 10:26:34 -0600 | [diff] [blame] | 769 | const HwcDisplayConfig* config = display->GetLastRequestedConfig(); |
| 770 | if (config == nullptr) { |
| 771 | return ToBinderStatus(hwc3::Error::kBadConfig); |
Drew Davenport | 5951b11 | 2024-08-05 09:44:27 -0600 | [diff] [blame] | 772 | } |
Drew Davenport | 85be25d | 2024-10-23 10:26:34 -0600 | [diff] [blame] | 773 | |
| 774 | *config_id = Hwc2ConfigIdToHwc3(config->id); |
Dennis Tsiang | 33f0ece | 2023-11-29 12:45:04 +0000 | [diff] [blame] | 775 | return ndk::ScopedAStatus::ok(); |
| 776 | } |
| 777 | |
| 778 | ndk::ScopedAStatus ComposerClient::getColorModes( |
Drew Davenport | 5951b11 | 2024-08-05 09:44:27 -0600 | [diff] [blame] | 779 | int64_t display_id, std::vector<ColorMode>* color_modes) { |
Dennis Tsiang | 33f0ece | 2023-11-29 12:45:04 +0000 | [diff] [blame] | 780 | DEBUG_FUNC(); |
Drew Davenport | 5951b11 | 2024-08-05 09:44:27 -0600 | [diff] [blame] | 781 | const std::unique_lock lock(hwc_->GetResMan().GetMainLock()); |
| 782 | HwcDisplay* display = GetDisplay(display_id); |
| 783 | if (display == nullptr) { |
| 784 | return ToBinderStatus(hwc3::Error::kBadDisplay); |
| 785 | } |
| 786 | |
| 787 | uint32_t num_modes = 0; |
| 788 | auto error = Hwc2toHwc3Error(display->GetColorModes(&num_modes, nullptr)); |
| 789 | if (error != hwc3::Error::kNone) { |
| 790 | return ToBinderStatus(error); |
| 791 | } |
| 792 | |
| 793 | std::vector<int32_t> hwc2_color_modes(num_modes); |
| 794 | error = Hwc2toHwc3Error( |
| 795 | display->GetColorModes(&num_modes, hwc2_color_modes.data())); |
| 796 | if (error != hwc3::Error::kNone) { |
| 797 | return ToBinderStatus(error); |
| 798 | } |
| 799 | |
| 800 | for (const auto& mode : hwc2_color_modes) { |
| 801 | color_modes->push_back(Hwc2ColorModeToHwc3(mode)); |
| 802 | } |
| 803 | |
Dennis Tsiang | 33f0ece | 2023-11-29 12:45:04 +0000 | [diff] [blame] | 804 | return ndk::ScopedAStatus::ok(); |
| 805 | } |
| 806 | |
| 807 | ndk::ScopedAStatus ComposerClient::getDataspaceSaturationMatrix( |
Drew Davenport | 5951b11 | 2024-08-05 09:44:27 -0600 | [diff] [blame] | 808 | common::Dataspace dataspace, std::vector<float>* matrix) { |
Dennis Tsiang | 33f0ece | 2023-11-29 12:45:04 +0000 | [diff] [blame] | 809 | DEBUG_FUNC(); |
Drew Davenport | 5951b11 | 2024-08-05 09:44:27 -0600 | [diff] [blame] | 810 | if (dataspace != common::Dataspace::SRGB_LINEAR) { |
| 811 | return ToBinderStatus(hwc3::Error::kBadParameter); |
| 812 | } |
| 813 | |
| 814 | matrix->clear(); |
| 815 | matrix->insert(matrix->begin(), kIdentityMatrix.begin(), |
| 816 | kIdentityMatrix.end()); |
| 817 | |
Dennis Tsiang | 33f0ece | 2023-11-29 12:45:04 +0000 | [diff] [blame] | 818 | return ndk::ScopedAStatus::ok(); |
| 819 | } |
| 820 | |
| 821 | ndk::ScopedAStatus ComposerClient::getDisplayAttribute( |
Drew Davenport | 1afb579 | 2024-09-24 12:53:22 -0600 | [diff] [blame] | 822 | int64_t display_id, int32_t config_id, DisplayAttribute attribute, |
Drew Davenport | 5951b11 | 2024-08-05 09:44:27 -0600 | [diff] [blame] | 823 | int32_t* value) { |
Dennis Tsiang | 33f0ece | 2023-11-29 12:45:04 +0000 | [diff] [blame] | 824 | DEBUG_FUNC(); |
Drew Davenport | 5951b11 | 2024-08-05 09:44:27 -0600 | [diff] [blame] | 825 | const std::unique_lock lock(hwc_->GetResMan().GetMainLock()); |
| 826 | HwcDisplay* display = GetDisplay(display_id); |
| 827 | if (display == nullptr) { |
| 828 | return ToBinderStatus(hwc3::Error::kBadDisplay); |
| 829 | } |
| 830 | |
Drew Davenport | 1afb579 | 2024-09-24 12:53:22 -0600 | [diff] [blame] | 831 | const HwcDisplayConfigs& configs = display->GetDisplayConfigs(); |
| 832 | auto config = configs.hwc_configs.find(config_id); |
| 833 | if (config == configs.hwc_configs.end()) { |
| 834 | return ToBinderStatus(hwc3::Error::kBadConfig); |
| 835 | } |
| 836 | |
| 837 | DisplayConfiguration |
| 838 | aidl_configuration = HwcDisplayConfigToAidlConfiguration(configs, |
| 839 | config->second); |
| 840 | // Legacy API for querying DPI uses units of dots per 1000 inches. |
| 841 | static const int kLegacyDpiUnit = 1000; |
| 842 | switch (attribute) { |
| 843 | case DisplayAttribute::WIDTH: |
| 844 | *value = aidl_configuration.width; |
| 845 | break; |
| 846 | case DisplayAttribute::HEIGHT: |
| 847 | *value = aidl_configuration.height; |
| 848 | break; |
| 849 | case DisplayAttribute::VSYNC_PERIOD: |
| 850 | *value = aidl_configuration.vsyncPeriod; |
| 851 | break; |
| 852 | case DisplayAttribute::DPI_X: |
| 853 | *value = aidl_configuration.dpi |
| 854 | ? static_cast<int>(aidl_configuration.dpi->x * |
| 855 | kLegacyDpiUnit) |
| 856 | : -1; |
| 857 | break; |
| 858 | case DisplayAttribute::DPI_Y: |
| 859 | *value = aidl_configuration.dpi |
| 860 | ? static_cast<int>(aidl_configuration.dpi->y * |
| 861 | kLegacyDpiUnit) |
| 862 | : -1; |
| 863 | break; |
| 864 | case DisplayAttribute::CONFIG_GROUP: |
| 865 | *value = aidl_configuration.configGroup; |
| 866 | break; |
| 867 | case DisplayAttribute::INVALID: |
| 868 | return ToBinderStatus(hwc3::Error::kUnsupported); |
| 869 | } |
| 870 | return ndk::ScopedAStatus::ok(); |
Dennis Tsiang | 33f0ece | 2023-11-29 12:45:04 +0000 | [diff] [blame] | 871 | } |
| 872 | |
| 873 | ndk::ScopedAStatus ComposerClient::getDisplayCapabilities( |
Drew Davenport | 5951b11 | 2024-08-05 09:44:27 -0600 | [diff] [blame] | 874 | int64_t display_id, std::vector<DisplayCapability>* caps) { |
Dennis Tsiang | 33f0ece | 2023-11-29 12:45:04 +0000 | [diff] [blame] | 875 | DEBUG_FUNC(); |
Drew Davenport | 5951b11 | 2024-08-05 09:44:27 -0600 | [diff] [blame] | 876 | const std::unique_lock lock(hwc_->GetResMan().GetMainLock()); |
| 877 | HwcDisplay* display = GetDisplay(display_id); |
| 878 | if (display == nullptr) { |
| 879 | return ToBinderStatus(hwc3::Error::kBadDisplay); |
| 880 | } |
Dennis Tsiang | 33f0ece | 2023-11-29 12:45:04 +0000 | [diff] [blame] | 881 | |
Drew Davenport | 5951b11 | 2024-08-05 09:44:27 -0600 | [diff] [blame] | 882 | uint32_t num_capabilities = 0; |
| 883 | hwc3::Error error = Hwc2toHwc3Error( |
| 884 | display->GetDisplayCapabilities(&num_capabilities, nullptr)); |
| 885 | if (error != hwc3::Error::kNone) { |
| 886 | return ToBinderStatus(error); |
| 887 | } |
| 888 | |
| 889 | std::vector<uint32_t> out_caps(num_capabilities); |
| 890 | error = Hwc2toHwc3Error( |
| 891 | display->GetDisplayCapabilities(&num_capabilities, out_caps.data())); |
| 892 | if (error != hwc3::Error::kNone) { |
| 893 | return ToBinderStatus(error); |
| 894 | } |
| 895 | |
| 896 | caps->reserve(num_capabilities); |
| 897 | for (const auto cap : out_caps) { |
| 898 | caps->emplace_back(Hwc2DisplayCapabilityToHwc3(cap)); |
| 899 | } |
Dennis Tsiang | 33f0ece | 2023-11-29 12:45:04 +0000 | [diff] [blame] | 900 | return ndk::ScopedAStatus::ok(); |
| 901 | } |
| 902 | |
| 903 | ndk::ScopedAStatus ComposerClient::getDisplayConfigs( |
Drew Davenport | 1afb579 | 2024-09-24 12:53:22 -0600 | [diff] [blame] | 904 | int64_t display_id, std::vector<int32_t>* out_configs) { |
Dennis Tsiang | 33f0ece | 2023-11-29 12:45:04 +0000 | [diff] [blame] | 905 | DEBUG_FUNC(); |
Drew Davenport | 5951b11 | 2024-08-05 09:44:27 -0600 | [diff] [blame] | 906 | const std::unique_lock lock(hwc_->GetResMan().GetMainLock()); |
| 907 | HwcDisplay* display = GetDisplay(display_id); |
| 908 | if (display == nullptr) { |
| 909 | return ToBinderStatus(hwc3::Error::kBadDisplay); |
| 910 | } |
| 911 | |
Drew Davenport | 1afb579 | 2024-09-24 12:53:22 -0600 | [diff] [blame] | 912 | const HwcDisplayConfigs& configs = display->GetDisplayConfigs(); |
| 913 | for (const auto& [id, config] : configs.hwc_configs) { |
| 914 | out_configs->push_back(static_cast<int32_t>(id)); |
Drew Davenport | 5951b11 | 2024-08-05 09:44:27 -0600 | [diff] [blame] | 915 | } |
Dennis Tsiang | 33f0ece | 2023-11-29 12:45:04 +0000 | [diff] [blame] | 916 | return ndk::ScopedAStatus::ok(); |
| 917 | } |
| 918 | |
| 919 | ndk::ScopedAStatus ComposerClient::getDisplayConnectionType( |
Drew Davenport | 5951b11 | 2024-08-05 09:44:27 -0600 | [diff] [blame] | 920 | int64_t display_id, DisplayConnectionType* type) { |
Dennis Tsiang | 33f0ece | 2023-11-29 12:45:04 +0000 | [diff] [blame] | 921 | DEBUG_FUNC(); |
Drew Davenport | 5951b11 | 2024-08-05 09:44:27 -0600 | [diff] [blame] | 922 | const std::unique_lock lock(hwc_->GetResMan().GetMainLock()); |
| 923 | HwcDisplay* display = GetDisplay(display_id); |
| 924 | if (display == nullptr) { |
| 925 | return ToBinderStatus(hwc3::Error::kBadDisplay); |
| 926 | } |
| 927 | |
| 928 | uint32_t out_type = 0; |
| 929 | const hwc3::Error error = Hwc2toHwc3Error( |
| 930 | display->GetDisplayConnectionType(&out_type)); |
| 931 | if (error != hwc3::Error::kNone) { |
| 932 | return ToBinderStatus(error); |
| 933 | } |
| 934 | |
| 935 | *type = Hwc2DisplayConnectionTypeToHwc3(out_type); |
Dennis Tsiang | 33f0ece | 2023-11-29 12:45:04 +0000 | [diff] [blame] | 936 | return ndk::ScopedAStatus::ok(); |
| 937 | } |
| 938 | |
| 939 | ndk::ScopedAStatus ComposerClient::getDisplayIdentificationData( |
Drew Davenport | 5951b11 | 2024-08-05 09:44:27 -0600 | [diff] [blame] | 940 | int64_t display_id, DisplayIdentification* id) { |
Dennis Tsiang | 33f0ece | 2023-11-29 12:45:04 +0000 | [diff] [blame] | 941 | DEBUG_FUNC(); |
Drew Davenport | 5951b11 | 2024-08-05 09:44:27 -0600 | [diff] [blame] | 942 | const std::unique_lock lock(hwc_->GetResMan().GetMainLock()); |
| 943 | HwcDisplay* display = GetDisplay(display_id); |
| 944 | if (display == nullptr) { |
| 945 | return ToBinderStatus(hwc3::Error::kBadDisplay); |
| 946 | } |
| 947 | |
| 948 | uint8_t port = 0; |
| 949 | uint32_t data_size = 0; |
| 950 | hwc3::Error error = Hwc2toHwc3Error( |
| 951 | display->GetDisplayIdentificationData(&port, &data_size, nullptr)); |
| 952 | if (error != hwc3::Error::kNone) { |
| 953 | return ToBinderStatus(error); |
| 954 | } |
| 955 | |
| 956 | id->data.resize(data_size); |
| 957 | error = Hwc2toHwc3Error( |
| 958 | display->GetDisplayIdentificationData(&port, &data_size, |
| 959 | id->data.data())); |
| 960 | if (error != hwc3::Error::kNone) { |
| 961 | return ToBinderStatus(error); |
| 962 | } |
| 963 | |
| 964 | id->port = static_cast<int8_t>(port); |
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::getDisplayName(int64_t display_id, |
| 969 | std::string* name) { |
Dennis Tsiang | 33f0ece | 2023-11-29 12:45:04 +0000 | [diff] [blame] | 970 | DEBUG_FUNC(); |
Drew Davenport | 5951b11 | 2024-08-05 09:44:27 -0600 | [diff] [blame] | 971 | const std::unique_lock lock(hwc_->GetResMan().GetMainLock()); |
| 972 | HwcDisplay* display = GetDisplay(display_id); |
| 973 | if (display == nullptr) { |
| 974 | return ToBinderStatus(hwc3::Error::kBadDisplay); |
| 975 | } |
| 976 | |
| 977 | uint32_t size = 0; |
| 978 | auto error = Hwc2toHwc3Error(display->GetDisplayName(&size, nullptr)); |
| 979 | if (error != hwc3::Error::kNone) { |
| 980 | return ToBinderStatus(error); |
| 981 | } |
| 982 | |
| 983 | name->resize(size); |
| 984 | error = Hwc2toHwc3Error(display->GetDisplayName(&size, name->data())); |
| 985 | return ToBinderStatus(error); |
Dennis Tsiang | 33f0ece | 2023-11-29 12:45:04 +0000 | [diff] [blame] | 986 | } |
| 987 | |
| 988 | ndk::ScopedAStatus ComposerClient::getDisplayVsyncPeriod( |
Drew Davenport | 5951b11 | 2024-08-05 09:44:27 -0600 | [diff] [blame] | 989 | int64_t display_id, int32_t* vsync_period) { |
Dennis Tsiang | 33f0ece | 2023-11-29 12:45:04 +0000 | [diff] [blame] | 990 | DEBUG_FUNC(); |
Drew Davenport | 5951b11 | 2024-08-05 09:44:27 -0600 | [diff] [blame] | 991 | const std::unique_lock lock(hwc_->GetResMan().GetMainLock()); |
| 992 | HwcDisplay* display = GetDisplay(display_id); |
| 993 | if (display == nullptr) { |
| 994 | return ToBinderStatus(hwc3::Error::kBadDisplay); |
| 995 | } |
| 996 | |
Drew Davenport | 9799ab8 | 2024-10-23 10:15:45 -0600 | [diff] [blame] | 997 | // getDisplayVsyncPeriod should return the vsync period of the config that |
| 998 | // is currently committed to the kernel. If a config change is pending due to |
| 999 | // setActiveConfigWithConstraints, return the pre-change vsync period. |
| 1000 | const HwcDisplayConfig* config = display->GetCurrentConfig(); |
| 1001 | if (config == nullptr) { |
| 1002 | return ToBinderStatus(hwc3::Error::kBadConfig); |
Drew Davenport | 5951b11 | 2024-08-05 09:44:27 -0600 | [diff] [blame] | 1003 | } |
| 1004 | |
Drew Davenport | 9799ab8 | 2024-10-23 10:15:45 -0600 | [diff] [blame] | 1005 | *vsync_period = config->mode.GetVSyncPeriodNs(); |
Dennis Tsiang | 33f0ece | 2023-11-29 12:45:04 +0000 | [diff] [blame] | 1006 | return ndk::ScopedAStatus::ok(); |
| 1007 | } |
| 1008 | |
| 1009 | ndk::ScopedAStatus ComposerClient::getDisplayedContentSample( |
Drew Davenport | 5951b11 | 2024-08-05 09:44:27 -0600 | [diff] [blame] | 1010 | int64_t /*display_id*/, int64_t /*max_frames*/, int64_t /*timestamp*/, |
Dennis Tsiang | 33f0ece | 2023-11-29 12:45:04 +0000 | [diff] [blame] | 1011 | DisplayContentSample* /*samples*/) { |
| 1012 | DEBUG_FUNC(); |
Drew Davenport | 5951b11 | 2024-08-05 09:44:27 -0600 | [diff] [blame] | 1013 | return ToBinderStatus(hwc3::Error::kUnsupported); |
Dennis Tsiang | 33f0ece | 2023-11-29 12:45:04 +0000 | [diff] [blame] | 1014 | } |
| 1015 | |
| 1016 | ndk::ScopedAStatus ComposerClient::getDisplayedContentSamplingAttributes( |
Drew Davenport | 5951b11 | 2024-08-05 09:44:27 -0600 | [diff] [blame] | 1017 | int64_t /*display_id*/, DisplayContentSamplingAttributes* /*attrs*/) { |
Dennis Tsiang | 33f0ece | 2023-11-29 12:45:04 +0000 | [diff] [blame] | 1018 | DEBUG_FUNC(); |
Drew Davenport | 5951b11 | 2024-08-05 09:44:27 -0600 | [diff] [blame] | 1019 | return ToBinderStatus(hwc3::Error::kUnsupported); |
Dennis Tsiang | 33f0ece | 2023-11-29 12:45:04 +0000 | [diff] [blame] | 1020 | } |
| 1021 | |
| 1022 | ndk::ScopedAStatus ComposerClient::getDisplayPhysicalOrientation( |
Drew Davenport | 5951b11 | 2024-08-05 09:44:27 -0600 | [diff] [blame] | 1023 | int64_t display_id, common::Transform* orientation) { |
Dennis Tsiang | 33f0ece | 2023-11-29 12:45:04 +0000 | [diff] [blame] | 1024 | DEBUG_FUNC(); |
Tim Van Patten | a2f3efa | 2024-10-15 17:44:54 -0600 | [diff] [blame] | 1025 | |
| 1026 | if (orientation == nullptr) { |
| 1027 | ALOGE("Invalid 'orientation' pointer."); |
| 1028 | return ToBinderStatus(hwc3::Error::kBadParameter); |
| 1029 | } |
| 1030 | |
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 | |
Tim Van Patten | a2f3efa | 2024-10-15 17:44:54 -0600 | [diff] [blame] | 1037 | PanelOrientation |
| 1038 | drm_orientation = display->getDisplayPhysicalOrientation().value_or( |
| 1039 | PanelOrientation::kModePanelOrientationNormal); |
| 1040 | |
| 1041 | switch (drm_orientation) { |
| 1042 | case PanelOrientation::kModePanelOrientationNormal: |
| 1043 | *orientation = common::Transform::NONE; |
| 1044 | break; |
| 1045 | case PanelOrientation::kModePanelOrientationBottomUp: |
| 1046 | *orientation = common::Transform::ROT_180; |
| 1047 | break; |
| 1048 | case PanelOrientation::kModePanelOrientationLeftUp: |
| 1049 | *orientation = common::Transform::ROT_270; |
| 1050 | break; |
| 1051 | case PanelOrientation::kModePanelOrientationRightUp: |
| 1052 | *orientation = common::Transform::ROT_90; |
| 1053 | break; |
| 1054 | default: |
| 1055 | ALOGE("Unknown panel orientation value: %d", drm_orientation); |
| 1056 | return ToBinderStatus(hwc3::Error::kBadDisplay); |
| 1057 | } |
| 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::getHdrCapabilities(int64_t display_id, |
| 1063 | HdrCapabilities* caps) { |
Dennis Tsiang | 33f0ece | 2023-11-29 12:45:04 +0000 | [diff] [blame] | 1064 | DEBUG_FUNC(); |
Drew Davenport | 5951b11 | 2024-08-05 09:44:27 -0600 | [diff] [blame] | 1065 | const std::unique_lock lock(hwc_->GetResMan().GetMainLock()); |
| 1066 | HwcDisplay* display = GetDisplay(display_id); |
| 1067 | if (display == nullptr) { |
| 1068 | return ToBinderStatus(hwc3::Error::kBadDisplay); |
| 1069 | } |
| 1070 | |
Sasha McIntosh | 851ea4d | 2024-12-04 17:14:55 -0500 | [diff] [blame] | 1071 | uint32_t num_types = 0; |
| 1072 | hwc3::Error error = Hwc2toHwc3Error( |
| 1073 | display->GetHdrCapabilities(&num_types, nullptr, nullptr, nullptr, |
| 1074 | nullptr)); |
| 1075 | if (error != hwc3::Error::kNone) { |
| 1076 | return ToBinderStatus(error); |
| 1077 | } |
| 1078 | |
| 1079 | std::vector<int32_t> out_types(num_types); |
| 1080 | error = Hwc2toHwc3Error( |
| 1081 | display->GetHdrCapabilities(&num_types, out_types.data(), |
| 1082 | &caps->maxLuminance, |
| 1083 | &caps->maxAverageLuminance, |
| 1084 | &caps->minLuminance)); |
| 1085 | if (error != hwc3::Error::kNone) { |
| 1086 | return ToBinderStatus(error); |
| 1087 | } |
| 1088 | |
| 1089 | caps->types.reserve(num_types); |
| 1090 | for (const auto type : out_types) |
| 1091 | caps->types.emplace_back(Hwc2HdrTypeToHwc3(type)); |
| 1092 | |
Dennis Tsiang | 33f0ece | 2023-11-29 12:45:04 +0000 | [diff] [blame] | 1093 | return ndk::ScopedAStatus::ok(); |
| 1094 | } |
| 1095 | |
Drew Davenport | 5951b11 | 2024-08-05 09:44:27 -0600 | [diff] [blame] | 1096 | ndk::ScopedAStatus ComposerClient::getMaxVirtualDisplayCount(int32_t* count) { |
Dennis Tsiang | 33f0ece | 2023-11-29 12:45:04 +0000 | [diff] [blame] | 1097 | DEBUG_FUNC(); |
Drew Davenport | 5951b11 | 2024-08-05 09:44:27 -0600 | [diff] [blame] | 1098 | const std::unique_lock lock(hwc_->GetResMan().GetMainLock()); |
| 1099 | *count = static_cast<int32_t>(hwc_->GetMaxVirtualDisplayCount()); |
Dennis Tsiang | 33f0ece | 2023-11-29 12:45:04 +0000 | [diff] [blame] | 1100 | return ndk::ScopedAStatus::ok(); |
| 1101 | } |
| 1102 | |
| 1103 | ndk::ScopedAStatus ComposerClient::getPerFrameMetadataKeys( |
Drew Davenport | 5951b11 | 2024-08-05 09:44:27 -0600 | [diff] [blame] | 1104 | int64_t /*display_id*/, std::vector<PerFrameMetadataKey>* /*keys*/) { |
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::getReadbackBufferAttributes( |
Drew Davenport | 5951b11 | 2024-08-05 09:44:27 -0600 | [diff] [blame] | 1110 | int64_t /*display_id*/, ReadbackBufferAttributes* /*attrs*/) { |
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 | |
| 1115 | ndk::ScopedAStatus ComposerClient::getReadbackBufferFence( |
Drew Davenport | 5951b11 | 2024-08-05 09:44:27 -0600 | [diff] [blame] | 1116 | int64_t /*display_id*/, ndk::ScopedFileDescriptor* /*acquireFence*/) { |
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 | return ToBinderStatus(hwc3::Error::kUnsupported); |
Dennis Tsiang | 33f0ece | 2023-11-29 12:45:04 +0000 | [diff] [blame] | 1119 | } |
| 1120 | |
| 1121 | ndk::ScopedAStatus ComposerClient::getRenderIntents( |
Drew Davenport | 5951b11 | 2024-08-05 09:44:27 -0600 | [diff] [blame] | 1122 | int64_t display_id, ColorMode mode, std::vector<RenderIntent>* intents) { |
Dennis Tsiang | 33f0ece | 2023-11-29 12:45:04 +0000 | [diff] [blame] | 1123 | DEBUG_FUNC(); |
Drew Davenport | 5951b11 | 2024-08-05 09:44:27 -0600 | [diff] [blame] | 1124 | const std::unique_lock lock(hwc_->GetResMan().GetMainLock()); |
| 1125 | HwcDisplay* display = GetDisplay(display_id); |
| 1126 | if (display == nullptr) { |
| 1127 | return ToBinderStatus(hwc3::Error::kBadDisplay); |
| 1128 | } |
| 1129 | |
| 1130 | const int32_t hwc2_color_mode = Hwc3ColorModeToHwc2(mode); |
| 1131 | uint32_t out_num_intents = 0; |
| 1132 | auto error = Hwc2toHwc3Error( |
| 1133 | display->GetRenderIntents(hwc2_color_mode, &out_num_intents, nullptr)); |
| 1134 | if (error != hwc3::Error::kNone) { |
| 1135 | return ToBinderStatus(error); |
| 1136 | } |
| 1137 | |
| 1138 | std::vector<int32_t> out_intents(out_num_intents); |
| 1139 | error = Hwc2toHwc3Error(display->GetRenderIntents(hwc2_color_mode, |
| 1140 | &out_num_intents, |
| 1141 | out_intents.data())); |
| 1142 | if (error != hwc3::Error::kNone) { |
| 1143 | return ToBinderStatus(error); |
| 1144 | } |
| 1145 | |
| 1146 | intents->reserve(out_num_intents); |
| 1147 | for (const auto intent : out_intents) { |
| 1148 | intents->emplace_back(Hwc2RenderIntentToHwc3(intent)); |
| 1149 | } |
Dennis Tsiang | 33f0ece | 2023-11-29 12:45:04 +0000 | [diff] [blame] | 1150 | return ndk::ScopedAStatus::ok(); |
| 1151 | } |
| 1152 | |
| 1153 | ndk::ScopedAStatus ComposerClient::getSupportedContentTypes( |
Drew Davenport | 5951b11 | 2024-08-05 09:44:27 -0600 | [diff] [blame] | 1154 | int64_t display_id, std::vector<ContentType>* types) { |
Dennis Tsiang | 33f0ece | 2023-11-29 12:45:04 +0000 | [diff] [blame] | 1155 | DEBUG_FUNC(); |
Drew Davenport | 5951b11 | 2024-08-05 09:44:27 -0600 | [diff] [blame] | 1156 | const std::unique_lock lock(hwc_->GetResMan().GetMainLock()); |
| 1157 | HwcDisplay* display = GetDisplay(display_id); |
| 1158 | if (display == nullptr) { |
| 1159 | return ToBinderStatus(hwc3::Error::kBadDisplay); |
| 1160 | } |
| 1161 | |
Drew Davenport | 8d38dc7 | 2024-09-24 12:26:07 -0600 | [diff] [blame] | 1162 | // Support for ContentType is not implemented. |
| 1163 | types->clear(); |
Dennis Tsiang | 33f0ece | 2023-11-29 12:45:04 +0000 | [diff] [blame] | 1164 | return ndk::ScopedAStatus::ok(); |
| 1165 | } |
| 1166 | |
| 1167 | ndk::ScopedAStatus ComposerClient::getDisplayDecorationSupport( |
Drew Davenport | 5951b11 | 2024-08-05 09:44:27 -0600 | [diff] [blame] | 1168 | int64_t /*display_id*/, |
| 1169 | std::optional<common::DisplayDecorationSupport>* /*support_struct*/) { |
Dennis Tsiang | 33f0ece | 2023-11-29 12:45:04 +0000 | [diff] [blame] | 1170 | DEBUG_FUNC(); |
Drew Davenport | 5951b11 | 2024-08-05 09:44:27 -0600 | [diff] [blame] | 1171 | return ToBinderStatus(hwc3::Error::kUnsupported); |
Dennis Tsiang | 33f0ece | 2023-11-29 12:45:04 +0000 | [diff] [blame] | 1172 | } |
| 1173 | |
| 1174 | ndk::ScopedAStatus ComposerClient::registerCallback( |
Drew Davenport | 5951b11 | 2024-08-05 09:44:27 -0600 | [diff] [blame] | 1175 | const std::shared_ptr<IComposerCallback>& callback) { |
Dennis Tsiang | 33f0ece | 2023-11-29 12:45:04 +0000 | [diff] [blame] | 1176 | DEBUG_FUNC(); |
Drew Davenport | 5951b11 | 2024-08-05 09:44:27 -0600 | [diff] [blame] | 1177 | const std::unique_lock lock(hwc_->GetResMan().GetMainLock()); |
| 1178 | // This function is specified to be called exactly once. |
| 1179 | hwc_->Init(callback); |
Dennis Tsiang | 33f0ece | 2023-11-29 12:45:04 +0000 | [diff] [blame] | 1180 | return ndk::ScopedAStatus::ok(); |
| 1181 | } |
| 1182 | |
Drew Davenport | 5951b11 | 2024-08-05 09:44:27 -0600 | [diff] [blame] | 1183 | ndk::ScopedAStatus ComposerClient::setActiveConfig(int64_t display_id, |
| 1184 | int32_t config) { |
Dennis Tsiang | 33f0ece | 2023-11-29 12:45:04 +0000 | [diff] [blame] | 1185 | DEBUG_FUNC(); |
Drew Davenport | 5951b11 | 2024-08-05 09:44:27 -0600 | [diff] [blame] | 1186 | |
Drew Davenport | 8998f8b | 2024-10-24 10:15:12 -0600 | [diff] [blame] | 1187 | VsyncPeriodChangeTimeline timeline; |
| 1188 | VsyncPeriodChangeConstraints constraints = { |
| 1189 | .desiredTimeNanos = ::android::ResourceManager::GetTimeMonotonicNs(), |
| 1190 | .seamlessRequired = false, |
| 1191 | }; |
| 1192 | return setActiveConfigWithConstraints(display_id, config, constraints, |
| 1193 | &timeline); |
Dennis Tsiang | 33f0ece | 2023-11-29 12:45:04 +0000 | [diff] [blame] | 1194 | } |
| 1195 | |
| 1196 | ndk::ScopedAStatus ComposerClient::setActiveConfigWithConstraints( |
Drew Davenport | 5951b11 | 2024-08-05 09:44:27 -0600 | [diff] [blame] | 1197 | int64_t display_id, int32_t config, |
| 1198 | const VsyncPeriodChangeConstraints& constraints, |
| 1199 | VsyncPeriodChangeTimeline* timeline) { |
Dennis Tsiang | 33f0ece | 2023-11-29 12:45:04 +0000 | [diff] [blame] | 1200 | DEBUG_FUNC(); |
Drew Davenport | 5951b11 | 2024-08-05 09:44:27 -0600 | [diff] [blame] | 1201 | const std::unique_lock lock(hwc_->GetResMan().GetMainLock()); |
| 1202 | HwcDisplay* display = GetDisplay(display_id); |
| 1203 | if (display == nullptr) { |
| 1204 | return ToBinderStatus(hwc3::Error::kBadDisplay); |
| 1205 | } |
| 1206 | |
Drew Davenport | 97b5abc | 2024-11-07 10:43:54 -0700 | [diff] [blame] | 1207 | if (constraints.seamlessRequired) { |
| 1208 | return ToBinderStatus(hwc3::Error::kSeamlessNotAllowed); |
| 1209 | } |
| 1210 | |
| 1211 | const bool future_config = constraints.desiredTimeNanos > |
| 1212 | ::android::ResourceManager::GetTimeMonotonicNs(); |
| 1213 | const HwcDisplayConfig* current_config = display->GetCurrentConfig(); |
| 1214 | const HwcDisplayConfig* next_config = display->GetConfig(config); |
| 1215 | const bool same_config_group = current_config != nullptr && |
| 1216 | next_config != nullptr && |
| 1217 | current_config->group_id == |
| 1218 | next_config->group_id; |
| 1219 | // If the contraints dictate that this is to be applied in the future, it |
| 1220 | // must be queued. If the new config is in the same config group as the |
| 1221 | // current one, then queue it to reduce jank. |
| 1222 | HwcDisplay::ConfigError result{}; |
| 1223 | if (future_config || same_config_group) { |
| 1224 | QueuedConfigTiming timing = {}; |
| 1225 | result = display->QueueConfig(config, constraints.desiredTimeNanos, |
| 1226 | constraints.seamlessRequired, &timing); |
| 1227 | timeline->newVsyncAppliedTimeNanos = timing.new_vsync_time_ns; |
| 1228 | timeline->refreshTimeNanos = timing.refresh_time_ns; |
| 1229 | timeline->refreshRequired = true; |
| 1230 | } else { |
| 1231 | // Fall back to a blocking commit, which may modeset. |
| 1232 | result = display->SetConfig(config); |
| 1233 | timeline->newVsyncAppliedTimeNanos = ::android::ResourceManager:: |
| 1234 | GetTimeMonotonicNs(); |
| 1235 | timeline->refreshRequired = false; |
| 1236 | } |
Drew Davenport | 5951b11 | 2024-08-05 09:44:27 -0600 | [diff] [blame] | 1237 | |
Drew Davenport | 8998f8b | 2024-10-24 10:15:12 -0600 | [diff] [blame] | 1238 | switch (result) { |
| 1239 | case HwcDisplay::ConfigError::kBadConfig: |
| 1240 | return ToBinderStatus(hwc3::Error::kBadConfig); |
| 1241 | case HwcDisplay::ConfigError::kSeamlessNotAllowed: |
| 1242 | return ToBinderStatus(hwc3::Error::kSeamlessNotAllowed); |
| 1243 | case HwcDisplay::ConfigError::kSeamlessNotPossible: |
| 1244 | return ToBinderStatus(hwc3::Error::kSeamlessNotPossible); |
| 1245 | case HwcDisplay::ConfigError::kNone: |
| 1246 | return ndk::ScopedAStatus::ok(); |
Drew Davenport | 5951b11 | 2024-08-05 09:44:27 -0600 | [diff] [blame] | 1247 | } |
Dennis Tsiang | 33f0ece | 2023-11-29 12:45:04 +0000 | [diff] [blame] | 1248 | } |
| 1249 | |
Drew Davenport | 5951b11 | 2024-08-05 09:44:27 -0600 | [diff] [blame] | 1250 | ndk::ScopedAStatus ComposerClient::setBootDisplayConfig(int64_t /*display_id*/, |
Dennis Tsiang | 33f0ece | 2023-11-29 12:45:04 +0000 | [diff] [blame] | 1251 | int32_t /*config*/) { |
| 1252 | DEBUG_FUNC(); |
Drew Davenport | 5951b11 | 2024-08-05 09:44:27 -0600 | [diff] [blame] | 1253 | return ToBinderStatus(hwc3::Error::kUnsupported); |
Dennis Tsiang | 33f0ece | 2023-11-29 12:45:04 +0000 | [diff] [blame] | 1254 | } |
| 1255 | |
Drew Davenport | 5951b11 | 2024-08-05 09:44:27 -0600 | [diff] [blame] | 1256 | ndk::ScopedAStatus ComposerClient::clearBootDisplayConfig( |
| 1257 | int64_t /*display_id*/) { |
Dennis Tsiang | 33f0ece | 2023-11-29 12:45:04 +0000 | [diff] [blame] | 1258 | DEBUG_FUNC(); |
Drew Davenport | 5951b11 | 2024-08-05 09:44:27 -0600 | [diff] [blame] | 1259 | return ToBinderStatus(hwc3::Error::kUnsupported); |
Dennis Tsiang | 33f0ece | 2023-11-29 12:45:04 +0000 | [diff] [blame] | 1260 | } |
| 1261 | |
| 1262 | ndk::ScopedAStatus ComposerClient::getPreferredBootDisplayConfig( |
Drew Davenport | 5951b11 | 2024-08-05 09:44:27 -0600 | [diff] [blame] | 1263 | int64_t /*display_id*/, int32_t* /*config*/) { |
Dennis Tsiang | 33f0ece | 2023-11-29 12:45:04 +0000 | [diff] [blame] | 1264 | DEBUG_FUNC(); |
Drew Davenport | 5951b11 | 2024-08-05 09:44:27 -0600 | [diff] [blame] | 1265 | return ToBinderStatus(hwc3::Error::kUnsupported); |
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::setAutoLowLatencyMode(int64_t display_id, |
| 1269 | bool on) { |
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 | |
| 1277 | auto error = Hwc2toHwc3Error(display->SetAutoLowLatencyMode(on)); |
| 1278 | return ToBinderStatus(error); |
Dennis Tsiang | 33f0ece | 2023-11-29 12:45:04 +0000 | [diff] [blame] | 1279 | } |
| 1280 | |
Roman Stratiienko | e501a97 | 2025-01-26 14:10:31 +0200 | [diff] [blame] | 1281 | ndk::ScopedAStatus ComposerClient::setClientTargetSlotCount( |
| 1282 | int64_t /*display_id*/, int32_t /*count*/) { |
Dennis Tsiang | 33f0ece | 2023-11-29 12:45:04 +0000 | [diff] [blame] | 1283 | DEBUG_FUNC(); |
Roman Stratiienko | e501a97 | 2025-01-26 14:10:31 +0200 | [diff] [blame] | 1284 | return ToBinderStatus(hwc3::Error::kNone); |
Dennis Tsiang | 33f0ece | 2023-11-29 12:45:04 +0000 | [diff] [blame] | 1285 | } |
| 1286 | |
Drew Davenport | 5951b11 | 2024-08-05 09:44:27 -0600 | [diff] [blame] | 1287 | ndk::ScopedAStatus ComposerClient::setColorMode(int64_t display_id, |
| 1288 | ColorMode mode, |
| 1289 | RenderIntent intent) { |
Dennis Tsiang | 33f0ece | 2023-11-29 12:45:04 +0000 | [diff] [blame] | 1290 | DEBUG_FUNC(); |
Drew Davenport | 5951b11 | 2024-08-05 09:44:27 -0600 | [diff] [blame] | 1291 | const std::unique_lock lock(hwc_->GetResMan().GetMainLock()); |
| 1292 | HwcDisplay* display = GetDisplay(display_id); |
| 1293 | if (display == nullptr) { |
| 1294 | return ToBinderStatus(hwc3::Error::kBadDisplay); |
| 1295 | } |
| 1296 | |
| 1297 | auto error = display->SetColorModeWithIntent(Hwc3ColorModeToHwc2(mode), |
| 1298 | Hwc3RenderIntentToHwc2(intent)); |
| 1299 | return ToBinderStatus(Hwc2toHwc3Error(error)); |
Dennis Tsiang | 33f0ece | 2023-11-29 12:45:04 +0000 | [diff] [blame] | 1300 | } |
| 1301 | |
Drew Davenport | 5951b11 | 2024-08-05 09:44:27 -0600 | [diff] [blame] | 1302 | ndk::ScopedAStatus ComposerClient::setContentType(int64_t display_id, |
| 1303 | ContentType type) { |
Dennis Tsiang | 33f0ece | 2023-11-29 12:45:04 +0000 | [diff] [blame] | 1304 | DEBUG_FUNC(); |
Drew Davenport | 5951b11 | 2024-08-05 09:44:27 -0600 | [diff] [blame] | 1305 | const std::unique_lock lock(hwc_->GetResMan().GetMainLock()); |
| 1306 | HwcDisplay* display = GetDisplay(display_id); |
| 1307 | if (display == nullptr) { |
| 1308 | return ToBinderStatus(hwc3::Error::kBadDisplay); |
| 1309 | } |
| 1310 | |
Drew Davenport | 8d38dc7 | 2024-09-24 12:26:07 -0600 | [diff] [blame] | 1311 | if (type == ContentType::NONE) { |
| 1312 | return ndk::ScopedAStatus::ok(); |
| 1313 | } |
| 1314 | return ToBinderStatus(hwc3::Error::kUnsupported); |
Dennis Tsiang | 33f0ece | 2023-11-29 12:45:04 +0000 | [diff] [blame] | 1315 | } |
| 1316 | |
| 1317 | ndk::ScopedAStatus ComposerClient::setDisplayedContentSamplingEnabled( |
Drew Davenport | 5951b11 | 2024-08-05 09:44:27 -0600 | [diff] [blame] | 1318 | int64_t /*display_id*/, bool /*enable*/, |
Dennis Tsiang | 33f0ece | 2023-11-29 12:45:04 +0000 | [diff] [blame] | 1319 | FormatColorComponent /*componentMask*/, int64_t /*maxFrames*/) { |
| 1320 | DEBUG_FUNC(); |
Drew Davenport | 5951b11 | 2024-08-05 09:44:27 -0600 | [diff] [blame] | 1321 | return ToBinderStatus(hwc3::Error::kUnsupported); |
Dennis Tsiang | 33f0ece | 2023-11-29 12:45:04 +0000 | [diff] [blame] | 1322 | } |
| 1323 | |
Drew Davenport | 5951b11 | 2024-08-05 09:44:27 -0600 | [diff] [blame] | 1324 | ndk::ScopedAStatus ComposerClient::setPowerMode(int64_t display_id, |
| 1325 | PowerMode mode) { |
Dennis Tsiang | 33f0ece | 2023-11-29 12:45:04 +0000 | [diff] [blame] | 1326 | DEBUG_FUNC(); |
Drew Davenport | 5951b11 | 2024-08-05 09:44:27 -0600 | [diff] [blame] | 1327 | const std::unique_lock lock(hwc_->GetResMan().GetMainLock()); |
| 1328 | HwcDisplay* display = GetDisplay(display_id); |
| 1329 | if (display == nullptr) { |
| 1330 | return ToBinderStatus(hwc3::Error::kBadDisplay); |
| 1331 | } |
| 1332 | |
Dennis Tsiang | 1a96620 | 2024-01-24 12:46:33 +0000 | [diff] [blame] | 1333 | if (mode == PowerMode::ON_SUSPEND) { |
| 1334 | return ToBinderStatus(hwc3::Error::kUnsupported); |
| 1335 | } |
| 1336 | |
Drew Davenport | 5951b11 | 2024-08-05 09:44:27 -0600 | [diff] [blame] | 1337 | auto error = display->SetPowerMode(Hwc3PowerModeToHwc2(mode)); |
| 1338 | return ToBinderStatus(Hwc2toHwc3Error(error)); |
Dennis Tsiang | 33f0ece | 2023-11-29 12:45:04 +0000 | [diff] [blame] | 1339 | } |
| 1340 | |
| 1341 | ndk::ScopedAStatus ComposerClient::setReadbackBuffer( |
Drew Davenport | 5951b11 | 2024-08-05 09:44:27 -0600 | [diff] [blame] | 1342 | int64_t /*display_id*/, const AidlNativeHandle& /*aidlBuffer*/, |
Dennis Tsiang | 33f0ece | 2023-11-29 12:45:04 +0000 | [diff] [blame] | 1343 | const ndk::ScopedFileDescriptor& /*releaseFence*/) { |
| 1344 | DEBUG_FUNC(); |
Drew Davenport | 5951b11 | 2024-08-05 09:44:27 -0600 | [diff] [blame] | 1345 | return ToBinderStatus(hwc3::Error::kUnsupported); |
Dennis Tsiang | 33f0ece | 2023-11-29 12:45:04 +0000 | [diff] [blame] | 1346 | } |
| 1347 | |
Drew Davenport | 5951b11 | 2024-08-05 09:44:27 -0600 | [diff] [blame] | 1348 | ndk::ScopedAStatus ComposerClient::setVsyncEnabled(int64_t display_id, |
| 1349 | bool enabled) { |
Dennis Tsiang | 33f0ece | 2023-11-29 12:45:04 +0000 | [diff] [blame] | 1350 | DEBUG_FUNC(); |
Drew Davenport | 5951b11 | 2024-08-05 09:44:27 -0600 | [diff] [blame] | 1351 | const std::unique_lock lock(hwc_->GetResMan().GetMainLock()); |
| 1352 | HwcDisplay* display = GetDisplay(display_id); |
| 1353 | if (display == nullptr) { |
| 1354 | return ToBinderStatus(hwc3::Error::kBadDisplay); |
| 1355 | } |
| 1356 | |
| 1357 | auto error = display->SetVsyncEnabled(static_cast<int32_t>(enabled)); |
| 1358 | return ToBinderStatus(Hwc2toHwc3Error(error)); |
Dennis Tsiang | 33f0ece | 2023-11-29 12:45:04 +0000 | [diff] [blame] | 1359 | } |
| 1360 | |
Drew Davenport | 5951b11 | 2024-08-05 09:44:27 -0600 | [diff] [blame] | 1361 | ndk::ScopedAStatus ComposerClient::setIdleTimerEnabled(int64_t /*display_id*/, |
Dennis Tsiang | 33f0ece | 2023-11-29 12:45:04 +0000 | [diff] [blame] | 1362 | int32_t /*timeout*/) { |
| 1363 | DEBUG_FUNC(); |
Drew Davenport | 5951b11 | 2024-08-05 09:44:27 -0600 | [diff] [blame] | 1364 | return ToBinderStatus(hwc3::Error::kUnsupported); |
| 1365 | } |
| 1366 | |
Roman Stratiienko | 445ef20 | 2024-11-27 00:24:48 +0200 | [diff] [blame] | 1367 | #if __ANDROID_API__ >= 34 |
| 1368 | |
Drew Davenport | 7f1761b | 2024-08-20 10:09:43 -0600 | [diff] [blame] | 1369 | ndk::ScopedAStatus ComposerClient::getOverlaySupport( |
| 1370 | OverlayProperties* /*out_overlay_properties*/) { |
| 1371 | return ToBinderStatus(hwc3::Error::kUnsupported); |
| 1372 | } |
| 1373 | |
| 1374 | ndk::ScopedAStatus ComposerClient::getHdrConversionCapabilities( |
| 1375 | std::vector<common::HdrConversionCapability>* /*out_capabilities*/) { |
| 1376 | return ToBinderStatus(hwc3::Error::kUnsupported); |
| 1377 | } |
| 1378 | |
| 1379 | ndk::ScopedAStatus ComposerClient::setHdrConversionStrategy( |
| 1380 | const common::HdrConversionStrategy& /*conversion_strategy*/, |
| 1381 | common::Hdr* /*out_hdr*/) { |
| 1382 | return ToBinderStatus(hwc3::Error::kUnsupported); |
| 1383 | } |
| 1384 | |
| 1385 | ndk::ScopedAStatus ComposerClient::setRefreshRateChangedCallbackDebugEnabled( |
| 1386 | int64_t /*display*/, bool /*enabled*/) { |
| 1387 | return ToBinderStatus(hwc3::Error::kUnsupported); |
| 1388 | } |
| 1389 | |
Roman Stratiienko | 445ef20 | 2024-11-27 00:24:48 +0200 | [diff] [blame] | 1390 | #endif |
| 1391 | |
Roman Stratiienko | 71a8f02 | 2024-10-16 23:17:33 +0300 | [diff] [blame] | 1392 | #if __ANDROID_API__ >= 35 |
| 1393 | |
Drew Davenport | 7f1761b | 2024-08-20 10:09:43 -0600 | [diff] [blame] | 1394 | ndk::ScopedAStatus ComposerClient::getDisplayConfigurations( |
Drew Davenport | f7e8833 | 2024-09-06 12:54:38 -0600 | [diff] [blame] | 1395 | int64_t display_id, int32_t /*max_frame_interval_ns*/, |
Drew Davenport | 7f1761b | 2024-08-20 10:09:43 -0600 | [diff] [blame] | 1396 | std::vector<DisplayConfiguration>* configurations) { |
Drew Davenport | f7e8833 | 2024-09-06 12:54:38 -0600 | [diff] [blame] | 1397 | DEBUG_FUNC(); |
| 1398 | const std::unique_lock lock(hwc_->GetResMan().GetMainLock()); |
| 1399 | HwcDisplay* display = GetDisplay(display_id); |
| 1400 | if (display == nullptr) { |
| 1401 | return ToBinderStatus(hwc3::Error::kBadDisplay); |
| 1402 | } |
| 1403 | |
| 1404 | const HwcDisplayConfigs& configs = display->GetDisplayConfigs(); |
| 1405 | for (const auto& [id, config] : configs.hwc_configs) { |
Drew Davenport | 1afb579 | 2024-09-24 12:53:22 -0600 | [diff] [blame] | 1406 | configurations->push_back( |
| 1407 | HwcDisplayConfigToAidlConfiguration(configs, config)); |
Drew Davenport | f7e8833 | 2024-09-06 12:54:38 -0600 | [diff] [blame] | 1408 | } |
| 1409 | return ndk::ScopedAStatus::ok(); |
Drew Davenport | 7f1761b | 2024-08-20 10:09:43 -0600 | [diff] [blame] | 1410 | } |
| 1411 | |
| 1412 | ndk::ScopedAStatus ComposerClient::notifyExpectedPresent( |
Roman Stratiienko | 7c8cc4e | 2025-01-25 22:41:53 +0200 | [diff] [blame] | 1413 | int64_t /*display*/, |
| 1414 | const ClockMonotonicTimestamp& /*expected_present_time*/, |
Drew Davenport | 7f1761b | 2024-08-20 10:09:43 -0600 | [diff] [blame] | 1415 | int32_t /*frame_interval_ns*/) { |
| 1416 | return ToBinderStatus(hwc3::Error::kUnsupported); |
| 1417 | } |
| 1418 | |
Roman Stratiienko | 71a8f02 | 2024-10-16 23:17:33 +0300 | [diff] [blame] | 1419 | #endif |
| 1420 | |
Drew Davenport | 5951b11 | 2024-08-05 09:44:27 -0600 | [diff] [blame] | 1421 | std::string ComposerClient::Dump() { |
| 1422 | uint32_t size = 0; |
| 1423 | hwc_->Dump(&size, nullptr); |
| 1424 | |
| 1425 | std::string buffer(size, '\0'); |
| 1426 | hwc_->Dump(&size, &buffer.front()); |
| 1427 | return buffer; |
Dennis Tsiang | 33f0ece | 2023-11-29 12:45:04 +0000 | [diff] [blame] | 1428 | } |
| 1429 | |
| 1430 | ::ndk::SpAIBinder ComposerClient::createBinder() { |
| 1431 | auto binder = BnComposerClient::createBinder(); |
| 1432 | AIBinder_setInheritRt(binder.get(), true); |
| 1433 | return binder; |
| 1434 | } |
| 1435 | |
Drew Davenport | 5951b11 | 2024-08-05 09:44:27 -0600 | [diff] [blame] | 1436 | void ComposerClient::ExecuteSetDisplayClientTarget( |
| 1437 | uint64_t display_id, const ClientTarget& command) { |
| 1438 | auto* display = GetDisplay(display_id); |
| 1439 | if (display == nullptr) { |
| 1440 | cmd_result_writer_->AddError(hwc3::Error::kBadDisplay); |
| 1441 | return; |
| 1442 | } |
| 1443 | |
Roman Stratiienko | 7c8cc4e | 2025-01-25 22:41:53 +0200 | [diff] [blame] | 1444 | auto& client_layer = display->GetClientLayer(); |
| 1445 | auto hwc3layer = GetHwc3Layer(client_layer); |
Drew Davenport | 5951b11 | 2024-08-05 09:44:27 -0600 | [diff] [blame] | 1446 | |
Roman Stratiienko | 7c8cc4e | 2025-01-25 22:41:53 +0200 | [diff] [blame] | 1447 | std::optional<buffer_handle_t> raw_buffer = std::nullopt; |
| 1448 | if (command.buffer.handle) { |
| 1449 | raw_buffer = ::android::makeFromAidl(*command.buffer.handle); |
Drew Davenport | 5951b11 | 2024-08-05 09:44:27 -0600 | [diff] [blame] | 1450 | } |
| 1451 | |
| 1452 | // NOLINTNEXTLINE(cppcoreguidelines-pro-type-const-cast) |
| 1453 | auto fence = const_cast<::ndk::ScopedFileDescriptor&>(command.buffer.fence) |
| 1454 | .release(); |
Roman Stratiienko | 70ab939 | 2025-01-23 12:11:48 +0200 | [diff] [blame] | 1455 | |
Roman Stratiienko | 7c8cc4e | 2025-01-25 22:41:53 +0200 | [diff] [blame] | 1456 | auto properties = hwc3layer->HandleNextBuffer(raw_buffer, |
| 1457 | ::android::MakeSharedFd(fence), |
| 1458 | command.buffer.slot); |
| 1459 | |
| 1460 | if (!properties) { |
| 1461 | ALOGE("Failed to import client target buffer."); |
| 1462 | /* Here, sending an error would be the natural way to do the thing. |
| 1463 | * But VTS checks for no error. Is it the VTS issue? |
| 1464 | * https://cs.android.com/android/platform/superproject/main/+/main:hardware/interfaces/graphics/composer/aidl/vts/VtsHalGraphicsComposer3_TargetTest.cpp;l=1892;drc=2647200f4c535ca6567b452695b7d13f2aaf3f2a |
| 1465 | */ |
| 1466 | return; |
| 1467 | } |
| 1468 | |
| 1469 | properties->color_space = AidlToColorSpace(command.dataspace); |
| 1470 | properties->sample_range = AidlToSampleRange(command.dataspace); |
| 1471 | |
| 1472 | client_layer.SetLayerProperties(properties.value()); |
Drew Davenport | 5951b11 | 2024-08-05 09:44:27 -0600 | [diff] [blame] | 1473 | } |
| 1474 | |
| 1475 | void ComposerClient::ExecuteSetDisplayOutputBuffer(uint64_t display_id, |
| 1476 | const Buffer& buffer) { |
| 1477 | auto* display = GetDisplay(display_id); |
| 1478 | if (display == nullptr) { |
| 1479 | cmd_result_writer_->AddError(hwc3::Error::kBadDisplay); |
| 1480 | return; |
| 1481 | } |
| 1482 | |
Roman Stratiienko | 70ab939 | 2025-01-23 12:11:48 +0200 | [diff] [blame] | 1483 | auto& writeback_layer = display->GetWritebackLayer(); |
| 1484 | if (!writeback_layer) { |
| 1485 | cmd_result_writer_->AddError(hwc3::Error::kBadLayer); |
Drew Davenport | 5951b11 | 2024-08-05 09:44:27 -0600 | [diff] [blame] | 1486 | return; |
| 1487 | } |
Roman Stratiienko | 70ab939 | 2025-01-23 12:11:48 +0200 | [diff] [blame] | 1488 | |
Roman Stratiienko | 7c8cc4e | 2025-01-25 22:41:53 +0200 | [diff] [blame] | 1489 | auto hwc3layer = GetHwc3Layer(*writeback_layer); |
Roman Stratiienko | 70ab939 | 2025-01-23 12:11:48 +0200 | [diff] [blame] | 1490 | |
Roman Stratiienko | 7c8cc4e | 2025-01-25 22:41:53 +0200 | [diff] [blame] | 1491 | std::optional<buffer_handle_t> raw_buffer = std::nullopt; |
| 1492 | if (buffer.handle) { |
| 1493 | raw_buffer = ::android::makeFromAidl(*buffer.handle); |
| 1494 | } |
| 1495 | |
| 1496 | // NOLINTNEXTLINE(cppcoreguidelines-pro-type-const-cast) |
| 1497 | auto fence = const_cast<::ndk::ScopedFileDescriptor&>(buffer.fence).release(); |
| 1498 | |
| 1499 | auto properties = hwc3layer->HandleNextBuffer(raw_buffer, |
| 1500 | ::android::MakeSharedFd(fence), |
| 1501 | buffer.slot); |
| 1502 | |
| 1503 | if (!properties) { |
| 1504 | cmd_result_writer_->AddError(hwc3::Error::kBadLayer); |
| 1505 | return; |
| 1506 | } |
| 1507 | |
| 1508 | writeback_layer->SetLayerProperties(properties.value()); |
Drew Davenport | 5951b11 | 2024-08-05 09:44:27 -0600 | [diff] [blame] | 1509 | } |
Drew Davenport | 5951b11 | 2024-08-05 09:44:27 -0600 | [diff] [blame] | 1510 | |
Dennis Tsiang | 33f0ece | 2023-11-29 12:45:04 +0000 | [diff] [blame] | 1511 | } // namespace aidl::android::hardware::graphics::composer3::impl |