blob: 2d957e6334d78dce22505a242e834781ca21239e [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>
Alec Mouri9b133ca2023-11-14 19:00:01 +000027#include <common/FlagManager.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,
ramindani09acbb82023-11-03 09:02:38 -0700753 int32_t frameIntervalNs, uint32_t* outNumTypes,
754 uint32_t* outNumRequests) {
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400755 const auto displayId = translate<int64_t>(display);
Leon Scroggins IIIe85e16e2022-12-12 12:51:18 -0500756 ATRACE_FORMAT("HwcValidateDisplay %" PRId64, displayId);
757
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400758 Error error = Error::NONE;
759 mMutex.lock_shared();
760 auto writer = getWriter(display);
761 auto reader = getReader(display);
762 if (writer && reader) {
ramindani09acbb82023-11-03 09:02:38 -0700763 writer->get().validateDisplay(displayId, ClockMonotonicTimestamp{expectedPresentTime},
764 frameIntervalNs);
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400765 error = execute(display);
766 } else {
767 error = Error::BAD_DISPLAY;
768 }
Ady Abrahame7385f72021-09-05 00:54:25 -0700769
Ady Abrahame7385f72021-09-05 00:54:25 -0700770 if (error != Error::NONE) {
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400771 mMutex.unlock_shared();
Ady Abrahame7385f72021-09-05 00:54:25 -0700772 return error;
773 }
774
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400775 reader->get().hasChanges(displayId, outNumTypes, outNumRequests);
Ady Abrahame7385f72021-09-05 00:54:25 -0700776
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400777 mMutex.unlock_shared();
Ady Abrahame7385f72021-09-05 00:54:25 -0700778 return Error::NONE;
779}
780
Ady Abraham43065bd2021-12-10 17:22:15 -0800781Error AidlComposer::presentOrValidateDisplay(Display display, nsecs_t expectedPresentTime,
ramindani4aac32c2023-10-30 14:13:30 -0700782 int32_t frameIntervalNs, uint32_t* outNumTypes,
783 uint32_t* outNumRequests, int* outPresentFence,
784 uint32_t* state) {
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400785 const auto displayId = translate<int64_t>(display);
Leon Scroggins IIIe85e16e2022-12-12 12:51:18 -0500786 ATRACE_FORMAT("HwcPresentOrValidateDisplay %" PRId64, displayId);
787
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400788 Error error = Error::NONE;
789 mMutex.lock_shared();
790 auto writer = getWriter(display);
791 auto reader = getReader(display);
792 if (writer && reader) {
793 writer->get().presentOrvalidateDisplay(displayId,
ramindani4aac32c2023-10-30 14:13:30 -0700794 ClockMonotonicTimestamp{expectedPresentTime},
795 frameIntervalNs);
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400796 error = execute(display);
797 } else {
798 error = Error::BAD_DISPLAY;
799 }
Ady Abrahame7385f72021-09-05 00:54:25 -0700800
Ady Abrahame7385f72021-09-05 00:54:25 -0700801 if (error != Error::NONE) {
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400802 mMutex.unlock_shared();
Ady Abrahame7385f72021-09-05 00:54:25 -0700803 return error;
804 }
805
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400806 const auto result = reader->get().takePresentOrValidateStage(displayId);
Ady Abrahamde792782021-12-20 10:00:49 -0800807 if (!result.has_value()) {
808 *state = translate<uint32_t>(-1);
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400809 mMutex.unlock_shared();
Ady Abrahamde792782021-12-20 10:00:49 -0800810 return Error::NO_RESOURCES;
Ady Abrahame7385f72021-09-05 00:54:25 -0700811 }
812
Ady Abrahamde792782021-12-20 10:00:49 -0800813 *state = translate<uint32_t>(*result);
814
815 if (*result == PresentOrValidate::Result::Presented) {
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400816 auto fence = reader->get().takePresentFence(displayId);
Ady Abrahamde792782021-12-20 10:00:49 -0800817 // take ownership
818 *outPresentFence = fence.get();
819 *fence.getR() = -1;
820 }
821
822 if (*result == PresentOrValidate::Result::Validated) {
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400823 reader->get().hasChanges(displayId, outNumTypes, outNumRequests);
Ady Abrahame7385f72021-09-05 00:54:25 -0700824 }
825
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400826 mMutex.unlock_shared();
Ady Abrahame7385f72021-09-05 00:54:25 -0700827 return Error::NONE;
828}
829
830Error AidlComposer::setCursorPosition(Display display, Layer layer, int32_t x, int32_t y) {
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400831 Error error = Error::NONE;
832 mMutex.lock_shared();
833 if (auto writer = getWriter(display)) {
834 writer->get().setLayerCursorPosition(translate<int64_t>(display), translate<int64_t>(layer),
835 x, y);
836 } else {
837 error = Error::BAD_DISPLAY;
838 }
839 mMutex.unlock_shared();
840 return error;
Ady Abrahame7385f72021-09-05 00:54:25 -0700841}
842
843Error AidlComposer::setLayerBuffer(Display display, Layer layer, uint32_t slot,
844 const sp<GraphicBuffer>& buffer, int acquireFence) {
Ady Abrahame7385f72021-09-05 00:54:25 -0700845 const native_handle_t* handle = nullptr;
846 if (buffer.get()) {
847 handle = buffer->getNativeBuffer()->handle;
848 }
849
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400850 Error error = Error::NONE;
851 mMutex.lock_shared();
852 if (auto writer = getWriter(display)) {
853 writer->get().setLayerBuffer(translate<int64_t>(display), translate<int64_t>(layer), slot,
854 handle, acquireFence);
855 } else {
856 error = Error::BAD_DISPLAY;
857 }
858 mMutex.unlock_shared();
859 return error;
Ady Abrahame7385f72021-09-05 00:54:25 -0700860}
861
Brian Lindahlb158a5c2022-12-15 15:21:13 -0700862Error AidlComposer::setLayerBufferSlotsToClear(Display display, Layer layer,
863 const std::vector<uint32_t>& slotsToClear,
864 uint32_t activeBufferSlot) {
865 if (slotsToClear.empty()) {
866 return Error::NONE;
867 }
868
Brian Lindahl90553da2022-12-06 13:36:30 -0700869 Error error = Error::NONE;
870 mMutex.lock_shared();
871 if (auto writer = getWriter(display)) {
ramindani0cd1d8d2023-06-13 13:43:23 -0700872 if (mComposerInterfaceVersion > 1) {
Brian Lindahldbf7e3a2022-12-16 11:43:39 -0700873 writer->get().setLayerBufferSlotsToClear(translate<int64_t>(display),
874 translate<int64_t>(layer), slotsToClear);
Brian Lindahl5b0ffe02023-06-15 14:19:43 -0600875 // Backwards compatible way of clearing buffer slots is to set the layer buffer with a
876 // placeholder buffer, using the slot that needs to cleared... tricky.
877 } else if (mClearSlotBuffer != nullptr) {
Brian Lindahldbf7e3a2022-12-16 11:43:39 -0700878 for (uint32_t slot : slotsToClear) {
879 // Don't clear the active buffer slot because we need to restore the active buffer
880 // after clearing the requested buffer slots with a placeholder buffer.
881 if (slot != activeBufferSlot) {
882 writer->get().setLayerBufferWithNewCommand(translate<int64_t>(display),
883 translate<int64_t>(layer), slot,
884 mClearSlotBuffer->handle,
885 /*fence*/ -1);
886 }
Brian Lindahlb158a5c2022-12-15 15:21:13 -0700887 }
Brian Lindahldbf7e3a2022-12-16 11:43:39 -0700888 // Since we clear buffers by setting them to a placeholder buffer, we want to make
889 // sure that the last setLayerBuffer command is sent with the currently active
890 // buffer, not the placeholder buffer, so that there is no perceptual change when
891 // buffers are discarded.
892 writer->get().setLayerBufferWithNewCommand(translate<int64_t>(display),
893 translate<int64_t>(layer), activeBufferSlot,
894 // The active buffer is still cached in
895 // its slot and doesn't need a fence.
896 /*buffer*/ nullptr, /*fence*/ -1);
Brian Lindahlb158a5c2022-12-15 15:21:13 -0700897 }
Brian Lindahl90553da2022-12-06 13:36:30 -0700898 } else {
899 error = Error::BAD_DISPLAY;
900 }
901 mMutex.unlock_shared();
902 return error;
903}
904
Ady Abrahame7385f72021-09-05 00:54:25 -0700905Error AidlComposer::setLayerSurfaceDamage(Display display, Layer layer,
906 const std::vector<IComposerClient::Rect>& damage) {
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400907 Error error = Error::NONE;
908 mMutex.lock_shared();
909 if (auto writer = getWriter(display)) {
910 writer->get().setLayerSurfaceDamage(translate<int64_t>(display), translate<int64_t>(layer),
911 translate<AidlRect>(damage));
912 } else {
913 error = Error::BAD_DISPLAY;
914 }
915 mMutex.unlock_shared();
916 return error;
Ady Abrahame7385f72021-09-05 00:54:25 -0700917}
918
919Error AidlComposer::setLayerBlendMode(Display display, Layer layer,
920 IComposerClient::BlendMode mode) {
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400921 Error error = Error::NONE;
922 mMutex.lock_shared();
923 if (auto writer = getWriter(display)) {
924 writer->get().setLayerBlendMode(translate<int64_t>(display), translate<int64_t>(layer),
925 translate<BlendMode>(mode));
926 } else {
927 error = Error::BAD_DISPLAY;
928 }
929 mMutex.unlock_shared();
930 return error;
Ady Abrahame7385f72021-09-05 00:54:25 -0700931}
932
Ady Abraham6e60b142022-01-06 18:10:35 -0800933Error AidlComposer::setLayerColor(Display display, Layer layer, const Color& color) {
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400934 Error error = Error::NONE;
935 mMutex.lock_shared();
936 if (auto writer = getWriter(display)) {
937 writer->get().setLayerColor(translate<int64_t>(display), translate<int64_t>(layer), color);
938 } else {
939 error = Error::BAD_DISPLAY;
940 }
941 mMutex.unlock_shared();
942 return error;
Ady Abrahame7385f72021-09-05 00:54:25 -0700943}
944
Leon Scroggins III2e1aa182021-12-01 17:33:12 -0500945Error AidlComposer::setLayerCompositionType(
946 Display display, Layer layer,
947 aidl::android::hardware::graphics::composer3::Composition type) {
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400948 Error error = Error::NONE;
949 mMutex.lock_shared();
950 if (auto writer = getWriter(display)) {
951 writer->get().setLayerCompositionType(translate<int64_t>(display),
952 translate<int64_t>(layer), type);
953 } else {
954 error = Error::BAD_DISPLAY;
955 }
956 mMutex.unlock_shared();
957 return error;
Ady Abrahame7385f72021-09-05 00:54:25 -0700958}
959
960Error AidlComposer::setLayerDataspace(Display display, Layer layer, Dataspace dataspace) {
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400961 Error error = Error::NONE;
962 mMutex.lock_shared();
963 if (auto writer = getWriter(display)) {
964 writer->get().setLayerDataspace(translate<int64_t>(display), translate<int64_t>(layer),
965 translate<AidlDataspace>(dataspace));
966 } else {
967 error = Error::BAD_DISPLAY;
968 }
969 mMutex.unlock_shared();
970 return error;
Ady Abrahame7385f72021-09-05 00:54:25 -0700971}
972
973Error AidlComposer::setLayerDisplayFrame(Display display, Layer layer,
974 const IComposerClient::Rect& frame) {
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400975 Error error = Error::NONE;
976 mMutex.lock_shared();
977 if (auto writer = getWriter(display)) {
978 writer->get().setLayerDisplayFrame(translate<int64_t>(display), translate<int64_t>(layer),
979 translate<AidlRect>(frame));
980 } else {
981 error = Error::BAD_DISPLAY;
982 }
983 mMutex.unlock_shared();
984 return error;
Ady Abrahame7385f72021-09-05 00:54:25 -0700985}
986
987Error AidlComposer::setLayerPlaneAlpha(Display display, Layer layer, float alpha) {
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -0400988 Error error = Error::NONE;
989 mMutex.lock_shared();
990 if (auto writer = getWriter(display)) {
991 writer->get().setLayerPlaneAlpha(translate<int64_t>(display), translate<int64_t>(layer),
992 alpha);
993 } else {
994 error = Error::BAD_DISPLAY;
995 }
996 mMutex.unlock_shared();
997 return error;
Ady Abrahame7385f72021-09-05 00:54:25 -0700998}
999
1000Error AidlComposer::setLayerSidebandStream(Display display, Layer layer,
1001 const native_handle_t* stream) {
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -04001002 Error error = Error::NONE;
1003 mMutex.lock_shared();
1004 if (auto writer = getWriter(display)) {
1005 writer->get().setLayerSidebandStream(translate<int64_t>(display), translate<int64_t>(layer),
1006 stream);
1007 } else {
1008 error = Error::BAD_DISPLAY;
1009 }
1010 mMutex.unlock_shared();
1011 return error;
Ady Abrahame7385f72021-09-05 00:54:25 -07001012}
1013
1014Error AidlComposer::setLayerSourceCrop(Display display, Layer layer,
1015 const IComposerClient::FRect& crop) {
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -04001016 Error error = Error::NONE;
1017 mMutex.lock_shared();
1018 if (auto writer = getWriter(display)) {
1019 writer->get().setLayerSourceCrop(translate<int64_t>(display), translate<int64_t>(layer),
1020 translate<AidlFRect>(crop));
1021 } else {
1022 error = Error::BAD_DISPLAY;
1023 }
1024 mMutex.unlock_shared();
1025 return error;
Ady Abrahame7385f72021-09-05 00:54:25 -07001026}
1027
1028Error AidlComposer::setLayerTransform(Display display, Layer layer, Transform transform) {
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -04001029 Error error = Error::NONE;
1030 mMutex.lock_shared();
1031 if (auto writer = getWriter(display)) {
1032 writer->get().setLayerTransform(translate<int64_t>(display), translate<int64_t>(layer),
1033 translate<AidlTransform>(transform));
1034 } else {
1035 error = Error::BAD_DISPLAY;
1036 }
1037 mMutex.unlock_shared();
1038 return error;
Ady Abrahame7385f72021-09-05 00:54:25 -07001039}
1040
1041Error AidlComposer::setLayerVisibleRegion(Display display, Layer layer,
1042 const std::vector<IComposerClient::Rect>& visible) {
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -04001043 Error error = Error::NONE;
1044 mMutex.lock_shared();
1045 if (auto writer = getWriter(display)) {
1046 writer->get().setLayerVisibleRegion(translate<int64_t>(display), translate<int64_t>(layer),
1047 translate<AidlRect>(visible));
1048 } else {
1049 error = Error::BAD_DISPLAY;
1050 }
1051 mMutex.unlock_shared();
1052 return error;
Ady Abrahame7385f72021-09-05 00:54:25 -07001053}
1054
1055Error AidlComposer::setLayerZOrder(Display display, Layer layer, uint32_t z) {
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -04001056 Error error = Error::NONE;
1057 mMutex.lock_shared();
1058 if (auto writer = getWriter(display)) {
1059 writer->get().setLayerZOrder(translate<int64_t>(display), translate<int64_t>(layer), z);
1060 } else {
1061 error = Error::BAD_DISPLAY;
1062 }
1063 mMutex.unlock_shared();
1064 return error;
Ady Abrahame7385f72021-09-05 00:54:25 -07001065}
1066
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -04001067Error AidlComposer::execute(Display display) {
1068 auto writer = getWriter(display);
1069 auto reader = getReader(display);
1070 if (!writer || !reader) {
1071 return Error::BAD_DISPLAY;
1072 }
1073
Huihong Luoe7382c12023-04-21 20:24:32 +00001074 auto commands = writer->get().takePendingCommands();
Ady Abrahama6388c02021-11-11 21:11:51 -08001075 if (commands.empty()) {
Ady Abrahame7385f72021-09-05 00:54:25 -07001076 return Error::NONE;
1077 }
1078
Ady Abrahamde792782021-12-20 10:00:49 -08001079 { // scope for results
1080 std::vector<CommandResultPayload> results;
1081 auto status = mAidlComposerClient->executeCommands(commands, &results);
1082 if (!status.isOk()) {
1083 ALOGE("executeCommands failed %s", status.getDescription().c_str());
1084 return static_cast<Error>(status.getServiceSpecificError());
1085 }
Ady Abrahame7385f72021-09-05 00:54:25 -07001086
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -04001087 reader->get().parse(std::move(results));
Ady Abrahamde792782021-12-20 10:00:49 -08001088 }
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -04001089 const auto commandErrors = reader->get().takeErrors();
Ady Abrahama6388c02021-11-11 21:11:51 -08001090 Error error = Error::NONE;
1091 for (const auto& cmdErr : commandErrors) {
1092 const auto index = static_cast<size_t>(cmdErr.commandIndex);
1093 if (index < 0 || index >= commands.size()) {
1094 ALOGE("invalid command index %zu", index);
1095 return Error::BAD_PARAMETER;
Ady Abrahame7385f72021-09-05 00:54:25 -07001096 }
1097
Ady Abrahama6388c02021-11-11 21:11:51 -08001098 const auto& command = commands[index];
Ady Abraham42977362021-12-07 21:04:49 -08001099 if (command.validateDisplay || command.presentDisplay || command.presentOrValidateDisplay) {
1100 error = translate<Error>(cmdErr.errorCode);
1101 } else {
1102 ALOGW("command '%s' generated error %" PRId32, command.toString().c_str(),
1103 cmdErr.errorCode);
Ady Abrahame7385f72021-09-05 00:54:25 -07001104 }
1105 }
1106
Ady Abrahame7385f72021-09-05 00:54:25 -07001107 return error;
1108}
1109
1110Error AidlComposer::setLayerPerFrameMetadata(
1111 Display display, Layer layer,
1112 const std::vector<IComposerClient::PerFrameMetadata>& perFrameMetadatas) {
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -04001113 Error error = Error::NONE;
1114 mMutex.lock_shared();
1115 if (auto writer = getWriter(display)) {
1116 writer->get().setLayerPerFrameMetadata(translate<int64_t>(display),
1117 translate<int64_t>(layer),
1118 translate<AidlPerFrameMetadata>(perFrameMetadatas));
1119 } else {
1120 error = Error::BAD_DISPLAY;
1121 }
1122 mMutex.unlock_shared();
1123 return error;
Ady Abrahame7385f72021-09-05 00:54:25 -07001124}
1125
1126std::vector<IComposerClient::PerFrameMetadataKey> AidlComposer::getPerFrameMetadataKeys(
1127 Display display) {
1128 std::vector<AidlPerFrameMetadataKey> keys;
1129 const auto status =
1130 mAidlComposerClient->getPerFrameMetadataKeys(translate<int64_t>(display), &keys);
1131 if (!status.isOk()) {
1132 ALOGE("getPerFrameMetadataKeys failed %s", status.getDescription().c_str());
1133 return {};
1134 }
1135 return translate<IComposerClient::PerFrameMetadataKey>(keys);
1136}
1137
1138Error AidlComposer::getRenderIntents(Display display, ColorMode colorMode,
1139 std::vector<RenderIntent>* outRenderIntents) {
1140 std::vector<AidlRenderIntent> renderIntents;
1141 const auto status = mAidlComposerClient->getRenderIntents(translate<int64_t>(display),
1142 translate<AidlColorMode>(colorMode),
1143 &renderIntents);
1144 if (!status.isOk()) {
1145 ALOGE("getRenderIntents failed %s", status.getDescription().c_str());
1146 return static_cast<Error>(status.getServiceSpecificError());
1147 }
1148 *outRenderIntents = translate<RenderIntent>(renderIntents);
1149 return Error::NONE;
1150}
1151
1152Error AidlComposer::getDataspaceSaturationMatrix(Dataspace dataspace, mat4* outMatrix) {
1153 std::vector<float> matrix;
1154 const auto status =
1155 mAidlComposerClient->getDataspaceSaturationMatrix(translate<AidlDataspace>(dataspace),
1156 &matrix);
1157 if (!status.isOk()) {
1158 ALOGE("getDataspaceSaturationMatrix failed %s", status.getDescription().c_str());
1159 return static_cast<Error>(status.getServiceSpecificError());
1160 }
1161 *outMatrix = makeMat4(matrix);
1162 return Error::NONE;
1163}
1164
1165Error AidlComposer::getDisplayIdentificationData(Display display, uint8_t* outPort,
1166 std::vector<uint8_t>* outData) {
1167 AidlDisplayIdentification displayIdentification;
1168 const auto status =
1169 mAidlComposerClient->getDisplayIdentificationData(translate<int64_t>(display),
1170 &displayIdentification);
1171 if (!status.isOk()) {
1172 ALOGE("getDisplayIdentificationData failed %s", status.getDescription().c_str());
1173 return static_cast<Error>(status.getServiceSpecificError());
1174 }
1175
1176 *outPort = static_cast<uint8_t>(displayIdentification.port);
1177 *outData = displayIdentification.data;
1178
1179 return Error::NONE;
1180}
1181
1182Error AidlComposer::setLayerColorTransform(Display display, Layer layer, const float* matrix) {
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -04001183 Error error = Error::NONE;
1184 mMutex.lock_shared();
1185 if (auto writer = getWriter(display)) {
1186 writer->get().setLayerColorTransform(translate<int64_t>(display), translate<int64_t>(layer),
1187 matrix);
1188 } else {
1189 error = Error::BAD_DISPLAY;
1190 }
1191 mMutex.unlock_shared();
1192 return error;
Ady Abrahame7385f72021-09-05 00:54:25 -07001193}
1194
1195Error AidlComposer::getDisplayedContentSamplingAttributes(Display display, PixelFormat* outFormat,
1196 Dataspace* outDataspace,
1197 uint8_t* outComponentMask) {
1198 if (!outFormat || !outDataspace || !outComponentMask) {
1199 return Error::BAD_PARAMETER;
1200 }
1201
1202 AidlDisplayContentSamplingAttributes attributes;
1203 const auto status =
1204 mAidlComposerClient->getDisplayedContentSamplingAttributes(translate<int64_t>(display),
1205 &attributes);
1206 if (!status.isOk()) {
1207 ALOGE("getDisplayedContentSamplingAttributes failed %s", status.getDescription().c_str());
1208 return static_cast<Error>(status.getServiceSpecificError());
1209 }
1210
1211 *outFormat = translate<PixelFormat>(attributes.format);
1212 *outDataspace = translate<Dataspace>(attributes.dataspace);
1213 *outComponentMask = static_cast<uint8_t>(attributes.componentMask);
1214 return Error::NONE;
1215}
1216
1217Error AidlComposer::setDisplayContentSamplingEnabled(Display display, bool enabled,
1218 uint8_t componentMask, uint64_t maxFrames) {
1219 const auto status =
1220 mAidlComposerClient
1221 ->setDisplayedContentSamplingEnabled(translate<int64_t>(display), enabled,
1222 static_cast<AidlFormatColorComponent>(
1223 componentMask),
1224 static_cast<int64_t>(maxFrames));
1225 if (!status.isOk()) {
1226 ALOGE("setDisplayedContentSamplingEnabled failed %s", status.getDescription().c_str());
1227 return static_cast<Error>(status.getServiceSpecificError());
1228 }
1229 return Error::NONE;
1230}
1231
1232Error AidlComposer::getDisplayedContentSample(Display display, uint64_t maxFrames,
1233 uint64_t timestamp, DisplayedFrameStats* outStats) {
1234 if (!outStats) {
1235 return Error::BAD_PARAMETER;
1236 }
1237
1238 AidlDisplayContentSample sample;
1239 const auto status =
1240 mAidlComposerClient->getDisplayedContentSample(translate<int64_t>(display),
1241 static_cast<int64_t>(maxFrames),
1242 static_cast<int64_t>(timestamp),
1243 &sample);
1244 if (!status.isOk()) {
1245 ALOGE("getDisplayedContentSample failed %s", status.getDescription().c_str());
1246 return static_cast<Error>(status.getServiceSpecificError());
1247 }
1248 *outStats = translate<DisplayedFrameStats>(sample);
1249 return Error::NONE;
1250}
1251
1252Error AidlComposer::setLayerPerFrameMetadataBlobs(
1253 Display display, Layer layer,
1254 const std::vector<IComposerClient::PerFrameMetadataBlob>& metadata) {
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -04001255 Error error = Error::NONE;
1256 mMutex.lock_shared();
1257 if (auto writer = getWriter(display)) {
1258 writer->get().setLayerPerFrameMetadataBlobs(translate<int64_t>(display),
1259 translate<int64_t>(layer),
1260 translate<AidlPerFrameMetadataBlob>(metadata));
1261 } else {
1262 error = Error::BAD_DISPLAY;
1263 }
1264 mMutex.unlock_shared();
1265 return error;
Ady Abrahame7385f72021-09-05 00:54:25 -07001266}
1267
Alec Mouri4d8a05d2022-03-23 18:14:26 +00001268Error AidlComposer::setDisplayBrightness(Display display, float brightness, float brightnessNits,
Alec Mouricdf16792021-12-10 13:16:06 -08001269 const DisplayBrightnessOptions& options) {
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -04001270 Error error = Error::NONE;
1271 mMutex.lock_shared();
1272 if (auto writer = getWriter(display)) {
1273 writer->get().setDisplayBrightness(translate<int64_t>(display), brightness, brightnessNits);
Alec Mouricdf16792021-12-10 13:16:06 -08001274
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -04001275 if (options.applyImmediately) {
1276 error = execute(display);
1277 mMutex.unlock_shared();
1278 return error;
1279 }
1280 } else {
1281 error = Error::BAD_DISPLAY;
Alec Mouricdf16792021-12-10 13:16:06 -08001282 }
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -04001283 mMutex.unlock_shared();
1284 return error;
Ady Abrahame7385f72021-09-05 00:54:25 -07001285}
1286
1287Error AidlComposer::getDisplayCapabilities(Display display,
Leon Scroggins III5967aec2021-12-29 11:14:22 -05001288 std::vector<AidlDisplayCapability>* outCapabilities) {
1289 const auto status = mAidlComposerClient->getDisplayCapabilities(translate<int64_t>(display),
1290 outCapabilities);
Ady Abrahame7385f72021-09-05 00:54:25 -07001291 if (!status.isOk()) {
1292 ALOGE("getDisplayCapabilities failed %s", status.getDescription().c_str());
Leon Scroggins III5967aec2021-12-29 11:14:22 -05001293 outCapabilities->clear();
Ady Abrahame7385f72021-09-05 00:54:25 -07001294 return static_cast<Error>(status.getServiceSpecificError());
1295 }
Ady Abrahame7385f72021-09-05 00:54:25 -07001296 return Error::NONE;
1297}
1298
1299V2_4::Error AidlComposer::getDisplayConnectionType(
1300 Display display, IComposerClient::DisplayConnectionType* outType) {
1301 AidlDisplayConnectionType type;
1302 const auto status =
1303 mAidlComposerClient->getDisplayConnectionType(translate<int64_t>(display), &type);
1304 if (!status.isOk()) {
1305 ALOGE("getDisplayConnectionType failed %s", status.getDescription().c_str());
1306 return static_cast<V2_4::Error>(status.getServiceSpecificError());
1307 }
1308 *outType = translate<IComposerClient::DisplayConnectionType>(type);
1309 return V2_4::Error::NONE;
1310}
1311
1312V2_4::Error AidlComposer::getDisplayVsyncPeriod(Display display, VsyncPeriodNanos* outVsyncPeriod) {
1313 int32_t vsyncPeriod;
1314 const auto status =
1315 mAidlComposerClient->getDisplayVsyncPeriod(translate<int64_t>(display), &vsyncPeriod);
1316 if (!status.isOk()) {
1317 ALOGE("getDisplayVsyncPeriod failed %s", status.getDescription().c_str());
1318 return static_cast<V2_4::Error>(status.getServiceSpecificError());
1319 }
1320 *outVsyncPeriod = translate<VsyncPeriodNanos>(vsyncPeriod);
1321 return V2_4::Error::NONE;
1322}
1323
1324V2_4::Error AidlComposer::setActiveConfigWithConstraints(
1325 Display display, Config config,
1326 const IComposerClient::VsyncPeriodChangeConstraints& vsyncPeriodChangeConstraints,
1327 VsyncPeriodChangeTimeline* outTimeline) {
1328 AidlVsyncPeriodChangeTimeline timeline;
1329 const auto status =
1330 mAidlComposerClient
1331 ->setActiveConfigWithConstraints(translate<int64_t>(display),
1332 translate<int32_t>(config),
1333 translate<AidlVsyncPeriodChangeConstraints>(
1334 vsyncPeriodChangeConstraints),
1335 &timeline);
1336 if (!status.isOk()) {
1337 ALOGE("setActiveConfigWithConstraints failed %s", status.getDescription().c_str());
1338 return static_cast<V2_4::Error>(status.getServiceSpecificError());
1339 }
1340 *outTimeline = translate<VsyncPeriodChangeTimeline>(timeline);
1341 return V2_4::Error::NONE;
1342}
1343
1344V2_4::Error AidlComposer::setAutoLowLatencyMode(Display display, bool on) {
1345 const auto status = mAidlComposerClient->setAutoLowLatencyMode(translate<int64_t>(display), on);
1346 if (!status.isOk()) {
1347 ALOGE("setAutoLowLatencyMode failed %s", status.getDescription().c_str());
1348 return static_cast<V2_4::Error>(status.getServiceSpecificError());
1349 }
1350 return V2_4::Error::NONE;
1351}
1352
1353V2_4::Error AidlComposer::getSupportedContentTypes(
1354 Display displayId, std::vector<IComposerClient::ContentType>* outSupportedContentTypes) {
1355 std::vector<AidlContentType> types;
1356 const auto status =
1357 mAidlComposerClient->getSupportedContentTypes(translate<int64_t>(displayId), &types);
1358 if (!status.isOk()) {
1359 ALOGE("getSupportedContentTypes failed %s", status.getDescription().c_str());
1360 return static_cast<V2_4::Error>(status.getServiceSpecificError());
1361 }
1362 *outSupportedContentTypes = translate<IComposerClient::ContentType>(types);
1363 return V2_4::Error::NONE;
1364}
1365
1366V2_4::Error AidlComposer::setContentType(Display display,
1367 IComposerClient::ContentType contentType) {
1368 const auto status =
1369 mAidlComposerClient->setContentType(translate<int64_t>(display),
1370 translate<AidlContentType>(contentType));
1371 if (!status.isOk()) {
1372 ALOGE("setContentType failed %s", status.getDescription().c_str());
1373 return static_cast<V2_4::Error>(status.getServiceSpecificError());
1374 }
1375 return V2_4::Error::NONE;
1376}
1377
Ady Abraham3f976752021-12-20 16:17:50 -08001378V2_4::Error AidlComposer::setLayerGenericMetadata(Display, Layer, const std::string&, bool,
1379 const std::vector<uint8_t>&) {
1380 // There are no users for this API. See b/209691612.
1381 return V2_4::Error::UNSUPPORTED;
Ady Abrahame7385f72021-09-05 00:54:25 -07001382}
1383
1384V2_4::Error AidlComposer::getLayerGenericMetadataKeys(
Ady Abraham3f976752021-12-20 16:17:50 -08001385 std::vector<IComposerClient::LayerGenericMetadataKey>*) {
1386 // There are no users for this API. See b/209691612.
1387 return V2_4::Error::UNSUPPORTED;
Ady Abrahame7385f72021-09-05 00:54:25 -07001388}
1389
Kriti Dang7defaf32021-11-15 11:55:43 +01001390Error AidlComposer::setBootDisplayConfig(Display display, Config config) {
1391 const auto status = mAidlComposerClient->setBootDisplayConfig(translate<int64_t>(display),
1392 translate<int32_t>(config));
1393 if (!status.isOk()) {
1394 ALOGE("setBootDisplayConfig failed %s", status.getDescription().c_str());
1395 return static_cast<Error>(status.getServiceSpecificError());
1396 }
1397 return Error::NONE;
1398}
1399
1400Error AidlComposer::clearBootDisplayConfig(Display display) {
1401 const auto status = mAidlComposerClient->clearBootDisplayConfig(translate<int64_t>(display));
1402 if (!status.isOk()) {
1403 ALOGE("clearBootDisplayConfig failed %s", status.getDescription().c_str());
1404 return static_cast<Error>(status.getServiceSpecificError());
1405 }
1406 return Error::NONE;
1407}
1408
1409Error AidlComposer::getPreferredBootDisplayConfig(Display display, Config* config) {
1410 int32_t displayConfig;
1411 const auto status =
1412 mAidlComposerClient->getPreferredBootDisplayConfig(translate<int64_t>(display),
1413 &displayConfig);
1414 if (!status.isOk()) {
1415 ALOGE("getPreferredBootDisplayConfig failed %s", status.getDescription().c_str());
1416 return static_cast<Error>(status.getServiceSpecificError());
1417 }
1418 *config = translate<uint32_t>(displayConfig);
1419 return Error::NONE;
1420}
1421
Kriti Dang674b9372022-11-18 10:58:44 +01001422Error AidlComposer::getHdrConversionCapabilities(
1423 std::vector<AidlHdrConversionCapability>* hdrConversionCapabilities) {
1424 const auto status =
1425 mAidlComposerClient->getHdrConversionCapabilities(hdrConversionCapabilities);
1426 if (!status.isOk()) {
1427 hdrConversionCapabilities = {};
1428 ALOGE("getHdrConversionCapabilities failed %s", status.getDescription().c_str());
1429 return static_cast<Error>(status.getServiceSpecificError());
1430 }
1431 return Error::NONE;
1432}
1433
Kriti Dangd432bb52023-02-09 18:21:04 +01001434Error AidlComposer::setHdrConversionStrategy(AidlHdrConversionStrategy hdrConversionStrategy,
1435 Hdr* outPreferredHdrOutputType) {
1436 const auto status = mAidlComposerClient->setHdrConversionStrategy(hdrConversionStrategy,
1437 outPreferredHdrOutputType);
Kriti Dang674b9372022-11-18 10:58:44 +01001438 if (!status.isOk()) {
1439 ALOGE("setHdrConversionStrategy failed %s", status.getDescription().c_str());
1440 return static_cast<Error>(status.getServiceSpecificError());
1441 }
1442 return Error::NONE;
1443}
1444
ramindanib2158ee2023-02-13 20:29:59 -08001445Error AidlComposer::setRefreshRateChangedCallbackDebugEnabled(Display displayId, bool enabled) {
1446 const auto status =
1447 mAidlComposerClient->setRefreshRateChangedCallbackDebugEnabled(translate<int64_t>(
1448 displayId),
1449 enabled);
1450 if (!status.isOk()) {
1451 ALOGE("setRefreshRateChangedCallbackDebugEnabled failed %s",
1452 status.getDescription().c_str());
1453 return static_cast<Error>(status.getServiceSpecificError());
1454 }
1455 return Error::NONE;
1456}
1457
ramindani3acaaf52023-09-25 10:31:27 -07001458Error AidlComposer::notifyExpectedPresent(Display displayId, nsecs_t expectedPresentTime,
1459 int32_t frameIntervalNs) {
1460 const auto status =
1461 mAidlComposerClient->notifyExpectedPresent(translate<int64_t>(displayId),
1462 ClockMonotonicTimestamp{expectedPresentTime},
1463 frameIntervalNs);
1464
1465 if (!status.isOk()) {
1466 ALOGE("notifyExpectedPresent failed %s", status.getDescription().c_str());
1467 return static_cast<Error>(status.getServiceSpecificError());
1468 }
1469 return Error::NONE;
1470}
1471
Ady Abrahame7385f72021-09-05 00:54:25 -07001472Error AidlComposer::getClientTargetProperty(
Alec Mouri85065692022-03-18 00:58:26 +00001473 Display display, ClientTargetPropertyWithBrightness* outClientTargetProperty) {
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -04001474 Error error = Error::NONE;
1475 mMutex.lock_shared();
1476 if (auto reader = getReader(display)) {
1477 *outClientTargetProperty =
1478 reader->get().takeClientTargetProperty(translate<int64_t>(display));
1479 } else {
1480 error = Error::BAD_DISPLAY;
1481 }
1482 mMutex.unlock_shared();
1483 return error;
Ady Abrahame7385f72021-09-05 00:54:25 -07001484}
1485
Alec Mouri6da0e272022-02-07 12:45:57 -08001486Error AidlComposer::setLayerBrightness(Display display, Layer layer, float brightness) {
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -04001487 Error error = Error::NONE;
1488 mMutex.lock_shared();
1489 if (auto writer = getWriter(display)) {
1490 writer->get().setLayerBrightness(translate<int64_t>(display), translate<int64_t>(layer),
1491 brightness);
1492 } else {
1493 error = Error::BAD_DISPLAY;
1494 }
1495 mMutex.unlock_shared();
1496 return error;
Alec Mouricdf6cbc2021-11-01 17:21:15 -07001497}
1498
Leon Scroggins IIId77d3162022-01-05 10:42:28 -05001499Error AidlComposer::setLayerBlockingRegion(Display display, Layer layer,
1500 const std::vector<IComposerClient::Rect>& blocking) {
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -04001501 Error error = Error::NONE;
1502 mMutex.lock_shared();
1503 if (auto writer = getWriter(display)) {
1504 writer->get().setLayerBlockingRegion(translate<int64_t>(display), translate<int64_t>(layer),
1505 translate<AidlRect>(blocking));
1506 } else {
1507 error = Error::BAD_DISPLAY;
1508 }
1509 mMutex.unlock_shared();
1510 return error;
Leon Scroggins IIId77d3162022-01-05 10:42:28 -05001511}
Leon Scroggins IIIe7c51c62022-02-01 15:53:54 -05001512
1513Error AidlComposer::getDisplayDecorationSupport(Display display,
1514 std::optional<DisplayDecorationSupport>* support) {
1515 const auto status =
1516 mAidlComposerClient->getDisplayDecorationSupport(translate<int64_t>(display), support);
1517 if (!status.isOk()) {
1518 ALOGE("getDisplayDecorationSupport failed %s", status.getDescription().c_str());
1519 support->reset();
1520 return static_cast<Error>(status.getServiceSpecificError());
1521 }
1522 return Error::NONE;
1523}
ramindani32cf0602022-03-02 02:30:29 +00001524
1525Error AidlComposer::setIdleTimerEnabled(Display displayId, std::chrono::milliseconds timeout) {
1526 const auto status =
1527 mAidlComposerClient->setIdleTimerEnabled(translate<int64_t>(displayId),
1528 translate<int32_t>(timeout.count()));
1529 if (!status.isOk()) {
1530 ALOGE("setIdleTimerEnabled failed %s", status.getDescription().c_str());
1531 return static_cast<Error>(status.getServiceSpecificError());
1532 }
1533 return Error::NONE;
1534}
1535
ramindani06e518e2022-03-14 18:47:53 +00001536Error AidlComposer::getPhysicalDisplayOrientation(Display displayId,
1537 AidlTransform* outDisplayOrientation) {
1538 const auto status =
1539 mAidlComposerClient->getDisplayPhysicalOrientation(translate<int64_t>(displayId),
1540 outDisplayOrientation);
1541 if (!status.isOk()) {
1542 ALOGE("getPhysicalDisplayOrientation failed %s", status.getDescription().c_str());
1543 return static_cast<Error>(status.getServiceSpecificError());
1544 }
1545 return Error::NONE;
1546}
1547
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -04001548ftl::Optional<std::reference_wrapper<ComposerClientWriter>> AidlComposer::getWriter(Display display)
1549 REQUIRES_SHARED(mMutex) {
1550 return mWriters.get(display);
1551}
1552
1553ftl::Optional<std::reference_wrapper<ComposerClientReader>> AidlComposer::getReader(Display display)
1554 REQUIRES_SHARED(mMutex) {
1555 if (mSingleReader) {
1556 display = translate<Display>(kSingleReaderKey);
1557 }
1558 return mReaders.get(display);
1559}
1560
1561void AidlComposer::removeDisplay(Display display) {
1562 mMutex.lock();
1563 bool wasErased = mWriters.erase(display);
1564 ALOGW_IF(!wasErased,
1565 "Attempting to remove writer for display %" PRId64 " which is not connected",
1566 translate<int64_t>(display));
1567 if (!mSingleReader) {
1568 removeReader(display);
1569 }
1570 mMutex.unlock();
1571}
1572
1573void AidlComposer::onHotplugDisconnect(Display display) {
1574 removeDisplay(display);
1575}
1576
1577bool AidlComposer::hasMultiThreadedPresentSupport(Display display) {
Leon Scroggins IIIc1cf4582023-03-23 18:37:44 -04001578#if 0
1579 // TODO (b/259132483): Reenable
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -04001580 const auto displayId = translate<int64_t>(display);
1581 std::vector<AidlDisplayCapability> capabilities;
1582 const auto status = mAidlComposerClient->getDisplayCapabilities(displayId, &capabilities);
1583 if (!status.isOk()) {
1584 ALOGE("getDisplayCapabilities failed %s", status.getDescription().c_str());
1585 return false;
1586 }
1587 return std::find(capabilities.begin(), capabilities.end(),
1588 AidlDisplayCapability::MULTI_THREADED_PRESENT) != capabilities.end();
Leon Scroggins IIIc1cf4582023-03-23 18:37:44 -04001589#else
1590 (void) display;
1591 return false;
1592#endif
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -04001593}
1594
1595void AidlComposer::addReader(Display display) {
1596 const auto displayId = translate<int64_t>(display);
1597 std::optional<int64_t> displayOpt;
1598 if (displayId != kSingleReaderKey) {
1599 displayOpt.emplace(displayId);
1600 }
1601 auto [it, added] = mReaders.try_emplace(display, std::move(displayOpt));
1602 ALOGW_IF(!added, "Attempting to add writer for display %" PRId64 " which is already connected",
1603 displayId);
1604}
1605
1606void AidlComposer::removeReader(Display display) {
1607 bool wasErased = mReaders.erase(display);
1608 ALOGW_IF(!wasErased,
1609 "Attempting to remove reader for display %" PRId64 " which is not connected",
1610 translate<int64_t>(display));
1611}
1612
1613void AidlComposer::addDisplay(Display display) {
1614 const auto displayId = translate<int64_t>(display);
1615 mMutex.lock();
1616 auto [it, added] = mWriters.try_emplace(display, displayId);
1617 ALOGW_IF(!added, "Attempting to add writer for display %" PRId64 " which is already connected",
1618 displayId);
1619 if (mSingleReader) {
1620 if (hasMultiThreadedPresentSupport(display)) {
1621 mSingleReader = false;
1622 removeReader(translate<Display>(kSingleReaderKey));
1623 // Note that this includes the new display.
1624 for (const auto& [existingDisplay, _] : mWriters) {
1625 addReader(existingDisplay);
1626 }
1627 }
1628 } else {
1629 addReader(display);
1630 }
1631 mMutex.unlock();
1632}
1633
1634void AidlComposer::onHotplugConnect(Display display) {
1635 addDisplay(display);
1636}
Ady Abrahame7385f72021-09-05 00:54:25 -07001637} // namespace Hwc2
1638} // namespace android