add tdm_output_set_dpms_async
[platform/core/uifw/libtdm.git] / include / tdm_backend.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_BACKEND_H_
37 #define _TDM_BACKEND_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_backend.h
49  * @brief The backend header file of TDM to implement a TDM backend module.
50  * @par Example
51  * @code
52  * #include <tdm_backend.h>
53  * @endcode
54  */
55
56 /**
57  * @brief The backend module data
58  * @details
59  * The init() function of #tdm_backend_module returns the backend module data.
60  * And it will be passed to display functions of #tdm_func_display.
61  * @see tdm_backend_module, tdm_backend_module
62  */
63 typedef void tdm_backend_data;
64
65 /**
66  * @brief The output status handler
67  * @details This handler will be called when the status of a output object is
68  * changed in runtime.
69  */
70 typedef void (*tdm_output_status_handler)(tdm_output *output,
71                                                                                   tdm_output_conn_status status,
72                                                                                   void *user_data);
73
74 /**
75  * @brief The output dpms handler
76  * @details This handler will be called when the dpms of a output object is
77  * changed in runtime.
78  */
79 typedef void (*tdm_output_dpms_handler)(tdm_output *output,
80                                                                                 tdm_output_dpms dpms,
81                                                                                 void *user_data);
82
83 /**
84  * @brief The display capabilities structure of a backend module
85  * @see The display_get_capability() function of #tdm_func_display
86  */
87 typedef struct _tdm_caps_display {
88         int max_layer_count;    /**< The maximum layer count */
89 } tdm_caps_display;
90
91 /**
92  * @brief The capabilities structure of a output object
93  * @see The output_get_capability() function of #tdm_func_output
94  */
95 typedef struct _tdm_caps_output {
96         char maker[TDM_NAME_LEN];       /**< The output maker */
97         char model[TDM_NAME_LEN];       /**< The output model */
98         char name[TDM_NAME_LEN];        /**< The output name */
99
100         tdm_output_conn_status status;  /**< The connection status */
101         tdm_output_type type;           /**< The connection type */
102         unsigned int type_id;           /**< The connection type id */
103
104         unsigned int mode_count;        /**< The count of available modes */
105         tdm_output_mode
106         *modes;         /**< The @b newly-allocated array of modes. will be freed in frontend. */
107
108         unsigned int prop_count;        /**< The count of available properties */
109         tdm_prop *props;                /**< The @b newly-allocated array of properties. will be freed in frontend. */
110
111         unsigned int mmWidth;           /**< The physical width (milimeter) */
112         unsigned int mmHeight;          /**< The physical height (milimeter) */
113         unsigned int subpixel;          /**< The subpixel */
114
115         int min_w;              /**< The minimun width */
116         int min_h;              /**< The minimun height */
117         int max_w;              /**< The maximum width */
118         int max_h;              /**< The maximum height */
119         int preferred_align;    /**< The prefered align */
120
121         tdm_output_capability capabilities;  /**< The capabilities of output. @since 1.4.1 */
122
123         int cursor_min_w;              /**< The minimun width.  @since 1.5.0 */
124         int cursor_min_h;              /**< The minimun height. @since 1.5.0 */
125         int cursor_max_w;              /**< The maximum width. @since 1.5.0 */
126         int cursor_max_h;              /**< The maximum height. @since 1.5.0 */
127         int cursor_preferred_align;    /**< The prefered align. @since 1.5.0 */
128 } tdm_caps_output;
129
130 /**
131  * @brief The capabilities structure of a layer object
132  * @see The layer_get_capability() function of #tdm_func_layer
133  */
134 typedef struct _tdm_caps_layer {
135         tdm_layer_capability capabilities;  /**< The capabilities of layer */
136
137         /**
138          * The z-order
139          * GRAPHIC layers are non-changeable. The zpos of GRAPHIC layers starts
140          * from 0. If there are 4 GRAPHIC layers, The zpos SHOULD be 0, 1, 2, 3.\n
141          * But the zpos of VIDEO layer is changeable by layer_set_video_pos() function
142          * of #tdm_func_layer. And The zpos of VIDEO layers is less than GRAPHIC
143          * layers or more than GRAPHIC layers.
144          * ie, ..., -2, -1, 4, 5, ... (if 0 <= GRAPHIC layer's zpos < 4).
145          * The zpos of VIDEO layers is @b relative. It doesn't need to start
146          * from -1 or 4. Let's suppose that there are two VIDEO layers.
147          * One has -2 zpos. Another has -4 zpos. Then -2 Video layer is higher
148          * than -4 VIDEO layer.
149         */
150         int zpos;
151
152         unsigned int format_count;      /**< The count of available formats */
153         tbm_format
154         *formats;            /**< The @b newly-allocated array of formats. will be freed in frontend. */
155
156         unsigned int prop_count;        /**< The count of available properties */
157         tdm_prop *props;                /**< The @b newly-allocated array of properties. will be freed in frontend. */
158 } tdm_caps_layer;
159
160 /**
161  * @brief The capabilities structure of a pp object
162  * @see The display_get_pp_capability() function of #tdm_func_display
163  */
164 typedef struct _tdm_caps_pp {
165         tdm_pp_capability capabilities; /**< The capabilities of pp */
166
167         unsigned int format_count;      /**< The count of available formats */
168         tbm_format
169         *formats;            /**< The @b newly-allocated array. will be freed in frontend. */
170
171         int min_w;              /**< The minimun width */
172         int min_h;              /**< The minimun height */
173         int max_w;              /**< The maximum width */
174         int max_h;              /**< The maximum height */
175         int preferred_align;    /**< The prefered align */
176
177         /**< The attach count which a PP object can handle. @since 1.2.0 */
178         int max_attach_count;
179 } tdm_caps_pp;
180
181 /**
182  * @brief The capabilities structure of a capture object
183  * @see The display_get_capture_capability() function of #tdm_func_display
184  */
185 typedef struct _tdm_caps_capture {
186         tdm_capture_capability capabilities;    /**< The capabilities of capture */
187
188         unsigned int format_count;      /**< The count of available formats */
189         tbm_format
190         *formats;            /**< The @b newly-allocated array of formats. will be freed in frontend. */
191
192         int min_w;              /**< The minimun width */
193         int min_h;              /**< The minimun height */
194         int max_w;              /**< The maximum width */
195         int max_h;              /**< The maximum height */
196         int preferred_align;    /**< The prefered align */
197
198         /**< The attach count which a capture object can handle. @since 1.2.0 */
199         int max_attach_count;
200 } tdm_caps_capture;
201
202 /**
203  * @brief The display functions for a backend module.
204  */
205 typedef struct _tdm_func_display {
206         /**
207          * @brief Get the display capabilities of a backend module
208          * @param[in] bdata The backend module data
209          * @param[out] caps The display capabilities of a backend module
210          * @return #TDM_ERROR_NONE if success. Otherwise, error value.
211          * @remark
212          * A backend module @b SHOULD implement this function. TDM calls this function
213          * not only at the initial time, but also at the update time when new output
214          * is connected.\n
215          * If a hardware has the restriction of the number of max usable layer count,
216          * a backend module can set the max count to max_layer_count of #tdm_caps_display
217          * structure.
218          */
219         tdm_error (*display_get_capability)(tdm_backend_data *bdata, tdm_caps_display *caps);
220
221         /**
222          * @brief Get the pp capabilities of a backend module
223          * @param[in] bdata The backend module data
224          * @param[out] caps The pp capabilities of a backend module
225          * @return #TDM_ERROR_NONE if success. Otherwise, error value.
226          * @see tdm_backend_register_func_pp
227          * @remark
228          * TDM calls this function not only at the initial time, but also at the update
229          * time when new output is connected.\n
230          * A backend module doesn't need to implement this function if a hardware
231          * doesn't have the memory-to-memory converting device. Otherwise, a backend module
232          * @b SHOULD fill the #tdm_caps_pp data. #tdm_caps_pp contains the hardware
233          * restriction information which a converting device can handle. ie, format, size, etc.
234          */
235         tdm_error (*display_get_pp_capability)(tdm_backend_data *bdata, tdm_caps_pp *caps);
236
237         /**
238          * @brief Get the capture capabilities of a backend module
239          * @param[in] bdata The backend module data
240          * @param[out] caps The capture capabilities of a backend module
241          * @return #TDM_ERROR_NONE if success. Otherwise, error value.
242          * @see tdm_backend_register_func_capture
243          * @remark
244          * TDM calls this function not only at the initial time, but also at the update
245          * time when new output is connected.\n
246          * A backend module doesn't need to implement this function if a hardware
247          * doesn't have the capture device. Otherwise, a backend module @b SHOULD fill the
248          * #tdm_caps_capture data. #tdm_caps_capture contains the hardware restriction
249          * information which a capture device can handle. ie, format, size, etc.
250          */
251         tdm_error (*display_get_capture_capability)(tdm_backend_data *bdata, tdm_caps_capture *caps);
252
253         /**
254          * @brief Get a output array of a backend module
255          * @param[in] bdata The backend module data
256          * @param[out] count The count of outputs
257          * @param[out] error #TDM_ERROR_NONE if success. Otherwise, error value.
258          * @return A output array which is @b newly-allocated
259          * @see tdm_backend_register_func_capture
260          * @remark
261          * A backend module @b SHOULD implement this function. TDM calls this function
262          * not only at the initial time, but also at the update time when new output
263          * is connected.\n
264          * A backend module @b SHOULD return the @b newly-allocated array which contains
265          * "tdm_output*" data. It will be freed in frontend.
266          * @par Example
267          * @code
268          *  tdm_output**
269          *  drm_display_get_outputs(tdm_backend_data *bdata, int *count, tdm_error *error)
270          *  {
271          *      tdm_drm_data *drm_data = bdata;
272          *      tdm_drm_output_data *output_data = NULL;
273          *      tdm_output **outputs;
274          *      int i;
275          *
276          *      (*count) = 0;
277          *      LIST_FOR_EACH_ENTRY(output_data, &drm_data->output_list, link)
278          *          (*count)++;
279          *
280          *      if ((*count) == 0)
281          *      {
282          *          if (error) *error = TDM_ERROR_NONE;
283          *          return NULL;
284          *      }
285          *
286          *      // will be freed in frontend
287          *      outputs = calloc(*count, sizeof(tdm_drm_output_data*));
288          *      if (!outputs)
289          *      {
290          *          (*count) = 0;
291          *          if (error) *error = TDM_ERROR_OUT_OF_MEMORY;
292          *          return NULL;
293          *      }
294          *
295          *      i = 0;
296          *      LIST_FOR_EACH_ENTRY(output_data, &drm_data->output_list, link)
297          *          outputs[i++] = output_data;
298          *
299          *      if (error) *error = TDM_ERROR_NONE;
300          *
301          *      return outputs;
302          *  }
303          * @endcode
304          */
305         tdm_output **(*display_get_outputs)(tdm_backend_data *bdata, int *count,
306                                                                                 tdm_error *error);
307
308         /**
309          * @brief Get the file descriptor of a backend module
310          * @param[in] bdata The backend module data
311          * @param[out] fd The fd of a backend module
312          * @return #TDM_ERROR_NONE if success. Otherwise, error value.
313          * @see display_handle_events() function of #tdm_func_display
314          * @remark
315          * A backend module can return epoll's fd which is watching the backend device one more fds.
316          */
317         tdm_error (*display_get_fd)(tdm_backend_data *bdata, int *fd);
318
319         /**
320          * @brief Handle the events which happens on the fd of a backend module
321          * @param[in] bdata The backend module data
322          * @return #TDM_ERROR_NONE if success. Otherwise, error value.
323          */
324         tdm_error (*display_handle_events)(tdm_backend_data *bdata);
325
326         /**
327          * @brief Create a pp object of a backend module
328          * @param[in] bdata The backend module data
329          * @param[out] error #TDM_ERROR_NONE if success. Otherwise, error value.
330          * @return A pp object
331          * @see pp_destroy() function of #tdm_func_pp
332          * @remark
333          * A backend module doesn't need to implement this function if a hardware
334          * doesn't have the memory-to-memory converting device.
335          */
336         tdm_pp *(*display_create_pp)(tdm_backend_data *bdata, tdm_error *error);
337
338         void (*reserved1)(void);
339         void (*reserved2)(void);
340         void (*reserved3)(void);
341         void (*reserved4)(void);
342         void (*reserved5)(void);
343         void (*reserved6)(void);
344         void (*reserved7)(void);
345         void (*reserved8)(void);
346 } tdm_func_display;
347
348 /**
349  * @brief The output functions for a backend module.
350  */
351 typedef struct _tdm_func_output {
352         /**
353          * @brief Get the capabilities of a output object
354          * @param[in] output A output object
355          * @param[out] caps The capabilities of a output object
356          * @return #TDM_ERROR_NONE if success. Otherwise, error value.
357          * @remark
358          * A backend module @b SHOULD implement this function. TDM calls this function
359          * not only at the initial time, but also at the update time when new output
360          * is connected.\n
361          * #tdm_caps_output contains connection status, modes, avaiable properties,
362          * size restriction information, etc.
363          */
364         tdm_error (*output_get_capability)(tdm_output *output, tdm_caps_output *caps);
365
366         /**
367          * @brief Get a layer array of a output object
368          * @param[in] output A output object
369          * @param[out] count The count of layers
370          * @param[out] error #TDM_ERROR_NONE if success. Otherwise, error value.
371          * @return A layer array which is @b newly-allocated
372          * @remark
373          * A backend module @b SHOULD implement this function. TDM calls this function
374          * not only at the initial time, but also at the update time when new output
375          * is connected.\n
376          * A backend module @b SHOULD return the @b newly-allocated array which contains
377          * "tdm_layer*" data. It will be freed in frontend.
378          */
379         tdm_layer **(*output_get_layers)(tdm_output *output, int *count,
380                                                                          tdm_error *error);
381
382         /**
383          * @brief Set the property which has a given id
384          * @param[in] output A output object
385          * @param[in] id The property id
386          * @param[in] value The value
387          * @return #TDM_ERROR_NONE if success. Otherwise, error value.
388          */
389         tdm_error (*output_set_property)(tdm_output *output, unsigned int id,
390                                                                          tdm_value value);
391
392         /**
393          * @brief Get the property which has a given id
394          * @param[in] output A output object
395          * @param[in] id The property id
396          * @param[out] value The value
397          * @return #TDM_ERROR_NONE if success. Otherwise, error value.
398          */
399         tdm_error (*output_get_property)(tdm_output *output, unsigned int id,
400                                                                          tdm_value *value);
401
402         /**
403          * @brief Wait for VBLANK
404          * @param[in] output A output object
405          * @param[in] interval vblank interval
406          * @param[in] sync 0: asynchronous, 1:synchronous
407          * @param[in] user_data The user data
408          * @return #TDM_ERROR_NONE if success. Otherwise, error value.
409          * @see output_set_vblank_handler, tdm_output_vblank_handler
410          * @remark
411          * If this function returns TDM_ERROR_NONE, a backend module @b SHOULD call
412          * a user vblank handler with the user data of this function after interval
413          * vblanks.
414          */
415         tdm_error (*output_wait_vblank)(tdm_output *output, int interval, int sync,
416                                                                         void *user_data);
417
418         /**
419          * @brief Set a user vblank handler
420          * @param[in] output A output object
421          * @param[in] func A user vblank handler
422          * @return #TDM_ERROR_NONE if success. Otherwise, error value.
423          */
424         tdm_error (*output_set_vblank_handler)(tdm_output *output,
425                                                                                    tdm_output_vblank_handler func);
426
427         /**
428          * @brief Commit changes for a output object
429          * @param[in] output A output object
430          * @param[in] sync 0: asynchronous, 1:synchronous
431          * @param[in] user_data The user data
432          * @return #TDM_ERROR_NONE if success. Otherwise, error value.
433          * @see output_set_commit_handler, tdm_output_commit_handler
434          * @remark
435          * When this function is called, a backend module @b SHOULD apply the all
436          * changes of the given output object to screen as well as the layer changes
437          * of this output.
438          * If this function returns TDM_ERROR_NONE, a backend module @b SHOULD call
439          * a user commit handler with the user data of this function after all
440          * changes of the given output object are applied.
441          */
442         tdm_error (*output_commit)(tdm_output *output, int sync, void *user_data);
443
444         /**
445          * @brief Set a user commit handler
446          * @param[in] output A output object
447          * @param[in] func A user commit handler
448          * @return #TDM_ERROR_NONE if success. Otherwise, error value.
449          */
450         tdm_error (*output_set_commit_handler)(tdm_output *output,
451                                                                                    tdm_output_commit_handler func);
452
453         /**
454          * @brief Set DPMS of a output object synchronously
455          * @param[in] output A output object
456          * @param[in] dpms_value DPMS value
457          * @return #TDM_ERROR_NONE if success. Otherwise, error value.
458          */
459         tdm_error (*output_set_dpms)(tdm_output *output, tdm_output_dpms dpms_value);
460
461         /**
462          * @brief Get DPMS of a output object
463          * @param[in] output A output object
464          * @param[out] dpms_value DPMS value
465          * @return #TDM_ERROR_NONE if success. Otherwise, error value.
466          */
467         tdm_error (*output_get_dpms)(tdm_output *output, tdm_output_dpms *dpms_value);
468
469         /**
470          * @brief Set one of available modes of a output object
471          * @param[in] output A output object
472          * @param[in] mode A output mode
473          * @return #TDM_ERROR_NONE if success. Otherwise, error value.
474          */
475         tdm_error (*output_set_mode)(tdm_output *output, const tdm_output_mode *mode);
476
477         /**
478          * @brief Get the mode of a output object
479          * @deprecated
480          * @param[in] output A output object
481          * @param[out] mode A output mode
482          * @return #TDM_ERROR_NONE if success. Otherwise, error value.
483          */
484         tdm_error (*output_get_mode)(tdm_output *output, const tdm_output_mode **mode);
485
486         /**
487          * @brief Create a capture object of a output object
488          * @param[in] output A output object
489          * @param[out] error #TDM_ERROR_NONE if success. Otherwise, error value.
490          * @return A capture object
491          * @see capture_destroy() function of #tdm_func_capture
492          * @remark
493          * A backend module doesn't need to implement this function if a hardware
494          * doesn't have the capture device.
495          */
496         tdm_capture *(*output_create_capture)(tdm_output *output, tdm_error *error);
497
498         /**
499          * @brief Set a output connection status handler
500          * @details A backend module need to call the output status handler when the
501          * output connection status has been changed to let the TDM frontend know
502          * the change.
503          * @param[in] output A output object
504          * @param[in] func A output status handler
505          * @param[in] user_data The user data
506          * @return #TDM_ERROR_NONE if success. Otherwise, error value.
507          * @since 1.1.0
508          */
509         tdm_error (*output_set_status_handler)(tdm_output *output,
510                                                                                    tdm_output_status_handler func,
511                                                                                    void *user_data);
512
513         /**
514          * @brief Set a output dpms handler
515          * @details This function can be NULL if an output doesn't support asynchronous
516          * DPMS control. Otherwise, a backend module needs to call the output dpms handler
517          * to let the TDM frontend know the output DPMS change indeed.
518          * @param[in] output A output object
519          * @param[in] func A output dpms handler
520          * @param[in] user_data The user data
521          * @return #TDM_ERROR_NONE if success. Otherwise, error value.
522          * @see #output_set_dpms_async, #TDM_OUTPUT_CAPABILITY_ASYNC_DPMS
523          * @since 1.4.0
524          */
525         tdm_error (*output_set_dpms_handler)(tdm_output *output,
526                                                                                  tdm_output_dpms_handler func,
527                                                                                  void *user_data);
528
529         /**
530          * @brief Set DPMS of a output object asynchronously
531          * @param[in] output A output object
532          * @details This function can be NULL if an output doesn't support asynchronous
533          * DPMS control. Otherwise, an output should have #TDM_OUTPUT_CAPABILITY_ASYNC_DPMS
534          * flags which #output_get_capability returns. And if a output dpms handler is added with
535          * #output_set_dpms_handler, a backend module needs to call the output dpms handler
536          * to let the TDM frontend know the output DPMS change indeed.
537          * @param[in] dpms_value DPMS value
538          * @return #TDM_ERROR_NONE if success. Otherwise, error value.
539          * @see #output_set_dpms_handler, #TDM_OUTPUT_CAPABILITY_ASYNC_DPMS
540          * @since 1.7.0
541          */
542         tdm_error (*output_set_dpms_async)(tdm_output *output, tdm_output_dpms dpms_value);
543
544         void (*reserved3)(void);
545         void (*reserved4)(void);
546         void (*reserved5)(void);
547         void (*reserved6)(void);
548         void (*reserved7)(void);
549         void (*reserved8)(void);
550 } tdm_func_output;
551
552 /**
553  * @brief The layer functions for a backend module.
554  */
555 typedef struct _tdm_func_layer {
556         /**
557          * @brief Get the capabilities of a layer object
558          * @param[in] layer A layer object
559          * @param[out] caps The capabilities of a layer object
560          * @return #TDM_ERROR_NONE if success. Otherwise, error value.
561          * @remark
562          * A backend module @b SHOULD implement this function. TDM calls this function
563          * not only at the initial time, but also at the update time when new output
564          * is connected.\n
565          * #tdm_caps_layer contains avaiable formats/properties, zpos information, etc.
566          */
567         tdm_error (*layer_get_capability)(tdm_layer *layer, tdm_caps_layer *caps);
568
569         /**
570          * @brief Set the property which has a given id.
571          * @param[in] layer A layer object
572          * @param[in] id The property id
573          * @param[in] value The value
574          * @return #TDM_ERROR_NONE if success. Otherwise, error value.
575          */
576         tdm_error (*layer_set_property)(tdm_layer *layer, unsigned int id,
577                                                                         tdm_value value);
578
579         /**
580          * @brief Get the property which has a given id.
581          * @param[in] layer A layer object
582          * @param[in] id The property id
583          * @param[out] value The value
584          * @return #TDM_ERROR_NONE if success. Otherwise, error value.
585          */
586         tdm_error (*layer_get_property)(tdm_layer *layer, unsigned int id,
587                                                                         tdm_value *value);
588
589         /**
590          * @brief Set the geometry information to a layer object
591          * @param[in] layer A layer object
592          * @param[in] info The geometry information
593          * @return #TDM_ERROR_NONE if success. Otherwise, error value.
594          * @see output_commit() function of #tdm_func_output
595          * @remark
596          * A backend module would apply the geometry information when the output object
597          * of a layer object is committed.
598          */
599         tdm_error (*layer_set_info)(tdm_layer *layer, tdm_info_layer *info);
600
601         /**
602          * @brief Get the geometry information to a layer object
603          * @param[in] layer A layer object
604          * @param[out] info The geometry information
605          * @return #TDM_ERROR_NONE if success. Otherwise, error value.
606          */
607         tdm_error (*layer_get_info)(tdm_layer *layer, tdm_info_layer *info);
608
609         /**
610          * @brief Set a TDM buffer to a layer object
611          * @param[in] layer A layer object
612          * @param[in] buffer A TDM buffer
613          * @return #TDM_ERROR_NONE if success. Otherwise, error value.
614          * @see output_commit() function of #tdm_func_output
615          * @remark
616          * A backend module would show a TDM buffer on screen when the output object
617          * of a layer object is committed.
618          */
619         tdm_error (*layer_set_buffer)(tdm_layer *layer, tbm_surface_h buffer);
620
621         /**
622          * @brief Unset a TDM buffer from a layer object
623          * @param[in] layer A layer object
624          * @return #TDM_ERROR_NONE if success. Otherwise, error value.
625          * @remark
626          * A backend module @b SHOULD remove the current showing buffer from screen.
627          */
628         tdm_error (*layer_unset_buffer)(tdm_layer *layer);
629
630         /**
631          * @brief Set the zpos for a VIDEO layer object
632          * @param[in] layer A layer object
633          * @param[in] zpos z-order
634          * @return #TDM_ERROR_NONE if success. Otherwise, error value.
635          * @see tdm_caps_layer, tdm_layer_capability
636          * @remark
637          * A backend module doesn't need to implement this function if a backend
638          * module doesn't have VIDEO layers.\n
639          * This function is for VIDEO layers.
640          * GRAPHIC layers are non-changeable. The zpos of GRAPHIC layers starts
641          * from 0. If there are 4 GRAPHIC layers, The zpos SHOULD be 0, 1, 2, 3.\n
642          * But the zpos of VIDEO layer is changeable. And The zpos of VIDEO layers
643          * is less than GRAPHIC layers or more than GRAPHIC layers.
644          * ie, ..., -2, -1, 4, 5, ... (if 0 <= GRAPHIC layer's zpos < 4).
645          * The zpos of VIDEO layers is @b relative. It doesn't need to start
646          * from -1 or 4. Let's suppose that there are two VIDEO layers.
647          * One has -2 zpos. Another has -4 zpos. Then -2 Video layer is higher
648          * than -4 VIDEO layer.
649          */
650         tdm_error (*layer_set_video_pos)(tdm_layer *layer, int zpos);
651
652         /**
653          * @brief Create a capture object of a layer object
654          * @param[in] output A output object
655          * @param[out] error #TDM_ERROR_NONE if success. Otherwise, error value.
656          * @return A capture object
657          * @see capture_destroy() function of #tdm_func_capture
658          * @remark
659          * A backend module doesn't need to implement this function if a hardware
660          * doesn't have the capture device.
661          */
662         tdm_capture *(*layer_create_capture)(tdm_layer *layer, tdm_error *error);
663
664         /**
665          * @brief Get buffer flags which the layer can support.
666          * @param[in] layer A layer object
667          * @param[out] flags The buffer flags which should be the tbm_bo flags
668          * @return #TDM_ERROR_NONE if success. Otherwise, error value.
669          */
670         tdm_error (*layer_get_buffer_flags)(tdm_layer *layer, unsigned int *flags);
671
672         void (*reserved1)(void);
673         void (*reserved2)(void);
674         void (*reserved3)(void);
675         void (*reserved4)(void);
676         void (*reserved5)(void);
677         void (*reserved6)(void);
678         void (*reserved7)(void);
679 } tdm_func_layer;
680
681 /**
682  * @brief The pp functions for a backend module.
683  */
684 typedef struct _tdm_func_pp {
685         /**
686          * @brief Destroy a pp object
687          * @param[in] pp A pp object
688          * @see display_create_pp() function of #tdm_func_display
689          */
690         void (*pp_destroy)(tdm_pp *pp);
691
692         /**
693          * @brief Set the geometry information to a pp object
694          * @param[in] pp A pp object
695          * @param[in] info The geometry information
696          * @return #TDM_ERROR_NONE if success. Otherwise, error value.
697          * @see pp_commit() function of #tdm_func_pp
698          * @remark
699          * A backend module would apply the geometry information when committed.
700          */
701         tdm_error (*pp_set_info)(tdm_pp *pp, tdm_info_pp *info);
702
703         /**
704          * @brief Attach a source buffer and a destination buffer to a pp object
705          * @param[in] pp A pp object
706          * @param[in] src A source buffer
707          * @param[in] dst A destination buffer
708          * @return #TDM_ERROR_NONE if success. Otherwise, error value.
709          * @see pp_set_info() function of #tdm_func_pp
710          * @see pp_commit() function of #tdm_func_pp
711          * @see pp_set_done_handler, tdm_pp_done_handler
712          * @remark
713          * A backend module converts the image of a source buffer to a destination
714          * buffer when committed. The size/crop/transform information is set via
715          * #pp_set_info() of #tdm_func_pp. When done, a backend module @b SHOULD
716          * return the source/destination buffer via tdm_pp_done_handler.
717          */
718         tdm_error (*pp_attach)(tdm_pp *pp, tbm_surface_h src, tbm_surface_h dst);
719
720         /**
721          * @brief Commit changes for a pp object
722          * @param[in] pp A pp object
723          * @return #TDM_ERROR_NONE if success. Otherwise, error value.
724          */
725         tdm_error (*pp_commit)(tdm_pp *pp);
726
727         /**
728          * @brief Set a user done handler to a pp object
729          * @param[in] pp A pp object
730          * @param[in] func A user done handler
731          * @param[in] user_data user data
732          * @return #TDM_ERROR_NONE if success. Otherwise, error value.
733          * @remark
734          * A backend module @b SHOULD call #tdm_pp_done_handler when converintg a image is done.
735          */
736         tdm_error (*pp_set_done_handler)(tdm_pp *pp, tdm_pp_done_handler func,
737                                                                          void *user_data);
738
739         void (*reserved1)(void);
740         void (*reserved2)(void);
741         void (*reserved3)(void);
742         void (*reserved4)(void);
743         void (*reserved5)(void);
744         void (*reserved6)(void);
745         void (*reserved7)(void);
746         void (*reserved8)(void);
747 } tdm_func_pp;
748
749 /**
750  * @brief The capture functions for a backend module.
751  */
752 typedef struct _tdm_func_capture {
753         /**
754          * @brief Destroy a capture object
755          * @param[in] capture A capture object
756          * @see output_create_capture() function of #tdm_func_output
757          * @see layer_create_capture() function of #tdm_func_layer
758          */
759         void (*capture_destroy)(tdm_capture *capture);
760
761         /**
762          * @brief Set the geometry information to a capture object
763          * @param[in] capture A capture object
764          * @param[in] info The geometry information
765          * @return #TDM_ERROR_NONE if success. Otherwise, error value.
766          * @see capture_commit() function of #tdm_func_capture
767          * @remark
768          * A backend module would apply the geometry information when committed.
769          */
770         tdm_error (*capture_set_info)(tdm_capture *capture, tdm_info_capture *info);
771
772         /**
773          * @brief Attach a TDM buffer to a capture object
774          * @details When capture_commit() function is called, a backend module starts
775          * to dump a output or a layer to a TDM buffer.
776          * @param[in] capture A capture object
777          * @param[in] buffer A TDM buffer
778          * @return #TDM_ERROR_NONE if success. Otherwise, error value.
779          * @see capture_set_info() function of #tdm_func_capture
780          * @see capture_commit() function of #tdm_func_capture
781          * @see capture_set_done_handler, tdm_capture_done_handler
782          * @remark
783          * A backend module starts to dump a output or a layer to to a TDM buffer when
784          * committed. The size/crop/transform information is set via #capture_set_info()
785          * of #tdm_func_capture. When done, a backend module @b SHOULD return the TDM
786          * buffer via tdm_capture_done_handler.
787          */
788         tdm_error (*capture_attach)(tdm_capture *capture, tbm_surface_h buffer);
789
790         /**
791          * @brief Commit changes for a capture object
792          * @param[in] capture A capture object
793          * @return #TDM_ERROR_NONE if success. Otherwise, error value.
794          */
795         tdm_error (*capture_commit)(tdm_capture *capture);
796
797         /**
798          * @brief Set a user done handler to a capture object
799          * @param[in] capture A capture object
800          * @param[in] func A user done handler
801          * @param[in] user_data user data
802          * @return #TDM_ERROR_NONE if success. Otherwise, error value.
803          * @remark
804          * A backend module @b SHOULD call #tdm_capture_done_handler when capture operation is done.
805          */
806         tdm_error (*capture_set_done_handler)(tdm_capture *capture,
807                                                                                   tdm_capture_done_handler func, void *user_data);
808
809         void (*reserved1)(void);
810         void (*reserved2)(void);
811         void (*reserved3)(void);
812         void (*reserved4)(void);
813         void (*reserved5)(void);
814         void (*reserved6)(void);
815         void (*reserved7)(void);
816         void (*reserved8)(void);
817 } tdm_func_capture;
818
819 /**
820  * @brief The tdm event source
821  */
822 typedef void tdm_event_loop_source;
823
824 /**
825  * @brief The fd source handler
826  */
827 typedef tdm_error (*tdm_event_loop_fd_handler)(int fd, tdm_event_loop_mask mask, void *user_data);
828
829 /**
830  * @brief The timer source handler
831  */
832 typedef tdm_error (*tdm_event_loop_timer_handler)(void *user_data);
833
834 #define TDM_BACKEND_MINOR_VERSION_MASK  0x0000FFFF
835 #define TDM_BACKEND_MAJOR_VERSION_MASK  0xFFFF0000
836 #define TDM_BACKEND_GET_ABI_MINOR(v)    ((v) & TDM_BACKEND_MINOR_VERSION_MASK)
837 #define TDM_BACKEND_GET_ABI_MAJOR(v)    (((v) & TDM_BACKEND_MAJOR_VERSION_MASK) >> 16)
838
839 /**
840  * @brief
841  * The ABI version of TDM backend module. It has a major and minor revision.
842  * Modules using lower minor revisions will work with TDM frontend of a higher
843  * minor revision. There is no compatibility between different major revisions.
844  * The minor revision mask is 0x0000FFFF and the major revision mask is 0xFFFF0000.
845  * @par Example
846  * @code
847  *  tdm_backend_module tdm_backend_module_data = {
848  *      "drm",
849  *      "Samsung",
850  *      TDM_BACKEND_SET_ABI_VERSION(1,1),
851  *      tdm_drm_init,
852  *      tdm_drm_deinit
853  *  };
854  * @endcode
855  */
856 #define TDM_BACKEND_SET_ABI_VERSION(major, minor) \
857         (((major) << 16) & TDM_BACKEND_MAJOR_VERSION_MASK) | \
858         ((minor) & TDM_BACKEND_MINOR_VERSION_MASK)
859
860 /**
861  * @brief
862  * This MACRO is deprecated since 1.2.0. Use TDM_BACKEND_SET_ABI_VERSION instead of this.
863  * @deprecated
864  * Use #TDM_BACKEND_SET_ABI_VERSION macro instead of this macro.
865  */
866 #define TDM_BACKEND_ABI_VERSION     TDM_BACKEND_SET_ABI_VERSION(1, 1)
867
868 /**
869  * @brief The backend module information of the entry point to initialize a TDM
870  * backend module.
871  * @remark
872  * A backend module @b SHOULD define the global data symbol of which name is
873  * @b "tdm_backend_module_data". TDM will read this symbol, @b "tdm_backend_module_data",
874  * at the initial time and call init() function of #tdm_backend_module.
875  */
876 typedef struct _tdm_backend_module {
877         const char *name;           /**< The module name of a backend module */
878         const char *vendor;         /**< The vendor name of a backend module */
879         unsigned long abi_version;  /**< The ABI version of a backend module */
880
881         /**
882          * @brief The init function of a backend module
883          * @param[in] dpy A display object
884          * @param[out] error #TDM_ERROR_NONE if success. Otherwise, error value.
885          * @return The backend module data
886          * @see tdm_backend_data
887          */
888         tdm_backend_data *(*init)(tdm_display *dpy, tdm_error *error);
889
890         /**
891          * @brief The deinit function of a backend module
892          * @param[in] bdata The backend module data
893          */
894         void (*deinit)(tdm_backend_data *bdata);
895 } tdm_backend_module;
896
897 /**
898  * @brief Register the backend display functions to a display
899  * @param[in] dpy A display object
900  * @param[in] func_display display functions
901  * @return #TDM_ERROR_NONE if success. Otherwise, error value.
902  * @see tdm_backend_register_func_output, tdm_backend_register_func_layer
903  * @remarks
904  * A backend module @b SHOULD set the backend display functions at least.
905  */
906 tdm_error
907 tdm_backend_register_func_display(tdm_display *dpy,
908                                                                   tdm_func_display *func_display);
909
910 /**
911  * @brief Register the backend output functions to a display
912  * @param[in] dpy A display object
913  * @param[in] func_output output functions
914  * @return #TDM_ERROR_NONE if success. Otherwise, error value.
915  * @see tdm_backend_register_func_display, tdm_backend_register_func_layer
916  * @remarks
917  * A backend module @b SHOULD set the backend output functions at least.
918  */
919 tdm_error
920 tdm_backend_register_func_output(tdm_display *dpy,
921                                                                  tdm_func_output *func_output);
922
923 /**
924  * @brief Register the backend layer functions to a display
925  * @param[in] dpy A display object
926  * @param[in] func_layer layer functions
927  * @return #TDM_ERROR_NONE if success. Otherwise, error value.
928  * @see tdm_backend_register_func_display, tdm_backend_register_func_output
929  * @remarks
930  * A backend module @b SHOULD set the backend layer functions at least.
931  */
932 tdm_error
933 tdm_backend_register_func_layer(tdm_display *dpy, tdm_func_layer *func_layer);
934
935 /**
936  * @brief Register the backend pp functions to a display
937  * @param[in] dpy A display object
938  * @param[in] func_pp pp functions
939  * @return #TDM_ERROR_NONE if success. Otherwise, error value.
940  * @see tdm_backend_register_func_display, tdm_backend_register_func_capture
941  * @remark
942  * A backend module doesn'tcan skip to register the backend pp functions
943  * if a hardware doesn't have the memory-to-memory converting device.
944  */
945 tdm_error
946 tdm_backend_register_func_pp(tdm_display *dpy, tdm_func_pp *func_pp);
947
948 /**
949  * @brief Register the backend capture functions to a display
950  * @param[in] dpy A display object
951  * @param[in] func_capture capture functions
952  * @return #TDM_ERROR_NONE if success. Otherwise, error value.
953  * @see tdm_backend_register_func_display, tdm_backend_register_func_pp
954  * @remark
955  * A backend module can skip to register the backend capture functions
956  * if a hardware doesn't have the capture device.
957  */
958 tdm_error
959 tdm_backend_register_func_capture(tdm_display *dpy,
960                                                                   tdm_func_capture *func_capture);
961
962 /**
963  * @brief Increase the ref_count of a TDM buffer
964  * @details
965  * TDM has its own buffer release mechanism to let an frontend user know when a TDM buffer
966  * becomes available for a next job. A TDM buffer can be used for TDM to show
967  * it on screen or to capture an output and a layer. After all operations,
968  * TDM will release it immediately when TDM doesn't need it any more.
969  * @param[in] buffer A TDM buffer
970  * @return A buffer itself. Otherwise, NULL.
971  * @see tdm_buffer_unref_backend
972  * @remark
973  * - This function @b SHOULD be paired with #tdm_buffer_unref_backend. \n
974  * - For example, this function @b SHOULD be called in case that a backend module uses the TDM
975  * buffer of a layer for capturing a output or a layer to avoid tearing issue.
976  */
977 tbm_surface_h
978 tdm_buffer_ref_backend(tbm_surface_h buffer);
979
980 /**
981  * @brief Decrease the ref_count of a TDM buffer
982  * @param[in] buffer A TDM buffer
983  * @see tdm_buffer_ref_backend
984  */
985 void
986 tdm_buffer_unref_backend(tbm_surface_h buffer);
987
988 /**
989  * @brief The destroy handler of a TDM buffer
990  * @param[in] buffer A TDM buffer
991  * @param[in] user_data user data
992  * @see tdm_buffer_add_destroy_handler, tdm_buffer_remove_destroy_handler
993  */
994 typedef void (*tdm_buffer_destroy_handler)(tbm_surface_h buffer,
995                                                                                    void *user_data);
996
997 /**
998  * @brief Add a destroy handler to a TDM buffer
999  * @param[in] buffer A TDM buffer
1000  * @param[in] func A destroy handler
1001  * @param[in] user_data user data
1002  * @return #TDM_ERROR_NONE if success. Otherwise, error value.
1003  * @see tdm_buffer_remove_destroy_handler
1004  * @remark
1005  * A backend module can add a TDM buffer destroy handler to a TDM buffer which
1006  * is a #tbm_surface_h object. When the TDM buffer is destroyed, this handler will
1007  * be called.
1008  */
1009 tdm_error
1010 tdm_buffer_add_destroy_handler(tbm_surface_h buffer,
1011                                                            tdm_buffer_destroy_handler func, void *user_data);
1012
1013 /**
1014  * @brief Remove a destroy handler from a TDM buffer
1015  * @param[in] buffer A TDM buffer
1016  * @param[in] func A destroy handler
1017  * @param[in] user_data user data
1018  * @see tdm_buffer_add_destroy_handler
1019  */
1020 void
1021 tdm_buffer_remove_destroy_handler(tbm_surface_h buffer,
1022                                                                   tdm_buffer_destroy_handler func, void *user_data);
1023
1024 /**
1025  * @brief Add a FD handler for activity on the given file descriptor
1026  * @param[in] dpy A display object
1027  * @param[in] fd A file descriptor
1028  * @param[in] mask to monitor FD
1029  * @param[in] func A FD handler function
1030  * @param[in] user_data user data
1031  * @param[out] error #TDM_ERROR_NONE if success. Otherwise, error value.
1032  * @return A FD event source
1033  * @see #tdm_event_loop_source_fd_update, #tdm_event_loop_source_remove
1034  */
1035 tdm_event_loop_source*
1036 tdm_event_loop_add_fd_handler(tdm_display *dpy, int fd, tdm_event_loop_mask mask,
1037                                                           tdm_event_loop_fd_handler func, void *user_data,
1038                                                           tdm_error *error);
1039
1040 /**
1041  * @brief Update the mask of the given FD event source
1042  * @param[in] source The given FD event source
1043  * @param[in] mask to monitor FD
1044  * @return #TDM_ERROR_NONE if success. Otherwise, error value.
1045  */
1046 tdm_error
1047 tdm_event_loop_source_fd_update(tdm_event_loop_source *source, tdm_event_loop_mask mask);
1048
1049 /**
1050  * @brief Add a timer handler
1051  * @param[in] dpy A display object
1052  * @param[in] func A timer handler function
1053  * @param[in] user_data user data
1054  * @param[out] error #TDM_ERROR_NONE if success. Otherwise, error value.
1055  * @return A timer event source
1056  * @see #tdm_event_loop_source_timer_update, #tdm_event_loop_source_remove
1057  */
1058 tdm_event_loop_source*
1059 tdm_event_loop_add_timer_handler(tdm_display *dpy, tdm_event_loop_timer_handler func,
1060                                                                  void *user_data, tdm_error *error);
1061
1062 /**
1063  * @brief Update the millisecond delay time of the given timer event source.
1064  * @param[in] source The given timer event source
1065  * @param[in] ms_delay The millisecond delay time. zero "0" disarms the timer.
1066  * @return #TDM_ERROR_NONE if success. Otherwise, error value.
1067  */
1068 tdm_error
1069 tdm_event_loop_source_timer_update(tdm_event_loop_source *source, unsigned int ms_delay);
1070
1071 /**
1072  * @brief Remove the given event source
1073  * @param[in] source The given event source
1074  * @see #tdm_event_loop_add_fd_handler, #tdm_event_loop_add_timer_handler
1075  */
1076 void
1077 tdm_event_loop_source_remove(tdm_event_loop_source *source);
1078
1079 #ifdef __cplusplus
1080 }
1081 #endif
1082
1083 #endif /* _TDM_BACKEND_H_ */