Ady Abraham | 9fc2805 | 2021-10-14 17:21:38 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2016 The Android Open Source Project |
| 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 | |
| 17 | // TODO(b/129481165): remove the #pragma below and fix conversion issues |
| 18 | #pragma clang diagnostic push |
| 19 | #pragma clang diagnostic ignored "-Wconversion" |
| 20 | |
| 21 | #undef LOG_TAG |
| 22 | #define LOG_TAG "HwcComposer" |
| 23 | #define ATRACE_TAG ATRACE_TAG_GRAPHICS |
| 24 | |
| 25 | #include "HidlComposerHal.h" |
| 26 | |
Brian Lindahl | 5b0ffe0 | 2023-06-15 14:19:43 -0600 | [diff] [blame] | 27 | #include <SurfaceFlingerProperties.h> |
Huihong Luo | 791bef9 | 2023-09-19 21:18:45 -0700 | [diff] [blame] | 28 | #include <aidl/android/hardware/graphics/common/DisplayHotplugEvent.h> |
Ady Abraham | 9fc2805 | 2021-10-14 17:21:38 -0700 | [diff] [blame] | 29 | #include <android/binder_manager.h> |
Manasi Navare | fc2a4a7 | 2024-11-12 23:59:21 +0000 | [diff] [blame] | 30 | #include <android/hardware/graphics/composer/2.1/types.h> |
Vishnu Nair | be0ad90 | 2024-06-27 23:38:43 +0000 | [diff] [blame] | 31 | #include <common/trace.h> |
Ady Abraham | 9fc2805 | 2021-10-14 17:21:38 -0700 | [diff] [blame] | 32 | #include <composer-command-buffer/2.2/ComposerCommandBuffer.h> |
| 33 | #include <hidl/HidlTransportSupport.h> |
| 34 | #include <hidl/HidlTransportUtils.h> |
| 35 | #include <log/log.h> |
Brian Lindahl | 5b0ffe0 | 2023-06-15 14:19:43 -0600 | [diff] [blame] | 36 | |
Yichi Chen | 3401b56 | 2022-01-17 15:42:35 +0800 | [diff] [blame] | 37 | #include "HWC2.h" |
Leon Scroggins III | 09c2541 | 2021-12-02 14:49:56 -0500 | [diff] [blame] | 38 | #include "Hal.h" |
Ady Abraham | 9fc2805 | 2021-10-14 17:21:38 -0700 | [diff] [blame] | 39 | |
| 40 | #include <algorithm> |
| 41 | #include <cinttypes> |
| 42 | |
Huihong Luo | 791bef9 | 2023-09-19 21:18:45 -0700 | [diff] [blame] | 43 | using aidl::android::hardware::graphics::common::DisplayHotplugEvent; |
Kriti Dang | 674b937 | 2022-11-18 10:58:44 +0100 | [diff] [blame] | 44 | using aidl::android::hardware::graphics::common::HdrConversionCapability; |
| 45 | using aidl::android::hardware::graphics::common::HdrConversionStrategy; |
Ady Abraham | de549d4 | 2022-01-26 19:19:17 -0800 | [diff] [blame] | 46 | using aidl::android::hardware::graphics::composer3::Capability; |
Alec Mouri | 8506569 | 2022-03-18 00:58:26 +0000 | [diff] [blame] | 47 | using aidl::android::hardware::graphics::composer3::ClientTargetPropertyWithBrightness; |
| 48 | using aidl::android::hardware::graphics::composer3::DimmingStage; |
Leon Scroggins III | 5967aec | 2021-12-29 11:14:22 -0500 | [diff] [blame] | 49 | using aidl::android::hardware::graphics::composer3::DisplayCapability; |
Sally Qi | 11dcd58 | 2024-08-16 18:11:27 -0700 | [diff] [blame] | 50 | using aidl::android::hardware::graphics::composer3::DisplayLuts; |
Sally Qi | 0abc4a5 | 2024-09-26 16:13:06 -0700 | [diff] [blame] | 51 | using aidl::android::hardware::graphics::composer3::Luts; |
Sally Qi | 0cbd08b | 2022-08-17 12:12:28 -0700 | [diff] [blame] | 52 | using aidl::android::hardware::graphics::composer3::OverlayProperties; |
Leon Scroggins III | 5967aec | 2021-12-29 11:14:22 -0500 | [diff] [blame] | 53 | |
Ady Abraham | 9fc2805 | 2021-10-14 17:21:38 -0700 | [diff] [blame] | 54 | namespace android { |
| 55 | |
| 56 | using hardware::hidl_handle; |
| 57 | using hardware::hidl_vec; |
| 58 | using hardware::Return; |
| 59 | |
| 60 | namespace Hwc2 { |
Yichi Chen | 3401b56 | 2022-01-17 15:42:35 +0800 | [diff] [blame] | 61 | namespace { |
| 62 | |
| 63 | using android::hardware::Return; |
| 64 | using android::hardware::Void; |
| 65 | using android::HWC2::ComposerCallback; |
| 66 | |
| 67 | class ComposerCallbackBridge : public IComposerCallback { |
| 68 | public: |
| 69 | ComposerCallbackBridge(ComposerCallback& callback, bool vsyncSwitchingSupported) |
| 70 | : mCallback(callback), mVsyncSwitchingSupported(vsyncSwitchingSupported) {} |
| 71 | |
Huihong Luo | 791bef9 | 2023-09-19 21:18:45 -0700 | [diff] [blame] | 72 | // For code sharing purposes, `ComposerCallback` (implemented by SurfaceFlinger) |
| 73 | // replaced `onComposerHalHotplug` with `onComposerHalHotplugEvent` by converting |
| 74 | // from HIDL's connection into an AIDL DisplayHotplugEvent. |
Yichi Chen | 3401b56 | 2022-01-17 15:42:35 +0800 | [diff] [blame] | 75 | Return<void> onHotplug(Display display, Connection connection) override { |
Huihong Luo | 791bef9 | 2023-09-19 21:18:45 -0700 | [diff] [blame] | 76 | const auto event = connection == Connection::CONNECTED ? DisplayHotplugEvent::CONNECTED |
| 77 | : DisplayHotplugEvent::DISCONNECTED; |
| 78 | mCallback.onComposerHalHotplugEvent(display, event); |
Yichi Chen | 3401b56 | 2022-01-17 15:42:35 +0800 | [diff] [blame] | 79 | return Void(); |
| 80 | } |
| 81 | |
| 82 | Return<void> onRefresh(Display display) override { |
| 83 | mCallback.onComposerHalRefresh(display); |
| 84 | return Void(); |
| 85 | } |
| 86 | |
| 87 | Return<void> onVsync(Display display, int64_t timestamp) override { |
| 88 | if (!mVsyncSwitchingSupported) { |
| 89 | mCallback.onComposerHalVsync(display, timestamp, std::nullopt); |
| 90 | } else { |
| 91 | ALOGW("Unexpected onVsync callback on composer >= 2.4, ignoring."); |
| 92 | } |
| 93 | return Void(); |
| 94 | } |
| 95 | |
| 96 | Return<void> onVsync_2_4(Display display, int64_t timestamp, |
| 97 | VsyncPeriodNanos vsyncPeriodNanos) override { |
| 98 | if (mVsyncSwitchingSupported) { |
| 99 | mCallback.onComposerHalVsync(display, timestamp, vsyncPeriodNanos); |
| 100 | } else { |
| 101 | ALOGW("Unexpected onVsync_2_4 callback on composer <= 2.3, ignoring."); |
| 102 | } |
| 103 | return Void(); |
| 104 | } |
| 105 | |
| 106 | Return<void> onVsyncPeriodTimingChanged(Display display, |
| 107 | const VsyncPeriodChangeTimeline& timeline) override { |
| 108 | mCallback.onComposerHalVsyncPeriodTimingChanged(display, timeline); |
| 109 | return Void(); |
| 110 | } |
| 111 | |
| 112 | Return<void> onSeamlessPossible(Display display) override { |
| 113 | mCallback.onComposerHalSeamlessPossible(display); |
| 114 | return Void(); |
| 115 | } |
| 116 | |
| 117 | private: |
| 118 | ComposerCallback& mCallback; |
| 119 | const bool mVsyncSwitchingSupported; |
| 120 | }; |
| 121 | |
| 122 | } // namespace |
Ady Abraham | 9fc2805 | 2021-10-14 17:21:38 -0700 | [diff] [blame] | 123 | |
| 124 | HidlComposer::~HidlComposer() = default; |
| 125 | |
| 126 | namespace { |
| 127 | |
| 128 | class BufferHandle { |
| 129 | public: |
| 130 | explicit BufferHandle(const native_handle_t* buffer) { |
| 131 | // nullptr is not a valid handle to HIDL |
| 132 | mHandle = (buffer) ? buffer : native_handle_init(mStorage, 0, 0); |
| 133 | } |
| 134 | |
| 135 | operator const hidl_handle&() const // NOLINT(google-explicit-constructor) |
| 136 | { |
| 137 | return mHandle; |
| 138 | } |
| 139 | |
| 140 | private: |
| 141 | NATIVE_HANDLE_DECLARE_STORAGE(mStorage, 0, 0); |
| 142 | hidl_handle mHandle; |
| 143 | }; |
| 144 | |
| 145 | class FenceHandle { |
| 146 | public: |
| 147 | FenceHandle(int fd, bool owned) : mOwned(owned) { |
| 148 | native_handle_t* handle; |
| 149 | if (fd >= 0) { |
| 150 | handle = native_handle_init(mStorage, 1, 0); |
| 151 | handle->data[0] = fd; |
| 152 | } else { |
| 153 | // nullptr is not a valid handle to HIDL |
| 154 | handle = native_handle_init(mStorage, 0, 0); |
| 155 | } |
| 156 | mHandle = handle; |
| 157 | } |
| 158 | |
| 159 | ~FenceHandle() { |
| 160 | if (mOwned) { |
| 161 | native_handle_close(mHandle); |
| 162 | } |
| 163 | } |
| 164 | |
| 165 | operator const hidl_handle&() const // NOLINT(google-explicit-constructor) |
| 166 | { |
| 167 | return mHandle; |
| 168 | } |
| 169 | |
| 170 | private: |
| 171 | bool mOwned; |
| 172 | NATIVE_HANDLE_DECLARE_STORAGE(mStorage, 1, 0); |
| 173 | hidl_handle mHandle; |
| 174 | }; |
| 175 | |
| 176 | // assume NO_RESOURCES when Status::isOk returns false |
Manasi Navare | fc2a4a7 | 2024-11-12 23:59:21 +0000 | [diff] [blame] | 177 | constexpr V2_1::Error kDefaultError = V2_1::Error::NO_RESOURCES; |
Ady Abraham | 9fc2805 | 2021-10-14 17:21:38 -0700 | [diff] [blame] | 178 | constexpr V2_4::Error kDefaultError_2_4 = static_cast<V2_4::Error>(kDefaultError); |
| 179 | |
| 180 | template <typename T, typename U> |
| 181 | T unwrapRet(Return<T>& ret, const U& default_val) { |
| 182 | return (ret.isOk()) ? static_cast<T>(ret) : static_cast<T>(default_val); |
| 183 | } |
| 184 | |
Manasi Navare | fc2a4a7 | 2024-11-12 23:59:21 +0000 | [diff] [blame] | 185 | V2_1::Error unwrapRet(Return<V2_1::Error>& ret) { |
Ady Abraham | 9fc2805 | 2021-10-14 17:21:38 -0700 | [diff] [blame] | 186 | return unwrapRet(ret, kDefaultError); |
| 187 | } |
| 188 | |
Ady Abraham | de549d4 | 2022-01-26 19:19:17 -0800 | [diff] [blame] | 189 | template <typename To, typename From> |
| 190 | To translate(From x) { |
| 191 | return static_cast<To>(x); |
| 192 | } |
| 193 | |
| 194 | template <typename To, typename From> |
| 195 | std::vector<To> translate(const hidl_vec<From>& in) { |
| 196 | std::vector<To> out; |
| 197 | out.reserve(in.size()); |
| 198 | std::transform(in.begin(), in.end(), std::back_inserter(out), |
| 199 | [](From x) { return translate<To>(x); }); |
| 200 | return out; |
| 201 | } |
| 202 | |
Brian Lindahl | 90553da | 2022-12-06 13:36:30 -0700 | [diff] [blame] | 203 | sp<GraphicBuffer> allocateClearSlotBuffer() { |
Brian Lindahl | 5b0ffe0 | 2023-06-15 14:19:43 -0600 | [diff] [blame] | 204 | if (!sysprop::clear_slots_with_set_layer_buffer(false)) { |
| 205 | return nullptr; |
| 206 | } |
Brian Lindahl | 90553da | 2022-12-06 13:36:30 -0700 | [diff] [blame] | 207 | sp<GraphicBuffer> buffer = sp<GraphicBuffer>::make(1, 1, PIXEL_FORMAT_RGBX_8888, |
| 208 | GraphicBuffer::USAGE_HW_COMPOSER | |
| 209 | GraphicBuffer::USAGE_SW_READ_OFTEN | |
| 210 | GraphicBuffer::USAGE_SW_WRITE_OFTEN, |
| 211 | "HidlComposer"); |
| 212 | if (!buffer || buffer->initCheck() != ::android::OK) { |
| 213 | return nullptr; |
| 214 | } |
Yi Kong | 01b8126 | 2024-08-12 07:30:15 +0800 | [diff] [blame] | 215 | return buffer; |
Brian Lindahl | 90553da | 2022-12-06 13:36:30 -0700 | [diff] [blame] | 216 | } |
| 217 | |
Ady Abraham | 9fc2805 | 2021-10-14 17:21:38 -0700 | [diff] [blame] | 218 | } // anonymous namespace |
| 219 | |
Brian Lindahl | 90553da | 2022-12-06 13:36:30 -0700 | [diff] [blame] | 220 | HidlComposer::HidlComposer(const std::string& serviceName) |
| 221 | : mClearSlotBuffer(allocateClearSlotBuffer()), mWriter(kWriterInitialSize) { |
Ady Abraham | 9fc2805 | 2021-10-14 17:21:38 -0700 | [diff] [blame] | 222 | mComposer = V2_1::IComposer::getService(serviceName); |
| 223 | |
| 224 | if (mComposer == nullptr) { |
| 225 | LOG_ALWAYS_FATAL("failed to get hwcomposer service"); |
| 226 | } |
| 227 | |
| 228 | if (sp<IComposer> composer_2_4 = IComposer::castFrom(mComposer)) { |
| 229 | composer_2_4->createClient_2_4([&](const auto& tmpError, const auto& tmpClient) { |
| 230 | if (tmpError == V2_4::Error::NONE) { |
| 231 | mClient = tmpClient; |
| 232 | mClient_2_2 = tmpClient; |
| 233 | mClient_2_3 = tmpClient; |
| 234 | mClient_2_4 = tmpClient; |
| 235 | } |
| 236 | }); |
| 237 | } else if (sp<V2_3::IComposer> composer_2_3 = V2_3::IComposer::castFrom(mComposer)) { |
| 238 | composer_2_3->createClient_2_3([&](const auto& tmpError, const auto& tmpClient) { |
Manasi Navare | fc2a4a7 | 2024-11-12 23:59:21 +0000 | [diff] [blame] | 239 | if (tmpError == V2_1::Error::NONE) { |
Ady Abraham | 9fc2805 | 2021-10-14 17:21:38 -0700 | [diff] [blame] | 240 | mClient = tmpClient; |
| 241 | mClient_2_2 = tmpClient; |
| 242 | mClient_2_3 = tmpClient; |
| 243 | } |
| 244 | }); |
| 245 | } else { |
| 246 | mComposer->createClient([&](const auto& tmpError, const auto& tmpClient) { |
Manasi Navare | fc2a4a7 | 2024-11-12 23:59:21 +0000 | [diff] [blame] | 247 | if (tmpError != V2_1::Error::NONE) { |
Ady Abraham | 9fc2805 | 2021-10-14 17:21:38 -0700 | [diff] [blame] | 248 | return; |
| 249 | } |
| 250 | |
| 251 | mClient = tmpClient; |
| 252 | if (sp<V2_2::IComposer> composer_2_2 = V2_2::IComposer::castFrom(mComposer)) { |
| 253 | mClient_2_2 = V2_2::IComposerClient::castFrom(mClient); |
| 254 | LOG_ALWAYS_FATAL_IF(mClient_2_2 == nullptr, |
| 255 | "IComposer 2.2 did not return IComposerClient 2.2"); |
| 256 | } |
| 257 | }); |
| 258 | } |
| 259 | |
| 260 | if (mClient == nullptr) { |
| 261 | LOG_ALWAYS_FATAL("failed to create composer client"); |
| 262 | } |
Brian Lindahl | 90553da | 2022-12-06 13:36:30 -0700 | [diff] [blame] | 263 | |
Brian Lindahl | 5b0ffe0 | 2023-06-15 14:19:43 -0600 | [diff] [blame] | 264 | if (!mClearSlotBuffer && sysprop::clear_slots_with_set_layer_buffer(false)) { |
Brian Lindahl | 90553da | 2022-12-06 13:36:30 -0700 | [diff] [blame] | 265 | LOG_ALWAYS_FATAL("Failed to allocate a buffer for clearing layer buffer slots"); |
| 266 | return; |
| 267 | } |
Ady Abraham | 9fc2805 | 2021-10-14 17:21:38 -0700 | [diff] [blame] | 268 | } |
| 269 | |
Ady Abraham | 4d211cf | 2021-12-14 16:19:03 -0800 | [diff] [blame] | 270 | bool HidlComposer::isSupported(OptionalFeature feature) const { |
| 271 | switch (feature) { |
| 272 | case OptionalFeature::RefreshRateSwitching: |
| 273 | return mClient_2_4 != nullptr; |
Ady Abraham | 43065bd | 2021-12-10 17:22:15 -0800 | [diff] [blame] | 274 | case OptionalFeature::ExpectedPresentTime: |
Alec Mouri | cdf1679 | 2021-12-10 13:16:06 -0800 | [diff] [blame] | 275 | case OptionalFeature::DisplayBrightnessCommand: |
ramindani | 32cf060 | 2022-03-02 02:30:29 +0000 | [diff] [blame] | 276 | case OptionalFeature::KernelIdleTimer: |
ramindani | 06e518e | 2022-03-14 18:47:53 +0000 | [diff] [blame] | 277 | case OptionalFeature::PhysicalDisplayOrientation: |
Ady Abraham | 43065bd | 2021-12-10 17:22:15 -0800 | [diff] [blame] | 278 | return false; |
Ady Abraham | 4d211cf | 2021-12-14 16:19:03 -0800 | [diff] [blame] | 279 | } |
| 280 | } |
| 281 | |
ramindani | 19919ff | 2023-12-07 11:27:06 -0800 | [diff] [blame] | 282 | bool HidlComposer::isVrrSupported() const { |
| 283 | // VRR is not supported on the HIDL composer. |
ramindani | 0cd1d8d | 2023-06-13 13:43:23 -0700 | [diff] [blame] | 284 | return false; |
| 285 | }; |
| 286 | |
Ady Abraham | de549d4 | 2022-01-26 19:19:17 -0800 | [diff] [blame] | 287 | std::vector<Capability> HidlComposer::getCapabilities() { |
| 288 | std::vector<Capability> capabilities; |
| 289 | mComposer->getCapabilities([&](const auto& tmpCapabilities) { |
| 290 | capabilities = translate<Capability>(tmpCapabilities); |
| 291 | }); |
Ady Abraham | 9fc2805 | 2021-10-14 17:21:38 -0700 | [diff] [blame] | 292 | return capabilities; |
| 293 | } |
| 294 | |
| 295 | std::string HidlComposer::dumpDebugInfo() { |
| 296 | std::string info; |
Ady Abraham | b7b9a4f | 2024-01-25 15:57:24 -0800 | [diff] [blame] | 297 | info += std::string(mComposer->descriptor) + "\n"; |
Ady Abraham | 9fc2805 | 2021-10-14 17:21:38 -0700 | [diff] [blame] | 298 | mComposer->dumpDebugInfo([&](const auto& tmpInfo) { info = tmpInfo.c_str(); }); |
| 299 | |
| 300 | return info; |
| 301 | } |
| 302 | |
| 303 | void HidlComposer::registerCallback(const sp<IComposerCallback>& callback) { |
| 304 | android::hardware::setMinSchedulerPolicy(callback, SCHED_FIFO, 2); |
| 305 | |
| 306 | auto ret = [&]() { |
| 307 | if (mClient_2_4) { |
| 308 | return mClient_2_4->registerCallback_2_4(callback); |
| 309 | } |
| 310 | return mClient->registerCallback(callback); |
| 311 | }(); |
| 312 | if (!ret.isOk()) { |
| 313 | ALOGE("failed to register IComposerCallback"); |
| 314 | } |
| 315 | } |
| 316 | |
Leon Scroggins III | e24d78f | 2022-09-20 16:38:19 -0400 | [diff] [blame] | 317 | Error HidlComposer::executeCommands(Display) { |
Ady Abraham | 9fc2805 | 2021-10-14 17:21:38 -0700 | [diff] [blame] | 318 | return execute(); |
| 319 | } |
| 320 | |
| 321 | uint32_t HidlComposer::getMaxVirtualDisplayCount() { |
| 322 | auto ret = mClient->getMaxVirtualDisplayCount(); |
| 323 | return unwrapRet(ret, 0); |
| 324 | } |
| 325 | |
| 326 | Error HidlComposer::createVirtualDisplay(uint32_t width, uint32_t height, PixelFormat* format, |
| 327 | Display* outDisplay) { |
| 328 | const uint32_t bufferSlotCount = 1; |
Manasi Navare | fc2a4a7 | 2024-11-12 23:59:21 +0000 | [diff] [blame] | 329 | Error error = static_cast<Error>(kDefaultError); |
Ady Abraham | 9fc2805 | 2021-10-14 17:21:38 -0700 | [diff] [blame] | 330 | if (mClient_2_2) { |
| 331 | mClient_2_2->createVirtualDisplay_2_2(width, height, |
| 332 | static_cast<types::V1_1::PixelFormat>(*format), |
| 333 | bufferSlotCount, |
| 334 | [&](const auto& tmpError, const auto& tmpDisplay, |
| 335 | const auto& tmpFormat) { |
Manasi Navare | fc2a4a7 | 2024-11-12 23:59:21 +0000 | [diff] [blame] | 336 | error = static_cast<Error>(tmpError); |
Ady Abraham | 9fc2805 | 2021-10-14 17:21:38 -0700 | [diff] [blame] | 337 | if (error != Error::NONE) { |
| 338 | return; |
| 339 | } |
| 340 | |
| 341 | *outDisplay = tmpDisplay; |
| 342 | *format = static_cast<types::V1_2::PixelFormat>( |
| 343 | tmpFormat); |
| 344 | }); |
| 345 | } else { |
| 346 | mClient->createVirtualDisplay(width, height, static_cast<types::V1_0::PixelFormat>(*format), |
| 347 | bufferSlotCount, |
| 348 | [&](const auto& tmpError, const auto& tmpDisplay, |
| 349 | const auto& tmpFormat) { |
Manasi Navare | fc2a4a7 | 2024-11-12 23:59:21 +0000 | [diff] [blame] | 350 | error = static_cast<Error>(tmpError); |
Ady Abraham | 9fc2805 | 2021-10-14 17:21:38 -0700 | [diff] [blame] | 351 | if (error != Error::NONE) { |
| 352 | return; |
| 353 | } |
| 354 | |
| 355 | *outDisplay = tmpDisplay; |
| 356 | *format = static_cast<PixelFormat>(tmpFormat); |
| 357 | }); |
| 358 | } |
| 359 | |
| 360 | return error; |
| 361 | } |
| 362 | |
| 363 | Error HidlComposer::destroyVirtualDisplay(Display display) { |
| 364 | auto ret = mClient->destroyVirtualDisplay(display); |
Manasi Navare | fc2a4a7 | 2024-11-12 23:59:21 +0000 | [diff] [blame] | 365 | return static_cast<Error>(unwrapRet(ret)); |
Ady Abraham | 9fc2805 | 2021-10-14 17:21:38 -0700 | [diff] [blame] | 366 | } |
| 367 | |
| 368 | Error HidlComposer::acceptDisplayChanges(Display display) { |
| 369 | mWriter.selectDisplay(display); |
| 370 | mWriter.acceptDisplayChanges(); |
| 371 | return Error::NONE; |
| 372 | } |
| 373 | |
| 374 | Error HidlComposer::createLayer(Display display, Layer* outLayer) { |
Manasi Navare | fc2a4a7 | 2024-11-12 23:59:21 +0000 | [diff] [blame] | 375 | Error error = static_cast<Error>(kDefaultError); |
Ady Abraham | 9fc2805 | 2021-10-14 17:21:38 -0700 | [diff] [blame] | 376 | mClient->createLayer(display, kMaxLayerBufferCount, |
| 377 | [&](const auto& tmpError, const auto& tmpLayer) { |
Manasi Navare | fc2a4a7 | 2024-11-12 23:59:21 +0000 | [diff] [blame] | 378 | error = static_cast<Error>(tmpError); |
Ady Abraham | 9fc2805 | 2021-10-14 17:21:38 -0700 | [diff] [blame] | 379 | if (error != Error::NONE) { |
| 380 | return; |
| 381 | } |
| 382 | |
| 383 | *outLayer = tmpLayer; |
| 384 | }); |
| 385 | |
| 386 | return error; |
| 387 | } |
| 388 | |
| 389 | Error HidlComposer::destroyLayer(Display display, Layer layer) { |
| 390 | auto ret = mClient->destroyLayer(display, layer); |
Manasi Navare | fc2a4a7 | 2024-11-12 23:59:21 +0000 | [diff] [blame] | 391 | return static_cast<Error>(unwrapRet(ret)); |
Ady Abraham | 9fc2805 | 2021-10-14 17:21:38 -0700 | [diff] [blame] | 392 | } |
| 393 | |
| 394 | Error HidlComposer::getActiveConfig(Display display, Config* outConfig) { |
Manasi Navare | fc2a4a7 | 2024-11-12 23:59:21 +0000 | [diff] [blame] | 395 | Error error = static_cast<Error>(kDefaultError); |
Ady Abraham | 9fc2805 | 2021-10-14 17:21:38 -0700 | [diff] [blame] | 396 | mClient->getActiveConfig(display, [&](const auto& tmpError, const auto& tmpConfig) { |
Manasi Navare | fc2a4a7 | 2024-11-12 23:59:21 +0000 | [diff] [blame] | 397 | error = static_cast<Error>(tmpError); |
Ady Abraham | 9fc2805 | 2021-10-14 17:21:38 -0700 | [diff] [blame] | 398 | if (error != Error::NONE) { |
| 399 | return; |
| 400 | } |
| 401 | |
| 402 | *outConfig = tmpConfig; |
| 403 | }); |
| 404 | |
| 405 | return error; |
| 406 | } |
| 407 | |
| 408 | Error HidlComposer::getChangedCompositionTypes( |
| 409 | Display display, std::vector<Layer>* outLayers, |
Leon Scroggins III | 2e1aa18 | 2021-12-01 17:33:12 -0500 | [diff] [blame] | 410 | std::vector<aidl::android::hardware::graphics::composer3::Composition>* outTypes) { |
Ady Abraham | 9fc2805 | 2021-10-14 17:21:38 -0700 | [diff] [blame] | 411 | mReader.takeChangedCompositionTypes(display, outLayers, outTypes); |
| 412 | return Error::NONE; |
| 413 | } |
| 414 | |
| 415 | Error HidlComposer::getColorModes(Display display, std::vector<ColorMode>* outModes) { |
Manasi Navare | fc2a4a7 | 2024-11-12 23:59:21 +0000 | [diff] [blame] | 416 | Error error = static_cast<Error>(kDefaultError); |
Ady Abraham | 9fc2805 | 2021-10-14 17:21:38 -0700 | [diff] [blame] | 417 | |
| 418 | if (mClient_2_3) { |
| 419 | mClient_2_3->getColorModes_2_3(display, [&](const auto& tmpError, const auto& tmpModes) { |
Manasi Navare | fc2a4a7 | 2024-11-12 23:59:21 +0000 | [diff] [blame] | 420 | error = static_cast<Error>(tmpError); |
Ady Abraham | 9fc2805 | 2021-10-14 17:21:38 -0700 | [diff] [blame] | 421 | if (error != Error::NONE) { |
| 422 | return; |
| 423 | } |
| 424 | |
| 425 | *outModes = tmpModes; |
| 426 | }); |
| 427 | } else if (mClient_2_2) { |
| 428 | mClient_2_2->getColorModes_2_2(display, [&](const auto& tmpError, const auto& tmpModes) { |
Manasi Navare | fc2a4a7 | 2024-11-12 23:59:21 +0000 | [diff] [blame] | 429 | error = static_cast<Error>(tmpError); |
Ady Abraham | 9fc2805 | 2021-10-14 17:21:38 -0700 | [diff] [blame] | 430 | if (error != Error::NONE) { |
| 431 | return; |
| 432 | } |
| 433 | |
| 434 | for (types::V1_1::ColorMode colorMode : tmpModes) { |
| 435 | outModes->push_back(static_cast<ColorMode>(colorMode)); |
| 436 | } |
| 437 | }); |
| 438 | } else { |
| 439 | mClient->getColorModes(display, [&](const auto& tmpError, const auto& tmpModes) { |
Manasi Navare | fc2a4a7 | 2024-11-12 23:59:21 +0000 | [diff] [blame] | 440 | error = static_cast<Error>(tmpError); |
Ady Abraham | 9fc2805 | 2021-10-14 17:21:38 -0700 | [diff] [blame] | 441 | if (error != Error::NONE) { |
| 442 | return; |
| 443 | } |
| 444 | for (types::V1_0::ColorMode colorMode : tmpModes) { |
| 445 | outModes->push_back(static_cast<ColorMode>(colorMode)); |
| 446 | } |
| 447 | }); |
| 448 | } |
| 449 | |
| 450 | return error; |
| 451 | } |
| 452 | |
| 453 | Error HidlComposer::getDisplayAttribute(Display display, Config config, |
| 454 | IComposerClient::Attribute attribute, int32_t* outValue) { |
Manasi Navare | fc2a4a7 | 2024-11-12 23:59:21 +0000 | [diff] [blame] | 455 | Error error = static_cast<Error>(kDefaultError); |
Ady Abraham | 9fc2805 | 2021-10-14 17:21:38 -0700 | [diff] [blame] | 456 | if (mClient_2_4) { |
| 457 | mClient_2_4->getDisplayAttribute_2_4(display, config, attribute, |
| 458 | [&](const auto& tmpError, const auto& tmpValue) { |
| 459 | error = static_cast<Error>(tmpError); |
| 460 | if (error != Error::NONE) { |
| 461 | return; |
| 462 | } |
| 463 | |
| 464 | *outValue = tmpValue; |
| 465 | }); |
| 466 | } else { |
| 467 | mClient->getDisplayAttribute(display, config, |
| 468 | static_cast<V2_1::IComposerClient::Attribute>(attribute), |
| 469 | [&](const auto& tmpError, const auto& tmpValue) { |
Manasi Navare | fc2a4a7 | 2024-11-12 23:59:21 +0000 | [diff] [blame] | 470 | error = static_cast<Error>(tmpError); |
Ady Abraham | 9fc2805 | 2021-10-14 17:21:38 -0700 | [diff] [blame] | 471 | if (error != Error::NONE) { |
| 472 | return; |
| 473 | } |
| 474 | |
| 475 | *outValue = tmpValue; |
| 476 | }); |
| 477 | } |
| 478 | |
| 479 | return error; |
| 480 | } |
| 481 | |
| 482 | Error HidlComposer::getDisplayConfigs(Display display, std::vector<Config>* outConfigs) { |
Manasi Navare | fc2a4a7 | 2024-11-12 23:59:21 +0000 | [diff] [blame] | 483 | Error error = static_cast<Error>(kDefaultError); |
Ady Abraham | 9fc2805 | 2021-10-14 17:21:38 -0700 | [diff] [blame] | 484 | mClient->getDisplayConfigs(display, [&](const auto& tmpError, const auto& tmpConfigs) { |
Manasi Navare | fc2a4a7 | 2024-11-12 23:59:21 +0000 | [diff] [blame] | 485 | error = static_cast<Error>(tmpError); |
Ady Abraham | 9fc2805 | 2021-10-14 17:21:38 -0700 | [diff] [blame] | 486 | if (error != Error::NONE) { |
| 487 | return; |
| 488 | } |
| 489 | |
| 490 | *outConfigs = tmpConfigs; |
| 491 | }); |
| 492 | |
| 493 | return error; |
| 494 | } |
| 495 | |
ramindani | 263a3f1 | 2023-07-18 20:44:49 -0700 | [diff] [blame] | 496 | Error HidlComposer::getDisplayConfigurations(Display, int32_t /*maxFrameIntervalNs*/, |
| 497 | std::vector<DisplayConfiguration>*) { |
ramindani | 0cd1d8d | 2023-06-13 13:43:23 -0700 | [diff] [blame] | 498 | LOG_ALWAYS_FATAL("getDisplayConfigurations should not have been called on this, as " |
| 499 | "it's a HWC3 interface version 3 feature"); |
| 500 | } |
| 501 | |
Ady Abraham | 9fc2805 | 2021-10-14 17:21:38 -0700 | [diff] [blame] | 502 | Error HidlComposer::getDisplayName(Display display, std::string* outName) { |
Manasi Navare | fc2a4a7 | 2024-11-12 23:59:21 +0000 | [diff] [blame] | 503 | Error error = static_cast<Error>(kDefaultError); |
Ady Abraham | 9fc2805 | 2021-10-14 17:21:38 -0700 | [diff] [blame] | 504 | mClient->getDisplayName(display, [&](const auto& tmpError, const auto& tmpName) { |
Manasi Navare | fc2a4a7 | 2024-11-12 23:59:21 +0000 | [diff] [blame] | 505 | error = static_cast<Error>(tmpError); |
Ady Abraham | 9fc2805 | 2021-10-14 17:21:38 -0700 | [diff] [blame] | 506 | if (error != Error::NONE) { |
| 507 | return; |
| 508 | } |
| 509 | |
| 510 | *outName = tmpName.c_str(); |
| 511 | }); |
| 512 | |
| 513 | return error; |
| 514 | } |
| 515 | |
| 516 | Error HidlComposer::getDisplayRequests(Display display, uint32_t* outDisplayRequestMask, |
| 517 | std::vector<Layer>* outLayers, |
| 518 | std::vector<uint32_t>* outLayerRequestMasks) { |
| 519 | mReader.takeDisplayRequests(display, outDisplayRequestMask, outLayers, outLayerRequestMasks); |
| 520 | return Error::NONE; |
| 521 | } |
| 522 | |
| 523 | Error HidlComposer::getDozeSupport(Display display, bool* outSupport) { |
Manasi Navare | fc2a4a7 | 2024-11-12 23:59:21 +0000 | [diff] [blame] | 524 | Error error = static_cast<Error>(kDefaultError); |
Ady Abraham | 9fc2805 | 2021-10-14 17:21:38 -0700 | [diff] [blame] | 525 | mClient->getDozeSupport(display, [&](const auto& tmpError, const auto& tmpSupport) { |
Manasi Navare | fc2a4a7 | 2024-11-12 23:59:21 +0000 | [diff] [blame] | 526 | error = static_cast<Error>(tmpError); |
Ady Abraham | 9fc2805 | 2021-10-14 17:21:38 -0700 | [diff] [blame] | 527 | if (error != Error::NONE) { |
| 528 | return; |
| 529 | } |
| 530 | |
| 531 | *outSupport = tmpSupport; |
| 532 | }); |
| 533 | |
| 534 | return error; |
| 535 | } |
| 536 | |
ramindani | 32cf060 | 2022-03-02 02:30:29 +0000 | [diff] [blame] | 537 | Error HidlComposer::hasDisplayIdleTimerCapability(Display, bool*) { |
| 538 | LOG_ALWAYS_FATAL("hasDisplayIdleTimerCapability should have never been called on this as " |
| 539 | "OptionalFeature::KernelIdleTimer is not supported on HIDL"); |
| 540 | } |
| 541 | |
Marc Kassis | bdf7e4b | 2022-11-04 17:26:48 +0100 | [diff] [blame] | 542 | Error HidlComposer::getHdrCapabilities(Display display, std::vector<Hdr>* outHdrTypes, |
Ady Abraham | 9fc2805 | 2021-10-14 17:21:38 -0700 | [diff] [blame] | 543 | float* outMaxLuminance, float* outMaxAverageLuminance, |
| 544 | float* outMinLuminance) { |
Manasi Navare | fc2a4a7 | 2024-11-12 23:59:21 +0000 | [diff] [blame] | 545 | Error error = static_cast<Error>(kDefaultError); |
Ady Abraham | 9fc2805 | 2021-10-14 17:21:38 -0700 | [diff] [blame] | 546 | if (mClient_2_3) { |
| 547 | mClient_2_3->getHdrCapabilities_2_3(display, |
Marc Kassis | bdf7e4b | 2022-11-04 17:26:48 +0100 | [diff] [blame] | 548 | [&](const auto& tmpError, const auto& tmpHdrTypes, |
Ady Abraham | 9fc2805 | 2021-10-14 17:21:38 -0700 | [diff] [blame] | 549 | const auto& tmpMaxLuminance, |
| 550 | const auto& tmpMaxAverageLuminance, |
| 551 | const auto& tmpMinLuminance) { |
Manasi Navare | fc2a4a7 | 2024-11-12 23:59:21 +0000 | [diff] [blame] | 552 | error = static_cast<Error>(tmpError); |
Ady Abraham | 9fc2805 | 2021-10-14 17:21:38 -0700 | [diff] [blame] | 553 | if (error != Error::NONE) { |
| 554 | return; |
| 555 | } |
Marc Kassis | bdf7e4b | 2022-11-04 17:26:48 +0100 | [diff] [blame] | 556 | *outHdrTypes = translate<ui::Hdr>(tmpHdrTypes); |
Ady Abraham | 9fc2805 | 2021-10-14 17:21:38 -0700 | [diff] [blame] | 557 | |
Ady Abraham | 9fc2805 | 2021-10-14 17:21:38 -0700 | [diff] [blame] | 558 | *outMaxLuminance = tmpMaxLuminance; |
| 559 | *outMaxAverageLuminance = tmpMaxAverageLuminance; |
| 560 | *outMinLuminance = tmpMinLuminance; |
| 561 | }); |
| 562 | } else { |
| 563 | mClient->getHdrCapabilities(display, |
Marc Kassis | bdf7e4b | 2022-11-04 17:26:48 +0100 | [diff] [blame] | 564 | [&](const auto& tmpError, const auto& tmpHdrTypes, |
Ady Abraham | 9fc2805 | 2021-10-14 17:21:38 -0700 | [diff] [blame] | 565 | const auto& tmpMaxLuminance, |
| 566 | const auto& tmpMaxAverageLuminance, |
| 567 | const auto& tmpMinLuminance) { |
Manasi Navare | fc2a4a7 | 2024-11-12 23:59:21 +0000 | [diff] [blame] | 568 | error = static_cast<Error>(tmpError); |
Ady Abraham | 9fc2805 | 2021-10-14 17:21:38 -0700 | [diff] [blame] | 569 | if (error != Error::NONE) { |
| 570 | return; |
| 571 | } |
Marc Kassis | bdf7e4b | 2022-11-04 17:26:48 +0100 | [diff] [blame] | 572 | *outHdrTypes = translate<ui::Hdr>(tmpHdrTypes); |
Ady Abraham | 9fc2805 | 2021-10-14 17:21:38 -0700 | [diff] [blame] | 573 | |
| 574 | *outMaxLuminance = tmpMaxLuminance; |
| 575 | *outMaxAverageLuminance = tmpMaxAverageLuminance; |
| 576 | *outMinLuminance = tmpMinLuminance; |
| 577 | }); |
| 578 | } |
| 579 | |
| 580 | return error; |
| 581 | } |
| 582 | |
Sally Qi | 0cbd08b | 2022-08-17 12:12:28 -0700 | [diff] [blame] | 583 | Error HidlComposer::getOverlaySupport(OverlayProperties* /*outProperties*/) { |
| 584 | return Error::NONE; |
| 585 | } |
| 586 | |
Ady Abraham | 9fc2805 | 2021-10-14 17:21:38 -0700 | [diff] [blame] | 587 | Error HidlComposer::getReleaseFences(Display display, std::vector<Layer>* outLayers, |
| 588 | std::vector<int>* outReleaseFences) { |
| 589 | mReader.takeReleaseFences(display, outLayers, outReleaseFences); |
| 590 | return Error::NONE; |
| 591 | } |
| 592 | |
| 593 | Error HidlComposer::presentDisplay(Display display, int* outPresentFence) { |
Vishnu Nair | be0ad90 | 2024-06-27 23:38:43 +0000 | [diff] [blame] | 594 | SFTRACE_NAME("HwcPresentDisplay"); |
Ady Abraham | 9fc2805 | 2021-10-14 17:21:38 -0700 | [diff] [blame] | 595 | mWriter.selectDisplay(display); |
| 596 | mWriter.presentDisplay(); |
| 597 | |
| 598 | Error error = execute(); |
| 599 | if (error != Error::NONE) { |
| 600 | return error; |
| 601 | } |
| 602 | |
| 603 | mReader.takePresentFence(display, outPresentFence); |
| 604 | |
| 605 | return Error::NONE; |
| 606 | } |
| 607 | |
| 608 | Error HidlComposer::setActiveConfig(Display display, Config config) { |
| 609 | auto ret = mClient->setActiveConfig(display, config); |
Manasi Navare | fc2a4a7 | 2024-11-12 23:59:21 +0000 | [diff] [blame] | 610 | return static_cast<Error>(unwrapRet(ret)); |
Ady Abraham | 9fc2805 | 2021-10-14 17:21:38 -0700 | [diff] [blame] | 611 | } |
| 612 | |
| 613 | Error HidlComposer::setClientTarget(Display display, uint32_t slot, const sp<GraphicBuffer>& target, |
| 614 | int acquireFence, Dataspace dataspace, |
Alec Mouri | f97df4d | 2023-09-06 02:10:05 +0000 | [diff] [blame] | 615 | const std::vector<IComposerClient::Rect>& damage, |
| 616 | float /*hdrSdrRatio*/) { |
Ady Abraham | 9fc2805 | 2021-10-14 17:21:38 -0700 | [diff] [blame] | 617 | mWriter.selectDisplay(display); |
| 618 | |
| 619 | const native_handle_t* handle = nullptr; |
| 620 | if (target.get()) { |
| 621 | handle = target->getNativeBuffer()->handle; |
| 622 | } |
| 623 | |
| 624 | mWriter.setClientTarget(slot, handle, acquireFence, dataspace, damage); |
| 625 | return Error::NONE; |
| 626 | } |
| 627 | |
| 628 | Error HidlComposer::setColorMode(Display display, ColorMode mode, RenderIntent renderIntent) { |
Manasi Navare | fc2a4a7 | 2024-11-12 23:59:21 +0000 | [diff] [blame] | 629 | hardware::Return<V2_1::Error> ret(kDefaultError); |
Ady Abraham | 9fc2805 | 2021-10-14 17:21:38 -0700 | [diff] [blame] | 630 | if (mClient_2_3) { |
| 631 | ret = mClient_2_3->setColorMode_2_3(display, mode, renderIntent); |
| 632 | } else if (mClient_2_2) { |
| 633 | ret = mClient_2_2->setColorMode_2_2(display, static_cast<types::V1_1::ColorMode>(mode), |
| 634 | renderIntent); |
| 635 | } else { |
| 636 | ret = mClient->setColorMode(display, static_cast<types::V1_0::ColorMode>(mode)); |
| 637 | } |
Manasi Navare | fc2a4a7 | 2024-11-12 23:59:21 +0000 | [diff] [blame] | 638 | return static_cast<Error>(unwrapRet(ret)); |
Ady Abraham | 9fc2805 | 2021-10-14 17:21:38 -0700 | [diff] [blame] | 639 | } |
| 640 | |
Ady Abraham | dc011a9 | 2021-12-21 14:06:44 -0800 | [diff] [blame] | 641 | Error HidlComposer::setColorTransform(Display display, const float* matrix) { |
Ady Abraham | 9fc2805 | 2021-10-14 17:21:38 -0700 | [diff] [blame] | 642 | mWriter.selectDisplay(display); |
Ady Abraham | dc011a9 | 2021-12-21 14:06:44 -0800 | [diff] [blame] | 643 | const bool isIdentity = (mat4(matrix) == mat4()); |
| 644 | mWriter.setColorTransform(matrix, |
| 645 | isIdentity ? ColorTransform::IDENTITY |
| 646 | : ColorTransform::ARBITRARY_MATRIX); |
Ady Abraham | 9fc2805 | 2021-10-14 17:21:38 -0700 | [diff] [blame] | 647 | return Error::NONE; |
| 648 | } |
| 649 | |
| 650 | Error HidlComposer::setOutputBuffer(Display display, const native_handle_t* buffer, |
| 651 | int releaseFence) { |
| 652 | mWriter.selectDisplay(display); |
| 653 | mWriter.setOutputBuffer(0, buffer, dup(releaseFence)); |
| 654 | return Error::NONE; |
| 655 | } |
| 656 | |
| 657 | Error HidlComposer::setPowerMode(Display display, IComposerClient::PowerMode mode) { |
Manasi Navare | fc2a4a7 | 2024-11-12 23:59:21 +0000 | [diff] [blame] | 658 | Return<V2_1::Error> ret(V2_1::Error::UNSUPPORTED); |
Ady Abraham | 9fc2805 | 2021-10-14 17:21:38 -0700 | [diff] [blame] | 659 | if (mClient_2_2) { |
| 660 | ret = mClient_2_2->setPowerMode_2_2(display, mode); |
| 661 | } else if (mode != IComposerClient::PowerMode::ON_SUSPEND) { |
| 662 | ret = mClient->setPowerMode(display, static_cast<V2_1::IComposerClient::PowerMode>(mode)); |
| 663 | } |
| 664 | |
Manasi Navare | fc2a4a7 | 2024-11-12 23:59:21 +0000 | [diff] [blame] | 665 | return static_cast<Error>(unwrapRet(ret)); |
Ady Abraham | 9fc2805 | 2021-10-14 17:21:38 -0700 | [diff] [blame] | 666 | } |
| 667 | |
| 668 | Error HidlComposer::setVsyncEnabled(Display display, IComposerClient::Vsync enabled) { |
| 669 | auto ret = mClient->setVsyncEnabled(display, enabled); |
Manasi Navare | fc2a4a7 | 2024-11-12 23:59:21 +0000 | [diff] [blame] | 670 | return static_cast<Error>(unwrapRet(ret)); |
Ady Abraham | 9fc2805 | 2021-10-14 17:21:38 -0700 | [diff] [blame] | 671 | } |
| 672 | |
| 673 | Error HidlComposer::setClientTargetSlotCount(Display display) { |
| 674 | const uint32_t bufferSlotCount = BufferQueue::NUM_BUFFER_SLOTS; |
| 675 | auto ret = mClient->setClientTargetSlotCount(display, bufferSlotCount); |
Manasi Navare | fc2a4a7 | 2024-11-12 23:59:21 +0000 | [diff] [blame] | 676 | return static_cast<Error>(unwrapRet(ret)); |
Ady Abraham | 9fc2805 | 2021-10-14 17:21:38 -0700 | [diff] [blame] | 677 | } |
| 678 | |
Ady Abraham | 43065bd | 2021-12-10 17:22:15 -0800 | [diff] [blame] | 679 | Error HidlComposer::validateDisplay(Display display, nsecs_t /*expectedPresentTime*/, |
ramindani | 09acbb8 | 2023-11-03 09:02:38 -0700 | [diff] [blame] | 680 | int32_t /*frameIntervalNs*/, uint32_t* outNumTypes, |
| 681 | uint32_t* outNumRequests) { |
Vishnu Nair | be0ad90 | 2024-06-27 23:38:43 +0000 | [diff] [blame] | 682 | SFTRACE_NAME("HwcValidateDisplay"); |
Ady Abraham | 9fc2805 | 2021-10-14 17:21:38 -0700 | [diff] [blame] | 683 | mWriter.selectDisplay(display); |
| 684 | mWriter.validateDisplay(); |
| 685 | |
| 686 | Error error = execute(); |
| 687 | if (error != Error::NONE) { |
| 688 | return error; |
| 689 | } |
| 690 | |
| 691 | mReader.hasChanges(display, outNumTypes, outNumRequests); |
| 692 | |
| 693 | return Error::NONE; |
| 694 | } |
| 695 | |
Ady Abraham | 43065bd | 2021-12-10 17:22:15 -0800 | [diff] [blame] | 696 | Error HidlComposer::presentOrValidateDisplay(Display display, nsecs_t /*expectedPresentTime*/, |
ramindani | 4aac32c | 2023-10-30 14:13:30 -0700 | [diff] [blame] | 697 | int32_t /*frameIntervalNs*/, uint32_t* outNumTypes, |
| 698 | uint32_t* outNumRequests, int* outPresentFence, |
| 699 | uint32_t* state) { |
Vishnu Nair | be0ad90 | 2024-06-27 23:38:43 +0000 | [diff] [blame] | 700 | SFTRACE_NAME("HwcPresentOrValidateDisplay"); |
Ady Abraham | 9fc2805 | 2021-10-14 17:21:38 -0700 | [diff] [blame] | 701 | mWriter.selectDisplay(display); |
| 702 | mWriter.presentOrvalidateDisplay(); |
| 703 | |
| 704 | Error error = execute(); |
| 705 | if (error != Error::NONE) { |
| 706 | return error; |
| 707 | } |
| 708 | |
| 709 | mReader.takePresentOrValidateStage(display, state); |
| 710 | |
| 711 | if (*state == 1) { // Present succeeded |
| 712 | mReader.takePresentFence(display, outPresentFence); |
| 713 | } |
| 714 | |
| 715 | if (*state == 0) { // Validate succeeded. |
| 716 | mReader.hasChanges(display, outNumTypes, outNumRequests); |
| 717 | } |
| 718 | |
| 719 | return Error::NONE; |
| 720 | } |
| 721 | |
| 722 | Error HidlComposer::setCursorPosition(Display display, Layer layer, int32_t x, int32_t y) { |
| 723 | mWriter.selectDisplay(display); |
| 724 | mWriter.selectLayer(layer); |
| 725 | mWriter.setLayerCursorPosition(x, y); |
| 726 | return Error::NONE; |
| 727 | } |
| 728 | |
| 729 | Error HidlComposer::setLayerBuffer(Display display, Layer layer, uint32_t slot, |
| 730 | const sp<GraphicBuffer>& buffer, int acquireFence) { |
| 731 | mWriter.selectDisplay(display); |
| 732 | mWriter.selectLayer(layer); |
| 733 | |
| 734 | const native_handle_t* handle = nullptr; |
| 735 | if (buffer.get()) { |
| 736 | handle = buffer->getNativeBuffer()->handle; |
| 737 | } |
| 738 | |
| 739 | mWriter.setLayerBuffer(slot, handle, acquireFence); |
| 740 | return Error::NONE; |
| 741 | } |
| 742 | |
Brian Lindahl | b158a5c | 2022-12-15 15:21:13 -0700 | [diff] [blame] | 743 | Error HidlComposer::setLayerBufferSlotsToClear(Display display, Layer layer, |
| 744 | const std::vector<uint32_t>& slotsToClear, |
| 745 | uint32_t activeBufferSlot) { |
| 746 | if (slotsToClear.empty()) { |
| 747 | return Error::NONE; |
| 748 | } |
Brian Lindahl | 5b0ffe0 | 2023-06-15 14:19:43 -0600 | [diff] [blame] | 749 | // This can be null when the HAL hasn't explicitly enabled this feature. |
| 750 | if (mClearSlotBuffer == nullptr) { |
| 751 | return Error::NONE; |
| 752 | } |
| 753 | // Backwards compatible way of clearing buffer is to set the layer buffer with a placeholder |
Brian Lindahl | b158a5c | 2022-12-15 15:21:13 -0700 | [diff] [blame] | 754 | // buffer, using the slot that needs to cleared... tricky. |
| 755 | for (uint32_t slot : slotsToClear) { |
| 756 | // Don't clear the active buffer slot because we need to restore the active buffer after |
| 757 | // setting the requested buffer slots with a placeholder buffer. |
| 758 | if (slot != activeBufferSlot) { |
| 759 | mWriter.selectDisplay(display); |
| 760 | mWriter.selectLayer(layer); |
| 761 | mWriter.setLayerBuffer(slot, mClearSlotBuffer->handle, /*fence*/ -1); |
| 762 | } |
| 763 | } |
| 764 | // Since we clear buffers by setting them to a placeholder buffer, we want to make sure that the |
| 765 | // last setLayerBuffer command is sent with the currently active buffer, not the placeholder |
| 766 | // buffer, so that there is no perceptual change. |
Brian Lindahl | 90553da | 2022-12-06 13:36:30 -0700 | [diff] [blame] | 767 | mWriter.selectDisplay(display); |
| 768 | mWriter.selectLayer(layer); |
Brian Lindahl | b158a5c | 2022-12-15 15:21:13 -0700 | [diff] [blame] | 769 | mWriter.setLayerBuffer(activeBufferSlot, /*buffer*/ nullptr, /*fence*/ -1); |
Brian Lindahl | 90553da | 2022-12-06 13:36:30 -0700 | [diff] [blame] | 770 | return Error::NONE; |
| 771 | } |
| 772 | |
Ady Abraham | 9fc2805 | 2021-10-14 17:21:38 -0700 | [diff] [blame] | 773 | Error HidlComposer::setLayerSurfaceDamage(Display display, Layer layer, |
| 774 | const std::vector<IComposerClient::Rect>& damage) { |
| 775 | mWriter.selectDisplay(display); |
| 776 | mWriter.selectLayer(layer); |
| 777 | mWriter.setLayerSurfaceDamage(damage); |
| 778 | return Error::NONE; |
| 779 | } |
| 780 | |
| 781 | Error HidlComposer::setLayerBlendMode(Display display, Layer layer, |
| 782 | IComposerClient::BlendMode mode) { |
| 783 | mWriter.selectDisplay(display); |
| 784 | mWriter.selectLayer(layer); |
| 785 | mWriter.setLayerBlendMode(mode); |
| 786 | return Error::NONE; |
| 787 | } |
| 788 | |
Ady Abraham | 6e60b14 | 2022-01-06 18:10:35 -0800 | [diff] [blame] | 789 | static IComposerClient::Color to_hidl_type( |
| 790 | aidl::android::hardware::graphics::composer3::Color color) { |
| 791 | const auto floatColorToUint8Clamped = [](float val) -> uint8_t { |
| 792 | const auto intVal = static_cast<uint64_t>(std::round(255.0f * val)); |
| 793 | const auto minVal = static_cast<uint64_t>(0); |
| 794 | const auto maxVal = static_cast<uint64_t>(255); |
| 795 | return std::clamp(intVal, minVal, maxVal); |
| 796 | }; |
| 797 | |
| 798 | return IComposerClient::Color{ |
| 799 | floatColorToUint8Clamped(color.r), |
| 800 | floatColorToUint8Clamped(color.g), |
| 801 | floatColorToUint8Clamped(color.b), |
| 802 | floatColorToUint8Clamped(color.a), |
| 803 | }; |
| 804 | } |
| 805 | |
| 806 | Error HidlComposer::setLayerColor( |
| 807 | Display display, Layer layer, |
| 808 | const aidl::android::hardware::graphics::composer3::Color& color) { |
Ady Abraham | 9fc2805 | 2021-10-14 17:21:38 -0700 | [diff] [blame] | 809 | mWriter.selectDisplay(display); |
| 810 | mWriter.selectLayer(layer); |
Ady Abraham | 6e60b14 | 2022-01-06 18:10:35 -0800 | [diff] [blame] | 811 | mWriter.setLayerColor(to_hidl_type(color)); |
Ady Abraham | 9fc2805 | 2021-10-14 17:21:38 -0700 | [diff] [blame] | 812 | return Error::NONE; |
| 813 | } |
| 814 | |
Leon Scroggins III | 2e1aa18 | 2021-12-01 17:33:12 -0500 | [diff] [blame] | 815 | static IComposerClient::Composition to_hidl_type( |
| 816 | aidl::android::hardware::graphics::composer3::Composition type) { |
Leon Scroggins III | 09c2541 | 2021-12-02 14:49:56 -0500 | [diff] [blame] | 817 | LOG_ALWAYS_FATAL_IF(static_cast<int32_t>(type) > |
| 818 | static_cast<int32_t>(IComposerClient::Composition::SIDEBAND), |
| 819 | "Trying to use %s, which is not supported by HidlComposer!", |
| 820 | android::to_string(type).c_str()); |
| 821 | |
Leon Scroggins III | 2e1aa18 | 2021-12-01 17:33:12 -0500 | [diff] [blame] | 822 | return static_cast<IComposerClient::Composition>(type); |
| 823 | } |
| 824 | |
| 825 | Error HidlComposer::setLayerCompositionType( |
| 826 | Display display, Layer layer, |
| 827 | aidl::android::hardware::graphics::composer3::Composition type) { |
Ady Abraham | 9fc2805 | 2021-10-14 17:21:38 -0700 | [diff] [blame] | 828 | mWriter.selectDisplay(display); |
| 829 | mWriter.selectLayer(layer); |
Leon Scroggins III | 2e1aa18 | 2021-12-01 17:33:12 -0500 | [diff] [blame] | 830 | mWriter.setLayerCompositionType(to_hidl_type(type)); |
Ady Abraham | 9fc2805 | 2021-10-14 17:21:38 -0700 | [diff] [blame] | 831 | return Error::NONE; |
| 832 | } |
| 833 | |
| 834 | Error HidlComposer::setLayerDataspace(Display display, Layer layer, Dataspace dataspace) { |
| 835 | mWriter.selectDisplay(display); |
| 836 | mWriter.selectLayer(layer); |
| 837 | mWriter.setLayerDataspace(dataspace); |
| 838 | return Error::NONE; |
| 839 | } |
| 840 | |
| 841 | Error HidlComposer::setLayerDisplayFrame(Display display, Layer layer, |
| 842 | const IComposerClient::Rect& frame) { |
| 843 | mWriter.selectDisplay(display); |
| 844 | mWriter.selectLayer(layer); |
| 845 | mWriter.setLayerDisplayFrame(frame); |
| 846 | return Error::NONE; |
| 847 | } |
| 848 | |
| 849 | Error HidlComposer::setLayerPlaneAlpha(Display display, Layer layer, float alpha) { |
| 850 | mWriter.selectDisplay(display); |
| 851 | mWriter.selectLayer(layer); |
| 852 | mWriter.setLayerPlaneAlpha(alpha); |
| 853 | return Error::NONE; |
| 854 | } |
| 855 | |
| 856 | Error HidlComposer::setLayerSidebandStream(Display display, Layer layer, |
| 857 | const native_handle_t* stream) { |
| 858 | mWriter.selectDisplay(display); |
| 859 | mWriter.selectLayer(layer); |
| 860 | mWriter.setLayerSidebandStream(stream); |
| 861 | return Error::NONE; |
| 862 | } |
| 863 | |
| 864 | Error HidlComposer::setLayerSourceCrop(Display display, Layer layer, |
| 865 | const IComposerClient::FRect& crop) { |
| 866 | mWriter.selectDisplay(display); |
| 867 | mWriter.selectLayer(layer); |
| 868 | mWriter.setLayerSourceCrop(crop); |
| 869 | return Error::NONE; |
| 870 | } |
| 871 | |
| 872 | Error HidlComposer::setLayerTransform(Display display, Layer layer, Transform transform) { |
| 873 | mWriter.selectDisplay(display); |
| 874 | mWriter.selectLayer(layer); |
| 875 | mWriter.setLayerTransform(transform); |
| 876 | return Error::NONE; |
| 877 | } |
| 878 | |
| 879 | Error HidlComposer::setLayerVisibleRegion(Display display, Layer layer, |
| 880 | const std::vector<IComposerClient::Rect>& visible) { |
| 881 | mWriter.selectDisplay(display); |
| 882 | mWriter.selectLayer(layer); |
| 883 | mWriter.setLayerVisibleRegion(visible); |
| 884 | return Error::NONE; |
| 885 | } |
| 886 | |
| 887 | Error HidlComposer::setLayerZOrder(Display display, Layer layer, uint32_t z) { |
| 888 | mWriter.selectDisplay(display); |
| 889 | mWriter.selectLayer(layer); |
| 890 | mWriter.setLayerZOrder(z); |
| 891 | return Error::NONE; |
| 892 | } |
| 893 | |
| 894 | Error HidlComposer::execute() { |
| 895 | // prepare input command queue |
| 896 | bool queueChanged = false; |
| 897 | uint32_t commandLength = 0; |
| 898 | hidl_vec<hidl_handle> commandHandles; |
| 899 | if (!mWriter.writeQueue(&queueChanged, &commandLength, &commandHandles)) { |
| 900 | mWriter.reset(); |
| 901 | return Error::NO_RESOURCES; |
| 902 | } |
| 903 | |
| 904 | // set up new input command queue if necessary |
| 905 | if (queueChanged) { |
| 906 | auto ret = mClient->setInputCommandQueue(*mWriter.getMQDescriptor()); |
Manasi Navare | fc2a4a7 | 2024-11-12 23:59:21 +0000 | [diff] [blame] | 907 | auto error = static_cast<Error>(unwrapRet(ret)); |
Ady Abraham | 9fc2805 | 2021-10-14 17:21:38 -0700 | [diff] [blame] | 908 | if (error != Error::NONE) { |
| 909 | mWriter.reset(); |
| 910 | return error; |
| 911 | } |
| 912 | } |
| 913 | |
| 914 | if (commandLength == 0) { |
| 915 | mWriter.reset(); |
| 916 | return Error::NONE; |
| 917 | } |
| 918 | |
Manasi Navare | fc2a4a7 | 2024-11-12 23:59:21 +0000 | [diff] [blame] | 919 | Error error = static_cast<Error>(kDefaultError); |
Ady Abraham | 9fc2805 | 2021-10-14 17:21:38 -0700 | [diff] [blame] | 920 | hardware::Return<void> ret; |
| 921 | auto hidl_callback = [&](const auto& tmpError, const auto& tmpOutChanged, |
| 922 | const auto& tmpOutLength, const auto& tmpOutHandles) { |
Manasi Navare | fc2a4a7 | 2024-11-12 23:59:21 +0000 | [diff] [blame] | 923 | error = static_cast<Error>(tmpError); |
Ady Abraham | 9fc2805 | 2021-10-14 17:21:38 -0700 | [diff] [blame] | 924 | |
| 925 | // set up new output command queue if necessary |
| 926 | if (error == Error::NONE && tmpOutChanged) { |
Manasi Navare | fc2a4a7 | 2024-11-12 23:59:21 +0000 | [diff] [blame] | 927 | error = static_cast<Error>(kDefaultError); |
Ady Abraham | 9fc2805 | 2021-10-14 17:21:38 -0700 | [diff] [blame] | 928 | mClient->getOutputCommandQueue([&](const auto& tmpError, const auto& tmpDescriptor) { |
Manasi Navare | fc2a4a7 | 2024-11-12 23:59:21 +0000 | [diff] [blame] | 929 | error = static_cast<Error>(tmpError); |
Ady Abraham | 9fc2805 | 2021-10-14 17:21:38 -0700 | [diff] [blame] | 930 | if (error != Error::NONE) { |
| 931 | return; |
| 932 | } |
| 933 | |
| 934 | mReader.setMQDescriptor(tmpDescriptor); |
| 935 | }); |
| 936 | } |
| 937 | |
| 938 | if (error != Error::NONE) { |
| 939 | return; |
| 940 | } |
| 941 | |
| 942 | if (mReader.readQueue(tmpOutLength, tmpOutHandles)) { |
| 943 | error = mReader.parse(); |
| 944 | mReader.reset(); |
| 945 | } else { |
| 946 | error = Error::NO_RESOURCES; |
| 947 | } |
| 948 | }; |
| 949 | if (mClient_2_2) { |
| 950 | ret = mClient_2_2->executeCommands_2_2(commandLength, commandHandles, hidl_callback); |
| 951 | } else { |
| 952 | ret = mClient->executeCommands(commandLength, commandHandles, hidl_callback); |
| 953 | } |
| 954 | // executeCommands can fail because of out-of-fd and we do not want to |
| 955 | // abort() in that case |
| 956 | if (!ret.isOk()) { |
| 957 | ALOGE("executeCommands failed because of %s", ret.description().c_str()); |
| 958 | } |
| 959 | |
| 960 | if (error == Error::NONE) { |
| 961 | std::vector<CommandReader::CommandError> commandErrors = mReader.takeErrors(); |
| 962 | |
| 963 | for (const auto& cmdErr : commandErrors) { |
| 964 | auto command = |
| 965 | static_cast<IComposerClient::Command>(mWriter.getCommand(cmdErr.location)); |
| 966 | |
| 967 | if (command == IComposerClient::Command::VALIDATE_DISPLAY || |
| 968 | command == IComposerClient::Command::PRESENT_DISPLAY || |
| 969 | command == IComposerClient::Command::PRESENT_OR_VALIDATE_DISPLAY) { |
| 970 | error = cmdErr.error; |
| 971 | } else { |
| 972 | ALOGW("command 0x%x generated error %d", command, cmdErr.error); |
| 973 | } |
| 974 | } |
| 975 | } |
| 976 | |
| 977 | mWriter.reset(); |
| 978 | |
| 979 | return error; |
| 980 | } |
| 981 | |
| 982 | // Composer HAL 2.2 |
| 983 | |
| 984 | Error HidlComposer::setLayerPerFrameMetadata( |
| 985 | Display display, Layer layer, |
| 986 | const std::vector<IComposerClient::PerFrameMetadata>& perFrameMetadatas) { |
| 987 | if (!mClient_2_2) { |
| 988 | return Error::UNSUPPORTED; |
| 989 | } |
| 990 | |
| 991 | mWriter.selectDisplay(display); |
| 992 | mWriter.selectLayer(layer); |
| 993 | mWriter.setLayerPerFrameMetadata(perFrameMetadatas); |
| 994 | return Error::NONE; |
| 995 | } |
| 996 | |
| 997 | std::vector<IComposerClient::PerFrameMetadataKey> HidlComposer::getPerFrameMetadataKeys( |
| 998 | Display display) { |
| 999 | std::vector<IComposerClient::PerFrameMetadataKey> keys; |
| 1000 | if (!mClient_2_2) { |
| 1001 | return keys; |
| 1002 | } |
| 1003 | |
Manasi Navare | fc2a4a7 | 2024-11-12 23:59:21 +0000 | [diff] [blame] | 1004 | Error error = static_cast<Error>(kDefaultError); |
Ady Abraham | 9fc2805 | 2021-10-14 17:21:38 -0700 | [diff] [blame] | 1005 | if (mClient_2_3) { |
| 1006 | mClient_2_3->getPerFrameMetadataKeys_2_3(display, |
| 1007 | [&](const auto& tmpError, const auto& tmpKeys) { |
Manasi Navare | fc2a4a7 | 2024-11-12 23:59:21 +0000 | [diff] [blame] | 1008 | error = static_cast<Error>(tmpError); |
Ady Abraham | 9fc2805 | 2021-10-14 17:21:38 -0700 | [diff] [blame] | 1009 | if (error != Error::NONE) { |
| 1010 | ALOGW("getPerFrameMetadataKeys failed " |
| 1011 | "with %d", |
| 1012 | tmpError); |
| 1013 | return; |
| 1014 | } |
| 1015 | keys = tmpKeys; |
| 1016 | }); |
| 1017 | } else { |
| 1018 | mClient_2_2 |
| 1019 | ->getPerFrameMetadataKeys(display, [&](const auto& tmpError, const auto& tmpKeys) { |
Manasi Navare | fc2a4a7 | 2024-11-12 23:59:21 +0000 | [diff] [blame] | 1020 | error = static_cast<Error>(tmpError); |
Ady Abraham | 9fc2805 | 2021-10-14 17:21:38 -0700 | [diff] [blame] | 1021 | if (error != Error::NONE) { |
| 1022 | ALOGW("getPerFrameMetadataKeys failed with %d", tmpError); |
| 1023 | return; |
| 1024 | } |
| 1025 | |
| 1026 | keys.clear(); |
| 1027 | for (auto key : tmpKeys) { |
| 1028 | keys.push_back(static_cast<IComposerClient::PerFrameMetadataKey>(key)); |
| 1029 | } |
| 1030 | }); |
| 1031 | } |
| 1032 | |
| 1033 | return keys; |
| 1034 | } |
| 1035 | |
| 1036 | Error HidlComposer::getRenderIntents(Display display, ColorMode colorMode, |
| 1037 | std::vector<RenderIntent>* outRenderIntents) { |
| 1038 | if (!mClient_2_2) { |
| 1039 | outRenderIntents->push_back(RenderIntent::COLORIMETRIC); |
| 1040 | return Error::NONE; |
| 1041 | } |
| 1042 | |
Manasi Navare | fc2a4a7 | 2024-11-12 23:59:21 +0000 | [diff] [blame] | 1043 | Error error = static_cast<Error>(kDefaultError); |
Ady Abraham | 9fc2805 | 2021-10-14 17:21:38 -0700 | [diff] [blame] | 1044 | |
| 1045 | auto getRenderIntentsLambda = [&](const auto& tmpError, const auto& tmpKeys) { |
Manasi Navare | fc2a4a7 | 2024-11-12 23:59:21 +0000 | [diff] [blame] | 1046 | error = static_cast<Error>(tmpError); |
Ady Abraham | 9fc2805 | 2021-10-14 17:21:38 -0700 | [diff] [blame] | 1047 | if (error != Error::NONE) { |
| 1048 | return; |
| 1049 | } |
| 1050 | |
| 1051 | *outRenderIntents = tmpKeys; |
| 1052 | }; |
| 1053 | |
| 1054 | if (mClient_2_3) { |
| 1055 | mClient_2_3->getRenderIntents_2_3(display, colorMode, getRenderIntentsLambda); |
| 1056 | } else { |
| 1057 | mClient_2_2->getRenderIntents(display, static_cast<types::V1_1::ColorMode>(colorMode), |
| 1058 | getRenderIntentsLambda); |
| 1059 | } |
| 1060 | |
| 1061 | return error; |
| 1062 | } |
| 1063 | |
| 1064 | Error HidlComposer::getDataspaceSaturationMatrix(Dataspace dataspace, mat4* outMatrix) { |
| 1065 | if (!mClient_2_2) { |
| 1066 | *outMatrix = mat4(); |
| 1067 | return Error::NONE; |
| 1068 | } |
| 1069 | |
Manasi Navare | fc2a4a7 | 2024-11-12 23:59:21 +0000 | [diff] [blame] | 1070 | Error error = static_cast<Error>(kDefaultError); |
Ady Abraham | 9fc2805 | 2021-10-14 17:21:38 -0700 | [diff] [blame] | 1071 | mClient_2_2->getDataspaceSaturationMatrix(static_cast<types::V1_1::Dataspace>(dataspace), |
| 1072 | [&](const auto& tmpError, const auto& tmpMatrix) { |
Manasi Navare | fc2a4a7 | 2024-11-12 23:59:21 +0000 | [diff] [blame] | 1073 | error = static_cast<Error>(tmpError); |
Ady Abraham | 9fc2805 | 2021-10-14 17:21:38 -0700 | [diff] [blame] | 1074 | if (error != Error::NONE) { |
| 1075 | return; |
| 1076 | } |
| 1077 | *outMatrix = mat4(tmpMatrix.data()); |
| 1078 | }); |
| 1079 | |
| 1080 | return error; |
| 1081 | } |
| 1082 | |
| 1083 | // Composer HAL 2.3 |
| 1084 | |
| 1085 | Error HidlComposer::getDisplayIdentificationData(Display display, uint8_t* outPort, |
| 1086 | std::vector<uint8_t>* outData) { |
| 1087 | if (!mClient_2_3) { |
| 1088 | return Error::UNSUPPORTED; |
| 1089 | } |
| 1090 | |
Manasi Navare | fc2a4a7 | 2024-11-12 23:59:21 +0000 | [diff] [blame] | 1091 | Error error = static_cast<Error>(kDefaultError); |
Ady Abraham | 9fc2805 | 2021-10-14 17:21:38 -0700 | [diff] [blame] | 1092 | mClient_2_3->getDisplayIdentificationData(display, |
| 1093 | [&](const auto& tmpError, const auto& tmpPort, |
| 1094 | const auto& tmpData) { |
Manasi Navare | fc2a4a7 | 2024-11-12 23:59:21 +0000 | [diff] [blame] | 1095 | error = static_cast<Error>(tmpError); |
Ady Abraham | 9fc2805 | 2021-10-14 17:21:38 -0700 | [diff] [blame] | 1096 | if (error != Error::NONE) { |
| 1097 | return; |
| 1098 | } |
| 1099 | |
| 1100 | *outPort = tmpPort; |
| 1101 | *outData = tmpData; |
| 1102 | }); |
| 1103 | |
| 1104 | return error; |
| 1105 | } |
| 1106 | |
| 1107 | Error HidlComposer::setLayerColorTransform(Display display, Layer layer, const float* matrix) { |
| 1108 | if (!mClient_2_3) { |
| 1109 | return Error::UNSUPPORTED; |
| 1110 | } |
| 1111 | |
| 1112 | mWriter.selectDisplay(display); |
| 1113 | mWriter.selectLayer(layer); |
| 1114 | mWriter.setLayerColorTransform(matrix); |
| 1115 | return Error::NONE; |
| 1116 | } |
| 1117 | |
| 1118 | Error HidlComposer::getDisplayedContentSamplingAttributes(Display display, PixelFormat* outFormat, |
| 1119 | Dataspace* outDataspace, |
| 1120 | uint8_t* outComponentMask) { |
| 1121 | if (!outFormat || !outDataspace || !outComponentMask) { |
| 1122 | return Error::BAD_PARAMETER; |
| 1123 | } |
| 1124 | if (!mClient_2_3) { |
| 1125 | return Error::UNSUPPORTED; |
| 1126 | } |
Manasi Navare | fc2a4a7 | 2024-11-12 23:59:21 +0000 | [diff] [blame] | 1127 | Error error = static_cast<Error>(kDefaultError); |
Ady Abraham | 9fc2805 | 2021-10-14 17:21:38 -0700 | [diff] [blame] | 1128 | mClient_2_3->getDisplayedContentSamplingAttributes(display, |
| 1129 | [&](const auto tmpError, |
| 1130 | const auto& tmpFormat, |
| 1131 | const auto& tmpDataspace, |
| 1132 | const auto& tmpComponentMask) { |
Manasi Navare | fc2a4a7 | 2024-11-12 23:59:21 +0000 | [diff] [blame] | 1133 | error = static_cast<Error>(tmpError); |
Ady Abraham | 9fc2805 | 2021-10-14 17:21:38 -0700 | [diff] [blame] | 1134 | if (error == Error::NONE) { |
| 1135 | *outFormat = tmpFormat; |
| 1136 | *outDataspace = tmpDataspace; |
| 1137 | *outComponentMask = |
| 1138 | static_cast<uint8_t>( |
| 1139 | tmpComponentMask); |
| 1140 | } |
| 1141 | }); |
| 1142 | return error; |
| 1143 | } |
| 1144 | |
| 1145 | Error HidlComposer::setDisplayContentSamplingEnabled(Display display, bool enabled, |
| 1146 | uint8_t componentMask, uint64_t maxFrames) { |
| 1147 | if (!mClient_2_3) { |
| 1148 | return Error::UNSUPPORTED; |
| 1149 | } |
| 1150 | |
| 1151 | auto enable = enabled ? V2_3::IComposerClient::DisplayedContentSampling::ENABLE |
| 1152 | : V2_3::IComposerClient::DisplayedContentSampling::DISABLE; |
Manasi Navare | fc2a4a7 | 2024-11-12 23:59:21 +0000 | [diff] [blame] | 1153 | auto ret = mClient_2_3->setDisplayedContentSamplingEnabled(display, enable, componentMask, |
| 1154 | maxFrames); |
| 1155 | return static_cast<Error>(unwrapRet(ret)); |
Ady Abraham | 9fc2805 | 2021-10-14 17:21:38 -0700 | [diff] [blame] | 1156 | } |
| 1157 | |
| 1158 | Error HidlComposer::getDisplayedContentSample(Display display, uint64_t maxFrames, |
| 1159 | uint64_t timestamp, DisplayedFrameStats* outStats) { |
| 1160 | if (!outStats) { |
| 1161 | return Error::BAD_PARAMETER; |
| 1162 | } |
| 1163 | if (!mClient_2_3) { |
| 1164 | return Error::UNSUPPORTED; |
| 1165 | } |
Manasi Navare | fc2a4a7 | 2024-11-12 23:59:21 +0000 | [diff] [blame] | 1166 | Error error = static_cast<Error>(kDefaultError); |
Ady Abraham | 9fc2805 | 2021-10-14 17:21:38 -0700 | [diff] [blame] | 1167 | mClient_2_3->getDisplayedContentSample(display, maxFrames, timestamp, |
| 1168 | [&](const auto tmpError, auto tmpNumFrames, |
| 1169 | const auto& tmpSamples0, const auto& tmpSamples1, |
| 1170 | const auto& tmpSamples2, const auto& tmpSamples3) { |
Manasi Navare | fc2a4a7 | 2024-11-12 23:59:21 +0000 | [diff] [blame] | 1171 | error = static_cast<Error>(tmpError); |
Ady Abraham | 9fc2805 | 2021-10-14 17:21:38 -0700 | [diff] [blame] | 1172 | if (error == Error::NONE) { |
| 1173 | outStats->numFrames = tmpNumFrames; |
| 1174 | outStats->component_0_sample = tmpSamples0; |
| 1175 | outStats->component_1_sample = tmpSamples1; |
| 1176 | outStats->component_2_sample = tmpSamples2; |
| 1177 | outStats->component_3_sample = tmpSamples3; |
| 1178 | } |
| 1179 | }); |
| 1180 | return error; |
| 1181 | } |
| 1182 | |
| 1183 | Error HidlComposer::setLayerPerFrameMetadataBlobs( |
| 1184 | Display display, Layer layer, |
| 1185 | const std::vector<IComposerClient::PerFrameMetadataBlob>& metadata) { |
| 1186 | if (!mClient_2_3) { |
| 1187 | return Error::UNSUPPORTED; |
| 1188 | } |
| 1189 | |
| 1190 | mWriter.selectDisplay(display); |
| 1191 | mWriter.selectLayer(layer); |
| 1192 | mWriter.setLayerPerFrameMetadataBlobs(metadata); |
| 1193 | return Error::NONE; |
| 1194 | } |
| 1195 | |
Alec Mouri | 4d8a05d | 2022-03-23 18:14:26 +0000 | [diff] [blame] | 1196 | Error HidlComposer::setDisplayBrightness(Display display, float brightness, float, |
Alec Mouri | cdf1679 | 2021-12-10 13:16:06 -0800 | [diff] [blame] | 1197 | const DisplayBrightnessOptions&) { |
Ady Abraham | 9fc2805 | 2021-10-14 17:21:38 -0700 | [diff] [blame] | 1198 | if (!mClient_2_3) { |
| 1199 | return Error::UNSUPPORTED; |
| 1200 | } |
Manasi Navare | fc2a4a7 | 2024-11-12 23:59:21 +0000 | [diff] [blame] | 1201 | auto ret = mClient_2_3->setDisplayBrightness(display, brightness); |
| 1202 | return static_cast<Error>(unwrapRet(ret)); |
Ady Abraham | 9fc2805 | 2021-10-14 17:21:38 -0700 | [diff] [blame] | 1203 | } |
| 1204 | |
| 1205 | // Composer HAL 2.4 |
| 1206 | |
| 1207 | Error HidlComposer::getDisplayCapabilities(Display display, |
| 1208 | std::vector<DisplayCapability>* outCapabilities) { |
| 1209 | if (!mClient_2_3) { |
| 1210 | return Error::UNSUPPORTED; |
| 1211 | } |
| 1212 | |
| 1213 | V2_4::Error error = kDefaultError_2_4; |
| 1214 | if (mClient_2_4) { |
| 1215 | mClient_2_4->getDisplayCapabilities_2_4(display, |
| 1216 | [&](const auto& tmpError, const auto& tmpCaps) { |
| 1217 | error = tmpError; |
| 1218 | if (error != V2_4::Error::NONE) { |
| 1219 | return; |
| 1220 | } |
Ady Abraham | de549d4 | 2022-01-26 19:19:17 -0800 | [diff] [blame] | 1221 | *outCapabilities = |
| 1222 | translate<DisplayCapability>(tmpCaps); |
Ady Abraham | 9fc2805 | 2021-10-14 17:21:38 -0700 | [diff] [blame] | 1223 | }); |
| 1224 | } else { |
| 1225 | mClient_2_3 |
| 1226 | ->getDisplayCapabilities(display, [&](const auto& tmpError, const auto& tmpCaps) { |
| 1227 | error = static_cast<V2_4::Error>(tmpError); |
| 1228 | if (error != V2_4::Error::NONE) { |
| 1229 | return; |
| 1230 | } |
| 1231 | |
Ady Abraham | de549d4 | 2022-01-26 19:19:17 -0800 | [diff] [blame] | 1232 | *outCapabilities = translate<DisplayCapability>(tmpCaps); |
Ady Abraham | 9fc2805 | 2021-10-14 17:21:38 -0700 | [diff] [blame] | 1233 | }); |
| 1234 | } |
| 1235 | |
| 1236 | return static_cast<Error>(error); |
| 1237 | } |
| 1238 | |
| 1239 | V2_4::Error HidlComposer::getDisplayConnectionType( |
| 1240 | Display display, IComposerClient::DisplayConnectionType* outType) { |
| 1241 | using Error = V2_4::Error; |
| 1242 | if (!mClient_2_4) { |
| 1243 | return Error::UNSUPPORTED; |
| 1244 | } |
| 1245 | |
| 1246 | Error error = kDefaultError_2_4; |
| 1247 | mClient_2_4->getDisplayConnectionType(display, [&](const auto& tmpError, const auto& tmpType) { |
| 1248 | error = tmpError; |
| 1249 | if (error != V2_4::Error::NONE) { |
| 1250 | return; |
| 1251 | } |
| 1252 | |
| 1253 | *outType = tmpType; |
| 1254 | }); |
| 1255 | |
| 1256 | return error; |
| 1257 | } |
| 1258 | |
| 1259 | V2_4::Error HidlComposer::getDisplayVsyncPeriod(Display display, VsyncPeriodNanos* outVsyncPeriod) { |
| 1260 | using Error = V2_4::Error; |
| 1261 | if (!mClient_2_4) { |
| 1262 | return Error::UNSUPPORTED; |
| 1263 | } |
| 1264 | |
| 1265 | Error error = kDefaultError_2_4; |
| 1266 | mClient_2_4->getDisplayVsyncPeriod(display, |
| 1267 | [&](const auto& tmpError, const auto& tmpVsyncPeriod) { |
| 1268 | error = tmpError; |
| 1269 | if (error != Error::NONE) { |
| 1270 | return; |
| 1271 | } |
| 1272 | |
| 1273 | *outVsyncPeriod = tmpVsyncPeriod; |
| 1274 | }); |
| 1275 | |
| 1276 | return error; |
| 1277 | } |
| 1278 | |
Manasi Navare | fc2a4a7 | 2024-11-12 23:59:21 +0000 | [diff] [blame] | 1279 | Error HidlComposer::setActiveConfigWithConstraints( |
Ady Abraham | 9fc2805 | 2021-10-14 17:21:38 -0700 | [diff] [blame] | 1280 | Display display, Config config, |
| 1281 | const IComposerClient::VsyncPeriodChangeConstraints& vsyncPeriodChangeConstraints, |
| 1282 | VsyncPeriodChangeTimeline* outTimeline) { |
Ady Abraham | 9fc2805 | 2021-10-14 17:21:38 -0700 | [diff] [blame] | 1283 | if (!mClient_2_4) { |
| 1284 | return Error::UNSUPPORTED; |
| 1285 | } |
| 1286 | |
Manasi Navare | fc2a4a7 | 2024-11-12 23:59:21 +0000 | [diff] [blame] | 1287 | Error error = static_cast<Error>(kDefaultError_2_4); |
Ady Abraham | 9fc2805 | 2021-10-14 17:21:38 -0700 | [diff] [blame] | 1288 | mClient_2_4->setActiveConfigWithConstraints(display, config, vsyncPeriodChangeConstraints, |
| 1289 | [&](const auto& tmpError, const auto& tmpTimeline) { |
Manasi Navare | fc2a4a7 | 2024-11-12 23:59:21 +0000 | [diff] [blame] | 1290 | error = static_cast<Error>(tmpError); |
Ady Abraham | 9fc2805 | 2021-10-14 17:21:38 -0700 | [diff] [blame] | 1291 | if (error != Error::NONE) { |
| 1292 | return; |
| 1293 | } |
| 1294 | |
| 1295 | *outTimeline = tmpTimeline; |
| 1296 | }); |
| 1297 | |
| 1298 | return error; |
| 1299 | } |
| 1300 | |
| 1301 | V2_4::Error HidlComposer::setAutoLowLatencyMode(Display display, bool on) { |
| 1302 | using Error = V2_4::Error; |
| 1303 | if (!mClient_2_4) { |
| 1304 | return Error::UNSUPPORTED; |
| 1305 | } |
| 1306 | |
| 1307 | return mClient_2_4->setAutoLowLatencyMode(display, on); |
| 1308 | } |
| 1309 | |
| 1310 | V2_4::Error HidlComposer::getSupportedContentTypes( |
| 1311 | Display displayId, std::vector<IComposerClient::ContentType>* outSupportedContentTypes) { |
| 1312 | using Error = V2_4::Error; |
| 1313 | if (!mClient_2_4) { |
| 1314 | return Error::UNSUPPORTED; |
| 1315 | } |
| 1316 | |
| 1317 | Error error = kDefaultError_2_4; |
| 1318 | mClient_2_4->getSupportedContentTypes(displayId, |
| 1319 | [&](const auto& tmpError, |
| 1320 | const auto& tmpSupportedContentTypes) { |
| 1321 | error = tmpError; |
| 1322 | if (error != Error::NONE) { |
| 1323 | return; |
| 1324 | } |
| 1325 | |
| 1326 | *outSupportedContentTypes = tmpSupportedContentTypes; |
| 1327 | }); |
| 1328 | return error; |
| 1329 | } |
| 1330 | |
| 1331 | V2_4::Error HidlComposer::setContentType(Display display, |
| 1332 | IComposerClient::ContentType contentType) { |
| 1333 | using Error = V2_4::Error; |
| 1334 | if (!mClient_2_4) { |
| 1335 | return Error::UNSUPPORTED; |
| 1336 | } |
| 1337 | |
| 1338 | return mClient_2_4->setContentType(display, contentType); |
| 1339 | } |
| 1340 | |
| 1341 | V2_4::Error HidlComposer::setLayerGenericMetadata(Display display, Layer layer, |
| 1342 | const std::string& key, bool mandatory, |
| 1343 | const std::vector<uint8_t>& value) { |
| 1344 | using Error = V2_4::Error; |
| 1345 | if (!mClient_2_4) { |
| 1346 | return Error::UNSUPPORTED; |
| 1347 | } |
| 1348 | mWriter.selectDisplay(display); |
| 1349 | mWriter.selectLayer(layer); |
| 1350 | mWriter.setLayerGenericMetadata(key, mandatory, value); |
| 1351 | return Error::NONE; |
| 1352 | } |
| 1353 | |
| 1354 | V2_4::Error HidlComposer::getLayerGenericMetadataKeys( |
| 1355 | std::vector<IComposerClient::LayerGenericMetadataKey>* outKeys) { |
| 1356 | using Error = V2_4::Error; |
| 1357 | if (!mClient_2_4) { |
| 1358 | return Error::UNSUPPORTED; |
| 1359 | } |
| 1360 | Error error = kDefaultError_2_4; |
| 1361 | mClient_2_4->getLayerGenericMetadataKeys([&](const auto& tmpError, const auto& tmpKeys) { |
| 1362 | error = tmpError; |
| 1363 | if (error != Error::NONE) { |
| 1364 | return; |
| 1365 | } |
| 1366 | |
| 1367 | *outKeys = tmpKeys; |
| 1368 | }); |
| 1369 | return error; |
| 1370 | } |
| 1371 | |
Kriti Dang | 7defaf3 | 2021-11-15 11:55:43 +0100 | [diff] [blame] | 1372 | Error HidlComposer::setBootDisplayConfig(Display /*displayId*/, Config) { |
| 1373 | return Error::UNSUPPORTED; |
| 1374 | } |
| 1375 | |
| 1376 | Error HidlComposer::clearBootDisplayConfig(Display /*displayId*/) { |
| 1377 | return Error::UNSUPPORTED; |
| 1378 | } |
| 1379 | |
| 1380 | Error HidlComposer::getPreferredBootDisplayConfig(Display /*displayId*/, Config*) { |
| 1381 | return Error::UNSUPPORTED; |
| 1382 | } |
| 1383 | |
Kriti Dang | 674b937 | 2022-11-18 10:58:44 +0100 | [diff] [blame] | 1384 | Error HidlComposer::getHdrConversionCapabilities(std::vector<HdrConversionCapability>*) { |
| 1385 | return Error::UNSUPPORTED; |
| 1386 | } |
| 1387 | |
Kriti Dang | d432bb5 | 2023-02-09 18:21:04 +0100 | [diff] [blame] | 1388 | Error HidlComposer::setHdrConversionStrategy(HdrConversionStrategy, Hdr*) { |
Kriti Dang | 674b937 | 2022-11-18 10:58:44 +0100 | [diff] [blame] | 1389 | return Error::UNSUPPORTED; |
| 1390 | } |
| 1391 | |
ramindani | b2158ee | 2023-02-13 20:29:59 -0800 | [diff] [blame] | 1392 | Error HidlComposer::setRefreshRateChangedCallbackDebugEnabled(Display, bool) { |
| 1393 | return Error::UNSUPPORTED; |
| 1394 | } |
| 1395 | |
ramindani | 3acaaf5 | 2023-09-25 10:31:27 -0700 | [diff] [blame] | 1396 | Error HidlComposer::notifyExpectedPresent(Display, nsecs_t, int32_t) { |
| 1397 | return Error::UNSUPPORTED; |
| 1398 | } |
| 1399 | |
Ady Abraham | 9fc2805 | 2021-10-14 17:21:38 -0700 | [diff] [blame] | 1400 | Error HidlComposer::getClientTargetProperty( |
Alec Mouri | 8506569 | 2022-03-18 00:58:26 +0000 | [diff] [blame] | 1401 | Display display, ClientTargetPropertyWithBrightness* outClientTargetProperty) { |
| 1402 | IComposerClient::ClientTargetProperty property; |
| 1403 | mReader.takeClientTargetProperty(display, &property); |
| 1404 | outClientTargetProperty->display = display; |
| 1405 | outClientTargetProperty->clientTargetProperty.dataspace = |
| 1406 | static_cast<::aidl::android::hardware::graphics::common::Dataspace>(property.dataspace); |
| 1407 | outClientTargetProperty->clientTargetProperty.pixelFormat = |
| 1408 | static_cast<::aidl::android::hardware::graphics::common::PixelFormat>( |
| 1409 | property.pixelFormat); |
| 1410 | outClientTargetProperty->brightness = 1.f; |
| 1411 | outClientTargetProperty->dimmingStage = DimmingStage::NONE; |
Alec Mouri | cdf6cbc | 2021-11-01 17:21:15 -0700 | [diff] [blame] | 1412 | return Error::NONE; |
| 1413 | } |
| 1414 | |
Sally Qi | 95f669a | 2024-08-27 11:31:42 -0700 | [diff] [blame] | 1415 | Error HidlComposer::getRequestedLuts(Display, std::vector<Layer>*, |
| 1416 | std::vector<DisplayLuts::LayerLut>*) { |
Sally Qi | 11dcd58 | 2024-08-16 18:11:27 -0700 | [diff] [blame] | 1417 | return Error::NONE; |
| 1418 | } |
| 1419 | |
Sally Qi | 0abc4a5 | 2024-09-26 16:13:06 -0700 | [diff] [blame] | 1420 | Error HidlComposer::setLayerLuts(Display, Layer, Luts&) { |
Sally Qi | 492cec3 | 2024-06-28 14:34:47 -0700 | [diff] [blame] | 1421 | return Error::NONE; |
| 1422 | } |
| 1423 | |
Alec Mouri | 6da0e27 | 2022-02-07 12:45:57 -0800 | [diff] [blame] | 1424 | Error HidlComposer::setLayerBrightness(Display, Layer, float) { |
Ady Abraham | 9fc2805 | 2021-10-14 17:21:38 -0700 | [diff] [blame] | 1425 | return Error::NONE; |
| 1426 | } |
| 1427 | |
Leon Scroggins III | d77d316 | 2022-01-05 10:42:28 -0500 | [diff] [blame] | 1428 | Error HidlComposer::setLayerBlockingRegion(Display, Layer, |
| 1429 | const std::vector<IComposerClient::Rect>&) { |
| 1430 | return Error::NONE; |
| 1431 | } |
| 1432 | |
Leon Scroggins III | e7c51c6 | 2022-02-01 15:53:54 -0500 | [diff] [blame] | 1433 | Error HidlComposer::getDisplayDecorationSupport( |
| 1434 | Display, |
| 1435 | std::optional<aidl::android::hardware::graphics::common::DisplayDecorationSupport>* |
| 1436 | support) { |
| 1437 | support->reset(); |
| 1438 | return Error::UNSUPPORTED; |
| 1439 | } |
| 1440 | |
ramindani | 32cf060 | 2022-03-02 02:30:29 +0000 | [diff] [blame] | 1441 | Error HidlComposer::setIdleTimerEnabled(Display, std::chrono::milliseconds) { |
| 1442 | LOG_ALWAYS_FATAL("setIdleTimerEnabled should have never been called on this as " |
| 1443 | "OptionalFeature::KernelIdleTimer is not supported on HIDL"); |
| 1444 | } |
| 1445 | |
ramindani | 06e518e | 2022-03-14 18:47:53 +0000 | [diff] [blame] | 1446 | Error HidlComposer::getPhysicalDisplayOrientation(Display, AidlTransform*) { |
| 1447 | LOG_ALWAYS_FATAL("getPhysicalDisplayOrientation should have never been called on this as " |
| 1448 | "OptionalFeature::PhysicalDisplayOrientation is not supported on HIDL"); |
| 1449 | } |
| 1450 | |
Brian Lindahl | 7a4cb7e | 2024-10-30 10:42:21 -0600 | [diff] [blame] | 1451 | Error HidlComposer::getMaxLayerPictureProfiles(Display, int32_t*) { |
| 1452 | return Error::UNSUPPORTED; |
| 1453 | } |
| 1454 | |
| 1455 | Error HidlComposer::setDisplayPictureProfileId(Display, PictureProfileId) { |
| 1456 | return Error::UNSUPPORTED; |
| 1457 | } |
| 1458 | |
| 1459 | Error HidlComposer::setLayerPictureProfileId(Display, Layer, PictureProfileId) { |
| 1460 | return Error::UNSUPPORTED; |
| 1461 | } |
| 1462 | |
Yichi Chen | 3401b56 | 2022-01-17 15:42:35 +0800 | [diff] [blame] | 1463 | void HidlComposer::registerCallback(ComposerCallback& callback) { |
| 1464 | const bool vsyncSwitchingSupported = |
| 1465 | isSupported(Hwc2::Composer::OptionalFeature::RefreshRateSwitching); |
| 1466 | |
| 1467 | registerCallback(sp<ComposerCallbackBridge>::make(callback, vsyncSwitchingSupported)); |
| 1468 | } |
| 1469 | |
Leon Scroggins III | e24d78f | 2022-09-20 16:38:19 -0400 | [diff] [blame] | 1470 | void HidlComposer::onHotplugConnect(Display) {} |
| 1471 | void HidlComposer::onHotplugDisconnect(Display) {} |
| 1472 | |
Ady Abraham | 9fc2805 | 2021-10-14 17:21:38 -0700 | [diff] [blame] | 1473 | CommandReader::~CommandReader() { |
| 1474 | resetData(); |
| 1475 | } |
| 1476 | |
| 1477 | Error CommandReader::parse() { |
| 1478 | resetData(); |
| 1479 | |
| 1480 | IComposerClient::Command command; |
| 1481 | uint16_t length = 0; |
| 1482 | |
| 1483 | while (!isEmpty()) { |
| 1484 | if (!beginCommand(&command, &length)) { |
| 1485 | break; |
| 1486 | } |
| 1487 | |
| 1488 | bool parsed = false; |
| 1489 | switch (command) { |
| 1490 | case IComposerClient::Command::SELECT_DISPLAY: |
| 1491 | parsed = parseSelectDisplay(length); |
| 1492 | break; |
| 1493 | case IComposerClient::Command::SET_ERROR: |
| 1494 | parsed = parseSetError(length); |
| 1495 | break; |
| 1496 | case IComposerClient::Command::SET_CHANGED_COMPOSITION_TYPES: |
| 1497 | parsed = parseSetChangedCompositionTypes(length); |
| 1498 | break; |
| 1499 | case IComposerClient::Command::SET_DISPLAY_REQUESTS: |
| 1500 | parsed = parseSetDisplayRequests(length); |
| 1501 | break; |
| 1502 | case IComposerClient::Command::SET_PRESENT_FENCE: |
| 1503 | parsed = parseSetPresentFence(length); |
| 1504 | break; |
| 1505 | case IComposerClient::Command::SET_RELEASE_FENCES: |
| 1506 | parsed = parseSetReleaseFences(length); |
| 1507 | break; |
| 1508 | case IComposerClient::Command ::SET_PRESENT_OR_VALIDATE_DISPLAY_RESULT: |
| 1509 | parsed = parseSetPresentOrValidateDisplayResult(length); |
| 1510 | break; |
| 1511 | case IComposerClient::Command::SET_CLIENT_TARGET_PROPERTY: |
| 1512 | parsed = parseSetClientTargetProperty(length); |
| 1513 | break; |
| 1514 | default: |
| 1515 | parsed = false; |
| 1516 | break; |
| 1517 | } |
| 1518 | |
| 1519 | endCommand(); |
| 1520 | |
| 1521 | if (!parsed) { |
| 1522 | ALOGE("failed to parse command 0x%x length %" PRIu16, command, length); |
| 1523 | break; |
| 1524 | } |
| 1525 | } |
| 1526 | |
| 1527 | return isEmpty() ? Error::NONE : Error::NO_RESOURCES; |
| 1528 | } |
| 1529 | |
| 1530 | bool CommandReader::parseSelectDisplay(uint16_t length) { |
| 1531 | if (length != CommandWriterBase::kSelectDisplayLength) { |
| 1532 | return false; |
| 1533 | } |
| 1534 | |
| 1535 | mCurrentReturnData = &mReturnData[read64()]; |
| 1536 | |
| 1537 | return true; |
| 1538 | } |
| 1539 | |
| 1540 | bool CommandReader::parseSetError(uint16_t length) { |
| 1541 | if (length != CommandWriterBase::kSetErrorLength) { |
| 1542 | return false; |
| 1543 | } |
| 1544 | |
| 1545 | auto location = read(); |
| 1546 | auto error = static_cast<Error>(readSigned()); |
| 1547 | |
| 1548 | mErrors.emplace_back(CommandError{location, error}); |
| 1549 | |
| 1550 | return true; |
| 1551 | } |
| 1552 | |
| 1553 | bool CommandReader::parseSetChangedCompositionTypes(uint16_t length) { |
| 1554 | // (layer id, composition type) pairs |
| 1555 | if (length % 3 != 0 || !mCurrentReturnData) { |
| 1556 | return false; |
| 1557 | } |
| 1558 | |
| 1559 | uint32_t count = length / 3; |
| 1560 | mCurrentReturnData->changedLayers.reserve(count); |
| 1561 | mCurrentReturnData->compositionTypes.reserve(count); |
| 1562 | while (count > 0) { |
| 1563 | auto layer = read64(); |
Leon Scroggins III | 2e1aa18 | 2021-12-01 17:33:12 -0500 | [diff] [blame] | 1564 | auto type = static_cast<aidl::android::hardware::graphics::composer3::Composition>( |
| 1565 | readSigned()); |
Ady Abraham | 9fc2805 | 2021-10-14 17:21:38 -0700 | [diff] [blame] | 1566 | |
| 1567 | mCurrentReturnData->changedLayers.push_back(layer); |
| 1568 | mCurrentReturnData->compositionTypes.push_back(type); |
| 1569 | |
| 1570 | count--; |
| 1571 | } |
| 1572 | |
| 1573 | return true; |
| 1574 | } |
| 1575 | |
| 1576 | bool CommandReader::parseSetDisplayRequests(uint16_t length) { |
| 1577 | // display requests followed by (layer id, layer requests) pairs |
| 1578 | if (length % 3 != 1 || !mCurrentReturnData) { |
| 1579 | return false; |
| 1580 | } |
| 1581 | |
| 1582 | mCurrentReturnData->displayRequests = read(); |
| 1583 | |
| 1584 | uint32_t count = (length - 1) / 3; |
| 1585 | mCurrentReturnData->requestedLayers.reserve(count); |
| 1586 | mCurrentReturnData->requestMasks.reserve(count); |
| 1587 | while (count > 0) { |
| 1588 | auto layer = read64(); |
| 1589 | auto layerRequestMask = read(); |
| 1590 | |
| 1591 | mCurrentReturnData->requestedLayers.push_back(layer); |
| 1592 | mCurrentReturnData->requestMasks.push_back(layerRequestMask); |
| 1593 | |
| 1594 | count--; |
| 1595 | } |
| 1596 | |
| 1597 | return true; |
| 1598 | } |
| 1599 | |
| 1600 | bool CommandReader::parseSetPresentFence(uint16_t length) { |
| 1601 | if (length != CommandWriterBase::kSetPresentFenceLength || !mCurrentReturnData) { |
| 1602 | return false; |
| 1603 | } |
| 1604 | |
| 1605 | if (mCurrentReturnData->presentFence >= 0) { |
| 1606 | close(mCurrentReturnData->presentFence); |
| 1607 | } |
| 1608 | mCurrentReturnData->presentFence = readFence(); |
| 1609 | |
| 1610 | return true; |
| 1611 | } |
| 1612 | |
| 1613 | bool CommandReader::parseSetReleaseFences(uint16_t length) { |
| 1614 | // (layer id, release fence index) pairs |
| 1615 | if (length % 3 != 0 || !mCurrentReturnData) { |
| 1616 | return false; |
| 1617 | } |
| 1618 | |
| 1619 | uint32_t count = length / 3; |
| 1620 | mCurrentReturnData->releasedLayers.reserve(count); |
| 1621 | mCurrentReturnData->releaseFences.reserve(count); |
| 1622 | while (count > 0) { |
| 1623 | auto layer = read64(); |
| 1624 | auto fence = readFence(); |
| 1625 | |
| 1626 | mCurrentReturnData->releasedLayers.push_back(layer); |
| 1627 | mCurrentReturnData->releaseFences.push_back(fence); |
| 1628 | |
| 1629 | count--; |
| 1630 | } |
| 1631 | |
| 1632 | return true; |
| 1633 | } |
| 1634 | |
| 1635 | bool CommandReader::parseSetPresentOrValidateDisplayResult(uint16_t length) { |
| 1636 | if (length != CommandWriterBase::kPresentOrValidateDisplayResultLength || !mCurrentReturnData) { |
| 1637 | return false; |
| 1638 | } |
| 1639 | mCurrentReturnData->presentOrValidateState = read(); |
| 1640 | return true; |
| 1641 | } |
| 1642 | |
| 1643 | bool CommandReader::parseSetClientTargetProperty(uint16_t length) { |
| 1644 | if (length != CommandWriterBase::kSetClientTargetPropertyLength || !mCurrentReturnData) { |
| 1645 | return false; |
| 1646 | } |
| 1647 | mCurrentReturnData->clientTargetProperty.pixelFormat = static_cast<PixelFormat>(readSigned()); |
| 1648 | mCurrentReturnData->clientTargetProperty.dataspace = static_cast<Dataspace>(readSigned()); |
| 1649 | return true; |
| 1650 | } |
| 1651 | |
| 1652 | void CommandReader::resetData() { |
| 1653 | mErrors.clear(); |
| 1654 | |
| 1655 | for (auto& data : mReturnData) { |
| 1656 | if (data.second.presentFence >= 0) { |
| 1657 | close(data.second.presentFence); |
| 1658 | } |
| 1659 | for (auto fence : data.second.releaseFences) { |
| 1660 | if (fence >= 0) { |
| 1661 | close(fence); |
| 1662 | } |
| 1663 | } |
| 1664 | } |
| 1665 | |
| 1666 | mReturnData.clear(); |
| 1667 | mCurrentReturnData = nullptr; |
| 1668 | } |
| 1669 | |
| 1670 | std::vector<CommandReader::CommandError> CommandReader::takeErrors() { |
| 1671 | return std::move(mErrors); |
| 1672 | } |
| 1673 | |
| 1674 | bool CommandReader::hasChanges(Display display, uint32_t* outNumChangedCompositionTypes, |
| 1675 | uint32_t* outNumLayerRequestMasks) const { |
| 1676 | auto found = mReturnData.find(display); |
| 1677 | if (found == mReturnData.end()) { |
| 1678 | *outNumChangedCompositionTypes = 0; |
| 1679 | *outNumLayerRequestMasks = 0; |
| 1680 | return false; |
| 1681 | } |
| 1682 | |
| 1683 | const ReturnData& data = found->second; |
| 1684 | |
| 1685 | *outNumChangedCompositionTypes = data.compositionTypes.size(); |
| 1686 | *outNumLayerRequestMasks = data.requestMasks.size(); |
| 1687 | |
| 1688 | return !(data.compositionTypes.empty() && data.requestMasks.empty()); |
| 1689 | } |
| 1690 | |
| 1691 | void CommandReader::takeChangedCompositionTypes( |
| 1692 | Display display, std::vector<Layer>* outLayers, |
Leon Scroggins III | 2e1aa18 | 2021-12-01 17:33:12 -0500 | [diff] [blame] | 1693 | std::vector<aidl::android::hardware::graphics::composer3::Composition>* outTypes) { |
Ady Abraham | 9fc2805 | 2021-10-14 17:21:38 -0700 | [diff] [blame] | 1694 | auto found = mReturnData.find(display); |
| 1695 | if (found == mReturnData.end()) { |
| 1696 | outLayers->clear(); |
| 1697 | outTypes->clear(); |
| 1698 | return; |
| 1699 | } |
| 1700 | |
| 1701 | ReturnData& data = found->second; |
| 1702 | |
| 1703 | *outLayers = std::move(data.changedLayers); |
| 1704 | *outTypes = std::move(data.compositionTypes); |
| 1705 | } |
| 1706 | |
| 1707 | void CommandReader::takeDisplayRequests(Display display, uint32_t* outDisplayRequestMask, |
| 1708 | std::vector<Layer>* outLayers, |
| 1709 | std::vector<uint32_t>* outLayerRequestMasks) { |
| 1710 | auto found = mReturnData.find(display); |
| 1711 | if (found == mReturnData.end()) { |
| 1712 | *outDisplayRequestMask = 0; |
| 1713 | outLayers->clear(); |
| 1714 | outLayerRequestMasks->clear(); |
| 1715 | return; |
| 1716 | } |
| 1717 | |
| 1718 | ReturnData& data = found->second; |
| 1719 | |
| 1720 | *outDisplayRequestMask = data.displayRequests; |
| 1721 | *outLayers = std::move(data.requestedLayers); |
| 1722 | *outLayerRequestMasks = std::move(data.requestMasks); |
| 1723 | } |
| 1724 | |
| 1725 | void CommandReader::takeReleaseFences(Display display, std::vector<Layer>* outLayers, |
| 1726 | std::vector<int>* outReleaseFences) { |
| 1727 | auto found = mReturnData.find(display); |
| 1728 | if (found == mReturnData.end()) { |
| 1729 | outLayers->clear(); |
| 1730 | outReleaseFences->clear(); |
| 1731 | return; |
| 1732 | } |
| 1733 | |
| 1734 | ReturnData& data = found->second; |
| 1735 | |
| 1736 | *outLayers = std::move(data.releasedLayers); |
| 1737 | *outReleaseFences = std::move(data.releaseFences); |
| 1738 | } |
| 1739 | |
| 1740 | void CommandReader::takePresentFence(Display display, int* outPresentFence) { |
| 1741 | auto found = mReturnData.find(display); |
| 1742 | if (found == mReturnData.end()) { |
| 1743 | *outPresentFence = -1; |
| 1744 | return; |
| 1745 | } |
| 1746 | |
| 1747 | ReturnData& data = found->second; |
| 1748 | |
| 1749 | *outPresentFence = data.presentFence; |
| 1750 | data.presentFence = -1; |
| 1751 | } |
| 1752 | |
| 1753 | void CommandReader::takePresentOrValidateStage(Display display, uint32_t* state) { |
| 1754 | auto found = mReturnData.find(display); |
| 1755 | if (found == mReturnData.end()) { |
| 1756 | *state = -1; |
| 1757 | return; |
| 1758 | } |
| 1759 | ReturnData& data = found->second; |
| 1760 | *state = data.presentOrValidateState; |
| 1761 | } |
| 1762 | |
| 1763 | void CommandReader::takeClientTargetProperty( |
| 1764 | Display display, IComposerClient::ClientTargetProperty* outClientTargetProperty) { |
| 1765 | auto found = mReturnData.find(display); |
| 1766 | |
| 1767 | // If not found, return the default values. |
| 1768 | if (found == mReturnData.end()) { |
| 1769 | outClientTargetProperty->pixelFormat = PixelFormat::RGBA_8888; |
| 1770 | outClientTargetProperty->dataspace = Dataspace::UNKNOWN; |
| 1771 | return; |
| 1772 | } |
| 1773 | |
| 1774 | ReturnData& data = found->second; |
| 1775 | *outClientTargetProperty = data.clientTargetProperty; |
| 1776 | } |
| 1777 | |
| 1778 | } // namespace Hwc2 |
| 1779 | } // namespace android |
| 1780 | |
| 1781 | // TODO(b/129481165): remove the #pragma below and fix conversion issues |
| 1782 | #pragma clang diagnostic pop // ignored "-Wconversion" |