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 bo->allocated_hal_tbm_bo = 1;
388 } else if (bufmgr->backend_module_data) {
389 bo_data = bufmgr->bufmgr_func->bufmgr_alloc_bo(bufmgr->bufmgr_data, (unsigned int)size, flags, &error);
391 /* LCOV_EXCL_START */
392 _tbm_set_last_result(error);
396 bo->bo_data = bo_data;
398 bo_priv = bufmgr->backend->bo_alloc(bo, size, flags);
400 /* LCOV_EXCL_START */
402 _tbm_set_last_result(TBM_ERROR_INVALID_OPERATION);
409 _tbm_bo_init(bufmgr, bo, flags);
411 TBM_TRACE_BO("bo(%p) size(%d) refcnt(%d), flag(%s)\n", bo, size, bo->ref_cnt,
412 _tbm_flag_to_str(bo->flags));
414 _tbm_bufmgr_mutex_unlock();
419 TBM_ERR("error: fail to create of tbm_bo size(%d) flag(%s)\n", size, _tbm_flag_to_str(flags));
421 _tbm_bufmgr_mutex_unlock();
425 /* LCOV_EXCL_START */
427 tbm_bo_alloc_with_format(tbm_bufmgr bufmgr, int format, int bo_idx, int width,
428 int height, int bpp, tbm_bo_memory_type flags, tbm_error_e *error)
431 tbm_backend_bo_data *bo_data;
433 _tbm_bufmgr_mutex_lock();
434 _tbm_set_last_result(TBM_ERROR_NONE);
436 TBM_BO_RETURN_VAL_IF_FAIL(TBM_BUFMGR_IS_VALID(bufmgr), NULL);
438 bo = calloc(1, sizeof(struct _tbm_bo));
440 TBM_ERR("error: fail to tbm_bo_alloc_with_format fmt(%s) idx(%d) w(%d) h(%d) mem_types(%s)\n",
441 FOURCC_STR(format), bo_idx, width, height, _tbm_flag_to_str(flags));
442 _tbm_set_last_result(TBM_ERROR_OUT_OF_MEMORY);
446 _tbm_util_check_bo_cnt(bufmgr);
448 /* LCOV_EXCL_START */
449 if (!bufmgr->use_hal_tbm) {
450 if (!bufmgr->backend_module_data || !bufmgr->bufmgr_func->bufmgr_alloc_bo_with_format) {
452 TBM_ERR("error: not supported tbm_bo_alloc_with_format\n");
453 _tbm_set_last_result(TBM_ERROR_NOT_SUPPORTED);
459 if (bufmgr->use_hal_tbm) {
461 bo_data = (tbm_backend_bo_data *)hal_tbm_bufmgr_alloc_bo_with_format(bufmgr->hal_bufmgr,
462 format, bo_idx, width, height, bpp, (hal_tbm_bo_memory_type)flags, &ret);
464 *error = (tbm_error_e)ret;
465 if (ret != HAL_TBM_ERROR_NONE) {
466 if (ret != HAL_TBM_ERROR_NOT_SUPPORTED) {
467 TBM_ERR("error: fail to tbm_bo_alloc_with_format\n");
469 _tbm_set_last_result(*error);
474 bo_data = bufmgr->bufmgr_func->bufmgr_alloc_bo_with_format(bufmgr->bufmgr_data, format, bo_idx,
475 width, height, flags, error);
477 TBM_ERR("error: fail to tbm_bo_alloc_with_format fmt(%s) idx(%d) w(%d) h(%d) mem_types(%s)\n",
478 FOURCC_STR(format), bo_idx, width, height, _tbm_flag_to_str(flags));
480 _tbm_set_last_result(*error);
485 bo->bo_data = bo_data;
486 _tbm_bo_init(bufmgr, bo, flags);
488 _tbm_bufmgr_mutex_unlock();
495 _tbm_bufmgr_mutex_unlock();
500 tbm_bo_alloc_with_tiled_format(tbm_bufmgr bufmgr, int width, int height, int bpp, int format,
501 tbm_bo_memory_type flags, int bo_idx, tbm_error_e *error)
504 tbm_backend_bo_data *bo_data;
506 _tbm_bufmgr_mutex_lock();
507 _tbm_set_last_result(TBM_ERROR_NONE);
509 TBM_BO_RETURN_VAL_IF_FAIL(TBM_BUFMGR_IS_VALID(bufmgr), NULL);
511 bo = calloc(1, sizeof(struct _tbm_bo));
513 TBM_ERR("error: fail to tbm_bo_alloc_with_tiled_format fmt(%s) idx(%d) w(%d) h(%d) flags(%s)\n",
514 FOURCC_STR(format), bo_idx, width, height, _tbm_flag_to_str(flags));
515 _tbm_set_last_result(TBM_ERROR_OUT_OF_MEMORY);
516 _tbm_bufmgr_mutex_unlock();
520 _tbm_util_check_bo_cnt(bufmgr);
522 if (!bufmgr->use_hal_tbm) {
523 if (!bufmgr->backend_module_data || !bufmgr->bufmgr_func->bufmgr_alloc_bo_with_tiled_format) {
524 TBM_ERR("error: not supported tbm_bo_alloc_with_tiled_format\n");
525 _tbm_set_last_result(TBM_ERROR_NOT_SUPPORTED);
530 if (bufmgr->use_hal_tbm) {
532 bo_data = (tbm_backend_bo_data *)hal_tbm_bufmgr_alloc_bo_with_format(bufmgr->hal_bufmgr,
533 width, height, bpp, format, (hal_tbm_bo_memory_type)flags, bo_idx, &ret);
535 *error = (tbm_error_e)ret;
536 if (ret != HAL_TBM_ERROR_NONE) {
537 if (ret != HAL_TBM_ERROR_NOT_SUPPORTED) {
538 TBM_ERR("error: fail to tbm_bo_alloc_with_tiled_format fmt(%s) idx(%d) w(%d) h(%d) flags(%s)\n",
539 FOURCC_STR(format), bo_idx, width, height, _tbm_flag_to_str(flags));
541 _tbm_set_last_result(*error);
546 bo_data = bufmgr->bufmgr_func->bufmgr_alloc_bo_with_tiled_format(bufmgr->bufmgr_data, width, height,
547 bpp, format, flags, bo_idx, error);
549 TBM_ERR("error: fail to tbm_bo_alloc_with_tiled_format fmt(%s) idx(%d) w(%d) h(%d) flags(%s)\n",
550 FOURCC_STR(format), bo_idx, width, height, _tbm_flag_to_str(flags));
552 _tbm_set_last_result(*error);
557 bo->bo_data = bo_data;
558 _tbm_bo_init(bufmgr, bo, flags);
560 _tbm_bufmgr_mutex_unlock();
566 _tbm_bufmgr_mutex_unlock();
571 tbm_bo_alloc_with_surface(tbm_bufmgr bufmgr, int width, int height, int format, int flags, int bo_idx)
576 _tbm_bufmgr_mutex_lock();
577 _tbm_set_last_result(TBM_ERROR_NONE);
579 TBM_BO_RETURN_VAL_IF_FAIL(TBM_BUFMGR_IS_VALID(bufmgr), NULL);
581 bo = calloc(1, sizeof(struct _tbm_bo));
583 TBM_ERR("error: fail to tbm_bo_alloc_with_surface fmt(%s) idx(%d) w(%d) h(%d) flags(%s)\n",
584 FOURCC_STR(format), bo_idx, width, height, _tbm_flag_to_str(flags));
585 _tbm_set_last_result(TBM_ERROR_OUT_OF_MEMORY);
586 _tbm_bufmgr_mutex_unlock();
590 _tbm_util_check_bo_cnt(bufmgr);
592 if (!bufmgr->backend->surface_bo_alloc) {
593 TBM_ERR("error: not supported tbm_bo_alloc_with_surface\n");
594 _tbm_set_last_result(TBM_ERROR_NOT_SUPPORTED);
596 _tbm_bufmgr_mutex_unlock();
600 bo_priv = bufmgr->backend->surface_bo_alloc(bo, width, height, format, flags, bo_idx);
602 TBM_ERR("error: fail to tbm_bo_alloc_with_surface fmt(%s) idx(%d) w(%d) h(%d) flags(%s)\n",
603 FOURCC_STR(format), bo_idx, width, height, _tbm_flag_to_str(flags));
604 _tbm_set_last_result(TBM_ERROR_INVALID_OPERATION);
606 _tbm_bufmgr_mutex_unlock();
611 _tbm_bo_init(bufmgr, bo, flags);
613 _tbm_bufmgr_mutex_unlock();
619 tbm_bo_alloc_with_bo_data(tbm_bufmgr bufmgr, tbm_backend_bo_data *bo_data, int flags)
623 _tbm_bufmgr_mutex_lock();
624 _tbm_set_last_result(TBM_ERROR_NONE);
626 TBM_BO_RETURN_VAL_IF_FAIL(TBM_BUFMGR_IS_VALID(bufmgr), NULL);
627 TBM_BO_RETURN_VAL_IF_FAIL(bo_data, NULL);
629 bo = calloc(1, sizeof(struct _tbm_bo));
631 /* LCOV_EXCL_START */
632 _tbm_set_last_result(TBM_ERROR_OUT_OF_MEMORY);
633 _tbm_bufmgr_mutex_unlock();
638 _tbm_util_check_bo_cnt(bufmgr);
640 bo->bo_data = bo_data;
642 _tbm_bo_init(bufmgr, bo, flags);
644 TBM_TRACE_BO("bo(%p) refcnt(%d), flag(%s)\n", bo, bo->ref_cnt, _tbm_flag_to_str(bo->flags));
646 _tbm_bufmgr_mutex_unlock();
654 tbm_bo_ref(tbm_bo bo)
656 _tbm_bufmgr_mutex_lock();
657 _tbm_set_last_result(TBM_ERROR_NONE);
659 TBM_BO_RETURN_VAL_IF_FAIL(_tbm_bo_is_valid(bo), NULL);
663 TBM_TRACE_BO("bo(%p) ref_cnt(%d)\n", bo, bo->ref_cnt);
665 _tbm_bufmgr_mutex_unlock();
671 tbm_bo_unref(tbm_bo bo)
673 _tbm_bufmgr_mutex_lock();
674 _tbm_set_last_result(TBM_ERROR_NONE);
676 TBM_BO_RETURN_IF_FAIL(_tbm_bo_is_valid(bo));
678 TBM_TRACE_BO("bo(%p) ref_cnt(%d)\n", bo, bo->ref_cnt - 1);
680 if (bo->ref_cnt <= 0) {
681 _tbm_bufmgr_mutex_unlock();
686 if (bo->ref_cnt == 0)
689 _tbm_bufmgr_mutex_unlock();
693 tbm_bo_map(tbm_bo bo, int device, int opt)
695 tbm_bo_handle bo_handle;
698 _tbm_bufmgr_mutex_lock();
699 _tbm_set_last_result(TBM_ERROR_NONE);
701 TBM_BO_RETURN_VAL_IF_FAIL(_tbm_bo_is_valid(bo), (tbm_bo_handle) NULL);
703 if (!_tbm_bo_lock(bo, device, opt)) {
704 TBM_ERR("error: fail to lock bo:%p)\n", bo);
705 _tbm_bufmgr_mutex_unlock();
706 return (tbm_bo_handle) NULL;
709 if (bo->bufmgr->use_hal_tbm) {
710 hal_tbm_bo_handle hbo_handle;
711 hbo_handle = hal_tbm_bo_map((hal_tbm_bo *)bo->bo_data, device, opt, (hal_tbm_error *)&error);
712 if (hbo_handle.ptr == NULL) {
713 /* LCOV_EXCL_START */
714 _tbm_set_last_result(error);
715 TBM_ERR("error: bo(%p) bo_handle(%p) error(%d)\n", bo, hbo_handle.ptr, error);
719 memcpy(&bo_handle.ptr, &hbo_handle.ptr, sizeof(tbm_bo_handle));
720 } else if (bo->bufmgr->backend_module_data) {
721 bo_handle = bo->bufmgr->bo_func->bo_map(bo->bo_data, device, opt, &error);
722 if (bo_handle.ptr == NULL) {
723 /* LCOV_EXCL_START */
724 _tbm_set_last_result(error);
725 TBM_ERR("error: fail to map bo:%p error:%d\n", bo, error);
730 bo_handle = bo->bufmgr->backend->bo_map(bo, device, opt);
731 if (bo_handle.ptr == NULL) {
732 /* LCOV_EXCL_START */
733 _tbm_set_last_result(TBM_ERROR_INVALID_OPERATION);
734 TBM_ERR("error: fail to map bo:%p\n", bo);
740 /* increase the map_count */
743 TBM_TRACE_BO("bo(%p) map_cnt(%d)\n", bo, bo->map_cnt);
745 _tbm_bufmgr_mutex_unlock();
751 _tbm_bufmgr_mutex_unlock();
752 return (tbm_bo_handle) NULL;
756 tbm_bo_unmap(tbm_bo bo)
761 _tbm_bufmgr_mutex_lock();
762 _tbm_set_last_result(TBM_ERROR_NONE);
764 TBM_BO_RETURN_VAL_IF_FAIL(_tbm_bo_is_valid(bo), 0);
765 TBM_BO_RETURN_VAL_IF_FAIL(bo->map_cnt > 0, 0);
767 if (bo->bufmgr->use_hal_tbm) {
768 error = (hal_tbm_error)hal_tbm_bo_unmap((hal_tbm_bo *)bo->bo_data);
769 if (error != TBM_ERROR_NONE) {
770 /* LCOV_EXCL_START */
771 TBM_ERR("error: bo(%p) map_cnt(%d) error(%d)\n", bo, bo->map_cnt, error);
772 _tbm_set_last_result(error);
777 } else if (bo->bufmgr->backend_module_data) {
778 error = bo->bufmgr->bo_func->bo_unmap(bo->bo_data);
779 if (error != TBM_ERROR_NONE) {
780 /* LCOV_EXCL_START */
781 TBM_ERR("error: bo(%p) map_cnt(%d) error(%d)\n", bo, bo->map_cnt, error);
782 _tbm_set_last_result(error);
788 ret = bo->bufmgr->backend->bo_unmap(bo);
790 /* LCOV_EXCL_START */
791 TBM_ERR("error: bo(%p) map_cnt(%d)\n", bo, bo->map_cnt);
792 _tbm_set_last_result(TBM_ERROR_INVALID_OPERATION);
798 /* decrease the map_count */
801 TBM_TRACE_BO("bo(%p) map_cnt(%d)\n", bo, bo->map_cnt);
806 _tbm_bufmgr_mutex_unlock();
812 tbm_bo_get_handle(tbm_bo bo, int device)
814 tbm_bo_handle bo_handle;
817 _tbm_bufmgr_mutex_lock();
818 _tbm_set_last_result(TBM_ERROR_NONE);
820 TBM_BO_RETURN_VAL_IF_FAIL(_tbm_bo_is_valid(bo), (tbm_bo_handle) NULL);
822 if (bo->bufmgr->use_hal_tbm) {
823 hal_tbm_bo_handle hbo_handle;
824 hbo_handle = hal_tbm_bo_get_handle((hal_tbm_bo *)bo->bo_data, device, (hal_tbm_error *)&error);
825 if (hbo_handle.ptr == NULL) {
826 /* LCOV_EXCL_START */
827 TBM_ERR("error: bo(%p) bo_handle(%p) error(%d)\n", bo, hbo_handle.ptr, error);
828 _tbm_set_last_result(error);
832 memcpy(&bo_handle.ptr, &hbo_handle.ptr, sizeof(tbm_bo_handle));
833 } else if (bo->bufmgr->backend_module_data) {
834 bo_handle = bo->bufmgr->bo_func->bo_get_handle(bo->bo_data, device, &error);
835 if (bo_handle.ptr == NULL) {
836 /* LCOV_EXCL_START */
837 TBM_ERR("error: bo(%p) bo_handle(%p) error(%d)\n", bo, bo_handle.ptr, error);
838 _tbm_set_last_result(error);
843 bo_handle = bo->bufmgr->backend->bo_get_handle(bo, device);
844 if (bo_handle.ptr == NULL) {
845 /* LCOV_EXCL_START */
846 TBM_ERR("error: bo(%p) bo_handle(%p)\n", bo, bo_handle.ptr);
847 _tbm_set_last_result(TBM_ERROR_INVALID_OPERATION);
853 TBM_TRACE_BO("bo(%p) bo_handle(%p)\n", bo, bo_handle.ptr);
855 _tbm_bufmgr_mutex_unlock();
860 _tbm_bufmgr_mutex_unlock();
861 return (tbm_bo_handle) NULL;
865 tbm_bo_export(tbm_bo bo)
870 _tbm_bufmgr_mutex_lock();
871 _tbm_set_last_result(TBM_ERROR_NONE);
873 TBM_BO_RETURN_VAL_IF_FAIL(_tbm_bo_is_valid(bo), 0);
875 if (bo->bufmgr->use_hal_tbm) {
876 ret = (hal_tbm_key)hal_tbm_bo_export_key((hal_tbm_bo *)bo->bo_data, (hal_tbm_error *)&error);
878 /* LCOV_EXCL_START */
879 TBM_ERR("error: bo(%p) tbm_key(%d) error(%d)\n", bo, ret, error);
880 _tbm_set_last_result(error);
884 } else if (bo->bufmgr->backend_module_data) {
885 if (!bo->bufmgr->bo_func->bo_export_key) {
886 /* LCOV_EXCL_START */
887 _tbm_bufmgr_mutex_unlock();
888 _tbm_set_last_result(TBM_ERROR_NOT_SUPPORTED);
893 ret = bo->bufmgr->bo_func->bo_export_key(bo->bo_data, &error);
895 /* LCOV_EXCL_START */
896 TBM_ERR("error: bo(%p) tbm_key(%d) error(%d)\n", bo, ret, error);
897 _tbm_set_last_result(error);
902 if (!bo->bufmgr->backend->bo_export) {
903 /* LCOV_EXCL_START */
904 _tbm_bufmgr_mutex_unlock();
905 _tbm_set_last_result(TBM_ERROR_NOT_SUPPORTED);
910 ret = bo->bufmgr->backend->bo_export(bo);
912 /* LCOV_EXCL_START */
913 TBM_ERR("error: bo(%p) tbm_key(%d)\n", bo, ret);
914 _tbm_set_last_result(TBM_ERROR_INVALID_OPERATION);
920 TBM_TRACE_BO("bo(%p) tbm_key(%u)\n", bo, ret);
923 _tbm_bufmgr_mutex_unlock();
929 tbm_bo_export_fd(tbm_bo bo)
934 _tbm_bufmgr_mutex_lock();
935 _tbm_set_last_result(TBM_ERROR_NONE);
937 TBM_BO_RETURN_VAL_IF_FAIL(_tbm_bo_is_valid(bo), -1);
939 if (bo->bufmgr->use_hal_tbm) {
940 ret = (hal_tbm_fd)hal_tbm_bo_export_fd((hal_tbm_bo *)bo->bo_data, (hal_tbm_error *)&error);
942 /* LCOV_EXCL_START */
943 TBM_ERR("error: bo(%p) tbm_fd(%d) error(%d)\n", bo, ret, error);
944 _tbm_set_last_result(error);
948 } else if (bo->bufmgr->backend_module_data) {
949 if (!bo->bufmgr->bo_func->bo_export_fd) {
950 /* LCOV_EXCL_START */
951 _tbm_bufmgr_mutex_unlock();
952 _tbm_set_last_result(TBM_ERROR_NOT_SUPPORTED);
957 ret = bo->bufmgr->bo_func->bo_export_fd(bo->bo_data, &error);
959 /* LCOV_EXCL_START */
960 TBM_ERR("error: bo(%p) tbm_fd(%d) error(%d)\n", bo, ret, error);
961 _tbm_set_last_result(error);
966 if (!bo->bufmgr->backend->bo_export_fd) {
967 /* LCOV_EXCL_START */
968 _tbm_bufmgr_mutex_unlock();
969 _tbm_set_last_result(TBM_ERROR_NOT_SUPPORTED);
974 ret = bo->bufmgr->backend->bo_export_fd(bo);
976 /* LCOV_EXCL_START */
977 TBM_ERR("error: bo(%p) tbm_fd(%d)\n", bo, ret);
978 _tbm_set_last_result(TBM_ERROR_INVALID_OPERATION);
984 TBM_TRACE_BO("bo(%p) tbm_fd(%d)\n", bo, ret);
987 _tbm_bufmgr_mutex_unlock();
993 tbm_bo_import(tbm_bufmgr bufmgr, unsigned int key)
999 tbm_backend_bo_data *bo_data;
1002 _tbm_bufmgr_mutex_lock();
1003 _tbm_set_last_result(TBM_ERROR_NONE);
1005 TBM_BO_RETURN_VAL_IF_FAIL(TBM_BUFMGR_IS_VALID(bufmgr), NULL);
1007 if (!bufmgr->use_hal_tbm) {
1008 if (bufmgr->backend_module_data) {
1009 if (!bufmgr->bufmgr_func->bufmgr_import_key) {
1010 /* LCOV_EXCL_START */
1011 _tbm_bufmgr_mutex_unlock();
1012 _tbm_set_last_result(TBM_ERROR_NOT_SUPPORTED);
1014 /* LCOV_EXCL_STOP */
1017 if (!bufmgr->backend->bo_import) {
1018 /* LCOV_EXCL_START */
1019 _tbm_bufmgr_mutex_unlock();
1020 _tbm_set_last_result(TBM_ERROR_NOT_SUPPORTED);
1022 /* LCOV_EXCL_STOP */
1027 _tbm_util_check_bo_cnt(bufmgr);
1029 bo = calloc(1, sizeof(struct _tbm_bo));
1031 /* LCOV_EXCL_START */
1032 TBM_ERR("error: fail to import of tbm_bo by key(%d)\n", key);
1033 _tbm_set_last_result(TBM_ERROR_OUT_OF_MEMORY);
1034 _tbm_bufmgr_mutex_unlock();
1036 /* LCOV_EXCL_STOP */
1039 if (bufmgr->use_hal_tbm) {
1040 bo_data = (tbm_backend_bo_data *)hal_tbm_bufmgr_import_key(bufmgr->hal_bufmgr, key, (hal_tbm_error *)&error);
1041 /* LCOV_EXCL_START */
1043 TBM_ERR("error: fail to import of tbm_bo by key(%d). error(%d)\n", key, error);
1044 _tbm_set_last_result(error);
1047 /* LCOV_EXCL_STOP */
1048 if (!LIST_IS_EMPTY(&bufmgr->bo_list)) {
1049 LIST_FOR_EACH_ENTRY(bo2, &bufmgr->bo_list, item_link) {
1050 if (bo2->bo_data == bo_data) {
1051 TBM_TRACE_BO("find bo(%p) ref(%d) key(%d) flag(%s) in list\n",
1052 bo2, bo2->ref_cnt, key,
1053 _tbm_flag_to_str(bo2->flags));
1056 _tbm_bufmgr_mutex_unlock();
1061 bo->bo_data = bo_data;
1062 } else if (bufmgr->backend_module_data) {
1063 bo_data = bufmgr->bufmgr_func->bufmgr_import_key(bufmgr->bufmgr_data, key, &error);
1065 /* LCOV_EXCL_START */
1066 TBM_ERR("error: fail to import of tbm_bo by key(%d). error(%d)\n", key, error);
1067 _tbm_set_last_result(error);
1069 /* LCOV_EXCL_STOP */
1072 if (!LIST_IS_EMPTY(&bufmgr->bo_list)) {
1073 LIST_FOR_EACH_ENTRY(bo2, &bufmgr->bo_list, item_link) {
1074 if (bo2->bo_data == bo_data) {
1075 TBM_TRACE_BO("find bo(%p) ref(%d) key(%d) flag(%s) in list\n",
1076 bo2, bo2->ref_cnt, key,
1077 _tbm_flag_to_str(bo2->flags));
1080 _tbm_bufmgr_mutex_unlock();
1085 bo->bo_data = bo_data;
1087 bo_priv = bufmgr->backend->bo_import(bo, key);
1089 /* LCOV_EXCL_START */
1090 TBM_ERR("error: fail to import of tbm_bo by key(%d)\n", key);
1091 _tbm_set_last_result(TBM_ERROR_INVALID_OPERATION);
1093 /* LCOV_EXCL_STOP */
1096 if (!LIST_IS_EMPTY(&bufmgr->bo_list)) {
1097 LIST_FOR_EACH_ENTRY(bo2, &bufmgr->bo_list, item_link) {
1098 if (bo2->priv == bo_priv) {
1099 TBM_TRACE_BO("find bo(%p) ref(%d) key(%d) flag(%s) in list\n",
1100 bo2, bo2->ref_cnt, key,
1101 _tbm_flag_to_str(bo2->flags));
1104 _tbm_bufmgr_mutex_unlock();
1112 if (bufmgr->use_hal_tbm) {
1113 flags = (tbm_bo_memory_type)hal_tbm_bo_get_memory_types((hal_tbm_bo *)bo->bo_data, (hal_tbm_error *)&error);
1114 if (error != TBM_ERROR_NONE) {
1115 TBM_ERR("fail to get the bo flags(memory_types)");
1116 _tbm_set_last_result(error);
1117 flags = TBM_BO_DEFAULT;
1119 } else if (bufmgr->backend_module_data) {
1120 flags = bufmgr->bo_func->bo_get_memory_types(bo->bo_data, &error);
1121 if (error != TBM_ERROR_NONE) {
1122 TBM_ERR("fail to get the bo flags(memory_types)");
1123 _tbm_set_last_result(error);
1124 flags = TBM_BO_DEFAULT;
1127 if (bufmgr->backend->bo_get_flags)
1128 flags = bufmgr->backend->bo_get_flags(bo);
1130 flags = TBM_BO_DEFAULT;
1133 _tbm_bo_init(bufmgr, bo, flags);
1135 TBM_TRACE_BO("import new bo(%p) ref(%d) key(%d) flag(%s) in list\n",
1136 bo, bo->ref_cnt, key, _tbm_flag_to_str(bo->flags));
1138 _tbm_bufmgr_mutex_unlock();
1144 _tbm_bufmgr_mutex_unlock();
1149 tbm_bo_import_fd(tbm_bufmgr bufmgr, tbm_fd fd)
1154 tbm_backend_bo_data *bo_data;
1158 _tbm_bufmgr_mutex_lock();
1159 _tbm_set_last_result(TBM_ERROR_NONE);
1161 TBM_BO_RETURN_VAL_IF_FAIL(TBM_BUFMGR_IS_VALID(bufmgr), NULL);
1163 if (!bufmgr->use_hal_tbm) {
1164 if (bufmgr->backend_module_data) {
1165 if (!bufmgr->bufmgr_func->bufmgr_import_fd) {
1166 /* LCOV_EXCL_START */
1167 _tbm_bufmgr_mutex_unlock();
1168 _tbm_set_last_result(TBM_ERROR_NOT_SUPPORTED);
1170 /* LCOV_EXCL_STOP */
1173 if (!bufmgr->backend->bo_import_fd) {
1174 /* LCOV_EXCL_START */
1175 _tbm_bufmgr_mutex_unlock();
1176 _tbm_set_last_result(TBM_ERROR_NOT_SUPPORTED);
1178 /* LCOV_EXCL_STOP */
1183 _tbm_util_check_bo_cnt(bufmgr);
1185 bo = calloc(1, sizeof(struct _tbm_bo));
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_OUT_OF_MEMORY);
1190 _tbm_bufmgr_mutex_unlock();
1192 /* LCOV_EXCL_STOP */
1195 if (bufmgr->use_hal_tbm) {
1196 bo_data = (tbm_backend_bo_data *)hal_tbm_bufmgr_import_fd(bufmgr->hal_bufmgr, (hal_tbm_fd)fd, (hal_tbm_error *)&error);
1197 /* LCOV_EXCL_START */
1199 TBM_ERR("error: fail to import tbm_bo by tbm_fd(%d). error(%d)\n", fd, error);
1200 _tbm_set_last_result(error);
1203 /* LCOV_EXCL_STOP */
1205 if (!LIST_IS_EMPTY(&bufmgr->bo_list)) {
1206 LIST_FOR_EACH_ENTRY(bo2, &bufmgr->bo_list, item_link) {
1207 if (bo2->bo_data == bo_data) {
1208 TBM_TRACE_BO("find bo(%p) ref(%d) fd(%d) flag(%s) in list\n",
1209 bo2, bo2->ref_cnt, fd, _tbm_flag_to_str(bo2->flags));
1212 _tbm_bufmgr_mutex_unlock();
1217 bo->bo_data = bo_data;
1218 } else if (bufmgr->backend_module_data) {
1219 bo_data = bufmgr->bufmgr_func->bufmgr_import_fd(bufmgr->bufmgr_data, fd, &error);
1221 /* LCOV_EXCL_START */
1222 TBM_ERR("error: fail to import tbm_bo by tbm_fd(%d). error(%d)\n", fd, error);
1223 _tbm_set_last_result(error);
1225 /* LCOV_EXCL_STOP */
1228 if (!LIST_IS_EMPTY(&bufmgr->bo_list)) {
1229 LIST_FOR_EACH_ENTRY(bo2, &bufmgr->bo_list, item_link) {
1230 if (bo2->bo_data == bo_data) {
1231 TBM_TRACE_BO("find bo(%p) ref(%d) fd(%d) flag(%s) in list\n",
1232 bo2, bo2->ref_cnt, fd, _tbm_flag_to_str(bo2->flags));
1235 _tbm_bufmgr_mutex_unlock();
1240 bo->bo_data = bo_data;
1242 bo_priv = bufmgr->backend->bo_import_fd(bo, fd);
1244 /* LCOV_EXCL_START */
1245 TBM_ERR("error: fail to import tbm_bo by tbm_fd(%d)\n", fd);
1246 _tbm_set_last_result(TBM_ERROR_INVALID_OPERATION);
1248 /* LCOV_EXCL_STOP */
1251 if (!LIST_IS_EMPTY(&bufmgr->bo_list)) {
1252 LIST_FOR_EACH_ENTRY(bo2, &bufmgr->bo_list, item_link) {
1253 if (bo2->priv == bo_priv) {
1254 TBM_TRACE_BO("find bo(%p) ref(%d) fd(%d) flag(%s) in list\n",
1255 bo2, bo2->ref_cnt, fd, _tbm_flag_to_str(bo2->flags));
1258 _tbm_bufmgr_mutex_unlock();
1266 if (bufmgr->use_hal_tbm) {
1267 flags = (tbm_bo_memory_type)hal_tbm_bo_get_memory_types((hal_tbm_bo *)bo->bo_data, (hal_tbm_error *)&error);
1268 if (error != TBM_ERROR_NONE) {
1269 TBM_ERR("fail to get the bo flags(memory_types)");
1270 _tbm_set_last_result(error);
1271 flags = TBM_BO_DEFAULT;
1273 } else if (bufmgr->backend_module_data) {
1274 flags = bufmgr->bo_func->bo_get_memory_types(bo->bo_data, &error);
1275 if (error != TBM_ERROR_NONE) {
1276 TBM_ERR("fail to get the bo flags(memory_types)");
1277 _tbm_set_last_result(error);
1278 flags = TBM_BO_DEFAULT;
1281 if (bufmgr->backend->bo_get_flags)
1282 flags = bufmgr->backend->bo_get_flags(bo);
1284 flags = TBM_BO_DEFAULT;
1287 _tbm_bo_init(bufmgr, bo, flags);
1289 TBM_TRACE_BO("import bo(%p) ref(%d) fd(%d) flag(%s)\n",
1290 bo, bo->ref_cnt, fd, _tbm_flag_to_str(bo->flags));
1292 _tbm_bufmgr_mutex_unlock();
1298 _tbm_bufmgr_mutex_unlock();
1303 tbm_bo_size(tbm_bo bo)
1308 _tbm_bufmgr_mutex_lock();
1309 _tbm_set_last_result(TBM_ERROR_NONE);
1311 TBM_BO_RETURN_VAL_IF_FAIL(_tbm_bo_is_valid(bo), 0);
1313 if (bo->bufmgr->use_hal_tbm) {
1314 size = hal_tbm_bo_get_size((hal_tbm_bo *)bo->bo_data, (hal_tbm_error *)&error);
1315 if (error != TBM_ERROR_NONE) {
1316 TBM_ERR("fail to get the size of the bo_data(%d).", error);
1317 _tbm_set_last_result(TBM_ERROR_NONE);
1319 } else if (bo->bufmgr->backend_module_data) {
1320 size = bo->bufmgr->bo_func->bo_get_size(bo->bo_data, &error);
1321 if (error != TBM_ERROR_NONE) {
1322 TBM_ERR("fail to get the size of the bo_data(%d).", error);
1323 _tbm_set_last_result(TBM_ERROR_NONE);
1326 size = bo->bufmgr->backend->bo_size(bo);
1328 TBM_TRACE_BO("bo(%p) size(%d)\n", bo, size);
1330 _tbm_bufmgr_mutex_unlock();
1336 tbm_bo_locked(tbm_bo bo)
1338 _tbm_bufmgr_mutex_lock();
1339 _tbm_set_last_result(TBM_ERROR_NONE);
1341 TBM_BO_RETURN_VAL_IF_FAIL(_tbm_bo_is_valid(bo), 0);
1343 if (bo->bufmgr->bo_lock_type == TBM_BUFMGR_BO_LOCK_TYPE_NEVER) {
1344 TBM_ERR("bo(%p) lock_cnt(%d)\n", bo, bo->lock_cnt);
1345 _tbm_set_last_result(TBM_ERROR_INVALID_OPERATION);
1346 _tbm_bufmgr_mutex_unlock();
1350 if (bo->lock_cnt > 0) {
1351 TBM_TRACE_BO("error: bo(%p) lock_cnt(%d)\n", bo, bo->lock_cnt);
1352 _tbm_bufmgr_mutex_unlock();
1356 TBM_TRACE_BO("bo(%p) lock_cnt(%d)\n", bo, bo->lock_cnt);
1357 _tbm_bufmgr_mutex_unlock();
1363 tbm_bo_swap(tbm_bo bo1, tbm_bo bo2)
1365 tbm_error_e error1, error2;
1366 int size1 = -1, size2 = -2;
1369 _tbm_bufmgr_mutex_lock();
1370 _tbm_set_last_result(TBM_ERROR_NONE);
1372 TBM_BO_RETURN_VAL_IF_FAIL(_tbm_bo_is_valid(bo1), 0);
1373 TBM_BO_RETURN_VAL_IF_FAIL(_tbm_bo_is_valid(bo2), 0);
1375 TBM_TRACE_BO("before: bo1(%p) bo2(%p)\n", bo1, bo2);
1377 if (bo1->bufmgr->use_hal_tbm) {
1378 size1 = hal_tbm_bo_get_size((hal_tbm_bo *)bo1->bo_data, (hal_tbm_error *)&error1);
1379 if (error1 != TBM_ERROR_NONE) {
1380 TBM_ERR("fail to get the size of bo1.(%d)", error1);
1381 _tbm_set_last_result(error1);
1384 size2 = hal_tbm_bo_get_size((hal_tbm_bo *)bo2->bo_data, (hal_tbm_error *)&error2);
1385 if (error2 != TBM_ERROR_NONE) {
1386 TBM_ERR("fail to get the size of bo1.(%d)", error2);
1387 _tbm_set_last_result(error2);
1390 } else if (bo1->bufmgr->backend_module_data) {
1391 size1 = bo1->bufmgr->bo_func->bo_get_size(bo1->bo_data, &error1);
1392 if (error1 != TBM_ERROR_NONE) {
1393 TBM_ERR("fail to get the size of bo1.(%d)", error1);
1394 _tbm_set_last_result(error1);
1397 size2 = bo2->bufmgr->bo_func->bo_get_size(bo2->bo_data, &error2);
1398 if (error2 != TBM_ERROR_NONE) {
1399 TBM_ERR("fail to get the size of bo2.(%d)", error2);
1400 _tbm_set_last_result(error2);
1404 size1 = bo1->bufmgr->backend->bo_size(bo1);
1405 size2 = bo2->bufmgr->backend->bo_size(bo2);
1408 if (size1 != size2) {
1409 TBM_ERR("error: bo1 size(%d) and bo2 size(%d) is different.", size1, size2);
1410 _tbm_set_last_result(TBM_ERROR_INVALID_OPERATION);
1414 TBM_TRACE_BO("after: bo1(%p) bo2(%p)\n", bo1, bo2);
1417 bo1->priv = bo2->priv;
1420 _tbm_bufmgr_mutex_unlock();
1425 TBM_ERR("error: bo1(%p) bo2(%p)\n", bo1, bo2);
1426 _tbm_bufmgr_mutex_unlock();
1432 tbm_bo_add_user_data(tbm_bo bo, unsigned long key,
1433 tbm_data_free data_free_func)
1435 tbm_user_data *data;
1437 _tbm_bufmgr_mutex_lock();
1438 _tbm_set_last_result(TBM_ERROR_NONE);
1440 TBM_BO_RETURN_VAL_IF_FAIL(_tbm_bo_is_valid(bo), 0);
1442 /* check if the data according to the key exist if so, return false. */
1443 data = user_data_lookup(&bo->user_data_list, key);
1445 TBM_TRACE_BO("warning: user data already exist key(%ld)\n", key);
1446 _tbm_set_last_result(TBM_ERROR_INVALID_PARAMETER);
1447 _tbm_bufmgr_mutex_unlock();
1451 data = user_data_create(key, data_free_func);
1453 TBM_ERR("error: bo(%p) key(%lu)\n", bo, key);
1454 _tbm_set_last_result(TBM_ERROR_INVALID_PARAMETER);
1455 _tbm_bufmgr_mutex_unlock();
1459 TBM_TRACE_BO("bo(%p) key(%lu) data(%p)\n", bo, key, data->data);
1461 LIST_ADD(&data->item_link, &bo->user_data_list);
1463 _tbm_bufmgr_mutex_unlock();
1469 tbm_bo_delete_user_data(tbm_bo bo, unsigned long key)
1471 tbm_user_data *old_data;
1473 _tbm_bufmgr_mutex_lock();
1474 _tbm_set_last_result(TBM_ERROR_NONE);
1476 TBM_BO_RETURN_VAL_IF_FAIL(_tbm_bo_is_valid(bo), 0);
1478 if (LIST_IS_EMPTY(&bo->user_data_list)) {
1479 TBM_TRACE_BO("bo(%p) key(%lu)\n", bo, key);
1480 _tbm_set_last_result(TBM_ERROR_INVALID_PARAMETER);
1481 _tbm_bufmgr_mutex_unlock();
1485 old_data = user_data_lookup(&bo->user_data_list, key);
1487 TBM_TRACE_BO("bo(%p) key(%lu)\n", bo, key);
1488 _tbm_set_last_result(TBM_ERROR_INVALID_PARAMETER);
1489 _tbm_bufmgr_mutex_unlock();
1493 TBM_TRACE_BO("bo(%p) key(%lu) data(%p)\n", bo, key, old_data->data);
1495 user_data_delete(old_data);
1497 _tbm_bufmgr_mutex_unlock();
1503 tbm_bo_set_user_data(tbm_bo bo, unsigned long key, void *data)
1505 tbm_user_data *old_data;
1507 _tbm_bufmgr_mutex_lock();
1508 _tbm_set_last_result(TBM_ERROR_NONE);
1510 TBM_BO_RETURN_VAL_IF_FAIL(_tbm_bo_is_valid(bo), 0);
1512 if (LIST_IS_EMPTY(&bo->user_data_list)) {
1513 TBM_TRACE_BO("error: bo(%p) key(%lu)\n", bo, key);
1514 _tbm_set_last_result(TBM_ERROR_INVALID_PARAMETER);
1515 _tbm_bufmgr_mutex_unlock();
1519 old_data = user_data_lookup(&bo->user_data_list, key);
1521 TBM_TRACE_BO("error: bo(%p) key(%lu)\n", bo, key);
1522 _tbm_set_last_result(TBM_ERROR_INVALID_PARAMETER);
1523 _tbm_bufmgr_mutex_unlock();
1527 if (old_data->data && old_data->free_func)
1528 old_data->free_func(old_data->data);
1529 old_data->data = data;
1531 TBM_TRACE_BO("bo(%p) key(%lu) data(%p)\n", bo, key, old_data->data);
1533 _tbm_bufmgr_mutex_unlock();
1539 tbm_bo_get_user_data(tbm_bo bo, unsigned long key, void **data)
1541 tbm_user_data *old_data;
1543 _tbm_bufmgr_mutex_lock();
1544 _tbm_set_last_result(TBM_ERROR_NONE);
1546 TBM_BO_RETURN_VAL_IF_FAIL(_tbm_bo_is_valid(bo), 0);
1548 if (!data || LIST_IS_EMPTY(&bo->user_data_list)) {
1549 TBM_TRACE_BO("error: bo(%p) key(%lu)\n", bo, key);
1550 _tbm_set_last_result(TBM_ERROR_INVALID_PARAMETER);
1551 _tbm_bufmgr_mutex_unlock();
1555 old_data = user_data_lookup(&bo->user_data_list, key);
1558 TBM_TRACE_BO("error: bo(%p) key(%lu)\n", bo, key);
1559 _tbm_set_last_result(TBM_ERROR_INVALID_PARAMETER);
1560 _tbm_bufmgr_mutex_unlock();
1564 *data = old_data->data;
1566 TBM_TRACE_BO("bo(%p) key(%lu) data(%p)\n", bo, key, old_data->data);
1568 _tbm_bufmgr_mutex_unlock();
1574 tbm_bo_get_flags(tbm_bo bo)
1578 _tbm_bufmgr_mutex_lock();
1580 TBM_BO_RETURN_VAL_IF_FAIL(_tbm_bo_is_valid(bo), 0);
1584 TBM_TRACE_BO("bo(%p)\n", bo);
1586 _tbm_bufmgr_mutex_unlock();
1591 /* LCOV_EXCL_START */
1592 /* internal function */
1594 _tbm_bo_set_surface(tbm_bo bo, tbm_surface_h surface)
1596 _tbm_bufmgr_mutex_lock();
1598 TBM_BO_RETURN_VAL_IF_FAIL(_tbm_bo_is_valid(bo), 0);
1600 bo->surface = surface;
1602 _tbm_bufmgr_mutex_unlock();
1608 _tbm_bo_free(tbm_bo bo)
1610 /* destory the user_data_list */
1611 if (!LIST_IS_EMPTY(&bo->user_data_list)) {
1612 tbm_user_data *old_data = NULL, *tmp;
1614 LIST_FOR_EACH_ENTRY_SAFE(old_data, tmp,
1615 &bo->user_data_list, item_link) {
1616 TBM_DBG("free user_data\n");
1617 user_data_delete(old_data);
1621 while (bo->lock_cnt > 0) {
1622 TBM_ERR("error lock_cnt:%d\n", bo->lock_cnt);
1627 /* call the bo_free */
1628 if (bo->bufmgr->use_hal_tbm) {
1629 // call hal_tbm_bo_free when bo is created by tbm_bo_alloc api.
1630 if (bo->allocated_hal_tbm_bo) {
1631 hal_tbm_bo_free(bo->bo_data);
1633 bo->allocated_hal_tbm_bo = 0;
1635 } else if (bo->bufmgr->backend_module_data) {
1636 bo->bufmgr->bo_func->bo_free(bo->bo_data);
1639 bo->bufmgr->backend->bo_free(bo);
1647 /* LCOV_EXCL_STOP */