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);
609 v->func(v->private_output, sequence, tv_sec, tv_usec, v->user_data);
613 _pthread_mutex_lock(&private_display->lock);
615 if (tdm_debug_module & TDM_DEBUG_COMMIT)
616 TDM_INFO("-----------------------------------------...");
620 tdm_output_cb_commit(tdm_output *output_backend, unsigned int sequence,
621 unsigned int tv_sec, unsigned int tv_usec, void *user_data)
623 tdm_private_output_commit_handler *output_commit_handler = user_data;
624 tdm_private_display *private_display;
625 tdm_private_output *private_output;
626 tdm_private_layer *private_layer = NULL;
628 TDM_RETURN_IF_FAIL(TDM_MUTEX_IS_LOCKED());
630 if (!output_commit_handler)
633 private_output = output_commit_handler->private_output;
634 private_display = private_output->private_display;
636 if (output_commit_handler->owner_tid != syscall(SYS_gettid)) {
637 tdm_thread_cb_output_commit output_commit;
640 output_commit.base.type = TDM_THREAD_CB_OUTPUT_COMMIT;
641 output_commit.base.length = sizeof output_commit;
642 output_commit.output_stamp = private_output->stamp;
643 output_commit.sequence = sequence;
644 output_commit.tv_sec = tv_sec;
645 output_commit.tv_usec = tv_usec;
646 output_commit.user_data = user_data;
648 ret = tdm_thread_send_cb(private_display->private_loop, &output_commit.base);
649 TDM_WARNING_IF_FAIL(ret == TDM_ERROR_NONE);
654 if (tdm_debug_module & TDM_DEBUG_COMMIT) {
655 TDM_INFO("----------------------------------------- output(%d) committed", private_output->pipe);
656 TDM_INFO("handler(%p)", output_commit_handler);
659 if (private_display->commit_type == TDM_COMMIT_TYPE_OUTPUT) {
660 /* In case of layer commit, the below will be handled in the layer commit callback */
661 LIST_FOR_EACH_ENTRY(private_layer, &private_output->layer_list, link) {
662 if (private_layer->committed_buffer)
663 tdm_layer_committed(private_layer, &private_layer->committed_buffer);
667 if (output_commit_handler->func) {
668 _pthread_mutex_unlock(&private_display->lock);
669 output_commit_handler->func(private_output, sequence,
670 tv_sec, tv_usec, output_commit_handler->user_data);
671 _pthread_mutex_lock(&private_display->lock);
674 LIST_DEL(&output_commit_handler->link);
675 free(output_commit_handler);
677 if (tdm_debug_module & TDM_DEBUG_COMMIT)
678 TDM_INFO("-----------------------------------------...");
681 /* add_front: To distinguish between the user vblank handlers and the layer
682 * commit vblank handlers. The layer commit handlers will be called
683 * before calling the user vblank handlers.
686 _tdm_output_wait_vblank(tdm_output *output, int interval, int sync,
687 tdm_output_vblank_handler func, void *user_data,
688 unsigned int add_front)
690 tdm_func_output *func_output;
691 tdm_private_vblank_handler *vblank_handler = NULL, *v = NULL;
692 unsigned int skip_request = 0;
693 pid_t tid = syscall(SYS_gettid);
697 func_output = &private_display->func_output;
699 /* interval SHOULD be at least 1 */
703 if (!func_output->output_wait_vblank) {
704 TDM_ERR("not implemented!!");
705 return TDM_ERROR_NOT_IMPLEMENTED;
708 if (!private_output->regist_vblank_cb) {
709 private_output->regist_vblank_cb = 1;
710 ret = func_output->output_set_vblank_handler(private_output->output_backend,
711 tdm_output_cb_vblank);
714 vblank_handler = calloc(1, sizeof(tdm_private_vblank_handler));
715 if (!vblank_handler) {
716 TDM_ERR("failed: alloc memory");
717 return TDM_ERROR_OUT_OF_MEMORY;
720 if (tdm_debug_module & TDM_DEBUG_COMMIT)
721 TDM_INFO("output(%d) wait_vblank: handler(%p)", private_output->pipe, vblank_handler);
723 LIST_FOR_EACH_ENTRY(v, &private_output->vblank_handler_list, link) {
724 if (v->interval == interval && v->sync == sync && v->owner_tid == tid) {
731 LIST_ADD(&vblank_handler->link, &private_output->vblank_handler_list);
733 LIST_ADDTAIL(&vblank_handler->link, &private_output->vblank_handler_list);
735 vblank_handler->private_output = private_output;
736 vblank_handler->interval = interval;
737 vblank_handler->sync = sync;
738 vblank_handler->func = func;
739 vblank_handler->user_data = user_data;
740 vblank_handler->owner_tid = tid;
742 /* If there is the previous request, we can skip to call output_wait_vblank() */
744 ret = func_output->output_wait_vblank(private_output->output_backend, interval,
745 sync, vblank_handler);
746 TDM_GOTO_IF_FAIL(ret == TDM_ERROR_NONE, wait_failed);
748 if (tdm_debug_module & TDM_DEBUG_COMMIT)
749 TDM_INFO("output(%d) backend wait_vblank", private_output->pipe);
755 if (vblank_handler) {
756 LIST_DEL(&vblank_handler->link);
757 free(vblank_handler);
763 tdm_output_wait_vblank(tdm_output *output, int interval, int sync,
764 tdm_output_vblank_handler func, void *user_data)
768 _pthread_mutex_lock(&private_display->lock);
770 if (private_output->current_dpms_value > TDM_OUTPUT_DPMS_ON) {
771 TDM_WRN("output(%d) dpms: %s", private_output->pipe,
772 tdm_dpms_str(private_output->current_dpms_value));
773 _pthread_mutex_unlock(&private_display->lock);
774 return TDM_ERROR_DPMS_OFF;
777 ret = _tdm_output_wait_vblank(output, interval, sync, func, user_data, 0);
779 _pthread_mutex_unlock(&private_display->lock);
785 tdm_output_wait_vblank_add_front(tdm_output *output, int interval, int sync,
786 tdm_output_vblank_handler func, void *user_data)
790 _pthread_mutex_lock(&private_display->lock);
792 if (private_output->current_dpms_value > TDM_OUTPUT_DPMS_ON) {
793 TDM_WRN("output(%d) dpms: %s", private_output->pipe,
794 tdm_dpms_str(private_output->current_dpms_value));
795 _pthread_mutex_unlock(&private_display->lock);
796 return TDM_ERROR_DPMS_OFF;
799 ret = _tdm_output_wait_vblank(output, interval, sync, func, user_data, 1);
801 _pthread_mutex_unlock(&private_display->lock);
807 tdm_output_commit_internal(tdm_output *output, int sync, tdm_output_commit_handler func, void *user_data)
809 tdm_func_output *func_output;
810 tdm_private_output_commit_handler *output_commit_handler = NULL;
811 tdm_private_layer *private_layer = NULL;
812 tdm_output_dpms dpms_value = TDM_OUTPUT_DPMS_ON;
816 func_output = &private_display->func_output;
818 if (!func_output->output_commit) {
819 TDM_ERR("not implemented!!");
820 return TDM_ERROR_NOT_IMPLEMENTED;
823 tdm_output_get_dpms_internal(output, &dpms_value);
825 if (dpms_value == TDM_OUTPUT_DPMS_ON) {
827 if (!private_output->regist_commit_cb) {
828 private_output->regist_commit_cb = 1;
829 ret = func_output->output_set_commit_handler(private_output->output_backend,
830 tdm_output_cb_commit);
831 TDM_GOTO_IF_FAIL(ret == TDM_ERROR_NONE, commit_failed);
834 output_commit_handler = calloc(1, sizeof(tdm_private_output_commit_handler));
835 if (!output_commit_handler) {
836 TDM_ERR("failed: alloc memory");
837 return TDM_ERROR_OUT_OF_MEMORY;
840 LIST_ADDTAIL(&output_commit_handler->link, &private_output->output_commit_handler_list);
841 output_commit_handler->private_output = private_output;
842 output_commit_handler->func = func;
843 output_commit_handler->user_data = user_data;
844 output_commit_handler->owner_tid = syscall(SYS_gettid);
847 ret = func_output->output_commit(private_output->output_backend, sync,
848 output_commit_handler);
849 TDM_GOTO_IF_FAIL(ret == TDM_ERROR_NONE, commit_failed);
851 if (tdm_debug_module & TDM_DEBUG_COMMIT)
852 TDM_INFO("output(%d) backend commit: handle(%p) func(%p) user_data(%p)",
853 private_output->pipe, output_commit_handler, func, user_data);
856 /* Even if DPMS is off, committed_buffer should be changed because it will be referred
857 * for tdm_layer_committed() function.
859 LIST_FOR_EACH_ENTRY(private_layer, &private_output->layer_list, link) {
860 if (!private_layer->waiting_buffer)
863 private_layer->committed_buffer = private_layer->waiting_buffer;
864 private_layer->waiting_buffer = NULL;
865 if (tdm_debug_module & TDM_DEBUG_BUFFER)
866 TDM_INFO("layer(%p) waiting_buffer(%p) committed_buffer(%p)",
867 private_layer, private_layer->waiting_buffer,
868 private_layer->committed_buffer->buffer);
871 if (dpms_value != TDM_OUTPUT_DPMS_ON) {
872 TDM_WRN("TDM_OUTPUT_DPMS_OFF. Directly call commit handler instead of commit.");
874 func(output, 0, 0, 0, user_data);
880 if (output_commit_handler) {
881 LIST_DEL(&output_commit_handler->link);
882 free(output_commit_handler);
888 tdm_output_commit(tdm_output *output, int sync, tdm_output_commit_handler func,
893 _pthread_mutex_lock(&private_display->lock);
895 if (private_display->commit_type == TDM_COMMIT_TYPE_NONE)
896 private_display->commit_type = TDM_COMMIT_TYPE_OUTPUT;
897 else if (private_display->commit_type == TDM_COMMIT_TYPE_LAYER) {
898 TDM_ERR("Can't supported. Use tdm_layer_commit");
899 _pthread_mutex_unlock(&private_display->lock);
900 return TDM_ERROR_BAD_REQUEST;
903 if (private_display->commit_per_vblank) {
904 TDM_ERR("Use tdm_layer_commit");
905 _pthread_mutex_unlock(&private_display->lock);
906 return TDM_ERROR_BAD_REQUEST;
909 if (private_output->current_dpms_value > TDM_OUTPUT_DPMS_ON) {
910 TDM_ERR("output(%d) dpms: %s", private_output->pipe,
911 tdm_dpms_str(private_output->current_dpms_value));
912 _pthread_mutex_unlock(&private_display->lock);
913 return TDM_ERROR_DPMS_OFF;
916 if (tdm_debug_module & TDM_DEBUG_COMMIT)
917 TDM_INFO("output(%d) commit", private_output->pipe);
919 ret = tdm_output_commit_internal(output, sync, func, user_data);
921 _pthread_mutex_unlock(&private_display->lock);
927 tdm_output_set_mode(tdm_output *output, const tdm_output_mode *mode)
929 tdm_func_output *func_output;
932 TDM_RETURN_VAL_IF_FAIL(mode != NULL, TDM_ERROR_INVALID_PARAMETER);
934 _pthread_mutex_lock(&private_display->lock);
936 func_output = &private_display->func_output;
938 if (!func_output->output_set_mode) {
939 _pthread_mutex_unlock(&private_display->lock);
940 TDM_ERR("not implemented!!");
941 return TDM_ERROR_NOT_IMPLEMENTED;
944 ret = func_output->output_set_mode(private_output->output_backend, mode);
945 if (ret == TDM_ERROR_NONE)
946 private_output->current_mode = mode;
947 _pthread_mutex_unlock(&private_display->lock);
953 tdm_output_get_mode(tdm_output *output, const tdm_output_mode **mode)
957 TDM_RETURN_VAL_IF_FAIL(mode != NULL, TDM_ERROR_INVALID_PARAMETER);
959 _pthread_mutex_lock(&private_display->lock);
961 *mode = private_output->current_mode;
963 _pthread_mutex_unlock(&private_display->lock);
969 _tdm_output_dpms_changed_timeout(void *user_data)
971 tdm_private_output *private_output = user_data;
974 value.u32 = private_output->current_dpms_value;
975 tdm_output_call_change_handler_internal(private_output,
976 &private_output->change_handler_list_sub,
977 TDM_OUTPUT_CHANGE_DPMS,
980 return TDM_ERROR_NONE;
984 tdm_output_cb_dpms(tdm_output *output_backend, tdm_output_dpms dpms, void *user_data)
986 tdm_private_display *private_display;
987 tdm_private_output *private_output = user_data;
990 TDM_RETURN_IF_FAIL(TDM_MUTEX_IS_LOCKED());
991 TDM_RETURN_IF_FAIL(private_output);
993 private_display = private_output->private_display;
995 if (!tdm_thread_in_display_thread(syscall(SYS_gettid))) {
996 tdm_thread_cb_output_dpms output_dpms;
999 _tdm_output_update(output_backend, user_data);
1001 output_dpms.base.type = TDM_THREAD_CB_OUTPUT_DPMS;
1002 output_dpms.base.length = sizeof output_dpms;
1003 output_dpms.output_stamp = private_output->stamp;
1004 output_dpms.dpms = dpms;
1005 output_dpms.user_data = user_data;
1008 tdm_output_call_change_handler_internal(private_output,
1009 &private_output->change_handler_list_sub,
1010 TDM_OUTPUT_CHANGE_DPMS,
1013 ret = tdm_thread_send_cb(private_display->private_loop, &output_dpms.base);
1014 TDM_WARNING_IF_FAIL(ret == TDM_ERROR_NONE);
1019 private_output->current_dpms_value = dpms;
1021 TDM_INFO("output(%d) dpms %s", private_output->pipe, tdm_dpms_str(dpms));
1024 tdm_output_call_change_handler_internal(private_output,
1025 &private_output->change_handler_list_main,
1026 TDM_OUTPUT_CHANGE_DPMS,
1031 tdm_output_set_dpms(tdm_output *output, tdm_output_dpms dpms_value)
1033 tdm_func_output *func_output;
1034 OUTPUT_FUNC_ENTRY();
1036 if (dpms_value > TDM_OUTPUT_DPMS_OFF)
1037 dpms_value = TDM_OUTPUT_DPMS_OFF;
1039 _pthread_mutex_lock(&private_display->lock);
1041 if (private_output->current_dpms_value == dpms_value) {
1042 _pthread_mutex_unlock(&private_display->lock);
1043 return TDM_ERROR_NONE;
1046 /** Use timer to call the output change callback of the sub-thread.
1047 * The output change callback of tdm_server and tdm_vblank was called
1048 * in the main thread. And it made the multi thread issue. If we use
1049 * the timer, we can call the sub-thread's output change callback in
1052 if (!private_output->dpms_changed_timer) {
1053 private_output->dpms_changed_timer =
1054 tdm_event_loop_add_timer_handler(private_output->private_display,
1055 _tdm_output_dpms_changed_timeout, private_output, NULL);
1056 if (!private_output->dpms_changed_timer) {
1057 TDM_ERR("can't create dpms timer!!");
1058 _pthread_mutex_unlock(&private_display->lock);
1059 return TDM_ERROR_OUT_OF_MEMORY;
1063 func_output = &private_display->func_output;
1065 if (!func_output->output_set_dpms) {
1066 _pthread_mutex_unlock(&private_display->lock);
1067 private_output->current_dpms_value = dpms_value;
1068 TDM_INFO("output(%d) dpms %s", private_output->pipe, tdm_dpms_str(dpms_value));
1069 TDM_WRN("not implemented!!");
1070 return TDM_ERROR_NONE;
1073 if (func_output->output_set_dpms_handler) {
1074 if (!private_output->regist_dpms_cb) {
1075 private_output->regist_dpms_cb = 1;
1076 ret = func_output->output_set_dpms_handler(private_output->output_backend,
1077 tdm_output_cb_dpms, private_output);
1078 if (ret != TDM_ERROR_NONE) {
1079 _pthread_mutex_unlock(&private_display->lock);
1080 TDM_ERR("Can't set the dpms handler!!");
1086 ret = func_output->output_set_dpms(private_output->output_backend, dpms_value);
1088 if (ret == TDM_ERROR_NONE && !func_output->output_set_dpms_handler) {
1091 private_output->current_dpms_value = dpms_value;
1092 TDM_INFO("output(%d) dpms %s", private_output->pipe, tdm_dpms_str(dpms_value));
1094 value.u32 = dpms_value;
1095 tdm_output_call_change_handler_internal(private_output,
1096 &private_output->change_handler_list_main,
1097 TDM_OUTPUT_CHANGE_DPMS,
1100 if (!LIST_IS_EMPTY(&private_output->change_handler_list_sub)) {
1101 ret = tdm_event_loop_source_timer_update(private_output->dpms_changed_timer, 1);
1102 if (ret != TDM_ERROR_NONE)
1103 TDM_NEVER_GET_HERE();
1107 _pthread_mutex_unlock(&private_display->lock);
1113 tdm_output_get_dpms_internal(tdm_output *output, tdm_output_dpms *dpms_value)
1115 tdm_func_output *func_output;
1116 OUTPUT_FUNC_ENTRY();
1118 TDM_RETURN_VAL_IF_FAIL(private_output != NULL, TDM_ERROR_INVALID_PARAMETER);
1120 func_output = &private_display->func_output;
1122 if (!func_output->output_get_dpms) {
1123 *dpms_value = private_output->current_dpms_value;
1124 TDM_WRN("not implemented!!");
1125 return TDM_ERROR_NONE;
1128 ret = func_output->output_get_dpms(private_output->output_backend, dpms_value);
1129 if (ret != TDM_ERROR_NONE) {
1130 TDM_ERR("output_get_dpms failed");
1131 *dpms_value = TDM_OUTPUT_DPMS_OFF;
1134 if (*dpms_value != private_output->current_dpms_value) {
1135 private_output->current_dpms_value = *dpms_value;
1136 TDM_ERR("output(%d) dpms changed suddenly: %s", private_output->pipe, tdm_dpms_str(*dpms_value));
1143 tdm_output_get_dpms(tdm_output *output, tdm_output_dpms *dpms_value)
1145 OUTPUT_FUNC_ENTRY();
1147 TDM_RETURN_VAL_IF_FAIL(dpms_value != NULL, TDM_ERROR_INVALID_PARAMETER);
1149 _pthread_mutex_lock(&private_display->lock);
1151 ret = tdm_output_get_dpms_internal(output, dpms_value);
1153 _pthread_mutex_unlock(&private_display->lock);
1158 EXTERN tdm_capture *
1159 tdm_output_create_capture(tdm_output *output, tdm_error *error)
1161 tdm_capture *capture = NULL;
1163 OUTPUT_FUNC_ENTRY_ERROR();
1165 _pthread_mutex_lock(&private_display->lock);
1167 capture = (tdm_capture *)tdm_capture_create_output_internal(private_output, error);
1169 _pthread_mutex_unlock(&private_display->lock);
1175 tdm_output_call_change_handler_internal(tdm_private_output *private_output,
1176 struct list_head *change_handler_list,
1177 tdm_output_change_type type,
1179 int no_check_thread_id)
1181 tdm_private_display *private_display;
1182 tdm_private_change_handler *change_handler = NULL;
1184 TDM_RETURN_IF_FAIL(TDM_MUTEX_IS_LOCKED());
1185 TDM_RETURN_IF_FAIL(private_output);
1187 private_display = private_output->private_display;
1188 if (!tdm_thread_in_display_thread(syscall(SYS_gettid))) {
1189 if (type & TDM_OUTPUT_CHANGE_CONNECTION)
1190 TDM_INFO("output(%d) changed: %s (%d)",
1191 private_output->pipe, tdm_status_str(value.u32), value.u32);
1192 if (type & TDM_OUTPUT_CHANGE_DPMS)
1193 TDM_INFO("output(%d) changed: dpms %s (%d)",
1194 private_output->pipe, tdm_dpms_str(value.u32), value.u32);
1197 if (LIST_IS_EMPTY(change_handler_list))
1200 LIST_FOR_EACH_ENTRY(change_handler, change_handler_list, link) {
1201 if (!no_check_thread_id && change_handler->owner_tid != syscall(SYS_gettid))
1202 TDM_NEVER_GET_HERE();
1204 _pthread_mutex_unlock(&private_display->lock);
1205 change_handler->func(private_output, type,
1206 value, change_handler->user_data);
1207 _pthread_mutex_lock(&private_display->lock);