4c9ce1961b707c546a9d60292151949e59d3ea31
[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         bufmgr->bufmgr_func = func;
99
100         return TBM_ERROR_NONE;
101 }
102
103 tbm_backend_bo_func *
104 tbm_backend_bufmgr_alloc_bo_func(tbm_bufmgr bufmgr, tbm_error_e *error)
105 {
106         tbm_backend_bo_func *bufmgr_bo;
107
108         bufmgr_bo = calloc(1, sizeof(struct _tbm_backend_bo_func));
109         if (!bufmgr_bo) {
110                 TBM_ERR("error: fail to allocate the tbm_backend_bo_func\n");
111                 if (error)
112                         *error = TBM_ERROR_OUT_OF_MEMORY;
113                 return NULL;
114         }
115
116         if (error)
117                 *error = TBM_ERROR_NONE;
118
119         return bufmgr_bo;
120 }
121
122 void
123 tbm_backend_bufmgr_free_bo_func(tbm_bufmgr bufmgr, tbm_backend_bo_func *func)
124 {
125         TBM_RETURN_IF_FAIL(bufmgr);
126
127         if (func)
128                 free(func);
129 }
130
131 tbm_error_e
132 tbm_backend_bufmgr_register_bo_func(tbm_bufmgr bufmgr, tbm_backend_bo_func *func)
133 {
134         TBM_RETURN_VAL_IF_FAIL(bufmgr, TBM_ERROR_INVALID_PARAMETER);
135         TBM_RETURN_VAL_IF_FAIL(func, TBM_ERROR_INVALID_PARAMETER);
136
137         bufmgr->bo_func = func;
138
139         return TBM_ERROR_NONE;
140 }
141
142 /* LCOV_EXCL_STOP */