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_mode_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");
1487 _pthread_mutex_unlock(&private_display->lock);
1492 if (LIST_LENGTH(&private_voutput->voutput_commit_handler_list) == 0) {
1493 _pthread_mutex_unlock(&private_display->lock);
1494 return TDM_ERROR_NONE;
1497 if (LIST_LENGTH(&private_output->output_commit_handler_list) != 0) {
1498 //commiting. don't remove voutput commit thread here
1499 _pthread_mutex_unlock(&private_display->lock);
1500 return TDM_ERROR_NONE;
1503 if (LIST_LENGTH(&private_voutput->voutput_commit_handler_list) != 0) {
1504 voutput_commit_handler = LIST_FIRST_ENTRY(&private_voutput->voutput_commit_handler_list, tdm_private_voutput_commit_handler, link);
1506 _pthread_mutex_unlock(&private_display->lock);
1507 return TDM_ERROR_NONE;
1510 tdm_thread_cb_remove(private_output->private_voutput, TDM_THREAD_CB_VOUTPUT_COMMIT, voutput_commit_handler, _tdm_voutput_thread_cb_commit, NULL);
1512 _pthread_mutex_unlock(&private_display->lock);
1514 return TDM_ERROR_NONE;
1518 tdm_output_commit_internal(tdm_output *output, int sync, tdm_output_commit_handler func, void *user_data)
1520 tdm_private_display *private_display;
1521 tdm_private_output *private_output;
1522 tdm_private_voutput *private_voutput;
1523 tdm_private_module *private_module;
1524 tdm_func_output *func_output;
1525 tdm_private_output_commit_handler *output_commit_handler = NULL;
1526 tdm_private_voutput_commit_handler *voutput_commit_handler = NULL;
1527 tdm_private_layer *private_layer = NULL;
1528 tdm_output_dpms dpms_value = TDM_OUTPUT_DPMS_ON;
1529 tdm_error ret = TDM_ERROR_NONE;
1531 TDM_RETURN_VAL_IF_FAIL(output != NULL, TDM_ERROR_INVALID_PARAMETER);
1533 private_output = (tdm_private_output*)output;
1534 private_module = private_output->private_module;
1535 private_display = private_module->private_display;
1536 func_output = &private_module->func_output;
1538 if (!func_output->output_commit) {
1539 /* LCOV_EXCL_START */
1540 TDM_WRN("not implemented!!");
1541 return TDM_ERROR_NOT_IMPLEMENTED;
1542 /* LCOV_EXCL_STOP */
1545 ret = tdm_output_get_dpms_internal(output, &dpms_value);
1546 TDM_RETURN_VAL_IF_FAIL(ret == TDM_ERROR_NONE, ret);
1548 if (!TDM_OUTPUT_DPMS_VSYNC_IS_OFF(dpms_value)) {
1549 if (!private_output->regist_commit_cb) {
1550 private_output->regist_commit_cb = 1;
1551 ret = func_output->output_set_commit_handler(private_output->output_backend, _tdm_output_cb_commit);
1552 TDM_GOTO_IF_FAIL(ret == TDM_ERROR_NONE, commit_failed);
1555 output_commit_handler = calloc(1, sizeof(tdm_private_output_commit_handler));
1556 if (!output_commit_handler) {
1557 /* LCOV_EXCL_START */
1558 TDM_ERR("failed: alloc memory");
1559 return TDM_ERROR_OUT_OF_MEMORY;
1560 /* LCOV_EXCL_STOP */
1563 if (private_module == private_display->virtual_module) {
1564 if (!private_output->private_voutput) {
1565 TDM_ERR("virtual module but don't have voutput");
1566 free(output_commit_handler);
1567 return TDM_ERROR_BAD_MODULE;
1571 ret = tdm_thread_cb_add(private_output, TDM_THREAD_CB_OUTPUT_COMMIT, output_commit_handler, _tdm_output_thread_cb_commit, NULL);
1572 if (ret != TDM_ERROR_NONE) {
1573 TDM_ERR("tdm_thread_cb_add failed");
1574 free(output_commit_handler);
1578 LIST_ADDTAIL(&output_commit_handler->link, &private_output->output_commit_handler_list);
1579 output_commit_handler->private_output = private_output;
1580 output_commit_handler->func = func;
1581 output_commit_handler->user_data = user_data;
1582 output_commit_handler->owner_tid = syscall(SYS_gettid);
1584 if (private_module == private_display->virtual_module) {
1585 private_voutput = private_output->private_voutput;
1587 /* voutput use only 1 layer */
1588 private_layer = LIST_FIRST_ENTRY(&private_output->layer_list, tdm_private_layer, link);
1590 if (LIST_LENGTH(&private_voutput->voutput_commit_handler_list) != 0) {
1591 voutput_commit_handler = LIST_FIRST_ENTRY(&private_voutput->voutput_commit_handler_list, tdm_private_voutput_commit_handler, link);
1592 voutput_commit_handler->user_data = private_layer->commiting_buffer;
1596 ret = func_output->output_commit(private_output->output_backend, sync,
1597 output_commit_handler);
1598 TDM_GOTO_IF_FAIL(ret == TDM_ERROR_NONE, commit_failed);
1600 if (tdm_debug_module & TDM_DEBUG_COMMIT)
1601 TDM_INFO("output(%d) backend commit: handle(%p) func(%p) user_data(%p)",
1602 private_output->pipe, output_commit_handler, func, user_data);
1605 /* Even if DPMS is off, committed_buffer should be changed because it will be referred
1606 * for tdm_layer_committed() function.
1608 LIST_FOR_EACH_ENTRY(private_layer, &private_output->layer_list, link) {
1609 if (!private_layer->waiting_buffer)
1612 if (private_layer->committed_buffer) {
1613 tdm_layer_free_buffer(private_layer, private_layer->committed_buffer);
1614 private_layer->committed_buffer = NULL;
1615 if (tdm_debug_module & TDM_DEBUG_BUFFER)
1616 TDM_INFO("layer(%p) waiting_buffer(%p) committed_buffer(%p)",
1617 private_layer, private_layer->waiting_buffer->buffer,
1618 private_layer->committed_buffer);
1621 private_layer->committed_buffer = private_layer->waiting_buffer;
1622 private_layer->waiting_buffer = NULL;
1623 private_layer->commiting_buffer = NULL;
1624 if (tdm_debug_module & TDM_DEBUG_BUFFER)
1625 TDM_INFO("layer(%p) waiting_buffer(%p) committed_buffer(%p)",
1626 private_layer, private_layer->waiting_buffer,
1627 private_layer->committed_buffer->buffer);
1630 if (TDM_OUTPUT_DPMS_VSYNC_IS_OFF(dpms_value)) {
1631 TDM_WRN("dpms %s. Directly call commit handler instead of commit.", tdm_dpms_str(dpms_value));
1633 func(output, 0, 0, 0, user_data);
1639 /* LCOV_EXCL_START */
1640 if (output_commit_handler) {
1641 tdm_thread_cb_remove(private_output, TDM_THREAD_CB_OUTPUT_COMMIT, output_commit_handler, _tdm_output_thread_cb_commit, NULL);
1642 LIST_DEL(&output_commit_handler->link);
1643 free(output_commit_handler);
1647 /* LCOV_EXCL_STOP */
1651 tdm_output_commit(tdm_output *output, int sync, tdm_output_commit_handler func,
1654 tdm_private_layer *private_layer = NULL;
1656 OUTPUT_FUNC_ENTRY();
1658 _pthread_mutex_lock(&private_display->lock);
1660 if (private_output->commit_type == TDM_COMMIT_TYPE_NONE)
1661 private_output->commit_type = TDM_COMMIT_TYPE_OUTPUT;
1662 else if (private_output->commit_type == TDM_COMMIT_TYPE_LAYER) {
1663 TDM_ERR("Can't supported. Use tdm_layer_commit");
1664 _pthread_mutex_unlock(&private_display->lock);
1665 return TDM_ERROR_BAD_REQUEST;
1668 if (private_output->commit_per_vblank) {
1669 TDM_ERR("Use tdm_layer_commit");
1670 _pthread_mutex_unlock(&private_display->lock);
1671 return TDM_ERROR_BAD_REQUEST;
1674 if (TDM_OUTPUT_DPMS_VSYNC_IS_OFF(private_output->current_dpms_value)) {
1675 TDM_ERR("output(%d) dpms: %s", private_output->pipe,
1676 tdm_dpms_str(private_output->current_dpms_value));
1677 _pthread_mutex_unlock(&private_display->lock);
1678 return TDM_ERROR_DPMS_OFF;
1681 if (tdm_debug_module & TDM_DEBUG_COMMIT)
1682 TDM_INFO("output(%d) commit", private_output->pipe);
1684 /* apply the pending data of all layers */
1685 LIST_FOR_EACH_ENTRY(private_layer, &private_output->layer_list, link) {
1686 tdm_layer_commit_pending_data(private_layer);
1689 ret = tdm_output_commit_internal(output, sync, func, user_data);
1691 _pthread_mutex_unlock(&private_display->lock);
1697 tdm_output_set_mode(tdm_output *output, const tdm_output_mode *mode)
1699 tdm_private_module *private_module;
1700 tdm_func_output *func_output;
1701 OUTPUT_FUNC_ENTRY();
1703 TDM_RETURN_VAL_IF_FAIL(mode != NULL, TDM_ERROR_INVALID_PARAMETER);
1705 _pthread_mutex_lock(&private_display->lock);
1707 private_module = private_output->private_module;
1708 func_output = &private_module->func_output;
1710 if (!func_output->output_set_mode) {
1711 /* LCOV_EXCL_START */
1712 _pthread_mutex_unlock(&private_display->lock);
1713 TDM_WRN("not implemented!!");
1714 return TDM_ERROR_NOT_IMPLEMENTED;
1715 /* LCOV_EXCL_STOP */
1718 ret = func_output->output_set_mode(private_output->output_backend, mode);
1719 if (ret == TDM_ERROR_NONE) {
1720 private_output->current_mode = mode;
1721 private_output->need_set_target_info = 1;
1722 TDM_INFO("mode: %dx%d %dhz", mode->hdisplay, mode->vdisplay, mode->vrefresh);
1725 _pthread_mutex_unlock(&private_display->lock);
1731 tdm_output_get_mode(tdm_output *output, const tdm_output_mode **mode)
1733 OUTPUT_FUNC_ENTRY();
1735 TDM_RETURN_VAL_IF_FAIL(mode != NULL, TDM_ERROR_INVALID_PARAMETER);
1737 _pthread_mutex_lock(&private_display->lock);
1739 *mode = private_output->current_mode;
1741 _pthread_mutex_unlock(&private_display->lock);
1747 tdm_output_set_dpms(tdm_output *output, tdm_output_dpms dpms_value)
1749 tdm_private_module *private_module;
1750 tdm_func_output *func_output;
1751 OUTPUT_FUNC_ENTRY();
1753 if (dpms_value > TDM_OUTPUT_DPMS_OFF) {
1754 if (dpms_value & TDM_OUTPUT_DPMS_DEFAULT_MASK) {
1755 TDM_ERR("Don't use the low-4bit for an extended DPMS mode: dpms_value(%x)", dpms_value);
1756 return TDM_ERROR_BAD_REQUEST;
1759 if (!(private_output->caps.capabilities & TDM_OUTPUT_CAPABILITY_EXTENDED_DPMS)) {
1760 TDM_ERR("output(%d) doesn't support the extended DPMS control: '%s'",
1761 private_output->pipe, tdm_dpms_str(dpms_value));
1762 return TDM_ERROR_BAD_REQUEST;
1766 _pthread_mutex_lock(&private_display->lock);
1768 if (private_output->waiting_dpms_change) {
1769 TDM_ERR("DPMS is not changed yet. Can't be changed twice");
1770 _pthread_mutex_unlock(&private_display->lock);
1771 return TDM_ERROR_BAD_REQUEST;
1774 private_module = private_output->private_module;
1775 func_output = &private_module->func_output;
1777 TDM_INFO("output(%d) dpms '%s'", private_output->pipe, tdm_dpms_str(dpms_value));
1779 if (func_output->output_set_dpms)
1780 ret = func_output->output_set_dpms(private_output->output_backend, dpms_value);
1782 /* LCOV_EXCL_START */
1783 ret = TDM_ERROR_NONE;
1784 TDM_WRN("not implemented!!");
1786 /* LCOV_EXCL_STOP */
1790 if (ret == TDM_ERROR_NONE) {
1791 if (private_output->current_dpms_value != dpms_value) {
1792 private_output->current_dpms_value = dpms_value;
1793 _tdm_output_call_thread_cb_dpms(private_output, dpms_value);
1795 TDM_INFO("output(%d) dpms '%s' done", private_output->pipe, tdm_dpms_str(dpms_value));
1797 tdm_output_dpms temp = TDM_OUTPUT_DPMS_OFF;
1799 /* update current_dpms_value forcely */
1800 tdm_output_get_dpms_internal(output, &temp);
1802 TDM_ERR("output(%d) set_dpms failed: dpms '%s'", private_output->pipe, tdm_dpms_str(temp));
1805 _pthread_mutex_unlock(&private_display->lock);
1810 /* LCOV_EXCL_START */
1812 tdm_output_set_dpms_async(tdm_output *output, tdm_output_dpms dpms_value)
1814 tdm_private_module *private_module;
1815 tdm_func_output *func_output;
1816 OUTPUT_FUNC_ENTRY();
1818 if (!(private_output->caps.capabilities & TDM_OUTPUT_CAPABILITY_ASYNC_DPMS)) {
1819 TDM_ERR("output doesn't support the asynchronous DPMS control!");
1820 return TDM_ERROR_BAD_REQUEST;
1823 if (dpms_value > TDM_OUTPUT_DPMS_OFF) {
1824 if (dpms_value & TDM_OUTPUT_DPMS_DEFAULT_MASK) {
1825 TDM_ERR("Don't use the low-4bit for an extended DPMS mode: dpms_value(%x)", dpms_value);
1826 return TDM_ERROR_BAD_REQUEST;
1829 if (!(private_output->caps.capabilities & TDM_OUTPUT_CAPABILITY_EXTENDED_DPMS)) {
1830 TDM_ERR("output(%d) doesn't support the extended DPMS control: '%s'",
1831 private_output->pipe, tdm_dpms_str(dpms_value));
1832 return TDM_ERROR_BAD_REQUEST;
1836 _pthread_mutex_lock(&private_display->lock);
1838 if (private_output->waiting_dpms_change) {
1839 TDM_ERR("DPMS is not changed yet. Can't be changed twice");
1840 _pthread_mutex_unlock(&private_display->lock);
1841 return TDM_ERROR_BAD_REQUEST;
1844 private_module = private_output->private_module;
1845 func_output = &private_module->func_output;
1846 if (!func_output->output_set_dpms_handler) {
1847 TDM_WRN("not implemented: output_set_dpms_handler");
1848 _pthread_mutex_unlock(&private_display->lock);
1849 return TDM_ERROR_NOT_IMPLEMENTED;
1852 if (!func_output->output_set_dpms_async) {
1853 TDM_WRN("not implemented: output_set_dpms_async");
1854 _pthread_mutex_unlock(&private_display->lock);
1855 return TDM_ERROR_NOT_IMPLEMENTED;
1858 if (!private_output->regist_dpms_cb) {
1859 private_output->regist_dpms_cb = 1;
1860 ret = func_output->output_set_dpms_handler(private_output->output_backend,
1861 tdm_output_cb_dpms, private_output);
1862 if (ret != TDM_ERROR_NONE) {
1863 _pthread_mutex_unlock(&private_display->lock);
1864 TDM_ERR("Can't set the dpms handler!!");
1869 TDM_INFO("output(%d) dpms async '%s'", private_output->pipe, tdm_dpms_str(dpms_value));
1871 ret = func_output->output_set_dpms_async(private_output->output_backend, dpms_value);
1873 if (ret == TDM_ERROR_NONE) {
1874 private_output->waiting_dpms_change = 1;
1875 TDM_INFO("output(%d) dpms async '%s' waiting", private_output->pipe, tdm_dpms_str(dpms_value));
1877 tdm_output_dpms temp = TDM_OUTPUT_DPMS_OFF;
1879 /* update current_dpms_value forcely */
1880 tdm_output_get_dpms_internal(output, &temp);
1882 TDM_ERR("output(%d) set_dpms_async failed: dpms '%s'", private_output->pipe, tdm_dpms_str(temp));
1885 _pthread_mutex_unlock(&private_display->lock);
1889 /* LCOV_EXCL_STOP */
1892 tdm_output_get_dpms_internal(tdm_output *output, tdm_output_dpms *dpms_value)
1894 tdm_private_output *private_output;
1895 tdm_private_module *private_module;
1896 tdm_func_output *func_output;
1897 tdm_error ret = TDM_ERROR_NONE;
1899 TDM_RETURN_VAL_IF_FAIL(output != NULL, TDM_ERROR_INVALID_PARAMETER);
1901 private_output = (tdm_private_output*)output;
1903 /* TODO: this is ugly. But before calling backend's output_get_dpms(), we have
1904 * to check if all backends's DPMS operation has no problem. In future, we'd
1905 * better use new env instead of using commit_per_vblank variable to distinguish
1906 * whether we use the stored value or backend's output_get_dpms.
1908 if (!private_output->commit_per_vblank) {
1909 *dpms_value = private_output->current_dpms_value;
1910 return TDM_ERROR_NONE;
1913 private_module = private_output->private_module;
1914 func_output = &private_module->func_output;
1916 if (!func_output->output_get_dpms) {
1917 /* LCOV_EXCL_START */
1918 *dpms_value = private_output->current_dpms_value;
1919 TDM_WRN("not implemented!!");
1920 return TDM_ERROR_NONE;
1921 /* LCOV_EXCL_STOP */
1924 ret = func_output->output_get_dpms(private_output->output_backend, dpms_value);
1925 if (ret != TDM_ERROR_NONE) {
1926 /* LCOV_EXCL_START */
1927 TDM_ERR("output_get_dpms failed");
1928 *dpms_value = TDM_OUTPUT_DPMS_OFF;
1929 /* LCOV_EXCL_STOP */
1932 /* checking with backend's value */
1933 if (*dpms_value != private_output->current_dpms_value) {
1934 TDM_ERR("output(%d) dpms changed suddenly: %s -> %s",
1935 private_output->pipe, tdm_dpms_str(private_output->current_dpms_value),
1936 tdm_dpms_str(*dpms_value));
1937 private_output->current_dpms_value = *dpms_value;
1938 _tdm_output_call_thread_cb_dpms(private_output, *dpms_value);
1945 tdm_output_get_dpms(tdm_output *output, tdm_output_dpms *dpms_value)
1947 OUTPUT_FUNC_ENTRY();
1949 TDM_RETURN_VAL_IF_FAIL(dpms_value != NULL, TDM_ERROR_INVALID_PARAMETER);
1951 _pthread_mutex_lock(&private_display->lock);
1953 ret = tdm_output_get_dpms_internal(output, dpms_value);
1955 _pthread_mutex_unlock(&private_display->lock);
1961 tdm_output_has_capture_capability(tdm_output *output, unsigned int *has_capability)
1963 tdm_private_module *private_module;
1965 OUTPUT_FUNC_ENTRY();
1967 TDM_RETURN_VAL_IF_FAIL(has_capability != NULL, TDM_ERROR_INVALID_PARAMETER);
1969 _pthread_mutex_lock(&private_display->lock);
1971 private_module = private_output->private_module;
1973 if (!(private_module->capabilities & TDM_DISPLAY_CAPABILITY_CAPTURE))
1974 *has_capability = 0;
1975 else if (!(private_module->caps_capture.capabilities & TDM_CAPTURE_CAPABILITY_OUTPUT))
1976 *has_capability = 0;
1978 *has_capability = 1;
1980 _pthread_mutex_unlock(&private_display->lock);
1985 EXTERN tdm_capture *
1986 tdm_output_create_capture(tdm_output *output, tdm_error *error)
1988 tdm_capture *capture = NULL;
1990 OUTPUT_FUNC_ENTRY_ERROR();
1992 _pthread_mutex_lock(&private_display->lock);
1994 capture = (tdm_capture *)tdm_capture_create_output_internal(private_output, error);
1996 _pthread_mutex_unlock(&private_display->lock);
2002 tdm_output_get_hwc(tdm_output *output, tdm_error *error)
2004 tdm_private_hwc *private_hwc = NULL;
2006 OUTPUT_FUNC_ENTRY_ERROR();
2008 _pthread_mutex_lock(&private_display->lock);
2010 private_hwc = private_output->private_hwc;
2013 *error = TDM_ERROR_BAD_REQUEST;
2014 _pthread_mutex_unlock(&private_display->lock);
2019 *error = TDM_ERROR_NONE;
2021 _pthread_mutex_unlock(&private_display->lock);
2027 tdm_output_choose_commit_per_vblank_mode(tdm_private_output *private_output, int mode)
2029 if (!private_output)
2030 return TDM_ERROR_INVALID_PARAMETER;
2032 if (mode < 0 || mode > 2)
2033 return TDM_ERROR_INVALID_PARAMETER;
2035 private_output->commit_per_vblank = mode;
2037 if (private_output->commit_per_vblank == 0)
2038 TDM_INFO("commit per vblank: disable");
2039 else if (private_output->commit_per_vblank == 1)
2040 TDM_INFO("commit per vblank: enable (1 layer)");
2041 else if (private_output->commit_per_vblank == 2)
2042 TDM_INFO("commit per vblank: enable (previous commit)");
2044 return TDM_ERROR_NONE;
2047 INTERN tdm_voutput *
2048 tdm_voutput_create(tdm_display *dpy, const char *name, tdm_error *error)
2050 tdm_private_module *private_module = NULL;
2051 tdm_private_module *current_module = NULL;
2052 tdm_private_voutput *private_voutput = NULL;
2053 tdm_private_output *private_output = NULL;
2054 tdm_func_display *func_display = NULL;
2055 tdm_func_voutput *func_voutput = NULL;
2056 tdm_voutput *voutput_backend = NULL;
2057 tdm_output *output_backend = NULL;
2058 int output_find = 0;
2059 tdm_private_display *private_display;
2060 tdm_error ret = TDM_ERROR_NONE;
2062 TDM_RETURN_VAL_IF_FAIL_WITH_ERROR(dpy != NULL, TDM_ERROR_INVALID_PARAMETER, NULL);
2063 private_display = (tdm_private_display*)dpy;
2064 private_module = private_display->virtual_module;
2065 TDM_RETURN_VAL_IF_FAIL_WITH_ERROR(private_module != NULL, TDM_ERROR_BAD_MODULE, NULL);
2067 _pthread_mutex_lock(&private_display->lock);
2069 if (error) *error = TDM_ERROR_NONE;
2071 private_voutput = calloc(1, sizeof(tdm_private_voutput));
2072 if (!private_voutput) {
2073 if (error) *error = TDM_ERROR_OUT_OF_MEMORY;
2074 _pthread_mutex_unlock(&private_display->lock);
2078 func_display = &private_module->func_display;
2079 func_voutput = &private_module->func_voutput;
2080 current_module = private_display->current_module;
2081 private_display->current_module = private_module;
2083 voutput_backend = func_display->voutput_create(private_module->bdata, name, &ret);
2085 if (voutput_backend == NULL || ret != TDM_ERROR_NONE) {
2086 TDM_ERR("voutput_create fail");
2087 free(private_voutput);
2088 if (error) *error = ret;
2089 private_display->current_module = current_module;
2090 _pthread_mutex_unlock(&private_display->lock);
2093 private_voutput->voutput_backend = voutput_backend;
2094 private_voutput->private_display = private_display;
2095 private_voutput->private_module = private_module;
2096 LIST_INITHEAD(&private_voutput->voutput_commit_handler_list);
2098 output_backend = func_voutput->voutput_get_output(voutput_backend, &ret);
2099 if (output_backend == NULL || ret != TDM_ERROR_NONE) {
2100 TDM_ERR("voutput_get_output fail");
2101 free(private_voutput);
2102 if (error) *error = ret;
2103 if (func_voutput->voutput_destroy)
2104 func_voutput->voutput_destroy(voutput_backend);
2106 TDM_ERR("no destroy function");
2107 private_display->current_module = current_module;
2108 _pthread_mutex_unlock(&private_display->lock);
2112 ret = tdm_display_update_output(private_display->current_module, output_backend);
2113 if (ret != TDM_ERROR_NONE) {
2114 TDM_ERR("tdm_display_update_output fail");
2115 free(private_voutput);
2116 if (func_voutput->voutput_destroy)
2117 func_voutput->voutput_destroy(voutput_backend);
2119 TDM_ERR("no destroy function");
2120 if (error) *error = ret;
2121 private_display->current_module = current_module;
2122 _pthread_mutex_unlock(&private_display->lock);
2126 LIST_FOR_EACH_ENTRY(private_output, &private_module->output_list, link) {
2127 if (private_output->output_backend == output_backend) {
2133 if (output_find != 1) {
2134 private_output = NULL;
2135 free(private_voutput);
2136 if (func_voutput->voutput_destroy)
2137 func_voutput->voutput_destroy(voutput_backend);
2139 TDM_ERR("no destroy function");
2140 private_voutput = NULL;
2142 strncpy(private_voutput->name, name, TDM_NAME_LEN - 1);
2143 private_voutput->name[TDM_NAME_LEN - 1] = '\0';
2144 strncpy(private_output->name, name, TDM_NAME_LEN - 1);
2145 private_output->name[TDM_NAME_LEN - 1] = '\0';
2147 private_voutput->private_output = private_output;
2148 private_output->private_voutput = private_voutput;
2150 /* do not use vblank */
2151 tdm_output_choose_commit_per_vblank_mode(private_output, 0);
2153 LIST_ADDTAIL(&private_voutput->link, &private_module->voutput_list);
2156 private_display->current_module = current_module;
2158 _pthread_mutex_unlock(&private_display->lock);
2160 return private_voutput;
2164 tdm_voutput_destroy(tdm_voutput *voutput)
2166 tdm_private_module *private_module = NULL;
2167 tdm_voutput *voutput_backend = NULL;
2168 tdm_func_voutput *func_voutput = NULL;
2170 tdm_private_display *private_display;
2171 tdm_private_voutput *private_voutput;
2172 tdm_private_output *private_output;
2173 tdm_error ret = TDM_ERROR_NONE;
2174 TDM_RETURN_VAL_IF_FAIL(voutput != NULL, TDM_ERROR_INVALID_PARAMETER);
2175 private_voutput = (tdm_private_voutput*)voutput;
2176 private_display = private_voutput->private_display;
2177 private_module = private_voutput->private_module;
2178 TDM_RETURN_VAL_IF_FAIL(private_module == private_display->virtual_module, TDM_ERROR_BAD_MODULE);
2180 _pthread_mutex_lock(&private_display->lock);
2182 func_voutput = &private_module->func_voutput;
2183 voutput_backend = private_voutput->voutput_backend;
2184 private_output = private_voutput->private_output;
2185 tdm_display_destroy_private_output(private_output);
2186 LIST_DEL(&private_voutput->link);
2187 free(private_voutput);
2188 if (func_voutput->voutput_destroy)
2189 ret = func_voutput->voutput_destroy(voutput_backend);
2191 _pthread_mutex_unlock(&private_display->lock);
2197 tdm_voutput_set_available_mode(tdm_voutput *voutput, const tdm_output_mode *modes, int count)
2199 tdm_private_display *private_display;
2200 tdm_private_module *private_module = NULL;
2201 tdm_private_voutput *private_voutput;
2202 tdm_func_voutput *func_voutput = NULL;
2203 tdm_error ret = TDM_ERROR_NONE;
2205 TDM_RETURN_VAL_IF_FAIL(voutput != NULL, TDM_ERROR_INVALID_PARAMETER);
2206 TDM_RETURN_VAL_IF_FAIL(modes != NULL, TDM_ERROR_INVALID_PARAMETER);
2207 TDM_RETURN_VAL_IF_FAIL(count != 0, TDM_ERROR_INVALID_PARAMETER);
2209 private_voutput = (tdm_private_voutput*)voutput;
2210 private_display = private_voutput->private_display;
2211 private_module = private_voutput->private_module;
2212 TDM_RETURN_VAL_IF_FAIL(private_module == private_display->virtual_module, TDM_ERROR_BAD_MODULE);
2214 _pthread_mutex_lock(&private_display->lock);
2216 func_voutput = &private_module->func_voutput;
2217 if (func_voutput->voutput_set_available_mode)
2218 ret = func_voutput->voutput_set_available_mode(private_voutput->voutput_backend, modes, count);
2220 ret = TDM_ERROR_NOT_IMPLEMENTED;
2222 _pthread_mutex_unlock(&private_display->lock);
2228 tdm_voutput_set_physical_size(tdm_voutput *voutput, unsigned int mmwidth, unsigned int mmheight)
2230 tdm_private_display *private_display;
2231 tdm_private_module *private_module = NULL;
2232 tdm_private_voutput *private_voutput;
2233 tdm_func_voutput *func_voutput = NULL;
2234 tdm_error ret = TDM_ERROR_NONE;
2236 TDM_RETURN_VAL_IF_FAIL(voutput != NULL, TDM_ERROR_INVALID_PARAMETER);
2237 TDM_RETURN_VAL_IF_FAIL(mmwidth != 0, TDM_ERROR_INVALID_PARAMETER);
2238 TDM_RETURN_VAL_IF_FAIL(mmheight != 0, TDM_ERROR_INVALID_PARAMETER);
2240 private_voutput = (tdm_private_voutput*)voutput;
2241 private_display = private_voutput->private_display;
2242 private_module = private_voutput->private_module;
2243 TDM_RETURN_VAL_IF_FAIL(private_module == private_display->virtual_module, TDM_ERROR_BAD_MODULE);
2245 _pthread_mutex_lock(&private_display->lock);
2247 func_voutput = &private_module->func_voutput;
2248 if (func_voutput->voutput_set_physical_size)
2249 ret = func_voutput->voutput_set_physical_size(private_voutput->voutput_backend, mmwidth, mmheight);
2251 ret = TDM_ERROR_NOT_IMPLEMENTED;
2253 _pthread_mutex_unlock(&private_display->lock);
2259 tdm_voutput_connect(tdm_voutput *voutput)
2261 tdm_private_display *private_display;
2262 tdm_private_module *private_module = NULL;
2263 tdm_private_voutput *private_voutput;
2264 tdm_func_voutput *func_voutput = NULL;
2265 tdm_error ret = TDM_ERROR_NONE;
2267 TDM_RETURN_VAL_IF_FAIL(voutput != NULL, TDM_ERROR_INVALID_PARAMETER);
2269 private_voutput = (tdm_private_voutput*)voutput;
2270 private_display = private_voutput->private_display;
2271 private_module = private_voutput->private_module;
2272 TDM_RETURN_VAL_IF_FAIL(private_module == private_display->virtual_module, TDM_ERROR_BAD_MODULE);
2274 _pthread_mutex_lock(&private_display->lock);
2276 func_voutput = &private_module->func_voutput;
2277 if (func_voutput->voutput_connect)
2278 ret = func_voutput->voutput_connect(private_voutput->voutput_backend);
2280 ret = TDM_ERROR_NOT_IMPLEMENTED;
2282 _pthread_mutex_unlock(&private_display->lock);
2288 tdm_voutput_disconnect(tdm_voutput *voutput)
2290 tdm_private_display *private_display;
2291 tdm_private_module *private_module = NULL;
2292 tdm_private_voutput *private_voutput;
2293 tdm_func_voutput *func_voutput = NULL;
2294 tdm_error ret = TDM_ERROR_NONE;
2296 TDM_RETURN_VAL_IF_FAIL(voutput != NULL, TDM_ERROR_INVALID_PARAMETER);
2298 private_voutput = (tdm_private_voutput*)voutput;
2299 private_display = private_voutput->private_display;
2300 private_module = private_voutput->private_module;
2301 TDM_RETURN_VAL_IF_FAIL(private_module == private_display->virtual_module, TDM_ERROR_BAD_MODULE);
2303 _pthread_mutex_lock(&private_display->lock);
2305 func_voutput = &private_module->func_voutput;
2306 if (func_voutput->voutput_disconnect)
2307 ret = func_voutput->voutput_disconnect(private_voutput->voutput_backend);
2309 ret = TDM_ERROR_NOT_IMPLEMENTED;
2311 _pthread_mutex_unlock(&private_display->lock);
2316 /* LCOV_EXCL_START */
2318 tdm_voutput_set_commit_func(tdm_voutput *voutput, tdm_voutput_commit_handler func)
2320 tdm_private_display *private_display;
2321 tdm_private_module *private_module = NULL;
2322 tdm_private_voutput *private_voutput;
2323 tdm_func_voutput *func_voutput = NULL;
2324 tdm_error ret = TDM_ERROR_NONE;
2326 TDM_RETURN_VAL_IF_FAIL(voutput != NULL, TDM_ERROR_INVALID_PARAMETER);
2328 private_voutput = (tdm_private_voutput*)voutput;
2329 private_display = private_voutput->private_display;
2330 private_module = private_voutput->private_module;
2331 TDM_RETURN_VAL_IF_FAIL(private_module == private_display->virtual_module, TDM_ERROR_BAD_MODULE);
2333 func_voutput = &private_module->func_voutput;
2334 if (func_voutput->voutput_set_commit_func)
2335 ret = func_voutput->voutput_set_commit_func(private_voutput->voutput_backend, func);
2337 ret = TDM_ERROR_NOT_IMPLEMENTED;
2343 tdm_voutput_commit_done(tdm_voutput *voutput)
2345 tdm_private_display *private_display;
2346 tdm_private_module *private_module = NULL;
2347 tdm_private_voutput *private_voutput;
2348 tdm_func_voutput *func_voutput = NULL;
2349 tdm_error ret = TDM_ERROR_NONE;
2351 TDM_RETURN_VAL_IF_FAIL(voutput != NULL, TDM_ERROR_INVALID_PARAMETER);
2353 private_voutput = (tdm_private_voutput*)voutput;
2354 private_display = private_voutput->private_display;
2355 private_module = private_voutput->private_module;
2356 TDM_RETURN_VAL_IF_FAIL(private_module == private_display->virtual_module, TDM_ERROR_BAD_MODULE);
2358 _pthread_mutex_lock(&private_display->lock);
2360 func_voutput = &private_module->func_voutput;
2361 if (func_voutput->voutput_commit_done)
2362 ret = func_voutput->voutput_commit_done(private_voutput->voutput_backend);
2364 ret = TDM_ERROR_NOT_IMPLEMENTED;
2366 _pthread_mutex_unlock(&private_display->lock);
2370 /* LCOV_EXCL_STOP */