1*38e8c45fSAndroid Build Coastguard Worker /*
2*38e8c45fSAndroid Build Coastguard Worker * Copyright 2021 The Android Open Source Project
3*38e8c45fSAndroid Build Coastguard Worker *
4*38e8c45fSAndroid Build Coastguard Worker * Licensed under the Apache License, Version 2.0 (the "License");
5*38e8c45fSAndroid Build Coastguard Worker * you may not use this file except in compliance with the License.
6*38e8c45fSAndroid Build Coastguard Worker * You may obtain a copy of the License at
7*38e8c45fSAndroid Build Coastguard Worker *
8*38e8c45fSAndroid Build Coastguard Worker * http://www.apache.org/licenses/LICENSE-2.0
9*38e8c45fSAndroid Build Coastguard Worker *
10*38e8c45fSAndroid Build Coastguard Worker * Unless required by applicable law or agreed to in writing, software
11*38e8c45fSAndroid Build Coastguard Worker * distributed under the License is distributed on an "AS IS" BASIS,
12*38e8c45fSAndroid Build Coastguard Worker * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13*38e8c45fSAndroid Build Coastguard Worker * See the License for the specific language governing permissions and
14*38e8c45fSAndroid Build Coastguard Worker * limitations under the License.
15*38e8c45fSAndroid Build Coastguard Worker */
16*38e8c45fSAndroid Build Coastguard Worker
17*38e8c45fSAndroid Build Coastguard Worker #undef LOG_TAG
18*38e8c45fSAndroid Build Coastguard Worker #define LOG_TAG "HwcComposer"
19*38e8c45fSAndroid Build Coastguard Worker #define ATRACE_TAG ATRACE_TAG_GRAPHICS
20*38e8c45fSAndroid Build Coastguard Worker
21*38e8c45fSAndroid Build Coastguard Worker #include "AidlComposerHal.h"
22*38e8c45fSAndroid Build Coastguard Worker
23*38e8c45fSAndroid Build Coastguard Worker #include <SurfaceFlingerProperties.h>
24*38e8c45fSAndroid Build Coastguard Worker #include <android-base/file.h>
25*38e8c45fSAndroid Build Coastguard Worker #include <android/binder_ibinder_platform.h>
26*38e8c45fSAndroid Build Coastguard Worker #include <android/binder_manager.h>
27*38e8c45fSAndroid Build Coastguard Worker #include <common/FlagManager.h>
28*38e8c45fSAndroid Build Coastguard Worker #include <common/trace.h>
29*38e8c45fSAndroid Build Coastguard Worker #include <log/log.h>
30*38e8c45fSAndroid Build Coastguard Worker
31*38e8c45fSAndroid Build Coastguard Worker #include <aidl/android/hardware/graphics/composer3/BnComposerCallback.h>
32*38e8c45fSAndroid Build Coastguard Worker
33*38e8c45fSAndroid Build Coastguard Worker #include <algorithm>
34*38e8c45fSAndroid Build Coastguard Worker #include <cinttypes>
35*38e8c45fSAndroid Build Coastguard Worker
36*38e8c45fSAndroid Build Coastguard Worker #include "HWC2.h"
37*38e8c45fSAndroid Build Coastguard Worker
38*38e8c45fSAndroid Build Coastguard Worker namespace android {
39*38e8c45fSAndroid Build Coastguard Worker
40*38e8c45fSAndroid Build Coastguard Worker using aidl::android::hardware::graphics::composer3::BnComposerCallback;
41*38e8c45fSAndroid Build Coastguard Worker using aidl::android::hardware::graphics::composer3::Capability;
42*38e8c45fSAndroid Build Coastguard Worker using aidl::android::hardware::graphics::composer3::ClientTargetPropertyWithBrightness;
43*38e8c45fSAndroid Build Coastguard Worker using aidl::android::hardware::graphics::composer3::CommandResultPayload;
44*38e8c45fSAndroid Build Coastguard Worker using aidl::android::hardware::graphics::composer3::Luts;
45*38e8c45fSAndroid Build Coastguard Worker using aidl::android::hardware::graphics::composer3::PowerMode;
46*38e8c45fSAndroid Build Coastguard Worker using aidl::android::hardware::graphics::composer3::VirtualDisplay;
47*38e8c45fSAndroid Build Coastguard Worker
48*38e8c45fSAndroid Build Coastguard Worker using AidlColorMode = aidl::android::hardware::graphics::composer3::ColorMode;
49*38e8c45fSAndroid Build Coastguard Worker using AidlContentType = aidl::android::hardware::graphics::composer3::ContentType;
50*38e8c45fSAndroid Build Coastguard Worker using AidlDisplayIdentification =
51*38e8c45fSAndroid Build Coastguard Worker aidl::android::hardware::graphics::composer3::DisplayIdentification;
52*38e8c45fSAndroid Build Coastguard Worker using AidlDisplayContentSample = aidl::android::hardware::graphics::composer3::DisplayContentSample;
53*38e8c45fSAndroid Build Coastguard Worker using AidlDisplayAttribute = aidl::android::hardware::graphics::composer3::DisplayAttribute;
54*38e8c45fSAndroid Build Coastguard Worker using AidlDisplayCapability = aidl::android::hardware::graphics::composer3::DisplayCapability;
55*38e8c45fSAndroid Build Coastguard Worker using AidlHdrCapabilities = aidl::android::hardware::graphics::composer3::HdrCapabilities;
56*38e8c45fSAndroid Build Coastguard Worker using AidlHdrConversionCapability =
57*38e8c45fSAndroid Build Coastguard Worker aidl::android::hardware::graphics::common::HdrConversionCapability;
58*38e8c45fSAndroid Build Coastguard Worker using AidlHdcpLevels = aidl::android::hardware::drm::HdcpLevels;
59*38e8c45fSAndroid Build Coastguard Worker using AidlHdrConversionStrategy = aidl::android::hardware::graphics::common::HdrConversionStrategy;
60*38e8c45fSAndroid Build Coastguard Worker using AidlOverlayProperties = aidl::android::hardware::graphics::composer3::OverlayProperties;
61*38e8c45fSAndroid Build Coastguard Worker using AidlPerFrameMetadata = aidl::android::hardware::graphics::composer3::PerFrameMetadata;
62*38e8c45fSAndroid Build Coastguard Worker using AidlPerFrameMetadataKey = aidl::android::hardware::graphics::composer3::PerFrameMetadataKey;
63*38e8c45fSAndroid Build Coastguard Worker using AidlPerFrameMetadataBlob = aidl::android::hardware::graphics::composer3::PerFrameMetadataBlob;
64*38e8c45fSAndroid Build Coastguard Worker using AidlRenderIntent = aidl::android::hardware::graphics::composer3::RenderIntent;
65*38e8c45fSAndroid Build Coastguard Worker using AidlVsyncPeriodChangeConstraints =
66*38e8c45fSAndroid Build Coastguard Worker aidl::android::hardware::graphics::composer3::VsyncPeriodChangeConstraints;
67*38e8c45fSAndroid Build Coastguard Worker using AidlVsyncPeriodChangeTimeline =
68*38e8c45fSAndroid Build Coastguard Worker aidl::android::hardware::graphics::composer3::VsyncPeriodChangeTimeline;
69*38e8c45fSAndroid Build Coastguard Worker using AidlDisplayContentSamplingAttributes =
70*38e8c45fSAndroid Build Coastguard Worker aidl::android::hardware::graphics::composer3::DisplayContentSamplingAttributes;
71*38e8c45fSAndroid Build Coastguard Worker using AidlFormatColorComponent = aidl::android::hardware::graphics::composer3::FormatColorComponent;
72*38e8c45fSAndroid Build Coastguard Worker using AidlDisplayConnectionType =
73*38e8c45fSAndroid Build Coastguard Worker aidl::android::hardware::graphics::composer3::DisplayConnectionType;
74*38e8c45fSAndroid Build Coastguard Worker
75*38e8c45fSAndroid Build Coastguard Worker using AidlColorTransform = aidl::android::hardware::graphics::common::ColorTransform;
76*38e8c45fSAndroid Build Coastguard Worker using AidlDataspace = aidl::android::hardware::graphics::common::Dataspace;
77*38e8c45fSAndroid Build Coastguard Worker using AidlDisplayHotplugEvent = aidl::android::hardware::graphics::common::DisplayHotplugEvent;
78*38e8c45fSAndroid Build Coastguard Worker using AidlFRect = aidl::android::hardware::graphics::common::FRect;
79*38e8c45fSAndroid Build Coastguard Worker using AidlRect = aidl::android::hardware::graphics::common::Rect;
80*38e8c45fSAndroid Build Coastguard Worker using AidlTransform = aidl::android::hardware::graphics::common::Transform;
81*38e8c45fSAndroid Build Coastguard Worker
82*38e8c45fSAndroid Build Coastguard Worker namespace Hwc2 {
83*38e8c45fSAndroid Build Coastguard Worker
84*38e8c45fSAndroid Build Coastguard Worker namespace {
85*38e8c45fSAndroid Build Coastguard Worker
86*38e8c45fSAndroid Build Coastguard Worker template <typename To, typename From>
translate(From x)87*38e8c45fSAndroid Build Coastguard Worker To translate(From x) {
88*38e8c45fSAndroid Build Coastguard Worker return static_cast<To>(x);
89*38e8c45fSAndroid Build Coastguard Worker }
90*38e8c45fSAndroid Build Coastguard Worker
91*38e8c45fSAndroid Build Coastguard Worker template <typename To, typename From>
translate(const std::vector<From> & in)92*38e8c45fSAndroid Build Coastguard Worker std::vector<To> translate(const std::vector<From>& in) {
93*38e8c45fSAndroid Build Coastguard Worker std::vector<To> out;
94*38e8c45fSAndroid Build Coastguard Worker out.reserve(in.size());
95*38e8c45fSAndroid Build Coastguard Worker std::transform(in.begin(), in.end(), std::back_inserter(out),
96*38e8c45fSAndroid Build Coastguard Worker [](From x) { return translate<To>(x); });
97*38e8c45fSAndroid Build Coastguard Worker return out;
98*38e8c45fSAndroid Build Coastguard Worker }
99*38e8c45fSAndroid Build Coastguard Worker
100*38e8c45fSAndroid Build Coastguard Worker template <>
translate(IComposerClient::Rect x)101*38e8c45fSAndroid Build Coastguard Worker AidlRect translate(IComposerClient::Rect x) {
102*38e8c45fSAndroid Build Coastguard Worker return AidlRect{
103*38e8c45fSAndroid Build Coastguard Worker .left = x.left,
104*38e8c45fSAndroid Build Coastguard Worker .top = x.top,
105*38e8c45fSAndroid Build Coastguard Worker .right = x.right,
106*38e8c45fSAndroid Build Coastguard Worker .bottom = x.bottom,
107*38e8c45fSAndroid Build Coastguard Worker };
108*38e8c45fSAndroid Build Coastguard Worker }
109*38e8c45fSAndroid Build Coastguard Worker
110*38e8c45fSAndroid Build Coastguard Worker template <>
translate(IComposerClient::FRect x)111*38e8c45fSAndroid Build Coastguard Worker AidlFRect translate(IComposerClient::FRect x) {
112*38e8c45fSAndroid Build Coastguard Worker return AidlFRect{
113*38e8c45fSAndroid Build Coastguard Worker .left = x.left,
114*38e8c45fSAndroid Build Coastguard Worker .top = x.top,
115*38e8c45fSAndroid Build Coastguard Worker .right = x.right,
116*38e8c45fSAndroid Build Coastguard Worker .bottom = x.bottom,
117*38e8c45fSAndroid Build Coastguard Worker };
118*38e8c45fSAndroid Build Coastguard Worker }
119*38e8c45fSAndroid Build Coastguard Worker
120*38e8c45fSAndroid Build Coastguard Worker template <>
translate(IComposerClient::PerFrameMetadataBlob x)121*38e8c45fSAndroid Build Coastguard Worker AidlPerFrameMetadataBlob translate(IComposerClient::PerFrameMetadataBlob x) {
122*38e8c45fSAndroid Build Coastguard Worker AidlPerFrameMetadataBlob blob;
123*38e8c45fSAndroid Build Coastguard Worker blob.key = translate<AidlPerFrameMetadataKey>(x.key),
124*38e8c45fSAndroid Build Coastguard Worker std::copy(x.blob.begin(), x.blob.end(), std::inserter(blob.blob, blob.blob.end()));
125*38e8c45fSAndroid Build Coastguard Worker return blob;
126*38e8c45fSAndroid Build Coastguard Worker }
127*38e8c45fSAndroid Build Coastguard Worker
128*38e8c45fSAndroid Build Coastguard Worker template <>
translate(IComposerClient::PerFrameMetadata x)129*38e8c45fSAndroid Build Coastguard Worker AidlPerFrameMetadata translate(IComposerClient::PerFrameMetadata x) {
130*38e8c45fSAndroid Build Coastguard Worker return AidlPerFrameMetadata{
131*38e8c45fSAndroid Build Coastguard Worker .key = translate<AidlPerFrameMetadataKey>(x.key),
132*38e8c45fSAndroid Build Coastguard Worker .value = x.value,
133*38e8c45fSAndroid Build Coastguard Worker };
134*38e8c45fSAndroid Build Coastguard Worker }
135*38e8c45fSAndroid Build Coastguard Worker
136*38e8c45fSAndroid Build Coastguard Worker template <>
translate(AidlDisplayContentSample x)137*38e8c45fSAndroid Build Coastguard Worker DisplayedFrameStats translate(AidlDisplayContentSample x) {
138*38e8c45fSAndroid Build Coastguard Worker return DisplayedFrameStats{
139*38e8c45fSAndroid Build Coastguard Worker .numFrames = static_cast<uint64_t>(x.frameCount),
140*38e8c45fSAndroid Build Coastguard Worker .component_0_sample = translate<uint64_t>(x.sampleComponent0),
141*38e8c45fSAndroid Build Coastguard Worker .component_1_sample = translate<uint64_t>(x.sampleComponent1),
142*38e8c45fSAndroid Build Coastguard Worker .component_2_sample = translate<uint64_t>(x.sampleComponent2),
143*38e8c45fSAndroid Build Coastguard Worker .component_3_sample = translate<uint64_t>(x.sampleComponent3),
144*38e8c45fSAndroid Build Coastguard Worker };
145*38e8c45fSAndroid Build Coastguard Worker }
146*38e8c45fSAndroid Build Coastguard Worker
147*38e8c45fSAndroid Build Coastguard Worker template <>
translate(IComposerClient::VsyncPeriodChangeConstraints x)148*38e8c45fSAndroid Build Coastguard Worker AidlVsyncPeriodChangeConstraints translate(IComposerClient::VsyncPeriodChangeConstraints x) {
149*38e8c45fSAndroid Build Coastguard Worker return AidlVsyncPeriodChangeConstraints{
150*38e8c45fSAndroid Build Coastguard Worker .desiredTimeNanos = x.desiredTimeNanos,
151*38e8c45fSAndroid Build Coastguard Worker .seamlessRequired = x.seamlessRequired,
152*38e8c45fSAndroid Build Coastguard Worker };
153*38e8c45fSAndroid Build Coastguard Worker }
154*38e8c45fSAndroid Build Coastguard Worker
155*38e8c45fSAndroid Build Coastguard Worker template <>
translate(AidlVsyncPeriodChangeTimeline x)156*38e8c45fSAndroid Build Coastguard Worker VsyncPeriodChangeTimeline translate(AidlVsyncPeriodChangeTimeline x) {
157*38e8c45fSAndroid Build Coastguard Worker return VsyncPeriodChangeTimeline{
158*38e8c45fSAndroid Build Coastguard Worker .newVsyncAppliedTimeNanos = x.newVsyncAppliedTimeNanos,
159*38e8c45fSAndroid Build Coastguard Worker .refreshRequired = x.refreshRequired,
160*38e8c45fSAndroid Build Coastguard Worker .refreshTimeNanos = x.refreshTimeNanos,
161*38e8c45fSAndroid Build Coastguard Worker };
162*38e8c45fSAndroid Build Coastguard Worker }
makeMat4(std::vector<float> in)163*38e8c45fSAndroid Build Coastguard Worker mat4 makeMat4(std::vector<float> in) {
164*38e8c45fSAndroid Build Coastguard Worker return mat4(static_cast<const float*>(in.data()));
165*38e8c45fSAndroid Build Coastguard Worker }
166*38e8c45fSAndroid Build Coastguard Worker
167*38e8c45fSAndroid Build Coastguard Worker } // namespace
168*38e8c45fSAndroid Build Coastguard Worker
169*38e8c45fSAndroid Build Coastguard Worker class AidlIComposerCallbackWrapper : public BnComposerCallback {
170*38e8c45fSAndroid Build Coastguard Worker public:
AidlIComposerCallbackWrapper(HWC2::ComposerCallback & callback)171*38e8c45fSAndroid Build Coastguard Worker AidlIComposerCallbackWrapper(HWC2::ComposerCallback& callback) : mCallback(callback) {}
172*38e8c45fSAndroid Build Coastguard Worker
onHotplug(int64_t in_display,bool in_connected)173*38e8c45fSAndroid Build Coastguard Worker ::ndk::ScopedAStatus onHotplug(int64_t in_display, bool in_connected) override {
174*38e8c45fSAndroid Build Coastguard Worker const auto event = in_connected ? AidlDisplayHotplugEvent::CONNECTED
175*38e8c45fSAndroid Build Coastguard Worker : AidlDisplayHotplugEvent::DISCONNECTED;
176*38e8c45fSAndroid Build Coastguard Worker mCallback.onComposerHalHotplugEvent(translate<Display>(in_display), event);
177*38e8c45fSAndroid Build Coastguard Worker return ::ndk::ScopedAStatus::ok();
178*38e8c45fSAndroid Build Coastguard Worker }
179*38e8c45fSAndroid Build Coastguard Worker
onRefresh(int64_t in_display)180*38e8c45fSAndroid Build Coastguard Worker ::ndk::ScopedAStatus onRefresh(int64_t in_display) override {
181*38e8c45fSAndroid Build Coastguard Worker mCallback.onComposerHalRefresh(translate<Display>(in_display));
182*38e8c45fSAndroid Build Coastguard Worker return ::ndk::ScopedAStatus::ok();
183*38e8c45fSAndroid Build Coastguard Worker }
184*38e8c45fSAndroid Build Coastguard Worker
onSeamlessPossible(int64_t in_display)185*38e8c45fSAndroid Build Coastguard Worker ::ndk::ScopedAStatus onSeamlessPossible(int64_t in_display) override {
186*38e8c45fSAndroid Build Coastguard Worker mCallback.onComposerHalSeamlessPossible(translate<Display>(in_display));
187*38e8c45fSAndroid Build Coastguard Worker return ::ndk::ScopedAStatus::ok();
188*38e8c45fSAndroid Build Coastguard Worker }
189*38e8c45fSAndroid Build Coastguard Worker
onVsync(int64_t in_display,int64_t in_timestamp,int32_t in_vsyncPeriodNanos)190*38e8c45fSAndroid Build Coastguard Worker ::ndk::ScopedAStatus onVsync(int64_t in_display, int64_t in_timestamp,
191*38e8c45fSAndroid Build Coastguard Worker int32_t in_vsyncPeriodNanos) override {
192*38e8c45fSAndroid Build Coastguard Worker mCallback.onComposerHalVsync(translate<Display>(in_display), in_timestamp,
193*38e8c45fSAndroid Build Coastguard Worker static_cast<uint32_t>(in_vsyncPeriodNanos));
194*38e8c45fSAndroid Build Coastguard Worker return ::ndk::ScopedAStatus::ok();
195*38e8c45fSAndroid Build Coastguard Worker }
196*38e8c45fSAndroid Build Coastguard Worker
onVsyncPeriodTimingChanged(int64_t in_display,const AidlVsyncPeriodChangeTimeline & in_updatedTimeline)197*38e8c45fSAndroid Build Coastguard Worker ::ndk::ScopedAStatus onVsyncPeriodTimingChanged(
198*38e8c45fSAndroid Build Coastguard Worker int64_t in_display, const AidlVsyncPeriodChangeTimeline& in_updatedTimeline) override {
199*38e8c45fSAndroid Build Coastguard Worker mCallback.onComposerHalVsyncPeriodTimingChanged(translate<Display>(in_display),
200*38e8c45fSAndroid Build Coastguard Worker translate<V2_4::VsyncPeriodChangeTimeline>(
201*38e8c45fSAndroid Build Coastguard Worker in_updatedTimeline));
202*38e8c45fSAndroid Build Coastguard Worker return ::ndk::ScopedAStatus::ok();
203*38e8c45fSAndroid Build Coastguard Worker }
204*38e8c45fSAndroid Build Coastguard Worker
onVsyncIdle(int64_t in_display)205*38e8c45fSAndroid Build Coastguard Worker ::ndk::ScopedAStatus onVsyncIdle(int64_t in_display) override {
206*38e8c45fSAndroid Build Coastguard Worker mCallback.onComposerHalVsyncIdle(translate<Display>(in_display));
207*38e8c45fSAndroid Build Coastguard Worker return ::ndk::ScopedAStatus::ok();
208*38e8c45fSAndroid Build Coastguard Worker }
209*38e8c45fSAndroid Build Coastguard Worker
onRefreshRateChangedDebug(const RefreshRateChangedDebugData & refreshRateChangedDebugData)210*38e8c45fSAndroid Build Coastguard Worker ::ndk::ScopedAStatus onRefreshRateChangedDebug(
211*38e8c45fSAndroid Build Coastguard Worker const RefreshRateChangedDebugData& refreshRateChangedDebugData) override {
212*38e8c45fSAndroid Build Coastguard Worker mCallback.onRefreshRateChangedDebug(refreshRateChangedDebugData);
213*38e8c45fSAndroid Build Coastguard Worker return ::ndk::ScopedAStatus::ok();
214*38e8c45fSAndroid Build Coastguard Worker }
215*38e8c45fSAndroid Build Coastguard Worker
onHotplugEvent(int64_t in_display,AidlDisplayHotplugEvent event)216*38e8c45fSAndroid Build Coastguard Worker ::ndk::ScopedAStatus onHotplugEvent(int64_t in_display,
217*38e8c45fSAndroid Build Coastguard Worker AidlDisplayHotplugEvent event) override {
218*38e8c45fSAndroid Build Coastguard Worker mCallback.onComposerHalHotplugEvent(translate<Display>(in_display), event);
219*38e8c45fSAndroid Build Coastguard Worker return ::ndk::ScopedAStatus::ok();
220*38e8c45fSAndroid Build Coastguard Worker }
221*38e8c45fSAndroid Build Coastguard Worker
onHdcpLevelsChanged(int64_t in_display,const AidlHdcpLevels & levels)222*38e8c45fSAndroid Build Coastguard Worker ::ndk::ScopedAStatus onHdcpLevelsChanged(int64_t in_display,
223*38e8c45fSAndroid Build Coastguard Worker const AidlHdcpLevels& levels) override {
224*38e8c45fSAndroid Build Coastguard Worker mCallback.onComposerHalHdcpLevelsChanged(translate<Display>(in_display), levels);
225*38e8c45fSAndroid Build Coastguard Worker return ::ndk::ScopedAStatus::ok();
226*38e8c45fSAndroid Build Coastguard Worker }
227*38e8c45fSAndroid Build Coastguard Worker
228*38e8c45fSAndroid Build Coastguard Worker private:
229*38e8c45fSAndroid Build Coastguard Worker HWC2::ComposerCallback& mCallback;
230*38e8c45fSAndroid Build Coastguard Worker };
231*38e8c45fSAndroid Build Coastguard Worker
instance(const std::string & serviceName)232*38e8c45fSAndroid Build Coastguard Worker std::string AidlComposer::instance(const std::string& serviceName) {
233*38e8c45fSAndroid Build Coastguard Worker return std::string(AidlIComposer::descriptor) + "/" + serviceName;
234*38e8c45fSAndroid Build Coastguard Worker }
235*38e8c45fSAndroid Build Coastguard Worker
isDeclared(const std::string & serviceName)236*38e8c45fSAndroid Build Coastguard Worker bool AidlComposer::isDeclared(const std::string& serviceName) {
237*38e8c45fSAndroid Build Coastguard Worker return AServiceManager_isDeclared(instance(serviceName).c_str());
238*38e8c45fSAndroid Build Coastguard Worker }
239*38e8c45fSAndroid Build Coastguard Worker
AidlComposer(const std::string & serviceName)240*38e8c45fSAndroid Build Coastguard Worker AidlComposer::AidlComposer(const std::string& serviceName) {
241*38e8c45fSAndroid Build Coastguard Worker // This only waits if the service is actually declared
242*38e8c45fSAndroid Build Coastguard Worker mAidlComposer = AidlIComposer::fromBinder(
243*38e8c45fSAndroid Build Coastguard Worker ndk::SpAIBinder(AServiceManager_waitForService(instance(serviceName).c_str())));
244*38e8c45fSAndroid Build Coastguard Worker if (!mAidlComposer) {
245*38e8c45fSAndroid Build Coastguard Worker LOG_ALWAYS_FATAL("Failed to get AIDL composer service");
246*38e8c45fSAndroid Build Coastguard Worker return;
247*38e8c45fSAndroid Build Coastguard Worker }
248*38e8c45fSAndroid Build Coastguard Worker
249*38e8c45fSAndroid Build Coastguard Worker if (!mAidlComposer->createClient(&mAidlComposerClient).isOk()) {
250*38e8c45fSAndroid Build Coastguard Worker LOG_ALWAYS_FATAL("Can't create AidlComposerClient, fallback to HIDL");
251*38e8c45fSAndroid Build Coastguard Worker return;
252*38e8c45fSAndroid Build Coastguard Worker }
253*38e8c45fSAndroid Build Coastguard Worker
254*38e8c45fSAndroid Build Coastguard Worker addReader(translate<Display>(kSingleReaderKey));
255*38e8c45fSAndroid Build Coastguard Worker
256*38e8c45fSAndroid Build Coastguard Worker // If unable to read interface version, then become backwards compatible.
257*38e8c45fSAndroid Build Coastguard Worker const auto status = mAidlComposerClient->getInterfaceVersion(&mComposerInterfaceVersion);
258*38e8c45fSAndroid Build Coastguard Worker if (!status.isOk()) {
259*38e8c45fSAndroid Build Coastguard Worker ALOGE("getInterfaceVersion for AidlComposer constructor failed %s",
260*38e8c45fSAndroid Build Coastguard Worker status.getDescription().c_str());
261*38e8c45fSAndroid Build Coastguard Worker }
262*38e8c45fSAndroid Build Coastguard Worker
263*38e8c45fSAndroid Build Coastguard Worker if (mComposerInterfaceVersion <= 1) {
264*38e8c45fSAndroid Build Coastguard Worker if (sysprop::clear_slots_with_set_layer_buffer(false)) {
265*38e8c45fSAndroid Build Coastguard Worker mClearSlotBuffer = sp<GraphicBuffer>::make(1, 1, PIXEL_FORMAT_RGBX_8888,
266*38e8c45fSAndroid Build Coastguard Worker GraphicBuffer::USAGE_HW_COMPOSER |
267*38e8c45fSAndroid Build Coastguard Worker GraphicBuffer::USAGE_SW_READ_OFTEN |
268*38e8c45fSAndroid Build Coastguard Worker GraphicBuffer::USAGE_SW_WRITE_OFTEN,
269*38e8c45fSAndroid Build Coastguard Worker "AidlComposer");
270*38e8c45fSAndroid Build Coastguard Worker if (!mClearSlotBuffer || mClearSlotBuffer->initCheck() != ::android::OK) {
271*38e8c45fSAndroid Build Coastguard Worker LOG_ALWAYS_FATAL("Failed to allocate a buffer for clearing layer buffer slots");
272*38e8c45fSAndroid Build Coastguard Worker return;
273*38e8c45fSAndroid Build Coastguard Worker }
274*38e8c45fSAndroid Build Coastguard Worker }
275*38e8c45fSAndroid Build Coastguard Worker }
276*38e8c45fSAndroid Build Coastguard Worker if (getLayerLifecycleBatchCommand()) {
277*38e8c45fSAndroid Build Coastguard Worker mEnableLayerCommandBatchingFlag =
278*38e8c45fSAndroid Build Coastguard Worker FlagManager::getInstance().enable_layer_command_batching();
279*38e8c45fSAndroid Build Coastguard Worker }
280*38e8c45fSAndroid Build Coastguard Worker ALOGI("Loaded AIDL composer3 HAL service");
281*38e8c45fSAndroid Build Coastguard Worker }
282*38e8c45fSAndroid Build Coastguard Worker
283*38e8c45fSAndroid Build Coastguard Worker AidlComposer::~AidlComposer() = default;
284*38e8c45fSAndroid Build Coastguard Worker
isSupported(OptionalFeature feature) const285*38e8c45fSAndroid Build Coastguard Worker bool AidlComposer::isSupported(OptionalFeature feature) const {
286*38e8c45fSAndroid Build Coastguard Worker switch (feature) {
287*38e8c45fSAndroid Build Coastguard Worker case OptionalFeature::RefreshRateSwitching:
288*38e8c45fSAndroid Build Coastguard Worker case OptionalFeature::ExpectedPresentTime:
289*38e8c45fSAndroid Build Coastguard Worker case OptionalFeature::DisplayBrightnessCommand:
290*38e8c45fSAndroid Build Coastguard Worker case OptionalFeature::KernelIdleTimer:
291*38e8c45fSAndroid Build Coastguard Worker case OptionalFeature::PhysicalDisplayOrientation:
292*38e8c45fSAndroid Build Coastguard Worker return true;
293*38e8c45fSAndroid Build Coastguard Worker }
294*38e8c45fSAndroid Build Coastguard Worker }
295*38e8c45fSAndroid Build Coastguard Worker
isVrrSupported() const296*38e8c45fSAndroid Build Coastguard Worker bool AidlComposer::isVrrSupported() const {
297*38e8c45fSAndroid Build Coastguard Worker return mComposerInterfaceVersion >= 3 && FlagManager::getInstance().vrr_config();
298*38e8c45fSAndroid Build Coastguard Worker }
299*38e8c45fSAndroid Build Coastguard Worker
getCapabilities()300*38e8c45fSAndroid Build Coastguard Worker std::vector<Capability> AidlComposer::getCapabilities() {
301*38e8c45fSAndroid Build Coastguard Worker std::vector<Capability> capabilities;
302*38e8c45fSAndroid Build Coastguard Worker const auto status = mAidlComposer->getCapabilities(&capabilities);
303*38e8c45fSAndroid Build Coastguard Worker if (!status.isOk()) {
304*38e8c45fSAndroid Build Coastguard Worker ALOGE("getCapabilities failed %s", status.getDescription().c_str());
305*38e8c45fSAndroid Build Coastguard Worker return {};
306*38e8c45fSAndroid Build Coastguard Worker }
307*38e8c45fSAndroid Build Coastguard Worker return capabilities;
308*38e8c45fSAndroid Build Coastguard Worker }
309*38e8c45fSAndroid Build Coastguard Worker
dumpDebugInfo()310*38e8c45fSAndroid Build Coastguard Worker std::string AidlComposer::dumpDebugInfo() {
311*38e8c45fSAndroid Build Coastguard Worker int pipefds[2];
312*38e8c45fSAndroid Build Coastguard Worker int result = pipe(pipefds);
313*38e8c45fSAndroid Build Coastguard Worker if (result < 0) {
314*38e8c45fSAndroid Build Coastguard Worker ALOGE("dumpDebugInfo: pipe failed: %s", strerror(errno));
315*38e8c45fSAndroid Build Coastguard Worker return {};
316*38e8c45fSAndroid Build Coastguard Worker }
317*38e8c45fSAndroid Build Coastguard Worker
318*38e8c45fSAndroid Build Coastguard Worker std::string str;
319*38e8c45fSAndroid Build Coastguard Worker // Use other thread to read pipe to prevent
320*38e8c45fSAndroid Build Coastguard Worker // pipe is full, making HWC be blocked in writing.
321*38e8c45fSAndroid Build Coastguard Worker std::thread t([&]() {
322*38e8c45fSAndroid Build Coastguard Worker base::ReadFdToString(pipefds[0], &str);
323*38e8c45fSAndroid Build Coastguard Worker });
324*38e8c45fSAndroid Build Coastguard Worker const auto status = mAidlComposer->dump(pipefds[1], /*args*/ nullptr, /*numArgs*/ 0);
325*38e8c45fSAndroid Build Coastguard Worker // Close the write-end of the pipe to make sure that when reading from the
326*38e8c45fSAndroid Build Coastguard Worker // read-end we will get eof instead of blocking forever
327*38e8c45fSAndroid Build Coastguard Worker close(pipefds[1]);
328*38e8c45fSAndroid Build Coastguard Worker
329*38e8c45fSAndroid Build Coastguard Worker if (status != STATUS_OK) {
330*38e8c45fSAndroid Build Coastguard Worker ALOGE("dumpDebugInfo: dump failed: %d", status);
331*38e8c45fSAndroid Build Coastguard Worker }
332*38e8c45fSAndroid Build Coastguard Worker
333*38e8c45fSAndroid Build Coastguard Worker t.join();
334*38e8c45fSAndroid Build Coastguard Worker close(pipefds[0]);
335*38e8c45fSAndroid Build Coastguard Worker
336*38e8c45fSAndroid Build Coastguard Worker std::string hash;
337*38e8c45fSAndroid Build Coastguard Worker mAidlComposer->getInterfaceHash(&hash);
338*38e8c45fSAndroid Build Coastguard Worker return std::string(mAidlComposer->descriptor) +
339*38e8c45fSAndroid Build Coastguard Worker " version:" + std::to_string(mComposerInterfaceVersion) + " hash:" + hash + str;
340*38e8c45fSAndroid Build Coastguard Worker }
341*38e8c45fSAndroid Build Coastguard Worker
registerCallback(HWC2::ComposerCallback & callback)342*38e8c45fSAndroid Build Coastguard Worker void AidlComposer::registerCallback(HWC2::ComposerCallback& callback) {
343*38e8c45fSAndroid Build Coastguard Worker if (mAidlComposerCallback) {
344*38e8c45fSAndroid Build Coastguard Worker ALOGE("Callback already registered");
345*38e8c45fSAndroid Build Coastguard Worker }
346*38e8c45fSAndroid Build Coastguard Worker
347*38e8c45fSAndroid Build Coastguard Worker mAidlComposerCallback = ndk::SharedRefBase::make<AidlIComposerCallbackWrapper>(callback);
348*38e8c45fSAndroid Build Coastguard Worker
349*38e8c45fSAndroid Build Coastguard Worker ndk::SpAIBinder binder = mAidlComposerCallback->asBinder();
350*38e8c45fSAndroid Build Coastguard Worker AIBinder_setMinSchedulerPolicy(binder.get(), SCHED_FIFO, 2);
351*38e8c45fSAndroid Build Coastguard Worker
352*38e8c45fSAndroid Build Coastguard Worker const auto status = mAidlComposerClient->registerCallback(mAidlComposerCallback);
353*38e8c45fSAndroid Build Coastguard Worker if (!status.isOk()) {
354*38e8c45fSAndroid Build Coastguard Worker ALOGE("registerCallback failed %s", status.getDescription().c_str());
355*38e8c45fSAndroid Build Coastguard Worker }
356*38e8c45fSAndroid Build Coastguard Worker }
357*38e8c45fSAndroid Build Coastguard Worker
executeCommands(Display display)358*38e8c45fSAndroid Build Coastguard Worker Error AidlComposer::executeCommands(Display display) {
359*38e8c45fSAndroid Build Coastguard Worker mMutex.lock_shared();
360*38e8c45fSAndroid Build Coastguard Worker auto error = execute(display);
361*38e8c45fSAndroid Build Coastguard Worker mMutex.unlock_shared();
362*38e8c45fSAndroid Build Coastguard Worker return error;
363*38e8c45fSAndroid Build Coastguard Worker }
364*38e8c45fSAndroid Build Coastguard Worker
getMaxVirtualDisplayCount()365*38e8c45fSAndroid Build Coastguard Worker uint32_t AidlComposer::getMaxVirtualDisplayCount() {
366*38e8c45fSAndroid Build Coastguard Worker int32_t count = 0;
367*38e8c45fSAndroid Build Coastguard Worker const auto status = mAidlComposerClient->getMaxVirtualDisplayCount(&count);
368*38e8c45fSAndroid Build Coastguard Worker if (!status.isOk()) {
369*38e8c45fSAndroid Build Coastguard Worker ALOGE("getMaxVirtualDisplayCount failed %s", status.getDescription().c_str());
370*38e8c45fSAndroid Build Coastguard Worker return 0;
371*38e8c45fSAndroid Build Coastguard Worker }
372*38e8c45fSAndroid Build Coastguard Worker return static_cast<uint32_t>(count);
373*38e8c45fSAndroid Build Coastguard Worker }
374*38e8c45fSAndroid Build Coastguard Worker
createVirtualDisplay(uint32_t width,uint32_t height,PixelFormat * format,Display * outDisplay)375*38e8c45fSAndroid Build Coastguard Worker Error AidlComposer::createVirtualDisplay(uint32_t width, uint32_t height, PixelFormat* format,
376*38e8c45fSAndroid Build Coastguard Worker Display* outDisplay) {
377*38e8c45fSAndroid Build Coastguard Worker using AidlPixelFormat = aidl::android::hardware::graphics::common::PixelFormat;
378*38e8c45fSAndroid Build Coastguard Worker const int32_t bufferSlotCount = 1;
379*38e8c45fSAndroid Build Coastguard Worker VirtualDisplay virtualDisplay;
380*38e8c45fSAndroid Build Coastguard Worker const auto status =
381*38e8c45fSAndroid Build Coastguard Worker mAidlComposerClient->createVirtualDisplay(static_cast<int32_t>(width),
382*38e8c45fSAndroid Build Coastguard Worker static_cast<int32_t>(height),
383*38e8c45fSAndroid Build Coastguard Worker static_cast<AidlPixelFormat>(*format),
384*38e8c45fSAndroid Build Coastguard Worker bufferSlotCount, &virtualDisplay);
385*38e8c45fSAndroid Build Coastguard Worker
386*38e8c45fSAndroid Build Coastguard Worker if (!status.isOk()) {
387*38e8c45fSAndroid Build Coastguard Worker ALOGE("createVirtualDisplay failed %s", status.getDescription().c_str());
388*38e8c45fSAndroid Build Coastguard Worker return static_cast<Error>(status.getServiceSpecificError());
389*38e8c45fSAndroid Build Coastguard Worker }
390*38e8c45fSAndroid Build Coastguard Worker
391*38e8c45fSAndroid Build Coastguard Worker *outDisplay = translate<Display>(virtualDisplay.display);
392*38e8c45fSAndroid Build Coastguard Worker *format = static_cast<PixelFormat>(virtualDisplay.format);
393*38e8c45fSAndroid Build Coastguard Worker addDisplay(translate<Display>(virtualDisplay.display));
394*38e8c45fSAndroid Build Coastguard Worker return Error::NONE;
395*38e8c45fSAndroid Build Coastguard Worker }
396*38e8c45fSAndroid Build Coastguard Worker
destroyVirtualDisplay(Display display)397*38e8c45fSAndroid Build Coastguard Worker Error AidlComposer::destroyVirtualDisplay(Display display) {
398*38e8c45fSAndroid Build Coastguard Worker const auto status = mAidlComposerClient->destroyVirtualDisplay(translate<int64_t>(display));
399*38e8c45fSAndroid Build Coastguard Worker if (!status.isOk()) {
400*38e8c45fSAndroid Build Coastguard Worker ALOGE("destroyVirtualDisplay failed %s", status.getDescription().c_str());
401*38e8c45fSAndroid Build Coastguard Worker return static_cast<Error>(status.getServiceSpecificError());
402*38e8c45fSAndroid Build Coastguard Worker }
403*38e8c45fSAndroid Build Coastguard Worker removeDisplay(display);
404*38e8c45fSAndroid Build Coastguard Worker return Error::NONE;
405*38e8c45fSAndroid Build Coastguard Worker }
406*38e8c45fSAndroid Build Coastguard Worker
acceptDisplayChanges(Display display)407*38e8c45fSAndroid Build Coastguard Worker Error AidlComposer::acceptDisplayChanges(Display display) {
408*38e8c45fSAndroid Build Coastguard Worker Error error = Error::NONE;
409*38e8c45fSAndroid Build Coastguard Worker mMutex.lock_shared();
410*38e8c45fSAndroid Build Coastguard Worker if (auto writer = getWriter(display)) {
411*38e8c45fSAndroid Build Coastguard Worker writer->get().acceptDisplayChanges(translate<int64_t>(display));
412*38e8c45fSAndroid Build Coastguard Worker } else {
413*38e8c45fSAndroid Build Coastguard Worker error = Error::BAD_DISPLAY;
414*38e8c45fSAndroid Build Coastguard Worker }
415*38e8c45fSAndroid Build Coastguard Worker mMutex.unlock_shared();
416*38e8c45fSAndroid Build Coastguard Worker return error;
417*38e8c45fSAndroid Build Coastguard Worker }
418*38e8c45fSAndroid Build Coastguard Worker
createLayer(Display display,Layer * outLayer)419*38e8c45fSAndroid Build Coastguard Worker Error AidlComposer::createLayer(Display display, Layer* outLayer) {
420*38e8c45fSAndroid Build Coastguard Worker int64_t layer;
421*38e8c45fSAndroid Build Coastguard Worker Error error = Error::NONE;
422*38e8c45fSAndroid Build Coastguard Worker if (!mEnableLayerCommandBatchingFlag) {
423*38e8c45fSAndroid Build Coastguard Worker const auto status = mAidlComposerClient->createLayer(translate<int64_t>(display),
424*38e8c45fSAndroid Build Coastguard Worker kMaxLayerBufferCount, &layer);
425*38e8c45fSAndroid Build Coastguard Worker if (!status.isOk()) {
426*38e8c45fSAndroid Build Coastguard Worker ALOGE("createLayer failed %s", status.getDescription().c_str());
427*38e8c45fSAndroid Build Coastguard Worker return static_cast<Error>(status.getServiceSpecificError());
428*38e8c45fSAndroid Build Coastguard Worker }
429*38e8c45fSAndroid Build Coastguard Worker } else {
430*38e8c45fSAndroid Build Coastguard Worker // generate a unique layerID. map in AidlComposer with <SF_layerID, HWC_layerID>
431*38e8c45fSAndroid Build Coastguard Worker // Add this as a new displayCommand in execute command.
432*38e8c45fSAndroid Build Coastguard Worker // return the SF generated layerID instead of calling HWC
433*38e8c45fSAndroid Build Coastguard Worker layer = mLayerID++;
434*38e8c45fSAndroid Build Coastguard Worker mMutex.lock_shared();
435*38e8c45fSAndroid Build Coastguard Worker if (auto writer = getWriter(display)) {
436*38e8c45fSAndroid Build Coastguard Worker writer->get().setLayerLifecycleBatchCommandType(translate<int64_t>(display),
437*38e8c45fSAndroid Build Coastguard Worker translate<int64_t>(layer),
438*38e8c45fSAndroid Build Coastguard Worker LayerLifecycleBatchCommandType::CREATE);
439*38e8c45fSAndroid Build Coastguard Worker writer->get().setNewBufferSlotCount(translate<int64_t>(display),
440*38e8c45fSAndroid Build Coastguard Worker translate<int64_t>(layer), kMaxLayerBufferCount);
441*38e8c45fSAndroid Build Coastguard Worker } else {
442*38e8c45fSAndroid Build Coastguard Worker error = Error::BAD_DISPLAY;
443*38e8c45fSAndroid Build Coastguard Worker }
444*38e8c45fSAndroid Build Coastguard Worker mMutex.unlock_shared();
445*38e8c45fSAndroid Build Coastguard Worker }
446*38e8c45fSAndroid Build Coastguard Worker *outLayer = translate<Layer>(layer);
447*38e8c45fSAndroid Build Coastguard Worker return error;
448*38e8c45fSAndroid Build Coastguard Worker }
449*38e8c45fSAndroid Build Coastguard Worker
destroyLayer(Display display,Layer layer)450*38e8c45fSAndroid Build Coastguard Worker Error AidlComposer::destroyLayer(Display display, Layer layer) {
451*38e8c45fSAndroid Build Coastguard Worker Error error = Error::NONE;
452*38e8c45fSAndroid Build Coastguard Worker if (!mEnableLayerCommandBatchingFlag) {
453*38e8c45fSAndroid Build Coastguard Worker const auto status = mAidlComposerClient->destroyLayer(translate<int64_t>(display),
454*38e8c45fSAndroid Build Coastguard Worker translate<int64_t>(layer));
455*38e8c45fSAndroid Build Coastguard Worker if (!status.isOk()) {
456*38e8c45fSAndroid Build Coastguard Worker ALOGE("destroyLayer failed %s", status.getDescription().c_str());
457*38e8c45fSAndroid Build Coastguard Worker return static_cast<Error>(status.getServiceSpecificError());
458*38e8c45fSAndroid Build Coastguard Worker }
459*38e8c45fSAndroid Build Coastguard Worker } else {
460*38e8c45fSAndroid Build Coastguard Worker mMutex.lock_shared();
461*38e8c45fSAndroid Build Coastguard Worker if (auto writer = getWriter(display)) {
462*38e8c45fSAndroid Build Coastguard Worker writer->get()
463*38e8c45fSAndroid Build Coastguard Worker .setLayerLifecycleBatchCommandType(translate<int64_t>(display),
464*38e8c45fSAndroid Build Coastguard Worker translate<int64_t>(layer),
465*38e8c45fSAndroid Build Coastguard Worker LayerLifecycleBatchCommandType::DESTROY);
466*38e8c45fSAndroid Build Coastguard Worker } else {
467*38e8c45fSAndroid Build Coastguard Worker error = Error::BAD_DISPLAY;
468*38e8c45fSAndroid Build Coastguard Worker }
469*38e8c45fSAndroid Build Coastguard Worker mMutex.unlock_shared();
470*38e8c45fSAndroid Build Coastguard Worker }
471*38e8c45fSAndroid Build Coastguard Worker
472*38e8c45fSAndroid Build Coastguard Worker return error;
473*38e8c45fSAndroid Build Coastguard Worker }
474*38e8c45fSAndroid Build Coastguard Worker
getActiveConfig(Display display,Config * outConfig)475*38e8c45fSAndroid Build Coastguard Worker Error AidlComposer::getActiveConfig(Display display, Config* outConfig) {
476*38e8c45fSAndroid Build Coastguard Worker int32_t config;
477*38e8c45fSAndroid Build Coastguard Worker const auto status = mAidlComposerClient->getActiveConfig(translate<int64_t>(display), &config);
478*38e8c45fSAndroid Build Coastguard Worker if (!status.isOk()) {
479*38e8c45fSAndroid Build Coastguard Worker ALOGE("getActiveConfig failed %s", status.getDescription().c_str());
480*38e8c45fSAndroid Build Coastguard Worker return static_cast<Error>(status.getServiceSpecificError());
481*38e8c45fSAndroid Build Coastguard Worker }
482*38e8c45fSAndroid Build Coastguard Worker *outConfig = translate<Config>(config);
483*38e8c45fSAndroid Build Coastguard Worker return Error::NONE;
484*38e8c45fSAndroid Build Coastguard Worker }
485*38e8c45fSAndroid Build Coastguard Worker
getChangedCompositionTypes(Display display,std::vector<Layer> * outLayers,std::vector<aidl::android::hardware::graphics::composer3::Composition> * outTypes)486*38e8c45fSAndroid Build Coastguard Worker Error AidlComposer::getChangedCompositionTypes(
487*38e8c45fSAndroid Build Coastguard Worker Display display, std::vector<Layer>* outLayers,
488*38e8c45fSAndroid Build Coastguard Worker std::vector<aidl::android::hardware::graphics::composer3::Composition>* outTypes) {
489*38e8c45fSAndroid Build Coastguard Worker std::vector<ChangedCompositionLayer> changedLayers;
490*38e8c45fSAndroid Build Coastguard Worker Error error = Error::NONE;
491*38e8c45fSAndroid Build Coastguard Worker {
492*38e8c45fSAndroid Build Coastguard Worker mMutex.lock_shared();
493*38e8c45fSAndroid Build Coastguard Worker if (auto reader = getReader(display)) {
494*38e8c45fSAndroid Build Coastguard Worker changedLayers = reader->get().takeChangedCompositionTypes(translate<int64_t>(display));
495*38e8c45fSAndroid Build Coastguard Worker } else {
496*38e8c45fSAndroid Build Coastguard Worker error = Error::BAD_DISPLAY;
497*38e8c45fSAndroid Build Coastguard Worker }
498*38e8c45fSAndroid Build Coastguard Worker mMutex.unlock_shared();
499*38e8c45fSAndroid Build Coastguard Worker }
500*38e8c45fSAndroid Build Coastguard Worker outLayers->reserve(changedLayers.size());
501*38e8c45fSAndroid Build Coastguard Worker outTypes->reserve(changedLayers.size());
502*38e8c45fSAndroid Build Coastguard Worker
503*38e8c45fSAndroid Build Coastguard Worker for (const auto& layer : changedLayers) {
504*38e8c45fSAndroid Build Coastguard Worker outLayers->emplace_back(translate<Layer>(layer.layer));
505*38e8c45fSAndroid Build Coastguard Worker outTypes->emplace_back(layer.composition);
506*38e8c45fSAndroid Build Coastguard Worker }
507*38e8c45fSAndroid Build Coastguard Worker return error;
508*38e8c45fSAndroid Build Coastguard Worker }
509*38e8c45fSAndroid Build Coastguard Worker
getColorModes(Display display,std::vector<ColorMode> * outModes)510*38e8c45fSAndroid Build Coastguard Worker Error AidlComposer::getColorModes(Display display, std::vector<ColorMode>* outModes) {
511*38e8c45fSAndroid Build Coastguard Worker std::vector<AidlColorMode> modes;
512*38e8c45fSAndroid Build Coastguard Worker const auto status = mAidlComposerClient->getColorModes(translate<int64_t>(display), &modes);
513*38e8c45fSAndroid Build Coastguard Worker if (!status.isOk()) {
514*38e8c45fSAndroid Build Coastguard Worker ALOGE("getColorModes failed %s", status.getDescription().c_str());
515*38e8c45fSAndroid Build Coastguard Worker return static_cast<Error>(status.getServiceSpecificError());
516*38e8c45fSAndroid Build Coastguard Worker }
517*38e8c45fSAndroid Build Coastguard Worker *outModes = translate<ColorMode>(modes);
518*38e8c45fSAndroid Build Coastguard Worker return Error::NONE;
519*38e8c45fSAndroid Build Coastguard Worker }
520*38e8c45fSAndroid Build Coastguard Worker
getDisplayAttribute(Display display,Config config,IComposerClient::Attribute attribute,int32_t * outValue)521*38e8c45fSAndroid Build Coastguard Worker Error AidlComposer::getDisplayAttribute(Display display, Config config,
522*38e8c45fSAndroid Build Coastguard Worker IComposerClient::Attribute attribute, int32_t* outValue) {
523*38e8c45fSAndroid Build Coastguard Worker #pragma clang diagnostic push
524*38e8c45fSAndroid Build Coastguard Worker #pragma clang diagnostic ignored "-Wdeprecated-declarations"
525*38e8c45fSAndroid Build Coastguard Worker const auto status =
526*38e8c45fSAndroid Build Coastguard Worker mAidlComposerClient->getDisplayAttribute(translate<int64_t>(display),
527*38e8c45fSAndroid Build Coastguard Worker translate<int32_t>(config),
528*38e8c45fSAndroid Build Coastguard Worker static_cast<AidlDisplayAttribute>(attribute),
529*38e8c45fSAndroid Build Coastguard Worker outValue);
530*38e8c45fSAndroid Build Coastguard Worker #pragma clang diagnostic pop
531*38e8c45fSAndroid Build Coastguard Worker
532*38e8c45fSAndroid Build Coastguard Worker if (!status.isOk()) {
533*38e8c45fSAndroid Build Coastguard Worker ALOGE("getDisplayAttribute failed %s", status.getDescription().c_str());
534*38e8c45fSAndroid Build Coastguard Worker return static_cast<Error>(status.getServiceSpecificError());
535*38e8c45fSAndroid Build Coastguard Worker }
536*38e8c45fSAndroid Build Coastguard Worker return Error::NONE;
537*38e8c45fSAndroid Build Coastguard Worker }
538*38e8c45fSAndroid Build Coastguard Worker
getDisplayConfigs(Display display,std::vector<Config> * outConfigs)539*38e8c45fSAndroid Build Coastguard Worker Error AidlComposer::getDisplayConfigs(Display display, std::vector<Config>* outConfigs) {
540*38e8c45fSAndroid Build Coastguard Worker std::vector<int32_t> configs;
541*38e8c45fSAndroid Build Coastguard Worker
542*38e8c45fSAndroid Build Coastguard Worker #pragma clang diagnostic push
543*38e8c45fSAndroid Build Coastguard Worker #pragma clang diagnostic ignored "-Wdeprecated-declarations"
544*38e8c45fSAndroid Build Coastguard Worker const auto status =
545*38e8c45fSAndroid Build Coastguard Worker mAidlComposerClient->getDisplayConfigs(translate<int64_t>(display), &configs);
546*38e8c45fSAndroid Build Coastguard Worker #pragma clang diagnostic pop
547*38e8c45fSAndroid Build Coastguard Worker
548*38e8c45fSAndroid Build Coastguard Worker if (!status.isOk()) {
549*38e8c45fSAndroid Build Coastguard Worker ALOGE("getDisplayConfigs failed %s", status.getDescription().c_str());
550*38e8c45fSAndroid Build Coastguard Worker return static_cast<Error>(status.getServiceSpecificError());
551*38e8c45fSAndroid Build Coastguard Worker }
552*38e8c45fSAndroid Build Coastguard Worker *outConfigs = translate<Config>(configs);
553*38e8c45fSAndroid Build Coastguard Worker return Error::NONE;
554*38e8c45fSAndroid Build Coastguard Worker }
555*38e8c45fSAndroid Build Coastguard Worker
getDisplayConfigurations(Display display,int32_t maxFrameIntervalNs,std::vector<DisplayConfiguration> * outConfigs)556*38e8c45fSAndroid Build Coastguard Worker Error AidlComposer::getDisplayConfigurations(Display display, int32_t maxFrameIntervalNs,
557*38e8c45fSAndroid Build Coastguard Worker std::vector<DisplayConfiguration>* outConfigs) {
558*38e8c45fSAndroid Build Coastguard Worker const auto status =
559*38e8c45fSAndroid Build Coastguard Worker mAidlComposerClient->getDisplayConfigurations(translate<int64_t>(display),
560*38e8c45fSAndroid Build Coastguard Worker maxFrameIntervalNs, outConfigs);
561*38e8c45fSAndroid Build Coastguard Worker if (!status.isOk()) {
562*38e8c45fSAndroid Build Coastguard Worker ALOGE("getDisplayConfigurations failed %s", status.getDescription().c_str());
563*38e8c45fSAndroid Build Coastguard Worker return static_cast<Error>(status.getServiceSpecificError());
564*38e8c45fSAndroid Build Coastguard Worker }
565*38e8c45fSAndroid Build Coastguard Worker
566*38e8c45fSAndroid Build Coastguard Worker return Error::NONE;
567*38e8c45fSAndroid Build Coastguard Worker }
568*38e8c45fSAndroid Build Coastguard Worker
getDisplayName(Display display,std::string * outName)569*38e8c45fSAndroid Build Coastguard Worker Error AidlComposer::getDisplayName(Display display, std::string* outName) {
570*38e8c45fSAndroid Build Coastguard Worker const auto status = mAidlComposerClient->getDisplayName(translate<int64_t>(display), outName);
571*38e8c45fSAndroid Build Coastguard Worker if (!status.isOk()) {
572*38e8c45fSAndroid Build Coastguard Worker ALOGE("getDisplayName failed %s", status.getDescription().c_str());
573*38e8c45fSAndroid Build Coastguard Worker return static_cast<Error>(status.getServiceSpecificError());
574*38e8c45fSAndroid Build Coastguard Worker }
575*38e8c45fSAndroid Build Coastguard Worker return Error::NONE;
576*38e8c45fSAndroid Build Coastguard Worker }
577*38e8c45fSAndroid Build Coastguard Worker
getDisplayRequests(Display display,uint32_t * outDisplayRequestMask,std::vector<Layer> * outLayers,std::vector<uint32_t> * outLayerRequestMasks)578*38e8c45fSAndroid Build Coastguard Worker Error AidlComposer::getDisplayRequests(Display display, uint32_t* outDisplayRequestMask,
579*38e8c45fSAndroid Build Coastguard Worker std::vector<Layer>* outLayers,
580*38e8c45fSAndroid Build Coastguard Worker std::vector<uint32_t>* outLayerRequestMasks) {
581*38e8c45fSAndroid Build Coastguard Worker Error error = Error::NONE;
582*38e8c45fSAndroid Build Coastguard Worker DisplayRequest displayRequests;
583*38e8c45fSAndroid Build Coastguard Worker {
584*38e8c45fSAndroid Build Coastguard Worker mMutex.lock_shared();
585*38e8c45fSAndroid Build Coastguard Worker if (auto reader = getReader(display)) {
586*38e8c45fSAndroid Build Coastguard Worker displayRequests = reader->get().takeDisplayRequests(translate<int64_t>(display));
587*38e8c45fSAndroid Build Coastguard Worker } else {
588*38e8c45fSAndroid Build Coastguard Worker error = Error::BAD_DISPLAY;
589*38e8c45fSAndroid Build Coastguard Worker }
590*38e8c45fSAndroid Build Coastguard Worker mMutex.unlock_shared();
591*38e8c45fSAndroid Build Coastguard Worker }
592*38e8c45fSAndroid Build Coastguard Worker *outDisplayRequestMask = translate<uint32_t>(displayRequests.mask);
593*38e8c45fSAndroid Build Coastguard Worker outLayers->reserve(displayRequests.layerRequests.size());
594*38e8c45fSAndroid Build Coastguard Worker outLayerRequestMasks->reserve(displayRequests.layerRequests.size());
595*38e8c45fSAndroid Build Coastguard Worker
596*38e8c45fSAndroid Build Coastguard Worker for (const auto& layer : displayRequests.layerRequests) {
597*38e8c45fSAndroid Build Coastguard Worker outLayers->emplace_back(translate<Layer>(layer.layer));
598*38e8c45fSAndroid Build Coastguard Worker outLayerRequestMasks->emplace_back(translate<uint32_t>(layer.mask));
599*38e8c45fSAndroid Build Coastguard Worker }
600*38e8c45fSAndroid Build Coastguard Worker return error;
601*38e8c45fSAndroid Build Coastguard Worker }
602*38e8c45fSAndroid Build Coastguard Worker
getDozeSupport(Display display,bool * outSupport)603*38e8c45fSAndroid Build Coastguard Worker Error AidlComposer::getDozeSupport(Display display, bool* outSupport) {
604*38e8c45fSAndroid Build Coastguard Worker std::vector<AidlDisplayCapability> capabilities;
605*38e8c45fSAndroid Build Coastguard Worker const auto status =
606*38e8c45fSAndroid Build Coastguard Worker mAidlComposerClient->getDisplayCapabilities(translate<int64_t>(display), &capabilities);
607*38e8c45fSAndroid Build Coastguard Worker if (!status.isOk()) {
608*38e8c45fSAndroid Build Coastguard Worker ALOGE("getDisplayCapabilities failed %s", status.getDescription().c_str());
609*38e8c45fSAndroid Build Coastguard Worker return static_cast<Error>(status.getServiceSpecificError());
610*38e8c45fSAndroid Build Coastguard Worker }
611*38e8c45fSAndroid Build Coastguard Worker *outSupport = std::find(capabilities.begin(), capabilities.end(),
612*38e8c45fSAndroid Build Coastguard Worker AidlDisplayCapability::DOZE) != capabilities.end();
613*38e8c45fSAndroid Build Coastguard Worker return Error::NONE;
614*38e8c45fSAndroid Build Coastguard Worker }
615*38e8c45fSAndroid Build Coastguard Worker
hasDisplayIdleTimerCapability(Display display,bool * outSupport)616*38e8c45fSAndroid Build Coastguard Worker Error AidlComposer::hasDisplayIdleTimerCapability(Display display, bool* outSupport) {
617*38e8c45fSAndroid Build Coastguard Worker std::vector<AidlDisplayCapability> capabilities;
618*38e8c45fSAndroid Build Coastguard Worker const auto status =
619*38e8c45fSAndroid Build Coastguard Worker mAidlComposerClient->getDisplayCapabilities(translate<int64_t>(display), &capabilities);
620*38e8c45fSAndroid Build Coastguard Worker if (!status.isOk()) {
621*38e8c45fSAndroid Build Coastguard Worker ALOGE("getDisplayCapabilities failed %s", status.getDescription().c_str());
622*38e8c45fSAndroid Build Coastguard Worker return static_cast<Error>(status.getServiceSpecificError());
623*38e8c45fSAndroid Build Coastguard Worker }
624*38e8c45fSAndroid Build Coastguard Worker *outSupport = std::find(capabilities.begin(), capabilities.end(),
625*38e8c45fSAndroid Build Coastguard Worker AidlDisplayCapability::DISPLAY_IDLE_TIMER) != capabilities.end();
626*38e8c45fSAndroid Build Coastguard Worker return Error::NONE;
627*38e8c45fSAndroid Build Coastguard Worker }
628*38e8c45fSAndroid Build Coastguard Worker
getHdrCapabilities(Display display,std::vector<Hdr> * outTypes,float * outMaxLuminance,float * outMaxAverageLuminance,float * outMinLuminance)629*38e8c45fSAndroid Build Coastguard Worker Error AidlComposer::getHdrCapabilities(Display display, std::vector<Hdr>* outTypes,
630*38e8c45fSAndroid Build Coastguard Worker float* outMaxLuminance, float* outMaxAverageLuminance,
631*38e8c45fSAndroid Build Coastguard Worker float* outMinLuminance) {
632*38e8c45fSAndroid Build Coastguard Worker AidlHdrCapabilities capabilities;
633*38e8c45fSAndroid Build Coastguard Worker const auto status =
634*38e8c45fSAndroid Build Coastguard Worker mAidlComposerClient->getHdrCapabilities(translate<int64_t>(display), &capabilities);
635*38e8c45fSAndroid Build Coastguard Worker if (!status.isOk()) {
636*38e8c45fSAndroid Build Coastguard Worker ALOGE("getHdrCapabilities failed %s", status.getDescription().c_str());
637*38e8c45fSAndroid Build Coastguard Worker return static_cast<Error>(status.getServiceSpecificError());
638*38e8c45fSAndroid Build Coastguard Worker }
639*38e8c45fSAndroid Build Coastguard Worker
640*38e8c45fSAndroid Build Coastguard Worker *outTypes = capabilities.types;
641*38e8c45fSAndroid Build Coastguard Worker *outMaxLuminance = capabilities.maxLuminance;
642*38e8c45fSAndroid Build Coastguard Worker *outMaxAverageLuminance = capabilities.maxAverageLuminance;
643*38e8c45fSAndroid Build Coastguard Worker *outMinLuminance = capabilities.minLuminance;
644*38e8c45fSAndroid Build Coastguard Worker return Error::NONE;
645*38e8c45fSAndroid Build Coastguard Worker }
646*38e8c45fSAndroid Build Coastguard Worker
getLayerLifecycleBatchCommand()647*38e8c45fSAndroid Build Coastguard Worker bool AidlComposer::getLayerLifecycleBatchCommand() {
648*38e8c45fSAndroid Build Coastguard Worker std::vector<Capability> capabilities = getCapabilities();
649*38e8c45fSAndroid Build Coastguard Worker bool hasCapability = std::find(capabilities.begin(), capabilities.end(),
650*38e8c45fSAndroid Build Coastguard Worker Capability::LAYER_LIFECYCLE_BATCH_COMMAND) != capabilities.end();
651*38e8c45fSAndroid Build Coastguard Worker return hasCapability;
652*38e8c45fSAndroid Build Coastguard Worker }
653*38e8c45fSAndroid Build Coastguard Worker
getOverlaySupport(AidlOverlayProperties * outProperties)654*38e8c45fSAndroid Build Coastguard Worker Error AidlComposer::getOverlaySupport(AidlOverlayProperties* outProperties) {
655*38e8c45fSAndroid Build Coastguard Worker const auto status = mAidlComposerClient->getOverlaySupport(outProperties);
656*38e8c45fSAndroid Build Coastguard Worker if (!status.isOk()) {
657*38e8c45fSAndroid Build Coastguard Worker ALOGE("getOverlaySupport failed %s", status.getDescription().c_str());
658*38e8c45fSAndroid Build Coastguard Worker return static_cast<Error>(status.getServiceSpecificError());
659*38e8c45fSAndroid Build Coastguard Worker }
660*38e8c45fSAndroid Build Coastguard Worker return Error::NONE;
661*38e8c45fSAndroid Build Coastguard Worker }
662*38e8c45fSAndroid Build Coastguard Worker
getReleaseFences(Display display,std::vector<Layer> * outLayers,std::vector<int> * outReleaseFences)663*38e8c45fSAndroid Build Coastguard Worker Error AidlComposer::getReleaseFences(Display display, std::vector<Layer>* outLayers,
664*38e8c45fSAndroid Build Coastguard Worker std::vector<int>* outReleaseFences) {
665*38e8c45fSAndroid Build Coastguard Worker Error error = Error::NONE;
666*38e8c45fSAndroid Build Coastguard Worker std::vector<ReleaseFences::Layer> fences;
667*38e8c45fSAndroid Build Coastguard Worker {
668*38e8c45fSAndroid Build Coastguard Worker mMutex.lock_shared();
669*38e8c45fSAndroid Build Coastguard Worker if (auto reader = getReader(display)) {
670*38e8c45fSAndroid Build Coastguard Worker fences = reader->get().takeReleaseFences(translate<int64_t>(display));
671*38e8c45fSAndroid Build Coastguard Worker } else {
672*38e8c45fSAndroid Build Coastguard Worker error = Error::BAD_DISPLAY;
673*38e8c45fSAndroid Build Coastguard Worker }
674*38e8c45fSAndroid Build Coastguard Worker mMutex.unlock_shared();
675*38e8c45fSAndroid Build Coastguard Worker }
676*38e8c45fSAndroid Build Coastguard Worker outLayers->reserve(fences.size());
677*38e8c45fSAndroid Build Coastguard Worker outReleaseFences->reserve(fences.size());
678*38e8c45fSAndroid Build Coastguard Worker
679*38e8c45fSAndroid Build Coastguard Worker for (auto& fence : fences) {
680*38e8c45fSAndroid Build Coastguard Worker outLayers->emplace_back(translate<Layer>(fence.layer));
681*38e8c45fSAndroid Build Coastguard Worker // take ownership
682*38e8c45fSAndroid Build Coastguard Worker const int fenceOwner = fence.fence.get();
683*38e8c45fSAndroid Build Coastguard Worker *fence.fence.getR() = -1;
684*38e8c45fSAndroid Build Coastguard Worker outReleaseFences->emplace_back(fenceOwner);
685*38e8c45fSAndroid Build Coastguard Worker }
686*38e8c45fSAndroid Build Coastguard Worker return error;
687*38e8c45fSAndroid Build Coastguard Worker }
688*38e8c45fSAndroid Build Coastguard Worker
presentDisplay(Display display,int * outPresentFence)689*38e8c45fSAndroid Build Coastguard Worker Error AidlComposer::presentDisplay(Display display, int* outPresentFence) {
690*38e8c45fSAndroid Build Coastguard Worker const auto displayId = translate<int64_t>(display);
691*38e8c45fSAndroid Build Coastguard Worker SFTRACE_FORMAT("HwcPresentDisplay %" PRId64, displayId);
692*38e8c45fSAndroid Build Coastguard Worker
693*38e8c45fSAndroid Build Coastguard Worker Error error = Error::NONE;
694*38e8c45fSAndroid Build Coastguard Worker mMutex.lock_shared();
695*38e8c45fSAndroid Build Coastguard Worker auto writer = getWriter(display);
696*38e8c45fSAndroid Build Coastguard Worker auto reader = getReader(display);
697*38e8c45fSAndroid Build Coastguard Worker if (writer && reader) {
698*38e8c45fSAndroid Build Coastguard Worker writer->get().presentDisplay(displayId);
699*38e8c45fSAndroid Build Coastguard Worker error = execute(display);
700*38e8c45fSAndroid Build Coastguard Worker } else {
701*38e8c45fSAndroid Build Coastguard Worker error = Error::BAD_DISPLAY;
702*38e8c45fSAndroid Build Coastguard Worker }
703*38e8c45fSAndroid Build Coastguard Worker
704*38e8c45fSAndroid Build Coastguard Worker if (error != Error::NONE) {
705*38e8c45fSAndroid Build Coastguard Worker mMutex.unlock_shared();
706*38e8c45fSAndroid Build Coastguard Worker return error;
707*38e8c45fSAndroid Build Coastguard Worker }
708*38e8c45fSAndroid Build Coastguard Worker
709*38e8c45fSAndroid Build Coastguard Worker auto fence = reader->get().takePresentFence(displayId);
710*38e8c45fSAndroid Build Coastguard Worker mMutex.unlock_shared();
711*38e8c45fSAndroid Build Coastguard Worker // take ownership
712*38e8c45fSAndroid Build Coastguard Worker *outPresentFence = fence.get();
713*38e8c45fSAndroid Build Coastguard Worker *fence.getR() = -1;
714*38e8c45fSAndroid Build Coastguard Worker return Error::NONE;
715*38e8c45fSAndroid Build Coastguard Worker }
716*38e8c45fSAndroid Build Coastguard Worker
setActiveConfig(Display display,Config config)717*38e8c45fSAndroid Build Coastguard Worker Error AidlComposer::setActiveConfig(Display display, Config config) {
718*38e8c45fSAndroid Build Coastguard Worker const auto status = mAidlComposerClient->setActiveConfig(translate<int64_t>(display),
719*38e8c45fSAndroid Build Coastguard Worker translate<int32_t>(config));
720*38e8c45fSAndroid Build Coastguard Worker if (!status.isOk()) {
721*38e8c45fSAndroid Build Coastguard Worker ALOGE("setActiveConfig failed %s", status.getDescription().c_str());
722*38e8c45fSAndroid Build Coastguard Worker return static_cast<Error>(status.getServiceSpecificError());
723*38e8c45fSAndroid Build Coastguard Worker }
724*38e8c45fSAndroid Build Coastguard Worker return Error::NONE;
725*38e8c45fSAndroid Build Coastguard Worker }
726*38e8c45fSAndroid Build Coastguard Worker
setClientTarget(Display display,uint32_t slot,const sp<GraphicBuffer> & target,int acquireFence,Dataspace dataspace,const std::vector<IComposerClient::Rect> & damage,float hdrSdrRatio)727*38e8c45fSAndroid Build Coastguard Worker Error AidlComposer::setClientTarget(Display display, uint32_t slot, const sp<GraphicBuffer>& target,
728*38e8c45fSAndroid Build Coastguard Worker int acquireFence, Dataspace dataspace,
729*38e8c45fSAndroid Build Coastguard Worker const std::vector<IComposerClient::Rect>& damage,
730*38e8c45fSAndroid Build Coastguard Worker float hdrSdrRatio) {
731*38e8c45fSAndroid Build Coastguard Worker const native_handle_t* handle = nullptr;
732*38e8c45fSAndroid Build Coastguard Worker if (target.get()) {
733*38e8c45fSAndroid Build Coastguard Worker handle = target->getNativeBuffer()->handle;
734*38e8c45fSAndroid Build Coastguard Worker }
735*38e8c45fSAndroid Build Coastguard Worker
736*38e8c45fSAndroid Build Coastguard Worker Error error = Error::NONE;
737*38e8c45fSAndroid Build Coastguard Worker mMutex.lock_shared();
738*38e8c45fSAndroid Build Coastguard Worker if (auto writer = getWriter(display)) {
739*38e8c45fSAndroid Build Coastguard Worker writer->get()
740*38e8c45fSAndroid Build Coastguard Worker .setClientTarget(translate<int64_t>(display), slot, handle, acquireFence,
741*38e8c45fSAndroid Build Coastguard Worker translate<aidl::android::hardware::graphics::common::Dataspace>(
742*38e8c45fSAndroid Build Coastguard Worker dataspace),
743*38e8c45fSAndroid Build Coastguard Worker translate<AidlRect>(damage), hdrSdrRatio);
744*38e8c45fSAndroid Build Coastguard Worker } else {
745*38e8c45fSAndroid Build Coastguard Worker error = Error::BAD_DISPLAY;
746*38e8c45fSAndroid Build Coastguard Worker }
747*38e8c45fSAndroid Build Coastguard Worker mMutex.unlock_shared();
748*38e8c45fSAndroid Build Coastguard Worker return error;
749*38e8c45fSAndroid Build Coastguard Worker }
750*38e8c45fSAndroid Build Coastguard Worker
setColorMode(Display display,ColorMode mode,RenderIntent renderIntent)751*38e8c45fSAndroid Build Coastguard Worker Error AidlComposer::setColorMode(Display display, ColorMode mode, RenderIntent renderIntent) {
752*38e8c45fSAndroid Build Coastguard Worker const auto status =
753*38e8c45fSAndroid Build Coastguard Worker mAidlComposerClient->setColorMode(translate<int64_t>(display),
754*38e8c45fSAndroid Build Coastguard Worker translate<AidlColorMode>(mode),
755*38e8c45fSAndroid Build Coastguard Worker translate<AidlRenderIntent>(renderIntent));
756*38e8c45fSAndroid Build Coastguard Worker if (!status.isOk()) {
757*38e8c45fSAndroid Build Coastguard Worker ALOGE("setColorMode failed %s", status.getDescription().c_str());
758*38e8c45fSAndroid Build Coastguard Worker return static_cast<Error>(status.getServiceSpecificError());
759*38e8c45fSAndroid Build Coastguard Worker }
760*38e8c45fSAndroid Build Coastguard Worker return Error::NONE;
761*38e8c45fSAndroid Build Coastguard Worker }
762*38e8c45fSAndroid Build Coastguard Worker
setColorTransform(Display display,const float * matrix)763*38e8c45fSAndroid Build Coastguard Worker Error AidlComposer::setColorTransform(Display display, const float* matrix) {
764*38e8c45fSAndroid Build Coastguard Worker auto error = Error::NONE;
765*38e8c45fSAndroid Build Coastguard Worker mMutex.lock_shared();
766*38e8c45fSAndroid Build Coastguard Worker if (auto writer = getWriter(display)) {
767*38e8c45fSAndroid Build Coastguard Worker writer->get().setColorTransform(translate<int64_t>(display), matrix);
768*38e8c45fSAndroid Build Coastguard Worker } else {
769*38e8c45fSAndroid Build Coastguard Worker error = Error::BAD_DISPLAY;
770*38e8c45fSAndroid Build Coastguard Worker }
771*38e8c45fSAndroid Build Coastguard Worker mMutex.unlock_shared();
772*38e8c45fSAndroid Build Coastguard Worker return error;
773*38e8c45fSAndroid Build Coastguard Worker }
774*38e8c45fSAndroid Build Coastguard Worker
setOutputBuffer(Display display,const native_handle_t * buffer,int releaseFence)775*38e8c45fSAndroid Build Coastguard Worker Error AidlComposer::setOutputBuffer(Display display, const native_handle_t* buffer,
776*38e8c45fSAndroid Build Coastguard Worker int releaseFence) {
777*38e8c45fSAndroid Build Coastguard Worker auto error = Error::NONE;
778*38e8c45fSAndroid Build Coastguard Worker mMutex.lock_shared();
779*38e8c45fSAndroid Build Coastguard Worker if (auto writer = getWriter(display)) {
780*38e8c45fSAndroid Build Coastguard Worker writer->get().setOutputBuffer(translate<int64_t>(display), 0, buffer, dup(releaseFence));
781*38e8c45fSAndroid Build Coastguard Worker } else {
782*38e8c45fSAndroid Build Coastguard Worker error = Error::BAD_DISPLAY;
783*38e8c45fSAndroid Build Coastguard Worker }
784*38e8c45fSAndroid Build Coastguard Worker mMutex.unlock_shared();
785*38e8c45fSAndroid Build Coastguard Worker return error;
786*38e8c45fSAndroid Build Coastguard Worker }
787*38e8c45fSAndroid Build Coastguard Worker
setPowerMode(Display display,IComposerClient::PowerMode mode)788*38e8c45fSAndroid Build Coastguard Worker Error AidlComposer::setPowerMode(Display display, IComposerClient::PowerMode mode) {
789*38e8c45fSAndroid Build Coastguard Worker const auto status = mAidlComposerClient->setPowerMode(translate<int64_t>(display),
790*38e8c45fSAndroid Build Coastguard Worker translate<PowerMode>(mode));
791*38e8c45fSAndroid Build Coastguard Worker if (!status.isOk()) {
792*38e8c45fSAndroid Build Coastguard Worker ALOGE("setPowerMode failed %s", status.getDescription().c_str());
793*38e8c45fSAndroid Build Coastguard Worker return static_cast<Error>(status.getServiceSpecificError());
794*38e8c45fSAndroid Build Coastguard Worker }
795*38e8c45fSAndroid Build Coastguard Worker return Error::NONE;
796*38e8c45fSAndroid Build Coastguard Worker }
797*38e8c45fSAndroid Build Coastguard Worker
setVsyncEnabled(Display display,IComposerClient::Vsync enabled)798*38e8c45fSAndroid Build Coastguard Worker Error AidlComposer::setVsyncEnabled(Display display, IComposerClient::Vsync enabled) {
799*38e8c45fSAndroid Build Coastguard Worker const bool enableVsync = enabled == IComposerClient::Vsync::ENABLE;
800*38e8c45fSAndroid Build Coastguard Worker const auto status =
801*38e8c45fSAndroid Build Coastguard Worker mAidlComposerClient->setVsyncEnabled(translate<int64_t>(display), enableVsync);
802*38e8c45fSAndroid Build Coastguard Worker if (!status.isOk()) {
803*38e8c45fSAndroid Build Coastguard Worker ALOGE("setVsyncEnabled failed %s", status.getDescription().c_str());
804*38e8c45fSAndroid Build Coastguard Worker return static_cast<Error>(status.getServiceSpecificError());
805*38e8c45fSAndroid Build Coastguard Worker }
806*38e8c45fSAndroid Build Coastguard Worker return Error::NONE;
807*38e8c45fSAndroid Build Coastguard Worker }
808*38e8c45fSAndroid Build Coastguard Worker
setClientTargetSlotCount(Display display)809*38e8c45fSAndroid Build Coastguard Worker Error AidlComposer::setClientTargetSlotCount(Display display) {
810*38e8c45fSAndroid Build Coastguard Worker const int32_t bufferSlotCount = BufferQueue::NUM_BUFFER_SLOTS;
811*38e8c45fSAndroid Build Coastguard Worker const auto status = mAidlComposerClient->setClientTargetSlotCount(translate<int64_t>(display),
812*38e8c45fSAndroid Build Coastguard Worker bufferSlotCount);
813*38e8c45fSAndroid Build Coastguard Worker if (!status.isOk()) {
814*38e8c45fSAndroid Build Coastguard Worker ALOGE("setClientTargetSlotCount failed %s", status.getDescription().c_str());
815*38e8c45fSAndroid Build Coastguard Worker return static_cast<Error>(status.getServiceSpecificError());
816*38e8c45fSAndroid Build Coastguard Worker }
817*38e8c45fSAndroid Build Coastguard Worker return Error::NONE;
818*38e8c45fSAndroid Build Coastguard Worker }
819*38e8c45fSAndroid Build Coastguard Worker
validateDisplay(Display display,nsecs_t expectedPresentTime,int32_t frameIntervalNs,uint32_t * outNumTypes,uint32_t * outNumRequests)820*38e8c45fSAndroid Build Coastguard Worker Error AidlComposer::validateDisplay(Display display, nsecs_t expectedPresentTime,
821*38e8c45fSAndroid Build Coastguard Worker int32_t frameIntervalNs, uint32_t* outNumTypes,
822*38e8c45fSAndroid Build Coastguard Worker uint32_t* outNumRequests) {
823*38e8c45fSAndroid Build Coastguard Worker const auto displayId = translate<int64_t>(display);
824*38e8c45fSAndroid Build Coastguard Worker SFTRACE_FORMAT("HwcValidateDisplay %" PRId64, displayId);
825*38e8c45fSAndroid Build Coastguard Worker
826*38e8c45fSAndroid Build Coastguard Worker Error error = Error::NONE;
827*38e8c45fSAndroid Build Coastguard Worker mMutex.lock_shared();
828*38e8c45fSAndroid Build Coastguard Worker auto writer = getWriter(display);
829*38e8c45fSAndroid Build Coastguard Worker auto reader = getReader(display);
830*38e8c45fSAndroid Build Coastguard Worker if (writer && reader) {
831*38e8c45fSAndroid Build Coastguard Worker writer->get().validateDisplay(displayId, ClockMonotonicTimestamp{expectedPresentTime},
832*38e8c45fSAndroid Build Coastguard Worker frameIntervalNs);
833*38e8c45fSAndroid Build Coastguard Worker error = execute(display);
834*38e8c45fSAndroid Build Coastguard Worker } else {
835*38e8c45fSAndroid Build Coastguard Worker error = Error::BAD_DISPLAY;
836*38e8c45fSAndroid Build Coastguard Worker }
837*38e8c45fSAndroid Build Coastguard Worker
838*38e8c45fSAndroid Build Coastguard Worker if (error != Error::NONE) {
839*38e8c45fSAndroid Build Coastguard Worker mMutex.unlock_shared();
840*38e8c45fSAndroid Build Coastguard Worker return error;
841*38e8c45fSAndroid Build Coastguard Worker }
842*38e8c45fSAndroid Build Coastguard Worker
843*38e8c45fSAndroid Build Coastguard Worker reader->get().hasChanges(displayId, outNumTypes, outNumRequests);
844*38e8c45fSAndroid Build Coastguard Worker
845*38e8c45fSAndroid Build Coastguard Worker mMutex.unlock_shared();
846*38e8c45fSAndroid Build Coastguard Worker return Error::NONE;
847*38e8c45fSAndroid Build Coastguard Worker }
848*38e8c45fSAndroid Build Coastguard Worker
presentOrValidateDisplay(Display display,nsecs_t expectedPresentTime,int32_t frameIntervalNs,uint32_t * outNumTypes,uint32_t * outNumRequests,int * outPresentFence,uint32_t * state)849*38e8c45fSAndroid Build Coastguard Worker Error AidlComposer::presentOrValidateDisplay(Display display, nsecs_t expectedPresentTime,
850*38e8c45fSAndroid Build Coastguard Worker int32_t frameIntervalNs, uint32_t* outNumTypes,
851*38e8c45fSAndroid Build Coastguard Worker uint32_t* outNumRequests, int* outPresentFence,
852*38e8c45fSAndroid Build Coastguard Worker uint32_t* state) {
853*38e8c45fSAndroid Build Coastguard Worker const auto displayId = translate<int64_t>(display);
854*38e8c45fSAndroid Build Coastguard Worker SFTRACE_FORMAT("HwcPresentOrValidateDisplay %" PRId64, displayId);
855*38e8c45fSAndroid Build Coastguard Worker
856*38e8c45fSAndroid Build Coastguard Worker Error error = Error::NONE;
857*38e8c45fSAndroid Build Coastguard Worker mMutex.lock_shared();
858*38e8c45fSAndroid Build Coastguard Worker auto writer = getWriter(display);
859*38e8c45fSAndroid Build Coastguard Worker auto reader = getReader(display);
860*38e8c45fSAndroid Build Coastguard Worker if (writer && reader) {
861*38e8c45fSAndroid Build Coastguard Worker writer->get().presentOrvalidateDisplay(displayId,
862*38e8c45fSAndroid Build Coastguard Worker ClockMonotonicTimestamp{expectedPresentTime},
863*38e8c45fSAndroid Build Coastguard Worker frameIntervalNs);
864*38e8c45fSAndroid Build Coastguard Worker error = execute(display);
865*38e8c45fSAndroid Build Coastguard Worker } else {
866*38e8c45fSAndroid Build Coastguard Worker error = Error::BAD_DISPLAY;
867*38e8c45fSAndroid Build Coastguard Worker }
868*38e8c45fSAndroid Build Coastguard Worker
869*38e8c45fSAndroid Build Coastguard Worker if (error != Error::NONE) {
870*38e8c45fSAndroid Build Coastguard Worker mMutex.unlock_shared();
871*38e8c45fSAndroid Build Coastguard Worker return error;
872*38e8c45fSAndroid Build Coastguard Worker }
873*38e8c45fSAndroid Build Coastguard Worker
874*38e8c45fSAndroid Build Coastguard Worker const auto result = reader->get().takePresentOrValidateStage(displayId);
875*38e8c45fSAndroid Build Coastguard Worker if (!result.has_value()) {
876*38e8c45fSAndroid Build Coastguard Worker *state = translate<uint32_t>(-1);
877*38e8c45fSAndroid Build Coastguard Worker mMutex.unlock_shared();
878*38e8c45fSAndroid Build Coastguard Worker return Error::NO_RESOURCES;
879*38e8c45fSAndroid Build Coastguard Worker }
880*38e8c45fSAndroid Build Coastguard Worker
881*38e8c45fSAndroid Build Coastguard Worker *state = translate<uint32_t>(*result);
882*38e8c45fSAndroid Build Coastguard Worker
883*38e8c45fSAndroid Build Coastguard Worker if (*result == PresentOrValidate::Result::Presented) {
884*38e8c45fSAndroid Build Coastguard Worker auto fence = reader->get().takePresentFence(displayId);
885*38e8c45fSAndroid Build Coastguard Worker // take ownership
886*38e8c45fSAndroid Build Coastguard Worker *outPresentFence = fence.get();
887*38e8c45fSAndroid Build Coastguard Worker *fence.getR() = -1;
888*38e8c45fSAndroid Build Coastguard Worker }
889*38e8c45fSAndroid Build Coastguard Worker
890*38e8c45fSAndroid Build Coastguard Worker if (*result == PresentOrValidate::Result::Validated) {
891*38e8c45fSAndroid Build Coastguard Worker reader->get().hasChanges(displayId, outNumTypes, outNumRequests);
892*38e8c45fSAndroid Build Coastguard Worker }
893*38e8c45fSAndroid Build Coastguard Worker
894*38e8c45fSAndroid Build Coastguard Worker mMutex.unlock_shared();
895*38e8c45fSAndroid Build Coastguard Worker return Error::NONE;
896*38e8c45fSAndroid Build Coastguard Worker }
897*38e8c45fSAndroid Build Coastguard Worker
setCursorPosition(Display display,Layer layer,int32_t x,int32_t y)898*38e8c45fSAndroid Build Coastguard Worker Error AidlComposer::setCursorPosition(Display display, Layer layer, int32_t x, int32_t y) {
899*38e8c45fSAndroid Build Coastguard Worker Error error = Error::NONE;
900*38e8c45fSAndroid Build Coastguard Worker mMutex.lock_shared();
901*38e8c45fSAndroid Build Coastguard Worker if (auto writer = getWriter(display)) {
902*38e8c45fSAndroid Build Coastguard Worker writer->get().setLayerCursorPosition(translate<int64_t>(display), translate<int64_t>(layer),
903*38e8c45fSAndroid Build Coastguard Worker x, y);
904*38e8c45fSAndroid Build Coastguard Worker } else {
905*38e8c45fSAndroid Build Coastguard Worker error = Error::BAD_DISPLAY;
906*38e8c45fSAndroid Build Coastguard Worker }
907*38e8c45fSAndroid Build Coastguard Worker mMutex.unlock_shared();
908*38e8c45fSAndroid Build Coastguard Worker return error;
909*38e8c45fSAndroid Build Coastguard Worker }
910*38e8c45fSAndroid Build Coastguard Worker
setLayerBuffer(Display display,Layer layer,uint32_t slot,const sp<GraphicBuffer> & buffer,int acquireFence)911*38e8c45fSAndroid Build Coastguard Worker Error AidlComposer::setLayerBuffer(Display display, Layer layer, uint32_t slot,
912*38e8c45fSAndroid Build Coastguard Worker const sp<GraphicBuffer>& buffer, int acquireFence) {
913*38e8c45fSAndroid Build Coastguard Worker const native_handle_t* handle = nullptr;
914*38e8c45fSAndroid Build Coastguard Worker if (buffer.get()) {
915*38e8c45fSAndroid Build Coastguard Worker handle = buffer->getNativeBuffer()->handle;
916*38e8c45fSAndroid Build Coastguard Worker }
917*38e8c45fSAndroid Build Coastguard Worker
918*38e8c45fSAndroid Build Coastguard Worker Error error = Error::NONE;
919*38e8c45fSAndroid Build Coastguard Worker mMutex.lock_shared();
920*38e8c45fSAndroid Build Coastguard Worker if (auto writer = getWriter(display)) {
921*38e8c45fSAndroid Build Coastguard Worker writer->get().setLayerBuffer(translate<int64_t>(display), translate<int64_t>(layer), slot,
922*38e8c45fSAndroid Build Coastguard Worker handle, acquireFence);
923*38e8c45fSAndroid Build Coastguard Worker } else {
924*38e8c45fSAndroid Build Coastguard Worker error = Error::BAD_DISPLAY;
925*38e8c45fSAndroid Build Coastguard Worker }
926*38e8c45fSAndroid Build Coastguard Worker mMutex.unlock_shared();
927*38e8c45fSAndroid Build Coastguard Worker return error;
928*38e8c45fSAndroid Build Coastguard Worker }
929*38e8c45fSAndroid Build Coastguard Worker
setLayerBufferSlotsToClear(Display display,Layer layer,const std::vector<uint32_t> & slotsToClear,uint32_t activeBufferSlot)930*38e8c45fSAndroid Build Coastguard Worker Error AidlComposer::setLayerBufferSlotsToClear(Display display, Layer layer,
931*38e8c45fSAndroid Build Coastguard Worker const std::vector<uint32_t>& slotsToClear,
932*38e8c45fSAndroid Build Coastguard Worker uint32_t activeBufferSlot) {
933*38e8c45fSAndroid Build Coastguard Worker if (slotsToClear.empty()) {
934*38e8c45fSAndroid Build Coastguard Worker return Error::NONE;
935*38e8c45fSAndroid Build Coastguard Worker }
936*38e8c45fSAndroid Build Coastguard Worker
937*38e8c45fSAndroid Build Coastguard Worker Error error = Error::NONE;
938*38e8c45fSAndroid Build Coastguard Worker mMutex.lock_shared();
939*38e8c45fSAndroid Build Coastguard Worker if (auto writer = getWriter(display)) {
940*38e8c45fSAndroid Build Coastguard Worker if (mComposerInterfaceVersion > 1) {
941*38e8c45fSAndroid Build Coastguard Worker writer->get().setLayerBufferSlotsToClear(translate<int64_t>(display),
942*38e8c45fSAndroid Build Coastguard Worker translate<int64_t>(layer), slotsToClear);
943*38e8c45fSAndroid Build Coastguard Worker // Backwards compatible way of clearing buffer slots is to set the layer buffer with a
944*38e8c45fSAndroid Build Coastguard Worker // placeholder buffer, using the slot that needs to cleared... tricky.
945*38e8c45fSAndroid Build Coastguard Worker } else if (mClearSlotBuffer != nullptr) {
946*38e8c45fSAndroid Build Coastguard Worker for (uint32_t slot : slotsToClear) {
947*38e8c45fSAndroid Build Coastguard Worker // Don't clear the active buffer slot because we need to restore the active buffer
948*38e8c45fSAndroid Build Coastguard Worker // after clearing the requested buffer slots with a placeholder buffer.
949*38e8c45fSAndroid Build Coastguard Worker if (slot != activeBufferSlot) {
950*38e8c45fSAndroid Build Coastguard Worker writer->get().setLayerBufferWithNewCommand(translate<int64_t>(display),
951*38e8c45fSAndroid Build Coastguard Worker translate<int64_t>(layer), slot,
952*38e8c45fSAndroid Build Coastguard Worker mClearSlotBuffer->handle,
953*38e8c45fSAndroid Build Coastguard Worker /*fence*/ -1);
954*38e8c45fSAndroid Build Coastguard Worker }
955*38e8c45fSAndroid Build Coastguard Worker }
956*38e8c45fSAndroid Build Coastguard Worker // Since we clear buffers by setting them to a placeholder buffer, we want to make
957*38e8c45fSAndroid Build Coastguard Worker // sure that the last setLayerBuffer command is sent with the currently active
958*38e8c45fSAndroid Build Coastguard Worker // buffer, not the placeholder buffer, so that there is no perceptual change when
959*38e8c45fSAndroid Build Coastguard Worker // buffers are discarded.
960*38e8c45fSAndroid Build Coastguard Worker writer->get().setLayerBufferWithNewCommand(translate<int64_t>(display),
961*38e8c45fSAndroid Build Coastguard Worker translate<int64_t>(layer), activeBufferSlot,
962*38e8c45fSAndroid Build Coastguard Worker // The active buffer is still cached in
963*38e8c45fSAndroid Build Coastguard Worker // its slot and doesn't need a fence.
964*38e8c45fSAndroid Build Coastguard Worker /*buffer*/ nullptr, /*fence*/ -1);
965*38e8c45fSAndroid Build Coastguard Worker }
966*38e8c45fSAndroid Build Coastguard Worker } else {
967*38e8c45fSAndroid Build Coastguard Worker error = Error::BAD_DISPLAY;
968*38e8c45fSAndroid Build Coastguard Worker }
969*38e8c45fSAndroid Build Coastguard Worker mMutex.unlock_shared();
970*38e8c45fSAndroid Build Coastguard Worker return error;
971*38e8c45fSAndroid Build Coastguard Worker }
972*38e8c45fSAndroid Build Coastguard Worker
setLayerSurfaceDamage(Display display,Layer layer,const std::vector<IComposerClient::Rect> & damage)973*38e8c45fSAndroid Build Coastguard Worker Error AidlComposer::setLayerSurfaceDamage(Display display, Layer layer,
974*38e8c45fSAndroid Build Coastguard Worker const std::vector<IComposerClient::Rect>& damage) {
975*38e8c45fSAndroid Build Coastguard Worker Error error = Error::NONE;
976*38e8c45fSAndroid Build Coastguard Worker mMutex.lock_shared();
977*38e8c45fSAndroid Build Coastguard Worker if (auto writer = getWriter(display)) {
978*38e8c45fSAndroid Build Coastguard Worker writer->get().setLayerSurfaceDamage(translate<int64_t>(display), translate<int64_t>(layer),
979*38e8c45fSAndroid Build Coastguard Worker translate<AidlRect>(damage));
980*38e8c45fSAndroid Build Coastguard Worker } else {
981*38e8c45fSAndroid Build Coastguard Worker error = Error::BAD_DISPLAY;
982*38e8c45fSAndroid Build Coastguard Worker }
983*38e8c45fSAndroid Build Coastguard Worker mMutex.unlock_shared();
984*38e8c45fSAndroid Build Coastguard Worker return error;
985*38e8c45fSAndroid Build Coastguard Worker }
986*38e8c45fSAndroid Build Coastguard Worker
setLayerBlendMode(Display display,Layer layer,IComposerClient::BlendMode mode)987*38e8c45fSAndroid Build Coastguard Worker Error AidlComposer::setLayerBlendMode(Display display, Layer layer,
988*38e8c45fSAndroid Build Coastguard Worker IComposerClient::BlendMode mode) {
989*38e8c45fSAndroid Build Coastguard Worker Error error = Error::NONE;
990*38e8c45fSAndroid Build Coastguard Worker mMutex.lock_shared();
991*38e8c45fSAndroid Build Coastguard Worker if (auto writer = getWriter(display)) {
992*38e8c45fSAndroid Build Coastguard Worker writer->get().setLayerBlendMode(translate<int64_t>(display), translate<int64_t>(layer),
993*38e8c45fSAndroid Build Coastguard Worker translate<BlendMode>(mode));
994*38e8c45fSAndroid Build Coastguard Worker } else {
995*38e8c45fSAndroid Build Coastguard Worker error = Error::BAD_DISPLAY;
996*38e8c45fSAndroid Build Coastguard Worker }
997*38e8c45fSAndroid Build Coastguard Worker mMutex.unlock_shared();
998*38e8c45fSAndroid Build Coastguard Worker return error;
999*38e8c45fSAndroid Build Coastguard Worker }
1000*38e8c45fSAndroid Build Coastguard Worker
setLayerColor(Display display,Layer layer,const Color & color)1001*38e8c45fSAndroid Build Coastguard Worker Error AidlComposer::setLayerColor(Display display, Layer layer, const Color& color) {
1002*38e8c45fSAndroid Build Coastguard Worker Error error = Error::NONE;
1003*38e8c45fSAndroid Build Coastguard Worker mMutex.lock_shared();
1004*38e8c45fSAndroid Build Coastguard Worker if (auto writer = getWriter(display)) {
1005*38e8c45fSAndroid Build Coastguard Worker writer->get().setLayerColor(translate<int64_t>(display), translate<int64_t>(layer), color);
1006*38e8c45fSAndroid Build Coastguard Worker } else {
1007*38e8c45fSAndroid Build Coastguard Worker error = Error::BAD_DISPLAY;
1008*38e8c45fSAndroid Build Coastguard Worker }
1009*38e8c45fSAndroid Build Coastguard Worker mMutex.unlock_shared();
1010*38e8c45fSAndroid Build Coastguard Worker return error;
1011*38e8c45fSAndroid Build Coastguard Worker }
1012*38e8c45fSAndroid Build Coastguard Worker
setLayerCompositionType(Display display,Layer layer,aidl::android::hardware::graphics::composer3::Composition type)1013*38e8c45fSAndroid Build Coastguard Worker Error AidlComposer::setLayerCompositionType(
1014*38e8c45fSAndroid Build Coastguard Worker Display display, Layer layer,
1015*38e8c45fSAndroid Build Coastguard Worker aidl::android::hardware::graphics::composer3::Composition type) {
1016*38e8c45fSAndroid Build Coastguard Worker Error error = Error::NONE;
1017*38e8c45fSAndroid Build Coastguard Worker mMutex.lock_shared();
1018*38e8c45fSAndroid Build Coastguard Worker if (auto writer = getWriter(display)) {
1019*38e8c45fSAndroid Build Coastguard Worker writer->get().setLayerCompositionType(translate<int64_t>(display),
1020*38e8c45fSAndroid Build Coastguard Worker translate<int64_t>(layer), type);
1021*38e8c45fSAndroid Build Coastguard Worker } else {
1022*38e8c45fSAndroid Build Coastguard Worker error = Error::BAD_DISPLAY;
1023*38e8c45fSAndroid Build Coastguard Worker }
1024*38e8c45fSAndroid Build Coastguard Worker mMutex.unlock_shared();
1025*38e8c45fSAndroid Build Coastguard Worker return error;
1026*38e8c45fSAndroid Build Coastguard Worker }
1027*38e8c45fSAndroid Build Coastguard Worker
setLayerDataspace(Display display,Layer layer,Dataspace dataspace)1028*38e8c45fSAndroid Build Coastguard Worker Error AidlComposer::setLayerDataspace(Display display, Layer layer, Dataspace dataspace) {
1029*38e8c45fSAndroid Build Coastguard Worker Error error = Error::NONE;
1030*38e8c45fSAndroid Build Coastguard Worker mMutex.lock_shared();
1031*38e8c45fSAndroid Build Coastguard Worker if (auto writer = getWriter(display)) {
1032*38e8c45fSAndroid Build Coastguard Worker writer->get().setLayerDataspace(translate<int64_t>(display), translate<int64_t>(layer),
1033*38e8c45fSAndroid Build Coastguard Worker translate<AidlDataspace>(dataspace));
1034*38e8c45fSAndroid Build Coastguard Worker } else {
1035*38e8c45fSAndroid Build Coastguard Worker error = Error::BAD_DISPLAY;
1036*38e8c45fSAndroid Build Coastguard Worker }
1037*38e8c45fSAndroid Build Coastguard Worker mMutex.unlock_shared();
1038*38e8c45fSAndroid Build Coastguard Worker return error;
1039*38e8c45fSAndroid Build Coastguard Worker }
1040*38e8c45fSAndroid Build Coastguard Worker
setLayerDisplayFrame(Display display,Layer layer,const IComposerClient::Rect & frame)1041*38e8c45fSAndroid Build Coastguard Worker Error AidlComposer::setLayerDisplayFrame(Display display, Layer layer,
1042*38e8c45fSAndroid Build Coastguard Worker const IComposerClient::Rect& frame) {
1043*38e8c45fSAndroid Build Coastguard Worker Error error = Error::NONE;
1044*38e8c45fSAndroid Build Coastguard Worker mMutex.lock_shared();
1045*38e8c45fSAndroid Build Coastguard Worker if (auto writer = getWriter(display)) {
1046*38e8c45fSAndroid Build Coastguard Worker writer->get().setLayerDisplayFrame(translate<int64_t>(display), translate<int64_t>(layer),
1047*38e8c45fSAndroid Build Coastguard Worker translate<AidlRect>(frame));
1048*38e8c45fSAndroid Build Coastguard Worker } else {
1049*38e8c45fSAndroid Build Coastguard Worker error = Error::BAD_DISPLAY;
1050*38e8c45fSAndroid Build Coastguard Worker }
1051*38e8c45fSAndroid Build Coastguard Worker mMutex.unlock_shared();
1052*38e8c45fSAndroid Build Coastguard Worker return error;
1053*38e8c45fSAndroid Build Coastguard Worker }
1054*38e8c45fSAndroid Build Coastguard Worker
setLayerPlaneAlpha(Display display,Layer layer,float alpha)1055*38e8c45fSAndroid Build Coastguard Worker Error AidlComposer::setLayerPlaneAlpha(Display display, Layer layer, float alpha) {
1056*38e8c45fSAndroid Build Coastguard Worker Error error = Error::NONE;
1057*38e8c45fSAndroid Build Coastguard Worker mMutex.lock_shared();
1058*38e8c45fSAndroid Build Coastguard Worker if (auto writer = getWriter(display)) {
1059*38e8c45fSAndroid Build Coastguard Worker writer->get().setLayerPlaneAlpha(translate<int64_t>(display), translate<int64_t>(layer),
1060*38e8c45fSAndroid Build Coastguard Worker alpha);
1061*38e8c45fSAndroid Build Coastguard Worker } else {
1062*38e8c45fSAndroid Build Coastguard Worker error = Error::BAD_DISPLAY;
1063*38e8c45fSAndroid Build Coastguard Worker }
1064*38e8c45fSAndroid Build Coastguard Worker mMutex.unlock_shared();
1065*38e8c45fSAndroid Build Coastguard Worker return error;
1066*38e8c45fSAndroid Build Coastguard Worker }
1067*38e8c45fSAndroid Build Coastguard Worker
setLayerSidebandStream(Display display,Layer layer,const native_handle_t * stream)1068*38e8c45fSAndroid Build Coastguard Worker Error AidlComposer::setLayerSidebandStream(Display display, Layer layer,
1069*38e8c45fSAndroid Build Coastguard Worker const native_handle_t* stream) {
1070*38e8c45fSAndroid Build Coastguard Worker Error error = Error::NONE;
1071*38e8c45fSAndroid Build Coastguard Worker mMutex.lock_shared();
1072*38e8c45fSAndroid Build Coastguard Worker if (auto writer = getWriter(display)) {
1073*38e8c45fSAndroid Build Coastguard Worker writer->get().setLayerSidebandStream(translate<int64_t>(display), translate<int64_t>(layer),
1074*38e8c45fSAndroid Build Coastguard Worker stream);
1075*38e8c45fSAndroid Build Coastguard Worker } else {
1076*38e8c45fSAndroid Build Coastguard Worker error = Error::BAD_DISPLAY;
1077*38e8c45fSAndroid Build Coastguard Worker }
1078*38e8c45fSAndroid Build Coastguard Worker mMutex.unlock_shared();
1079*38e8c45fSAndroid Build Coastguard Worker return error;
1080*38e8c45fSAndroid Build Coastguard Worker }
1081*38e8c45fSAndroid Build Coastguard Worker
setLayerSourceCrop(Display display,Layer layer,const IComposerClient::FRect & crop)1082*38e8c45fSAndroid Build Coastguard Worker Error AidlComposer::setLayerSourceCrop(Display display, Layer layer,
1083*38e8c45fSAndroid Build Coastguard Worker const IComposerClient::FRect& crop) {
1084*38e8c45fSAndroid Build Coastguard Worker Error error = Error::NONE;
1085*38e8c45fSAndroid Build Coastguard Worker mMutex.lock_shared();
1086*38e8c45fSAndroid Build Coastguard Worker if (auto writer = getWriter(display)) {
1087*38e8c45fSAndroid Build Coastguard Worker writer->get().setLayerSourceCrop(translate<int64_t>(display), translate<int64_t>(layer),
1088*38e8c45fSAndroid Build Coastguard Worker translate<AidlFRect>(crop));
1089*38e8c45fSAndroid Build Coastguard Worker } else {
1090*38e8c45fSAndroid Build Coastguard Worker error = Error::BAD_DISPLAY;
1091*38e8c45fSAndroid Build Coastguard Worker }
1092*38e8c45fSAndroid Build Coastguard Worker mMutex.unlock_shared();
1093*38e8c45fSAndroid Build Coastguard Worker return error;
1094*38e8c45fSAndroid Build Coastguard Worker }
1095*38e8c45fSAndroid Build Coastguard Worker
setLayerTransform(Display display,Layer layer,Transform transform)1096*38e8c45fSAndroid Build Coastguard Worker Error AidlComposer::setLayerTransform(Display display, Layer layer, Transform transform) {
1097*38e8c45fSAndroid Build Coastguard Worker Error error = Error::NONE;
1098*38e8c45fSAndroid Build Coastguard Worker mMutex.lock_shared();
1099*38e8c45fSAndroid Build Coastguard Worker if (auto writer = getWriter(display)) {
1100*38e8c45fSAndroid Build Coastguard Worker writer->get().setLayerTransform(translate<int64_t>(display), translate<int64_t>(layer),
1101*38e8c45fSAndroid Build Coastguard Worker translate<AidlTransform>(transform));
1102*38e8c45fSAndroid Build Coastguard Worker } else {
1103*38e8c45fSAndroid Build Coastguard Worker error = Error::BAD_DISPLAY;
1104*38e8c45fSAndroid Build Coastguard Worker }
1105*38e8c45fSAndroid Build Coastguard Worker mMutex.unlock_shared();
1106*38e8c45fSAndroid Build Coastguard Worker return error;
1107*38e8c45fSAndroid Build Coastguard Worker }
1108*38e8c45fSAndroid Build Coastguard Worker
setLayerVisibleRegion(Display display,Layer layer,const std::vector<IComposerClient::Rect> & visible)1109*38e8c45fSAndroid Build Coastguard Worker Error AidlComposer::setLayerVisibleRegion(Display display, Layer layer,
1110*38e8c45fSAndroid Build Coastguard Worker const std::vector<IComposerClient::Rect>& visible) {
1111*38e8c45fSAndroid Build Coastguard Worker Error error = Error::NONE;
1112*38e8c45fSAndroid Build Coastguard Worker mMutex.lock_shared();
1113*38e8c45fSAndroid Build Coastguard Worker if (auto writer = getWriter(display)) {
1114*38e8c45fSAndroid Build Coastguard Worker writer->get().setLayerVisibleRegion(translate<int64_t>(display), translate<int64_t>(layer),
1115*38e8c45fSAndroid Build Coastguard Worker translate<AidlRect>(visible));
1116*38e8c45fSAndroid Build Coastguard Worker } else {
1117*38e8c45fSAndroid Build Coastguard Worker error = Error::BAD_DISPLAY;
1118*38e8c45fSAndroid Build Coastguard Worker }
1119*38e8c45fSAndroid Build Coastguard Worker mMutex.unlock_shared();
1120*38e8c45fSAndroid Build Coastguard Worker return error;
1121*38e8c45fSAndroid Build Coastguard Worker }
1122*38e8c45fSAndroid Build Coastguard Worker
setLayerZOrder(Display display,Layer layer,uint32_t z)1123*38e8c45fSAndroid Build Coastguard Worker Error AidlComposer::setLayerZOrder(Display display, Layer layer, uint32_t z) {
1124*38e8c45fSAndroid Build Coastguard Worker Error error = Error::NONE;
1125*38e8c45fSAndroid Build Coastguard Worker mMutex.lock_shared();
1126*38e8c45fSAndroid Build Coastguard Worker if (auto writer = getWriter(display)) {
1127*38e8c45fSAndroid Build Coastguard Worker writer->get().setLayerZOrder(translate<int64_t>(display), translate<int64_t>(layer), z);
1128*38e8c45fSAndroid Build Coastguard Worker } else {
1129*38e8c45fSAndroid Build Coastguard Worker error = Error::BAD_DISPLAY;
1130*38e8c45fSAndroid Build Coastguard Worker }
1131*38e8c45fSAndroid Build Coastguard Worker mMutex.unlock_shared();
1132*38e8c45fSAndroid Build Coastguard Worker return error;
1133*38e8c45fSAndroid Build Coastguard Worker }
1134*38e8c45fSAndroid Build Coastguard Worker
execute(Display display)1135*38e8c45fSAndroid Build Coastguard Worker Error AidlComposer::execute(Display display) {
1136*38e8c45fSAndroid Build Coastguard Worker auto writer = getWriter(display);
1137*38e8c45fSAndroid Build Coastguard Worker auto reader = getReader(display);
1138*38e8c45fSAndroid Build Coastguard Worker if (!writer || !reader) {
1139*38e8c45fSAndroid Build Coastguard Worker return Error::BAD_DISPLAY;
1140*38e8c45fSAndroid Build Coastguard Worker }
1141*38e8c45fSAndroid Build Coastguard Worker
1142*38e8c45fSAndroid Build Coastguard Worker auto commands = writer->get().takePendingCommands();
1143*38e8c45fSAndroid Build Coastguard Worker if (commands.empty()) {
1144*38e8c45fSAndroid Build Coastguard Worker return Error::NONE;
1145*38e8c45fSAndroid Build Coastguard Worker }
1146*38e8c45fSAndroid Build Coastguard Worker
1147*38e8c45fSAndroid Build Coastguard Worker { // scope for results
1148*38e8c45fSAndroid Build Coastguard Worker std::vector<CommandResultPayload> results;
1149*38e8c45fSAndroid Build Coastguard Worker auto status = mAidlComposerClient->executeCommands(commands, &results);
1150*38e8c45fSAndroid Build Coastguard Worker if (!status.isOk()) {
1151*38e8c45fSAndroid Build Coastguard Worker ALOGE("executeCommands failed %s", status.getDescription().c_str());
1152*38e8c45fSAndroid Build Coastguard Worker return static_cast<Error>(status.getServiceSpecificError());
1153*38e8c45fSAndroid Build Coastguard Worker }
1154*38e8c45fSAndroid Build Coastguard Worker
1155*38e8c45fSAndroid Build Coastguard Worker reader->get().parse(std::move(results));
1156*38e8c45fSAndroid Build Coastguard Worker }
1157*38e8c45fSAndroid Build Coastguard Worker const auto commandErrors = reader->get().takeErrors();
1158*38e8c45fSAndroid Build Coastguard Worker Error error = Error::NONE;
1159*38e8c45fSAndroid Build Coastguard Worker for (const auto& cmdErr : commandErrors) {
1160*38e8c45fSAndroid Build Coastguard Worker const auto index = static_cast<size_t>(cmdErr.commandIndex);
1161*38e8c45fSAndroid Build Coastguard Worker if (index < 0 || index >= commands.size()) {
1162*38e8c45fSAndroid Build Coastguard Worker ALOGE("invalid command index %zu", index);
1163*38e8c45fSAndroid Build Coastguard Worker return Error::BAD_PARAMETER;
1164*38e8c45fSAndroid Build Coastguard Worker }
1165*38e8c45fSAndroid Build Coastguard Worker
1166*38e8c45fSAndroid Build Coastguard Worker const auto& command = commands[index];
1167*38e8c45fSAndroid Build Coastguard Worker if (command.validateDisplay || command.presentDisplay || command.presentOrValidateDisplay) {
1168*38e8c45fSAndroid Build Coastguard Worker error = translate<Error>(cmdErr.errorCode);
1169*38e8c45fSAndroid Build Coastguard Worker } else {
1170*38e8c45fSAndroid Build Coastguard Worker ALOGW("command '%s' generated error %" PRId32, command.toString().c_str(),
1171*38e8c45fSAndroid Build Coastguard Worker cmdErr.errorCode);
1172*38e8c45fSAndroid Build Coastguard Worker }
1173*38e8c45fSAndroid Build Coastguard Worker }
1174*38e8c45fSAndroid Build Coastguard Worker
1175*38e8c45fSAndroid Build Coastguard Worker return error;
1176*38e8c45fSAndroid Build Coastguard Worker }
1177*38e8c45fSAndroid Build Coastguard Worker
setLayerPerFrameMetadata(Display display,Layer layer,const std::vector<IComposerClient::PerFrameMetadata> & perFrameMetadatas)1178*38e8c45fSAndroid Build Coastguard Worker Error AidlComposer::setLayerPerFrameMetadata(
1179*38e8c45fSAndroid Build Coastguard Worker Display display, Layer layer,
1180*38e8c45fSAndroid Build Coastguard Worker const std::vector<IComposerClient::PerFrameMetadata>& perFrameMetadatas) {
1181*38e8c45fSAndroid Build Coastguard Worker Error error = Error::NONE;
1182*38e8c45fSAndroid Build Coastguard Worker mMutex.lock_shared();
1183*38e8c45fSAndroid Build Coastguard Worker if (auto writer = getWriter(display)) {
1184*38e8c45fSAndroid Build Coastguard Worker writer->get().setLayerPerFrameMetadata(translate<int64_t>(display),
1185*38e8c45fSAndroid Build Coastguard Worker translate<int64_t>(layer),
1186*38e8c45fSAndroid Build Coastguard Worker translate<AidlPerFrameMetadata>(perFrameMetadatas));
1187*38e8c45fSAndroid Build Coastguard Worker } else {
1188*38e8c45fSAndroid Build Coastguard Worker error = Error::BAD_DISPLAY;
1189*38e8c45fSAndroid Build Coastguard Worker }
1190*38e8c45fSAndroid Build Coastguard Worker mMutex.unlock_shared();
1191*38e8c45fSAndroid Build Coastguard Worker return error;
1192*38e8c45fSAndroid Build Coastguard Worker }
1193*38e8c45fSAndroid Build Coastguard Worker
getPerFrameMetadataKeys(Display display)1194*38e8c45fSAndroid Build Coastguard Worker std::vector<IComposerClient::PerFrameMetadataKey> AidlComposer::getPerFrameMetadataKeys(
1195*38e8c45fSAndroid Build Coastguard Worker Display display) {
1196*38e8c45fSAndroid Build Coastguard Worker std::vector<AidlPerFrameMetadataKey> keys;
1197*38e8c45fSAndroid Build Coastguard Worker const auto status =
1198*38e8c45fSAndroid Build Coastguard Worker mAidlComposerClient->getPerFrameMetadataKeys(translate<int64_t>(display), &keys);
1199*38e8c45fSAndroid Build Coastguard Worker if (!status.isOk()) {
1200*38e8c45fSAndroid Build Coastguard Worker ALOGE("getPerFrameMetadataKeys failed %s", status.getDescription().c_str());
1201*38e8c45fSAndroid Build Coastguard Worker return {};
1202*38e8c45fSAndroid Build Coastguard Worker }
1203*38e8c45fSAndroid Build Coastguard Worker return translate<IComposerClient::PerFrameMetadataKey>(keys);
1204*38e8c45fSAndroid Build Coastguard Worker }
1205*38e8c45fSAndroid Build Coastguard Worker
getRenderIntents(Display display,ColorMode colorMode,std::vector<RenderIntent> * outRenderIntents)1206*38e8c45fSAndroid Build Coastguard Worker Error AidlComposer::getRenderIntents(Display display, ColorMode colorMode,
1207*38e8c45fSAndroid Build Coastguard Worker std::vector<RenderIntent>* outRenderIntents) {
1208*38e8c45fSAndroid Build Coastguard Worker std::vector<AidlRenderIntent> renderIntents;
1209*38e8c45fSAndroid Build Coastguard Worker const auto status = mAidlComposerClient->getRenderIntents(translate<int64_t>(display),
1210*38e8c45fSAndroid Build Coastguard Worker translate<AidlColorMode>(colorMode),
1211*38e8c45fSAndroid Build Coastguard Worker &renderIntents);
1212*38e8c45fSAndroid Build Coastguard Worker if (!status.isOk()) {
1213*38e8c45fSAndroid Build Coastguard Worker ALOGE("getRenderIntents failed %s", status.getDescription().c_str());
1214*38e8c45fSAndroid Build Coastguard Worker return static_cast<Error>(status.getServiceSpecificError());
1215*38e8c45fSAndroid Build Coastguard Worker }
1216*38e8c45fSAndroid Build Coastguard Worker *outRenderIntents = translate<RenderIntent>(renderIntents);
1217*38e8c45fSAndroid Build Coastguard Worker return Error::NONE;
1218*38e8c45fSAndroid Build Coastguard Worker }
1219*38e8c45fSAndroid Build Coastguard Worker
getDataspaceSaturationMatrix(Dataspace dataspace,mat4 * outMatrix)1220*38e8c45fSAndroid Build Coastguard Worker Error AidlComposer::getDataspaceSaturationMatrix(Dataspace dataspace, mat4* outMatrix) {
1221*38e8c45fSAndroid Build Coastguard Worker std::vector<float> matrix;
1222*38e8c45fSAndroid Build Coastguard Worker const auto status =
1223*38e8c45fSAndroid Build Coastguard Worker mAidlComposerClient->getDataspaceSaturationMatrix(translate<AidlDataspace>(dataspace),
1224*38e8c45fSAndroid Build Coastguard Worker &matrix);
1225*38e8c45fSAndroid Build Coastguard Worker if (!status.isOk()) {
1226*38e8c45fSAndroid Build Coastguard Worker ALOGE("getDataspaceSaturationMatrix failed %s", status.getDescription().c_str());
1227*38e8c45fSAndroid Build Coastguard Worker return static_cast<Error>(status.getServiceSpecificError());
1228*38e8c45fSAndroid Build Coastguard Worker }
1229*38e8c45fSAndroid Build Coastguard Worker *outMatrix = makeMat4(matrix);
1230*38e8c45fSAndroid Build Coastguard Worker return Error::NONE;
1231*38e8c45fSAndroid Build Coastguard Worker }
1232*38e8c45fSAndroid Build Coastguard Worker
getDisplayIdentificationData(Display display,uint8_t * outPort,std::vector<uint8_t> * outData)1233*38e8c45fSAndroid Build Coastguard Worker Error AidlComposer::getDisplayIdentificationData(Display display, uint8_t* outPort,
1234*38e8c45fSAndroid Build Coastguard Worker std::vector<uint8_t>* outData) {
1235*38e8c45fSAndroid Build Coastguard Worker AidlDisplayIdentification displayIdentification;
1236*38e8c45fSAndroid Build Coastguard Worker const auto status =
1237*38e8c45fSAndroid Build Coastguard Worker mAidlComposerClient->getDisplayIdentificationData(translate<int64_t>(display),
1238*38e8c45fSAndroid Build Coastguard Worker &displayIdentification);
1239*38e8c45fSAndroid Build Coastguard Worker if (!status.isOk()) {
1240*38e8c45fSAndroid Build Coastguard Worker ALOGE("getDisplayIdentificationData failed %s", status.getDescription().c_str());
1241*38e8c45fSAndroid Build Coastguard Worker return static_cast<Error>(status.getServiceSpecificError());
1242*38e8c45fSAndroid Build Coastguard Worker }
1243*38e8c45fSAndroid Build Coastguard Worker
1244*38e8c45fSAndroid Build Coastguard Worker *outPort = static_cast<uint8_t>(displayIdentification.port);
1245*38e8c45fSAndroid Build Coastguard Worker *outData = displayIdentification.data;
1246*38e8c45fSAndroid Build Coastguard Worker
1247*38e8c45fSAndroid Build Coastguard Worker return Error::NONE;
1248*38e8c45fSAndroid Build Coastguard Worker }
1249*38e8c45fSAndroid Build Coastguard Worker
setLayerColorTransform(Display display,Layer layer,const float * matrix)1250*38e8c45fSAndroid Build Coastguard Worker Error AidlComposer::setLayerColorTransform(Display display, Layer layer, const float* matrix) {
1251*38e8c45fSAndroid Build Coastguard Worker Error error = Error::NONE;
1252*38e8c45fSAndroid Build Coastguard Worker mMutex.lock_shared();
1253*38e8c45fSAndroid Build Coastguard Worker if (auto writer = getWriter(display)) {
1254*38e8c45fSAndroid Build Coastguard Worker writer->get().setLayerColorTransform(translate<int64_t>(display), translate<int64_t>(layer),
1255*38e8c45fSAndroid Build Coastguard Worker matrix);
1256*38e8c45fSAndroid Build Coastguard Worker } else {
1257*38e8c45fSAndroid Build Coastguard Worker error = Error::BAD_DISPLAY;
1258*38e8c45fSAndroid Build Coastguard Worker }
1259*38e8c45fSAndroid Build Coastguard Worker mMutex.unlock_shared();
1260*38e8c45fSAndroid Build Coastguard Worker return error;
1261*38e8c45fSAndroid Build Coastguard Worker }
1262*38e8c45fSAndroid Build Coastguard Worker
getDisplayedContentSamplingAttributes(Display display,PixelFormat * outFormat,Dataspace * outDataspace,uint8_t * outComponentMask)1263*38e8c45fSAndroid Build Coastguard Worker Error AidlComposer::getDisplayedContentSamplingAttributes(Display display, PixelFormat* outFormat,
1264*38e8c45fSAndroid Build Coastguard Worker Dataspace* outDataspace,
1265*38e8c45fSAndroid Build Coastguard Worker uint8_t* outComponentMask) {
1266*38e8c45fSAndroid Build Coastguard Worker if (!outFormat || !outDataspace || !outComponentMask) {
1267*38e8c45fSAndroid Build Coastguard Worker return Error::BAD_PARAMETER;
1268*38e8c45fSAndroid Build Coastguard Worker }
1269*38e8c45fSAndroid Build Coastguard Worker
1270*38e8c45fSAndroid Build Coastguard Worker AidlDisplayContentSamplingAttributes attributes;
1271*38e8c45fSAndroid Build Coastguard Worker const auto status =
1272*38e8c45fSAndroid Build Coastguard Worker mAidlComposerClient->getDisplayedContentSamplingAttributes(translate<int64_t>(display),
1273*38e8c45fSAndroid Build Coastguard Worker &attributes);
1274*38e8c45fSAndroid Build Coastguard Worker if (!status.isOk()) {
1275*38e8c45fSAndroid Build Coastguard Worker ALOGE("getDisplayedContentSamplingAttributes failed %s", status.getDescription().c_str());
1276*38e8c45fSAndroid Build Coastguard Worker return static_cast<Error>(status.getServiceSpecificError());
1277*38e8c45fSAndroid Build Coastguard Worker }
1278*38e8c45fSAndroid Build Coastguard Worker
1279*38e8c45fSAndroid Build Coastguard Worker *outFormat = translate<PixelFormat>(attributes.format);
1280*38e8c45fSAndroid Build Coastguard Worker *outDataspace = translate<Dataspace>(attributes.dataspace);
1281*38e8c45fSAndroid Build Coastguard Worker *outComponentMask = static_cast<uint8_t>(attributes.componentMask);
1282*38e8c45fSAndroid Build Coastguard Worker return Error::NONE;
1283*38e8c45fSAndroid Build Coastguard Worker }
1284*38e8c45fSAndroid Build Coastguard Worker
setDisplayContentSamplingEnabled(Display display,bool enabled,uint8_t componentMask,uint64_t maxFrames)1285*38e8c45fSAndroid Build Coastguard Worker Error AidlComposer::setDisplayContentSamplingEnabled(Display display, bool enabled,
1286*38e8c45fSAndroid Build Coastguard Worker uint8_t componentMask, uint64_t maxFrames) {
1287*38e8c45fSAndroid Build Coastguard Worker const auto status =
1288*38e8c45fSAndroid Build Coastguard Worker mAidlComposerClient
1289*38e8c45fSAndroid Build Coastguard Worker ->setDisplayedContentSamplingEnabled(translate<int64_t>(display), enabled,
1290*38e8c45fSAndroid Build Coastguard Worker static_cast<AidlFormatColorComponent>(
1291*38e8c45fSAndroid Build Coastguard Worker componentMask),
1292*38e8c45fSAndroid Build Coastguard Worker static_cast<int64_t>(maxFrames));
1293*38e8c45fSAndroid Build Coastguard Worker if (!status.isOk()) {
1294*38e8c45fSAndroid Build Coastguard Worker ALOGE("setDisplayedContentSamplingEnabled failed %s", status.getDescription().c_str());
1295*38e8c45fSAndroid Build Coastguard Worker return static_cast<Error>(status.getServiceSpecificError());
1296*38e8c45fSAndroid Build Coastguard Worker }
1297*38e8c45fSAndroid Build Coastguard Worker return Error::NONE;
1298*38e8c45fSAndroid Build Coastguard Worker }
1299*38e8c45fSAndroid Build Coastguard Worker
getDisplayedContentSample(Display display,uint64_t maxFrames,uint64_t timestamp,DisplayedFrameStats * outStats)1300*38e8c45fSAndroid Build Coastguard Worker Error AidlComposer::getDisplayedContentSample(Display display, uint64_t maxFrames,
1301*38e8c45fSAndroid Build Coastguard Worker uint64_t timestamp, DisplayedFrameStats* outStats) {
1302*38e8c45fSAndroid Build Coastguard Worker if (!outStats) {
1303*38e8c45fSAndroid Build Coastguard Worker return Error::BAD_PARAMETER;
1304*38e8c45fSAndroid Build Coastguard Worker }
1305*38e8c45fSAndroid Build Coastguard Worker
1306*38e8c45fSAndroid Build Coastguard Worker AidlDisplayContentSample sample;
1307*38e8c45fSAndroid Build Coastguard Worker const auto status =
1308*38e8c45fSAndroid Build Coastguard Worker mAidlComposerClient->getDisplayedContentSample(translate<int64_t>(display),
1309*38e8c45fSAndroid Build Coastguard Worker static_cast<int64_t>(maxFrames),
1310*38e8c45fSAndroid Build Coastguard Worker static_cast<int64_t>(timestamp),
1311*38e8c45fSAndroid Build Coastguard Worker &sample);
1312*38e8c45fSAndroid Build Coastguard Worker if (!status.isOk()) {
1313*38e8c45fSAndroid Build Coastguard Worker ALOGE("getDisplayedContentSample failed %s", status.getDescription().c_str());
1314*38e8c45fSAndroid Build Coastguard Worker return static_cast<Error>(status.getServiceSpecificError());
1315*38e8c45fSAndroid Build Coastguard Worker }
1316*38e8c45fSAndroid Build Coastguard Worker *outStats = translate<DisplayedFrameStats>(sample);
1317*38e8c45fSAndroid Build Coastguard Worker return Error::NONE;
1318*38e8c45fSAndroid Build Coastguard Worker }
1319*38e8c45fSAndroid Build Coastguard Worker
setLayerPerFrameMetadataBlobs(Display display,Layer layer,const std::vector<IComposerClient::PerFrameMetadataBlob> & metadata)1320*38e8c45fSAndroid Build Coastguard Worker Error AidlComposer::setLayerPerFrameMetadataBlobs(
1321*38e8c45fSAndroid Build Coastguard Worker Display display, Layer layer,
1322*38e8c45fSAndroid Build Coastguard Worker const std::vector<IComposerClient::PerFrameMetadataBlob>& metadata) {
1323*38e8c45fSAndroid Build Coastguard Worker Error error = Error::NONE;
1324*38e8c45fSAndroid Build Coastguard Worker mMutex.lock_shared();
1325*38e8c45fSAndroid Build Coastguard Worker if (auto writer = getWriter(display)) {
1326*38e8c45fSAndroid Build Coastguard Worker writer->get().setLayerPerFrameMetadataBlobs(translate<int64_t>(display),
1327*38e8c45fSAndroid Build Coastguard Worker translate<int64_t>(layer),
1328*38e8c45fSAndroid Build Coastguard Worker translate<AidlPerFrameMetadataBlob>(metadata));
1329*38e8c45fSAndroid Build Coastguard Worker } else {
1330*38e8c45fSAndroid Build Coastguard Worker error = Error::BAD_DISPLAY;
1331*38e8c45fSAndroid Build Coastguard Worker }
1332*38e8c45fSAndroid Build Coastguard Worker mMutex.unlock_shared();
1333*38e8c45fSAndroid Build Coastguard Worker return error;
1334*38e8c45fSAndroid Build Coastguard Worker }
1335*38e8c45fSAndroid Build Coastguard Worker
setDisplayBrightness(Display display,float brightness,float brightnessNits,const DisplayBrightnessOptions & options)1336*38e8c45fSAndroid Build Coastguard Worker Error AidlComposer::setDisplayBrightness(Display display, float brightness, float brightnessNits,
1337*38e8c45fSAndroid Build Coastguard Worker const DisplayBrightnessOptions& options) {
1338*38e8c45fSAndroid Build Coastguard Worker Error error = Error::NONE;
1339*38e8c45fSAndroid Build Coastguard Worker mMutex.lock_shared();
1340*38e8c45fSAndroid Build Coastguard Worker if (auto writer = getWriter(display)) {
1341*38e8c45fSAndroid Build Coastguard Worker writer->get().setDisplayBrightness(translate<int64_t>(display), brightness, brightnessNits);
1342*38e8c45fSAndroid Build Coastguard Worker
1343*38e8c45fSAndroid Build Coastguard Worker if (options.applyImmediately) {
1344*38e8c45fSAndroid Build Coastguard Worker error = execute(display);
1345*38e8c45fSAndroid Build Coastguard Worker mMutex.unlock_shared();
1346*38e8c45fSAndroid Build Coastguard Worker return error;
1347*38e8c45fSAndroid Build Coastguard Worker }
1348*38e8c45fSAndroid Build Coastguard Worker } else {
1349*38e8c45fSAndroid Build Coastguard Worker error = Error::BAD_DISPLAY;
1350*38e8c45fSAndroid Build Coastguard Worker }
1351*38e8c45fSAndroid Build Coastguard Worker mMutex.unlock_shared();
1352*38e8c45fSAndroid Build Coastguard Worker return error;
1353*38e8c45fSAndroid Build Coastguard Worker }
1354*38e8c45fSAndroid Build Coastguard Worker
getDisplayCapabilities(Display display,std::vector<AidlDisplayCapability> * outCapabilities)1355*38e8c45fSAndroid Build Coastguard Worker Error AidlComposer::getDisplayCapabilities(Display display,
1356*38e8c45fSAndroid Build Coastguard Worker std::vector<AidlDisplayCapability>* outCapabilities) {
1357*38e8c45fSAndroid Build Coastguard Worker const auto status = mAidlComposerClient->getDisplayCapabilities(translate<int64_t>(display),
1358*38e8c45fSAndroid Build Coastguard Worker outCapabilities);
1359*38e8c45fSAndroid Build Coastguard Worker if (!status.isOk()) {
1360*38e8c45fSAndroid Build Coastguard Worker ALOGE("getDisplayCapabilities failed %s", status.getDescription().c_str());
1361*38e8c45fSAndroid Build Coastguard Worker outCapabilities->clear();
1362*38e8c45fSAndroid Build Coastguard Worker return static_cast<Error>(status.getServiceSpecificError());
1363*38e8c45fSAndroid Build Coastguard Worker }
1364*38e8c45fSAndroid Build Coastguard Worker return Error::NONE;
1365*38e8c45fSAndroid Build Coastguard Worker }
1366*38e8c45fSAndroid Build Coastguard Worker
getDisplayConnectionType(Display display,IComposerClient::DisplayConnectionType * outType)1367*38e8c45fSAndroid Build Coastguard Worker V2_4::Error AidlComposer::getDisplayConnectionType(
1368*38e8c45fSAndroid Build Coastguard Worker Display display, IComposerClient::DisplayConnectionType* outType) {
1369*38e8c45fSAndroid Build Coastguard Worker AidlDisplayConnectionType type;
1370*38e8c45fSAndroid Build Coastguard Worker const auto status =
1371*38e8c45fSAndroid Build Coastguard Worker mAidlComposerClient->getDisplayConnectionType(translate<int64_t>(display), &type);
1372*38e8c45fSAndroid Build Coastguard Worker if (!status.isOk()) {
1373*38e8c45fSAndroid Build Coastguard Worker ALOGE("getDisplayConnectionType failed %s", status.getDescription().c_str());
1374*38e8c45fSAndroid Build Coastguard Worker return static_cast<V2_4::Error>(status.getServiceSpecificError());
1375*38e8c45fSAndroid Build Coastguard Worker }
1376*38e8c45fSAndroid Build Coastguard Worker *outType = translate<IComposerClient::DisplayConnectionType>(type);
1377*38e8c45fSAndroid Build Coastguard Worker return V2_4::Error::NONE;
1378*38e8c45fSAndroid Build Coastguard Worker }
1379*38e8c45fSAndroid Build Coastguard Worker
getDisplayVsyncPeriod(Display display,VsyncPeriodNanos * outVsyncPeriod)1380*38e8c45fSAndroid Build Coastguard Worker V2_4::Error AidlComposer::getDisplayVsyncPeriod(Display display, VsyncPeriodNanos* outVsyncPeriod) {
1381*38e8c45fSAndroid Build Coastguard Worker int32_t vsyncPeriod;
1382*38e8c45fSAndroid Build Coastguard Worker const auto status =
1383*38e8c45fSAndroid Build Coastguard Worker mAidlComposerClient->getDisplayVsyncPeriod(translate<int64_t>(display), &vsyncPeriod);
1384*38e8c45fSAndroid Build Coastguard Worker if (!status.isOk()) {
1385*38e8c45fSAndroid Build Coastguard Worker ALOGE("getDisplayVsyncPeriod failed %s", status.getDescription().c_str());
1386*38e8c45fSAndroid Build Coastguard Worker return static_cast<V2_4::Error>(status.getServiceSpecificError());
1387*38e8c45fSAndroid Build Coastguard Worker }
1388*38e8c45fSAndroid Build Coastguard Worker *outVsyncPeriod = translate<VsyncPeriodNanos>(vsyncPeriod);
1389*38e8c45fSAndroid Build Coastguard Worker return V2_4::Error::NONE;
1390*38e8c45fSAndroid Build Coastguard Worker }
1391*38e8c45fSAndroid Build Coastguard Worker
setActiveConfigWithConstraints(Display display,Config config,const IComposerClient::VsyncPeriodChangeConstraints & vsyncPeriodChangeConstraints,VsyncPeriodChangeTimeline * outTimeline)1392*38e8c45fSAndroid Build Coastguard Worker Error AidlComposer::setActiveConfigWithConstraints(
1393*38e8c45fSAndroid Build Coastguard Worker Display display, Config config,
1394*38e8c45fSAndroid Build Coastguard Worker const IComposerClient::VsyncPeriodChangeConstraints& vsyncPeriodChangeConstraints,
1395*38e8c45fSAndroid Build Coastguard Worker VsyncPeriodChangeTimeline* outTimeline) {
1396*38e8c45fSAndroid Build Coastguard Worker AidlVsyncPeriodChangeTimeline timeline;
1397*38e8c45fSAndroid Build Coastguard Worker const auto status =
1398*38e8c45fSAndroid Build Coastguard Worker mAidlComposerClient
1399*38e8c45fSAndroid Build Coastguard Worker ->setActiveConfigWithConstraints(translate<int64_t>(display),
1400*38e8c45fSAndroid Build Coastguard Worker translate<int32_t>(config),
1401*38e8c45fSAndroid Build Coastguard Worker translate<AidlVsyncPeriodChangeConstraints>(
1402*38e8c45fSAndroid Build Coastguard Worker vsyncPeriodChangeConstraints),
1403*38e8c45fSAndroid Build Coastguard Worker &timeline);
1404*38e8c45fSAndroid Build Coastguard Worker if (!status.isOk()) {
1405*38e8c45fSAndroid Build Coastguard Worker ALOGE("setActiveConfigWithConstraints failed %s", status.getDescription().c_str());
1406*38e8c45fSAndroid Build Coastguard Worker return static_cast<Error>(status.getServiceSpecificError());
1407*38e8c45fSAndroid Build Coastguard Worker }
1408*38e8c45fSAndroid Build Coastguard Worker *outTimeline = translate<VsyncPeriodChangeTimeline>(timeline);
1409*38e8c45fSAndroid Build Coastguard Worker return Error::NONE;
1410*38e8c45fSAndroid Build Coastguard Worker }
1411*38e8c45fSAndroid Build Coastguard Worker
setAutoLowLatencyMode(Display display,bool on)1412*38e8c45fSAndroid Build Coastguard Worker V2_4::Error AidlComposer::setAutoLowLatencyMode(Display display, bool on) {
1413*38e8c45fSAndroid Build Coastguard Worker const auto status = mAidlComposerClient->setAutoLowLatencyMode(translate<int64_t>(display), on);
1414*38e8c45fSAndroid Build Coastguard Worker if (!status.isOk()) {
1415*38e8c45fSAndroid Build Coastguard Worker ALOGE("setAutoLowLatencyMode failed %s", status.getDescription().c_str());
1416*38e8c45fSAndroid Build Coastguard Worker return static_cast<V2_4::Error>(status.getServiceSpecificError());
1417*38e8c45fSAndroid Build Coastguard Worker }
1418*38e8c45fSAndroid Build Coastguard Worker return V2_4::Error::NONE;
1419*38e8c45fSAndroid Build Coastguard Worker }
1420*38e8c45fSAndroid Build Coastguard Worker
getSupportedContentTypes(Display displayId,std::vector<IComposerClient::ContentType> * outSupportedContentTypes)1421*38e8c45fSAndroid Build Coastguard Worker V2_4::Error AidlComposer::getSupportedContentTypes(
1422*38e8c45fSAndroid Build Coastguard Worker Display displayId, std::vector<IComposerClient::ContentType>* outSupportedContentTypes) {
1423*38e8c45fSAndroid Build Coastguard Worker std::vector<AidlContentType> types;
1424*38e8c45fSAndroid Build Coastguard Worker const auto status =
1425*38e8c45fSAndroid Build Coastguard Worker mAidlComposerClient->getSupportedContentTypes(translate<int64_t>(displayId), &types);
1426*38e8c45fSAndroid Build Coastguard Worker if (!status.isOk()) {
1427*38e8c45fSAndroid Build Coastguard Worker ALOGE("getSupportedContentTypes failed %s", status.getDescription().c_str());
1428*38e8c45fSAndroid Build Coastguard Worker return static_cast<V2_4::Error>(status.getServiceSpecificError());
1429*38e8c45fSAndroid Build Coastguard Worker }
1430*38e8c45fSAndroid Build Coastguard Worker *outSupportedContentTypes = translate<IComposerClient::ContentType>(types);
1431*38e8c45fSAndroid Build Coastguard Worker return V2_4::Error::NONE;
1432*38e8c45fSAndroid Build Coastguard Worker }
1433*38e8c45fSAndroid Build Coastguard Worker
setContentType(Display display,IComposerClient::ContentType contentType)1434*38e8c45fSAndroid Build Coastguard Worker V2_4::Error AidlComposer::setContentType(Display display,
1435*38e8c45fSAndroid Build Coastguard Worker IComposerClient::ContentType contentType) {
1436*38e8c45fSAndroid Build Coastguard Worker const auto status =
1437*38e8c45fSAndroid Build Coastguard Worker mAidlComposerClient->setContentType(translate<int64_t>(display),
1438*38e8c45fSAndroid Build Coastguard Worker translate<AidlContentType>(contentType));
1439*38e8c45fSAndroid Build Coastguard Worker if (!status.isOk()) {
1440*38e8c45fSAndroid Build Coastguard Worker ALOGE("setContentType failed %s", status.getDescription().c_str());
1441*38e8c45fSAndroid Build Coastguard Worker return static_cast<V2_4::Error>(status.getServiceSpecificError());
1442*38e8c45fSAndroid Build Coastguard Worker }
1443*38e8c45fSAndroid Build Coastguard Worker return V2_4::Error::NONE;
1444*38e8c45fSAndroid Build Coastguard Worker }
1445*38e8c45fSAndroid Build Coastguard Worker
setLayerGenericMetadata(Display,Layer,const std::string &,bool,const std::vector<uint8_t> &)1446*38e8c45fSAndroid Build Coastguard Worker V2_4::Error AidlComposer::setLayerGenericMetadata(Display, Layer, const std::string&, bool,
1447*38e8c45fSAndroid Build Coastguard Worker const std::vector<uint8_t>&) {
1448*38e8c45fSAndroid Build Coastguard Worker // There are no users for this API. See b/209691612.
1449*38e8c45fSAndroid Build Coastguard Worker return V2_4::Error::UNSUPPORTED;
1450*38e8c45fSAndroid Build Coastguard Worker }
1451*38e8c45fSAndroid Build Coastguard Worker
getLayerGenericMetadataKeys(std::vector<IComposerClient::LayerGenericMetadataKey> *)1452*38e8c45fSAndroid Build Coastguard Worker V2_4::Error AidlComposer::getLayerGenericMetadataKeys(
1453*38e8c45fSAndroid Build Coastguard Worker std::vector<IComposerClient::LayerGenericMetadataKey>*) {
1454*38e8c45fSAndroid Build Coastguard Worker // There are no users for this API. See b/209691612.
1455*38e8c45fSAndroid Build Coastguard Worker return V2_4::Error::UNSUPPORTED;
1456*38e8c45fSAndroid Build Coastguard Worker }
1457*38e8c45fSAndroid Build Coastguard Worker
setBootDisplayConfig(Display display,Config config)1458*38e8c45fSAndroid Build Coastguard Worker Error AidlComposer::setBootDisplayConfig(Display display, Config config) {
1459*38e8c45fSAndroid Build Coastguard Worker const auto status = mAidlComposerClient->setBootDisplayConfig(translate<int64_t>(display),
1460*38e8c45fSAndroid Build Coastguard Worker translate<int32_t>(config));
1461*38e8c45fSAndroid Build Coastguard Worker if (!status.isOk()) {
1462*38e8c45fSAndroid Build Coastguard Worker ALOGE("setBootDisplayConfig failed %s", status.getDescription().c_str());
1463*38e8c45fSAndroid Build Coastguard Worker return static_cast<Error>(status.getServiceSpecificError());
1464*38e8c45fSAndroid Build Coastguard Worker }
1465*38e8c45fSAndroid Build Coastguard Worker return Error::NONE;
1466*38e8c45fSAndroid Build Coastguard Worker }
1467*38e8c45fSAndroid Build Coastguard Worker
clearBootDisplayConfig(Display display)1468*38e8c45fSAndroid Build Coastguard Worker Error AidlComposer::clearBootDisplayConfig(Display display) {
1469*38e8c45fSAndroid Build Coastguard Worker const auto status = mAidlComposerClient->clearBootDisplayConfig(translate<int64_t>(display));
1470*38e8c45fSAndroid Build Coastguard Worker if (!status.isOk()) {
1471*38e8c45fSAndroid Build Coastguard Worker ALOGE("clearBootDisplayConfig failed %s", status.getDescription().c_str());
1472*38e8c45fSAndroid Build Coastguard Worker return static_cast<Error>(status.getServiceSpecificError());
1473*38e8c45fSAndroid Build Coastguard Worker }
1474*38e8c45fSAndroid Build Coastguard Worker return Error::NONE;
1475*38e8c45fSAndroid Build Coastguard Worker }
1476*38e8c45fSAndroid Build Coastguard Worker
getPreferredBootDisplayConfig(Display display,Config * config)1477*38e8c45fSAndroid Build Coastguard Worker Error AidlComposer::getPreferredBootDisplayConfig(Display display, Config* config) {
1478*38e8c45fSAndroid Build Coastguard Worker int32_t displayConfig;
1479*38e8c45fSAndroid Build Coastguard Worker const auto status =
1480*38e8c45fSAndroid Build Coastguard Worker mAidlComposerClient->getPreferredBootDisplayConfig(translate<int64_t>(display),
1481*38e8c45fSAndroid Build Coastguard Worker &displayConfig);
1482*38e8c45fSAndroid Build Coastguard Worker if (!status.isOk()) {
1483*38e8c45fSAndroid Build Coastguard Worker ALOGE("getPreferredBootDisplayConfig failed %s", status.getDescription().c_str());
1484*38e8c45fSAndroid Build Coastguard Worker return static_cast<Error>(status.getServiceSpecificError());
1485*38e8c45fSAndroid Build Coastguard Worker }
1486*38e8c45fSAndroid Build Coastguard Worker *config = translate<uint32_t>(displayConfig);
1487*38e8c45fSAndroid Build Coastguard Worker return Error::NONE;
1488*38e8c45fSAndroid Build Coastguard Worker }
1489*38e8c45fSAndroid Build Coastguard Worker
getHdrConversionCapabilities(std::vector<AidlHdrConversionCapability> * hdrConversionCapabilities)1490*38e8c45fSAndroid Build Coastguard Worker Error AidlComposer::getHdrConversionCapabilities(
1491*38e8c45fSAndroid Build Coastguard Worker std::vector<AidlHdrConversionCapability>* hdrConversionCapabilities) {
1492*38e8c45fSAndroid Build Coastguard Worker const auto status =
1493*38e8c45fSAndroid Build Coastguard Worker mAidlComposerClient->getHdrConversionCapabilities(hdrConversionCapabilities);
1494*38e8c45fSAndroid Build Coastguard Worker if (!status.isOk()) {
1495*38e8c45fSAndroid Build Coastguard Worker hdrConversionCapabilities = {};
1496*38e8c45fSAndroid Build Coastguard Worker ALOGE("getHdrConversionCapabilities failed %s", status.getDescription().c_str());
1497*38e8c45fSAndroid Build Coastguard Worker return static_cast<Error>(status.getServiceSpecificError());
1498*38e8c45fSAndroid Build Coastguard Worker }
1499*38e8c45fSAndroid Build Coastguard Worker return Error::NONE;
1500*38e8c45fSAndroid Build Coastguard Worker }
1501*38e8c45fSAndroid Build Coastguard Worker
setHdrConversionStrategy(AidlHdrConversionStrategy hdrConversionStrategy,Hdr * outPreferredHdrOutputType)1502*38e8c45fSAndroid Build Coastguard Worker Error AidlComposer::setHdrConversionStrategy(AidlHdrConversionStrategy hdrConversionStrategy,
1503*38e8c45fSAndroid Build Coastguard Worker Hdr* outPreferredHdrOutputType) {
1504*38e8c45fSAndroid Build Coastguard Worker const auto status = mAidlComposerClient->setHdrConversionStrategy(hdrConversionStrategy,
1505*38e8c45fSAndroid Build Coastguard Worker outPreferredHdrOutputType);
1506*38e8c45fSAndroid Build Coastguard Worker if (!status.isOk()) {
1507*38e8c45fSAndroid Build Coastguard Worker ALOGE("setHdrConversionStrategy failed %s", status.getDescription().c_str());
1508*38e8c45fSAndroid Build Coastguard Worker return static_cast<Error>(status.getServiceSpecificError());
1509*38e8c45fSAndroid Build Coastguard Worker }
1510*38e8c45fSAndroid Build Coastguard Worker return Error::NONE;
1511*38e8c45fSAndroid Build Coastguard Worker }
1512*38e8c45fSAndroid Build Coastguard Worker
setRefreshRateChangedCallbackDebugEnabled(Display displayId,bool enabled)1513*38e8c45fSAndroid Build Coastguard Worker Error AidlComposer::setRefreshRateChangedCallbackDebugEnabled(Display displayId, bool enabled) {
1514*38e8c45fSAndroid Build Coastguard Worker const auto status =
1515*38e8c45fSAndroid Build Coastguard Worker mAidlComposerClient->setRefreshRateChangedCallbackDebugEnabled(translate<int64_t>(
1516*38e8c45fSAndroid Build Coastguard Worker displayId),
1517*38e8c45fSAndroid Build Coastguard Worker enabled);
1518*38e8c45fSAndroid Build Coastguard Worker if (!status.isOk()) {
1519*38e8c45fSAndroid Build Coastguard Worker ALOGE("setRefreshRateChangedCallbackDebugEnabled failed %s",
1520*38e8c45fSAndroid Build Coastguard Worker status.getDescription().c_str());
1521*38e8c45fSAndroid Build Coastguard Worker return static_cast<Error>(status.getServiceSpecificError());
1522*38e8c45fSAndroid Build Coastguard Worker }
1523*38e8c45fSAndroid Build Coastguard Worker return Error::NONE;
1524*38e8c45fSAndroid Build Coastguard Worker }
1525*38e8c45fSAndroid Build Coastguard Worker
notifyExpectedPresent(Display displayId,nsecs_t expectedPresentTime,int32_t frameIntervalNs)1526*38e8c45fSAndroid Build Coastguard Worker Error AidlComposer::notifyExpectedPresent(Display displayId, nsecs_t expectedPresentTime,
1527*38e8c45fSAndroid Build Coastguard Worker int32_t frameIntervalNs) {
1528*38e8c45fSAndroid Build Coastguard Worker const auto status =
1529*38e8c45fSAndroid Build Coastguard Worker mAidlComposerClient->notifyExpectedPresent(translate<int64_t>(displayId),
1530*38e8c45fSAndroid Build Coastguard Worker ClockMonotonicTimestamp{expectedPresentTime},
1531*38e8c45fSAndroid Build Coastguard Worker frameIntervalNs);
1532*38e8c45fSAndroid Build Coastguard Worker
1533*38e8c45fSAndroid Build Coastguard Worker if (!status.isOk()) {
1534*38e8c45fSAndroid Build Coastguard Worker ALOGE("notifyExpectedPresent failed %s", status.getDescription().c_str());
1535*38e8c45fSAndroid Build Coastguard Worker return static_cast<Error>(status.getServiceSpecificError());
1536*38e8c45fSAndroid Build Coastguard Worker }
1537*38e8c45fSAndroid Build Coastguard Worker return Error::NONE;
1538*38e8c45fSAndroid Build Coastguard Worker }
1539*38e8c45fSAndroid Build Coastguard Worker
getClientTargetProperty(Display display,ClientTargetPropertyWithBrightness * outClientTargetProperty)1540*38e8c45fSAndroid Build Coastguard Worker Error AidlComposer::getClientTargetProperty(
1541*38e8c45fSAndroid Build Coastguard Worker Display display, ClientTargetPropertyWithBrightness* outClientTargetProperty) {
1542*38e8c45fSAndroid Build Coastguard Worker Error error = Error::NONE;
1543*38e8c45fSAndroid Build Coastguard Worker mMutex.lock_shared();
1544*38e8c45fSAndroid Build Coastguard Worker if (auto reader = getReader(display)) {
1545*38e8c45fSAndroid Build Coastguard Worker *outClientTargetProperty =
1546*38e8c45fSAndroid Build Coastguard Worker reader->get().takeClientTargetProperty(translate<int64_t>(display));
1547*38e8c45fSAndroid Build Coastguard Worker } else {
1548*38e8c45fSAndroid Build Coastguard Worker error = Error::BAD_DISPLAY;
1549*38e8c45fSAndroid Build Coastguard Worker }
1550*38e8c45fSAndroid Build Coastguard Worker mMutex.unlock_shared();
1551*38e8c45fSAndroid Build Coastguard Worker return error;
1552*38e8c45fSAndroid Build Coastguard Worker }
1553*38e8c45fSAndroid Build Coastguard Worker
getRequestedLuts(Display display,std::vector<Layer> * outLayers,std::vector<DisplayLuts::LayerLut> * outLuts)1554*38e8c45fSAndroid Build Coastguard Worker Error AidlComposer::getRequestedLuts(Display display, std::vector<Layer>* outLayers,
1555*38e8c45fSAndroid Build Coastguard Worker std::vector<DisplayLuts::LayerLut>* outLuts) {
1556*38e8c45fSAndroid Build Coastguard Worker Error error = Error::NONE;
1557*38e8c45fSAndroid Build Coastguard Worker mMutex.lock_shared();
1558*38e8c45fSAndroid Build Coastguard Worker if (auto reader = getReader(display)) {
1559*38e8c45fSAndroid Build Coastguard Worker *outLuts = reader->get().takeDisplayLuts(translate<int64_t>(display));
1560*38e8c45fSAndroid Build Coastguard Worker } else {
1561*38e8c45fSAndroid Build Coastguard Worker error = Error::BAD_DISPLAY;
1562*38e8c45fSAndroid Build Coastguard Worker }
1563*38e8c45fSAndroid Build Coastguard Worker mMutex.unlock_shared();
1564*38e8c45fSAndroid Build Coastguard Worker
1565*38e8c45fSAndroid Build Coastguard Worker outLayers->reserve(outLuts->size());
1566*38e8c45fSAndroid Build Coastguard Worker for (const auto& layerLut : *outLuts) {
1567*38e8c45fSAndroid Build Coastguard Worker outLayers->emplace_back(translate<Layer>(layerLut.layer));
1568*38e8c45fSAndroid Build Coastguard Worker }
1569*38e8c45fSAndroid Build Coastguard Worker return error;
1570*38e8c45fSAndroid Build Coastguard Worker }
1571*38e8c45fSAndroid Build Coastguard Worker
setLayerLuts(Display display,Layer layer,Luts & luts)1572*38e8c45fSAndroid Build Coastguard Worker Error AidlComposer::setLayerLuts(Display display, Layer layer, Luts& luts) {
1573*38e8c45fSAndroid Build Coastguard Worker Error error = Error::NONE;
1574*38e8c45fSAndroid Build Coastguard Worker mMutex.lock_shared();
1575*38e8c45fSAndroid Build Coastguard Worker if (auto writer = getWriter(display)) {
1576*38e8c45fSAndroid Build Coastguard Worker writer->get().setLayerLuts(translate<int64_t>(display), translate<int64_t>(layer), luts);
1577*38e8c45fSAndroid Build Coastguard Worker } else {
1578*38e8c45fSAndroid Build Coastguard Worker error = Error::BAD_DISPLAY;
1579*38e8c45fSAndroid Build Coastguard Worker }
1580*38e8c45fSAndroid Build Coastguard Worker mMutex.unlock_shared();
1581*38e8c45fSAndroid Build Coastguard Worker return error;
1582*38e8c45fSAndroid Build Coastguard Worker }
1583*38e8c45fSAndroid Build Coastguard Worker
setLayerBrightness(Display display,Layer layer,float brightness)1584*38e8c45fSAndroid Build Coastguard Worker Error AidlComposer::setLayerBrightness(Display display, Layer layer, float brightness) {
1585*38e8c45fSAndroid Build Coastguard Worker Error error = Error::NONE;
1586*38e8c45fSAndroid Build Coastguard Worker mMutex.lock_shared();
1587*38e8c45fSAndroid Build Coastguard Worker if (auto writer = getWriter(display)) {
1588*38e8c45fSAndroid Build Coastguard Worker writer->get().setLayerBrightness(translate<int64_t>(display), translate<int64_t>(layer),
1589*38e8c45fSAndroid Build Coastguard Worker brightness);
1590*38e8c45fSAndroid Build Coastguard Worker } else {
1591*38e8c45fSAndroid Build Coastguard Worker error = Error::BAD_DISPLAY;
1592*38e8c45fSAndroid Build Coastguard Worker }
1593*38e8c45fSAndroid Build Coastguard Worker mMutex.unlock_shared();
1594*38e8c45fSAndroid Build Coastguard Worker return error;
1595*38e8c45fSAndroid Build Coastguard Worker }
1596*38e8c45fSAndroid Build Coastguard Worker
setLayerBlockingRegion(Display display,Layer layer,const std::vector<IComposerClient::Rect> & blocking)1597*38e8c45fSAndroid Build Coastguard Worker Error AidlComposer::setLayerBlockingRegion(Display display, Layer layer,
1598*38e8c45fSAndroid Build Coastguard Worker const std::vector<IComposerClient::Rect>& blocking) {
1599*38e8c45fSAndroid Build Coastguard Worker Error error = Error::NONE;
1600*38e8c45fSAndroid Build Coastguard Worker mMutex.lock_shared();
1601*38e8c45fSAndroid Build Coastguard Worker if (auto writer = getWriter(display)) {
1602*38e8c45fSAndroid Build Coastguard Worker writer->get().setLayerBlockingRegion(translate<int64_t>(display), translate<int64_t>(layer),
1603*38e8c45fSAndroid Build Coastguard Worker translate<AidlRect>(blocking));
1604*38e8c45fSAndroid Build Coastguard Worker } else {
1605*38e8c45fSAndroid Build Coastguard Worker error = Error::BAD_DISPLAY;
1606*38e8c45fSAndroid Build Coastguard Worker }
1607*38e8c45fSAndroid Build Coastguard Worker mMutex.unlock_shared();
1608*38e8c45fSAndroid Build Coastguard Worker return error;
1609*38e8c45fSAndroid Build Coastguard Worker }
1610*38e8c45fSAndroid Build Coastguard Worker
getDisplayDecorationSupport(Display display,std::optional<DisplayDecorationSupport> * support)1611*38e8c45fSAndroid Build Coastguard Worker Error AidlComposer::getDisplayDecorationSupport(Display display,
1612*38e8c45fSAndroid Build Coastguard Worker std::optional<DisplayDecorationSupport>* support) {
1613*38e8c45fSAndroid Build Coastguard Worker const auto status =
1614*38e8c45fSAndroid Build Coastguard Worker mAidlComposerClient->getDisplayDecorationSupport(translate<int64_t>(display), support);
1615*38e8c45fSAndroid Build Coastguard Worker if (!status.isOk()) {
1616*38e8c45fSAndroid Build Coastguard Worker ALOGE("getDisplayDecorationSupport failed %s", status.getDescription().c_str());
1617*38e8c45fSAndroid Build Coastguard Worker support->reset();
1618*38e8c45fSAndroid Build Coastguard Worker return static_cast<Error>(status.getServiceSpecificError());
1619*38e8c45fSAndroid Build Coastguard Worker }
1620*38e8c45fSAndroid Build Coastguard Worker return Error::NONE;
1621*38e8c45fSAndroid Build Coastguard Worker }
1622*38e8c45fSAndroid Build Coastguard Worker
setIdleTimerEnabled(Display displayId,std::chrono::milliseconds timeout)1623*38e8c45fSAndroid Build Coastguard Worker Error AidlComposer::setIdleTimerEnabled(Display displayId, std::chrono::milliseconds timeout) {
1624*38e8c45fSAndroid Build Coastguard Worker const auto status =
1625*38e8c45fSAndroid Build Coastguard Worker mAidlComposerClient->setIdleTimerEnabled(translate<int64_t>(displayId),
1626*38e8c45fSAndroid Build Coastguard Worker translate<int32_t>(timeout.count()));
1627*38e8c45fSAndroid Build Coastguard Worker if (!status.isOk()) {
1628*38e8c45fSAndroid Build Coastguard Worker ALOGE("setIdleTimerEnabled failed %s", status.getDescription().c_str());
1629*38e8c45fSAndroid Build Coastguard Worker return static_cast<Error>(status.getServiceSpecificError());
1630*38e8c45fSAndroid Build Coastguard Worker }
1631*38e8c45fSAndroid Build Coastguard Worker return Error::NONE;
1632*38e8c45fSAndroid Build Coastguard Worker }
1633*38e8c45fSAndroid Build Coastguard Worker
getPhysicalDisplayOrientation(Display displayId,AidlTransform * outDisplayOrientation)1634*38e8c45fSAndroid Build Coastguard Worker Error AidlComposer::getPhysicalDisplayOrientation(Display displayId,
1635*38e8c45fSAndroid Build Coastguard Worker AidlTransform* outDisplayOrientation) {
1636*38e8c45fSAndroid Build Coastguard Worker const auto status =
1637*38e8c45fSAndroid Build Coastguard Worker mAidlComposerClient->getDisplayPhysicalOrientation(translate<int64_t>(displayId),
1638*38e8c45fSAndroid Build Coastguard Worker outDisplayOrientation);
1639*38e8c45fSAndroid Build Coastguard Worker if (!status.isOk()) {
1640*38e8c45fSAndroid Build Coastguard Worker ALOGE("getPhysicalDisplayOrientation failed %s", status.getDescription().c_str());
1641*38e8c45fSAndroid Build Coastguard Worker return static_cast<Error>(status.getServiceSpecificError());
1642*38e8c45fSAndroid Build Coastguard Worker }
1643*38e8c45fSAndroid Build Coastguard Worker return Error::NONE;
1644*38e8c45fSAndroid Build Coastguard Worker }
1645*38e8c45fSAndroid Build Coastguard Worker
getMaxLayerPictureProfiles(Display display,int32_t * outMaxProfiles)1646*38e8c45fSAndroid Build Coastguard Worker Error AidlComposer::getMaxLayerPictureProfiles(Display display, int32_t* outMaxProfiles) {
1647*38e8c45fSAndroid Build Coastguard Worker const auto status = mAidlComposerClient->getMaxLayerPictureProfiles(translate<int64_t>(display),
1648*38e8c45fSAndroid Build Coastguard Worker outMaxProfiles);
1649*38e8c45fSAndroid Build Coastguard Worker if (!status.isOk()) {
1650*38e8c45fSAndroid Build Coastguard Worker ALOGE("getMaxLayerPictureProfiles failed %s", status.getDescription().c_str());
1651*38e8c45fSAndroid Build Coastguard Worker return static_cast<Error>(status.getServiceSpecificError());
1652*38e8c45fSAndroid Build Coastguard Worker }
1653*38e8c45fSAndroid Build Coastguard Worker return Error::NONE;
1654*38e8c45fSAndroid Build Coastguard Worker }
1655*38e8c45fSAndroid Build Coastguard Worker
setDisplayPictureProfileId(Display display,PictureProfileId id)1656*38e8c45fSAndroid Build Coastguard Worker Error AidlComposer::setDisplayPictureProfileId(Display display, PictureProfileId id) {
1657*38e8c45fSAndroid Build Coastguard Worker Error error = Error::NONE;
1658*38e8c45fSAndroid Build Coastguard Worker mMutex.lock_shared();
1659*38e8c45fSAndroid Build Coastguard Worker if (auto writer = getWriter(display)) {
1660*38e8c45fSAndroid Build Coastguard Worker writer->get().setDisplayPictureProfileId(translate<int64_t>(display), id);
1661*38e8c45fSAndroid Build Coastguard Worker } else {
1662*38e8c45fSAndroid Build Coastguard Worker error = Error::BAD_DISPLAY;
1663*38e8c45fSAndroid Build Coastguard Worker }
1664*38e8c45fSAndroid Build Coastguard Worker mMutex.unlock_shared();
1665*38e8c45fSAndroid Build Coastguard Worker return error;
1666*38e8c45fSAndroid Build Coastguard Worker }
1667*38e8c45fSAndroid Build Coastguard Worker
setLayerPictureProfileId(Display display,Layer layer,PictureProfileId id)1668*38e8c45fSAndroid Build Coastguard Worker Error AidlComposer::setLayerPictureProfileId(Display display, Layer layer, PictureProfileId id) {
1669*38e8c45fSAndroid Build Coastguard Worker Error error = Error::NONE;
1670*38e8c45fSAndroid Build Coastguard Worker mMutex.lock_shared();
1671*38e8c45fSAndroid Build Coastguard Worker if (auto writer = getWriter(display)) {
1672*38e8c45fSAndroid Build Coastguard Worker writer->get().setLayerPictureProfileId(translate<int64_t>(display),
1673*38e8c45fSAndroid Build Coastguard Worker translate<int64_t>(layer), id);
1674*38e8c45fSAndroid Build Coastguard Worker } else {
1675*38e8c45fSAndroid Build Coastguard Worker error = Error::BAD_DISPLAY;
1676*38e8c45fSAndroid Build Coastguard Worker }
1677*38e8c45fSAndroid Build Coastguard Worker mMutex.unlock_shared();
1678*38e8c45fSAndroid Build Coastguard Worker return error;
1679*38e8c45fSAndroid Build Coastguard Worker }
1680*38e8c45fSAndroid Build Coastguard Worker
getWriter(Display display)1681*38e8c45fSAndroid Build Coastguard Worker ftl::Optional<std::reference_wrapper<ComposerClientWriter>> AidlComposer::getWriter(Display display)
1682*38e8c45fSAndroid Build Coastguard Worker REQUIRES_SHARED(mMutex) {
1683*38e8c45fSAndroid Build Coastguard Worker return mWriters.get(display);
1684*38e8c45fSAndroid Build Coastguard Worker }
1685*38e8c45fSAndroid Build Coastguard Worker
getReader(Display display)1686*38e8c45fSAndroid Build Coastguard Worker ftl::Optional<std::reference_wrapper<ComposerClientReader>> AidlComposer::getReader(Display display)
1687*38e8c45fSAndroid Build Coastguard Worker REQUIRES_SHARED(mMutex) {
1688*38e8c45fSAndroid Build Coastguard Worker if (mSingleReader) {
1689*38e8c45fSAndroid Build Coastguard Worker display = translate<Display>(kSingleReaderKey);
1690*38e8c45fSAndroid Build Coastguard Worker }
1691*38e8c45fSAndroid Build Coastguard Worker return mReaders.get(display);
1692*38e8c45fSAndroid Build Coastguard Worker }
1693*38e8c45fSAndroid Build Coastguard Worker
removeDisplay(Display display)1694*38e8c45fSAndroid Build Coastguard Worker void AidlComposer::removeDisplay(Display display) {
1695*38e8c45fSAndroid Build Coastguard Worker mMutex.lock();
1696*38e8c45fSAndroid Build Coastguard Worker bool wasErased = mWriters.erase(display);
1697*38e8c45fSAndroid Build Coastguard Worker ALOGW_IF(!wasErased,
1698*38e8c45fSAndroid Build Coastguard Worker "Attempting to remove writer for display %" PRId64 " which is not connected",
1699*38e8c45fSAndroid Build Coastguard Worker translate<int64_t>(display));
1700*38e8c45fSAndroid Build Coastguard Worker if (!mSingleReader) {
1701*38e8c45fSAndroid Build Coastguard Worker removeReader(display);
1702*38e8c45fSAndroid Build Coastguard Worker }
1703*38e8c45fSAndroid Build Coastguard Worker mMutex.unlock();
1704*38e8c45fSAndroid Build Coastguard Worker }
1705*38e8c45fSAndroid Build Coastguard Worker
onHotplugDisconnect(Display display)1706*38e8c45fSAndroid Build Coastguard Worker void AidlComposer::onHotplugDisconnect(Display display) {
1707*38e8c45fSAndroid Build Coastguard Worker removeDisplay(display);
1708*38e8c45fSAndroid Build Coastguard Worker }
1709*38e8c45fSAndroid Build Coastguard Worker
hasMultiThreadedPresentSupport(Display display)1710*38e8c45fSAndroid Build Coastguard Worker bool AidlComposer::hasMultiThreadedPresentSupport(Display display) {
1711*38e8c45fSAndroid Build Coastguard Worker if (!FlagManager::getInstance().multithreaded_present()) return false;
1712*38e8c45fSAndroid Build Coastguard Worker const auto displayId = translate<int64_t>(display);
1713*38e8c45fSAndroid Build Coastguard Worker std::vector<AidlDisplayCapability> capabilities;
1714*38e8c45fSAndroid Build Coastguard Worker const auto status = mAidlComposerClient->getDisplayCapabilities(displayId, &capabilities);
1715*38e8c45fSAndroid Build Coastguard Worker if (!status.isOk()) {
1716*38e8c45fSAndroid Build Coastguard Worker ALOGE("getDisplayCapabilities failed %s", status.getDescription().c_str());
1717*38e8c45fSAndroid Build Coastguard Worker return false;
1718*38e8c45fSAndroid Build Coastguard Worker }
1719*38e8c45fSAndroid Build Coastguard Worker return std::find(capabilities.begin(), capabilities.end(),
1720*38e8c45fSAndroid Build Coastguard Worker AidlDisplayCapability::MULTI_THREADED_PRESENT) != capabilities.end();
1721*38e8c45fSAndroid Build Coastguard Worker }
1722*38e8c45fSAndroid Build Coastguard Worker
addReader(Display display)1723*38e8c45fSAndroid Build Coastguard Worker void AidlComposer::addReader(Display display) {
1724*38e8c45fSAndroid Build Coastguard Worker const auto displayId = translate<int64_t>(display);
1725*38e8c45fSAndroid Build Coastguard Worker std::optional<int64_t> displayOpt;
1726*38e8c45fSAndroid Build Coastguard Worker if (displayId != kSingleReaderKey) {
1727*38e8c45fSAndroid Build Coastguard Worker displayOpt.emplace(displayId);
1728*38e8c45fSAndroid Build Coastguard Worker }
1729*38e8c45fSAndroid Build Coastguard Worker auto [it, added] = mReaders.try_emplace(display, std::move(displayOpt));
1730*38e8c45fSAndroid Build Coastguard Worker ALOGW_IF(!added, "Attempting to add writer for display %" PRId64 " which is already connected",
1731*38e8c45fSAndroid Build Coastguard Worker displayId);
1732*38e8c45fSAndroid Build Coastguard Worker }
1733*38e8c45fSAndroid Build Coastguard Worker
removeReader(Display display)1734*38e8c45fSAndroid Build Coastguard Worker void AidlComposer::removeReader(Display display) {
1735*38e8c45fSAndroid Build Coastguard Worker bool wasErased = mReaders.erase(display);
1736*38e8c45fSAndroid Build Coastguard Worker ALOGW_IF(!wasErased,
1737*38e8c45fSAndroid Build Coastguard Worker "Attempting to remove reader for display %" PRId64 " which is not connected",
1738*38e8c45fSAndroid Build Coastguard Worker translate<int64_t>(display));
1739*38e8c45fSAndroid Build Coastguard Worker }
1740*38e8c45fSAndroid Build Coastguard Worker
addDisplay(Display display)1741*38e8c45fSAndroid Build Coastguard Worker void AidlComposer::addDisplay(Display display) {
1742*38e8c45fSAndroid Build Coastguard Worker const auto displayId = translate<int64_t>(display);
1743*38e8c45fSAndroid Build Coastguard Worker mMutex.lock();
1744*38e8c45fSAndroid Build Coastguard Worker auto [it, added] = mWriters.try_emplace(display, displayId);
1745*38e8c45fSAndroid Build Coastguard Worker ALOGW_IF(!added, "Attempting to add writer for display %" PRId64 " which is already connected",
1746*38e8c45fSAndroid Build Coastguard Worker displayId);
1747*38e8c45fSAndroid Build Coastguard Worker if (mSingleReader) {
1748*38e8c45fSAndroid Build Coastguard Worker if (hasMultiThreadedPresentSupport(display)) {
1749*38e8c45fSAndroid Build Coastguard Worker mSingleReader = false;
1750*38e8c45fSAndroid Build Coastguard Worker removeReader(translate<Display>(kSingleReaderKey));
1751*38e8c45fSAndroid Build Coastguard Worker // Note that this includes the new display.
1752*38e8c45fSAndroid Build Coastguard Worker for (const auto& [existingDisplay, _] : mWriters) {
1753*38e8c45fSAndroid Build Coastguard Worker addReader(existingDisplay);
1754*38e8c45fSAndroid Build Coastguard Worker }
1755*38e8c45fSAndroid Build Coastguard Worker }
1756*38e8c45fSAndroid Build Coastguard Worker } else {
1757*38e8c45fSAndroid Build Coastguard Worker addReader(display);
1758*38e8c45fSAndroid Build Coastguard Worker }
1759*38e8c45fSAndroid Build Coastguard Worker mMutex.unlock();
1760*38e8c45fSAndroid Build Coastguard Worker }
1761*38e8c45fSAndroid Build Coastguard Worker
onHotplugConnect(Display display)1762*38e8c45fSAndroid Build Coastguard Worker void AidlComposer::onHotplugConnect(Display display) {
1763*38e8c45fSAndroid Build Coastguard Worker addDisplay(display);
1764*38e8c45fSAndroid Build Coastguard Worker }
1765*38e8c45fSAndroid Build Coastguard Worker } // namespace Hwc2
1766*38e8c45fSAndroid Build Coastguard Worker } // namespace android
1767