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