87d3c78bbfc7209d861543723763be5e0576f7eb
[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         if (!bufmgr) {
66                 TBM_ERR("error: fail to init tbm backend... bufmgr is null\n");
67                 return 0;
68         }
69
70         if (!backend) {
71                 TBM_ERR("error: fail to init tbm backend... backend is null\n");
72                 return 0;
73         }
74
75         bufmgr->backend = backend;
76         bufmgr->capabilities = TBM_BUFMGR_CAPABILITY_NONE;
77
78         if (bufmgr->backend->bo_import && bufmgr->backend->bo_export)
79                 bufmgr->capabilities |= TBM_BUFMGR_CAPABILITY_SHARE_KEY;
80
81         if (bufmgr->backend->bo_import_fd && bufmgr->backend->bo_export_fd)
82                 bufmgr->capabilities |= TBM_BUFMGR_CAPABILITY_SHARE_FD;
83
84         return 1;
85 }
86
87 void *tbm_backend_get_bufmgr_priv(tbm_bo bo)
88 {
89         tbm_bufmgr_backend backend = bo->bufmgr->backend;
90
91         return backend->priv;
92 }
93
94 void *tbm_backend_get_priv_from_bufmgr(tbm_bufmgr bufmgr)
95 {
96         tbm_bufmgr_backend backend = bufmgr->backend;
97
98         return backend->priv;
99 }
100
101 void tbm_backend_set_bo_priv(tbm_bo bo, void *bo_priv)
102 {
103         bo->priv = bo_priv;
104 }
105
106 void *tbm_backend_get_bo_priv(tbm_bo bo)
107 {
108         return bo->priv;
109 }
110
111 int tbm_backend_is_display_server(void)
112 {
113         const char *value;
114
115         if (gBufMgr == NULL) {
116                 TBM_ERR("error: no gBufMgr.\n");
117                 return 0;
118         }
119
120         /* TODO: TBM_DISPLAY_SERVER will be removed */
121         value = (const char*)getenv("TBM_DISPLAY_SERVER");
122
123         if (value || gBufMgr->display_server)
124                 return 1;
125
126         return 0;
127 }
128 /* LCOV_EXCL_STOP */