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