Package version up to 2.7.1
[platform/core/uifw/libtdm.git] / src / tdm_backend.c
1 /**************************************************************************
2  *
3  * libtdm
4  *
5  * Copyright 2015 Samsung Electronics co., Ltd. All Rights Reserved.
6  *
7  * Contact: Eunchul Kim <chulspro.kim@samsung.com>,
8  *          JinYoung Jeon <jy0.jeon@samsung.com>,
9  *          Taeheon Kim <th908.kim@samsung.com>,
10  *          YoungJun Cho <yj44.cho@samsung.com>,
11  *          SooChan Lim <sc1.lim@samsung.com>,
12  *          Boram Park <boram1288.park@samsung.com>
13  *
14  * Permission is hereby granted, free of charge, to any person obtaining a
15  * copy of this software and associated documentation files (the
16  * "Software"), to deal in the Software without restriction, including
17  * without limitation the rights to use, copy, modify, merge, publish,
18  * distribute, sub license, and/or sell copies of the Software, and to
19  * permit persons to whom the Software is furnished to do so, subject to
20  * the following conditions:
21  *
22  * The above copyright notice and this permission notice (including the
23  * next paragraph) shall be included in all copies or substantial portions
24  * of the Software.
25  *
26  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
27  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
28  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
29  * IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR
30  * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
31  * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
32  * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
33  *
34 **************************************************************************/
35
36 #ifdef HAVE_CONFIG_H
37 #include "config.h"
38 #endif
39
40 #include "tdm_private.h"
41
42 #define BACKEND_FUNC_ENTRY() \
43         tdm_private_display *private_display; \
44         TDM_RETURN_VAL_IF_FAIL(dpy != NULL, TDM_ERROR_INVALID_PARAMETER); \
45         private_display = (tdm_private_display*)dpy;
46
47 static int
48 _check_abi_version(tdm_backend_module *module, int abimaj, int abimin)
49 {
50         int major = TDM_BACKEND_GET_ABI_MAJOR(module->abi_version);
51         int minor = TDM_BACKEND_GET_ABI_MINOR(module->abi_version);
52
53         if (major < abimaj) goto failed;
54         if (major > abimaj) return 0;
55         if (minor < abimin) goto failed;
56         return 0;
57 failed:
58         TDM_ERR("The ABI version(%d.%d) of '%s' is less than %d.%d",
59                         major, minor, module->name ? module->name : "unknown",
60                         abimaj, abimin);
61         return -1;
62 }
63
64 EXTERN tdm_error
65 tdm_backend_register_func_display(tdm_display *dpy,
66                                                                   tdm_func_display *func_display)
67 {
68         tdm_backend_module *module;
69
70         TDM_RETURN_VAL_IF_FAIL(TDM_MUTEX_IS_LOCKED(), TDM_ERROR_OPERATION_FAILED);
71
72         BACKEND_FUNC_ENTRY();
73
74         TDM_RETURN_VAL_IF_FAIL(func_display != NULL, TDM_ERROR_INVALID_PARAMETER);
75
76         assert(private_display->current_module);
77
78         /* the ABI version of backend module should be more than 1.1 */
79         module = private_display->current_module->module_data;
80         if (_check_abi_version(module, 1, 1) < 0)
81                 return TDM_ERROR_BAD_MODULE;
82
83         private_display->current_module->func_display = *func_display;
84
85         return TDM_ERROR_NONE;
86 }
87
88 EXTERN tdm_error
89 tdm_backend_register_func_output(tdm_display *dpy, tdm_func_output *func_output)
90 {
91         tdm_backend_module *module;
92
93         TDM_RETURN_VAL_IF_FAIL(TDM_MUTEX_IS_LOCKED(), TDM_ERROR_OPERATION_FAILED);
94
95         BACKEND_FUNC_ENTRY();
96
97         TDM_RETURN_VAL_IF_FAIL(func_output != NULL, TDM_ERROR_INVALID_PARAMETER);
98
99         assert(private_display->current_module);
100
101         /* the ABI version of backend module should be more than 1.1 */
102         module = private_display->current_module->module_data;
103         if (_check_abi_version(module, 1, 1) < 0)
104                 return TDM_ERROR_BAD_MODULE;
105
106         private_display->current_module->func_output = *func_output;
107
108         return TDM_ERROR_NONE;
109 }
110
111 EXTERN tdm_error
112 tdm_backend_register_func_voutput(tdm_display *dpy, tdm_func_voutput *func_voutput)
113 {
114         tdm_backend_module *module;
115
116         TDM_RETURN_VAL_IF_FAIL(TDM_MUTEX_IS_LOCKED(), TDM_ERROR_OPERATION_FAILED);
117
118         BACKEND_FUNC_ENTRY();
119
120         TDM_RETURN_VAL_IF_FAIL(func_voutput != NULL, TDM_ERROR_INVALID_PARAMETER);
121
122         assert(private_display->current_module);
123
124         /* the ABI version of backend module should be more than 1.1 */
125         module = private_display->current_module->module_data;
126         if (_check_abi_version(module, 1, 1) < 0)
127                 return TDM_ERROR_BAD_MODULE;
128
129         private_display->current_module->func_voutput = *func_voutput;
130
131         return TDM_ERROR_NONE;
132 }
133
134
135 EXTERN tdm_error
136 tdm_backend_register_func_layer(tdm_display *dpy, tdm_func_layer *func_layer)
137 {
138         tdm_backend_module *module;
139
140         TDM_RETURN_VAL_IF_FAIL(TDM_MUTEX_IS_LOCKED(), TDM_ERROR_OPERATION_FAILED);
141
142         BACKEND_FUNC_ENTRY();
143
144         TDM_RETURN_VAL_IF_FAIL(func_layer != NULL, TDM_ERROR_INVALID_PARAMETER);
145
146         assert(private_display->current_module);
147
148         /* the ABI version of backend module should be more than 1.1 */
149         module = private_display->current_module->module_data;
150         if (_check_abi_version(module, 1, 1) < 0)
151                 return TDM_ERROR_BAD_MODULE;
152
153         private_display->current_module->func_layer = *func_layer;
154
155         return TDM_ERROR_NONE;
156 }
157
158 /* LCOV_EXCL_START */
159 EXTERN tdm_error
160 tdm_backend_register_func_hwc(tdm_display *dpy, tdm_func_hwc *func_hwc)
161 {
162         tdm_backend_module *module;
163
164         TDM_RETURN_VAL_IF_FAIL(TDM_MUTEX_IS_LOCKED(), TDM_ERROR_OPERATION_FAILED);
165
166         BACKEND_FUNC_ENTRY();
167
168         TDM_RETURN_VAL_IF_FAIL(func_hwc != NULL, TDM_ERROR_INVALID_PARAMETER);
169
170         assert(private_display->current_module);
171
172         module = private_display->current_module->module_data;
173         if (_check_abi_version(module, 2, 0) < 0)
174                 return TDM_ERROR_BAD_MODULE;
175
176         private_display->current_module->func_hwc = *func_hwc;
177
178         return TDM_ERROR_NONE;
179 }
180
181 EXTERN tdm_error
182 tdm_backend_register_func_hwc_window(tdm_display *dpy, tdm_func_hwc_window *func_hwc_window)
183 {
184         tdm_backend_module *module;
185
186         TDM_RETURN_VAL_IF_FAIL(TDM_MUTEX_IS_LOCKED(), TDM_ERROR_OPERATION_FAILED);
187
188         BACKEND_FUNC_ENTRY();
189
190         TDM_RETURN_VAL_IF_FAIL(func_hwc_window != NULL, TDM_ERROR_INVALID_PARAMETER);
191
192         assert(private_display->current_module);
193
194         module = private_display->current_module->module_data;
195         if (_check_abi_version(module, 2, 0) < 0)
196                 return TDM_ERROR_BAD_MODULE;
197
198         private_display->current_module->func_hwc_window = *func_hwc_window;
199
200         return TDM_ERROR_NONE;
201 }
202 /* LCOV_EXCL_STOP */
203
204 EXTERN tdm_error
205 tdm_backend_register_func_pp(tdm_display *dpy, tdm_func_pp *func_pp)
206 {
207         TDM_RETURN_VAL_IF_FAIL(TDM_MUTEX_IS_LOCKED(), TDM_ERROR_OPERATION_FAILED);
208
209         BACKEND_FUNC_ENTRY();
210
211         if (!func_pp)
212                 return TDM_ERROR_NONE;
213
214         assert(private_display->current_module);
215
216         private_display->current_module->capabilities |= TDM_DISPLAY_CAPABILITY_PP;
217         private_display->current_module->func_pp = *func_pp;
218
219         if (!private_display->pp_module)
220                 private_display->pp_module = private_display->current_module;
221         else
222                 TDM_ERR("already has pp backend(%s)", private_display->pp_module->module_data->name);
223
224         return TDM_ERROR_NONE;
225 }
226
227 EXTERN tdm_error
228 tdm_backend_register_func_capture(tdm_display *dpy,
229                                                                   tdm_func_capture *func_capture)
230 {
231         TDM_RETURN_VAL_IF_FAIL(TDM_MUTEX_IS_LOCKED(), TDM_ERROR_OPERATION_FAILED);
232
233         BACKEND_FUNC_ENTRY();
234
235         if (!func_capture)
236                 return TDM_ERROR_NONE;
237
238         assert(private_display->current_module);
239
240         private_display->current_module->capabilities |= TDM_DISPLAY_CAPABILITY_CAPTURE;
241         private_display->current_module->func_capture = *func_capture;
242
243         //TODO: remove later
244         if (!private_display->capture_module)
245                 private_display->capture_module = private_display->current_module;
246         else
247                 TDM_ERR("already has capture backend(%s)", private_display->capture_module->module_data->name);
248
249         return TDM_ERROR_NONE;
250 }