hwc: remove dump code
[platform/core/uifw/libtdm.git] / src / tdm_hwc_window.c
1 /**************************************************************************
2  *
3  * libtdm
4  *
5  * Copyright 2015 Samsung Electronics co., Ltd. All Rights Reserved.
6  *
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>
13  *
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:
21  *
22  * The above copyright notice and this permission notice (including the
23  * next paragraph) shall be included in all copies or substantial portions
24  * of the Software.
25  *
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.
33  *
34 **************************************************************************/
35
36 #ifdef HAVE_CONFIG_H
37 #include "config.h"
38 #endif
39
40 #include "tdm_private.h"
41
42 #define COUNT_MAX   10
43
44 #define HWC_WINDOW_FUNC_ENTRY() \
45         tdm_private_display *private_display; \
46         tdm_private_output *private_output; \
47         tdm_private_hwc_window *private_hwc_window; \
48         tdm_error ret = TDM_ERROR_NONE; /* default TDM_ERROR_NONE */\
49         TDM_RETURN_VAL_IF_FAIL(hwc_window != NULL, TDM_ERROR_INVALID_PARAMETER); \
50         private_hwc_window = (tdm_private_hwc_window*)hwc_window; \
51         private_output = private_hwc_window->private_output; \
52         private_display = private_output->private_display
53
54 #define HWC_WINDOW_FUNC_ENTRY_ERROR() \
55         tdm_private_display *private_display; \
56         tdm_private_output *private_output; \
57         tdm_private_hwc_window *private_hwc_window; \
58         tdm_error ret = TDM_ERROR_NONE; /* default TDM_ERROR_NONE */\
59         TDM_RETURN_VAL_IF_FAIL_WITH_ERROR(hwc_window != NULL, TDM_ERROR_INVALID_PARAMETER, NULL); \
60         private_hwc_window = (tdm_private_hwc_window*)hwc_window; \
61         private_output = private_hwc_window->private_output; \
62         private_display = private_output->private_display
63
64 #define HWC_WINDOW_FUNC_ENTRY_VOID_RETURN() \
65         tdm_private_display *private_display; \
66         tdm_private_output *private_output; \
67         tdm_private_hwc_window *private_hwc_window; \
68         tdm_error ret = TDM_ERROR_NONE; /* default TDM_ERROR_NONE */\
69         TDM_RETURN_IF_FAIL(hwc_window != NULL); \
70         private_hwc_window = (tdm_private_hwc_window*)hwc_window; \
71         private_output = private_hwc_window->private_output; \
72         private_display = private_output->private_display
73
74 tbm_surface_queue_h
75 tdm_hwc_window_get_tbm_buffer_queue(tdm_hwc_window *hwc_window, tdm_error *error)
76 {
77         tdm_func_hwc_window *func_hwc_window = NULL;
78         tbm_surface_queue_h queue = NULL;
79
80         HWC_WINDOW_FUNC_ENTRY_ERROR();
81
82         _pthread_mutex_lock(&private_display->lock);
83
84         func_hwc_window = &private_display->func_hwc_window;
85
86         if (!func_hwc_window->hwc_window_get_tbm_buffer_queue) {
87                 /* LCOV_EXCL_START */
88                 _pthread_mutex_unlock(&private_display->lock);
89                 TDM_ERR("not implemented!!");
90                 if (error)
91                         *error = TDM_ERROR_NOT_IMPLEMENTED;
92                 return NULL;
93                 /* LCOV_EXCL_STOP */
94         }
95
96         queue = func_hwc_window->hwc_window_get_tbm_buffer_queue(private_hwc_window->hwc_window_backend, error);
97
98         _pthread_mutex_unlock(&private_display->lock);
99
100         return queue;
101 }
102
103 EXTERN tdm_error
104 tdm_hwc_window_set_zpos(tdm_hwc_window *hwc_window, int32_t zpos)
105 {
106         tdm_func_hwc_window *func_hwc_window = NULL;
107
108         HWC_WINDOW_FUNC_ENTRY();
109
110         _pthread_mutex_lock(&private_display->lock);
111
112         func_hwc_window = &private_display->func_hwc_window;
113
114         if (!func_hwc_window->hwc_window_set_zpos) {
115                 /* LCOV_EXCL_START */
116                 _pthread_mutex_unlock(&private_display->lock);
117                 TDM_ERR("not implemented!!");
118                 return TDM_ERROR_NOT_IMPLEMENTED;
119                 /* LCOV_EXCL_STOP */
120         }
121
122         ret = func_hwc_window->hwc_window_set_zpos(private_hwc_window->hwc_window_backend, zpos);
123         if (ret == TDM_ERROR_NONE)
124                 private_hwc_window->zpos = zpos;
125
126         _pthread_mutex_unlock(&private_display->lock);
127
128         return ret;
129 }
130
131 EXTERN tdm_error
132 tdm_hwc_window_set_composition_type(tdm_hwc_window *hwc_window,
133                                                                         tdm_hwc_window_composition composition_type)
134 {
135         tdm_func_hwc_window *func_hwc_window = NULL;
136
137         HWC_WINDOW_FUNC_ENTRY();
138         TDM_RETURN_VAL_IF_FAIL(composition_type >= TDM_COMPOSITION_NONE, TDM_ERROR_INVALID_PARAMETER);
139         TDM_RETURN_VAL_IF_FAIL(composition_type <= TDM_COMPOSITION_VIDEO, TDM_ERROR_INVALID_PARAMETER);
140
141         _pthread_mutex_lock(&private_display->lock);
142
143         func_hwc_window = &private_display->func_hwc_window;
144
145         if (!func_hwc_window->hwc_window_set_composition_type) {
146                 /* LCOV_EXCL_START */
147                 _pthread_mutex_unlock(&private_display->lock);
148                 TDM_ERR("not implemented!!");
149                 return TDM_ERROR_NOT_IMPLEMENTED;
150                 /* LCOV_EXCL_STOP */
151         }
152
153         ret = func_hwc_window->hwc_window_set_composition_type(private_hwc_window->hwc_window_backend, composition_type);
154
155         _pthread_mutex_unlock(&private_display->lock);
156
157         return ret;
158 }
159
160 EXTERN tdm_error
161 tdm_hwc_window_set_buffer_damage(tdm_hwc_window *hwc_window, tdm_hwc_region damage)
162 {
163         tdm_func_hwc_window *func_hwc_window = NULL;
164
165         HWC_WINDOW_FUNC_ENTRY();
166         if (damage.num_rects > 0)
167                 TDM_RETURN_VAL_IF_FAIL(damage.rects != NULL, TDM_ERROR_INVALID_PARAMETER);
168
169         _pthread_mutex_lock(&private_display->lock);
170
171         func_hwc_window = &private_display->func_hwc_window;
172
173         if (!func_hwc_window->hwc_window_set_buffer_damage) {
174                 /* LCOV_EXCL_START */
175                 _pthread_mutex_unlock(&private_display->lock);
176                 TDM_ERR("not implemented!!");
177                 return TDM_ERROR_NOT_IMPLEMENTED;
178                 /* LCOV_EXCL_STOP */
179         }
180
181         ret = func_hwc_window->hwc_window_set_buffer_damage(private_hwc_window->hwc_window_backend, damage);
182
183         _pthread_mutex_unlock(&private_display->lock);
184
185         return ret;
186 }
187
188
189 EXTERN tdm_error
190 tdm_hwc_window_set_info(tdm_hwc_window *hwc_window, tdm_hwc_window_info *info)
191 {
192         tdm_func_hwc_window *func_hwc_window = NULL;
193         char fmtstr[128];
194
195         HWC_WINDOW_FUNC_ENTRY();
196
197         TDM_RETURN_VAL_IF_FAIL(info != NULL, TDM_ERROR_INVALID_PARAMETER);
198
199         _pthread_mutex_lock(&private_display->lock);
200
201         func_hwc_window = &private_display->func_hwc_window;
202
203         if (!func_hwc_window->hwc_window_set_info) {
204                 /* LCOV_EXCL_START */
205                 _pthread_mutex_unlock(&private_display->lock);
206                 TDM_ERR("not implemented!!");
207                 return TDM_ERROR_NOT_IMPLEMENTED;
208                 /* LCOV_EXCL_STOP */
209         }
210
211         if (info->src_config.format)
212                 snprintf(fmtstr, 128, "%c%c%c%c", FOURCC_STR(info->src_config.format));
213         else
214                 snprintf(fmtstr, 128, "NONE");
215
216         TDM_INFO("hwc_window(%p) info: src(%dx%d %d,%d %dx%d %s) dst(%d,%d %dx%d) trans(%d)",
217                          private_hwc_window, info->src_config.size.h, info->src_config.size.v,
218                          info->src_config.pos.x, info->src_config.pos.y,
219                          info->src_config.pos.w, info->src_config.pos.h,
220                          fmtstr,
221                          info->dst_pos.x, info->dst_pos.y,
222                          info->dst_pos.w, info->dst_pos.h,
223                          info->transform);
224
225         ret = func_hwc_window->hwc_window_set_info(private_hwc_window->hwc_window_backend, info);
226
227         _pthread_mutex_unlock(&private_display->lock);
228
229         return ret;
230 }
231
232 EXTERN tdm_error
233 tdm_hwc_window_set_buffer(tdm_hwc_window *hwc_window, tbm_surface_h buffer)
234 {
235         tdm_func_hwc_window *func_hwc_window;
236
237         HWC_WINDOW_FUNC_ENTRY();
238
239         _pthread_mutex_lock(&private_display->lock);
240
241         if ((tdm_debug_dump & TDM_DUMP_FLAG_WINDOW) && buffer) {
242                 /* LCOV_EXCL_START */
243                 char str[TDM_PATH_LEN];
244                 static int i;
245                 snprintf(str, TDM_PATH_LEN, "window_%d_%d_%03d",
246                                  private_output->index, private_hwc_window->zpos, i++);
247                 tdm_helper_dump_buffer_str(buffer, tdm_debug_dump_dir, str);
248                 /* LCOV_EXCL_STOP */
249         }
250
251         func_hwc_window = &private_display->func_hwc_window;
252
253         if (!func_hwc_window->hwc_window_set_buffer) {
254                 /* LCOV_EXCL_START */
255                 _pthread_mutex_unlock(&private_display->lock);
256                 TDM_ERR("not implemented!!");
257                 return TDM_ERROR_NOT_IMPLEMENTED;
258                 /* LCOV_EXCL_STOP */
259         }
260
261         ret = func_hwc_window->hwc_window_set_buffer(private_hwc_window->hwc_window_backend, buffer);
262
263         _pthread_mutex_unlock(&private_display->lock);
264
265         return ret;
266 }
267
268 INTERN tdm_hwc_window *
269 tdm_hwc_window_create_internal(tdm_private_output *private_output, int is_video,
270                                                                    tdm_error *error)
271 {
272         tdm_private_display *private_display = private_output->private_display;
273         tdm_func_output *func_output = &private_display->func_output;
274         tdm_private_hwc_window *private_hwc_window = NULL;
275         tdm_hwc_window *hwc_window_backend = NULL;
276         tdm_error ret = TDM_ERROR_NONE;
277
278         TDM_RETURN_VAL_IF_FAIL(TDM_MUTEX_IS_LOCKED(), NULL);
279
280         if (!is_video) {
281                 if (!func_output->output_hwc_create_window) {
282                         /* LCOV_EXCL_START */
283                         if (error)
284                                 *error = TDM_ERROR_BAD_MODULE;
285                         return NULL;
286                         /* LCOV_EXCL_STOP */
287                 }
288
289                 hwc_window_backend = func_output->output_hwc_create_window(
290                                                  private_output->output_backend, &ret);
291                 if (ret != TDM_ERROR_NONE) {
292                         if (error)
293                                 *error = ret;
294                         return NULL;
295                 }
296         } else {
297                 if (!func_output->output_hwc_create_video_window) {
298                         /* LCOV_EXCL_START */
299                         if (error)
300                                 *error = TDM_ERROR_NOT_IMPLEMENTED;
301                         return NULL;
302                         /* LCOV_EXCL_STOP */
303                 }
304
305                 hwc_window_backend = func_output->output_hwc_create_video_window(
306                                                  private_output->output_backend, &ret);
307                 if (ret != TDM_ERROR_NONE) {
308                         if (error)
309                                 *error = ret;
310                         return NULL;
311                 }
312         }
313
314         private_hwc_window = calloc(1, sizeof(tdm_private_hwc_window));
315         if (!private_hwc_window) {
316                 /* LCOV_EXCL_START */
317                 TDM_ERR("failed: alloc memory");
318                 func_output->output_hwc_destroy_window(private_output->output_backend, hwc_window_backend);
319                 if (error)
320                         *error = TDM_ERROR_OUT_OF_MEMORY;
321                 return NULL;
322                 /* LCOV_EXCL_STOP */
323         }
324
325         LIST_ADD(&private_hwc_window->link, &private_output->hwc_window_list);
326
327         private_hwc_window->private_display = private_display;
328         private_hwc_window->private_output = private_output;
329         private_hwc_window->hwc_window_backend = hwc_window_backend;
330
331         TDM_DBG("hwc_window(%p) create", private_hwc_window);
332
333         if (error)
334                 *error = TDM_ERROR_NONE;
335
336         return private_hwc_window;
337 }
338
339 INTERN tdm_error
340 tdm_hwc_window_destroy_internal(tdm_private_hwc_window * private_hwc_window)
341 {
342         tdm_private_display *private_display;
343         tdm_private_output *private_output;
344         tdm_func_output *func_output;
345
346         TDM_RETURN_VAL_IF_FAIL(TDM_MUTEX_IS_LOCKED(), TDM_ERROR_OPERATION_FAILED);
347
348         if (!private_hwc_window)
349                 return TDM_ERROR_OPERATION_FAILED;
350
351         private_display = private_hwc_window->private_display;
352         private_output = private_hwc_window->private_output;
353
354         LIST_DEL(&private_hwc_window->link);
355
356         func_output = &private_display->func_output;
357         func_output->output_hwc_destroy_window(private_output->output_backend, private_hwc_window->hwc_window_backend);
358
359         free(private_hwc_window);
360         return TDM_ERROR_NONE;
361 }
362
363 EXTERN tdm_error
364 tdm_hwc_window_set_flags(tdm_hwc_window *hwc_window, tdm_hwc_window_flag flags)
365 {
366         tdm_func_hwc_window *func_hwc_window = NULL;
367
368         HWC_WINDOW_FUNC_ENTRY();
369
370         _pthread_mutex_lock(&private_display->lock);
371
372         func_hwc_window = &private_display->func_hwc_window;
373
374         if (!func_hwc_window->hwc_window_set_flags) {
375                 /* LCOV_EXCL_START */
376                 _pthread_mutex_unlock(&private_display->lock);
377                 TDM_ERR("not implemented!!");
378                 return TDM_ERROR_NOT_IMPLEMENTED;
379                 /* LCOV_EXCL_STOP */
380         }
381
382         ret = func_hwc_window->hwc_window_set_flags(private_hwc_window->hwc_window_backend, flags);
383
384         _pthread_mutex_unlock(&private_display->lock);
385
386         return ret;
387 }
388
389 EXTERN tdm_error
390 tdm_hwc_window_unset_flags(tdm_hwc_window *hwc_window, tdm_hwc_window_flag flags)
391 {
392         tdm_func_hwc_window *func_hwc_window = NULL;
393
394         HWC_WINDOW_FUNC_ENTRY();
395
396         _pthread_mutex_lock(&private_display->lock);
397
398         func_hwc_window = &private_display->func_hwc_window;
399
400         if (!func_hwc_window->hwc_window_unset_flags) {
401                 /* LCOV_EXCL_START */
402                 _pthread_mutex_unlock(&private_display->lock);
403                 TDM_ERR("not implemented!!");
404                 return TDM_ERROR_NOT_IMPLEMENTED;
405                 /* LCOV_EXCL_STOP */
406         }
407
408         ret = func_hwc_window->hwc_window_unset_flags(private_hwc_window->hwc_window_backend, flags);
409
410         _pthread_mutex_unlock(&private_display->lock);
411
412         return ret;
413 }
414
415 EXTERN tdm_error
416 tdm_hwc_window_video_get_capability(tdm_hwc_window *hwc_window,
417                                                                         tdm_hwc_window_video_capability *video_capability)
418 {
419         tdm_func_hwc_window *func_hwc_window = NULL;
420
421         HWC_WINDOW_FUNC_ENTRY();
422
423         TDM_RETURN_VAL_IF_FAIL(video_capability != NULL, TDM_ERROR_INVALID_PARAMETER);
424
425         _pthread_mutex_lock(&private_display->lock);
426
427         func_hwc_window = &private_display->func_hwc_window;
428
429         if (!func_hwc_window->hwc_window_video_get_capability) {
430                 /* LCOV_EXCL_START */
431                 _pthread_mutex_unlock(&private_display->lock);
432                 TDM_ERR("not implemented!!");
433                 return TDM_ERROR_NOT_IMPLEMENTED;
434                 /* LCOV_EXCL_STOP */
435         }
436
437         ret = func_hwc_window->hwc_window_video_get_capability(private_hwc_window->hwc_window_backend,
438                                                                                                                    video_capability);
439
440         _pthread_mutex_unlock(&private_display->lock);
441
442         return ret;
443 }
444
445 EXTERN tdm_error
446 tdm_hwc_window_video_get_available_properties(tdm_hwc_window *hwc_window,
447                                                                                           const tdm_prop **props, int *count)
448 {
449         tdm_func_hwc_window *func_hwc_window = NULL;
450
451         HWC_WINDOW_FUNC_ENTRY();
452
453         TDM_RETURN_VAL_IF_FAIL(props != NULL, TDM_ERROR_INVALID_PARAMETER);
454         TDM_RETURN_VAL_IF_FAIL(count != NULL, TDM_ERROR_INVALID_PARAMETER);
455
456         _pthread_mutex_lock(&private_display->lock);
457
458         func_hwc_window = &private_display->func_hwc_window;
459
460         if (!func_hwc_window->hwc_window_video_get_available_properties) {
461                 /* LCOV_EXCL_START */
462                 _pthread_mutex_unlock(&private_display->lock);
463                 TDM_ERR("not implemented!!");
464                 return TDM_ERROR_NOT_IMPLEMENTED;
465                 /* LCOV_EXCL_STOP */
466         }
467
468         ret = func_hwc_window->hwc_window_video_get_available_properties(private_hwc_window->hwc_window_backend,
469                                                                                                                                          props, count);
470
471         _pthread_mutex_unlock(&private_display->lock);
472
473         return ret;
474 }
475
476 EXTERN tdm_error
477 tdm_hwc_window_video_get_property(tdm_hwc_window *hwc_window,
478                                                                         unsigned int id, tdm_value *value)
479 {
480         tdm_func_hwc_window *func_hwc_window = NULL;
481
482         HWC_WINDOW_FUNC_ENTRY();
483
484         TDM_RETURN_VAL_IF_FAIL(value != NULL, TDM_ERROR_INVALID_PARAMETER);
485
486         _pthread_mutex_lock(&private_display->lock);
487
488         func_hwc_window = &private_display->func_hwc_window;
489
490         if (!func_hwc_window->hwc_window_video_get_property) {
491                 /* LCOV_EXCL_START */
492                 _pthread_mutex_unlock(&private_display->lock);
493                 TDM_ERR("not implemented!!");
494                 return TDM_ERROR_NOT_IMPLEMENTED;
495                 /* LCOV_EXCL_STOP */
496         }
497
498         ret = func_hwc_window->hwc_window_video_get_property(private_hwc_window->hwc_window_backend,
499                                                                                                                  id, value);
500
501         _pthread_mutex_unlock(&private_display->lock);
502
503         return ret;
504 }
505
506 EXTERN tdm_error
507 tdm_hwc_window_video_set_property(tdm_hwc_window *hwc_window,
508                                                                         unsigned int id, tdm_value value)
509 {
510         tdm_func_hwc_window *func_hwc_window = NULL;
511
512         HWC_WINDOW_FUNC_ENTRY();
513
514         _pthread_mutex_lock(&private_display->lock);
515
516         func_hwc_window = &private_display->func_hwc_window;
517
518         if (!func_hwc_window->hwc_window_video_set_property) {
519                 /* LCOV_EXCL_START */
520                 _pthread_mutex_unlock(&private_display->lock);
521                 TDM_ERR("not implemented!!");
522                 return TDM_ERROR_NOT_IMPLEMENTED;
523                 /* LCOV_EXCL_STOP */
524         }
525
526         ret = func_hwc_window->hwc_window_video_set_property(private_hwc_window->hwc_window_backend,
527                                                                                                                  id, value);
528
529         _pthread_mutex_unlock(&private_display->lock);
530
531         return ret;
532 }