Package version up to 2.7.1
[platform/core/uifw/libtdm.git] / include / tdm_helper.h
1 /**************************************************************************
2  *
3  * libtdm
4  *
5  * Copyright 2015 Samsung Electronics co., Ltd. All Rights Reserved.
6  *
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>
13  *
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:
21  *
22  * The above copyright notice and this permission notice (including the
23  * next paragraph) shall be included in all copies or substantial portions
24  * of the Software.
25  *
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.
33  *
34 **************************************************************************/
35
36 #ifndef _TDM_HELPER_H_
37 #define _TDM_HELPER_H_
38
39 #include <tbm_surface.h>
40
41 #include "tdm_types.h"
42
43 #ifdef __cplusplus
44 extern "C" {
45 #endif
46
47 /**
48  * @file tdm_helper.h
49  * @brief The header file to help tdm backend/frontend user
50  */
51
52 /**
53  * @brief Get the current time as a floating point value in seconds
54  * @return The number of seconds
55  */
56 double
57 tdm_helper_get_time(void);
58
59 /**
60  * @brief Dump a buffer
61  * @details
62  * This function supports only if a buffer has below formats.
63  * - TBM_FORMAT_ARGB8888
64  * - TBM_FORMAT_XRGB8888
65  * - TBM_FORMAT_YVU420
66  * - TBM_FORMAT_YUV420
67  * - TBM_FORMAT_NV12
68  * - TBM_FORMAT_NV21
69  * The filename extension should be "png" for TBM_FORMAT_ARGB8888 and TBM_FORMAT_XRGB8888
70  * or "yuv" for YUV formats.
71  * @param[in] buffer A TDM buffer
72  * @param[in] file The path of file.
73  */
74 void
75 tdm_helper_dump_buffer(tbm_surface_h buffer, const char *file);
76
77 /**
78  * @brief Dump a buffer.
79  * @details
80  * The filename will includes the buffer information. (width, height, format)
81  * @param[in] buffer A TDM buffer
82  * @param[in] file The path of file.
83  */
84 void
85 tdm_helper_dump_buffer_str(tbm_surface_h buffer, char *dir, char *str);
86
87 /**
88  * @brief fill a buffer with 0 for given pos.
89  * @details
90  * This function supports only if a buffer has below formats.
91  * - TBM_FORMAT_ARGB8888
92  * - TBM_FORMAT_XRGB8888
93  * @param[in] buffer A TDM buffer
94  */
95 void
96 tdm_helper_clear_buffer_pos(tbm_surface_h buffer, tdm_pos *pos);
97
98 /**
99  * @brief fill a buffer with 0 for given pos.
100  * @details
101  * This function supports only if a buffer has below formats.
102  * - TBM_FORMAT_ARGB8888
103  * - TBM_FORMAT_XRGB8888
104  * @param[in] buffer A TDM buffer
105  */
106 void
107 tdm_helper_clear_buffer_color(tbm_surface_h buffer, tdm_pos *pos, unsigned int color);
108
109 /**
110  * @brief fill a buffer with 0.
111  * @details
112  * This function supports only if a buffer has below formats.
113  * - TBM_FORMAT_ARGB8888
114  * - TBM_FORMAT_XRGB8888
115  * - TBM_FORMAT_YVU420
116  * - TBM_FORMAT_YUV420
117  * - TBM_FORMAT_NV12
118  * - TBM_FORMAT_NV21
119  * @param[in] buffer A TDM buffer
120  */
121 void
122 tdm_helper_clear_buffer(tbm_surface_h buffer);
123
124 /**
125  * @brief Get the buffer full size.
126  * @details
127  * In some hardware, the buffer width or height is aligned with the fixed size.
128  * eg. 8, 16, etc. In this case, the real size of buffer could be bigger than
129  * the buffer size of tbm_surface_info_s.
130  * @param[in] buffer A TDM buffer
131  */
132 void
133 tdm_helper_get_buffer_full_size(tbm_surface_h buffer, int *buffer_w, int *buffer_h);
134
135 /**
136  * @brief convert the source buffer to the destination buffer with given rectangles
137  * trannsform
138  * @details
139  * This function supports only if buffers have below formats.
140  * - TBM_FORMAT_ARGB8888
141  * - TBM_FORMAT_XRGB8888
142  * @param[in] buffer A TDM buffer
143  */
144 tdm_error
145 tdm_helper_convert_buffer(tbm_surface_h srcbuf, tbm_surface_h dstbuf,
146                                                   tdm_pos *srcpos, tdm_pos *dstpos,
147                                                   tdm_transform transform, int over);
148
149 /**
150  * @brief Get a fd from the given enviroment variable.
151  * @details
152  * This function will dup the fd of the given enviroment variable. The Caller
153  * @b SHOULD close the fd.
154  * @param[in] env The given enviroment variable
155  * @return fd if success. Otherwise, -1.
156  * @see #tdm_helper_set_fd()
157  */
158 int tdm_helper_get_fd(const char *env);
159
160 /**
161  * @brief Set the given fd to the give enviroment variable.
162  * @param[in] env The given enviroment variable
163  * @param[in] fd The given fd
164  * @see #tdm_helper_get_fd()
165  */
166 void tdm_helper_set_fd(const char *env, int fd);
167
168 /**
169  * @brief Start the dump debugging.
170  * @details
171  * Start tdm dump.
172  * Make dump file when tdm_layer_set_buffer() function is called.
173  * Set the dump count to 1.
174  * @param[in] dumppath The given dump path
175  * @param[in] count The dump count number
176  * @see #tdm_helper_dump_stop()
177  */
178 void
179 tdm_helper_dump_start(char *dumppath, int *count);
180
181 /**
182  * @brief Stop the dump debugging.
183  * @details
184  * Stop tdm dump.
185  * Set the dump count to 0.
186  * @see #tdm_helper_dump_start()
187  */
188 void
189 tdm_helper_dump_stop(void);
190
191 /**
192  * @brief The tdm helper capture handler
193  * @details
194  * This handler will be called when composit image produced.
195  * @see #tdm_helper_capture_output() function
196  */
197 typedef void (*tdm_helper_capture_handler)(tbm_surface_h buffer, void *user_data);
198
199 /**
200  * @brief Make an output's image surface.
201  * @details Composit specific output's all layer's buffer to dst_buffer surface.
202  * After composing, tdm_helper_capture_handler func will be called.
203  * @param[in] output A output object
204  * @param[in] dst_buffer A surface composite image saved
205  * @param[in] x A horizontal position of composite image on dst_buffer
206  * @param[in] y A vertical position of composite image on dst_buffer
207  * @param[in] w A composite image width
208  * @param[in] h A composite image height
209  * @param[in] func A composing done handler
210  * @param[in] user_data The user data
211  * @return #TDM_ERROR_NONE if success. Otherwise, error value.
212  */
213 tdm_error
214 tdm_helper_capture_output(tdm_output *output, tbm_surface_h dst_buffer,
215                                                   int x, int y, int w, int h,
216                                                   tdm_helper_capture_handler func, void *data);
217
218 /**
219  * @brief Fill the display information to the reply buffer as string.
220  * @param[in] dpy A display object
221  * @param[out] reply the string buffer to be filled by this function.
222  * @param[out] len the length of the reply buffer
223  */
224 void
225 tdm_helper_get_display_information(tdm_display *dpy, char *reply, int *len);
226
227 /**
228  * @brief Get whether the commit-per-vblank functionality is enabled or not for the output.
229  * @param[in] output An output the functionality has to be checked for
230  * @return -1 if error occurred, 1 if enabled, 0 if disabled.
231  */
232 int
233 tdm_helper_output_commit_per_vblank_enabled(tdm_output *output);
234
235 /**
236  * @brief Get whether the vblank timer is expired or not for the output.
237  * @param[in] output An output the functionality has to be checked for
238  * @return -1 if error occurred, 1 if enabled, 0 if disabled.
239  */
240 unsigned int
241 tdm_helper_output_vblank_timer_expired(tdm_output *output);
242
243 #ifdef __cplusplus
244 }
245 #endif
246
247 #endif /* _TDM_HELPER_H_ */