1 /**************************************************************************
5 * Copyright 2015 Samsung Electronics co., Ltd. All Rights Reserved.
7 * Contact: Eunchul Kim <chulspro.kim@samsung.com>,
8 * JinYoung Jeon <jy0.jeon@samsung.com>,
9 * Taeheon Kim <th908.kim@samsung.com>,
10 * YoungJun Cho <yj44.cho@samsung.com>,
11 * SooChan Lim <sc1.lim@samsung.com>,
12 * Boram Park <boram1288.park@samsung.com>
14 * Permission is hereby granted, free of charge, to any person obtaining a
15 * copy of this software and associated documentation files (the
16 * "Software"), to deal in the Software without restriction, including
17 * without limitation the rights to use, copy, modify, merge, publish,
18 * distribute, sub license, and/or sell copies of the Software, and to
19 * permit persons to whom the Software is furnished to do so, subject to
20 * the following conditions:
22 * The above copyright notice and this permission notice (including the
23 * next paragraph) shall be included in all copies or substantial portions
26 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
27 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
28 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
29 * IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR
30 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
31 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
32 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
34 **************************************************************************/
40 #include "tdm_private.h"
44 #define OUTPUT_FUNC_ENTRY() \
45 tdm_private_display *private_display; \
46 tdm_private_output *private_output; \
47 tdm_error ret = TDM_ERROR_NONE; /* default TDM_ERROR_NONE */\
48 TDM_RETURN_VAL_IF_FAIL(output != NULL, TDM_ERROR_INVALID_PARAMETER); \
49 private_output = (tdm_private_output*)output; \
50 private_display = private_output->private_display
52 #define OUTPUT_FUNC_ENTRY_ERROR() \
53 tdm_private_display *private_display; \
54 tdm_private_output *private_output; \
55 tdm_error ret = TDM_ERROR_NONE; /* default TDM_ERROR_NONE */\
56 TDM_RETURN_VAL_IF_FAIL_WITH_ERROR(output != NULL, TDM_ERROR_INVALID_PARAMETER, NULL); \
57 private_output = (tdm_private_output*)output; \
58 private_display = private_output->private_display
61 _tdm_output_vblank_timeout_update(tdm_private_output *private_output, int ms_delay);
64 _tdm_output_vblank_timeout_cb(void *user_data)
66 tdm_private_output *private_output = user_data;
67 tdm_private_output_vblank_handler *v = NULL;
69 TDM_RETURN_VAL_IF_FAIL(private_output != NULL, TDM_ERROR_OPERATION_FAILED);
71 private_output->vblank_timeout_timer_expired++;
73 TDM_ERR("TDM output(%d) vblank TIMEOUT!! (%d time%s)",
75 private_output->vblank_timeout_timer_expired,
76 (private_output->vblank_timeout_timer_expired > 1) ? "s" : "");
78 LIST_FOR_EACH_ENTRY(v, &private_output->vblank_handler_list, link) {
79 TDM_ERR("vblank_handler(%p) interval(%d) sync(%d) sent_to_frontend(%u) owner_tid(%d)",
80 v, v->interval, v->sync, v->sent_to_frontend, v->owner_tid);
83 return TDM_ERROR_NONE;
87 tdm_output_vblank_print_wait_information(tdm_private_output *private_output, void *user_data)
89 tdm_private_output_vblank_handler *v = NULL;
91 TDM_RETURN_IF_FAIL(private_output != NULL);
92 TDM_RETURN_IF_FAIL(user_data != NULL);
94 TDM_ERR("TDM output(%d) vblank user_data(%p) info!!", private_output->pipe, user_data);
96 LIST_FOR_EACH_ENTRY(v, &private_output->vblank_handler_list, link) {
97 if (v->user_data != user_data)
99 TDM_ERR("vblank_handler(%p) interval(%d) sync(%d) sent_to_frontend(%u) owner_tid(%d)",
100 v, v->interval, v->sync, v->sent_to_frontend, v->owner_tid);
105 _tdm_output_vblank_timeout_update(tdm_private_output *private_output, int ms_delay)
109 if (!private_output->vblank_timeout_timer) {
110 private_output->vblank_timeout_timer =
111 tdm_event_loop_add_timer_handler(private_output->private_display,
112 _tdm_output_vblank_timeout_cb,
115 if (!private_output->vblank_timeout_timer) {
116 TDM_ERR("output(%d) couldn't add timer", private_output->pipe);
119 TDM_INFO("output(%d) create vblank timeout timer", private_output->pipe);
120 private_output->vblank_timeout_timer_expired = 0;
123 ret = tdm_event_loop_source_timer_update(private_output->vblank_timeout_timer, ms_delay);
124 if (ret != TDM_ERROR_NONE) {
125 TDM_ERR("output(%d) couldn't update timer", private_output->pipe);
130 static tdm_private_hwc_window *
131 _tdm_output_find_private_hwc_window(tdm_private_output *private_output,
132 tdm_hwc_window *hwc_window_backend)
134 tdm_private_hwc_window *private_hwc_window = NULL;
136 LIST_FOR_EACH_ENTRY(private_hwc_window, &private_output->hwc_window_list, link) {
137 if (private_hwc_window->hwc_window_backend == hwc_window_backend)
138 return private_hwc_window;
145 tdm_output_init(tdm_private_display *private_display)
147 tdm_thread_cb_set_find_func(TDM_THREAD_CB_OUTPUT_COMMIT, tdm_display_find_output_stamp);
148 tdm_thread_cb_set_find_func(TDM_THREAD_CB_OUTPUT_VBLANK, tdm_display_find_output_stamp);
149 tdm_thread_cb_set_find_func(TDM_THREAD_CB_OUTPUT_STATUS, tdm_display_find_output_stamp);
150 tdm_thread_cb_set_find_func(TDM_THREAD_CB_OUTPUT_DPMS, tdm_display_find_output_stamp);
153 return TDM_ERROR_NONE;
157 tdm_output_get_backend_module(tdm_output *output, tdm_error *error)
159 tdm_private_module *private_module;
161 OUTPUT_FUNC_ENTRY_ERROR();
163 _pthread_mutex_lock(&private_display->lock);
165 private_module = private_output->private_module;
168 *error = TDM_ERROR_NONE;
170 _pthread_mutex_unlock(&private_display->lock);
172 return private_module;
176 tdm_output_get_model_info(tdm_output *output, const char **maker,
177 const char **model, const char **name)
181 _pthread_mutex_lock(&private_display->lock);
184 *maker = private_output->caps.maker;
186 *model = private_output->caps.model;
188 *name = private_output->caps.name;
190 _pthread_mutex_unlock(&private_display->lock);
196 tdm_output_get_capabilities(tdm_output *output, tdm_output_capability *capabilities)
200 TDM_RETURN_VAL_IF_FAIL(capabilities != NULL, TDM_ERROR_INVALID_PARAMETER);
202 _pthread_mutex_lock(&private_display->lock);
204 *capabilities = private_output->caps.capabilities;
206 _pthread_mutex_unlock(&private_display->lock);
212 tdm_output_get_conn_status(tdm_output *output, tdm_output_conn_status *status)
216 TDM_RETURN_VAL_IF_FAIL(status != NULL, TDM_ERROR_INVALID_PARAMETER);
218 _pthread_mutex_lock(&private_display->lock);
220 *status = private_output->caps.status;
222 _pthread_mutex_unlock(&private_display->lock);
228 tdm_output_thread_cb_change(tdm_private_display *private_display, void *object, tdm_thread_cb_base *cb_base, void *user_data)
230 tdm_private_output *private_output = object;
231 tdm_private_output_change_handler *change_handler = user_data;
232 tdm_output_change_type type = TDM_OUTPUT_CHANGE_CONNECTION;
233 tdm_value value = {.u32 = 0 };
235 TDM_RETURN_IF_FAIL(TDM_MUTEX_IS_LOCKED());
237 assert(change_handler->owner_tid == syscall(SYS_gettid));
239 if (cb_base->type == TDM_THREAD_CB_OUTPUT_STATUS) {
240 tdm_thread_cb_output_status *output_status = (tdm_thread_cb_output_status *)cb_base;
241 type = TDM_OUTPUT_CHANGE_CONNECTION;
242 value.u32 = output_status->status;
243 } else if (cb_base->type == TDM_THREAD_CB_OUTPUT_DPMS) {
244 tdm_thread_cb_output_dpms *output_dpms = (tdm_thread_cb_output_dpms *)cb_base;
245 type = TDM_OUTPUT_CHANGE_DPMS;
246 value.u32 = output_dpms->dpms;
248 TDM_NEVER_GET_HERE();
252 _pthread_mutex_unlock(&private_display->lock);
253 change_handler->func(private_output, type, value, change_handler->user_data);
254 _pthread_mutex_lock(&private_display->lock);
259 _tdm_output_call_thread_cb_status(tdm_private_output *private_output, tdm_output_conn_status status)
261 tdm_thread_cb_output_status output_status;
264 memset(&output_status, 0, sizeof output_status);
265 output_status.base.type = TDM_THREAD_CB_OUTPUT_STATUS;
266 output_status.base.length = sizeof output_status;
267 output_status.base.object_stamp = private_output->stamp;
268 output_status.base.data = NULL;
269 output_status.base.sync = 1;
270 output_status.status = status;
272 ret = tdm_thread_cb_call(private_output, &output_status.base, 1);
273 TDM_WARNING_IF_FAIL(ret == TDM_ERROR_NONE);
275 return TDM_ERROR_NONE;
279 _tdm_output_call_thread_cb_dpms(tdm_private_output *private_output, tdm_output_dpms dpms)
281 tdm_thread_cb_output_dpms output_dpms;
284 memset(&output_dpms, 0, sizeof output_dpms);
285 output_dpms.base.type = TDM_THREAD_CB_OUTPUT_DPMS;
286 output_dpms.base.length = sizeof output_dpms;
287 output_dpms.base.object_stamp = private_output->stamp;
288 output_dpms.base.data = NULL;
289 output_dpms.base.sync = 0;
290 output_dpms.dpms = dpms;
292 ret = tdm_thread_cb_call(private_output, &output_dpms.base, 1);
293 TDM_WARNING_IF_FAIL(ret == TDM_ERROR_NONE);
295 return TDM_ERROR_NONE;
299 tdm_output_cb_status(tdm_output *output_backend, tdm_output_conn_status status, void *user_data)
301 tdm_private_output *private_output = user_data;
304 TDM_RETURN_IF_FAIL(private_output);
306 TDM_INFO("output(%d) %s", private_output->pipe, tdm_status_str(status));
308 if ((private_output->caps.status == TDM_OUTPUT_CONN_STATUS_DISCONNECTED && status != TDM_OUTPUT_CONN_STATUS_DISCONNECTED) ||
309 (private_output->caps.status != TDM_OUTPUT_CONN_STATUS_DISCONNECTED && status == TDM_OUTPUT_CONN_STATUS_DISCONNECTED)) {
310 ret = tdm_display_update_output(private_output->private_module, output_backend, private_output->pipe, 1);
311 TDM_RETURN_IF_FAIL(ret == TDM_ERROR_NONE);
313 private_output->caps.status = status;
316 ret = _tdm_output_call_thread_cb_status(private_output, status);
317 TDM_WARNING_IF_FAIL(ret == TDM_ERROR_NONE);
321 tdm_output_cb_dpms(tdm_output *output_backend, tdm_output_dpms dpms, void *user_data)
323 tdm_private_output *private_output = user_data;
326 TDM_INFO("output(%d) %s", private_output->pipe, tdm_status_str(dpms));
328 private_output->current_dpms_value = dpms;
329 private_output->waiting_dpms_change = 0;
330 TDM_INFO("output(%d) dpms async '%s' done", private_output->pipe, tdm_dpms_str(dpms));
332 ret = _tdm_output_call_thread_cb_dpms(private_output, dpms);
333 TDM_WARNING_IF_FAIL(ret == TDM_ERROR_NONE);
337 tdm_output_add_change_handler(tdm_output *output,
338 tdm_output_change_handler func,
341 tdm_private_output_change_handler *change_handler = NULL;
344 TDM_RETURN_VAL_IF_FAIL(func != NULL, TDM_ERROR_INVALID_PARAMETER);
346 _pthread_mutex_lock(&private_display->lock);
348 LIST_FOR_EACH_ENTRY(change_handler, &private_output->change_handler_list, link) {
349 if (change_handler->func == func && change_handler->user_data == user_data) {
350 TDM_ERR("can't add twice");
351 _pthread_mutex_unlock(&private_display->lock);
352 return TDM_ERROR_BAD_REQUEST;
356 change_handler = calloc(1, sizeof(tdm_private_output_change_handler));
357 if (!change_handler) {
358 /* LCOV_EXCL_START */
359 TDM_ERR("failed: alloc memory");
360 _pthread_mutex_unlock(&private_display->lock);
361 return TDM_ERROR_OUT_OF_MEMORY;
365 ret = tdm_thread_cb_add(private_output, TDM_THREAD_CB_OUTPUT_DPMS, NULL, tdm_output_thread_cb_change, change_handler);
366 if (ret != TDM_ERROR_NONE) {
367 /* LCOV_EXCL_START */
368 TDM_ERR("tdm_thread_cb_add failed");
369 free(change_handler);
370 _pthread_mutex_unlock(&private_display->lock);
371 return TDM_ERROR_OPERATION_FAILED;
375 ret = tdm_thread_cb_add(private_output, TDM_THREAD_CB_OUTPUT_STATUS, NULL, tdm_output_thread_cb_change, change_handler);
376 if (ret != TDM_ERROR_NONE) {
377 /* LCOV_EXCL_START */
378 TDM_ERR("tdm_thread_cb_add failed");
379 tdm_thread_cb_remove(private_output, TDM_THREAD_CB_OUTPUT_DPMS, NULL, tdm_output_thread_cb_change, change_handler);
380 free(change_handler);
381 _pthread_mutex_unlock(&private_display->lock);
382 return TDM_ERROR_OPERATION_FAILED;
386 change_handler->private_output = private_output;
387 change_handler->func = func;
388 change_handler->user_data = user_data;
389 change_handler->owner_tid = syscall(SYS_gettid);
391 LIST_ADDTAIL(&change_handler->link, &private_output->change_handler_list);
393 _pthread_mutex_unlock(&private_display->lock);
399 tdm_output_remove_change_handler(tdm_output *output,
400 tdm_output_change_handler func,
403 tdm_private_display *private_display;
404 tdm_private_output *private_output;
405 tdm_private_output_change_handler *change_handler = NULL, *hh = NULL;
407 TDM_RETURN_IF_FAIL(output != NULL);
408 TDM_RETURN_IF_FAIL(func != NULL);
410 private_output = (tdm_private_output*)output;
411 private_display = private_output->private_display;
413 _pthread_mutex_lock(&private_display->lock);
415 LIST_FOR_EACH_ENTRY_SAFE(change_handler, hh, &private_output->change_handler_list, link) {
416 if (change_handler->func != func || change_handler->user_data != user_data)
419 tdm_thread_cb_remove(private_output, TDM_THREAD_CB_OUTPUT_DPMS, NULL, tdm_output_thread_cb_change, change_handler);
420 tdm_thread_cb_remove(private_output, TDM_THREAD_CB_OUTPUT_STATUS, NULL, tdm_output_thread_cb_change, change_handler);
422 LIST_DEL(&change_handler->link);
423 free(change_handler);
425 _pthread_mutex_unlock(&private_display->lock);
430 _pthread_mutex_unlock(&private_display->lock);
434 tdm_output_get_output_type(tdm_output *output, tdm_output_type *type)
438 TDM_RETURN_VAL_IF_FAIL(type != NULL, TDM_ERROR_INVALID_PARAMETER);
440 _pthread_mutex_lock(&private_display->lock);
442 *type = private_output->caps.type;
444 _pthread_mutex_unlock(&private_display->lock);
450 tdm_output_get_layer_count(tdm_output *output, int *count)
452 tdm_private_layer *private_layer = NULL;
456 TDM_RETURN_VAL_IF_FAIL(count != NULL, TDM_ERROR_INVALID_PARAMETER);
458 _pthread_mutex_lock(&private_display->lock);
460 if (private_output->caps.capabilities & TDM_OUTPUT_CAPABILITY_HWC) {
461 TDM_ERR("output(%p) support HWC. Use HWC functions", private_output);
463 _pthread_mutex_unlock(&private_display->lock);
464 return TDM_ERROR_BAD_REQUEST;
468 LIST_FOR_EACH_ENTRY(private_layer, &private_output->layer_list, link)
471 _pthread_mutex_unlock(&private_display->lock);
472 return TDM_ERROR_NONE;
475 _pthread_mutex_unlock(&private_display->lock);
482 tdm_output_get_layer(tdm_output *output, int index, tdm_error *error)
484 tdm_private_layer *private_layer = NULL;
486 OUTPUT_FUNC_ENTRY_ERROR();
488 _pthread_mutex_lock(&private_display->lock);
491 *error = TDM_ERROR_NONE;
493 if (private_output->caps.capabilities & TDM_OUTPUT_CAPABILITY_HWC) {
494 _pthread_mutex_unlock(&private_display->lock);
495 TDM_ERR("output(%p) support HWC. Use HWC functions", private_output);
497 *error = TDM_ERROR_BAD_REQUEST;
501 LIST_FOR_EACH_ENTRY(private_layer, &private_output->layer_list, link) {
502 if (private_layer->index == index) {
503 _pthread_mutex_unlock(&private_display->lock);
504 return private_layer;
508 _pthread_mutex_unlock(&private_display->lock);
514 tdm_output_get_available_properties(tdm_output *output, const tdm_prop **props,
519 TDM_RETURN_VAL_IF_FAIL(props != NULL, TDM_ERROR_INVALID_PARAMETER);
520 TDM_RETURN_VAL_IF_FAIL(count != NULL, TDM_ERROR_INVALID_PARAMETER);
522 _pthread_mutex_lock(&private_display->lock);
524 *props = (const tdm_prop *)private_output->caps.props;
525 *count = private_output->caps.prop_count;
527 _pthread_mutex_unlock(&private_display->lock);
533 tdm_output_get_available_modes(tdm_output *output,
534 const tdm_output_mode **modes, int *count)
538 TDM_RETURN_VAL_IF_FAIL(modes != NULL, TDM_ERROR_INVALID_PARAMETER);
539 TDM_RETURN_VAL_IF_FAIL(count != NULL, TDM_ERROR_INVALID_PARAMETER);
541 _pthread_mutex_lock(&private_display->lock);
543 *modes = (const tdm_output_mode *)private_output->caps.modes;
544 *count = private_output->caps.mode_count;
546 _pthread_mutex_unlock(&private_display->lock);
552 tdm_output_get_available_size(tdm_output *output, int *min_w, int *min_h,
553 int *max_w, int *max_h, int *preferred_align)
557 _pthread_mutex_lock(&private_display->lock);
560 *min_w = TDM_FRONT_VALUE(private_output->caps.min_w);
562 *min_h = TDM_FRONT_VALUE(private_output->caps.min_h);
564 *max_w = TDM_FRONT_VALUE(private_output->caps.max_w);
566 *max_h = TDM_FRONT_VALUE(private_output->caps.max_h);
568 *preferred_align = TDM_FRONT_VALUE(private_output->caps.preferred_align);
570 _pthread_mutex_unlock(&private_display->lock);
576 tdm_output_get_cursor_available_size(tdm_output *output, int *min_w, int *min_h,
577 int *max_w, int *max_h, int *preferred_align)
581 _pthread_mutex_lock(&private_display->lock);
583 if (!tdm_module_check_abi(private_output->private_module, 1, 5)) {
584 _pthread_mutex_unlock(&private_display->lock);
585 return TDM_ERROR_BAD_REQUEST;
589 *min_w = TDM_FRONT_VALUE(private_output->caps.cursor_min_w);
591 *min_h = TDM_FRONT_VALUE(private_output->caps.cursor_min_h);
593 *max_w = TDM_FRONT_VALUE(private_output->caps.cursor_max_w);
595 *max_h = TDM_FRONT_VALUE(private_output->caps.cursor_max_h);
597 *preferred_align = TDM_FRONT_VALUE(private_output->caps.cursor_preferred_align);
599 _pthread_mutex_unlock(&private_display->lock);
605 tdm_output_get_physical_size(tdm_output *output, unsigned int *mmWidth,
606 unsigned int *mmHeight)
610 _pthread_mutex_lock(&private_display->lock);
613 *mmWidth = private_output->caps.mmWidth;
615 *mmHeight = private_output->caps.mmHeight;
617 _pthread_mutex_unlock(&private_display->lock);
623 tdm_output_get_subpixel(tdm_output *output, unsigned int *subpixel)
626 TDM_RETURN_VAL_IF_FAIL(subpixel != NULL, TDM_ERROR_INVALID_PARAMETER);
628 _pthread_mutex_lock(&private_display->lock);
630 *subpixel = private_output->caps.subpixel;
632 _pthread_mutex_unlock(&private_display->lock);
638 tdm_output_get_pipe(tdm_output *output, unsigned int *pipe)
641 TDM_RETURN_VAL_IF_FAIL(pipe != NULL, TDM_ERROR_INVALID_PARAMETER);
643 _pthread_mutex_lock(&private_display->lock);
645 *pipe = private_output->pipe;
647 _pthread_mutex_unlock(&private_display->lock);
653 tdm_output_get_primary_index(tdm_output *output, int *index)
655 tdm_private_layer *private_layer = NULL;
658 TDM_RETURN_VAL_IF_FAIL(index != NULL, TDM_ERROR_INVALID_PARAMETER);
660 _pthread_mutex_lock(&private_display->lock);
662 LIST_FOR_EACH_ENTRY(private_layer, &private_output->layer_list, link) {
663 if (private_layer->caps.capabilities & TDM_LAYER_CAPABILITY_PRIMARY) {
664 *index = private_layer->index;
669 _pthread_mutex_unlock(&private_display->lock);
675 tdm_output_set_property(tdm_output *output, unsigned int id, tdm_value value)
677 tdm_private_module *private_module;
678 tdm_func_output *func_output;
681 _pthread_mutex_lock(&private_display->lock);
683 private_module = private_output->private_module;
684 func_output = &private_module->func_output;
686 if (!func_output->output_set_property) {
687 /* LCOV_EXCL_START */
688 _pthread_mutex_unlock(&private_display->lock);
689 TDM_WRN("not implemented!!");
690 return TDM_ERROR_NOT_IMPLEMENTED;
694 ret = func_output->output_set_property(private_output->output_backend, id,
697 _pthread_mutex_unlock(&private_display->lock);
703 tdm_output_get_property(tdm_output *output, unsigned int id, tdm_value *value)
705 tdm_private_module *private_module;
706 tdm_func_output *func_output;
709 TDM_RETURN_VAL_IF_FAIL(value != NULL, TDM_ERROR_INVALID_PARAMETER);
711 _pthread_mutex_lock(&private_display->lock);
713 private_module = private_output->private_module;
714 func_output = &private_module->func_output;
716 if (!func_output->output_get_property) {
717 /* LCOV_EXCL_START */
718 _pthread_mutex_unlock(&private_display->lock);
719 TDM_WRN("not implemented!!");
720 return TDM_ERROR_NOT_IMPLEMENTED;
724 ret = func_output->output_get_property(private_output->output_backend, id,
727 _pthread_mutex_unlock(&private_display->lock);
733 _tdm_output_thread_cb_vblank(tdm_private_display *private_display, void *object, tdm_thread_cb_base *cb_base, void *user_data)
735 tdm_thread_cb_output_vblank *output_vblank = (tdm_thread_cb_output_vblank *)cb_base;
736 tdm_private_output_vblank_handler *vblank_handler = output_vblank->base.data;
737 tdm_private_output_vblank_handler *v = NULL, *vv = NULL;
738 tdm_private_output *private_output = object;
739 struct list_head clone_list;
741 pid_t tid = syscall(SYS_gettid);
743 TDM_RETURN_IF_FAIL(TDM_MUTEX_IS_LOCKED());
745 assert(vblank_handler->owner_tid == tid);
747 vblank_handler->sent_to_frontend = 0;
749 _tdm_output_vblank_timeout_update(private_output, 0);
751 tdm_thread_cb_remove(private_output, TDM_THREAD_CB_OUTPUT_VBLANK, vblank_handler, _tdm_output_thread_cb_vblank, NULL);
753 interval = vblank_handler->interval;
754 sync = vblank_handler->sync;
756 LIST_INITHEAD(&clone_list);
758 LIST_FOR_EACH_ENTRY_SAFE(v, vv, &private_output->vblank_handler_list, link) {
759 if (v->interval != interval || v->sync != sync || v->owner_tid != tid)
763 LIST_ADDTAIL(&v->link, &clone_list);
766 if (tdm_debug_module & TDM_DEBUG_COMMIT)
767 TDM_INFO("----------------------------------------- output(%d) got vblank", private_output->pipe);
769 _pthread_mutex_unlock(&private_display->lock);
770 LIST_FOR_EACH_ENTRY_SAFE(v, vv, &clone_list, link) {
771 if (tdm_debug_module & TDM_DEBUG_COMMIT)
772 TDM_INFO("handler(%p)", v);
777 v->func(v->private_output,
778 output_vblank->sequence,
779 output_vblank->tv_sec,
780 output_vblank->tv_usec,
785 _pthread_mutex_lock(&private_display->lock);
787 if (tdm_debug_module & TDM_DEBUG_COMMIT)
788 TDM_INFO("-----------------------------------------...");
792 _tdm_output_cb_vblank(tdm_output *output_backend, unsigned int sequence,
793 unsigned int tv_sec, unsigned int tv_usec, void *user_data)
795 tdm_private_output_vblank_handler *vblank_handler = user_data;
796 tdm_thread_cb_output_vblank output_vblank;
799 memset(&output_vblank, 0, sizeof output_vblank);
800 output_vblank.base.type = TDM_THREAD_CB_OUTPUT_VBLANK;
801 output_vblank.base.length = sizeof output_vblank;
802 output_vblank.base.object_stamp = vblank_handler->private_output->stamp;
803 output_vblank.base.data = vblank_handler;
804 output_vblank.base.sync = 0;
805 output_vblank.sequence = sequence;
806 output_vblank.tv_sec = tv_sec;
807 output_vblank.tv_usec = tv_usec;
809 vblank_handler->sent_to_frontend = 1;
811 if (tdm_debug_module & TDM_DEBUG_COMMIT)
812 TDM_INFO("output(%d) wait_vblank: handler(%p)", vblank_handler->private_output->pipe, vblank_handler);
814 ret = tdm_thread_cb_call(vblank_handler->private_output, &output_vblank.base, 1);
815 TDM_WARNING_IF_FAIL(ret == TDM_ERROR_NONE);
819 _tdm_output_thread_cb_commit(tdm_private_display *private_display, void *object, tdm_thread_cb_base *cb_base, void *user_data)
821 tdm_thread_cb_output_commit *output_commit = (tdm_thread_cb_output_commit *)cb_base;
822 tdm_private_output_commit_handler *output_commit_handler = output_commit->base.data;
823 tdm_private_output *private_output = object;
824 tdm_private_layer *private_layer = NULL;
826 TDM_RETURN_IF_FAIL(TDM_MUTEX_IS_LOCKED());
828 if (!output_commit_handler)
831 assert(output_commit_handler->owner_tid == syscall(SYS_gettid));
833 tdm_thread_cb_remove(private_output, TDM_THREAD_CB_OUTPUT_COMMIT, output_commit_handler, _tdm_output_thread_cb_commit, NULL);
835 LIST_DEL(&output_commit_handler->link);
837 if (tdm_debug_module & TDM_DEBUG_COMMIT) {
838 TDM_INFO("----------------------------------------- output(%d) committed", private_output->pipe);
839 TDM_INFO("handler(%p)", output_commit_handler);
842 if (private_output->commit_type == TDM_COMMIT_TYPE_OUTPUT) {
843 /* In case of layer commit, the below will be handled in the layer commit callback */
844 LIST_FOR_EACH_ENTRY(private_layer, &private_output->layer_list, link) {
845 if (private_layer->committed_buffer)
846 tdm_layer_committed(private_layer, &private_layer->committed_buffer);
850 if (output_commit_handler->func) {
851 _pthread_mutex_unlock(&private_display->lock);
852 output_commit_handler->func(private_output,
853 output_commit->sequence,
854 output_commit->tv_sec,
855 output_commit->tv_usec,
856 output_commit_handler->user_data);
857 _pthread_mutex_lock(&private_display->lock);
860 free(output_commit_handler);
862 if (tdm_debug_module & TDM_DEBUG_COMMIT)
863 TDM_INFO("-----------------------------------------...");
867 _tdm_output_cb_commit(tdm_output *output_backend, unsigned int sequence,
868 unsigned int tv_sec, unsigned int tv_usec, void *user_data)
870 tdm_private_output_commit_handler *output_commit_handler = user_data;
871 tdm_private_output *private_output;
872 tdm_thread_cb_output_commit output_commit;
875 if (output_commit_handler)
876 private_output = output_commit_handler->private_output;
878 private_output = tdm_display_find_private_output(tdm_display_get(), output_backend);
880 memset(&output_commit, 0, sizeof output_commit);
881 output_commit.base.type = TDM_THREAD_CB_OUTPUT_COMMIT;
882 output_commit.base.length = sizeof output_commit;
883 output_commit.base.object_stamp = private_output->stamp;
884 output_commit.base.data = output_commit_handler;
885 output_commit.base.sync = 0;
886 output_commit.sequence = sequence;
887 output_commit.tv_sec = tv_sec;
888 output_commit.tv_usec = tv_usec;
890 ret = tdm_thread_cb_call(private_output, &output_commit.base, 1);
891 TDM_WARNING_IF_FAIL(ret == TDM_ERROR_NONE);
894 /* add_front: To distinguish between the user vblank handlers and the layer
895 * commit vblank handlers. The layer commit handlers will be called
896 * before calling the user vblank handlers.
899 _tdm_output_wait_vblank(tdm_private_output *private_output, int interval, int sync,
900 tdm_output_vblank_handler func, void *user_data,
901 unsigned int add_front)
903 tdm_private_module *private_module;
904 tdm_func_output *func_output;
905 tdm_private_output_vblank_handler *vblank_handler = NULL, *v = NULL;
906 unsigned int skip_request = 0;
907 pid_t tid = syscall(SYS_gettid);
908 tdm_error ret = TDM_ERROR_NONE;
910 private_module = private_output->private_module;
911 func_output = &private_module->func_output;
913 /* interval SHOULD be at least 1 */
917 if (!func_output->output_wait_vblank) {
918 /* LCOV_EXCL_START */
919 TDM_WRN("not implemented!!");
920 return TDM_ERROR_NOT_IMPLEMENTED;
924 if (!private_output->regist_vblank_cb) {
925 private_output->regist_vblank_cb = 1;
926 ret = func_output->output_set_vblank_handler(private_output->output_backend,
927 _tdm_output_cb_vblank);
930 vblank_handler = calloc(1, sizeof(tdm_private_output_vblank_handler));
931 if (!vblank_handler) {
932 /* LCOV_EXCL_START */
933 TDM_ERR("failed: alloc memory");
934 return TDM_ERROR_OUT_OF_MEMORY;
938 if (tdm_debug_module & TDM_DEBUG_COMMIT)
939 TDM_INFO("output(%d) wait_vblank: handler(%p)", private_output->pipe, vblank_handler);
941 LIST_FOR_EACH_ENTRY(v, &private_output->vblank_handler_list, link) {
942 if (v->interval == interval && v->sync == sync && v->owner_tid == tid) {
949 LIST_ADD(&vblank_handler->link, &private_output->vblank_handler_list);
951 LIST_ADDTAIL(&vblank_handler->link, &private_output->vblank_handler_list);
953 vblank_handler->private_output = private_output;
954 vblank_handler->interval = interval;
955 vblank_handler->sync = sync;
956 vblank_handler->func = func;
957 vblank_handler->user_data = user_data;
958 vblank_handler->owner_tid = tid;
960 /* If there is the previous request, we can skip to call output_wait_vblank() */
962 ret = tdm_thread_cb_add(private_output, TDM_THREAD_CB_OUTPUT_VBLANK, vblank_handler, _tdm_output_thread_cb_vblank, NULL);
963 if (ret != TDM_ERROR_NONE) {
964 TDM_ERR("tdm_thread_cb_add failed");
968 ret = func_output->output_wait_vblank(private_output->output_backend, interval,
969 sync, vblank_handler);
970 TDM_GOTO_IF_FAIL(ret == TDM_ERROR_NONE, wait_failed);
972 _tdm_output_vblank_timeout_update(private_output, 1000);
974 if (tdm_debug_module & TDM_DEBUG_COMMIT)
975 TDM_INFO("output(%d) backend wait_vblank", private_output->pipe);
981 /* LCOV_EXCL_START */
982 if (vblank_handler) {
983 tdm_thread_cb_remove(private_output, TDM_THREAD_CB_OUTPUT_VBLANK, vblank_handler, _tdm_output_thread_cb_vblank, NULL);
984 LIST_DEL(&vblank_handler->link);
985 free(vblank_handler);
992 tdm_output_wait_vblank(tdm_output *output, int interval, int sync,
993 tdm_output_vblank_handler func, void *user_data)
996 TDM_RETURN_VAL_IF_FAIL(interval > 0, TDM_ERROR_INVALID_PARAMETER);
998 _pthread_mutex_lock(&private_display->lock);
1000 if (TDM_OUTPUT_DPMS_VSYNC_IS_OFF(private_output->current_dpms_value)) {
1001 TDM_WRN("output(%d) dpms: %s", private_output->pipe,
1002 tdm_dpms_str(private_output->current_dpms_value));
1003 _pthread_mutex_unlock(&private_display->lock);
1004 return TDM_ERROR_DPMS_OFF;
1007 ret = _tdm_output_wait_vblank(private_output, interval, sync, func, user_data, 0);
1009 _pthread_mutex_unlock(&private_display->lock);
1014 /* LCOV_EXCL_START */
1016 tdm_output_wait_vblank_add_front(tdm_output *output, int interval, int sync,
1017 tdm_output_vblank_handler func, void *user_data)
1019 OUTPUT_FUNC_ENTRY();
1021 _pthread_mutex_lock(&private_display->lock);
1023 if (TDM_OUTPUT_DPMS_VSYNC_IS_OFF(private_output->current_dpms_value)) {
1024 TDM_WRN("output(%d) dpms: %s", private_output->pipe,
1025 tdm_dpms_str(private_output->current_dpms_value));
1026 _pthread_mutex_unlock(&private_display->lock);
1027 return TDM_ERROR_DPMS_OFF;
1030 ret = _tdm_output_wait_vblank(private_output, interval, sync, func, user_data, 1);
1032 _pthread_mutex_unlock(&private_display->lock);
1036 /* LCOV_EXCL_STOP */
1039 tdm_output_remove_vblank_handler_internal(tdm_output *output, tdm_output_vblank_handler func, void *user_data)
1041 tdm_private_output *private_output = (tdm_private_output*)output;
1042 tdm_private_output_vblank_handler *v = NULL;
1044 TDM_RETURN_IF_FAIL(private_output != NULL);
1045 TDM_RETURN_IF_FAIL(TDM_MUTEX_IS_LOCKED());
1047 LIST_FOR_EACH_ENTRY(v, &private_output->vblank_handler_list, link) {
1048 if (v->func == func && v->user_data == user_data) {
1049 /* only set func & user_data to NULL. It will be freed when an event occurs */
1051 v->user_data = NULL;
1058 tdm_output_remove_commit_handler_internal(tdm_output *output, tdm_output_commit_handler func, void *user_data)
1060 tdm_private_output *private_output = (tdm_private_output*)output;
1061 tdm_private_output_commit_handler *c = NULL;
1063 TDM_RETURN_IF_FAIL(private_output != NULL);
1064 TDM_RETURN_IF_FAIL(TDM_MUTEX_IS_LOCKED());
1066 LIST_FOR_EACH_ENTRY(c, &private_output->output_commit_handler_list, link) {
1067 if (c->func == func && c->user_data == user_data) {
1068 /* only set func & user_data to NULL. It will be freed when an event occurs */
1070 c->user_data = NULL;
1077 tdm_output_remove_vblank_handler(tdm_output *output, tdm_output_vblank_handler func, void *user_data)
1079 OUTPUT_FUNC_ENTRY();
1081 _pthread_mutex_lock(&private_display->lock);
1083 tdm_output_remove_vblank_handler_internal(output, func, user_data);
1085 _pthread_mutex_unlock(&private_display->lock);
1091 tdm_output_remove_commit_handler(tdm_output *output, tdm_output_commit_handler func, void *user_data)
1093 OUTPUT_FUNC_ENTRY();
1095 _pthread_mutex_lock(&private_display->lock);
1097 tdm_output_remove_commit_handler_internal(output, func, user_data);
1099 _pthread_mutex_unlock(&private_display->lock);
1105 tdm_output_commit_internal(tdm_output *output, int sync, tdm_output_commit_handler func, void *user_data)
1107 tdm_private_output *private_output;
1108 tdm_private_module *private_module;
1109 tdm_func_output *func_output;
1110 tdm_private_output_commit_handler *output_commit_handler = NULL;
1111 tdm_private_layer *private_layer = NULL;
1112 tdm_output_dpms dpms_value = TDM_OUTPUT_DPMS_ON;
1113 tdm_error ret = TDM_ERROR_NONE;
1115 TDM_RETURN_VAL_IF_FAIL(output != NULL, TDM_ERROR_INVALID_PARAMETER);
1117 private_output = (tdm_private_output*)output;
1118 private_module = private_output->private_module;
1119 func_output = &private_module->func_output;
1121 if (!func_output->output_commit) {
1122 /* LCOV_EXCL_START */
1123 TDM_WRN("not implemented!!");
1124 return TDM_ERROR_NOT_IMPLEMENTED;
1125 /* LCOV_EXCL_STOP */
1128 ret = tdm_output_get_dpms_internal(output, &dpms_value);
1129 TDM_RETURN_VAL_IF_FAIL(ret == TDM_ERROR_NONE, ret);
1131 if (!TDM_OUTPUT_DPMS_VSYNC_IS_OFF(dpms_value)) {
1132 if (!private_output->regist_commit_cb) {
1133 private_output->regist_commit_cb = 1;
1134 ret = func_output->output_set_commit_handler(private_output->output_backend, _tdm_output_cb_commit);
1135 TDM_GOTO_IF_FAIL(ret == TDM_ERROR_NONE, commit_failed);
1138 output_commit_handler = calloc(1, sizeof(tdm_private_output_commit_handler));
1139 if (!output_commit_handler) {
1140 /* LCOV_EXCL_START */
1141 TDM_ERR("failed: alloc memory");
1142 return TDM_ERROR_OUT_OF_MEMORY;
1143 /* LCOV_EXCL_STOP */
1146 ret = tdm_thread_cb_add(private_output, TDM_THREAD_CB_OUTPUT_COMMIT, output_commit_handler, _tdm_output_thread_cb_commit, NULL);
1147 if (ret != TDM_ERROR_NONE) {
1148 TDM_ERR("tdm_thread_cb_add failed");
1149 free(output_commit_handler);
1153 LIST_ADDTAIL(&output_commit_handler->link, &private_output->output_commit_handler_list);
1154 output_commit_handler->private_output = private_output;
1155 output_commit_handler->func = func;
1156 output_commit_handler->user_data = user_data;
1157 output_commit_handler->owner_tid = syscall(SYS_gettid);
1159 ret = func_output->output_commit(private_output->output_backend, sync,
1160 output_commit_handler);
1161 TDM_GOTO_IF_FAIL(ret == TDM_ERROR_NONE, commit_failed);
1163 if (ret == TDM_ERROR_NONE) {
1164 if (private_output->current_mode &&
1165 private_output->caps.status != TDM_OUTPUT_CONN_STATUS_MODE_SETTED) {
1166 TDM_WRN("backend doesn't change the output connection status");
1167 tdm_output_cb_status(private_output->output_backend,
1168 TDM_OUTPUT_CONN_STATUS_MODE_SETTED,
1173 if (tdm_debug_module & TDM_DEBUG_COMMIT)
1174 TDM_INFO("output(%d) backend commit: handle(%p) func(%p) user_data(%p)",
1175 private_output->pipe, output_commit_handler, func, user_data);
1178 /* Even if DPMS is off, committed_buffer should be changed because it will be referred
1179 * for tdm_layer_committed() function.
1181 LIST_FOR_EACH_ENTRY(private_layer, &private_output->layer_list, link) {
1182 if (!private_layer->waiting_buffer)
1185 if (private_layer->committed_buffer) {
1186 tdm_layer_free_buffer(private_layer, private_layer->committed_buffer);
1187 private_layer->committed_buffer = NULL;
1188 if (tdm_debug_module & TDM_DEBUG_BUFFER)
1189 TDM_INFO("layer(%p) waiting_buffer(%p) committed_buffer(%p)",
1190 private_layer, private_layer->waiting_buffer->buffer,
1191 private_layer->committed_buffer);
1194 private_layer->committed_buffer = private_layer->waiting_buffer;
1195 private_layer->waiting_buffer = NULL;
1196 if (tdm_debug_module & TDM_DEBUG_BUFFER)
1197 TDM_INFO("layer(%p) waiting_buffer(%p) committed_buffer(%p)",
1198 private_layer, private_layer->waiting_buffer,
1199 private_layer->committed_buffer->buffer);
1202 if (TDM_OUTPUT_DPMS_VSYNC_IS_OFF(dpms_value)) {
1203 TDM_WRN("dpms %s. Directly call commit handler instead of commit.", tdm_dpms_str(dpms_value));
1205 func(output, 0, 0, 0, user_data);
1211 /* LCOV_EXCL_START */
1212 if (output_commit_handler) {
1213 tdm_thread_cb_remove(private_output, TDM_THREAD_CB_OUTPUT_COMMIT, output_commit_handler, _tdm_output_thread_cb_commit, NULL);
1214 LIST_DEL(&output_commit_handler->link);
1215 free(output_commit_handler);
1218 /* LCOV_EXCL_STOP */
1222 tdm_output_commit(tdm_output *output, int sync, tdm_output_commit_handler func,
1225 tdm_private_layer *private_layer = NULL;
1227 OUTPUT_FUNC_ENTRY();
1229 _pthread_mutex_lock(&private_display->lock);
1231 if (private_output->commit_type == TDM_COMMIT_TYPE_NONE)
1232 private_output->commit_type = TDM_COMMIT_TYPE_OUTPUT;
1233 else if (private_output->commit_type == TDM_COMMIT_TYPE_LAYER) {
1234 TDM_ERR("Can't supported. Use tdm_layer_commit");
1235 _pthread_mutex_unlock(&private_display->lock);
1236 return TDM_ERROR_BAD_REQUEST;
1239 if (private_output->commit_per_vblank) {
1240 TDM_ERR("Use tdm_layer_commit");
1241 _pthread_mutex_unlock(&private_display->lock);
1242 return TDM_ERROR_BAD_REQUEST;
1245 if (TDM_OUTPUT_DPMS_VSYNC_IS_OFF(private_output->current_dpms_value)) {
1246 TDM_ERR("output(%d) dpms: %s", private_output->pipe,
1247 tdm_dpms_str(private_output->current_dpms_value));
1248 _pthread_mutex_unlock(&private_display->lock);
1249 return TDM_ERROR_DPMS_OFF;
1252 if (tdm_debug_module & TDM_DEBUG_COMMIT)
1253 TDM_INFO("output(%d) commit", private_output->pipe);
1255 /* apply the pending data of all layers */
1256 LIST_FOR_EACH_ENTRY(private_layer, &private_output->layer_list, link) {
1257 tdm_layer_commit_pending_data(private_layer);
1260 ret = tdm_output_commit_internal(output, sync, func, user_data);
1262 _pthread_mutex_unlock(&private_display->lock);
1268 tdm_output_set_mode(tdm_output *output, const tdm_output_mode *mode)
1270 tdm_private_module *private_module;
1271 tdm_func_output *func_output;
1272 OUTPUT_FUNC_ENTRY();
1274 TDM_RETURN_VAL_IF_FAIL(mode != NULL, TDM_ERROR_INVALID_PARAMETER);
1276 _pthread_mutex_lock(&private_display->lock);
1278 private_module = private_output->private_module;
1279 func_output = &private_module->func_output;
1281 if (!func_output->output_set_mode) {
1282 /* LCOV_EXCL_START */
1283 _pthread_mutex_unlock(&private_display->lock);
1284 TDM_WRN("not implemented!!");
1285 return TDM_ERROR_NOT_IMPLEMENTED;
1286 /* LCOV_EXCL_STOP */
1289 ret = func_output->output_set_mode(private_output->output_backend, mode);
1290 if (ret == TDM_ERROR_NONE) {
1291 private_output->current_mode = mode;
1292 private_output->need_set_target_info = 1;
1293 TDM_INFO("mode: %dx%d %dhz", mode->hdisplay, mode->vdisplay, mode->vrefresh);
1296 _pthread_mutex_unlock(&private_display->lock);
1302 tdm_output_get_mode(tdm_output *output, const tdm_output_mode **mode)
1304 OUTPUT_FUNC_ENTRY();
1306 TDM_RETURN_VAL_IF_FAIL(mode != NULL, TDM_ERROR_INVALID_PARAMETER);
1308 _pthread_mutex_lock(&private_display->lock);
1310 *mode = private_output->current_mode;
1312 _pthread_mutex_unlock(&private_display->lock);
1318 tdm_output_set_dpms(tdm_output *output, tdm_output_dpms dpms_value)
1320 tdm_private_module *private_module;
1321 tdm_func_output *func_output;
1322 OUTPUT_FUNC_ENTRY();
1324 if (dpms_value > TDM_OUTPUT_DPMS_OFF) {
1325 if (dpms_value & TDM_OUTPUT_DPMS_DEFAULT_MASK) {
1326 TDM_ERR("Don't use the low-4bit for an extended DPMS mode: dpms_value(%x)", dpms_value);
1327 return TDM_ERROR_BAD_REQUEST;
1330 if (!(private_output->caps.capabilities & TDM_OUTPUT_CAPABILITY_EXTENDED_DPMS)) {
1331 TDM_ERR("output(%d) doesn't support the extended DPMS control: '%s'",
1332 private_output->pipe, tdm_dpms_str(dpms_value));
1333 return TDM_ERROR_BAD_REQUEST;
1337 _pthread_mutex_lock(&private_display->lock);
1339 if (private_output->waiting_dpms_change) {
1340 TDM_ERR("DPMS is not changed yet. Can't be changed twice");
1341 _pthread_mutex_unlock(&private_display->lock);
1342 return TDM_ERROR_BAD_REQUEST;
1345 private_module = private_output->private_module;
1346 func_output = &private_module->func_output;
1348 TDM_INFO("output(%d) dpms '%s'", private_output->pipe, tdm_dpms_str(dpms_value));
1350 if (func_output->output_set_dpms)
1351 ret = func_output->output_set_dpms(private_output->output_backend, dpms_value);
1353 /* LCOV_EXCL_START */
1354 ret = TDM_ERROR_NONE;
1355 TDM_WRN("not implemented!!");
1357 /* LCOV_EXCL_STOP */
1361 if (ret == TDM_ERROR_NONE) {
1362 if (private_output->current_dpms_value != dpms_value) {
1363 private_output->current_dpms_value = dpms_value;
1364 _tdm_output_call_thread_cb_dpms(private_output, dpms_value);
1366 TDM_INFO("output(%d) dpms '%s' done", private_output->pipe, tdm_dpms_str(dpms_value));
1368 tdm_output_dpms temp = TDM_OUTPUT_DPMS_OFF;
1370 /* update current_dpms_value forcely */
1371 tdm_output_get_dpms_internal(output, &temp);
1373 TDM_ERR("output(%d) set_dpms failed: dpms '%s'", private_output->pipe, tdm_dpms_str(temp));
1376 _pthread_mutex_unlock(&private_display->lock);
1381 /* LCOV_EXCL_START */
1383 tdm_output_set_dpms_async(tdm_output *output, tdm_output_dpms dpms_value)
1385 tdm_private_module *private_module;
1386 tdm_func_output *func_output;
1387 OUTPUT_FUNC_ENTRY();
1389 if (!(private_output->caps.capabilities & TDM_OUTPUT_CAPABILITY_ASYNC_DPMS)) {
1390 TDM_ERR("output doesn't support the asynchronous DPMS control!");
1391 return TDM_ERROR_BAD_REQUEST;
1394 if (dpms_value > TDM_OUTPUT_DPMS_OFF) {
1395 if (dpms_value & TDM_OUTPUT_DPMS_DEFAULT_MASK) {
1396 TDM_ERR("Don't use the low-4bit for an extended DPMS mode: dpms_value(%x)", dpms_value);
1397 return TDM_ERROR_BAD_REQUEST;
1400 if (!(private_output->caps.capabilities & TDM_OUTPUT_CAPABILITY_EXTENDED_DPMS)) {
1401 TDM_ERR("output(%d) doesn't support the extended DPMS control: '%s'",
1402 private_output->pipe, tdm_dpms_str(dpms_value));
1403 return TDM_ERROR_BAD_REQUEST;
1407 _pthread_mutex_lock(&private_display->lock);
1409 if (private_output->waiting_dpms_change) {
1410 TDM_ERR("DPMS is not changed yet. Can't be changed twice");
1411 _pthread_mutex_unlock(&private_display->lock);
1412 return TDM_ERROR_BAD_REQUEST;
1415 private_module = private_output->private_module;
1416 func_output = &private_module->func_output;
1417 if (!func_output->output_set_dpms_handler) {
1418 TDM_WRN("not implemented: output_set_dpms_handler");
1419 _pthread_mutex_unlock(&private_display->lock);
1420 return TDM_ERROR_NOT_IMPLEMENTED;
1423 if (!func_output->output_set_dpms_async) {
1424 TDM_WRN("not implemented: output_set_dpms_async");
1425 _pthread_mutex_unlock(&private_display->lock);
1426 return TDM_ERROR_NOT_IMPLEMENTED;
1429 if (!private_output->regist_dpms_cb) {
1430 private_output->regist_dpms_cb = 1;
1431 ret = func_output->output_set_dpms_handler(private_output->output_backend,
1432 tdm_output_cb_dpms, private_output);
1433 if (ret != TDM_ERROR_NONE) {
1434 _pthread_mutex_unlock(&private_display->lock);
1435 TDM_ERR("Can't set the dpms handler!!");
1440 TDM_INFO("output(%d) dpms async '%s'", private_output->pipe, tdm_dpms_str(dpms_value));
1442 ret = func_output->output_set_dpms_async(private_output->output_backend, dpms_value);
1444 if (ret == TDM_ERROR_NONE) {
1445 private_output->waiting_dpms_change = 1;
1446 TDM_INFO("output(%d) dpms async '%s' waiting", private_output->pipe, tdm_dpms_str(dpms_value));
1448 tdm_output_dpms temp = TDM_OUTPUT_DPMS_OFF;
1450 /* update current_dpms_value forcely */
1451 tdm_output_get_dpms_internal(output, &temp);
1453 TDM_ERR("output(%d) set_dpms_async failed: dpms '%s'", private_output->pipe, tdm_dpms_str(temp));
1456 _pthread_mutex_unlock(&private_display->lock);
1460 /* LCOV_EXCL_STOP */
1463 tdm_output_get_dpms_internal(tdm_output *output, tdm_output_dpms *dpms_value)
1465 tdm_private_output *private_output;
1466 tdm_private_module *private_module;
1467 tdm_func_output *func_output;
1468 tdm_error ret = TDM_ERROR_NONE;
1470 TDM_RETURN_VAL_IF_FAIL(output != NULL, TDM_ERROR_INVALID_PARAMETER);
1472 private_output = (tdm_private_output*)output;
1474 /* TODO: this is ugly. But before calling backend's output_get_dpms(), we have
1475 * to check if all backends's DPMS operation has no problem. In future, we'd
1476 * better use new env instead of using commit_per_vblank variable to distinguish
1477 * whether we use the stored value or backend's output_get_dpms.
1479 if (!private_output->commit_per_vblank) {
1480 *dpms_value = private_output->current_dpms_value;
1481 return TDM_ERROR_NONE;
1484 private_module = private_output->private_module;
1485 func_output = &private_module->func_output;
1487 if (!func_output->output_get_dpms) {
1488 /* LCOV_EXCL_START */
1489 *dpms_value = private_output->current_dpms_value;
1490 TDM_WRN("not implemented!!");
1491 return TDM_ERROR_NONE;
1492 /* LCOV_EXCL_STOP */
1495 ret = func_output->output_get_dpms(private_output->output_backend, dpms_value);
1496 if (ret != TDM_ERROR_NONE) {
1497 /* LCOV_EXCL_START */
1498 TDM_ERR("output_get_dpms failed");
1499 *dpms_value = TDM_OUTPUT_DPMS_OFF;
1500 /* LCOV_EXCL_STOP */
1503 /* checking with backend's value */
1504 if (*dpms_value != private_output->current_dpms_value) {
1505 TDM_ERR("output(%d) dpms changed suddenly: %s -> %s",
1506 private_output->pipe, tdm_dpms_str(private_output->current_dpms_value),
1507 tdm_dpms_str(*dpms_value));
1508 private_output->current_dpms_value = *dpms_value;
1509 _tdm_output_call_thread_cb_dpms(private_output, *dpms_value);
1516 tdm_output_get_dpms(tdm_output *output, tdm_output_dpms *dpms_value)
1518 OUTPUT_FUNC_ENTRY();
1520 TDM_RETURN_VAL_IF_FAIL(dpms_value != NULL, TDM_ERROR_INVALID_PARAMETER);
1522 _pthread_mutex_lock(&private_display->lock);
1524 ret = tdm_output_get_dpms_internal(output, dpms_value);
1526 _pthread_mutex_unlock(&private_display->lock);
1532 tdm_output_has_capture_capability(tdm_output *output, unsigned int *has_capability)
1534 tdm_private_module *private_module;
1536 OUTPUT_FUNC_ENTRY();
1538 TDM_RETURN_VAL_IF_FAIL(has_capability != NULL, TDM_ERROR_INVALID_PARAMETER);
1540 _pthread_mutex_lock(&private_display->lock);
1542 private_module = private_output->private_module;
1544 if (!(private_module->capabilities & TDM_DISPLAY_CAPABILITY_CAPTURE))
1545 *has_capability = 0;
1546 else if (!(private_module->caps_capture.capabilities & TDM_CAPTURE_CAPABILITY_OUTPUT))
1547 *has_capability = 0;
1549 *has_capability = 1;
1551 _pthread_mutex_unlock(&private_display->lock);
1556 EXTERN tdm_capture *
1557 tdm_output_create_capture(tdm_output *output, tdm_error *error)
1559 tdm_capture *capture = NULL;
1561 OUTPUT_FUNC_ENTRY_ERROR();
1563 _pthread_mutex_lock(&private_display->lock);
1565 capture = (tdm_capture *)tdm_capture_create_output_internal(private_output, error);
1567 _pthread_mutex_unlock(&private_display->lock);
1572 EXTERN tdm_hwc_window *
1573 tdm_output_hwc_create_window(tdm_output *output, tdm_error *error)
1575 tdm_hwc_window *hwc_window = NULL;
1577 OUTPUT_FUNC_ENTRY_ERROR();
1579 _pthread_mutex_lock(&private_display->lock);
1581 if (private_output->caps.capabilities & TDM_OUTPUT_CAPABILITY_HWC)
1582 hwc_window = (tdm_hwc_window *)tdm_hwc_window_create_internal(private_output, 0, error);
1584 /* LCOV_EXCL_START */
1585 TDM_ERR("output(%p) not support HWC", private_output);
1587 *error = TDM_ERROR_BAD_REQUEST;
1588 /* LCOV_EXCL_STOP */
1591 _pthread_mutex_unlock(&private_display->lock);
1596 EXTERN tdm_hwc_window *
1597 tdm_output_hwc_create_video_window(tdm_output *output, tdm_error *error)
1599 tdm_hwc_window *hwc_window = NULL;
1601 OUTPUT_FUNC_ENTRY_ERROR();
1603 _pthread_mutex_lock(&private_display->lock);
1605 if (private_output->caps.capabilities & TDM_OUTPUT_CAPABILITY_HWC)
1606 hwc_window = (tdm_hwc_window *)tdm_hwc_window_create_internal(private_output, 1, error);
1608 /* LCOV_EXCL_START */
1609 TDM_ERR("output(%p) not support HWC", private_output);
1611 *error = TDM_ERROR_BAD_REQUEST;
1612 /* LCOV_EXCL_STOP */
1615 _pthread_mutex_unlock(&private_display->lock);
1621 tdm_output_hwc_destroy_window(tdm_output *output, tdm_hwc_window *hwc_window)
1623 OUTPUT_FUNC_ENTRY();
1625 TDM_RETURN_VAL_IF_FAIL(hwc_window != NULL, TDM_ERROR_INVALID_PARAMETER);
1627 _pthread_mutex_lock(&private_display->lock);
1629 ret = tdm_hwc_window_destroy_internal(hwc_window);
1631 _pthread_mutex_unlock(&private_display->lock);
1637 tdm_output_hwc_validate(tdm_output *output, tdm_hwc_window **composited_wnds,
1638 uint32_t num_wnds, uint32_t *num_types)
1640 tdm_private_module *private_module;
1641 tdm_func_output *func_output = NULL;
1642 tdm_private_hwc_window **composited_wnds_frontend = NULL;
1643 tdm_hwc_window **composited_wnds_backend = NULL;
1646 OUTPUT_FUNC_ENTRY();
1648 TDM_RETURN_VAL_IF_FAIL(num_types != NULL, TDM_ERROR_INVALID_PARAMETER);
1650 _pthread_mutex_lock(&private_display->lock);
1652 if (!(private_output->caps.capabilities & TDM_OUTPUT_CAPABILITY_HWC)) {
1653 TDM_ERR("output(%p) not support HWC", private_output);
1654 _pthread_mutex_unlock(&private_display->lock);
1655 return TDM_ERROR_BAD_REQUEST;
1658 private_module = private_output->private_module;
1659 func_output = &private_module->func_output;
1661 if (!func_output->output_hwc_validate) {
1662 /* LCOV_EXCL_START */
1663 _pthread_mutex_unlock(&private_display->lock);
1664 TDM_WRN("not implemented!!");
1665 return TDM_ERROR_NOT_IMPLEMENTED;
1666 /* LCOV_EXCL_STOP */
1669 if (num_wnds == 0) {
1670 ret = func_output->output_hwc_validate(private_output->output_backend, NULL, 0, num_types);
1672 _pthread_mutex_unlock(&private_display->lock);
1677 composited_wnds_backend = calloc(num_wnds, sizeof(tdm_hwc_window *));
1678 if (!composited_wnds_backend) {
1679 /* LCOV_EXCL_START */
1680 _pthread_mutex_unlock(&private_display->lock);
1681 return TDM_ERROR_OUT_OF_MEMORY;
1682 /* LCOV_EXCL_STOP */
1685 composited_wnds_frontend = (tdm_private_hwc_window **)composited_wnds;
1687 for (i = 0; i < num_wnds; i++)
1688 composited_wnds_backend[i] = composited_wnds_frontend[i]->hwc_window_backend;
1690 ret = func_output->output_hwc_validate(private_output->output_backend, composited_wnds_backend, num_wnds, num_types);
1692 free(composited_wnds_backend);
1694 _pthread_mutex_unlock(&private_display->lock);
1700 tdm_output_hwc_set_need_validate_handler(tdm_output *output,
1701 tdm_output_need_validate_handler hndl)
1703 OUTPUT_FUNC_ENTRY();
1705 TDM_RETURN_VAL_IF_FAIL(hndl != NULL, TDM_ERROR_INVALID_PARAMETER);
1707 _pthread_mutex_lock(&private_display->lock);
1709 if (!(private_output->caps.capabilities & TDM_OUTPUT_CAPABILITY_HWC)) {
1710 TDM_ERR("output(%p) not support HWC", private_output);
1711 _pthread_mutex_unlock(&private_display->lock);
1712 return TDM_ERROR_BAD_REQUEST;
1715 /* there's no reason to allow this */
1716 if (private_output->need_validate.hndl) {
1718 _pthread_mutex_unlock(&private_display->lock);
1719 return TDM_ERROR_OPERATION_FAILED;
1722 private_output->need_validate.hndl = hndl;
1724 _pthread_mutex_unlock(&private_display->lock);
1730 tdm_output_hwc_get_changed_composition_types(tdm_output *output,
1731 uint32_t *num_elements,
1732 tdm_hwc_window **hwc_window,
1733 tdm_hwc_window_composition *composition_types)
1735 tdm_private_module *private_module;
1736 tdm_func_output *func_output = NULL;
1737 tdm_private_hwc_window * private_hwc_window = NULL;
1740 OUTPUT_FUNC_ENTRY();
1742 TDM_RETURN_VAL_IF_FAIL(num_elements != NULL, TDM_ERROR_INVALID_PARAMETER);
1744 _pthread_mutex_lock(&private_display->lock);
1746 if (!(private_output->caps.capabilities & TDM_OUTPUT_CAPABILITY_HWC)) {
1747 TDM_ERR("output(%p) not support HWC", private_output);
1748 _pthread_mutex_unlock(&private_display->lock);
1749 return TDM_ERROR_BAD_REQUEST;
1752 private_module = private_output->private_module;
1753 func_output = &private_module->func_output;
1755 if (!func_output->output_hwc_get_changed_composition_types) {
1756 /* LCOV_EXCL_START */
1757 _pthread_mutex_unlock(&private_display->lock);
1758 TDM_WRN("not implemented!!");
1759 return TDM_ERROR_NOT_IMPLEMENTED;
1760 /* LCOV_EXCL_STOP */
1763 ret = func_output->output_hwc_get_changed_composition_types(private_output->output_backend,
1764 num_elements, hwc_window, composition_types);
1765 if (ret != TDM_ERROR_NONE) {
1766 /* LCOV_EXCL_START */
1767 _pthread_mutex_unlock(&private_display->lock);
1769 /* LCOV_EXCL_STOP */
1772 if (hwc_window == NULL || composition_types == NULL) {
1773 _pthread_mutex_unlock(&private_display->lock);
1774 return TDM_ERROR_NONE;
1777 for (i = 0; i < *num_elements; i++) {
1779 private_hwc_window = _tdm_output_find_private_hwc_window(private_output, hwc_window[i]);
1781 if (private_hwc_window == NULL) {
1782 /* LCOV_EXCL_START */
1783 TDM_ERR("failed! This should never happen!");
1784 func_output->output_hwc_destroy_window(private_output->output_backend, hwc_window[i]);
1786 _pthread_mutex_unlock(&private_display->lock);
1787 return TDM_ERROR_OPERATION_FAILED;
1788 /* LCOV_EXCL_STOP */
1791 hwc_window[i] = (tdm_hwc_window*)private_hwc_window;
1794 _pthread_mutex_unlock(&private_display->lock);
1800 tdm_output_hwc_accept_changes(tdm_output *output)
1802 tdm_private_module *private_module;
1803 tdm_func_output *func_output = NULL;
1805 OUTPUT_FUNC_ENTRY();
1807 _pthread_mutex_lock(&private_display->lock);
1809 if (!(private_output->caps.capabilities & TDM_OUTPUT_CAPABILITY_HWC)) {
1810 TDM_ERR("output(%p) not support HWC", private_output);
1811 _pthread_mutex_unlock(&private_display->lock);
1812 return TDM_ERROR_BAD_REQUEST;
1815 private_module = private_output->private_module;
1816 func_output = &private_module->func_output;
1818 if (!func_output->output_hwc_validate) {
1819 /* LCOV_EXCL_START */
1820 _pthread_mutex_unlock(&private_display->lock);
1821 TDM_WRN("not implemented!!");
1822 return TDM_ERROR_NOT_IMPLEMENTED;
1823 /* LCOV_EXCL_STOP */
1826 ret = func_output->output_hwc_accept_changes(private_output->output_backend);
1828 _pthread_mutex_unlock(&private_display->lock);
1834 tdm_output_hwc_get_target_buffer_queue(tdm_output *output, tdm_error *error)
1836 tdm_private_module *private_module;
1837 tdm_func_output *func_output = NULL;
1838 tbm_surface_queue_h queue = NULL;
1840 OUTPUT_FUNC_ENTRY_ERROR();
1842 _pthread_mutex_lock(&private_display->lock);
1844 if (!(private_output->caps.capabilities & TDM_OUTPUT_CAPABILITY_HWC)) {
1845 TDM_ERR("output(%p) not support HWC", private_output);
1847 *error = TDM_ERROR_BAD_REQUEST;
1848 _pthread_mutex_unlock(&private_display->lock);
1852 private_module = private_output->private_module;
1853 func_output = &private_module->func_output;
1855 if (!func_output->output_hwc_get_target_buffer_queue) {
1856 /* LCOV_EXCL_START */
1857 _pthread_mutex_unlock(&private_display->lock);
1858 TDM_WRN("not implemented!!");
1860 /* LCOV_EXCL_STOP */
1863 queue = func_output->output_hwc_get_target_buffer_queue(private_output->output_backend, error);
1865 _pthread_mutex_unlock(&private_display->lock);
1871 tdm_output_hwc_set_client_target_buffer(tdm_output *output, tbm_surface_h target_buffer, tdm_hwc_region damage)
1873 tdm_private_module *private_module;
1874 tdm_func_output *func_output = NULL;
1876 OUTPUT_FUNC_ENTRY();
1878 _pthread_mutex_lock(&private_display->lock);
1880 if (!(private_output->caps.capabilities & TDM_OUTPUT_CAPABILITY_HWC)) {
1881 TDM_ERR("output(%p) not support HWC", private_output);
1882 _pthread_mutex_unlock(&private_display->lock);
1883 return TDM_ERROR_BAD_REQUEST;
1886 if (tdm_debug_dump & TDM_DUMP_FLAG_WINDOW) {
1887 /* LCOV_EXCL_START */
1888 char str[TDM_PATH_LEN];
1890 snprintf(str, TDM_PATH_LEN, "target_window_%d_%03d",
1891 private_output->index, i++);
1892 tdm_helper_dump_buffer_str(target_buffer, tdm_debug_dump_dir, str);
1893 /* LCOV_EXCL_STOP */
1896 private_module = private_output->private_module;
1897 func_output = &private_module->func_output;
1899 if (!func_output->output_hwc_set_client_target_buffer) {
1900 /* LCOV_EXCL_START */
1901 _pthread_mutex_unlock(&private_display->lock);
1902 TDM_WRN("not implemented!!");
1903 return TDM_ERROR_NOT_IMPLEMENTED;
1904 /* LCOV_EXCL_STOP */
1907 ret = func_output->output_hwc_set_client_target_buffer(private_output->output_backend, target_buffer, damage);
1909 _pthread_mutex_unlock(&private_display->lock);
1915 tdm_output_hwc_unset_client_target_buffer(tdm_output *output)
1917 tdm_private_module *private_module;
1918 tdm_func_output *func_output = NULL;
1920 OUTPUT_FUNC_ENTRY();
1922 _pthread_mutex_lock(&private_display->lock);
1924 if (!(private_output->caps.capabilities & TDM_OUTPUT_CAPABILITY_HWC)) {
1925 TDM_ERR("output(%p) not support HWC", private_output);
1926 _pthread_mutex_unlock(&private_display->lock);
1927 return TDM_ERROR_BAD_REQUEST;
1930 private_module = private_output->private_module;
1931 func_output = &private_module->func_output;
1933 if (!func_output->output_hwc_unset_client_target_buffer) {
1934 /* LCOV_EXCL_START */
1935 _pthread_mutex_unlock(&private_display->lock);
1936 TDM_ERR("not implemented!!");
1937 return TDM_ERROR_NOT_IMPLEMENTED;
1938 /* LCOV_EXCL_STOP */
1941 ret = func_output->output_hwc_unset_client_target_buffer(private_output->output_backend);
1943 _pthread_mutex_unlock(&private_display->lock);
1949 _tdm_output_hwc_layer_commit_handler(tdm_layer *layer, unsigned int sequence,
1950 unsigned int tv_sec, unsigned int tv_usec,
1953 tdm_private_output_hwc_target_buffer_commit_handler *output_hwc_target_buffer_commit_handler = (tdm_private_output_hwc_target_buffer_commit_handler *)user_data;
1954 tdm_output_hwc_target_buffer_commit_handler func = output_hwc_target_buffer_commit_handler->func;
1955 tdm_output *output = (tdm_output *)output_hwc_target_buffer_commit_handler->private_output;
1956 void *data = output_hwc_target_buffer_commit_handler->user_data;
1958 func(output, sequence, tv_sec, tv_usec, data);
1960 free(output_hwc_target_buffer_commit_handler);
1964 tdm_output_hwc_commit_client_target_buffer(tdm_output *output, tdm_output_hwc_target_buffer_commit_handler func, void *user_data)
1966 tdm_private_module *private_module;
1967 tdm_func_output *func_output;
1968 tdm_private_output_hwc_target_buffer_commit_handler *output_hwc_target_buffer_commit_handler;
1969 tdm_layer *layer = NULL;
1970 tdm_private_layer *private_layer;
1971 const tdm_output_mode *mode;
1972 tbm_surface_h buffer;
1974 OUTPUT_FUNC_ENTRY();
1976 _pthread_mutex_lock(&private_display->lock);
1978 if (!(private_output->caps.capabilities & TDM_OUTPUT_CAPABILITY_HWC)) {
1979 TDM_ERR("output(%p) not support HWC", private_output);
1980 _pthread_mutex_unlock(&private_display->lock);
1981 return TDM_ERROR_BAD_REQUEST;
1984 private_module = private_output->private_module;
1985 func_output = &private_module->func_output;
1987 if (!func_output->output_hwc_get_client_target_buffer_layer) {
1988 /* LCOV_EXCL_START */
1989 _pthread_mutex_unlock(&private_display->lock);
1990 TDM_ERR("not implemented!!");
1991 return TDM_ERROR_NOT_IMPLEMENTED;
1992 /* LCOV_EXCL_STOP */
1995 layer = func_output->output_hwc_get_client_target_buffer_layer(private_output->output_backend,
1998 /* LCOV_EXCL_START */
1999 _pthread_mutex_unlock(&private_display->lock);
2000 TDM_ERR("no assigned layer!!");
2001 return TDM_ERROR_INVALID_PARAMETER;
2002 /* LCOV_EXCL_STOP */
2005 private_layer = (tdm_private_layer*)layer;
2007 if (!func_output->output_hwc_get_client_target_buffer) {
2008 /* LCOV_EXCL_START */
2009 _pthread_mutex_unlock(&private_display->lock);
2010 TDM_ERR("not implemented!!");
2011 return TDM_ERROR_NOT_IMPLEMENTED;
2012 /* LCOV_EXCL_STOP */
2015 buffer = func_output->output_hwc_get_client_target_buffer(private_output->output_backend,
2018 ret = tdm_layer_set_buffer_internal(private_layer, buffer);
2020 ret = tdm_layer_unset_buffer_internal(private_layer);
2021 if (ret != TDM_ERROR_NONE) {
2022 /* LCOV_EXCL_START */
2023 TDM_ERR("failed: layer set info(window)");
2024 _pthread_mutex_unlock(&private_display->lock);
2025 /* LCOV_EXCL_STOP */
2029 if (private_output->need_set_target_info) {
2030 mode = private_output->current_mode;
2031 private_output->target_buffer_info.src_config.size.h = mode->hdisplay;
2032 private_output->target_buffer_info.src_config.size.v = mode->vdisplay;
2033 private_output->target_buffer_info.src_config.pos.x = 0;
2034 private_output->target_buffer_info.src_config.pos.y = 0;
2035 private_output->target_buffer_info.src_config.pos.w = mode->hdisplay;
2036 private_output->target_buffer_info.src_config.pos.h = mode->vdisplay;
2037 private_output->target_buffer_info.dst_pos.x = 0;
2038 private_output->target_buffer_info.dst_pos.y = 0;
2039 private_output->target_buffer_info.dst_pos.w = mode->hdisplay;
2040 private_output->target_buffer_info.dst_pos.h = mode->vdisplay;
2041 private_output->target_buffer_info.transform = TDM_TRANSFORM_NORMAL;
2043 ret = tdm_layer_set_info_internal(private_layer, &private_output->target_buffer_info);
2044 if (ret != TDM_ERROR_NONE) {
2045 /* LCOV_EXCL_START */
2046 TDM_ERR("failed: layer set info(window)");
2047 _pthread_mutex_unlock(&private_display->lock);
2048 /* LCOV_EXCL_STOP */
2052 private_output->need_set_target_info = 0;
2055 output_hwc_target_buffer_commit_handler = calloc(1, sizeof(tdm_private_output_hwc_target_buffer_commit_handler));
2056 if (!output_hwc_target_buffer_commit_handler) {
2057 /* LCOV_EXCL_START */
2058 TDM_ERR("failed: alloc memory");
2059 _pthread_mutex_unlock(&private_display->lock);
2060 return TDM_ERROR_OUT_OF_MEMORY;
2061 /* LCOV_EXCL_STOP */
2064 output_hwc_target_buffer_commit_handler->private_output = private_output;
2065 output_hwc_target_buffer_commit_handler->func = func;
2066 output_hwc_target_buffer_commit_handler->user_data = user_data;
2068 ret = tdm_layer_commit_internal(private_layer, _tdm_output_hwc_layer_commit_handler, output_hwc_target_buffer_commit_handler);
2069 if (ret != TDM_ERROR_NONE) {
2070 /* LCOV_EXCL_START */
2071 TDM_ERR("failed: commit layer(target buffer)");
2072 free(output_hwc_target_buffer_commit_handler);
2073 _pthread_mutex_unlock(&private_display->lock);
2074 /* LCOV_EXCL_STOP */
2078 _pthread_mutex_unlock(&private_display->lock);
2084 tdm_output_hwc_get_video_supported_formats(tdm_output *output, const tbm_format **formats,
2087 tdm_private_module *private_module;
2088 tdm_func_output *func_output;
2089 OUTPUT_FUNC_ENTRY();
2091 TDM_RETURN_VAL_IF_FAIL(formats != NULL, TDM_ERROR_INVALID_PARAMETER);
2092 TDM_RETURN_VAL_IF_FAIL(count != NULL, TDM_ERROR_INVALID_PARAMETER);
2094 _pthread_mutex_lock(&private_display->lock);
2096 private_module = private_output->private_module;
2097 func_output = &private_module->func_output;
2099 if (!func_output->output_hwc_get_video_supported_formats) {
2100 /* LCOV_EXCL_START */
2101 _pthread_mutex_unlock(&private_display->lock);
2102 TDM_WRN("not implemented!!");
2103 return TDM_ERROR_NOT_IMPLEMENTED;
2104 /* LCOV_EXCL_STOP */
2107 ret = func_output->output_hwc_get_video_supported_formats(
2108 private_output->output_backend, formats, count);
2110 _pthread_mutex_unlock(&private_display->lock);
2116 _is_hwc_output_still_existed(tdm_private_output *private_output)
2118 tdm_private_module *private_module = private_output->private_module;
2119 tdm_private_output *o = NULL;
2121 LIST_FOR_EACH_ENTRY(o, &private_module->output_list, link) {
2122 if (!(o->caps.capabilities & TDM_OUTPUT_CAPABILITY_HWC))
2125 if (o == private_output)
2135 /* gets called on behalf of the ecore-main-loop thread */
2137 tdm_output_need_validate_handler_thread(tdm_private_display *private_display, void *object, tdm_thread_cb_base *cb_base, void *user_data)
2139 tdm_private_output *private_output = object;
2141 TDM_RETURN_IF_FAIL(private_output != NULL);
2143 _pthread_mutex_lock(&private_display->lock);
2145 /* as we get 'private_output' within an event, an output this 'private_output'
2146 * points to can be destroyed already */
2147 if (!_is_hwc_output_still_existed(private_output)) {
2148 _pthread_mutex_unlock(&private_display->lock);
2152 _pthread_mutex_unlock(&private_display->lock);
2154 TDM_INFO("tdm-backend asks for revalidation for the output:%p.", private_output);
2156 if (private_output->need_validate.hndl)
2157 private_output->need_validate.hndl((tdm_output*)private_output);
2160 /* gets called on behalf of the tdm-thread */
2162 _need_validate_handler(int fd, tdm_event_loop_mask mask, void *user_data)
2164 tdm_thread_cb_need_validate ev;
2165 tdm_private_output *private_output;
2169 private_output = (tdm_private_output *)user_data;
2171 if (read(private_output->need_validate.event_fd, &value, sizeof(value)) < 0) {
2172 TDM_ERR("error while trying to read from a need_validate.event_fd fd.");
2173 return TDM_ERROR_OPERATION_FAILED;
2176 memset(&ev, 0, sizeof ev);
2177 ev.base.type = TDM_THREAD_CB_NEED_VALIDATE;
2178 ev.base.length = sizeof ev;
2179 ev.base.object_stamp = private_output->stamp;
2180 ev.base.data = NULL;
2183 ret = tdm_thread_cb_call(private_output, &ev.base, 1);
2184 TDM_WARNING_IF_FAIL(ret == TDM_ERROR_NONE);
2186 TDM_INFO("tdm-thread: get a 'need to revalidate' event for the ouptut:%p.", private_output);
2188 /* who cares about this? */
2189 return TDM_ERROR_NONE;
2193 tdm_output_need_validate_event_init(tdm_output *output)
2197 OUTPUT_FUNC_ENTRY();
2199 TDM_RETURN_VAL_IF_FAIL(TDM_MUTEX_IS_LOCKED(), TDM_ERROR_OPERATION_FAILED);
2201 if (!(private_output->caps.capabilities & TDM_OUTPUT_CAPABILITY_HWC)) {
2202 TDM_ERR("output(%p) not support HWC", private_output);
2203 return TDM_ERROR_BAD_REQUEST;
2206 /* build in eventfd fds into event_loop listened & handled by the tdm-thread */
2208 TDM_WARNING_IF_FAIL(fd >= 0);
2210 private_output->need_validate.event_source = tdm_event_loop_add_fd_handler(private_display,
2211 fd, TDM_EVENT_LOOP_READABLE, _need_validate_handler, private_output, &ret);
2212 TDM_WARNING_IF_FAIL(ret == TDM_ERROR_NONE);
2214 private_output->need_validate.event_fd = fd;
2216 TDM_INFO("register an output:%p for the revalidation, event_fd:%d.", private_output, fd);
2222 tdm_output_choose_commit_per_vblank_mode(tdm_private_output *private_output, int mode)
2224 if (!private_output)
2225 return TDM_ERROR_INVALID_PARAMETER;
2227 if (mode < 0 || mode > 2)
2228 return TDM_ERROR_INVALID_PARAMETER;
2230 private_output->commit_per_vblank = mode;
2232 if (private_output->commit_per_vblank == 0)
2233 TDM_INFO("commit per vblank: disable");
2234 else if (private_output->commit_per_vblank == 1)
2235 TDM_INFO("commit per vblank: enable (1 layer)");
2236 else if (private_output->commit_per_vblank == 2)
2237 TDM_INFO("commit per vblank: enable (previous commit)");
2239 return TDM_ERROR_NONE;