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