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"
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
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
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
75 tdm_hwc_window_get_tbm_buffer_queue(tdm_hwc_window *hwc_window, tdm_error *error)
77 tdm_func_hwc_window *func_hwc_window = NULL;
78 tbm_surface_queue_h queue = NULL;
80 HWC_WINDOW_FUNC_ENTRY_ERROR();
82 _pthread_mutex_lock(&private_display->lock);
84 func_hwc_window = &private_display->func_hwc_window;
86 if (!func_hwc_window->hwc_window_get_tbm_buffer_queue) {
88 _pthread_mutex_unlock(&private_display->lock);
89 TDM_ERR("not implemented!!");
91 *error = TDM_ERROR_NOT_IMPLEMENTED;
96 queue = func_hwc_window->hwc_window_get_tbm_buffer_queue(private_hwc_window->hwc_window_backend, error);
98 _pthread_mutex_unlock(&private_display->lock);
104 tdm_hwc_window_set_zpos(tdm_hwc_window *hwc_window, int32_t zpos)
106 tdm_func_hwc_window *func_hwc_window = NULL;
108 HWC_WINDOW_FUNC_ENTRY();
110 _pthread_mutex_lock(&private_display->lock);
112 func_hwc_window = &private_display->func_hwc_window;
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;
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;
126 _pthread_mutex_unlock(&private_display->lock);
132 tdm_hwc_window_set_composition_type(tdm_hwc_window *hwc_window,
133 tdm_hwc_window_composition composition_type)
135 tdm_func_hwc_window *func_hwc_window = NULL;
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);
141 _pthread_mutex_lock(&private_display->lock);
143 func_hwc_window = &private_display->func_hwc_window;
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;
153 ret = func_hwc_window->hwc_window_set_composition_type(private_hwc_window->hwc_window_backend, composition_type);
155 _pthread_mutex_unlock(&private_display->lock);
161 tdm_hwc_window_set_buffer_damage(tdm_hwc_window *hwc_window, tdm_hwc_region damage)
163 tdm_func_hwc_window *func_hwc_window = NULL;
165 HWC_WINDOW_FUNC_ENTRY();
166 if (damage.num_rects > 0)
167 TDM_RETURN_VAL_IF_FAIL(damage.rects != NULL, TDM_ERROR_INVALID_PARAMETER);
169 _pthread_mutex_lock(&private_display->lock);
171 func_hwc_window = &private_display->func_hwc_window;
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;
181 ret = func_hwc_window->hwc_window_set_buffer_damage(private_hwc_window->hwc_window_backend, damage);
183 _pthread_mutex_unlock(&private_display->lock);
190 tdm_hwc_window_set_info(tdm_hwc_window *hwc_window, tdm_hwc_window_info *info)
192 tdm_func_hwc_window *func_hwc_window = NULL;
195 HWC_WINDOW_FUNC_ENTRY();
197 TDM_RETURN_VAL_IF_FAIL(info != NULL, TDM_ERROR_INVALID_PARAMETER);
199 _pthread_mutex_lock(&private_display->lock);
201 func_hwc_window = &private_display->func_hwc_window;
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;
211 if (info->src_config.format)
212 snprintf(fmtstr, 128, "%c%c%c%c", FOURCC_STR(info->src_config.format));
214 snprintf(fmtstr, 128, "NONE");
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,
221 info->dst_pos.x, info->dst_pos.y,
222 info->dst_pos.w, info->dst_pos.h,
225 ret = func_hwc_window->hwc_window_set_info(private_hwc_window->hwc_window_backend, info);
227 _pthread_mutex_unlock(&private_display->lock);
233 tdm_hwc_window_set_buffer(tdm_hwc_window *hwc_window, tbm_surface_h buffer)
235 tdm_func_hwc_window *func_hwc_window;
237 HWC_WINDOW_FUNC_ENTRY();
239 _pthread_mutex_lock(&private_display->lock);
241 if ((tdm_debug_dump & TDM_DUMP_FLAG_WINDOW) && buffer) {
242 /* LCOV_EXCL_START */
243 char str[TDM_PATH_LEN];
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);
251 func_hwc_window = &private_display->func_hwc_window;
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;
261 ret = func_hwc_window->hwc_window_set_buffer(private_hwc_window->hwc_window_backend, buffer);
263 _pthread_mutex_unlock(&private_display->lock);
268 INTERN tdm_hwc_window *
269 tdm_hwc_window_create_internal(tdm_private_output *private_output, int is_video,
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;
278 TDM_RETURN_VAL_IF_FAIL(TDM_MUTEX_IS_LOCKED(), NULL);
281 if (!func_output->output_hwc_create_window) {
282 /* LCOV_EXCL_START */
284 *error = TDM_ERROR_BAD_MODULE;
289 hwc_window_backend = func_output->output_hwc_create_window(
290 private_output->output_backend, &ret);
291 if (ret != TDM_ERROR_NONE) {
297 if (!func_output->output_hwc_create_video_window) {
298 /* LCOV_EXCL_START */
300 *error = TDM_ERROR_NOT_IMPLEMENTED;
305 hwc_window_backend = func_output->output_hwc_create_video_window(
306 private_output->output_backend, &ret);
307 if (ret != TDM_ERROR_NONE) {
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);
320 *error = TDM_ERROR_OUT_OF_MEMORY;
325 LIST_ADD(&private_hwc_window->link, &private_output->hwc_window_list);
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;
331 TDM_DBG("hwc_window(%p) create", private_hwc_window);
334 *error = TDM_ERROR_NONE;
336 return private_hwc_window;
340 tdm_hwc_window_destroy_internal(tdm_private_hwc_window * private_hwc_window)
342 tdm_private_display *private_display;
343 tdm_private_output *private_output;
344 tdm_func_output *func_output;
346 TDM_RETURN_VAL_IF_FAIL(TDM_MUTEX_IS_LOCKED(), TDM_ERROR_OPERATION_FAILED);
348 if (!private_hwc_window)
349 return TDM_ERROR_OPERATION_FAILED;
351 private_display = private_hwc_window->private_display;
352 private_output = private_hwc_window->private_output;
354 LIST_DEL(&private_hwc_window->link);
356 func_output = &private_display->func_output;
357 func_output->output_hwc_destroy_window(private_output->output_backend, private_hwc_window->hwc_window_backend);
359 free(private_hwc_window);
360 return TDM_ERROR_NONE;
364 tdm_hwc_window_set_flags(tdm_hwc_window *hwc_window, tdm_hwc_window_flag flags)
366 tdm_func_hwc_window *func_hwc_window = NULL;
368 HWC_WINDOW_FUNC_ENTRY();
370 _pthread_mutex_lock(&private_display->lock);
372 func_hwc_window = &private_display->func_hwc_window;
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;
382 ret = func_hwc_window->hwc_window_set_flags(private_hwc_window->hwc_window_backend, flags);
384 _pthread_mutex_unlock(&private_display->lock);
390 tdm_hwc_window_unset_flags(tdm_hwc_window *hwc_window, tdm_hwc_window_flag flags)
392 tdm_func_hwc_window *func_hwc_window = NULL;
394 HWC_WINDOW_FUNC_ENTRY();
396 _pthread_mutex_lock(&private_display->lock);
398 func_hwc_window = &private_display->func_hwc_window;
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;
408 ret = func_hwc_window->hwc_window_unset_flags(private_hwc_window->hwc_window_backend, flags);
410 _pthread_mutex_unlock(&private_display->lock);
416 tdm_hwc_window_video_get_capability(tdm_hwc_window *hwc_window,
417 tdm_hwc_window_video_capability *video_capability)
419 tdm_func_hwc_window *func_hwc_window = NULL;
421 HWC_WINDOW_FUNC_ENTRY();
423 TDM_RETURN_VAL_IF_FAIL(video_capability != NULL, TDM_ERROR_INVALID_PARAMETER);
425 _pthread_mutex_lock(&private_display->lock);
427 func_hwc_window = &private_display->func_hwc_window;
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;
437 ret = func_hwc_window->hwc_window_video_get_capability(private_hwc_window->hwc_window_backend,
440 _pthread_mutex_unlock(&private_display->lock);
446 tdm_hwc_window_video_get_available_properties(tdm_hwc_window *hwc_window,
447 const tdm_prop **props, int *count)
449 tdm_func_hwc_window *func_hwc_window = NULL;
451 HWC_WINDOW_FUNC_ENTRY();
453 TDM_RETURN_VAL_IF_FAIL(props != NULL, TDM_ERROR_INVALID_PARAMETER);
454 TDM_RETURN_VAL_IF_FAIL(count != NULL, TDM_ERROR_INVALID_PARAMETER);
456 _pthread_mutex_lock(&private_display->lock);
458 func_hwc_window = &private_display->func_hwc_window;
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;
468 ret = func_hwc_window->hwc_window_video_get_available_properties(private_hwc_window->hwc_window_backend,
471 _pthread_mutex_unlock(&private_display->lock);
477 tdm_hwc_window_video_get_property(tdm_hwc_window *hwc_window,
478 unsigned int id, tdm_value *value)
480 tdm_func_hwc_window *func_hwc_window = NULL;
482 HWC_WINDOW_FUNC_ENTRY();
484 TDM_RETURN_VAL_IF_FAIL(value != NULL, TDM_ERROR_INVALID_PARAMETER);
486 _pthread_mutex_lock(&private_display->lock);
488 func_hwc_window = &private_display->func_hwc_window;
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;
498 ret = func_hwc_window->hwc_window_video_get_property(private_hwc_window->hwc_window_backend,
501 _pthread_mutex_unlock(&private_display->lock);
507 tdm_hwc_window_video_set_property(tdm_hwc_window *hwc_window,
508 unsigned int id, tdm_value value)
510 tdm_func_hwc_window *func_hwc_window = NULL;
512 HWC_WINDOW_FUNC_ENTRY();
514 _pthread_mutex_lock(&private_display->lock);
516 func_hwc_window = &private_display->func_hwc_window;
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;
526 ret = func_hwc_window->hwc_window_video_set_property(private_hwc_window->hwc_window_backend,
529 _pthread_mutex_unlock(&private_display->lock);