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 if (bo->bufmgr->use_hal_tbm) {
145 error = (tbm_error_e)hal_tbm_bo_lock((hal_tbm_bo *)bo->bo_data, device, opt);
146 if (error == TBM_ERROR_NOT_SUPPORTED) {
147 _tbm_set_last_result(TBM_ERROR_NONE);
149 if (error != TBM_ERROR_NONE) {
150 TBM_WRN("fail to lock");
151 _tbm_set_last_result(error);
155 } else if (bo->bufmgr->backend_module_data) {
156 if (bo->bufmgr->bo_func->bo_lock) {
157 error = bo->bufmgr->bo_func->bo_lock(bo->bo_data, device, opt);
158 if (error != TBM_ERROR_NONE) {
159 TBM_WRN("fail to lock");
160 _tbm_set_last_result(error);
165 if (bo->bufmgr->backend->bo_lock) {
166 ret = bo->bufmgr->backend->bo_lock(bo, device, opt);
168 _tbm_set_last_result(TBM_ERROR_INVALID_OPERATION);
176 _bo_unlock(tbm_bo bo)
180 if (bo->bufmgr->use_hal_tbm) {
181 error = (tbm_error_e)hal_tbm_bo_unlock((hal_tbm_bo *)bo->bo_data);
182 if (error == TBM_ERROR_NOT_SUPPORTED) {
183 _tbm_set_last_result(TBM_ERROR_NONE);
185 if (error != TBM_ERROR_NONE) {
186 TBM_WRN("fail to lock");
187 _tbm_set_last_result(error);
190 } else if (bo->bufmgr->backend_module_data) {
191 if (bo->bufmgr->bo_func->bo_unlock) {
192 error = bo->bufmgr->bo_func->bo_unlock(bo->bo_data);
193 if (error != TBM_ERROR_NONE) {
194 TBM_WRN("fail to unlock");
195 _tbm_set_last_result(error);
199 if (bo->bufmgr->backend->bo_unlock)
200 bo->bufmgr->backend->bo_unlock(bo);
205 _tbm_bo_lock(tbm_bo bo, int device, int opt)
212 /* do not try to lock the bo */
213 if (bo->bufmgr->bo_lock_type == TBM_BUFMGR_BO_LOCK_TYPE_NEVER)
216 if (bo->lock_cnt < 0) {
217 TBM_ERR("error bo:%p LOCK_CNT=%d\n",
224 switch (bo->bufmgr->bo_lock_type) {
225 case TBM_BUFMGR_BO_LOCK_TYPE_ONCE:
226 if (bo->lock_cnt == 0) {
227 _tbm_bufmgr_mutex_unlock();
228 ret = _bo_lock(bo, device, opt);
229 _tbm_bufmgr_mutex_lock();
235 case TBM_BUFMGR_BO_LOCK_TYPE_ALWAYS:
236 _tbm_bufmgr_mutex_unlock();
237 ret = _bo_lock(bo, device, opt);
238 _tbm_bufmgr_mutex_lock();
243 TBM_ERR("error bo:%p bo_lock_type[%d] is wrong.\n",
244 bo, bo->bufmgr->bo_lock_type);
249 TBM_DBG(">> LOCK bo:%p(%d->%d)\n", bo, old, bo->lock_cnt);
255 _tbm_bo_unlock(tbm_bo bo)
259 /* do not try to unlock the bo */
260 if (bo->bufmgr->bo_lock_type == TBM_BUFMGR_BO_LOCK_TYPE_NEVER)
265 switch (bo->bufmgr->bo_lock_type) {
266 case TBM_BUFMGR_BO_LOCK_TYPE_ONCE:
267 if (bo->lock_cnt > 0) {
269 if (bo->lock_cnt == 0)
273 case TBM_BUFMGR_BO_LOCK_TYPE_ALWAYS:
274 if (bo->lock_cnt > 0) {
280 TBM_ERR("error bo:%p bo_lock_type[%d] is wrong.\n",
281 bo, bo->bufmgr->bo_lock_type);
285 if (bo->lock_cnt < 0)
288 TBM_DBG(">> UNLOCK bo:%p(%d->%d)\n", bo, old, bo->lock_cnt);
292 _tbm_bo_magic_check(tbm_bo bo)
294 if (bo->magic != TBM_BO_MAGIC)
301 _tbm_bo_is_valid(tbm_bo bo)
304 TBM_ERR("error: bo is NULL.\n");
308 if (!_tbm_bo_magic_check(bo)) {
309 TBM_ERR("error: No valid bo(%p).\n", bo);
317 _tbm_bo_deinit(tbm_bo bo)
321 bo->bufmgr->bo_cnt--;
322 LIST_DEL(&bo->item_link);
326 tbm_bo_alloc(tbm_bufmgr bufmgr, int size, int flags)
331 _tbm_bufmgr_mutex_lock();
332 _tbm_set_last_result(TBM_ERROR_NONE);
334 TBM_BO_RETURN_VAL_IF_FAIL(TBM_BUFMGR_IS_VALID(bufmgr), NULL);
335 TBM_BO_RETURN_VAL_IF_FAIL(size > 0, NULL);
337 bo = tbm_bufmgr_internal_alloc_bo(bufmgr, size, flags, &error);
339 /* LCOV_EXCL_START */
340 TBM_ERR("tbm_bufmgr_internal_alloc_bo failed. error:%d", error);
341 _tbm_set_last_result(error);
342 _tbm_bufmgr_mutex_unlock();
347 TBM_TRACE_BO("bo(%p) size(%d) refcnt(%d), flag(%s)\n", bo, size, bo->ref_cnt,
348 _tbm_flag_to_str(bo->flags));
350 _tbm_bufmgr_mutex_unlock();
356 tbm_bo_ref(tbm_bo bo)
358 _tbm_bufmgr_mutex_lock();
359 _tbm_set_last_result(TBM_ERROR_NONE);
361 TBM_BO_RETURN_VAL_IF_FAIL(_tbm_bo_is_valid(bo), NULL);
365 TBM_TRACE_BO("bo(%p) ref_cnt(%d)\n", bo, bo->ref_cnt);
367 _tbm_bufmgr_mutex_unlock();
373 tbm_bo_unref(tbm_bo bo)
375 _tbm_bufmgr_mutex_lock();
376 _tbm_set_last_result(TBM_ERROR_NONE);
378 TBM_BO_RETURN_IF_FAIL(_tbm_bo_is_valid(bo));
380 TBM_TRACE_BO("bo(%p) ref_cnt(%d)\n", bo, bo->ref_cnt - 1);
382 if (bo->ref_cnt <= 0) {
383 _tbm_bufmgr_mutex_unlock();
388 if (bo->ref_cnt == 0)
391 _tbm_bufmgr_mutex_unlock();
395 tbm_bo_map(tbm_bo bo, int device, int opt)
397 tbm_bo_handle bo_handle;
400 _tbm_bufmgr_mutex_lock();
401 _tbm_set_last_result(TBM_ERROR_NONE);
403 TBM_BO_RETURN_VAL_IF_FAIL(_tbm_bo_is_valid(bo), (tbm_bo_handle) NULL);
405 if (!_tbm_bo_lock(bo, device, opt)) {
406 TBM_ERR("error: fail to lock bo:%p)\n", bo);
407 _tbm_bufmgr_mutex_unlock();
408 return (tbm_bo_handle) NULL;
411 bo_handle = tbm_module_bo_map(bo->bufmgr->module, bo, bo->bo_data, device, opt, &error);
412 if (bo_handle.ptr == NULL) {
413 /* LCOV_EXCL_START */
414 TBM_ERR("error: fail to map bo:%p error:%d\n", bo, error);
415 _tbm_set_last_result(error);
417 _tbm_bufmgr_mutex_unlock();
418 return (tbm_bo_handle) NULL;
422 /* increase the map_count */
425 TBM_TRACE_BO("bo(%p) map_cnt(%d)\n", bo, bo->map_cnt);
427 _tbm_bufmgr_mutex_unlock();
433 tbm_bo_unmap(tbm_bo bo)
438 _tbm_bufmgr_mutex_lock();
439 _tbm_set_last_result(TBM_ERROR_NONE);
441 TBM_BO_RETURN_VAL_IF_FAIL(_tbm_bo_is_valid(bo), 0);
442 TBM_BO_RETURN_VAL_IF_FAIL(bo->map_cnt > 0, 0);
444 if (bo->bufmgr->use_hal_tbm) {
445 error = (hal_tbm_error)hal_tbm_bo_unmap((hal_tbm_bo *)bo->bo_data);
446 if (error != TBM_ERROR_NONE) {
447 /* LCOV_EXCL_START */
448 TBM_ERR("error: bo(%p) map_cnt(%d) error(%d)\n", bo, bo->map_cnt, error);
449 _tbm_set_last_result(error);
454 } else if (bo->bufmgr->backend_module_data) {
455 error = bo->bufmgr->bo_func->bo_unmap(bo->bo_data);
456 if (error != TBM_ERROR_NONE) {
457 /* LCOV_EXCL_START */
458 TBM_ERR("error: bo(%p) map_cnt(%d) error(%d)\n", bo, bo->map_cnt, error);
459 _tbm_set_last_result(error);
465 ret = bo->bufmgr->backend->bo_unmap(bo);
467 /* LCOV_EXCL_START */
468 TBM_ERR("error: bo(%p) map_cnt(%d)\n", bo, bo->map_cnt);
469 _tbm_set_last_result(TBM_ERROR_INVALID_OPERATION);
475 /* decrease the map_count */
478 TBM_TRACE_BO("bo(%p) map_cnt(%d)\n", bo, bo->map_cnt);
483 _tbm_bufmgr_mutex_unlock();
489 tbm_bo_get_handle(tbm_bo bo, int device)
491 tbm_bo_handle bo_handle;
494 _tbm_bufmgr_mutex_lock();
495 _tbm_set_last_result(TBM_ERROR_NONE);
497 TBM_BO_RETURN_VAL_IF_FAIL(_tbm_bo_is_valid(bo), (tbm_bo_handle) NULL);
499 bo_handle = tbm_module_bo_get_handle(bo->bufmgr->module, bo, bo->bo_data, device, &error);
500 if (bo_handle.ptr == NULL) {
501 /* LCOV_EXCL_START */
502 TBM_ERR("error: bo(%p) bo_handle(%p) error(%d)\n", bo, bo_handle.ptr, error);
503 _tbm_set_last_result(error);
504 _tbm_bufmgr_mutex_unlock();
505 return (tbm_bo_handle)NULL;
509 TBM_TRACE_BO("bo(%p) bo_handle(%p)\n", bo, bo_handle.ptr);
511 _tbm_bufmgr_mutex_unlock();
517 tbm_bo_export(tbm_bo bo)
522 _tbm_bufmgr_mutex_lock();
523 _tbm_set_last_result(TBM_ERROR_NONE);
525 TBM_BO_RETURN_VAL_IF_FAIL(_tbm_bo_is_valid(bo), 0);
527 if (bo->bufmgr->use_hal_tbm) {
528 ret = (hal_tbm_key)hal_tbm_bo_export_key((hal_tbm_bo *)bo->bo_data, (hal_tbm_error *)&error);
530 /* LCOV_EXCL_START */
531 TBM_ERR("error: bo(%p) tbm_key(%d) error(%d)\n", bo, ret, error);
532 _tbm_set_last_result(error);
536 } else if (bo->bufmgr->backend_module_data) {
537 if (!bo->bufmgr->bo_func->bo_export_key) {
538 /* LCOV_EXCL_START */
539 _tbm_bufmgr_mutex_unlock();
540 _tbm_set_last_result(TBM_ERROR_NOT_SUPPORTED);
545 ret = bo->bufmgr->bo_func->bo_export_key(bo->bo_data, &error);
547 /* LCOV_EXCL_START */
548 TBM_ERR("error: bo(%p) tbm_key(%d) error(%d)\n", bo, ret, error);
549 _tbm_set_last_result(error);
554 if (!bo->bufmgr->backend->bo_export) {
555 /* LCOV_EXCL_START */
556 _tbm_bufmgr_mutex_unlock();
557 _tbm_set_last_result(TBM_ERROR_NOT_SUPPORTED);
562 ret = bo->bufmgr->backend->bo_export(bo);
564 /* LCOV_EXCL_START */
565 TBM_ERR("error: bo(%p) tbm_key(%d)\n", bo, ret);
566 _tbm_set_last_result(TBM_ERROR_INVALID_OPERATION);
572 TBM_TRACE_BO("bo(%p) tbm_key(%u)\n", bo, ret);
575 _tbm_bufmgr_mutex_unlock();
581 tbm_bo_export_fd(tbm_bo bo)
586 _tbm_bufmgr_mutex_lock();
587 _tbm_set_last_result(TBM_ERROR_NONE);
589 TBM_BO_RETURN_VAL_IF_FAIL(_tbm_bo_is_valid(bo), -1);
591 if (bo->bufmgr->use_hal_tbm) {
592 ret = (hal_tbm_fd)hal_tbm_bo_export_fd((hal_tbm_bo *)bo->bo_data, (hal_tbm_error *)&error);
594 /* LCOV_EXCL_START */
595 TBM_ERR("error: bo(%p) tbm_fd(%d) error(%d)\n", bo, ret, error);
596 _tbm_set_last_result(error);
600 } else if (bo->bufmgr->backend_module_data) {
601 if (!bo->bufmgr->bo_func->bo_export_fd) {
602 /* LCOV_EXCL_START */
603 _tbm_bufmgr_mutex_unlock();
604 _tbm_set_last_result(TBM_ERROR_NOT_SUPPORTED);
609 ret = bo->bufmgr->bo_func->bo_export_fd(bo->bo_data, &error);
611 /* LCOV_EXCL_START */
612 TBM_ERR("error: bo(%p) tbm_fd(%d) error(%d)\n", bo, ret, error);
613 _tbm_set_last_result(error);
618 if (!bo->bufmgr->backend->bo_export_fd) {
619 /* LCOV_EXCL_START */
620 _tbm_bufmgr_mutex_unlock();
621 _tbm_set_last_result(TBM_ERROR_NOT_SUPPORTED);
626 ret = bo->bufmgr->backend->bo_export_fd(bo);
628 /* LCOV_EXCL_START */
629 TBM_ERR("error: bo(%p) tbm_fd(%d)\n", bo, ret);
630 _tbm_set_last_result(TBM_ERROR_INVALID_OPERATION);
636 TBM_TRACE_BO("bo(%p) tbm_fd(%d)\n", bo, ret);
639 _tbm_bufmgr_mutex_unlock();
645 tbm_bo_import(tbm_bufmgr bufmgr, unsigned int key)
650 _tbm_bufmgr_mutex_lock();
651 _tbm_set_last_result(TBM_ERROR_NONE);
653 TBM_BO_RETURN_VAL_IF_FAIL(TBM_BUFMGR_IS_VALID(bufmgr), NULL);
655 bo = tbm_bufmgr_internal_import_bo_with_key(bufmgr, key, &error);
657 /* LCOV_EXCL_START */
658 TBM_ERR("tbm_bufmgr_internal_import_key failed. error:%d", error);
659 _tbm_set_last_result(error);
660 _tbm_bufmgr_mutex_unlock();
665 TBM_TRACE_BO("import new bo(%p) ref(%d) key(%d) flag(%s) in list\n",
666 bo, bo->ref_cnt, key, _tbm_flag_to_str(bo->flags));
668 _tbm_bufmgr_mutex_unlock();
674 tbm_bo_import_fd(tbm_bufmgr bufmgr, tbm_fd fd)
679 _tbm_bufmgr_mutex_lock();
680 _tbm_set_last_result(TBM_ERROR_NONE);
682 TBM_BO_RETURN_VAL_IF_FAIL(TBM_BUFMGR_IS_VALID(bufmgr), NULL);
684 bo = tbm_bufmgr_internal_import_bo_with_fd(bufmgr, fd, &error);
686 /* LCOV_EXCL_START */
687 TBM_ERR("tbm_bufmgr_internal_import_fd failed. error:%d", error);
688 _tbm_set_last_result(error);
689 _tbm_bufmgr_mutex_unlock();
694 LIST_INITHEAD(&bo->user_data_list); // TODO: remove this. build-break when it is removed.
696 TBM_TRACE_BO("import bo(%p) ref(%d) fd(%d) flag(%s)\n",
697 bo, bo->ref_cnt, fd, _tbm_flag_to_str(bo->flags));
699 _tbm_bufmgr_mutex_unlock();
705 tbm_bo_size(tbm_bo bo)
710 _tbm_bufmgr_mutex_lock();
711 _tbm_set_last_result(TBM_ERROR_NONE);
713 TBM_BO_RETURN_VAL_IF_FAIL(_tbm_bo_is_valid(bo), 0);
715 size = tbm_module_bo_get_size(bo->bufmgr->module, bo, bo->bo_data, &error);
716 _tbm_set_last_result(error);
718 TBM_TRACE_BO("bo(%p) size(%d)\n", bo, size);
720 _tbm_bufmgr_mutex_unlock();
726 tbm_bo_locked(tbm_bo bo)
728 _tbm_bufmgr_mutex_lock();
729 _tbm_set_last_result(TBM_ERROR_NONE);
731 TBM_BO_RETURN_VAL_IF_FAIL(_tbm_bo_is_valid(bo), 0);
733 if (bo->bufmgr->bo_lock_type == TBM_BUFMGR_BO_LOCK_TYPE_NEVER) {
734 TBM_ERR("bo(%p) lock_cnt(%d)\n", bo, bo->lock_cnt);
735 _tbm_set_last_result(TBM_ERROR_INVALID_OPERATION);
736 _tbm_bufmgr_mutex_unlock();
740 if (bo->lock_cnt > 0) {
741 TBM_TRACE_BO("error: bo(%p) lock_cnt(%d)\n", bo, bo->lock_cnt);
742 _tbm_bufmgr_mutex_unlock();
746 TBM_TRACE_BO("bo(%p) lock_cnt(%d)\n", bo, bo->lock_cnt);
747 _tbm_bufmgr_mutex_unlock();
753 tbm_bo_swap(tbm_bo bo1, tbm_bo bo2)
755 tbm_error_e error1, error2;
756 int size1 = -1, size2 = -2;
759 _tbm_bufmgr_mutex_lock();
760 _tbm_set_last_result(TBM_ERROR_NONE);
762 TBM_BO_RETURN_VAL_IF_FAIL(_tbm_bo_is_valid(bo1), 0);
763 TBM_BO_RETURN_VAL_IF_FAIL(_tbm_bo_is_valid(bo2), 0);
765 TBM_TRACE_BO("before: bo1(%p) bo2(%p)\n", bo1, bo2);
767 size1 = tbm_module_bo_get_size(bo1->bufmgr->module, bo1, bo1->bo_data, &error1);
768 _tbm_set_last_result(error1);
769 size2 = tbm_module_bo_get_size(bo2->bufmgr->module, bo2, bo2->bo_data, &error2);
770 _tbm_set_last_result(error2);
772 if (size1 != size2) {
773 TBM_ERR("error: bo1 size(%d) and bo2 size(%d) is different.", size1, size2);
774 _tbm_set_last_result(TBM_ERROR_INVALID_OPERATION);
778 TBM_TRACE_BO("after: bo1(%p) bo2(%p)\n", bo1, bo2);
781 bo1->priv = bo2->priv;
784 _tbm_bufmgr_mutex_unlock();
789 TBM_ERR("error: bo1(%p) bo2(%p)\n", bo1, bo2);
790 _tbm_bufmgr_mutex_unlock();
796 tbm_bo_add_user_data(tbm_bo bo, unsigned long key,
797 tbm_data_free data_free_func)
801 _tbm_bufmgr_mutex_lock();
802 _tbm_set_last_result(TBM_ERROR_NONE);
804 TBM_BO_RETURN_VAL_IF_FAIL(_tbm_bo_is_valid(bo), 0);
806 /* check if the data according to the key exist if so, return false. */
807 data = user_data_lookup(&bo->user_data_list, key);
809 TBM_TRACE_BO("warning: user data already exist key(%ld)\n", key);
810 _tbm_set_last_result(TBM_ERROR_INVALID_PARAMETER);
811 _tbm_bufmgr_mutex_unlock();
815 data = user_data_create(key, data_free_func);
817 TBM_ERR("error: bo(%p) key(%lu)\n", bo, key);
818 _tbm_set_last_result(TBM_ERROR_INVALID_PARAMETER);
819 _tbm_bufmgr_mutex_unlock();
823 TBM_TRACE_BO("bo(%p) key(%lu) data(%p)\n", bo, key, data->data);
825 LIST_ADD(&data->item_link, &bo->user_data_list);
827 _tbm_bufmgr_mutex_unlock();
833 tbm_bo_delete_user_data(tbm_bo bo, unsigned long key)
835 tbm_user_data *old_data;
837 _tbm_bufmgr_mutex_lock();
838 _tbm_set_last_result(TBM_ERROR_NONE);
840 TBM_BO_RETURN_VAL_IF_FAIL(_tbm_bo_is_valid(bo), 0);
842 if (LIST_IS_EMPTY(&bo->user_data_list)) {
843 TBM_TRACE_BO("bo(%p) key(%lu)\n", bo, key);
844 _tbm_set_last_result(TBM_ERROR_INVALID_PARAMETER);
845 _tbm_bufmgr_mutex_unlock();
849 old_data = user_data_lookup(&bo->user_data_list, key);
851 TBM_TRACE_BO("bo(%p) key(%lu)\n", bo, key);
852 _tbm_set_last_result(TBM_ERROR_INVALID_PARAMETER);
853 _tbm_bufmgr_mutex_unlock();
857 TBM_TRACE_BO("bo(%p) key(%lu) data(%p)\n", bo, key, old_data->data);
859 user_data_delete(old_data);
861 _tbm_bufmgr_mutex_unlock();
867 tbm_bo_set_user_data(tbm_bo bo, unsigned long key, void *data)
869 tbm_user_data *old_data;
871 _tbm_bufmgr_mutex_lock();
872 _tbm_set_last_result(TBM_ERROR_NONE);
874 TBM_BO_RETURN_VAL_IF_FAIL(_tbm_bo_is_valid(bo), 0);
876 if (LIST_IS_EMPTY(&bo->user_data_list)) {
877 TBM_TRACE_BO("error: bo(%p) key(%lu)\n", bo, key);
878 _tbm_set_last_result(TBM_ERROR_INVALID_PARAMETER);
879 _tbm_bufmgr_mutex_unlock();
883 old_data = user_data_lookup(&bo->user_data_list, key);
885 TBM_TRACE_BO("error: bo(%p) key(%lu)\n", bo, key);
886 _tbm_set_last_result(TBM_ERROR_INVALID_PARAMETER);
887 _tbm_bufmgr_mutex_unlock();
891 if (old_data->data && old_data->free_func)
892 old_data->free_func(old_data->data);
893 old_data->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_user_data(tbm_bo bo, unsigned long key, void **data)
905 tbm_user_data *old_data;
907 _tbm_bufmgr_mutex_lock();
908 _tbm_set_last_result(TBM_ERROR_NONE);
910 TBM_BO_RETURN_VAL_IF_FAIL(_tbm_bo_is_valid(bo), 0);
912 if (!data || LIST_IS_EMPTY(&bo->user_data_list)) {
913 TBM_TRACE_BO("error: bo(%p) key(%lu)\n", bo, key);
914 _tbm_set_last_result(TBM_ERROR_INVALID_PARAMETER);
915 _tbm_bufmgr_mutex_unlock();
919 old_data = user_data_lookup(&bo->user_data_list, key);
922 TBM_TRACE_BO("error: bo(%p) key(%lu)\n", bo, key);
923 _tbm_set_last_result(TBM_ERROR_INVALID_PARAMETER);
924 _tbm_bufmgr_mutex_unlock();
928 *data = old_data->data;
930 TBM_TRACE_BO("bo(%p) key(%lu) data(%p)\n", bo, key, old_data->data);
932 _tbm_bufmgr_mutex_unlock();
938 tbm_bo_get_flags(tbm_bo bo)
942 _tbm_bufmgr_mutex_lock();
944 TBM_BO_RETURN_VAL_IF_FAIL(_tbm_bo_is_valid(bo), 0);
948 TBM_TRACE_BO("bo(%p)\n", bo);
950 _tbm_bufmgr_mutex_unlock();
955 /* LCOV_EXCL_START */
956 /* internal function */
958 _tbm_bo_set_surface(tbm_bo bo, tbm_surface_h surface)
960 _tbm_bufmgr_mutex_lock();
962 TBM_BO_RETURN_VAL_IF_FAIL(_tbm_bo_is_valid(bo), 0);
964 bo->surface = surface;
966 _tbm_bufmgr_mutex_unlock();
972 _tbm_bo_free(tbm_bo bo)
974 /* destory the user_data_list */
975 if (!LIST_IS_EMPTY(&bo->user_data_list)) {
976 tbm_user_data *old_data = NULL, *tmp;
978 LIST_FOR_EACH_ENTRY_SAFE(old_data, tmp,
979 &bo->user_data_list, item_link) {
980 TBM_DBG("free user_data\n");
981 user_data_delete(old_data);
985 while (bo->lock_cnt > 0) {
986 TBM_ERR("error lock_cnt:%d\n", bo->lock_cnt);
991 tbm_module_bo_free(bo->bufmgr->module, bo, bo->bo_data, bo->get_from_hal_surface);