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