blob: 1643ad0659cb64cd3fd1663a498e32c9b8b46ba3 [file] [log] [blame]
Ady Abrahame7385f72021-09-05 00:54:25 -07001/*
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 Abraham9fc28052021-10-14 17:21:38 -070021#include "AidlComposerHal.h"
Ady Abrahame7385f72021-09-05 00:54:25 -070022
Brian Lindahl5b0ffe02023-06-15 14:19:43 -060023#include <SurfaceFlingerProperties.h>
Ady Abrahamc4acf512022-02-18 17:11:59 -080024#include <android-base/file.h>
Ady Abrahame7385f72021-09-05 00:54:25 -070025#include <android/binder_ibinder_platform.h>
26#include <android/binder_manager.h>
Leon Scroggins IIIe85e16e2022-12-12 12:51:18 -050027#include <gui/TraceUtils.h>
Ady Abrahame7385f72021-09-05 00:54:25 -070028#include <log/log.h>
29#include <utils/Trace.h>
30
31#include <aidl/android/hardware/graphics/composer3/BnComposerCallback.h>
32
33#include <algorithm>
34#include <cinttypes>
35
Yichi Chen3401b562022-01-17 15:42:35 +080036#include "HWC2.h"
37
Ady Abrahame7385f72021-09-05 00:54:25 -070038namespace android {
39
40using hardware::hidl_handle;
41using hardware::hidl_vec;
42using hardware::Return;
43
44using aidl::android::hardware::graphics::composer3::BnComposerCallback;
45using aidl::android::hardware::graphics::composer3::Capability;
Alec Mouri85065692022-03-18 00:58:26 +000046using aidl::android::hardware::graphics::composer3::ClientTargetPropertyWithBrightness;
Ady Abrahame7385f72021-09-05 00:54:25 -070047using aidl::android::hardware::graphics::composer3::PowerMode;
48using aidl::android::hardware::graphics::composer3::VirtualDisplay;
49
Ady Abraham42977362021-12-07 21:04:49 -080050using aidl::android::hardware::graphics::composer3::CommandResultPayload;
Ady Abrahama6388c02021-11-11 21:11:51 -080051
Ady Abrahame7385f72021-09-05 00:54:25 -070052using AidlColorMode = aidl::android::hardware::graphics::composer3::ColorMode;
53using AidlContentType = aidl::android::hardware::graphics::composer3::ContentType;
54using AidlDisplayIdentification =
55 aidl::android::hardware::graphics::composer3::DisplayIdentification;
56using AidlDisplayContentSample = aidl::android::hardware::graphics::composer3::DisplayContentSample;
57using AidlDisplayAttribute = aidl::android::hardware::graphics::composer3::DisplayAttribute;
58using AidlDisplayCapability = aidl::android::hardware::graphics::composer3::DisplayCapability;
Ady Abrahame7385f72021-09-05 00:54:25 -070059using AidlHdrCapabilities = aidl::android::hardware::graphics::composer3::HdrCapabilities;
Kriti Dang674b9372022-11-18 10:58:44 +010060using AidlHdrConversionCapability =
61 aidl::android::hardware::graphics::common::HdrConversionCapability;
62using AidlHdrConversionStrategy = aidl::android::hardware::graphics::common::HdrConversionStrategy;
Sally Qi0cbd08b2022-08-17 12:12:28 -070063using AidlOverlayProperties = aidl::android::hardware::graphics::composer3::OverlayProperties;
Ady Abrahame7385f72021-09-05 00:54:25 -070064using AidlPerFrameMetadata = aidl::android::hardware::graphics::composer3::PerFrameMetadata;
65using AidlPerFrameMetadataKey = aidl::android::hardware::graphics::composer3::PerFrameMetadataKey;
66using AidlPerFrameMetadataBlob = aidl::android::hardware::graphics::composer3::PerFrameMetadataBlob;
67using AidlRenderIntent = aidl::android::hardware::graphics::composer3::RenderIntent;
68using AidlVsyncPeriodChangeConstraints =
69 aidl::android::hardware::graphics::composer3::VsyncPeriodChangeConstraints;
70using AidlVsyncPeriodChangeTimeline =
71 aidl::android::hardware::graphics::composer3::VsyncPeriodChangeTimeline;
Ady Abrahame7385f72021-09-05 00:54:25 -070072using AidlDisplayContentSamplingAttributes =
73 aidl::android::hardware::graphics::composer3::DisplayContentSamplingAttributes;
74using AidlFormatColorComponent = aidl::android::hardware::graphics::composer3::FormatColorComponent;
75using AidlDisplayConnectionType =
76 aidl::android::hardware::graphics::composer3::DisplayConnectionType;
Ady Abrahame7385f72021-09-05 00:54:25 -070077
78using AidlColorTransform = aidl::android::hardware::graphics::common::ColorTransform;
79using AidlDataspace = aidl::android::hardware::graphics::common::Dataspace;
80using AidlFRect = aidl::android::hardware::graphics::common::FRect;
81using AidlRect = aidl::android::hardware::graphics::common::Rect;
82using AidlTransform = aidl::android::hardware::graphics::common::Transform;
83
84namespace Hwc2 {
85
86namespace {
87
88template <typename To, typename From>
89To translate(From x) {
90 return static_cast<To>(x);
91}
92
93template <typename To, typename From>
94std::vector<To> translate(const std::vector<From>& in) {
95 std::vector<To> out;
96 out.reserve(in.size());
97 std::transform(in.begin(), in.end(), std::back_inserter(out),
98 [](From x) { return translate<To>(x); });
99 return out;
100}
101
102template <>
103AidlRect translate(IComposerClient::Rect x) {
104 return AidlRect{
105 .left = x.left,
106 .top = x.top,
107 .right = x.right,
108 .bottom = x.bottom,
109 };
110}
111
112template <>
113AidlFRect translate(IComposerClient::FRect x) {
114 return AidlFRect{
115 .left = x.left,
116 .top = x.top,
117 .right = x.right,
118 .bottom = x.bottom,
119 };
120}
121
122template <>
Ady Abrahame7385f72021-09-05 00:54:25 -0700123AidlPerFrameMetadataBlob translate(IComposerClient::PerFrameMetadataBlob x) {
124 AidlPerFrameMetadataBlob blob;
125 blob.key = translate<AidlPerFrameMetadataKey>(x.key),
Long Linga4628782022-02-18 13:44:26 -0800126 std::copy(x.blob.begin(), x.blob.end(), std::inserter(blob.blob, blob.blob.end()));
Ady Abrahame7385f72021-09-05 00:54:25 -0700127 return blob;
128}
129
130template <>
131AidlPerFrameMetadata translate(IComposerClient::PerFrameMetadata x) {
132 return AidlPerFrameMetadata{
133 .key = translate<AidlPerFrameMetadataKey>(x.key),
134 .value = x.value,
135 };
136}
137
138template <>
139DisplayedFrameStats translate(AidlDisplayContentSample x) {
140 return DisplayedFrameStats{
141 .numFrames = static_cast<uint64_t>(x.frameCount),
142 .component_0_sample = translate<uint64_t>(x.sampleComponent0),
143 .component_1_sample = translate<uint64_t>(x.sampleComponent1),
144 .component_2_sample = translate<uint64_t>(x.sampleComponent2),
145 .component_3_sample = translate<uint64_t>(x.sampleComponent3),
146 };
147}
148
149template <>
150AidlVsyncPeriodChangeConstraints translate(IComposerClient::VsyncPeriodChangeConstraints x) {
151 return AidlVsyncPeriodChangeConstraints{
152 .desiredTimeNanos = x.desiredTimeNanos,
153 .seamlessRequired = x.seamlessRequired,
154 };
155}
156
157template <>
158VsyncPeriodChangeTimeline translate(AidlVsyncPeriodChangeTimeline x) {
159 return VsyncPeriodChangeTimeline{
160 .newVsyncAppliedTimeNanos = x.newVsyncAppliedTimeNanos,
161 .refreshRequired = x.refreshRequired,
162 .refreshTimeNanos = x.refreshTimeNanos,
163 };
164}
Ady Abrahame7385f72021-09-05 00:54:25 -0700165mat4 makeMat4(std::vector<float> in) {
166 return mat4(static_cast<const float*>(in.data()));
167}
168
169} // namespace
170
171class AidlIComposerCallbackWrapper : public BnComposerCallback {
172public:
Yichi Chen3401b562022-01-17 15:42:35 +0800173 AidlIComposerCallbackWrapper(HWC2::ComposerCallback& callback) : mCallback(callback) {}
Ady Abrahame7385f72021-09-05 00:54:25 -0700174
175 ::ndk::ScopedAStatus onHotplug(int64_t in_display, bool in_connected) override {
176 const auto connection = in_connected ? V2_4::IComposerCallback::Connection::CONNECTED
177 : V2_4::IComposerCallback::Connection::DISCONNECTED;
Yichi Chen3401b562022-01-17 15:42:35 +0800178 mCallback.onComposerHalHotplug(translate<Display>(in_display), connection);
Ady Abrahame7385f72021-09-05 00:54:25 -0700179 return ::ndk::ScopedAStatus::ok();
180 }
181
182 ::ndk::ScopedAStatus onRefresh(int64_t in_display) override {
Yichi Chen3401b562022-01-17 15:42:35 +0800183 mCallback.onComposerHalRefresh(translate<Display>(in_display));
Ady Abrahame7385f72021-09-05 00:54:25 -0700184 return ::ndk::ScopedAStatus::ok();
185 }
Yichi Chen3401b562022-01-17 15:42:35 +0800186
Ady Abrahame7385f72021-09-05 00:54:25 -0700187 ::ndk::ScopedAStatus onSeamlessPossible(int64_t in_display) override {
Yichi Chen3401b562022-01-17 15:42:35 +0800188 mCallback.onComposerHalSeamlessPossible(translate<Display>(in_display));
Ady Abrahame7385f72021-09-05 00:54:25 -0700189 return ::ndk::ScopedAStatus::ok();
190 }
Yichi Chen3401b562022-01-17 15:42:35 +0800191
Ady Abrahame7385f72021-09-05 00:54:25 -0700192 ::ndk::ScopedAStatus onVsync(int64_t in_display, int64_t in_timestamp,
193 int32_t in_vsyncPeriodNanos) override {
Yichi Chen3401b562022-01-17 15:42:35 +0800194 mCallback.onComposerHalVsync(translate<Display>(in_display), in_timestamp,
195 static_cast<uint32_t>(in_vsyncPeriodNanos));
Ady Abrahame7385f72021-09-05 00:54:25 -0700196 return ::ndk::ScopedAStatus::ok();
197 }
Yichi Chen3401b562022-01-17 15:42:35 +0800198
Ady Abrahame7385f72021-09-05 00:54:25 -0700199 ::ndk::ScopedAStatus onVsyncPeriodTimingChanged(
200 int64_t in_display, const AidlVsyncPeriodChangeTimeline& in_updatedTimeline) override {
Yichi Chen3401b562022-01-17 15:42:35 +0800201 mCallback.onComposerHalVsyncPeriodTimingChanged(translate<Display>(in_display),
202 translate<V2_4::VsyncPeriodChangeTimeline>(
203 in_updatedTimeline));
204 return ::ndk::ScopedAStatus::ok();
205 }
206
207 ::ndk::ScopedAStatus onVsyncIdle(int64_t in_display) override {
208 mCallback.onComposerHalVsyncIdle(translate<Display>(in_display));
Ady Abrahame7385f72021-09-05 00:54:25 -0700209 return ::ndk::ScopedAStatus::ok();
210 }
211
ramindani12bfe6b2023-02-03 13:29:19 -0800212 ::ndk::ScopedAStatus onRefreshRateChangedDebug(
213 const RefreshRateChangedDebugData& refreshRateChangedDebugData) override {
214 mCallback.onRefreshRateChangedDebug(refreshRateChangedDebugData);
215 return ::ndk::ScopedAStatus::ok();
216 }
217
Ady Abrahame7385f72021-09-05 00:54:25 -0700218private:
Yichi Chen3401b562022-01-17 15:42:35 +0800219 HWC2::ComposerCallback& mCallback;
Ady Abrahame7385f72021-09-05 00:54:25 -0700220};
221
Ady Abraham9fc28052021-10-14 17:21:38 -0700222std::string AidlComposer::instance(const std::string& serviceName) {
223 return std::string(AidlIComposer::descriptor) + "/" + serviceName;
224}
225
226bool AidlComposer::isDeclared(const std::string& serviceName) {
227 return AServiceManager_isDeclared(instance(serviceName).c_str());
228}
Ady Abrahame7385f72021-09-05 00:54:25 -0700229
Ady Abrahama6388c02021-11-11 21:11:51 -0800230AidlComposer::AidlComposer(const std::string& serviceName) {
Ady Abrahame7385f72021-09-05 00:54:25 -0700231 // This only waits if the service is actually declared
Ady Abraham9fc28052021-10-14 17:21:38 -0700232 mAidlComposer = AidlIComposer::fromBinder(
233 ndk::SpAIBinder(AServiceManager_waitForService(instance(serviceName).c_str())));
Ady Abrahame7385f72021-09-05 00:54:25 -0700234 if (!mAidlComposer) {
235 LOG_ALWAYS_FATAL("Failed to get AIDL composer service");
236 return;
237 }
238
239 if (!mAidlComposer->createClient(&mAidlComposerClient).isOk()) {
240 LOG_ALWAYS_FATAL("Can't create AidlComposerClient, fallback to HIDL");
241 return;
242 }
243
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400244 addReader(translate<Display>(kSingleReaderKey));
245
Brian Lindahldbf7e3a2022-12-16 11:43:39 -0700246 // If unable to read interface version, then become backwards compatible.
ramindani0cd1d8d2023-06-13 13:43:23 -0700247 const auto status = mAidlComposerClient->getInterfaceVersion(&mComposerInterfaceVersion);
Brian Lindahldbf7e3a2022-12-16 11:43:39 -0700248 if (!status.isOk()) {
249 ALOGE("getInterfaceVersion for AidlComposer constructor failed %s",
250 status.getDescription().c_str());
251 }
ramindani0cd1d8d2023-06-13 13:43:23 -0700252
253 if (mComposerInterfaceVersion <= 1) {
Brian Lindahl5b0ffe02023-06-15 14:19:43 -0600254 if (sysprop::clear_slots_with_set_layer_buffer(false)) {
255 mClearSlotBuffer = sp<GraphicBuffer>::make(1, 1, PIXEL_FORMAT_RGBX_8888,
256 GraphicBuffer::USAGE_HW_COMPOSER |
257 GraphicBuffer::USAGE_SW_READ_OFTEN |
258 GraphicBuffer::USAGE_SW_WRITE_OFTEN,
259 "AidlComposer");
260 if (!mClearSlotBuffer || mClearSlotBuffer->initCheck() != ::android::OK) {
261 LOG_ALWAYS_FATAL("Failed to allocate a buffer for clearing layer buffer slots");
262 return;
263 }
Brian Lindahldbf7e3a2022-12-16 11:43:39 -0700264 }
Brian Lindahl90553da2022-12-06 13:36:30 -0700265 }
266
Ady Abrahame7385f72021-09-05 00:54:25 -0700267 ALOGI("Loaded AIDL composer3 HAL service");
268}
269
270AidlComposer::~AidlComposer() = default;
271
Ady Abraham4d211cf2021-12-14 16:19:03 -0800272bool AidlComposer::isSupported(OptionalFeature feature) const {
273 switch (feature) {
274 case OptionalFeature::RefreshRateSwitching:
Ady Abraham43065bd2021-12-10 17:22:15 -0800275 case OptionalFeature::ExpectedPresentTime:
Alec Mouricdf16792021-12-10 13:16:06 -0800276 case OptionalFeature::DisplayBrightnessCommand:
ramindani32cf0602022-03-02 02:30:29 +0000277 case OptionalFeature::KernelIdleTimer:
ramindani06e518e2022-03-14 18:47:53 +0000278 case OptionalFeature::PhysicalDisplayOrientation:
Ady Abraham4d211cf2021-12-14 16:19:03 -0800279 return true;
280 }
281}
282
ramindani0cd1d8d2023-06-13 13:43:23 -0700283bool AidlComposer::getDisplayConfigurationsSupported() const {
284 return mComposerInterfaceVersion >= 3;
285}
286
Ady Abrahamde549d42022-01-26 19:19:17 -0800287std::vector<Capability> AidlComposer::getCapabilities() {
Ady Abrahame7385f72021-09-05 00:54:25 -0700288 std::vector<Capability> capabilities;
289 const auto status = mAidlComposer->getCapabilities(&capabilities);
290 if (!status.isOk()) {
291 ALOGE("getCapabilities failed %s", status.getDescription().c_str());
292 return {};
293 }
Ady Abrahamde549d42022-01-26 19:19:17 -0800294 return capabilities;
Ady Abrahame7385f72021-09-05 00:54:25 -0700295}
296
297std::string AidlComposer::dumpDebugInfo() {
Ady Abrahamc4acf512022-02-18 17:11:59 -0800298 int pipefds[2];
299 int result = pipe(pipefds);
300 if (result < 0) {
301 ALOGE("dumpDebugInfo: pipe failed: %s", strerror(errno));
Ady Abrahame7385f72021-09-05 00:54:25 -0700302 return {};
303 }
Ady Abrahamc4acf512022-02-18 17:11:59 -0800304
305 std::string str;
yihsing.shen58847c52022-09-23 15:39:30 +0800306 // Use other thread to read pipe to prevent
307 // pipe is full, making HWC be blocked in writing.
308 std::thread t([&]() {
309 base::ReadFdToString(pipefds[0], &str);
310 });
Ady Abrahamc4acf512022-02-18 17:11:59 -0800311 const auto status = mAidlComposer->dump(pipefds[1], /*args*/ nullptr, /*numArgs*/ 0);
312 // Close the write-end of the pipe to make sure that when reading from the
313 // read-end we will get eof instead of blocking forever
314 close(pipefds[1]);
315
yihsing.shen58847c52022-09-23 15:39:30 +0800316 if (status != STATUS_OK) {
Ady Abrahamc4acf512022-02-18 17:11:59 -0800317 ALOGE("dumpDebugInfo: dump failed: %d", status);
318 }
319
yihsing.shen58847c52022-09-23 15:39:30 +0800320 t.join();
Ady Abrahamc4acf512022-02-18 17:11:59 -0800321 close(pipefds[0]);
322 return str;
Ady Abrahame7385f72021-09-05 00:54:25 -0700323}
324
Yichi Chen3401b562022-01-17 15:42:35 +0800325void AidlComposer::registerCallback(HWC2::ComposerCallback& callback) {
Ady Abrahame7385f72021-09-05 00:54:25 -0700326 if (mAidlComposerCallback) {
327 ALOGE("Callback already registered");
328 }
Yichi Chen3401b562022-01-17 15:42:35 +0800329
Ady Abraham9fc28052021-10-14 17:21:38 -0700330 mAidlComposerCallback = ndk::SharedRefBase::make<AidlIComposerCallbackWrapper>(callback);
Ady Abrahame7385f72021-09-05 00:54:25 -0700331 AIBinder_setMinSchedulerPolicy(mAidlComposerCallback->asBinder().get(), SCHED_FIFO, 2);
332
333 const auto status = mAidlComposerClient->registerCallback(mAidlComposerCallback);
334 if (!status.isOk()) {
335 ALOGE("registerCallback failed %s", status.getDescription().c_str());
336 }
337}
338
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400339Error AidlComposer::executeCommands(Display display) {
340 mMutex.lock_shared();
341 auto error = execute(display);
342 mMutex.unlock_shared();
343 return error;
Ady Abrahame7385f72021-09-05 00:54:25 -0700344}
345
346uint32_t AidlComposer::getMaxVirtualDisplayCount() {
347 int32_t count = 0;
348 const auto status = mAidlComposerClient->getMaxVirtualDisplayCount(&count);
349 if (!status.isOk()) {
350 ALOGE("getMaxVirtualDisplayCount failed %s", status.getDescription().c_str());
351 return 0;
352 }
353 return static_cast<uint32_t>(count);
354}
355
356Error AidlComposer::createVirtualDisplay(uint32_t width, uint32_t height, PixelFormat* format,
357 Display* outDisplay) {
358 using AidlPixelFormat = aidl::android::hardware::graphics::common::PixelFormat;
359 const int32_t bufferSlotCount = 1;
360 VirtualDisplay virtualDisplay;
361 const auto status =
362 mAidlComposerClient->createVirtualDisplay(static_cast<int32_t>(width),
363 static_cast<int32_t>(height),
364 static_cast<AidlPixelFormat>(*format),
365 bufferSlotCount, &virtualDisplay);
366
367 if (!status.isOk()) {
368 ALOGE("createVirtualDisplay failed %s", status.getDescription().c_str());
369 return static_cast<Error>(status.getServiceSpecificError());
370 }
371
372 *outDisplay = translate<Display>(virtualDisplay.display);
373 *format = static_cast<PixelFormat>(virtualDisplay.format);
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400374 addDisplay(translate<Display>(virtualDisplay.display));
Ady Abrahame7385f72021-09-05 00:54:25 -0700375 return Error::NONE;
376}
377
378Error AidlComposer::destroyVirtualDisplay(Display display) {
379 const auto status = mAidlComposerClient->destroyVirtualDisplay(translate<int64_t>(display));
380 if (!status.isOk()) {
381 ALOGE("destroyVirtualDisplay failed %s", status.getDescription().c_str());
382 return static_cast<Error>(status.getServiceSpecificError());
383 }
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400384 removeDisplay(display);
Ady Abrahame7385f72021-09-05 00:54:25 -0700385 return Error::NONE;
386}
387
388Error AidlComposer::acceptDisplayChanges(Display display) {
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400389 Error error = Error::NONE;
390 mMutex.lock_shared();
391 if (auto writer = getWriter(display)) {
392 writer->get().acceptDisplayChanges(translate<int64_t>(display));
393 } else {
394 error = Error::BAD_DISPLAY;
395 }
396 mMutex.unlock_shared();
397 return error;
Ady Abrahame7385f72021-09-05 00:54:25 -0700398}
399
400Error AidlComposer::createLayer(Display display, Layer* outLayer) {
401 int64_t layer;
402 const auto status = mAidlComposerClient->createLayer(translate<int64_t>(display),
403 kMaxLayerBufferCount, &layer);
404 if (!status.isOk()) {
405 ALOGE("createLayer failed %s", status.getDescription().c_str());
406 return static_cast<Error>(status.getServiceSpecificError());
407 }
408
409 *outLayer = translate<Layer>(layer);
410 return Error::NONE;
411}
412
413Error AidlComposer::destroyLayer(Display display, Layer layer) {
414 const auto status = mAidlComposerClient->destroyLayer(translate<int64_t>(display),
415 translate<int64_t>(layer));
416 if (!status.isOk()) {
417 ALOGE("destroyLayer failed %s", status.getDescription().c_str());
418 return static_cast<Error>(status.getServiceSpecificError());
419 }
420 return Error::NONE;
421}
422
423Error AidlComposer::getActiveConfig(Display display, Config* outConfig) {
424 int32_t config;
425 const auto status = mAidlComposerClient->getActiveConfig(translate<int64_t>(display), &config);
426 if (!status.isOk()) {
427 ALOGE("getActiveConfig failed %s", status.getDescription().c_str());
428 return static_cast<Error>(status.getServiceSpecificError());
429 }
430 *outConfig = translate<Config>(config);
431 return Error::NONE;
432}
433
434Error AidlComposer::getChangedCompositionTypes(
435 Display display, std::vector<Layer>* outLayers,
Leon Scroggins III2e1aa182021-12-01 17:33:12 -0500436 std::vector<aidl::android::hardware::graphics::composer3::Composition>* outTypes) {
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400437 std::vector<ChangedCompositionLayer> changedLayers;
438 Error error = Error::NONE;
439 {
440 mMutex.lock_shared();
441 if (auto reader = getReader(display)) {
442 changedLayers = reader->get().takeChangedCompositionTypes(translate<int64_t>(display));
443 } else {
444 error = Error::BAD_DISPLAY;
445 }
446 mMutex.unlock_shared();
447 }
Ady Abrahamde792782021-12-20 10:00:49 -0800448 outLayers->reserve(changedLayers.size());
449 outTypes->reserve(changedLayers.size());
Ady Abrahama6388c02021-11-11 21:11:51 -0800450
Ady Abrahamde792782021-12-20 10:00:49 -0800451 for (const auto& layer : changedLayers) {
452 outLayers->emplace_back(translate<Layer>(layer.layer));
453 outTypes->emplace_back(layer.composition);
454 }
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400455 return error;
Ady Abrahame7385f72021-09-05 00:54:25 -0700456}
457
458Error AidlComposer::getColorModes(Display display, std::vector<ColorMode>* outModes) {
459 std::vector<AidlColorMode> modes;
460 const auto status = mAidlComposerClient->getColorModes(translate<int64_t>(display), &modes);
461 if (!status.isOk()) {
462 ALOGE("getColorModes failed %s", status.getDescription().c_str());
463 return static_cast<Error>(status.getServiceSpecificError());
464 }
465 *outModes = translate<ColorMode>(modes);
466 return Error::NONE;
467}
468
469Error AidlComposer::getDisplayAttribute(Display display, Config config,
470 IComposerClient::Attribute attribute, int32_t* outValue) {
471 const auto status =
472 mAidlComposerClient->getDisplayAttribute(translate<int64_t>(display),
473 translate<int32_t>(config),
474 static_cast<AidlDisplayAttribute>(attribute),
475 outValue);
476 if (!status.isOk()) {
477 ALOGE("getDisplayAttribute failed %s", status.getDescription().c_str());
478 return static_cast<Error>(status.getServiceSpecificError());
479 }
480 return Error::NONE;
481}
482
483Error AidlComposer::getDisplayConfigs(Display display, std::vector<Config>* outConfigs) {
484 std::vector<int32_t> configs;
485 const auto status =
486 mAidlComposerClient->getDisplayConfigs(translate<int64_t>(display), &configs);
487 if (!status.isOk()) {
488 ALOGE("getDisplayConfigs failed %s", status.getDescription().c_str());
489 return static_cast<Error>(status.getServiceSpecificError());
490 }
491 *outConfigs = translate<Config>(configs);
492 return Error::NONE;
493}
494
ramindani263a3f12023-07-18 20:44:49 -0700495Error AidlComposer::getDisplayConfigurations(Display display, int32_t maxFrameIntervalNs,
ramindani0cd1d8d2023-06-13 13:43:23 -0700496 std::vector<DisplayConfiguration>* outConfigs) {
497 const auto status =
ramindani263a3f12023-07-18 20:44:49 -0700498 mAidlComposerClient->getDisplayConfigurations(translate<int64_t>(display),
499 maxFrameIntervalNs, outConfigs);
ramindani0cd1d8d2023-06-13 13:43:23 -0700500 if (!status.isOk()) {
501 ALOGE("getDisplayConfigurations failed %s", status.getDescription().c_str());
502 return static_cast<Error>(status.getServiceSpecificError());
503 }
504
505 return Error::NONE;
506}
507
Ady Abrahame7385f72021-09-05 00:54:25 -0700508Error AidlComposer::getDisplayName(Display display, std::string* outName) {
509 const auto status = mAidlComposerClient->getDisplayName(translate<int64_t>(display), outName);
510 if (!status.isOk()) {
511 ALOGE("getDisplayName failed %s", status.getDescription().c_str());
512 return static_cast<Error>(status.getServiceSpecificError());
513 }
514 return Error::NONE;
515}
516
517Error AidlComposer::getDisplayRequests(Display display, uint32_t* outDisplayRequestMask,
518 std::vector<Layer>* outLayers,
519 std::vector<uint32_t>* outLayerRequestMasks) {
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400520 Error error = Error::NONE;
521 DisplayRequest displayRequests;
522 {
523 mMutex.lock_shared();
524 if (auto reader = getReader(display)) {
525 displayRequests = reader->get().takeDisplayRequests(translate<int64_t>(display));
526 } else {
527 error = Error::BAD_DISPLAY;
528 }
529 mMutex.unlock_shared();
530 }
Ady Abrahamde792782021-12-20 10:00:49 -0800531 *outDisplayRequestMask = translate<uint32_t>(displayRequests.mask);
532 outLayers->reserve(displayRequests.layerRequests.size());
533 outLayerRequestMasks->reserve(displayRequests.layerRequests.size());
534
535 for (const auto& layer : displayRequests.layerRequests) {
536 outLayers->emplace_back(translate<Layer>(layer.layer));
537 outLayerRequestMasks->emplace_back(translate<uint32_t>(layer.mask));
538 }
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400539 return error;
Ady Abrahame7385f72021-09-05 00:54:25 -0700540}
541
542Error AidlComposer::getDozeSupport(Display display, bool* outSupport) {
Ady Abraham33b92b92021-12-08 18:30:27 -0800543 std::vector<AidlDisplayCapability> capabilities;
Ady Abrahame7385f72021-09-05 00:54:25 -0700544 const auto status =
Ady Abraham33b92b92021-12-08 18:30:27 -0800545 mAidlComposerClient->getDisplayCapabilities(translate<int64_t>(display), &capabilities);
Ady Abrahame7385f72021-09-05 00:54:25 -0700546 if (!status.isOk()) {
Ady Abraham33b92b92021-12-08 18:30:27 -0800547 ALOGE("getDisplayCapabilities failed %s", status.getDescription().c_str());
Ady Abrahame7385f72021-09-05 00:54:25 -0700548 return static_cast<Error>(status.getServiceSpecificError());
549 }
Ady Abraham33b92b92021-12-08 18:30:27 -0800550 *outSupport = std::find(capabilities.begin(), capabilities.end(),
551 AidlDisplayCapability::DOZE) != capabilities.end();
Ady Abrahame7385f72021-09-05 00:54:25 -0700552 return Error::NONE;
553}
554
ramindani32cf0602022-03-02 02:30:29 +0000555Error AidlComposer::hasDisplayIdleTimerCapability(Display display, bool* outSupport) {
556 std::vector<AidlDisplayCapability> capabilities;
557 const auto status =
558 mAidlComposerClient->getDisplayCapabilities(translate<int64_t>(display), &capabilities);
559 if (!status.isOk()) {
560 ALOGE("getDisplayCapabilities failed %s", status.getDescription().c_str());
561 return static_cast<Error>(status.getServiceSpecificError());
562 }
563 *outSupport = std::find(capabilities.begin(), capabilities.end(),
564 AidlDisplayCapability::DISPLAY_IDLE_TIMER) != capabilities.end();
565 return Error::NONE;
566}
567
Ady Abrahame7385f72021-09-05 00:54:25 -0700568Error AidlComposer::getHdrCapabilities(Display display, std::vector<Hdr>* outTypes,
569 float* outMaxLuminance, float* outMaxAverageLuminance,
570 float* outMinLuminance) {
571 AidlHdrCapabilities capabilities;
572 const auto status =
573 mAidlComposerClient->getHdrCapabilities(translate<int64_t>(display), &capabilities);
574 if (!status.isOk()) {
575 ALOGE("getHdrCapabilities failed %s", status.getDescription().c_str());
576 return static_cast<Error>(status.getServiceSpecificError());
577 }
578
Marc Kassisbdf7e4b2022-11-04 17:26:48 +0100579 *outTypes = capabilities.types;
Ady Abrahame7385f72021-09-05 00:54:25 -0700580 *outMaxLuminance = capabilities.maxLuminance;
581 *outMaxAverageLuminance = capabilities.maxAverageLuminance;
582 *outMinLuminance = capabilities.minLuminance;
583 return Error::NONE;
584}
585
Sally Qibb866c12022-10-17 11:31:20 -0700586Error AidlComposer::getOverlaySupport(AidlOverlayProperties* outProperties) {
587 const auto status = mAidlComposerClient->getOverlaySupport(outProperties);
588 if (!status.isOk()) {
589 ALOGE("getOverlaySupport failed %s", status.getDescription().c_str());
590 return static_cast<Error>(status.getServiceSpecificError());
591 }
Sally Qi0cbd08b2022-08-17 12:12:28 -0700592 return Error::NONE;
593}
594
Ady Abrahame7385f72021-09-05 00:54:25 -0700595Error AidlComposer::getReleaseFences(Display display, std::vector<Layer>* outLayers,
596 std::vector<int>* outReleaseFences) {
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400597 Error error = Error::NONE;
598 std::vector<ReleaseFences::Layer> fences;
599 {
600 mMutex.lock_shared();
601 if (auto reader = getReader(display)) {
602 fences = reader->get().takeReleaseFences(translate<int64_t>(display));
603 } else {
604 error = Error::BAD_DISPLAY;
605 }
606 mMutex.unlock_shared();
607 }
Ady Abrahamde792782021-12-20 10:00:49 -0800608 outLayers->reserve(fences.size());
609 outReleaseFences->reserve(fences.size());
610
611 for (auto& fence : fences) {
612 outLayers->emplace_back(translate<Layer>(fence.layer));
613 // take ownership
614 const int fenceOwner = fence.fence.get();
615 *fence.fence.getR() = -1;
616 outReleaseFences->emplace_back(fenceOwner);
617 }
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400618 return error;
Ady Abrahame7385f72021-09-05 00:54:25 -0700619}
620
621Error AidlComposer::presentDisplay(Display display, int* outPresentFence) {
Leon Scroggins IIIe85e16e2022-12-12 12:51:18 -0500622 const auto displayId = translate<int64_t>(display);
623 ATRACE_FORMAT("HwcPresentDisplay %" PRId64, displayId);
624
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400625 Error error = Error::NONE;
626 mMutex.lock_shared();
627 auto writer = getWriter(display);
628 auto reader = getReader(display);
629 if (writer && reader) {
Leon Scroggins IIIe85e16e2022-12-12 12:51:18 -0500630 writer->get().presentDisplay(displayId);
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400631 error = execute(display);
632 } else {
633 error = Error::BAD_DISPLAY;
634 }
Ady Abrahame7385f72021-09-05 00:54:25 -0700635
Ady Abrahame7385f72021-09-05 00:54:25 -0700636 if (error != Error::NONE) {
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400637 mMutex.unlock_shared();
Ady Abrahame7385f72021-09-05 00:54:25 -0700638 return error;
639 }
640
Leon Scroggins IIIe85e16e2022-12-12 12:51:18 -0500641 auto fence = reader->get().takePresentFence(displayId);
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400642 mMutex.unlock_shared();
Ady Abrahamde792782021-12-20 10:00:49 -0800643 // take ownership
644 *outPresentFence = fence.get();
645 *fence.getR() = -1;
Ady Abrahame7385f72021-09-05 00:54:25 -0700646 return Error::NONE;
647}
648
649Error AidlComposer::setActiveConfig(Display display, Config config) {
650 const auto status = mAidlComposerClient->setActiveConfig(translate<int64_t>(display),
651 translate<int32_t>(config));
652 if (!status.isOk()) {
653 ALOGE("setActiveConfig failed %s", status.getDescription().c_str());
654 return static_cast<Error>(status.getServiceSpecificError());
655 }
656 return Error::NONE;
657}
658
659Error AidlComposer::setClientTarget(Display display, uint32_t slot, const sp<GraphicBuffer>& target,
660 int acquireFence, Dataspace dataspace,
661 const std::vector<IComposerClient::Rect>& damage) {
Ady Abrahame7385f72021-09-05 00:54:25 -0700662 const native_handle_t* handle = nullptr;
663 if (target.get()) {
664 handle = target->getNativeBuffer()->handle;
665 }
666
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400667 Error error = Error::NONE;
668 mMutex.lock_shared();
669 if (auto writer = getWriter(display)) {
670 writer->get()
671 .setClientTarget(translate<int64_t>(display), slot, handle, acquireFence,
672 translate<aidl::android::hardware::graphics::common::Dataspace>(
673 dataspace),
674 translate<AidlRect>(damage));
675 } else {
676 error = Error::BAD_DISPLAY;
677 }
678 mMutex.unlock_shared();
679 return error;
Ady Abrahame7385f72021-09-05 00:54:25 -0700680}
681
682Error AidlComposer::setColorMode(Display display, ColorMode mode, RenderIntent renderIntent) {
683 const auto status =
684 mAidlComposerClient->setColorMode(translate<int64_t>(display),
685 translate<AidlColorMode>(mode),
686 translate<AidlRenderIntent>(renderIntent));
687 if (!status.isOk()) {
688 ALOGE("setColorMode failed %s", status.getDescription().c_str());
689 return static_cast<Error>(status.getServiceSpecificError());
690 }
691 return Error::NONE;
692}
693
Ady Abrahamdc011a92021-12-21 14:06:44 -0800694Error AidlComposer::setColorTransform(Display display, const float* matrix) {
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400695 auto error = Error::NONE;
696 mMutex.lock_shared();
697 if (auto writer = getWriter(display)) {
698 writer->get().setColorTransform(translate<int64_t>(display), matrix);
699 } else {
700 error = Error::BAD_DISPLAY;
701 }
702 mMutex.unlock_shared();
703 return error;
Ady Abrahame7385f72021-09-05 00:54:25 -0700704}
705
706Error AidlComposer::setOutputBuffer(Display display, const native_handle_t* buffer,
707 int releaseFence) {
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400708 auto error = Error::NONE;
709 mMutex.lock_shared();
710 if (auto writer = getWriter(display)) {
711 writer->get().setOutputBuffer(translate<int64_t>(display), 0, buffer, dup(releaseFence));
712 } else {
713 error = Error::BAD_DISPLAY;
714 }
715 mMutex.unlock_shared();
716 return error;
Ady Abrahame7385f72021-09-05 00:54:25 -0700717}
718
719Error AidlComposer::setPowerMode(Display display, IComposerClient::PowerMode mode) {
720 const auto status = mAidlComposerClient->setPowerMode(translate<int64_t>(display),
721 translate<PowerMode>(mode));
722 if (!status.isOk()) {
723 ALOGE("setPowerMode failed %s", status.getDescription().c_str());
724 return static_cast<Error>(status.getServiceSpecificError());
725 }
726 return Error::NONE;
727}
728
729Error AidlComposer::setVsyncEnabled(Display display, IComposerClient::Vsync enabled) {
730 const bool enableVsync = enabled == IComposerClient::Vsync::ENABLE;
731 const auto status =
732 mAidlComposerClient->setVsyncEnabled(translate<int64_t>(display), enableVsync);
733 if (!status.isOk()) {
734 ALOGE("setVsyncEnabled failed %s", status.getDescription().c_str());
735 return static_cast<Error>(status.getServiceSpecificError());
736 }
737 return Error::NONE;
738}
739
740Error AidlComposer::setClientTargetSlotCount(Display display) {
741 const int32_t bufferSlotCount = BufferQueue::NUM_BUFFER_SLOTS;
742 const auto status = mAidlComposerClient->setClientTargetSlotCount(translate<int64_t>(display),
743 bufferSlotCount);
744 if (!status.isOk()) {
745 ALOGE("setClientTargetSlotCount failed %s", status.getDescription().c_str());
746 return static_cast<Error>(status.getServiceSpecificError());
747 }
748 return Error::NONE;
749}
750
Ady Abraham43065bd2021-12-10 17:22:15 -0800751Error AidlComposer::validateDisplay(Display display, nsecs_t expectedPresentTime,
752 uint32_t* outNumTypes, uint32_t* outNumRequests) {
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400753 const auto displayId = translate<int64_t>(display);
Leon Scroggins IIIe85e16e2022-12-12 12:51:18 -0500754 ATRACE_FORMAT("HwcValidateDisplay %" PRId64, displayId);
755
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400756 Error error = Error::NONE;
757 mMutex.lock_shared();
758 auto writer = getWriter(display);
759 auto reader = getReader(display);
760 if (writer && reader) {
761 writer->get().validateDisplay(displayId, ClockMonotonicTimestamp{expectedPresentTime});
762 error = execute(display);
763 } else {
764 error = Error::BAD_DISPLAY;
765 }
Ady Abrahame7385f72021-09-05 00:54:25 -0700766
Ady Abrahame7385f72021-09-05 00:54:25 -0700767 if (error != Error::NONE) {
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400768 mMutex.unlock_shared();
Ady Abrahame7385f72021-09-05 00:54:25 -0700769 return error;
770 }
771
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400772 reader->get().hasChanges(displayId, outNumTypes, outNumRequests);
Ady Abrahame7385f72021-09-05 00:54:25 -0700773
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400774 mMutex.unlock_shared();
Ady Abrahame7385f72021-09-05 00:54:25 -0700775 return Error::NONE;
776}
777
Ady Abraham43065bd2021-12-10 17:22:15 -0800778Error AidlComposer::presentOrValidateDisplay(Display display, nsecs_t expectedPresentTime,
779 uint32_t* outNumTypes, uint32_t* outNumRequests,
780 int* outPresentFence, uint32_t* state) {
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400781 const auto displayId = translate<int64_t>(display);
Leon Scroggins IIIe85e16e2022-12-12 12:51:18 -0500782 ATRACE_FORMAT("HwcPresentOrValidateDisplay %" PRId64, displayId);
783
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400784 Error error = Error::NONE;
785 mMutex.lock_shared();
786 auto writer = getWriter(display);
787 auto reader = getReader(display);
788 if (writer && reader) {
789 writer->get().presentOrvalidateDisplay(displayId,
790 ClockMonotonicTimestamp{expectedPresentTime});
791 error = execute(display);
792 } else {
793 error = Error::BAD_DISPLAY;
794 }
Ady Abrahame7385f72021-09-05 00:54:25 -0700795
Ady Abrahame7385f72021-09-05 00:54:25 -0700796 if (error != Error::NONE) {
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400797 mMutex.unlock_shared();
Ady Abrahame7385f72021-09-05 00:54:25 -0700798 return error;
799 }
800
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400801 const auto result = reader->get().takePresentOrValidateStage(displayId);
Ady Abrahamde792782021-12-20 10:00:49 -0800802 if (!result.has_value()) {
803 *state = translate<uint32_t>(-1);
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400804 mMutex.unlock_shared();
Ady Abrahamde792782021-12-20 10:00:49 -0800805 return Error::NO_RESOURCES;
Ady Abrahame7385f72021-09-05 00:54:25 -0700806 }
807
Ady Abrahamde792782021-12-20 10:00:49 -0800808 *state = translate<uint32_t>(*result);
809
810 if (*result == PresentOrValidate::Result::Presented) {
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400811 auto fence = reader->get().takePresentFence(displayId);
Ady Abrahamde792782021-12-20 10:00:49 -0800812 // take ownership
813 *outPresentFence = fence.get();
814 *fence.getR() = -1;
815 }
816
817 if (*result == PresentOrValidate::Result::Validated) {
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400818 reader->get().hasChanges(displayId, outNumTypes, outNumRequests);
Ady Abrahame7385f72021-09-05 00:54:25 -0700819 }
820
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400821 mMutex.unlock_shared();
Ady Abrahame7385f72021-09-05 00:54:25 -0700822 return Error::NONE;
823}
824
825Error AidlComposer::setCursorPosition(Display display, Layer layer, int32_t x, int32_t y) {
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400826 Error error = Error::NONE;
827 mMutex.lock_shared();
828 if (auto writer = getWriter(display)) {
829 writer->get().setLayerCursorPosition(translate<int64_t>(display), translate<int64_t>(layer),
830 x, y);
831 } else {
832 error = Error::BAD_DISPLAY;
833 }
834 mMutex.unlock_shared();
835 return error;
Ady Abrahame7385f72021-09-05 00:54:25 -0700836}
837
838Error AidlComposer::setLayerBuffer(Display display, Layer layer, uint32_t slot,
839 const sp<GraphicBuffer>& buffer, int acquireFence) {
Ady Abrahame7385f72021-09-05 00:54:25 -0700840 const native_handle_t* handle = nullptr;
841 if (buffer.get()) {
842 handle = buffer->getNativeBuffer()->handle;
843 }
844
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400845 Error error = Error::NONE;
846 mMutex.lock_shared();
847 if (auto writer = getWriter(display)) {
848 writer->get().setLayerBuffer(translate<int64_t>(display), translate<int64_t>(layer), slot,
849 handle, acquireFence);
850 } else {
851 error = Error::BAD_DISPLAY;
852 }
853 mMutex.unlock_shared();
854 return error;
Ady Abrahame7385f72021-09-05 00:54:25 -0700855}
856
Brian Lindahlb158a5c2022-12-15 15:21:13 -0700857Error AidlComposer::setLayerBufferSlotsToClear(Display display, Layer layer,
858 const std::vector<uint32_t>& slotsToClear,
859 uint32_t activeBufferSlot) {
860 if (slotsToClear.empty()) {
861 return Error::NONE;
862 }
863
Brian Lindahl90553da2022-12-06 13:36:30 -0700864 Error error = Error::NONE;
865 mMutex.lock_shared();
866 if (auto writer = getWriter(display)) {
ramindani0cd1d8d2023-06-13 13:43:23 -0700867 if (mComposerInterfaceVersion > 1) {
Brian Lindahldbf7e3a2022-12-16 11:43:39 -0700868 writer->get().setLayerBufferSlotsToClear(translate<int64_t>(display),
869 translate<int64_t>(layer), slotsToClear);
Brian Lindahl5b0ffe02023-06-15 14:19:43 -0600870 // Backwards compatible way of clearing buffer slots is to set the layer buffer with a
871 // placeholder buffer, using the slot that needs to cleared... tricky.
872 } else if (mClearSlotBuffer != nullptr) {
Brian Lindahldbf7e3a2022-12-16 11:43:39 -0700873 for (uint32_t slot : slotsToClear) {
874 // Don't clear the active buffer slot because we need to restore the active buffer
875 // after clearing the requested buffer slots with a placeholder buffer.
876 if (slot != activeBufferSlot) {
877 writer->get().setLayerBufferWithNewCommand(translate<int64_t>(display),
878 translate<int64_t>(layer), slot,
879 mClearSlotBuffer->handle,
880 /*fence*/ -1);
881 }
Brian Lindahlb158a5c2022-12-15 15:21:13 -0700882 }
Brian Lindahldbf7e3a2022-12-16 11:43:39 -0700883 // Since we clear buffers by setting them to a placeholder buffer, we want to make
884 // sure that the last setLayerBuffer command is sent with the currently active
885 // buffer, not the placeholder buffer, so that there is no perceptual change when
886 // buffers are discarded.
887 writer->get().setLayerBufferWithNewCommand(translate<int64_t>(display),
888 translate<int64_t>(layer), activeBufferSlot,
889 // The active buffer is still cached in
890 // its slot and doesn't need a fence.
891 /*buffer*/ nullptr, /*fence*/ -1);
Brian Lindahlb158a5c2022-12-15 15:21:13 -0700892 }
Brian Lindahl90553da2022-12-06 13:36:30 -0700893 } else {
894 error = Error::BAD_DISPLAY;
895 }
896 mMutex.unlock_shared();
897 return error;
898}
899
Ady Abrahame7385f72021-09-05 00:54:25 -0700900Error AidlComposer::setLayerSurfaceDamage(Display display, Layer layer,
901 const std::vector<IComposerClient::Rect>& damage) {
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400902 Error error = Error::NONE;
903 mMutex.lock_shared();
904 if (auto writer = getWriter(display)) {
905 writer->get().setLayerSurfaceDamage(translate<int64_t>(display), translate<int64_t>(layer),
906 translate<AidlRect>(damage));
907 } else {
908 error = Error::BAD_DISPLAY;
909 }
910 mMutex.unlock_shared();
911 return error;
Ady Abrahame7385f72021-09-05 00:54:25 -0700912}
913
914Error AidlComposer::setLayerBlendMode(Display display, Layer layer,
915 IComposerClient::BlendMode mode) {
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400916 Error error = Error::NONE;
917 mMutex.lock_shared();
918 if (auto writer = getWriter(display)) {
919 writer->get().setLayerBlendMode(translate<int64_t>(display), translate<int64_t>(layer),
920 translate<BlendMode>(mode));
921 } else {
922 error = Error::BAD_DISPLAY;
923 }
924 mMutex.unlock_shared();
925 return error;
Ady Abrahame7385f72021-09-05 00:54:25 -0700926}
927
Ady Abraham6e60b142022-01-06 18:10:35 -0800928Error AidlComposer::setLayerColor(Display display, Layer layer, const Color& color) {
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400929 Error error = Error::NONE;
930 mMutex.lock_shared();
931 if (auto writer = getWriter(display)) {
932 writer->get().setLayerColor(translate<int64_t>(display), translate<int64_t>(layer), color);
933 } else {
934 error = Error::BAD_DISPLAY;
935 }
936 mMutex.unlock_shared();
937 return error;
Ady Abrahame7385f72021-09-05 00:54:25 -0700938}
939
Leon Scroggins III2e1aa182021-12-01 17:33:12 -0500940Error AidlComposer::setLayerCompositionType(
941 Display display, Layer layer,
942 aidl::android::hardware::graphics::composer3::Composition type) {
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400943 Error error = Error::NONE;
944 mMutex.lock_shared();
945 if (auto writer = getWriter(display)) {
946 writer->get().setLayerCompositionType(translate<int64_t>(display),
947 translate<int64_t>(layer), type);
948 } else {
949 error = Error::BAD_DISPLAY;
950 }
951 mMutex.unlock_shared();
952 return error;
Ady Abrahame7385f72021-09-05 00:54:25 -0700953}
954
955Error AidlComposer::setLayerDataspace(Display display, Layer layer, Dataspace dataspace) {
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400956 Error error = Error::NONE;
957 mMutex.lock_shared();
958 if (auto writer = getWriter(display)) {
959 writer->get().setLayerDataspace(translate<int64_t>(display), translate<int64_t>(layer),
960 translate<AidlDataspace>(dataspace));
961 } else {
962 error = Error::BAD_DISPLAY;
963 }
964 mMutex.unlock_shared();
965 return error;
Ady Abrahame7385f72021-09-05 00:54:25 -0700966}
967
968Error AidlComposer::setLayerDisplayFrame(Display display, Layer layer,
969 const IComposerClient::Rect& frame) {
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400970 Error error = Error::NONE;
971 mMutex.lock_shared();
972 if (auto writer = getWriter(display)) {
973 writer->get().setLayerDisplayFrame(translate<int64_t>(display), translate<int64_t>(layer),
974 translate<AidlRect>(frame));
975 } else {
976 error = Error::BAD_DISPLAY;
977 }
978 mMutex.unlock_shared();
979 return error;
Ady Abrahame7385f72021-09-05 00:54:25 -0700980}
981
982Error AidlComposer::setLayerPlaneAlpha(Display display, Layer layer, float alpha) {
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400983 Error error = Error::NONE;
984 mMutex.lock_shared();
985 if (auto writer = getWriter(display)) {
986 writer->get().setLayerPlaneAlpha(translate<int64_t>(display), translate<int64_t>(layer),
987 alpha);
988 } else {
989 error = Error::BAD_DISPLAY;
990 }
991 mMutex.unlock_shared();
992 return error;
Ady Abrahame7385f72021-09-05 00:54:25 -0700993}
994
995Error AidlComposer::setLayerSidebandStream(Display display, Layer layer,
996 const native_handle_t* stream) {
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400997 Error error = Error::NONE;
998 mMutex.lock_shared();
999 if (auto writer = getWriter(display)) {
1000 writer->get().setLayerSidebandStream(translate<int64_t>(display), translate<int64_t>(layer),
1001 stream);
1002 } else {
1003 error = Error::BAD_DISPLAY;
1004 }
1005 mMutex.unlock_shared();
1006 return error;
Ady Abrahame7385f72021-09-05 00:54:25 -07001007}
1008
1009Error AidlComposer::setLayerSourceCrop(Display display, Layer layer,
1010 const IComposerClient::FRect& crop) {
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -04001011 Error error = Error::NONE;
1012 mMutex.lock_shared();
1013 if (auto writer = getWriter(display)) {
1014 writer->get().setLayerSourceCrop(translate<int64_t>(display), translate<int64_t>(layer),
1015 translate<AidlFRect>(crop));
1016 } else {
1017 error = Error::BAD_DISPLAY;
1018 }
1019 mMutex.unlock_shared();
1020 return error;
Ady Abrahame7385f72021-09-05 00:54:25 -07001021}
1022
1023Error AidlComposer::setLayerTransform(Display display, Layer layer, Transform transform) {
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -04001024 Error error = Error::NONE;
1025 mMutex.lock_shared();
1026 if (auto writer = getWriter(display)) {
1027 writer->get().setLayerTransform(translate<int64_t>(display), translate<int64_t>(layer),
1028 translate<AidlTransform>(transform));
1029 } else {
1030 error = Error::BAD_DISPLAY;
1031 }
1032 mMutex.unlock_shared();
1033 return error;
Ady Abrahame7385f72021-09-05 00:54:25 -07001034}
1035
1036Error AidlComposer::setLayerVisibleRegion(Display display, Layer layer,
1037 const std::vector<IComposerClient::Rect>& visible) {
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -04001038 Error error = Error::NONE;
1039 mMutex.lock_shared();
1040 if (auto writer = getWriter(display)) {
1041 writer->get().setLayerVisibleRegion(translate<int64_t>(display), translate<int64_t>(layer),
1042 translate<AidlRect>(visible));
1043 } else {
1044 error = Error::BAD_DISPLAY;
1045 }
1046 mMutex.unlock_shared();
1047 return error;
Ady Abrahame7385f72021-09-05 00:54:25 -07001048}
1049
1050Error AidlComposer::setLayerZOrder(Display display, Layer layer, uint32_t z) {
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -04001051 Error error = Error::NONE;
1052 mMutex.lock_shared();
1053 if (auto writer = getWriter(display)) {
1054 writer->get().setLayerZOrder(translate<int64_t>(display), translate<int64_t>(layer), z);
1055 } else {
1056 error = Error::BAD_DISPLAY;
1057 }
1058 mMutex.unlock_shared();
1059 return error;
Ady Abrahame7385f72021-09-05 00:54:25 -07001060}
1061
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -04001062Error AidlComposer::execute(Display display) {
1063 auto writer = getWriter(display);
1064 auto reader = getReader(display);
1065 if (!writer || !reader) {
1066 return Error::BAD_DISPLAY;
1067 }
1068
Huihong Luoe7382c12023-04-21 20:24:32 +00001069 auto commands = writer->get().takePendingCommands();
Ady Abrahama6388c02021-11-11 21:11:51 -08001070 if (commands.empty()) {
Ady Abrahame7385f72021-09-05 00:54:25 -07001071 return Error::NONE;
1072 }
1073
Ady Abrahamde792782021-12-20 10:00:49 -08001074 { // scope for results
1075 std::vector<CommandResultPayload> results;
1076 auto status = mAidlComposerClient->executeCommands(commands, &results);
1077 if (!status.isOk()) {
1078 ALOGE("executeCommands failed %s", status.getDescription().c_str());
1079 return static_cast<Error>(status.getServiceSpecificError());
1080 }
Ady Abrahame7385f72021-09-05 00:54:25 -07001081
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -04001082 reader->get().parse(std::move(results));
Ady Abrahamde792782021-12-20 10:00:49 -08001083 }
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -04001084 const auto commandErrors = reader->get().takeErrors();
Ady Abrahama6388c02021-11-11 21:11:51 -08001085 Error error = Error::NONE;
1086 for (const auto& cmdErr : commandErrors) {
1087 const auto index = static_cast<size_t>(cmdErr.commandIndex);
1088 if (index < 0 || index >= commands.size()) {
1089 ALOGE("invalid command index %zu", index);
1090 return Error::BAD_PARAMETER;
Ady Abrahame7385f72021-09-05 00:54:25 -07001091 }
1092
Ady Abrahama6388c02021-11-11 21:11:51 -08001093 const auto& command = commands[index];
Ady Abraham42977362021-12-07 21:04:49 -08001094 if (command.validateDisplay || command.presentDisplay || command.presentOrValidateDisplay) {
1095 error = translate<Error>(cmdErr.errorCode);
1096 } else {
1097 ALOGW("command '%s' generated error %" PRId32, command.toString().c_str(),
1098 cmdErr.errorCode);
Ady Abrahame7385f72021-09-05 00:54:25 -07001099 }
1100 }
1101
Ady Abrahame7385f72021-09-05 00:54:25 -07001102 return error;
1103}
1104
1105Error AidlComposer::setLayerPerFrameMetadata(
1106 Display display, Layer layer,
1107 const std::vector<IComposerClient::PerFrameMetadata>& perFrameMetadatas) {
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -04001108 Error error = Error::NONE;
1109 mMutex.lock_shared();
1110 if (auto writer = getWriter(display)) {
1111 writer->get().setLayerPerFrameMetadata(translate<int64_t>(display),
1112 translate<int64_t>(layer),
1113 translate<AidlPerFrameMetadata>(perFrameMetadatas));
1114 } else {
1115 error = Error::BAD_DISPLAY;
1116 }
1117 mMutex.unlock_shared();
1118 return error;
Ady Abrahame7385f72021-09-05 00:54:25 -07001119}
1120
1121std::vector<IComposerClient::PerFrameMetadataKey> AidlComposer::getPerFrameMetadataKeys(
1122 Display display) {
1123 std::vector<AidlPerFrameMetadataKey> keys;
1124 const auto status =
1125 mAidlComposerClient->getPerFrameMetadataKeys(translate<int64_t>(display), &keys);
1126 if (!status.isOk()) {
1127 ALOGE("getPerFrameMetadataKeys failed %s", status.getDescription().c_str());
1128 return {};
1129 }
1130 return translate<IComposerClient::PerFrameMetadataKey>(keys);
1131}
1132
1133Error AidlComposer::getRenderIntents(Display display, ColorMode colorMode,
1134 std::vector<RenderIntent>* outRenderIntents) {
1135 std::vector<AidlRenderIntent> renderIntents;
1136 const auto status = mAidlComposerClient->getRenderIntents(translate<int64_t>(display),
1137 translate<AidlColorMode>(colorMode),
1138 &renderIntents);
1139 if (!status.isOk()) {
1140 ALOGE("getRenderIntents failed %s", status.getDescription().c_str());
1141 return static_cast<Error>(status.getServiceSpecificError());
1142 }
1143 *outRenderIntents = translate<RenderIntent>(renderIntents);
1144 return Error::NONE;
1145}
1146
1147Error AidlComposer::getDataspaceSaturationMatrix(Dataspace dataspace, mat4* outMatrix) {
1148 std::vector<float> matrix;
1149 const auto status =
1150 mAidlComposerClient->getDataspaceSaturationMatrix(translate<AidlDataspace>(dataspace),
1151 &matrix);
1152 if (!status.isOk()) {
1153 ALOGE("getDataspaceSaturationMatrix failed %s", status.getDescription().c_str());
1154 return static_cast<Error>(status.getServiceSpecificError());
1155 }
1156 *outMatrix = makeMat4(matrix);
1157 return Error::NONE;
1158}
1159
1160Error AidlComposer::getDisplayIdentificationData(Display display, uint8_t* outPort,
1161 std::vector<uint8_t>* outData) {
1162 AidlDisplayIdentification displayIdentification;
1163 const auto status =
1164 mAidlComposerClient->getDisplayIdentificationData(translate<int64_t>(display),
1165 &displayIdentification);
1166 if (!status.isOk()) {
1167 ALOGE("getDisplayIdentificationData failed %s", status.getDescription().c_str());
1168 return static_cast<Error>(status.getServiceSpecificError());
1169 }
1170
1171 *outPort = static_cast<uint8_t>(displayIdentification.port);
1172 *outData = displayIdentification.data;
1173
1174 return Error::NONE;
1175}
1176
1177Error AidlComposer::setLayerColorTransform(Display display, Layer layer, const float* matrix) {
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -04001178 Error error = Error::NONE;
1179 mMutex.lock_shared();
1180 if (auto writer = getWriter(display)) {
1181 writer->get().setLayerColorTransform(translate<int64_t>(display), translate<int64_t>(layer),
1182 matrix);
1183 } else {
1184 error = Error::BAD_DISPLAY;
1185 }
1186 mMutex.unlock_shared();
1187 return error;
Ady Abrahame7385f72021-09-05 00:54:25 -07001188}
1189
1190Error AidlComposer::getDisplayedContentSamplingAttributes(Display display, PixelFormat* outFormat,
1191 Dataspace* outDataspace,
1192 uint8_t* outComponentMask) {
1193 if (!outFormat || !outDataspace || !outComponentMask) {
1194 return Error::BAD_PARAMETER;
1195 }
1196
1197 AidlDisplayContentSamplingAttributes attributes;
1198 const auto status =
1199 mAidlComposerClient->getDisplayedContentSamplingAttributes(translate<int64_t>(display),
1200 &attributes);
1201 if (!status.isOk()) {
1202 ALOGE("getDisplayedContentSamplingAttributes failed %s", status.getDescription().c_str());
1203 return static_cast<Error>(status.getServiceSpecificError());
1204 }
1205
1206 *outFormat = translate<PixelFormat>(attributes.format);
1207 *outDataspace = translate<Dataspace>(attributes.dataspace);
1208 *outComponentMask = static_cast<uint8_t>(attributes.componentMask);
1209 return Error::NONE;
1210}
1211
1212Error AidlComposer::setDisplayContentSamplingEnabled(Display display, bool enabled,
1213 uint8_t componentMask, uint64_t maxFrames) {
1214 const auto status =
1215 mAidlComposerClient
1216 ->setDisplayedContentSamplingEnabled(translate<int64_t>(display), enabled,
1217 static_cast<AidlFormatColorComponent>(
1218 componentMask),
1219 static_cast<int64_t>(maxFrames));
1220 if (!status.isOk()) {
1221 ALOGE("setDisplayedContentSamplingEnabled failed %s", status.getDescription().c_str());
1222 return static_cast<Error>(status.getServiceSpecificError());
1223 }
1224 return Error::NONE;
1225}
1226
1227Error AidlComposer::getDisplayedContentSample(Display display, uint64_t maxFrames,
1228 uint64_t timestamp, DisplayedFrameStats* outStats) {
1229 if (!outStats) {
1230 return Error::BAD_PARAMETER;
1231 }
1232
1233 AidlDisplayContentSample sample;
1234 const auto status =
1235 mAidlComposerClient->getDisplayedContentSample(translate<int64_t>(display),
1236 static_cast<int64_t>(maxFrames),
1237 static_cast<int64_t>(timestamp),
1238 &sample);
1239 if (!status.isOk()) {
1240 ALOGE("getDisplayedContentSample failed %s", status.getDescription().c_str());
1241 return static_cast<Error>(status.getServiceSpecificError());
1242 }
1243 *outStats = translate<DisplayedFrameStats>(sample);
1244 return Error::NONE;
1245}
1246
1247Error AidlComposer::setLayerPerFrameMetadataBlobs(
1248 Display display, Layer layer,
1249 const std::vector<IComposerClient::PerFrameMetadataBlob>& metadata) {
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -04001250 Error error = Error::NONE;
1251 mMutex.lock_shared();
1252 if (auto writer = getWriter(display)) {
1253 writer->get().setLayerPerFrameMetadataBlobs(translate<int64_t>(display),
1254 translate<int64_t>(layer),
1255 translate<AidlPerFrameMetadataBlob>(metadata));
1256 } else {
1257 error = Error::BAD_DISPLAY;
1258 }
1259 mMutex.unlock_shared();
1260 return error;
Ady Abrahame7385f72021-09-05 00:54:25 -07001261}
1262
Alec Mouri4d8a05d2022-03-23 18:14:26 +00001263Error AidlComposer::setDisplayBrightness(Display display, float brightness, float brightnessNits,
Alec Mouricdf16792021-12-10 13:16:06 -08001264 const DisplayBrightnessOptions& options) {
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -04001265 Error error = Error::NONE;
1266 mMutex.lock_shared();
1267 if (auto writer = getWriter(display)) {
1268 writer->get().setDisplayBrightness(translate<int64_t>(display), brightness, brightnessNits);
Alec Mouricdf16792021-12-10 13:16:06 -08001269
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -04001270 if (options.applyImmediately) {
1271 error = execute(display);
1272 mMutex.unlock_shared();
1273 return error;
1274 }
1275 } else {
1276 error = Error::BAD_DISPLAY;
Alec Mouricdf16792021-12-10 13:16:06 -08001277 }
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -04001278 mMutex.unlock_shared();
1279 return error;
Ady Abrahame7385f72021-09-05 00:54:25 -07001280}
1281
1282Error AidlComposer::getDisplayCapabilities(Display display,
Leon Scroggins III5967aec2021-12-29 11:14:22 -05001283 std::vector<AidlDisplayCapability>* outCapabilities) {
1284 const auto status = mAidlComposerClient->getDisplayCapabilities(translate<int64_t>(display),
1285 outCapabilities);
Ady Abrahame7385f72021-09-05 00:54:25 -07001286 if (!status.isOk()) {
1287 ALOGE("getDisplayCapabilities failed %s", status.getDescription().c_str());
Leon Scroggins III5967aec2021-12-29 11:14:22 -05001288 outCapabilities->clear();
Ady Abrahame7385f72021-09-05 00:54:25 -07001289 return static_cast<Error>(status.getServiceSpecificError());
1290 }
Ady Abrahame7385f72021-09-05 00:54:25 -07001291 return Error::NONE;
1292}
1293
1294V2_4::Error AidlComposer::getDisplayConnectionType(
1295 Display display, IComposerClient::DisplayConnectionType* outType) {
1296 AidlDisplayConnectionType type;
1297 const auto status =
1298 mAidlComposerClient->getDisplayConnectionType(translate<int64_t>(display), &type);
1299 if (!status.isOk()) {
1300 ALOGE("getDisplayConnectionType failed %s", status.getDescription().c_str());
1301 return static_cast<V2_4::Error>(status.getServiceSpecificError());
1302 }
1303 *outType = translate<IComposerClient::DisplayConnectionType>(type);
1304 return V2_4::Error::NONE;
1305}
1306
1307V2_4::Error AidlComposer::getDisplayVsyncPeriod(Display display, VsyncPeriodNanos* outVsyncPeriod) {
1308 int32_t vsyncPeriod;
1309 const auto status =
1310 mAidlComposerClient->getDisplayVsyncPeriod(translate<int64_t>(display), &vsyncPeriod);
1311 if (!status.isOk()) {
1312 ALOGE("getDisplayVsyncPeriod failed %s", status.getDescription().c_str());
1313 return static_cast<V2_4::Error>(status.getServiceSpecificError());
1314 }
1315 *outVsyncPeriod = translate<VsyncPeriodNanos>(vsyncPeriod);
1316 return V2_4::Error::NONE;
1317}
1318
1319V2_4::Error AidlComposer::setActiveConfigWithConstraints(
1320 Display display, Config config,
1321 const IComposerClient::VsyncPeriodChangeConstraints& vsyncPeriodChangeConstraints,
1322 VsyncPeriodChangeTimeline* outTimeline) {
1323 AidlVsyncPeriodChangeTimeline timeline;
1324 const auto status =
1325 mAidlComposerClient
1326 ->setActiveConfigWithConstraints(translate<int64_t>(display),
1327 translate<int32_t>(config),
1328 translate<AidlVsyncPeriodChangeConstraints>(
1329 vsyncPeriodChangeConstraints),
1330 &timeline);
1331 if (!status.isOk()) {
1332 ALOGE("setActiveConfigWithConstraints failed %s", status.getDescription().c_str());
1333 return static_cast<V2_4::Error>(status.getServiceSpecificError());
1334 }
1335 *outTimeline = translate<VsyncPeriodChangeTimeline>(timeline);
1336 return V2_4::Error::NONE;
1337}
1338
1339V2_4::Error AidlComposer::setAutoLowLatencyMode(Display display, bool on) {
1340 const auto status = mAidlComposerClient->setAutoLowLatencyMode(translate<int64_t>(display), on);
1341 if (!status.isOk()) {
1342 ALOGE("setAutoLowLatencyMode failed %s", status.getDescription().c_str());
1343 return static_cast<V2_4::Error>(status.getServiceSpecificError());
1344 }
1345 return V2_4::Error::NONE;
1346}
1347
1348V2_4::Error AidlComposer::getSupportedContentTypes(
1349 Display displayId, std::vector<IComposerClient::ContentType>* outSupportedContentTypes) {
1350 std::vector<AidlContentType> types;
1351 const auto status =
1352 mAidlComposerClient->getSupportedContentTypes(translate<int64_t>(displayId), &types);
1353 if (!status.isOk()) {
1354 ALOGE("getSupportedContentTypes failed %s", status.getDescription().c_str());
1355 return static_cast<V2_4::Error>(status.getServiceSpecificError());
1356 }
1357 *outSupportedContentTypes = translate<IComposerClient::ContentType>(types);
1358 return V2_4::Error::NONE;
1359}
1360
1361V2_4::Error AidlComposer::setContentType(Display display,
1362 IComposerClient::ContentType contentType) {
1363 const auto status =
1364 mAidlComposerClient->setContentType(translate<int64_t>(display),
1365 translate<AidlContentType>(contentType));
1366 if (!status.isOk()) {
1367 ALOGE("setContentType failed %s", status.getDescription().c_str());
1368 return static_cast<V2_4::Error>(status.getServiceSpecificError());
1369 }
1370 return V2_4::Error::NONE;
1371}
1372
Ady Abraham3f976752021-12-20 16:17:50 -08001373V2_4::Error AidlComposer::setLayerGenericMetadata(Display, Layer, const std::string&, bool,
1374 const std::vector<uint8_t>&) {
1375 // There are no users for this API. See b/209691612.
1376 return V2_4::Error::UNSUPPORTED;
Ady Abrahame7385f72021-09-05 00:54:25 -07001377}
1378
1379V2_4::Error AidlComposer::getLayerGenericMetadataKeys(
Ady Abraham3f976752021-12-20 16:17:50 -08001380 std::vector<IComposerClient::LayerGenericMetadataKey>*) {
1381 // There are no users for this API. See b/209691612.
1382 return V2_4::Error::UNSUPPORTED;
Ady Abrahame7385f72021-09-05 00:54:25 -07001383}
1384
Kriti Dang7defaf32021-11-15 11:55:43 +01001385Error AidlComposer::setBootDisplayConfig(Display display, Config config) {
1386 const auto status = mAidlComposerClient->setBootDisplayConfig(translate<int64_t>(display),
1387 translate<int32_t>(config));
1388 if (!status.isOk()) {
1389 ALOGE("setBootDisplayConfig failed %s", status.getDescription().c_str());
1390 return static_cast<Error>(status.getServiceSpecificError());
1391 }
1392 return Error::NONE;
1393}
1394
1395Error AidlComposer::clearBootDisplayConfig(Display display) {
1396 const auto status = mAidlComposerClient->clearBootDisplayConfig(translate<int64_t>(display));
1397 if (!status.isOk()) {
1398 ALOGE("clearBootDisplayConfig failed %s", status.getDescription().c_str());
1399 return static_cast<Error>(status.getServiceSpecificError());
1400 }
1401 return Error::NONE;
1402}
1403
1404Error AidlComposer::getPreferredBootDisplayConfig(Display display, Config* config) {
1405 int32_t displayConfig;
1406 const auto status =
1407 mAidlComposerClient->getPreferredBootDisplayConfig(translate<int64_t>(display),
1408 &displayConfig);
1409 if (!status.isOk()) {
1410 ALOGE("getPreferredBootDisplayConfig failed %s", status.getDescription().c_str());
1411 return static_cast<Error>(status.getServiceSpecificError());
1412 }
1413 *config = translate<uint32_t>(displayConfig);
1414 return Error::NONE;
1415}
1416
Kriti Dang674b9372022-11-18 10:58:44 +01001417Error AidlComposer::getHdrConversionCapabilities(
1418 std::vector<AidlHdrConversionCapability>* hdrConversionCapabilities) {
1419 const auto status =
1420 mAidlComposerClient->getHdrConversionCapabilities(hdrConversionCapabilities);
1421 if (!status.isOk()) {
1422 hdrConversionCapabilities = {};
1423 ALOGE("getHdrConversionCapabilities failed %s", status.getDescription().c_str());
1424 return static_cast<Error>(status.getServiceSpecificError());
1425 }
1426 return Error::NONE;
1427}
1428
Kriti Dangd432bb52023-02-09 18:21:04 +01001429Error AidlComposer::setHdrConversionStrategy(AidlHdrConversionStrategy hdrConversionStrategy,
1430 Hdr* outPreferredHdrOutputType) {
1431 const auto status = mAidlComposerClient->setHdrConversionStrategy(hdrConversionStrategy,
1432 outPreferredHdrOutputType);
Kriti Dang674b9372022-11-18 10:58:44 +01001433 if (!status.isOk()) {
1434 ALOGE("setHdrConversionStrategy failed %s", status.getDescription().c_str());
1435 return static_cast<Error>(status.getServiceSpecificError());
1436 }
1437 return Error::NONE;
1438}
1439
ramindanib2158ee2023-02-13 20:29:59 -08001440Error AidlComposer::setRefreshRateChangedCallbackDebugEnabled(Display displayId, bool enabled) {
1441 const auto status =
1442 mAidlComposerClient->setRefreshRateChangedCallbackDebugEnabled(translate<int64_t>(
1443 displayId),
1444 enabled);
1445 if (!status.isOk()) {
1446 ALOGE("setRefreshRateChangedCallbackDebugEnabled failed %s",
1447 status.getDescription().c_str());
1448 return static_cast<Error>(status.getServiceSpecificError());
1449 }
1450 return Error::NONE;
1451}
1452
ramindani3acaaf52023-09-25 10:31:27 -07001453Error AidlComposer::notifyExpectedPresent(Display displayId, nsecs_t expectedPresentTime,
1454 int32_t frameIntervalNs) {
1455 const auto status =
1456 mAidlComposerClient->notifyExpectedPresent(translate<int64_t>(displayId),
1457 ClockMonotonicTimestamp{expectedPresentTime},
1458 frameIntervalNs);
1459
1460 if (!status.isOk()) {
1461 ALOGE("notifyExpectedPresent failed %s", status.getDescription().c_str());
1462 return static_cast<Error>(status.getServiceSpecificError());
1463 }
1464 return Error::NONE;
1465}
1466
Ady Abrahame7385f72021-09-05 00:54:25 -07001467Error AidlComposer::getClientTargetProperty(
Alec Mouri85065692022-03-18 00:58:26 +00001468 Display display, ClientTargetPropertyWithBrightness* outClientTargetProperty) {
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -04001469 Error error = Error::NONE;
1470 mMutex.lock_shared();
1471 if (auto reader = getReader(display)) {
1472 *outClientTargetProperty =
1473 reader->get().takeClientTargetProperty(translate<int64_t>(display));
1474 } else {
1475 error = Error::BAD_DISPLAY;
1476 }
1477 mMutex.unlock_shared();
1478 return error;
Ady Abrahame7385f72021-09-05 00:54:25 -07001479}
1480
Alec Mouri6da0e272022-02-07 12:45:57 -08001481Error AidlComposer::setLayerBrightness(Display display, Layer layer, float brightness) {
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -04001482 Error error = Error::NONE;
1483 mMutex.lock_shared();
1484 if (auto writer = getWriter(display)) {
1485 writer->get().setLayerBrightness(translate<int64_t>(display), translate<int64_t>(layer),
1486 brightness);
1487 } else {
1488 error = Error::BAD_DISPLAY;
1489 }
1490 mMutex.unlock_shared();
1491 return error;
Alec Mouricdf6cbc2021-11-01 17:21:15 -07001492}
1493
Leon Scroggins IIId77d3162022-01-05 10:42:28 -05001494Error AidlComposer::setLayerBlockingRegion(Display display, Layer layer,
1495 const std::vector<IComposerClient::Rect>& blocking) {
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -04001496 Error error = Error::NONE;
1497 mMutex.lock_shared();
1498 if (auto writer = getWriter(display)) {
1499 writer->get().setLayerBlockingRegion(translate<int64_t>(display), translate<int64_t>(layer),
1500 translate<AidlRect>(blocking));
1501 } else {
1502 error = Error::BAD_DISPLAY;
1503 }
1504 mMutex.unlock_shared();
1505 return error;
Leon Scroggins IIId77d3162022-01-05 10:42:28 -05001506}
Leon Scroggins IIIe7c51c62022-02-01 15:53:54 -05001507
1508Error AidlComposer::getDisplayDecorationSupport(Display display,
1509 std::optional<DisplayDecorationSupport>* support) {
1510 const auto status =
1511 mAidlComposerClient->getDisplayDecorationSupport(translate<int64_t>(display), support);
1512 if (!status.isOk()) {
1513 ALOGE("getDisplayDecorationSupport failed %s", status.getDescription().c_str());
1514 support->reset();
1515 return static_cast<Error>(status.getServiceSpecificError());
1516 }
1517 return Error::NONE;
1518}
ramindani32cf0602022-03-02 02:30:29 +00001519
1520Error AidlComposer::setIdleTimerEnabled(Display displayId, std::chrono::milliseconds timeout) {
1521 const auto status =
1522 mAidlComposerClient->setIdleTimerEnabled(translate<int64_t>(displayId),
1523 translate<int32_t>(timeout.count()));
1524 if (!status.isOk()) {
1525 ALOGE("setIdleTimerEnabled failed %s", status.getDescription().c_str());
1526 return static_cast<Error>(status.getServiceSpecificError());
1527 }
1528 return Error::NONE;
1529}
1530
ramindani06e518e2022-03-14 18:47:53 +00001531Error AidlComposer::getPhysicalDisplayOrientation(Display displayId,
1532 AidlTransform* outDisplayOrientation) {
1533 const auto status =
1534 mAidlComposerClient->getDisplayPhysicalOrientation(translate<int64_t>(displayId),
1535 outDisplayOrientation);
1536 if (!status.isOk()) {
1537 ALOGE("getPhysicalDisplayOrientation failed %s", status.getDescription().c_str());
1538 return static_cast<Error>(status.getServiceSpecificError());
1539 }
1540 return Error::NONE;
1541}
1542
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -04001543ftl::Optional<std::reference_wrapper<ComposerClientWriter>> AidlComposer::getWriter(Display display)
1544 REQUIRES_SHARED(mMutex) {
1545 return mWriters.get(display);
1546}
1547
1548ftl::Optional<std::reference_wrapper<ComposerClientReader>> AidlComposer::getReader(Display display)
1549 REQUIRES_SHARED(mMutex) {
1550 if (mSingleReader) {
1551 display = translate<Display>(kSingleReaderKey);
1552 }
1553 return mReaders.get(display);
1554}
1555
1556void AidlComposer::removeDisplay(Display display) {
1557 mMutex.lock();
1558 bool wasErased = mWriters.erase(display);
1559 ALOGW_IF(!wasErased,
1560 "Attempting to remove writer for display %" PRId64 " which is not connected",
1561 translate<int64_t>(display));
1562 if (!mSingleReader) {
1563 removeReader(display);
1564 }
1565 mMutex.unlock();
1566}
1567
1568void AidlComposer::onHotplugDisconnect(Display display) {
1569 removeDisplay(display);
1570}
1571
1572bool AidlComposer::hasMultiThreadedPresentSupport(Display display) {
Leon Scroggins IIIc1cf4582023-03-23 18:37:44 -04001573#if 0
1574 // TODO (b/259132483): Reenable
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -04001575 const auto displayId = translate<int64_t>(display);
1576 std::vector<AidlDisplayCapability> capabilities;
1577 const auto status = mAidlComposerClient->getDisplayCapabilities(displayId, &capabilities);
1578 if (!status.isOk()) {
1579 ALOGE("getDisplayCapabilities failed %s", status.getDescription().c_str());
1580 return false;
1581 }
1582 return std::find(capabilities.begin(), capabilities.end(),
1583 AidlDisplayCapability::MULTI_THREADED_PRESENT) != capabilities.end();
Leon Scroggins IIIc1cf4582023-03-23 18:37:44 -04001584#else
1585 (void) display;
1586 return false;
1587#endif
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -04001588}
1589
1590void AidlComposer::addReader(Display display) {
1591 const auto displayId = translate<int64_t>(display);
1592 std::optional<int64_t> displayOpt;
1593 if (displayId != kSingleReaderKey) {
1594 displayOpt.emplace(displayId);
1595 }
1596 auto [it, added] = mReaders.try_emplace(display, std::move(displayOpt));
1597 ALOGW_IF(!added, "Attempting to add writer for display %" PRId64 " which is already connected",
1598 displayId);
1599}
1600
1601void AidlComposer::removeReader(Display display) {
1602 bool wasErased = mReaders.erase(display);
1603 ALOGW_IF(!wasErased,
1604 "Attempting to remove reader for display %" PRId64 " which is not connected",
1605 translate<int64_t>(display));
1606}
1607
1608void AidlComposer::addDisplay(Display display) {
1609 const auto displayId = translate<int64_t>(display);
1610 mMutex.lock();
1611 auto [it, added] = mWriters.try_emplace(display, displayId);
1612 ALOGW_IF(!added, "Attempting to add writer for display %" PRId64 " which is already connected",
1613 displayId);
1614 if (mSingleReader) {
1615 if (hasMultiThreadedPresentSupport(display)) {
1616 mSingleReader = false;
1617 removeReader(translate<Display>(kSingleReaderKey));
1618 // Note that this includes the new display.
1619 for (const auto& [existingDisplay, _] : mWriters) {
1620 addReader(existingDisplay);
1621 }
1622 }
1623 } else {
1624 addReader(display);
1625 }
1626 mMutex.unlock();
1627}
1628
1629void AidlComposer::onHotplugConnect(Display display) {
1630 addDisplay(display);
1631}
Ady Abrahame7385f72021-09-05 00:54:25 -07001632} // namespace Hwc2
1633} // namespace android