blob: eff5130f5a73319ebdc75e0abf33e2f2f652cb8e [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>
26#include <log/log.h>
27#include <utils/Trace.h>
28
29#include <aidl/android/hardware/graphics/composer3/BnComposerCallback.h>
30
31#include <algorithm>
32#include <cinttypes>
33
Yichi Chen3401b562022-01-17 15:42:35 +080034#include "HWC2.h"
35
Ady Abrahame7385f72021-09-05 00:54:25 -070036namespace android {
37
38using hardware::hidl_handle;
39using hardware::hidl_vec;
40using hardware::Return;
41
42using aidl::android::hardware::graphics::composer3::BnComposerCallback;
43using aidl::android::hardware::graphics::composer3::Capability;
Alec Mouri85065692022-03-18 00:58:26 +000044using aidl::android::hardware::graphics::composer3::ClientTargetPropertyWithBrightness;
Ady Abrahame7385f72021-09-05 00:54:25 -070045using aidl::android::hardware::graphics::composer3::PowerMode;
46using aidl::android::hardware::graphics::composer3::VirtualDisplay;
47
Ady Abraham42977362021-12-07 21:04:49 -080048using aidl::android::hardware::graphics::composer3::CommandResultPayload;
Ady Abrahama6388c02021-11-11 21:11:51 -080049
Ady Abrahame7385f72021-09-05 00:54:25 -070050using AidlColorMode = aidl::android::hardware::graphics::composer3::ColorMode;
51using AidlContentType = aidl::android::hardware::graphics::composer3::ContentType;
52using AidlDisplayIdentification =
53 aidl::android::hardware::graphics::composer3::DisplayIdentification;
54using AidlDisplayContentSample = aidl::android::hardware::graphics::composer3::DisplayContentSample;
55using AidlDisplayAttribute = aidl::android::hardware::graphics::composer3::DisplayAttribute;
56using AidlDisplayCapability = aidl::android::hardware::graphics::composer3::DisplayCapability;
Ady Abrahame7385f72021-09-05 00:54:25 -070057using AidlHdrCapabilities = aidl::android::hardware::graphics::composer3::HdrCapabilities;
Sally Qi0cbd08b2022-08-17 12:12:28 -070058using AidlOverlayProperties = aidl::android::hardware::graphics::composer3::OverlayProperties;
Ady Abrahame7385f72021-09-05 00:54:25 -070059using AidlPerFrameMetadata = aidl::android::hardware::graphics::composer3::PerFrameMetadata;
60using AidlPerFrameMetadataKey = aidl::android::hardware::graphics::composer3::PerFrameMetadataKey;
61using AidlPerFrameMetadataBlob = aidl::android::hardware::graphics::composer3::PerFrameMetadataBlob;
62using AidlRenderIntent = aidl::android::hardware::graphics::composer3::RenderIntent;
63using AidlVsyncPeriodChangeConstraints =
64 aidl::android::hardware::graphics::composer3::VsyncPeriodChangeConstraints;
65using AidlVsyncPeriodChangeTimeline =
66 aidl::android::hardware::graphics::composer3::VsyncPeriodChangeTimeline;
Ady Abrahame7385f72021-09-05 00:54:25 -070067using AidlDisplayContentSamplingAttributes =
68 aidl::android::hardware::graphics::composer3::DisplayContentSamplingAttributes;
69using AidlFormatColorComponent = aidl::android::hardware::graphics::composer3::FormatColorComponent;
70using AidlDisplayConnectionType =
71 aidl::android::hardware::graphics::composer3::DisplayConnectionType;
Ady Abrahame7385f72021-09-05 00:54:25 -070072
73using AidlColorTransform = aidl::android::hardware::graphics::common::ColorTransform;
74using AidlDataspace = aidl::android::hardware::graphics::common::Dataspace;
75using AidlFRect = aidl::android::hardware::graphics::common::FRect;
76using AidlRect = aidl::android::hardware::graphics::common::Rect;
77using AidlTransform = aidl::android::hardware::graphics::common::Transform;
78
79namespace Hwc2 {
80
81namespace {
82
83template <typename To, typename From>
84To translate(From x) {
85 return static_cast<To>(x);
86}
87
88template <typename To, typename From>
89std::vector<To> translate(const std::vector<From>& in) {
90 std::vector<To> out;
91 out.reserve(in.size());
92 std::transform(in.begin(), in.end(), std::back_inserter(out),
93 [](From x) { return translate<To>(x); });
94 return out;
95}
96
97template <>
98AidlRect translate(IComposerClient::Rect x) {
99 return AidlRect{
100 .left = x.left,
101 .top = x.top,
102 .right = x.right,
103 .bottom = x.bottom,
104 };
105}
106
107template <>
108AidlFRect translate(IComposerClient::FRect x) {
109 return AidlFRect{
110 .left = x.left,
111 .top = x.top,
112 .right = x.right,
113 .bottom = x.bottom,
114 };
115}
116
117template <>
Ady Abrahame7385f72021-09-05 00:54:25 -0700118AidlPerFrameMetadataBlob translate(IComposerClient::PerFrameMetadataBlob x) {
119 AidlPerFrameMetadataBlob blob;
120 blob.key = translate<AidlPerFrameMetadataKey>(x.key),
Long Linga4628782022-02-18 13:44:26 -0800121 std::copy(x.blob.begin(), x.blob.end(), std::inserter(blob.blob, blob.blob.end()));
Ady Abrahame7385f72021-09-05 00:54:25 -0700122 return blob;
123}
124
125template <>
126AidlPerFrameMetadata translate(IComposerClient::PerFrameMetadata x) {
127 return AidlPerFrameMetadata{
128 .key = translate<AidlPerFrameMetadataKey>(x.key),
129 .value = x.value,
130 };
131}
132
133template <>
134DisplayedFrameStats translate(AidlDisplayContentSample x) {
135 return DisplayedFrameStats{
136 .numFrames = static_cast<uint64_t>(x.frameCount),
137 .component_0_sample = translate<uint64_t>(x.sampleComponent0),
138 .component_1_sample = translate<uint64_t>(x.sampleComponent1),
139 .component_2_sample = translate<uint64_t>(x.sampleComponent2),
140 .component_3_sample = translate<uint64_t>(x.sampleComponent3),
141 };
142}
143
144template <>
145AidlVsyncPeriodChangeConstraints translate(IComposerClient::VsyncPeriodChangeConstraints x) {
146 return AidlVsyncPeriodChangeConstraints{
147 .desiredTimeNanos = x.desiredTimeNanos,
148 .seamlessRequired = x.seamlessRequired,
149 };
150}
151
152template <>
153VsyncPeriodChangeTimeline translate(AidlVsyncPeriodChangeTimeline x) {
154 return VsyncPeriodChangeTimeline{
155 .newVsyncAppliedTimeNanos = x.newVsyncAppliedTimeNanos,
156 .refreshRequired = x.refreshRequired,
157 .refreshTimeNanos = x.refreshTimeNanos,
158 };
159}
Ady Abrahame7385f72021-09-05 00:54:25 -0700160mat4 makeMat4(std::vector<float> in) {
161 return mat4(static_cast<const float*>(in.data()));
162}
163
164} // namespace
165
166class AidlIComposerCallbackWrapper : public BnComposerCallback {
167public:
Yichi Chen3401b562022-01-17 15:42:35 +0800168 AidlIComposerCallbackWrapper(HWC2::ComposerCallback& callback) : mCallback(callback) {}
Ady Abrahame7385f72021-09-05 00:54:25 -0700169
170 ::ndk::ScopedAStatus onHotplug(int64_t in_display, bool in_connected) override {
171 const auto connection = in_connected ? V2_4::IComposerCallback::Connection::CONNECTED
172 : V2_4::IComposerCallback::Connection::DISCONNECTED;
Yichi Chen3401b562022-01-17 15:42:35 +0800173 mCallback.onComposerHalHotplug(translate<Display>(in_display), connection);
Ady Abrahame7385f72021-09-05 00:54:25 -0700174 return ::ndk::ScopedAStatus::ok();
175 }
176
177 ::ndk::ScopedAStatus onRefresh(int64_t in_display) override {
Yichi Chen3401b562022-01-17 15:42:35 +0800178 mCallback.onComposerHalRefresh(translate<Display>(in_display));
Ady Abrahame7385f72021-09-05 00:54:25 -0700179 return ::ndk::ScopedAStatus::ok();
180 }
Yichi Chen3401b562022-01-17 15:42:35 +0800181
Ady Abrahame7385f72021-09-05 00:54:25 -0700182 ::ndk::ScopedAStatus onSeamlessPossible(int64_t in_display) override {
Yichi Chen3401b562022-01-17 15:42:35 +0800183 mCallback.onComposerHalSeamlessPossible(translate<Display>(in_display));
Ady Abrahame7385f72021-09-05 00:54:25 -0700184 return ::ndk::ScopedAStatus::ok();
185 }
Yichi Chen3401b562022-01-17 15:42:35 +0800186
Ady Abrahame7385f72021-09-05 00:54:25 -0700187 ::ndk::ScopedAStatus onVsync(int64_t in_display, int64_t in_timestamp,
188 int32_t in_vsyncPeriodNanos) override {
Yichi Chen3401b562022-01-17 15:42:35 +0800189 mCallback.onComposerHalVsync(translate<Display>(in_display), in_timestamp,
190 static_cast<uint32_t>(in_vsyncPeriodNanos));
Ady Abrahame7385f72021-09-05 00:54:25 -0700191 return ::ndk::ScopedAStatus::ok();
192 }
Yichi Chen3401b562022-01-17 15:42:35 +0800193
Ady Abrahame7385f72021-09-05 00:54:25 -0700194 ::ndk::ScopedAStatus onVsyncPeriodTimingChanged(
195 int64_t in_display, const AidlVsyncPeriodChangeTimeline& in_updatedTimeline) override {
Yichi Chen3401b562022-01-17 15:42:35 +0800196 mCallback.onComposerHalVsyncPeriodTimingChanged(translate<Display>(in_display),
197 translate<V2_4::VsyncPeriodChangeTimeline>(
198 in_updatedTimeline));
199 return ::ndk::ScopedAStatus::ok();
200 }
201
202 ::ndk::ScopedAStatus onVsyncIdle(int64_t in_display) override {
203 mCallback.onComposerHalVsyncIdle(translate<Display>(in_display));
Ady Abrahame7385f72021-09-05 00:54:25 -0700204 return ::ndk::ScopedAStatus::ok();
205 }
206
207private:
Yichi Chen3401b562022-01-17 15:42:35 +0800208 HWC2::ComposerCallback& mCallback;
Ady Abrahame7385f72021-09-05 00:54:25 -0700209};
210
Ady Abraham9fc28052021-10-14 17:21:38 -0700211std::string AidlComposer::instance(const std::string& serviceName) {
212 return std::string(AidlIComposer::descriptor) + "/" + serviceName;
213}
214
215bool AidlComposer::isDeclared(const std::string& serviceName) {
216 return AServiceManager_isDeclared(instance(serviceName).c_str());
217}
Ady Abrahame7385f72021-09-05 00:54:25 -0700218
Ady Abrahama6388c02021-11-11 21:11:51 -0800219AidlComposer::AidlComposer(const std::string& serviceName) {
Ady Abrahame7385f72021-09-05 00:54:25 -0700220 // This only waits if the service is actually declared
Ady Abraham9fc28052021-10-14 17:21:38 -0700221 mAidlComposer = AidlIComposer::fromBinder(
222 ndk::SpAIBinder(AServiceManager_waitForService(instance(serviceName).c_str())));
Ady Abrahame7385f72021-09-05 00:54:25 -0700223 if (!mAidlComposer) {
224 LOG_ALWAYS_FATAL("Failed to get AIDL composer service");
225 return;
226 }
227
228 if (!mAidlComposer->createClient(&mAidlComposerClient).isOk()) {
229 LOG_ALWAYS_FATAL("Can't create AidlComposerClient, fallback to HIDL");
230 return;
231 }
232
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400233 addReader(translate<Display>(kSingleReaderKey));
234
Ady Abrahame7385f72021-09-05 00:54:25 -0700235 ALOGI("Loaded AIDL composer3 HAL service");
236}
237
238AidlComposer::~AidlComposer() = default;
239
Ady Abraham4d211cf2021-12-14 16:19:03 -0800240bool AidlComposer::isSupported(OptionalFeature feature) const {
241 switch (feature) {
242 case OptionalFeature::RefreshRateSwitching:
Ady Abraham43065bd2021-12-10 17:22:15 -0800243 case OptionalFeature::ExpectedPresentTime:
Alec Mouricdf16792021-12-10 13:16:06 -0800244 case OptionalFeature::DisplayBrightnessCommand:
ramindani32cf0602022-03-02 02:30:29 +0000245 case OptionalFeature::KernelIdleTimer:
ramindani06e518e2022-03-14 18:47:53 +0000246 case OptionalFeature::PhysicalDisplayOrientation:
Ady Abraham4d211cf2021-12-14 16:19:03 -0800247 return true;
248 }
249}
250
Ady Abrahamde549d42022-01-26 19:19:17 -0800251std::vector<Capability> AidlComposer::getCapabilities() {
Ady Abrahame7385f72021-09-05 00:54:25 -0700252 std::vector<Capability> capabilities;
253 const auto status = mAidlComposer->getCapabilities(&capabilities);
254 if (!status.isOk()) {
255 ALOGE("getCapabilities failed %s", status.getDescription().c_str());
256 return {};
257 }
Ady Abrahamde549d42022-01-26 19:19:17 -0800258 return capabilities;
Ady Abrahame7385f72021-09-05 00:54:25 -0700259}
260
261std::string AidlComposer::dumpDebugInfo() {
Ady Abrahamc4acf512022-02-18 17:11:59 -0800262 int pipefds[2];
263 int result = pipe(pipefds);
264 if (result < 0) {
265 ALOGE("dumpDebugInfo: pipe failed: %s", strerror(errno));
Ady Abrahame7385f72021-09-05 00:54:25 -0700266 return {};
267 }
Ady Abrahamc4acf512022-02-18 17:11:59 -0800268
269 std::string str;
yihsing.shen58847c52022-09-23 15:39:30 +0800270 // Use other thread to read pipe to prevent
271 // pipe is full, making HWC be blocked in writing.
272 std::thread t([&]() {
273 base::ReadFdToString(pipefds[0], &str);
274 });
Ady Abrahamc4acf512022-02-18 17:11:59 -0800275 const auto status = mAidlComposer->dump(pipefds[1], /*args*/ nullptr, /*numArgs*/ 0);
276 // Close the write-end of the pipe to make sure that when reading from the
277 // read-end we will get eof instead of blocking forever
278 close(pipefds[1]);
279
yihsing.shen58847c52022-09-23 15:39:30 +0800280 if (status != STATUS_OK) {
Ady Abrahamc4acf512022-02-18 17:11:59 -0800281 ALOGE("dumpDebugInfo: dump failed: %d", status);
282 }
283
yihsing.shen58847c52022-09-23 15:39:30 +0800284 t.join();
Ady Abrahamc4acf512022-02-18 17:11:59 -0800285 close(pipefds[0]);
286 return str;
Ady Abrahame7385f72021-09-05 00:54:25 -0700287}
288
Yichi Chen3401b562022-01-17 15:42:35 +0800289void AidlComposer::registerCallback(HWC2::ComposerCallback& callback) {
Ady Abrahame7385f72021-09-05 00:54:25 -0700290 if (mAidlComposerCallback) {
291 ALOGE("Callback already registered");
292 }
Yichi Chen3401b562022-01-17 15:42:35 +0800293
Ady Abraham9fc28052021-10-14 17:21:38 -0700294 mAidlComposerCallback = ndk::SharedRefBase::make<AidlIComposerCallbackWrapper>(callback);
Ady Abrahame7385f72021-09-05 00:54:25 -0700295 AIBinder_setMinSchedulerPolicy(mAidlComposerCallback->asBinder().get(), SCHED_FIFO, 2);
296
297 const auto status = mAidlComposerClient->registerCallback(mAidlComposerCallback);
298 if (!status.isOk()) {
299 ALOGE("registerCallback failed %s", status.getDescription().c_str());
300 }
301}
302
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400303void AidlComposer::resetCommands(Display display) {
304 mMutex.lock_shared();
305 if (auto writer = getWriter(display)) {
306 writer->get().reset();
307 }
308 mMutex.unlock_shared();
Ady Abrahame7385f72021-09-05 00:54:25 -0700309}
310
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400311Error AidlComposer::executeCommands(Display display) {
312 mMutex.lock_shared();
313 auto error = execute(display);
314 mMutex.unlock_shared();
315 return error;
Ady Abrahame7385f72021-09-05 00:54:25 -0700316}
317
318uint32_t AidlComposer::getMaxVirtualDisplayCount() {
319 int32_t count = 0;
320 const auto status = mAidlComposerClient->getMaxVirtualDisplayCount(&count);
321 if (!status.isOk()) {
322 ALOGE("getMaxVirtualDisplayCount failed %s", status.getDescription().c_str());
323 return 0;
324 }
325 return static_cast<uint32_t>(count);
326}
327
328Error AidlComposer::createVirtualDisplay(uint32_t width, uint32_t height, PixelFormat* format,
329 Display* outDisplay) {
330 using AidlPixelFormat = aidl::android::hardware::graphics::common::PixelFormat;
331 const int32_t bufferSlotCount = 1;
332 VirtualDisplay virtualDisplay;
333 const auto status =
334 mAidlComposerClient->createVirtualDisplay(static_cast<int32_t>(width),
335 static_cast<int32_t>(height),
336 static_cast<AidlPixelFormat>(*format),
337 bufferSlotCount, &virtualDisplay);
338
339 if (!status.isOk()) {
340 ALOGE("createVirtualDisplay failed %s", status.getDescription().c_str());
341 return static_cast<Error>(status.getServiceSpecificError());
342 }
343
344 *outDisplay = translate<Display>(virtualDisplay.display);
345 *format = static_cast<PixelFormat>(virtualDisplay.format);
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400346 addDisplay(translate<Display>(virtualDisplay.display));
Ady Abrahame7385f72021-09-05 00:54:25 -0700347 return Error::NONE;
348}
349
350Error AidlComposer::destroyVirtualDisplay(Display display) {
351 const auto status = mAidlComposerClient->destroyVirtualDisplay(translate<int64_t>(display));
352 if (!status.isOk()) {
353 ALOGE("destroyVirtualDisplay failed %s", status.getDescription().c_str());
354 return static_cast<Error>(status.getServiceSpecificError());
355 }
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400356 removeDisplay(display);
Ady Abrahame7385f72021-09-05 00:54:25 -0700357 return Error::NONE;
358}
359
360Error AidlComposer::acceptDisplayChanges(Display display) {
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400361 Error error = Error::NONE;
362 mMutex.lock_shared();
363 if (auto writer = getWriter(display)) {
364 writer->get().acceptDisplayChanges(translate<int64_t>(display));
365 } else {
366 error = Error::BAD_DISPLAY;
367 }
368 mMutex.unlock_shared();
369 return error;
Ady Abrahame7385f72021-09-05 00:54:25 -0700370}
371
372Error AidlComposer::createLayer(Display display, Layer* outLayer) {
373 int64_t layer;
374 const auto status = mAidlComposerClient->createLayer(translate<int64_t>(display),
375 kMaxLayerBufferCount, &layer);
376 if (!status.isOk()) {
377 ALOGE("createLayer failed %s", status.getDescription().c_str());
378 return static_cast<Error>(status.getServiceSpecificError());
379 }
380
381 *outLayer = translate<Layer>(layer);
382 return Error::NONE;
383}
384
385Error AidlComposer::destroyLayer(Display display, Layer layer) {
386 const auto status = mAidlComposerClient->destroyLayer(translate<int64_t>(display),
387 translate<int64_t>(layer));
388 if (!status.isOk()) {
389 ALOGE("destroyLayer failed %s", status.getDescription().c_str());
390 return static_cast<Error>(status.getServiceSpecificError());
391 }
392 return Error::NONE;
393}
394
395Error AidlComposer::getActiveConfig(Display display, Config* outConfig) {
396 int32_t config;
397 const auto status = mAidlComposerClient->getActiveConfig(translate<int64_t>(display), &config);
398 if (!status.isOk()) {
399 ALOGE("getActiveConfig failed %s", status.getDescription().c_str());
400 return static_cast<Error>(status.getServiceSpecificError());
401 }
402 *outConfig = translate<Config>(config);
403 return Error::NONE;
404}
405
406Error AidlComposer::getChangedCompositionTypes(
407 Display display, std::vector<Layer>* outLayers,
Leon Scroggins III2e1aa182021-12-01 17:33:12 -0500408 std::vector<aidl::android::hardware::graphics::composer3::Composition>* outTypes) {
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400409 std::vector<ChangedCompositionLayer> changedLayers;
410 Error error = Error::NONE;
411 {
412 mMutex.lock_shared();
413 if (auto reader = getReader(display)) {
414 changedLayers = reader->get().takeChangedCompositionTypes(translate<int64_t>(display));
415 } else {
416 error = Error::BAD_DISPLAY;
417 }
418 mMutex.unlock_shared();
419 }
Ady Abrahamde792782021-12-20 10:00:49 -0800420 outLayers->reserve(changedLayers.size());
421 outTypes->reserve(changedLayers.size());
Ady Abrahama6388c02021-11-11 21:11:51 -0800422
Ady Abrahamde792782021-12-20 10:00:49 -0800423 for (const auto& layer : changedLayers) {
424 outLayers->emplace_back(translate<Layer>(layer.layer));
425 outTypes->emplace_back(layer.composition);
426 }
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400427 return error;
Ady Abrahame7385f72021-09-05 00:54:25 -0700428}
429
430Error AidlComposer::getColorModes(Display display, std::vector<ColorMode>* outModes) {
431 std::vector<AidlColorMode> modes;
432 const auto status = mAidlComposerClient->getColorModes(translate<int64_t>(display), &modes);
433 if (!status.isOk()) {
434 ALOGE("getColorModes failed %s", status.getDescription().c_str());
435 return static_cast<Error>(status.getServiceSpecificError());
436 }
437 *outModes = translate<ColorMode>(modes);
438 return Error::NONE;
439}
440
441Error AidlComposer::getDisplayAttribute(Display display, Config config,
442 IComposerClient::Attribute attribute, int32_t* outValue) {
443 const auto status =
444 mAidlComposerClient->getDisplayAttribute(translate<int64_t>(display),
445 translate<int32_t>(config),
446 static_cast<AidlDisplayAttribute>(attribute),
447 outValue);
448 if (!status.isOk()) {
449 ALOGE("getDisplayAttribute failed %s", status.getDescription().c_str());
450 return static_cast<Error>(status.getServiceSpecificError());
451 }
452 return Error::NONE;
453}
454
455Error AidlComposer::getDisplayConfigs(Display display, std::vector<Config>* outConfigs) {
456 std::vector<int32_t> configs;
457 const auto status =
458 mAidlComposerClient->getDisplayConfigs(translate<int64_t>(display), &configs);
459 if (!status.isOk()) {
460 ALOGE("getDisplayConfigs failed %s", status.getDescription().c_str());
461 return static_cast<Error>(status.getServiceSpecificError());
462 }
463 *outConfigs = translate<Config>(configs);
464 return Error::NONE;
465}
466
467Error AidlComposer::getDisplayName(Display display, std::string* outName) {
468 const auto status = mAidlComposerClient->getDisplayName(translate<int64_t>(display), outName);
469 if (!status.isOk()) {
470 ALOGE("getDisplayName failed %s", status.getDescription().c_str());
471 return static_cast<Error>(status.getServiceSpecificError());
472 }
473 return Error::NONE;
474}
475
476Error AidlComposer::getDisplayRequests(Display display, uint32_t* outDisplayRequestMask,
477 std::vector<Layer>* outLayers,
478 std::vector<uint32_t>* outLayerRequestMasks) {
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400479 Error error = Error::NONE;
480 DisplayRequest displayRequests;
481 {
482 mMutex.lock_shared();
483 if (auto reader = getReader(display)) {
484 displayRequests = reader->get().takeDisplayRequests(translate<int64_t>(display));
485 } else {
486 error = Error::BAD_DISPLAY;
487 }
488 mMutex.unlock_shared();
489 }
Ady Abrahamde792782021-12-20 10:00:49 -0800490 *outDisplayRequestMask = translate<uint32_t>(displayRequests.mask);
491 outLayers->reserve(displayRequests.layerRequests.size());
492 outLayerRequestMasks->reserve(displayRequests.layerRequests.size());
493
494 for (const auto& layer : displayRequests.layerRequests) {
495 outLayers->emplace_back(translate<Layer>(layer.layer));
496 outLayerRequestMasks->emplace_back(translate<uint32_t>(layer.mask));
497 }
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400498 return error;
Ady Abrahame7385f72021-09-05 00:54:25 -0700499}
500
501Error AidlComposer::getDozeSupport(Display display, bool* outSupport) {
Ady Abraham33b92b92021-12-08 18:30:27 -0800502 std::vector<AidlDisplayCapability> capabilities;
Ady Abrahame7385f72021-09-05 00:54:25 -0700503 const auto status =
Ady Abraham33b92b92021-12-08 18:30:27 -0800504 mAidlComposerClient->getDisplayCapabilities(translate<int64_t>(display), &capabilities);
Ady Abrahame7385f72021-09-05 00:54:25 -0700505 if (!status.isOk()) {
Ady Abraham33b92b92021-12-08 18:30:27 -0800506 ALOGE("getDisplayCapabilities failed %s", status.getDescription().c_str());
Ady Abrahame7385f72021-09-05 00:54:25 -0700507 return static_cast<Error>(status.getServiceSpecificError());
508 }
Ady Abraham33b92b92021-12-08 18:30:27 -0800509 *outSupport = std::find(capabilities.begin(), capabilities.end(),
510 AidlDisplayCapability::DOZE) != capabilities.end();
Ady Abrahame7385f72021-09-05 00:54:25 -0700511 return Error::NONE;
512}
513
ramindani32cf0602022-03-02 02:30:29 +0000514Error AidlComposer::hasDisplayIdleTimerCapability(Display display, bool* outSupport) {
515 std::vector<AidlDisplayCapability> capabilities;
516 const auto status =
517 mAidlComposerClient->getDisplayCapabilities(translate<int64_t>(display), &capabilities);
518 if (!status.isOk()) {
519 ALOGE("getDisplayCapabilities failed %s", status.getDescription().c_str());
520 return static_cast<Error>(status.getServiceSpecificError());
521 }
522 *outSupport = std::find(capabilities.begin(), capabilities.end(),
523 AidlDisplayCapability::DISPLAY_IDLE_TIMER) != capabilities.end();
524 return Error::NONE;
525}
526
Ady Abrahame7385f72021-09-05 00:54:25 -0700527Error AidlComposer::getHdrCapabilities(Display display, std::vector<Hdr>* outTypes,
528 float* outMaxLuminance, float* outMaxAverageLuminance,
529 float* outMinLuminance) {
530 AidlHdrCapabilities capabilities;
531 const auto status =
532 mAidlComposerClient->getHdrCapabilities(translate<int64_t>(display), &capabilities);
533 if (!status.isOk()) {
534 ALOGE("getHdrCapabilities failed %s", status.getDescription().c_str());
535 return static_cast<Error>(status.getServiceSpecificError());
536 }
537
538 *outTypes = translate<Hdr>(capabilities.types);
539 *outMaxLuminance = capabilities.maxLuminance;
540 *outMaxAverageLuminance = capabilities.maxAverageLuminance;
541 *outMinLuminance = capabilities.minLuminance;
542 return Error::NONE;
543}
544
Sally Qi0cbd08b2022-08-17 12:12:28 -0700545Error AidlComposer::getOverlaySupport(AidlOverlayProperties* /*outProperties*/) {
546 // TODO(b/242588489): implement details
547 return Error::NONE;
548}
549
Ady Abrahame7385f72021-09-05 00:54:25 -0700550Error AidlComposer::getReleaseFences(Display display, std::vector<Layer>* outLayers,
551 std::vector<int>* outReleaseFences) {
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400552 Error error = Error::NONE;
553 std::vector<ReleaseFences::Layer> fences;
554 {
555 mMutex.lock_shared();
556 if (auto reader = getReader(display)) {
557 fences = reader->get().takeReleaseFences(translate<int64_t>(display));
558 } else {
559 error = Error::BAD_DISPLAY;
560 }
561 mMutex.unlock_shared();
562 }
Ady Abrahamde792782021-12-20 10:00:49 -0800563 outLayers->reserve(fences.size());
564 outReleaseFences->reserve(fences.size());
565
566 for (auto& fence : fences) {
567 outLayers->emplace_back(translate<Layer>(fence.layer));
568 // take ownership
569 const int fenceOwner = fence.fence.get();
570 *fence.fence.getR() = -1;
571 outReleaseFences->emplace_back(fenceOwner);
572 }
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400573 return error;
Ady Abrahame7385f72021-09-05 00:54:25 -0700574}
575
576Error AidlComposer::presentDisplay(Display display, int* outPresentFence) {
577 ATRACE_NAME("HwcPresentDisplay");
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400578 Error error = Error::NONE;
579 mMutex.lock_shared();
580 auto writer = getWriter(display);
581 auto reader = getReader(display);
582 if (writer && reader) {
583 writer->get().presentDisplay(translate<int64_t>(display));
584 error = execute(display);
585 } else {
586 error = Error::BAD_DISPLAY;
587 }
Ady Abrahame7385f72021-09-05 00:54:25 -0700588
Ady Abrahame7385f72021-09-05 00:54:25 -0700589 if (error != Error::NONE) {
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400590 mMutex.unlock_shared();
Ady Abrahame7385f72021-09-05 00:54:25 -0700591 return error;
592 }
593
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400594 auto fence = reader->get().takePresentFence(translate<int64_t>(display));
595 mMutex.unlock_shared();
Ady Abrahamde792782021-12-20 10:00:49 -0800596 // take ownership
597 *outPresentFence = fence.get();
598 *fence.getR() = -1;
Ady Abrahame7385f72021-09-05 00:54:25 -0700599 return Error::NONE;
600}
601
602Error AidlComposer::setActiveConfig(Display display, Config config) {
603 const auto status = mAidlComposerClient->setActiveConfig(translate<int64_t>(display),
604 translate<int32_t>(config));
605 if (!status.isOk()) {
606 ALOGE("setActiveConfig failed %s", status.getDescription().c_str());
607 return static_cast<Error>(status.getServiceSpecificError());
608 }
609 return Error::NONE;
610}
611
612Error AidlComposer::setClientTarget(Display display, uint32_t slot, const sp<GraphicBuffer>& target,
613 int acquireFence, Dataspace dataspace,
614 const std::vector<IComposerClient::Rect>& damage) {
Ady Abrahame7385f72021-09-05 00:54:25 -0700615 const native_handle_t* handle = nullptr;
616 if (target.get()) {
617 handle = target->getNativeBuffer()->handle;
618 }
619
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400620 Error error = Error::NONE;
621 mMutex.lock_shared();
622 if (auto writer = getWriter(display)) {
623 writer->get()
624 .setClientTarget(translate<int64_t>(display), slot, handle, acquireFence,
625 translate<aidl::android::hardware::graphics::common::Dataspace>(
626 dataspace),
627 translate<AidlRect>(damage));
628 } else {
629 error = Error::BAD_DISPLAY;
630 }
631 mMutex.unlock_shared();
632 return error;
Ady Abrahame7385f72021-09-05 00:54:25 -0700633}
634
635Error AidlComposer::setColorMode(Display display, ColorMode mode, RenderIntent renderIntent) {
636 const auto status =
637 mAidlComposerClient->setColorMode(translate<int64_t>(display),
638 translate<AidlColorMode>(mode),
639 translate<AidlRenderIntent>(renderIntent));
640 if (!status.isOk()) {
641 ALOGE("setColorMode failed %s", status.getDescription().c_str());
642 return static_cast<Error>(status.getServiceSpecificError());
643 }
644 return Error::NONE;
645}
646
Ady Abrahamdc011a92021-12-21 14:06:44 -0800647Error AidlComposer::setColorTransform(Display display, const float* matrix) {
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400648 auto error = Error::NONE;
649 mMutex.lock_shared();
650 if (auto writer = getWriter(display)) {
651 writer->get().setColorTransform(translate<int64_t>(display), matrix);
652 } else {
653 error = Error::BAD_DISPLAY;
654 }
655 mMutex.unlock_shared();
656 return error;
Ady Abrahame7385f72021-09-05 00:54:25 -0700657}
658
659Error AidlComposer::setOutputBuffer(Display display, const native_handle_t* buffer,
660 int releaseFence) {
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400661 auto error = Error::NONE;
662 mMutex.lock_shared();
663 if (auto writer = getWriter(display)) {
664 writer->get().setOutputBuffer(translate<int64_t>(display), 0, buffer, dup(releaseFence));
665 } else {
666 error = Error::BAD_DISPLAY;
667 }
668 mMutex.unlock_shared();
669 return error;
Ady Abrahame7385f72021-09-05 00:54:25 -0700670}
671
672Error AidlComposer::setPowerMode(Display display, IComposerClient::PowerMode mode) {
673 const auto status = mAidlComposerClient->setPowerMode(translate<int64_t>(display),
674 translate<PowerMode>(mode));
675 if (!status.isOk()) {
676 ALOGE("setPowerMode failed %s", status.getDescription().c_str());
677 return static_cast<Error>(status.getServiceSpecificError());
678 }
679 return Error::NONE;
680}
681
682Error AidlComposer::setVsyncEnabled(Display display, IComposerClient::Vsync enabled) {
683 const bool enableVsync = enabled == IComposerClient::Vsync::ENABLE;
684 const auto status =
685 mAidlComposerClient->setVsyncEnabled(translate<int64_t>(display), enableVsync);
686 if (!status.isOk()) {
687 ALOGE("setVsyncEnabled failed %s", status.getDescription().c_str());
688 return static_cast<Error>(status.getServiceSpecificError());
689 }
690 return Error::NONE;
691}
692
693Error AidlComposer::setClientTargetSlotCount(Display display) {
694 const int32_t bufferSlotCount = BufferQueue::NUM_BUFFER_SLOTS;
695 const auto status = mAidlComposerClient->setClientTargetSlotCount(translate<int64_t>(display),
696 bufferSlotCount);
697 if (!status.isOk()) {
698 ALOGE("setClientTargetSlotCount failed %s", status.getDescription().c_str());
699 return static_cast<Error>(status.getServiceSpecificError());
700 }
701 return Error::NONE;
702}
703
Ady Abraham43065bd2021-12-10 17:22:15 -0800704Error AidlComposer::validateDisplay(Display display, nsecs_t expectedPresentTime,
705 uint32_t* outNumTypes, uint32_t* outNumRequests) {
Ady Abrahame7385f72021-09-05 00:54:25 -0700706 ATRACE_NAME("HwcValidateDisplay");
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400707 const auto displayId = translate<int64_t>(display);
708 Error error = Error::NONE;
709 mMutex.lock_shared();
710 auto writer = getWriter(display);
711 auto reader = getReader(display);
712 if (writer && reader) {
713 writer->get().validateDisplay(displayId, ClockMonotonicTimestamp{expectedPresentTime});
714 error = execute(display);
715 } else {
716 error = Error::BAD_DISPLAY;
717 }
Ady Abrahame7385f72021-09-05 00:54:25 -0700718
Ady Abrahame7385f72021-09-05 00:54:25 -0700719 if (error != Error::NONE) {
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400720 mMutex.unlock_shared();
Ady Abrahame7385f72021-09-05 00:54:25 -0700721 return error;
722 }
723
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400724 reader->get().hasChanges(displayId, outNumTypes, outNumRequests);
Ady Abrahame7385f72021-09-05 00:54:25 -0700725
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400726 mMutex.unlock_shared();
Ady Abrahame7385f72021-09-05 00:54:25 -0700727 return Error::NONE;
728}
729
Ady Abraham43065bd2021-12-10 17:22:15 -0800730Error AidlComposer::presentOrValidateDisplay(Display display, nsecs_t expectedPresentTime,
731 uint32_t* outNumTypes, uint32_t* outNumRequests,
732 int* outPresentFence, uint32_t* state) {
Ady Abrahame7385f72021-09-05 00:54:25 -0700733 ATRACE_NAME("HwcPresentOrValidateDisplay");
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400734 const auto displayId = translate<int64_t>(display);
735 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().presentOrvalidateDisplay(displayId,
741 ClockMonotonicTimestamp{expectedPresentTime});
742 error = execute(display);
743 } else {
744 error = Error::BAD_DISPLAY;
745 }
Ady Abrahame7385f72021-09-05 00:54:25 -0700746
Ady Abrahame7385f72021-09-05 00:54:25 -0700747 if (error != Error::NONE) {
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400748 mMutex.unlock_shared();
Ady Abrahame7385f72021-09-05 00:54:25 -0700749 return error;
750 }
751
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400752 const auto result = reader->get().takePresentOrValidateStage(displayId);
Ady Abrahamde792782021-12-20 10:00:49 -0800753 if (!result.has_value()) {
754 *state = translate<uint32_t>(-1);
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400755 mMutex.unlock_shared();
Ady Abrahamde792782021-12-20 10:00:49 -0800756 return Error::NO_RESOURCES;
Ady Abrahame7385f72021-09-05 00:54:25 -0700757 }
758
Ady Abrahamde792782021-12-20 10:00:49 -0800759 *state = translate<uint32_t>(*result);
760
761 if (*result == PresentOrValidate::Result::Presented) {
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400762 auto fence = reader->get().takePresentFence(displayId);
Ady Abrahamde792782021-12-20 10:00:49 -0800763 // take ownership
764 *outPresentFence = fence.get();
765 *fence.getR() = -1;
766 }
767
768 if (*result == PresentOrValidate::Result::Validated) {
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400769 reader->get().hasChanges(displayId, outNumTypes, outNumRequests);
Ady Abrahame7385f72021-09-05 00:54:25 -0700770 }
771
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400772 mMutex.unlock_shared();
Ady Abrahame7385f72021-09-05 00:54:25 -0700773 return Error::NONE;
774}
775
776Error AidlComposer::setCursorPosition(Display display, Layer layer, int32_t x, int32_t y) {
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400777 Error error = Error::NONE;
778 mMutex.lock_shared();
779 if (auto writer = getWriter(display)) {
780 writer->get().setLayerCursorPosition(translate<int64_t>(display), translate<int64_t>(layer),
781 x, y);
782 } else {
783 error = Error::BAD_DISPLAY;
784 }
785 mMutex.unlock_shared();
786 return error;
Ady Abrahame7385f72021-09-05 00:54:25 -0700787}
788
789Error AidlComposer::setLayerBuffer(Display display, Layer layer, uint32_t slot,
790 const sp<GraphicBuffer>& buffer, int acquireFence) {
Ady Abrahame7385f72021-09-05 00:54:25 -0700791 const native_handle_t* handle = nullptr;
792 if (buffer.get()) {
793 handle = buffer->getNativeBuffer()->handle;
794 }
795
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400796 Error error = Error::NONE;
797 mMutex.lock_shared();
798 if (auto writer = getWriter(display)) {
799 writer->get().setLayerBuffer(translate<int64_t>(display), translate<int64_t>(layer), slot,
800 handle, acquireFence);
801 } else {
802 error = Error::BAD_DISPLAY;
803 }
804 mMutex.unlock_shared();
805 return error;
Ady Abrahame7385f72021-09-05 00:54:25 -0700806}
807
808Error AidlComposer::setLayerSurfaceDamage(Display display, Layer layer,
809 const std::vector<IComposerClient::Rect>& damage) {
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400810 Error error = Error::NONE;
811 mMutex.lock_shared();
812 if (auto writer = getWriter(display)) {
813 writer->get().setLayerSurfaceDamage(translate<int64_t>(display), translate<int64_t>(layer),
814 translate<AidlRect>(damage));
815 } else {
816 error = Error::BAD_DISPLAY;
817 }
818 mMutex.unlock_shared();
819 return error;
Ady Abrahame7385f72021-09-05 00:54:25 -0700820}
821
822Error AidlComposer::setLayerBlendMode(Display display, Layer layer,
823 IComposerClient::BlendMode mode) {
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().setLayerBlendMode(translate<int64_t>(display), translate<int64_t>(layer),
828 translate<BlendMode>(mode));
829 } else {
830 error = Error::BAD_DISPLAY;
831 }
832 mMutex.unlock_shared();
833 return error;
Ady Abrahame7385f72021-09-05 00:54:25 -0700834}
835
Ady Abraham6e60b142022-01-06 18:10:35 -0800836Error AidlComposer::setLayerColor(Display display, Layer layer, const Color& color) {
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400837 Error error = Error::NONE;
838 mMutex.lock_shared();
839 if (auto writer = getWriter(display)) {
840 writer->get().setLayerColor(translate<int64_t>(display), translate<int64_t>(layer), color);
841 } else {
842 error = Error::BAD_DISPLAY;
843 }
844 mMutex.unlock_shared();
845 return error;
Ady Abrahame7385f72021-09-05 00:54:25 -0700846}
847
Leon Scroggins III2e1aa182021-12-01 17:33:12 -0500848Error AidlComposer::setLayerCompositionType(
849 Display display, Layer layer,
850 aidl::android::hardware::graphics::composer3::Composition type) {
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400851 Error error = Error::NONE;
852 mMutex.lock_shared();
853 if (auto writer = getWriter(display)) {
854 writer->get().setLayerCompositionType(translate<int64_t>(display),
855 translate<int64_t>(layer), type);
856 } else {
857 error = Error::BAD_DISPLAY;
858 }
859 mMutex.unlock_shared();
860 return error;
Ady Abrahame7385f72021-09-05 00:54:25 -0700861}
862
863Error AidlComposer::setLayerDataspace(Display display, Layer layer, Dataspace dataspace) {
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400864 Error error = Error::NONE;
865 mMutex.lock_shared();
866 if (auto writer = getWriter(display)) {
867 writer->get().setLayerDataspace(translate<int64_t>(display), translate<int64_t>(layer),
868 translate<AidlDataspace>(dataspace));
869 } else {
870 error = Error::BAD_DISPLAY;
871 }
872 mMutex.unlock_shared();
873 return error;
Ady Abrahame7385f72021-09-05 00:54:25 -0700874}
875
876Error AidlComposer::setLayerDisplayFrame(Display display, Layer layer,
877 const IComposerClient::Rect& frame) {
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400878 Error error = Error::NONE;
879 mMutex.lock_shared();
880 if (auto writer = getWriter(display)) {
881 writer->get().setLayerDisplayFrame(translate<int64_t>(display), translate<int64_t>(layer),
882 translate<AidlRect>(frame));
883 } else {
884 error = Error::BAD_DISPLAY;
885 }
886 mMutex.unlock_shared();
887 return error;
Ady Abrahame7385f72021-09-05 00:54:25 -0700888}
889
890Error AidlComposer::setLayerPlaneAlpha(Display display, Layer layer, float alpha) {
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400891 Error error = Error::NONE;
892 mMutex.lock_shared();
893 if (auto writer = getWriter(display)) {
894 writer->get().setLayerPlaneAlpha(translate<int64_t>(display), translate<int64_t>(layer),
895 alpha);
896 } else {
897 error = Error::BAD_DISPLAY;
898 }
899 mMutex.unlock_shared();
900 return error;
Ady Abrahame7385f72021-09-05 00:54:25 -0700901}
902
903Error AidlComposer::setLayerSidebandStream(Display display, Layer layer,
904 const native_handle_t* stream) {
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400905 Error error = Error::NONE;
906 mMutex.lock_shared();
907 if (auto writer = getWriter(display)) {
908 writer->get().setLayerSidebandStream(translate<int64_t>(display), translate<int64_t>(layer),
909 stream);
910 } else {
911 error = Error::BAD_DISPLAY;
912 }
913 mMutex.unlock_shared();
914 return error;
Ady Abrahame7385f72021-09-05 00:54:25 -0700915}
916
917Error AidlComposer::setLayerSourceCrop(Display display, Layer layer,
918 const IComposerClient::FRect& crop) {
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400919 Error error = Error::NONE;
920 mMutex.lock_shared();
921 if (auto writer = getWriter(display)) {
922 writer->get().setLayerSourceCrop(translate<int64_t>(display), translate<int64_t>(layer),
923 translate<AidlFRect>(crop));
924 } else {
925 error = Error::BAD_DISPLAY;
926 }
927 mMutex.unlock_shared();
928 return error;
Ady Abrahame7385f72021-09-05 00:54:25 -0700929}
930
931Error AidlComposer::setLayerTransform(Display display, Layer layer, Transform transform) {
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400932 Error error = Error::NONE;
933 mMutex.lock_shared();
934 if (auto writer = getWriter(display)) {
935 writer->get().setLayerTransform(translate<int64_t>(display), translate<int64_t>(layer),
936 translate<AidlTransform>(transform));
937 } else {
938 error = Error::BAD_DISPLAY;
939 }
940 mMutex.unlock_shared();
941 return error;
Ady Abrahame7385f72021-09-05 00:54:25 -0700942}
943
944Error AidlComposer::setLayerVisibleRegion(Display display, Layer layer,
945 const std::vector<IComposerClient::Rect>& visible) {
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400946 Error error = Error::NONE;
947 mMutex.lock_shared();
948 if (auto writer = getWriter(display)) {
949 writer->get().setLayerVisibleRegion(translate<int64_t>(display), translate<int64_t>(layer),
950 translate<AidlRect>(visible));
951 } else {
952 error = Error::BAD_DISPLAY;
953 }
954 mMutex.unlock_shared();
955 return error;
Ady Abrahame7385f72021-09-05 00:54:25 -0700956}
957
958Error AidlComposer::setLayerZOrder(Display display, Layer layer, uint32_t z) {
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400959 Error error = Error::NONE;
960 mMutex.lock_shared();
961 if (auto writer = getWriter(display)) {
962 writer->get().setLayerZOrder(translate<int64_t>(display), translate<int64_t>(layer), z);
963 } else {
964 error = Error::BAD_DISPLAY;
965 }
966 mMutex.unlock_shared();
967 return error;
Ady Abrahame7385f72021-09-05 00:54:25 -0700968}
969
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400970Error AidlComposer::execute(Display display) {
971 auto writer = getWriter(display);
972 auto reader = getReader(display);
973 if (!writer || !reader) {
974 return Error::BAD_DISPLAY;
975 }
976
977 const auto& commands = writer->get().getPendingCommands();
Ady Abrahama6388c02021-11-11 21:11:51 -0800978 if (commands.empty()) {
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400979 writer->get().reset();
Ady Abrahame7385f72021-09-05 00:54:25 -0700980 return Error::NONE;
981 }
982
Ady Abrahamde792782021-12-20 10:00:49 -0800983 { // scope for results
984 std::vector<CommandResultPayload> results;
985 auto status = mAidlComposerClient->executeCommands(commands, &results);
986 if (!status.isOk()) {
987 ALOGE("executeCommands failed %s", status.getDescription().c_str());
988 return static_cast<Error>(status.getServiceSpecificError());
989 }
Ady Abrahame7385f72021-09-05 00:54:25 -0700990
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400991 reader->get().parse(std::move(results));
Ady Abrahamde792782021-12-20 10:00:49 -0800992 }
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400993 const auto commandErrors = reader->get().takeErrors();
Ady Abrahama6388c02021-11-11 21:11:51 -0800994 Error error = Error::NONE;
995 for (const auto& cmdErr : commandErrors) {
996 const auto index = static_cast<size_t>(cmdErr.commandIndex);
997 if (index < 0 || index >= commands.size()) {
998 ALOGE("invalid command index %zu", index);
999 return Error::BAD_PARAMETER;
Ady Abrahame7385f72021-09-05 00:54:25 -07001000 }
1001
Ady Abrahama6388c02021-11-11 21:11:51 -08001002 const auto& command = commands[index];
Ady Abraham42977362021-12-07 21:04:49 -08001003 if (command.validateDisplay || command.presentDisplay || command.presentOrValidateDisplay) {
1004 error = translate<Error>(cmdErr.errorCode);
1005 } else {
1006 ALOGW("command '%s' generated error %" PRId32, command.toString().c_str(),
1007 cmdErr.errorCode);
Ady Abrahame7385f72021-09-05 00:54:25 -07001008 }
1009 }
1010
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -04001011 writer->get().reset();
Ady Abrahame7385f72021-09-05 00:54:25 -07001012
1013 return error;
1014}
1015
1016Error AidlComposer::setLayerPerFrameMetadata(
1017 Display display, Layer layer,
1018 const std::vector<IComposerClient::PerFrameMetadata>& perFrameMetadatas) {
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -04001019 Error error = Error::NONE;
1020 mMutex.lock_shared();
1021 if (auto writer = getWriter(display)) {
1022 writer->get().setLayerPerFrameMetadata(translate<int64_t>(display),
1023 translate<int64_t>(layer),
1024 translate<AidlPerFrameMetadata>(perFrameMetadatas));
1025 } else {
1026 error = Error::BAD_DISPLAY;
1027 }
1028 mMutex.unlock_shared();
1029 return error;
Ady Abrahame7385f72021-09-05 00:54:25 -07001030}
1031
1032std::vector<IComposerClient::PerFrameMetadataKey> AidlComposer::getPerFrameMetadataKeys(
1033 Display display) {
1034 std::vector<AidlPerFrameMetadataKey> keys;
1035 const auto status =
1036 mAidlComposerClient->getPerFrameMetadataKeys(translate<int64_t>(display), &keys);
1037 if (!status.isOk()) {
1038 ALOGE("getPerFrameMetadataKeys failed %s", status.getDescription().c_str());
1039 return {};
1040 }
1041 return translate<IComposerClient::PerFrameMetadataKey>(keys);
1042}
1043
1044Error AidlComposer::getRenderIntents(Display display, ColorMode colorMode,
1045 std::vector<RenderIntent>* outRenderIntents) {
1046 std::vector<AidlRenderIntent> renderIntents;
1047 const auto status = mAidlComposerClient->getRenderIntents(translate<int64_t>(display),
1048 translate<AidlColorMode>(colorMode),
1049 &renderIntents);
1050 if (!status.isOk()) {
1051 ALOGE("getRenderIntents failed %s", status.getDescription().c_str());
1052 return static_cast<Error>(status.getServiceSpecificError());
1053 }
1054 *outRenderIntents = translate<RenderIntent>(renderIntents);
1055 return Error::NONE;
1056}
1057
1058Error AidlComposer::getDataspaceSaturationMatrix(Dataspace dataspace, mat4* outMatrix) {
1059 std::vector<float> matrix;
1060 const auto status =
1061 mAidlComposerClient->getDataspaceSaturationMatrix(translate<AidlDataspace>(dataspace),
1062 &matrix);
1063 if (!status.isOk()) {
1064 ALOGE("getDataspaceSaturationMatrix failed %s", status.getDescription().c_str());
1065 return static_cast<Error>(status.getServiceSpecificError());
1066 }
1067 *outMatrix = makeMat4(matrix);
1068 return Error::NONE;
1069}
1070
1071Error AidlComposer::getDisplayIdentificationData(Display display, uint8_t* outPort,
1072 std::vector<uint8_t>* outData) {
1073 AidlDisplayIdentification displayIdentification;
1074 const auto status =
1075 mAidlComposerClient->getDisplayIdentificationData(translate<int64_t>(display),
1076 &displayIdentification);
1077 if (!status.isOk()) {
1078 ALOGE("getDisplayIdentificationData failed %s", status.getDescription().c_str());
1079 return static_cast<Error>(status.getServiceSpecificError());
1080 }
1081
1082 *outPort = static_cast<uint8_t>(displayIdentification.port);
1083 *outData = displayIdentification.data;
1084
1085 return Error::NONE;
1086}
1087
1088Error AidlComposer::setLayerColorTransform(Display display, Layer layer, const float* matrix) {
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -04001089 Error error = Error::NONE;
1090 mMutex.lock_shared();
1091 if (auto writer = getWriter(display)) {
1092 writer->get().setLayerColorTransform(translate<int64_t>(display), translate<int64_t>(layer),
1093 matrix);
1094 } else {
1095 error = Error::BAD_DISPLAY;
1096 }
1097 mMutex.unlock_shared();
1098 return error;
Ady Abrahame7385f72021-09-05 00:54:25 -07001099}
1100
1101Error AidlComposer::getDisplayedContentSamplingAttributes(Display display, PixelFormat* outFormat,
1102 Dataspace* outDataspace,
1103 uint8_t* outComponentMask) {
1104 if (!outFormat || !outDataspace || !outComponentMask) {
1105 return Error::BAD_PARAMETER;
1106 }
1107
1108 AidlDisplayContentSamplingAttributes attributes;
1109 const auto status =
1110 mAidlComposerClient->getDisplayedContentSamplingAttributes(translate<int64_t>(display),
1111 &attributes);
1112 if (!status.isOk()) {
1113 ALOGE("getDisplayedContentSamplingAttributes failed %s", status.getDescription().c_str());
1114 return static_cast<Error>(status.getServiceSpecificError());
1115 }
1116
1117 *outFormat = translate<PixelFormat>(attributes.format);
1118 *outDataspace = translate<Dataspace>(attributes.dataspace);
1119 *outComponentMask = static_cast<uint8_t>(attributes.componentMask);
1120 return Error::NONE;
1121}
1122
1123Error AidlComposer::setDisplayContentSamplingEnabled(Display display, bool enabled,
1124 uint8_t componentMask, uint64_t maxFrames) {
1125 const auto status =
1126 mAidlComposerClient
1127 ->setDisplayedContentSamplingEnabled(translate<int64_t>(display), enabled,
1128 static_cast<AidlFormatColorComponent>(
1129 componentMask),
1130 static_cast<int64_t>(maxFrames));
1131 if (!status.isOk()) {
1132 ALOGE("setDisplayedContentSamplingEnabled failed %s", status.getDescription().c_str());
1133 return static_cast<Error>(status.getServiceSpecificError());
1134 }
1135 return Error::NONE;
1136}
1137
1138Error AidlComposer::getDisplayedContentSample(Display display, uint64_t maxFrames,
1139 uint64_t timestamp, DisplayedFrameStats* outStats) {
1140 if (!outStats) {
1141 return Error::BAD_PARAMETER;
1142 }
1143
1144 AidlDisplayContentSample sample;
1145 const auto status =
1146 mAidlComposerClient->getDisplayedContentSample(translate<int64_t>(display),
1147 static_cast<int64_t>(maxFrames),
1148 static_cast<int64_t>(timestamp),
1149 &sample);
1150 if (!status.isOk()) {
1151 ALOGE("getDisplayedContentSample failed %s", status.getDescription().c_str());
1152 return static_cast<Error>(status.getServiceSpecificError());
1153 }
1154 *outStats = translate<DisplayedFrameStats>(sample);
1155 return Error::NONE;
1156}
1157
1158Error AidlComposer::setLayerPerFrameMetadataBlobs(
1159 Display display, Layer layer,
1160 const std::vector<IComposerClient::PerFrameMetadataBlob>& metadata) {
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -04001161 Error error = Error::NONE;
1162 mMutex.lock_shared();
1163 if (auto writer = getWriter(display)) {
1164 writer->get().setLayerPerFrameMetadataBlobs(translate<int64_t>(display),
1165 translate<int64_t>(layer),
1166 translate<AidlPerFrameMetadataBlob>(metadata));
1167 } else {
1168 error = Error::BAD_DISPLAY;
1169 }
1170 mMutex.unlock_shared();
1171 return error;
Ady Abrahame7385f72021-09-05 00:54:25 -07001172}
1173
Alec Mouri4d8a05d2022-03-23 18:14:26 +00001174Error AidlComposer::setDisplayBrightness(Display display, float brightness, float brightnessNits,
Alec Mouricdf16792021-12-10 13:16:06 -08001175 const DisplayBrightnessOptions& options) {
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -04001176 Error error = Error::NONE;
1177 mMutex.lock_shared();
1178 if (auto writer = getWriter(display)) {
1179 writer->get().setDisplayBrightness(translate<int64_t>(display), brightness, brightnessNits);
Alec Mouricdf16792021-12-10 13:16:06 -08001180
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -04001181 if (options.applyImmediately) {
1182 error = execute(display);
1183 mMutex.unlock_shared();
1184 return error;
1185 }
1186 } else {
1187 error = Error::BAD_DISPLAY;
Alec Mouricdf16792021-12-10 13:16:06 -08001188 }
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -04001189 mMutex.unlock_shared();
1190 return error;
Ady Abrahame7385f72021-09-05 00:54:25 -07001191}
1192
1193Error AidlComposer::getDisplayCapabilities(Display display,
Leon Scroggins III5967aec2021-12-29 11:14:22 -05001194 std::vector<AidlDisplayCapability>* outCapabilities) {
1195 const auto status = mAidlComposerClient->getDisplayCapabilities(translate<int64_t>(display),
1196 outCapabilities);
Ady Abrahame7385f72021-09-05 00:54:25 -07001197 if (!status.isOk()) {
1198 ALOGE("getDisplayCapabilities failed %s", status.getDescription().c_str());
Leon Scroggins III5967aec2021-12-29 11:14:22 -05001199 outCapabilities->clear();
Ady Abrahame7385f72021-09-05 00:54:25 -07001200 return static_cast<Error>(status.getServiceSpecificError());
1201 }
Ady Abrahame7385f72021-09-05 00:54:25 -07001202 return Error::NONE;
1203}
1204
1205V2_4::Error AidlComposer::getDisplayConnectionType(
1206 Display display, IComposerClient::DisplayConnectionType* outType) {
1207 AidlDisplayConnectionType type;
1208 const auto status =
1209 mAidlComposerClient->getDisplayConnectionType(translate<int64_t>(display), &type);
1210 if (!status.isOk()) {
1211 ALOGE("getDisplayConnectionType failed %s", status.getDescription().c_str());
1212 return static_cast<V2_4::Error>(status.getServiceSpecificError());
1213 }
1214 *outType = translate<IComposerClient::DisplayConnectionType>(type);
1215 return V2_4::Error::NONE;
1216}
1217
1218V2_4::Error AidlComposer::getDisplayVsyncPeriod(Display display, VsyncPeriodNanos* outVsyncPeriod) {
1219 int32_t vsyncPeriod;
1220 const auto status =
1221 mAidlComposerClient->getDisplayVsyncPeriod(translate<int64_t>(display), &vsyncPeriod);
1222 if (!status.isOk()) {
1223 ALOGE("getDisplayVsyncPeriod failed %s", status.getDescription().c_str());
1224 return static_cast<V2_4::Error>(status.getServiceSpecificError());
1225 }
1226 *outVsyncPeriod = translate<VsyncPeriodNanos>(vsyncPeriod);
1227 return V2_4::Error::NONE;
1228}
1229
1230V2_4::Error AidlComposer::setActiveConfigWithConstraints(
1231 Display display, Config config,
1232 const IComposerClient::VsyncPeriodChangeConstraints& vsyncPeriodChangeConstraints,
1233 VsyncPeriodChangeTimeline* outTimeline) {
1234 AidlVsyncPeriodChangeTimeline timeline;
1235 const auto status =
1236 mAidlComposerClient
1237 ->setActiveConfigWithConstraints(translate<int64_t>(display),
1238 translate<int32_t>(config),
1239 translate<AidlVsyncPeriodChangeConstraints>(
1240 vsyncPeriodChangeConstraints),
1241 &timeline);
1242 if (!status.isOk()) {
1243 ALOGE("setActiveConfigWithConstraints failed %s", status.getDescription().c_str());
1244 return static_cast<V2_4::Error>(status.getServiceSpecificError());
1245 }
1246 *outTimeline = translate<VsyncPeriodChangeTimeline>(timeline);
1247 return V2_4::Error::NONE;
1248}
1249
1250V2_4::Error AidlComposer::setAutoLowLatencyMode(Display display, bool on) {
1251 const auto status = mAidlComposerClient->setAutoLowLatencyMode(translate<int64_t>(display), on);
1252 if (!status.isOk()) {
1253 ALOGE("setAutoLowLatencyMode failed %s", status.getDescription().c_str());
1254 return static_cast<V2_4::Error>(status.getServiceSpecificError());
1255 }
1256 return V2_4::Error::NONE;
1257}
1258
1259V2_4::Error AidlComposer::getSupportedContentTypes(
1260 Display displayId, std::vector<IComposerClient::ContentType>* outSupportedContentTypes) {
1261 std::vector<AidlContentType> types;
1262 const auto status =
1263 mAidlComposerClient->getSupportedContentTypes(translate<int64_t>(displayId), &types);
1264 if (!status.isOk()) {
1265 ALOGE("getSupportedContentTypes failed %s", status.getDescription().c_str());
1266 return static_cast<V2_4::Error>(status.getServiceSpecificError());
1267 }
1268 *outSupportedContentTypes = translate<IComposerClient::ContentType>(types);
1269 return V2_4::Error::NONE;
1270}
1271
1272V2_4::Error AidlComposer::setContentType(Display display,
1273 IComposerClient::ContentType contentType) {
1274 const auto status =
1275 mAidlComposerClient->setContentType(translate<int64_t>(display),
1276 translate<AidlContentType>(contentType));
1277 if (!status.isOk()) {
1278 ALOGE("setContentType failed %s", status.getDescription().c_str());
1279 return static_cast<V2_4::Error>(status.getServiceSpecificError());
1280 }
1281 return V2_4::Error::NONE;
1282}
1283
Ady Abraham3f976752021-12-20 16:17:50 -08001284V2_4::Error AidlComposer::setLayerGenericMetadata(Display, Layer, const std::string&, bool,
1285 const std::vector<uint8_t>&) {
1286 // There are no users for this API. See b/209691612.
1287 return V2_4::Error::UNSUPPORTED;
Ady Abrahame7385f72021-09-05 00:54:25 -07001288}
1289
1290V2_4::Error AidlComposer::getLayerGenericMetadataKeys(
Ady Abraham3f976752021-12-20 16:17:50 -08001291 std::vector<IComposerClient::LayerGenericMetadataKey>*) {
1292 // There are no users for this API. See b/209691612.
1293 return V2_4::Error::UNSUPPORTED;
Ady Abrahame7385f72021-09-05 00:54:25 -07001294}
1295
Kriti Dang7defaf32021-11-15 11:55:43 +01001296Error AidlComposer::setBootDisplayConfig(Display display, Config config) {
1297 const auto status = mAidlComposerClient->setBootDisplayConfig(translate<int64_t>(display),
1298 translate<int32_t>(config));
1299 if (!status.isOk()) {
1300 ALOGE("setBootDisplayConfig failed %s", status.getDescription().c_str());
1301 return static_cast<Error>(status.getServiceSpecificError());
1302 }
1303 return Error::NONE;
1304}
1305
1306Error AidlComposer::clearBootDisplayConfig(Display display) {
1307 const auto status = mAidlComposerClient->clearBootDisplayConfig(translate<int64_t>(display));
1308 if (!status.isOk()) {
1309 ALOGE("clearBootDisplayConfig failed %s", status.getDescription().c_str());
1310 return static_cast<Error>(status.getServiceSpecificError());
1311 }
1312 return Error::NONE;
1313}
1314
1315Error AidlComposer::getPreferredBootDisplayConfig(Display display, Config* config) {
1316 int32_t displayConfig;
1317 const auto status =
1318 mAidlComposerClient->getPreferredBootDisplayConfig(translate<int64_t>(display),
1319 &displayConfig);
1320 if (!status.isOk()) {
1321 ALOGE("getPreferredBootDisplayConfig failed %s", status.getDescription().c_str());
1322 return static_cast<Error>(status.getServiceSpecificError());
1323 }
1324 *config = translate<uint32_t>(displayConfig);
1325 return Error::NONE;
1326}
1327
Ady Abrahame7385f72021-09-05 00:54:25 -07001328Error AidlComposer::getClientTargetProperty(
Alec Mouri85065692022-03-18 00:58:26 +00001329 Display display, ClientTargetPropertyWithBrightness* outClientTargetProperty) {
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -04001330 Error error = Error::NONE;
1331 mMutex.lock_shared();
1332 if (auto reader = getReader(display)) {
1333 *outClientTargetProperty =
1334 reader->get().takeClientTargetProperty(translate<int64_t>(display));
1335 } else {
1336 error = Error::BAD_DISPLAY;
1337 }
1338 mMutex.unlock_shared();
1339 return error;
Ady Abrahame7385f72021-09-05 00:54:25 -07001340}
1341
Alec Mouri6da0e272022-02-07 12:45:57 -08001342Error AidlComposer::setLayerBrightness(Display display, Layer layer, float brightness) {
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -04001343 Error error = Error::NONE;
1344 mMutex.lock_shared();
1345 if (auto writer = getWriter(display)) {
1346 writer->get().setLayerBrightness(translate<int64_t>(display), translate<int64_t>(layer),
1347 brightness);
1348 } else {
1349 error = Error::BAD_DISPLAY;
1350 }
1351 mMutex.unlock_shared();
1352 return error;
Alec Mouricdf6cbc2021-11-01 17:21:15 -07001353}
1354
Leon Scroggins IIId77d3162022-01-05 10:42:28 -05001355Error AidlComposer::setLayerBlockingRegion(Display display, Layer layer,
1356 const std::vector<IComposerClient::Rect>& blocking) {
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -04001357 Error error = Error::NONE;
1358 mMutex.lock_shared();
1359 if (auto writer = getWriter(display)) {
1360 writer->get().setLayerBlockingRegion(translate<int64_t>(display), translate<int64_t>(layer),
1361 translate<AidlRect>(blocking));
1362 } else {
1363 error = Error::BAD_DISPLAY;
1364 }
1365 mMutex.unlock_shared();
1366 return error;
Leon Scroggins IIId77d3162022-01-05 10:42:28 -05001367}
Leon Scroggins IIIe7c51c62022-02-01 15:53:54 -05001368
1369Error AidlComposer::getDisplayDecorationSupport(Display display,
1370 std::optional<DisplayDecorationSupport>* support) {
1371 const auto status =
1372 mAidlComposerClient->getDisplayDecorationSupport(translate<int64_t>(display), support);
1373 if (!status.isOk()) {
1374 ALOGE("getDisplayDecorationSupport failed %s", status.getDescription().c_str());
1375 support->reset();
1376 return static_cast<Error>(status.getServiceSpecificError());
1377 }
1378 return Error::NONE;
1379}
ramindani32cf0602022-03-02 02:30:29 +00001380
1381Error AidlComposer::setIdleTimerEnabled(Display displayId, std::chrono::milliseconds timeout) {
1382 const auto status =
1383 mAidlComposerClient->setIdleTimerEnabled(translate<int64_t>(displayId),
1384 translate<int32_t>(timeout.count()));
1385 if (!status.isOk()) {
1386 ALOGE("setIdleTimerEnabled failed %s", status.getDescription().c_str());
1387 return static_cast<Error>(status.getServiceSpecificError());
1388 }
1389 return Error::NONE;
1390}
1391
ramindani06e518e2022-03-14 18:47:53 +00001392Error AidlComposer::getPhysicalDisplayOrientation(Display displayId,
1393 AidlTransform* outDisplayOrientation) {
1394 const auto status =
1395 mAidlComposerClient->getDisplayPhysicalOrientation(translate<int64_t>(displayId),
1396 outDisplayOrientation);
1397 if (!status.isOk()) {
1398 ALOGE("getPhysicalDisplayOrientation failed %s", status.getDescription().c_str());
1399 return static_cast<Error>(status.getServiceSpecificError());
1400 }
1401 return Error::NONE;
1402}
1403
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -04001404ftl::Optional<std::reference_wrapper<ComposerClientWriter>> AidlComposer::getWriter(Display display)
1405 REQUIRES_SHARED(mMutex) {
1406 return mWriters.get(display);
1407}
1408
1409ftl::Optional<std::reference_wrapper<ComposerClientReader>> AidlComposer::getReader(Display display)
1410 REQUIRES_SHARED(mMutex) {
1411 if (mSingleReader) {
1412 display = translate<Display>(kSingleReaderKey);
1413 }
1414 return mReaders.get(display);
1415}
1416
1417void AidlComposer::removeDisplay(Display display) {
1418 mMutex.lock();
1419 bool wasErased = mWriters.erase(display);
1420 ALOGW_IF(!wasErased,
1421 "Attempting to remove writer for display %" PRId64 " which is not connected",
1422 translate<int64_t>(display));
1423 if (!mSingleReader) {
1424 removeReader(display);
1425 }
1426 mMutex.unlock();
1427}
1428
1429void AidlComposer::onHotplugDisconnect(Display display) {
1430 removeDisplay(display);
1431}
1432
1433bool AidlComposer::hasMultiThreadedPresentSupport(Display display) {
1434 const auto displayId = translate<int64_t>(display);
1435 std::vector<AidlDisplayCapability> capabilities;
1436 const auto status = mAidlComposerClient->getDisplayCapabilities(displayId, &capabilities);
1437 if (!status.isOk()) {
1438 ALOGE("getDisplayCapabilities failed %s", status.getDescription().c_str());
1439 return false;
1440 }
1441 return std::find(capabilities.begin(), capabilities.end(),
1442 AidlDisplayCapability::MULTI_THREADED_PRESENT) != capabilities.end();
1443}
1444
1445void AidlComposer::addReader(Display display) {
1446 const auto displayId = translate<int64_t>(display);
1447 std::optional<int64_t> displayOpt;
1448 if (displayId != kSingleReaderKey) {
1449 displayOpt.emplace(displayId);
1450 }
1451 auto [it, added] = mReaders.try_emplace(display, std::move(displayOpt));
1452 ALOGW_IF(!added, "Attempting to add writer for display %" PRId64 " which is already connected",
1453 displayId);
1454}
1455
1456void AidlComposer::removeReader(Display display) {
1457 bool wasErased = mReaders.erase(display);
1458 ALOGW_IF(!wasErased,
1459 "Attempting to remove reader for display %" PRId64 " which is not connected",
1460 translate<int64_t>(display));
1461}
1462
1463void AidlComposer::addDisplay(Display display) {
1464 const auto displayId = translate<int64_t>(display);
1465 mMutex.lock();
1466 auto [it, added] = mWriters.try_emplace(display, displayId);
1467 ALOGW_IF(!added, "Attempting to add writer for display %" PRId64 " which is already connected",
1468 displayId);
1469 if (mSingleReader) {
1470 if (hasMultiThreadedPresentSupport(display)) {
1471 mSingleReader = false;
1472 removeReader(translate<Display>(kSingleReaderKey));
1473 // Note that this includes the new display.
1474 for (const auto& [existingDisplay, _] : mWriters) {
1475 addReader(existingDisplay);
1476 }
1477 }
1478 } else {
1479 addReader(display);
1480 }
1481 mMutex.unlock();
1482}
1483
1484void AidlComposer::onHotplugConnect(Display display) {
1485 addDisplay(display);
1486}
Ady Abrahame7385f72021-09-05 00:54:25 -07001487} // namespace Hwc2
1488} // namespace android