1 /**************************************************************************
5 * Copyright 2018 Samsung Electronics co., Ltd. All Rights Reserved.
7 * Contact: SooChan Lim <sc1.lim@samsung.com>,
8 * Boram Park <boram1288.park@samsung.com>,
9 * Changyeon Lee <cyeon.lee@samsung.com>,
10 * Sangjin Lee <lsj119@samsung.com>
12 * Permission is hereby granted, free of charge, to any person obtaining a
13 * copy of this software and associated documentation files (the
14 * "Software"), to deal in the Software without restriction, including
15 * without limitation the rights to use, copy, modify, merge, publish,
16 * distribute, sub license, and/or sell copies of the Software, and to
17 * permit persons to whom the Software is furnished to do so, subject to
18 * the following conditions:
20 * The above copyright notice and this permission notice (including the
21 * next paragraph) shall be included in all copies or substantial portions
24 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
25 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
26 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
27 * IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR
28 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
29 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
30 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
32 **************************************************************************/
38 #include "tdm_private.h"
40 #define HWC_FUNC_ENTRY() \
41 tdm_private_display *private_display; \
42 tdm_private_output *private_output; \
43 tdm_private_hwc *private_hwc; \
44 tdm_error ret = TDM_ERROR_NONE; /* default TDM_ERROR_NONE */\
45 TDM_RETURN_VAL_IF_FAIL(hwc != NULL, TDM_ERROR_INVALID_PARAMETER); \
46 private_hwc = (tdm_private_hwc*)hwc; \
47 private_output = private_hwc->private_output; \
48 TDM_RETURN_VAL_IF_FAIL(private_output != NULL, TDM_ERROR_INVALID_PARAMETER); \
49 private_display = private_output->private_display
51 #define HWC_FUNC_ENTRY_ERROR() \
52 tdm_private_display *private_display; \
53 tdm_private_output *private_output; \
54 tdm_private_hwc *private_hwc; \
55 tdm_error ret = TDM_ERROR_NONE; /* default TDM_ERROR_NONE */\
56 TDM_RETURN_VAL_IF_FAIL_WITH_ERROR(hwc != NULL, TDM_ERROR_INVALID_PARAMETER, NULL); \
57 private_hwc = (tdm_private_hwc*)hwc; \
58 private_output = private_hwc->private_output; \
59 TDM_RETURN_VAL_IF_FAIL_WITH_ERROR(private_output != NULL, TDM_ERROR_INVALID_PARAMETER, NULL); \
60 private_display = private_output->private_display
62 #define HWC_FUNC_ENTRY_VOID_RETURN() \
63 tdm_private_display *private_display; \
64 tdm_private_output *private_output; \
65 tdm_private_hwc *private_hwc; \
66 tdm_error ret = TDM_ERROR_NONE; /* default TDM_ERROR_NONE */\
67 TDM_RETURN_IF_FAIL(hwc != NULL); \
68 private_hwc = (tdm_private_hwc*)hwc; \
69 private_output = private_hwc->private_output; \
70 TDM_RETURN_IF_FAIL(private_output != NULL); \
71 private_display = private_output->private_display
73 static int hwc_use_vblank;
74 static unsigned int hwc_vblank_fps;
76 static tdm_private_hwc_window *
77 _tdm_hwc_find_private_hwc_window(tdm_private_hwc *private_hwc, tdm_hwc_window *hwc_window_backend)
79 tdm_private_hwc_window *private_hwc_window = NULL;
81 LIST_FOR_EACH_ENTRY(private_hwc_window, &private_hwc->hwc_window_list, link) {
82 if (private_hwc_window->hwc_window_backend == hwc_window_backend)
83 return private_hwc_window;
90 _tdm_hwc_check_hwc_commit_handler_validation(tdm_private_hwc *private_hwc, tdm_private_hwc_commit_handler *hwc_commit_handler)
92 tdm_private_hwc_commit_handler *commit_handler = NULL;
94 if (LIST_IS_EMPTY(&private_hwc->hwc_commit_handler_list))
95 return TDM_ERROR_INVALID_PARAMETER;
97 LIST_FOR_EACH_ENTRY(commit_handler, &private_hwc->hwc_commit_handler_list, link) {
98 if (commit_handler == hwc_commit_handler)
99 return TDM_ERROR_NONE;
102 return TDM_ERROR_INVALID_PARAMETER;
106 _tdm_hwc_thread_cb_commit(tdm_private_display *private_display, void *object,
107 tdm_thread_cb_base *cb_base, void *user_data)
109 tdm_thread_cb_hwc_commit *hwc_commit = (tdm_thread_cb_hwc_commit *)cb_base;
110 tdm_private_hwc_commit_handler *hwc_commit_handler = hwc_commit->base.data;
111 tdm_private_hwc *private_hwc = object;
113 TDM_RETURN_IF_FAIL(TDM_MUTEX_IS_LOCKED());
115 if (!hwc_commit_handler)
118 assert(hwc_commit_handler->owner_tid == syscall(SYS_gettid));
120 tdm_thread_cb_remove(private_hwc, TDM_THREAD_CB_HWC_COMMIT, hwc_commit_handler,
121 _tdm_hwc_thread_cb_commit, NULL);
123 TDM_RETURN_IF_FAIL(_tdm_hwc_check_hwc_commit_handler_validation(private_hwc, hwc_commit_handler) == TDM_ERROR_NONE)
125 LIST_DEL(&hwc_commit_handler->link);
127 if (tdm_debug_module & TDM_DEBUG_COMMIT) {
128 TDM_INFO("----------------------------------------- hwc(%d) committed", private_hwc->index);
129 TDM_INFO("handler(%p)", hwc_commit_handler);
132 /* LCOV_EXCL_START */
133 if (private_display->print_fps) {
134 double curr = tdm_helper_get_time();
135 if (private_hwc->fps_stamp == 0) {
136 private_hwc->fps_stamp = curr;
137 } else if ((curr - private_hwc->fps_stamp) > 1.0) {
138 TDM_INFO("hwc(%p,%d) fps: %d",
139 private_hwc, private_hwc->index, private_hwc->fps_count);
140 private_hwc->fps_count = 0;
141 private_hwc->fps_stamp = curr;
143 private_hwc->fps_count++;
144 } else if (private_hwc->fps_stamp != 0) {
145 private_hwc->fps_stamp = 0;
146 private_hwc->fps_count = 0;
150 if (hwc_commit_handler->func) {
151 _pthread_mutex_unlock(&private_display->lock);
152 hwc_commit_handler->func(private_hwc,
153 hwc_commit->sequence,
156 hwc_commit_handler->user_data);
157 _pthread_mutex_lock(&private_display->lock);
160 free(hwc_commit_handler);
162 if (tdm_debug_module & TDM_DEBUG_COMMIT)
163 TDM_INFO("-----------------------------------------...");
167 _tdm_hwc_cb_commit(tdm_hwc *hwc_backend, unsigned int sequence,
168 unsigned int tv_sec, unsigned int tv_usec, void *user_data)
170 tdm_private_hwc_commit_handler *hwc_commit_handler = user_data;
171 tdm_private_hwc *private_hwc;
172 tdm_thread_cb_hwc_commit hwc_commit;
175 if (hwc_commit_handler && hwc_commit_handler->use_vblank)
178 if (hwc_commit_handler)
179 private_hwc = hwc_commit_handler->private_hwc;
181 private_hwc = tdm_display_find_private_hwc(tdm_display_get(), hwc_backend);
183 memset(&hwc_commit, 0, sizeof hwc_commit);
184 hwc_commit.base.type = TDM_THREAD_CB_HWC_COMMIT;
185 hwc_commit.base.length = sizeof hwc_commit;
186 hwc_commit.base.object_stamp = private_hwc->stamp;
187 hwc_commit.base.data = hwc_commit_handler;
188 hwc_commit.base.sync = 0;
189 hwc_commit.sequence = sequence;
190 hwc_commit.tv_sec = tv_sec;
191 hwc_commit.tv_usec = tv_usec;
193 ret = tdm_thread_cb_call(private_hwc, &hwc_commit.base, 1);
194 TDM_WARNING_IF_FAIL(ret == TDM_ERROR_NONE);
197 /* LCOV_EXCL_START */
199 _tdm_hwc_got_wait_vblank(unsigned int sequence,
200 unsigned int tv_sec, unsigned int tv_usec, void *user_data)
202 tdm_private_hwc_commit_handler *hwc_commit_handler = user_data;
203 tdm_private_hwc *private_hwc;
204 tdm_thread_cb_hwc_commit hwc_commit;
206 private_hwc = hwc_commit_handler->private_hwc;
207 private_hwc->private_output->layer_waiting_vblank = 0;
209 memset(&hwc_commit, 0, sizeof hwc_commit);
210 hwc_commit.base.type = TDM_THREAD_CB_HWC_COMMIT;
211 hwc_commit.base.length = sizeof hwc_commit;
212 hwc_commit.base.object_stamp = private_hwc->stamp;
213 hwc_commit.base.data = hwc_commit_handler;
214 hwc_commit.base.sync = 0;
215 hwc_commit.sequence = sequence;
216 hwc_commit.tv_sec = tv_sec;
217 hwc_commit.tv_usec = tv_usec;
219 _tdm_hwc_thread_cb_commit(private_hwc->private_output->private_display, private_hwc, &hwc_commit.base, user_data);
223 _tdm_hwc_cb_wait_vblank(tdm_vblank *vblank, tdm_error error, unsigned int sequence,
224 unsigned int tv_sec, unsigned int tv_usec, void *user_data)
226 tdm_private_hwc_commit_handler *hwc_commit_handler = user_data;
227 tdm_private_output *private_output = NULL;
228 tdm_private_display *private_display;
230 if (!hwc_commit_handler->use_vblank)
233 TDM_RETURN_IF_FAIL(hwc_commit_handler != NULL);
234 TDM_RETURN_IF_FAIL(hwc_commit_handler->private_hwc != NULL);
236 private_output = hwc_commit_handler->private_hwc->private_output;
237 TDM_RETURN_IF_FAIL(private_output != NULL);
239 private_display = private_output->private_display;
241 _pthread_mutex_lock(&private_display->lock);
243 _tdm_hwc_got_wait_vblank(sequence, tv_sec, tv_usec, user_data);
245 _pthread_mutex_unlock(&private_display->lock);
249 _tdm_hwc_vblank(tdm_private_hwc *private_hwc, tdm_private_hwc_commit_handler *hwc_commit_handler)
251 tdm_private_display *private_display;
252 tdm_private_output *private_output;
253 tdm_error ret = TDM_ERROR_NONE;
255 private_output = private_hwc->private_output;
256 TDM_RETURN_VAL_IF_FAIL(private_output != NULL, TDM_ERROR_INVALID_PARAMETER);
257 private_display = private_output->private_display;
259 if (!private_output->vblank) {
260 /* tdm_vblank APIs is for server. it should be called in unlock status*/
261 _pthread_mutex_unlock(&private_display->lock);
262 private_output->vblank = tdm_vblank_create(private_display, private_output, NULL);
263 _pthread_mutex_lock(&private_display->lock);
264 TDM_RETURN_VAL_IF_FAIL(private_output->vblank != NULL, TDM_ERROR_OPERATION_FAILED);
267 if (!private_output->layer_waiting_vblank) {
268 ret = tdm_vblank_set_fps(private_output->vblank, hwc_vblank_fps);
269 if (ret != TDM_ERROR_NONE)
272 private_output->layer_waiting_vblank = 1;
274 /* tdm_vblank APIs is for server. it should be called in unlock status*/
275 _pthread_mutex_unlock(&private_display->lock);
276 ret = tdm_vblank_wait(private_output->vblank, 0, 0, 1, _tdm_hwc_cb_wait_vblank, hwc_commit_handler);
277 _pthread_mutex_lock(&private_display->lock);
278 if (ret != TDM_ERROR_NONE) {
279 if (!TDM_OUTPUT_DPMS_VSYNC_IS_OFF(private_output->current_dpms_value)) {
280 private_output->layer_waiting_vblank = 0;
291 tdm_hwc_init(tdm_private_display *private_display)
293 tdm_thread_cb_set_find_func(TDM_THREAD_CB_HWC_COMMIT, tdm_display_find_hwc_stamp);
295 return TDM_ERROR_NONE;
299 tdm_hwc_set_vblank(unsigned int fps)
302 hwc_vblank_fps = fps;
306 tdm_hwc_unset_vblank(void)
312 EXTERN tdm_hwc_window *
313 tdm_hwc_create_window(tdm_hwc *hwc, tdm_error *error)
315 tdm_hwc_window *hwc_window = NULL;
317 HWC_FUNC_ENTRY_ERROR();
319 _pthread_mutex_lock(&private_display->lock);
321 hwc_window = (tdm_hwc_window *)tdm_hwc_window_create_internal(private_hwc, error);
323 _pthread_mutex_unlock(&private_display->lock);
329 tdm_hwc_get_video_supported_formats(tdm_hwc *hwc, const tbm_format **formats, int *count)
331 tdm_private_module *private_module;
332 tdm_func_hwc *func_hwc;
336 TDM_RETURN_VAL_IF_FAIL(formats != NULL, TDM_ERROR_INVALID_PARAMETER);
337 TDM_RETURN_VAL_IF_FAIL(count != NULL, TDM_ERROR_INVALID_PARAMETER);
339 _pthread_mutex_lock(&private_display->lock);
341 private_module = private_output->private_module;
342 func_hwc = &private_module->func_hwc;
344 if (!func_hwc->hwc_get_video_supported_formats) {
345 /* LCOV_EXCL_START */
346 _pthread_mutex_unlock(&private_display->lock);
347 TDM_WRN("not implemented!!");
348 return TDM_ERROR_NOT_IMPLEMENTED;
352 ret = func_hwc->hwc_get_video_supported_formats(private_hwc->hwc_backend, formats, count);
354 _pthread_mutex_unlock(&private_display->lock);
360 tdm_hwc_get_video_available_properties(tdm_hwc *hwc, const tdm_prop **props, int *count)
362 tdm_private_module *private_module;
363 tdm_func_hwc *func_hwc = NULL;
367 TDM_RETURN_VAL_IF_FAIL(props != NULL, TDM_ERROR_INVALID_PARAMETER);
368 TDM_RETURN_VAL_IF_FAIL(count != NULL, TDM_ERROR_INVALID_PARAMETER);
370 _pthread_mutex_lock(&private_display->lock);
372 private_module = private_output->private_module;
373 func_hwc = &private_module->func_hwc;
375 if (!func_hwc->hwc_get_video_available_properties) {
376 /* LCOV_EXCL_START */
377 _pthread_mutex_unlock(&private_display->lock);
378 TDM_WRN("not implemented!!");
379 return TDM_ERROR_NOT_IMPLEMENTED;
383 ret = func_hwc->hwc_get_video_available_properties(private_hwc->hwc_backend, props, count);
385 _pthread_mutex_unlock(&private_display->lock);
391 tdm_hwc_get_capabilities(tdm_hwc *hwc, tdm_hwc_capability *capabilities)
393 tdm_private_module *private_module;
394 tdm_func_hwc *func_hwc;
398 _pthread_mutex_lock(&private_display->lock);
400 private_module = private_output->private_module;
401 func_hwc = &private_module->func_hwc;
403 if (!func_hwc->hwc_get_capabilities) {
404 _pthread_mutex_unlock(&private_display->lock);
405 TDM_WRN("not implemented!!");
406 return TDM_ERROR_NOT_IMPLEMENTED;
409 ret = func_hwc->hwc_get_capabilities(private_hwc->hwc_backend, capabilities);
411 _pthread_mutex_unlock(&private_display->lock);
417 tdm_hwc_get_available_properties(tdm_hwc *hwc, const tdm_prop **props, int *count)
419 tdm_private_module *private_module;
420 tdm_func_hwc *func_hwc = NULL;
424 TDM_RETURN_VAL_IF_FAIL(props != NULL, TDM_ERROR_INVALID_PARAMETER);
425 TDM_RETURN_VAL_IF_FAIL(count != NULL, TDM_ERROR_INVALID_PARAMETER);
427 _pthread_mutex_lock(&private_display->lock);
429 private_module = private_output->private_module;
430 func_hwc = &private_module->func_hwc;
432 if (!func_hwc->hwc_get_available_properties) {
433 /* LCOV_EXCL_START */
434 _pthread_mutex_unlock(&private_display->lock);
435 TDM_WRN("not implemented!!");
436 return TDM_ERROR_NOT_IMPLEMENTED;
440 ret = func_hwc->hwc_get_available_properties(private_hwc->hwc_backend, props, count);
442 _pthread_mutex_unlock(&private_display->lock);
447 EXTERN tbm_surface_queue_h
448 tdm_hwc_get_client_target_buffer_queue(tdm_hwc *hwc, tdm_error *error)
450 tdm_private_module *private_module;
451 tdm_func_hwc *func_hwc = NULL;
452 tbm_surface_queue_h queue = NULL;
454 HWC_FUNC_ENTRY_ERROR();
456 _pthread_mutex_lock(&private_display->lock);
458 private_module = private_hwc->private_module;
459 func_hwc = &private_module->func_hwc;
461 if (!func_hwc->hwc_get_client_target_buffer_queue) {
462 /* LCOV_EXCL_START */
463 _pthread_mutex_unlock(&private_display->lock);
464 TDM_WRN("not implemented!!");
469 queue = func_hwc->hwc_get_client_target_buffer_queue(private_hwc->hwc_backend, error);
471 _pthread_mutex_unlock(&private_display->lock);
477 tdm_hwc_set_client_target_buffer(tdm_hwc *hwc, tbm_surface_h target_buffer, tdm_region damage)
479 tdm_private_module *private_module;
480 tdm_func_hwc *func_hwc = NULL;
484 _pthread_mutex_lock(&private_display->lock);
486 if (tdm_debug_dump & TDM_DUMP_FLAG_WINDOW) {
487 /* LCOV_EXCL_START */
488 char str[TDM_PATH_LEN];
490 snprintf(str, TDM_PATH_LEN, "target_window_%03d", i++);
491 tdm_helper_dump_buffer_str(target_buffer, tdm_debug_dump_dir, str);
495 private_module = private_hwc->private_module;
496 func_hwc = &private_module->func_hwc;
498 if (!func_hwc->hwc_set_client_target_buffer) {
499 /* LCOV_EXCL_START */
500 _pthread_mutex_unlock(&private_display->lock);
501 TDM_WRN("not implemented!!");
502 return TDM_ERROR_NOT_IMPLEMENTED;
506 ret = func_hwc->hwc_set_client_target_buffer(private_hwc->hwc_backend, target_buffer, damage);
508 if (private_hwc->display_target_buffer) {
509 if (private_hwc->display_target_buffer != target_buffer) {
510 tbm_surface_internal_unref(private_hwc->display_target_buffer);
511 private_hwc->display_target_buffer = target_buffer;
513 tbm_surface_internal_ref(private_hwc->display_target_buffer);
517 private_hwc->display_target_buffer = target_buffer;
518 tbm_surface_internal_ref(private_hwc->display_target_buffer);
522 _pthread_mutex_unlock(&private_display->lock);
528 tdm_hwc_set_client_target_acquire_fence(tdm_hwc *hwc, int acquire_fence)
530 tdm_private_module *private_module;
531 tdm_func_hwc *func_hwc = NULL;
535 _pthread_mutex_lock(&private_display->lock);
537 private_module = private_hwc->private_module;
538 func_hwc = &private_module->func_hwc;
540 if (!func_hwc->hwc_set_client_target_acquire_fence) {
541 /* LCOV_EXCL_START */
542 _pthread_mutex_unlock(&private_display->lock);
543 TDM_WRN("not implemented!!");
544 return TDM_ERROR_NOT_IMPLEMENTED;
548 ret = func_hwc->hwc_set_client_target_acquire_fence(private_hwc->hwc_backend, acquire_fence);
550 _pthread_mutex_unlock(&private_display->lock);
556 tdm_hwc_validate(tdm_hwc *hwc, tdm_hwc_window **composited_wnds, uint32_t num_wnds, uint32_t *num_types)
558 tdm_private_module *private_module;
559 tdm_func_hwc *func_hwc = NULL;
560 tdm_private_hwc_window **composited_wnds_frontend = NULL;
561 tdm_hwc_window **composited_wnds_backend = NULL;
566 TDM_RETURN_VAL_IF_FAIL(num_types != NULL, TDM_ERROR_INVALID_PARAMETER);
568 _pthread_mutex_lock(&private_display->lock);
570 private_module = private_hwc->private_module;
571 func_hwc = &private_module->func_hwc;
573 if (!func_hwc->hwc_validate) {
574 /* LCOV_EXCL_START */
575 _pthread_mutex_unlock(&private_display->lock);
576 TDM_WRN("not implemented!!");
577 return TDM_ERROR_NOT_IMPLEMENTED;
582 ret = func_hwc->hwc_validate(private_hwc->hwc_backend, NULL, 0, num_types);
584 _pthread_mutex_unlock(&private_display->lock);
588 composited_wnds_backend = calloc(num_wnds, sizeof(tdm_hwc_window *));
589 if (!composited_wnds_backend) {
590 /* LCOV_EXCL_START */
591 _pthread_mutex_unlock(&private_display->lock);
592 return TDM_ERROR_OUT_OF_MEMORY;
596 composited_wnds_frontend = (tdm_private_hwc_window **)composited_wnds;
598 for (i = 0; i < num_wnds; i++)
599 composited_wnds_backend[i] = composited_wnds_frontend[i]->hwc_window_backend;
601 ret = func_hwc->hwc_validate(private_hwc->hwc_backend, composited_wnds_backend,
602 num_wnds, num_types);
604 free(composited_wnds_backend);
606 _pthread_mutex_unlock(&private_display->lock);
612 tdm_hwc_get_changed_composition_types(tdm_hwc *hwc, uint32_t *num_elements,
613 tdm_hwc_window **hwc_window,
614 tdm_hwc_window_composition *composition_types)
616 tdm_private_module *private_module;
617 tdm_func_hwc *func_hwc = NULL;
618 tdm_private_hwc_window * private_hwc_window = NULL;
623 TDM_RETURN_VAL_IF_FAIL(num_elements != NULL, TDM_ERROR_INVALID_PARAMETER);
625 _pthread_mutex_lock(&private_display->lock);
627 private_module = private_hwc->private_module;
628 func_hwc = &private_module->func_hwc;
630 if (!func_hwc->hwc_get_changed_composition_types) {
631 /* LCOV_EXCL_START */
632 _pthread_mutex_unlock(&private_display->lock);
633 TDM_WRN("not implemented!!");
634 return TDM_ERROR_NOT_IMPLEMENTED;
638 ret = func_hwc->hwc_get_changed_composition_types(private_hwc->hwc_backend,
639 num_elements, hwc_window, composition_types);
640 if (ret != TDM_ERROR_NONE) {
641 /* LCOV_EXCL_START */
642 _pthread_mutex_unlock(&private_display->lock);
647 if (hwc_window == NULL || composition_types == NULL) {
648 _pthread_mutex_unlock(&private_display->lock);
649 return TDM_ERROR_NONE;
652 for (i = 0; i < *num_elements; i++) {
653 private_hwc_window = _tdm_hwc_find_private_hwc_window(private_hwc, hwc_window[i]);
654 if (private_hwc_window == NULL) {
655 /* LCOV_EXCL_START */
656 TDM_ERR("failed! This should never happen!");
657 tdm_hwc_window_destroy_internal(private_hwc_window);
659 _pthread_mutex_unlock(&private_display->lock);
660 return TDM_ERROR_OPERATION_FAILED;
664 hwc_window[i] = (tdm_hwc_window*)private_hwc_window;
667 _pthread_mutex_unlock(&private_display->lock);
673 tdm_hwc_accept_validation(tdm_hwc *hwc)
675 tdm_private_module *private_module;
676 tdm_func_hwc *func_hwc = NULL;
680 _pthread_mutex_lock(&private_display->lock);
682 private_module = private_hwc->private_module;
683 func_hwc = &private_module->func_hwc;
685 if (!func_hwc->hwc_validate) {
686 /* LCOV_EXCL_START */
687 _pthread_mutex_unlock(&private_display->lock);
688 TDM_WRN("not implemented!!");
689 return TDM_ERROR_NOT_IMPLEMENTED;
693 ret = func_hwc->hwc_accept_validation(private_hwc->hwc_backend);
695 _pthread_mutex_unlock(&private_display->lock);
701 tdm_hwc_commit(tdm_hwc *hwc, int sync, tdm_hwc_commit_handler func, void *user_data)
703 tdm_private_module *private_module;
704 tdm_func_hwc *func_hwc = NULL;
705 tdm_private_hwc_commit_handler *hwc_commit_handler = NULL;
706 tdm_private_voutput *private_voutput = NULL;
707 tdm_private_voutput_commit_handler *voutput_commit_handler = NULL;
711 _pthread_mutex_lock(&private_display->lock);
713 private_module = private_hwc->private_module;
714 func_hwc = &private_module->func_hwc;
716 if (!func_hwc->hwc_commit) {
717 /* LCOV_EXCL_START */
718 TDM_WRN("not implemented!!");
719 _pthread_mutex_unlock(&private_display->lock);
720 return TDM_ERROR_NOT_IMPLEMENTED;
724 //TODO: I am not sure yet whether we have to check the dpms at hwc_commit.
726 /* check if the dpms is off */
727 if (TDM_OUTPUT_DPMS_VSYNC_IS_OFF(private_output->current_dpms_value)) {
728 TDM_ERR("hwc(%d) dpms: %s", private_hwc->index,
729 tdm_dpms_str(private_output->current_dpms_value));
730 _pthread_mutex_unlock(&private_display->lock);
731 return TDM_ERROR_DPMS_OFF;
735 if (tdm_debug_module & TDM_DEBUG_COMMIT)
736 TDM_INFO("hwc(%d) commit", private_hwc->index);
738 if (private_module == private_display->virtual_module) {
739 if (!private_output->private_voutput) {
740 TDM_ERR("virtual module but don't have voutput");
741 _pthread_mutex_unlock(&private_display->lock);
742 return TDM_ERROR_BAD_MODULE;
746 if (!private_hwc->regist_commit_cb) {
747 private_hwc->regist_commit_cb = 1;
748 ret = func_hwc->hwc_set_commit_handler(private_hwc->hwc_backend, _tdm_hwc_cb_commit);
749 /* LCOV_EXCL_START */
750 if (ret != TDM_ERROR_NONE) {
751 private_hwc->regist_commit_cb = 0;
752 TDM_ERR("hwc(%d) fail to set hwc_set_commit_handler", private_hwc->index);
753 _pthread_mutex_unlock(&private_display->lock);
759 hwc_commit_handler = calloc(1, sizeof(tdm_private_hwc_commit_handler));
760 if (!hwc_commit_handler) {
761 /* LCOV_EXCL_START */
762 TDM_ERR("failed: alloc memory");
763 _pthread_mutex_unlock(&private_display->lock);
764 return TDM_ERROR_OUT_OF_MEMORY;
768 ret = tdm_thread_cb_add(private_hwc, TDM_THREAD_CB_HWC_COMMIT, hwc_commit_handler,
769 _tdm_hwc_thread_cb_commit, NULL);
770 if (ret != TDM_ERROR_NONE) {
771 TDM_ERR("tdm_thread_cb_add failed");
772 free(hwc_commit_handler);
773 _pthread_mutex_unlock(&private_display->lock);
777 LIST_ADDTAIL(&hwc_commit_handler->link, &private_hwc->hwc_commit_handler_list);
778 hwc_commit_handler->private_hwc = private_hwc;
779 hwc_commit_handler->func = func;
780 hwc_commit_handler->user_data = user_data;
781 hwc_commit_handler->owner_tid = syscall(SYS_gettid);
783 hwc_commit_handler->use_vblank = 1;
785 if (private_module == private_display->virtual_module) {
786 private_voutput = private_output->private_voutput;
788 if (LIST_LENGTH(&private_voutput->voutput_commit_handler_list) != 0) {
789 voutput_commit_handler = LIST_FIRST_ENTRY(&private_voutput->voutput_commit_handler_list, tdm_private_voutput_commit_handler, link);
790 voutput_commit_handler->user_data = private_hwc->display_target_buffer;
794 ret = func_hwc->hwc_commit(private_hwc->hwc_backend, sync, hwc_commit_handler);
795 TDM_GOTO_IF_FAIL(ret == TDM_ERROR_NONE, commit_failed);
797 if (hwc_use_vblank) {
798 /* LCOV_EXCL_START */
799 ret = _tdm_hwc_vblank(private_hwc, hwc_commit_handler);
800 if (ret == TDM_ERROR_NONE) {
801 if (tdm_debug_module & TDM_DEBUG_COMMIT)
802 TDM_INFO("hwc(%d) backend commit: wait vblank handle(%p) func(%p) user_data(%p)",
803 private_hwc->index, hwc_commit_handler, func, user_data);
808 if (tdm_debug_module & TDM_DEBUG_COMMIT)
809 TDM_INFO("hwc(%d) backend commit: handle(%p) func(%p) user_data(%p)",
810 private_hwc->index, hwc_commit_handler, func, user_data);
813 _pthread_mutex_unlock(&private_display->lock);
818 /* LCOV_EXCL_START */
819 if (hwc_commit_handler) {
820 tdm_thread_cb_remove(private_hwc, TDM_THREAD_CB_HWC_COMMIT, hwc_commit_handler,
821 _tdm_hwc_thread_cb_commit, NULL);
822 LIST_DEL(&hwc_commit_handler->link);
823 free(hwc_commit_handler);
826 _pthread_mutex_unlock(&private_display->lock);
833 tdm_hwc_get_commit_fence(tdm_hwc *hwc, int *commit_fence)
835 tdm_private_module *private_module;
836 tdm_func_hwc *func_hwc = NULL;
840 _pthread_mutex_lock(&private_display->lock);
842 private_module = private_hwc->private_module;
843 func_hwc = &private_module->func_hwc;
845 if (!func_hwc->hwc_get_commit_fence) {
846 /* LCOV_EXCL_START */
847 _pthread_mutex_unlock(&private_display->lock);
848 TDM_WRN("not implemented!!");
849 return TDM_ERROR_NOT_IMPLEMENTED;
853 ret = func_hwc->hwc_get_commit_fence(private_hwc->hwc_backend, commit_fence);
855 _pthread_mutex_unlock(&private_display->lock);
861 tdm_hwc_get_release_fences(tdm_hwc *hwc, uint32_t *num_elements,
862 tdm_hwc_window **hwc_windows, int *fences)
864 tdm_private_module *private_module;
865 tdm_func_hwc *func_hwc = NULL;
866 tdm_private_hwc_window *private_hwc_window = NULL;
871 _pthread_mutex_lock(&private_display->lock);
873 private_module = private_hwc->private_module;
874 func_hwc = &private_module->func_hwc;
876 if (!func_hwc->hwc_get_release_fences) {
877 /* LCOV_EXCL_START */
878 _pthread_mutex_unlock(&private_display->lock);
879 TDM_WRN("not implemented!!");
880 return TDM_ERROR_NOT_IMPLEMENTED;
884 ret = func_hwc->hwc_get_release_fences(private_hwc->hwc_backend, num_elements,
885 hwc_windows, fences);
887 if (hwc_windows == NULL || fences == NULL) {
888 _pthread_mutex_unlock(&private_display->lock);
889 return TDM_ERROR_NONE;
892 for (i = 0; i < *num_elements; i++) {
893 private_hwc_window = _tdm_hwc_find_private_hwc_window(private_hwc, hwc_windows[i]);
894 if (private_hwc_window == NULL) {
895 /* LCOV_EXCL_START */
896 TDM_ERR("failed! This should never happen!");
897 tdm_hwc_window_destroy_internal(private_hwc_window);
899 _pthread_mutex_unlock(&private_display->lock);
900 return TDM_ERROR_OPERATION_FAILED;
904 hwc_windows[i] = (tdm_hwc_window*)private_hwc_window;
907 _pthread_mutex_unlock(&private_display->lock);
913 tdm_hwc_set_property(tdm_hwc *hwc, uint32_t id, tdm_value value)
915 tdm_private_module *private_module;
916 tdm_func_hwc *func_hwc = NULL;
920 _pthread_mutex_lock(&private_display->lock);
922 private_module = private_hwc->private_module;
923 func_hwc = &private_module->func_hwc;
925 if (!func_hwc->hwc_set_property) {
926 /* LCOV_EXCL_START */
927 _pthread_mutex_unlock(&private_display->lock);
928 TDM_WRN("not implemented!!");
929 return TDM_ERROR_NOT_IMPLEMENTED;
933 ret = func_hwc->hwc_set_property(private_hwc->hwc_backend, id, value);
935 _pthread_mutex_unlock(&private_display->lock);
941 tdm_hwc_get_property(tdm_hwc *hwc, uint32_t id, tdm_value *value)
943 tdm_private_module *private_module;
944 tdm_func_hwc *func_hwc = NULL;
948 _pthread_mutex_lock(&private_display->lock);
950 private_module = private_hwc->private_module;
951 func_hwc = &private_module->func_hwc;
953 if (!func_hwc->hwc_get_property) {
954 /* LCOV_EXCL_START */
955 _pthread_mutex_unlock(&private_display->lock);
956 TDM_WRN("not implemented!!");
957 return TDM_ERROR_NOT_IMPLEMENTED;
961 ret = func_hwc->hwc_get_property(private_hwc->hwc_backend, id, value);
963 _pthread_mutex_unlock(&private_display->lock);