blob: 2a6443a98ae66da43c8813f4c3131649f5bd8688 [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
Brian Lindahl5b0ffe02023-06-15 14:19:43 -060023#include <SurfaceFlingerProperties.h>
Ady Abrahamc4acf512022-02-18 17:11:59 -080024#include <android-base/file.h>
Ady Abrahame7385f72021-09-05 00:54:25 -070025#include <android/binder_ibinder_platform.h>
26#include <android/binder_manager.h>
Leon Scroggins IIIe85e16e2022-12-12 12:51:18 -050027#include <gui/TraceUtils.h>
Ady Abrahame7385f72021-09-05 00:54:25 -070028#include <log/log.h>
29#include <utils/Trace.h>
30
31#include <aidl/android/hardware/graphics/composer3/BnComposerCallback.h>
32
33#include <algorithm>
34#include <cinttypes>
35
Yichi Chen3401b562022-01-17 15:42:35 +080036#include "HWC2.h"
37
Ady Abrahame7385f72021-09-05 00:54:25 -070038namespace android {
39
40using hardware::hidl_handle;
41using hardware::hidl_vec;
42using hardware::Return;
43
44using aidl::android::hardware::graphics::composer3::BnComposerCallback;
45using aidl::android::hardware::graphics::composer3::Capability;
Alec Mouri85065692022-03-18 00:58:26 +000046using aidl::android::hardware::graphics::composer3::ClientTargetPropertyWithBrightness;
Ady Abrahame7385f72021-09-05 00:54:25 -070047using aidl::android::hardware::graphics::composer3::PowerMode;
48using aidl::android::hardware::graphics::composer3::VirtualDisplay;
49
Ady Abraham42977362021-12-07 21:04:49 -080050using aidl::android::hardware::graphics::composer3::CommandResultPayload;
Ady Abrahama6388c02021-11-11 21:11:51 -080051
Ady Abrahame7385f72021-09-05 00:54:25 -070052using AidlColorMode = aidl::android::hardware::graphics::composer3::ColorMode;
53using AidlContentType = aidl::android::hardware::graphics::composer3::ContentType;
54using AidlDisplayIdentification =
55 aidl::android::hardware::graphics::composer3::DisplayIdentification;
56using AidlDisplayContentSample = aidl::android::hardware::graphics::composer3::DisplayContentSample;
57using AidlDisplayAttribute = aidl::android::hardware::graphics::composer3::DisplayAttribute;
58using AidlDisplayCapability = aidl::android::hardware::graphics::composer3::DisplayCapability;
Ady Abrahame7385f72021-09-05 00:54:25 -070059using AidlHdrCapabilities = aidl::android::hardware::graphics::composer3::HdrCapabilities;
Kriti Dang674b9372022-11-18 10:58:44 +010060using AidlHdrConversionCapability =
61 aidl::android::hardware::graphics::common::HdrConversionCapability;
62using AidlHdrConversionStrategy = aidl::android::hardware::graphics::common::HdrConversionStrategy;
Sally Qi0cbd08b2022-08-17 12:12:28 -070063using AidlOverlayProperties = aidl::android::hardware::graphics::composer3::OverlayProperties;
Ady Abrahame7385f72021-09-05 00:54:25 -070064using AidlPerFrameMetadata = aidl::android::hardware::graphics::composer3::PerFrameMetadata;
65using AidlPerFrameMetadataKey = aidl::android::hardware::graphics::composer3::PerFrameMetadataKey;
66using AidlPerFrameMetadataBlob = aidl::android::hardware::graphics::composer3::PerFrameMetadataBlob;
67using AidlRenderIntent = aidl::android::hardware::graphics::composer3::RenderIntent;
68using AidlVsyncPeriodChangeConstraints =
69 aidl::android::hardware::graphics::composer3::VsyncPeriodChangeConstraints;
70using AidlVsyncPeriodChangeTimeline =
71 aidl::android::hardware::graphics::composer3::VsyncPeriodChangeTimeline;
Ady Abrahame7385f72021-09-05 00:54:25 -070072using AidlDisplayContentSamplingAttributes =
73 aidl::android::hardware::graphics::composer3::DisplayContentSamplingAttributes;
74using AidlFormatColorComponent = aidl::android::hardware::graphics::composer3::FormatColorComponent;
75using AidlDisplayConnectionType =
76 aidl::android::hardware::graphics::composer3::DisplayConnectionType;
Ady Abrahame7385f72021-09-05 00:54:25 -070077
78using AidlColorTransform = aidl::android::hardware::graphics::common::ColorTransform;
79using AidlDataspace = aidl::android::hardware::graphics::common::Dataspace;
80using AidlFRect = aidl::android::hardware::graphics::common::FRect;
81using AidlRect = aidl::android::hardware::graphics::common::Rect;
82using AidlTransform = aidl::android::hardware::graphics::common::Transform;
83
84namespace Hwc2 {
85
86namespace {
87
88template <typename To, typename From>
89To translate(From x) {
90 return static_cast<To>(x);
91}
92
93template <typename To, typename From>
94std::vector<To> translate(const std::vector<From>& in) {
95 std::vector<To> out;
96 out.reserve(in.size());
97 std::transform(in.begin(), in.end(), std::back_inserter(out),
98 [](From x) { return translate<To>(x); });
99 return out;
100}
101
102template <>
103AidlRect translate(IComposerClient::Rect x) {
104 return AidlRect{
105 .left = x.left,
106 .top = x.top,
107 .right = x.right,
108 .bottom = x.bottom,
109 };
110}
111
112template <>
113AidlFRect translate(IComposerClient::FRect x) {
114 return AidlFRect{
115 .left = x.left,
116 .top = x.top,
117 .right = x.right,
118 .bottom = x.bottom,
119 };
120}
121
122template <>
Ady Abrahame7385f72021-09-05 00:54:25 -0700123AidlPerFrameMetadataBlob translate(IComposerClient::PerFrameMetadataBlob x) {
124 AidlPerFrameMetadataBlob blob;
125 blob.key = translate<AidlPerFrameMetadataKey>(x.key),
Long Linga4628782022-02-18 13:44:26 -0800126 std::copy(x.blob.begin(), x.blob.end(), std::inserter(blob.blob, blob.blob.end()));
Ady Abrahame7385f72021-09-05 00:54:25 -0700127 return blob;
128}
129
130template <>
131AidlPerFrameMetadata translate(IComposerClient::PerFrameMetadata x) {
132 return AidlPerFrameMetadata{
133 .key = translate<AidlPerFrameMetadataKey>(x.key),
134 .value = x.value,
135 };
136}
137
138template <>
139DisplayedFrameStats translate(AidlDisplayContentSample x) {
140 return DisplayedFrameStats{
141 .numFrames = static_cast<uint64_t>(x.frameCount),
142 .component_0_sample = translate<uint64_t>(x.sampleComponent0),
143 .component_1_sample = translate<uint64_t>(x.sampleComponent1),
144 .component_2_sample = translate<uint64_t>(x.sampleComponent2),
145 .component_3_sample = translate<uint64_t>(x.sampleComponent3),
146 };
147}
148
149template <>
150AidlVsyncPeriodChangeConstraints translate(IComposerClient::VsyncPeriodChangeConstraints x) {
151 return AidlVsyncPeriodChangeConstraints{
152 .desiredTimeNanos = x.desiredTimeNanos,
153 .seamlessRequired = x.seamlessRequired,
154 };
155}
156
157template <>
158VsyncPeriodChangeTimeline translate(AidlVsyncPeriodChangeTimeline x) {
159 return VsyncPeriodChangeTimeline{
160 .newVsyncAppliedTimeNanos = x.newVsyncAppliedTimeNanos,
161 .refreshRequired = x.refreshRequired,
162 .refreshTimeNanos = x.refreshTimeNanos,
163 };
164}
Ady Abrahame7385f72021-09-05 00:54:25 -0700165mat4 makeMat4(std::vector<float> in) {
166 return mat4(static_cast<const float*>(in.data()));
167}
168
169} // namespace
170
171class AidlIComposerCallbackWrapper : public BnComposerCallback {
172public:
Yichi Chen3401b562022-01-17 15:42:35 +0800173 AidlIComposerCallbackWrapper(HWC2::ComposerCallback& callback) : mCallback(callback) {}
Ady Abrahame7385f72021-09-05 00:54:25 -0700174
175 ::ndk::ScopedAStatus onHotplug(int64_t in_display, bool in_connected) override {
176 const auto connection = in_connected ? V2_4::IComposerCallback::Connection::CONNECTED
177 : V2_4::IComposerCallback::Connection::DISCONNECTED;
Yichi Chen3401b562022-01-17 15:42:35 +0800178 mCallback.onComposerHalHotplug(translate<Display>(in_display), connection);
Ady Abrahame7385f72021-09-05 00:54:25 -0700179 return ::ndk::ScopedAStatus::ok();
180 }
181
182 ::ndk::ScopedAStatus onRefresh(int64_t in_display) override {
Yichi Chen3401b562022-01-17 15:42:35 +0800183 mCallback.onComposerHalRefresh(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 onSeamlessPossible(int64_t in_display) override {
Yichi Chen3401b562022-01-17 15:42:35 +0800188 mCallback.onComposerHalSeamlessPossible(translate<Display>(in_display));
Ady Abrahame7385f72021-09-05 00:54:25 -0700189 return ::ndk::ScopedAStatus::ok();
190 }
Yichi Chen3401b562022-01-17 15:42:35 +0800191
Ady Abrahame7385f72021-09-05 00:54:25 -0700192 ::ndk::ScopedAStatus onVsync(int64_t in_display, int64_t in_timestamp,
193 int32_t in_vsyncPeriodNanos) override {
Yichi Chen3401b562022-01-17 15:42:35 +0800194 mCallback.onComposerHalVsync(translate<Display>(in_display), in_timestamp,
195 static_cast<uint32_t>(in_vsyncPeriodNanos));
Ady Abrahame7385f72021-09-05 00:54:25 -0700196 return ::ndk::ScopedAStatus::ok();
197 }
Yichi Chen3401b562022-01-17 15:42:35 +0800198
Ady Abrahame7385f72021-09-05 00:54:25 -0700199 ::ndk::ScopedAStatus onVsyncPeriodTimingChanged(
200 int64_t in_display, const AidlVsyncPeriodChangeTimeline& in_updatedTimeline) override {
Yichi Chen3401b562022-01-17 15:42:35 +0800201 mCallback.onComposerHalVsyncPeriodTimingChanged(translate<Display>(in_display),
202 translate<V2_4::VsyncPeriodChangeTimeline>(
203 in_updatedTimeline));
204 return ::ndk::ScopedAStatus::ok();
205 }
206
207 ::ndk::ScopedAStatus onVsyncIdle(int64_t in_display) override {
208 mCallback.onComposerHalVsyncIdle(translate<Display>(in_display));
Ady Abrahame7385f72021-09-05 00:54:25 -0700209 return ::ndk::ScopedAStatus::ok();
210 }
211
ramindani12bfe6b2023-02-03 13:29:19 -0800212 ::ndk::ScopedAStatus onRefreshRateChangedDebug(
213 const RefreshRateChangedDebugData& refreshRateChangedDebugData) override {
214 mCallback.onRefreshRateChangedDebug(refreshRateChangedDebugData);
215 return ::ndk::ScopedAStatus::ok();
216 }
217
Ady Abrahame7385f72021-09-05 00:54:25 -0700218private:
Yichi Chen3401b562022-01-17 15:42:35 +0800219 HWC2::ComposerCallback& mCallback;
Ady Abrahame7385f72021-09-05 00:54:25 -0700220};
221
Ady Abraham9fc28052021-10-14 17:21:38 -0700222std::string AidlComposer::instance(const std::string& serviceName) {
223 return std::string(AidlIComposer::descriptor) + "/" + serviceName;
224}
225
226bool AidlComposer::isDeclared(const std::string& serviceName) {
227 return AServiceManager_isDeclared(instance(serviceName).c_str());
228}
Ady Abrahame7385f72021-09-05 00:54:25 -0700229
Ady Abrahama6388c02021-11-11 21:11:51 -0800230AidlComposer::AidlComposer(const std::string& serviceName) {
Ady Abrahame7385f72021-09-05 00:54:25 -0700231 // This only waits if the service is actually declared
Ady Abraham9fc28052021-10-14 17:21:38 -0700232 mAidlComposer = AidlIComposer::fromBinder(
233 ndk::SpAIBinder(AServiceManager_waitForService(instance(serviceName).c_str())));
Ady Abrahame7385f72021-09-05 00:54:25 -0700234 if (!mAidlComposer) {
235 LOG_ALWAYS_FATAL("Failed to get AIDL composer service");
236 return;
237 }
238
239 if (!mAidlComposer->createClient(&mAidlComposerClient).isOk()) {
240 LOG_ALWAYS_FATAL("Can't create AidlComposerClient, fallback to HIDL");
241 return;
242 }
243
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400244 addReader(translate<Display>(kSingleReaderKey));
245
Brian Lindahldbf7e3a2022-12-16 11:43:39 -0700246 // If unable to read interface version, then become backwards compatible.
ramindani0cd1d8d2023-06-13 13:43:23 -0700247 const auto status = mAidlComposerClient->getInterfaceVersion(&mComposerInterfaceVersion);
Brian Lindahldbf7e3a2022-12-16 11:43:39 -0700248 if (!status.isOk()) {
249 ALOGE("getInterfaceVersion for AidlComposer constructor failed %s",
250 status.getDescription().c_str());
251 }
ramindani0cd1d8d2023-06-13 13:43:23 -0700252
253 if (mComposerInterfaceVersion <= 1) {
Brian Lindahl5b0ffe02023-06-15 14:19:43 -0600254 if (sysprop::clear_slots_with_set_layer_buffer(false)) {
255 mClearSlotBuffer = sp<GraphicBuffer>::make(1, 1, PIXEL_FORMAT_RGBX_8888,
256 GraphicBuffer::USAGE_HW_COMPOSER |
257 GraphicBuffer::USAGE_SW_READ_OFTEN |
258 GraphicBuffer::USAGE_SW_WRITE_OFTEN,
259 "AidlComposer");
260 if (!mClearSlotBuffer || mClearSlotBuffer->initCheck() != ::android::OK) {
261 LOG_ALWAYS_FATAL("Failed to allocate a buffer for clearing layer buffer slots");
262 return;
263 }
Brian Lindahldbf7e3a2022-12-16 11:43:39 -0700264 }
Brian Lindahl90553da2022-12-06 13:36:30 -0700265 }
266
Ady Abrahame7385f72021-09-05 00:54:25 -0700267 ALOGI("Loaded AIDL composer3 HAL service");
268}
269
270AidlComposer::~AidlComposer() = default;
271
Ady Abraham4d211cf2021-12-14 16:19:03 -0800272bool AidlComposer::isSupported(OptionalFeature feature) const {
273 switch (feature) {
274 case OptionalFeature::RefreshRateSwitching:
Ady Abraham43065bd2021-12-10 17:22:15 -0800275 case OptionalFeature::ExpectedPresentTime:
Alec Mouricdf16792021-12-10 13:16:06 -0800276 case OptionalFeature::DisplayBrightnessCommand:
ramindani32cf0602022-03-02 02:30:29 +0000277 case OptionalFeature::KernelIdleTimer:
ramindani06e518e2022-03-14 18:47:53 +0000278 case OptionalFeature::PhysicalDisplayOrientation:
Ady Abraham4d211cf2021-12-14 16:19:03 -0800279 return true;
280 }
281}
282
ramindani0cd1d8d2023-06-13 13:43:23 -0700283bool AidlComposer::getDisplayConfigurationsSupported() const {
284 return mComposerInterfaceVersion >= 3;
285}
286
Ady Abrahamde549d42022-01-26 19:19:17 -0800287std::vector<Capability> AidlComposer::getCapabilities() {
Ady Abrahame7385f72021-09-05 00:54:25 -0700288 std::vector<Capability> capabilities;
289 const auto status = mAidlComposer->getCapabilities(&capabilities);
290 if (!status.isOk()) {
291 ALOGE("getCapabilities failed %s", status.getDescription().c_str());
292 return {};
293 }
Ady Abrahamde549d42022-01-26 19:19:17 -0800294 return capabilities;
Ady Abrahame7385f72021-09-05 00:54:25 -0700295}
296
297std::string AidlComposer::dumpDebugInfo() {
Ady Abrahamc4acf512022-02-18 17:11:59 -0800298 int pipefds[2];
299 int result = pipe(pipefds);
300 if (result < 0) {
301 ALOGE("dumpDebugInfo: pipe failed: %s", strerror(errno));
Ady Abrahame7385f72021-09-05 00:54:25 -0700302 return {};
303 }
Ady Abrahamc4acf512022-02-18 17:11:59 -0800304
305 std::string str;
yihsing.shen58847c52022-09-23 15:39:30 +0800306 // Use other thread to read pipe to prevent
307 // pipe is full, making HWC be blocked in writing.
308 std::thread t([&]() {
309 base::ReadFdToString(pipefds[0], &str);
310 });
Ady Abrahamc4acf512022-02-18 17:11:59 -0800311 const auto status = mAidlComposer->dump(pipefds[1], /*args*/ nullptr, /*numArgs*/ 0);
312 // Close the write-end of the pipe to make sure that when reading from the
313 // read-end we will get eof instead of blocking forever
314 close(pipefds[1]);
315
yihsing.shen58847c52022-09-23 15:39:30 +0800316 if (status != STATUS_OK) {
Ady Abrahamc4acf512022-02-18 17:11:59 -0800317 ALOGE("dumpDebugInfo: dump failed: %d", status);
318 }
319
yihsing.shen58847c52022-09-23 15:39:30 +0800320 t.join();
Ady Abrahamc4acf512022-02-18 17:11:59 -0800321 close(pipefds[0]);
322 return str;
Ady Abrahame7385f72021-09-05 00:54:25 -0700323}
324
Yichi Chen3401b562022-01-17 15:42:35 +0800325void AidlComposer::registerCallback(HWC2::ComposerCallback& callback) {
Ady Abrahame7385f72021-09-05 00:54:25 -0700326 if (mAidlComposerCallback) {
327 ALOGE("Callback already registered");
328 }
Yichi Chen3401b562022-01-17 15:42:35 +0800329
Ady Abraham9fc28052021-10-14 17:21:38 -0700330 mAidlComposerCallback = ndk::SharedRefBase::make<AidlIComposerCallbackWrapper>(callback);
Ady Abrahame7385f72021-09-05 00:54:25 -0700331 AIBinder_setMinSchedulerPolicy(mAidlComposerCallback->asBinder().get(), SCHED_FIFO, 2);
332
333 const auto status = mAidlComposerClient->registerCallback(mAidlComposerCallback);
334 if (!status.isOk()) {
335 ALOGE("registerCallback failed %s", status.getDescription().c_str());
336 }
337}
338
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400339Error AidlComposer::executeCommands(Display display) {
340 mMutex.lock_shared();
341 auto error = execute(display);
342 mMutex.unlock_shared();
343 return error;
Ady Abrahame7385f72021-09-05 00:54:25 -0700344}
345
346uint32_t AidlComposer::getMaxVirtualDisplayCount() {
347 int32_t count = 0;
348 const auto status = mAidlComposerClient->getMaxVirtualDisplayCount(&count);
349 if (!status.isOk()) {
350 ALOGE("getMaxVirtualDisplayCount failed %s", status.getDescription().c_str());
351 return 0;
352 }
353 return static_cast<uint32_t>(count);
354}
355
356Error AidlComposer::createVirtualDisplay(uint32_t width, uint32_t height, PixelFormat* format,
357 Display* outDisplay) {
358 using AidlPixelFormat = aidl::android::hardware::graphics::common::PixelFormat;
359 const int32_t bufferSlotCount = 1;
360 VirtualDisplay virtualDisplay;
361 const auto status =
362 mAidlComposerClient->createVirtualDisplay(static_cast<int32_t>(width),
363 static_cast<int32_t>(height),
364 static_cast<AidlPixelFormat>(*format),
365 bufferSlotCount, &virtualDisplay);
366
367 if (!status.isOk()) {
368 ALOGE("createVirtualDisplay failed %s", status.getDescription().c_str());
369 return static_cast<Error>(status.getServiceSpecificError());
370 }
371
372 *outDisplay = translate<Display>(virtualDisplay.display);
373 *format = static_cast<PixelFormat>(virtualDisplay.format);
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400374 addDisplay(translate<Display>(virtualDisplay.display));
Ady Abrahame7385f72021-09-05 00:54:25 -0700375 return Error::NONE;
376}
377
378Error AidlComposer::destroyVirtualDisplay(Display display) {
379 const auto status = mAidlComposerClient->destroyVirtualDisplay(translate<int64_t>(display));
380 if (!status.isOk()) {
381 ALOGE("destroyVirtualDisplay failed %s", status.getDescription().c_str());
382 return static_cast<Error>(status.getServiceSpecificError());
383 }
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400384 removeDisplay(display);
Ady Abrahame7385f72021-09-05 00:54:25 -0700385 return Error::NONE;
386}
387
388Error AidlComposer::acceptDisplayChanges(Display display) {
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400389 Error error = Error::NONE;
390 mMutex.lock_shared();
391 if (auto writer = getWriter(display)) {
392 writer->get().acceptDisplayChanges(translate<int64_t>(display));
393 } else {
394 error = Error::BAD_DISPLAY;
395 }
396 mMutex.unlock_shared();
397 return error;
Ady Abrahame7385f72021-09-05 00:54:25 -0700398}
399
400Error AidlComposer::createLayer(Display display, Layer* outLayer) {
401 int64_t layer;
402 const auto status = mAidlComposerClient->createLayer(translate<int64_t>(display),
403 kMaxLayerBufferCount, &layer);
404 if (!status.isOk()) {
405 ALOGE("createLayer failed %s", status.getDescription().c_str());
406 return static_cast<Error>(status.getServiceSpecificError());
407 }
408
409 *outLayer = translate<Layer>(layer);
410 return Error::NONE;
411}
412
413Error AidlComposer::destroyLayer(Display display, Layer layer) {
414 const auto status = mAidlComposerClient->destroyLayer(translate<int64_t>(display),
415 translate<int64_t>(layer));
416 if (!status.isOk()) {
417 ALOGE("destroyLayer failed %s", status.getDescription().c_str());
418 return static_cast<Error>(status.getServiceSpecificError());
419 }
420 return Error::NONE;
421}
422
423Error AidlComposer::getActiveConfig(Display display, Config* outConfig) {
424 int32_t config;
425 const auto status = mAidlComposerClient->getActiveConfig(translate<int64_t>(display), &config);
426 if (!status.isOk()) {
427 ALOGE("getActiveConfig failed %s", status.getDescription().c_str());
428 return static_cast<Error>(status.getServiceSpecificError());
429 }
430 *outConfig = translate<Config>(config);
431 return Error::NONE;
432}
433
434Error AidlComposer::getChangedCompositionTypes(
435 Display display, std::vector<Layer>* outLayers,
Leon Scroggins III2e1aa182021-12-01 17:33:12 -0500436 std::vector<aidl::android::hardware::graphics::composer3::Composition>* outTypes) {
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400437 std::vector<ChangedCompositionLayer> changedLayers;
438 Error error = Error::NONE;
439 {
440 mMutex.lock_shared();
441 if (auto reader = getReader(display)) {
442 changedLayers = reader->get().takeChangedCompositionTypes(translate<int64_t>(display));
443 } else {
444 error = Error::BAD_DISPLAY;
445 }
446 mMutex.unlock_shared();
447 }
Ady Abrahamde792782021-12-20 10:00:49 -0800448 outLayers->reserve(changedLayers.size());
449 outTypes->reserve(changedLayers.size());
Ady Abrahama6388c02021-11-11 21:11:51 -0800450
Ady Abrahamde792782021-12-20 10:00:49 -0800451 for (const auto& layer : changedLayers) {
452 outLayers->emplace_back(translate<Layer>(layer.layer));
453 outTypes->emplace_back(layer.composition);
454 }
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400455 return error;
Ady Abrahame7385f72021-09-05 00:54:25 -0700456}
457
458Error AidlComposer::getColorModes(Display display, std::vector<ColorMode>* outModes) {
459 std::vector<AidlColorMode> modes;
460 const auto status = mAidlComposerClient->getColorModes(translate<int64_t>(display), &modes);
461 if (!status.isOk()) {
462 ALOGE("getColorModes failed %s", status.getDescription().c_str());
463 return static_cast<Error>(status.getServiceSpecificError());
464 }
465 *outModes = translate<ColorMode>(modes);
466 return Error::NONE;
467}
468
469Error AidlComposer::getDisplayAttribute(Display display, Config config,
470 IComposerClient::Attribute attribute, int32_t* outValue) {
471 const auto status =
472 mAidlComposerClient->getDisplayAttribute(translate<int64_t>(display),
473 translate<int32_t>(config),
474 static_cast<AidlDisplayAttribute>(attribute),
475 outValue);
476 if (!status.isOk()) {
477 ALOGE("getDisplayAttribute failed %s", status.getDescription().c_str());
478 return static_cast<Error>(status.getServiceSpecificError());
479 }
480 return Error::NONE;
481}
482
483Error AidlComposer::getDisplayConfigs(Display display, std::vector<Config>* outConfigs) {
484 std::vector<int32_t> configs;
485 const auto status =
486 mAidlComposerClient->getDisplayConfigs(translate<int64_t>(display), &configs);
487 if (!status.isOk()) {
488 ALOGE("getDisplayConfigs failed %s", status.getDescription().c_str());
489 return static_cast<Error>(status.getServiceSpecificError());
490 }
491 *outConfigs = translate<Config>(configs);
492 return Error::NONE;
493}
494
ramindani263a3f12023-07-18 20:44:49 -0700495Error AidlComposer::getDisplayConfigurations(Display display, int32_t maxFrameIntervalNs,
ramindani0cd1d8d2023-06-13 13:43:23 -0700496 std::vector<DisplayConfiguration>* outConfigs) {
497 const auto status =
ramindani263a3f12023-07-18 20:44:49 -0700498 mAidlComposerClient->getDisplayConfigurations(translate<int64_t>(display),
499 maxFrameIntervalNs, outConfigs);
ramindani0cd1d8d2023-06-13 13:43:23 -0700500 if (!status.isOk()) {
501 ALOGE("getDisplayConfigurations failed %s", status.getDescription().c_str());
502 return static_cast<Error>(status.getServiceSpecificError());
503 }
504
505 return Error::NONE;
506}
507
Ady Abrahame7385f72021-09-05 00:54:25 -0700508Error AidlComposer::getDisplayName(Display display, std::string* outName) {
509 const auto status = mAidlComposerClient->getDisplayName(translate<int64_t>(display), outName);
510 if (!status.isOk()) {
511 ALOGE("getDisplayName failed %s", status.getDescription().c_str());
512 return static_cast<Error>(status.getServiceSpecificError());
513 }
514 return Error::NONE;
515}
516
517Error AidlComposer::getDisplayRequests(Display display, uint32_t* outDisplayRequestMask,
518 std::vector<Layer>* outLayers,
519 std::vector<uint32_t>* outLayerRequestMasks) {
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400520 Error error = Error::NONE;
521 DisplayRequest displayRequests;
522 {
523 mMutex.lock_shared();
524 if (auto reader = getReader(display)) {
525 displayRequests = reader->get().takeDisplayRequests(translate<int64_t>(display));
526 } else {
527 error = Error::BAD_DISPLAY;
528 }
529 mMutex.unlock_shared();
530 }
Ady Abrahamde792782021-12-20 10:00:49 -0800531 *outDisplayRequestMask = translate<uint32_t>(displayRequests.mask);
532 outLayers->reserve(displayRequests.layerRequests.size());
533 outLayerRequestMasks->reserve(displayRequests.layerRequests.size());
534
535 for (const auto& layer : displayRequests.layerRequests) {
536 outLayers->emplace_back(translate<Layer>(layer.layer));
537 outLayerRequestMasks->emplace_back(translate<uint32_t>(layer.mask));
538 }
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400539 return error;
Ady Abrahame7385f72021-09-05 00:54:25 -0700540}
541
542Error AidlComposer::getDozeSupport(Display display, bool* outSupport) {
Ady Abraham33b92b92021-12-08 18:30:27 -0800543 std::vector<AidlDisplayCapability> capabilities;
Ady Abrahame7385f72021-09-05 00:54:25 -0700544 const auto status =
Ady Abraham33b92b92021-12-08 18:30:27 -0800545 mAidlComposerClient->getDisplayCapabilities(translate<int64_t>(display), &capabilities);
Ady Abrahame7385f72021-09-05 00:54:25 -0700546 if (!status.isOk()) {
Ady Abraham33b92b92021-12-08 18:30:27 -0800547 ALOGE("getDisplayCapabilities failed %s", status.getDescription().c_str());
Ady Abrahame7385f72021-09-05 00:54:25 -0700548 return static_cast<Error>(status.getServiceSpecificError());
549 }
Ady Abraham33b92b92021-12-08 18:30:27 -0800550 *outSupport = std::find(capabilities.begin(), capabilities.end(),
551 AidlDisplayCapability::DOZE) != capabilities.end();
Ady Abrahame7385f72021-09-05 00:54:25 -0700552 return Error::NONE;
553}
554
ramindani32cf0602022-03-02 02:30:29 +0000555Error AidlComposer::hasDisplayIdleTimerCapability(Display display, bool* outSupport) {
556 std::vector<AidlDisplayCapability> capabilities;
557 const auto status =
558 mAidlComposerClient->getDisplayCapabilities(translate<int64_t>(display), &capabilities);
559 if (!status.isOk()) {
560 ALOGE("getDisplayCapabilities failed %s", status.getDescription().c_str());
561 return static_cast<Error>(status.getServiceSpecificError());
562 }
563 *outSupport = std::find(capabilities.begin(), capabilities.end(),
564 AidlDisplayCapability::DISPLAY_IDLE_TIMER) != capabilities.end();
565 return Error::NONE;
566}
567
Ady Abrahame7385f72021-09-05 00:54:25 -0700568Error AidlComposer::getHdrCapabilities(Display display, std::vector<Hdr>* outTypes,
569 float* outMaxLuminance, float* outMaxAverageLuminance,
570 float* outMinLuminance) {
571 AidlHdrCapabilities capabilities;
572 const auto status =
573 mAidlComposerClient->getHdrCapabilities(translate<int64_t>(display), &capabilities);
574 if (!status.isOk()) {
575 ALOGE("getHdrCapabilities failed %s", status.getDescription().c_str());
576 return static_cast<Error>(status.getServiceSpecificError());
577 }
578
Marc Kassisbdf7e4b2022-11-04 17:26:48 +0100579 *outTypes = capabilities.types;
Ady Abrahame7385f72021-09-05 00:54:25 -0700580 *outMaxLuminance = capabilities.maxLuminance;
581 *outMaxAverageLuminance = capabilities.maxAverageLuminance;
582 *outMinLuminance = capabilities.minLuminance;
583 return Error::NONE;
584}
585
Sally Qibb866c12022-10-17 11:31:20 -0700586Error AidlComposer::getOverlaySupport(AidlOverlayProperties* outProperties) {
587 const auto status = mAidlComposerClient->getOverlaySupport(outProperties);
588 if (!status.isOk()) {
589 ALOGE("getOverlaySupport failed %s", status.getDescription().c_str());
590 return static_cast<Error>(status.getServiceSpecificError());
591 }
Sally Qi0cbd08b2022-08-17 12:12:28 -0700592 return Error::NONE;
593}
594
Ady Abrahame7385f72021-09-05 00:54:25 -0700595Error AidlComposer::getReleaseFences(Display display, std::vector<Layer>* outLayers,
596 std::vector<int>* outReleaseFences) {
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400597 Error error = Error::NONE;
598 std::vector<ReleaseFences::Layer> fences;
599 {
600 mMutex.lock_shared();
601 if (auto reader = getReader(display)) {
602 fences = reader->get().takeReleaseFences(translate<int64_t>(display));
603 } else {
604 error = Error::BAD_DISPLAY;
605 }
606 mMutex.unlock_shared();
607 }
Ady Abrahamde792782021-12-20 10:00:49 -0800608 outLayers->reserve(fences.size());
609 outReleaseFences->reserve(fences.size());
610
611 for (auto& fence : fences) {
612 outLayers->emplace_back(translate<Layer>(fence.layer));
613 // take ownership
614 const int fenceOwner = fence.fence.get();
615 *fence.fence.getR() = -1;
616 outReleaseFences->emplace_back(fenceOwner);
617 }
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400618 return error;
Ady Abrahame7385f72021-09-05 00:54:25 -0700619}
620
621Error AidlComposer::presentDisplay(Display display, int* outPresentFence) {
Leon Scroggins IIIe85e16e2022-12-12 12:51:18 -0500622 const auto displayId = translate<int64_t>(display);
623 ATRACE_FORMAT("HwcPresentDisplay %" PRId64, displayId);
624
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400625 Error error = Error::NONE;
626 mMutex.lock_shared();
627 auto writer = getWriter(display);
628 auto reader = getReader(display);
629 if (writer && reader) {
Leon Scroggins IIIe85e16e2022-12-12 12:51:18 -0500630 writer->get().presentDisplay(displayId);
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400631 error = execute(display);
632 } else {
633 error = Error::BAD_DISPLAY;
634 }
Ady Abrahame7385f72021-09-05 00:54:25 -0700635
Ady Abrahame7385f72021-09-05 00:54:25 -0700636 if (error != Error::NONE) {
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400637 mMutex.unlock_shared();
Ady Abrahame7385f72021-09-05 00:54:25 -0700638 return error;
639 }
640
Leon Scroggins IIIe85e16e2022-12-12 12:51:18 -0500641 auto fence = reader->get().takePresentFence(displayId);
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400642 mMutex.unlock_shared();
Ady Abrahamde792782021-12-20 10:00:49 -0800643 // take ownership
644 *outPresentFence = fence.get();
645 *fence.getR() = -1;
Ady Abrahame7385f72021-09-05 00:54:25 -0700646 return Error::NONE;
647}
648
649Error AidlComposer::setActiveConfig(Display display, Config config) {
650 const auto status = mAidlComposerClient->setActiveConfig(translate<int64_t>(display),
651 translate<int32_t>(config));
652 if (!status.isOk()) {
653 ALOGE("setActiveConfig failed %s", status.getDescription().c_str());
654 return static_cast<Error>(status.getServiceSpecificError());
655 }
656 return Error::NONE;
657}
658
659Error AidlComposer::setClientTarget(Display display, uint32_t slot, const sp<GraphicBuffer>& target,
660 int acquireFence, Dataspace dataspace,
661 const std::vector<IComposerClient::Rect>& damage) {
Ady Abrahame7385f72021-09-05 00:54:25 -0700662 const native_handle_t* handle = nullptr;
663 if (target.get()) {
664 handle = target->getNativeBuffer()->handle;
665 }
666
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400667 Error error = Error::NONE;
668 mMutex.lock_shared();
669 if (auto writer = getWriter(display)) {
670 writer->get()
671 .setClientTarget(translate<int64_t>(display), slot, handle, acquireFence,
672 translate<aidl::android::hardware::graphics::common::Dataspace>(
673 dataspace),
674 translate<AidlRect>(damage));
675 } else {
676 error = Error::BAD_DISPLAY;
677 }
678 mMutex.unlock_shared();
679 return error;
Ady Abrahame7385f72021-09-05 00:54:25 -0700680}
681
682Error AidlComposer::setColorMode(Display display, ColorMode mode, RenderIntent renderIntent) {
683 const auto status =
684 mAidlComposerClient->setColorMode(translate<int64_t>(display),
685 translate<AidlColorMode>(mode),
686 translate<AidlRenderIntent>(renderIntent));
687 if (!status.isOk()) {
688 ALOGE("setColorMode failed %s", status.getDescription().c_str());
689 return static_cast<Error>(status.getServiceSpecificError());
690 }
691 return Error::NONE;
692}
693
Ady Abrahamdc011a92021-12-21 14:06:44 -0800694Error AidlComposer::setColorTransform(Display display, const float* matrix) {
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400695 auto error = Error::NONE;
696 mMutex.lock_shared();
697 if (auto writer = getWriter(display)) {
698 writer->get().setColorTransform(translate<int64_t>(display), matrix);
699 } else {
700 error = Error::BAD_DISPLAY;
701 }
702 mMutex.unlock_shared();
703 return error;
Ady Abrahame7385f72021-09-05 00:54:25 -0700704}
705
706Error AidlComposer::setOutputBuffer(Display display, const native_handle_t* buffer,
707 int releaseFence) {
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400708 auto error = Error::NONE;
709 mMutex.lock_shared();
710 if (auto writer = getWriter(display)) {
711 writer->get().setOutputBuffer(translate<int64_t>(display), 0, buffer, dup(releaseFence));
712 } else {
713 error = Error::BAD_DISPLAY;
714 }
715 mMutex.unlock_shared();
716 return error;
Ady Abrahame7385f72021-09-05 00:54:25 -0700717}
718
719Error AidlComposer::setPowerMode(Display display, IComposerClient::PowerMode mode) {
720 const auto status = mAidlComposerClient->setPowerMode(translate<int64_t>(display),
721 translate<PowerMode>(mode));
722 if (!status.isOk()) {
723 ALOGE("setPowerMode failed %s", status.getDescription().c_str());
724 return static_cast<Error>(status.getServiceSpecificError());
725 }
726 return Error::NONE;
727}
728
729Error AidlComposer::setVsyncEnabled(Display display, IComposerClient::Vsync enabled) {
730 const bool enableVsync = enabled == IComposerClient::Vsync::ENABLE;
731 const auto status =
732 mAidlComposerClient->setVsyncEnabled(translate<int64_t>(display), enableVsync);
733 if (!status.isOk()) {
734 ALOGE("setVsyncEnabled failed %s", status.getDescription().c_str());
735 return static_cast<Error>(status.getServiceSpecificError());
736 }
737 return Error::NONE;
738}
739
740Error AidlComposer::setClientTargetSlotCount(Display display) {
741 const int32_t bufferSlotCount = BufferQueue::NUM_BUFFER_SLOTS;
742 const auto status = mAidlComposerClient->setClientTargetSlotCount(translate<int64_t>(display),
743 bufferSlotCount);
744 if (!status.isOk()) {
745 ALOGE("setClientTargetSlotCount failed %s", status.getDescription().c_str());
746 return static_cast<Error>(status.getServiceSpecificError());
747 }
748 return Error::NONE;
749}
750
Ady Abraham43065bd2021-12-10 17:22:15 -0800751Error AidlComposer::validateDisplay(Display display, nsecs_t expectedPresentTime,
ramindani09acbb82023-11-03 09:02:38 -0700752 int32_t frameIntervalNs, uint32_t* outNumTypes,
753 uint32_t* outNumRequests) {
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400754 const auto displayId = translate<int64_t>(display);
Leon Scroggins IIIe85e16e2022-12-12 12:51:18 -0500755 ATRACE_FORMAT("HwcValidateDisplay %" PRId64, displayId);
756
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400757 Error error = Error::NONE;
758 mMutex.lock_shared();
759 auto writer = getWriter(display);
760 auto reader = getReader(display);
761 if (writer && reader) {
ramindani09acbb82023-11-03 09:02:38 -0700762 writer->get().validateDisplay(displayId, ClockMonotonicTimestamp{expectedPresentTime},
763 frameIntervalNs);
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400764 error = execute(display);
765 } else {
766 error = Error::BAD_DISPLAY;
767 }
Ady Abrahame7385f72021-09-05 00:54:25 -0700768
Ady Abrahame7385f72021-09-05 00:54:25 -0700769 if (error != Error::NONE) {
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400770 mMutex.unlock_shared();
Ady Abrahame7385f72021-09-05 00:54:25 -0700771 return error;
772 }
773
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400774 reader->get().hasChanges(displayId, outNumTypes, outNumRequests);
Ady Abrahame7385f72021-09-05 00:54:25 -0700775
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400776 mMutex.unlock_shared();
Ady Abrahame7385f72021-09-05 00:54:25 -0700777 return Error::NONE;
778}
779
Ady Abraham43065bd2021-12-10 17:22:15 -0800780Error AidlComposer::presentOrValidateDisplay(Display display, nsecs_t expectedPresentTime,
ramindani4aac32c2023-10-30 14:13:30 -0700781 int32_t frameIntervalNs, uint32_t* outNumTypes,
782 uint32_t* outNumRequests, int* outPresentFence,
783 uint32_t* state) {
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400784 const auto displayId = translate<int64_t>(display);
Leon Scroggins IIIe85e16e2022-12-12 12:51:18 -0500785 ATRACE_FORMAT("HwcPresentOrValidateDisplay %" PRId64, displayId);
786
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400787 Error error = Error::NONE;
788 mMutex.lock_shared();
789 auto writer = getWriter(display);
790 auto reader = getReader(display);
791 if (writer && reader) {
792 writer->get().presentOrvalidateDisplay(displayId,
ramindani4aac32c2023-10-30 14:13:30 -0700793 ClockMonotonicTimestamp{expectedPresentTime},
794 frameIntervalNs);
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400795 error = execute(display);
796 } else {
797 error = Error::BAD_DISPLAY;
798 }
Ady Abrahame7385f72021-09-05 00:54:25 -0700799
Ady Abrahame7385f72021-09-05 00:54:25 -0700800 if (error != Error::NONE) {
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400801 mMutex.unlock_shared();
Ady Abrahame7385f72021-09-05 00:54:25 -0700802 return error;
803 }
804
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400805 const auto result = reader->get().takePresentOrValidateStage(displayId);
Ady Abrahamde792782021-12-20 10:00:49 -0800806 if (!result.has_value()) {
807 *state = translate<uint32_t>(-1);
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400808 mMutex.unlock_shared();
Ady Abrahamde792782021-12-20 10:00:49 -0800809 return Error::NO_RESOURCES;
Ady Abrahame7385f72021-09-05 00:54:25 -0700810 }
811
Ady Abrahamde792782021-12-20 10:00:49 -0800812 *state = translate<uint32_t>(*result);
813
814 if (*result == PresentOrValidate::Result::Presented) {
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400815 auto fence = reader->get().takePresentFence(displayId);
Ady Abrahamde792782021-12-20 10:00:49 -0800816 // take ownership
817 *outPresentFence = fence.get();
818 *fence.getR() = -1;
819 }
820
821 if (*result == PresentOrValidate::Result::Validated) {
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400822 reader->get().hasChanges(displayId, outNumTypes, outNumRequests);
Ady Abrahame7385f72021-09-05 00:54:25 -0700823 }
824
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400825 mMutex.unlock_shared();
Ady Abrahame7385f72021-09-05 00:54:25 -0700826 return Error::NONE;
827}
828
829Error AidlComposer::setCursorPosition(Display display, Layer layer, int32_t x, int32_t y) {
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400830 Error error = Error::NONE;
831 mMutex.lock_shared();
832 if (auto writer = getWriter(display)) {
833 writer->get().setLayerCursorPosition(translate<int64_t>(display), translate<int64_t>(layer),
834 x, y);
835 } else {
836 error = Error::BAD_DISPLAY;
837 }
838 mMutex.unlock_shared();
839 return error;
Ady Abrahame7385f72021-09-05 00:54:25 -0700840}
841
842Error AidlComposer::setLayerBuffer(Display display, Layer layer, uint32_t slot,
843 const sp<GraphicBuffer>& buffer, int acquireFence) {
Ady Abrahame7385f72021-09-05 00:54:25 -0700844 const native_handle_t* handle = nullptr;
845 if (buffer.get()) {
846 handle = buffer->getNativeBuffer()->handle;
847 }
848
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400849 Error error = Error::NONE;
850 mMutex.lock_shared();
851 if (auto writer = getWriter(display)) {
852 writer->get().setLayerBuffer(translate<int64_t>(display), translate<int64_t>(layer), slot,
853 handle, acquireFence);
854 } else {
855 error = Error::BAD_DISPLAY;
856 }
857 mMutex.unlock_shared();
858 return error;
Ady Abrahame7385f72021-09-05 00:54:25 -0700859}
860
Brian Lindahlb158a5c2022-12-15 15:21:13 -0700861Error AidlComposer::setLayerBufferSlotsToClear(Display display, Layer layer,
862 const std::vector<uint32_t>& slotsToClear,
863 uint32_t activeBufferSlot) {
864 if (slotsToClear.empty()) {
865 return Error::NONE;
866 }
867
Brian Lindahl90553da2022-12-06 13:36:30 -0700868 Error error = Error::NONE;
869 mMutex.lock_shared();
870 if (auto writer = getWriter(display)) {
ramindani0cd1d8d2023-06-13 13:43:23 -0700871 if (mComposerInterfaceVersion > 1) {
Brian Lindahldbf7e3a2022-12-16 11:43:39 -0700872 writer->get().setLayerBufferSlotsToClear(translate<int64_t>(display),
873 translate<int64_t>(layer), slotsToClear);
Brian Lindahl5b0ffe02023-06-15 14:19:43 -0600874 // Backwards compatible way of clearing buffer slots is to set the layer buffer with a
875 // placeholder buffer, using the slot that needs to cleared... tricky.
876 } else if (mClearSlotBuffer != nullptr) {
Brian Lindahldbf7e3a2022-12-16 11:43:39 -0700877 for (uint32_t slot : slotsToClear) {
878 // Don't clear the active buffer slot because we need to restore the active buffer
879 // after clearing the requested buffer slots with a placeholder buffer.
880 if (slot != activeBufferSlot) {
881 writer->get().setLayerBufferWithNewCommand(translate<int64_t>(display),
882 translate<int64_t>(layer), slot,
883 mClearSlotBuffer->handle,
884 /*fence*/ -1);
885 }
Brian Lindahlb158a5c2022-12-15 15:21:13 -0700886 }
Brian Lindahldbf7e3a2022-12-16 11:43:39 -0700887 // Since we clear buffers by setting them to a placeholder buffer, we want to make
888 // sure that the last setLayerBuffer command is sent with the currently active
889 // buffer, not the placeholder buffer, so that there is no perceptual change when
890 // buffers are discarded.
891 writer->get().setLayerBufferWithNewCommand(translate<int64_t>(display),
892 translate<int64_t>(layer), activeBufferSlot,
893 // The active buffer is still cached in
894 // its slot and doesn't need a fence.
895 /*buffer*/ nullptr, /*fence*/ -1);
Brian Lindahlb158a5c2022-12-15 15:21:13 -0700896 }
Brian Lindahl90553da2022-12-06 13:36:30 -0700897 } else {
898 error = Error::BAD_DISPLAY;
899 }
900 mMutex.unlock_shared();
901 return error;
902}
903
Ady Abrahame7385f72021-09-05 00:54:25 -0700904Error AidlComposer::setLayerSurfaceDamage(Display display, Layer layer,
905 const std::vector<IComposerClient::Rect>& damage) {
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400906 Error error = Error::NONE;
907 mMutex.lock_shared();
908 if (auto writer = getWriter(display)) {
909 writer->get().setLayerSurfaceDamage(translate<int64_t>(display), translate<int64_t>(layer),
910 translate<AidlRect>(damage));
911 } else {
912 error = Error::BAD_DISPLAY;
913 }
914 mMutex.unlock_shared();
915 return error;
Ady Abrahame7385f72021-09-05 00:54:25 -0700916}
917
918Error AidlComposer::setLayerBlendMode(Display display, Layer layer,
919 IComposerClient::BlendMode mode) {
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().setLayerBlendMode(translate<int64_t>(display), translate<int64_t>(layer),
924 translate<BlendMode>(mode));
925 } else {
926 error = Error::BAD_DISPLAY;
927 }
928 mMutex.unlock_shared();
929 return error;
Ady Abrahame7385f72021-09-05 00:54:25 -0700930}
931
Ady Abraham6e60b142022-01-06 18:10:35 -0800932Error AidlComposer::setLayerColor(Display display, Layer layer, const Color& color) {
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400933 Error error = Error::NONE;
934 mMutex.lock_shared();
935 if (auto writer = getWriter(display)) {
936 writer->get().setLayerColor(translate<int64_t>(display), translate<int64_t>(layer), color);
937 } else {
938 error = Error::BAD_DISPLAY;
939 }
940 mMutex.unlock_shared();
941 return error;
Ady Abrahame7385f72021-09-05 00:54:25 -0700942}
943
Leon Scroggins III2e1aa182021-12-01 17:33:12 -0500944Error AidlComposer::setLayerCompositionType(
945 Display display, Layer layer,
946 aidl::android::hardware::graphics::composer3::Composition type) {
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400947 Error error = Error::NONE;
948 mMutex.lock_shared();
949 if (auto writer = getWriter(display)) {
950 writer->get().setLayerCompositionType(translate<int64_t>(display),
951 translate<int64_t>(layer), type);
952 } else {
953 error = Error::BAD_DISPLAY;
954 }
955 mMutex.unlock_shared();
956 return error;
Ady Abrahame7385f72021-09-05 00:54:25 -0700957}
958
959Error AidlComposer::setLayerDataspace(Display display, Layer layer, Dataspace dataspace) {
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400960 Error error = Error::NONE;
961 mMutex.lock_shared();
962 if (auto writer = getWriter(display)) {
963 writer->get().setLayerDataspace(translate<int64_t>(display), translate<int64_t>(layer),
964 translate<AidlDataspace>(dataspace));
965 } else {
966 error = Error::BAD_DISPLAY;
967 }
968 mMutex.unlock_shared();
969 return error;
Ady Abrahame7385f72021-09-05 00:54:25 -0700970}
971
972Error AidlComposer::setLayerDisplayFrame(Display display, Layer layer,
973 const IComposerClient::Rect& frame) {
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400974 Error error = Error::NONE;
975 mMutex.lock_shared();
976 if (auto writer = getWriter(display)) {
977 writer->get().setLayerDisplayFrame(translate<int64_t>(display), translate<int64_t>(layer),
978 translate<AidlRect>(frame));
979 } else {
980 error = Error::BAD_DISPLAY;
981 }
982 mMutex.unlock_shared();
983 return error;
Ady Abrahame7385f72021-09-05 00:54:25 -0700984}
985
986Error AidlComposer::setLayerPlaneAlpha(Display display, Layer layer, float alpha) {
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400987 Error error = Error::NONE;
988 mMutex.lock_shared();
989 if (auto writer = getWriter(display)) {
990 writer->get().setLayerPlaneAlpha(translate<int64_t>(display), translate<int64_t>(layer),
991 alpha);
992 } else {
993 error = Error::BAD_DISPLAY;
994 }
995 mMutex.unlock_shared();
996 return error;
Ady Abrahame7385f72021-09-05 00:54:25 -0700997}
998
999Error AidlComposer::setLayerSidebandStream(Display display, Layer layer,
1000 const native_handle_t* stream) {
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -04001001 Error error = Error::NONE;
1002 mMutex.lock_shared();
1003 if (auto writer = getWriter(display)) {
1004 writer->get().setLayerSidebandStream(translate<int64_t>(display), translate<int64_t>(layer),
1005 stream);
1006 } else {
1007 error = Error::BAD_DISPLAY;
1008 }
1009 mMutex.unlock_shared();
1010 return error;
Ady Abrahame7385f72021-09-05 00:54:25 -07001011}
1012
1013Error AidlComposer::setLayerSourceCrop(Display display, Layer layer,
1014 const IComposerClient::FRect& crop) {
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -04001015 Error error = Error::NONE;
1016 mMutex.lock_shared();
1017 if (auto writer = getWriter(display)) {
1018 writer->get().setLayerSourceCrop(translate<int64_t>(display), translate<int64_t>(layer),
1019 translate<AidlFRect>(crop));
1020 } else {
1021 error = Error::BAD_DISPLAY;
1022 }
1023 mMutex.unlock_shared();
1024 return error;
Ady Abrahame7385f72021-09-05 00:54:25 -07001025}
1026
1027Error AidlComposer::setLayerTransform(Display display, Layer layer, Transform transform) {
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -04001028 Error error = Error::NONE;
1029 mMutex.lock_shared();
1030 if (auto writer = getWriter(display)) {
1031 writer->get().setLayerTransform(translate<int64_t>(display), translate<int64_t>(layer),
1032 translate<AidlTransform>(transform));
1033 } else {
1034 error = Error::BAD_DISPLAY;
1035 }
1036 mMutex.unlock_shared();
1037 return error;
Ady Abrahame7385f72021-09-05 00:54:25 -07001038}
1039
1040Error AidlComposer::setLayerVisibleRegion(Display display, Layer layer,
1041 const std::vector<IComposerClient::Rect>& visible) {
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -04001042 Error error = Error::NONE;
1043 mMutex.lock_shared();
1044 if (auto writer = getWriter(display)) {
1045 writer->get().setLayerVisibleRegion(translate<int64_t>(display), translate<int64_t>(layer),
1046 translate<AidlRect>(visible));
1047 } else {
1048 error = Error::BAD_DISPLAY;
1049 }
1050 mMutex.unlock_shared();
1051 return error;
Ady Abrahame7385f72021-09-05 00:54:25 -07001052}
1053
1054Error AidlComposer::setLayerZOrder(Display display, Layer layer, uint32_t z) {
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -04001055 Error error = Error::NONE;
1056 mMutex.lock_shared();
1057 if (auto writer = getWriter(display)) {
1058 writer->get().setLayerZOrder(translate<int64_t>(display), translate<int64_t>(layer), z);
1059 } else {
1060 error = Error::BAD_DISPLAY;
1061 }
1062 mMutex.unlock_shared();
1063 return error;
Ady Abrahame7385f72021-09-05 00:54:25 -07001064}
1065
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -04001066Error AidlComposer::execute(Display display) {
1067 auto writer = getWriter(display);
1068 auto reader = getReader(display);
1069 if (!writer || !reader) {
1070 return Error::BAD_DISPLAY;
1071 }
1072
Huihong Luoe7382c12023-04-21 20:24:32 +00001073 auto commands = writer->get().takePendingCommands();
Ady Abrahama6388c02021-11-11 21:11:51 -08001074 if (commands.empty()) {
Ady Abrahame7385f72021-09-05 00:54:25 -07001075 return Error::NONE;
1076 }
1077
Ady Abrahamde792782021-12-20 10:00:49 -08001078 { // scope for results
1079 std::vector<CommandResultPayload> results;
1080 auto status = mAidlComposerClient->executeCommands(commands, &results);
1081 if (!status.isOk()) {
1082 ALOGE("executeCommands failed %s", status.getDescription().c_str());
1083 return static_cast<Error>(status.getServiceSpecificError());
1084 }
Ady Abrahame7385f72021-09-05 00:54:25 -07001085
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -04001086 reader->get().parse(std::move(results));
Ady Abrahamde792782021-12-20 10:00:49 -08001087 }
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -04001088 const auto commandErrors = reader->get().takeErrors();
Ady Abrahama6388c02021-11-11 21:11:51 -08001089 Error error = Error::NONE;
1090 for (const auto& cmdErr : commandErrors) {
1091 const auto index = static_cast<size_t>(cmdErr.commandIndex);
1092 if (index < 0 || index >= commands.size()) {
1093 ALOGE("invalid command index %zu", index);
1094 return Error::BAD_PARAMETER;
Ady Abrahame7385f72021-09-05 00:54:25 -07001095 }
1096
Ady Abrahama6388c02021-11-11 21:11:51 -08001097 const auto& command = commands[index];
Ady Abraham42977362021-12-07 21:04:49 -08001098 if (command.validateDisplay || command.presentDisplay || command.presentOrValidateDisplay) {
1099 error = translate<Error>(cmdErr.errorCode);
1100 } else {
1101 ALOGW("command '%s' generated error %" PRId32, command.toString().c_str(),
1102 cmdErr.errorCode);
Ady Abrahame7385f72021-09-05 00:54:25 -07001103 }
1104 }
1105
Ady Abrahame7385f72021-09-05 00:54:25 -07001106 return error;
1107}
1108
1109Error AidlComposer::setLayerPerFrameMetadata(
1110 Display display, Layer layer,
1111 const std::vector<IComposerClient::PerFrameMetadata>& perFrameMetadatas) {
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -04001112 Error error = Error::NONE;
1113 mMutex.lock_shared();
1114 if (auto writer = getWriter(display)) {
1115 writer->get().setLayerPerFrameMetadata(translate<int64_t>(display),
1116 translate<int64_t>(layer),
1117 translate<AidlPerFrameMetadata>(perFrameMetadatas));
1118 } else {
1119 error = Error::BAD_DISPLAY;
1120 }
1121 mMutex.unlock_shared();
1122 return error;
Ady Abrahame7385f72021-09-05 00:54:25 -07001123}
1124
1125std::vector<IComposerClient::PerFrameMetadataKey> AidlComposer::getPerFrameMetadataKeys(
1126 Display display) {
1127 std::vector<AidlPerFrameMetadataKey> keys;
1128 const auto status =
1129 mAidlComposerClient->getPerFrameMetadataKeys(translate<int64_t>(display), &keys);
1130 if (!status.isOk()) {
1131 ALOGE("getPerFrameMetadataKeys failed %s", status.getDescription().c_str());
1132 return {};
1133 }
1134 return translate<IComposerClient::PerFrameMetadataKey>(keys);
1135}
1136
1137Error AidlComposer::getRenderIntents(Display display, ColorMode colorMode,
1138 std::vector<RenderIntent>* outRenderIntents) {
1139 std::vector<AidlRenderIntent> renderIntents;
1140 const auto status = mAidlComposerClient->getRenderIntents(translate<int64_t>(display),
1141 translate<AidlColorMode>(colorMode),
1142 &renderIntents);
1143 if (!status.isOk()) {
1144 ALOGE("getRenderIntents failed %s", status.getDescription().c_str());
1145 return static_cast<Error>(status.getServiceSpecificError());
1146 }
1147 *outRenderIntents = translate<RenderIntent>(renderIntents);
1148 return Error::NONE;
1149}
1150
1151Error AidlComposer::getDataspaceSaturationMatrix(Dataspace dataspace, mat4* outMatrix) {
1152 std::vector<float> matrix;
1153 const auto status =
1154 mAidlComposerClient->getDataspaceSaturationMatrix(translate<AidlDataspace>(dataspace),
1155 &matrix);
1156 if (!status.isOk()) {
1157 ALOGE("getDataspaceSaturationMatrix failed %s", status.getDescription().c_str());
1158 return static_cast<Error>(status.getServiceSpecificError());
1159 }
1160 *outMatrix = makeMat4(matrix);
1161 return Error::NONE;
1162}
1163
1164Error AidlComposer::getDisplayIdentificationData(Display display, uint8_t* outPort,
1165 std::vector<uint8_t>* outData) {
1166 AidlDisplayIdentification displayIdentification;
1167 const auto status =
1168 mAidlComposerClient->getDisplayIdentificationData(translate<int64_t>(display),
1169 &displayIdentification);
1170 if (!status.isOk()) {
1171 ALOGE("getDisplayIdentificationData failed %s", status.getDescription().c_str());
1172 return static_cast<Error>(status.getServiceSpecificError());
1173 }
1174
1175 *outPort = static_cast<uint8_t>(displayIdentification.port);
1176 *outData = displayIdentification.data;
1177
1178 return Error::NONE;
1179}
1180
1181Error AidlComposer::setLayerColorTransform(Display display, Layer layer, const float* matrix) {
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -04001182 Error error = Error::NONE;
1183 mMutex.lock_shared();
1184 if (auto writer = getWriter(display)) {
1185 writer->get().setLayerColorTransform(translate<int64_t>(display), translate<int64_t>(layer),
1186 matrix);
1187 } else {
1188 error = Error::BAD_DISPLAY;
1189 }
1190 mMutex.unlock_shared();
1191 return error;
Ady Abrahame7385f72021-09-05 00:54:25 -07001192}
1193
1194Error AidlComposer::getDisplayedContentSamplingAttributes(Display display, PixelFormat* outFormat,
1195 Dataspace* outDataspace,
1196 uint8_t* outComponentMask) {
1197 if (!outFormat || !outDataspace || !outComponentMask) {
1198 return Error::BAD_PARAMETER;
1199 }
1200
1201 AidlDisplayContentSamplingAttributes attributes;
1202 const auto status =
1203 mAidlComposerClient->getDisplayedContentSamplingAttributes(translate<int64_t>(display),
1204 &attributes);
1205 if (!status.isOk()) {
1206 ALOGE("getDisplayedContentSamplingAttributes failed %s", status.getDescription().c_str());
1207 return static_cast<Error>(status.getServiceSpecificError());
1208 }
1209
1210 *outFormat = translate<PixelFormat>(attributes.format);
1211 *outDataspace = translate<Dataspace>(attributes.dataspace);
1212 *outComponentMask = static_cast<uint8_t>(attributes.componentMask);
1213 return Error::NONE;
1214}
1215
1216Error AidlComposer::setDisplayContentSamplingEnabled(Display display, bool enabled,
1217 uint8_t componentMask, uint64_t maxFrames) {
1218 const auto status =
1219 mAidlComposerClient
1220 ->setDisplayedContentSamplingEnabled(translate<int64_t>(display), enabled,
1221 static_cast<AidlFormatColorComponent>(
1222 componentMask),
1223 static_cast<int64_t>(maxFrames));
1224 if (!status.isOk()) {
1225 ALOGE("setDisplayedContentSamplingEnabled failed %s", status.getDescription().c_str());
1226 return static_cast<Error>(status.getServiceSpecificError());
1227 }
1228 return Error::NONE;
1229}
1230
1231Error AidlComposer::getDisplayedContentSample(Display display, uint64_t maxFrames,
1232 uint64_t timestamp, DisplayedFrameStats* outStats) {
1233 if (!outStats) {
1234 return Error::BAD_PARAMETER;
1235 }
1236
1237 AidlDisplayContentSample sample;
1238 const auto status =
1239 mAidlComposerClient->getDisplayedContentSample(translate<int64_t>(display),
1240 static_cast<int64_t>(maxFrames),
1241 static_cast<int64_t>(timestamp),
1242 &sample);
1243 if (!status.isOk()) {
1244 ALOGE("getDisplayedContentSample failed %s", status.getDescription().c_str());
1245 return static_cast<Error>(status.getServiceSpecificError());
1246 }
1247 *outStats = translate<DisplayedFrameStats>(sample);
1248 return Error::NONE;
1249}
1250
1251Error AidlComposer::setLayerPerFrameMetadataBlobs(
1252 Display display, Layer layer,
1253 const std::vector<IComposerClient::PerFrameMetadataBlob>& metadata) {
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -04001254 Error error = Error::NONE;
1255 mMutex.lock_shared();
1256 if (auto writer = getWriter(display)) {
1257 writer->get().setLayerPerFrameMetadataBlobs(translate<int64_t>(display),
1258 translate<int64_t>(layer),
1259 translate<AidlPerFrameMetadataBlob>(metadata));
1260 } else {
1261 error = Error::BAD_DISPLAY;
1262 }
1263 mMutex.unlock_shared();
1264 return error;
Ady Abrahame7385f72021-09-05 00:54:25 -07001265}
1266
Alec Mouri4d8a05d2022-03-23 18:14:26 +00001267Error AidlComposer::setDisplayBrightness(Display display, float brightness, float brightnessNits,
Alec Mouricdf16792021-12-10 13:16:06 -08001268 const DisplayBrightnessOptions& options) {
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -04001269 Error error = Error::NONE;
1270 mMutex.lock_shared();
1271 if (auto writer = getWriter(display)) {
1272 writer->get().setDisplayBrightness(translate<int64_t>(display), brightness, brightnessNits);
Alec Mouricdf16792021-12-10 13:16:06 -08001273
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -04001274 if (options.applyImmediately) {
1275 error = execute(display);
1276 mMutex.unlock_shared();
1277 return error;
1278 }
1279 } else {
1280 error = Error::BAD_DISPLAY;
Alec Mouricdf16792021-12-10 13:16:06 -08001281 }
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -04001282 mMutex.unlock_shared();
1283 return error;
Ady Abrahame7385f72021-09-05 00:54:25 -07001284}
1285
1286Error AidlComposer::getDisplayCapabilities(Display display,
Leon Scroggins III5967aec2021-12-29 11:14:22 -05001287 std::vector<AidlDisplayCapability>* outCapabilities) {
1288 const auto status = mAidlComposerClient->getDisplayCapabilities(translate<int64_t>(display),
1289 outCapabilities);
Ady Abrahame7385f72021-09-05 00:54:25 -07001290 if (!status.isOk()) {
1291 ALOGE("getDisplayCapabilities failed %s", status.getDescription().c_str());
Leon Scroggins III5967aec2021-12-29 11:14:22 -05001292 outCapabilities->clear();
Ady Abrahame7385f72021-09-05 00:54:25 -07001293 return static_cast<Error>(status.getServiceSpecificError());
1294 }
Ady Abrahame7385f72021-09-05 00:54:25 -07001295 return Error::NONE;
1296}
1297
1298V2_4::Error AidlComposer::getDisplayConnectionType(
1299 Display display, IComposerClient::DisplayConnectionType* outType) {
1300 AidlDisplayConnectionType type;
1301 const auto status =
1302 mAidlComposerClient->getDisplayConnectionType(translate<int64_t>(display), &type);
1303 if (!status.isOk()) {
1304 ALOGE("getDisplayConnectionType failed %s", status.getDescription().c_str());
1305 return static_cast<V2_4::Error>(status.getServiceSpecificError());
1306 }
1307 *outType = translate<IComposerClient::DisplayConnectionType>(type);
1308 return V2_4::Error::NONE;
1309}
1310
1311V2_4::Error AidlComposer::getDisplayVsyncPeriod(Display display, VsyncPeriodNanos* outVsyncPeriod) {
1312 int32_t vsyncPeriod;
1313 const auto status =
1314 mAidlComposerClient->getDisplayVsyncPeriod(translate<int64_t>(display), &vsyncPeriod);
1315 if (!status.isOk()) {
1316 ALOGE("getDisplayVsyncPeriod failed %s", status.getDescription().c_str());
1317 return static_cast<V2_4::Error>(status.getServiceSpecificError());
1318 }
1319 *outVsyncPeriod = translate<VsyncPeriodNanos>(vsyncPeriod);
1320 return V2_4::Error::NONE;
1321}
1322
1323V2_4::Error AidlComposer::setActiveConfigWithConstraints(
1324 Display display, Config config,
1325 const IComposerClient::VsyncPeriodChangeConstraints& vsyncPeriodChangeConstraints,
1326 VsyncPeriodChangeTimeline* outTimeline) {
1327 AidlVsyncPeriodChangeTimeline timeline;
1328 const auto status =
1329 mAidlComposerClient
1330 ->setActiveConfigWithConstraints(translate<int64_t>(display),
1331 translate<int32_t>(config),
1332 translate<AidlVsyncPeriodChangeConstraints>(
1333 vsyncPeriodChangeConstraints),
1334 &timeline);
1335 if (!status.isOk()) {
1336 ALOGE("setActiveConfigWithConstraints failed %s", status.getDescription().c_str());
1337 return static_cast<V2_4::Error>(status.getServiceSpecificError());
1338 }
1339 *outTimeline = translate<VsyncPeriodChangeTimeline>(timeline);
1340 return V2_4::Error::NONE;
1341}
1342
1343V2_4::Error AidlComposer::setAutoLowLatencyMode(Display display, bool on) {
1344 const auto status = mAidlComposerClient->setAutoLowLatencyMode(translate<int64_t>(display), on);
1345 if (!status.isOk()) {
1346 ALOGE("setAutoLowLatencyMode failed %s", status.getDescription().c_str());
1347 return static_cast<V2_4::Error>(status.getServiceSpecificError());
1348 }
1349 return V2_4::Error::NONE;
1350}
1351
1352V2_4::Error AidlComposer::getSupportedContentTypes(
1353 Display displayId, std::vector<IComposerClient::ContentType>* outSupportedContentTypes) {
1354 std::vector<AidlContentType> types;
1355 const auto status =
1356 mAidlComposerClient->getSupportedContentTypes(translate<int64_t>(displayId), &types);
1357 if (!status.isOk()) {
1358 ALOGE("getSupportedContentTypes failed %s", status.getDescription().c_str());
1359 return static_cast<V2_4::Error>(status.getServiceSpecificError());
1360 }
1361 *outSupportedContentTypes = translate<IComposerClient::ContentType>(types);
1362 return V2_4::Error::NONE;
1363}
1364
1365V2_4::Error AidlComposer::setContentType(Display display,
1366 IComposerClient::ContentType contentType) {
1367 const auto status =
1368 mAidlComposerClient->setContentType(translate<int64_t>(display),
1369 translate<AidlContentType>(contentType));
1370 if (!status.isOk()) {
1371 ALOGE("setContentType failed %s", status.getDescription().c_str());
1372 return static_cast<V2_4::Error>(status.getServiceSpecificError());
1373 }
1374 return V2_4::Error::NONE;
1375}
1376
Ady Abraham3f976752021-12-20 16:17:50 -08001377V2_4::Error AidlComposer::setLayerGenericMetadata(Display, Layer, const std::string&, bool,
1378 const std::vector<uint8_t>&) {
1379 // There are no users for this API. See b/209691612.
1380 return V2_4::Error::UNSUPPORTED;
Ady Abrahame7385f72021-09-05 00:54:25 -07001381}
1382
1383V2_4::Error AidlComposer::getLayerGenericMetadataKeys(
Ady Abraham3f976752021-12-20 16:17:50 -08001384 std::vector<IComposerClient::LayerGenericMetadataKey>*) {
1385 // There are no users for this API. See b/209691612.
1386 return V2_4::Error::UNSUPPORTED;
Ady Abrahame7385f72021-09-05 00:54:25 -07001387}
1388
Kriti Dang7defaf32021-11-15 11:55:43 +01001389Error AidlComposer::setBootDisplayConfig(Display display, Config config) {
1390 const auto status = mAidlComposerClient->setBootDisplayConfig(translate<int64_t>(display),
1391 translate<int32_t>(config));
1392 if (!status.isOk()) {
1393 ALOGE("setBootDisplayConfig failed %s", status.getDescription().c_str());
1394 return static_cast<Error>(status.getServiceSpecificError());
1395 }
1396 return Error::NONE;
1397}
1398
1399Error AidlComposer::clearBootDisplayConfig(Display display) {
1400 const auto status = mAidlComposerClient->clearBootDisplayConfig(translate<int64_t>(display));
1401 if (!status.isOk()) {
1402 ALOGE("clearBootDisplayConfig failed %s", status.getDescription().c_str());
1403 return static_cast<Error>(status.getServiceSpecificError());
1404 }
1405 return Error::NONE;
1406}
1407
1408Error AidlComposer::getPreferredBootDisplayConfig(Display display, Config* config) {
1409 int32_t displayConfig;
1410 const auto status =
1411 mAidlComposerClient->getPreferredBootDisplayConfig(translate<int64_t>(display),
1412 &displayConfig);
1413 if (!status.isOk()) {
1414 ALOGE("getPreferredBootDisplayConfig failed %s", status.getDescription().c_str());
1415 return static_cast<Error>(status.getServiceSpecificError());
1416 }
1417 *config = translate<uint32_t>(displayConfig);
1418 return Error::NONE;
1419}
1420
Kriti Dang674b9372022-11-18 10:58:44 +01001421Error AidlComposer::getHdrConversionCapabilities(
1422 std::vector<AidlHdrConversionCapability>* hdrConversionCapabilities) {
1423 const auto status =
1424 mAidlComposerClient->getHdrConversionCapabilities(hdrConversionCapabilities);
1425 if (!status.isOk()) {
1426 hdrConversionCapabilities = {};
1427 ALOGE("getHdrConversionCapabilities failed %s", status.getDescription().c_str());
1428 return static_cast<Error>(status.getServiceSpecificError());
1429 }
1430 return Error::NONE;
1431}
1432
Kriti Dangd432bb52023-02-09 18:21:04 +01001433Error AidlComposer::setHdrConversionStrategy(AidlHdrConversionStrategy hdrConversionStrategy,
1434 Hdr* outPreferredHdrOutputType) {
1435 const auto status = mAidlComposerClient->setHdrConversionStrategy(hdrConversionStrategy,
1436 outPreferredHdrOutputType);
Kriti Dang674b9372022-11-18 10:58:44 +01001437 if (!status.isOk()) {
1438 ALOGE("setHdrConversionStrategy failed %s", status.getDescription().c_str());
1439 return static_cast<Error>(status.getServiceSpecificError());
1440 }
1441 return Error::NONE;
1442}
1443
ramindanib2158ee2023-02-13 20:29:59 -08001444Error AidlComposer::setRefreshRateChangedCallbackDebugEnabled(Display displayId, bool enabled) {
1445 const auto status =
1446 mAidlComposerClient->setRefreshRateChangedCallbackDebugEnabled(translate<int64_t>(
1447 displayId),
1448 enabled);
1449 if (!status.isOk()) {
1450 ALOGE("setRefreshRateChangedCallbackDebugEnabled failed %s",
1451 status.getDescription().c_str());
1452 return static_cast<Error>(status.getServiceSpecificError());
1453 }
1454 return Error::NONE;
1455}
1456
ramindani3acaaf52023-09-25 10:31:27 -07001457Error AidlComposer::notifyExpectedPresent(Display displayId, nsecs_t expectedPresentTime,
1458 int32_t frameIntervalNs) {
1459 const auto status =
1460 mAidlComposerClient->notifyExpectedPresent(translate<int64_t>(displayId),
1461 ClockMonotonicTimestamp{expectedPresentTime},
1462 frameIntervalNs);
1463
1464 if (!status.isOk()) {
1465 ALOGE("notifyExpectedPresent failed %s", status.getDescription().c_str());
1466 return static_cast<Error>(status.getServiceSpecificError());
1467 }
1468 return Error::NONE;
1469}
1470
Ady Abrahame7385f72021-09-05 00:54:25 -07001471Error AidlComposer::getClientTargetProperty(
Alec Mouri85065692022-03-18 00:58:26 +00001472 Display display, ClientTargetPropertyWithBrightness* outClientTargetProperty) {
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -04001473 Error error = Error::NONE;
1474 mMutex.lock_shared();
1475 if (auto reader = getReader(display)) {
1476 *outClientTargetProperty =
1477 reader->get().takeClientTargetProperty(translate<int64_t>(display));
1478 } else {
1479 error = Error::BAD_DISPLAY;
1480 }
1481 mMutex.unlock_shared();
1482 return error;
Ady Abrahame7385f72021-09-05 00:54:25 -07001483}
1484
Alec Mouri6da0e272022-02-07 12:45:57 -08001485Error AidlComposer::setLayerBrightness(Display display, Layer layer, float brightness) {
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -04001486 Error error = Error::NONE;
1487 mMutex.lock_shared();
1488 if (auto writer = getWriter(display)) {
1489 writer->get().setLayerBrightness(translate<int64_t>(display), translate<int64_t>(layer),
1490 brightness);
1491 } else {
1492 error = Error::BAD_DISPLAY;
1493 }
1494 mMutex.unlock_shared();
1495 return error;
Alec Mouricdf6cbc2021-11-01 17:21:15 -07001496}
1497
Leon Scroggins IIId77d3162022-01-05 10:42:28 -05001498Error AidlComposer::setLayerBlockingRegion(Display display, Layer layer,
1499 const std::vector<IComposerClient::Rect>& blocking) {
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -04001500 Error error = Error::NONE;
1501 mMutex.lock_shared();
1502 if (auto writer = getWriter(display)) {
1503 writer->get().setLayerBlockingRegion(translate<int64_t>(display), translate<int64_t>(layer),
1504 translate<AidlRect>(blocking));
1505 } else {
1506 error = Error::BAD_DISPLAY;
1507 }
1508 mMutex.unlock_shared();
1509 return error;
Leon Scroggins IIId77d3162022-01-05 10:42:28 -05001510}
Leon Scroggins IIIe7c51c62022-02-01 15:53:54 -05001511
1512Error AidlComposer::getDisplayDecorationSupport(Display display,
1513 std::optional<DisplayDecorationSupport>* support) {
1514 const auto status =
1515 mAidlComposerClient->getDisplayDecorationSupport(translate<int64_t>(display), support);
1516 if (!status.isOk()) {
1517 ALOGE("getDisplayDecorationSupport failed %s", status.getDescription().c_str());
1518 support->reset();
1519 return static_cast<Error>(status.getServiceSpecificError());
1520 }
1521 return Error::NONE;
1522}
ramindani32cf0602022-03-02 02:30:29 +00001523
1524Error AidlComposer::setIdleTimerEnabled(Display displayId, std::chrono::milliseconds timeout) {
1525 const auto status =
1526 mAidlComposerClient->setIdleTimerEnabled(translate<int64_t>(displayId),
1527 translate<int32_t>(timeout.count()));
1528 if (!status.isOk()) {
1529 ALOGE("setIdleTimerEnabled failed %s", status.getDescription().c_str());
1530 return static_cast<Error>(status.getServiceSpecificError());
1531 }
1532 return Error::NONE;
1533}
1534
ramindani06e518e2022-03-14 18:47:53 +00001535Error AidlComposer::getPhysicalDisplayOrientation(Display displayId,
1536 AidlTransform* outDisplayOrientation) {
1537 const auto status =
1538 mAidlComposerClient->getDisplayPhysicalOrientation(translate<int64_t>(displayId),
1539 outDisplayOrientation);
1540 if (!status.isOk()) {
1541 ALOGE("getPhysicalDisplayOrientation failed %s", status.getDescription().c_str());
1542 return static_cast<Error>(status.getServiceSpecificError());
1543 }
1544 return Error::NONE;
1545}
1546
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -04001547ftl::Optional<std::reference_wrapper<ComposerClientWriter>> AidlComposer::getWriter(Display display)
1548 REQUIRES_SHARED(mMutex) {
1549 return mWriters.get(display);
1550}
1551
1552ftl::Optional<std::reference_wrapper<ComposerClientReader>> AidlComposer::getReader(Display display)
1553 REQUIRES_SHARED(mMutex) {
1554 if (mSingleReader) {
1555 display = translate<Display>(kSingleReaderKey);
1556 }
1557 return mReaders.get(display);
1558}
1559
1560void AidlComposer::removeDisplay(Display display) {
1561 mMutex.lock();
1562 bool wasErased = mWriters.erase(display);
1563 ALOGW_IF(!wasErased,
1564 "Attempting to remove writer for display %" PRId64 " which is not connected",
1565 translate<int64_t>(display));
1566 if (!mSingleReader) {
1567 removeReader(display);
1568 }
1569 mMutex.unlock();
1570}
1571
1572void AidlComposer::onHotplugDisconnect(Display display) {
1573 removeDisplay(display);
1574}
1575
1576bool AidlComposer::hasMultiThreadedPresentSupport(Display display) {
Leon Scroggins IIIc1cf4582023-03-23 18:37:44 -04001577#if 0
1578 // TODO (b/259132483): Reenable
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -04001579 const auto displayId = translate<int64_t>(display);
1580 std::vector<AidlDisplayCapability> capabilities;
1581 const auto status = mAidlComposerClient->getDisplayCapabilities(displayId, &capabilities);
1582 if (!status.isOk()) {
1583 ALOGE("getDisplayCapabilities failed %s", status.getDescription().c_str());
1584 return false;
1585 }
1586 return std::find(capabilities.begin(), capabilities.end(),
1587 AidlDisplayCapability::MULTI_THREADED_PRESENT) != capabilities.end();
Leon Scroggins IIIc1cf4582023-03-23 18:37:44 -04001588#else
1589 (void) display;
1590 return false;
1591#endif
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -04001592}
1593
1594void AidlComposer::addReader(Display display) {
1595 const auto displayId = translate<int64_t>(display);
1596 std::optional<int64_t> displayOpt;
1597 if (displayId != kSingleReaderKey) {
1598 displayOpt.emplace(displayId);
1599 }
1600 auto [it, added] = mReaders.try_emplace(display, std::move(displayOpt));
1601 ALOGW_IF(!added, "Attempting to add writer for display %" PRId64 " which is already connected",
1602 displayId);
1603}
1604
1605void AidlComposer::removeReader(Display display) {
1606 bool wasErased = mReaders.erase(display);
1607 ALOGW_IF(!wasErased,
1608 "Attempting to remove reader for display %" PRId64 " which is not connected",
1609 translate<int64_t>(display));
1610}
1611
1612void AidlComposer::addDisplay(Display display) {
1613 const auto displayId = translate<int64_t>(display);
1614 mMutex.lock();
1615 auto [it, added] = mWriters.try_emplace(display, displayId);
1616 ALOGW_IF(!added, "Attempting to add writer for display %" PRId64 " which is already connected",
1617 displayId);
1618 if (mSingleReader) {
1619 if (hasMultiThreadedPresentSupport(display)) {
1620 mSingleReader = false;
1621 removeReader(translate<Display>(kSingleReaderKey));
1622 // Note that this includes the new display.
1623 for (const auto& [existingDisplay, _] : mWriters) {
1624 addReader(existingDisplay);
1625 }
1626 }
1627 } else {
1628 addReader(display);
1629 }
1630 mMutex.unlock();
1631}
1632
1633void AidlComposer::onHotplugConnect(Display display) {
1634 addDisplay(display);
1635}
Ady Abrahame7385f72021-09-05 00:54:25 -07001636} // namespace Hwc2
1637} // namespace android