fa8260248382c3dc1389f9603b18321434e9954a
[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 <sc1.lim@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  * - TBM_FORMAT_YUYV
70  * - TBM_FORMAT_UYVY
71  * The filename extension should be "png" for TBM_FORMAT_ARGB8888 and TBM_FORMAT_XRGB8888
72  * or "yuv" for YUV formats.
73  * @param[in] buffer A TDM buffer
74  * @param[in] file The path of file.
75  */
76 void
77 tdm_helper_dump_buffer(tbm_surface_h buffer, const char *file);
78
79 /**
80  * @brief Dump a buffer.
81  * @details
82  * The filename will includes the buffer information. (width, height, format)
83  * @param[in] buffer A TDM buffer
84  * @param[in] file The path of file.
85  */
86 void
87 tdm_helper_dump_buffer_str(tbm_surface_h buffer, char *dir, char *str);
88
89 /**
90  * @brief fill a buffer with 0 for given pos.
91  * @details
92  * This function supports only if a buffer has below formats.
93  * - TBM_FORMAT_ARGB8888
94  * - TBM_FORMAT_XRGB8888
95  * @param[in] buffer A TDM buffer
96  */
97 void
98 tdm_helper_clear_buffer_pos(tbm_surface_h buffer, tdm_pos *pos);
99
100 /**
101  * @brief fill a buffer with 0 for given pos.
102  * @details
103  * This function supports only if a buffer has below formats.
104  * - TBM_FORMAT_ARGB8888
105  * - TBM_FORMAT_XRGB8888
106  * @param[in] buffer A TDM buffer
107  */
108 void
109 tdm_helper_clear_buffer_color(tbm_surface_h buffer, tdm_pos *pos, unsigned int color);
110
111 /**
112  * @brief fill a buffer with 0.
113  * @details
114  * This function supports only if a buffer has below formats.
115  * - TBM_FORMAT_ARGB8888
116  * - TBM_FORMAT_XRGB8888
117  * - TBM_FORMAT_YVU420
118  * - TBM_FORMAT_YUV420
119  * - TBM_FORMAT_NV12
120  * - TBM_FORMAT_NV21
121  * - TBM_FORMAT_YUYV
122  * - TBM_FORMAT_UYVY
123  * @param[in] buffer A TDM buffer
124  */
125 void
126 tdm_helper_clear_buffer(tbm_surface_h buffer);
127
128 /**
129  * @brief Get the buffer full size.
130  * @details
131  * In some hardware, the buffer width or height is aligned with the fixed size.
132  * eg. 8, 16, etc. In this case, the real size of buffer could be bigger than
133  * the buffer size of tbm_surface_info_s.
134  * @param[in] buffer A TDM buffer
135  */
136 void
137 tdm_helper_get_buffer_full_size(tbm_surface_h buffer, int *buffer_w, int *buffer_h);
138
139 /**
140  * @brief convert the source buffer to the destination buffer with given rectangles
141  * trannsform
142  * @details
143  * This function supports only if buffers have below formats.
144  * - TBM_FORMAT_ARGB8888
145  * - TBM_FORMAT_XRGB8888
146  * @param[in] buffer A TDM buffer
147  */
148 tdm_error
149 tdm_helper_convert_buffer(tbm_surface_h srcbuf, tbm_surface_h dstbuf,
150                                                   tdm_pos *srcpos, tdm_pos *dstpos,
151                                                   tdm_transform transform, int over);
152
153 /**
154  * @brief Get a fd from the given enviroment variable.
155  * @details
156  * This function will dup the fd of the given enviroment variable. The Caller
157  * @b SHOULD close the fd.
158  * @param[in] env The given enviroment variable
159  * @return fd if success. Otherwise, -1.
160  * @see #tdm_helper_set_fd()
161  */
162 int tdm_helper_get_fd(const char *env);
163
164 /**
165  * @brief Set the given fd to the give enviroment variable.
166  * @param[in] env The given enviroment variable
167  * @param[in] fd The given fd
168  * @see #tdm_helper_get_fd()
169  */
170 void tdm_helper_set_fd(const char *env, int fd);
171
172 /**
173  * @brief Start the dump debugging.
174  * @details
175  * Start tdm dump.
176  * Make dump file when tdm_layer_set_buffer() function is called.
177  * Set the dump count to 1.
178  * @param[in] dumppath The given dump path
179  * @param[in] count The dump count number
180  * @see #tdm_helper_dump_stop()
181  */
182 void
183 tdm_helper_dump_start(char *dumppath, int *count);
184
185 /**
186  * @brief Stop the dump debugging.
187  * @details
188  * Stop tdm dump.
189  * Set the dump count to 0.
190  * @see #tdm_helper_dump_start()
191  */
192 void
193 tdm_helper_dump_stop(void);
194
195 /**
196  * @brief The tdm helper capture handler
197  * @details
198  * This handler will be called when composit image produced.
199  * @see #tdm_helper_capture_output() function
200  */
201 typedef void (*tdm_helper_capture_handler)(tbm_surface_h buffer, void *user_data);
202
203 /**
204  * @brief Make an output's image surface.
205  * @details Composit specific output's all layer's buffer to dst_buffer surface.
206  * After composing, tdm_helper_capture_handler func will be called.
207  * @param[in] output A output object
208  * @param[in] dst_buffer A surface composite image saved
209  * @param[in] x A horizontal position of composite image on dst_buffer
210  * @param[in] y A vertical position of composite image on dst_buffer
211  * @param[in] w A composite image width
212  * @param[in] h A composite image height
213  * @param[in] func A composing done handler
214  * @param[in] user_data The user data
215  * @return #TDM_ERROR_NONE if success. Otherwise, error value.
216  */
217 tdm_error
218 tdm_helper_capture_output(tdm_output *output, tbm_surface_h dst_buffer,
219                                                   int x, int y, int w, int h,
220                                                   tdm_helper_capture_handler func, void *data);
221
222 /**
223  * @brief Fill the display information to the reply buffer as string.
224  * @param[in] dpy A display object
225  * @param[out] reply the string buffer to be filled by this function.
226  * @param[out] len the length of the reply buffer
227  */
228 void
229 tdm_helper_get_display_information(tdm_display *dpy, char *reply, int *len);
230
231 /**
232  * @brief Get whether the commit-per-vblank functionality is enabled or not for the output.
233  * @param[in] output An output the functionality has to be checked for
234  * @return -1 if error occurred, 1 if enabled, 0 if disabled.
235  */
236 int
237 tdm_helper_output_commit_per_vblank_enabled(tdm_output *output);
238
239 #ifdef __cplusplus
240 }
241 #endif
242
243 #endif /* _TDM_HELPER_H_ */