blob: f7049b98e73b2c384150bedb34f5a1a8fe974d79 [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 -0400332Error AidlComposer::executeCommands(Display display) {
333 mMutex.lock_shared();
334 auto error = execute(display);
335 mMutex.unlock_shared();
336 return error;
Ady Abrahame7385f72021-09-05 00:54:25 -0700337}
338
339uint32_t AidlComposer::getMaxVirtualDisplayCount() {
340 int32_t count = 0;
341 const auto status = mAidlComposerClient->getMaxVirtualDisplayCount(&count);
342 if (!status.isOk()) {
343 ALOGE("getMaxVirtualDisplayCount failed %s", status.getDescription().c_str());
344 return 0;
345 }
346 return static_cast<uint32_t>(count);
347}
348
349Error AidlComposer::createVirtualDisplay(uint32_t width, uint32_t height, PixelFormat* format,
350 Display* outDisplay) {
351 using AidlPixelFormat = aidl::android::hardware::graphics::common::PixelFormat;
352 const int32_t bufferSlotCount = 1;
353 VirtualDisplay virtualDisplay;
354 const auto status =
355 mAidlComposerClient->createVirtualDisplay(static_cast<int32_t>(width),
356 static_cast<int32_t>(height),
357 static_cast<AidlPixelFormat>(*format),
358 bufferSlotCount, &virtualDisplay);
359
360 if (!status.isOk()) {
361 ALOGE("createVirtualDisplay failed %s", status.getDescription().c_str());
362 return static_cast<Error>(status.getServiceSpecificError());
363 }
364
365 *outDisplay = translate<Display>(virtualDisplay.display);
366 *format = static_cast<PixelFormat>(virtualDisplay.format);
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400367 addDisplay(translate<Display>(virtualDisplay.display));
Ady Abrahame7385f72021-09-05 00:54:25 -0700368 return Error::NONE;
369}
370
371Error AidlComposer::destroyVirtualDisplay(Display display) {
372 const auto status = mAidlComposerClient->destroyVirtualDisplay(translate<int64_t>(display));
373 if (!status.isOk()) {
374 ALOGE("destroyVirtualDisplay failed %s", status.getDescription().c_str());
375 return static_cast<Error>(status.getServiceSpecificError());
376 }
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400377 removeDisplay(display);
Ady Abrahame7385f72021-09-05 00:54:25 -0700378 return Error::NONE;
379}
380
381Error AidlComposer::acceptDisplayChanges(Display display) {
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400382 Error error = Error::NONE;
383 mMutex.lock_shared();
384 if (auto writer = getWriter(display)) {
385 writer->get().acceptDisplayChanges(translate<int64_t>(display));
386 } else {
387 error = Error::BAD_DISPLAY;
388 }
389 mMutex.unlock_shared();
390 return error;
Ady Abrahame7385f72021-09-05 00:54:25 -0700391}
392
393Error AidlComposer::createLayer(Display display, Layer* outLayer) {
394 int64_t layer;
395 const auto status = mAidlComposerClient->createLayer(translate<int64_t>(display),
396 kMaxLayerBufferCount, &layer);
397 if (!status.isOk()) {
398 ALOGE("createLayer failed %s", status.getDescription().c_str());
399 return static_cast<Error>(status.getServiceSpecificError());
400 }
401
402 *outLayer = translate<Layer>(layer);
403 return Error::NONE;
404}
405
406Error AidlComposer::destroyLayer(Display display, Layer layer) {
407 const auto status = mAidlComposerClient->destroyLayer(translate<int64_t>(display),
408 translate<int64_t>(layer));
409 if (!status.isOk()) {
410 ALOGE("destroyLayer failed %s", status.getDescription().c_str());
411 return static_cast<Error>(status.getServiceSpecificError());
412 }
413 return Error::NONE;
414}
415
416Error AidlComposer::getActiveConfig(Display display, Config* outConfig) {
417 int32_t config;
418 const auto status = mAidlComposerClient->getActiveConfig(translate<int64_t>(display), &config);
419 if (!status.isOk()) {
420 ALOGE("getActiveConfig failed %s", status.getDescription().c_str());
421 return static_cast<Error>(status.getServiceSpecificError());
422 }
423 *outConfig = translate<Config>(config);
424 return Error::NONE;
425}
426
427Error AidlComposer::getChangedCompositionTypes(
428 Display display, std::vector<Layer>* outLayers,
Leon Scroggins III2e1aa182021-12-01 17:33:12 -0500429 std::vector<aidl::android::hardware::graphics::composer3::Composition>* outTypes) {
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400430 std::vector<ChangedCompositionLayer> changedLayers;
431 Error error = Error::NONE;
432 {
433 mMutex.lock_shared();
434 if (auto reader = getReader(display)) {
435 changedLayers = reader->get().takeChangedCompositionTypes(translate<int64_t>(display));
436 } else {
437 error = Error::BAD_DISPLAY;
438 }
439 mMutex.unlock_shared();
440 }
Ady Abrahamde792782021-12-20 10:00:49 -0800441 outLayers->reserve(changedLayers.size());
442 outTypes->reserve(changedLayers.size());
Ady Abrahama6388c02021-11-11 21:11:51 -0800443
Ady Abrahamde792782021-12-20 10:00:49 -0800444 for (const auto& layer : changedLayers) {
445 outLayers->emplace_back(translate<Layer>(layer.layer));
446 outTypes->emplace_back(layer.composition);
447 }
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400448 return error;
Ady Abrahame7385f72021-09-05 00:54:25 -0700449}
450
451Error AidlComposer::getColorModes(Display display, std::vector<ColorMode>* outModes) {
452 std::vector<AidlColorMode> modes;
453 const auto status = mAidlComposerClient->getColorModes(translate<int64_t>(display), &modes);
454 if (!status.isOk()) {
455 ALOGE("getColorModes failed %s", status.getDescription().c_str());
456 return static_cast<Error>(status.getServiceSpecificError());
457 }
458 *outModes = translate<ColorMode>(modes);
459 return Error::NONE;
460}
461
462Error AidlComposer::getDisplayAttribute(Display display, Config config,
463 IComposerClient::Attribute attribute, int32_t* outValue) {
464 const auto status =
465 mAidlComposerClient->getDisplayAttribute(translate<int64_t>(display),
466 translate<int32_t>(config),
467 static_cast<AidlDisplayAttribute>(attribute),
468 outValue);
469 if (!status.isOk()) {
470 ALOGE("getDisplayAttribute failed %s", status.getDescription().c_str());
471 return static_cast<Error>(status.getServiceSpecificError());
472 }
473 return Error::NONE;
474}
475
476Error AidlComposer::getDisplayConfigs(Display display, std::vector<Config>* outConfigs) {
477 std::vector<int32_t> configs;
478 const auto status =
479 mAidlComposerClient->getDisplayConfigs(translate<int64_t>(display), &configs);
480 if (!status.isOk()) {
481 ALOGE("getDisplayConfigs failed %s", status.getDescription().c_str());
482 return static_cast<Error>(status.getServiceSpecificError());
483 }
484 *outConfigs = translate<Config>(configs);
485 return Error::NONE;
486}
487
488Error AidlComposer::getDisplayName(Display display, std::string* outName) {
489 const auto status = mAidlComposerClient->getDisplayName(translate<int64_t>(display), outName);
490 if (!status.isOk()) {
491 ALOGE("getDisplayName failed %s", status.getDescription().c_str());
492 return static_cast<Error>(status.getServiceSpecificError());
493 }
494 return Error::NONE;
495}
496
497Error AidlComposer::getDisplayRequests(Display display, uint32_t* outDisplayRequestMask,
498 std::vector<Layer>* outLayers,
499 std::vector<uint32_t>* outLayerRequestMasks) {
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400500 Error error = Error::NONE;
501 DisplayRequest displayRequests;
502 {
503 mMutex.lock_shared();
504 if (auto reader = getReader(display)) {
505 displayRequests = reader->get().takeDisplayRequests(translate<int64_t>(display));
506 } else {
507 error = Error::BAD_DISPLAY;
508 }
509 mMutex.unlock_shared();
510 }
Ady Abrahamde792782021-12-20 10:00:49 -0800511 *outDisplayRequestMask = translate<uint32_t>(displayRequests.mask);
512 outLayers->reserve(displayRequests.layerRequests.size());
513 outLayerRequestMasks->reserve(displayRequests.layerRequests.size());
514
515 for (const auto& layer : displayRequests.layerRequests) {
516 outLayers->emplace_back(translate<Layer>(layer.layer));
517 outLayerRequestMasks->emplace_back(translate<uint32_t>(layer.mask));
518 }
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400519 return error;
Ady Abrahame7385f72021-09-05 00:54:25 -0700520}
521
522Error AidlComposer::getDozeSupport(Display display, bool* outSupport) {
Ady Abraham33b92b92021-12-08 18:30:27 -0800523 std::vector<AidlDisplayCapability> capabilities;
Ady Abrahame7385f72021-09-05 00:54:25 -0700524 const auto status =
Ady Abraham33b92b92021-12-08 18:30:27 -0800525 mAidlComposerClient->getDisplayCapabilities(translate<int64_t>(display), &capabilities);
Ady Abrahame7385f72021-09-05 00:54:25 -0700526 if (!status.isOk()) {
Ady Abraham33b92b92021-12-08 18:30:27 -0800527 ALOGE("getDisplayCapabilities failed %s", status.getDescription().c_str());
Ady Abrahame7385f72021-09-05 00:54:25 -0700528 return static_cast<Error>(status.getServiceSpecificError());
529 }
Ady Abraham33b92b92021-12-08 18:30:27 -0800530 *outSupport = std::find(capabilities.begin(), capabilities.end(),
531 AidlDisplayCapability::DOZE) != capabilities.end();
Ady Abrahame7385f72021-09-05 00:54:25 -0700532 return Error::NONE;
533}
534
ramindani32cf0602022-03-02 02:30:29 +0000535Error AidlComposer::hasDisplayIdleTimerCapability(Display display, bool* outSupport) {
536 std::vector<AidlDisplayCapability> capabilities;
537 const auto status =
538 mAidlComposerClient->getDisplayCapabilities(translate<int64_t>(display), &capabilities);
539 if (!status.isOk()) {
540 ALOGE("getDisplayCapabilities failed %s", status.getDescription().c_str());
541 return static_cast<Error>(status.getServiceSpecificError());
542 }
543 *outSupport = std::find(capabilities.begin(), capabilities.end(),
544 AidlDisplayCapability::DISPLAY_IDLE_TIMER) != capabilities.end();
545 return Error::NONE;
546}
547
Ady Abrahame7385f72021-09-05 00:54:25 -0700548Error AidlComposer::getHdrCapabilities(Display display, std::vector<Hdr>* outTypes,
549 float* outMaxLuminance, float* outMaxAverageLuminance,
550 float* outMinLuminance) {
551 AidlHdrCapabilities capabilities;
552 const auto status =
553 mAidlComposerClient->getHdrCapabilities(translate<int64_t>(display), &capabilities);
554 if (!status.isOk()) {
555 ALOGE("getHdrCapabilities failed %s", status.getDescription().c_str());
556 return static_cast<Error>(status.getServiceSpecificError());
557 }
558
Marc Kassisbdf7e4b2022-11-04 17:26:48 +0100559 *outTypes = capabilities.types;
Ady Abrahame7385f72021-09-05 00:54:25 -0700560 *outMaxLuminance = capabilities.maxLuminance;
561 *outMaxAverageLuminance = capabilities.maxAverageLuminance;
562 *outMinLuminance = capabilities.minLuminance;
563 return Error::NONE;
564}
565
Sally Qibb866c12022-10-17 11:31:20 -0700566Error AidlComposer::getOverlaySupport(AidlOverlayProperties* outProperties) {
567 const auto status = mAidlComposerClient->getOverlaySupport(outProperties);
568 if (!status.isOk()) {
569 ALOGE("getOverlaySupport failed %s", status.getDescription().c_str());
570 return static_cast<Error>(status.getServiceSpecificError());
571 }
Sally Qi0cbd08b2022-08-17 12:12:28 -0700572 return Error::NONE;
573}
574
Ady Abrahame7385f72021-09-05 00:54:25 -0700575Error AidlComposer::getReleaseFences(Display display, std::vector<Layer>* outLayers,
576 std::vector<int>* outReleaseFences) {
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400577 Error error = Error::NONE;
578 std::vector<ReleaseFences::Layer> fences;
579 {
580 mMutex.lock_shared();
581 if (auto reader = getReader(display)) {
582 fences = reader->get().takeReleaseFences(translate<int64_t>(display));
583 } else {
584 error = Error::BAD_DISPLAY;
585 }
586 mMutex.unlock_shared();
587 }
Ady Abrahamde792782021-12-20 10:00:49 -0800588 outLayers->reserve(fences.size());
589 outReleaseFences->reserve(fences.size());
590
591 for (auto& fence : fences) {
592 outLayers->emplace_back(translate<Layer>(fence.layer));
593 // take ownership
594 const int fenceOwner = fence.fence.get();
595 *fence.fence.getR() = -1;
596 outReleaseFences->emplace_back(fenceOwner);
597 }
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400598 return error;
Ady Abrahame7385f72021-09-05 00:54:25 -0700599}
600
601Error AidlComposer::presentDisplay(Display display, int* outPresentFence) {
Leon Scroggins IIIe85e16e2022-12-12 12:51:18 -0500602 const auto displayId = translate<int64_t>(display);
603 ATRACE_FORMAT("HwcPresentDisplay %" PRId64, displayId);
604
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400605 Error error = Error::NONE;
606 mMutex.lock_shared();
607 auto writer = getWriter(display);
608 auto reader = getReader(display);
609 if (writer && reader) {
Leon Scroggins IIIe85e16e2022-12-12 12:51:18 -0500610 writer->get().presentDisplay(displayId);
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400611 error = execute(display);
612 } else {
613 error = Error::BAD_DISPLAY;
614 }
Ady Abrahame7385f72021-09-05 00:54:25 -0700615
Ady Abrahame7385f72021-09-05 00:54:25 -0700616 if (error != Error::NONE) {
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400617 mMutex.unlock_shared();
Ady Abrahame7385f72021-09-05 00:54:25 -0700618 return error;
619 }
620
Leon Scroggins IIIe85e16e2022-12-12 12:51:18 -0500621 auto fence = reader->get().takePresentFence(displayId);
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400622 mMutex.unlock_shared();
Ady Abrahamde792782021-12-20 10:00:49 -0800623 // take ownership
624 *outPresentFence = fence.get();
625 *fence.getR() = -1;
Ady Abrahame7385f72021-09-05 00:54:25 -0700626 return Error::NONE;
627}
628
629Error AidlComposer::setActiveConfig(Display display, Config config) {
630 const auto status = mAidlComposerClient->setActiveConfig(translate<int64_t>(display),
631 translate<int32_t>(config));
632 if (!status.isOk()) {
633 ALOGE("setActiveConfig failed %s", status.getDescription().c_str());
634 return static_cast<Error>(status.getServiceSpecificError());
635 }
636 return Error::NONE;
637}
638
639Error AidlComposer::setClientTarget(Display display, uint32_t slot, const sp<GraphicBuffer>& target,
640 int acquireFence, Dataspace dataspace,
641 const std::vector<IComposerClient::Rect>& damage) {
Ady Abrahame7385f72021-09-05 00:54:25 -0700642 const native_handle_t* handle = nullptr;
643 if (target.get()) {
644 handle = target->getNativeBuffer()->handle;
645 }
646
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400647 Error error = Error::NONE;
648 mMutex.lock_shared();
649 if (auto writer = getWriter(display)) {
650 writer->get()
651 .setClientTarget(translate<int64_t>(display), slot, handle, acquireFence,
652 translate<aidl::android::hardware::graphics::common::Dataspace>(
653 dataspace),
654 translate<AidlRect>(damage));
655 } else {
656 error = Error::BAD_DISPLAY;
657 }
658 mMutex.unlock_shared();
659 return error;
Ady Abrahame7385f72021-09-05 00:54:25 -0700660}
661
662Error AidlComposer::setColorMode(Display display, ColorMode mode, RenderIntent renderIntent) {
663 const auto status =
664 mAidlComposerClient->setColorMode(translate<int64_t>(display),
665 translate<AidlColorMode>(mode),
666 translate<AidlRenderIntent>(renderIntent));
667 if (!status.isOk()) {
668 ALOGE("setColorMode failed %s", status.getDescription().c_str());
669 return static_cast<Error>(status.getServiceSpecificError());
670 }
671 return Error::NONE;
672}
673
Ady Abrahamdc011a92021-12-21 14:06:44 -0800674Error AidlComposer::setColorTransform(Display display, const float* matrix) {
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400675 auto error = Error::NONE;
676 mMutex.lock_shared();
677 if (auto writer = getWriter(display)) {
678 writer->get().setColorTransform(translate<int64_t>(display), matrix);
679 } else {
680 error = Error::BAD_DISPLAY;
681 }
682 mMutex.unlock_shared();
683 return error;
Ady Abrahame7385f72021-09-05 00:54:25 -0700684}
685
686Error AidlComposer::setOutputBuffer(Display display, const native_handle_t* buffer,
687 int releaseFence) {
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400688 auto error = Error::NONE;
689 mMutex.lock_shared();
690 if (auto writer = getWriter(display)) {
691 writer->get().setOutputBuffer(translate<int64_t>(display), 0, buffer, dup(releaseFence));
692 } else {
693 error = Error::BAD_DISPLAY;
694 }
695 mMutex.unlock_shared();
696 return error;
Ady Abrahame7385f72021-09-05 00:54:25 -0700697}
698
699Error AidlComposer::setPowerMode(Display display, IComposerClient::PowerMode mode) {
700 const auto status = mAidlComposerClient->setPowerMode(translate<int64_t>(display),
701 translate<PowerMode>(mode));
702 if (!status.isOk()) {
703 ALOGE("setPowerMode failed %s", status.getDescription().c_str());
704 return static_cast<Error>(status.getServiceSpecificError());
705 }
706 return Error::NONE;
707}
708
709Error AidlComposer::setVsyncEnabled(Display display, IComposerClient::Vsync enabled) {
710 const bool enableVsync = enabled == IComposerClient::Vsync::ENABLE;
711 const auto status =
712 mAidlComposerClient->setVsyncEnabled(translate<int64_t>(display), enableVsync);
713 if (!status.isOk()) {
714 ALOGE("setVsyncEnabled failed %s", status.getDescription().c_str());
715 return static_cast<Error>(status.getServiceSpecificError());
716 }
717 return Error::NONE;
718}
719
720Error AidlComposer::setClientTargetSlotCount(Display display) {
721 const int32_t bufferSlotCount = BufferQueue::NUM_BUFFER_SLOTS;
722 const auto status = mAidlComposerClient->setClientTargetSlotCount(translate<int64_t>(display),
723 bufferSlotCount);
724 if (!status.isOk()) {
725 ALOGE("setClientTargetSlotCount failed %s", status.getDescription().c_str());
726 return static_cast<Error>(status.getServiceSpecificError());
727 }
728 return Error::NONE;
729}
730
Ady Abraham43065bd2021-12-10 17:22:15 -0800731Error AidlComposer::validateDisplay(Display display, nsecs_t expectedPresentTime,
732 uint32_t* outNumTypes, uint32_t* outNumRequests) {
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400733 const auto displayId = translate<int64_t>(display);
Leon Scroggins IIIe85e16e2022-12-12 12:51:18 -0500734 ATRACE_FORMAT("HwcValidateDisplay %" PRId64, displayId);
735
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400736 Error error = Error::NONE;
737 mMutex.lock_shared();
738 auto writer = getWriter(display);
739 auto reader = getReader(display);
740 if (writer && reader) {
741 writer->get().validateDisplay(displayId, ClockMonotonicTimestamp{expectedPresentTime});
742 error = execute(display);
743 } else {
744 error = Error::BAD_DISPLAY;
745 }
Ady Abrahame7385f72021-09-05 00:54:25 -0700746
Ady Abrahame7385f72021-09-05 00:54:25 -0700747 if (error != Error::NONE) {
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400748 mMutex.unlock_shared();
Ady Abrahame7385f72021-09-05 00:54:25 -0700749 return error;
750 }
751
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400752 reader->get().hasChanges(displayId, outNumTypes, outNumRequests);
Ady Abrahame7385f72021-09-05 00:54:25 -0700753
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400754 mMutex.unlock_shared();
Ady Abrahame7385f72021-09-05 00:54:25 -0700755 return Error::NONE;
756}
757
Ady Abraham43065bd2021-12-10 17:22:15 -0800758Error AidlComposer::presentOrValidateDisplay(Display display, nsecs_t expectedPresentTime,
759 uint32_t* outNumTypes, uint32_t* outNumRequests,
760 int* outPresentFence, uint32_t* state) {
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400761 const auto displayId = translate<int64_t>(display);
Leon Scroggins IIIe85e16e2022-12-12 12:51:18 -0500762 ATRACE_FORMAT("HwcPresentOrValidateDisplay %" PRId64, displayId);
763
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400764 Error error = Error::NONE;
765 mMutex.lock_shared();
766 auto writer = getWriter(display);
767 auto reader = getReader(display);
768 if (writer && reader) {
769 writer->get().presentOrvalidateDisplay(displayId,
770 ClockMonotonicTimestamp{expectedPresentTime});
771 error = execute(display);
772 } else {
773 error = Error::BAD_DISPLAY;
774 }
Ady Abrahame7385f72021-09-05 00:54:25 -0700775
Ady Abrahame7385f72021-09-05 00:54:25 -0700776 if (error != Error::NONE) {
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400777 mMutex.unlock_shared();
Ady Abrahame7385f72021-09-05 00:54:25 -0700778 return error;
779 }
780
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400781 const auto result = reader->get().takePresentOrValidateStage(displayId);
Ady Abrahamde792782021-12-20 10:00:49 -0800782 if (!result.has_value()) {
783 *state = translate<uint32_t>(-1);
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400784 mMutex.unlock_shared();
Ady Abrahamde792782021-12-20 10:00:49 -0800785 return Error::NO_RESOURCES;
Ady Abrahame7385f72021-09-05 00:54:25 -0700786 }
787
Ady Abrahamde792782021-12-20 10:00:49 -0800788 *state = translate<uint32_t>(*result);
789
790 if (*result == PresentOrValidate::Result::Presented) {
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400791 auto fence = reader->get().takePresentFence(displayId);
Ady Abrahamde792782021-12-20 10:00:49 -0800792 // take ownership
793 *outPresentFence = fence.get();
794 *fence.getR() = -1;
795 }
796
797 if (*result == PresentOrValidate::Result::Validated) {
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400798 reader->get().hasChanges(displayId, outNumTypes, outNumRequests);
Ady Abrahame7385f72021-09-05 00:54:25 -0700799 }
800
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400801 mMutex.unlock_shared();
Ady Abrahame7385f72021-09-05 00:54:25 -0700802 return Error::NONE;
803}
804
805Error AidlComposer::setCursorPosition(Display display, Layer layer, int32_t x, int32_t y) {
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400806 Error error = Error::NONE;
807 mMutex.lock_shared();
808 if (auto writer = getWriter(display)) {
809 writer->get().setLayerCursorPosition(translate<int64_t>(display), translate<int64_t>(layer),
810 x, y);
811 } else {
812 error = Error::BAD_DISPLAY;
813 }
814 mMutex.unlock_shared();
815 return error;
Ady Abrahame7385f72021-09-05 00:54:25 -0700816}
817
818Error AidlComposer::setLayerBuffer(Display display, Layer layer, uint32_t slot,
819 const sp<GraphicBuffer>& buffer, int acquireFence) {
Ady Abrahame7385f72021-09-05 00:54:25 -0700820 const native_handle_t* handle = nullptr;
821 if (buffer.get()) {
822 handle = buffer->getNativeBuffer()->handle;
823 }
824
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400825 Error error = Error::NONE;
826 mMutex.lock_shared();
827 if (auto writer = getWriter(display)) {
828 writer->get().setLayerBuffer(translate<int64_t>(display), translate<int64_t>(layer), slot,
829 handle, acquireFence);
830 } else {
831 error = Error::BAD_DISPLAY;
832 }
833 mMutex.unlock_shared();
834 return error;
Ady Abrahame7385f72021-09-05 00:54:25 -0700835}
836
Brian Lindahlb158a5c2022-12-15 15:21:13 -0700837Error AidlComposer::setLayerBufferSlotsToClear(Display display, Layer layer,
838 const std::vector<uint32_t>& slotsToClear,
839 uint32_t activeBufferSlot) {
840 if (slotsToClear.empty()) {
841 return Error::NONE;
842 }
843
Brian Lindahl90553da2022-12-06 13:36:30 -0700844 Error error = Error::NONE;
845 mMutex.lock_shared();
846 if (auto writer = getWriter(display)) {
Brian Lindahldbf7e3a2022-12-16 11:43:39 -0700847 // Backwards compatible way of clearing buffer is to set the layer buffer with a placeholder
848 // buffer, using the slot that needs to cleared... tricky.
849 if (mClearSlotBuffer == nullptr) {
850 writer->get().setLayerBufferSlotsToClear(translate<int64_t>(display),
851 translate<int64_t>(layer), slotsToClear);
852 } else {
853 for (uint32_t slot : slotsToClear) {
854 // Don't clear the active buffer slot because we need to restore the active buffer
855 // after clearing the requested buffer slots with a placeholder buffer.
856 if (slot != activeBufferSlot) {
857 writer->get().setLayerBufferWithNewCommand(translate<int64_t>(display),
858 translate<int64_t>(layer), slot,
859 mClearSlotBuffer->handle,
860 /*fence*/ -1);
861 }
Brian Lindahlb158a5c2022-12-15 15:21:13 -0700862 }
Brian Lindahldbf7e3a2022-12-16 11:43:39 -0700863 // Since we clear buffers by setting them to a placeholder buffer, we want to make
864 // sure that the last setLayerBuffer command is sent with the currently active
865 // buffer, not the placeholder buffer, so that there is no perceptual change when
866 // buffers are discarded.
867 writer->get().setLayerBufferWithNewCommand(translate<int64_t>(display),
868 translate<int64_t>(layer), activeBufferSlot,
869 // The active buffer is still cached in
870 // its slot and doesn't need a fence.
871 /*buffer*/ nullptr, /*fence*/ -1);
Brian Lindahlb158a5c2022-12-15 15:21:13 -0700872 }
Brian Lindahl90553da2022-12-06 13:36:30 -0700873 } else {
874 error = Error::BAD_DISPLAY;
875 }
876 mMutex.unlock_shared();
877 return error;
878}
879
Ady Abrahame7385f72021-09-05 00:54:25 -0700880Error AidlComposer::setLayerSurfaceDamage(Display display, Layer layer,
881 const std::vector<IComposerClient::Rect>& damage) {
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400882 Error error = Error::NONE;
883 mMutex.lock_shared();
884 if (auto writer = getWriter(display)) {
885 writer->get().setLayerSurfaceDamage(translate<int64_t>(display), translate<int64_t>(layer),
886 translate<AidlRect>(damage));
887 } else {
888 error = Error::BAD_DISPLAY;
889 }
890 mMutex.unlock_shared();
891 return error;
Ady Abrahame7385f72021-09-05 00:54:25 -0700892}
893
894Error AidlComposer::setLayerBlendMode(Display display, Layer layer,
895 IComposerClient::BlendMode mode) {
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400896 Error error = Error::NONE;
897 mMutex.lock_shared();
898 if (auto writer = getWriter(display)) {
899 writer->get().setLayerBlendMode(translate<int64_t>(display), translate<int64_t>(layer),
900 translate<BlendMode>(mode));
901 } else {
902 error = Error::BAD_DISPLAY;
903 }
904 mMutex.unlock_shared();
905 return error;
Ady Abrahame7385f72021-09-05 00:54:25 -0700906}
907
Ady Abraham6e60b142022-01-06 18:10:35 -0800908Error AidlComposer::setLayerColor(Display display, Layer layer, const Color& color) {
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400909 Error error = Error::NONE;
910 mMutex.lock_shared();
911 if (auto writer = getWriter(display)) {
912 writer->get().setLayerColor(translate<int64_t>(display), translate<int64_t>(layer), color);
913 } else {
914 error = Error::BAD_DISPLAY;
915 }
916 mMutex.unlock_shared();
917 return error;
Ady Abrahame7385f72021-09-05 00:54:25 -0700918}
919
Leon Scroggins III2e1aa182021-12-01 17:33:12 -0500920Error AidlComposer::setLayerCompositionType(
921 Display display, Layer layer,
922 aidl::android::hardware::graphics::composer3::Composition type) {
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400923 Error error = Error::NONE;
924 mMutex.lock_shared();
925 if (auto writer = getWriter(display)) {
926 writer->get().setLayerCompositionType(translate<int64_t>(display),
927 translate<int64_t>(layer), type);
928 } else {
929 error = Error::BAD_DISPLAY;
930 }
931 mMutex.unlock_shared();
932 return error;
Ady Abrahame7385f72021-09-05 00:54:25 -0700933}
934
935Error AidlComposer::setLayerDataspace(Display display, Layer layer, Dataspace dataspace) {
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400936 Error error = Error::NONE;
937 mMutex.lock_shared();
938 if (auto writer = getWriter(display)) {
939 writer->get().setLayerDataspace(translate<int64_t>(display), translate<int64_t>(layer),
940 translate<AidlDataspace>(dataspace));
941 } else {
942 error = Error::BAD_DISPLAY;
943 }
944 mMutex.unlock_shared();
945 return error;
Ady Abrahame7385f72021-09-05 00:54:25 -0700946}
947
948Error AidlComposer::setLayerDisplayFrame(Display display, Layer layer,
949 const IComposerClient::Rect& frame) {
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400950 Error error = Error::NONE;
951 mMutex.lock_shared();
952 if (auto writer = getWriter(display)) {
953 writer->get().setLayerDisplayFrame(translate<int64_t>(display), translate<int64_t>(layer),
954 translate<AidlRect>(frame));
955 } else {
956 error = Error::BAD_DISPLAY;
957 }
958 mMutex.unlock_shared();
959 return error;
Ady Abrahame7385f72021-09-05 00:54:25 -0700960}
961
962Error AidlComposer::setLayerPlaneAlpha(Display display, Layer layer, float alpha) {
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400963 Error error = Error::NONE;
964 mMutex.lock_shared();
965 if (auto writer = getWriter(display)) {
966 writer->get().setLayerPlaneAlpha(translate<int64_t>(display), translate<int64_t>(layer),
967 alpha);
968 } else {
969 error = Error::BAD_DISPLAY;
970 }
971 mMutex.unlock_shared();
972 return error;
Ady Abrahame7385f72021-09-05 00:54:25 -0700973}
974
975Error AidlComposer::setLayerSidebandStream(Display display, Layer layer,
976 const native_handle_t* stream) {
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400977 Error error = Error::NONE;
978 mMutex.lock_shared();
979 if (auto writer = getWriter(display)) {
980 writer->get().setLayerSidebandStream(translate<int64_t>(display), translate<int64_t>(layer),
981 stream);
982 } else {
983 error = Error::BAD_DISPLAY;
984 }
985 mMutex.unlock_shared();
986 return error;
Ady Abrahame7385f72021-09-05 00:54:25 -0700987}
988
989Error AidlComposer::setLayerSourceCrop(Display display, Layer layer,
990 const IComposerClient::FRect& crop) {
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400991 Error error = Error::NONE;
992 mMutex.lock_shared();
993 if (auto writer = getWriter(display)) {
994 writer->get().setLayerSourceCrop(translate<int64_t>(display), translate<int64_t>(layer),
995 translate<AidlFRect>(crop));
996 } else {
997 error = Error::BAD_DISPLAY;
998 }
999 mMutex.unlock_shared();
1000 return error;
Ady Abrahame7385f72021-09-05 00:54:25 -07001001}
1002
1003Error AidlComposer::setLayerTransform(Display display, Layer layer, Transform transform) {
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -04001004 Error error = Error::NONE;
1005 mMutex.lock_shared();
1006 if (auto writer = getWriter(display)) {
1007 writer->get().setLayerTransform(translate<int64_t>(display), translate<int64_t>(layer),
1008 translate<AidlTransform>(transform));
1009 } else {
1010 error = Error::BAD_DISPLAY;
1011 }
1012 mMutex.unlock_shared();
1013 return error;
Ady Abrahame7385f72021-09-05 00:54:25 -07001014}
1015
1016Error AidlComposer::setLayerVisibleRegion(Display display, Layer layer,
1017 const std::vector<IComposerClient::Rect>& visible) {
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -04001018 Error error = Error::NONE;
1019 mMutex.lock_shared();
1020 if (auto writer = getWriter(display)) {
1021 writer->get().setLayerVisibleRegion(translate<int64_t>(display), translate<int64_t>(layer),
1022 translate<AidlRect>(visible));
1023 } else {
1024 error = Error::BAD_DISPLAY;
1025 }
1026 mMutex.unlock_shared();
1027 return error;
Ady Abrahame7385f72021-09-05 00:54:25 -07001028}
1029
1030Error AidlComposer::setLayerZOrder(Display display, Layer layer, uint32_t z) {
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -04001031 Error error = Error::NONE;
1032 mMutex.lock_shared();
1033 if (auto writer = getWriter(display)) {
1034 writer->get().setLayerZOrder(translate<int64_t>(display), translate<int64_t>(layer), z);
1035 } else {
1036 error = Error::BAD_DISPLAY;
1037 }
1038 mMutex.unlock_shared();
1039 return error;
Ady Abrahame7385f72021-09-05 00:54:25 -07001040}
1041
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -04001042Error AidlComposer::execute(Display display) {
1043 auto writer = getWriter(display);
1044 auto reader = getReader(display);
1045 if (!writer || !reader) {
1046 return Error::BAD_DISPLAY;
1047 }
1048
Huihong Luoe7382c12023-04-21 20:24:32 +00001049 auto commands = writer->get().takePendingCommands();
Ady Abrahama6388c02021-11-11 21:11:51 -08001050 if (commands.empty()) {
Ady Abrahame7385f72021-09-05 00:54:25 -07001051 return Error::NONE;
1052 }
1053
Ady Abrahamde792782021-12-20 10:00:49 -08001054 { // scope for results
1055 std::vector<CommandResultPayload> results;
1056 auto status = mAidlComposerClient->executeCommands(commands, &results);
1057 if (!status.isOk()) {
1058 ALOGE("executeCommands failed %s", status.getDescription().c_str());
1059 return static_cast<Error>(status.getServiceSpecificError());
1060 }
Ady Abrahame7385f72021-09-05 00:54:25 -07001061
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -04001062 reader->get().parse(std::move(results));
Ady Abrahamde792782021-12-20 10:00:49 -08001063 }
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -04001064 const auto commandErrors = reader->get().takeErrors();
Ady Abrahama6388c02021-11-11 21:11:51 -08001065 Error error = Error::NONE;
1066 for (const auto& cmdErr : commandErrors) {
1067 const auto index = static_cast<size_t>(cmdErr.commandIndex);
1068 if (index < 0 || index >= commands.size()) {
1069 ALOGE("invalid command index %zu", index);
1070 return Error::BAD_PARAMETER;
Ady Abrahame7385f72021-09-05 00:54:25 -07001071 }
1072
Ady Abrahama6388c02021-11-11 21:11:51 -08001073 const auto& command = commands[index];
Ady Abraham42977362021-12-07 21:04:49 -08001074 if (command.validateDisplay || command.presentDisplay || command.presentOrValidateDisplay) {
1075 error = translate<Error>(cmdErr.errorCode);
1076 } else {
1077 ALOGW("command '%s' generated error %" PRId32, command.toString().c_str(),
1078 cmdErr.errorCode);
Ady Abrahame7385f72021-09-05 00:54:25 -07001079 }
1080 }
1081
Ady Abrahame7385f72021-09-05 00:54:25 -07001082 return error;
1083}
1084
1085Error AidlComposer::setLayerPerFrameMetadata(
1086 Display display, Layer layer,
1087 const std::vector<IComposerClient::PerFrameMetadata>& perFrameMetadatas) {
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -04001088 Error error = Error::NONE;
1089 mMutex.lock_shared();
1090 if (auto writer = getWriter(display)) {
1091 writer->get().setLayerPerFrameMetadata(translate<int64_t>(display),
1092 translate<int64_t>(layer),
1093 translate<AidlPerFrameMetadata>(perFrameMetadatas));
1094 } else {
1095 error = Error::BAD_DISPLAY;
1096 }
1097 mMutex.unlock_shared();
1098 return error;
Ady Abrahame7385f72021-09-05 00:54:25 -07001099}
1100
1101std::vector<IComposerClient::PerFrameMetadataKey> AidlComposer::getPerFrameMetadataKeys(
1102 Display display) {
1103 std::vector<AidlPerFrameMetadataKey> keys;
1104 const auto status =
1105 mAidlComposerClient->getPerFrameMetadataKeys(translate<int64_t>(display), &keys);
1106 if (!status.isOk()) {
1107 ALOGE("getPerFrameMetadataKeys failed %s", status.getDescription().c_str());
1108 return {};
1109 }
1110 return translate<IComposerClient::PerFrameMetadataKey>(keys);
1111}
1112
1113Error AidlComposer::getRenderIntents(Display display, ColorMode colorMode,
1114 std::vector<RenderIntent>* outRenderIntents) {
1115 std::vector<AidlRenderIntent> renderIntents;
1116 const auto status = mAidlComposerClient->getRenderIntents(translate<int64_t>(display),
1117 translate<AidlColorMode>(colorMode),
1118 &renderIntents);
1119 if (!status.isOk()) {
1120 ALOGE("getRenderIntents failed %s", status.getDescription().c_str());
1121 return static_cast<Error>(status.getServiceSpecificError());
1122 }
1123 *outRenderIntents = translate<RenderIntent>(renderIntents);
1124 return Error::NONE;
1125}
1126
1127Error AidlComposer::getDataspaceSaturationMatrix(Dataspace dataspace, mat4* outMatrix) {
1128 std::vector<float> matrix;
1129 const auto status =
1130 mAidlComposerClient->getDataspaceSaturationMatrix(translate<AidlDataspace>(dataspace),
1131 &matrix);
1132 if (!status.isOk()) {
1133 ALOGE("getDataspaceSaturationMatrix failed %s", status.getDescription().c_str());
1134 return static_cast<Error>(status.getServiceSpecificError());
1135 }
1136 *outMatrix = makeMat4(matrix);
1137 return Error::NONE;
1138}
1139
1140Error AidlComposer::getDisplayIdentificationData(Display display, uint8_t* outPort,
1141 std::vector<uint8_t>* outData) {
1142 AidlDisplayIdentification displayIdentification;
1143 const auto status =
1144 mAidlComposerClient->getDisplayIdentificationData(translate<int64_t>(display),
1145 &displayIdentification);
1146 if (!status.isOk()) {
1147 ALOGE("getDisplayIdentificationData failed %s", status.getDescription().c_str());
1148 return static_cast<Error>(status.getServiceSpecificError());
1149 }
1150
1151 *outPort = static_cast<uint8_t>(displayIdentification.port);
1152 *outData = displayIdentification.data;
1153
1154 return Error::NONE;
1155}
1156
1157Error AidlComposer::setLayerColorTransform(Display display, Layer layer, const float* matrix) {
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -04001158 Error error = Error::NONE;
1159 mMutex.lock_shared();
1160 if (auto writer = getWriter(display)) {
1161 writer->get().setLayerColorTransform(translate<int64_t>(display), translate<int64_t>(layer),
1162 matrix);
1163 } else {
1164 error = Error::BAD_DISPLAY;
1165 }
1166 mMutex.unlock_shared();
1167 return error;
Ady Abrahame7385f72021-09-05 00:54:25 -07001168}
1169
1170Error AidlComposer::getDisplayedContentSamplingAttributes(Display display, PixelFormat* outFormat,
1171 Dataspace* outDataspace,
1172 uint8_t* outComponentMask) {
1173 if (!outFormat || !outDataspace || !outComponentMask) {
1174 return Error::BAD_PARAMETER;
1175 }
1176
1177 AidlDisplayContentSamplingAttributes attributes;
1178 const auto status =
1179 mAidlComposerClient->getDisplayedContentSamplingAttributes(translate<int64_t>(display),
1180 &attributes);
1181 if (!status.isOk()) {
1182 ALOGE("getDisplayedContentSamplingAttributes failed %s", status.getDescription().c_str());
1183 return static_cast<Error>(status.getServiceSpecificError());
1184 }
1185
1186 *outFormat = translate<PixelFormat>(attributes.format);
1187 *outDataspace = translate<Dataspace>(attributes.dataspace);
1188 *outComponentMask = static_cast<uint8_t>(attributes.componentMask);
1189 return Error::NONE;
1190}
1191
1192Error AidlComposer::setDisplayContentSamplingEnabled(Display display, bool enabled,
1193 uint8_t componentMask, uint64_t maxFrames) {
1194 const auto status =
1195 mAidlComposerClient
1196 ->setDisplayedContentSamplingEnabled(translate<int64_t>(display), enabled,
1197 static_cast<AidlFormatColorComponent>(
1198 componentMask),
1199 static_cast<int64_t>(maxFrames));
1200 if (!status.isOk()) {
1201 ALOGE("setDisplayedContentSamplingEnabled failed %s", status.getDescription().c_str());
1202 return static_cast<Error>(status.getServiceSpecificError());
1203 }
1204 return Error::NONE;
1205}
1206
1207Error AidlComposer::getDisplayedContentSample(Display display, uint64_t maxFrames,
1208 uint64_t timestamp, DisplayedFrameStats* outStats) {
1209 if (!outStats) {
1210 return Error::BAD_PARAMETER;
1211 }
1212
1213 AidlDisplayContentSample sample;
1214 const auto status =
1215 mAidlComposerClient->getDisplayedContentSample(translate<int64_t>(display),
1216 static_cast<int64_t>(maxFrames),
1217 static_cast<int64_t>(timestamp),
1218 &sample);
1219 if (!status.isOk()) {
1220 ALOGE("getDisplayedContentSample failed %s", status.getDescription().c_str());
1221 return static_cast<Error>(status.getServiceSpecificError());
1222 }
1223 *outStats = translate<DisplayedFrameStats>(sample);
1224 return Error::NONE;
1225}
1226
1227Error AidlComposer::setLayerPerFrameMetadataBlobs(
1228 Display display, Layer layer,
1229 const std::vector<IComposerClient::PerFrameMetadataBlob>& metadata) {
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -04001230 Error error = Error::NONE;
1231 mMutex.lock_shared();
1232 if (auto writer = getWriter(display)) {
1233 writer->get().setLayerPerFrameMetadataBlobs(translate<int64_t>(display),
1234 translate<int64_t>(layer),
1235 translate<AidlPerFrameMetadataBlob>(metadata));
1236 } else {
1237 error = Error::BAD_DISPLAY;
1238 }
1239 mMutex.unlock_shared();
1240 return error;
Ady Abrahame7385f72021-09-05 00:54:25 -07001241}
1242
Alec Mouri4d8a05d2022-03-23 18:14:26 +00001243Error AidlComposer::setDisplayBrightness(Display display, float brightness, float brightnessNits,
Alec Mouricdf16792021-12-10 13:16:06 -08001244 const DisplayBrightnessOptions& options) {
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -04001245 Error error = Error::NONE;
1246 mMutex.lock_shared();
1247 if (auto writer = getWriter(display)) {
1248 writer->get().setDisplayBrightness(translate<int64_t>(display), brightness, brightnessNits);
Alec Mouricdf16792021-12-10 13:16:06 -08001249
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -04001250 if (options.applyImmediately) {
1251 error = execute(display);
1252 mMutex.unlock_shared();
1253 return error;
1254 }
1255 } else {
1256 error = Error::BAD_DISPLAY;
Alec Mouricdf16792021-12-10 13:16:06 -08001257 }
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -04001258 mMutex.unlock_shared();
1259 return error;
Ady Abrahame7385f72021-09-05 00:54:25 -07001260}
1261
1262Error AidlComposer::getDisplayCapabilities(Display display,
Leon Scroggins III5967aec2021-12-29 11:14:22 -05001263 std::vector<AidlDisplayCapability>* outCapabilities) {
1264 const auto status = mAidlComposerClient->getDisplayCapabilities(translate<int64_t>(display),
1265 outCapabilities);
Ady Abrahame7385f72021-09-05 00:54:25 -07001266 if (!status.isOk()) {
1267 ALOGE("getDisplayCapabilities failed %s", status.getDescription().c_str());
Leon Scroggins III5967aec2021-12-29 11:14:22 -05001268 outCapabilities->clear();
Ady Abrahame7385f72021-09-05 00:54:25 -07001269 return static_cast<Error>(status.getServiceSpecificError());
1270 }
Ady Abrahame7385f72021-09-05 00:54:25 -07001271 return Error::NONE;
1272}
1273
1274V2_4::Error AidlComposer::getDisplayConnectionType(
1275 Display display, IComposerClient::DisplayConnectionType* outType) {
1276 AidlDisplayConnectionType type;
1277 const auto status =
1278 mAidlComposerClient->getDisplayConnectionType(translate<int64_t>(display), &type);
1279 if (!status.isOk()) {
1280 ALOGE("getDisplayConnectionType failed %s", status.getDescription().c_str());
1281 return static_cast<V2_4::Error>(status.getServiceSpecificError());
1282 }
1283 *outType = translate<IComposerClient::DisplayConnectionType>(type);
1284 return V2_4::Error::NONE;
1285}
1286
1287V2_4::Error AidlComposer::getDisplayVsyncPeriod(Display display, VsyncPeriodNanos* outVsyncPeriod) {
1288 int32_t vsyncPeriod;
1289 const auto status =
1290 mAidlComposerClient->getDisplayVsyncPeriod(translate<int64_t>(display), &vsyncPeriod);
1291 if (!status.isOk()) {
1292 ALOGE("getDisplayVsyncPeriod failed %s", status.getDescription().c_str());
1293 return static_cast<V2_4::Error>(status.getServiceSpecificError());
1294 }
1295 *outVsyncPeriod = translate<VsyncPeriodNanos>(vsyncPeriod);
1296 return V2_4::Error::NONE;
1297}
1298
1299V2_4::Error AidlComposer::setActiveConfigWithConstraints(
1300 Display display, Config config,
1301 const IComposerClient::VsyncPeriodChangeConstraints& vsyncPeriodChangeConstraints,
1302 VsyncPeriodChangeTimeline* outTimeline) {
1303 AidlVsyncPeriodChangeTimeline timeline;
1304 const auto status =
1305 mAidlComposerClient
1306 ->setActiveConfigWithConstraints(translate<int64_t>(display),
1307 translate<int32_t>(config),
1308 translate<AidlVsyncPeriodChangeConstraints>(
1309 vsyncPeriodChangeConstraints),
1310 &timeline);
1311 if (!status.isOk()) {
1312 ALOGE("setActiveConfigWithConstraints failed %s", status.getDescription().c_str());
1313 return static_cast<V2_4::Error>(status.getServiceSpecificError());
1314 }
1315 *outTimeline = translate<VsyncPeriodChangeTimeline>(timeline);
1316 return V2_4::Error::NONE;
1317}
1318
1319V2_4::Error AidlComposer::setAutoLowLatencyMode(Display display, bool on) {
1320 const auto status = mAidlComposerClient->setAutoLowLatencyMode(translate<int64_t>(display), on);
1321 if (!status.isOk()) {
1322 ALOGE("setAutoLowLatencyMode failed %s", status.getDescription().c_str());
1323 return static_cast<V2_4::Error>(status.getServiceSpecificError());
1324 }
1325 return V2_4::Error::NONE;
1326}
1327
1328V2_4::Error AidlComposer::getSupportedContentTypes(
1329 Display displayId, std::vector<IComposerClient::ContentType>* outSupportedContentTypes) {
1330 std::vector<AidlContentType> types;
1331 const auto status =
1332 mAidlComposerClient->getSupportedContentTypes(translate<int64_t>(displayId), &types);
1333 if (!status.isOk()) {
1334 ALOGE("getSupportedContentTypes failed %s", status.getDescription().c_str());
1335 return static_cast<V2_4::Error>(status.getServiceSpecificError());
1336 }
1337 *outSupportedContentTypes = translate<IComposerClient::ContentType>(types);
1338 return V2_4::Error::NONE;
1339}
1340
1341V2_4::Error AidlComposer::setContentType(Display display,
1342 IComposerClient::ContentType contentType) {
1343 const auto status =
1344 mAidlComposerClient->setContentType(translate<int64_t>(display),
1345 translate<AidlContentType>(contentType));
1346 if (!status.isOk()) {
1347 ALOGE("setContentType failed %s", status.getDescription().c_str());
1348 return static_cast<V2_4::Error>(status.getServiceSpecificError());
1349 }
1350 return V2_4::Error::NONE;
1351}
1352
Ady Abraham3f976752021-12-20 16:17:50 -08001353V2_4::Error AidlComposer::setLayerGenericMetadata(Display, Layer, const std::string&, bool,
1354 const std::vector<uint8_t>&) {
1355 // There are no users for this API. See b/209691612.
1356 return V2_4::Error::UNSUPPORTED;
Ady Abrahame7385f72021-09-05 00:54:25 -07001357}
1358
1359V2_4::Error AidlComposer::getLayerGenericMetadataKeys(
Ady Abraham3f976752021-12-20 16:17:50 -08001360 std::vector<IComposerClient::LayerGenericMetadataKey>*) {
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
Kriti Dang7defaf32021-11-15 11:55:43 +01001365Error AidlComposer::setBootDisplayConfig(Display display, Config config) {
1366 const auto status = mAidlComposerClient->setBootDisplayConfig(translate<int64_t>(display),
1367 translate<int32_t>(config));
1368 if (!status.isOk()) {
1369 ALOGE("setBootDisplayConfig failed %s", status.getDescription().c_str());
1370 return static_cast<Error>(status.getServiceSpecificError());
1371 }
1372 return Error::NONE;
1373}
1374
1375Error AidlComposer::clearBootDisplayConfig(Display display) {
1376 const auto status = mAidlComposerClient->clearBootDisplayConfig(translate<int64_t>(display));
1377 if (!status.isOk()) {
1378 ALOGE("clearBootDisplayConfig failed %s", status.getDescription().c_str());
1379 return static_cast<Error>(status.getServiceSpecificError());
1380 }
1381 return Error::NONE;
1382}
1383
1384Error AidlComposer::getPreferredBootDisplayConfig(Display display, Config* config) {
1385 int32_t displayConfig;
1386 const auto status =
1387 mAidlComposerClient->getPreferredBootDisplayConfig(translate<int64_t>(display),
1388 &displayConfig);
1389 if (!status.isOk()) {
1390 ALOGE("getPreferredBootDisplayConfig failed %s", status.getDescription().c_str());
1391 return static_cast<Error>(status.getServiceSpecificError());
1392 }
1393 *config = translate<uint32_t>(displayConfig);
1394 return Error::NONE;
1395}
1396
Kriti Dang674b9372022-11-18 10:58:44 +01001397Error AidlComposer::getHdrConversionCapabilities(
1398 std::vector<AidlHdrConversionCapability>* hdrConversionCapabilities) {
1399 const auto status =
1400 mAidlComposerClient->getHdrConversionCapabilities(hdrConversionCapabilities);
1401 if (!status.isOk()) {
1402 hdrConversionCapabilities = {};
1403 ALOGE("getHdrConversionCapabilities failed %s", status.getDescription().c_str());
1404 return static_cast<Error>(status.getServiceSpecificError());
1405 }
1406 return Error::NONE;
1407}
1408
Kriti Dangd432bb52023-02-09 18:21:04 +01001409Error AidlComposer::setHdrConversionStrategy(AidlHdrConversionStrategy hdrConversionStrategy,
1410 Hdr* outPreferredHdrOutputType) {
1411 const auto status = mAidlComposerClient->setHdrConversionStrategy(hdrConversionStrategy,
1412 outPreferredHdrOutputType);
Kriti Dang674b9372022-11-18 10:58:44 +01001413 if (!status.isOk()) {
1414 ALOGE("setHdrConversionStrategy failed %s", status.getDescription().c_str());
1415 return static_cast<Error>(status.getServiceSpecificError());
1416 }
1417 return Error::NONE;
1418}
1419
ramindanib2158ee2023-02-13 20:29:59 -08001420Error AidlComposer::setRefreshRateChangedCallbackDebugEnabled(Display displayId, bool enabled) {
1421 const auto status =
1422 mAidlComposerClient->setRefreshRateChangedCallbackDebugEnabled(translate<int64_t>(
1423 displayId),
1424 enabled);
1425 if (!status.isOk()) {
1426 ALOGE("setRefreshRateChangedCallbackDebugEnabled failed %s",
1427 status.getDescription().c_str());
1428 return static_cast<Error>(status.getServiceSpecificError());
1429 }
1430 return Error::NONE;
1431}
1432
Ady Abrahame7385f72021-09-05 00:54:25 -07001433Error AidlComposer::getClientTargetProperty(
Alec Mouri85065692022-03-18 00:58:26 +00001434 Display display, ClientTargetPropertyWithBrightness* outClientTargetProperty) {
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -04001435 Error error = Error::NONE;
1436 mMutex.lock_shared();
1437 if (auto reader = getReader(display)) {
1438 *outClientTargetProperty =
1439 reader->get().takeClientTargetProperty(translate<int64_t>(display));
1440 } else {
1441 error = Error::BAD_DISPLAY;
1442 }
1443 mMutex.unlock_shared();
1444 return error;
Ady Abrahame7385f72021-09-05 00:54:25 -07001445}
1446
Alec Mouri6da0e272022-02-07 12:45:57 -08001447Error AidlComposer::setLayerBrightness(Display display, Layer layer, float brightness) {
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -04001448 Error error = Error::NONE;
1449 mMutex.lock_shared();
1450 if (auto writer = getWriter(display)) {
1451 writer->get().setLayerBrightness(translate<int64_t>(display), translate<int64_t>(layer),
1452 brightness);
1453 } else {
1454 error = Error::BAD_DISPLAY;
1455 }
1456 mMutex.unlock_shared();
1457 return error;
Alec Mouricdf6cbc2021-11-01 17:21:15 -07001458}
1459
Leon Scroggins IIId77d3162022-01-05 10:42:28 -05001460Error AidlComposer::setLayerBlockingRegion(Display display, Layer layer,
1461 const std::vector<IComposerClient::Rect>& blocking) {
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -04001462 Error error = Error::NONE;
1463 mMutex.lock_shared();
1464 if (auto writer = getWriter(display)) {
1465 writer->get().setLayerBlockingRegion(translate<int64_t>(display), translate<int64_t>(layer),
1466 translate<AidlRect>(blocking));
1467 } else {
1468 error = Error::BAD_DISPLAY;
1469 }
1470 mMutex.unlock_shared();
1471 return error;
Leon Scroggins IIId77d3162022-01-05 10:42:28 -05001472}
Leon Scroggins IIIe7c51c62022-02-01 15:53:54 -05001473
1474Error AidlComposer::getDisplayDecorationSupport(Display display,
1475 std::optional<DisplayDecorationSupport>* support) {
1476 const auto status =
1477 mAidlComposerClient->getDisplayDecorationSupport(translate<int64_t>(display), support);
1478 if (!status.isOk()) {
1479 ALOGE("getDisplayDecorationSupport failed %s", status.getDescription().c_str());
1480 support->reset();
1481 return static_cast<Error>(status.getServiceSpecificError());
1482 }
1483 return Error::NONE;
1484}
ramindani32cf0602022-03-02 02:30:29 +00001485
1486Error AidlComposer::setIdleTimerEnabled(Display displayId, std::chrono::milliseconds timeout) {
1487 const auto status =
1488 mAidlComposerClient->setIdleTimerEnabled(translate<int64_t>(displayId),
1489 translate<int32_t>(timeout.count()));
1490 if (!status.isOk()) {
1491 ALOGE("setIdleTimerEnabled failed %s", status.getDescription().c_str());
1492 return static_cast<Error>(status.getServiceSpecificError());
1493 }
1494 return Error::NONE;
1495}
1496
ramindani06e518e2022-03-14 18:47:53 +00001497Error AidlComposer::getPhysicalDisplayOrientation(Display displayId,
1498 AidlTransform* outDisplayOrientation) {
1499 const auto status =
1500 mAidlComposerClient->getDisplayPhysicalOrientation(translate<int64_t>(displayId),
1501 outDisplayOrientation);
1502 if (!status.isOk()) {
1503 ALOGE("getPhysicalDisplayOrientation failed %s", status.getDescription().c_str());
1504 return static_cast<Error>(status.getServiceSpecificError());
1505 }
1506 return Error::NONE;
1507}
1508
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -04001509ftl::Optional<std::reference_wrapper<ComposerClientWriter>> AidlComposer::getWriter(Display display)
1510 REQUIRES_SHARED(mMutex) {
1511 return mWriters.get(display);
1512}
1513
1514ftl::Optional<std::reference_wrapper<ComposerClientReader>> AidlComposer::getReader(Display display)
1515 REQUIRES_SHARED(mMutex) {
1516 if (mSingleReader) {
1517 display = translate<Display>(kSingleReaderKey);
1518 }
1519 return mReaders.get(display);
1520}
1521
1522void AidlComposer::removeDisplay(Display display) {
1523 mMutex.lock();
1524 bool wasErased = mWriters.erase(display);
1525 ALOGW_IF(!wasErased,
1526 "Attempting to remove writer for display %" PRId64 " which is not connected",
1527 translate<int64_t>(display));
1528 if (!mSingleReader) {
1529 removeReader(display);
1530 }
1531 mMutex.unlock();
1532}
1533
1534void AidlComposer::onHotplugDisconnect(Display display) {
1535 removeDisplay(display);
1536}
1537
1538bool AidlComposer::hasMultiThreadedPresentSupport(Display display) {
Leon Scroggins IIIc1cf4582023-03-23 18:37:44 -04001539#if 0
1540 // TODO (b/259132483): Reenable
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -04001541 const auto displayId = translate<int64_t>(display);
1542 std::vector<AidlDisplayCapability> capabilities;
1543 const auto status = mAidlComposerClient->getDisplayCapabilities(displayId, &capabilities);
1544 if (!status.isOk()) {
1545 ALOGE("getDisplayCapabilities failed %s", status.getDescription().c_str());
1546 return false;
1547 }
1548 return std::find(capabilities.begin(), capabilities.end(),
1549 AidlDisplayCapability::MULTI_THREADED_PRESENT) != capabilities.end();
Leon Scroggins IIIc1cf4582023-03-23 18:37:44 -04001550#else
1551 (void) display;
1552 return false;
1553#endif
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -04001554}
1555
1556void AidlComposer::addReader(Display display) {
1557 const auto displayId = translate<int64_t>(display);
1558 std::optional<int64_t> displayOpt;
1559 if (displayId != kSingleReaderKey) {
1560 displayOpt.emplace(displayId);
1561 }
1562 auto [it, added] = mReaders.try_emplace(display, std::move(displayOpt));
1563 ALOGW_IF(!added, "Attempting to add writer for display %" PRId64 " which is already connected",
1564 displayId);
1565}
1566
1567void AidlComposer::removeReader(Display display) {
1568 bool wasErased = mReaders.erase(display);
1569 ALOGW_IF(!wasErased,
1570 "Attempting to remove reader for display %" PRId64 " which is not connected",
1571 translate<int64_t>(display));
1572}
1573
1574void AidlComposer::addDisplay(Display display) {
1575 const auto displayId = translate<int64_t>(display);
1576 mMutex.lock();
1577 auto [it, added] = mWriters.try_emplace(display, displayId);
1578 ALOGW_IF(!added, "Attempting to add writer for display %" PRId64 " which is already connected",
1579 displayId);
1580 if (mSingleReader) {
1581 if (hasMultiThreadedPresentSupport(display)) {
1582 mSingleReader = false;
1583 removeReader(translate<Display>(kSingleReaderKey));
1584 // Note that this includes the new display.
1585 for (const auto& [existingDisplay, _] : mWriters) {
1586 addReader(existingDisplay);
1587 }
1588 }
1589 } else {
1590 addReader(display);
1591 }
1592 mMutex.unlock();
1593}
1594
1595void AidlComposer::onHotplugConnect(Display display) {
1596 addDisplay(display);
1597}
Ady Abrahame7385f72021-09-05 00:54:25 -07001598} // namespace Hwc2
1599} // namespace android