tbm_module: remove the static variable
[platform/core/uifw/libtbm.git] / src / tbm_module.h
1 /**************************************************************************
2
3 libtbm
4
5 Copyright 2012-2021 Samsung Electronics co., Ltd. All Rights Reserved.
6
7 Contact: SooChan Lim <sc1.lim@samsung.com>
8          Changyeon Lee <cyeon.lee@samsung.com>
9
10 Permission is hereby granted, free of charge, to any person obtaining a
11 copy of this software and associated documentation files (the
12 "Software"), to deal in the Software without restriction, including
13 without limitation the rights to use, copy, modify, merge, publish,
14 distribute, sub license, and/or sell copies of the Software, and to
15 permit persons to whom the Software is furnished to do so, subject to
16 the following conditions:
17
18 The above copyright notice and this permission notice (including the
19 next paragraph) shall be included in all copies or substantial portions
20 of the Software.
21
22 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
23 OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
24 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
25 IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR
26 ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
27 TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
28 SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
29
30 **************************************************************************/
31
32 #ifndef _TBM_MODULE_H_
33 #define _TBM_MODULE_H_
34
35 #include <tbm_bufmgr.h>
36 #include <tbm_bo.h>
37 #include <tbm_surface.h>
38 #include <tbm_surface_internal.h>
39 #include <tbm_surface_queue.h>
40 #include <tbm_log.h>
41 #include <tbm_bufmgr_backend.h>
42 #include <tbm_backend.h>
43 #include <tbm_error.h>
44 #include <hal/hal-tbm.h>
45
46 typedef enum _tbm_module_type {
47         TBM_MODULE_TYPE_NONE,
48         TBM_MODULE_TYPE_HAL_TBM,
49         TBM_MODULE_TYPE_TBM_BACKEND,
50         TBM_MODULE_TYPE_BUFMGR_BACKEND,
51 } tbm_module_type;
52
53 typedef struct _tbm_module {
54         tbm_module_type type;
55         int support_surface_data;
56         int check_surface_data;
57
58         void *module_data;                         /* backend module */
59         tbm_bufmgr_backend   backend;              /* bufmgr backend (will be DEPRECATED) */
60
61         tbm_backend_module       *backend_module_data;  /* backend module data */
62         tbm_backend_bufmgr_data  *bufmgr_data;          /* backend data of the backend module */
63         tbm_backend_bufmgr_func  *bufmgr_func;          /* backend functions for bufmgr */
64         tbm_backend_bo_func      *bo_func;              /* backend functions for bo */
65
66         int use_hal_tbm;                                /* use hal-api-tbm */
67         int auth_wl_socket_created;                     /* create wayland socket for authenticated drm_fd */
68         int auth_fd;
69         hal_tbm_backend          *hal_backend;          /* hal-api-tbm backend */
70         hal_tbm_bufmgr           *hal_bufmgr;           /* hal-api-tbm bufmgr */
71 } tbm_module;
72
73 typedef struct _tbm_surface_data {
74         tbm_module *module;
75         hal_tbm_surface *hal_surface;
76 } tbm_surface_data;
77
78 typedef struct _tbm_bo_data {
79         tbm_module *module;
80         hal_tbm_bo *hal_bo;
81         tbm_backend_bo_data *backend_bo_data;
82         void *priv;
83 } tbm_bo_data;
84
85 /* tbm_module functions */
86 tbm_module *tbm_module_load(int fd);
87 void        tbm_module_unload(tbm_module *module);
88
89 int                  tbm_module_get_capabilities(tbm_module *module, tbm_error_e *error);
90 tbm_error_e          tbm_module_bind_native_display(tbm_module *module, void *native_display);
91 tbm_error_e          tbm_module_get_supported_formats(tbm_module *module, uint32_t **formats, uint32_t *num);
92 tbm_error_e          tbm_module_get_plane_data(tbm_module *module, int format, int plane_idx, uint32_t w, uint32_t h, uint32_t *size, uint32_t *offset, uint32_t *pitch, int *bo_idx);
93 int                  tbm_module_support_surface_data(tbm_module *module);
94
95 tbm_surface_data  *tbm_module_alloc_surface_data(tbm_module *module, int width, int height, int format, int flags, tbm_error_e *error);
96 tbm_surface_data  *tbm_module_import_surface_data(tbm_module *module, int width, int height, int format, tbm_surface_buffer_data *buffer_data, tbm_error_e *error);
97
98 tbm_bo_data *tbm_module_alloc_bo_data(tbm_module *module, tbm_bo bo, int size, int flags, tbm_error_e *error);
99 tbm_bo_data *tbm_module_alloc_bo_data_with_format(tbm_module *module, int format, int bo_idx, int width, int height, int bpp, tbm_bo_memory_type flags, tbm_error_e *error);
100 tbm_bo_data *tbm_module_import_bo_data_with_fd(tbm_module *module, tbm_bo bo, tbm_fd fd, tbm_error_e *error);
101 tbm_bo_data *tbm_module_import_bo_data_with_key(tbm_module *module, tbm_bo bo, tbm_key key, tbm_error_e *error);
102 int          tbm_module_compare_bo_data(tbm_module *module, tbm_bo_data *bo_data1, tbm_bo_data *bo_data2);
103
104 void                      tbm_surface_data_free(tbm_surface_data *surface_data);
105 tbm_error_e               tbm_surface_data_get_plane_data(tbm_surface_data *surface_data, int plane_idx, uint32_t *size, uint32_t *offset, uint32_t *pitch, int *bo_idx);
106 tbm_bo_data             **tbm_surface_data_get_bo_data_array(tbm_surface_data *surface_data, int *num_bos, tbm_error_e *error);
107 tbm_surface_buffer_data  *tbm_surface_data_export(tbm_surface_data *surface_data, tbm_error_e *error);
108
109 void          tbm_bo_data_free(tbm_bo_data *bo_data, int get_from_surface_data);
110 int           tbm_bo_data_get_size(tbm_bo_data *bo_data, tbm_error_e *error);
111 int           tbm_bo_data_get_memory_types(tbm_bo_data *bo_data, tbm_error_e *error);
112 tbm_bo_handle tbm_bo_data_get_handle(tbm_bo_data *bo_data, int device, tbm_error_e *error);
113 tbm_bo_handle tbm_bo_data_map(tbm_bo_data *bo_data, int device, int opt, tbm_error_e *error);
114 tbm_error_e   tbm_bo_data_unmap(tbm_bo_data *bo_data);
115 tbm_error_e   tbm_bo_data_lock(tbm_bo_data *bo_data, int device, int opt);
116 tbm_error_e   tbm_bo_data_unlock(tbm_bo_data *bo_data);
117 tbm_fd        tbm_bo_data_export_fd(tbm_bo_data *bo_data, tbm_error_e *error);
118 tbm_key       tbm_bo_data_export_key(tbm_bo_data *bo_data, tbm_error_e *error);
119
120 #endif // _TBM_MODULE_H_