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: |
Ady Abraham | 4d211cf | 2021-12-14 16:19:03 -0800 | [diff] [blame] | 240 | return true; |
| 241 | } |
| 242 | } |
| 243 | |
Ady Abraham | e7385f7 | 2021-09-05 00:54:25 -0700 | [diff] [blame] | 244 | std::vector<IComposer::Capability> AidlComposer::getCapabilities() { |
| 245 | std::vector<Capability> capabilities; |
| 246 | const auto status = mAidlComposer->getCapabilities(&capabilities); |
| 247 | if (!status.isOk()) { |
| 248 | ALOGE("getCapabilities failed %s", status.getDescription().c_str()); |
| 249 | return {}; |
| 250 | } |
| 251 | return translate<IComposer::Capability>(capabilities); |
| 252 | } |
| 253 | |
| 254 | std::string AidlComposer::dumpDebugInfo() { |
| 255 | std::string info; |
| 256 | const auto status = mAidlComposer->dumpDebugInfo(&info); |
| 257 | if (!status.isOk()) { |
| 258 | ALOGE("dumpDebugInfo failed %s", status.getDescription().c_str()); |
| 259 | return {}; |
| 260 | } |
| 261 | return info; |
| 262 | } |
| 263 | |
| 264 | void AidlComposer::registerCallback(const sp<IComposerCallback>& callback) { |
| 265 | if (mAidlComposerCallback) { |
| 266 | ALOGE("Callback already registered"); |
| 267 | } |
Ady Abraham | 9fc2805 | 2021-10-14 17:21:38 -0700 | [diff] [blame] | 268 | mAidlComposerCallback = ndk::SharedRefBase::make<AidlIComposerCallbackWrapper>(callback); |
Ady Abraham | e7385f7 | 2021-09-05 00:54:25 -0700 | [diff] [blame] | 269 | AIBinder_setMinSchedulerPolicy(mAidlComposerCallback->asBinder().get(), SCHED_FIFO, 2); |
| 270 | |
| 271 | const auto status = mAidlComposerClient->registerCallback(mAidlComposerCallback); |
| 272 | if (!status.isOk()) { |
| 273 | ALOGE("registerCallback failed %s", status.getDescription().c_str()); |
| 274 | } |
| 275 | } |
| 276 | |
| 277 | void AidlComposer::resetCommands() { |
| 278 | mWriter.reset(); |
| 279 | } |
| 280 | |
| 281 | Error AidlComposer::executeCommands() { |
| 282 | return execute(); |
| 283 | } |
| 284 | |
| 285 | uint32_t AidlComposer::getMaxVirtualDisplayCount() { |
| 286 | int32_t count = 0; |
| 287 | const auto status = mAidlComposerClient->getMaxVirtualDisplayCount(&count); |
| 288 | if (!status.isOk()) { |
| 289 | ALOGE("getMaxVirtualDisplayCount failed %s", status.getDescription().c_str()); |
| 290 | return 0; |
| 291 | } |
| 292 | return static_cast<uint32_t>(count); |
| 293 | } |
| 294 | |
| 295 | Error AidlComposer::createVirtualDisplay(uint32_t width, uint32_t height, PixelFormat* format, |
| 296 | Display* outDisplay) { |
| 297 | using AidlPixelFormat = aidl::android::hardware::graphics::common::PixelFormat; |
| 298 | const int32_t bufferSlotCount = 1; |
| 299 | VirtualDisplay virtualDisplay; |
| 300 | const auto status = |
| 301 | mAidlComposerClient->createVirtualDisplay(static_cast<int32_t>(width), |
| 302 | static_cast<int32_t>(height), |
| 303 | static_cast<AidlPixelFormat>(*format), |
| 304 | bufferSlotCount, &virtualDisplay); |
| 305 | |
| 306 | if (!status.isOk()) { |
| 307 | ALOGE("createVirtualDisplay failed %s", status.getDescription().c_str()); |
| 308 | return static_cast<Error>(status.getServiceSpecificError()); |
| 309 | } |
| 310 | |
| 311 | *outDisplay = translate<Display>(virtualDisplay.display); |
| 312 | *format = static_cast<PixelFormat>(virtualDisplay.format); |
| 313 | return Error::NONE; |
| 314 | } |
| 315 | |
| 316 | Error AidlComposer::destroyVirtualDisplay(Display display) { |
| 317 | const auto status = mAidlComposerClient->destroyVirtualDisplay(translate<int64_t>(display)); |
| 318 | if (!status.isOk()) { |
| 319 | ALOGE("destroyVirtualDisplay failed %s", status.getDescription().c_str()); |
| 320 | return static_cast<Error>(status.getServiceSpecificError()); |
| 321 | } |
| 322 | return Error::NONE; |
| 323 | } |
| 324 | |
| 325 | Error AidlComposer::acceptDisplayChanges(Display display) { |
Ady Abraham | a6388c0 | 2021-11-11 21:11:51 -0800 | [diff] [blame] | 326 | mWriter.acceptDisplayChanges(translate<int64_t>(display)); |
Ady Abraham | e7385f7 | 2021-09-05 00:54:25 -0700 | [diff] [blame] | 327 | return Error::NONE; |
| 328 | } |
| 329 | |
| 330 | Error AidlComposer::createLayer(Display display, Layer* outLayer) { |
| 331 | int64_t layer; |
| 332 | const auto status = mAidlComposerClient->createLayer(translate<int64_t>(display), |
| 333 | kMaxLayerBufferCount, &layer); |
| 334 | if (!status.isOk()) { |
| 335 | ALOGE("createLayer failed %s", status.getDescription().c_str()); |
| 336 | return static_cast<Error>(status.getServiceSpecificError()); |
| 337 | } |
| 338 | |
| 339 | *outLayer = translate<Layer>(layer); |
| 340 | return Error::NONE; |
| 341 | } |
| 342 | |
| 343 | Error AidlComposer::destroyLayer(Display display, Layer layer) { |
| 344 | const auto status = mAidlComposerClient->destroyLayer(translate<int64_t>(display), |
| 345 | translate<int64_t>(layer)); |
| 346 | if (!status.isOk()) { |
| 347 | ALOGE("destroyLayer failed %s", status.getDescription().c_str()); |
| 348 | return static_cast<Error>(status.getServiceSpecificError()); |
| 349 | } |
| 350 | return Error::NONE; |
| 351 | } |
| 352 | |
| 353 | Error AidlComposer::getActiveConfig(Display display, Config* outConfig) { |
| 354 | int32_t config; |
| 355 | const auto status = mAidlComposerClient->getActiveConfig(translate<int64_t>(display), &config); |
| 356 | if (!status.isOk()) { |
| 357 | ALOGE("getActiveConfig failed %s", status.getDescription().c_str()); |
| 358 | return static_cast<Error>(status.getServiceSpecificError()); |
| 359 | } |
| 360 | *outConfig = translate<Config>(config); |
| 361 | return Error::NONE; |
| 362 | } |
| 363 | |
| 364 | Error AidlComposer::getChangedCompositionTypes( |
| 365 | Display display, std::vector<Layer>* outLayers, |
Leon Scroggins III | 2e1aa18 | 2021-12-01 17:33:12 -0500 | [diff] [blame] | 366 | std::vector<aidl::android::hardware::graphics::composer3::Composition>* outTypes) { |
Ady Abraham | de79278 | 2021-12-20 10:00:49 -0800 | [diff] [blame] | 367 | const auto changedLayers = mReader.takeChangedCompositionTypes(translate<int64_t>(display)); |
| 368 | outLayers->reserve(changedLayers.size()); |
| 369 | outTypes->reserve(changedLayers.size()); |
Ady Abraham | a6388c0 | 2021-11-11 21:11:51 -0800 | [diff] [blame] | 370 | |
Ady Abraham | de79278 | 2021-12-20 10:00:49 -0800 | [diff] [blame] | 371 | for (const auto& layer : changedLayers) { |
| 372 | outLayers->emplace_back(translate<Layer>(layer.layer)); |
| 373 | outTypes->emplace_back(layer.composition); |
| 374 | } |
Ady Abraham | e7385f7 | 2021-09-05 00:54:25 -0700 | [diff] [blame] | 375 | return Error::NONE; |
| 376 | } |
| 377 | |
| 378 | Error AidlComposer::getColorModes(Display display, std::vector<ColorMode>* outModes) { |
| 379 | std::vector<AidlColorMode> modes; |
| 380 | const auto status = mAidlComposerClient->getColorModes(translate<int64_t>(display), &modes); |
| 381 | if (!status.isOk()) { |
| 382 | ALOGE("getColorModes failed %s", status.getDescription().c_str()); |
| 383 | return static_cast<Error>(status.getServiceSpecificError()); |
| 384 | } |
| 385 | *outModes = translate<ColorMode>(modes); |
| 386 | return Error::NONE; |
| 387 | } |
| 388 | |
| 389 | Error AidlComposer::getDisplayAttribute(Display display, Config config, |
| 390 | IComposerClient::Attribute attribute, int32_t* outValue) { |
| 391 | const auto status = |
| 392 | mAidlComposerClient->getDisplayAttribute(translate<int64_t>(display), |
| 393 | translate<int32_t>(config), |
| 394 | static_cast<AidlDisplayAttribute>(attribute), |
| 395 | outValue); |
| 396 | if (!status.isOk()) { |
| 397 | ALOGE("getDisplayAttribute failed %s", status.getDescription().c_str()); |
| 398 | return static_cast<Error>(status.getServiceSpecificError()); |
| 399 | } |
| 400 | return Error::NONE; |
| 401 | } |
| 402 | |
| 403 | Error AidlComposer::getDisplayConfigs(Display display, std::vector<Config>* outConfigs) { |
| 404 | std::vector<int32_t> configs; |
| 405 | const auto status = |
| 406 | mAidlComposerClient->getDisplayConfigs(translate<int64_t>(display), &configs); |
| 407 | if (!status.isOk()) { |
| 408 | ALOGE("getDisplayConfigs failed %s", status.getDescription().c_str()); |
| 409 | return static_cast<Error>(status.getServiceSpecificError()); |
| 410 | } |
| 411 | *outConfigs = translate<Config>(configs); |
| 412 | return Error::NONE; |
| 413 | } |
| 414 | |
| 415 | Error AidlComposer::getDisplayName(Display display, std::string* outName) { |
| 416 | const auto status = mAidlComposerClient->getDisplayName(translate<int64_t>(display), outName); |
| 417 | if (!status.isOk()) { |
| 418 | ALOGE("getDisplayName failed %s", status.getDescription().c_str()); |
| 419 | return static_cast<Error>(status.getServiceSpecificError()); |
| 420 | } |
| 421 | return Error::NONE; |
| 422 | } |
| 423 | |
| 424 | Error AidlComposer::getDisplayRequests(Display display, uint32_t* outDisplayRequestMask, |
| 425 | std::vector<Layer>* outLayers, |
| 426 | std::vector<uint32_t>* outLayerRequestMasks) { |
Ady Abraham | de79278 | 2021-12-20 10:00:49 -0800 | [diff] [blame] | 427 | const auto displayRequests = mReader.takeDisplayRequests(translate<int64_t>(display)); |
| 428 | *outDisplayRequestMask = translate<uint32_t>(displayRequests.mask); |
| 429 | outLayers->reserve(displayRequests.layerRequests.size()); |
| 430 | outLayerRequestMasks->reserve(displayRequests.layerRequests.size()); |
| 431 | |
| 432 | for (const auto& layer : displayRequests.layerRequests) { |
| 433 | outLayers->emplace_back(translate<Layer>(layer.layer)); |
| 434 | outLayerRequestMasks->emplace_back(translate<uint32_t>(layer.mask)); |
| 435 | } |
Ady Abraham | e7385f7 | 2021-09-05 00:54:25 -0700 | [diff] [blame] | 436 | return Error::NONE; |
| 437 | } |
| 438 | |
| 439 | Error AidlComposer::getDozeSupport(Display display, bool* outSupport) { |
Ady Abraham | 33b92b9 | 2021-12-08 18:30:27 -0800 | [diff] [blame] | 440 | std::vector<AidlDisplayCapability> capabilities; |
Ady Abraham | e7385f7 | 2021-09-05 00:54:25 -0700 | [diff] [blame] | 441 | const auto status = |
Ady Abraham | 33b92b9 | 2021-12-08 18:30:27 -0800 | [diff] [blame] | 442 | mAidlComposerClient->getDisplayCapabilities(translate<int64_t>(display), &capabilities); |
Ady Abraham | e7385f7 | 2021-09-05 00:54:25 -0700 | [diff] [blame] | 443 | if (!status.isOk()) { |
Ady Abraham | 33b92b9 | 2021-12-08 18:30:27 -0800 | [diff] [blame] | 444 | ALOGE("getDisplayCapabilities failed %s", status.getDescription().c_str()); |
Ady Abraham | e7385f7 | 2021-09-05 00:54:25 -0700 | [diff] [blame] | 445 | return static_cast<Error>(status.getServiceSpecificError()); |
| 446 | } |
Ady Abraham | 33b92b9 | 2021-12-08 18:30:27 -0800 | [diff] [blame] | 447 | *outSupport = std::find(capabilities.begin(), capabilities.end(), |
| 448 | AidlDisplayCapability::DOZE) != capabilities.end(); |
Ady Abraham | e7385f7 | 2021-09-05 00:54:25 -0700 | [diff] [blame] | 449 | return Error::NONE; |
| 450 | } |
| 451 | |
| 452 | Error AidlComposer::getHdrCapabilities(Display display, std::vector<Hdr>* outTypes, |
| 453 | float* outMaxLuminance, float* outMaxAverageLuminance, |
| 454 | float* outMinLuminance) { |
| 455 | AidlHdrCapabilities capabilities; |
| 456 | const auto status = |
| 457 | mAidlComposerClient->getHdrCapabilities(translate<int64_t>(display), &capabilities); |
| 458 | if (!status.isOk()) { |
| 459 | ALOGE("getHdrCapabilities failed %s", status.getDescription().c_str()); |
| 460 | return static_cast<Error>(status.getServiceSpecificError()); |
| 461 | } |
| 462 | |
| 463 | *outTypes = translate<Hdr>(capabilities.types); |
| 464 | *outMaxLuminance = capabilities.maxLuminance; |
| 465 | *outMaxAverageLuminance = capabilities.maxAverageLuminance; |
| 466 | *outMinLuminance = capabilities.minLuminance; |
| 467 | return Error::NONE; |
| 468 | } |
| 469 | |
| 470 | Error AidlComposer::getReleaseFences(Display display, std::vector<Layer>* outLayers, |
| 471 | std::vector<int>* outReleaseFences) { |
Ady Abraham | de79278 | 2021-12-20 10:00:49 -0800 | [diff] [blame] | 472 | auto fences = mReader.takeReleaseFences(translate<int64_t>(display)); |
| 473 | outLayers->reserve(fences.size()); |
| 474 | outReleaseFences->reserve(fences.size()); |
| 475 | |
| 476 | for (auto& fence : fences) { |
| 477 | outLayers->emplace_back(translate<Layer>(fence.layer)); |
| 478 | // take ownership |
| 479 | const int fenceOwner = fence.fence.get(); |
| 480 | *fence.fence.getR() = -1; |
| 481 | outReleaseFences->emplace_back(fenceOwner); |
| 482 | } |
Ady Abraham | e7385f7 | 2021-09-05 00:54:25 -0700 | [diff] [blame] | 483 | return Error::NONE; |
| 484 | } |
| 485 | |
| 486 | Error AidlComposer::presentDisplay(Display display, int* outPresentFence) { |
| 487 | ATRACE_NAME("HwcPresentDisplay"); |
Ady Abraham | a6388c0 | 2021-11-11 21:11:51 -0800 | [diff] [blame] | 488 | mWriter.presentDisplay(translate<int64_t>(display)); |
Ady Abraham | e7385f7 | 2021-09-05 00:54:25 -0700 | [diff] [blame] | 489 | |
| 490 | Error error = execute(); |
| 491 | if (error != Error::NONE) { |
| 492 | return error; |
| 493 | } |
| 494 | |
Ady Abraham | de79278 | 2021-12-20 10:00:49 -0800 | [diff] [blame] | 495 | auto fence = mReader.takePresentFence(translate<int64_t>(display)); |
| 496 | // take ownership |
| 497 | *outPresentFence = fence.get(); |
| 498 | *fence.getR() = -1; |
Ady Abraham | e7385f7 | 2021-09-05 00:54:25 -0700 | [diff] [blame] | 499 | return Error::NONE; |
| 500 | } |
| 501 | |
| 502 | Error AidlComposer::setActiveConfig(Display display, Config config) { |
| 503 | const auto status = mAidlComposerClient->setActiveConfig(translate<int64_t>(display), |
| 504 | translate<int32_t>(config)); |
| 505 | if (!status.isOk()) { |
| 506 | ALOGE("setActiveConfig failed %s", status.getDescription().c_str()); |
| 507 | return static_cast<Error>(status.getServiceSpecificError()); |
| 508 | } |
| 509 | return Error::NONE; |
| 510 | } |
| 511 | |
| 512 | Error AidlComposer::setClientTarget(Display display, uint32_t slot, const sp<GraphicBuffer>& target, |
| 513 | int acquireFence, Dataspace dataspace, |
| 514 | const std::vector<IComposerClient::Rect>& damage) { |
Ady Abraham | e7385f7 | 2021-09-05 00:54:25 -0700 | [diff] [blame] | 515 | const native_handle_t* handle = nullptr; |
| 516 | if (target.get()) { |
| 517 | handle = target->getNativeBuffer()->handle; |
| 518 | } |
| 519 | |
Ady Abraham | a6388c0 | 2021-11-11 21:11:51 -0800 | [diff] [blame] | 520 | mWriter.setClientTarget(translate<int64_t>(display), slot, handle, acquireFence, |
Ady Abraham | e7385f7 | 2021-09-05 00:54:25 -0700 | [diff] [blame] | 521 | translate<aidl::android::hardware::graphics::common::Dataspace>( |
| 522 | dataspace), |
| 523 | translate<AidlRect>(damage)); |
| 524 | return Error::NONE; |
| 525 | } |
| 526 | |
| 527 | Error AidlComposer::setColorMode(Display display, ColorMode mode, RenderIntent renderIntent) { |
| 528 | const auto status = |
| 529 | mAidlComposerClient->setColorMode(translate<int64_t>(display), |
| 530 | translate<AidlColorMode>(mode), |
| 531 | translate<AidlRenderIntent>(renderIntent)); |
| 532 | if (!status.isOk()) { |
| 533 | ALOGE("setColorMode failed %s", status.getDescription().c_str()); |
| 534 | return static_cast<Error>(status.getServiceSpecificError()); |
| 535 | } |
| 536 | return Error::NONE; |
| 537 | } |
| 538 | |
Ady Abraham | dc011a9 | 2021-12-21 14:06:44 -0800 | [diff] [blame] | 539 | Error AidlComposer::setColorTransform(Display display, const float* matrix) { |
| 540 | mWriter.setColorTransform(translate<int64_t>(display), matrix); |
Ady Abraham | e7385f7 | 2021-09-05 00:54:25 -0700 | [diff] [blame] | 541 | return Error::NONE; |
| 542 | } |
| 543 | |
| 544 | Error AidlComposer::setOutputBuffer(Display display, const native_handle_t* buffer, |
| 545 | int releaseFence) { |
Ady Abraham | a6388c0 | 2021-11-11 21:11:51 -0800 | [diff] [blame] | 546 | mWriter.setOutputBuffer(translate<int64_t>(display), 0, buffer, dup(releaseFence)); |
Ady Abraham | e7385f7 | 2021-09-05 00:54:25 -0700 | [diff] [blame] | 547 | return Error::NONE; |
| 548 | } |
| 549 | |
| 550 | Error AidlComposer::setPowerMode(Display display, IComposerClient::PowerMode mode) { |
| 551 | const auto status = mAidlComposerClient->setPowerMode(translate<int64_t>(display), |
| 552 | translate<PowerMode>(mode)); |
| 553 | if (!status.isOk()) { |
| 554 | ALOGE("setPowerMode failed %s", status.getDescription().c_str()); |
| 555 | return static_cast<Error>(status.getServiceSpecificError()); |
| 556 | } |
| 557 | return Error::NONE; |
| 558 | } |
| 559 | |
| 560 | Error AidlComposer::setVsyncEnabled(Display display, IComposerClient::Vsync enabled) { |
| 561 | const bool enableVsync = enabled == IComposerClient::Vsync::ENABLE; |
| 562 | const auto status = |
| 563 | mAidlComposerClient->setVsyncEnabled(translate<int64_t>(display), enableVsync); |
| 564 | if (!status.isOk()) { |
| 565 | ALOGE("setVsyncEnabled failed %s", status.getDescription().c_str()); |
| 566 | return static_cast<Error>(status.getServiceSpecificError()); |
| 567 | } |
| 568 | return Error::NONE; |
| 569 | } |
| 570 | |
| 571 | Error AidlComposer::setClientTargetSlotCount(Display display) { |
| 572 | const int32_t bufferSlotCount = BufferQueue::NUM_BUFFER_SLOTS; |
| 573 | const auto status = mAidlComposerClient->setClientTargetSlotCount(translate<int64_t>(display), |
| 574 | bufferSlotCount); |
| 575 | if (!status.isOk()) { |
| 576 | ALOGE("setClientTargetSlotCount failed %s", status.getDescription().c_str()); |
| 577 | return static_cast<Error>(status.getServiceSpecificError()); |
| 578 | } |
| 579 | return Error::NONE; |
| 580 | } |
| 581 | |
Ady Abraham | 43065bd | 2021-12-10 17:22:15 -0800 | [diff] [blame] | 582 | Error AidlComposer::validateDisplay(Display display, nsecs_t expectedPresentTime, |
| 583 | uint32_t* outNumTypes, uint32_t* outNumRequests) { |
Ady Abraham | e7385f7 | 2021-09-05 00:54:25 -0700 | [diff] [blame] | 584 | ATRACE_NAME("HwcValidateDisplay"); |
Ady Abraham | 43065bd | 2021-12-10 17:22:15 -0800 | [diff] [blame] | 585 | mWriter.validateDisplay(translate<int64_t>(display), |
| 586 | ClockMonotonicTimestamp{expectedPresentTime}); |
Ady Abraham | e7385f7 | 2021-09-05 00:54:25 -0700 | [diff] [blame] | 587 | |
| 588 | Error error = execute(); |
| 589 | if (error != Error::NONE) { |
| 590 | return error; |
| 591 | } |
| 592 | |
Ady Abraham | a6388c0 | 2021-11-11 21:11:51 -0800 | [diff] [blame] | 593 | mReader.hasChanges(translate<int64_t>(display), outNumTypes, outNumRequests); |
Ady Abraham | e7385f7 | 2021-09-05 00:54:25 -0700 | [diff] [blame] | 594 | |
| 595 | return Error::NONE; |
| 596 | } |
| 597 | |
Ady Abraham | 43065bd | 2021-12-10 17:22:15 -0800 | [diff] [blame] | 598 | Error AidlComposer::presentOrValidateDisplay(Display display, nsecs_t expectedPresentTime, |
| 599 | uint32_t* outNumTypes, uint32_t* outNumRequests, |
| 600 | int* outPresentFence, uint32_t* state) { |
Ady Abraham | e7385f7 | 2021-09-05 00:54:25 -0700 | [diff] [blame] | 601 | ATRACE_NAME("HwcPresentOrValidateDisplay"); |
Ady Abraham | 43065bd | 2021-12-10 17:22:15 -0800 | [diff] [blame] | 602 | mWriter.presentOrvalidateDisplay(translate<int64_t>(display), |
| 603 | ClockMonotonicTimestamp{expectedPresentTime}); |
Ady Abraham | e7385f7 | 2021-09-05 00:54:25 -0700 | [diff] [blame] | 604 | |
| 605 | Error error = execute(); |
| 606 | if (error != Error::NONE) { |
| 607 | return error; |
| 608 | } |
| 609 | |
Ady Abraham | de79278 | 2021-12-20 10:00:49 -0800 | [diff] [blame] | 610 | const auto result = mReader.takePresentOrValidateStage(translate<int64_t>(display)); |
| 611 | if (!result.has_value()) { |
| 612 | *state = translate<uint32_t>(-1); |
| 613 | return Error::NO_RESOURCES; |
Ady Abraham | e7385f7 | 2021-09-05 00:54:25 -0700 | [diff] [blame] | 614 | } |
| 615 | |
Ady Abraham | de79278 | 2021-12-20 10:00:49 -0800 | [diff] [blame] | 616 | *state = translate<uint32_t>(*result); |
| 617 | |
| 618 | if (*result == PresentOrValidate::Result::Presented) { |
| 619 | auto fence = mReader.takePresentFence(translate<int64_t>(display)); |
| 620 | // take ownership |
| 621 | *outPresentFence = fence.get(); |
| 622 | *fence.getR() = -1; |
| 623 | } |
| 624 | |
| 625 | if (*result == PresentOrValidate::Result::Validated) { |
Ady Abraham | a6388c0 | 2021-11-11 21:11:51 -0800 | [diff] [blame] | 626 | mReader.hasChanges(translate<int64_t>(display), outNumTypes, outNumRequests); |
Ady Abraham | e7385f7 | 2021-09-05 00:54:25 -0700 | [diff] [blame] | 627 | } |
| 628 | |
| 629 | return Error::NONE; |
| 630 | } |
| 631 | |
| 632 | 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] | 633 | mWriter.setLayerCursorPosition(translate<int64_t>(display), translate<int64_t>(layer), x, y); |
Ady Abraham | e7385f7 | 2021-09-05 00:54:25 -0700 | [diff] [blame] | 634 | return Error::NONE; |
| 635 | } |
| 636 | |
| 637 | Error AidlComposer::setLayerBuffer(Display display, Layer layer, uint32_t slot, |
| 638 | const sp<GraphicBuffer>& buffer, int acquireFence) { |
Ady Abraham | e7385f7 | 2021-09-05 00:54:25 -0700 | [diff] [blame] | 639 | const native_handle_t* handle = nullptr; |
| 640 | if (buffer.get()) { |
| 641 | handle = buffer->getNativeBuffer()->handle; |
| 642 | } |
| 643 | |
Ady Abraham | a6388c0 | 2021-11-11 21:11:51 -0800 | [diff] [blame] | 644 | mWriter.setLayerBuffer(translate<int64_t>(display), translate<int64_t>(layer), slot, handle, |
| 645 | acquireFence); |
Ady Abraham | e7385f7 | 2021-09-05 00:54:25 -0700 | [diff] [blame] | 646 | return Error::NONE; |
| 647 | } |
| 648 | |
| 649 | Error AidlComposer::setLayerSurfaceDamage(Display display, Layer layer, |
| 650 | const std::vector<IComposerClient::Rect>& damage) { |
Ady Abraham | a6388c0 | 2021-11-11 21:11:51 -0800 | [diff] [blame] | 651 | mWriter.setLayerSurfaceDamage(translate<int64_t>(display), translate<int64_t>(layer), |
| 652 | translate<AidlRect>(damage)); |
Ady Abraham | e7385f7 | 2021-09-05 00:54:25 -0700 | [diff] [blame] | 653 | return Error::NONE; |
| 654 | } |
| 655 | |
| 656 | Error AidlComposer::setLayerBlendMode(Display display, Layer layer, |
| 657 | IComposerClient::BlendMode mode) { |
Ady Abraham | a6388c0 | 2021-11-11 21:11:51 -0800 | [diff] [blame] | 658 | mWriter.setLayerBlendMode(translate<int64_t>(display), translate<int64_t>(layer), |
| 659 | translate<BlendMode>(mode)); |
Ady Abraham | e7385f7 | 2021-09-05 00:54:25 -0700 | [diff] [blame] | 660 | return Error::NONE; |
| 661 | } |
| 662 | |
Ady Abraham | 6e60b14 | 2022-01-06 18:10:35 -0800 | [diff] [blame] | 663 | Error AidlComposer::setLayerColor(Display display, Layer layer, const Color& color) { |
| 664 | mWriter.setLayerColor(translate<int64_t>(display), translate<int64_t>(layer), color); |
Ady Abraham | e7385f7 | 2021-09-05 00:54:25 -0700 | [diff] [blame] | 665 | return Error::NONE; |
| 666 | } |
| 667 | |
Leon Scroggins III | 2e1aa18 | 2021-12-01 17:33:12 -0500 | [diff] [blame] | 668 | Error AidlComposer::setLayerCompositionType( |
| 669 | Display display, Layer layer, |
| 670 | aidl::android::hardware::graphics::composer3::Composition type) { |
| 671 | mWriter.setLayerCompositionType(translate<int64_t>(display), translate<int64_t>(layer), type); |
Ady Abraham | e7385f7 | 2021-09-05 00:54:25 -0700 | [diff] [blame] | 672 | return Error::NONE; |
| 673 | } |
| 674 | |
| 675 | Error AidlComposer::setLayerDataspace(Display display, Layer layer, Dataspace dataspace) { |
Ady Abraham | a6388c0 | 2021-11-11 21:11:51 -0800 | [diff] [blame] | 676 | mWriter.setLayerDataspace(translate<int64_t>(display), translate<int64_t>(layer), |
| 677 | translate<AidlDataspace>(dataspace)); |
Ady Abraham | e7385f7 | 2021-09-05 00:54:25 -0700 | [diff] [blame] | 678 | return Error::NONE; |
| 679 | } |
| 680 | |
| 681 | Error AidlComposer::setLayerDisplayFrame(Display display, Layer layer, |
| 682 | const IComposerClient::Rect& frame) { |
Ady Abraham | a6388c0 | 2021-11-11 21:11:51 -0800 | [diff] [blame] | 683 | mWriter.setLayerDisplayFrame(translate<int64_t>(display), translate<int64_t>(layer), |
| 684 | translate<AidlRect>(frame)); |
Ady Abraham | e7385f7 | 2021-09-05 00:54:25 -0700 | [diff] [blame] | 685 | return Error::NONE; |
| 686 | } |
| 687 | |
| 688 | Error AidlComposer::setLayerPlaneAlpha(Display display, Layer layer, float alpha) { |
Ady Abraham | a6388c0 | 2021-11-11 21:11:51 -0800 | [diff] [blame] | 689 | mWriter.setLayerPlaneAlpha(translate<int64_t>(display), translate<int64_t>(layer), alpha); |
Ady Abraham | e7385f7 | 2021-09-05 00:54:25 -0700 | [diff] [blame] | 690 | return Error::NONE; |
| 691 | } |
| 692 | |
| 693 | Error AidlComposer::setLayerSidebandStream(Display display, Layer layer, |
| 694 | const native_handle_t* stream) { |
Ady Abraham | a6388c0 | 2021-11-11 21:11:51 -0800 | [diff] [blame] | 695 | mWriter.setLayerSidebandStream(translate<int64_t>(display), translate<int64_t>(layer), stream); |
Ady Abraham | e7385f7 | 2021-09-05 00:54:25 -0700 | [diff] [blame] | 696 | return Error::NONE; |
| 697 | } |
| 698 | |
| 699 | Error AidlComposer::setLayerSourceCrop(Display display, Layer layer, |
| 700 | const IComposerClient::FRect& crop) { |
Ady Abraham | a6388c0 | 2021-11-11 21:11:51 -0800 | [diff] [blame] | 701 | mWriter.setLayerSourceCrop(translate<int64_t>(display), translate<int64_t>(layer), |
| 702 | translate<AidlFRect>(crop)); |
Ady Abraham | e7385f7 | 2021-09-05 00:54:25 -0700 | [diff] [blame] | 703 | return Error::NONE; |
| 704 | } |
| 705 | |
| 706 | Error AidlComposer::setLayerTransform(Display display, Layer layer, Transform transform) { |
Ady Abraham | a6388c0 | 2021-11-11 21:11:51 -0800 | [diff] [blame] | 707 | mWriter.setLayerTransform(translate<int64_t>(display), translate<int64_t>(layer), |
| 708 | translate<AidlTransform>(transform)); |
Ady Abraham | e7385f7 | 2021-09-05 00:54:25 -0700 | [diff] [blame] | 709 | return Error::NONE; |
| 710 | } |
| 711 | |
| 712 | Error AidlComposer::setLayerVisibleRegion(Display display, Layer layer, |
| 713 | const std::vector<IComposerClient::Rect>& visible) { |
Ady Abraham | a6388c0 | 2021-11-11 21:11:51 -0800 | [diff] [blame] | 714 | mWriter.setLayerVisibleRegion(translate<int64_t>(display), translate<int64_t>(layer), |
| 715 | translate<AidlRect>(visible)); |
Ady Abraham | e7385f7 | 2021-09-05 00:54:25 -0700 | [diff] [blame] | 716 | return Error::NONE; |
| 717 | } |
| 718 | |
| 719 | Error AidlComposer::setLayerZOrder(Display display, Layer layer, uint32_t z) { |
Ady Abraham | a6388c0 | 2021-11-11 21:11:51 -0800 | [diff] [blame] | 720 | mWriter.setLayerZOrder(translate<int64_t>(display), translate<int64_t>(layer), z); |
Ady Abraham | e7385f7 | 2021-09-05 00:54:25 -0700 | [diff] [blame] | 721 | return Error::NONE; |
| 722 | } |
| 723 | |
| 724 | Error AidlComposer::execute() { |
Ady Abraham | a6388c0 | 2021-11-11 21:11:51 -0800 | [diff] [blame] | 725 | const auto& commands = mWriter.getPendingCommands(); |
| 726 | if (commands.empty()) { |
Ady Abraham | e7385f7 | 2021-09-05 00:54:25 -0700 | [diff] [blame] | 727 | mWriter.reset(); |
| 728 | return Error::NONE; |
| 729 | } |
| 730 | |
Ady Abraham | de79278 | 2021-12-20 10:00:49 -0800 | [diff] [blame] | 731 | { // scope for results |
| 732 | std::vector<CommandResultPayload> results; |
| 733 | auto status = mAidlComposerClient->executeCommands(commands, &results); |
| 734 | if (!status.isOk()) { |
| 735 | ALOGE("executeCommands failed %s", status.getDescription().c_str()); |
| 736 | return static_cast<Error>(status.getServiceSpecificError()); |
| 737 | } |
Ady Abraham | e7385f7 | 2021-09-05 00:54:25 -0700 | [diff] [blame] | 738 | |
Ady Abraham | de79278 | 2021-12-20 10:00:49 -0800 | [diff] [blame] | 739 | mReader.parse(std::move(results)); |
| 740 | } |
Ady Abraham | a6388c0 | 2021-11-11 21:11:51 -0800 | [diff] [blame] | 741 | const auto commandErrors = mReader.takeErrors(); |
| 742 | Error error = Error::NONE; |
| 743 | for (const auto& cmdErr : commandErrors) { |
| 744 | const auto index = static_cast<size_t>(cmdErr.commandIndex); |
| 745 | if (index < 0 || index >= commands.size()) { |
| 746 | ALOGE("invalid command index %zu", index); |
| 747 | return Error::BAD_PARAMETER; |
Ady Abraham | e7385f7 | 2021-09-05 00:54:25 -0700 | [diff] [blame] | 748 | } |
| 749 | |
Ady Abraham | a6388c0 | 2021-11-11 21:11:51 -0800 | [diff] [blame] | 750 | const auto& command = commands[index]; |
Ady Abraham | 4297736 | 2021-12-07 21:04:49 -0800 | [diff] [blame] | 751 | if (command.validateDisplay || command.presentDisplay || command.presentOrValidateDisplay) { |
| 752 | error = translate<Error>(cmdErr.errorCode); |
| 753 | } else { |
| 754 | ALOGW("command '%s' generated error %" PRId32, command.toString().c_str(), |
| 755 | cmdErr.errorCode); |
Ady Abraham | e7385f7 | 2021-09-05 00:54:25 -0700 | [diff] [blame] | 756 | } |
| 757 | } |
| 758 | |
| 759 | mWriter.reset(); |
| 760 | |
| 761 | return error; |
| 762 | } |
| 763 | |
| 764 | Error AidlComposer::setLayerPerFrameMetadata( |
| 765 | Display display, Layer layer, |
| 766 | const std::vector<IComposerClient::PerFrameMetadata>& perFrameMetadatas) { |
Ady Abraham | a6388c0 | 2021-11-11 21:11:51 -0800 | [diff] [blame] | 767 | mWriter.setLayerPerFrameMetadata(translate<int64_t>(display), translate<int64_t>(layer), |
| 768 | translate<AidlPerFrameMetadata>(perFrameMetadatas)); |
Ady Abraham | e7385f7 | 2021-09-05 00:54:25 -0700 | [diff] [blame] | 769 | return Error::NONE; |
| 770 | } |
| 771 | |
| 772 | std::vector<IComposerClient::PerFrameMetadataKey> AidlComposer::getPerFrameMetadataKeys( |
| 773 | Display display) { |
| 774 | std::vector<AidlPerFrameMetadataKey> keys; |
| 775 | const auto status = |
| 776 | mAidlComposerClient->getPerFrameMetadataKeys(translate<int64_t>(display), &keys); |
| 777 | if (!status.isOk()) { |
| 778 | ALOGE("getPerFrameMetadataKeys failed %s", status.getDescription().c_str()); |
| 779 | return {}; |
| 780 | } |
| 781 | return translate<IComposerClient::PerFrameMetadataKey>(keys); |
| 782 | } |
| 783 | |
| 784 | Error AidlComposer::getRenderIntents(Display display, ColorMode colorMode, |
| 785 | std::vector<RenderIntent>* outRenderIntents) { |
| 786 | std::vector<AidlRenderIntent> renderIntents; |
| 787 | const auto status = mAidlComposerClient->getRenderIntents(translate<int64_t>(display), |
| 788 | translate<AidlColorMode>(colorMode), |
| 789 | &renderIntents); |
| 790 | if (!status.isOk()) { |
| 791 | ALOGE("getRenderIntents failed %s", status.getDescription().c_str()); |
| 792 | return static_cast<Error>(status.getServiceSpecificError()); |
| 793 | } |
| 794 | *outRenderIntents = translate<RenderIntent>(renderIntents); |
| 795 | return Error::NONE; |
| 796 | } |
| 797 | |
| 798 | Error AidlComposer::getDataspaceSaturationMatrix(Dataspace dataspace, mat4* outMatrix) { |
| 799 | std::vector<float> matrix; |
| 800 | const auto status = |
| 801 | mAidlComposerClient->getDataspaceSaturationMatrix(translate<AidlDataspace>(dataspace), |
| 802 | &matrix); |
| 803 | if (!status.isOk()) { |
| 804 | ALOGE("getDataspaceSaturationMatrix failed %s", status.getDescription().c_str()); |
| 805 | return static_cast<Error>(status.getServiceSpecificError()); |
| 806 | } |
| 807 | *outMatrix = makeMat4(matrix); |
| 808 | return Error::NONE; |
| 809 | } |
| 810 | |
| 811 | Error AidlComposer::getDisplayIdentificationData(Display display, uint8_t* outPort, |
| 812 | std::vector<uint8_t>* outData) { |
| 813 | AidlDisplayIdentification displayIdentification; |
| 814 | const auto status = |
| 815 | mAidlComposerClient->getDisplayIdentificationData(translate<int64_t>(display), |
| 816 | &displayIdentification); |
| 817 | if (!status.isOk()) { |
| 818 | ALOGE("getDisplayIdentificationData failed %s", status.getDescription().c_str()); |
| 819 | return static_cast<Error>(status.getServiceSpecificError()); |
| 820 | } |
| 821 | |
| 822 | *outPort = static_cast<uint8_t>(displayIdentification.port); |
| 823 | *outData = displayIdentification.data; |
| 824 | |
| 825 | return Error::NONE; |
| 826 | } |
| 827 | |
| 828 | Error AidlComposer::setLayerColorTransform(Display display, Layer layer, const float* matrix) { |
Ady Abraham | a6388c0 | 2021-11-11 21:11:51 -0800 | [diff] [blame] | 829 | mWriter.setLayerColorTransform(translate<int64_t>(display), translate<int64_t>(layer), matrix); |
Ady Abraham | e7385f7 | 2021-09-05 00:54:25 -0700 | [diff] [blame] | 830 | return Error::NONE; |
| 831 | } |
| 832 | |
| 833 | Error AidlComposer::getDisplayedContentSamplingAttributes(Display display, PixelFormat* outFormat, |
| 834 | Dataspace* outDataspace, |
| 835 | uint8_t* outComponentMask) { |
| 836 | if (!outFormat || !outDataspace || !outComponentMask) { |
| 837 | return Error::BAD_PARAMETER; |
| 838 | } |
| 839 | |
| 840 | AidlDisplayContentSamplingAttributes attributes; |
| 841 | const auto status = |
| 842 | mAidlComposerClient->getDisplayedContentSamplingAttributes(translate<int64_t>(display), |
| 843 | &attributes); |
| 844 | if (!status.isOk()) { |
| 845 | ALOGE("getDisplayedContentSamplingAttributes failed %s", status.getDescription().c_str()); |
| 846 | return static_cast<Error>(status.getServiceSpecificError()); |
| 847 | } |
| 848 | |
| 849 | *outFormat = translate<PixelFormat>(attributes.format); |
| 850 | *outDataspace = translate<Dataspace>(attributes.dataspace); |
| 851 | *outComponentMask = static_cast<uint8_t>(attributes.componentMask); |
| 852 | return Error::NONE; |
| 853 | } |
| 854 | |
| 855 | Error AidlComposer::setDisplayContentSamplingEnabled(Display display, bool enabled, |
| 856 | uint8_t componentMask, uint64_t maxFrames) { |
| 857 | const auto status = |
| 858 | mAidlComposerClient |
| 859 | ->setDisplayedContentSamplingEnabled(translate<int64_t>(display), enabled, |
| 860 | static_cast<AidlFormatColorComponent>( |
| 861 | componentMask), |
| 862 | static_cast<int64_t>(maxFrames)); |
| 863 | if (!status.isOk()) { |
| 864 | ALOGE("setDisplayedContentSamplingEnabled failed %s", status.getDescription().c_str()); |
| 865 | return static_cast<Error>(status.getServiceSpecificError()); |
| 866 | } |
| 867 | return Error::NONE; |
| 868 | } |
| 869 | |
| 870 | Error AidlComposer::getDisplayedContentSample(Display display, uint64_t maxFrames, |
| 871 | uint64_t timestamp, DisplayedFrameStats* outStats) { |
| 872 | if (!outStats) { |
| 873 | return Error::BAD_PARAMETER; |
| 874 | } |
| 875 | |
| 876 | AidlDisplayContentSample sample; |
| 877 | const auto status = |
| 878 | mAidlComposerClient->getDisplayedContentSample(translate<int64_t>(display), |
| 879 | static_cast<int64_t>(maxFrames), |
| 880 | static_cast<int64_t>(timestamp), |
| 881 | &sample); |
| 882 | if (!status.isOk()) { |
| 883 | ALOGE("getDisplayedContentSample failed %s", status.getDescription().c_str()); |
| 884 | return static_cast<Error>(status.getServiceSpecificError()); |
| 885 | } |
| 886 | *outStats = translate<DisplayedFrameStats>(sample); |
| 887 | return Error::NONE; |
| 888 | } |
| 889 | |
| 890 | Error AidlComposer::setLayerPerFrameMetadataBlobs( |
| 891 | Display display, Layer layer, |
| 892 | const std::vector<IComposerClient::PerFrameMetadataBlob>& metadata) { |
Ady Abraham | a6388c0 | 2021-11-11 21:11:51 -0800 | [diff] [blame] | 893 | mWriter.setLayerPerFrameMetadataBlobs(translate<int64_t>(display), translate<int64_t>(layer), |
| 894 | translate<AidlPerFrameMetadataBlob>(metadata)); |
Ady Abraham | e7385f7 | 2021-09-05 00:54:25 -0700 | [diff] [blame] | 895 | return Error::NONE; |
| 896 | } |
| 897 | |
Alec Mouri | cdf1679 | 2021-12-10 13:16:06 -0800 | [diff] [blame] | 898 | Error AidlComposer::setDisplayBrightness(Display display, float brightness, |
| 899 | const DisplayBrightnessOptions& options) { |
Alec Mouri | cdf1679 | 2021-12-10 13:16:06 -0800 | [diff] [blame] | 900 | mWriter.setDisplayBrightness(translate<int64_t>(display), brightness); |
| 901 | |
| 902 | if (options.applyImmediately) { |
| 903 | return execute(); |
| 904 | } |
| 905 | |
Ady Abraham | e7385f7 | 2021-09-05 00:54:25 -0700 | [diff] [blame] | 906 | return Error::NONE; |
| 907 | } |
| 908 | |
| 909 | Error AidlComposer::getDisplayCapabilities(Display display, |
Leon Scroggins III | 5967aec | 2021-12-29 11:14:22 -0500 | [diff] [blame] | 910 | std::vector<AidlDisplayCapability>* outCapabilities) { |
| 911 | const auto status = mAidlComposerClient->getDisplayCapabilities(translate<int64_t>(display), |
| 912 | outCapabilities); |
Ady Abraham | e7385f7 | 2021-09-05 00:54:25 -0700 | [diff] [blame] | 913 | if (!status.isOk()) { |
| 914 | ALOGE("getDisplayCapabilities failed %s", status.getDescription().c_str()); |
Leon Scroggins III | 5967aec | 2021-12-29 11:14:22 -0500 | [diff] [blame] | 915 | outCapabilities->clear(); |
Ady Abraham | e7385f7 | 2021-09-05 00:54:25 -0700 | [diff] [blame] | 916 | return static_cast<Error>(status.getServiceSpecificError()); |
| 917 | } |
Ady Abraham | e7385f7 | 2021-09-05 00:54:25 -0700 | [diff] [blame] | 918 | return Error::NONE; |
| 919 | } |
| 920 | |
| 921 | V2_4::Error AidlComposer::getDisplayConnectionType( |
| 922 | Display display, IComposerClient::DisplayConnectionType* outType) { |
| 923 | AidlDisplayConnectionType type; |
| 924 | const auto status = |
| 925 | mAidlComposerClient->getDisplayConnectionType(translate<int64_t>(display), &type); |
| 926 | if (!status.isOk()) { |
| 927 | ALOGE("getDisplayConnectionType failed %s", status.getDescription().c_str()); |
| 928 | return static_cast<V2_4::Error>(status.getServiceSpecificError()); |
| 929 | } |
| 930 | *outType = translate<IComposerClient::DisplayConnectionType>(type); |
| 931 | return V2_4::Error::NONE; |
| 932 | } |
| 933 | |
| 934 | V2_4::Error AidlComposer::getDisplayVsyncPeriod(Display display, VsyncPeriodNanos* outVsyncPeriod) { |
| 935 | int32_t vsyncPeriod; |
| 936 | const auto status = |
| 937 | mAidlComposerClient->getDisplayVsyncPeriod(translate<int64_t>(display), &vsyncPeriod); |
| 938 | if (!status.isOk()) { |
| 939 | ALOGE("getDisplayVsyncPeriod failed %s", status.getDescription().c_str()); |
| 940 | return static_cast<V2_4::Error>(status.getServiceSpecificError()); |
| 941 | } |
| 942 | *outVsyncPeriod = translate<VsyncPeriodNanos>(vsyncPeriod); |
| 943 | return V2_4::Error::NONE; |
| 944 | } |
| 945 | |
| 946 | V2_4::Error AidlComposer::setActiveConfigWithConstraints( |
| 947 | Display display, Config config, |
| 948 | const IComposerClient::VsyncPeriodChangeConstraints& vsyncPeriodChangeConstraints, |
| 949 | VsyncPeriodChangeTimeline* outTimeline) { |
| 950 | AidlVsyncPeriodChangeTimeline timeline; |
| 951 | const auto status = |
| 952 | mAidlComposerClient |
| 953 | ->setActiveConfigWithConstraints(translate<int64_t>(display), |
| 954 | translate<int32_t>(config), |
| 955 | translate<AidlVsyncPeriodChangeConstraints>( |
| 956 | vsyncPeriodChangeConstraints), |
| 957 | &timeline); |
| 958 | if (!status.isOk()) { |
| 959 | ALOGE("setActiveConfigWithConstraints failed %s", status.getDescription().c_str()); |
| 960 | return static_cast<V2_4::Error>(status.getServiceSpecificError()); |
| 961 | } |
| 962 | *outTimeline = translate<VsyncPeriodChangeTimeline>(timeline); |
| 963 | return V2_4::Error::NONE; |
| 964 | } |
| 965 | |
| 966 | V2_4::Error AidlComposer::setAutoLowLatencyMode(Display display, bool on) { |
| 967 | const auto status = mAidlComposerClient->setAutoLowLatencyMode(translate<int64_t>(display), on); |
| 968 | if (!status.isOk()) { |
| 969 | ALOGE("setAutoLowLatencyMode failed %s", status.getDescription().c_str()); |
| 970 | return static_cast<V2_4::Error>(status.getServiceSpecificError()); |
| 971 | } |
| 972 | return V2_4::Error::NONE; |
| 973 | } |
| 974 | |
| 975 | V2_4::Error AidlComposer::getSupportedContentTypes( |
| 976 | Display displayId, std::vector<IComposerClient::ContentType>* outSupportedContentTypes) { |
| 977 | std::vector<AidlContentType> types; |
| 978 | const auto status = |
| 979 | mAidlComposerClient->getSupportedContentTypes(translate<int64_t>(displayId), &types); |
| 980 | if (!status.isOk()) { |
| 981 | ALOGE("getSupportedContentTypes failed %s", status.getDescription().c_str()); |
| 982 | return static_cast<V2_4::Error>(status.getServiceSpecificError()); |
| 983 | } |
| 984 | *outSupportedContentTypes = translate<IComposerClient::ContentType>(types); |
| 985 | return V2_4::Error::NONE; |
| 986 | } |
| 987 | |
| 988 | V2_4::Error AidlComposer::setContentType(Display display, |
| 989 | IComposerClient::ContentType contentType) { |
| 990 | const auto status = |
| 991 | mAidlComposerClient->setContentType(translate<int64_t>(display), |
| 992 | translate<AidlContentType>(contentType)); |
| 993 | if (!status.isOk()) { |
| 994 | ALOGE("setContentType failed %s", status.getDescription().c_str()); |
| 995 | return static_cast<V2_4::Error>(status.getServiceSpecificError()); |
| 996 | } |
| 997 | return V2_4::Error::NONE; |
| 998 | } |
| 999 | |
Ady Abraham | 3f97675 | 2021-12-20 16:17:50 -0800 | [diff] [blame] | 1000 | V2_4::Error AidlComposer::setLayerGenericMetadata(Display, Layer, const std::string&, bool, |
| 1001 | const std::vector<uint8_t>&) { |
| 1002 | // There are no users for this API. See b/209691612. |
| 1003 | return V2_4::Error::UNSUPPORTED; |
Ady Abraham | e7385f7 | 2021-09-05 00:54:25 -0700 | [diff] [blame] | 1004 | } |
| 1005 | |
| 1006 | V2_4::Error AidlComposer::getLayerGenericMetadataKeys( |
Ady Abraham | 3f97675 | 2021-12-20 16:17:50 -0800 | [diff] [blame] | 1007 | std::vector<IComposerClient::LayerGenericMetadataKey>*) { |
| 1008 | // There are no users for this API. See b/209691612. |
| 1009 | return V2_4::Error::UNSUPPORTED; |
Ady Abraham | e7385f7 | 2021-09-05 00:54:25 -0700 | [diff] [blame] | 1010 | } |
| 1011 | |
| 1012 | Error AidlComposer::getClientTargetProperty( |
Alec Mouri | cdf6cbc | 2021-11-01 17:21:15 -0700 | [diff] [blame] | 1013 | Display display, IComposerClient::ClientTargetProperty* outClientTargetProperty, |
| 1014 | float* whitePointNits) { |
Ady Abraham | de79278 | 2021-12-20 10:00:49 -0800 | [diff] [blame] | 1015 | const auto property = mReader.takeClientTargetProperty(translate<int64_t>(display)); |
| 1016 | *outClientTargetProperty = |
| 1017 | translate<IComposerClient::ClientTargetProperty>(property.clientTargetProperty); |
| 1018 | *whitePointNits = property.whitePointNits; |
Ady Abraham | e7385f7 | 2021-09-05 00:54:25 -0700 | [diff] [blame] | 1019 | return Error::NONE; |
| 1020 | } |
| 1021 | |
Alec Mouri | cdf6cbc | 2021-11-01 17:21:15 -0700 | [diff] [blame] | 1022 | Error AidlComposer::setLayerWhitePointNits(Display display, Layer layer, float whitePointNits) { |
| 1023 | mWriter.setLayerWhitePointNits(translate<int64_t>(display), translate<int64_t>(layer), |
| 1024 | whitePointNits); |
| 1025 | return Error::NONE; |
| 1026 | } |
| 1027 | |
Leon Scroggins III | d77d316 | 2022-01-05 10:42:28 -0500 | [diff] [blame] | 1028 | Error AidlComposer::setLayerBlockingRegion(Display display, Layer layer, |
| 1029 | const std::vector<IComposerClient::Rect>& blocking) { |
| 1030 | mWriter.setLayerBlockingRegion(translate<int64_t>(display), translate<int64_t>(layer), |
| 1031 | translate<AidlRect>(blocking)); |
| 1032 | return Error::NONE; |
| 1033 | } |
Ady Abraham | e7385f7 | 2021-09-05 00:54:25 -0700 | [diff] [blame] | 1034 | } // namespace Hwc2 |
| 1035 | } // namespace android |