1 /**************************************************************************
5 * Copyright 2015 Samsung Electronics co., Ltd. All Rights Reserved.
7 * Contact: Eunchul Kim <chulspro.kim@samsung.com>,
8 * JinYoung Jeon <jy0.jeon@samsung.com>,
9 * Taeheon Kim <th908.kim@samsung.com>,
10 * YoungJun Cho <yj44.cho@samsung.com>,
11 * SooChan Lim <sc1.lim@samsung.com>,
12 * Boram Park <sc1.lim@samsung.com>
14 * Permission is hereby granted, free of charge, to any person obtaining a
15 * copy of this software and associated documentation files (the
16 * "Software"), to deal in the Software without restriction, including
17 * without limitation the rights to use, copy, modify, merge, publish,
18 * distribute, sub license, and/or sell copies of the Software, and to
19 * permit persons to whom the Software is furnished to do so, subject to
20 * the following conditions:
22 * The above copyright notice and this permission notice (including the
23 * next paragraph) shall be included in all copies or substantial portions
26 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
27 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
28 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
29 * IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR
30 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
31 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
32 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
34 **************************************************************************/
40 #include "tdm_private.h"
44 #define 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(tdm_output_is_valid(output), 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(tdm_output_is_valid(output), 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_vblank_handler *v = NULL;
69 TDM_RETURN_VAL_IF_FAIL(private_output != NULL, TDM_ERROR_OPERATION_FAILED);
71 TDM_ERR("TDM output(%d) vblank TIMEOUT!!", private_output->pipe);
73 LIST_FOR_EACH_ENTRY(v, &private_output->vblank_handler_list, link) {
74 TDM_ERR("vblank_handler(%p) interval(%d) sync(%d) sent_to_frontend(%u) owner_tid(%d)",
75 v, v->interval, v->sync, v->sent_to_frontend, v->owner_tid);
78 return TDM_ERROR_NONE;
82 tdm_output_vblank_print_wait_information(tdm_private_output *private_output, void *user_data)
84 tdm_private_vblank_handler *v = NULL;
86 TDM_RETURN_IF_FAIL(private_output != NULL);
87 TDM_RETURN_IF_FAIL(user_data != NULL);
89 TDM_ERR("TDM output(%d) vblank user_data(%p) info!!", private_output->pipe, user_data);
91 LIST_FOR_EACH_ENTRY(v, &private_output->vblank_handler_list, link) {
92 if (v->user_data != user_data)
94 TDM_ERR("vblank_handler(%p) interval(%d) sync(%d) sent_to_frontend(%u) owner_tid(%d)",
95 v, v->interval, v->sync, v->sent_to_frontend, v->owner_tid);
100 _tdm_output_vblank_timeout_update(tdm_private_output *private_output, int ms_delay)
104 if (!private_output->vblank_timeout_timer) {
105 private_output->vblank_timeout_timer =
106 tdm_event_loop_add_timer_handler(private_output->private_display,
107 _tdm_output_vblank_timeout_cb,
110 if (!private_output->vblank_timeout_timer) {
111 TDM_ERR("output(%d) couldn't add timer", private_output->pipe);
114 TDM_INFO("output(%d) create vblank timeout timer", private_output->pipe);
117 ret = tdm_event_loop_source_timer_update(private_output->vblank_timeout_timer, ms_delay);
118 if (ret != TDM_ERROR_NONE) {
119 TDM_ERR("output(%d) couldn't update timer", private_output->pipe);
124 static tdm_private_hwc_window *
125 _tdm_output_find_private_hwc_window(tdm_private_output *private_output,
126 tdm_hwc_window *hwc_window_backend)
128 tdm_private_hwc_window *private_hwc_window = NULL;
130 LIST_FOR_EACH_ENTRY(private_hwc_window, &private_output->hwc_window_list, link) {
131 if (private_hwc_window->hwc_window_backend == hwc_window_backend)
132 return private_hwc_window;
139 tdm_output_get_model_info(tdm_output *output, const char **maker,
140 const char **model, const char **name)
144 _pthread_mutex_lock(&private_display->lock);
147 *maker = private_output->caps.maker;
149 *model = private_output->caps.model;
151 *name = private_output->caps.name;
153 _pthread_mutex_unlock(&private_display->lock);
159 tdm_output_get_capabilities(tdm_output *output, tdm_output_capability *capabilities)
163 TDM_RETURN_VAL_IF_FAIL(capabilities != NULL, TDM_ERROR_INVALID_PARAMETER);
165 _pthread_mutex_lock(&private_display->lock);
167 *capabilities = private_output->caps.capabilities;
169 _pthread_mutex_unlock(&private_display->lock);
175 tdm_output_get_conn_status(tdm_output *output, tdm_output_conn_status *status)
179 TDM_RETURN_VAL_IF_FAIL(status != NULL, TDM_ERROR_INVALID_PARAMETER);
181 _pthread_mutex_lock(&private_display->lock);
183 *status = private_output->caps.status;
185 _pthread_mutex_unlock(&private_display->lock);
190 /* LCOV_EXCL_START */
192 _tdm_output_update(tdm_output *output_backend, void *user_data)
194 tdm_private_display *private_display;
195 tdm_private_output *private_output = user_data;
198 TDM_RETURN_IF_FAIL(private_output);
200 private_display = private_output->private_display;
202 ret = tdm_display_update_output(private_display, output_backend, private_output->pipe);
203 TDM_RETURN_IF_FAIL(ret == TDM_ERROR_NONE);
207 tdm_output_cb_status(tdm_output *output_backend, tdm_output_conn_status status,
210 tdm_private_display *private_display;
211 tdm_private_output *private_output = user_data;
214 TDM_RETURN_IF_FAIL(TDM_MUTEX_IS_LOCKED());
215 TDM_RETURN_IF_FAIL(private_output);
217 private_display = private_output->private_display;
219 if (!tdm_thread_in_display_thread(syscall(SYS_gettid))) {
220 tdm_thread_cb_output_status output_status;
223 TDM_INFO("output(%d) %s", private_output->pipe, tdm_status_str(status));
225 _tdm_output_update(output_backend, user_data);
226 private_output->caps.status = status;
228 output_status.base.type = TDM_THREAD_CB_OUTPUT_STATUS;
229 output_status.base.length = sizeof output_status;
230 output_status.output_stamp = private_output->stamp;
231 output_status.status = status;
232 output_status.user_data = user_data;
235 tdm_output_call_change_handler_internal(private_output,
236 &private_output->change_handler_list_sub,
237 TDM_OUTPUT_CHANGE_CONNECTION,
240 ret = tdm_thread_send_cb(private_display->private_loop, &output_status.base);
241 TDM_WARNING_IF_FAIL(ret == TDM_ERROR_NONE);
246 TDM_INFO("output(%d) %s", private_output->pipe, tdm_status_str(status));
248 if (!tdm_thread_is_running())
249 _tdm_output_update(output_backend, user_data);
250 private_output->caps.status = status;
253 tdm_output_call_change_handler_internal(private_output,
254 &private_output->change_handler_list_main,
255 TDM_OUTPUT_CHANGE_CONNECTION,
261 tdm_output_add_change_handler(tdm_output *output,
262 tdm_output_change_handler func,
265 tdm_private_change_handler *change_handler;
268 TDM_RETURN_VAL_IF_FAIL(func != NULL, TDM_ERROR_INVALID_PARAMETER);
270 _pthread_mutex_lock(&private_display->lock);
272 change_handler = calloc(1, sizeof(tdm_private_change_handler));
273 if (!change_handler) {
274 /* LCOV_EXCL_START */
275 TDM_ERR("failed: alloc memory");
276 _pthread_mutex_unlock(&private_display->lock);
277 return TDM_ERROR_OUT_OF_MEMORY;
281 change_handler->private_output = private_output;
282 change_handler->func = func;
283 change_handler->user_data = user_data;
284 change_handler->owner_tid = syscall(SYS_gettid);
286 if (!tdm_thread_in_display_thread(change_handler->owner_tid))
287 LIST_ADDTAIL(&change_handler->link, &private_output->change_handler_list_sub);
289 LIST_ADDTAIL(&change_handler->link, &private_output->change_handler_list_main);
291 _pthread_mutex_unlock(&private_display->lock);
297 tdm_output_remove_change_handler(tdm_output *output,
298 tdm_output_change_handler func,
301 tdm_private_display *private_display;
302 tdm_private_output *private_output;
303 tdm_private_change_handler *h = NULL, *hh = NULL;
305 TDM_RETURN_IF_FAIL(tdm_output_is_valid(output));
306 TDM_RETURN_IF_FAIL(func != NULL);
308 private_output = (tdm_private_output*)output;
309 private_display = private_output->private_display;
311 _pthread_mutex_lock(&private_display->lock);
313 LIST_FOR_EACH_ENTRY_SAFE(h, hh, &private_output->change_handler_list_main, link) {
314 if (h->func != func || h->user_data != user_data)
320 _pthread_mutex_unlock(&private_display->lock);
325 LIST_FOR_EACH_ENTRY_SAFE(h, hh, &private_output->change_handler_list_sub, link) {
326 if (h->func != func || h->user_data != user_data)
332 _pthread_mutex_unlock(&private_display->lock);
337 _pthread_mutex_unlock(&private_display->lock);
341 tdm_output_get_output_type(tdm_output *output, tdm_output_type *type)
345 TDM_RETURN_VAL_IF_FAIL(type != NULL, TDM_ERROR_INVALID_PARAMETER);
347 _pthread_mutex_lock(&private_display->lock);
349 *type = private_output->caps.type;
351 _pthread_mutex_unlock(&private_display->lock);
357 tdm_output_get_layer_count(tdm_output *output, int *count)
359 tdm_private_layer *private_layer = NULL;
363 TDM_RETURN_VAL_IF_FAIL(count != NULL, TDM_ERROR_INVALID_PARAMETER);
365 _pthread_mutex_lock(&private_display->lock);
367 if (private_output->caps.capabilities & TDM_OUTPUT_CAPABILITY_HWC) {
368 TDM_ERR("output(%p) support HWC. Use HWC functions", private_output);
370 _pthread_mutex_unlock(&private_display->lock);
371 return TDM_ERROR_BAD_REQUEST;
375 LIST_FOR_EACH_ENTRY(private_layer, &private_output->layer_list, link)
378 _pthread_mutex_unlock(&private_display->lock);
379 return TDM_ERROR_NONE;
382 _pthread_mutex_unlock(&private_display->lock);
389 tdm_output_get_layer(tdm_output *output, int index, tdm_error *error)
391 tdm_private_layer *private_layer = NULL;
393 OUTPUT_FUNC_ENTRY_ERROR();
395 _pthread_mutex_lock(&private_display->lock);
398 *error = TDM_ERROR_NONE;
400 if (private_output->caps.capabilities & TDM_OUTPUT_CAPABILITY_HWC) {
401 _pthread_mutex_unlock(&private_display->lock);
402 TDM_ERR("output(%p) support HWC. Use HWC functions", private_output);
404 *error = TDM_ERROR_BAD_REQUEST;
408 LIST_FOR_EACH_ENTRY(private_layer, &private_output->layer_list, link) {
409 if (private_layer->index == index) {
410 _pthread_mutex_unlock(&private_display->lock);
411 return private_layer;
415 _pthread_mutex_unlock(&private_display->lock);
421 tdm_output_get_available_properties(tdm_output *output, const tdm_prop **props,
426 TDM_RETURN_VAL_IF_FAIL(props != NULL, TDM_ERROR_INVALID_PARAMETER);
427 TDM_RETURN_VAL_IF_FAIL(count != NULL, TDM_ERROR_INVALID_PARAMETER);
429 _pthread_mutex_lock(&private_display->lock);
431 *props = (const tdm_prop *)private_output->caps.props;
432 *count = private_output->caps.prop_count;
434 _pthread_mutex_unlock(&private_display->lock);
440 tdm_output_get_available_modes(tdm_output *output,
441 const tdm_output_mode **modes, int *count)
445 TDM_RETURN_VAL_IF_FAIL(modes != NULL, TDM_ERROR_INVALID_PARAMETER);
446 TDM_RETURN_VAL_IF_FAIL(count != NULL, TDM_ERROR_INVALID_PARAMETER);
448 _pthread_mutex_lock(&private_display->lock);
450 *modes = (const tdm_output_mode *)private_output->caps.modes;
451 *count = private_output->caps.mode_count;
453 _pthread_mutex_unlock(&private_display->lock);
459 tdm_output_get_available_size(tdm_output *output, int *min_w, int *min_h,
460 int *max_w, int *max_h, int *preferred_align)
464 _pthread_mutex_lock(&private_display->lock);
467 *min_w = TDM_FRONT_VALUE(private_output->caps.min_w);
469 *min_h = TDM_FRONT_VALUE(private_output->caps.min_h);
471 *max_w = TDM_FRONT_VALUE(private_output->caps.max_w);
473 *max_h = TDM_FRONT_VALUE(private_output->caps.max_h);
475 *preferred_align = TDM_FRONT_VALUE(private_output->caps.preferred_align);
477 _pthread_mutex_unlock(&private_display->lock);
483 tdm_output_get_cursor_available_size(tdm_output *output, int *min_w, int *min_h,
484 int *max_w, int *max_h, int *preferred_align)
488 _pthread_mutex_lock(&private_display->lock);
490 if (!tdm_display_check_module_abi(private_display, 1, 5)) {
501 *preferred_align = -1;
503 _pthread_mutex_unlock(&private_display->lock);
505 return TDM_ERROR_BAD_MODULE;
509 *min_w = TDM_FRONT_VALUE(private_output->caps.cursor_min_w);
511 *min_h = TDM_FRONT_VALUE(private_output->caps.cursor_min_h);
513 *max_w = TDM_FRONT_VALUE(private_output->caps.cursor_max_w);
515 *max_h = TDM_FRONT_VALUE(private_output->caps.cursor_max_h);
517 *preferred_align = TDM_FRONT_VALUE(private_output->caps.cursor_preferred_align);
519 _pthread_mutex_unlock(&private_display->lock);
525 tdm_output_get_physical_size(tdm_output *output, unsigned int *mmWidth,
526 unsigned int *mmHeight)
530 _pthread_mutex_lock(&private_display->lock);
533 *mmWidth = private_output->caps.mmWidth;
535 *mmHeight = private_output->caps.mmHeight;
537 _pthread_mutex_unlock(&private_display->lock);
543 tdm_output_get_subpixel(tdm_output *output, unsigned int *subpixel)
546 TDM_RETURN_VAL_IF_FAIL(subpixel != NULL, TDM_ERROR_INVALID_PARAMETER);
548 _pthread_mutex_lock(&private_display->lock);
550 *subpixel = private_output->caps.subpixel;
552 _pthread_mutex_unlock(&private_display->lock);
558 tdm_output_get_pipe(tdm_output *output, unsigned int *pipe)
561 TDM_RETURN_VAL_IF_FAIL(pipe != NULL, TDM_ERROR_INVALID_PARAMETER);
563 _pthread_mutex_lock(&private_display->lock);
565 *pipe = private_output->pipe;
567 _pthread_mutex_unlock(&private_display->lock);
573 tdm_output_get_primary_index(tdm_output *output, int *index)
575 tdm_private_layer *private_layer = NULL;
578 TDM_RETURN_VAL_IF_FAIL(index != NULL, TDM_ERROR_INVALID_PARAMETER);
580 _pthread_mutex_lock(&private_display->lock);
582 LIST_FOR_EACH_ENTRY(private_layer, &private_output->layer_list, link) {
583 if (private_layer->caps.capabilities & TDM_LAYER_CAPABILITY_PRIMARY) {
584 *index = private_layer->index;
589 _pthread_mutex_unlock(&private_display->lock);
595 tdm_output_set_property(tdm_output *output, unsigned int id, tdm_value value)
597 tdm_func_output *func_output;
600 _pthread_mutex_lock(&private_display->lock);
602 func_output = &private_display->func_output;
604 if (!func_output->output_set_property) {
605 /* LCOV_EXCL_START */
606 _pthread_mutex_unlock(&private_display->lock);
607 TDM_ERR("not implemented!!");
608 return TDM_ERROR_NOT_IMPLEMENTED;
612 ret = func_output->output_set_property(private_output->output_backend, id,
615 _pthread_mutex_unlock(&private_display->lock);
621 tdm_output_get_property(tdm_output *output, unsigned int id, tdm_value *value)
623 tdm_func_output *func_output;
626 TDM_RETURN_VAL_IF_FAIL(value != NULL, TDM_ERROR_INVALID_PARAMETER);
628 _pthread_mutex_lock(&private_display->lock);
630 func_output = &private_display->func_output;
632 if (!func_output->output_get_property) {
633 /* LCOV_EXCL_START */
634 _pthread_mutex_unlock(&private_display->lock);
635 TDM_ERR("not implemented!!");
636 return TDM_ERROR_NOT_IMPLEMENTED;
640 ret = func_output->output_get_property(private_output->output_backend, id,
643 _pthread_mutex_unlock(&private_display->lock);
649 tdm_output_cb_vblank(tdm_output *output_backend, unsigned int sequence,
650 unsigned int tv_sec, unsigned int tv_usec, void *user_data)
652 tdm_private_vblank_handler *vblank_handler = user_data;
653 tdm_private_vblank_handler *v = NULL, *vv = NULL;
654 tdm_private_output *private_output;
655 tdm_private_display *private_display;
656 struct list_head clone_list;
658 pid_t tid = syscall(SYS_gettid);
660 TDM_RETURN_IF_FAIL(TDM_MUTEX_IS_LOCKED());
661 TDM_RETURN_IF_FAIL(vblank_handler);
663 private_output = vblank_handler->private_output;
664 private_display = private_output->private_display;
666 if (vblank_handler->owner_tid != tid) {
667 tdm_thread_cb_output_vblank output_vblank;
670 vblank_handler->sent_to_frontend = 1;
672 output_vblank.base.type = TDM_THREAD_CB_OUTPUT_VBLANK;
673 output_vblank.base.length = sizeof output_vblank;
674 output_vblank.output_stamp = vblank_handler->private_output->stamp;
675 output_vblank.sequence = sequence;
676 output_vblank.tv_sec = tv_sec;
677 output_vblank.tv_usec = tv_usec;
678 output_vblank.user_data = user_data;
680 ret = tdm_thread_send_cb(private_display->private_loop, &output_vblank.base);
681 TDM_WARNING_IF_FAIL(ret == TDM_ERROR_NONE);
686 vblank_handler->sent_to_frontend = 0;
688 _tdm_output_vblank_timeout_update(private_output, 0);
690 if (vblank_handler->owner_tid != tid)
691 TDM_NEVER_GET_HERE();
693 interval = vblank_handler->interval;
694 sync = vblank_handler->sync;
696 LIST_INITHEAD(&clone_list);
698 LIST_FOR_EACH_ENTRY_SAFE(v, vv, &private_output->vblank_handler_list, link) {
699 if (v->interval != interval || v->sync != sync || v->owner_tid != tid)
703 LIST_ADDTAIL(&v->link, &clone_list);
706 if (tdm_debug_module & TDM_DEBUG_COMMIT)
707 TDM_INFO("----------------------------------------- output(%d) got vblank", private_output->pipe);
709 _pthread_mutex_unlock(&private_display->lock);
710 LIST_FOR_EACH_ENTRY_SAFE(v, vv, &clone_list, link) {
711 if (tdm_debug_module & TDM_DEBUG_COMMIT)
712 TDM_INFO("handler(%p)", v);
717 v->func(v->private_output, sequence, tv_sec, tv_usec, v->user_data);
721 _pthread_mutex_lock(&private_display->lock);
723 if (tdm_debug_module & TDM_DEBUG_COMMIT)
724 TDM_INFO("-----------------------------------------...");
728 tdm_output_cb_commit(tdm_output *output_backend, unsigned int sequence,
729 unsigned int tv_sec, unsigned int tv_usec, void *user_data)
731 tdm_private_output_commit_handler *output_commit_handler = user_data;
732 tdm_private_display *private_display;
733 tdm_private_output *private_output;
734 tdm_private_layer *private_layer = NULL;
736 TDM_RETURN_IF_FAIL(TDM_MUTEX_IS_LOCKED());
738 if (!output_commit_handler)
741 private_output = output_commit_handler->private_output;
742 private_display = private_output->private_display;
744 if (output_commit_handler->owner_tid != syscall(SYS_gettid)) {
745 tdm_thread_cb_output_commit output_commit;
748 output_commit.base.type = TDM_THREAD_CB_OUTPUT_COMMIT;
749 output_commit.base.length = sizeof output_commit;
750 output_commit.output_stamp = private_output->stamp;
751 output_commit.sequence = sequence;
752 output_commit.tv_sec = tv_sec;
753 output_commit.tv_usec = tv_usec;
754 output_commit.user_data = user_data;
756 ret = tdm_thread_send_cb(private_display->private_loop, &output_commit.base);
757 TDM_WARNING_IF_FAIL(ret == TDM_ERROR_NONE);
762 LIST_DEL(&output_commit_handler->link);
764 if (tdm_debug_module & TDM_DEBUG_COMMIT) {
765 TDM_INFO("----------------------------------------- output(%d) committed", private_output->pipe);
766 TDM_INFO("handler(%p)", output_commit_handler);
769 if (private_output->commit_type == TDM_COMMIT_TYPE_OUTPUT) {
770 /* In case of layer commit, the below will be handled in the layer commit callback */
771 LIST_FOR_EACH_ENTRY(private_layer, &private_output->layer_list, link) {
772 if (private_layer->committed_buffer)
773 tdm_layer_committed(private_layer, &private_layer->committed_buffer);
777 if (output_commit_handler->func) {
778 _pthread_mutex_unlock(&private_display->lock);
779 output_commit_handler->func(private_output, sequence,
780 tv_sec, tv_usec, output_commit_handler->user_data);
781 _pthread_mutex_lock(&private_display->lock);
784 free(output_commit_handler);
786 if (tdm_debug_module & TDM_DEBUG_COMMIT)
787 TDM_INFO("-----------------------------------------...");
790 /* add_front: To distinguish between the user vblank handlers and the layer
791 * commit vblank handlers. The layer commit handlers will be called
792 * before calling the user vblank handlers.
795 _tdm_output_wait_vblank(tdm_output *output, int interval, int sync,
796 tdm_output_vblank_handler func, void *user_data,
797 unsigned int add_front)
799 tdm_func_output *func_output;
800 tdm_private_vblank_handler *vblank_handler = NULL, *v = NULL;
801 unsigned int skip_request = 0;
802 pid_t tid = syscall(SYS_gettid);
806 func_output = &private_display->func_output;
808 /* interval SHOULD be at least 1 */
812 if (!func_output->output_wait_vblank) {
813 /* LCOV_EXCL_START */
814 TDM_ERR("not implemented!!");
815 return TDM_ERROR_NOT_IMPLEMENTED;
819 if (!private_output->regist_vblank_cb) {
820 private_output->regist_vblank_cb = 1;
821 ret = func_output->output_set_vblank_handler(private_output->output_backend,
822 tdm_output_cb_vblank);
825 vblank_handler = calloc(1, sizeof(tdm_private_vblank_handler));
826 if (!vblank_handler) {
827 /* LCOV_EXCL_START */
828 TDM_ERR("failed: alloc memory");
829 return TDM_ERROR_OUT_OF_MEMORY;
833 if (tdm_debug_module & TDM_DEBUG_COMMIT)
834 TDM_INFO("output(%d) wait_vblank: handler(%p)", private_output->pipe, vblank_handler);
836 LIST_FOR_EACH_ENTRY(v, &private_output->vblank_handler_list, link) {
837 if (v->interval == interval && v->sync == sync && v->owner_tid == tid) {
844 LIST_ADD(&vblank_handler->link, &private_output->vblank_handler_list);
846 LIST_ADDTAIL(&vblank_handler->link, &private_output->vblank_handler_list);
848 vblank_handler->private_output = private_output;
849 vblank_handler->interval = interval;
850 vblank_handler->sync = sync;
851 vblank_handler->func = func;
852 vblank_handler->user_data = user_data;
853 vblank_handler->owner_tid = tid;
855 /* If there is the previous request, we can skip to call output_wait_vblank() */
857 ret = func_output->output_wait_vblank(private_output->output_backend, interval,
858 sync, vblank_handler);
859 TDM_GOTO_IF_FAIL(ret == TDM_ERROR_NONE, wait_failed);
861 _tdm_output_vblank_timeout_update(private_output, 1000);
863 if (tdm_debug_module & TDM_DEBUG_COMMIT)
864 TDM_INFO("output(%d) backend wait_vblank", private_output->pipe);
870 /* LCOV_EXCL_START */
871 if (vblank_handler) {
872 LIST_DEL(&vblank_handler->link);
873 free(vblank_handler);
880 tdm_output_wait_vblank(tdm_output *output, int interval, int sync,
881 tdm_output_vblank_handler func, void *user_data)
885 _pthread_mutex_lock(&private_display->lock);
887 if (TDM_OUTPUT_DPMS_VSYNC_IS_OFF(private_output->current_dpms_value)) {
888 TDM_WRN("output(%d) dpms: %s", private_output->pipe,
889 tdm_dpms_str(private_output->current_dpms_value));
890 _pthread_mutex_unlock(&private_display->lock);
891 return TDM_ERROR_DPMS_OFF;
894 ret = _tdm_output_wait_vblank(output, interval, sync, func, user_data, 0);
896 _pthread_mutex_unlock(&private_display->lock);
901 /* LCOV_EXCL_START */
903 tdm_output_wait_vblank_add_front(tdm_output *output, int interval, int sync,
904 tdm_output_vblank_handler func, void *user_data)
908 _pthread_mutex_lock(&private_display->lock);
910 if (TDM_OUTPUT_DPMS_VSYNC_IS_OFF(private_output->current_dpms_value)) {
911 TDM_WRN("output(%d) dpms: %s", private_output->pipe,
912 tdm_dpms_str(private_output->current_dpms_value));
913 _pthread_mutex_unlock(&private_display->lock);
914 return TDM_ERROR_DPMS_OFF;
917 ret = _tdm_output_wait_vblank(output, interval, sync, func, user_data, 1);
919 _pthread_mutex_unlock(&private_display->lock);
926 tdm_output_remove_vblank_handler_internal(tdm_output *output, tdm_output_vblank_handler func, void *user_data)
928 tdm_private_output *private_output = (tdm_private_output*)output;
929 tdm_private_vblank_handler *v = NULL;
931 TDM_RETURN_IF_FAIL(private_output != NULL);
932 TDM_RETURN_IF_FAIL(TDM_MUTEX_IS_LOCKED());
934 LIST_FOR_EACH_ENTRY(v, &private_output->vblank_handler_list, link) {
935 if (v->func == func && v->user_data == user_data) {
936 /* only set func & user_data to NULL. It will be freed when an event occurs */
945 tdm_output_remove_commit_handler_internal(tdm_output *output, tdm_output_commit_handler func, void *user_data)
947 tdm_private_output *private_output = (tdm_private_output*)output;
948 tdm_private_output_commit_handler *c = NULL;
950 TDM_RETURN_IF_FAIL(private_output != NULL);
951 TDM_RETURN_IF_FAIL(TDM_MUTEX_IS_LOCKED());
953 LIST_FOR_EACH_ENTRY(c, &private_output->output_commit_handler_list, link) {
954 if (c->func == func && c->user_data == user_data) {
955 /* only set func & user_data to NULL. It will be freed when an event occurs */
964 tdm_output_remove_vblank_handler(tdm_output *output, tdm_output_vblank_handler func, void *user_data)
968 _pthread_mutex_lock(&private_display->lock);
970 tdm_output_remove_vblank_handler_internal(output, func, user_data);
972 _pthread_mutex_unlock(&private_display->lock);
978 tdm_output_remove_commit_handler(tdm_output *output, tdm_output_commit_handler func, void *user_data)
982 _pthread_mutex_lock(&private_display->lock);
984 tdm_output_remove_commit_handler_internal(output, func, user_data);
986 _pthread_mutex_unlock(&private_display->lock);
992 tdm_output_commit_internal(tdm_output *output, int sync, tdm_output_commit_handler func, void *user_data)
994 tdm_func_output *func_output;
995 tdm_private_output_commit_handler *output_commit_handler = NULL;
996 tdm_private_layer *private_layer = NULL;
997 tdm_output_dpms dpms_value = TDM_OUTPUT_DPMS_ON;
1001 func_output = &private_display->func_output;
1003 if (!func_output->output_commit) {
1004 /* LCOV_EXCL_START */
1005 TDM_ERR("not implemented!!");
1006 return TDM_ERROR_NOT_IMPLEMENTED;
1007 /* LCOV_EXCL_STOP */
1010 ret = tdm_output_get_dpms_internal(output, &dpms_value);
1011 TDM_RETURN_VAL_IF_FAIL(ret == TDM_ERROR_NONE, ret);
1013 if (!TDM_OUTPUT_DPMS_VSYNC_IS_OFF(dpms_value)) {
1015 if (!private_output->regist_commit_cb) {
1016 private_output->regist_commit_cb = 1;
1017 ret = func_output->output_set_commit_handler(private_output->output_backend,
1018 tdm_output_cb_commit);
1019 TDM_GOTO_IF_FAIL(ret == TDM_ERROR_NONE, commit_failed);
1022 output_commit_handler = calloc(1, sizeof(tdm_private_output_commit_handler));
1023 if (!output_commit_handler) {
1024 /* LCOV_EXCL_START */
1025 TDM_ERR("failed: alloc memory");
1026 return TDM_ERROR_OUT_OF_MEMORY;
1027 /* LCOV_EXCL_STOP */
1030 LIST_ADDTAIL(&output_commit_handler->link, &private_output->output_commit_handler_list);
1031 output_commit_handler->private_output = private_output;
1032 output_commit_handler->func = func;
1033 output_commit_handler->user_data = user_data;
1034 output_commit_handler->owner_tid = syscall(SYS_gettid);
1037 ret = func_output->output_commit(private_output->output_backend, sync,
1038 output_commit_handler);
1039 TDM_GOTO_IF_FAIL(ret == TDM_ERROR_NONE, commit_failed);
1041 if (tdm_debug_module & TDM_DEBUG_COMMIT)
1042 TDM_INFO("output(%d) backend commit: handle(%p) func(%p) user_data(%p)",
1043 private_output->pipe, output_commit_handler, func, user_data);
1046 /* Even if DPMS is off, committed_buffer should be changed because it will be referred
1047 * for tdm_layer_committed() function.
1049 LIST_FOR_EACH_ENTRY(private_layer, &private_output->layer_list, link) {
1050 if (!private_layer->waiting_buffer)
1053 private_layer->committed_buffer = private_layer->waiting_buffer;
1054 private_layer->waiting_buffer = NULL;
1055 if (tdm_debug_module & TDM_DEBUG_BUFFER)
1056 TDM_INFO("layer(%p) waiting_buffer(%p) committed_buffer(%p)",
1057 private_layer, private_layer->waiting_buffer,
1058 private_layer->committed_buffer->buffer);
1061 if (TDM_OUTPUT_DPMS_VSYNC_IS_OFF(dpms_value)) {
1062 TDM_WRN("dpms %s. Directly call commit handler instead of commit.", tdm_dpms_str(dpms_value));
1064 func(output, 0, 0, 0, user_data);
1070 /* LCOV_EXCL_START */
1071 if (output_commit_handler) {
1072 LIST_DEL(&output_commit_handler->link);
1073 free(output_commit_handler);
1076 /* LCOV_EXCL_STOP */
1080 tdm_output_commit(tdm_output *output, int sync, tdm_output_commit_handler func,
1083 tdm_private_layer *private_layer = NULL;
1085 OUTPUT_FUNC_ENTRY();
1087 _pthread_mutex_lock(&private_display->lock);
1089 if (private_output->commit_type == TDM_COMMIT_TYPE_NONE)
1090 private_output->commit_type = TDM_COMMIT_TYPE_OUTPUT;
1091 else if (private_output->commit_type == TDM_COMMIT_TYPE_LAYER) {
1092 TDM_ERR("Can't supported. Use tdm_layer_commit");
1093 _pthread_mutex_unlock(&private_display->lock);
1094 return TDM_ERROR_BAD_REQUEST;
1097 if (private_output->commit_per_vblank) {
1098 TDM_ERR("Use tdm_layer_commit");
1099 _pthread_mutex_unlock(&private_display->lock);
1100 return TDM_ERROR_BAD_REQUEST;
1103 if (TDM_OUTPUT_DPMS_VSYNC_IS_OFF(private_output->current_dpms_value)) {
1104 TDM_ERR("output(%d) dpms: %s", private_output->pipe,
1105 tdm_dpms_str(private_output->current_dpms_value));
1106 _pthread_mutex_unlock(&private_display->lock);
1107 return TDM_ERROR_DPMS_OFF;
1110 if (tdm_debug_module & TDM_DEBUG_COMMIT)
1111 TDM_INFO("output(%d) commit", private_output->pipe);
1113 /* apply the pending data of all layers */
1114 LIST_FOR_EACH_ENTRY(private_layer, &private_output->layer_list, link) {
1115 tdm_layer_commit_pending_data(private_layer);
1118 ret = tdm_output_commit_internal(output, sync, func, user_data);
1120 _pthread_mutex_unlock(&private_display->lock);
1126 tdm_output_set_mode(tdm_output *output, const tdm_output_mode *mode)
1128 tdm_func_output *func_output;
1129 OUTPUT_FUNC_ENTRY();
1131 TDM_RETURN_VAL_IF_FAIL(mode != NULL, TDM_ERROR_INVALID_PARAMETER);
1133 _pthread_mutex_lock(&private_display->lock);
1135 func_output = &private_display->func_output;
1137 if (!func_output->output_set_mode) {
1138 /* LCOV_EXCL_START */
1139 _pthread_mutex_unlock(&private_display->lock);
1140 TDM_ERR("not implemented!!");
1141 return TDM_ERROR_NOT_IMPLEMENTED;
1142 /* LCOV_EXCL_STOP */
1145 ret = func_output->output_set_mode(private_output->output_backend, mode);
1146 if (ret == TDM_ERROR_NONE) {
1147 private_output->current_mode = mode;
1148 TDM_INFO("mode: %dx%d %dhz", mode->hdisplay, mode->vdisplay, mode->vrefresh);
1151 _pthread_mutex_unlock(&private_display->lock);
1157 tdm_output_get_mode(tdm_output *output, const tdm_output_mode **mode)
1159 OUTPUT_FUNC_ENTRY();
1161 TDM_RETURN_VAL_IF_FAIL(mode != NULL, TDM_ERROR_INVALID_PARAMETER);
1163 _pthread_mutex_lock(&private_display->lock);
1165 *mode = private_output->current_mode;
1167 _pthread_mutex_unlock(&private_display->lock);
1173 _tdm_output_dpms_changed_timeout(void *user_data)
1175 tdm_private_output *private_output = user_data;
1178 value.u32 = private_output->current_dpms_value;
1179 tdm_output_call_change_handler_internal(private_output,
1180 &private_output->change_handler_list_sub,
1181 TDM_OUTPUT_CHANGE_DPMS,
1184 return TDM_ERROR_NONE;
1188 tdm_output_call_dpms_change_handler(tdm_output *output)
1190 tdm_private_output *private_output = (tdm_private_output*)output;
1193 /** Use timer to call the output change callback of the sub-thread.
1194 * The output change callback of tdm_server and tdm_vblank was called
1195 * in the main thread. And it made the multi thread issue. If we use
1196 * the timer, we can call the sub-thread's output change callback in
1199 if (!private_output->dpms_changed_timer) {
1200 private_output->dpms_changed_timer =
1201 tdm_event_loop_add_timer_handler(private_output->private_display,
1202 _tdm_output_dpms_changed_timeout, private_output, NULL);
1203 if (!private_output->dpms_changed_timer) {
1204 /* LCOV_EXCL_START */
1205 TDM_ERR("can't create dpms timer!!");
1206 return TDM_ERROR_OUT_OF_MEMORY;
1207 /* LCOV_EXCL_STOP */
1211 value.u32 = private_output->current_dpms_value;
1212 tdm_output_call_change_handler_internal(private_output,
1213 &private_output->change_handler_list_main,
1214 TDM_OUTPUT_CHANGE_DPMS,
1217 if (!LIST_IS_EMPTY(&private_output->change_handler_list_sub)) {
1218 tdm_error ret = tdm_event_loop_source_timer_update(private_output->dpms_changed_timer, 1);
1219 if (ret != TDM_ERROR_NONE)
1220 TDM_NEVER_GET_HERE();
1223 return TDM_ERROR_NONE;
1226 /* LCOV_EXCL_START */
1228 tdm_output_cb_dpms(tdm_output *output_backend, tdm_output_dpms dpms, void *user_data)
1230 tdm_private_display *private_display;
1231 tdm_private_output *private_output = user_data;
1234 TDM_RETURN_IF_FAIL(TDM_MUTEX_IS_LOCKED());
1235 TDM_RETURN_IF_FAIL(private_output);
1237 private_display = private_output->private_display;
1239 if (!tdm_thread_in_display_thread(syscall(SYS_gettid))) {
1240 tdm_thread_cb_output_dpms output_dpms;
1243 _tdm_output_update(output_backend, user_data);
1245 output_dpms.base.type = TDM_THREAD_CB_OUTPUT_DPMS;
1246 output_dpms.base.length = sizeof output_dpms;
1247 output_dpms.output_stamp = private_output->stamp;
1248 output_dpms.dpms = dpms;
1249 output_dpms.user_data = user_data;
1252 tdm_output_call_change_handler_internal(private_output,
1253 &private_output->change_handler_list_sub,
1254 TDM_OUTPUT_CHANGE_DPMS,
1257 ret = tdm_thread_send_cb(private_display->private_loop, &output_dpms.base);
1258 TDM_WARNING_IF_FAIL(ret == TDM_ERROR_NONE);
1263 private_output->current_dpms_value = dpms;
1264 private_output->waiting_dpms_change = 0;
1266 TDM_INFO("output(%d) dpms async '%s' done", private_output->pipe, tdm_dpms_str(dpms));
1269 tdm_output_call_change_handler_internal(private_output,
1270 &private_output->change_handler_list_main,
1271 TDM_OUTPUT_CHANGE_DPMS,
1274 /* LCOV_EXCL_STOP */
1277 tdm_output_set_dpms(tdm_output *output, tdm_output_dpms dpms_value)
1279 tdm_func_output *func_output;
1280 OUTPUT_FUNC_ENTRY();
1282 if (dpms_value > TDM_OUTPUT_DPMS_OFF) {
1283 if (dpms_value & TDM_OUTPUT_DPMS_DEFAULT_MASK) {
1284 TDM_ERR("Don't use the low-4bit for an extended DPMS mode: dpms_value(%x)", dpms_value);
1285 return TDM_ERROR_BAD_REQUEST;
1288 if (!(private_output->caps.capabilities & TDM_OUTPUT_CAPABILITY_EXTENDED_DPMS)) {
1289 TDM_ERR("output(%d) doesn't support the extended DPMS control: '%s'",
1290 private_output->pipe, tdm_dpms_str(dpms_value));
1291 return TDM_ERROR_BAD_REQUEST;
1295 _pthread_mutex_lock(&private_display->lock);
1297 if (private_output->waiting_dpms_change) {
1298 TDM_ERR("DPMS is not changed yet. Can't be changed twice");
1299 _pthread_mutex_unlock(&private_display->lock);
1300 return TDM_ERROR_BAD_REQUEST;
1303 func_output = &private_display->func_output;
1305 TDM_INFO("output(%d) dpms '%s'", private_output->pipe, tdm_dpms_str(dpms_value));
1307 if (func_output->output_set_dpms)
1308 ret = func_output->output_set_dpms(private_output->output_backend, dpms_value);
1310 /* LCOV_EXCL_START */
1311 ret = TDM_ERROR_NONE;
1312 TDM_WRN("not implemented!!");
1314 /* LCOV_EXCL_STOP */
1318 if (ret == TDM_ERROR_NONE) {
1319 if (private_output->current_dpms_value != dpms_value) {
1320 private_output->current_dpms_value = dpms_value;
1321 TDM_INFO("output(%d) dpms '%s' done", private_output->pipe, tdm_dpms_str(dpms_value));
1322 tdm_output_call_dpms_change_handler(output);
1325 tdm_output_dpms temp = TDM_OUTPUT_DPMS_OFF;
1327 /* update current_dpms_value forcely */
1328 tdm_output_get_dpms_internal(output, &temp);
1330 TDM_ERR("output(%d) set_dpms failed: dpms '%s'", private_output->pipe, tdm_dpms_str(temp));
1333 _pthread_mutex_unlock(&private_display->lock);
1338 /* LCOV_EXCL_START */
1340 tdm_output_set_dpms_async(tdm_output *output, tdm_output_dpms dpms_value)
1342 tdm_func_output *func_output;
1343 OUTPUT_FUNC_ENTRY();
1345 if (!(private_output->caps.capabilities & TDM_OUTPUT_CAPABILITY_ASYNC_DPMS)) {
1346 TDM_ERR("output doesn't support the asynchronous DPMS control!");
1347 return TDM_ERROR_BAD_REQUEST;
1350 if (dpms_value > TDM_OUTPUT_DPMS_OFF) {
1351 if (dpms_value & TDM_OUTPUT_DPMS_DEFAULT_MASK) {
1352 TDM_ERR("Don't use the low-4bit for an extended DPMS mode: dpms_value(%x)", dpms_value);
1353 return TDM_ERROR_BAD_REQUEST;
1356 if (!(private_output->caps.capabilities & TDM_OUTPUT_CAPABILITY_EXTENDED_DPMS)) {
1357 TDM_ERR("output(%d) doesn't support the extended DPMS control: '%s'",
1358 private_output->pipe, tdm_dpms_str(dpms_value));
1359 return TDM_ERROR_BAD_REQUEST;
1363 _pthread_mutex_lock(&private_display->lock);
1365 if (private_output->waiting_dpms_change) {
1366 TDM_ERR("DPMS is not changed yet. Can't be changed twice");
1367 _pthread_mutex_unlock(&private_display->lock);
1368 return TDM_ERROR_BAD_REQUEST;
1371 func_output = &private_display->func_output;
1372 if (!func_output->output_set_dpms_handler) {
1373 TDM_ERR("not implemented: output_set_dpms_handler");
1374 _pthread_mutex_unlock(&private_display->lock);
1375 return TDM_ERROR_NOT_IMPLEMENTED;
1378 if (!func_output->output_set_dpms_async) {
1379 TDM_ERR("not implemented: output_set_dpms_async");
1380 _pthread_mutex_unlock(&private_display->lock);
1381 return TDM_ERROR_NOT_IMPLEMENTED;
1384 if (!private_output->regist_dpms_cb) {
1385 private_output->regist_dpms_cb = 1;
1386 ret = func_output->output_set_dpms_handler(private_output->output_backend,
1387 tdm_output_cb_dpms, private_output);
1388 if (ret != TDM_ERROR_NONE) {
1389 _pthread_mutex_unlock(&private_display->lock);
1390 TDM_ERR("Can't set the dpms handler!!");
1395 TDM_INFO("output(%d) dpms async '%s'", private_output->pipe, tdm_dpms_str(dpms_value));
1397 ret = func_output->output_set_dpms_async(private_output->output_backend, dpms_value);
1399 if (ret == TDM_ERROR_NONE) {
1400 private_output->waiting_dpms_change = 1;
1401 TDM_INFO("output(%d) dpms async '%s' waiting", private_output->pipe, tdm_dpms_str(dpms_value));
1403 tdm_output_dpms temp = TDM_OUTPUT_DPMS_OFF;
1405 /* update current_dpms_value forcely */
1406 tdm_output_get_dpms_internal(output, &temp);
1408 TDM_ERR("output(%d) set_dpms_async failed: dpms '%s'", private_output->pipe, tdm_dpms_str(temp));
1411 _pthread_mutex_unlock(&private_display->lock);
1415 /* LCOV_EXCL_STOP */
1418 tdm_output_get_dpms_internal(tdm_output *output, tdm_output_dpms *dpms_value)
1420 tdm_func_output *func_output;
1421 OUTPUT_FUNC_ENTRY();
1423 TDM_RETURN_VAL_IF_FAIL(private_output != NULL, TDM_ERROR_INVALID_PARAMETER);
1425 /* TODO: this is ugly. But before calling backend's output_get_dpms(), we have
1426 * to check if all backends's DPMS operation has no problem. In future, we'd
1427 * better use new env instead of using commit_per_vblank variable to distinguish
1428 * whether we use the stored value or backend's output_get_dpms.
1430 if (!private_output->commit_per_vblank) {
1431 *dpms_value = private_output->current_dpms_value;
1432 return TDM_ERROR_NONE;
1435 func_output = &private_display->func_output;
1437 if (!func_output->output_get_dpms) {
1438 /* LCOV_EXCL_START */
1439 *dpms_value = private_output->current_dpms_value;
1440 TDM_WRN("not implemented!!");
1441 return TDM_ERROR_NONE;
1442 /* LCOV_EXCL_STOP */
1445 ret = func_output->output_get_dpms(private_output->output_backend, dpms_value);
1446 if (ret != TDM_ERROR_NONE) {
1447 /* LCOV_EXCL_START */
1448 TDM_ERR("output_get_dpms failed");
1449 *dpms_value = TDM_OUTPUT_DPMS_OFF;
1450 /* LCOV_EXCL_STOP */
1453 /* checking with backend's value */
1454 if (*dpms_value != private_output->current_dpms_value) {
1455 TDM_ERR("output(%d) dpms changed suddenly: %s -> %s",
1456 private_output->pipe, private_output->current_dpms_value,
1457 tdm_dpms_str(*dpms_value));
1458 private_output->current_dpms_value = *dpms_value;
1459 tdm_output_call_dpms_change_handler(output);
1466 tdm_output_get_dpms(tdm_output *output, tdm_output_dpms *dpms_value)
1468 OUTPUT_FUNC_ENTRY();
1470 TDM_RETURN_VAL_IF_FAIL(dpms_value != NULL, TDM_ERROR_INVALID_PARAMETER);
1472 _pthread_mutex_lock(&private_display->lock);
1474 ret = tdm_output_get_dpms_internal(output, dpms_value);
1476 _pthread_mutex_unlock(&private_display->lock);
1481 EXTERN tdm_capture *
1482 tdm_output_create_capture(tdm_output *output, tdm_error *error)
1484 tdm_capture *capture = NULL;
1486 OUTPUT_FUNC_ENTRY_ERROR();
1488 _pthread_mutex_lock(&private_display->lock);
1490 capture = (tdm_capture *)tdm_capture_create_output_internal(private_output, error);
1492 _pthread_mutex_unlock(&private_display->lock);
1497 EXTERN tdm_hwc_window *
1498 tdm_output_hwc_create_window(tdm_output *output, tdm_error *error)
1500 tdm_hwc_window *hwc_window = NULL;
1502 OUTPUT_FUNC_ENTRY_ERROR();
1504 _pthread_mutex_lock(&private_display->lock);
1506 if (private_output->caps.capabilities & TDM_OUTPUT_CAPABILITY_HWC)
1507 hwc_window = (tdm_hwc_window *)tdm_hwc_window_create_internal(private_output, 0, error);
1509 /* LCOV_EXCL_START */
1510 TDM_ERR("output(%p) not support HWC", private_output);
1512 *error = TDM_ERROR_BAD_REQUEST;
1513 /* LCOV_EXCL_STOP */
1516 _pthread_mutex_unlock(&private_display->lock);
1521 EXTERN tdm_hwc_window *
1522 tdm_output_hwc_create_video_window(tdm_output *output, tdm_error *error)
1524 tdm_hwc_window *hwc_window = NULL;
1526 OUTPUT_FUNC_ENTRY_ERROR();
1528 _pthread_mutex_lock(&private_display->lock);
1530 if (private_output->caps.capabilities & TDM_OUTPUT_CAPABILITY_HWC)
1531 hwc_window = (tdm_hwc_window *)tdm_hwc_window_create_internal(private_output, 1, error);
1533 /* LCOV_EXCL_START */
1534 TDM_ERR("output(%p) not support HWC", private_output);
1536 *error = TDM_ERROR_BAD_REQUEST;
1537 /* LCOV_EXCL_STOP */
1540 _pthread_mutex_unlock(&private_display->lock);
1546 tdm_output_hwc_destroy_window(tdm_output *output, tdm_hwc_window *hwc_window)
1548 OUTPUT_FUNC_ENTRY();
1550 TDM_RETURN_VAL_IF_FAIL(hwc_window != NULL, TDM_ERROR_INVALID_PARAMETER);
1552 _pthread_mutex_lock(&private_display->lock);
1554 ret = tdm_hwc_window_destroy_internal(hwc_window);
1556 _pthread_mutex_unlock(&private_display->lock);
1562 tdm_output_hwc_validate(tdm_output *output, tdm_hwc_window **composited_wnds,
1563 uint32_t num_wnds, uint32_t *num_types)
1565 tdm_func_output *func_output = NULL;
1566 tdm_private_hwc_window **composited_wnds_frontend = NULL;
1567 tdm_hwc_window **composited_wnds_backend = NULL;
1570 OUTPUT_FUNC_ENTRY();
1572 TDM_RETURN_VAL_IF_FAIL(num_types != NULL, TDM_ERROR_INVALID_PARAMETER);
1574 _pthread_mutex_lock(&private_display->lock);
1576 if (!(private_output->caps.capabilities & TDM_OUTPUT_CAPABILITY_HWC)) {
1577 TDM_ERR("output(%p) not support HWC", private_output);
1578 _pthread_mutex_unlock(&private_display->lock);
1579 return TDM_ERROR_BAD_REQUEST;
1582 func_output = &private_display->func_output;
1584 if (!func_output->output_hwc_validate) {
1585 /* LCOV_EXCL_START */
1586 _pthread_mutex_unlock(&private_display->lock);
1587 TDM_ERR("not implemented!!");
1588 return TDM_ERROR_NOT_IMPLEMENTED;
1589 /* LCOV_EXCL_STOP */
1592 if (num_wnds == 0) {
1593 ret = func_output->output_hwc_validate(private_output->output_backend, NULL, 0, num_types);
1595 _pthread_mutex_unlock(&private_display->lock);
1600 composited_wnds_backend = calloc(num_wnds, sizeof(tdm_hwc_window *));
1601 if (!composited_wnds_backend) {
1602 /* LCOV_EXCL_START */
1603 _pthread_mutex_unlock(&private_display->lock);
1604 return TDM_ERROR_OUT_OF_MEMORY;
1605 /* LCOV_EXCL_STOP */
1608 composited_wnds_frontend = (tdm_private_hwc_window **)composited_wnds;
1610 for (i = 0; i < num_wnds; i++)
1611 composited_wnds_backend[i] = composited_wnds_frontend[i]->hwc_window_backend;
1613 ret = func_output->output_hwc_validate(private_output->output_backend, composited_wnds_backend, num_wnds, num_types);
1615 free(composited_wnds_backend);
1617 _pthread_mutex_unlock(&private_display->lock);
1623 tdm_output_hwc_set_need_validate_handler(tdm_output *output,
1624 tdm_output_need_validate_handler hndl)
1626 OUTPUT_FUNC_ENTRY();
1628 TDM_RETURN_VAL_IF_FAIL(hndl != NULL, TDM_ERROR_INVALID_PARAMETER);
1630 _pthread_mutex_lock(&private_display->lock);
1632 if (!(private_output->caps.capabilities & TDM_OUTPUT_CAPABILITY_HWC)) {
1633 TDM_ERR("output(%p) not support HWC", private_output);
1634 _pthread_mutex_unlock(&private_display->lock);
1635 return TDM_ERROR_BAD_REQUEST;
1638 /* there's no reason to allow this */
1639 if (private_output->need_validate.hndl) {
1641 _pthread_mutex_unlock(&private_display->lock);
1642 return TDM_ERROR_OPERATION_FAILED;
1645 private_output->need_validate.hndl = hndl;
1647 _pthread_mutex_unlock(&private_display->lock);
1653 tdm_output_hwc_get_changed_composition_types(tdm_output *output,
1654 uint32_t *num_elements,
1655 tdm_hwc_window **hwc_window,
1656 tdm_hwc_window_composition *composition_types)
1658 tdm_func_output *func_output = NULL;
1659 tdm_private_hwc_window * private_hwc_window = NULL;
1662 OUTPUT_FUNC_ENTRY();
1664 TDM_RETURN_VAL_IF_FAIL(num_elements != NULL, TDM_ERROR_INVALID_PARAMETER);
1666 _pthread_mutex_lock(&private_display->lock);
1668 if (!(private_output->caps.capabilities & TDM_OUTPUT_CAPABILITY_HWC)) {
1669 TDM_ERR("output(%p) not support HWC", private_output);
1670 _pthread_mutex_unlock(&private_display->lock);
1671 return TDM_ERROR_BAD_REQUEST;
1674 func_output = &private_display->func_output;
1676 if (!func_output->output_hwc_get_changed_composition_types) {
1677 /* LCOV_EXCL_START */
1678 _pthread_mutex_unlock(&private_display->lock);
1679 TDM_ERR("not implemented!!");
1680 return TDM_ERROR_NOT_IMPLEMENTED;
1681 /* LCOV_EXCL_STOP */
1684 ret = func_output->output_hwc_get_changed_composition_types(private_output->output_backend,
1685 num_elements, hwc_window, composition_types);
1686 if (ret != TDM_ERROR_NONE) {
1687 /* LCOV_EXCL_START */
1688 _pthread_mutex_unlock(&private_display->lock);
1690 /* LCOV_EXCL_STOP */
1693 if (hwc_window == NULL || composition_types == NULL) {
1694 _pthread_mutex_unlock(&private_display->lock);
1695 return TDM_ERROR_NONE;
1698 for (i = 0; i < *num_elements; i++) {
1700 private_hwc_window = _tdm_output_find_private_hwc_window(private_output, hwc_window[i]);
1702 if (private_hwc_window == NULL) {
1703 /* LCOV_EXCL_START */
1704 TDM_ERR("failed! This should never happen!");
1705 func_output->output_hwc_destroy_window(private_output->output_backend, hwc_window[i]);
1707 _pthread_mutex_unlock(&private_display->lock);
1708 return TDM_ERROR_OPERATION_FAILED;
1709 /* LCOV_EXCL_STOP */
1712 hwc_window[i] = (tdm_hwc_window*)private_hwc_window;
1715 _pthread_mutex_unlock(&private_display->lock);
1721 tdm_output_hwc_accept_changes(tdm_output *output)
1723 tdm_func_output *func_output = NULL;
1725 OUTPUT_FUNC_ENTRY();
1727 _pthread_mutex_lock(&private_display->lock);
1729 if (!(private_output->caps.capabilities & TDM_OUTPUT_CAPABILITY_HWC)) {
1730 TDM_ERR("output(%p) not support HWC", private_output);
1731 _pthread_mutex_unlock(&private_display->lock);
1732 return TDM_ERROR_BAD_REQUEST;
1735 func_output = &private_display->func_output;
1737 if (!func_output->output_hwc_validate) {
1738 /* LCOV_EXCL_START */
1739 _pthread_mutex_unlock(&private_display->lock);
1740 TDM_ERR("not implemented!!");
1741 return TDM_ERROR_NOT_IMPLEMENTED;
1742 /* LCOV_EXCL_STOP */
1745 ret = func_output->output_hwc_accept_changes(private_output->output_backend);
1747 _pthread_mutex_unlock(&private_display->lock);
1753 tdm_output_hwc_get_target_buffer_queue(tdm_output *output, tdm_error *error)
1755 tdm_func_output *func_output = NULL;
1756 tbm_surface_queue_h queue = NULL;
1758 OUTPUT_FUNC_ENTRY_ERROR();
1760 _pthread_mutex_lock(&private_display->lock);
1762 if (!(private_output->caps.capabilities & TDM_OUTPUT_CAPABILITY_HWC)) {
1763 TDM_ERR("output(%p) not support HWC", private_output);
1765 *error = TDM_ERROR_BAD_REQUEST;
1766 _pthread_mutex_unlock(&private_display->lock);
1770 func_output = &private_display->func_output;
1772 if (!func_output->output_hwc_get_target_buffer_queue) {
1773 /* LCOV_EXCL_START */
1774 _pthread_mutex_unlock(&private_display->lock);
1775 TDM_ERR("not implemented!!");
1777 /* LCOV_EXCL_STOP */
1780 queue = func_output->output_hwc_get_target_buffer_queue(private_output->output_backend, error);
1782 _pthread_mutex_unlock(&private_display->lock);
1788 tdm_output_hwc_set_client_target_buffer(tdm_output *output, tbm_surface_h target_buffer, tdm_hwc_region damage)
1790 tdm_func_output *func_output = NULL;
1792 OUTPUT_FUNC_ENTRY();
1794 _pthread_mutex_lock(&private_display->lock);
1796 if (!(private_output->caps.capabilities & TDM_OUTPUT_CAPABILITY_HWC)) {
1797 TDM_ERR("output(%p) not support HWC", private_output);
1798 _pthread_mutex_unlock(&private_display->lock);
1799 return TDM_ERROR_BAD_REQUEST;
1802 if (tdm_debug_dump & TDM_DUMP_FLAG_WINDOW) {
1803 /* LCOV_EXCL_START */
1804 char str[TDM_PATH_LEN];
1806 snprintf(str, TDM_PATH_LEN, "target_window_%d_%03d",
1807 private_output->index, i++);
1808 tdm_helper_dump_buffer_str(target_buffer, tdm_debug_dump_dir, str);
1809 /* LCOV_EXCL_STOP */
1812 func_output = &private_display->func_output;
1814 if (!func_output->output_hwc_set_client_target_buffer) {
1815 /* LCOV_EXCL_START */
1816 _pthread_mutex_unlock(&private_display->lock);
1817 TDM_ERR("not implemented!!");
1818 return TDM_ERROR_NOT_IMPLEMENTED;
1819 /* LCOV_EXCL_STOP */
1822 ret = func_output->output_hwc_set_client_target_buffer(private_output->output_backend, target_buffer, damage);
1824 _pthread_mutex_unlock(&private_display->lock);
1830 tdm_output_hwc_get_video_supported_formats(tdm_output *output, const tbm_format **formats,
1833 tdm_func_output *func_output;
1834 OUTPUT_FUNC_ENTRY();
1836 TDM_RETURN_VAL_IF_FAIL(formats != NULL, TDM_ERROR_INVALID_PARAMETER);
1837 TDM_RETURN_VAL_IF_FAIL(count != NULL, TDM_ERROR_INVALID_PARAMETER);
1839 _pthread_mutex_lock(&private_display->lock);
1841 func_output = &private_display->func_output;
1843 if (!func_output->output_hwc_get_video_supported_formats) {
1844 /* LCOV_EXCL_START */
1845 _pthread_mutex_unlock(&private_display->lock);
1846 TDM_ERR("not implemented!!");
1847 return TDM_ERROR_NOT_IMPLEMENTED;
1848 /* LCOV_EXCL_STOP */
1851 ret = func_output->output_hwc_get_video_supported_formats(
1852 private_output->output_backend, formats, count);
1854 _pthread_mutex_unlock(&private_display->lock);
1860 tdm_output_call_change_handler_internal(tdm_private_output *private_output,
1861 struct list_head *change_handler_list,
1862 tdm_output_change_type type,
1864 int no_check_thread_id)
1866 tdm_private_display *private_display;
1867 tdm_private_change_handler *change_handler = NULL;
1869 TDM_RETURN_IF_FAIL(TDM_MUTEX_IS_LOCKED());
1870 TDM_RETURN_IF_FAIL(private_output);
1872 private_display = private_output->private_display;
1873 if (!tdm_thread_in_display_thread(syscall(SYS_gettid))) {
1874 if (type & TDM_OUTPUT_CHANGE_CONNECTION)
1875 TDM_INFO("output(%d) changed: %s (%d)",
1876 private_output->pipe, tdm_status_str(value.u32), value.u32);
1877 if (type & TDM_OUTPUT_CHANGE_DPMS)
1878 TDM_INFO("output(%d) changed: dpms %s (%d)",
1879 private_output->pipe, tdm_dpms_str(value.u32), value.u32);
1882 if (LIST_IS_EMPTY(change_handler_list))
1885 LIST_FOR_EACH_ENTRY(change_handler, change_handler_list, link) {
1886 if (!no_check_thread_id && change_handler->owner_tid != syscall(SYS_gettid))
1887 TDM_NEVER_GET_HERE();
1889 _pthread_mutex_unlock(&private_display->lock);
1890 change_handler->func(private_output, type,
1891 value, change_handler->user_data);
1892 _pthread_mutex_lock(&private_display->lock);
1897 _is_hwc_output_still_existed(tdm_private_output *private_output)
1899 tdm_private_display *dpy;
1900 tdm_private_output *o = NULL;
1902 dpy = tdm_display_init(NULL);
1903 TDM_RETURN_VAL_IF_FAIL(dpy != NULL, TDM_ERROR_OPERATION_FAILED);
1905 LIST_FOR_EACH_ENTRY(o, &dpy->output_list, link) {
1906 if (!(o->caps.capabilities & TDM_OUTPUT_CAPABILITY_HWC))
1909 if (o == private_output)
1913 tdm_display_deinit(dpy);
1917 tdm_display_deinit(dpy);
1921 /* gets called on behalf of the ecore-main-loop thread */
1923 tdm_output_cb_need_validate(tdm_private_output *private_output)
1925 TDM_RETURN_VAL_IF_FAIL(private_output != NULL, TDM_ERROR_INVALID_PARAMETER);
1927 /* as we get 'private_output' within an event, an output this 'private_output'
1928 * points to can be destroyed already */
1929 if (!_is_hwc_output_still_existed(private_output))
1930 return TDM_ERROR_NONE;
1932 TDM_INFO("tdm-backend asks for revalidation for the output:%p.", private_output);
1934 if (private_output->need_validate.hndl)
1935 private_output->need_validate.hndl((tdm_output*)private_output);
1937 return TDM_ERROR_NONE;
1940 /* gets called on behalf of the tdm-thread */
1942 _need_validate_handler(int fd, tdm_event_loop_mask mask, void *user_data)
1944 tdm_thread_cb_need_validate ev;
1945 tdm_private_output *private_output;
1949 private_output = (tdm_private_output *)user_data;
1951 if (read(private_output->need_validate.event_fd, &value, sizeof(value)) < 0) {
1952 TDM_ERR("error while trying to read from a need_validate.event_fd fd.");
1953 return TDM_ERROR_OPERATION_FAILED;
1956 ev.base.type = TDM_THREAD_CB_NEED_VALIDATE;
1957 ev.base.length = sizeof ev;
1958 ev.o = private_output;
1960 ret = tdm_thread_send_cb(private_output->private_display->private_loop, &ev.base);
1961 TDM_WARNING_IF_FAIL(ret == TDM_ERROR_NONE);
1963 TDM_INFO("tdm-thread: get a 'need to revalidate' event for the ouptut:%p.", private_output);
1965 /* who cares about this? */
1966 return TDM_ERROR_NONE;
1970 tdm_output_need_validate_event_init(tdm_output *output)
1974 OUTPUT_FUNC_ENTRY();
1976 TDM_RETURN_VAL_IF_FAIL(TDM_MUTEX_IS_LOCKED(), TDM_ERROR_OPERATION_FAILED);
1978 if (!(private_output->caps.capabilities & TDM_OUTPUT_CAPABILITY_HWC)) {
1979 TDM_ERR("output(%p) not support HWC", private_output);
1980 return TDM_ERROR_BAD_REQUEST;
1983 /* build in eventfd fds into event_loop listened & handled by the tdm-thread */
1985 TDM_WARNING_IF_FAIL(fd >= 0);
1987 private_output->need_validate.event_source = tdm_event_loop_add_fd_handler(private_display,
1988 fd, TDM_EVENT_LOOP_READABLE, _need_validate_handler, private_output, &ret);
1989 TDM_WARNING_IF_FAIL(ret == TDM_ERROR_NONE);
1991 private_output->need_validate.event_fd = fd;
1993 TDM_INFO("register an output:%p for the revalidation, event_fd:%d.", private_output, fd);
1999 tdm_output_choose_commit_per_vblank_mode(tdm_private_output *private_output, int mode)
2001 if (!private_output)
2002 return TDM_ERROR_INVALID_PARAMETER;
2004 if (mode < 0 || mode > 2)
2005 return TDM_ERROR_INVALID_PARAMETER;
2007 private_output->commit_per_vblank = mode;
2009 if (private_output->commit_per_vblank == 0)
2010 TDM_INFO("commit per vblank: disable");
2011 else if (private_output->commit_per_vblank == 1)
2012 TDM_INFO("commit per vblank: enable (1 layer)");
2013 else if (private_output->commit_per_vblank == 2)
2014 TDM_INFO("commit per vblank: enable (previous commit)");
2016 return TDM_ERROR_NONE;