Merge from Tizen 2.2 release
[platform/core/uifw/libtbm.git] / drm_slp / drm_slp_bufmgr.c
1 /**************************************************************************
2
3 xserver-xorg-video-sec
4
5 Copyright 2011 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 #include <stdio.h>
33 #include <sys/types.h>
34 #include <unistd.h>
35 #include <stdlib.h>
36 #include "drm_slp_bufmgr.h"
37 #include "tbm_bufmgr.h"
38 #include "tbm_bufmgr_int.h"
39
40 drm_slp_bufmgr
41 drm_slp_bufmgr_init(int fd, void *arg)
42 {
43     tbm_bufmgr bufmgr = NULL;
44
45     bufmgr = tbm_bufmgr_init (fd);
46     if (!bufmgr)
47     {
48         TBM_LOG ("[libdrm_slp:%d]: error bufmgr is null\n", getpid());
49         return NULL;
50     }
51
52     return (drm_slp_bufmgr)bufmgr;
53 }
54
55 void
56 drm_slp_bufmgr_destroy(drm_slp_bufmgr bufmgr)
57 {
58     tbm_bufmgr_deinit ((tbm_bufmgr)bufmgr);
59 }
60
61 void
62 drm_slp_bo_unref(drm_slp_bo bo)
63 {
64     tbm_bo_unref ((tbm_bo)bo);
65 }
66
67 drm_slp_bo
68 drm_slp_bo_import(drm_slp_bufmgr bufmgr, unsigned int key)
69 {
70     tbm_bo bo = NULL;
71
72     bo = tbm_bo_import ((tbm_bufmgr)bufmgr, key);
73     if (!bo)
74     {
75         TBM_LOG ("[libdrm_slp:%d]: error bo is null\n", getpid());
76         return NULL;
77     }
78
79     return (drm_slp_bo)bo;
80 }
81
82 unsigned int
83 drm_slp_bo_map(drm_slp_bo bo, int device, int opt)
84 {
85     tbm_bo_handle bo_handle;
86     unsigned long ret = 0;
87
88     bo_handle = tbm_bo_map ((tbm_bo)bo, device, opt);
89     if (bo_handle.ptr == NULL)
90     {
91         TBM_LOG ("[libdrm_slp:%d]: error bo_handle is null\n", getpid());
92         return 0;
93     }
94
95     switch (device)
96     {
97         case TBM_DEVICE_DEFAULT:
98         case TBM_DEVICE_2D:
99         case TBM_DEVICE_3D:
100         case TBM_DEVICE_MM:
101             ret = (unsigned long)bo_handle.u32;
102             break;
103         case TBM_DEVICE_CPU:
104             ret = (unsigned long)bo_handle.ptr;
105             break;
106         default:
107             TBM_LOG ("[libdrm_slp:%d]: error wrong device type\n", getpid());
108             return 0;
109     }
110
111     return ret;
112 }
113
114 int
115 drm_slp_bo_unmap(drm_slp_bo bo, int device)
116 {
117     tbm_bo_unmap ((tbm_bo)bo);
118
119     return 1;
120 }
121