blob: a93bd95e48c71bc2f53c2d9316c1927a8aa7d64a [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
Brian Lindahl90553da2022-12-06 13:36:30 -0700235 // TODO(b/262041682): When using new API to clear buffer slots, don't allocate this buffer.
236 mClearSlotBuffer = sp<GraphicBuffer>::make(1, 1, PIXEL_FORMAT_RGBX_8888,
237 GraphicBuffer::USAGE_HW_COMPOSER |
238 GraphicBuffer::USAGE_SW_READ_OFTEN |
239 GraphicBuffer::USAGE_SW_WRITE_OFTEN,
240 "AidlComposer");
241 if (!mClearSlotBuffer || mClearSlotBuffer->initCheck() != ::android::OK) {
242 LOG_ALWAYS_FATAL("Failed to allocate a buffer for clearing layer buffer slots");
243 return;
244 }
245
Ady Abrahame7385f72021-09-05 00:54:25 -0700246 ALOGI("Loaded AIDL composer3 HAL service");
247}
248
249AidlComposer::~AidlComposer() = default;
250
Ady Abraham4d211cf2021-12-14 16:19:03 -0800251bool AidlComposer::isSupported(OptionalFeature feature) const {
252 switch (feature) {
253 case OptionalFeature::RefreshRateSwitching:
Ady Abraham43065bd2021-12-10 17:22:15 -0800254 case OptionalFeature::ExpectedPresentTime:
Alec Mouricdf16792021-12-10 13:16:06 -0800255 case OptionalFeature::DisplayBrightnessCommand:
ramindani32cf0602022-03-02 02:30:29 +0000256 case OptionalFeature::KernelIdleTimer:
ramindani06e518e2022-03-14 18:47:53 +0000257 case OptionalFeature::PhysicalDisplayOrientation:
Ady Abraham4d211cf2021-12-14 16:19:03 -0800258 return true;
259 }
260}
261
Ady Abrahamde549d42022-01-26 19:19:17 -0800262std::vector<Capability> AidlComposer::getCapabilities() {
Ady Abrahame7385f72021-09-05 00:54:25 -0700263 std::vector<Capability> capabilities;
264 const auto status = mAidlComposer->getCapabilities(&capabilities);
265 if (!status.isOk()) {
266 ALOGE("getCapabilities failed %s", status.getDescription().c_str());
267 return {};
268 }
Ady Abrahamde549d42022-01-26 19:19:17 -0800269 return capabilities;
Ady Abrahame7385f72021-09-05 00:54:25 -0700270}
271
272std::string AidlComposer::dumpDebugInfo() {
Ady Abrahamc4acf512022-02-18 17:11:59 -0800273 int pipefds[2];
274 int result = pipe(pipefds);
275 if (result < 0) {
276 ALOGE("dumpDebugInfo: pipe failed: %s", strerror(errno));
Ady Abrahame7385f72021-09-05 00:54:25 -0700277 return {};
278 }
Ady Abrahamc4acf512022-02-18 17:11:59 -0800279
280 std::string str;
yihsing.shen58847c52022-09-23 15:39:30 +0800281 // Use other thread to read pipe to prevent
282 // pipe is full, making HWC be blocked in writing.
283 std::thread t([&]() {
284 base::ReadFdToString(pipefds[0], &str);
285 });
Ady Abrahamc4acf512022-02-18 17:11:59 -0800286 const auto status = mAidlComposer->dump(pipefds[1], /*args*/ nullptr, /*numArgs*/ 0);
287 // Close the write-end of the pipe to make sure that when reading from the
288 // read-end we will get eof instead of blocking forever
289 close(pipefds[1]);
290
yihsing.shen58847c52022-09-23 15:39:30 +0800291 if (status != STATUS_OK) {
Ady Abrahamc4acf512022-02-18 17:11:59 -0800292 ALOGE("dumpDebugInfo: dump failed: %d", status);
293 }
294
yihsing.shen58847c52022-09-23 15:39:30 +0800295 t.join();
Ady Abrahamc4acf512022-02-18 17:11:59 -0800296 close(pipefds[0]);
297 return str;
Ady Abrahame7385f72021-09-05 00:54:25 -0700298}
299
Yichi Chen3401b562022-01-17 15:42:35 +0800300void AidlComposer::registerCallback(HWC2::ComposerCallback& callback) {
Ady Abrahame7385f72021-09-05 00:54:25 -0700301 if (mAidlComposerCallback) {
302 ALOGE("Callback already registered");
303 }
Yichi Chen3401b562022-01-17 15:42:35 +0800304
Ady Abraham9fc28052021-10-14 17:21:38 -0700305 mAidlComposerCallback = ndk::SharedRefBase::make<AidlIComposerCallbackWrapper>(callback);
Ady Abrahame7385f72021-09-05 00:54:25 -0700306 AIBinder_setMinSchedulerPolicy(mAidlComposerCallback->asBinder().get(), SCHED_FIFO, 2);
307
308 const auto status = mAidlComposerClient->registerCallback(mAidlComposerCallback);
309 if (!status.isOk()) {
310 ALOGE("registerCallback failed %s", status.getDescription().c_str());
311 }
312}
313
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400314void AidlComposer::resetCommands(Display display) {
315 mMutex.lock_shared();
316 if (auto writer = getWriter(display)) {
317 writer->get().reset();
318 }
319 mMutex.unlock_shared();
Ady Abrahame7385f72021-09-05 00:54:25 -0700320}
321
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400322Error AidlComposer::executeCommands(Display display) {
323 mMutex.lock_shared();
324 auto error = execute(display);
325 mMutex.unlock_shared();
326 return error;
Ady Abrahame7385f72021-09-05 00:54:25 -0700327}
328
329uint32_t AidlComposer::getMaxVirtualDisplayCount() {
330 int32_t count = 0;
331 const auto status = mAidlComposerClient->getMaxVirtualDisplayCount(&count);
332 if (!status.isOk()) {
333 ALOGE("getMaxVirtualDisplayCount failed %s", status.getDescription().c_str());
334 return 0;
335 }
336 return static_cast<uint32_t>(count);
337}
338
339Error AidlComposer::createVirtualDisplay(uint32_t width, uint32_t height, PixelFormat* format,
340 Display* outDisplay) {
341 using AidlPixelFormat = aidl::android::hardware::graphics::common::PixelFormat;
342 const int32_t bufferSlotCount = 1;
343 VirtualDisplay virtualDisplay;
344 const auto status =
345 mAidlComposerClient->createVirtualDisplay(static_cast<int32_t>(width),
346 static_cast<int32_t>(height),
347 static_cast<AidlPixelFormat>(*format),
348 bufferSlotCount, &virtualDisplay);
349
350 if (!status.isOk()) {
351 ALOGE("createVirtualDisplay failed %s", status.getDescription().c_str());
352 return static_cast<Error>(status.getServiceSpecificError());
353 }
354
355 *outDisplay = translate<Display>(virtualDisplay.display);
356 *format = static_cast<PixelFormat>(virtualDisplay.format);
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400357 addDisplay(translate<Display>(virtualDisplay.display));
Ady Abrahame7385f72021-09-05 00:54:25 -0700358 return Error::NONE;
359}
360
361Error AidlComposer::destroyVirtualDisplay(Display display) {
362 const auto status = mAidlComposerClient->destroyVirtualDisplay(translate<int64_t>(display));
363 if (!status.isOk()) {
364 ALOGE("destroyVirtualDisplay failed %s", status.getDescription().c_str());
365 return static_cast<Error>(status.getServiceSpecificError());
366 }
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400367 removeDisplay(display);
Ady Abrahame7385f72021-09-05 00:54:25 -0700368 return Error::NONE;
369}
370
371Error AidlComposer::acceptDisplayChanges(Display display) {
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400372 Error error = Error::NONE;
373 mMutex.lock_shared();
374 if (auto writer = getWriter(display)) {
375 writer->get().acceptDisplayChanges(translate<int64_t>(display));
376 } else {
377 error = Error::BAD_DISPLAY;
378 }
379 mMutex.unlock_shared();
380 return error;
Ady Abrahame7385f72021-09-05 00:54:25 -0700381}
382
383Error AidlComposer::createLayer(Display display, Layer* outLayer) {
384 int64_t layer;
385 const auto status = mAidlComposerClient->createLayer(translate<int64_t>(display),
386 kMaxLayerBufferCount, &layer);
387 if (!status.isOk()) {
388 ALOGE("createLayer failed %s", status.getDescription().c_str());
389 return static_cast<Error>(status.getServiceSpecificError());
390 }
391
392 *outLayer = translate<Layer>(layer);
393 return Error::NONE;
394}
395
396Error AidlComposer::destroyLayer(Display display, Layer layer) {
397 const auto status = mAidlComposerClient->destroyLayer(translate<int64_t>(display),
398 translate<int64_t>(layer));
399 if (!status.isOk()) {
400 ALOGE("destroyLayer failed %s", status.getDescription().c_str());
401 return static_cast<Error>(status.getServiceSpecificError());
402 }
403 return Error::NONE;
404}
405
406Error AidlComposer::getActiveConfig(Display display, Config* outConfig) {
407 int32_t config;
408 const auto status = mAidlComposerClient->getActiveConfig(translate<int64_t>(display), &config);
409 if (!status.isOk()) {
410 ALOGE("getActiveConfig failed %s", status.getDescription().c_str());
411 return static_cast<Error>(status.getServiceSpecificError());
412 }
413 *outConfig = translate<Config>(config);
414 return Error::NONE;
415}
416
417Error AidlComposer::getChangedCompositionTypes(
418 Display display, std::vector<Layer>* outLayers,
Leon Scroggins III2e1aa182021-12-01 17:33:12 -0500419 std::vector<aidl::android::hardware::graphics::composer3::Composition>* outTypes) {
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400420 std::vector<ChangedCompositionLayer> changedLayers;
421 Error error = Error::NONE;
422 {
423 mMutex.lock_shared();
424 if (auto reader = getReader(display)) {
425 changedLayers = reader->get().takeChangedCompositionTypes(translate<int64_t>(display));
426 } else {
427 error = Error::BAD_DISPLAY;
428 }
429 mMutex.unlock_shared();
430 }
Ady Abrahamde792782021-12-20 10:00:49 -0800431 outLayers->reserve(changedLayers.size());
432 outTypes->reserve(changedLayers.size());
Ady Abrahama6388c02021-11-11 21:11:51 -0800433
Ady Abrahamde792782021-12-20 10:00:49 -0800434 for (const auto& layer : changedLayers) {
435 outLayers->emplace_back(translate<Layer>(layer.layer));
436 outTypes->emplace_back(layer.composition);
437 }
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400438 return error;
Ady Abrahame7385f72021-09-05 00:54:25 -0700439}
440
441Error AidlComposer::getColorModes(Display display, std::vector<ColorMode>* outModes) {
442 std::vector<AidlColorMode> modes;
443 const auto status = mAidlComposerClient->getColorModes(translate<int64_t>(display), &modes);
444 if (!status.isOk()) {
445 ALOGE("getColorModes failed %s", status.getDescription().c_str());
446 return static_cast<Error>(status.getServiceSpecificError());
447 }
448 *outModes = translate<ColorMode>(modes);
449 return Error::NONE;
450}
451
452Error AidlComposer::getDisplayAttribute(Display display, Config config,
453 IComposerClient::Attribute attribute, int32_t* outValue) {
454 const auto status =
455 mAidlComposerClient->getDisplayAttribute(translate<int64_t>(display),
456 translate<int32_t>(config),
457 static_cast<AidlDisplayAttribute>(attribute),
458 outValue);
459 if (!status.isOk()) {
460 ALOGE("getDisplayAttribute failed %s", status.getDescription().c_str());
461 return static_cast<Error>(status.getServiceSpecificError());
462 }
463 return Error::NONE;
464}
465
466Error AidlComposer::getDisplayConfigs(Display display, std::vector<Config>* outConfigs) {
467 std::vector<int32_t> configs;
468 const auto status =
469 mAidlComposerClient->getDisplayConfigs(translate<int64_t>(display), &configs);
470 if (!status.isOk()) {
471 ALOGE("getDisplayConfigs failed %s", status.getDescription().c_str());
472 return static_cast<Error>(status.getServiceSpecificError());
473 }
474 *outConfigs = translate<Config>(configs);
475 return Error::NONE;
476}
477
478Error AidlComposer::getDisplayName(Display display, std::string* outName) {
479 const auto status = mAidlComposerClient->getDisplayName(translate<int64_t>(display), outName);
480 if (!status.isOk()) {
481 ALOGE("getDisplayName failed %s", status.getDescription().c_str());
482 return static_cast<Error>(status.getServiceSpecificError());
483 }
484 return Error::NONE;
485}
486
487Error AidlComposer::getDisplayRequests(Display display, uint32_t* outDisplayRequestMask,
488 std::vector<Layer>* outLayers,
489 std::vector<uint32_t>* outLayerRequestMasks) {
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400490 Error error = Error::NONE;
491 DisplayRequest displayRequests;
492 {
493 mMutex.lock_shared();
494 if (auto reader = getReader(display)) {
495 displayRequests = reader->get().takeDisplayRequests(translate<int64_t>(display));
496 } else {
497 error = Error::BAD_DISPLAY;
498 }
499 mMutex.unlock_shared();
500 }
Ady Abrahamde792782021-12-20 10:00:49 -0800501 *outDisplayRequestMask = translate<uint32_t>(displayRequests.mask);
502 outLayers->reserve(displayRequests.layerRequests.size());
503 outLayerRequestMasks->reserve(displayRequests.layerRequests.size());
504
505 for (const auto& layer : displayRequests.layerRequests) {
506 outLayers->emplace_back(translate<Layer>(layer.layer));
507 outLayerRequestMasks->emplace_back(translate<uint32_t>(layer.mask));
508 }
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400509 return error;
Ady Abrahame7385f72021-09-05 00:54:25 -0700510}
511
512Error AidlComposer::getDozeSupport(Display display, bool* outSupport) {
Ady Abraham33b92b92021-12-08 18:30:27 -0800513 std::vector<AidlDisplayCapability> capabilities;
Ady Abrahame7385f72021-09-05 00:54:25 -0700514 const auto status =
Ady Abraham33b92b92021-12-08 18:30:27 -0800515 mAidlComposerClient->getDisplayCapabilities(translate<int64_t>(display), &capabilities);
Ady Abrahame7385f72021-09-05 00:54:25 -0700516 if (!status.isOk()) {
Ady Abraham33b92b92021-12-08 18:30:27 -0800517 ALOGE("getDisplayCapabilities failed %s", status.getDescription().c_str());
Ady Abrahame7385f72021-09-05 00:54:25 -0700518 return static_cast<Error>(status.getServiceSpecificError());
519 }
Ady Abraham33b92b92021-12-08 18:30:27 -0800520 *outSupport = std::find(capabilities.begin(), capabilities.end(),
521 AidlDisplayCapability::DOZE) != capabilities.end();
Ady Abrahame7385f72021-09-05 00:54:25 -0700522 return Error::NONE;
523}
524
ramindani32cf0602022-03-02 02:30:29 +0000525Error AidlComposer::hasDisplayIdleTimerCapability(Display display, bool* outSupport) {
526 std::vector<AidlDisplayCapability> capabilities;
527 const auto status =
528 mAidlComposerClient->getDisplayCapabilities(translate<int64_t>(display), &capabilities);
529 if (!status.isOk()) {
530 ALOGE("getDisplayCapabilities failed %s", status.getDescription().c_str());
531 return static_cast<Error>(status.getServiceSpecificError());
532 }
533 *outSupport = std::find(capabilities.begin(), capabilities.end(),
534 AidlDisplayCapability::DISPLAY_IDLE_TIMER) != capabilities.end();
535 return Error::NONE;
536}
537
Ady Abrahame7385f72021-09-05 00:54:25 -0700538Error AidlComposer::getHdrCapabilities(Display display, std::vector<Hdr>* outTypes,
539 float* outMaxLuminance, float* outMaxAverageLuminance,
540 float* outMinLuminance) {
541 AidlHdrCapabilities capabilities;
542 const auto status =
543 mAidlComposerClient->getHdrCapabilities(translate<int64_t>(display), &capabilities);
544 if (!status.isOk()) {
545 ALOGE("getHdrCapabilities failed %s", status.getDescription().c_str());
546 return static_cast<Error>(status.getServiceSpecificError());
547 }
548
Marc Kassisbdf7e4b2022-11-04 17:26:48 +0100549 *outTypes = capabilities.types;
Ady Abrahame7385f72021-09-05 00:54:25 -0700550 *outMaxLuminance = capabilities.maxLuminance;
551 *outMaxAverageLuminance = capabilities.maxAverageLuminance;
552 *outMinLuminance = capabilities.minLuminance;
553 return Error::NONE;
554}
555
Sally Qibb866c12022-10-17 11:31:20 -0700556Error AidlComposer::getOverlaySupport(AidlOverlayProperties* outProperties) {
557 const auto status = mAidlComposerClient->getOverlaySupport(outProperties);
558 if (!status.isOk()) {
559 ALOGE("getOverlaySupport failed %s", status.getDescription().c_str());
560 return static_cast<Error>(status.getServiceSpecificError());
561 }
Sally Qi0cbd08b2022-08-17 12:12:28 -0700562 return Error::NONE;
563}
564
Ady Abrahame7385f72021-09-05 00:54:25 -0700565Error AidlComposer::getReleaseFences(Display display, std::vector<Layer>* outLayers,
566 std::vector<int>* outReleaseFences) {
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400567 Error error = Error::NONE;
568 std::vector<ReleaseFences::Layer> fences;
569 {
570 mMutex.lock_shared();
571 if (auto reader = getReader(display)) {
572 fences = reader->get().takeReleaseFences(translate<int64_t>(display));
573 } else {
574 error = Error::BAD_DISPLAY;
575 }
576 mMutex.unlock_shared();
577 }
Ady Abrahamde792782021-12-20 10:00:49 -0800578 outLayers->reserve(fences.size());
579 outReleaseFences->reserve(fences.size());
580
581 for (auto& fence : fences) {
582 outLayers->emplace_back(translate<Layer>(fence.layer));
583 // take ownership
584 const int fenceOwner = fence.fence.get();
585 *fence.fence.getR() = -1;
586 outReleaseFences->emplace_back(fenceOwner);
587 }
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400588 return error;
Ady Abrahame7385f72021-09-05 00:54:25 -0700589}
590
591Error AidlComposer::presentDisplay(Display display, int* outPresentFence) {
592 ATRACE_NAME("HwcPresentDisplay");
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400593 Error error = Error::NONE;
594 mMutex.lock_shared();
595 auto writer = getWriter(display);
596 auto reader = getReader(display);
597 if (writer && reader) {
598 writer->get().presentDisplay(translate<int64_t>(display));
599 error = execute(display);
600 } else {
601 error = Error::BAD_DISPLAY;
602 }
Ady Abrahame7385f72021-09-05 00:54:25 -0700603
Ady Abrahame7385f72021-09-05 00:54:25 -0700604 if (error != Error::NONE) {
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400605 mMutex.unlock_shared();
Ady Abrahame7385f72021-09-05 00:54:25 -0700606 return error;
607 }
608
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400609 auto fence = reader->get().takePresentFence(translate<int64_t>(display));
610 mMutex.unlock_shared();
Ady Abrahamde792782021-12-20 10:00:49 -0800611 // take ownership
612 *outPresentFence = fence.get();
613 *fence.getR() = -1;
Ady Abrahame7385f72021-09-05 00:54:25 -0700614 return Error::NONE;
615}
616
617Error AidlComposer::setActiveConfig(Display display, Config config) {
618 const auto status = mAidlComposerClient->setActiveConfig(translate<int64_t>(display),
619 translate<int32_t>(config));
620 if (!status.isOk()) {
621 ALOGE("setActiveConfig failed %s", status.getDescription().c_str());
622 return static_cast<Error>(status.getServiceSpecificError());
623 }
624 return Error::NONE;
625}
626
627Error AidlComposer::setClientTarget(Display display, uint32_t slot, const sp<GraphicBuffer>& target,
628 int acquireFence, Dataspace dataspace,
629 const std::vector<IComposerClient::Rect>& damage) {
Ady Abrahame7385f72021-09-05 00:54:25 -0700630 const native_handle_t* handle = nullptr;
631 if (target.get()) {
632 handle = target->getNativeBuffer()->handle;
633 }
634
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400635 Error error = Error::NONE;
636 mMutex.lock_shared();
637 if (auto writer = getWriter(display)) {
638 writer->get()
639 .setClientTarget(translate<int64_t>(display), slot, handle, acquireFence,
640 translate<aidl::android::hardware::graphics::common::Dataspace>(
641 dataspace),
642 translate<AidlRect>(damage));
643 } else {
644 error = Error::BAD_DISPLAY;
645 }
646 mMutex.unlock_shared();
647 return error;
Ady Abrahame7385f72021-09-05 00:54:25 -0700648}
649
650Error AidlComposer::setColorMode(Display display, ColorMode mode, RenderIntent renderIntent) {
651 const auto status =
652 mAidlComposerClient->setColorMode(translate<int64_t>(display),
653 translate<AidlColorMode>(mode),
654 translate<AidlRenderIntent>(renderIntent));
655 if (!status.isOk()) {
656 ALOGE("setColorMode failed %s", status.getDescription().c_str());
657 return static_cast<Error>(status.getServiceSpecificError());
658 }
659 return Error::NONE;
660}
661
Ady Abrahamdc011a92021-12-21 14:06:44 -0800662Error AidlComposer::setColorTransform(Display display, const float* matrix) {
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400663 auto error = Error::NONE;
664 mMutex.lock_shared();
665 if (auto writer = getWriter(display)) {
666 writer->get().setColorTransform(translate<int64_t>(display), matrix);
667 } else {
668 error = Error::BAD_DISPLAY;
669 }
670 mMutex.unlock_shared();
671 return error;
Ady Abrahame7385f72021-09-05 00:54:25 -0700672}
673
674Error AidlComposer::setOutputBuffer(Display display, const native_handle_t* buffer,
675 int releaseFence) {
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400676 auto error = Error::NONE;
677 mMutex.lock_shared();
678 if (auto writer = getWriter(display)) {
679 writer->get().setOutputBuffer(translate<int64_t>(display), 0, buffer, dup(releaseFence));
680 } else {
681 error = Error::BAD_DISPLAY;
682 }
683 mMutex.unlock_shared();
684 return error;
Ady Abrahame7385f72021-09-05 00:54:25 -0700685}
686
687Error AidlComposer::setPowerMode(Display display, IComposerClient::PowerMode mode) {
688 const auto status = mAidlComposerClient->setPowerMode(translate<int64_t>(display),
689 translate<PowerMode>(mode));
690 if (!status.isOk()) {
691 ALOGE("setPowerMode failed %s", status.getDescription().c_str());
692 return static_cast<Error>(status.getServiceSpecificError());
693 }
694 return Error::NONE;
695}
696
697Error AidlComposer::setVsyncEnabled(Display display, IComposerClient::Vsync enabled) {
698 const bool enableVsync = enabled == IComposerClient::Vsync::ENABLE;
699 const auto status =
700 mAidlComposerClient->setVsyncEnabled(translate<int64_t>(display), enableVsync);
701 if (!status.isOk()) {
702 ALOGE("setVsyncEnabled failed %s", status.getDescription().c_str());
703 return static_cast<Error>(status.getServiceSpecificError());
704 }
705 return Error::NONE;
706}
707
708Error AidlComposer::setClientTargetSlotCount(Display display) {
709 const int32_t bufferSlotCount = BufferQueue::NUM_BUFFER_SLOTS;
710 const auto status = mAidlComposerClient->setClientTargetSlotCount(translate<int64_t>(display),
711 bufferSlotCount);
712 if (!status.isOk()) {
713 ALOGE("setClientTargetSlotCount failed %s", status.getDescription().c_str());
714 return static_cast<Error>(status.getServiceSpecificError());
715 }
716 return Error::NONE;
717}
718
Ady Abraham43065bd2021-12-10 17:22:15 -0800719Error AidlComposer::validateDisplay(Display display, nsecs_t expectedPresentTime,
720 uint32_t* outNumTypes, uint32_t* outNumRequests) {
Ady Abrahame7385f72021-09-05 00:54:25 -0700721 ATRACE_NAME("HwcValidateDisplay");
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400722 const auto displayId = translate<int64_t>(display);
723 Error error = Error::NONE;
724 mMutex.lock_shared();
725 auto writer = getWriter(display);
726 auto reader = getReader(display);
727 if (writer && reader) {
728 writer->get().validateDisplay(displayId, ClockMonotonicTimestamp{expectedPresentTime});
729 error = execute(display);
730 } else {
731 error = Error::BAD_DISPLAY;
732 }
Ady Abrahame7385f72021-09-05 00:54:25 -0700733
Ady Abrahame7385f72021-09-05 00:54:25 -0700734 if (error != Error::NONE) {
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400735 mMutex.unlock_shared();
Ady Abrahame7385f72021-09-05 00:54:25 -0700736 return error;
737 }
738
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400739 reader->get().hasChanges(displayId, outNumTypes, outNumRequests);
Ady Abrahame7385f72021-09-05 00:54:25 -0700740
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400741 mMutex.unlock_shared();
Ady Abrahame7385f72021-09-05 00:54:25 -0700742 return Error::NONE;
743}
744
Ady Abraham43065bd2021-12-10 17:22:15 -0800745Error AidlComposer::presentOrValidateDisplay(Display display, nsecs_t expectedPresentTime,
746 uint32_t* outNumTypes, uint32_t* outNumRequests,
747 int* outPresentFence, uint32_t* state) {
Ady Abrahame7385f72021-09-05 00:54:25 -0700748 ATRACE_NAME("HwcPresentOrValidateDisplay");
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400749 const auto displayId = translate<int64_t>(display);
750 Error error = Error::NONE;
751 mMutex.lock_shared();
752 auto writer = getWriter(display);
753 auto reader = getReader(display);
754 if (writer && reader) {
755 writer->get().presentOrvalidateDisplay(displayId,
756 ClockMonotonicTimestamp{expectedPresentTime});
757 error = execute(display);
758 } else {
759 error = Error::BAD_DISPLAY;
760 }
Ady Abrahame7385f72021-09-05 00:54:25 -0700761
Ady Abrahame7385f72021-09-05 00:54:25 -0700762 if (error != Error::NONE) {
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400763 mMutex.unlock_shared();
Ady Abrahame7385f72021-09-05 00:54:25 -0700764 return error;
765 }
766
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400767 const auto result = reader->get().takePresentOrValidateStage(displayId);
Ady Abrahamde792782021-12-20 10:00:49 -0800768 if (!result.has_value()) {
769 *state = translate<uint32_t>(-1);
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400770 mMutex.unlock_shared();
Ady Abrahamde792782021-12-20 10:00:49 -0800771 return Error::NO_RESOURCES;
Ady Abrahame7385f72021-09-05 00:54:25 -0700772 }
773
Ady Abrahamde792782021-12-20 10:00:49 -0800774 *state = translate<uint32_t>(*result);
775
776 if (*result == PresentOrValidate::Result::Presented) {
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400777 auto fence = reader->get().takePresentFence(displayId);
Ady Abrahamde792782021-12-20 10:00:49 -0800778 // take ownership
779 *outPresentFence = fence.get();
780 *fence.getR() = -1;
781 }
782
783 if (*result == PresentOrValidate::Result::Validated) {
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400784 reader->get().hasChanges(displayId, outNumTypes, outNumRequests);
Ady Abrahame7385f72021-09-05 00:54:25 -0700785 }
786
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400787 mMutex.unlock_shared();
Ady Abrahame7385f72021-09-05 00:54:25 -0700788 return Error::NONE;
789}
790
791Error AidlComposer::setCursorPosition(Display display, Layer layer, int32_t x, int32_t y) {
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400792 Error error = Error::NONE;
793 mMutex.lock_shared();
794 if (auto writer = getWriter(display)) {
795 writer->get().setLayerCursorPosition(translate<int64_t>(display), translate<int64_t>(layer),
796 x, y);
797 } else {
798 error = Error::BAD_DISPLAY;
799 }
800 mMutex.unlock_shared();
801 return error;
Ady Abrahame7385f72021-09-05 00:54:25 -0700802}
803
804Error AidlComposer::setLayerBuffer(Display display, Layer layer, uint32_t slot,
805 const sp<GraphicBuffer>& buffer, int acquireFence) {
Ady Abrahame7385f72021-09-05 00:54:25 -0700806 const native_handle_t* handle = nullptr;
807 if (buffer.get()) {
808 handle = buffer->getNativeBuffer()->handle;
809 }
810
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400811 Error error = Error::NONE;
812 mMutex.lock_shared();
813 if (auto writer = getWriter(display)) {
814 writer->get().setLayerBuffer(translate<int64_t>(display), translate<int64_t>(layer), slot,
815 handle, acquireFence);
816 } else {
817 error = Error::BAD_DISPLAY;
818 }
819 mMutex.unlock_shared();
820 return error;
Ady Abrahame7385f72021-09-05 00:54:25 -0700821}
822
Brian Lindahl90553da2022-12-06 13:36:30 -0700823Error AidlComposer::clearLayerBufferSlot(Display display, Layer layer, uint32_t slot) {
824 Error error = Error::NONE;
825 mMutex.lock_shared();
826 if (auto writer = getWriter(display)) {
827 writer->get().setLayerBufferWithNewCommand(translate<int64_t>(display),
828 translate<int64_t>(layer), slot,
829 mClearSlotBuffer->handle, /*fence*/ -1);
830 } else {
831 error = Error::BAD_DISPLAY;
832 }
833 mMutex.unlock_shared();
834 return error;
835}
836
Ady Abrahame7385f72021-09-05 00:54:25 -0700837Error AidlComposer::setLayerSurfaceDamage(Display display, Layer layer,
838 const std::vector<IComposerClient::Rect>& damage) {
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400839 Error error = Error::NONE;
840 mMutex.lock_shared();
841 if (auto writer = getWriter(display)) {
842 writer->get().setLayerSurfaceDamage(translate<int64_t>(display), translate<int64_t>(layer),
843 translate<AidlRect>(damage));
844 } else {
845 error = Error::BAD_DISPLAY;
846 }
847 mMutex.unlock_shared();
848 return error;
Ady Abrahame7385f72021-09-05 00:54:25 -0700849}
850
851Error AidlComposer::setLayerBlendMode(Display display, Layer layer,
852 IComposerClient::BlendMode mode) {
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400853 Error error = Error::NONE;
854 mMutex.lock_shared();
855 if (auto writer = getWriter(display)) {
856 writer->get().setLayerBlendMode(translate<int64_t>(display), translate<int64_t>(layer),
857 translate<BlendMode>(mode));
858 } else {
859 error = Error::BAD_DISPLAY;
860 }
861 mMutex.unlock_shared();
862 return error;
Ady Abrahame7385f72021-09-05 00:54:25 -0700863}
864
Ady Abraham6e60b142022-01-06 18:10:35 -0800865Error AidlComposer::setLayerColor(Display display, Layer layer, const Color& color) {
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400866 Error error = Error::NONE;
867 mMutex.lock_shared();
868 if (auto writer = getWriter(display)) {
869 writer->get().setLayerColor(translate<int64_t>(display), translate<int64_t>(layer), color);
870 } else {
871 error = Error::BAD_DISPLAY;
872 }
873 mMutex.unlock_shared();
874 return error;
Ady Abrahame7385f72021-09-05 00:54:25 -0700875}
876
Leon Scroggins III2e1aa182021-12-01 17:33:12 -0500877Error AidlComposer::setLayerCompositionType(
878 Display display, Layer layer,
879 aidl::android::hardware::graphics::composer3::Composition type) {
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400880 Error error = Error::NONE;
881 mMutex.lock_shared();
882 if (auto writer = getWriter(display)) {
883 writer->get().setLayerCompositionType(translate<int64_t>(display),
884 translate<int64_t>(layer), type);
885 } else {
886 error = Error::BAD_DISPLAY;
887 }
888 mMutex.unlock_shared();
889 return error;
Ady Abrahame7385f72021-09-05 00:54:25 -0700890}
891
892Error AidlComposer::setLayerDataspace(Display display, Layer layer, Dataspace dataspace) {
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400893 Error error = Error::NONE;
894 mMutex.lock_shared();
895 if (auto writer = getWriter(display)) {
896 writer->get().setLayerDataspace(translate<int64_t>(display), translate<int64_t>(layer),
897 translate<AidlDataspace>(dataspace));
898 } else {
899 error = Error::BAD_DISPLAY;
900 }
901 mMutex.unlock_shared();
902 return error;
Ady Abrahame7385f72021-09-05 00:54:25 -0700903}
904
905Error AidlComposer::setLayerDisplayFrame(Display display, Layer layer,
906 const IComposerClient::Rect& frame) {
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400907 Error error = Error::NONE;
908 mMutex.lock_shared();
909 if (auto writer = getWriter(display)) {
910 writer->get().setLayerDisplayFrame(translate<int64_t>(display), translate<int64_t>(layer),
911 translate<AidlRect>(frame));
912 } else {
913 error = Error::BAD_DISPLAY;
914 }
915 mMutex.unlock_shared();
916 return error;
Ady Abrahame7385f72021-09-05 00:54:25 -0700917}
918
919Error AidlComposer::setLayerPlaneAlpha(Display display, Layer layer, float alpha) {
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400920 Error error = Error::NONE;
921 mMutex.lock_shared();
922 if (auto writer = getWriter(display)) {
923 writer->get().setLayerPlaneAlpha(translate<int64_t>(display), translate<int64_t>(layer),
924 alpha);
925 } else {
926 error = Error::BAD_DISPLAY;
927 }
928 mMutex.unlock_shared();
929 return error;
Ady Abrahame7385f72021-09-05 00:54:25 -0700930}
931
932Error AidlComposer::setLayerSidebandStream(Display display, Layer layer,
933 const native_handle_t* stream) {
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400934 Error error = Error::NONE;
935 mMutex.lock_shared();
936 if (auto writer = getWriter(display)) {
937 writer->get().setLayerSidebandStream(translate<int64_t>(display), translate<int64_t>(layer),
938 stream);
939 } else {
940 error = Error::BAD_DISPLAY;
941 }
942 mMutex.unlock_shared();
943 return error;
Ady Abrahame7385f72021-09-05 00:54:25 -0700944}
945
946Error AidlComposer::setLayerSourceCrop(Display display, Layer layer,
947 const IComposerClient::FRect& crop) {
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400948 Error error = Error::NONE;
949 mMutex.lock_shared();
950 if (auto writer = getWriter(display)) {
951 writer->get().setLayerSourceCrop(translate<int64_t>(display), translate<int64_t>(layer),
952 translate<AidlFRect>(crop));
953 } else {
954 error = Error::BAD_DISPLAY;
955 }
956 mMutex.unlock_shared();
957 return error;
Ady Abrahame7385f72021-09-05 00:54:25 -0700958}
959
960Error AidlComposer::setLayerTransform(Display display, Layer layer, Transform transform) {
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400961 Error error = Error::NONE;
962 mMutex.lock_shared();
963 if (auto writer = getWriter(display)) {
964 writer->get().setLayerTransform(translate<int64_t>(display), translate<int64_t>(layer),
965 translate<AidlTransform>(transform));
966 } else {
967 error = Error::BAD_DISPLAY;
968 }
969 mMutex.unlock_shared();
970 return error;
Ady Abrahame7385f72021-09-05 00:54:25 -0700971}
972
973Error AidlComposer::setLayerVisibleRegion(Display display, Layer layer,
974 const std::vector<IComposerClient::Rect>& visible) {
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400975 Error error = Error::NONE;
976 mMutex.lock_shared();
977 if (auto writer = getWriter(display)) {
978 writer->get().setLayerVisibleRegion(translate<int64_t>(display), translate<int64_t>(layer),
979 translate<AidlRect>(visible));
980 } else {
981 error = Error::BAD_DISPLAY;
982 }
983 mMutex.unlock_shared();
984 return error;
Ady Abrahame7385f72021-09-05 00:54:25 -0700985}
986
987Error AidlComposer::setLayerZOrder(Display display, Layer layer, uint32_t z) {
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400988 Error error = Error::NONE;
989 mMutex.lock_shared();
990 if (auto writer = getWriter(display)) {
991 writer->get().setLayerZOrder(translate<int64_t>(display), translate<int64_t>(layer), z);
992 } else {
993 error = Error::BAD_DISPLAY;
994 }
995 mMutex.unlock_shared();
996 return error;
Ady Abrahame7385f72021-09-05 00:54:25 -0700997}
998
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400999Error AidlComposer::execute(Display display) {
1000 auto writer = getWriter(display);
1001 auto reader = getReader(display);
1002 if (!writer || !reader) {
1003 return Error::BAD_DISPLAY;
1004 }
1005
1006 const auto& commands = writer->get().getPendingCommands();
Ady Abrahama6388c02021-11-11 21:11:51 -08001007 if (commands.empty()) {
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -04001008 writer->get().reset();
Ady Abrahame7385f72021-09-05 00:54:25 -07001009 return Error::NONE;
1010 }
1011
Ady Abrahamde792782021-12-20 10:00:49 -08001012 { // scope for results
1013 std::vector<CommandResultPayload> results;
1014 auto status = mAidlComposerClient->executeCommands(commands, &results);
1015 if (!status.isOk()) {
1016 ALOGE("executeCommands failed %s", status.getDescription().c_str());
1017 return static_cast<Error>(status.getServiceSpecificError());
1018 }
Ady Abrahame7385f72021-09-05 00:54:25 -07001019
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -04001020 reader->get().parse(std::move(results));
Ady Abrahamde792782021-12-20 10:00:49 -08001021 }
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -04001022 const auto commandErrors = reader->get().takeErrors();
Ady Abrahama6388c02021-11-11 21:11:51 -08001023 Error error = Error::NONE;
1024 for (const auto& cmdErr : commandErrors) {
1025 const auto index = static_cast<size_t>(cmdErr.commandIndex);
1026 if (index < 0 || index >= commands.size()) {
1027 ALOGE("invalid command index %zu", index);
1028 return Error::BAD_PARAMETER;
Ady Abrahame7385f72021-09-05 00:54:25 -07001029 }
1030
Ady Abrahama6388c02021-11-11 21:11:51 -08001031 const auto& command = commands[index];
Ady Abraham42977362021-12-07 21:04:49 -08001032 if (command.validateDisplay || command.presentDisplay || command.presentOrValidateDisplay) {
1033 error = translate<Error>(cmdErr.errorCode);
1034 } else {
1035 ALOGW("command '%s' generated error %" PRId32, command.toString().c_str(),
1036 cmdErr.errorCode);
Ady Abrahame7385f72021-09-05 00:54:25 -07001037 }
1038 }
1039
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -04001040 writer->get().reset();
Ady Abrahame7385f72021-09-05 00:54:25 -07001041
1042 return error;
1043}
1044
1045Error AidlComposer::setLayerPerFrameMetadata(
1046 Display display, Layer layer,
1047 const std::vector<IComposerClient::PerFrameMetadata>& perFrameMetadatas) {
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -04001048 Error error = Error::NONE;
1049 mMutex.lock_shared();
1050 if (auto writer = getWriter(display)) {
1051 writer->get().setLayerPerFrameMetadata(translate<int64_t>(display),
1052 translate<int64_t>(layer),
1053 translate<AidlPerFrameMetadata>(perFrameMetadatas));
1054 } else {
1055 error = Error::BAD_DISPLAY;
1056 }
1057 mMutex.unlock_shared();
1058 return error;
Ady Abrahame7385f72021-09-05 00:54:25 -07001059}
1060
1061std::vector<IComposerClient::PerFrameMetadataKey> AidlComposer::getPerFrameMetadataKeys(
1062 Display display) {
1063 std::vector<AidlPerFrameMetadataKey> keys;
1064 const auto status =
1065 mAidlComposerClient->getPerFrameMetadataKeys(translate<int64_t>(display), &keys);
1066 if (!status.isOk()) {
1067 ALOGE("getPerFrameMetadataKeys failed %s", status.getDescription().c_str());
1068 return {};
1069 }
1070 return translate<IComposerClient::PerFrameMetadataKey>(keys);
1071}
1072
1073Error AidlComposer::getRenderIntents(Display display, ColorMode colorMode,
1074 std::vector<RenderIntent>* outRenderIntents) {
1075 std::vector<AidlRenderIntent> renderIntents;
1076 const auto status = mAidlComposerClient->getRenderIntents(translate<int64_t>(display),
1077 translate<AidlColorMode>(colorMode),
1078 &renderIntents);
1079 if (!status.isOk()) {
1080 ALOGE("getRenderIntents failed %s", status.getDescription().c_str());
1081 return static_cast<Error>(status.getServiceSpecificError());
1082 }
1083 *outRenderIntents = translate<RenderIntent>(renderIntents);
1084 return Error::NONE;
1085}
1086
1087Error AidlComposer::getDataspaceSaturationMatrix(Dataspace dataspace, mat4* outMatrix) {
1088 std::vector<float> matrix;
1089 const auto status =
1090 mAidlComposerClient->getDataspaceSaturationMatrix(translate<AidlDataspace>(dataspace),
1091 &matrix);
1092 if (!status.isOk()) {
1093 ALOGE("getDataspaceSaturationMatrix failed %s", status.getDescription().c_str());
1094 return static_cast<Error>(status.getServiceSpecificError());
1095 }
1096 *outMatrix = makeMat4(matrix);
1097 return Error::NONE;
1098}
1099
1100Error AidlComposer::getDisplayIdentificationData(Display display, uint8_t* outPort,
1101 std::vector<uint8_t>* outData) {
1102 AidlDisplayIdentification displayIdentification;
1103 const auto status =
1104 mAidlComposerClient->getDisplayIdentificationData(translate<int64_t>(display),
1105 &displayIdentification);
1106 if (!status.isOk()) {
1107 ALOGE("getDisplayIdentificationData failed %s", status.getDescription().c_str());
1108 return static_cast<Error>(status.getServiceSpecificError());
1109 }
1110
1111 *outPort = static_cast<uint8_t>(displayIdentification.port);
1112 *outData = displayIdentification.data;
1113
1114 return Error::NONE;
1115}
1116
1117Error AidlComposer::setLayerColorTransform(Display display, Layer layer, const float* matrix) {
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -04001118 Error error = Error::NONE;
1119 mMutex.lock_shared();
1120 if (auto writer = getWriter(display)) {
1121 writer->get().setLayerColorTransform(translate<int64_t>(display), translate<int64_t>(layer),
1122 matrix);
1123 } else {
1124 error = Error::BAD_DISPLAY;
1125 }
1126 mMutex.unlock_shared();
1127 return error;
Ady Abrahame7385f72021-09-05 00:54:25 -07001128}
1129
1130Error AidlComposer::getDisplayedContentSamplingAttributes(Display display, PixelFormat* outFormat,
1131 Dataspace* outDataspace,
1132 uint8_t* outComponentMask) {
1133 if (!outFormat || !outDataspace || !outComponentMask) {
1134 return Error::BAD_PARAMETER;
1135 }
1136
1137 AidlDisplayContentSamplingAttributes attributes;
1138 const auto status =
1139 mAidlComposerClient->getDisplayedContentSamplingAttributes(translate<int64_t>(display),
1140 &attributes);
1141 if (!status.isOk()) {
1142 ALOGE("getDisplayedContentSamplingAttributes failed %s", status.getDescription().c_str());
1143 return static_cast<Error>(status.getServiceSpecificError());
1144 }
1145
1146 *outFormat = translate<PixelFormat>(attributes.format);
1147 *outDataspace = translate<Dataspace>(attributes.dataspace);
1148 *outComponentMask = static_cast<uint8_t>(attributes.componentMask);
1149 return Error::NONE;
1150}
1151
1152Error AidlComposer::setDisplayContentSamplingEnabled(Display display, bool enabled,
1153 uint8_t componentMask, uint64_t maxFrames) {
1154 const auto status =
1155 mAidlComposerClient
1156 ->setDisplayedContentSamplingEnabled(translate<int64_t>(display), enabled,
1157 static_cast<AidlFormatColorComponent>(
1158 componentMask),
1159 static_cast<int64_t>(maxFrames));
1160 if (!status.isOk()) {
1161 ALOGE("setDisplayedContentSamplingEnabled failed %s", status.getDescription().c_str());
1162 return static_cast<Error>(status.getServiceSpecificError());
1163 }
1164 return Error::NONE;
1165}
1166
1167Error AidlComposer::getDisplayedContentSample(Display display, uint64_t maxFrames,
1168 uint64_t timestamp, DisplayedFrameStats* outStats) {
1169 if (!outStats) {
1170 return Error::BAD_PARAMETER;
1171 }
1172
1173 AidlDisplayContentSample sample;
1174 const auto status =
1175 mAidlComposerClient->getDisplayedContentSample(translate<int64_t>(display),
1176 static_cast<int64_t>(maxFrames),
1177 static_cast<int64_t>(timestamp),
1178 &sample);
1179 if (!status.isOk()) {
1180 ALOGE("getDisplayedContentSample failed %s", status.getDescription().c_str());
1181 return static_cast<Error>(status.getServiceSpecificError());
1182 }
1183 *outStats = translate<DisplayedFrameStats>(sample);
1184 return Error::NONE;
1185}
1186
1187Error AidlComposer::setLayerPerFrameMetadataBlobs(
1188 Display display, Layer layer,
1189 const std::vector<IComposerClient::PerFrameMetadataBlob>& metadata) {
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -04001190 Error error = Error::NONE;
1191 mMutex.lock_shared();
1192 if (auto writer = getWriter(display)) {
1193 writer->get().setLayerPerFrameMetadataBlobs(translate<int64_t>(display),
1194 translate<int64_t>(layer),
1195 translate<AidlPerFrameMetadataBlob>(metadata));
1196 } else {
1197 error = Error::BAD_DISPLAY;
1198 }
1199 mMutex.unlock_shared();
1200 return error;
Ady Abrahame7385f72021-09-05 00:54:25 -07001201}
1202
Alec Mouri4d8a05d2022-03-23 18:14:26 +00001203Error AidlComposer::setDisplayBrightness(Display display, float brightness, float brightnessNits,
Alec Mouricdf16792021-12-10 13:16:06 -08001204 const DisplayBrightnessOptions& options) {
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -04001205 Error error = Error::NONE;
1206 mMutex.lock_shared();
1207 if (auto writer = getWriter(display)) {
1208 writer->get().setDisplayBrightness(translate<int64_t>(display), brightness, brightnessNits);
Alec Mouricdf16792021-12-10 13:16:06 -08001209
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -04001210 if (options.applyImmediately) {
1211 error = execute(display);
1212 mMutex.unlock_shared();
1213 return error;
1214 }
1215 } else {
1216 error = Error::BAD_DISPLAY;
Alec Mouricdf16792021-12-10 13:16:06 -08001217 }
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -04001218 mMutex.unlock_shared();
1219 return error;
Ady Abrahame7385f72021-09-05 00:54:25 -07001220}
1221
1222Error AidlComposer::getDisplayCapabilities(Display display,
Leon Scroggins III5967aec2021-12-29 11:14:22 -05001223 std::vector<AidlDisplayCapability>* outCapabilities) {
1224 const auto status = mAidlComposerClient->getDisplayCapabilities(translate<int64_t>(display),
1225 outCapabilities);
Ady Abrahame7385f72021-09-05 00:54:25 -07001226 if (!status.isOk()) {
1227 ALOGE("getDisplayCapabilities failed %s", status.getDescription().c_str());
Leon Scroggins III5967aec2021-12-29 11:14:22 -05001228 outCapabilities->clear();
Ady Abrahame7385f72021-09-05 00:54:25 -07001229 return static_cast<Error>(status.getServiceSpecificError());
1230 }
Ady Abrahame7385f72021-09-05 00:54:25 -07001231 return Error::NONE;
1232}
1233
1234V2_4::Error AidlComposer::getDisplayConnectionType(
1235 Display display, IComposerClient::DisplayConnectionType* outType) {
1236 AidlDisplayConnectionType type;
1237 const auto status =
1238 mAidlComposerClient->getDisplayConnectionType(translate<int64_t>(display), &type);
1239 if (!status.isOk()) {
1240 ALOGE("getDisplayConnectionType failed %s", status.getDescription().c_str());
1241 return static_cast<V2_4::Error>(status.getServiceSpecificError());
1242 }
1243 *outType = translate<IComposerClient::DisplayConnectionType>(type);
1244 return V2_4::Error::NONE;
1245}
1246
1247V2_4::Error AidlComposer::getDisplayVsyncPeriod(Display display, VsyncPeriodNanos* outVsyncPeriod) {
1248 int32_t vsyncPeriod;
1249 const auto status =
1250 mAidlComposerClient->getDisplayVsyncPeriod(translate<int64_t>(display), &vsyncPeriod);
1251 if (!status.isOk()) {
1252 ALOGE("getDisplayVsyncPeriod failed %s", status.getDescription().c_str());
1253 return static_cast<V2_4::Error>(status.getServiceSpecificError());
1254 }
1255 *outVsyncPeriod = translate<VsyncPeriodNanos>(vsyncPeriod);
1256 return V2_4::Error::NONE;
1257}
1258
1259V2_4::Error AidlComposer::setActiveConfigWithConstraints(
1260 Display display, Config config,
1261 const IComposerClient::VsyncPeriodChangeConstraints& vsyncPeriodChangeConstraints,
1262 VsyncPeriodChangeTimeline* outTimeline) {
1263 AidlVsyncPeriodChangeTimeline timeline;
1264 const auto status =
1265 mAidlComposerClient
1266 ->setActiveConfigWithConstraints(translate<int64_t>(display),
1267 translate<int32_t>(config),
1268 translate<AidlVsyncPeriodChangeConstraints>(
1269 vsyncPeriodChangeConstraints),
1270 &timeline);
1271 if (!status.isOk()) {
1272 ALOGE("setActiveConfigWithConstraints failed %s", status.getDescription().c_str());
1273 return static_cast<V2_4::Error>(status.getServiceSpecificError());
1274 }
1275 *outTimeline = translate<VsyncPeriodChangeTimeline>(timeline);
1276 return V2_4::Error::NONE;
1277}
1278
1279V2_4::Error AidlComposer::setAutoLowLatencyMode(Display display, bool on) {
1280 const auto status = mAidlComposerClient->setAutoLowLatencyMode(translate<int64_t>(display), on);
1281 if (!status.isOk()) {
1282 ALOGE("setAutoLowLatencyMode failed %s", status.getDescription().c_str());
1283 return static_cast<V2_4::Error>(status.getServiceSpecificError());
1284 }
1285 return V2_4::Error::NONE;
1286}
1287
1288V2_4::Error AidlComposer::getSupportedContentTypes(
1289 Display displayId, std::vector<IComposerClient::ContentType>* outSupportedContentTypes) {
1290 std::vector<AidlContentType> types;
1291 const auto status =
1292 mAidlComposerClient->getSupportedContentTypes(translate<int64_t>(displayId), &types);
1293 if (!status.isOk()) {
1294 ALOGE("getSupportedContentTypes failed %s", status.getDescription().c_str());
1295 return static_cast<V2_4::Error>(status.getServiceSpecificError());
1296 }
1297 *outSupportedContentTypes = translate<IComposerClient::ContentType>(types);
1298 return V2_4::Error::NONE;
1299}
1300
1301V2_4::Error AidlComposer::setContentType(Display display,
1302 IComposerClient::ContentType contentType) {
1303 const auto status =
1304 mAidlComposerClient->setContentType(translate<int64_t>(display),
1305 translate<AidlContentType>(contentType));
1306 if (!status.isOk()) {
1307 ALOGE("setContentType failed %s", status.getDescription().c_str());
1308 return static_cast<V2_4::Error>(status.getServiceSpecificError());
1309 }
1310 return V2_4::Error::NONE;
1311}
1312
Ady Abraham3f976752021-12-20 16:17:50 -08001313V2_4::Error AidlComposer::setLayerGenericMetadata(Display, Layer, const std::string&, bool,
1314 const std::vector<uint8_t>&) {
1315 // There are no users for this API. See b/209691612.
1316 return V2_4::Error::UNSUPPORTED;
Ady Abrahame7385f72021-09-05 00:54:25 -07001317}
1318
1319V2_4::Error AidlComposer::getLayerGenericMetadataKeys(
Ady Abraham3f976752021-12-20 16:17:50 -08001320 std::vector<IComposerClient::LayerGenericMetadataKey>*) {
1321 // There are no users for this API. See b/209691612.
1322 return V2_4::Error::UNSUPPORTED;
Ady Abrahame7385f72021-09-05 00:54:25 -07001323}
1324
Kriti Dang7defaf32021-11-15 11:55:43 +01001325Error AidlComposer::setBootDisplayConfig(Display display, Config config) {
1326 const auto status = mAidlComposerClient->setBootDisplayConfig(translate<int64_t>(display),
1327 translate<int32_t>(config));
1328 if (!status.isOk()) {
1329 ALOGE("setBootDisplayConfig failed %s", status.getDescription().c_str());
1330 return static_cast<Error>(status.getServiceSpecificError());
1331 }
1332 return Error::NONE;
1333}
1334
1335Error AidlComposer::clearBootDisplayConfig(Display display) {
1336 const auto status = mAidlComposerClient->clearBootDisplayConfig(translate<int64_t>(display));
1337 if (!status.isOk()) {
1338 ALOGE("clearBootDisplayConfig failed %s", status.getDescription().c_str());
1339 return static_cast<Error>(status.getServiceSpecificError());
1340 }
1341 return Error::NONE;
1342}
1343
1344Error AidlComposer::getPreferredBootDisplayConfig(Display display, Config* config) {
1345 int32_t displayConfig;
1346 const auto status =
1347 mAidlComposerClient->getPreferredBootDisplayConfig(translate<int64_t>(display),
1348 &displayConfig);
1349 if (!status.isOk()) {
1350 ALOGE("getPreferredBootDisplayConfig failed %s", status.getDescription().c_str());
1351 return static_cast<Error>(status.getServiceSpecificError());
1352 }
1353 *config = translate<uint32_t>(displayConfig);
1354 return Error::NONE;
1355}
1356
Ady Abrahame7385f72021-09-05 00:54:25 -07001357Error AidlComposer::getClientTargetProperty(
Alec Mouri85065692022-03-18 00:58:26 +00001358 Display display, ClientTargetPropertyWithBrightness* outClientTargetProperty) {
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -04001359 Error error = Error::NONE;
1360 mMutex.lock_shared();
1361 if (auto reader = getReader(display)) {
1362 *outClientTargetProperty =
1363 reader->get().takeClientTargetProperty(translate<int64_t>(display));
1364 } else {
1365 error = Error::BAD_DISPLAY;
1366 }
1367 mMutex.unlock_shared();
1368 return error;
Ady Abrahame7385f72021-09-05 00:54:25 -07001369}
1370
Alec Mouri6da0e272022-02-07 12:45:57 -08001371Error AidlComposer::setLayerBrightness(Display display, Layer layer, float brightness) {
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -04001372 Error error = Error::NONE;
1373 mMutex.lock_shared();
1374 if (auto writer = getWriter(display)) {
1375 writer->get().setLayerBrightness(translate<int64_t>(display), translate<int64_t>(layer),
1376 brightness);
1377 } else {
1378 error = Error::BAD_DISPLAY;
1379 }
1380 mMutex.unlock_shared();
1381 return error;
Alec Mouricdf6cbc2021-11-01 17:21:15 -07001382}
1383
Leon Scroggins IIId77d3162022-01-05 10:42:28 -05001384Error AidlComposer::setLayerBlockingRegion(Display display, Layer layer,
1385 const std::vector<IComposerClient::Rect>& blocking) {
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -04001386 Error error = Error::NONE;
1387 mMutex.lock_shared();
1388 if (auto writer = getWriter(display)) {
1389 writer->get().setLayerBlockingRegion(translate<int64_t>(display), translate<int64_t>(layer),
1390 translate<AidlRect>(blocking));
1391 } else {
1392 error = Error::BAD_DISPLAY;
1393 }
1394 mMutex.unlock_shared();
1395 return error;
Leon Scroggins IIId77d3162022-01-05 10:42:28 -05001396}
Leon Scroggins IIIe7c51c62022-02-01 15:53:54 -05001397
1398Error AidlComposer::getDisplayDecorationSupport(Display display,
1399 std::optional<DisplayDecorationSupport>* support) {
1400 const auto status =
1401 mAidlComposerClient->getDisplayDecorationSupport(translate<int64_t>(display), support);
1402 if (!status.isOk()) {
1403 ALOGE("getDisplayDecorationSupport failed %s", status.getDescription().c_str());
1404 support->reset();
1405 return static_cast<Error>(status.getServiceSpecificError());
1406 }
1407 return Error::NONE;
1408}
ramindani32cf0602022-03-02 02:30:29 +00001409
1410Error AidlComposer::setIdleTimerEnabled(Display displayId, std::chrono::milliseconds timeout) {
1411 const auto status =
1412 mAidlComposerClient->setIdleTimerEnabled(translate<int64_t>(displayId),
1413 translate<int32_t>(timeout.count()));
1414 if (!status.isOk()) {
1415 ALOGE("setIdleTimerEnabled failed %s", status.getDescription().c_str());
1416 return static_cast<Error>(status.getServiceSpecificError());
1417 }
1418 return Error::NONE;
1419}
1420
ramindani06e518e2022-03-14 18:47:53 +00001421Error AidlComposer::getPhysicalDisplayOrientation(Display displayId,
1422 AidlTransform* outDisplayOrientation) {
1423 const auto status =
1424 mAidlComposerClient->getDisplayPhysicalOrientation(translate<int64_t>(displayId),
1425 outDisplayOrientation);
1426 if (!status.isOk()) {
1427 ALOGE("getPhysicalDisplayOrientation failed %s", status.getDescription().c_str());
1428 return static_cast<Error>(status.getServiceSpecificError());
1429 }
1430 return Error::NONE;
1431}
1432
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -04001433ftl::Optional<std::reference_wrapper<ComposerClientWriter>> AidlComposer::getWriter(Display display)
1434 REQUIRES_SHARED(mMutex) {
1435 return mWriters.get(display);
1436}
1437
1438ftl::Optional<std::reference_wrapper<ComposerClientReader>> AidlComposer::getReader(Display display)
1439 REQUIRES_SHARED(mMutex) {
1440 if (mSingleReader) {
1441 display = translate<Display>(kSingleReaderKey);
1442 }
1443 return mReaders.get(display);
1444}
1445
1446void AidlComposer::removeDisplay(Display display) {
1447 mMutex.lock();
1448 bool wasErased = mWriters.erase(display);
1449 ALOGW_IF(!wasErased,
1450 "Attempting to remove writer for display %" PRId64 " which is not connected",
1451 translate<int64_t>(display));
1452 if (!mSingleReader) {
1453 removeReader(display);
1454 }
1455 mMutex.unlock();
1456}
1457
1458void AidlComposer::onHotplugDisconnect(Display display) {
1459 removeDisplay(display);
1460}
1461
1462bool AidlComposer::hasMultiThreadedPresentSupport(Display display) {
1463 const auto displayId = translate<int64_t>(display);
1464 std::vector<AidlDisplayCapability> capabilities;
1465 const auto status = mAidlComposerClient->getDisplayCapabilities(displayId, &capabilities);
1466 if (!status.isOk()) {
1467 ALOGE("getDisplayCapabilities failed %s", status.getDescription().c_str());
1468 return false;
1469 }
1470 return std::find(capabilities.begin(), capabilities.end(),
1471 AidlDisplayCapability::MULTI_THREADED_PRESENT) != capabilities.end();
1472}
1473
1474void AidlComposer::addReader(Display display) {
1475 const auto displayId = translate<int64_t>(display);
1476 std::optional<int64_t> displayOpt;
1477 if (displayId != kSingleReaderKey) {
1478 displayOpt.emplace(displayId);
1479 }
1480 auto [it, added] = mReaders.try_emplace(display, std::move(displayOpt));
1481 ALOGW_IF(!added, "Attempting to add writer for display %" PRId64 " which is already connected",
1482 displayId);
1483}
1484
1485void AidlComposer::removeReader(Display display) {
1486 bool wasErased = mReaders.erase(display);
1487 ALOGW_IF(!wasErased,
1488 "Attempting to remove reader for display %" PRId64 " which is not connected",
1489 translate<int64_t>(display));
1490}
1491
1492void AidlComposer::addDisplay(Display display) {
1493 const auto displayId = translate<int64_t>(display);
1494 mMutex.lock();
1495 auto [it, added] = mWriters.try_emplace(display, displayId);
1496 ALOGW_IF(!added, "Attempting to add writer for display %" PRId64 " which is already connected",
1497 displayId);
1498 if (mSingleReader) {
1499 if (hasMultiThreadedPresentSupport(display)) {
1500 mSingleReader = false;
1501 removeReader(translate<Display>(kSingleReaderKey));
1502 // Note that this includes the new display.
1503 for (const auto& [existingDisplay, _] : mWriters) {
1504 addReader(existingDisplay);
1505 }
1506 }
1507 } else {
1508 addReader(display);
1509 }
1510 mMutex.unlock();
1511}
1512
1513void AidlComposer::onHotplugConnect(Display display) {
1514 addDisplay(display);
1515}
Ady Abrahame7385f72021-09-05 00:54:25 -07001516} // namespace Hwc2
1517} // namespace android