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 */
400 _tbm_set_last_result(TBM_ERROR_INVALID_OPERATION);
407 _tbm_bo_init(bufmgr, bo, flags);
409 TBM_TRACE_BO("bo(%p) size(%d) refcnt(%d), flag(%s)\n", bo, size, bo->ref_cnt,
410 _tbm_flag_to_str(bo->flags));
412 _tbm_bufmgr_mutex_unlock();
417 TBM_ERR("error: fail to create of tbm_bo size(%d) flag(%s)\n", size, _tbm_flag_to_str(flags));
419 _tbm_bufmgr_mutex_unlock();
423 /* LCOV_EXCL_START */
425 tbm_bo_alloc_with_format(tbm_bufmgr bufmgr, int format, int bo_idx, int width,
426 int height, int bpp, tbm_bo_memory_type flags, tbm_error_e *error)
429 tbm_backend_bo_data *bo_data;
431 _tbm_bufmgr_mutex_lock();
432 _tbm_set_last_result(TBM_ERROR_NONE);
434 TBM_BO_RETURN_VAL_IF_FAIL(TBM_BUFMGR_IS_VALID(bufmgr), NULL);
436 bo = calloc(1, sizeof(struct _tbm_bo));
438 TBM_ERR("error: fail to tbm_bo_alloc_with_format fmt(%s) idx(%d) w(%d) h(%d) mem_types(%s)\n",
439 FOURCC_STR(format), bo_idx, width, height, _tbm_flag_to_str(flags));
440 _tbm_set_last_result(TBM_ERROR_OUT_OF_MEMORY);
444 _tbm_util_check_bo_cnt(bufmgr);
446 /* LCOV_EXCL_START */
447 if (!bufmgr->use_hal_tbm) {
448 if (!bufmgr->backend_module_data || !bufmgr->bufmgr_func->bufmgr_alloc_bo_with_format) {
449 TBM_ERR("error: not supported tbm_bo_alloc_with_format\n");
450 _tbm_set_last_result(TBM_ERROR_NOT_SUPPORTED);
456 if (bufmgr->use_hal_tbm) {
458 bo_data = (tbm_backend_bo_data *)hal_tbm_bufmgr_alloc_bo_with_format(bufmgr->hal_bufmgr,
459 format, bo_idx, width, height, bpp, (hal_tbm_bo_memory_type)flags, &ret);
461 *error = (tbm_error_e)ret;
462 if (ret != HAL_TBM_ERROR_NONE) {
463 if (ret != HAL_TBM_ERROR_NOT_SUPPORTED) {
464 TBM_ERR("error: fail to tbm_bo_alloc_with_format\n");
466 _tbm_set_last_result(*error);
470 bo->bo_data = bo_data;
472 bo_data = bufmgr->bufmgr_func->bufmgr_alloc_bo_with_format(bufmgr->bufmgr_data, format, bo_idx,
473 width, height, flags, error);
475 TBM_ERR("error: fail to tbm_bo_alloc_with_format fmt(%s) idx(%d) w(%d) h(%d) mem_types(%s)\n",
476 FOURCC_STR(format), bo_idx, width, height, _tbm_flag_to_str(flags));
478 _tbm_set_last_result(*error);
481 bo->bo_data = bo_data;
484 _tbm_bo_init(bufmgr, bo, flags);
486 _tbm_bufmgr_mutex_unlock();
493 _tbm_bufmgr_mutex_unlock();
498 tbm_bo_alloc_with_tiled_format(tbm_bufmgr bufmgr, int width, int height, int bpp, int format,
499 tbm_bo_memory_type flags, int bo_idx, tbm_error_e *error)
502 tbm_backend_bo_data *bo_data;
504 _tbm_bufmgr_mutex_lock();
505 _tbm_set_last_result(TBM_ERROR_NONE);
507 TBM_BO_RETURN_VAL_IF_FAIL(TBM_BUFMGR_IS_VALID(bufmgr), NULL);
509 bo = calloc(1, sizeof(struct _tbm_bo));
511 TBM_ERR("error: fail to tbm_bo_alloc_with_tiled_format fmt(%s) idx(%d) w(%d) h(%d) flags(%s)\n",
512 FOURCC_STR(format), bo_idx, width, height, _tbm_flag_to_str(flags));
513 _tbm_set_last_result(TBM_ERROR_OUT_OF_MEMORY);
514 _tbm_bufmgr_mutex_unlock();
518 _tbm_util_check_bo_cnt(bufmgr);
520 if (!bufmgr->use_hal_tbm) {
521 if (!bufmgr->backend_module_data || !bufmgr->bufmgr_func->bufmgr_alloc_bo_with_tiled_format) {
522 TBM_ERR("error: not supported tbm_bo_alloc_with_tiled_format\n");
523 _tbm_set_last_result(TBM_ERROR_NOT_SUPPORTED);
528 if (bufmgr->use_hal_tbm) {
530 bo_data = (tbm_backend_bo_data *)hal_tbm_bufmgr_alloc_bo_with_format(bufmgr->hal_bufmgr,
531 width, height, bpp, format, (hal_tbm_bo_memory_type)flags, bo_idx, &ret);
533 *error = (tbm_error_e)ret;
534 if (ret != HAL_TBM_ERROR_NONE) {
535 if (ret != HAL_TBM_ERROR_NOT_SUPPORTED) {
536 TBM_ERR("error: fail to tbm_bo_alloc_with_tiled_format fmt(%s) idx(%d) w(%d) h(%d) flags(%s)\n",
537 FOURCC_STR(format), bo_idx, width, height, _tbm_flag_to_str(flags));
539 _tbm_set_last_result(*error);
543 bo->bo_data = bo_data;
545 bo_data = bufmgr->bufmgr_func->bufmgr_alloc_bo_with_tiled_format(bufmgr->bufmgr_data, width, height,
546 bpp, format, flags, bo_idx, error);
548 TBM_ERR("error: fail to tbm_bo_alloc_with_tiled_format fmt(%s) idx(%d) w(%d) h(%d) flags(%s)\n",
549 FOURCC_STR(format), bo_idx, width, height, _tbm_flag_to_str(flags));
551 _tbm_set_last_result(*error);
554 bo->bo_data = bo_data;
557 _tbm_bo_init(bufmgr, bo, flags);
559 _tbm_bufmgr_mutex_unlock();
565 _tbm_bufmgr_mutex_unlock();
570 tbm_bo_alloc_with_surface(tbm_bufmgr bufmgr, int width, int height, int format, int flags, int bo_idx)
575 _tbm_bufmgr_mutex_lock();
576 _tbm_set_last_result(TBM_ERROR_NONE);
578 TBM_BO_RETURN_VAL_IF_FAIL(TBM_BUFMGR_IS_VALID(bufmgr), NULL);
580 bo = calloc(1, sizeof(struct _tbm_bo));
582 TBM_ERR("error: fail to tbm_bo_alloc_with_surface fmt(%s) idx(%d) w(%d) h(%d) flags(%s)\n",
583 FOURCC_STR(format), bo_idx, width, height, _tbm_flag_to_str(flags));
584 _tbm_set_last_result(TBM_ERROR_OUT_OF_MEMORY);
585 _tbm_bufmgr_mutex_unlock();
589 _tbm_util_check_bo_cnt(bufmgr);
591 if (!bufmgr->backend->surface_bo_alloc) {
592 TBM_ERR("error: not supported tbm_bo_alloc_with_surface\n");
593 _tbm_set_last_result(TBM_ERROR_NOT_SUPPORTED);
595 _tbm_bufmgr_mutex_unlock();
599 bo_priv = bufmgr->backend->surface_bo_alloc(bo, width, height, format, flags, bo_idx);
601 TBM_ERR("error: fail to tbm_bo_alloc_with_surface fmt(%s) idx(%d) w(%d) h(%d) flags(%s)\n",
602 FOURCC_STR(format), bo_idx, width, height, _tbm_flag_to_str(flags));
603 _tbm_set_last_result(TBM_ERROR_INVALID_OPERATION);
605 _tbm_bufmgr_mutex_unlock();
610 _tbm_bo_init(bufmgr, bo, flags);
612 _tbm_bufmgr_mutex_unlock();
618 tbm_bo_alloc_with_bo_data(tbm_bufmgr bufmgr, tbm_backend_bo_data *bo_data, int flags)
620 tbm_bo bo, bo2 = NULL;
622 _tbm_bufmgr_mutex_lock();
623 _tbm_set_last_result(TBM_ERROR_NONE);
625 TBM_BO_RETURN_VAL_IF_FAIL(TBM_BUFMGR_IS_VALID(bufmgr), NULL);
626 TBM_BO_RETURN_VAL_IF_FAIL(bo_data, NULL);
628 // return an existed bo if the bo is already created with the same bo_data.
629 if (!LIST_IS_EMPTY(&bufmgr->bo_list)) {
630 LIST_FOR_EACH_ENTRY(bo2, &bufmgr->bo_list, item_link) {
631 if (bo2->bo_data == bo_data) {
632 TBM_ERR("find bo(%p) ref(%d) flag(%s) in list\n",
633 bo2, bo2->ref_cnt, _tbm_flag_to_str(bo2->flags));
635 _tbm_bufmgr_mutex_unlock();
641 bo = calloc(1, sizeof(struct _tbm_bo));
643 /* LCOV_EXCL_START */
644 _tbm_set_last_result(TBM_ERROR_OUT_OF_MEMORY);
645 _tbm_bufmgr_mutex_unlock();
650 _tbm_util_check_bo_cnt(bufmgr);
652 bo->get_from_hal_surface = 1;
653 bo->bo_data = bo_data;
655 _tbm_bo_init(bufmgr, bo, flags);
657 TBM_TRACE_BO("bo(%p) refcnt(%d), flag(%s)\n", bo, bo->ref_cnt, _tbm_flag_to_str(bo->flags));
659 _tbm_bufmgr_mutex_unlock();
667 tbm_bo_ref(tbm_bo bo)
669 _tbm_bufmgr_mutex_lock();
670 _tbm_set_last_result(TBM_ERROR_NONE);
672 TBM_BO_RETURN_VAL_IF_FAIL(_tbm_bo_is_valid(bo), NULL);
676 TBM_TRACE_BO("bo(%p) ref_cnt(%d)\n", bo, bo->ref_cnt);
678 _tbm_bufmgr_mutex_unlock();
684 tbm_bo_unref(tbm_bo bo)
686 _tbm_bufmgr_mutex_lock();
687 _tbm_set_last_result(TBM_ERROR_NONE);
689 TBM_BO_RETURN_IF_FAIL(_tbm_bo_is_valid(bo));
691 TBM_TRACE_BO("bo(%p) ref_cnt(%d)\n", bo, bo->ref_cnt - 1);
693 if (bo->ref_cnt <= 0) {
694 _tbm_bufmgr_mutex_unlock();
699 if (bo->ref_cnt == 0)
702 _tbm_bufmgr_mutex_unlock();
706 tbm_bo_map(tbm_bo bo, int device, int opt)
708 tbm_bo_handle bo_handle;
711 _tbm_bufmgr_mutex_lock();
712 _tbm_set_last_result(TBM_ERROR_NONE);
714 TBM_BO_RETURN_VAL_IF_FAIL(_tbm_bo_is_valid(bo), (tbm_bo_handle) NULL);
716 if (!_tbm_bo_lock(bo, device, opt)) {
717 TBM_ERR("error: fail to lock bo:%p)\n", bo);
718 _tbm_bufmgr_mutex_unlock();
719 return (tbm_bo_handle) NULL;
722 if (bo->bufmgr->use_hal_tbm) {
723 hal_tbm_bo_handle hbo_handle;
724 hbo_handle = hal_tbm_bo_map((hal_tbm_bo *)bo->bo_data, device, opt, (hal_tbm_error *)&error);
725 if (hbo_handle.ptr == NULL) {
726 /* LCOV_EXCL_START */
727 _tbm_set_last_result(error);
728 TBM_ERR("error: bo(%p) bo_handle(%p) error(%d)\n", bo, hbo_handle.ptr, error);
732 memcpy(&bo_handle.ptr, &hbo_handle.ptr, sizeof(tbm_bo_handle));
733 } else if (bo->bufmgr->backend_module_data) {
734 bo_handle = bo->bufmgr->bo_func->bo_map(bo->bo_data, device, opt, &error);
735 if (bo_handle.ptr == NULL) {
736 /* LCOV_EXCL_START */
737 _tbm_set_last_result(error);
738 TBM_ERR("error: fail to map bo:%p error:%d\n", bo, error);
743 bo_handle = bo->bufmgr->backend->bo_map(bo, device, opt);
744 if (bo_handle.ptr == NULL) {
745 /* LCOV_EXCL_START */
746 _tbm_set_last_result(TBM_ERROR_INVALID_OPERATION);
747 TBM_ERR("error: fail to map bo:%p\n", bo);
753 /* increase the map_count */
756 TBM_TRACE_BO("bo(%p) map_cnt(%d)\n", bo, bo->map_cnt);
758 _tbm_bufmgr_mutex_unlock();
764 _tbm_bufmgr_mutex_unlock();
765 return (tbm_bo_handle) NULL;
769 tbm_bo_unmap(tbm_bo bo)
774 _tbm_bufmgr_mutex_lock();
775 _tbm_set_last_result(TBM_ERROR_NONE);
777 TBM_BO_RETURN_VAL_IF_FAIL(_tbm_bo_is_valid(bo), 0);
778 TBM_BO_RETURN_VAL_IF_FAIL(bo->map_cnt > 0, 0);
780 if (bo->bufmgr->use_hal_tbm) {
781 error = (hal_tbm_error)hal_tbm_bo_unmap((hal_tbm_bo *)bo->bo_data);
782 if (error != TBM_ERROR_NONE) {
783 /* LCOV_EXCL_START */
784 TBM_ERR("error: bo(%p) map_cnt(%d) error(%d)\n", bo, bo->map_cnt, error);
785 _tbm_set_last_result(error);
790 } else if (bo->bufmgr->backend_module_data) {
791 error = bo->bufmgr->bo_func->bo_unmap(bo->bo_data);
792 if (error != TBM_ERROR_NONE) {
793 /* LCOV_EXCL_START */
794 TBM_ERR("error: bo(%p) map_cnt(%d) error(%d)\n", bo, bo->map_cnt, error);
795 _tbm_set_last_result(error);
801 ret = bo->bufmgr->backend->bo_unmap(bo);
803 /* LCOV_EXCL_START */
804 TBM_ERR("error: bo(%p) map_cnt(%d)\n", bo, bo->map_cnt);
805 _tbm_set_last_result(TBM_ERROR_INVALID_OPERATION);
811 /* decrease the map_count */
814 TBM_TRACE_BO("bo(%p) map_cnt(%d)\n", bo, bo->map_cnt);
819 _tbm_bufmgr_mutex_unlock();
825 tbm_bo_get_handle(tbm_bo bo, int device)
827 tbm_bo_handle bo_handle;
830 _tbm_bufmgr_mutex_lock();
831 _tbm_set_last_result(TBM_ERROR_NONE);
833 TBM_BO_RETURN_VAL_IF_FAIL(_tbm_bo_is_valid(bo), (tbm_bo_handle) NULL);
835 if (bo->bufmgr->use_hal_tbm) {
836 hal_tbm_bo_handle hbo_handle;
837 hbo_handle = hal_tbm_bo_get_handle((hal_tbm_bo *)bo->bo_data, device, (hal_tbm_error *)&error);
838 if (hbo_handle.ptr == NULL) {
839 /* LCOV_EXCL_START */
840 TBM_ERR("error: bo(%p) bo_handle(%p) error(%d)\n", bo, hbo_handle.ptr, error);
841 _tbm_set_last_result(error);
845 memcpy(&bo_handle.ptr, &hbo_handle.ptr, sizeof(tbm_bo_handle));
846 } else if (bo->bufmgr->backend_module_data) {
847 bo_handle = bo->bufmgr->bo_func->bo_get_handle(bo->bo_data, device, &error);
848 if (bo_handle.ptr == NULL) {
849 /* LCOV_EXCL_START */
850 TBM_ERR("error: bo(%p) bo_handle(%p) error(%d)\n", bo, bo_handle.ptr, error);
851 _tbm_set_last_result(error);
856 bo_handle = bo->bufmgr->backend->bo_get_handle(bo, device);
857 if (bo_handle.ptr == NULL) {
858 /* LCOV_EXCL_START */
859 TBM_ERR("error: bo(%p) bo_handle(%p)\n", bo, bo_handle.ptr);
860 _tbm_set_last_result(TBM_ERROR_INVALID_OPERATION);
866 TBM_TRACE_BO("bo(%p) bo_handle(%p)\n", bo, bo_handle.ptr);
868 _tbm_bufmgr_mutex_unlock();
873 _tbm_bufmgr_mutex_unlock();
874 return (tbm_bo_handle) NULL;
878 tbm_bo_export(tbm_bo bo)
883 _tbm_bufmgr_mutex_lock();
884 _tbm_set_last_result(TBM_ERROR_NONE);
886 TBM_BO_RETURN_VAL_IF_FAIL(_tbm_bo_is_valid(bo), 0);
888 if (bo->bufmgr->use_hal_tbm) {
889 ret = (hal_tbm_key)hal_tbm_bo_export_key((hal_tbm_bo *)bo->bo_data, (hal_tbm_error *)&error);
891 /* LCOV_EXCL_START */
892 TBM_ERR("error: bo(%p) tbm_key(%d) error(%d)\n", bo, ret, error);
893 _tbm_set_last_result(error);
897 } else if (bo->bufmgr->backend_module_data) {
898 if (!bo->bufmgr->bo_func->bo_export_key) {
899 /* LCOV_EXCL_START */
900 _tbm_bufmgr_mutex_unlock();
901 _tbm_set_last_result(TBM_ERROR_NOT_SUPPORTED);
906 ret = bo->bufmgr->bo_func->bo_export_key(bo->bo_data, &error);
908 /* LCOV_EXCL_START */
909 TBM_ERR("error: bo(%p) tbm_key(%d) error(%d)\n", bo, ret, error);
910 _tbm_set_last_result(error);
915 if (!bo->bufmgr->backend->bo_export) {
916 /* LCOV_EXCL_START */
917 _tbm_bufmgr_mutex_unlock();
918 _tbm_set_last_result(TBM_ERROR_NOT_SUPPORTED);
923 ret = bo->bufmgr->backend->bo_export(bo);
925 /* LCOV_EXCL_START */
926 TBM_ERR("error: bo(%p) tbm_key(%d)\n", bo, ret);
927 _tbm_set_last_result(TBM_ERROR_INVALID_OPERATION);
933 TBM_TRACE_BO("bo(%p) tbm_key(%u)\n", bo, ret);
936 _tbm_bufmgr_mutex_unlock();
942 tbm_bo_export_fd(tbm_bo bo)
947 _tbm_bufmgr_mutex_lock();
948 _tbm_set_last_result(TBM_ERROR_NONE);
950 TBM_BO_RETURN_VAL_IF_FAIL(_tbm_bo_is_valid(bo), -1);
952 if (bo->bufmgr->use_hal_tbm) {
953 ret = (hal_tbm_fd)hal_tbm_bo_export_fd((hal_tbm_bo *)bo->bo_data, (hal_tbm_error *)&error);
955 /* LCOV_EXCL_START */
956 TBM_ERR("error: bo(%p) tbm_fd(%d) error(%d)\n", bo, ret, error);
957 _tbm_set_last_result(error);
961 } else if (bo->bufmgr->backend_module_data) {
962 if (!bo->bufmgr->bo_func->bo_export_fd) {
963 /* LCOV_EXCL_START */
964 _tbm_bufmgr_mutex_unlock();
965 _tbm_set_last_result(TBM_ERROR_NOT_SUPPORTED);
970 ret = bo->bufmgr->bo_func->bo_export_fd(bo->bo_data, &error);
972 /* LCOV_EXCL_START */
973 TBM_ERR("error: bo(%p) tbm_fd(%d) error(%d)\n", bo, ret, error);
974 _tbm_set_last_result(error);
979 if (!bo->bufmgr->backend->bo_export_fd) {
980 /* LCOV_EXCL_START */
981 _tbm_bufmgr_mutex_unlock();
982 _tbm_set_last_result(TBM_ERROR_NOT_SUPPORTED);
987 ret = bo->bufmgr->backend->bo_export_fd(bo);
989 /* LCOV_EXCL_START */
990 TBM_ERR("error: bo(%p) tbm_fd(%d)\n", bo, ret);
991 _tbm_set_last_result(TBM_ERROR_INVALID_OPERATION);
997 TBM_TRACE_BO("bo(%p) tbm_fd(%d)\n", bo, ret);
1000 _tbm_bufmgr_mutex_unlock();
1006 tbm_bo_import(tbm_bufmgr bufmgr, unsigned int key)
1012 tbm_backend_bo_data *bo_data;
1015 _tbm_bufmgr_mutex_lock();
1016 _tbm_set_last_result(TBM_ERROR_NONE);
1018 TBM_BO_RETURN_VAL_IF_FAIL(TBM_BUFMGR_IS_VALID(bufmgr), NULL);
1020 if (!bufmgr->use_hal_tbm) {
1021 if (bufmgr->backend_module_data) {
1022 if (!bufmgr->bufmgr_func->bufmgr_import_key) {
1023 /* LCOV_EXCL_START */
1024 _tbm_bufmgr_mutex_unlock();
1025 _tbm_set_last_result(TBM_ERROR_NOT_SUPPORTED);
1027 /* LCOV_EXCL_STOP */
1030 if (!bufmgr->backend->bo_import) {
1031 /* LCOV_EXCL_START */
1032 _tbm_bufmgr_mutex_unlock();
1033 _tbm_set_last_result(TBM_ERROR_NOT_SUPPORTED);
1035 /* LCOV_EXCL_STOP */
1040 _tbm_util_check_bo_cnt(bufmgr);
1042 bo = calloc(1, sizeof(struct _tbm_bo));
1044 /* LCOV_EXCL_START */
1045 TBM_ERR("error: fail to import of tbm_bo by key(%d)\n", key);
1046 _tbm_set_last_result(TBM_ERROR_OUT_OF_MEMORY);
1047 _tbm_bufmgr_mutex_unlock();
1049 /* LCOV_EXCL_STOP */
1052 if (bufmgr->use_hal_tbm) {
1053 bo_data = (tbm_backend_bo_data *)hal_tbm_bufmgr_import_key(bufmgr->hal_bufmgr, key, (hal_tbm_error *)&error);
1054 /* LCOV_EXCL_START */
1056 TBM_ERR("error: fail to import of tbm_bo by key(%d). error(%d)\n", key, error);
1057 _tbm_set_last_result(error);
1060 /* LCOV_EXCL_STOP */
1061 if (!LIST_IS_EMPTY(&bufmgr->bo_list)) {
1062 LIST_FOR_EACH_ENTRY(bo2, &bufmgr->bo_list, item_link) {
1063 if (bo2->bo_data == bo_data) {
1064 TBM_TRACE_BO("find bo(%p) ref(%d) key(%d) flag(%s) in list\n",
1065 bo2, bo2->ref_cnt, key,
1066 _tbm_flag_to_str(bo2->flags));
1069 _tbm_bufmgr_mutex_unlock();
1074 bo->bo_data = bo_data;
1075 } else if (bufmgr->backend_module_data) {
1076 bo_data = bufmgr->bufmgr_func->bufmgr_import_key(bufmgr->bufmgr_data, key, &error);
1078 /* LCOV_EXCL_START */
1079 TBM_ERR("error: fail to import of tbm_bo by key(%d). error(%d)\n", key, error);
1080 _tbm_set_last_result(error);
1082 /* LCOV_EXCL_STOP */
1085 if (!LIST_IS_EMPTY(&bufmgr->bo_list)) {
1086 LIST_FOR_EACH_ENTRY(bo2, &bufmgr->bo_list, item_link) {
1087 if (bo2->bo_data == bo_data) {
1088 TBM_TRACE_BO("find bo(%p) ref(%d) key(%d) flag(%s) in list\n",
1089 bo2, bo2->ref_cnt, key,
1090 _tbm_flag_to_str(bo2->flags));
1093 _tbm_bufmgr_mutex_unlock();
1098 bo->bo_data = bo_data;
1100 bo_priv = bufmgr->backend->bo_import(bo, key);
1102 /* LCOV_EXCL_START */
1103 TBM_ERR("error: fail to import of tbm_bo by key(%d)\n", key);
1104 _tbm_set_last_result(TBM_ERROR_INVALID_OPERATION);
1106 /* LCOV_EXCL_STOP */
1109 if (!LIST_IS_EMPTY(&bufmgr->bo_list)) {
1110 LIST_FOR_EACH_ENTRY(bo2, &bufmgr->bo_list, item_link) {
1111 if (bo2->priv == bo_priv) {
1112 TBM_TRACE_BO("find bo(%p) ref(%d) key(%d) flag(%s) in list\n",
1113 bo2, bo2->ref_cnt, key,
1114 _tbm_flag_to_str(bo2->flags));
1117 _tbm_bufmgr_mutex_unlock();
1125 if (bufmgr->use_hal_tbm) {
1126 flags = (tbm_bo_memory_type)hal_tbm_bo_get_memory_types((hal_tbm_bo *)bo->bo_data, (hal_tbm_error *)&error);
1127 if (error != TBM_ERROR_NONE) {
1128 TBM_ERR("fail to get the bo flags(memory_types)");
1129 _tbm_set_last_result(error);
1130 flags = TBM_BO_DEFAULT;
1132 } else if (bufmgr->backend_module_data) {
1133 flags = bufmgr->bo_func->bo_get_memory_types(bo->bo_data, &error);
1134 if (error != TBM_ERROR_NONE) {
1135 TBM_ERR("fail to get the bo flags(memory_types)");
1136 _tbm_set_last_result(error);
1137 flags = TBM_BO_DEFAULT;
1140 if (bufmgr->backend->bo_get_flags)
1141 flags = bufmgr->backend->bo_get_flags(bo);
1143 flags = TBM_BO_DEFAULT;
1146 _tbm_bo_init(bufmgr, bo, flags);
1148 TBM_TRACE_BO("import new bo(%p) ref(%d) key(%d) flag(%s) in list\n",
1149 bo, bo->ref_cnt, key, _tbm_flag_to_str(bo->flags));
1151 _tbm_bufmgr_mutex_unlock();
1157 _tbm_bufmgr_mutex_unlock();
1162 tbm_bo_import_fd(tbm_bufmgr bufmgr, tbm_fd fd)
1167 tbm_backend_bo_data *bo_data;
1171 _tbm_bufmgr_mutex_lock();
1172 _tbm_set_last_result(TBM_ERROR_NONE);
1174 TBM_BO_RETURN_VAL_IF_FAIL(TBM_BUFMGR_IS_VALID(bufmgr), NULL);
1176 if (!bufmgr->use_hal_tbm) {
1177 if (bufmgr->backend_module_data) {
1178 if (!bufmgr->bufmgr_func->bufmgr_import_fd) {
1179 /* LCOV_EXCL_START */
1180 _tbm_bufmgr_mutex_unlock();
1181 _tbm_set_last_result(TBM_ERROR_NOT_SUPPORTED);
1183 /* LCOV_EXCL_STOP */
1186 if (!bufmgr->backend->bo_import_fd) {
1187 /* LCOV_EXCL_START */
1188 _tbm_bufmgr_mutex_unlock();
1189 _tbm_set_last_result(TBM_ERROR_NOT_SUPPORTED);
1191 /* LCOV_EXCL_STOP */
1196 _tbm_util_check_bo_cnt(bufmgr);
1198 bo = calloc(1, sizeof(struct _tbm_bo));
1200 /* LCOV_EXCL_START */
1201 TBM_ERR("error: fail to import tbm_bo by tbm_fd(%d)\n", fd);
1202 _tbm_set_last_result(TBM_ERROR_OUT_OF_MEMORY);
1203 _tbm_bufmgr_mutex_unlock();
1205 /* LCOV_EXCL_STOP */
1208 if (bufmgr->use_hal_tbm) {
1209 bo_data = (tbm_backend_bo_data *)hal_tbm_bufmgr_import_fd(bufmgr->hal_bufmgr, (hal_tbm_fd)fd, (hal_tbm_error *)&error);
1210 /* LCOV_EXCL_START */
1212 TBM_ERR("error: fail to import tbm_bo by tbm_fd(%d). error(%d)\n", fd, error);
1213 _tbm_set_last_result(error);
1216 /* LCOV_EXCL_STOP */
1218 if (!LIST_IS_EMPTY(&bufmgr->bo_list)) {
1219 LIST_FOR_EACH_ENTRY(bo2, &bufmgr->bo_list, item_link) {
1220 if (bo2->bo_data == bo_data) {
1221 TBM_TRACE_BO("find bo(%p) ref(%d) fd(%d) flag(%s) in list\n",
1222 bo2, bo2->ref_cnt, fd, _tbm_flag_to_str(bo2->flags));
1225 _tbm_bufmgr_mutex_unlock();
1230 bo->bo_data = bo_data;
1231 } else if (bufmgr->backend_module_data) {
1232 bo_data = bufmgr->bufmgr_func->bufmgr_import_fd(bufmgr->bufmgr_data, fd, &error);
1234 /* LCOV_EXCL_START */
1235 TBM_ERR("error: fail to import tbm_bo by tbm_fd(%d). error(%d)\n", fd, error);
1236 _tbm_set_last_result(error);
1238 /* LCOV_EXCL_STOP */
1241 if (!LIST_IS_EMPTY(&bufmgr->bo_list)) {
1242 LIST_FOR_EACH_ENTRY(bo2, &bufmgr->bo_list, item_link) {
1243 if (bo2->bo_data == bo_data) {
1244 TBM_TRACE_BO("find bo(%p) ref(%d) fd(%d) flag(%s) in list\n",
1245 bo2, bo2->ref_cnt, fd, _tbm_flag_to_str(bo2->flags));
1248 _tbm_bufmgr_mutex_unlock();
1253 bo->bo_data = bo_data;
1255 bo_priv = bufmgr->backend->bo_import_fd(bo, fd);
1257 /* LCOV_EXCL_START */
1258 TBM_ERR("error: fail to import tbm_bo by tbm_fd(%d)\n", fd);
1259 _tbm_set_last_result(TBM_ERROR_INVALID_OPERATION);
1261 /* LCOV_EXCL_STOP */
1264 if (!LIST_IS_EMPTY(&bufmgr->bo_list)) {
1265 LIST_FOR_EACH_ENTRY(bo2, &bufmgr->bo_list, item_link) {
1266 if (bo2->priv == bo_priv) {
1267 TBM_TRACE_BO("find bo(%p) ref(%d) fd(%d) flag(%s) in list\n",
1268 bo2, bo2->ref_cnt, fd, _tbm_flag_to_str(bo2->flags));
1271 _tbm_bufmgr_mutex_unlock();
1279 if (bufmgr->use_hal_tbm) {
1280 flags = (tbm_bo_memory_type)hal_tbm_bo_get_memory_types((hal_tbm_bo *)bo->bo_data, (hal_tbm_error *)&error);
1281 if (error != TBM_ERROR_NONE) {
1282 TBM_ERR("fail to get the bo flags(memory_types)");
1283 _tbm_set_last_result(error);
1284 flags = TBM_BO_DEFAULT;
1286 } else if (bufmgr->backend_module_data) {
1287 flags = bufmgr->bo_func->bo_get_memory_types(bo->bo_data, &error);
1288 if (error != TBM_ERROR_NONE) {
1289 TBM_ERR("fail to get the bo flags(memory_types)");
1290 _tbm_set_last_result(error);
1291 flags = TBM_BO_DEFAULT;
1294 if (bufmgr->backend->bo_get_flags)
1295 flags = bufmgr->backend->bo_get_flags(bo);
1297 flags = TBM_BO_DEFAULT;
1300 _tbm_bo_init(bufmgr, bo, flags);
1302 TBM_TRACE_BO("import bo(%p) ref(%d) fd(%d) flag(%s)\n",
1303 bo, bo->ref_cnt, fd, _tbm_flag_to_str(bo->flags));
1305 _tbm_bufmgr_mutex_unlock();
1311 _tbm_bufmgr_mutex_unlock();
1316 tbm_bo_size(tbm_bo bo)
1321 _tbm_bufmgr_mutex_lock();
1322 _tbm_set_last_result(TBM_ERROR_NONE);
1324 TBM_BO_RETURN_VAL_IF_FAIL(_tbm_bo_is_valid(bo), 0);
1326 if (bo->bufmgr->use_hal_tbm) {
1327 size = hal_tbm_bo_get_size((hal_tbm_bo *)bo->bo_data, (hal_tbm_error *)&error);
1328 if (error != TBM_ERROR_NONE) {
1329 TBM_ERR("fail to get the size of the bo_data(%d).", error);
1330 _tbm_set_last_result(TBM_ERROR_NONE);
1332 } else if (bo->bufmgr->backend_module_data) {
1333 size = bo->bufmgr->bo_func->bo_get_size(bo->bo_data, &error);
1334 if (error != TBM_ERROR_NONE) {
1335 TBM_ERR("fail to get the size of the bo_data(%d).", error);
1336 _tbm_set_last_result(TBM_ERROR_NONE);
1339 size = bo->bufmgr->backend->bo_size(bo);
1341 TBM_TRACE_BO("bo(%p) size(%d)\n", bo, size);
1343 _tbm_bufmgr_mutex_unlock();
1349 tbm_bo_locked(tbm_bo bo)
1351 _tbm_bufmgr_mutex_lock();
1352 _tbm_set_last_result(TBM_ERROR_NONE);
1354 TBM_BO_RETURN_VAL_IF_FAIL(_tbm_bo_is_valid(bo), 0);
1356 if (bo->bufmgr->bo_lock_type == TBM_BUFMGR_BO_LOCK_TYPE_NEVER) {
1357 TBM_ERR("bo(%p) lock_cnt(%d)\n", bo, bo->lock_cnt);
1358 _tbm_set_last_result(TBM_ERROR_INVALID_OPERATION);
1359 _tbm_bufmgr_mutex_unlock();
1363 if (bo->lock_cnt > 0) {
1364 TBM_TRACE_BO("error: bo(%p) lock_cnt(%d)\n", bo, bo->lock_cnt);
1365 _tbm_bufmgr_mutex_unlock();
1369 TBM_TRACE_BO("bo(%p) lock_cnt(%d)\n", bo, bo->lock_cnt);
1370 _tbm_bufmgr_mutex_unlock();
1376 tbm_bo_swap(tbm_bo bo1, tbm_bo bo2)
1378 tbm_error_e error1, error2;
1379 int size1 = -1, size2 = -2;
1382 _tbm_bufmgr_mutex_lock();
1383 _tbm_set_last_result(TBM_ERROR_NONE);
1385 TBM_BO_RETURN_VAL_IF_FAIL(_tbm_bo_is_valid(bo1), 0);
1386 TBM_BO_RETURN_VAL_IF_FAIL(_tbm_bo_is_valid(bo2), 0);
1388 TBM_TRACE_BO("before: bo1(%p) bo2(%p)\n", bo1, bo2);
1390 if (bo1->bufmgr->use_hal_tbm) {
1391 size1 = hal_tbm_bo_get_size((hal_tbm_bo *)bo1->bo_data, (hal_tbm_error *)&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 = hal_tbm_bo_get_size((hal_tbm_bo *)bo2->bo_data, (hal_tbm_error *)&error2);
1398 if (error2 != TBM_ERROR_NONE) {
1399 TBM_ERR("fail to get the size of bo1.(%d)", error2);
1400 _tbm_set_last_result(error2);
1403 } else if (bo1->bufmgr->backend_module_data) {
1404 size1 = bo1->bufmgr->bo_func->bo_get_size(bo1->bo_data, &error1);
1405 if (error1 != TBM_ERROR_NONE) {
1406 TBM_ERR("fail to get the size of bo1.(%d)", error1);
1407 _tbm_set_last_result(error1);
1410 size2 = bo2->bufmgr->bo_func->bo_get_size(bo2->bo_data, &error2);
1411 if (error2 != TBM_ERROR_NONE) {
1412 TBM_ERR("fail to get the size of bo2.(%d)", error2);
1413 _tbm_set_last_result(error2);
1417 size1 = bo1->bufmgr->backend->bo_size(bo1);
1418 size2 = bo2->bufmgr->backend->bo_size(bo2);
1421 if (size1 != size2) {
1422 TBM_ERR("error: bo1 size(%d) and bo2 size(%d) is different.", size1, size2);
1423 _tbm_set_last_result(TBM_ERROR_INVALID_OPERATION);
1427 TBM_TRACE_BO("after: bo1(%p) bo2(%p)\n", bo1, bo2);
1430 bo1->priv = bo2->priv;
1433 _tbm_bufmgr_mutex_unlock();
1438 TBM_ERR("error: bo1(%p) bo2(%p)\n", bo1, bo2);
1439 _tbm_bufmgr_mutex_unlock();
1445 tbm_bo_add_user_data(tbm_bo bo, unsigned long key,
1446 tbm_data_free data_free_func)
1448 tbm_user_data *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 /* check if the data according to the key exist if so, return false. */
1456 data = user_data_lookup(&bo->user_data_list, key);
1458 TBM_TRACE_BO("warning: user data already exist key(%ld)\n", key);
1459 _tbm_set_last_result(TBM_ERROR_INVALID_PARAMETER);
1460 _tbm_bufmgr_mutex_unlock();
1464 data = user_data_create(key, data_free_func);
1466 TBM_ERR("error: bo(%p) key(%lu)\n", bo, key);
1467 _tbm_set_last_result(TBM_ERROR_INVALID_PARAMETER);
1468 _tbm_bufmgr_mutex_unlock();
1472 TBM_TRACE_BO("bo(%p) key(%lu) data(%p)\n", bo, key, data->data);
1474 LIST_ADD(&data->item_link, &bo->user_data_list);
1476 _tbm_bufmgr_mutex_unlock();
1482 tbm_bo_delete_user_data(tbm_bo bo, unsigned long key)
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 (LIST_IS_EMPTY(&bo->user_data_list)) {
1492 TBM_TRACE_BO("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);
1500 TBM_TRACE_BO("bo(%p) key(%lu)\n", bo, key);
1501 _tbm_set_last_result(TBM_ERROR_INVALID_PARAMETER);
1502 _tbm_bufmgr_mutex_unlock();
1506 TBM_TRACE_BO("bo(%p) key(%lu) data(%p)\n", bo, key, old_data->data);
1508 user_data_delete(old_data);
1510 _tbm_bufmgr_mutex_unlock();
1516 tbm_bo_set_user_data(tbm_bo bo, unsigned long key, void *data)
1518 tbm_user_data *old_data;
1520 _tbm_bufmgr_mutex_lock();
1521 _tbm_set_last_result(TBM_ERROR_NONE);
1523 TBM_BO_RETURN_VAL_IF_FAIL(_tbm_bo_is_valid(bo), 0);
1525 if (LIST_IS_EMPTY(&bo->user_data_list)) {
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 old_data = user_data_lookup(&bo->user_data_list, key);
1534 TBM_TRACE_BO("error: bo(%p) key(%lu)\n", bo, key);
1535 _tbm_set_last_result(TBM_ERROR_INVALID_PARAMETER);
1536 _tbm_bufmgr_mutex_unlock();
1540 if (old_data->data && old_data->free_func)
1541 old_data->free_func(old_data->data);
1542 old_data->data = data;
1544 TBM_TRACE_BO("bo(%p) key(%lu) data(%p)\n", bo, key, old_data->data);
1546 _tbm_bufmgr_mutex_unlock();
1552 tbm_bo_get_user_data(tbm_bo bo, unsigned long key, void **data)
1554 tbm_user_data *old_data;
1556 _tbm_bufmgr_mutex_lock();
1557 _tbm_set_last_result(TBM_ERROR_NONE);
1559 TBM_BO_RETURN_VAL_IF_FAIL(_tbm_bo_is_valid(bo), 0);
1561 if (!data || LIST_IS_EMPTY(&bo->user_data_list)) {
1562 TBM_TRACE_BO("error: bo(%p) key(%lu)\n", bo, key);
1563 _tbm_set_last_result(TBM_ERROR_INVALID_PARAMETER);
1564 _tbm_bufmgr_mutex_unlock();
1568 old_data = user_data_lookup(&bo->user_data_list, key);
1571 TBM_TRACE_BO("error: bo(%p) key(%lu)\n", bo, key);
1572 _tbm_set_last_result(TBM_ERROR_INVALID_PARAMETER);
1573 _tbm_bufmgr_mutex_unlock();
1577 *data = old_data->data;
1579 TBM_TRACE_BO("bo(%p) key(%lu) data(%p)\n", bo, key, old_data->data);
1581 _tbm_bufmgr_mutex_unlock();
1587 tbm_bo_get_flags(tbm_bo bo)
1591 _tbm_bufmgr_mutex_lock();
1593 TBM_BO_RETURN_VAL_IF_FAIL(_tbm_bo_is_valid(bo), 0);
1597 TBM_TRACE_BO("bo(%p)\n", bo);
1599 _tbm_bufmgr_mutex_unlock();
1604 /* LCOV_EXCL_START */
1605 /* internal function */
1607 _tbm_bo_set_surface(tbm_bo bo, tbm_surface_h surface)
1609 _tbm_bufmgr_mutex_lock();
1611 TBM_BO_RETURN_VAL_IF_FAIL(_tbm_bo_is_valid(bo), 0);
1613 bo->surface = surface;
1615 _tbm_bufmgr_mutex_unlock();
1621 _tbm_bo_free(tbm_bo bo)
1623 /* destory the user_data_list */
1624 if (!LIST_IS_EMPTY(&bo->user_data_list)) {
1625 tbm_user_data *old_data = NULL, *tmp;
1627 LIST_FOR_EACH_ENTRY_SAFE(old_data, tmp,
1628 &bo->user_data_list, item_link) {
1629 TBM_DBG("free user_data\n");
1630 user_data_delete(old_data);
1634 while (bo->lock_cnt > 0) {
1635 TBM_ERR("error lock_cnt:%d\n", bo->lock_cnt);
1640 /* call the bo_free */
1641 if (bo->bufmgr->use_hal_tbm) {
1642 // call hal_tbm_bo_free when bo is created by tbm_bo_alloc api.
1643 if (!bo->get_from_hal_surface) {
1644 bo->get_from_hal_surface = 0;
1646 hal_tbm_bo_free(bo->bo_data);
1649 } else if (bo->bufmgr->backend_module_data) {
1650 bo->bufmgr->bo_func->bo_free(bo->bo_data);
1653 bo->bufmgr->backend->bo_free(bo);
1661 /* LCOV_EXCL_STOP */