Package version up to 3.0.6
[platform/adaptation/nexell/libtdm-nexell.git] / src / libtdm-nexell / tdm_nexell_hwc_window.c
1 /**************************************************************************
2
3 libtdm_nexell
4
5 Copyright 2017 Samsung Electronics co., Ltd. All Rights Reserved.
6
7 Contact: SooChan Lim <sc1.lim@samsung.com>
8
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:
16
17 The above copyright notice and this permission notice (including the
18 next paragraph) shall be included in all copies or substantial portions
19 of the Software.
20
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.
28
29 **************************************************************************/
30
31 #ifdef HAVE_CONFIG_H
32 #include "config.h"
33 #endif
34
35 #include "tdm_nexell.h"
36
37 tbm_surface_queue_h
38 nexell_hwc_window_acquire_buffer_queue(tdm_hwc_window *hwc_window, tdm_error *error)
39 {
40         tdm_nexell_hwc_data *hwc_data = NULL;
41         tdm_nexell_hwc_window_data *hwc_window_data = NULL;
42         tbm_surface_queue_h tqueue = NULL;
43         int width, height;
44
45         if (error)
46                 *error = TDM_ERROR_INVALID_PARAMETER;
47
48         hwc_window_data = (tdm_nexell_hwc_window_data *)hwc_window;
49         RETURN_VAL_IF_FAIL(hwc_window_data != NULL, NULL);
50
51         hwc_data = hwc_window_data->hwc_data;
52         RETURN_VAL_IF_FAIL(hwc_data != NULL, NULL);
53
54         if (error)
55                 *error = TDM_ERROR_NONE;
56
57         if ((hwc_window_data->lzpos_queue < 0) || (hwc_window_data->lzpos_queue >= NUM_LAYERS)) {
58                 TDM_ERR("invliad hwc_window:%p lzpos_queue:%d", hwc_window_data, hwc_window_data->lzpos);
59                 if (error)
60                         *error = TDM_ERROR_OPERATION_FAILED;
61
62                 return NULL;
63         }
64
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++;
68         } else {
69                 tqueue = tdm_nexell_hwc_window_create_tbm_buffer_queue(hwc_window, error);
70                 if (!tqueue) {
71                         TDM_ERR("fail to create buffer queue");
72                         return NULL;
73                 }
74
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++;
77         }
78
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);
83
84                 if ((hwc_window_data->info.src_config.pos.w != width) ||
85                         (hwc_window_data->info.src_config.pos.h != height))
86                         {
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);
91                         }
92         }
93
94         return tqueue;
95 }
96
97 void
98 nexell_hwc_window_release_buffer_queue(tdm_hwc_window *hwc_window, tbm_surface_queue_h queue)
99 {
100         tdm_nexell_hwc_data *hwc_data = NULL;
101         tdm_nexell_hwc_window_data *hwc_window_data = NULL;
102         int i;
103
104         hwc_window_data = (tdm_nexell_hwc_window_data *)hwc_window;
105         RETURN_IF_FAIL(hwc_window_data != NULL);
106
107         hwc_data = hwc_window_data->hwc_data;
108         RETURN_IF_FAIL(hwc_data != NULL);
109
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--;
114
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;
118                         }
119
120                         break;
121                 }
122         }
123 }
124
125 void
126 nexell_hwc_window_destroy(tdm_hwc_window *hwc_window)
127 {
128         tdm_nexell_hwc_window_data *hwc_window_data = hwc_window;
129
130         RETURN_IF_FAIL(hwc_window_data != NULL);
131
132         LIST_DEL(&hwc_window_data->link);
133
134         free(hwc_window_data);
135 }
136
137 tdm_error
138 nexell_hwc_window_set_composition_type(tdm_hwc_window *hwc_window,
139                                                                         tdm_hwc_window_composition comp_type)
140 {
141         tdm_nexell_hwc_window_data *hwc_window_data = hwc_window;
142         tdm_nexell_hwc_data *hwc_data = hwc_window_data->hwc_data;
143
144         RETURN_VAL_IF_FAIL(hwc_window_data != NULL, TDM_ERROR_INVALID_PARAMETER);
145         RETURN_VAL_IF_FAIL(hwc_data != NULL, TDM_ERROR_INVALID_PARAMETER);
146
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 TDM_ERROR_NONE;
150
151         hwc_window_data->client_type = comp_type;
152
153         return TDM_ERROR_NONE;
154 }
155
156 tdm_error
157 nexell_hwc_window_set_buffer_damage(tdm_hwc_window *hwc_window, tdm_region damage)
158 {
159         tdm_nexell_hwc_window_data *hwc_window_data = hwc_window;
160
161         RETURN_VAL_IF_FAIL(hwc_window_data != NULL, TDM_ERROR_INVALID_PARAMETER);
162
163         //TODO::
164
165         return TDM_ERROR_NONE;
166 }
167
168 tdm_error
169 nexell_hwc_window_set_info(tdm_hwc_window *hwc_window, tdm_hwc_window_info *info)
170 {
171         tdm_nexell_hwc_window_data *hwc_window_data = hwc_window;
172         tdm_nexell_hwc_data *hwc_data;
173
174         RETURN_VAL_IF_FAIL(hwc_window_data != NULL, TDM_ERROR_INVALID_PARAMETER);
175         hwc_data = hwc_window_data->hwc_data;
176         RETURN_VAL_IF_FAIL(hwc_data != NULL, TDM_ERROR_INVALID_PARAMETER);
177         RETURN_VAL_IF_FAIL(info != NULL, TDM_ERROR_INVALID_PARAMETER);
178
179         if (!memcmp(&hwc_window_data->info, info, sizeof(tdm_hwc_window_info)))
180                 return TDM_ERROR_NONE;
181
182         hwc_window_data->info = *info;
183
184         return TDM_ERROR_NONE;
185 }
186
187 tdm_error
188 nexell_hwc_window_set_buffer(tdm_hwc_window *hwc_window, tbm_surface_h surface)
189 {
190         tdm_nexell_hwc_window_data *hwc_window_data = hwc_window;
191         tdm_error err = TDM_ERROR_OPERATION_FAILED;
192
193         RETURN_VAL_IF_FAIL(hwc_window_data != NULL, err);
194
195         if (hwc_window_data->surface == surface)
196                 return TDM_ERROR_NONE;
197
198         hwc_window_data->surface = surface;
199
200         return TDM_ERROR_NONE;
201 }
202
203 tdm_error
204 nexell_hwc_window_set_property(tdm_hwc_window *hwc_window, unsigned int id, tdm_value value)
205 {
206         tdm_nexell_hwc_window_data *hwc_window_data = hwc_window;
207
208         RETURN_VAL_IF_FAIL(hwc_window_data != NULL, TDM_ERROR_INVALID_PARAMETER);
209
210         //TODO:
211
212         return TDM_ERROR_NONE;
213 }
214
215 tdm_error
216 nexell_hwc_window_get_property(tdm_hwc_window *hwc_window, unsigned int id, tdm_value *value)
217 {
218         tdm_nexell_hwc_window_data *hwc_window_data = hwc_window;
219
220         RETURN_VAL_IF_FAIL(hwc_window_data != NULL, TDM_ERROR_INVALID_PARAMETER);
221
222         //TODO:
223
224         return TDM_ERROR_NONE;
225 }
226
227 tdm_error
228 nexell_hwc_window_get_constraints(tdm_hwc_window *hwc_window, int *constraints)
229 {
230         tdm_nexell_hwc_window_data *hwc_window_data = hwc_window;
231
232         RETURN_VAL_IF_FAIL(hwc_window_data != NULL, TDM_ERROR_INVALID_PARAMETER);
233         RETURN_VAL_IF_FAIL(constraints != NULL, TDM_ERROR_INVALID_PARAMETER);
234
235         *constraints = hwc_window_data->constraints;
236
237         return TDM_ERROR_NONE;
238 }
239
240 tdm_error
241 nexell_hwc_window_set_name(tdm_hwc_window *hwc_window, const char *name)
242 {
243         tdm_nexell_hwc_window_data *hwc_window_data = hwc_window;
244
245         RETURN_VAL_IF_FAIL(hwc_window_data != NULL, TDM_ERROR_INVALID_PARAMETER);
246
247         if (!name)
248                 return TDM_ERROR_NONE;
249
250         snprintf(hwc_window_data->name, TDM_NAME_LEN, "%s", name);
251
252         return TDM_ERROR_NONE;
253 }
254
255 tdm_error
256 nexell_hwc_window_set_cursor_image(tdm_hwc_window *hwc_window, int width, int height, int stride, void *ptr)
257 {
258         tdm_nexell_hwc_window_data *hwc_window_data = hwc_window;
259
260         RETURN_VAL_IF_FAIL(hwc_window_data != NULL, TDM_ERROR_INVALID_PARAMETER);
261
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;
266
267         hwc_window_data->cursor_img_refresh = 1;
268
269         return TDM_ERROR_NONE;
270 }