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);
434 _tbm_bufmgr_mutex_unlock();
438 _tbm_util_check_bo_cnt(bufmgr);
440 /* LCOV_EXCL_START */
441 if (!bufmgr->use_hal_tbm) {
442 if (!bufmgr->backend_module_data || !bufmgr->bufmgr_func->bufmgr_alloc_bo_with_format) {
444 TBM_ERR("error: not supported tbm_bo_alloc_with_format\n");
445 _tbm_set_last_result(TBM_ERROR_NOT_SUPPORTED);
447 _tbm_bufmgr_mutex_unlock();
453 if (bufmgr->use_hal_tbm)
454 bo_data = (tbm_backend_bo_data *)hal_tbm_bufmgr_alloc_bo_with_format(bufmgr->hal_bufmgr,
455 format, bo_idx, width, height, (hal_tbm_bo_memory_type)flags, (hal_tbm_error *)error);
457 bo_data = bufmgr->bufmgr_func->bufmgr_alloc_bo_with_format(bufmgr->bufmgr_data, format, bo_idx,
458 width, height, flags, error);
460 TBM_ERR("error: fail to tbm_bo_alloc_with_format fmt(%s) idx(%d) w(%d) h(%d) mem_types(%s)\n",
461 FOURCC_STR(format), bo_idx, width, height, _tbm_flag_to_str(flags));
462 _tbm_set_last_result(*error);
464 _tbm_bufmgr_mutex_unlock();
468 bo->bo_data = bo_data;
469 _tbm_bo_init(bufmgr, bo, flags);
471 _tbm_bufmgr_mutex_unlock();
477 tbm_bo_alloc_with_tiled_format(tbm_bufmgr bufmgr, int width, int height, int bpp, int format,
478 tbm_bo_memory_type flags, int bo_idx, tbm_error_e *error)
481 tbm_backend_bo_data *bo_data;
483 _tbm_bufmgr_mutex_lock();
484 _tbm_set_last_result(TBM_ERROR_NONE);
486 TBM_BO_RETURN_VAL_IF_FAIL(TBM_BUFMGR_IS_VALID(bufmgr), NULL);
488 bo = calloc(1, sizeof(struct _tbm_bo));
490 TBM_ERR("error: fail to tbm_bo_alloc_with_tiled_format fmt(%s) idx(%d) w(%d) h(%d) flags(%s)\n",
491 FOURCC_STR(format), bo_idx, width, height, _tbm_flag_to_str(flags));
492 _tbm_set_last_result(TBM_ERROR_OUT_OF_MEMORY);
493 _tbm_bufmgr_mutex_unlock();
497 _tbm_util_check_bo_cnt(bufmgr);
499 if (!bufmgr->use_hal_tbm) {
500 if (!bufmgr->backend_module_data || !bufmgr->bufmgr_func->bufmgr_alloc_bo_with_tiled_format) {
501 TBM_ERR("error: not supported tbm_bo_alloc_with_tiled_format\n");
502 _tbm_set_last_result(TBM_ERROR_NOT_SUPPORTED);
504 _tbm_bufmgr_mutex_unlock();
509 if (bufmgr->use_hal_tbm)
510 bo_data = (tbm_backend_bo_data *)hal_tbm_bufmgr_alloc_bo_with_tiled_format(bufmgr->hal_bufmgr,
511 width, height, bpp, format, (hal_tbm_bo_memory_type)flags, bo_idx, (hal_tbm_error *)error);
513 bo_data = bufmgr->bufmgr_func->bufmgr_alloc_bo_with_tiled_format(bufmgr->bufmgr_data, width, height,
514 bpp, format, flags, bo_idx, error);
516 TBM_ERR("error: fail to tbm_bo_alloc_with_tiled_format fmt(%s) idx(%d) w(%d) h(%d) flags(%s)\n",
517 FOURCC_STR(format), bo_idx, width, height, _tbm_flag_to_str(flags));
518 _tbm_set_last_result(*error);
520 _tbm_bufmgr_mutex_unlock();
524 bo->bo_data = bo_data;
525 _tbm_bo_init(bufmgr, bo, flags);
527 _tbm_bufmgr_mutex_unlock();
533 tbm_bo_alloc_with_surface(tbm_bufmgr bufmgr, int width, int height, int format, int flags, int bo_idx)
538 _tbm_bufmgr_mutex_lock();
539 _tbm_set_last_result(TBM_ERROR_NONE);
541 TBM_BO_RETURN_VAL_IF_FAIL(TBM_BUFMGR_IS_VALID(bufmgr), NULL);
543 bo = calloc(1, sizeof(struct _tbm_bo));
545 TBM_ERR("error: fail to tbm_bo_alloc_with_surface fmt(%s) idx(%d) w(%d) h(%d) flags(%s)\n",
546 FOURCC_STR(format), bo_idx, width, height, _tbm_flag_to_str(flags));
547 _tbm_set_last_result(TBM_ERROR_OUT_OF_MEMORY);
548 _tbm_bufmgr_mutex_unlock();
552 _tbm_util_check_bo_cnt(bufmgr);
554 if (!bufmgr->backend->surface_bo_alloc) {
555 TBM_ERR("error: not supported tbm_bo_alloc_with_surface\n");
556 _tbm_set_last_result(TBM_ERROR_NOT_SUPPORTED);
558 _tbm_bufmgr_mutex_unlock();
562 bo_priv = bufmgr->backend->surface_bo_alloc(bo, width, height, format, flags, bo_idx);
564 TBM_ERR("error: fail to tbm_bo_alloc_with_surface fmt(%s) idx(%d) w(%d) h(%d) flags(%s)\n",
565 FOURCC_STR(format), bo_idx, width, height, _tbm_flag_to_str(flags));
566 _tbm_set_last_result(TBM_ERROR_INVALID_OPERATION);
568 _tbm_bufmgr_mutex_unlock();
573 _tbm_bo_init(bufmgr, bo, flags);
575 _tbm_bufmgr_mutex_unlock();
582 tbm_bo_ref(tbm_bo bo)
584 _tbm_bufmgr_mutex_lock();
585 _tbm_set_last_result(TBM_ERROR_NONE);
587 TBM_BO_RETURN_VAL_IF_FAIL(_tbm_bo_is_valid(bo), NULL);
591 TBM_TRACE_BO("bo(%p) ref_cnt(%d)\n", bo, bo->ref_cnt);
593 _tbm_bufmgr_mutex_unlock();
599 tbm_bo_unref(tbm_bo bo)
601 _tbm_bufmgr_mutex_lock();
602 _tbm_set_last_result(TBM_ERROR_NONE);
604 TBM_BO_RETURN_IF_FAIL(_tbm_bo_is_valid(bo));
606 TBM_TRACE_BO("bo(%p) ref_cnt(%d)\n", bo, bo->ref_cnt - 1);
608 if (bo->ref_cnt <= 0) {
609 _tbm_bufmgr_mutex_unlock();
614 if (bo->ref_cnt == 0)
617 _tbm_bufmgr_mutex_unlock();
621 tbm_bo_map(tbm_bo bo, int device, int opt)
623 tbm_bo_handle bo_handle;
626 _tbm_bufmgr_mutex_lock();
627 _tbm_set_last_result(TBM_ERROR_NONE);
629 TBM_BO_RETURN_VAL_IF_FAIL(_tbm_bo_is_valid(bo), (tbm_bo_handle) NULL);
631 if (!_tbm_bo_lock(bo, device, opt)) {
632 TBM_ERR("error: fail to lock bo:%p)\n", bo);
633 _tbm_bufmgr_mutex_unlock();
634 return (tbm_bo_handle) NULL;
637 if (bo->bufmgr->use_hal_tbm) {
638 hal_tbm_bo_handle hbo_handle;
639 hbo_handle = hal_tbm_bo_map((hal_tbm_bo *)bo->bo_data, device, opt, (hal_tbm_error *)&error);
640 if (hbo_handle.ptr == NULL) {
641 /* LCOV_EXCL_START */
642 _tbm_set_last_result(error);
643 TBM_ERR("error: bo(%p) bo_handle(%p) error(%d)\n", bo, hbo_handle.ptr, error);
647 memcpy(&bo_handle.ptr, &hbo_handle.ptr, sizeof(tbm_bo_handle));
648 } else if (bo->bufmgr->backend_module_data) {
649 bo_handle = bo->bufmgr->bo_func->bo_map(bo->bo_data, device, opt, &error);
650 if (bo_handle.ptr == NULL) {
651 /* LCOV_EXCL_START */
652 _tbm_set_last_result(error);
653 TBM_ERR("error: fail to map bo:%p error:%d\n", bo, error);
658 bo_handle = bo->bufmgr->backend->bo_map(bo, device, opt);
659 if (bo_handle.ptr == NULL) {
660 /* LCOV_EXCL_START */
661 _tbm_set_last_result(TBM_ERROR_INVALID_OPERATION);
662 TBM_ERR("error: fail to map bo:%p\n", bo);
668 /* increase the map_count */
671 TBM_TRACE_BO("bo(%p) map_cnt(%d)\n", bo, bo->map_cnt);
673 _tbm_bufmgr_mutex_unlock();
679 _tbm_bufmgr_mutex_unlock();
680 return (tbm_bo_handle) NULL;
684 tbm_bo_unmap(tbm_bo bo)
689 _tbm_bufmgr_mutex_lock();
690 _tbm_set_last_result(TBM_ERROR_NONE);
692 TBM_BO_RETURN_VAL_IF_FAIL(_tbm_bo_is_valid(bo), 0);
693 TBM_BO_RETURN_VAL_IF_FAIL(bo->map_cnt > 0, 0);
695 if (bo->bufmgr->use_hal_tbm) {
696 error = (hal_tbm_error)hal_tbm_bo_unmap((hal_tbm_bo *)bo->bo_data);
697 if (error != TBM_ERROR_NONE) {
698 /* LCOV_EXCL_START */
699 TBM_ERR("error: bo(%p) map_cnt(%d) error(%d)\n", bo, bo->map_cnt, error);
700 _tbm_set_last_result(error);
705 } else if (bo->bufmgr->backend_module_data) {
706 error = bo->bufmgr->bo_func->bo_unmap(bo->bo_data);
707 if (error != TBM_ERROR_NONE) {
708 /* LCOV_EXCL_START */
709 TBM_ERR("error: bo(%p) map_cnt(%d) error(%d)\n", bo, bo->map_cnt, error);
710 _tbm_set_last_result(error);
716 ret = bo->bufmgr->backend->bo_unmap(bo);
718 /* LCOV_EXCL_START */
719 TBM_ERR("error: bo(%p) map_cnt(%d)\n", bo, bo->map_cnt);
720 _tbm_set_last_result(TBM_ERROR_INVALID_OPERATION);
726 /* decrease the map_count */
729 TBM_TRACE_BO("bo(%p) map_cnt(%d)\n", bo, bo->map_cnt);
734 _tbm_bufmgr_mutex_unlock();
740 tbm_bo_get_handle(tbm_bo bo, int device)
742 tbm_bo_handle bo_handle;
745 _tbm_bufmgr_mutex_lock();
746 _tbm_set_last_result(TBM_ERROR_NONE);
748 TBM_BO_RETURN_VAL_IF_FAIL(_tbm_bo_is_valid(bo), (tbm_bo_handle) NULL);
750 if (bo->bufmgr->use_hal_tbm) {
751 hal_tbm_bo_handle hbo_handle;
752 hbo_handle = hal_tbm_bo_get_handle((hal_tbm_bo *)bo->bo_data, device, (hal_tbm_error *)&error);
753 if (hbo_handle.ptr == NULL) {
754 /* LCOV_EXCL_START */
755 TBM_ERR("error: bo(%p) bo_handle(%p) error(%d)\n", bo, hbo_handle.ptr, error);
756 _tbm_set_last_result(error);
760 memcpy(&bo_handle.ptr, &hbo_handle.ptr, sizeof(tbm_bo_handle));
761 } else if (bo->bufmgr->backend_module_data) {
762 bo_handle = bo->bufmgr->bo_func->bo_get_handle(bo->bo_data, device, &error);
763 if (bo_handle.ptr == NULL) {
764 /* LCOV_EXCL_START */
765 TBM_ERR("error: bo(%p) bo_handle(%p) error(%d)\n", bo, bo_handle.ptr, error);
766 _tbm_set_last_result(error);
771 bo_handle = bo->bufmgr->backend->bo_get_handle(bo, device);
772 if (bo_handle.ptr == NULL) {
773 /* LCOV_EXCL_START */
774 TBM_ERR("error: bo(%p) bo_handle(%p)\n", bo, bo_handle.ptr);
775 _tbm_set_last_result(TBM_ERROR_INVALID_OPERATION);
781 TBM_TRACE_BO("bo(%p) bo_handle(%p)\n", bo, bo_handle.ptr);
783 _tbm_bufmgr_mutex_unlock();
788 _tbm_bufmgr_mutex_unlock();
789 return (tbm_bo_handle) NULL;
793 tbm_bo_export(tbm_bo bo)
798 _tbm_bufmgr_mutex_lock();
799 _tbm_set_last_result(TBM_ERROR_NONE);
801 TBM_BO_RETURN_VAL_IF_FAIL(_tbm_bo_is_valid(bo), 0);
803 if (bo->bufmgr->use_hal_tbm) {
804 ret = (hal_tbm_key)hal_tbm_bo_export_key((hal_tbm_bo *)bo->bo_data, (hal_tbm_error *)&error);
806 /* LCOV_EXCL_START */
807 TBM_ERR("error: bo(%p) tbm_key(%d) error(%d)\n", bo, ret, error);
808 _tbm_set_last_result(error);
812 } else if (bo->bufmgr->backend_module_data) {
813 if (!bo->bufmgr->bo_func->bo_export_key) {
814 /* LCOV_EXCL_START */
815 _tbm_bufmgr_mutex_unlock();
816 _tbm_set_last_result(TBM_ERROR_NOT_SUPPORTED);
821 ret = bo->bufmgr->bo_func->bo_export_key(bo->bo_data, &error);
823 /* LCOV_EXCL_START */
824 TBM_ERR("error: bo(%p) tbm_key(%d) error(%d)\n", bo, ret, error);
825 _tbm_set_last_result(error);
830 if (!bo->bufmgr->backend->bo_export) {
831 /* LCOV_EXCL_START */
832 _tbm_bufmgr_mutex_unlock();
833 _tbm_set_last_result(TBM_ERROR_NOT_SUPPORTED);
838 ret = bo->bufmgr->backend->bo_export(bo);
840 /* LCOV_EXCL_START */
841 TBM_ERR("error: bo(%p) tbm_key(%d)\n", bo, ret);
842 _tbm_set_last_result(TBM_ERROR_INVALID_OPERATION);
848 TBM_TRACE_BO("bo(%p) tbm_key(%u)\n", bo, ret);
851 _tbm_bufmgr_mutex_unlock();
857 tbm_bo_export_fd(tbm_bo bo)
862 _tbm_bufmgr_mutex_lock();
863 _tbm_set_last_result(TBM_ERROR_NONE);
865 TBM_BO_RETURN_VAL_IF_FAIL(_tbm_bo_is_valid(bo), -1);
867 if (bo->bufmgr->use_hal_tbm) {
868 ret = (hal_tbm_fd)hal_tbm_bo_export_fd((hal_tbm_bo *)bo->bo_data, (hal_tbm_error *)&error);
870 /* LCOV_EXCL_START */
871 TBM_ERR("error: bo(%p) tbm_fd(%d) error(%d)\n", bo, ret, error);
872 _tbm_set_last_result(error);
876 } else if (bo->bufmgr->backend_module_data) {
877 if (!bo->bufmgr->bo_func->bo_export_fd) {
878 /* LCOV_EXCL_START */
879 _tbm_bufmgr_mutex_unlock();
880 _tbm_set_last_result(TBM_ERROR_NOT_SUPPORTED);
885 ret = bo->bufmgr->bo_func->bo_export_fd(bo->bo_data, &error);
887 /* LCOV_EXCL_START */
888 TBM_ERR("error: bo(%p) tbm_fd(%d) error(%d)\n", bo, ret, error);
889 _tbm_set_last_result(error);
894 if (!bo->bufmgr->backend->bo_export_fd) {
895 /* LCOV_EXCL_START */
896 _tbm_bufmgr_mutex_unlock();
897 _tbm_set_last_result(TBM_ERROR_NOT_SUPPORTED);
902 ret = bo->bufmgr->backend->bo_export_fd(bo);
904 /* LCOV_EXCL_START */
905 TBM_ERR("error: bo(%p) tbm_fd(%d)\n", bo, ret);
906 _tbm_set_last_result(TBM_ERROR_INVALID_OPERATION);
912 TBM_TRACE_BO("bo(%p) tbm_fd(%d)\n", bo, ret);
915 _tbm_bufmgr_mutex_unlock();
921 tbm_bo_import(tbm_bufmgr bufmgr, unsigned int key)
927 tbm_backend_bo_data *bo_data;
930 _tbm_bufmgr_mutex_lock();
931 _tbm_set_last_result(TBM_ERROR_NONE);
933 TBM_BO_RETURN_VAL_IF_FAIL(TBM_BUFMGR_IS_VALID(bufmgr), NULL);
935 if (!bufmgr->use_hal_tbm) {
936 if (bufmgr->backend_module_data) {
937 if (!bufmgr->bufmgr_func->bufmgr_import_key) {
938 /* LCOV_EXCL_START */
939 _tbm_bufmgr_mutex_unlock();
940 _tbm_set_last_result(TBM_ERROR_NOT_SUPPORTED);
945 if (!bufmgr->backend->bo_import) {
946 /* LCOV_EXCL_START */
947 _tbm_bufmgr_mutex_unlock();
948 _tbm_set_last_result(TBM_ERROR_NOT_SUPPORTED);
955 _tbm_util_check_bo_cnt(bufmgr);
957 bo = calloc(1, sizeof(struct _tbm_bo));
959 /* LCOV_EXCL_START */
960 TBM_ERR("error: fail to import of tbm_bo by key(%d)\n", key);
961 _tbm_set_last_result(TBM_ERROR_OUT_OF_MEMORY);
962 _tbm_bufmgr_mutex_unlock();
967 if (bufmgr->use_hal_tbm) {
968 bo_data = (tbm_backend_bo_data *)hal_tbm_bufmgr_import_key(bufmgr->hal_bufmgr, key, (hal_tbm_error *)&error);
969 /* LCOV_EXCL_START */
971 TBM_ERR("error: fail to import of tbm_bo by key(%d). error(%d)\n", key, error);
972 _tbm_set_last_result(error);
976 if (!LIST_IS_EMPTY(&bufmgr->bo_list)) {
977 LIST_FOR_EACH_ENTRY(bo2, &bufmgr->bo_list, item_link) {
978 if (bo2->bo_data == bo_data) {
979 TBM_TRACE_BO("find bo(%p) ref(%d) key(%d) flag(%s) in list\n",
980 bo2, bo2->ref_cnt, key,
981 _tbm_flag_to_str(bo2->flags));
984 _tbm_bufmgr_mutex_unlock();
989 bo->bo_data = bo_data;
990 } else if (bufmgr->backend_module_data) {
991 bo_data = bufmgr->bufmgr_func->bufmgr_import_key(bufmgr->bufmgr_data, key, &error);
993 /* LCOV_EXCL_START */
994 TBM_ERR("error: fail to import of tbm_bo by key(%d). error(%d)\n", key, error);
995 _tbm_set_last_result(error);
1000 if (!LIST_IS_EMPTY(&bufmgr->bo_list)) {
1001 LIST_FOR_EACH_ENTRY(bo2, &bufmgr->bo_list, item_link) {
1002 if (bo2->bo_data == bo_data) {
1003 TBM_TRACE_BO("find bo(%p) ref(%d) key(%d) flag(%s) in list\n",
1004 bo2, bo2->ref_cnt, key,
1005 _tbm_flag_to_str(bo2->flags));
1008 _tbm_bufmgr_mutex_unlock();
1013 bo->bo_data = bo_data;
1015 bo_priv = bufmgr->backend->bo_import(bo, key);
1017 /* LCOV_EXCL_START */
1018 TBM_ERR("error: fail to import of tbm_bo by key(%d)\n", key);
1019 _tbm_set_last_result(TBM_ERROR_INVALID_OPERATION);
1021 /* LCOV_EXCL_STOP */
1024 if (!LIST_IS_EMPTY(&bufmgr->bo_list)) {
1025 LIST_FOR_EACH_ENTRY(bo2, &bufmgr->bo_list, item_link) {
1026 if (bo2->priv == bo_priv) {
1027 TBM_TRACE_BO("find bo(%p) ref(%d) key(%d) flag(%s) in list\n",
1028 bo2, bo2->ref_cnt, key,
1029 _tbm_flag_to_str(bo2->flags));
1032 _tbm_bufmgr_mutex_unlock();
1040 if (bufmgr->use_hal_tbm) {
1041 flags = (tbm_bo_memory_type)hal_tbm_bo_get_memory_types((hal_tbm_bo *)bo->bo_data, (hal_tbm_error *)&error);
1042 if (error != TBM_ERROR_NONE) {
1043 TBM_ERR("fail to get the bo flags(memory_types)");
1044 _tbm_set_last_result(error);
1045 flags = TBM_BO_DEFAULT;
1047 } else if (bufmgr->backend_module_data) {
1048 flags = bufmgr->bo_func->bo_get_memory_types(bo->bo_data, &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;
1055 if (bufmgr->backend->bo_get_flags)
1056 flags = bufmgr->backend->bo_get_flags(bo);
1058 flags = TBM_BO_DEFAULT;
1061 _tbm_bo_init(bufmgr, bo, flags);
1063 TBM_TRACE_BO("import new bo(%p) ref(%d) key(%d) flag(%s) in list\n",
1064 bo, bo->ref_cnt, key, _tbm_flag_to_str(bo->flags));
1066 _tbm_bufmgr_mutex_unlock();
1072 _tbm_bufmgr_mutex_unlock();
1077 tbm_bo_import_fd(tbm_bufmgr bufmgr, tbm_fd fd)
1082 tbm_backend_bo_data *bo_data;
1086 _tbm_bufmgr_mutex_lock();
1087 _tbm_set_last_result(TBM_ERROR_NONE);
1089 TBM_BO_RETURN_VAL_IF_FAIL(TBM_BUFMGR_IS_VALID(bufmgr), NULL);
1091 if (!bufmgr->use_hal_tbm) {
1092 if (bufmgr->backend_module_data) {
1093 if (!bufmgr->bufmgr_func->bufmgr_import_fd) {
1094 /* LCOV_EXCL_START */
1095 _tbm_bufmgr_mutex_unlock();
1096 _tbm_set_last_result(TBM_ERROR_NOT_SUPPORTED);
1098 /* LCOV_EXCL_STOP */
1101 if (!bufmgr->backend->bo_import_fd) {
1102 /* LCOV_EXCL_START */
1103 _tbm_bufmgr_mutex_unlock();
1104 _tbm_set_last_result(TBM_ERROR_NOT_SUPPORTED);
1106 /* LCOV_EXCL_STOP */
1111 _tbm_util_check_bo_cnt(bufmgr);
1113 bo = calloc(1, sizeof(struct _tbm_bo));
1115 /* LCOV_EXCL_START */
1116 TBM_ERR("error: fail to import tbm_bo by tbm_fd(%d)\n", fd);
1117 _tbm_set_last_result(TBM_ERROR_OUT_OF_MEMORY);
1118 _tbm_bufmgr_mutex_unlock();
1120 /* LCOV_EXCL_STOP */
1123 if (bufmgr->use_hal_tbm) {
1124 bo_data = (tbm_backend_bo_data *)hal_tbm_bufmgr_import_fd(bufmgr->hal_bufmgr, (hal_tbm_fd)fd, (hal_tbm_error *)&error);
1125 /* LCOV_EXCL_START */
1127 TBM_ERR("error: fail to import tbm_bo by tbm_fd(%d). error(%d)\n", fd, error);
1128 _tbm_set_last_result(error);
1131 /* LCOV_EXCL_STOP */
1133 if (!LIST_IS_EMPTY(&bufmgr->bo_list)) {
1134 LIST_FOR_EACH_ENTRY(bo2, &bufmgr->bo_list, item_link) {
1135 if (bo2->bo_data == bo_data) {
1136 TBM_TRACE_BO("find bo(%p) ref(%d) fd(%d) flag(%s) in list\n",
1137 bo2, bo2->ref_cnt, fd, _tbm_flag_to_str(bo2->flags));
1140 _tbm_bufmgr_mutex_unlock();
1145 bo->bo_data = bo_data;
1146 } else if (bufmgr->backend_module_data) {
1147 bo_data = bufmgr->bufmgr_func->bufmgr_import_fd(bufmgr->bufmgr_data, fd, &error);
1149 /* LCOV_EXCL_START */
1150 TBM_ERR("error: fail to import tbm_bo by tbm_fd(%d). error(%d)\n", fd, error);
1151 _tbm_set_last_result(error);
1153 /* LCOV_EXCL_STOP */
1156 if (!LIST_IS_EMPTY(&bufmgr->bo_list)) {
1157 LIST_FOR_EACH_ENTRY(bo2, &bufmgr->bo_list, item_link) {
1158 if (bo2->bo_data == bo_data) {
1159 TBM_TRACE_BO("find bo(%p) ref(%d) fd(%d) flag(%s) in list\n",
1160 bo2, bo2->ref_cnt, fd, _tbm_flag_to_str(bo2->flags));
1163 _tbm_bufmgr_mutex_unlock();
1168 bo->bo_data = bo_data;
1170 bo_priv = bufmgr->backend->bo_import_fd(bo, fd);
1172 /* LCOV_EXCL_START */
1173 TBM_ERR("error: fail to import tbm_bo by tbm_fd(%d)\n", fd);
1174 _tbm_set_last_result(TBM_ERROR_INVALID_OPERATION);
1176 /* LCOV_EXCL_STOP */
1179 if (!LIST_IS_EMPTY(&bufmgr->bo_list)) {
1180 LIST_FOR_EACH_ENTRY(bo2, &bufmgr->bo_list, item_link) {
1181 if (bo2->priv == bo_priv) {
1182 TBM_TRACE_BO("find bo(%p) ref(%d) fd(%d) flag(%s) in list\n",
1183 bo2, bo2->ref_cnt, fd, _tbm_flag_to_str(bo2->flags));
1186 _tbm_bufmgr_mutex_unlock();
1194 if (bufmgr->use_hal_tbm) {
1195 flags = (tbm_bo_memory_type)hal_tbm_bo_get_memory_types((hal_tbm_bo *)bo->bo_data, (hal_tbm_error *)&error);
1196 if (error != TBM_ERROR_NONE) {
1197 TBM_ERR("fail to get the bo flags(memory_types)");
1198 _tbm_set_last_result(error);
1199 flags = TBM_BO_DEFAULT;
1201 } else if (bufmgr->backend_module_data) {
1202 flags = bufmgr->bo_func->bo_get_memory_types(bo->bo_data, &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;
1209 if (bufmgr->backend->bo_get_flags)
1210 flags = bufmgr->backend->bo_get_flags(bo);
1212 flags = TBM_BO_DEFAULT;
1215 _tbm_bo_init(bufmgr, bo, flags);
1217 TBM_TRACE_BO("import bo(%p) ref(%d) fd(%d) flag(%s)\n",
1218 bo, bo->ref_cnt, fd, _tbm_flag_to_str(bo->flags));
1220 _tbm_bufmgr_mutex_unlock();
1226 _tbm_bufmgr_mutex_unlock();
1231 tbm_bo_size(tbm_bo bo)
1236 _tbm_bufmgr_mutex_lock();
1237 _tbm_set_last_result(TBM_ERROR_NONE);
1239 TBM_BO_RETURN_VAL_IF_FAIL(_tbm_bo_is_valid(bo), 0);
1241 if (bo->bufmgr->use_hal_tbm) {
1242 size = hal_tbm_bo_get_size((hal_tbm_bo *)bo->bo_data, (hal_tbm_error *)&error);
1243 if (error != TBM_ERROR_NONE) {
1244 TBM_ERR("fail to get the size of the bo_data(%d).", error);
1245 _tbm_set_last_result(TBM_ERROR_NONE);
1247 } else if (bo->bufmgr->backend_module_data) {
1248 size = bo->bufmgr->bo_func->bo_get_size(bo->bo_data, &error);
1249 if (error != TBM_ERROR_NONE) {
1250 TBM_ERR("fail to get the size of the bo_data(%d).", error);
1251 _tbm_set_last_result(TBM_ERROR_NONE);
1254 size = bo->bufmgr->backend->bo_size(bo);
1256 TBM_TRACE_BO("bo(%p) size(%d)\n", bo, size);
1258 _tbm_bufmgr_mutex_unlock();
1264 tbm_bo_locked(tbm_bo bo)
1266 _tbm_bufmgr_mutex_lock();
1267 _tbm_set_last_result(TBM_ERROR_NONE);
1269 TBM_BO_RETURN_VAL_IF_FAIL(_tbm_bo_is_valid(bo), 0);
1271 if (bo->bufmgr->bo_lock_type == TBM_BUFMGR_BO_LOCK_TYPE_NEVER) {
1272 TBM_ERR("bo(%p) lock_cnt(%d)\n", bo, bo->lock_cnt);
1273 _tbm_set_last_result(TBM_ERROR_INVALID_OPERATION);
1274 _tbm_bufmgr_mutex_unlock();
1278 if (bo->lock_cnt > 0) {
1279 TBM_TRACE_BO("error: bo(%p) lock_cnt(%d)\n", bo, bo->lock_cnt);
1280 _tbm_bufmgr_mutex_unlock();
1284 TBM_TRACE_BO("bo(%p) lock_cnt(%d)\n", bo, bo->lock_cnt);
1285 _tbm_bufmgr_mutex_unlock();
1291 tbm_bo_swap(tbm_bo bo1, tbm_bo bo2)
1293 tbm_error_e error1, error2;
1294 int size1 = -1, size2 = -2;
1297 _tbm_bufmgr_mutex_lock();
1298 _tbm_set_last_result(TBM_ERROR_NONE);
1300 TBM_BO_RETURN_VAL_IF_FAIL(_tbm_bo_is_valid(bo1), 0);
1301 TBM_BO_RETURN_VAL_IF_FAIL(_tbm_bo_is_valid(bo2), 0);
1303 TBM_TRACE_BO("before: bo1(%p) bo2(%p)\n", bo1, bo2);
1305 if (bo1->bufmgr->use_hal_tbm) {
1306 size1 = hal_tbm_bo_get_size((hal_tbm_bo *)bo1->bo_data, (hal_tbm_error *)&error1);
1307 if (error1 != TBM_ERROR_NONE) {
1308 TBM_ERR("fail to get the size of bo1.(%d)", error1);
1309 _tbm_set_last_result(error1);
1312 size2 = hal_tbm_bo_get_size((hal_tbm_bo *)bo2->bo_data, (hal_tbm_error *)&error2);
1313 if (error2 != TBM_ERROR_NONE) {
1314 TBM_ERR("fail to get the size of bo1.(%d)", error2);
1315 _tbm_set_last_result(error2);
1318 } else if (bo1->bufmgr->backend_module_data) {
1319 size1 = bo1->bufmgr->bo_func->bo_get_size(bo1->bo_data, &error1);
1320 if (error1 != TBM_ERROR_NONE) {
1321 TBM_ERR("fail to get the size of bo1.(%d)", error1);
1322 _tbm_set_last_result(error1);
1325 size2 = bo2->bufmgr->bo_func->bo_get_size(bo2->bo_data, &error2);
1326 if (error2 != TBM_ERROR_NONE) {
1327 TBM_ERR("fail to get the size of bo2.(%d)", error2);
1328 _tbm_set_last_result(error2);
1332 size1 = bo1->bufmgr->backend->bo_size(bo1);
1333 size2 = bo2->bufmgr->backend->bo_size(bo2);
1336 if (size1 != size2) {
1337 TBM_ERR("error: bo1 size(%d) and bo2 size(%d) is different.", size1, size2);
1338 _tbm_set_last_result(TBM_ERROR_INVALID_OPERATION);
1342 TBM_TRACE_BO("after: bo1(%p) bo2(%p)\n", bo1, bo2);
1345 bo1->priv = bo2->priv;
1348 _tbm_bufmgr_mutex_unlock();
1353 TBM_ERR("error: bo1(%p) bo2(%p)\n", bo1, bo2);
1354 _tbm_bufmgr_mutex_unlock();
1360 tbm_bo_add_user_data(tbm_bo bo, unsigned long key,
1361 tbm_data_free data_free_func)
1363 tbm_user_data *data;
1365 _tbm_bufmgr_mutex_lock();
1366 _tbm_set_last_result(TBM_ERROR_NONE);
1368 TBM_BO_RETURN_VAL_IF_FAIL(_tbm_bo_is_valid(bo), 0);
1370 /* check if the data according to the key exist if so, return false. */
1371 data = user_data_lookup(&bo->user_data_list, key);
1373 TBM_TRACE_BO("warning: user data already exist key(%ld)\n", key);
1374 _tbm_set_last_result(TBM_ERROR_INVALID_PARAMETER);
1375 _tbm_bufmgr_mutex_unlock();
1379 data = user_data_create(key, data_free_func);
1381 TBM_ERR("error: bo(%p) key(%lu)\n", bo, key);
1382 _tbm_set_last_result(TBM_ERROR_INVALID_PARAMETER);
1383 _tbm_bufmgr_mutex_unlock();
1387 TBM_TRACE_BO("bo(%p) key(%lu) data(%p)\n", bo, key, data->data);
1389 LIST_ADD(&data->item_link, &bo->user_data_list);
1391 _tbm_bufmgr_mutex_unlock();
1397 tbm_bo_delete_user_data(tbm_bo bo, unsigned long key)
1399 tbm_user_data *old_data;
1401 _tbm_bufmgr_mutex_lock();
1402 _tbm_set_last_result(TBM_ERROR_NONE);
1404 TBM_BO_RETURN_VAL_IF_FAIL(_tbm_bo_is_valid(bo), 0);
1406 if (LIST_IS_EMPTY(&bo->user_data_list)) {
1407 TBM_TRACE_BO("bo(%p) key(%lu)\n", bo, key);
1408 _tbm_set_last_result(TBM_ERROR_INVALID_PARAMETER);
1409 _tbm_bufmgr_mutex_unlock();
1413 old_data = user_data_lookup(&bo->user_data_list, key);
1415 TBM_TRACE_BO("bo(%p) key(%lu)\n", bo, key);
1416 _tbm_set_last_result(TBM_ERROR_INVALID_PARAMETER);
1417 _tbm_bufmgr_mutex_unlock();
1421 TBM_TRACE_BO("bo(%p) key(%lu) data(%p)\n", bo, key, old_data->data);
1423 user_data_delete(old_data);
1425 _tbm_bufmgr_mutex_unlock();
1431 tbm_bo_set_user_data(tbm_bo bo, unsigned long key, void *data)
1433 tbm_user_data *old_data;
1435 _tbm_bufmgr_mutex_lock();
1436 _tbm_set_last_result(TBM_ERROR_NONE);
1438 TBM_BO_RETURN_VAL_IF_FAIL(_tbm_bo_is_valid(bo), 0);
1440 if (LIST_IS_EMPTY(&bo->user_data_list)) {
1441 TBM_TRACE_BO("error: bo(%p) key(%lu)\n", bo, key);
1442 _tbm_set_last_result(TBM_ERROR_INVALID_PARAMETER);
1443 _tbm_bufmgr_mutex_unlock();
1447 old_data = user_data_lookup(&bo->user_data_list, key);
1449 TBM_TRACE_BO("error: bo(%p) key(%lu)\n", bo, key);
1450 _tbm_set_last_result(TBM_ERROR_INVALID_PARAMETER);
1451 _tbm_bufmgr_mutex_unlock();
1455 if (old_data->data && old_data->free_func)
1456 old_data->free_func(old_data->data);
1457 old_data->data = data;
1459 TBM_TRACE_BO("bo(%p) key(%lu) data(%p)\n", bo, key, old_data->data);
1461 _tbm_bufmgr_mutex_unlock();
1467 tbm_bo_get_user_data(tbm_bo bo, unsigned long key, void **data)
1469 tbm_user_data *old_data;
1471 _tbm_bufmgr_mutex_lock();
1472 _tbm_set_last_result(TBM_ERROR_NONE);
1474 TBM_BO_RETURN_VAL_IF_FAIL(_tbm_bo_is_valid(bo), 0);
1476 if (!data || LIST_IS_EMPTY(&bo->user_data_list)) {
1477 TBM_TRACE_BO("error: bo(%p) key(%lu)\n", bo, key);
1478 _tbm_set_last_result(TBM_ERROR_INVALID_PARAMETER);
1479 _tbm_bufmgr_mutex_unlock();
1483 old_data = user_data_lookup(&bo->user_data_list, key);
1486 TBM_TRACE_BO("error: bo(%p) key(%lu)\n", bo, key);
1487 _tbm_set_last_result(TBM_ERROR_INVALID_PARAMETER);
1488 _tbm_bufmgr_mutex_unlock();
1492 *data = old_data->data;
1494 TBM_TRACE_BO("bo(%p) key(%lu) data(%p)\n", bo, key, old_data->data);
1496 _tbm_bufmgr_mutex_unlock();
1502 tbm_bo_get_flags(tbm_bo bo)
1506 _tbm_bufmgr_mutex_lock();
1508 TBM_BO_RETURN_VAL_IF_FAIL(_tbm_bo_is_valid(bo), 0);
1512 TBM_TRACE_BO("bo(%p)\n", bo);
1514 _tbm_bufmgr_mutex_unlock();
1519 /* LCOV_EXCL_START */
1520 /* internal function */
1522 _tbm_bo_set_surface(tbm_bo bo, tbm_surface_h surface)
1524 _tbm_bufmgr_mutex_lock();
1526 TBM_BO_RETURN_VAL_IF_FAIL(_tbm_bo_is_valid(bo), 0);
1528 bo->surface = surface;
1530 _tbm_bufmgr_mutex_unlock();
1536 _tbm_bo_free(tbm_bo bo)
1538 /* destory the user_data_list */
1539 if (!LIST_IS_EMPTY(&bo->user_data_list)) {
1540 tbm_user_data *old_data = NULL, *tmp;
1542 LIST_FOR_EACH_ENTRY_SAFE(old_data, tmp,
1543 &bo->user_data_list, item_link) {
1544 TBM_DBG("free user_data\n");
1545 user_data_delete(old_data);
1549 while (bo->lock_cnt > 0) {
1550 TBM_ERR("error lock_cnt:%d\n", bo->lock_cnt);
1555 /* call the bo_free */
1556 if (bo->bufmgr->use_hal_tbm) {
1557 hal_tbm_bo_free(bo->bo_data);
1559 } else if (bo->bufmgr->backend_module_data) {
1560 bo->bufmgr->bo_func->bo_free(bo->bo_data);
1563 bo->bufmgr->backend->bo_free(bo);
1571 /* LCOV_EXCL_STOP */