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);
131 tdm_output_init(tdm_private_display *private_display)
133 tdm_thread_cb_set_find_func(TDM_THREAD_CB_OUTPUT_DESTROY, tdm_display_find_output_stamp);
134 tdm_thread_cb_set_find_func(TDM_THREAD_CB_OUTPUT_COMMIT, tdm_display_find_output_stamp);
135 tdm_thread_cb_set_find_func(TDM_THREAD_CB_OUTPUT_VBLANK, tdm_display_find_output_stamp);
136 tdm_thread_cb_set_find_func(TDM_THREAD_CB_OUTPUT_STATUS, tdm_display_find_output_stamp);
137 tdm_thread_cb_set_find_func(TDM_THREAD_CB_OUTPUT_DPMS, tdm_display_find_output_stamp);
138 tdm_thread_cb_set_find_func(TDM_THREAD_CB_VOUTPUT_COMMIT, tdm_display_find_private_voutput);
140 return TDM_ERROR_NONE;
144 tdm_output_call_thread_cb_destroy(tdm_private_output *private_output)
146 tdm_thread_cb_output_destroy output_destroy;
149 memset(&output_destroy, 0, sizeof output_destroy);
150 output_destroy.base.type = TDM_THREAD_CB_OUTPUT_DESTROY;
151 output_destroy.base.length = sizeof output_destroy;
152 output_destroy.base.object_stamp = private_output->stamp;
153 output_destroy.base.data = NULL;
154 output_destroy.base.sync = 1;
156 ret = tdm_thread_cb_call(private_output, &output_destroy.base, 1);
157 TDM_WARNING_IF_FAIL(ret == TDM_ERROR_NONE);
159 return TDM_ERROR_NONE;
163 tdm_output_thread_cb_destroy(tdm_private_display *private_display, void *object, tdm_thread_cb_base *cb_base, void *user_data)
165 tdm_private_output *private_output = object;
166 tdm_private_output_destroy_handler *destroy_handler = user_data;
168 TDM_RETURN_IF_FAIL(TDM_MUTEX_IS_LOCKED());
170 assert(destroy_handler->owner_tid == syscall(SYS_gettid));
172 _pthread_mutex_unlock(&private_display->lock);
173 destroy_handler->func(private_output, destroy_handler->user_data);
174 _pthread_mutex_lock(&private_display->lock);
178 tdm_output_add_destroy_handler(tdm_output *output,
179 tdm_output_destroy_handler func,
182 tdm_private_output_destroy_handler *destroy_handler = NULL;
185 TDM_RETURN_VAL_IF_FAIL(func != NULL, TDM_ERROR_INVALID_PARAMETER);
187 _pthread_mutex_lock(&private_display->lock);
189 LIST_FOR_EACH_ENTRY(destroy_handler, &private_output->destroy_handler_list, link) {
190 if (destroy_handler->func == func && destroy_handler->user_data == user_data) {
191 TDM_ERR("can't add twice");
192 _pthread_mutex_unlock(&private_display->lock);
193 return TDM_ERROR_BAD_REQUEST;
197 destroy_handler = calloc(1, sizeof(tdm_private_output_destroy_handler));
198 if (!destroy_handler) {
199 TDM_ERR("failed: alloc memory");
200 _pthread_mutex_unlock(&private_display->lock);
201 return TDM_ERROR_OUT_OF_MEMORY;
204 ret = tdm_thread_cb_add(private_output, TDM_THREAD_CB_OUTPUT_DESTROY, NULL, tdm_output_thread_cb_destroy, destroy_handler);
205 if (ret != TDM_ERROR_NONE) {
206 TDM_ERR("tdm_thread_cb_add failed");
207 free(destroy_handler);
208 _pthread_mutex_unlock(&private_display->lock);
209 return TDM_ERROR_OPERATION_FAILED;
212 destroy_handler->private_output = private_output;
213 destroy_handler->func = func;
214 destroy_handler->user_data = user_data;
215 destroy_handler->owner_tid = syscall(SYS_gettid);
217 LIST_ADDTAIL(&destroy_handler->link, &private_output->destroy_handler_list);
219 _pthread_mutex_unlock(&private_display->lock);
225 tdm_output_remove_destroy_handler(tdm_output *output,
226 tdm_output_destroy_handler func,
229 tdm_private_display *private_display;
230 tdm_private_output *private_output;
231 tdm_private_output_destroy_handler *destroy_handler = NULL, *hh = NULL;
233 TDM_RETURN_IF_FAIL(output != NULL);
234 TDM_RETURN_IF_FAIL(func != NULL);
236 private_output = (tdm_private_output*)output;
237 private_display = private_output->private_display;
239 _pthread_mutex_lock(&private_display->lock);
241 LIST_FOR_EACH_ENTRY_SAFE(destroy_handler, hh, &private_output->destroy_handler_list, link) {
242 if (destroy_handler->func != func || destroy_handler->user_data != user_data)
245 tdm_thread_cb_remove(private_output, TDM_THREAD_CB_OUTPUT_DESTROY, NULL, tdm_output_thread_cb_destroy, destroy_handler);
247 LIST_DEL(&destroy_handler->link);
248 free(destroy_handler);
250 _pthread_mutex_unlock(&private_display->lock);
255 _pthread_mutex_unlock(&private_display->lock);
259 tdm_output_get_backend_module(tdm_output *output, tdm_error *error)
261 tdm_private_module *private_module;
263 OUTPUT_FUNC_ENTRY_ERROR();
265 _pthread_mutex_lock(&private_display->lock);
267 private_module = private_output->private_module;
270 *error = TDM_ERROR_NONE;
272 _pthread_mutex_unlock(&private_display->lock);
274 return private_module;
278 tdm_output_get_model_info(tdm_output *output, const char **maker,
279 const char **model, const char **name)
283 _pthread_mutex_lock(&private_display->lock);
286 *maker = private_output->caps.maker;
288 *model = private_output->caps.model;
290 *name = private_output->caps.name;
292 _pthread_mutex_unlock(&private_display->lock);
298 tdm_output_get_capabilities(tdm_output *output, tdm_output_capability *capabilities)
302 TDM_RETURN_VAL_IF_FAIL(capabilities != NULL, TDM_ERROR_INVALID_PARAMETER);
304 _pthread_mutex_lock(&private_display->lock);
306 *capabilities = private_output->caps.capabilities;
308 _pthread_mutex_unlock(&private_display->lock);
314 tdm_output_get_conn_status(tdm_output *output, tdm_output_conn_status *status)
318 TDM_RETURN_VAL_IF_FAIL(status != NULL, TDM_ERROR_INVALID_PARAMETER);
320 _pthread_mutex_lock(&private_display->lock);
322 *status = private_output->caps.status;
324 _pthread_mutex_unlock(&private_display->lock);
330 tdm_output_thread_cb_change(tdm_private_display *private_display, void *object, tdm_thread_cb_base *cb_base, void *user_data)
332 tdm_private_output *private_output = object;
333 tdm_private_output_change_handler *change_handler = user_data;
334 tdm_output_change_type type = TDM_OUTPUT_CHANGE_CONNECTION;
335 tdm_value value = {.u32 = 0 };
337 TDM_RETURN_IF_FAIL(TDM_MUTEX_IS_LOCKED());
339 assert(change_handler->owner_tid == syscall(SYS_gettid));
341 if (cb_base->type == TDM_THREAD_CB_OUTPUT_STATUS) {
342 tdm_thread_cb_output_status *output_status = (tdm_thread_cb_output_status *)cb_base;
343 type = TDM_OUTPUT_CHANGE_CONNECTION;
344 value.u32 = output_status->status;
345 } else if (cb_base->type == TDM_THREAD_CB_OUTPUT_DPMS) {
346 tdm_thread_cb_output_dpms *output_dpms = (tdm_thread_cb_output_dpms *)cb_base;
347 type = TDM_OUTPUT_CHANGE_DPMS;
348 value.u32 = output_dpms->dpms;
350 TDM_NEVER_GET_HERE();
354 _pthread_mutex_unlock(&private_display->lock);
355 change_handler->func(private_output, type, value, change_handler->user_data);
356 _pthread_mutex_lock(&private_display->lock);
361 _tdm_output_call_thread_cb_status(tdm_private_output *private_output, tdm_output_conn_status status)
363 tdm_thread_cb_output_status output_status;
364 pid_t caller_tid = syscall(SYS_gettid);
367 memset(&output_status, 0, sizeof output_status);
368 output_status.base.type = TDM_THREAD_CB_OUTPUT_STATUS;
369 output_status.base.length = sizeof output_status;
370 output_status.base.object_stamp = private_output->stamp;
371 output_status.base.data = NULL;
372 if (tdm_thread_in_display_thread(caller_tid))
373 output_status.base.sync = 0;
375 output_status.base.sync = 1;
376 output_status.status = status;
378 ret = tdm_thread_cb_call(private_output, &output_status.base, 1);
379 TDM_WARNING_IF_FAIL(ret == TDM_ERROR_NONE);
381 return TDM_ERROR_NONE;
385 _tdm_output_call_thread_cb_dpms(tdm_private_output *private_output, tdm_output_dpms dpms)
387 tdm_thread_cb_output_dpms output_dpms;
390 memset(&output_dpms, 0, sizeof output_dpms);
391 output_dpms.base.type = TDM_THREAD_CB_OUTPUT_DPMS;
392 output_dpms.base.length = sizeof output_dpms;
393 output_dpms.base.object_stamp = private_output->stamp;
394 output_dpms.base.data = NULL;
395 output_dpms.base.sync = 0;
396 output_dpms.dpms = dpms;
398 ret = tdm_thread_cb_call(private_output, &output_dpms.base, 1);
399 TDM_WARNING_IF_FAIL(ret == TDM_ERROR_NONE);
401 return TDM_ERROR_NONE;
405 tdm_output_cb_status(tdm_output *output_backend, tdm_output_conn_status status, void *user_data)
407 tdm_private_output *private_output = user_data;
410 TDM_RETURN_IF_FAIL(private_output);
412 TDM_INFO("output(%d) %s", private_output->pipe, tdm_status_str(status));
414 if ((private_output->caps.status == TDM_OUTPUT_CONN_STATUS_DISCONNECTED && status != TDM_OUTPUT_CONN_STATUS_DISCONNECTED) ||
415 (private_output->caps.status != TDM_OUTPUT_CONN_STATUS_DISCONNECTED && status == TDM_OUTPUT_CONN_STATUS_DISCONNECTED)) {
416 ret = tdm_display_update_output(private_output->private_module, output_backend);
417 TDM_RETURN_IF_FAIL(ret == TDM_ERROR_NONE);
419 private_output->caps.status = status;
422 ret = _tdm_output_call_thread_cb_status(private_output, status);
423 TDM_WARNING_IF_FAIL(ret == TDM_ERROR_NONE);
427 tdm_output_cb_dpms(tdm_output *output_backend, tdm_output_dpms dpms, void *user_data)
429 tdm_private_output *private_output = user_data;
432 TDM_INFO("output(%d) %s", private_output->pipe, tdm_status_str(dpms));
434 private_output->current_dpms_value = dpms;
435 private_output->waiting_dpms_change = 0;
436 TDM_INFO("output(%d) dpms async '%s' done", private_output->pipe, tdm_dpms_str(dpms));
438 ret = _tdm_output_call_thread_cb_dpms(private_output, dpms);
439 TDM_WARNING_IF_FAIL(ret == TDM_ERROR_NONE);
443 tdm_output_add_change_handler(tdm_output *output,
444 tdm_output_change_handler func,
447 tdm_private_output_change_handler *change_handler = NULL;
450 TDM_RETURN_VAL_IF_FAIL(func != NULL, TDM_ERROR_INVALID_PARAMETER);
452 _pthread_mutex_lock(&private_display->lock);
454 LIST_FOR_EACH_ENTRY(change_handler, &private_output->change_handler_list, link) {
455 if (change_handler->func == func && change_handler->user_data == user_data) {
456 TDM_ERR("can't add twice");
457 _pthread_mutex_unlock(&private_display->lock);
458 return TDM_ERROR_BAD_REQUEST;
462 change_handler = calloc(1, sizeof(tdm_private_output_change_handler));
463 if (!change_handler) {
464 /* LCOV_EXCL_START */
465 TDM_ERR("failed: alloc memory");
466 _pthread_mutex_unlock(&private_display->lock);
467 return TDM_ERROR_OUT_OF_MEMORY;
471 ret = tdm_thread_cb_add(private_output, TDM_THREAD_CB_OUTPUT_DPMS, NULL, tdm_output_thread_cb_change, change_handler);
472 if (ret != TDM_ERROR_NONE) {
473 /* LCOV_EXCL_START */
474 TDM_ERR("tdm_thread_cb_add failed");
475 free(change_handler);
476 _pthread_mutex_unlock(&private_display->lock);
477 return TDM_ERROR_OPERATION_FAILED;
481 ret = tdm_thread_cb_add(private_output, TDM_THREAD_CB_OUTPUT_STATUS, NULL, tdm_output_thread_cb_change, change_handler);
482 if (ret != TDM_ERROR_NONE) {
483 /* LCOV_EXCL_START */
484 TDM_ERR("tdm_thread_cb_add failed");
485 tdm_thread_cb_remove(private_output, TDM_THREAD_CB_OUTPUT_DPMS, NULL, tdm_output_thread_cb_change, change_handler);
486 free(change_handler);
487 _pthread_mutex_unlock(&private_display->lock);
488 return TDM_ERROR_OPERATION_FAILED;
492 change_handler->private_output = private_output;
493 change_handler->func = func;
494 change_handler->user_data = user_data;
495 change_handler->owner_tid = syscall(SYS_gettid);
497 LIST_ADDTAIL(&change_handler->link, &private_output->change_handler_list);
499 _pthread_mutex_unlock(&private_display->lock);
505 tdm_output_add_mode_change_request_handler(tdm_output *output,
506 tdm_output_mode_change_request_handler func,
509 tdm_private_display *private_display;
510 tdm_private_output *private_output;
511 tdm_private_output_mode_change_handler *mode_change_handler = NULL;
513 TDM_RETURN_VAL_IF_FAIL(output != NULL, TDM_ERROR_INVALID_PARAMETER);
514 TDM_RETURN_VAL_IF_FAIL(func != NULL, TDM_ERROR_INVALID_PARAMETER);
516 private_output = (tdm_private_output*)output;
517 private_display = private_output->private_display;
519 _pthread_mutex_lock(&private_display->lock);
521 LIST_FOR_EACH_ENTRY(mode_change_handler, &private_output->mode_change_request_handler_list, link) {
522 if (mode_change_handler->func == func && mode_change_handler->user_data == user_data) {
523 TDM_ERR("can't add twice");
524 _pthread_mutex_unlock(&private_display->lock);
525 return TDM_ERROR_BAD_REQUEST;
529 mode_change_handler = calloc(1, sizeof(tdm_private_output_change_handler));
530 if (!mode_change_handler) {
531 /* LCOV_EXCL_START */
532 TDM_ERR("failed: alloc memory");
533 _pthread_mutex_unlock(&private_display->lock);
534 return TDM_ERROR_OUT_OF_MEMORY;
538 mode_change_handler->private_output = private_output;
539 mode_change_handler->func = func;
540 mode_change_handler->user_data = user_data;
542 LIST_ADDTAIL(&mode_change_handler->link, &private_output->mode_change_request_handler_list);
544 _pthread_mutex_unlock(&private_display->lock);
546 return TDM_ERROR_NONE;
550 tdm_output_remove_mode_change_request_handler(tdm_output *output,
551 tdm_output_mode_change_request_handler func,
554 tdm_private_display *private_display;
555 tdm_private_output *private_output;
556 tdm_private_output_mode_change_handler *mode_change_handler = NULL, *hh = NULL;
558 TDM_RETURN_VAL_IF_FAIL(output != NULL, TDM_ERROR_INVALID_PARAMETER);
559 TDM_RETURN_VAL_IF_FAIL(func != NULL, TDM_ERROR_INVALID_PARAMETER);
561 private_output = (tdm_private_output*)output;
562 private_display = private_output->private_display;
564 _pthread_mutex_lock(&private_display->lock);
566 LIST_FOR_EACH_ENTRY_SAFE(mode_change_handler, hh, &private_output->mode_change_request_handler_list, link) {
567 if (mode_change_handler->func != func || mode_change_handler->user_data != user_data)
570 LIST_DEL(&mode_change_handler->link);
571 free(mode_change_handler);
573 _pthread_mutex_unlock(&private_display->lock);
575 return TDM_ERROR_NONE;
578 _pthread_mutex_unlock(&private_display->lock);
580 return TDM_ERROR_INVALID_PARAMETER;
584 tdm_output_remove_change_handler(tdm_output *output,
585 tdm_output_change_handler func,
588 tdm_private_display *private_display;
589 tdm_private_output *private_output;
590 tdm_private_output_change_handler *change_handler = NULL, *hh = NULL;
592 TDM_RETURN_IF_FAIL(output != NULL);
593 TDM_RETURN_IF_FAIL(func != NULL);
595 private_output = (tdm_private_output*)output;
596 private_display = private_output->private_display;
598 _pthread_mutex_lock(&private_display->lock);
600 LIST_FOR_EACH_ENTRY_SAFE(change_handler, hh, &private_output->change_handler_list, link) {
601 if (change_handler->func != func || change_handler->user_data != user_data)
604 tdm_thread_cb_remove(private_output, TDM_THREAD_CB_OUTPUT_DPMS, NULL, tdm_output_thread_cb_change, change_handler);
605 tdm_thread_cb_remove(private_output, TDM_THREAD_CB_OUTPUT_STATUS, NULL, tdm_output_thread_cb_change, change_handler);
607 LIST_DEL(&change_handler->link);
608 free(change_handler);
610 _pthread_mutex_unlock(&private_display->lock);
615 _pthread_mutex_unlock(&private_display->lock);
619 tdm_output_get_output_type(tdm_output *output, tdm_output_type *type)
623 TDM_RETURN_VAL_IF_FAIL(type != NULL, TDM_ERROR_INVALID_PARAMETER);
625 _pthread_mutex_lock(&private_display->lock);
627 *type = private_output->caps.type;
629 _pthread_mutex_unlock(&private_display->lock);
635 tdm_output_get_layer_count(tdm_output *output, int *count)
637 tdm_private_layer *private_layer = NULL;
641 TDM_RETURN_VAL_IF_FAIL(count != NULL, TDM_ERROR_INVALID_PARAMETER);
643 _pthread_mutex_lock(&private_display->lock);
645 if (private_output->caps.capabilities & TDM_OUTPUT_CAPABILITY_HWC) {
646 TDM_ERR("output(%p) support HWC. Use HWC functions", private_output);
648 _pthread_mutex_unlock(&private_display->lock);
649 return TDM_ERROR_BAD_REQUEST;
653 LIST_FOR_EACH_ENTRY(private_layer, &private_output->layer_list, link)
656 _pthread_mutex_unlock(&private_display->lock);
657 return TDM_ERROR_NONE;
660 _pthread_mutex_unlock(&private_display->lock);
667 tdm_output_get_layer(tdm_output *output, int index, tdm_error *error)
669 tdm_private_layer *private_layer = NULL;
671 OUTPUT_FUNC_ENTRY_ERROR();
673 _pthread_mutex_lock(&private_display->lock);
676 *error = TDM_ERROR_NONE;
678 if (private_output->caps.capabilities & TDM_OUTPUT_CAPABILITY_HWC) {
679 _pthread_mutex_unlock(&private_display->lock);
680 TDM_ERR("output(%p) support HWC. Use HWC functions", private_output);
682 *error = TDM_ERROR_BAD_REQUEST;
686 LIST_FOR_EACH_ENTRY(private_layer, &private_output->layer_list, link) {
687 if (private_layer->index == index) {
688 _pthread_mutex_unlock(&private_display->lock);
689 return private_layer;
693 _pthread_mutex_unlock(&private_display->lock);
699 tdm_output_get_available_properties(tdm_output *output, const tdm_prop **props,
704 TDM_RETURN_VAL_IF_FAIL(props != NULL, TDM_ERROR_INVALID_PARAMETER);
705 TDM_RETURN_VAL_IF_FAIL(count != NULL, TDM_ERROR_INVALID_PARAMETER);
707 _pthread_mutex_lock(&private_display->lock);
709 *props = (const tdm_prop *)private_output->caps.props;
710 *count = private_output->caps.prop_count;
712 _pthread_mutex_unlock(&private_display->lock);
718 tdm_output_get_available_modes(tdm_output *output,
719 const tdm_output_mode **modes, int *count)
723 TDM_RETURN_VAL_IF_FAIL(modes != NULL, TDM_ERROR_INVALID_PARAMETER);
724 TDM_RETURN_VAL_IF_FAIL(count != NULL, TDM_ERROR_INVALID_PARAMETER);
726 _pthread_mutex_lock(&private_display->lock);
728 *modes = (const tdm_output_mode *)private_output->caps.modes;
729 *count = private_output->caps.mode_count;
731 _pthread_mutex_unlock(&private_display->lock);
737 tdm_output_get_available_size(tdm_output *output, int *min_w, int *min_h,
738 int *max_w, int *max_h, int *preferred_align)
742 _pthread_mutex_lock(&private_display->lock);
745 *min_w = TDM_FRONT_VALUE(private_output->caps.min_w);
747 *min_h = TDM_FRONT_VALUE(private_output->caps.min_h);
749 *max_w = TDM_FRONT_VALUE(private_output->caps.max_w);
751 *max_h = TDM_FRONT_VALUE(private_output->caps.max_h);
753 *preferred_align = TDM_FRONT_VALUE(private_output->caps.preferred_align);
755 _pthread_mutex_unlock(&private_display->lock);
761 tdm_output_get_cursor_available_size(tdm_output *output, int *min_w, int *min_h,
762 int *max_w, int *max_h, int *preferred_align)
766 _pthread_mutex_lock(&private_display->lock);
768 if (!tdm_module_check_abi(private_output->private_module, 1, 5)) {
769 _pthread_mutex_unlock(&private_display->lock);
770 return TDM_ERROR_BAD_REQUEST;
774 *min_w = TDM_FRONT_VALUE(private_output->caps.cursor_min_w);
776 *min_h = TDM_FRONT_VALUE(private_output->caps.cursor_min_h);
778 *max_w = TDM_FRONT_VALUE(private_output->caps.cursor_max_w);
780 *max_h = TDM_FRONT_VALUE(private_output->caps.cursor_max_h);
782 *preferred_align = TDM_FRONT_VALUE(private_output->caps.cursor_preferred_align);
784 _pthread_mutex_unlock(&private_display->lock);
790 tdm_output_get_physical_size(tdm_output *output, unsigned int *mmWidth,
791 unsigned int *mmHeight)
795 _pthread_mutex_lock(&private_display->lock);
798 *mmWidth = private_output->caps.mmWidth;
800 *mmHeight = private_output->caps.mmHeight;
802 _pthread_mutex_unlock(&private_display->lock);
808 tdm_output_get_subpixel(tdm_output *output, unsigned int *subpixel)
811 TDM_RETURN_VAL_IF_FAIL(subpixel != NULL, TDM_ERROR_INVALID_PARAMETER);
813 _pthread_mutex_lock(&private_display->lock);
815 *subpixel = private_output->caps.subpixel;
817 _pthread_mutex_unlock(&private_display->lock);
823 tdm_output_get_pipe(tdm_output *output, unsigned int *pipe)
826 TDM_RETURN_VAL_IF_FAIL(pipe != NULL, TDM_ERROR_INVALID_PARAMETER);
828 _pthread_mutex_lock(&private_display->lock);
830 *pipe = private_output->pipe;
832 _pthread_mutex_unlock(&private_display->lock);
838 tdm_output_get_primary_index(tdm_output *output, int *index)
840 tdm_private_layer *private_layer = NULL;
843 TDM_RETURN_VAL_IF_FAIL(index != NULL, TDM_ERROR_INVALID_PARAMETER);
845 _pthread_mutex_lock(&private_display->lock);
847 LIST_FOR_EACH_ENTRY(private_layer, &private_output->layer_list, link) {
848 if (private_layer->caps.capabilities & TDM_LAYER_CAPABILITY_PRIMARY) {
849 *index = private_layer->index;
854 _pthread_mutex_unlock(&private_display->lock);
860 tdm_output_set_property(tdm_output *output, unsigned int id, tdm_value value)
862 tdm_private_module *private_module;
863 tdm_func_output *func_output;
866 _pthread_mutex_lock(&private_display->lock);
868 private_module = private_output->private_module;
869 func_output = &private_module->func_output;
871 if (!func_output->output_set_property) {
872 /* LCOV_EXCL_START */
873 _pthread_mutex_unlock(&private_display->lock);
874 TDM_WRN("not implemented!!");
875 return TDM_ERROR_NOT_IMPLEMENTED;
879 ret = func_output->output_set_property(private_output->output_backend, id,
882 _pthread_mutex_unlock(&private_display->lock);
888 tdm_output_get_property(tdm_output *output, unsigned int id, tdm_value *value)
890 tdm_private_module *private_module;
891 tdm_func_output *func_output;
894 TDM_RETURN_VAL_IF_FAIL(value != NULL, TDM_ERROR_INVALID_PARAMETER);
896 _pthread_mutex_lock(&private_display->lock);
898 private_module = private_output->private_module;
899 func_output = &private_module->func_output;
901 if (!func_output->output_get_property) {
902 /* LCOV_EXCL_START */
903 _pthread_mutex_unlock(&private_display->lock);
904 TDM_WRN("not implemented!!");
905 return TDM_ERROR_NOT_IMPLEMENTED;
909 ret = func_output->output_get_property(private_output->output_backend, id,
912 _pthread_mutex_unlock(&private_display->lock);
918 _tdm_output_thread_cb_vblank(tdm_private_display *private_display, void *object, tdm_thread_cb_base *cb_base, void *user_data)
920 tdm_thread_cb_output_vblank *output_vblank = (tdm_thread_cb_output_vblank *)cb_base;
921 tdm_private_output_vblank_handler *vblank_handler = output_vblank->base.data;
922 tdm_private_output_vblank_handler *v = NULL, *vv = NULL;
923 tdm_private_output *private_output = object;
924 struct list_head clone_list;
926 pid_t tid = syscall(SYS_gettid);
928 TDM_RETURN_IF_FAIL(TDM_MUTEX_IS_LOCKED());
930 assert(vblank_handler->owner_tid == tid);
932 vblank_handler->sent_to_frontend = 0;
934 _tdm_output_vblank_timeout_update(private_output, 0);
936 tdm_thread_cb_remove(private_output, TDM_THREAD_CB_OUTPUT_VBLANK, vblank_handler, _tdm_output_thread_cb_vblank, NULL);
938 interval = vblank_handler->interval;
939 sync = vblank_handler->sync;
941 LIST_INITHEAD(&clone_list);
943 LIST_FOR_EACH_ENTRY_SAFE(v, vv, &private_output->vblank_handler_list, link) {
944 if (v->interval != interval || v->sync != sync || v->owner_tid != tid)
948 LIST_ADDTAIL(&v->link, &clone_list);
951 if (tdm_debug_module & TDM_DEBUG_COMMIT)
952 TDM_INFO("----------------------------------------- output(%d) got vblank", private_output->pipe);
954 _pthread_mutex_unlock(&private_display->lock);
955 LIST_FOR_EACH_ENTRY_SAFE(v, vv, &clone_list, link) {
956 if (tdm_debug_module & TDM_DEBUG_COMMIT)
957 TDM_INFO("handler(%p)", v);
962 v->func(v->private_output,
963 output_vblank->sequence,
964 output_vblank->tv_sec,
965 output_vblank->tv_usec,
970 _pthread_mutex_lock(&private_display->lock);
972 if (tdm_debug_module & TDM_DEBUG_COMMIT)
973 TDM_INFO("-----------------------------------------...");
977 _tdm_output_cb_vblank(tdm_output *output_backend, unsigned int sequence,
978 unsigned int tv_sec, unsigned int tv_usec, void *user_data)
980 tdm_private_output_vblank_handler *vblank_handler = user_data;
981 tdm_thread_cb_output_vblank output_vblank;
984 memset(&output_vblank, 0, sizeof output_vblank);
985 output_vblank.base.type = TDM_THREAD_CB_OUTPUT_VBLANK;
986 output_vblank.base.length = sizeof output_vblank;
987 output_vblank.base.object_stamp = vblank_handler->private_output->stamp;
988 output_vblank.base.data = vblank_handler;
989 output_vblank.base.sync = 0;
990 output_vblank.sequence = sequence;
991 output_vblank.tv_sec = tv_sec;
992 output_vblank.tv_usec = tv_usec;
994 vblank_handler->sent_to_frontend = 1;
996 if (tdm_debug_module & TDM_DEBUG_COMMIT)
997 TDM_INFO("output(%d) wait_vblank: handler(%p)", vblank_handler->private_output->pipe, vblank_handler);
999 ret = tdm_thread_cb_call(vblank_handler->private_output, &output_vblank.base, 1);
1000 TDM_WARNING_IF_FAIL(ret == TDM_ERROR_NONE);
1004 _tdm_output_thread_cb_commit(tdm_private_display *private_display, void *object, tdm_thread_cb_base *cb_base, void *user_data)
1006 tdm_thread_cb_output_commit *output_commit = (tdm_thread_cb_output_commit *)cb_base;
1007 tdm_private_output_commit_handler *output_commit_handler = output_commit->base.data;
1008 tdm_private_output *private_output = object;
1009 tdm_private_layer *private_layer = NULL;
1011 TDM_RETURN_IF_FAIL(TDM_MUTEX_IS_LOCKED());
1013 if (!output_commit_handler)
1016 assert(output_commit_handler->owner_tid == syscall(SYS_gettid));
1018 tdm_thread_cb_remove(private_output, TDM_THREAD_CB_OUTPUT_COMMIT, output_commit_handler, _tdm_output_thread_cb_commit, NULL);
1020 LIST_DEL(&output_commit_handler->link);
1022 if (tdm_debug_module & TDM_DEBUG_COMMIT) {
1023 TDM_INFO("----------------------------------------- output(%d) committed", private_output->pipe);
1024 TDM_INFO("handler(%p)", output_commit_handler);
1027 if (private_output->commit_type == TDM_COMMIT_TYPE_OUTPUT) {
1028 /* In case of layer commit, the below will be handled in the layer commit callback */
1029 LIST_FOR_EACH_ENTRY(private_layer, &private_output->layer_list, link) {
1030 if (private_layer->committed_buffer)
1031 tdm_layer_committed(private_layer, &private_layer->committed_buffer);
1035 if (output_commit_handler->func) {
1036 _pthread_mutex_unlock(&private_display->lock);
1037 output_commit_handler->func(private_output,
1038 output_commit->sequence,
1039 output_commit->tv_sec,
1040 output_commit->tv_usec,
1041 output_commit_handler->user_data);
1042 _pthread_mutex_lock(&private_display->lock);
1045 free(output_commit_handler);
1047 if (tdm_debug_module & TDM_DEBUG_COMMIT)
1048 TDM_INFO("-----------------------------------------...");
1052 _tdm_output_cb_commit(tdm_output *output_backend, unsigned int sequence,
1053 unsigned int tv_sec, unsigned int tv_usec, void *user_data)
1055 tdm_private_output_commit_handler *output_commit_handler = user_data;
1056 tdm_private_output *private_output;
1057 tdm_thread_cb_output_commit output_commit;
1060 if (output_commit_handler)
1061 private_output = output_commit_handler->private_output;
1063 private_output = tdm_display_find_private_output(tdm_display_get(), output_backend);
1065 memset(&output_commit, 0, sizeof output_commit);
1066 output_commit.base.type = TDM_THREAD_CB_OUTPUT_COMMIT;
1067 output_commit.base.length = sizeof output_commit;
1068 output_commit.base.object_stamp = private_output->stamp;
1069 output_commit.base.data = output_commit_handler;
1070 output_commit.base.sync = 0;
1071 output_commit.sequence = sequence;
1072 output_commit.tv_sec = tv_sec;
1073 output_commit.tv_usec = tv_usec;
1075 ret = tdm_thread_cb_call(private_output, &output_commit.base, 1);
1076 TDM_WARNING_IF_FAIL(ret == TDM_ERROR_NONE);
1080 _tdm_voutput_thread_cb_commit(tdm_private_display *private_display, void *object, tdm_thread_cb_base *cb_base, void *user_data)
1082 tdm_thread_cb_voutput_commit *voutput_commit = (tdm_thread_cb_voutput_commit *)cb_base;
1083 tdm_private_voutput_commit_handler *voutput_commit_handler = voutput_commit->base.data;
1084 tdm_private_voutput *private_voutput = object;
1085 tdm_private_output *private_output = NULL;
1087 TDM_RETURN_IF_FAIL(TDM_MUTEX_IS_LOCKED());
1089 if (!voutput_commit_handler)
1092 assert(voutput_commit_handler->owner_tid == syscall(SYS_gettid));
1094 tdm_thread_cb_remove(private_voutput, TDM_THREAD_CB_VOUTPUT_COMMIT, voutput_commit_handler, _tdm_voutput_thread_cb_commit, NULL);
1096 LIST_DEL(&voutput_commit_handler->link);
1098 private_output = private_voutput->private_output;
1099 if (tdm_debug_module & TDM_DEBUG_COMMIT) {
1100 TDM_INFO("----------------------------------------- voutput(%d) committed", private_output->pipe);
1101 TDM_INFO("handler(%p)", voutput_commit_handler);
1104 if (voutput_commit_handler->func && private_voutput->set_voutput_commit != 0) {
1105 _pthread_mutex_unlock(&private_display->lock);
1106 voutput_commit_handler->func(private_voutput, voutput_commit_handler->user_data);
1107 _pthread_mutex_lock(&private_display->lock);
1110 free(voutput_commit_handler);
1112 if (tdm_debug_module & TDM_DEBUG_COMMIT)
1113 TDM_INFO("-----------------------------------------...");
1117 _tdm_voutput_cb_commit(tdm_voutput *voutput_backend, unsigned int sequence,
1118 unsigned int tv_sec, unsigned int tv_usec, void *user_data)
1120 tdm_private_voutput_commit_handler *voutput_commit_handler = NULL;
1121 tdm_private_module *private_module;
1122 tdm_private_voutput *private_voutput = NULL, *v = NULL;
1123 tdm_private_output *private_output;
1124 tdm_thread_cb_voutput_commit voutput_commit;
1127 private_module = tdm_display_get()->virtual_module;
1129 LIST_FOR_EACH_ENTRY(v, &private_module->voutput_list, link) {
1130 if (v->voutput_backend == voutput_backend) {
1131 private_voutput = v;
1135 if (!private_voutput) {
1136 TDM_ERR("cannot find voutput");
1140 if (LIST_LENGTH(&private_voutput->voutput_commit_handler_list) == 0) return;
1142 voutput_commit_handler = LIST_FIRST_ENTRY(&private_voutput->voutput_commit_handler_list, tdm_private_voutput_commit_handler, link);
1144 private_output = private_voutput->private_output;
1146 memset(&voutput_commit, 0, sizeof voutput_commit);
1147 voutput_commit.base.type = TDM_THREAD_CB_VOUTPUT_COMMIT;
1148 voutput_commit.base.length = sizeof voutput_commit;
1149 voutput_commit.base.object_stamp = private_output->stamp;
1150 voutput_commit.base.data = voutput_commit_handler;
1151 voutput_commit.base.sync = 0;
1152 voutput_commit.sequence = sequence;
1153 voutput_commit.tv_sec = tv_sec;
1154 voutput_commit.tv_usec = tv_usec;
1156 ret = tdm_thread_cb_call(private_voutput, &voutput_commit.base, 1);
1157 TDM_WARNING_IF_FAIL(ret == TDM_ERROR_NONE);
1160 /* add_front: To distinguish between the user vblank handlers and the layer
1161 * commit vblank handlers. The layer commit handlers will be called
1162 * before calling the user vblank handlers.
1165 _tdm_output_wait_vblank(tdm_private_output *private_output, int interval, int sync,
1166 tdm_output_vblank_handler func, void *user_data,
1167 unsigned int add_front)
1169 tdm_private_module *private_module;
1170 tdm_func_output *func_output;
1171 tdm_private_output_vblank_handler *vblank_handler = NULL, *v = NULL;
1172 unsigned int skip_request = 0;
1173 pid_t tid = syscall(SYS_gettid);
1174 tdm_error ret = TDM_ERROR_NONE;
1176 private_module = private_output->private_module;
1177 func_output = &private_module->func_output;
1179 /* interval SHOULD be at least 1 */
1183 if (!func_output->output_wait_vblank) {
1184 /* LCOV_EXCL_START */
1185 TDM_WRN("not implemented!!");
1186 return TDM_ERROR_NOT_IMPLEMENTED;
1187 /* LCOV_EXCL_STOP */
1190 if (!private_output->regist_vblank_cb) {
1191 private_output->regist_vblank_cb = 1;
1192 ret = func_output->output_set_vblank_handler(private_output->output_backend,
1193 _tdm_output_cb_vblank);
1196 vblank_handler = calloc(1, sizeof(tdm_private_output_vblank_handler));
1197 if (!vblank_handler) {
1198 /* LCOV_EXCL_START */
1199 TDM_ERR("failed: alloc memory");
1200 return TDM_ERROR_OUT_OF_MEMORY;
1201 /* LCOV_EXCL_STOP */
1204 if (tdm_debug_module & TDM_DEBUG_COMMIT)
1205 TDM_INFO("output(%d) wait_vblank: handler(%p)", private_output->pipe, vblank_handler);
1207 LIST_FOR_EACH_ENTRY(v, &private_output->vblank_handler_list, link) {
1208 if (v->interval == interval && v->sync == sync && v->owner_tid == tid) {
1215 LIST_ADD(&vblank_handler->link, &private_output->vblank_handler_list);
1217 LIST_ADDTAIL(&vblank_handler->link, &private_output->vblank_handler_list);
1219 vblank_handler->private_output = private_output;
1220 vblank_handler->interval = interval;
1221 vblank_handler->sync = sync;
1222 vblank_handler->func = func;
1223 vblank_handler->user_data = user_data;
1224 vblank_handler->owner_tid = tid;
1226 /* If there is the previous request, we can skip to call output_wait_vblank() */
1227 if (!skip_request) {
1228 ret = tdm_thread_cb_add(private_output, TDM_THREAD_CB_OUTPUT_VBLANK, vblank_handler, _tdm_output_thread_cb_vblank, NULL);
1229 if (ret != TDM_ERROR_NONE) {
1230 TDM_ERR("tdm_thread_cb_add failed");
1234 ret = func_output->output_wait_vblank(private_output->output_backend, interval,
1235 sync, vblank_handler);
1236 TDM_GOTO_IF_FAIL(ret == TDM_ERROR_NONE, wait_failed);
1238 _tdm_output_vblank_timeout_update(private_output, 1000);
1240 if (tdm_debug_module & TDM_DEBUG_COMMIT)
1241 TDM_INFO("output(%d) backend wait_vblank", private_output->pipe);
1247 /* LCOV_EXCL_START */
1248 if (vblank_handler) {
1249 tdm_thread_cb_remove(private_output, TDM_THREAD_CB_OUTPUT_VBLANK, vblank_handler, _tdm_output_thread_cb_vblank, NULL);
1250 LIST_DEL(&vblank_handler->link);
1251 free(vblank_handler);
1254 /* LCOV_EXCL_STOP */
1258 tdm_output_wait_vblank(tdm_output *output, int interval, int sync,
1259 tdm_output_vblank_handler func, void *user_data)
1261 OUTPUT_FUNC_ENTRY();
1262 TDM_RETURN_VAL_IF_FAIL(interval > 0, TDM_ERROR_INVALID_PARAMETER);
1264 _pthread_mutex_lock(&private_display->lock);
1266 if (TDM_OUTPUT_DPMS_VSYNC_IS_OFF(private_output->current_dpms_value)) {
1267 TDM_WRN("output(%d) dpms: %s", private_output->pipe,
1268 tdm_dpms_str(private_output->current_dpms_value));
1269 _pthread_mutex_unlock(&private_display->lock);
1270 return TDM_ERROR_DPMS_OFF;
1273 ret = _tdm_output_wait_vblank(private_output, interval, sync, func, user_data, 0);
1275 _pthread_mutex_unlock(&private_display->lock);
1280 /* LCOV_EXCL_START */
1282 tdm_output_wait_vblank_add_front(tdm_output *output, int interval, int sync,
1283 tdm_output_vblank_handler func, void *user_data)
1285 OUTPUT_FUNC_ENTRY();
1287 _pthread_mutex_lock(&private_display->lock);
1289 if (TDM_OUTPUT_DPMS_VSYNC_IS_OFF(private_output->current_dpms_value)) {
1290 TDM_WRN("output(%d) dpms: %s", private_output->pipe,
1291 tdm_dpms_str(private_output->current_dpms_value));
1292 _pthread_mutex_unlock(&private_display->lock);
1293 return TDM_ERROR_DPMS_OFF;
1296 ret = _tdm_output_wait_vblank(private_output, interval, sync, func, user_data, 1);
1298 _pthread_mutex_unlock(&private_display->lock);
1302 /* LCOV_EXCL_STOP */
1305 tdm_output_remove_vblank_handler_internal(tdm_output *output, tdm_output_vblank_handler func, void *user_data)
1307 tdm_private_output *private_output = (tdm_private_output*)output;
1308 tdm_private_output_vblank_handler *v = NULL;
1310 TDM_RETURN_IF_FAIL(private_output != NULL);
1311 TDM_RETURN_IF_FAIL(TDM_MUTEX_IS_LOCKED());
1313 LIST_FOR_EACH_ENTRY(v, &private_output->vblank_handler_list, link) {
1314 if (v->func == func && v->user_data == user_data) {
1315 /* only set func & user_data to NULL. It will be freed when an event occurs */
1317 v->user_data = NULL;
1324 tdm_output_remove_commit_handler_internal(tdm_output *output, tdm_output_commit_handler func, void *user_data)
1326 tdm_private_output *private_output = (tdm_private_output*)output;
1327 tdm_private_output_commit_handler *c = NULL;
1329 TDM_RETURN_IF_FAIL(private_output != NULL);
1330 TDM_RETURN_IF_FAIL(TDM_MUTEX_IS_LOCKED());
1332 LIST_FOR_EACH_ENTRY(c, &private_output->output_commit_handler_list, link) {
1333 if (c->func == func && c->user_data == user_data) {
1334 /* only set func & user_data to NULL. It will be freed when an event occurs */
1336 c->user_data = NULL;
1343 tdm_output_remove_vblank_handler(tdm_output *output, tdm_output_vblank_handler func, void *user_data)
1345 OUTPUT_FUNC_ENTRY();
1347 _pthread_mutex_lock(&private_display->lock);
1349 tdm_output_remove_vblank_handler_internal(output, func, user_data);
1351 _pthread_mutex_unlock(&private_display->lock);
1357 tdm_output_remove_commit_handler(tdm_output *output, tdm_output_commit_handler func, void *user_data)
1359 OUTPUT_FUNC_ENTRY();
1361 _pthread_mutex_lock(&private_display->lock);
1363 tdm_output_remove_commit_handler_internal(output, func, user_data);
1365 _pthread_mutex_unlock(&private_display->lock);
1371 tdm_output_request_mode_set(tdm_output *output, unsigned int index)
1373 tdm_private_output *private_output = (tdm_private_output*)output;
1374 tdm_private_output_mode_change_handler *mode_change_handler = NULL;
1376 TDM_RETURN_IF_FAIL(private_output != NULL);
1378 if (LIST_IS_EMPTY(&private_output->mode_change_request_handler_list))
1381 LIST_FOR_EACH_ENTRY(mode_change_handler, &private_output->mode_change_request_handler_list, link) {
1382 mode_change_handler->func(mode_change_handler->private_output, index, mode_change_handler->user_data);
1387 _voutput_commit_func(tdm_voutput *voutput, tbm_surface_h buffer)
1389 tdm_private_voutput *private_voutput = (tdm_private_voutput *)voutput;
1392 TDM_RETURN_IF_FAIL(voutput != NULL);
1393 TDM_RETURN_IF_FAIL(buffer != NULL);
1395 ret = tdm_voutput_attach_buffer(private_voutput, buffer);
1396 TDM_RETURN_IF_FAIL(ret == TDM_ERROR_NONE);
1397 ret = tdm_voutput_commit_buffer(private_voutput);
1398 TDM_RETURN_IF_FAIL(ret == TDM_ERROR_NONE);
1404 tdm_output_set_voutput_commit(tdm_voutput *voutput)
1406 tdm_private_display *private_display;
1407 tdm_private_output *private_output;
1408 tdm_private_voutput *private_voutput;
1409 tdm_private_voutput_commit_handler *voutput_commit_handler = NULL;
1410 tdm_error ret = TDM_ERROR_NONE;
1412 TDM_RETURN_VAL_IF_FAIL(voutput != NULL, TDM_ERROR_INVALID_PARAMETER);
1414 private_voutput = (tdm_private_voutput *)voutput;
1415 private_display = private_voutput->private_display;
1416 private_output = (tdm_private_output *)private_voutput->private_output;
1418 _pthread_mutex_lock(&private_display->lock);
1420 if (LIST_LENGTH(&private_voutput->voutput_commit_handler_list) != 0) {
1421 _pthread_mutex_unlock(&private_display->lock);
1425 if (!private_voutput->regist_commit_cb) {
1426 private_voutput->regist_commit_cb = 1;
1427 ret = tdm_voutput_set_commit_func(private_voutput, _tdm_voutput_cb_commit);
1428 if (ret != TDM_ERROR_NONE) {
1429 TDM_ERR("failed: tdm_voutput_set_commit_func");
1434 voutput_commit_handler = calloc(1, sizeof(tdm_private_voutput_commit_handler));
1435 if (!voutput_commit_handler) {
1436 /* LCOV_EXCL_START */
1437 TDM_ERR("failed: alloc memory");
1438 _pthread_mutex_unlock(&private_display->lock);
1439 return TDM_ERROR_OUT_OF_MEMORY;
1440 /* LCOV_EXCL_STOP */
1443 ret = tdm_thread_cb_add(private_output->private_voutput, TDM_THREAD_CB_VOUTPUT_COMMIT, voutput_commit_handler, _tdm_voutput_thread_cb_commit, NULL);
1444 if (ret != TDM_ERROR_NONE) {
1445 TDM_ERR("tdm_thread_cb_add failed");
1446 free(voutput_commit_handler);
1447 _pthread_mutex_unlock(&private_display->lock);
1451 LIST_ADDTAIL(&voutput_commit_handler->link, &private_voutput->voutput_commit_handler_list);
1452 voutput_commit_handler->private_voutput = private_voutput;
1453 voutput_commit_handler->func = _voutput_commit_func;
1454 voutput_commit_handler->owner_tid = syscall(SYS_gettid);
1456 private_voutput->set_voutput_commit = 1;
1458 _pthread_mutex_unlock(&private_display->lock);
1464 tdm_output_unset_voutput_commit(tdm_voutput *voutput)
1466 tdm_private_display *private_display;
1467 tdm_private_output *private_output;
1468 tdm_private_voutput *private_voutput;
1469 tdm_private_voutput_commit_handler *voutput_commit_handler = NULL;
1470 tdm_error ret = TDM_ERROR_NONE;
1472 TDM_RETURN_VAL_IF_FAIL(voutput != NULL, TDM_ERROR_INVALID_PARAMETER);
1474 private_voutput = (tdm_private_voutput *)voutput;
1475 private_display = private_voutput->private_display;
1476 private_output = (tdm_private_output *)private_voutput->private_output;
1478 _pthread_mutex_lock(&private_display->lock);
1480 private_voutput->set_voutput_commit = 0;
1482 if (private_voutput->regist_commit_cb) {
1483 private_voutput->regist_commit_cb = 0;
1484 ret = tdm_voutput_set_commit_func(private_voutput, NULL);
1485 if (ret != TDM_ERROR_NONE) {
1486 TDM_ERR("failed: tdm_voutput_set_commit_func");
1491 if (LIST_LENGTH(&private_voutput->voutput_commit_handler_list) == 0) {
1492 _pthread_mutex_unlock(&private_display->lock);
1493 return TDM_ERROR_NONE;
1496 if (LIST_LENGTH(&private_output->output_commit_handler_list) != 0) {
1497 //commiting. don't remove voutput commit thread here
1498 _pthread_mutex_unlock(&private_display->lock);
1499 return TDM_ERROR_NONE;
1502 if (LIST_LENGTH(&private_voutput->voutput_commit_handler_list) != 0) {
1503 voutput_commit_handler = LIST_FIRST_ENTRY(&private_voutput->voutput_commit_handler_list, tdm_private_voutput_commit_handler, link);
1505 _pthread_mutex_unlock(&private_display->lock);
1506 return TDM_ERROR_NONE;
1509 tdm_thread_cb_remove(private_output->private_voutput, TDM_THREAD_CB_VOUTPUT_COMMIT, voutput_commit_handler, _tdm_voutput_thread_cb_commit, NULL);
1511 _pthread_mutex_unlock(&private_display->lock);
1513 return TDM_ERROR_NONE;
1517 tdm_output_commit_internal(tdm_output *output, int sync, tdm_output_commit_handler func, void *user_data)
1519 tdm_private_display *private_display;
1520 tdm_private_output *private_output;
1521 tdm_private_voutput *private_voutput;
1522 tdm_private_module *private_module;
1523 tdm_func_output *func_output;
1524 tdm_private_output_commit_handler *output_commit_handler = NULL;
1525 tdm_private_voutput_commit_handler *voutput_commit_handler = NULL;
1526 tdm_private_layer *private_layer = NULL;
1527 tdm_output_dpms dpms_value = TDM_OUTPUT_DPMS_ON;
1528 tdm_error ret = TDM_ERROR_NONE;
1530 TDM_RETURN_VAL_IF_FAIL(output != NULL, TDM_ERROR_INVALID_PARAMETER);
1532 private_output = (tdm_private_output*)output;
1533 private_module = private_output->private_module;
1534 private_display = private_module->private_display;
1535 func_output = &private_module->func_output;
1537 if (!func_output->output_commit) {
1538 /* LCOV_EXCL_START */
1539 TDM_WRN("not implemented!!");
1540 return TDM_ERROR_NOT_IMPLEMENTED;
1541 /* LCOV_EXCL_STOP */
1544 ret = tdm_output_get_dpms_internal(output, &dpms_value);
1545 TDM_RETURN_VAL_IF_FAIL(ret == TDM_ERROR_NONE, ret);
1547 if (!TDM_OUTPUT_DPMS_VSYNC_IS_OFF(dpms_value)) {
1548 if (!private_output->regist_commit_cb) {
1549 private_output->regist_commit_cb = 1;
1550 ret = func_output->output_set_commit_handler(private_output->output_backend, _tdm_output_cb_commit);
1551 TDM_GOTO_IF_FAIL(ret == TDM_ERROR_NONE, commit_failed);
1554 output_commit_handler = calloc(1, sizeof(tdm_private_output_commit_handler));
1555 if (!output_commit_handler) {
1556 /* LCOV_EXCL_START */
1557 TDM_ERR("failed: alloc memory");
1558 return TDM_ERROR_OUT_OF_MEMORY;
1559 /* LCOV_EXCL_STOP */
1562 if (private_module == private_display->virtual_module) {
1563 if (!private_output->private_voutput) {
1564 TDM_ERR("virtual module but don't have voutput");
1565 free(output_commit_handler);
1566 return TDM_ERROR_BAD_MODULE;
1570 ret = tdm_thread_cb_add(private_output, TDM_THREAD_CB_OUTPUT_COMMIT, output_commit_handler, _tdm_output_thread_cb_commit, NULL);
1571 if (ret != TDM_ERROR_NONE) {
1572 TDM_ERR("tdm_thread_cb_add failed");
1573 free(output_commit_handler);
1577 LIST_ADDTAIL(&output_commit_handler->link, &private_output->output_commit_handler_list);
1578 output_commit_handler->private_output = private_output;
1579 output_commit_handler->func = func;
1580 output_commit_handler->user_data = user_data;
1581 output_commit_handler->owner_tid = syscall(SYS_gettid);
1583 if (private_module == private_display->virtual_module) {
1584 private_voutput = private_output->private_voutput;
1586 /* voutput use only 1 layer */
1587 private_layer = LIST_FIRST_ENTRY(&private_output->layer_list, tdm_private_layer, link);
1589 if (LIST_LENGTH(&private_voutput->voutput_commit_handler_list) != 0) {
1590 voutput_commit_handler = LIST_FIRST_ENTRY(&private_voutput->voutput_commit_handler_list, tdm_private_voutput_commit_handler, link);
1591 voutput_commit_handler->user_data = private_layer->commiting_buffer;
1595 ret = func_output->output_commit(private_output->output_backend, sync,
1596 output_commit_handler);
1597 TDM_GOTO_IF_FAIL(ret == TDM_ERROR_NONE, commit_failed);
1599 if (tdm_debug_module & TDM_DEBUG_COMMIT)
1600 TDM_INFO("output(%d) backend commit: handle(%p) func(%p) user_data(%p)",
1601 private_output->pipe, output_commit_handler, func, user_data);
1604 /* Even if DPMS is off, committed_buffer should be changed because it will be referred
1605 * for tdm_layer_committed() function.
1607 LIST_FOR_EACH_ENTRY(private_layer, &private_output->layer_list, link) {
1608 if (!private_layer->waiting_buffer)
1611 if (private_layer->committed_buffer) {
1612 tdm_layer_free_buffer(private_layer, private_layer->committed_buffer);
1613 private_layer->committed_buffer = NULL;
1614 if (tdm_debug_module & TDM_DEBUG_BUFFER)
1615 TDM_INFO("layer(%p) waiting_buffer(%p) committed_buffer(%p)",
1616 private_layer, private_layer->waiting_buffer->buffer,
1617 private_layer->committed_buffer);
1620 private_layer->committed_buffer = private_layer->waiting_buffer;
1621 private_layer->waiting_buffer = NULL;
1622 private_layer->commiting_buffer = NULL;
1623 if (tdm_debug_module & TDM_DEBUG_BUFFER)
1624 TDM_INFO("layer(%p) waiting_buffer(%p) committed_buffer(%p)",
1625 private_layer, private_layer->waiting_buffer,
1626 private_layer->committed_buffer->buffer);
1629 if (TDM_OUTPUT_DPMS_VSYNC_IS_OFF(dpms_value)) {
1630 TDM_WRN("dpms %s. Directly call commit handler instead of commit.", tdm_dpms_str(dpms_value));
1632 func(output, 0, 0, 0, user_data);
1638 /* LCOV_EXCL_START */
1639 if (output_commit_handler) {
1640 tdm_thread_cb_remove(private_output, TDM_THREAD_CB_OUTPUT_COMMIT, output_commit_handler, _tdm_output_thread_cb_commit, NULL);
1641 LIST_DEL(&output_commit_handler->link);
1642 free(output_commit_handler);
1646 /* LCOV_EXCL_STOP */
1650 tdm_output_commit(tdm_output *output, int sync, tdm_output_commit_handler func,
1653 tdm_private_layer *private_layer = NULL;
1655 OUTPUT_FUNC_ENTRY();
1657 _pthread_mutex_lock(&private_display->lock);
1659 if (private_output->commit_type == TDM_COMMIT_TYPE_NONE)
1660 private_output->commit_type = TDM_COMMIT_TYPE_OUTPUT;
1661 else if (private_output->commit_type == TDM_COMMIT_TYPE_LAYER) {
1662 TDM_ERR("Can't supported. Use tdm_layer_commit");
1663 _pthread_mutex_unlock(&private_display->lock);
1664 return TDM_ERROR_BAD_REQUEST;
1667 if (private_output->commit_per_vblank) {
1668 TDM_ERR("Use tdm_layer_commit");
1669 _pthread_mutex_unlock(&private_display->lock);
1670 return TDM_ERROR_BAD_REQUEST;
1673 if (TDM_OUTPUT_DPMS_VSYNC_IS_OFF(private_output->current_dpms_value)) {
1674 TDM_ERR("output(%d) dpms: %s", private_output->pipe,
1675 tdm_dpms_str(private_output->current_dpms_value));
1676 _pthread_mutex_unlock(&private_display->lock);
1677 return TDM_ERROR_DPMS_OFF;
1680 if (tdm_debug_module & TDM_DEBUG_COMMIT)
1681 TDM_INFO("output(%d) commit", private_output->pipe);
1683 /* apply the pending data of all layers */
1684 LIST_FOR_EACH_ENTRY(private_layer, &private_output->layer_list, link) {
1685 tdm_layer_commit_pending_data(private_layer);
1688 ret = tdm_output_commit_internal(output, sync, func, user_data);
1690 _pthread_mutex_unlock(&private_display->lock);
1696 tdm_output_set_mode(tdm_output *output, const tdm_output_mode *mode)
1698 tdm_private_module *private_module;
1699 tdm_func_output *func_output;
1700 OUTPUT_FUNC_ENTRY();
1702 TDM_RETURN_VAL_IF_FAIL(mode != NULL, TDM_ERROR_INVALID_PARAMETER);
1704 _pthread_mutex_lock(&private_display->lock);
1706 private_module = private_output->private_module;
1707 func_output = &private_module->func_output;
1709 if (!func_output->output_set_mode) {
1710 /* LCOV_EXCL_START */
1711 _pthread_mutex_unlock(&private_display->lock);
1712 TDM_WRN("not implemented!!");
1713 return TDM_ERROR_NOT_IMPLEMENTED;
1714 /* LCOV_EXCL_STOP */
1717 ret = func_output->output_set_mode(private_output->output_backend, mode);
1718 if (ret == TDM_ERROR_NONE) {
1719 private_output->current_mode = mode;
1720 private_output->need_set_target_info = 1;
1721 TDM_INFO("mode: %dx%d %dhz", mode->hdisplay, mode->vdisplay, mode->vrefresh);
1724 _pthread_mutex_unlock(&private_display->lock);
1730 tdm_output_get_mode(tdm_output *output, const tdm_output_mode **mode)
1732 OUTPUT_FUNC_ENTRY();
1734 TDM_RETURN_VAL_IF_FAIL(mode != NULL, TDM_ERROR_INVALID_PARAMETER);
1736 _pthread_mutex_lock(&private_display->lock);
1738 *mode = private_output->current_mode;
1740 _pthread_mutex_unlock(&private_display->lock);
1746 tdm_output_set_dpms(tdm_output *output, tdm_output_dpms dpms_value)
1748 tdm_private_module *private_module;
1749 tdm_func_output *func_output;
1750 OUTPUT_FUNC_ENTRY();
1752 if (dpms_value > TDM_OUTPUT_DPMS_OFF) {
1753 if (dpms_value & TDM_OUTPUT_DPMS_DEFAULT_MASK) {
1754 TDM_ERR("Don't use the low-4bit for an extended DPMS mode: dpms_value(%x)", dpms_value);
1755 return TDM_ERROR_BAD_REQUEST;
1758 if (!(private_output->caps.capabilities & TDM_OUTPUT_CAPABILITY_EXTENDED_DPMS)) {
1759 TDM_ERR("output(%d) doesn't support the extended DPMS control: '%s'",
1760 private_output->pipe, tdm_dpms_str(dpms_value));
1761 return TDM_ERROR_BAD_REQUEST;
1765 _pthread_mutex_lock(&private_display->lock);
1767 if (private_output->waiting_dpms_change) {
1768 TDM_ERR("DPMS is not changed yet. Can't be changed twice");
1769 _pthread_mutex_unlock(&private_display->lock);
1770 return TDM_ERROR_BAD_REQUEST;
1773 private_module = private_output->private_module;
1774 func_output = &private_module->func_output;
1776 TDM_INFO("output(%d) dpms '%s'", private_output->pipe, tdm_dpms_str(dpms_value));
1778 if (func_output->output_set_dpms)
1779 ret = func_output->output_set_dpms(private_output->output_backend, dpms_value);
1781 /* LCOV_EXCL_START */
1782 ret = TDM_ERROR_NONE;
1783 TDM_WRN("not implemented!!");
1785 /* LCOV_EXCL_STOP */
1789 if (ret == TDM_ERROR_NONE) {
1790 if (private_output->current_dpms_value != dpms_value) {
1791 private_output->current_dpms_value = dpms_value;
1792 _tdm_output_call_thread_cb_dpms(private_output, dpms_value);
1794 TDM_INFO("output(%d) dpms '%s' done", private_output->pipe, tdm_dpms_str(dpms_value));
1796 tdm_output_dpms temp = TDM_OUTPUT_DPMS_OFF;
1798 /* update current_dpms_value forcely */
1799 tdm_output_get_dpms_internal(output, &temp);
1801 TDM_ERR("output(%d) set_dpms failed: dpms '%s'", private_output->pipe, tdm_dpms_str(temp));
1804 _pthread_mutex_unlock(&private_display->lock);
1809 /* LCOV_EXCL_START */
1811 tdm_output_set_dpms_async(tdm_output *output, tdm_output_dpms dpms_value)
1813 tdm_private_module *private_module;
1814 tdm_func_output *func_output;
1815 OUTPUT_FUNC_ENTRY();
1817 if (!(private_output->caps.capabilities & TDM_OUTPUT_CAPABILITY_ASYNC_DPMS)) {
1818 TDM_ERR("output doesn't support the asynchronous DPMS control!");
1819 return TDM_ERROR_BAD_REQUEST;
1822 if (dpms_value > TDM_OUTPUT_DPMS_OFF) {
1823 if (dpms_value & TDM_OUTPUT_DPMS_DEFAULT_MASK) {
1824 TDM_ERR("Don't use the low-4bit for an extended DPMS mode: dpms_value(%x)", dpms_value);
1825 return TDM_ERROR_BAD_REQUEST;
1828 if (!(private_output->caps.capabilities & TDM_OUTPUT_CAPABILITY_EXTENDED_DPMS)) {
1829 TDM_ERR("output(%d) doesn't support the extended DPMS control: '%s'",
1830 private_output->pipe, tdm_dpms_str(dpms_value));
1831 return TDM_ERROR_BAD_REQUEST;
1835 _pthread_mutex_lock(&private_display->lock);
1837 if (private_output->waiting_dpms_change) {
1838 TDM_ERR("DPMS is not changed yet. Can't be changed twice");
1839 _pthread_mutex_unlock(&private_display->lock);
1840 return TDM_ERROR_BAD_REQUEST;
1843 private_module = private_output->private_module;
1844 func_output = &private_module->func_output;
1845 if (!func_output->output_set_dpms_handler) {
1846 TDM_WRN("not implemented: output_set_dpms_handler");
1847 _pthread_mutex_unlock(&private_display->lock);
1848 return TDM_ERROR_NOT_IMPLEMENTED;
1851 if (!func_output->output_set_dpms_async) {
1852 TDM_WRN("not implemented: output_set_dpms_async");
1853 _pthread_mutex_unlock(&private_display->lock);
1854 return TDM_ERROR_NOT_IMPLEMENTED;
1857 if (!private_output->regist_dpms_cb) {
1858 private_output->regist_dpms_cb = 1;
1859 ret = func_output->output_set_dpms_handler(private_output->output_backend,
1860 tdm_output_cb_dpms, private_output);
1861 if (ret != TDM_ERROR_NONE) {
1862 _pthread_mutex_unlock(&private_display->lock);
1863 TDM_ERR("Can't set the dpms handler!!");
1868 TDM_INFO("output(%d) dpms async '%s'", private_output->pipe, tdm_dpms_str(dpms_value));
1870 ret = func_output->output_set_dpms_async(private_output->output_backend, dpms_value);
1872 if (ret == TDM_ERROR_NONE) {
1873 private_output->waiting_dpms_change = 1;
1874 TDM_INFO("output(%d) dpms async '%s' waiting", private_output->pipe, tdm_dpms_str(dpms_value));
1876 tdm_output_dpms temp = TDM_OUTPUT_DPMS_OFF;
1878 /* update current_dpms_value forcely */
1879 tdm_output_get_dpms_internal(output, &temp);
1881 TDM_ERR("output(%d) set_dpms_async failed: dpms '%s'", private_output->pipe, tdm_dpms_str(temp));
1884 _pthread_mutex_unlock(&private_display->lock);
1888 /* LCOV_EXCL_STOP */
1891 tdm_output_get_dpms_internal(tdm_output *output, tdm_output_dpms *dpms_value)
1893 tdm_private_output *private_output;
1894 tdm_private_module *private_module;
1895 tdm_func_output *func_output;
1896 tdm_error ret = TDM_ERROR_NONE;
1898 TDM_RETURN_VAL_IF_FAIL(output != NULL, TDM_ERROR_INVALID_PARAMETER);
1900 private_output = (tdm_private_output*)output;
1902 /* TODO: this is ugly. But before calling backend's output_get_dpms(), we have
1903 * to check if all backends's DPMS operation has no problem. In future, we'd
1904 * better use new env instead of using commit_per_vblank variable to distinguish
1905 * whether we use the stored value or backend's output_get_dpms.
1907 if (!private_output->commit_per_vblank) {
1908 *dpms_value = private_output->current_dpms_value;
1909 return TDM_ERROR_NONE;
1912 private_module = private_output->private_module;
1913 func_output = &private_module->func_output;
1915 if (!func_output->output_get_dpms) {
1916 /* LCOV_EXCL_START */
1917 *dpms_value = private_output->current_dpms_value;
1918 TDM_WRN("not implemented!!");
1919 return TDM_ERROR_NONE;
1920 /* LCOV_EXCL_STOP */
1923 ret = func_output->output_get_dpms(private_output->output_backend, dpms_value);
1924 if (ret != TDM_ERROR_NONE) {
1925 /* LCOV_EXCL_START */
1926 TDM_ERR("output_get_dpms failed");
1927 *dpms_value = TDM_OUTPUT_DPMS_OFF;
1928 /* LCOV_EXCL_STOP */
1931 /* checking with backend's value */
1932 if (*dpms_value != private_output->current_dpms_value) {
1933 TDM_ERR("output(%d) dpms changed suddenly: %s -> %s",
1934 private_output->pipe, tdm_dpms_str(private_output->current_dpms_value),
1935 tdm_dpms_str(*dpms_value));
1936 private_output->current_dpms_value = *dpms_value;
1937 _tdm_output_call_thread_cb_dpms(private_output, *dpms_value);
1944 tdm_output_get_dpms(tdm_output *output, tdm_output_dpms *dpms_value)
1946 OUTPUT_FUNC_ENTRY();
1948 TDM_RETURN_VAL_IF_FAIL(dpms_value != NULL, TDM_ERROR_INVALID_PARAMETER);
1950 _pthread_mutex_lock(&private_display->lock);
1952 ret = tdm_output_get_dpms_internal(output, dpms_value);
1954 _pthread_mutex_unlock(&private_display->lock);
1960 tdm_output_has_capture_capability(tdm_output *output, unsigned int *has_capability)
1962 tdm_private_module *private_module;
1964 OUTPUT_FUNC_ENTRY();
1966 TDM_RETURN_VAL_IF_FAIL(has_capability != NULL, TDM_ERROR_INVALID_PARAMETER);
1968 _pthread_mutex_lock(&private_display->lock);
1970 private_module = private_output->private_module;
1972 if (!(private_module->capabilities & TDM_DISPLAY_CAPABILITY_CAPTURE))
1973 *has_capability = 0;
1974 else if (!(private_module->caps_capture.capabilities & TDM_CAPTURE_CAPABILITY_OUTPUT))
1975 *has_capability = 0;
1977 *has_capability = 1;
1979 _pthread_mutex_unlock(&private_display->lock);
1984 EXTERN tdm_capture *
1985 tdm_output_create_capture(tdm_output *output, tdm_error *error)
1987 tdm_capture *capture = NULL;
1989 OUTPUT_FUNC_ENTRY_ERROR();
1991 _pthread_mutex_lock(&private_display->lock);
1993 capture = (tdm_capture *)tdm_capture_create_output_internal(private_output, error);
1995 _pthread_mutex_unlock(&private_display->lock);
2001 tdm_output_get_hwc(tdm_output *output, tdm_error *error)
2003 tdm_private_hwc *private_hwc = NULL;
2005 OUTPUT_FUNC_ENTRY_ERROR();
2007 _pthread_mutex_lock(&private_display->lock);
2009 private_hwc = private_output->private_hwc;
2012 *error = TDM_ERROR_BAD_REQUEST;
2013 _pthread_mutex_unlock(&private_display->lock);
2018 *error = TDM_ERROR_NONE;
2020 _pthread_mutex_unlock(&private_display->lock);
2026 tdm_output_choose_commit_per_vblank_mode(tdm_private_output *private_output, int mode)
2028 if (!private_output)
2029 return TDM_ERROR_INVALID_PARAMETER;
2031 if (mode < 0 || mode > 2)
2032 return TDM_ERROR_INVALID_PARAMETER;
2034 private_output->commit_per_vblank = mode;
2036 if (private_output->commit_per_vblank == 0)
2037 TDM_INFO("commit per vblank: disable");
2038 else if (private_output->commit_per_vblank == 1)
2039 TDM_INFO("commit per vblank: enable (1 layer)");
2040 else if (private_output->commit_per_vblank == 2)
2041 TDM_INFO("commit per vblank: enable (previous commit)");
2043 return TDM_ERROR_NONE;
2046 INTERN tdm_voutput *
2047 tdm_voutput_create(tdm_display *dpy, const char *name, tdm_error *error)
2049 tdm_private_module *private_module = NULL;
2050 tdm_private_module *current_module = NULL;
2051 tdm_private_voutput *private_voutput = NULL;
2052 tdm_private_output *private_output = NULL;
2053 tdm_func_display *func_display = NULL;
2054 tdm_func_voutput *func_voutput = NULL;
2055 tdm_voutput *voutput_backend = NULL;
2056 tdm_output *output_backend = NULL;
2057 int output_find = 0;
2058 tdm_private_display *private_display;
2059 tdm_error ret = TDM_ERROR_NONE;
2061 TDM_RETURN_VAL_IF_FAIL_WITH_ERROR(dpy != NULL, TDM_ERROR_INVALID_PARAMETER, NULL);
2062 private_display = (tdm_private_display*)dpy;
2063 private_module = private_display->virtual_module;
2064 TDM_RETURN_VAL_IF_FAIL_WITH_ERROR(private_module != NULL, TDM_ERROR_BAD_MODULE, NULL);
2066 _pthread_mutex_lock(&private_display->lock);
2068 if (error) *error = TDM_ERROR_NONE;
2070 private_voutput = calloc(1, sizeof(tdm_private_voutput));
2071 if (!private_voutput) {
2072 if (error) *error = TDM_ERROR_OUT_OF_MEMORY;
2073 _pthread_mutex_unlock(&private_display->lock);
2077 func_display = &private_module->func_display;
2078 func_voutput = &private_module->func_voutput;
2079 current_module = private_display->current_module;
2080 private_display->current_module = private_module;
2082 voutput_backend = func_display->voutput_create(private_module->bdata, name, &ret);
2084 if (voutput_backend == NULL || ret != TDM_ERROR_NONE) {
2085 TDM_ERR("voutput_create fail");
2086 free(private_voutput);
2087 if (error) *error = ret;
2088 private_display->current_module = current_module;
2089 _pthread_mutex_unlock(&private_display->lock);
2092 private_voutput->voutput_backend = voutput_backend;
2093 private_voutput->private_display = private_display;
2094 private_voutput->private_module = private_module;
2095 LIST_INITHEAD(&private_voutput->voutput_commit_handler_list);
2097 output_backend = func_voutput->voutput_get_output(voutput_backend, &ret);
2098 if (output_backend == NULL || ret != TDM_ERROR_NONE) {
2099 TDM_ERR("voutput_get_output fail");
2100 free(private_voutput);
2101 if (error) *error = ret;
2102 if (func_voutput->voutput_destroy)
2103 func_voutput->voutput_destroy(voutput_backend);
2105 TDM_ERR("no destroy function");
2106 private_display->current_module = current_module;
2107 _pthread_mutex_unlock(&private_display->lock);
2111 ret = tdm_display_update_output(private_display->current_module, output_backend);
2112 if (ret != TDM_ERROR_NONE) {
2113 TDM_ERR("tdm_display_update_output fail");
2114 free(private_voutput);
2115 if (func_voutput->voutput_destroy)
2116 func_voutput->voutput_destroy(voutput_backend);
2118 TDM_ERR("no destroy function");
2119 if (error) *error = ret;
2120 private_display->current_module = current_module;
2121 _pthread_mutex_unlock(&private_display->lock);
2125 LIST_FOR_EACH_ENTRY(private_output, &private_module->output_list, link) {
2126 if (private_output->output_backend == output_backend) {
2132 if (output_find != 1) {
2133 private_output = NULL;
2134 free(private_voutput);
2135 if (func_voutput->voutput_destroy)
2136 func_voutput->voutput_destroy(voutput_backend);
2138 TDM_ERR("no destroy function");
2139 private_voutput = NULL;
2141 strncpy(private_voutput->name, name, TDM_NAME_LEN - 1);
2142 private_voutput->name[TDM_NAME_LEN - 1] = '\0';
2143 strncpy(private_output->name, name, TDM_NAME_LEN - 1);
2144 private_output->name[TDM_NAME_LEN - 1] = '\0';
2146 private_voutput->private_output = private_output;
2147 private_output->private_voutput = private_voutput;
2149 /* do not use vblank */
2150 tdm_output_choose_commit_per_vblank_mode(private_output, 0);
2152 LIST_ADDTAIL(&private_voutput->link, &private_module->voutput_list);
2155 private_display->current_module = current_module;
2157 _pthread_mutex_unlock(&private_display->lock);
2159 return private_voutput;
2163 tdm_voutput_destroy(tdm_voutput *voutput)
2165 tdm_private_module *private_module = NULL;
2166 tdm_voutput *voutput_backend = NULL;
2167 tdm_func_voutput *func_voutput = NULL;
2169 tdm_private_display *private_display;
2170 tdm_private_voutput *private_voutput;
2171 tdm_private_output *private_output;
2172 tdm_error ret = TDM_ERROR_NONE;
2173 TDM_RETURN_VAL_IF_FAIL(voutput != NULL, TDM_ERROR_INVALID_PARAMETER);
2174 private_voutput = (tdm_private_voutput*)voutput;
2175 private_display = private_voutput->private_display;
2176 private_module = private_voutput->private_module;
2177 TDM_RETURN_VAL_IF_FAIL(private_module == private_display->virtual_module, TDM_ERROR_BAD_MODULE);
2179 _pthread_mutex_lock(&private_display->lock);
2181 func_voutput = &private_module->func_voutput;
2182 voutput_backend = private_voutput->voutput_backend;
2183 private_output = private_voutput->private_output;
2184 tdm_display_destroy_private_output(private_output);
2185 LIST_DEL(&private_voutput->link);
2186 free(private_voutput);
2187 if (func_voutput->voutput_destroy)
2188 ret = func_voutput->voutput_destroy(voutput_backend);
2190 _pthread_mutex_unlock(&private_display->lock);
2196 tdm_voutput_set_available_mode(tdm_voutput *voutput, const tdm_output_mode *modes, int count)
2198 tdm_private_display *private_display;
2199 tdm_private_module *private_module = NULL;
2200 tdm_private_voutput *private_voutput;
2201 tdm_func_voutput *func_voutput = NULL;
2202 tdm_error ret = TDM_ERROR_NONE;
2204 TDM_RETURN_VAL_IF_FAIL(voutput != NULL, TDM_ERROR_INVALID_PARAMETER);
2205 TDM_RETURN_VAL_IF_FAIL(modes != NULL, TDM_ERROR_INVALID_PARAMETER);
2206 TDM_RETURN_VAL_IF_FAIL(count != 0, TDM_ERROR_INVALID_PARAMETER);
2208 private_voutput = (tdm_private_voutput*)voutput;
2209 private_display = private_voutput->private_display;
2210 private_module = private_voutput->private_module;
2211 TDM_RETURN_VAL_IF_FAIL(private_module == private_display->virtual_module, TDM_ERROR_BAD_MODULE);
2213 _pthread_mutex_lock(&private_display->lock);
2215 func_voutput = &private_module->func_voutput;
2216 if (func_voutput->voutput_set_available_mode)
2217 ret = func_voutput->voutput_set_available_mode(private_voutput->voutput_backend, modes, count);
2219 ret = TDM_ERROR_NOT_IMPLEMENTED;
2221 _pthread_mutex_unlock(&private_display->lock);
2227 tdm_voutput_set_physical_size(tdm_voutput *voutput, unsigned int mmwidth, unsigned int mmheight)
2229 tdm_private_display *private_display;
2230 tdm_private_module *private_module = NULL;
2231 tdm_private_voutput *private_voutput;
2232 tdm_func_voutput *func_voutput = NULL;
2233 tdm_error ret = TDM_ERROR_NONE;
2235 TDM_RETURN_VAL_IF_FAIL(voutput != NULL, TDM_ERROR_INVALID_PARAMETER);
2236 TDM_RETURN_VAL_IF_FAIL(mmwidth != 0, TDM_ERROR_INVALID_PARAMETER);
2237 TDM_RETURN_VAL_IF_FAIL(mmheight != 0, TDM_ERROR_INVALID_PARAMETER);
2239 private_voutput = (tdm_private_voutput*)voutput;
2240 private_display = private_voutput->private_display;
2241 private_module = private_voutput->private_module;
2242 TDM_RETURN_VAL_IF_FAIL(private_module == private_display->virtual_module, TDM_ERROR_BAD_MODULE);
2244 _pthread_mutex_lock(&private_display->lock);
2246 func_voutput = &private_module->func_voutput;
2247 if (func_voutput->voutput_set_physical_size)
2248 ret = func_voutput->voutput_set_physical_size(private_voutput->voutput_backend, mmwidth, mmheight);
2250 ret = TDM_ERROR_NOT_IMPLEMENTED;
2252 _pthread_mutex_unlock(&private_display->lock);
2258 tdm_voutput_connect(tdm_voutput *voutput)
2260 tdm_private_display *private_display;
2261 tdm_private_module *private_module = NULL;
2262 tdm_private_voutput *private_voutput;
2263 tdm_func_voutput *func_voutput = NULL;
2264 tdm_error ret = TDM_ERROR_NONE;
2266 TDM_RETURN_VAL_IF_FAIL(voutput != NULL, TDM_ERROR_INVALID_PARAMETER);
2268 private_voutput = (tdm_private_voutput*)voutput;
2269 private_display = private_voutput->private_display;
2270 private_module = private_voutput->private_module;
2271 TDM_RETURN_VAL_IF_FAIL(private_module == private_display->virtual_module, TDM_ERROR_BAD_MODULE);
2273 _pthread_mutex_lock(&private_display->lock);
2275 func_voutput = &private_module->func_voutput;
2276 if (func_voutput->voutput_connect)
2277 ret = func_voutput->voutput_connect(private_voutput->voutput_backend);
2279 ret = TDM_ERROR_NOT_IMPLEMENTED;
2281 _pthread_mutex_unlock(&private_display->lock);
2287 tdm_voutput_disconnect(tdm_voutput *voutput)
2289 tdm_private_display *private_display;
2290 tdm_private_module *private_module = NULL;
2291 tdm_private_voutput *private_voutput;
2292 tdm_func_voutput *func_voutput = NULL;
2293 tdm_error ret = TDM_ERROR_NONE;
2295 TDM_RETURN_VAL_IF_FAIL(voutput != NULL, TDM_ERROR_INVALID_PARAMETER);
2297 private_voutput = (tdm_private_voutput*)voutput;
2298 private_display = private_voutput->private_display;
2299 private_module = private_voutput->private_module;
2300 TDM_RETURN_VAL_IF_FAIL(private_module == private_display->virtual_module, TDM_ERROR_BAD_MODULE);
2302 _pthread_mutex_lock(&private_display->lock);
2304 func_voutput = &private_module->func_voutput;
2305 if (func_voutput->voutput_disconnect)
2306 ret = func_voutput->voutput_disconnect(private_voutput->voutput_backend);
2308 ret = TDM_ERROR_NOT_IMPLEMENTED;
2310 _pthread_mutex_unlock(&private_display->lock);
2315 /* LCOV_EXCL_START */
2317 tdm_voutput_set_commit_func(tdm_voutput *voutput, tdm_voutput_commit_handler func)
2319 tdm_private_display *private_display;
2320 tdm_private_module *private_module = NULL;
2321 tdm_private_voutput *private_voutput;
2322 tdm_func_voutput *func_voutput = NULL;
2323 tdm_error ret = TDM_ERROR_NONE;
2325 TDM_RETURN_VAL_IF_FAIL(voutput != NULL, TDM_ERROR_INVALID_PARAMETER);
2327 private_voutput = (tdm_private_voutput*)voutput;
2328 private_display = private_voutput->private_display;
2329 private_module = private_voutput->private_module;
2330 TDM_RETURN_VAL_IF_FAIL(private_module == private_display->virtual_module, TDM_ERROR_BAD_MODULE);
2332 func_voutput = &private_module->func_voutput;
2333 if (func_voutput->voutput_set_commit_func)
2334 ret = func_voutput->voutput_set_commit_func(private_voutput->voutput_backend, func);
2336 ret = TDM_ERROR_NOT_IMPLEMENTED;
2342 tdm_voutput_commit_done(tdm_voutput *voutput)
2344 tdm_private_display *private_display;
2345 tdm_private_module *private_module = NULL;
2346 tdm_private_voutput *private_voutput;
2347 tdm_func_voutput *func_voutput = NULL;
2348 tdm_error ret = TDM_ERROR_NONE;
2350 TDM_RETURN_VAL_IF_FAIL(voutput != NULL, TDM_ERROR_INVALID_PARAMETER);
2352 private_voutput = (tdm_private_voutput*)voutput;
2353 private_display = private_voutput->private_display;
2354 private_module = private_voutput->private_module;
2355 TDM_RETURN_VAL_IF_FAIL(private_module == private_display->virtual_module, TDM_ERROR_BAD_MODULE);
2357 _pthread_mutex_lock(&private_display->lock);
2359 func_voutput = &private_module->func_voutput;
2360 if (func_voutput->voutput_commit_done)
2361 ret = func_voutput->voutput_commit_done(private_voutput->voutput_backend);
2363 ret = TDM_ERROR_NOT_IMPLEMENTED;
2365 _pthread_mutex_unlock(&private_display->lock);
2369 /* LCOV_EXCL_STOP */