remove execute permissions
[platform/core/uifw/libtbm.git] / src / tbm_surface.c
1 /**************************************************************************
2
3 libtbm
4
5 Copyright 2014 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 #include "tbm_bufmgr.h"
34 #include "tbm_bufmgr_int.h"
35 #include "tbm_surface_internal.h"
36
37 static int
38 _tbm_surface_get_info (struct _tbm_surface *surf, int opt, tbm_surface_info_s *info, int map)
39 {
40     tbm_bo_handle bo_handles[4];
41     int i;
42
43     info->width = surf->info.width;
44     info->height = surf->info.height;
45     info->format = surf->info.format;
46     info->bpp = surf->info.bpp;
47     info->size = surf->info.size;
48     info->num_planes = surf->info.num_planes;
49
50     if (surf->num_bos == 1)
51     {
52         if (map == 1)
53         {
54             bo_handles[0] = tbm_bo_map (surf->bos[0], TBM_DEVICE_CPU, opt);
55             if (bo_handles[0].ptr == NULL)
56                 return 0;
57         }
58         else
59         {
60             bo_handles[0] = tbm_bo_get_handle (surf->bos[0], TBM_DEVICE_CPU);
61             if (bo_handles[0].ptr == NULL)
62                 return 0;
63         }
64
65         for (i = 0; i < surf->info.num_planes; i++)
66         {
67             info->planes[i].size = surf->info.planes[i].size;
68             info->planes[i].offset = surf->info.planes[i].offset;
69             info->planes[i].stride = surf->info.planes[i].stride;
70             info->planes[i].ptr = bo_handles[0].ptr + surf->info.planes[i].offset;
71         }
72     }
73     else
74     {
75         /* TODO: calculate the virtaul address when num_bos is over 1 */
76     }
77
78     return 1;
79 }
80
81 int
82 tbm_surface_query_formats (uint32_t **formats, uint32_t *num)
83 {
84     if (!tbm_surface_internal_query_supported_formats (formats, num))
85         return TBM_SURFACE_ERROR_INVALID_OPERATION;
86
87     return TBM_SURFACE_ERROR_NONE;
88 }
89
90 tbm_surface_h
91 tbm_surface_create (int width, int height, tbm_format format)
92 {
93     if (!(width > 0) || !(height > 0))
94     {
95 #ifdef HAVE_CAPI_0_1_1
96         set_last_result (TBM_SURFACE_ERROR_INVALID_PARAMETER);
97 #endif
98         return NULL;
99     }
100
101     struct _tbm_surface *surf = NULL;
102
103     surf = tbm_surface_internal_create_with_flags (width, height, format, TBM_BO_DEFAULT);
104     if (!surf)
105     {
106 #ifdef HAVE_CAPI_0_1_1
107         set_last_result (TBM_SURFACE_ERROR_INVALID_OPERATION);
108 #endif
109         return NULL;
110     }
111
112 #ifdef HAVE_CAPI_0_1_1
113     set_last_result (TBM_SURFACE_ERROR_NONE);
114 #endif
115     return surf;
116 }
117
118
119 int
120 tbm_surface_destroy (tbm_surface_h surface)
121 {
122     if (!surface)
123         return TBM_SURFACE_ERROR_INVALID_PARAMETER;
124
125     tbm_surface_internal_destroy (surface);
126
127     return TBM_SURFACE_ERROR_NONE;
128 }
129
130 int
131 tbm_surface_map (tbm_surface_h surface, int opt, tbm_surface_info_s *info)
132 {
133     TBM_RETURN_VAL_IF_FAIL (surface != NULL, TBM_SURFACE_ERROR_INVALID_PARAMETER);
134     TBM_RETURN_VAL_IF_FAIL (info != NULL, TBM_SURFACE_ERROR_INVALID_PARAMETER);
135
136     struct _tbm_surface *surf = (struct _tbm_surface *)surface;
137     int ret = 0;
138
139     ret = _tbm_surface_get_info (surf, opt, info, 1);
140     if (ret == 0)
141         return TBM_SURFACE_ERROR_INVALID_OPERATION;
142
143     return TBM_SURFACE_ERROR_NONE;
144 }
145
146 int
147 tbm_surface_unmap (tbm_surface_h surface)
148 {
149     TBM_RETURN_VAL_IF_FAIL (surface != NULL, TBM_SURFACE_ERROR_INVALID_PARAMETER);
150
151     struct _tbm_surface *surf = (struct _tbm_surface *)surface;
152     int i;
153
154     for (i = 0; i < surf->num_bos; i++)
155         tbm_bo_unmap (surf->bos[i]);
156
157     return TBM_SURFACE_ERROR_NONE;
158 }
159
160 int
161 tbm_surface_get_info (tbm_surface_h surface, tbm_surface_info_s *info)
162 {
163     TBM_RETURN_VAL_IF_FAIL (surface != NULL, TBM_SURFACE_ERROR_INVALID_PARAMETER);
164     TBM_RETURN_VAL_IF_FAIL (info != NULL, TBM_SURFACE_ERROR_INVALID_PARAMETER);
165
166     struct _tbm_surface *surf = (struct _tbm_surface *)surface;
167     int ret = 0;
168
169     ret = _tbm_surface_get_info (surf, 0, info, 0);
170     if (ret == 0)
171         return TBM_SURFACE_ERROR_INVALID_OPERATION;
172
173     return TBM_SURFACE_ERROR_NONE;
174 }
175
176 int
177 tbm_surface_get_width (tbm_surface_h surface)
178 {
179     TBM_RETURN_VAL_IF_FAIL (surface != NULL, TBM_SURFACE_ERROR_INVALID_PARAMETER);
180
181     struct _tbm_surface *surf = (struct _tbm_surface *)surface;
182
183     return surf->info.width;
184 }
185
186 int
187 tbm_surface_get_height (tbm_surface_h surface)
188 {
189     TBM_RETURN_VAL_IF_FAIL (surface != NULL, TBM_SURFACE_ERROR_INVALID_PARAMETER);
190
191     struct _tbm_surface *surf = (struct _tbm_surface *)surface;
192
193     return surf->info.height;
194 }
195
196 tbm_format
197 tbm_surface_get_format (tbm_surface_h surface)
198 {
199     if (!surface)
200     {
201 #ifdef HAVE_CAPI_0_1_1
202         set_last_result (TBM_SURFACE_ERROR_INVALID_PARAMETER);
203 #endif
204         return 0;
205     }
206
207     struct _tbm_surface *surf = (struct _tbm_surface *)surface;
208
209 #ifdef HAVE_CAPI_0_1_1
210     set_last_result (TBM_SURFACE_ERROR_NONE);
211 #endif
212     return surf->info.format;
213 }
214