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