e41068189aaaef907a9454aaaf8831c9ce9b1c5e
[platform/core/uifw/libtbm.git] / ut / src / ut_tbm_bufmgr.h
1 #ifndef _TBM_BUFMGR_H_
2 #define _TBM_BUFMGR_H_
3
4 #include <tbm_type.h>
5 #include <stdint.h>
6
7 /* tbm error base : this error base is same as TIZEN_ERROR_TBM in tizen_error.h */
8 #ifndef TBM_ERROR_BASE
9 #define TBM_ERROR_BASE                  -0x02830000
10 #endif
11
12 typedef struct _tbm_bufmgr *tbm_bufmgr;
13
14 typedef struct _tbm_bo *tbm_bo;
15
16 typedef uint32_t tbm_key;
17
18 typedef int32_t tbm_fd;
19
20 /* TBM_DEVICE_TYPE */
21
22 #define TBM_DEVICE_DEFAULT   0
23 #define TBM_DEVICE_CPU       1
24 #define TBM_DEVICE_2D        2
25 #define TBM_DEVICE_3D        3
26 #define TBM_DEVICE_MM        4
27
28 /* TBM_OPTION */
29
30 #define TBM_OPTION_READ      (1 << 0)
31 #define TBM_OPTION_WRITE     (1 << 1)
32 #define TBM_OPTION_VENDOR    (0xffff0000)
33
34 /* stub for union tbm_bo_handle */
35 class tbm_bo_handle {
36 public:
37         void *ptr;
38         int32_t s32;
39         uint32_t u32;
40         int64_t s64;
41         uint64_t u64;
42         tbm_bo_handle() {}
43         tbm_bo_handle(const uint64_t v)
44         {
45                 if (v == 0)
46                         ptr = NULL;
47                 else
48                         ptr = &u64;
49
50                 s32 = v;
51                 u32 = v;
52                 s64 = v;
53                 u64 = v;
54         }
55 };
56
57 enum TBM_BO_FLAGS {
58         TBM_BO_DEFAULT = 0,                        /**< default memory: it depends on the backend         */
59         TBM_BO_SCANOUT = (1 << 0),         /**< scanout memory                                    */
60         TBM_BO_NONCACHABLE = (1 << 1), /**< non-cachable memory                               */
61         TBM_BO_WC = (1 << 2),              /**< write-combine memory                              */
62         TBM_BO_VENDOR = (0xffff0000), /**< vendor specific memory: it depends on the backend */
63 };
64
65 typedef enum {
66         TBM_ERROR_NONE = 0,                                             /**< Successful */
67         TBM_BO_ERROR_GET_FD_FAILED = TBM_ERROR_BASE | 0x0101,     /**< failed to get fd failed */
68         TBM_BO_ERROR_HEAP_ALLOC_FAILED = TBM_ERROR_BASE | 0x0102, /**< failed to allocate the heap memory */
69         TBM_BO_ERROR_LOAD_MODULE_FAILED = TBM_ERROR_BASE | 0x0103,/**< failed to load module*/
70         TBM_BO_ERROR_THREAD_INIT_FAILED = TBM_ERROR_BASE | 0x0104,/**< failed to initialize the pthread */
71         TBM_BO_ERROR_BO_ALLOC_FAILED = TBM_ERROR_BASE | 0x0105,   /**< failed to allocate tbm_bo */
72         TBM_BO_ERROR_INIT_STATE_FAILED = TBM_ERROR_BASE | 0x0106, /**< failed to initialize the state of tbm_bo */
73         TBM_BO_ERROR_IMPORT_FAILED = TBM_ERROR_BASE | 0x0107,     /**< failed to import the handle of tbm_bo */
74         TBM_BO_ERROR_IMPORT_FD_FAILED = TBM_ERROR_BASE | 0x0108,  /**< failed to import fd of tbm_bo */
75         TBM_BO_ERROR_EXPORT_FAILED = TBM_ERROR_BASE | 0x0109,     /**< failed to export the handle of the tbm_bo */
76         TBM_BO_ERROR_EXPORT_FD_FAILED = TBM_ERROR_BASE | 0x01010, /**< failed to export fd of tbm_bo */
77         TBM_BO_ERROR_GET_HANDLE_FAILED = TBM_ERROR_BASE | 0x0111, /**< failed to get the tbm_bo_handle */
78         TBM_BO_ERROR_LOCK_FAILED = TBM_ERROR_BASE | 0x0112,               /**< failed to lock the tbm_bo */
79         TBM_BO_ERROR_MAP_FAILED = TBM_ERROR_BASE | 0x0113,                /**< failed to map the tbm_bo to get the tbm_bo_handle */
80         TBM_BO_ERROR_UNMAP_FAILED = TBM_ERROR_BASE | 0x0114,      /**< failed to unmap the tbm_bo */
81         TBM_BO_ERROR_SWAP_FAILED = TBM_ERROR_BASE | 0x0115,               /**< failed to swap the tbm_bos */
82         TBM_BO_ERROR_DUP_FD_FAILED = TBM_ERROR_BASE | 0x0116,     /**< failed to duplicate fd */
83 } tbm_error_e;
84
85 enum TBM_BUFMGR_CAPABILITY {
86         TBM_BUFMGR_CAPABILITY_NONE = 0,                                 /**< Not Support capability*/
87         TBM_BUFMGR_CAPABILITY_SHARE_KEY = (1 << 0),             /**< Support sharing buffer by tbm key */
88         TBM_BUFMGR_CAPABILITY_SHARE_FD = (1 << 1),              /**< Support sharing buffer by tbm fd */
89 };
90
91 #ifdef __cplusplus
92 extern "C" {
93 #endif
94
95 /* Functions for buffer manager */
96
97 tbm_bufmgr tbm_bufmgr_init(int fd);
98
99 void tbm_bufmgr_deinit(tbm_bufmgr bufmgr);
100
101 /* Functions for bo */
102
103 tbm_bo tbm_bo_alloc(tbm_bufmgr bufmgr, int size, int flags);
104
105 tbm_bo tbm_bo_ref(tbm_bo bo);
106
107 void tbm_bo_unref(tbm_bo bo);
108
109 tbm_bo_handle tbm_bo_map(tbm_bo bo, int device, int opt);
110
111 int tbm_bo_unmap(tbm_bo bo);
112
113 tbm_bo_handle tbm_bo_get_handle(tbm_bo bo, int device);
114
115 tbm_key tbm_bo_export(tbm_bo bo);
116
117 tbm_fd tbm_bo_export_fd(tbm_bo bo);
118
119 tbm_bo tbm_bo_import(tbm_bufmgr bufmgr, tbm_key key);
120
121 tbm_bo tbm_bo_import_fd(tbm_bufmgr bufmgr, tbm_fd fd);
122
123 int tbm_bo_size(tbm_bo bo);
124
125 int tbm_bo_locked(tbm_bo bo);
126
127 int tbm_bo_swap(tbm_bo bo1, tbm_bo bo2);
128
129 typedef void (*tbm_data_free) (void *user_data);
130
131 int tbm_bo_add_user_data(tbm_bo bo, unsigned long key,
132                          tbm_data_free data_free_func);
133
134 int tbm_bo_delete_user_data(tbm_bo bo, unsigned long key);
135
136 int tbm_bo_set_user_data(tbm_bo bo, unsigned long key, void *data);
137
138 int tbm_bo_get_user_data(tbm_bo bo, unsigned long key, void **data);
139
140 tbm_error_e tbm_get_last_error(void);
141
142 unsigned int tbm_bufmgr_get_capability(tbm_bufmgr bufmgr);
143
144 int tbm_bo_get_flags(tbm_bo bo);
145
146 void tbm_bufmgr_debug_show(tbm_bufmgr bufmgr);
147
148 void tbm_bufmgr_debug_trace(tbm_bufmgr bufmgr, int onoff);
149
150 int tbm_bufmgr_bind_native_display(tbm_bufmgr bufmgr, void *NativeDisplay);
151
152 #ifdef __cplusplus
153 }
154 #endif
155 #endif                                                  /* _TBM_BUFMGR_H_ */