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 <boram1288.park@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 OUTPUT_FUNC_ENTRY() \
45 tdm_private_display *private_display; \
46 tdm_private_output *private_output; \
47 tdm_error ret = TDM_ERROR_NONE; /* default TDM_ERROR_NONE */\
48 TDM_RETURN_VAL_IF_FAIL(output != NULL, TDM_ERROR_INVALID_PARAMETER); \
49 private_output = (tdm_private_output*)output; \
50 private_display = private_output->private_display
52 #define OUTPUT_FUNC_ENTRY_ERROR() \
53 tdm_private_display *private_display; \
54 tdm_private_output *private_output; \
55 tdm_error ret = TDM_ERROR_NONE; /* default TDM_ERROR_NONE */\
56 TDM_RETURN_VAL_IF_FAIL_WITH_ERROR(output != NULL, TDM_ERROR_INVALID_PARAMETER, NULL); \
57 private_output = (tdm_private_output*)output; \
58 private_display = private_output->private_display
61 _tdm_output_vblank_timeout_update(tdm_private_output *private_output, int ms_delay);
64 _tdm_output_vblank_timeout_cb(void *user_data)
66 tdm_private_output *private_output = user_data;
67 tdm_private_output_vblank_handler *v = NULL;
69 TDM_RETURN_VAL_IF_FAIL(private_output != NULL, TDM_ERROR_OPERATION_FAILED);
71 private_output->vblank_timeout_timer_expired++;
73 TDM_ERR("TDM output(%d) vblank TIMEOUT!! (%d time%s)",
75 private_output->vblank_timeout_timer_expired,
76 (private_output->vblank_timeout_timer_expired > 1) ? "s" : "");
78 LIST_FOR_EACH_ENTRY(v, &private_output->vblank_handler_list, link) {
79 TDM_ERR("vblank_handler(%p) interval(%d) sync(%d) sent_to_frontend(%u) owner_tid(%d)",
80 v, v->interval, v->sync, v->sent_to_frontend, v->owner_tid);
83 return TDM_ERROR_NONE;
87 tdm_output_vblank_print_wait_information(tdm_private_output *private_output, void *user_data)
89 tdm_private_output_vblank_handler *v = NULL;
91 TDM_RETURN_IF_FAIL(private_output != NULL);
92 TDM_RETURN_IF_FAIL(user_data != NULL);
94 TDM_ERR("TDM output(%d) vblank user_data(%p) info!!", private_output->pipe, user_data);
96 LIST_FOR_EACH_ENTRY(v, &private_output->vblank_handler_list, link) {
97 if (v->user_data != user_data)
99 TDM_ERR("vblank_handler(%p) interval(%d) sync(%d) sent_to_frontend(%u) owner_tid(%d)",
100 v, v->interval, v->sync, v->sent_to_frontend, v->owner_tid);
105 _tdm_output_vblank_timeout_update(tdm_private_output *private_output, int ms_delay)
109 if (!private_output->vblank_timeout_timer) {
110 private_output->vblank_timeout_timer =
111 tdm_event_loop_add_timer_handler(private_output->private_display,
112 _tdm_output_vblank_timeout_cb,
115 if (!private_output->vblank_timeout_timer) {
116 TDM_ERR("output(%d) couldn't add timer", private_output->pipe);
119 TDM_INFO("output(%d) create vblank timeout timer", private_output->pipe);
120 private_output->vblank_timeout_timer_expired = 0;
123 ret = tdm_event_loop_source_timer_update(private_output->vblank_timeout_timer, ms_delay);
124 if (ret != TDM_ERROR_NONE) {
125 TDM_ERR("output(%d) couldn't update timer", private_output->pipe);
131 tdm_output_init(tdm_private_display *private_display)
133 tdm_thread_cb_set_find_func(TDM_THREAD_CB_OUTPUT_DESTROY, tdm_display_find_output_stamp);
134 tdm_thread_cb_set_find_func(TDM_THREAD_CB_OUTPUT_COMMIT, tdm_display_find_output_stamp);
135 tdm_thread_cb_set_find_func(TDM_THREAD_CB_OUTPUT_VBLANK, tdm_display_find_output_stamp);
136 tdm_thread_cb_set_find_func(TDM_THREAD_CB_OUTPUT_STATUS, tdm_display_find_output_stamp);
137 tdm_thread_cb_set_find_func(TDM_THREAD_CB_OUTPUT_DPMS, tdm_display_find_output_stamp);
138 tdm_thread_cb_set_find_func(TDM_THREAD_CB_VOUTPUT_COMMIT, tdm_display_find_private_voutput);
140 return TDM_ERROR_NONE;
144 tdm_output_call_thread_cb_destroy(tdm_private_output *private_output)
146 tdm_thread_cb_output_destroy output_destroy;
149 memset(&output_destroy, 0, sizeof output_destroy);
150 output_destroy.base.type = TDM_THREAD_CB_OUTPUT_DESTROY;
151 output_destroy.base.length = sizeof output_destroy;
152 output_destroy.base.object_stamp = private_output->stamp;
153 output_destroy.base.data = NULL;
154 output_destroy.base.sync = 1;
156 ret = tdm_thread_cb_call(private_output, &output_destroy.base, 1);
157 TDM_WARNING_IF_FAIL(ret == TDM_ERROR_NONE);
159 return TDM_ERROR_NONE;
162 /* LCOV_EXCL_START */
164 tdm_output_thread_cb_destroy(tdm_private_display *private_display, void *object, tdm_thread_cb_base *cb_base, void *user_data)
166 tdm_private_output *private_output = object;
167 tdm_private_output_destroy_handler *destroy_handler = user_data;
169 TDM_RETURN_IF_FAIL(TDM_MUTEX_IS_LOCKED());
171 assert(destroy_handler->owner_tid == syscall(SYS_gettid));
173 _pthread_mutex_unlock(&private_display->lock);
174 destroy_handler->func(private_output, destroy_handler->user_data);
175 _pthread_mutex_lock(&private_display->lock);
179 tdm_output_add_destroy_handler(tdm_output *output,
180 tdm_output_destroy_handler func,
183 tdm_private_output_destroy_handler *destroy_handler = NULL;
186 TDM_RETURN_VAL_IF_FAIL(func != NULL, TDM_ERROR_INVALID_PARAMETER);
188 _pthread_mutex_lock(&private_display->lock);
190 LIST_FOR_EACH_ENTRY(destroy_handler, &private_output->destroy_handler_list, link) {
191 if (destroy_handler->func == func && destroy_handler->user_data == user_data) {
192 TDM_ERR("can't add twice");
193 _pthread_mutex_unlock(&private_display->lock);
194 return TDM_ERROR_BAD_REQUEST;
198 destroy_handler = calloc(1, sizeof(tdm_private_output_destroy_handler));
199 if (!destroy_handler) {
200 TDM_ERR("failed: alloc memory");
201 _pthread_mutex_unlock(&private_display->lock);
202 return TDM_ERROR_OUT_OF_MEMORY;
205 ret = tdm_thread_cb_add(private_output, TDM_THREAD_CB_OUTPUT_DESTROY, NULL, tdm_output_thread_cb_destroy, destroy_handler);
206 if (ret != TDM_ERROR_NONE) {
207 TDM_ERR("tdm_thread_cb_add failed");
208 free(destroy_handler);
209 _pthread_mutex_unlock(&private_display->lock);
210 return TDM_ERROR_OPERATION_FAILED;
213 destroy_handler->private_output = private_output;
214 destroy_handler->func = func;
215 destroy_handler->user_data = user_data;
216 destroy_handler->owner_tid = syscall(SYS_gettid);
218 LIST_ADDTAIL(&destroy_handler->link, &private_output->destroy_handler_list);
220 _pthread_mutex_unlock(&private_display->lock);
226 tdm_output_remove_destroy_handler(tdm_output *output,
227 tdm_output_destroy_handler func,
230 tdm_private_display *private_display;
231 tdm_private_output *private_output;
232 tdm_private_output_destroy_handler *destroy_handler = NULL, *hh = NULL;
234 TDM_RETURN_IF_FAIL(output != NULL);
235 TDM_RETURN_IF_FAIL(func != NULL);
237 private_output = (tdm_private_output*)output;
238 private_display = private_output->private_display;
240 _pthread_mutex_lock(&private_display->lock);
242 LIST_FOR_EACH_ENTRY_SAFE(destroy_handler, hh, &private_output->destroy_handler_list, link) {
243 if (destroy_handler->func != func || destroy_handler->user_data != user_data)
246 tdm_thread_cb_remove(private_output, TDM_THREAD_CB_OUTPUT_DESTROY, NULL, tdm_output_thread_cb_destroy, destroy_handler);
248 LIST_DEL(&destroy_handler->link);
249 free(destroy_handler);
251 _pthread_mutex_unlock(&private_display->lock);
256 _pthread_mutex_unlock(&private_display->lock);
261 tdm_output_get_backend_module(tdm_output *output, tdm_error *error)
263 tdm_private_module *private_module;
265 OUTPUT_FUNC_ENTRY_ERROR();
267 _pthread_mutex_lock(&private_display->lock);
269 private_module = private_output->private_module;
272 *error = TDM_ERROR_NONE;
274 _pthread_mutex_unlock(&private_display->lock);
276 return private_module;
280 tdm_output_get_model_info(tdm_output *output, const char **maker,
281 const char **model, const char **name)
285 _pthread_mutex_lock(&private_display->lock);
288 *maker = private_output->caps.maker;
290 *model = private_output->caps.model;
292 *name = private_output->caps.name;
294 _pthread_mutex_unlock(&private_display->lock);
300 tdm_output_get_capabilities(tdm_output *output, tdm_output_capability *capabilities)
304 TDM_RETURN_VAL_IF_FAIL(capabilities != NULL, TDM_ERROR_INVALID_PARAMETER);
306 _pthread_mutex_lock(&private_display->lock);
308 *capabilities = private_output->caps.capabilities;
310 _pthread_mutex_unlock(&private_display->lock);
316 tdm_output_get_conn_status(tdm_output *output, tdm_output_conn_status *status)
320 TDM_RETURN_VAL_IF_FAIL(status != NULL, TDM_ERROR_INVALID_PARAMETER);
322 _pthread_mutex_lock(&private_display->lock);
324 *status = private_output->caps.status;
326 _pthread_mutex_unlock(&private_display->lock);
332 tdm_output_thread_cb_change(tdm_private_display *private_display, void *object, tdm_thread_cb_base *cb_base, void *user_data)
334 tdm_private_output *private_output = object;
335 tdm_private_output_change_handler *change_handler = user_data;
336 tdm_output_change_type type = TDM_OUTPUT_CHANGE_CONNECTION;
337 tdm_value value = {.u32 = 0 };
339 TDM_RETURN_IF_FAIL(TDM_MUTEX_IS_LOCKED());
341 assert(change_handler->owner_tid == syscall(SYS_gettid));
343 if (cb_base->type == TDM_THREAD_CB_OUTPUT_STATUS) {
344 tdm_thread_cb_output_status *output_status = (tdm_thread_cb_output_status *)cb_base;
345 type = TDM_OUTPUT_CHANGE_CONNECTION;
346 value.u32 = output_status->status;
347 } else if (cb_base->type == TDM_THREAD_CB_OUTPUT_DPMS) {
348 tdm_thread_cb_output_dpms *output_dpms = (tdm_thread_cb_output_dpms *)cb_base;
349 type = TDM_OUTPUT_CHANGE_DPMS;
350 value.u32 = output_dpms->dpms;
352 TDM_NEVER_GET_HERE();
356 _pthread_mutex_unlock(&private_display->lock);
357 change_handler->func(private_output, type, value, change_handler->user_data);
358 _pthread_mutex_lock(&private_display->lock);
363 _tdm_output_call_thread_cb_status(tdm_private_output *private_output, tdm_output_conn_status status)
365 tdm_thread_cb_output_status output_status;
366 pid_t caller_tid = syscall(SYS_gettid);
369 memset(&output_status, 0, sizeof output_status);
370 output_status.base.type = TDM_THREAD_CB_OUTPUT_STATUS;
371 output_status.base.length = sizeof output_status;
372 output_status.base.object_stamp = private_output->stamp;
373 output_status.base.data = NULL;
374 if (tdm_thread_in_display_thread(caller_tid))
375 output_status.base.sync = 0;
377 output_status.base.sync = 1;
378 output_status.status = status;
380 ret = tdm_thread_cb_call(private_output, &output_status.base, 1);
381 TDM_WARNING_IF_FAIL(ret == TDM_ERROR_NONE);
383 return TDM_ERROR_NONE;
387 _tdm_output_call_thread_cb_dpms(tdm_private_output *private_output, tdm_output_dpms dpms)
389 tdm_thread_cb_output_dpms output_dpms;
392 memset(&output_dpms, 0, sizeof output_dpms);
393 output_dpms.base.type = TDM_THREAD_CB_OUTPUT_DPMS;
394 output_dpms.base.length = sizeof output_dpms;
395 output_dpms.base.object_stamp = private_output->stamp;
396 output_dpms.base.data = NULL;
397 output_dpms.base.sync = 0;
398 output_dpms.dpms = dpms;
400 ret = tdm_thread_cb_call(private_output, &output_dpms.base, 1);
401 TDM_WARNING_IF_FAIL(ret == TDM_ERROR_NONE);
403 return TDM_ERROR_NONE;
406 /* LCOV_EXCL_START */
408 tdm_output_cb_status(tdm_output *output_backend, tdm_output_conn_status status, void *user_data)
410 tdm_private_output *private_output = user_data;
413 TDM_RETURN_IF_FAIL(private_output);
415 TDM_INFO("output(%d) %s", private_output->pipe, tdm_status_str(status));
417 if ((private_output->caps.status == TDM_OUTPUT_CONN_STATUS_DISCONNECTED && status != TDM_OUTPUT_CONN_STATUS_DISCONNECTED) ||
418 (private_output->caps.status != TDM_OUTPUT_CONN_STATUS_DISCONNECTED && status == TDM_OUTPUT_CONN_STATUS_DISCONNECTED)) {
419 ret = tdm_display_update_output(private_output->private_module, output_backend);
420 TDM_RETURN_IF_FAIL(ret == TDM_ERROR_NONE);
422 private_output->caps.status = status;
425 ret = _tdm_output_call_thread_cb_status(private_output, status);
426 TDM_WARNING_IF_FAIL(ret == TDM_ERROR_NONE);
430 tdm_output_cb_dpms(tdm_output *output_backend, tdm_output_dpms dpms, void *user_data)
432 tdm_private_output *private_output = user_data;
435 TDM_INFO("output(%d) %s", private_output->pipe, tdm_dpms_str(dpms));
437 private_output->current_dpms_value = dpms;
438 private_output->waiting_dpms_change = 0;
439 TDM_INFO("output(%d) DPMS async '%s' done", private_output->pipe, tdm_dpms_str(dpms));
441 ret = _tdm_output_call_thread_cb_dpms(private_output, dpms);
442 TDM_WARNING_IF_FAIL(ret == TDM_ERROR_NONE);
447 tdm_output_add_change_handler(tdm_output *output,
448 tdm_output_change_handler func,
451 tdm_private_output_change_handler *change_handler = NULL;
454 TDM_RETURN_VAL_IF_FAIL(func != NULL, TDM_ERROR_INVALID_PARAMETER);
456 _pthread_mutex_lock(&private_display->lock);
458 LIST_FOR_EACH_ENTRY(change_handler, &private_output->change_handler_list, link) {
459 if (change_handler->func == func && change_handler->user_data == user_data) {
460 TDM_ERR("can't add twice");
461 _pthread_mutex_unlock(&private_display->lock);
462 return TDM_ERROR_BAD_REQUEST;
466 change_handler = calloc(1, sizeof(tdm_private_output_change_handler));
467 if (!change_handler) {
468 /* LCOV_EXCL_START */
469 TDM_ERR("failed: alloc memory");
470 _pthread_mutex_unlock(&private_display->lock);
471 return TDM_ERROR_OUT_OF_MEMORY;
475 ret = tdm_thread_cb_add(private_output, TDM_THREAD_CB_OUTPUT_DPMS, NULL, tdm_output_thread_cb_change, change_handler);
476 if (ret != TDM_ERROR_NONE) {
477 /* LCOV_EXCL_START */
478 TDM_ERR("tdm_thread_cb_add failed");
479 free(change_handler);
480 _pthread_mutex_unlock(&private_display->lock);
481 return TDM_ERROR_OPERATION_FAILED;
485 ret = tdm_thread_cb_add(private_output, TDM_THREAD_CB_OUTPUT_STATUS, NULL, tdm_output_thread_cb_change, change_handler);
486 if (ret != TDM_ERROR_NONE) {
487 /* LCOV_EXCL_START */
488 TDM_ERR("tdm_thread_cb_add failed");
489 tdm_thread_cb_remove(private_output, TDM_THREAD_CB_OUTPUT_DPMS, NULL, tdm_output_thread_cb_change, change_handler);
490 free(change_handler);
491 _pthread_mutex_unlock(&private_display->lock);
492 return TDM_ERROR_OPERATION_FAILED;
496 change_handler->private_output = private_output;
497 change_handler->func = func;
498 change_handler->user_data = user_data;
499 change_handler->owner_tid = syscall(SYS_gettid);
501 LIST_ADDTAIL(&change_handler->link, &private_output->change_handler_list);
503 _pthread_mutex_unlock(&private_display->lock);
508 /* LCOV_EXCL_START */
510 tdm_output_add_mode_change_request_handler(tdm_output *output,
511 tdm_output_mode_change_request_handler func,
514 tdm_private_display *private_display;
515 tdm_private_output *private_output;
516 tdm_private_output_mode_change_handler *mode_change_handler = NULL;
518 TDM_RETURN_VAL_IF_FAIL(output != NULL, TDM_ERROR_INVALID_PARAMETER);
519 TDM_RETURN_VAL_IF_FAIL(func != NULL, TDM_ERROR_INVALID_PARAMETER);
521 private_output = (tdm_private_output*)output;
522 private_display = private_output->private_display;
524 _pthread_mutex_lock(&private_display->lock);
526 LIST_FOR_EACH_ENTRY(mode_change_handler, &private_output->mode_change_request_handler_list, link) {
527 if (mode_change_handler->func == func && mode_change_handler->user_data == user_data) {
528 TDM_ERR("can't add twice");
529 _pthread_mutex_unlock(&private_display->lock);
530 return TDM_ERROR_BAD_REQUEST;
534 mode_change_handler = calloc(1, sizeof(tdm_private_output_mode_change_handler));
535 if (!mode_change_handler) {
536 /* LCOV_EXCL_START */
537 TDM_ERR("failed: alloc memory");
538 _pthread_mutex_unlock(&private_display->lock);
539 return TDM_ERROR_OUT_OF_MEMORY;
543 mode_change_handler->private_output = private_output;
544 mode_change_handler->func = func;
545 mode_change_handler->user_data = user_data;
547 LIST_ADDTAIL(&mode_change_handler->link, &private_output->mode_change_request_handler_list);
549 _pthread_mutex_unlock(&private_display->lock);
551 return TDM_ERROR_NONE;
555 tdm_output_remove_mode_change_request_handler(tdm_output *output,
556 tdm_output_mode_change_request_handler func,
559 tdm_private_display *private_display;
560 tdm_private_output *private_output;
561 tdm_private_output_mode_change_handler *mode_change_handler = NULL, *hh = NULL;
563 TDM_RETURN_VAL_IF_FAIL(output != NULL, TDM_ERROR_INVALID_PARAMETER);
564 TDM_RETURN_VAL_IF_FAIL(func != NULL, TDM_ERROR_INVALID_PARAMETER);
566 private_output = (tdm_private_output*)output;
567 private_display = private_output->private_display;
569 _pthread_mutex_lock(&private_display->lock);
571 LIST_FOR_EACH_ENTRY_SAFE(mode_change_handler, hh, &private_output->mode_change_request_handler_list, link) {
572 if (mode_change_handler->func != func || mode_change_handler->user_data != user_data)
575 LIST_DEL(&mode_change_handler->link);
576 free(mode_change_handler);
578 _pthread_mutex_unlock(&private_display->lock);
580 return TDM_ERROR_NONE;
583 _pthread_mutex_unlock(&private_display->lock);
585 return TDM_ERROR_INVALID_PARAMETER;
590 tdm_output_remove_change_handler(tdm_output *output,
591 tdm_output_change_handler func,
594 tdm_private_display *private_display;
595 tdm_private_output *private_output;
596 tdm_private_output_change_handler *change_handler = NULL, *hh = NULL;
598 TDM_RETURN_IF_FAIL(output != NULL);
599 TDM_RETURN_IF_FAIL(func != NULL);
601 private_output = (tdm_private_output*)output;
602 private_display = private_output->private_display;
604 _pthread_mutex_lock(&private_display->lock);
606 LIST_FOR_EACH_ENTRY_SAFE(change_handler, hh, &private_output->change_handler_list, link) {
607 if (change_handler->func != func || change_handler->user_data != user_data)
610 tdm_thread_cb_remove(private_output, TDM_THREAD_CB_OUTPUT_DPMS, NULL, tdm_output_thread_cb_change, change_handler);
611 tdm_thread_cb_remove(private_output, TDM_THREAD_CB_OUTPUT_STATUS, NULL, tdm_output_thread_cb_change, change_handler);
613 LIST_DEL(&change_handler->link);
614 free(change_handler);
616 _pthread_mutex_unlock(&private_display->lock);
621 _pthread_mutex_unlock(&private_display->lock);
625 tdm_output_get_output_type(tdm_output *output, tdm_output_type *type)
629 TDM_RETURN_VAL_IF_FAIL(type != NULL, TDM_ERROR_INVALID_PARAMETER);
631 _pthread_mutex_lock(&private_display->lock);
633 *type = private_output->caps.type;
635 _pthread_mutex_unlock(&private_display->lock);
641 tdm_output_get_layer_count(tdm_output *output, int *count)
643 tdm_private_layer *private_layer = NULL;
647 TDM_RETURN_VAL_IF_FAIL(count != NULL, TDM_ERROR_INVALID_PARAMETER);
649 _pthread_mutex_lock(&private_display->lock);
651 if (private_output->caps.capabilities & TDM_OUTPUT_CAPABILITY_HWC) {
652 TDM_ERR("output(%p) support HWC. Use HWC functions", private_output);
654 _pthread_mutex_unlock(&private_display->lock);
655 return TDM_ERROR_BAD_REQUEST;
659 LIST_FOR_EACH_ENTRY(private_layer, &private_output->layer_list, link)
662 _pthread_mutex_unlock(&private_display->lock);
663 return TDM_ERROR_NONE;
666 _pthread_mutex_unlock(&private_display->lock);
673 tdm_output_get_layer(tdm_output *output, int index, tdm_error *error)
675 tdm_private_layer *private_layer = NULL;
677 OUTPUT_FUNC_ENTRY_ERROR();
679 _pthread_mutex_lock(&private_display->lock);
682 *error = TDM_ERROR_NONE;
684 if (private_output->caps.capabilities & TDM_OUTPUT_CAPABILITY_HWC) {
685 _pthread_mutex_unlock(&private_display->lock);
686 TDM_ERR("output(%p) support HWC. Use HWC functions", private_output);
688 *error = TDM_ERROR_BAD_REQUEST;
692 LIST_FOR_EACH_ENTRY(private_layer, &private_output->layer_list, link) {
693 if (private_layer->index == index) {
694 _pthread_mutex_unlock(&private_display->lock);
695 return private_layer;
699 _pthread_mutex_unlock(&private_display->lock);
705 tdm_output_get_available_properties(tdm_output *output, const tdm_prop **props,
710 TDM_RETURN_VAL_IF_FAIL(props != NULL, TDM_ERROR_INVALID_PARAMETER);
711 TDM_RETURN_VAL_IF_FAIL(count != NULL, TDM_ERROR_INVALID_PARAMETER);
713 _pthread_mutex_lock(&private_display->lock);
715 *props = (const tdm_prop *)private_output->caps.props;
716 *count = private_output->caps.prop_count;
718 _pthread_mutex_unlock(&private_display->lock);
724 tdm_output_get_available_modes(tdm_output *output,
725 const tdm_output_mode **modes, int *count)
729 TDM_RETURN_VAL_IF_FAIL(modes != NULL, TDM_ERROR_INVALID_PARAMETER);
730 TDM_RETURN_VAL_IF_FAIL(count != NULL, TDM_ERROR_INVALID_PARAMETER);
732 _pthread_mutex_lock(&private_display->lock);
734 *modes = (const tdm_output_mode *)private_output->caps.modes;
735 *count = private_output->caps.mode_count;
737 _pthread_mutex_unlock(&private_display->lock);
743 tdm_output_get_available_size(tdm_output *output, int *min_w, int *min_h,
744 int *max_w, int *max_h, int *preferred_align)
748 _pthread_mutex_lock(&private_display->lock);
751 *min_w = TDM_FRONT_VALUE(private_output->caps.min_w);
753 *min_h = TDM_FRONT_VALUE(private_output->caps.min_h);
755 *max_w = TDM_FRONT_VALUE(private_output->caps.max_w);
757 *max_h = TDM_FRONT_VALUE(private_output->caps.max_h);
759 *preferred_align = TDM_FRONT_VALUE(private_output->caps.preferred_align);
761 _pthread_mutex_unlock(&private_display->lock);
767 tdm_output_get_cursor_available_size(tdm_output *output, int *min_w, int *min_h,
768 int *max_w, int *max_h, int *preferred_align)
772 _pthread_mutex_lock(&private_display->lock);
774 if (!tdm_module_check_abi(private_output->private_module, 1, 5)) {
775 _pthread_mutex_unlock(&private_display->lock);
776 return TDM_ERROR_BAD_REQUEST;
780 *min_w = TDM_FRONT_VALUE(private_output->caps.cursor_min_w);
782 *min_h = TDM_FRONT_VALUE(private_output->caps.cursor_min_h);
784 *max_w = TDM_FRONT_VALUE(private_output->caps.cursor_max_w);
786 *max_h = TDM_FRONT_VALUE(private_output->caps.cursor_max_h);
788 *preferred_align = TDM_FRONT_VALUE(private_output->caps.cursor_preferred_align);
790 _pthread_mutex_unlock(&private_display->lock);
796 tdm_output_get_physical_size(tdm_output *output, unsigned int *mmWidth,
797 unsigned int *mmHeight)
801 _pthread_mutex_lock(&private_display->lock);
804 *mmWidth = private_output->caps.mmWidth;
806 *mmHeight = private_output->caps.mmHeight;
808 _pthread_mutex_unlock(&private_display->lock);
814 tdm_output_get_subpixel(tdm_output *output, unsigned int *subpixel)
817 TDM_RETURN_VAL_IF_FAIL(subpixel != NULL, TDM_ERROR_INVALID_PARAMETER);
819 _pthread_mutex_lock(&private_display->lock);
821 *subpixel = private_output->caps.subpixel;
823 _pthread_mutex_unlock(&private_display->lock);
829 tdm_output_get_pipe(tdm_output *output, unsigned int *pipe)
832 TDM_RETURN_VAL_IF_FAIL(pipe != NULL, TDM_ERROR_INVALID_PARAMETER);
834 _pthread_mutex_lock(&private_display->lock);
836 *pipe = private_output->pipe;
838 _pthread_mutex_unlock(&private_display->lock);
844 tdm_output_get_primary_index(tdm_output *output, int *index)
846 tdm_private_layer *private_layer = NULL;
849 TDM_RETURN_VAL_IF_FAIL(index != NULL, TDM_ERROR_INVALID_PARAMETER);
851 _pthread_mutex_lock(&private_display->lock);
853 LIST_FOR_EACH_ENTRY(private_layer, &private_output->layer_list, link) {
854 if (private_layer->caps.capabilities & TDM_LAYER_CAPABILITY_PRIMARY) {
855 *index = private_layer->index;
860 _pthread_mutex_unlock(&private_display->lock);
866 tdm_output_set_property(tdm_output *output, unsigned int id, tdm_value value)
868 tdm_private_module *private_module;
869 tdm_func_output *func_output;
872 _pthread_mutex_lock(&private_display->lock);
874 private_module = private_output->private_module;
875 func_output = &private_module->func_output;
877 if (!func_output->output_set_property) {
878 /* LCOV_EXCL_START */
879 _pthread_mutex_unlock(&private_display->lock);
880 TDM_WRN("not implemented!!");
881 return TDM_ERROR_NOT_IMPLEMENTED;
885 ret = func_output->output_set_property(private_output->output_backend, id,
888 _pthread_mutex_unlock(&private_display->lock);
894 tdm_output_get_property(tdm_output *output, unsigned int id, tdm_value *value)
896 tdm_private_module *private_module;
897 tdm_func_output *func_output;
900 TDM_RETURN_VAL_IF_FAIL(value != NULL, TDM_ERROR_INVALID_PARAMETER);
902 _pthread_mutex_lock(&private_display->lock);
904 private_module = private_output->private_module;
905 func_output = &private_module->func_output;
907 if (!func_output->output_get_property) {
908 /* LCOV_EXCL_START */
909 _pthread_mutex_unlock(&private_display->lock);
910 TDM_WRN("not implemented!!");
911 return TDM_ERROR_NOT_IMPLEMENTED;
915 ret = func_output->output_get_property(private_output->output_backend, id,
918 _pthread_mutex_unlock(&private_display->lock);
924 _tdm_output_thread_cb_vblank(tdm_private_display *private_display, void *object, tdm_thread_cb_base *cb_base, void *user_data)
926 tdm_thread_cb_output_vblank *output_vblank = (tdm_thread_cb_output_vblank *)cb_base;
927 tdm_private_output_vblank_handler *vblank_handler = output_vblank->base.data;
928 tdm_private_output_vblank_handler *v = NULL, *vv = NULL;
929 tdm_private_output *private_output = object;
930 struct list_head clone_list;
932 pid_t tid = syscall(SYS_gettid);
934 TDM_RETURN_IF_FAIL(TDM_MUTEX_IS_LOCKED());
936 assert(vblank_handler->owner_tid == tid);
938 vblank_handler->sent_to_frontend = 0;
940 _tdm_output_vblank_timeout_update(private_output, 0);
942 tdm_thread_cb_remove(private_output, TDM_THREAD_CB_OUTPUT_VBLANK, vblank_handler, _tdm_output_thread_cb_vblank, NULL);
944 interval = vblank_handler->interval;
945 sync = vblank_handler->sync;
947 LIST_INITHEAD(&clone_list);
949 LIST_FOR_EACH_ENTRY_SAFE(v, vv, &private_output->vblank_handler_list, link) {
950 if (v->interval != interval || v->sync != sync || v->owner_tid != tid)
954 LIST_ADDTAIL(&v->link, &clone_list);
957 if (tdm_debug_module & TDM_DEBUG_COMMIT)
958 TDM_INFO("----------------------------------------- output(%d) got vblank", private_output->pipe);
960 _pthread_mutex_unlock(&private_display->lock);
961 LIST_FOR_EACH_ENTRY_SAFE(v, vv, &clone_list, link) {
962 if (tdm_debug_module & TDM_DEBUG_COMMIT)
963 TDM_INFO("handler(%p)", v);
968 v->func(v->private_output,
969 output_vblank->sequence,
970 output_vblank->tv_sec,
971 output_vblank->tv_usec,
976 _pthread_mutex_lock(&private_display->lock);
978 if (tdm_debug_module & TDM_DEBUG_COMMIT)
979 TDM_INFO("-----------------------------------------...");
983 _tdm_output_cb_vblank(tdm_output *output_backend, unsigned int sequence,
984 unsigned int tv_sec, unsigned int tv_usec, void *user_data)
986 tdm_private_output_vblank_handler *vblank_handler = user_data;
987 tdm_thread_cb_output_vblank output_vblank;
990 memset(&output_vblank, 0, sizeof output_vblank);
991 output_vblank.base.type = TDM_THREAD_CB_OUTPUT_VBLANK;
992 output_vblank.base.length = sizeof output_vblank;
993 output_vblank.base.object_stamp = vblank_handler->private_output->stamp;
994 output_vblank.base.data = vblank_handler;
995 output_vblank.base.sync = 0;
996 output_vblank.sequence = sequence;
997 output_vblank.tv_sec = tv_sec;
998 output_vblank.tv_usec = tv_usec;
1000 vblank_handler->sent_to_frontend = 1;
1002 if (tdm_debug_module & TDM_DEBUG_COMMIT)
1003 TDM_INFO("output(%d) wait_vblank: handler(%p)", vblank_handler->private_output->pipe, vblank_handler);
1005 ret = tdm_thread_cb_call(vblank_handler->private_output, &output_vblank.base, 1);
1006 TDM_WARNING_IF_FAIL(ret == TDM_ERROR_NONE);
1009 /* LCOV_EXCL_START */
1011 _tdm_output_thread_cb_commit(tdm_private_display *private_display, void *object, tdm_thread_cb_base *cb_base, void *user_data)
1013 tdm_thread_cb_output_commit *output_commit = (tdm_thread_cb_output_commit *)cb_base;
1014 tdm_private_output_commit_handler *output_commit_handler = output_commit->base.data;
1015 tdm_private_output *private_output = object;
1016 tdm_private_layer *private_layer = NULL;
1018 TDM_RETURN_IF_FAIL(TDM_MUTEX_IS_LOCKED());
1020 if (!output_commit_handler)
1023 assert(output_commit_handler->owner_tid == syscall(SYS_gettid));
1025 tdm_thread_cb_remove(private_output, TDM_THREAD_CB_OUTPUT_COMMIT, output_commit_handler, _tdm_output_thread_cb_commit, NULL);
1027 LIST_DEL(&output_commit_handler->link);
1029 if (tdm_debug_module & TDM_DEBUG_COMMIT) {
1030 TDM_INFO("----------------------------------------- output(%d) committed", private_output->pipe);
1031 TDM_INFO("handler(%p)", output_commit_handler);
1034 if (private_output->commit_type == TDM_COMMIT_TYPE_OUTPUT) {
1035 /* In case of layer commit, the below will be handled in the layer commit callback */
1036 LIST_FOR_EACH_ENTRY(private_layer, &private_output->layer_list, link) {
1037 if (private_layer->committed_buffer)
1038 tdm_layer_committed(private_layer, &private_layer->committed_buffer);
1042 if (output_commit_handler->func) {
1043 _pthread_mutex_unlock(&private_display->lock);
1044 output_commit_handler->func(private_output,
1045 output_commit->sequence,
1046 output_commit->tv_sec,
1047 output_commit->tv_usec,
1048 output_commit_handler->user_data);
1049 _pthread_mutex_lock(&private_display->lock);
1052 free(output_commit_handler);
1054 if (tdm_debug_module & TDM_DEBUG_COMMIT)
1055 TDM_INFO("-----------------------------------------...");
1059 _tdm_output_cb_commit(tdm_output *output_backend, unsigned int sequence,
1060 unsigned int tv_sec, unsigned int tv_usec, void *user_data)
1062 tdm_private_output_commit_handler *output_commit_handler = user_data;
1063 tdm_private_output *private_output;
1064 tdm_thread_cb_output_commit output_commit;
1067 if (output_commit_handler)
1068 private_output = output_commit_handler->private_output;
1070 private_output = tdm_display_find_private_output(tdm_display_get(), output_backend);
1072 memset(&output_commit, 0, sizeof output_commit);
1073 output_commit.base.type = TDM_THREAD_CB_OUTPUT_COMMIT;
1074 output_commit.base.length = sizeof output_commit;
1075 output_commit.base.object_stamp = private_output->stamp;
1076 output_commit.base.data = output_commit_handler;
1077 output_commit.base.sync = 0;
1078 output_commit.sequence = sequence;
1079 output_commit.tv_sec = tv_sec;
1080 output_commit.tv_usec = tv_usec;
1082 ret = tdm_thread_cb_call(private_output, &output_commit.base, 1);
1083 TDM_WARNING_IF_FAIL(ret == TDM_ERROR_NONE);
1085 /* LCOV_EXCL_STOP */
1087 /* LCOV_EXCL_START */
1089 _tdm_voutput_thread_cb_commit(tdm_private_display *private_display, void *object, tdm_thread_cb_base *cb_base, void *user_data)
1091 tdm_thread_cb_voutput_commit *voutput_commit = (tdm_thread_cb_voutput_commit *)cb_base;
1092 tdm_private_voutput_commit_handler *voutput_commit_handler = voutput_commit->base.data;
1093 tdm_private_voutput *private_voutput = object;
1094 tdm_private_output *private_output = NULL;
1096 TDM_RETURN_IF_FAIL(TDM_MUTEX_IS_LOCKED());
1098 if (!voutput_commit_handler)
1101 assert(voutput_commit_handler->owner_tid == syscall(SYS_gettid));
1103 tdm_thread_cb_remove(private_voutput, TDM_THREAD_CB_VOUTPUT_COMMIT, voutput_commit_handler, _tdm_voutput_thread_cb_commit, NULL);
1105 LIST_DEL(&voutput_commit_handler->link);
1107 private_output = private_voutput->private_output;
1108 if (tdm_debug_module & TDM_DEBUG_COMMIT) {
1109 TDM_INFO("----------------------------------------- voutput(%d) committed", private_output->pipe);
1110 TDM_INFO("handler(%p)", voutput_commit_handler);
1113 if (voutput_commit_handler->func && private_voutput->set_voutput_commit != 0) {
1114 _pthread_mutex_unlock(&private_display->lock);
1115 voutput_commit_handler->func(private_voutput, voutput_commit_handler->user_data);
1116 _pthread_mutex_lock(&private_display->lock);
1119 free(voutput_commit_handler);
1121 if (tdm_debug_module & TDM_DEBUG_COMMIT)
1122 TDM_INFO("-----------------------------------------...");
1126 _tdm_voutput_cb_commit(tdm_voutput *voutput_backend, unsigned int sequence,
1127 unsigned int tv_sec, unsigned int tv_usec, void *user_data)
1129 tdm_private_voutput_commit_handler *voutput_commit_handler = NULL;
1130 tdm_private_module *private_module;
1131 tdm_private_voutput *private_voutput = NULL, *v = NULL;
1132 tdm_private_output *private_output;
1133 tdm_thread_cb_voutput_commit voutput_commit;
1136 private_module = tdm_display_get()->virtual_module;
1138 LIST_FOR_EACH_ENTRY(v, &private_module->voutput_list, link) {
1139 if (v->voutput_backend == voutput_backend) {
1140 private_voutput = v;
1144 if (!private_voutput) {
1145 TDM_ERR("cannot find voutput");
1149 if (LIST_LENGTH(&private_voutput->voutput_commit_handler_list) == 0) return;
1151 voutput_commit_handler = LIST_FIRST_ENTRY(&private_voutput->voutput_commit_handler_list, tdm_private_voutput_commit_handler, link);
1153 private_output = private_voutput->private_output;
1155 memset(&voutput_commit, 0, sizeof voutput_commit);
1156 voutput_commit.base.type = TDM_THREAD_CB_VOUTPUT_COMMIT;
1157 voutput_commit.base.length = sizeof voutput_commit;
1158 voutput_commit.base.object_stamp = private_output->stamp;
1159 voutput_commit.base.data = voutput_commit_handler;
1160 voutput_commit.base.sync = 0;
1161 voutput_commit.sequence = sequence;
1162 voutput_commit.tv_sec = tv_sec;
1163 voutput_commit.tv_usec = tv_usec;
1165 ret = tdm_thread_cb_call(private_voutput, &voutput_commit.base, 1);
1166 TDM_WARNING_IF_FAIL(ret == TDM_ERROR_NONE);
1168 /* LCOV_EXCL_STOP */
1170 /* add_front: To distinguish between the user vblank handlers and the layer
1171 * commit vblank handlers. The layer commit handlers will be called
1172 * before calling the user vblank handlers.
1175 _tdm_output_wait_vblank(tdm_private_output *private_output, int interval, int sync,
1176 tdm_output_vblank_handler func, void *user_data,
1177 unsigned int add_front)
1179 tdm_private_module *private_module;
1180 tdm_func_output *func_output;
1181 tdm_private_output_vblank_handler *vblank_handler = NULL, *v = NULL;
1182 unsigned int skip_request = 0;
1183 pid_t tid = syscall(SYS_gettid);
1184 tdm_error ret = TDM_ERROR_NONE;
1186 private_module = private_output->private_module;
1187 func_output = &private_module->func_output;
1189 /* interval SHOULD be at least 1 */
1193 if (!func_output->output_wait_vblank) {
1194 /* LCOV_EXCL_START */
1195 TDM_WRN("not implemented!!");
1196 return TDM_ERROR_NOT_IMPLEMENTED;
1197 /* LCOV_EXCL_STOP */
1200 if (!private_output->regist_vblank_cb) {
1201 private_output->regist_vblank_cb = 1;
1202 ret = func_output->output_set_vblank_handler(private_output->output_backend,
1203 _tdm_output_cb_vblank);
1206 vblank_handler = calloc(1, sizeof(tdm_private_output_vblank_handler));
1207 if (!vblank_handler) {
1208 /* LCOV_EXCL_START */
1209 TDM_ERR("failed: alloc memory");
1210 return TDM_ERROR_OUT_OF_MEMORY;
1211 /* LCOV_EXCL_STOP */
1214 if (tdm_debug_module & TDM_DEBUG_COMMIT)
1215 TDM_INFO("output(%d) wait_vblank: handler(%p)", private_output->pipe, vblank_handler);
1217 LIST_FOR_EACH_ENTRY(v, &private_output->vblank_handler_list, link) {
1218 if (v->interval == interval && v->sync == sync && v->owner_tid == tid) {
1225 LIST_ADD(&vblank_handler->link, &private_output->vblank_handler_list);
1227 LIST_ADDTAIL(&vblank_handler->link, &private_output->vblank_handler_list);
1229 vblank_handler->private_output = private_output;
1230 vblank_handler->interval = interval;
1231 vblank_handler->sync = sync;
1232 vblank_handler->func = func;
1233 vblank_handler->user_data = user_data;
1234 vblank_handler->owner_tid = tid;
1236 /* If there is the previous request, we can skip to call output_wait_vblank() */
1237 if (!skip_request) {
1238 ret = tdm_thread_cb_add(private_output, TDM_THREAD_CB_OUTPUT_VBLANK, vblank_handler, _tdm_output_thread_cb_vblank, NULL);
1239 if (ret != TDM_ERROR_NONE) {
1240 TDM_ERR("tdm_thread_cb_add failed");
1244 ret = func_output->output_wait_vblank(private_output->output_backend, interval,
1245 sync, vblank_handler);
1246 TDM_GOTO_IF_FAIL(ret == TDM_ERROR_NONE, wait_failed);
1248 _tdm_output_vblank_timeout_update(private_output, 1000);
1250 if (tdm_debug_module & TDM_DEBUG_COMMIT)
1251 TDM_INFO("output(%d) backend wait_vblank", private_output->pipe);
1257 /* LCOV_EXCL_START */
1258 if (vblank_handler) {
1259 tdm_thread_cb_remove(private_output, TDM_THREAD_CB_OUTPUT_VBLANK, vblank_handler, _tdm_output_thread_cb_vblank, NULL);
1260 LIST_DEL(&vblank_handler->link);
1261 free(vblank_handler);
1264 /* LCOV_EXCL_STOP */
1268 tdm_output_wait_vblank(tdm_output *output, int interval, int sync,
1269 tdm_output_vblank_handler func, void *user_data)
1271 OUTPUT_FUNC_ENTRY();
1272 TDM_RETURN_VAL_IF_FAIL(interval > 0, TDM_ERROR_INVALID_PARAMETER);
1274 _pthread_mutex_lock(&private_display->lock);
1276 if (TDM_OUTPUT_DPMS_VSYNC_IS_OFF(private_output->current_dpms_value)) {
1277 TDM_WRN("output(%d) dpms: %s", private_output->pipe,
1278 tdm_dpms_str(private_output->current_dpms_value));
1279 _pthread_mutex_unlock(&private_display->lock);
1280 return TDM_ERROR_DPMS_OFF;
1283 if (private_output->waiting_dpms_change) {
1284 TDM_WRN("output(%d) dpms is changing: %s", private_output->pipe,
1285 tdm_dpms_str(private_output->current_dpms_value));
1286 _pthread_mutex_unlock(&private_display->lock);
1287 return TDM_ERROR_DPMS_OFF;
1290 ret = _tdm_output_wait_vblank(private_output, interval, sync, func, user_data, 0);
1292 _pthread_mutex_unlock(&private_display->lock);
1297 /* LCOV_EXCL_START */
1299 tdm_output_wait_vblank_add_front(tdm_output *output, int interval, int sync,
1300 tdm_output_vblank_handler func, void *user_data)
1302 OUTPUT_FUNC_ENTRY();
1304 _pthread_mutex_lock(&private_display->lock);
1306 if (TDM_OUTPUT_DPMS_VSYNC_IS_OFF(private_output->current_dpms_value)) {
1307 TDM_WRN("output(%d) dpms: %s", private_output->pipe,
1308 tdm_dpms_str(private_output->current_dpms_value));
1309 _pthread_mutex_unlock(&private_display->lock);
1310 return TDM_ERROR_DPMS_OFF;
1313 if (private_output->waiting_dpms_change) {
1314 TDM_WRN("output(%d) dpms is changing: %s", private_output->pipe,
1315 tdm_dpms_str(private_output->current_dpms_value));
1316 _pthread_mutex_unlock(&private_display->lock);
1317 return TDM_ERROR_DPMS_OFF;
1320 ret = _tdm_output_wait_vblank(private_output, interval, sync, func, user_data, 1);
1322 _pthread_mutex_unlock(&private_display->lock);
1326 /* LCOV_EXCL_STOP */
1329 tdm_output_remove_vblank_handler_internal(tdm_output *output, tdm_output_vblank_handler func, void *user_data)
1331 tdm_private_output *private_output = (tdm_private_output*)output;
1332 tdm_private_output_vblank_handler *v = NULL;
1334 TDM_RETURN_IF_FAIL(private_output != NULL);
1335 TDM_RETURN_IF_FAIL(TDM_MUTEX_IS_LOCKED());
1337 LIST_FOR_EACH_ENTRY(v, &private_output->vblank_handler_list, link) {
1338 if (v->func == func && v->user_data == user_data) {
1339 /* only set func & user_data to NULL. It will be freed when an event occurs */
1341 v->user_data = NULL;
1347 /* LCOV_EXCL_START */
1349 tdm_output_remove_commit_handler_internal(tdm_output *output, tdm_output_commit_handler func, void *user_data)
1351 tdm_private_output *private_output = (tdm_private_output*)output;
1352 tdm_private_output_commit_handler *c = NULL;
1354 TDM_RETURN_IF_FAIL(private_output != NULL);
1355 TDM_RETURN_IF_FAIL(TDM_MUTEX_IS_LOCKED());
1357 LIST_FOR_EACH_ENTRY(c, &private_output->output_commit_handler_list, link) {
1358 if (c->func == func && c->user_data == user_data) {
1359 /* only set func & user_data to NULL. It will be freed when an event occurs */
1361 c->user_data = NULL;
1366 /* LCOV_EXCL_STOP */
1369 tdm_output_remove_vblank_handler(tdm_output *output, tdm_output_vblank_handler func, void *user_data)
1371 OUTPUT_FUNC_ENTRY();
1373 _pthread_mutex_lock(&private_display->lock);
1375 tdm_output_remove_vblank_handler_internal(output, func, user_data);
1377 _pthread_mutex_unlock(&private_display->lock);
1382 /* LCOV_EXCL_START */
1384 tdm_output_remove_commit_handler(tdm_output *output, tdm_output_commit_handler func, void *user_data)
1386 OUTPUT_FUNC_ENTRY();
1388 _pthread_mutex_lock(&private_display->lock);
1390 tdm_output_remove_commit_handler_internal(output, func, user_data);
1392 _pthread_mutex_unlock(&private_display->lock);
1396 /* LCOV_EXCL_STOP */
1398 /* LCOV_EXCL_START */
1400 tdm_output_request_mode_set(tdm_output *output, unsigned int index)
1402 tdm_private_output *private_output = (tdm_private_output*)output;
1403 tdm_private_output_mode_change_handler *mode_change_handler = NULL;
1405 TDM_RETURN_IF_FAIL(private_output != NULL);
1407 if (LIST_IS_EMPTY(&private_output->mode_change_request_handler_list))
1410 LIST_FOR_EACH_ENTRY(mode_change_handler, &private_output->mode_change_request_handler_list, link) {
1411 mode_change_handler->func(mode_change_handler->private_output, index, mode_change_handler->user_data);
1416 _voutput_commit_func(tdm_voutput *voutput, tbm_surface_h buffer)
1418 tdm_private_voutput *private_voutput = (tdm_private_voutput *)voutput;
1421 TDM_RETURN_IF_FAIL(voutput != NULL);
1422 TDM_RETURN_IF_FAIL(buffer != NULL);
1424 ret = tdm_voutput_attach_buffer(private_voutput, buffer);
1425 TDM_RETURN_IF_FAIL(ret == TDM_ERROR_NONE);
1426 ret = tdm_voutput_commit_buffer(private_voutput);
1427 TDM_RETURN_IF_FAIL(ret == TDM_ERROR_NONE);
1433 tdm_output_set_voutput_commit(tdm_voutput *voutput)
1435 tdm_private_display *private_display;
1436 tdm_private_output *private_output;
1437 tdm_private_voutput *private_voutput;
1438 tdm_private_voutput_commit_handler *voutput_commit_handler = NULL;
1439 tdm_error ret = TDM_ERROR_NONE;
1441 TDM_RETURN_VAL_IF_FAIL(voutput != NULL, TDM_ERROR_INVALID_PARAMETER);
1443 private_voutput = (tdm_private_voutput *)voutput;
1444 private_display = private_voutput->private_display;
1445 private_output = (tdm_private_output *)private_voutput->private_output;
1447 _pthread_mutex_lock(&private_display->lock);
1449 if (LIST_LENGTH(&private_voutput->voutput_commit_handler_list) != 0) {
1450 _pthread_mutex_unlock(&private_display->lock);
1454 if (!private_voutput->regist_commit_cb) {
1455 private_voutput->regist_commit_cb = 1;
1456 ret = tdm_voutput_set_commit_func(private_voutput, _tdm_voutput_cb_commit);
1457 if (ret != TDM_ERROR_NONE) {
1458 TDM_ERR("failed: tdm_voutput_set_commit_func");
1459 _pthread_mutex_unlock(&private_display->lock);
1464 voutput_commit_handler = calloc(1, sizeof(tdm_private_voutput_commit_handler));
1465 if (!voutput_commit_handler) {
1466 TDM_ERR("failed: alloc memory");
1467 _pthread_mutex_unlock(&private_display->lock);
1468 return TDM_ERROR_OUT_OF_MEMORY;
1471 ret = tdm_thread_cb_add(private_output->private_voutput, TDM_THREAD_CB_VOUTPUT_COMMIT, voutput_commit_handler, _tdm_voutput_thread_cb_commit, NULL);
1472 if (ret != TDM_ERROR_NONE) {
1473 TDM_ERR("tdm_thread_cb_add failed");
1474 free(voutput_commit_handler);
1475 _pthread_mutex_unlock(&private_display->lock);
1479 LIST_ADDTAIL(&voutput_commit_handler->link, &private_voutput->voutput_commit_handler_list);
1480 voutput_commit_handler->private_voutput = private_voutput;
1481 voutput_commit_handler->func = _voutput_commit_func;
1482 voutput_commit_handler->owner_tid = syscall(SYS_gettid);
1484 private_voutput->set_voutput_commit = 1;
1486 _pthread_mutex_unlock(&private_display->lock);
1492 tdm_output_unset_voutput_commit(tdm_voutput *voutput)
1494 tdm_private_display *private_display;
1495 tdm_private_output *private_output;
1496 tdm_private_voutput *private_voutput;
1497 tdm_private_voutput_commit_handler *voutput_commit_handler = NULL;
1498 tdm_error ret = TDM_ERROR_NONE;
1500 TDM_RETURN_VAL_IF_FAIL(voutput != NULL, TDM_ERROR_INVALID_PARAMETER);
1502 private_voutput = (tdm_private_voutput *)voutput;
1503 private_display = private_voutput->private_display;
1504 private_output = (tdm_private_output *)private_voutput->private_output;
1506 _pthread_mutex_lock(&private_display->lock);
1508 private_voutput->set_voutput_commit = 0;
1510 if (private_voutput->regist_commit_cb) {
1511 private_voutput->regist_commit_cb = 0;
1512 ret = tdm_voutput_set_commit_func(private_voutput, NULL);
1513 if (ret != TDM_ERROR_NONE) {
1514 TDM_ERR("failed: tdm_voutput_set_commit_func");
1515 _pthread_mutex_unlock(&private_display->lock);
1520 if (LIST_LENGTH(&private_voutput->voutput_commit_handler_list) == 0) {
1521 _pthread_mutex_unlock(&private_display->lock);
1522 return TDM_ERROR_NONE;
1525 if (LIST_LENGTH(&private_output->output_commit_handler_list) != 0) {
1526 //commiting. don't remove voutput commit thread here
1527 _pthread_mutex_unlock(&private_display->lock);
1528 return TDM_ERROR_NONE;
1531 if (LIST_LENGTH(&private_voutput->voutput_commit_handler_list) != 0) {
1532 voutput_commit_handler = LIST_FIRST_ENTRY(&private_voutput->voutput_commit_handler_list, tdm_private_voutput_commit_handler, link);
1534 _pthread_mutex_unlock(&private_display->lock);
1535 return TDM_ERROR_NONE;
1538 tdm_thread_cb_remove(private_output->private_voutput, TDM_THREAD_CB_VOUTPUT_COMMIT, voutput_commit_handler, _tdm_voutput_thread_cb_commit, NULL);
1540 _pthread_mutex_unlock(&private_display->lock);
1542 return TDM_ERROR_NONE;
1544 /* LCOV_EXCL_STOP */
1546 /* LCOV_EXCL_START */
1548 tdm_output_commit_internal(tdm_output *output, int sync, tdm_output_commit_handler func, void *user_data)
1550 tdm_private_display *private_display;
1551 tdm_private_output *private_output;
1552 tdm_private_voutput *private_voutput;
1553 tdm_private_module *private_module;
1554 tdm_func_output *func_output;
1555 tdm_private_output_commit_handler *output_commit_handler = NULL;
1556 tdm_private_voutput_commit_handler *voutput_commit_handler = NULL;
1557 tdm_private_layer *private_layer = NULL;
1558 tdm_output_dpms dpms_value = TDM_OUTPUT_DPMS_ON;
1559 tdm_error ret = TDM_ERROR_NONE;
1561 TDM_RETURN_VAL_IF_FAIL(output != NULL, TDM_ERROR_INVALID_PARAMETER);
1563 private_output = (tdm_private_output*)output;
1564 private_module = private_output->private_module;
1565 private_display = private_module->private_display;
1566 func_output = &private_module->func_output;
1568 if (!func_output->output_commit) {
1569 TDM_WRN("not implemented!!");
1570 return TDM_ERROR_NOT_IMPLEMENTED;
1573 ret = tdm_output_get_dpms_internal(output, &dpms_value);
1574 TDM_RETURN_VAL_IF_FAIL(ret == TDM_ERROR_NONE, ret);
1576 if (!TDM_OUTPUT_DPMS_VSYNC_IS_OFF(dpms_value)) {
1577 if (!private_output->regist_commit_cb) {
1578 private_output->regist_commit_cb = 1;
1579 ret = func_output->output_set_commit_handler(private_output->output_backend, _tdm_output_cb_commit);
1580 TDM_GOTO_IF_FAIL(ret == TDM_ERROR_NONE, commit_failed);
1583 output_commit_handler = calloc(1, sizeof(tdm_private_output_commit_handler));
1584 if (!output_commit_handler) {
1585 TDM_ERR("failed: alloc memory");
1586 return TDM_ERROR_OUT_OF_MEMORY;
1589 if (private_module == private_display->virtual_module) {
1590 if (!private_output->private_voutput) {
1591 TDM_ERR("virtual module but don't have voutput");
1592 free(output_commit_handler);
1593 return TDM_ERROR_BAD_MODULE;
1597 ret = tdm_thread_cb_add(private_output, TDM_THREAD_CB_OUTPUT_COMMIT, output_commit_handler, _tdm_output_thread_cb_commit, NULL);
1598 if (ret != TDM_ERROR_NONE) {
1599 TDM_ERR("tdm_thread_cb_add failed");
1600 free(output_commit_handler);
1604 LIST_ADDTAIL(&output_commit_handler->link, &private_output->output_commit_handler_list);
1605 output_commit_handler->private_output = private_output;
1606 output_commit_handler->func = func;
1607 output_commit_handler->user_data = user_data;
1608 output_commit_handler->owner_tid = syscall(SYS_gettid);
1610 if (private_module == private_display->virtual_module) {
1611 private_voutput = private_output->private_voutput;
1613 /* voutput use only 1 layer */
1614 private_layer = LIST_FIRST_ENTRY(&private_output->layer_list, tdm_private_layer, link);
1616 if (LIST_LENGTH(&private_voutput->voutput_commit_handler_list) != 0) {
1617 voutput_commit_handler = LIST_FIRST_ENTRY(&private_voutput->voutput_commit_handler_list, tdm_private_voutput_commit_handler, link);
1618 voutput_commit_handler->user_data = private_layer->commiting_buffer;
1622 ret = func_output->output_commit(private_output->output_backend, sync,
1623 output_commit_handler);
1624 TDM_GOTO_IF_FAIL(ret == TDM_ERROR_NONE, commit_failed);
1626 if (tdm_debug_module & TDM_DEBUG_COMMIT)
1627 TDM_INFO("output(%d) backend commit: handle(%p) func(%p) user_data(%p)",
1628 private_output->pipe, output_commit_handler, func, user_data);
1631 /* Even if DPMS is off, committed_buffer should be changed because it will be referred
1632 * for tdm_layer_committed() function.
1634 LIST_FOR_EACH_ENTRY(private_layer, &private_output->layer_list, link) {
1635 if (!private_layer->waiting_buffer)
1638 if (private_layer->committed_buffer) {
1639 tdm_layer_free_buffer(private_layer, private_layer->committed_buffer);
1640 private_layer->committed_buffer = NULL;
1641 if (tdm_debug_module & TDM_DEBUG_BUFFER)
1642 TDM_INFO("layer(%p) waiting_buffer(%p) committed_buffer(%p)",
1643 private_layer, private_layer->waiting_buffer->buffer,
1644 private_layer->committed_buffer);
1647 private_layer->committed_buffer = private_layer->waiting_buffer;
1648 private_layer->waiting_buffer = NULL;
1649 private_layer->commiting_buffer = NULL;
1650 if (tdm_debug_module & TDM_DEBUG_BUFFER)
1651 TDM_INFO("layer(%p) waiting_buffer(%p) committed_buffer(%p)",
1652 private_layer, private_layer->waiting_buffer,
1653 private_layer->committed_buffer->buffer);
1656 if (TDM_OUTPUT_DPMS_VSYNC_IS_OFF(dpms_value)) {
1657 TDM_WRN("dpms %s. Directly call commit handler instead of commit.", tdm_dpms_str(dpms_value));
1659 _pthread_mutex_unlock(&private_display->lock);
1660 func(output, 0, 0, 0, user_data);
1661 _pthread_mutex_lock(&private_display->lock);
1668 if (output_commit_handler) {
1669 tdm_thread_cb_remove(private_output, TDM_THREAD_CB_OUTPUT_COMMIT, output_commit_handler, _tdm_output_thread_cb_commit, NULL);
1670 LIST_DEL(&output_commit_handler->link);
1671 free(output_commit_handler);
1678 tdm_output_commit(tdm_output *output, int sync, tdm_output_commit_handler func,
1681 tdm_private_layer *private_layer = NULL;
1683 OUTPUT_FUNC_ENTRY();
1685 _pthread_mutex_lock(&private_display->lock);
1687 if (private_output->commit_type == TDM_COMMIT_TYPE_NONE)
1688 private_output->commit_type = TDM_COMMIT_TYPE_OUTPUT;
1689 else if (private_output->commit_type == TDM_COMMIT_TYPE_LAYER) {
1690 TDM_ERR("Can't supported. Use tdm_layer_commit");
1691 _pthread_mutex_unlock(&private_display->lock);
1692 return TDM_ERROR_BAD_REQUEST;
1695 if (private_output->commit_per_vblank) {
1696 TDM_ERR("Use tdm_layer_commit");
1697 _pthread_mutex_unlock(&private_display->lock);
1698 return TDM_ERROR_BAD_REQUEST;
1701 if (TDM_OUTPUT_DPMS_VSYNC_IS_OFF(private_output->current_dpms_value)) {
1702 TDM_ERR("output(%d) dpms: %s", private_output->pipe,
1703 tdm_dpms_str(private_output->current_dpms_value));
1704 _pthread_mutex_unlock(&private_display->lock);
1705 return TDM_ERROR_DPMS_OFF;
1708 if (tdm_debug_module & TDM_DEBUG_COMMIT)
1709 TDM_INFO("output(%d) commit", private_output->pipe);
1711 /* apply the pending data of all layers */
1712 LIST_FOR_EACH_ENTRY(private_layer, &private_output->layer_list, link) {
1713 tdm_layer_commit_pending_data(private_layer);
1716 ret = tdm_output_commit_internal(output, sync, func, user_data);
1718 _pthread_mutex_unlock(&private_display->lock);
1722 /* LCOV_EXCL_STOP */
1725 tdm_output_set_mode(tdm_output *output, const tdm_output_mode *mode)
1727 tdm_private_module *private_module;
1728 tdm_func_output *func_output;
1729 OUTPUT_FUNC_ENTRY();
1731 TDM_RETURN_VAL_IF_FAIL(mode != NULL, TDM_ERROR_INVALID_PARAMETER);
1733 _pthread_mutex_lock(&private_display->lock);
1735 private_module = private_output->private_module;
1736 func_output = &private_module->func_output;
1738 if (!func_output->output_set_mode) {
1739 /* LCOV_EXCL_START */
1740 _pthread_mutex_unlock(&private_display->lock);
1741 TDM_WRN("not implemented!!");
1742 return TDM_ERROR_NOT_IMPLEMENTED;
1743 /* LCOV_EXCL_STOP */
1746 ret = func_output->output_set_mode(private_output->output_backend, mode);
1747 if (ret == TDM_ERROR_NONE) {
1748 private_output->current_mode = mode;
1749 private_output->need_set_target_info = 1;
1750 TDM_INFO("mode: %dx%d %dhz", mode->hdisplay, mode->vdisplay, mode->vrefresh);
1753 _pthread_mutex_unlock(&private_display->lock);
1759 tdm_output_get_mode(tdm_output *output, const tdm_output_mode **mode)
1761 OUTPUT_FUNC_ENTRY();
1763 TDM_RETURN_VAL_IF_FAIL(mode != NULL, TDM_ERROR_INVALID_PARAMETER);
1765 _pthread_mutex_lock(&private_display->lock);
1767 *mode = private_output->current_mode;
1769 _pthread_mutex_unlock(&private_display->lock);
1775 tdm_output_set_dpms(tdm_output *output, tdm_output_dpms dpms_value)
1777 tdm_private_module *private_module;
1778 tdm_func_output *func_output;
1779 OUTPUT_FUNC_ENTRY();
1781 if (dpms_value > TDM_OUTPUT_DPMS_OFF) {
1782 if (dpms_value & TDM_OUTPUT_DPMS_DEFAULT_MASK) {
1783 TDM_ERR("Don't use the low-4bit for an extended DPMS mode: dpms_value(%x)", dpms_value);
1784 return TDM_ERROR_BAD_REQUEST;
1787 if (!(private_output->caps.capabilities & TDM_OUTPUT_CAPABILITY_EXTENDED_DPMS)) {
1788 TDM_ERR("output(%d) doesn't support the extended DPMS control: '%s'",
1789 private_output->pipe, tdm_dpms_str(dpms_value));
1790 return TDM_ERROR_BAD_REQUEST;
1794 _pthread_mutex_lock(&private_display->lock);
1796 if (private_output->waiting_dpms_change) {
1797 TDM_ERR("DPMS is not changed yet. Can't be changed twice");
1798 _pthread_mutex_unlock(&private_display->lock);
1799 return TDM_ERROR_BAD_REQUEST;
1802 private_module = private_output->private_module;
1803 func_output = &private_module->func_output;
1805 TDM_INFO("output(%d) DPMS '%s'", private_output->pipe, tdm_dpms_str(dpms_value));
1807 if (func_output->output_set_dpms)
1808 ret = func_output->output_set_dpms(private_output->output_backend, dpms_value);
1810 /* LCOV_EXCL_START */
1811 ret = TDM_ERROR_NONE;
1812 TDM_WRN("DPMS not implemented!!");
1814 /* LCOV_EXCL_STOP */
1818 if (ret == TDM_ERROR_NONE) {
1819 if (private_output->current_dpms_value != dpms_value) {
1820 private_output->current_dpms_value = dpms_value;
1821 _tdm_output_call_thread_cb_dpms(private_output, dpms_value);
1823 TDM_INFO("output(%d) DPMS '%s' done", private_output->pipe, tdm_dpms_str(dpms_value));
1825 tdm_output_dpms temp = TDM_OUTPUT_DPMS_OFF;
1827 /* update current_dpms_value forcely */
1828 tdm_output_get_dpms_internal(output, &temp);
1830 TDM_ERR("output(%d) set DPMS failed: dpms '%s'", private_output->pipe, tdm_dpms_str(temp));
1833 _pthread_mutex_unlock(&private_display->lock);
1838 /* LCOV_EXCL_START */
1840 tdm_output_set_dpms_async(tdm_output *output, tdm_output_dpms dpms_value)
1842 tdm_private_module *private_module;
1843 tdm_func_output *func_output;
1845 OUTPUT_FUNC_ENTRY();
1847 if (!(private_output->caps.capabilities & TDM_OUTPUT_CAPABILITY_ASYNC_DPMS)) {
1848 TDM_ERR("output doesn't support the asynchronous DPMS control!");
1849 return TDM_ERROR_BAD_REQUEST;
1852 if (dpms_value > TDM_OUTPUT_DPMS_OFF) {
1853 if (dpms_value & TDM_OUTPUT_DPMS_DEFAULT_MASK) {
1854 TDM_ERR("Don't use the low-4bit for an extended DPMS mode: dpms_value(%x)", dpms_value);
1855 return TDM_ERROR_BAD_REQUEST;
1858 if (!(private_output->caps.capabilities & TDM_OUTPUT_CAPABILITY_EXTENDED_DPMS)) {
1859 TDM_ERR("output(%d) doesn't support the extended DPMS control: '%s'",
1860 private_output->pipe, tdm_dpms_str(dpms_value));
1861 return TDM_ERROR_BAD_REQUEST;
1865 _pthread_mutex_lock(&private_display->lock);
1867 if (private_output->waiting_dpms_change) {
1868 TDM_ERR("DPMS is not changed yet. Can't be changed twice");
1869 _pthread_mutex_unlock(&private_display->lock);
1870 return TDM_ERROR_BAD_REQUEST;
1873 private_module = private_output->private_module;
1874 func_output = &private_module->func_output;
1875 if (!func_output->output_set_dpms_handler) {
1876 TDM_WRN("not implemented DPMS: output_set_dpms_handler");
1877 _pthread_mutex_unlock(&private_display->lock);
1878 return TDM_ERROR_NOT_IMPLEMENTED;
1881 if (!func_output->output_set_dpms_async) {
1882 TDM_WRN("not implemented DPMS: output_set_dpms_async");
1883 _pthread_mutex_unlock(&private_display->lock);
1884 return TDM_ERROR_NOT_IMPLEMENTED;
1887 if (!private_output->regist_dpms_cb) {
1888 private_output->regist_dpms_cb = 1;
1889 ret = func_output->output_set_dpms_handler(private_output->output_backend,
1890 tdm_output_cb_dpms, private_output);
1891 if (ret != TDM_ERROR_NONE) {
1892 _pthread_mutex_unlock(&private_display->lock);
1893 TDM_ERR("Can't set the DPMS handler!!");
1898 TDM_INFO("output(%d) DPMS async '%s'", private_output->pipe, tdm_dpms_str(dpms_value));
1900 ret = func_output->output_set_dpms_async(private_output->output_backend, dpms_value, &sync);
1902 if (ret == TDM_ERROR_NONE) {
1904 tdm_output_dpms temp = TDM_OUTPUT_DPMS_OFF;
1906 tdm_output_get_dpms_internal(output, &temp);
1907 TDM_INFO("output(%d) DPMS async '%s'(%s) done", private_output->pipe, tdm_dpms_str(dpms_value), tdm_dpms_str(temp));
1909 private_output->waiting_dpms_change = 1;
1910 TDM_INFO("output(%d) DPMS async '%s' waiting", private_output->pipe, tdm_dpms_str(dpms_value));
1913 tdm_output_dpms temp = TDM_OUTPUT_DPMS_OFF;
1915 /* update current_dpms_value forcely */
1916 tdm_output_get_dpms_internal(output, &temp);
1918 TDM_ERR("output(%d) set DPMS async failed: dpms '%s'", private_output->pipe, tdm_dpms_str(temp));
1921 _pthread_mutex_unlock(&private_display->lock);
1925 /* LCOV_EXCL_STOP */
1928 tdm_output_get_dpms_internal(tdm_output *output, tdm_output_dpms *dpms_value)
1930 tdm_private_output *private_output;
1931 tdm_private_module *private_module;
1932 tdm_func_output *func_output;
1933 tdm_error ret = TDM_ERROR_NONE;
1935 TDM_RETURN_VAL_IF_FAIL(output != NULL, TDM_ERROR_INVALID_PARAMETER);
1937 private_output = (tdm_private_output*)output;
1939 /* TODO: this is ugly. But before calling backend's output_get_dpms(), we have
1940 * to check if all backends's DPMS operation has no problem. In future, we'd
1941 * better use new env instead of using commit_per_vblank variable to distinguish
1942 * whether we use the stored value or backend's output_get_dpms.
1944 if (!private_output->commit_per_vblank) {
1945 *dpms_value = private_output->current_dpms_value;
1946 return TDM_ERROR_NONE;
1949 private_module = private_output->private_module;
1950 func_output = &private_module->func_output;
1952 if (!func_output->output_get_dpms) {
1953 /* LCOV_EXCL_START */
1954 *dpms_value = private_output->current_dpms_value;
1955 TDM_WRN("DPMS get not implemented!!");
1956 return TDM_ERROR_NONE;
1957 /* LCOV_EXCL_STOP */
1960 ret = func_output->output_get_dpms(private_output->output_backend, dpms_value);
1961 if (ret != TDM_ERROR_NONE) {
1962 /* LCOV_EXCL_START */
1963 TDM_ERR("output get DPMS failed");
1964 *dpms_value = TDM_OUTPUT_DPMS_OFF;
1965 /* LCOV_EXCL_STOP */
1968 /* checking with backend's value */
1969 if (*dpms_value != private_output->current_dpms_value) {
1970 TDM_ERR("output(%d) DPMS changed suddenly: %s -> %s",
1971 private_output->pipe, tdm_dpms_str(private_output->current_dpms_value),
1972 tdm_dpms_str(*dpms_value));
1973 private_output->current_dpms_value = *dpms_value;
1974 _tdm_output_call_thread_cb_dpms(private_output, *dpms_value);
1981 tdm_output_get_dpms_changing(tdm_output *output, int *changing)
1983 tdm_private_output *private_output;
1985 TDM_RETURN_VAL_IF_FAIL(output != NULL, TDM_ERROR_INVALID_PARAMETER);
1986 TDM_RETURN_VAL_IF_FAIL(changing != NULL, TDM_ERROR_INVALID_PARAMETER);
1988 private_output = (tdm_private_output*)output;
1990 *changing = private_output->waiting_dpms_change;
1992 return TDM_ERROR_NONE;
1997 tdm_output_get_dpms(tdm_output *output, tdm_output_dpms *dpms_value)
1999 OUTPUT_FUNC_ENTRY();
2001 TDM_RETURN_VAL_IF_FAIL(dpms_value != NULL, TDM_ERROR_INVALID_PARAMETER);
2003 _pthread_mutex_lock(&private_display->lock);
2005 ret = tdm_output_get_dpms_internal(output, dpms_value);
2007 _pthread_mutex_unlock(&private_display->lock);
2013 tdm_output_has_capture_capability(tdm_output *output, unsigned int *has_capability)
2015 tdm_private_module *private_module;
2017 OUTPUT_FUNC_ENTRY();
2019 TDM_RETURN_VAL_IF_FAIL(has_capability != NULL, TDM_ERROR_INVALID_PARAMETER);
2021 _pthread_mutex_lock(&private_display->lock);
2023 private_module = private_output->private_module;
2025 if (!(private_module->capabilities & TDM_DISPLAY_CAPABILITY_CAPTURE))
2026 *has_capability = 0;
2027 else if (!(private_module->caps_capture.capabilities & TDM_CAPTURE_CAPABILITY_OUTPUT))
2028 *has_capability = 0;
2030 *has_capability = 1;
2032 _pthread_mutex_unlock(&private_display->lock);
2037 EXTERN tdm_capture *
2038 tdm_output_create_capture(tdm_output *output, tdm_error *error)
2040 tdm_capture *capture = NULL;
2042 OUTPUT_FUNC_ENTRY_ERROR();
2044 _pthread_mutex_lock(&private_display->lock);
2046 capture = (tdm_capture *)tdm_capture_create_output_internal(private_output, error);
2048 _pthread_mutex_unlock(&private_display->lock);
2054 tdm_output_get_hwc(tdm_output *output, tdm_error *error)
2056 tdm_private_hwc *private_hwc = NULL;
2058 OUTPUT_FUNC_ENTRY_ERROR();
2060 _pthread_mutex_lock(&private_display->lock);
2062 private_hwc = private_output->private_hwc;
2065 *error = TDM_ERROR_BAD_REQUEST;
2066 _pthread_mutex_unlock(&private_display->lock);
2071 *error = TDM_ERROR_NONE;
2073 _pthread_mutex_unlock(&private_display->lock);
2079 tdm_output_set_mirror(tdm_output *output, tdm_output *src_output, tdm_transform transform)
2081 /* LCOV_EXCL_START */
2082 tdm_private_module *private_module;
2083 tdm_func_output *func_output;
2084 tdm_private_output *private_src_output;
2086 OUTPUT_FUNC_ENTRY();
2088 TDM_RETURN_VAL_IF_FAIL(src_output != NULL, TDM_ERROR_INVALID_PARAMETER);
2090 _pthread_mutex_lock(&private_display->lock);
2092 private_module = private_output->private_module;
2093 func_output = &private_module->func_output;
2094 private_src_output = (tdm_private_output*)src_output;
2096 if (!(private_output->caps.capabilities & TDM_OUTPUT_CAPABILITY_MIRROR)) {
2097 TDM_INFO("output(%d) doesn't support the mirror.", private_output->pipe);
2098 _pthread_mutex_unlock(&private_display->lock);
2099 return TDM_ERROR_BAD_REQUEST;
2102 if (!func_output->output_set_mirror) {
2103 TDM_WRN("not implemented!!");
2104 _pthread_mutex_unlock(&private_display->lock);
2105 return TDM_ERROR_NOT_IMPLEMENTED;
2108 ret = func_output->output_set_mirror(private_output->output_backend,
2109 private_src_output->output_backend,
2111 if (ret != TDM_ERROR_NONE) {
2112 TDM_ERR("output(%p) fails to set MIRROR.", private_output);
2113 _pthread_mutex_unlock(&private_display->lock);
2114 return TDM_ERROR_BAD_REQUEST;
2117 _pthread_mutex_unlock(&private_display->lock);
2120 /* LCOV_EXCL_STOP */
2124 tdm_output_unset_mirror(tdm_output *output)
2126 /* LCOV_EXCL_START */
2127 tdm_private_module *private_module;
2128 tdm_func_output *func_output;
2130 OUTPUT_FUNC_ENTRY();
2132 _pthread_mutex_lock(&private_display->lock);
2134 private_module = private_output->private_module;
2135 func_output = &private_module->func_output;
2137 if (!(private_output->caps.capabilities & TDM_OUTPUT_CAPABILITY_MIRROR)) {
2138 TDM_INFO("output(%d) doesn't support the mirror.", private_output->pipe);
2139 _pthread_mutex_unlock(&private_display->lock);
2140 return TDM_ERROR_BAD_REQUEST;
2143 if (!func_output->output_unset_mirror) {
2144 TDM_WRN("not implemented!!");
2145 _pthread_mutex_unlock(&private_display->lock);
2146 return TDM_ERROR_NOT_IMPLEMENTED;
2149 ret = func_output->output_unset_mirror(private_output->output_backend);
2150 if (ret != TDM_ERROR_NONE) {
2151 TDM_ERR("output(%p) fails to unset MIRROR.", private_output);
2152 _pthread_mutex_unlock(&private_display->lock);
2153 return TDM_ERROR_BAD_REQUEST;
2156 _pthread_mutex_unlock(&private_display->lock);
2159 /* LCOV_EXCL_STOP */
2163 tdm_output_choose_commit_per_vblank_mode(tdm_private_output *private_output, int mode)
2165 if (!private_output)
2166 return TDM_ERROR_INVALID_PARAMETER;
2168 if (mode < 0 || mode > 2)
2169 return TDM_ERROR_INVALID_PARAMETER;
2171 private_output->commit_per_vblank = mode;
2173 if (private_output->commit_per_vblank == 0)
2174 TDM_INFO("commit per vblank: disable");
2175 else if (private_output->commit_per_vblank == 1)
2176 TDM_INFO("commit per vblank: enable (1 layer)");
2177 else if (private_output->commit_per_vblank == 2)
2178 TDM_INFO("commit per vblank: enable (previous commit)");
2180 return TDM_ERROR_NONE;
2183 /* LCOV_EXCL_START */
2185 tdm_voutput_destroy(tdm_voutput *voutput)
2187 tdm_private_module *private_module = NULL;
2188 tdm_voutput *voutput_backend = NULL;
2189 tdm_func_voutput *func_voutput = NULL;
2191 tdm_private_display *private_display;
2192 tdm_private_voutput *private_voutput;
2193 tdm_private_output *private_output;
2194 tdm_error ret = TDM_ERROR_NONE;
2195 TDM_RETURN_VAL_IF_FAIL(voutput != NULL, TDM_ERROR_INVALID_PARAMETER);
2196 private_voutput = (tdm_private_voutput*)voutput;
2197 private_display = private_voutput->private_display;
2198 private_module = private_voutput->private_module;
2199 TDM_RETURN_VAL_IF_FAIL(private_module == private_display->virtual_module, TDM_ERROR_BAD_MODULE);
2201 _pthread_mutex_lock(&private_display->lock);
2203 func_voutput = &private_module->func_voutput;
2204 voutput_backend = private_voutput->voutput_backend;
2205 private_output = private_voutput->private_output;
2206 tdm_display_destroy_private_output(private_output);
2207 LIST_DEL(&private_voutput->link);
2208 free(private_voutput);
2209 if (func_voutput->voutput_destroy)
2210 ret = func_voutput->voutput_destroy(voutput_backend);
2212 _pthread_mutex_unlock(&private_display->lock);
2218 tdm_voutput_set_available_mode(tdm_voutput *voutput, const tdm_output_mode *modes, int count)
2220 tdm_private_display *private_display;
2221 tdm_private_module *private_module = NULL;
2222 tdm_private_voutput *private_voutput;
2223 tdm_func_voutput *func_voutput = NULL;
2224 tdm_error ret = TDM_ERROR_NONE;
2226 TDM_RETURN_VAL_IF_FAIL(voutput != NULL, TDM_ERROR_INVALID_PARAMETER);
2227 TDM_RETURN_VAL_IF_FAIL(modes != NULL, TDM_ERROR_INVALID_PARAMETER);
2228 TDM_RETURN_VAL_IF_FAIL(count != 0, TDM_ERROR_INVALID_PARAMETER);
2230 private_voutput = (tdm_private_voutput*)voutput;
2231 private_display = private_voutput->private_display;
2232 private_module = private_voutput->private_module;
2233 TDM_RETURN_VAL_IF_FAIL(private_module == private_display->virtual_module, TDM_ERROR_BAD_MODULE);
2235 _pthread_mutex_lock(&private_display->lock);
2237 func_voutput = &private_module->func_voutput;
2238 if (func_voutput->voutput_set_available_mode)
2239 ret = func_voutput->voutput_set_available_mode(private_voutput->voutput_backend, modes, count);
2241 ret = TDM_ERROR_NOT_IMPLEMENTED;
2243 _pthread_mutex_unlock(&private_display->lock);
2249 tdm_voutput_set_physical_size(tdm_voutput *voutput, unsigned int mmwidth, unsigned int mmheight)
2251 tdm_private_display *private_display;
2252 tdm_private_module *private_module = NULL;
2253 tdm_private_voutput *private_voutput;
2254 tdm_func_voutput *func_voutput = NULL;
2255 tdm_error ret = TDM_ERROR_NONE;
2257 TDM_RETURN_VAL_IF_FAIL(voutput != NULL, TDM_ERROR_INVALID_PARAMETER);
2258 TDM_RETURN_VAL_IF_FAIL(mmwidth != 0, TDM_ERROR_INVALID_PARAMETER);
2259 TDM_RETURN_VAL_IF_FAIL(mmheight != 0, TDM_ERROR_INVALID_PARAMETER);
2261 private_voutput = (tdm_private_voutput*)voutput;
2262 private_display = private_voutput->private_display;
2263 private_module = private_voutput->private_module;
2264 TDM_RETURN_VAL_IF_FAIL(private_module == private_display->virtual_module, TDM_ERROR_BAD_MODULE);
2266 _pthread_mutex_lock(&private_display->lock);
2268 func_voutput = &private_module->func_voutput;
2269 if (func_voutput->voutput_set_physical_size)
2270 ret = func_voutput->voutput_set_physical_size(private_voutput->voutput_backend, mmwidth, mmheight);
2272 ret = TDM_ERROR_NOT_IMPLEMENTED;
2274 _pthread_mutex_unlock(&private_display->lock);
2280 tdm_voutput_connect(tdm_voutput *voutput)
2282 tdm_private_display *private_display;
2283 tdm_private_module *private_module = NULL;
2284 tdm_private_voutput *private_voutput;
2285 tdm_func_voutput *func_voutput = NULL;
2286 tdm_error ret = TDM_ERROR_NONE;
2288 TDM_RETURN_VAL_IF_FAIL(voutput != NULL, TDM_ERROR_INVALID_PARAMETER);
2290 private_voutput = (tdm_private_voutput*)voutput;
2291 private_display = private_voutput->private_display;
2292 private_module = private_voutput->private_module;
2293 TDM_RETURN_VAL_IF_FAIL(private_module == private_display->virtual_module, TDM_ERROR_BAD_MODULE);
2295 _pthread_mutex_lock(&private_display->lock);
2297 func_voutput = &private_module->func_voutput;
2298 if (func_voutput->voutput_connect)
2299 ret = func_voutput->voutput_connect(private_voutput->voutput_backend);
2301 ret = TDM_ERROR_NOT_IMPLEMENTED;
2303 _pthread_mutex_unlock(&private_display->lock);
2309 tdm_voutput_disconnect(tdm_voutput *voutput)
2311 tdm_private_display *private_display;
2312 tdm_private_module *private_module = NULL;
2313 tdm_private_voutput *private_voutput;
2314 tdm_func_voutput *func_voutput = NULL;
2315 tdm_error ret = TDM_ERROR_NONE;
2317 TDM_RETURN_VAL_IF_FAIL(voutput != NULL, TDM_ERROR_INVALID_PARAMETER);
2319 private_voutput = (tdm_private_voutput*)voutput;
2320 private_display = private_voutput->private_display;
2321 private_module = private_voutput->private_module;
2322 TDM_RETURN_VAL_IF_FAIL(private_module == private_display->virtual_module, TDM_ERROR_BAD_MODULE);
2324 _pthread_mutex_lock(&private_display->lock);
2326 func_voutput = &private_module->func_voutput;
2327 if (func_voutput->voutput_disconnect)
2328 ret = func_voutput->voutput_disconnect(private_voutput->voutput_backend);
2330 ret = TDM_ERROR_NOT_IMPLEMENTED;
2332 _pthread_mutex_unlock(&private_display->lock);
2338 tdm_voutput_set_commit_func(tdm_voutput *voutput, tdm_voutput_commit_handler func)
2340 tdm_private_display *private_display;
2341 tdm_private_module *private_module = NULL;
2342 tdm_private_voutput *private_voutput;
2343 tdm_func_voutput *func_voutput = NULL;
2344 tdm_error ret = TDM_ERROR_NONE;
2346 TDM_RETURN_VAL_IF_FAIL(voutput != NULL, TDM_ERROR_INVALID_PARAMETER);
2348 private_voutput = (tdm_private_voutput*)voutput;
2349 private_display = private_voutput->private_display;
2350 private_module = private_voutput->private_module;
2351 TDM_RETURN_VAL_IF_FAIL(private_module == private_display->virtual_module, TDM_ERROR_BAD_MODULE);
2353 func_voutput = &private_module->func_voutput;
2354 if (func_voutput->voutput_set_commit_func)
2355 ret = func_voutput->voutput_set_commit_func(private_voutput->voutput_backend, func);
2357 ret = TDM_ERROR_NOT_IMPLEMENTED;
2363 tdm_voutput_commit_done(tdm_voutput *voutput)
2365 tdm_private_display *private_display;
2366 tdm_private_module *private_module = NULL;
2367 tdm_private_voutput *private_voutput;
2368 tdm_func_voutput *func_voutput = NULL;
2369 tdm_error ret = TDM_ERROR_NONE;
2371 TDM_RETURN_VAL_IF_FAIL(voutput != NULL, TDM_ERROR_INVALID_PARAMETER);
2373 private_voutput = (tdm_private_voutput*)voutput;
2374 private_display = private_voutput->private_display;
2375 private_module = private_voutput->private_module;
2376 TDM_RETURN_VAL_IF_FAIL(private_module == private_display->virtual_module, TDM_ERROR_BAD_MODULE);
2378 _pthread_mutex_lock(&private_display->lock);
2380 func_voutput = &private_module->func_voutput;
2381 if (func_voutput->voutput_commit_done)
2382 ret = func_voutput->voutput_commit_done(private_voutput->voutput_backend);
2384 ret = TDM_ERROR_NOT_IMPLEMENTED;
2386 _pthread_mutex_unlock(&private_display->lock);
2390 /* LCOV_EXCL_STOP */