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 <sc1.lim@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 **************************************************************************/
41 #include "tdm_backend.h"
42 #include "tdm_private.h"
46 #define DISPLAY_FUNC_ENTRY() \
47 tdm_private_display *private_display; \
48 tdm_error ret = TDM_ERROR_NONE; /* default TDM_ERROR_NONE */\
49 TDM_RETURN_VAL_IF_FAIL(dpy != NULL, TDM_ERROR_INVALID_PARAMETER); \
50 private_display = (tdm_private_display*)dpy;
52 #define DISPLAY_FUNC_ENTRY_ERROR() \
53 tdm_private_display *private_display; \
54 tdm_error ret = TDM_ERROR_NONE; /* default TDM_ERROR_NONE */\
55 TDM_RETURN_VAL_IF_FAIL_WITH_ERROR(dpy != NULL, TDM_ERROR_INVALID_PARAMETER, NULL); \
56 private_display = (tdm_private_display*)dpy;
58 #define OUTPUT_FUNC_ENTRY() \
59 tdm_private_display *private_display; \
60 tdm_private_output *private_output; \
61 tdm_error ret = TDM_ERROR_NONE; /* default TDM_ERROR_NONE */\
62 TDM_RETURN_VAL_IF_FAIL(output != NULL, TDM_ERROR_INVALID_PARAMETER); \
63 private_output = (tdm_private_output*)output; \
64 private_display = private_output->private_display
66 #define OUTPUT_FUNC_ENTRY_ERROR() \
67 tdm_private_display *private_display; \
68 tdm_private_output *private_output; \
69 tdm_error ret = TDM_ERROR_NONE; /* default TDM_ERROR_NONE */\
70 TDM_RETURN_VAL_IF_FAIL_WITH_ERROR(output != NULL, TDM_ERROR_INVALID_PARAMETER, NULL); \
71 private_output = (tdm_private_output*)output; \
72 private_display = private_output->private_display
74 #define LAYER_FUNC_ENTRY() \
75 tdm_private_display *private_display; \
76 tdm_private_output *private_output; \
77 tdm_private_layer *private_layer; \
78 tdm_error ret = TDM_ERROR_NONE; /* default TDM_ERROR_NONE */\
79 TDM_RETURN_VAL_IF_FAIL(layer != NULL, TDM_ERROR_INVALID_PARAMETER); \
80 private_layer = (tdm_private_layer*)layer; \
81 private_output = private_layer->private_output; \
82 private_display = private_output->private_display
84 #define LAYER_FUNC_ENTRY_ERROR() \
85 tdm_private_display *private_display; \
86 tdm_private_output *private_output; \
87 tdm_private_layer *private_layer; \
88 tdm_error ret = TDM_ERROR_NONE; /* default TDM_ERROR_NONE */\
89 TDM_RETURN_VAL_IF_FAIL_WITH_ERROR(layer != NULL, TDM_ERROR_INVALID_PARAMETER, NULL); \
90 private_layer = (tdm_private_layer*)layer; \
91 private_output = private_layer->private_output; \
92 private_display = private_output->private_display
94 #define LAYER_FUNC_ENTRY_VOID_RETURN() \
95 tdm_private_display *private_display; \
96 tdm_private_output *private_output; \
97 tdm_private_layer *private_layer; \
98 tdm_error ret = TDM_ERROR_NONE; /* default TDM_ERROR_NONE */\
99 TDM_RETURN_IF_FAIL(layer != NULL); \
100 private_layer = (tdm_private_layer*)layer; \
101 private_output = private_layer->private_output; \
102 private_display = private_output->private_display
105 tdm_display_get_capabilities(tdm_display *dpy, tdm_display_capability *capabilities)
107 DISPLAY_FUNC_ENTRY();
109 TDM_RETURN_VAL_IF_FAIL(capabilities != NULL, TDM_ERROR_INVALID_PARAMETER);
111 pthread_mutex_lock(&private_display->lock);
113 *capabilities = private_display->capabilities;
115 pthread_mutex_unlock(&private_display->lock);
121 tdm_display_get_pp_capabilities(tdm_display *dpy, tdm_pp_capability *capabilities)
123 DISPLAY_FUNC_ENTRY();
125 TDM_RETURN_VAL_IF_FAIL(capabilities != NULL, TDM_ERROR_INVALID_PARAMETER);
127 pthread_mutex_lock(&private_display->lock);
129 if (!(private_display->capabilities & TDM_DISPLAY_CAPABILITY_PP))
131 TDM_ERR("no pp capability");
132 pthread_mutex_unlock(&private_display->lock);
133 return TDM_ERROR_NO_CAPABILITY;
136 *capabilities = private_display->caps_pp.capabilities;
138 pthread_mutex_unlock(&private_display->lock);
144 tdm_display_get_pp_available_formats(tdm_display *dpy, const tbm_format **formats, int *count)
146 DISPLAY_FUNC_ENTRY();
148 TDM_RETURN_VAL_IF_FAIL(formats != NULL, TDM_ERROR_INVALID_PARAMETER);
149 TDM_RETURN_VAL_IF_FAIL(count != NULL, TDM_ERROR_INVALID_PARAMETER);
151 pthread_mutex_lock(&private_display->lock);
153 if (!(private_display->capabilities & TDM_DISPLAY_CAPABILITY_PP))
155 TDM_ERR("no pp capability");
156 pthread_mutex_unlock(&private_display->lock);
157 return TDM_ERROR_NO_CAPABILITY;
160 *formats = (const tbm_format*)private_display->caps_pp.formats;
161 *count = private_display->caps_pp.format_count;
163 pthread_mutex_unlock(&private_display->lock);
169 tdm_display_get_pp_available_size(tdm_display *dpy, int *min_w, int *min_h,
170 int *max_w, int *max_h, int *preferred_align)
172 DISPLAY_FUNC_ENTRY();
174 pthread_mutex_lock(&private_display->lock);
176 if (!(private_display->capabilities & TDM_DISPLAY_CAPABILITY_PP))
178 TDM_ERR("no pp capability");
179 pthread_mutex_unlock(&private_display->lock);
180 return TDM_ERROR_NO_CAPABILITY;
184 *min_w = private_display->caps_pp.min_w;
186 *min_h = private_display->caps_pp.min_h;
188 *max_w = private_display->caps_pp.max_w;
190 *max_h = private_display->caps_pp.max_h;
192 *preferred_align = private_display->caps_pp.preferred_align;
194 pthread_mutex_unlock(&private_display->lock);
200 tdm_display_get_capture_capabilities(tdm_display *dpy, tdm_capture_capability *capabilities)
202 DISPLAY_FUNC_ENTRY();
204 TDM_RETURN_VAL_IF_FAIL(capabilities != NULL, TDM_ERROR_INVALID_PARAMETER);
206 pthread_mutex_lock(&private_display->lock);
208 if (!(private_display->capabilities & TDM_DISPLAY_CAPABILITY_CAPTURE))
210 TDM_ERR("no capture capability");
211 pthread_mutex_unlock(&private_display->lock);
212 return TDM_ERROR_NO_CAPABILITY;
215 *capabilities = private_display->caps_capture.capabilities;
217 pthread_mutex_unlock(&private_display->lock);
223 tdm_display_get_catpure_available_formats(tdm_display *dpy, const tbm_format **formats, int *count)
225 DISPLAY_FUNC_ENTRY();
227 TDM_RETURN_VAL_IF_FAIL(formats != NULL, TDM_ERROR_INVALID_PARAMETER);
228 TDM_RETURN_VAL_IF_FAIL(count != NULL, TDM_ERROR_INVALID_PARAMETER);
230 pthread_mutex_lock(&private_display->lock);
232 if (!(private_display->capabilities & TDM_DISPLAY_CAPABILITY_CAPTURE))
234 TDM_ERR("no capture capability");
235 pthread_mutex_unlock(&private_display->lock);
236 return TDM_ERROR_NO_CAPABILITY;
239 *formats = (const tbm_format*)private_display->caps_capture.formats;
240 *count = private_display->caps_capture.format_count;
242 pthread_mutex_unlock(&private_display->lock);
248 tdm_display_get_output_count(tdm_display *dpy, int *count)
250 tdm_private_output *private_output = NULL;
252 DISPLAY_FUNC_ENTRY();
254 TDM_RETURN_VAL_IF_FAIL(count != NULL, TDM_ERROR_INVALID_PARAMETER);
256 pthread_mutex_lock(&private_display->lock);
259 LIST_FOR_EACH_ENTRY(private_output, &private_display->output_list, link)
264 pthread_mutex_unlock(&private_display->lock);
265 return TDM_ERROR_NONE;
268 pthread_mutex_unlock(&private_display->lock);
275 tdm_display_get_output(tdm_display *dpy, int index, tdm_error *error)
277 tdm_private_output *private_output = NULL;
280 DISPLAY_FUNC_ENTRY_ERROR();
282 pthread_mutex_lock(&private_display->lock);
285 *error = TDM_ERROR_NONE;
288 LIST_FOR_EACH_ENTRY(private_output, &private_display->output_list, link)
292 pthread_mutex_unlock(&private_display->lock);
293 return private_output;
298 pthread_mutex_unlock(&private_display->lock);
304 tdm_display_get_fd(tdm_display *dpy, int *fd)
306 tdm_func_display *func_display;
307 DISPLAY_FUNC_ENTRY();
309 TDM_RETURN_VAL_IF_FAIL(fd != NULL, TDM_ERROR_INVALID_PARAMETER);
311 pthread_mutex_lock(&private_display->lock);
313 func_display = &private_display->func_display;
315 if (!func_display->display_get_fd)
317 pthread_mutex_unlock(&private_display->lock);
318 return TDM_ERROR_NONE;
321 ret = func_display->display_get_fd(private_display->bdata, fd);
323 pthread_mutex_unlock(&private_display->lock);
329 tdm_display_handle_events(tdm_display *dpy)
331 tdm_func_display *func_display;
332 DISPLAY_FUNC_ENTRY();
334 pthread_mutex_lock(&private_display->lock);
336 func_display = &private_display->func_display;
338 if (!func_display->display_handle_events)
340 pthread_mutex_unlock(&private_display->lock);
341 return TDM_ERROR_NONE;
344 ret = func_display->display_handle_events(private_display->bdata);
346 pthread_mutex_unlock(&private_display->lock);
352 tdm_display_create_pp(tdm_display *dpy, tdm_error *error)
356 DISPLAY_FUNC_ENTRY_ERROR();
358 pthread_mutex_lock(&private_display->lock);
360 pp = (tdm_pp*)tdm_pp_create_internal(private_display, error);
362 pthread_mutex_unlock(&private_display->lock);
368 tdm_output_get_model_info(tdm_output *output, const char **maker, const char **model, const char **name)
372 pthread_mutex_lock(&private_display->lock);
375 *maker = private_output->caps.maker;
377 *model = private_output->caps.model;
379 *name = private_output->caps.name;
381 pthread_mutex_unlock(&private_display->lock);
387 tdm_output_get_conn_status(tdm_output *output, tdm_output_conn_status *status)
391 TDM_RETURN_VAL_IF_FAIL(status != NULL, TDM_ERROR_INVALID_PARAMETER);
393 pthread_mutex_lock(&private_display->lock);
395 *status = private_output->caps.status;
397 pthread_mutex_unlock(&private_display->lock);
403 tdm_output_get_output_type(tdm_output *output, tdm_output_type *type)
407 TDM_RETURN_VAL_IF_FAIL(type != NULL, TDM_ERROR_INVALID_PARAMETER);
409 pthread_mutex_lock(&private_display->lock);
411 *type = private_output->caps.type;
413 pthread_mutex_unlock(&private_display->lock);
419 tdm_output_get_layer_count(tdm_output *output, int *count)
421 tdm_private_layer *private_layer = NULL;
425 TDM_RETURN_VAL_IF_FAIL(count != NULL, TDM_ERROR_INVALID_PARAMETER);
427 pthread_mutex_lock(&private_display->lock);
430 LIST_FOR_EACH_ENTRY(private_layer, &private_output->layer_list, link)
434 pthread_mutex_unlock(&private_display->lock);
435 return TDM_ERROR_NONE;
438 pthread_mutex_unlock(&private_display->lock);
445 tdm_output_get_layer(tdm_output *output, int index, tdm_error *error)
447 tdm_private_layer *private_layer = NULL;
450 OUTPUT_FUNC_ENTRY_ERROR();
452 pthread_mutex_lock(&private_display->lock);
455 *error = TDM_ERROR_NONE;
457 LIST_FOR_EACH_ENTRY(private_layer, &private_output->layer_list, link)
461 pthread_mutex_unlock(&private_display->lock);
462 return private_layer;
467 pthread_mutex_unlock(&private_display->lock);
473 tdm_output_get_available_properties(tdm_output *output, const tdm_prop **props, int *count)
477 TDM_RETURN_VAL_IF_FAIL(props != NULL, TDM_ERROR_INVALID_PARAMETER);
478 TDM_RETURN_VAL_IF_FAIL(count != NULL, TDM_ERROR_INVALID_PARAMETER);
480 pthread_mutex_lock(&private_display->lock);
482 *props = (const tdm_prop*)private_output->caps.props;
483 *count = private_output->caps.prop_count;
485 pthread_mutex_unlock(&private_display->lock);
491 tdm_output_get_available_modes(tdm_output *output, const tdm_output_mode **modes, int *count)
495 TDM_RETURN_VAL_IF_FAIL(modes != NULL, TDM_ERROR_INVALID_PARAMETER);
496 TDM_RETURN_VAL_IF_FAIL(count != NULL, TDM_ERROR_INVALID_PARAMETER);
498 pthread_mutex_lock(&private_display->lock);
500 *modes = (const tdm_output_mode*)private_output->caps.modes;
501 *count = private_output->caps.mode_count;
503 pthread_mutex_unlock(&private_display->lock);
509 tdm_output_get_available_size(tdm_output *output, int *min_w, int *min_h,
510 int *max_w, int *max_h, int *preferred_align)
514 pthread_mutex_lock(&private_display->lock);
517 *min_w = private_output->caps.min_w;
519 *min_h = private_output->caps.min_h;
521 *max_w = private_output->caps.max_w;
523 *max_h = private_output->caps.max_h;
525 *preferred_align = private_output->caps.preferred_align;
527 pthread_mutex_unlock(&private_display->lock);
533 tdm_output_get_physical_size(tdm_output *output, unsigned int *mmWidth, unsigned int *mmHeight)
537 pthread_mutex_lock(&private_display->lock);
540 *mmWidth = private_output->caps.mmWidth;
542 *mmHeight = private_output->caps.mmHeight;
544 pthread_mutex_unlock(&private_display->lock);
550 tdm_output_get_subpixel(tdm_output *output, unsigned int *subpixel)
553 TDM_RETURN_VAL_IF_FAIL(subpixel != NULL, TDM_ERROR_INVALID_PARAMETER);
555 pthread_mutex_lock(&private_display->lock);
557 *subpixel = private_output->caps.subpixel;
559 pthread_mutex_unlock(&private_display->lock);
565 tdm_output_get_pipe(tdm_output *output, unsigned int *pipe)
568 TDM_RETURN_VAL_IF_FAIL(pipe != NULL, TDM_ERROR_INVALID_PARAMETER);
570 pthread_mutex_lock(&private_display->lock);
572 *pipe = private_output->pipe;
574 pthread_mutex_unlock(&private_display->lock);
581 tdm_output_set_property(tdm_output *output, unsigned int id, tdm_value value)
583 tdm_func_output *func_output;
586 pthread_mutex_lock(&private_display->lock);
588 func_output = &private_display->func_output;
590 if (!func_output->output_set_property)
592 pthread_mutex_unlock(&private_display->lock);
593 return TDM_ERROR_NONE;
596 ret = func_output->output_set_property(private_output->output_backend, id, value);
598 pthread_mutex_unlock(&private_display->lock);
604 tdm_output_get_property(tdm_output *output, unsigned int id, tdm_value *value)
606 tdm_func_output *func_output;
609 TDM_RETURN_VAL_IF_FAIL(value != NULL, TDM_ERROR_INVALID_PARAMETER);
611 pthread_mutex_lock(&private_display->lock);
613 func_output = &private_display->func_output;
615 if (!func_output->output_get_property)
617 pthread_mutex_unlock(&private_display->lock);
618 return TDM_ERROR_NONE;
621 ret = func_output->output_get_property(private_output->output_backend, id, value);
623 pthread_mutex_unlock(&private_display->lock);
629 _tdm_output_cb_vblank(tdm_output *output_backend, unsigned int sequence,
630 unsigned int tv_sec, unsigned int tv_usec, void *user_data)
632 tdm_private_vblank_handler *vblank_handler = user_data;
633 tdm_private_display *private_display;
635 TDM_RETURN_IF_FAIL(vblank_handler);
637 private_display = vblank_handler->private_output->private_display;
639 if (vblank_handler->func)
641 pthread_mutex_unlock(&private_display->lock);
642 vblank_handler->func(vblank_handler->private_output, sequence,
643 tv_sec, tv_usec, vblank_handler->user_data);
644 pthread_mutex_lock(&private_display->lock);
647 LIST_DEL(&vblank_handler->link);
648 free(vblank_handler);
652 _tdm_output_cb_commit(tdm_output *output_backend, unsigned int sequence,
653 unsigned int tv_sec, unsigned int tv_usec, void *user_data)
655 tdm_private_commit_handler *commit_handler = user_data;
656 tdm_private_display *private_display;
657 tdm_private_output *private_output;
658 tdm_private_layer *private_layer = NULL;
660 TDM_RETURN_IF_FAIL(commit_handler);
662 private_output = commit_handler->private_output;
663 private_display = private_output->private_display;
665 LIST_FOR_EACH_ENTRY(private_layer, &private_output->layer_list, link)
667 if (!private_layer->waiting_buffer)
670 if (private_layer->showing_buffer)
672 pthread_mutex_unlock(&private_display->lock);
673 tdm_buffer_unref_backend(private_layer->showing_buffer);
674 pthread_mutex_lock(&private_display->lock);
676 if (private_layer->buffer_queue)
678 pthread_mutex_unlock(&private_display->lock);
679 tbm_surface_queue_release(private_layer->buffer_queue,
680 private_layer->showing_buffer);
681 pthread_mutex_lock(&private_display->lock);
685 private_layer->showing_buffer = private_layer->waiting_buffer;
686 private_layer->waiting_buffer = NULL;
689 if (commit_handler->func)
691 pthread_mutex_unlock(&private_display->lock);
692 commit_handler->func(private_output, sequence,
693 tv_sec, tv_usec, commit_handler->user_data);
694 pthread_mutex_lock(&private_display->lock);
697 LIST_DEL(&commit_handler->link);
698 free(commit_handler);
702 tdm_output_wait_vblank(tdm_output *output, int interval, int sync,
703 tdm_output_vblank_handler func, void *user_data)
705 tdm_func_output *func_output;
706 tdm_private_vblank_handler *vblank_handler;
709 pthread_mutex_lock(&private_display->lock);
711 func_output = &private_display->func_output;
713 if (!func_output->output_wait_vblank)
715 pthread_mutex_unlock(&private_display->lock);
716 return TDM_ERROR_NONE;
719 vblank_handler = calloc(1, sizeof(tdm_private_vblank_handler));
722 TDM_ERR("failed: alloc memory");
723 pthread_mutex_unlock(&private_display->lock);
724 return TDM_ERROR_OUT_OF_MEMORY;
727 LIST_ADD(&vblank_handler->link, &private_output->vblank_handler_list);
728 vblank_handler->private_output = private_output;
729 vblank_handler->func = func;
730 vblank_handler->user_data = user_data;
732 ret = func_output->output_wait_vblank(private_output->output_backend, interval,
733 sync, vblank_handler);
734 if (ret != TDM_ERROR_NONE)
736 pthread_mutex_unlock(&private_display->lock);
740 if (!private_output->regist_vblank_cb)
742 private_output->regist_vblank_cb = 1;
743 ret = func_output->output_set_vblank_handler(private_output->output_backend,
744 _tdm_output_cb_vblank);
747 pthread_mutex_unlock(&private_display->lock);
753 _tdm_output_commit(tdm_output *output, int sync, tdm_output_commit_handler func, void *user_data)
755 tdm_func_output *func_output;
756 tdm_private_commit_handler *commit_handler;
759 func_output = &private_display->func_output;
761 if (!func_output->output_commit)
763 return TDM_ERROR_NONE;
766 commit_handler = calloc(1, sizeof(tdm_private_commit_handler));
769 TDM_ERR("failed: alloc memory");
770 return TDM_ERROR_OUT_OF_MEMORY;
773 LIST_ADD(&commit_handler->link, &private_output->commit_handler_list);
774 commit_handler->private_output = private_output;
775 commit_handler->func = func;
776 commit_handler->user_data = user_data;
778 ret = func_output->output_commit(private_output->output_backend, sync, commit_handler);
779 if (ret != TDM_ERROR_NONE)
784 if (!private_output->regist_commit_cb)
786 private_output->regist_commit_cb = 1;
787 ret = func_output->output_set_commit_handler(private_output->output_backend,
788 _tdm_output_cb_commit);
795 tdm_output_commit(tdm_output *output, int sync, tdm_output_commit_handler func, void *user_data)
799 pthread_mutex_lock(&private_display->lock);
801 ret = _tdm_output_commit(output, sync, func, user_data);
803 pthread_mutex_unlock(&private_display->lock);
809 tdm_output_set_mode(tdm_output *output, const tdm_output_mode *mode)
811 tdm_func_output *func_output;
814 TDM_RETURN_VAL_IF_FAIL(mode != NULL, TDM_ERROR_INVALID_PARAMETER);
816 pthread_mutex_lock(&private_display->lock);
818 func_output = &private_display->func_output;
820 if (!func_output->output_set_mode)
822 pthread_mutex_unlock(&private_display->lock);
823 return TDM_ERROR_NONE;
826 ret = func_output->output_set_mode(private_output->output_backend, mode);
828 pthread_mutex_unlock(&private_display->lock);
834 tdm_output_get_mode(tdm_output *output, const tdm_output_mode **mode)
836 tdm_func_output *func_output;
839 TDM_RETURN_VAL_IF_FAIL(mode != NULL, TDM_ERROR_INVALID_PARAMETER);
841 pthread_mutex_lock(&private_display->lock);
843 func_output = &private_display->func_output;
845 if (!func_output->output_get_mode)
847 pthread_mutex_unlock(&private_display->lock);
848 return TDM_ERROR_NONE;
851 ret = func_output->output_get_mode(private_output->output_backend, mode);
853 pthread_mutex_unlock(&private_display->lock);
859 tdm_output_set_dpms(tdm_output *output, tdm_output_dpms dpms_value)
861 tdm_func_output *func_output;
864 if (dpms_value < TDM_OUTPUT_DPMS_ON)
865 dpms_value = TDM_OUTPUT_DPMS_ON;
866 else if (dpms_value > TDM_OUTPUT_DPMS_OFF)
867 dpms_value = TDM_OUTPUT_DPMS_OFF;
869 pthread_mutex_lock(&private_display->lock);
871 func_output = &private_display->func_output;
873 if (!func_output->output_set_dpms)
875 pthread_mutex_unlock(&private_display->lock);
876 return TDM_ERROR_NONE;
879 ret = func_output->output_set_dpms(private_output->output_backend, dpms_value);
881 pthread_mutex_unlock(&private_display->lock);
887 tdm_output_get_dpms(tdm_output *output, tdm_output_dpms *dpms_value)
889 tdm_func_output *func_output;
892 TDM_RETURN_VAL_IF_FAIL(dpms_value != NULL, TDM_ERROR_INVALID_PARAMETER);
894 pthread_mutex_lock(&private_display->lock);
896 func_output = &private_display->func_output;
898 if (!func_output->output_get_dpms)
900 pthread_mutex_unlock(&private_display->lock);
901 return TDM_ERROR_NONE;
904 ret = func_output->output_get_dpms(private_output->output_backend, dpms_value);
906 pthread_mutex_unlock(&private_display->lock);
912 tdm_output_create_capture(tdm_output *output, tdm_error *error)
914 tdm_capture *capture = NULL;
916 OUTPUT_FUNC_ENTRY_ERROR();
918 pthread_mutex_lock(&private_display->lock);
920 capture = (tdm_capture*)tdm_capture_create_output_internal(private_output, error);
922 pthread_mutex_unlock(&private_display->lock);
928 tdm_layer_get_capabilities(tdm_layer *layer, tdm_layer_capability *capabilities)
932 TDM_RETURN_VAL_IF_FAIL(capabilities != NULL, TDM_ERROR_INVALID_PARAMETER);
934 pthread_mutex_lock(&private_display->lock);
936 *capabilities = private_layer->caps.capabilities;
938 pthread_mutex_unlock(&private_display->lock);
944 tdm_layer_get_available_formats(tdm_layer *layer, const tbm_format **formats, int *count)
948 TDM_RETURN_VAL_IF_FAIL(formats != NULL, TDM_ERROR_INVALID_PARAMETER);
949 TDM_RETURN_VAL_IF_FAIL(count != NULL, TDM_ERROR_INVALID_PARAMETER);
951 pthread_mutex_lock(&private_display->lock);
953 *formats = (const tbm_format*)private_layer->caps.formats;
954 *count = private_layer->caps.format_count;
956 pthread_mutex_unlock(&private_display->lock);
962 tdm_layer_get_available_properties(tdm_layer *layer, const tdm_prop **props, int *count)
966 TDM_RETURN_VAL_IF_FAIL(props != NULL, TDM_ERROR_INVALID_PARAMETER);
967 TDM_RETURN_VAL_IF_FAIL(count != NULL, TDM_ERROR_INVALID_PARAMETER);
969 pthread_mutex_lock(&private_display->lock);
971 *props = (const tdm_prop*)private_layer->caps.props;
972 *count = private_layer->caps.prop_count;
974 pthread_mutex_unlock(&private_display->lock);
980 tdm_layer_get_zpos(tdm_layer *layer, unsigned int *zpos)
984 TDM_RETURN_VAL_IF_FAIL(zpos != NULL, TDM_ERROR_INVALID_PARAMETER);
986 pthread_mutex_lock(&private_display->lock);
988 *zpos = private_layer->caps.zpos;
990 pthread_mutex_unlock(&private_display->lock);
996 tdm_layer_set_property(tdm_layer *layer, unsigned int id, tdm_value value)
998 tdm_func_layer *func_layer;
1001 pthread_mutex_lock(&private_display->lock);
1003 func_layer = &private_display->func_layer;
1005 if (!func_layer->layer_set_property)
1007 pthread_mutex_unlock(&private_display->lock);
1008 return TDM_ERROR_NONE;
1011 ret = func_layer->layer_set_property(private_layer->layer_backend, id, value);
1013 pthread_mutex_unlock(&private_display->lock);
1019 tdm_layer_get_property(tdm_layer *layer, unsigned int id, tdm_value *value)
1021 tdm_func_layer *func_layer;
1024 TDM_RETURN_VAL_IF_FAIL(value != NULL, TDM_ERROR_INVALID_PARAMETER);
1026 pthread_mutex_lock(&private_display->lock);
1028 func_layer = &private_display->func_layer;
1030 if (!func_layer->layer_get_property)
1032 pthread_mutex_unlock(&private_display->lock);
1033 return TDM_ERROR_NONE;
1036 ret = func_layer->layer_get_property(private_layer->layer_backend, id, value);
1038 pthread_mutex_unlock(&private_display->lock);
1044 tdm_layer_set_info(tdm_layer *layer, tdm_info_layer *info)
1046 tdm_func_layer *func_layer;
1049 TDM_RETURN_VAL_IF_FAIL(info != NULL, TDM_ERROR_INVALID_PARAMETER);
1051 pthread_mutex_lock(&private_display->lock);
1053 func_layer = &private_display->func_layer;
1055 private_layer->usable = 0;
1057 if (!func_layer->layer_set_info)
1059 pthread_mutex_unlock(&private_display->lock);
1060 return TDM_ERROR_NONE;
1063 ret = func_layer->layer_set_info(private_layer->layer_backend, info);
1065 pthread_mutex_unlock(&private_display->lock);
1071 tdm_layer_get_info(tdm_layer *layer, tdm_info_layer *info)
1073 tdm_func_layer *func_layer;
1076 TDM_RETURN_VAL_IF_FAIL(info != NULL, TDM_ERROR_INVALID_PARAMETER);
1078 pthread_mutex_lock(&private_display->lock);
1080 func_layer = &private_display->func_layer;
1082 if (!func_layer->layer_get_info)
1084 pthread_mutex_unlock(&private_display->lock);
1085 return TDM_ERROR_NONE;
1088 ret = func_layer->layer_get_info(private_layer->layer_backend, info);
1090 pthread_mutex_unlock(&private_display->lock);
1096 tdm_layer_set_buffer(tdm_layer *layer, tbm_surface_h buffer)
1098 tdm_func_layer *func_layer;
1101 TDM_RETURN_VAL_IF_FAIL(buffer != NULL, TDM_ERROR_INVALID_PARAMETER);
1103 pthread_mutex_lock(&private_display->lock);
1105 func_layer = &private_display->func_layer;
1107 private_layer->usable = 0;
1109 if (!func_layer->layer_set_buffer)
1111 pthread_mutex_unlock(&private_display->lock);
1112 return TDM_ERROR_NONE;
1115 if (private_layer->waiting_buffer)
1117 pthread_mutex_unlock(&private_display->lock);
1118 tdm_buffer_unref_backend(private_layer->waiting_buffer);
1119 pthread_mutex_lock(&private_display->lock);
1122 private_layer->waiting_buffer = tdm_buffer_ref_backend(buffer);
1124 ret = func_layer->layer_set_buffer(private_layer->layer_backend, buffer);
1126 pthread_mutex_unlock(&private_display->lock);
1132 tdm_layer_unset_buffer(tdm_layer *layer)
1134 tdm_func_layer *func_layer;
1137 pthread_mutex_lock(&private_display->lock);
1139 func_layer = &private_display->func_layer;
1141 if (private_layer->waiting_buffer)
1143 pthread_mutex_unlock(&private_display->lock);
1144 tdm_buffer_unref_backend(private_layer->waiting_buffer);
1145 pthread_mutex_lock(&private_display->lock);
1146 private_layer->waiting_buffer = NULL;
1149 if (private_layer->showing_buffer)
1151 pthread_mutex_unlock(&private_display->lock);
1152 tdm_buffer_unref_backend(private_layer->showing_buffer);
1153 pthread_mutex_lock(&private_display->lock);
1154 private_layer->showing_buffer = NULL;
1157 private_layer->usable = 1;
1159 if (!func_layer->layer_unset_buffer)
1161 pthread_mutex_unlock(&private_display->lock);
1162 return TDM_ERROR_NONE;
1165 ret = func_layer->layer_unset_buffer(private_layer->layer_backend);
1167 pthread_mutex_unlock(&private_display->lock);
1173 _tbm_layer_queue_acquirable_cb(tbm_surface_queue_h surface_queue, void *data)
1175 TDM_RETURN_IF_FAIL(data != NULL);
1176 tdm_layer *layer = data;
1177 tdm_func_layer *func_layer;
1178 tbm_surface_h surface = NULL;
1179 LAYER_FUNC_ENTRY_VOID_RETURN();
1181 pthread_mutex_lock(&private_display->lock);
1183 func_layer = &private_display->func_layer;
1184 if (!func_layer->layer_set_buffer)
1186 pthread_mutex_unlock(&private_display->lock);
1190 if (TBM_SURFACE_QUEUE_ERROR_NONE != tbm_surface_queue_acquire(private_layer->buffer_queue, &surface) ||
1193 TDM_ERR("tbm_surface_queue_acquire() failed surface:%p", surface);
1194 pthread_mutex_unlock(&private_display->lock);
1198 if (private_layer->waiting_buffer)
1200 pthread_mutex_unlock(&private_display->lock);
1201 tdm_buffer_unref_backend(private_layer->waiting_buffer);
1202 tbm_surface_queue_release(private_layer->buffer_queue, private_layer->waiting_buffer);
1203 pthread_mutex_lock(&private_display->lock);
1206 private_layer->waiting_buffer = tdm_buffer_ref_backend(surface);
1208 func_layer->layer_set_buffer(private_layer->layer_backend, surface);
1210 ret = _tdm_output_commit(private_layer->private_output, 0, NULL, NULL);
1211 if (ret != TDM_ERROR_NONE)
1212 TDM_ERR("_tdm_output_commit() is fail");
1214 pthread_mutex_unlock(&private_display->lock);
1218 _tbm_layer_queue_destroy_cb(tbm_surface_queue_h surface_queue, void *data)
1220 TDM_RETURN_IF_FAIL(data != NULL);
1221 tdm_layer *layer = data;
1222 LAYER_FUNC_ENTRY_VOID_RETURN();
1223 TDM_RETURN_IF_FAIL(ret == TDM_ERROR_NONE);
1225 pthread_mutex_lock(&private_display->lock);
1227 if (private_layer->waiting_buffer)
1229 pthread_mutex_unlock(&private_display->lock);
1230 tdm_buffer_unref_backend(private_layer->waiting_buffer);
1231 tbm_surface_queue_release(private_layer->buffer_queue, private_layer->waiting_buffer);
1232 pthread_mutex_lock(&private_display->lock);
1235 private_layer->buffer_queue = NULL;
1237 pthread_mutex_unlock(&private_display->lock);
1241 tdm_layer_set_buffer_queue(tdm_layer *layer, tbm_surface_queue_h buffer_queue)
1243 tdm_func_layer *func_layer;
1246 TDM_RETURN_VAL_IF_FAIL(buffer_queue != NULL, TDM_ERROR_INVALID_PARAMETER);
1248 pthread_mutex_lock(&private_display->lock);
1250 func_layer = &private_display->func_layer;
1252 private_layer->usable = 0;
1254 if (!func_layer->layer_set_buffer)
1256 pthread_mutex_unlock(&private_display->lock);
1257 return TDM_ERROR_NONE;
1260 if (buffer_queue == private_layer->buffer_queue)
1262 pthread_mutex_unlock(&private_display->lock);
1263 return TDM_ERROR_NONE;
1266 if (private_layer->waiting_buffer)
1268 pthread_mutex_unlock(&private_display->lock);
1269 tdm_buffer_unref_backend(private_layer->waiting_buffer);
1270 tbm_surface_queue_release(private_layer->buffer_queue, private_layer->waiting_buffer);
1271 private_layer->waiting_buffer = NULL;
1272 pthread_mutex_lock(&private_display->lock);
1275 private_layer->buffer_queue = buffer_queue;
1276 tbm_surface_queue_set_acquirable_cb(private_layer->buffer_queue,
1277 _tbm_layer_queue_acquirable_cb,
1279 tbm_surface_queue_set_destroy_cb(private_layer->buffer_queue,
1280 _tbm_layer_queue_destroy_cb,
1282 pthread_mutex_unlock(&private_display->lock);
1288 tdm_layer_unset_buffer_queue(tdm_layer *layer)
1290 tdm_func_layer *func_layer;
1293 pthread_mutex_lock(&private_display->lock);
1295 func_layer = &private_display->func_layer;
1297 if (private_layer->waiting_buffer)
1299 pthread_mutex_unlock(&private_display->lock);
1300 tdm_buffer_unref_backend(private_layer->waiting_buffer);
1301 tbm_surface_queue_release(private_layer->buffer_queue, private_layer->waiting_buffer);
1302 private_layer->waiting_buffer = NULL;
1303 pthread_mutex_lock(&private_display->lock);
1306 if (private_layer->showing_buffer)
1308 pthread_mutex_unlock(&private_display->lock);
1309 tdm_buffer_unref_backend(private_layer->showing_buffer);
1310 tbm_surface_queue_release(private_layer->buffer_queue, private_layer->showing_buffer);
1311 pthread_mutex_lock(&private_display->lock);
1312 private_layer->showing_buffer = NULL;
1315 tbm_surface_queue_set_acquirable_cb(private_layer->buffer_queue, NULL, NULL);
1316 tbm_surface_queue_set_destroy_cb(private_layer->buffer_queue, NULL, NULL);
1317 private_layer->buffer_queue = NULL;
1318 private_layer->usable = 1;
1320 if (!func_layer->layer_unset_buffer)
1322 pthread_mutex_unlock(&private_display->lock);
1323 return TDM_ERROR_NONE;
1326 ret = func_layer->layer_unset_buffer(private_layer->layer_backend);
1328 pthread_mutex_unlock(&private_display->lock);
1334 tdm_layer_is_usable(tdm_layer *layer, unsigned int *usable)
1338 TDM_RETURN_VAL_IF_FAIL(usable != NULL, TDM_ERROR_INVALID_PARAMETER);
1340 pthread_mutex_lock(&private_display->lock);
1342 *usable = private_layer->usable;
1344 pthread_mutex_unlock(&private_display->lock);
1350 tdm_layer_set_video_pos(tdm_layer *layer, int zpos)
1352 tdm_func_layer *func_layer;
1355 pthread_mutex_lock(&private_display->lock);
1357 func_layer = &private_display->func_layer;
1359 if (!(private_layer->caps.capabilities & TDM_LAYER_CAPABILITY_VIDEO))
1361 TDM_ERR("layer is not video layer");
1362 pthread_mutex_unlock(&private_display->lock);
1363 return TDM_ERROR_INVALID_PARAMETER;
1366 if (!func_layer->layer_set_video_pos)
1368 pthread_mutex_unlock(&private_display->lock);
1369 return TDM_ERROR_NONE;
1372 ret = func_layer->layer_set_video_pos(private_layer->layer_backend, zpos);
1374 pthread_mutex_unlock(&private_display->lock);
1380 tdm_layer_create_capture(tdm_layer *layer, tdm_error *error)
1382 tdm_capture *capture = NULL;
1384 LAYER_FUNC_ENTRY_ERROR();
1386 pthread_mutex_lock(&private_display->lock);
1388 capture = (tdm_capture*)tdm_capture_create_layer_internal(private_layer, error);
1390 pthread_mutex_unlock(&private_display->lock);