Implementation of TDM_HWC
[platform/adaptation/nexell/libtdm-nexell.git] / src / tdm_nexell_hwc_window.c
1
2 #ifdef HAVE_CONFIG_H
3 #include "config.h"
4 #endif
5
6 #include "tdm_nexell.h"
7
8 tbm_surface_queue_h
9 nexell_hwc_window_acquire_buffer_queue(tdm_hwc_window *hwc_window, tdm_error *error)
10 {
11         tdm_nexell_hwc_data *hwc_data = NULL;
12         tdm_nexell_hwc_window_data *hwc_window_data = NULL;
13         tbm_surface_queue_h tqueue = NULL;
14
15         if (error)
16                 *error = TDM_ERROR_INVALID_PARAMETER;
17
18         hwc_window_data = (tdm_nexell_hwc_window_data *)hwc_window;
19         RETURN_VAL_IF_FAIL(hwc_window_data != NULL, NULL);
20
21         hwc_data = hwc_window_data->hwc_data;
22         RETURN_VAL_IF_FAIL(hwc_data != NULL, NULL);
23
24         if (error)
25                 *error = TDM_ERROR_NONE;
26
27         if (hwc_data->ui_buffer_queue[hwc_window_data->lzpos_queue].tqueue) {
28                 /* reference the ui_buffer queue */
29                 tqueue = hwc_data->ui_buffer_queue[hwc_window_data->lzpos_queue].tqueue;
30                 hwc_data->ui_buffer_queue[hwc_window_data->lzpos_queue].ref_cnt++;
31                 TDM_ERR(" Acquire BUFFER_QUEUE[reference]: lzpos_queue:%d tqueue:%p ref_cnt:%d",
32                                 hwc_window_data->lzpos_queue,
33                                 hwc_data->ui_buffer_queue[hwc_window_data->lzpos_queue].tqueue,
34                                 hwc_data->ui_buffer_queue[hwc_window_data->lzpos_queue].ref_cnt);
35         } else {
36                 /* create a ui_buffer_queue */
37                 tqueue = tdm_nexell_hwc_window_create_tbm_buffer_queue(hwc_window_data, error);
38                 RETURN_VAL_IF_FAIL(tqueue != NULL, NULL);
39
40                 hwc_data->ui_buffer_queue[hwc_window_data->lzpos_queue].tqueue = tqueue;
41                 hwc_data->ui_buffer_queue[hwc_window_data->lzpos_queue].ref_cnt = 1;
42                 TDM_ERR(" Acquire BUFFER_QUEUE[create]: lzpos_queue:%d tqueue:%p ref_cnt:%d",
43                                 hwc_window_data->lzpos_queue,
44                                 hwc_data->ui_buffer_queue[hwc_window_data->lzpos_queue].tqueue,
45                                 hwc_data->ui_buffer_queue[hwc_window_data->lzpos_queue].ref_cnt);
46         }
47
48         return tqueue;
49 }
50
51 void
52 nexell_hwc_window_release_buffer_queue(tdm_hwc_window *hwc_window, tbm_surface_queue_h queue)
53 {
54         tdm_nexell_hwc_data *hwc_data = NULL;
55         tdm_nexell_hwc_window_data *hwc_window_data = NULL;
56
57         hwc_window_data = (tdm_nexell_hwc_window_data *)hwc_window;
58         RETURN_IF_FAIL(hwc_window_data != NULL);
59
60         hwc_data = hwc_window_data->hwc_data;
61         RETURN_IF_FAIL(hwc_data != NULL);
62
63         if (hwc_data->ui_buffer_queue[hwc_window_data->lzpos_queue].ref_cnt > 0) {
64                 hwc_data->ui_buffer_queue[hwc_window_data->lzpos_queue].ref_cnt--;
65
66                 TDM_ERR(" Release BUFFER_QUEUE[dereference]: lzpos_queue:%d tqueue:%p ref_cnt:%d",
67                                 hwc_window_data->lzpos_queue,
68                                 hwc_data->ui_buffer_queue[hwc_window_data->lzpos_queue].tqueue,
69                                 hwc_data->ui_buffer_queue[hwc_window_data->lzpos_queue].ref_cnt);
70
71                 /* destroy a ui_buffer_queue when ref_cnt is 0 */
72                 if (hwc_data->ui_buffer_queue[hwc_window_data->lzpos_queue].ref_cnt == 0) {
73                         TDM_ERR(" Release BUFFER_QUEUE", "destroy buffer_queue(%p)", hwc_data->ui_buffer_queue[hwc_window_data->lzpos_queue].tqueue);
74
75                         tdm_nexell_hwc_window_destroy_tbm_buffer_queue(hwc_data->ui_buffer_queue[hwc_window_data->lzpos_queue].tqueue);
76                         hwc_data->ui_buffer_queue[hwc_window_data->lzpos_queue].tqueue = NULL;
77                 }
78         }
79 }
80
81 void
82 nexell_hwc_window_destroy(tdm_hwc_window *hwc_window)
83 {
84         tdm_nexell_hwc_window_data *hwc_window_data = hwc_window;
85
86         RETURN_IF_FAIL(hwc_window_data != NULL);
87
88         LIST_DEL(&hwc_window_data->link);
89
90         free(hwc_window_data);
91 }
92
93 tdm_error
94 nexell_hwc_window_set_composition_type(tdm_hwc_window *hwc_window,
95                                                                         tdm_hwc_window_composition comp_type)
96 {
97         tdm_nexell_hwc_window_data *hwc_window_data = hwc_window;
98         tdm_nexell_hwc_data *hwc_data = hwc_window_data->hwc_data;
99
100         RETURN_VAL_IF_FAIL(hwc_window_data != NULL, TDM_ERROR_INVALID_PARAMETER);
101         RETURN_VAL_IF_FAIL(hwc_data != NULL, TDM_ERROR_INVALID_PARAMETER);
102
103         /* change the client_type when it is different from one which has before */
104         if (hwc_window_data->client_type == comp_type)
105                 return TDM_ERROR_NONE;
106
107         hwc_window_data->client_type = comp_type;
108
109         return TDM_ERROR_NONE;
110 }
111
112 tdm_error
113 nexell_hwc_window_set_buffer_damage(tdm_hwc_window *hwc_window, tdm_region damage)
114 {
115         tdm_nexell_hwc_window_data *hwc_window_data = hwc_window;
116
117         RETURN_VAL_IF_FAIL(hwc_window_data != NULL, TDM_ERROR_INVALID_PARAMETER);
118
119         //TODO::
120
121         return TDM_ERROR_NONE;
122 }
123
124 tdm_error
125 nexell_hwc_window_set_info(tdm_hwc_window *hwc_window, tdm_hwc_window_info *info)
126 {
127         tdm_nexell_hwc_window_data *hwc_window_data = hwc_window;
128         tdm_nexell_hwc_data *hwc_data;
129
130         RETURN_VAL_IF_FAIL(hwc_window_data != NULL, TDM_ERROR_INVALID_PARAMETER);
131         hwc_data = hwc_window_data->hwc_data;
132         RETURN_VAL_IF_FAIL(hwc_data != NULL, TDM_ERROR_INVALID_PARAMETER);
133         RETURN_VAL_IF_FAIL(info != NULL, TDM_ERROR_INVALID_PARAMETER);
134
135         if (!memcmp(&hwc_window_data->info, info, sizeof(tdm_hwc_window_info)))
136                 return TDM_ERROR_NONE;
137
138         hwc_window_data->info = *info;
139
140         return TDM_ERROR_NONE;
141 }
142
143 tdm_error
144 nexell_hwc_window_set_buffer(tdm_hwc_window *hwc_window, tbm_surface_h surface)
145 {
146         tdm_nexell_hwc_window_data *hwc_window_data = hwc_window;
147         tdm_error err = TDM_ERROR_OPERATION_FAILED;
148
149         RETURN_VAL_IF_FAIL(hwc_window_data != NULL, err);
150
151         if (hwc_window_data->surface == surface)
152                 return TDM_ERROR_NONE;
153
154         hwc_window_data->surface = surface;
155
156         return TDM_ERROR_NONE;
157 }
158
159 tdm_error
160 nexell_hwc_window_set_property(tdm_hwc_window *hwc_window, unsigned int id, tdm_value value)
161 {
162         tdm_nexell_hwc_window_data *hwc_window_data = hwc_window;
163
164         RETURN_VAL_IF_FAIL(hwc_window_data != NULL, TDM_ERROR_INVALID_PARAMETER);
165
166         //TODO:
167
168         return TDM_ERROR_NONE;
169 }
170
171 tdm_error
172 nexell_hwc_window_get_property(tdm_hwc_window *hwc_window, unsigned int id, tdm_value *value)
173 {
174         tdm_nexell_hwc_window_data *hwc_window_data = hwc_window;
175
176         RETURN_VAL_IF_FAIL(hwc_window_data != NULL, TDM_ERROR_INVALID_PARAMETER);
177
178         //TODO:
179
180         return TDM_ERROR_NONE;
181 }
182
183 tdm_error
184 nexell_hwc_window_get_constraints(tdm_hwc_window *hwc_window, int *constraints)
185 {
186         tdm_nexell_hwc_window_data *hwc_window_data = hwc_window;
187
188         RETURN_VAL_IF_FAIL(hwc_window_data != NULL, TDM_ERROR_INVALID_PARAMETER);
189         RETURN_VAL_IF_FAIL(constraints != NULL, TDM_ERROR_INVALID_PARAMETER);
190
191         *constraints = hwc_window_data->constraints;
192
193         return TDM_ERROR_NONE;
194 }
195
196 tdm_error
197 nexell_hwc_window_set_name(tdm_hwc_window *hwc_window, const char *name)
198 {
199         tdm_nexell_hwc_window_data *hwc_window_data = hwc_window;
200
201         RETURN_VAL_IF_FAIL(hwc_window_data != NULL, TDM_ERROR_INVALID_PARAMETER);
202
203         if (!name)
204                 return TDM_ERROR_NONE;
205
206         snprintf(hwc_window_data->name, TDM_NAME_LEN, "%s", name);
207
208         return TDM_ERROR_NONE;
209 }
210
211 tdm_error
212 nexell_hwc_window_set_cursor_image(tdm_hwc_window *hwc_window, int width, int height, int stride, void *ptr)
213 {
214         tdm_nexell_hwc_window_data *hwc_window_data = hwc_window;
215
216         RETURN_VAL_IF_FAIL(hwc_window_data != NULL, TDM_ERROR_INVALID_PARAMETER);
217         RETURN_VAL_IF_FAIL(hwc_window_data->client_type == TDM_HWC_WIN_COMPOSITION_CURSOR, TDM_ERROR_INVALID_PARAMETER);
218
219         hwc_window_data->cursor_img.width = width;
220         hwc_window_data->cursor_img.height = height;
221         hwc_window_data->cursor_img.stride = stride;
222         hwc_window_data->cursor_img.ptr = ptr;
223
224         hwc_window_data->cursor_img_refresh = 1;
225
226         return TDM_ERROR_NONE;
227 }