tbm_surface_internal: refactor the creation of a surface
[platform/core/uifw/libtbm.git] / src / tbm_bufmgr_backend.c
1 /**************************************************************************
2
3 libtbm
4
5 Copyright 2012 Samsung Electronics co., Ltd. All Rights Reserved.
6
7 Contact: SooChan Lim <sc1.lim@samsung.com>, Sangjin Lee <lsj119@samsung.com>
8 Boram Park <boram1288.park@samsung.com>, 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 #include "config.h"
33
34 #include <unistd.h>
35 #include <stdio.h>
36 #include <stdlib.h>
37 #include <sys/types.h>
38 #include "tbm_bufmgr_int.h"
39
40 /* LCOV_EXCL_START */
41 tbm_bufmgr_backend tbm_backend_alloc(void)
42 {
43         tbm_bufmgr_backend bufmgr_backend;
44
45         bufmgr_backend = calloc(1, sizeof(struct _tbm_bufmgr_backend));
46         if (!bufmgr_backend) {
47                 TBM_ERR("error: fail to allocate the bufmgr_backend\n");
48                 return NULL;
49         }
50
51         return bufmgr_backend;
52 }
53
54 void tbm_backend_free(tbm_bufmgr_backend backend)
55 {
56         if (!backend)
57                 return;
58
59         free(backend);
60         backend = NULL;
61 }
62
63 int tbm_backend_init(tbm_bufmgr bufmgr, tbm_bufmgr_backend backend)
64 {
65         tbm_module *module = NULL;
66
67         if (!bufmgr) {
68                 TBM_ERR("error: fail to init tbm backend... bufmgr is null\n");
69                 return 0;
70         }
71
72         if (!backend) {
73                 TBM_ERR("error: fail to init tbm backend... backend is null\n");
74                 return 0;
75         }
76
77         module = (tbm_module *)bufmgr;
78
79         module->backend = backend;
80
81 #if 0 // DEPRECATED
82         module->capabilities = TBM_BUFMGR_CAPABILITY_NONE;
83
84         if (module->backend->bo_import && module->backend->bo_export)
85                 module->capabilities |= TBM_BUFMGR_CAPABILITY_SHARE_KEY;
86
87         if (module->backend->bo_import_fd && module->backend->bo_export_fd)
88                 module->capabilities |= TBM_BUFMGR_CAPABILITY_SHARE_FD;
89 #endif
90
91         return 1;
92 }
93
94 void *tbm_backend_get_bufmgr_priv(tbm_bo bo)
95 {
96         tbm_bufmgr_backend backend = bo->bufmgr->module->backend;
97
98         return backend->priv;
99 }
100
101 void *tbm_backend_get_priv_from_bufmgr(tbm_bufmgr bufmgr)
102 {
103         tbm_module *module = (tbm_module *)bufmgr;
104         tbm_bufmgr_backend backend = module->backend;
105
106         return backend->priv;
107 }
108
109 void tbm_backend_set_bo_priv(tbm_bo bo, void *bo_priv)
110 {
111         bo->bo_data->priv = bo_priv;
112 }
113
114 void *tbm_backend_get_bo_priv(tbm_bo bo)
115 {
116         return bo->bo_data->priv;
117 }
118
119 int tbm_backend_is_display_server(void)
120 {
121         const char *value;
122
123         if (gBufMgr == NULL) {
124                 TBM_ERR("error: no gBufMgr.\n");
125                 return 0;
126         }
127
128         /* TODO: TBM_DISPLAY_SERVER will be removed */
129         value = (const char*)getenv("TBM_DISPLAY_SERVER");
130
131         if (value || gBufMgr->display_server)
132                 return 1;
133
134         return 0;
135 }
136 /* LCOV_EXCL_STOP */