1 /**************************************************************************
5 Copyright 2012 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"
37 #define TBM_BO_MAGIC 0xBF011234
40 #define TBM_BO_RETURN_IF_FAIL(cond) {\
42 TBM_ERR("'%s' failed.\n", #cond);\
43 _tbm_set_last_result(TBM_ERROR_INVALID_PARAMETER);\
44 _tbm_bufmgr_mutex_unlock();\
49 #define TBM_BO_RETURN_VAL_IF_FAIL(cond, val) {\
51 TBM_ERR("'%s' failed.\n", #cond);\
52 _tbm_set_last_result(TBM_ERROR_INVALID_PARAMETER);\
53 _tbm_bufmgr_mutex_unlock();\
59 _tbm_flag_to_str(int f)
63 if (f == TBM_BO_DEFAULT)
64 snprintf(str, 255, "DEFAULT");
68 if (f & TBM_BO_SCANOUT)
69 c += snprintf(&str[c], 255-c, "SCANOUT");
71 if (f & TBM_BO_NONCACHABLE) {
72 if (c >= 0 && c < 255)
73 c += snprintf(&str[c], 255-c, ", ");
75 if (c >= 0 && c < 255)
76 c += snprintf(&str[c], 255-c, "NONCACHABLE,");
80 if (c >= 0 && c < 255)
81 c += snprintf(&str[c], 255-c, ", ");
83 if (c >= 0 && c < 255)
84 c += snprintf(&str[c], 255-c, "WC");
92 _tbm_util_check_bo_cnt(tbm_bufmgr bufmgr)
94 static int last_chk_bo_cnt = 0;
96 if ((bufmgr->bo_cnt >= 500) && ((bufmgr->bo_cnt % 20) == 0) &&
97 (bufmgr->bo_cnt > last_chk_bo_cnt)) {
98 TBM_DBG("============TBM BO CNT DEBUG: bo_cnt=%d\n", bufmgr->bo_cnt);
99 tbm_bufmgr_debug_show(bufmgr);
100 last_chk_bo_cnt = bufmgr->bo_cnt;
106 user_data_lookup(struct list_head *user_data_list, unsigned long key)
108 tbm_user_data *old_data = NULL;
110 if (LIST_IS_EMPTY(user_data_list))
113 LIST_FOR_EACH_ENTRY(old_data, user_data_list, item_link) {
114 if (old_data->key == key)
122 user_data_create(unsigned long key, tbm_data_free data_free_func)
124 tbm_user_data *user_data;
126 user_data = calloc(1, sizeof(tbm_user_data));
128 /* LCOV_EXCL_START */
129 TBM_ERR("fail to allocate an user_date\n");
130 _tbm_set_last_result(TBM_ERROR_OUT_OF_MEMORY);
135 user_data->key = key;
136 user_data->free_func = data_free_func;
142 user_data_delete(tbm_user_data *user_data)
144 if (user_data->data && user_data->free_func)
145 user_data->free_func(user_data->data);
147 LIST_DEL(&user_data->item_link);
153 _bo_lock(tbm_bo bo, int device, int opt)
158 if (bo->bufmgr->use_hal_tbm) {
159 error = (tbm_error_e)hal_tbm_bo_lock((hal_tbm_bo *)bo->bo_data, device, opt);
160 if (error != TBM_ERROR_NONE) {
161 TBM_WRN("fail to lock");
162 _tbm_set_last_result(error);
165 } else if (bo->bufmgr->backend_module_data) {
166 if (bo->bufmgr->bo_func->bo_lock) {
167 error = bo->bufmgr->bo_func->bo_lock(bo->bo_data, device, opt);
168 if (error != TBM_ERROR_NONE) {
169 TBM_WRN("fail to lock");
170 _tbm_set_last_result(error);
175 if (bo->bufmgr->backend->bo_lock) {
176 ret = bo->bufmgr->backend->bo_lock(bo, device, opt);
178 _tbm_set_last_result(TBM_ERROR_INVALID_OPERATION);
186 _bo_unlock(tbm_bo bo)
190 if (bo->bufmgr->use_hal_tbm) {
191 error = (tbm_error_e)hal_tbm_bo_unlock((hal_tbm_bo *)bo->bo_data);
192 if (error != TBM_ERROR_NONE) {
193 TBM_WRN("fail to lock");
194 _tbm_set_last_result(error);
196 } else if (bo->bufmgr->backend_module_data) {
197 if (bo->bufmgr->bo_func->bo_unlock) {
198 error = bo->bufmgr->bo_func->bo_unlock(bo->bo_data);
199 if (error != TBM_ERROR_NONE) {
200 TBM_WRN("fail to unlock");
201 _tbm_set_last_result(error);
205 if (bo->bufmgr->backend->bo_unlock)
206 bo->bufmgr->backend->bo_unlock(bo);
211 _tbm_bo_lock(tbm_bo bo, int device, int opt)
218 /* do not try to lock the bo */
219 if (bo->bufmgr->bo_lock_type == TBM_BUFMGR_BO_LOCK_TYPE_NEVER)
222 if (bo->lock_cnt < 0) {
223 TBM_ERR("error bo:%p LOCK_CNT=%d\n",
230 switch (bo->bufmgr->bo_lock_type) {
231 case TBM_BUFMGR_BO_LOCK_TYPE_ONCE:
232 if (bo->lock_cnt == 0) {
233 _tbm_bufmgr_mutex_unlock();
234 ret = _bo_lock(bo, device, opt);
235 _tbm_bufmgr_mutex_lock();
241 case TBM_BUFMGR_BO_LOCK_TYPE_ALWAYS:
242 _tbm_bufmgr_mutex_unlock();
243 ret = _bo_lock(bo, device, opt);
244 _tbm_bufmgr_mutex_lock();
249 TBM_ERR("error bo:%p bo_lock_type[%d] is wrong.\n",
250 bo, bo->bufmgr->bo_lock_type);
255 TBM_DBG(">> LOCK bo:%p(%d->%d)\n", bo, old, bo->lock_cnt);
261 _tbm_bo_unlock(tbm_bo bo)
265 /* do not try to unlock the bo */
266 if (bo->bufmgr->bo_lock_type == TBM_BUFMGR_BO_LOCK_TYPE_NEVER)
271 switch (bo->bufmgr->bo_lock_type) {
272 case TBM_BUFMGR_BO_LOCK_TYPE_ONCE:
273 if (bo->lock_cnt > 0) {
275 if (bo->lock_cnt == 0)
279 case TBM_BUFMGR_BO_LOCK_TYPE_ALWAYS:
280 if (bo->lock_cnt > 0) {
286 TBM_ERR("error bo:%p bo_lock_type[%d] is wrong.\n",
287 bo, bo->bufmgr->bo_lock_type);
291 if (bo->lock_cnt < 0)
294 TBM_DBG(">> UNLOCK bo:%p(%d->%d)\n", bo, old, bo->lock_cnt);
298 _tbm_bo_magic_check(tbm_bo bo)
300 if (bo->magic != TBM_BO_MAGIC)
307 _tbm_bo_is_valid(tbm_bo bo)
310 TBM_ERR("error: bo is NULL.\n");
314 if (!_tbm_bo_magic_check(bo)) {
315 TBM_ERR("error: No valid bo(%p).\n", bo);
323 _tbm_bo_init(tbm_bufmgr bufmgr, tbm_bo bo, int flags)
327 bo->magic = TBM_BO_MAGIC;
330 LIST_INITHEAD(&bo->user_data_list);
333 LIST_ADD(&bo->item_link, &bufmgr->bo_list);
337 _tbm_bo_deinit(tbm_bo bo)
341 bo->bufmgr->bo_cnt--;
342 LIST_DEL(&bo->item_link);
346 tbm_bo_alloc(tbm_bufmgr bufmgr, int size, int flags)
350 tbm_backend_bo_data *bo_data;
353 _tbm_bufmgr_mutex_lock();
354 _tbm_set_last_result(TBM_ERROR_NONE);
356 TBM_BO_RETURN_VAL_IF_FAIL(TBM_BUFMGR_IS_VALID(bufmgr), NULL);
357 TBM_BO_RETURN_VAL_IF_FAIL(size > 0, NULL);
359 bo = calloc(1, sizeof(struct _tbm_bo));
361 /* LCOV_EXCL_START */
362 _tbm_set_last_result(TBM_ERROR_OUT_OF_MEMORY);
363 _tbm_bufmgr_mutex_unlock();
368 _tbm_util_check_bo_cnt(bufmgr);
370 if (bufmgr->use_hal_tbm) {
371 bo_data = (tbm_backend_bo_data *)hal_tbm_bufmgr_alloc_bo(bufmgr->hal_bufmgr, size, flags, (hal_tbm_error *)&error);
372 /* LCOV_EXCL_START */
374 _tbm_set_last_result(error);
378 bo->bo_data = bo_data;
379 } else if (bufmgr->backend_module_data) {
380 bo_data = bufmgr->bufmgr_func->bufmgr_alloc_bo(bufmgr->bufmgr_data, (unsigned int)size, flags, &error);
382 /* LCOV_EXCL_START */
383 _tbm_set_last_result(error);
387 bo->bo_data = bo_data;
389 bo_priv = bufmgr->backend->bo_alloc(bo, size, flags);
391 /* LCOV_EXCL_START */
393 _tbm_set_last_result(TBM_ERROR_INVALID_OPERATION);
400 _tbm_bo_init(bufmgr, bo, flags);
402 TBM_TRACE_BO("bo(%p) size(%d) refcnt(%d), flag(%s)\n", bo, size, bo->ref_cnt,
403 _tbm_flag_to_str(bo->flags));
405 _tbm_bufmgr_mutex_unlock();
410 TBM_ERR("error: fail to create of tbm_bo size(%d) flag(%s)\n", size, _tbm_flag_to_str(flags));
412 _tbm_bufmgr_mutex_unlock();
416 /* LCOV_EXCL_START */
418 tbm_bo_alloc_with_format(tbm_bufmgr bufmgr, int format, int bo_idx, int width,
419 int height, tbm_bo_memory_type flags, tbm_error_e *error)
422 tbm_backend_bo_data *bo_data;
424 _tbm_bufmgr_mutex_lock();
425 _tbm_set_last_result(TBM_ERROR_NONE);
427 TBM_BO_RETURN_VAL_IF_FAIL(TBM_BUFMGR_IS_VALID(bufmgr), NULL);
429 bo = calloc(1, sizeof(struct _tbm_bo));
431 TBM_ERR("error: fail to tbm_bo_alloc_with_format fmt(%s) idx(%d) w(%d) h(%d) mem_types(%s)\n",
432 FOURCC_STR(format), bo_idx, width, height, _tbm_flag_to_str(flags));
433 _tbm_set_last_result(TBM_ERROR_OUT_OF_MEMORY);
437 _tbm_util_check_bo_cnt(bufmgr);
439 /* LCOV_EXCL_START */
440 if (!bufmgr->use_hal_tbm) {
441 if (!bufmgr->backend_module_data || !bufmgr->bufmgr_func->bufmgr_alloc_bo_with_format) {
443 TBM_ERR("error: not supported tbm_bo_alloc_with_format\n");
444 _tbm_set_last_result(TBM_ERROR_NOT_SUPPORTED);
450 if (bufmgr->use_hal_tbm) {
451 bo_data = (tbm_backend_bo_data *)hal_tbm_bufmgr_alloc_bo_with_format(bufmgr->hal_bufmgr,
452 format, bo_idx, width, height, (hal_tbm_bo_memory_type)flags, (hal_tbm_error *)error);
454 TBM_ERR("error: fail to tbm_bo_alloc_with_format\n");
455 _tbm_set_last_result(*error);
459 bo_data = bufmgr->bufmgr_func->bufmgr_alloc_bo_with_format(bufmgr->bufmgr_data, format, bo_idx,
460 width, height, flags, error);
462 TBM_ERR("error: fail to tbm_bo_alloc_with_format fmt(%s) idx(%d) w(%d) h(%d) mem_types(%s)\n",
463 FOURCC_STR(format), bo_idx, width, height, _tbm_flag_to_str(flags));
464 _tbm_set_last_result(*error);
469 bo->bo_data = bo_data;
470 _tbm_bo_init(bufmgr, bo, flags);
472 _tbm_bufmgr_mutex_unlock();
479 _tbm_bufmgr_mutex_unlock();
484 tbm_bo_alloc_with_tiled_format(tbm_bufmgr bufmgr, int width, int height, int bpp, int format,
485 tbm_bo_memory_type flags, int bo_idx, tbm_error_e *error)
488 tbm_backend_bo_data *bo_data;
490 _tbm_bufmgr_mutex_lock();
491 _tbm_set_last_result(TBM_ERROR_NONE);
493 TBM_BO_RETURN_VAL_IF_FAIL(TBM_BUFMGR_IS_VALID(bufmgr), NULL);
495 bo = calloc(1, sizeof(struct _tbm_bo));
497 TBM_ERR("error: fail to tbm_bo_alloc_with_tiled_format fmt(%s) idx(%d) w(%d) h(%d) flags(%s)\n",
498 FOURCC_STR(format), bo_idx, width, height, _tbm_flag_to_str(flags));
499 _tbm_set_last_result(TBM_ERROR_OUT_OF_MEMORY);
500 _tbm_bufmgr_mutex_unlock();
504 _tbm_util_check_bo_cnt(bufmgr);
506 if (!bufmgr->use_hal_tbm) {
507 if (!bufmgr->backend_module_data || !bufmgr->bufmgr_func->bufmgr_alloc_bo_with_tiled_format) {
508 TBM_ERR("error: not supported tbm_bo_alloc_with_tiled_format\n");
509 _tbm_set_last_result(TBM_ERROR_NOT_SUPPORTED);
511 _tbm_bufmgr_mutex_unlock();
516 if (bufmgr->use_hal_tbm)
517 bo_data = (tbm_backend_bo_data *)hal_tbm_bufmgr_alloc_bo_with_tiled_format(bufmgr->hal_bufmgr,
518 width, height, bpp, format, (hal_tbm_bo_memory_type)flags, bo_idx, (hal_tbm_error *)error);
520 bo_data = bufmgr->bufmgr_func->bufmgr_alloc_bo_with_tiled_format(bufmgr->bufmgr_data, width, height,
521 bpp, format, flags, bo_idx, error);
523 TBM_ERR("error: fail to tbm_bo_alloc_with_tiled_format fmt(%s) idx(%d) w(%d) h(%d) flags(%s)\n",
524 FOURCC_STR(format), bo_idx, width, height, _tbm_flag_to_str(flags));
525 _tbm_set_last_result(*error);
527 _tbm_bufmgr_mutex_unlock();
531 bo->bo_data = bo_data;
532 _tbm_bo_init(bufmgr, bo, flags);
534 _tbm_bufmgr_mutex_unlock();
540 tbm_bo_alloc_with_surface(tbm_bufmgr bufmgr, int width, int height, int format, int flags, int bo_idx)
545 _tbm_bufmgr_mutex_lock();
546 _tbm_set_last_result(TBM_ERROR_NONE);
548 TBM_BO_RETURN_VAL_IF_FAIL(TBM_BUFMGR_IS_VALID(bufmgr), NULL);
550 bo = calloc(1, sizeof(struct _tbm_bo));
552 TBM_ERR("error: fail to tbm_bo_alloc_with_surface fmt(%s) idx(%d) w(%d) h(%d) flags(%s)\n",
553 FOURCC_STR(format), bo_idx, width, height, _tbm_flag_to_str(flags));
554 _tbm_set_last_result(TBM_ERROR_OUT_OF_MEMORY);
555 _tbm_bufmgr_mutex_unlock();
559 _tbm_util_check_bo_cnt(bufmgr);
561 if (!bufmgr->backend->surface_bo_alloc) {
562 TBM_ERR("error: not supported tbm_bo_alloc_with_surface\n");
563 _tbm_set_last_result(TBM_ERROR_NOT_SUPPORTED);
565 _tbm_bufmgr_mutex_unlock();
569 bo_priv = bufmgr->backend->surface_bo_alloc(bo, width, height, format, flags, bo_idx);
571 TBM_ERR("error: fail to tbm_bo_alloc_with_surface fmt(%s) idx(%d) w(%d) h(%d) flags(%s)\n",
572 FOURCC_STR(format), bo_idx, width, height, _tbm_flag_to_str(flags));
573 _tbm_set_last_result(TBM_ERROR_INVALID_OPERATION);
575 _tbm_bufmgr_mutex_unlock();
580 _tbm_bo_init(bufmgr, bo, flags);
582 _tbm_bufmgr_mutex_unlock();
589 tbm_bo_ref(tbm_bo bo)
591 _tbm_bufmgr_mutex_lock();
592 _tbm_set_last_result(TBM_ERROR_NONE);
594 TBM_BO_RETURN_VAL_IF_FAIL(_tbm_bo_is_valid(bo), NULL);
598 TBM_TRACE_BO("bo(%p) ref_cnt(%d)\n", bo, bo->ref_cnt);
600 _tbm_bufmgr_mutex_unlock();
606 tbm_bo_unref(tbm_bo bo)
608 _tbm_bufmgr_mutex_lock();
609 _tbm_set_last_result(TBM_ERROR_NONE);
611 TBM_BO_RETURN_IF_FAIL(_tbm_bo_is_valid(bo));
613 TBM_TRACE_BO("bo(%p) ref_cnt(%d)\n", bo, bo->ref_cnt - 1);
615 if (bo->ref_cnt <= 0) {
616 _tbm_bufmgr_mutex_unlock();
621 if (bo->ref_cnt == 0)
624 _tbm_bufmgr_mutex_unlock();
628 tbm_bo_map(tbm_bo bo, int device, int opt)
630 tbm_bo_handle bo_handle;
633 _tbm_bufmgr_mutex_lock();
634 _tbm_set_last_result(TBM_ERROR_NONE);
636 TBM_BO_RETURN_VAL_IF_FAIL(_tbm_bo_is_valid(bo), (tbm_bo_handle) NULL);
638 if (!_tbm_bo_lock(bo, device, opt)) {
639 TBM_ERR("error: fail to lock bo:%p)\n", bo);
640 _tbm_bufmgr_mutex_unlock();
641 return (tbm_bo_handle) NULL;
644 if (bo->bufmgr->use_hal_tbm) {
645 hal_tbm_bo_handle hbo_handle;
646 hbo_handle = hal_tbm_bo_map((hal_tbm_bo *)bo->bo_data, device, opt, (hal_tbm_error *)&error);
647 if (hbo_handle.ptr == NULL) {
648 /* LCOV_EXCL_START */
649 _tbm_set_last_result(error);
650 TBM_ERR("error: bo(%p) bo_handle(%p) error(%d)\n", bo, hbo_handle.ptr, error);
654 memcpy(&bo_handle.ptr, &hbo_handle.ptr, sizeof(tbm_bo_handle));
655 } else if (bo->bufmgr->backend_module_data) {
656 bo_handle = bo->bufmgr->bo_func->bo_map(bo->bo_data, device, opt, &error);
657 if (bo_handle.ptr == NULL) {
658 /* LCOV_EXCL_START */
659 _tbm_set_last_result(error);
660 TBM_ERR("error: fail to map bo:%p error:%d\n", bo, error);
665 bo_handle = bo->bufmgr->backend->bo_map(bo, device, opt);
666 if (bo_handle.ptr == NULL) {
667 /* LCOV_EXCL_START */
668 _tbm_set_last_result(TBM_ERROR_INVALID_OPERATION);
669 TBM_ERR("error: fail to map bo:%p\n", bo);
675 /* increase the map_count */
678 TBM_TRACE_BO("bo(%p) map_cnt(%d)\n", bo, bo->map_cnt);
680 _tbm_bufmgr_mutex_unlock();
686 _tbm_bufmgr_mutex_unlock();
687 return (tbm_bo_handle) NULL;
691 tbm_bo_unmap(tbm_bo bo)
696 _tbm_bufmgr_mutex_lock();
697 _tbm_set_last_result(TBM_ERROR_NONE);
699 TBM_BO_RETURN_VAL_IF_FAIL(_tbm_bo_is_valid(bo), 0);
700 TBM_BO_RETURN_VAL_IF_FAIL(bo->map_cnt > 0, 0);
702 if (bo->bufmgr->use_hal_tbm) {
703 error = (hal_tbm_error)hal_tbm_bo_unmap((hal_tbm_bo *)bo->bo_data);
704 if (error != TBM_ERROR_NONE) {
705 /* LCOV_EXCL_START */
706 TBM_ERR("error: bo(%p) map_cnt(%d) error(%d)\n", bo, bo->map_cnt, error);
707 _tbm_set_last_result(error);
712 } else if (bo->bufmgr->backend_module_data) {
713 error = bo->bufmgr->bo_func->bo_unmap(bo->bo_data);
714 if (error != TBM_ERROR_NONE) {
715 /* LCOV_EXCL_START */
716 TBM_ERR("error: bo(%p) map_cnt(%d) error(%d)\n", bo, bo->map_cnt, error);
717 _tbm_set_last_result(error);
723 ret = bo->bufmgr->backend->bo_unmap(bo);
725 /* LCOV_EXCL_START */
726 TBM_ERR("error: bo(%p) map_cnt(%d)\n", bo, bo->map_cnt);
727 _tbm_set_last_result(TBM_ERROR_INVALID_OPERATION);
733 /* decrease the map_count */
736 TBM_TRACE_BO("bo(%p) map_cnt(%d)\n", bo, bo->map_cnt);
741 _tbm_bufmgr_mutex_unlock();
747 tbm_bo_get_handle(tbm_bo bo, int device)
749 tbm_bo_handle bo_handle;
752 _tbm_bufmgr_mutex_lock();
753 _tbm_set_last_result(TBM_ERROR_NONE);
755 TBM_BO_RETURN_VAL_IF_FAIL(_tbm_bo_is_valid(bo), (tbm_bo_handle) NULL);
757 if (bo->bufmgr->use_hal_tbm) {
758 hal_tbm_bo_handle hbo_handle;
759 hbo_handle = hal_tbm_bo_get_handle((hal_tbm_bo *)bo->bo_data, device, (hal_tbm_error *)&error);
760 if (hbo_handle.ptr == NULL) {
761 /* LCOV_EXCL_START */
762 TBM_ERR("error: bo(%p) bo_handle(%p) error(%d)\n", bo, hbo_handle.ptr, error);
763 _tbm_set_last_result(error);
767 memcpy(&bo_handle.ptr, &hbo_handle.ptr, sizeof(tbm_bo_handle));
768 } else if (bo->bufmgr->backend_module_data) {
769 bo_handle = bo->bufmgr->bo_func->bo_get_handle(bo->bo_data, device, &error);
770 if (bo_handle.ptr == NULL) {
771 /* LCOV_EXCL_START */
772 TBM_ERR("error: bo(%p) bo_handle(%p) error(%d)\n", bo, bo_handle.ptr, error);
773 _tbm_set_last_result(error);
778 bo_handle = bo->bufmgr->backend->bo_get_handle(bo, device);
779 if (bo_handle.ptr == NULL) {
780 /* LCOV_EXCL_START */
781 TBM_ERR("error: bo(%p) bo_handle(%p)\n", bo, bo_handle.ptr);
782 _tbm_set_last_result(TBM_ERROR_INVALID_OPERATION);
788 TBM_TRACE_BO("bo(%p) bo_handle(%p)\n", bo, bo_handle.ptr);
790 _tbm_bufmgr_mutex_unlock();
795 _tbm_bufmgr_mutex_unlock();
796 return (tbm_bo_handle) NULL;
800 tbm_bo_export(tbm_bo bo)
805 _tbm_bufmgr_mutex_lock();
806 _tbm_set_last_result(TBM_ERROR_NONE);
808 TBM_BO_RETURN_VAL_IF_FAIL(_tbm_bo_is_valid(bo), 0);
810 if (bo->bufmgr->use_hal_tbm) {
811 ret = (hal_tbm_key)hal_tbm_bo_export_key((hal_tbm_bo *)bo->bo_data, (hal_tbm_error *)&error);
813 /* LCOV_EXCL_START */
814 TBM_ERR("error: bo(%p) tbm_key(%d) error(%d)\n", bo, ret, error);
815 _tbm_set_last_result(error);
819 } else if (bo->bufmgr->backend_module_data) {
820 if (!bo->bufmgr->bo_func->bo_export_key) {
821 /* LCOV_EXCL_START */
822 _tbm_bufmgr_mutex_unlock();
823 _tbm_set_last_result(TBM_ERROR_NOT_SUPPORTED);
828 ret = bo->bufmgr->bo_func->bo_export_key(bo->bo_data, &error);
830 /* LCOV_EXCL_START */
831 TBM_ERR("error: bo(%p) tbm_key(%d) error(%d)\n", bo, ret, error);
832 _tbm_set_last_result(error);
837 if (!bo->bufmgr->backend->bo_export) {
838 /* LCOV_EXCL_START */
839 _tbm_bufmgr_mutex_unlock();
840 _tbm_set_last_result(TBM_ERROR_NOT_SUPPORTED);
845 ret = bo->bufmgr->backend->bo_export(bo);
847 /* LCOV_EXCL_START */
848 TBM_ERR("error: bo(%p) tbm_key(%d)\n", bo, ret);
849 _tbm_set_last_result(TBM_ERROR_INVALID_OPERATION);
855 TBM_TRACE_BO("bo(%p) tbm_key(%u)\n", bo, ret);
858 _tbm_bufmgr_mutex_unlock();
864 tbm_bo_export_fd(tbm_bo bo)
869 _tbm_bufmgr_mutex_lock();
870 _tbm_set_last_result(TBM_ERROR_NONE);
872 TBM_BO_RETURN_VAL_IF_FAIL(_tbm_bo_is_valid(bo), -1);
874 if (bo->bufmgr->use_hal_tbm) {
875 ret = (hal_tbm_fd)hal_tbm_bo_export_fd((hal_tbm_bo *)bo->bo_data, (hal_tbm_error *)&error);
877 /* LCOV_EXCL_START */
878 TBM_ERR("error: bo(%p) tbm_fd(%d) error(%d)\n", bo, ret, error);
879 _tbm_set_last_result(error);
883 } else if (bo->bufmgr->backend_module_data) {
884 if (!bo->bufmgr->bo_func->bo_export_fd) {
885 /* LCOV_EXCL_START */
886 _tbm_bufmgr_mutex_unlock();
887 _tbm_set_last_result(TBM_ERROR_NOT_SUPPORTED);
892 ret = bo->bufmgr->bo_func->bo_export_fd(bo->bo_data, &error);
894 /* LCOV_EXCL_START */
895 TBM_ERR("error: bo(%p) tbm_fd(%d) error(%d)\n", bo, ret, error);
896 _tbm_set_last_result(error);
901 if (!bo->bufmgr->backend->bo_export_fd) {
902 /* LCOV_EXCL_START */
903 _tbm_bufmgr_mutex_unlock();
904 _tbm_set_last_result(TBM_ERROR_NOT_SUPPORTED);
909 ret = bo->bufmgr->backend->bo_export_fd(bo);
911 /* LCOV_EXCL_START */
912 TBM_ERR("error: bo(%p) tbm_fd(%d)\n", bo, ret);
913 _tbm_set_last_result(TBM_ERROR_INVALID_OPERATION);
919 TBM_TRACE_BO("bo(%p) tbm_fd(%d)\n", bo, ret);
922 _tbm_bufmgr_mutex_unlock();
928 tbm_bo_import(tbm_bufmgr bufmgr, unsigned int key)
934 tbm_backend_bo_data *bo_data;
937 _tbm_bufmgr_mutex_lock();
938 _tbm_set_last_result(TBM_ERROR_NONE);
940 TBM_BO_RETURN_VAL_IF_FAIL(TBM_BUFMGR_IS_VALID(bufmgr), NULL);
942 if (!bufmgr->use_hal_tbm) {
943 if (bufmgr->backend_module_data) {
944 if (!bufmgr->bufmgr_func->bufmgr_import_key) {
945 /* LCOV_EXCL_START */
946 _tbm_bufmgr_mutex_unlock();
947 _tbm_set_last_result(TBM_ERROR_NOT_SUPPORTED);
952 if (!bufmgr->backend->bo_import) {
953 /* LCOV_EXCL_START */
954 _tbm_bufmgr_mutex_unlock();
955 _tbm_set_last_result(TBM_ERROR_NOT_SUPPORTED);
962 _tbm_util_check_bo_cnt(bufmgr);
964 bo = calloc(1, sizeof(struct _tbm_bo));
966 /* LCOV_EXCL_START */
967 TBM_ERR("error: fail to import of tbm_bo by key(%d)\n", key);
968 _tbm_set_last_result(TBM_ERROR_OUT_OF_MEMORY);
969 _tbm_bufmgr_mutex_unlock();
974 if (bufmgr->use_hal_tbm) {
975 bo_data = (tbm_backend_bo_data *)hal_tbm_bufmgr_import_key(bufmgr->hal_bufmgr, key, (hal_tbm_error *)&error);
976 /* LCOV_EXCL_START */
978 TBM_ERR("error: fail to import of tbm_bo by key(%d). error(%d)\n", key, error);
979 _tbm_set_last_result(error);
983 if (!LIST_IS_EMPTY(&bufmgr->bo_list)) {
984 LIST_FOR_EACH_ENTRY(bo2, &bufmgr->bo_list, item_link) {
985 if (bo2->bo_data == bo_data) {
986 TBM_TRACE_BO("find bo(%p) ref(%d) key(%d) flag(%s) in list\n",
987 bo2, bo2->ref_cnt, key,
988 _tbm_flag_to_str(bo2->flags));
991 _tbm_bufmgr_mutex_unlock();
996 bo->bo_data = bo_data;
997 } else if (bufmgr->backend_module_data) {
998 bo_data = bufmgr->bufmgr_func->bufmgr_import_key(bufmgr->bufmgr_data, key, &error);
1000 /* LCOV_EXCL_START */
1001 TBM_ERR("error: fail to import of tbm_bo by key(%d). error(%d)\n", key, error);
1002 _tbm_set_last_result(error);
1004 /* LCOV_EXCL_STOP */
1007 if (!LIST_IS_EMPTY(&bufmgr->bo_list)) {
1008 LIST_FOR_EACH_ENTRY(bo2, &bufmgr->bo_list, item_link) {
1009 if (bo2->bo_data == bo_data) {
1010 TBM_TRACE_BO("find bo(%p) ref(%d) key(%d) flag(%s) in list\n",
1011 bo2, bo2->ref_cnt, key,
1012 _tbm_flag_to_str(bo2->flags));
1015 _tbm_bufmgr_mutex_unlock();
1020 bo->bo_data = bo_data;
1022 bo_priv = bufmgr->backend->bo_import(bo, key);
1024 /* LCOV_EXCL_START */
1025 TBM_ERR("error: fail to import of tbm_bo by key(%d)\n", key);
1026 _tbm_set_last_result(TBM_ERROR_INVALID_OPERATION);
1028 /* LCOV_EXCL_STOP */
1031 if (!LIST_IS_EMPTY(&bufmgr->bo_list)) {
1032 LIST_FOR_EACH_ENTRY(bo2, &bufmgr->bo_list, item_link) {
1033 if (bo2->priv == bo_priv) {
1034 TBM_TRACE_BO("find bo(%p) ref(%d) key(%d) flag(%s) in list\n",
1035 bo2, bo2->ref_cnt, key,
1036 _tbm_flag_to_str(bo2->flags));
1039 _tbm_bufmgr_mutex_unlock();
1047 if (bufmgr->use_hal_tbm) {
1048 flags = (tbm_bo_memory_type)hal_tbm_bo_get_memory_types((hal_tbm_bo *)bo->bo_data, (hal_tbm_error *)&error);
1049 if (error != TBM_ERROR_NONE) {
1050 TBM_ERR("fail to get the bo flags(memory_types)");
1051 _tbm_set_last_result(error);
1052 flags = TBM_BO_DEFAULT;
1054 } else if (bufmgr->backend_module_data) {
1055 flags = bufmgr->bo_func->bo_get_memory_types(bo->bo_data, &error);
1056 if (error != TBM_ERROR_NONE) {
1057 TBM_ERR("fail to get the bo flags(memory_types)");
1058 _tbm_set_last_result(error);
1059 flags = TBM_BO_DEFAULT;
1062 if (bufmgr->backend->bo_get_flags)
1063 flags = bufmgr->backend->bo_get_flags(bo);
1065 flags = TBM_BO_DEFAULT;
1068 _tbm_bo_init(bufmgr, bo, flags);
1070 TBM_TRACE_BO("import new bo(%p) ref(%d) key(%d) flag(%s) in list\n",
1071 bo, bo->ref_cnt, key, _tbm_flag_to_str(bo->flags));
1073 _tbm_bufmgr_mutex_unlock();
1079 _tbm_bufmgr_mutex_unlock();
1084 tbm_bo_import_fd(tbm_bufmgr bufmgr, tbm_fd fd)
1089 tbm_backend_bo_data *bo_data;
1093 _tbm_bufmgr_mutex_lock();
1094 _tbm_set_last_result(TBM_ERROR_NONE);
1096 TBM_BO_RETURN_VAL_IF_FAIL(TBM_BUFMGR_IS_VALID(bufmgr), NULL);
1098 if (!bufmgr->use_hal_tbm) {
1099 if (bufmgr->backend_module_data) {
1100 if (!bufmgr->bufmgr_func->bufmgr_import_fd) {
1101 /* LCOV_EXCL_START */
1102 _tbm_bufmgr_mutex_unlock();
1103 _tbm_set_last_result(TBM_ERROR_NOT_SUPPORTED);
1105 /* LCOV_EXCL_STOP */
1108 if (!bufmgr->backend->bo_import_fd) {
1109 /* LCOV_EXCL_START */
1110 _tbm_bufmgr_mutex_unlock();
1111 _tbm_set_last_result(TBM_ERROR_NOT_SUPPORTED);
1113 /* LCOV_EXCL_STOP */
1118 _tbm_util_check_bo_cnt(bufmgr);
1120 bo = calloc(1, sizeof(struct _tbm_bo));
1122 /* LCOV_EXCL_START */
1123 TBM_ERR("error: fail to import tbm_bo by tbm_fd(%d)\n", fd);
1124 _tbm_set_last_result(TBM_ERROR_OUT_OF_MEMORY);
1125 _tbm_bufmgr_mutex_unlock();
1127 /* LCOV_EXCL_STOP */
1130 if (bufmgr->use_hal_tbm) {
1131 bo_data = (tbm_backend_bo_data *)hal_tbm_bufmgr_import_fd(bufmgr->hal_bufmgr, (hal_tbm_fd)fd, (hal_tbm_error *)&error);
1132 /* LCOV_EXCL_START */
1134 TBM_ERR("error: fail to import tbm_bo by tbm_fd(%d). error(%d)\n", fd, error);
1135 _tbm_set_last_result(error);
1138 /* LCOV_EXCL_STOP */
1140 if (!LIST_IS_EMPTY(&bufmgr->bo_list)) {
1141 LIST_FOR_EACH_ENTRY(bo2, &bufmgr->bo_list, item_link) {
1142 if (bo2->bo_data == bo_data) {
1143 TBM_TRACE_BO("find bo(%p) ref(%d) fd(%d) flag(%s) in list\n",
1144 bo2, bo2->ref_cnt, fd, _tbm_flag_to_str(bo2->flags));
1147 _tbm_bufmgr_mutex_unlock();
1152 bo->bo_data = bo_data;
1153 } else if (bufmgr->backend_module_data) {
1154 bo_data = bufmgr->bufmgr_func->bufmgr_import_fd(bufmgr->bufmgr_data, fd, &error);
1156 /* LCOV_EXCL_START */
1157 TBM_ERR("error: fail to import tbm_bo by tbm_fd(%d). error(%d)\n", fd, error);
1158 _tbm_set_last_result(error);
1160 /* LCOV_EXCL_STOP */
1163 if (!LIST_IS_EMPTY(&bufmgr->bo_list)) {
1164 LIST_FOR_EACH_ENTRY(bo2, &bufmgr->bo_list, item_link) {
1165 if (bo2->bo_data == bo_data) {
1166 TBM_TRACE_BO("find bo(%p) ref(%d) fd(%d) flag(%s) in list\n",
1167 bo2, bo2->ref_cnt, fd, _tbm_flag_to_str(bo2->flags));
1170 _tbm_bufmgr_mutex_unlock();
1175 bo->bo_data = bo_data;
1177 bo_priv = bufmgr->backend->bo_import_fd(bo, fd);
1179 /* LCOV_EXCL_START */
1180 TBM_ERR("error: fail to import tbm_bo by tbm_fd(%d)\n", fd);
1181 _tbm_set_last_result(TBM_ERROR_INVALID_OPERATION);
1183 /* LCOV_EXCL_STOP */
1186 if (!LIST_IS_EMPTY(&bufmgr->bo_list)) {
1187 LIST_FOR_EACH_ENTRY(bo2, &bufmgr->bo_list, item_link) {
1188 if (bo2->priv == bo_priv) {
1189 TBM_TRACE_BO("find bo(%p) ref(%d) fd(%d) flag(%s) in list\n",
1190 bo2, bo2->ref_cnt, fd, _tbm_flag_to_str(bo2->flags));
1193 _tbm_bufmgr_mutex_unlock();
1201 if (bufmgr->use_hal_tbm) {
1202 flags = (tbm_bo_memory_type)hal_tbm_bo_get_memory_types((hal_tbm_bo *)bo->bo_data, (hal_tbm_error *)&error);
1203 if (error != TBM_ERROR_NONE) {
1204 TBM_ERR("fail to get the bo flags(memory_types)");
1205 _tbm_set_last_result(error);
1206 flags = TBM_BO_DEFAULT;
1208 } else if (bufmgr->backend_module_data) {
1209 flags = bufmgr->bo_func->bo_get_memory_types(bo->bo_data, &error);
1210 if (error != TBM_ERROR_NONE) {
1211 TBM_ERR("fail to get the bo flags(memory_types)");
1212 _tbm_set_last_result(error);
1213 flags = TBM_BO_DEFAULT;
1216 if (bufmgr->backend->bo_get_flags)
1217 flags = bufmgr->backend->bo_get_flags(bo);
1219 flags = TBM_BO_DEFAULT;
1222 _tbm_bo_init(bufmgr, bo, flags);
1224 TBM_TRACE_BO("import bo(%p) ref(%d) fd(%d) flag(%s)\n",
1225 bo, bo->ref_cnt, fd, _tbm_flag_to_str(bo->flags));
1227 _tbm_bufmgr_mutex_unlock();
1233 _tbm_bufmgr_mutex_unlock();
1238 tbm_bo_size(tbm_bo bo)
1243 _tbm_bufmgr_mutex_lock();
1244 _tbm_set_last_result(TBM_ERROR_NONE);
1246 TBM_BO_RETURN_VAL_IF_FAIL(_tbm_bo_is_valid(bo), 0);
1248 if (bo->bufmgr->use_hal_tbm) {
1249 size = hal_tbm_bo_get_size((hal_tbm_bo *)bo->bo_data, (hal_tbm_error *)&error);
1250 if (error != TBM_ERROR_NONE) {
1251 TBM_ERR("fail to get the size of the bo_data(%d).", error);
1252 _tbm_set_last_result(TBM_ERROR_NONE);
1254 } else if (bo->bufmgr->backend_module_data) {
1255 size = bo->bufmgr->bo_func->bo_get_size(bo->bo_data, &error);
1256 if (error != TBM_ERROR_NONE) {
1257 TBM_ERR("fail to get the size of the bo_data(%d).", error);
1258 _tbm_set_last_result(TBM_ERROR_NONE);
1261 size = bo->bufmgr->backend->bo_size(bo);
1263 TBM_TRACE_BO("bo(%p) size(%d)\n", bo, size);
1265 _tbm_bufmgr_mutex_unlock();
1271 tbm_bo_locked(tbm_bo bo)
1273 _tbm_bufmgr_mutex_lock();
1274 _tbm_set_last_result(TBM_ERROR_NONE);
1276 TBM_BO_RETURN_VAL_IF_FAIL(_tbm_bo_is_valid(bo), 0);
1278 if (bo->bufmgr->bo_lock_type == TBM_BUFMGR_BO_LOCK_TYPE_NEVER) {
1279 TBM_ERR("bo(%p) lock_cnt(%d)\n", bo, bo->lock_cnt);
1280 _tbm_set_last_result(TBM_ERROR_INVALID_OPERATION);
1281 _tbm_bufmgr_mutex_unlock();
1285 if (bo->lock_cnt > 0) {
1286 TBM_TRACE_BO("error: bo(%p) lock_cnt(%d)\n", bo, bo->lock_cnt);
1287 _tbm_bufmgr_mutex_unlock();
1291 TBM_TRACE_BO("bo(%p) lock_cnt(%d)\n", bo, bo->lock_cnt);
1292 _tbm_bufmgr_mutex_unlock();
1298 tbm_bo_swap(tbm_bo bo1, tbm_bo bo2)
1300 tbm_error_e error1, error2;
1301 int size1 = -1, size2 = -2;
1304 _tbm_bufmgr_mutex_lock();
1305 _tbm_set_last_result(TBM_ERROR_NONE);
1307 TBM_BO_RETURN_VAL_IF_FAIL(_tbm_bo_is_valid(bo1), 0);
1308 TBM_BO_RETURN_VAL_IF_FAIL(_tbm_bo_is_valid(bo2), 0);
1310 TBM_TRACE_BO("before: bo1(%p) bo2(%p)\n", bo1, bo2);
1312 if (bo1->bufmgr->use_hal_tbm) {
1313 size1 = hal_tbm_bo_get_size((hal_tbm_bo *)bo1->bo_data, (hal_tbm_error *)&error1);
1314 if (error1 != TBM_ERROR_NONE) {
1315 TBM_ERR("fail to get the size of bo1.(%d)", error1);
1316 _tbm_set_last_result(error1);
1319 size2 = hal_tbm_bo_get_size((hal_tbm_bo *)bo2->bo_data, (hal_tbm_error *)&error2);
1320 if (error2 != TBM_ERROR_NONE) {
1321 TBM_ERR("fail to get the size of bo1.(%d)", error2);
1322 _tbm_set_last_result(error2);
1325 } else if (bo1->bufmgr->backend_module_data) {
1326 size1 = bo1->bufmgr->bo_func->bo_get_size(bo1->bo_data, &error1);
1327 if (error1 != TBM_ERROR_NONE) {
1328 TBM_ERR("fail to get the size of bo1.(%d)", error1);
1329 _tbm_set_last_result(error1);
1332 size2 = bo2->bufmgr->bo_func->bo_get_size(bo2->bo_data, &error2);
1333 if (error2 != TBM_ERROR_NONE) {
1334 TBM_ERR("fail to get the size of bo2.(%d)", error2);
1335 _tbm_set_last_result(error2);
1339 size1 = bo1->bufmgr->backend->bo_size(bo1);
1340 size2 = bo2->bufmgr->backend->bo_size(bo2);
1343 if (size1 != size2) {
1344 TBM_ERR("error: bo1 size(%d) and bo2 size(%d) is different.", size1, size2);
1345 _tbm_set_last_result(TBM_ERROR_INVALID_OPERATION);
1349 TBM_TRACE_BO("after: bo1(%p) bo2(%p)\n", bo1, bo2);
1352 bo1->priv = bo2->priv;
1355 _tbm_bufmgr_mutex_unlock();
1360 TBM_ERR("error: bo1(%p) bo2(%p)\n", bo1, bo2);
1361 _tbm_bufmgr_mutex_unlock();
1367 tbm_bo_add_user_data(tbm_bo bo, unsigned long key,
1368 tbm_data_free data_free_func)
1370 tbm_user_data *data;
1372 _tbm_bufmgr_mutex_lock();
1373 _tbm_set_last_result(TBM_ERROR_NONE);
1375 TBM_BO_RETURN_VAL_IF_FAIL(_tbm_bo_is_valid(bo), 0);
1377 /* check if the data according to the key exist if so, return false. */
1378 data = user_data_lookup(&bo->user_data_list, key);
1380 TBM_TRACE_BO("warning: user data already exist key(%ld)\n", key);
1381 _tbm_set_last_result(TBM_ERROR_INVALID_PARAMETER);
1382 _tbm_bufmgr_mutex_unlock();
1386 data = user_data_create(key, data_free_func);
1388 TBM_ERR("error: bo(%p) key(%lu)\n", bo, key);
1389 _tbm_set_last_result(TBM_ERROR_INVALID_PARAMETER);
1390 _tbm_bufmgr_mutex_unlock();
1394 TBM_TRACE_BO("bo(%p) key(%lu) data(%p)\n", bo, key, data->data);
1396 LIST_ADD(&data->item_link, &bo->user_data_list);
1398 _tbm_bufmgr_mutex_unlock();
1404 tbm_bo_delete_user_data(tbm_bo bo, unsigned long key)
1406 tbm_user_data *old_data;
1408 _tbm_bufmgr_mutex_lock();
1409 _tbm_set_last_result(TBM_ERROR_NONE);
1411 TBM_BO_RETURN_VAL_IF_FAIL(_tbm_bo_is_valid(bo), 0);
1413 if (LIST_IS_EMPTY(&bo->user_data_list)) {
1414 TBM_TRACE_BO("bo(%p) key(%lu)\n", bo, key);
1415 _tbm_set_last_result(TBM_ERROR_INVALID_PARAMETER);
1416 _tbm_bufmgr_mutex_unlock();
1420 old_data = user_data_lookup(&bo->user_data_list, key);
1422 TBM_TRACE_BO("bo(%p) key(%lu)\n", bo, key);
1423 _tbm_set_last_result(TBM_ERROR_INVALID_PARAMETER);
1424 _tbm_bufmgr_mutex_unlock();
1428 TBM_TRACE_BO("bo(%p) key(%lu) data(%p)\n", bo, key, old_data->data);
1430 user_data_delete(old_data);
1432 _tbm_bufmgr_mutex_unlock();
1438 tbm_bo_set_user_data(tbm_bo bo, unsigned long key, void *data)
1440 tbm_user_data *old_data;
1442 _tbm_bufmgr_mutex_lock();
1443 _tbm_set_last_result(TBM_ERROR_NONE);
1445 TBM_BO_RETURN_VAL_IF_FAIL(_tbm_bo_is_valid(bo), 0);
1447 if (LIST_IS_EMPTY(&bo->user_data_list)) {
1448 TBM_TRACE_BO("error: bo(%p) key(%lu)\n", bo, key);
1449 _tbm_set_last_result(TBM_ERROR_INVALID_PARAMETER);
1450 _tbm_bufmgr_mutex_unlock();
1454 old_data = user_data_lookup(&bo->user_data_list, key);
1456 TBM_TRACE_BO("error: bo(%p) key(%lu)\n", bo, key);
1457 _tbm_set_last_result(TBM_ERROR_INVALID_PARAMETER);
1458 _tbm_bufmgr_mutex_unlock();
1462 if (old_data->data && old_data->free_func)
1463 old_data->free_func(old_data->data);
1464 old_data->data = data;
1466 TBM_TRACE_BO("bo(%p) key(%lu) data(%p)\n", bo, key, old_data->data);
1468 _tbm_bufmgr_mutex_unlock();
1474 tbm_bo_get_user_data(tbm_bo bo, unsigned long key, void **data)
1476 tbm_user_data *old_data;
1478 _tbm_bufmgr_mutex_lock();
1479 _tbm_set_last_result(TBM_ERROR_NONE);
1481 TBM_BO_RETURN_VAL_IF_FAIL(_tbm_bo_is_valid(bo), 0);
1483 if (!data || LIST_IS_EMPTY(&bo->user_data_list)) {
1484 TBM_TRACE_BO("error: bo(%p) key(%lu)\n", bo, key);
1485 _tbm_set_last_result(TBM_ERROR_INVALID_PARAMETER);
1486 _tbm_bufmgr_mutex_unlock();
1490 old_data = user_data_lookup(&bo->user_data_list, key);
1493 TBM_TRACE_BO("error: bo(%p) key(%lu)\n", bo, key);
1494 _tbm_set_last_result(TBM_ERROR_INVALID_PARAMETER);
1495 _tbm_bufmgr_mutex_unlock();
1499 *data = old_data->data;
1501 TBM_TRACE_BO("bo(%p) key(%lu) data(%p)\n", bo, key, old_data->data);
1503 _tbm_bufmgr_mutex_unlock();
1509 tbm_bo_get_flags(tbm_bo bo)
1513 _tbm_bufmgr_mutex_lock();
1515 TBM_BO_RETURN_VAL_IF_FAIL(_tbm_bo_is_valid(bo), 0);
1519 TBM_TRACE_BO("bo(%p)\n", bo);
1521 _tbm_bufmgr_mutex_unlock();
1526 /* LCOV_EXCL_START */
1527 /* internal function */
1529 _tbm_bo_set_surface(tbm_bo bo, tbm_surface_h surface)
1531 _tbm_bufmgr_mutex_lock();
1533 TBM_BO_RETURN_VAL_IF_FAIL(_tbm_bo_is_valid(bo), 0);
1535 bo->surface = surface;
1537 _tbm_bufmgr_mutex_unlock();
1543 _tbm_bo_free(tbm_bo bo)
1545 /* destory the user_data_list */
1546 if (!LIST_IS_EMPTY(&bo->user_data_list)) {
1547 tbm_user_data *old_data = NULL, *tmp;
1549 LIST_FOR_EACH_ENTRY_SAFE(old_data, tmp,
1550 &bo->user_data_list, item_link) {
1551 TBM_DBG("free user_data\n");
1552 user_data_delete(old_data);
1556 while (bo->lock_cnt > 0) {
1557 TBM_ERR("error lock_cnt:%d\n", bo->lock_cnt);
1562 /* call the bo_free */
1563 if (bo->bufmgr->use_hal_tbm) {
1564 hal_tbm_bo_free(bo->bo_data);
1566 } else if (bo->bufmgr->backend_module_data) {
1567 bo->bufmgr->bo_func->bo_free(bo->bo_data);
1570 bo->bufmgr->backend->bo_free(bo);
1578 /* LCOV_EXCL_STOP */