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 static tdm_private_hwc_window *
65 _tdm_output_find_private_hwc_window(tdm_private_output *private_output,
66 tdm_hwc_window *hwc_window_backend)
68 tdm_private_hwc_window *private_hwc_window = NULL;
70 LIST_FOR_EACH_ENTRY(private_hwc_window, &private_output->hwc_window_list, link) {
71 if (private_hwc_window->hwc_window_backend == hwc_window_backend)
72 return private_hwc_window;
79 tdm_output_get_model_info(tdm_output *output, const char **maker,
80 const char **model, const char **name)
84 _pthread_mutex_lock(&private_display->lock);
87 *maker = private_output->caps.maker;
89 *model = private_output->caps.model;
91 *name = private_output->caps.name;
93 _pthread_mutex_unlock(&private_display->lock);
99 tdm_output_get_capabilities(tdm_output *output, tdm_output_capability *capabilities)
103 TDM_RETURN_VAL_IF_FAIL(capabilities != NULL, TDM_ERROR_INVALID_PARAMETER);
105 _pthread_mutex_lock(&private_display->lock);
107 *capabilities = private_output->caps.capabilities;
109 _pthread_mutex_unlock(&private_display->lock);
115 tdm_output_get_conn_status(tdm_output *output, tdm_output_conn_status *status)
119 TDM_RETURN_VAL_IF_FAIL(status != NULL, TDM_ERROR_INVALID_PARAMETER);
121 _pthread_mutex_lock(&private_display->lock);
123 *status = private_output->caps.status;
125 _pthread_mutex_unlock(&private_display->lock);
130 /* LCOV_EXCL_START */
132 _tdm_output_update(tdm_output *output_backend, void *user_data)
134 tdm_private_display *private_display;
135 tdm_private_output *private_output = user_data;
138 TDM_RETURN_IF_FAIL(private_output);
140 private_display = private_output->private_display;
142 ret = tdm_display_update_output(private_display, output_backend, private_output->pipe);
143 TDM_RETURN_IF_FAIL(ret == TDM_ERROR_NONE);
147 tdm_output_cb_status(tdm_output *output_backend, tdm_output_conn_status status,
150 tdm_private_display *private_display;
151 tdm_private_output *private_output = user_data;
154 TDM_RETURN_IF_FAIL(TDM_MUTEX_IS_LOCKED());
155 TDM_RETURN_IF_FAIL(private_output);
157 private_display = private_output->private_display;
159 if (!tdm_thread_in_display_thread(syscall(SYS_gettid))) {
160 tdm_thread_cb_output_status output_status;
163 TDM_INFO("output(%d) %s", private_output->pipe, tdm_status_str(status));
165 _tdm_output_update(output_backend, user_data);
167 output_status.base.type = TDM_THREAD_CB_OUTPUT_STATUS;
168 output_status.base.length = sizeof output_status;
169 output_status.output_stamp = private_output->stamp;
170 output_status.status = status;
171 output_status.user_data = user_data;
174 tdm_output_call_change_handler_internal(private_output,
175 &private_output->change_handler_list_sub,
176 TDM_OUTPUT_CHANGE_CONNECTION,
179 ret = tdm_thread_send_cb(private_display->private_loop, &output_status.base);
180 TDM_WARNING_IF_FAIL(ret == TDM_ERROR_NONE);
185 TDM_INFO("output(%d) %s", private_output->pipe, tdm_status_str(status));
187 if (!tdm_thread_is_running())
188 _tdm_output_update(output_backend, user_data);
191 tdm_output_call_change_handler_internal(private_output,
192 &private_output->change_handler_list_main,
193 TDM_OUTPUT_CHANGE_CONNECTION,
199 tdm_output_add_change_handler(tdm_output *output,
200 tdm_output_change_handler func,
203 tdm_private_change_handler *change_handler;
206 TDM_RETURN_VAL_IF_FAIL(func != NULL, TDM_ERROR_INVALID_PARAMETER);
208 pthread_mutex_lock(&private_display->lock);
210 change_handler = calloc(1, sizeof(tdm_private_change_handler));
211 if (!change_handler) {
212 /* LCOV_EXCL_START */
213 TDM_ERR("failed: alloc memory");
214 _pthread_mutex_unlock(&private_display->lock);
215 return TDM_ERROR_OUT_OF_MEMORY;
219 change_handler->private_output = private_output;
220 change_handler->func = func;
221 change_handler->user_data = user_data;
222 change_handler->owner_tid = syscall(SYS_gettid);
224 if (!tdm_thread_in_display_thread(change_handler->owner_tid))
225 LIST_ADDTAIL(&change_handler->link, &private_output->change_handler_list_sub);
227 LIST_ADDTAIL(&change_handler->link, &private_output->change_handler_list_main);
229 _pthread_mutex_unlock(&private_display->lock);
235 tdm_output_remove_change_handler(tdm_output *output,
236 tdm_output_change_handler func,
239 tdm_private_display *private_display;
240 tdm_private_output *private_output;
241 tdm_private_change_handler *h = NULL, *hh = NULL;
243 TDM_RETURN_IF_FAIL(output != NULL);
244 TDM_RETURN_IF_FAIL(func != NULL);
246 private_output = (tdm_private_output*)output;
247 private_display = private_output->private_display;
249 _pthread_mutex_lock(&private_display->lock);
251 LIST_FOR_EACH_ENTRY_SAFE(h, hh, &private_output->change_handler_list_main, link) {
252 if (h->func != func || h->user_data != user_data)
258 _pthread_mutex_unlock(&private_display->lock);
263 LIST_FOR_EACH_ENTRY_SAFE(h, hh, &private_output->change_handler_list_sub, link) {
264 if (h->func != func || h->user_data != user_data)
270 _pthread_mutex_unlock(&private_display->lock);
275 _pthread_mutex_unlock(&private_display->lock);
279 tdm_output_get_output_type(tdm_output *output, tdm_output_type *type)
283 TDM_RETURN_VAL_IF_FAIL(type != NULL, TDM_ERROR_INVALID_PARAMETER);
285 _pthread_mutex_lock(&private_display->lock);
287 *type = private_output->caps.type;
289 _pthread_mutex_unlock(&private_display->lock);
295 tdm_output_get_layer_count(tdm_output *output, int *count)
297 tdm_private_layer *private_layer = NULL;
301 TDM_RETURN_VAL_IF_FAIL(count != NULL, TDM_ERROR_INVALID_PARAMETER);
303 _pthread_mutex_lock(&private_display->lock);
305 if (private_output->caps.capabilities & TDM_OUTPUT_CAPABILITY_HWC) {
306 TDM_ERR("output(%p) support HWC. Use HWC functions", private_output);
308 _pthread_mutex_unlock(&private_display->lock);
309 return TDM_ERROR_BAD_REQUEST;
313 LIST_FOR_EACH_ENTRY(private_layer, &private_output->layer_list, link)
316 _pthread_mutex_unlock(&private_display->lock);
317 return TDM_ERROR_NONE;
320 _pthread_mutex_unlock(&private_display->lock);
327 tdm_output_get_layer(tdm_output *output, int index, tdm_error *error)
329 tdm_private_layer *private_layer = NULL;
331 OUTPUT_FUNC_ENTRY_ERROR();
333 _pthread_mutex_lock(&private_display->lock);
336 *error = TDM_ERROR_NONE;
338 if (private_output->caps.capabilities & TDM_OUTPUT_CAPABILITY_HWC) {
339 _pthread_mutex_unlock(&private_display->lock);
340 TDM_ERR("output(%p) support HWC. Use HWC functions", private_output);
342 *error = TDM_ERROR_BAD_REQUEST;
346 LIST_FOR_EACH_ENTRY(private_layer, &private_output->layer_list, link) {
347 if (private_layer->index == index) {
348 _pthread_mutex_unlock(&private_display->lock);
349 return private_layer;
353 _pthread_mutex_unlock(&private_display->lock);
359 tdm_output_get_available_properties(tdm_output *output, const tdm_prop **props,
364 TDM_RETURN_VAL_IF_FAIL(props != NULL, TDM_ERROR_INVALID_PARAMETER);
365 TDM_RETURN_VAL_IF_FAIL(count != NULL, TDM_ERROR_INVALID_PARAMETER);
367 _pthread_mutex_lock(&private_display->lock);
369 *props = (const tdm_prop *)private_output->caps.props;
370 *count = private_output->caps.prop_count;
372 _pthread_mutex_unlock(&private_display->lock);
378 tdm_output_get_available_modes(tdm_output *output,
379 const tdm_output_mode **modes, int *count)
383 TDM_RETURN_VAL_IF_FAIL(modes != NULL, TDM_ERROR_INVALID_PARAMETER);
384 TDM_RETURN_VAL_IF_FAIL(count != NULL, TDM_ERROR_INVALID_PARAMETER);
386 _pthread_mutex_lock(&private_display->lock);
388 *modes = (const tdm_output_mode *)private_output->caps.modes;
389 *count = private_output->caps.mode_count;
391 _pthread_mutex_unlock(&private_display->lock);
397 tdm_output_get_available_size(tdm_output *output, int *min_w, int *min_h,
398 int *max_w, int *max_h, int *preferred_align)
402 _pthread_mutex_lock(&private_display->lock);
405 *min_w = TDM_FRONT_VALUE(private_output->caps.min_w);
407 *min_h = TDM_FRONT_VALUE(private_output->caps.min_h);
409 *max_w = TDM_FRONT_VALUE(private_output->caps.max_w);
411 *max_h = TDM_FRONT_VALUE(private_output->caps.max_h);
413 *preferred_align = TDM_FRONT_VALUE(private_output->caps.preferred_align);
415 _pthread_mutex_unlock(&private_display->lock);
421 tdm_output_get_cursor_available_size(tdm_output *output, int *min_w, int *min_h,
422 int *max_w, int *max_h, int *preferred_align)
426 _pthread_mutex_lock(&private_display->lock);
428 if (!tdm_display_check_module_abi(private_display, 1, 5)) {
439 *preferred_align = -1;
441 _pthread_mutex_unlock(&private_display->lock);
443 return TDM_ERROR_BAD_MODULE;
447 *min_w = TDM_FRONT_VALUE(private_output->caps.cursor_min_w);
449 *min_h = TDM_FRONT_VALUE(private_output->caps.cursor_min_h);
451 *max_w = TDM_FRONT_VALUE(private_output->caps.cursor_max_w);
453 *max_h = TDM_FRONT_VALUE(private_output->caps.cursor_max_h);
455 *preferred_align = TDM_FRONT_VALUE(private_output->caps.cursor_preferred_align);
457 _pthread_mutex_unlock(&private_display->lock);
463 tdm_output_get_physical_size(tdm_output *output, unsigned int *mmWidth,
464 unsigned int *mmHeight)
468 _pthread_mutex_lock(&private_display->lock);
471 *mmWidth = private_output->caps.mmWidth;
473 *mmHeight = private_output->caps.mmHeight;
475 _pthread_mutex_unlock(&private_display->lock);
481 tdm_output_get_subpixel(tdm_output *output, unsigned int *subpixel)
484 TDM_RETURN_VAL_IF_FAIL(subpixel != NULL, TDM_ERROR_INVALID_PARAMETER);
486 _pthread_mutex_lock(&private_display->lock);
488 *subpixel = private_output->caps.subpixel;
490 _pthread_mutex_unlock(&private_display->lock);
496 tdm_output_get_pipe(tdm_output *output, unsigned int *pipe)
499 TDM_RETURN_VAL_IF_FAIL(pipe != NULL, TDM_ERROR_INVALID_PARAMETER);
501 _pthread_mutex_lock(&private_display->lock);
503 *pipe = private_output->pipe;
505 _pthread_mutex_unlock(&private_display->lock);
511 tdm_output_get_primary_index(tdm_output *output, int *index)
513 tdm_private_layer *private_layer = NULL;
516 TDM_RETURN_VAL_IF_FAIL(index != NULL, TDM_ERROR_INVALID_PARAMETER);
518 _pthread_mutex_lock(&private_display->lock);
520 LIST_FOR_EACH_ENTRY(private_layer, &private_output->layer_list, link) {
521 if (private_layer->caps.capabilities & TDM_LAYER_CAPABILITY_PRIMARY) {
522 *index = private_layer->index;
527 _pthread_mutex_unlock(&private_display->lock);
533 tdm_output_set_property(tdm_output *output, unsigned int id, tdm_value value)
535 tdm_func_output *func_output;
538 _pthread_mutex_lock(&private_display->lock);
540 func_output = &private_display->func_output;
542 if (!func_output->output_set_property) {
543 /* LCOV_EXCL_START */
544 _pthread_mutex_unlock(&private_display->lock);
545 TDM_ERR("not implemented!!");
546 return TDM_ERROR_NOT_IMPLEMENTED;
550 ret = func_output->output_set_property(private_output->output_backend, id,
553 _pthread_mutex_unlock(&private_display->lock);
559 tdm_output_get_property(tdm_output *output, unsigned int id, tdm_value *value)
561 tdm_func_output *func_output;
564 TDM_RETURN_VAL_IF_FAIL(value != NULL, TDM_ERROR_INVALID_PARAMETER);
566 _pthread_mutex_lock(&private_display->lock);
568 func_output = &private_display->func_output;
570 if (!func_output->output_get_property) {
571 /* LCOV_EXCL_START */
572 _pthread_mutex_unlock(&private_display->lock);
573 TDM_ERR("not implemented!!");
574 return TDM_ERROR_NOT_IMPLEMENTED;
578 ret = func_output->output_get_property(private_output->output_backend, id,
581 _pthread_mutex_unlock(&private_display->lock);
587 tdm_output_cb_vblank(tdm_output *output_backend, unsigned int sequence,
588 unsigned int tv_sec, unsigned int tv_usec, void *user_data)
590 tdm_private_vblank_handler *vblank_handler = user_data;
591 tdm_private_vblank_handler *v = NULL, *vv = NULL;
592 tdm_private_output *private_output;
593 tdm_private_display *private_display;
594 struct list_head clone_list;
596 pid_t tid = syscall(SYS_gettid);
598 TDM_RETURN_IF_FAIL(TDM_MUTEX_IS_LOCKED());
599 TDM_RETURN_IF_FAIL(vblank_handler);
601 private_output = vblank_handler->private_output;
602 private_display = private_output->private_display;
604 if (vblank_handler->owner_tid != tid) {
605 tdm_thread_cb_output_vblank output_vblank;
608 output_vblank.base.type = TDM_THREAD_CB_OUTPUT_VBLANK;
609 output_vblank.base.length = sizeof output_vblank;
610 output_vblank.output_stamp = vblank_handler->private_output->stamp;
611 output_vblank.sequence = sequence;
612 output_vblank.tv_sec = tv_sec;
613 output_vblank.tv_usec = tv_usec;
614 output_vblank.user_data = user_data;
616 ret = tdm_thread_send_cb(private_display->private_loop, &output_vblank.base);
617 TDM_WARNING_IF_FAIL(ret == TDM_ERROR_NONE);
622 if (vblank_handler->owner_tid != tid)
623 TDM_NEVER_GET_HERE();
625 interval = vblank_handler->interval;
626 sync = vblank_handler->sync;
628 LIST_INITHEAD(&clone_list);
630 LIST_FOR_EACH_ENTRY_SAFE(v, vv, &private_output->vblank_handler_list, link) {
631 if (v->interval != interval || v->sync != sync || v->owner_tid != tid)
635 LIST_ADDTAIL(&v->link, &clone_list);
638 if (tdm_debug_module & TDM_DEBUG_COMMIT)
639 TDM_INFO("----------------------------------------- output(%d) got vblank", private_output->pipe);
641 _pthread_mutex_unlock(&private_display->lock);
642 LIST_FOR_EACH_ENTRY_SAFE(v, vv, &clone_list, link) {
643 if (tdm_debug_module & TDM_DEBUG_COMMIT)
644 TDM_INFO("handler(%p)", v);
649 v->func(v->private_output, sequence, tv_sec, tv_usec, v->user_data);
653 _pthread_mutex_lock(&private_display->lock);
655 if (tdm_debug_module & TDM_DEBUG_COMMIT)
656 TDM_INFO("-----------------------------------------...");
660 tdm_output_cb_commit(tdm_output *output_backend, unsigned int sequence,
661 unsigned int tv_sec, unsigned int tv_usec, void *user_data)
663 tdm_private_output_commit_handler *output_commit_handler = user_data;
664 tdm_private_display *private_display;
665 tdm_private_output *private_output;
666 tdm_private_layer *private_layer = NULL;
668 TDM_RETURN_IF_FAIL(TDM_MUTEX_IS_LOCKED());
670 if (!output_commit_handler)
673 private_output = output_commit_handler->private_output;
674 private_display = private_output->private_display;
676 if (output_commit_handler->owner_tid != syscall(SYS_gettid)) {
677 tdm_thread_cb_output_commit output_commit;
680 output_commit.base.type = TDM_THREAD_CB_OUTPUT_COMMIT;
681 output_commit.base.length = sizeof output_commit;
682 output_commit.output_stamp = private_output->stamp;
683 output_commit.sequence = sequence;
684 output_commit.tv_sec = tv_sec;
685 output_commit.tv_usec = tv_usec;
686 output_commit.user_data = user_data;
688 ret = tdm_thread_send_cb(private_display->private_loop, &output_commit.base);
689 TDM_WARNING_IF_FAIL(ret == TDM_ERROR_NONE);
694 LIST_DEL(&output_commit_handler->link);
696 if (tdm_debug_module & TDM_DEBUG_COMMIT) {
697 TDM_INFO("----------------------------------------- output(%d) committed", private_output->pipe);
698 TDM_INFO("handler(%p)", output_commit_handler);
701 if (private_output->commit_type == TDM_COMMIT_TYPE_OUTPUT) {
702 /* In case of layer commit, the below will be handled in the layer commit callback */
703 LIST_FOR_EACH_ENTRY(private_layer, &private_output->layer_list, link) {
704 if (private_layer->committed_buffer)
705 tdm_layer_committed(private_layer, &private_layer->committed_buffer);
709 if (output_commit_handler->func) {
710 _pthread_mutex_unlock(&private_display->lock);
711 output_commit_handler->func(private_output, sequence,
712 tv_sec, tv_usec, output_commit_handler->user_data);
713 _pthread_mutex_lock(&private_display->lock);
716 free(output_commit_handler);
718 if (tdm_debug_module & TDM_DEBUG_COMMIT)
719 TDM_INFO("-----------------------------------------...");
722 /* add_front: To distinguish between the user vblank handlers and the layer
723 * commit vblank handlers. The layer commit handlers will be called
724 * before calling the user vblank handlers.
727 _tdm_output_wait_vblank(tdm_output *output, int interval, int sync,
728 tdm_output_vblank_handler func, void *user_data,
729 unsigned int add_front)
731 tdm_func_output *func_output;
732 tdm_private_vblank_handler *vblank_handler = NULL, *v = NULL;
733 unsigned int skip_request = 0;
734 pid_t tid = syscall(SYS_gettid);
738 func_output = &private_display->func_output;
740 /* interval SHOULD be at least 1 */
744 if (!func_output->output_wait_vblank) {
745 /* LCOV_EXCL_START */
746 TDM_ERR("not implemented!!");
747 return TDM_ERROR_NOT_IMPLEMENTED;
751 if (!private_output->regist_vblank_cb) {
752 private_output->regist_vblank_cb = 1;
753 ret = func_output->output_set_vblank_handler(private_output->output_backend,
754 tdm_output_cb_vblank);
757 vblank_handler = calloc(1, sizeof(tdm_private_vblank_handler));
758 if (!vblank_handler) {
759 /* LCOV_EXCL_START */
760 TDM_ERR("failed: alloc memory");
761 return TDM_ERROR_OUT_OF_MEMORY;
765 if (tdm_debug_module & TDM_DEBUG_COMMIT)
766 TDM_INFO("output(%d) wait_vblank: handler(%p)", private_output->pipe, vblank_handler);
768 LIST_FOR_EACH_ENTRY(v, &private_output->vblank_handler_list, link) {
769 if (v->interval == interval && v->sync == sync && v->owner_tid == tid) {
776 LIST_ADD(&vblank_handler->link, &private_output->vblank_handler_list);
778 LIST_ADDTAIL(&vblank_handler->link, &private_output->vblank_handler_list);
780 vblank_handler->private_output = private_output;
781 vblank_handler->interval = interval;
782 vblank_handler->sync = sync;
783 vblank_handler->func = func;
784 vblank_handler->user_data = user_data;
785 vblank_handler->owner_tid = tid;
787 /* If there is the previous request, we can skip to call output_wait_vblank() */
789 ret = func_output->output_wait_vblank(private_output->output_backend, interval,
790 sync, vblank_handler);
791 TDM_GOTO_IF_FAIL(ret == TDM_ERROR_NONE, wait_failed);
793 if (tdm_debug_module & TDM_DEBUG_COMMIT)
794 TDM_INFO("output(%d) backend wait_vblank", private_output->pipe);
800 /* LCOV_EXCL_START */
801 if (vblank_handler) {
802 LIST_DEL(&vblank_handler->link);
803 free(vblank_handler);
810 tdm_output_wait_vblank(tdm_output *output, int interval, int sync,
811 tdm_output_vblank_handler func, void *user_data)
815 _pthread_mutex_lock(&private_display->lock);
817 if (TDM_OUTPUT_DPMS_VSYNC_IS_OFF(private_output->current_dpms_value)) {
818 TDM_WRN("output(%d) dpms: %s", private_output->pipe,
819 tdm_dpms_str(private_output->current_dpms_value));
820 _pthread_mutex_unlock(&private_display->lock);
821 return TDM_ERROR_DPMS_OFF;
824 ret = _tdm_output_wait_vblank(output, interval, sync, func, user_data, 0);
826 _pthread_mutex_unlock(&private_display->lock);
831 /* LCOV_EXCL_START */
833 tdm_output_wait_vblank_add_front(tdm_output *output, int interval, int sync,
834 tdm_output_vblank_handler func, void *user_data)
838 _pthread_mutex_lock(&private_display->lock);
840 if (TDM_OUTPUT_DPMS_VSYNC_IS_OFF(private_output->current_dpms_value)) {
841 TDM_WRN("output(%d) dpms: %s", private_output->pipe,
842 tdm_dpms_str(private_output->current_dpms_value));
843 _pthread_mutex_unlock(&private_display->lock);
844 return TDM_ERROR_DPMS_OFF;
847 ret = _tdm_output_wait_vblank(output, interval, sync, func, user_data, 1);
849 _pthread_mutex_unlock(&private_display->lock);
856 tdm_output_remove_vblank_handler_internal(tdm_output *output, tdm_output_vblank_handler func, void *user_data)
858 tdm_private_output *private_output = (tdm_private_output*)output;
859 tdm_private_vblank_handler *v = NULL;
861 TDM_RETURN_IF_FAIL(private_output != NULL);
862 TDM_RETURN_IF_FAIL(TDM_MUTEX_IS_LOCKED());
864 LIST_FOR_EACH_ENTRY(v, &private_output->vblank_handler_list, link) {
865 if (v->func == func && v->user_data == user_data) {
866 /* only set func & user_data to NULL. It will be freed when an event occurs */
875 tdm_output_remove_commit_handler_internal(tdm_output *output, tdm_output_commit_handler func, void *user_data)
877 tdm_private_output *private_output = (tdm_private_output*)output;
878 tdm_private_output_commit_handler *c = NULL;
880 TDM_RETURN_IF_FAIL(private_output != NULL);
881 TDM_RETURN_IF_FAIL(TDM_MUTEX_IS_LOCKED());
883 LIST_FOR_EACH_ENTRY(c, &private_output->output_commit_handler_list, link) {
884 if (c->func == func && c->user_data == user_data) {
885 /* only set func & user_data to NULL. It will be freed when an event occurs */
894 tdm_output_remove_vblank_handler(tdm_output *output, tdm_output_vblank_handler func, void *user_data)
898 _pthread_mutex_lock(&private_display->lock);
900 tdm_output_remove_vblank_handler_internal(output, func, user_data);
902 _pthread_mutex_unlock(&private_display->lock);
908 tdm_output_remove_commit_handler(tdm_output *output, tdm_output_commit_handler func, void *user_data)
912 _pthread_mutex_lock(&private_display->lock);
914 tdm_output_remove_commit_handler_internal(output, func, user_data);
916 _pthread_mutex_unlock(&private_display->lock);
922 tdm_output_commit_internal(tdm_output *output, int sync, tdm_output_commit_handler func, void *user_data)
924 tdm_func_output *func_output;
925 tdm_private_output_commit_handler *output_commit_handler = NULL;
926 tdm_private_layer *private_layer = NULL;
927 tdm_output_dpms dpms_value = TDM_OUTPUT_DPMS_ON;
931 func_output = &private_display->func_output;
933 if (!func_output->output_commit) {
934 /* LCOV_EXCL_START */
935 TDM_ERR("not implemented!!");
936 return TDM_ERROR_NOT_IMPLEMENTED;
940 ret = tdm_output_get_dpms_internal(output, &dpms_value);
941 TDM_RETURN_VAL_IF_FAIL(ret == TDM_ERROR_NONE, ret);
943 if (!TDM_OUTPUT_DPMS_VSYNC_IS_OFF(dpms_value)) {
945 if (!private_output->regist_commit_cb) {
946 private_output->regist_commit_cb = 1;
947 ret = func_output->output_set_commit_handler(private_output->output_backend,
948 tdm_output_cb_commit);
949 TDM_GOTO_IF_FAIL(ret == TDM_ERROR_NONE, commit_failed);
952 output_commit_handler = calloc(1, sizeof(tdm_private_output_commit_handler));
953 if (!output_commit_handler) {
954 /* LCOV_EXCL_START */
955 TDM_ERR("failed: alloc memory");
956 return TDM_ERROR_OUT_OF_MEMORY;
960 LIST_ADDTAIL(&output_commit_handler->link, &private_output->output_commit_handler_list);
961 output_commit_handler->private_output = private_output;
962 output_commit_handler->func = func;
963 output_commit_handler->user_data = user_data;
964 output_commit_handler->owner_tid = syscall(SYS_gettid);
967 ret = func_output->output_commit(private_output->output_backend, sync,
968 output_commit_handler);
969 TDM_GOTO_IF_FAIL(ret == TDM_ERROR_NONE, commit_failed);
971 if (tdm_debug_module & TDM_DEBUG_COMMIT)
972 TDM_INFO("output(%d) backend commit: handle(%p) func(%p) user_data(%p)",
973 private_output->pipe, output_commit_handler, func, user_data);
976 /* Even if DPMS is off, committed_buffer should be changed because it will be referred
977 * for tdm_layer_committed() function.
979 LIST_FOR_EACH_ENTRY(private_layer, &private_output->layer_list, link) {
980 if (!private_layer->waiting_buffer)
983 private_layer->committed_buffer = private_layer->waiting_buffer;
984 private_layer->waiting_buffer = NULL;
985 if (tdm_debug_module & TDM_DEBUG_BUFFER)
986 TDM_INFO("layer(%p) waiting_buffer(%p) committed_buffer(%p)",
987 private_layer, private_layer->waiting_buffer,
988 private_layer->committed_buffer->buffer);
991 if (TDM_OUTPUT_DPMS_VSYNC_IS_OFF(dpms_value)) {
992 TDM_WRN("dpms %s. Directly call commit handler instead of commit.", tdm_dpms_str(dpms_value));
994 func(output, 0, 0, 0, user_data);
1000 /* LCOV_EXCL_START */
1001 if (output_commit_handler) {
1002 LIST_DEL(&output_commit_handler->link);
1003 free(output_commit_handler);
1006 /* LCOV_EXCL_STOP */
1010 tdm_output_commit(tdm_output *output, int sync, tdm_output_commit_handler func,
1013 tdm_private_layer *private_layer = NULL;
1015 OUTPUT_FUNC_ENTRY();
1017 _pthread_mutex_lock(&private_display->lock);
1019 if (private_output->commit_type == TDM_COMMIT_TYPE_NONE)
1020 private_output->commit_type = TDM_COMMIT_TYPE_OUTPUT;
1021 else if (private_output->commit_type == TDM_COMMIT_TYPE_LAYER) {
1022 TDM_ERR("Can't supported. Use tdm_layer_commit");
1023 _pthread_mutex_unlock(&private_display->lock);
1024 return TDM_ERROR_BAD_REQUEST;
1027 if (private_output->commit_per_vblank) {
1028 TDM_ERR("Use tdm_layer_commit");
1029 _pthread_mutex_unlock(&private_display->lock);
1030 return TDM_ERROR_BAD_REQUEST;
1033 if (TDM_OUTPUT_DPMS_VSYNC_IS_OFF(private_output->current_dpms_value)) {
1034 TDM_ERR("output(%d) dpms: %s", private_output->pipe,
1035 tdm_dpms_str(private_output->current_dpms_value));
1036 _pthread_mutex_unlock(&private_display->lock);
1037 return TDM_ERROR_DPMS_OFF;
1040 if (tdm_debug_module & TDM_DEBUG_COMMIT)
1041 TDM_INFO("output(%d) commit", private_output->pipe);
1043 /* apply the pending data of all layers */
1044 LIST_FOR_EACH_ENTRY(private_layer, &private_output->layer_list, link) {
1045 tdm_layer_commit_pending_data(private_layer);
1048 ret = tdm_output_commit_internal(output, sync, func, user_data);
1050 _pthread_mutex_unlock(&private_display->lock);
1056 tdm_output_set_mode(tdm_output *output, const tdm_output_mode *mode)
1058 tdm_func_output *func_output;
1059 OUTPUT_FUNC_ENTRY();
1061 TDM_RETURN_VAL_IF_FAIL(mode != NULL, TDM_ERROR_INVALID_PARAMETER);
1063 _pthread_mutex_lock(&private_display->lock);
1065 func_output = &private_display->func_output;
1067 if (!func_output->output_set_mode) {
1068 /* LCOV_EXCL_START */
1069 _pthread_mutex_unlock(&private_display->lock);
1070 TDM_ERR("not implemented!!");
1071 return TDM_ERROR_NOT_IMPLEMENTED;
1072 /* LCOV_EXCL_STOP */
1075 ret = func_output->output_set_mode(private_output->output_backend, mode);
1076 if (ret == TDM_ERROR_NONE) {
1077 private_output->current_mode = mode;
1078 TDM_INFO("mode: %dx%d %dhz", mode->hdisplay, mode->vdisplay, mode->vrefresh);
1081 _pthread_mutex_unlock(&private_display->lock);
1087 tdm_output_get_mode(tdm_output *output, const tdm_output_mode **mode)
1089 OUTPUT_FUNC_ENTRY();
1091 TDM_RETURN_VAL_IF_FAIL(mode != NULL, TDM_ERROR_INVALID_PARAMETER);
1093 _pthread_mutex_lock(&private_display->lock);
1095 *mode = private_output->current_mode;
1097 _pthread_mutex_unlock(&private_display->lock);
1103 _tdm_output_dpms_changed_timeout(void *user_data)
1105 tdm_private_output *private_output = user_data;
1108 value.u32 = private_output->current_dpms_value;
1109 tdm_output_call_change_handler_internal(private_output,
1110 &private_output->change_handler_list_sub,
1111 TDM_OUTPUT_CHANGE_DPMS,
1114 return TDM_ERROR_NONE;
1118 tdm_output_call_dpms_change_handler(tdm_output *output)
1120 tdm_private_output *private_output = (tdm_private_output*)output;
1123 /** Use timer to call the output change callback of the sub-thread.
1124 * The output change callback of tdm_server and tdm_vblank was called
1125 * in the main thread. And it made the multi thread issue. If we use
1126 * the timer, we can call the sub-thread's output change callback in
1129 if (!private_output->dpms_changed_timer) {
1130 private_output->dpms_changed_timer =
1131 tdm_event_loop_add_timer_handler(private_output->private_display,
1132 _tdm_output_dpms_changed_timeout, private_output, NULL);
1133 if (!private_output->dpms_changed_timer) {
1134 /* LCOV_EXCL_START */
1135 TDM_ERR("can't create dpms timer!!");
1136 return TDM_ERROR_OUT_OF_MEMORY;
1137 /* LCOV_EXCL_STOP */
1141 value.u32 = private_output->current_dpms_value;
1142 tdm_output_call_change_handler_internal(private_output,
1143 &private_output->change_handler_list_main,
1144 TDM_OUTPUT_CHANGE_DPMS,
1147 if (!LIST_IS_EMPTY(&private_output->change_handler_list_sub)) {
1148 tdm_error ret = tdm_event_loop_source_timer_update(private_output->dpms_changed_timer, 1);
1149 if (ret != TDM_ERROR_NONE)
1150 TDM_NEVER_GET_HERE();
1153 return TDM_ERROR_NONE;
1156 /* LCOV_EXCL_START */
1158 tdm_output_cb_dpms(tdm_output *output_backend, tdm_output_dpms dpms, void *user_data)
1160 tdm_private_display *private_display;
1161 tdm_private_output *private_output = user_data;
1164 TDM_RETURN_IF_FAIL(TDM_MUTEX_IS_LOCKED());
1165 TDM_RETURN_IF_FAIL(private_output);
1167 private_display = private_output->private_display;
1169 if (!tdm_thread_in_display_thread(syscall(SYS_gettid))) {
1170 tdm_thread_cb_output_dpms output_dpms;
1173 _tdm_output_update(output_backend, user_data);
1175 output_dpms.base.type = TDM_THREAD_CB_OUTPUT_DPMS;
1176 output_dpms.base.length = sizeof output_dpms;
1177 output_dpms.output_stamp = private_output->stamp;
1178 output_dpms.dpms = dpms;
1179 output_dpms.user_data = user_data;
1182 tdm_output_call_change_handler_internal(private_output,
1183 &private_output->change_handler_list_sub,
1184 TDM_OUTPUT_CHANGE_DPMS,
1187 ret = tdm_thread_send_cb(private_display->private_loop, &output_dpms.base);
1188 TDM_WARNING_IF_FAIL(ret == TDM_ERROR_NONE);
1193 private_output->current_dpms_value = dpms;
1194 private_output->waiting_dpms_change = 0;
1196 TDM_INFO("output(%d) dpms async '%s' done", private_output->pipe, tdm_dpms_str(dpms));
1199 tdm_output_call_change_handler_internal(private_output,
1200 &private_output->change_handler_list_main,
1201 TDM_OUTPUT_CHANGE_DPMS,
1204 /* LCOV_EXCL_STOP */
1207 tdm_output_set_dpms(tdm_output *output, tdm_output_dpms dpms_value)
1209 tdm_func_output *func_output;
1210 OUTPUT_FUNC_ENTRY();
1212 _pthread_mutex_lock(&private_display->lock);
1214 if (private_output->waiting_dpms_change) {
1215 TDM_ERR("DPMS is not changed yet. Can't be changed twice");
1216 _pthread_mutex_unlock(&private_display->lock);
1217 return TDM_ERROR_BAD_REQUEST;
1220 func_output = &private_display->func_output;
1222 TDM_INFO("output(%d) dpms '%s'", private_output->pipe, tdm_dpms_str(dpms_value));
1224 if (func_output->output_set_dpms)
1225 ret = func_output->output_set_dpms(private_output->output_backend, dpms_value);
1227 /* LCOV_EXCL_START */
1228 ret = TDM_ERROR_NONE;
1229 TDM_WRN("not implemented!!");
1231 /* LCOV_EXCL_STOP */
1235 if (ret == TDM_ERROR_NONE) {
1236 if (private_output->current_dpms_value != dpms_value) {
1237 private_output->current_dpms_value = dpms_value;
1238 TDM_INFO("output(%d) dpms '%s' done", private_output->pipe, tdm_dpms_str(dpms_value));
1239 tdm_output_call_dpms_change_handler(output);
1242 tdm_output_dpms temp = TDM_OUTPUT_DPMS_OFF;
1244 /* update current_dpms_value forcely */
1245 tdm_output_get_dpms_internal(output, &temp);
1247 TDM_ERR("output(%d) set_dpms failed: dpms '%s'", private_output->pipe, tdm_dpms_str(temp));
1250 _pthread_mutex_unlock(&private_display->lock);
1255 /* LCOV_EXCL_START */
1257 tdm_output_set_dpms_async(tdm_output *output, tdm_output_dpms dpms_value)
1259 tdm_func_output *func_output;
1260 OUTPUT_FUNC_ENTRY();
1262 if (!(private_output->caps.capabilities & TDM_OUTPUT_CAPABILITY_ASYNC_DPMS)) {
1263 TDM_ERR("output doesn't support the asynchronous DPMS control!");
1264 return TDM_ERROR_BAD_REQUEST;
1267 _pthread_mutex_lock(&private_display->lock);
1269 if (private_output->waiting_dpms_change) {
1270 TDM_ERR("DPMS is not changed yet. Can't be changed twice");
1271 _pthread_mutex_unlock(&private_display->lock);
1272 return TDM_ERROR_BAD_REQUEST;
1275 func_output = &private_display->func_output;
1276 if (!func_output->output_set_dpms_handler) {
1277 TDM_ERR("not implemented: output_set_dpms_handler");
1278 _pthread_mutex_unlock(&private_display->lock);
1279 return TDM_ERROR_NOT_IMPLEMENTED;
1282 if (!func_output->output_set_dpms_async) {
1283 TDM_ERR("not implemented: output_set_dpms_async");
1284 _pthread_mutex_unlock(&private_display->lock);
1285 return TDM_ERROR_NOT_IMPLEMENTED;
1288 if (!private_output->regist_dpms_cb) {
1289 private_output->regist_dpms_cb = 1;
1290 ret = func_output->output_set_dpms_handler(private_output->output_backend,
1291 tdm_output_cb_dpms, private_output);
1292 if (ret != TDM_ERROR_NONE) {
1293 _pthread_mutex_unlock(&private_display->lock);
1294 TDM_ERR("Can't set the dpms handler!!");
1299 TDM_INFO("output(%d) dpms async '%s'", private_output->pipe, tdm_dpms_str(dpms_value));
1301 ret = func_output->output_set_dpms_async(private_output->output_backend, dpms_value);
1303 if (ret == TDM_ERROR_NONE) {
1304 private_output->waiting_dpms_change = 1;
1305 TDM_INFO("output(%d) dpms async '%s' waiting", private_output->pipe, tdm_dpms_str(dpms_value));
1307 tdm_output_dpms temp = TDM_OUTPUT_DPMS_OFF;
1309 /* update current_dpms_value forcely */
1310 tdm_output_get_dpms_internal(output, &temp);
1312 TDM_ERR("output(%d) set_dpms_async failed: dpms '%s'", private_output->pipe, tdm_dpms_str(temp));
1315 _pthread_mutex_unlock(&private_display->lock);
1319 /* LCOV_EXCL_STOP */
1322 tdm_output_get_dpms_internal(tdm_output *output, tdm_output_dpms *dpms_value)
1324 tdm_func_output *func_output;
1325 OUTPUT_FUNC_ENTRY();
1327 TDM_RETURN_VAL_IF_FAIL(private_output != NULL, TDM_ERROR_INVALID_PARAMETER);
1329 /* TODO: this is ugly. But before calling backend's output_get_dpms(), we have
1330 * to check if all backends's DPMS operation has no problem. In future, we'd
1331 * better use new env instead of using commit_per_vblank variable to distinguish
1332 * whether we use the stored value or backend's output_get_dpms.
1334 if (!private_output->commit_per_vblank) {
1335 *dpms_value = private_output->current_dpms_value;
1336 return TDM_ERROR_NONE;
1339 func_output = &private_display->func_output;
1341 if (!func_output->output_get_dpms) {
1342 /* LCOV_EXCL_START */
1343 *dpms_value = private_output->current_dpms_value;
1344 TDM_WRN("not implemented!!");
1345 return TDM_ERROR_NONE;
1346 /* LCOV_EXCL_STOP */
1349 ret = func_output->output_get_dpms(private_output->output_backend, dpms_value);
1350 if (ret != TDM_ERROR_NONE) {
1351 /* LCOV_EXCL_START */
1352 TDM_ERR("output_get_dpms failed");
1353 *dpms_value = TDM_OUTPUT_DPMS_OFF;
1354 /* LCOV_EXCL_STOP */
1357 /* checking with backend's value */
1358 if (*dpms_value != private_output->current_dpms_value) {
1359 TDM_ERR("output(%d) dpms changed suddenly: %s -> %s",
1360 private_output->pipe, private_output->current_dpms_value,
1361 tdm_dpms_str(*dpms_value));
1362 private_output->current_dpms_value = *dpms_value;
1363 tdm_output_call_dpms_change_handler(output);
1370 tdm_output_get_dpms(tdm_output *output, tdm_output_dpms *dpms_value)
1372 OUTPUT_FUNC_ENTRY();
1374 TDM_RETURN_VAL_IF_FAIL(dpms_value != NULL, TDM_ERROR_INVALID_PARAMETER);
1376 _pthread_mutex_lock(&private_display->lock);
1378 ret = tdm_output_get_dpms_internal(output, dpms_value);
1380 _pthread_mutex_unlock(&private_display->lock);
1385 EXTERN tdm_capture *
1386 tdm_output_create_capture(tdm_output *output, tdm_error *error)
1388 tdm_capture *capture = NULL;
1390 OUTPUT_FUNC_ENTRY_ERROR();
1392 _pthread_mutex_lock(&private_display->lock);
1394 capture = (tdm_capture *)tdm_capture_create_output_internal(private_output, error);
1396 _pthread_mutex_unlock(&private_display->lock);
1401 EXTERN tdm_hwc_window *
1402 tdm_output_hwc_create_window(tdm_output *output, tdm_error *error)
1404 tdm_hwc_window *hwc_window = NULL;
1406 OUTPUT_FUNC_ENTRY_ERROR();
1408 _pthread_mutex_lock(&private_display->lock);
1410 if (private_output->caps.capabilities & TDM_OUTPUT_CAPABILITY_HWC)
1411 hwc_window = (tdm_hwc_window *)tdm_hwc_window_create_internal(private_output, error);
1413 /* LCOV_EXCL_START */
1414 TDM_ERR("output(%p) not support HWC", private_output);
1416 *error = TDM_ERROR_BAD_REQUEST;
1417 /* LCOV_EXCL_STOP */
1420 _pthread_mutex_unlock(&private_display->lock);
1426 tdm_output_hwc_destroy_window(tdm_output *output, tdm_hwc_window *hwc_window)
1428 OUTPUT_FUNC_ENTRY();
1430 TDM_RETURN_VAL_IF_FAIL(hwc_window != NULL, TDM_ERROR_INVALID_PARAMETER);
1432 _pthread_mutex_lock(&private_display->lock);
1434 ret = tdm_hwc_window_destroy_internal(hwc_window);
1436 _pthread_mutex_unlock(&private_display->lock);
1442 tdm_output_hwc_validate(tdm_output *output, uint32_t *num_types)
1444 tdm_func_output *func_output = NULL;
1446 OUTPUT_FUNC_ENTRY();
1448 TDM_RETURN_VAL_IF_FAIL(num_types != NULL, TDM_ERROR_INVALID_PARAMETER);
1450 _pthread_mutex_lock(&private_display->lock);
1452 if (!(private_output->caps.capabilities & TDM_OUTPUT_CAPABILITY_HWC)) {
1453 TDM_ERR("output(%p) not support HWC", private_output);
1454 _pthread_mutex_unlock(&private_display->lock);
1455 return TDM_ERROR_BAD_REQUEST;
1458 func_output = &private_display->func_output;
1460 if (!func_output->output_hwc_validate) {
1461 /* LCOV_EXCL_START */
1462 _pthread_mutex_unlock(&private_display->lock);
1463 TDM_ERR("not implemented!!");
1464 return TDM_ERROR_NOT_IMPLEMENTED;
1465 /* LCOV_EXCL_STOP */
1468 ret = func_output->output_hwc_validate(private_output->output_backend, num_types);
1470 _pthread_mutex_unlock(&private_display->lock);
1476 tdm_output_hwc_set_need_validate_handler(tdm_output *output,
1477 tdm_output_need_validate_handler hndl)
1479 OUTPUT_FUNC_ENTRY();
1481 TDM_RETURN_VAL_IF_FAIL(hndl != NULL, TDM_ERROR_INVALID_PARAMETER);
1483 _pthread_mutex_lock(&private_display->lock);
1485 if (!(private_output->caps.capabilities & TDM_OUTPUT_CAPABILITY_HWC)) {
1486 TDM_ERR("output(%p) not support HWC", private_output);
1487 _pthread_mutex_unlock(&private_display->lock);
1488 return TDM_ERROR_BAD_REQUEST;
1491 /* there's no reason to allow this */
1492 if (private_output->need_validate.hndl) {
1494 _pthread_mutex_unlock(&private_display->lock);
1495 return TDM_ERROR_OPERATION_FAILED;
1498 private_output->need_validate.hndl = hndl;
1500 _pthread_mutex_unlock(&private_display->lock);
1506 tdm_output_hwc_get_changed_composition_types(tdm_output *output,
1507 uint32_t *num_elements,
1508 tdm_hwc_window **hwc_window,
1509 tdm_hwc_window_composition *composition_types)
1511 tdm_func_output *func_output = NULL;
1512 tdm_private_hwc_window * private_hwc_window = NULL;
1515 OUTPUT_FUNC_ENTRY();
1517 TDM_RETURN_VAL_IF_FAIL(num_elements != NULL, TDM_ERROR_INVALID_PARAMETER);
1519 _pthread_mutex_lock(&private_display->lock);
1521 if (!(private_output->caps.capabilities & TDM_OUTPUT_CAPABILITY_HWC)) {
1522 TDM_ERR("output(%p) not support HWC", private_output);
1523 _pthread_mutex_unlock(&private_display->lock);
1524 return TDM_ERROR_BAD_REQUEST;
1527 func_output = &private_display->func_output;
1529 if (!func_output->output_hwc_get_changed_composition_types) {
1530 /* LCOV_EXCL_START */
1531 _pthread_mutex_unlock(&private_display->lock);
1532 TDM_ERR("not implemented!!");
1533 return TDM_ERROR_NOT_IMPLEMENTED;
1534 /* LCOV_EXCL_STOP */
1537 ret = func_output->output_hwc_get_changed_composition_types(private_output->output_backend,
1538 num_elements, hwc_window, composition_types);
1539 if (ret != TDM_ERROR_NONE) {
1540 /* LCOV_EXCL_START */
1541 _pthread_mutex_unlock(&private_display->lock);
1543 /* LCOV_EXCL_STOP */
1546 if (hwc_window == NULL || composition_types == NULL) {
1547 _pthread_mutex_unlock(&private_display->lock);
1548 return TDM_ERROR_NONE;
1551 for (i = 0; i < *num_elements; i++) {
1553 private_hwc_window = _tdm_output_find_private_hwc_window(private_output, hwc_window[i]);
1555 if (private_hwc_window == NULL) {
1556 /* LCOV_EXCL_START */
1557 TDM_ERR("failed! This should never happen!");
1558 func_output->output_hwc_destroy_window(private_output->output_backend, hwc_window[i]);
1560 _pthread_mutex_unlock(&private_display->lock);
1561 return TDM_ERROR_OPERATION_FAILED;
1562 /* LCOV_EXCL_STOP */
1565 hwc_window[i] = (tdm_hwc_window*)private_hwc_window;
1568 _pthread_mutex_unlock(&private_display->lock);
1574 tdm_output_hwc_accept_changes(tdm_output *output)
1576 tdm_func_output *func_output = NULL;
1578 OUTPUT_FUNC_ENTRY();
1580 _pthread_mutex_lock(&private_display->lock);
1582 if (!(private_output->caps.capabilities & TDM_OUTPUT_CAPABILITY_HWC)) {
1583 TDM_ERR("output(%p) not support HWC", private_output);
1584 _pthread_mutex_unlock(&private_display->lock);
1585 return TDM_ERROR_BAD_REQUEST;
1588 func_output = &private_display->func_output;
1590 if (!func_output->output_hwc_validate) {
1591 /* LCOV_EXCL_START */
1592 _pthread_mutex_unlock(&private_display->lock);
1593 TDM_ERR("not implemented!!");
1594 return TDM_ERROR_NOT_IMPLEMENTED;
1595 /* LCOV_EXCL_STOP */
1598 ret = func_output->output_hwc_accept_changes(private_output->output_backend);
1600 _pthread_mutex_unlock(&private_display->lock);
1606 tdm_output_hwc_get_target_buffer_queue(tdm_output *output, tdm_error *error)
1608 tdm_func_output *func_output = NULL;
1609 tbm_surface_queue_h queue = NULL;
1611 OUTPUT_FUNC_ENTRY_ERROR();
1613 _pthread_mutex_lock(&private_display->lock);
1615 if (!(private_output->caps.capabilities & TDM_OUTPUT_CAPABILITY_HWC)) {
1616 TDM_ERR("output(%p) not support HWC", private_output);
1618 *error = TDM_ERROR_BAD_REQUEST;
1619 _pthread_mutex_unlock(&private_display->lock);
1623 func_output = &private_display->func_output;
1625 if (!func_output->output_hwc_get_target_buffer_queue) {
1626 /* LCOV_EXCL_START */
1627 _pthread_mutex_unlock(&private_display->lock);
1628 TDM_ERR("not implemented!!");
1630 /* LCOV_EXCL_STOP */
1633 queue = func_output->output_hwc_get_target_buffer_queue(private_output->output_backend, error);
1635 _pthread_mutex_unlock(&private_display->lock);
1640 /* LCOV_EXCL_START */
1642 _tdm_target_window_dump_buffer(tdm_private_output *private_output, tbm_surface_h buffer)
1645 char fname[PATH_MAX];
1647 pipe = private_output->pipe;
1649 snprintf(fname, sizeof(fname), "tdm_%d_target_win", pipe);
1651 tbm_surface_internal_dump_buffer(buffer, fname);
1652 TDM_DBG("%s dump excute", fname);
1656 /* LCOV_EXCL_STOP */
1659 tdm_output_hwc_set_client_target_buffer(tdm_output *output, tbm_surface_h target_buffer,
1660 tdm_hwc_region damage)
1662 tdm_func_output *func_output = NULL;
1664 OUTPUT_FUNC_ENTRY();
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 if (tdm_debug_dump & TDM_DUMP_FLAG_WINDOW) {
1675 /* LCOV_EXCL_START */
1676 char str[TDM_PATH_LEN];
1678 snprintf(str, TDM_PATH_LEN, "target_window_%d_%03d",
1679 private_output->index, i++);
1680 tdm_helper_dump_buffer_str(target_buffer, tdm_debug_dump_dir, str);
1681 /* LCOV_EXCL_STOP */
1684 func_output = &private_display->func_output;
1686 if (!func_output->output_hwc_set_client_target_buffer) {
1687 /* LCOV_EXCL_START */
1688 _pthread_mutex_unlock(&private_display->lock);
1689 TDM_ERR("not implemented!!");
1690 return TDM_ERROR_NOT_IMPLEMENTED;
1691 /* LCOV_EXCL_STOP */
1695 if (tdm_dump_enable)
1696 /* LCOV_EXCL_START */
1697 _tdm_target_window_dump_buffer((tdm_private_output *)output, target_buffer);
1698 /* LCOV_EXCL_STOP */
1700 ret = func_output->output_hwc_set_client_target_buffer(private_output->output_backend, target_buffer, damage);
1702 _pthread_mutex_unlock(&private_display->lock);
1708 tdm_output_call_change_handler_internal(tdm_private_output *private_output,
1709 struct list_head *change_handler_list,
1710 tdm_output_change_type type,
1712 int no_check_thread_id)
1714 tdm_private_display *private_display;
1715 tdm_private_change_handler *change_handler = NULL;
1717 TDM_RETURN_IF_FAIL(TDM_MUTEX_IS_LOCKED());
1718 TDM_RETURN_IF_FAIL(private_output);
1720 private_display = private_output->private_display;
1721 if (!tdm_thread_in_display_thread(syscall(SYS_gettid))) {
1722 if (type & TDM_OUTPUT_CHANGE_CONNECTION)
1723 TDM_INFO("output(%d) changed: %s (%d)",
1724 private_output->pipe, tdm_status_str(value.u32), value.u32);
1725 if (type & TDM_OUTPUT_CHANGE_DPMS)
1726 TDM_INFO("output(%d) changed: dpms %s (%d)",
1727 private_output->pipe, tdm_dpms_str(value.u32), value.u32);
1730 if (LIST_IS_EMPTY(change_handler_list))
1733 LIST_FOR_EACH_ENTRY(change_handler, change_handler_list, link) {
1734 if (!no_check_thread_id && change_handler->owner_tid != syscall(SYS_gettid))
1735 TDM_NEVER_GET_HERE();
1737 _pthread_mutex_unlock(&private_display->lock);
1738 change_handler->func(private_output, type,
1739 value, change_handler->user_data);
1740 _pthread_mutex_lock(&private_display->lock);
1745 /* gets called on behalf of the ecore-main-loop thread */
1747 tdm_output_cb_need_validate(tdm_private_output *private_output)
1749 TDM_RETURN_VAL_IF_FAIL(private_output != NULL, TDM_ERROR_INVALID_PARAMETER);
1751 TDM_INFO("tdm-backend asks for revalidation for the output:%p.", private_output);
1753 if (private_output->need_validate.hndl)
1754 private_output->need_validate.hndl((tdm_output*)private_output);
1756 return TDM_ERROR_NONE;
1759 /* gets called on behalf of the tdm-thread */
1761 _need_validate_handler(int fd, tdm_event_loop_mask mask, void *user_data)
1763 tdm_thread_cb_need_validate ev;
1764 tdm_private_output *private_output;
1767 private_output = (tdm_private_output *)user_data;
1769 ev.base.type = TDM_THREAD_CB_NEED_VALIDATE;
1770 ev.base.length = sizeof ev;
1771 ev.o = private_output;
1773 ret = tdm_thread_send_cb(private_output->private_display->private_loop, &ev.base);
1774 TDM_WARNING_IF_FAIL(ret == TDM_ERROR_NONE);
1776 TDM_INFO("tdm-thread: get a 'need to revalidate' event for the ouptut:%p.", private_output);
1778 /* who cares about this? */
1779 return TDM_ERROR_NONE;
1783 tdm_output_need_validate_event_init(tdm_output *output)
1787 OUTPUT_FUNC_ENTRY();
1789 TDM_RETURN_VAL_IF_FAIL(TDM_MUTEX_IS_LOCKED(), TDM_ERROR_OPERATION_FAILED);
1791 if (!(private_output->caps.capabilities & TDM_OUTPUT_CAPABILITY_HWC)) {
1792 TDM_ERR("output(%p) not support HWC", private_output);
1793 return TDM_ERROR_BAD_REQUEST;
1796 /* build in eventfd fds into event_loop listened & handled by the tdm-thread */
1798 TDM_WARNING_IF_FAIL(fd >= 0);
1800 tdm_event_loop_add_fd_handler(private_display, fd, TDM_EVENT_LOOP_READABLE,
1801 _need_validate_handler, private_output, &ret);
1802 TDM_WARNING_IF_FAIL(ret == TDM_ERROR_NONE);
1804 private_output->need_validate.event_fd = fd;
1806 TDM_INFO("register an output:%p for the revalidation, event_fd:%d.", private_output, fd);
1812 tdm_output_choose_commit_per_vblank_mode(tdm_private_output *private_output, int mode)
1814 if (!private_output)
1815 return TDM_ERROR_INVALID_PARAMETER;
1817 if (mode < 0 || mode > 2)
1818 return TDM_ERROR_INVALID_PARAMETER;
1820 private_output->commit_per_vblank = mode;
1822 if (private_output->commit_per_vblank == 0)
1823 TDM_INFO("commit per vblank: disable");
1824 else if (private_output->commit_per_vblank == 1)
1825 TDM_INFO("commit per vblank: enable (1 layer)");
1826 else if (private_output->commit_per_vblank == 2)
1827 TDM_INFO("commit per vblank: enable (previous commit)");
1829 return TDM_ERROR_NONE;