tbm_bufmgr: lock/unlock tbm_bufmgr_mutex at tbm_bufmgr function
[platform/core/uifw/libtbm.git] / src / tbm_backend.c
1 /**************************************************************************
2
3 libtbm
4
5 Copyright 2018 Samsung Electronics co., Ltd. All Rights Reserved.
6
7 Contact: SooChan Lim <sc1.lim@samsung.com>,
8                  Sangjin Lee <lsj119@samsung.com>,
9                  Boram Park <boram1288.park@samsung.com>,
10                  Changyeon Lee <cyeon.lee@samsung.com>
11
12 Permission is hereby granted, free of charge, to any person obtaining a
13 copy of this software and associated documentation files (the
14 "Software"), to deal in the Software without restriction, including
15 without limitation the rights to use, copy, modify, merge, publish,
16 distribute, sub license, and/or sell copies of the Software, and to
17 permit persons to whom the Software is furnished to do so, subject to
18 the following conditions:
19
20 The above copyright notice and this permission notice (including the
21 next paragraph) shall be included in all copies or substantial portions
22 of the Software.
23
24 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
25 OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
26 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
27 IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR
28 ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
29 TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
30 SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
31
32 **************************************************************************/
33
34 #include "config.h"
35 #include "tbm_bufmgr_int.h"
36
37 /* LCOV_EXCL_START */
38 int
39 tbm_backend_bufmgr_query_display_server(tbm_bufmgr bufmgr, tbm_error_e *error)
40 {
41         const char *value;
42
43         if (!bufmgr) {
44                 if (error)
45                         *error = TBM_ERROR_INVALID_PARAMETER;
46                 return 0;
47         }
48
49         /* TODO: TBM_DISPLAY_SERVER will be removed */
50         value = (const char*)getenv("TBM_DISPLAY_SERVER");
51
52         if (value || gBufMgr->display_server) {
53                 if (error)
54                         *error = TBM_ERROR_NONE;
55                 return 1;
56         }
57
58         if (error)
59                 *error = TBM_ERROR_NONE;
60
61         return 0;
62 }
63
64 tbm_backend_bufmgr_func *
65 tbm_backend_bufmgr_alloc_bufmgr_func(tbm_bufmgr bufmgr, tbm_error_e *error)
66 {
67         tbm_backend_bufmgr_func *bufmgr_func;
68
69         bufmgr_func = calloc(1, sizeof(struct _tbm_backend_bufmgr_func));
70         if (!bufmgr_func) {
71                 TBM_ERR("error: fail to allocate the tbm_backend_bufmgr_func\n");
72                 if (error)
73                         *error = TBM_ERROR_OUT_OF_MEMORY;
74                 return NULL;
75         }
76
77         if (error)
78                 *error = TBM_ERROR_NONE;
79
80         return bufmgr_func;
81 }
82
83 void
84 tbm_backend_bufmgr_free_bufmgr_func(tbm_bufmgr bufmgr, tbm_backend_bufmgr_func *func)
85 {
86         TBM_RETURN_IF_FAIL(bufmgr);
87
88         if (func)
89                 free(func);
90 }
91
92 tbm_error_e
93 tbm_backend_bufmgr_register_bufmgr_func(tbm_bufmgr bufmgr, tbm_backend_bufmgr_func *func)
94 {
95         TBM_RETURN_VAL_IF_FAIL(bufmgr, TBM_ERROR_INVALID_PARAMETER);
96         TBM_RETURN_VAL_IF_FAIL(func, TBM_ERROR_INVALID_PARAMETER);
97
98         // The tbm_bufmgr from backend module is actually tbm_module memory in libtbm.
99         // libtbm initializes module init with this tbm_module which is casted with tbm_bufmgr.
100         tbm_module *module = (tbm_module *)bufmgr;
101         module->bufmgr_func = func;
102
103         return TBM_ERROR_NONE;
104 }
105
106 tbm_backend_bo_func *
107 tbm_backend_bufmgr_alloc_bo_func(tbm_bufmgr bufmgr, tbm_error_e *error)
108 {
109         tbm_backend_bo_func *bufmgr_bo;
110
111         bufmgr_bo = calloc(1, sizeof(struct _tbm_backend_bo_func));
112         if (!bufmgr_bo) {
113                 TBM_ERR("error: fail to allocate the tbm_backend_bo_func\n");
114                 if (error)
115                         *error = TBM_ERROR_OUT_OF_MEMORY;
116                 return NULL;
117         }
118
119         if (error)
120                 *error = TBM_ERROR_NONE;
121
122         return bufmgr_bo;
123 }
124
125 void
126 tbm_backend_bufmgr_free_bo_func(tbm_bufmgr bufmgr, tbm_backend_bo_func *func)
127 {
128         TBM_RETURN_IF_FAIL(bufmgr);
129
130         if (func)
131                 free(func);
132 }
133
134 tbm_error_e
135 tbm_backend_bufmgr_register_bo_func(tbm_bufmgr bufmgr, tbm_backend_bo_func *func)
136 {
137         TBM_RETURN_VAL_IF_FAIL(bufmgr, TBM_ERROR_INVALID_PARAMETER);
138         TBM_RETURN_VAL_IF_FAIL(func, TBM_ERROR_INVALID_PARAMETER);
139
140         // The tbm_bufmgr from backend module is actually tbm_module memory in libtbm.
141         // libtbm initializes module init with this tbm_module which is casted with tbm_bufmgr.
142         tbm_module *module = (tbm_module *)bufmgr;
143         module->bo_func = func;
144
145         return TBM_ERROR_NONE;
146 }
147
148 /* LCOV_EXCL_STOP */