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)
357 tbm_backend_bo_data *bo_data;
360 _tbm_bufmgr_mutex_lock();
361 _tbm_set_last_result(TBM_ERROR_NONE);
363 TBM_BO_RETURN_VAL_IF_FAIL(TBM_BUFMGR_IS_VALID(bufmgr), NULL);
364 TBM_BO_RETURN_VAL_IF_FAIL(size > 0, NULL);
366 bo = calloc(1, sizeof(struct _tbm_bo));
368 /* LCOV_EXCL_START */
369 _tbm_set_last_result(TBM_ERROR_OUT_OF_MEMORY);
370 _tbm_bufmgr_mutex_unlock();
375 _tbm_util_check_bo_cnt(bufmgr);
377 bo_data = tbm_module_bufmgr_bo_alloc(bufmgr->module, bo, size, flags, &error);
378 if (!bo_data || error != TBM_ERROR_NONE) {
379 /* LCOV_EXCL_START */
380 TBM_ERR("tbm_module_bufmgr_bo_alloc failed. error:%d", error);
381 _tbm_set_last_result(error);
385 bo->bo_data = bo_data;
386 bo->priv = (void *)bo_data; // TODO: this will be DEPRECATED.
388 _tbm_bo_init(bufmgr, bo, flags);
390 TBM_TRACE_BO("bo(%p) size(%d) refcnt(%d), flag(%s)\n", bo, size, bo->ref_cnt,
391 _tbm_flag_to_str(bo->flags));
393 _tbm_bufmgr_mutex_unlock();
398 TBM_ERR("error: fail to create of tbm_bo size(%d) flag(%s)\n", size, _tbm_flag_to_str(flags));
400 _tbm_bufmgr_mutex_unlock();
404 /* LCOV_EXCL_START */
406 tbm_bo_alloc_with_format(tbm_bufmgr bufmgr, int format, int bo_idx, int width,
407 int height, int bpp, tbm_bo_memory_type flags, tbm_error_e *error)
411 _tbm_bufmgr_mutex_lock();
412 _tbm_set_last_result(TBM_ERROR_NONE);
414 TBM_BO_RETURN_VAL_IF_FAIL(TBM_BUFMGR_IS_VALID(bufmgr), NULL);
416 bo = calloc(1, sizeof(struct _tbm_bo));
418 /* LCOV_EXCL_START */
419 TBM_ERR("error: fail to tbm_bo_alloc_with_format fmt(%s) idx(%d) w(%d) h(%d) mem_types(%s)\n",
420 FOURCC_STR(format), bo_idx, width, height, _tbm_flag_to_str(flags));
421 _tbm_set_last_result(TBM_ERROR_OUT_OF_MEMORY);
426 _tbm_util_check_bo_cnt(bufmgr);
428 bo->bo_data = tbm_module_bufmgr_bo_alloc_with_format(bufmgr->module, format, bo_idx, width, height, bpp, flags, error);
430 /* LCOV_EXCL_START */
431 TBM_ERR("tbm_module_bufmgr_bo_alloc_with_format failed. fmt:%d idx:%d wxh:%dx%d mem_types:%s\n",
432 format, bo_idx, width, height, _tbm_flag_to_str(flags));
433 _tbm_set_last_result(*error);
438 _tbm_bo_init(bufmgr, bo, flags);
440 _tbm_bufmgr_mutex_unlock();
447 _tbm_bufmgr_mutex_unlock();
453 tbm_bo_alloc_with_tiled_format(tbm_bufmgr bufmgr, int width, int height, int bpp, int format,
454 tbm_bo_memory_type flags, int bo_idx, tbm_error_e *error)
457 tbm_backend_bo_data *bo_data;
459 _tbm_bufmgr_mutex_lock();
460 _tbm_set_last_result(TBM_ERROR_NONE);
462 TBM_BO_RETURN_VAL_IF_FAIL(TBM_BUFMGR_IS_VALID(bufmgr), NULL);
464 bo = calloc(1, sizeof(struct _tbm_bo));
466 TBM_ERR("error: fail to tbm_bo_alloc_with_tiled_format fmt(%s) idx(%d) w(%d) h(%d) flags(%s)\n",
467 FOURCC_STR(format), bo_idx, width, height, _tbm_flag_to_str(flags));
468 _tbm_set_last_result(TBM_ERROR_OUT_OF_MEMORY);
469 _tbm_bufmgr_mutex_unlock();
473 _tbm_util_check_bo_cnt(bufmgr);
475 if (!bufmgr->use_hal_tbm) {
476 if (!bufmgr->backend_module_data || !bufmgr->bufmgr_func->bufmgr_alloc_bo_with_tiled_format) {
477 TBM_ERR("error: not supported tbm_bo_alloc_with_tiled_format\n");
478 _tbm_set_last_result(TBM_ERROR_NOT_SUPPORTED);
483 if (bufmgr->use_hal_tbm) {
485 bo_data = (tbm_backend_bo_data *)hal_tbm_bufmgr_alloc_bo_with_format(bufmgr->hal_bufmgr,
486 width, height, bpp, format, (hal_tbm_bo_memory_type)flags, bo_idx, &ret);
488 *error = (tbm_error_e)ret;
489 if (ret != HAL_TBM_ERROR_NONE) {
490 if (ret != HAL_TBM_ERROR_NOT_SUPPORTED) {
491 TBM_ERR("error: fail to tbm_bo_alloc_with_tiled_format fmt(%s) idx(%d) w(%d) h(%d) flags(%s)\n",
492 FOURCC_STR(format), bo_idx, width, height, _tbm_flag_to_str(flags));
494 _tbm_set_last_result(*error);
498 bo->bo_data = bo_data;
500 bo_data = bufmgr->bufmgr_func->bufmgr_alloc_bo_with_tiled_format(bufmgr->bufmgr_data, width, height,
501 bpp, format, flags, bo_idx, error);
503 TBM_ERR("error: fail to tbm_bo_alloc_with_tiled_format fmt(%s) idx(%d) w(%d) h(%d) flags(%s)\n",
504 FOURCC_STR(format), bo_idx, width, height, _tbm_flag_to_str(flags));
506 _tbm_set_last_result(*error);
509 bo->bo_data = bo_data;
512 _tbm_bo_init(bufmgr, bo, flags);
514 _tbm_bufmgr_mutex_unlock();
520 _tbm_bufmgr_mutex_unlock();
525 tbm_bo_alloc_with_surface(tbm_bufmgr bufmgr, int width, int height, int format, int flags, int bo_idx)
530 _tbm_bufmgr_mutex_lock();
531 _tbm_set_last_result(TBM_ERROR_NONE);
533 TBM_BO_RETURN_VAL_IF_FAIL(TBM_BUFMGR_IS_VALID(bufmgr), NULL);
535 bo = calloc(1, sizeof(struct _tbm_bo));
537 TBM_ERR("error: fail to tbm_bo_alloc_with_surface fmt(%s) idx(%d) w(%d) h(%d) flags(%s)\n",
538 FOURCC_STR(format), bo_idx, width, height, _tbm_flag_to_str(flags));
539 _tbm_set_last_result(TBM_ERROR_OUT_OF_MEMORY);
540 _tbm_bufmgr_mutex_unlock();
544 _tbm_util_check_bo_cnt(bufmgr);
546 if (!bufmgr->backend->surface_bo_alloc) {
547 TBM_ERR("error: not supported tbm_bo_alloc_with_surface\n");
548 _tbm_set_last_result(TBM_ERROR_NOT_SUPPORTED);
550 _tbm_bufmgr_mutex_unlock();
554 bo_priv = bufmgr->backend->surface_bo_alloc(bo, width, height, format, flags, bo_idx);
556 TBM_ERR("error: fail to tbm_bo_alloc_with_surface fmt(%s) idx(%d) w(%d) h(%d) flags(%s)\n",
557 FOURCC_STR(format), bo_idx, width, height, _tbm_flag_to_str(flags));
558 _tbm_set_last_result(TBM_ERROR_INVALID_OPERATION);
560 _tbm_bufmgr_mutex_unlock();
565 _tbm_bo_init(bufmgr, bo, flags);
567 _tbm_bufmgr_mutex_unlock();
573 tbm_bo_alloc_with_bo_data(tbm_bufmgr bufmgr, tbm_backend_bo_data *bo_data, int flags)
575 tbm_bo bo, bo2 = NULL;
577 _tbm_bufmgr_mutex_lock();
578 _tbm_set_last_result(TBM_ERROR_NONE);
580 TBM_BO_RETURN_VAL_IF_FAIL(TBM_BUFMGR_IS_VALID(bufmgr), NULL);
581 TBM_BO_RETURN_VAL_IF_FAIL(bo_data, NULL);
583 // return an existed bo if the bo is already created with the same bo_data.
584 if (!LIST_IS_EMPTY(&bufmgr->bo_list)) {
585 LIST_FOR_EACH_ENTRY(bo2, &bufmgr->bo_list, item_link) {
586 if (bo2->bo_data == bo_data) {
587 TBM_ERR("find bo(%p) ref(%d) flag(%s) in list\n",
588 bo2, bo2->ref_cnt, _tbm_flag_to_str(bo2->flags));
590 _tbm_bufmgr_mutex_unlock();
596 bo = calloc(1, sizeof(struct _tbm_bo));
598 /* LCOV_EXCL_START */
599 _tbm_set_last_result(TBM_ERROR_OUT_OF_MEMORY);
600 _tbm_bufmgr_mutex_unlock();
605 _tbm_util_check_bo_cnt(bufmgr);
607 bo->get_from_hal_surface = 1;
608 bo->bo_data = bo_data;
610 _tbm_bo_init(bufmgr, bo, flags);
612 TBM_TRACE_BO("bo(%p) refcnt(%d), flag(%s)\n", bo, bo->ref_cnt, _tbm_flag_to_str(bo->flags));
614 _tbm_bufmgr_mutex_unlock();
622 tbm_bo_ref(tbm_bo bo)
624 _tbm_bufmgr_mutex_lock();
625 _tbm_set_last_result(TBM_ERROR_NONE);
627 TBM_BO_RETURN_VAL_IF_FAIL(_tbm_bo_is_valid(bo), NULL);
631 TBM_TRACE_BO("bo(%p) ref_cnt(%d)\n", bo, bo->ref_cnt);
633 _tbm_bufmgr_mutex_unlock();
639 tbm_bo_unref(tbm_bo bo)
641 _tbm_bufmgr_mutex_lock();
642 _tbm_set_last_result(TBM_ERROR_NONE);
644 TBM_BO_RETURN_IF_FAIL(_tbm_bo_is_valid(bo));
646 TBM_TRACE_BO("bo(%p) ref_cnt(%d)\n", bo, bo->ref_cnt - 1);
648 if (bo->ref_cnt <= 0) {
649 _tbm_bufmgr_mutex_unlock();
654 if (bo->ref_cnt == 0)
657 _tbm_bufmgr_mutex_unlock();
661 tbm_bo_map(tbm_bo bo, int device, int opt)
663 tbm_bo_handle bo_handle;
666 _tbm_bufmgr_mutex_lock();
667 _tbm_set_last_result(TBM_ERROR_NONE);
669 TBM_BO_RETURN_VAL_IF_FAIL(_tbm_bo_is_valid(bo), (tbm_bo_handle) NULL);
671 if (!_tbm_bo_lock(bo, device, opt)) {
672 TBM_ERR("error: fail to lock bo:%p)\n", bo);
673 _tbm_bufmgr_mutex_unlock();
674 return (tbm_bo_handle) NULL;
677 if (bo->bufmgr->use_hal_tbm) {
678 hal_tbm_bo_handle hbo_handle;
679 hbo_handle = hal_tbm_bo_map((hal_tbm_bo *)bo->bo_data, device, opt, (hal_tbm_error *)&error);
680 if (hbo_handle.ptr == NULL) {
681 /* LCOV_EXCL_START */
682 _tbm_set_last_result(error);
683 TBM_ERR("error: bo(%p) bo_handle(%p) error(%d)\n", bo, hbo_handle.ptr, error);
687 memcpy(&bo_handle.ptr, &hbo_handle.ptr, sizeof(tbm_bo_handle));
688 } else if (bo->bufmgr->backend_module_data) {
689 bo_handle = bo->bufmgr->bo_func->bo_map(bo->bo_data, device, opt, &error);
690 if (bo_handle.ptr == NULL) {
691 /* LCOV_EXCL_START */
692 _tbm_set_last_result(error);
693 TBM_ERR("error: fail to map bo:%p error:%d\n", bo, error);
698 bo_handle = bo->bufmgr->backend->bo_map(bo, device, opt);
699 if (bo_handle.ptr == NULL) {
700 /* LCOV_EXCL_START */
701 _tbm_set_last_result(TBM_ERROR_INVALID_OPERATION);
702 TBM_ERR("error: fail to map bo:%p\n", bo);
708 /* increase the map_count */
711 TBM_TRACE_BO("bo(%p) map_cnt(%d)\n", bo, bo->map_cnt);
713 _tbm_bufmgr_mutex_unlock();
719 _tbm_bufmgr_mutex_unlock();
720 return (tbm_bo_handle) NULL;
724 tbm_bo_unmap(tbm_bo bo)
729 _tbm_bufmgr_mutex_lock();
730 _tbm_set_last_result(TBM_ERROR_NONE);
732 TBM_BO_RETURN_VAL_IF_FAIL(_tbm_bo_is_valid(bo), 0);
733 TBM_BO_RETURN_VAL_IF_FAIL(bo->map_cnt > 0, 0);
735 if (bo->bufmgr->use_hal_tbm) {
736 error = (hal_tbm_error)hal_tbm_bo_unmap((hal_tbm_bo *)bo->bo_data);
737 if (error != TBM_ERROR_NONE) {
738 /* LCOV_EXCL_START */
739 TBM_ERR("error: bo(%p) map_cnt(%d) error(%d)\n", bo, bo->map_cnt, error);
740 _tbm_set_last_result(error);
745 } else if (bo->bufmgr->backend_module_data) {
746 error = bo->bufmgr->bo_func->bo_unmap(bo->bo_data);
747 if (error != TBM_ERROR_NONE) {
748 /* LCOV_EXCL_START */
749 TBM_ERR("error: bo(%p) map_cnt(%d) error(%d)\n", bo, bo->map_cnt, error);
750 _tbm_set_last_result(error);
756 ret = bo->bufmgr->backend->bo_unmap(bo);
758 /* LCOV_EXCL_START */
759 TBM_ERR("error: bo(%p) map_cnt(%d)\n", bo, bo->map_cnt);
760 _tbm_set_last_result(TBM_ERROR_INVALID_OPERATION);
766 /* decrease the map_count */
769 TBM_TRACE_BO("bo(%p) map_cnt(%d)\n", bo, bo->map_cnt);
774 _tbm_bufmgr_mutex_unlock();
780 tbm_bo_get_handle(tbm_bo bo, int device)
782 tbm_bo_handle bo_handle;
785 _tbm_bufmgr_mutex_lock();
786 _tbm_set_last_result(TBM_ERROR_NONE);
788 TBM_BO_RETURN_VAL_IF_FAIL(_tbm_bo_is_valid(bo), (tbm_bo_handle) NULL);
790 if (bo->bufmgr->use_hal_tbm) {
791 hal_tbm_bo_handle hbo_handle;
792 hbo_handle = hal_tbm_bo_get_handle((hal_tbm_bo *)bo->bo_data, device, (hal_tbm_error *)&error);
793 if (hbo_handle.ptr == NULL) {
794 /* LCOV_EXCL_START */
795 TBM_ERR("error: bo(%p) bo_handle(%p) error(%d)\n", bo, hbo_handle.ptr, error);
796 _tbm_set_last_result(error);
800 memcpy(&bo_handle.ptr, &hbo_handle.ptr, sizeof(tbm_bo_handle));
801 } else if (bo->bufmgr->backend_module_data) {
802 bo_handle = bo->bufmgr->bo_func->bo_get_handle(bo->bo_data, device, &error);
803 if (bo_handle.ptr == NULL) {
804 /* LCOV_EXCL_START */
805 TBM_ERR("error: bo(%p) bo_handle(%p) error(%d)\n", bo, bo_handle.ptr, error);
806 _tbm_set_last_result(error);
811 bo_handle = bo->bufmgr->backend->bo_get_handle(bo, device);
812 if (bo_handle.ptr == NULL) {
813 /* LCOV_EXCL_START */
814 TBM_ERR("error: bo(%p) bo_handle(%p)\n", bo, bo_handle.ptr);
815 _tbm_set_last_result(TBM_ERROR_INVALID_OPERATION);
821 TBM_TRACE_BO("bo(%p) bo_handle(%p)\n", bo, bo_handle.ptr);
823 _tbm_bufmgr_mutex_unlock();
828 _tbm_bufmgr_mutex_unlock();
829 return (tbm_bo_handle) NULL;
833 tbm_bo_export(tbm_bo bo)
838 _tbm_bufmgr_mutex_lock();
839 _tbm_set_last_result(TBM_ERROR_NONE);
841 TBM_BO_RETURN_VAL_IF_FAIL(_tbm_bo_is_valid(bo), 0);
843 if (bo->bufmgr->use_hal_tbm) {
844 ret = (hal_tbm_key)hal_tbm_bo_export_key((hal_tbm_bo *)bo->bo_data, (hal_tbm_error *)&error);
846 /* LCOV_EXCL_START */
847 TBM_ERR("error: bo(%p) tbm_key(%d) error(%d)\n", bo, ret, error);
848 _tbm_set_last_result(error);
852 } else if (bo->bufmgr->backend_module_data) {
853 if (!bo->bufmgr->bo_func->bo_export_key) {
854 /* LCOV_EXCL_START */
855 _tbm_bufmgr_mutex_unlock();
856 _tbm_set_last_result(TBM_ERROR_NOT_SUPPORTED);
861 ret = bo->bufmgr->bo_func->bo_export_key(bo->bo_data, &error);
863 /* LCOV_EXCL_START */
864 TBM_ERR("error: bo(%p) tbm_key(%d) error(%d)\n", bo, ret, error);
865 _tbm_set_last_result(error);
870 if (!bo->bufmgr->backend->bo_export) {
871 /* LCOV_EXCL_START */
872 _tbm_bufmgr_mutex_unlock();
873 _tbm_set_last_result(TBM_ERROR_NOT_SUPPORTED);
878 ret = bo->bufmgr->backend->bo_export(bo);
880 /* LCOV_EXCL_START */
881 TBM_ERR("error: bo(%p) tbm_key(%d)\n", bo, ret);
882 _tbm_set_last_result(TBM_ERROR_INVALID_OPERATION);
888 TBM_TRACE_BO("bo(%p) tbm_key(%u)\n", bo, ret);
891 _tbm_bufmgr_mutex_unlock();
897 tbm_bo_export_fd(tbm_bo bo)
902 _tbm_bufmgr_mutex_lock();
903 _tbm_set_last_result(TBM_ERROR_NONE);
905 TBM_BO_RETURN_VAL_IF_FAIL(_tbm_bo_is_valid(bo), -1);
907 if (bo->bufmgr->use_hal_tbm) {
908 ret = (hal_tbm_fd)hal_tbm_bo_export_fd((hal_tbm_bo *)bo->bo_data, (hal_tbm_error *)&error);
910 /* LCOV_EXCL_START */
911 TBM_ERR("error: bo(%p) tbm_fd(%d) error(%d)\n", bo, ret, error);
912 _tbm_set_last_result(error);
916 } else if (bo->bufmgr->backend_module_data) {
917 if (!bo->bufmgr->bo_func->bo_export_fd) {
918 /* LCOV_EXCL_START */
919 _tbm_bufmgr_mutex_unlock();
920 _tbm_set_last_result(TBM_ERROR_NOT_SUPPORTED);
925 ret = bo->bufmgr->bo_func->bo_export_fd(bo->bo_data, &error);
927 /* LCOV_EXCL_START */
928 TBM_ERR("error: bo(%p) tbm_fd(%d) error(%d)\n", bo, ret, error);
929 _tbm_set_last_result(error);
934 if (!bo->bufmgr->backend->bo_export_fd) {
935 /* LCOV_EXCL_START */
936 _tbm_bufmgr_mutex_unlock();
937 _tbm_set_last_result(TBM_ERROR_NOT_SUPPORTED);
942 ret = bo->bufmgr->backend->bo_export_fd(bo);
944 /* LCOV_EXCL_START */
945 TBM_ERR("error: bo(%p) tbm_fd(%d)\n", bo, ret);
946 _tbm_set_last_result(TBM_ERROR_INVALID_OPERATION);
952 TBM_TRACE_BO("bo(%p) tbm_fd(%d)\n", bo, ret);
955 _tbm_bufmgr_mutex_unlock();
961 tbm_bo_import(tbm_bufmgr bufmgr, unsigned int key)
967 tbm_backend_bo_data *bo_data;
970 _tbm_bufmgr_mutex_lock();
971 _tbm_set_last_result(TBM_ERROR_NONE);
973 TBM_BO_RETURN_VAL_IF_FAIL(TBM_BUFMGR_IS_VALID(bufmgr), NULL);
975 if (!bufmgr->use_hal_tbm) {
976 if (bufmgr->backend_module_data) {
977 if (!bufmgr->bufmgr_func->bufmgr_import_key) {
978 /* LCOV_EXCL_START */
979 _tbm_bufmgr_mutex_unlock();
980 _tbm_set_last_result(TBM_ERROR_NOT_SUPPORTED);
985 if (!bufmgr->backend->bo_import) {
986 /* LCOV_EXCL_START */
987 _tbm_bufmgr_mutex_unlock();
988 _tbm_set_last_result(TBM_ERROR_NOT_SUPPORTED);
995 _tbm_util_check_bo_cnt(bufmgr);
997 bo = calloc(1, sizeof(struct _tbm_bo));
999 /* LCOV_EXCL_START */
1000 TBM_ERR("error: fail to import of tbm_bo by key(%d)\n", key);
1001 _tbm_set_last_result(TBM_ERROR_OUT_OF_MEMORY);
1002 _tbm_bufmgr_mutex_unlock();
1004 /* LCOV_EXCL_STOP */
1007 if (bufmgr->use_hal_tbm) {
1008 bo_data = (tbm_backend_bo_data *)hal_tbm_bufmgr_import_key(bufmgr->hal_bufmgr, key, (hal_tbm_error *)&error);
1009 /* LCOV_EXCL_START */
1011 TBM_ERR("error: fail to import of tbm_bo by key(%d). error(%d)\n", key, error);
1012 _tbm_set_last_result(error);
1015 /* LCOV_EXCL_STOP */
1016 if (!LIST_IS_EMPTY(&bufmgr->bo_list)) {
1017 LIST_FOR_EACH_ENTRY(bo2, &bufmgr->bo_list, item_link) {
1018 if (bo2->bo_data == bo_data) {
1019 TBM_TRACE_BO("find bo(%p) ref(%d) key(%d) flag(%s) in list\n",
1020 bo2, bo2->ref_cnt, key,
1021 _tbm_flag_to_str(bo2->flags));
1024 _tbm_bufmgr_mutex_unlock();
1029 bo->bo_data = bo_data;
1030 } else if (bufmgr->backend_module_data) {
1031 bo_data = bufmgr->bufmgr_func->bufmgr_import_key(bufmgr->bufmgr_data, key, &error);
1033 /* LCOV_EXCL_START */
1034 TBM_ERR("error: fail to import of tbm_bo by key(%d). error(%d)\n", key, error);
1035 _tbm_set_last_result(error);
1037 /* LCOV_EXCL_STOP */
1040 if (!LIST_IS_EMPTY(&bufmgr->bo_list)) {
1041 LIST_FOR_EACH_ENTRY(bo2, &bufmgr->bo_list, item_link) {
1042 if (bo2->bo_data == bo_data) {
1043 TBM_TRACE_BO("find bo(%p) ref(%d) key(%d) flag(%s) in list\n",
1044 bo2, bo2->ref_cnt, key,
1045 _tbm_flag_to_str(bo2->flags));
1048 _tbm_bufmgr_mutex_unlock();
1053 bo->bo_data = bo_data;
1055 bo_priv = bufmgr->backend->bo_import(bo, key);
1057 /* LCOV_EXCL_START */
1058 TBM_ERR("error: fail to import of tbm_bo by key(%d)\n", key);
1059 _tbm_set_last_result(TBM_ERROR_INVALID_OPERATION);
1061 /* LCOV_EXCL_STOP */
1064 if (!LIST_IS_EMPTY(&bufmgr->bo_list)) {
1065 LIST_FOR_EACH_ENTRY(bo2, &bufmgr->bo_list, item_link) {
1066 if (bo2->priv == bo_priv) {
1067 TBM_TRACE_BO("find bo(%p) ref(%d) key(%d) flag(%s) in list\n",
1068 bo2, bo2->ref_cnt, key,
1069 _tbm_flag_to_str(bo2->flags));
1072 _tbm_bufmgr_mutex_unlock();
1080 if (bufmgr->use_hal_tbm) {
1081 flags = (tbm_bo_memory_type)hal_tbm_bo_get_memory_types((hal_tbm_bo *)bo->bo_data, (hal_tbm_error *)&error);
1082 if (error != TBM_ERROR_NONE) {
1083 TBM_ERR("fail to get the bo flags(memory_types)");
1084 _tbm_set_last_result(error);
1085 flags = TBM_BO_DEFAULT;
1087 } else if (bufmgr->backend_module_data) {
1088 flags = bufmgr->bo_func->bo_get_memory_types(bo->bo_data, &error);
1089 if (error != TBM_ERROR_NONE) {
1090 TBM_ERR("fail to get the bo flags(memory_types)");
1091 _tbm_set_last_result(error);
1092 flags = TBM_BO_DEFAULT;
1095 if (bufmgr->backend->bo_get_flags)
1096 flags = bufmgr->backend->bo_get_flags(bo);
1098 flags = TBM_BO_DEFAULT;
1101 _tbm_bo_init(bufmgr, bo, flags);
1103 TBM_TRACE_BO("import new bo(%p) ref(%d) key(%d) flag(%s) in list\n",
1104 bo, bo->ref_cnt, key, _tbm_flag_to_str(bo->flags));
1106 _tbm_bufmgr_mutex_unlock();
1112 _tbm_bufmgr_mutex_unlock();
1117 tbm_bo_import_fd(tbm_bufmgr bufmgr, tbm_fd fd)
1122 tbm_backend_bo_data *bo_data;
1126 _tbm_bufmgr_mutex_lock();
1127 _tbm_set_last_result(TBM_ERROR_NONE);
1129 TBM_BO_RETURN_VAL_IF_FAIL(TBM_BUFMGR_IS_VALID(bufmgr), NULL);
1131 if (!bufmgr->use_hal_tbm) {
1132 if (bufmgr->backend_module_data) {
1133 if (!bufmgr->bufmgr_func->bufmgr_import_fd) {
1134 /* LCOV_EXCL_START */
1135 _tbm_bufmgr_mutex_unlock();
1136 _tbm_set_last_result(TBM_ERROR_NOT_SUPPORTED);
1138 /* LCOV_EXCL_STOP */
1141 if (!bufmgr->backend->bo_import_fd) {
1142 /* LCOV_EXCL_START */
1143 _tbm_bufmgr_mutex_unlock();
1144 _tbm_set_last_result(TBM_ERROR_NOT_SUPPORTED);
1146 /* LCOV_EXCL_STOP */
1151 _tbm_util_check_bo_cnt(bufmgr);
1153 bo = calloc(1, sizeof(struct _tbm_bo));
1155 /* LCOV_EXCL_START */
1156 TBM_ERR("error: fail to import tbm_bo by tbm_fd(%d)\n", fd);
1157 _tbm_set_last_result(TBM_ERROR_OUT_OF_MEMORY);
1158 _tbm_bufmgr_mutex_unlock();
1160 /* LCOV_EXCL_STOP */
1163 if (bufmgr->use_hal_tbm) {
1164 bo_data = (tbm_backend_bo_data *)hal_tbm_bufmgr_import_fd(bufmgr->hal_bufmgr, (hal_tbm_fd)fd, (hal_tbm_error *)&error);
1165 /* LCOV_EXCL_START */
1167 TBM_ERR("error: fail to import tbm_bo by tbm_fd(%d). error(%d)\n", fd, error);
1168 _tbm_set_last_result(error);
1171 /* LCOV_EXCL_STOP */
1173 if (!LIST_IS_EMPTY(&bufmgr->bo_list)) {
1174 LIST_FOR_EACH_ENTRY(bo2, &bufmgr->bo_list, item_link) {
1175 if (bo2->bo_data == bo_data) {
1176 TBM_TRACE_BO("find bo(%p) ref(%d) fd(%d) flag(%s) in list\n",
1177 bo2, bo2->ref_cnt, fd, _tbm_flag_to_str(bo2->flags));
1180 _tbm_bufmgr_mutex_unlock();
1185 bo->bo_data = bo_data;
1186 } else if (bufmgr->backend_module_data) {
1187 bo_data = bufmgr->bufmgr_func->bufmgr_import_fd(bufmgr->bufmgr_data, fd, &error);
1189 /* LCOV_EXCL_START */
1190 TBM_ERR("error: fail to import tbm_bo by tbm_fd(%d). error(%d)\n", fd, error);
1191 _tbm_set_last_result(error);
1193 /* LCOV_EXCL_STOP */
1196 if (!LIST_IS_EMPTY(&bufmgr->bo_list)) {
1197 LIST_FOR_EACH_ENTRY(bo2, &bufmgr->bo_list, item_link) {
1198 if (bo2->bo_data == bo_data) {
1199 TBM_TRACE_BO("find bo(%p) ref(%d) fd(%d) flag(%s) in list\n",
1200 bo2, bo2->ref_cnt, fd, _tbm_flag_to_str(bo2->flags));
1203 _tbm_bufmgr_mutex_unlock();
1208 bo->bo_data = bo_data;
1210 bo_priv = bufmgr->backend->bo_import_fd(bo, fd);
1212 /* LCOV_EXCL_START */
1213 TBM_ERR("error: fail to import tbm_bo by tbm_fd(%d)\n", fd);
1214 _tbm_set_last_result(TBM_ERROR_INVALID_OPERATION);
1216 /* LCOV_EXCL_STOP */
1219 if (!LIST_IS_EMPTY(&bufmgr->bo_list)) {
1220 LIST_FOR_EACH_ENTRY(bo2, &bufmgr->bo_list, item_link) {
1221 if (bo2->priv == bo_priv) {
1222 TBM_TRACE_BO("find bo(%p) ref(%d) fd(%d) flag(%s) in list\n",
1223 bo2, bo2->ref_cnt, fd, _tbm_flag_to_str(bo2->flags));
1226 _tbm_bufmgr_mutex_unlock();
1234 if (bufmgr->use_hal_tbm) {
1235 flags = (tbm_bo_memory_type)hal_tbm_bo_get_memory_types((hal_tbm_bo *)bo->bo_data, (hal_tbm_error *)&error);
1236 if (error != TBM_ERROR_NONE) {
1237 TBM_ERR("fail to get the bo flags(memory_types)");
1238 _tbm_set_last_result(error);
1239 flags = TBM_BO_DEFAULT;
1241 } else if (bufmgr->backend_module_data) {
1242 flags = bufmgr->bo_func->bo_get_memory_types(bo->bo_data, &error);
1243 if (error != TBM_ERROR_NONE) {
1244 TBM_ERR("fail to get the bo flags(memory_types)");
1245 _tbm_set_last_result(error);
1246 flags = TBM_BO_DEFAULT;
1249 if (bufmgr->backend->bo_get_flags)
1250 flags = bufmgr->backend->bo_get_flags(bo);
1252 flags = TBM_BO_DEFAULT;
1255 _tbm_bo_init(bufmgr, bo, flags);
1257 TBM_TRACE_BO("import bo(%p) ref(%d) fd(%d) flag(%s)\n",
1258 bo, bo->ref_cnt, fd, _tbm_flag_to_str(bo->flags));
1260 _tbm_bufmgr_mutex_unlock();
1266 _tbm_bufmgr_mutex_unlock();
1271 tbm_bo_size(tbm_bo bo)
1276 _tbm_bufmgr_mutex_lock();
1277 _tbm_set_last_result(TBM_ERROR_NONE);
1279 TBM_BO_RETURN_VAL_IF_FAIL(_tbm_bo_is_valid(bo), 0);
1281 if (bo->bufmgr->use_hal_tbm) {
1282 size = hal_tbm_bo_get_size((hal_tbm_bo *)bo->bo_data, (hal_tbm_error *)&error);
1283 if (error != TBM_ERROR_NONE) {
1284 TBM_ERR("fail to get the size of the bo_data(%d).", error);
1285 _tbm_set_last_result(TBM_ERROR_NONE);
1287 } else if (bo->bufmgr->backend_module_data) {
1288 size = bo->bufmgr->bo_func->bo_get_size(bo->bo_data, &error);
1289 if (error != TBM_ERROR_NONE) {
1290 TBM_ERR("fail to get the size of the bo_data(%d).", error);
1291 _tbm_set_last_result(TBM_ERROR_NONE);
1294 size = bo->bufmgr->backend->bo_size(bo);
1296 TBM_TRACE_BO("bo(%p) size(%d)\n", bo, size);
1298 _tbm_bufmgr_mutex_unlock();
1304 tbm_bo_locked(tbm_bo bo)
1306 _tbm_bufmgr_mutex_lock();
1307 _tbm_set_last_result(TBM_ERROR_NONE);
1309 TBM_BO_RETURN_VAL_IF_FAIL(_tbm_bo_is_valid(bo), 0);
1311 if (bo->bufmgr->bo_lock_type == TBM_BUFMGR_BO_LOCK_TYPE_NEVER) {
1312 TBM_ERR("bo(%p) lock_cnt(%d)\n", bo, bo->lock_cnt);
1313 _tbm_set_last_result(TBM_ERROR_INVALID_OPERATION);
1314 _tbm_bufmgr_mutex_unlock();
1318 if (bo->lock_cnt > 0) {
1319 TBM_TRACE_BO("error: bo(%p) lock_cnt(%d)\n", bo, bo->lock_cnt);
1320 _tbm_bufmgr_mutex_unlock();
1324 TBM_TRACE_BO("bo(%p) lock_cnt(%d)\n", bo, bo->lock_cnt);
1325 _tbm_bufmgr_mutex_unlock();
1331 tbm_bo_swap(tbm_bo bo1, tbm_bo bo2)
1333 tbm_error_e error1, error2;
1334 int size1 = -1, size2 = -2;
1337 _tbm_bufmgr_mutex_lock();
1338 _tbm_set_last_result(TBM_ERROR_NONE);
1340 TBM_BO_RETURN_VAL_IF_FAIL(_tbm_bo_is_valid(bo1), 0);
1341 TBM_BO_RETURN_VAL_IF_FAIL(_tbm_bo_is_valid(bo2), 0);
1343 TBM_TRACE_BO("before: bo1(%p) bo2(%p)\n", bo1, bo2);
1345 if (bo1->bufmgr->use_hal_tbm) {
1346 size1 = hal_tbm_bo_get_size((hal_tbm_bo *)bo1->bo_data, (hal_tbm_error *)&error1);
1347 if (error1 != TBM_ERROR_NONE) {
1348 TBM_ERR("fail to get the size of bo1.(%d)", error1);
1349 _tbm_set_last_result(error1);
1352 size2 = hal_tbm_bo_get_size((hal_tbm_bo *)bo2->bo_data, (hal_tbm_error *)&error2);
1353 if (error2 != TBM_ERROR_NONE) {
1354 TBM_ERR("fail to get the size of bo1.(%d)", error2);
1355 _tbm_set_last_result(error2);
1358 } else if (bo1->bufmgr->backend_module_data) {
1359 size1 = bo1->bufmgr->bo_func->bo_get_size(bo1->bo_data, &error1);
1360 if (error1 != TBM_ERROR_NONE) {
1361 TBM_ERR("fail to get the size of bo1.(%d)", error1);
1362 _tbm_set_last_result(error1);
1365 size2 = bo2->bufmgr->bo_func->bo_get_size(bo2->bo_data, &error2);
1366 if (error2 != TBM_ERROR_NONE) {
1367 TBM_ERR("fail to get the size of bo2.(%d)", error2);
1368 _tbm_set_last_result(error2);
1372 size1 = bo1->bufmgr->backend->bo_size(bo1);
1373 size2 = bo2->bufmgr->backend->bo_size(bo2);
1376 if (size1 != size2) {
1377 TBM_ERR("error: bo1 size(%d) and bo2 size(%d) is different.", size1, size2);
1378 _tbm_set_last_result(TBM_ERROR_INVALID_OPERATION);
1382 TBM_TRACE_BO("after: bo1(%p) bo2(%p)\n", bo1, bo2);
1385 bo1->priv = bo2->priv;
1388 _tbm_bufmgr_mutex_unlock();
1393 TBM_ERR("error: bo1(%p) bo2(%p)\n", bo1, bo2);
1394 _tbm_bufmgr_mutex_unlock();
1400 tbm_bo_add_user_data(tbm_bo bo, unsigned long key,
1401 tbm_data_free data_free_func)
1403 tbm_user_data *data;
1405 _tbm_bufmgr_mutex_lock();
1406 _tbm_set_last_result(TBM_ERROR_NONE);
1408 TBM_BO_RETURN_VAL_IF_FAIL(_tbm_bo_is_valid(bo), 0);
1410 /* check if the data according to the key exist if so, return false. */
1411 data = user_data_lookup(&bo->user_data_list, key);
1413 TBM_TRACE_BO("warning: user data already exist key(%ld)\n", key);
1414 _tbm_set_last_result(TBM_ERROR_INVALID_PARAMETER);
1415 _tbm_bufmgr_mutex_unlock();
1419 data = user_data_create(key, data_free_func);
1421 TBM_ERR("error: bo(%p) key(%lu)\n", bo, key);
1422 _tbm_set_last_result(TBM_ERROR_INVALID_PARAMETER);
1423 _tbm_bufmgr_mutex_unlock();
1427 TBM_TRACE_BO("bo(%p) key(%lu) data(%p)\n", bo, key, data->data);
1429 LIST_ADD(&data->item_link, &bo->user_data_list);
1431 _tbm_bufmgr_mutex_unlock();
1437 tbm_bo_delete_user_data(tbm_bo bo, unsigned long key)
1439 tbm_user_data *old_data;
1441 _tbm_bufmgr_mutex_lock();
1442 _tbm_set_last_result(TBM_ERROR_NONE);
1444 TBM_BO_RETURN_VAL_IF_FAIL(_tbm_bo_is_valid(bo), 0);
1446 if (LIST_IS_EMPTY(&bo->user_data_list)) {
1447 TBM_TRACE_BO("bo(%p) key(%lu)\n", bo, key);
1448 _tbm_set_last_result(TBM_ERROR_INVALID_PARAMETER);
1449 _tbm_bufmgr_mutex_unlock();
1453 old_data = user_data_lookup(&bo->user_data_list, key);
1455 TBM_TRACE_BO("bo(%p) key(%lu)\n", bo, key);
1456 _tbm_set_last_result(TBM_ERROR_INVALID_PARAMETER);
1457 _tbm_bufmgr_mutex_unlock();
1461 TBM_TRACE_BO("bo(%p) key(%lu) data(%p)\n", bo, key, old_data->data);
1463 user_data_delete(old_data);
1465 _tbm_bufmgr_mutex_unlock();
1471 tbm_bo_set_user_data(tbm_bo bo, unsigned long key, void *data)
1473 tbm_user_data *old_data;
1475 _tbm_bufmgr_mutex_lock();
1476 _tbm_set_last_result(TBM_ERROR_NONE);
1478 TBM_BO_RETURN_VAL_IF_FAIL(_tbm_bo_is_valid(bo), 0);
1480 if (LIST_IS_EMPTY(&bo->user_data_list)) {
1481 TBM_TRACE_BO("error: bo(%p) key(%lu)\n", bo, key);
1482 _tbm_set_last_result(TBM_ERROR_INVALID_PARAMETER);
1483 _tbm_bufmgr_mutex_unlock();
1487 old_data = user_data_lookup(&bo->user_data_list, key);
1489 TBM_TRACE_BO("error: bo(%p) key(%lu)\n", bo, key);
1490 _tbm_set_last_result(TBM_ERROR_INVALID_PARAMETER);
1491 _tbm_bufmgr_mutex_unlock();
1495 if (old_data->data && old_data->free_func)
1496 old_data->free_func(old_data->data);
1497 old_data->data = data;
1499 TBM_TRACE_BO("bo(%p) key(%lu) data(%p)\n", bo, key, old_data->data);
1501 _tbm_bufmgr_mutex_unlock();
1507 tbm_bo_get_user_data(tbm_bo bo, unsigned long key, void **data)
1509 tbm_user_data *old_data;
1511 _tbm_bufmgr_mutex_lock();
1512 _tbm_set_last_result(TBM_ERROR_NONE);
1514 TBM_BO_RETURN_VAL_IF_FAIL(_tbm_bo_is_valid(bo), 0);
1516 if (!data || LIST_IS_EMPTY(&bo->user_data_list)) {
1517 TBM_TRACE_BO("error: bo(%p) key(%lu)\n", bo, key);
1518 _tbm_set_last_result(TBM_ERROR_INVALID_PARAMETER);
1519 _tbm_bufmgr_mutex_unlock();
1523 old_data = user_data_lookup(&bo->user_data_list, key);
1526 TBM_TRACE_BO("error: bo(%p) key(%lu)\n", bo, key);
1527 _tbm_set_last_result(TBM_ERROR_INVALID_PARAMETER);
1528 _tbm_bufmgr_mutex_unlock();
1532 *data = old_data->data;
1534 TBM_TRACE_BO("bo(%p) key(%lu) data(%p)\n", bo, key, old_data->data);
1536 _tbm_bufmgr_mutex_unlock();
1542 tbm_bo_get_flags(tbm_bo bo)
1546 _tbm_bufmgr_mutex_lock();
1548 TBM_BO_RETURN_VAL_IF_FAIL(_tbm_bo_is_valid(bo), 0);
1552 TBM_TRACE_BO("bo(%p)\n", bo);
1554 _tbm_bufmgr_mutex_unlock();
1559 /* LCOV_EXCL_START */
1560 /* internal function */
1562 _tbm_bo_set_surface(tbm_bo bo, tbm_surface_h surface)
1564 _tbm_bufmgr_mutex_lock();
1566 TBM_BO_RETURN_VAL_IF_FAIL(_tbm_bo_is_valid(bo), 0);
1568 bo->surface = surface;
1570 _tbm_bufmgr_mutex_unlock();
1576 _tbm_bo_free(tbm_bo bo)
1578 /* destory the user_data_list */
1579 if (!LIST_IS_EMPTY(&bo->user_data_list)) {
1580 tbm_user_data *old_data = NULL, *tmp;
1582 LIST_FOR_EACH_ENTRY_SAFE(old_data, tmp,
1583 &bo->user_data_list, item_link) {
1584 TBM_DBG("free user_data\n");
1585 user_data_delete(old_data);
1589 while (bo->lock_cnt > 0) {
1590 TBM_ERR("error lock_cnt:%d\n", bo->lock_cnt);
1595 /* call the bo_free */
1596 if (bo->bufmgr->use_hal_tbm) {
1597 // call hal_tbm_bo_free when bo is created by tbm_bo_alloc api.
1598 if (!bo->get_from_hal_surface) {
1599 bo->get_from_hal_surface = 0;
1601 hal_tbm_bo_free(bo->bo_data);
1604 } else if (bo->bufmgr->backend_module_data) {
1605 bo->bufmgr->bo_func->bo_free(bo->bo_data);
1608 bo->bufmgr->backend->bo_free(bo);
1616 /* LCOV_EXCL_STOP */