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