blob: e372b72b33acf183ebb8310f108f0f65663b9e5c [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;
Sally Qi0cbd08b2022-08-17 12:12:28 -070059using AidlOverlayProperties = aidl::android::hardware::graphics::composer3::OverlayProperties;
Ady Abrahame7385f72021-09-05 00:54:25 -070060using AidlPerFrameMetadata = aidl::android::hardware::graphics::composer3::PerFrameMetadata;
61using AidlPerFrameMetadataKey = aidl::android::hardware::graphics::composer3::PerFrameMetadataKey;
62using AidlPerFrameMetadataBlob = aidl::android::hardware::graphics::composer3::PerFrameMetadataBlob;
63using AidlRenderIntent = aidl::android::hardware::graphics::composer3::RenderIntent;
64using AidlVsyncPeriodChangeConstraints =
65 aidl::android::hardware::graphics::composer3::VsyncPeriodChangeConstraints;
66using AidlVsyncPeriodChangeTimeline =
67 aidl::android::hardware::graphics::composer3::VsyncPeriodChangeTimeline;
Ady Abrahame7385f72021-09-05 00:54:25 -070068using AidlDisplayContentSamplingAttributes =
69 aidl::android::hardware::graphics::composer3::DisplayContentSamplingAttributes;
70using AidlFormatColorComponent = aidl::android::hardware::graphics::composer3::FormatColorComponent;
71using AidlDisplayConnectionType =
72 aidl::android::hardware::graphics::composer3::DisplayConnectionType;
Ady Abrahame7385f72021-09-05 00:54:25 -070073
74using AidlColorTransform = aidl::android::hardware::graphics::common::ColorTransform;
75using AidlDataspace = aidl::android::hardware::graphics::common::Dataspace;
76using AidlFRect = aidl::android::hardware::graphics::common::FRect;
77using AidlRect = aidl::android::hardware::graphics::common::Rect;
78using AidlTransform = aidl::android::hardware::graphics::common::Transform;
79
80namespace Hwc2 {
81
82namespace {
83
84template <typename To, typename From>
85To translate(From x) {
86 return static_cast<To>(x);
87}
88
89template <typename To, typename From>
90std::vector<To> translate(const std::vector<From>& in) {
91 std::vector<To> out;
92 out.reserve(in.size());
93 std::transform(in.begin(), in.end(), std::back_inserter(out),
94 [](From x) { return translate<To>(x); });
95 return out;
96}
97
98template <>
99AidlRect translate(IComposerClient::Rect x) {
100 return AidlRect{
101 .left = x.left,
102 .top = x.top,
103 .right = x.right,
104 .bottom = x.bottom,
105 };
106}
107
108template <>
109AidlFRect translate(IComposerClient::FRect x) {
110 return AidlFRect{
111 .left = x.left,
112 .top = x.top,
113 .right = x.right,
114 .bottom = x.bottom,
115 };
116}
117
118template <>
Ady Abrahame7385f72021-09-05 00:54:25 -0700119AidlPerFrameMetadataBlob translate(IComposerClient::PerFrameMetadataBlob x) {
120 AidlPerFrameMetadataBlob blob;
121 blob.key = translate<AidlPerFrameMetadataKey>(x.key),
Long Linga4628782022-02-18 13:44:26 -0800122 std::copy(x.blob.begin(), x.blob.end(), std::inserter(blob.blob, blob.blob.end()));
Ady Abrahame7385f72021-09-05 00:54:25 -0700123 return blob;
124}
125
126template <>
127AidlPerFrameMetadata translate(IComposerClient::PerFrameMetadata x) {
128 return AidlPerFrameMetadata{
129 .key = translate<AidlPerFrameMetadataKey>(x.key),
130 .value = x.value,
131 };
132}
133
134template <>
135DisplayedFrameStats translate(AidlDisplayContentSample x) {
136 return DisplayedFrameStats{
137 .numFrames = static_cast<uint64_t>(x.frameCount),
138 .component_0_sample = translate<uint64_t>(x.sampleComponent0),
139 .component_1_sample = translate<uint64_t>(x.sampleComponent1),
140 .component_2_sample = translate<uint64_t>(x.sampleComponent2),
141 .component_3_sample = translate<uint64_t>(x.sampleComponent3),
142 };
143}
144
145template <>
146AidlVsyncPeriodChangeConstraints translate(IComposerClient::VsyncPeriodChangeConstraints x) {
147 return AidlVsyncPeriodChangeConstraints{
148 .desiredTimeNanos = x.desiredTimeNanos,
149 .seamlessRequired = x.seamlessRequired,
150 };
151}
152
153template <>
154VsyncPeriodChangeTimeline translate(AidlVsyncPeriodChangeTimeline x) {
155 return VsyncPeriodChangeTimeline{
156 .newVsyncAppliedTimeNanos = x.newVsyncAppliedTimeNanos,
157 .refreshRequired = x.refreshRequired,
158 .refreshTimeNanos = x.refreshTimeNanos,
159 };
160}
Ady Abrahame7385f72021-09-05 00:54:25 -0700161mat4 makeMat4(std::vector<float> in) {
162 return mat4(static_cast<const float*>(in.data()));
163}
164
165} // namespace
166
167class AidlIComposerCallbackWrapper : public BnComposerCallback {
168public:
Yichi Chen3401b562022-01-17 15:42:35 +0800169 AidlIComposerCallbackWrapper(HWC2::ComposerCallback& callback) : mCallback(callback) {}
Ady Abrahame7385f72021-09-05 00:54:25 -0700170
171 ::ndk::ScopedAStatus onHotplug(int64_t in_display, bool in_connected) override {
172 const auto connection = in_connected ? V2_4::IComposerCallback::Connection::CONNECTED
173 : V2_4::IComposerCallback::Connection::DISCONNECTED;
Yichi Chen3401b562022-01-17 15:42:35 +0800174 mCallback.onComposerHalHotplug(translate<Display>(in_display), connection);
Ady Abrahame7385f72021-09-05 00:54:25 -0700175 return ::ndk::ScopedAStatus::ok();
176 }
177
178 ::ndk::ScopedAStatus onRefresh(int64_t in_display) override {
Yichi Chen3401b562022-01-17 15:42:35 +0800179 mCallback.onComposerHalRefresh(translate<Display>(in_display));
Ady Abrahame7385f72021-09-05 00:54:25 -0700180 return ::ndk::ScopedAStatus::ok();
181 }
Yichi Chen3401b562022-01-17 15:42:35 +0800182
Ady Abrahame7385f72021-09-05 00:54:25 -0700183 ::ndk::ScopedAStatus onSeamlessPossible(int64_t in_display) override {
Yichi Chen3401b562022-01-17 15:42:35 +0800184 mCallback.onComposerHalSeamlessPossible(translate<Display>(in_display));
Ady Abrahame7385f72021-09-05 00:54:25 -0700185 return ::ndk::ScopedAStatus::ok();
186 }
Yichi Chen3401b562022-01-17 15:42:35 +0800187
Ady Abrahame7385f72021-09-05 00:54:25 -0700188 ::ndk::ScopedAStatus onVsync(int64_t in_display, int64_t in_timestamp,
189 int32_t in_vsyncPeriodNanos) override {
Yichi Chen3401b562022-01-17 15:42:35 +0800190 mCallback.onComposerHalVsync(translate<Display>(in_display), in_timestamp,
191 static_cast<uint32_t>(in_vsyncPeriodNanos));
Ady Abrahame7385f72021-09-05 00:54:25 -0700192 return ::ndk::ScopedAStatus::ok();
193 }
Yichi Chen3401b562022-01-17 15:42:35 +0800194
Ady Abrahame7385f72021-09-05 00:54:25 -0700195 ::ndk::ScopedAStatus onVsyncPeriodTimingChanged(
196 int64_t in_display, const AidlVsyncPeriodChangeTimeline& in_updatedTimeline) override {
Yichi Chen3401b562022-01-17 15:42:35 +0800197 mCallback.onComposerHalVsyncPeriodTimingChanged(translate<Display>(in_display),
198 translate<V2_4::VsyncPeriodChangeTimeline>(
199 in_updatedTimeline));
200 return ::ndk::ScopedAStatus::ok();
201 }
202
203 ::ndk::ScopedAStatus onVsyncIdle(int64_t in_display) override {
204 mCallback.onComposerHalVsyncIdle(translate<Display>(in_display));
Ady Abrahame7385f72021-09-05 00:54:25 -0700205 return ::ndk::ScopedAStatus::ok();
206 }
207
208private:
Yichi Chen3401b562022-01-17 15:42:35 +0800209 HWC2::ComposerCallback& mCallback;
Ady Abrahame7385f72021-09-05 00:54:25 -0700210};
211
Ady Abraham9fc28052021-10-14 17:21:38 -0700212std::string AidlComposer::instance(const std::string& serviceName) {
213 return std::string(AidlIComposer::descriptor) + "/" + serviceName;
214}
215
216bool AidlComposer::isDeclared(const std::string& serviceName) {
217 return AServiceManager_isDeclared(instance(serviceName).c_str());
218}
Ady Abrahame7385f72021-09-05 00:54:25 -0700219
Ady Abrahama6388c02021-11-11 21:11:51 -0800220AidlComposer::AidlComposer(const std::string& serviceName) {
Ady Abrahame7385f72021-09-05 00:54:25 -0700221 // This only waits if the service is actually declared
Ady Abraham9fc28052021-10-14 17:21:38 -0700222 mAidlComposer = AidlIComposer::fromBinder(
223 ndk::SpAIBinder(AServiceManager_waitForService(instance(serviceName).c_str())));
Ady Abrahame7385f72021-09-05 00:54:25 -0700224 if (!mAidlComposer) {
225 LOG_ALWAYS_FATAL("Failed to get AIDL composer service");
226 return;
227 }
228
229 if (!mAidlComposer->createClient(&mAidlComposerClient).isOk()) {
230 LOG_ALWAYS_FATAL("Can't create AidlComposerClient, fallback to HIDL");
231 return;
232 }
233
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400234 addReader(translate<Display>(kSingleReaderKey));
235
Brian Lindahldbf7e3a2022-12-16 11:43:39 -0700236 // If unable to read interface version, then become backwards compatible.
237 int32_t version = 1;
238 const auto status = mAidlComposerClient->getInterfaceVersion(&version);
239 if (!status.isOk()) {
240 ALOGE("getInterfaceVersion for AidlComposer constructor failed %s",
241 status.getDescription().c_str());
242 }
243 if (version == 1) {
244 mClearSlotBuffer = sp<GraphicBuffer>::make(1, 1, PIXEL_FORMAT_RGBX_8888,
245 GraphicBuffer::USAGE_HW_COMPOSER |
246 GraphicBuffer::USAGE_SW_READ_OFTEN |
247 GraphicBuffer::USAGE_SW_WRITE_OFTEN,
248 "AidlComposer");
249 if (!mClearSlotBuffer || mClearSlotBuffer->initCheck() != ::android::OK) {
250 LOG_ALWAYS_FATAL("Failed to allocate a buffer for clearing layer buffer slots");
251 return;
252 }
Brian Lindahl90553da2022-12-06 13:36:30 -0700253 }
254
Ady Abrahame7385f72021-09-05 00:54:25 -0700255 ALOGI("Loaded AIDL composer3 HAL service");
256}
257
258AidlComposer::~AidlComposer() = default;
259
Ady Abraham4d211cf2021-12-14 16:19:03 -0800260bool AidlComposer::isSupported(OptionalFeature feature) const {
261 switch (feature) {
262 case OptionalFeature::RefreshRateSwitching:
Ady Abraham43065bd2021-12-10 17:22:15 -0800263 case OptionalFeature::ExpectedPresentTime:
Alec Mouricdf16792021-12-10 13:16:06 -0800264 case OptionalFeature::DisplayBrightnessCommand:
ramindani32cf0602022-03-02 02:30:29 +0000265 case OptionalFeature::KernelIdleTimer:
ramindani06e518e2022-03-14 18:47:53 +0000266 case OptionalFeature::PhysicalDisplayOrientation:
Ady Abraham4d211cf2021-12-14 16:19:03 -0800267 return true;
268 }
269}
270
Ady Abrahamde549d42022-01-26 19:19:17 -0800271std::vector<Capability> AidlComposer::getCapabilities() {
Ady Abrahame7385f72021-09-05 00:54:25 -0700272 std::vector<Capability> capabilities;
273 const auto status = mAidlComposer->getCapabilities(&capabilities);
274 if (!status.isOk()) {
275 ALOGE("getCapabilities failed %s", status.getDescription().c_str());
276 return {};
277 }
Ady Abrahamde549d42022-01-26 19:19:17 -0800278 return capabilities;
Ady Abrahame7385f72021-09-05 00:54:25 -0700279}
280
281std::string AidlComposer::dumpDebugInfo() {
Ady Abrahamc4acf512022-02-18 17:11:59 -0800282 int pipefds[2];
283 int result = pipe(pipefds);
284 if (result < 0) {
285 ALOGE("dumpDebugInfo: pipe failed: %s", strerror(errno));
Ady Abrahame7385f72021-09-05 00:54:25 -0700286 return {};
287 }
Ady Abrahamc4acf512022-02-18 17:11:59 -0800288
289 std::string str;
yihsing.shen58847c52022-09-23 15:39:30 +0800290 // Use other thread to read pipe to prevent
291 // pipe is full, making HWC be blocked in writing.
292 std::thread t([&]() {
293 base::ReadFdToString(pipefds[0], &str);
294 });
Ady Abrahamc4acf512022-02-18 17:11:59 -0800295 const auto status = mAidlComposer->dump(pipefds[1], /*args*/ nullptr, /*numArgs*/ 0);
296 // Close the write-end of the pipe to make sure that when reading from the
297 // read-end we will get eof instead of blocking forever
298 close(pipefds[1]);
299
yihsing.shen58847c52022-09-23 15:39:30 +0800300 if (status != STATUS_OK) {
Ady Abrahamc4acf512022-02-18 17:11:59 -0800301 ALOGE("dumpDebugInfo: dump failed: %d", status);
302 }
303
yihsing.shen58847c52022-09-23 15:39:30 +0800304 t.join();
Ady Abrahamc4acf512022-02-18 17:11:59 -0800305 close(pipefds[0]);
306 return str;
Ady Abrahame7385f72021-09-05 00:54:25 -0700307}
308
Yichi Chen3401b562022-01-17 15:42:35 +0800309void AidlComposer::registerCallback(HWC2::ComposerCallback& callback) {
Ady Abrahame7385f72021-09-05 00:54:25 -0700310 if (mAidlComposerCallback) {
311 ALOGE("Callback already registered");
312 }
Yichi Chen3401b562022-01-17 15:42:35 +0800313
Ady Abraham9fc28052021-10-14 17:21:38 -0700314 mAidlComposerCallback = ndk::SharedRefBase::make<AidlIComposerCallbackWrapper>(callback);
Ady Abrahame7385f72021-09-05 00:54:25 -0700315 AIBinder_setMinSchedulerPolicy(mAidlComposerCallback->asBinder().get(), SCHED_FIFO, 2);
316
317 const auto status = mAidlComposerClient->registerCallback(mAidlComposerCallback);
318 if (!status.isOk()) {
319 ALOGE("registerCallback failed %s", status.getDescription().c_str());
320 }
321}
322
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400323void AidlComposer::resetCommands(Display display) {
324 mMutex.lock_shared();
325 if (auto writer = getWriter(display)) {
326 writer->get().reset();
327 }
328 mMutex.unlock_shared();
Ady Abrahame7385f72021-09-05 00:54:25 -0700329}
330
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400331Error AidlComposer::executeCommands(Display display) {
332 mMutex.lock_shared();
333 auto error = execute(display);
334 mMutex.unlock_shared();
335 return error;
Ady Abrahame7385f72021-09-05 00:54:25 -0700336}
337
338uint32_t AidlComposer::getMaxVirtualDisplayCount() {
339 int32_t count = 0;
340 const auto status = mAidlComposerClient->getMaxVirtualDisplayCount(&count);
341 if (!status.isOk()) {
342 ALOGE("getMaxVirtualDisplayCount failed %s", status.getDescription().c_str());
343 return 0;
344 }
345 return static_cast<uint32_t>(count);
346}
347
348Error AidlComposer::createVirtualDisplay(uint32_t width, uint32_t height, PixelFormat* format,
349 Display* outDisplay) {
350 using AidlPixelFormat = aidl::android::hardware::graphics::common::PixelFormat;
351 const int32_t bufferSlotCount = 1;
352 VirtualDisplay virtualDisplay;
353 const auto status =
354 mAidlComposerClient->createVirtualDisplay(static_cast<int32_t>(width),
355 static_cast<int32_t>(height),
356 static_cast<AidlPixelFormat>(*format),
357 bufferSlotCount, &virtualDisplay);
358
359 if (!status.isOk()) {
360 ALOGE("createVirtualDisplay failed %s", status.getDescription().c_str());
361 return static_cast<Error>(status.getServiceSpecificError());
362 }
363
364 *outDisplay = translate<Display>(virtualDisplay.display);
365 *format = static_cast<PixelFormat>(virtualDisplay.format);
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400366 addDisplay(translate<Display>(virtualDisplay.display));
Ady Abrahame7385f72021-09-05 00:54:25 -0700367 return Error::NONE;
368}
369
370Error AidlComposer::destroyVirtualDisplay(Display display) {
371 const auto status = mAidlComposerClient->destroyVirtualDisplay(translate<int64_t>(display));
372 if (!status.isOk()) {
373 ALOGE("destroyVirtualDisplay failed %s", status.getDescription().c_str());
374 return static_cast<Error>(status.getServiceSpecificError());
375 }
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400376 removeDisplay(display);
Ady Abrahame7385f72021-09-05 00:54:25 -0700377 return Error::NONE;
378}
379
380Error AidlComposer::acceptDisplayChanges(Display display) {
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400381 Error error = Error::NONE;
382 mMutex.lock_shared();
383 if (auto writer = getWriter(display)) {
384 writer->get().acceptDisplayChanges(translate<int64_t>(display));
385 } else {
386 error = Error::BAD_DISPLAY;
387 }
388 mMutex.unlock_shared();
389 return error;
Ady Abrahame7385f72021-09-05 00:54:25 -0700390}
391
392Error AidlComposer::createLayer(Display display, Layer* outLayer) {
393 int64_t layer;
394 const auto status = mAidlComposerClient->createLayer(translate<int64_t>(display),
395 kMaxLayerBufferCount, &layer);
396 if (!status.isOk()) {
397 ALOGE("createLayer failed %s", status.getDescription().c_str());
398 return static_cast<Error>(status.getServiceSpecificError());
399 }
400
401 *outLayer = translate<Layer>(layer);
402 return Error::NONE;
403}
404
405Error AidlComposer::destroyLayer(Display display, Layer layer) {
406 const auto status = mAidlComposerClient->destroyLayer(translate<int64_t>(display),
407 translate<int64_t>(layer));
408 if (!status.isOk()) {
409 ALOGE("destroyLayer failed %s", status.getDescription().c_str());
410 return static_cast<Error>(status.getServiceSpecificError());
411 }
412 return Error::NONE;
413}
414
415Error AidlComposer::getActiveConfig(Display display, Config* outConfig) {
416 int32_t config;
417 const auto status = mAidlComposerClient->getActiveConfig(translate<int64_t>(display), &config);
418 if (!status.isOk()) {
419 ALOGE("getActiveConfig failed %s", status.getDescription().c_str());
420 return static_cast<Error>(status.getServiceSpecificError());
421 }
422 *outConfig = translate<Config>(config);
423 return Error::NONE;
424}
425
426Error AidlComposer::getChangedCompositionTypes(
427 Display display, std::vector<Layer>* outLayers,
Leon Scroggins III2e1aa182021-12-01 17:33:12 -0500428 std::vector<aidl::android::hardware::graphics::composer3::Composition>* outTypes) {
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400429 std::vector<ChangedCompositionLayer> changedLayers;
430 Error error = Error::NONE;
431 {
432 mMutex.lock_shared();
433 if (auto reader = getReader(display)) {
434 changedLayers = reader->get().takeChangedCompositionTypes(translate<int64_t>(display));
435 } else {
436 error = Error::BAD_DISPLAY;
437 }
438 mMutex.unlock_shared();
439 }
Ady Abrahamde792782021-12-20 10:00:49 -0800440 outLayers->reserve(changedLayers.size());
441 outTypes->reserve(changedLayers.size());
Ady Abrahama6388c02021-11-11 21:11:51 -0800442
Ady Abrahamde792782021-12-20 10:00:49 -0800443 for (const auto& layer : changedLayers) {
444 outLayers->emplace_back(translate<Layer>(layer.layer));
445 outTypes->emplace_back(layer.composition);
446 }
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400447 return error;
Ady Abrahame7385f72021-09-05 00:54:25 -0700448}
449
450Error AidlComposer::getColorModes(Display display, std::vector<ColorMode>* outModes) {
451 std::vector<AidlColorMode> modes;
452 const auto status = mAidlComposerClient->getColorModes(translate<int64_t>(display), &modes);
453 if (!status.isOk()) {
454 ALOGE("getColorModes failed %s", status.getDescription().c_str());
455 return static_cast<Error>(status.getServiceSpecificError());
456 }
457 *outModes = translate<ColorMode>(modes);
458 return Error::NONE;
459}
460
461Error AidlComposer::getDisplayAttribute(Display display, Config config,
462 IComposerClient::Attribute attribute, int32_t* outValue) {
463 const auto status =
464 mAidlComposerClient->getDisplayAttribute(translate<int64_t>(display),
465 translate<int32_t>(config),
466 static_cast<AidlDisplayAttribute>(attribute),
467 outValue);
468 if (!status.isOk()) {
469 ALOGE("getDisplayAttribute failed %s", status.getDescription().c_str());
470 return static_cast<Error>(status.getServiceSpecificError());
471 }
472 return Error::NONE;
473}
474
475Error AidlComposer::getDisplayConfigs(Display display, std::vector<Config>* outConfigs) {
476 std::vector<int32_t> configs;
477 const auto status =
478 mAidlComposerClient->getDisplayConfigs(translate<int64_t>(display), &configs);
479 if (!status.isOk()) {
480 ALOGE("getDisplayConfigs failed %s", status.getDescription().c_str());
481 return static_cast<Error>(status.getServiceSpecificError());
482 }
483 *outConfigs = translate<Config>(configs);
484 return Error::NONE;
485}
486
487Error AidlComposer::getDisplayName(Display display, std::string* outName) {
488 const auto status = mAidlComposerClient->getDisplayName(translate<int64_t>(display), outName);
489 if (!status.isOk()) {
490 ALOGE("getDisplayName failed %s", status.getDescription().c_str());
491 return static_cast<Error>(status.getServiceSpecificError());
492 }
493 return Error::NONE;
494}
495
496Error AidlComposer::getDisplayRequests(Display display, uint32_t* outDisplayRequestMask,
497 std::vector<Layer>* outLayers,
498 std::vector<uint32_t>* outLayerRequestMasks) {
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400499 Error error = Error::NONE;
500 DisplayRequest displayRequests;
501 {
502 mMutex.lock_shared();
503 if (auto reader = getReader(display)) {
504 displayRequests = reader->get().takeDisplayRequests(translate<int64_t>(display));
505 } else {
506 error = Error::BAD_DISPLAY;
507 }
508 mMutex.unlock_shared();
509 }
Ady Abrahamde792782021-12-20 10:00:49 -0800510 *outDisplayRequestMask = translate<uint32_t>(displayRequests.mask);
511 outLayers->reserve(displayRequests.layerRequests.size());
512 outLayerRequestMasks->reserve(displayRequests.layerRequests.size());
513
514 for (const auto& layer : displayRequests.layerRequests) {
515 outLayers->emplace_back(translate<Layer>(layer.layer));
516 outLayerRequestMasks->emplace_back(translate<uint32_t>(layer.mask));
517 }
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400518 return error;
Ady Abrahame7385f72021-09-05 00:54:25 -0700519}
520
521Error AidlComposer::getDozeSupport(Display display, bool* outSupport) {
Ady Abraham33b92b92021-12-08 18:30:27 -0800522 std::vector<AidlDisplayCapability> capabilities;
Ady Abrahame7385f72021-09-05 00:54:25 -0700523 const auto status =
Ady Abraham33b92b92021-12-08 18:30:27 -0800524 mAidlComposerClient->getDisplayCapabilities(translate<int64_t>(display), &capabilities);
Ady Abrahame7385f72021-09-05 00:54:25 -0700525 if (!status.isOk()) {
Ady Abraham33b92b92021-12-08 18:30:27 -0800526 ALOGE("getDisplayCapabilities failed %s", status.getDescription().c_str());
Ady Abrahame7385f72021-09-05 00:54:25 -0700527 return static_cast<Error>(status.getServiceSpecificError());
528 }
Ady Abraham33b92b92021-12-08 18:30:27 -0800529 *outSupport = std::find(capabilities.begin(), capabilities.end(),
530 AidlDisplayCapability::DOZE) != capabilities.end();
Ady Abrahame7385f72021-09-05 00:54:25 -0700531 return Error::NONE;
532}
533
ramindani32cf0602022-03-02 02:30:29 +0000534Error AidlComposer::hasDisplayIdleTimerCapability(Display display, bool* outSupport) {
535 std::vector<AidlDisplayCapability> capabilities;
536 const auto status =
537 mAidlComposerClient->getDisplayCapabilities(translate<int64_t>(display), &capabilities);
538 if (!status.isOk()) {
539 ALOGE("getDisplayCapabilities failed %s", status.getDescription().c_str());
540 return static_cast<Error>(status.getServiceSpecificError());
541 }
542 *outSupport = std::find(capabilities.begin(), capabilities.end(),
543 AidlDisplayCapability::DISPLAY_IDLE_TIMER) != capabilities.end();
544 return Error::NONE;
545}
546
Ady Abrahame7385f72021-09-05 00:54:25 -0700547Error AidlComposer::getHdrCapabilities(Display display, std::vector<Hdr>* outTypes,
548 float* outMaxLuminance, float* outMaxAverageLuminance,
549 float* outMinLuminance) {
550 AidlHdrCapabilities capabilities;
551 const auto status =
552 mAidlComposerClient->getHdrCapabilities(translate<int64_t>(display), &capabilities);
553 if (!status.isOk()) {
554 ALOGE("getHdrCapabilities failed %s", status.getDescription().c_str());
555 return static_cast<Error>(status.getServiceSpecificError());
556 }
557
Marc Kassisbdf7e4b2022-11-04 17:26:48 +0100558 *outTypes = capabilities.types;
Ady Abrahame7385f72021-09-05 00:54:25 -0700559 *outMaxLuminance = capabilities.maxLuminance;
560 *outMaxAverageLuminance = capabilities.maxAverageLuminance;
561 *outMinLuminance = capabilities.minLuminance;
562 return Error::NONE;
563}
564
Sally Qibb866c12022-10-17 11:31:20 -0700565Error AidlComposer::getOverlaySupport(AidlOverlayProperties* outProperties) {
566 const auto status = mAidlComposerClient->getOverlaySupport(outProperties);
567 if (!status.isOk()) {
568 ALOGE("getOverlaySupport failed %s", status.getDescription().c_str());
569 return static_cast<Error>(status.getServiceSpecificError());
570 }
Sally Qi0cbd08b2022-08-17 12:12:28 -0700571 return Error::NONE;
572}
573
Ady Abrahame7385f72021-09-05 00:54:25 -0700574Error AidlComposer::getReleaseFences(Display display, std::vector<Layer>* outLayers,
575 std::vector<int>* outReleaseFences) {
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400576 Error error = Error::NONE;
577 std::vector<ReleaseFences::Layer> fences;
578 {
579 mMutex.lock_shared();
580 if (auto reader = getReader(display)) {
581 fences = reader->get().takeReleaseFences(translate<int64_t>(display));
582 } else {
583 error = Error::BAD_DISPLAY;
584 }
585 mMutex.unlock_shared();
586 }
Ady Abrahamde792782021-12-20 10:00:49 -0800587 outLayers->reserve(fences.size());
588 outReleaseFences->reserve(fences.size());
589
590 for (auto& fence : fences) {
591 outLayers->emplace_back(translate<Layer>(fence.layer));
592 // take ownership
593 const int fenceOwner = fence.fence.get();
594 *fence.fence.getR() = -1;
595 outReleaseFences->emplace_back(fenceOwner);
596 }
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400597 return error;
Ady Abrahame7385f72021-09-05 00:54:25 -0700598}
599
600Error AidlComposer::presentDisplay(Display display, int* outPresentFence) {
Leon Scroggins IIIe85e16e2022-12-12 12:51:18 -0500601 const auto displayId = translate<int64_t>(display);
602 ATRACE_FORMAT("HwcPresentDisplay %" PRId64, displayId);
603
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400604 Error error = Error::NONE;
605 mMutex.lock_shared();
606 auto writer = getWriter(display);
607 auto reader = getReader(display);
608 if (writer && reader) {
Leon Scroggins IIIe85e16e2022-12-12 12:51:18 -0500609 writer->get().presentDisplay(displayId);
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400610 error = execute(display);
611 } else {
612 error = Error::BAD_DISPLAY;
613 }
Ady Abrahame7385f72021-09-05 00:54:25 -0700614
Ady Abrahame7385f72021-09-05 00:54:25 -0700615 if (error != Error::NONE) {
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400616 mMutex.unlock_shared();
Ady Abrahame7385f72021-09-05 00:54:25 -0700617 return error;
618 }
619
Leon Scroggins IIIe85e16e2022-12-12 12:51:18 -0500620 auto fence = reader->get().takePresentFence(displayId);
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400621 mMutex.unlock_shared();
Ady Abrahamde792782021-12-20 10:00:49 -0800622 // take ownership
623 *outPresentFence = fence.get();
624 *fence.getR() = -1;
Ady Abrahame7385f72021-09-05 00:54:25 -0700625 return Error::NONE;
626}
627
628Error AidlComposer::setActiveConfig(Display display, Config config) {
629 const auto status = mAidlComposerClient->setActiveConfig(translate<int64_t>(display),
630 translate<int32_t>(config));
631 if (!status.isOk()) {
632 ALOGE("setActiveConfig failed %s", status.getDescription().c_str());
633 return static_cast<Error>(status.getServiceSpecificError());
634 }
635 return Error::NONE;
636}
637
638Error AidlComposer::setClientTarget(Display display, uint32_t slot, const sp<GraphicBuffer>& target,
639 int acquireFence, Dataspace dataspace,
640 const std::vector<IComposerClient::Rect>& damage) {
Ady Abrahame7385f72021-09-05 00:54:25 -0700641 const native_handle_t* handle = nullptr;
642 if (target.get()) {
643 handle = target->getNativeBuffer()->handle;
644 }
645
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400646 Error error = Error::NONE;
647 mMutex.lock_shared();
648 if (auto writer = getWriter(display)) {
649 writer->get()
650 .setClientTarget(translate<int64_t>(display), slot, handle, acquireFence,
651 translate<aidl::android::hardware::graphics::common::Dataspace>(
652 dataspace),
653 translate<AidlRect>(damage));
654 } else {
655 error = Error::BAD_DISPLAY;
656 }
657 mMutex.unlock_shared();
658 return error;
Ady Abrahame7385f72021-09-05 00:54:25 -0700659}
660
661Error AidlComposer::setColorMode(Display display, ColorMode mode, RenderIntent renderIntent) {
662 const auto status =
663 mAidlComposerClient->setColorMode(translate<int64_t>(display),
664 translate<AidlColorMode>(mode),
665 translate<AidlRenderIntent>(renderIntent));
666 if (!status.isOk()) {
667 ALOGE("setColorMode failed %s", status.getDescription().c_str());
668 return static_cast<Error>(status.getServiceSpecificError());
669 }
670 return Error::NONE;
671}
672
Ady Abrahamdc011a92021-12-21 14:06:44 -0800673Error AidlComposer::setColorTransform(Display display, const float* matrix) {
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400674 auto error = Error::NONE;
675 mMutex.lock_shared();
676 if (auto writer = getWriter(display)) {
677 writer->get().setColorTransform(translate<int64_t>(display), matrix);
678 } else {
679 error = Error::BAD_DISPLAY;
680 }
681 mMutex.unlock_shared();
682 return error;
Ady Abrahame7385f72021-09-05 00:54:25 -0700683}
684
685Error AidlComposer::setOutputBuffer(Display display, const native_handle_t* buffer,
686 int releaseFence) {
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400687 auto error = Error::NONE;
688 mMutex.lock_shared();
689 if (auto writer = getWriter(display)) {
690 writer->get().setOutputBuffer(translate<int64_t>(display), 0, buffer, dup(releaseFence));
691 } else {
692 error = Error::BAD_DISPLAY;
693 }
694 mMutex.unlock_shared();
695 return error;
Ady Abrahame7385f72021-09-05 00:54:25 -0700696}
697
698Error AidlComposer::setPowerMode(Display display, IComposerClient::PowerMode mode) {
699 const auto status = mAidlComposerClient->setPowerMode(translate<int64_t>(display),
700 translate<PowerMode>(mode));
701 if (!status.isOk()) {
702 ALOGE("setPowerMode failed %s", status.getDescription().c_str());
703 return static_cast<Error>(status.getServiceSpecificError());
704 }
705 return Error::NONE;
706}
707
708Error AidlComposer::setVsyncEnabled(Display display, IComposerClient::Vsync enabled) {
709 const bool enableVsync = enabled == IComposerClient::Vsync::ENABLE;
710 const auto status =
711 mAidlComposerClient->setVsyncEnabled(translate<int64_t>(display), enableVsync);
712 if (!status.isOk()) {
713 ALOGE("setVsyncEnabled failed %s", status.getDescription().c_str());
714 return static_cast<Error>(status.getServiceSpecificError());
715 }
716 return Error::NONE;
717}
718
719Error AidlComposer::setClientTargetSlotCount(Display display) {
720 const int32_t bufferSlotCount = BufferQueue::NUM_BUFFER_SLOTS;
721 const auto status = mAidlComposerClient->setClientTargetSlotCount(translate<int64_t>(display),
722 bufferSlotCount);
723 if (!status.isOk()) {
724 ALOGE("setClientTargetSlotCount failed %s", status.getDescription().c_str());
725 return static_cast<Error>(status.getServiceSpecificError());
726 }
727 return Error::NONE;
728}
729
Ady Abraham43065bd2021-12-10 17:22:15 -0800730Error AidlComposer::validateDisplay(Display display, nsecs_t expectedPresentTime,
731 uint32_t* outNumTypes, uint32_t* outNumRequests) {
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400732 const auto displayId = translate<int64_t>(display);
Leon Scroggins IIIe85e16e2022-12-12 12:51:18 -0500733 ATRACE_FORMAT("HwcValidateDisplay %" PRId64, displayId);
734
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400735 Error error = Error::NONE;
736 mMutex.lock_shared();
737 auto writer = getWriter(display);
738 auto reader = getReader(display);
739 if (writer && reader) {
740 writer->get().validateDisplay(displayId, ClockMonotonicTimestamp{expectedPresentTime});
741 error = execute(display);
742 } else {
743 error = Error::BAD_DISPLAY;
744 }
Ady Abrahame7385f72021-09-05 00:54:25 -0700745
Ady Abrahame7385f72021-09-05 00:54:25 -0700746 if (error != Error::NONE) {
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400747 mMutex.unlock_shared();
Ady Abrahame7385f72021-09-05 00:54:25 -0700748 return error;
749 }
750
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400751 reader->get().hasChanges(displayId, outNumTypes, outNumRequests);
Ady Abrahame7385f72021-09-05 00:54:25 -0700752
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400753 mMutex.unlock_shared();
Ady Abrahame7385f72021-09-05 00:54:25 -0700754 return Error::NONE;
755}
756
Ady Abraham43065bd2021-12-10 17:22:15 -0800757Error AidlComposer::presentOrValidateDisplay(Display display, nsecs_t expectedPresentTime,
758 uint32_t* outNumTypes, uint32_t* outNumRequests,
759 int* outPresentFence, uint32_t* state) {
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400760 const auto displayId = translate<int64_t>(display);
Leon Scroggins IIIe85e16e2022-12-12 12:51:18 -0500761 ATRACE_FORMAT("HwcPresentOrValidateDisplay %" PRId64, displayId);
762
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400763 Error error = Error::NONE;
764 mMutex.lock_shared();
765 auto writer = getWriter(display);
766 auto reader = getReader(display);
767 if (writer && reader) {
768 writer->get().presentOrvalidateDisplay(displayId,
769 ClockMonotonicTimestamp{expectedPresentTime});
770 error = execute(display);
771 } else {
772 error = Error::BAD_DISPLAY;
773 }
Ady Abrahame7385f72021-09-05 00:54:25 -0700774
Ady Abrahame7385f72021-09-05 00:54:25 -0700775 if (error != Error::NONE) {
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400776 mMutex.unlock_shared();
Ady Abrahame7385f72021-09-05 00:54:25 -0700777 return error;
778 }
779
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400780 const auto result = reader->get().takePresentOrValidateStage(displayId);
Ady Abrahamde792782021-12-20 10:00:49 -0800781 if (!result.has_value()) {
782 *state = translate<uint32_t>(-1);
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400783 mMutex.unlock_shared();
Ady Abrahamde792782021-12-20 10:00:49 -0800784 return Error::NO_RESOURCES;
Ady Abrahame7385f72021-09-05 00:54:25 -0700785 }
786
Ady Abrahamde792782021-12-20 10:00:49 -0800787 *state = translate<uint32_t>(*result);
788
789 if (*result == PresentOrValidate::Result::Presented) {
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400790 auto fence = reader->get().takePresentFence(displayId);
Ady Abrahamde792782021-12-20 10:00:49 -0800791 // take ownership
792 *outPresentFence = fence.get();
793 *fence.getR() = -1;
794 }
795
796 if (*result == PresentOrValidate::Result::Validated) {
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400797 reader->get().hasChanges(displayId, outNumTypes, outNumRequests);
Ady Abrahame7385f72021-09-05 00:54:25 -0700798 }
799
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400800 mMutex.unlock_shared();
Ady Abrahame7385f72021-09-05 00:54:25 -0700801 return Error::NONE;
802}
803
804Error AidlComposer::setCursorPosition(Display display, Layer layer, int32_t x, int32_t y) {
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400805 Error error = Error::NONE;
806 mMutex.lock_shared();
807 if (auto writer = getWriter(display)) {
808 writer->get().setLayerCursorPosition(translate<int64_t>(display), translate<int64_t>(layer),
809 x, y);
810 } else {
811 error = Error::BAD_DISPLAY;
812 }
813 mMutex.unlock_shared();
814 return error;
Ady Abrahame7385f72021-09-05 00:54:25 -0700815}
816
817Error AidlComposer::setLayerBuffer(Display display, Layer layer, uint32_t slot,
818 const sp<GraphicBuffer>& buffer, int acquireFence) {
Ady Abrahame7385f72021-09-05 00:54:25 -0700819 const native_handle_t* handle = nullptr;
820 if (buffer.get()) {
821 handle = buffer->getNativeBuffer()->handle;
822 }
823
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400824 Error error = Error::NONE;
825 mMutex.lock_shared();
826 if (auto writer = getWriter(display)) {
827 writer->get().setLayerBuffer(translate<int64_t>(display), translate<int64_t>(layer), slot,
828 handle, acquireFence);
829 } else {
830 error = Error::BAD_DISPLAY;
831 }
832 mMutex.unlock_shared();
833 return error;
Ady Abrahame7385f72021-09-05 00:54:25 -0700834}
835
Brian Lindahlb158a5c2022-12-15 15:21:13 -0700836Error AidlComposer::setLayerBufferSlotsToClear(Display display, Layer layer,
837 const std::vector<uint32_t>& slotsToClear,
838 uint32_t activeBufferSlot) {
839 if (slotsToClear.empty()) {
840 return Error::NONE;
841 }
842
Brian Lindahl90553da2022-12-06 13:36:30 -0700843 Error error = Error::NONE;
844 mMutex.lock_shared();
845 if (auto writer = getWriter(display)) {
Brian Lindahldbf7e3a2022-12-16 11:43:39 -0700846 // Backwards compatible way of clearing buffer is to set the layer buffer with a placeholder
847 // buffer, using the slot that needs to cleared... tricky.
848 if (mClearSlotBuffer == nullptr) {
849 writer->get().setLayerBufferSlotsToClear(translate<int64_t>(display),
850 translate<int64_t>(layer), slotsToClear);
851 } else {
852 for (uint32_t slot : slotsToClear) {
853 // Don't clear the active buffer slot because we need to restore the active buffer
854 // after clearing the requested buffer slots with a placeholder buffer.
855 if (slot != activeBufferSlot) {
856 writer->get().setLayerBufferWithNewCommand(translate<int64_t>(display),
857 translate<int64_t>(layer), slot,
858 mClearSlotBuffer->handle,
859 /*fence*/ -1);
860 }
Brian Lindahlb158a5c2022-12-15 15:21:13 -0700861 }
Brian Lindahldbf7e3a2022-12-16 11:43:39 -0700862 // Since we clear buffers by setting them to a placeholder buffer, we want to make
863 // sure that the last setLayerBuffer command is sent with the currently active
864 // buffer, not the placeholder buffer, so that there is no perceptual change when
865 // buffers are discarded.
866 writer->get().setLayerBufferWithNewCommand(translate<int64_t>(display),
867 translate<int64_t>(layer), activeBufferSlot,
868 // The active buffer is still cached in
869 // its slot and doesn't need a fence.
870 /*buffer*/ nullptr, /*fence*/ -1);
Brian Lindahlb158a5c2022-12-15 15:21:13 -0700871 }
Brian Lindahl90553da2022-12-06 13:36:30 -0700872 } else {
873 error = Error::BAD_DISPLAY;
874 }
875 mMutex.unlock_shared();
876 return error;
877}
878
Ady Abrahame7385f72021-09-05 00:54:25 -0700879Error AidlComposer::setLayerSurfaceDamage(Display display, Layer layer,
880 const std::vector<IComposerClient::Rect>& damage) {
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400881 Error error = Error::NONE;
882 mMutex.lock_shared();
883 if (auto writer = getWriter(display)) {
884 writer->get().setLayerSurfaceDamage(translate<int64_t>(display), translate<int64_t>(layer),
885 translate<AidlRect>(damage));
886 } else {
887 error = Error::BAD_DISPLAY;
888 }
889 mMutex.unlock_shared();
890 return error;
Ady Abrahame7385f72021-09-05 00:54:25 -0700891}
892
893Error AidlComposer::setLayerBlendMode(Display display, Layer layer,
894 IComposerClient::BlendMode mode) {
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400895 Error error = Error::NONE;
896 mMutex.lock_shared();
897 if (auto writer = getWriter(display)) {
898 writer->get().setLayerBlendMode(translate<int64_t>(display), translate<int64_t>(layer),
899 translate<BlendMode>(mode));
900 } else {
901 error = Error::BAD_DISPLAY;
902 }
903 mMutex.unlock_shared();
904 return error;
Ady Abrahame7385f72021-09-05 00:54:25 -0700905}
906
Ady Abraham6e60b142022-01-06 18:10:35 -0800907Error AidlComposer::setLayerColor(Display display, Layer layer, const Color& color) {
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400908 Error error = Error::NONE;
909 mMutex.lock_shared();
910 if (auto writer = getWriter(display)) {
911 writer->get().setLayerColor(translate<int64_t>(display), translate<int64_t>(layer), color);
912 } else {
913 error = Error::BAD_DISPLAY;
914 }
915 mMutex.unlock_shared();
916 return error;
Ady Abrahame7385f72021-09-05 00:54:25 -0700917}
918
Leon Scroggins III2e1aa182021-12-01 17:33:12 -0500919Error AidlComposer::setLayerCompositionType(
920 Display display, Layer layer,
921 aidl::android::hardware::graphics::composer3::Composition type) {
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400922 Error error = Error::NONE;
923 mMutex.lock_shared();
924 if (auto writer = getWriter(display)) {
925 writer->get().setLayerCompositionType(translate<int64_t>(display),
926 translate<int64_t>(layer), type);
927 } else {
928 error = Error::BAD_DISPLAY;
929 }
930 mMutex.unlock_shared();
931 return error;
Ady Abrahame7385f72021-09-05 00:54:25 -0700932}
933
934Error AidlComposer::setLayerDataspace(Display display, Layer layer, Dataspace dataspace) {
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400935 Error error = Error::NONE;
936 mMutex.lock_shared();
937 if (auto writer = getWriter(display)) {
938 writer->get().setLayerDataspace(translate<int64_t>(display), translate<int64_t>(layer),
939 translate<AidlDataspace>(dataspace));
940 } else {
941 error = Error::BAD_DISPLAY;
942 }
943 mMutex.unlock_shared();
944 return error;
Ady Abrahame7385f72021-09-05 00:54:25 -0700945}
946
947Error AidlComposer::setLayerDisplayFrame(Display display, Layer layer,
948 const IComposerClient::Rect& frame) {
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400949 Error error = Error::NONE;
950 mMutex.lock_shared();
951 if (auto writer = getWriter(display)) {
952 writer->get().setLayerDisplayFrame(translate<int64_t>(display), translate<int64_t>(layer),
953 translate<AidlRect>(frame));
954 } else {
955 error = Error::BAD_DISPLAY;
956 }
957 mMutex.unlock_shared();
958 return error;
Ady Abrahame7385f72021-09-05 00:54:25 -0700959}
960
961Error AidlComposer::setLayerPlaneAlpha(Display display, Layer layer, float alpha) {
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400962 Error error = Error::NONE;
963 mMutex.lock_shared();
964 if (auto writer = getWriter(display)) {
965 writer->get().setLayerPlaneAlpha(translate<int64_t>(display), translate<int64_t>(layer),
966 alpha);
967 } else {
968 error = Error::BAD_DISPLAY;
969 }
970 mMutex.unlock_shared();
971 return error;
Ady Abrahame7385f72021-09-05 00:54:25 -0700972}
973
974Error AidlComposer::setLayerSidebandStream(Display display, Layer layer,
975 const native_handle_t* stream) {
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400976 Error error = Error::NONE;
977 mMutex.lock_shared();
978 if (auto writer = getWriter(display)) {
979 writer->get().setLayerSidebandStream(translate<int64_t>(display), translate<int64_t>(layer),
980 stream);
981 } else {
982 error = Error::BAD_DISPLAY;
983 }
984 mMutex.unlock_shared();
985 return error;
Ady Abrahame7385f72021-09-05 00:54:25 -0700986}
987
988Error AidlComposer::setLayerSourceCrop(Display display, Layer layer,
989 const IComposerClient::FRect& crop) {
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400990 Error error = Error::NONE;
991 mMutex.lock_shared();
992 if (auto writer = getWriter(display)) {
993 writer->get().setLayerSourceCrop(translate<int64_t>(display), translate<int64_t>(layer),
994 translate<AidlFRect>(crop));
995 } else {
996 error = Error::BAD_DISPLAY;
997 }
998 mMutex.unlock_shared();
999 return error;
Ady Abrahame7385f72021-09-05 00:54:25 -07001000}
1001
1002Error AidlComposer::setLayerTransform(Display display, Layer layer, Transform transform) {
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -04001003 Error error = Error::NONE;
1004 mMutex.lock_shared();
1005 if (auto writer = getWriter(display)) {
1006 writer->get().setLayerTransform(translate<int64_t>(display), translate<int64_t>(layer),
1007 translate<AidlTransform>(transform));
1008 } else {
1009 error = Error::BAD_DISPLAY;
1010 }
1011 mMutex.unlock_shared();
1012 return error;
Ady Abrahame7385f72021-09-05 00:54:25 -07001013}
1014
1015Error AidlComposer::setLayerVisibleRegion(Display display, Layer layer,
1016 const std::vector<IComposerClient::Rect>& visible) {
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -04001017 Error error = Error::NONE;
1018 mMutex.lock_shared();
1019 if (auto writer = getWriter(display)) {
1020 writer->get().setLayerVisibleRegion(translate<int64_t>(display), translate<int64_t>(layer),
1021 translate<AidlRect>(visible));
1022 } else {
1023 error = Error::BAD_DISPLAY;
1024 }
1025 mMutex.unlock_shared();
1026 return error;
Ady Abrahame7385f72021-09-05 00:54:25 -07001027}
1028
1029Error AidlComposer::setLayerZOrder(Display display, Layer layer, uint32_t z) {
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -04001030 Error error = Error::NONE;
1031 mMutex.lock_shared();
1032 if (auto writer = getWriter(display)) {
1033 writer->get().setLayerZOrder(translate<int64_t>(display), translate<int64_t>(layer), z);
1034 } else {
1035 error = Error::BAD_DISPLAY;
1036 }
1037 mMutex.unlock_shared();
1038 return error;
Ady Abrahame7385f72021-09-05 00:54:25 -07001039}
1040
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -04001041Error AidlComposer::execute(Display display) {
1042 auto writer = getWriter(display);
1043 auto reader = getReader(display);
1044 if (!writer || !reader) {
1045 return Error::BAD_DISPLAY;
1046 }
1047
1048 const auto& commands = writer->get().getPendingCommands();
Ady Abrahama6388c02021-11-11 21:11:51 -08001049 if (commands.empty()) {
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -04001050 writer->get().reset();
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
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -04001082 writer->get().reset();
Ady Abrahame7385f72021-09-05 00:54:25 -07001083
1084 return error;
1085}
1086
1087Error AidlComposer::setLayerPerFrameMetadata(
1088 Display display, Layer layer,
1089 const std::vector<IComposerClient::PerFrameMetadata>& perFrameMetadatas) {
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -04001090 Error error = Error::NONE;
1091 mMutex.lock_shared();
1092 if (auto writer = getWriter(display)) {
1093 writer->get().setLayerPerFrameMetadata(translate<int64_t>(display),
1094 translate<int64_t>(layer),
1095 translate<AidlPerFrameMetadata>(perFrameMetadatas));
1096 } else {
1097 error = Error::BAD_DISPLAY;
1098 }
1099 mMutex.unlock_shared();
1100 return error;
Ady Abrahame7385f72021-09-05 00:54:25 -07001101}
1102
1103std::vector<IComposerClient::PerFrameMetadataKey> AidlComposer::getPerFrameMetadataKeys(
1104 Display display) {
1105 std::vector<AidlPerFrameMetadataKey> keys;
1106 const auto status =
1107 mAidlComposerClient->getPerFrameMetadataKeys(translate<int64_t>(display), &keys);
1108 if (!status.isOk()) {
1109 ALOGE("getPerFrameMetadataKeys failed %s", status.getDescription().c_str());
1110 return {};
1111 }
1112 return translate<IComposerClient::PerFrameMetadataKey>(keys);
1113}
1114
1115Error AidlComposer::getRenderIntents(Display display, ColorMode colorMode,
1116 std::vector<RenderIntent>* outRenderIntents) {
1117 std::vector<AidlRenderIntent> renderIntents;
1118 const auto status = mAidlComposerClient->getRenderIntents(translate<int64_t>(display),
1119 translate<AidlColorMode>(colorMode),
1120 &renderIntents);
1121 if (!status.isOk()) {
1122 ALOGE("getRenderIntents failed %s", status.getDescription().c_str());
1123 return static_cast<Error>(status.getServiceSpecificError());
1124 }
1125 *outRenderIntents = translate<RenderIntent>(renderIntents);
1126 return Error::NONE;
1127}
1128
1129Error AidlComposer::getDataspaceSaturationMatrix(Dataspace dataspace, mat4* outMatrix) {
1130 std::vector<float> matrix;
1131 const auto status =
1132 mAidlComposerClient->getDataspaceSaturationMatrix(translate<AidlDataspace>(dataspace),
1133 &matrix);
1134 if (!status.isOk()) {
1135 ALOGE("getDataspaceSaturationMatrix failed %s", status.getDescription().c_str());
1136 return static_cast<Error>(status.getServiceSpecificError());
1137 }
1138 *outMatrix = makeMat4(matrix);
1139 return Error::NONE;
1140}
1141
1142Error AidlComposer::getDisplayIdentificationData(Display display, uint8_t* outPort,
1143 std::vector<uint8_t>* outData) {
1144 AidlDisplayIdentification displayIdentification;
1145 const auto status =
1146 mAidlComposerClient->getDisplayIdentificationData(translate<int64_t>(display),
1147 &displayIdentification);
1148 if (!status.isOk()) {
1149 ALOGE("getDisplayIdentificationData failed %s", status.getDescription().c_str());
1150 return static_cast<Error>(status.getServiceSpecificError());
1151 }
1152
1153 *outPort = static_cast<uint8_t>(displayIdentification.port);
1154 *outData = displayIdentification.data;
1155
1156 return Error::NONE;
1157}
1158
1159Error AidlComposer::setLayerColorTransform(Display display, Layer layer, const float* matrix) {
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -04001160 Error error = Error::NONE;
1161 mMutex.lock_shared();
1162 if (auto writer = getWriter(display)) {
1163 writer->get().setLayerColorTransform(translate<int64_t>(display), translate<int64_t>(layer),
1164 matrix);
1165 } else {
1166 error = Error::BAD_DISPLAY;
1167 }
1168 mMutex.unlock_shared();
1169 return error;
Ady Abrahame7385f72021-09-05 00:54:25 -07001170}
1171
1172Error AidlComposer::getDisplayedContentSamplingAttributes(Display display, PixelFormat* outFormat,
1173 Dataspace* outDataspace,
1174 uint8_t* outComponentMask) {
1175 if (!outFormat || !outDataspace || !outComponentMask) {
1176 return Error::BAD_PARAMETER;
1177 }
1178
1179 AidlDisplayContentSamplingAttributes attributes;
1180 const auto status =
1181 mAidlComposerClient->getDisplayedContentSamplingAttributes(translate<int64_t>(display),
1182 &attributes);
1183 if (!status.isOk()) {
1184 ALOGE("getDisplayedContentSamplingAttributes failed %s", status.getDescription().c_str());
1185 return static_cast<Error>(status.getServiceSpecificError());
1186 }
1187
1188 *outFormat = translate<PixelFormat>(attributes.format);
1189 *outDataspace = translate<Dataspace>(attributes.dataspace);
1190 *outComponentMask = static_cast<uint8_t>(attributes.componentMask);
1191 return Error::NONE;
1192}
1193
1194Error AidlComposer::setDisplayContentSamplingEnabled(Display display, bool enabled,
1195 uint8_t componentMask, uint64_t maxFrames) {
1196 const auto status =
1197 mAidlComposerClient
1198 ->setDisplayedContentSamplingEnabled(translate<int64_t>(display), enabled,
1199 static_cast<AidlFormatColorComponent>(
1200 componentMask),
1201 static_cast<int64_t>(maxFrames));
1202 if (!status.isOk()) {
1203 ALOGE("setDisplayedContentSamplingEnabled failed %s", status.getDescription().c_str());
1204 return static_cast<Error>(status.getServiceSpecificError());
1205 }
1206 return Error::NONE;
1207}
1208
1209Error AidlComposer::getDisplayedContentSample(Display display, uint64_t maxFrames,
1210 uint64_t timestamp, DisplayedFrameStats* outStats) {
1211 if (!outStats) {
1212 return Error::BAD_PARAMETER;
1213 }
1214
1215 AidlDisplayContentSample sample;
1216 const auto status =
1217 mAidlComposerClient->getDisplayedContentSample(translate<int64_t>(display),
1218 static_cast<int64_t>(maxFrames),
1219 static_cast<int64_t>(timestamp),
1220 &sample);
1221 if (!status.isOk()) {
1222 ALOGE("getDisplayedContentSample failed %s", status.getDescription().c_str());
1223 return static_cast<Error>(status.getServiceSpecificError());
1224 }
1225 *outStats = translate<DisplayedFrameStats>(sample);
1226 return Error::NONE;
1227}
1228
1229Error AidlComposer::setLayerPerFrameMetadataBlobs(
1230 Display display, Layer layer,
1231 const std::vector<IComposerClient::PerFrameMetadataBlob>& metadata) {
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -04001232 Error error = Error::NONE;
1233 mMutex.lock_shared();
1234 if (auto writer = getWriter(display)) {
1235 writer->get().setLayerPerFrameMetadataBlobs(translate<int64_t>(display),
1236 translate<int64_t>(layer),
1237 translate<AidlPerFrameMetadataBlob>(metadata));
1238 } else {
1239 error = Error::BAD_DISPLAY;
1240 }
1241 mMutex.unlock_shared();
1242 return error;
Ady Abrahame7385f72021-09-05 00:54:25 -07001243}
1244
Alec Mouri4d8a05d2022-03-23 18:14:26 +00001245Error AidlComposer::setDisplayBrightness(Display display, float brightness, float brightnessNits,
Alec Mouricdf16792021-12-10 13:16:06 -08001246 const DisplayBrightnessOptions& options) {
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -04001247 Error error = Error::NONE;
1248 mMutex.lock_shared();
1249 if (auto writer = getWriter(display)) {
1250 writer->get().setDisplayBrightness(translate<int64_t>(display), brightness, brightnessNits);
Alec Mouricdf16792021-12-10 13:16:06 -08001251
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -04001252 if (options.applyImmediately) {
1253 error = execute(display);
1254 mMutex.unlock_shared();
1255 return error;
1256 }
1257 } else {
1258 error = Error::BAD_DISPLAY;
Alec Mouricdf16792021-12-10 13:16:06 -08001259 }
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -04001260 mMutex.unlock_shared();
1261 return error;
Ady Abrahame7385f72021-09-05 00:54:25 -07001262}
1263
1264Error AidlComposer::getDisplayCapabilities(Display display,
Leon Scroggins III5967aec2021-12-29 11:14:22 -05001265 std::vector<AidlDisplayCapability>* outCapabilities) {
1266 const auto status = mAidlComposerClient->getDisplayCapabilities(translate<int64_t>(display),
1267 outCapabilities);
Ady Abrahame7385f72021-09-05 00:54:25 -07001268 if (!status.isOk()) {
1269 ALOGE("getDisplayCapabilities failed %s", status.getDescription().c_str());
Leon Scroggins III5967aec2021-12-29 11:14:22 -05001270 outCapabilities->clear();
Ady Abrahame7385f72021-09-05 00:54:25 -07001271 return static_cast<Error>(status.getServiceSpecificError());
1272 }
Ady Abrahame7385f72021-09-05 00:54:25 -07001273 return Error::NONE;
1274}
1275
1276V2_4::Error AidlComposer::getDisplayConnectionType(
1277 Display display, IComposerClient::DisplayConnectionType* outType) {
1278 AidlDisplayConnectionType type;
1279 const auto status =
1280 mAidlComposerClient->getDisplayConnectionType(translate<int64_t>(display), &type);
1281 if (!status.isOk()) {
1282 ALOGE("getDisplayConnectionType failed %s", status.getDescription().c_str());
1283 return static_cast<V2_4::Error>(status.getServiceSpecificError());
1284 }
1285 *outType = translate<IComposerClient::DisplayConnectionType>(type);
1286 return V2_4::Error::NONE;
1287}
1288
1289V2_4::Error AidlComposer::getDisplayVsyncPeriod(Display display, VsyncPeriodNanos* outVsyncPeriod) {
1290 int32_t vsyncPeriod;
1291 const auto status =
1292 mAidlComposerClient->getDisplayVsyncPeriod(translate<int64_t>(display), &vsyncPeriod);
1293 if (!status.isOk()) {
1294 ALOGE("getDisplayVsyncPeriod failed %s", status.getDescription().c_str());
1295 return static_cast<V2_4::Error>(status.getServiceSpecificError());
1296 }
1297 *outVsyncPeriod = translate<VsyncPeriodNanos>(vsyncPeriod);
1298 return V2_4::Error::NONE;
1299}
1300
1301V2_4::Error AidlComposer::setActiveConfigWithConstraints(
1302 Display display, Config config,
1303 const IComposerClient::VsyncPeriodChangeConstraints& vsyncPeriodChangeConstraints,
1304 VsyncPeriodChangeTimeline* outTimeline) {
1305 AidlVsyncPeriodChangeTimeline timeline;
1306 const auto status =
1307 mAidlComposerClient
1308 ->setActiveConfigWithConstraints(translate<int64_t>(display),
1309 translate<int32_t>(config),
1310 translate<AidlVsyncPeriodChangeConstraints>(
1311 vsyncPeriodChangeConstraints),
1312 &timeline);
1313 if (!status.isOk()) {
1314 ALOGE("setActiveConfigWithConstraints failed %s", status.getDescription().c_str());
1315 return static_cast<V2_4::Error>(status.getServiceSpecificError());
1316 }
1317 *outTimeline = translate<VsyncPeriodChangeTimeline>(timeline);
1318 return V2_4::Error::NONE;
1319}
1320
1321V2_4::Error AidlComposer::setAutoLowLatencyMode(Display display, bool on) {
1322 const auto status = mAidlComposerClient->setAutoLowLatencyMode(translate<int64_t>(display), on);
1323 if (!status.isOk()) {
1324 ALOGE("setAutoLowLatencyMode failed %s", status.getDescription().c_str());
1325 return static_cast<V2_4::Error>(status.getServiceSpecificError());
1326 }
1327 return V2_4::Error::NONE;
1328}
1329
1330V2_4::Error AidlComposer::getSupportedContentTypes(
1331 Display displayId, std::vector<IComposerClient::ContentType>* outSupportedContentTypes) {
1332 std::vector<AidlContentType> types;
1333 const auto status =
1334 mAidlComposerClient->getSupportedContentTypes(translate<int64_t>(displayId), &types);
1335 if (!status.isOk()) {
1336 ALOGE("getSupportedContentTypes failed %s", status.getDescription().c_str());
1337 return static_cast<V2_4::Error>(status.getServiceSpecificError());
1338 }
1339 *outSupportedContentTypes = translate<IComposerClient::ContentType>(types);
1340 return V2_4::Error::NONE;
1341}
1342
1343V2_4::Error AidlComposer::setContentType(Display display,
1344 IComposerClient::ContentType contentType) {
1345 const auto status =
1346 mAidlComposerClient->setContentType(translate<int64_t>(display),
1347 translate<AidlContentType>(contentType));
1348 if (!status.isOk()) {
1349 ALOGE("setContentType failed %s", status.getDescription().c_str());
1350 return static_cast<V2_4::Error>(status.getServiceSpecificError());
1351 }
1352 return V2_4::Error::NONE;
1353}
1354
Ady Abraham3f976752021-12-20 16:17:50 -08001355V2_4::Error AidlComposer::setLayerGenericMetadata(Display, Layer, const std::string&, bool,
1356 const std::vector<uint8_t>&) {
1357 // There are no users for this API. See b/209691612.
1358 return V2_4::Error::UNSUPPORTED;
Ady Abrahame7385f72021-09-05 00:54:25 -07001359}
1360
1361V2_4::Error AidlComposer::getLayerGenericMetadataKeys(
Ady Abraham3f976752021-12-20 16:17:50 -08001362 std::vector<IComposerClient::LayerGenericMetadataKey>*) {
1363 // There are no users for this API. See b/209691612.
1364 return V2_4::Error::UNSUPPORTED;
Ady Abrahame7385f72021-09-05 00:54:25 -07001365}
1366
Kriti Dang7defaf32021-11-15 11:55:43 +01001367Error AidlComposer::setBootDisplayConfig(Display display, Config config) {
1368 const auto status = mAidlComposerClient->setBootDisplayConfig(translate<int64_t>(display),
1369 translate<int32_t>(config));
1370 if (!status.isOk()) {
1371 ALOGE("setBootDisplayConfig failed %s", status.getDescription().c_str());
1372 return static_cast<Error>(status.getServiceSpecificError());
1373 }
1374 return Error::NONE;
1375}
1376
1377Error AidlComposer::clearBootDisplayConfig(Display display) {
1378 const auto status = mAidlComposerClient->clearBootDisplayConfig(translate<int64_t>(display));
1379 if (!status.isOk()) {
1380 ALOGE("clearBootDisplayConfig failed %s", status.getDescription().c_str());
1381 return static_cast<Error>(status.getServiceSpecificError());
1382 }
1383 return Error::NONE;
1384}
1385
1386Error AidlComposer::getPreferredBootDisplayConfig(Display display, Config* config) {
1387 int32_t displayConfig;
1388 const auto status =
1389 mAidlComposerClient->getPreferredBootDisplayConfig(translate<int64_t>(display),
1390 &displayConfig);
1391 if (!status.isOk()) {
1392 ALOGE("getPreferredBootDisplayConfig failed %s", status.getDescription().c_str());
1393 return static_cast<Error>(status.getServiceSpecificError());
1394 }
1395 *config = translate<uint32_t>(displayConfig);
1396 return Error::NONE;
1397}
1398
Ady Abrahame7385f72021-09-05 00:54:25 -07001399Error AidlComposer::getClientTargetProperty(
Alec Mouri85065692022-03-18 00:58:26 +00001400 Display display, ClientTargetPropertyWithBrightness* outClientTargetProperty) {
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -04001401 Error error = Error::NONE;
1402 mMutex.lock_shared();
1403 if (auto reader = getReader(display)) {
1404 *outClientTargetProperty =
1405 reader->get().takeClientTargetProperty(translate<int64_t>(display));
1406 } else {
1407 error = Error::BAD_DISPLAY;
1408 }
1409 mMutex.unlock_shared();
1410 return error;
Ady Abrahame7385f72021-09-05 00:54:25 -07001411}
1412
Alec Mouri6da0e272022-02-07 12:45:57 -08001413Error AidlComposer::setLayerBrightness(Display display, Layer layer, float brightness) {
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -04001414 Error error = Error::NONE;
1415 mMutex.lock_shared();
1416 if (auto writer = getWriter(display)) {
1417 writer->get().setLayerBrightness(translate<int64_t>(display), translate<int64_t>(layer),
1418 brightness);
1419 } else {
1420 error = Error::BAD_DISPLAY;
1421 }
1422 mMutex.unlock_shared();
1423 return error;
Alec Mouricdf6cbc2021-11-01 17:21:15 -07001424}
1425
Leon Scroggins IIId77d3162022-01-05 10:42:28 -05001426Error AidlComposer::setLayerBlockingRegion(Display display, Layer layer,
1427 const std::vector<IComposerClient::Rect>& blocking) {
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -04001428 Error error = Error::NONE;
1429 mMutex.lock_shared();
1430 if (auto writer = getWriter(display)) {
1431 writer->get().setLayerBlockingRegion(translate<int64_t>(display), translate<int64_t>(layer),
1432 translate<AidlRect>(blocking));
1433 } else {
1434 error = Error::BAD_DISPLAY;
1435 }
1436 mMutex.unlock_shared();
1437 return error;
Leon Scroggins IIId77d3162022-01-05 10:42:28 -05001438}
Leon Scroggins IIIe7c51c62022-02-01 15:53:54 -05001439
1440Error AidlComposer::getDisplayDecorationSupport(Display display,
1441 std::optional<DisplayDecorationSupport>* support) {
1442 const auto status =
1443 mAidlComposerClient->getDisplayDecorationSupport(translate<int64_t>(display), support);
1444 if (!status.isOk()) {
1445 ALOGE("getDisplayDecorationSupport failed %s", status.getDescription().c_str());
1446 support->reset();
1447 return static_cast<Error>(status.getServiceSpecificError());
1448 }
1449 return Error::NONE;
1450}
ramindani32cf0602022-03-02 02:30:29 +00001451
1452Error AidlComposer::setIdleTimerEnabled(Display displayId, std::chrono::milliseconds timeout) {
1453 const auto status =
1454 mAidlComposerClient->setIdleTimerEnabled(translate<int64_t>(displayId),
1455 translate<int32_t>(timeout.count()));
1456 if (!status.isOk()) {
1457 ALOGE("setIdleTimerEnabled failed %s", status.getDescription().c_str());
1458 return static_cast<Error>(status.getServiceSpecificError());
1459 }
1460 return Error::NONE;
1461}
1462
ramindani06e518e2022-03-14 18:47:53 +00001463Error AidlComposer::getPhysicalDisplayOrientation(Display displayId,
1464 AidlTransform* outDisplayOrientation) {
1465 const auto status =
1466 mAidlComposerClient->getDisplayPhysicalOrientation(translate<int64_t>(displayId),
1467 outDisplayOrientation);
1468 if (!status.isOk()) {
1469 ALOGE("getPhysicalDisplayOrientation failed %s", status.getDescription().c_str());
1470 return static_cast<Error>(status.getServiceSpecificError());
1471 }
1472 return Error::NONE;
1473}
1474
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -04001475ftl::Optional<std::reference_wrapper<ComposerClientWriter>> AidlComposer::getWriter(Display display)
1476 REQUIRES_SHARED(mMutex) {
1477 return mWriters.get(display);
1478}
1479
1480ftl::Optional<std::reference_wrapper<ComposerClientReader>> AidlComposer::getReader(Display display)
1481 REQUIRES_SHARED(mMutex) {
1482 if (mSingleReader) {
1483 display = translate<Display>(kSingleReaderKey);
1484 }
1485 return mReaders.get(display);
1486}
1487
1488void AidlComposer::removeDisplay(Display display) {
1489 mMutex.lock();
1490 bool wasErased = mWriters.erase(display);
1491 ALOGW_IF(!wasErased,
1492 "Attempting to remove writer for display %" PRId64 " which is not connected",
1493 translate<int64_t>(display));
1494 if (!mSingleReader) {
1495 removeReader(display);
1496 }
1497 mMutex.unlock();
1498}
1499
1500void AidlComposer::onHotplugDisconnect(Display display) {
1501 removeDisplay(display);
1502}
1503
1504bool AidlComposer::hasMultiThreadedPresentSupport(Display display) {
1505 const auto displayId = translate<int64_t>(display);
1506 std::vector<AidlDisplayCapability> capabilities;
1507 const auto status = mAidlComposerClient->getDisplayCapabilities(displayId, &capabilities);
1508 if (!status.isOk()) {
1509 ALOGE("getDisplayCapabilities failed %s", status.getDescription().c_str());
1510 return false;
1511 }
1512 return std::find(capabilities.begin(), capabilities.end(),
1513 AidlDisplayCapability::MULTI_THREADED_PRESENT) != capabilities.end();
1514}
1515
1516void AidlComposer::addReader(Display display) {
1517 const auto displayId = translate<int64_t>(display);
1518 std::optional<int64_t> displayOpt;
1519 if (displayId != kSingleReaderKey) {
1520 displayOpt.emplace(displayId);
1521 }
1522 auto [it, added] = mReaders.try_emplace(display, std::move(displayOpt));
1523 ALOGW_IF(!added, "Attempting to add writer for display %" PRId64 " which is already connected",
1524 displayId);
1525}
1526
1527void AidlComposer::removeReader(Display display) {
1528 bool wasErased = mReaders.erase(display);
1529 ALOGW_IF(!wasErased,
1530 "Attempting to remove reader for display %" PRId64 " which is not connected",
1531 translate<int64_t>(display));
1532}
1533
1534void AidlComposer::addDisplay(Display display) {
1535 const auto displayId = translate<int64_t>(display);
1536 mMutex.lock();
1537 auto [it, added] = mWriters.try_emplace(display, displayId);
1538 ALOGW_IF(!added, "Attempting to add writer for display %" PRId64 " which is already connected",
1539 displayId);
1540 if (mSingleReader) {
1541 if (hasMultiThreadedPresentSupport(display)) {
1542 mSingleReader = false;
1543 removeReader(translate<Display>(kSingleReaderKey));
1544 // Note that this includes the new display.
1545 for (const auto& [existingDisplay, _] : mWriters) {
1546 addReader(existingDisplay);
1547 }
1548 }
1549 } else {
1550 addReader(display);
1551 }
1552 mMutex.unlock();
1553}
1554
1555void AidlComposer::onHotplugConnect(Display display) {
1556 addDisplay(display);
1557}
Ady Abrahame7385f72021-09-05 00:54:25 -07001558} // namespace Hwc2
1559} // namespace android