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);
198 _tdm_hwc_got_wait_vblank(unsigned int sequence,
199 unsigned int tv_sec, unsigned int tv_usec, void *user_data)
201 tdm_private_hwc_commit_handler *hwc_commit_handler = user_data;
202 tdm_private_hwc *private_hwc;
203 tdm_thread_cb_hwc_commit hwc_commit;
205 private_hwc = hwc_commit_handler->private_hwc;
206 private_hwc->private_output->layer_waiting_vblank = 0;
208 memset(&hwc_commit, 0, sizeof hwc_commit);
209 hwc_commit.base.type = TDM_THREAD_CB_HWC_COMMIT;
210 hwc_commit.base.length = sizeof hwc_commit;
211 hwc_commit.base.object_stamp = private_hwc->stamp;
212 hwc_commit.base.data = hwc_commit_handler;
213 hwc_commit.base.sync = 0;
214 hwc_commit.sequence = sequence;
215 hwc_commit.tv_sec = tv_sec;
216 hwc_commit.tv_usec = tv_usec;
218 _tdm_hwc_thread_cb_commit(private_hwc->private_output->private_display, private_hwc, &hwc_commit.base, user_data);
222 _tdm_hwc_cb_wait_vblank(tdm_vblank *vblank, tdm_error error, unsigned int sequence,
223 unsigned int tv_sec, unsigned int tv_usec, void *user_data)
225 tdm_private_hwc_commit_handler *hwc_commit_handler = user_data;
226 tdm_private_output *private_output = NULL;
227 tdm_private_display *private_display;
229 if (!hwc_commit_handler->use_vblank)
232 TDM_RETURN_IF_FAIL(hwc_commit_handler != NULL);
233 TDM_RETURN_IF_FAIL(hwc_commit_handler->private_hwc != NULL);
235 private_output = hwc_commit_handler->private_hwc->private_output;
236 TDM_RETURN_IF_FAIL(private_output != NULL);
238 private_display = private_output->private_display;
240 _pthread_mutex_lock(&private_display->lock);
242 _tdm_hwc_got_wait_vblank(sequence, tv_sec, tv_usec, user_data);
244 _pthread_mutex_unlock(&private_display->lock);
248 _tdm_hwc_vblank(tdm_private_hwc *private_hwc, tdm_private_hwc_commit_handler *hwc_commit_handler)
250 tdm_private_display *private_display;
251 tdm_private_output *private_output;
252 tdm_error ret = TDM_ERROR_NONE;
254 private_output = private_hwc->private_output;
255 TDM_RETURN_VAL_IF_FAIL(private_output != NULL, TDM_ERROR_INVALID_PARAMETER);
256 private_display = private_output->private_display;
258 if (!private_output->vblank) {
259 /* tdm_vblank APIs is for server. it should be called in unlock status*/
260 _pthread_mutex_unlock(&private_display->lock);
261 private_output->vblank = tdm_vblank_create(private_display, private_output, NULL);
262 _pthread_mutex_lock(&private_display->lock);
263 TDM_RETURN_VAL_IF_FAIL(private_output->vblank != NULL, TDM_ERROR_OPERATION_FAILED);
266 if (!private_output->layer_waiting_vblank) {
267 ret = tdm_vblank_set_fps(private_output->vblank, hwc_vblank_fps);
268 if (ret != TDM_ERROR_NONE)
271 hwc_commit_handler->use_vblank = 1;
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 hwc_commit_handler->use_vblank = 0;
281 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);
529 tdm_hwc_validate(tdm_hwc *hwc, tdm_hwc_window **composited_wnds, uint32_t num_wnds, uint32_t *num_types)
531 tdm_private_module *private_module;
532 tdm_func_hwc *func_hwc = NULL;
533 tdm_private_hwc_window **composited_wnds_frontend = NULL;
534 tdm_hwc_window **composited_wnds_backend = NULL;
539 TDM_RETURN_VAL_IF_FAIL(num_types != NULL, TDM_ERROR_INVALID_PARAMETER);
541 _pthread_mutex_lock(&private_display->lock);
543 private_module = private_hwc->private_module;
544 func_hwc = &private_module->func_hwc;
546 if (!func_hwc->hwc_validate) {
547 /* LCOV_EXCL_START */
548 _pthread_mutex_unlock(&private_display->lock);
549 TDM_WRN("not implemented!!");
550 return TDM_ERROR_NOT_IMPLEMENTED;
555 ret = func_hwc->hwc_validate(private_hwc->hwc_backend, NULL, 0, num_types);
557 _pthread_mutex_unlock(&private_display->lock);
561 composited_wnds_backend = calloc(num_wnds, sizeof(tdm_hwc_window *));
562 if (!composited_wnds_backend) {
563 /* LCOV_EXCL_START */
564 _pthread_mutex_unlock(&private_display->lock);
565 return TDM_ERROR_OUT_OF_MEMORY;
569 composited_wnds_frontend = (tdm_private_hwc_window **)composited_wnds;
571 for (i = 0; i < num_wnds; i++)
572 composited_wnds_backend[i] = composited_wnds_frontend[i]->hwc_window_backend;
574 ret = func_hwc->hwc_validate(private_hwc->hwc_backend, composited_wnds_backend,
575 num_wnds, num_types);
577 free(composited_wnds_backend);
579 _pthread_mutex_unlock(&private_display->lock);
585 tdm_hwc_get_changed_composition_types(tdm_hwc *hwc, uint32_t *num_elements,
586 tdm_hwc_window **hwc_window,
587 tdm_hwc_window_composition *composition_types)
589 tdm_private_module *private_module;
590 tdm_func_hwc *func_hwc = NULL;
591 tdm_private_hwc_window * private_hwc_window = NULL;
596 TDM_RETURN_VAL_IF_FAIL(num_elements != NULL, TDM_ERROR_INVALID_PARAMETER);
598 _pthread_mutex_lock(&private_display->lock);
600 private_module = private_hwc->private_module;
601 func_hwc = &private_module->func_hwc;
603 if (!func_hwc->hwc_get_changed_composition_types) {
604 /* LCOV_EXCL_START */
605 _pthread_mutex_unlock(&private_display->lock);
606 TDM_WRN("not implemented!!");
607 return TDM_ERROR_NOT_IMPLEMENTED;
611 ret = func_hwc->hwc_get_changed_composition_types(private_hwc->hwc_backend,
612 num_elements, hwc_window, composition_types);
613 if (ret != TDM_ERROR_NONE) {
614 /* LCOV_EXCL_START */
615 _pthread_mutex_unlock(&private_display->lock);
620 if (hwc_window == NULL || composition_types == NULL) {
621 _pthread_mutex_unlock(&private_display->lock);
622 return TDM_ERROR_NONE;
625 for (i = 0; i < *num_elements; i++) {
626 private_hwc_window = _tdm_hwc_find_private_hwc_window(private_hwc, hwc_window[i]);
627 if (private_hwc_window == NULL) {
628 /* LCOV_EXCL_START */
629 TDM_ERR("failed! This should never happen!");
630 tdm_hwc_window_destroy_internal(private_hwc_window);
632 _pthread_mutex_unlock(&private_display->lock);
633 return TDM_ERROR_OPERATION_FAILED;
637 hwc_window[i] = (tdm_hwc_window*)private_hwc_window;
640 _pthread_mutex_unlock(&private_display->lock);
646 tdm_hwc_accept_validation(tdm_hwc *hwc)
648 tdm_private_module *private_module;
649 tdm_func_hwc *func_hwc = NULL;
653 _pthread_mutex_lock(&private_display->lock);
655 private_module = private_hwc->private_module;
656 func_hwc = &private_module->func_hwc;
658 if (!func_hwc->hwc_validate) {
659 /* LCOV_EXCL_START */
660 _pthread_mutex_unlock(&private_display->lock);
661 TDM_WRN("not implemented!!");
662 return TDM_ERROR_NOT_IMPLEMENTED;
666 ret = func_hwc->hwc_accept_validation(private_hwc->hwc_backend);
668 _pthread_mutex_unlock(&private_display->lock);
674 tdm_hwc_commit(tdm_hwc *hwc, int sync, tdm_hwc_commit_handler func, void *user_data)
676 tdm_private_module *private_module;
677 tdm_func_hwc *func_hwc = NULL;
678 tdm_private_hwc_commit_handler *hwc_commit_handler = NULL;
679 tdm_private_voutput *private_voutput = NULL;
680 tdm_private_voutput_commit_handler *voutput_commit_handler = NULL;
684 _pthread_mutex_lock(&private_display->lock);
686 private_module = private_hwc->private_module;
687 func_hwc = &private_module->func_hwc;
689 if (!func_hwc->hwc_commit) {
690 /* LCOV_EXCL_START */
691 TDM_WRN("not implemented!!");
692 _pthread_mutex_unlock(&private_display->lock);
693 return TDM_ERROR_NOT_IMPLEMENTED;
697 //TODO: I am not sure yet whether we have to check the dpms at hwc_commit.
699 /* check if the dpms is off */
700 if (TDM_OUTPUT_DPMS_VSYNC_IS_OFF(private_output->current_dpms_value)) {
701 TDM_ERR("hwc(%d) dpms: %s", private_hwc->index,
702 tdm_dpms_str(private_output->current_dpms_value));
703 _pthread_mutex_unlock(&private_display->lock);
704 return TDM_ERROR_DPMS_OFF;
708 if (tdm_debug_module & TDM_DEBUG_COMMIT)
709 TDM_INFO("hwc(%d) commit", private_hwc->index);
711 if (private_module == private_display->virtual_module) {
712 if (!private_output->private_voutput) {
713 TDM_ERR("virtual module but don't have voutput");
714 _pthread_mutex_unlock(&private_display->lock);
715 return TDM_ERROR_BAD_MODULE;
719 if (!private_hwc->regist_commit_cb) {
720 private_hwc->regist_commit_cb = 1;
721 ret = func_hwc->hwc_set_commit_handler(private_hwc->hwc_backend, _tdm_hwc_cb_commit);
722 /* LCOV_EXCL_START */
723 if (ret != TDM_ERROR_NONE) {
724 private_hwc->regist_commit_cb = 0;
725 TDM_ERR("hwc(%d) fail to set hwc_set_commit_handler", private_hwc->index);
726 _pthread_mutex_unlock(&private_display->lock);
732 hwc_commit_handler = calloc(1, sizeof(tdm_private_hwc_commit_handler));
733 if (!hwc_commit_handler) {
734 /* LCOV_EXCL_START */
735 TDM_ERR("failed: alloc memory");
736 _pthread_mutex_unlock(&private_display->lock);
737 return TDM_ERROR_OUT_OF_MEMORY;
741 ret = tdm_thread_cb_add(private_hwc, TDM_THREAD_CB_HWC_COMMIT, hwc_commit_handler,
742 _tdm_hwc_thread_cb_commit, NULL);
743 if (ret != TDM_ERROR_NONE) {
744 TDM_ERR("tdm_thread_cb_add failed");
745 free(hwc_commit_handler);
746 _pthread_mutex_unlock(&private_display->lock);
750 LIST_ADDTAIL(&hwc_commit_handler->link, &private_hwc->hwc_commit_handler_list);
751 hwc_commit_handler->private_hwc = private_hwc;
752 hwc_commit_handler->func = func;
753 hwc_commit_handler->user_data = user_data;
754 hwc_commit_handler->owner_tid = syscall(SYS_gettid);
756 if (private_module == private_display->virtual_module) {
757 private_voutput = private_output->private_voutput;
759 if (LIST_LENGTH(&private_voutput->voutput_commit_handler_list) != 0) {
760 voutput_commit_handler = LIST_FIRST_ENTRY(&private_voutput->voutput_commit_handler_list, tdm_private_voutput_commit_handler, link);
761 voutput_commit_handler->user_data = private_hwc->display_target_buffer;
765 ret = func_hwc->hwc_commit(private_hwc->hwc_backend, sync, hwc_commit_handler);
766 TDM_GOTO_IF_FAIL(ret == TDM_ERROR_NONE, commit_failed);
768 if (hwc_use_vblank) {
769 ret = _tdm_hwc_vblank(private_hwc, hwc_commit_handler);
770 if (ret == TDM_ERROR_NONE) {
771 if (tdm_debug_module & TDM_DEBUG_COMMIT)
772 TDM_INFO("hwc(%d) backend commit: wait vblank handle(%p) func(%p) user_data(%p)",
773 private_hwc->index, hwc_commit_handler, func, user_data);
777 if (tdm_debug_module & TDM_DEBUG_COMMIT)
778 TDM_INFO("hwc(%d) backend commit: handle(%p) func(%p) user_data(%p)",
779 private_hwc->index, hwc_commit_handler, func, user_data);
782 _pthread_mutex_unlock(&private_display->lock);
787 /* LCOV_EXCL_START */
788 if (hwc_commit_handler) {
789 tdm_thread_cb_remove(private_hwc, TDM_THREAD_CB_HWC_COMMIT, hwc_commit_handler,
790 _tdm_hwc_thread_cb_commit, NULL);
791 LIST_DEL(&hwc_commit_handler->link);
792 free(hwc_commit_handler);
795 _pthread_mutex_unlock(&private_display->lock);
802 tdm_hwc_set_property(tdm_hwc *hwc, uint32_t id, tdm_value value)
804 tdm_private_module *private_module;
805 tdm_func_hwc *func_hwc = NULL;
809 _pthread_mutex_lock(&private_display->lock);
811 private_module = private_hwc->private_module;
812 func_hwc = &private_module->func_hwc;
814 if (!func_hwc->hwc_set_property) {
815 /* LCOV_EXCL_START */
816 _pthread_mutex_unlock(&private_display->lock);
817 TDM_WRN("not implemented!!");
818 return TDM_ERROR_NOT_IMPLEMENTED;
822 ret = func_hwc->hwc_set_property(private_hwc->hwc_backend, id, value);
824 _pthread_mutex_unlock(&private_display->lock);
830 tdm_hwc_get_property(tdm_hwc *hwc, uint32_t id, tdm_value *value)
832 tdm_private_module *private_module;
833 tdm_func_hwc *func_hwc = NULL;
837 _pthread_mutex_lock(&private_display->lock);
839 private_module = private_hwc->private_module;
840 func_hwc = &private_module->func_hwc;
842 if (!func_hwc->hwc_get_property) {
843 /* LCOV_EXCL_START */
844 _pthread_mutex_unlock(&private_display->lock);
845 TDM_WRN("not implemented!!");
846 return TDM_ERROR_NOT_IMPLEMENTED;
850 ret = func_hwc->hwc_get_property(private_hwc->hwc_backend, id, value);
852 _pthread_mutex_unlock(&private_display->lock);