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