vblank: move the set-client-vblank-fps function to server function
[platform/core/uifw/libtdm.git] / client / tdm_client.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_CLIENT_H_
37 #define _TDM_CLIENT_H_
38
39 #ifdef __cplusplus
40 extern "C" {
41 #endif
42
43 /**
44  * @file tdm_client.h
45  * @brief The header file for a client of TDM.
46  * @par Example
47  * @code
48  * #include <tdm_client.h>    //for a client of TDM
49  * @endcode
50  */
51
52 #include <tdm_client_types.h>
53
54 /**
55  * @brief Create a TDM client object.
56  * @param[out] error #TDM_ERROR_NONE if success. Otherwise, error value.
57  * @return A TDM client object if success. Otherwise, NULL.
58  * @see #tdm_client_destroy
59  */
60 tdm_client*
61 tdm_client_create(tdm_error *error);
62
63 /**
64  * @brief Destroy a TDM client object
65  * @param[in] client A TDM client object
66  * @see #tdm_client_create
67  */
68 void
69 tdm_client_destroy(tdm_client *client);
70
71 /**
72  * @brief Get the file descriptor
73  * @param[in] client A TDM client object
74  * @param[out] fd The file descriptor
75  * @return #TDM_ERROR_NONE if success. Otherwise, error value.
76  * @see #tdm_client_handle_events
77  * @par Example
78  * @code
79  * #include <tdm_client.h>    //for a client of TDM
80  *
81  * err = tdm_client_get_fd(client, &fd);
82  * if (err != TDM_ERROR_NONE) {
83  *     //error handling
84  * }
85  *
86  * fds.events = POLLIN;
87  * fds.fd = fd;
88  * fds.revents = 0;
89  *
90  * while(1) {
91  *    ret = poll(&fds, 1, -1);
92  *    if (ret < 0) {
93  *       if (errno == EINTR || errno == EAGAIN)
94  *          continue;
95  *       else {
96  *          //error handling
97  *       }
98  *    }
99  *
100  *    err = tdm_client_handle_events(client);
101  *    if (err != TDM_ERROR_NONE) {
102  *        //error handling
103  *    }
104  * }
105  * @endcode
106  */
107 tdm_error
108 tdm_client_get_fd(tdm_client *client, int *fd);
109
110 /**
111  * @brief Handle the events of the given file descriptor
112  * @param[in] client A TDM client object
113  * @return #TDM_ERROR_NONE if success. Otherwise, error value.
114  * @see #tdm_client_get_fd
115  */
116 tdm_error
117 tdm_client_handle_events(tdm_client *client);
118
119 /**
120  * @brief @b Deprecated. Wait for VBLANK.
121  * @deprecated
122  * @details After interval vblanks, a client vblank handler will be called.
123  * If 'sw_timer' param is 1 in case of DPMS off, TDM will use the SW timer and
124  * call a client vblank handler. Otherwise, this function will return error.
125  * @param[in] client A TDM client object
126  * @param[in] name The name of a TDM output
127  * @param[in] sw_timer 0: not using SW timer, 1: using SW timer
128  * @param[in] interval vblank interval
129  * @param[in] sync 0: asynchronous, 1:synchronous
130  * @param[in] func A client vblank handler
131  * @param[in] user_data The user data
132  * @return #TDM_ERROR_NONE if success. Otherwise, error value.
133  * @see #tdm_client_vblank_handler
134  */
135 tdm_error
136 tdm_client_wait_vblank(tdm_client *client, char *name,
137                                            int sw_timer, int interval, int sync,
138                                            tdm_client_vblank_handler2 func, void *user_data);
139
140 /**
141  * @brief Get the client output object which has the given name.
142  * @details
143  * The client output name can be @b 'primary' or @b 'default' to get the main output.
144  * @param[in] client The TDM client object
145  * @param[in] name The name of the TDM client output object
146  * @param[out] error #TDM_ERROR_NONE if success. Otherwise, error value.
147  * @return A client output object if success. Otherwise, NULL.
148  */
149 tdm_client_output*
150 tdm_client_get_output(tdm_client *client, char *name, tdm_error *error);
151
152 /**
153  * @brief Add the client output change handler
154  * @details The handler will be called when the status of a
155  * client output object is changed. connection, DPMS, etc.
156  * @param[in] output The client output object
157  * @param[in] func The client output change handler
158  * @param[in] user_data The user data
159  * @return #TDM_ERROR_NONE if success. Otherwise, error value.
160  * @par Example
161  * @code
162  * #include <tdm_client.h>    //for a client of TDM
163  *
164  * static void
165  * _client_output_handler(tdm_client_output *output, tdm_output_change_type type,
166  *                        tdm_value value, void *user_data)
167  * {
168  *     char *conn_str[3] = {"disconnected", "connected", "mode_setted"};
169  *     char *dpms_str[4] = {"on", "standy", "suspend", "off"};
170  *
171  *     if (type == TDM_OUTPUT_CHANGE_CONNECTION)
172  *         printf("output %s.\n", conn_str[value.u32]);
173  *     else if (type == TDM_OUTPUT_CHANGE_DPMS)
174  *         printf("dpms %s.\n", dpms_str[value.u32]);
175  * }
176  * ...
177  * tdm_client_output_add_change_handler(output, _client_output_handler, NULL);
178  * ...
179  * tdm_client_output_remove_change_handler(output, _client_output_handler, NULL);
180  *
181  * @endcode
182  */
183 tdm_error
184 tdm_client_output_add_change_handler(tdm_client_output *output,
185                                                                          tdm_client_output_change_handler func,
186                                                                          void *user_data);
187
188 /**
189  * @brief Remove the client output change handler
190  * @param[in] output The client output object
191  * @param[in] func The client output change handler
192  * @param[in] user_data The user data
193  * @return #TDM_ERROR_NONE if success. Otherwise, error value.
194  */
195 void
196 tdm_client_output_remove_change_handler(tdm_client_output *output,
197                                                                                 tdm_client_output_change_handler func,
198                                                                                 void *user_data);
199
200 /**
201  * @brief Get the vertical refresh rate of the given client output
202  * @param[in] output The client output object
203  * @param[out] refresh The refresh rate
204  * @return #TDM_ERROR_NONE if success. Otherwise, error value.
205  */
206 tdm_error
207 tdm_client_output_get_refresh_rate(tdm_client_output *output, unsigned int *refresh);
208
209 /**
210  * @brief Get the connection status of the given client output
211  * @param[in] output The client output object
212  * @param[out] status The connection status
213  * @return #TDM_ERROR_NONE if success. Otherwise, error value.
214  */
215 tdm_error
216 tdm_client_output_get_conn_status(tdm_client_output *output, tdm_output_conn_status *status);
217
218 /**
219  * @brief Get the DPMS value of the given client output
220  * @param[in] output The client output object
221  * @param[out] dpms The DPMS value
222  * @return #TDM_ERROR_NONE if success. Otherwise, error value.
223  */
224 tdm_error
225 tdm_client_output_get_dpms(tdm_client_output *output, tdm_output_dpms *dpms);
226
227 /**
228  * @brief Create the client vblank object of the given client output
229  * @param[in] output The client output object
230  * @param[out] error #TDM_ERROR_NONE if success. Otherwise, error value.
231  * @return A client vblank object if success. Otherwise, NULL.
232  */
233 tdm_client_vblank*
234 tdm_client_output_create_vblank(tdm_client_output *output, tdm_error *error);
235
236 /**
237  * @brief Destroy the client vblank object
238  * @param[in] vblank The client vblank object
239  */
240 void
241 tdm_client_vblank_destroy(tdm_client_vblank *vblank);
242
243 /**
244  * @brief Set the name to the client vblank object
245  * @param[in] vblank The client vblank object
246  * @param[in] name The client vblank name
247  * @return #TDM_ERROR_NONE if success. Otherwise, error value.
248  */
249 tdm_error
250 tdm_client_vblank_set_name(tdm_client_vblank *vblank, const char *name);
251
252 /**
253  * @brief Set the sync value to the client vblank object
254  * @details
255  * If sync == 1, the user client vblank handler of #tdm_client_vblank_wait
256  * will be called before #tdm_client_vblank_wait returns the result. If sync == 0,
257  * the user client vblank handler of #tdm_client_vblank_wait will be called
258  * asynchronously after #tdm_client_vblank_wait returns. Default is @b asynchronous.
259  * @param[in] vblank The client vblank object
260  * @param[in] sync 0: asynchronous, 1:synchronous
261  * @return #TDM_ERROR_NONE if success. Otherwise, error value.
262  */
263 tdm_error
264 tdm_client_vblank_set_sync(tdm_client_vblank *vblank, unsigned int sync);
265
266 /**
267  * @brief Set the fps to the client vblank object
268  * @details Default is the @b vertical @b refresh @b rate of the given client output.
269  * @param[in] vblank The client vblank object
270  * @param[in] fps more than 0
271  * @return #TDM_ERROR_NONE if success. Otherwise, error value.
272  */
273 tdm_error
274 tdm_client_vblank_set_fps(tdm_client_vblank *vblank, unsigned int fps);
275
276 /**
277  * @brief Set the offset(milli-second) to the client vblank object
278  * @details Default is @b 0.
279  * @param[in] vblank The client vblank object
280  * @param[in] offset_ms the offset(milli-second)
281  * @return #TDM_ERROR_NONE if success. Otherwise, error value.
282  */
283 tdm_error
284 tdm_client_vblank_set_offset(tdm_client_vblank *vblank, int offset_ms);
285
286 /**
287  * @brief Enable/Disable the fake vblank to the client vblank object
288  * @details
289  * If enable_fake == 0, #tdm_client_vblank_wait will return TDM_ERROR_DPMS_OFF
290  * when DPMS off. Otherwise, #tdm_client_vblank_wait will return TDM_ERROR_NONE
291  * as success. Once #tdm_client_vblank_wait returns TDM_ERROR_NONE, the user client
292  * vblank handler(#tdm_client_vblank_handler) SHOULD be called after the given
293  * interval of #tdm_client_vblank_wait. Default is @b disable.
294  * @param[in] vblank The client vblank object
295  * @param[in] enable_fake 1:enable, 0:disable
296  * @return #TDM_ERROR_NONE if success. Otherwise, error value.
297  */
298 tdm_error
299 tdm_client_vblank_set_enable_fake(tdm_client_vblank *vblank, unsigned int enable_fake);
300
301 /**
302  * @brief Wait for a vblank
303  * @details
304  * This function will return TDM_ERROR_DPMS_OFF when DPMS off. However,
305  * #tdm_client_vblank_wait will return TDM_ERROR_NONE as success if
306  * #tdm_client_vblank_set_enable_fake sets true. Once #tdm_client_vblank_wait
307  * returns TDM_ERROR_NONE, the user client vblank handler(#tdm_client_vblank_handler)
308  * SHOULD be called after the given interval. \n
309  * The sequence value of tdm_client_vblank_handler is the relative value of fps.
310  * If fps = 10, this sequence value should be increased by 10 during 1 second.
311  * @param[in] vblank The client vblank object
312  * @param[in] interval The vblank interval
313  * @param[in] func The user client vblank handler
314  * @param[in] user_data The user data
315  * @return #TDM_ERROR_NONE if success. Otherwise, error value.
316  * @par Example
317  * @code
318  * #include <tdm_client.h>    //for a client of TDM
319  *
320  * static void
321  * _client_vblank_handler(tdm_client_vblank *vblank, tdm_error error, unsigned int sequence,
322  *                        unsigned int tv_sec, unsigned int tv_usec, void *user_data)
323  * {
324  *     if (error != TDM_ERROR_NONE)
325  *         //error handling
326  * }
327  *
328  * {
329  *     tdm_client_output *output;
330  *     tdm_client_vblank *vblank;
331  *     tdm_error error;
332  *     struct pollfd fds;
333  *     int fd = -1;
334  *
335  *     cliet = tdm_client_create(&error);
336  *     if (error != TDM_ERROR_NONE)
337  *         //error handling
338  *
339  *     output = tdm_client_get_output(client, NULL, &error);
340  *     if (error != TDM_ERROR_NONE)
341  *         //error handling
342  *
343  *     vblank = tdm_client_output_create_vblank(output, &error);
344  *     if (error != TDM_ERROR_NONE)
345  *         //error handling
346  *
347  *     tdm_client_vblank_set_enable_fake(vblank, enable_fake); //default: disable
348  *     tdm_client_vblank_set_sync(vblank, 0); //default: async
349  *     tdm_client_vblank_set_fps(vblank, fps); //default: refresh rate of output
350  *     tdm_client_vblank_set_offset(vblank, offset); //default: 0
351  *
352  *     error = tdm_client_get_fd(data->client, &fd);
353  *     if (error != TDM_ERROR_NONE)
354  *         //error handling
355  *
356  *     fds.events = POLLIN;
357  *     fds.fd = fd;
358  *     fds.revents = 0;
359  *
360  *     while (1) {
361  *         int ret;
362  *
363  *         error = tdm_client_vblank_wait(vblank, interval,
364  *                                        _client_vblank_handler, NULL);
365  *         if (error != TDM_ERROR_NONE)
366  *             //error handling
367  *
368  *         ret = poll(&fds, 1, -1);
369  *         if (ret < 0) {
370  *             if (errno == EINTR || errno == EAGAIN)  // normal case
371  *                 continue;
372  *             else
373  *                 //error handling
374  *         }
375  *
376  *         error = tdm_client_handle_events(client);
377  *         if (error != TDM_ERROR_NONE)
378  *             //error handling
379  *     }
380  *
381  *     tdm_client_vblank_destroy(vblank);
382  *     tdm_client_destroy(client);
383  * }
384  * @endcode
385  */
386 tdm_error
387 tdm_client_vblank_wait(tdm_client_vblank *vblank, unsigned int interval, tdm_client_vblank_handler func, void *user_data);
388
389 /**
390  * @brief Wait for a vblank with the target sequence number
391  * @details
392  * This function will return TDM_ERROR_DPMS_OFF when DPMS off. However,
393  * #tdm_client_vblank_wait will return TDM_ERROR_NONE as success if
394  * #tdm_client_vblank_set_enable_fake sets true. Once #tdm_client_vblank_wait_seq
395  * returns TDM_ERROR_NONE, the user client vblank handler(#tdm_client_vblank_handler)
396  * SHOULD be called on reaching the target sequence.
397  * @param[in] vblank The client vblank object
398  * @param[in] sequence The target sequence number
399  * @param[in] func The user client vblank handler
400  * @param[in] user_data The user data
401  * @return #TDM_ERROR_NONE if success. Otherwise, error value.
402  */
403 tdm_error
404 tdm_client_vblank_wait_seq(tdm_client_vblank *vblank, unsigned int sequence, tdm_client_vblank_handler func, void *user_data);
405
406 #ifdef __cplusplus
407 }
408 #endif
409
410 #endif /* _TDM_CLIENT_H_ */