blob: 59d466a699bacca76d47125342490c8cc971f38d [file] [log] [blame]
Dileep Marchya6860b2b2017-04-07 15:56:47 +05301/*
Ramakant Singhd58ec8f2018-08-31 17:38:43 +05302* Copyright (c) 2017-2018 The Linux Foundation. All rights reserved.
Dileep Marchya6860b2b2017-04-07 15:56:47 +05303*
4* Redistribution and use in source and binary forms, with or without
5* modification, are permitted provided that the following conditions are
6* met:
7* * Redistributions of source code must retain the above copyright
8* notice, this list of conditions and the following disclaimer.
9* * Redistributions in binary form must reproduce the above
10* copyright notice, this list of conditions and the following
11* disclaimer in the documentation and/or other materials provided
12* with the distribution.
13* * Neither the name of The Linux Foundation. nor the names of its
14* contributors may be used to endorse or promote products derived
15* from this software without specific prior written permission.
16*
17* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
18* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
19* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
20* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
21* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
24* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
25* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
26* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
27* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28*/
29
Ramakant Singhd58ec8f2018-08-31 17:38:43 +053030#ifdef DISPLAY_CONFIG_1_4
31#include <vendor/display/config/1.4/IDisplayConfig.h>
32#else
Dileep Marchya6860b2b2017-04-07 15:56:47 +053033#include <vendor/display/config/1.0/IDisplayConfig.h>
Ramakant Singhd58ec8f2018-08-31 17:38:43 +053034#endif
35
Dileep Marchya6860b2b2017-04-07 15:56:47 +053036
37#include "DisplayConfig.h"
38
39namespace display {
Ramakant Singhd58ec8f2018-08-31 17:38:43 +053040#ifdef DISPLAY_CONFIG_1_4
41using vendor::display::config::V1_4::IDisplayConfig;
42#else
Dileep Marchya6860b2b2017-04-07 15:56:47 +053043using vendor::display::config::V1_0::IDisplayConfig;
Ramakant Singhd58ec8f2018-08-31 17:38:43 +053044#endif
Dileep Marchya6860b2b2017-04-07 15:56:47 +053045
46//=============================================================================
47// The functions below run in the client process and wherever necessary
48// do a binder call to HWC to get/set data.
49
50IDisplayConfig::DisplayType MapDisplayType(int dpy) {
51 switch (dpy) {
52 case DISPLAY_PRIMARY:
53 return IDisplayConfig::DisplayType::DISPLAY_PRIMARY;
54
55 case DISPLAY_EXTERNAL:
56 return IDisplayConfig::DisplayType::DISPLAY_EXTERNAL;
57
58 case DISPLAY_VIRTUAL:
59 return IDisplayConfig::DisplayType::DISPLAY_VIRTUAL;
60
61 default:
62 break;
63 }
64
65 return IDisplayConfig::DisplayType::INVALID;
66}
67
68IDisplayConfig::DisplayExternalStatus MapExternalStatus(uint32_t status) {
69 switch (status) {
70 case EXTERNAL_OFFLINE:
71 return IDisplayConfig::DisplayExternalStatus::EXTERNAL_OFFLINE;
72
73 case EXTERNAL_ONLINE:
74 return IDisplayConfig::DisplayExternalStatus::EXTERNAL_ONLINE;
75
76 case EXTERNAL_PAUSE:
77 return IDisplayConfig::DisplayExternalStatus::EXTERNAL_PAUSE;
78
79 case EXTERNAL_RESUME:
80 return IDisplayConfig::DisplayExternalStatus::EXTERNAL_RESUME;
81
82 default:
83 break;
84 }
85
86 return IDisplayConfig::DisplayExternalStatus::INVALID;
87}
88
89IDisplayConfig::DisplayDynRefreshRateOp MapDynRefreshRateOp(uint32_t op) {
90 switch (op) {
91 case DISABLE_METADATA_DYN_REFRESH_RATE:
92 return IDisplayConfig::DisplayDynRefreshRateOp::DISABLE_METADATA_DYN_REFRESH_RATE;
93
94 case ENABLE_METADATA_DYN_REFRESH_RATE:
95 return IDisplayConfig::DisplayDynRefreshRateOp::ENABLE_METADATA_DYN_REFRESH_RATE;
96
97 case SET_BINDER_DYN_REFRESH_RATE:
98 return IDisplayConfig::DisplayDynRefreshRateOp::SET_BINDER_DYN_REFRESH_RATE;
99
100 default:
101 break;
102 }
103
104 return IDisplayConfig::DisplayDynRefreshRateOp::INVALID;
105}
106
107int MapDisplayPortType(IDisplayConfig::DisplayPortType panelType) {
108 switch (panelType) {
109 case IDisplayConfig::DisplayPortType::DISPLAY_PORT_DEFAULT:
110 return DISPLAY_PORT_DEFAULT;
111
112 case IDisplayConfig::DisplayPortType::DISPLAY_PORT_DSI:
113 return DISPLAY_PORT_DSI;
114
115 case IDisplayConfig::DisplayPortType::DISPLAY_PORT_DTV:
116 return DISPLAY_PORT_DTV;
117
118 case IDisplayConfig::DisplayPortType::DISPLAY_PORT_WRITEBACK:
119 return DISPLAY_PORT_WRITEBACK;
120
121 case IDisplayConfig::DisplayPortType::DISPLAY_PORT_LVDS:
122 return DISPLAY_PORT_LVDS;
123
124 case IDisplayConfig::DisplayPortType::DISPLAY_PORT_EDP:
125 return DISPLAY_PORT_EDP;
126
127 case IDisplayConfig::DisplayPortType::DISPLAY_PORT_DP:
128 return DISPLAY_PORT_DP;
129
130 default:
131 break;
132 }
133
134 return -1;
135}
136
137int isExternalConnected() {
138 android::sp<IDisplayConfig> intf = IDisplayConfig::getService();
139 if (intf == NULL) {
140 return 0;
141 }
142
143 int connected = 0;
144 intf->isDisplayConnected(IDisplayConfig::DisplayType::DISPLAY_EXTERNAL,
145 [&](const auto &tmpError, const auto &tmpStatus) {
146 if (tmpError) {
147 return;
148 }
149
150 connected = tmpStatus;
151 });
152
153 return connected;
154}
155
156int setSecondayDisplayStatus(int dpy, uint32_t status) {
157 android::sp<IDisplayConfig> intf = IDisplayConfig::getService();
158 if (intf == NULL) {
159 return -1;
160 }
161
162 return intf->setSecondayDisplayStatus(MapDisplayType(dpy), MapExternalStatus(status));
163}
164
165int configureDynRefeshRate(uint32_t op, uint32_t refreshRate) {
166 android::sp<IDisplayConfig> intf = IDisplayConfig::getService();
167 if (intf == NULL) {
168 return -1;
169 }
170
171 return intf->configureDynRefeshRate(MapDynRefreshRateOp(op), refreshRate);
172}
173
174int getConfigCount(int dpy) {
175 android::sp<IDisplayConfig> intf = IDisplayConfig::getService();
176 if (intf == NULL) {
177 return -1;
178 }
179
180 int count = 0;
Uday Kiran Pichika2b396bc2017-07-06 17:24:54 +0530181 intf->getConfigCount(MapDisplayType(dpy),
Dileep Marchya6860b2b2017-04-07 15:56:47 +0530182 [&](const auto &tmpError, const auto &tmpCount) {
183 if (tmpError) {
184 return;
185 }
186
187 count = tmpCount;
188 });
189
190 return count;
191}
192
193int getActiveConfig(int dpy) {
194 android::sp<IDisplayConfig> intf = IDisplayConfig::getService();
195 if (intf == NULL) {
196 return -1;
197 }
198
199 int config = 0;
200 intf->getActiveConfig(MapDisplayType(dpy),
201 [&](const auto &tmpError, const auto &tmpConfig) {
202 if (tmpError) {
203 return;
204 }
205
206 config = tmpConfig;
207 });
208
209 return config;
210}
211
212int setActiveConfig(int dpy, uint32_t config) {
213 android::sp<IDisplayConfig> intf = IDisplayConfig::getService();
214 if (intf == NULL) {
215 return -1;
216 }
217
218 return intf->setActiveConfig(MapDisplayType(dpy), config);
219}
220
221DisplayAttributes getDisplayAttributes(uint32_t configIndex, int dpy) {
222 DisplayAttributes attributes;
223
224 android::sp<IDisplayConfig> intf = IDisplayConfig::getService();
225 if (intf == NULL) {
226 return attributes;
227 }
228
229 intf->getDisplayAttributes(configIndex, MapDisplayType(dpy),
230 [&](const auto &tmpError, const auto &tmpAttributes) {
231 if (tmpError) {
232 return;
233 }
234
235 attributes.vsync_period = tmpAttributes.vsyncPeriod;
236 attributes.xres = tmpAttributes.xRes;
237 attributes.yres = tmpAttributes.yRes;
238 attributes.xdpi = tmpAttributes.xDpi;
239 attributes.ydpi = tmpAttributes.yDpi;
240 attributes.panel_type = MapDisplayPortType(tmpAttributes.panelType);
241 attributes.is_yuv = tmpAttributes.isYuv;
242 });
243
244 return attributes;
245}
246
247int setPanelBrightness(uint32_t level) {
248 android::sp<IDisplayConfig> intf = IDisplayConfig::getService();
249 if (intf == NULL) {
250 return -1;
251 }
252
253 return intf->setPanelBrightness(level);
254}
255
256uint32_t getPanelBrightness() {
257 android::sp<IDisplayConfig> intf = IDisplayConfig::getService();
258 if (intf == NULL) {
259 return 0;
260 }
261
262 int level = 0;
263 intf->getPanelBrightness(
264 [&](const auto &tmpError, const auto &tmpLevel) {
265 if (tmpError) {
266 return;
267 }
268
269 level = tmpLevel;
270 });
271
272 return level;
273}
274
275int minHdcpEncryptionLevelChanged(int dpy, uint32_t min_enc_level) {
276 android::sp<IDisplayConfig> intf = IDisplayConfig::getService();
277 if (intf == NULL) {
278 return -1;
279 }
280
281 return intf->minHdcpEncryptionLevelChanged(MapDisplayType(dpy), min_enc_level);
282}
283
284int refreshScreen() {
285 android::sp<IDisplayConfig> intf = IDisplayConfig::getService();
286 if (intf == NULL) {
287 return -1;
288 }
289
290 return intf->refreshScreen();
291}
292
293int controlPartialUpdate(int dpy, bool enable) {
294 android::sp<IDisplayConfig> intf = IDisplayConfig::getService();
295 if (intf == NULL) {
296 return -1;
297 }
298
299 return intf->controlPartialUpdate(MapDisplayType(dpy), enable);
300}
301
302int toggleScreenUpdate(uint32_t on) {
303 android::sp<IDisplayConfig> intf = IDisplayConfig::getService();
304 if (intf == NULL) {
305 return -1;
306 }
307
308 return intf->toggleScreenUpdate(on == 1);
309}
310
311int setIdleTimeout(uint32_t value) {
312 android::sp<IDisplayConfig> intf = IDisplayConfig::getService();
313 if (intf == NULL) {
314 return -1;
315 }
316
317 return intf->setIdleTimeout(value);
318}
319
320int getHDRCapabilities(int dpy, DisplayHDRCapabilities *caps) {
321 android::sp<IDisplayConfig> intf = IDisplayConfig::getService();
322 if (intf == NULL || caps == NULL) {
323 return -1;
324 }
325
326 int error = -1;
327 intf->getHDRCapabilities(MapDisplayType(dpy),
328 [&](const auto &tmpError, const auto &tmpCaps) {
329 error = tmpError;
330 if (error) {
331 return;
332 }
333
334 caps->supported_hdr_types = tmpCaps.supportedHdrTypes;
335 caps->max_luminance = tmpCaps.maxLuminance;
336 caps->max_avg_luminance = tmpCaps.maxAvgLuminance;
337 caps->min_luminance = tmpCaps.minLuminance;
338 });
339
340 return error;
341}
342
Ramakant Singhd58ec8f2018-08-31 17:38:43 +0530343#ifdef DISPLAY_CONFIG_1_4
344int32_t getWriteBackCapabilities( WriteBackCapabilities *caps) {
345 android::sp<IDisplayConfig> intf = IDisplayConfig::getService();
346 if (intf == NULL || caps == NULL) {
347 return -1;
348 }
349
350 int error = -1;
351 intf->getWriteBackCapabilities(
352 [&](const auto &tmpError, const auto &tmpCaps) {
353 error = tmpError;
354 if (error) {
355 return;
356 }
357 caps->isWbUbwcSupported = tmpCaps.isWbUbwcSupported;
358 });
359
360 return error;
361}
362#endif
363
Dileep Marchya6860b2b2017-04-07 15:56:47 +0530364int setCameraLaunchStatus(uint32_t on) {
365 android::sp<IDisplayConfig> intf = IDisplayConfig::getService();
366 if (intf == NULL) {
367 return -1;
368 }
369
370 return intf->setCameraLaunchStatus(on);
371}
372
373bool displayBWTransactionPending() {
374 android::sp<IDisplayConfig> intf = IDisplayConfig::getService();
375 if (intf == NULL) {
376 return 0;
377 }
378
379 int status = 0;
380 intf->displayBWTransactionPending(
381 [&](const auto &tmpError, const auto &tmpStatus) {
382 if (tmpError) {
383 return;
384 }
385
386 status = tmpStatus;
387 });
388
389 return status;
390}
391
392} // namespace display