1 /**************************************************************************
5 Copyright 2017 Samsung Electronics co., Ltd. All Rights Reserved.
7 Contact: SooChan Lim <sc1.lim@samsung.com>
9 Permission is hereby granted, free of charge, to any person obtaining a
10 copy of this software and associated documentation files (the
11 "Software"), to deal in the Software without restriction, including
12 without limitation the rights to use, copy, modify, merge, publish,
13 distribute, sub license, and/or sell copies of the Software, and to
14 permit persons to whom the Software is furnished to do so, subject to
15 the following conditions:
17 The above copyright notice and this permission notice (including the
18 next paragraph) shall be included in all copies or substantial portions
21 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
22 OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
23 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
24 IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR
25 ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
26 TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
27 SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
29 **************************************************************************/
35 #include "tdm_backend_nexell.h"
38 nexell_hwc_window_acquire_buffer_queue(hal_tdm_hwc_window *hwc_window, hal_tdm_error *error)
40 tdm_nexell_hwc *hwc_data = NULL;
41 tdm_nexell_hwc_window_data *hwc_window_data = NULL;
42 tbm_surface_queue_h tqueue = NULL;
46 *error = HAL_TDM_ERROR_INVALID_PARAMETER;
48 hwc_window_data = (tdm_nexell_hwc_window_data *)hwc_window;
49 TDM_BACKEND_RETURN_VAL_IF_FAIL(hwc_window_data != NULL, NULL);
51 hwc_data = hwc_window_data->hwc_data;
52 TDM_BACKEND_RETURN_VAL_IF_FAIL(hwc_data != NULL, NULL);
55 *error = HAL_TDM_ERROR_NONE;
57 if ((hwc_window_data->lzpos_queue < 0) || (hwc_window_data->lzpos_queue >= NUM_LAYERS)) {
58 TDM_BACKEND_ERR("invliad hwc_window:%p lzpos_queue:%d", hwc_window_data, hwc_window_data->lzpos);
60 *error = HAL_TDM_ERROR_OPERATION_FAILED;
65 if (hwc_data->ui_buffer_queue[hwc_window_data->lzpos_queue].tqueue) {
66 tqueue = hwc_data->ui_buffer_queue[hwc_window_data->lzpos_queue].tqueue;
67 hwc_data->ui_buffer_queue[hwc_window_data->lzpos_queue].ref_cnt++;
69 tqueue = tdm_nexell_hwc_window_create_tbm_buffer_queue(hwc_window, error);
71 TDM_BACKEND_ERR("fail to create buffer queue");
75 hwc_data->ui_buffer_queue[hwc_window_data->lzpos_queue].tqueue = tqueue;
76 hwc_data->ui_buffer_queue[hwc_window_data->lzpos_queue].ref_cnt++;
79 // target buffer queue can't be reset
80 if (hwc_window_data->lzpos_queue != ZPOS_1) {
81 width = tbm_surface_queue_get_width(tqueue);
82 height = tbm_surface_queue_get_height(tqueue);
84 if ((hwc_window_data->info.src_config.pos.w != width) ||
85 (hwc_window_data->info.src_config.pos.h != height))
87 tbm_surface_queue_reset(tqueue,
88 hwc_window_data->info.src_config.pos.w,
89 hwc_window_data->info.src_config.pos.h,
90 hwc_window_data->info.src_config.format);
98 nexell_hwc_window_release_buffer_queue(hal_tdm_hwc_window *hwc_window, tbm_surface_queue_h queue)
100 tdm_nexell_hwc *hwc_data = NULL;
101 tdm_nexell_hwc_window_data *hwc_window_data = NULL;
104 hwc_window_data = (tdm_nexell_hwc_window_data *)hwc_window;
105 TDM_BACKEND_RETURN_IF_FAIL(hwc_window_data != NULL);
107 hwc_data = hwc_window_data->hwc_data;
108 TDM_BACKEND_RETURN_IF_FAIL(hwc_data != NULL);
110 for (i = 0; i < NUM_LAYERS; i++) {
111 if (hwc_data->ui_buffer_queue[i].tqueue == queue) {
112 if (hwc_data->ui_buffer_queue[i].ref_cnt > 0)
113 hwc_data->ui_buffer_queue[i].ref_cnt--;
115 if ((i != ZPOS_1) && (hwc_data->ui_buffer_queue[i].ref_cnt == 0)) {
116 tdm_nexell_hwc_window_destroy_tbm_buffer_queue(hwc_data->ui_buffer_queue[i].tqueue);
117 hwc_data->ui_buffer_queue[i].tqueue = NULL;
126 nexell_hwc_window_destroy(hal_tdm_hwc_window *hwc_window)
128 tdm_nexell_hwc_window_data *hwc_window_data = hwc_window;
130 TDM_BACKEND_RETURN_IF_FAIL(hwc_window_data != NULL);
132 LIST_DEL(&hwc_window_data->link);
134 free(hwc_window_data);
138 nexell_hwc_window_set_composition_type(hal_tdm_hwc_window *hwc_window,
139 hal_tdm_hwc_window_composition comp_type)
141 tdm_nexell_hwc_window_data *hwc_window_data = hwc_window;
142 tdm_nexell_hwc *hwc_data = hwc_window_data->hwc_data;
144 TDM_BACKEND_RETURN_VAL_IF_FAIL(hwc_window_data != NULL, HAL_TDM_ERROR_INVALID_PARAMETER);
145 TDM_BACKEND_RETURN_VAL_IF_FAIL(hwc_data != NULL, HAL_TDM_ERROR_INVALID_PARAMETER);
147 /* change the client_type when it is different from one which has before */
148 if (hwc_window_data->client_type == comp_type)
149 return HAL_TDM_ERROR_NONE;
151 hwc_window_data->client_type = comp_type;
153 return HAL_TDM_ERROR_NONE;
157 nexell_hwc_window_set_buffer_damage(hal_tdm_hwc_window *hwc_window, hal_tdm_region damage)
159 tdm_nexell_hwc_window_data *hwc_window_data = hwc_window;
161 TDM_BACKEND_RETURN_VAL_IF_FAIL(hwc_window_data != NULL, HAL_TDM_ERROR_INVALID_PARAMETER);
165 return HAL_TDM_ERROR_NONE;
169 nexell_hwc_window_set_info(hal_tdm_hwc_window *hwc_window, hal_tdm_hwc_window_info *info)
171 tdm_nexell_hwc_window_data *hwc_window_data = hwc_window;
172 tdm_nexell_hwc *hwc_data;
174 TDM_BACKEND_RETURN_VAL_IF_FAIL(hwc_window_data != NULL, HAL_TDM_ERROR_INVALID_PARAMETER);
175 hwc_data = hwc_window_data->hwc_data;
176 TDM_BACKEND_RETURN_VAL_IF_FAIL(hwc_data != NULL, HAL_TDM_ERROR_INVALID_PARAMETER);
177 TDM_BACKEND_RETURN_VAL_IF_FAIL(info != NULL, HAL_TDM_ERROR_INVALID_PARAMETER);
179 if (!memcmp(&hwc_window_data->info, info, sizeof(hal_tdm_hwc_window_info)))
180 return HAL_TDM_ERROR_NONE;
182 hwc_window_data->info = *info;
184 return HAL_TDM_ERROR_NONE;
188 nexell_hwc_window_set_buffer(hal_tdm_hwc_window *hwc_window, tbm_surface_h surface)
190 tdm_nexell_hwc_window_data *hwc_window_data = hwc_window;
191 hal_tdm_error err = HAL_TDM_ERROR_OPERATION_FAILED;
193 TDM_BACKEND_RETURN_VAL_IF_FAIL(hwc_window_data != NULL, err);
195 if (hwc_window_data->surface == surface)
196 return HAL_TDM_ERROR_NONE;
198 hwc_window_data->surface = surface;
200 return HAL_TDM_ERROR_NONE;
204 nexell_hwc_window_set_property(hal_tdm_hwc_window *hwc_window, unsigned int id, hal_tdm_value value)
206 tdm_nexell_hwc_window_data *hwc_window_data = hwc_window;
208 TDM_BACKEND_RETURN_VAL_IF_FAIL(hwc_window_data != NULL, HAL_TDM_ERROR_INVALID_PARAMETER);
212 return HAL_TDM_ERROR_NONE;
216 nexell_hwc_window_get_property(hal_tdm_hwc_window *hwc_window, unsigned int id, hal_tdm_value *value)
218 tdm_nexell_hwc_window_data *hwc_window_data = hwc_window;
220 TDM_BACKEND_RETURN_VAL_IF_FAIL(hwc_window_data != NULL, HAL_TDM_ERROR_INVALID_PARAMETER);
224 return HAL_TDM_ERROR_NONE;
228 nexell_hwc_window_get_constraints(hal_tdm_hwc_window *hwc_window, int *constraints)
230 tdm_nexell_hwc_window_data *hwc_window_data = hwc_window;
232 TDM_BACKEND_RETURN_VAL_IF_FAIL(hwc_window_data != NULL, HAL_TDM_ERROR_INVALID_PARAMETER);
233 TDM_BACKEND_RETURN_VAL_IF_FAIL(constraints != NULL, HAL_TDM_ERROR_INVALID_PARAMETER);
235 *constraints = hwc_window_data->constraints;
237 return HAL_TDM_ERROR_NONE;
241 nexell_hwc_window_set_name(hal_tdm_hwc_window *hwc_window, const char *name)
243 tdm_nexell_hwc_window_data *hwc_window_data = hwc_window;
245 TDM_BACKEND_RETURN_VAL_IF_FAIL(hwc_window_data != NULL, HAL_TDM_ERROR_INVALID_PARAMETER);
248 return HAL_TDM_ERROR_NONE;
250 snprintf(hwc_window_data->name, HAL_TDM_NAME_LEN, "%s", name);
252 return HAL_TDM_ERROR_NONE;
256 nexell_hwc_window_set_cursor_image(hal_tdm_hwc_window *hwc_window, int width, int height, int stride, void *ptr)
258 tdm_nexell_hwc_window_data *hwc_window_data = hwc_window;
260 TDM_BACKEND_RETURN_VAL_IF_FAIL(hwc_window_data != NULL, HAL_TDM_ERROR_INVALID_PARAMETER);
262 hwc_window_data->cursor_img.width = width;
263 hwc_window_data->cursor_img.height = height;
264 hwc_window_data->cursor_img.stride = stride;
265 hwc_window_data->cursor_img.ptr = ptr;
267 hwc_window_data->cursor_img_refresh = 1;
269 return HAL_TDM_ERROR_NONE;