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 **************************************************************************/
41 #include "tdm_backend.h"
42 #include "tdm_private.h"
43 #include "tdm_helper.h"
47 #define OUTPUT_FUNC_ENTRY() \
48 tdm_private_display *private_display; \
49 tdm_private_output *private_output; \
50 tdm_error ret = TDM_ERROR_NONE; /* default TDM_ERROR_NONE */\
51 TDM_RETURN_VAL_IF_FAIL(output != NULL, TDM_ERROR_INVALID_PARAMETER); \
52 private_output = (tdm_private_output*)output; \
53 private_display = private_output->private_display
55 #define OUTPUT_FUNC_ENTRY_ERROR() \
56 tdm_private_display *private_display; \
57 tdm_private_output *private_output; \
58 tdm_error ret = TDM_ERROR_NONE; /* default TDM_ERROR_NONE */\
59 TDM_RETURN_VAL_IF_FAIL_WITH_ERROR(output != NULL, TDM_ERROR_INVALID_PARAMETER, NULL); \
60 private_output = (tdm_private_output*)output; \
61 private_display = private_output->private_display
64 tdm_output_get_model_info(tdm_output *output, const char **maker,
65 const char **model, const char **name)
69 _pthread_mutex_lock(&private_display->lock);
72 *maker = private_output->caps.maker;
74 *model = private_output->caps.model;
76 *name = private_output->caps.name;
78 _pthread_mutex_unlock(&private_display->lock);
84 tdm_output_get_capabilities(tdm_output *output, tdm_output_capability *capabilities)
88 TDM_RETURN_VAL_IF_FAIL(capabilities != NULL, TDM_ERROR_INVALID_PARAMETER);
90 _pthread_mutex_lock(&private_display->lock);
92 *capabilities = private_output->caps.capabilities;
94 _pthread_mutex_unlock(&private_display->lock);
100 tdm_output_get_conn_status(tdm_output *output, tdm_output_conn_status *status)
104 TDM_RETURN_VAL_IF_FAIL(status != NULL, TDM_ERROR_INVALID_PARAMETER);
106 _pthread_mutex_lock(&private_display->lock);
108 *status = private_output->caps.status;
110 _pthread_mutex_unlock(&private_display->lock);
116 _tdm_output_update(tdm_output *output_backend, void *user_data)
118 tdm_private_display *private_display;
119 tdm_private_output *private_output = user_data;
122 TDM_RETURN_IF_FAIL(private_output);
124 private_display = private_output->private_display;
126 ret = tdm_display_update_output(private_display, output_backend, private_output->pipe);
127 TDM_RETURN_IF_FAIL(ret == TDM_ERROR_NONE);
131 tdm_output_cb_status(tdm_output *output_backend, tdm_output_conn_status status,
134 tdm_private_display *private_display;
135 tdm_private_output *private_output = user_data;
138 TDM_RETURN_IF_FAIL(TDM_MUTEX_IS_LOCKED());
139 TDM_RETURN_IF_FAIL(private_output);
141 private_display = private_output->private_display;
143 if (!tdm_thread_in_display_thread(syscall(SYS_gettid))) {
144 tdm_thread_cb_output_status output_status;
147 TDM_INFO("output(%d) %s", private_output->pipe, tdm_status_str(status));
149 _tdm_output_update(output_backend, user_data);
151 output_status.base.type = TDM_THREAD_CB_OUTPUT_STATUS;
152 output_status.base.length = sizeof output_status;
153 output_status.output_stamp = private_output->stamp;
154 output_status.status = status;
155 output_status.user_data = user_data;
158 tdm_output_call_change_handler_internal(private_output,
159 &private_output->change_handler_list_sub,
160 TDM_OUTPUT_CHANGE_CONNECTION,
163 ret = tdm_thread_send_cb(private_display->private_loop, &output_status.base);
164 TDM_WARNING_IF_FAIL(ret == TDM_ERROR_NONE);
169 TDM_INFO("output(%d) %s", private_output->pipe, tdm_status_str(status));
171 if (!tdm_thread_is_running())
172 _tdm_output_update(output_backend, user_data);
175 tdm_output_call_change_handler_internal(private_output,
176 &private_output->change_handler_list_main,
177 TDM_OUTPUT_CHANGE_CONNECTION,
182 tdm_output_add_change_handler(tdm_output *output,
183 tdm_output_change_handler func,
186 tdm_private_change_handler *change_handler;
189 TDM_RETURN_VAL_IF_FAIL(func != NULL, TDM_ERROR_INVALID_PARAMETER);
191 _pthread_mutex_lock(&private_display->lock);
193 change_handler = calloc(1, sizeof(tdm_private_change_handler));
194 if (!change_handler) {
195 TDM_ERR("failed: alloc memory");
196 _pthread_mutex_unlock(&private_display->lock);
197 return TDM_ERROR_OUT_OF_MEMORY;
200 change_handler->private_output = private_output;
201 change_handler->func = func;
202 change_handler->user_data = user_data;
203 change_handler->owner_tid = syscall(SYS_gettid);
205 if (!tdm_thread_in_display_thread(change_handler->owner_tid))
206 LIST_ADDTAIL(&change_handler->link, &private_output->change_handler_list_sub);
208 LIST_ADDTAIL(&change_handler->link, &private_output->change_handler_list_main);
210 _pthread_mutex_unlock(&private_display->lock);
216 tdm_output_remove_change_handler(tdm_output *output,
217 tdm_output_change_handler func,
220 tdm_private_display *private_display;
221 tdm_private_output *private_output;
222 tdm_private_change_handler *h = NULL, *hh = NULL;
224 TDM_RETURN_IF_FAIL(output != NULL);
225 TDM_RETURN_IF_FAIL(func != NULL);
227 private_output = (tdm_private_output*)output;
228 private_display = private_output->private_display;
230 _pthread_mutex_lock(&private_display->lock);
232 LIST_FOR_EACH_ENTRY_SAFE(h, hh, &private_output->change_handler_list_main, link) {
233 if (h->func != func || h->user_data != user_data)
239 _pthread_mutex_unlock(&private_display->lock);
244 LIST_FOR_EACH_ENTRY_SAFE(h, hh, &private_output->change_handler_list_sub, link) {
245 if (h->func != func || h->user_data != user_data)
251 _pthread_mutex_unlock(&private_display->lock);
256 _pthread_mutex_unlock(&private_display->lock);
260 tdm_output_get_output_type(tdm_output *output, tdm_output_type *type)
264 TDM_RETURN_VAL_IF_FAIL(type != NULL, TDM_ERROR_INVALID_PARAMETER);
266 _pthread_mutex_lock(&private_display->lock);
268 *type = private_output->caps.type;
270 _pthread_mutex_unlock(&private_display->lock);
276 tdm_output_get_layer_count(tdm_output *output, int *count)
278 tdm_private_layer *private_layer = NULL;
282 TDM_RETURN_VAL_IF_FAIL(count != NULL, TDM_ERROR_INVALID_PARAMETER);
284 _pthread_mutex_lock(&private_display->lock);
287 LIST_FOR_EACH_ENTRY(private_layer, &private_output->layer_list, link)
290 _pthread_mutex_unlock(&private_display->lock);
291 return TDM_ERROR_NONE;
294 _pthread_mutex_unlock(&private_display->lock);
301 tdm_output_get_layer(tdm_output *output, int index, tdm_error *error)
303 tdm_private_layer *private_layer = NULL;
305 OUTPUT_FUNC_ENTRY_ERROR();
307 _pthread_mutex_lock(&private_display->lock);
310 *error = TDM_ERROR_NONE;
312 LIST_FOR_EACH_ENTRY(private_layer, &private_output->layer_list, link) {
313 if (private_layer->index == index) {
314 _pthread_mutex_unlock(&private_display->lock);
315 return private_layer;
319 _pthread_mutex_unlock(&private_display->lock);
325 tdm_output_get_available_properties(tdm_output *output, const tdm_prop **props,
330 TDM_RETURN_VAL_IF_FAIL(props != NULL, TDM_ERROR_INVALID_PARAMETER);
331 TDM_RETURN_VAL_IF_FAIL(count != NULL, TDM_ERROR_INVALID_PARAMETER);
333 _pthread_mutex_lock(&private_display->lock);
335 *props = (const tdm_prop *)private_output->caps.props;
336 *count = private_output->caps.prop_count;
338 _pthread_mutex_unlock(&private_display->lock);
344 tdm_output_get_available_modes(tdm_output *output,
345 const tdm_output_mode **modes, int *count)
349 TDM_RETURN_VAL_IF_FAIL(modes != NULL, TDM_ERROR_INVALID_PARAMETER);
350 TDM_RETURN_VAL_IF_FAIL(count != NULL, TDM_ERROR_INVALID_PARAMETER);
352 _pthread_mutex_lock(&private_display->lock);
354 *modes = (const tdm_output_mode *)private_output->caps.modes;
355 *count = private_output->caps.mode_count;
357 _pthread_mutex_unlock(&private_display->lock);
363 tdm_output_get_available_size(tdm_output *output, int *min_w, int *min_h,
364 int *max_w, int *max_h, int *preferred_align)
368 _pthread_mutex_lock(&private_display->lock);
371 *min_w = TDM_FRONT_VALUE(private_output->caps.min_w);
373 *min_h = TDM_FRONT_VALUE(private_output->caps.min_h);
375 *max_w = TDM_FRONT_VALUE(private_output->caps.max_w);
377 *max_h = TDM_FRONT_VALUE(private_output->caps.max_h);
379 *preferred_align = TDM_FRONT_VALUE(private_output->caps.preferred_align);
381 _pthread_mutex_unlock(&private_display->lock);
387 tdm_output_get_cursor_available_size(tdm_output *output, int *min_w, int *min_h,
388 int *max_w, int *max_h, int *preferred_align)
392 _pthread_mutex_lock(&private_display->lock);
394 if (!tdm_display_check_module_abi(private_display, 1, 5)) {
405 *preferred_align = -1;
407 _pthread_mutex_unlock(&private_display->lock);
409 return TDM_ERROR_BAD_MODULE;
413 *min_w = TDM_FRONT_VALUE(private_output->caps.cursor_min_w);
415 *min_h = TDM_FRONT_VALUE(private_output->caps.cursor_min_h);
417 *max_w = TDM_FRONT_VALUE(private_output->caps.cursor_max_w);
419 *max_h = TDM_FRONT_VALUE(private_output->caps.cursor_max_h);
421 *preferred_align = TDM_FRONT_VALUE(private_output->caps.cursor_preferred_align);
423 _pthread_mutex_unlock(&private_display->lock);
429 tdm_output_get_physical_size(tdm_output *output, unsigned int *mmWidth,
430 unsigned int *mmHeight)
434 _pthread_mutex_lock(&private_display->lock);
437 *mmWidth = private_output->caps.mmWidth;
439 *mmHeight = private_output->caps.mmHeight;
441 _pthread_mutex_unlock(&private_display->lock);
447 tdm_output_get_subpixel(tdm_output *output, unsigned int *subpixel)
450 TDM_RETURN_VAL_IF_FAIL(subpixel != NULL, TDM_ERROR_INVALID_PARAMETER);
452 _pthread_mutex_lock(&private_display->lock);
454 *subpixel = private_output->caps.subpixel;
456 _pthread_mutex_unlock(&private_display->lock);
462 tdm_output_get_pipe(tdm_output *output, unsigned int *pipe)
465 TDM_RETURN_VAL_IF_FAIL(pipe != NULL, TDM_ERROR_INVALID_PARAMETER);
467 _pthread_mutex_lock(&private_display->lock);
469 *pipe = private_output->pipe;
471 _pthread_mutex_unlock(&private_display->lock);
477 tdm_output_get_primary_index(tdm_output *output, int *index)
479 tdm_private_layer *private_layer = NULL;
482 TDM_RETURN_VAL_IF_FAIL(index != NULL, TDM_ERROR_INVALID_PARAMETER);
484 _pthread_mutex_lock(&private_display->lock);
486 LIST_FOR_EACH_ENTRY(private_layer, &private_output->layer_list, link) {
487 if (private_layer->caps.capabilities & TDM_LAYER_CAPABILITY_PRIMARY) {
488 *index = private_layer->index;
493 _pthread_mutex_unlock(&private_display->lock);
499 tdm_output_set_property(tdm_output *output, unsigned int id, tdm_value value)
501 tdm_func_output *func_output;
504 _pthread_mutex_lock(&private_display->lock);
506 func_output = &private_display->func_output;
508 if (!func_output->output_set_property) {
509 _pthread_mutex_unlock(&private_display->lock);
510 TDM_ERR("not implemented!!");
511 return TDM_ERROR_NOT_IMPLEMENTED;
514 ret = func_output->output_set_property(private_output->output_backend, id,
517 _pthread_mutex_unlock(&private_display->lock);
523 tdm_output_get_property(tdm_output *output, unsigned int id, tdm_value *value)
525 tdm_func_output *func_output;
528 TDM_RETURN_VAL_IF_FAIL(value != NULL, TDM_ERROR_INVALID_PARAMETER);
530 _pthread_mutex_lock(&private_display->lock);
532 func_output = &private_display->func_output;
534 if (!func_output->output_get_property) {
535 _pthread_mutex_unlock(&private_display->lock);
536 TDM_ERR("not implemented!!");
537 return TDM_ERROR_NOT_IMPLEMENTED;
540 ret = func_output->output_get_property(private_output->output_backend, id,
543 _pthread_mutex_unlock(&private_display->lock);
549 tdm_output_cb_vblank(tdm_output *output_backend, unsigned int sequence,
550 unsigned int tv_sec, unsigned int tv_usec, void *user_data)
552 tdm_private_vblank_handler *vblank_handler = user_data;
553 tdm_private_vblank_handler *v = NULL, *vv = NULL;
554 tdm_private_output *private_output;
555 tdm_private_display *private_display;
556 struct list_head clone_list;
558 pid_t tid = syscall(SYS_gettid);
560 TDM_RETURN_IF_FAIL(TDM_MUTEX_IS_LOCKED());
561 TDM_RETURN_IF_FAIL(vblank_handler);
563 private_output = vblank_handler->private_output;
564 private_display = private_output->private_display;
566 if (vblank_handler->owner_tid != tid) {
567 tdm_thread_cb_output_vblank output_vblank;
570 output_vblank.base.type = TDM_THREAD_CB_OUTPUT_VBLANK;
571 output_vblank.base.length = sizeof output_vblank;
572 output_vblank.output_stamp = vblank_handler->private_output->stamp;
573 output_vblank.sequence = sequence;
574 output_vblank.tv_sec = tv_sec;
575 output_vblank.tv_usec = tv_usec;
576 output_vblank.user_data = user_data;
578 ret = tdm_thread_send_cb(private_display->private_loop, &output_vblank.base);
579 TDM_WARNING_IF_FAIL(ret == TDM_ERROR_NONE);
584 if (vblank_handler->owner_tid != tid)
585 TDM_NEVER_GET_HERE();
587 interval = vblank_handler->interval;
588 sync = vblank_handler->sync;
590 LIST_INITHEAD(&clone_list);
592 LIST_FOR_EACH_ENTRY_SAFE(v, vv, &private_output->vblank_handler_list, link) {
593 if (v->interval != interval || v->sync != sync || v->owner_tid != tid)
597 LIST_ADDTAIL(&v->link, &clone_list);
600 if (tdm_debug_module & TDM_DEBUG_COMMIT)
601 TDM_INFO("----------------------------------------- output(%d) got vblank", private_output->pipe);
603 _pthread_mutex_unlock(&private_display->lock);
604 LIST_FOR_EACH_ENTRY_SAFE(v, vv, &clone_list, link) {
605 if (tdm_debug_module & TDM_DEBUG_COMMIT)
606 TDM_INFO("handler(%p)", v);
611 v->func(v->private_output, sequence, tv_sec, tv_usec, v->user_data);
615 _pthread_mutex_lock(&private_display->lock);
617 if (tdm_debug_module & TDM_DEBUG_COMMIT)
618 TDM_INFO("-----------------------------------------...");
622 tdm_output_cb_commit(tdm_output *output_backend, unsigned int sequence,
623 unsigned int tv_sec, unsigned int tv_usec, void *user_data)
625 tdm_private_output_commit_handler *output_commit_handler = user_data;
626 tdm_private_display *private_display;
627 tdm_private_output *private_output;
628 tdm_private_layer *private_layer = NULL;
630 TDM_RETURN_IF_FAIL(TDM_MUTEX_IS_LOCKED());
632 if (!output_commit_handler)
635 private_output = output_commit_handler->private_output;
636 private_display = private_output->private_display;
638 if (output_commit_handler->owner_tid != syscall(SYS_gettid)) {
639 tdm_thread_cb_output_commit output_commit;
642 output_commit.base.type = TDM_THREAD_CB_OUTPUT_COMMIT;
643 output_commit.base.length = sizeof output_commit;
644 output_commit.output_stamp = private_output->stamp;
645 output_commit.sequence = sequence;
646 output_commit.tv_sec = tv_sec;
647 output_commit.tv_usec = tv_usec;
648 output_commit.user_data = user_data;
650 ret = tdm_thread_send_cb(private_display->private_loop, &output_commit.base);
651 TDM_WARNING_IF_FAIL(ret == TDM_ERROR_NONE);
656 LIST_DEL(&output_commit_handler->link);
658 if (tdm_debug_module & TDM_DEBUG_COMMIT) {
659 TDM_INFO("----------------------------------------- output(%d) committed", private_output->pipe);
660 TDM_INFO("handler(%p)", output_commit_handler);
663 if (private_display->commit_type == TDM_COMMIT_TYPE_OUTPUT) {
664 /* In case of layer commit, the below will be handled in the layer commit callback */
665 LIST_FOR_EACH_ENTRY(private_layer, &private_output->layer_list, link) {
666 if (private_layer->committed_buffer)
667 tdm_layer_committed(private_layer, &private_layer->committed_buffer);
671 if (output_commit_handler->func) {
672 _pthread_mutex_unlock(&private_display->lock);
673 output_commit_handler->func(private_output, sequence,
674 tv_sec, tv_usec, output_commit_handler->user_data);
675 _pthread_mutex_lock(&private_display->lock);
678 free(output_commit_handler);
680 if (tdm_debug_module & TDM_DEBUG_COMMIT)
681 TDM_INFO("-----------------------------------------...");
684 /* add_front: To distinguish between the user vblank handlers and the layer
685 * commit vblank handlers. The layer commit handlers will be called
686 * before calling the user vblank handlers.
689 _tdm_output_wait_vblank(tdm_output *output, int interval, int sync,
690 tdm_output_vblank_handler func, void *user_data,
691 unsigned int add_front)
693 tdm_func_output *func_output;
694 tdm_private_vblank_handler *vblank_handler = NULL, *v = NULL;
695 unsigned int skip_request = 0;
696 pid_t tid = syscall(SYS_gettid);
700 func_output = &private_display->func_output;
702 /* interval SHOULD be at least 1 */
706 if (!func_output->output_wait_vblank) {
707 TDM_ERR("not implemented!!");
708 return TDM_ERROR_NOT_IMPLEMENTED;
711 if (!private_output->regist_vblank_cb) {
712 private_output->regist_vblank_cb = 1;
713 ret = func_output->output_set_vblank_handler(private_output->output_backend,
714 tdm_output_cb_vblank);
717 vblank_handler = calloc(1, sizeof(tdm_private_vblank_handler));
718 if (!vblank_handler) {
719 TDM_ERR("failed: alloc memory");
720 return TDM_ERROR_OUT_OF_MEMORY;
723 if (tdm_debug_module & TDM_DEBUG_COMMIT)
724 TDM_INFO("output(%d) wait_vblank: handler(%p)", private_output->pipe, vblank_handler);
726 LIST_FOR_EACH_ENTRY(v, &private_output->vblank_handler_list, link) {
727 if (v->interval == interval && v->sync == sync && v->owner_tid == tid) {
734 LIST_ADD(&vblank_handler->link, &private_output->vblank_handler_list);
736 LIST_ADDTAIL(&vblank_handler->link, &private_output->vblank_handler_list);
738 vblank_handler->private_output = private_output;
739 vblank_handler->interval = interval;
740 vblank_handler->sync = sync;
741 vblank_handler->func = func;
742 vblank_handler->user_data = user_data;
743 vblank_handler->owner_tid = tid;
745 /* If there is the previous request, we can skip to call output_wait_vblank() */
747 ret = func_output->output_wait_vblank(private_output->output_backend, interval,
748 sync, vblank_handler);
749 TDM_GOTO_IF_FAIL(ret == TDM_ERROR_NONE, wait_failed);
751 if (tdm_debug_module & TDM_DEBUG_COMMIT)
752 TDM_INFO("output(%d) backend wait_vblank", private_output->pipe);
758 if (vblank_handler) {
759 LIST_DEL(&vblank_handler->link);
760 free(vblank_handler);
766 tdm_output_wait_vblank(tdm_output *output, int interval, int sync,
767 tdm_output_vblank_handler func, void *user_data)
771 _pthread_mutex_lock(&private_display->lock);
773 if (private_output->current_dpms_value > TDM_OUTPUT_DPMS_ON) {
774 TDM_WRN("output(%d) dpms: %s", private_output->pipe,
775 tdm_dpms_str(private_output->current_dpms_value));
776 _pthread_mutex_unlock(&private_display->lock);
777 return TDM_ERROR_DPMS_OFF;
780 ret = _tdm_output_wait_vblank(output, interval, sync, func, user_data, 0);
782 _pthread_mutex_unlock(&private_display->lock);
788 tdm_output_wait_vblank_add_front(tdm_output *output, int interval, int sync,
789 tdm_output_vblank_handler func, void *user_data)
793 _pthread_mutex_lock(&private_display->lock);
795 if (private_output->current_dpms_value > TDM_OUTPUT_DPMS_ON) {
796 TDM_WRN("output(%d) dpms: %s", private_output->pipe,
797 tdm_dpms_str(private_output->current_dpms_value));
798 _pthread_mutex_unlock(&private_display->lock);
799 return TDM_ERROR_DPMS_OFF;
802 ret = _tdm_output_wait_vblank(output, interval, sync, func, user_data, 1);
804 _pthread_mutex_unlock(&private_display->lock);
810 tdm_output_remove_vblank_handler_internal(tdm_output *output, tdm_output_vblank_handler func, void *user_data)
812 tdm_private_output *private_output = (tdm_private_output*)output;
813 tdm_private_vblank_handler *v = NULL;
815 TDM_RETURN_IF_FAIL(private_output != NULL);
816 TDM_RETURN_IF_FAIL(TDM_MUTEX_IS_LOCKED());
818 LIST_FOR_EACH_ENTRY(v, &private_output->vblank_handler_list, link) {
819 if (v->func == func && v->user_data == user_data) {
820 /* only set func & user_data to NULL. It will be freed when an event occurs */
829 tdm_output_remove_commit_handler_internal(tdm_output *output, tdm_output_commit_handler func, void *user_data)
831 tdm_private_output *private_output = (tdm_private_output*)output;
832 tdm_private_output_commit_handler *c = NULL;
834 TDM_RETURN_IF_FAIL(private_output != NULL);
835 TDM_RETURN_IF_FAIL(TDM_MUTEX_IS_LOCKED());
837 LIST_FOR_EACH_ENTRY(c, &private_output->output_commit_handler_list, link) {
838 if (c->func == func && c->user_data == user_data) {
839 /* only set func & user_data to NULL. It will be freed when an event occurs */
848 tdm_output_remove_vblank_handler(tdm_output *output, tdm_output_vblank_handler func, void *user_data)
852 _pthread_mutex_lock(&private_display->lock);
854 tdm_output_remove_vblank_handler_internal(output, func, user_data);
856 _pthread_mutex_unlock(&private_display->lock);
862 tdm_output_remove_commit_handler(tdm_output *output, tdm_output_commit_handler func, void *user_data)
866 _pthread_mutex_lock(&private_display->lock);
868 tdm_output_remove_commit_handler_internal(output, func, user_data);
870 _pthread_mutex_unlock(&private_display->lock);
876 tdm_output_commit_internal(tdm_output *output, int sync, tdm_output_commit_handler func, void *user_data)
878 tdm_func_output *func_output;
879 tdm_private_output_commit_handler *output_commit_handler = NULL;
880 tdm_private_layer *private_layer = NULL;
881 tdm_output_dpms dpms_value = TDM_OUTPUT_DPMS_ON;
885 func_output = &private_display->func_output;
887 if (!func_output->output_commit) {
888 TDM_ERR("not implemented!!");
889 return TDM_ERROR_NOT_IMPLEMENTED;
892 ret = tdm_output_get_dpms_internal(output, &dpms_value);
893 TDM_RETURN_VAL_IF_FAIL(ret == TDM_ERROR_NONE, ret);
895 if (dpms_value == TDM_OUTPUT_DPMS_ON) {
897 if (!private_output->regist_commit_cb) {
898 private_output->regist_commit_cb = 1;
899 ret = func_output->output_set_commit_handler(private_output->output_backend,
900 tdm_output_cb_commit);
901 TDM_GOTO_IF_FAIL(ret == TDM_ERROR_NONE, commit_failed);
904 output_commit_handler = calloc(1, sizeof(tdm_private_output_commit_handler));
905 if (!output_commit_handler) {
906 TDM_ERR("failed: alloc memory");
907 return TDM_ERROR_OUT_OF_MEMORY;
910 LIST_ADDTAIL(&output_commit_handler->link, &private_output->output_commit_handler_list);
911 output_commit_handler->private_output = private_output;
912 output_commit_handler->func = func;
913 output_commit_handler->user_data = user_data;
914 output_commit_handler->owner_tid = syscall(SYS_gettid);
917 ret = func_output->output_commit(private_output->output_backend, sync,
918 output_commit_handler);
919 TDM_GOTO_IF_FAIL(ret == TDM_ERROR_NONE, commit_failed);
921 if (tdm_debug_module & TDM_DEBUG_COMMIT)
922 TDM_INFO("output(%d) backend commit: handle(%p) func(%p) user_data(%p)",
923 private_output->pipe, output_commit_handler, func, user_data);
926 /* Even if DPMS is off, committed_buffer should be changed because it will be referred
927 * for tdm_layer_committed() function.
929 LIST_FOR_EACH_ENTRY(private_layer, &private_output->layer_list, link) {
930 if (!private_layer->waiting_buffer)
933 private_layer->committed_buffer = private_layer->waiting_buffer;
934 private_layer->waiting_buffer = NULL;
935 if (tdm_debug_module & TDM_DEBUG_BUFFER)
936 TDM_INFO("layer(%p) waiting_buffer(%p) committed_buffer(%p)",
937 private_layer, private_layer->waiting_buffer,
938 private_layer->committed_buffer->buffer);
941 if (dpms_value != TDM_OUTPUT_DPMS_ON) {
942 TDM_WRN("TDM_OUTPUT_DPMS_OFF. Directly call commit handler instead of commit.");
944 func(output, 0, 0, 0, user_data);
950 if (output_commit_handler) {
951 LIST_DEL(&output_commit_handler->link);
952 free(output_commit_handler);
958 tdm_output_commit(tdm_output *output, int sync, tdm_output_commit_handler func,
961 tdm_private_layer *private_layer = NULL;
965 _pthread_mutex_lock(&private_display->lock);
967 if (private_display->commit_type == TDM_COMMIT_TYPE_NONE)
968 private_display->commit_type = TDM_COMMIT_TYPE_OUTPUT;
969 else if (private_display->commit_type == TDM_COMMIT_TYPE_LAYER) {
970 TDM_ERR("Can't supported. Use tdm_layer_commit");
971 _pthread_mutex_unlock(&private_display->lock);
972 return TDM_ERROR_BAD_REQUEST;
975 if (private_display->commit_per_vblank) {
976 TDM_ERR("Use tdm_layer_commit");
977 _pthread_mutex_unlock(&private_display->lock);
978 return TDM_ERROR_BAD_REQUEST;
981 if (private_output->current_dpms_value > TDM_OUTPUT_DPMS_ON) {
982 TDM_ERR("output(%d) dpms: %s", private_output->pipe,
983 tdm_dpms_str(private_output->current_dpms_value));
984 _pthread_mutex_unlock(&private_display->lock);
985 return TDM_ERROR_DPMS_OFF;
988 if (tdm_debug_module & TDM_DEBUG_COMMIT)
989 TDM_INFO("output(%d) commit", private_output->pipe);
991 /* apply the pending data of all layers */
992 LIST_FOR_EACH_ENTRY(private_layer, &private_output->layer_list, link) {
993 tdm_layer_commit_pending_data(private_layer);
996 ret = tdm_output_commit_internal(output, sync, func, user_data);
998 _pthread_mutex_unlock(&private_display->lock);
1004 tdm_output_set_mode(tdm_output *output, const tdm_output_mode *mode)
1006 tdm_func_output *func_output;
1007 OUTPUT_FUNC_ENTRY();
1009 TDM_RETURN_VAL_IF_FAIL(mode != NULL, TDM_ERROR_INVALID_PARAMETER);
1011 _pthread_mutex_lock(&private_display->lock);
1013 func_output = &private_display->func_output;
1015 if (!func_output->output_set_mode) {
1016 _pthread_mutex_unlock(&private_display->lock);
1017 TDM_ERR("not implemented!!");
1018 return TDM_ERROR_NOT_IMPLEMENTED;
1021 ret = func_output->output_set_mode(private_output->output_backend, mode);
1022 if (ret == TDM_ERROR_NONE)
1023 private_output->current_mode = mode;
1024 _pthread_mutex_unlock(&private_display->lock);
1030 tdm_output_get_mode(tdm_output *output, const tdm_output_mode **mode)
1032 OUTPUT_FUNC_ENTRY();
1034 TDM_RETURN_VAL_IF_FAIL(mode != NULL, TDM_ERROR_INVALID_PARAMETER);
1036 _pthread_mutex_lock(&private_display->lock);
1038 *mode = private_output->current_mode;
1040 _pthread_mutex_unlock(&private_display->lock);
1046 _tdm_output_dpms_changed_timeout(void *user_data)
1048 tdm_private_output *private_output = user_data;
1051 value.u32 = private_output->current_dpms_value;
1052 tdm_output_call_change_handler_internal(private_output,
1053 &private_output->change_handler_list_sub,
1054 TDM_OUTPUT_CHANGE_DPMS,
1057 return TDM_ERROR_NONE;
1061 tdm_output_cb_dpms(tdm_output *output_backend, tdm_output_dpms dpms, void *user_data)
1063 tdm_private_display *private_display;
1064 tdm_private_output *private_output = user_data;
1067 TDM_RETURN_IF_FAIL(TDM_MUTEX_IS_LOCKED());
1068 TDM_RETURN_IF_FAIL(private_output);
1070 private_display = private_output->private_display;
1072 if (!tdm_thread_in_display_thread(syscall(SYS_gettid))) {
1073 tdm_thread_cb_output_dpms output_dpms;
1076 _tdm_output_update(output_backend, user_data);
1078 output_dpms.base.type = TDM_THREAD_CB_OUTPUT_DPMS;
1079 output_dpms.base.length = sizeof output_dpms;
1080 output_dpms.output_stamp = private_output->stamp;
1081 output_dpms.dpms = dpms;
1082 output_dpms.user_data = user_data;
1085 tdm_output_call_change_handler_internal(private_output,
1086 &private_output->change_handler_list_sub,
1087 TDM_OUTPUT_CHANGE_DPMS,
1090 ret = tdm_thread_send_cb(private_display->private_loop, &output_dpms.base);
1091 TDM_WARNING_IF_FAIL(ret == TDM_ERROR_NONE);
1096 private_output->current_dpms_value = dpms;
1097 private_output->waiting_dpms_change = 0;
1099 TDM_INFO("output(%d) dpms async '%s' done", private_output->pipe, tdm_dpms_str(dpms));
1102 tdm_output_call_change_handler_internal(private_output,
1103 &private_output->change_handler_list_main,
1104 TDM_OUTPUT_CHANGE_DPMS,
1109 tdm_output_set_dpms(tdm_output *output, tdm_output_dpms dpms_value)
1111 tdm_func_output *func_output;
1112 OUTPUT_FUNC_ENTRY();
1114 if (dpms_value > TDM_OUTPUT_DPMS_OFF)
1115 dpms_value = TDM_OUTPUT_DPMS_OFF;
1117 _pthread_mutex_lock(&private_display->lock);
1119 if (private_output->waiting_dpms_change) {
1120 TDM_ERR("DPMS is not changed yet. Can't be changed twice");
1121 _pthread_mutex_unlock(&private_display->lock);
1122 return TDM_ERROR_BAD_REQUEST;
1125 if (private_output->current_dpms_value == dpms_value) {
1126 _pthread_mutex_unlock(&private_display->lock);
1127 return TDM_ERROR_NONE;
1130 /** Use timer to call the output change callback of the sub-thread.
1131 * The output change callback of tdm_server and tdm_vblank was called
1132 * in the main thread. And it made the multi thread issue. If we use
1133 * the timer, we can call the sub-thread's output change callback in
1136 if (!private_output->dpms_changed_timer) {
1137 private_output->dpms_changed_timer =
1138 tdm_event_loop_add_timer_handler(private_output->private_display,
1139 _tdm_output_dpms_changed_timeout, private_output, NULL);
1140 if (!private_output->dpms_changed_timer) {
1141 TDM_ERR("can't create dpms timer!!");
1142 _pthread_mutex_unlock(&private_display->lock);
1143 return TDM_ERROR_OUT_OF_MEMORY;
1147 func_output = &private_display->func_output;
1149 TDM_INFO("output(%d) dpms '%s'", private_output->pipe, tdm_dpms_str(dpms_value));
1151 if (func_output->output_set_dpms)
1152 ret = func_output->output_set_dpms(private_output->output_backend, dpms_value);
1154 ret = TDM_ERROR_NONE;
1155 TDM_WRN("not implemented!!");
1160 if (ret == TDM_ERROR_NONE) {
1163 private_output->current_dpms_value = dpms_value;
1164 TDM_INFO("output(%d) dpms '%s' done", private_output->pipe, tdm_dpms_str(dpms_value));
1166 value.u32 = dpms_value;
1167 tdm_output_call_change_handler_internal(private_output,
1168 &private_output->change_handler_list_main,
1169 TDM_OUTPUT_CHANGE_DPMS,
1172 if (!LIST_IS_EMPTY(&private_output->change_handler_list_sub)) {
1173 ret = tdm_event_loop_source_timer_update(private_output->dpms_changed_timer, 1);
1174 if (ret != TDM_ERROR_NONE)
1175 TDM_NEVER_GET_HERE();
1179 _pthread_mutex_unlock(&private_display->lock);
1185 tdm_output_set_dpms_async(tdm_output *output, tdm_output_dpms dpms_value)
1187 tdm_func_output *func_output;
1188 OUTPUT_FUNC_ENTRY();
1190 if (!(private_output->caps.capabilities & TDM_OUTPUT_CAPABILITY_ASYNC_DPMS)) {
1191 TDM_ERR("output doesn't support the asynchronous DPMS control!");
1192 return TDM_ERROR_BAD_REQUEST;
1195 if (dpms_value > TDM_OUTPUT_DPMS_OFF)
1196 dpms_value = TDM_OUTPUT_DPMS_OFF;
1198 _pthread_mutex_lock(&private_display->lock);
1200 if (private_output->waiting_dpms_change) {
1201 TDM_ERR("DPMS is not changed yet. Can't be changed twice");
1202 _pthread_mutex_unlock(&private_display->lock);
1203 return TDM_ERROR_BAD_REQUEST;
1206 if (private_output->current_dpms_value == dpms_value) {
1207 _pthread_mutex_unlock(&private_display->lock);
1208 return TDM_ERROR_NONE;
1211 func_output = &private_display->func_output;
1212 if (!func_output->output_set_dpms_handler) {
1213 TDM_ERR("not implemented: output_set_dpms_handler");
1214 _pthread_mutex_unlock(&private_display->lock);
1215 return TDM_ERROR_NOT_IMPLEMENTED;
1218 if (!func_output->output_set_dpms_async) {
1219 TDM_ERR("not implemented: output_set_dpms_async");
1220 _pthread_mutex_unlock(&private_display->lock);
1221 return TDM_ERROR_NOT_IMPLEMENTED;
1224 if (!private_output->regist_dpms_cb) {
1225 private_output->regist_dpms_cb = 1;
1226 ret = func_output->output_set_dpms_handler(private_output->output_backend,
1227 tdm_output_cb_dpms, private_output);
1228 if (ret != TDM_ERROR_NONE) {
1229 _pthread_mutex_unlock(&private_display->lock);
1230 TDM_ERR("Can't set the dpms handler!!");
1235 TDM_INFO("output(%d) dpms async '%s'", private_output->pipe, tdm_dpms_str(dpms_value));
1237 ret = func_output->output_set_dpms_async(private_output->output_backend, dpms_value);
1239 if (ret == TDM_ERROR_NONE) {
1240 private_output->waiting_dpms_change = 1;
1241 TDM_INFO("output(%d) dpms async '%s' waiting", private_output->pipe, tdm_dpms_str(dpms_value));
1244 _pthread_mutex_unlock(&private_display->lock);
1250 tdm_output_get_dpms_internal(tdm_output *output, tdm_output_dpms *dpms_value)
1252 tdm_func_output *func_output;
1253 OUTPUT_FUNC_ENTRY();
1255 TDM_RETURN_VAL_IF_FAIL(private_output != NULL, TDM_ERROR_INVALID_PARAMETER);
1257 /* TODO: this is ugly. But before calling backend's output_get_dpms(), we have
1258 * to check if all backends's DPMS operation has no problem. In future, we'd
1259 * better use new env instead of using commit_per_vblank variable to distinguish
1260 * whether we use the stored value or backend's output_get_dpms.
1262 if (!private_display->commit_per_vblank) {
1263 *dpms_value = private_output->current_dpms_value;
1264 return TDM_ERROR_NONE;
1267 func_output = &private_display->func_output;
1269 if (!func_output->output_get_dpms) {
1270 *dpms_value = private_output->current_dpms_value;
1271 TDM_WRN("not implemented!!");
1272 return TDM_ERROR_NONE;
1275 ret = func_output->output_get_dpms(private_output->output_backend, dpms_value);
1276 if (ret != TDM_ERROR_NONE) {
1277 TDM_ERR("output_get_dpms failed");
1278 *dpms_value = TDM_OUTPUT_DPMS_OFF;
1281 /* TODO: this is ugly. But we have to check if all backends's DPMS operation has no problem. */
1282 if (private_display->commit_per_vblank)
1283 if (*dpms_value != private_output->current_dpms_value) {
1284 private_output->current_dpms_value = *dpms_value;
1285 TDM_ERR("output(%d) dpms changed suddenly: %s",
1286 private_output->pipe, tdm_dpms_str(*dpms_value));
1293 tdm_output_get_dpms(tdm_output *output, tdm_output_dpms *dpms_value)
1295 OUTPUT_FUNC_ENTRY();
1297 TDM_RETURN_VAL_IF_FAIL(dpms_value != NULL, TDM_ERROR_INVALID_PARAMETER);
1299 _pthread_mutex_lock(&private_display->lock);
1301 ret = tdm_output_get_dpms_internal(output, dpms_value);
1303 _pthread_mutex_unlock(&private_display->lock);
1308 EXTERN tdm_capture *
1309 tdm_output_create_capture(tdm_output *output, tdm_error *error)
1311 tdm_capture *capture = NULL;
1313 OUTPUT_FUNC_ENTRY_ERROR();
1315 _pthread_mutex_lock(&private_display->lock);
1317 capture = (tdm_capture *)tdm_capture_create_output_internal(private_output, error);
1319 _pthread_mutex_unlock(&private_display->lock);
1325 tdm_output_call_change_handler_internal(tdm_private_output *private_output,
1326 struct list_head *change_handler_list,
1327 tdm_output_change_type type,
1329 int no_check_thread_id)
1331 tdm_private_display *private_display;
1332 tdm_private_change_handler *change_handler = NULL;
1334 TDM_RETURN_IF_FAIL(TDM_MUTEX_IS_LOCKED());
1335 TDM_RETURN_IF_FAIL(private_output);
1337 private_display = private_output->private_display;
1338 if (!tdm_thread_in_display_thread(syscall(SYS_gettid))) {
1339 if (type & TDM_OUTPUT_CHANGE_CONNECTION)
1340 TDM_INFO("output(%d) changed: %s (%d)",
1341 private_output->pipe, tdm_status_str(value.u32), value.u32);
1342 if (type & TDM_OUTPUT_CHANGE_DPMS)
1343 TDM_INFO("output(%d) changed: dpms %s (%d)",
1344 private_output->pipe, tdm_dpms_str(value.u32), value.u32);
1347 if (LIST_IS_EMPTY(change_handler_list))
1350 LIST_FOR_EACH_ENTRY(change_handler, change_handler_list, link) {
1351 if (!no_check_thread_id && change_handler->owner_tid != syscall(SYS_gettid))
1352 TDM_NEVER_GET_HERE();
1354 _pthread_mutex_unlock(&private_display->lock);
1355 change_handler->func(private_output, type,
1356 value, change_handler->user_data);
1357 _pthread_mutex_lock(&private_display->lock);