1 /**************************************************************************
5 Copyright 2014 Samsung Electronics co., Ltd. All Rights Reserved.
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>
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:
18 The above copyright notice and this permission notice (including the
19 next paragraph) shall be included in all copies or substantial portions
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.
30 **************************************************************************/
33 #include "tbm_bufmgr.h"
34 #include "tbm_bufmgr_int.h"
35 #include "tbm_surface_internal.h"
37 extern tbm_bufmgr gBufMgr;
40 _tbm_surface_get_info (struct _tbm_surface *surf, int opt, tbm_surface_info_s *info, int map)
42 tbm_bo_handle bo_handles[4];
45 info->width = surf->info.width;
46 info->height = surf->info.height;
47 info->format = surf->info.format;
48 info->bpp = surf->info.bpp;
49 info->size = surf->info.size;
50 info->num_planes = surf->info.num_planes;
52 if (surf->num_bos == 1)
56 bo_handles[0] = tbm_bo_map (surf->bos[0], TBM_DEVICE_CPU, opt);
57 if (bo_handles[0].ptr == NULL)
62 bo_handles[0] = tbm_bo_get_handle (surf->bos[0], TBM_DEVICE_CPU);
63 if (bo_handles[0].ptr == NULL)
67 for (i = 0; i < surf->info.num_planes; i++)
69 info->planes[i].size = surf->info.planes[i].size;
70 info->planes[i].offset = surf->info.planes[i].offset;
71 info->planes[i].stride = surf->info.planes[i].stride;
72 info->planes[i].ptr = bo_handles[0].ptr + surf->info.planes[i].offset;
77 /* TODO: calculate the virtaul address when num_bos is over 1 */
84 tbm_surface_query_formats (uint32_t **formats, uint32_t *num)
88 gBufMgr = tbm_bufmgr_init (-1);
91 if (!tbm_surface_internal_query_supported_formats (gBufMgr, formats, num))
92 return TBM_SURFACE_ERROR_INVALID_OPERATION;
94 return TBM_SURFACE_ERROR_NONE;
98 tbm_surface_create (int width, int height, tbm_format format)
100 if (!(width > 0) || !(height > 0))
102 #ifdef HAVE_CAPI_0_1_1
103 set_last_result (TBM_SURFACE_ERROR_INVALID_PARAMETER);
108 struct _tbm_surface *surf = NULL;
112 gBufMgr = tbm_bufmgr_init (-1);
115 surf = tbm_surface_internal_create_with_flags (gBufMgr, width, height, format, TBM_BO_DEFAULT);
118 #ifdef HAVE_CAPI_0_1_1
119 set_last_result (TBM_SURFACE_ERROR_INVALID_OPERATION);
124 #ifdef HAVE_CAPI_0_1_1
125 set_last_result (TBM_SURFACE_ERROR_NONE);
132 tbm_surface_destroy (tbm_surface_h surface)
134 struct _tbm_surface *surf = NULL;
138 return TBM_SURFACE_ERROR_INVALID_PARAMETER;
140 surf = (struct _tbm_surface *)surface;
142 for (i = 0; i < surf->num_bos; i++)
144 tbm_bo_unref (surf->bos[i]);
151 return TBM_SURFACE_ERROR_NONE;
155 tbm_surface_map (tbm_surface_h surface, int opt, tbm_surface_info_s *info)
157 TBM_RETURN_VAL_IF_FAIL (surface != NULL, TBM_SURFACE_ERROR_INVALID_PARAMETER);
158 TBM_RETURN_VAL_IF_FAIL (info != NULL, TBM_SURFACE_ERROR_INVALID_PARAMETER);
160 struct _tbm_surface *surf = (struct _tbm_surface *)surface;
163 ret = _tbm_surface_get_info (surf, opt, info, 1);
165 return TBM_SURFACE_ERROR_INVALID_OPERATION;
167 return TBM_SURFACE_ERROR_NONE;
171 tbm_surface_unmap (tbm_surface_h surface)
173 TBM_RETURN_VAL_IF_FAIL (surface != NULL, TBM_SURFACE_ERROR_INVALID_PARAMETER);
175 struct _tbm_surface *surf = (struct _tbm_surface *)surface;
178 for (i = 0; i < surf->num_bos; i++)
179 tbm_bo_unmap (surf->bos[i]);
181 return TBM_SURFACE_ERROR_NONE;
185 tbm_surface_get_info (tbm_surface_h surface, tbm_surface_info_s *info)
187 TBM_RETURN_VAL_IF_FAIL (surface != NULL, TBM_SURFACE_ERROR_INVALID_PARAMETER);
188 TBM_RETURN_VAL_IF_FAIL (info != NULL, TBM_SURFACE_ERROR_INVALID_PARAMETER);
190 struct _tbm_surface *surf = (struct _tbm_surface *)surface;
193 ret = _tbm_surface_get_info (surf, 0, info, 0);
195 return TBM_SURFACE_ERROR_INVALID_OPERATION;
197 return TBM_SURFACE_ERROR_NONE;
201 tbm_surface_get_width (tbm_surface_h surface)
203 TBM_RETURN_VAL_IF_FAIL (surface != NULL, TBM_SURFACE_ERROR_INVALID_PARAMETER);
205 struct _tbm_surface *surf = (struct _tbm_surface *)surface;
207 return surf->info.width;
211 tbm_surface_get_height (tbm_surface_h surface)
213 TBM_RETURN_VAL_IF_FAIL (surface != NULL, TBM_SURFACE_ERROR_INVALID_PARAMETER);
215 struct _tbm_surface *surf = (struct _tbm_surface *)surface;
217 return surf->info.height;
221 tbm_surface_get_format (tbm_surface_h surface)
225 #ifdef HAVE_CAPI_0_1_1
226 set_last_result (TBM_SURFACE_ERROR_INVALID_PARAMETER);
231 struct _tbm_surface *surf = (struct _tbm_surface *)surface;
233 #ifdef HAVE_CAPI_0_1_1
234 set_last_result (TBM_SURFACE_ERROR_NONE);
236 return surf->info.format;