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 <boram1288.park@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 **************************************************************************/
36 #ifndef _TDM_CLIENT_H_
37 #define _TDM_CLIENT_H_
39 #include "tdm_client_types.h"
47 * @brief The header file for a client of TDM.
50 * #include <tdm_client.h> //for a client of TDM
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
61 tdm_client_create(tdm_error *error);
64 * @brief Destroy a TDM client object
65 * @param[in] client A TDM client object
66 * @see #tdm_client_create
69 tdm_client_destroy(tdm_client *client);
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
79 * #include <tdm_client.h> //for a client of TDM
81 * err = tdm_client_get_fd(client, &fd);
82 * if (err != TDM_ERROR_NONE) {
86 * fds.events = POLLIN;
91 * ret = poll(&fds, 1, -1);
93 * if (errno == EINTR || errno == EAGAIN)
100 * err = tdm_client_handle_events(client);
101 * if (err != TDM_ERROR_NONE) {
108 tdm_client_get_fd(tdm_client *client, int *fd);
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
117 tdm_client_handle_events(tdm_client *client);
120 * @brief Handle the events of the given file descriptor with millisecond timeout
122 * -1: infinite. 0: return immediately. Otherwise, waiting for ms_timeout milliseconds.
123 * @param[in] client A TDM client object
124 * @param[in] ms_timeout timeout value.
125 * @return #TDM_ERROR_NONE if success. Otherwise, error value.
126 * @see #tdm_client_get_fd
129 tdm_client_handle_events_timeout(tdm_client *client, int ms_timeout);
132 * @brief @b Deprecated. Wait for VBLANK.
134 * @details After interval vblanks, a client vblank handler will be called.
135 * If 'sw_timer' param is 1 in case of DPMS off, TDM will use the SW timer and
136 * call a client vblank handler. Otherwise, this function will return error.
137 * @param[in] client A TDM client object
138 * @param[in] name The name of a TDM output
139 * @param[in] sw_timer 0: not using SW timer, 1: using SW timer
140 * @param[in] interval vblank interval
141 * @param[in] sync 0: asynchronous, 1:synchronous
142 * @param[in] func A client vblank handler
143 * @param[in] user_data The user data
144 * @return #TDM_ERROR_NONE if success. Otherwise, error value.
145 * @see #tdm_client_vblank_handler
148 tdm_client_wait_vblank(tdm_client *client, char *name,
149 int sw_timer, int interval, int sync,
150 tdm_client_vblank_handler2 func, void *user_data);
153 * @brief Get the client output object which has the given name.
155 * The client output name can be @b 'primary' or @b 'default' to get the main output.
156 * @param[in] client The TDM client object
157 * @param[in] name The name of the TDM client output object
158 * @param[out] error #TDM_ERROR_NONE if success. Otherwise, error value.
159 * @return A client output object if success. Otherwise, NULL.
162 tdm_client_get_output(tdm_client *client, char *name, tdm_error *error);
165 * @brief Add the client output change handler
166 * @details The handler will be called when the status of a
167 * client output object is changed. connection, DPMS, etc.
168 * @param[in] output The client output object
169 * @param[in] func The client output change handler
170 * @param[in] user_data The user data
171 * @return #TDM_ERROR_NONE if success. Otherwise, error value.
174 * #include <tdm_client.h> //for a client of TDM
177 * _client_output_handler(tdm_client_output *output, tdm_output_change_type type,
178 * tdm_value value, void *user_data)
180 * char *conn_str[3] = {"disconnected", "connected", "mode_setted"};
181 * char *dpms_str[4] = {"on", "standy", "suspend", "off"};
183 * if (type == TDM_OUTPUT_CHANGE_CONNECTION)
184 * printf("output %s.\n", conn_str[value.u32]);
185 * else if (type == TDM_OUTPUT_CHANGE_DPMS)
186 * printf("dpms %s.\n", dpms_str[value.u32]);
189 * tdm_client_output_add_change_handler(output, _client_output_handler, NULL);
191 * tdm_client_output_remove_change_handler(output, _client_output_handler, NULL);
196 tdm_client_output_add_change_handler(tdm_client_output *output,
197 tdm_client_output_change_handler func,
201 * @brief Remove the client output change handler
202 * @param[in] output The client output object
203 * @param[in] func The client output change handler
204 * @param[in] user_data The user data
205 * @return #TDM_ERROR_NONE if success. Otherwise, error value.
208 tdm_client_output_remove_change_handler(tdm_client_output *output,
209 tdm_client_output_change_handler func,
213 * @brief Get the vertical refresh rate of the given client output
214 * @param[in] output The client output object
215 * @param[out] refresh The refresh rate
216 * @return #TDM_ERROR_NONE if success. Otherwise, error value.
219 tdm_client_output_get_refresh_rate(tdm_client_output *output, unsigned int *refresh);
222 * @brief Get the width and height of the given client output mode
223 * @param[in] output The client output object
224 * @param[out] width The width of output mode
225 * @param[out] height The height of output mode
226 * @return #TDM_ERROR_NONE if success. Otherwise, error value.
229 tdm_client_output_get_mode(tdm_client_output *output, unsigned int *width, unsigned int *height);
232 * @brief Get the connection status of the given client output
233 * @param[in] output The client output object
234 * @param[out] status The connection status
235 * @return #TDM_ERROR_NONE if success. Otherwise, error value.
238 tdm_client_output_get_conn_status(tdm_client_output *output, tdm_output_conn_status *status);
241 * @brief Get the DPMS value of the given client output
242 * @param[in] output The client output object
243 * @param[out] dpms The DPMS value
244 * @return #TDM_ERROR_NONE if success. Otherwise, error value.
247 tdm_client_output_get_dpms(tdm_client_output *output, tdm_output_dpms *dpms);
250 * @brief Create the client vblank object of the given client output
252 * tdm client vblank basically uses the HW vblank resource. Therefore, if HW vblank
253 * is not available for some reasons, such as output disconnection and dpms off,
254 * #tdm_client_vblank_wait will return error. If you want it to work propery in spite
255 * of these reasons, you can use #tdm_client_vblank_set_enable_fake to get SW fake
257 * @param[in] output The client output object
258 * @param[out] error #TDM_ERROR_NONE if success. Otherwise, error value.
259 * @return A client vblank object if success. Otherwise, NULL.
262 tdm_client_output_create_vblank(tdm_client_output *output, tdm_error *error);
265 * @brief Destroy the client vblank object
266 * @param[in] vblank The client vblank object
269 tdm_client_vblank_destroy(tdm_client_vblank *vblank);
272 * @brief Set the name to the client vblank object
273 * @param[in] vblank The client vblank object
274 * @param[in] name The client vblank name
275 * @return #TDM_ERROR_NONE if success. Otherwise, error value.
278 tdm_client_vblank_set_name(tdm_client_vblank *vblank, const char *name);
281 * @brief Set the sync value to the client vblank object
283 * If sync == 1, the user client vblank handler of #tdm_client_vblank_wait
284 * will be called before #tdm_client_vblank_wait returns the result. If sync == 0,
285 * the user client vblank handler of #tdm_client_vblank_wait will be called
286 * asynchronously after #tdm_client_vblank_wait returns. Default is @b asynchronous.
287 * @param[in] vblank The client vblank object
288 * @param[in] sync 0: asynchronous, 1:synchronous
289 * @return #TDM_ERROR_NONE if success. Otherwise, error value.
292 tdm_client_vblank_set_sync(tdm_client_vblank *vblank, unsigned int sync);
295 * @brief Set the fps to the client vblank object
296 * @details Default is the @b vertical @b refresh @b rate of the given client output.
297 * @param[in] vblank The client vblank object
298 * @param[in] fps more than 0
299 * @return #TDM_ERROR_NONE if success. Otherwise, error value.
302 tdm_client_vblank_set_fps(tdm_client_vblank *vblank, unsigned int fps);
305 * @brief Set the offset(milli-second) to the client vblank object
306 * @details Default is @b 0.
307 * @param[in] vblank The client vblank object
308 * @param[in] offset_ms the offset(milli-second)
309 * @return #TDM_ERROR_NONE if success. Otherwise, error value.
312 tdm_client_vblank_set_offset(tdm_client_vblank *vblank, int offset_ms);
315 * @brief Enable/Disable the fake vblank to the client vblank object
317 * If enable_fake == 0, #tdm_client_vblank_wait will return error when HW vblank is
318 * not available. Otherwise, #tdm_client_vblank_wait will return TDM_ERROR_NONE
319 * as success. Once #tdm_client_vblank_wait returns TDM_ERROR_NONE, the user client
320 * vblank handler(#tdm_client_vblank_handler) SHOULD be called after the given
321 * interval of #tdm_client_vblank_wait. Default is @b disable.
322 * @param[in] vblank The client vblank object
323 * @param[in] enable_fake 1:enable, 0:disable
324 * @return #TDM_ERROR_NONE if success. Otherwise, error value.
327 tdm_client_vblank_set_enable_fake(tdm_client_vblank *vblank, unsigned int enable_fake);
330 * @brief Wait for a vblank
332 * This function will return error when HW vblank resource is not available. However,
333 * #tdm_client_vblank_wait will return TDM_ERROR_NONE as success if
334 * #tdm_client_vblank_set_enable_fake sets true. Once #tdm_client_vblank_wait
335 * returns TDM_ERROR_NONE, the user client vblank handler(#tdm_client_vblank_handler)
336 * SHOULD be called after the given interval. \n
337 * The sequence value of tdm_client_vblank_handler is the relative value of fps.
338 * If fps = 10, this sequence value should be increased by 10 during 1 second.
339 * @param[in] vblank The client vblank object
340 * @param[in] interval The vblank interval
341 * @param[in] func The user client vblank handler
342 * @param[in] user_data The user data
343 * @return #TDM_ERROR_NONE if success. Otherwise, error value.
346 * #include <tdm_client.h> //for a client of TDM
349 * _client_vblank_handler(tdm_client_vblank *vblank, tdm_error error, unsigned int sequence,
350 * unsigned int tv_sec, unsigned int tv_usec, void *user_data)
352 * if (error != TDM_ERROR_NONE)
357 * tdm_client_output *output;
358 * tdm_client_vblank *vblank;
363 * cliet = tdm_client_create(&error);
364 * if (error != TDM_ERROR_NONE)
367 * output = tdm_client_get_output(client, NULL, &error);
368 * if (error != TDM_ERROR_NONE)
371 * vblank = tdm_client_output_create_vblank(output, &error);
372 * if (error != TDM_ERROR_NONE)
375 * tdm_client_vblank_set_enable_fake(vblank, enable_fake); //default: disable
376 * tdm_client_vblank_set_sync(vblank, 0); //default: async
377 * tdm_client_vblank_set_fps(vblank, fps); //default: refresh rate of output
378 * tdm_client_vblank_set_offset(vblank, offset); //default: 0
380 * error = tdm_client_get_fd(data->client, &fd);
381 * if (error != TDM_ERROR_NONE)
384 * fds.events = POLLIN;
391 * error = tdm_client_vblank_wait(vblank, interval,
392 * _client_vblank_handler, NULL);
393 * if (error != TDM_ERROR_NONE)
396 * ret = poll(&fds, 1, -1);
398 * if (errno == EINTR || errno == EAGAIN) // normal case
404 * error = tdm_client_handle_events(client);
405 * if (error != TDM_ERROR_NONE)
409 * tdm_client_vblank_destroy(vblank);
410 * tdm_client_destroy(client);
415 tdm_client_vblank_wait(tdm_client_vblank *vblank, unsigned int interval, tdm_client_vblank_handler func, void *user_data);
418 * @brief Wait for a vblank with the target sequence number
420 * This function will return error when HW vblank resource is not available. However,
421 * #tdm_client_vblank_wait will return TDM_ERROR_NONE as success if
422 * #tdm_client_vblank_set_enable_fake sets true. Once #tdm_client_vblank_wait_seq
423 * returns TDM_ERROR_NONE, the user client vblank handler(#tdm_client_vblank_handler)
424 * SHOULD be called on reaching the target sequence.
425 * @param[in] vblank The client vblank object
426 * @param[in] sequence The target sequence number
427 * @param[in] func The user client vblank handler
428 * @param[in] user_data The user data
429 * @return #TDM_ERROR_NONE if success. Otherwise, error value.
432 tdm_client_vblank_wait_seq(tdm_client_vblank *vblank, unsigned int sequence, tdm_client_vblank_handler func, void *user_data);
435 * @brief Check if the client vblank object is waiting a vblank event
436 * @param[in] vblank The client vblank object
437 * @return 1 if waiting. 0 if not waiting.
440 tdm_client_vblank_is_waiting(tdm_client_vblank *vblank);
445 tdm_client_create_voutput(tdm_client *client, const char *name, tdm_error *error);
448 tdm_client_voutput_destroy(tdm_client_voutput *voutput);
451 tdm_client_voutput_set_available_modes(tdm_client_voutput *voutput, const tdm_client_output_mode *modes, int count);
454 tdm_client_voutput_set_physical_size(tdm_client_voutput *voutput, unsigned int mmWidth, unsigned int mmHeight);
457 tdm_client_voutput_add_commit_handler(tdm_client_voutput *voutput, tdm_client_voutput_commit_handler func, void *user_data);
460 tdm_client_voutput_remove_commit_handler(tdm_client_voutput *voutput, tdm_client_voutput_commit_handler func, void *user_data);
463 tdm_client_voutput_get_committed_tbm_surface(tdm_client_voutput *voutput, tbm_surface_h surface);
466 tdm_client_voutput_commit_done(tdm_client_voutput *voutput);
469 tdm_client_voutput_get_client_output(tdm_client_voutput *voutput, tdm_error *error);
472 tdm_client_voutput_set_mode(tdm_client_voutput *voutput, int index);
475 tdm_client_voutput_connect(tdm_client_voutput *voutput);
478 tdm_client_voutput_disconnect(tdm_client_voutput *voutput);
479 /* End of Virtual Output */
485 #endif /* _TDM_CLIENT_H_ */