display: add getter/setter for white balance
[platform/hal/api/device.git] / src / display.c
1 /*
2  * Copyright (c) 2021 Samsung Electronics Co., Ltd All Rights Reserved
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 #include <hal/hal-common.h>
18
19 #include "hal-display-interface.h"
20 #include "common.h"
21
22 static hal_backend_display_funcs *hal_display_funcs = NULL;
23 /*
24 -1 : failed to initialize
25 0  : not initialized
26 1  : succeeded to initialize
27 */
28 static int hal_initialized = 0;
29
30 int hal_device_display_get_backend(void)
31 {
32         int ret;
33
34         if (hal_display_funcs)
35                 return 0;
36
37         ret = hal_common_get_backend(HAL_MODULE_DEVICE_DISPLAY, (void **)&hal_display_funcs);
38         if (ret < 0) {
39                  _E("Failed to get display backend");
40                 hal_initialized = -1;
41                 return -EINVAL;
42         }
43
44         hal_initialized = 1;
45         return 0;
46 }
47
48 int hal_device_display_put_backend(void)
49 {
50         if (!hal_display_funcs)
51                 return 0;
52
53         hal_common_put_backend(HAL_MODULE_DEVICE_DISPLAY, (void *)hal_display_funcs);
54         hal_display_funcs = NULL;
55         hal_initialized = 0;
56
57         return 0;
58 }
59
60 int hal_device_display_get_max_brightness(int *brightness)
61 {
62         int ret;
63
64         if (!hal_display_funcs && !hal_initialized) {
65                 if ((ret = hal_device_display_get_backend()) < 0)
66                         return ret;
67         }
68
69         if (!hal_display_funcs ||
70             !hal_display_funcs->get_max_brightness)
71                 return -ENODEV;
72
73         return hal_display_funcs->get_max_brightness(brightness);
74 }
75
76 int hal_device_display_get_brightness(int *brightness)
77 {
78         int ret;
79
80         if (!hal_display_funcs && !hal_initialized) {
81                 if ((ret = hal_device_display_get_backend()) < 0)
82                         return ret;
83         }
84
85         if (!hal_display_funcs ||
86             !hal_display_funcs->get_brightness)
87                 return -ENODEV;
88
89         return hal_display_funcs->get_brightness(brightness);
90 }
91
92 int hal_device_display_set_brightness(int brightness)
93 {
94         int ret;
95
96         if (!hal_display_funcs && !hal_initialized) {
97                 if ((ret = hal_device_display_get_backend()) < 0)
98                         return ret;
99         }
100
101         if (!hal_display_funcs ||
102             !hal_display_funcs->set_brightness)
103                 return -ENODEV;
104
105         return hal_display_funcs->set_brightness(brightness);
106 }
107
108 int hal_device_display_set_multi_brightness(int brightness, int step, int delay)
109 {
110         int ret;
111
112         if (!hal_display_funcs && !hal_initialized) {
113                 if ((ret = hal_device_display_get_backend()) < 0)
114                         return ret;
115         }
116
117         if (!hal_display_funcs ||
118             !hal_display_funcs->set_multi_brightness)
119                 return -ENODEV;
120
121         return hal_display_funcs->set_multi_brightness(brightness, step, delay);
122 }
123
124 int hal_device_display_get_auto_brightness(float lmax, float lmin, float light, int *brightness)
125 {
126         int ret;
127
128         if (!hal_display_funcs && !hal_initialized) {
129                 if ((ret = hal_device_display_get_backend()) < 0)
130                         return ret;
131         }
132
133         if (!hal_display_funcs ||
134             !hal_display_funcs->get_auto_brightness)
135                 return -ENODEV;
136
137         return hal_display_funcs->get_auto_brightness(lmax, lmin, light, brightness);
138 }
139
140 int hal_device_display_get_state(enum display_state *state)
141 {
142         int ret;
143
144         if (!hal_display_funcs && !hal_initialized) {
145                 if ((ret = hal_device_display_get_backend()) < 0)
146                         return ret;
147         }
148
149         if (!hal_display_funcs ||
150             !hal_display_funcs->get_state)
151                 return -ENODEV;
152
153         return hal_display_funcs->get_state(state);
154 }
155
156 int hal_device_display_set_state(enum display_state state)
157 {
158         int ret;
159
160         if (!hal_display_funcs && !hal_initialized) {
161                 if ((ret = hal_device_display_get_backend()) < 0)
162                         return ret;
163         }
164
165         if (!hal_display_funcs ||
166             !hal_display_funcs->set_state)
167                 return -ENODEV;
168
169         return hal_display_funcs->set_state(state);
170 }
171
172 int hal_device_display_get_image_effect(enum display_image_effect *effect)
173 {
174         int ret;
175
176         if (!hal_display_funcs && !hal_initialized) {
177                 if ((ret = hal_device_display_get_backend()) < 0)
178                         return ret;
179         }
180
181         if (!hal_display_funcs ||
182             !hal_display_funcs->get_image_effect)
183                 return -ENODEV;
184
185         return hal_display_funcs->get_image_effect(effect);
186 }
187
188 int hal_device_display_set_image_effect(enum display_image_effect effect)
189 {
190         int ret;
191
192         if (!hal_display_funcs && !hal_initialized) {
193                 if ((ret = hal_device_display_get_backend()) < 0)
194                         return ret;
195         }
196
197         if (!hal_display_funcs ||
198             !hal_display_funcs->set_image_effect)
199                 return -ENODEV;
200
201         return hal_display_funcs->set_image_effect(effect);
202 }
203
204 int hal_device_display_get_panel_mode(enum display_panel_mode *mode)
205 {
206         int ret;
207
208         if (!hal_display_funcs && !hal_initialized) {
209                 if ((ret = hal_device_display_get_backend()) < 0)
210                         return ret;
211         }
212
213         if (!hal_display_funcs ||
214             !hal_display_funcs->get_panel_mode)
215                 return -ENODEV;
216
217         return hal_display_funcs->get_panel_mode(mode);
218 }
219
220 int hal_device_display_set_panel_mode(enum display_panel_mode mode)
221 {
222         int ret;
223
224         if (!hal_display_funcs && !hal_initialized) {
225                 if ((ret = hal_device_display_get_backend()) < 0)
226                         return ret;
227         }
228
229         if (!hal_display_funcs ||
230             !hal_display_funcs->set_panel_mode)
231                 return -ENODEV;
232
233         return hal_display_funcs->set_panel_mode(mode);
234 }
235
236 int hal_device_display_get_aod_mode(enum display_aod_mode *mode)
237 {
238         int ret;
239
240         if (!hal_display_funcs && !hal_initialized) {
241                 if ((ret = hal_device_display_get_backend()) < 0)
242                         return ret;
243         }
244
245         if (!hal_display_funcs ||
246             !hal_display_funcs->get_aod_mode)
247                 return -ENODEV;
248
249         return hal_display_funcs->get_aod_mode(mode);
250 }
251
252 int hal_device_display_get_aod_brightness(int *max, int *normal, int *min, int *charging)
253 {
254         int ret;
255
256         if (!hal_display_funcs && !hal_initialized) {
257                 if ((ret = hal_device_display_get_backend()) < 0)
258                         return ret;
259         }
260
261         if (!hal_display_funcs ||
262             !hal_display_funcs->get_aod_brightness)
263                 return -ENODEV;
264
265         return hal_display_funcs->get_aod_brightness(max, normal, min, charging);
266 }
267
268 int hal_device_display_get_max_frame_rate(int *rate)
269 {
270         int ret;
271
272         if (!hal_display_funcs && !hal_initialized) {
273                 if ((ret = hal_device_display_get_backend()) < 0)
274                         return ret;
275         }
276
277         if (!hal_display_funcs ||
278             !hal_display_funcs->get_max_frame_rate)
279                 return -ENODEV;
280
281         return hal_display_funcs->get_max_frame_rate(rate);
282 }
283
284 int hal_device_display_get_min_frame_rate(int *rate)
285 {
286         int ret;
287
288         if (!hal_display_funcs && !hal_initialized) {
289                 if ((ret = hal_device_display_get_backend()) < 0)
290                         return ret;
291         }
292
293         if (!hal_display_funcs ||
294             !hal_display_funcs->get_min_frame_rate)
295                 return -ENODEV;
296
297         return hal_display_funcs->get_min_frame_rate(rate);
298 }
299
300 int hal_device_display_get_frame_rate(int *rate)
301 {
302         int ret;
303
304         if (!hal_display_funcs && !hal_initialized) {
305                 if ((ret = hal_device_display_get_backend()) < 0)
306                         return ret;
307         }
308
309         if (!hal_display_funcs ||
310             !hal_display_funcs->get_frame_rate)
311                 return -ENODEV;
312
313         return hal_display_funcs->get_frame_rate(rate);
314 }
315
316 int hal_device_display_set_frame_rate(int rate)
317 {
318         int ret;
319
320         if (!hal_display_funcs && !hal_initialized) {
321                 if ((ret = hal_device_display_get_backend()) < 0)
322                         return ret;
323         }
324
325         if (!hal_display_funcs ||
326             !hal_display_funcs->set_frame_rate)
327                 return -ENODEV;
328
329         return hal_display_funcs->set_frame_rate(rate);
330 }
331
332 int hal_device_display_set_white_balance(enum hal_display_white_balance white_balance_type, int value)
333 {
334         int ret;
335
336         if (!hal_display_funcs && !hal_initialized) {
337                 if ((ret = hal_device_display_get_backend()) < 0)
338                         return ret;
339         }
340
341         if (!hal_display_funcs ||
342                 !hal_display_funcs->set_white_balance)
343                 return -ENODEV;
344
345         return hal_display_funcs->set_white_balance(white_balance_type, value);
346 }
347
348 int hal_device_display_get_white_balance(enum hal_display_white_balance white_balance_type, int* value)
349 {
350         int ret;
351
352         if (!hal_display_funcs && !hal_initialized) {
353                 if ((ret = hal_device_display_get_backend()) < 0)
354                         return ret;
355         }
356
357         if (!hal_display_funcs ||
358                 !hal_display_funcs->get_white_balance)
359                 return -ENODEV;
360
361         return hal_display_funcs->get_white_balance(white_balance_type, value);
362 }