blob: fa6db1000c00cd76e9a7475b8c46fc6695bc0124 [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"
Sally Qid57eb0d2023-11-07 16:46:15 -080022#include "FlagManager.h"
Ady Abrahame7385f72021-09-05 00:54:25 -070023
Brian Lindahl5b0ffe02023-06-15 14:19:43 -060024#include <SurfaceFlingerProperties.h>
Ady Abrahamc4acf512022-02-18 17:11:59 -080025#include <android-base/file.h>
Ady Abrahame7385f72021-09-05 00:54:25 -070026#include <android/binder_ibinder_platform.h>
27#include <android/binder_manager.h>
Leon Scroggins IIIe85e16e2022-12-12 12:51:18 -050028#include <gui/TraceUtils.h>
Ady Abrahame7385f72021-09-05 00:54:25 -070029#include <log/log.h>
30#include <utils/Trace.h>
31
32#include <aidl/android/hardware/graphics/composer3/BnComposerCallback.h>
33
34#include <algorithm>
35#include <cinttypes>
36
Yichi Chen3401b562022-01-17 15:42:35 +080037#include "HWC2.h"
38
Ady Abrahame7385f72021-09-05 00:54:25 -070039namespace android {
40
41using hardware::hidl_handle;
42using hardware::hidl_vec;
43using hardware::Return;
44
45using aidl::android::hardware::graphics::composer3::BnComposerCallback;
46using aidl::android::hardware::graphics::composer3::Capability;
Alec Mouri85065692022-03-18 00:58:26 +000047using aidl::android::hardware::graphics::composer3::ClientTargetPropertyWithBrightness;
Ady Abrahame7385f72021-09-05 00:54:25 -070048using aidl::android::hardware::graphics::composer3::PowerMode;
49using aidl::android::hardware::graphics::composer3::VirtualDisplay;
50
Ady Abraham42977362021-12-07 21:04:49 -080051using aidl::android::hardware::graphics::composer3::CommandResultPayload;
Ady Abrahama6388c02021-11-11 21:11:51 -080052
Ady Abrahame7385f72021-09-05 00:54:25 -070053using AidlColorMode = aidl::android::hardware::graphics::composer3::ColorMode;
54using AidlContentType = aidl::android::hardware::graphics::composer3::ContentType;
55using AidlDisplayIdentification =
56 aidl::android::hardware::graphics::composer3::DisplayIdentification;
57using AidlDisplayContentSample = aidl::android::hardware::graphics::composer3::DisplayContentSample;
58using AidlDisplayAttribute = aidl::android::hardware::graphics::composer3::DisplayAttribute;
59using AidlDisplayCapability = aidl::android::hardware::graphics::composer3::DisplayCapability;
Ady Abrahame7385f72021-09-05 00:54:25 -070060using AidlHdrCapabilities = aidl::android::hardware::graphics::composer3::HdrCapabilities;
Kriti Dang674b9372022-11-18 10:58:44 +010061using AidlHdrConversionCapability =
62 aidl::android::hardware::graphics::common::HdrConversionCapability;
63using AidlHdrConversionStrategy = aidl::android::hardware::graphics::common::HdrConversionStrategy;
Sally Qi0cbd08b2022-08-17 12:12:28 -070064using AidlOverlayProperties = aidl::android::hardware::graphics::composer3::OverlayProperties;
Ady Abrahame7385f72021-09-05 00:54:25 -070065using AidlPerFrameMetadata = aidl::android::hardware::graphics::composer3::PerFrameMetadata;
66using AidlPerFrameMetadataKey = aidl::android::hardware::graphics::composer3::PerFrameMetadataKey;
67using AidlPerFrameMetadataBlob = aidl::android::hardware::graphics::composer3::PerFrameMetadataBlob;
68using AidlRenderIntent = aidl::android::hardware::graphics::composer3::RenderIntent;
69using AidlVsyncPeriodChangeConstraints =
70 aidl::android::hardware::graphics::composer3::VsyncPeriodChangeConstraints;
71using AidlVsyncPeriodChangeTimeline =
72 aidl::android::hardware::graphics::composer3::VsyncPeriodChangeTimeline;
Ady Abrahame7385f72021-09-05 00:54:25 -070073using AidlDisplayContentSamplingAttributes =
74 aidl::android::hardware::graphics::composer3::DisplayContentSamplingAttributes;
75using AidlFormatColorComponent = aidl::android::hardware::graphics::composer3::FormatColorComponent;
76using AidlDisplayConnectionType =
77 aidl::android::hardware::graphics::composer3::DisplayConnectionType;
Ady Abrahame7385f72021-09-05 00:54:25 -070078
79using AidlColorTransform = aidl::android::hardware::graphics::common::ColorTransform;
80using AidlDataspace = aidl::android::hardware::graphics::common::Dataspace;
81using AidlFRect = aidl::android::hardware::graphics::common::FRect;
82using AidlRect = aidl::android::hardware::graphics::common::Rect;
83using AidlTransform = aidl::android::hardware::graphics::common::Transform;
84
85namespace Hwc2 {
86
87namespace {
88
89template <typename To, typename From>
90To translate(From x) {
91 return static_cast<To>(x);
92}
93
94template <typename To, typename From>
95std::vector<To> translate(const std::vector<From>& in) {
96 std::vector<To> out;
97 out.reserve(in.size());
98 std::transform(in.begin(), in.end(), std::back_inserter(out),
99 [](From x) { return translate<To>(x); });
100 return out;
101}
102
103template <>
104AidlRect translate(IComposerClient::Rect x) {
105 return AidlRect{
106 .left = x.left,
107 .top = x.top,
108 .right = x.right,
109 .bottom = x.bottom,
110 };
111}
112
113template <>
114AidlFRect translate(IComposerClient::FRect x) {
115 return AidlFRect{
116 .left = x.left,
117 .top = x.top,
118 .right = x.right,
119 .bottom = x.bottom,
120 };
121}
122
123template <>
Ady Abrahame7385f72021-09-05 00:54:25 -0700124AidlPerFrameMetadataBlob translate(IComposerClient::PerFrameMetadataBlob x) {
125 AidlPerFrameMetadataBlob blob;
126 blob.key = translate<AidlPerFrameMetadataKey>(x.key),
Long Linga4628782022-02-18 13:44:26 -0800127 std::copy(x.blob.begin(), x.blob.end(), std::inserter(blob.blob, blob.blob.end()));
Ady Abrahame7385f72021-09-05 00:54:25 -0700128 return blob;
129}
130
131template <>
132AidlPerFrameMetadata translate(IComposerClient::PerFrameMetadata x) {
133 return AidlPerFrameMetadata{
134 .key = translate<AidlPerFrameMetadataKey>(x.key),
135 .value = x.value,
136 };
137}
138
139template <>
140DisplayedFrameStats translate(AidlDisplayContentSample x) {
141 return DisplayedFrameStats{
142 .numFrames = static_cast<uint64_t>(x.frameCount),
143 .component_0_sample = translate<uint64_t>(x.sampleComponent0),
144 .component_1_sample = translate<uint64_t>(x.sampleComponent1),
145 .component_2_sample = translate<uint64_t>(x.sampleComponent2),
146 .component_3_sample = translate<uint64_t>(x.sampleComponent3),
147 };
148}
149
150template <>
151AidlVsyncPeriodChangeConstraints translate(IComposerClient::VsyncPeriodChangeConstraints x) {
152 return AidlVsyncPeriodChangeConstraints{
153 .desiredTimeNanos = x.desiredTimeNanos,
154 .seamlessRequired = x.seamlessRequired,
155 };
156}
157
158template <>
159VsyncPeriodChangeTimeline translate(AidlVsyncPeriodChangeTimeline x) {
160 return VsyncPeriodChangeTimeline{
161 .newVsyncAppliedTimeNanos = x.newVsyncAppliedTimeNanos,
162 .refreshRequired = x.refreshRequired,
163 .refreshTimeNanos = x.refreshTimeNanos,
164 };
165}
Ady Abrahame7385f72021-09-05 00:54:25 -0700166mat4 makeMat4(std::vector<float> in) {
167 return mat4(static_cast<const float*>(in.data()));
168}
169
170} // namespace
171
172class AidlIComposerCallbackWrapper : public BnComposerCallback {
173public:
Yichi Chen3401b562022-01-17 15:42:35 +0800174 AidlIComposerCallbackWrapper(HWC2::ComposerCallback& callback) : mCallback(callback) {}
Ady Abrahame7385f72021-09-05 00:54:25 -0700175
176 ::ndk::ScopedAStatus onHotplug(int64_t in_display, bool in_connected) override {
177 const auto connection = in_connected ? V2_4::IComposerCallback::Connection::CONNECTED
178 : V2_4::IComposerCallback::Connection::DISCONNECTED;
Yichi Chen3401b562022-01-17 15:42:35 +0800179 mCallback.onComposerHalHotplug(translate<Display>(in_display), connection);
Ady Abrahame7385f72021-09-05 00:54:25 -0700180 return ::ndk::ScopedAStatus::ok();
181 }
182
183 ::ndk::ScopedAStatus onRefresh(int64_t in_display) override {
Yichi Chen3401b562022-01-17 15:42:35 +0800184 mCallback.onComposerHalRefresh(translate<Display>(in_display));
Ady Abrahame7385f72021-09-05 00:54:25 -0700185 return ::ndk::ScopedAStatus::ok();
186 }
Yichi Chen3401b562022-01-17 15:42:35 +0800187
Ady Abrahame7385f72021-09-05 00:54:25 -0700188 ::ndk::ScopedAStatus onSeamlessPossible(int64_t in_display) override {
Yichi Chen3401b562022-01-17 15:42:35 +0800189 mCallback.onComposerHalSeamlessPossible(translate<Display>(in_display));
Ady Abrahame7385f72021-09-05 00:54:25 -0700190 return ::ndk::ScopedAStatus::ok();
191 }
Yichi Chen3401b562022-01-17 15:42:35 +0800192
Ady Abrahame7385f72021-09-05 00:54:25 -0700193 ::ndk::ScopedAStatus onVsync(int64_t in_display, int64_t in_timestamp,
194 int32_t in_vsyncPeriodNanos) override {
Yichi Chen3401b562022-01-17 15:42:35 +0800195 mCallback.onComposerHalVsync(translate<Display>(in_display), in_timestamp,
196 static_cast<uint32_t>(in_vsyncPeriodNanos));
Ady Abrahame7385f72021-09-05 00:54:25 -0700197 return ::ndk::ScopedAStatus::ok();
198 }
Yichi Chen3401b562022-01-17 15:42:35 +0800199
Ady Abrahame7385f72021-09-05 00:54:25 -0700200 ::ndk::ScopedAStatus onVsyncPeriodTimingChanged(
201 int64_t in_display, const AidlVsyncPeriodChangeTimeline& in_updatedTimeline) override {
Yichi Chen3401b562022-01-17 15:42:35 +0800202 mCallback.onComposerHalVsyncPeriodTimingChanged(translate<Display>(in_display),
203 translate<V2_4::VsyncPeriodChangeTimeline>(
204 in_updatedTimeline));
205 return ::ndk::ScopedAStatus::ok();
206 }
207
208 ::ndk::ScopedAStatus onVsyncIdle(int64_t in_display) override {
209 mCallback.onComposerHalVsyncIdle(translate<Display>(in_display));
Ady Abrahame7385f72021-09-05 00:54:25 -0700210 return ::ndk::ScopedAStatus::ok();
211 }
212
ramindani12bfe6b2023-02-03 13:29:19 -0800213 ::ndk::ScopedAStatus onRefreshRateChangedDebug(
214 const RefreshRateChangedDebugData& refreshRateChangedDebugData) override {
215 mCallback.onRefreshRateChangedDebug(refreshRateChangedDebugData);
216 return ::ndk::ScopedAStatus::ok();
217 }
218
Ady Abrahame7385f72021-09-05 00:54:25 -0700219private:
Yichi Chen3401b562022-01-17 15:42:35 +0800220 HWC2::ComposerCallback& mCallback;
Ady Abrahame7385f72021-09-05 00:54:25 -0700221};
222
Ady Abraham9fc28052021-10-14 17:21:38 -0700223std::string AidlComposer::instance(const std::string& serviceName) {
224 return std::string(AidlIComposer::descriptor) + "/" + serviceName;
225}
226
227bool AidlComposer::isDeclared(const std::string& serviceName) {
228 return AServiceManager_isDeclared(instance(serviceName).c_str());
229}
Ady Abrahame7385f72021-09-05 00:54:25 -0700230
Ady Abrahama6388c02021-11-11 21:11:51 -0800231AidlComposer::AidlComposer(const std::string& serviceName) {
Ady Abrahame7385f72021-09-05 00:54:25 -0700232 // This only waits if the service is actually declared
Ady Abraham9fc28052021-10-14 17:21:38 -0700233 mAidlComposer = AidlIComposer::fromBinder(
234 ndk::SpAIBinder(AServiceManager_waitForService(instance(serviceName).c_str())));
Ady Abrahame7385f72021-09-05 00:54:25 -0700235 if (!mAidlComposer) {
236 LOG_ALWAYS_FATAL("Failed to get AIDL composer service");
237 return;
238 }
239
240 if (!mAidlComposer->createClient(&mAidlComposerClient).isOk()) {
241 LOG_ALWAYS_FATAL("Can't create AidlComposerClient, fallback to HIDL");
242 return;
243 }
244
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400245 addReader(translate<Display>(kSingleReaderKey));
246
Brian Lindahldbf7e3a2022-12-16 11:43:39 -0700247 // If unable to read interface version, then become backwards compatible.
ramindani0cd1d8d2023-06-13 13:43:23 -0700248 const auto status = mAidlComposerClient->getInterfaceVersion(&mComposerInterfaceVersion);
Brian Lindahldbf7e3a2022-12-16 11:43:39 -0700249 if (!status.isOk()) {
250 ALOGE("getInterfaceVersion for AidlComposer constructor failed %s",
251 status.getDescription().c_str());
252 }
ramindani0cd1d8d2023-06-13 13:43:23 -0700253
254 if (mComposerInterfaceVersion <= 1) {
Brian Lindahl5b0ffe02023-06-15 14:19:43 -0600255 if (sysprop::clear_slots_with_set_layer_buffer(false)) {
256 mClearSlotBuffer = sp<GraphicBuffer>::make(1, 1, PIXEL_FORMAT_RGBX_8888,
257 GraphicBuffer::USAGE_HW_COMPOSER |
258 GraphicBuffer::USAGE_SW_READ_OFTEN |
259 GraphicBuffer::USAGE_SW_WRITE_OFTEN,
260 "AidlComposer");
261 if (!mClearSlotBuffer || mClearSlotBuffer->initCheck() != ::android::OK) {
262 LOG_ALWAYS_FATAL("Failed to allocate a buffer for clearing layer buffer slots");
263 return;
264 }
Brian Lindahldbf7e3a2022-12-16 11:43:39 -0700265 }
Brian Lindahl90553da2022-12-06 13:36:30 -0700266 }
267
Ady Abrahame7385f72021-09-05 00:54:25 -0700268 ALOGI("Loaded AIDL composer3 HAL service");
269}
270
271AidlComposer::~AidlComposer() = default;
272
Ady Abraham4d211cf2021-12-14 16:19:03 -0800273bool AidlComposer::isSupported(OptionalFeature feature) const {
274 switch (feature) {
275 case OptionalFeature::RefreshRateSwitching:
Ady Abraham43065bd2021-12-10 17:22:15 -0800276 case OptionalFeature::ExpectedPresentTime:
Alec Mouricdf16792021-12-10 13:16:06 -0800277 case OptionalFeature::DisplayBrightnessCommand:
ramindani32cf0602022-03-02 02:30:29 +0000278 case OptionalFeature::KernelIdleTimer:
ramindani06e518e2022-03-14 18:47:53 +0000279 case OptionalFeature::PhysicalDisplayOrientation:
Ady Abraham4d211cf2021-12-14 16:19:03 -0800280 return true;
281 }
282}
283
ramindani0cd1d8d2023-06-13 13:43:23 -0700284bool AidlComposer::getDisplayConfigurationsSupported() const {
Sally Qid57eb0d2023-11-07 16:46:15 -0800285 return mComposerInterfaceVersion >= 3 && FlagManager::getInstance().vrr_config();
ramindani0cd1d8d2023-06-13 13:43:23 -0700286}
287
Ady Abrahamde549d42022-01-26 19:19:17 -0800288std::vector<Capability> AidlComposer::getCapabilities() {
Ady Abrahame7385f72021-09-05 00:54:25 -0700289 std::vector<Capability> capabilities;
290 const auto status = mAidlComposer->getCapabilities(&capabilities);
291 if (!status.isOk()) {
292 ALOGE("getCapabilities failed %s", status.getDescription().c_str());
293 return {};
294 }
Ady Abrahamde549d42022-01-26 19:19:17 -0800295 return capabilities;
Ady Abrahame7385f72021-09-05 00:54:25 -0700296}
297
298std::string AidlComposer::dumpDebugInfo() {
Ady Abrahamc4acf512022-02-18 17:11:59 -0800299 int pipefds[2];
300 int result = pipe(pipefds);
301 if (result < 0) {
302 ALOGE("dumpDebugInfo: pipe failed: %s", strerror(errno));
Ady Abrahame7385f72021-09-05 00:54:25 -0700303 return {};
304 }
Ady Abrahamc4acf512022-02-18 17:11:59 -0800305
306 std::string str;
yihsing.shen58847c52022-09-23 15:39:30 +0800307 // Use other thread to read pipe to prevent
308 // pipe is full, making HWC be blocked in writing.
309 std::thread t([&]() {
310 base::ReadFdToString(pipefds[0], &str);
311 });
Ady Abrahamc4acf512022-02-18 17:11:59 -0800312 const auto status = mAidlComposer->dump(pipefds[1], /*args*/ nullptr, /*numArgs*/ 0);
313 // Close the write-end of the pipe to make sure that when reading from the
314 // read-end we will get eof instead of blocking forever
315 close(pipefds[1]);
316
yihsing.shen58847c52022-09-23 15:39:30 +0800317 if (status != STATUS_OK) {
Ady Abrahamc4acf512022-02-18 17:11:59 -0800318 ALOGE("dumpDebugInfo: dump failed: %d", status);
319 }
320
yihsing.shen58847c52022-09-23 15:39:30 +0800321 t.join();
Ady Abrahamc4acf512022-02-18 17:11:59 -0800322 close(pipefds[0]);
323 return str;
Ady Abrahame7385f72021-09-05 00:54:25 -0700324}
325
Yichi Chen3401b562022-01-17 15:42:35 +0800326void AidlComposer::registerCallback(HWC2::ComposerCallback& callback) {
Ady Abrahame7385f72021-09-05 00:54:25 -0700327 if (mAidlComposerCallback) {
328 ALOGE("Callback already registered");
329 }
Yichi Chen3401b562022-01-17 15:42:35 +0800330
Ady Abraham9fc28052021-10-14 17:21:38 -0700331 mAidlComposerCallback = ndk::SharedRefBase::make<AidlIComposerCallbackWrapper>(callback);
Ady Abrahame7385f72021-09-05 00:54:25 -0700332 AIBinder_setMinSchedulerPolicy(mAidlComposerCallback->asBinder().get(), SCHED_FIFO, 2);
333
334 const auto status = mAidlComposerClient->registerCallback(mAidlComposerCallback);
335 if (!status.isOk()) {
336 ALOGE("registerCallback failed %s", status.getDescription().c_str());
337 }
338}
339
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400340Error AidlComposer::executeCommands(Display display) {
341 mMutex.lock_shared();
342 auto error = execute(display);
343 mMutex.unlock_shared();
344 return error;
Ady Abrahame7385f72021-09-05 00:54:25 -0700345}
346
347uint32_t AidlComposer::getMaxVirtualDisplayCount() {
348 int32_t count = 0;
349 const auto status = mAidlComposerClient->getMaxVirtualDisplayCount(&count);
350 if (!status.isOk()) {
351 ALOGE("getMaxVirtualDisplayCount failed %s", status.getDescription().c_str());
352 return 0;
353 }
354 return static_cast<uint32_t>(count);
355}
356
357Error AidlComposer::createVirtualDisplay(uint32_t width, uint32_t height, PixelFormat* format,
358 Display* outDisplay) {
359 using AidlPixelFormat = aidl::android::hardware::graphics::common::PixelFormat;
360 const int32_t bufferSlotCount = 1;
361 VirtualDisplay virtualDisplay;
362 const auto status =
363 mAidlComposerClient->createVirtualDisplay(static_cast<int32_t>(width),
364 static_cast<int32_t>(height),
365 static_cast<AidlPixelFormat>(*format),
366 bufferSlotCount, &virtualDisplay);
367
368 if (!status.isOk()) {
369 ALOGE("createVirtualDisplay failed %s", status.getDescription().c_str());
370 return static_cast<Error>(status.getServiceSpecificError());
371 }
372
373 *outDisplay = translate<Display>(virtualDisplay.display);
374 *format = static_cast<PixelFormat>(virtualDisplay.format);
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400375 addDisplay(translate<Display>(virtualDisplay.display));
Ady Abrahame7385f72021-09-05 00:54:25 -0700376 return Error::NONE;
377}
378
379Error AidlComposer::destroyVirtualDisplay(Display display) {
380 const auto status = mAidlComposerClient->destroyVirtualDisplay(translate<int64_t>(display));
381 if (!status.isOk()) {
382 ALOGE("destroyVirtualDisplay failed %s", status.getDescription().c_str());
383 return static_cast<Error>(status.getServiceSpecificError());
384 }
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400385 removeDisplay(display);
Ady Abrahame7385f72021-09-05 00:54:25 -0700386 return Error::NONE;
387}
388
389Error AidlComposer::acceptDisplayChanges(Display display) {
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400390 Error error = Error::NONE;
391 mMutex.lock_shared();
392 if (auto writer = getWriter(display)) {
393 writer->get().acceptDisplayChanges(translate<int64_t>(display));
394 } else {
395 error = Error::BAD_DISPLAY;
396 }
397 mMutex.unlock_shared();
398 return error;
Ady Abrahame7385f72021-09-05 00:54:25 -0700399}
400
401Error AidlComposer::createLayer(Display display, Layer* outLayer) {
402 int64_t layer;
403 const auto status = mAidlComposerClient->createLayer(translate<int64_t>(display),
404 kMaxLayerBufferCount, &layer);
405 if (!status.isOk()) {
406 ALOGE("createLayer failed %s", status.getDescription().c_str());
407 return static_cast<Error>(status.getServiceSpecificError());
408 }
409
410 *outLayer = translate<Layer>(layer);
411 return Error::NONE;
412}
413
414Error AidlComposer::destroyLayer(Display display, Layer layer) {
415 const auto status = mAidlComposerClient->destroyLayer(translate<int64_t>(display),
416 translate<int64_t>(layer));
417 if (!status.isOk()) {
418 ALOGE("destroyLayer failed %s", status.getDescription().c_str());
419 return static_cast<Error>(status.getServiceSpecificError());
420 }
421 return Error::NONE;
422}
423
424Error AidlComposer::getActiveConfig(Display display, Config* outConfig) {
425 int32_t config;
426 const auto status = mAidlComposerClient->getActiveConfig(translate<int64_t>(display), &config);
427 if (!status.isOk()) {
428 ALOGE("getActiveConfig failed %s", status.getDescription().c_str());
429 return static_cast<Error>(status.getServiceSpecificError());
430 }
431 *outConfig = translate<Config>(config);
432 return Error::NONE;
433}
434
435Error AidlComposer::getChangedCompositionTypes(
436 Display display, std::vector<Layer>* outLayers,
Leon Scroggins III2e1aa182021-12-01 17:33:12 -0500437 std::vector<aidl::android::hardware::graphics::composer3::Composition>* outTypes) {
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400438 std::vector<ChangedCompositionLayer> changedLayers;
439 Error error = Error::NONE;
440 {
441 mMutex.lock_shared();
442 if (auto reader = getReader(display)) {
443 changedLayers = reader->get().takeChangedCompositionTypes(translate<int64_t>(display));
444 } else {
445 error = Error::BAD_DISPLAY;
446 }
447 mMutex.unlock_shared();
448 }
Ady Abrahamde792782021-12-20 10:00:49 -0800449 outLayers->reserve(changedLayers.size());
450 outTypes->reserve(changedLayers.size());
Ady Abrahama6388c02021-11-11 21:11:51 -0800451
Ady Abrahamde792782021-12-20 10:00:49 -0800452 for (const auto& layer : changedLayers) {
453 outLayers->emplace_back(translate<Layer>(layer.layer));
454 outTypes->emplace_back(layer.composition);
455 }
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400456 return error;
Ady Abrahame7385f72021-09-05 00:54:25 -0700457}
458
459Error AidlComposer::getColorModes(Display display, std::vector<ColorMode>* outModes) {
460 std::vector<AidlColorMode> modes;
461 const auto status = mAidlComposerClient->getColorModes(translate<int64_t>(display), &modes);
462 if (!status.isOk()) {
463 ALOGE("getColorModes failed %s", status.getDescription().c_str());
464 return static_cast<Error>(status.getServiceSpecificError());
465 }
466 *outModes = translate<ColorMode>(modes);
467 return Error::NONE;
468}
469
470Error AidlComposer::getDisplayAttribute(Display display, Config config,
471 IComposerClient::Attribute attribute, int32_t* outValue) {
472 const auto status =
473 mAidlComposerClient->getDisplayAttribute(translate<int64_t>(display),
474 translate<int32_t>(config),
475 static_cast<AidlDisplayAttribute>(attribute),
476 outValue);
477 if (!status.isOk()) {
478 ALOGE("getDisplayAttribute failed %s", status.getDescription().c_str());
479 return static_cast<Error>(status.getServiceSpecificError());
480 }
481 return Error::NONE;
482}
483
484Error AidlComposer::getDisplayConfigs(Display display, std::vector<Config>* outConfigs) {
485 std::vector<int32_t> configs;
486 const auto status =
487 mAidlComposerClient->getDisplayConfigs(translate<int64_t>(display), &configs);
488 if (!status.isOk()) {
489 ALOGE("getDisplayConfigs failed %s", status.getDescription().c_str());
490 return static_cast<Error>(status.getServiceSpecificError());
491 }
492 *outConfigs = translate<Config>(configs);
493 return Error::NONE;
494}
495
ramindani263a3f12023-07-18 20:44:49 -0700496Error AidlComposer::getDisplayConfigurations(Display display, int32_t maxFrameIntervalNs,
ramindani0cd1d8d2023-06-13 13:43:23 -0700497 std::vector<DisplayConfiguration>* outConfigs) {
498 const auto status =
ramindani263a3f12023-07-18 20:44:49 -0700499 mAidlComposerClient->getDisplayConfigurations(translate<int64_t>(display),
500 maxFrameIntervalNs, outConfigs);
ramindani0cd1d8d2023-06-13 13:43:23 -0700501 if (!status.isOk()) {
502 ALOGE("getDisplayConfigurations failed %s", status.getDescription().c_str());
503 return static_cast<Error>(status.getServiceSpecificError());
504 }
505
506 return Error::NONE;
507}
508
Ady Abrahame7385f72021-09-05 00:54:25 -0700509Error AidlComposer::getDisplayName(Display display, std::string* outName) {
510 const auto status = mAidlComposerClient->getDisplayName(translate<int64_t>(display), outName);
511 if (!status.isOk()) {
512 ALOGE("getDisplayName failed %s", status.getDescription().c_str());
513 return static_cast<Error>(status.getServiceSpecificError());
514 }
515 return Error::NONE;
516}
517
518Error AidlComposer::getDisplayRequests(Display display, uint32_t* outDisplayRequestMask,
519 std::vector<Layer>* outLayers,
520 std::vector<uint32_t>* outLayerRequestMasks) {
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400521 Error error = Error::NONE;
522 DisplayRequest displayRequests;
523 {
524 mMutex.lock_shared();
525 if (auto reader = getReader(display)) {
526 displayRequests = reader->get().takeDisplayRequests(translate<int64_t>(display));
527 } else {
528 error = Error::BAD_DISPLAY;
529 }
530 mMutex.unlock_shared();
531 }
Ady Abrahamde792782021-12-20 10:00:49 -0800532 *outDisplayRequestMask = translate<uint32_t>(displayRequests.mask);
533 outLayers->reserve(displayRequests.layerRequests.size());
534 outLayerRequestMasks->reserve(displayRequests.layerRequests.size());
535
536 for (const auto& layer : displayRequests.layerRequests) {
537 outLayers->emplace_back(translate<Layer>(layer.layer));
538 outLayerRequestMasks->emplace_back(translate<uint32_t>(layer.mask));
539 }
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400540 return error;
Ady Abrahame7385f72021-09-05 00:54:25 -0700541}
542
543Error AidlComposer::getDozeSupport(Display display, bool* outSupport) {
Ady Abraham33b92b92021-12-08 18:30:27 -0800544 std::vector<AidlDisplayCapability> capabilities;
Ady Abrahame7385f72021-09-05 00:54:25 -0700545 const auto status =
Ady Abraham33b92b92021-12-08 18:30:27 -0800546 mAidlComposerClient->getDisplayCapabilities(translate<int64_t>(display), &capabilities);
Ady Abrahame7385f72021-09-05 00:54:25 -0700547 if (!status.isOk()) {
Ady Abraham33b92b92021-12-08 18:30:27 -0800548 ALOGE("getDisplayCapabilities failed %s", status.getDescription().c_str());
Ady Abrahame7385f72021-09-05 00:54:25 -0700549 return static_cast<Error>(status.getServiceSpecificError());
550 }
Ady Abraham33b92b92021-12-08 18:30:27 -0800551 *outSupport = std::find(capabilities.begin(), capabilities.end(),
552 AidlDisplayCapability::DOZE) != capabilities.end();
Ady Abrahame7385f72021-09-05 00:54:25 -0700553 return Error::NONE;
554}
555
ramindani32cf0602022-03-02 02:30:29 +0000556Error AidlComposer::hasDisplayIdleTimerCapability(Display display, bool* outSupport) {
557 std::vector<AidlDisplayCapability> capabilities;
558 const auto status =
559 mAidlComposerClient->getDisplayCapabilities(translate<int64_t>(display), &capabilities);
560 if (!status.isOk()) {
561 ALOGE("getDisplayCapabilities failed %s", status.getDescription().c_str());
562 return static_cast<Error>(status.getServiceSpecificError());
563 }
564 *outSupport = std::find(capabilities.begin(), capabilities.end(),
565 AidlDisplayCapability::DISPLAY_IDLE_TIMER) != capabilities.end();
566 return Error::NONE;
567}
568
Ady Abrahame7385f72021-09-05 00:54:25 -0700569Error AidlComposer::getHdrCapabilities(Display display, std::vector<Hdr>* outTypes,
570 float* outMaxLuminance, float* outMaxAverageLuminance,
571 float* outMinLuminance) {
572 AidlHdrCapabilities capabilities;
573 const auto status =
574 mAidlComposerClient->getHdrCapabilities(translate<int64_t>(display), &capabilities);
575 if (!status.isOk()) {
576 ALOGE("getHdrCapabilities failed %s", status.getDescription().c_str());
577 return static_cast<Error>(status.getServiceSpecificError());
578 }
579
Marc Kassisbdf7e4b2022-11-04 17:26:48 +0100580 *outTypes = capabilities.types;
Ady Abrahame7385f72021-09-05 00:54:25 -0700581 *outMaxLuminance = capabilities.maxLuminance;
582 *outMaxAverageLuminance = capabilities.maxAverageLuminance;
583 *outMinLuminance = capabilities.minLuminance;
584 return Error::NONE;
585}
586
Sally Qibb866c12022-10-17 11:31:20 -0700587Error AidlComposer::getOverlaySupport(AidlOverlayProperties* outProperties) {
588 const auto status = mAidlComposerClient->getOverlaySupport(outProperties);
589 if (!status.isOk()) {
590 ALOGE("getOverlaySupport failed %s", status.getDescription().c_str());
591 return static_cast<Error>(status.getServiceSpecificError());
592 }
Sally Qi0cbd08b2022-08-17 12:12:28 -0700593 return Error::NONE;
594}
595
Ady Abrahame7385f72021-09-05 00:54:25 -0700596Error AidlComposer::getReleaseFences(Display display, std::vector<Layer>* outLayers,
597 std::vector<int>* outReleaseFences) {
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400598 Error error = Error::NONE;
599 std::vector<ReleaseFences::Layer> fences;
600 {
601 mMutex.lock_shared();
602 if (auto reader = getReader(display)) {
603 fences = reader->get().takeReleaseFences(translate<int64_t>(display));
604 } else {
605 error = Error::BAD_DISPLAY;
606 }
607 mMutex.unlock_shared();
608 }
Ady Abrahamde792782021-12-20 10:00:49 -0800609 outLayers->reserve(fences.size());
610 outReleaseFences->reserve(fences.size());
611
612 for (auto& fence : fences) {
613 outLayers->emplace_back(translate<Layer>(fence.layer));
614 // take ownership
615 const int fenceOwner = fence.fence.get();
616 *fence.fence.getR() = -1;
617 outReleaseFences->emplace_back(fenceOwner);
618 }
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400619 return error;
Ady Abrahame7385f72021-09-05 00:54:25 -0700620}
621
622Error AidlComposer::presentDisplay(Display display, int* outPresentFence) {
Leon Scroggins IIIe85e16e2022-12-12 12:51:18 -0500623 const auto displayId = translate<int64_t>(display);
624 ATRACE_FORMAT("HwcPresentDisplay %" PRId64, displayId);
625
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400626 Error error = Error::NONE;
627 mMutex.lock_shared();
628 auto writer = getWriter(display);
629 auto reader = getReader(display);
630 if (writer && reader) {
Leon Scroggins IIIe85e16e2022-12-12 12:51:18 -0500631 writer->get().presentDisplay(displayId);
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400632 error = execute(display);
633 } else {
634 error = Error::BAD_DISPLAY;
635 }
Ady Abrahame7385f72021-09-05 00:54:25 -0700636
Ady Abrahame7385f72021-09-05 00:54:25 -0700637 if (error != Error::NONE) {
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400638 mMutex.unlock_shared();
Ady Abrahame7385f72021-09-05 00:54:25 -0700639 return error;
640 }
641
Leon Scroggins IIIe85e16e2022-12-12 12:51:18 -0500642 auto fence = reader->get().takePresentFence(displayId);
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400643 mMutex.unlock_shared();
Ady Abrahamde792782021-12-20 10:00:49 -0800644 // take ownership
645 *outPresentFence = fence.get();
646 *fence.getR() = -1;
Ady Abrahame7385f72021-09-05 00:54:25 -0700647 return Error::NONE;
648}
649
650Error AidlComposer::setActiveConfig(Display display, Config config) {
651 const auto status = mAidlComposerClient->setActiveConfig(translate<int64_t>(display),
652 translate<int32_t>(config));
653 if (!status.isOk()) {
654 ALOGE("setActiveConfig failed %s", status.getDescription().c_str());
655 return static_cast<Error>(status.getServiceSpecificError());
656 }
657 return Error::NONE;
658}
659
660Error AidlComposer::setClientTarget(Display display, uint32_t slot, const sp<GraphicBuffer>& target,
661 int acquireFence, Dataspace dataspace,
662 const std::vector<IComposerClient::Rect>& damage) {
Ady Abrahame7385f72021-09-05 00:54:25 -0700663 const native_handle_t* handle = nullptr;
664 if (target.get()) {
665 handle = target->getNativeBuffer()->handle;
666 }
667
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400668 Error error = Error::NONE;
669 mMutex.lock_shared();
670 if (auto writer = getWriter(display)) {
671 writer->get()
672 .setClientTarget(translate<int64_t>(display), slot, handle, acquireFence,
673 translate<aidl::android::hardware::graphics::common::Dataspace>(
674 dataspace),
675 translate<AidlRect>(damage));
676 } else {
677 error = Error::BAD_DISPLAY;
678 }
679 mMutex.unlock_shared();
680 return error;
Ady Abrahame7385f72021-09-05 00:54:25 -0700681}
682
683Error AidlComposer::setColorMode(Display display, ColorMode mode, RenderIntent renderIntent) {
684 const auto status =
685 mAidlComposerClient->setColorMode(translate<int64_t>(display),
686 translate<AidlColorMode>(mode),
687 translate<AidlRenderIntent>(renderIntent));
688 if (!status.isOk()) {
689 ALOGE("setColorMode failed %s", status.getDescription().c_str());
690 return static_cast<Error>(status.getServiceSpecificError());
691 }
692 return Error::NONE;
693}
694
Ady Abrahamdc011a92021-12-21 14:06:44 -0800695Error AidlComposer::setColorTransform(Display display, const float* matrix) {
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400696 auto error = Error::NONE;
697 mMutex.lock_shared();
698 if (auto writer = getWriter(display)) {
699 writer->get().setColorTransform(translate<int64_t>(display), matrix);
700 } else {
701 error = Error::BAD_DISPLAY;
702 }
703 mMutex.unlock_shared();
704 return error;
Ady Abrahame7385f72021-09-05 00:54:25 -0700705}
706
707Error AidlComposer::setOutputBuffer(Display display, const native_handle_t* buffer,
708 int releaseFence) {
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400709 auto error = Error::NONE;
710 mMutex.lock_shared();
711 if (auto writer = getWriter(display)) {
712 writer->get().setOutputBuffer(translate<int64_t>(display), 0, buffer, dup(releaseFence));
713 } else {
714 error = Error::BAD_DISPLAY;
715 }
716 mMutex.unlock_shared();
717 return error;
Ady Abrahame7385f72021-09-05 00:54:25 -0700718}
719
720Error AidlComposer::setPowerMode(Display display, IComposerClient::PowerMode mode) {
721 const auto status = mAidlComposerClient->setPowerMode(translate<int64_t>(display),
722 translate<PowerMode>(mode));
723 if (!status.isOk()) {
724 ALOGE("setPowerMode failed %s", status.getDescription().c_str());
725 return static_cast<Error>(status.getServiceSpecificError());
726 }
727 return Error::NONE;
728}
729
730Error AidlComposer::setVsyncEnabled(Display display, IComposerClient::Vsync enabled) {
731 const bool enableVsync = enabled == IComposerClient::Vsync::ENABLE;
732 const auto status =
733 mAidlComposerClient->setVsyncEnabled(translate<int64_t>(display), enableVsync);
734 if (!status.isOk()) {
735 ALOGE("setVsyncEnabled failed %s", status.getDescription().c_str());
736 return static_cast<Error>(status.getServiceSpecificError());
737 }
738 return Error::NONE;
739}
740
741Error AidlComposer::setClientTargetSlotCount(Display display) {
742 const int32_t bufferSlotCount = BufferQueue::NUM_BUFFER_SLOTS;
743 const auto status = mAidlComposerClient->setClientTargetSlotCount(translate<int64_t>(display),
744 bufferSlotCount);
745 if (!status.isOk()) {
746 ALOGE("setClientTargetSlotCount failed %s", status.getDescription().c_str());
747 return static_cast<Error>(status.getServiceSpecificError());
748 }
749 return Error::NONE;
750}
751
Ady Abraham43065bd2021-12-10 17:22:15 -0800752Error AidlComposer::validateDisplay(Display display, nsecs_t expectedPresentTime,
753 uint32_t* outNumTypes, 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) {
762 writer->get().validateDisplay(displayId, ClockMonotonicTimestamp{expectedPresentTime});
763 error = execute(display);
764 } else {
765 error = Error::BAD_DISPLAY;
766 }
Ady Abrahame7385f72021-09-05 00:54:25 -0700767
Ady Abrahame7385f72021-09-05 00:54:25 -0700768 if (error != Error::NONE) {
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400769 mMutex.unlock_shared();
Ady Abrahame7385f72021-09-05 00:54:25 -0700770 return error;
771 }
772
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400773 reader->get().hasChanges(displayId, outNumTypes, outNumRequests);
Ady Abrahame7385f72021-09-05 00:54:25 -0700774
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400775 mMutex.unlock_shared();
Ady Abrahame7385f72021-09-05 00:54:25 -0700776 return Error::NONE;
777}
778
Ady Abraham43065bd2021-12-10 17:22:15 -0800779Error AidlComposer::presentOrValidateDisplay(Display display, nsecs_t expectedPresentTime,
780 uint32_t* outNumTypes, uint32_t* outNumRequests,
781 int* outPresentFence, uint32_t* state) {
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400782 const auto displayId = translate<int64_t>(display);
Leon Scroggins IIIe85e16e2022-12-12 12:51:18 -0500783 ATRACE_FORMAT("HwcPresentOrValidateDisplay %" PRId64, displayId);
784
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400785 Error error = Error::NONE;
786 mMutex.lock_shared();
787 auto writer = getWriter(display);
788 auto reader = getReader(display);
789 if (writer && reader) {
790 writer->get().presentOrvalidateDisplay(displayId,
791 ClockMonotonicTimestamp{expectedPresentTime});
792 error = execute(display);
793 } else {
794 error = Error::BAD_DISPLAY;
795 }
Ady Abrahame7385f72021-09-05 00:54:25 -0700796
Ady Abrahame7385f72021-09-05 00:54:25 -0700797 if (error != Error::NONE) {
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400798 mMutex.unlock_shared();
Ady Abrahame7385f72021-09-05 00:54:25 -0700799 return error;
800 }
801
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400802 const auto result = reader->get().takePresentOrValidateStage(displayId);
Ady Abrahamde792782021-12-20 10:00:49 -0800803 if (!result.has_value()) {
804 *state = translate<uint32_t>(-1);
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400805 mMutex.unlock_shared();
Ady Abrahamde792782021-12-20 10:00:49 -0800806 return Error::NO_RESOURCES;
Ady Abrahame7385f72021-09-05 00:54:25 -0700807 }
808
Ady Abrahamde792782021-12-20 10:00:49 -0800809 *state = translate<uint32_t>(*result);
810
811 if (*result == PresentOrValidate::Result::Presented) {
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400812 auto fence = reader->get().takePresentFence(displayId);
Ady Abrahamde792782021-12-20 10:00:49 -0800813 // take ownership
814 *outPresentFence = fence.get();
815 *fence.getR() = -1;
816 }
817
818 if (*result == PresentOrValidate::Result::Validated) {
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400819 reader->get().hasChanges(displayId, outNumTypes, outNumRequests);
Ady Abrahame7385f72021-09-05 00:54:25 -0700820 }
821
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400822 mMutex.unlock_shared();
Ady Abrahame7385f72021-09-05 00:54:25 -0700823 return Error::NONE;
824}
825
826Error AidlComposer::setCursorPosition(Display display, Layer layer, int32_t x, int32_t y) {
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400827 Error error = Error::NONE;
828 mMutex.lock_shared();
829 if (auto writer = getWriter(display)) {
830 writer->get().setLayerCursorPosition(translate<int64_t>(display), translate<int64_t>(layer),
831 x, y);
832 } else {
833 error = Error::BAD_DISPLAY;
834 }
835 mMutex.unlock_shared();
836 return error;
Ady Abrahame7385f72021-09-05 00:54:25 -0700837}
838
839Error AidlComposer::setLayerBuffer(Display display, Layer layer, uint32_t slot,
840 const sp<GraphicBuffer>& buffer, int acquireFence) {
Ady Abrahame7385f72021-09-05 00:54:25 -0700841 const native_handle_t* handle = nullptr;
842 if (buffer.get()) {
843 handle = buffer->getNativeBuffer()->handle;
844 }
845
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400846 Error error = Error::NONE;
847 mMutex.lock_shared();
848 if (auto writer = getWriter(display)) {
849 writer->get().setLayerBuffer(translate<int64_t>(display), translate<int64_t>(layer), slot,
850 handle, acquireFence);
851 } else {
852 error = Error::BAD_DISPLAY;
853 }
854 mMutex.unlock_shared();
855 return error;
Ady Abrahame7385f72021-09-05 00:54:25 -0700856}
857
Brian Lindahlb158a5c2022-12-15 15:21:13 -0700858Error AidlComposer::setLayerBufferSlotsToClear(Display display, Layer layer,
859 const std::vector<uint32_t>& slotsToClear,
860 uint32_t activeBufferSlot) {
861 if (slotsToClear.empty()) {
862 return Error::NONE;
863 }
864
Brian Lindahl90553da2022-12-06 13:36:30 -0700865 Error error = Error::NONE;
866 mMutex.lock_shared();
867 if (auto writer = getWriter(display)) {
ramindani0cd1d8d2023-06-13 13:43:23 -0700868 if (mComposerInterfaceVersion > 1) {
Brian Lindahldbf7e3a2022-12-16 11:43:39 -0700869 writer->get().setLayerBufferSlotsToClear(translate<int64_t>(display),
870 translate<int64_t>(layer), slotsToClear);
Brian Lindahl5b0ffe02023-06-15 14:19:43 -0600871 // Backwards compatible way of clearing buffer slots is to set the layer buffer with a
872 // placeholder buffer, using the slot that needs to cleared... tricky.
873 } else if (mClearSlotBuffer != nullptr) {
Brian Lindahldbf7e3a2022-12-16 11:43:39 -0700874 for (uint32_t slot : slotsToClear) {
875 // Don't clear the active buffer slot because we need to restore the active buffer
876 // after clearing the requested buffer slots with a placeholder buffer.
877 if (slot != activeBufferSlot) {
878 writer->get().setLayerBufferWithNewCommand(translate<int64_t>(display),
879 translate<int64_t>(layer), slot,
880 mClearSlotBuffer->handle,
881 /*fence*/ -1);
882 }
Brian Lindahlb158a5c2022-12-15 15:21:13 -0700883 }
Brian Lindahldbf7e3a2022-12-16 11:43:39 -0700884 // Since we clear buffers by setting them to a placeholder buffer, we want to make
885 // sure that the last setLayerBuffer command is sent with the currently active
886 // buffer, not the placeholder buffer, so that there is no perceptual change when
887 // buffers are discarded.
888 writer->get().setLayerBufferWithNewCommand(translate<int64_t>(display),
889 translate<int64_t>(layer), activeBufferSlot,
890 // The active buffer is still cached in
891 // its slot and doesn't need a fence.
892 /*buffer*/ nullptr, /*fence*/ -1);
Brian Lindahlb158a5c2022-12-15 15:21:13 -0700893 }
Brian Lindahl90553da2022-12-06 13:36:30 -0700894 } else {
895 error = Error::BAD_DISPLAY;
896 }
897 mMutex.unlock_shared();
898 return error;
899}
900
Ady Abrahame7385f72021-09-05 00:54:25 -0700901Error AidlComposer::setLayerSurfaceDamage(Display display, Layer layer,
902 const std::vector<IComposerClient::Rect>& damage) {
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400903 Error error = Error::NONE;
904 mMutex.lock_shared();
905 if (auto writer = getWriter(display)) {
906 writer->get().setLayerSurfaceDamage(translate<int64_t>(display), translate<int64_t>(layer),
907 translate<AidlRect>(damage));
908 } else {
909 error = Error::BAD_DISPLAY;
910 }
911 mMutex.unlock_shared();
912 return error;
Ady Abrahame7385f72021-09-05 00:54:25 -0700913}
914
915Error AidlComposer::setLayerBlendMode(Display display, Layer layer,
916 IComposerClient::BlendMode mode) {
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400917 Error error = Error::NONE;
918 mMutex.lock_shared();
919 if (auto writer = getWriter(display)) {
920 writer->get().setLayerBlendMode(translate<int64_t>(display), translate<int64_t>(layer),
921 translate<BlendMode>(mode));
922 } else {
923 error = Error::BAD_DISPLAY;
924 }
925 mMutex.unlock_shared();
926 return error;
Ady Abrahame7385f72021-09-05 00:54:25 -0700927}
928
Ady Abraham6e60b142022-01-06 18:10:35 -0800929Error AidlComposer::setLayerColor(Display display, Layer layer, const Color& color) {
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400930 Error error = Error::NONE;
931 mMutex.lock_shared();
932 if (auto writer = getWriter(display)) {
933 writer->get().setLayerColor(translate<int64_t>(display), translate<int64_t>(layer), color);
934 } else {
935 error = Error::BAD_DISPLAY;
936 }
937 mMutex.unlock_shared();
938 return error;
Ady Abrahame7385f72021-09-05 00:54:25 -0700939}
940
Leon Scroggins III2e1aa182021-12-01 17:33:12 -0500941Error AidlComposer::setLayerCompositionType(
942 Display display, Layer layer,
943 aidl::android::hardware::graphics::composer3::Composition type) {
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400944 Error error = Error::NONE;
945 mMutex.lock_shared();
946 if (auto writer = getWriter(display)) {
947 writer->get().setLayerCompositionType(translate<int64_t>(display),
948 translate<int64_t>(layer), type);
949 } else {
950 error = Error::BAD_DISPLAY;
951 }
952 mMutex.unlock_shared();
953 return error;
Ady Abrahame7385f72021-09-05 00:54:25 -0700954}
955
956Error AidlComposer::setLayerDataspace(Display display, Layer layer, Dataspace dataspace) {
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400957 Error error = Error::NONE;
958 mMutex.lock_shared();
959 if (auto writer = getWriter(display)) {
960 writer->get().setLayerDataspace(translate<int64_t>(display), translate<int64_t>(layer),
961 translate<AidlDataspace>(dataspace));
962 } else {
963 error = Error::BAD_DISPLAY;
964 }
965 mMutex.unlock_shared();
966 return error;
Ady Abrahame7385f72021-09-05 00:54:25 -0700967}
968
969Error AidlComposer::setLayerDisplayFrame(Display display, Layer layer,
970 const IComposerClient::Rect& frame) {
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400971 Error error = Error::NONE;
972 mMutex.lock_shared();
973 if (auto writer = getWriter(display)) {
974 writer->get().setLayerDisplayFrame(translate<int64_t>(display), translate<int64_t>(layer),
975 translate<AidlRect>(frame));
976 } else {
977 error = Error::BAD_DISPLAY;
978 }
979 mMutex.unlock_shared();
980 return error;
Ady Abrahame7385f72021-09-05 00:54:25 -0700981}
982
983Error AidlComposer::setLayerPlaneAlpha(Display display, Layer layer, float alpha) {
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400984 Error error = Error::NONE;
985 mMutex.lock_shared();
986 if (auto writer = getWriter(display)) {
987 writer->get().setLayerPlaneAlpha(translate<int64_t>(display), translate<int64_t>(layer),
988 alpha);
989 } else {
990 error = Error::BAD_DISPLAY;
991 }
992 mMutex.unlock_shared();
993 return error;
Ady Abrahame7385f72021-09-05 00:54:25 -0700994}
995
996Error AidlComposer::setLayerSidebandStream(Display display, Layer layer,
997 const native_handle_t* stream) {
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400998 Error error = Error::NONE;
999 mMutex.lock_shared();
1000 if (auto writer = getWriter(display)) {
1001 writer->get().setLayerSidebandStream(translate<int64_t>(display), translate<int64_t>(layer),
1002 stream);
1003 } else {
1004 error = Error::BAD_DISPLAY;
1005 }
1006 mMutex.unlock_shared();
1007 return error;
Ady Abrahame7385f72021-09-05 00:54:25 -07001008}
1009
1010Error AidlComposer::setLayerSourceCrop(Display display, Layer layer,
1011 const IComposerClient::FRect& crop) {
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -04001012 Error error = Error::NONE;
1013 mMutex.lock_shared();
1014 if (auto writer = getWriter(display)) {
1015 writer->get().setLayerSourceCrop(translate<int64_t>(display), translate<int64_t>(layer),
1016 translate<AidlFRect>(crop));
1017 } else {
1018 error = Error::BAD_DISPLAY;
1019 }
1020 mMutex.unlock_shared();
1021 return error;
Ady Abrahame7385f72021-09-05 00:54:25 -07001022}
1023
1024Error AidlComposer::setLayerTransform(Display display, Layer layer, Transform transform) {
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -04001025 Error error = Error::NONE;
1026 mMutex.lock_shared();
1027 if (auto writer = getWriter(display)) {
1028 writer->get().setLayerTransform(translate<int64_t>(display), translate<int64_t>(layer),
1029 translate<AidlTransform>(transform));
1030 } else {
1031 error = Error::BAD_DISPLAY;
1032 }
1033 mMutex.unlock_shared();
1034 return error;
Ady Abrahame7385f72021-09-05 00:54:25 -07001035}
1036
1037Error AidlComposer::setLayerVisibleRegion(Display display, Layer layer,
1038 const std::vector<IComposerClient::Rect>& visible) {
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -04001039 Error error = Error::NONE;
1040 mMutex.lock_shared();
1041 if (auto writer = getWriter(display)) {
1042 writer->get().setLayerVisibleRegion(translate<int64_t>(display), translate<int64_t>(layer),
1043 translate<AidlRect>(visible));
1044 } else {
1045 error = Error::BAD_DISPLAY;
1046 }
1047 mMutex.unlock_shared();
1048 return error;
Ady Abrahame7385f72021-09-05 00:54:25 -07001049}
1050
1051Error AidlComposer::setLayerZOrder(Display display, Layer layer, uint32_t z) {
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -04001052 Error error = Error::NONE;
1053 mMutex.lock_shared();
1054 if (auto writer = getWriter(display)) {
1055 writer->get().setLayerZOrder(translate<int64_t>(display), translate<int64_t>(layer), z);
1056 } else {
1057 error = Error::BAD_DISPLAY;
1058 }
1059 mMutex.unlock_shared();
1060 return error;
Ady Abrahame7385f72021-09-05 00:54:25 -07001061}
1062
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -04001063Error AidlComposer::execute(Display display) {
1064 auto writer = getWriter(display);
1065 auto reader = getReader(display);
1066 if (!writer || !reader) {
1067 return Error::BAD_DISPLAY;
1068 }
1069
Huihong Luoe7382c12023-04-21 20:24:32 +00001070 auto commands = writer->get().takePendingCommands();
Ady Abrahama6388c02021-11-11 21:11:51 -08001071 if (commands.empty()) {
Ady Abrahame7385f72021-09-05 00:54:25 -07001072 return Error::NONE;
1073 }
1074
Ady Abrahamde792782021-12-20 10:00:49 -08001075 { // scope for results
1076 std::vector<CommandResultPayload> results;
1077 auto status = mAidlComposerClient->executeCommands(commands, &results);
1078 if (!status.isOk()) {
1079 ALOGE("executeCommands failed %s", status.getDescription().c_str());
1080 return static_cast<Error>(status.getServiceSpecificError());
1081 }
Ady Abrahame7385f72021-09-05 00:54:25 -07001082
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -04001083 reader->get().parse(std::move(results));
Ady Abrahamde792782021-12-20 10:00:49 -08001084 }
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -04001085 const auto commandErrors = reader->get().takeErrors();
Ady Abrahama6388c02021-11-11 21:11:51 -08001086 Error error = Error::NONE;
1087 for (const auto& cmdErr : commandErrors) {
1088 const auto index = static_cast<size_t>(cmdErr.commandIndex);
1089 if (index < 0 || index >= commands.size()) {
1090 ALOGE("invalid command index %zu", index);
1091 return Error::BAD_PARAMETER;
Ady Abrahame7385f72021-09-05 00:54:25 -07001092 }
1093
Ady Abrahama6388c02021-11-11 21:11:51 -08001094 const auto& command = commands[index];
Ady Abraham42977362021-12-07 21:04:49 -08001095 if (command.validateDisplay || command.presentDisplay || command.presentOrValidateDisplay) {
1096 error = translate<Error>(cmdErr.errorCode);
1097 } else {
1098 ALOGW("command '%s' generated error %" PRId32, command.toString().c_str(),
1099 cmdErr.errorCode);
Ady Abrahame7385f72021-09-05 00:54:25 -07001100 }
1101 }
1102
Ady Abrahame7385f72021-09-05 00:54:25 -07001103 return error;
1104}
1105
1106Error AidlComposer::setLayerPerFrameMetadata(
1107 Display display, Layer layer,
1108 const std::vector<IComposerClient::PerFrameMetadata>& perFrameMetadatas) {
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -04001109 Error error = Error::NONE;
1110 mMutex.lock_shared();
1111 if (auto writer = getWriter(display)) {
1112 writer->get().setLayerPerFrameMetadata(translate<int64_t>(display),
1113 translate<int64_t>(layer),
1114 translate<AidlPerFrameMetadata>(perFrameMetadatas));
1115 } else {
1116 error = Error::BAD_DISPLAY;
1117 }
1118 mMutex.unlock_shared();
1119 return error;
Ady Abrahame7385f72021-09-05 00:54:25 -07001120}
1121
1122std::vector<IComposerClient::PerFrameMetadataKey> AidlComposer::getPerFrameMetadataKeys(
1123 Display display) {
1124 std::vector<AidlPerFrameMetadataKey> keys;
1125 const auto status =
1126 mAidlComposerClient->getPerFrameMetadataKeys(translate<int64_t>(display), &keys);
1127 if (!status.isOk()) {
1128 ALOGE("getPerFrameMetadataKeys failed %s", status.getDescription().c_str());
1129 return {};
1130 }
1131 return translate<IComposerClient::PerFrameMetadataKey>(keys);
1132}
1133
1134Error AidlComposer::getRenderIntents(Display display, ColorMode colorMode,
1135 std::vector<RenderIntent>* outRenderIntents) {
1136 std::vector<AidlRenderIntent> renderIntents;
1137 const auto status = mAidlComposerClient->getRenderIntents(translate<int64_t>(display),
1138 translate<AidlColorMode>(colorMode),
1139 &renderIntents);
1140 if (!status.isOk()) {
1141 ALOGE("getRenderIntents failed %s", status.getDescription().c_str());
1142 return static_cast<Error>(status.getServiceSpecificError());
1143 }
1144 *outRenderIntents = translate<RenderIntent>(renderIntents);
1145 return Error::NONE;
1146}
1147
1148Error AidlComposer::getDataspaceSaturationMatrix(Dataspace dataspace, mat4* outMatrix) {
1149 std::vector<float> matrix;
1150 const auto status =
1151 mAidlComposerClient->getDataspaceSaturationMatrix(translate<AidlDataspace>(dataspace),
1152 &matrix);
1153 if (!status.isOk()) {
1154 ALOGE("getDataspaceSaturationMatrix failed %s", status.getDescription().c_str());
1155 return static_cast<Error>(status.getServiceSpecificError());
1156 }
1157 *outMatrix = makeMat4(matrix);
1158 return Error::NONE;
1159}
1160
1161Error AidlComposer::getDisplayIdentificationData(Display display, uint8_t* outPort,
1162 std::vector<uint8_t>* outData) {
1163 AidlDisplayIdentification displayIdentification;
1164 const auto status =
1165 mAidlComposerClient->getDisplayIdentificationData(translate<int64_t>(display),
1166 &displayIdentification);
1167 if (!status.isOk()) {
1168 ALOGE("getDisplayIdentificationData failed %s", status.getDescription().c_str());
1169 return static_cast<Error>(status.getServiceSpecificError());
1170 }
1171
1172 *outPort = static_cast<uint8_t>(displayIdentification.port);
1173 *outData = displayIdentification.data;
1174
1175 return Error::NONE;
1176}
1177
1178Error AidlComposer::setLayerColorTransform(Display display, Layer layer, const float* matrix) {
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -04001179 Error error = Error::NONE;
1180 mMutex.lock_shared();
1181 if (auto writer = getWriter(display)) {
1182 writer->get().setLayerColorTransform(translate<int64_t>(display), translate<int64_t>(layer),
1183 matrix);
1184 } else {
1185 error = Error::BAD_DISPLAY;
1186 }
1187 mMutex.unlock_shared();
1188 return error;
Ady Abrahame7385f72021-09-05 00:54:25 -07001189}
1190
1191Error AidlComposer::getDisplayedContentSamplingAttributes(Display display, PixelFormat* outFormat,
1192 Dataspace* outDataspace,
1193 uint8_t* outComponentMask) {
1194 if (!outFormat || !outDataspace || !outComponentMask) {
1195 return Error::BAD_PARAMETER;
1196 }
1197
1198 AidlDisplayContentSamplingAttributes attributes;
1199 const auto status =
1200 mAidlComposerClient->getDisplayedContentSamplingAttributes(translate<int64_t>(display),
1201 &attributes);
1202 if (!status.isOk()) {
1203 ALOGE("getDisplayedContentSamplingAttributes failed %s", status.getDescription().c_str());
1204 return static_cast<Error>(status.getServiceSpecificError());
1205 }
1206
1207 *outFormat = translate<PixelFormat>(attributes.format);
1208 *outDataspace = translate<Dataspace>(attributes.dataspace);
1209 *outComponentMask = static_cast<uint8_t>(attributes.componentMask);
1210 return Error::NONE;
1211}
1212
1213Error AidlComposer::setDisplayContentSamplingEnabled(Display display, bool enabled,
1214 uint8_t componentMask, uint64_t maxFrames) {
1215 const auto status =
1216 mAidlComposerClient
1217 ->setDisplayedContentSamplingEnabled(translate<int64_t>(display), enabled,
1218 static_cast<AidlFormatColorComponent>(
1219 componentMask),
1220 static_cast<int64_t>(maxFrames));
1221 if (!status.isOk()) {
1222 ALOGE("setDisplayedContentSamplingEnabled failed %s", status.getDescription().c_str());
1223 return static_cast<Error>(status.getServiceSpecificError());
1224 }
1225 return Error::NONE;
1226}
1227
1228Error AidlComposer::getDisplayedContentSample(Display display, uint64_t maxFrames,
1229 uint64_t timestamp, DisplayedFrameStats* outStats) {
1230 if (!outStats) {
1231 return Error::BAD_PARAMETER;
1232 }
1233
1234 AidlDisplayContentSample sample;
1235 const auto status =
1236 mAidlComposerClient->getDisplayedContentSample(translate<int64_t>(display),
1237 static_cast<int64_t>(maxFrames),
1238 static_cast<int64_t>(timestamp),
1239 &sample);
1240 if (!status.isOk()) {
1241 ALOGE("getDisplayedContentSample failed %s", status.getDescription().c_str());
1242 return static_cast<Error>(status.getServiceSpecificError());
1243 }
1244 *outStats = translate<DisplayedFrameStats>(sample);
1245 return Error::NONE;
1246}
1247
1248Error AidlComposer::setLayerPerFrameMetadataBlobs(
1249 Display display, Layer layer,
1250 const std::vector<IComposerClient::PerFrameMetadataBlob>& metadata) {
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -04001251 Error error = Error::NONE;
1252 mMutex.lock_shared();
1253 if (auto writer = getWriter(display)) {
1254 writer->get().setLayerPerFrameMetadataBlobs(translate<int64_t>(display),
1255 translate<int64_t>(layer),
1256 translate<AidlPerFrameMetadataBlob>(metadata));
1257 } else {
1258 error = Error::BAD_DISPLAY;
1259 }
1260 mMutex.unlock_shared();
1261 return error;
Ady Abrahame7385f72021-09-05 00:54:25 -07001262}
1263
Alec Mouri4d8a05d2022-03-23 18:14:26 +00001264Error AidlComposer::setDisplayBrightness(Display display, float brightness, float brightnessNits,
Alec Mouricdf16792021-12-10 13:16:06 -08001265 const DisplayBrightnessOptions& options) {
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -04001266 Error error = Error::NONE;
1267 mMutex.lock_shared();
1268 if (auto writer = getWriter(display)) {
1269 writer->get().setDisplayBrightness(translate<int64_t>(display), brightness, brightnessNits);
Alec Mouricdf16792021-12-10 13:16:06 -08001270
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -04001271 if (options.applyImmediately) {
1272 error = execute(display);
1273 mMutex.unlock_shared();
1274 return error;
1275 }
1276 } else {
1277 error = Error::BAD_DISPLAY;
Alec Mouricdf16792021-12-10 13:16:06 -08001278 }
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -04001279 mMutex.unlock_shared();
1280 return error;
Ady Abrahame7385f72021-09-05 00:54:25 -07001281}
1282
1283Error AidlComposer::getDisplayCapabilities(Display display,
Leon Scroggins III5967aec2021-12-29 11:14:22 -05001284 std::vector<AidlDisplayCapability>* outCapabilities) {
1285 const auto status = mAidlComposerClient->getDisplayCapabilities(translate<int64_t>(display),
1286 outCapabilities);
Ady Abrahame7385f72021-09-05 00:54:25 -07001287 if (!status.isOk()) {
1288 ALOGE("getDisplayCapabilities failed %s", status.getDescription().c_str());
Leon Scroggins III5967aec2021-12-29 11:14:22 -05001289 outCapabilities->clear();
Ady Abrahame7385f72021-09-05 00:54:25 -07001290 return static_cast<Error>(status.getServiceSpecificError());
1291 }
Ady Abrahame7385f72021-09-05 00:54:25 -07001292 return Error::NONE;
1293}
1294
1295V2_4::Error AidlComposer::getDisplayConnectionType(
1296 Display display, IComposerClient::DisplayConnectionType* outType) {
1297 AidlDisplayConnectionType type;
1298 const auto status =
1299 mAidlComposerClient->getDisplayConnectionType(translate<int64_t>(display), &type);
1300 if (!status.isOk()) {
1301 ALOGE("getDisplayConnectionType failed %s", status.getDescription().c_str());
1302 return static_cast<V2_4::Error>(status.getServiceSpecificError());
1303 }
1304 *outType = translate<IComposerClient::DisplayConnectionType>(type);
1305 return V2_4::Error::NONE;
1306}
1307
1308V2_4::Error AidlComposer::getDisplayVsyncPeriod(Display display, VsyncPeriodNanos* outVsyncPeriod) {
1309 int32_t vsyncPeriod;
1310 const auto status =
1311 mAidlComposerClient->getDisplayVsyncPeriod(translate<int64_t>(display), &vsyncPeriod);
1312 if (!status.isOk()) {
1313 ALOGE("getDisplayVsyncPeriod failed %s", status.getDescription().c_str());
1314 return static_cast<V2_4::Error>(status.getServiceSpecificError());
1315 }
1316 *outVsyncPeriod = translate<VsyncPeriodNanos>(vsyncPeriod);
1317 return V2_4::Error::NONE;
1318}
1319
1320V2_4::Error AidlComposer::setActiveConfigWithConstraints(
1321 Display display, Config config,
1322 const IComposerClient::VsyncPeriodChangeConstraints& vsyncPeriodChangeConstraints,
1323 VsyncPeriodChangeTimeline* outTimeline) {
1324 AidlVsyncPeriodChangeTimeline timeline;
1325 const auto status =
1326 mAidlComposerClient
1327 ->setActiveConfigWithConstraints(translate<int64_t>(display),
1328 translate<int32_t>(config),
1329 translate<AidlVsyncPeriodChangeConstraints>(
1330 vsyncPeriodChangeConstraints),
1331 &timeline);
1332 if (!status.isOk()) {
1333 ALOGE("setActiveConfigWithConstraints failed %s", status.getDescription().c_str());
1334 return static_cast<V2_4::Error>(status.getServiceSpecificError());
1335 }
1336 *outTimeline = translate<VsyncPeriodChangeTimeline>(timeline);
1337 return V2_4::Error::NONE;
1338}
1339
1340V2_4::Error AidlComposer::setAutoLowLatencyMode(Display display, bool on) {
1341 const auto status = mAidlComposerClient->setAutoLowLatencyMode(translate<int64_t>(display), on);
1342 if (!status.isOk()) {
1343 ALOGE("setAutoLowLatencyMode failed %s", status.getDescription().c_str());
1344 return static_cast<V2_4::Error>(status.getServiceSpecificError());
1345 }
1346 return V2_4::Error::NONE;
1347}
1348
1349V2_4::Error AidlComposer::getSupportedContentTypes(
1350 Display displayId, std::vector<IComposerClient::ContentType>* outSupportedContentTypes) {
1351 std::vector<AidlContentType> types;
1352 const auto status =
1353 mAidlComposerClient->getSupportedContentTypes(translate<int64_t>(displayId), &types);
1354 if (!status.isOk()) {
1355 ALOGE("getSupportedContentTypes failed %s", status.getDescription().c_str());
1356 return static_cast<V2_4::Error>(status.getServiceSpecificError());
1357 }
1358 *outSupportedContentTypes = translate<IComposerClient::ContentType>(types);
1359 return V2_4::Error::NONE;
1360}
1361
1362V2_4::Error AidlComposer::setContentType(Display display,
1363 IComposerClient::ContentType contentType) {
1364 const auto status =
1365 mAidlComposerClient->setContentType(translate<int64_t>(display),
1366 translate<AidlContentType>(contentType));
1367 if (!status.isOk()) {
1368 ALOGE("setContentType failed %s", status.getDescription().c_str());
1369 return static_cast<V2_4::Error>(status.getServiceSpecificError());
1370 }
1371 return V2_4::Error::NONE;
1372}
1373
Ady Abraham3f976752021-12-20 16:17:50 -08001374V2_4::Error AidlComposer::setLayerGenericMetadata(Display, Layer, const std::string&, bool,
1375 const std::vector<uint8_t>&) {
1376 // There are no users for this API. See b/209691612.
1377 return V2_4::Error::UNSUPPORTED;
Ady Abrahame7385f72021-09-05 00:54:25 -07001378}
1379
1380V2_4::Error AidlComposer::getLayerGenericMetadataKeys(
Ady Abraham3f976752021-12-20 16:17:50 -08001381 std::vector<IComposerClient::LayerGenericMetadataKey>*) {
1382 // There are no users for this API. See b/209691612.
1383 return V2_4::Error::UNSUPPORTED;
Ady Abrahame7385f72021-09-05 00:54:25 -07001384}
1385
Kriti Dang7defaf32021-11-15 11:55:43 +01001386Error AidlComposer::setBootDisplayConfig(Display display, Config config) {
1387 const auto status = mAidlComposerClient->setBootDisplayConfig(translate<int64_t>(display),
1388 translate<int32_t>(config));
1389 if (!status.isOk()) {
1390 ALOGE("setBootDisplayConfig failed %s", status.getDescription().c_str());
1391 return static_cast<Error>(status.getServiceSpecificError());
1392 }
1393 return Error::NONE;
1394}
1395
1396Error AidlComposer::clearBootDisplayConfig(Display display) {
1397 const auto status = mAidlComposerClient->clearBootDisplayConfig(translate<int64_t>(display));
1398 if (!status.isOk()) {
1399 ALOGE("clearBootDisplayConfig failed %s", status.getDescription().c_str());
1400 return static_cast<Error>(status.getServiceSpecificError());
1401 }
1402 return Error::NONE;
1403}
1404
1405Error AidlComposer::getPreferredBootDisplayConfig(Display display, Config* config) {
1406 int32_t displayConfig;
1407 const auto status =
1408 mAidlComposerClient->getPreferredBootDisplayConfig(translate<int64_t>(display),
1409 &displayConfig);
1410 if (!status.isOk()) {
1411 ALOGE("getPreferredBootDisplayConfig failed %s", status.getDescription().c_str());
1412 return static_cast<Error>(status.getServiceSpecificError());
1413 }
1414 *config = translate<uint32_t>(displayConfig);
1415 return Error::NONE;
1416}
1417
Kriti Dang674b9372022-11-18 10:58:44 +01001418Error AidlComposer::getHdrConversionCapabilities(
1419 std::vector<AidlHdrConversionCapability>* hdrConversionCapabilities) {
1420 const auto status =
1421 mAidlComposerClient->getHdrConversionCapabilities(hdrConversionCapabilities);
1422 if (!status.isOk()) {
1423 hdrConversionCapabilities = {};
1424 ALOGE("getHdrConversionCapabilities failed %s", status.getDescription().c_str());
1425 return static_cast<Error>(status.getServiceSpecificError());
1426 }
1427 return Error::NONE;
1428}
1429
Kriti Dangd432bb52023-02-09 18:21:04 +01001430Error AidlComposer::setHdrConversionStrategy(AidlHdrConversionStrategy hdrConversionStrategy,
1431 Hdr* outPreferredHdrOutputType) {
1432 const auto status = mAidlComposerClient->setHdrConversionStrategy(hdrConversionStrategy,
1433 outPreferredHdrOutputType);
Kriti Dang674b9372022-11-18 10:58:44 +01001434 if (!status.isOk()) {
1435 ALOGE("setHdrConversionStrategy failed %s", status.getDescription().c_str());
1436 return static_cast<Error>(status.getServiceSpecificError());
1437 }
1438 return Error::NONE;
1439}
1440
ramindanib2158ee2023-02-13 20:29:59 -08001441Error AidlComposer::setRefreshRateChangedCallbackDebugEnabled(Display displayId, bool enabled) {
1442 const auto status =
1443 mAidlComposerClient->setRefreshRateChangedCallbackDebugEnabled(translate<int64_t>(
1444 displayId),
1445 enabled);
1446 if (!status.isOk()) {
1447 ALOGE("setRefreshRateChangedCallbackDebugEnabled failed %s",
1448 status.getDescription().c_str());
1449 return static_cast<Error>(status.getServiceSpecificError());
1450 }
1451 return Error::NONE;
1452}
1453
ramindani3acaaf52023-09-25 10:31:27 -07001454Error AidlComposer::notifyExpectedPresent(Display displayId, nsecs_t expectedPresentTime,
1455 int32_t frameIntervalNs) {
1456 const auto status =
1457 mAidlComposerClient->notifyExpectedPresent(translate<int64_t>(displayId),
1458 ClockMonotonicTimestamp{expectedPresentTime},
1459 frameIntervalNs);
1460
1461 if (!status.isOk()) {
1462 ALOGE("notifyExpectedPresent failed %s", status.getDescription().c_str());
1463 return static_cast<Error>(status.getServiceSpecificError());
1464 }
1465 return Error::NONE;
1466}
1467
Ady Abrahame7385f72021-09-05 00:54:25 -07001468Error AidlComposer::getClientTargetProperty(
Alec Mouri85065692022-03-18 00:58:26 +00001469 Display display, ClientTargetPropertyWithBrightness* outClientTargetProperty) {
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -04001470 Error error = Error::NONE;
1471 mMutex.lock_shared();
1472 if (auto reader = getReader(display)) {
1473 *outClientTargetProperty =
1474 reader->get().takeClientTargetProperty(translate<int64_t>(display));
1475 } else {
1476 error = Error::BAD_DISPLAY;
1477 }
1478 mMutex.unlock_shared();
1479 return error;
Ady Abrahame7385f72021-09-05 00:54:25 -07001480}
1481
Alec Mouri6da0e272022-02-07 12:45:57 -08001482Error AidlComposer::setLayerBrightness(Display display, Layer layer, float brightness) {
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -04001483 Error error = Error::NONE;
1484 mMutex.lock_shared();
1485 if (auto writer = getWriter(display)) {
1486 writer->get().setLayerBrightness(translate<int64_t>(display), translate<int64_t>(layer),
1487 brightness);
1488 } else {
1489 error = Error::BAD_DISPLAY;
1490 }
1491 mMutex.unlock_shared();
1492 return error;
Alec Mouricdf6cbc2021-11-01 17:21:15 -07001493}
1494
Leon Scroggins IIId77d3162022-01-05 10:42:28 -05001495Error AidlComposer::setLayerBlockingRegion(Display display, Layer layer,
1496 const std::vector<IComposerClient::Rect>& blocking) {
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -04001497 Error error = Error::NONE;
1498 mMutex.lock_shared();
1499 if (auto writer = getWriter(display)) {
1500 writer->get().setLayerBlockingRegion(translate<int64_t>(display), translate<int64_t>(layer),
1501 translate<AidlRect>(blocking));
1502 } else {
1503 error = Error::BAD_DISPLAY;
1504 }
1505 mMutex.unlock_shared();
1506 return error;
Leon Scroggins IIId77d3162022-01-05 10:42:28 -05001507}
Leon Scroggins IIIe7c51c62022-02-01 15:53:54 -05001508
1509Error AidlComposer::getDisplayDecorationSupport(Display display,
1510 std::optional<DisplayDecorationSupport>* support) {
1511 const auto status =
1512 mAidlComposerClient->getDisplayDecorationSupport(translate<int64_t>(display), support);
1513 if (!status.isOk()) {
1514 ALOGE("getDisplayDecorationSupport failed %s", status.getDescription().c_str());
1515 support->reset();
1516 return static_cast<Error>(status.getServiceSpecificError());
1517 }
1518 return Error::NONE;
1519}
ramindani32cf0602022-03-02 02:30:29 +00001520
1521Error AidlComposer::setIdleTimerEnabled(Display displayId, std::chrono::milliseconds timeout) {
1522 const auto status =
1523 mAidlComposerClient->setIdleTimerEnabled(translate<int64_t>(displayId),
1524 translate<int32_t>(timeout.count()));
1525 if (!status.isOk()) {
1526 ALOGE("setIdleTimerEnabled failed %s", status.getDescription().c_str());
1527 return static_cast<Error>(status.getServiceSpecificError());
1528 }
1529 return Error::NONE;
1530}
1531
ramindani06e518e2022-03-14 18:47:53 +00001532Error AidlComposer::getPhysicalDisplayOrientation(Display displayId,
1533 AidlTransform* outDisplayOrientation) {
1534 const auto status =
1535 mAidlComposerClient->getDisplayPhysicalOrientation(translate<int64_t>(displayId),
1536 outDisplayOrientation);
1537 if (!status.isOk()) {
1538 ALOGE("getPhysicalDisplayOrientation failed %s", status.getDescription().c_str());
1539 return static_cast<Error>(status.getServiceSpecificError());
1540 }
1541 return Error::NONE;
1542}
1543
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -04001544ftl::Optional<std::reference_wrapper<ComposerClientWriter>> AidlComposer::getWriter(Display display)
1545 REQUIRES_SHARED(mMutex) {
1546 return mWriters.get(display);
1547}
1548
1549ftl::Optional<std::reference_wrapper<ComposerClientReader>> AidlComposer::getReader(Display display)
1550 REQUIRES_SHARED(mMutex) {
1551 if (mSingleReader) {
1552 display = translate<Display>(kSingleReaderKey);
1553 }
1554 return mReaders.get(display);
1555}
1556
1557void AidlComposer::removeDisplay(Display display) {
1558 mMutex.lock();
1559 bool wasErased = mWriters.erase(display);
1560 ALOGW_IF(!wasErased,
1561 "Attempting to remove writer for display %" PRId64 " which is not connected",
1562 translate<int64_t>(display));
1563 if (!mSingleReader) {
1564 removeReader(display);
1565 }
1566 mMutex.unlock();
1567}
1568
1569void AidlComposer::onHotplugDisconnect(Display display) {
1570 removeDisplay(display);
1571}
1572
1573bool AidlComposer::hasMultiThreadedPresentSupport(Display display) {
Leon Scroggins IIIc1cf4582023-03-23 18:37:44 -04001574#if 0
1575 // TODO (b/259132483): Reenable
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -04001576 const auto displayId = translate<int64_t>(display);
1577 std::vector<AidlDisplayCapability> capabilities;
1578 const auto status = mAidlComposerClient->getDisplayCapabilities(displayId, &capabilities);
1579 if (!status.isOk()) {
1580 ALOGE("getDisplayCapabilities failed %s", status.getDescription().c_str());
1581 return false;
1582 }
1583 return std::find(capabilities.begin(), capabilities.end(),
1584 AidlDisplayCapability::MULTI_THREADED_PRESENT) != capabilities.end();
Leon Scroggins IIIc1cf4582023-03-23 18:37:44 -04001585#else
1586 (void) display;
1587 return false;
1588#endif
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -04001589}
1590
1591void AidlComposer::addReader(Display display) {
1592 const auto displayId = translate<int64_t>(display);
1593 std::optional<int64_t> displayOpt;
1594 if (displayId != kSingleReaderKey) {
1595 displayOpt.emplace(displayId);
1596 }
1597 auto [it, added] = mReaders.try_emplace(display, std::move(displayOpt));
1598 ALOGW_IF(!added, "Attempting to add writer for display %" PRId64 " which is already connected",
1599 displayId);
1600}
1601
1602void AidlComposer::removeReader(Display display) {
1603 bool wasErased = mReaders.erase(display);
1604 ALOGW_IF(!wasErased,
1605 "Attempting to remove reader for display %" PRId64 " which is not connected",
1606 translate<int64_t>(display));
1607}
1608
1609void AidlComposer::addDisplay(Display display) {
1610 const auto displayId = translate<int64_t>(display);
1611 mMutex.lock();
1612 auto [it, added] = mWriters.try_emplace(display, displayId);
1613 ALOGW_IF(!added, "Attempting to add writer for display %" PRId64 " which is already connected",
1614 displayId);
1615 if (mSingleReader) {
1616 if (hasMultiThreadedPresentSupport(display)) {
1617 mSingleReader = false;
1618 removeReader(translate<Display>(kSingleReaderKey));
1619 // Note that this includes the new display.
1620 for (const auto& [existingDisplay, _] : mWriters) {
1621 addReader(existingDisplay);
1622 }
1623 }
1624 } else {
1625 addReader(display);
1626 }
1627 mMutex.unlock();
1628}
1629
1630void AidlComposer::onHotplugConnect(Display display) {
1631 addDisplay(display);
1632}
Ady Abrahame7385f72021-09-05 00:54:25 -07001633} // namespace Hwc2
1634} // namespace android