blob: f28bfd44cd1fe2c9092dc5945274bca3986a9fd6 [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
ramindani12bfe6b2023-02-03 13:29:19 -0800211 ::ndk::ScopedAStatus onRefreshRateChangedDebug(
212 const RefreshRateChangedDebugData& refreshRateChangedDebugData) override {
213 mCallback.onRefreshRateChangedDebug(refreshRateChangedDebugData);
214 return ::ndk::ScopedAStatus::ok();
215 }
216
Ady Abrahame7385f72021-09-05 00:54:25 -0700217private:
Yichi Chen3401b562022-01-17 15:42:35 +0800218 HWC2::ComposerCallback& mCallback;
Ady Abrahame7385f72021-09-05 00:54:25 -0700219};
220
Ady Abraham9fc28052021-10-14 17:21:38 -0700221std::string AidlComposer::instance(const std::string& serviceName) {
222 return std::string(AidlIComposer::descriptor) + "/" + serviceName;
223}
224
225bool AidlComposer::isDeclared(const std::string& serviceName) {
226 return AServiceManager_isDeclared(instance(serviceName).c_str());
227}
Ady Abrahame7385f72021-09-05 00:54:25 -0700228
Ady Abrahama6388c02021-11-11 21:11:51 -0800229AidlComposer::AidlComposer(const std::string& serviceName) {
Ady Abrahame7385f72021-09-05 00:54:25 -0700230 // This only waits if the service is actually declared
Ady Abraham9fc28052021-10-14 17:21:38 -0700231 mAidlComposer = AidlIComposer::fromBinder(
232 ndk::SpAIBinder(AServiceManager_waitForService(instance(serviceName).c_str())));
Ady Abrahame7385f72021-09-05 00:54:25 -0700233 if (!mAidlComposer) {
234 LOG_ALWAYS_FATAL("Failed to get AIDL composer service");
235 return;
236 }
237
238 if (!mAidlComposer->createClient(&mAidlComposerClient).isOk()) {
239 LOG_ALWAYS_FATAL("Can't create AidlComposerClient, fallback to HIDL");
240 return;
241 }
242
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400243 addReader(translate<Display>(kSingleReaderKey));
244
Brian Lindahldbf7e3a2022-12-16 11:43:39 -0700245 // If unable to read interface version, then become backwards compatible.
246 int32_t version = 1;
247 const auto status = mAidlComposerClient->getInterfaceVersion(&version);
248 if (!status.isOk()) {
249 ALOGE("getInterfaceVersion for AidlComposer constructor failed %s",
250 status.getDescription().c_str());
251 }
252 if (version == 1) {
253 mClearSlotBuffer = sp<GraphicBuffer>::make(1, 1, PIXEL_FORMAT_RGBX_8888,
254 GraphicBuffer::USAGE_HW_COMPOSER |
255 GraphicBuffer::USAGE_SW_READ_OFTEN |
256 GraphicBuffer::USAGE_SW_WRITE_OFTEN,
257 "AidlComposer");
258 if (!mClearSlotBuffer || mClearSlotBuffer->initCheck() != ::android::OK) {
259 LOG_ALWAYS_FATAL("Failed to allocate a buffer for clearing layer buffer slots");
260 return;
261 }
Brian Lindahl90553da2022-12-06 13:36:30 -0700262 }
263
Ady Abrahame7385f72021-09-05 00:54:25 -0700264 ALOGI("Loaded AIDL composer3 HAL service");
265}
266
267AidlComposer::~AidlComposer() = default;
268
Ady Abraham4d211cf2021-12-14 16:19:03 -0800269bool AidlComposer::isSupported(OptionalFeature feature) const {
270 switch (feature) {
271 case OptionalFeature::RefreshRateSwitching:
Ady Abraham43065bd2021-12-10 17:22:15 -0800272 case OptionalFeature::ExpectedPresentTime:
Alec Mouricdf16792021-12-10 13:16:06 -0800273 case OptionalFeature::DisplayBrightnessCommand:
ramindani32cf0602022-03-02 02:30:29 +0000274 case OptionalFeature::KernelIdleTimer:
ramindani06e518e2022-03-14 18:47:53 +0000275 case OptionalFeature::PhysicalDisplayOrientation:
Ady Abraham4d211cf2021-12-14 16:19:03 -0800276 return true;
277 }
278}
279
Ady Abrahamde549d42022-01-26 19:19:17 -0800280std::vector<Capability> AidlComposer::getCapabilities() {
Ady Abrahame7385f72021-09-05 00:54:25 -0700281 std::vector<Capability> capabilities;
282 const auto status = mAidlComposer->getCapabilities(&capabilities);
283 if (!status.isOk()) {
284 ALOGE("getCapabilities failed %s", status.getDescription().c_str());
285 return {};
286 }
Ady Abrahamde549d42022-01-26 19:19:17 -0800287 return capabilities;
Ady Abrahame7385f72021-09-05 00:54:25 -0700288}
289
290std::string AidlComposer::dumpDebugInfo() {
Ady Abrahamc4acf512022-02-18 17:11:59 -0800291 int pipefds[2];
292 int result = pipe(pipefds);
293 if (result < 0) {
294 ALOGE("dumpDebugInfo: pipe failed: %s", strerror(errno));
Ady Abrahame7385f72021-09-05 00:54:25 -0700295 return {};
296 }
Ady Abrahamc4acf512022-02-18 17:11:59 -0800297
298 std::string str;
yihsing.shen58847c52022-09-23 15:39:30 +0800299 // Use other thread to read pipe to prevent
300 // pipe is full, making HWC be blocked in writing.
301 std::thread t([&]() {
302 base::ReadFdToString(pipefds[0], &str);
303 });
Ady Abrahamc4acf512022-02-18 17:11:59 -0800304 const auto status = mAidlComposer->dump(pipefds[1], /*args*/ nullptr, /*numArgs*/ 0);
305 // Close the write-end of the pipe to make sure that when reading from the
306 // read-end we will get eof instead of blocking forever
307 close(pipefds[1]);
308
yihsing.shen58847c52022-09-23 15:39:30 +0800309 if (status != STATUS_OK) {
Ady Abrahamc4acf512022-02-18 17:11:59 -0800310 ALOGE("dumpDebugInfo: dump failed: %d", status);
311 }
312
yihsing.shen58847c52022-09-23 15:39:30 +0800313 t.join();
Ady Abrahamc4acf512022-02-18 17:11:59 -0800314 close(pipefds[0]);
315 return str;
Ady Abrahame7385f72021-09-05 00:54:25 -0700316}
317
Yichi Chen3401b562022-01-17 15:42:35 +0800318void AidlComposer::registerCallback(HWC2::ComposerCallback& callback) {
Ady Abrahame7385f72021-09-05 00:54:25 -0700319 if (mAidlComposerCallback) {
320 ALOGE("Callback already registered");
321 }
Yichi Chen3401b562022-01-17 15:42:35 +0800322
Ady Abraham9fc28052021-10-14 17:21:38 -0700323 mAidlComposerCallback = ndk::SharedRefBase::make<AidlIComposerCallbackWrapper>(callback);
Ady Abrahame7385f72021-09-05 00:54:25 -0700324 AIBinder_setMinSchedulerPolicy(mAidlComposerCallback->asBinder().get(), SCHED_FIFO, 2);
325
326 const auto status = mAidlComposerClient->registerCallback(mAidlComposerCallback);
327 if (!status.isOk()) {
328 ALOGE("registerCallback failed %s", status.getDescription().c_str());
329 }
330}
331
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400332void AidlComposer::resetCommands(Display display) {
333 mMutex.lock_shared();
334 if (auto writer = getWriter(display)) {
335 writer->get().reset();
336 }
337 mMutex.unlock_shared();
Ady Abrahame7385f72021-09-05 00:54:25 -0700338}
339
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400340Error AidlComposer::executeCommands(Display display) {
341 mMutex.lock_shared();
342 auto error = execute(display);
343 mMutex.unlock_shared();
344 return error;
Ady Abrahame7385f72021-09-05 00:54:25 -0700345}
346
347uint32_t AidlComposer::getMaxVirtualDisplayCount() {
348 int32_t count = 0;
349 const auto status = mAidlComposerClient->getMaxVirtualDisplayCount(&count);
350 if (!status.isOk()) {
351 ALOGE("getMaxVirtualDisplayCount failed %s", status.getDescription().c_str());
352 return 0;
353 }
354 return static_cast<uint32_t>(count);
355}
356
357Error AidlComposer::createVirtualDisplay(uint32_t width, uint32_t height, PixelFormat* format,
358 Display* outDisplay) {
359 using AidlPixelFormat = aidl::android::hardware::graphics::common::PixelFormat;
360 const int32_t bufferSlotCount = 1;
361 VirtualDisplay virtualDisplay;
362 const auto status =
363 mAidlComposerClient->createVirtualDisplay(static_cast<int32_t>(width),
364 static_cast<int32_t>(height),
365 static_cast<AidlPixelFormat>(*format),
366 bufferSlotCount, &virtualDisplay);
367
368 if (!status.isOk()) {
369 ALOGE("createVirtualDisplay failed %s", status.getDescription().c_str());
370 return static_cast<Error>(status.getServiceSpecificError());
371 }
372
373 *outDisplay = translate<Display>(virtualDisplay.display);
374 *format = static_cast<PixelFormat>(virtualDisplay.format);
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400375 addDisplay(translate<Display>(virtualDisplay.display));
Ady Abrahame7385f72021-09-05 00:54:25 -0700376 return Error::NONE;
377}
378
379Error AidlComposer::destroyVirtualDisplay(Display display) {
380 const auto status = mAidlComposerClient->destroyVirtualDisplay(translate<int64_t>(display));
381 if (!status.isOk()) {
382 ALOGE("destroyVirtualDisplay failed %s", status.getDescription().c_str());
383 return static_cast<Error>(status.getServiceSpecificError());
384 }
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400385 removeDisplay(display);
Ady Abrahame7385f72021-09-05 00:54:25 -0700386 return Error::NONE;
387}
388
389Error AidlComposer::acceptDisplayChanges(Display display) {
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400390 Error error = Error::NONE;
391 mMutex.lock_shared();
392 if (auto writer = getWriter(display)) {
393 writer->get().acceptDisplayChanges(translate<int64_t>(display));
394 } else {
395 error = Error::BAD_DISPLAY;
396 }
397 mMutex.unlock_shared();
398 return error;
Ady Abrahame7385f72021-09-05 00:54:25 -0700399}
400
401Error AidlComposer::createLayer(Display display, Layer* outLayer) {
402 int64_t layer;
403 const auto status = mAidlComposerClient->createLayer(translate<int64_t>(display),
404 kMaxLayerBufferCount, &layer);
405 if (!status.isOk()) {
406 ALOGE("createLayer failed %s", status.getDescription().c_str());
407 return static_cast<Error>(status.getServiceSpecificError());
408 }
409
410 *outLayer = translate<Layer>(layer);
411 return Error::NONE;
412}
413
414Error AidlComposer::destroyLayer(Display display, Layer layer) {
415 const auto status = mAidlComposerClient->destroyLayer(translate<int64_t>(display),
416 translate<int64_t>(layer));
417 if (!status.isOk()) {
418 ALOGE("destroyLayer failed %s", status.getDescription().c_str());
419 return static_cast<Error>(status.getServiceSpecificError());
420 }
421 return Error::NONE;
422}
423
424Error AidlComposer::getActiveConfig(Display display, Config* outConfig) {
425 int32_t config;
426 const auto status = mAidlComposerClient->getActiveConfig(translate<int64_t>(display), &config);
427 if (!status.isOk()) {
428 ALOGE("getActiveConfig failed %s", status.getDescription().c_str());
429 return static_cast<Error>(status.getServiceSpecificError());
430 }
431 *outConfig = translate<Config>(config);
432 return Error::NONE;
433}
434
435Error AidlComposer::getChangedCompositionTypes(
436 Display display, std::vector<Layer>* outLayers,
Leon Scroggins III2e1aa182021-12-01 17:33:12 -0500437 std::vector<aidl::android::hardware::graphics::composer3::Composition>* outTypes) {
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400438 std::vector<ChangedCompositionLayer> changedLayers;
439 Error error = Error::NONE;
440 {
441 mMutex.lock_shared();
442 if (auto reader = getReader(display)) {
443 changedLayers = reader->get().takeChangedCompositionTypes(translate<int64_t>(display));
444 } else {
445 error = Error::BAD_DISPLAY;
446 }
447 mMutex.unlock_shared();
448 }
Ady Abrahamde792782021-12-20 10:00:49 -0800449 outLayers->reserve(changedLayers.size());
450 outTypes->reserve(changedLayers.size());
Ady Abrahama6388c02021-11-11 21:11:51 -0800451
Ady Abrahamde792782021-12-20 10:00:49 -0800452 for (const auto& layer : changedLayers) {
453 outLayers->emplace_back(translate<Layer>(layer.layer));
454 outTypes->emplace_back(layer.composition);
455 }
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400456 return error;
Ady Abrahame7385f72021-09-05 00:54:25 -0700457}
458
459Error AidlComposer::getColorModes(Display display, std::vector<ColorMode>* outModes) {
460 std::vector<AidlColorMode> modes;
461 const auto status = mAidlComposerClient->getColorModes(translate<int64_t>(display), &modes);
462 if (!status.isOk()) {
463 ALOGE("getColorModes failed %s", status.getDescription().c_str());
464 return static_cast<Error>(status.getServiceSpecificError());
465 }
466 *outModes = translate<ColorMode>(modes);
467 return Error::NONE;
468}
469
470Error AidlComposer::getDisplayAttribute(Display display, Config config,
471 IComposerClient::Attribute attribute, int32_t* outValue) {
472 const auto status =
473 mAidlComposerClient->getDisplayAttribute(translate<int64_t>(display),
474 translate<int32_t>(config),
475 static_cast<AidlDisplayAttribute>(attribute),
476 outValue);
477 if (!status.isOk()) {
478 ALOGE("getDisplayAttribute failed %s", status.getDescription().c_str());
479 return static_cast<Error>(status.getServiceSpecificError());
480 }
481 return Error::NONE;
482}
483
484Error AidlComposer::getDisplayConfigs(Display display, std::vector<Config>* outConfigs) {
485 std::vector<int32_t> configs;
486 const auto status =
487 mAidlComposerClient->getDisplayConfigs(translate<int64_t>(display), &configs);
488 if (!status.isOk()) {
489 ALOGE("getDisplayConfigs failed %s", status.getDescription().c_str());
490 return static_cast<Error>(status.getServiceSpecificError());
491 }
492 *outConfigs = translate<Config>(configs);
493 return Error::NONE;
494}
495
496Error AidlComposer::getDisplayName(Display display, std::string* outName) {
497 const auto status = mAidlComposerClient->getDisplayName(translate<int64_t>(display), outName);
498 if (!status.isOk()) {
499 ALOGE("getDisplayName failed %s", status.getDescription().c_str());
500 return static_cast<Error>(status.getServiceSpecificError());
501 }
502 return Error::NONE;
503}
504
505Error AidlComposer::getDisplayRequests(Display display, uint32_t* outDisplayRequestMask,
506 std::vector<Layer>* outLayers,
507 std::vector<uint32_t>* outLayerRequestMasks) {
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400508 Error error = Error::NONE;
509 DisplayRequest displayRequests;
510 {
511 mMutex.lock_shared();
512 if (auto reader = getReader(display)) {
513 displayRequests = reader->get().takeDisplayRequests(translate<int64_t>(display));
514 } else {
515 error = Error::BAD_DISPLAY;
516 }
517 mMutex.unlock_shared();
518 }
Ady Abrahamde792782021-12-20 10:00:49 -0800519 *outDisplayRequestMask = translate<uint32_t>(displayRequests.mask);
520 outLayers->reserve(displayRequests.layerRequests.size());
521 outLayerRequestMasks->reserve(displayRequests.layerRequests.size());
522
523 for (const auto& layer : displayRequests.layerRequests) {
524 outLayers->emplace_back(translate<Layer>(layer.layer));
525 outLayerRequestMasks->emplace_back(translate<uint32_t>(layer.mask));
526 }
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400527 return error;
Ady Abrahame7385f72021-09-05 00:54:25 -0700528}
529
530Error AidlComposer::getDozeSupport(Display display, bool* outSupport) {
Ady Abraham33b92b92021-12-08 18:30:27 -0800531 std::vector<AidlDisplayCapability> capabilities;
Ady Abrahame7385f72021-09-05 00:54:25 -0700532 const auto status =
Ady Abraham33b92b92021-12-08 18:30:27 -0800533 mAidlComposerClient->getDisplayCapabilities(translate<int64_t>(display), &capabilities);
Ady Abrahame7385f72021-09-05 00:54:25 -0700534 if (!status.isOk()) {
Ady Abraham33b92b92021-12-08 18:30:27 -0800535 ALOGE("getDisplayCapabilities failed %s", status.getDescription().c_str());
Ady Abrahame7385f72021-09-05 00:54:25 -0700536 return static_cast<Error>(status.getServiceSpecificError());
537 }
Ady Abraham33b92b92021-12-08 18:30:27 -0800538 *outSupport = std::find(capabilities.begin(), capabilities.end(),
539 AidlDisplayCapability::DOZE) != capabilities.end();
Ady Abrahame7385f72021-09-05 00:54:25 -0700540 return Error::NONE;
541}
542
ramindani32cf0602022-03-02 02:30:29 +0000543Error AidlComposer::hasDisplayIdleTimerCapability(Display display, bool* outSupport) {
544 std::vector<AidlDisplayCapability> capabilities;
545 const auto status =
546 mAidlComposerClient->getDisplayCapabilities(translate<int64_t>(display), &capabilities);
547 if (!status.isOk()) {
548 ALOGE("getDisplayCapabilities failed %s", status.getDescription().c_str());
549 return static_cast<Error>(status.getServiceSpecificError());
550 }
551 *outSupport = std::find(capabilities.begin(), capabilities.end(),
552 AidlDisplayCapability::DISPLAY_IDLE_TIMER) != capabilities.end();
553 return Error::NONE;
554}
555
Ady Abrahame7385f72021-09-05 00:54:25 -0700556Error AidlComposer::getHdrCapabilities(Display display, std::vector<Hdr>* outTypes,
557 float* outMaxLuminance, float* outMaxAverageLuminance,
558 float* outMinLuminance) {
559 AidlHdrCapabilities capabilities;
560 const auto status =
561 mAidlComposerClient->getHdrCapabilities(translate<int64_t>(display), &capabilities);
562 if (!status.isOk()) {
563 ALOGE("getHdrCapabilities failed %s", status.getDescription().c_str());
564 return static_cast<Error>(status.getServiceSpecificError());
565 }
566
Marc Kassisbdf7e4b2022-11-04 17:26:48 +0100567 *outTypes = capabilities.types;
Ady Abrahame7385f72021-09-05 00:54:25 -0700568 *outMaxLuminance = capabilities.maxLuminance;
569 *outMaxAverageLuminance = capabilities.maxAverageLuminance;
570 *outMinLuminance = capabilities.minLuminance;
571 return Error::NONE;
572}
573
Sally Qibb866c12022-10-17 11:31:20 -0700574Error AidlComposer::getOverlaySupport(AidlOverlayProperties* outProperties) {
575 const auto status = mAidlComposerClient->getOverlaySupport(outProperties);
576 if (!status.isOk()) {
577 ALOGE("getOverlaySupport failed %s", status.getDescription().c_str());
578 return static_cast<Error>(status.getServiceSpecificError());
579 }
Sally Qi0cbd08b2022-08-17 12:12:28 -0700580 return Error::NONE;
581}
582
Ady Abrahame7385f72021-09-05 00:54:25 -0700583Error AidlComposer::getReleaseFences(Display display, std::vector<Layer>* outLayers,
584 std::vector<int>* outReleaseFences) {
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400585 Error error = Error::NONE;
586 std::vector<ReleaseFences::Layer> fences;
587 {
588 mMutex.lock_shared();
589 if (auto reader = getReader(display)) {
590 fences = reader->get().takeReleaseFences(translate<int64_t>(display));
591 } else {
592 error = Error::BAD_DISPLAY;
593 }
594 mMutex.unlock_shared();
595 }
Ady Abrahamde792782021-12-20 10:00:49 -0800596 outLayers->reserve(fences.size());
597 outReleaseFences->reserve(fences.size());
598
599 for (auto& fence : fences) {
600 outLayers->emplace_back(translate<Layer>(fence.layer));
601 // take ownership
602 const int fenceOwner = fence.fence.get();
603 *fence.fence.getR() = -1;
604 outReleaseFences->emplace_back(fenceOwner);
605 }
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400606 return error;
Ady Abrahame7385f72021-09-05 00:54:25 -0700607}
608
609Error AidlComposer::presentDisplay(Display display, int* outPresentFence) {
Leon Scroggins IIIe85e16e2022-12-12 12:51:18 -0500610 const auto displayId = translate<int64_t>(display);
611 ATRACE_FORMAT("HwcPresentDisplay %" PRId64, displayId);
612
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400613 Error error = Error::NONE;
614 mMutex.lock_shared();
615 auto writer = getWriter(display);
616 auto reader = getReader(display);
617 if (writer && reader) {
Leon Scroggins IIIe85e16e2022-12-12 12:51:18 -0500618 writer->get().presentDisplay(displayId);
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400619 error = execute(display);
620 } else {
621 error = Error::BAD_DISPLAY;
622 }
Ady Abrahame7385f72021-09-05 00:54:25 -0700623
Ady Abrahame7385f72021-09-05 00:54:25 -0700624 if (error != Error::NONE) {
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400625 mMutex.unlock_shared();
Ady Abrahame7385f72021-09-05 00:54:25 -0700626 return error;
627 }
628
Leon Scroggins IIIe85e16e2022-12-12 12:51:18 -0500629 auto fence = reader->get().takePresentFence(displayId);
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400630 mMutex.unlock_shared();
Ady Abrahamde792782021-12-20 10:00:49 -0800631 // take ownership
632 *outPresentFence = fence.get();
633 *fence.getR() = -1;
Ady Abrahame7385f72021-09-05 00:54:25 -0700634 return Error::NONE;
635}
636
637Error AidlComposer::setActiveConfig(Display display, Config config) {
638 const auto status = mAidlComposerClient->setActiveConfig(translate<int64_t>(display),
639 translate<int32_t>(config));
640 if (!status.isOk()) {
641 ALOGE("setActiveConfig failed %s", status.getDescription().c_str());
642 return static_cast<Error>(status.getServiceSpecificError());
643 }
644 return Error::NONE;
645}
646
647Error AidlComposer::setClientTarget(Display display, uint32_t slot, const sp<GraphicBuffer>& target,
648 int acquireFence, Dataspace dataspace,
649 const std::vector<IComposerClient::Rect>& damage) {
Ady Abrahame7385f72021-09-05 00:54:25 -0700650 const native_handle_t* handle = nullptr;
651 if (target.get()) {
652 handle = target->getNativeBuffer()->handle;
653 }
654
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400655 Error error = Error::NONE;
656 mMutex.lock_shared();
657 if (auto writer = getWriter(display)) {
658 writer->get()
659 .setClientTarget(translate<int64_t>(display), slot, handle, acquireFence,
660 translate<aidl::android::hardware::graphics::common::Dataspace>(
661 dataspace),
662 translate<AidlRect>(damage));
663 } else {
664 error = Error::BAD_DISPLAY;
665 }
666 mMutex.unlock_shared();
667 return error;
Ady Abrahame7385f72021-09-05 00:54:25 -0700668}
669
670Error AidlComposer::setColorMode(Display display, ColorMode mode, RenderIntent renderIntent) {
671 const auto status =
672 mAidlComposerClient->setColorMode(translate<int64_t>(display),
673 translate<AidlColorMode>(mode),
674 translate<AidlRenderIntent>(renderIntent));
675 if (!status.isOk()) {
676 ALOGE("setColorMode failed %s", status.getDescription().c_str());
677 return static_cast<Error>(status.getServiceSpecificError());
678 }
679 return Error::NONE;
680}
681
Ady Abrahamdc011a92021-12-21 14:06:44 -0800682Error AidlComposer::setColorTransform(Display display, const float* matrix) {
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400683 auto error = Error::NONE;
684 mMutex.lock_shared();
685 if (auto writer = getWriter(display)) {
686 writer->get().setColorTransform(translate<int64_t>(display), matrix);
687 } else {
688 error = Error::BAD_DISPLAY;
689 }
690 mMutex.unlock_shared();
691 return error;
Ady Abrahame7385f72021-09-05 00:54:25 -0700692}
693
694Error AidlComposer::setOutputBuffer(Display display, const native_handle_t* buffer,
695 int releaseFence) {
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400696 auto error = Error::NONE;
697 mMutex.lock_shared();
698 if (auto writer = getWriter(display)) {
699 writer->get().setOutputBuffer(translate<int64_t>(display), 0, buffer, dup(releaseFence));
700 } else {
701 error = Error::BAD_DISPLAY;
702 }
703 mMutex.unlock_shared();
704 return error;
Ady Abrahame7385f72021-09-05 00:54:25 -0700705}
706
707Error AidlComposer::setPowerMode(Display display, IComposerClient::PowerMode mode) {
708 const auto status = mAidlComposerClient->setPowerMode(translate<int64_t>(display),
709 translate<PowerMode>(mode));
710 if (!status.isOk()) {
711 ALOGE("setPowerMode failed %s", status.getDescription().c_str());
712 return static_cast<Error>(status.getServiceSpecificError());
713 }
714 return Error::NONE;
715}
716
717Error AidlComposer::setVsyncEnabled(Display display, IComposerClient::Vsync enabled) {
718 const bool enableVsync = enabled == IComposerClient::Vsync::ENABLE;
719 const auto status =
720 mAidlComposerClient->setVsyncEnabled(translate<int64_t>(display), enableVsync);
721 if (!status.isOk()) {
722 ALOGE("setVsyncEnabled failed %s", status.getDescription().c_str());
723 return static_cast<Error>(status.getServiceSpecificError());
724 }
725 return Error::NONE;
726}
727
728Error AidlComposer::setClientTargetSlotCount(Display display) {
729 const int32_t bufferSlotCount = BufferQueue::NUM_BUFFER_SLOTS;
730 const auto status = mAidlComposerClient->setClientTargetSlotCount(translate<int64_t>(display),
731 bufferSlotCount);
732 if (!status.isOk()) {
733 ALOGE("setClientTargetSlotCount failed %s", status.getDescription().c_str());
734 return static_cast<Error>(status.getServiceSpecificError());
735 }
736 return Error::NONE;
737}
738
Ady Abraham43065bd2021-12-10 17:22:15 -0800739Error AidlComposer::validateDisplay(Display display, nsecs_t expectedPresentTime,
740 uint32_t* outNumTypes, uint32_t* outNumRequests) {
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400741 const auto displayId = translate<int64_t>(display);
Leon Scroggins IIIe85e16e2022-12-12 12:51:18 -0500742 ATRACE_FORMAT("HwcValidateDisplay %" PRId64, displayId);
743
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400744 Error error = Error::NONE;
745 mMutex.lock_shared();
746 auto writer = getWriter(display);
747 auto reader = getReader(display);
748 if (writer && reader) {
749 writer->get().validateDisplay(displayId, ClockMonotonicTimestamp{expectedPresentTime});
750 error = execute(display);
751 } else {
752 error = Error::BAD_DISPLAY;
753 }
Ady Abrahame7385f72021-09-05 00:54:25 -0700754
Ady Abrahame7385f72021-09-05 00:54:25 -0700755 if (error != Error::NONE) {
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400756 mMutex.unlock_shared();
Ady Abrahame7385f72021-09-05 00:54:25 -0700757 return error;
758 }
759
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400760 reader->get().hasChanges(displayId, outNumTypes, outNumRequests);
Ady Abrahame7385f72021-09-05 00:54:25 -0700761
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400762 mMutex.unlock_shared();
Ady Abrahame7385f72021-09-05 00:54:25 -0700763 return Error::NONE;
764}
765
Ady Abraham43065bd2021-12-10 17:22:15 -0800766Error AidlComposer::presentOrValidateDisplay(Display display, nsecs_t expectedPresentTime,
767 uint32_t* outNumTypes, uint32_t* outNumRequests,
768 int* outPresentFence, uint32_t* state) {
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400769 const auto displayId = translate<int64_t>(display);
Leon Scroggins IIIe85e16e2022-12-12 12:51:18 -0500770 ATRACE_FORMAT("HwcPresentOrValidateDisplay %" PRId64, displayId);
771
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400772 Error error = Error::NONE;
773 mMutex.lock_shared();
774 auto writer = getWriter(display);
775 auto reader = getReader(display);
776 if (writer && reader) {
777 writer->get().presentOrvalidateDisplay(displayId,
778 ClockMonotonicTimestamp{expectedPresentTime});
779 error = execute(display);
780 } else {
781 error = Error::BAD_DISPLAY;
782 }
Ady Abrahame7385f72021-09-05 00:54:25 -0700783
Ady Abrahame7385f72021-09-05 00:54:25 -0700784 if (error != Error::NONE) {
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400785 mMutex.unlock_shared();
Ady Abrahame7385f72021-09-05 00:54:25 -0700786 return error;
787 }
788
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400789 const auto result = reader->get().takePresentOrValidateStage(displayId);
Ady Abrahamde792782021-12-20 10:00:49 -0800790 if (!result.has_value()) {
791 *state = translate<uint32_t>(-1);
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400792 mMutex.unlock_shared();
Ady Abrahamde792782021-12-20 10:00:49 -0800793 return Error::NO_RESOURCES;
Ady Abrahame7385f72021-09-05 00:54:25 -0700794 }
795
Ady Abrahamde792782021-12-20 10:00:49 -0800796 *state = translate<uint32_t>(*result);
797
798 if (*result == PresentOrValidate::Result::Presented) {
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400799 auto fence = reader->get().takePresentFence(displayId);
Ady Abrahamde792782021-12-20 10:00:49 -0800800 // take ownership
801 *outPresentFence = fence.get();
802 *fence.getR() = -1;
803 }
804
805 if (*result == PresentOrValidate::Result::Validated) {
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400806 reader->get().hasChanges(displayId, outNumTypes, outNumRequests);
Ady Abrahame7385f72021-09-05 00:54:25 -0700807 }
808
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400809 mMutex.unlock_shared();
Ady Abrahame7385f72021-09-05 00:54:25 -0700810 return Error::NONE;
811}
812
813Error AidlComposer::setCursorPosition(Display display, Layer layer, int32_t x, int32_t y) {
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400814 Error error = Error::NONE;
815 mMutex.lock_shared();
816 if (auto writer = getWriter(display)) {
817 writer->get().setLayerCursorPosition(translate<int64_t>(display), translate<int64_t>(layer),
818 x, y);
819 } else {
820 error = Error::BAD_DISPLAY;
821 }
822 mMutex.unlock_shared();
823 return error;
Ady Abrahame7385f72021-09-05 00:54:25 -0700824}
825
826Error AidlComposer::setLayerBuffer(Display display, Layer layer, uint32_t slot,
827 const sp<GraphicBuffer>& buffer, int acquireFence) {
Ady Abrahame7385f72021-09-05 00:54:25 -0700828 const native_handle_t* handle = nullptr;
829 if (buffer.get()) {
830 handle = buffer->getNativeBuffer()->handle;
831 }
832
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400833 Error error = Error::NONE;
834 mMutex.lock_shared();
835 if (auto writer = getWriter(display)) {
836 writer->get().setLayerBuffer(translate<int64_t>(display), translate<int64_t>(layer), slot,
837 handle, acquireFence);
838 } else {
839 error = Error::BAD_DISPLAY;
840 }
841 mMutex.unlock_shared();
842 return error;
Ady Abrahame7385f72021-09-05 00:54:25 -0700843}
844
Brian Lindahlb158a5c2022-12-15 15:21:13 -0700845Error AidlComposer::setLayerBufferSlotsToClear(Display display, Layer layer,
846 const std::vector<uint32_t>& slotsToClear,
847 uint32_t activeBufferSlot) {
848 if (slotsToClear.empty()) {
849 return Error::NONE;
850 }
851
Brian Lindahl90553da2022-12-06 13:36:30 -0700852 Error error = Error::NONE;
853 mMutex.lock_shared();
854 if (auto writer = getWriter(display)) {
Brian Lindahldbf7e3a2022-12-16 11:43:39 -0700855 // Backwards compatible way of clearing buffer is to set the layer buffer with a placeholder
856 // buffer, using the slot that needs to cleared... tricky.
857 if (mClearSlotBuffer == nullptr) {
858 writer->get().setLayerBufferSlotsToClear(translate<int64_t>(display),
859 translate<int64_t>(layer), slotsToClear);
860 } else {
861 for (uint32_t slot : slotsToClear) {
862 // Don't clear the active buffer slot because we need to restore the active buffer
863 // after clearing the requested buffer slots with a placeholder buffer.
864 if (slot != activeBufferSlot) {
865 writer->get().setLayerBufferWithNewCommand(translate<int64_t>(display),
866 translate<int64_t>(layer), slot,
867 mClearSlotBuffer->handle,
868 /*fence*/ -1);
869 }
Brian Lindahlb158a5c2022-12-15 15:21:13 -0700870 }
Brian Lindahldbf7e3a2022-12-16 11:43:39 -0700871 // Since we clear buffers by setting them to a placeholder buffer, we want to make
872 // sure that the last setLayerBuffer command is sent with the currently active
873 // buffer, not the placeholder buffer, so that there is no perceptual change when
874 // buffers are discarded.
875 writer->get().setLayerBufferWithNewCommand(translate<int64_t>(display),
876 translate<int64_t>(layer), activeBufferSlot,
877 // The active buffer is still cached in
878 // its slot and doesn't need a fence.
879 /*buffer*/ nullptr, /*fence*/ -1);
Brian Lindahlb158a5c2022-12-15 15:21:13 -0700880 }
Brian Lindahl90553da2022-12-06 13:36:30 -0700881 } else {
882 error = Error::BAD_DISPLAY;
883 }
884 mMutex.unlock_shared();
885 return error;
886}
887
Ady Abrahame7385f72021-09-05 00:54:25 -0700888Error AidlComposer::setLayerSurfaceDamage(Display display, Layer layer,
889 const std::vector<IComposerClient::Rect>& damage) {
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400890 Error error = Error::NONE;
891 mMutex.lock_shared();
892 if (auto writer = getWriter(display)) {
893 writer->get().setLayerSurfaceDamage(translate<int64_t>(display), translate<int64_t>(layer),
894 translate<AidlRect>(damage));
895 } else {
896 error = Error::BAD_DISPLAY;
897 }
898 mMutex.unlock_shared();
899 return error;
Ady Abrahame7385f72021-09-05 00:54:25 -0700900}
901
902Error AidlComposer::setLayerBlendMode(Display display, Layer layer,
903 IComposerClient::BlendMode mode) {
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400904 Error error = Error::NONE;
905 mMutex.lock_shared();
906 if (auto writer = getWriter(display)) {
907 writer->get().setLayerBlendMode(translate<int64_t>(display), translate<int64_t>(layer),
908 translate<BlendMode>(mode));
909 } else {
910 error = Error::BAD_DISPLAY;
911 }
912 mMutex.unlock_shared();
913 return error;
Ady Abrahame7385f72021-09-05 00:54:25 -0700914}
915
Ady Abraham6e60b142022-01-06 18:10:35 -0800916Error AidlComposer::setLayerColor(Display display, Layer layer, const Color& color) {
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400917 Error error = Error::NONE;
918 mMutex.lock_shared();
919 if (auto writer = getWriter(display)) {
920 writer->get().setLayerColor(translate<int64_t>(display), translate<int64_t>(layer), color);
921 } else {
922 error = Error::BAD_DISPLAY;
923 }
924 mMutex.unlock_shared();
925 return error;
Ady Abrahame7385f72021-09-05 00:54:25 -0700926}
927
Leon Scroggins III2e1aa182021-12-01 17:33:12 -0500928Error AidlComposer::setLayerCompositionType(
929 Display display, Layer layer,
930 aidl::android::hardware::graphics::composer3::Composition type) {
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400931 Error error = Error::NONE;
932 mMutex.lock_shared();
933 if (auto writer = getWriter(display)) {
934 writer->get().setLayerCompositionType(translate<int64_t>(display),
935 translate<int64_t>(layer), type);
936 } else {
937 error = Error::BAD_DISPLAY;
938 }
939 mMutex.unlock_shared();
940 return error;
Ady Abrahame7385f72021-09-05 00:54:25 -0700941}
942
943Error AidlComposer::setLayerDataspace(Display display, Layer layer, Dataspace dataspace) {
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400944 Error error = Error::NONE;
945 mMutex.lock_shared();
946 if (auto writer = getWriter(display)) {
947 writer->get().setLayerDataspace(translate<int64_t>(display), translate<int64_t>(layer),
948 translate<AidlDataspace>(dataspace));
949 } else {
950 error = Error::BAD_DISPLAY;
951 }
952 mMutex.unlock_shared();
953 return error;
Ady Abrahame7385f72021-09-05 00:54:25 -0700954}
955
956Error AidlComposer::setLayerDisplayFrame(Display display, Layer layer,
957 const IComposerClient::Rect& frame) {
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400958 Error error = Error::NONE;
959 mMutex.lock_shared();
960 if (auto writer = getWriter(display)) {
961 writer->get().setLayerDisplayFrame(translate<int64_t>(display), translate<int64_t>(layer),
962 translate<AidlRect>(frame));
963 } else {
964 error = Error::BAD_DISPLAY;
965 }
966 mMutex.unlock_shared();
967 return error;
Ady Abrahame7385f72021-09-05 00:54:25 -0700968}
969
970Error AidlComposer::setLayerPlaneAlpha(Display display, Layer layer, float alpha) {
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400971 Error error = Error::NONE;
972 mMutex.lock_shared();
973 if (auto writer = getWriter(display)) {
974 writer->get().setLayerPlaneAlpha(translate<int64_t>(display), translate<int64_t>(layer),
975 alpha);
976 } else {
977 error = Error::BAD_DISPLAY;
978 }
979 mMutex.unlock_shared();
980 return error;
Ady Abrahame7385f72021-09-05 00:54:25 -0700981}
982
983Error AidlComposer::setLayerSidebandStream(Display display, Layer layer,
984 const native_handle_t* stream) {
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400985 Error error = Error::NONE;
986 mMutex.lock_shared();
987 if (auto writer = getWriter(display)) {
988 writer->get().setLayerSidebandStream(translate<int64_t>(display), translate<int64_t>(layer),
989 stream);
990 } else {
991 error = Error::BAD_DISPLAY;
992 }
993 mMutex.unlock_shared();
994 return error;
Ady Abrahame7385f72021-09-05 00:54:25 -0700995}
996
997Error AidlComposer::setLayerSourceCrop(Display display, Layer layer,
998 const IComposerClient::FRect& crop) {
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400999 Error error = Error::NONE;
1000 mMutex.lock_shared();
1001 if (auto writer = getWriter(display)) {
1002 writer->get().setLayerSourceCrop(translate<int64_t>(display), translate<int64_t>(layer),
1003 translate<AidlFRect>(crop));
1004 } else {
1005 error = Error::BAD_DISPLAY;
1006 }
1007 mMutex.unlock_shared();
1008 return error;
Ady Abrahame7385f72021-09-05 00:54:25 -07001009}
1010
1011Error AidlComposer::setLayerTransform(Display display, Layer layer, Transform transform) {
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -04001012 Error error = Error::NONE;
1013 mMutex.lock_shared();
1014 if (auto writer = getWriter(display)) {
1015 writer->get().setLayerTransform(translate<int64_t>(display), translate<int64_t>(layer),
1016 translate<AidlTransform>(transform));
1017 } else {
1018 error = Error::BAD_DISPLAY;
1019 }
1020 mMutex.unlock_shared();
1021 return error;
Ady Abrahame7385f72021-09-05 00:54:25 -07001022}
1023
1024Error AidlComposer::setLayerVisibleRegion(Display display, Layer layer,
1025 const std::vector<IComposerClient::Rect>& visible) {
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -04001026 Error error = Error::NONE;
1027 mMutex.lock_shared();
1028 if (auto writer = getWriter(display)) {
1029 writer->get().setLayerVisibleRegion(translate<int64_t>(display), translate<int64_t>(layer),
1030 translate<AidlRect>(visible));
1031 } else {
1032 error = Error::BAD_DISPLAY;
1033 }
1034 mMutex.unlock_shared();
1035 return error;
Ady Abrahame7385f72021-09-05 00:54:25 -07001036}
1037
1038Error AidlComposer::setLayerZOrder(Display display, Layer layer, uint32_t z) {
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -04001039 Error error = Error::NONE;
1040 mMutex.lock_shared();
1041 if (auto writer = getWriter(display)) {
1042 writer->get().setLayerZOrder(translate<int64_t>(display), translate<int64_t>(layer), z);
1043 } else {
1044 error = Error::BAD_DISPLAY;
1045 }
1046 mMutex.unlock_shared();
1047 return error;
Ady Abrahame7385f72021-09-05 00:54:25 -07001048}
1049
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -04001050Error AidlComposer::execute(Display display) {
1051 auto writer = getWriter(display);
1052 auto reader = getReader(display);
1053 if (!writer || !reader) {
1054 return Error::BAD_DISPLAY;
1055 }
1056
1057 const auto& commands = writer->get().getPendingCommands();
Ady Abrahama6388c02021-11-11 21:11:51 -08001058 if (commands.empty()) {
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -04001059 writer->get().reset();
Ady Abrahame7385f72021-09-05 00:54:25 -07001060 return Error::NONE;
1061 }
1062
Ady Abrahamde792782021-12-20 10:00:49 -08001063 { // scope for results
1064 std::vector<CommandResultPayload> results;
1065 auto status = mAidlComposerClient->executeCommands(commands, &results);
1066 if (!status.isOk()) {
1067 ALOGE("executeCommands failed %s", status.getDescription().c_str());
1068 return static_cast<Error>(status.getServiceSpecificError());
1069 }
Ady Abrahame7385f72021-09-05 00:54:25 -07001070
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -04001071 reader->get().parse(std::move(results));
Ady Abrahamde792782021-12-20 10:00:49 -08001072 }
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -04001073 const auto commandErrors = reader->get().takeErrors();
Ady Abrahama6388c02021-11-11 21:11:51 -08001074 Error error = Error::NONE;
1075 for (const auto& cmdErr : commandErrors) {
1076 const auto index = static_cast<size_t>(cmdErr.commandIndex);
1077 if (index < 0 || index >= commands.size()) {
1078 ALOGE("invalid command index %zu", index);
1079 return Error::BAD_PARAMETER;
Ady Abrahame7385f72021-09-05 00:54:25 -07001080 }
1081
Ady Abrahama6388c02021-11-11 21:11:51 -08001082 const auto& command = commands[index];
Ady Abraham42977362021-12-07 21:04:49 -08001083 if (command.validateDisplay || command.presentDisplay || command.presentOrValidateDisplay) {
1084 error = translate<Error>(cmdErr.errorCode);
1085 } else {
1086 ALOGW("command '%s' generated error %" PRId32, command.toString().c_str(),
1087 cmdErr.errorCode);
Ady Abrahame7385f72021-09-05 00:54:25 -07001088 }
1089 }
1090
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -04001091 writer->get().reset();
Ady Abrahame7385f72021-09-05 00:54:25 -07001092
1093 return error;
1094}
1095
1096Error AidlComposer::setLayerPerFrameMetadata(
1097 Display display, Layer layer,
1098 const std::vector<IComposerClient::PerFrameMetadata>& perFrameMetadatas) {
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -04001099 Error error = Error::NONE;
1100 mMutex.lock_shared();
1101 if (auto writer = getWriter(display)) {
1102 writer->get().setLayerPerFrameMetadata(translate<int64_t>(display),
1103 translate<int64_t>(layer),
1104 translate<AidlPerFrameMetadata>(perFrameMetadatas));
1105 } else {
1106 error = Error::BAD_DISPLAY;
1107 }
1108 mMutex.unlock_shared();
1109 return error;
Ady Abrahame7385f72021-09-05 00:54:25 -07001110}
1111
1112std::vector<IComposerClient::PerFrameMetadataKey> AidlComposer::getPerFrameMetadataKeys(
1113 Display display) {
1114 std::vector<AidlPerFrameMetadataKey> keys;
1115 const auto status =
1116 mAidlComposerClient->getPerFrameMetadataKeys(translate<int64_t>(display), &keys);
1117 if (!status.isOk()) {
1118 ALOGE("getPerFrameMetadataKeys failed %s", status.getDescription().c_str());
1119 return {};
1120 }
1121 return translate<IComposerClient::PerFrameMetadataKey>(keys);
1122}
1123
1124Error AidlComposer::getRenderIntents(Display display, ColorMode colorMode,
1125 std::vector<RenderIntent>* outRenderIntents) {
1126 std::vector<AidlRenderIntent> renderIntents;
1127 const auto status = mAidlComposerClient->getRenderIntents(translate<int64_t>(display),
1128 translate<AidlColorMode>(colorMode),
1129 &renderIntents);
1130 if (!status.isOk()) {
1131 ALOGE("getRenderIntents failed %s", status.getDescription().c_str());
1132 return static_cast<Error>(status.getServiceSpecificError());
1133 }
1134 *outRenderIntents = translate<RenderIntent>(renderIntents);
1135 return Error::NONE;
1136}
1137
1138Error AidlComposer::getDataspaceSaturationMatrix(Dataspace dataspace, mat4* outMatrix) {
1139 std::vector<float> matrix;
1140 const auto status =
1141 mAidlComposerClient->getDataspaceSaturationMatrix(translate<AidlDataspace>(dataspace),
1142 &matrix);
1143 if (!status.isOk()) {
1144 ALOGE("getDataspaceSaturationMatrix failed %s", status.getDescription().c_str());
1145 return static_cast<Error>(status.getServiceSpecificError());
1146 }
1147 *outMatrix = makeMat4(matrix);
1148 return Error::NONE;
1149}
1150
1151Error AidlComposer::getDisplayIdentificationData(Display display, uint8_t* outPort,
1152 std::vector<uint8_t>* outData) {
1153 AidlDisplayIdentification displayIdentification;
1154 const auto status =
1155 mAidlComposerClient->getDisplayIdentificationData(translate<int64_t>(display),
1156 &displayIdentification);
1157 if (!status.isOk()) {
1158 ALOGE("getDisplayIdentificationData failed %s", status.getDescription().c_str());
1159 return static_cast<Error>(status.getServiceSpecificError());
1160 }
1161
1162 *outPort = static_cast<uint8_t>(displayIdentification.port);
1163 *outData = displayIdentification.data;
1164
1165 return Error::NONE;
1166}
1167
1168Error AidlComposer::setLayerColorTransform(Display display, Layer layer, const float* matrix) {
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -04001169 Error error = Error::NONE;
1170 mMutex.lock_shared();
1171 if (auto writer = getWriter(display)) {
1172 writer->get().setLayerColorTransform(translate<int64_t>(display), translate<int64_t>(layer),
1173 matrix);
1174 } else {
1175 error = Error::BAD_DISPLAY;
1176 }
1177 mMutex.unlock_shared();
1178 return error;
Ady Abrahame7385f72021-09-05 00:54:25 -07001179}
1180
1181Error AidlComposer::getDisplayedContentSamplingAttributes(Display display, PixelFormat* outFormat,
1182 Dataspace* outDataspace,
1183 uint8_t* outComponentMask) {
1184 if (!outFormat || !outDataspace || !outComponentMask) {
1185 return Error::BAD_PARAMETER;
1186 }
1187
1188 AidlDisplayContentSamplingAttributes attributes;
1189 const auto status =
1190 mAidlComposerClient->getDisplayedContentSamplingAttributes(translate<int64_t>(display),
1191 &attributes);
1192 if (!status.isOk()) {
1193 ALOGE("getDisplayedContentSamplingAttributes failed %s", status.getDescription().c_str());
1194 return static_cast<Error>(status.getServiceSpecificError());
1195 }
1196
1197 *outFormat = translate<PixelFormat>(attributes.format);
1198 *outDataspace = translate<Dataspace>(attributes.dataspace);
1199 *outComponentMask = static_cast<uint8_t>(attributes.componentMask);
1200 return Error::NONE;
1201}
1202
1203Error AidlComposer::setDisplayContentSamplingEnabled(Display display, bool enabled,
1204 uint8_t componentMask, uint64_t maxFrames) {
1205 const auto status =
1206 mAidlComposerClient
1207 ->setDisplayedContentSamplingEnabled(translate<int64_t>(display), enabled,
1208 static_cast<AidlFormatColorComponent>(
1209 componentMask),
1210 static_cast<int64_t>(maxFrames));
1211 if (!status.isOk()) {
1212 ALOGE("setDisplayedContentSamplingEnabled failed %s", status.getDescription().c_str());
1213 return static_cast<Error>(status.getServiceSpecificError());
1214 }
1215 return Error::NONE;
1216}
1217
1218Error AidlComposer::getDisplayedContentSample(Display display, uint64_t maxFrames,
1219 uint64_t timestamp, DisplayedFrameStats* outStats) {
1220 if (!outStats) {
1221 return Error::BAD_PARAMETER;
1222 }
1223
1224 AidlDisplayContentSample sample;
1225 const auto status =
1226 mAidlComposerClient->getDisplayedContentSample(translate<int64_t>(display),
1227 static_cast<int64_t>(maxFrames),
1228 static_cast<int64_t>(timestamp),
1229 &sample);
1230 if (!status.isOk()) {
1231 ALOGE("getDisplayedContentSample failed %s", status.getDescription().c_str());
1232 return static_cast<Error>(status.getServiceSpecificError());
1233 }
1234 *outStats = translate<DisplayedFrameStats>(sample);
1235 return Error::NONE;
1236}
1237
1238Error AidlComposer::setLayerPerFrameMetadataBlobs(
1239 Display display, Layer layer,
1240 const std::vector<IComposerClient::PerFrameMetadataBlob>& metadata) {
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -04001241 Error error = Error::NONE;
1242 mMutex.lock_shared();
1243 if (auto writer = getWriter(display)) {
1244 writer->get().setLayerPerFrameMetadataBlobs(translate<int64_t>(display),
1245 translate<int64_t>(layer),
1246 translate<AidlPerFrameMetadataBlob>(metadata));
1247 } else {
1248 error = Error::BAD_DISPLAY;
1249 }
1250 mMutex.unlock_shared();
1251 return error;
Ady Abrahame7385f72021-09-05 00:54:25 -07001252}
1253
Alec Mouri4d8a05d2022-03-23 18:14:26 +00001254Error AidlComposer::setDisplayBrightness(Display display, float brightness, float brightnessNits,
Alec Mouricdf16792021-12-10 13:16:06 -08001255 const DisplayBrightnessOptions& options) {
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -04001256 Error error = Error::NONE;
1257 mMutex.lock_shared();
1258 if (auto writer = getWriter(display)) {
1259 writer->get().setDisplayBrightness(translate<int64_t>(display), brightness, brightnessNits);
Alec Mouricdf16792021-12-10 13:16:06 -08001260
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -04001261 if (options.applyImmediately) {
1262 error = execute(display);
1263 mMutex.unlock_shared();
1264 return error;
1265 }
1266 } else {
1267 error = Error::BAD_DISPLAY;
Alec Mouricdf16792021-12-10 13:16:06 -08001268 }
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -04001269 mMutex.unlock_shared();
1270 return error;
Ady Abrahame7385f72021-09-05 00:54:25 -07001271}
1272
1273Error AidlComposer::getDisplayCapabilities(Display display,
Leon Scroggins III5967aec2021-12-29 11:14:22 -05001274 std::vector<AidlDisplayCapability>* outCapabilities) {
1275 const auto status = mAidlComposerClient->getDisplayCapabilities(translate<int64_t>(display),
1276 outCapabilities);
Ady Abrahame7385f72021-09-05 00:54:25 -07001277 if (!status.isOk()) {
1278 ALOGE("getDisplayCapabilities failed %s", status.getDescription().c_str());
Leon Scroggins III5967aec2021-12-29 11:14:22 -05001279 outCapabilities->clear();
Ady Abrahame7385f72021-09-05 00:54:25 -07001280 return static_cast<Error>(status.getServiceSpecificError());
1281 }
Ady Abrahame7385f72021-09-05 00:54:25 -07001282 return Error::NONE;
1283}
1284
1285V2_4::Error AidlComposer::getDisplayConnectionType(
1286 Display display, IComposerClient::DisplayConnectionType* outType) {
1287 AidlDisplayConnectionType type;
1288 const auto status =
1289 mAidlComposerClient->getDisplayConnectionType(translate<int64_t>(display), &type);
1290 if (!status.isOk()) {
1291 ALOGE("getDisplayConnectionType failed %s", status.getDescription().c_str());
1292 return static_cast<V2_4::Error>(status.getServiceSpecificError());
1293 }
1294 *outType = translate<IComposerClient::DisplayConnectionType>(type);
1295 return V2_4::Error::NONE;
1296}
1297
1298V2_4::Error AidlComposer::getDisplayVsyncPeriod(Display display, VsyncPeriodNanos* outVsyncPeriod) {
1299 int32_t vsyncPeriod;
1300 const auto status =
1301 mAidlComposerClient->getDisplayVsyncPeriod(translate<int64_t>(display), &vsyncPeriod);
1302 if (!status.isOk()) {
1303 ALOGE("getDisplayVsyncPeriod failed %s", status.getDescription().c_str());
1304 return static_cast<V2_4::Error>(status.getServiceSpecificError());
1305 }
1306 *outVsyncPeriod = translate<VsyncPeriodNanos>(vsyncPeriod);
1307 return V2_4::Error::NONE;
1308}
1309
1310V2_4::Error AidlComposer::setActiveConfigWithConstraints(
1311 Display display, Config config,
1312 const IComposerClient::VsyncPeriodChangeConstraints& vsyncPeriodChangeConstraints,
1313 VsyncPeriodChangeTimeline* outTimeline) {
1314 AidlVsyncPeriodChangeTimeline timeline;
1315 const auto status =
1316 mAidlComposerClient
1317 ->setActiveConfigWithConstraints(translate<int64_t>(display),
1318 translate<int32_t>(config),
1319 translate<AidlVsyncPeriodChangeConstraints>(
1320 vsyncPeriodChangeConstraints),
1321 &timeline);
1322 if (!status.isOk()) {
1323 ALOGE("setActiveConfigWithConstraints failed %s", status.getDescription().c_str());
1324 return static_cast<V2_4::Error>(status.getServiceSpecificError());
1325 }
1326 *outTimeline = translate<VsyncPeriodChangeTimeline>(timeline);
1327 return V2_4::Error::NONE;
1328}
1329
1330V2_4::Error AidlComposer::setAutoLowLatencyMode(Display display, bool on) {
1331 const auto status = mAidlComposerClient->setAutoLowLatencyMode(translate<int64_t>(display), on);
1332 if (!status.isOk()) {
1333 ALOGE("setAutoLowLatencyMode failed %s", status.getDescription().c_str());
1334 return static_cast<V2_4::Error>(status.getServiceSpecificError());
1335 }
1336 return V2_4::Error::NONE;
1337}
1338
1339V2_4::Error AidlComposer::getSupportedContentTypes(
1340 Display displayId, std::vector<IComposerClient::ContentType>* outSupportedContentTypes) {
1341 std::vector<AidlContentType> types;
1342 const auto status =
1343 mAidlComposerClient->getSupportedContentTypes(translate<int64_t>(displayId), &types);
1344 if (!status.isOk()) {
1345 ALOGE("getSupportedContentTypes failed %s", status.getDescription().c_str());
1346 return static_cast<V2_4::Error>(status.getServiceSpecificError());
1347 }
1348 *outSupportedContentTypes = translate<IComposerClient::ContentType>(types);
1349 return V2_4::Error::NONE;
1350}
1351
1352V2_4::Error AidlComposer::setContentType(Display display,
1353 IComposerClient::ContentType contentType) {
1354 const auto status =
1355 mAidlComposerClient->setContentType(translate<int64_t>(display),
1356 translate<AidlContentType>(contentType));
1357 if (!status.isOk()) {
1358 ALOGE("setContentType failed %s", status.getDescription().c_str());
1359 return static_cast<V2_4::Error>(status.getServiceSpecificError());
1360 }
1361 return V2_4::Error::NONE;
1362}
1363
Ady Abraham3f976752021-12-20 16:17:50 -08001364V2_4::Error AidlComposer::setLayerGenericMetadata(Display, Layer, const std::string&, bool,
1365 const std::vector<uint8_t>&) {
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
1370V2_4::Error AidlComposer::getLayerGenericMetadataKeys(
Ady Abraham3f976752021-12-20 16:17:50 -08001371 std::vector<IComposerClient::LayerGenericMetadataKey>*) {
1372 // There are no users for this API. See b/209691612.
1373 return V2_4::Error::UNSUPPORTED;
Ady Abrahame7385f72021-09-05 00:54:25 -07001374}
1375
Kriti Dang7defaf32021-11-15 11:55:43 +01001376Error AidlComposer::setBootDisplayConfig(Display display, Config config) {
1377 const auto status = mAidlComposerClient->setBootDisplayConfig(translate<int64_t>(display),
1378 translate<int32_t>(config));
1379 if (!status.isOk()) {
1380 ALOGE("setBootDisplayConfig failed %s", status.getDescription().c_str());
1381 return static_cast<Error>(status.getServiceSpecificError());
1382 }
1383 return Error::NONE;
1384}
1385
1386Error AidlComposer::clearBootDisplayConfig(Display display) {
1387 const auto status = mAidlComposerClient->clearBootDisplayConfig(translate<int64_t>(display));
1388 if (!status.isOk()) {
1389 ALOGE("clearBootDisplayConfig failed %s", status.getDescription().c_str());
1390 return static_cast<Error>(status.getServiceSpecificError());
1391 }
1392 return Error::NONE;
1393}
1394
1395Error AidlComposer::getPreferredBootDisplayConfig(Display display, Config* config) {
1396 int32_t displayConfig;
1397 const auto status =
1398 mAidlComposerClient->getPreferredBootDisplayConfig(translate<int64_t>(display),
1399 &displayConfig);
1400 if (!status.isOk()) {
1401 ALOGE("getPreferredBootDisplayConfig failed %s", status.getDescription().c_str());
1402 return static_cast<Error>(status.getServiceSpecificError());
1403 }
1404 *config = translate<uint32_t>(displayConfig);
1405 return Error::NONE;
1406}
1407
Kriti Dang674b9372022-11-18 10:58:44 +01001408Error AidlComposer::getHdrConversionCapabilities(
1409 std::vector<AidlHdrConversionCapability>* hdrConversionCapabilities) {
1410 const auto status =
1411 mAidlComposerClient->getHdrConversionCapabilities(hdrConversionCapabilities);
1412 if (!status.isOk()) {
1413 hdrConversionCapabilities = {};
1414 ALOGE("getHdrConversionCapabilities failed %s", status.getDescription().c_str());
1415 return static_cast<Error>(status.getServiceSpecificError());
1416 }
1417 return Error::NONE;
1418}
1419
Kriti Dangd432bb52023-02-09 18:21:04 +01001420Error AidlComposer::setHdrConversionStrategy(AidlHdrConversionStrategy hdrConversionStrategy,
1421 Hdr* outPreferredHdrOutputType) {
1422 const auto status = mAidlComposerClient->setHdrConversionStrategy(hdrConversionStrategy,
1423 outPreferredHdrOutputType);
Kriti Dang674b9372022-11-18 10:58:44 +01001424 if (!status.isOk()) {
1425 ALOGE("setHdrConversionStrategy failed %s", status.getDescription().c_str());
1426 return static_cast<Error>(status.getServiceSpecificError());
1427 }
1428 return Error::NONE;
1429}
1430
ramindanib2158ee2023-02-13 20:29:59 -08001431Error AidlComposer::setRefreshRateChangedCallbackDebugEnabled(Display displayId, bool enabled) {
1432 const auto status =
1433 mAidlComposerClient->setRefreshRateChangedCallbackDebugEnabled(translate<int64_t>(
1434 displayId),
1435 enabled);
1436 if (!status.isOk()) {
1437 ALOGE("setRefreshRateChangedCallbackDebugEnabled failed %s",
1438 status.getDescription().c_str());
1439 return static_cast<Error>(status.getServiceSpecificError());
1440 }
1441 return Error::NONE;
1442}
1443
Ady Abrahame7385f72021-09-05 00:54:25 -07001444Error AidlComposer::getClientTargetProperty(
Alec Mouri85065692022-03-18 00:58:26 +00001445 Display display, ClientTargetPropertyWithBrightness* outClientTargetProperty) {
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -04001446 Error error = Error::NONE;
1447 mMutex.lock_shared();
1448 if (auto reader = getReader(display)) {
1449 *outClientTargetProperty =
1450 reader->get().takeClientTargetProperty(translate<int64_t>(display));
1451 } else {
1452 error = Error::BAD_DISPLAY;
1453 }
1454 mMutex.unlock_shared();
1455 return error;
Ady Abrahame7385f72021-09-05 00:54:25 -07001456}
1457
Alec Mouri6da0e272022-02-07 12:45:57 -08001458Error AidlComposer::setLayerBrightness(Display display, Layer layer, float brightness) {
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -04001459 Error error = Error::NONE;
1460 mMutex.lock_shared();
1461 if (auto writer = getWriter(display)) {
1462 writer->get().setLayerBrightness(translate<int64_t>(display), translate<int64_t>(layer),
1463 brightness);
1464 } else {
1465 error = Error::BAD_DISPLAY;
1466 }
1467 mMutex.unlock_shared();
1468 return error;
Alec Mouricdf6cbc2021-11-01 17:21:15 -07001469}
1470
Leon Scroggins IIId77d3162022-01-05 10:42:28 -05001471Error AidlComposer::setLayerBlockingRegion(Display display, Layer layer,
1472 const std::vector<IComposerClient::Rect>& blocking) {
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -04001473 Error error = Error::NONE;
1474 mMutex.lock_shared();
1475 if (auto writer = getWriter(display)) {
1476 writer->get().setLayerBlockingRegion(translate<int64_t>(display), translate<int64_t>(layer),
1477 translate<AidlRect>(blocking));
1478 } else {
1479 error = Error::BAD_DISPLAY;
1480 }
1481 mMutex.unlock_shared();
1482 return error;
Leon Scroggins IIId77d3162022-01-05 10:42:28 -05001483}
Leon Scroggins IIIe7c51c62022-02-01 15:53:54 -05001484
1485Error AidlComposer::getDisplayDecorationSupport(Display display,
1486 std::optional<DisplayDecorationSupport>* support) {
1487 const auto status =
1488 mAidlComposerClient->getDisplayDecorationSupport(translate<int64_t>(display), support);
1489 if (!status.isOk()) {
1490 ALOGE("getDisplayDecorationSupport failed %s", status.getDescription().c_str());
1491 support->reset();
1492 return static_cast<Error>(status.getServiceSpecificError());
1493 }
1494 return Error::NONE;
1495}
ramindani32cf0602022-03-02 02:30:29 +00001496
1497Error AidlComposer::setIdleTimerEnabled(Display displayId, std::chrono::milliseconds timeout) {
1498 const auto status =
1499 mAidlComposerClient->setIdleTimerEnabled(translate<int64_t>(displayId),
1500 translate<int32_t>(timeout.count()));
1501 if (!status.isOk()) {
1502 ALOGE("setIdleTimerEnabled failed %s", status.getDescription().c_str());
1503 return static_cast<Error>(status.getServiceSpecificError());
1504 }
1505 return Error::NONE;
1506}
1507
ramindani06e518e2022-03-14 18:47:53 +00001508Error AidlComposer::getPhysicalDisplayOrientation(Display displayId,
1509 AidlTransform* outDisplayOrientation) {
1510 const auto status =
1511 mAidlComposerClient->getDisplayPhysicalOrientation(translate<int64_t>(displayId),
1512 outDisplayOrientation);
1513 if (!status.isOk()) {
1514 ALOGE("getPhysicalDisplayOrientation failed %s", status.getDescription().c_str());
1515 return static_cast<Error>(status.getServiceSpecificError());
1516 }
1517 return Error::NONE;
1518}
1519
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -04001520ftl::Optional<std::reference_wrapper<ComposerClientWriter>> AidlComposer::getWriter(Display display)
1521 REQUIRES_SHARED(mMutex) {
1522 return mWriters.get(display);
1523}
1524
1525ftl::Optional<std::reference_wrapper<ComposerClientReader>> AidlComposer::getReader(Display display)
1526 REQUIRES_SHARED(mMutex) {
1527 if (mSingleReader) {
1528 display = translate<Display>(kSingleReaderKey);
1529 }
1530 return mReaders.get(display);
1531}
1532
1533void AidlComposer::removeDisplay(Display display) {
1534 mMutex.lock();
1535 bool wasErased = mWriters.erase(display);
1536 ALOGW_IF(!wasErased,
1537 "Attempting to remove writer for display %" PRId64 " which is not connected",
1538 translate<int64_t>(display));
1539 if (!mSingleReader) {
1540 removeReader(display);
1541 }
1542 mMutex.unlock();
1543}
1544
1545void AidlComposer::onHotplugDisconnect(Display display) {
1546 removeDisplay(display);
1547}
1548
1549bool AidlComposer::hasMultiThreadedPresentSupport(Display display) {
Leon Scroggins IIIc1cf4582023-03-23 18:37:44 -04001550#if 0
1551 // TODO (b/259132483): Reenable
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -04001552 const auto displayId = translate<int64_t>(display);
1553 std::vector<AidlDisplayCapability> capabilities;
1554 const auto status = mAidlComposerClient->getDisplayCapabilities(displayId, &capabilities);
1555 if (!status.isOk()) {
1556 ALOGE("getDisplayCapabilities failed %s", status.getDescription().c_str());
1557 return false;
1558 }
1559 return std::find(capabilities.begin(), capabilities.end(),
1560 AidlDisplayCapability::MULTI_THREADED_PRESENT) != capabilities.end();
Leon Scroggins IIIc1cf4582023-03-23 18:37:44 -04001561#else
1562 (void) display;
1563 return false;
1564#endif
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -04001565}
1566
1567void AidlComposer::addReader(Display display) {
1568 const auto displayId = translate<int64_t>(display);
1569 std::optional<int64_t> displayOpt;
1570 if (displayId != kSingleReaderKey) {
1571 displayOpt.emplace(displayId);
1572 }
1573 auto [it, added] = mReaders.try_emplace(display, std::move(displayOpt));
1574 ALOGW_IF(!added, "Attempting to add writer for display %" PRId64 " which is already connected",
1575 displayId);
1576}
1577
1578void AidlComposer::removeReader(Display display) {
1579 bool wasErased = mReaders.erase(display);
1580 ALOGW_IF(!wasErased,
1581 "Attempting to remove reader for display %" PRId64 " which is not connected",
1582 translate<int64_t>(display));
1583}
1584
1585void AidlComposer::addDisplay(Display display) {
1586 const auto displayId = translate<int64_t>(display);
1587 mMutex.lock();
1588 auto [it, added] = mWriters.try_emplace(display, displayId);
1589 ALOGW_IF(!added, "Attempting to add writer for display %" PRId64 " which is already connected",
1590 displayId);
1591 if (mSingleReader) {
1592 if (hasMultiThreadedPresentSupport(display)) {
1593 mSingleReader = false;
1594 removeReader(translate<Display>(kSingleReaderKey));
1595 // Note that this includes the new display.
1596 for (const auto& [existingDisplay, _] : mWriters) {
1597 addReader(existingDisplay);
1598 }
1599 }
1600 } else {
1601 addReader(display);
1602 }
1603 mMutex.unlock();
1604}
1605
1606void AidlComposer::onHotplugConnect(Display display) {
1607 addDisplay(display);
1608}
Ady Abrahame7385f72021-09-05 00:54:25 -07001609} // namespace Hwc2
1610} // namespace android