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_NOT_SUPPORTED) {
161 _tbm_set_last_result(TBM_ERROR_NONE);
163 if (error != TBM_ERROR_NONE) {
164 TBM_WRN("fail to lock");
165 _tbm_set_last_result(error);
169 } else if (bo->bufmgr->backend_module_data) {
170 if (bo->bufmgr->bo_func->bo_lock) {
171 error = bo->bufmgr->bo_func->bo_lock(bo->bo_data, device, opt);
172 if (error != TBM_ERROR_NONE) {
173 TBM_WRN("fail to lock");
174 _tbm_set_last_result(error);
179 if (bo->bufmgr->backend->bo_lock) {
180 ret = bo->bufmgr->backend->bo_lock(bo, device, opt);
182 _tbm_set_last_result(TBM_ERROR_INVALID_OPERATION);
190 _bo_unlock(tbm_bo bo)
194 if (bo->bufmgr->use_hal_tbm) {
195 error = (tbm_error_e)hal_tbm_bo_unlock((hal_tbm_bo *)bo->bo_data);
196 if (error == TBM_ERROR_NOT_SUPPORTED) {
197 _tbm_set_last_result(TBM_ERROR_NONE);
199 if (error != TBM_ERROR_NONE) {
200 TBM_WRN("fail to lock");
201 _tbm_set_last_result(error);
204 } else if (bo->bufmgr->backend_module_data) {
205 if (bo->bufmgr->bo_func->bo_unlock) {
206 error = bo->bufmgr->bo_func->bo_unlock(bo->bo_data);
207 if (error != TBM_ERROR_NONE) {
208 TBM_WRN("fail to unlock");
209 _tbm_set_last_result(error);
213 if (bo->bufmgr->backend->bo_unlock)
214 bo->bufmgr->backend->bo_unlock(bo);
219 _tbm_bo_lock(tbm_bo bo, int device, int opt)
226 /* do not try to lock the bo */
227 if (bo->bufmgr->bo_lock_type == TBM_BUFMGR_BO_LOCK_TYPE_NEVER)
230 if (bo->lock_cnt < 0) {
231 TBM_ERR("error bo:%p LOCK_CNT=%d\n",
238 switch (bo->bufmgr->bo_lock_type) {
239 case TBM_BUFMGR_BO_LOCK_TYPE_ONCE:
240 if (bo->lock_cnt == 0) {
241 _tbm_bufmgr_mutex_unlock();
242 ret = _bo_lock(bo, device, opt);
243 _tbm_bufmgr_mutex_lock();
249 case TBM_BUFMGR_BO_LOCK_TYPE_ALWAYS:
250 _tbm_bufmgr_mutex_unlock();
251 ret = _bo_lock(bo, device, opt);
252 _tbm_bufmgr_mutex_lock();
257 TBM_ERR("error bo:%p bo_lock_type[%d] is wrong.\n",
258 bo, bo->bufmgr->bo_lock_type);
263 TBM_DBG(">> LOCK bo:%p(%d->%d)\n", bo, old, bo->lock_cnt);
269 _tbm_bo_unlock(tbm_bo bo)
273 /* do not try to unlock the bo */
274 if (bo->bufmgr->bo_lock_type == TBM_BUFMGR_BO_LOCK_TYPE_NEVER)
279 switch (bo->bufmgr->bo_lock_type) {
280 case TBM_BUFMGR_BO_LOCK_TYPE_ONCE:
281 if (bo->lock_cnt > 0) {
283 if (bo->lock_cnt == 0)
287 case TBM_BUFMGR_BO_LOCK_TYPE_ALWAYS:
288 if (bo->lock_cnt > 0) {
294 TBM_ERR("error bo:%p bo_lock_type[%d] is wrong.\n",
295 bo, bo->bufmgr->bo_lock_type);
299 if (bo->lock_cnt < 0)
302 TBM_DBG(">> UNLOCK bo:%p(%d->%d)\n", bo, old, bo->lock_cnt);
306 _tbm_bo_magic_check(tbm_bo bo)
308 if (bo->magic != TBM_BO_MAGIC)
315 _tbm_bo_is_valid(tbm_bo bo)
318 TBM_ERR("error: bo is NULL.\n");
322 if (!_tbm_bo_magic_check(bo)) {
323 TBM_ERR("error: No valid bo(%p).\n", bo);
331 _tbm_bo_init(tbm_bufmgr bufmgr, tbm_bo bo, int flags)
335 bo->magic = TBM_BO_MAGIC;
338 LIST_INITHEAD(&bo->user_data_list);
341 LIST_ADD(&bo->item_link, &bufmgr->bo_list);
345 _tbm_bo_deinit(tbm_bo bo)
349 bo->bufmgr->bo_cnt--;
350 LIST_DEL(&bo->item_link);
354 tbm_bo_alloc(tbm_bufmgr bufmgr, int size, int flags)
358 tbm_backend_bo_data *bo_data;
361 _tbm_bufmgr_mutex_lock();
362 _tbm_set_last_result(TBM_ERROR_NONE);
364 TBM_BO_RETURN_VAL_IF_FAIL(TBM_BUFMGR_IS_VALID(bufmgr), NULL);
365 TBM_BO_RETURN_VAL_IF_FAIL(size > 0, NULL);
367 bo = calloc(1, sizeof(struct _tbm_bo));
369 /* LCOV_EXCL_START */
370 _tbm_set_last_result(TBM_ERROR_OUT_OF_MEMORY);
371 _tbm_bufmgr_mutex_unlock();
376 _tbm_util_check_bo_cnt(bufmgr);
378 if (bufmgr->use_hal_tbm) {
379 bo_data = (tbm_backend_bo_data *)hal_tbm_bufmgr_alloc_bo(bufmgr->hal_bufmgr, size, flags, (hal_tbm_error *)&error);
380 /* LCOV_EXCL_START */
382 _tbm_set_last_result(error);
386 bo->bo_data = bo_data;
387 } else if (bufmgr->backend_module_data) {
388 bo_data = bufmgr->bufmgr_func->bufmgr_alloc_bo(bufmgr->bufmgr_data, (unsigned int)size, flags, &error);
390 /* LCOV_EXCL_START */
391 _tbm_set_last_result(error);
395 bo->bo_data = bo_data;
397 bo_priv = bufmgr->backend->bo_alloc(bo, size, flags);
399 /* LCOV_EXCL_START */
401 _tbm_set_last_result(TBM_ERROR_INVALID_OPERATION);
408 _tbm_bo_init(bufmgr, bo, flags);
410 TBM_TRACE_BO("bo(%p) size(%d) refcnt(%d), flag(%s)\n", bo, size, bo->ref_cnt,
411 _tbm_flag_to_str(bo->flags));
413 _tbm_bufmgr_mutex_unlock();
418 TBM_ERR("error: fail to create of tbm_bo size(%d) flag(%s)\n", size, _tbm_flag_to_str(flags));
420 _tbm_bufmgr_mutex_unlock();
424 /* LCOV_EXCL_START */
426 tbm_bo_alloc_with_format(tbm_bufmgr bufmgr, int format, int bo_idx, int width,
427 int height, tbm_bo_memory_type flags, tbm_error_e *error)
430 tbm_backend_bo_data *bo_data;
432 _tbm_bufmgr_mutex_lock();
433 _tbm_set_last_result(TBM_ERROR_NONE);
435 TBM_BO_RETURN_VAL_IF_FAIL(TBM_BUFMGR_IS_VALID(bufmgr), NULL);
437 bo = calloc(1, sizeof(struct _tbm_bo));
439 TBM_ERR("error: fail to tbm_bo_alloc_with_format fmt(%s) idx(%d) w(%d) h(%d) mem_types(%s)\n",
440 FOURCC_STR(format), bo_idx, width, height, _tbm_flag_to_str(flags));
441 _tbm_set_last_result(TBM_ERROR_OUT_OF_MEMORY);
445 _tbm_util_check_bo_cnt(bufmgr);
447 /* LCOV_EXCL_START */
448 if (!bufmgr->use_hal_tbm) {
449 if (!bufmgr->backend_module_data || !bufmgr->bufmgr_func->bufmgr_alloc_bo_with_format) {
451 TBM_ERR("error: not supported tbm_bo_alloc_with_format\n");
452 _tbm_set_last_result(TBM_ERROR_NOT_SUPPORTED);
458 if (bufmgr->use_hal_tbm) {
459 bo_data = (tbm_backend_bo_data *)hal_tbm_bufmgr_alloc_bo_with_format(bufmgr->hal_bufmgr,
460 format, bo_idx, width, height, (hal_tbm_bo_memory_type)flags, (hal_tbm_error *)error);
462 TBM_ERR("error: fail to tbm_bo_alloc_with_format\n");
463 _tbm_set_last_result(*error);
467 bo_data = bufmgr->bufmgr_func->bufmgr_alloc_bo_with_format(bufmgr->bufmgr_data, format, bo_idx,
468 width, height, flags, error);
470 TBM_ERR("error: fail to tbm_bo_alloc_with_format fmt(%s) idx(%d) w(%d) h(%d) mem_types(%s)\n",
471 FOURCC_STR(format), bo_idx, width, height, _tbm_flag_to_str(flags));
472 _tbm_set_last_result(*error);
477 bo->bo_data = bo_data;
478 _tbm_bo_init(bufmgr, bo, flags);
480 _tbm_bufmgr_mutex_unlock();
487 _tbm_bufmgr_mutex_unlock();
492 tbm_bo_alloc_with_tiled_format(tbm_bufmgr bufmgr, int width, int height, int bpp, int format,
493 tbm_bo_memory_type flags, int bo_idx, tbm_error_e *error)
496 tbm_backend_bo_data *bo_data;
498 _tbm_bufmgr_mutex_lock();
499 _tbm_set_last_result(TBM_ERROR_NONE);
501 TBM_BO_RETURN_VAL_IF_FAIL(TBM_BUFMGR_IS_VALID(bufmgr), NULL);
503 bo = calloc(1, sizeof(struct _tbm_bo));
505 TBM_ERR("error: fail to tbm_bo_alloc_with_tiled_format fmt(%s) idx(%d) w(%d) h(%d) flags(%s)\n",
506 FOURCC_STR(format), bo_idx, width, height, _tbm_flag_to_str(flags));
507 _tbm_set_last_result(TBM_ERROR_OUT_OF_MEMORY);
508 _tbm_bufmgr_mutex_unlock();
512 _tbm_util_check_bo_cnt(bufmgr);
514 if (!bufmgr->use_hal_tbm) {
515 if (!bufmgr->backend_module_data || !bufmgr->bufmgr_func->bufmgr_alloc_bo_with_tiled_format) {
516 TBM_ERR("error: not supported tbm_bo_alloc_with_tiled_format\n");
517 _tbm_set_last_result(TBM_ERROR_NOT_SUPPORTED);
519 _tbm_bufmgr_mutex_unlock();
524 if (bufmgr->use_hal_tbm)
525 bo_data = (tbm_backend_bo_data *)hal_tbm_bufmgr_alloc_bo_with_tiled_format(bufmgr->hal_bufmgr,
526 width, height, bpp, format, (hal_tbm_bo_memory_type)flags, bo_idx, (hal_tbm_error *)error);
528 bo_data = bufmgr->bufmgr_func->bufmgr_alloc_bo_with_tiled_format(bufmgr->bufmgr_data, width, height,
529 bpp, format, flags, bo_idx, error);
531 TBM_ERR("error: fail to tbm_bo_alloc_with_tiled_format fmt(%s) idx(%d) w(%d) h(%d) flags(%s)\n",
532 FOURCC_STR(format), bo_idx, width, height, _tbm_flag_to_str(flags));
533 _tbm_set_last_result(*error);
535 _tbm_bufmgr_mutex_unlock();
539 bo->bo_data = bo_data;
540 _tbm_bo_init(bufmgr, bo, flags);
542 _tbm_bufmgr_mutex_unlock();
548 tbm_bo_alloc_with_surface(tbm_bufmgr bufmgr, int width, int height, int format, int flags, int bo_idx)
553 _tbm_bufmgr_mutex_lock();
554 _tbm_set_last_result(TBM_ERROR_NONE);
556 TBM_BO_RETURN_VAL_IF_FAIL(TBM_BUFMGR_IS_VALID(bufmgr), NULL);
558 bo = calloc(1, sizeof(struct _tbm_bo));
560 TBM_ERR("error: fail to tbm_bo_alloc_with_surface fmt(%s) idx(%d) w(%d) h(%d) flags(%s)\n",
561 FOURCC_STR(format), bo_idx, width, height, _tbm_flag_to_str(flags));
562 _tbm_set_last_result(TBM_ERROR_OUT_OF_MEMORY);
563 _tbm_bufmgr_mutex_unlock();
567 _tbm_util_check_bo_cnt(bufmgr);
569 if (!bufmgr->backend->surface_bo_alloc) {
570 TBM_ERR("error: not supported tbm_bo_alloc_with_surface\n");
571 _tbm_set_last_result(TBM_ERROR_NOT_SUPPORTED);
573 _tbm_bufmgr_mutex_unlock();
577 bo_priv = bufmgr->backend->surface_bo_alloc(bo, width, height, format, flags, bo_idx);
579 TBM_ERR("error: fail to tbm_bo_alloc_with_surface fmt(%s) idx(%d) w(%d) h(%d) flags(%s)\n",
580 FOURCC_STR(format), bo_idx, width, height, _tbm_flag_to_str(flags));
581 _tbm_set_last_result(TBM_ERROR_INVALID_OPERATION);
583 _tbm_bufmgr_mutex_unlock();
588 _tbm_bo_init(bufmgr, bo, flags);
590 _tbm_bufmgr_mutex_unlock();
597 tbm_bo_ref(tbm_bo bo)
599 _tbm_bufmgr_mutex_lock();
600 _tbm_set_last_result(TBM_ERROR_NONE);
602 TBM_BO_RETURN_VAL_IF_FAIL(_tbm_bo_is_valid(bo), NULL);
606 TBM_TRACE_BO("bo(%p) ref_cnt(%d)\n", bo, bo->ref_cnt);
608 _tbm_bufmgr_mutex_unlock();
614 tbm_bo_unref(tbm_bo bo)
616 _tbm_bufmgr_mutex_lock();
617 _tbm_set_last_result(TBM_ERROR_NONE);
619 TBM_BO_RETURN_IF_FAIL(_tbm_bo_is_valid(bo));
621 TBM_TRACE_BO("bo(%p) ref_cnt(%d)\n", bo, bo->ref_cnt - 1);
623 if (bo->ref_cnt <= 0) {
624 _tbm_bufmgr_mutex_unlock();
629 if (bo->ref_cnt == 0)
632 _tbm_bufmgr_mutex_unlock();
636 tbm_bo_map(tbm_bo bo, int device, int opt)
638 tbm_bo_handle bo_handle;
641 _tbm_bufmgr_mutex_lock();
642 _tbm_set_last_result(TBM_ERROR_NONE);
644 TBM_BO_RETURN_VAL_IF_FAIL(_tbm_bo_is_valid(bo), (tbm_bo_handle) NULL);
646 if (!_tbm_bo_lock(bo, device, opt)) {
647 TBM_ERR("error: fail to lock bo:%p)\n", bo);
648 _tbm_bufmgr_mutex_unlock();
649 return (tbm_bo_handle) NULL;
652 if (bo->bufmgr->use_hal_tbm) {
653 hal_tbm_bo_handle hbo_handle;
654 hbo_handle = hal_tbm_bo_map((hal_tbm_bo *)bo->bo_data, device, opt, (hal_tbm_error *)&error);
655 if (hbo_handle.ptr == NULL) {
656 /* LCOV_EXCL_START */
657 _tbm_set_last_result(error);
658 TBM_ERR("error: bo(%p) bo_handle(%p) error(%d)\n", bo, hbo_handle.ptr, error);
662 memcpy(&bo_handle.ptr, &hbo_handle.ptr, sizeof(tbm_bo_handle));
663 } else if (bo->bufmgr->backend_module_data) {
664 bo_handle = bo->bufmgr->bo_func->bo_map(bo->bo_data, device, opt, &error);
665 if (bo_handle.ptr == NULL) {
666 /* LCOV_EXCL_START */
667 _tbm_set_last_result(error);
668 TBM_ERR("error: fail to map bo:%p error:%d\n", bo, error);
673 bo_handle = bo->bufmgr->backend->bo_map(bo, device, opt);
674 if (bo_handle.ptr == NULL) {
675 /* LCOV_EXCL_START */
676 _tbm_set_last_result(TBM_ERROR_INVALID_OPERATION);
677 TBM_ERR("error: fail to map bo:%p\n", bo);
683 /* increase the map_count */
686 TBM_TRACE_BO("bo(%p) map_cnt(%d)\n", bo, bo->map_cnt);
688 _tbm_bufmgr_mutex_unlock();
694 _tbm_bufmgr_mutex_unlock();
695 return (tbm_bo_handle) NULL;
699 tbm_bo_unmap(tbm_bo bo)
704 _tbm_bufmgr_mutex_lock();
705 _tbm_set_last_result(TBM_ERROR_NONE);
707 TBM_BO_RETURN_VAL_IF_FAIL(_tbm_bo_is_valid(bo), 0);
708 TBM_BO_RETURN_VAL_IF_FAIL(bo->map_cnt > 0, 0);
710 if (bo->bufmgr->use_hal_tbm) {
711 error = (hal_tbm_error)hal_tbm_bo_unmap((hal_tbm_bo *)bo->bo_data);
712 if (error != TBM_ERROR_NONE) {
713 /* LCOV_EXCL_START */
714 TBM_ERR("error: bo(%p) map_cnt(%d) error(%d)\n", bo, bo->map_cnt, error);
715 _tbm_set_last_result(error);
720 } else if (bo->bufmgr->backend_module_data) {
721 error = bo->bufmgr->bo_func->bo_unmap(bo->bo_data);
722 if (error != TBM_ERROR_NONE) {
723 /* LCOV_EXCL_START */
724 TBM_ERR("error: bo(%p) map_cnt(%d) error(%d)\n", bo, bo->map_cnt, error);
725 _tbm_set_last_result(error);
731 ret = bo->bufmgr->backend->bo_unmap(bo);
733 /* LCOV_EXCL_START */
734 TBM_ERR("error: bo(%p) map_cnt(%d)\n", bo, bo->map_cnt);
735 _tbm_set_last_result(TBM_ERROR_INVALID_OPERATION);
741 /* decrease the map_count */
744 TBM_TRACE_BO("bo(%p) map_cnt(%d)\n", bo, bo->map_cnt);
749 _tbm_bufmgr_mutex_unlock();
755 tbm_bo_get_handle(tbm_bo bo, int device)
757 tbm_bo_handle bo_handle;
760 _tbm_bufmgr_mutex_lock();
761 _tbm_set_last_result(TBM_ERROR_NONE);
763 TBM_BO_RETURN_VAL_IF_FAIL(_tbm_bo_is_valid(bo), (tbm_bo_handle) NULL);
765 if (bo->bufmgr->use_hal_tbm) {
766 hal_tbm_bo_handle hbo_handle;
767 hbo_handle = hal_tbm_bo_get_handle((hal_tbm_bo *)bo->bo_data, device, (hal_tbm_error *)&error);
768 if (hbo_handle.ptr == NULL) {
769 /* LCOV_EXCL_START */
770 TBM_ERR("error: bo(%p) bo_handle(%p) error(%d)\n", bo, hbo_handle.ptr, error);
771 _tbm_set_last_result(error);
775 memcpy(&bo_handle.ptr, &hbo_handle.ptr, sizeof(tbm_bo_handle));
776 } else if (bo->bufmgr->backend_module_data) {
777 bo_handle = bo->bufmgr->bo_func->bo_get_handle(bo->bo_data, device, &error);
778 if (bo_handle.ptr == NULL) {
779 /* LCOV_EXCL_START */
780 TBM_ERR("error: bo(%p) bo_handle(%p) error(%d)\n", bo, bo_handle.ptr, error);
781 _tbm_set_last_result(error);
786 bo_handle = bo->bufmgr->backend->bo_get_handle(bo, device);
787 if (bo_handle.ptr == NULL) {
788 /* LCOV_EXCL_START */
789 TBM_ERR("error: bo(%p) bo_handle(%p)\n", bo, bo_handle.ptr);
790 _tbm_set_last_result(TBM_ERROR_INVALID_OPERATION);
796 TBM_TRACE_BO("bo(%p) bo_handle(%p)\n", bo, bo_handle.ptr);
798 _tbm_bufmgr_mutex_unlock();
803 _tbm_bufmgr_mutex_unlock();
804 return (tbm_bo_handle) NULL;
808 tbm_bo_export(tbm_bo bo)
813 _tbm_bufmgr_mutex_lock();
814 _tbm_set_last_result(TBM_ERROR_NONE);
816 TBM_BO_RETURN_VAL_IF_FAIL(_tbm_bo_is_valid(bo), 0);
818 if (bo->bufmgr->use_hal_tbm) {
819 ret = (hal_tbm_key)hal_tbm_bo_export_key((hal_tbm_bo *)bo->bo_data, (hal_tbm_error *)&error);
821 /* LCOV_EXCL_START */
822 TBM_ERR("error: bo(%p) tbm_key(%d) error(%d)\n", bo, ret, error);
823 _tbm_set_last_result(error);
827 } else if (bo->bufmgr->backend_module_data) {
828 if (!bo->bufmgr->bo_func->bo_export_key) {
829 /* LCOV_EXCL_START */
830 _tbm_bufmgr_mutex_unlock();
831 _tbm_set_last_result(TBM_ERROR_NOT_SUPPORTED);
836 ret = bo->bufmgr->bo_func->bo_export_key(bo->bo_data, &error);
838 /* LCOV_EXCL_START */
839 TBM_ERR("error: bo(%p) tbm_key(%d) error(%d)\n", bo, ret, error);
840 _tbm_set_last_result(error);
845 if (!bo->bufmgr->backend->bo_export) {
846 /* LCOV_EXCL_START */
847 _tbm_bufmgr_mutex_unlock();
848 _tbm_set_last_result(TBM_ERROR_NOT_SUPPORTED);
853 ret = bo->bufmgr->backend->bo_export(bo);
855 /* LCOV_EXCL_START */
856 TBM_ERR("error: bo(%p) tbm_key(%d)\n", bo, ret);
857 _tbm_set_last_result(TBM_ERROR_INVALID_OPERATION);
863 TBM_TRACE_BO("bo(%p) tbm_key(%u)\n", bo, ret);
866 _tbm_bufmgr_mutex_unlock();
872 tbm_bo_export_fd(tbm_bo bo)
877 _tbm_bufmgr_mutex_lock();
878 _tbm_set_last_result(TBM_ERROR_NONE);
880 TBM_BO_RETURN_VAL_IF_FAIL(_tbm_bo_is_valid(bo), -1);
882 if (bo->bufmgr->use_hal_tbm) {
883 ret = (hal_tbm_fd)hal_tbm_bo_export_fd((hal_tbm_bo *)bo->bo_data, (hal_tbm_error *)&error);
885 /* LCOV_EXCL_START */
886 TBM_ERR("error: bo(%p) tbm_fd(%d) error(%d)\n", bo, ret, error);
887 _tbm_set_last_result(error);
891 } else if (bo->bufmgr->backend_module_data) {
892 if (!bo->bufmgr->bo_func->bo_export_fd) {
893 /* LCOV_EXCL_START */
894 _tbm_bufmgr_mutex_unlock();
895 _tbm_set_last_result(TBM_ERROR_NOT_SUPPORTED);
900 ret = bo->bufmgr->bo_func->bo_export_fd(bo->bo_data, &error);
902 /* LCOV_EXCL_START */
903 TBM_ERR("error: bo(%p) tbm_fd(%d) error(%d)\n", bo, ret, error);
904 _tbm_set_last_result(error);
909 if (!bo->bufmgr->backend->bo_export_fd) {
910 /* LCOV_EXCL_START */
911 _tbm_bufmgr_mutex_unlock();
912 _tbm_set_last_result(TBM_ERROR_NOT_SUPPORTED);
917 ret = bo->bufmgr->backend->bo_export_fd(bo);
919 /* LCOV_EXCL_START */
920 TBM_ERR("error: bo(%p) tbm_fd(%d)\n", bo, ret);
921 _tbm_set_last_result(TBM_ERROR_INVALID_OPERATION);
927 TBM_TRACE_BO("bo(%p) tbm_fd(%d)\n", bo, ret);
930 _tbm_bufmgr_mutex_unlock();
936 tbm_bo_import(tbm_bufmgr bufmgr, unsigned int key)
942 tbm_backend_bo_data *bo_data;
945 _tbm_bufmgr_mutex_lock();
946 _tbm_set_last_result(TBM_ERROR_NONE);
948 TBM_BO_RETURN_VAL_IF_FAIL(TBM_BUFMGR_IS_VALID(bufmgr), NULL);
950 if (!bufmgr->use_hal_tbm) {
951 if (bufmgr->backend_module_data) {
952 if (!bufmgr->bufmgr_func->bufmgr_import_key) {
953 /* LCOV_EXCL_START */
954 _tbm_bufmgr_mutex_unlock();
955 _tbm_set_last_result(TBM_ERROR_NOT_SUPPORTED);
960 if (!bufmgr->backend->bo_import) {
961 /* LCOV_EXCL_START */
962 _tbm_bufmgr_mutex_unlock();
963 _tbm_set_last_result(TBM_ERROR_NOT_SUPPORTED);
970 _tbm_util_check_bo_cnt(bufmgr);
972 bo = calloc(1, sizeof(struct _tbm_bo));
974 /* LCOV_EXCL_START */
975 TBM_ERR("error: fail to import of tbm_bo by key(%d)\n", key);
976 _tbm_set_last_result(TBM_ERROR_OUT_OF_MEMORY);
977 _tbm_bufmgr_mutex_unlock();
982 if (bufmgr->use_hal_tbm) {
983 bo_data = (tbm_backend_bo_data *)hal_tbm_bufmgr_import_key(bufmgr->hal_bufmgr, key, (hal_tbm_error *)&error);
984 /* LCOV_EXCL_START */
986 TBM_ERR("error: fail to import of tbm_bo by key(%d). error(%d)\n", key, error);
987 _tbm_set_last_result(error);
991 if (!LIST_IS_EMPTY(&bufmgr->bo_list)) {
992 LIST_FOR_EACH_ENTRY(bo2, &bufmgr->bo_list, item_link) {
993 if (bo2->bo_data == bo_data) {
994 TBM_TRACE_BO("find bo(%p) ref(%d) key(%d) flag(%s) in list\n",
995 bo2, bo2->ref_cnt, key,
996 _tbm_flag_to_str(bo2->flags));
999 _tbm_bufmgr_mutex_unlock();
1004 bo->bo_data = bo_data;
1005 } else if (bufmgr->backend_module_data) {
1006 bo_data = bufmgr->bufmgr_func->bufmgr_import_key(bufmgr->bufmgr_data, key, &error);
1008 /* LCOV_EXCL_START */
1009 TBM_ERR("error: fail to import of tbm_bo by key(%d). error(%d)\n", key, error);
1010 _tbm_set_last_result(error);
1012 /* LCOV_EXCL_STOP */
1015 if (!LIST_IS_EMPTY(&bufmgr->bo_list)) {
1016 LIST_FOR_EACH_ENTRY(bo2, &bufmgr->bo_list, item_link) {
1017 if (bo2->bo_data == bo_data) {
1018 TBM_TRACE_BO("find bo(%p) ref(%d) key(%d) flag(%s) in list\n",
1019 bo2, bo2->ref_cnt, key,
1020 _tbm_flag_to_str(bo2->flags));
1023 _tbm_bufmgr_mutex_unlock();
1028 bo->bo_data = bo_data;
1030 bo_priv = bufmgr->backend->bo_import(bo, key);
1032 /* LCOV_EXCL_START */
1033 TBM_ERR("error: fail to import of tbm_bo by key(%d)\n", key);
1034 _tbm_set_last_result(TBM_ERROR_INVALID_OPERATION);
1036 /* LCOV_EXCL_STOP */
1039 if (!LIST_IS_EMPTY(&bufmgr->bo_list)) {
1040 LIST_FOR_EACH_ENTRY(bo2, &bufmgr->bo_list, item_link) {
1041 if (bo2->priv == bo_priv) {
1042 TBM_TRACE_BO("find bo(%p) ref(%d) key(%d) flag(%s) in list\n",
1043 bo2, bo2->ref_cnt, key,
1044 _tbm_flag_to_str(bo2->flags));
1047 _tbm_bufmgr_mutex_unlock();
1055 if (bufmgr->use_hal_tbm) {
1056 flags = (tbm_bo_memory_type)hal_tbm_bo_get_memory_types((hal_tbm_bo *)bo->bo_data, (hal_tbm_error *)&error);
1057 if (error != TBM_ERROR_NONE) {
1058 TBM_ERR("fail to get the bo flags(memory_types)");
1059 _tbm_set_last_result(error);
1060 flags = TBM_BO_DEFAULT;
1062 } else if (bufmgr->backend_module_data) {
1063 flags = bufmgr->bo_func->bo_get_memory_types(bo->bo_data, &error);
1064 if (error != TBM_ERROR_NONE) {
1065 TBM_ERR("fail to get the bo flags(memory_types)");
1066 _tbm_set_last_result(error);
1067 flags = TBM_BO_DEFAULT;
1070 if (bufmgr->backend->bo_get_flags)
1071 flags = bufmgr->backend->bo_get_flags(bo);
1073 flags = TBM_BO_DEFAULT;
1076 _tbm_bo_init(bufmgr, bo, flags);
1078 TBM_TRACE_BO("import new bo(%p) ref(%d) key(%d) flag(%s) in list\n",
1079 bo, bo->ref_cnt, key, _tbm_flag_to_str(bo->flags));
1081 _tbm_bufmgr_mutex_unlock();
1087 _tbm_bufmgr_mutex_unlock();
1092 tbm_bo_import_fd(tbm_bufmgr bufmgr, tbm_fd fd)
1097 tbm_backend_bo_data *bo_data;
1101 _tbm_bufmgr_mutex_lock();
1102 _tbm_set_last_result(TBM_ERROR_NONE);
1104 TBM_BO_RETURN_VAL_IF_FAIL(TBM_BUFMGR_IS_VALID(bufmgr), NULL);
1106 if (!bufmgr->use_hal_tbm) {
1107 if (bufmgr->backend_module_data) {
1108 if (!bufmgr->bufmgr_func->bufmgr_import_fd) {
1109 /* LCOV_EXCL_START */
1110 _tbm_bufmgr_mutex_unlock();
1111 _tbm_set_last_result(TBM_ERROR_NOT_SUPPORTED);
1113 /* LCOV_EXCL_STOP */
1116 if (!bufmgr->backend->bo_import_fd) {
1117 /* LCOV_EXCL_START */
1118 _tbm_bufmgr_mutex_unlock();
1119 _tbm_set_last_result(TBM_ERROR_NOT_SUPPORTED);
1121 /* LCOV_EXCL_STOP */
1126 _tbm_util_check_bo_cnt(bufmgr);
1128 bo = calloc(1, sizeof(struct _tbm_bo));
1130 /* LCOV_EXCL_START */
1131 TBM_ERR("error: fail to import tbm_bo by tbm_fd(%d)\n", fd);
1132 _tbm_set_last_result(TBM_ERROR_OUT_OF_MEMORY);
1133 _tbm_bufmgr_mutex_unlock();
1135 /* LCOV_EXCL_STOP */
1138 if (bufmgr->use_hal_tbm) {
1139 bo_data = (tbm_backend_bo_data *)hal_tbm_bufmgr_import_fd(bufmgr->hal_bufmgr, (hal_tbm_fd)fd, (hal_tbm_error *)&error);
1140 /* LCOV_EXCL_START */
1142 TBM_ERR("error: fail to import tbm_bo by tbm_fd(%d). error(%d)\n", fd, error);
1143 _tbm_set_last_result(error);
1146 /* LCOV_EXCL_STOP */
1148 if (!LIST_IS_EMPTY(&bufmgr->bo_list)) {
1149 LIST_FOR_EACH_ENTRY(bo2, &bufmgr->bo_list, item_link) {
1150 if (bo2->bo_data == bo_data) {
1151 TBM_TRACE_BO("find bo(%p) ref(%d) fd(%d) flag(%s) in list\n",
1152 bo2, bo2->ref_cnt, fd, _tbm_flag_to_str(bo2->flags));
1155 _tbm_bufmgr_mutex_unlock();
1160 bo->bo_data = bo_data;
1161 } else if (bufmgr->backend_module_data) {
1162 bo_data = bufmgr->bufmgr_func->bufmgr_import_fd(bufmgr->bufmgr_data, fd, &error);
1164 /* LCOV_EXCL_START */
1165 TBM_ERR("error: fail to import tbm_bo by tbm_fd(%d). error(%d)\n", fd, error);
1166 _tbm_set_last_result(error);
1168 /* LCOV_EXCL_STOP */
1171 if (!LIST_IS_EMPTY(&bufmgr->bo_list)) {
1172 LIST_FOR_EACH_ENTRY(bo2, &bufmgr->bo_list, item_link) {
1173 if (bo2->bo_data == bo_data) {
1174 TBM_TRACE_BO("find bo(%p) ref(%d) fd(%d) flag(%s) in list\n",
1175 bo2, bo2->ref_cnt, fd, _tbm_flag_to_str(bo2->flags));
1178 _tbm_bufmgr_mutex_unlock();
1183 bo->bo_data = bo_data;
1185 bo_priv = bufmgr->backend->bo_import_fd(bo, fd);
1187 /* LCOV_EXCL_START */
1188 TBM_ERR("error: fail to import tbm_bo by tbm_fd(%d)\n", fd);
1189 _tbm_set_last_result(TBM_ERROR_INVALID_OPERATION);
1191 /* LCOV_EXCL_STOP */
1194 if (!LIST_IS_EMPTY(&bufmgr->bo_list)) {
1195 LIST_FOR_EACH_ENTRY(bo2, &bufmgr->bo_list, item_link) {
1196 if (bo2->priv == bo_priv) {
1197 TBM_TRACE_BO("find bo(%p) ref(%d) fd(%d) flag(%s) in list\n",
1198 bo2, bo2->ref_cnt, fd, _tbm_flag_to_str(bo2->flags));
1201 _tbm_bufmgr_mutex_unlock();
1209 if (bufmgr->use_hal_tbm) {
1210 flags = (tbm_bo_memory_type)hal_tbm_bo_get_memory_types((hal_tbm_bo *)bo->bo_data, (hal_tbm_error *)&error);
1211 if (error != TBM_ERROR_NONE) {
1212 TBM_ERR("fail to get the bo flags(memory_types)");
1213 _tbm_set_last_result(error);
1214 flags = TBM_BO_DEFAULT;
1216 } else if (bufmgr->backend_module_data) {
1217 flags = bufmgr->bo_func->bo_get_memory_types(bo->bo_data, &error);
1218 if (error != TBM_ERROR_NONE) {
1219 TBM_ERR("fail to get the bo flags(memory_types)");
1220 _tbm_set_last_result(error);
1221 flags = TBM_BO_DEFAULT;
1224 if (bufmgr->backend->bo_get_flags)
1225 flags = bufmgr->backend->bo_get_flags(bo);
1227 flags = TBM_BO_DEFAULT;
1230 _tbm_bo_init(bufmgr, bo, flags);
1232 TBM_TRACE_BO("import bo(%p) ref(%d) fd(%d) flag(%s)\n",
1233 bo, bo->ref_cnt, fd, _tbm_flag_to_str(bo->flags));
1235 _tbm_bufmgr_mutex_unlock();
1241 _tbm_bufmgr_mutex_unlock();
1246 tbm_bo_size(tbm_bo bo)
1251 _tbm_bufmgr_mutex_lock();
1252 _tbm_set_last_result(TBM_ERROR_NONE);
1254 TBM_BO_RETURN_VAL_IF_FAIL(_tbm_bo_is_valid(bo), 0);
1256 if (bo->bufmgr->use_hal_tbm) {
1257 size = hal_tbm_bo_get_size((hal_tbm_bo *)bo->bo_data, (hal_tbm_error *)&error);
1258 if (error != TBM_ERROR_NONE) {
1259 TBM_ERR("fail to get the size of the bo_data(%d).", error);
1260 _tbm_set_last_result(TBM_ERROR_NONE);
1262 } else if (bo->bufmgr->backend_module_data) {
1263 size = bo->bufmgr->bo_func->bo_get_size(bo->bo_data, &error);
1264 if (error != TBM_ERROR_NONE) {
1265 TBM_ERR("fail to get the size of the bo_data(%d).", error);
1266 _tbm_set_last_result(TBM_ERROR_NONE);
1269 size = bo->bufmgr->backend->bo_size(bo);
1271 TBM_TRACE_BO("bo(%p) size(%d)\n", bo, size);
1273 _tbm_bufmgr_mutex_unlock();
1279 tbm_bo_locked(tbm_bo bo)
1281 _tbm_bufmgr_mutex_lock();
1282 _tbm_set_last_result(TBM_ERROR_NONE);
1284 TBM_BO_RETURN_VAL_IF_FAIL(_tbm_bo_is_valid(bo), 0);
1286 if (bo->bufmgr->bo_lock_type == TBM_BUFMGR_BO_LOCK_TYPE_NEVER) {
1287 TBM_ERR("bo(%p) lock_cnt(%d)\n", bo, bo->lock_cnt);
1288 _tbm_set_last_result(TBM_ERROR_INVALID_OPERATION);
1289 _tbm_bufmgr_mutex_unlock();
1293 if (bo->lock_cnt > 0) {
1294 TBM_TRACE_BO("error: bo(%p) lock_cnt(%d)\n", bo, bo->lock_cnt);
1295 _tbm_bufmgr_mutex_unlock();
1299 TBM_TRACE_BO("bo(%p) lock_cnt(%d)\n", bo, bo->lock_cnt);
1300 _tbm_bufmgr_mutex_unlock();
1306 tbm_bo_swap(tbm_bo bo1, tbm_bo bo2)
1308 tbm_error_e error1, error2;
1309 int size1 = -1, size2 = -2;
1312 _tbm_bufmgr_mutex_lock();
1313 _tbm_set_last_result(TBM_ERROR_NONE);
1315 TBM_BO_RETURN_VAL_IF_FAIL(_tbm_bo_is_valid(bo1), 0);
1316 TBM_BO_RETURN_VAL_IF_FAIL(_tbm_bo_is_valid(bo2), 0);
1318 TBM_TRACE_BO("before: bo1(%p) bo2(%p)\n", bo1, bo2);
1320 if (bo1->bufmgr->use_hal_tbm) {
1321 size1 = hal_tbm_bo_get_size((hal_tbm_bo *)bo1->bo_data, (hal_tbm_error *)&error1);
1322 if (error1 != TBM_ERROR_NONE) {
1323 TBM_ERR("fail to get the size of bo1.(%d)", error1);
1324 _tbm_set_last_result(error1);
1327 size2 = hal_tbm_bo_get_size((hal_tbm_bo *)bo2->bo_data, (hal_tbm_error *)&error2);
1328 if (error2 != TBM_ERROR_NONE) {
1329 TBM_ERR("fail to get the size of bo1.(%d)", error2);
1330 _tbm_set_last_result(error2);
1333 } else if (bo1->bufmgr->backend_module_data) {
1334 size1 = bo1->bufmgr->bo_func->bo_get_size(bo1->bo_data, &error1);
1335 if (error1 != TBM_ERROR_NONE) {
1336 TBM_ERR("fail to get the size of bo1.(%d)", error1);
1337 _tbm_set_last_result(error1);
1340 size2 = bo2->bufmgr->bo_func->bo_get_size(bo2->bo_data, &error2);
1341 if (error2 != TBM_ERROR_NONE) {
1342 TBM_ERR("fail to get the size of bo2.(%d)", error2);
1343 _tbm_set_last_result(error2);
1347 size1 = bo1->bufmgr->backend->bo_size(bo1);
1348 size2 = bo2->bufmgr->backend->bo_size(bo2);
1351 if (size1 != size2) {
1352 TBM_ERR("error: bo1 size(%d) and bo2 size(%d) is different.", size1, size2);
1353 _tbm_set_last_result(TBM_ERROR_INVALID_OPERATION);
1357 TBM_TRACE_BO("after: bo1(%p) bo2(%p)\n", bo1, bo2);
1360 bo1->priv = bo2->priv;
1363 _tbm_bufmgr_mutex_unlock();
1368 TBM_ERR("error: bo1(%p) bo2(%p)\n", bo1, bo2);
1369 _tbm_bufmgr_mutex_unlock();
1375 tbm_bo_add_user_data(tbm_bo bo, unsigned long key,
1376 tbm_data_free data_free_func)
1378 tbm_user_data *data;
1380 _tbm_bufmgr_mutex_lock();
1381 _tbm_set_last_result(TBM_ERROR_NONE);
1383 TBM_BO_RETURN_VAL_IF_FAIL(_tbm_bo_is_valid(bo), 0);
1385 /* check if the data according to the key exist if so, return false. */
1386 data = user_data_lookup(&bo->user_data_list, key);
1388 TBM_TRACE_BO("warning: user data already exist key(%ld)\n", key);
1389 _tbm_set_last_result(TBM_ERROR_INVALID_PARAMETER);
1390 _tbm_bufmgr_mutex_unlock();
1394 data = user_data_create(key, data_free_func);
1396 TBM_ERR("error: bo(%p) key(%lu)\n", bo, key);
1397 _tbm_set_last_result(TBM_ERROR_INVALID_PARAMETER);
1398 _tbm_bufmgr_mutex_unlock();
1402 TBM_TRACE_BO("bo(%p) key(%lu) data(%p)\n", bo, key, data->data);
1404 LIST_ADD(&data->item_link, &bo->user_data_list);
1406 _tbm_bufmgr_mutex_unlock();
1412 tbm_bo_delete_user_data(tbm_bo bo, unsigned long key)
1414 tbm_user_data *old_data;
1416 _tbm_bufmgr_mutex_lock();
1417 _tbm_set_last_result(TBM_ERROR_NONE);
1419 TBM_BO_RETURN_VAL_IF_FAIL(_tbm_bo_is_valid(bo), 0);
1421 if (LIST_IS_EMPTY(&bo->user_data_list)) {
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 old_data = user_data_lookup(&bo->user_data_list, key);
1430 TBM_TRACE_BO("bo(%p) key(%lu)\n", bo, key);
1431 _tbm_set_last_result(TBM_ERROR_INVALID_PARAMETER);
1432 _tbm_bufmgr_mutex_unlock();
1436 TBM_TRACE_BO("bo(%p) key(%lu) data(%p)\n", bo, key, old_data->data);
1438 user_data_delete(old_data);
1440 _tbm_bufmgr_mutex_unlock();
1446 tbm_bo_set_user_data(tbm_bo bo, unsigned long key, void *data)
1448 tbm_user_data *old_data;
1450 _tbm_bufmgr_mutex_lock();
1451 _tbm_set_last_result(TBM_ERROR_NONE);
1453 TBM_BO_RETURN_VAL_IF_FAIL(_tbm_bo_is_valid(bo), 0);
1455 if (LIST_IS_EMPTY(&bo->user_data_list)) {
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 old_data = user_data_lookup(&bo->user_data_list, key);
1464 TBM_TRACE_BO("error: bo(%p) key(%lu)\n", bo, key);
1465 _tbm_set_last_result(TBM_ERROR_INVALID_PARAMETER);
1466 _tbm_bufmgr_mutex_unlock();
1470 if (old_data->data && old_data->free_func)
1471 old_data->free_func(old_data->data);
1472 old_data->data = data;
1474 TBM_TRACE_BO("bo(%p) key(%lu) data(%p)\n", bo, key, old_data->data);
1476 _tbm_bufmgr_mutex_unlock();
1482 tbm_bo_get_user_data(tbm_bo bo, unsigned long key, void **data)
1484 tbm_user_data *old_data;
1486 _tbm_bufmgr_mutex_lock();
1487 _tbm_set_last_result(TBM_ERROR_NONE);
1489 TBM_BO_RETURN_VAL_IF_FAIL(_tbm_bo_is_valid(bo), 0);
1491 if (!data || LIST_IS_EMPTY(&bo->user_data_list)) {
1492 TBM_TRACE_BO("error: bo(%p) key(%lu)\n", bo, key);
1493 _tbm_set_last_result(TBM_ERROR_INVALID_PARAMETER);
1494 _tbm_bufmgr_mutex_unlock();
1498 old_data = user_data_lookup(&bo->user_data_list, key);
1501 TBM_TRACE_BO("error: bo(%p) key(%lu)\n", bo, key);
1502 _tbm_set_last_result(TBM_ERROR_INVALID_PARAMETER);
1503 _tbm_bufmgr_mutex_unlock();
1507 *data = old_data->data;
1509 TBM_TRACE_BO("bo(%p) key(%lu) data(%p)\n", bo, key, old_data->data);
1511 _tbm_bufmgr_mutex_unlock();
1517 tbm_bo_get_flags(tbm_bo bo)
1521 _tbm_bufmgr_mutex_lock();
1523 TBM_BO_RETURN_VAL_IF_FAIL(_tbm_bo_is_valid(bo), 0);
1527 TBM_TRACE_BO("bo(%p)\n", bo);
1529 _tbm_bufmgr_mutex_unlock();
1534 /* LCOV_EXCL_START */
1535 /* internal function */
1537 _tbm_bo_set_surface(tbm_bo bo, tbm_surface_h surface)
1539 _tbm_bufmgr_mutex_lock();
1541 TBM_BO_RETURN_VAL_IF_FAIL(_tbm_bo_is_valid(bo), 0);
1543 bo->surface = surface;
1545 _tbm_bufmgr_mutex_unlock();
1551 _tbm_bo_free(tbm_bo bo)
1553 /* destory the user_data_list */
1554 if (!LIST_IS_EMPTY(&bo->user_data_list)) {
1555 tbm_user_data *old_data = NULL, *tmp;
1557 LIST_FOR_EACH_ENTRY_SAFE(old_data, tmp,
1558 &bo->user_data_list, item_link) {
1559 TBM_DBG("free user_data\n");
1560 user_data_delete(old_data);
1564 while (bo->lock_cnt > 0) {
1565 TBM_ERR("error lock_cnt:%d\n", bo->lock_cnt);
1570 /* call the bo_free */
1571 if (bo->bufmgr->use_hal_tbm) {
1572 hal_tbm_bo_free(bo->bo_data);
1574 } else if (bo->bufmgr->backend_module_data) {
1575 bo->bufmgr->bo_func->bo_free(bo->bo_data);
1578 bo->bufmgr->backend->bo_free(bo);
1586 /* LCOV_EXCL_STOP */