blob: 3cda3343b019d1916a8c7f05ab3e79a332738483 [file] [log] [blame]
Ady Abrahame7385f72021-09-05 00:54:25 -07001/*
2 * Copyright 2021 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#undef LOG_TAG
18#define LOG_TAG "HwcComposer"
19#define ATRACE_TAG ATRACE_TAG_GRAPHICS
20
Ady Abraham9fc28052021-10-14 17:21:38 -070021#include "AidlComposerHal.h"
Ady Abrahame7385f72021-09-05 00:54:25 -070022
Brian Lindahlab84e112023-06-15 14:19:43 -060023#include <SurfaceFlingerProperties.h>
Ady Abrahamc4acf512022-02-18 17:11:59 -080024#include <android-base/file.h>
Ady Abrahame7385f72021-09-05 00:54:25 -070025#include <android/binder_ibinder_platform.h>
26#include <android/binder_manager.h>
Leon Scroggins IIIe85e16e2022-12-12 12:51:18 -050027#include <gui/TraceUtils.h>
Ady Abrahame7385f72021-09-05 00:54:25 -070028#include <log/log.h>
29#include <utils/Trace.h>
30
31#include <aidl/android/hardware/graphics/composer3/BnComposerCallback.h>
32
33#include <algorithm>
34#include <cinttypes>
35
Yichi Chen3401b562022-01-17 15:42:35 +080036#include "HWC2.h"
37
Ady Abrahame7385f72021-09-05 00:54:25 -070038namespace android {
39
40using hardware::hidl_handle;
41using hardware::hidl_vec;
42using hardware::Return;
43
44using aidl::android::hardware::graphics::composer3::BnComposerCallback;
45using aidl::android::hardware::graphics::composer3::Capability;
Alec Mouri85065692022-03-18 00:58:26 +000046using aidl::android::hardware::graphics::composer3::ClientTargetPropertyWithBrightness;
Ady Abrahame7385f72021-09-05 00:54:25 -070047using aidl::android::hardware::graphics::composer3::PowerMode;
48using aidl::android::hardware::graphics::composer3::VirtualDisplay;
49
Ady Abraham42977362021-12-07 21:04:49 -080050using aidl::android::hardware::graphics::composer3::CommandResultPayload;
Ady Abrahama6388c02021-11-11 21:11:51 -080051
Ady Abrahame7385f72021-09-05 00:54:25 -070052using AidlColorMode = aidl::android::hardware::graphics::composer3::ColorMode;
53using AidlContentType = aidl::android::hardware::graphics::composer3::ContentType;
54using AidlDisplayIdentification =
55 aidl::android::hardware::graphics::composer3::DisplayIdentification;
56using AidlDisplayContentSample = aidl::android::hardware::graphics::composer3::DisplayContentSample;
57using AidlDisplayAttribute = aidl::android::hardware::graphics::composer3::DisplayAttribute;
58using AidlDisplayCapability = aidl::android::hardware::graphics::composer3::DisplayCapability;
Ady Abrahame7385f72021-09-05 00:54:25 -070059using AidlHdrCapabilities = aidl::android::hardware::graphics::composer3::HdrCapabilities;
Kriti Dang674b9372022-11-18 10:58:44 +010060using AidlHdrConversionCapability =
61 aidl::android::hardware::graphics::common::HdrConversionCapability;
62using AidlHdrConversionStrategy = aidl::android::hardware::graphics::common::HdrConversionStrategy;
Sally Qi0cbd08b2022-08-17 12:12:28 -070063using AidlOverlayProperties = aidl::android::hardware::graphics::composer3::OverlayProperties;
Ady Abrahame7385f72021-09-05 00:54:25 -070064using AidlPerFrameMetadata = aidl::android::hardware::graphics::composer3::PerFrameMetadata;
65using AidlPerFrameMetadataKey = aidl::android::hardware::graphics::composer3::PerFrameMetadataKey;
66using AidlPerFrameMetadataBlob = aidl::android::hardware::graphics::composer3::PerFrameMetadataBlob;
67using AidlRenderIntent = aidl::android::hardware::graphics::composer3::RenderIntent;
68using AidlVsyncPeriodChangeConstraints =
69 aidl::android::hardware::graphics::composer3::VsyncPeriodChangeConstraints;
70using AidlVsyncPeriodChangeTimeline =
71 aidl::android::hardware::graphics::composer3::VsyncPeriodChangeTimeline;
Ady Abrahame7385f72021-09-05 00:54:25 -070072using AidlDisplayContentSamplingAttributes =
73 aidl::android::hardware::graphics::composer3::DisplayContentSamplingAttributes;
74using AidlFormatColorComponent = aidl::android::hardware::graphics::composer3::FormatColorComponent;
75using AidlDisplayConnectionType =
76 aidl::android::hardware::graphics::composer3::DisplayConnectionType;
Ady Abrahame7385f72021-09-05 00:54:25 -070077
78using AidlColorTransform = aidl::android::hardware::graphics::common::ColorTransform;
79using AidlDataspace = aidl::android::hardware::graphics::common::Dataspace;
80using AidlFRect = aidl::android::hardware::graphics::common::FRect;
81using AidlRect = aidl::android::hardware::graphics::common::Rect;
82using AidlTransform = aidl::android::hardware::graphics::common::Transform;
83
84namespace Hwc2 {
85
86namespace {
87
88template <typename To, typename From>
89To translate(From x) {
90 return static_cast<To>(x);
91}
92
93template <typename To, typename From>
94std::vector<To> translate(const std::vector<From>& in) {
95 std::vector<To> out;
96 out.reserve(in.size());
97 std::transform(in.begin(), in.end(), std::back_inserter(out),
98 [](From x) { return translate<To>(x); });
99 return out;
100}
101
102template <>
103AidlRect translate(IComposerClient::Rect x) {
104 return AidlRect{
105 .left = x.left,
106 .top = x.top,
107 .right = x.right,
108 .bottom = x.bottom,
109 };
110}
111
112template <>
113AidlFRect translate(IComposerClient::FRect x) {
114 return AidlFRect{
115 .left = x.left,
116 .top = x.top,
117 .right = x.right,
118 .bottom = x.bottom,
119 };
120}
121
122template <>
Ady Abrahame7385f72021-09-05 00:54:25 -0700123AidlPerFrameMetadataBlob translate(IComposerClient::PerFrameMetadataBlob x) {
124 AidlPerFrameMetadataBlob blob;
125 blob.key = translate<AidlPerFrameMetadataKey>(x.key),
Long Linga4628782022-02-18 13:44:26 -0800126 std::copy(x.blob.begin(), x.blob.end(), std::inserter(blob.blob, blob.blob.end()));
Ady Abrahame7385f72021-09-05 00:54:25 -0700127 return blob;
128}
129
130template <>
131AidlPerFrameMetadata translate(IComposerClient::PerFrameMetadata x) {
132 return AidlPerFrameMetadata{
133 .key = translate<AidlPerFrameMetadataKey>(x.key),
134 .value = x.value,
135 };
136}
137
138template <>
139DisplayedFrameStats translate(AidlDisplayContentSample x) {
140 return DisplayedFrameStats{
141 .numFrames = static_cast<uint64_t>(x.frameCount),
142 .component_0_sample = translate<uint64_t>(x.sampleComponent0),
143 .component_1_sample = translate<uint64_t>(x.sampleComponent1),
144 .component_2_sample = translate<uint64_t>(x.sampleComponent2),
145 .component_3_sample = translate<uint64_t>(x.sampleComponent3),
146 };
147}
148
149template <>
150AidlVsyncPeriodChangeConstraints translate(IComposerClient::VsyncPeriodChangeConstraints x) {
151 return AidlVsyncPeriodChangeConstraints{
152 .desiredTimeNanos = x.desiredTimeNanos,
153 .seamlessRequired = x.seamlessRequired,
154 };
155}
156
157template <>
158VsyncPeriodChangeTimeline translate(AidlVsyncPeriodChangeTimeline x) {
159 return VsyncPeriodChangeTimeline{
160 .newVsyncAppliedTimeNanos = x.newVsyncAppliedTimeNanos,
161 .refreshRequired = x.refreshRequired,
162 .refreshTimeNanos = x.refreshTimeNanos,
163 };
164}
Ady Abrahame7385f72021-09-05 00:54:25 -0700165mat4 makeMat4(std::vector<float> in) {
166 return mat4(static_cast<const float*>(in.data()));
167}
168
169} // namespace
170
171class AidlIComposerCallbackWrapper : public BnComposerCallback {
172public:
Yichi Chen3401b562022-01-17 15:42:35 +0800173 AidlIComposerCallbackWrapper(HWC2::ComposerCallback& callback) : mCallback(callback) {}
Ady Abrahame7385f72021-09-05 00:54:25 -0700174
175 ::ndk::ScopedAStatus onHotplug(int64_t in_display, bool in_connected) override {
176 const auto connection = in_connected ? V2_4::IComposerCallback::Connection::CONNECTED
177 : V2_4::IComposerCallback::Connection::DISCONNECTED;
Yichi Chen3401b562022-01-17 15:42:35 +0800178 mCallback.onComposerHalHotplug(translate<Display>(in_display), connection);
Ady Abrahame7385f72021-09-05 00:54:25 -0700179 return ::ndk::ScopedAStatus::ok();
180 }
181
182 ::ndk::ScopedAStatus onRefresh(int64_t in_display) override {
Yichi Chen3401b562022-01-17 15:42:35 +0800183 mCallback.onComposerHalRefresh(translate<Display>(in_display));
Ady Abrahame7385f72021-09-05 00:54:25 -0700184 return ::ndk::ScopedAStatus::ok();
185 }
Yichi Chen3401b562022-01-17 15:42:35 +0800186
Ady Abrahame7385f72021-09-05 00:54:25 -0700187 ::ndk::ScopedAStatus onSeamlessPossible(int64_t in_display) override {
Yichi Chen3401b562022-01-17 15:42:35 +0800188 mCallback.onComposerHalSeamlessPossible(translate<Display>(in_display));
Ady Abrahame7385f72021-09-05 00:54:25 -0700189 return ::ndk::ScopedAStatus::ok();
190 }
Yichi Chen3401b562022-01-17 15:42:35 +0800191
Ady Abrahame7385f72021-09-05 00:54:25 -0700192 ::ndk::ScopedAStatus onVsync(int64_t in_display, int64_t in_timestamp,
193 int32_t in_vsyncPeriodNanos) override {
Yichi Chen3401b562022-01-17 15:42:35 +0800194 mCallback.onComposerHalVsync(translate<Display>(in_display), in_timestamp,
195 static_cast<uint32_t>(in_vsyncPeriodNanos));
Ady Abrahame7385f72021-09-05 00:54:25 -0700196 return ::ndk::ScopedAStatus::ok();
197 }
Yichi Chen3401b562022-01-17 15:42:35 +0800198
Ady Abrahame7385f72021-09-05 00:54:25 -0700199 ::ndk::ScopedAStatus onVsyncPeriodTimingChanged(
200 int64_t in_display, const AidlVsyncPeriodChangeTimeline& in_updatedTimeline) override {
Yichi Chen3401b562022-01-17 15:42:35 +0800201 mCallback.onComposerHalVsyncPeriodTimingChanged(translate<Display>(in_display),
202 translate<V2_4::VsyncPeriodChangeTimeline>(
203 in_updatedTimeline));
204 return ::ndk::ScopedAStatus::ok();
205 }
206
207 ::ndk::ScopedAStatus onVsyncIdle(int64_t in_display) override {
208 mCallback.onComposerHalVsyncIdle(translate<Display>(in_display));
Ady Abrahame7385f72021-09-05 00:54:25 -0700209 return ::ndk::ScopedAStatus::ok();
210 }
211
ramindani12bfe6b2023-02-03 13:29:19 -0800212 ::ndk::ScopedAStatus onRefreshRateChangedDebug(
213 const RefreshRateChangedDebugData& refreshRateChangedDebugData) override {
214 mCallback.onRefreshRateChangedDebug(refreshRateChangedDebugData);
215 return ::ndk::ScopedAStatus::ok();
216 }
217
Ady Abrahame7385f72021-09-05 00:54:25 -0700218private:
Yichi Chen3401b562022-01-17 15:42:35 +0800219 HWC2::ComposerCallback& mCallback;
Ady Abrahame7385f72021-09-05 00:54:25 -0700220};
221
Ady Abraham9fc28052021-10-14 17:21:38 -0700222std::string AidlComposer::instance(const std::string& serviceName) {
223 return std::string(AidlIComposer::descriptor) + "/" + serviceName;
224}
225
226bool AidlComposer::isDeclared(const std::string& serviceName) {
227 return AServiceManager_isDeclared(instance(serviceName).c_str());
228}
Ady Abrahame7385f72021-09-05 00:54:25 -0700229
Ady Abrahama6388c02021-11-11 21:11:51 -0800230AidlComposer::AidlComposer(const std::string& serviceName) {
Ady Abrahame7385f72021-09-05 00:54:25 -0700231 // This only waits if the service is actually declared
Ady Abraham9fc28052021-10-14 17:21:38 -0700232 mAidlComposer = AidlIComposer::fromBinder(
233 ndk::SpAIBinder(AServiceManager_waitForService(instance(serviceName).c_str())));
Ady Abrahame7385f72021-09-05 00:54:25 -0700234 if (!mAidlComposer) {
235 LOG_ALWAYS_FATAL("Failed to get AIDL composer service");
236 return;
237 }
238
239 if (!mAidlComposer->createClient(&mAidlComposerClient).isOk()) {
240 LOG_ALWAYS_FATAL("Can't create AidlComposerClient, fallback to HIDL");
241 return;
242 }
243
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400244 addReader(translate<Display>(kSingleReaderKey));
245
Brian Lindahldbf7e3a2022-12-16 11:43:39 -0700246 // If unable to read interface version, then become backwards compatible.
247 int32_t version = 1;
248 const auto status = mAidlComposerClient->getInterfaceVersion(&version);
249 if (!status.isOk()) {
250 ALOGE("getInterfaceVersion for AidlComposer constructor failed %s",
251 status.getDescription().c_str());
252 }
Brian Lindahlab84e112023-06-15 14:19:43 -0600253 mSupportsBufferSlotsToClear = version > 1;
254 if (!mSupportsBufferSlotsToClear) {
255 if (sysprop::clear_slots_with_set_layer_buffer(false)) {
256 mClearSlotBuffer = sp<GraphicBuffer>::make(1, 1, PIXEL_FORMAT_RGBX_8888,
257 GraphicBuffer::USAGE_HW_COMPOSER |
258 GraphicBuffer::USAGE_SW_READ_OFTEN |
259 GraphicBuffer::USAGE_SW_WRITE_OFTEN,
260 "AidlComposer");
261 if (!mClearSlotBuffer || mClearSlotBuffer->initCheck() != ::android::OK) {
262 LOG_ALWAYS_FATAL("Failed to allocate a buffer for clearing layer buffer slots");
263 return;
264 }
Brian Lindahldbf7e3a2022-12-16 11:43:39 -0700265 }
Brian Lindahl90553da2022-12-06 13:36:30 -0700266 }
267
Ady Abrahame7385f72021-09-05 00:54:25 -0700268 ALOGI("Loaded AIDL composer3 HAL service");
269}
270
271AidlComposer::~AidlComposer() = default;
272
Ady Abraham4d211cf2021-12-14 16:19:03 -0800273bool AidlComposer::isSupported(OptionalFeature feature) const {
274 switch (feature) {
275 case OptionalFeature::RefreshRateSwitching:
Ady Abraham43065bd2021-12-10 17:22:15 -0800276 case OptionalFeature::ExpectedPresentTime:
Alec Mouricdf16792021-12-10 13:16:06 -0800277 case OptionalFeature::DisplayBrightnessCommand:
ramindani32cf0602022-03-02 02:30:29 +0000278 case OptionalFeature::KernelIdleTimer:
ramindani06e518e2022-03-14 18:47:53 +0000279 case OptionalFeature::PhysicalDisplayOrientation:
Ady Abraham4d211cf2021-12-14 16:19:03 -0800280 return true;
281 }
282}
283
Ady Abrahamde549d42022-01-26 19:19:17 -0800284std::vector<Capability> AidlComposer::getCapabilities() {
Ady Abrahame7385f72021-09-05 00:54:25 -0700285 std::vector<Capability> capabilities;
286 const auto status = mAidlComposer->getCapabilities(&capabilities);
287 if (!status.isOk()) {
288 ALOGE("getCapabilities failed %s", status.getDescription().c_str());
289 return {};
290 }
Ady Abrahamde549d42022-01-26 19:19:17 -0800291 return capabilities;
Ady Abrahame7385f72021-09-05 00:54:25 -0700292}
293
294std::string AidlComposer::dumpDebugInfo() {
Ady Abrahamc4acf512022-02-18 17:11:59 -0800295 int pipefds[2];
296 int result = pipe(pipefds);
297 if (result < 0) {
298 ALOGE("dumpDebugInfo: pipe failed: %s", strerror(errno));
Ady Abrahame7385f72021-09-05 00:54:25 -0700299 return {};
300 }
Ady Abrahamc4acf512022-02-18 17:11:59 -0800301
302 std::string str;
yihsing.shen58847c52022-09-23 15:39:30 +0800303 // Use other thread to read pipe to prevent
304 // pipe is full, making HWC be blocked in writing.
305 std::thread t([&]() {
306 base::ReadFdToString(pipefds[0], &str);
307 });
Ady Abrahamc4acf512022-02-18 17:11:59 -0800308 const auto status = mAidlComposer->dump(pipefds[1], /*args*/ nullptr, /*numArgs*/ 0);
309 // Close the write-end of the pipe to make sure that when reading from the
310 // read-end we will get eof instead of blocking forever
311 close(pipefds[1]);
312
yihsing.shen58847c52022-09-23 15:39:30 +0800313 if (status != STATUS_OK) {
Ady Abrahamc4acf512022-02-18 17:11:59 -0800314 ALOGE("dumpDebugInfo: dump failed: %d", status);
315 }
316
yihsing.shen58847c52022-09-23 15:39:30 +0800317 t.join();
Ady Abrahamc4acf512022-02-18 17:11:59 -0800318 close(pipefds[0]);
319 return str;
Ady Abrahame7385f72021-09-05 00:54:25 -0700320}
321
Yichi Chen3401b562022-01-17 15:42:35 +0800322void AidlComposer::registerCallback(HWC2::ComposerCallback& callback) {
Ady Abrahame7385f72021-09-05 00:54:25 -0700323 if (mAidlComposerCallback) {
324 ALOGE("Callback already registered");
325 }
Yichi Chen3401b562022-01-17 15:42:35 +0800326
Ady Abraham9fc28052021-10-14 17:21:38 -0700327 mAidlComposerCallback = ndk::SharedRefBase::make<AidlIComposerCallbackWrapper>(callback);
shuide chenf1111e12024-01-03 18:41:38 +0800328
329 ndk::SpAIBinder binder = mAidlComposerCallback->asBinder();
330 AIBinder_setMinSchedulerPolicy(binder.get(), SCHED_FIFO, 2);
Ady Abrahame7385f72021-09-05 00:54:25 -0700331
332 const auto status = mAidlComposerClient->registerCallback(mAidlComposerCallback);
333 if (!status.isOk()) {
334 ALOGE("registerCallback failed %s", status.getDescription().c_str());
335 }
336}
337
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400338Error AidlComposer::executeCommands(Display display) {
339 mMutex.lock_shared();
340 auto error = execute(display);
341 mMutex.unlock_shared();
342 return error;
Ady Abrahame7385f72021-09-05 00:54:25 -0700343}
344
345uint32_t AidlComposer::getMaxVirtualDisplayCount() {
346 int32_t count = 0;
347 const auto status = mAidlComposerClient->getMaxVirtualDisplayCount(&count);
348 if (!status.isOk()) {
349 ALOGE("getMaxVirtualDisplayCount failed %s", status.getDescription().c_str());
350 return 0;
351 }
352 return static_cast<uint32_t>(count);
353}
354
355Error AidlComposer::createVirtualDisplay(uint32_t width, uint32_t height, PixelFormat* format,
356 Display* outDisplay) {
357 using AidlPixelFormat = aidl::android::hardware::graphics::common::PixelFormat;
358 const int32_t bufferSlotCount = 1;
359 VirtualDisplay virtualDisplay;
360 const auto status =
361 mAidlComposerClient->createVirtualDisplay(static_cast<int32_t>(width),
362 static_cast<int32_t>(height),
363 static_cast<AidlPixelFormat>(*format),
364 bufferSlotCount, &virtualDisplay);
365
366 if (!status.isOk()) {
367 ALOGE("createVirtualDisplay failed %s", status.getDescription().c_str());
368 return static_cast<Error>(status.getServiceSpecificError());
369 }
370
371 *outDisplay = translate<Display>(virtualDisplay.display);
372 *format = static_cast<PixelFormat>(virtualDisplay.format);
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400373 addDisplay(translate<Display>(virtualDisplay.display));
Ady Abrahame7385f72021-09-05 00:54:25 -0700374 return Error::NONE;
375}
376
377Error AidlComposer::destroyVirtualDisplay(Display display) {
378 const auto status = mAidlComposerClient->destroyVirtualDisplay(translate<int64_t>(display));
379 if (!status.isOk()) {
380 ALOGE("destroyVirtualDisplay failed %s", status.getDescription().c_str());
381 return static_cast<Error>(status.getServiceSpecificError());
382 }
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400383 removeDisplay(display);
Ady Abrahame7385f72021-09-05 00:54:25 -0700384 return Error::NONE;
385}
386
387Error AidlComposer::acceptDisplayChanges(Display display) {
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400388 Error error = Error::NONE;
389 mMutex.lock_shared();
390 if (auto writer = getWriter(display)) {
391 writer->get().acceptDisplayChanges(translate<int64_t>(display));
392 } else {
393 error = Error::BAD_DISPLAY;
394 }
395 mMutex.unlock_shared();
396 return error;
Ady Abrahame7385f72021-09-05 00:54:25 -0700397}
398
399Error AidlComposer::createLayer(Display display, Layer* outLayer) {
400 int64_t layer;
401 const auto status = mAidlComposerClient->createLayer(translate<int64_t>(display),
402 kMaxLayerBufferCount, &layer);
403 if (!status.isOk()) {
404 ALOGE("createLayer failed %s", status.getDescription().c_str());
405 return static_cast<Error>(status.getServiceSpecificError());
406 }
407
408 *outLayer = translate<Layer>(layer);
409 return Error::NONE;
410}
411
412Error AidlComposer::destroyLayer(Display display, Layer layer) {
413 const auto status = mAidlComposerClient->destroyLayer(translate<int64_t>(display),
414 translate<int64_t>(layer));
415 if (!status.isOk()) {
416 ALOGE("destroyLayer failed %s", status.getDescription().c_str());
417 return static_cast<Error>(status.getServiceSpecificError());
418 }
419 return Error::NONE;
420}
421
422Error AidlComposer::getActiveConfig(Display display, Config* outConfig) {
423 int32_t config;
424 const auto status = mAidlComposerClient->getActiveConfig(translate<int64_t>(display), &config);
425 if (!status.isOk()) {
426 ALOGE("getActiveConfig failed %s", status.getDescription().c_str());
427 return static_cast<Error>(status.getServiceSpecificError());
428 }
429 *outConfig = translate<Config>(config);
430 return Error::NONE;
431}
432
433Error AidlComposer::getChangedCompositionTypes(
434 Display display, std::vector<Layer>* outLayers,
Leon Scroggins III2e1aa182021-12-01 17:33:12 -0500435 std::vector<aidl::android::hardware::graphics::composer3::Composition>* outTypes) {
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400436 std::vector<ChangedCompositionLayer> changedLayers;
437 Error error = Error::NONE;
438 {
439 mMutex.lock_shared();
440 if (auto reader = getReader(display)) {
441 changedLayers = reader->get().takeChangedCompositionTypes(translate<int64_t>(display));
442 } else {
443 error = Error::BAD_DISPLAY;
444 }
445 mMutex.unlock_shared();
446 }
Ady Abrahamde792782021-12-20 10:00:49 -0800447 outLayers->reserve(changedLayers.size());
448 outTypes->reserve(changedLayers.size());
Ady Abrahama6388c02021-11-11 21:11:51 -0800449
Ady Abrahamde792782021-12-20 10:00:49 -0800450 for (const auto& layer : changedLayers) {
451 outLayers->emplace_back(translate<Layer>(layer.layer));
452 outTypes->emplace_back(layer.composition);
453 }
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400454 return error;
Ady Abrahame7385f72021-09-05 00:54:25 -0700455}
456
457Error AidlComposer::getColorModes(Display display, std::vector<ColorMode>* outModes) {
458 std::vector<AidlColorMode> modes;
459 const auto status = mAidlComposerClient->getColorModes(translate<int64_t>(display), &modes);
460 if (!status.isOk()) {
461 ALOGE("getColorModes failed %s", status.getDescription().c_str());
462 return static_cast<Error>(status.getServiceSpecificError());
463 }
464 *outModes = translate<ColorMode>(modes);
465 return Error::NONE;
466}
467
468Error AidlComposer::getDisplayAttribute(Display display, Config config,
469 IComposerClient::Attribute attribute, int32_t* outValue) {
470 const auto status =
471 mAidlComposerClient->getDisplayAttribute(translate<int64_t>(display),
472 translate<int32_t>(config),
473 static_cast<AidlDisplayAttribute>(attribute),
474 outValue);
475 if (!status.isOk()) {
476 ALOGE("getDisplayAttribute failed %s", status.getDescription().c_str());
477 return static_cast<Error>(status.getServiceSpecificError());
478 }
479 return Error::NONE;
480}
481
482Error AidlComposer::getDisplayConfigs(Display display, std::vector<Config>* outConfigs) {
483 std::vector<int32_t> configs;
484 const auto status =
485 mAidlComposerClient->getDisplayConfigs(translate<int64_t>(display), &configs);
486 if (!status.isOk()) {
487 ALOGE("getDisplayConfigs failed %s", status.getDescription().c_str());
488 return static_cast<Error>(status.getServiceSpecificError());
489 }
490 *outConfigs = translate<Config>(configs);
491 return Error::NONE;
492}
493
494Error AidlComposer::getDisplayName(Display display, std::string* outName) {
495 const auto status = mAidlComposerClient->getDisplayName(translate<int64_t>(display), outName);
496 if (!status.isOk()) {
497 ALOGE("getDisplayName failed %s", status.getDescription().c_str());
498 return static_cast<Error>(status.getServiceSpecificError());
499 }
500 return Error::NONE;
501}
502
503Error AidlComposer::getDisplayRequests(Display display, uint32_t* outDisplayRequestMask,
504 std::vector<Layer>* outLayers,
505 std::vector<uint32_t>* outLayerRequestMasks) {
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400506 Error error = Error::NONE;
507 DisplayRequest displayRequests;
508 {
509 mMutex.lock_shared();
510 if (auto reader = getReader(display)) {
511 displayRequests = reader->get().takeDisplayRequests(translate<int64_t>(display));
512 } else {
513 error = Error::BAD_DISPLAY;
514 }
515 mMutex.unlock_shared();
516 }
Ady Abrahamde792782021-12-20 10:00:49 -0800517 *outDisplayRequestMask = translate<uint32_t>(displayRequests.mask);
518 outLayers->reserve(displayRequests.layerRequests.size());
519 outLayerRequestMasks->reserve(displayRequests.layerRequests.size());
520
521 for (const auto& layer : displayRequests.layerRequests) {
522 outLayers->emplace_back(translate<Layer>(layer.layer));
523 outLayerRequestMasks->emplace_back(translate<uint32_t>(layer.mask));
524 }
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400525 return error;
Ady Abrahame7385f72021-09-05 00:54:25 -0700526}
527
528Error AidlComposer::getDozeSupport(Display display, bool* outSupport) {
Ady Abraham33b92b92021-12-08 18:30:27 -0800529 std::vector<AidlDisplayCapability> capabilities;
Ady Abrahame7385f72021-09-05 00:54:25 -0700530 const auto status =
Ady Abraham33b92b92021-12-08 18:30:27 -0800531 mAidlComposerClient->getDisplayCapabilities(translate<int64_t>(display), &capabilities);
Ady Abrahame7385f72021-09-05 00:54:25 -0700532 if (!status.isOk()) {
Ady Abraham33b92b92021-12-08 18:30:27 -0800533 ALOGE("getDisplayCapabilities failed %s", status.getDescription().c_str());
Ady Abrahame7385f72021-09-05 00:54:25 -0700534 return static_cast<Error>(status.getServiceSpecificError());
535 }
Ady Abraham33b92b92021-12-08 18:30:27 -0800536 *outSupport = std::find(capabilities.begin(), capabilities.end(),
537 AidlDisplayCapability::DOZE) != capabilities.end();
Ady Abrahame7385f72021-09-05 00:54:25 -0700538 return Error::NONE;
539}
540
ramindani32cf0602022-03-02 02:30:29 +0000541Error AidlComposer::hasDisplayIdleTimerCapability(Display display, bool* outSupport) {
542 std::vector<AidlDisplayCapability> capabilities;
543 const auto status =
544 mAidlComposerClient->getDisplayCapabilities(translate<int64_t>(display), &capabilities);
545 if (!status.isOk()) {
546 ALOGE("getDisplayCapabilities failed %s", status.getDescription().c_str());
547 return static_cast<Error>(status.getServiceSpecificError());
548 }
549 *outSupport = std::find(capabilities.begin(), capabilities.end(),
550 AidlDisplayCapability::DISPLAY_IDLE_TIMER) != capabilities.end();
551 return Error::NONE;
552}
553
Ady Abrahame7385f72021-09-05 00:54:25 -0700554Error AidlComposer::getHdrCapabilities(Display display, std::vector<Hdr>* outTypes,
555 float* outMaxLuminance, float* outMaxAverageLuminance,
556 float* outMinLuminance) {
557 AidlHdrCapabilities capabilities;
558 const auto status =
559 mAidlComposerClient->getHdrCapabilities(translate<int64_t>(display), &capabilities);
560 if (!status.isOk()) {
561 ALOGE("getHdrCapabilities failed %s", status.getDescription().c_str());
562 return static_cast<Error>(status.getServiceSpecificError());
563 }
564
Marc Kassisbdf7e4b2022-11-04 17:26:48 +0100565 *outTypes = capabilities.types;
Ady Abrahame7385f72021-09-05 00:54:25 -0700566 *outMaxLuminance = capabilities.maxLuminance;
567 *outMaxAverageLuminance = capabilities.maxAverageLuminance;
568 *outMinLuminance = capabilities.minLuminance;
569 return Error::NONE;
570}
571
Sally Qibb866c12022-10-17 11:31:20 -0700572Error AidlComposer::getOverlaySupport(AidlOverlayProperties* outProperties) {
573 const auto status = mAidlComposerClient->getOverlaySupport(outProperties);
574 if (!status.isOk()) {
575 ALOGE("getOverlaySupport failed %s", status.getDescription().c_str());
576 return static_cast<Error>(status.getServiceSpecificError());
577 }
Sally Qi0cbd08b2022-08-17 12:12:28 -0700578 return Error::NONE;
579}
580
Ady Abrahame7385f72021-09-05 00:54:25 -0700581Error AidlComposer::getReleaseFences(Display display, std::vector<Layer>* outLayers,
582 std::vector<int>* outReleaseFences) {
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400583 Error error = Error::NONE;
584 std::vector<ReleaseFences::Layer> fences;
585 {
586 mMutex.lock_shared();
587 if (auto reader = getReader(display)) {
588 fences = reader->get().takeReleaseFences(translate<int64_t>(display));
589 } else {
590 error = Error::BAD_DISPLAY;
591 }
592 mMutex.unlock_shared();
593 }
Ady Abrahamde792782021-12-20 10:00:49 -0800594 outLayers->reserve(fences.size());
595 outReleaseFences->reserve(fences.size());
596
597 for (auto& fence : fences) {
598 outLayers->emplace_back(translate<Layer>(fence.layer));
599 // take ownership
600 const int fenceOwner = fence.fence.get();
601 *fence.fence.getR() = -1;
602 outReleaseFences->emplace_back(fenceOwner);
603 }
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400604 return error;
Ady Abrahame7385f72021-09-05 00:54:25 -0700605}
606
607Error AidlComposer::presentDisplay(Display display, int* outPresentFence) {
Leon Scroggins IIIe85e16e2022-12-12 12:51:18 -0500608 const auto displayId = translate<int64_t>(display);
609 ATRACE_FORMAT("HwcPresentDisplay %" PRId64, displayId);
610
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400611 Error error = Error::NONE;
612 mMutex.lock_shared();
613 auto writer = getWriter(display);
614 auto reader = getReader(display);
615 if (writer && reader) {
Leon Scroggins IIIe85e16e2022-12-12 12:51:18 -0500616 writer->get().presentDisplay(displayId);
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400617 error = execute(display);
618 } else {
619 error = Error::BAD_DISPLAY;
620 }
Ady Abrahame7385f72021-09-05 00:54:25 -0700621
Ady Abrahame7385f72021-09-05 00:54:25 -0700622 if (error != Error::NONE) {
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400623 mMutex.unlock_shared();
Ady Abrahame7385f72021-09-05 00:54:25 -0700624 return error;
625 }
626
Leon Scroggins IIIe85e16e2022-12-12 12:51:18 -0500627 auto fence = reader->get().takePresentFence(displayId);
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400628 mMutex.unlock_shared();
Ady Abrahamde792782021-12-20 10:00:49 -0800629 // take ownership
630 *outPresentFence = fence.get();
631 *fence.getR() = -1;
Ady Abrahame7385f72021-09-05 00:54:25 -0700632 return Error::NONE;
633}
634
635Error AidlComposer::setActiveConfig(Display display, Config config) {
636 const auto status = mAidlComposerClient->setActiveConfig(translate<int64_t>(display),
637 translate<int32_t>(config));
638 if (!status.isOk()) {
639 ALOGE("setActiveConfig failed %s", status.getDescription().c_str());
640 return static_cast<Error>(status.getServiceSpecificError());
641 }
642 return Error::NONE;
643}
644
645Error AidlComposer::setClientTarget(Display display, uint32_t slot, const sp<GraphicBuffer>& target,
646 int acquireFence, Dataspace dataspace,
647 const std::vector<IComposerClient::Rect>& damage) {
Ady Abrahame7385f72021-09-05 00:54:25 -0700648 const native_handle_t* handle = nullptr;
649 if (target.get()) {
650 handle = target->getNativeBuffer()->handle;
651 }
652
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400653 Error error = Error::NONE;
654 mMutex.lock_shared();
655 if (auto writer = getWriter(display)) {
656 writer->get()
657 .setClientTarget(translate<int64_t>(display), slot, handle, acquireFence,
658 translate<aidl::android::hardware::graphics::common::Dataspace>(
659 dataspace),
660 translate<AidlRect>(damage));
661 } else {
662 error = Error::BAD_DISPLAY;
663 }
664 mMutex.unlock_shared();
665 return error;
Ady Abrahame7385f72021-09-05 00:54:25 -0700666}
667
668Error AidlComposer::setColorMode(Display display, ColorMode mode, RenderIntent renderIntent) {
669 const auto status =
670 mAidlComposerClient->setColorMode(translate<int64_t>(display),
671 translate<AidlColorMode>(mode),
672 translate<AidlRenderIntent>(renderIntent));
673 if (!status.isOk()) {
674 ALOGE("setColorMode failed %s", status.getDescription().c_str());
675 return static_cast<Error>(status.getServiceSpecificError());
676 }
677 return Error::NONE;
678}
679
Ady Abrahamdc011a92021-12-21 14:06:44 -0800680Error AidlComposer::setColorTransform(Display display, const float* matrix) {
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400681 auto error = Error::NONE;
682 mMutex.lock_shared();
683 if (auto writer = getWriter(display)) {
684 writer->get().setColorTransform(translate<int64_t>(display), matrix);
685 } else {
686 error = Error::BAD_DISPLAY;
687 }
688 mMutex.unlock_shared();
689 return error;
Ady Abrahame7385f72021-09-05 00:54:25 -0700690}
691
692Error AidlComposer::setOutputBuffer(Display display, const native_handle_t* buffer,
693 int releaseFence) {
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400694 auto error = Error::NONE;
695 mMutex.lock_shared();
696 if (auto writer = getWriter(display)) {
697 writer->get().setOutputBuffer(translate<int64_t>(display), 0, buffer, dup(releaseFence));
698 } else {
699 error = Error::BAD_DISPLAY;
700 }
701 mMutex.unlock_shared();
702 return error;
Ady Abrahame7385f72021-09-05 00:54:25 -0700703}
704
705Error AidlComposer::setPowerMode(Display display, IComposerClient::PowerMode mode) {
706 const auto status = mAidlComposerClient->setPowerMode(translate<int64_t>(display),
707 translate<PowerMode>(mode));
708 if (!status.isOk()) {
709 ALOGE("setPowerMode failed %s", status.getDescription().c_str());
710 return static_cast<Error>(status.getServiceSpecificError());
711 }
712 return Error::NONE;
713}
714
715Error AidlComposer::setVsyncEnabled(Display display, IComposerClient::Vsync enabled) {
716 const bool enableVsync = enabled == IComposerClient::Vsync::ENABLE;
717 const auto status =
718 mAidlComposerClient->setVsyncEnabled(translate<int64_t>(display), enableVsync);
719 if (!status.isOk()) {
720 ALOGE("setVsyncEnabled failed %s", status.getDescription().c_str());
721 return static_cast<Error>(status.getServiceSpecificError());
722 }
723 return Error::NONE;
724}
725
726Error AidlComposer::setClientTargetSlotCount(Display display) {
727 const int32_t bufferSlotCount = BufferQueue::NUM_BUFFER_SLOTS;
728 const auto status = mAidlComposerClient->setClientTargetSlotCount(translate<int64_t>(display),
729 bufferSlotCount);
730 if (!status.isOk()) {
731 ALOGE("setClientTargetSlotCount failed %s", status.getDescription().c_str());
732 return static_cast<Error>(status.getServiceSpecificError());
733 }
734 return Error::NONE;
735}
736
Ady Abraham43065bd2021-12-10 17:22:15 -0800737Error AidlComposer::validateDisplay(Display display, nsecs_t expectedPresentTime,
738 uint32_t* outNumTypes, uint32_t* outNumRequests) {
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400739 const auto displayId = translate<int64_t>(display);
Leon Scroggins IIIe85e16e2022-12-12 12:51:18 -0500740 ATRACE_FORMAT("HwcValidateDisplay %" PRId64, displayId);
741
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400742 Error error = Error::NONE;
743 mMutex.lock_shared();
744 auto writer = getWriter(display);
745 auto reader = getReader(display);
746 if (writer && reader) {
747 writer->get().validateDisplay(displayId, ClockMonotonicTimestamp{expectedPresentTime});
748 error = execute(display);
749 } else {
750 error = Error::BAD_DISPLAY;
751 }
Ady Abrahame7385f72021-09-05 00:54:25 -0700752
Ady Abrahame7385f72021-09-05 00:54:25 -0700753 if (error != Error::NONE) {
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400754 mMutex.unlock_shared();
Ady Abrahame7385f72021-09-05 00:54:25 -0700755 return error;
756 }
757
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400758 reader->get().hasChanges(displayId, outNumTypes, outNumRequests);
Ady Abrahame7385f72021-09-05 00:54:25 -0700759
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400760 mMutex.unlock_shared();
Ady Abrahame7385f72021-09-05 00:54:25 -0700761 return Error::NONE;
762}
763
Ady Abraham43065bd2021-12-10 17:22:15 -0800764Error AidlComposer::presentOrValidateDisplay(Display display, nsecs_t expectedPresentTime,
765 uint32_t* outNumTypes, uint32_t* outNumRequests,
766 int* outPresentFence, uint32_t* state) {
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400767 const auto displayId = translate<int64_t>(display);
Leon Scroggins IIIe85e16e2022-12-12 12:51:18 -0500768 ATRACE_FORMAT("HwcPresentOrValidateDisplay %" PRId64, displayId);
769
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400770 Error error = Error::NONE;
771 mMutex.lock_shared();
772 auto writer = getWriter(display);
773 auto reader = getReader(display);
774 if (writer && reader) {
775 writer->get().presentOrvalidateDisplay(displayId,
776 ClockMonotonicTimestamp{expectedPresentTime});
777 error = execute(display);
778 } else {
779 error = Error::BAD_DISPLAY;
780 }
Ady Abrahame7385f72021-09-05 00:54:25 -0700781
Ady Abrahame7385f72021-09-05 00:54:25 -0700782 if (error != Error::NONE) {
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400783 mMutex.unlock_shared();
Ady Abrahame7385f72021-09-05 00:54:25 -0700784 return error;
785 }
786
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400787 const auto result = reader->get().takePresentOrValidateStage(displayId);
Ady Abrahamde792782021-12-20 10:00:49 -0800788 if (!result.has_value()) {
789 *state = translate<uint32_t>(-1);
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400790 mMutex.unlock_shared();
Ady Abrahamde792782021-12-20 10:00:49 -0800791 return Error::NO_RESOURCES;
Ady Abrahame7385f72021-09-05 00:54:25 -0700792 }
793
Ady Abrahamde792782021-12-20 10:00:49 -0800794 *state = translate<uint32_t>(*result);
795
796 if (*result == PresentOrValidate::Result::Presented) {
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400797 auto fence = reader->get().takePresentFence(displayId);
Ady Abrahamde792782021-12-20 10:00:49 -0800798 // take ownership
799 *outPresentFence = fence.get();
800 *fence.getR() = -1;
801 }
802
803 if (*result == PresentOrValidate::Result::Validated) {
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400804 reader->get().hasChanges(displayId, outNumTypes, outNumRequests);
Ady Abrahame7385f72021-09-05 00:54:25 -0700805 }
806
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400807 mMutex.unlock_shared();
Ady Abrahame7385f72021-09-05 00:54:25 -0700808 return Error::NONE;
809}
810
811Error AidlComposer::setCursorPosition(Display display, Layer layer, int32_t x, int32_t y) {
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400812 Error error = Error::NONE;
813 mMutex.lock_shared();
814 if (auto writer = getWriter(display)) {
815 writer->get().setLayerCursorPosition(translate<int64_t>(display), translate<int64_t>(layer),
816 x, y);
817 } else {
818 error = Error::BAD_DISPLAY;
819 }
820 mMutex.unlock_shared();
821 return error;
Ady Abrahame7385f72021-09-05 00:54:25 -0700822}
823
824Error AidlComposer::setLayerBuffer(Display display, Layer layer, uint32_t slot,
825 const sp<GraphicBuffer>& buffer, int acquireFence) {
Ady Abrahame7385f72021-09-05 00:54:25 -0700826 const native_handle_t* handle = nullptr;
827 if (buffer.get()) {
828 handle = buffer->getNativeBuffer()->handle;
829 }
830
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400831 Error error = Error::NONE;
832 mMutex.lock_shared();
833 if (auto writer = getWriter(display)) {
834 writer->get().setLayerBuffer(translate<int64_t>(display), translate<int64_t>(layer), slot,
835 handle, acquireFence);
836 } else {
837 error = Error::BAD_DISPLAY;
838 }
839 mMutex.unlock_shared();
840 return error;
Ady Abrahame7385f72021-09-05 00:54:25 -0700841}
842
Brian Lindahlb158a5c2022-12-15 15:21:13 -0700843Error AidlComposer::setLayerBufferSlotsToClear(Display display, Layer layer,
844 const std::vector<uint32_t>& slotsToClear,
845 uint32_t activeBufferSlot) {
846 if (slotsToClear.empty()) {
847 return Error::NONE;
848 }
849
Brian Lindahl90553da2022-12-06 13:36:30 -0700850 Error error = Error::NONE;
851 mMutex.lock_shared();
852 if (auto writer = getWriter(display)) {
Brian Lindahlab84e112023-06-15 14:19:43 -0600853 if (mSupportsBufferSlotsToClear) {
Brian Lindahldbf7e3a2022-12-16 11:43:39 -0700854 writer->get().setLayerBufferSlotsToClear(translate<int64_t>(display),
855 translate<int64_t>(layer), slotsToClear);
Brian Lindahlab84e112023-06-15 14:19:43 -0600856 // Backwards compatible way of clearing buffer slots is to set the layer buffer with a
857 // placeholder buffer, using the slot that needs to cleared... tricky.
858 } else if (mClearSlotBuffer != nullptr) {
Brian Lindahldbf7e3a2022-12-16 11:43:39 -0700859 for (uint32_t slot : slotsToClear) {
860 // Don't clear the active buffer slot because we need to restore the active buffer
861 // after clearing the requested buffer slots with a placeholder buffer.
862 if (slot != activeBufferSlot) {
863 writer->get().setLayerBufferWithNewCommand(translate<int64_t>(display),
864 translate<int64_t>(layer), slot,
865 mClearSlotBuffer->handle,
866 /*fence*/ -1);
867 }
Brian Lindahlb158a5c2022-12-15 15:21:13 -0700868 }
Brian Lindahldbf7e3a2022-12-16 11:43:39 -0700869 // Since we clear buffers by setting them to a placeholder buffer, we want to make
870 // sure that the last setLayerBuffer command is sent with the currently active
871 // buffer, not the placeholder buffer, so that there is no perceptual change when
872 // buffers are discarded.
873 writer->get().setLayerBufferWithNewCommand(translate<int64_t>(display),
874 translate<int64_t>(layer), activeBufferSlot,
875 // The active buffer is still cached in
876 // its slot and doesn't need a fence.
877 /*buffer*/ nullptr, /*fence*/ -1);
Brian Lindahlb158a5c2022-12-15 15:21:13 -0700878 }
Brian Lindahl90553da2022-12-06 13:36:30 -0700879 } else {
880 error = Error::BAD_DISPLAY;
881 }
882 mMutex.unlock_shared();
883 return error;
884}
885
Ady Abrahame7385f72021-09-05 00:54:25 -0700886Error AidlComposer::setLayerSurfaceDamage(Display display, Layer layer,
887 const std::vector<IComposerClient::Rect>& damage) {
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400888 Error error = Error::NONE;
889 mMutex.lock_shared();
890 if (auto writer = getWriter(display)) {
891 writer->get().setLayerSurfaceDamage(translate<int64_t>(display), translate<int64_t>(layer),
892 translate<AidlRect>(damage));
893 } else {
894 error = Error::BAD_DISPLAY;
895 }
896 mMutex.unlock_shared();
897 return error;
Ady Abrahame7385f72021-09-05 00:54:25 -0700898}
899
900Error AidlComposer::setLayerBlendMode(Display display, Layer layer,
901 IComposerClient::BlendMode mode) {
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400902 Error error = Error::NONE;
903 mMutex.lock_shared();
904 if (auto writer = getWriter(display)) {
905 writer->get().setLayerBlendMode(translate<int64_t>(display), translate<int64_t>(layer),
906 translate<BlendMode>(mode));
907 } else {
908 error = Error::BAD_DISPLAY;
909 }
910 mMutex.unlock_shared();
911 return error;
Ady Abrahame7385f72021-09-05 00:54:25 -0700912}
913
Ady Abraham6e60b142022-01-06 18:10:35 -0800914Error AidlComposer::setLayerColor(Display display, Layer layer, const Color& color) {
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400915 Error error = Error::NONE;
916 mMutex.lock_shared();
917 if (auto writer = getWriter(display)) {
918 writer->get().setLayerColor(translate<int64_t>(display), translate<int64_t>(layer), color);
919 } else {
920 error = Error::BAD_DISPLAY;
921 }
922 mMutex.unlock_shared();
923 return error;
Ady Abrahame7385f72021-09-05 00:54:25 -0700924}
925
Leon Scroggins III2e1aa182021-12-01 17:33:12 -0500926Error AidlComposer::setLayerCompositionType(
927 Display display, Layer layer,
928 aidl::android::hardware::graphics::composer3::Composition type) {
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400929 Error error = Error::NONE;
930 mMutex.lock_shared();
931 if (auto writer = getWriter(display)) {
932 writer->get().setLayerCompositionType(translate<int64_t>(display),
933 translate<int64_t>(layer), type);
934 } else {
935 error = Error::BAD_DISPLAY;
936 }
937 mMutex.unlock_shared();
938 return error;
Ady Abrahame7385f72021-09-05 00:54:25 -0700939}
940
941Error AidlComposer::setLayerDataspace(Display display, Layer layer, Dataspace dataspace) {
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400942 Error error = Error::NONE;
943 mMutex.lock_shared();
944 if (auto writer = getWriter(display)) {
945 writer->get().setLayerDataspace(translate<int64_t>(display), translate<int64_t>(layer),
946 translate<AidlDataspace>(dataspace));
947 } else {
948 error = Error::BAD_DISPLAY;
949 }
950 mMutex.unlock_shared();
951 return error;
Ady Abrahame7385f72021-09-05 00:54:25 -0700952}
953
954Error AidlComposer::setLayerDisplayFrame(Display display, Layer layer,
955 const IComposerClient::Rect& frame) {
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400956 Error error = Error::NONE;
957 mMutex.lock_shared();
958 if (auto writer = getWriter(display)) {
959 writer->get().setLayerDisplayFrame(translate<int64_t>(display), translate<int64_t>(layer),
960 translate<AidlRect>(frame));
961 } else {
962 error = Error::BAD_DISPLAY;
963 }
964 mMutex.unlock_shared();
965 return error;
Ady Abrahame7385f72021-09-05 00:54:25 -0700966}
967
968Error AidlComposer::setLayerPlaneAlpha(Display display, Layer layer, float alpha) {
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400969 Error error = Error::NONE;
970 mMutex.lock_shared();
971 if (auto writer = getWriter(display)) {
972 writer->get().setLayerPlaneAlpha(translate<int64_t>(display), translate<int64_t>(layer),
973 alpha);
974 } else {
975 error = Error::BAD_DISPLAY;
976 }
977 mMutex.unlock_shared();
978 return error;
Ady Abrahame7385f72021-09-05 00:54:25 -0700979}
980
981Error AidlComposer::setLayerSidebandStream(Display display, Layer layer,
982 const native_handle_t* stream) {
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400983 Error error = Error::NONE;
984 mMutex.lock_shared();
985 if (auto writer = getWriter(display)) {
986 writer->get().setLayerSidebandStream(translate<int64_t>(display), translate<int64_t>(layer),
987 stream);
988 } else {
989 error = Error::BAD_DISPLAY;
990 }
991 mMutex.unlock_shared();
992 return error;
Ady Abrahame7385f72021-09-05 00:54:25 -0700993}
994
995Error AidlComposer::setLayerSourceCrop(Display display, Layer layer,
996 const IComposerClient::FRect& crop) {
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400997 Error error = Error::NONE;
998 mMutex.lock_shared();
999 if (auto writer = getWriter(display)) {
1000 writer->get().setLayerSourceCrop(translate<int64_t>(display), translate<int64_t>(layer),
1001 translate<AidlFRect>(crop));
1002 } else {
1003 error = Error::BAD_DISPLAY;
1004 }
1005 mMutex.unlock_shared();
1006 return error;
Ady Abrahame7385f72021-09-05 00:54:25 -07001007}
1008
1009Error AidlComposer::setLayerTransform(Display display, Layer layer, Transform transform) {
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -04001010 Error error = Error::NONE;
1011 mMutex.lock_shared();
1012 if (auto writer = getWriter(display)) {
1013 writer->get().setLayerTransform(translate<int64_t>(display), translate<int64_t>(layer),
1014 translate<AidlTransform>(transform));
1015 } else {
1016 error = Error::BAD_DISPLAY;
1017 }
1018 mMutex.unlock_shared();
1019 return error;
Ady Abrahame7385f72021-09-05 00:54:25 -07001020}
1021
1022Error AidlComposer::setLayerVisibleRegion(Display display, Layer layer,
1023 const std::vector<IComposerClient::Rect>& visible) {
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -04001024 Error error = Error::NONE;
1025 mMutex.lock_shared();
1026 if (auto writer = getWriter(display)) {
1027 writer->get().setLayerVisibleRegion(translate<int64_t>(display), translate<int64_t>(layer),
1028 translate<AidlRect>(visible));
1029 } else {
1030 error = Error::BAD_DISPLAY;
1031 }
1032 mMutex.unlock_shared();
1033 return error;
Ady Abrahame7385f72021-09-05 00:54:25 -07001034}
1035
1036Error AidlComposer::setLayerZOrder(Display display, Layer layer, uint32_t z) {
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -04001037 Error error = Error::NONE;
1038 mMutex.lock_shared();
1039 if (auto writer = getWriter(display)) {
1040 writer->get().setLayerZOrder(translate<int64_t>(display), translate<int64_t>(layer), z);
1041 } else {
1042 error = Error::BAD_DISPLAY;
1043 }
1044 mMutex.unlock_shared();
1045 return error;
Ady Abrahame7385f72021-09-05 00:54:25 -07001046}
1047
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -04001048Error AidlComposer::execute(Display display) {
1049 auto writer = getWriter(display);
1050 auto reader = getReader(display);
1051 if (!writer || !reader) {
1052 return Error::BAD_DISPLAY;
1053 }
1054
Huihong Luoe7382c12023-04-21 20:24:32 +00001055 auto commands = writer->get().takePendingCommands();
Ady Abrahama6388c02021-11-11 21:11:51 -08001056 if (commands.empty()) {
Ady Abrahame7385f72021-09-05 00:54:25 -07001057 return Error::NONE;
1058 }
1059
Ady Abrahamde792782021-12-20 10:00:49 -08001060 { // scope for results
1061 std::vector<CommandResultPayload> results;
1062 auto status = mAidlComposerClient->executeCommands(commands, &results);
1063 if (!status.isOk()) {
1064 ALOGE("executeCommands failed %s", status.getDescription().c_str());
1065 return static_cast<Error>(status.getServiceSpecificError());
1066 }
Ady Abrahame7385f72021-09-05 00:54:25 -07001067
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -04001068 reader->get().parse(std::move(results));
Ady Abrahamde792782021-12-20 10:00:49 -08001069 }
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -04001070 const auto commandErrors = reader->get().takeErrors();
Ady Abrahama6388c02021-11-11 21:11:51 -08001071 Error error = Error::NONE;
1072 for (const auto& cmdErr : commandErrors) {
1073 const auto index = static_cast<size_t>(cmdErr.commandIndex);
1074 if (index < 0 || index >= commands.size()) {
1075 ALOGE("invalid command index %zu", index);
1076 return Error::BAD_PARAMETER;
Ady Abrahame7385f72021-09-05 00:54:25 -07001077 }
1078
Ady Abrahama6388c02021-11-11 21:11:51 -08001079 const auto& command = commands[index];
Ady Abraham42977362021-12-07 21:04:49 -08001080 if (command.validateDisplay || command.presentDisplay || command.presentOrValidateDisplay) {
1081 error = translate<Error>(cmdErr.errorCode);
1082 } else {
1083 ALOGW("command '%s' generated error %" PRId32, command.toString().c_str(),
1084 cmdErr.errorCode);
Ady Abrahame7385f72021-09-05 00:54:25 -07001085 }
1086 }
1087
Ady Abrahame7385f72021-09-05 00:54:25 -07001088 return error;
1089}
1090
1091Error AidlComposer::setLayerPerFrameMetadata(
1092 Display display, Layer layer,
1093 const std::vector<IComposerClient::PerFrameMetadata>& perFrameMetadatas) {
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -04001094 Error error = Error::NONE;
1095 mMutex.lock_shared();
1096 if (auto writer = getWriter(display)) {
1097 writer->get().setLayerPerFrameMetadata(translate<int64_t>(display),
1098 translate<int64_t>(layer),
1099 translate<AidlPerFrameMetadata>(perFrameMetadatas));
1100 } else {
1101 error = Error::BAD_DISPLAY;
1102 }
1103 mMutex.unlock_shared();
1104 return error;
Ady Abrahame7385f72021-09-05 00:54:25 -07001105}
1106
1107std::vector<IComposerClient::PerFrameMetadataKey> AidlComposer::getPerFrameMetadataKeys(
1108 Display display) {
1109 std::vector<AidlPerFrameMetadataKey> keys;
1110 const auto status =
1111 mAidlComposerClient->getPerFrameMetadataKeys(translate<int64_t>(display), &keys);
1112 if (!status.isOk()) {
1113 ALOGE("getPerFrameMetadataKeys failed %s", status.getDescription().c_str());
1114 return {};
1115 }
1116 return translate<IComposerClient::PerFrameMetadataKey>(keys);
1117}
1118
1119Error AidlComposer::getRenderIntents(Display display, ColorMode colorMode,
1120 std::vector<RenderIntent>* outRenderIntents) {
1121 std::vector<AidlRenderIntent> renderIntents;
1122 const auto status = mAidlComposerClient->getRenderIntents(translate<int64_t>(display),
1123 translate<AidlColorMode>(colorMode),
1124 &renderIntents);
1125 if (!status.isOk()) {
1126 ALOGE("getRenderIntents failed %s", status.getDescription().c_str());
1127 return static_cast<Error>(status.getServiceSpecificError());
1128 }
1129 *outRenderIntents = translate<RenderIntent>(renderIntents);
1130 return Error::NONE;
1131}
1132
1133Error AidlComposer::getDataspaceSaturationMatrix(Dataspace dataspace, mat4* outMatrix) {
1134 std::vector<float> matrix;
1135 const auto status =
1136 mAidlComposerClient->getDataspaceSaturationMatrix(translate<AidlDataspace>(dataspace),
1137 &matrix);
1138 if (!status.isOk()) {
1139 ALOGE("getDataspaceSaturationMatrix failed %s", status.getDescription().c_str());
1140 return static_cast<Error>(status.getServiceSpecificError());
1141 }
1142 *outMatrix = makeMat4(matrix);
1143 return Error::NONE;
1144}
1145
1146Error AidlComposer::getDisplayIdentificationData(Display display, uint8_t* outPort,
1147 std::vector<uint8_t>* outData) {
1148 AidlDisplayIdentification displayIdentification;
1149 const auto status =
1150 mAidlComposerClient->getDisplayIdentificationData(translate<int64_t>(display),
1151 &displayIdentification);
1152 if (!status.isOk()) {
1153 ALOGE("getDisplayIdentificationData failed %s", status.getDescription().c_str());
1154 return static_cast<Error>(status.getServiceSpecificError());
1155 }
1156
1157 *outPort = static_cast<uint8_t>(displayIdentification.port);
1158 *outData = displayIdentification.data;
1159
1160 return Error::NONE;
1161}
1162
1163Error AidlComposer::setLayerColorTransform(Display display, Layer layer, const float* matrix) {
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -04001164 Error error = Error::NONE;
1165 mMutex.lock_shared();
1166 if (auto writer = getWriter(display)) {
1167 writer->get().setLayerColorTransform(translate<int64_t>(display), translate<int64_t>(layer),
1168 matrix);
1169 } else {
1170 error = Error::BAD_DISPLAY;
1171 }
1172 mMutex.unlock_shared();
1173 return error;
Ady Abrahame7385f72021-09-05 00:54:25 -07001174}
1175
1176Error AidlComposer::getDisplayedContentSamplingAttributes(Display display, PixelFormat* outFormat,
1177 Dataspace* outDataspace,
1178 uint8_t* outComponentMask) {
1179 if (!outFormat || !outDataspace || !outComponentMask) {
1180 return Error::BAD_PARAMETER;
1181 }
1182
1183 AidlDisplayContentSamplingAttributes attributes;
1184 const auto status =
1185 mAidlComposerClient->getDisplayedContentSamplingAttributes(translate<int64_t>(display),
1186 &attributes);
1187 if (!status.isOk()) {
1188 ALOGE("getDisplayedContentSamplingAttributes failed %s", status.getDescription().c_str());
1189 return static_cast<Error>(status.getServiceSpecificError());
1190 }
1191
1192 *outFormat = translate<PixelFormat>(attributes.format);
1193 *outDataspace = translate<Dataspace>(attributes.dataspace);
1194 *outComponentMask = static_cast<uint8_t>(attributes.componentMask);
1195 return Error::NONE;
1196}
1197
1198Error AidlComposer::setDisplayContentSamplingEnabled(Display display, bool enabled,
1199 uint8_t componentMask, uint64_t maxFrames) {
1200 const auto status =
1201 mAidlComposerClient
1202 ->setDisplayedContentSamplingEnabled(translate<int64_t>(display), enabled,
1203 static_cast<AidlFormatColorComponent>(
1204 componentMask),
1205 static_cast<int64_t>(maxFrames));
1206 if (!status.isOk()) {
1207 ALOGE("setDisplayedContentSamplingEnabled failed %s", status.getDescription().c_str());
1208 return static_cast<Error>(status.getServiceSpecificError());
1209 }
1210 return Error::NONE;
1211}
1212
1213Error AidlComposer::getDisplayedContentSample(Display display, uint64_t maxFrames,
1214 uint64_t timestamp, DisplayedFrameStats* outStats) {
1215 if (!outStats) {
1216 return Error::BAD_PARAMETER;
1217 }
1218
1219 AidlDisplayContentSample sample;
1220 const auto status =
1221 mAidlComposerClient->getDisplayedContentSample(translate<int64_t>(display),
1222 static_cast<int64_t>(maxFrames),
1223 static_cast<int64_t>(timestamp),
1224 &sample);
1225 if (!status.isOk()) {
1226 ALOGE("getDisplayedContentSample failed %s", status.getDescription().c_str());
1227 return static_cast<Error>(status.getServiceSpecificError());
1228 }
1229 *outStats = translate<DisplayedFrameStats>(sample);
1230 return Error::NONE;
1231}
1232
1233Error AidlComposer::setLayerPerFrameMetadataBlobs(
1234 Display display, Layer layer,
1235 const std::vector<IComposerClient::PerFrameMetadataBlob>& metadata) {
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -04001236 Error error = Error::NONE;
1237 mMutex.lock_shared();
1238 if (auto writer = getWriter(display)) {
1239 writer->get().setLayerPerFrameMetadataBlobs(translate<int64_t>(display),
1240 translate<int64_t>(layer),
1241 translate<AidlPerFrameMetadataBlob>(metadata));
1242 } else {
1243 error = Error::BAD_DISPLAY;
1244 }
1245 mMutex.unlock_shared();
1246 return error;
Ady Abrahame7385f72021-09-05 00:54:25 -07001247}
1248
Alec Mouri4d8a05d2022-03-23 18:14:26 +00001249Error AidlComposer::setDisplayBrightness(Display display, float brightness, float brightnessNits,
Alec Mouricdf16792021-12-10 13:16:06 -08001250 const DisplayBrightnessOptions& options) {
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -04001251 Error error = Error::NONE;
1252 mMutex.lock_shared();
1253 if (auto writer = getWriter(display)) {
1254 writer->get().setDisplayBrightness(translate<int64_t>(display), brightness, brightnessNits);
Alec Mouricdf16792021-12-10 13:16:06 -08001255
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -04001256 if (options.applyImmediately) {
1257 error = execute(display);
1258 mMutex.unlock_shared();
1259 return error;
1260 }
1261 } else {
1262 error = Error::BAD_DISPLAY;
Alec Mouricdf16792021-12-10 13:16:06 -08001263 }
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -04001264 mMutex.unlock_shared();
1265 return error;
Ady Abrahame7385f72021-09-05 00:54:25 -07001266}
1267
1268Error AidlComposer::getDisplayCapabilities(Display display,
Leon Scroggins III5967aec2021-12-29 11:14:22 -05001269 std::vector<AidlDisplayCapability>* outCapabilities) {
1270 const auto status = mAidlComposerClient->getDisplayCapabilities(translate<int64_t>(display),
1271 outCapabilities);
Ady Abrahame7385f72021-09-05 00:54:25 -07001272 if (!status.isOk()) {
1273 ALOGE("getDisplayCapabilities failed %s", status.getDescription().c_str());
Leon Scroggins III5967aec2021-12-29 11:14:22 -05001274 outCapabilities->clear();
Ady Abrahame7385f72021-09-05 00:54:25 -07001275 return static_cast<Error>(status.getServiceSpecificError());
1276 }
Ady Abrahame7385f72021-09-05 00:54:25 -07001277 return Error::NONE;
1278}
1279
1280V2_4::Error AidlComposer::getDisplayConnectionType(
1281 Display display, IComposerClient::DisplayConnectionType* outType) {
1282 AidlDisplayConnectionType type;
1283 const auto status =
1284 mAidlComposerClient->getDisplayConnectionType(translate<int64_t>(display), &type);
1285 if (!status.isOk()) {
1286 ALOGE("getDisplayConnectionType failed %s", status.getDescription().c_str());
1287 return static_cast<V2_4::Error>(status.getServiceSpecificError());
1288 }
1289 *outType = translate<IComposerClient::DisplayConnectionType>(type);
1290 return V2_4::Error::NONE;
1291}
1292
1293V2_4::Error AidlComposer::getDisplayVsyncPeriod(Display display, VsyncPeriodNanos* outVsyncPeriod) {
1294 int32_t vsyncPeriod;
1295 const auto status =
1296 mAidlComposerClient->getDisplayVsyncPeriod(translate<int64_t>(display), &vsyncPeriod);
1297 if (!status.isOk()) {
1298 ALOGE("getDisplayVsyncPeriod failed %s", status.getDescription().c_str());
1299 return static_cast<V2_4::Error>(status.getServiceSpecificError());
1300 }
1301 *outVsyncPeriod = translate<VsyncPeriodNanos>(vsyncPeriod);
1302 return V2_4::Error::NONE;
1303}
1304
1305V2_4::Error AidlComposer::setActiveConfigWithConstraints(
1306 Display display, Config config,
1307 const IComposerClient::VsyncPeriodChangeConstraints& vsyncPeriodChangeConstraints,
1308 VsyncPeriodChangeTimeline* outTimeline) {
1309 AidlVsyncPeriodChangeTimeline timeline;
1310 const auto status =
1311 mAidlComposerClient
1312 ->setActiveConfigWithConstraints(translate<int64_t>(display),
1313 translate<int32_t>(config),
1314 translate<AidlVsyncPeriodChangeConstraints>(
1315 vsyncPeriodChangeConstraints),
1316 &timeline);
1317 if (!status.isOk()) {
1318 ALOGE("setActiveConfigWithConstraints failed %s", status.getDescription().c_str());
1319 return static_cast<V2_4::Error>(status.getServiceSpecificError());
1320 }
1321 *outTimeline = translate<VsyncPeriodChangeTimeline>(timeline);
1322 return V2_4::Error::NONE;
1323}
1324
1325V2_4::Error AidlComposer::setAutoLowLatencyMode(Display display, bool on) {
1326 const auto status = mAidlComposerClient->setAutoLowLatencyMode(translate<int64_t>(display), on);
1327 if (!status.isOk()) {
1328 ALOGE("setAutoLowLatencyMode failed %s", status.getDescription().c_str());
1329 return static_cast<V2_4::Error>(status.getServiceSpecificError());
1330 }
1331 return V2_4::Error::NONE;
1332}
1333
1334V2_4::Error AidlComposer::getSupportedContentTypes(
1335 Display displayId, std::vector<IComposerClient::ContentType>* outSupportedContentTypes) {
1336 std::vector<AidlContentType> types;
1337 const auto status =
1338 mAidlComposerClient->getSupportedContentTypes(translate<int64_t>(displayId), &types);
1339 if (!status.isOk()) {
1340 ALOGE("getSupportedContentTypes failed %s", status.getDescription().c_str());
1341 return static_cast<V2_4::Error>(status.getServiceSpecificError());
1342 }
1343 *outSupportedContentTypes = translate<IComposerClient::ContentType>(types);
1344 return V2_4::Error::NONE;
1345}
1346
1347V2_4::Error AidlComposer::setContentType(Display display,
1348 IComposerClient::ContentType contentType) {
1349 const auto status =
1350 mAidlComposerClient->setContentType(translate<int64_t>(display),
1351 translate<AidlContentType>(contentType));
1352 if (!status.isOk()) {
1353 ALOGE("setContentType failed %s", status.getDescription().c_str());
1354 return static_cast<V2_4::Error>(status.getServiceSpecificError());
1355 }
1356 return V2_4::Error::NONE;
1357}
1358
Ady Abraham3f976752021-12-20 16:17:50 -08001359V2_4::Error AidlComposer::setLayerGenericMetadata(Display, Layer, const std::string&, bool,
1360 const std::vector<uint8_t>&) {
1361 // There are no users for this API. See b/209691612.
1362 return V2_4::Error::UNSUPPORTED;
Ady Abrahame7385f72021-09-05 00:54:25 -07001363}
1364
1365V2_4::Error AidlComposer::getLayerGenericMetadataKeys(
Ady Abraham3f976752021-12-20 16:17:50 -08001366 std::vector<IComposerClient::LayerGenericMetadataKey>*) {
1367 // There are no users for this API. See b/209691612.
1368 return V2_4::Error::UNSUPPORTED;
Ady Abrahame7385f72021-09-05 00:54:25 -07001369}
1370
Kriti Dang7defaf32021-11-15 11:55:43 +01001371Error AidlComposer::setBootDisplayConfig(Display display, Config config) {
1372 const auto status = mAidlComposerClient->setBootDisplayConfig(translate<int64_t>(display),
1373 translate<int32_t>(config));
1374 if (!status.isOk()) {
1375 ALOGE("setBootDisplayConfig failed %s", status.getDescription().c_str());
1376 return static_cast<Error>(status.getServiceSpecificError());
1377 }
1378 return Error::NONE;
1379}
1380
1381Error AidlComposer::clearBootDisplayConfig(Display display) {
1382 const auto status = mAidlComposerClient->clearBootDisplayConfig(translate<int64_t>(display));
1383 if (!status.isOk()) {
1384 ALOGE("clearBootDisplayConfig failed %s", status.getDescription().c_str());
1385 return static_cast<Error>(status.getServiceSpecificError());
1386 }
1387 return Error::NONE;
1388}
1389
1390Error AidlComposer::getPreferredBootDisplayConfig(Display display, Config* config) {
1391 int32_t displayConfig;
1392 const auto status =
1393 mAidlComposerClient->getPreferredBootDisplayConfig(translate<int64_t>(display),
1394 &displayConfig);
1395 if (!status.isOk()) {
1396 ALOGE("getPreferredBootDisplayConfig failed %s", status.getDescription().c_str());
1397 return static_cast<Error>(status.getServiceSpecificError());
1398 }
1399 *config = translate<uint32_t>(displayConfig);
1400 return Error::NONE;
1401}
1402
Kriti Dang674b9372022-11-18 10:58:44 +01001403Error AidlComposer::getHdrConversionCapabilities(
1404 std::vector<AidlHdrConversionCapability>* hdrConversionCapabilities) {
1405 const auto status =
1406 mAidlComposerClient->getHdrConversionCapabilities(hdrConversionCapabilities);
1407 if (!status.isOk()) {
1408 hdrConversionCapabilities = {};
1409 ALOGE("getHdrConversionCapabilities failed %s", status.getDescription().c_str());
1410 return static_cast<Error>(status.getServiceSpecificError());
1411 }
1412 return Error::NONE;
1413}
1414
Kriti Dangd432bb52023-02-09 18:21:04 +01001415Error AidlComposer::setHdrConversionStrategy(AidlHdrConversionStrategy hdrConversionStrategy,
1416 Hdr* outPreferredHdrOutputType) {
1417 const auto status = mAidlComposerClient->setHdrConversionStrategy(hdrConversionStrategy,
1418 outPreferredHdrOutputType);
Kriti Dang674b9372022-11-18 10:58:44 +01001419 if (!status.isOk()) {
1420 ALOGE("setHdrConversionStrategy failed %s", status.getDescription().c_str());
1421 return static_cast<Error>(status.getServiceSpecificError());
1422 }
1423 return Error::NONE;
1424}
1425
ramindanib2158ee2023-02-13 20:29:59 -08001426Error AidlComposer::setRefreshRateChangedCallbackDebugEnabled(Display displayId, bool enabled) {
1427 const auto status =
1428 mAidlComposerClient->setRefreshRateChangedCallbackDebugEnabled(translate<int64_t>(
1429 displayId),
1430 enabled);
1431 if (!status.isOk()) {
1432 ALOGE("setRefreshRateChangedCallbackDebugEnabled failed %s",
1433 status.getDescription().c_str());
1434 return static_cast<Error>(status.getServiceSpecificError());
1435 }
1436 return Error::NONE;
1437}
1438
Ady Abrahame7385f72021-09-05 00:54:25 -07001439Error AidlComposer::getClientTargetProperty(
Alec Mouri85065692022-03-18 00:58:26 +00001440 Display display, ClientTargetPropertyWithBrightness* outClientTargetProperty) {
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -04001441 Error error = Error::NONE;
1442 mMutex.lock_shared();
1443 if (auto reader = getReader(display)) {
1444 *outClientTargetProperty =
1445 reader->get().takeClientTargetProperty(translate<int64_t>(display));
1446 } else {
1447 error = Error::BAD_DISPLAY;
1448 }
1449 mMutex.unlock_shared();
1450 return error;
Ady Abrahame7385f72021-09-05 00:54:25 -07001451}
1452
Alec Mouri6da0e272022-02-07 12:45:57 -08001453Error AidlComposer::setLayerBrightness(Display display, Layer layer, float brightness) {
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -04001454 Error error = Error::NONE;
1455 mMutex.lock_shared();
1456 if (auto writer = getWriter(display)) {
1457 writer->get().setLayerBrightness(translate<int64_t>(display), translate<int64_t>(layer),
1458 brightness);
1459 } else {
1460 error = Error::BAD_DISPLAY;
1461 }
1462 mMutex.unlock_shared();
1463 return error;
Alec Mouricdf6cbc2021-11-01 17:21:15 -07001464}
1465
Leon Scroggins IIId77d3162022-01-05 10:42:28 -05001466Error AidlComposer::setLayerBlockingRegion(Display display, Layer layer,
1467 const std::vector<IComposerClient::Rect>& blocking) {
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -04001468 Error error = Error::NONE;
1469 mMutex.lock_shared();
1470 if (auto writer = getWriter(display)) {
1471 writer->get().setLayerBlockingRegion(translate<int64_t>(display), translate<int64_t>(layer),
1472 translate<AidlRect>(blocking));
1473 } else {
1474 error = Error::BAD_DISPLAY;
1475 }
1476 mMutex.unlock_shared();
1477 return error;
Leon Scroggins IIId77d3162022-01-05 10:42:28 -05001478}
Leon Scroggins IIIe7c51c62022-02-01 15:53:54 -05001479
1480Error AidlComposer::getDisplayDecorationSupport(Display display,
1481 std::optional<DisplayDecorationSupport>* support) {
1482 const auto status =
1483 mAidlComposerClient->getDisplayDecorationSupport(translate<int64_t>(display), support);
1484 if (!status.isOk()) {
1485 ALOGE("getDisplayDecorationSupport failed %s", status.getDescription().c_str());
1486 support->reset();
1487 return static_cast<Error>(status.getServiceSpecificError());
1488 }
1489 return Error::NONE;
1490}
ramindani32cf0602022-03-02 02:30:29 +00001491
1492Error AidlComposer::setIdleTimerEnabled(Display displayId, std::chrono::milliseconds timeout) {
1493 const auto status =
1494 mAidlComposerClient->setIdleTimerEnabled(translate<int64_t>(displayId),
1495 translate<int32_t>(timeout.count()));
1496 if (!status.isOk()) {
1497 ALOGE("setIdleTimerEnabled failed %s", status.getDescription().c_str());
1498 return static_cast<Error>(status.getServiceSpecificError());
1499 }
1500 return Error::NONE;
1501}
1502
ramindani06e518e2022-03-14 18:47:53 +00001503Error AidlComposer::getPhysicalDisplayOrientation(Display displayId,
1504 AidlTransform* outDisplayOrientation) {
1505 const auto status =
1506 mAidlComposerClient->getDisplayPhysicalOrientation(translate<int64_t>(displayId),
1507 outDisplayOrientation);
1508 if (!status.isOk()) {
1509 ALOGE("getPhysicalDisplayOrientation failed %s", status.getDescription().c_str());
1510 return static_cast<Error>(status.getServiceSpecificError());
1511 }
1512 return Error::NONE;
1513}
1514
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -04001515ftl::Optional<std::reference_wrapper<ComposerClientWriter>> AidlComposer::getWriter(Display display)
1516 REQUIRES_SHARED(mMutex) {
1517 return mWriters.get(display);
1518}
1519
1520ftl::Optional<std::reference_wrapper<ComposerClientReader>> AidlComposer::getReader(Display display)
1521 REQUIRES_SHARED(mMutex) {
1522 if (mSingleReader) {
1523 display = translate<Display>(kSingleReaderKey);
1524 }
1525 return mReaders.get(display);
1526}
1527
1528void AidlComposer::removeDisplay(Display display) {
1529 mMutex.lock();
1530 bool wasErased = mWriters.erase(display);
1531 ALOGW_IF(!wasErased,
1532 "Attempting to remove writer for display %" PRId64 " which is not connected",
1533 translate<int64_t>(display));
1534 if (!mSingleReader) {
1535 removeReader(display);
1536 }
1537 mMutex.unlock();
1538}
1539
1540void AidlComposer::onHotplugDisconnect(Display display) {
1541 removeDisplay(display);
1542}
1543
1544bool AidlComposer::hasMultiThreadedPresentSupport(Display display) {
Leon Scroggins IIIc1cf4582023-03-23 18:37:44 -04001545#if 0
1546 // TODO (b/259132483): Reenable
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -04001547 const auto displayId = translate<int64_t>(display);
1548 std::vector<AidlDisplayCapability> capabilities;
1549 const auto status = mAidlComposerClient->getDisplayCapabilities(displayId, &capabilities);
1550 if (!status.isOk()) {
1551 ALOGE("getDisplayCapabilities failed %s", status.getDescription().c_str());
1552 return false;
1553 }
1554 return std::find(capabilities.begin(), capabilities.end(),
1555 AidlDisplayCapability::MULTI_THREADED_PRESENT) != capabilities.end();
Leon Scroggins IIIc1cf4582023-03-23 18:37:44 -04001556#else
1557 (void) display;
1558 return false;
1559#endif
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -04001560}
1561
1562void AidlComposer::addReader(Display display) {
1563 const auto displayId = translate<int64_t>(display);
1564 std::optional<int64_t> displayOpt;
1565 if (displayId != kSingleReaderKey) {
1566 displayOpt.emplace(displayId);
1567 }
1568 auto [it, added] = mReaders.try_emplace(display, std::move(displayOpt));
1569 ALOGW_IF(!added, "Attempting to add writer for display %" PRId64 " which is already connected",
1570 displayId);
1571}
1572
1573void AidlComposer::removeReader(Display display) {
1574 bool wasErased = mReaders.erase(display);
1575 ALOGW_IF(!wasErased,
1576 "Attempting to remove reader for display %" PRId64 " which is not connected",
1577 translate<int64_t>(display));
1578}
1579
1580void AidlComposer::addDisplay(Display display) {
1581 const auto displayId = translate<int64_t>(display);
1582 mMutex.lock();
1583 auto [it, added] = mWriters.try_emplace(display, displayId);
1584 ALOGW_IF(!added, "Attempting to add writer for display %" PRId64 " which is already connected",
1585 displayId);
1586 if (mSingleReader) {
1587 if (hasMultiThreadedPresentSupport(display)) {
1588 mSingleReader = false;
1589 removeReader(translate<Display>(kSingleReaderKey));
1590 // Note that this includes the new display.
1591 for (const auto& [existingDisplay, _] : mWriters) {
1592 addReader(existingDisplay);
1593 }
1594 }
1595 } else {
1596 addReader(display);
1597 }
1598 mMutex.unlock();
1599}
1600
1601void AidlComposer::onHotplugConnect(Display display) {
1602 addDisplay(display);
1603}
Ady Abrahame7385f72021-09-05 00:54:25 -07001604} // namespace Hwc2
1605} // namespace android