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 static int _tbm_surface_internal_get_num_planes (tbm_format format)
44 case TBM_FORMAT_RGB332:
45 case TBM_FORMAT_BGR233:
46 case TBM_FORMAT_XRGB4444:
47 case TBM_FORMAT_XBGR4444:
48 case TBM_FORMAT_RGBX4444:
49 case TBM_FORMAT_BGRX4444:
50 case TBM_FORMAT_ARGB4444:
51 case TBM_FORMAT_ABGR4444:
52 case TBM_FORMAT_RGBA4444:
53 case TBM_FORMAT_BGRA4444:
54 case TBM_FORMAT_XRGB1555:
55 case TBM_FORMAT_XBGR1555:
56 case TBM_FORMAT_RGBX5551:
57 case TBM_FORMAT_BGRX5551:
58 case TBM_FORMAT_ARGB1555:
59 case TBM_FORMAT_ABGR1555:
60 case TBM_FORMAT_RGBA5551:
61 case TBM_FORMAT_BGRA5551:
62 case TBM_FORMAT_RGB565:
63 case TBM_FORMAT_BGR565:
64 case TBM_FORMAT_RGB888:
65 case TBM_FORMAT_BGR888:
66 case TBM_FORMAT_XRGB8888:
67 case TBM_FORMAT_XBGR8888:
68 case TBM_FORMAT_RGBX8888:
69 case TBM_FORMAT_BGRX8888:
70 case TBM_FORMAT_ARGB8888:
71 case TBM_FORMAT_ABGR8888:
72 case TBM_FORMAT_RGBA8888:
73 case TBM_FORMAT_BGRA8888:
74 case TBM_FORMAT_XRGB2101010:
75 case TBM_FORMAT_XBGR2101010:
76 case TBM_FORMAT_RGBX1010102:
77 case TBM_FORMAT_BGRX1010102:
78 case TBM_FORMAT_ARGB2101010:
79 case TBM_FORMAT_ABGR2101010:
80 case TBM_FORMAT_RGBA1010102:
81 case TBM_FORMAT_BGRA1010102:
95 case TBM_FORMAT_YUV410:
96 case TBM_FORMAT_YVU410:
97 case TBM_FORMAT_YUV411:
98 case TBM_FORMAT_YVU411:
99 case TBM_FORMAT_YUV420:
100 case TBM_FORMAT_YVU420:
101 case TBM_FORMAT_YUV422:
102 case TBM_FORMAT_YVU422:
103 case TBM_FORMAT_YUV444:
104 case TBM_FORMAT_YVU444:
116 static int _tbm_surface_internal_get_bpp (tbm_format format)
123 case TBM_FORMAT_RGB332:
124 case TBM_FORMAT_BGR233:
127 case TBM_FORMAT_XRGB4444:
128 case TBM_FORMAT_XBGR4444:
129 case TBM_FORMAT_RGBX4444:
130 case TBM_FORMAT_BGRX4444:
131 case TBM_FORMAT_ARGB4444:
132 case TBM_FORMAT_ABGR4444:
133 case TBM_FORMAT_RGBA4444:
134 case TBM_FORMAT_BGRA4444:
135 case TBM_FORMAT_XRGB1555:
136 case TBM_FORMAT_XBGR1555:
137 case TBM_FORMAT_RGBX5551:
138 case TBM_FORMAT_BGRX5551:
139 case TBM_FORMAT_ARGB1555:
140 case TBM_FORMAT_ABGR1555:
141 case TBM_FORMAT_RGBA5551:
142 case TBM_FORMAT_BGRA5551:
143 case TBM_FORMAT_RGB565:
144 case TBM_FORMAT_BGR565:
147 case TBM_FORMAT_RGB888:
148 case TBM_FORMAT_BGR888:
151 case TBM_FORMAT_XRGB8888:
152 case TBM_FORMAT_XBGR8888:
153 case TBM_FORMAT_RGBX8888:
154 case TBM_FORMAT_BGRX8888:
155 case TBM_FORMAT_ARGB8888:
156 case TBM_FORMAT_ABGR8888:
157 case TBM_FORMAT_RGBA8888:
158 case TBM_FORMAT_BGRA8888:
159 case TBM_FORMAT_XRGB2101010:
160 case TBM_FORMAT_XBGR2101010:
161 case TBM_FORMAT_RGBX1010102:
162 case TBM_FORMAT_BGRX1010102:
163 case TBM_FORMAT_ARGB2101010:
164 case TBM_FORMAT_ABGR2101010:
165 case TBM_FORMAT_RGBA1010102:
166 case TBM_FORMAT_BGRA1010102:
167 case TBM_FORMAT_YUYV:
168 case TBM_FORMAT_YVYU:
169 case TBM_FORMAT_UYVY:
170 case TBM_FORMAT_VYUY:
171 case TBM_FORMAT_AYUV:
174 case TBM_FORMAT_NV12:
175 case TBM_FORMAT_NV21:
178 case TBM_FORMAT_NV16:
179 case TBM_FORMAT_NV61:
182 case TBM_FORMAT_YUV410:
183 case TBM_FORMAT_YVU410:
186 case TBM_FORMAT_YUV411:
187 case TBM_FORMAT_YVU411:
188 case TBM_FORMAT_YUV420:
189 case TBM_FORMAT_YVU420:
192 case TBM_FORMAT_YUV422:
193 case TBM_FORMAT_YVU422:
196 case TBM_FORMAT_YUV444:
197 case TBM_FORMAT_YVU444:
209 tbm_surface_internal_query_supported_formats (tbm_bufmgr bufmgr, uint32_t **formats, uint32_t *num)
211 TBM_RETURN_VAL_IF_FAIL (bufmgr, 0);
213 struct _tbm_bufmgr *mgr = (struct _tbm_bufmgr*)bufmgr;
216 pthread_mutex_lock (&mgr->lock);
218 ret = mgr->backend->surface_supported_format (formats, num);
220 pthread_mutex_unlock (&mgr->lock);
226 tbm_surface_internal_create_with_flags (tbm_bufmgr bufmgr, int width, int height, int format, int flags)
228 TBM_RETURN_VAL_IF_FAIL (bufmgr, NULL);
229 TBM_RETURN_VAL_IF_FAIL (width > 0, NULL);
230 TBM_RETURN_VAL_IF_FAIL (height > 0, NULL);
232 struct _tbm_bufmgr *mgr = (struct _tbm_bufmgr*)bufmgr;
234 TBM_RETURN_VAL_IF_FAIL (TBM_BUFMGR_IS_VALID(mgr), NULL);
236 struct _tbm_surface *surf = NULL;
242 surf = calloc (1, sizeof(struct _tbm_surface));
246 surf->bufmgr = bufmgr;
247 surf->info.width = width;
248 surf->info.height = height;
249 surf->info.format = format;
250 surf->info.bpp = _tbm_surface_internal_get_bpp (format);
251 surf->info.size = tbm_surface_internal_get_size (surf);
252 surf->info.num_planes = _tbm_surface_internal_get_num_planes(format);
254 /* get size, stride and offset */
255 for (i = 0; i < surf->info.num_planes; i++)
257 tbm_surface_internal_get_plane_data (surf, i, &size, &offset, &stride);
258 surf->info.planes[i].size = size;
259 surf->info.planes[i].offset = offset;
260 surf->info.planes[i].stride = stride;
265 /* create only one bo */
267 surf->bos[0] = tbm_bo_alloc (mgr, surf->info.size, flags);
274 // LIST_ADD (&surf->item_link, &mgr->surf_list);
280 tbm_surface_internal_create_with_bos (tbm_bufmgr bufmgr, int width, int height, int format, tbm_bo *bos, int num)
282 TBM_RETURN_VAL_IF_FAIL (bufmgr, NULL);
283 TBM_RETURN_VAL_IF_FAIL (width > 0, NULL);
284 TBM_RETURN_VAL_IF_FAIL (height > 0, NULL);
285 TBM_RETURN_VAL_IF_FAIL (bos, NULL);
287 struct _tbm_bufmgr *mgr = (struct _tbm_bufmgr*)bufmgr;
289 TBM_RETURN_VAL_IF_FAIL (TBM_BUFMGR_IS_VALID(mgr), NULL);
291 struct _tbm_surface *surf = NULL;
297 surf = calloc (1, sizeof(struct _tbm_surface));
301 surf->bufmgr = bufmgr;
302 surf->info.width = width;
303 surf->info.height = height;
304 surf->info.format = format;
305 surf->info.bpp = _tbm_surface_internal_get_bpp (format);
306 surf->info.size = tbm_surface_internal_get_size (surf);
307 surf->info.num_planes = _tbm_surface_internal_get_num_planes(format);
309 /* get size, stride and offset */
310 for (i = 0; i < surf->info.num_planes; i++)
312 tbm_surface_internal_get_plane_data (surf, i, &size, &offset, &stride);
313 surf->info.planes[i].size = size;
314 surf->info.planes[i].offset = offset;
315 surf->info.planes[i].stride = stride;
318 surf->flags = TBM_BO_DEFAULT;
320 /* create only one bo */
322 for (i = 0; i < num; i++)
324 bos[i] = tbm_bo_alloc (mgr, surf->info.size, TBM_BO_DEFAULT);
327 surf->bos[i] = bos[i];
330 // LIST_ADD (&surf->item_link, &mgr->surf_list);
334 for (i = 0; i < num; i++)
350 tbm_surface_internal_get_num_bos (tbm_surface_h surface)
352 TBM_RETURN_VAL_IF_FAIL (surface, 0);
354 struct _tbm_surface *surf = (struct _tbm_surface *) surface;
356 return surf->num_bos;
360 tbm_surface_internal_get_bo (tbm_surface_h surface, int bo_idx)
362 TBM_RETURN_VAL_IF_FAIL (surface, NULL);
363 TBM_RETURN_VAL_IF_FAIL (bo_idx > -1, NULL);
365 struct _tbm_surface *surf = (struct _tbm_surface *) surface;
367 return surf->bos[bo_idx];
371 tbm_surface_internal_get_size (tbm_surface_h surface)
373 TBM_RETURN_VAL_IF_FAIL (surface, 0);
375 struct _tbm_surface *surf = (struct _tbm_surface *) surface;
376 struct _tbm_bufmgr *mgr = surf->bufmgr;
379 TBM_RETURN_VAL_IF_FAIL (surf->info.width > 0, 0);
380 TBM_RETURN_VAL_IF_FAIL (surf->info.height > 0, 0);
381 TBM_RETURN_VAL_IF_FAIL (surf->info.format > 0, 0);
383 pthread_mutex_lock (&mgr->lock);
385 size = mgr->backend->surface_get_size (surf, surf->info.width, surf->info.height, surf->info.format);
387 pthread_mutex_unlock (&mgr->lock);
393 tbm_surface_internal_get_plane_data (tbm_surface_h surface, int plane_idx, uint32_t *size, uint32_t *offset, uint32_t *pitch)
395 TBM_RETURN_VAL_IF_FAIL (surface, 0);
396 TBM_RETURN_VAL_IF_FAIL (plane_idx > -1, 0);
398 struct _tbm_surface *surf = (struct _tbm_surface *) surface;
399 struct _tbm_bufmgr *mgr = surf->bufmgr;
402 TBM_RETURN_VAL_IF_FAIL (surf->info.width > 0, 0);
403 TBM_RETURN_VAL_IF_FAIL (surf->info.height > 0, 0);
404 TBM_RETURN_VAL_IF_FAIL (surf->info.format > 0, 0);
406 pthread_mutex_lock (&mgr->lock);
408 ret = mgr->backend->surface_get_plane_data (surf, surf->info.width, surf->info.height, surf->info.format, plane_idx, size, offset, pitch);
412 pthread_mutex_unlock (&mgr->lock);