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