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; |
| 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) { |
Ady Abraham | 33b92b9 | 2021-12-08 18:30:27 -0800 | [diff] [blame^] | 445 | std::vector<AidlDisplayCapability> capabilities; |
Ady Abraham | e7385f7 | 2021-09-05 00:54:25 -0700 | [diff] [blame] | 446 | const auto status = |
Ady Abraham | 33b92b9 | 2021-12-08 18:30:27 -0800 | [diff] [blame^] | 447 | mAidlComposerClient->getDisplayCapabilities(translate<int64_t>(display), &capabilities); |
Ady Abraham | e7385f7 | 2021-09-05 00:54:25 -0700 | [diff] [blame] | 448 | if (!status.isOk()) { |
Ady Abraham | 33b92b9 | 2021-12-08 18:30:27 -0800 | [diff] [blame^] | 449 | ALOGE("getDisplayCapabilities failed %s", status.getDescription().c_str()); |
Ady Abraham | e7385f7 | 2021-09-05 00:54:25 -0700 | [diff] [blame] | 450 | return static_cast<Error>(status.getServiceSpecificError()); |
| 451 | } |
Ady Abraham | 33b92b9 | 2021-12-08 18:30:27 -0800 | [diff] [blame^] | 452 | *outSupport = std::find(capabilities.begin(), capabilities.end(), |
| 453 | AidlDisplayCapability::DOZE) != capabilities.end(); |
Ady Abraham | e7385f7 | 2021-09-05 00:54:25 -0700 | [diff] [blame] | 454 | return Error::NONE; |
| 455 | } |
| 456 | |
| 457 | Error AidlComposer::getHdrCapabilities(Display display, std::vector<Hdr>* outTypes, |
| 458 | float* outMaxLuminance, float* outMaxAverageLuminance, |
| 459 | float* outMinLuminance) { |
| 460 | AidlHdrCapabilities capabilities; |
| 461 | const auto status = |
| 462 | mAidlComposerClient->getHdrCapabilities(translate<int64_t>(display), &capabilities); |
| 463 | if (!status.isOk()) { |
| 464 | ALOGE("getHdrCapabilities failed %s", status.getDescription().c_str()); |
| 465 | return static_cast<Error>(status.getServiceSpecificError()); |
| 466 | } |
| 467 | |
| 468 | *outTypes = translate<Hdr>(capabilities.types); |
| 469 | *outMaxLuminance = capabilities.maxLuminance; |
| 470 | *outMaxAverageLuminance = capabilities.maxAverageLuminance; |
| 471 | *outMinLuminance = capabilities.minLuminance; |
| 472 | return Error::NONE; |
| 473 | } |
| 474 | |
| 475 | Error AidlComposer::getReleaseFences(Display display, std::vector<Layer>* outLayers, |
| 476 | std::vector<int>* outReleaseFences) { |
Ady Abraham | a6388c0 | 2021-11-11 21:11:51 -0800 | [diff] [blame] | 477 | std::vector<int64_t> layers; |
| 478 | mReader.takeReleaseFences(translate<int64_t>(display), &layers, outReleaseFences); |
| 479 | *outLayers = translate<Layer>(layers); |
Ady Abraham | e7385f7 | 2021-09-05 00:54:25 -0700 | [diff] [blame] | 480 | return Error::NONE; |
| 481 | } |
| 482 | |
| 483 | Error AidlComposer::presentDisplay(Display display, int* outPresentFence) { |
| 484 | ATRACE_NAME("HwcPresentDisplay"); |
Ady Abraham | a6388c0 | 2021-11-11 21:11:51 -0800 | [diff] [blame] | 485 | mWriter.presentDisplay(translate<int64_t>(display)); |
Ady Abraham | e7385f7 | 2021-09-05 00:54:25 -0700 | [diff] [blame] | 486 | |
| 487 | Error error = execute(); |
| 488 | if (error != Error::NONE) { |
| 489 | return error; |
| 490 | } |
| 491 | |
Ady Abraham | a6388c0 | 2021-11-11 21:11:51 -0800 | [diff] [blame] | 492 | mReader.takePresentFence(translate<int64_t>(display), outPresentFence); |
Ady Abraham | e7385f7 | 2021-09-05 00:54:25 -0700 | [diff] [blame] | 493 | |
| 494 | return Error::NONE; |
| 495 | } |
| 496 | |
| 497 | Error AidlComposer::setActiveConfig(Display display, Config config) { |
| 498 | const auto status = mAidlComposerClient->setActiveConfig(translate<int64_t>(display), |
| 499 | translate<int32_t>(config)); |
| 500 | if (!status.isOk()) { |
| 501 | ALOGE("setActiveConfig failed %s", status.getDescription().c_str()); |
| 502 | return static_cast<Error>(status.getServiceSpecificError()); |
| 503 | } |
| 504 | return Error::NONE; |
| 505 | } |
| 506 | |
| 507 | Error AidlComposer::setClientTarget(Display display, uint32_t slot, const sp<GraphicBuffer>& target, |
| 508 | int acquireFence, Dataspace dataspace, |
| 509 | const std::vector<IComposerClient::Rect>& damage) { |
Ady Abraham | e7385f7 | 2021-09-05 00:54:25 -0700 | [diff] [blame] | 510 | const native_handle_t* handle = nullptr; |
| 511 | if (target.get()) { |
| 512 | handle = target->getNativeBuffer()->handle; |
| 513 | } |
| 514 | |
Ady Abraham | a6388c0 | 2021-11-11 21:11:51 -0800 | [diff] [blame] | 515 | mWriter.setClientTarget(translate<int64_t>(display), slot, handle, acquireFence, |
Ady Abraham | e7385f7 | 2021-09-05 00:54:25 -0700 | [diff] [blame] | 516 | translate<aidl::android::hardware::graphics::common::Dataspace>( |
| 517 | dataspace), |
| 518 | translate<AidlRect>(damage)); |
| 519 | return Error::NONE; |
| 520 | } |
| 521 | |
| 522 | Error AidlComposer::setColorMode(Display display, ColorMode mode, RenderIntent renderIntent) { |
| 523 | const auto status = |
| 524 | mAidlComposerClient->setColorMode(translate<int64_t>(display), |
| 525 | translate<AidlColorMode>(mode), |
| 526 | translate<AidlRenderIntent>(renderIntent)); |
| 527 | if (!status.isOk()) { |
| 528 | ALOGE("setColorMode failed %s", status.getDescription().c_str()); |
| 529 | return static_cast<Error>(status.getServiceSpecificError()); |
| 530 | } |
| 531 | return Error::NONE; |
| 532 | } |
| 533 | |
| 534 | Error AidlComposer::setColorTransform(Display display, const float* matrix, ColorTransform hint) { |
Ady Abraham | a6388c0 | 2021-11-11 21:11:51 -0800 | [diff] [blame] | 535 | mWriter.setColorTransform(translate<int64_t>(display), matrix, |
| 536 | translate<AidlColorTransform>(hint)); |
Ady Abraham | e7385f7 | 2021-09-05 00:54:25 -0700 | [diff] [blame] | 537 | return Error::NONE; |
| 538 | } |
| 539 | |
| 540 | Error AidlComposer::setOutputBuffer(Display display, const native_handle_t* buffer, |
| 541 | int releaseFence) { |
Ady Abraham | a6388c0 | 2021-11-11 21:11:51 -0800 | [diff] [blame] | 542 | mWriter.setOutputBuffer(translate<int64_t>(display), 0, buffer, dup(releaseFence)); |
Ady Abraham | e7385f7 | 2021-09-05 00:54:25 -0700 | [diff] [blame] | 543 | return Error::NONE; |
| 544 | } |
| 545 | |
| 546 | Error AidlComposer::setPowerMode(Display display, IComposerClient::PowerMode mode) { |
| 547 | const auto status = mAidlComposerClient->setPowerMode(translate<int64_t>(display), |
| 548 | translate<PowerMode>(mode)); |
| 549 | if (!status.isOk()) { |
| 550 | ALOGE("setPowerMode failed %s", status.getDescription().c_str()); |
| 551 | return static_cast<Error>(status.getServiceSpecificError()); |
| 552 | } |
| 553 | return Error::NONE; |
| 554 | } |
| 555 | |
| 556 | Error AidlComposer::setVsyncEnabled(Display display, IComposerClient::Vsync enabled) { |
| 557 | const bool enableVsync = enabled == IComposerClient::Vsync::ENABLE; |
| 558 | const auto status = |
| 559 | mAidlComposerClient->setVsyncEnabled(translate<int64_t>(display), enableVsync); |
| 560 | if (!status.isOk()) { |
| 561 | ALOGE("setVsyncEnabled failed %s", status.getDescription().c_str()); |
| 562 | return static_cast<Error>(status.getServiceSpecificError()); |
| 563 | } |
| 564 | return Error::NONE; |
| 565 | } |
| 566 | |
| 567 | Error AidlComposer::setClientTargetSlotCount(Display display) { |
| 568 | const int32_t bufferSlotCount = BufferQueue::NUM_BUFFER_SLOTS; |
| 569 | const auto status = mAidlComposerClient->setClientTargetSlotCount(translate<int64_t>(display), |
| 570 | bufferSlotCount); |
| 571 | if (!status.isOk()) { |
| 572 | ALOGE("setClientTargetSlotCount failed %s", status.getDescription().c_str()); |
| 573 | return static_cast<Error>(status.getServiceSpecificError()); |
| 574 | } |
| 575 | return Error::NONE; |
| 576 | } |
| 577 | |
| 578 | Error AidlComposer::validateDisplay(Display display, uint32_t* outNumTypes, |
| 579 | uint32_t* outNumRequests) { |
| 580 | ATRACE_NAME("HwcValidateDisplay"); |
Ady Abraham | a6388c0 | 2021-11-11 21:11:51 -0800 | [diff] [blame] | 581 | mWriter.validateDisplay(translate<int64_t>(display)); |
Ady Abraham | e7385f7 | 2021-09-05 00:54:25 -0700 | [diff] [blame] | 582 | |
| 583 | Error error = execute(); |
| 584 | if (error != Error::NONE) { |
| 585 | return error; |
| 586 | } |
| 587 | |
Ady Abraham | a6388c0 | 2021-11-11 21:11:51 -0800 | [diff] [blame] | 588 | mReader.hasChanges(translate<int64_t>(display), outNumTypes, outNumRequests); |
Ady Abraham | e7385f7 | 2021-09-05 00:54:25 -0700 | [diff] [blame] | 589 | |
| 590 | return Error::NONE; |
| 591 | } |
| 592 | |
| 593 | Error AidlComposer::presentOrValidateDisplay(Display display, uint32_t* outNumTypes, |
| 594 | uint32_t* outNumRequests, int* outPresentFence, |
| 595 | uint32_t* state) { |
| 596 | ATRACE_NAME("HwcPresentOrValidateDisplay"); |
Ady Abraham | a6388c0 | 2021-11-11 21:11:51 -0800 | [diff] [blame] | 597 | mWriter.presentOrvalidateDisplay(translate<int64_t>(display)); |
Ady Abraham | e7385f7 | 2021-09-05 00:54:25 -0700 | [diff] [blame] | 598 | |
| 599 | Error error = execute(); |
| 600 | if (error != Error::NONE) { |
| 601 | return error; |
| 602 | } |
| 603 | |
Ady Abraham | a6388c0 | 2021-11-11 21:11:51 -0800 | [diff] [blame] | 604 | mReader.takePresentOrValidateStage(translate<int64_t>(display), state); |
Ady Abraham | e7385f7 | 2021-09-05 00:54:25 -0700 | [diff] [blame] | 605 | |
| 606 | if (*state == 1) { // Present succeeded |
Ady Abraham | a6388c0 | 2021-11-11 21:11:51 -0800 | [diff] [blame] | 607 | mReader.takePresentFence(translate<int64_t>(display), outPresentFence); |
Ady Abraham | e7385f7 | 2021-09-05 00:54:25 -0700 | [diff] [blame] | 608 | } |
| 609 | |
| 610 | if (*state == 0) { // Validate succeeded. |
Ady Abraham | a6388c0 | 2021-11-11 21:11:51 -0800 | [diff] [blame] | 611 | mReader.hasChanges(translate<int64_t>(display), outNumTypes, outNumRequests); |
Ady Abraham | e7385f7 | 2021-09-05 00:54:25 -0700 | [diff] [blame] | 612 | } |
| 613 | |
| 614 | return Error::NONE; |
| 615 | } |
| 616 | |
| 617 | 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] | 618 | mWriter.setLayerCursorPosition(translate<int64_t>(display), translate<int64_t>(layer), x, y); |
Ady Abraham | e7385f7 | 2021-09-05 00:54:25 -0700 | [diff] [blame] | 619 | return Error::NONE; |
| 620 | } |
| 621 | |
| 622 | Error AidlComposer::setLayerBuffer(Display display, Layer layer, uint32_t slot, |
| 623 | const sp<GraphicBuffer>& buffer, int acquireFence) { |
Ady Abraham | e7385f7 | 2021-09-05 00:54:25 -0700 | [diff] [blame] | 624 | const native_handle_t* handle = nullptr; |
| 625 | if (buffer.get()) { |
| 626 | handle = buffer->getNativeBuffer()->handle; |
| 627 | } |
| 628 | |
Ady Abraham | a6388c0 | 2021-11-11 21:11:51 -0800 | [diff] [blame] | 629 | mWriter.setLayerBuffer(translate<int64_t>(display), translate<int64_t>(layer), slot, handle, |
| 630 | acquireFence); |
Ady Abraham | e7385f7 | 2021-09-05 00:54:25 -0700 | [diff] [blame] | 631 | return Error::NONE; |
| 632 | } |
| 633 | |
| 634 | Error AidlComposer::setLayerSurfaceDamage(Display display, Layer layer, |
| 635 | const std::vector<IComposerClient::Rect>& damage) { |
Ady Abraham | a6388c0 | 2021-11-11 21:11:51 -0800 | [diff] [blame] | 636 | mWriter.setLayerSurfaceDamage(translate<int64_t>(display), translate<int64_t>(layer), |
| 637 | translate<AidlRect>(damage)); |
Ady Abraham | e7385f7 | 2021-09-05 00:54:25 -0700 | [diff] [blame] | 638 | return Error::NONE; |
| 639 | } |
| 640 | |
| 641 | Error AidlComposer::setLayerBlendMode(Display display, Layer layer, |
| 642 | IComposerClient::BlendMode mode) { |
Ady Abraham | a6388c0 | 2021-11-11 21:11:51 -0800 | [diff] [blame] | 643 | mWriter.setLayerBlendMode(translate<int64_t>(display), translate<int64_t>(layer), |
| 644 | translate<BlendMode>(mode)); |
Ady Abraham | e7385f7 | 2021-09-05 00:54:25 -0700 | [diff] [blame] | 645 | return Error::NONE; |
| 646 | } |
| 647 | |
| 648 | Error AidlComposer::setLayerColor(Display display, Layer layer, |
| 649 | const IComposerClient::Color& color) { |
Ady Abraham | a6388c0 | 2021-11-11 21:11:51 -0800 | [diff] [blame] | 650 | mWriter.setLayerColor(translate<int64_t>(display), translate<int64_t>(layer), |
| 651 | translate<Color>(color)); |
Ady Abraham | e7385f7 | 2021-09-05 00:54:25 -0700 | [diff] [blame] | 652 | return Error::NONE; |
| 653 | } |
| 654 | |
| 655 | Error AidlComposer::setLayerCompositionType(Display display, Layer layer, |
| 656 | IComposerClient::Composition type) { |
Ady Abraham | a6388c0 | 2021-11-11 21:11:51 -0800 | [diff] [blame] | 657 | mWriter.setLayerCompositionType(translate<int64_t>(display), translate<int64_t>(layer), |
| 658 | translate<Composition>(type)); |
Ady Abraham | e7385f7 | 2021-09-05 00:54:25 -0700 | [diff] [blame] | 659 | return Error::NONE; |
| 660 | } |
| 661 | |
| 662 | Error AidlComposer::setLayerDataspace(Display display, Layer layer, Dataspace dataspace) { |
Ady Abraham | a6388c0 | 2021-11-11 21:11:51 -0800 | [diff] [blame] | 663 | mWriter.setLayerDataspace(translate<int64_t>(display), translate<int64_t>(layer), |
| 664 | translate<AidlDataspace>(dataspace)); |
Ady Abraham | e7385f7 | 2021-09-05 00:54:25 -0700 | [diff] [blame] | 665 | return Error::NONE; |
| 666 | } |
| 667 | |
| 668 | Error AidlComposer::setLayerDisplayFrame(Display display, Layer layer, |
| 669 | const IComposerClient::Rect& frame) { |
Ady Abraham | a6388c0 | 2021-11-11 21:11:51 -0800 | [diff] [blame] | 670 | mWriter.setLayerDisplayFrame(translate<int64_t>(display), translate<int64_t>(layer), |
| 671 | translate<AidlRect>(frame)); |
Ady Abraham | e7385f7 | 2021-09-05 00:54:25 -0700 | [diff] [blame] | 672 | return Error::NONE; |
| 673 | } |
| 674 | |
| 675 | Error AidlComposer::setLayerPlaneAlpha(Display display, Layer layer, float alpha) { |
Ady Abraham | a6388c0 | 2021-11-11 21:11:51 -0800 | [diff] [blame] | 676 | mWriter.setLayerPlaneAlpha(translate<int64_t>(display), translate<int64_t>(layer), alpha); |
Ady Abraham | e7385f7 | 2021-09-05 00:54:25 -0700 | [diff] [blame] | 677 | return Error::NONE; |
| 678 | } |
| 679 | |
| 680 | Error AidlComposer::setLayerSidebandStream(Display display, Layer layer, |
| 681 | const native_handle_t* stream) { |
Ady Abraham | a6388c0 | 2021-11-11 21:11:51 -0800 | [diff] [blame] | 682 | mWriter.setLayerSidebandStream(translate<int64_t>(display), translate<int64_t>(layer), stream); |
Ady Abraham | e7385f7 | 2021-09-05 00:54:25 -0700 | [diff] [blame] | 683 | return Error::NONE; |
| 684 | } |
| 685 | |
| 686 | Error AidlComposer::setLayerSourceCrop(Display display, Layer layer, |
| 687 | const IComposerClient::FRect& crop) { |
Ady Abraham | a6388c0 | 2021-11-11 21:11:51 -0800 | [diff] [blame] | 688 | mWriter.setLayerSourceCrop(translate<int64_t>(display), translate<int64_t>(layer), |
| 689 | translate<AidlFRect>(crop)); |
Ady Abraham | e7385f7 | 2021-09-05 00:54:25 -0700 | [diff] [blame] | 690 | return Error::NONE; |
| 691 | } |
| 692 | |
| 693 | Error AidlComposer::setLayerTransform(Display display, Layer layer, Transform transform) { |
Ady Abraham | a6388c0 | 2021-11-11 21:11:51 -0800 | [diff] [blame] | 694 | mWriter.setLayerTransform(translate<int64_t>(display), translate<int64_t>(layer), |
| 695 | translate<AidlTransform>(transform)); |
Ady Abraham | e7385f7 | 2021-09-05 00:54:25 -0700 | [diff] [blame] | 696 | return Error::NONE; |
| 697 | } |
| 698 | |
| 699 | Error AidlComposer::setLayerVisibleRegion(Display display, Layer layer, |
| 700 | const std::vector<IComposerClient::Rect>& visible) { |
Ady Abraham | a6388c0 | 2021-11-11 21:11:51 -0800 | [diff] [blame] | 701 | mWriter.setLayerVisibleRegion(translate<int64_t>(display), translate<int64_t>(layer), |
| 702 | translate<AidlRect>(visible)); |
Ady Abraham | e7385f7 | 2021-09-05 00:54:25 -0700 | [diff] [blame] | 703 | return Error::NONE; |
| 704 | } |
| 705 | |
| 706 | Error AidlComposer::setLayerZOrder(Display display, Layer layer, uint32_t z) { |
Ady Abraham | a6388c0 | 2021-11-11 21:11:51 -0800 | [diff] [blame] | 707 | mWriter.setLayerZOrder(translate<int64_t>(display), translate<int64_t>(layer), z); |
Ady Abraham | e7385f7 | 2021-09-05 00:54:25 -0700 | [diff] [blame] | 708 | return Error::NONE; |
| 709 | } |
| 710 | |
| 711 | Error AidlComposer::execute() { |
Ady Abraham | a6388c0 | 2021-11-11 21:11:51 -0800 | [diff] [blame] | 712 | const auto& commands = mWriter.getPendingCommands(); |
| 713 | if (commands.empty()) { |
Ady Abraham | e7385f7 | 2021-09-05 00:54:25 -0700 | [diff] [blame] | 714 | mWriter.reset(); |
| 715 | return Error::NONE; |
| 716 | } |
| 717 | |
Ady Abraham | a6388c0 | 2021-11-11 21:11:51 -0800 | [diff] [blame] | 718 | std::vector<CommandResultPayload> results; |
| 719 | auto status = mAidlComposerClient->executeCommands(commands, &results); |
Ady Abraham | e7385f7 | 2021-09-05 00:54:25 -0700 | [diff] [blame] | 720 | if (!status.isOk()) { |
| 721 | ALOGE("executeCommands failed %s", status.getDescription().c_str()); |
| 722 | return static_cast<Error>(status.getServiceSpecificError()); |
| 723 | } |
| 724 | |
Ady Abraham | a6388c0 | 2021-11-11 21:11:51 -0800 | [diff] [blame] | 725 | mReader.parse(results); |
| 726 | const auto commandErrors = mReader.takeErrors(); |
| 727 | Error error = Error::NONE; |
| 728 | for (const auto& cmdErr : commandErrors) { |
| 729 | const auto index = static_cast<size_t>(cmdErr.commandIndex); |
| 730 | if (index < 0 || index >= commands.size()) { |
| 731 | ALOGE("invalid command index %zu", index); |
| 732 | return Error::BAD_PARAMETER; |
Ady Abraham | e7385f7 | 2021-09-05 00:54:25 -0700 | [diff] [blame] | 733 | } |
| 734 | |
Ady Abraham | a6388c0 | 2021-11-11 21:11:51 -0800 | [diff] [blame] | 735 | const auto& command = commands[index]; |
Ady Abraham | 4297736 | 2021-12-07 21:04:49 -0800 | [diff] [blame] | 736 | if (command.validateDisplay || command.presentDisplay || command.presentOrValidateDisplay) { |
| 737 | error = translate<Error>(cmdErr.errorCode); |
| 738 | } else { |
| 739 | ALOGW("command '%s' generated error %" PRId32, command.toString().c_str(), |
| 740 | cmdErr.errorCode); |
Ady Abraham | e7385f7 | 2021-09-05 00:54:25 -0700 | [diff] [blame] | 741 | } |
| 742 | } |
| 743 | |
| 744 | mWriter.reset(); |
| 745 | |
| 746 | return error; |
| 747 | } |
| 748 | |
| 749 | Error AidlComposer::setLayerPerFrameMetadata( |
| 750 | Display display, Layer layer, |
| 751 | const std::vector<IComposerClient::PerFrameMetadata>& perFrameMetadatas) { |
Ady Abraham | a6388c0 | 2021-11-11 21:11:51 -0800 | [diff] [blame] | 752 | mWriter.setLayerPerFrameMetadata(translate<int64_t>(display), translate<int64_t>(layer), |
| 753 | translate<AidlPerFrameMetadata>(perFrameMetadatas)); |
Ady Abraham | e7385f7 | 2021-09-05 00:54:25 -0700 | [diff] [blame] | 754 | return Error::NONE; |
| 755 | } |
| 756 | |
| 757 | std::vector<IComposerClient::PerFrameMetadataKey> AidlComposer::getPerFrameMetadataKeys( |
| 758 | Display display) { |
| 759 | std::vector<AidlPerFrameMetadataKey> keys; |
| 760 | const auto status = |
| 761 | mAidlComposerClient->getPerFrameMetadataKeys(translate<int64_t>(display), &keys); |
| 762 | if (!status.isOk()) { |
| 763 | ALOGE("getPerFrameMetadataKeys failed %s", status.getDescription().c_str()); |
| 764 | return {}; |
| 765 | } |
| 766 | return translate<IComposerClient::PerFrameMetadataKey>(keys); |
| 767 | } |
| 768 | |
| 769 | Error AidlComposer::getRenderIntents(Display display, ColorMode colorMode, |
| 770 | std::vector<RenderIntent>* outRenderIntents) { |
| 771 | std::vector<AidlRenderIntent> renderIntents; |
| 772 | const auto status = mAidlComposerClient->getRenderIntents(translate<int64_t>(display), |
| 773 | translate<AidlColorMode>(colorMode), |
| 774 | &renderIntents); |
| 775 | if (!status.isOk()) { |
| 776 | ALOGE("getRenderIntents failed %s", status.getDescription().c_str()); |
| 777 | return static_cast<Error>(status.getServiceSpecificError()); |
| 778 | } |
| 779 | *outRenderIntents = translate<RenderIntent>(renderIntents); |
| 780 | return Error::NONE; |
| 781 | } |
| 782 | |
| 783 | Error AidlComposer::getDataspaceSaturationMatrix(Dataspace dataspace, mat4* outMatrix) { |
| 784 | std::vector<float> matrix; |
| 785 | const auto status = |
| 786 | mAidlComposerClient->getDataspaceSaturationMatrix(translate<AidlDataspace>(dataspace), |
| 787 | &matrix); |
| 788 | if (!status.isOk()) { |
| 789 | ALOGE("getDataspaceSaturationMatrix failed %s", status.getDescription().c_str()); |
| 790 | return static_cast<Error>(status.getServiceSpecificError()); |
| 791 | } |
| 792 | *outMatrix = makeMat4(matrix); |
| 793 | return Error::NONE; |
| 794 | } |
| 795 | |
| 796 | Error AidlComposer::getDisplayIdentificationData(Display display, uint8_t* outPort, |
| 797 | std::vector<uint8_t>* outData) { |
| 798 | AidlDisplayIdentification displayIdentification; |
| 799 | const auto status = |
| 800 | mAidlComposerClient->getDisplayIdentificationData(translate<int64_t>(display), |
| 801 | &displayIdentification); |
| 802 | if (!status.isOk()) { |
| 803 | ALOGE("getDisplayIdentificationData failed %s", status.getDescription().c_str()); |
| 804 | return static_cast<Error>(status.getServiceSpecificError()); |
| 805 | } |
| 806 | |
| 807 | *outPort = static_cast<uint8_t>(displayIdentification.port); |
| 808 | *outData = displayIdentification.data; |
| 809 | |
| 810 | return Error::NONE; |
| 811 | } |
| 812 | |
| 813 | Error AidlComposer::setLayerColorTransform(Display display, Layer layer, const float* matrix) { |
Ady Abraham | a6388c0 | 2021-11-11 21:11:51 -0800 | [diff] [blame] | 814 | mWriter.setLayerColorTransform(translate<int64_t>(display), translate<int64_t>(layer), matrix); |
Ady Abraham | e7385f7 | 2021-09-05 00:54:25 -0700 | [diff] [blame] | 815 | return Error::NONE; |
| 816 | } |
| 817 | |
| 818 | Error AidlComposer::getDisplayedContentSamplingAttributes(Display display, PixelFormat* outFormat, |
| 819 | Dataspace* outDataspace, |
| 820 | uint8_t* outComponentMask) { |
| 821 | if (!outFormat || !outDataspace || !outComponentMask) { |
| 822 | return Error::BAD_PARAMETER; |
| 823 | } |
| 824 | |
| 825 | AidlDisplayContentSamplingAttributes attributes; |
| 826 | const auto status = |
| 827 | mAidlComposerClient->getDisplayedContentSamplingAttributes(translate<int64_t>(display), |
| 828 | &attributes); |
| 829 | if (!status.isOk()) { |
| 830 | ALOGE("getDisplayedContentSamplingAttributes failed %s", status.getDescription().c_str()); |
| 831 | return static_cast<Error>(status.getServiceSpecificError()); |
| 832 | } |
| 833 | |
| 834 | *outFormat = translate<PixelFormat>(attributes.format); |
| 835 | *outDataspace = translate<Dataspace>(attributes.dataspace); |
| 836 | *outComponentMask = static_cast<uint8_t>(attributes.componentMask); |
| 837 | return Error::NONE; |
| 838 | } |
| 839 | |
| 840 | Error AidlComposer::setDisplayContentSamplingEnabled(Display display, bool enabled, |
| 841 | uint8_t componentMask, uint64_t maxFrames) { |
| 842 | const auto status = |
| 843 | mAidlComposerClient |
| 844 | ->setDisplayedContentSamplingEnabled(translate<int64_t>(display), enabled, |
| 845 | static_cast<AidlFormatColorComponent>( |
| 846 | componentMask), |
| 847 | static_cast<int64_t>(maxFrames)); |
| 848 | if (!status.isOk()) { |
| 849 | ALOGE("setDisplayedContentSamplingEnabled failed %s", status.getDescription().c_str()); |
| 850 | return static_cast<Error>(status.getServiceSpecificError()); |
| 851 | } |
| 852 | return Error::NONE; |
| 853 | } |
| 854 | |
| 855 | Error AidlComposer::getDisplayedContentSample(Display display, uint64_t maxFrames, |
| 856 | uint64_t timestamp, DisplayedFrameStats* outStats) { |
| 857 | if (!outStats) { |
| 858 | return Error::BAD_PARAMETER; |
| 859 | } |
| 860 | |
| 861 | AidlDisplayContentSample sample; |
| 862 | const auto status = |
| 863 | mAidlComposerClient->getDisplayedContentSample(translate<int64_t>(display), |
| 864 | static_cast<int64_t>(maxFrames), |
| 865 | static_cast<int64_t>(timestamp), |
| 866 | &sample); |
| 867 | if (!status.isOk()) { |
| 868 | ALOGE("getDisplayedContentSample failed %s", status.getDescription().c_str()); |
| 869 | return static_cast<Error>(status.getServiceSpecificError()); |
| 870 | } |
| 871 | *outStats = translate<DisplayedFrameStats>(sample); |
| 872 | return Error::NONE; |
| 873 | } |
| 874 | |
| 875 | Error AidlComposer::setLayerPerFrameMetadataBlobs( |
| 876 | Display display, Layer layer, |
| 877 | const std::vector<IComposerClient::PerFrameMetadataBlob>& metadata) { |
Ady Abraham | a6388c0 | 2021-11-11 21:11:51 -0800 | [diff] [blame] | 878 | mWriter.setLayerPerFrameMetadataBlobs(translate<int64_t>(display), translate<int64_t>(layer), |
| 879 | translate<AidlPerFrameMetadataBlob>(metadata)); |
Ady Abraham | e7385f7 | 2021-09-05 00:54:25 -0700 | [diff] [blame] | 880 | return Error::NONE; |
| 881 | } |
| 882 | |
| 883 | Error AidlComposer::setDisplayBrightness(Display display, float brightness) { |
| 884 | const auto status = |
| 885 | mAidlComposerClient->setDisplayBrightness(translate<int64_t>(display), brightness); |
| 886 | if (!status.isOk()) { |
| 887 | ALOGE("setDisplayBrightness failed %s", status.getDescription().c_str()); |
| 888 | return static_cast<Error>(status.getServiceSpecificError()); |
| 889 | } |
| 890 | return Error::NONE; |
| 891 | } |
| 892 | |
| 893 | Error AidlComposer::getDisplayCapabilities(Display display, |
| 894 | std::vector<DisplayCapability>* outCapabilities) { |
| 895 | std::vector<AidlDisplayCapability> capabilities; |
| 896 | const auto status = |
| 897 | mAidlComposerClient->getDisplayCapabilities(translate<int64_t>(display), &capabilities); |
| 898 | if (!status.isOk()) { |
| 899 | ALOGE("getDisplayCapabilities failed %s", status.getDescription().c_str()); |
| 900 | return static_cast<Error>(status.getServiceSpecificError()); |
| 901 | } |
| 902 | *outCapabilities = translate<DisplayCapability>(capabilities); |
| 903 | return Error::NONE; |
| 904 | } |
| 905 | |
| 906 | V2_4::Error AidlComposer::getDisplayConnectionType( |
| 907 | Display display, IComposerClient::DisplayConnectionType* outType) { |
| 908 | AidlDisplayConnectionType type; |
| 909 | const auto status = |
| 910 | mAidlComposerClient->getDisplayConnectionType(translate<int64_t>(display), &type); |
| 911 | if (!status.isOk()) { |
| 912 | ALOGE("getDisplayConnectionType failed %s", status.getDescription().c_str()); |
| 913 | return static_cast<V2_4::Error>(status.getServiceSpecificError()); |
| 914 | } |
| 915 | *outType = translate<IComposerClient::DisplayConnectionType>(type); |
| 916 | return V2_4::Error::NONE; |
| 917 | } |
| 918 | |
| 919 | V2_4::Error AidlComposer::getDisplayVsyncPeriod(Display display, VsyncPeriodNanos* outVsyncPeriod) { |
| 920 | int32_t vsyncPeriod; |
| 921 | const auto status = |
| 922 | mAidlComposerClient->getDisplayVsyncPeriod(translate<int64_t>(display), &vsyncPeriod); |
| 923 | if (!status.isOk()) { |
| 924 | ALOGE("getDisplayVsyncPeriod failed %s", status.getDescription().c_str()); |
| 925 | return static_cast<V2_4::Error>(status.getServiceSpecificError()); |
| 926 | } |
| 927 | *outVsyncPeriod = translate<VsyncPeriodNanos>(vsyncPeriod); |
| 928 | return V2_4::Error::NONE; |
| 929 | } |
| 930 | |
| 931 | V2_4::Error AidlComposer::setActiveConfigWithConstraints( |
| 932 | Display display, Config config, |
| 933 | const IComposerClient::VsyncPeriodChangeConstraints& vsyncPeriodChangeConstraints, |
| 934 | VsyncPeriodChangeTimeline* outTimeline) { |
| 935 | AidlVsyncPeriodChangeTimeline timeline; |
| 936 | const auto status = |
| 937 | mAidlComposerClient |
| 938 | ->setActiveConfigWithConstraints(translate<int64_t>(display), |
| 939 | translate<int32_t>(config), |
| 940 | translate<AidlVsyncPeriodChangeConstraints>( |
| 941 | vsyncPeriodChangeConstraints), |
| 942 | &timeline); |
| 943 | if (!status.isOk()) { |
| 944 | ALOGE("setActiveConfigWithConstraints failed %s", status.getDescription().c_str()); |
| 945 | return static_cast<V2_4::Error>(status.getServiceSpecificError()); |
| 946 | } |
| 947 | *outTimeline = translate<VsyncPeriodChangeTimeline>(timeline); |
| 948 | return V2_4::Error::NONE; |
| 949 | } |
| 950 | |
| 951 | V2_4::Error AidlComposer::setAutoLowLatencyMode(Display display, bool on) { |
| 952 | const auto status = mAidlComposerClient->setAutoLowLatencyMode(translate<int64_t>(display), on); |
| 953 | if (!status.isOk()) { |
| 954 | ALOGE("setAutoLowLatencyMode failed %s", status.getDescription().c_str()); |
| 955 | return static_cast<V2_4::Error>(status.getServiceSpecificError()); |
| 956 | } |
| 957 | return V2_4::Error::NONE; |
| 958 | } |
| 959 | |
| 960 | V2_4::Error AidlComposer::getSupportedContentTypes( |
| 961 | Display displayId, std::vector<IComposerClient::ContentType>* outSupportedContentTypes) { |
| 962 | std::vector<AidlContentType> types; |
| 963 | const auto status = |
| 964 | mAidlComposerClient->getSupportedContentTypes(translate<int64_t>(displayId), &types); |
| 965 | if (!status.isOk()) { |
| 966 | ALOGE("getSupportedContentTypes failed %s", status.getDescription().c_str()); |
| 967 | return static_cast<V2_4::Error>(status.getServiceSpecificError()); |
| 968 | } |
| 969 | *outSupportedContentTypes = translate<IComposerClient::ContentType>(types); |
| 970 | return V2_4::Error::NONE; |
| 971 | } |
| 972 | |
| 973 | V2_4::Error AidlComposer::setContentType(Display display, |
| 974 | IComposerClient::ContentType contentType) { |
| 975 | const auto status = |
| 976 | mAidlComposerClient->setContentType(translate<int64_t>(display), |
| 977 | translate<AidlContentType>(contentType)); |
| 978 | if (!status.isOk()) { |
| 979 | ALOGE("setContentType failed %s", status.getDescription().c_str()); |
| 980 | return static_cast<V2_4::Error>(status.getServiceSpecificError()); |
| 981 | } |
| 982 | return V2_4::Error::NONE; |
| 983 | } |
| 984 | |
| 985 | V2_4::Error AidlComposer::setLayerGenericMetadata(Display display, Layer layer, |
| 986 | const std::string& key, bool mandatory, |
| 987 | const std::vector<uint8_t>& value) { |
Ady Abraham | a6388c0 | 2021-11-11 21:11:51 -0800 | [diff] [blame] | 988 | mWriter.setLayerGenericMetadata(translate<int64_t>(display), translate<int64_t>(layer), key, |
| 989 | mandatory, value); |
Ady Abraham | e7385f7 | 2021-09-05 00:54:25 -0700 | [diff] [blame] | 990 | return V2_4::Error::NONE; |
| 991 | } |
| 992 | |
| 993 | V2_4::Error AidlComposer::getLayerGenericMetadataKeys( |
| 994 | std::vector<IComposerClient::LayerGenericMetadataKey>* outKeys) { |
| 995 | std::vector<AidlLayerGenericMetadataKey> keys; |
| 996 | const auto status = mAidlComposerClient->getLayerGenericMetadataKeys(&keys); |
| 997 | if (!status.isOk()) { |
| 998 | ALOGE("getLayerGenericMetadataKeys failed %s", status.getDescription().c_str()); |
| 999 | return static_cast<V2_4::Error>(status.getServiceSpecificError()); |
| 1000 | } |
| 1001 | *outKeys = translate<IComposerClient::LayerGenericMetadataKey>(keys); |
| 1002 | return V2_4::Error::NONE; |
| 1003 | } |
| 1004 | |
| 1005 | Error AidlComposer::getClientTargetProperty( |
Alec Mouri | cdf6cbc | 2021-11-01 17:21:15 -0700 | [diff] [blame] | 1006 | Display display, IComposerClient::ClientTargetProperty* outClientTargetProperty, |
| 1007 | float* whitePointNits) { |
Ady Abraham | a6388c0 | 2021-11-11 21:11:51 -0800 | [diff] [blame] | 1008 | ClientTargetProperty property; |
Alec Mouri | cdf6cbc | 2021-11-01 17:21:15 -0700 | [diff] [blame] | 1009 | mReader.takeClientTargetProperty(translate<int64_t>(display), &property, whitePointNits); |
Ady Abraham | a6388c0 | 2021-11-11 21:11:51 -0800 | [diff] [blame] | 1010 | *outClientTargetProperty = translate<IComposerClient::ClientTargetProperty>(property); |
Ady Abraham | e7385f7 | 2021-09-05 00:54:25 -0700 | [diff] [blame] | 1011 | return Error::NONE; |
| 1012 | } |
| 1013 | |
Alec Mouri | cdf6cbc | 2021-11-01 17:21:15 -0700 | [diff] [blame] | 1014 | Error AidlComposer::setLayerWhitePointNits(Display display, Layer layer, float whitePointNits) { |
| 1015 | mWriter.setLayerWhitePointNits(translate<int64_t>(display), translate<int64_t>(layer), |
| 1016 | whitePointNits); |
| 1017 | return Error::NONE; |
| 1018 | } |
| 1019 | |
Ady Abraham | e7385f7 | 2021-09-05 00:54:25 -0700 | [diff] [blame] | 1020 | } // namespace Hwc2 |
| 1021 | } // namespace android |