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