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, 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, (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);
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));
477 _tbm_set_last_result(*error);
482 bo->bo_data = bo_data;
483 _tbm_bo_init(bufmgr, bo, flags);
485 _tbm_bufmgr_mutex_unlock();
492 _tbm_bufmgr_mutex_unlock();
497 tbm_bo_alloc_with_tiled_format(tbm_bufmgr bufmgr, int width, int height, int bpp, int format,
498 tbm_bo_memory_type flags, int bo_idx, tbm_error_e *error)
501 tbm_backend_bo_data *bo_data;
503 _tbm_bufmgr_mutex_lock();
504 _tbm_set_last_result(TBM_ERROR_NONE);
506 TBM_BO_RETURN_VAL_IF_FAIL(TBM_BUFMGR_IS_VALID(bufmgr), NULL);
508 bo = calloc(1, sizeof(struct _tbm_bo));
510 TBM_ERR("error: fail to tbm_bo_alloc_with_tiled_format fmt(%s) idx(%d) w(%d) h(%d) flags(%s)\n",
511 FOURCC_STR(format), bo_idx, width, height, _tbm_flag_to_str(flags));
512 _tbm_set_last_result(TBM_ERROR_OUT_OF_MEMORY);
513 _tbm_bufmgr_mutex_unlock();
517 _tbm_util_check_bo_cnt(bufmgr);
519 if (!bufmgr->use_hal_tbm) {
520 if (!bufmgr->backend_module_data || !bufmgr->bufmgr_func->bufmgr_alloc_bo_with_tiled_format) {
521 TBM_ERR("error: not supported tbm_bo_alloc_with_tiled_format\n");
522 _tbm_set_last_result(TBM_ERROR_NOT_SUPPORTED);
527 if (bufmgr->use_hal_tbm) {
529 bo_data = (tbm_backend_bo_data *)hal_tbm_bufmgr_alloc_bo_with_tiled_format(bufmgr->hal_bufmgr,
530 width, height, bpp, format, (hal_tbm_bo_memory_type)flags, bo_idx, &ret);
532 *error = (tbm_error_e)ret;
533 if (ret != HAL_TBM_ERROR_NONE) {
534 if (ret != HAL_TBM_ERROR_NOT_SUPPORTED) {
535 TBM_ERR("error: fail to tbm_bo_alloc_with_tiled_format fmt(%s) idx(%d) w(%d) h(%d) flags(%s)\n",
536 FOURCC_STR(format), bo_idx, width, height, _tbm_flag_to_str(flags));
538 _tbm_set_last_result(*error);
542 bo_data = bufmgr->bufmgr_func->bufmgr_alloc_bo_with_tiled_format(bufmgr->bufmgr_data, width, height,
543 bpp, format, flags, bo_idx, error);
545 TBM_ERR("error: fail to tbm_bo_alloc_with_tiled_format fmt(%s) idx(%d) w(%d) h(%d) flags(%s)\n",
546 FOURCC_STR(format), bo_idx, width, height, _tbm_flag_to_str(flags));
547 _tbm_set_last_result(*error);
552 bo->bo_data = bo_data;
553 _tbm_bo_init(bufmgr, bo, flags);
555 _tbm_bufmgr_mutex_unlock();
561 _tbm_bufmgr_mutex_unlock();
566 tbm_bo_alloc_with_surface(tbm_bufmgr bufmgr, int width, int height, int format, int flags, int bo_idx)
571 _tbm_bufmgr_mutex_lock();
572 _tbm_set_last_result(TBM_ERROR_NONE);
574 TBM_BO_RETURN_VAL_IF_FAIL(TBM_BUFMGR_IS_VALID(bufmgr), NULL);
576 bo = calloc(1, sizeof(struct _tbm_bo));
578 TBM_ERR("error: fail to tbm_bo_alloc_with_surface fmt(%s) idx(%d) w(%d) h(%d) flags(%s)\n",
579 FOURCC_STR(format), bo_idx, width, height, _tbm_flag_to_str(flags));
580 _tbm_set_last_result(TBM_ERROR_OUT_OF_MEMORY);
581 _tbm_bufmgr_mutex_unlock();
585 _tbm_util_check_bo_cnt(bufmgr);
587 if (!bufmgr->backend->surface_bo_alloc) {
588 TBM_ERR("error: not supported tbm_bo_alloc_with_surface\n");
589 _tbm_set_last_result(TBM_ERROR_NOT_SUPPORTED);
591 _tbm_bufmgr_mutex_unlock();
595 bo_priv = bufmgr->backend->surface_bo_alloc(bo, width, height, format, flags, bo_idx);
597 TBM_ERR("error: fail to tbm_bo_alloc_with_surface fmt(%s) idx(%d) w(%d) h(%d) flags(%s)\n",
598 FOURCC_STR(format), bo_idx, width, height, _tbm_flag_to_str(flags));
599 _tbm_set_last_result(TBM_ERROR_INVALID_OPERATION);
601 _tbm_bufmgr_mutex_unlock();
606 _tbm_bo_init(bufmgr, bo, flags);
608 _tbm_bufmgr_mutex_unlock();
615 tbm_bo_ref(tbm_bo bo)
617 _tbm_bufmgr_mutex_lock();
618 _tbm_set_last_result(TBM_ERROR_NONE);
620 TBM_BO_RETURN_VAL_IF_FAIL(_tbm_bo_is_valid(bo), NULL);
624 TBM_TRACE_BO("bo(%p) ref_cnt(%d)\n", bo, bo->ref_cnt);
626 _tbm_bufmgr_mutex_unlock();
632 tbm_bo_unref(tbm_bo bo)
634 _tbm_bufmgr_mutex_lock();
635 _tbm_set_last_result(TBM_ERROR_NONE);
637 TBM_BO_RETURN_IF_FAIL(_tbm_bo_is_valid(bo));
639 TBM_TRACE_BO("bo(%p) ref_cnt(%d)\n", bo, bo->ref_cnt - 1);
641 if (bo->ref_cnt <= 0) {
642 _tbm_bufmgr_mutex_unlock();
647 if (bo->ref_cnt == 0)
650 _tbm_bufmgr_mutex_unlock();
654 tbm_bo_map(tbm_bo bo, int device, int opt)
656 tbm_bo_handle bo_handle;
659 _tbm_bufmgr_mutex_lock();
660 _tbm_set_last_result(TBM_ERROR_NONE);
662 TBM_BO_RETURN_VAL_IF_FAIL(_tbm_bo_is_valid(bo), (tbm_bo_handle) NULL);
664 if (!_tbm_bo_lock(bo, device, opt)) {
665 TBM_ERR("error: fail to lock bo:%p)\n", bo);
666 _tbm_bufmgr_mutex_unlock();
667 return (tbm_bo_handle) NULL;
670 if (bo->bufmgr->use_hal_tbm) {
671 hal_tbm_bo_handle hbo_handle;
672 hbo_handle = hal_tbm_bo_map((hal_tbm_bo *)bo->bo_data, device, opt, (hal_tbm_error *)&error);
673 if (hbo_handle.ptr == NULL) {
674 /* LCOV_EXCL_START */
675 _tbm_set_last_result(error);
676 TBM_ERR("error: bo(%p) bo_handle(%p) error(%d)\n", bo, hbo_handle.ptr, error);
680 memcpy(&bo_handle.ptr, &hbo_handle.ptr, sizeof(tbm_bo_handle));
681 } else if (bo->bufmgr->backend_module_data) {
682 bo_handle = bo->bufmgr->bo_func->bo_map(bo->bo_data, device, opt, &error);
683 if (bo_handle.ptr == NULL) {
684 /* LCOV_EXCL_START */
685 _tbm_set_last_result(error);
686 TBM_ERR("error: fail to map bo:%p error:%d\n", bo, error);
691 bo_handle = bo->bufmgr->backend->bo_map(bo, device, opt);
692 if (bo_handle.ptr == NULL) {
693 /* LCOV_EXCL_START */
694 _tbm_set_last_result(TBM_ERROR_INVALID_OPERATION);
695 TBM_ERR("error: fail to map bo:%p\n", bo);
701 /* increase the map_count */
704 TBM_TRACE_BO("bo(%p) map_cnt(%d)\n", bo, bo->map_cnt);
706 _tbm_bufmgr_mutex_unlock();
712 _tbm_bufmgr_mutex_unlock();
713 return (tbm_bo_handle) NULL;
717 tbm_bo_unmap(tbm_bo bo)
722 _tbm_bufmgr_mutex_lock();
723 _tbm_set_last_result(TBM_ERROR_NONE);
725 TBM_BO_RETURN_VAL_IF_FAIL(_tbm_bo_is_valid(bo), 0);
726 TBM_BO_RETURN_VAL_IF_FAIL(bo->map_cnt > 0, 0);
728 if (bo->bufmgr->use_hal_tbm) {
729 error = (hal_tbm_error)hal_tbm_bo_unmap((hal_tbm_bo *)bo->bo_data);
730 if (error != TBM_ERROR_NONE) {
731 /* LCOV_EXCL_START */
732 TBM_ERR("error: bo(%p) map_cnt(%d) error(%d)\n", bo, bo->map_cnt, error);
733 _tbm_set_last_result(error);
738 } else if (bo->bufmgr->backend_module_data) {
739 error = bo->bufmgr->bo_func->bo_unmap(bo->bo_data);
740 if (error != TBM_ERROR_NONE) {
741 /* LCOV_EXCL_START */
742 TBM_ERR("error: bo(%p) map_cnt(%d) error(%d)\n", bo, bo->map_cnt, error);
743 _tbm_set_last_result(error);
749 ret = bo->bufmgr->backend->bo_unmap(bo);
751 /* LCOV_EXCL_START */
752 TBM_ERR("error: bo(%p) map_cnt(%d)\n", bo, bo->map_cnt);
753 _tbm_set_last_result(TBM_ERROR_INVALID_OPERATION);
759 /* decrease the map_count */
762 TBM_TRACE_BO("bo(%p) map_cnt(%d)\n", bo, bo->map_cnt);
767 _tbm_bufmgr_mutex_unlock();
773 tbm_bo_get_handle(tbm_bo bo, int device)
775 tbm_bo_handle bo_handle;
778 _tbm_bufmgr_mutex_lock();
779 _tbm_set_last_result(TBM_ERROR_NONE);
781 TBM_BO_RETURN_VAL_IF_FAIL(_tbm_bo_is_valid(bo), (tbm_bo_handle) NULL);
783 if (bo->bufmgr->use_hal_tbm) {
784 hal_tbm_bo_handle hbo_handle;
785 hbo_handle = hal_tbm_bo_get_handle((hal_tbm_bo *)bo->bo_data, device, (hal_tbm_error *)&error);
786 if (hbo_handle.ptr == NULL) {
787 /* LCOV_EXCL_START */
788 TBM_ERR("error: bo(%p) bo_handle(%p) error(%d)\n", bo, hbo_handle.ptr, error);
789 _tbm_set_last_result(error);
793 memcpy(&bo_handle.ptr, &hbo_handle.ptr, sizeof(tbm_bo_handle));
794 } else if (bo->bufmgr->backend_module_data) {
795 bo_handle = bo->bufmgr->bo_func->bo_get_handle(bo->bo_data, device, &error);
796 if (bo_handle.ptr == NULL) {
797 /* LCOV_EXCL_START */
798 TBM_ERR("error: bo(%p) bo_handle(%p) error(%d)\n", bo, bo_handle.ptr, error);
799 _tbm_set_last_result(error);
804 bo_handle = bo->bufmgr->backend->bo_get_handle(bo, device);
805 if (bo_handle.ptr == NULL) {
806 /* LCOV_EXCL_START */
807 TBM_ERR("error: bo(%p) bo_handle(%p)\n", bo, bo_handle.ptr);
808 _tbm_set_last_result(TBM_ERROR_INVALID_OPERATION);
814 TBM_TRACE_BO("bo(%p) bo_handle(%p)\n", bo, bo_handle.ptr);
816 _tbm_bufmgr_mutex_unlock();
821 _tbm_bufmgr_mutex_unlock();
822 return (tbm_bo_handle) NULL;
826 tbm_bo_export(tbm_bo bo)
831 _tbm_bufmgr_mutex_lock();
832 _tbm_set_last_result(TBM_ERROR_NONE);
834 TBM_BO_RETURN_VAL_IF_FAIL(_tbm_bo_is_valid(bo), 0);
836 if (bo->bufmgr->use_hal_tbm) {
837 ret = (hal_tbm_key)hal_tbm_bo_export_key((hal_tbm_bo *)bo->bo_data, (hal_tbm_error *)&error);
839 /* LCOV_EXCL_START */
840 TBM_ERR("error: bo(%p) tbm_key(%d) error(%d)\n", bo, ret, error);
841 _tbm_set_last_result(error);
845 } else if (bo->bufmgr->backend_module_data) {
846 if (!bo->bufmgr->bo_func->bo_export_key) {
847 /* LCOV_EXCL_START */
848 _tbm_bufmgr_mutex_unlock();
849 _tbm_set_last_result(TBM_ERROR_NOT_SUPPORTED);
854 ret = bo->bufmgr->bo_func->bo_export_key(bo->bo_data, &error);
856 /* LCOV_EXCL_START */
857 TBM_ERR("error: bo(%p) tbm_key(%d) error(%d)\n", bo, ret, error);
858 _tbm_set_last_result(error);
863 if (!bo->bufmgr->backend->bo_export) {
864 /* LCOV_EXCL_START */
865 _tbm_bufmgr_mutex_unlock();
866 _tbm_set_last_result(TBM_ERROR_NOT_SUPPORTED);
871 ret = bo->bufmgr->backend->bo_export(bo);
873 /* LCOV_EXCL_START */
874 TBM_ERR("error: bo(%p) tbm_key(%d)\n", bo, ret);
875 _tbm_set_last_result(TBM_ERROR_INVALID_OPERATION);
881 TBM_TRACE_BO("bo(%p) tbm_key(%u)\n", bo, ret);
884 _tbm_bufmgr_mutex_unlock();
890 tbm_bo_export_fd(tbm_bo bo)
895 _tbm_bufmgr_mutex_lock();
896 _tbm_set_last_result(TBM_ERROR_NONE);
898 TBM_BO_RETURN_VAL_IF_FAIL(_tbm_bo_is_valid(bo), -1);
900 if (bo->bufmgr->use_hal_tbm) {
901 ret = (hal_tbm_fd)hal_tbm_bo_export_fd((hal_tbm_bo *)bo->bo_data, (hal_tbm_error *)&error);
903 /* LCOV_EXCL_START */
904 TBM_ERR("error: bo(%p) tbm_fd(%d) error(%d)\n", bo, ret, error);
905 _tbm_set_last_result(error);
909 } else if (bo->bufmgr->backend_module_data) {
910 if (!bo->bufmgr->bo_func->bo_export_fd) {
911 /* LCOV_EXCL_START */
912 _tbm_bufmgr_mutex_unlock();
913 _tbm_set_last_result(TBM_ERROR_NOT_SUPPORTED);
918 ret = bo->bufmgr->bo_func->bo_export_fd(bo->bo_data, &error);
920 /* LCOV_EXCL_START */
921 TBM_ERR("error: bo(%p) tbm_fd(%d) error(%d)\n", bo, ret, error);
922 _tbm_set_last_result(error);
927 if (!bo->bufmgr->backend->bo_export_fd) {
928 /* LCOV_EXCL_START */
929 _tbm_bufmgr_mutex_unlock();
930 _tbm_set_last_result(TBM_ERROR_NOT_SUPPORTED);
935 ret = bo->bufmgr->backend->bo_export_fd(bo);
937 /* LCOV_EXCL_START */
938 TBM_ERR("error: bo(%p) tbm_fd(%d)\n", bo, ret);
939 _tbm_set_last_result(TBM_ERROR_INVALID_OPERATION);
945 TBM_TRACE_BO("bo(%p) tbm_fd(%d)\n", bo, ret);
948 _tbm_bufmgr_mutex_unlock();
954 tbm_bo_import(tbm_bufmgr bufmgr, unsigned int key)
960 tbm_backend_bo_data *bo_data;
963 _tbm_bufmgr_mutex_lock();
964 _tbm_set_last_result(TBM_ERROR_NONE);
966 TBM_BO_RETURN_VAL_IF_FAIL(TBM_BUFMGR_IS_VALID(bufmgr), NULL);
968 if (!bufmgr->use_hal_tbm) {
969 if (bufmgr->backend_module_data) {
970 if (!bufmgr->bufmgr_func->bufmgr_import_key) {
971 /* LCOV_EXCL_START */
972 _tbm_bufmgr_mutex_unlock();
973 _tbm_set_last_result(TBM_ERROR_NOT_SUPPORTED);
978 if (!bufmgr->backend->bo_import) {
979 /* LCOV_EXCL_START */
980 _tbm_bufmgr_mutex_unlock();
981 _tbm_set_last_result(TBM_ERROR_NOT_SUPPORTED);
988 _tbm_util_check_bo_cnt(bufmgr);
990 bo = calloc(1, sizeof(struct _tbm_bo));
992 /* LCOV_EXCL_START */
993 TBM_ERR("error: fail to import of tbm_bo by key(%d)\n", key);
994 _tbm_set_last_result(TBM_ERROR_OUT_OF_MEMORY);
995 _tbm_bufmgr_mutex_unlock();
1000 if (bufmgr->use_hal_tbm) {
1001 bo_data = (tbm_backend_bo_data *)hal_tbm_bufmgr_import_key(bufmgr->hal_bufmgr, key, (hal_tbm_error *)&error);
1002 /* LCOV_EXCL_START */
1004 TBM_ERR("error: fail to import of tbm_bo by key(%d). error(%d)\n", key, error);
1005 _tbm_set_last_result(error);
1008 /* LCOV_EXCL_STOP */
1009 if (!LIST_IS_EMPTY(&bufmgr->bo_list)) {
1010 LIST_FOR_EACH_ENTRY(bo2, &bufmgr->bo_list, item_link) {
1011 if (bo2->bo_data == bo_data) {
1012 TBM_TRACE_BO("find bo(%p) ref(%d) key(%d) flag(%s) in list\n",
1013 bo2, bo2->ref_cnt, key,
1014 _tbm_flag_to_str(bo2->flags));
1017 _tbm_bufmgr_mutex_unlock();
1022 bo->bo_data = bo_data;
1023 } else if (bufmgr->backend_module_data) {
1024 bo_data = bufmgr->bufmgr_func->bufmgr_import_key(bufmgr->bufmgr_data, key, &error);
1026 /* LCOV_EXCL_START */
1027 TBM_ERR("error: fail to import of tbm_bo by key(%d). error(%d)\n", key, error);
1028 _tbm_set_last_result(error);
1030 /* LCOV_EXCL_STOP */
1033 if (!LIST_IS_EMPTY(&bufmgr->bo_list)) {
1034 LIST_FOR_EACH_ENTRY(bo2, &bufmgr->bo_list, item_link) {
1035 if (bo2->bo_data == bo_data) {
1036 TBM_TRACE_BO("find bo(%p) ref(%d) key(%d) flag(%s) in list\n",
1037 bo2, bo2->ref_cnt, key,
1038 _tbm_flag_to_str(bo2->flags));
1041 _tbm_bufmgr_mutex_unlock();
1046 bo->bo_data = bo_data;
1048 bo_priv = bufmgr->backend->bo_import(bo, key);
1050 /* LCOV_EXCL_START */
1051 TBM_ERR("error: fail to import of tbm_bo by key(%d)\n", key);
1052 _tbm_set_last_result(TBM_ERROR_INVALID_OPERATION);
1054 /* LCOV_EXCL_STOP */
1057 if (!LIST_IS_EMPTY(&bufmgr->bo_list)) {
1058 LIST_FOR_EACH_ENTRY(bo2, &bufmgr->bo_list, item_link) {
1059 if (bo2->priv == bo_priv) {
1060 TBM_TRACE_BO("find bo(%p) ref(%d) key(%d) flag(%s) in list\n",
1061 bo2, bo2->ref_cnt, key,
1062 _tbm_flag_to_str(bo2->flags));
1065 _tbm_bufmgr_mutex_unlock();
1073 if (bufmgr->use_hal_tbm) {
1074 flags = (tbm_bo_memory_type)hal_tbm_bo_get_memory_types((hal_tbm_bo *)bo->bo_data, (hal_tbm_error *)&error);
1075 if (error != TBM_ERROR_NONE) {
1076 TBM_ERR("fail to get the bo flags(memory_types)");
1077 _tbm_set_last_result(error);
1078 flags = TBM_BO_DEFAULT;
1080 } else if (bufmgr->backend_module_data) {
1081 flags = bufmgr->bo_func->bo_get_memory_types(bo->bo_data, &error);
1082 if (error != TBM_ERROR_NONE) {
1083 TBM_ERR("fail to get the bo flags(memory_types)");
1084 _tbm_set_last_result(error);
1085 flags = TBM_BO_DEFAULT;
1088 if (bufmgr->backend->bo_get_flags)
1089 flags = bufmgr->backend->bo_get_flags(bo);
1091 flags = TBM_BO_DEFAULT;
1094 _tbm_bo_init(bufmgr, bo, flags);
1096 TBM_TRACE_BO("import new bo(%p) ref(%d) key(%d) flag(%s) in list\n",
1097 bo, bo->ref_cnt, key, _tbm_flag_to_str(bo->flags));
1099 _tbm_bufmgr_mutex_unlock();
1105 _tbm_bufmgr_mutex_unlock();
1110 tbm_bo_import_fd(tbm_bufmgr bufmgr, tbm_fd fd)
1115 tbm_backend_bo_data *bo_data;
1119 _tbm_bufmgr_mutex_lock();
1120 _tbm_set_last_result(TBM_ERROR_NONE);
1122 TBM_BO_RETURN_VAL_IF_FAIL(TBM_BUFMGR_IS_VALID(bufmgr), NULL);
1124 if (!bufmgr->use_hal_tbm) {
1125 if (bufmgr->backend_module_data) {
1126 if (!bufmgr->bufmgr_func->bufmgr_import_fd) {
1127 /* LCOV_EXCL_START */
1128 _tbm_bufmgr_mutex_unlock();
1129 _tbm_set_last_result(TBM_ERROR_NOT_SUPPORTED);
1131 /* LCOV_EXCL_STOP */
1134 if (!bufmgr->backend->bo_import_fd) {
1135 /* LCOV_EXCL_START */
1136 _tbm_bufmgr_mutex_unlock();
1137 _tbm_set_last_result(TBM_ERROR_NOT_SUPPORTED);
1139 /* LCOV_EXCL_STOP */
1144 _tbm_util_check_bo_cnt(bufmgr);
1146 bo = calloc(1, sizeof(struct _tbm_bo));
1148 /* LCOV_EXCL_START */
1149 TBM_ERR("error: fail to import tbm_bo by tbm_fd(%d)\n", fd);
1150 _tbm_set_last_result(TBM_ERROR_OUT_OF_MEMORY);
1151 _tbm_bufmgr_mutex_unlock();
1153 /* LCOV_EXCL_STOP */
1156 if (bufmgr->use_hal_tbm) {
1157 bo_data = (tbm_backend_bo_data *)hal_tbm_bufmgr_import_fd(bufmgr->hal_bufmgr, (hal_tbm_fd)fd, (hal_tbm_error *)&error);
1158 /* LCOV_EXCL_START */
1160 TBM_ERR("error: fail to import tbm_bo by tbm_fd(%d). error(%d)\n", fd, error);
1161 _tbm_set_last_result(error);
1164 /* LCOV_EXCL_STOP */
1166 if (!LIST_IS_EMPTY(&bufmgr->bo_list)) {
1167 LIST_FOR_EACH_ENTRY(bo2, &bufmgr->bo_list, item_link) {
1168 if (bo2->bo_data == bo_data) {
1169 TBM_TRACE_BO("find bo(%p) ref(%d) fd(%d) flag(%s) in list\n",
1170 bo2, bo2->ref_cnt, fd, _tbm_flag_to_str(bo2->flags));
1173 _tbm_bufmgr_mutex_unlock();
1178 bo->bo_data = bo_data;
1179 } else if (bufmgr->backend_module_data) {
1180 bo_data = bufmgr->bufmgr_func->bufmgr_import_fd(bufmgr->bufmgr_data, fd, &error);
1182 /* LCOV_EXCL_START */
1183 TBM_ERR("error: fail to import tbm_bo by tbm_fd(%d). error(%d)\n", fd, error);
1184 _tbm_set_last_result(error);
1186 /* LCOV_EXCL_STOP */
1189 if (!LIST_IS_EMPTY(&bufmgr->bo_list)) {
1190 LIST_FOR_EACH_ENTRY(bo2, &bufmgr->bo_list, item_link) {
1191 if (bo2->bo_data == bo_data) {
1192 TBM_TRACE_BO("find bo(%p) ref(%d) fd(%d) flag(%s) in list\n",
1193 bo2, bo2->ref_cnt, fd, _tbm_flag_to_str(bo2->flags));
1196 _tbm_bufmgr_mutex_unlock();
1201 bo->bo_data = bo_data;
1203 bo_priv = bufmgr->backend->bo_import_fd(bo, fd);
1205 /* LCOV_EXCL_START */
1206 TBM_ERR("error: fail to import tbm_bo by tbm_fd(%d)\n", fd);
1207 _tbm_set_last_result(TBM_ERROR_INVALID_OPERATION);
1209 /* LCOV_EXCL_STOP */
1212 if (!LIST_IS_EMPTY(&bufmgr->bo_list)) {
1213 LIST_FOR_EACH_ENTRY(bo2, &bufmgr->bo_list, item_link) {
1214 if (bo2->priv == bo_priv) {
1215 TBM_TRACE_BO("find bo(%p) ref(%d) fd(%d) flag(%s) in list\n",
1216 bo2, bo2->ref_cnt, fd, _tbm_flag_to_str(bo2->flags));
1219 _tbm_bufmgr_mutex_unlock();
1227 if (bufmgr->use_hal_tbm) {
1228 flags = (tbm_bo_memory_type)hal_tbm_bo_get_memory_types((hal_tbm_bo *)bo->bo_data, (hal_tbm_error *)&error);
1229 if (error != TBM_ERROR_NONE) {
1230 TBM_ERR("fail to get the bo flags(memory_types)");
1231 _tbm_set_last_result(error);
1232 flags = TBM_BO_DEFAULT;
1234 } else if (bufmgr->backend_module_data) {
1235 flags = bufmgr->bo_func->bo_get_memory_types(bo->bo_data, &error);
1236 if (error != TBM_ERROR_NONE) {
1237 TBM_ERR("fail to get the bo flags(memory_types)");
1238 _tbm_set_last_result(error);
1239 flags = TBM_BO_DEFAULT;
1242 if (bufmgr->backend->bo_get_flags)
1243 flags = bufmgr->backend->bo_get_flags(bo);
1245 flags = TBM_BO_DEFAULT;
1248 _tbm_bo_init(bufmgr, bo, flags);
1250 TBM_TRACE_BO("import bo(%p) ref(%d) fd(%d) flag(%s)\n",
1251 bo, bo->ref_cnt, fd, _tbm_flag_to_str(bo->flags));
1253 _tbm_bufmgr_mutex_unlock();
1259 _tbm_bufmgr_mutex_unlock();
1264 tbm_bo_size(tbm_bo bo)
1269 _tbm_bufmgr_mutex_lock();
1270 _tbm_set_last_result(TBM_ERROR_NONE);
1272 TBM_BO_RETURN_VAL_IF_FAIL(_tbm_bo_is_valid(bo), 0);
1274 if (bo->bufmgr->use_hal_tbm) {
1275 size = hal_tbm_bo_get_size((hal_tbm_bo *)bo->bo_data, (hal_tbm_error *)&error);
1276 if (error != TBM_ERROR_NONE) {
1277 TBM_ERR("fail to get the size of the bo_data(%d).", error);
1278 _tbm_set_last_result(TBM_ERROR_NONE);
1280 } else if (bo->bufmgr->backend_module_data) {
1281 size = bo->bufmgr->bo_func->bo_get_size(bo->bo_data, &error);
1282 if (error != TBM_ERROR_NONE) {
1283 TBM_ERR("fail to get the size of the bo_data(%d).", error);
1284 _tbm_set_last_result(TBM_ERROR_NONE);
1287 size = bo->bufmgr->backend->bo_size(bo);
1289 TBM_TRACE_BO("bo(%p) size(%d)\n", bo, size);
1291 _tbm_bufmgr_mutex_unlock();
1297 tbm_bo_locked(tbm_bo bo)
1299 _tbm_bufmgr_mutex_lock();
1300 _tbm_set_last_result(TBM_ERROR_NONE);
1302 TBM_BO_RETURN_VAL_IF_FAIL(_tbm_bo_is_valid(bo), 0);
1304 if (bo->bufmgr->bo_lock_type == TBM_BUFMGR_BO_LOCK_TYPE_NEVER) {
1305 TBM_ERR("bo(%p) lock_cnt(%d)\n", bo, bo->lock_cnt);
1306 _tbm_set_last_result(TBM_ERROR_INVALID_OPERATION);
1307 _tbm_bufmgr_mutex_unlock();
1311 if (bo->lock_cnt > 0) {
1312 TBM_TRACE_BO("error: bo(%p) lock_cnt(%d)\n", bo, bo->lock_cnt);
1313 _tbm_bufmgr_mutex_unlock();
1317 TBM_TRACE_BO("bo(%p) lock_cnt(%d)\n", bo, bo->lock_cnt);
1318 _tbm_bufmgr_mutex_unlock();
1324 tbm_bo_swap(tbm_bo bo1, tbm_bo bo2)
1326 tbm_error_e error1, error2;
1327 int size1 = -1, size2 = -2;
1330 _tbm_bufmgr_mutex_lock();
1331 _tbm_set_last_result(TBM_ERROR_NONE);
1333 TBM_BO_RETURN_VAL_IF_FAIL(_tbm_bo_is_valid(bo1), 0);
1334 TBM_BO_RETURN_VAL_IF_FAIL(_tbm_bo_is_valid(bo2), 0);
1336 TBM_TRACE_BO("before: bo1(%p) bo2(%p)\n", bo1, bo2);
1338 if (bo1->bufmgr->use_hal_tbm) {
1339 size1 = hal_tbm_bo_get_size((hal_tbm_bo *)bo1->bo_data, (hal_tbm_error *)&error1);
1340 if (error1 != TBM_ERROR_NONE) {
1341 TBM_ERR("fail to get the size of bo1.(%d)", error1);
1342 _tbm_set_last_result(error1);
1345 size2 = hal_tbm_bo_get_size((hal_tbm_bo *)bo2->bo_data, (hal_tbm_error *)&error2);
1346 if (error2 != TBM_ERROR_NONE) {
1347 TBM_ERR("fail to get the size of bo1.(%d)", error2);
1348 _tbm_set_last_result(error2);
1351 } else if (bo1->bufmgr->backend_module_data) {
1352 size1 = bo1->bufmgr->bo_func->bo_get_size(bo1->bo_data, &error1);
1353 if (error1 != TBM_ERROR_NONE) {
1354 TBM_ERR("fail to get the size of bo1.(%d)", error1);
1355 _tbm_set_last_result(error1);
1358 size2 = bo2->bufmgr->bo_func->bo_get_size(bo2->bo_data, &error2);
1359 if (error2 != TBM_ERROR_NONE) {
1360 TBM_ERR("fail to get the size of bo2.(%d)", error2);
1361 _tbm_set_last_result(error2);
1365 size1 = bo1->bufmgr->backend->bo_size(bo1);
1366 size2 = bo2->bufmgr->backend->bo_size(bo2);
1369 if (size1 != size2) {
1370 TBM_ERR("error: bo1 size(%d) and bo2 size(%d) is different.", size1, size2);
1371 _tbm_set_last_result(TBM_ERROR_INVALID_OPERATION);
1375 TBM_TRACE_BO("after: bo1(%p) bo2(%p)\n", bo1, bo2);
1378 bo1->priv = bo2->priv;
1381 _tbm_bufmgr_mutex_unlock();
1386 TBM_ERR("error: bo1(%p) bo2(%p)\n", bo1, bo2);
1387 _tbm_bufmgr_mutex_unlock();
1393 tbm_bo_add_user_data(tbm_bo bo, unsigned long key,
1394 tbm_data_free data_free_func)
1396 tbm_user_data *data;
1398 _tbm_bufmgr_mutex_lock();
1399 _tbm_set_last_result(TBM_ERROR_NONE);
1401 TBM_BO_RETURN_VAL_IF_FAIL(_tbm_bo_is_valid(bo), 0);
1403 /* check if the data according to the key exist if so, return false. */
1404 data = user_data_lookup(&bo->user_data_list, key);
1406 TBM_TRACE_BO("warning: user data already exist key(%ld)\n", key);
1407 _tbm_set_last_result(TBM_ERROR_INVALID_PARAMETER);
1408 _tbm_bufmgr_mutex_unlock();
1412 data = user_data_create(key, data_free_func);
1414 TBM_ERR("error: bo(%p) key(%lu)\n", bo, key);
1415 _tbm_set_last_result(TBM_ERROR_INVALID_PARAMETER);
1416 _tbm_bufmgr_mutex_unlock();
1420 TBM_TRACE_BO("bo(%p) key(%lu) data(%p)\n", bo, key, data->data);
1422 LIST_ADD(&data->item_link, &bo->user_data_list);
1424 _tbm_bufmgr_mutex_unlock();
1430 tbm_bo_delete_user_data(tbm_bo bo, unsigned long key)
1432 tbm_user_data *old_data;
1434 _tbm_bufmgr_mutex_lock();
1435 _tbm_set_last_result(TBM_ERROR_NONE);
1437 TBM_BO_RETURN_VAL_IF_FAIL(_tbm_bo_is_valid(bo), 0);
1439 if (LIST_IS_EMPTY(&bo->user_data_list)) {
1440 TBM_TRACE_BO("bo(%p) key(%lu)\n", bo, key);
1441 _tbm_set_last_result(TBM_ERROR_INVALID_PARAMETER);
1442 _tbm_bufmgr_mutex_unlock();
1446 old_data = user_data_lookup(&bo->user_data_list, key);
1448 TBM_TRACE_BO("bo(%p) key(%lu)\n", bo, key);
1449 _tbm_set_last_result(TBM_ERROR_INVALID_PARAMETER);
1450 _tbm_bufmgr_mutex_unlock();
1454 TBM_TRACE_BO("bo(%p) key(%lu) data(%p)\n", bo, key, old_data->data);
1456 user_data_delete(old_data);
1458 _tbm_bufmgr_mutex_unlock();
1464 tbm_bo_set_user_data(tbm_bo bo, unsigned long key, void *data)
1466 tbm_user_data *old_data;
1468 _tbm_bufmgr_mutex_lock();
1469 _tbm_set_last_result(TBM_ERROR_NONE);
1471 TBM_BO_RETURN_VAL_IF_FAIL(_tbm_bo_is_valid(bo), 0);
1473 if (LIST_IS_EMPTY(&bo->user_data_list)) {
1474 TBM_TRACE_BO("error: bo(%p) key(%lu)\n", bo, key);
1475 _tbm_set_last_result(TBM_ERROR_INVALID_PARAMETER);
1476 _tbm_bufmgr_mutex_unlock();
1480 old_data = user_data_lookup(&bo->user_data_list, key);
1482 TBM_TRACE_BO("error: bo(%p) key(%lu)\n", bo, key);
1483 _tbm_set_last_result(TBM_ERROR_INVALID_PARAMETER);
1484 _tbm_bufmgr_mutex_unlock();
1488 if (old_data->data && old_data->free_func)
1489 old_data->free_func(old_data->data);
1490 old_data->data = data;
1492 TBM_TRACE_BO("bo(%p) key(%lu) data(%p)\n", bo, key, old_data->data);
1494 _tbm_bufmgr_mutex_unlock();
1500 tbm_bo_get_user_data(tbm_bo bo, unsigned long key, void **data)
1502 tbm_user_data *old_data;
1504 _tbm_bufmgr_mutex_lock();
1505 _tbm_set_last_result(TBM_ERROR_NONE);
1507 TBM_BO_RETURN_VAL_IF_FAIL(_tbm_bo_is_valid(bo), 0);
1509 if (!data || LIST_IS_EMPTY(&bo->user_data_list)) {
1510 TBM_TRACE_BO("error: bo(%p) key(%lu)\n", bo, key);
1511 _tbm_set_last_result(TBM_ERROR_INVALID_PARAMETER);
1512 _tbm_bufmgr_mutex_unlock();
1516 old_data = user_data_lookup(&bo->user_data_list, key);
1519 TBM_TRACE_BO("error: bo(%p) key(%lu)\n", bo, key);
1520 _tbm_set_last_result(TBM_ERROR_INVALID_PARAMETER);
1521 _tbm_bufmgr_mutex_unlock();
1525 *data = old_data->data;
1527 TBM_TRACE_BO("bo(%p) key(%lu) data(%p)\n", bo, key, old_data->data);
1529 _tbm_bufmgr_mutex_unlock();
1535 tbm_bo_get_flags(tbm_bo bo)
1539 _tbm_bufmgr_mutex_lock();
1541 TBM_BO_RETURN_VAL_IF_FAIL(_tbm_bo_is_valid(bo), 0);
1545 TBM_TRACE_BO("bo(%p)\n", bo);
1547 _tbm_bufmgr_mutex_unlock();
1552 /* LCOV_EXCL_START */
1553 /* internal function */
1555 _tbm_bo_set_surface(tbm_bo bo, tbm_surface_h surface)
1557 _tbm_bufmgr_mutex_lock();
1559 TBM_BO_RETURN_VAL_IF_FAIL(_tbm_bo_is_valid(bo), 0);
1561 bo->surface = surface;
1563 _tbm_bufmgr_mutex_unlock();
1569 _tbm_bo_free(tbm_bo bo)
1571 /* destory the user_data_list */
1572 if (!LIST_IS_EMPTY(&bo->user_data_list)) {
1573 tbm_user_data *old_data = NULL, *tmp;
1575 LIST_FOR_EACH_ENTRY_SAFE(old_data, tmp,
1576 &bo->user_data_list, item_link) {
1577 TBM_DBG("free user_data\n");
1578 user_data_delete(old_data);
1582 while (bo->lock_cnt > 0) {
1583 TBM_ERR("error lock_cnt:%d\n", bo->lock_cnt);
1588 /* call the bo_free */
1589 if (bo->bufmgr->use_hal_tbm) {
1590 hal_tbm_bo_free(bo->bo_data);
1592 } else if (bo->bufmgr->backend_module_data) {
1593 bo->bufmgr->bo_func->bo_free(bo->bo_data);
1596 bo->bufmgr->backend->bo_free(bo);
1604 /* LCOV_EXCL_STOP */