sync with master
[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
9 Permission is hereby granted, free of charge, to any person obtaining a
10 copy of this software and associated documentation files (the
11 "Software"), to deal in the Software without restriction, including
12 without limitation the rights to use, copy, modify, merge, publish,
13 distribute, sub license, and/or sell copies of the Software, and to
14 permit persons to whom the Software is furnished to do so, subject to
15 the following conditions:
16
17 The above copyright notice and this permission notice (including the
18 next paragraph) shall be included in all copies or substantial portions
19 of the Software.
20
21 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
22 OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
23 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
24 IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR
25 ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
26 TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
27 SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
28
29 **************************************************************************/
30
31 #include "config.h"
32
33 #include <unistd.h>
34 #include <stdio.h>
35 #include <stdlib.h>
36 #include <sys/types.h>
37 #include "tbm_bufmgr_int.h"
38
39 tbm_bufmgr_backend
40 tbm_backend_alloc (void)
41 {
42     tbm_bufmgr_backend bufmgr_backend;
43
44     bufmgr_backend = calloc (1, sizeof(struct _tbm_bufmgr_backend));
45     if (!bufmgr_backend)
46         return NULL;
47
48     return bufmgr_backend;
49 }
50
51 void
52 tbm_backend_free (tbm_bufmgr_backend backend)
53 {
54     if (!backend)
55         return;
56
57     free (backend);
58     backend = NULL;
59 }
60
61 int
62 tbm_backend_init (tbm_bufmgr bufmgr, tbm_bufmgr_backend backend)
63 {
64     int flags = 0;
65
66     if (!bufmgr)
67     {
68         fprintf (stderr, "[libtbm:%d] "
69             "error (%s): fail to init tbm backend... bufmgr is null\n",
70             getpid(), __FUNCTION__);
71         return 0;
72     }
73
74     if (!backend)
75     {
76         fprintf (stderr, "[libtbm:%d] "
77             "error (%s): fail to init tbm backend... backend is null\n",
78             getpid(), __FUNCTION__);
79         return 0;
80     }
81
82     flags = backend->flags;
83     /* check the backend flags */
84     if (!(flags&TBM_CACHE_CTRL_BACKEND))
85     {
86         if (!backend->bo_cache_flush)
87         {
88             fprintf (stderr, "[libtbm:%d] "
89                 "error (%s): TBM_FLAG_CACHE_CTRL_TBM needs backend->bo_cache_flush\n",
90                 getpid(), __FUNCTION__);
91             return 0;
92         }
93     }
94
95     /* log for tbm flags */
96     fprintf (stderr, "[libtbm:%d] ", getpid());
97     fprintf (stderr, "cache_crtl:");
98     if (flags&TBM_CACHE_CTRL_BACKEND)
99         fprintf (stderr, "BACKEND ");
100     else
101         fprintf (stderr, "TBM ");
102     fprintf (stderr, "lock_crtl:");
103     if (flags&TBM_LOCK_CTRL_BACKEND)
104         fprintf (stderr, "BACKEND ");
105     else
106         fprintf (stderr, "TBM ");
107     fprintf (stderr, "\n");
108
109     bufmgr->backend = backend;
110
111     return 1;
112 }
113
114 void *
115 tbm_backend_get_bufmgr_priv (tbm_bo bo)
116 {
117     tbm_bufmgr_backend backend = bo->bufmgr->backend;
118
119     return backend->priv;
120 }
121
122 void
123 tbm_backend_set_bo_priv (tbm_bo bo, void *bo_priv)
124 {
125     bo->priv = bo_priv;
126 }
127
128 void *
129 tbm_backend_get_bo_priv (tbm_bo bo)
130 {
131     return bo->priv;
132 }
133
134
135