db0a295aab1285a82f4485f8026f690930da424a
[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
56         void *module_data;                         /* backend module */
57         tbm_bufmgr_backend   backend;              /* bufmgr backend (will be DEPRECATED) */
58
59         tbm_backend_module       *backend_module_data;  /* backend module data */
60         tbm_backend_bufmgr_data  *bufmgr_data;          /* backend data of the backend module */
61         tbm_backend_bufmgr_func  *bufmgr_func;          /* backend functions for bufmgr */
62         tbm_backend_bo_func      *bo_func;              /* backend functions for bo */
63
64         int use_hal_tbm;                                /* use hal-api-tbm */
65         int auth_wl_socket_created;                     /* create wayland socket for authenticated drm_fd */
66         int auth_fd;
67         hal_tbm_backend          *hal_backend;          /* hal-api-tbm backend */
68         hal_tbm_bufmgr           *hal_bufmgr;           /* hal-api-tbm bufmgr */
69 } tbm_module;
70
71 typedef struct _tbm_backend_surface_data {
72         tbm_module *module;
73         hal_tbm_surface *hal_surface;
74 } tbm_backend_surface_data;
75
76 /* tbm_module functions */
77 tbm_module *tbm_module_load(int fd);
78 void        tbm_module_unload(tbm_module *module);
79
80 int                  tbm_module_get_capabilities(tbm_module *module, tbm_error_e *error);
81 tbm_error_e          tbm_module_bind_native_display(tbm_module *module, void *native_display);
82 tbm_error_e          tbm_module_get_supported_formats(tbm_module *module, uint32_t **formats, uint32_t *num);
83 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);
84
85 tbm_backend_surface_data  *tbm_module_alloc_surface_data(tbm_module *module, int width, int height, int format, int flags, tbm_error_e *error);
86 tbm_backend_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);
87
88 tbm_backend_bo_data *tbm_module_alloc_bo_data(tbm_module *module, tbm_bo bo, int size, int flags, tbm_error_e *error);
89 tbm_backend_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);
90 tbm_backend_bo_data *tbm_module_import_bo_data_with_fd(tbm_module *module, tbm_bo bo, tbm_fd fd, tbm_error_e *error);
91 tbm_backend_bo_data *tbm_module_import_bo_data_with_key(tbm_module *module, tbm_bo bo, tbm_key key, tbm_error_e *error);
92
93 void          tbm_module_bo_free(tbm_module *module, tbm_bo bo, tbm_backend_bo_data *bo_data, int get_from_hal_surface);
94 int           tbm_module_bo_get_size(tbm_module *module, tbm_bo bo, tbm_backend_bo_data *bo_data, tbm_error_e *error);
95 int           tbm_module_bo_get_memory_types(tbm_module *module, tbm_bo bo, tbm_backend_bo_data *bo_data, tbm_error_e *error);
96 tbm_bo_handle tbm_module_bo_get_handle(tbm_module *module, tbm_bo bo, tbm_backend_bo_data *bo_data, int device, tbm_error_e *error);
97 tbm_bo_handle tbm_module_bo_map(tbm_module *module, tbm_bo bo, tbm_backend_bo_data *bo_data, int device, int opt, tbm_error_e *error);
98 tbm_error_e   tbm_module_bo_unmap(tbm_module *module, tbm_bo bo, tbm_backend_bo_data *bo_data);
99 tbm_error_e   tbm_module_bo_lock(tbm_module *module, tbm_bo bo, tbm_backend_bo_data *bo_data, int device, int opt);
100 tbm_error_e   tbm_module_bo_unlock(tbm_module *module, tbm_bo bo, tbm_backend_bo_data *bo_data);
101 tbm_fd        tbm_module_bo_export_fd(tbm_module *module, tbm_bo bo, tbm_backend_bo_data *bo_data, tbm_error_e *error);
102 tbm_key       tbm_module_bo_export_key(tbm_module *module, tbm_bo bo, tbm_backend_bo_data *bo_data, tbm_error_e *error);
103
104 #endif // _TBM_MODULE_H_