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