1 /**************************************************************************
5 * Copyright 2015 Samsung Electronics co., Ltd. All Rights Reserved.
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>
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:
22 * The above copyright notice and this permission notice (including the
23 * next paragraph) shall be included in all copies or substantial portions
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.
34 **************************************************************************/
40 #include "tdm_private.h"
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;
47 #define BACKEND_FUNC_ENTRY_VOID() \
48 tdm_private_display *private_display; \
49 TDM_RETURN_IF_FAIL(dpy != NULL); \
50 private_display = (tdm_private_display*)dpy;
53 _check_abi_version(tdm_backend_module *module, int abimaj, int abimin)
55 int major = TDM_BACKEND_GET_ABI_MAJOR(module->abi_version);
56 int minor = TDM_BACKEND_GET_ABI_MINOR(module->abi_version);
58 if (major < abimaj) goto failed;
59 if (major > abimaj) return 0;
60 if (minor < abimin) goto failed;
63 TDM_ERR("The ABI version(%d.%d) of '%s' is less than %d.%d",
64 major, minor, module->name ? module->name : "unknown",
70 tdm_backend_register_func_display(tdm_display *dpy,
71 tdm_func_display *func_display)
73 tdm_backend_module *module;
75 TDM_RETURN_VAL_IF_FAIL(TDM_MUTEX_IS_LOCKED(), TDM_ERROR_OPERATION_FAILED);
79 TDM_RETURN_VAL_IF_FAIL(func_display != NULL, TDM_ERROR_INVALID_PARAMETER);
81 assert(private_display->current_module);
83 /* the ABI version of backend module should be more than 1.1 */
84 module = private_display->current_module->module_data;
85 if (_check_abi_version(module, 1, 1) < 0)
86 return TDM_ERROR_BAD_MODULE;
88 private_display->current_module->func_display = *func_display;
90 return TDM_ERROR_NONE;
94 tdm_backend_register_func_output(tdm_display *dpy, tdm_func_output *func_output)
96 tdm_backend_module *module;
98 TDM_RETURN_VAL_IF_FAIL(TDM_MUTEX_IS_LOCKED(), TDM_ERROR_OPERATION_FAILED);
100 BACKEND_FUNC_ENTRY();
102 TDM_RETURN_VAL_IF_FAIL(func_output != NULL, TDM_ERROR_INVALID_PARAMETER);
104 assert(private_display->current_module);
106 /* the ABI version of backend module should be more than 1.1 */
107 module = private_display->current_module->module_data;
108 if (_check_abi_version(module, 1, 1) < 0)
109 return TDM_ERROR_BAD_MODULE;
111 private_display->current_module->func_output = *func_output;
113 return TDM_ERROR_NONE;
117 tdm_backend_register_func_layer(tdm_display *dpy, tdm_func_layer *func_layer)
119 tdm_backend_module *module;
121 TDM_RETURN_VAL_IF_FAIL(TDM_MUTEX_IS_LOCKED(), TDM_ERROR_OPERATION_FAILED);
123 BACKEND_FUNC_ENTRY();
125 TDM_RETURN_VAL_IF_FAIL(func_layer != NULL, TDM_ERROR_INVALID_PARAMETER);
127 assert(private_display->current_module);
129 /* the ABI version of backend module should be more than 1.1 */
130 module = private_display->current_module->module_data;
131 if (_check_abi_version(module, 1, 1) < 0)
132 return TDM_ERROR_BAD_MODULE;
134 private_display->current_module->func_layer = *func_layer;
136 return TDM_ERROR_NONE;
139 /* LCOV_EXCL_START */
141 tdm_backend_register_func_hwc(tdm_display *dpy, tdm_func_hwc *func_hwc)
143 tdm_backend_module *module;
145 TDM_RETURN_VAL_IF_FAIL(TDM_MUTEX_IS_LOCKED(), TDM_ERROR_OPERATION_FAILED);
147 BACKEND_FUNC_ENTRY();
149 TDM_RETURN_VAL_IF_FAIL(func_hwc != NULL, TDM_ERROR_INVALID_PARAMETER);
151 assert(private_display->current_module);
153 module = private_display->current_module->module_data;
154 if (_check_abi_version(module, 2, 0) < 0)
155 return TDM_ERROR_BAD_MODULE;
157 private_display->current_module->func_hwc = *func_hwc;
159 return TDM_ERROR_NONE;
163 tdm_backend_register_func_hwc_window(tdm_display *dpy, tdm_func_hwc_window *func_hwc_window)
165 tdm_backend_module *module;
167 TDM_RETURN_VAL_IF_FAIL(TDM_MUTEX_IS_LOCKED(), TDM_ERROR_OPERATION_FAILED);
169 BACKEND_FUNC_ENTRY();
171 TDM_RETURN_VAL_IF_FAIL(func_hwc_window != NULL, TDM_ERROR_INVALID_PARAMETER);
173 assert(private_display->current_module);
175 module = private_display->current_module->module_data;
176 if (_check_abi_version(module, 2, 0) < 0)
177 return TDM_ERROR_BAD_MODULE;
179 private_display->current_module->func_hwc_window = *func_hwc_window;
181 return TDM_ERROR_NONE;
186 tdm_backend_register_func_pp(tdm_display *dpy, tdm_func_pp *func_pp)
188 TDM_RETURN_VAL_IF_FAIL(TDM_MUTEX_IS_LOCKED(), TDM_ERROR_OPERATION_FAILED);
190 BACKEND_FUNC_ENTRY();
193 return TDM_ERROR_NONE;
195 assert(private_display->current_module);
197 private_display->current_module->capabilities |= TDM_DISPLAY_CAPABILITY_PP;
198 private_display->current_module->func_pp = *func_pp;
200 if (!private_display->pp_module)
201 private_display->pp_module = private_display->current_module;
203 TDM_ERR("already has pp backend(%s)", private_display->pp_module->module_data->name);
205 return TDM_ERROR_NONE;
209 tdm_backend_register_func_capture(tdm_display *dpy,
210 tdm_func_capture *func_capture)
212 TDM_RETURN_VAL_IF_FAIL(TDM_MUTEX_IS_LOCKED(), TDM_ERROR_OPERATION_FAILED);
214 BACKEND_FUNC_ENTRY();
217 return TDM_ERROR_NONE;
219 assert(private_display->current_module);
221 private_display->current_module->capabilities |= TDM_DISPLAY_CAPABILITY_CAPTURE;
222 private_display->current_module->func_capture = *func_capture;
225 if (!private_display->capture_module)
226 private_display->capture_module = private_display->current_module;
228 TDM_ERR("already has capture backend(%s)", private_display->capture_module->module_data->name);
230 return TDM_ERROR_NONE;
234 tdm_backend_register_output(tdm_display *dpy, tdm_output *output)
238 BACKEND_FUNC_ENTRY();
240 TDM_RETURN_VAL_IF_FAIL(TDM_MUTEX_IS_LOCKED(), TDM_ERROR_OPERATION_FAILED);
241 TDM_RETURN_VAL_IF_FAIL(output != NULL, TDM_ERROR_INVALID_PARAMETER);
243 /* this function is only for backend. if backend calls this function, it means
244 * that it's triggered by frontend. frontend should set current_module before calling
247 TDM_RETURN_VAL_IF_FAIL(private_display->current_module != NULL, TDM_ERROR_OPERATION_FAILED);
249 ret = tdm_display_update_output(private_display->current_module, output);
250 TDM_RETURN_VAL_IF_FAIL(ret == TDM_ERROR_NONE, ret);
252 return TDM_ERROR_NONE;
256 tdm_backend_unregister_output(tdm_display *dpy, tdm_output *output)
258 tdm_private_output *private_output;
260 BACKEND_FUNC_ENTRY_VOID();
262 TDM_RETURN_IF_FAIL(TDM_MUTEX_IS_LOCKED());
263 TDM_RETURN_IF_FAIL(output != NULL);
265 /* this function is only for backend. if backend calls this function, it means
266 * that it's triggered by frontend. frontend should set current_module before calling
269 TDM_RETURN_IF_FAIL(private_display->current_module != NULL);
271 private_output = tdm_display_find_private_output(private_display, output);
272 tdm_display_destroy_private_output(private_output);