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"
38 #define TBM_BO_RETURN_IF_FAIL(cond) {\
40 TBM_ERR("'%s' failed.\n", #cond);\
41 _tbm_set_last_result(TBM_ERROR_INVALID_PARAMETER);\
42 _tbm_bufmgr_mutex_unlock();\
47 #define TBM_BO_RETURN_VAL_IF_FAIL(cond, val) {\
49 TBM_ERR("'%s' failed.\n", #cond);\
50 _tbm_set_last_result(TBM_ERROR_INVALID_PARAMETER);\
51 _tbm_bufmgr_mutex_unlock();\
57 _tbm_flag_to_str(int f)
61 if (f == TBM_BO_DEFAULT)
62 snprintf(str, 255, "DEFAULT");
66 if (f & TBM_BO_SCANOUT)
67 c += snprintf(&str[c], 255-c, "SCANOUT");
69 if (f & TBM_BO_NONCACHABLE) {
70 if (c >= 0 && c < 255)
71 c += snprintf(&str[c], 255-c, ", ");
73 if (c >= 0 && c < 255)
74 c += snprintf(&str[c], 255-c, "NONCACHABLE,");
78 if (c >= 0 && c < 255)
79 c += snprintf(&str[c], 255-c, ", ");
81 if (c >= 0 && c < 255)
82 c += snprintf(&str[c], 255-c, "WC");
92 user_data_lookup(struct list_head *user_data_list, unsigned long key)
94 tbm_user_data *old_data = NULL;
96 if (LIST_IS_EMPTY(user_data_list))
99 LIST_FOR_EACH_ENTRY(old_data, user_data_list, item_link) {
100 if (old_data->key == key)
108 user_data_create(unsigned long key, tbm_data_free data_free_func)
110 tbm_user_data *user_data;
112 user_data = calloc(1, sizeof(tbm_user_data));
114 /* LCOV_EXCL_START */
115 TBM_ERR("fail to allocate an user_date\n");
116 _tbm_set_last_result(TBM_ERROR_OUT_OF_MEMORY);
121 user_data->key = key;
122 user_data->free_func = data_free_func;
128 user_data_delete(tbm_user_data *user_data)
130 if (user_data->data && user_data->free_func)
131 user_data->free_func(user_data->data);
133 LIST_DEL(&user_data->item_link);
139 _bo_lock(tbm_bo bo, int device, int opt)
144 error = tbm_module_bo_lock(bo->bufmgr->module, bo, bo->bo_data, device, opt);
145 _tbm_set_last_result(error);
150 case TBM_ERROR_NOT_SUPPORTED:
152 _tbm_set_last_result(TBM_ERROR_NONE);
156 TBM_WRN("fail to lock. error:%d", error);
164 _bo_unlock(tbm_bo bo)
168 if (bo->bufmgr->use_hal_tbm) {
169 error = (tbm_error_e)hal_tbm_bo_unlock((hal_tbm_bo *)bo->bo_data);
170 if (error == TBM_ERROR_NOT_SUPPORTED) {
171 _tbm_set_last_result(TBM_ERROR_NONE);
173 if (error != TBM_ERROR_NONE) {
174 TBM_WRN("fail to lock");
175 _tbm_set_last_result(error);
178 } else if (bo->bufmgr->backend_module_data) {
179 if (bo->bufmgr->bo_func->bo_unlock) {
180 error = bo->bufmgr->bo_func->bo_unlock(bo->bo_data);
181 if (error != TBM_ERROR_NONE) {
182 TBM_WRN("fail to unlock");
183 _tbm_set_last_result(error);
187 if (bo->bufmgr->backend->bo_unlock)
188 bo->bufmgr->backend->bo_unlock(bo);
193 _tbm_bo_lock(tbm_bo bo, int device, int opt)
200 /* do not try to lock the bo */
201 if (bo->bufmgr->bo_lock_type == TBM_BUFMGR_BO_LOCK_TYPE_NEVER)
204 if (bo->lock_cnt < 0) {
205 TBM_ERR("error bo:%p LOCK_CNT=%d\n",
212 switch (bo->bufmgr->bo_lock_type) {
213 case TBM_BUFMGR_BO_LOCK_TYPE_ONCE:
214 if (bo->lock_cnt == 0) {
215 _tbm_bufmgr_mutex_unlock();
216 ret = _bo_lock(bo, device, opt);
217 _tbm_bufmgr_mutex_lock();
223 case TBM_BUFMGR_BO_LOCK_TYPE_ALWAYS:
224 _tbm_bufmgr_mutex_unlock();
225 ret = _bo_lock(bo, device, opt);
226 _tbm_bufmgr_mutex_lock();
231 TBM_ERR("error bo:%p bo_lock_type[%d] is wrong.\n",
232 bo, bo->bufmgr->bo_lock_type);
237 TBM_DBG(">> LOCK bo:%p(%d->%d)\n", bo, old, bo->lock_cnt);
243 _tbm_bo_unlock(tbm_bo bo)
247 /* do not try to unlock the bo */
248 if (bo->bufmgr->bo_lock_type == TBM_BUFMGR_BO_LOCK_TYPE_NEVER)
253 switch (bo->bufmgr->bo_lock_type) {
254 case TBM_BUFMGR_BO_LOCK_TYPE_ONCE:
255 if (bo->lock_cnt > 0) {
257 if (bo->lock_cnt == 0)
261 case TBM_BUFMGR_BO_LOCK_TYPE_ALWAYS:
262 if (bo->lock_cnt > 0) {
268 TBM_ERR("error bo:%p bo_lock_type[%d] is wrong.\n",
269 bo, bo->bufmgr->bo_lock_type);
273 if (bo->lock_cnt < 0)
276 TBM_DBG(">> UNLOCK bo:%p(%d->%d)\n", bo, old, bo->lock_cnt);
280 _tbm_bo_magic_check(tbm_bo bo)
282 if (bo->magic != TBM_BO_MAGIC)
289 _tbm_bo_is_valid(tbm_bo bo)
292 TBM_ERR("error: bo is NULL.\n");
296 if (!_tbm_bo_magic_check(bo)) {
297 TBM_ERR("error: No valid bo(%p).\n", bo);
305 _tbm_bo_deinit(tbm_bo bo)
309 bo->bufmgr->bo_cnt--;
310 LIST_DEL(&bo->item_link);
314 tbm_bo_alloc(tbm_bufmgr bufmgr, int size, int flags)
319 _tbm_bufmgr_mutex_lock();
320 _tbm_set_last_result(TBM_ERROR_NONE);
322 TBM_BO_RETURN_VAL_IF_FAIL(TBM_BUFMGR_IS_VALID(bufmgr), NULL);
323 TBM_BO_RETURN_VAL_IF_FAIL(size > 0, NULL);
325 bo = tbm_bufmgr_internal_alloc_bo(bufmgr, size, flags, &error);
327 /* LCOV_EXCL_START */
328 TBM_ERR("tbm_bufmgr_internal_alloc_bo failed. error:%d", error);
329 _tbm_set_last_result(error);
330 _tbm_bufmgr_mutex_unlock();
335 TBM_TRACE_BO("bo(%p) size(%d) refcnt(%d), flag(%s)\n", bo, size, bo->ref_cnt,
336 _tbm_flag_to_str(bo->flags));
338 _tbm_bufmgr_mutex_unlock();
344 tbm_bo_ref(tbm_bo bo)
346 _tbm_bufmgr_mutex_lock();
347 _tbm_set_last_result(TBM_ERROR_NONE);
349 TBM_BO_RETURN_VAL_IF_FAIL(_tbm_bo_is_valid(bo), NULL);
353 TBM_TRACE_BO("bo(%p) ref_cnt(%d)\n", bo, bo->ref_cnt);
355 _tbm_bufmgr_mutex_unlock();
361 tbm_bo_unref(tbm_bo bo)
363 _tbm_bufmgr_mutex_lock();
364 _tbm_set_last_result(TBM_ERROR_NONE);
366 TBM_BO_RETURN_IF_FAIL(_tbm_bo_is_valid(bo));
368 TBM_TRACE_BO("bo(%p) ref_cnt(%d)\n", bo, bo->ref_cnt - 1);
370 if (bo->ref_cnt <= 0) {
371 _tbm_bufmgr_mutex_unlock();
376 if (bo->ref_cnt == 0)
379 _tbm_bufmgr_mutex_unlock();
383 tbm_bo_map(tbm_bo bo, int device, int opt)
385 tbm_bo_handle bo_handle;
388 _tbm_bufmgr_mutex_lock();
389 _tbm_set_last_result(TBM_ERROR_NONE);
391 TBM_BO_RETURN_VAL_IF_FAIL(_tbm_bo_is_valid(bo), (tbm_bo_handle) NULL);
393 if (!_tbm_bo_lock(bo, device, opt)) {
394 TBM_ERR("error: fail to lock bo:%p)\n", bo);
395 _tbm_bufmgr_mutex_unlock();
396 return (tbm_bo_handle) NULL;
399 bo_handle = tbm_module_bo_map(bo->bufmgr->module, bo, bo->bo_data, device, opt, &error);
400 if (bo_handle.ptr == NULL) {
401 /* LCOV_EXCL_START */
402 TBM_ERR("error: fail to map bo:%p error:%d\n", bo, error);
403 _tbm_set_last_result(error);
405 _tbm_bufmgr_mutex_unlock();
406 return (tbm_bo_handle) NULL;
410 /* increase the map_count */
413 TBM_TRACE_BO("bo(%p) map_cnt(%d)\n", bo, bo->map_cnt);
415 _tbm_bufmgr_mutex_unlock();
421 tbm_bo_unmap(tbm_bo bo)
425 _tbm_bufmgr_mutex_lock();
426 _tbm_set_last_result(TBM_ERROR_NONE);
428 TBM_BO_RETURN_VAL_IF_FAIL(_tbm_bo_is_valid(bo), 0);
429 TBM_BO_RETURN_VAL_IF_FAIL(bo->map_cnt > 0, 0);
431 error = tbm_module_bo_unmap(bo->bufmgr->module, bo, bo->bo_data);
432 if (error != TBM_ERROR_NONE) {
433 /* LCOV_EXCL_START */
434 TBM_ERR("error: bo(%p) map_cnt(%d) error(%d)\n", bo, bo->map_cnt, error);
435 _tbm_set_last_result(error);
436 _tbm_bufmgr_mutex_unlock();
441 /* decrease the map_count */
444 TBM_TRACE_BO("bo(%p) map_cnt(%d)\n", bo, bo->map_cnt);
448 _tbm_bufmgr_mutex_unlock();
454 tbm_bo_get_handle(tbm_bo bo, int device)
456 tbm_bo_handle bo_handle;
459 _tbm_bufmgr_mutex_lock();
460 _tbm_set_last_result(TBM_ERROR_NONE);
462 TBM_BO_RETURN_VAL_IF_FAIL(_tbm_bo_is_valid(bo), (tbm_bo_handle) NULL);
464 bo_handle = tbm_module_bo_get_handle(bo->bufmgr->module, bo, bo->bo_data, device, &error);
465 if (bo_handle.ptr == NULL) {
466 /* LCOV_EXCL_START */
467 TBM_ERR("error: bo(%p) bo_handle(%p) error(%d)\n", bo, bo_handle.ptr, error);
468 _tbm_set_last_result(error);
469 _tbm_bufmgr_mutex_unlock();
470 return (tbm_bo_handle)NULL;
474 TBM_TRACE_BO("bo(%p) bo_handle(%p)\n", bo, bo_handle.ptr);
476 _tbm_bufmgr_mutex_unlock();
482 tbm_bo_export(tbm_bo bo)
487 _tbm_bufmgr_mutex_lock();
488 _tbm_set_last_result(TBM_ERROR_NONE);
490 TBM_BO_RETURN_VAL_IF_FAIL(_tbm_bo_is_valid(bo), 0);
492 if (bo->bufmgr->use_hal_tbm) {
493 ret = (hal_tbm_key)hal_tbm_bo_export_key((hal_tbm_bo *)bo->bo_data, (hal_tbm_error *)&error);
495 /* LCOV_EXCL_START */
496 TBM_ERR("error: bo(%p) tbm_key(%d) error(%d)\n", bo, ret, error);
497 _tbm_set_last_result(error);
501 } else if (bo->bufmgr->backend_module_data) {
502 if (!bo->bufmgr->bo_func->bo_export_key) {
503 /* LCOV_EXCL_START */
504 _tbm_bufmgr_mutex_unlock();
505 _tbm_set_last_result(TBM_ERROR_NOT_SUPPORTED);
510 ret = bo->bufmgr->bo_func->bo_export_key(bo->bo_data, &error);
512 /* LCOV_EXCL_START */
513 TBM_ERR("error: bo(%p) tbm_key(%d) error(%d)\n", bo, ret, error);
514 _tbm_set_last_result(error);
519 if (!bo->bufmgr->backend->bo_export) {
520 /* LCOV_EXCL_START */
521 _tbm_bufmgr_mutex_unlock();
522 _tbm_set_last_result(TBM_ERROR_NOT_SUPPORTED);
527 ret = bo->bufmgr->backend->bo_export(bo);
529 /* LCOV_EXCL_START */
530 TBM_ERR("error: bo(%p) tbm_key(%d)\n", bo, ret);
531 _tbm_set_last_result(TBM_ERROR_INVALID_OPERATION);
537 TBM_TRACE_BO("bo(%p) tbm_key(%u)\n", bo, ret);
540 _tbm_bufmgr_mutex_unlock();
546 tbm_bo_export_fd(tbm_bo bo)
551 _tbm_bufmgr_mutex_lock();
552 _tbm_set_last_result(TBM_ERROR_NONE);
554 TBM_BO_RETURN_VAL_IF_FAIL(_tbm_bo_is_valid(bo), -1);
556 if (bo->bufmgr->use_hal_tbm) {
557 ret = (hal_tbm_fd)hal_tbm_bo_export_fd((hal_tbm_bo *)bo->bo_data, (hal_tbm_error *)&error);
559 /* LCOV_EXCL_START */
560 TBM_ERR("error: bo(%p) tbm_fd(%d) error(%d)\n", bo, ret, error);
561 _tbm_set_last_result(error);
565 } else if (bo->bufmgr->backend_module_data) {
566 if (!bo->bufmgr->bo_func->bo_export_fd) {
567 /* LCOV_EXCL_START */
568 _tbm_bufmgr_mutex_unlock();
569 _tbm_set_last_result(TBM_ERROR_NOT_SUPPORTED);
574 ret = bo->bufmgr->bo_func->bo_export_fd(bo->bo_data, &error);
576 /* LCOV_EXCL_START */
577 TBM_ERR("error: bo(%p) tbm_fd(%d) error(%d)\n", bo, ret, error);
578 _tbm_set_last_result(error);
583 if (!bo->bufmgr->backend->bo_export_fd) {
584 /* LCOV_EXCL_START */
585 _tbm_bufmgr_mutex_unlock();
586 _tbm_set_last_result(TBM_ERROR_NOT_SUPPORTED);
591 ret = bo->bufmgr->backend->bo_export_fd(bo);
593 /* LCOV_EXCL_START */
594 TBM_ERR("error: bo(%p) tbm_fd(%d)\n", bo, ret);
595 _tbm_set_last_result(TBM_ERROR_INVALID_OPERATION);
601 TBM_TRACE_BO("bo(%p) tbm_fd(%d)\n", bo, ret);
604 _tbm_bufmgr_mutex_unlock();
610 tbm_bo_import(tbm_bufmgr bufmgr, unsigned int key)
615 _tbm_bufmgr_mutex_lock();
616 _tbm_set_last_result(TBM_ERROR_NONE);
618 TBM_BO_RETURN_VAL_IF_FAIL(TBM_BUFMGR_IS_VALID(bufmgr), NULL);
620 bo = tbm_bufmgr_internal_import_bo_with_key(bufmgr, key, &error);
622 /* LCOV_EXCL_START */
623 TBM_ERR("tbm_bufmgr_internal_import_key failed. error:%d", error);
624 _tbm_set_last_result(error);
625 _tbm_bufmgr_mutex_unlock();
630 TBM_TRACE_BO("import new bo(%p) ref(%d) key(%d) flag(%s) in list\n",
631 bo, bo->ref_cnt, key, _tbm_flag_to_str(bo->flags));
633 _tbm_bufmgr_mutex_unlock();
639 tbm_bo_import_fd(tbm_bufmgr bufmgr, tbm_fd fd)
644 _tbm_bufmgr_mutex_lock();
645 _tbm_set_last_result(TBM_ERROR_NONE);
647 TBM_BO_RETURN_VAL_IF_FAIL(TBM_BUFMGR_IS_VALID(bufmgr), NULL);
649 bo = tbm_bufmgr_internal_import_bo_with_fd(bufmgr, fd, &error);
651 /* LCOV_EXCL_START */
652 TBM_ERR("tbm_bufmgr_internal_import_fd failed. error:%d", error);
653 _tbm_set_last_result(error);
654 _tbm_bufmgr_mutex_unlock();
659 LIST_INITHEAD(&bo->user_data_list); // TODO: remove this. build-break when it is removed.
661 TBM_TRACE_BO("import bo(%p) ref(%d) fd(%d) flag(%s)\n",
662 bo, bo->ref_cnt, fd, _tbm_flag_to_str(bo->flags));
664 _tbm_bufmgr_mutex_unlock();
670 tbm_bo_size(tbm_bo bo)
675 _tbm_bufmgr_mutex_lock();
676 _tbm_set_last_result(TBM_ERROR_NONE);
678 TBM_BO_RETURN_VAL_IF_FAIL(_tbm_bo_is_valid(bo), 0);
680 size = tbm_module_bo_get_size(bo->bufmgr->module, bo, bo->bo_data, &error);
681 _tbm_set_last_result(error);
683 TBM_TRACE_BO("bo(%p) size(%d)\n", bo, size);
685 _tbm_bufmgr_mutex_unlock();
691 tbm_bo_locked(tbm_bo bo)
693 _tbm_bufmgr_mutex_lock();
694 _tbm_set_last_result(TBM_ERROR_NONE);
696 TBM_BO_RETURN_VAL_IF_FAIL(_tbm_bo_is_valid(bo), 0);
698 if (bo->bufmgr->bo_lock_type == TBM_BUFMGR_BO_LOCK_TYPE_NEVER) {
699 TBM_ERR("bo(%p) lock_cnt(%d)\n", bo, bo->lock_cnt);
700 _tbm_set_last_result(TBM_ERROR_INVALID_OPERATION);
701 _tbm_bufmgr_mutex_unlock();
705 if (bo->lock_cnt > 0) {
706 TBM_TRACE_BO("error: bo(%p) lock_cnt(%d)\n", bo, bo->lock_cnt);
707 _tbm_bufmgr_mutex_unlock();
711 TBM_TRACE_BO("bo(%p) lock_cnt(%d)\n", bo, bo->lock_cnt);
712 _tbm_bufmgr_mutex_unlock();
718 tbm_bo_swap(tbm_bo bo1, tbm_bo bo2)
720 tbm_error_e error1, error2;
721 int size1 = -1, size2 = -2;
724 _tbm_bufmgr_mutex_lock();
725 _tbm_set_last_result(TBM_ERROR_NONE);
727 TBM_BO_RETURN_VAL_IF_FAIL(_tbm_bo_is_valid(bo1), 0);
728 TBM_BO_RETURN_VAL_IF_FAIL(_tbm_bo_is_valid(bo2), 0);
730 TBM_TRACE_BO("before: bo1(%p) bo2(%p)\n", bo1, bo2);
732 size1 = tbm_module_bo_get_size(bo1->bufmgr->module, bo1, bo1->bo_data, &error1);
733 _tbm_set_last_result(error1);
734 size2 = tbm_module_bo_get_size(bo2->bufmgr->module, bo2, bo2->bo_data, &error2);
735 _tbm_set_last_result(error2);
737 if (size1 != size2) {
738 TBM_ERR("error: bo1 size(%d) and bo2 size(%d) is different.", size1, size2);
739 _tbm_set_last_result(TBM_ERROR_INVALID_OPERATION);
743 TBM_TRACE_BO("after: bo1(%p) bo2(%p)\n", bo1, bo2);
746 bo1->priv = bo2->priv;
749 _tbm_bufmgr_mutex_unlock();
754 TBM_ERR("error: bo1(%p) bo2(%p)\n", bo1, bo2);
755 _tbm_bufmgr_mutex_unlock();
761 tbm_bo_add_user_data(tbm_bo bo, unsigned long key,
762 tbm_data_free data_free_func)
766 _tbm_bufmgr_mutex_lock();
767 _tbm_set_last_result(TBM_ERROR_NONE);
769 TBM_BO_RETURN_VAL_IF_FAIL(_tbm_bo_is_valid(bo), 0);
771 /* check if the data according to the key exist if so, return false. */
772 data = user_data_lookup(&bo->user_data_list, key);
774 TBM_TRACE_BO("warning: user data already exist key(%ld)\n", key);
775 _tbm_set_last_result(TBM_ERROR_INVALID_PARAMETER);
776 _tbm_bufmgr_mutex_unlock();
780 data = user_data_create(key, data_free_func);
782 TBM_ERR("error: bo(%p) key(%lu)\n", bo, key);
783 _tbm_set_last_result(TBM_ERROR_INVALID_PARAMETER);
784 _tbm_bufmgr_mutex_unlock();
788 TBM_TRACE_BO("bo(%p) key(%lu) data(%p)\n", bo, key, data->data);
790 LIST_ADD(&data->item_link, &bo->user_data_list);
792 _tbm_bufmgr_mutex_unlock();
798 tbm_bo_delete_user_data(tbm_bo bo, unsigned long key)
800 tbm_user_data *old_data;
802 _tbm_bufmgr_mutex_lock();
803 _tbm_set_last_result(TBM_ERROR_NONE);
805 TBM_BO_RETURN_VAL_IF_FAIL(_tbm_bo_is_valid(bo), 0);
807 if (LIST_IS_EMPTY(&bo->user_data_list)) {
808 TBM_TRACE_BO("bo(%p) key(%lu)\n", bo, key);
809 _tbm_set_last_result(TBM_ERROR_INVALID_PARAMETER);
810 _tbm_bufmgr_mutex_unlock();
814 old_data = user_data_lookup(&bo->user_data_list, key);
816 TBM_TRACE_BO("bo(%p) key(%lu)\n", bo, key);
817 _tbm_set_last_result(TBM_ERROR_INVALID_PARAMETER);
818 _tbm_bufmgr_mutex_unlock();
822 TBM_TRACE_BO("bo(%p) key(%lu) data(%p)\n", bo, key, old_data->data);
824 user_data_delete(old_data);
826 _tbm_bufmgr_mutex_unlock();
832 tbm_bo_set_user_data(tbm_bo bo, unsigned long key, void *data)
834 tbm_user_data *old_data;
836 _tbm_bufmgr_mutex_lock();
837 _tbm_set_last_result(TBM_ERROR_NONE);
839 TBM_BO_RETURN_VAL_IF_FAIL(_tbm_bo_is_valid(bo), 0);
841 if (LIST_IS_EMPTY(&bo->user_data_list)) {
842 TBM_TRACE_BO("error: bo(%p) key(%lu)\n", bo, key);
843 _tbm_set_last_result(TBM_ERROR_INVALID_PARAMETER);
844 _tbm_bufmgr_mutex_unlock();
848 old_data = user_data_lookup(&bo->user_data_list, key);
850 TBM_TRACE_BO("error: bo(%p) key(%lu)\n", bo, key);
851 _tbm_set_last_result(TBM_ERROR_INVALID_PARAMETER);
852 _tbm_bufmgr_mutex_unlock();
856 if (old_data->data && old_data->free_func)
857 old_data->free_func(old_data->data);
858 old_data->data = data;
860 TBM_TRACE_BO("bo(%p) key(%lu) data(%p)\n", bo, key, old_data->data);
862 _tbm_bufmgr_mutex_unlock();
868 tbm_bo_get_user_data(tbm_bo bo, unsigned long key, void **data)
870 tbm_user_data *old_data;
872 _tbm_bufmgr_mutex_lock();
873 _tbm_set_last_result(TBM_ERROR_NONE);
875 TBM_BO_RETURN_VAL_IF_FAIL(_tbm_bo_is_valid(bo), 0);
877 if (!data || LIST_IS_EMPTY(&bo->user_data_list)) {
878 TBM_TRACE_BO("error: bo(%p) key(%lu)\n", bo, key);
879 _tbm_set_last_result(TBM_ERROR_INVALID_PARAMETER);
880 _tbm_bufmgr_mutex_unlock();
884 old_data = user_data_lookup(&bo->user_data_list, key);
887 TBM_TRACE_BO("error: bo(%p) key(%lu)\n", bo, key);
888 _tbm_set_last_result(TBM_ERROR_INVALID_PARAMETER);
889 _tbm_bufmgr_mutex_unlock();
893 *data = old_data->data;
895 TBM_TRACE_BO("bo(%p) key(%lu) data(%p)\n", bo, key, old_data->data);
897 _tbm_bufmgr_mutex_unlock();
903 tbm_bo_get_flags(tbm_bo bo)
907 _tbm_bufmgr_mutex_lock();
909 TBM_BO_RETURN_VAL_IF_FAIL(_tbm_bo_is_valid(bo), 0);
913 TBM_TRACE_BO("bo(%p)\n", bo);
915 _tbm_bufmgr_mutex_unlock();
920 /* LCOV_EXCL_START */
921 /* internal function */
923 _tbm_bo_set_surface(tbm_bo bo, tbm_surface_h surface)
925 _tbm_bufmgr_mutex_lock();
927 TBM_BO_RETURN_VAL_IF_FAIL(_tbm_bo_is_valid(bo), 0);
929 bo->surface = surface;
931 _tbm_bufmgr_mutex_unlock();
937 _tbm_bo_free(tbm_bo bo)
939 /* destory the user_data_list */
940 if (!LIST_IS_EMPTY(&bo->user_data_list)) {
941 tbm_user_data *old_data = NULL, *tmp;
943 LIST_FOR_EACH_ENTRY_SAFE(old_data, tmp,
944 &bo->user_data_list, item_link) {
945 TBM_DBG("free user_data\n");
946 user_data_delete(old_data);
950 while (bo->lock_cnt > 0) {
951 TBM_ERR("error lock_cnt:%d\n", bo->lock_cnt);
956 tbm_module_bo_free(bo->bufmgr->module, bo, bo->bo_data, bo->get_from_hal_surface);