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 <sc1.lim@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;
48 _check_abi_version(tdm_backend_module *module, int abimaj, int abimin)
50 int major = TDM_BACKEND_GET_ABI_MAJOR(module->abi_version);
51 int minor = TDM_BACKEND_GET_ABI_MINOR(module->abi_version);
53 if (major < abimaj) goto failed;
54 if (major > abimaj) return 0;
55 if (minor < abimin) goto failed;
58 TDM_ERR("The ABI version(%d.%d) of '%s' is less than %d.%d",
59 major, minor, module->name ? module->name : "unknown",
65 tdm_backend_register_func_display(tdm_display *dpy,
66 tdm_func_display *func_display)
68 tdm_backend_module *module;
70 TDM_RETURN_VAL_IF_FAIL(TDM_MUTEX_IS_LOCKED(), TDM_ERROR_OPERATION_FAILED);
74 TDM_RETURN_VAL_IF_FAIL(func_display != NULL, TDM_ERROR_INVALID_PARAMETER);
76 assert(private_display->current_module);
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;
83 private_display->current_module->func_display = *func_display;
85 return TDM_ERROR_NONE;
89 tdm_backend_register_func_output(tdm_display *dpy, tdm_func_output *func_output)
91 tdm_backend_module *module;
93 TDM_RETURN_VAL_IF_FAIL(TDM_MUTEX_IS_LOCKED(), TDM_ERROR_OPERATION_FAILED);
97 TDM_RETURN_VAL_IF_FAIL(func_output != NULL, TDM_ERROR_INVALID_PARAMETER);
99 assert(private_display->current_module);
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;
106 private_display->current_module->func_output = *func_output;
108 return TDM_ERROR_NONE;
112 tdm_backend_register_func_layer(tdm_display *dpy, tdm_func_layer *func_layer)
114 tdm_backend_module *module;
116 TDM_RETURN_VAL_IF_FAIL(TDM_MUTEX_IS_LOCKED(), TDM_ERROR_OPERATION_FAILED);
118 BACKEND_FUNC_ENTRY();
120 TDM_RETURN_VAL_IF_FAIL(func_layer != NULL, TDM_ERROR_INVALID_PARAMETER);
122 assert(private_display->current_module);
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;
129 private_display->current_module->func_layer = *func_layer;
131 return TDM_ERROR_NONE;
135 tdm_backend_register_func_hwc_window(tdm_display *dpy, tdm_func_hwc_window *func_hwc_window)
137 tdm_backend_module *module;
139 TDM_RETURN_VAL_IF_FAIL(TDM_MUTEX_IS_LOCKED(), TDM_ERROR_OPERATION_FAILED);
141 BACKEND_FUNC_ENTRY();
143 TDM_RETURN_VAL_IF_FAIL(func_hwc_window != NULL, TDM_ERROR_INVALID_PARAMETER);
145 assert(private_display->current_module);
147 module = private_display->current_module->module_data;
149 Temporarily, we set the version of hwc window to 1.1 for the development.
150 Originally the hwc window version is 2.0. */
151 if (_check_abi_version(module, 1, 1) < 0)
152 return TDM_ERROR_BAD_MODULE;
154 private_display->current_module->func_hwc_window = *func_hwc_window;
156 return TDM_ERROR_NONE;
160 tdm_backend_register_func_pp(tdm_display *dpy, tdm_func_pp *func_pp)
162 TDM_RETURN_VAL_IF_FAIL(TDM_MUTEX_IS_LOCKED(), TDM_ERROR_OPERATION_FAILED);
164 BACKEND_FUNC_ENTRY();
167 return TDM_ERROR_NONE;
169 assert(private_display->current_module);
171 private_display->current_module->capabilities |= TDM_DISPLAY_CAPABILITY_PP;
172 private_display->current_module->func_pp = *func_pp;
174 if (!private_display->pp_module)
175 private_display->pp_module = private_display->current_module;
177 TDM_ERR("already has pp backend(%s)", private_display->pp_module->module_data->name);
179 return TDM_ERROR_NONE;
183 tdm_backend_register_func_capture(tdm_display *dpy,
184 tdm_func_capture *func_capture)
186 TDM_RETURN_VAL_IF_FAIL(TDM_MUTEX_IS_LOCKED(), TDM_ERROR_OPERATION_FAILED);
188 BACKEND_FUNC_ENTRY();
191 return TDM_ERROR_NONE;
193 assert(private_display->current_module);
195 private_display->current_module->capabilities |= TDM_DISPLAY_CAPABILITY_CAPTURE;
196 private_display->current_module->func_capture = *func_capture;
199 if (!private_display->capture_module)
200 private_display->capture_module = private_display->current_module;
202 TDM_ERR("already has capture backend(%s)", private_display->capture_module->module_data->name);
204 return TDM_ERROR_NONE;
207 /* backend operates itself types */
208 static tdm_private_output*
209 _look_for_frontend_hwc_output(tdm_output *backend_output)
211 tdm_private_output *frontend_output = NULL, *o = NULL;
212 tdm_private_display *private_display = tdm_display_get();
213 tdm_private_module *private_module = NULL;
215 LIST_FOR_EACH_ENTRY(private_module, &private_display->module_list, link) {
216 LIST_FOR_EACH_ENTRY(o, &private_module->output_list, link) {
217 if (!(o->caps.capabilities & TDM_OUTPUT_CAPABILITY_HWC))
220 if (o->output_backend == backend_output) {
222 return frontend_output;
231 tdm_backend_trigger_need_validate_event(tdm_output *output)
233 tdm_private_output *private_output;
237 private_output = _look_for_frontend_hwc_output(output);
238 TDM_RETURN_VAL_IF_FAIL(private_output != NULL, TDM_ERROR_INVALID_PARAMETER);
242 /* do not lock the global display lock here */
244 res = write(private_output->need_validate.event_fd, &value, sizeof(value));
246 return TDM_ERROR_OPERATION_FAILED;
248 return TDM_ERROR_NONE;