blob: 9470552e41f26bcc2023d4e3e95deca30de3f508 [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
Ady Abrahamc4acf512022-02-18 17:11:59 -080023#include <android-base/file.h>
Ady Abrahame7385f72021-09-05 00:54:25 -070024#include <android/binder_ibinder_platform.h>
25#include <android/binder_manager.h>
Leon Scroggins IIIe85e16e2022-12-12 12:51:18 -050026#include <gui/TraceUtils.h>
Ady Abrahame7385f72021-09-05 00:54:25 -070027#include <log/log.h>
28#include <utils/Trace.h>
29
30#include <aidl/android/hardware/graphics/composer3/BnComposerCallback.h>
31
32#include <algorithm>
33#include <cinttypes>
34
Yichi Chen3401b562022-01-17 15:42:35 +080035#include "HWC2.h"
36
Ady Abrahame7385f72021-09-05 00:54:25 -070037namespace android {
38
39using hardware::hidl_handle;
40using hardware::hidl_vec;
41using hardware::Return;
42
43using aidl::android::hardware::graphics::composer3::BnComposerCallback;
44using aidl::android::hardware::graphics::composer3::Capability;
Alec Mouri85065692022-03-18 00:58:26 +000045using aidl::android::hardware::graphics::composer3::ClientTargetPropertyWithBrightness;
Ady Abrahame7385f72021-09-05 00:54:25 -070046using aidl::android::hardware::graphics::composer3::PowerMode;
47using aidl::android::hardware::graphics::composer3::VirtualDisplay;
48
Ady Abraham42977362021-12-07 21:04:49 -080049using aidl::android::hardware::graphics::composer3::CommandResultPayload;
Ady Abrahama6388c02021-11-11 21:11:51 -080050
Ady Abrahame7385f72021-09-05 00:54:25 -070051using AidlColorMode = aidl::android::hardware::graphics::composer3::ColorMode;
52using AidlContentType = aidl::android::hardware::graphics::composer3::ContentType;
53using AidlDisplayIdentification =
54 aidl::android::hardware::graphics::composer3::DisplayIdentification;
55using AidlDisplayContentSample = aidl::android::hardware::graphics::composer3::DisplayContentSample;
56using AidlDisplayAttribute = aidl::android::hardware::graphics::composer3::DisplayAttribute;
57using AidlDisplayCapability = aidl::android::hardware::graphics::composer3::DisplayCapability;
Ady Abrahame7385f72021-09-05 00:54:25 -070058using AidlHdrCapabilities = aidl::android::hardware::graphics::composer3::HdrCapabilities;
Kriti Dang674b9372022-11-18 10:58:44 +010059using AidlHdrConversionCapability =
60 aidl::android::hardware::graphics::common::HdrConversionCapability;
61using AidlHdrConversionStrategy = aidl::android::hardware::graphics::common::HdrConversionStrategy;
Sally Qi0cbd08b2022-08-17 12:12:28 -070062using AidlOverlayProperties = aidl::android::hardware::graphics::composer3::OverlayProperties;
Ady Abrahame7385f72021-09-05 00:54:25 -070063using AidlPerFrameMetadata = aidl::android::hardware::graphics::composer3::PerFrameMetadata;
64using AidlPerFrameMetadataKey = aidl::android::hardware::graphics::composer3::PerFrameMetadataKey;
65using AidlPerFrameMetadataBlob = aidl::android::hardware::graphics::composer3::PerFrameMetadataBlob;
66using AidlRenderIntent = aidl::android::hardware::graphics::composer3::RenderIntent;
67using AidlVsyncPeriodChangeConstraints =
68 aidl::android::hardware::graphics::composer3::VsyncPeriodChangeConstraints;
69using AidlVsyncPeriodChangeTimeline =
70 aidl::android::hardware::graphics::composer3::VsyncPeriodChangeTimeline;
Ady Abrahame7385f72021-09-05 00:54:25 -070071using AidlDisplayContentSamplingAttributes =
72 aidl::android::hardware::graphics::composer3::DisplayContentSamplingAttributes;
73using AidlFormatColorComponent = aidl::android::hardware::graphics::composer3::FormatColorComponent;
74using AidlDisplayConnectionType =
75 aidl::android::hardware::graphics::composer3::DisplayConnectionType;
Ady Abrahame7385f72021-09-05 00:54:25 -070076
77using AidlColorTransform = aidl::android::hardware::graphics::common::ColorTransform;
78using AidlDataspace = aidl::android::hardware::graphics::common::Dataspace;
79using AidlFRect = aidl::android::hardware::graphics::common::FRect;
80using AidlRect = aidl::android::hardware::graphics::common::Rect;
81using AidlTransform = aidl::android::hardware::graphics::common::Transform;
82
83namespace Hwc2 {
84
85namespace {
86
87template <typename To, typename From>
88To translate(From x) {
89 return static_cast<To>(x);
90}
91
92template <typename To, typename From>
93std::vector<To> translate(const std::vector<From>& in) {
94 std::vector<To> out;
95 out.reserve(in.size());
96 std::transform(in.begin(), in.end(), std::back_inserter(out),
97 [](From x) { return translate<To>(x); });
98 return out;
99}
100
101template <>
102AidlRect translate(IComposerClient::Rect x) {
103 return AidlRect{
104 .left = x.left,
105 .top = x.top,
106 .right = x.right,
107 .bottom = x.bottom,
108 };
109}
110
111template <>
112AidlFRect translate(IComposerClient::FRect x) {
113 return AidlFRect{
114 .left = x.left,
115 .top = x.top,
116 .right = x.right,
117 .bottom = x.bottom,
118 };
119}
120
121template <>
Ady Abrahame7385f72021-09-05 00:54:25 -0700122AidlPerFrameMetadataBlob translate(IComposerClient::PerFrameMetadataBlob x) {
123 AidlPerFrameMetadataBlob blob;
124 blob.key = translate<AidlPerFrameMetadataKey>(x.key),
Long Linga4628782022-02-18 13:44:26 -0800125 std::copy(x.blob.begin(), x.blob.end(), std::inserter(blob.blob, blob.blob.end()));
Ady Abrahame7385f72021-09-05 00:54:25 -0700126 return blob;
127}
128
129template <>
130AidlPerFrameMetadata translate(IComposerClient::PerFrameMetadata x) {
131 return AidlPerFrameMetadata{
132 .key = translate<AidlPerFrameMetadataKey>(x.key),
133 .value = x.value,
134 };
135}
136
137template <>
138DisplayedFrameStats translate(AidlDisplayContentSample x) {
139 return DisplayedFrameStats{
140 .numFrames = static_cast<uint64_t>(x.frameCount),
141 .component_0_sample = translate<uint64_t>(x.sampleComponent0),
142 .component_1_sample = translate<uint64_t>(x.sampleComponent1),
143 .component_2_sample = translate<uint64_t>(x.sampleComponent2),
144 .component_3_sample = translate<uint64_t>(x.sampleComponent3),
145 };
146}
147
148template <>
149AidlVsyncPeriodChangeConstraints translate(IComposerClient::VsyncPeriodChangeConstraints x) {
150 return AidlVsyncPeriodChangeConstraints{
151 .desiredTimeNanos = x.desiredTimeNanos,
152 .seamlessRequired = x.seamlessRequired,
153 };
154}
155
156template <>
157VsyncPeriodChangeTimeline translate(AidlVsyncPeriodChangeTimeline x) {
158 return VsyncPeriodChangeTimeline{
159 .newVsyncAppliedTimeNanos = x.newVsyncAppliedTimeNanos,
160 .refreshRequired = x.refreshRequired,
161 .refreshTimeNanos = x.refreshTimeNanos,
162 };
163}
Ady Abrahame7385f72021-09-05 00:54:25 -0700164mat4 makeMat4(std::vector<float> in) {
165 return mat4(static_cast<const float*>(in.data()));
166}
167
168} // namespace
169
170class AidlIComposerCallbackWrapper : public BnComposerCallback {
171public:
Yichi Chen3401b562022-01-17 15:42:35 +0800172 AidlIComposerCallbackWrapper(HWC2::ComposerCallback& callback) : mCallback(callback) {}
Ady Abrahame7385f72021-09-05 00:54:25 -0700173
174 ::ndk::ScopedAStatus onHotplug(int64_t in_display, bool in_connected) override {
175 const auto connection = in_connected ? V2_4::IComposerCallback::Connection::CONNECTED
176 : V2_4::IComposerCallback::Connection::DISCONNECTED;
Yichi Chen3401b562022-01-17 15:42:35 +0800177 mCallback.onComposerHalHotplug(translate<Display>(in_display), connection);
Ady Abrahame7385f72021-09-05 00:54:25 -0700178 return ::ndk::ScopedAStatus::ok();
179 }
180
181 ::ndk::ScopedAStatus onRefresh(int64_t in_display) override {
Yichi Chen3401b562022-01-17 15:42:35 +0800182 mCallback.onComposerHalRefresh(translate<Display>(in_display));
Ady Abrahame7385f72021-09-05 00:54:25 -0700183 return ::ndk::ScopedAStatus::ok();
184 }
Yichi Chen3401b562022-01-17 15:42:35 +0800185
Ady Abrahame7385f72021-09-05 00:54:25 -0700186 ::ndk::ScopedAStatus onSeamlessPossible(int64_t in_display) override {
Yichi Chen3401b562022-01-17 15:42:35 +0800187 mCallback.onComposerHalSeamlessPossible(translate<Display>(in_display));
Ady Abrahame7385f72021-09-05 00:54:25 -0700188 return ::ndk::ScopedAStatus::ok();
189 }
Yichi Chen3401b562022-01-17 15:42:35 +0800190
Ady Abrahame7385f72021-09-05 00:54:25 -0700191 ::ndk::ScopedAStatus onVsync(int64_t in_display, int64_t in_timestamp,
192 int32_t in_vsyncPeriodNanos) override {
Yichi Chen3401b562022-01-17 15:42:35 +0800193 mCallback.onComposerHalVsync(translate<Display>(in_display), in_timestamp,
194 static_cast<uint32_t>(in_vsyncPeriodNanos));
Ady Abrahame7385f72021-09-05 00:54:25 -0700195 return ::ndk::ScopedAStatus::ok();
196 }
Yichi Chen3401b562022-01-17 15:42:35 +0800197
Ady Abrahame7385f72021-09-05 00:54:25 -0700198 ::ndk::ScopedAStatus onVsyncPeriodTimingChanged(
199 int64_t in_display, const AidlVsyncPeriodChangeTimeline& in_updatedTimeline) override {
Yichi Chen3401b562022-01-17 15:42:35 +0800200 mCallback.onComposerHalVsyncPeriodTimingChanged(translate<Display>(in_display),
201 translate<V2_4::VsyncPeriodChangeTimeline>(
202 in_updatedTimeline));
203 return ::ndk::ScopedAStatus::ok();
204 }
205
206 ::ndk::ScopedAStatus onVsyncIdle(int64_t in_display) override {
207 mCallback.onComposerHalVsyncIdle(translate<Display>(in_display));
Ady Abrahame7385f72021-09-05 00:54:25 -0700208 return ::ndk::ScopedAStatus::ok();
209 }
210
211private:
Yichi Chen3401b562022-01-17 15:42:35 +0800212 HWC2::ComposerCallback& mCallback;
Ady Abrahame7385f72021-09-05 00:54:25 -0700213};
214
Ady Abraham9fc28052021-10-14 17:21:38 -0700215std::string AidlComposer::instance(const std::string& serviceName) {
216 return std::string(AidlIComposer::descriptor) + "/" + serviceName;
217}
218
219bool AidlComposer::isDeclared(const std::string& serviceName) {
220 return AServiceManager_isDeclared(instance(serviceName).c_str());
221}
Ady Abrahame7385f72021-09-05 00:54:25 -0700222
Ady Abrahama6388c02021-11-11 21:11:51 -0800223AidlComposer::AidlComposer(const std::string& serviceName) {
Ady Abrahame7385f72021-09-05 00:54:25 -0700224 // This only waits if the service is actually declared
Ady Abraham9fc28052021-10-14 17:21:38 -0700225 mAidlComposer = AidlIComposer::fromBinder(
226 ndk::SpAIBinder(AServiceManager_waitForService(instance(serviceName).c_str())));
Ady Abrahame7385f72021-09-05 00:54:25 -0700227 if (!mAidlComposer) {
228 LOG_ALWAYS_FATAL("Failed to get AIDL composer service");
229 return;
230 }
231
232 if (!mAidlComposer->createClient(&mAidlComposerClient).isOk()) {
233 LOG_ALWAYS_FATAL("Can't create AidlComposerClient, fallback to HIDL");
234 return;
235 }
236
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400237 addReader(translate<Display>(kSingleReaderKey));
238
Brian Lindahldbf7e3a2022-12-16 11:43:39 -0700239 // If unable to read interface version, then become backwards compatible.
240 int32_t version = 1;
241 const auto status = mAidlComposerClient->getInterfaceVersion(&version);
242 if (!status.isOk()) {
243 ALOGE("getInterfaceVersion for AidlComposer constructor failed %s",
244 status.getDescription().c_str());
245 }
246 if (version == 1) {
247 mClearSlotBuffer = sp<GraphicBuffer>::make(1, 1, PIXEL_FORMAT_RGBX_8888,
248 GraphicBuffer::USAGE_HW_COMPOSER |
249 GraphicBuffer::USAGE_SW_READ_OFTEN |
250 GraphicBuffer::USAGE_SW_WRITE_OFTEN,
251 "AidlComposer");
252 if (!mClearSlotBuffer || mClearSlotBuffer->initCheck() != ::android::OK) {
253 LOG_ALWAYS_FATAL("Failed to allocate a buffer for clearing layer buffer slots");
254 return;
255 }
Brian Lindahl90553da2022-12-06 13:36:30 -0700256 }
257
Ady Abrahame7385f72021-09-05 00:54:25 -0700258 ALOGI("Loaded AIDL composer3 HAL service");
259}
260
261AidlComposer::~AidlComposer() = default;
262
Ady Abraham4d211cf2021-12-14 16:19:03 -0800263bool AidlComposer::isSupported(OptionalFeature feature) const {
264 switch (feature) {
265 case OptionalFeature::RefreshRateSwitching:
Ady Abraham43065bd2021-12-10 17:22:15 -0800266 case OptionalFeature::ExpectedPresentTime:
Alec Mouricdf16792021-12-10 13:16:06 -0800267 case OptionalFeature::DisplayBrightnessCommand:
ramindani32cf0602022-03-02 02:30:29 +0000268 case OptionalFeature::KernelIdleTimer:
ramindani06e518e2022-03-14 18:47:53 +0000269 case OptionalFeature::PhysicalDisplayOrientation:
Ady Abraham4d211cf2021-12-14 16:19:03 -0800270 return true;
271 }
272}
273
Ady Abrahamde549d42022-01-26 19:19:17 -0800274std::vector<Capability> AidlComposer::getCapabilities() {
Ady Abrahame7385f72021-09-05 00:54:25 -0700275 std::vector<Capability> capabilities;
276 const auto status = mAidlComposer->getCapabilities(&capabilities);
277 if (!status.isOk()) {
278 ALOGE("getCapabilities failed %s", status.getDescription().c_str());
279 return {};
280 }
Ady Abrahamde549d42022-01-26 19:19:17 -0800281 return capabilities;
Ady Abrahame7385f72021-09-05 00:54:25 -0700282}
283
284std::string AidlComposer::dumpDebugInfo() {
Ady Abrahamc4acf512022-02-18 17:11:59 -0800285 int pipefds[2];
286 int result = pipe(pipefds);
287 if (result < 0) {
288 ALOGE("dumpDebugInfo: pipe failed: %s", strerror(errno));
Ady Abrahame7385f72021-09-05 00:54:25 -0700289 return {};
290 }
Ady Abrahamc4acf512022-02-18 17:11:59 -0800291
292 std::string str;
yihsing.shen58847c52022-09-23 15:39:30 +0800293 // Use other thread to read pipe to prevent
294 // pipe is full, making HWC be blocked in writing.
295 std::thread t([&]() {
296 base::ReadFdToString(pipefds[0], &str);
297 });
Ady Abrahamc4acf512022-02-18 17:11:59 -0800298 const auto status = mAidlComposer->dump(pipefds[1], /*args*/ nullptr, /*numArgs*/ 0);
299 // Close the write-end of the pipe to make sure that when reading from the
300 // read-end we will get eof instead of blocking forever
301 close(pipefds[1]);
302
yihsing.shen58847c52022-09-23 15:39:30 +0800303 if (status != STATUS_OK) {
Ady Abrahamc4acf512022-02-18 17:11:59 -0800304 ALOGE("dumpDebugInfo: dump failed: %d", status);
305 }
306
yihsing.shen58847c52022-09-23 15:39:30 +0800307 t.join();
Ady Abrahamc4acf512022-02-18 17:11:59 -0800308 close(pipefds[0]);
309 return str;
Ady Abrahame7385f72021-09-05 00:54:25 -0700310}
311
Yichi Chen3401b562022-01-17 15:42:35 +0800312void AidlComposer::registerCallback(HWC2::ComposerCallback& callback) {
Ady Abrahame7385f72021-09-05 00:54:25 -0700313 if (mAidlComposerCallback) {
314 ALOGE("Callback already registered");
315 }
Yichi Chen3401b562022-01-17 15:42:35 +0800316
Ady Abraham9fc28052021-10-14 17:21:38 -0700317 mAidlComposerCallback = ndk::SharedRefBase::make<AidlIComposerCallbackWrapper>(callback);
Ady Abrahame7385f72021-09-05 00:54:25 -0700318 AIBinder_setMinSchedulerPolicy(mAidlComposerCallback->asBinder().get(), SCHED_FIFO, 2);
319
320 const auto status = mAidlComposerClient->registerCallback(mAidlComposerCallback);
321 if (!status.isOk()) {
322 ALOGE("registerCallback failed %s", status.getDescription().c_str());
323 }
324}
325
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400326void AidlComposer::resetCommands(Display display) {
327 mMutex.lock_shared();
328 if (auto writer = getWriter(display)) {
329 writer->get().reset();
330 }
331 mMutex.unlock_shared();
Ady Abrahame7385f72021-09-05 00:54:25 -0700332}
333
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400334Error AidlComposer::executeCommands(Display display) {
335 mMutex.lock_shared();
336 auto error = execute(display);
337 mMutex.unlock_shared();
338 return error;
Ady Abrahame7385f72021-09-05 00:54:25 -0700339}
340
341uint32_t AidlComposer::getMaxVirtualDisplayCount() {
342 int32_t count = 0;
343 const auto status = mAidlComposerClient->getMaxVirtualDisplayCount(&count);
344 if (!status.isOk()) {
345 ALOGE("getMaxVirtualDisplayCount failed %s", status.getDescription().c_str());
346 return 0;
347 }
348 return static_cast<uint32_t>(count);
349}
350
351Error AidlComposer::createVirtualDisplay(uint32_t width, uint32_t height, PixelFormat* format,
352 Display* outDisplay) {
353 using AidlPixelFormat = aidl::android::hardware::graphics::common::PixelFormat;
354 const int32_t bufferSlotCount = 1;
355 VirtualDisplay virtualDisplay;
356 const auto status =
357 mAidlComposerClient->createVirtualDisplay(static_cast<int32_t>(width),
358 static_cast<int32_t>(height),
359 static_cast<AidlPixelFormat>(*format),
360 bufferSlotCount, &virtualDisplay);
361
362 if (!status.isOk()) {
363 ALOGE("createVirtualDisplay failed %s", status.getDescription().c_str());
364 return static_cast<Error>(status.getServiceSpecificError());
365 }
366
367 *outDisplay = translate<Display>(virtualDisplay.display);
368 *format = static_cast<PixelFormat>(virtualDisplay.format);
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400369 addDisplay(translate<Display>(virtualDisplay.display));
Ady Abrahame7385f72021-09-05 00:54:25 -0700370 return Error::NONE;
371}
372
373Error AidlComposer::destroyVirtualDisplay(Display display) {
374 const auto status = mAidlComposerClient->destroyVirtualDisplay(translate<int64_t>(display));
375 if (!status.isOk()) {
376 ALOGE("destroyVirtualDisplay failed %s", status.getDescription().c_str());
377 return static_cast<Error>(status.getServiceSpecificError());
378 }
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400379 removeDisplay(display);
Ady Abrahame7385f72021-09-05 00:54:25 -0700380 return Error::NONE;
381}
382
383Error AidlComposer::acceptDisplayChanges(Display display) {
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400384 Error error = Error::NONE;
385 mMutex.lock_shared();
386 if (auto writer = getWriter(display)) {
387 writer->get().acceptDisplayChanges(translate<int64_t>(display));
388 } else {
389 error = Error::BAD_DISPLAY;
390 }
391 mMutex.unlock_shared();
392 return error;
Ady Abrahame7385f72021-09-05 00:54:25 -0700393}
394
395Error AidlComposer::createLayer(Display display, Layer* outLayer) {
396 int64_t layer;
397 const auto status = mAidlComposerClient->createLayer(translate<int64_t>(display),
398 kMaxLayerBufferCount, &layer);
399 if (!status.isOk()) {
400 ALOGE("createLayer failed %s", status.getDescription().c_str());
401 return static_cast<Error>(status.getServiceSpecificError());
402 }
403
404 *outLayer = translate<Layer>(layer);
405 return Error::NONE;
406}
407
408Error AidlComposer::destroyLayer(Display display, Layer layer) {
409 const auto status = mAidlComposerClient->destroyLayer(translate<int64_t>(display),
410 translate<int64_t>(layer));
411 if (!status.isOk()) {
412 ALOGE("destroyLayer failed %s", status.getDescription().c_str());
413 return static_cast<Error>(status.getServiceSpecificError());
414 }
415 return Error::NONE;
416}
417
418Error AidlComposer::getActiveConfig(Display display, Config* outConfig) {
419 int32_t config;
420 const auto status = mAidlComposerClient->getActiveConfig(translate<int64_t>(display), &config);
421 if (!status.isOk()) {
422 ALOGE("getActiveConfig failed %s", status.getDescription().c_str());
423 return static_cast<Error>(status.getServiceSpecificError());
424 }
425 *outConfig = translate<Config>(config);
426 return Error::NONE;
427}
428
429Error AidlComposer::getChangedCompositionTypes(
430 Display display, std::vector<Layer>* outLayers,
Leon Scroggins III2e1aa182021-12-01 17:33:12 -0500431 std::vector<aidl::android::hardware::graphics::composer3::Composition>* outTypes) {
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400432 std::vector<ChangedCompositionLayer> changedLayers;
433 Error error = Error::NONE;
434 {
435 mMutex.lock_shared();
436 if (auto reader = getReader(display)) {
437 changedLayers = reader->get().takeChangedCompositionTypes(translate<int64_t>(display));
438 } else {
439 error = Error::BAD_DISPLAY;
440 }
441 mMutex.unlock_shared();
442 }
Ady Abrahamde792782021-12-20 10:00:49 -0800443 outLayers->reserve(changedLayers.size());
444 outTypes->reserve(changedLayers.size());
Ady Abrahama6388c02021-11-11 21:11:51 -0800445
Ady Abrahamde792782021-12-20 10:00:49 -0800446 for (const auto& layer : changedLayers) {
447 outLayers->emplace_back(translate<Layer>(layer.layer));
448 outTypes->emplace_back(layer.composition);
449 }
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400450 return error;
Ady Abrahame7385f72021-09-05 00:54:25 -0700451}
452
453Error AidlComposer::getColorModes(Display display, std::vector<ColorMode>* outModes) {
454 std::vector<AidlColorMode> modes;
455 const auto status = mAidlComposerClient->getColorModes(translate<int64_t>(display), &modes);
456 if (!status.isOk()) {
457 ALOGE("getColorModes failed %s", status.getDescription().c_str());
458 return static_cast<Error>(status.getServiceSpecificError());
459 }
460 *outModes = translate<ColorMode>(modes);
461 return Error::NONE;
462}
463
464Error AidlComposer::getDisplayAttribute(Display display, Config config,
465 IComposerClient::Attribute attribute, int32_t* outValue) {
466 const auto status =
467 mAidlComposerClient->getDisplayAttribute(translate<int64_t>(display),
468 translate<int32_t>(config),
469 static_cast<AidlDisplayAttribute>(attribute),
470 outValue);
471 if (!status.isOk()) {
472 ALOGE("getDisplayAttribute failed %s", status.getDescription().c_str());
473 return static_cast<Error>(status.getServiceSpecificError());
474 }
475 return Error::NONE;
476}
477
478Error AidlComposer::getDisplayConfigs(Display display, std::vector<Config>* outConfigs) {
479 std::vector<int32_t> configs;
480 const auto status =
481 mAidlComposerClient->getDisplayConfigs(translate<int64_t>(display), &configs);
482 if (!status.isOk()) {
483 ALOGE("getDisplayConfigs failed %s", status.getDescription().c_str());
484 return static_cast<Error>(status.getServiceSpecificError());
485 }
486 *outConfigs = translate<Config>(configs);
487 return Error::NONE;
488}
489
490Error AidlComposer::getDisplayName(Display display, std::string* outName) {
491 const auto status = mAidlComposerClient->getDisplayName(translate<int64_t>(display), outName);
492 if (!status.isOk()) {
493 ALOGE("getDisplayName failed %s", status.getDescription().c_str());
494 return static_cast<Error>(status.getServiceSpecificError());
495 }
496 return Error::NONE;
497}
498
499Error AidlComposer::getDisplayRequests(Display display, uint32_t* outDisplayRequestMask,
500 std::vector<Layer>* outLayers,
501 std::vector<uint32_t>* outLayerRequestMasks) {
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400502 Error error = Error::NONE;
503 DisplayRequest displayRequests;
504 {
505 mMutex.lock_shared();
506 if (auto reader = getReader(display)) {
507 displayRequests = reader->get().takeDisplayRequests(translate<int64_t>(display));
508 } else {
509 error = Error::BAD_DISPLAY;
510 }
511 mMutex.unlock_shared();
512 }
Ady Abrahamde792782021-12-20 10:00:49 -0800513 *outDisplayRequestMask = translate<uint32_t>(displayRequests.mask);
514 outLayers->reserve(displayRequests.layerRequests.size());
515 outLayerRequestMasks->reserve(displayRequests.layerRequests.size());
516
517 for (const auto& layer : displayRequests.layerRequests) {
518 outLayers->emplace_back(translate<Layer>(layer.layer));
519 outLayerRequestMasks->emplace_back(translate<uint32_t>(layer.mask));
520 }
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400521 return error;
Ady Abrahame7385f72021-09-05 00:54:25 -0700522}
523
524Error AidlComposer::getDozeSupport(Display display, bool* outSupport) {
Ady Abraham33b92b92021-12-08 18:30:27 -0800525 std::vector<AidlDisplayCapability> capabilities;
Ady Abrahame7385f72021-09-05 00:54:25 -0700526 const auto status =
Ady Abraham33b92b92021-12-08 18:30:27 -0800527 mAidlComposerClient->getDisplayCapabilities(translate<int64_t>(display), &capabilities);
Ady Abrahame7385f72021-09-05 00:54:25 -0700528 if (!status.isOk()) {
Ady Abraham33b92b92021-12-08 18:30:27 -0800529 ALOGE("getDisplayCapabilities failed %s", status.getDescription().c_str());
Ady Abrahame7385f72021-09-05 00:54:25 -0700530 return static_cast<Error>(status.getServiceSpecificError());
531 }
Ady Abraham33b92b92021-12-08 18:30:27 -0800532 *outSupport = std::find(capabilities.begin(), capabilities.end(),
533 AidlDisplayCapability::DOZE) != capabilities.end();
Ady Abrahame7385f72021-09-05 00:54:25 -0700534 return Error::NONE;
535}
536
ramindani32cf0602022-03-02 02:30:29 +0000537Error AidlComposer::hasDisplayIdleTimerCapability(Display display, bool* outSupport) {
538 std::vector<AidlDisplayCapability> capabilities;
539 const auto status =
540 mAidlComposerClient->getDisplayCapabilities(translate<int64_t>(display), &capabilities);
541 if (!status.isOk()) {
542 ALOGE("getDisplayCapabilities failed %s", status.getDescription().c_str());
543 return static_cast<Error>(status.getServiceSpecificError());
544 }
545 *outSupport = std::find(capabilities.begin(), capabilities.end(),
546 AidlDisplayCapability::DISPLAY_IDLE_TIMER) != capabilities.end();
547 return Error::NONE;
548}
549
Ady Abrahame7385f72021-09-05 00:54:25 -0700550Error AidlComposer::getHdrCapabilities(Display display, std::vector<Hdr>* outTypes,
551 float* outMaxLuminance, float* outMaxAverageLuminance,
552 float* outMinLuminance) {
553 AidlHdrCapabilities capabilities;
554 const auto status =
555 mAidlComposerClient->getHdrCapabilities(translate<int64_t>(display), &capabilities);
556 if (!status.isOk()) {
557 ALOGE("getHdrCapabilities failed %s", status.getDescription().c_str());
558 return static_cast<Error>(status.getServiceSpecificError());
559 }
560
Marc Kassisbdf7e4b2022-11-04 17:26:48 +0100561 *outTypes = capabilities.types;
Ady Abrahame7385f72021-09-05 00:54:25 -0700562 *outMaxLuminance = capabilities.maxLuminance;
563 *outMaxAverageLuminance = capabilities.maxAverageLuminance;
564 *outMinLuminance = capabilities.minLuminance;
565 return Error::NONE;
566}
567
Sally Qibb866c12022-10-17 11:31:20 -0700568Error AidlComposer::getOverlaySupport(AidlOverlayProperties* outProperties) {
569 const auto status = mAidlComposerClient->getOverlaySupport(outProperties);
570 if (!status.isOk()) {
571 ALOGE("getOverlaySupport failed %s", status.getDescription().c_str());
572 return static_cast<Error>(status.getServiceSpecificError());
573 }
Sally Qi0cbd08b2022-08-17 12:12:28 -0700574 return Error::NONE;
575}
576
Ady Abrahame7385f72021-09-05 00:54:25 -0700577Error AidlComposer::getReleaseFences(Display display, std::vector<Layer>* outLayers,
578 std::vector<int>* outReleaseFences) {
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400579 Error error = Error::NONE;
580 std::vector<ReleaseFences::Layer> fences;
581 {
582 mMutex.lock_shared();
583 if (auto reader = getReader(display)) {
584 fences = reader->get().takeReleaseFences(translate<int64_t>(display));
585 } else {
586 error = Error::BAD_DISPLAY;
587 }
588 mMutex.unlock_shared();
589 }
Ady Abrahamde792782021-12-20 10:00:49 -0800590 outLayers->reserve(fences.size());
591 outReleaseFences->reserve(fences.size());
592
593 for (auto& fence : fences) {
594 outLayers->emplace_back(translate<Layer>(fence.layer));
595 // take ownership
596 const int fenceOwner = fence.fence.get();
597 *fence.fence.getR() = -1;
598 outReleaseFences->emplace_back(fenceOwner);
599 }
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400600 return error;
Ady Abrahame7385f72021-09-05 00:54:25 -0700601}
602
603Error AidlComposer::presentDisplay(Display display, int* outPresentFence) {
Leon Scroggins IIIe85e16e2022-12-12 12:51:18 -0500604 const auto displayId = translate<int64_t>(display);
605 ATRACE_FORMAT("HwcPresentDisplay %" PRId64, displayId);
606
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400607 Error error = Error::NONE;
608 mMutex.lock_shared();
609 auto writer = getWriter(display);
610 auto reader = getReader(display);
611 if (writer && reader) {
Leon Scroggins IIIe85e16e2022-12-12 12:51:18 -0500612 writer->get().presentDisplay(displayId);
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400613 error = execute(display);
614 } else {
615 error = Error::BAD_DISPLAY;
616 }
Ady Abrahame7385f72021-09-05 00:54:25 -0700617
Ady Abrahame7385f72021-09-05 00:54:25 -0700618 if (error != Error::NONE) {
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400619 mMutex.unlock_shared();
Ady Abrahame7385f72021-09-05 00:54:25 -0700620 return error;
621 }
622
Leon Scroggins IIIe85e16e2022-12-12 12:51:18 -0500623 auto fence = reader->get().takePresentFence(displayId);
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400624 mMutex.unlock_shared();
Ady Abrahamde792782021-12-20 10:00:49 -0800625 // take ownership
626 *outPresentFence = fence.get();
627 *fence.getR() = -1;
Ady Abrahame7385f72021-09-05 00:54:25 -0700628 return Error::NONE;
629}
630
631Error AidlComposer::setActiveConfig(Display display, Config config) {
632 const auto status = mAidlComposerClient->setActiveConfig(translate<int64_t>(display),
633 translate<int32_t>(config));
634 if (!status.isOk()) {
635 ALOGE("setActiveConfig failed %s", status.getDescription().c_str());
636 return static_cast<Error>(status.getServiceSpecificError());
637 }
638 return Error::NONE;
639}
640
641Error AidlComposer::setClientTarget(Display display, uint32_t slot, const sp<GraphicBuffer>& target,
642 int acquireFence, Dataspace dataspace,
643 const std::vector<IComposerClient::Rect>& damage) {
Ady Abrahame7385f72021-09-05 00:54:25 -0700644 const native_handle_t* handle = nullptr;
645 if (target.get()) {
646 handle = target->getNativeBuffer()->handle;
647 }
648
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400649 Error error = Error::NONE;
650 mMutex.lock_shared();
651 if (auto writer = getWriter(display)) {
652 writer->get()
653 .setClientTarget(translate<int64_t>(display), slot, handle, acquireFence,
654 translate<aidl::android::hardware::graphics::common::Dataspace>(
655 dataspace),
656 translate<AidlRect>(damage));
657 } else {
658 error = Error::BAD_DISPLAY;
659 }
660 mMutex.unlock_shared();
661 return error;
Ady Abrahame7385f72021-09-05 00:54:25 -0700662}
663
664Error AidlComposer::setColorMode(Display display, ColorMode mode, RenderIntent renderIntent) {
665 const auto status =
666 mAidlComposerClient->setColorMode(translate<int64_t>(display),
667 translate<AidlColorMode>(mode),
668 translate<AidlRenderIntent>(renderIntent));
669 if (!status.isOk()) {
670 ALOGE("setColorMode failed %s", status.getDescription().c_str());
671 return static_cast<Error>(status.getServiceSpecificError());
672 }
673 return Error::NONE;
674}
675
Ady Abrahamdc011a92021-12-21 14:06:44 -0800676Error AidlComposer::setColorTransform(Display display, const float* matrix) {
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400677 auto error = Error::NONE;
678 mMutex.lock_shared();
679 if (auto writer = getWriter(display)) {
680 writer->get().setColorTransform(translate<int64_t>(display), matrix);
681 } else {
682 error = Error::BAD_DISPLAY;
683 }
684 mMutex.unlock_shared();
685 return error;
Ady Abrahame7385f72021-09-05 00:54:25 -0700686}
687
688Error AidlComposer::setOutputBuffer(Display display, const native_handle_t* buffer,
689 int releaseFence) {
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400690 auto error = Error::NONE;
691 mMutex.lock_shared();
692 if (auto writer = getWriter(display)) {
693 writer->get().setOutputBuffer(translate<int64_t>(display), 0, buffer, dup(releaseFence));
694 } else {
695 error = Error::BAD_DISPLAY;
696 }
697 mMutex.unlock_shared();
698 return error;
Ady Abrahame7385f72021-09-05 00:54:25 -0700699}
700
701Error AidlComposer::setPowerMode(Display display, IComposerClient::PowerMode mode) {
702 const auto status = mAidlComposerClient->setPowerMode(translate<int64_t>(display),
703 translate<PowerMode>(mode));
704 if (!status.isOk()) {
705 ALOGE("setPowerMode failed %s", status.getDescription().c_str());
706 return static_cast<Error>(status.getServiceSpecificError());
707 }
708 return Error::NONE;
709}
710
711Error AidlComposer::setVsyncEnabled(Display display, IComposerClient::Vsync enabled) {
712 const bool enableVsync = enabled == IComposerClient::Vsync::ENABLE;
713 const auto status =
714 mAidlComposerClient->setVsyncEnabled(translate<int64_t>(display), enableVsync);
715 if (!status.isOk()) {
716 ALOGE("setVsyncEnabled failed %s", status.getDescription().c_str());
717 return static_cast<Error>(status.getServiceSpecificError());
718 }
719 return Error::NONE;
720}
721
722Error AidlComposer::setClientTargetSlotCount(Display display) {
723 const int32_t bufferSlotCount = BufferQueue::NUM_BUFFER_SLOTS;
724 const auto status = mAidlComposerClient->setClientTargetSlotCount(translate<int64_t>(display),
725 bufferSlotCount);
726 if (!status.isOk()) {
727 ALOGE("setClientTargetSlotCount failed %s", status.getDescription().c_str());
728 return static_cast<Error>(status.getServiceSpecificError());
729 }
730 return Error::NONE;
731}
732
Ady Abraham43065bd2021-12-10 17:22:15 -0800733Error AidlComposer::validateDisplay(Display display, nsecs_t expectedPresentTime,
734 uint32_t* outNumTypes, uint32_t* outNumRequests) {
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400735 const auto displayId = translate<int64_t>(display);
Leon Scroggins IIIe85e16e2022-12-12 12:51:18 -0500736 ATRACE_FORMAT("HwcValidateDisplay %" PRId64, displayId);
737
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400738 Error error = Error::NONE;
739 mMutex.lock_shared();
740 auto writer = getWriter(display);
741 auto reader = getReader(display);
742 if (writer && reader) {
743 writer->get().validateDisplay(displayId, ClockMonotonicTimestamp{expectedPresentTime});
744 error = execute(display);
745 } else {
746 error = Error::BAD_DISPLAY;
747 }
Ady Abrahame7385f72021-09-05 00:54:25 -0700748
Ady Abrahame7385f72021-09-05 00:54:25 -0700749 if (error != Error::NONE) {
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400750 mMutex.unlock_shared();
Ady Abrahame7385f72021-09-05 00:54:25 -0700751 return error;
752 }
753
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400754 reader->get().hasChanges(displayId, outNumTypes, outNumRequests);
Ady Abrahame7385f72021-09-05 00:54:25 -0700755
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400756 mMutex.unlock_shared();
Ady Abrahame7385f72021-09-05 00:54:25 -0700757 return Error::NONE;
758}
759
Ady Abraham43065bd2021-12-10 17:22:15 -0800760Error AidlComposer::presentOrValidateDisplay(Display display, nsecs_t expectedPresentTime,
761 uint32_t* outNumTypes, uint32_t* outNumRequests,
762 int* outPresentFence, uint32_t* state) {
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400763 const auto displayId = translate<int64_t>(display);
Leon Scroggins IIIe85e16e2022-12-12 12:51:18 -0500764 ATRACE_FORMAT("HwcPresentOrValidateDisplay %" PRId64, displayId);
765
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400766 Error error = Error::NONE;
767 mMutex.lock_shared();
768 auto writer = getWriter(display);
769 auto reader = getReader(display);
770 if (writer && reader) {
771 writer->get().presentOrvalidateDisplay(displayId,
772 ClockMonotonicTimestamp{expectedPresentTime});
773 error = execute(display);
774 } else {
775 error = Error::BAD_DISPLAY;
776 }
Ady Abrahame7385f72021-09-05 00:54:25 -0700777
Ady Abrahame7385f72021-09-05 00:54:25 -0700778 if (error != Error::NONE) {
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400779 mMutex.unlock_shared();
Ady Abrahame7385f72021-09-05 00:54:25 -0700780 return error;
781 }
782
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400783 const auto result = reader->get().takePresentOrValidateStage(displayId);
Ady Abrahamde792782021-12-20 10:00:49 -0800784 if (!result.has_value()) {
785 *state = translate<uint32_t>(-1);
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400786 mMutex.unlock_shared();
Ady Abrahamde792782021-12-20 10:00:49 -0800787 return Error::NO_RESOURCES;
Ady Abrahame7385f72021-09-05 00:54:25 -0700788 }
789
Ady Abrahamde792782021-12-20 10:00:49 -0800790 *state = translate<uint32_t>(*result);
791
792 if (*result == PresentOrValidate::Result::Presented) {
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400793 auto fence = reader->get().takePresentFence(displayId);
Ady Abrahamde792782021-12-20 10:00:49 -0800794 // take ownership
795 *outPresentFence = fence.get();
796 *fence.getR() = -1;
797 }
798
799 if (*result == PresentOrValidate::Result::Validated) {
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400800 reader->get().hasChanges(displayId, outNumTypes, outNumRequests);
Ady Abrahame7385f72021-09-05 00:54:25 -0700801 }
802
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400803 mMutex.unlock_shared();
Ady Abrahame7385f72021-09-05 00:54:25 -0700804 return Error::NONE;
805}
806
807Error AidlComposer::setCursorPosition(Display display, Layer layer, int32_t x, int32_t y) {
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400808 Error error = Error::NONE;
809 mMutex.lock_shared();
810 if (auto writer = getWriter(display)) {
811 writer->get().setLayerCursorPosition(translate<int64_t>(display), translate<int64_t>(layer),
812 x, y);
813 } else {
814 error = Error::BAD_DISPLAY;
815 }
816 mMutex.unlock_shared();
817 return error;
Ady Abrahame7385f72021-09-05 00:54:25 -0700818}
819
820Error AidlComposer::setLayerBuffer(Display display, Layer layer, uint32_t slot,
821 const sp<GraphicBuffer>& buffer, int acquireFence) {
Ady Abrahame7385f72021-09-05 00:54:25 -0700822 const native_handle_t* handle = nullptr;
823 if (buffer.get()) {
824 handle = buffer->getNativeBuffer()->handle;
825 }
826
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400827 Error error = Error::NONE;
828 mMutex.lock_shared();
829 if (auto writer = getWriter(display)) {
830 writer->get().setLayerBuffer(translate<int64_t>(display), translate<int64_t>(layer), slot,
831 handle, acquireFence);
832 } else {
833 error = Error::BAD_DISPLAY;
834 }
835 mMutex.unlock_shared();
836 return error;
Ady Abrahame7385f72021-09-05 00:54:25 -0700837}
838
Brian Lindahlb158a5c2022-12-15 15:21:13 -0700839Error AidlComposer::setLayerBufferSlotsToClear(Display display, Layer layer,
840 const std::vector<uint32_t>& slotsToClear,
841 uint32_t activeBufferSlot) {
842 if (slotsToClear.empty()) {
843 return Error::NONE;
844 }
845
Brian Lindahl90553da2022-12-06 13:36:30 -0700846 Error error = Error::NONE;
847 mMutex.lock_shared();
848 if (auto writer = getWriter(display)) {
Brian Lindahldbf7e3a2022-12-16 11:43:39 -0700849 // Backwards compatible way of clearing buffer is to set the layer buffer with a placeholder
850 // buffer, using the slot that needs to cleared... tricky.
851 if (mClearSlotBuffer == nullptr) {
852 writer->get().setLayerBufferSlotsToClear(translate<int64_t>(display),
853 translate<int64_t>(layer), slotsToClear);
854 } else {
855 for (uint32_t slot : slotsToClear) {
856 // Don't clear the active buffer slot because we need to restore the active buffer
857 // after clearing the requested buffer slots with a placeholder buffer.
858 if (slot != activeBufferSlot) {
859 writer->get().setLayerBufferWithNewCommand(translate<int64_t>(display),
860 translate<int64_t>(layer), slot,
861 mClearSlotBuffer->handle,
862 /*fence*/ -1);
863 }
Brian Lindahlb158a5c2022-12-15 15:21:13 -0700864 }
Brian Lindahldbf7e3a2022-12-16 11:43:39 -0700865 // Since we clear buffers by setting them to a placeholder buffer, we want to make
866 // sure that the last setLayerBuffer command is sent with the currently active
867 // buffer, not the placeholder buffer, so that there is no perceptual change when
868 // buffers are discarded.
869 writer->get().setLayerBufferWithNewCommand(translate<int64_t>(display),
870 translate<int64_t>(layer), activeBufferSlot,
871 // The active buffer is still cached in
872 // its slot and doesn't need a fence.
873 /*buffer*/ nullptr, /*fence*/ -1);
Brian Lindahlb158a5c2022-12-15 15:21:13 -0700874 }
Brian Lindahl90553da2022-12-06 13:36:30 -0700875 } else {
876 error = Error::BAD_DISPLAY;
877 }
878 mMutex.unlock_shared();
879 return error;
880}
881
Ady Abrahame7385f72021-09-05 00:54:25 -0700882Error AidlComposer::setLayerSurfaceDamage(Display display, Layer layer,
883 const std::vector<IComposerClient::Rect>& damage) {
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400884 Error error = Error::NONE;
885 mMutex.lock_shared();
886 if (auto writer = getWriter(display)) {
887 writer->get().setLayerSurfaceDamage(translate<int64_t>(display), translate<int64_t>(layer),
888 translate<AidlRect>(damage));
889 } else {
890 error = Error::BAD_DISPLAY;
891 }
892 mMutex.unlock_shared();
893 return error;
Ady Abrahame7385f72021-09-05 00:54:25 -0700894}
895
896Error AidlComposer::setLayerBlendMode(Display display, Layer layer,
897 IComposerClient::BlendMode mode) {
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400898 Error error = Error::NONE;
899 mMutex.lock_shared();
900 if (auto writer = getWriter(display)) {
901 writer->get().setLayerBlendMode(translate<int64_t>(display), translate<int64_t>(layer),
902 translate<BlendMode>(mode));
903 } else {
904 error = Error::BAD_DISPLAY;
905 }
906 mMutex.unlock_shared();
907 return error;
Ady Abrahame7385f72021-09-05 00:54:25 -0700908}
909
Ady Abraham6e60b142022-01-06 18:10:35 -0800910Error AidlComposer::setLayerColor(Display display, Layer layer, const Color& color) {
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400911 Error error = Error::NONE;
912 mMutex.lock_shared();
913 if (auto writer = getWriter(display)) {
914 writer->get().setLayerColor(translate<int64_t>(display), translate<int64_t>(layer), color);
915 } else {
916 error = Error::BAD_DISPLAY;
917 }
918 mMutex.unlock_shared();
919 return error;
Ady Abrahame7385f72021-09-05 00:54:25 -0700920}
921
Leon Scroggins III2e1aa182021-12-01 17:33:12 -0500922Error AidlComposer::setLayerCompositionType(
923 Display display, Layer layer,
924 aidl::android::hardware::graphics::composer3::Composition type) {
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400925 Error error = Error::NONE;
926 mMutex.lock_shared();
927 if (auto writer = getWriter(display)) {
928 writer->get().setLayerCompositionType(translate<int64_t>(display),
929 translate<int64_t>(layer), type);
930 } else {
931 error = Error::BAD_DISPLAY;
932 }
933 mMutex.unlock_shared();
934 return error;
Ady Abrahame7385f72021-09-05 00:54:25 -0700935}
936
937Error AidlComposer::setLayerDataspace(Display display, Layer layer, Dataspace dataspace) {
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400938 Error error = Error::NONE;
939 mMutex.lock_shared();
940 if (auto writer = getWriter(display)) {
941 writer->get().setLayerDataspace(translate<int64_t>(display), translate<int64_t>(layer),
942 translate<AidlDataspace>(dataspace));
943 } else {
944 error = Error::BAD_DISPLAY;
945 }
946 mMutex.unlock_shared();
947 return error;
Ady Abrahame7385f72021-09-05 00:54:25 -0700948}
949
950Error AidlComposer::setLayerDisplayFrame(Display display, Layer layer,
951 const IComposerClient::Rect& frame) {
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400952 Error error = Error::NONE;
953 mMutex.lock_shared();
954 if (auto writer = getWriter(display)) {
955 writer->get().setLayerDisplayFrame(translate<int64_t>(display), translate<int64_t>(layer),
956 translate<AidlRect>(frame));
957 } else {
958 error = Error::BAD_DISPLAY;
959 }
960 mMutex.unlock_shared();
961 return error;
Ady Abrahame7385f72021-09-05 00:54:25 -0700962}
963
964Error AidlComposer::setLayerPlaneAlpha(Display display, Layer layer, float alpha) {
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400965 Error error = Error::NONE;
966 mMutex.lock_shared();
967 if (auto writer = getWriter(display)) {
968 writer->get().setLayerPlaneAlpha(translate<int64_t>(display), translate<int64_t>(layer),
969 alpha);
970 } else {
971 error = Error::BAD_DISPLAY;
972 }
973 mMutex.unlock_shared();
974 return error;
Ady Abrahame7385f72021-09-05 00:54:25 -0700975}
976
977Error AidlComposer::setLayerSidebandStream(Display display, Layer layer,
978 const native_handle_t* stream) {
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400979 Error error = Error::NONE;
980 mMutex.lock_shared();
981 if (auto writer = getWriter(display)) {
982 writer->get().setLayerSidebandStream(translate<int64_t>(display), translate<int64_t>(layer),
983 stream);
984 } else {
985 error = Error::BAD_DISPLAY;
986 }
987 mMutex.unlock_shared();
988 return error;
Ady Abrahame7385f72021-09-05 00:54:25 -0700989}
990
991Error AidlComposer::setLayerSourceCrop(Display display, Layer layer,
992 const IComposerClient::FRect& crop) {
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400993 Error error = Error::NONE;
994 mMutex.lock_shared();
995 if (auto writer = getWriter(display)) {
996 writer->get().setLayerSourceCrop(translate<int64_t>(display), translate<int64_t>(layer),
997 translate<AidlFRect>(crop));
998 } else {
999 error = Error::BAD_DISPLAY;
1000 }
1001 mMutex.unlock_shared();
1002 return error;
Ady Abrahame7385f72021-09-05 00:54:25 -07001003}
1004
1005Error AidlComposer::setLayerTransform(Display display, Layer layer, Transform transform) {
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -04001006 Error error = Error::NONE;
1007 mMutex.lock_shared();
1008 if (auto writer = getWriter(display)) {
1009 writer->get().setLayerTransform(translate<int64_t>(display), translate<int64_t>(layer),
1010 translate<AidlTransform>(transform));
1011 } else {
1012 error = Error::BAD_DISPLAY;
1013 }
1014 mMutex.unlock_shared();
1015 return error;
Ady Abrahame7385f72021-09-05 00:54:25 -07001016}
1017
1018Error AidlComposer::setLayerVisibleRegion(Display display, Layer layer,
1019 const std::vector<IComposerClient::Rect>& visible) {
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -04001020 Error error = Error::NONE;
1021 mMutex.lock_shared();
1022 if (auto writer = getWriter(display)) {
1023 writer->get().setLayerVisibleRegion(translate<int64_t>(display), translate<int64_t>(layer),
1024 translate<AidlRect>(visible));
1025 } else {
1026 error = Error::BAD_DISPLAY;
1027 }
1028 mMutex.unlock_shared();
1029 return error;
Ady Abrahame7385f72021-09-05 00:54:25 -07001030}
1031
1032Error AidlComposer::setLayerZOrder(Display display, Layer layer, uint32_t z) {
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -04001033 Error error = Error::NONE;
1034 mMutex.lock_shared();
1035 if (auto writer = getWriter(display)) {
1036 writer->get().setLayerZOrder(translate<int64_t>(display), translate<int64_t>(layer), z);
1037 } else {
1038 error = Error::BAD_DISPLAY;
1039 }
1040 mMutex.unlock_shared();
1041 return error;
Ady Abrahame7385f72021-09-05 00:54:25 -07001042}
1043
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -04001044Error AidlComposer::execute(Display display) {
1045 auto writer = getWriter(display);
1046 auto reader = getReader(display);
1047 if (!writer || !reader) {
1048 return Error::BAD_DISPLAY;
1049 }
1050
1051 const auto& commands = writer->get().getPendingCommands();
Ady Abrahama6388c02021-11-11 21:11:51 -08001052 if (commands.empty()) {
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -04001053 writer->get().reset();
Ady Abrahame7385f72021-09-05 00:54:25 -07001054 return Error::NONE;
1055 }
1056
Ady Abrahamde792782021-12-20 10:00:49 -08001057 { // scope for results
1058 std::vector<CommandResultPayload> results;
1059 auto status = mAidlComposerClient->executeCommands(commands, &results);
1060 if (!status.isOk()) {
1061 ALOGE("executeCommands failed %s", status.getDescription().c_str());
1062 return static_cast<Error>(status.getServiceSpecificError());
1063 }
Ady Abrahame7385f72021-09-05 00:54:25 -07001064
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -04001065 reader->get().parse(std::move(results));
Ady Abrahamde792782021-12-20 10:00:49 -08001066 }
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -04001067 const auto commandErrors = reader->get().takeErrors();
Ady Abrahama6388c02021-11-11 21:11:51 -08001068 Error error = Error::NONE;
1069 for (const auto& cmdErr : commandErrors) {
1070 const auto index = static_cast<size_t>(cmdErr.commandIndex);
1071 if (index < 0 || index >= commands.size()) {
1072 ALOGE("invalid command index %zu", index);
1073 return Error::BAD_PARAMETER;
Ady Abrahame7385f72021-09-05 00:54:25 -07001074 }
1075
Ady Abrahama6388c02021-11-11 21:11:51 -08001076 const auto& command = commands[index];
Ady Abraham42977362021-12-07 21:04:49 -08001077 if (command.validateDisplay || command.presentDisplay || command.presentOrValidateDisplay) {
1078 error = translate<Error>(cmdErr.errorCode);
1079 } else {
1080 ALOGW("command '%s' generated error %" PRId32, command.toString().c_str(),
1081 cmdErr.errorCode);
Ady Abrahame7385f72021-09-05 00:54:25 -07001082 }
1083 }
1084
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -04001085 writer->get().reset();
Ady Abrahame7385f72021-09-05 00:54:25 -07001086
1087 return error;
1088}
1089
1090Error AidlComposer::setLayerPerFrameMetadata(
1091 Display display, Layer layer,
1092 const std::vector<IComposerClient::PerFrameMetadata>& perFrameMetadatas) {
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -04001093 Error error = Error::NONE;
1094 mMutex.lock_shared();
1095 if (auto writer = getWriter(display)) {
1096 writer->get().setLayerPerFrameMetadata(translate<int64_t>(display),
1097 translate<int64_t>(layer),
1098 translate<AidlPerFrameMetadata>(perFrameMetadatas));
1099 } else {
1100 error = Error::BAD_DISPLAY;
1101 }
1102 mMutex.unlock_shared();
1103 return error;
Ady Abrahame7385f72021-09-05 00:54:25 -07001104}
1105
1106std::vector<IComposerClient::PerFrameMetadataKey> AidlComposer::getPerFrameMetadataKeys(
1107 Display display) {
1108 std::vector<AidlPerFrameMetadataKey> keys;
1109 const auto status =
1110 mAidlComposerClient->getPerFrameMetadataKeys(translate<int64_t>(display), &keys);
1111 if (!status.isOk()) {
1112 ALOGE("getPerFrameMetadataKeys failed %s", status.getDescription().c_str());
1113 return {};
1114 }
1115 return translate<IComposerClient::PerFrameMetadataKey>(keys);
1116}
1117
1118Error AidlComposer::getRenderIntents(Display display, ColorMode colorMode,
1119 std::vector<RenderIntent>* outRenderIntents) {
1120 std::vector<AidlRenderIntent> renderIntents;
1121 const auto status = mAidlComposerClient->getRenderIntents(translate<int64_t>(display),
1122 translate<AidlColorMode>(colorMode),
1123 &renderIntents);
1124 if (!status.isOk()) {
1125 ALOGE("getRenderIntents failed %s", status.getDescription().c_str());
1126 return static_cast<Error>(status.getServiceSpecificError());
1127 }
1128 *outRenderIntents = translate<RenderIntent>(renderIntents);
1129 return Error::NONE;
1130}
1131
1132Error AidlComposer::getDataspaceSaturationMatrix(Dataspace dataspace, mat4* outMatrix) {
1133 std::vector<float> matrix;
1134 const auto status =
1135 mAidlComposerClient->getDataspaceSaturationMatrix(translate<AidlDataspace>(dataspace),
1136 &matrix);
1137 if (!status.isOk()) {
1138 ALOGE("getDataspaceSaturationMatrix failed %s", status.getDescription().c_str());
1139 return static_cast<Error>(status.getServiceSpecificError());
1140 }
1141 *outMatrix = makeMat4(matrix);
1142 return Error::NONE;
1143}
1144
1145Error AidlComposer::getDisplayIdentificationData(Display display, uint8_t* outPort,
1146 std::vector<uint8_t>* outData) {
1147 AidlDisplayIdentification displayIdentification;
1148 const auto status =
1149 mAidlComposerClient->getDisplayIdentificationData(translate<int64_t>(display),
1150 &displayIdentification);
1151 if (!status.isOk()) {
1152 ALOGE("getDisplayIdentificationData failed %s", status.getDescription().c_str());
1153 return static_cast<Error>(status.getServiceSpecificError());
1154 }
1155
1156 *outPort = static_cast<uint8_t>(displayIdentification.port);
1157 *outData = displayIdentification.data;
1158
1159 return Error::NONE;
1160}
1161
1162Error AidlComposer::setLayerColorTransform(Display display, Layer layer, const float* matrix) {
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -04001163 Error error = Error::NONE;
1164 mMutex.lock_shared();
1165 if (auto writer = getWriter(display)) {
1166 writer->get().setLayerColorTransform(translate<int64_t>(display), translate<int64_t>(layer),
1167 matrix);
1168 } else {
1169 error = Error::BAD_DISPLAY;
1170 }
1171 mMutex.unlock_shared();
1172 return error;
Ady Abrahame7385f72021-09-05 00:54:25 -07001173}
1174
1175Error AidlComposer::getDisplayedContentSamplingAttributes(Display display, PixelFormat* outFormat,
1176 Dataspace* outDataspace,
1177 uint8_t* outComponentMask) {
1178 if (!outFormat || !outDataspace || !outComponentMask) {
1179 return Error::BAD_PARAMETER;
1180 }
1181
1182 AidlDisplayContentSamplingAttributes attributes;
1183 const auto status =
1184 mAidlComposerClient->getDisplayedContentSamplingAttributes(translate<int64_t>(display),
1185 &attributes);
1186 if (!status.isOk()) {
1187 ALOGE("getDisplayedContentSamplingAttributes failed %s", status.getDescription().c_str());
1188 return static_cast<Error>(status.getServiceSpecificError());
1189 }
1190
1191 *outFormat = translate<PixelFormat>(attributes.format);
1192 *outDataspace = translate<Dataspace>(attributes.dataspace);
1193 *outComponentMask = static_cast<uint8_t>(attributes.componentMask);
1194 return Error::NONE;
1195}
1196
1197Error AidlComposer::setDisplayContentSamplingEnabled(Display display, bool enabled,
1198 uint8_t componentMask, uint64_t maxFrames) {
1199 const auto status =
1200 mAidlComposerClient
1201 ->setDisplayedContentSamplingEnabled(translate<int64_t>(display), enabled,
1202 static_cast<AidlFormatColorComponent>(
1203 componentMask),
1204 static_cast<int64_t>(maxFrames));
1205 if (!status.isOk()) {
1206 ALOGE("setDisplayedContentSamplingEnabled failed %s", status.getDescription().c_str());
1207 return static_cast<Error>(status.getServiceSpecificError());
1208 }
1209 return Error::NONE;
1210}
1211
1212Error AidlComposer::getDisplayedContentSample(Display display, uint64_t maxFrames,
1213 uint64_t timestamp, DisplayedFrameStats* outStats) {
1214 if (!outStats) {
1215 return Error::BAD_PARAMETER;
1216 }
1217
1218 AidlDisplayContentSample sample;
1219 const auto status =
1220 mAidlComposerClient->getDisplayedContentSample(translate<int64_t>(display),
1221 static_cast<int64_t>(maxFrames),
1222 static_cast<int64_t>(timestamp),
1223 &sample);
1224 if (!status.isOk()) {
1225 ALOGE("getDisplayedContentSample failed %s", status.getDescription().c_str());
1226 return static_cast<Error>(status.getServiceSpecificError());
1227 }
1228 *outStats = translate<DisplayedFrameStats>(sample);
1229 return Error::NONE;
1230}
1231
1232Error AidlComposer::setLayerPerFrameMetadataBlobs(
1233 Display display, Layer layer,
1234 const std::vector<IComposerClient::PerFrameMetadataBlob>& metadata) {
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -04001235 Error error = Error::NONE;
1236 mMutex.lock_shared();
1237 if (auto writer = getWriter(display)) {
1238 writer->get().setLayerPerFrameMetadataBlobs(translate<int64_t>(display),
1239 translate<int64_t>(layer),
1240 translate<AidlPerFrameMetadataBlob>(metadata));
1241 } else {
1242 error = Error::BAD_DISPLAY;
1243 }
1244 mMutex.unlock_shared();
1245 return error;
Ady Abrahame7385f72021-09-05 00:54:25 -07001246}
1247
Alec Mouri4d8a05d2022-03-23 18:14:26 +00001248Error AidlComposer::setDisplayBrightness(Display display, float brightness, float brightnessNits,
Alec Mouricdf16792021-12-10 13:16:06 -08001249 const DisplayBrightnessOptions& options) {
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().setDisplayBrightness(translate<int64_t>(display), brightness, brightnessNits);
Alec Mouricdf16792021-12-10 13:16:06 -08001254
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -04001255 if (options.applyImmediately) {
1256 error = execute(display);
1257 mMutex.unlock_shared();
1258 return error;
1259 }
1260 } else {
1261 error = Error::BAD_DISPLAY;
Alec Mouricdf16792021-12-10 13:16:06 -08001262 }
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -04001263 mMutex.unlock_shared();
1264 return error;
Ady Abrahame7385f72021-09-05 00:54:25 -07001265}
1266
1267Error AidlComposer::getDisplayCapabilities(Display display,
Leon Scroggins III5967aec2021-12-29 11:14:22 -05001268 std::vector<AidlDisplayCapability>* outCapabilities) {
1269 const auto status = mAidlComposerClient->getDisplayCapabilities(translate<int64_t>(display),
1270 outCapabilities);
Ady Abrahame7385f72021-09-05 00:54:25 -07001271 if (!status.isOk()) {
1272 ALOGE("getDisplayCapabilities failed %s", status.getDescription().c_str());
Leon Scroggins III5967aec2021-12-29 11:14:22 -05001273 outCapabilities->clear();
Ady Abrahame7385f72021-09-05 00:54:25 -07001274 return static_cast<Error>(status.getServiceSpecificError());
1275 }
Ady Abrahame7385f72021-09-05 00:54:25 -07001276 return Error::NONE;
1277}
1278
1279V2_4::Error AidlComposer::getDisplayConnectionType(
1280 Display display, IComposerClient::DisplayConnectionType* outType) {
1281 AidlDisplayConnectionType type;
1282 const auto status =
1283 mAidlComposerClient->getDisplayConnectionType(translate<int64_t>(display), &type);
1284 if (!status.isOk()) {
1285 ALOGE("getDisplayConnectionType failed %s", status.getDescription().c_str());
1286 return static_cast<V2_4::Error>(status.getServiceSpecificError());
1287 }
1288 *outType = translate<IComposerClient::DisplayConnectionType>(type);
1289 return V2_4::Error::NONE;
1290}
1291
1292V2_4::Error AidlComposer::getDisplayVsyncPeriod(Display display, VsyncPeriodNanos* outVsyncPeriod) {
1293 int32_t vsyncPeriod;
1294 const auto status =
1295 mAidlComposerClient->getDisplayVsyncPeriod(translate<int64_t>(display), &vsyncPeriod);
1296 if (!status.isOk()) {
1297 ALOGE("getDisplayVsyncPeriod failed %s", status.getDescription().c_str());
1298 return static_cast<V2_4::Error>(status.getServiceSpecificError());
1299 }
1300 *outVsyncPeriod = translate<VsyncPeriodNanos>(vsyncPeriod);
1301 return V2_4::Error::NONE;
1302}
1303
1304V2_4::Error AidlComposer::setActiveConfigWithConstraints(
1305 Display display, Config config,
1306 const IComposerClient::VsyncPeriodChangeConstraints& vsyncPeriodChangeConstraints,
1307 VsyncPeriodChangeTimeline* outTimeline) {
1308 AidlVsyncPeriodChangeTimeline timeline;
1309 const auto status =
1310 mAidlComposerClient
1311 ->setActiveConfigWithConstraints(translate<int64_t>(display),
1312 translate<int32_t>(config),
1313 translate<AidlVsyncPeriodChangeConstraints>(
1314 vsyncPeriodChangeConstraints),
1315 &timeline);
1316 if (!status.isOk()) {
1317 ALOGE("setActiveConfigWithConstraints failed %s", status.getDescription().c_str());
1318 return static_cast<V2_4::Error>(status.getServiceSpecificError());
1319 }
1320 *outTimeline = translate<VsyncPeriodChangeTimeline>(timeline);
1321 return V2_4::Error::NONE;
1322}
1323
1324V2_4::Error AidlComposer::setAutoLowLatencyMode(Display display, bool on) {
1325 const auto status = mAidlComposerClient->setAutoLowLatencyMode(translate<int64_t>(display), on);
1326 if (!status.isOk()) {
1327 ALOGE("setAutoLowLatencyMode failed %s", status.getDescription().c_str());
1328 return static_cast<V2_4::Error>(status.getServiceSpecificError());
1329 }
1330 return V2_4::Error::NONE;
1331}
1332
1333V2_4::Error AidlComposer::getSupportedContentTypes(
1334 Display displayId, std::vector<IComposerClient::ContentType>* outSupportedContentTypes) {
1335 std::vector<AidlContentType> types;
1336 const auto status =
1337 mAidlComposerClient->getSupportedContentTypes(translate<int64_t>(displayId), &types);
1338 if (!status.isOk()) {
1339 ALOGE("getSupportedContentTypes failed %s", status.getDescription().c_str());
1340 return static_cast<V2_4::Error>(status.getServiceSpecificError());
1341 }
1342 *outSupportedContentTypes = translate<IComposerClient::ContentType>(types);
1343 return V2_4::Error::NONE;
1344}
1345
1346V2_4::Error AidlComposer::setContentType(Display display,
1347 IComposerClient::ContentType contentType) {
1348 const auto status =
1349 mAidlComposerClient->setContentType(translate<int64_t>(display),
1350 translate<AidlContentType>(contentType));
1351 if (!status.isOk()) {
1352 ALOGE("setContentType failed %s", status.getDescription().c_str());
1353 return static_cast<V2_4::Error>(status.getServiceSpecificError());
1354 }
1355 return V2_4::Error::NONE;
1356}
1357
Ady Abraham3f976752021-12-20 16:17:50 -08001358V2_4::Error AidlComposer::setLayerGenericMetadata(Display, Layer, const std::string&, bool,
1359 const std::vector<uint8_t>&) {
1360 // There are no users for this API. See b/209691612.
1361 return V2_4::Error::UNSUPPORTED;
Ady Abrahame7385f72021-09-05 00:54:25 -07001362}
1363
1364V2_4::Error AidlComposer::getLayerGenericMetadataKeys(
Ady Abraham3f976752021-12-20 16:17:50 -08001365 std::vector<IComposerClient::LayerGenericMetadataKey>*) {
1366 // There are no users for this API. See b/209691612.
1367 return V2_4::Error::UNSUPPORTED;
Ady Abrahame7385f72021-09-05 00:54:25 -07001368}
1369
Kriti Dang7defaf32021-11-15 11:55:43 +01001370Error AidlComposer::setBootDisplayConfig(Display display, Config config) {
1371 const auto status = mAidlComposerClient->setBootDisplayConfig(translate<int64_t>(display),
1372 translate<int32_t>(config));
1373 if (!status.isOk()) {
1374 ALOGE("setBootDisplayConfig failed %s", status.getDescription().c_str());
1375 return static_cast<Error>(status.getServiceSpecificError());
1376 }
1377 return Error::NONE;
1378}
1379
1380Error AidlComposer::clearBootDisplayConfig(Display display) {
1381 const auto status = mAidlComposerClient->clearBootDisplayConfig(translate<int64_t>(display));
1382 if (!status.isOk()) {
1383 ALOGE("clearBootDisplayConfig failed %s", status.getDescription().c_str());
1384 return static_cast<Error>(status.getServiceSpecificError());
1385 }
1386 return Error::NONE;
1387}
1388
1389Error AidlComposer::getPreferredBootDisplayConfig(Display display, Config* config) {
1390 int32_t displayConfig;
1391 const auto status =
1392 mAidlComposerClient->getPreferredBootDisplayConfig(translate<int64_t>(display),
1393 &displayConfig);
1394 if (!status.isOk()) {
1395 ALOGE("getPreferredBootDisplayConfig failed %s", status.getDescription().c_str());
1396 return static_cast<Error>(status.getServiceSpecificError());
1397 }
1398 *config = translate<uint32_t>(displayConfig);
1399 return Error::NONE;
1400}
1401
Kriti Dang674b9372022-11-18 10:58:44 +01001402Error AidlComposer::getHdrConversionCapabilities(
1403 std::vector<AidlHdrConversionCapability>* hdrConversionCapabilities) {
1404 const auto status =
1405 mAidlComposerClient->getHdrConversionCapabilities(hdrConversionCapabilities);
1406 if (!status.isOk()) {
1407 hdrConversionCapabilities = {};
1408 ALOGE("getHdrConversionCapabilities failed %s", status.getDescription().c_str());
1409 return static_cast<Error>(status.getServiceSpecificError());
1410 }
1411 return Error::NONE;
1412}
1413
1414Error AidlComposer::setHdrConversionStrategy(AidlHdrConversionStrategy hdrConversionStrategy) {
1415 const auto status = mAidlComposerClient->setHdrConversionStrategy(hdrConversionStrategy);
1416 if (!status.isOk()) {
1417 ALOGE("setHdrConversionStrategy failed %s", status.getDescription().c_str());
1418 return static_cast<Error>(status.getServiceSpecificError());
1419 }
1420 return Error::NONE;
1421}
1422
Ady Abrahame7385f72021-09-05 00:54:25 -07001423Error AidlComposer::getClientTargetProperty(
Alec Mouri85065692022-03-18 00:58:26 +00001424 Display display, ClientTargetPropertyWithBrightness* outClientTargetProperty) {
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -04001425 Error error = Error::NONE;
1426 mMutex.lock_shared();
1427 if (auto reader = getReader(display)) {
1428 *outClientTargetProperty =
1429 reader->get().takeClientTargetProperty(translate<int64_t>(display));
1430 } else {
1431 error = Error::BAD_DISPLAY;
1432 }
1433 mMutex.unlock_shared();
1434 return error;
Ady Abrahame7385f72021-09-05 00:54:25 -07001435}
1436
Alec Mouri6da0e272022-02-07 12:45:57 -08001437Error AidlComposer::setLayerBrightness(Display display, Layer layer, float brightness) {
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -04001438 Error error = Error::NONE;
1439 mMutex.lock_shared();
1440 if (auto writer = getWriter(display)) {
1441 writer->get().setLayerBrightness(translate<int64_t>(display), translate<int64_t>(layer),
1442 brightness);
1443 } else {
1444 error = Error::BAD_DISPLAY;
1445 }
1446 mMutex.unlock_shared();
1447 return error;
Alec Mouricdf6cbc2021-11-01 17:21:15 -07001448}
1449
Leon Scroggins IIId77d3162022-01-05 10:42:28 -05001450Error AidlComposer::setLayerBlockingRegion(Display display, Layer layer,
1451 const std::vector<IComposerClient::Rect>& blocking) {
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -04001452 Error error = Error::NONE;
1453 mMutex.lock_shared();
1454 if (auto writer = getWriter(display)) {
1455 writer->get().setLayerBlockingRegion(translate<int64_t>(display), translate<int64_t>(layer),
1456 translate<AidlRect>(blocking));
1457 } else {
1458 error = Error::BAD_DISPLAY;
1459 }
1460 mMutex.unlock_shared();
1461 return error;
Leon Scroggins IIId77d3162022-01-05 10:42:28 -05001462}
Leon Scroggins IIIe7c51c62022-02-01 15:53:54 -05001463
1464Error AidlComposer::getDisplayDecorationSupport(Display display,
1465 std::optional<DisplayDecorationSupport>* support) {
1466 const auto status =
1467 mAidlComposerClient->getDisplayDecorationSupport(translate<int64_t>(display), support);
1468 if (!status.isOk()) {
1469 ALOGE("getDisplayDecorationSupport failed %s", status.getDescription().c_str());
1470 support->reset();
1471 return static_cast<Error>(status.getServiceSpecificError());
1472 }
1473 return Error::NONE;
1474}
ramindani32cf0602022-03-02 02:30:29 +00001475
1476Error AidlComposer::setIdleTimerEnabled(Display displayId, std::chrono::milliseconds timeout) {
1477 const auto status =
1478 mAidlComposerClient->setIdleTimerEnabled(translate<int64_t>(displayId),
1479 translate<int32_t>(timeout.count()));
1480 if (!status.isOk()) {
1481 ALOGE("setIdleTimerEnabled failed %s", status.getDescription().c_str());
1482 return static_cast<Error>(status.getServiceSpecificError());
1483 }
1484 return Error::NONE;
1485}
1486
ramindani06e518e2022-03-14 18:47:53 +00001487Error AidlComposer::getPhysicalDisplayOrientation(Display displayId,
1488 AidlTransform* outDisplayOrientation) {
1489 const auto status =
1490 mAidlComposerClient->getDisplayPhysicalOrientation(translate<int64_t>(displayId),
1491 outDisplayOrientation);
1492 if (!status.isOk()) {
1493 ALOGE("getPhysicalDisplayOrientation failed %s", status.getDescription().c_str());
1494 return static_cast<Error>(status.getServiceSpecificError());
1495 }
1496 return Error::NONE;
1497}
1498
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -04001499ftl::Optional<std::reference_wrapper<ComposerClientWriter>> AidlComposer::getWriter(Display display)
1500 REQUIRES_SHARED(mMutex) {
1501 return mWriters.get(display);
1502}
1503
1504ftl::Optional<std::reference_wrapper<ComposerClientReader>> AidlComposer::getReader(Display display)
1505 REQUIRES_SHARED(mMutex) {
1506 if (mSingleReader) {
1507 display = translate<Display>(kSingleReaderKey);
1508 }
1509 return mReaders.get(display);
1510}
1511
1512void AidlComposer::removeDisplay(Display display) {
1513 mMutex.lock();
1514 bool wasErased = mWriters.erase(display);
1515 ALOGW_IF(!wasErased,
1516 "Attempting to remove writer for display %" PRId64 " which is not connected",
1517 translate<int64_t>(display));
1518 if (!mSingleReader) {
1519 removeReader(display);
1520 }
1521 mMutex.unlock();
1522}
1523
1524void AidlComposer::onHotplugDisconnect(Display display) {
1525 removeDisplay(display);
1526}
1527
1528bool AidlComposer::hasMultiThreadedPresentSupport(Display display) {
1529 const auto displayId = translate<int64_t>(display);
1530 std::vector<AidlDisplayCapability> capabilities;
1531 const auto status = mAidlComposerClient->getDisplayCapabilities(displayId, &capabilities);
1532 if (!status.isOk()) {
1533 ALOGE("getDisplayCapabilities failed %s", status.getDescription().c_str());
1534 return false;
1535 }
1536 return std::find(capabilities.begin(), capabilities.end(),
1537 AidlDisplayCapability::MULTI_THREADED_PRESENT) != capabilities.end();
1538}
1539
1540void AidlComposer::addReader(Display display) {
1541 const auto displayId = translate<int64_t>(display);
1542 std::optional<int64_t> displayOpt;
1543 if (displayId != kSingleReaderKey) {
1544 displayOpt.emplace(displayId);
1545 }
1546 auto [it, added] = mReaders.try_emplace(display, std::move(displayOpt));
1547 ALOGW_IF(!added, "Attempting to add writer for display %" PRId64 " which is already connected",
1548 displayId);
1549}
1550
1551void AidlComposer::removeReader(Display display) {
1552 bool wasErased = mReaders.erase(display);
1553 ALOGW_IF(!wasErased,
1554 "Attempting to remove reader for display %" PRId64 " which is not connected",
1555 translate<int64_t>(display));
1556}
1557
1558void AidlComposer::addDisplay(Display display) {
1559 const auto displayId = translate<int64_t>(display);
1560 mMutex.lock();
1561 auto [it, added] = mWriters.try_emplace(display, displayId);
1562 ALOGW_IF(!added, "Attempting to add writer for display %" PRId64 " which is already connected",
1563 displayId);
1564 if (mSingleReader) {
1565 if (hasMultiThreadedPresentSupport(display)) {
1566 mSingleReader = false;
1567 removeReader(translate<Display>(kSingleReaderKey));
1568 // Note that this includes the new display.
1569 for (const auto& [existingDisplay, _] : mWriters) {
1570 addReader(existingDisplay);
1571 }
1572 }
1573 } else {
1574 addReader(display);
1575 }
1576 mMutex.unlock();
1577}
1578
1579void AidlComposer::onHotplugConnect(Display display) {
1580 addDisplay(display);
1581}
Ady Abrahame7385f72021-09-05 00:54:25 -07001582} // namespace Hwc2
1583} // namespace android