1 /**************************************************************************
5 Copyright 2012 Samsung Electronics co., Ltd. All Rights Reserved.
7 Contact: SooChan Lim <sc1.lim@samsung.com>, Sangjin Lee <lsj119@samsung.com>
8 Boram Park <boram1288.park@samsung.com>, Changyeon Lee <cyeon.lee@samsung.com>
10 Permission is hereby granted, free of charge, to any person obtaining a
11 copy of this software and associated documentation files (the
12 "Software"), to deal in the Software without restriction, including
13 without limitation the rights to use, copy, modify, merge, publish,
14 distribute, sub license, and/or sell copies of the Software, and to
15 permit persons to whom the Software is furnished to do so, subject to
16 the following conditions:
18 The above copyright notice and this permission notice (including the
19 next paragraph) shall be included in all copies or substantial portions
22 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
23 OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
24 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
25 IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR
26 ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
27 TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
28 SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
30 **************************************************************************/
33 #include "tbm_bufmgr.h"
34 #include "tbm_bufmgr_int.h"
37 #define TBM_BO_MAGIC 0xBF011234
40 #define TBM_BO_RETURN_IF_FAIL(cond) {\
42 TBM_ERR("'%s' failed.\n", #cond);\
43 _tbm_set_last_result(TBM_ERROR_INVALID_PARAMETER);\
44 _tbm_bufmgr_mutex_unlock();\
49 #define TBM_BO_RETURN_VAL_IF_FAIL(cond, val) {\
51 TBM_ERR("'%s' failed.\n", #cond);\
52 _tbm_set_last_result(TBM_ERROR_INVALID_PARAMETER);\
53 _tbm_bufmgr_mutex_unlock();\
59 _tbm_flag_to_str(int f)
63 if (f == TBM_BO_DEFAULT)
64 snprintf(str, 255, "DEFAULT");
68 if (f & TBM_BO_SCANOUT)
69 c += snprintf(&str[c], 255-c, "SCANOUT");
71 if (f & TBM_BO_NONCACHABLE) {
72 if (c >= 0 && c < 255)
73 c += snprintf(&str[c], 255-c, ", ");
75 if (c >= 0 && c < 255)
76 c += snprintf(&str[c], 255-c, "NONCACHABLE,");
80 if (c >= 0 && c < 255)
81 c += snprintf(&str[c], 255-c, ", ");
83 if (c >= 0 && c < 255)
84 c += snprintf(&str[c], 255-c, "WC");
92 _tbm_util_check_bo_cnt(tbm_bufmgr bufmgr)
94 static int last_chk_bo_cnt = 0;
96 if ((bufmgr->bo_cnt >= 500) && ((bufmgr->bo_cnt % 20) == 0) &&
97 (bufmgr->bo_cnt > last_chk_bo_cnt)) {
98 TBM_DBG("============TBM BO CNT DEBUG: bo_cnt=%d\n", bufmgr->bo_cnt);
99 tbm_bufmgr_debug_show(bufmgr);
100 last_chk_bo_cnt = bufmgr->bo_cnt;
106 user_data_lookup(struct list_head *user_data_list, unsigned long key)
108 tbm_user_data *old_data = NULL;
110 if (LIST_IS_EMPTY(user_data_list))
113 LIST_FOR_EACH_ENTRY(old_data, user_data_list, item_link) {
114 if (old_data->key == key)
122 user_data_create(unsigned long key, tbm_data_free data_free_func)
124 tbm_user_data *user_data;
126 user_data = calloc(1, sizeof(tbm_user_data));
128 /* LCOV_EXCL_START */
129 TBM_ERR("fail to allocate an user_date\n");
130 _tbm_set_last_result(TBM_ERROR_OUT_OF_MEMORY);
135 user_data->key = key;
136 user_data->free_func = data_free_func;
142 user_data_delete(tbm_user_data *user_data)
144 if (user_data->data && user_data->free_func)
145 user_data->free_func(user_data->data);
147 LIST_DEL(&user_data->item_link);
153 _bo_lock(tbm_bo bo, int device, int opt)
158 if (bo->bufmgr->use_hal_tbm) {
159 error = (tbm_error_e)hal_tbm_bo_lock((hal_tbm_bo *)bo->bo_data, device, opt);
160 if (error == TBM_ERROR_NOT_SUPPORTED) {
161 _tbm_set_last_result(TBM_ERROR_NONE);
163 if (error != TBM_ERROR_NONE) {
164 TBM_WRN("fail to lock");
165 _tbm_set_last_result(error);
169 } else if (bo->bufmgr->backend_module_data) {
170 if (bo->bufmgr->bo_func->bo_lock) {
171 error = bo->bufmgr->bo_func->bo_lock(bo->bo_data, device, opt);
172 if (error != TBM_ERROR_NONE) {
173 TBM_WRN("fail to lock");
174 _tbm_set_last_result(error);
179 if (bo->bufmgr->backend->bo_lock) {
180 ret = bo->bufmgr->backend->bo_lock(bo, device, opt);
182 _tbm_set_last_result(TBM_ERROR_INVALID_OPERATION);
190 _bo_unlock(tbm_bo bo)
194 if (bo->bufmgr->use_hal_tbm) {
195 error = (tbm_error_e)hal_tbm_bo_unlock((hal_tbm_bo *)bo->bo_data);
196 if (error == TBM_ERROR_NOT_SUPPORTED) {
197 _tbm_set_last_result(TBM_ERROR_NONE);
199 if (error != TBM_ERROR_NONE) {
200 TBM_WRN("fail to lock");
201 _tbm_set_last_result(error);
204 } else if (bo->bufmgr->backend_module_data) {
205 if (bo->bufmgr->bo_func->bo_unlock) {
206 error = bo->bufmgr->bo_func->bo_unlock(bo->bo_data);
207 if (error != TBM_ERROR_NONE) {
208 TBM_WRN("fail to unlock");
209 _tbm_set_last_result(error);
213 if (bo->bufmgr->backend->bo_unlock)
214 bo->bufmgr->backend->bo_unlock(bo);
219 _tbm_bo_lock(tbm_bo bo, int device, int opt)
226 /* do not try to lock the bo */
227 if (bo->bufmgr->bo_lock_type == TBM_BUFMGR_BO_LOCK_TYPE_NEVER)
230 if (bo->lock_cnt < 0) {
231 TBM_ERR("error bo:%p LOCK_CNT=%d\n",
238 switch (bo->bufmgr->bo_lock_type) {
239 case TBM_BUFMGR_BO_LOCK_TYPE_ONCE:
240 if (bo->lock_cnt == 0) {
241 _tbm_bufmgr_mutex_unlock();
242 ret = _bo_lock(bo, device, opt);
243 _tbm_bufmgr_mutex_lock();
249 case TBM_BUFMGR_BO_LOCK_TYPE_ALWAYS:
250 _tbm_bufmgr_mutex_unlock();
251 ret = _bo_lock(bo, device, opt);
252 _tbm_bufmgr_mutex_lock();
257 TBM_ERR("error bo:%p bo_lock_type[%d] is wrong.\n",
258 bo, bo->bufmgr->bo_lock_type);
263 TBM_DBG(">> LOCK bo:%p(%d->%d)\n", bo, old, bo->lock_cnt);
269 _tbm_bo_unlock(tbm_bo bo)
273 /* do not try to unlock the bo */
274 if (bo->bufmgr->bo_lock_type == TBM_BUFMGR_BO_LOCK_TYPE_NEVER)
279 switch (bo->bufmgr->bo_lock_type) {
280 case TBM_BUFMGR_BO_LOCK_TYPE_ONCE:
281 if (bo->lock_cnt > 0) {
283 if (bo->lock_cnt == 0)
287 case TBM_BUFMGR_BO_LOCK_TYPE_ALWAYS:
288 if (bo->lock_cnt > 0) {
294 TBM_ERR("error bo:%p bo_lock_type[%d] is wrong.\n",
295 bo, bo->bufmgr->bo_lock_type);
299 if (bo->lock_cnt < 0)
302 TBM_DBG(">> UNLOCK bo:%p(%d->%d)\n", bo, old, bo->lock_cnt);
306 _tbm_bo_magic_check(tbm_bo bo)
308 if (bo->magic != TBM_BO_MAGIC)
315 _tbm_bo_is_valid(tbm_bo bo)
318 TBM_ERR("error: bo is NULL.\n");
322 if (!_tbm_bo_magic_check(bo)) {
323 TBM_ERR("error: No valid bo(%p).\n", bo);
331 _tbm_bo_init(tbm_bufmgr bufmgr, tbm_bo bo, int flags)
335 bo->magic = TBM_BO_MAGIC;
338 LIST_INITHEAD(&bo->user_data_list);
341 LIST_ADD(&bo->item_link, &bufmgr->bo_list);
345 _tbm_bo_deinit(tbm_bo bo)
349 bo->bufmgr->bo_cnt--;
350 LIST_DEL(&bo->item_link);
354 tbm_bo_alloc(tbm_bufmgr bufmgr, int size, int flags)
358 tbm_backend_bo_data *bo_data;
361 _tbm_bufmgr_mutex_lock();
362 _tbm_set_last_result(TBM_ERROR_NONE);
364 TBM_BO_RETURN_VAL_IF_FAIL(TBM_BUFMGR_IS_VALID(bufmgr), NULL);
365 TBM_BO_RETURN_VAL_IF_FAIL(size > 0, NULL);
367 bo = calloc(1, sizeof(struct _tbm_bo));
369 /* LCOV_EXCL_START */
370 _tbm_set_last_result(TBM_ERROR_OUT_OF_MEMORY);
371 _tbm_bufmgr_mutex_unlock();
376 _tbm_util_check_bo_cnt(bufmgr);
378 if (bufmgr->use_hal_tbm) {
379 bo_data = (tbm_backend_bo_data *)hal_tbm_bufmgr_alloc_bo(bufmgr->hal_bufmgr, size, flags, (hal_tbm_error *)&error);
380 /* LCOV_EXCL_START */
382 _tbm_set_last_result(error);
386 bo->bo_data = bo_data;
387 } else if (bufmgr->backend_module_data) {
388 bo_data = bufmgr->bufmgr_func->bufmgr_alloc_bo(bufmgr->bufmgr_data, (unsigned int)size, flags, &error);
390 /* LCOV_EXCL_START */
391 _tbm_set_last_result(error);
395 bo->bo_data = bo_data;
397 bo_priv = bufmgr->backend->bo_alloc(bo, size, flags);
399 /* LCOV_EXCL_START */
401 _tbm_set_last_result(TBM_ERROR_INVALID_OPERATION);
408 _tbm_bo_init(bufmgr, bo, flags);
410 TBM_TRACE_BO("bo(%p) size(%d) refcnt(%d), flag(%s)\n", bo, size, bo->ref_cnt,
411 _tbm_flag_to_str(bo->flags));
413 _tbm_bufmgr_mutex_unlock();
418 TBM_ERR("error: fail to create of tbm_bo size(%d) flag(%s)\n", size, _tbm_flag_to_str(flags));
420 _tbm_bufmgr_mutex_unlock();
424 /* LCOV_EXCL_START */
426 tbm_bo_alloc_with_format(tbm_bufmgr bufmgr, int format, int bo_idx, int width,
427 int height, int bpp, tbm_bo_memory_type flags, tbm_error_e *error)
430 tbm_backend_bo_data *bo_data;
432 _tbm_bufmgr_mutex_lock();
433 _tbm_set_last_result(TBM_ERROR_NONE);
435 TBM_BO_RETURN_VAL_IF_FAIL(TBM_BUFMGR_IS_VALID(bufmgr), NULL);
437 bo = calloc(1, sizeof(struct _tbm_bo));
439 TBM_ERR("error: fail to tbm_bo_alloc_with_format fmt(%s) idx(%d) w(%d) h(%d) mem_types(%s)\n",
440 FOURCC_STR(format), bo_idx, width, height, _tbm_flag_to_str(flags));
441 _tbm_set_last_result(TBM_ERROR_OUT_OF_MEMORY);
445 _tbm_util_check_bo_cnt(bufmgr);
447 /* LCOV_EXCL_START */
448 if (!bufmgr->use_hal_tbm) {
449 if (!bufmgr->backend_module_data || !bufmgr->bufmgr_func->bufmgr_alloc_bo_with_format) {
451 TBM_ERR("error: not supported tbm_bo_alloc_with_format\n");
452 _tbm_set_last_result(TBM_ERROR_NOT_SUPPORTED);
458 if (bufmgr->use_hal_tbm) {
460 bo_data = (tbm_backend_bo_data *)hal_tbm_bufmgr_alloc_bo_with_format(bufmgr->hal_bufmgr,
461 format, bo_idx, width, height, bpp, (hal_tbm_bo_memory_type)flags, &ret);
463 *error = (tbm_error_e)ret;
464 if (ret != HAL_TBM_ERROR_NONE) {
465 if (ret != HAL_TBM_ERROR_NOT_SUPPORTED) {
466 TBM_ERR("error: fail to tbm_bo_alloc_with_format\n");
468 _tbm_set_last_result(*error);
473 bo_data = bufmgr->bufmgr_func->bufmgr_alloc_bo_with_format(bufmgr->bufmgr_data, format, bo_idx,
474 width, height, flags, error);
476 TBM_ERR("error: fail to tbm_bo_alloc_with_format fmt(%s) idx(%d) w(%d) h(%d) mem_types(%s)\n",
477 FOURCC_STR(format), bo_idx, width, height, _tbm_flag_to_str(flags));
479 _tbm_set_last_result(*error);
484 bo->bo_data = bo_data;
485 _tbm_bo_init(bufmgr, bo, flags);
487 _tbm_bufmgr_mutex_unlock();
494 _tbm_bufmgr_mutex_unlock();
499 tbm_bo_alloc_with_tiled_format(tbm_bufmgr bufmgr, int width, int height, int bpp, int format,
500 tbm_bo_memory_type flags, int bo_idx, tbm_error_e *error)
503 tbm_backend_bo_data *bo_data;
505 _tbm_bufmgr_mutex_lock();
506 _tbm_set_last_result(TBM_ERROR_NONE);
508 TBM_BO_RETURN_VAL_IF_FAIL(TBM_BUFMGR_IS_VALID(bufmgr), NULL);
510 bo = calloc(1, sizeof(struct _tbm_bo));
512 TBM_ERR("error: fail to tbm_bo_alloc_with_tiled_format fmt(%s) idx(%d) w(%d) h(%d) flags(%s)\n",
513 FOURCC_STR(format), bo_idx, width, height, _tbm_flag_to_str(flags));
514 _tbm_set_last_result(TBM_ERROR_OUT_OF_MEMORY);
515 _tbm_bufmgr_mutex_unlock();
519 _tbm_util_check_bo_cnt(bufmgr);
521 if (!bufmgr->use_hal_tbm) {
522 if (!bufmgr->backend_module_data || !bufmgr->bufmgr_func->bufmgr_alloc_bo_with_tiled_format) {
523 TBM_ERR("error: not supported tbm_bo_alloc_with_tiled_format\n");
524 _tbm_set_last_result(TBM_ERROR_NOT_SUPPORTED);
529 if (bufmgr->use_hal_tbm) {
531 bo_data = (tbm_backend_bo_data *)hal_tbm_bufmgr_alloc_bo_with_format(bufmgr->hal_bufmgr,
532 width, height, bpp, format, (hal_tbm_bo_memory_type)flags, bo_idx, &ret);
534 *error = (tbm_error_e)ret;
535 if (ret != HAL_TBM_ERROR_NONE) {
536 if (ret != HAL_TBM_ERROR_NOT_SUPPORTED) {
537 TBM_ERR("error: fail to tbm_bo_alloc_with_tiled_format fmt(%s) idx(%d) w(%d) h(%d) flags(%s)\n",
538 FOURCC_STR(format), bo_idx, width, height, _tbm_flag_to_str(flags));
540 _tbm_set_last_result(*error);
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);
556 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)
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 bo = calloc(1, sizeof(struct _tbm_bo));
630 /* LCOV_EXCL_START */
631 _tbm_set_last_result(TBM_ERROR_OUT_OF_MEMORY);
632 _tbm_bufmgr_mutex_unlock();
637 _tbm_util_check_bo_cnt(bufmgr);
639 bo->bo_data = bo_data;
641 _tbm_bo_init(bufmgr, bo, flags);
643 TBM_TRACE_BO("bo(%p) refcnt(%d), flag(%s)\n", bo, bo->ref_cnt, _tbm_flag_to_str(bo->flags));
645 _tbm_bufmgr_mutex_unlock();
653 tbm_bo_ref(tbm_bo bo)
655 _tbm_bufmgr_mutex_lock();
656 _tbm_set_last_result(TBM_ERROR_NONE);
658 TBM_BO_RETURN_VAL_IF_FAIL(_tbm_bo_is_valid(bo), NULL);
662 TBM_TRACE_BO("bo(%p) ref_cnt(%d)\n", bo, bo->ref_cnt);
664 _tbm_bufmgr_mutex_unlock();
670 tbm_bo_unref(tbm_bo bo)
672 _tbm_bufmgr_mutex_lock();
673 _tbm_set_last_result(TBM_ERROR_NONE);
675 TBM_BO_RETURN_IF_FAIL(_tbm_bo_is_valid(bo));
677 TBM_TRACE_BO("bo(%p) ref_cnt(%d)\n", bo, bo->ref_cnt - 1);
679 if (bo->ref_cnt <= 0) {
680 _tbm_bufmgr_mutex_unlock();
685 if (bo->ref_cnt == 0)
688 _tbm_bufmgr_mutex_unlock();
692 tbm_bo_map(tbm_bo bo, int device, int opt)
694 tbm_bo_handle bo_handle;
697 _tbm_bufmgr_mutex_lock();
698 _tbm_set_last_result(TBM_ERROR_NONE);
700 TBM_BO_RETURN_VAL_IF_FAIL(_tbm_bo_is_valid(bo), (tbm_bo_handle) NULL);
702 if (!_tbm_bo_lock(bo, device, opt)) {
703 TBM_ERR("error: fail to lock bo:%p)\n", bo);
704 _tbm_bufmgr_mutex_unlock();
705 return (tbm_bo_handle) NULL;
708 if (bo->bufmgr->use_hal_tbm) {
709 hal_tbm_bo_handle hbo_handle;
710 hbo_handle = hal_tbm_bo_map((hal_tbm_bo *)bo->bo_data, device, opt, (hal_tbm_error *)&error);
711 if (hbo_handle.ptr == NULL) {
712 /* LCOV_EXCL_START */
713 _tbm_set_last_result(error);
714 TBM_ERR("error: bo(%p) bo_handle(%p) error(%d)\n", bo, hbo_handle.ptr, error);
718 memcpy(&bo_handle.ptr, &hbo_handle.ptr, sizeof(tbm_bo_handle));
719 } else if (bo->bufmgr->backend_module_data) {
720 bo_handle = bo->bufmgr->bo_func->bo_map(bo->bo_data, device, opt, &error);
721 if (bo_handle.ptr == NULL) {
722 /* LCOV_EXCL_START */
723 _tbm_set_last_result(error);
724 TBM_ERR("error: fail to map bo:%p error:%d\n", bo, error);
729 bo_handle = bo->bufmgr->backend->bo_map(bo, device, opt);
730 if (bo_handle.ptr == NULL) {
731 /* LCOV_EXCL_START */
732 _tbm_set_last_result(TBM_ERROR_INVALID_OPERATION);
733 TBM_ERR("error: fail to map bo:%p\n", bo);
739 /* increase the map_count */
742 TBM_TRACE_BO("bo(%p) map_cnt(%d)\n", bo, bo->map_cnt);
744 _tbm_bufmgr_mutex_unlock();
750 _tbm_bufmgr_mutex_unlock();
751 return (tbm_bo_handle) NULL;
755 tbm_bo_unmap(tbm_bo bo)
760 _tbm_bufmgr_mutex_lock();
761 _tbm_set_last_result(TBM_ERROR_NONE);
763 TBM_BO_RETURN_VAL_IF_FAIL(_tbm_bo_is_valid(bo), 0);
764 TBM_BO_RETURN_VAL_IF_FAIL(bo->map_cnt > 0, 0);
766 if (bo->bufmgr->use_hal_tbm) {
767 error = (hal_tbm_error)hal_tbm_bo_unmap((hal_tbm_bo *)bo->bo_data);
768 if (error != TBM_ERROR_NONE) {
769 /* LCOV_EXCL_START */
770 TBM_ERR("error: bo(%p) map_cnt(%d) error(%d)\n", bo, bo->map_cnt, error);
771 _tbm_set_last_result(error);
776 } else if (bo->bufmgr->backend_module_data) {
777 error = bo->bufmgr->bo_func->bo_unmap(bo->bo_data);
778 if (error != TBM_ERROR_NONE) {
779 /* LCOV_EXCL_START */
780 TBM_ERR("error: bo(%p) map_cnt(%d) error(%d)\n", bo, bo->map_cnt, error);
781 _tbm_set_last_result(error);
787 ret = bo->bufmgr->backend->bo_unmap(bo);
789 /* LCOV_EXCL_START */
790 TBM_ERR("error: bo(%p) map_cnt(%d)\n", bo, bo->map_cnt);
791 _tbm_set_last_result(TBM_ERROR_INVALID_OPERATION);
797 /* decrease the map_count */
800 TBM_TRACE_BO("bo(%p) map_cnt(%d)\n", bo, bo->map_cnt);
805 _tbm_bufmgr_mutex_unlock();
811 tbm_bo_get_handle(tbm_bo bo, int device)
813 tbm_bo_handle bo_handle;
816 _tbm_bufmgr_mutex_lock();
817 _tbm_set_last_result(TBM_ERROR_NONE);
819 TBM_BO_RETURN_VAL_IF_FAIL(_tbm_bo_is_valid(bo), (tbm_bo_handle) NULL);
821 if (bo->bufmgr->use_hal_tbm) {
822 hal_tbm_bo_handle hbo_handle;
823 hbo_handle = hal_tbm_bo_get_handle((hal_tbm_bo *)bo->bo_data, device, (hal_tbm_error *)&error);
824 if (hbo_handle.ptr == NULL) {
825 /* LCOV_EXCL_START */
826 TBM_ERR("error: bo(%p) bo_handle(%p) error(%d)\n", bo, hbo_handle.ptr, error);
827 _tbm_set_last_result(error);
831 memcpy(&bo_handle.ptr, &hbo_handle.ptr, sizeof(tbm_bo_handle));
832 } else if (bo->bufmgr->backend_module_data) {
833 bo_handle = bo->bufmgr->bo_func->bo_get_handle(bo->bo_data, device, &error);
834 if (bo_handle.ptr == NULL) {
835 /* LCOV_EXCL_START */
836 TBM_ERR("error: bo(%p) bo_handle(%p) error(%d)\n", bo, bo_handle.ptr, error);
837 _tbm_set_last_result(error);
842 bo_handle = bo->bufmgr->backend->bo_get_handle(bo, device);
843 if (bo_handle.ptr == NULL) {
844 /* LCOV_EXCL_START */
845 TBM_ERR("error: bo(%p) bo_handle(%p)\n", bo, bo_handle.ptr);
846 _tbm_set_last_result(TBM_ERROR_INVALID_OPERATION);
852 TBM_TRACE_BO("bo(%p) bo_handle(%p)\n", bo, bo_handle.ptr);
854 _tbm_bufmgr_mutex_unlock();
859 _tbm_bufmgr_mutex_unlock();
860 return (tbm_bo_handle) NULL;
864 tbm_bo_export(tbm_bo bo)
869 _tbm_bufmgr_mutex_lock();
870 _tbm_set_last_result(TBM_ERROR_NONE);
872 TBM_BO_RETURN_VAL_IF_FAIL(_tbm_bo_is_valid(bo), 0);
874 if (bo->bufmgr->use_hal_tbm) {
875 ret = (hal_tbm_key)hal_tbm_bo_export_key((hal_tbm_bo *)bo->bo_data, (hal_tbm_error *)&error);
877 /* LCOV_EXCL_START */
878 TBM_ERR("error: bo(%p) tbm_key(%d) error(%d)\n", bo, ret, error);
879 _tbm_set_last_result(error);
883 } else if (bo->bufmgr->backend_module_data) {
884 if (!bo->bufmgr->bo_func->bo_export_key) {
885 /* LCOV_EXCL_START */
886 _tbm_bufmgr_mutex_unlock();
887 _tbm_set_last_result(TBM_ERROR_NOT_SUPPORTED);
892 ret = bo->bufmgr->bo_func->bo_export_key(bo->bo_data, &error);
894 /* LCOV_EXCL_START */
895 TBM_ERR("error: bo(%p) tbm_key(%d) error(%d)\n", bo, ret, error);
896 _tbm_set_last_result(error);
901 if (!bo->bufmgr->backend->bo_export) {
902 /* LCOV_EXCL_START */
903 _tbm_bufmgr_mutex_unlock();
904 _tbm_set_last_result(TBM_ERROR_NOT_SUPPORTED);
909 ret = bo->bufmgr->backend->bo_export(bo);
911 /* LCOV_EXCL_START */
912 TBM_ERR("error: bo(%p) tbm_key(%d)\n", bo, ret);
913 _tbm_set_last_result(TBM_ERROR_INVALID_OPERATION);
919 TBM_TRACE_BO("bo(%p) tbm_key(%u)\n", bo, ret);
922 _tbm_bufmgr_mutex_unlock();
928 tbm_bo_export_fd(tbm_bo bo)
933 _tbm_bufmgr_mutex_lock();
934 _tbm_set_last_result(TBM_ERROR_NONE);
936 TBM_BO_RETURN_VAL_IF_FAIL(_tbm_bo_is_valid(bo), -1);
938 if (bo->bufmgr->use_hal_tbm) {
939 ret = (hal_tbm_fd)hal_tbm_bo_export_fd((hal_tbm_bo *)bo->bo_data, (hal_tbm_error *)&error);
941 /* LCOV_EXCL_START */
942 TBM_ERR("error: bo(%p) tbm_fd(%d) error(%d)\n", bo, ret, error);
943 _tbm_set_last_result(error);
947 } else if (bo->bufmgr->backend_module_data) {
948 if (!bo->bufmgr->bo_func->bo_export_fd) {
949 /* LCOV_EXCL_START */
950 _tbm_bufmgr_mutex_unlock();
951 _tbm_set_last_result(TBM_ERROR_NOT_SUPPORTED);
956 ret = bo->bufmgr->bo_func->bo_export_fd(bo->bo_data, &error);
958 /* LCOV_EXCL_START */
959 TBM_ERR("error: bo(%p) tbm_fd(%d) error(%d)\n", bo, ret, error);
960 _tbm_set_last_result(error);
965 if (!bo->bufmgr->backend->bo_export_fd) {
966 /* LCOV_EXCL_START */
967 _tbm_bufmgr_mutex_unlock();
968 _tbm_set_last_result(TBM_ERROR_NOT_SUPPORTED);
973 ret = bo->bufmgr->backend->bo_export_fd(bo);
975 /* LCOV_EXCL_START */
976 TBM_ERR("error: bo(%p) tbm_fd(%d)\n", bo, ret);
977 _tbm_set_last_result(TBM_ERROR_INVALID_OPERATION);
983 TBM_TRACE_BO("bo(%p) tbm_fd(%d)\n", bo, ret);
986 _tbm_bufmgr_mutex_unlock();
992 tbm_bo_import(tbm_bufmgr bufmgr, unsigned int key)
998 tbm_backend_bo_data *bo_data;
1001 _tbm_bufmgr_mutex_lock();
1002 _tbm_set_last_result(TBM_ERROR_NONE);
1004 TBM_BO_RETURN_VAL_IF_FAIL(TBM_BUFMGR_IS_VALID(bufmgr), NULL);
1006 if (!bufmgr->use_hal_tbm) {
1007 if (bufmgr->backend_module_data) {
1008 if (!bufmgr->bufmgr_func->bufmgr_import_key) {
1009 /* LCOV_EXCL_START */
1010 _tbm_bufmgr_mutex_unlock();
1011 _tbm_set_last_result(TBM_ERROR_NOT_SUPPORTED);
1013 /* LCOV_EXCL_STOP */
1016 if (!bufmgr->backend->bo_import) {
1017 /* LCOV_EXCL_START */
1018 _tbm_bufmgr_mutex_unlock();
1019 _tbm_set_last_result(TBM_ERROR_NOT_SUPPORTED);
1021 /* LCOV_EXCL_STOP */
1026 _tbm_util_check_bo_cnt(bufmgr);
1028 bo = calloc(1, sizeof(struct _tbm_bo));
1030 /* LCOV_EXCL_START */
1031 TBM_ERR("error: fail to import of tbm_bo by key(%d)\n", key);
1032 _tbm_set_last_result(TBM_ERROR_OUT_OF_MEMORY);
1033 _tbm_bufmgr_mutex_unlock();
1035 /* LCOV_EXCL_STOP */
1038 if (bufmgr->use_hal_tbm) {
1039 bo_data = (tbm_backend_bo_data *)hal_tbm_bufmgr_import_key(bufmgr->hal_bufmgr, key, (hal_tbm_error *)&error);
1040 /* LCOV_EXCL_START */
1042 TBM_ERR("error: fail to import of tbm_bo by key(%d). error(%d)\n", key, error);
1043 _tbm_set_last_result(error);
1046 /* LCOV_EXCL_STOP */
1047 if (!LIST_IS_EMPTY(&bufmgr->bo_list)) {
1048 LIST_FOR_EACH_ENTRY(bo2, &bufmgr->bo_list, item_link) {
1049 if (bo2->bo_data == bo_data) {
1050 TBM_TRACE_BO("find bo(%p) ref(%d) key(%d) flag(%s) in list\n",
1051 bo2, bo2->ref_cnt, key,
1052 _tbm_flag_to_str(bo2->flags));
1055 _tbm_bufmgr_mutex_unlock();
1060 bo->bo_data = bo_data;
1061 } else if (bufmgr->backend_module_data) {
1062 bo_data = bufmgr->bufmgr_func->bufmgr_import_key(bufmgr->bufmgr_data, key, &error);
1064 /* LCOV_EXCL_START */
1065 TBM_ERR("error: fail to import of tbm_bo by key(%d). error(%d)\n", key, error);
1066 _tbm_set_last_result(error);
1068 /* LCOV_EXCL_STOP */
1071 if (!LIST_IS_EMPTY(&bufmgr->bo_list)) {
1072 LIST_FOR_EACH_ENTRY(bo2, &bufmgr->bo_list, item_link) {
1073 if (bo2->bo_data == bo_data) {
1074 TBM_TRACE_BO("find bo(%p) ref(%d) key(%d) flag(%s) in list\n",
1075 bo2, bo2->ref_cnt, key,
1076 _tbm_flag_to_str(bo2->flags));
1079 _tbm_bufmgr_mutex_unlock();
1084 bo->bo_data = bo_data;
1086 bo_priv = bufmgr->backend->bo_import(bo, key);
1088 /* LCOV_EXCL_START */
1089 TBM_ERR("error: fail to import of tbm_bo by key(%d)\n", key);
1090 _tbm_set_last_result(TBM_ERROR_INVALID_OPERATION);
1092 /* LCOV_EXCL_STOP */
1095 if (!LIST_IS_EMPTY(&bufmgr->bo_list)) {
1096 LIST_FOR_EACH_ENTRY(bo2, &bufmgr->bo_list, item_link) {
1097 if (bo2->priv == bo_priv) {
1098 TBM_TRACE_BO("find bo(%p) ref(%d) key(%d) flag(%s) in list\n",
1099 bo2, bo2->ref_cnt, key,
1100 _tbm_flag_to_str(bo2->flags));
1103 _tbm_bufmgr_mutex_unlock();
1111 if (bufmgr->use_hal_tbm) {
1112 flags = (tbm_bo_memory_type)hal_tbm_bo_get_memory_types((hal_tbm_bo *)bo->bo_data, (hal_tbm_error *)&error);
1113 if (error != TBM_ERROR_NONE) {
1114 TBM_ERR("fail to get the bo flags(memory_types)");
1115 _tbm_set_last_result(error);
1116 flags = TBM_BO_DEFAULT;
1118 } else if (bufmgr->backend_module_data) {
1119 flags = bufmgr->bo_func->bo_get_memory_types(bo->bo_data, &error);
1120 if (error != TBM_ERROR_NONE) {
1121 TBM_ERR("fail to get the bo flags(memory_types)");
1122 _tbm_set_last_result(error);
1123 flags = TBM_BO_DEFAULT;
1126 if (bufmgr->backend->bo_get_flags)
1127 flags = bufmgr->backend->bo_get_flags(bo);
1129 flags = TBM_BO_DEFAULT;
1132 _tbm_bo_init(bufmgr, bo, flags);
1134 TBM_TRACE_BO("import new bo(%p) ref(%d) key(%d) flag(%s) in list\n",
1135 bo, bo->ref_cnt, key, _tbm_flag_to_str(bo->flags));
1137 _tbm_bufmgr_mutex_unlock();
1143 _tbm_bufmgr_mutex_unlock();
1148 tbm_bo_import_fd(tbm_bufmgr bufmgr, tbm_fd fd)
1153 tbm_backend_bo_data *bo_data;
1157 _tbm_bufmgr_mutex_lock();
1158 _tbm_set_last_result(TBM_ERROR_NONE);
1160 TBM_BO_RETURN_VAL_IF_FAIL(TBM_BUFMGR_IS_VALID(bufmgr), NULL);
1162 if (!bufmgr->use_hal_tbm) {
1163 if (bufmgr->backend_module_data) {
1164 if (!bufmgr->bufmgr_func->bufmgr_import_fd) {
1165 /* LCOV_EXCL_START */
1166 _tbm_bufmgr_mutex_unlock();
1167 _tbm_set_last_result(TBM_ERROR_NOT_SUPPORTED);
1169 /* LCOV_EXCL_STOP */
1172 if (!bufmgr->backend->bo_import_fd) {
1173 /* LCOV_EXCL_START */
1174 _tbm_bufmgr_mutex_unlock();
1175 _tbm_set_last_result(TBM_ERROR_NOT_SUPPORTED);
1177 /* LCOV_EXCL_STOP */
1182 _tbm_util_check_bo_cnt(bufmgr);
1184 bo = calloc(1, sizeof(struct _tbm_bo));
1186 /* LCOV_EXCL_START */
1187 TBM_ERR("error: fail to import tbm_bo by tbm_fd(%d)\n", fd);
1188 _tbm_set_last_result(TBM_ERROR_OUT_OF_MEMORY);
1189 _tbm_bufmgr_mutex_unlock();
1191 /* LCOV_EXCL_STOP */
1194 if (bufmgr->use_hal_tbm) {
1195 bo_data = (tbm_backend_bo_data *)hal_tbm_bufmgr_import_fd(bufmgr->hal_bufmgr, (hal_tbm_fd)fd, (hal_tbm_error *)&error);
1196 /* LCOV_EXCL_START */
1198 TBM_ERR("error: fail to import tbm_bo by tbm_fd(%d). error(%d)\n", fd, error);
1199 _tbm_set_last_result(error);
1202 /* LCOV_EXCL_STOP */
1204 if (!LIST_IS_EMPTY(&bufmgr->bo_list)) {
1205 LIST_FOR_EACH_ENTRY(bo2, &bufmgr->bo_list, item_link) {
1206 if (bo2->bo_data == bo_data) {
1207 TBM_TRACE_BO("find bo(%p) ref(%d) fd(%d) flag(%s) in list\n",
1208 bo2, bo2->ref_cnt, fd, _tbm_flag_to_str(bo2->flags));
1211 _tbm_bufmgr_mutex_unlock();
1216 bo->bo_data = bo_data;
1217 } else if (bufmgr->backend_module_data) {
1218 bo_data = bufmgr->bufmgr_func->bufmgr_import_fd(bufmgr->bufmgr_data, fd, &error);
1220 /* LCOV_EXCL_START */
1221 TBM_ERR("error: fail to import tbm_bo by tbm_fd(%d). error(%d)\n", fd, error);
1222 _tbm_set_last_result(error);
1224 /* LCOV_EXCL_STOP */
1227 if (!LIST_IS_EMPTY(&bufmgr->bo_list)) {
1228 LIST_FOR_EACH_ENTRY(bo2, &bufmgr->bo_list, item_link) {
1229 if (bo2->bo_data == bo_data) {
1230 TBM_TRACE_BO("find bo(%p) ref(%d) fd(%d) flag(%s) in list\n",
1231 bo2, bo2->ref_cnt, fd, _tbm_flag_to_str(bo2->flags));
1234 _tbm_bufmgr_mutex_unlock();
1239 bo->bo_data = bo_data;
1241 bo_priv = bufmgr->backend->bo_import_fd(bo, fd);
1243 /* LCOV_EXCL_START */
1244 TBM_ERR("error: fail to import tbm_bo by tbm_fd(%d)\n", fd);
1245 _tbm_set_last_result(TBM_ERROR_INVALID_OPERATION);
1247 /* LCOV_EXCL_STOP */
1250 if (!LIST_IS_EMPTY(&bufmgr->bo_list)) {
1251 LIST_FOR_EACH_ENTRY(bo2, &bufmgr->bo_list, item_link) {
1252 if (bo2->priv == bo_priv) {
1253 TBM_TRACE_BO("find bo(%p) ref(%d) fd(%d) flag(%s) in list\n",
1254 bo2, bo2->ref_cnt, fd, _tbm_flag_to_str(bo2->flags));
1257 _tbm_bufmgr_mutex_unlock();
1265 if (bufmgr->use_hal_tbm) {
1266 flags = (tbm_bo_memory_type)hal_tbm_bo_get_memory_types((hal_tbm_bo *)bo->bo_data, (hal_tbm_error *)&error);
1267 if (error != TBM_ERROR_NONE) {
1268 TBM_ERR("fail to get the bo flags(memory_types)");
1269 _tbm_set_last_result(error);
1270 flags = TBM_BO_DEFAULT;
1272 } else if (bufmgr->backend_module_data) {
1273 flags = bufmgr->bo_func->bo_get_memory_types(bo->bo_data, &error);
1274 if (error != TBM_ERROR_NONE) {
1275 TBM_ERR("fail to get the bo flags(memory_types)");
1276 _tbm_set_last_result(error);
1277 flags = TBM_BO_DEFAULT;
1280 if (bufmgr->backend->bo_get_flags)
1281 flags = bufmgr->backend->bo_get_flags(bo);
1283 flags = TBM_BO_DEFAULT;
1286 _tbm_bo_init(bufmgr, bo, flags);
1288 TBM_TRACE_BO("import bo(%p) ref(%d) fd(%d) flag(%s)\n",
1289 bo, bo->ref_cnt, fd, _tbm_flag_to_str(bo->flags));
1291 _tbm_bufmgr_mutex_unlock();
1297 _tbm_bufmgr_mutex_unlock();
1302 tbm_bo_size(tbm_bo bo)
1307 _tbm_bufmgr_mutex_lock();
1308 _tbm_set_last_result(TBM_ERROR_NONE);
1310 TBM_BO_RETURN_VAL_IF_FAIL(_tbm_bo_is_valid(bo), 0);
1312 if (bo->bufmgr->use_hal_tbm) {
1313 size = hal_tbm_bo_get_size((hal_tbm_bo *)bo->bo_data, (hal_tbm_error *)&error);
1314 if (error != TBM_ERROR_NONE) {
1315 TBM_ERR("fail to get the size of the bo_data(%d).", error);
1316 _tbm_set_last_result(TBM_ERROR_NONE);
1318 } else if (bo->bufmgr->backend_module_data) {
1319 size = bo->bufmgr->bo_func->bo_get_size(bo->bo_data, &error);
1320 if (error != TBM_ERROR_NONE) {
1321 TBM_ERR("fail to get the size of the bo_data(%d).", error);
1322 _tbm_set_last_result(TBM_ERROR_NONE);
1325 size = bo->bufmgr->backend->bo_size(bo);
1327 TBM_TRACE_BO("bo(%p) size(%d)\n", bo, size);
1329 _tbm_bufmgr_mutex_unlock();
1335 tbm_bo_locked(tbm_bo bo)
1337 _tbm_bufmgr_mutex_lock();
1338 _tbm_set_last_result(TBM_ERROR_NONE);
1340 TBM_BO_RETURN_VAL_IF_FAIL(_tbm_bo_is_valid(bo), 0);
1342 if (bo->bufmgr->bo_lock_type == TBM_BUFMGR_BO_LOCK_TYPE_NEVER) {
1343 TBM_ERR("bo(%p) lock_cnt(%d)\n", bo, bo->lock_cnt);
1344 _tbm_set_last_result(TBM_ERROR_INVALID_OPERATION);
1345 _tbm_bufmgr_mutex_unlock();
1349 if (bo->lock_cnt > 0) {
1350 TBM_TRACE_BO("error: bo(%p) lock_cnt(%d)\n", bo, bo->lock_cnt);
1351 _tbm_bufmgr_mutex_unlock();
1355 TBM_TRACE_BO("bo(%p) lock_cnt(%d)\n", bo, bo->lock_cnt);
1356 _tbm_bufmgr_mutex_unlock();
1362 tbm_bo_swap(tbm_bo bo1, tbm_bo bo2)
1364 tbm_error_e error1, error2;
1365 int size1 = -1, size2 = -2;
1368 _tbm_bufmgr_mutex_lock();
1369 _tbm_set_last_result(TBM_ERROR_NONE);
1371 TBM_BO_RETURN_VAL_IF_FAIL(_tbm_bo_is_valid(bo1), 0);
1372 TBM_BO_RETURN_VAL_IF_FAIL(_tbm_bo_is_valid(bo2), 0);
1374 TBM_TRACE_BO("before: bo1(%p) bo2(%p)\n", bo1, bo2);
1376 if (bo1->bufmgr->use_hal_tbm) {
1377 size1 = hal_tbm_bo_get_size((hal_tbm_bo *)bo1->bo_data, (hal_tbm_error *)&error1);
1378 if (error1 != TBM_ERROR_NONE) {
1379 TBM_ERR("fail to get the size of bo1.(%d)", error1);
1380 _tbm_set_last_result(error1);
1383 size2 = hal_tbm_bo_get_size((hal_tbm_bo *)bo2->bo_data, (hal_tbm_error *)&error2);
1384 if (error2 != TBM_ERROR_NONE) {
1385 TBM_ERR("fail to get the size of bo1.(%d)", error2);
1386 _tbm_set_last_result(error2);
1389 } else if (bo1->bufmgr->backend_module_data) {
1390 size1 = bo1->bufmgr->bo_func->bo_get_size(bo1->bo_data, &error1);
1391 if (error1 != TBM_ERROR_NONE) {
1392 TBM_ERR("fail to get the size of bo1.(%d)", error1);
1393 _tbm_set_last_result(error1);
1396 size2 = bo2->bufmgr->bo_func->bo_get_size(bo2->bo_data, &error2);
1397 if (error2 != TBM_ERROR_NONE) {
1398 TBM_ERR("fail to get the size of bo2.(%d)", error2);
1399 _tbm_set_last_result(error2);
1403 size1 = bo1->bufmgr->backend->bo_size(bo1);
1404 size2 = bo2->bufmgr->backend->bo_size(bo2);
1407 if (size1 != size2) {
1408 TBM_ERR("error: bo1 size(%d) and bo2 size(%d) is different.", size1, size2);
1409 _tbm_set_last_result(TBM_ERROR_INVALID_OPERATION);
1413 TBM_TRACE_BO("after: bo1(%p) bo2(%p)\n", bo1, bo2);
1416 bo1->priv = bo2->priv;
1419 _tbm_bufmgr_mutex_unlock();
1424 TBM_ERR("error: bo1(%p) bo2(%p)\n", bo1, bo2);
1425 _tbm_bufmgr_mutex_unlock();
1431 tbm_bo_add_user_data(tbm_bo bo, unsigned long key,
1432 tbm_data_free data_free_func)
1434 tbm_user_data *data;
1436 _tbm_bufmgr_mutex_lock();
1437 _tbm_set_last_result(TBM_ERROR_NONE);
1439 TBM_BO_RETURN_VAL_IF_FAIL(_tbm_bo_is_valid(bo), 0);
1441 /* check if the data according to the key exist if so, return false. */
1442 data = user_data_lookup(&bo->user_data_list, key);
1444 TBM_TRACE_BO("warning: user data already exist key(%ld)\n", key);
1445 _tbm_set_last_result(TBM_ERROR_INVALID_PARAMETER);
1446 _tbm_bufmgr_mutex_unlock();
1450 data = user_data_create(key, data_free_func);
1452 TBM_ERR("error: bo(%p) key(%lu)\n", bo, key);
1453 _tbm_set_last_result(TBM_ERROR_INVALID_PARAMETER);
1454 _tbm_bufmgr_mutex_unlock();
1458 TBM_TRACE_BO("bo(%p) key(%lu) data(%p)\n", bo, key, data->data);
1460 LIST_ADD(&data->item_link, &bo->user_data_list);
1462 _tbm_bufmgr_mutex_unlock();
1468 tbm_bo_delete_user_data(tbm_bo bo, unsigned long key)
1470 tbm_user_data *old_data;
1472 _tbm_bufmgr_mutex_lock();
1473 _tbm_set_last_result(TBM_ERROR_NONE);
1475 TBM_BO_RETURN_VAL_IF_FAIL(_tbm_bo_is_valid(bo), 0);
1477 if (LIST_IS_EMPTY(&bo->user_data_list)) {
1478 TBM_TRACE_BO("bo(%p) key(%lu)\n", bo, key);
1479 _tbm_set_last_result(TBM_ERROR_INVALID_PARAMETER);
1480 _tbm_bufmgr_mutex_unlock();
1484 old_data = user_data_lookup(&bo->user_data_list, key);
1486 TBM_TRACE_BO("bo(%p) key(%lu)\n", bo, key);
1487 _tbm_set_last_result(TBM_ERROR_INVALID_PARAMETER);
1488 _tbm_bufmgr_mutex_unlock();
1492 TBM_TRACE_BO("bo(%p) key(%lu) data(%p)\n", bo, key, old_data->data);
1494 user_data_delete(old_data);
1496 _tbm_bufmgr_mutex_unlock();
1502 tbm_bo_set_user_data(tbm_bo bo, unsigned long key, void *data)
1504 tbm_user_data *old_data;
1506 _tbm_bufmgr_mutex_lock();
1507 _tbm_set_last_result(TBM_ERROR_NONE);
1509 TBM_BO_RETURN_VAL_IF_FAIL(_tbm_bo_is_valid(bo), 0);
1511 if (LIST_IS_EMPTY(&bo->user_data_list)) {
1512 TBM_TRACE_BO("error: bo(%p) key(%lu)\n", bo, key);
1513 _tbm_set_last_result(TBM_ERROR_INVALID_PARAMETER);
1514 _tbm_bufmgr_mutex_unlock();
1518 old_data = user_data_lookup(&bo->user_data_list, key);
1520 TBM_TRACE_BO("error: bo(%p) key(%lu)\n", bo, key);
1521 _tbm_set_last_result(TBM_ERROR_INVALID_PARAMETER);
1522 _tbm_bufmgr_mutex_unlock();
1526 if (old_data->data && old_data->free_func)
1527 old_data->free_func(old_data->data);
1528 old_data->data = data;
1530 TBM_TRACE_BO("bo(%p) key(%lu) data(%p)\n", bo, key, old_data->data);
1532 _tbm_bufmgr_mutex_unlock();
1538 tbm_bo_get_user_data(tbm_bo bo, unsigned long key, void **data)
1540 tbm_user_data *old_data;
1542 _tbm_bufmgr_mutex_lock();
1543 _tbm_set_last_result(TBM_ERROR_NONE);
1545 TBM_BO_RETURN_VAL_IF_FAIL(_tbm_bo_is_valid(bo), 0);
1547 if (!data || LIST_IS_EMPTY(&bo->user_data_list)) {
1548 TBM_TRACE_BO("error: bo(%p) key(%lu)\n", bo, key);
1549 _tbm_set_last_result(TBM_ERROR_INVALID_PARAMETER);
1550 _tbm_bufmgr_mutex_unlock();
1554 old_data = user_data_lookup(&bo->user_data_list, key);
1557 TBM_TRACE_BO("error: bo(%p) key(%lu)\n", bo, key);
1558 _tbm_set_last_result(TBM_ERROR_INVALID_PARAMETER);
1559 _tbm_bufmgr_mutex_unlock();
1563 *data = old_data->data;
1565 TBM_TRACE_BO("bo(%p) key(%lu) data(%p)\n", bo, key, old_data->data);
1567 _tbm_bufmgr_mutex_unlock();
1573 tbm_bo_get_flags(tbm_bo bo)
1577 _tbm_bufmgr_mutex_lock();
1579 TBM_BO_RETURN_VAL_IF_FAIL(_tbm_bo_is_valid(bo), 0);
1583 TBM_TRACE_BO("bo(%p)\n", bo);
1585 _tbm_bufmgr_mutex_unlock();
1590 /* LCOV_EXCL_START */
1591 /* internal function */
1593 _tbm_bo_set_surface(tbm_bo bo, tbm_surface_h surface)
1595 _tbm_bufmgr_mutex_lock();
1597 TBM_BO_RETURN_VAL_IF_FAIL(_tbm_bo_is_valid(bo), 0);
1599 bo->surface = surface;
1601 _tbm_bufmgr_mutex_unlock();
1607 _tbm_bo_free(tbm_bo bo)
1609 /* destory the user_data_list */
1610 if (!LIST_IS_EMPTY(&bo->user_data_list)) {
1611 tbm_user_data *old_data = NULL, *tmp;
1613 LIST_FOR_EACH_ENTRY_SAFE(old_data, tmp,
1614 &bo->user_data_list, item_link) {
1615 TBM_DBG("free user_data\n");
1616 user_data_delete(old_data);
1620 while (bo->lock_cnt > 0) {
1621 TBM_ERR("error lock_cnt:%d\n", bo->lock_cnt);
1626 /* call the bo_free */
1627 if (bo->bufmgr->use_hal_tbm) {
1628 hal_tbm_bo_free(bo->bo_data);
1630 } else if (bo->bufmgr->backend_module_data) {
1631 bo->bufmgr->bo_func->bo_free(bo->bo_data);
1634 bo->bufmgr->backend->bo_free(bo);
1642 /* LCOV_EXCL_STOP */