Ady Abraham | e7385f7 | 2021-09-05 00:54:25 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2021 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 | #undef LOG_TAG |
| 18 | #define LOG_TAG "HwcComposer" |
| 19 | #define ATRACE_TAG ATRACE_TAG_GRAPHICS |
| 20 | |
Ady Abraham | 9fc2805 | 2021-10-14 17:21:38 -0700 | [diff] [blame] | 21 | #include "AidlComposerHal.h" |
Ady Abraham | e7385f7 | 2021-09-05 00:54:25 -0700 | [diff] [blame] | 22 | |
| 23 | #include <android/binder_ibinder_platform.h> |
| 24 | #include <android/binder_manager.h> |
| 25 | #include <log/log.h> |
| 26 | #include <utils/Trace.h> |
| 27 | |
| 28 | #include <aidl/android/hardware/graphics/composer3/BnComposerCallback.h> |
| 29 | |
| 30 | #include <algorithm> |
| 31 | #include <cinttypes> |
| 32 | |
| 33 | namespace android { |
| 34 | |
| 35 | using hardware::hidl_handle; |
| 36 | using hardware::hidl_vec; |
| 37 | using hardware::Return; |
| 38 | |
| 39 | using aidl::android::hardware::graphics::composer3::BnComposerCallback; |
| 40 | using aidl::android::hardware::graphics::composer3::Capability; |
| 41 | using aidl::android::hardware::graphics::composer3::PowerMode; |
| 42 | using aidl::android::hardware::graphics::composer3::VirtualDisplay; |
| 43 | |
Ady Abraham | 4297736 | 2021-12-07 21:04:49 -0800 | [diff] [blame] | 44 | using aidl::android::hardware::graphics::composer3::CommandResultPayload; |
Ady Abraham | a6388c0 | 2021-11-11 21:11:51 -0800 | [diff] [blame] | 45 | |
Ady Abraham | e7385f7 | 2021-09-05 00:54:25 -0700 | [diff] [blame] | 46 | using AidlColorMode = aidl::android::hardware::graphics::composer3::ColorMode; |
| 47 | using AidlContentType = aidl::android::hardware::graphics::composer3::ContentType; |
| 48 | using AidlDisplayIdentification = |
| 49 | aidl::android::hardware::graphics::composer3::DisplayIdentification; |
| 50 | using AidlDisplayContentSample = aidl::android::hardware::graphics::composer3::DisplayContentSample; |
| 51 | using AidlDisplayAttribute = aidl::android::hardware::graphics::composer3::DisplayAttribute; |
| 52 | using AidlDisplayCapability = aidl::android::hardware::graphics::composer3::DisplayCapability; |
Ady Abraham | e7385f7 | 2021-09-05 00:54:25 -0700 | [diff] [blame] | 53 | using AidlHdrCapabilities = aidl::android::hardware::graphics::composer3::HdrCapabilities; |
| 54 | using AidlPerFrameMetadata = aidl::android::hardware::graphics::composer3::PerFrameMetadata; |
| 55 | using AidlPerFrameMetadataKey = aidl::android::hardware::graphics::composer3::PerFrameMetadataKey; |
| 56 | using AidlPerFrameMetadataBlob = aidl::android::hardware::graphics::composer3::PerFrameMetadataBlob; |
| 57 | using AidlRenderIntent = aidl::android::hardware::graphics::composer3::RenderIntent; |
| 58 | using AidlVsyncPeriodChangeConstraints = |
| 59 | aidl::android::hardware::graphics::composer3::VsyncPeriodChangeConstraints; |
| 60 | using AidlVsyncPeriodChangeTimeline = |
| 61 | aidl::android::hardware::graphics::composer3::VsyncPeriodChangeTimeline; |
Ady Abraham | e7385f7 | 2021-09-05 00:54:25 -0700 | [diff] [blame] | 62 | using AidlDisplayContentSamplingAttributes = |
| 63 | aidl::android::hardware::graphics::composer3::DisplayContentSamplingAttributes; |
| 64 | using AidlFormatColorComponent = aidl::android::hardware::graphics::composer3::FormatColorComponent; |
| 65 | using AidlDisplayConnectionType = |
| 66 | aidl::android::hardware::graphics::composer3::DisplayConnectionType; |
Ady Abraham | e7385f7 | 2021-09-05 00:54:25 -0700 | [diff] [blame] | 67 | |
| 68 | using AidlColorTransform = aidl::android::hardware::graphics::common::ColorTransform; |
| 69 | using AidlDataspace = aidl::android::hardware::graphics::common::Dataspace; |
| 70 | using AidlFRect = aidl::android::hardware::graphics::common::FRect; |
| 71 | using AidlRect = aidl::android::hardware::graphics::common::Rect; |
| 72 | using AidlTransform = aidl::android::hardware::graphics::common::Transform; |
| 73 | |
| 74 | namespace Hwc2 { |
| 75 | |
| 76 | namespace { |
| 77 | |
| 78 | template <typename To, typename From> |
| 79 | To translate(From x) { |
| 80 | return static_cast<To>(x); |
| 81 | } |
| 82 | |
| 83 | template <typename To, typename From> |
| 84 | std::vector<To> translate(const std::vector<From>& in) { |
| 85 | std::vector<To> out; |
| 86 | out.reserve(in.size()); |
| 87 | std::transform(in.begin(), in.end(), std::back_inserter(out), |
| 88 | [](From x) { return translate<To>(x); }); |
| 89 | return out; |
| 90 | } |
| 91 | |
| 92 | template <> |
| 93 | AidlRect translate(IComposerClient::Rect x) { |
| 94 | return AidlRect{ |
| 95 | .left = x.left, |
| 96 | .top = x.top, |
| 97 | .right = x.right, |
| 98 | .bottom = x.bottom, |
| 99 | }; |
| 100 | } |
| 101 | |
| 102 | template <> |
| 103 | AidlFRect translate(IComposerClient::FRect x) { |
| 104 | return AidlFRect{ |
| 105 | .left = x.left, |
| 106 | .top = x.top, |
| 107 | .right = x.right, |
| 108 | .bottom = x.bottom, |
| 109 | }; |
| 110 | } |
| 111 | |
| 112 | template <> |
Ady Abraham | e7385f7 | 2021-09-05 00:54:25 -0700 | [diff] [blame] | 113 | AidlPerFrameMetadataBlob translate(IComposerClient::PerFrameMetadataBlob x) { |
| 114 | AidlPerFrameMetadataBlob blob; |
| 115 | blob.key = translate<AidlPerFrameMetadataKey>(x.key), |
| 116 | std::copy(blob.blob.begin(), blob.blob.end(), x.blob.begin()); |
| 117 | return blob; |
| 118 | } |
| 119 | |
| 120 | template <> |
| 121 | AidlPerFrameMetadata translate(IComposerClient::PerFrameMetadata x) { |
| 122 | return AidlPerFrameMetadata{ |
| 123 | .key = translate<AidlPerFrameMetadataKey>(x.key), |
| 124 | .value = x.value, |
| 125 | }; |
| 126 | } |
| 127 | |
| 128 | template <> |
| 129 | DisplayedFrameStats translate(AidlDisplayContentSample x) { |
| 130 | return DisplayedFrameStats{ |
| 131 | .numFrames = static_cast<uint64_t>(x.frameCount), |
| 132 | .component_0_sample = translate<uint64_t>(x.sampleComponent0), |
| 133 | .component_1_sample = translate<uint64_t>(x.sampleComponent1), |
| 134 | .component_2_sample = translate<uint64_t>(x.sampleComponent2), |
| 135 | .component_3_sample = translate<uint64_t>(x.sampleComponent3), |
| 136 | }; |
| 137 | } |
| 138 | |
| 139 | template <> |
| 140 | AidlVsyncPeriodChangeConstraints translate(IComposerClient::VsyncPeriodChangeConstraints x) { |
| 141 | return AidlVsyncPeriodChangeConstraints{ |
| 142 | .desiredTimeNanos = x.desiredTimeNanos, |
| 143 | .seamlessRequired = x.seamlessRequired, |
| 144 | }; |
| 145 | } |
| 146 | |
| 147 | template <> |
| 148 | VsyncPeriodChangeTimeline translate(AidlVsyncPeriodChangeTimeline x) { |
| 149 | return VsyncPeriodChangeTimeline{ |
| 150 | .newVsyncAppliedTimeNanos = x.newVsyncAppliedTimeNanos, |
| 151 | .refreshRequired = x.refreshRequired, |
| 152 | .refreshTimeNanos = x.refreshTimeNanos, |
| 153 | }; |
| 154 | } |
| 155 | |
| 156 | template <> |
Ady Abraham | a6388c0 | 2021-11-11 21:11:51 -0800 | [diff] [blame] | 157 | IComposerClient::ClientTargetProperty translate(ClientTargetProperty x) { |
| 158 | return IComposerClient::ClientTargetProperty{ |
| 159 | .pixelFormat = translate<PixelFormat>(x.pixelFormat), |
| 160 | .dataspace = translate<Dataspace>(x.dataspace), |
| 161 | }; |
| 162 | } |
| 163 | |
Ady Abraham | e7385f7 | 2021-09-05 00:54:25 -0700 | [diff] [blame] | 164 | mat4 makeMat4(std::vector<float> in) { |
| 165 | return mat4(static_cast<const float*>(in.data())); |
| 166 | } |
| 167 | |
| 168 | } // namespace |
| 169 | |
| 170 | class AidlIComposerCallbackWrapper : public BnComposerCallback { |
| 171 | public: |
| 172 | AidlIComposerCallbackWrapper(sp<V2_4::IComposerCallback> callback) |
| 173 | : mCallback(std::move(callback)) {} |
| 174 | |
| 175 | ::ndk::ScopedAStatus onHotplug(int64_t in_display, bool in_connected) override { |
| 176 | const auto connection = in_connected ? V2_4::IComposerCallback::Connection::CONNECTED |
| 177 | : V2_4::IComposerCallback::Connection::DISCONNECTED; |
| 178 | mCallback->onHotplug(translate<Display>(in_display), connection); |
| 179 | return ::ndk::ScopedAStatus::ok(); |
| 180 | } |
| 181 | |
| 182 | ::ndk::ScopedAStatus onRefresh(int64_t in_display) override { |
| 183 | mCallback->onRefresh(translate<Display>(in_display)); |
| 184 | return ::ndk::ScopedAStatus::ok(); |
| 185 | } |
| 186 | ::ndk::ScopedAStatus onSeamlessPossible(int64_t in_display) override { |
| 187 | mCallback->onSeamlessPossible(translate<Display>(in_display)); |
| 188 | return ::ndk::ScopedAStatus::ok(); |
| 189 | } |
| 190 | ::ndk::ScopedAStatus onVsync(int64_t in_display, int64_t in_timestamp, |
| 191 | int32_t in_vsyncPeriodNanos) override { |
| 192 | mCallback->onVsync_2_4(translate<Display>(in_display), in_timestamp, |
| 193 | static_cast<uint32_t>(in_vsyncPeriodNanos)); |
| 194 | return ::ndk::ScopedAStatus::ok(); |
| 195 | } |
| 196 | ::ndk::ScopedAStatus onVsyncPeriodTimingChanged( |
| 197 | int64_t in_display, const AidlVsyncPeriodChangeTimeline& in_updatedTimeline) override { |
| 198 | mCallback->onVsyncPeriodTimingChanged(translate<Display>(in_display), |
| 199 | translate<V2_4::VsyncPeriodChangeTimeline>( |
| 200 | in_updatedTimeline)); |
| 201 | return ::ndk::ScopedAStatus::ok(); |
| 202 | } |
| 203 | |
| 204 | private: |
| 205 | sp<V2_4::IComposerCallback> mCallback; |
| 206 | }; |
| 207 | |
Ady Abraham | 9fc2805 | 2021-10-14 17:21:38 -0700 | [diff] [blame] | 208 | std::string AidlComposer::instance(const std::string& serviceName) { |
| 209 | return std::string(AidlIComposer::descriptor) + "/" + serviceName; |
| 210 | } |
| 211 | |
| 212 | bool AidlComposer::isDeclared(const std::string& serviceName) { |
| 213 | return AServiceManager_isDeclared(instance(serviceName).c_str()); |
| 214 | } |
Ady Abraham | e7385f7 | 2021-09-05 00:54:25 -0700 | [diff] [blame] | 215 | |
Ady Abraham | a6388c0 | 2021-11-11 21:11:51 -0800 | [diff] [blame] | 216 | AidlComposer::AidlComposer(const std::string& serviceName) { |
Ady Abraham | e7385f7 | 2021-09-05 00:54:25 -0700 | [diff] [blame] | 217 | // This only waits if the service is actually declared |
Ady Abraham | 9fc2805 | 2021-10-14 17:21:38 -0700 | [diff] [blame] | 218 | mAidlComposer = AidlIComposer::fromBinder( |
| 219 | ndk::SpAIBinder(AServiceManager_waitForService(instance(serviceName).c_str()))); |
Ady Abraham | e7385f7 | 2021-09-05 00:54:25 -0700 | [diff] [blame] | 220 | if (!mAidlComposer) { |
| 221 | LOG_ALWAYS_FATAL("Failed to get AIDL composer service"); |
| 222 | return; |
| 223 | } |
| 224 | |
| 225 | if (!mAidlComposer->createClient(&mAidlComposerClient).isOk()) { |
| 226 | LOG_ALWAYS_FATAL("Can't create AidlComposerClient, fallback to HIDL"); |
| 227 | return; |
| 228 | } |
| 229 | |
| 230 | ALOGI("Loaded AIDL composer3 HAL service"); |
| 231 | } |
| 232 | |
| 233 | AidlComposer::~AidlComposer() = default; |
| 234 | |
Ady Abraham | 4d211cf | 2021-12-14 16:19:03 -0800 | [diff] [blame] | 235 | bool AidlComposer::isSupported(OptionalFeature feature) const { |
| 236 | switch (feature) { |
| 237 | case OptionalFeature::RefreshRateSwitching: |
Ady Abraham | 43065bd | 2021-12-10 17:22:15 -0800 | [diff] [blame] | 238 | case OptionalFeature::ExpectedPresentTime: |
Alec Mouri | cdf1679 | 2021-12-10 13:16:06 -0800 | [diff] [blame] | 239 | case OptionalFeature::DisplayBrightnessCommand: |
Kriti Dang | 7defaf3 | 2021-11-15 11:55:43 +0100 | [diff] [blame] | 240 | case OptionalFeature::BootDisplayConfig: |
Ady Abraham | 4d211cf | 2021-12-14 16:19:03 -0800 | [diff] [blame] | 241 | return true; |
| 242 | } |
| 243 | } |
| 244 | |
Ady Abraham | e7385f7 | 2021-09-05 00:54:25 -0700 | [diff] [blame] | 245 | std::vector<IComposer::Capability> AidlComposer::getCapabilities() { |
| 246 | std::vector<Capability> capabilities; |
| 247 | const auto status = mAidlComposer->getCapabilities(&capabilities); |
| 248 | if (!status.isOk()) { |
| 249 | ALOGE("getCapabilities failed %s", status.getDescription().c_str()); |
| 250 | return {}; |
| 251 | } |
| 252 | return translate<IComposer::Capability>(capabilities); |
| 253 | } |
| 254 | |
| 255 | std::string AidlComposer::dumpDebugInfo() { |
| 256 | std::string info; |
| 257 | const auto status = mAidlComposer->dumpDebugInfo(&info); |
| 258 | if (!status.isOk()) { |
| 259 | ALOGE("dumpDebugInfo failed %s", status.getDescription().c_str()); |
| 260 | return {}; |
| 261 | } |
| 262 | return info; |
| 263 | } |
| 264 | |
| 265 | void AidlComposer::registerCallback(const sp<IComposerCallback>& callback) { |
| 266 | if (mAidlComposerCallback) { |
| 267 | ALOGE("Callback already registered"); |
| 268 | } |
Ady Abraham | 9fc2805 | 2021-10-14 17:21:38 -0700 | [diff] [blame] | 269 | mAidlComposerCallback = ndk::SharedRefBase::make<AidlIComposerCallbackWrapper>(callback); |
Ady Abraham | e7385f7 | 2021-09-05 00:54:25 -0700 | [diff] [blame] | 270 | AIBinder_setMinSchedulerPolicy(mAidlComposerCallback->asBinder().get(), SCHED_FIFO, 2); |
| 271 | |
| 272 | const auto status = mAidlComposerClient->registerCallback(mAidlComposerCallback); |
| 273 | if (!status.isOk()) { |
| 274 | ALOGE("registerCallback failed %s", status.getDescription().c_str()); |
| 275 | } |
| 276 | } |
| 277 | |
| 278 | void AidlComposer::resetCommands() { |
| 279 | mWriter.reset(); |
| 280 | } |
| 281 | |
| 282 | Error AidlComposer::executeCommands() { |
| 283 | return execute(); |
| 284 | } |
| 285 | |
| 286 | uint32_t AidlComposer::getMaxVirtualDisplayCount() { |
| 287 | int32_t count = 0; |
| 288 | const auto status = mAidlComposerClient->getMaxVirtualDisplayCount(&count); |
| 289 | if (!status.isOk()) { |
| 290 | ALOGE("getMaxVirtualDisplayCount failed %s", status.getDescription().c_str()); |
| 291 | return 0; |
| 292 | } |
| 293 | return static_cast<uint32_t>(count); |
| 294 | } |
| 295 | |
| 296 | Error AidlComposer::createVirtualDisplay(uint32_t width, uint32_t height, PixelFormat* format, |
| 297 | Display* outDisplay) { |
| 298 | using AidlPixelFormat = aidl::android::hardware::graphics::common::PixelFormat; |
| 299 | const int32_t bufferSlotCount = 1; |
| 300 | VirtualDisplay virtualDisplay; |
| 301 | const auto status = |
| 302 | mAidlComposerClient->createVirtualDisplay(static_cast<int32_t>(width), |
| 303 | static_cast<int32_t>(height), |
| 304 | static_cast<AidlPixelFormat>(*format), |
| 305 | bufferSlotCount, &virtualDisplay); |
| 306 | |
| 307 | if (!status.isOk()) { |
| 308 | ALOGE("createVirtualDisplay failed %s", status.getDescription().c_str()); |
| 309 | return static_cast<Error>(status.getServiceSpecificError()); |
| 310 | } |
| 311 | |
| 312 | *outDisplay = translate<Display>(virtualDisplay.display); |
| 313 | *format = static_cast<PixelFormat>(virtualDisplay.format); |
| 314 | return Error::NONE; |
| 315 | } |
| 316 | |
| 317 | Error AidlComposer::destroyVirtualDisplay(Display display) { |
| 318 | const auto status = mAidlComposerClient->destroyVirtualDisplay(translate<int64_t>(display)); |
| 319 | if (!status.isOk()) { |
| 320 | ALOGE("destroyVirtualDisplay failed %s", status.getDescription().c_str()); |
| 321 | return static_cast<Error>(status.getServiceSpecificError()); |
| 322 | } |
| 323 | return Error::NONE; |
| 324 | } |
| 325 | |
| 326 | Error AidlComposer::acceptDisplayChanges(Display display) { |
Ady Abraham | a6388c0 | 2021-11-11 21:11:51 -0800 | [diff] [blame] | 327 | mWriter.acceptDisplayChanges(translate<int64_t>(display)); |
Ady Abraham | e7385f7 | 2021-09-05 00:54:25 -0700 | [diff] [blame] | 328 | return Error::NONE; |
| 329 | } |
| 330 | |
| 331 | Error AidlComposer::createLayer(Display display, Layer* outLayer) { |
| 332 | int64_t layer; |
| 333 | const auto status = mAidlComposerClient->createLayer(translate<int64_t>(display), |
| 334 | kMaxLayerBufferCount, &layer); |
| 335 | if (!status.isOk()) { |
| 336 | ALOGE("createLayer failed %s", status.getDescription().c_str()); |
| 337 | return static_cast<Error>(status.getServiceSpecificError()); |
| 338 | } |
| 339 | |
| 340 | *outLayer = translate<Layer>(layer); |
| 341 | return Error::NONE; |
| 342 | } |
| 343 | |
| 344 | Error AidlComposer::destroyLayer(Display display, Layer layer) { |
| 345 | const auto status = mAidlComposerClient->destroyLayer(translate<int64_t>(display), |
| 346 | translate<int64_t>(layer)); |
| 347 | if (!status.isOk()) { |
| 348 | ALOGE("destroyLayer failed %s", status.getDescription().c_str()); |
| 349 | return static_cast<Error>(status.getServiceSpecificError()); |
| 350 | } |
| 351 | return Error::NONE; |
| 352 | } |
| 353 | |
| 354 | Error AidlComposer::getActiveConfig(Display display, Config* outConfig) { |
| 355 | int32_t config; |
| 356 | const auto status = mAidlComposerClient->getActiveConfig(translate<int64_t>(display), &config); |
| 357 | if (!status.isOk()) { |
| 358 | ALOGE("getActiveConfig failed %s", status.getDescription().c_str()); |
| 359 | return static_cast<Error>(status.getServiceSpecificError()); |
| 360 | } |
| 361 | *outConfig = translate<Config>(config); |
| 362 | return Error::NONE; |
| 363 | } |
| 364 | |
| 365 | Error AidlComposer::getChangedCompositionTypes( |
| 366 | Display display, std::vector<Layer>* outLayers, |
Leon Scroggins III | 2e1aa18 | 2021-12-01 17:33:12 -0500 | [diff] [blame] | 367 | std::vector<aidl::android::hardware::graphics::composer3::Composition>* outTypes) { |
Ady Abraham | de79278 | 2021-12-20 10:00:49 -0800 | [diff] [blame] | 368 | const auto changedLayers = mReader.takeChangedCompositionTypes(translate<int64_t>(display)); |
| 369 | outLayers->reserve(changedLayers.size()); |
| 370 | outTypes->reserve(changedLayers.size()); |
Ady Abraham | a6388c0 | 2021-11-11 21:11:51 -0800 | [diff] [blame] | 371 | |
Ady Abraham | de79278 | 2021-12-20 10:00:49 -0800 | [diff] [blame] | 372 | for (const auto& layer : changedLayers) { |
| 373 | outLayers->emplace_back(translate<Layer>(layer.layer)); |
| 374 | outTypes->emplace_back(layer.composition); |
| 375 | } |
Ady Abraham | e7385f7 | 2021-09-05 00:54:25 -0700 | [diff] [blame] | 376 | return Error::NONE; |
| 377 | } |
| 378 | |
| 379 | Error AidlComposer::getColorModes(Display display, std::vector<ColorMode>* outModes) { |
| 380 | std::vector<AidlColorMode> modes; |
| 381 | const auto status = mAidlComposerClient->getColorModes(translate<int64_t>(display), &modes); |
| 382 | if (!status.isOk()) { |
| 383 | ALOGE("getColorModes failed %s", status.getDescription().c_str()); |
| 384 | return static_cast<Error>(status.getServiceSpecificError()); |
| 385 | } |
| 386 | *outModes = translate<ColorMode>(modes); |
| 387 | return Error::NONE; |
| 388 | } |
| 389 | |
| 390 | Error AidlComposer::getDisplayAttribute(Display display, Config config, |
| 391 | IComposerClient::Attribute attribute, int32_t* outValue) { |
| 392 | const auto status = |
| 393 | mAidlComposerClient->getDisplayAttribute(translate<int64_t>(display), |
| 394 | translate<int32_t>(config), |
| 395 | static_cast<AidlDisplayAttribute>(attribute), |
| 396 | outValue); |
| 397 | if (!status.isOk()) { |
| 398 | ALOGE("getDisplayAttribute failed %s", status.getDescription().c_str()); |
| 399 | return static_cast<Error>(status.getServiceSpecificError()); |
| 400 | } |
| 401 | return Error::NONE; |
| 402 | } |
| 403 | |
| 404 | Error AidlComposer::getDisplayConfigs(Display display, std::vector<Config>* outConfigs) { |
| 405 | std::vector<int32_t> configs; |
| 406 | const auto status = |
| 407 | mAidlComposerClient->getDisplayConfigs(translate<int64_t>(display), &configs); |
| 408 | if (!status.isOk()) { |
| 409 | ALOGE("getDisplayConfigs failed %s", status.getDescription().c_str()); |
| 410 | return static_cast<Error>(status.getServiceSpecificError()); |
| 411 | } |
| 412 | *outConfigs = translate<Config>(configs); |
| 413 | return Error::NONE; |
| 414 | } |
| 415 | |
| 416 | Error AidlComposer::getDisplayName(Display display, std::string* outName) { |
| 417 | const auto status = mAidlComposerClient->getDisplayName(translate<int64_t>(display), outName); |
| 418 | if (!status.isOk()) { |
| 419 | ALOGE("getDisplayName failed %s", status.getDescription().c_str()); |
| 420 | return static_cast<Error>(status.getServiceSpecificError()); |
| 421 | } |
| 422 | return Error::NONE; |
| 423 | } |
| 424 | |
| 425 | Error AidlComposer::getDisplayRequests(Display display, uint32_t* outDisplayRequestMask, |
| 426 | std::vector<Layer>* outLayers, |
| 427 | std::vector<uint32_t>* outLayerRequestMasks) { |
Ady Abraham | de79278 | 2021-12-20 10:00:49 -0800 | [diff] [blame] | 428 | const auto displayRequests = mReader.takeDisplayRequests(translate<int64_t>(display)); |
| 429 | *outDisplayRequestMask = translate<uint32_t>(displayRequests.mask); |
| 430 | outLayers->reserve(displayRequests.layerRequests.size()); |
| 431 | outLayerRequestMasks->reserve(displayRequests.layerRequests.size()); |
| 432 | |
| 433 | for (const auto& layer : displayRequests.layerRequests) { |
| 434 | outLayers->emplace_back(translate<Layer>(layer.layer)); |
| 435 | outLayerRequestMasks->emplace_back(translate<uint32_t>(layer.mask)); |
| 436 | } |
Ady Abraham | e7385f7 | 2021-09-05 00:54:25 -0700 | [diff] [blame] | 437 | return Error::NONE; |
| 438 | } |
| 439 | |
| 440 | Error AidlComposer::getDozeSupport(Display display, bool* outSupport) { |
Ady Abraham | 33b92b9 | 2021-12-08 18:30:27 -0800 | [diff] [blame] | 441 | std::vector<AidlDisplayCapability> capabilities; |
Ady Abraham | e7385f7 | 2021-09-05 00:54:25 -0700 | [diff] [blame] | 442 | const auto status = |
Ady Abraham | 33b92b9 | 2021-12-08 18:30:27 -0800 | [diff] [blame] | 443 | mAidlComposerClient->getDisplayCapabilities(translate<int64_t>(display), &capabilities); |
Ady Abraham | e7385f7 | 2021-09-05 00:54:25 -0700 | [diff] [blame] | 444 | if (!status.isOk()) { |
Ady Abraham | 33b92b9 | 2021-12-08 18:30:27 -0800 | [diff] [blame] | 445 | ALOGE("getDisplayCapabilities failed %s", status.getDescription().c_str()); |
Ady Abraham | e7385f7 | 2021-09-05 00:54:25 -0700 | [diff] [blame] | 446 | return static_cast<Error>(status.getServiceSpecificError()); |
| 447 | } |
Ady Abraham | 33b92b9 | 2021-12-08 18:30:27 -0800 | [diff] [blame] | 448 | *outSupport = std::find(capabilities.begin(), capabilities.end(), |
| 449 | AidlDisplayCapability::DOZE) != capabilities.end(); |
Ady Abraham | e7385f7 | 2021-09-05 00:54:25 -0700 | [diff] [blame] | 450 | return Error::NONE; |
| 451 | } |
| 452 | |
| 453 | Error AidlComposer::getHdrCapabilities(Display display, std::vector<Hdr>* outTypes, |
| 454 | float* outMaxLuminance, float* outMaxAverageLuminance, |
| 455 | float* outMinLuminance) { |
| 456 | AidlHdrCapabilities capabilities; |
| 457 | const auto status = |
| 458 | mAidlComposerClient->getHdrCapabilities(translate<int64_t>(display), &capabilities); |
| 459 | if (!status.isOk()) { |
| 460 | ALOGE("getHdrCapabilities failed %s", status.getDescription().c_str()); |
| 461 | return static_cast<Error>(status.getServiceSpecificError()); |
| 462 | } |
| 463 | |
| 464 | *outTypes = translate<Hdr>(capabilities.types); |
| 465 | *outMaxLuminance = capabilities.maxLuminance; |
| 466 | *outMaxAverageLuminance = capabilities.maxAverageLuminance; |
| 467 | *outMinLuminance = capabilities.minLuminance; |
| 468 | return Error::NONE; |
| 469 | } |
| 470 | |
| 471 | Error AidlComposer::getReleaseFences(Display display, std::vector<Layer>* outLayers, |
| 472 | std::vector<int>* outReleaseFences) { |
Ady Abraham | de79278 | 2021-12-20 10:00:49 -0800 | [diff] [blame] | 473 | auto fences = mReader.takeReleaseFences(translate<int64_t>(display)); |
| 474 | outLayers->reserve(fences.size()); |
| 475 | outReleaseFences->reserve(fences.size()); |
| 476 | |
| 477 | for (auto& fence : fences) { |
| 478 | outLayers->emplace_back(translate<Layer>(fence.layer)); |
| 479 | // take ownership |
| 480 | const int fenceOwner = fence.fence.get(); |
| 481 | *fence.fence.getR() = -1; |
| 482 | outReleaseFences->emplace_back(fenceOwner); |
| 483 | } |
Ady Abraham | e7385f7 | 2021-09-05 00:54:25 -0700 | [diff] [blame] | 484 | return Error::NONE; |
| 485 | } |
| 486 | |
| 487 | Error AidlComposer::presentDisplay(Display display, int* outPresentFence) { |
| 488 | ATRACE_NAME("HwcPresentDisplay"); |
Ady Abraham | a6388c0 | 2021-11-11 21:11:51 -0800 | [diff] [blame] | 489 | mWriter.presentDisplay(translate<int64_t>(display)); |
Ady Abraham | e7385f7 | 2021-09-05 00:54:25 -0700 | [diff] [blame] | 490 | |
| 491 | Error error = execute(); |
| 492 | if (error != Error::NONE) { |
| 493 | return error; |
| 494 | } |
| 495 | |
Ady Abraham | de79278 | 2021-12-20 10:00:49 -0800 | [diff] [blame] | 496 | auto fence = mReader.takePresentFence(translate<int64_t>(display)); |
| 497 | // take ownership |
| 498 | *outPresentFence = fence.get(); |
| 499 | *fence.getR() = -1; |
Ady Abraham | e7385f7 | 2021-09-05 00:54:25 -0700 | [diff] [blame] | 500 | return Error::NONE; |
| 501 | } |
| 502 | |
| 503 | Error AidlComposer::setActiveConfig(Display display, Config config) { |
| 504 | const auto status = mAidlComposerClient->setActiveConfig(translate<int64_t>(display), |
| 505 | translate<int32_t>(config)); |
| 506 | if (!status.isOk()) { |
| 507 | ALOGE("setActiveConfig failed %s", status.getDescription().c_str()); |
| 508 | return static_cast<Error>(status.getServiceSpecificError()); |
| 509 | } |
| 510 | return Error::NONE; |
| 511 | } |
| 512 | |
| 513 | Error AidlComposer::setClientTarget(Display display, uint32_t slot, const sp<GraphicBuffer>& target, |
| 514 | int acquireFence, Dataspace dataspace, |
| 515 | const std::vector<IComposerClient::Rect>& damage) { |
Ady Abraham | e7385f7 | 2021-09-05 00:54:25 -0700 | [diff] [blame] | 516 | const native_handle_t* handle = nullptr; |
| 517 | if (target.get()) { |
| 518 | handle = target->getNativeBuffer()->handle; |
| 519 | } |
| 520 | |
Ady Abraham | a6388c0 | 2021-11-11 21:11:51 -0800 | [diff] [blame] | 521 | mWriter.setClientTarget(translate<int64_t>(display), slot, handle, acquireFence, |
Ady Abraham | e7385f7 | 2021-09-05 00:54:25 -0700 | [diff] [blame] | 522 | translate<aidl::android::hardware::graphics::common::Dataspace>( |
| 523 | dataspace), |
| 524 | translate<AidlRect>(damage)); |
| 525 | return Error::NONE; |
| 526 | } |
| 527 | |
| 528 | Error AidlComposer::setColorMode(Display display, ColorMode mode, RenderIntent renderIntent) { |
| 529 | const auto status = |
| 530 | mAidlComposerClient->setColorMode(translate<int64_t>(display), |
| 531 | translate<AidlColorMode>(mode), |
| 532 | translate<AidlRenderIntent>(renderIntent)); |
| 533 | if (!status.isOk()) { |
| 534 | ALOGE("setColorMode failed %s", status.getDescription().c_str()); |
| 535 | return static_cast<Error>(status.getServiceSpecificError()); |
| 536 | } |
| 537 | return Error::NONE; |
| 538 | } |
| 539 | |
Ady Abraham | dc011a9 | 2021-12-21 14:06:44 -0800 | [diff] [blame] | 540 | Error AidlComposer::setColorTransform(Display display, const float* matrix) { |
| 541 | mWriter.setColorTransform(translate<int64_t>(display), matrix); |
Ady Abraham | e7385f7 | 2021-09-05 00:54:25 -0700 | [diff] [blame] | 542 | return Error::NONE; |
| 543 | } |
| 544 | |
| 545 | Error AidlComposer::setOutputBuffer(Display display, const native_handle_t* buffer, |
| 546 | int releaseFence) { |
Ady Abraham | a6388c0 | 2021-11-11 21:11:51 -0800 | [diff] [blame] | 547 | mWriter.setOutputBuffer(translate<int64_t>(display), 0, buffer, dup(releaseFence)); |
Ady Abraham | e7385f7 | 2021-09-05 00:54:25 -0700 | [diff] [blame] | 548 | return Error::NONE; |
| 549 | } |
| 550 | |
| 551 | Error AidlComposer::setPowerMode(Display display, IComposerClient::PowerMode mode) { |
| 552 | const auto status = mAidlComposerClient->setPowerMode(translate<int64_t>(display), |
| 553 | translate<PowerMode>(mode)); |
| 554 | if (!status.isOk()) { |
| 555 | ALOGE("setPowerMode failed %s", status.getDescription().c_str()); |
| 556 | return static_cast<Error>(status.getServiceSpecificError()); |
| 557 | } |
| 558 | return Error::NONE; |
| 559 | } |
| 560 | |
| 561 | Error AidlComposer::setVsyncEnabled(Display display, IComposerClient::Vsync enabled) { |
| 562 | const bool enableVsync = enabled == IComposerClient::Vsync::ENABLE; |
| 563 | const auto status = |
| 564 | mAidlComposerClient->setVsyncEnabled(translate<int64_t>(display), enableVsync); |
| 565 | if (!status.isOk()) { |
| 566 | ALOGE("setVsyncEnabled failed %s", status.getDescription().c_str()); |
| 567 | return static_cast<Error>(status.getServiceSpecificError()); |
| 568 | } |
| 569 | return Error::NONE; |
| 570 | } |
| 571 | |
| 572 | Error AidlComposer::setClientTargetSlotCount(Display display) { |
| 573 | const int32_t bufferSlotCount = BufferQueue::NUM_BUFFER_SLOTS; |
| 574 | const auto status = mAidlComposerClient->setClientTargetSlotCount(translate<int64_t>(display), |
| 575 | bufferSlotCount); |
| 576 | if (!status.isOk()) { |
| 577 | ALOGE("setClientTargetSlotCount failed %s", status.getDescription().c_str()); |
| 578 | return static_cast<Error>(status.getServiceSpecificError()); |
| 579 | } |
| 580 | return Error::NONE; |
| 581 | } |
| 582 | |
Ady Abraham | 43065bd | 2021-12-10 17:22:15 -0800 | [diff] [blame] | 583 | Error AidlComposer::validateDisplay(Display display, nsecs_t expectedPresentTime, |
| 584 | uint32_t* outNumTypes, uint32_t* outNumRequests) { |
Ady Abraham | e7385f7 | 2021-09-05 00:54:25 -0700 | [diff] [blame] | 585 | ATRACE_NAME("HwcValidateDisplay"); |
Ady Abraham | 43065bd | 2021-12-10 17:22:15 -0800 | [diff] [blame] | 586 | mWriter.validateDisplay(translate<int64_t>(display), |
| 587 | ClockMonotonicTimestamp{expectedPresentTime}); |
Ady Abraham | e7385f7 | 2021-09-05 00:54:25 -0700 | [diff] [blame] | 588 | |
| 589 | Error error = execute(); |
| 590 | if (error != Error::NONE) { |
| 591 | return error; |
| 592 | } |
| 593 | |
Ady Abraham | a6388c0 | 2021-11-11 21:11:51 -0800 | [diff] [blame] | 594 | mReader.hasChanges(translate<int64_t>(display), outNumTypes, outNumRequests); |
Ady Abraham | e7385f7 | 2021-09-05 00:54:25 -0700 | [diff] [blame] | 595 | |
| 596 | return Error::NONE; |
| 597 | } |
| 598 | |
Ady Abraham | 43065bd | 2021-12-10 17:22:15 -0800 | [diff] [blame] | 599 | Error AidlComposer::presentOrValidateDisplay(Display display, nsecs_t expectedPresentTime, |
| 600 | uint32_t* outNumTypes, uint32_t* outNumRequests, |
| 601 | int* outPresentFence, uint32_t* state) { |
Ady Abraham | e7385f7 | 2021-09-05 00:54:25 -0700 | [diff] [blame] | 602 | ATRACE_NAME("HwcPresentOrValidateDisplay"); |
Ady Abraham | 43065bd | 2021-12-10 17:22:15 -0800 | [diff] [blame] | 603 | mWriter.presentOrvalidateDisplay(translate<int64_t>(display), |
| 604 | ClockMonotonicTimestamp{expectedPresentTime}); |
Ady Abraham | e7385f7 | 2021-09-05 00:54:25 -0700 | [diff] [blame] | 605 | |
| 606 | Error error = execute(); |
| 607 | if (error != Error::NONE) { |
| 608 | return error; |
| 609 | } |
| 610 | |
Ady Abraham | de79278 | 2021-12-20 10:00:49 -0800 | [diff] [blame] | 611 | const auto result = mReader.takePresentOrValidateStage(translate<int64_t>(display)); |
| 612 | if (!result.has_value()) { |
| 613 | *state = translate<uint32_t>(-1); |
| 614 | return Error::NO_RESOURCES; |
Ady Abraham | e7385f7 | 2021-09-05 00:54:25 -0700 | [diff] [blame] | 615 | } |
| 616 | |
Ady Abraham | de79278 | 2021-12-20 10:00:49 -0800 | [diff] [blame] | 617 | *state = translate<uint32_t>(*result); |
| 618 | |
| 619 | if (*result == PresentOrValidate::Result::Presented) { |
| 620 | auto fence = mReader.takePresentFence(translate<int64_t>(display)); |
| 621 | // take ownership |
| 622 | *outPresentFence = fence.get(); |
| 623 | *fence.getR() = -1; |
| 624 | } |
| 625 | |
| 626 | if (*result == PresentOrValidate::Result::Validated) { |
Ady Abraham | a6388c0 | 2021-11-11 21:11:51 -0800 | [diff] [blame] | 627 | mReader.hasChanges(translate<int64_t>(display), outNumTypes, outNumRequests); |
Ady Abraham | e7385f7 | 2021-09-05 00:54:25 -0700 | [diff] [blame] | 628 | } |
| 629 | |
| 630 | return Error::NONE; |
| 631 | } |
| 632 | |
| 633 | Error AidlComposer::setCursorPosition(Display display, Layer layer, int32_t x, int32_t y) { |
Ady Abraham | a6388c0 | 2021-11-11 21:11:51 -0800 | [diff] [blame] | 634 | mWriter.setLayerCursorPosition(translate<int64_t>(display), translate<int64_t>(layer), x, y); |
Ady Abraham | e7385f7 | 2021-09-05 00:54:25 -0700 | [diff] [blame] | 635 | return Error::NONE; |
| 636 | } |
| 637 | |
| 638 | Error AidlComposer::setLayerBuffer(Display display, Layer layer, uint32_t slot, |
| 639 | const sp<GraphicBuffer>& buffer, int acquireFence) { |
Ady Abraham | e7385f7 | 2021-09-05 00:54:25 -0700 | [diff] [blame] | 640 | const native_handle_t* handle = nullptr; |
| 641 | if (buffer.get()) { |
| 642 | handle = buffer->getNativeBuffer()->handle; |
| 643 | } |
| 644 | |
Ady Abraham | a6388c0 | 2021-11-11 21:11:51 -0800 | [diff] [blame] | 645 | mWriter.setLayerBuffer(translate<int64_t>(display), translate<int64_t>(layer), slot, handle, |
| 646 | acquireFence); |
Ady Abraham | e7385f7 | 2021-09-05 00:54:25 -0700 | [diff] [blame] | 647 | return Error::NONE; |
| 648 | } |
| 649 | |
| 650 | Error AidlComposer::setLayerSurfaceDamage(Display display, Layer layer, |
| 651 | const std::vector<IComposerClient::Rect>& damage) { |
Ady Abraham | a6388c0 | 2021-11-11 21:11:51 -0800 | [diff] [blame] | 652 | mWriter.setLayerSurfaceDamage(translate<int64_t>(display), translate<int64_t>(layer), |
| 653 | translate<AidlRect>(damage)); |
Ady Abraham | e7385f7 | 2021-09-05 00:54:25 -0700 | [diff] [blame] | 654 | return Error::NONE; |
| 655 | } |
| 656 | |
| 657 | Error AidlComposer::setLayerBlendMode(Display display, Layer layer, |
| 658 | IComposerClient::BlendMode mode) { |
Ady Abraham | a6388c0 | 2021-11-11 21:11:51 -0800 | [diff] [blame] | 659 | mWriter.setLayerBlendMode(translate<int64_t>(display), translate<int64_t>(layer), |
| 660 | translate<BlendMode>(mode)); |
Ady Abraham | e7385f7 | 2021-09-05 00:54:25 -0700 | [diff] [blame] | 661 | return Error::NONE; |
| 662 | } |
| 663 | |
Ady Abraham | 6e60b14 | 2022-01-06 18:10:35 -0800 | [diff] [blame] | 664 | Error AidlComposer::setLayerColor(Display display, Layer layer, const Color& color) { |
| 665 | mWriter.setLayerColor(translate<int64_t>(display), translate<int64_t>(layer), color); |
Ady Abraham | e7385f7 | 2021-09-05 00:54:25 -0700 | [diff] [blame] | 666 | return Error::NONE; |
| 667 | } |
| 668 | |
Leon Scroggins III | 2e1aa18 | 2021-12-01 17:33:12 -0500 | [diff] [blame] | 669 | Error AidlComposer::setLayerCompositionType( |
| 670 | Display display, Layer layer, |
| 671 | aidl::android::hardware::graphics::composer3::Composition type) { |
| 672 | mWriter.setLayerCompositionType(translate<int64_t>(display), translate<int64_t>(layer), type); |
Ady Abraham | e7385f7 | 2021-09-05 00:54:25 -0700 | [diff] [blame] | 673 | return Error::NONE; |
| 674 | } |
| 675 | |
| 676 | Error AidlComposer::setLayerDataspace(Display display, Layer layer, Dataspace dataspace) { |
Ady Abraham | a6388c0 | 2021-11-11 21:11:51 -0800 | [diff] [blame] | 677 | mWriter.setLayerDataspace(translate<int64_t>(display), translate<int64_t>(layer), |
| 678 | translate<AidlDataspace>(dataspace)); |
Ady Abraham | e7385f7 | 2021-09-05 00:54:25 -0700 | [diff] [blame] | 679 | return Error::NONE; |
| 680 | } |
| 681 | |
| 682 | Error AidlComposer::setLayerDisplayFrame(Display display, Layer layer, |
| 683 | const IComposerClient::Rect& frame) { |
Ady Abraham | a6388c0 | 2021-11-11 21:11:51 -0800 | [diff] [blame] | 684 | mWriter.setLayerDisplayFrame(translate<int64_t>(display), translate<int64_t>(layer), |
| 685 | translate<AidlRect>(frame)); |
Ady Abraham | e7385f7 | 2021-09-05 00:54:25 -0700 | [diff] [blame] | 686 | return Error::NONE; |
| 687 | } |
| 688 | |
| 689 | Error AidlComposer::setLayerPlaneAlpha(Display display, Layer layer, float alpha) { |
Ady Abraham | a6388c0 | 2021-11-11 21:11:51 -0800 | [diff] [blame] | 690 | mWriter.setLayerPlaneAlpha(translate<int64_t>(display), translate<int64_t>(layer), alpha); |
Ady Abraham | e7385f7 | 2021-09-05 00:54:25 -0700 | [diff] [blame] | 691 | return Error::NONE; |
| 692 | } |
| 693 | |
| 694 | Error AidlComposer::setLayerSidebandStream(Display display, Layer layer, |
| 695 | const native_handle_t* stream) { |
Ady Abraham | a6388c0 | 2021-11-11 21:11:51 -0800 | [diff] [blame] | 696 | mWriter.setLayerSidebandStream(translate<int64_t>(display), translate<int64_t>(layer), stream); |
Ady Abraham | e7385f7 | 2021-09-05 00:54:25 -0700 | [diff] [blame] | 697 | return Error::NONE; |
| 698 | } |
| 699 | |
| 700 | Error AidlComposer::setLayerSourceCrop(Display display, Layer layer, |
| 701 | const IComposerClient::FRect& crop) { |
Ady Abraham | a6388c0 | 2021-11-11 21:11:51 -0800 | [diff] [blame] | 702 | mWriter.setLayerSourceCrop(translate<int64_t>(display), translate<int64_t>(layer), |
| 703 | translate<AidlFRect>(crop)); |
Ady Abraham | e7385f7 | 2021-09-05 00:54:25 -0700 | [diff] [blame] | 704 | return Error::NONE; |
| 705 | } |
| 706 | |
| 707 | Error AidlComposer::setLayerTransform(Display display, Layer layer, Transform transform) { |
Ady Abraham | a6388c0 | 2021-11-11 21:11:51 -0800 | [diff] [blame] | 708 | mWriter.setLayerTransform(translate<int64_t>(display), translate<int64_t>(layer), |
| 709 | translate<AidlTransform>(transform)); |
Ady Abraham | e7385f7 | 2021-09-05 00:54:25 -0700 | [diff] [blame] | 710 | return Error::NONE; |
| 711 | } |
| 712 | |
| 713 | Error AidlComposer::setLayerVisibleRegion(Display display, Layer layer, |
| 714 | const std::vector<IComposerClient::Rect>& visible) { |
Ady Abraham | a6388c0 | 2021-11-11 21:11:51 -0800 | [diff] [blame] | 715 | mWriter.setLayerVisibleRegion(translate<int64_t>(display), translate<int64_t>(layer), |
| 716 | translate<AidlRect>(visible)); |
Ady Abraham | e7385f7 | 2021-09-05 00:54:25 -0700 | [diff] [blame] | 717 | return Error::NONE; |
| 718 | } |
| 719 | |
| 720 | Error AidlComposer::setLayerZOrder(Display display, Layer layer, uint32_t z) { |
Ady Abraham | a6388c0 | 2021-11-11 21:11:51 -0800 | [diff] [blame] | 721 | mWriter.setLayerZOrder(translate<int64_t>(display), translate<int64_t>(layer), z); |
Ady Abraham | e7385f7 | 2021-09-05 00:54:25 -0700 | [diff] [blame] | 722 | return Error::NONE; |
| 723 | } |
| 724 | |
| 725 | Error AidlComposer::execute() { |
Ady Abraham | a6388c0 | 2021-11-11 21:11:51 -0800 | [diff] [blame] | 726 | const auto& commands = mWriter.getPendingCommands(); |
| 727 | if (commands.empty()) { |
Ady Abraham | e7385f7 | 2021-09-05 00:54:25 -0700 | [diff] [blame] | 728 | mWriter.reset(); |
| 729 | return Error::NONE; |
| 730 | } |
| 731 | |
Ady Abraham | de79278 | 2021-12-20 10:00:49 -0800 | [diff] [blame] | 732 | { // scope for results |
| 733 | std::vector<CommandResultPayload> results; |
| 734 | auto status = mAidlComposerClient->executeCommands(commands, &results); |
| 735 | if (!status.isOk()) { |
| 736 | ALOGE("executeCommands failed %s", status.getDescription().c_str()); |
| 737 | return static_cast<Error>(status.getServiceSpecificError()); |
| 738 | } |
Ady Abraham | e7385f7 | 2021-09-05 00:54:25 -0700 | [diff] [blame] | 739 | |
Ady Abraham | de79278 | 2021-12-20 10:00:49 -0800 | [diff] [blame] | 740 | mReader.parse(std::move(results)); |
| 741 | } |
Ady Abraham | a6388c0 | 2021-11-11 21:11:51 -0800 | [diff] [blame] | 742 | const auto commandErrors = mReader.takeErrors(); |
| 743 | Error error = Error::NONE; |
| 744 | for (const auto& cmdErr : commandErrors) { |
| 745 | const auto index = static_cast<size_t>(cmdErr.commandIndex); |
| 746 | if (index < 0 || index >= commands.size()) { |
| 747 | ALOGE("invalid command index %zu", index); |
| 748 | return Error::BAD_PARAMETER; |
Ady Abraham | e7385f7 | 2021-09-05 00:54:25 -0700 | [diff] [blame] | 749 | } |
| 750 | |
Ady Abraham | a6388c0 | 2021-11-11 21:11:51 -0800 | [diff] [blame] | 751 | const auto& command = commands[index]; |
Ady Abraham | 4297736 | 2021-12-07 21:04:49 -0800 | [diff] [blame] | 752 | if (command.validateDisplay || command.presentDisplay || command.presentOrValidateDisplay) { |
| 753 | error = translate<Error>(cmdErr.errorCode); |
| 754 | } else { |
| 755 | ALOGW("command '%s' generated error %" PRId32, command.toString().c_str(), |
| 756 | cmdErr.errorCode); |
Ady Abraham | e7385f7 | 2021-09-05 00:54:25 -0700 | [diff] [blame] | 757 | } |
| 758 | } |
| 759 | |
| 760 | mWriter.reset(); |
| 761 | |
| 762 | return error; |
| 763 | } |
| 764 | |
| 765 | Error AidlComposer::setLayerPerFrameMetadata( |
| 766 | Display display, Layer layer, |
| 767 | const std::vector<IComposerClient::PerFrameMetadata>& perFrameMetadatas) { |
Ady Abraham | a6388c0 | 2021-11-11 21:11:51 -0800 | [diff] [blame] | 768 | mWriter.setLayerPerFrameMetadata(translate<int64_t>(display), translate<int64_t>(layer), |
| 769 | translate<AidlPerFrameMetadata>(perFrameMetadatas)); |
Ady Abraham | e7385f7 | 2021-09-05 00:54:25 -0700 | [diff] [blame] | 770 | return Error::NONE; |
| 771 | } |
| 772 | |
| 773 | std::vector<IComposerClient::PerFrameMetadataKey> AidlComposer::getPerFrameMetadataKeys( |
| 774 | Display display) { |
| 775 | std::vector<AidlPerFrameMetadataKey> keys; |
| 776 | const auto status = |
| 777 | mAidlComposerClient->getPerFrameMetadataKeys(translate<int64_t>(display), &keys); |
| 778 | if (!status.isOk()) { |
| 779 | ALOGE("getPerFrameMetadataKeys failed %s", status.getDescription().c_str()); |
| 780 | return {}; |
| 781 | } |
| 782 | return translate<IComposerClient::PerFrameMetadataKey>(keys); |
| 783 | } |
| 784 | |
| 785 | Error AidlComposer::getRenderIntents(Display display, ColorMode colorMode, |
| 786 | std::vector<RenderIntent>* outRenderIntents) { |
| 787 | std::vector<AidlRenderIntent> renderIntents; |
| 788 | const auto status = mAidlComposerClient->getRenderIntents(translate<int64_t>(display), |
| 789 | translate<AidlColorMode>(colorMode), |
| 790 | &renderIntents); |
| 791 | if (!status.isOk()) { |
| 792 | ALOGE("getRenderIntents failed %s", status.getDescription().c_str()); |
| 793 | return static_cast<Error>(status.getServiceSpecificError()); |
| 794 | } |
| 795 | *outRenderIntents = translate<RenderIntent>(renderIntents); |
| 796 | return Error::NONE; |
| 797 | } |
| 798 | |
| 799 | Error AidlComposer::getDataspaceSaturationMatrix(Dataspace dataspace, mat4* outMatrix) { |
| 800 | std::vector<float> matrix; |
| 801 | const auto status = |
| 802 | mAidlComposerClient->getDataspaceSaturationMatrix(translate<AidlDataspace>(dataspace), |
| 803 | &matrix); |
| 804 | if (!status.isOk()) { |
| 805 | ALOGE("getDataspaceSaturationMatrix failed %s", status.getDescription().c_str()); |
| 806 | return static_cast<Error>(status.getServiceSpecificError()); |
| 807 | } |
| 808 | *outMatrix = makeMat4(matrix); |
| 809 | return Error::NONE; |
| 810 | } |
| 811 | |
| 812 | Error AidlComposer::getDisplayIdentificationData(Display display, uint8_t* outPort, |
| 813 | std::vector<uint8_t>* outData) { |
| 814 | AidlDisplayIdentification displayIdentification; |
| 815 | const auto status = |
| 816 | mAidlComposerClient->getDisplayIdentificationData(translate<int64_t>(display), |
| 817 | &displayIdentification); |
| 818 | if (!status.isOk()) { |
| 819 | ALOGE("getDisplayIdentificationData failed %s", status.getDescription().c_str()); |
| 820 | return static_cast<Error>(status.getServiceSpecificError()); |
| 821 | } |
| 822 | |
| 823 | *outPort = static_cast<uint8_t>(displayIdentification.port); |
| 824 | *outData = displayIdentification.data; |
| 825 | |
| 826 | return Error::NONE; |
| 827 | } |
| 828 | |
| 829 | Error AidlComposer::setLayerColorTransform(Display display, Layer layer, const float* matrix) { |
Ady Abraham | a6388c0 | 2021-11-11 21:11:51 -0800 | [diff] [blame] | 830 | mWriter.setLayerColorTransform(translate<int64_t>(display), translate<int64_t>(layer), matrix); |
Ady Abraham | e7385f7 | 2021-09-05 00:54:25 -0700 | [diff] [blame] | 831 | return Error::NONE; |
| 832 | } |
| 833 | |
| 834 | Error AidlComposer::getDisplayedContentSamplingAttributes(Display display, PixelFormat* outFormat, |
| 835 | Dataspace* outDataspace, |
| 836 | uint8_t* outComponentMask) { |
| 837 | if (!outFormat || !outDataspace || !outComponentMask) { |
| 838 | return Error::BAD_PARAMETER; |
| 839 | } |
| 840 | |
| 841 | AidlDisplayContentSamplingAttributes attributes; |
| 842 | const auto status = |
| 843 | mAidlComposerClient->getDisplayedContentSamplingAttributes(translate<int64_t>(display), |
| 844 | &attributes); |
| 845 | if (!status.isOk()) { |
| 846 | ALOGE("getDisplayedContentSamplingAttributes failed %s", status.getDescription().c_str()); |
| 847 | return static_cast<Error>(status.getServiceSpecificError()); |
| 848 | } |
| 849 | |
| 850 | *outFormat = translate<PixelFormat>(attributes.format); |
| 851 | *outDataspace = translate<Dataspace>(attributes.dataspace); |
| 852 | *outComponentMask = static_cast<uint8_t>(attributes.componentMask); |
| 853 | return Error::NONE; |
| 854 | } |
| 855 | |
| 856 | Error AidlComposer::setDisplayContentSamplingEnabled(Display display, bool enabled, |
| 857 | uint8_t componentMask, uint64_t maxFrames) { |
| 858 | const auto status = |
| 859 | mAidlComposerClient |
| 860 | ->setDisplayedContentSamplingEnabled(translate<int64_t>(display), enabled, |
| 861 | static_cast<AidlFormatColorComponent>( |
| 862 | componentMask), |
| 863 | static_cast<int64_t>(maxFrames)); |
| 864 | if (!status.isOk()) { |
| 865 | ALOGE("setDisplayedContentSamplingEnabled failed %s", status.getDescription().c_str()); |
| 866 | return static_cast<Error>(status.getServiceSpecificError()); |
| 867 | } |
| 868 | return Error::NONE; |
| 869 | } |
| 870 | |
| 871 | Error AidlComposer::getDisplayedContentSample(Display display, uint64_t maxFrames, |
| 872 | uint64_t timestamp, DisplayedFrameStats* outStats) { |
| 873 | if (!outStats) { |
| 874 | return Error::BAD_PARAMETER; |
| 875 | } |
| 876 | |
| 877 | AidlDisplayContentSample sample; |
| 878 | const auto status = |
| 879 | mAidlComposerClient->getDisplayedContentSample(translate<int64_t>(display), |
| 880 | static_cast<int64_t>(maxFrames), |
| 881 | static_cast<int64_t>(timestamp), |
| 882 | &sample); |
| 883 | if (!status.isOk()) { |
| 884 | ALOGE("getDisplayedContentSample failed %s", status.getDescription().c_str()); |
| 885 | return static_cast<Error>(status.getServiceSpecificError()); |
| 886 | } |
| 887 | *outStats = translate<DisplayedFrameStats>(sample); |
| 888 | return Error::NONE; |
| 889 | } |
| 890 | |
| 891 | Error AidlComposer::setLayerPerFrameMetadataBlobs( |
| 892 | Display display, Layer layer, |
| 893 | const std::vector<IComposerClient::PerFrameMetadataBlob>& metadata) { |
Ady Abraham | a6388c0 | 2021-11-11 21:11:51 -0800 | [diff] [blame] | 894 | mWriter.setLayerPerFrameMetadataBlobs(translate<int64_t>(display), translate<int64_t>(layer), |
| 895 | translate<AidlPerFrameMetadataBlob>(metadata)); |
Ady Abraham | e7385f7 | 2021-09-05 00:54:25 -0700 | [diff] [blame] | 896 | return Error::NONE; |
| 897 | } |
| 898 | |
Alec Mouri | cdf1679 | 2021-12-10 13:16:06 -0800 | [diff] [blame] | 899 | Error AidlComposer::setDisplayBrightness(Display display, float brightness, |
| 900 | const DisplayBrightnessOptions& options) { |
Alec Mouri | cdf1679 | 2021-12-10 13:16:06 -0800 | [diff] [blame] | 901 | mWriter.setDisplayBrightness(translate<int64_t>(display), brightness); |
| 902 | |
| 903 | if (options.applyImmediately) { |
| 904 | return execute(); |
| 905 | } |
| 906 | |
Ady Abraham | e7385f7 | 2021-09-05 00:54:25 -0700 | [diff] [blame] | 907 | return Error::NONE; |
| 908 | } |
| 909 | |
| 910 | Error AidlComposer::getDisplayCapabilities(Display display, |
Leon Scroggins III | 5967aec | 2021-12-29 11:14:22 -0500 | [diff] [blame] | 911 | std::vector<AidlDisplayCapability>* outCapabilities) { |
| 912 | const auto status = mAidlComposerClient->getDisplayCapabilities(translate<int64_t>(display), |
| 913 | outCapabilities); |
Ady Abraham | e7385f7 | 2021-09-05 00:54:25 -0700 | [diff] [blame] | 914 | if (!status.isOk()) { |
| 915 | ALOGE("getDisplayCapabilities failed %s", status.getDescription().c_str()); |
Leon Scroggins III | 5967aec | 2021-12-29 11:14:22 -0500 | [diff] [blame] | 916 | outCapabilities->clear(); |
Ady Abraham | e7385f7 | 2021-09-05 00:54:25 -0700 | [diff] [blame] | 917 | return static_cast<Error>(status.getServiceSpecificError()); |
| 918 | } |
Ady Abraham | e7385f7 | 2021-09-05 00:54:25 -0700 | [diff] [blame] | 919 | return Error::NONE; |
| 920 | } |
| 921 | |
| 922 | V2_4::Error AidlComposer::getDisplayConnectionType( |
| 923 | Display display, IComposerClient::DisplayConnectionType* outType) { |
| 924 | AidlDisplayConnectionType type; |
| 925 | const auto status = |
| 926 | mAidlComposerClient->getDisplayConnectionType(translate<int64_t>(display), &type); |
| 927 | if (!status.isOk()) { |
| 928 | ALOGE("getDisplayConnectionType failed %s", status.getDescription().c_str()); |
| 929 | return static_cast<V2_4::Error>(status.getServiceSpecificError()); |
| 930 | } |
| 931 | *outType = translate<IComposerClient::DisplayConnectionType>(type); |
| 932 | return V2_4::Error::NONE; |
| 933 | } |
| 934 | |
| 935 | V2_4::Error AidlComposer::getDisplayVsyncPeriod(Display display, VsyncPeriodNanos* outVsyncPeriod) { |
| 936 | int32_t vsyncPeriod; |
| 937 | const auto status = |
| 938 | mAidlComposerClient->getDisplayVsyncPeriod(translate<int64_t>(display), &vsyncPeriod); |
| 939 | if (!status.isOk()) { |
| 940 | ALOGE("getDisplayVsyncPeriod failed %s", status.getDescription().c_str()); |
| 941 | return static_cast<V2_4::Error>(status.getServiceSpecificError()); |
| 942 | } |
| 943 | *outVsyncPeriod = translate<VsyncPeriodNanos>(vsyncPeriod); |
| 944 | return V2_4::Error::NONE; |
| 945 | } |
| 946 | |
| 947 | V2_4::Error AidlComposer::setActiveConfigWithConstraints( |
| 948 | Display display, Config config, |
| 949 | const IComposerClient::VsyncPeriodChangeConstraints& vsyncPeriodChangeConstraints, |
| 950 | VsyncPeriodChangeTimeline* outTimeline) { |
| 951 | AidlVsyncPeriodChangeTimeline timeline; |
| 952 | const auto status = |
| 953 | mAidlComposerClient |
| 954 | ->setActiveConfigWithConstraints(translate<int64_t>(display), |
| 955 | translate<int32_t>(config), |
| 956 | translate<AidlVsyncPeriodChangeConstraints>( |
| 957 | vsyncPeriodChangeConstraints), |
| 958 | &timeline); |
| 959 | if (!status.isOk()) { |
| 960 | ALOGE("setActiveConfigWithConstraints failed %s", status.getDescription().c_str()); |
| 961 | return static_cast<V2_4::Error>(status.getServiceSpecificError()); |
| 962 | } |
| 963 | *outTimeline = translate<VsyncPeriodChangeTimeline>(timeline); |
| 964 | return V2_4::Error::NONE; |
| 965 | } |
| 966 | |
| 967 | V2_4::Error AidlComposer::setAutoLowLatencyMode(Display display, bool on) { |
| 968 | const auto status = mAidlComposerClient->setAutoLowLatencyMode(translate<int64_t>(display), on); |
| 969 | if (!status.isOk()) { |
| 970 | ALOGE("setAutoLowLatencyMode failed %s", status.getDescription().c_str()); |
| 971 | return static_cast<V2_4::Error>(status.getServiceSpecificError()); |
| 972 | } |
| 973 | return V2_4::Error::NONE; |
| 974 | } |
| 975 | |
| 976 | V2_4::Error AidlComposer::getSupportedContentTypes( |
| 977 | Display displayId, std::vector<IComposerClient::ContentType>* outSupportedContentTypes) { |
| 978 | std::vector<AidlContentType> types; |
| 979 | const auto status = |
| 980 | mAidlComposerClient->getSupportedContentTypes(translate<int64_t>(displayId), &types); |
| 981 | if (!status.isOk()) { |
| 982 | ALOGE("getSupportedContentTypes failed %s", status.getDescription().c_str()); |
| 983 | return static_cast<V2_4::Error>(status.getServiceSpecificError()); |
| 984 | } |
| 985 | *outSupportedContentTypes = translate<IComposerClient::ContentType>(types); |
| 986 | return V2_4::Error::NONE; |
| 987 | } |
| 988 | |
| 989 | V2_4::Error AidlComposer::setContentType(Display display, |
| 990 | IComposerClient::ContentType contentType) { |
| 991 | const auto status = |
| 992 | mAidlComposerClient->setContentType(translate<int64_t>(display), |
| 993 | translate<AidlContentType>(contentType)); |
| 994 | if (!status.isOk()) { |
| 995 | ALOGE("setContentType failed %s", status.getDescription().c_str()); |
| 996 | return static_cast<V2_4::Error>(status.getServiceSpecificError()); |
| 997 | } |
| 998 | return V2_4::Error::NONE; |
| 999 | } |
| 1000 | |
Ady Abraham | 3f97675 | 2021-12-20 16:17:50 -0800 | [diff] [blame] | 1001 | V2_4::Error AidlComposer::setLayerGenericMetadata(Display, Layer, const std::string&, bool, |
| 1002 | const std::vector<uint8_t>&) { |
| 1003 | // There are no users for this API. See b/209691612. |
| 1004 | return V2_4::Error::UNSUPPORTED; |
Ady Abraham | e7385f7 | 2021-09-05 00:54:25 -0700 | [diff] [blame] | 1005 | } |
| 1006 | |
| 1007 | V2_4::Error AidlComposer::getLayerGenericMetadataKeys( |
Ady Abraham | 3f97675 | 2021-12-20 16:17:50 -0800 | [diff] [blame] | 1008 | std::vector<IComposerClient::LayerGenericMetadataKey>*) { |
| 1009 | // There are no users for this API. See b/209691612. |
| 1010 | return V2_4::Error::UNSUPPORTED; |
Ady Abraham | e7385f7 | 2021-09-05 00:54:25 -0700 | [diff] [blame] | 1011 | } |
| 1012 | |
Kriti Dang | 7defaf3 | 2021-11-15 11:55:43 +0100 | [diff] [blame] | 1013 | Error AidlComposer::setBootDisplayConfig(Display display, Config config) { |
| 1014 | const auto status = mAidlComposerClient->setBootDisplayConfig(translate<int64_t>(display), |
| 1015 | translate<int32_t>(config)); |
| 1016 | if (!status.isOk()) { |
| 1017 | ALOGE("setBootDisplayConfig failed %s", status.getDescription().c_str()); |
| 1018 | return static_cast<Error>(status.getServiceSpecificError()); |
| 1019 | } |
| 1020 | return Error::NONE; |
| 1021 | } |
| 1022 | |
| 1023 | Error AidlComposer::clearBootDisplayConfig(Display display) { |
| 1024 | const auto status = mAidlComposerClient->clearBootDisplayConfig(translate<int64_t>(display)); |
| 1025 | if (!status.isOk()) { |
| 1026 | ALOGE("clearBootDisplayConfig failed %s", status.getDescription().c_str()); |
| 1027 | return static_cast<Error>(status.getServiceSpecificError()); |
| 1028 | } |
| 1029 | return Error::NONE; |
| 1030 | } |
| 1031 | |
| 1032 | Error AidlComposer::getPreferredBootDisplayConfig(Display display, Config* config) { |
| 1033 | int32_t displayConfig; |
| 1034 | const auto status = |
| 1035 | mAidlComposerClient->getPreferredBootDisplayConfig(translate<int64_t>(display), |
| 1036 | &displayConfig); |
| 1037 | if (!status.isOk()) { |
| 1038 | ALOGE("getPreferredBootDisplayConfig failed %s", status.getDescription().c_str()); |
| 1039 | return static_cast<Error>(status.getServiceSpecificError()); |
| 1040 | } |
| 1041 | *config = translate<uint32_t>(displayConfig); |
| 1042 | return Error::NONE; |
| 1043 | } |
| 1044 | |
Ady Abraham | e7385f7 | 2021-09-05 00:54:25 -0700 | [diff] [blame] | 1045 | Error AidlComposer::getClientTargetProperty( |
Alec Mouri | cdf6cbc | 2021-11-01 17:21:15 -0700 | [diff] [blame] | 1046 | Display display, IComposerClient::ClientTargetProperty* outClientTargetProperty, |
| 1047 | float* whitePointNits) { |
Ady Abraham | de79278 | 2021-12-20 10:00:49 -0800 | [diff] [blame] | 1048 | const auto property = mReader.takeClientTargetProperty(translate<int64_t>(display)); |
| 1049 | *outClientTargetProperty = |
| 1050 | translate<IComposerClient::ClientTargetProperty>(property.clientTargetProperty); |
| 1051 | *whitePointNits = property.whitePointNits; |
Ady Abraham | e7385f7 | 2021-09-05 00:54:25 -0700 | [diff] [blame] | 1052 | return Error::NONE; |
| 1053 | } |
| 1054 | |
Alec Mouri | cdf6cbc | 2021-11-01 17:21:15 -0700 | [diff] [blame] | 1055 | Error AidlComposer::setLayerWhitePointNits(Display display, Layer layer, float whitePointNits) { |
| 1056 | mWriter.setLayerWhitePointNits(translate<int64_t>(display), translate<int64_t>(layer), |
| 1057 | whitePointNits); |
| 1058 | return Error::NONE; |
| 1059 | } |
| 1060 | |
Leon Scroggins III | d77d316 | 2022-01-05 10:42:28 -0500 | [diff] [blame] | 1061 | Error AidlComposer::setLayerBlockingRegion(Display display, Layer layer, |
| 1062 | const std::vector<IComposerClient::Rect>& blocking) { |
| 1063 | mWriter.setLayerBlockingRegion(translate<int64_t>(display), translate<int64_t>(layer), |
| 1064 | translate<AidlRect>(blocking)); |
| 1065 | return Error::NONE; |
| 1066 | } |
Ady Abraham | e7385f7 | 2021-09-05 00:54:25 -0700 | [diff] [blame] | 1067 | } // namespace Hwc2 |
| 1068 | } // namespace android |