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" |
Sally Qi | d57eb0d | 2023-11-07 16:46:15 -0800 | [diff] [blame] | 22 | #include "FlagManager.h" |
Ady Abraham | e7385f7 | 2021-09-05 00:54:25 -0700 | [diff] [blame] | 23 | |
Brian Lindahl | 5b0ffe0 | 2023-06-15 14:19:43 -0600 | [diff] [blame] | 24 | #include <SurfaceFlingerProperties.h> |
Ady Abraham | c4acf51 | 2022-02-18 17:11:59 -0800 | [diff] [blame] | 25 | #include <android-base/file.h> |
Ady Abraham | e7385f7 | 2021-09-05 00:54:25 -0700 | [diff] [blame] | 26 | #include <android/binder_ibinder_platform.h> |
| 27 | #include <android/binder_manager.h> |
Leon Scroggins III | e85e16e | 2022-12-12 12:51:18 -0500 | [diff] [blame] | 28 | #include <gui/TraceUtils.h> |
Ady Abraham | e7385f7 | 2021-09-05 00:54:25 -0700 | [diff] [blame] | 29 | #include <log/log.h> |
| 30 | #include <utils/Trace.h> |
| 31 | |
| 32 | #include <aidl/android/hardware/graphics/composer3/BnComposerCallback.h> |
| 33 | |
| 34 | #include <algorithm> |
| 35 | #include <cinttypes> |
| 36 | |
Yichi Chen | 3401b56 | 2022-01-17 15:42:35 +0800 | [diff] [blame] | 37 | #include "HWC2.h" |
| 38 | |
Ady Abraham | e7385f7 | 2021-09-05 00:54:25 -0700 | [diff] [blame] | 39 | namespace android { |
| 40 | |
| 41 | using hardware::hidl_handle; |
| 42 | using hardware::hidl_vec; |
| 43 | using hardware::Return; |
| 44 | |
| 45 | using aidl::android::hardware::graphics::composer3::BnComposerCallback; |
| 46 | using aidl::android::hardware::graphics::composer3::Capability; |
Alec Mouri | 8506569 | 2022-03-18 00:58:26 +0000 | [diff] [blame] | 47 | using aidl::android::hardware::graphics::composer3::ClientTargetPropertyWithBrightness; |
Ady Abraham | e7385f7 | 2021-09-05 00:54:25 -0700 | [diff] [blame] | 48 | using aidl::android::hardware::graphics::composer3::PowerMode; |
| 49 | using aidl::android::hardware::graphics::composer3::VirtualDisplay; |
| 50 | |
Ady Abraham | 4297736 | 2021-12-07 21:04:49 -0800 | [diff] [blame] | 51 | using aidl::android::hardware::graphics::composer3::CommandResultPayload; |
Ady Abraham | a6388c0 | 2021-11-11 21:11:51 -0800 | [diff] [blame] | 52 | |
Ady Abraham | e7385f7 | 2021-09-05 00:54:25 -0700 | [diff] [blame] | 53 | using AidlColorMode = aidl::android::hardware::graphics::composer3::ColorMode; |
| 54 | using AidlContentType = aidl::android::hardware::graphics::composer3::ContentType; |
| 55 | using AidlDisplayIdentification = |
| 56 | aidl::android::hardware::graphics::composer3::DisplayIdentification; |
| 57 | using AidlDisplayContentSample = aidl::android::hardware::graphics::composer3::DisplayContentSample; |
| 58 | using AidlDisplayAttribute = aidl::android::hardware::graphics::composer3::DisplayAttribute; |
| 59 | using AidlDisplayCapability = aidl::android::hardware::graphics::composer3::DisplayCapability; |
Ady Abraham | e7385f7 | 2021-09-05 00:54:25 -0700 | [diff] [blame] | 60 | using AidlHdrCapabilities = aidl::android::hardware::graphics::composer3::HdrCapabilities; |
Kriti Dang | 674b937 | 2022-11-18 10:58:44 +0100 | [diff] [blame] | 61 | using AidlHdrConversionCapability = |
| 62 | aidl::android::hardware::graphics::common::HdrConversionCapability; |
| 63 | using AidlHdrConversionStrategy = aidl::android::hardware::graphics::common::HdrConversionStrategy; |
Sally Qi | 0cbd08b | 2022-08-17 12:12:28 -0700 | [diff] [blame] | 64 | using AidlOverlayProperties = aidl::android::hardware::graphics::composer3::OverlayProperties; |
Ady Abraham | e7385f7 | 2021-09-05 00:54:25 -0700 | [diff] [blame] | 65 | using AidlPerFrameMetadata = aidl::android::hardware::graphics::composer3::PerFrameMetadata; |
| 66 | using AidlPerFrameMetadataKey = aidl::android::hardware::graphics::composer3::PerFrameMetadataKey; |
| 67 | using AidlPerFrameMetadataBlob = aidl::android::hardware::graphics::composer3::PerFrameMetadataBlob; |
| 68 | using AidlRenderIntent = aidl::android::hardware::graphics::composer3::RenderIntent; |
| 69 | using AidlVsyncPeriodChangeConstraints = |
| 70 | aidl::android::hardware::graphics::composer3::VsyncPeriodChangeConstraints; |
| 71 | using AidlVsyncPeriodChangeTimeline = |
| 72 | aidl::android::hardware::graphics::composer3::VsyncPeriodChangeTimeline; |
Ady Abraham | e7385f7 | 2021-09-05 00:54:25 -0700 | [diff] [blame] | 73 | using AidlDisplayContentSamplingAttributes = |
| 74 | aidl::android::hardware::graphics::composer3::DisplayContentSamplingAttributes; |
| 75 | using AidlFormatColorComponent = aidl::android::hardware::graphics::composer3::FormatColorComponent; |
| 76 | using AidlDisplayConnectionType = |
| 77 | aidl::android::hardware::graphics::composer3::DisplayConnectionType; |
Ady Abraham | e7385f7 | 2021-09-05 00:54:25 -0700 | [diff] [blame] | 78 | |
| 79 | using AidlColorTransform = aidl::android::hardware::graphics::common::ColorTransform; |
| 80 | using AidlDataspace = aidl::android::hardware::graphics::common::Dataspace; |
Huihong Luo | 791bef9 | 2023-09-19 21:18:45 -0700 | [diff] [blame^] | 81 | using AidlDisplayHotplugEvent = aidl::android::hardware::graphics::common::DisplayHotplugEvent; |
Ady Abraham | e7385f7 | 2021-09-05 00:54:25 -0700 | [diff] [blame] | 82 | using AidlFRect = aidl::android::hardware::graphics::common::FRect; |
| 83 | using AidlRect = aidl::android::hardware::graphics::common::Rect; |
| 84 | using AidlTransform = aidl::android::hardware::graphics::common::Transform; |
| 85 | |
| 86 | namespace Hwc2 { |
| 87 | |
| 88 | namespace { |
| 89 | |
| 90 | template <typename To, typename From> |
| 91 | To translate(From x) { |
| 92 | return static_cast<To>(x); |
| 93 | } |
| 94 | |
| 95 | template <typename To, typename From> |
| 96 | std::vector<To> translate(const std::vector<From>& in) { |
| 97 | std::vector<To> out; |
| 98 | out.reserve(in.size()); |
| 99 | std::transform(in.begin(), in.end(), std::back_inserter(out), |
| 100 | [](From x) { return translate<To>(x); }); |
| 101 | return out; |
| 102 | } |
| 103 | |
| 104 | template <> |
| 105 | AidlRect translate(IComposerClient::Rect x) { |
| 106 | return AidlRect{ |
| 107 | .left = x.left, |
| 108 | .top = x.top, |
| 109 | .right = x.right, |
| 110 | .bottom = x.bottom, |
| 111 | }; |
| 112 | } |
| 113 | |
| 114 | template <> |
| 115 | AidlFRect translate(IComposerClient::FRect x) { |
| 116 | return AidlFRect{ |
| 117 | .left = x.left, |
| 118 | .top = x.top, |
| 119 | .right = x.right, |
| 120 | .bottom = x.bottom, |
| 121 | }; |
| 122 | } |
| 123 | |
| 124 | template <> |
Ady Abraham | e7385f7 | 2021-09-05 00:54:25 -0700 | [diff] [blame] | 125 | AidlPerFrameMetadataBlob translate(IComposerClient::PerFrameMetadataBlob x) { |
| 126 | AidlPerFrameMetadataBlob blob; |
| 127 | blob.key = translate<AidlPerFrameMetadataKey>(x.key), |
Long Ling | a462878 | 2022-02-18 13:44:26 -0800 | [diff] [blame] | 128 | std::copy(x.blob.begin(), x.blob.end(), std::inserter(blob.blob, blob.blob.end())); |
Ady Abraham | e7385f7 | 2021-09-05 00:54:25 -0700 | [diff] [blame] | 129 | return blob; |
| 130 | } |
| 131 | |
| 132 | template <> |
| 133 | AidlPerFrameMetadata translate(IComposerClient::PerFrameMetadata x) { |
| 134 | return AidlPerFrameMetadata{ |
| 135 | .key = translate<AidlPerFrameMetadataKey>(x.key), |
| 136 | .value = x.value, |
| 137 | }; |
| 138 | } |
| 139 | |
| 140 | template <> |
| 141 | DisplayedFrameStats translate(AidlDisplayContentSample x) { |
| 142 | return DisplayedFrameStats{ |
| 143 | .numFrames = static_cast<uint64_t>(x.frameCount), |
| 144 | .component_0_sample = translate<uint64_t>(x.sampleComponent0), |
| 145 | .component_1_sample = translate<uint64_t>(x.sampleComponent1), |
| 146 | .component_2_sample = translate<uint64_t>(x.sampleComponent2), |
| 147 | .component_3_sample = translate<uint64_t>(x.sampleComponent3), |
| 148 | }; |
| 149 | } |
| 150 | |
| 151 | template <> |
| 152 | AidlVsyncPeriodChangeConstraints translate(IComposerClient::VsyncPeriodChangeConstraints x) { |
| 153 | return AidlVsyncPeriodChangeConstraints{ |
| 154 | .desiredTimeNanos = x.desiredTimeNanos, |
| 155 | .seamlessRequired = x.seamlessRequired, |
| 156 | }; |
| 157 | } |
| 158 | |
| 159 | template <> |
| 160 | VsyncPeriodChangeTimeline translate(AidlVsyncPeriodChangeTimeline x) { |
| 161 | return VsyncPeriodChangeTimeline{ |
| 162 | .newVsyncAppliedTimeNanos = x.newVsyncAppliedTimeNanos, |
| 163 | .refreshRequired = x.refreshRequired, |
| 164 | .refreshTimeNanos = x.refreshTimeNanos, |
| 165 | }; |
| 166 | } |
Ady Abraham | e7385f7 | 2021-09-05 00:54:25 -0700 | [diff] [blame] | 167 | mat4 makeMat4(std::vector<float> in) { |
| 168 | return mat4(static_cast<const float*>(in.data())); |
| 169 | } |
| 170 | |
| 171 | } // namespace |
| 172 | |
| 173 | class AidlIComposerCallbackWrapper : public BnComposerCallback { |
| 174 | public: |
Yichi Chen | 3401b56 | 2022-01-17 15:42:35 +0800 | [diff] [blame] | 175 | AidlIComposerCallbackWrapper(HWC2::ComposerCallback& callback) : mCallback(callback) {} |
Ady Abraham | e7385f7 | 2021-09-05 00:54:25 -0700 | [diff] [blame] | 176 | |
| 177 | ::ndk::ScopedAStatus onHotplug(int64_t in_display, bool in_connected) override { |
Huihong Luo | 791bef9 | 2023-09-19 21:18:45 -0700 | [diff] [blame^] | 178 | const auto event = in_connected ? AidlDisplayHotplugEvent::CONNECTED |
| 179 | : AidlDisplayHotplugEvent::DISCONNECTED; |
| 180 | mCallback.onComposerHalHotplugEvent(translate<Display>(in_display), event); |
Ady Abraham | e7385f7 | 2021-09-05 00:54:25 -0700 | [diff] [blame] | 181 | return ::ndk::ScopedAStatus::ok(); |
| 182 | } |
| 183 | |
| 184 | ::ndk::ScopedAStatus onRefresh(int64_t in_display) override { |
Yichi Chen | 3401b56 | 2022-01-17 15:42:35 +0800 | [diff] [blame] | 185 | mCallback.onComposerHalRefresh(translate<Display>(in_display)); |
Ady Abraham | e7385f7 | 2021-09-05 00:54:25 -0700 | [diff] [blame] | 186 | return ::ndk::ScopedAStatus::ok(); |
| 187 | } |
Yichi Chen | 3401b56 | 2022-01-17 15:42:35 +0800 | [diff] [blame] | 188 | |
Ady Abraham | e7385f7 | 2021-09-05 00:54:25 -0700 | [diff] [blame] | 189 | ::ndk::ScopedAStatus onSeamlessPossible(int64_t in_display) override { |
Yichi Chen | 3401b56 | 2022-01-17 15:42:35 +0800 | [diff] [blame] | 190 | mCallback.onComposerHalSeamlessPossible(translate<Display>(in_display)); |
Ady Abraham | e7385f7 | 2021-09-05 00:54:25 -0700 | [diff] [blame] | 191 | return ::ndk::ScopedAStatus::ok(); |
| 192 | } |
Yichi Chen | 3401b56 | 2022-01-17 15:42:35 +0800 | [diff] [blame] | 193 | |
Ady Abraham | e7385f7 | 2021-09-05 00:54:25 -0700 | [diff] [blame] | 194 | ::ndk::ScopedAStatus onVsync(int64_t in_display, int64_t in_timestamp, |
| 195 | int32_t in_vsyncPeriodNanos) override { |
Yichi Chen | 3401b56 | 2022-01-17 15:42:35 +0800 | [diff] [blame] | 196 | mCallback.onComposerHalVsync(translate<Display>(in_display), in_timestamp, |
| 197 | static_cast<uint32_t>(in_vsyncPeriodNanos)); |
Ady Abraham | e7385f7 | 2021-09-05 00:54:25 -0700 | [diff] [blame] | 198 | return ::ndk::ScopedAStatus::ok(); |
| 199 | } |
Yichi Chen | 3401b56 | 2022-01-17 15:42:35 +0800 | [diff] [blame] | 200 | |
Ady Abraham | e7385f7 | 2021-09-05 00:54:25 -0700 | [diff] [blame] | 201 | ::ndk::ScopedAStatus onVsyncPeriodTimingChanged( |
| 202 | int64_t in_display, const AidlVsyncPeriodChangeTimeline& in_updatedTimeline) override { |
Yichi Chen | 3401b56 | 2022-01-17 15:42:35 +0800 | [diff] [blame] | 203 | mCallback.onComposerHalVsyncPeriodTimingChanged(translate<Display>(in_display), |
| 204 | translate<V2_4::VsyncPeriodChangeTimeline>( |
| 205 | in_updatedTimeline)); |
| 206 | return ::ndk::ScopedAStatus::ok(); |
| 207 | } |
| 208 | |
| 209 | ::ndk::ScopedAStatus onVsyncIdle(int64_t in_display) override { |
| 210 | mCallback.onComposerHalVsyncIdle(translate<Display>(in_display)); |
Ady Abraham | e7385f7 | 2021-09-05 00:54:25 -0700 | [diff] [blame] | 211 | return ::ndk::ScopedAStatus::ok(); |
| 212 | } |
| 213 | |
ramindani | 12bfe6b | 2023-02-03 13:29:19 -0800 | [diff] [blame] | 214 | ::ndk::ScopedAStatus onRefreshRateChangedDebug( |
| 215 | const RefreshRateChangedDebugData& refreshRateChangedDebugData) override { |
| 216 | mCallback.onRefreshRateChangedDebug(refreshRateChangedDebugData); |
| 217 | return ::ndk::ScopedAStatus::ok(); |
| 218 | } |
| 219 | |
Huihong Luo | 791bef9 | 2023-09-19 21:18:45 -0700 | [diff] [blame^] | 220 | ::ndk::ScopedAStatus onHotplugEvent(int64_t in_display, |
| 221 | AidlDisplayHotplugEvent event) override { |
| 222 | mCallback.onComposerHalHotplugEvent(translate<Display>(in_display), event); |
| 223 | return ::ndk::ScopedAStatus::ok(); |
| 224 | } |
| 225 | |
Ady Abraham | e7385f7 | 2021-09-05 00:54:25 -0700 | [diff] [blame] | 226 | private: |
Yichi Chen | 3401b56 | 2022-01-17 15:42:35 +0800 | [diff] [blame] | 227 | HWC2::ComposerCallback& mCallback; |
Ady Abraham | e7385f7 | 2021-09-05 00:54:25 -0700 | [diff] [blame] | 228 | }; |
| 229 | |
Ady Abraham | 9fc2805 | 2021-10-14 17:21:38 -0700 | [diff] [blame] | 230 | std::string AidlComposer::instance(const std::string& serviceName) { |
| 231 | return std::string(AidlIComposer::descriptor) + "/" + serviceName; |
| 232 | } |
| 233 | |
| 234 | bool AidlComposer::isDeclared(const std::string& serviceName) { |
| 235 | return AServiceManager_isDeclared(instance(serviceName).c_str()); |
| 236 | } |
Ady Abraham | e7385f7 | 2021-09-05 00:54:25 -0700 | [diff] [blame] | 237 | |
Ady Abraham | a6388c0 | 2021-11-11 21:11:51 -0800 | [diff] [blame] | 238 | AidlComposer::AidlComposer(const std::string& serviceName) { |
Ady Abraham | e7385f7 | 2021-09-05 00:54:25 -0700 | [diff] [blame] | 239 | // This only waits if the service is actually declared |
Ady Abraham | 9fc2805 | 2021-10-14 17:21:38 -0700 | [diff] [blame] | 240 | mAidlComposer = AidlIComposer::fromBinder( |
| 241 | ndk::SpAIBinder(AServiceManager_waitForService(instance(serviceName).c_str()))); |
Ady Abraham | e7385f7 | 2021-09-05 00:54:25 -0700 | [diff] [blame] | 242 | if (!mAidlComposer) { |
| 243 | LOG_ALWAYS_FATAL("Failed to get AIDL composer service"); |
| 244 | return; |
| 245 | } |
| 246 | |
| 247 | if (!mAidlComposer->createClient(&mAidlComposerClient).isOk()) { |
| 248 | LOG_ALWAYS_FATAL("Can't create AidlComposerClient, fallback to HIDL"); |
| 249 | return; |
| 250 | } |
| 251 | |
Leon Scroggins III | e24d78f | 2022-09-20 16:38:19 -0400 | [diff] [blame] | 252 | addReader(translate<Display>(kSingleReaderKey)); |
| 253 | |
Brian Lindahl | dbf7e3a | 2022-12-16 11:43:39 -0700 | [diff] [blame] | 254 | // If unable to read interface version, then become backwards compatible. |
ramindani | 0cd1d8d | 2023-06-13 13:43:23 -0700 | [diff] [blame] | 255 | const auto status = mAidlComposerClient->getInterfaceVersion(&mComposerInterfaceVersion); |
Brian Lindahl | dbf7e3a | 2022-12-16 11:43:39 -0700 | [diff] [blame] | 256 | if (!status.isOk()) { |
| 257 | ALOGE("getInterfaceVersion for AidlComposer constructor failed %s", |
| 258 | status.getDescription().c_str()); |
| 259 | } |
ramindani | 0cd1d8d | 2023-06-13 13:43:23 -0700 | [diff] [blame] | 260 | |
| 261 | if (mComposerInterfaceVersion <= 1) { |
Brian Lindahl | 5b0ffe0 | 2023-06-15 14:19:43 -0600 | [diff] [blame] | 262 | if (sysprop::clear_slots_with_set_layer_buffer(false)) { |
| 263 | mClearSlotBuffer = sp<GraphicBuffer>::make(1, 1, PIXEL_FORMAT_RGBX_8888, |
| 264 | GraphicBuffer::USAGE_HW_COMPOSER | |
| 265 | GraphicBuffer::USAGE_SW_READ_OFTEN | |
| 266 | GraphicBuffer::USAGE_SW_WRITE_OFTEN, |
| 267 | "AidlComposer"); |
| 268 | if (!mClearSlotBuffer || mClearSlotBuffer->initCheck() != ::android::OK) { |
| 269 | LOG_ALWAYS_FATAL("Failed to allocate a buffer for clearing layer buffer slots"); |
| 270 | return; |
| 271 | } |
Brian Lindahl | dbf7e3a | 2022-12-16 11:43:39 -0700 | [diff] [blame] | 272 | } |
Brian Lindahl | 90553da | 2022-12-06 13:36:30 -0700 | [diff] [blame] | 273 | } |
| 274 | |
Ady Abraham | e7385f7 | 2021-09-05 00:54:25 -0700 | [diff] [blame] | 275 | ALOGI("Loaded AIDL composer3 HAL service"); |
| 276 | } |
| 277 | |
| 278 | AidlComposer::~AidlComposer() = default; |
| 279 | |
Ady Abraham | 4d211cf | 2021-12-14 16:19:03 -0800 | [diff] [blame] | 280 | bool AidlComposer::isSupported(OptionalFeature feature) const { |
| 281 | switch (feature) { |
| 282 | case OptionalFeature::RefreshRateSwitching: |
Ady Abraham | 43065bd | 2021-12-10 17:22:15 -0800 | [diff] [blame] | 283 | case OptionalFeature::ExpectedPresentTime: |
Alec Mouri | cdf1679 | 2021-12-10 13:16:06 -0800 | [diff] [blame] | 284 | case OptionalFeature::DisplayBrightnessCommand: |
ramindani | 32cf060 | 2022-03-02 02:30:29 +0000 | [diff] [blame] | 285 | case OptionalFeature::KernelIdleTimer: |
ramindani | 06e518e | 2022-03-14 18:47:53 +0000 | [diff] [blame] | 286 | case OptionalFeature::PhysicalDisplayOrientation: |
Ady Abraham | 4d211cf | 2021-12-14 16:19:03 -0800 | [diff] [blame] | 287 | return true; |
| 288 | } |
| 289 | } |
| 290 | |
ramindani | 0cd1d8d | 2023-06-13 13:43:23 -0700 | [diff] [blame] | 291 | bool AidlComposer::getDisplayConfigurationsSupported() const { |
Sally Qi | d57eb0d | 2023-11-07 16:46:15 -0800 | [diff] [blame] | 292 | return mComposerInterfaceVersion >= 3 && FlagManager::getInstance().vrr_config(); |
ramindani | 0cd1d8d | 2023-06-13 13:43:23 -0700 | [diff] [blame] | 293 | } |
| 294 | |
Ady Abraham | de549d4 | 2022-01-26 19:19:17 -0800 | [diff] [blame] | 295 | std::vector<Capability> AidlComposer::getCapabilities() { |
Ady Abraham | e7385f7 | 2021-09-05 00:54:25 -0700 | [diff] [blame] | 296 | std::vector<Capability> capabilities; |
| 297 | const auto status = mAidlComposer->getCapabilities(&capabilities); |
| 298 | if (!status.isOk()) { |
| 299 | ALOGE("getCapabilities failed %s", status.getDescription().c_str()); |
| 300 | return {}; |
| 301 | } |
Ady Abraham | de549d4 | 2022-01-26 19:19:17 -0800 | [diff] [blame] | 302 | return capabilities; |
Ady Abraham | e7385f7 | 2021-09-05 00:54:25 -0700 | [diff] [blame] | 303 | } |
| 304 | |
| 305 | std::string AidlComposer::dumpDebugInfo() { |
Ady Abraham | c4acf51 | 2022-02-18 17:11:59 -0800 | [diff] [blame] | 306 | int pipefds[2]; |
| 307 | int result = pipe(pipefds); |
| 308 | if (result < 0) { |
| 309 | ALOGE("dumpDebugInfo: pipe failed: %s", strerror(errno)); |
Ady Abraham | e7385f7 | 2021-09-05 00:54:25 -0700 | [diff] [blame] | 310 | return {}; |
| 311 | } |
Ady Abraham | c4acf51 | 2022-02-18 17:11:59 -0800 | [diff] [blame] | 312 | |
| 313 | std::string str; |
yihsing.shen | 58847c5 | 2022-09-23 15:39:30 +0800 | [diff] [blame] | 314 | // Use other thread to read pipe to prevent |
| 315 | // pipe is full, making HWC be blocked in writing. |
| 316 | std::thread t([&]() { |
| 317 | base::ReadFdToString(pipefds[0], &str); |
| 318 | }); |
Ady Abraham | c4acf51 | 2022-02-18 17:11:59 -0800 | [diff] [blame] | 319 | const auto status = mAidlComposer->dump(pipefds[1], /*args*/ nullptr, /*numArgs*/ 0); |
| 320 | // Close the write-end of the pipe to make sure that when reading from the |
| 321 | // read-end we will get eof instead of blocking forever |
| 322 | close(pipefds[1]); |
| 323 | |
yihsing.shen | 58847c5 | 2022-09-23 15:39:30 +0800 | [diff] [blame] | 324 | if (status != STATUS_OK) { |
Ady Abraham | c4acf51 | 2022-02-18 17:11:59 -0800 | [diff] [blame] | 325 | ALOGE("dumpDebugInfo: dump failed: %d", status); |
| 326 | } |
| 327 | |
yihsing.shen | 58847c5 | 2022-09-23 15:39:30 +0800 | [diff] [blame] | 328 | t.join(); |
Ady Abraham | c4acf51 | 2022-02-18 17:11:59 -0800 | [diff] [blame] | 329 | close(pipefds[0]); |
| 330 | return str; |
Ady Abraham | e7385f7 | 2021-09-05 00:54:25 -0700 | [diff] [blame] | 331 | } |
| 332 | |
Yichi Chen | 3401b56 | 2022-01-17 15:42:35 +0800 | [diff] [blame] | 333 | void AidlComposer::registerCallback(HWC2::ComposerCallback& callback) { |
Ady Abraham | e7385f7 | 2021-09-05 00:54:25 -0700 | [diff] [blame] | 334 | if (mAidlComposerCallback) { |
| 335 | ALOGE("Callback already registered"); |
| 336 | } |
Yichi Chen | 3401b56 | 2022-01-17 15:42:35 +0800 | [diff] [blame] | 337 | |
Ady Abraham | 9fc2805 | 2021-10-14 17:21:38 -0700 | [diff] [blame] | 338 | mAidlComposerCallback = ndk::SharedRefBase::make<AidlIComposerCallbackWrapper>(callback); |
Ady Abraham | e7385f7 | 2021-09-05 00:54:25 -0700 | [diff] [blame] | 339 | AIBinder_setMinSchedulerPolicy(mAidlComposerCallback->asBinder().get(), SCHED_FIFO, 2); |
| 340 | |
| 341 | const auto status = mAidlComposerClient->registerCallback(mAidlComposerCallback); |
| 342 | if (!status.isOk()) { |
| 343 | ALOGE("registerCallback failed %s", status.getDescription().c_str()); |
| 344 | } |
| 345 | } |
| 346 | |
Leon Scroggins III | e24d78f | 2022-09-20 16:38:19 -0400 | [diff] [blame] | 347 | Error AidlComposer::executeCommands(Display display) { |
| 348 | mMutex.lock_shared(); |
| 349 | auto error = execute(display); |
| 350 | mMutex.unlock_shared(); |
| 351 | return error; |
Ady Abraham | e7385f7 | 2021-09-05 00:54:25 -0700 | [diff] [blame] | 352 | } |
| 353 | |
| 354 | uint32_t AidlComposer::getMaxVirtualDisplayCount() { |
| 355 | int32_t count = 0; |
| 356 | const auto status = mAidlComposerClient->getMaxVirtualDisplayCount(&count); |
| 357 | if (!status.isOk()) { |
| 358 | ALOGE("getMaxVirtualDisplayCount failed %s", status.getDescription().c_str()); |
| 359 | return 0; |
| 360 | } |
| 361 | return static_cast<uint32_t>(count); |
| 362 | } |
| 363 | |
| 364 | Error AidlComposer::createVirtualDisplay(uint32_t width, uint32_t height, PixelFormat* format, |
| 365 | Display* outDisplay) { |
| 366 | using AidlPixelFormat = aidl::android::hardware::graphics::common::PixelFormat; |
| 367 | const int32_t bufferSlotCount = 1; |
| 368 | VirtualDisplay virtualDisplay; |
| 369 | const auto status = |
| 370 | mAidlComposerClient->createVirtualDisplay(static_cast<int32_t>(width), |
| 371 | static_cast<int32_t>(height), |
| 372 | static_cast<AidlPixelFormat>(*format), |
| 373 | bufferSlotCount, &virtualDisplay); |
| 374 | |
| 375 | if (!status.isOk()) { |
| 376 | ALOGE("createVirtualDisplay failed %s", status.getDescription().c_str()); |
| 377 | return static_cast<Error>(status.getServiceSpecificError()); |
| 378 | } |
| 379 | |
| 380 | *outDisplay = translate<Display>(virtualDisplay.display); |
| 381 | *format = static_cast<PixelFormat>(virtualDisplay.format); |
Leon Scroggins III | e24d78f | 2022-09-20 16:38:19 -0400 | [diff] [blame] | 382 | addDisplay(translate<Display>(virtualDisplay.display)); |
Ady Abraham | e7385f7 | 2021-09-05 00:54:25 -0700 | [diff] [blame] | 383 | return Error::NONE; |
| 384 | } |
| 385 | |
| 386 | Error AidlComposer::destroyVirtualDisplay(Display display) { |
| 387 | const auto status = mAidlComposerClient->destroyVirtualDisplay(translate<int64_t>(display)); |
| 388 | if (!status.isOk()) { |
| 389 | ALOGE("destroyVirtualDisplay failed %s", status.getDescription().c_str()); |
| 390 | return static_cast<Error>(status.getServiceSpecificError()); |
| 391 | } |
Leon Scroggins III | e24d78f | 2022-09-20 16:38:19 -0400 | [diff] [blame] | 392 | removeDisplay(display); |
Ady Abraham | e7385f7 | 2021-09-05 00:54:25 -0700 | [diff] [blame] | 393 | return Error::NONE; |
| 394 | } |
| 395 | |
| 396 | Error AidlComposer::acceptDisplayChanges(Display display) { |
Leon Scroggins III | e24d78f | 2022-09-20 16:38:19 -0400 | [diff] [blame] | 397 | Error error = Error::NONE; |
| 398 | mMutex.lock_shared(); |
| 399 | if (auto writer = getWriter(display)) { |
| 400 | writer->get().acceptDisplayChanges(translate<int64_t>(display)); |
| 401 | } else { |
| 402 | error = Error::BAD_DISPLAY; |
| 403 | } |
| 404 | mMutex.unlock_shared(); |
| 405 | return error; |
Ady Abraham | e7385f7 | 2021-09-05 00:54:25 -0700 | [diff] [blame] | 406 | } |
| 407 | |
| 408 | Error AidlComposer::createLayer(Display display, Layer* outLayer) { |
| 409 | int64_t layer; |
| 410 | const auto status = mAidlComposerClient->createLayer(translate<int64_t>(display), |
| 411 | kMaxLayerBufferCount, &layer); |
| 412 | if (!status.isOk()) { |
| 413 | ALOGE("createLayer failed %s", status.getDescription().c_str()); |
| 414 | return static_cast<Error>(status.getServiceSpecificError()); |
| 415 | } |
| 416 | |
| 417 | *outLayer = translate<Layer>(layer); |
| 418 | return Error::NONE; |
| 419 | } |
| 420 | |
| 421 | Error AidlComposer::destroyLayer(Display display, Layer layer) { |
| 422 | const auto status = mAidlComposerClient->destroyLayer(translate<int64_t>(display), |
| 423 | translate<int64_t>(layer)); |
| 424 | if (!status.isOk()) { |
| 425 | ALOGE("destroyLayer failed %s", status.getDescription().c_str()); |
| 426 | return static_cast<Error>(status.getServiceSpecificError()); |
| 427 | } |
| 428 | return Error::NONE; |
| 429 | } |
| 430 | |
| 431 | Error AidlComposer::getActiveConfig(Display display, Config* outConfig) { |
| 432 | int32_t config; |
| 433 | const auto status = mAidlComposerClient->getActiveConfig(translate<int64_t>(display), &config); |
| 434 | if (!status.isOk()) { |
| 435 | ALOGE("getActiveConfig failed %s", status.getDescription().c_str()); |
| 436 | return static_cast<Error>(status.getServiceSpecificError()); |
| 437 | } |
| 438 | *outConfig = translate<Config>(config); |
| 439 | return Error::NONE; |
| 440 | } |
| 441 | |
| 442 | Error AidlComposer::getChangedCompositionTypes( |
| 443 | Display display, std::vector<Layer>* outLayers, |
Leon Scroggins III | 2e1aa18 | 2021-12-01 17:33:12 -0500 | [diff] [blame] | 444 | std::vector<aidl::android::hardware::graphics::composer3::Composition>* outTypes) { |
Leon Scroggins III | e24d78f | 2022-09-20 16:38:19 -0400 | [diff] [blame] | 445 | std::vector<ChangedCompositionLayer> changedLayers; |
| 446 | Error error = Error::NONE; |
| 447 | { |
| 448 | mMutex.lock_shared(); |
| 449 | if (auto reader = getReader(display)) { |
| 450 | changedLayers = reader->get().takeChangedCompositionTypes(translate<int64_t>(display)); |
| 451 | } else { |
| 452 | error = Error::BAD_DISPLAY; |
| 453 | } |
| 454 | mMutex.unlock_shared(); |
| 455 | } |
Ady Abraham | de79278 | 2021-12-20 10:00:49 -0800 | [diff] [blame] | 456 | outLayers->reserve(changedLayers.size()); |
| 457 | outTypes->reserve(changedLayers.size()); |
Ady Abraham | a6388c0 | 2021-11-11 21:11:51 -0800 | [diff] [blame] | 458 | |
Ady Abraham | de79278 | 2021-12-20 10:00:49 -0800 | [diff] [blame] | 459 | for (const auto& layer : changedLayers) { |
| 460 | outLayers->emplace_back(translate<Layer>(layer.layer)); |
| 461 | outTypes->emplace_back(layer.composition); |
| 462 | } |
Leon Scroggins III | e24d78f | 2022-09-20 16:38:19 -0400 | [diff] [blame] | 463 | return error; |
Ady Abraham | e7385f7 | 2021-09-05 00:54:25 -0700 | [diff] [blame] | 464 | } |
| 465 | |
| 466 | Error AidlComposer::getColorModes(Display display, std::vector<ColorMode>* outModes) { |
| 467 | std::vector<AidlColorMode> modes; |
| 468 | const auto status = mAidlComposerClient->getColorModes(translate<int64_t>(display), &modes); |
| 469 | if (!status.isOk()) { |
| 470 | ALOGE("getColorModes failed %s", status.getDescription().c_str()); |
| 471 | return static_cast<Error>(status.getServiceSpecificError()); |
| 472 | } |
| 473 | *outModes = translate<ColorMode>(modes); |
| 474 | return Error::NONE; |
| 475 | } |
| 476 | |
| 477 | Error AidlComposer::getDisplayAttribute(Display display, Config config, |
| 478 | IComposerClient::Attribute attribute, int32_t* outValue) { |
| 479 | const auto status = |
| 480 | mAidlComposerClient->getDisplayAttribute(translate<int64_t>(display), |
| 481 | translate<int32_t>(config), |
| 482 | static_cast<AidlDisplayAttribute>(attribute), |
| 483 | outValue); |
| 484 | if (!status.isOk()) { |
| 485 | ALOGE("getDisplayAttribute failed %s", status.getDescription().c_str()); |
| 486 | return static_cast<Error>(status.getServiceSpecificError()); |
| 487 | } |
| 488 | return Error::NONE; |
| 489 | } |
| 490 | |
| 491 | Error AidlComposer::getDisplayConfigs(Display display, std::vector<Config>* outConfigs) { |
| 492 | std::vector<int32_t> configs; |
| 493 | const auto status = |
| 494 | mAidlComposerClient->getDisplayConfigs(translate<int64_t>(display), &configs); |
| 495 | if (!status.isOk()) { |
| 496 | ALOGE("getDisplayConfigs failed %s", status.getDescription().c_str()); |
| 497 | return static_cast<Error>(status.getServiceSpecificError()); |
| 498 | } |
| 499 | *outConfigs = translate<Config>(configs); |
| 500 | return Error::NONE; |
| 501 | } |
| 502 | |
ramindani | 263a3f1 | 2023-07-18 20:44:49 -0700 | [diff] [blame] | 503 | Error AidlComposer::getDisplayConfigurations(Display display, int32_t maxFrameIntervalNs, |
ramindani | 0cd1d8d | 2023-06-13 13:43:23 -0700 | [diff] [blame] | 504 | std::vector<DisplayConfiguration>* outConfigs) { |
| 505 | const auto status = |
ramindani | 263a3f1 | 2023-07-18 20:44:49 -0700 | [diff] [blame] | 506 | mAidlComposerClient->getDisplayConfigurations(translate<int64_t>(display), |
| 507 | maxFrameIntervalNs, outConfigs); |
ramindani | 0cd1d8d | 2023-06-13 13:43:23 -0700 | [diff] [blame] | 508 | if (!status.isOk()) { |
| 509 | ALOGE("getDisplayConfigurations failed %s", status.getDescription().c_str()); |
| 510 | return static_cast<Error>(status.getServiceSpecificError()); |
| 511 | } |
| 512 | |
| 513 | return Error::NONE; |
| 514 | } |
| 515 | |
Ady Abraham | e7385f7 | 2021-09-05 00:54:25 -0700 | [diff] [blame] | 516 | Error AidlComposer::getDisplayName(Display display, std::string* outName) { |
| 517 | const auto status = mAidlComposerClient->getDisplayName(translate<int64_t>(display), outName); |
| 518 | if (!status.isOk()) { |
| 519 | ALOGE("getDisplayName failed %s", status.getDescription().c_str()); |
| 520 | return static_cast<Error>(status.getServiceSpecificError()); |
| 521 | } |
| 522 | return Error::NONE; |
| 523 | } |
| 524 | |
| 525 | Error AidlComposer::getDisplayRequests(Display display, uint32_t* outDisplayRequestMask, |
| 526 | std::vector<Layer>* outLayers, |
| 527 | std::vector<uint32_t>* outLayerRequestMasks) { |
Leon Scroggins III | e24d78f | 2022-09-20 16:38:19 -0400 | [diff] [blame] | 528 | Error error = Error::NONE; |
| 529 | DisplayRequest displayRequests; |
| 530 | { |
| 531 | mMutex.lock_shared(); |
| 532 | if (auto reader = getReader(display)) { |
| 533 | displayRequests = reader->get().takeDisplayRequests(translate<int64_t>(display)); |
| 534 | } else { |
| 535 | error = Error::BAD_DISPLAY; |
| 536 | } |
| 537 | mMutex.unlock_shared(); |
| 538 | } |
Ady Abraham | de79278 | 2021-12-20 10:00:49 -0800 | [diff] [blame] | 539 | *outDisplayRequestMask = translate<uint32_t>(displayRequests.mask); |
| 540 | outLayers->reserve(displayRequests.layerRequests.size()); |
| 541 | outLayerRequestMasks->reserve(displayRequests.layerRequests.size()); |
| 542 | |
| 543 | for (const auto& layer : displayRequests.layerRequests) { |
| 544 | outLayers->emplace_back(translate<Layer>(layer.layer)); |
| 545 | outLayerRequestMasks->emplace_back(translate<uint32_t>(layer.mask)); |
| 546 | } |
Leon Scroggins III | e24d78f | 2022-09-20 16:38:19 -0400 | [diff] [blame] | 547 | return error; |
Ady Abraham | e7385f7 | 2021-09-05 00:54:25 -0700 | [diff] [blame] | 548 | } |
| 549 | |
| 550 | Error AidlComposer::getDozeSupport(Display display, bool* outSupport) { |
Ady Abraham | 33b92b9 | 2021-12-08 18:30:27 -0800 | [diff] [blame] | 551 | std::vector<AidlDisplayCapability> capabilities; |
Ady Abraham | e7385f7 | 2021-09-05 00:54:25 -0700 | [diff] [blame] | 552 | const auto status = |
Ady Abraham | 33b92b9 | 2021-12-08 18:30:27 -0800 | [diff] [blame] | 553 | mAidlComposerClient->getDisplayCapabilities(translate<int64_t>(display), &capabilities); |
Ady Abraham | e7385f7 | 2021-09-05 00:54:25 -0700 | [diff] [blame] | 554 | if (!status.isOk()) { |
Ady Abraham | 33b92b9 | 2021-12-08 18:30:27 -0800 | [diff] [blame] | 555 | ALOGE("getDisplayCapabilities failed %s", status.getDescription().c_str()); |
Ady Abraham | e7385f7 | 2021-09-05 00:54:25 -0700 | [diff] [blame] | 556 | return static_cast<Error>(status.getServiceSpecificError()); |
| 557 | } |
Ady Abraham | 33b92b9 | 2021-12-08 18:30:27 -0800 | [diff] [blame] | 558 | *outSupport = std::find(capabilities.begin(), capabilities.end(), |
| 559 | AidlDisplayCapability::DOZE) != capabilities.end(); |
Ady Abraham | e7385f7 | 2021-09-05 00:54:25 -0700 | [diff] [blame] | 560 | return Error::NONE; |
| 561 | } |
| 562 | |
ramindani | 32cf060 | 2022-03-02 02:30:29 +0000 | [diff] [blame] | 563 | Error AidlComposer::hasDisplayIdleTimerCapability(Display display, bool* outSupport) { |
| 564 | std::vector<AidlDisplayCapability> capabilities; |
| 565 | const auto status = |
| 566 | mAidlComposerClient->getDisplayCapabilities(translate<int64_t>(display), &capabilities); |
| 567 | if (!status.isOk()) { |
| 568 | ALOGE("getDisplayCapabilities failed %s", status.getDescription().c_str()); |
| 569 | return static_cast<Error>(status.getServiceSpecificError()); |
| 570 | } |
| 571 | *outSupport = std::find(capabilities.begin(), capabilities.end(), |
| 572 | AidlDisplayCapability::DISPLAY_IDLE_TIMER) != capabilities.end(); |
| 573 | return Error::NONE; |
| 574 | } |
| 575 | |
Ady Abraham | e7385f7 | 2021-09-05 00:54:25 -0700 | [diff] [blame] | 576 | Error AidlComposer::getHdrCapabilities(Display display, std::vector<Hdr>* outTypes, |
| 577 | float* outMaxLuminance, float* outMaxAverageLuminance, |
| 578 | float* outMinLuminance) { |
| 579 | AidlHdrCapabilities capabilities; |
| 580 | const auto status = |
| 581 | mAidlComposerClient->getHdrCapabilities(translate<int64_t>(display), &capabilities); |
| 582 | if (!status.isOk()) { |
| 583 | ALOGE("getHdrCapabilities failed %s", status.getDescription().c_str()); |
| 584 | return static_cast<Error>(status.getServiceSpecificError()); |
| 585 | } |
| 586 | |
Marc Kassis | bdf7e4b | 2022-11-04 17:26:48 +0100 | [diff] [blame] | 587 | *outTypes = capabilities.types; |
Ady Abraham | e7385f7 | 2021-09-05 00:54:25 -0700 | [diff] [blame] | 588 | *outMaxLuminance = capabilities.maxLuminance; |
| 589 | *outMaxAverageLuminance = capabilities.maxAverageLuminance; |
| 590 | *outMinLuminance = capabilities.minLuminance; |
| 591 | return Error::NONE; |
| 592 | } |
| 593 | |
Sally Qi | bb866c1 | 2022-10-17 11:31:20 -0700 | [diff] [blame] | 594 | Error AidlComposer::getOverlaySupport(AidlOverlayProperties* outProperties) { |
| 595 | const auto status = mAidlComposerClient->getOverlaySupport(outProperties); |
| 596 | if (!status.isOk()) { |
| 597 | ALOGE("getOverlaySupport failed %s", status.getDescription().c_str()); |
| 598 | return static_cast<Error>(status.getServiceSpecificError()); |
| 599 | } |
Sally Qi | 0cbd08b | 2022-08-17 12:12:28 -0700 | [diff] [blame] | 600 | return Error::NONE; |
| 601 | } |
| 602 | |
Ady Abraham | e7385f7 | 2021-09-05 00:54:25 -0700 | [diff] [blame] | 603 | Error AidlComposer::getReleaseFences(Display display, std::vector<Layer>* outLayers, |
| 604 | std::vector<int>* outReleaseFences) { |
Leon Scroggins III | e24d78f | 2022-09-20 16:38:19 -0400 | [diff] [blame] | 605 | Error error = Error::NONE; |
| 606 | std::vector<ReleaseFences::Layer> fences; |
| 607 | { |
| 608 | mMutex.lock_shared(); |
| 609 | if (auto reader = getReader(display)) { |
| 610 | fences = reader->get().takeReleaseFences(translate<int64_t>(display)); |
| 611 | } else { |
| 612 | error = Error::BAD_DISPLAY; |
| 613 | } |
| 614 | mMutex.unlock_shared(); |
| 615 | } |
Ady Abraham | de79278 | 2021-12-20 10:00:49 -0800 | [diff] [blame] | 616 | outLayers->reserve(fences.size()); |
| 617 | outReleaseFences->reserve(fences.size()); |
| 618 | |
| 619 | for (auto& fence : fences) { |
| 620 | outLayers->emplace_back(translate<Layer>(fence.layer)); |
| 621 | // take ownership |
| 622 | const int fenceOwner = fence.fence.get(); |
| 623 | *fence.fence.getR() = -1; |
| 624 | outReleaseFences->emplace_back(fenceOwner); |
| 625 | } |
Leon Scroggins III | e24d78f | 2022-09-20 16:38:19 -0400 | [diff] [blame] | 626 | return error; |
Ady Abraham | e7385f7 | 2021-09-05 00:54:25 -0700 | [diff] [blame] | 627 | } |
| 628 | |
| 629 | Error AidlComposer::presentDisplay(Display display, int* outPresentFence) { |
Leon Scroggins III | e85e16e | 2022-12-12 12:51:18 -0500 | [diff] [blame] | 630 | const auto displayId = translate<int64_t>(display); |
| 631 | ATRACE_FORMAT("HwcPresentDisplay %" PRId64, displayId); |
| 632 | |
Leon Scroggins III | e24d78f | 2022-09-20 16:38:19 -0400 | [diff] [blame] | 633 | Error error = Error::NONE; |
| 634 | mMutex.lock_shared(); |
| 635 | auto writer = getWriter(display); |
| 636 | auto reader = getReader(display); |
| 637 | if (writer && reader) { |
Leon Scroggins III | e85e16e | 2022-12-12 12:51:18 -0500 | [diff] [blame] | 638 | writer->get().presentDisplay(displayId); |
Leon Scroggins III | e24d78f | 2022-09-20 16:38:19 -0400 | [diff] [blame] | 639 | error = execute(display); |
| 640 | } else { |
| 641 | error = Error::BAD_DISPLAY; |
| 642 | } |
Ady Abraham | e7385f7 | 2021-09-05 00:54:25 -0700 | [diff] [blame] | 643 | |
Ady Abraham | e7385f7 | 2021-09-05 00:54:25 -0700 | [diff] [blame] | 644 | if (error != Error::NONE) { |
Leon Scroggins III | e24d78f | 2022-09-20 16:38:19 -0400 | [diff] [blame] | 645 | mMutex.unlock_shared(); |
Ady Abraham | e7385f7 | 2021-09-05 00:54:25 -0700 | [diff] [blame] | 646 | return error; |
| 647 | } |
| 648 | |
Leon Scroggins III | e85e16e | 2022-12-12 12:51:18 -0500 | [diff] [blame] | 649 | auto fence = reader->get().takePresentFence(displayId); |
Leon Scroggins III | e24d78f | 2022-09-20 16:38:19 -0400 | [diff] [blame] | 650 | mMutex.unlock_shared(); |
Ady Abraham | de79278 | 2021-12-20 10:00:49 -0800 | [diff] [blame] | 651 | // take ownership |
| 652 | *outPresentFence = fence.get(); |
| 653 | *fence.getR() = -1; |
Ady Abraham | e7385f7 | 2021-09-05 00:54:25 -0700 | [diff] [blame] | 654 | return Error::NONE; |
| 655 | } |
| 656 | |
| 657 | Error AidlComposer::setActiveConfig(Display display, Config config) { |
| 658 | const auto status = mAidlComposerClient->setActiveConfig(translate<int64_t>(display), |
| 659 | translate<int32_t>(config)); |
| 660 | if (!status.isOk()) { |
| 661 | ALOGE("setActiveConfig failed %s", status.getDescription().c_str()); |
| 662 | return static_cast<Error>(status.getServiceSpecificError()); |
| 663 | } |
| 664 | return Error::NONE; |
| 665 | } |
| 666 | |
| 667 | Error AidlComposer::setClientTarget(Display display, uint32_t slot, const sp<GraphicBuffer>& target, |
| 668 | int acquireFence, Dataspace dataspace, |
| 669 | const std::vector<IComposerClient::Rect>& damage) { |
Ady Abraham | e7385f7 | 2021-09-05 00:54:25 -0700 | [diff] [blame] | 670 | const native_handle_t* handle = nullptr; |
| 671 | if (target.get()) { |
| 672 | handle = target->getNativeBuffer()->handle; |
| 673 | } |
| 674 | |
Leon Scroggins III | e24d78f | 2022-09-20 16:38:19 -0400 | [diff] [blame] | 675 | Error error = Error::NONE; |
| 676 | mMutex.lock_shared(); |
| 677 | if (auto writer = getWriter(display)) { |
| 678 | writer->get() |
| 679 | .setClientTarget(translate<int64_t>(display), slot, handle, acquireFence, |
| 680 | translate<aidl::android::hardware::graphics::common::Dataspace>( |
| 681 | dataspace), |
| 682 | translate<AidlRect>(damage)); |
| 683 | } else { |
| 684 | error = Error::BAD_DISPLAY; |
| 685 | } |
| 686 | mMutex.unlock_shared(); |
| 687 | return error; |
Ady Abraham | e7385f7 | 2021-09-05 00:54:25 -0700 | [diff] [blame] | 688 | } |
| 689 | |
| 690 | Error AidlComposer::setColorMode(Display display, ColorMode mode, RenderIntent renderIntent) { |
| 691 | const auto status = |
| 692 | mAidlComposerClient->setColorMode(translate<int64_t>(display), |
| 693 | translate<AidlColorMode>(mode), |
| 694 | translate<AidlRenderIntent>(renderIntent)); |
| 695 | if (!status.isOk()) { |
| 696 | ALOGE("setColorMode failed %s", status.getDescription().c_str()); |
| 697 | return static_cast<Error>(status.getServiceSpecificError()); |
| 698 | } |
| 699 | return Error::NONE; |
| 700 | } |
| 701 | |
Ady Abraham | dc011a9 | 2021-12-21 14:06:44 -0800 | [diff] [blame] | 702 | Error AidlComposer::setColorTransform(Display display, const float* matrix) { |
Leon Scroggins III | e24d78f | 2022-09-20 16:38:19 -0400 | [diff] [blame] | 703 | auto error = Error::NONE; |
| 704 | mMutex.lock_shared(); |
| 705 | if (auto writer = getWriter(display)) { |
| 706 | writer->get().setColorTransform(translate<int64_t>(display), matrix); |
| 707 | } else { |
| 708 | error = Error::BAD_DISPLAY; |
| 709 | } |
| 710 | mMutex.unlock_shared(); |
| 711 | return error; |
Ady Abraham | e7385f7 | 2021-09-05 00:54:25 -0700 | [diff] [blame] | 712 | } |
| 713 | |
| 714 | Error AidlComposer::setOutputBuffer(Display display, const native_handle_t* buffer, |
| 715 | int releaseFence) { |
Leon Scroggins III | e24d78f | 2022-09-20 16:38:19 -0400 | [diff] [blame] | 716 | auto error = Error::NONE; |
| 717 | mMutex.lock_shared(); |
| 718 | if (auto writer = getWriter(display)) { |
| 719 | writer->get().setOutputBuffer(translate<int64_t>(display), 0, buffer, dup(releaseFence)); |
| 720 | } else { |
| 721 | error = Error::BAD_DISPLAY; |
| 722 | } |
| 723 | mMutex.unlock_shared(); |
| 724 | return error; |
Ady Abraham | e7385f7 | 2021-09-05 00:54:25 -0700 | [diff] [blame] | 725 | } |
| 726 | |
| 727 | Error AidlComposer::setPowerMode(Display display, IComposerClient::PowerMode mode) { |
| 728 | const auto status = mAidlComposerClient->setPowerMode(translate<int64_t>(display), |
| 729 | translate<PowerMode>(mode)); |
| 730 | if (!status.isOk()) { |
| 731 | ALOGE("setPowerMode failed %s", status.getDescription().c_str()); |
| 732 | return static_cast<Error>(status.getServiceSpecificError()); |
| 733 | } |
| 734 | return Error::NONE; |
| 735 | } |
| 736 | |
| 737 | Error AidlComposer::setVsyncEnabled(Display display, IComposerClient::Vsync enabled) { |
| 738 | const bool enableVsync = enabled == IComposerClient::Vsync::ENABLE; |
| 739 | const auto status = |
| 740 | mAidlComposerClient->setVsyncEnabled(translate<int64_t>(display), enableVsync); |
| 741 | if (!status.isOk()) { |
| 742 | ALOGE("setVsyncEnabled failed %s", status.getDescription().c_str()); |
| 743 | return static_cast<Error>(status.getServiceSpecificError()); |
| 744 | } |
| 745 | return Error::NONE; |
| 746 | } |
| 747 | |
| 748 | Error AidlComposer::setClientTargetSlotCount(Display display) { |
| 749 | const int32_t bufferSlotCount = BufferQueue::NUM_BUFFER_SLOTS; |
| 750 | const auto status = mAidlComposerClient->setClientTargetSlotCount(translate<int64_t>(display), |
| 751 | bufferSlotCount); |
| 752 | if (!status.isOk()) { |
| 753 | ALOGE("setClientTargetSlotCount failed %s", status.getDescription().c_str()); |
| 754 | return static_cast<Error>(status.getServiceSpecificError()); |
| 755 | } |
| 756 | return Error::NONE; |
| 757 | } |
| 758 | |
Ady Abraham | 43065bd | 2021-12-10 17:22:15 -0800 | [diff] [blame] | 759 | Error AidlComposer::validateDisplay(Display display, nsecs_t expectedPresentTime, |
ramindani | 09acbb8 | 2023-11-03 09:02:38 -0700 | [diff] [blame] | 760 | int32_t frameIntervalNs, uint32_t* outNumTypes, |
| 761 | uint32_t* outNumRequests) { |
Leon Scroggins III | e24d78f | 2022-09-20 16:38:19 -0400 | [diff] [blame] | 762 | const auto displayId = translate<int64_t>(display); |
Leon Scroggins III | e85e16e | 2022-12-12 12:51:18 -0500 | [diff] [blame] | 763 | ATRACE_FORMAT("HwcValidateDisplay %" PRId64, displayId); |
| 764 | |
Leon Scroggins III | e24d78f | 2022-09-20 16:38:19 -0400 | [diff] [blame] | 765 | Error error = Error::NONE; |
| 766 | mMutex.lock_shared(); |
| 767 | auto writer = getWriter(display); |
| 768 | auto reader = getReader(display); |
| 769 | if (writer && reader) { |
ramindani | 09acbb8 | 2023-11-03 09:02:38 -0700 | [diff] [blame] | 770 | writer->get().validateDisplay(displayId, ClockMonotonicTimestamp{expectedPresentTime}, |
| 771 | frameIntervalNs); |
Leon Scroggins III | e24d78f | 2022-09-20 16:38:19 -0400 | [diff] [blame] | 772 | error = execute(display); |
| 773 | } else { |
| 774 | error = Error::BAD_DISPLAY; |
| 775 | } |
Ady Abraham | e7385f7 | 2021-09-05 00:54:25 -0700 | [diff] [blame] | 776 | |
Ady Abraham | e7385f7 | 2021-09-05 00:54:25 -0700 | [diff] [blame] | 777 | if (error != Error::NONE) { |
Leon Scroggins III | e24d78f | 2022-09-20 16:38:19 -0400 | [diff] [blame] | 778 | mMutex.unlock_shared(); |
Ady Abraham | e7385f7 | 2021-09-05 00:54:25 -0700 | [diff] [blame] | 779 | return error; |
| 780 | } |
| 781 | |
Leon Scroggins III | e24d78f | 2022-09-20 16:38:19 -0400 | [diff] [blame] | 782 | reader->get().hasChanges(displayId, outNumTypes, outNumRequests); |
Ady Abraham | e7385f7 | 2021-09-05 00:54:25 -0700 | [diff] [blame] | 783 | |
Leon Scroggins III | e24d78f | 2022-09-20 16:38:19 -0400 | [diff] [blame] | 784 | mMutex.unlock_shared(); |
Ady Abraham | e7385f7 | 2021-09-05 00:54:25 -0700 | [diff] [blame] | 785 | return Error::NONE; |
| 786 | } |
| 787 | |
Ady Abraham | 43065bd | 2021-12-10 17:22:15 -0800 | [diff] [blame] | 788 | Error AidlComposer::presentOrValidateDisplay(Display display, nsecs_t expectedPresentTime, |
ramindani | 4aac32c | 2023-10-30 14:13:30 -0700 | [diff] [blame] | 789 | int32_t frameIntervalNs, uint32_t* outNumTypes, |
| 790 | uint32_t* outNumRequests, int* outPresentFence, |
| 791 | uint32_t* state) { |
Leon Scroggins III | e24d78f | 2022-09-20 16:38:19 -0400 | [diff] [blame] | 792 | const auto displayId = translate<int64_t>(display); |
Leon Scroggins III | e85e16e | 2022-12-12 12:51:18 -0500 | [diff] [blame] | 793 | ATRACE_FORMAT("HwcPresentOrValidateDisplay %" PRId64, displayId); |
| 794 | |
Leon Scroggins III | e24d78f | 2022-09-20 16:38:19 -0400 | [diff] [blame] | 795 | Error error = Error::NONE; |
| 796 | mMutex.lock_shared(); |
| 797 | auto writer = getWriter(display); |
| 798 | auto reader = getReader(display); |
| 799 | if (writer && reader) { |
| 800 | writer->get().presentOrvalidateDisplay(displayId, |
ramindani | 4aac32c | 2023-10-30 14:13:30 -0700 | [diff] [blame] | 801 | ClockMonotonicTimestamp{expectedPresentTime}, |
| 802 | frameIntervalNs); |
Leon Scroggins III | e24d78f | 2022-09-20 16:38:19 -0400 | [diff] [blame] | 803 | error = execute(display); |
| 804 | } else { |
| 805 | error = Error::BAD_DISPLAY; |
| 806 | } |
Ady Abraham | e7385f7 | 2021-09-05 00:54:25 -0700 | [diff] [blame] | 807 | |
Ady Abraham | e7385f7 | 2021-09-05 00:54:25 -0700 | [diff] [blame] | 808 | if (error != Error::NONE) { |
Leon Scroggins III | e24d78f | 2022-09-20 16:38:19 -0400 | [diff] [blame] | 809 | mMutex.unlock_shared(); |
Ady Abraham | e7385f7 | 2021-09-05 00:54:25 -0700 | [diff] [blame] | 810 | return error; |
| 811 | } |
| 812 | |
Leon Scroggins III | e24d78f | 2022-09-20 16:38:19 -0400 | [diff] [blame] | 813 | const auto result = reader->get().takePresentOrValidateStage(displayId); |
Ady Abraham | de79278 | 2021-12-20 10:00:49 -0800 | [diff] [blame] | 814 | if (!result.has_value()) { |
| 815 | *state = translate<uint32_t>(-1); |
Leon Scroggins III | e24d78f | 2022-09-20 16:38:19 -0400 | [diff] [blame] | 816 | mMutex.unlock_shared(); |
Ady Abraham | de79278 | 2021-12-20 10:00:49 -0800 | [diff] [blame] | 817 | return Error::NO_RESOURCES; |
Ady Abraham | e7385f7 | 2021-09-05 00:54:25 -0700 | [diff] [blame] | 818 | } |
| 819 | |
Ady Abraham | de79278 | 2021-12-20 10:00:49 -0800 | [diff] [blame] | 820 | *state = translate<uint32_t>(*result); |
| 821 | |
| 822 | if (*result == PresentOrValidate::Result::Presented) { |
Leon Scroggins III | e24d78f | 2022-09-20 16:38:19 -0400 | [diff] [blame] | 823 | auto fence = reader->get().takePresentFence(displayId); |
Ady Abraham | de79278 | 2021-12-20 10:00:49 -0800 | [diff] [blame] | 824 | // take ownership |
| 825 | *outPresentFence = fence.get(); |
| 826 | *fence.getR() = -1; |
| 827 | } |
| 828 | |
| 829 | if (*result == PresentOrValidate::Result::Validated) { |
Leon Scroggins III | e24d78f | 2022-09-20 16:38:19 -0400 | [diff] [blame] | 830 | reader->get().hasChanges(displayId, outNumTypes, outNumRequests); |
Ady Abraham | e7385f7 | 2021-09-05 00:54:25 -0700 | [diff] [blame] | 831 | } |
| 832 | |
Leon Scroggins III | e24d78f | 2022-09-20 16:38:19 -0400 | [diff] [blame] | 833 | mMutex.unlock_shared(); |
Ady Abraham | e7385f7 | 2021-09-05 00:54:25 -0700 | [diff] [blame] | 834 | return Error::NONE; |
| 835 | } |
| 836 | |
| 837 | Error AidlComposer::setCursorPosition(Display display, Layer layer, int32_t x, int32_t y) { |
Leon Scroggins III | e24d78f | 2022-09-20 16:38:19 -0400 | [diff] [blame] | 838 | Error error = Error::NONE; |
| 839 | mMutex.lock_shared(); |
| 840 | if (auto writer = getWriter(display)) { |
| 841 | writer->get().setLayerCursorPosition(translate<int64_t>(display), translate<int64_t>(layer), |
| 842 | x, y); |
| 843 | } else { |
| 844 | error = Error::BAD_DISPLAY; |
| 845 | } |
| 846 | mMutex.unlock_shared(); |
| 847 | return error; |
Ady Abraham | e7385f7 | 2021-09-05 00:54:25 -0700 | [diff] [blame] | 848 | } |
| 849 | |
| 850 | Error AidlComposer::setLayerBuffer(Display display, Layer layer, uint32_t slot, |
| 851 | const sp<GraphicBuffer>& buffer, int acquireFence) { |
Ady Abraham | e7385f7 | 2021-09-05 00:54:25 -0700 | [diff] [blame] | 852 | const native_handle_t* handle = nullptr; |
| 853 | if (buffer.get()) { |
| 854 | handle = buffer->getNativeBuffer()->handle; |
| 855 | } |
| 856 | |
Leon Scroggins III | e24d78f | 2022-09-20 16:38:19 -0400 | [diff] [blame] | 857 | Error error = Error::NONE; |
| 858 | mMutex.lock_shared(); |
| 859 | if (auto writer = getWriter(display)) { |
| 860 | writer->get().setLayerBuffer(translate<int64_t>(display), translate<int64_t>(layer), slot, |
| 861 | handle, acquireFence); |
| 862 | } else { |
| 863 | error = Error::BAD_DISPLAY; |
| 864 | } |
| 865 | mMutex.unlock_shared(); |
| 866 | return error; |
Ady Abraham | e7385f7 | 2021-09-05 00:54:25 -0700 | [diff] [blame] | 867 | } |
| 868 | |
Brian Lindahl | b158a5c | 2022-12-15 15:21:13 -0700 | [diff] [blame] | 869 | Error AidlComposer::setLayerBufferSlotsToClear(Display display, Layer layer, |
| 870 | const std::vector<uint32_t>& slotsToClear, |
| 871 | uint32_t activeBufferSlot) { |
| 872 | if (slotsToClear.empty()) { |
| 873 | return Error::NONE; |
| 874 | } |
| 875 | |
Brian Lindahl | 90553da | 2022-12-06 13:36:30 -0700 | [diff] [blame] | 876 | Error error = Error::NONE; |
| 877 | mMutex.lock_shared(); |
| 878 | if (auto writer = getWriter(display)) { |
ramindani | 0cd1d8d | 2023-06-13 13:43:23 -0700 | [diff] [blame] | 879 | if (mComposerInterfaceVersion > 1) { |
Brian Lindahl | dbf7e3a | 2022-12-16 11:43:39 -0700 | [diff] [blame] | 880 | writer->get().setLayerBufferSlotsToClear(translate<int64_t>(display), |
| 881 | translate<int64_t>(layer), slotsToClear); |
Brian Lindahl | 5b0ffe0 | 2023-06-15 14:19:43 -0600 | [diff] [blame] | 882 | // Backwards compatible way of clearing buffer slots is to set the layer buffer with a |
| 883 | // placeholder buffer, using the slot that needs to cleared... tricky. |
| 884 | } else if (mClearSlotBuffer != nullptr) { |
Brian Lindahl | dbf7e3a | 2022-12-16 11:43:39 -0700 | [diff] [blame] | 885 | for (uint32_t slot : slotsToClear) { |
| 886 | // Don't clear the active buffer slot because we need to restore the active buffer |
| 887 | // after clearing the requested buffer slots with a placeholder buffer. |
| 888 | if (slot != activeBufferSlot) { |
| 889 | writer->get().setLayerBufferWithNewCommand(translate<int64_t>(display), |
| 890 | translate<int64_t>(layer), slot, |
| 891 | mClearSlotBuffer->handle, |
| 892 | /*fence*/ -1); |
| 893 | } |
Brian Lindahl | b158a5c | 2022-12-15 15:21:13 -0700 | [diff] [blame] | 894 | } |
Brian Lindahl | dbf7e3a | 2022-12-16 11:43:39 -0700 | [diff] [blame] | 895 | // Since we clear buffers by setting them to a placeholder buffer, we want to make |
| 896 | // sure that the last setLayerBuffer command is sent with the currently active |
| 897 | // buffer, not the placeholder buffer, so that there is no perceptual change when |
| 898 | // buffers are discarded. |
| 899 | writer->get().setLayerBufferWithNewCommand(translate<int64_t>(display), |
| 900 | translate<int64_t>(layer), activeBufferSlot, |
| 901 | // The active buffer is still cached in |
| 902 | // its slot and doesn't need a fence. |
| 903 | /*buffer*/ nullptr, /*fence*/ -1); |
Brian Lindahl | b158a5c | 2022-12-15 15:21:13 -0700 | [diff] [blame] | 904 | } |
Brian Lindahl | 90553da | 2022-12-06 13:36:30 -0700 | [diff] [blame] | 905 | } else { |
| 906 | error = Error::BAD_DISPLAY; |
| 907 | } |
| 908 | mMutex.unlock_shared(); |
| 909 | return error; |
| 910 | } |
| 911 | |
Ady Abraham | e7385f7 | 2021-09-05 00:54:25 -0700 | [diff] [blame] | 912 | Error AidlComposer::setLayerSurfaceDamage(Display display, Layer layer, |
| 913 | const std::vector<IComposerClient::Rect>& damage) { |
Leon Scroggins III | e24d78f | 2022-09-20 16:38:19 -0400 | [diff] [blame] | 914 | Error error = Error::NONE; |
| 915 | mMutex.lock_shared(); |
| 916 | if (auto writer = getWriter(display)) { |
| 917 | writer->get().setLayerSurfaceDamage(translate<int64_t>(display), translate<int64_t>(layer), |
| 918 | translate<AidlRect>(damage)); |
| 919 | } else { |
| 920 | error = Error::BAD_DISPLAY; |
| 921 | } |
| 922 | mMutex.unlock_shared(); |
| 923 | return error; |
Ady Abraham | e7385f7 | 2021-09-05 00:54:25 -0700 | [diff] [blame] | 924 | } |
| 925 | |
| 926 | Error AidlComposer::setLayerBlendMode(Display display, Layer layer, |
| 927 | IComposerClient::BlendMode mode) { |
Leon Scroggins III | e24d78f | 2022-09-20 16:38:19 -0400 | [diff] [blame] | 928 | Error error = Error::NONE; |
| 929 | mMutex.lock_shared(); |
| 930 | if (auto writer = getWriter(display)) { |
| 931 | writer->get().setLayerBlendMode(translate<int64_t>(display), translate<int64_t>(layer), |
| 932 | translate<BlendMode>(mode)); |
| 933 | } else { |
| 934 | error = Error::BAD_DISPLAY; |
| 935 | } |
| 936 | mMutex.unlock_shared(); |
| 937 | return error; |
Ady Abraham | e7385f7 | 2021-09-05 00:54:25 -0700 | [diff] [blame] | 938 | } |
| 939 | |
Ady Abraham | 6e60b14 | 2022-01-06 18:10:35 -0800 | [diff] [blame] | 940 | Error AidlComposer::setLayerColor(Display display, Layer layer, const Color& color) { |
Leon Scroggins III | e24d78f | 2022-09-20 16:38:19 -0400 | [diff] [blame] | 941 | Error error = Error::NONE; |
| 942 | mMutex.lock_shared(); |
| 943 | if (auto writer = getWriter(display)) { |
| 944 | writer->get().setLayerColor(translate<int64_t>(display), translate<int64_t>(layer), color); |
| 945 | } else { |
| 946 | error = Error::BAD_DISPLAY; |
| 947 | } |
| 948 | mMutex.unlock_shared(); |
| 949 | return error; |
Ady Abraham | e7385f7 | 2021-09-05 00:54:25 -0700 | [diff] [blame] | 950 | } |
| 951 | |
Leon Scroggins III | 2e1aa18 | 2021-12-01 17:33:12 -0500 | [diff] [blame] | 952 | Error AidlComposer::setLayerCompositionType( |
| 953 | Display display, Layer layer, |
| 954 | aidl::android::hardware::graphics::composer3::Composition type) { |
Leon Scroggins III | e24d78f | 2022-09-20 16:38:19 -0400 | [diff] [blame] | 955 | Error error = Error::NONE; |
| 956 | mMutex.lock_shared(); |
| 957 | if (auto writer = getWriter(display)) { |
| 958 | writer->get().setLayerCompositionType(translate<int64_t>(display), |
| 959 | translate<int64_t>(layer), type); |
| 960 | } else { |
| 961 | error = Error::BAD_DISPLAY; |
| 962 | } |
| 963 | mMutex.unlock_shared(); |
| 964 | return error; |
Ady Abraham | e7385f7 | 2021-09-05 00:54:25 -0700 | [diff] [blame] | 965 | } |
| 966 | |
| 967 | Error AidlComposer::setLayerDataspace(Display display, Layer layer, Dataspace dataspace) { |
Leon Scroggins III | e24d78f | 2022-09-20 16:38:19 -0400 | [diff] [blame] | 968 | Error error = Error::NONE; |
| 969 | mMutex.lock_shared(); |
| 970 | if (auto writer = getWriter(display)) { |
| 971 | writer->get().setLayerDataspace(translate<int64_t>(display), translate<int64_t>(layer), |
| 972 | translate<AidlDataspace>(dataspace)); |
| 973 | } else { |
| 974 | error = Error::BAD_DISPLAY; |
| 975 | } |
| 976 | mMutex.unlock_shared(); |
| 977 | return error; |
Ady Abraham | e7385f7 | 2021-09-05 00:54:25 -0700 | [diff] [blame] | 978 | } |
| 979 | |
| 980 | Error AidlComposer::setLayerDisplayFrame(Display display, Layer layer, |
| 981 | const IComposerClient::Rect& frame) { |
Leon Scroggins III | e24d78f | 2022-09-20 16:38:19 -0400 | [diff] [blame] | 982 | Error error = Error::NONE; |
| 983 | mMutex.lock_shared(); |
| 984 | if (auto writer = getWriter(display)) { |
| 985 | writer->get().setLayerDisplayFrame(translate<int64_t>(display), translate<int64_t>(layer), |
| 986 | translate<AidlRect>(frame)); |
| 987 | } else { |
| 988 | error = Error::BAD_DISPLAY; |
| 989 | } |
| 990 | mMutex.unlock_shared(); |
| 991 | return error; |
Ady Abraham | e7385f7 | 2021-09-05 00:54:25 -0700 | [diff] [blame] | 992 | } |
| 993 | |
| 994 | Error AidlComposer::setLayerPlaneAlpha(Display display, Layer layer, float alpha) { |
Leon Scroggins III | e24d78f | 2022-09-20 16:38:19 -0400 | [diff] [blame] | 995 | Error error = Error::NONE; |
| 996 | mMutex.lock_shared(); |
| 997 | if (auto writer = getWriter(display)) { |
| 998 | writer->get().setLayerPlaneAlpha(translate<int64_t>(display), translate<int64_t>(layer), |
| 999 | alpha); |
| 1000 | } else { |
| 1001 | error = Error::BAD_DISPLAY; |
| 1002 | } |
| 1003 | mMutex.unlock_shared(); |
| 1004 | return error; |
Ady Abraham | e7385f7 | 2021-09-05 00:54:25 -0700 | [diff] [blame] | 1005 | } |
| 1006 | |
| 1007 | Error AidlComposer::setLayerSidebandStream(Display display, Layer layer, |
| 1008 | const native_handle_t* stream) { |
Leon Scroggins III | e24d78f | 2022-09-20 16:38:19 -0400 | [diff] [blame] | 1009 | Error error = Error::NONE; |
| 1010 | mMutex.lock_shared(); |
| 1011 | if (auto writer = getWriter(display)) { |
| 1012 | writer->get().setLayerSidebandStream(translate<int64_t>(display), translate<int64_t>(layer), |
| 1013 | stream); |
| 1014 | } else { |
| 1015 | error = Error::BAD_DISPLAY; |
| 1016 | } |
| 1017 | mMutex.unlock_shared(); |
| 1018 | return error; |
Ady Abraham | e7385f7 | 2021-09-05 00:54:25 -0700 | [diff] [blame] | 1019 | } |
| 1020 | |
| 1021 | Error AidlComposer::setLayerSourceCrop(Display display, Layer layer, |
| 1022 | const IComposerClient::FRect& crop) { |
Leon Scroggins III | e24d78f | 2022-09-20 16:38:19 -0400 | [diff] [blame] | 1023 | Error error = Error::NONE; |
| 1024 | mMutex.lock_shared(); |
| 1025 | if (auto writer = getWriter(display)) { |
| 1026 | writer->get().setLayerSourceCrop(translate<int64_t>(display), translate<int64_t>(layer), |
| 1027 | translate<AidlFRect>(crop)); |
| 1028 | } else { |
| 1029 | error = Error::BAD_DISPLAY; |
| 1030 | } |
| 1031 | mMutex.unlock_shared(); |
| 1032 | return error; |
Ady Abraham | e7385f7 | 2021-09-05 00:54:25 -0700 | [diff] [blame] | 1033 | } |
| 1034 | |
| 1035 | Error AidlComposer::setLayerTransform(Display display, Layer layer, Transform transform) { |
Leon Scroggins III | e24d78f | 2022-09-20 16:38:19 -0400 | [diff] [blame] | 1036 | Error error = Error::NONE; |
| 1037 | mMutex.lock_shared(); |
| 1038 | if (auto writer = getWriter(display)) { |
| 1039 | writer->get().setLayerTransform(translate<int64_t>(display), translate<int64_t>(layer), |
| 1040 | translate<AidlTransform>(transform)); |
| 1041 | } else { |
| 1042 | error = Error::BAD_DISPLAY; |
| 1043 | } |
| 1044 | mMutex.unlock_shared(); |
| 1045 | return error; |
Ady Abraham | e7385f7 | 2021-09-05 00:54:25 -0700 | [diff] [blame] | 1046 | } |
| 1047 | |
| 1048 | Error AidlComposer::setLayerVisibleRegion(Display display, Layer layer, |
| 1049 | const std::vector<IComposerClient::Rect>& visible) { |
Leon Scroggins III | e24d78f | 2022-09-20 16:38:19 -0400 | [diff] [blame] | 1050 | Error error = Error::NONE; |
| 1051 | mMutex.lock_shared(); |
| 1052 | if (auto writer = getWriter(display)) { |
| 1053 | writer->get().setLayerVisibleRegion(translate<int64_t>(display), translate<int64_t>(layer), |
| 1054 | translate<AidlRect>(visible)); |
| 1055 | } else { |
| 1056 | error = Error::BAD_DISPLAY; |
| 1057 | } |
| 1058 | mMutex.unlock_shared(); |
| 1059 | return error; |
Ady Abraham | e7385f7 | 2021-09-05 00:54:25 -0700 | [diff] [blame] | 1060 | } |
| 1061 | |
| 1062 | Error AidlComposer::setLayerZOrder(Display display, Layer layer, uint32_t z) { |
Leon Scroggins III | e24d78f | 2022-09-20 16:38:19 -0400 | [diff] [blame] | 1063 | Error error = Error::NONE; |
| 1064 | mMutex.lock_shared(); |
| 1065 | if (auto writer = getWriter(display)) { |
| 1066 | writer->get().setLayerZOrder(translate<int64_t>(display), translate<int64_t>(layer), z); |
| 1067 | } else { |
| 1068 | error = Error::BAD_DISPLAY; |
| 1069 | } |
| 1070 | mMutex.unlock_shared(); |
| 1071 | return error; |
Ady Abraham | e7385f7 | 2021-09-05 00:54:25 -0700 | [diff] [blame] | 1072 | } |
| 1073 | |
Leon Scroggins III | e24d78f | 2022-09-20 16:38:19 -0400 | [diff] [blame] | 1074 | Error AidlComposer::execute(Display display) { |
| 1075 | auto writer = getWriter(display); |
| 1076 | auto reader = getReader(display); |
| 1077 | if (!writer || !reader) { |
| 1078 | return Error::BAD_DISPLAY; |
| 1079 | } |
| 1080 | |
Huihong Luo | e7382c1 | 2023-04-21 20:24:32 +0000 | [diff] [blame] | 1081 | auto commands = writer->get().takePendingCommands(); |
Ady Abraham | a6388c0 | 2021-11-11 21:11:51 -0800 | [diff] [blame] | 1082 | if (commands.empty()) { |
Ady Abraham | e7385f7 | 2021-09-05 00:54:25 -0700 | [diff] [blame] | 1083 | return Error::NONE; |
| 1084 | } |
| 1085 | |
Ady Abraham | de79278 | 2021-12-20 10:00:49 -0800 | [diff] [blame] | 1086 | { // scope for results |
| 1087 | std::vector<CommandResultPayload> results; |
| 1088 | auto status = mAidlComposerClient->executeCommands(commands, &results); |
| 1089 | if (!status.isOk()) { |
| 1090 | ALOGE("executeCommands failed %s", status.getDescription().c_str()); |
| 1091 | return static_cast<Error>(status.getServiceSpecificError()); |
| 1092 | } |
Ady Abraham | e7385f7 | 2021-09-05 00:54:25 -0700 | [diff] [blame] | 1093 | |
Leon Scroggins III | e24d78f | 2022-09-20 16:38:19 -0400 | [diff] [blame] | 1094 | reader->get().parse(std::move(results)); |
Ady Abraham | de79278 | 2021-12-20 10:00:49 -0800 | [diff] [blame] | 1095 | } |
Leon Scroggins III | e24d78f | 2022-09-20 16:38:19 -0400 | [diff] [blame] | 1096 | const auto commandErrors = reader->get().takeErrors(); |
Ady Abraham | a6388c0 | 2021-11-11 21:11:51 -0800 | [diff] [blame] | 1097 | Error error = Error::NONE; |
| 1098 | for (const auto& cmdErr : commandErrors) { |
| 1099 | const auto index = static_cast<size_t>(cmdErr.commandIndex); |
| 1100 | if (index < 0 || index >= commands.size()) { |
| 1101 | ALOGE("invalid command index %zu", index); |
| 1102 | return Error::BAD_PARAMETER; |
Ady Abraham | e7385f7 | 2021-09-05 00:54:25 -0700 | [diff] [blame] | 1103 | } |
| 1104 | |
Ady Abraham | a6388c0 | 2021-11-11 21:11:51 -0800 | [diff] [blame] | 1105 | const auto& command = commands[index]; |
Ady Abraham | 4297736 | 2021-12-07 21:04:49 -0800 | [diff] [blame] | 1106 | if (command.validateDisplay || command.presentDisplay || command.presentOrValidateDisplay) { |
| 1107 | error = translate<Error>(cmdErr.errorCode); |
| 1108 | } else { |
| 1109 | ALOGW("command '%s' generated error %" PRId32, command.toString().c_str(), |
| 1110 | cmdErr.errorCode); |
Ady Abraham | e7385f7 | 2021-09-05 00:54:25 -0700 | [diff] [blame] | 1111 | } |
| 1112 | } |
| 1113 | |
Ady Abraham | e7385f7 | 2021-09-05 00:54:25 -0700 | [diff] [blame] | 1114 | return error; |
| 1115 | } |
| 1116 | |
| 1117 | Error AidlComposer::setLayerPerFrameMetadata( |
| 1118 | Display display, Layer layer, |
| 1119 | const std::vector<IComposerClient::PerFrameMetadata>& perFrameMetadatas) { |
Leon Scroggins III | e24d78f | 2022-09-20 16:38:19 -0400 | [diff] [blame] | 1120 | Error error = Error::NONE; |
| 1121 | mMutex.lock_shared(); |
| 1122 | if (auto writer = getWriter(display)) { |
| 1123 | writer->get().setLayerPerFrameMetadata(translate<int64_t>(display), |
| 1124 | translate<int64_t>(layer), |
| 1125 | translate<AidlPerFrameMetadata>(perFrameMetadatas)); |
| 1126 | } else { |
| 1127 | error = Error::BAD_DISPLAY; |
| 1128 | } |
| 1129 | mMutex.unlock_shared(); |
| 1130 | return error; |
Ady Abraham | e7385f7 | 2021-09-05 00:54:25 -0700 | [diff] [blame] | 1131 | } |
| 1132 | |
| 1133 | std::vector<IComposerClient::PerFrameMetadataKey> AidlComposer::getPerFrameMetadataKeys( |
| 1134 | Display display) { |
| 1135 | std::vector<AidlPerFrameMetadataKey> keys; |
| 1136 | const auto status = |
| 1137 | mAidlComposerClient->getPerFrameMetadataKeys(translate<int64_t>(display), &keys); |
| 1138 | if (!status.isOk()) { |
| 1139 | ALOGE("getPerFrameMetadataKeys failed %s", status.getDescription().c_str()); |
| 1140 | return {}; |
| 1141 | } |
| 1142 | return translate<IComposerClient::PerFrameMetadataKey>(keys); |
| 1143 | } |
| 1144 | |
| 1145 | Error AidlComposer::getRenderIntents(Display display, ColorMode colorMode, |
| 1146 | std::vector<RenderIntent>* outRenderIntents) { |
| 1147 | std::vector<AidlRenderIntent> renderIntents; |
| 1148 | const auto status = mAidlComposerClient->getRenderIntents(translate<int64_t>(display), |
| 1149 | translate<AidlColorMode>(colorMode), |
| 1150 | &renderIntents); |
| 1151 | if (!status.isOk()) { |
| 1152 | ALOGE("getRenderIntents failed %s", status.getDescription().c_str()); |
| 1153 | return static_cast<Error>(status.getServiceSpecificError()); |
| 1154 | } |
| 1155 | *outRenderIntents = translate<RenderIntent>(renderIntents); |
| 1156 | return Error::NONE; |
| 1157 | } |
| 1158 | |
| 1159 | Error AidlComposer::getDataspaceSaturationMatrix(Dataspace dataspace, mat4* outMatrix) { |
| 1160 | std::vector<float> matrix; |
| 1161 | const auto status = |
| 1162 | mAidlComposerClient->getDataspaceSaturationMatrix(translate<AidlDataspace>(dataspace), |
| 1163 | &matrix); |
| 1164 | if (!status.isOk()) { |
| 1165 | ALOGE("getDataspaceSaturationMatrix failed %s", status.getDescription().c_str()); |
| 1166 | return static_cast<Error>(status.getServiceSpecificError()); |
| 1167 | } |
| 1168 | *outMatrix = makeMat4(matrix); |
| 1169 | return Error::NONE; |
| 1170 | } |
| 1171 | |
| 1172 | Error AidlComposer::getDisplayIdentificationData(Display display, uint8_t* outPort, |
| 1173 | std::vector<uint8_t>* outData) { |
| 1174 | AidlDisplayIdentification displayIdentification; |
| 1175 | const auto status = |
| 1176 | mAidlComposerClient->getDisplayIdentificationData(translate<int64_t>(display), |
| 1177 | &displayIdentification); |
| 1178 | if (!status.isOk()) { |
| 1179 | ALOGE("getDisplayIdentificationData failed %s", status.getDescription().c_str()); |
| 1180 | return static_cast<Error>(status.getServiceSpecificError()); |
| 1181 | } |
| 1182 | |
| 1183 | *outPort = static_cast<uint8_t>(displayIdentification.port); |
| 1184 | *outData = displayIdentification.data; |
| 1185 | |
| 1186 | return Error::NONE; |
| 1187 | } |
| 1188 | |
| 1189 | Error AidlComposer::setLayerColorTransform(Display display, Layer layer, const float* matrix) { |
Leon Scroggins III | e24d78f | 2022-09-20 16:38:19 -0400 | [diff] [blame] | 1190 | Error error = Error::NONE; |
| 1191 | mMutex.lock_shared(); |
| 1192 | if (auto writer = getWriter(display)) { |
| 1193 | writer->get().setLayerColorTransform(translate<int64_t>(display), translate<int64_t>(layer), |
| 1194 | matrix); |
| 1195 | } else { |
| 1196 | error = Error::BAD_DISPLAY; |
| 1197 | } |
| 1198 | mMutex.unlock_shared(); |
| 1199 | return error; |
Ady Abraham | e7385f7 | 2021-09-05 00:54:25 -0700 | [diff] [blame] | 1200 | } |
| 1201 | |
| 1202 | Error AidlComposer::getDisplayedContentSamplingAttributes(Display display, PixelFormat* outFormat, |
| 1203 | Dataspace* outDataspace, |
| 1204 | uint8_t* outComponentMask) { |
| 1205 | if (!outFormat || !outDataspace || !outComponentMask) { |
| 1206 | return Error::BAD_PARAMETER; |
| 1207 | } |
| 1208 | |
| 1209 | AidlDisplayContentSamplingAttributes attributes; |
| 1210 | const auto status = |
| 1211 | mAidlComposerClient->getDisplayedContentSamplingAttributes(translate<int64_t>(display), |
| 1212 | &attributes); |
| 1213 | if (!status.isOk()) { |
| 1214 | ALOGE("getDisplayedContentSamplingAttributes failed %s", status.getDescription().c_str()); |
| 1215 | return static_cast<Error>(status.getServiceSpecificError()); |
| 1216 | } |
| 1217 | |
| 1218 | *outFormat = translate<PixelFormat>(attributes.format); |
| 1219 | *outDataspace = translate<Dataspace>(attributes.dataspace); |
| 1220 | *outComponentMask = static_cast<uint8_t>(attributes.componentMask); |
| 1221 | return Error::NONE; |
| 1222 | } |
| 1223 | |
| 1224 | Error AidlComposer::setDisplayContentSamplingEnabled(Display display, bool enabled, |
| 1225 | uint8_t componentMask, uint64_t maxFrames) { |
| 1226 | const auto status = |
| 1227 | mAidlComposerClient |
| 1228 | ->setDisplayedContentSamplingEnabled(translate<int64_t>(display), enabled, |
| 1229 | static_cast<AidlFormatColorComponent>( |
| 1230 | componentMask), |
| 1231 | static_cast<int64_t>(maxFrames)); |
| 1232 | if (!status.isOk()) { |
| 1233 | ALOGE("setDisplayedContentSamplingEnabled failed %s", status.getDescription().c_str()); |
| 1234 | return static_cast<Error>(status.getServiceSpecificError()); |
| 1235 | } |
| 1236 | return Error::NONE; |
| 1237 | } |
| 1238 | |
| 1239 | Error AidlComposer::getDisplayedContentSample(Display display, uint64_t maxFrames, |
| 1240 | uint64_t timestamp, DisplayedFrameStats* outStats) { |
| 1241 | if (!outStats) { |
| 1242 | return Error::BAD_PARAMETER; |
| 1243 | } |
| 1244 | |
| 1245 | AidlDisplayContentSample sample; |
| 1246 | const auto status = |
| 1247 | mAidlComposerClient->getDisplayedContentSample(translate<int64_t>(display), |
| 1248 | static_cast<int64_t>(maxFrames), |
| 1249 | static_cast<int64_t>(timestamp), |
| 1250 | &sample); |
| 1251 | if (!status.isOk()) { |
| 1252 | ALOGE("getDisplayedContentSample failed %s", status.getDescription().c_str()); |
| 1253 | return static_cast<Error>(status.getServiceSpecificError()); |
| 1254 | } |
| 1255 | *outStats = translate<DisplayedFrameStats>(sample); |
| 1256 | return Error::NONE; |
| 1257 | } |
| 1258 | |
| 1259 | Error AidlComposer::setLayerPerFrameMetadataBlobs( |
| 1260 | Display display, Layer layer, |
| 1261 | const std::vector<IComposerClient::PerFrameMetadataBlob>& metadata) { |
Leon Scroggins III | e24d78f | 2022-09-20 16:38:19 -0400 | [diff] [blame] | 1262 | Error error = Error::NONE; |
| 1263 | mMutex.lock_shared(); |
| 1264 | if (auto writer = getWriter(display)) { |
| 1265 | writer->get().setLayerPerFrameMetadataBlobs(translate<int64_t>(display), |
| 1266 | translate<int64_t>(layer), |
| 1267 | translate<AidlPerFrameMetadataBlob>(metadata)); |
| 1268 | } else { |
| 1269 | error = Error::BAD_DISPLAY; |
| 1270 | } |
| 1271 | mMutex.unlock_shared(); |
| 1272 | return error; |
Ady Abraham | e7385f7 | 2021-09-05 00:54:25 -0700 | [diff] [blame] | 1273 | } |
| 1274 | |
Alec Mouri | 4d8a05d | 2022-03-23 18:14:26 +0000 | [diff] [blame] | 1275 | Error AidlComposer::setDisplayBrightness(Display display, float brightness, float brightnessNits, |
Alec Mouri | cdf1679 | 2021-12-10 13:16:06 -0800 | [diff] [blame] | 1276 | const DisplayBrightnessOptions& options) { |
Leon Scroggins III | e24d78f | 2022-09-20 16:38:19 -0400 | [diff] [blame] | 1277 | Error error = Error::NONE; |
| 1278 | mMutex.lock_shared(); |
| 1279 | if (auto writer = getWriter(display)) { |
| 1280 | writer->get().setDisplayBrightness(translate<int64_t>(display), brightness, brightnessNits); |
Alec Mouri | cdf1679 | 2021-12-10 13:16:06 -0800 | [diff] [blame] | 1281 | |
Leon Scroggins III | e24d78f | 2022-09-20 16:38:19 -0400 | [diff] [blame] | 1282 | if (options.applyImmediately) { |
| 1283 | error = execute(display); |
| 1284 | mMutex.unlock_shared(); |
| 1285 | return error; |
| 1286 | } |
| 1287 | } else { |
| 1288 | error = Error::BAD_DISPLAY; |
Alec Mouri | cdf1679 | 2021-12-10 13:16:06 -0800 | [diff] [blame] | 1289 | } |
Leon Scroggins III | e24d78f | 2022-09-20 16:38:19 -0400 | [diff] [blame] | 1290 | mMutex.unlock_shared(); |
| 1291 | return error; |
Ady Abraham | e7385f7 | 2021-09-05 00:54:25 -0700 | [diff] [blame] | 1292 | } |
| 1293 | |
| 1294 | Error AidlComposer::getDisplayCapabilities(Display display, |
Leon Scroggins III | 5967aec | 2021-12-29 11:14:22 -0500 | [diff] [blame] | 1295 | std::vector<AidlDisplayCapability>* outCapabilities) { |
| 1296 | const auto status = mAidlComposerClient->getDisplayCapabilities(translate<int64_t>(display), |
| 1297 | outCapabilities); |
Ady Abraham | e7385f7 | 2021-09-05 00:54:25 -0700 | [diff] [blame] | 1298 | if (!status.isOk()) { |
| 1299 | ALOGE("getDisplayCapabilities failed %s", status.getDescription().c_str()); |
Leon Scroggins III | 5967aec | 2021-12-29 11:14:22 -0500 | [diff] [blame] | 1300 | outCapabilities->clear(); |
Ady Abraham | e7385f7 | 2021-09-05 00:54:25 -0700 | [diff] [blame] | 1301 | return static_cast<Error>(status.getServiceSpecificError()); |
| 1302 | } |
Ady Abraham | e7385f7 | 2021-09-05 00:54:25 -0700 | [diff] [blame] | 1303 | return Error::NONE; |
| 1304 | } |
| 1305 | |
| 1306 | V2_4::Error AidlComposer::getDisplayConnectionType( |
| 1307 | Display display, IComposerClient::DisplayConnectionType* outType) { |
| 1308 | AidlDisplayConnectionType type; |
| 1309 | const auto status = |
| 1310 | mAidlComposerClient->getDisplayConnectionType(translate<int64_t>(display), &type); |
| 1311 | if (!status.isOk()) { |
| 1312 | ALOGE("getDisplayConnectionType failed %s", status.getDescription().c_str()); |
| 1313 | return static_cast<V2_4::Error>(status.getServiceSpecificError()); |
| 1314 | } |
| 1315 | *outType = translate<IComposerClient::DisplayConnectionType>(type); |
| 1316 | return V2_4::Error::NONE; |
| 1317 | } |
| 1318 | |
| 1319 | V2_4::Error AidlComposer::getDisplayVsyncPeriod(Display display, VsyncPeriodNanos* outVsyncPeriod) { |
| 1320 | int32_t vsyncPeriod; |
| 1321 | const auto status = |
| 1322 | mAidlComposerClient->getDisplayVsyncPeriod(translate<int64_t>(display), &vsyncPeriod); |
| 1323 | if (!status.isOk()) { |
| 1324 | ALOGE("getDisplayVsyncPeriod failed %s", status.getDescription().c_str()); |
| 1325 | return static_cast<V2_4::Error>(status.getServiceSpecificError()); |
| 1326 | } |
| 1327 | *outVsyncPeriod = translate<VsyncPeriodNanos>(vsyncPeriod); |
| 1328 | return V2_4::Error::NONE; |
| 1329 | } |
| 1330 | |
| 1331 | V2_4::Error AidlComposer::setActiveConfigWithConstraints( |
| 1332 | Display display, Config config, |
| 1333 | const IComposerClient::VsyncPeriodChangeConstraints& vsyncPeriodChangeConstraints, |
| 1334 | VsyncPeriodChangeTimeline* outTimeline) { |
| 1335 | AidlVsyncPeriodChangeTimeline timeline; |
| 1336 | const auto status = |
| 1337 | mAidlComposerClient |
| 1338 | ->setActiveConfigWithConstraints(translate<int64_t>(display), |
| 1339 | translate<int32_t>(config), |
| 1340 | translate<AidlVsyncPeriodChangeConstraints>( |
| 1341 | vsyncPeriodChangeConstraints), |
| 1342 | &timeline); |
| 1343 | if (!status.isOk()) { |
| 1344 | ALOGE("setActiveConfigWithConstraints failed %s", status.getDescription().c_str()); |
| 1345 | return static_cast<V2_4::Error>(status.getServiceSpecificError()); |
| 1346 | } |
| 1347 | *outTimeline = translate<VsyncPeriodChangeTimeline>(timeline); |
| 1348 | return V2_4::Error::NONE; |
| 1349 | } |
| 1350 | |
| 1351 | V2_4::Error AidlComposer::setAutoLowLatencyMode(Display display, bool on) { |
| 1352 | const auto status = mAidlComposerClient->setAutoLowLatencyMode(translate<int64_t>(display), on); |
| 1353 | if (!status.isOk()) { |
| 1354 | ALOGE("setAutoLowLatencyMode failed %s", status.getDescription().c_str()); |
| 1355 | return static_cast<V2_4::Error>(status.getServiceSpecificError()); |
| 1356 | } |
| 1357 | return V2_4::Error::NONE; |
| 1358 | } |
| 1359 | |
| 1360 | V2_4::Error AidlComposer::getSupportedContentTypes( |
| 1361 | Display displayId, std::vector<IComposerClient::ContentType>* outSupportedContentTypes) { |
| 1362 | std::vector<AidlContentType> types; |
| 1363 | const auto status = |
| 1364 | mAidlComposerClient->getSupportedContentTypes(translate<int64_t>(displayId), &types); |
| 1365 | if (!status.isOk()) { |
| 1366 | ALOGE("getSupportedContentTypes failed %s", status.getDescription().c_str()); |
| 1367 | return static_cast<V2_4::Error>(status.getServiceSpecificError()); |
| 1368 | } |
| 1369 | *outSupportedContentTypes = translate<IComposerClient::ContentType>(types); |
| 1370 | return V2_4::Error::NONE; |
| 1371 | } |
| 1372 | |
| 1373 | V2_4::Error AidlComposer::setContentType(Display display, |
| 1374 | IComposerClient::ContentType contentType) { |
| 1375 | const auto status = |
| 1376 | mAidlComposerClient->setContentType(translate<int64_t>(display), |
| 1377 | translate<AidlContentType>(contentType)); |
| 1378 | if (!status.isOk()) { |
| 1379 | ALOGE("setContentType failed %s", status.getDescription().c_str()); |
| 1380 | return static_cast<V2_4::Error>(status.getServiceSpecificError()); |
| 1381 | } |
| 1382 | return V2_4::Error::NONE; |
| 1383 | } |
| 1384 | |
Ady Abraham | 3f97675 | 2021-12-20 16:17:50 -0800 | [diff] [blame] | 1385 | V2_4::Error AidlComposer::setLayerGenericMetadata(Display, Layer, const std::string&, bool, |
| 1386 | const std::vector<uint8_t>&) { |
| 1387 | // There are no users for this API. See b/209691612. |
| 1388 | return V2_4::Error::UNSUPPORTED; |
Ady Abraham | e7385f7 | 2021-09-05 00:54:25 -0700 | [diff] [blame] | 1389 | } |
| 1390 | |
| 1391 | V2_4::Error AidlComposer::getLayerGenericMetadataKeys( |
Ady Abraham | 3f97675 | 2021-12-20 16:17:50 -0800 | [diff] [blame] | 1392 | std::vector<IComposerClient::LayerGenericMetadataKey>*) { |
| 1393 | // There are no users for this API. See b/209691612. |
| 1394 | return V2_4::Error::UNSUPPORTED; |
Ady Abraham | e7385f7 | 2021-09-05 00:54:25 -0700 | [diff] [blame] | 1395 | } |
| 1396 | |
Kriti Dang | 7defaf3 | 2021-11-15 11:55:43 +0100 | [diff] [blame] | 1397 | Error AidlComposer::setBootDisplayConfig(Display display, Config config) { |
| 1398 | const auto status = mAidlComposerClient->setBootDisplayConfig(translate<int64_t>(display), |
| 1399 | translate<int32_t>(config)); |
| 1400 | if (!status.isOk()) { |
| 1401 | ALOGE("setBootDisplayConfig failed %s", status.getDescription().c_str()); |
| 1402 | return static_cast<Error>(status.getServiceSpecificError()); |
| 1403 | } |
| 1404 | return Error::NONE; |
| 1405 | } |
| 1406 | |
| 1407 | Error AidlComposer::clearBootDisplayConfig(Display display) { |
| 1408 | const auto status = mAidlComposerClient->clearBootDisplayConfig(translate<int64_t>(display)); |
| 1409 | if (!status.isOk()) { |
| 1410 | ALOGE("clearBootDisplayConfig failed %s", status.getDescription().c_str()); |
| 1411 | return static_cast<Error>(status.getServiceSpecificError()); |
| 1412 | } |
| 1413 | return Error::NONE; |
| 1414 | } |
| 1415 | |
| 1416 | Error AidlComposer::getPreferredBootDisplayConfig(Display display, Config* config) { |
| 1417 | int32_t displayConfig; |
| 1418 | const auto status = |
| 1419 | mAidlComposerClient->getPreferredBootDisplayConfig(translate<int64_t>(display), |
| 1420 | &displayConfig); |
| 1421 | if (!status.isOk()) { |
| 1422 | ALOGE("getPreferredBootDisplayConfig failed %s", status.getDescription().c_str()); |
| 1423 | return static_cast<Error>(status.getServiceSpecificError()); |
| 1424 | } |
| 1425 | *config = translate<uint32_t>(displayConfig); |
| 1426 | return Error::NONE; |
| 1427 | } |
| 1428 | |
Kriti Dang | 674b937 | 2022-11-18 10:58:44 +0100 | [diff] [blame] | 1429 | Error AidlComposer::getHdrConversionCapabilities( |
| 1430 | std::vector<AidlHdrConversionCapability>* hdrConversionCapabilities) { |
| 1431 | const auto status = |
| 1432 | mAidlComposerClient->getHdrConversionCapabilities(hdrConversionCapabilities); |
| 1433 | if (!status.isOk()) { |
| 1434 | hdrConversionCapabilities = {}; |
| 1435 | ALOGE("getHdrConversionCapabilities failed %s", status.getDescription().c_str()); |
| 1436 | return static_cast<Error>(status.getServiceSpecificError()); |
| 1437 | } |
| 1438 | return Error::NONE; |
| 1439 | } |
| 1440 | |
Kriti Dang | d432bb5 | 2023-02-09 18:21:04 +0100 | [diff] [blame] | 1441 | Error AidlComposer::setHdrConversionStrategy(AidlHdrConversionStrategy hdrConversionStrategy, |
| 1442 | Hdr* outPreferredHdrOutputType) { |
| 1443 | const auto status = mAidlComposerClient->setHdrConversionStrategy(hdrConversionStrategy, |
| 1444 | outPreferredHdrOutputType); |
Kriti Dang | 674b937 | 2022-11-18 10:58:44 +0100 | [diff] [blame] | 1445 | if (!status.isOk()) { |
| 1446 | ALOGE("setHdrConversionStrategy failed %s", status.getDescription().c_str()); |
| 1447 | return static_cast<Error>(status.getServiceSpecificError()); |
| 1448 | } |
| 1449 | return Error::NONE; |
| 1450 | } |
| 1451 | |
ramindani | b2158ee | 2023-02-13 20:29:59 -0800 | [diff] [blame] | 1452 | Error AidlComposer::setRefreshRateChangedCallbackDebugEnabled(Display displayId, bool enabled) { |
| 1453 | const auto status = |
| 1454 | mAidlComposerClient->setRefreshRateChangedCallbackDebugEnabled(translate<int64_t>( |
| 1455 | displayId), |
| 1456 | enabled); |
| 1457 | if (!status.isOk()) { |
| 1458 | ALOGE("setRefreshRateChangedCallbackDebugEnabled failed %s", |
| 1459 | status.getDescription().c_str()); |
| 1460 | return static_cast<Error>(status.getServiceSpecificError()); |
| 1461 | } |
| 1462 | return Error::NONE; |
| 1463 | } |
| 1464 | |
ramindani | 3acaaf5 | 2023-09-25 10:31:27 -0700 | [diff] [blame] | 1465 | Error AidlComposer::notifyExpectedPresent(Display displayId, nsecs_t expectedPresentTime, |
| 1466 | int32_t frameIntervalNs) { |
| 1467 | const auto status = |
| 1468 | mAidlComposerClient->notifyExpectedPresent(translate<int64_t>(displayId), |
| 1469 | ClockMonotonicTimestamp{expectedPresentTime}, |
| 1470 | frameIntervalNs); |
| 1471 | |
| 1472 | if (!status.isOk()) { |
| 1473 | ALOGE("notifyExpectedPresent failed %s", status.getDescription().c_str()); |
| 1474 | return static_cast<Error>(status.getServiceSpecificError()); |
| 1475 | } |
| 1476 | return Error::NONE; |
| 1477 | } |
| 1478 | |
Ady Abraham | e7385f7 | 2021-09-05 00:54:25 -0700 | [diff] [blame] | 1479 | Error AidlComposer::getClientTargetProperty( |
Alec Mouri | 8506569 | 2022-03-18 00:58:26 +0000 | [diff] [blame] | 1480 | Display display, ClientTargetPropertyWithBrightness* outClientTargetProperty) { |
Leon Scroggins III | e24d78f | 2022-09-20 16:38:19 -0400 | [diff] [blame] | 1481 | Error error = Error::NONE; |
| 1482 | mMutex.lock_shared(); |
| 1483 | if (auto reader = getReader(display)) { |
| 1484 | *outClientTargetProperty = |
| 1485 | reader->get().takeClientTargetProperty(translate<int64_t>(display)); |
| 1486 | } else { |
| 1487 | error = Error::BAD_DISPLAY; |
| 1488 | } |
| 1489 | mMutex.unlock_shared(); |
| 1490 | return error; |
Ady Abraham | e7385f7 | 2021-09-05 00:54:25 -0700 | [diff] [blame] | 1491 | } |
| 1492 | |
Alec Mouri | 6da0e27 | 2022-02-07 12:45:57 -0800 | [diff] [blame] | 1493 | Error AidlComposer::setLayerBrightness(Display display, Layer layer, float brightness) { |
Leon Scroggins III | e24d78f | 2022-09-20 16:38:19 -0400 | [diff] [blame] | 1494 | Error error = Error::NONE; |
| 1495 | mMutex.lock_shared(); |
| 1496 | if (auto writer = getWriter(display)) { |
| 1497 | writer->get().setLayerBrightness(translate<int64_t>(display), translate<int64_t>(layer), |
| 1498 | brightness); |
| 1499 | } else { |
| 1500 | error = Error::BAD_DISPLAY; |
| 1501 | } |
| 1502 | mMutex.unlock_shared(); |
| 1503 | return error; |
Alec Mouri | cdf6cbc | 2021-11-01 17:21:15 -0700 | [diff] [blame] | 1504 | } |
| 1505 | |
Leon Scroggins III | d77d316 | 2022-01-05 10:42:28 -0500 | [diff] [blame] | 1506 | Error AidlComposer::setLayerBlockingRegion(Display display, Layer layer, |
| 1507 | const std::vector<IComposerClient::Rect>& blocking) { |
Leon Scroggins III | e24d78f | 2022-09-20 16:38:19 -0400 | [diff] [blame] | 1508 | Error error = Error::NONE; |
| 1509 | mMutex.lock_shared(); |
| 1510 | if (auto writer = getWriter(display)) { |
| 1511 | writer->get().setLayerBlockingRegion(translate<int64_t>(display), translate<int64_t>(layer), |
| 1512 | translate<AidlRect>(blocking)); |
| 1513 | } else { |
| 1514 | error = Error::BAD_DISPLAY; |
| 1515 | } |
| 1516 | mMutex.unlock_shared(); |
| 1517 | return error; |
Leon Scroggins III | d77d316 | 2022-01-05 10:42:28 -0500 | [diff] [blame] | 1518 | } |
Leon Scroggins III | e7c51c6 | 2022-02-01 15:53:54 -0500 | [diff] [blame] | 1519 | |
| 1520 | Error AidlComposer::getDisplayDecorationSupport(Display display, |
| 1521 | std::optional<DisplayDecorationSupport>* support) { |
| 1522 | const auto status = |
| 1523 | mAidlComposerClient->getDisplayDecorationSupport(translate<int64_t>(display), support); |
| 1524 | if (!status.isOk()) { |
| 1525 | ALOGE("getDisplayDecorationSupport failed %s", status.getDescription().c_str()); |
| 1526 | support->reset(); |
| 1527 | return static_cast<Error>(status.getServiceSpecificError()); |
| 1528 | } |
| 1529 | return Error::NONE; |
| 1530 | } |
ramindani | 32cf060 | 2022-03-02 02:30:29 +0000 | [diff] [blame] | 1531 | |
| 1532 | Error AidlComposer::setIdleTimerEnabled(Display displayId, std::chrono::milliseconds timeout) { |
| 1533 | const auto status = |
| 1534 | mAidlComposerClient->setIdleTimerEnabled(translate<int64_t>(displayId), |
| 1535 | translate<int32_t>(timeout.count())); |
| 1536 | if (!status.isOk()) { |
| 1537 | ALOGE("setIdleTimerEnabled failed %s", status.getDescription().c_str()); |
| 1538 | return static_cast<Error>(status.getServiceSpecificError()); |
| 1539 | } |
| 1540 | return Error::NONE; |
| 1541 | } |
| 1542 | |
ramindani | 06e518e | 2022-03-14 18:47:53 +0000 | [diff] [blame] | 1543 | Error AidlComposer::getPhysicalDisplayOrientation(Display displayId, |
| 1544 | AidlTransform* outDisplayOrientation) { |
| 1545 | const auto status = |
| 1546 | mAidlComposerClient->getDisplayPhysicalOrientation(translate<int64_t>(displayId), |
| 1547 | outDisplayOrientation); |
| 1548 | if (!status.isOk()) { |
| 1549 | ALOGE("getPhysicalDisplayOrientation failed %s", status.getDescription().c_str()); |
| 1550 | return static_cast<Error>(status.getServiceSpecificError()); |
| 1551 | } |
| 1552 | return Error::NONE; |
| 1553 | } |
| 1554 | |
Leon Scroggins III | e24d78f | 2022-09-20 16:38:19 -0400 | [diff] [blame] | 1555 | ftl::Optional<std::reference_wrapper<ComposerClientWriter>> AidlComposer::getWriter(Display display) |
| 1556 | REQUIRES_SHARED(mMutex) { |
| 1557 | return mWriters.get(display); |
| 1558 | } |
| 1559 | |
| 1560 | ftl::Optional<std::reference_wrapper<ComposerClientReader>> AidlComposer::getReader(Display display) |
| 1561 | REQUIRES_SHARED(mMutex) { |
| 1562 | if (mSingleReader) { |
| 1563 | display = translate<Display>(kSingleReaderKey); |
| 1564 | } |
| 1565 | return mReaders.get(display); |
| 1566 | } |
| 1567 | |
| 1568 | void AidlComposer::removeDisplay(Display display) { |
| 1569 | mMutex.lock(); |
| 1570 | bool wasErased = mWriters.erase(display); |
| 1571 | ALOGW_IF(!wasErased, |
| 1572 | "Attempting to remove writer for display %" PRId64 " which is not connected", |
| 1573 | translate<int64_t>(display)); |
| 1574 | if (!mSingleReader) { |
| 1575 | removeReader(display); |
| 1576 | } |
| 1577 | mMutex.unlock(); |
| 1578 | } |
| 1579 | |
| 1580 | void AidlComposer::onHotplugDisconnect(Display display) { |
| 1581 | removeDisplay(display); |
| 1582 | } |
| 1583 | |
| 1584 | bool AidlComposer::hasMultiThreadedPresentSupport(Display display) { |
Leon Scroggins III | c1cf458 | 2023-03-23 18:37:44 -0400 | [diff] [blame] | 1585 | #if 0 |
| 1586 | // TODO (b/259132483): Reenable |
Leon Scroggins III | e24d78f | 2022-09-20 16:38:19 -0400 | [diff] [blame] | 1587 | const auto displayId = translate<int64_t>(display); |
| 1588 | std::vector<AidlDisplayCapability> capabilities; |
| 1589 | const auto status = mAidlComposerClient->getDisplayCapabilities(displayId, &capabilities); |
| 1590 | if (!status.isOk()) { |
| 1591 | ALOGE("getDisplayCapabilities failed %s", status.getDescription().c_str()); |
| 1592 | return false; |
| 1593 | } |
| 1594 | return std::find(capabilities.begin(), capabilities.end(), |
| 1595 | AidlDisplayCapability::MULTI_THREADED_PRESENT) != capabilities.end(); |
Leon Scroggins III | c1cf458 | 2023-03-23 18:37:44 -0400 | [diff] [blame] | 1596 | #else |
| 1597 | (void) display; |
| 1598 | return false; |
| 1599 | #endif |
Leon Scroggins III | e24d78f | 2022-09-20 16:38:19 -0400 | [diff] [blame] | 1600 | } |
| 1601 | |
| 1602 | void AidlComposer::addReader(Display display) { |
| 1603 | const auto displayId = translate<int64_t>(display); |
| 1604 | std::optional<int64_t> displayOpt; |
| 1605 | if (displayId != kSingleReaderKey) { |
| 1606 | displayOpt.emplace(displayId); |
| 1607 | } |
| 1608 | auto [it, added] = mReaders.try_emplace(display, std::move(displayOpt)); |
| 1609 | ALOGW_IF(!added, "Attempting to add writer for display %" PRId64 " which is already connected", |
| 1610 | displayId); |
| 1611 | } |
| 1612 | |
| 1613 | void AidlComposer::removeReader(Display display) { |
| 1614 | bool wasErased = mReaders.erase(display); |
| 1615 | ALOGW_IF(!wasErased, |
| 1616 | "Attempting to remove reader for display %" PRId64 " which is not connected", |
| 1617 | translate<int64_t>(display)); |
| 1618 | } |
| 1619 | |
| 1620 | void AidlComposer::addDisplay(Display display) { |
| 1621 | const auto displayId = translate<int64_t>(display); |
| 1622 | mMutex.lock(); |
| 1623 | auto [it, added] = mWriters.try_emplace(display, displayId); |
| 1624 | ALOGW_IF(!added, "Attempting to add writer for display %" PRId64 " which is already connected", |
| 1625 | displayId); |
| 1626 | if (mSingleReader) { |
| 1627 | if (hasMultiThreadedPresentSupport(display)) { |
| 1628 | mSingleReader = false; |
| 1629 | removeReader(translate<Display>(kSingleReaderKey)); |
| 1630 | // Note that this includes the new display. |
| 1631 | for (const auto& [existingDisplay, _] : mWriters) { |
| 1632 | addReader(existingDisplay); |
| 1633 | } |
| 1634 | } |
| 1635 | } else { |
| 1636 | addReader(display); |
| 1637 | } |
| 1638 | mMutex.unlock(); |
| 1639 | } |
| 1640 | |
| 1641 | void AidlComposer::onHotplugConnect(Display display) { |
| 1642 | addDisplay(display); |
| 1643 | } |
Ady Abraham | e7385f7 | 2021-09-05 00:54:25 -0700 | [diff] [blame] | 1644 | } // namespace Hwc2 |
| 1645 | } // namespace android |