blob: 806df871f6104b61a41b3391cbffb6be593d9b0f [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
Ady Abrahame7385f72021-09-05 00:54:25 -0700236 ALOGI("Loaded AIDL composer3 HAL service");
237}
238
239AidlComposer::~AidlComposer() = default;
240
Ady Abraham4d211cf2021-12-14 16:19:03 -0800241bool AidlComposer::isSupported(OptionalFeature feature) const {
242 switch (feature) {
243 case OptionalFeature::RefreshRateSwitching:
Ady Abraham43065bd2021-12-10 17:22:15 -0800244 case OptionalFeature::ExpectedPresentTime:
Alec Mouricdf16792021-12-10 13:16:06 -0800245 case OptionalFeature::DisplayBrightnessCommand:
ramindani32cf0602022-03-02 02:30:29 +0000246 case OptionalFeature::KernelIdleTimer:
ramindani06e518e2022-03-14 18:47:53 +0000247 case OptionalFeature::PhysicalDisplayOrientation:
Ady Abraham4d211cf2021-12-14 16:19:03 -0800248 return true;
249 }
250}
251
Ady Abrahamde549d42022-01-26 19:19:17 -0800252std::vector<Capability> AidlComposer::getCapabilities() {
Ady Abrahame7385f72021-09-05 00:54:25 -0700253 std::vector<Capability> capabilities;
254 const auto status = mAidlComposer->getCapabilities(&capabilities);
255 if (!status.isOk()) {
256 ALOGE("getCapabilities failed %s", status.getDescription().c_str());
257 return {};
258 }
Ady Abrahamde549d42022-01-26 19:19:17 -0800259 return capabilities;
Ady Abrahame7385f72021-09-05 00:54:25 -0700260}
261
262std::string AidlComposer::dumpDebugInfo() {
Ady Abrahamc4acf512022-02-18 17:11:59 -0800263 int pipefds[2];
264 int result = pipe(pipefds);
265 if (result < 0) {
266 ALOGE("dumpDebugInfo: pipe failed: %s", strerror(errno));
Ady Abrahame7385f72021-09-05 00:54:25 -0700267 return {};
268 }
Ady Abrahamc4acf512022-02-18 17:11:59 -0800269
270 std::string str;
yihsing.shen58847c52022-09-23 15:39:30 +0800271 // Use other thread to read pipe to prevent
272 // pipe is full, making HWC be blocked in writing.
273 std::thread t([&]() {
274 base::ReadFdToString(pipefds[0], &str);
275 });
Ady Abrahamc4acf512022-02-18 17:11:59 -0800276 const auto status = mAidlComposer->dump(pipefds[1], /*args*/ nullptr, /*numArgs*/ 0);
277 // Close the write-end of the pipe to make sure that when reading from the
278 // read-end we will get eof instead of blocking forever
279 close(pipefds[1]);
280
yihsing.shen58847c52022-09-23 15:39:30 +0800281 if (status != STATUS_OK) {
Ady Abrahamc4acf512022-02-18 17:11:59 -0800282 ALOGE("dumpDebugInfo: dump failed: %d", status);
283 }
284
yihsing.shen58847c52022-09-23 15:39:30 +0800285 t.join();
Ady Abrahamc4acf512022-02-18 17:11:59 -0800286 close(pipefds[0]);
287 return str;
Ady Abrahame7385f72021-09-05 00:54:25 -0700288}
289
Yichi Chen3401b562022-01-17 15:42:35 +0800290void AidlComposer::registerCallback(HWC2::ComposerCallback& callback) {
Ady Abrahame7385f72021-09-05 00:54:25 -0700291 if (mAidlComposerCallback) {
292 ALOGE("Callback already registered");
293 }
Yichi Chen3401b562022-01-17 15:42:35 +0800294
Ady Abraham9fc28052021-10-14 17:21:38 -0700295 mAidlComposerCallback = ndk::SharedRefBase::make<AidlIComposerCallbackWrapper>(callback);
Ady Abrahame7385f72021-09-05 00:54:25 -0700296 AIBinder_setMinSchedulerPolicy(mAidlComposerCallback->asBinder().get(), SCHED_FIFO, 2);
297
298 const auto status = mAidlComposerClient->registerCallback(mAidlComposerCallback);
299 if (!status.isOk()) {
300 ALOGE("registerCallback failed %s", status.getDescription().c_str());
301 }
302}
303
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400304void AidlComposer::resetCommands(Display display) {
305 mMutex.lock_shared();
306 if (auto writer = getWriter(display)) {
307 writer->get().reset();
308 }
309 mMutex.unlock_shared();
Ady Abrahame7385f72021-09-05 00:54:25 -0700310}
311
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400312Error AidlComposer::executeCommands(Display display) {
313 mMutex.lock_shared();
314 auto error = execute(display);
315 mMutex.unlock_shared();
316 return error;
Ady Abrahame7385f72021-09-05 00:54:25 -0700317}
318
319uint32_t AidlComposer::getMaxVirtualDisplayCount() {
320 int32_t count = 0;
321 const auto status = mAidlComposerClient->getMaxVirtualDisplayCount(&count);
322 if (!status.isOk()) {
323 ALOGE("getMaxVirtualDisplayCount failed %s", status.getDescription().c_str());
324 return 0;
325 }
326 return static_cast<uint32_t>(count);
327}
328
329Error AidlComposer::createVirtualDisplay(uint32_t width, uint32_t height, PixelFormat* format,
330 Display* outDisplay) {
331 using AidlPixelFormat = aidl::android::hardware::graphics::common::PixelFormat;
332 const int32_t bufferSlotCount = 1;
333 VirtualDisplay virtualDisplay;
334 const auto status =
335 mAidlComposerClient->createVirtualDisplay(static_cast<int32_t>(width),
336 static_cast<int32_t>(height),
337 static_cast<AidlPixelFormat>(*format),
338 bufferSlotCount, &virtualDisplay);
339
340 if (!status.isOk()) {
341 ALOGE("createVirtualDisplay failed %s", status.getDescription().c_str());
342 return static_cast<Error>(status.getServiceSpecificError());
343 }
344
345 *outDisplay = translate<Display>(virtualDisplay.display);
346 *format = static_cast<PixelFormat>(virtualDisplay.format);
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400347 addDisplay(translate<Display>(virtualDisplay.display));
Ady Abrahame7385f72021-09-05 00:54:25 -0700348 return Error::NONE;
349}
350
351Error AidlComposer::destroyVirtualDisplay(Display display) {
352 const auto status = mAidlComposerClient->destroyVirtualDisplay(translate<int64_t>(display));
353 if (!status.isOk()) {
354 ALOGE("destroyVirtualDisplay failed %s", status.getDescription().c_str());
355 return static_cast<Error>(status.getServiceSpecificError());
356 }
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400357 removeDisplay(display);
Ady Abrahame7385f72021-09-05 00:54:25 -0700358 return Error::NONE;
359}
360
361Error AidlComposer::acceptDisplayChanges(Display display) {
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400362 Error error = Error::NONE;
363 mMutex.lock_shared();
364 if (auto writer = getWriter(display)) {
365 writer->get().acceptDisplayChanges(translate<int64_t>(display));
366 } else {
367 error = Error::BAD_DISPLAY;
368 }
369 mMutex.unlock_shared();
370 return error;
Ady Abrahame7385f72021-09-05 00:54:25 -0700371}
372
373Error AidlComposer::createLayer(Display display, Layer* outLayer) {
374 int64_t layer;
375 const auto status = mAidlComposerClient->createLayer(translate<int64_t>(display),
376 kMaxLayerBufferCount, &layer);
377 if (!status.isOk()) {
378 ALOGE("createLayer failed %s", status.getDescription().c_str());
379 return static_cast<Error>(status.getServiceSpecificError());
380 }
381
382 *outLayer = translate<Layer>(layer);
383 return Error::NONE;
384}
385
386Error AidlComposer::destroyLayer(Display display, Layer layer) {
387 const auto status = mAidlComposerClient->destroyLayer(translate<int64_t>(display),
388 translate<int64_t>(layer));
389 if (!status.isOk()) {
390 ALOGE("destroyLayer failed %s", status.getDescription().c_str());
391 return static_cast<Error>(status.getServiceSpecificError());
392 }
393 return Error::NONE;
394}
395
396Error AidlComposer::getActiveConfig(Display display, Config* outConfig) {
397 int32_t config;
398 const auto status = mAidlComposerClient->getActiveConfig(translate<int64_t>(display), &config);
399 if (!status.isOk()) {
400 ALOGE("getActiveConfig failed %s", status.getDescription().c_str());
401 return static_cast<Error>(status.getServiceSpecificError());
402 }
403 *outConfig = translate<Config>(config);
404 return Error::NONE;
405}
406
407Error AidlComposer::getChangedCompositionTypes(
408 Display display, std::vector<Layer>* outLayers,
Leon Scroggins III2e1aa182021-12-01 17:33:12 -0500409 std::vector<aidl::android::hardware::graphics::composer3::Composition>* outTypes) {
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400410 std::vector<ChangedCompositionLayer> changedLayers;
411 Error error = Error::NONE;
412 {
413 mMutex.lock_shared();
414 if (auto reader = getReader(display)) {
415 changedLayers = reader->get().takeChangedCompositionTypes(translate<int64_t>(display));
416 } else {
417 error = Error::BAD_DISPLAY;
418 }
419 mMutex.unlock_shared();
420 }
Ady Abrahamde792782021-12-20 10:00:49 -0800421 outLayers->reserve(changedLayers.size());
422 outTypes->reserve(changedLayers.size());
Ady Abrahama6388c02021-11-11 21:11:51 -0800423
Ady Abrahamde792782021-12-20 10:00:49 -0800424 for (const auto& layer : changedLayers) {
425 outLayers->emplace_back(translate<Layer>(layer.layer));
426 outTypes->emplace_back(layer.composition);
427 }
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400428 return error;
Ady Abrahame7385f72021-09-05 00:54:25 -0700429}
430
431Error AidlComposer::getColorModes(Display display, std::vector<ColorMode>* outModes) {
432 std::vector<AidlColorMode> modes;
433 const auto status = mAidlComposerClient->getColorModes(translate<int64_t>(display), &modes);
434 if (!status.isOk()) {
435 ALOGE("getColorModes failed %s", status.getDescription().c_str());
436 return static_cast<Error>(status.getServiceSpecificError());
437 }
438 *outModes = translate<ColorMode>(modes);
439 return Error::NONE;
440}
441
442Error AidlComposer::getDisplayAttribute(Display display, Config config,
443 IComposerClient::Attribute attribute, int32_t* outValue) {
444 const auto status =
445 mAidlComposerClient->getDisplayAttribute(translate<int64_t>(display),
446 translate<int32_t>(config),
447 static_cast<AidlDisplayAttribute>(attribute),
448 outValue);
449 if (!status.isOk()) {
450 ALOGE("getDisplayAttribute failed %s", status.getDescription().c_str());
451 return static_cast<Error>(status.getServiceSpecificError());
452 }
453 return Error::NONE;
454}
455
456Error AidlComposer::getDisplayConfigs(Display display, std::vector<Config>* outConfigs) {
457 std::vector<int32_t> configs;
458 const auto status =
459 mAidlComposerClient->getDisplayConfigs(translate<int64_t>(display), &configs);
460 if (!status.isOk()) {
461 ALOGE("getDisplayConfigs failed %s", status.getDescription().c_str());
462 return static_cast<Error>(status.getServiceSpecificError());
463 }
464 *outConfigs = translate<Config>(configs);
465 return Error::NONE;
466}
467
468Error AidlComposer::getDisplayName(Display display, std::string* outName) {
469 const auto status = mAidlComposerClient->getDisplayName(translate<int64_t>(display), outName);
470 if (!status.isOk()) {
471 ALOGE("getDisplayName failed %s", status.getDescription().c_str());
472 return static_cast<Error>(status.getServiceSpecificError());
473 }
474 return Error::NONE;
475}
476
477Error AidlComposer::getDisplayRequests(Display display, uint32_t* outDisplayRequestMask,
478 std::vector<Layer>* outLayers,
479 std::vector<uint32_t>* outLayerRequestMasks) {
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400480 Error error = Error::NONE;
481 DisplayRequest displayRequests;
482 {
483 mMutex.lock_shared();
484 if (auto reader = getReader(display)) {
485 displayRequests = reader->get().takeDisplayRequests(translate<int64_t>(display));
486 } else {
487 error = Error::BAD_DISPLAY;
488 }
489 mMutex.unlock_shared();
490 }
Ady Abrahamde792782021-12-20 10:00:49 -0800491 *outDisplayRequestMask = translate<uint32_t>(displayRequests.mask);
492 outLayers->reserve(displayRequests.layerRequests.size());
493 outLayerRequestMasks->reserve(displayRequests.layerRequests.size());
494
495 for (const auto& layer : displayRequests.layerRequests) {
496 outLayers->emplace_back(translate<Layer>(layer.layer));
497 outLayerRequestMasks->emplace_back(translate<uint32_t>(layer.mask));
498 }
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400499 return error;
Ady Abrahame7385f72021-09-05 00:54:25 -0700500}
501
502Error AidlComposer::getDozeSupport(Display display, bool* outSupport) {
Ady Abraham33b92b92021-12-08 18:30:27 -0800503 std::vector<AidlDisplayCapability> capabilities;
Ady Abrahame7385f72021-09-05 00:54:25 -0700504 const auto status =
Ady Abraham33b92b92021-12-08 18:30:27 -0800505 mAidlComposerClient->getDisplayCapabilities(translate<int64_t>(display), &capabilities);
Ady Abrahame7385f72021-09-05 00:54:25 -0700506 if (!status.isOk()) {
Ady Abraham33b92b92021-12-08 18:30:27 -0800507 ALOGE("getDisplayCapabilities failed %s", status.getDescription().c_str());
Ady Abrahame7385f72021-09-05 00:54:25 -0700508 return static_cast<Error>(status.getServiceSpecificError());
509 }
Ady Abraham33b92b92021-12-08 18:30:27 -0800510 *outSupport = std::find(capabilities.begin(), capabilities.end(),
511 AidlDisplayCapability::DOZE) != capabilities.end();
Ady Abrahame7385f72021-09-05 00:54:25 -0700512 return Error::NONE;
513}
514
ramindani32cf0602022-03-02 02:30:29 +0000515Error AidlComposer::hasDisplayIdleTimerCapability(Display display, bool* outSupport) {
516 std::vector<AidlDisplayCapability> capabilities;
517 const auto status =
518 mAidlComposerClient->getDisplayCapabilities(translate<int64_t>(display), &capabilities);
519 if (!status.isOk()) {
520 ALOGE("getDisplayCapabilities failed %s", status.getDescription().c_str());
521 return static_cast<Error>(status.getServiceSpecificError());
522 }
523 *outSupport = std::find(capabilities.begin(), capabilities.end(),
524 AidlDisplayCapability::DISPLAY_IDLE_TIMER) != capabilities.end();
525 return Error::NONE;
526}
527
Ady Abrahame7385f72021-09-05 00:54:25 -0700528Error AidlComposer::getHdrCapabilities(Display display, std::vector<Hdr>* outTypes,
529 float* outMaxLuminance, float* outMaxAverageLuminance,
530 float* outMinLuminance) {
531 AidlHdrCapabilities capabilities;
532 const auto status =
533 mAidlComposerClient->getHdrCapabilities(translate<int64_t>(display), &capabilities);
534 if (!status.isOk()) {
535 ALOGE("getHdrCapabilities failed %s", status.getDescription().c_str());
536 return static_cast<Error>(status.getServiceSpecificError());
537 }
538
Marc Kassisbdf7e4b2022-11-04 17:26:48 +0100539 *outTypes = capabilities.types;
Ady Abrahame7385f72021-09-05 00:54:25 -0700540 *outMaxLuminance = capabilities.maxLuminance;
541 *outMaxAverageLuminance = capabilities.maxAverageLuminance;
542 *outMinLuminance = capabilities.minLuminance;
543 return Error::NONE;
544}
545
Sally Qibb866c12022-10-17 11:31:20 -0700546Error AidlComposer::getOverlaySupport(AidlOverlayProperties* outProperties) {
547 const auto status = mAidlComposerClient->getOverlaySupport(outProperties);
548 if (!status.isOk()) {
549 ALOGE("getOverlaySupport failed %s", status.getDescription().c_str());
550 return static_cast<Error>(status.getServiceSpecificError());
551 }
Sally Qi0cbd08b2022-08-17 12:12:28 -0700552 return Error::NONE;
553}
554
Ady Abrahame7385f72021-09-05 00:54:25 -0700555Error AidlComposer::getReleaseFences(Display display, std::vector<Layer>* outLayers,
556 std::vector<int>* outReleaseFences) {
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400557 Error error = Error::NONE;
558 std::vector<ReleaseFences::Layer> fences;
559 {
560 mMutex.lock_shared();
561 if (auto reader = getReader(display)) {
562 fences = reader->get().takeReleaseFences(translate<int64_t>(display));
563 } else {
564 error = Error::BAD_DISPLAY;
565 }
566 mMutex.unlock_shared();
567 }
Ady Abrahamde792782021-12-20 10:00:49 -0800568 outLayers->reserve(fences.size());
569 outReleaseFences->reserve(fences.size());
570
571 for (auto& fence : fences) {
572 outLayers->emplace_back(translate<Layer>(fence.layer));
573 // take ownership
574 const int fenceOwner = fence.fence.get();
575 *fence.fence.getR() = -1;
576 outReleaseFences->emplace_back(fenceOwner);
577 }
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400578 return error;
Ady Abrahame7385f72021-09-05 00:54:25 -0700579}
580
581Error AidlComposer::presentDisplay(Display display, int* outPresentFence) {
Leon Scroggins IIIe85e16e2022-12-12 12:51:18 -0500582 const auto displayId = translate<int64_t>(display);
583 ATRACE_FORMAT("HwcPresentDisplay %" PRId64, displayId);
584
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400585 Error error = Error::NONE;
586 mMutex.lock_shared();
587 auto writer = getWriter(display);
588 auto reader = getReader(display);
589 if (writer && reader) {
Leon Scroggins IIIe85e16e2022-12-12 12:51:18 -0500590 writer->get().presentDisplay(displayId);
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400591 error = execute(display);
592 } else {
593 error = Error::BAD_DISPLAY;
594 }
Ady Abrahame7385f72021-09-05 00:54:25 -0700595
Ady Abrahame7385f72021-09-05 00:54:25 -0700596 if (error != Error::NONE) {
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400597 mMutex.unlock_shared();
Ady Abrahame7385f72021-09-05 00:54:25 -0700598 return error;
599 }
600
Leon Scroggins IIIe85e16e2022-12-12 12:51:18 -0500601 auto fence = reader->get().takePresentFence(displayId);
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400602 mMutex.unlock_shared();
Ady Abrahamde792782021-12-20 10:00:49 -0800603 // take ownership
604 *outPresentFence = fence.get();
605 *fence.getR() = -1;
Ady Abrahame7385f72021-09-05 00:54:25 -0700606 return Error::NONE;
607}
608
609Error AidlComposer::setActiveConfig(Display display, Config config) {
610 const auto status = mAidlComposerClient->setActiveConfig(translate<int64_t>(display),
611 translate<int32_t>(config));
612 if (!status.isOk()) {
613 ALOGE("setActiveConfig failed %s", status.getDescription().c_str());
614 return static_cast<Error>(status.getServiceSpecificError());
615 }
616 return Error::NONE;
617}
618
619Error AidlComposer::setClientTarget(Display display, uint32_t slot, const sp<GraphicBuffer>& target,
620 int acquireFence, Dataspace dataspace,
621 const std::vector<IComposerClient::Rect>& damage) {
Ady Abrahame7385f72021-09-05 00:54:25 -0700622 const native_handle_t* handle = nullptr;
623 if (target.get()) {
624 handle = target->getNativeBuffer()->handle;
625 }
626
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400627 Error error = Error::NONE;
628 mMutex.lock_shared();
629 if (auto writer = getWriter(display)) {
630 writer->get()
631 .setClientTarget(translate<int64_t>(display), slot, handle, acquireFence,
632 translate<aidl::android::hardware::graphics::common::Dataspace>(
633 dataspace),
634 translate<AidlRect>(damage));
635 } else {
636 error = Error::BAD_DISPLAY;
637 }
638 mMutex.unlock_shared();
639 return error;
Ady Abrahame7385f72021-09-05 00:54:25 -0700640}
641
642Error AidlComposer::setColorMode(Display display, ColorMode mode, RenderIntent renderIntent) {
643 const auto status =
644 mAidlComposerClient->setColorMode(translate<int64_t>(display),
645 translate<AidlColorMode>(mode),
646 translate<AidlRenderIntent>(renderIntent));
647 if (!status.isOk()) {
648 ALOGE("setColorMode failed %s", status.getDescription().c_str());
649 return static_cast<Error>(status.getServiceSpecificError());
650 }
651 return Error::NONE;
652}
653
Ady Abrahamdc011a92021-12-21 14:06:44 -0800654Error AidlComposer::setColorTransform(Display display, const float* matrix) {
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400655 auto error = Error::NONE;
656 mMutex.lock_shared();
657 if (auto writer = getWriter(display)) {
658 writer->get().setColorTransform(translate<int64_t>(display), matrix);
659 } else {
660 error = Error::BAD_DISPLAY;
661 }
662 mMutex.unlock_shared();
663 return error;
Ady Abrahame7385f72021-09-05 00:54:25 -0700664}
665
666Error AidlComposer::setOutputBuffer(Display display, const native_handle_t* buffer,
667 int releaseFence) {
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400668 auto error = Error::NONE;
669 mMutex.lock_shared();
670 if (auto writer = getWriter(display)) {
671 writer->get().setOutputBuffer(translate<int64_t>(display), 0, buffer, dup(releaseFence));
672 } else {
673 error = Error::BAD_DISPLAY;
674 }
675 mMutex.unlock_shared();
676 return error;
Ady Abrahame7385f72021-09-05 00:54:25 -0700677}
678
679Error AidlComposer::setPowerMode(Display display, IComposerClient::PowerMode mode) {
680 const auto status = mAidlComposerClient->setPowerMode(translate<int64_t>(display),
681 translate<PowerMode>(mode));
682 if (!status.isOk()) {
683 ALOGE("setPowerMode failed %s", status.getDescription().c_str());
684 return static_cast<Error>(status.getServiceSpecificError());
685 }
686 return Error::NONE;
687}
688
689Error AidlComposer::setVsyncEnabled(Display display, IComposerClient::Vsync enabled) {
690 const bool enableVsync = enabled == IComposerClient::Vsync::ENABLE;
691 const auto status =
692 mAidlComposerClient->setVsyncEnabled(translate<int64_t>(display), enableVsync);
693 if (!status.isOk()) {
694 ALOGE("setVsyncEnabled failed %s", status.getDescription().c_str());
695 return static_cast<Error>(status.getServiceSpecificError());
696 }
697 return Error::NONE;
698}
699
700Error AidlComposer::setClientTargetSlotCount(Display display) {
701 const int32_t bufferSlotCount = BufferQueue::NUM_BUFFER_SLOTS;
702 const auto status = mAidlComposerClient->setClientTargetSlotCount(translate<int64_t>(display),
703 bufferSlotCount);
704 if (!status.isOk()) {
705 ALOGE("setClientTargetSlotCount failed %s", status.getDescription().c_str());
706 return static_cast<Error>(status.getServiceSpecificError());
707 }
708 return Error::NONE;
709}
710
Ady Abraham43065bd2021-12-10 17:22:15 -0800711Error AidlComposer::validateDisplay(Display display, nsecs_t expectedPresentTime,
712 uint32_t* outNumTypes, uint32_t* outNumRequests) {
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400713 const auto displayId = translate<int64_t>(display);
Leon Scroggins IIIe85e16e2022-12-12 12:51:18 -0500714 ATRACE_FORMAT("HwcValidateDisplay %" PRId64, displayId);
715
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400716 Error error = Error::NONE;
717 mMutex.lock_shared();
718 auto writer = getWriter(display);
719 auto reader = getReader(display);
720 if (writer && reader) {
721 writer->get().validateDisplay(displayId, ClockMonotonicTimestamp{expectedPresentTime});
722 error = execute(display);
723 } else {
724 error = Error::BAD_DISPLAY;
725 }
Ady Abrahame7385f72021-09-05 00:54:25 -0700726
Ady Abrahame7385f72021-09-05 00:54:25 -0700727 if (error != Error::NONE) {
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400728 mMutex.unlock_shared();
Ady Abrahame7385f72021-09-05 00:54:25 -0700729 return error;
730 }
731
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400732 reader->get().hasChanges(displayId, outNumTypes, outNumRequests);
Ady Abrahame7385f72021-09-05 00:54:25 -0700733
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400734 mMutex.unlock_shared();
Ady Abrahame7385f72021-09-05 00:54:25 -0700735 return Error::NONE;
736}
737
Ady Abraham43065bd2021-12-10 17:22:15 -0800738Error AidlComposer::presentOrValidateDisplay(Display display, nsecs_t expectedPresentTime,
739 uint32_t* outNumTypes, uint32_t* outNumRequests,
740 int* outPresentFence, uint32_t* state) {
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400741 const auto displayId = translate<int64_t>(display);
Leon Scroggins IIIe85e16e2022-12-12 12:51:18 -0500742 ATRACE_FORMAT("HwcPresentOrValidateDisplay %" PRId64, displayId);
743
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400744 Error error = Error::NONE;
745 mMutex.lock_shared();
746 auto writer = getWriter(display);
747 auto reader = getReader(display);
748 if (writer && reader) {
749 writer->get().presentOrvalidateDisplay(displayId,
750 ClockMonotonicTimestamp{expectedPresentTime});
751 error = execute(display);
752 } else {
753 error = Error::BAD_DISPLAY;
754 }
Ady Abrahame7385f72021-09-05 00:54:25 -0700755
Ady Abrahame7385f72021-09-05 00:54:25 -0700756 if (error != Error::NONE) {
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400757 mMutex.unlock_shared();
Ady Abrahame7385f72021-09-05 00:54:25 -0700758 return error;
759 }
760
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400761 const auto result = reader->get().takePresentOrValidateStage(displayId);
Ady Abrahamde792782021-12-20 10:00:49 -0800762 if (!result.has_value()) {
763 *state = translate<uint32_t>(-1);
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400764 mMutex.unlock_shared();
Ady Abrahamde792782021-12-20 10:00:49 -0800765 return Error::NO_RESOURCES;
Ady Abrahame7385f72021-09-05 00:54:25 -0700766 }
767
Ady Abrahamde792782021-12-20 10:00:49 -0800768 *state = translate<uint32_t>(*result);
769
770 if (*result == PresentOrValidate::Result::Presented) {
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400771 auto fence = reader->get().takePresentFence(displayId);
Ady Abrahamde792782021-12-20 10:00:49 -0800772 // take ownership
773 *outPresentFence = fence.get();
774 *fence.getR() = -1;
775 }
776
777 if (*result == PresentOrValidate::Result::Validated) {
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400778 reader->get().hasChanges(displayId, outNumTypes, outNumRequests);
Ady Abrahame7385f72021-09-05 00:54:25 -0700779 }
780
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400781 mMutex.unlock_shared();
Ady Abrahame7385f72021-09-05 00:54:25 -0700782 return Error::NONE;
783}
784
785Error AidlComposer::setCursorPosition(Display display, Layer layer, int32_t x, int32_t y) {
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400786 Error error = Error::NONE;
787 mMutex.lock_shared();
788 if (auto writer = getWriter(display)) {
789 writer->get().setLayerCursorPosition(translate<int64_t>(display), translate<int64_t>(layer),
790 x, y);
791 } else {
792 error = Error::BAD_DISPLAY;
793 }
794 mMutex.unlock_shared();
795 return error;
Ady Abrahame7385f72021-09-05 00:54:25 -0700796}
797
798Error AidlComposer::setLayerBuffer(Display display, Layer layer, uint32_t slot,
799 const sp<GraphicBuffer>& buffer, int acquireFence) {
Ady Abrahame7385f72021-09-05 00:54:25 -0700800 const native_handle_t* handle = nullptr;
801 if (buffer.get()) {
802 handle = buffer->getNativeBuffer()->handle;
803 }
804
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().setLayerBuffer(translate<int64_t>(display), translate<int64_t>(layer), slot,
809 handle, acquireFence);
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::setLayerSurfaceDamage(Display display, Layer layer,
818 const std::vector<IComposerClient::Rect>& damage) {
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400819 Error error = Error::NONE;
820 mMutex.lock_shared();
821 if (auto writer = getWriter(display)) {
822 writer->get().setLayerSurfaceDamage(translate<int64_t>(display), translate<int64_t>(layer),
823 translate<AidlRect>(damage));
824 } else {
825 error = Error::BAD_DISPLAY;
826 }
827 mMutex.unlock_shared();
828 return error;
Ady Abrahame7385f72021-09-05 00:54:25 -0700829}
830
831Error AidlComposer::setLayerBlendMode(Display display, Layer layer,
832 IComposerClient::BlendMode mode) {
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400833 Error error = Error::NONE;
834 mMutex.lock_shared();
835 if (auto writer = getWriter(display)) {
836 writer->get().setLayerBlendMode(translate<int64_t>(display), translate<int64_t>(layer),
837 translate<BlendMode>(mode));
838 } else {
839 error = Error::BAD_DISPLAY;
840 }
841 mMutex.unlock_shared();
842 return error;
Ady Abrahame7385f72021-09-05 00:54:25 -0700843}
844
Ady Abraham6e60b142022-01-06 18:10:35 -0800845Error AidlComposer::setLayerColor(Display display, Layer layer, const Color& color) {
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400846 Error error = Error::NONE;
847 mMutex.lock_shared();
848 if (auto writer = getWriter(display)) {
849 writer->get().setLayerColor(translate<int64_t>(display), translate<int64_t>(layer), color);
850 } else {
851 error = Error::BAD_DISPLAY;
852 }
853 mMutex.unlock_shared();
854 return error;
Ady Abrahame7385f72021-09-05 00:54:25 -0700855}
856
Leon Scroggins III2e1aa182021-12-01 17:33:12 -0500857Error AidlComposer::setLayerCompositionType(
858 Display display, Layer layer,
859 aidl::android::hardware::graphics::composer3::Composition type) {
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400860 Error error = Error::NONE;
861 mMutex.lock_shared();
862 if (auto writer = getWriter(display)) {
863 writer->get().setLayerCompositionType(translate<int64_t>(display),
864 translate<int64_t>(layer), type);
865 } else {
866 error = Error::BAD_DISPLAY;
867 }
868 mMutex.unlock_shared();
869 return error;
Ady Abrahame7385f72021-09-05 00:54:25 -0700870}
871
872Error AidlComposer::setLayerDataspace(Display display, Layer layer, Dataspace dataspace) {
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400873 Error error = Error::NONE;
874 mMutex.lock_shared();
875 if (auto writer = getWriter(display)) {
876 writer->get().setLayerDataspace(translate<int64_t>(display), translate<int64_t>(layer),
877 translate<AidlDataspace>(dataspace));
878 } else {
879 error = Error::BAD_DISPLAY;
880 }
881 mMutex.unlock_shared();
882 return error;
Ady Abrahame7385f72021-09-05 00:54:25 -0700883}
884
885Error AidlComposer::setLayerDisplayFrame(Display display, Layer layer,
886 const IComposerClient::Rect& frame) {
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400887 Error error = Error::NONE;
888 mMutex.lock_shared();
889 if (auto writer = getWriter(display)) {
890 writer->get().setLayerDisplayFrame(translate<int64_t>(display), translate<int64_t>(layer),
891 translate<AidlRect>(frame));
892 } else {
893 error = Error::BAD_DISPLAY;
894 }
895 mMutex.unlock_shared();
896 return error;
Ady Abrahame7385f72021-09-05 00:54:25 -0700897}
898
899Error AidlComposer::setLayerPlaneAlpha(Display display, Layer layer, float alpha) {
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400900 Error error = Error::NONE;
901 mMutex.lock_shared();
902 if (auto writer = getWriter(display)) {
903 writer->get().setLayerPlaneAlpha(translate<int64_t>(display), translate<int64_t>(layer),
904 alpha);
905 } else {
906 error = Error::BAD_DISPLAY;
907 }
908 mMutex.unlock_shared();
909 return error;
Ady Abrahame7385f72021-09-05 00:54:25 -0700910}
911
912Error AidlComposer::setLayerSidebandStream(Display display, Layer layer,
913 const native_handle_t* stream) {
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400914 Error error = Error::NONE;
915 mMutex.lock_shared();
916 if (auto writer = getWriter(display)) {
917 writer->get().setLayerSidebandStream(translate<int64_t>(display), translate<int64_t>(layer),
918 stream);
919 } else {
920 error = Error::BAD_DISPLAY;
921 }
922 mMutex.unlock_shared();
923 return error;
Ady Abrahame7385f72021-09-05 00:54:25 -0700924}
925
926Error AidlComposer::setLayerSourceCrop(Display display, Layer layer,
927 const IComposerClient::FRect& crop) {
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400928 Error error = Error::NONE;
929 mMutex.lock_shared();
930 if (auto writer = getWriter(display)) {
931 writer->get().setLayerSourceCrop(translate<int64_t>(display), translate<int64_t>(layer),
932 translate<AidlFRect>(crop));
933 } else {
934 error = Error::BAD_DISPLAY;
935 }
936 mMutex.unlock_shared();
937 return error;
Ady Abrahame7385f72021-09-05 00:54:25 -0700938}
939
940Error AidlComposer::setLayerTransform(Display display, Layer layer, Transform transform) {
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400941 Error error = Error::NONE;
942 mMutex.lock_shared();
943 if (auto writer = getWriter(display)) {
944 writer->get().setLayerTransform(translate<int64_t>(display), translate<int64_t>(layer),
945 translate<AidlTransform>(transform));
946 } else {
947 error = Error::BAD_DISPLAY;
948 }
949 mMutex.unlock_shared();
950 return error;
Ady Abrahame7385f72021-09-05 00:54:25 -0700951}
952
953Error AidlComposer::setLayerVisibleRegion(Display display, Layer layer,
954 const std::vector<IComposerClient::Rect>& visible) {
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400955 Error error = Error::NONE;
956 mMutex.lock_shared();
957 if (auto writer = getWriter(display)) {
958 writer->get().setLayerVisibleRegion(translate<int64_t>(display), translate<int64_t>(layer),
959 translate<AidlRect>(visible));
960 } else {
961 error = Error::BAD_DISPLAY;
962 }
963 mMutex.unlock_shared();
964 return error;
Ady Abrahame7385f72021-09-05 00:54:25 -0700965}
966
967Error AidlComposer::setLayerZOrder(Display display, Layer layer, uint32_t z) {
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400968 Error error = Error::NONE;
969 mMutex.lock_shared();
970 if (auto writer = getWriter(display)) {
971 writer->get().setLayerZOrder(translate<int64_t>(display), translate<int64_t>(layer), z);
972 } else {
973 error = Error::BAD_DISPLAY;
974 }
975 mMutex.unlock_shared();
976 return error;
Ady Abrahame7385f72021-09-05 00:54:25 -0700977}
978
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400979Error AidlComposer::execute(Display display) {
980 auto writer = getWriter(display);
981 auto reader = getReader(display);
982 if (!writer || !reader) {
983 return Error::BAD_DISPLAY;
984 }
985
986 const auto& commands = writer->get().getPendingCommands();
Ady Abrahama6388c02021-11-11 21:11:51 -0800987 if (commands.empty()) {
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400988 writer->get().reset();
Ady Abrahame7385f72021-09-05 00:54:25 -0700989 return Error::NONE;
990 }
991
Ady Abrahamde792782021-12-20 10:00:49 -0800992 { // scope for results
993 std::vector<CommandResultPayload> results;
994 auto status = mAidlComposerClient->executeCommands(commands, &results);
995 if (!status.isOk()) {
996 ALOGE("executeCommands failed %s", status.getDescription().c_str());
997 return static_cast<Error>(status.getServiceSpecificError());
998 }
Ady Abrahame7385f72021-09-05 00:54:25 -0700999
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -04001000 reader->get().parse(std::move(results));
Ady Abrahamde792782021-12-20 10:00:49 -08001001 }
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -04001002 const auto commandErrors = reader->get().takeErrors();
Ady Abrahama6388c02021-11-11 21:11:51 -08001003 Error error = Error::NONE;
1004 for (const auto& cmdErr : commandErrors) {
1005 const auto index = static_cast<size_t>(cmdErr.commandIndex);
1006 if (index < 0 || index >= commands.size()) {
1007 ALOGE("invalid command index %zu", index);
1008 return Error::BAD_PARAMETER;
Ady Abrahame7385f72021-09-05 00:54:25 -07001009 }
1010
Ady Abrahama6388c02021-11-11 21:11:51 -08001011 const auto& command = commands[index];
Ady Abraham42977362021-12-07 21:04:49 -08001012 if (command.validateDisplay || command.presentDisplay || command.presentOrValidateDisplay) {
1013 error = translate<Error>(cmdErr.errorCode);
1014 } else {
1015 ALOGW("command '%s' generated error %" PRId32, command.toString().c_str(),
1016 cmdErr.errorCode);
Ady Abrahame7385f72021-09-05 00:54:25 -07001017 }
1018 }
1019
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -04001020 writer->get().reset();
Ady Abrahame7385f72021-09-05 00:54:25 -07001021
1022 return error;
1023}
1024
1025Error AidlComposer::setLayerPerFrameMetadata(
1026 Display display, Layer layer,
1027 const std::vector<IComposerClient::PerFrameMetadata>& perFrameMetadatas) {
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -04001028 Error error = Error::NONE;
1029 mMutex.lock_shared();
1030 if (auto writer = getWriter(display)) {
1031 writer->get().setLayerPerFrameMetadata(translate<int64_t>(display),
1032 translate<int64_t>(layer),
1033 translate<AidlPerFrameMetadata>(perFrameMetadatas));
1034 } else {
1035 error = Error::BAD_DISPLAY;
1036 }
1037 mMutex.unlock_shared();
1038 return error;
Ady Abrahame7385f72021-09-05 00:54:25 -07001039}
1040
1041std::vector<IComposerClient::PerFrameMetadataKey> AidlComposer::getPerFrameMetadataKeys(
1042 Display display) {
1043 std::vector<AidlPerFrameMetadataKey> keys;
1044 const auto status =
1045 mAidlComposerClient->getPerFrameMetadataKeys(translate<int64_t>(display), &keys);
1046 if (!status.isOk()) {
1047 ALOGE("getPerFrameMetadataKeys failed %s", status.getDescription().c_str());
1048 return {};
1049 }
1050 return translate<IComposerClient::PerFrameMetadataKey>(keys);
1051}
1052
1053Error AidlComposer::getRenderIntents(Display display, ColorMode colorMode,
1054 std::vector<RenderIntent>* outRenderIntents) {
1055 std::vector<AidlRenderIntent> renderIntents;
1056 const auto status = mAidlComposerClient->getRenderIntents(translate<int64_t>(display),
1057 translate<AidlColorMode>(colorMode),
1058 &renderIntents);
1059 if (!status.isOk()) {
1060 ALOGE("getRenderIntents failed %s", status.getDescription().c_str());
1061 return static_cast<Error>(status.getServiceSpecificError());
1062 }
1063 *outRenderIntents = translate<RenderIntent>(renderIntents);
1064 return Error::NONE;
1065}
1066
1067Error AidlComposer::getDataspaceSaturationMatrix(Dataspace dataspace, mat4* outMatrix) {
1068 std::vector<float> matrix;
1069 const auto status =
1070 mAidlComposerClient->getDataspaceSaturationMatrix(translate<AidlDataspace>(dataspace),
1071 &matrix);
1072 if (!status.isOk()) {
1073 ALOGE("getDataspaceSaturationMatrix failed %s", status.getDescription().c_str());
1074 return static_cast<Error>(status.getServiceSpecificError());
1075 }
1076 *outMatrix = makeMat4(matrix);
1077 return Error::NONE;
1078}
1079
1080Error AidlComposer::getDisplayIdentificationData(Display display, uint8_t* outPort,
1081 std::vector<uint8_t>* outData) {
1082 AidlDisplayIdentification displayIdentification;
1083 const auto status =
1084 mAidlComposerClient->getDisplayIdentificationData(translate<int64_t>(display),
1085 &displayIdentification);
1086 if (!status.isOk()) {
1087 ALOGE("getDisplayIdentificationData failed %s", status.getDescription().c_str());
1088 return static_cast<Error>(status.getServiceSpecificError());
1089 }
1090
1091 *outPort = static_cast<uint8_t>(displayIdentification.port);
1092 *outData = displayIdentification.data;
1093
1094 return Error::NONE;
1095}
1096
1097Error AidlComposer::setLayerColorTransform(Display display, Layer layer, const float* matrix) {
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -04001098 Error error = Error::NONE;
1099 mMutex.lock_shared();
1100 if (auto writer = getWriter(display)) {
1101 writer->get().setLayerColorTransform(translate<int64_t>(display), translate<int64_t>(layer),
1102 matrix);
1103 } else {
1104 error = Error::BAD_DISPLAY;
1105 }
1106 mMutex.unlock_shared();
1107 return error;
Ady Abrahame7385f72021-09-05 00:54:25 -07001108}
1109
1110Error AidlComposer::getDisplayedContentSamplingAttributes(Display display, PixelFormat* outFormat,
1111 Dataspace* outDataspace,
1112 uint8_t* outComponentMask) {
1113 if (!outFormat || !outDataspace || !outComponentMask) {
1114 return Error::BAD_PARAMETER;
1115 }
1116
1117 AidlDisplayContentSamplingAttributes attributes;
1118 const auto status =
1119 mAidlComposerClient->getDisplayedContentSamplingAttributes(translate<int64_t>(display),
1120 &attributes);
1121 if (!status.isOk()) {
1122 ALOGE("getDisplayedContentSamplingAttributes failed %s", status.getDescription().c_str());
1123 return static_cast<Error>(status.getServiceSpecificError());
1124 }
1125
1126 *outFormat = translate<PixelFormat>(attributes.format);
1127 *outDataspace = translate<Dataspace>(attributes.dataspace);
1128 *outComponentMask = static_cast<uint8_t>(attributes.componentMask);
1129 return Error::NONE;
1130}
1131
1132Error AidlComposer::setDisplayContentSamplingEnabled(Display display, bool enabled,
1133 uint8_t componentMask, uint64_t maxFrames) {
1134 const auto status =
1135 mAidlComposerClient
1136 ->setDisplayedContentSamplingEnabled(translate<int64_t>(display), enabled,
1137 static_cast<AidlFormatColorComponent>(
1138 componentMask),
1139 static_cast<int64_t>(maxFrames));
1140 if (!status.isOk()) {
1141 ALOGE("setDisplayedContentSamplingEnabled failed %s", status.getDescription().c_str());
1142 return static_cast<Error>(status.getServiceSpecificError());
1143 }
1144 return Error::NONE;
1145}
1146
1147Error AidlComposer::getDisplayedContentSample(Display display, uint64_t maxFrames,
1148 uint64_t timestamp, DisplayedFrameStats* outStats) {
1149 if (!outStats) {
1150 return Error::BAD_PARAMETER;
1151 }
1152
1153 AidlDisplayContentSample sample;
1154 const auto status =
1155 mAidlComposerClient->getDisplayedContentSample(translate<int64_t>(display),
1156 static_cast<int64_t>(maxFrames),
1157 static_cast<int64_t>(timestamp),
1158 &sample);
1159 if (!status.isOk()) {
1160 ALOGE("getDisplayedContentSample failed %s", status.getDescription().c_str());
1161 return static_cast<Error>(status.getServiceSpecificError());
1162 }
1163 *outStats = translate<DisplayedFrameStats>(sample);
1164 return Error::NONE;
1165}
1166
1167Error AidlComposer::setLayerPerFrameMetadataBlobs(
1168 Display display, Layer layer,
1169 const std::vector<IComposerClient::PerFrameMetadataBlob>& metadata) {
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -04001170 Error error = Error::NONE;
1171 mMutex.lock_shared();
1172 if (auto writer = getWriter(display)) {
1173 writer->get().setLayerPerFrameMetadataBlobs(translate<int64_t>(display),
1174 translate<int64_t>(layer),
1175 translate<AidlPerFrameMetadataBlob>(metadata));
1176 } else {
1177 error = Error::BAD_DISPLAY;
1178 }
1179 mMutex.unlock_shared();
1180 return error;
Ady Abrahame7385f72021-09-05 00:54:25 -07001181}
1182
Alec Mouri4d8a05d2022-03-23 18:14:26 +00001183Error AidlComposer::setDisplayBrightness(Display display, float brightness, float brightnessNits,
Alec Mouricdf16792021-12-10 13:16:06 -08001184 const DisplayBrightnessOptions& options) {
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -04001185 Error error = Error::NONE;
1186 mMutex.lock_shared();
1187 if (auto writer = getWriter(display)) {
1188 writer->get().setDisplayBrightness(translate<int64_t>(display), brightness, brightnessNits);
Alec Mouricdf16792021-12-10 13:16:06 -08001189
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -04001190 if (options.applyImmediately) {
1191 error = execute(display);
1192 mMutex.unlock_shared();
1193 return error;
1194 }
1195 } else {
1196 error = Error::BAD_DISPLAY;
Alec Mouricdf16792021-12-10 13:16:06 -08001197 }
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -04001198 mMutex.unlock_shared();
1199 return error;
Ady Abrahame7385f72021-09-05 00:54:25 -07001200}
1201
1202Error AidlComposer::getDisplayCapabilities(Display display,
Leon Scroggins III5967aec2021-12-29 11:14:22 -05001203 std::vector<AidlDisplayCapability>* outCapabilities) {
1204 const auto status = mAidlComposerClient->getDisplayCapabilities(translate<int64_t>(display),
1205 outCapabilities);
Ady Abrahame7385f72021-09-05 00:54:25 -07001206 if (!status.isOk()) {
1207 ALOGE("getDisplayCapabilities failed %s", status.getDescription().c_str());
Leon Scroggins III5967aec2021-12-29 11:14:22 -05001208 outCapabilities->clear();
Ady Abrahame7385f72021-09-05 00:54:25 -07001209 return static_cast<Error>(status.getServiceSpecificError());
1210 }
Ady Abrahame7385f72021-09-05 00:54:25 -07001211 return Error::NONE;
1212}
1213
1214V2_4::Error AidlComposer::getDisplayConnectionType(
1215 Display display, IComposerClient::DisplayConnectionType* outType) {
1216 AidlDisplayConnectionType type;
1217 const auto status =
1218 mAidlComposerClient->getDisplayConnectionType(translate<int64_t>(display), &type);
1219 if (!status.isOk()) {
1220 ALOGE("getDisplayConnectionType failed %s", status.getDescription().c_str());
1221 return static_cast<V2_4::Error>(status.getServiceSpecificError());
1222 }
1223 *outType = translate<IComposerClient::DisplayConnectionType>(type);
1224 return V2_4::Error::NONE;
1225}
1226
1227V2_4::Error AidlComposer::getDisplayVsyncPeriod(Display display, VsyncPeriodNanos* outVsyncPeriod) {
1228 int32_t vsyncPeriod;
1229 const auto status =
1230 mAidlComposerClient->getDisplayVsyncPeriod(translate<int64_t>(display), &vsyncPeriod);
1231 if (!status.isOk()) {
1232 ALOGE("getDisplayVsyncPeriod failed %s", status.getDescription().c_str());
1233 return static_cast<V2_4::Error>(status.getServiceSpecificError());
1234 }
1235 *outVsyncPeriod = translate<VsyncPeriodNanos>(vsyncPeriod);
1236 return V2_4::Error::NONE;
1237}
1238
1239V2_4::Error AidlComposer::setActiveConfigWithConstraints(
1240 Display display, Config config,
1241 const IComposerClient::VsyncPeriodChangeConstraints& vsyncPeriodChangeConstraints,
1242 VsyncPeriodChangeTimeline* outTimeline) {
1243 AidlVsyncPeriodChangeTimeline timeline;
1244 const auto status =
1245 mAidlComposerClient
1246 ->setActiveConfigWithConstraints(translate<int64_t>(display),
1247 translate<int32_t>(config),
1248 translate<AidlVsyncPeriodChangeConstraints>(
1249 vsyncPeriodChangeConstraints),
1250 &timeline);
1251 if (!status.isOk()) {
1252 ALOGE("setActiveConfigWithConstraints failed %s", status.getDescription().c_str());
1253 return static_cast<V2_4::Error>(status.getServiceSpecificError());
1254 }
1255 *outTimeline = translate<VsyncPeriodChangeTimeline>(timeline);
1256 return V2_4::Error::NONE;
1257}
1258
1259V2_4::Error AidlComposer::setAutoLowLatencyMode(Display display, bool on) {
1260 const auto status = mAidlComposerClient->setAutoLowLatencyMode(translate<int64_t>(display), on);
1261 if (!status.isOk()) {
1262 ALOGE("setAutoLowLatencyMode failed %s", status.getDescription().c_str());
1263 return static_cast<V2_4::Error>(status.getServiceSpecificError());
1264 }
1265 return V2_4::Error::NONE;
1266}
1267
1268V2_4::Error AidlComposer::getSupportedContentTypes(
1269 Display displayId, std::vector<IComposerClient::ContentType>* outSupportedContentTypes) {
1270 std::vector<AidlContentType> types;
1271 const auto status =
1272 mAidlComposerClient->getSupportedContentTypes(translate<int64_t>(displayId), &types);
1273 if (!status.isOk()) {
1274 ALOGE("getSupportedContentTypes failed %s", status.getDescription().c_str());
1275 return static_cast<V2_4::Error>(status.getServiceSpecificError());
1276 }
1277 *outSupportedContentTypes = translate<IComposerClient::ContentType>(types);
1278 return V2_4::Error::NONE;
1279}
1280
1281V2_4::Error AidlComposer::setContentType(Display display,
1282 IComposerClient::ContentType contentType) {
1283 const auto status =
1284 mAidlComposerClient->setContentType(translate<int64_t>(display),
1285 translate<AidlContentType>(contentType));
1286 if (!status.isOk()) {
1287 ALOGE("setContentType failed %s", status.getDescription().c_str());
1288 return static_cast<V2_4::Error>(status.getServiceSpecificError());
1289 }
1290 return V2_4::Error::NONE;
1291}
1292
Ady Abraham3f976752021-12-20 16:17:50 -08001293V2_4::Error AidlComposer::setLayerGenericMetadata(Display, Layer, const std::string&, bool,
1294 const std::vector<uint8_t>&) {
1295 // There are no users for this API. See b/209691612.
1296 return V2_4::Error::UNSUPPORTED;
Ady Abrahame7385f72021-09-05 00:54:25 -07001297}
1298
1299V2_4::Error AidlComposer::getLayerGenericMetadataKeys(
Ady Abraham3f976752021-12-20 16:17:50 -08001300 std::vector<IComposerClient::LayerGenericMetadataKey>*) {
1301 // There are no users for this API. See b/209691612.
1302 return V2_4::Error::UNSUPPORTED;
Ady Abrahame7385f72021-09-05 00:54:25 -07001303}
1304
Kriti Dang7defaf32021-11-15 11:55:43 +01001305Error AidlComposer::setBootDisplayConfig(Display display, Config config) {
1306 const auto status = mAidlComposerClient->setBootDisplayConfig(translate<int64_t>(display),
1307 translate<int32_t>(config));
1308 if (!status.isOk()) {
1309 ALOGE("setBootDisplayConfig failed %s", status.getDescription().c_str());
1310 return static_cast<Error>(status.getServiceSpecificError());
1311 }
1312 return Error::NONE;
1313}
1314
1315Error AidlComposer::clearBootDisplayConfig(Display display) {
1316 const auto status = mAidlComposerClient->clearBootDisplayConfig(translate<int64_t>(display));
1317 if (!status.isOk()) {
1318 ALOGE("clearBootDisplayConfig failed %s", status.getDescription().c_str());
1319 return static_cast<Error>(status.getServiceSpecificError());
1320 }
1321 return Error::NONE;
1322}
1323
1324Error AidlComposer::getPreferredBootDisplayConfig(Display display, Config* config) {
1325 int32_t displayConfig;
1326 const auto status =
1327 mAidlComposerClient->getPreferredBootDisplayConfig(translate<int64_t>(display),
1328 &displayConfig);
1329 if (!status.isOk()) {
1330 ALOGE("getPreferredBootDisplayConfig failed %s", status.getDescription().c_str());
1331 return static_cast<Error>(status.getServiceSpecificError());
1332 }
1333 *config = translate<uint32_t>(displayConfig);
1334 return Error::NONE;
1335}
1336
Ady Abrahame7385f72021-09-05 00:54:25 -07001337Error AidlComposer::getClientTargetProperty(
Alec Mouri85065692022-03-18 00:58:26 +00001338 Display display, ClientTargetPropertyWithBrightness* outClientTargetProperty) {
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -04001339 Error error = Error::NONE;
1340 mMutex.lock_shared();
1341 if (auto reader = getReader(display)) {
1342 *outClientTargetProperty =
1343 reader->get().takeClientTargetProperty(translate<int64_t>(display));
1344 } else {
1345 error = Error::BAD_DISPLAY;
1346 }
1347 mMutex.unlock_shared();
1348 return error;
Ady Abrahame7385f72021-09-05 00:54:25 -07001349}
1350
Alec Mouri6da0e272022-02-07 12:45:57 -08001351Error AidlComposer::setLayerBrightness(Display display, Layer layer, float brightness) {
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -04001352 Error error = Error::NONE;
1353 mMutex.lock_shared();
1354 if (auto writer = getWriter(display)) {
1355 writer->get().setLayerBrightness(translate<int64_t>(display), translate<int64_t>(layer),
1356 brightness);
1357 } else {
1358 error = Error::BAD_DISPLAY;
1359 }
1360 mMutex.unlock_shared();
1361 return error;
Alec Mouricdf6cbc2021-11-01 17:21:15 -07001362}
1363
Leon Scroggins IIId77d3162022-01-05 10:42:28 -05001364Error AidlComposer::setLayerBlockingRegion(Display display, Layer layer,
1365 const std::vector<IComposerClient::Rect>& blocking) {
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -04001366 Error error = Error::NONE;
1367 mMutex.lock_shared();
1368 if (auto writer = getWriter(display)) {
1369 writer->get().setLayerBlockingRegion(translate<int64_t>(display), translate<int64_t>(layer),
1370 translate<AidlRect>(blocking));
1371 } else {
1372 error = Error::BAD_DISPLAY;
1373 }
1374 mMutex.unlock_shared();
1375 return error;
Leon Scroggins IIId77d3162022-01-05 10:42:28 -05001376}
Leon Scroggins IIIe7c51c62022-02-01 15:53:54 -05001377
1378Error AidlComposer::getDisplayDecorationSupport(Display display,
1379 std::optional<DisplayDecorationSupport>* support) {
1380 const auto status =
1381 mAidlComposerClient->getDisplayDecorationSupport(translate<int64_t>(display), support);
1382 if (!status.isOk()) {
1383 ALOGE("getDisplayDecorationSupport failed %s", status.getDescription().c_str());
1384 support->reset();
1385 return static_cast<Error>(status.getServiceSpecificError());
1386 }
1387 return Error::NONE;
1388}
ramindani32cf0602022-03-02 02:30:29 +00001389
1390Error AidlComposer::setIdleTimerEnabled(Display displayId, std::chrono::milliseconds timeout) {
1391 const auto status =
1392 mAidlComposerClient->setIdleTimerEnabled(translate<int64_t>(displayId),
1393 translate<int32_t>(timeout.count()));
1394 if (!status.isOk()) {
1395 ALOGE("setIdleTimerEnabled failed %s", status.getDescription().c_str());
1396 return static_cast<Error>(status.getServiceSpecificError());
1397 }
1398 return Error::NONE;
1399}
1400
ramindani06e518e2022-03-14 18:47:53 +00001401Error AidlComposer::getPhysicalDisplayOrientation(Display displayId,
1402 AidlTransform* outDisplayOrientation) {
1403 const auto status =
1404 mAidlComposerClient->getDisplayPhysicalOrientation(translate<int64_t>(displayId),
1405 outDisplayOrientation);
1406 if (!status.isOk()) {
1407 ALOGE("getPhysicalDisplayOrientation failed %s", status.getDescription().c_str());
1408 return static_cast<Error>(status.getServiceSpecificError());
1409 }
1410 return Error::NONE;
1411}
1412
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -04001413ftl::Optional<std::reference_wrapper<ComposerClientWriter>> AidlComposer::getWriter(Display display)
1414 REQUIRES_SHARED(mMutex) {
1415 return mWriters.get(display);
1416}
1417
1418ftl::Optional<std::reference_wrapper<ComposerClientReader>> AidlComposer::getReader(Display display)
1419 REQUIRES_SHARED(mMutex) {
1420 if (mSingleReader) {
1421 display = translate<Display>(kSingleReaderKey);
1422 }
1423 return mReaders.get(display);
1424}
1425
1426void AidlComposer::removeDisplay(Display display) {
1427 mMutex.lock();
1428 bool wasErased = mWriters.erase(display);
1429 ALOGW_IF(!wasErased,
1430 "Attempting to remove writer for display %" PRId64 " which is not connected",
1431 translate<int64_t>(display));
1432 if (!mSingleReader) {
1433 removeReader(display);
1434 }
1435 mMutex.unlock();
1436}
1437
1438void AidlComposer::onHotplugDisconnect(Display display) {
1439 removeDisplay(display);
1440}
1441
1442bool AidlComposer::hasMultiThreadedPresentSupport(Display display) {
1443 const auto displayId = translate<int64_t>(display);
1444 std::vector<AidlDisplayCapability> capabilities;
1445 const auto status = mAidlComposerClient->getDisplayCapabilities(displayId, &capabilities);
1446 if (!status.isOk()) {
1447 ALOGE("getDisplayCapabilities failed %s", status.getDescription().c_str());
1448 return false;
1449 }
1450 return std::find(capabilities.begin(), capabilities.end(),
1451 AidlDisplayCapability::MULTI_THREADED_PRESENT) != capabilities.end();
1452}
1453
1454void AidlComposer::addReader(Display display) {
1455 const auto displayId = translate<int64_t>(display);
1456 std::optional<int64_t> displayOpt;
1457 if (displayId != kSingleReaderKey) {
1458 displayOpt.emplace(displayId);
1459 }
1460 auto [it, added] = mReaders.try_emplace(display, std::move(displayOpt));
1461 ALOGW_IF(!added, "Attempting to add writer for display %" PRId64 " which is already connected",
1462 displayId);
1463}
1464
1465void AidlComposer::removeReader(Display display) {
1466 bool wasErased = mReaders.erase(display);
1467 ALOGW_IF(!wasErased,
1468 "Attempting to remove reader for display %" PRId64 " which is not connected",
1469 translate<int64_t>(display));
1470}
1471
1472void AidlComposer::addDisplay(Display display) {
1473 const auto displayId = translate<int64_t>(display);
1474 mMutex.lock();
1475 auto [it, added] = mWriters.try_emplace(display, displayId);
1476 ALOGW_IF(!added, "Attempting to add writer for display %" PRId64 " which is already connected",
1477 displayId);
1478 if (mSingleReader) {
1479 if (hasMultiThreadedPresentSupport(display)) {
1480 mSingleReader = false;
1481 removeReader(translate<Display>(kSingleReaderKey));
1482 // Note that this includes the new display.
1483 for (const auto& [existingDisplay, _] : mWriters) {
1484 addReader(existingDisplay);
1485 }
1486 }
1487 } else {
1488 addReader(display);
1489 }
1490 mMutex.unlock();
1491}
1492
1493void AidlComposer::onHotplugConnect(Display display) {
1494 addDisplay(display);
1495}
Ady Abrahame7385f72021-09-05 00:54:25 -07001496} // namespace Hwc2
1497} // namespace android