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