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