blob: 311820c3ed0193e88b12b15626c9c0aa4631554e [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
ramindani0cd1d8d2023-06-13 13:43:23 -0700495Error AidlComposer::getDisplayConfigurations(Display display,
496 std::vector<DisplayConfiguration>* outConfigs) {
497 const auto status =
498 mAidlComposerClient->getDisplayConfigurations(translate<int64_t>(display), outConfigs);
499 if (!status.isOk()) {
500 ALOGE("getDisplayConfigurations failed %s", status.getDescription().c_str());
501 return static_cast<Error>(status.getServiceSpecificError());
502 }
503
504 return Error::NONE;
505}
506
Ady Abrahame7385f72021-09-05 00:54:25 -0700507Error AidlComposer::getDisplayName(Display display, std::string* outName) {
508 const auto status = mAidlComposerClient->getDisplayName(translate<int64_t>(display), outName);
509 if (!status.isOk()) {
510 ALOGE("getDisplayName failed %s", status.getDescription().c_str());
511 return static_cast<Error>(status.getServiceSpecificError());
512 }
513 return Error::NONE;
514}
515
516Error AidlComposer::getDisplayRequests(Display display, uint32_t* outDisplayRequestMask,
517 std::vector<Layer>* outLayers,
518 std::vector<uint32_t>* outLayerRequestMasks) {
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400519 Error error = Error::NONE;
520 DisplayRequest displayRequests;
521 {
522 mMutex.lock_shared();
523 if (auto reader = getReader(display)) {
524 displayRequests = reader->get().takeDisplayRequests(translate<int64_t>(display));
525 } else {
526 error = Error::BAD_DISPLAY;
527 }
528 mMutex.unlock_shared();
529 }
Ady Abrahamde792782021-12-20 10:00:49 -0800530 *outDisplayRequestMask = translate<uint32_t>(displayRequests.mask);
531 outLayers->reserve(displayRequests.layerRequests.size());
532 outLayerRequestMasks->reserve(displayRequests.layerRequests.size());
533
534 for (const auto& layer : displayRequests.layerRequests) {
535 outLayers->emplace_back(translate<Layer>(layer.layer));
536 outLayerRequestMasks->emplace_back(translate<uint32_t>(layer.mask));
537 }
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400538 return error;
Ady Abrahame7385f72021-09-05 00:54:25 -0700539}
540
541Error AidlComposer::getDozeSupport(Display display, bool* outSupport) {
Ady Abraham33b92b92021-12-08 18:30:27 -0800542 std::vector<AidlDisplayCapability> capabilities;
Ady Abrahame7385f72021-09-05 00:54:25 -0700543 const auto status =
Ady Abraham33b92b92021-12-08 18:30:27 -0800544 mAidlComposerClient->getDisplayCapabilities(translate<int64_t>(display), &capabilities);
Ady Abrahame7385f72021-09-05 00:54:25 -0700545 if (!status.isOk()) {
Ady Abraham33b92b92021-12-08 18:30:27 -0800546 ALOGE("getDisplayCapabilities failed %s", status.getDescription().c_str());
Ady Abrahame7385f72021-09-05 00:54:25 -0700547 return static_cast<Error>(status.getServiceSpecificError());
548 }
Ady Abraham33b92b92021-12-08 18:30:27 -0800549 *outSupport = std::find(capabilities.begin(), capabilities.end(),
550 AidlDisplayCapability::DOZE) != capabilities.end();
Ady Abrahame7385f72021-09-05 00:54:25 -0700551 return Error::NONE;
552}
553
ramindani32cf0602022-03-02 02:30:29 +0000554Error AidlComposer::hasDisplayIdleTimerCapability(Display display, bool* outSupport) {
555 std::vector<AidlDisplayCapability> capabilities;
556 const auto status =
557 mAidlComposerClient->getDisplayCapabilities(translate<int64_t>(display), &capabilities);
558 if (!status.isOk()) {
559 ALOGE("getDisplayCapabilities failed %s", status.getDescription().c_str());
560 return static_cast<Error>(status.getServiceSpecificError());
561 }
562 *outSupport = std::find(capabilities.begin(), capabilities.end(),
563 AidlDisplayCapability::DISPLAY_IDLE_TIMER) != capabilities.end();
564 return Error::NONE;
565}
566
Ady Abrahame7385f72021-09-05 00:54:25 -0700567Error AidlComposer::getHdrCapabilities(Display display, std::vector<Hdr>* outTypes,
568 float* outMaxLuminance, float* outMaxAverageLuminance,
569 float* outMinLuminance) {
570 AidlHdrCapabilities capabilities;
571 const auto status =
572 mAidlComposerClient->getHdrCapabilities(translate<int64_t>(display), &capabilities);
573 if (!status.isOk()) {
574 ALOGE("getHdrCapabilities failed %s", status.getDescription().c_str());
575 return static_cast<Error>(status.getServiceSpecificError());
576 }
577
Marc Kassisbdf7e4b2022-11-04 17:26:48 +0100578 *outTypes = capabilities.types;
Ady Abrahame7385f72021-09-05 00:54:25 -0700579 *outMaxLuminance = capabilities.maxLuminance;
580 *outMaxAverageLuminance = capabilities.maxAverageLuminance;
581 *outMinLuminance = capabilities.minLuminance;
582 return Error::NONE;
583}
584
Sally Qibb866c12022-10-17 11:31:20 -0700585Error AidlComposer::getOverlaySupport(AidlOverlayProperties* outProperties) {
586 const auto status = mAidlComposerClient->getOverlaySupport(outProperties);
587 if (!status.isOk()) {
588 ALOGE("getOverlaySupport failed %s", status.getDescription().c_str());
589 return static_cast<Error>(status.getServiceSpecificError());
590 }
Sally Qi0cbd08b2022-08-17 12:12:28 -0700591 return Error::NONE;
592}
593
Ady Abrahame7385f72021-09-05 00:54:25 -0700594Error AidlComposer::getReleaseFences(Display display, std::vector<Layer>* outLayers,
595 std::vector<int>* outReleaseFences) {
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400596 Error error = Error::NONE;
597 std::vector<ReleaseFences::Layer> fences;
598 {
599 mMutex.lock_shared();
600 if (auto reader = getReader(display)) {
601 fences = reader->get().takeReleaseFences(translate<int64_t>(display));
602 } else {
603 error = Error::BAD_DISPLAY;
604 }
605 mMutex.unlock_shared();
606 }
Ady Abrahamde792782021-12-20 10:00:49 -0800607 outLayers->reserve(fences.size());
608 outReleaseFences->reserve(fences.size());
609
610 for (auto& fence : fences) {
611 outLayers->emplace_back(translate<Layer>(fence.layer));
612 // take ownership
613 const int fenceOwner = fence.fence.get();
614 *fence.fence.getR() = -1;
615 outReleaseFences->emplace_back(fenceOwner);
616 }
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400617 return error;
Ady Abrahame7385f72021-09-05 00:54:25 -0700618}
619
620Error AidlComposer::presentDisplay(Display display, int* outPresentFence) {
Leon Scroggins IIIe85e16e2022-12-12 12:51:18 -0500621 const auto displayId = translate<int64_t>(display);
622 ATRACE_FORMAT("HwcPresentDisplay %" PRId64, displayId);
623
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400624 Error error = Error::NONE;
625 mMutex.lock_shared();
626 auto writer = getWriter(display);
627 auto reader = getReader(display);
628 if (writer && reader) {
Leon Scroggins IIIe85e16e2022-12-12 12:51:18 -0500629 writer->get().presentDisplay(displayId);
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400630 error = execute(display);
631 } else {
632 error = Error::BAD_DISPLAY;
633 }
Ady Abrahame7385f72021-09-05 00:54:25 -0700634
Ady Abrahame7385f72021-09-05 00:54:25 -0700635 if (error != Error::NONE) {
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400636 mMutex.unlock_shared();
Ady Abrahame7385f72021-09-05 00:54:25 -0700637 return error;
638 }
639
Leon Scroggins IIIe85e16e2022-12-12 12:51:18 -0500640 auto fence = reader->get().takePresentFence(displayId);
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400641 mMutex.unlock_shared();
Ady Abrahamde792782021-12-20 10:00:49 -0800642 // take ownership
643 *outPresentFence = fence.get();
644 *fence.getR() = -1;
Ady Abrahame7385f72021-09-05 00:54:25 -0700645 return Error::NONE;
646}
647
648Error AidlComposer::setActiveConfig(Display display, Config config) {
649 const auto status = mAidlComposerClient->setActiveConfig(translate<int64_t>(display),
650 translate<int32_t>(config));
651 if (!status.isOk()) {
652 ALOGE("setActiveConfig failed %s", status.getDescription().c_str());
653 return static_cast<Error>(status.getServiceSpecificError());
654 }
655 return Error::NONE;
656}
657
658Error AidlComposer::setClientTarget(Display display, uint32_t slot, const sp<GraphicBuffer>& target,
659 int acquireFence, Dataspace dataspace,
660 const std::vector<IComposerClient::Rect>& damage) {
Ady Abrahame7385f72021-09-05 00:54:25 -0700661 const native_handle_t* handle = nullptr;
662 if (target.get()) {
663 handle = target->getNativeBuffer()->handle;
664 }
665
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400666 Error error = Error::NONE;
667 mMutex.lock_shared();
668 if (auto writer = getWriter(display)) {
669 writer->get()
670 .setClientTarget(translate<int64_t>(display), slot, handle, acquireFence,
671 translate<aidl::android::hardware::graphics::common::Dataspace>(
672 dataspace),
673 translate<AidlRect>(damage));
674 } else {
675 error = Error::BAD_DISPLAY;
676 }
677 mMutex.unlock_shared();
678 return error;
Ady Abrahame7385f72021-09-05 00:54:25 -0700679}
680
681Error AidlComposer::setColorMode(Display display, ColorMode mode, RenderIntent renderIntent) {
682 const auto status =
683 mAidlComposerClient->setColorMode(translate<int64_t>(display),
684 translate<AidlColorMode>(mode),
685 translate<AidlRenderIntent>(renderIntent));
686 if (!status.isOk()) {
687 ALOGE("setColorMode failed %s", status.getDescription().c_str());
688 return static_cast<Error>(status.getServiceSpecificError());
689 }
690 return Error::NONE;
691}
692
Ady Abrahamdc011a92021-12-21 14:06:44 -0800693Error AidlComposer::setColorTransform(Display display, const float* matrix) {
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400694 auto error = Error::NONE;
695 mMutex.lock_shared();
696 if (auto writer = getWriter(display)) {
697 writer->get().setColorTransform(translate<int64_t>(display), matrix);
698 } else {
699 error = Error::BAD_DISPLAY;
700 }
701 mMutex.unlock_shared();
702 return error;
Ady Abrahame7385f72021-09-05 00:54:25 -0700703}
704
705Error AidlComposer::setOutputBuffer(Display display, const native_handle_t* buffer,
706 int releaseFence) {
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400707 auto error = Error::NONE;
708 mMutex.lock_shared();
709 if (auto writer = getWriter(display)) {
710 writer->get().setOutputBuffer(translate<int64_t>(display), 0, buffer, dup(releaseFence));
711 } else {
712 error = Error::BAD_DISPLAY;
713 }
714 mMutex.unlock_shared();
715 return error;
Ady Abrahame7385f72021-09-05 00:54:25 -0700716}
717
718Error AidlComposer::setPowerMode(Display display, IComposerClient::PowerMode mode) {
719 const auto status = mAidlComposerClient->setPowerMode(translate<int64_t>(display),
720 translate<PowerMode>(mode));
721 if (!status.isOk()) {
722 ALOGE("setPowerMode failed %s", status.getDescription().c_str());
723 return static_cast<Error>(status.getServiceSpecificError());
724 }
725 return Error::NONE;
726}
727
728Error AidlComposer::setVsyncEnabled(Display display, IComposerClient::Vsync enabled) {
729 const bool enableVsync = enabled == IComposerClient::Vsync::ENABLE;
730 const auto status =
731 mAidlComposerClient->setVsyncEnabled(translate<int64_t>(display), enableVsync);
732 if (!status.isOk()) {
733 ALOGE("setVsyncEnabled failed %s", status.getDescription().c_str());
734 return static_cast<Error>(status.getServiceSpecificError());
735 }
736 return Error::NONE;
737}
738
739Error AidlComposer::setClientTargetSlotCount(Display display) {
740 const int32_t bufferSlotCount = BufferQueue::NUM_BUFFER_SLOTS;
741 const auto status = mAidlComposerClient->setClientTargetSlotCount(translate<int64_t>(display),
742 bufferSlotCount);
743 if (!status.isOk()) {
744 ALOGE("setClientTargetSlotCount failed %s", status.getDescription().c_str());
745 return static_cast<Error>(status.getServiceSpecificError());
746 }
747 return Error::NONE;
748}
749
Ady Abraham43065bd2021-12-10 17:22:15 -0800750Error AidlComposer::validateDisplay(Display display, nsecs_t expectedPresentTime,
751 uint32_t* outNumTypes, uint32_t* outNumRequests) {
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400752 const auto displayId = translate<int64_t>(display);
Leon Scroggins IIIe85e16e2022-12-12 12:51:18 -0500753 ATRACE_FORMAT("HwcValidateDisplay %" PRId64, displayId);
754
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400755 Error error = Error::NONE;
756 mMutex.lock_shared();
757 auto writer = getWriter(display);
758 auto reader = getReader(display);
759 if (writer && reader) {
760 writer->get().validateDisplay(displayId, ClockMonotonicTimestamp{expectedPresentTime});
761 error = execute(display);
762 } else {
763 error = Error::BAD_DISPLAY;
764 }
Ady Abrahame7385f72021-09-05 00:54:25 -0700765
Ady Abrahame7385f72021-09-05 00:54:25 -0700766 if (error != Error::NONE) {
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400767 mMutex.unlock_shared();
Ady Abrahame7385f72021-09-05 00:54:25 -0700768 return error;
769 }
770
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400771 reader->get().hasChanges(displayId, outNumTypes, outNumRequests);
Ady Abrahame7385f72021-09-05 00:54:25 -0700772
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400773 mMutex.unlock_shared();
Ady Abrahame7385f72021-09-05 00:54:25 -0700774 return Error::NONE;
775}
776
Ady Abraham43065bd2021-12-10 17:22:15 -0800777Error AidlComposer::presentOrValidateDisplay(Display display, nsecs_t expectedPresentTime,
778 uint32_t* outNumTypes, uint32_t* outNumRequests,
779 int* outPresentFence, uint32_t* state) {
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400780 const auto displayId = translate<int64_t>(display);
Leon Scroggins IIIe85e16e2022-12-12 12:51:18 -0500781 ATRACE_FORMAT("HwcPresentOrValidateDisplay %" PRId64, displayId);
782
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400783 Error error = Error::NONE;
784 mMutex.lock_shared();
785 auto writer = getWriter(display);
786 auto reader = getReader(display);
787 if (writer && reader) {
788 writer->get().presentOrvalidateDisplay(displayId,
789 ClockMonotonicTimestamp{expectedPresentTime});
790 error = execute(display);
791 } else {
792 error = Error::BAD_DISPLAY;
793 }
Ady Abrahame7385f72021-09-05 00:54:25 -0700794
Ady Abrahame7385f72021-09-05 00:54:25 -0700795 if (error != Error::NONE) {
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400796 mMutex.unlock_shared();
Ady Abrahame7385f72021-09-05 00:54:25 -0700797 return error;
798 }
799
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400800 const auto result = reader->get().takePresentOrValidateStage(displayId);
Ady Abrahamde792782021-12-20 10:00:49 -0800801 if (!result.has_value()) {
802 *state = translate<uint32_t>(-1);
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400803 mMutex.unlock_shared();
Ady Abrahamde792782021-12-20 10:00:49 -0800804 return Error::NO_RESOURCES;
Ady Abrahame7385f72021-09-05 00:54:25 -0700805 }
806
Ady Abrahamde792782021-12-20 10:00:49 -0800807 *state = translate<uint32_t>(*result);
808
809 if (*result == PresentOrValidate::Result::Presented) {
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400810 auto fence = reader->get().takePresentFence(displayId);
Ady Abrahamde792782021-12-20 10:00:49 -0800811 // take ownership
812 *outPresentFence = fence.get();
813 *fence.getR() = -1;
814 }
815
816 if (*result == PresentOrValidate::Result::Validated) {
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400817 reader->get().hasChanges(displayId, outNumTypes, outNumRequests);
Ady Abrahame7385f72021-09-05 00:54:25 -0700818 }
819
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400820 mMutex.unlock_shared();
Ady Abrahame7385f72021-09-05 00:54:25 -0700821 return Error::NONE;
822}
823
824Error AidlComposer::setCursorPosition(Display display, Layer layer, int32_t x, int32_t y) {
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400825 Error error = Error::NONE;
826 mMutex.lock_shared();
827 if (auto writer = getWriter(display)) {
828 writer->get().setLayerCursorPosition(translate<int64_t>(display), translate<int64_t>(layer),
829 x, y);
830 } else {
831 error = Error::BAD_DISPLAY;
832 }
833 mMutex.unlock_shared();
834 return error;
Ady Abrahame7385f72021-09-05 00:54:25 -0700835}
836
837Error AidlComposer::setLayerBuffer(Display display, Layer layer, uint32_t slot,
838 const sp<GraphicBuffer>& buffer, int acquireFence) {
Ady Abrahame7385f72021-09-05 00:54:25 -0700839 const native_handle_t* handle = nullptr;
840 if (buffer.get()) {
841 handle = buffer->getNativeBuffer()->handle;
842 }
843
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400844 Error error = Error::NONE;
845 mMutex.lock_shared();
846 if (auto writer = getWriter(display)) {
847 writer->get().setLayerBuffer(translate<int64_t>(display), translate<int64_t>(layer), slot,
848 handle, acquireFence);
849 } else {
850 error = Error::BAD_DISPLAY;
851 }
852 mMutex.unlock_shared();
853 return error;
Ady Abrahame7385f72021-09-05 00:54:25 -0700854}
855
Brian Lindahlb158a5c2022-12-15 15:21:13 -0700856Error AidlComposer::setLayerBufferSlotsToClear(Display display, Layer layer,
857 const std::vector<uint32_t>& slotsToClear,
858 uint32_t activeBufferSlot) {
859 if (slotsToClear.empty()) {
860 return Error::NONE;
861 }
862
Brian Lindahl90553da2022-12-06 13:36:30 -0700863 Error error = Error::NONE;
864 mMutex.lock_shared();
865 if (auto writer = getWriter(display)) {
ramindani0cd1d8d2023-06-13 13:43:23 -0700866 if (mComposerInterfaceVersion > 1) {
Brian Lindahldbf7e3a2022-12-16 11:43:39 -0700867 writer->get().setLayerBufferSlotsToClear(translate<int64_t>(display),
868 translate<int64_t>(layer), slotsToClear);
Brian Lindahl5b0ffe02023-06-15 14:19:43 -0600869 // Backwards compatible way of clearing buffer slots is to set the layer buffer with a
870 // placeholder buffer, using the slot that needs to cleared... tricky.
871 } else if (mClearSlotBuffer != nullptr) {
Brian Lindahldbf7e3a2022-12-16 11:43:39 -0700872 for (uint32_t slot : slotsToClear) {
873 // Don't clear the active buffer slot because we need to restore the active buffer
874 // after clearing the requested buffer slots with a placeholder buffer.
875 if (slot != activeBufferSlot) {
876 writer->get().setLayerBufferWithNewCommand(translate<int64_t>(display),
877 translate<int64_t>(layer), slot,
878 mClearSlotBuffer->handle,
879 /*fence*/ -1);
880 }
Brian Lindahlb158a5c2022-12-15 15:21:13 -0700881 }
Brian Lindahldbf7e3a2022-12-16 11:43:39 -0700882 // Since we clear buffers by setting them to a placeholder buffer, we want to make
883 // sure that the last setLayerBuffer command is sent with the currently active
884 // buffer, not the placeholder buffer, so that there is no perceptual change when
885 // buffers are discarded.
886 writer->get().setLayerBufferWithNewCommand(translate<int64_t>(display),
887 translate<int64_t>(layer), activeBufferSlot,
888 // The active buffer is still cached in
889 // its slot and doesn't need a fence.
890 /*buffer*/ nullptr, /*fence*/ -1);
Brian Lindahlb158a5c2022-12-15 15:21:13 -0700891 }
Brian Lindahl90553da2022-12-06 13:36:30 -0700892 } else {
893 error = Error::BAD_DISPLAY;
894 }
895 mMutex.unlock_shared();
896 return error;
897}
898
Ady Abrahame7385f72021-09-05 00:54:25 -0700899Error AidlComposer::setLayerSurfaceDamage(Display display, Layer layer,
900 const std::vector<IComposerClient::Rect>& damage) {
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400901 Error error = Error::NONE;
902 mMutex.lock_shared();
903 if (auto writer = getWriter(display)) {
904 writer->get().setLayerSurfaceDamage(translate<int64_t>(display), translate<int64_t>(layer),
905 translate<AidlRect>(damage));
906 } else {
907 error = Error::BAD_DISPLAY;
908 }
909 mMutex.unlock_shared();
910 return error;
Ady Abrahame7385f72021-09-05 00:54:25 -0700911}
912
913Error AidlComposer::setLayerBlendMode(Display display, Layer layer,
914 IComposerClient::BlendMode mode) {
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400915 Error error = Error::NONE;
916 mMutex.lock_shared();
917 if (auto writer = getWriter(display)) {
918 writer->get().setLayerBlendMode(translate<int64_t>(display), translate<int64_t>(layer),
919 translate<BlendMode>(mode));
920 } else {
921 error = Error::BAD_DISPLAY;
922 }
923 mMutex.unlock_shared();
924 return error;
Ady Abrahame7385f72021-09-05 00:54:25 -0700925}
926
Ady Abraham6e60b142022-01-06 18:10:35 -0800927Error AidlComposer::setLayerColor(Display display, Layer layer, const Color& color) {
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400928 Error error = Error::NONE;
929 mMutex.lock_shared();
930 if (auto writer = getWriter(display)) {
931 writer->get().setLayerColor(translate<int64_t>(display), translate<int64_t>(layer), color);
932 } else {
933 error = Error::BAD_DISPLAY;
934 }
935 mMutex.unlock_shared();
936 return error;
Ady Abrahame7385f72021-09-05 00:54:25 -0700937}
938
Leon Scroggins III2e1aa182021-12-01 17:33:12 -0500939Error AidlComposer::setLayerCompositionType(
940 Display display, Layer layer,
941 aidl::android::hardware::graphics::composer3::Composition type) {
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400942 Error error = Error::NONE;
943 mMutex.lock_shared();
944 if (auto writer = getWriter(display)) {
945 writer->get().setLayerCompositionType(translate<int64_t>(display),
946 translate<int64_t>(layer), type);
947 } else {
948 error = Error::BAD_DISPLAY;
949 }
950 mMutex.unlock_shared();
951 return error;
Ady Abrahame7385f72021-09-05 00:54:25 -0700952}
953
954Error AidlComposer::setLayerDataspace(Display display, Layer layer, Dataspace dataspace) {
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400955 Error error = Error::NONE;
956 mMutex.lock_shared();
957 if (auto writer = getWriter(display)) {
958 writer->get().setLayerDataspace(translate<int64_t>(display), translate<int64_t>(layer),
959 translate<AidlDataspace>(dataspace));
960 } else {
961 error = Error::BAD_DISPLAY;
962 }
963 mMutex.unlock_shared();
964 return error;
Ady Abrahame7385f72021-09-05 00:54:25 -0700965}
966
967Error AidlComposer::setLayerDisplayFrame(Display display, Layer layer,
968 const IComposerClient::Rect& frame) {
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400969 Error error = Error::NONE;
970 mMutex.lock_shared();
971 if (auto writer = getWriter(display)) {
972 writer->get().setLayerDisplayFrame(translate<int64_t>(display), translate<int64_t>(layer),
973 translate<AidlRect>(frame));
974 } else {
975 error = Error::BAD_DISPLAY;
976 }
977 mMutex.unlock_shared();
978 return error;
Ady Abrahame7385f72021-09-05 00:54:25 -0700979}
980
981Error AidlComposer::setLayerPlaneAlpha(Display display, Layer layer, float alpha) {
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400982 Error error = Error::NONE;
983 mMutex.lock_shared();
984 if (auto writer = getWriter(display)) {
985 writer->get().setLayerPlaneAlpha(translate<int64_t>(display), translate<int64_t>(layer),
986 alpha);
987 } else {
988 error = Error::BAD_DISPLAY;
989 }
990 mMutex.unlock_shared();
991 return error;
Ady Abrahame7385f72021-09-05 00:54:25 -0700992}
993
994Error AidlComposer::setLayerSidebandStream(Display display, Layer layer,
995 const native_handle_t* stream) {
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400996 Error error = Error::NONE;
997 mMutex.lock_shared();
998 if (auto writer = getWriter(display)) {
999 writer->get().setLayerSidebandStream(translate<int64_t>(display), translate<int64_t>(layer),
1000 stream);
1001 } else {
1002 error = Error::BAD_DISPLAY;
1003 }
1004 mMutex.unlock_shared();
1005 return error;
Ady Abrahame7385f72021-09-05 00:54:25 -07001006}
1007
1008Error AidlComposer::setLayerSourceCrop(Display display, Layer layer,
1009 const IComposerClient::FRect& crop) {
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -04001010 Error error = Error::NONE;
1011 mMutex.lock_shared();
1012 if (auto writer = getWriter(display)) {
1013 writer->get().setLayerSourceCrop(translate<int64_t>(display), translate<int64_t>(layer),
1014 translate<AidlFRect>(crop));
1015 } else {
1016 error = Error::BAD_DISPLAY;
1017 }
1018 mMutex.unlock_shared();
1019 return error;
Ady Abrahame7385f72021-09-05 00:54:25 -07001020}
1021
1022Error AidlComposer::setLayerTransform(Display display, Layer layer, Transform transform) {
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -04001023 Error error = Error::NONE;
1024 mMutex.lock_shared();
1025 if (auto writer = getWriter(display)) {
1026 writer->get().setLayerTransform(translate<int64_t>(display), translate<int64_t>(layer),
1027 translate<AidlTransform>(transform));
1028 } else {
1029 error = Error::BAD_DISPLAY;
1030 }
1031 mMutex.unlock_shared();
1032 return error;
Ady Abrahame7385f72021-09-05 00:54:25 -07001033}
1034
1035Error AidlComposer::setLayerVisibleRegion(Display display, Layer layer,
1036 const std::vector<IComposerClient::Rect>& visible) {
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -04001037 Error error = Error::NONE;
1038 mMutex.lock_shared();
1039 if (auto writer = getWriter(display)) {
1040 writer->get().setLayerVisibleRegion(translate<int64_t>(display), translate<int64_t>(layer),
1041 translate<AidlRect>(visible));
1042 } else {
1043 error = Error::BAD_DISPLAY;
1044 }
1045 mMutex.unlock_shared();
1046 return error;
Ady Abrahame7385f72021-09-05 00:54:25 -07001047}
1048
1049Error AidlComposer::setLayerZOrder(Display display, Layer layer, uint32_t z) {
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -04001050 Error error = Error::NONE;
1051 mMutex.lock_shared();
1052 if (auto writer = getWriter(display)) {
1053 writer->get().setLayerZOrder(translate<int64_t>(display), translate<int64_t>(layer), z);
1054 } else {
1055 error = Error::BAD_DISPLAY;
1056 }
1057 mMutex.unlock_shared();
1058 return error;
Ady Abrahame7385f72021-09-05 00:54:25 -07001059}
1060
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -04001061Error AidlComposer::execute(Display display) {
1062 auto writer = getWriter(display);
1063 auto reader = getReader(display);
1064 if (!writer || !reader) {
1065 return Error::BAD_DISPLAY;
1066 }
1067
Huihong Luoe7382c12023-04-21 20:24:32 +00001068 auto commands = writer->get().takePendingCommands();
Ady Abrahama6388c02021-11-11 21:11:51 -08001069 if (commands.empty()) {
Ady Abrahame7385f72021-09-05 00:54:25 -07001070 return Error::NONE;
1071 }
1072
Ady Abrahamde792782021-12-20 10:00:49 -08001073 { // scope for results
1074 std::vector<CommandResultPayload> results;
1075 auto status = mAidlComposerClient->executeCommands(commands, &results);
1076 if (!status.isOk()) {
1077 ALOGE("executeCommands failed %s", status.getDescription().c_str());
1078 return static_cast<Error>(status.getServiceSpecificError());
1079 }
Ady Abrahame7385f72021-09-05 00:54:25 -07001080
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -04001081 reader->get().parse(std::move(results));
Ady Abrahamde792782021-12-20 10:00:49 -08001082 }
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -04001083 const auto commandErrors = reader->get().takeErrors();
Ady Abrahama6388c02021-11-11 21:11:51 -08001084 Error error = Error::NONE;
1085 for (const auto& cmdErr : commandErrors) {
1086 const auto index = static_cast<size_t>(cmdErr.commandIndex);
1087 if (index < 0 || index >= commands.size()) {
1088 ALOGE("invalid command index %zu", index);
1089 return Error::BAD_PARAMETER;
Ady Abrahame7385f72021-09-05 00:54:25 -07001090 }
1091
Ady Abrahama6388c02021-11-11 21:11:51 -08001092 const auto& command = commands[index];
Ady Abraham42977362021-12-07 21:04:49 -08001093 if (command.validateDisplay || command.presentDisplay || command.presentOrValidateDisplay) {
1094 error = translate<Error>(cmdErr.errorCode);
1095 } else {
1096 ALOGW("command '%s' generated error %" PRId32, command.toString().c_str(),
1097 cmdErr.errorCode);
Ady Abrahame7385f72021-09-05 00:54:25 -07001098 }
1099 }
1100
Ady Abrahame7385f72021-09-05 00:54:25 -07001101 return error;
1102}
1103
1104Error AidlComposer::setLayerPerFrameMetadata(
1105 Display display, Layer layer,
1106 const std::vector<IComposerClient::PerFrameMetadata>& perFrameMetadatas) {
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -04001107 Error error = Error::NONE;
1108 mMutex.lock_shared();
1109 if (auto writer = getWriter(display)) {
1110 writer->get().setLayerPerFrameMetadata(translate<int64_t>(display),
1111 translate<int64_t>(layer),
1112 translate<AidlPerFrameMetadata>(perFrameMetadatas));
1113 } else {
1114 error = Error::BAD_DISPLAY;
1115 }
1116 mMutex.unlock_shared();
1117 return error;
Ady Abrahame7385f72021-09-05 00:54:25 -07001118}
1119
1120std::vector<IComposerClient::PerFrameMetadataKey> AidlComposer::getPerFrameMetadataKeys(
1121 Display display) {
1122 std::vector<AidlPerFrameMetadataKey> keys;
1123 const auto status =
1124 mAidlComposerClient->getPerFrameMetadataKeys(translate<int64_t>(display), &keys);
1125 if (!status.isOk()) {
1126 ALOGE("getPerFrameMetadataKeys failed %s", status.getDescription().c_str());
1127 return {};
1128 }
1129 return translate<IComposerClient::PerFrameMetadataKey>(keys);
1130}
1131
1132Error AidlComposer::getRenderIntents(Display display, ColorMode colorMode,
1133 std::vector<RenderIntent>* outRenderIntents) {
1134 std::vector<AidlRenderIntent> renderIntents;
1135 const auto status = mAidlComposerClient->getRenderIntents(translate<int64_t>(display),
1136 translate<AidlColorMode>(colorMode),
1137 &renderIntents);
1138 if (!status.isOk()) {
1139 ALOGE("getRenderIntents failed %s", status.getDescription().c_str());
1140 return static_cast<Error>(status.getServiceSpecificError());
1141 }
1142 *outRenderIntents = translate<RenderIntent>(renderIntents);
1143 return Error::NONE;
1144}
1145
1146Error AidlComposer::getDataspaceSaturationMatrix(Dataspace dataspace, mat4* outMatrix) {
1147 std::vector<float> matrix;
1148 const auto status =
1149 mAidlComposerClient->getDataspaceSaturationMatrix(translate<AidlDataspace>(dataspace),
1150 &matrix);
1151 if (!status.isOk()) {
1152 ALOGE("getDataspaceSaturationMatrix failed %s", status.getDescription().c_str());
1153 return static_cast<Error>(status.getServiceSpecificError());
1154 }
1155 *outMatrix = makeMat4(matrix);
1156 return Error::NONE;
1157}
1158
1159Error AidlComposer::getDisplayIdentificationData(Display display, uint8_t* outPort,
1160 std::vector<uint8_t>* outData) {
1161 AidlDisplayIdentification displayIdentification;
1162 const auto status =
1163 mAidlComposerClient->getDisplayIdentificationData(translate<int64_t>(display),
1164 &displayIdentification);
1165 if (!status.isOk()) {
1166 ALOGE("getDisplayIdentificationData failed %s", status.getDescription().c_str());
1167 return static_cast<Error>(status.getServiceSpecificError());
1168 }
1169
1170 *outPort = static_cast<uint8_t>(displayIdentification.port);
1171 *outData = displayIdentification.data;
1172
1173 return Error::NONE;
1174}
1175
1176Error AidlComposer::setLayerColorTransform(Display display, Layer layer, const float* matrix) {
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -04001177 Error error = Error::NONE;
1178 mMutex.lock_shared();
1179 if (auto writer = getWriter(display)) {
1180 writer->get().setLayerColorTransform(translate<int64_t>(display), translate<int64_t>(layer),
1181 matrix);
1182 } else {
1183 error = Error::BAD_DISPLAY;
1184 }
1185 mMutex.unlock_shared();
1186 return error;
Ady Abrahame7385f72021-09-05 00:54:25 -07001187}
1188
1189Error AidlComposer::getDisplayedContentSamplingAttributes(Display display, PixelFormat* outFormat,
1190 Dataspace* outDataspace,
1191 uint8_t* outComponentMask) {
1192 if (!outFormat || !outDataspace || !outComponentMask) {
1193 return Error::BAD_PARAMETER;
1194 }
1195
1196 AidlDisplayContentSamplingAttributes attributes;
1197 const auto status =
1198 mAidlComposerClient->getDisplayedContentSamplingAttributes(translate<int64_t>(display),
1199 &attributes);
1200 if (!status.isOk()) {
1201 ALOGE("getDisplayedContentSamplingAttributes failed %s", status.getDescription().c_str());
1202 return static_cast<Error>(status.getServiceSpecificError());
1203 }
1204
1205 *outFormat = translate<PixelFormat>(attributes.format);
1206 *outDataspace = translate<Dataspace>(attributes.dataspace);
1207 *outComponentMask = static_cast<uint8_t>(attributes.componentMask);
1208 return Error::NONE;
1209}
1210
1211Error AidlComposer::setDisplayContentSamplingEnabled(Display display, bool enabled,
1212 uint8_t componentMask, uint64_t maxFrames) {
1213 const auto status =
1214 mAidlComposerClient
1215 ->setDisplayedContentSamplingEnabled(translate<int64_t>(display), enabled,
1216 static_cast<AidlFormatColorComponent>(
1217 componentMask),
1218 static_cast<int64_t>(maxFrames));
1219 if (!status.isOk()) {
1220 ALOGE("setDisplayedContentSamplingEnabled failed %s", status.getDescription().c_str());
1221 return static_cast<Error>(status.getServiceSpecificError());
1222 }
1223 return Error::NONE;
1224}
1225
1226Error AidlComposer::getDisplayedContentSample(Display display, uint64_t maxFrames,
1227 uint64_t timestamp, DisplayedFrameStats* outStats) {
1228 if (!outStats) {
1229 return Error::BAD_PARAMETER;
1230 }
1231
1232 AidlDisplayContentSample sample;
1233 const auto status =
1234 mAidlComposerClient->getDisplayedContentSample(translate<int64_t>(display),
1235 static_cast<int64_t>(maxFrames),
1236 static_cast<int64_t>(timestamp),
1237 &sample);
1238 if (!status.isOk()) {
1239 ALOGE("getDisplayedContentSample failed %s", status.getDescription().c_str());
1240 return static_cast<Error>(status.getServiceSpecificError());
1241 }
1242 *outStats = translate<DisplayedFrameStats>(sample);
1243 return Error::NONE;
1244}
1245
1246Error AidlComposer::setLayerPerFrameMetadataBlobs(
1247 Display display, Layer layer,
1248 const std::vector<IComposerClient::PerFrameMetadataBlob>& metadata) {
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -04001249 Error error = Error::NONE;
1250 mMutex.lock_shared();
1251 if (auto writer = getWriter(display)) {
1252 writer->get().setLayerPerFrameMetadataBlobs(translate<int64_t>(display),
1253 translate<int64_t>(layer),
1254 translate<AidlPerFrameMetadataBlob>(metadata));
1255 } else {
1256 error = Error::BAD_DISPLAY;
1257 }
1258 mMutex.unlock_shared();
1259 return error;
Ady Abrahame7385f72021-09-05 00:54:25 -07001260}
1261
Alec Mouri4d8a05d2022-03-23 18:14:26 +00001262Error AidlComposer::setDisplayBrightness(Display display, float brightness, float brightnessNits,
Alec Mouricdf16792021-12-10 13:16:06 -08001263 const DisplayBrightnessOptions& options) {
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -04001264 Error error = Error::NONE;
1265 mMutex.lock_shared();
1266 if (auto writer = getWriter(display)) {
1267 writer->get().setDisplayBrightness(translate<int64_t>(display), brightness, brightnessNits);
Alec Mouricdf16792021-12-10 13:16:06 -08001268
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -04001269 if (options.applyImmediately) {
1270 error = execute(display);
1271 mMutex.unlock_shared();
1272 return error;
1273 }
1274 } else {
1275 error = Error::BAD_DISPLAY;
Alec Mouricdf16792021-12-10 13:16:06 -08001276 }
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -04001277 mMutex.unlock_shared();
1278 return error;
Ady Abrahame7385f72021-09-05 00:54:25 -07001279}
1280
1281Error AidlComposer::getDisplayCapabilities(Display display,
Leon Scroggins III5967aec2021-12-29 11:14:22 -05001282 std::vector<AidlDisplayCapability>* outCapabilities) {
1283 const auto status = mAidlComposerClient->getDisplayCapabilities(translate<int64_t>(display),
1284 outCapabilities);
Ady Abrahame7385f72021-09-05 00:54:25 -07001285 if (!status.isOk()) {
1286 ALOGE("getDisplayCapabilities failed %s", status.getDescription().c_str());
Leon Scroggins III5967aec2021-12-29 11:14:22 -05001287 outCapabilities->clear();
Ady Abrahame7385f72021-09-05 00:54:25 -07001288 return static_cast<Error>(status.getServiceSpecificError());
1289 }
Ady Abrahame7385f72021-09-05 00:54:25 -07001290 return Error::NONE;
1291}
1292
1293V2_4::Error AidlComposer::getDisplayConnectionType(
1294 Display display, IComposerClient::DisplayConnectionType* outType) {
1295 AidlDisplayConnectionType type;
1296 const auto status =
1297 mAidlComposerClient->getDisplayConnectionType(translate<int64_t>(display), &type);
1298 if (!status.isOk()) {
1299 ALOGE("getDisplayConnectionType failed %s", status.getDescription().c_str());
1300 return static_cast<V2_4::Error>(status.getServiceSpecificError());
1301 }
1302 *outType = translate<IComposerClient::DisplayConnectionType>(type);
1303 return V2_4::Error::NONE;
1304}
1305
1306V2_4::Error AidlComposer::getDisplayVsyncPeriod(Display display, VsyncPeriodNanos* outVsyncPeriod) {
1307 int32_t vsyncPeriod;
1308 const auto status =
1309 mAidlComposerClient->getDisplayVsyncPeriod(translate<int64_t>(display), &vsyncPeriod);
1310 if (!status.isOk()) {
1311 ALOGE("getDisplayVsyncPeriod failed %s", status.getDescription().c_str());
1312 return static_cast<V2_4::Error>(status.getServiceSpecificError());
1313 }
1314 *outVsyncPeriod = translate<VsyncPeriodNanos>(vsyncPeriod);
1315 return V2_4::Error::NONE;
1316}
1317
1318V2_4::Error AidlComposer::setActiveConfigWithConstraints(
1319 Display display, Config config,
1320 const IComposerClient::VsyncPeriodChangeConstraints& vsyncPeriodChangeConstraints,
1321 VsyncPeriodChangeTimeline* outTimeline) {
1322 AidlVsyncPeriodChangeTimeline timeline;
1323 const auto status =
1324 mAidlComposerClient
1325 ->setActiveConfigWithConstraints(translate<int64_t>(display),
1326 translate<int32_t>(config),
1327 translate<AidlVsyncPeriodChangeConstraints>(
1328 vsyncPeriodChangeConstraints),
1329 &timeline);
1330 if (!status.isOk()) {
1331 ALOGE("setActiveConfigWithConstraints failed %s", status.getDescription().c_str());
1332 return static_cast<V2_4::Error>(status.getServiceSpecificError());
1333 }
1334 *outTimeline = translate<VsyncPeriodChangeTimeline>(timeline);
1335 return V2_4::Error::NONE;
1336}
1337
1338V2_4::Error AidlComposer::setAutoLowLatencyMode(Display display, bool on) {
1339 const auto status = mAidlComposerClient->setAutoLowLatencyMode(translate<int64_t>(display), on);
1340 if (!status.isOk()) {
1341 ALOGE("setAutoLowLatencyMode failed %s", status.getDescription().c_str());
1342 return static_cast<V2_4::Error>(status.getServiceSpecificError());
1343 }
1344 return V2_4::Error::NONE;
1345}
1346
1347V2_4::Error AidlComposer::getSupportedContentTypes(
1348 Display displayId, std::vector<IComposerClient::ContentType>* outSupportedContentTypes) {
1349 std::vector<AidlContentType> types;
1350 const auto status =
1351 mAidlComposerClient->getSupportedContentTypes(translate<int64_t>(displayId), &types);
1352 if (!status.isOk()) {
1353 ALOGE("getSupportedContentTypes failed %s", status.getDescription().c_str());
1354 return static_cast<V2_4::Error>(status.getServiceSpecificError());
1355 }
1356 *outSupportedContentTypes = translate<IComposerClient::ContentType>(types);
1357 return V2_4::Error::NONE;
1358}
1359
1360V2_4::Error AidlComposer::setContentType(Display display,
1361 IComposerClient::ContentType contentType) {
1362 const auto status =
1363 mAidlComposerClient->setContentType(translate<int64_t>(display),
1364 translate<AidlContentType>(contentType));
1365 if (!status.isOk()) {
1366 ALOGE("setContentType failed %s", status.getDescription().c_str());
1367 return static_cast<V2_4::Error>(status.getServiceSpecificError());
1368 }
1369 return V2_4::Error::NONE;
1370}
1371
Ady Abraham3f976752021-12-20 16:17:50 -08001372V2_4::Error AidlComposer::setLayerGenericMetadata(Display, Layer, const std::string&, bool,
1373 const std::vector<uint8_t>&) {
1374 // There are no users for this API. See b/209691612.
1375 return V2_4::Error::UNSUPPORTED;
Ady Abrahame7385f72021-09-05 00:54:25 -07001376}
1377
1378V2_4::Error AidlComposer::getLayerGenericMetadataKeys(
Ady Abraham3f976752021-12-20 16:17:50 -08001379 std::vector<IComposerClient::LayerGenericMetadataKey>*) {
1380 // There are no users for this API. See b/209691612.
1381 return V2_4::Error::UNSUPPORTED;
Ady Abrahame7385f72021-09-05 00:54:25 -07001382}
1383
Kriti Dang7defaf32021-11-15 11:55:43 +01001384Error AidlComposer::setBootDisplayConfig(Display display, Config config) {
1385 const auto status = mAidlComposerClient->setBootDisplayConfig(translate<int64_t>(display),
1386 translate<int32_t>(config));
1387 if (!status.isOk()) {
1388 ALOGE("setBootDisplayConfig failed %s", status.getDescription().c_str());
1389 return static_cast<Error>(status.getServiceSpecificError());
1390 }
1391 return Error::NONE;
1392}
1393
1394Error AidlComposer::clearBootDisplayConfig(Display display) {
1395 const auto status = mAidlComposerClient->clearBootDisplayConfig(translate<int64_t>(display));
1396 if (!status.isOk()) {
1397 ALOGE("clearBootDisplayConfig failed %s", status.getDescription().c_str());
1398 return static_cast<Error>(status.getServiceSpecificError());
1399 }
1400 return Error::NONE;
1401}
1402
1403Error AidlComposer::getPreferredBootDisplayConfig(Display display, Config* config) {
1404 int32_t displayConfig;
1405 const auto status =
1406 mAidlComposerClient->getPreferredBootDisplayConfig(translate<int64_t>(display),
1407 &displayConfig);
1408 if (!status.isOk()) {
1409 ALOGE("getPreferredBootDisplayConfig failed %s", status.getDescription().c_str());
1410 return static_cast<Error>(status.getServiceSpecificError());
1411 }
1412 *config = translate<uint32_t>(displayConfig);
1413 return Error::NONE;
1414}
1415
Kriti Dang674b9372022-11-18 10:58:44 +01001416Error AidlComposer::getHdrConversionCapabilities(
1417 std::vector<AidlHdrConversionCapability>* hdrConversionCapabilities) {
1418 const auto status =
1419 mAidlComposerClient->getHdrConversionCapabilities(hdrConversionCapabilities);
1420 if (!status.isOk()) {
1421 hdrConversionCapabilities = {};
1422 ALOGE("getHdrConversionCapabilities failed %s", status.getDescription().c_str());
1423 return static_cast<Error>(status.getServiceSpecificError());
1424 }
1425 return Error::NONE;
1426}
1427
Kriti Dangd432bb52023-02-09 18:21:04 +01001428Error AidlComposer::setHdrConversionStrategy(AidlHdrConversionStrategy hdrConversionStrategy,
1429 Hdr* outPreferredHdrOutputType) {
1430 const auto status = mAidlComposerClient->setHdrConversionStrategy(hdrConversionStrategy,
1431 outPreferredHdrOutputType);
Kriti Dang674b9372022-11-18 10:58:44 +01001432 if (!status.isOk()) {
1433 ALOGE("setHdrConversionStrategy failed %s", status.getDescription().c_str());
1434 return static_cast<Error>(status.getServiceSpecificError());
1435 }
1436 return Error::NONE;
1437}
1438
ramindanib2158ee2023-02-13 20:29:59 -08001439Error AidlComposer::setRefreshRateChangedCallbackDebugEnabled(Display displayId, bool enabled) {
1440 const auto status =
1441 mAidlComposerClient->setRefreshRateChangedCallbackDebugEnabled(translate<int64_t>(
1442 displayId),
1443 enabled);
1444 if (!status.isOk()) {
1445 ALOGE("setRefreshRateChangedCallbackDebugEnabled failed %s",
1446 status.getDescription().c_str());
1447 return static_cast<Error>(status.getServiceSpecificError());
1448 }
1449 return Error::NONE;
1450}
1451
Ady Abrahame7385f72021-09-05 00:54:25 -07001452Error AidlComposer::getClientTargetProperty(
Alec Mouri85065692022-03-18 00:58:26 +00001453 Display display, ClientTargetPropertyWithBrightness* outClientTargetProperty) {
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -04001454 Error error = Error::NONE;
1455 mMutex.lock_shared();
1456 if (auto reader = getReader(display)) {
1457 *outClientTargetProperty =
1458 reader->get().takeClientTargetProperty(translate<int64_t>(display));
1459 } else {
1460 error = Error::BAD_DISPLAY;
1461 }
1462 mMutex.unlock_shared();
1463 return error;
Ady Abrahame7385f72021-09-05 00:54:25 -07001464}
1465
Alec Mouri6da0e272022-02-07 12:45:57 -08001466Error AidlComposer::setLayerBrightness(Display display, Layer layer, float brightness) {
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -04001467 Error error = Error::NONE;
1468 mMutex.lock_shared();
1469 if (auto writer = getWriter(display)) {
1470 writer->get().setLayerBrightness(translate<int64_t>(display), translate<int64_t>(layer),
1471 brightness);
1472 } else {
1473 error = Error::BAD_DISPLAY;
1474 }
1475 mMutex.unlock_shared();
1476 return error;
Alec Mouricdf6cbc2021-11-01 17:21:15 -07001477}
1478
Leon Scroggins IIId77d3162022-01-05 10:42:28 -05001479Error AidlComposer::setLayerBlockingRegion(Display display, Layer layer,
1480 const std::vector<IComposerClient::Rect>& blocking) {
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -04001481 Error error = Error::NONE;
1482 mMutex.lock_shared();
1483 if (auto writer = getWriter(display)) {
1484 writer->get().setLayerBlockingRegion(translate<int64_t>(display), translate<int64_t>(layer),
1485 translate<AidlRect>(blocking));
1486 } else {
1487 error = Error::BAD_DISPLAY;
1488 }
1489 mMutex.unlock_shared();
1490 return error;
Leon Scroggins IIId77d3162022-01-05 10:42:28 -05001491}
Leon Scroggins IIIe7c51c62022-02-01 15:53:54 -05001492
1493Error AidlComposer::getDisplayDecorationSupport(Display display,
1494 std::optional<DisplayDecorationSupport>* support) {
1495 const auto status =
1496 mAidlComposerClient->getDisplayDecorationSupport(translate<int64_t>(display), support);
1497 if (!status.isOk()) {
1498 ALOGE("getDisplayDecorationSupport failed %s", status.getDescription().c_str());
1499 support->reset();
1500 return static_cast<Error>(status.getServiceSpecificError());
1501 }
1502 return Error::NONE;
1503}
ramindani32cf0602022-03-02 02:30:29 +00001504
1505Error AidlComposer::setIdleTimerEnabled(Display displayId, std::chrono::milliseconds timeout) {
1506 const auto status =
1507 mAidlComposerClient->setIdleTimerEnabled(translate<int64_t>(displayId),
1508 translate<int32_t>(timeout.count()));
1509 if (!status.isOk()) {
1510 ALOGE("setIdleTimerEnabled failed %s", status.getDescription().c_str());
1511 return static_cast<Error>(status.getServiceSpecificError());
1512 }
1513 return Error::NONE;
1514}
1515
ramindani06e518e2022-03-14 18:47:53 +00001516Error AidlComposer::getPhysicalDisplayOrientation(Display displayId,
1517 AidlTransform* outDisplayOrientation) {
1518 const auto status =
1519 mAidlComposerClient->getDisplayPhysicalOrientation(translate<int64_t>(displayId),
1520 outDisplayOrientation);
1521 if (!status.isOk()) {
1522 ALOGE("getPhysicalDisplayOrientation failed %s", status.getDescription().c_str());
1523 return static_cast<Error>(status.getServiceSpecificError());
1524 }
1525 return Error::NONE;
1526}
1527
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -04001528ftl::Optional<std::reference_wrapper<ComposerClientWriter>> AidlComposer::getWriter(Display display)
1529 REQUIRES_SHARED(mMutex) {
1530 return mWriters.get(display);
1531}
1532
1533ftl::Optional<std::reference_wrapper<ComposerClientReader>> AidlComposer::getReader(Display display)
1534 REQUIRES_SHARED(mMutex) {
1535 if (mSingleReader) {
1536 display = translate<Display>(kSingleReaderKey);
1537 }
1538 return mReaders.get(display);
1539}
1540
1541void AidlComposer::removeDisplay(Display display) {
1542 mMutex.lock();
1543 bool wasErased = mWriters.erase(display);
1544 ALOGW_IF(!wasErased,
1545 "Attempting to remove writer for display %" PRId64 " which is not connected",
1546 translate<int64_t>(display));
1547 if (!mSingleReader) {
1548 removeReader(display);
1549 }
1550 mMutex.unlock();
1551}
1552
1553void AidlComposer::onHotplugDisconnect(Display display) {
1554 removeDisplay(display);
1555}
1556
1557bool AidlComposer::hasMultiThreadedPresentSupport(Display display) {
Leon Scroggins IIIc1cf4582023-03-23 18:37:44 -04001558#if 0
1559 // TODO (b/259132483): Reenable
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -04001560 const auto displayId = translate<int64_t>(display);
1561 std::vector<AidlDisplayCapability> capabilities;
1562 const auto status = mAidlComposerClient->getDisplayCapabilities(displayId, &capabilities);
1563 if (!status.isOk()) {
1564 ALOGE("getDisplayCapabilities failed %s", status.getDescription().c_str());
1565 return false;
1566 }
1567 return std::find(capabilities.begin(), capabilities.end(),
1568 AidlDisplayCapability::MULTI_THREADED_PRESENT) != capabilities.end();
Leon Scroggins IIIc1cf4582023-03-23 18:37:44 -04001569#else
1570 (void) display;
1571 return false;
1572#endif
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -04001573}
1574
1575void AidlComposer::addReader(Display display) {
1576 const auto displayId = translate<int64_t>(display);
1577 std::optional<int64_t> displayOpt;
1578 if (displayId != kSingleReaderKey) {
1579 displayOpt.emplace(displayId);
1580 }
1581 auto [it, added] = mReaders.try_emplace(display, std::move(displayOpt));
1582 ALOGW_IF(!added, "Attempting to add writer for display %" PRId64 " which is already connected",
1583 displayId);
1584}
1585
1586void AidlComposer::removeReader(Display display) {
1587 bool wasErased = mReaders.erase(display);
1588 ALOGW_IF(!wasErased,
1589 "Attempting to remove reader for display %" PRId64 " which is not connected",
1590 translate<int64_t>(display));
1591}
1592
1593void AidlComposer::addDisplay(Display display) {
1594 const auto displayId = translate<int64_t>(display);
1595 mMutex.lock();
1596 auto [it, added] = mWriters.try_emplace(display, displayId);
1597 ALOGW_IF(!added, "Attempting to add writer for display %" PRId64 " which is already connected",
1598 displayId);
1599 if (mSingleReader) {
1600 if (hasMultiThreadedPresentSupport(display)) {
1601 mSingleReader = false;
1602 removeReader(translate<Display>(kSingleReaderKey));
1603 // Note that this includes the new display.
1604 for (const auto& [existingDisplay, _] : mWriters) {
1605 addReader(existingDisplay);
1606 }
1607 }
1608 } else {
1609 addReader(display);
1610 }
1611 mMutex.unlock();
1612}
1613
1614void AidlComposer::onHotplugConnect(Display display) {
1615 addDisplay(display);
1616}
Ady Abrahame7385f72021-09-05 00:54:25 -07001617} // namespace Hwc2
1618} // namespace android