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"
38 static tbm_bufmgr g_surface_bufmgr = NULL;
39 static pthread_mutex_t tbm_surface_lock;
41 char *_tbm_surface_internal_format_to_str(tbm_format format)
45 return "TBM_FORMAT_C8";
46 case TBM_FORMAT_RGB332:
47 return "TBM_FORMAT_RGB332";
48 case TBM_FORMAT_BGR233:
49 return "TBM_FORMAT_BGR233";
50 case TBM_FORMAT_XRGB4444:
51 return "TBM_FORMAT_XRGB4444";
52 case TBM_FORMAT_XBGR4444:
53 return "TBM_FORMAT_XBGR4444";
54 case TBM_FORMAT_RGBX4444:
55 return "TBM_FORMAT_RGBX4444";
56 case TBM_FORMAT_BGRX4444:
57 return "TBM_FORMAT_BGRX4444";
58 case TBM_FORMAT_ARGB4444:
59 return "TBM_FORMAT_ARGB4444";
60 case TBM_FORMAT_ABGR4444:
61 return "TBM_FORMAT_ABGR4444";
62 case TBM_FORMAT_RGBA4444:
63 return "TBM_FORMAT_RGBA4444";
64 case TBM_FORMAT_BGRA4444:
65 return "TBM_FORMAT_BGRA4444";
66 case TBM_FORMAT_XRGB1555:
67 return "TBM_FORMAT_XRGB1555";
68 case TBM_FORMAT_XBGR1555:
69 return "TBM_FORMAT_XBGR1555";
70 case TBM_FORMAT_RGBX5551:
71 return "TBM_FORMAT_RGBX5551";
72 case TBM_FORMAT_BGRX5551:
73 return "TBM_FORMAT_BGRX5551";
74 case TBM_FORMAT_ARGB1555:
75 return "TBM_FORMAT_ARGB1555";
76 case TBM_FORMAT_ABGR1555:
77 return "TBM_FORMAT_ABGR1555";
78 case TBM_FORMAT_RGBA5551:
79 return "TBM_FORMAT_RGBA5551";
80 case TBM_FORMAT_BGRA5551:
81 return "TBM_FORMAT_BGRA5551";
82 case TBM_FORMAT_RGB565:
83 return "TBM_FORMAT_RGB565";
84 case TBM_FORMAT_BGR565:
85 return "TBM_FORMAT_BGR565";
86 case TBM_FORMAT_RGB888:
87 return "TBM_FORMAT_RGB888";
88 case TBM_FORMAT_BGR888:
89 return "TBM_FORMAT_BGR888";
90 case TBM_FORMAT_XRGB8888:
91 return "TBM_FORMAT_XRGB8888";
92 case TBM_FORMAT_XBGR8888:
93 return "TBM_FORMAT_XBGR8888";
94 case TBM_FORMAT_RGBX8888:
95 return "TBM_FORMAT_RGBX8888";
96 case TBM_FORMAT_BGRX8888:
97 return "TBM_FORMAT_BGRX8888";
98 case TBM_FORMAT_ARGB8888:
99 return "TBM_FORMAT_ARGB8888";
100 case TBM_FORMAT_ABGR8888:
101 return "TBM_FORMAT_ABGR8888";
102 case TBM_FORMAT_RGBA8888:
103 return "TBM_FORMAT_RGBA8888";
104 case TBM_FORMAT_BGRA8888:
105 return "TBM_FORMAT_BGRA8888";
106 case TBM_FORMAT_XRGB2101010:
107 return "TBM_FORMAT_XRGB2101010";
108 case TBM_FORMAT_XBGR2101010:
109 return "TBM_FORMAT_XBGR2101010";
110 case TBM_FORMAT_RGBX1010102:
111 return "TBM_FORMAT_RGBX1010102";
112 case TBM_FORMAT_BGRX1010102:
113 return "TBM_FORMAT_BGRX1010102";
114 case TBM_FORMAT_ARGB2101010:
115 return "TBM_FORMAT_ARGB2101010";
116 case TBM_FORMAT_ABGR2101010:
117 return "TBM_FORMAT_ABGR2101010";
118 case TBM_FORMAT_RGBA1010102:
119 return "TBM_FORMAT_RGBA1010102";
120 case TBM_FORMAT_BGRA1010102:
121 return "TBM_FORMAT_BGRA1010102";
122 case TBM_FORMAT_YUYV:
123 return "TBM_FORMAT_YUYV";
124 case TBM_FORMAT_YVYU:
125 return "TBM_FORMAT_YVYU";
126 case TBM_FORMAT_UYVY:
127 return "TBM_FORMAT_UYVY";
128 case TBM_FORMAT_VYUY:
129 return "TBM_FORMAT_VYUY";
130 case TBM_FORMAT_AYUV:
131 return "TBM_FORMAT_AYUV";
132 case TBM_FORMAT_NV12:
133 return "TBM_FORMAT_NV12";
134 case TBM_FORMAT_NV21:
135 return "TBM_FORMAT_NV21";
136 case TBM_FORMAT_NV16:
137 return "TBM_FORMAT_NV16";
138 case TBM_FORMAT_NV61:
139 return "TBM_FORMAT_NV61";
140 case TBM_FORMAT_YUV410:
141 return "TBM_FORMAT_YUV410";
142 case TBM_FORMAT_YVU410:
143 return "TBM_FORMAT_YVU410";
144 case TBM_FORMAT_YUV411:
145 return "TBM_FORMAT_YUV411";
146 case TBM_FORMAT_YVU411:
147 return "TBM_FORMAT_YVU411";
148 case TBM_FORMAT_YUV420:
149 return "TBM_FORMAT_YUV420";
150 case TBM_FORMAT_YVU420:
151 return "TBM_FORMAT_YVU420";
152 case TBM_FORMAT_YUV422:
153 return "TBM_FORMAT_YUV422";
154 case TBM_FORMAT_YVU422:
155 return "TBM_FORMAT_YVU422";
156 case TBM_FORMAT_YUV444:
157 return "TBM_FORMAT_YUV444";
158 case TBM_FORMAT_YVU444:
159 return "TBM_FORMAT_YVU444";
160 case TBM_FORMAT_NV12MT:
161 return "TBM_FORMAT_NV12MT";
167 static bool _tbm_surface_mutex_init(void)
169 static bool tbm_surface_mutex_init = false;
171 if (tbm_surface_mutex_init)
174 if (pthread_mutex_init(&tbm_surface_lock, NULL)) {
175 TBM_LOG("[libtbm] fail: tbm_surface mutex init\n");
179 tbm_surface_mutex_init = true;
184 void _tbm_surface_mutex_lock(void)
186 if (!_tbm_surface_mutex_init())
189 pthread_mutex_lock(&tbm_surface_lock);
192 void _tbm_surface_mutex_unlock(void)
194 pthread_mutex_unlock(&tbm_surface_lock);
197 static void _init_surface_bufmgr()
199 g_surface_bufmgr = tbm_bufmgr_init(-1);
202 static void _deinit_surface_bufmgr()
204 if (!g_surface_bufmgr)
207 tbm_bufmgr_deinit(g_surface_bufmgr);
208 g_surface_bufmgr = NULL;
211 static int _tbm_surface_internal_query_size(tbm_surface_h surface)
213 TBM_RETURN_VAL_IF_FAIL(surface, 0);
215 struct _tbm_surface *surf = (struct _tbm_surface *)surface;
216 struct _tbm_bufmgr *mgr = surf->bufmgr;
219 TBM_RETURN_VAL_IF_FAIL(mgr != NULL, 0);
220 TBM_RETURN_VAL_IF_FAIL(surf->info.width > 0, 0);
221 TBM_RETURN_VAL_IF_FAIL(surf->info.height > 0, 0);
222 TBM_RETURN_VAL_IF_FAIL(surf->info.format > 0, 0);
224 if (!mgr->backend->surface_get_size)
227 size = mgr->backend->surface_get_size(surf, surf->info.width, surf->info.height, surf->info.format);
232 static int _tbm_surface_internal_query_plane_data(tbm_surface_h surface, int plane_idx, uint32_t * size, uint32_t * offset, uint32_t * pitch, int *bo_idx)
234 TBM_RETURN_VAL_IF_FAIL(surface, 0);
235 TBM_RETURN_VAL_IF_FAIL(plane_idx > -1, 0);
237 struct _tbm_surface *surf = (struct _tbm_surface *)surface;
238 struct _tbm_bufmgr *mgr = surf->bufmgr;
241 TBM_RETURN_VAL_IF_FAIL(mgr != NULL, 0);
242 TBM_RETURN_VAL_IF_FAIL(surf->info.width > 0, 0);
243 TBM_RETURN_VAL_IF_FAIL(surf->info.height > 0, 0);
244 TBM_RETURN_VAL_IF_FAIL(surf->info.format > 0, 0);
246 if (!mgr->backend->surface_get_plane_data)
249 ret = mgr->backend->surface_get_plane_data(surf, surf->info.width, surf->info.height, surf->info.format, plane_idx, size, offset, pitch, bo_idx);
256 static int _tbm_surface_internal_query_num_bos(tbm_format format)
258 TBM_RETURN_VAL_IF_FAIL(format > 0, 0);
259 struct _tbm_bufmgr *mgr;
262 mgr = g_surface_bufmgr;
264 if (!mgr->backend->surface_get_num_bos)
267 ret = mgr->backend->surface_get_num_bos(format);
274 static void _tbm_surface_internal_destroy(tbm_surface_h surface)
277 tbm_bufmgr bufmgr = surface->bufmgr;
278 tbm_user_data *old_data = NULL, *tmp = NULL;
280 for (i = 0; i < surface->num_bos; i++) {
281 surface->bos[i]->surface = NULL;
283 tbm_bo_unref(surface->bos[i]);
284 surface->bos[i] = NULL;
287 /* destory the user_data_list */
288 if (!LIST_IS_EMPTY(&surface->user_data_list)) {
289 LIST_FOR_EACH_ENTRY_SAFE(old_data, tmp, &surface->user_data_list, item_link) {
290 TBM_LOG("[tbm_surface:%d] free user_data \n",
292 user_data_delete(old_data);
296 LIST_DEL(&surface->item_link);
301 if (LIST_IS_EMPTY(&bufmgr->surf_list)) {
302 LIST_DELINIT(&bufmgr->surf_list);
303 _deinit_surface_bufmgr();
307 int tbm_surface_internal_query_supported_formats(uint32_t ** formats, uint32_t * num)
309 struct _tbm_bufmgr *mgr;
312 _tbm_surface_mutex_lock();
314 if (!g_surface_bufmgr) {
315 _init_surface_bufmgr();
316 LIST_INITHEAD(&g_surface_bufmgr->surf_list);
319 mgr = g_surface_bufmgr;
321 if (!mgr->backend->surface_supported_format) {
322 _tbm_surface_mutex_unlock();
326 ret = mgr->backend->surface_supported_format(formats, num);
328 _tbm_surface_mutex_unlock();
333 int tbm_surface_internal_get_num_planes(tbm_format format)
339 case TBM_FORMAT_RGB332:
340 case TBM_FORMAT_BGR233:
341 case TBM_FORMAT_XRGB4444:
342 case TBM_FORMAT_XBGR4444:
343 case TBM_FORMAT_RGBX4444:
344 case TBM_FORMAT_BGRX4444:
345 case TBM_FORMAT_ARGB4444:
346 case TBM_FORMAT_ABGR4444:
347 case TBM_FORMAT_RGBA4444:
348 case TBM_FORMAT_BGRA4444:
349 case TBM_FORMAT_XRGB1555:
350 case TBM_FORMAT_XBGR1555:
351 case TBM_FORMAT_RGBX5551:
352 case TBM_FORMAT_BGRX5551:
353 case TBM_FORMAT_ARGB1555:
354 case TBM_FORMAT_ABGR1555:
355 case TBM_FORMAT_RGBA5551:
356 case TBM_FORMAT_BGRA5551:
357 case TBM_FORMAT_RGB565:
358 case TBM_FORMAT_BGR565:
359 case TBM_FORMAT_RGB888:
360 case TBM_FORMAT_BGR888:
361 case TBM_FORMAT_XRGB8888:
362 case TBM_FORMAT_XBGR8888:
363 case TBM_FORMAT_RGBX8888:
364 case TBM_FORMAT_BGRX8888:
365 case TBM_FORMAT_ARGB8888:
366 case TBM_FORMAT_ABGR8888:
367 case TBM_FORMAT_RGBA8888:
368 case TBM_FORMAT_BGRA8888:
369 case TBM_FORMAT_XRGB2101010:
370 case TBM_FORMAT_XBGR2101010:
371 case TBM_FORMAT_RGBX1010102:
372 case TBM_FORMAT_BGRX1010102:
373 case TBM_FORMAT_ARGB2101010:
374 case TBM_FORMAT_ABGR2101010:
375 case TBM_FORMAT_RGBA1010102:
376 case TBM_FORMAT_BGRA1010102:
377 case TBM_FORMAT_YUYV:
378 case TBM_FORMAT_YVYU:
379 case TBM_FORMAT_UYVY:
380 case TBM_FORMAT_VYUY:
381 case TBM_FORMAT_AYUV:
384 case TBM_FORMAT_NV12:
385 case TBM_FORMAT_NV21:
386 case TBM_FORMAT_NV16:
387 case TBM_FORMAT_NV61:
390 case TBM_FORMAT_YUV410:
391 case TBM_FORMAT_YVU410:
392 case TBM_FORMAT_YUV411:
393 case TBM_FORMAT_YVU411:
394 case TBM_FORMAT_YUV420:
395 case TBM_FORMAT_YVU420:
396 case TBM_FORMAT_YUV422:
397 case TBM_FORMAT_YVU422:
398 case TBM_FORMAT_YUV444:
399 case TBM_FORMAT_YVU444:
410 int tbm_surface_internal_get_bpp(tbm_format format)
416 case TBM_FORMAT_RGB332:
417 case TBM_FORMAT_BGR233:
420 case TBM_FORMAT_XRGB4444:
421 case TBM_FORMAT_XBGR4444:
422 case TBM_FORMAT_RGBX4444:
423 case TBM_FORMAT_BGRX4444:
424 case TBM_FORMAT_ARGB4444:
425 case TBM_FORMAT_ABGR4444:
426 case TBM_FORMAT_RGBA4444:
427 case TBM_FORMAT_BGRA4444:
428 case TBM_FORMAT_XRGB1555:
429 case TBM_FORMAT_XBGR1555:
430 case TBM_FORMAT_RGBX5551:
431 case TBM_FORMAT_BGRX5551:
432 case TBM_FORMAT_ARGB1555:
433 case TBM_FORMAT_ABGR1555:
434 case TBM_FORMAT_RGBA5551:
435 case TBM_FORMAT_BGRA5551:
436 case TBM_FORMAT_RGB565:
437 case TBM_FORMAT_BGR565:
440 case TBM_FORMAT_RGB888:
441 case TBM_FORMAT_BGR888:
444 case TBM_FORMAT_XRGB8888:
445 case TBM_FORMAT_XBGR8888:
446 case TBM_FORMAT_RGBX8888:
447 case TBM_FORMAT_BGRX8888:
448 case TBM_FORMAT_ARGB8888:
449 case TBM_FORMAT_ABGR8888:
450 case TBM_FORMAT_RGBA8888:
451 case TBM_FORMAT_BGRA8888:
452 case TBM_FORMAT_XRGB2101010:
453 case TBM_FORMAT_XBGR2101010:
454 case TBM_FORMAT_RGBX1010102:
455 case TBM_FORMAT_BGRX1010102:
456 case TBM_FORMAT_ARGB2101010:
457 case TBM_FORMAT_ABGR2101010:
458 case TBM_FORMAT_RGBA1010102:
459 case TBM_FORMAT_BGRA1010102:
460 case TBM_FORMAT_YUYV:
461 case TBM_FORMAT_YVYU:
462 case TBM_FORMAT_UYVY:
463 case TBM_FORMAT_VYUY:
464 case TBM_FORMAT_AYUV:
467 case TBM_FORMAT_NV12:
468 case TBM_FORMAT_NV21:
471 case TBM_FORMAT_NV16:
472 case TBM_FORMAT_NV61:
475 case TBM_FORMAT_YUV410:
476 case TBM_FORMAT_YVU410:
479 case TBM_FORMAT_YUV411:
480 case TBM_FORMAT_YVU411:
481 case TBM_FORMAT_YUV420:
482 case TBM_FORMAT_YVU420:
485 case TBM_FORMAT_YUV422:
486 case TBM_FORMAT_YVU422:
489 case TBM_FORMAT_YUV444:
490 case TBM_FORMAT_YVU444:
500 tbm_surface_h tbm_surface_internal_create_with_flags(int width, int height, int format, int flags)
502 TBM_RETURN_VAL_IF_FAIL(width > 0, NULL);
503 TBM_RETURN_VAL_IF_FAIL(height > 0, NULL);
505 struct _tbm_bufmgr *mgr;
506 struct _tbm_surface *surf = NULL;
510 uint32_t bo_size = 0;
514 _tbm_surface_mutex_lock();
516 if (!g_surface_bufmgr) {
517 _init_surface_bufmgr();
518 LIST_INITHEAD(&g_surface_bufmgr->surf_list);
521 mgr = g_surface_bufmgr;
522 if (!TBM_BUFMGR_IS_VALID(mgr)) {
523 _tbm_surface_mutex_unlock();
526 surf = calloc(1, sizeof(struct _tbm_surface));
528 _tbm_surface_mutex_unlock();
533 surf->info.width = width;
534 surf->info.height = height;
535 surf->info.format = format;
536 surf->info.bpp = tbm_surface_internal_get_bpp(format);
537 surf->info.size = _tbm_surface_internal_query_size(surf);
538 surf->info.num_planes = tbm_surface_internal_get_num_planes(format);
539 surf->num_bos = _tbm_surface_internal_query_num_bos(format);
542 /* get size, stride and offset bo_idx */
543 for (i = 0; i < surf->info.num_planes; i++) {
544 _tbm_surface_internal_query_plane_data(surf, i, &size, &offset, &stride, &bo_idx);
545 surf->info.planes[i].size = size;
546 surf->info.planes[i].offset = offset;
547 surf->info.planes[i].stride = stride;
548 surf->planes_bo_idx[i] = bo_idx;
553 for (i = 0; i < surf->num_bos; i++) {
555 for (j = 0; j < surf->info.num_planes; j++) {
556 if (surf->planes_bo_idx[j] == i)
557 bo_size += surf->info.planes[j].size;
559 surf->bos[i] = tbm_bo_alloc(mgr, bo_size, flags);
561 for (j = 0; j < i; j++) {
563 tbm_bo_unref(surf->bos[j]);
569 if (LIST_IS_EMPTY(&mgr->surf_list)) {
570 LIST_DELINIT(&mgr->surf_list);
571 _deinit_surface_bufmgr();
574 _tbm_surface_mutex_unlock();
577 _tbm_bo_set_surface(surf->bos[i], surf);
581 LIST_ADD(&surf->item_link, &mgr->surf_list);
583 _tbm_surface_mutex_unlock();
588 tbm_surface_h tbm_surface_internal_create_with_bos(tbm_surface_info_s * info, tbm_bo * bos, int num)
590 TBM_RETURN_VAL_IF_FAIL(bos, NULL);
591 TBM_RETURN_VAL_IF_FAIL(info, NULL);
592 TBM_RETURN_VAL_IF_FAIL(num == 1 || info->num_planes == num, NULL);
594 struct _tbm_bufmgr *mgr;
595 struct _tbm_surface *surf = NULL;
598 _tbm_surface_mutex_lock();
600 if (!g_surface_bufmgr) {
601 _init_surface_bufmgr();
602 LIST_INITHEAD(&g_surface_bufmgr->surf_list);
605 mgr = g_surface_bufmgr;
606 if (!TBM_BUFMGR_IS_VALID(mgr)) {
607 _tbm_surface_mutex_unlock();
611 surf = calloc(1, sizeof(struct _tbm_surface));
613 _tbm_surface_mutex_unlock();
618 surf->info.width = info->width;
619 surf->info.height = info->height;
620 surf->info.format = info->format;
621 surf->info.bpp = info->bpp;
622 surf->info.num_planes = info->num_planes;
625 /* get size, stride and offset */
626 for (i = 0; i < info->num_planes; i++) {
627 surf->info.planes[i].offset = info->planes[i].offset;
628 surf->info.planes[i].stride = info->planes[i].stride;
630 if (info->planes[i].size > 0)
631 surf->info.planes[i].size = info->planes[i].size;
633 surf->info.planes[i].size += surf->info.planes[i].stride * info->height;
636 surf->planes_bo_idx[i] = 0;
638 surf->planes_bo_idx[i] = i;
641 if (info->size > 0) {
642 surf->info.size = info->size;
645 for (i = 0; i < info->num_planes; i++)
646 surf->info.size += surf->info.planes[i].size;
649 surf->flags = TBM_BO_DEFAULT;
651 /* create only one bo */
653 for (i = 0; i < num; i++) {
657 surf->bos[i] = tbm_bo_ref(bos[i]);
658 _tbm_bo_set_surface(bos[i], surf);
661 LIST_ADD(&surf->item_link, &mgr->surf_list);
663 _tbm_surface_mutex_unlock();
667 for (i = 0; i < num; i++) {
669 tbm_bo_unref(surf->bos[i]);
677 if (LIST_IS_EMPTY(&g_surface_bufmgr->surf_list)) {
678 LIST_DELINIT(&g_surface_bufmgr->surf_list);
679 _deinit_surface_bufmgr();
682 _tbm_surface_mutex_unlock();
687 void tbm_surface_internal_destroy(tbm_surface_h surface)
692 _tbm_surface_mutex_lock();
696 if (surface->refcnt > 0) {
697 _tbm_surface_mutex_unlock();
701 if (surface->refcnt == 0)
702 _tbm_surface_internal_destroy(surface);
704 _tbm_surface_mutex_unlock();
707 void tbm_surface_internal_ref(tbm_surface_h surface)
709 TBM_RETURN_IF_FAIL(surface);
711 _tbm_surface_mutex_lock();
715 _tbm_surface_mutex_unlock();
718 void tbm_surface_internal_unref(tbm_surface_h surface)
720 TBM_RETURN_IF_FAIL(surface);
722 _tbm_surface_mutex_lock();
726 if (surface->refcnt > 0) {
727 _tbm_surface_mutex_unlock();
731 if (surface->refcnt == 0)
732 _tbm_surface_internal_destroy(surface);
734 _tbm_surface_mutex_unlock();
737 int tbm_surface_internal_get_num_bos(tbm_surface_h surface)
739 TBM_RETURN_VAL_IF_FAIL(surface, 0);
741 struct _tbm_surface *surf;
744 _tbm_surface_mutex_lock();
746 surf = (struct _tbm_surface *)surface;
749 _tbm_surface_mutex_unlock();
754 tbm_bo tbm_surface_internal_get_bo(tbm_surface_h surface, int bo_idx)
756 TBM_RETURN_VAL_IF_FAIL(surface, NULL);
757 TBM_RETURN_VAL_IF_FAIL(bo_idx > -1, NULL);
759 struct _tbm_surface *surf;
762 _tbm_surface_mutex_lock();
764 surf = (struct _tbm_surface *)surface;
765 bo = surf->bos[bo_idx];
767 _tbm_surface_mutex_unlock();
772 int tbm_surface_internal_get_size(tbm_surface_h surface)
774 TBM_RETURN_VAL_IF_FAIL(surface, 0);
776 struct _tbm_surface *surf;
779 _tbm_surface_mutex_lock();
781 surf = (struct _tbm_surface *)surface;
782 size = surf->info.size;
784 _tbm_surface_mutex_unlock();
789 int tbm_surface_internal_get_plane_data(tbm_surface_h surface, int plane_idx, uint32_t * size, uint32_t * offset, uint32_t * pitch)
791 TBM_RETURN_VAL_IF_FAIL(surface, 0);
792 TBM_RETURN_VAL_IF_FAIL(plane_idx > -1, 0);
794 struct _tbm_surface *surf;
796 _tbm_surface_mutex_lock();
798 surf = (struct _tbm_surface *)surface;
800 if (plane_idx >= surf->info.num_planes) {
801 _tbm_surface_mutex_unlock();
806 *size = surf->info.planes[plane_idx].size;
809 *offset = surf->info.planes[plane_idx].offset;
812 *pitch = surf->info.planes[plane_idx].stride;
814 _tbm_surface_mutex_unlock();
819 int tbm_surface_internal_get_info(tbm_surface_h surface, int opt, tbm_surface_info_s * info, int map)
821 struct _tbm_surface *surf;
822 tbm_bo_handle bo_handles[4];
825 _tbm_surface_mutex_lock();
827 memset(bo_handles, 0, sizeof(tbm_bo_handle) * 4);
829 surf = (struct _tbm_surface *)surface;
831 info->width = surf->info.width;
832 info->height = surf->info.height;
833 info->format = surf->info.format;
834 info->bpp = surf->info.bpp;
835 info->size = surf->info.size;
836 info->num_planes = surf->info.num_planes;
839 for (i = 0; i < surf->num_bos; i++) {
840 bo_handles[i] = tbm_bo_map(surf->bos[i], TBM_DEVICE_CPU, opt);
841 if (bo_handles[i].ptr == NULL) {
842 for (j = 0; j < i; j++)
843 tbm_bo_unmap(surf->bos[j]);
845 _tbm_surface_mutex_unlock();
850 for (i = 0; i < surf->num_bos; i++) {
851 bo_handles[i] = tbm_bo_get_handle(surf->bos[i], TBM_DEVICE_CPU);
852 if (bo_handles[i].ptr == NULL) {
853 _tbm_surface_mutex_unlock();
859 for (i = 0; i < surf->info.num_planes; i++) {
860 info->planes[i].size = surf->info.planes[i].size;
861 info->planes[i].offset = surf->info.planes[i].offset;
862 info->planes[i].stride = surf->info.planes[i].stride;
863 info->planes[i].ptr = bo_handles[surf->planes_bo_idx[i]].ptr + surf->info.planes[i].offset;
866 _tbm_surface_mutex_unlock();
871 void tbm_surface_internal_unmap(tbm_surface_h surface)
873 struct _tbm_surface *surf;
876 _tbm_surface_mutex_lock();
878 surf = (struct _tbm_surface *)surface;
880 for (i = 0; i < surf->num_bos; i++)
881 tbm_bo_unmap(surf->bos[i]);
883 _tbm_surface_mutex_unlock();
886 unsigned int tbm_surface_internal_get_width(tbm_surface_h surface)
888 struct _tbm_surface *surf;
891 _tbm_surface_mutex_lock();
893 surf = (struct _tbm_surface *)surface;
894 width = surf->info.width;
896 _tbm_surface_mutex_unlock();
901 unsigned int tbm_surface_internal_get_height(tbm_surface_h surface)
903 struct _tbm_surface *surf;
906 _tbm_surface_mutex_lock();
908 surf = (struct _tbm_surface *)surface;
909 height = surf->info.height;
911 _tbm_surface_mutex_unlock();
917 tbm_format tbm_surface_internal_get_format(tbm_surface_h surface)
919 struct _tbm_surface *surf;
922 _tbm_surface_mutex_lock();
924 surf = (struct _tbm_surface *)surface;
925 format = surf->info.format;
927 _tbm_surface_mutex_unlock();
932 int tbm_surface_internal_get_plane_bo_idx(tbm_surface_h surface, int plane_idx)
934 TBM_RETURN_VAL_IF_FAIL(surface, 0);
935 TBM_RETURN_VAL_IF_FAIL(plane_idx > -1, 0);
936 struct _tbm_surface *surf;
939 _tbm_surface_mutex_lock();
941 surf = (struct _tbm_surface *)surface;
942 bo_idx = surf->planes_bo_idx[plane_idx];
944 _tbm_surface_mutex_unlock();
949 unsigned int _tbm_surface_internal_get_debug_pid(tbm_surface_h surface)
951 TBM_RETURN_VAL_IF_FAIL(surface, 0);
953 return surface->debug_pid;
956 void tbm_surface_internal_set_debug_pid(tbm_surface_h surface, unsigned int pid)
958 TBM_RETURN_IF_FAIL(surface);
960 surface->debug_pid = pid;
963 int tbm_surface_internal_add_user_data(tbm_surface_h surface, unsigned long key, tbm_data_free data_free_func)
965 TBM_RETURN_VAL_IF_FAIL(surface, 0);
969 /* check if the data according to the key exist if so, return false. */
970 data = user_data_lookup(&surface->user_data_list, key);
972 TBM_LOG("[libtbm:%d] "
973 "waring: %s:%d user data already exist. key:%ld\n",
974 getpid(), __FUNCTION__, __LINE__, key);
978 data = user_data_create(key, data_free_func);
982 LIST_ADD(&data->item_link, &surface->user_data_list);
987 int tbm_surface_internal_set_user_data(tbm_surface_h surface, unsigned long key, void *data)
989 TBM_RETURN_VAL_IF_FAIL(surface, 0);
991 tbm_user_data *old_data;
993 if (LIST_IS_EMPTY(&surface->user_data_list))
996 old_data = user_data_lookup(&surface->user_data_list, key);
1000 if (old_data->data && old_data->free_func)
1001 old_data->free_func(old_data->data);
1003 old_data->data = data;
1008 int tbm_surface_internal_get_user_data(tbm_surface_h surface, unsigned long key, void **data)
1010 TBM_RETURN_VAL_IF_FAIL(surface, 0);
1012 tbm_user_data *old_data;
1014 if (!data || LIST_IS_EMPTY(&surface->user_data_list))
1017 old_data = user_data_lookup(&surface->user_data_list, key);
1023 *data = old_data->data;
1028 int tbm_surface_internal_delete_user_data(tbm_surface_h surface, unsigned long key)
1030 TBM_RETURN_VAL_IF_FAIL(surface, 0);
1032 tbm_user_data *old_data = (void *)0;
1034 if (LIST_IS_EMPTY(&surface->user_data_list))
1037 old_data = user_data_lookup(&surface->user_data_list, key);
1041 user_data_delete(old_data);