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();
619 tbm_bo_ref(tbm_bo bo)
621 _tbm_bufmgr_mutex_lock();
622 _tbm_set_last_result(TBM_ERROR_NONE);
624 TBM_BO_RETURN_VAL_IF_FAIL(_tbm_bo_is_valid(bo), NULL);
628 TBM_TRACE_BO("bo(%p) ref_cnt(%d)\n", bo, bo->ref_cnt);
630 _tbm_bufmgr_mutex_unlock();
636 tbm_bo_unref(tbm_bo bo)
638 _tbm_bufmgr_mutex_lock();
639 _tbm_set_last_result(TBM_ERROR_NONE);
641 TBM_BO_RETURN_IF_FAIL(_tbm_bo_is_valid(bo));
643 TBM_TRACE_BO("bo(%p) ref_cnt(%d)\n", bo, bo->ref_cnt - 1);
645 if (bo->ref_cnt <= 0) {
646 _tbm_bufmgr_mutex_unlock();
651 if (bo->ref_cnt == 0)
654 _tbm_bufmgr_mutex_unlock();
658 tbm_bo_map(tbm_bo bo, int device, int opt)
660 tbm_bo_handle bo_handle;
663 _tbm_bufmgr_mutex_lock();
664 _tbm_set_last_result(TBM_ERROR_NONE);
666 TBM_BO_RETURN_VAL_IF_FAIL(_tbm_bo_is_valid(bo), (tbm_bo_handle) NULL);
668 if (!_tbm_bo_lock(bo, device, opt)) {
669 TBM_ERR("error: fail to lock bo:%p)\n", bo);
670 _tbm_bufmgr_mutex_unlock();
671 return (tbm_bo_handle) NULL;
674 if (bo->bufmgr->use_hal_tbm) {
675 hal_tbm_bo_handle hbo_handle;
676 hbo_handle = hal_tbm_bo_map((hal_tbm_bo *)bo->bo_data, device, opt, (hal_tbm_error *)&error);
677 if (hbo_handle.ptr == NULL) {
678 /* LCOV_EXCL_START */
679 _tbm_set_last_result(error);
680 TBM_ERR("error: bo(%p) bo_handle(%p) error(%d)\n", bo, hbo_handle.ptr, error);
684 memcpy(&bo_handle.ptr, &hbo_handle.ptr, sizeof(tbm_bo_handle));
685 } else if (bo->bufmgr->backend_module_data) {
686 bo_handle = bo->bufmgr->bo_func->bo_map(bo->bo_data, device, opt, &error);
687 if (bo_handle.ptr == NULL) {
688 /* LCOV_EXCL_START */
689 _tbm_set_last_result(error);
690 TBM_ERR("error: fail to map bo:%p error:%d\n", bo, error);
695 bo_handle = bo->bufmgr->backend->bo_map(bo, device, opt);
696 if (bo_handle.ptr == NULL) {
697 /* LCOV_EXCL_START */
698 _tbm_set_last_result(TBM_ERROR_INVALID_OPERATION);
699 TBM_ERR("error: fail to map bo:%p\n", bo);
705 /* increase the map_count */
708 TBM_TRACE_BO("bo(%p) map_cnt(%d)\n", bo, bo->map_cnt);
710 _tbm_bufmgr_mutex_unlock();
716 _tbm_bufmgr_mutex_unlock();
717 return (tbm_bo_handle) NULL;
721 tbm_bo_unmap(tbm_bo bo)
726 _tbm_bufmgr_mutex_lock();
727 _tbm_set_last_result(TBM_ERROR_NONE);
729 TBM_BO_RETURN_VAL_IF_FAIL(_tbm_bo_is_valid(bo), 0);
730 TBM_BO_RETURN_VAL_IF_FAIL(bo->map_cnt > 0, 0);
732 if (bo->bufmgr->use_hal_tbm) {
733 error = (hal_tbm_error)hal_tbm_bo_unmap((hal_tbm_bo *)bo->bo_data);
734 if (error != TBM_ERROR_NONE) {
735 /* LCOV_EXCL_START */
736 TBM_ERR("error: bo(%p) map_cnt(%d) error(%d)\n", bo, bo->map_cnt, error);
737 _tbm_set_last_result(error);
742 } else if (bo->bufmgr->backend_module_data) {
743 error = bo->bufmgr->bo_func->bo_unmap(bo->bo_data);
744 if (error != TBM_ERROR_NONE) {
745 /* LCOV_EXCL_START */
746 TBM_ERR("error: bo(%p) map_cnt(%d) error(%d)\n", bo, bo->map_cnt, error);
747 _tbm_set_last_result(error);
753 ret = bo->bufmgr->backend->bo_unmap(bo);
755 /* LCOV_EXCL_START */
756 TBM_ERR("error: bo(%p) map_cnt(%d)\n", bo, bo->map_cnt);
757 _tbm_set_last_result(TBM_ERROR_INVALID_OPERATION);
763 /* decrease the map_count */
766 TBM_TRACE_BO("bo(%p) map_cnt(%d)\n", bo, bo->map_cnt);
771 _tbm_bufmgr_mutex_unlock();
777 tbm_bo_get_handle(tbm_bo bo, int device)
779 tbm_bo_handle bo_handle;
782 _tbm_bufmgr_mutex_lock();
783 _tbm_set_last_result(TBM_ERROR_NONE);
785 TBM_BO_RETURN_VAL_IF_FAIL(_tbm_bo_is_valid(bo), (tbm_bo_handle) NULL);
787 if (bo->bufmgr->use_hal_tbm) {
788 hal_tbm_bo_handle hbo_handle;
789 hbo_handle = hal_tbm_bo_get_handle((hal_tbm_bo *)bo->bo_data, device, (hal_tbm_error *)&error);
790 if (hbo_handle.ptr == NULL) {
791 /* LCOV_EXCL_START */
792 TBM_ERR("error: bo(%p) bo_handle(%p) error(%d)\n", bo, hbo_handle.ptr, error);
793 _tbm_set_last_result(error);
797 memcpy(&bo_handle.ptr, &hbo_handle.ptr, sizeof(tbm_bo_handle));
798 } else if (bo->bufmgr->backend_module_data) {
799 bo_handle = bo->bufmgr->bo_func->bo_get_handle(bo->bo_data, device, &error);
800 if (bo_handle.ptr == NULL) {
801 /* LCOV_EXCL_START */
802 TBM_ERR("error: bo(%p) bo_handle(%p) error(%d)\n", bo, bo_handle.ptr, error);
803 _tbm_set_last_result(error);
808 bo_handle = bo->bufmgr->backend->bo_get_handle(bo, device);
809 if (bo_handle.ptr == NULL) {
810 /* LCOV_EXCL_START */
811 TBM_ERR("error: bo(%p) bo_handle(%p)\n", bo, bo_handle.ptr);
812 _tbm_set_last_result(TBM_ERROR_INVALID_OPERATION);
818 TBM_TRACE_BO("bo(%p) bo_handle(%p)\n", bo, bo_handle.ptr);
820 _tbm_bufmgr_mutex_unlock();
825 _tbm_bufmgr_mutex_unlock();
826 return (tbm_bo_handle) NULL;
830 tbm_bo_export(tbm_bo bo)
835 _tbm_bufmgr_mutex_lock();
836 _tbm_set_last_result(TBM_ERROR_NONE);
838 TBM_BO_RETURN_VAL_IF_FAIL(_tbm_bo_is_valid(bo), 0);
840 if (bo->bufmgr->use_hal_tbm) {
841 ret = (hal_tbm_key)hal_tbm_bo_export_key((hal_tbm_bo *)bo->bo_data, (hal_tbm_error *)&error);
843 /* LCOV_EXCL_START */
844 TBM_ERR("error: bo(%p) tbm_key(%d) error(%d)\n", bo, ret, error);
845 _tbm_set_last_result(error);
849 } else if (bo->bufmgr->backend_module_data) {
850 if (!bo->bufmgr->bo_func->bo_export_key) {
851 /* LCOV_EXCL_START */
852 _tbm_bufmgr_mutex_unlock();
853 _tbm_set_last_result(TBM_ERROR_NOT_SUPPORTED);
858 ret = bo->bufmgr->bo_func->bo_export_key(bo->bo_data, &error);
860 /* LCOV_EXCL_START */
861 TBM_ERR("error: bo(%p) tbm_key(%d) error(%d)\n", bo, ret, error);
862 _tbm_set_last_result(error);
867 if (!bo->bufmgr->backend->bo_export) {
868 /* LCOV_EXCL_START */
869 _tbm_bufmgr_mutex_unlock();
870 _tbm_set_last_result(TBM_ERROR_NOT_SUPPORTED);
875 ret = bo->bufmgr->backend->bo_export(bo);
877 /* LCOV_EXCL_START */
878 TBM_ERR("error: bo(%p) tbm_key(%d)\n", bo, ret);
879 _tbm_set_last_result(TBM_ERROR_INVALID_OPERATION);
885 TBM_TRACE_BO("bo(%p) tbm_key(%u)\n", bo, ret);
888 _tbm_bufmgr_mutex_unlock();
894 tbm_bo_export_fd(tbm_bo bo)
899 _tbm_bufmgr_mutex_lock();
900 _tbm_set_last_result(TBM_ERROR_NONE);
902 TBM_BO_RETURN_VAL_IF_FAIL(_tbm_bo_is_valid(bo), -1);
904 if (bo->bufmgr->use_hal_tbm) {
905 ret = (hal_tbm_fd)hal_tbm_bo_export_fd((hal_tbm_bo *)bo->bo_data, (hal_tbm_error *)&error);
907 /* LCOV_EXCL_START */
908 TBM_ERR("error: bo(%p) tbm_fd(%d) error(%d)\n", bo, ret, error);
909 _tbm_set_last_result(error);
913 } else if (bo->bufmgr->backend_module_data) {
914 if (!bo->bufmgr->bo_func->bo_export_fd) {
915 /* LCOV_EXCL_START */
916 _tbm_bufmgr_mutex_unlock();
917 _tbm_set_last_result(TBM_ERROR_NOT_SUPPORTED);
922 ret = bo->bufmgr->bo_func->bo_export_fd(bo->bo_data, &error);
924 /* LCOV_EXCL_START */
925 TBM_ERR("error: bo(%p) tbm_fd(%d) error(%d)\n", bo, ret, error);
926 _tbm_set_last_result(error);
931 if (!bo->bufmgr->backend->bo_export_fd) {
932 /* LCOV_EXCL_START */
933 _tbm_bufmgr_mutex_unlock();
934 _tbm_set_last_result(TBM_ERROR_NOT_SUPPORTED);
939 ret = bo->bufmgr->backend->bo_export_fd(bo);
941 /* LCOV_EXCL_START */
942 TBM_ERR("error: bo(%p) tbm_fd(%d)\n", bo, ret);
943 _tbm_set_last_result(TBM_ERROR_INVALID_OPERATION);
949 TBM_TRACE_BO("bo(%p) tbm_fd(%d)\n", bo, ret);
952 _tbm_bufmgr_mutex_unlock();
958 tbm_bo_import(tbm_bufmgr bufmgr, unsigned int key)
964 tbm_backend_bo_data *bo_data;
967 _tbm_bufmgr_mutex_lock();
968 _tbm_set_last_result(TBM_ERROR_NONE);
970 TBM_BO_RETURN_VAL_IF_FAIL(TBM_BUFMGR_IS_VALID(bufmgr), NULL);
972 if (!bufmgr->use_hal_tbm) {
973 if (bufmgr->backend_module_data) {
974 if (!bufmgr->bufmgr_func->bufmgr_import_key) {
975 /* LCOV_EXCL_START */
976 _tbm_bufmgr_mutex_unlock();
977 _tbm_set_last_result(TBM_ERROR_NOT_SUPPORTED);
982 if (!bufmgr->backend->bo_import) {
983 /* LCOV_EXCL_START */
984 _tbm_bufmgr_mutex_unlock();
985 _tbm_set_last_result(TBM_ERROR_NOT_SUPPORTED);
992 _tbm_util_check_bo_cnt(bufmgr);
994 bo = calloc(1, sizeof(struct _tbm_bo));
996 /* LCOV_EXCL_START */
997 TBM_ERR("error: fail to import of tbm_bo by key(%d)\n", key);
998 _tbm_set_last_result(TBM_ERROR_OUT_OF_MEMORY);
999 _tbm_bufmgr_mutex_unlock();
1001 /* LCOV_EXCL_STOP */
1004 if (bufmgr->use_hal_tbm) {
1005 bo_data = (tbm_backend_bo_data *)hal_tbm_bufmgr_import_key(bufmgr->hal_bufmgr, key, (hal_tbm_error *)&error);
1006 /* LCOV_EXCL_START */
1008 TBM_ERR("error: fail to import of tbm_bo by key(%d). error(%d)\n", key, error);
1009 _tbm_set_last_result(error);
1012 /* LCOV_EXCL_STOP */
1013 if (!LIST_IS_EMPTY(&bufmgr->bo_list)) {
1014 LIST_FOR_EACH_ENTRY(bo2, &bufmgr->bo_list, item_link) {
1015 if (bo2->bo_data == bo_data) {
1016 TBM_TRACE_BO("find bo(%p) ref(%d) key(%d) flag(%s) in list\n",
1017 bo2, bo2->ref_cnt, key,
1018 _tbm_flag_to_str(bo2->flags));
1021 _tbm_bufmgr_mutex_unlock();
1026 bo->bo_data = bo_data;
1027 } else if (bufmgr->backend_module_data) {
1028 bo_data = bufmgr->bufmgr_func->bufmgr_import_key(bufmgr->bufmgr_data, key, &error);
1030 /* LCOV_EXCL_START */
1031 TBM_ERR("error: fail to import of tbm_bo by key(%d). error(%d)\n", key, error);
1032 _tbm_set_last_result(error);
1034 /* LCOV_EXCL_STOP */
1037 if (!LIST_IS_EMPTY(&bufmgr->bo_list)) {
1038 LIST_FOR_EACH_ENTRY(bo2, &bufmgr->bo_list, item_link) {
1039 if (bo2->bo_data == bo_data) {
1040 TBM_TRACE_BO("find bo(%p) ref(%d) key(%d) flag(%s) in list\n",
1041 bo2, bo2->ref_cnt, key,
1042 _tbm_flag_to_str(bo2->flags));
1045 _tbm_bufmgr_mutex_unlock();
1050 bo->bo_data = bo_data;
1052 bo_priv = bufmgr->backend->bo_import(bo, key);
1054 /* LCOV_EXCL_START */
1055 TBM_ERR("error: fail to import of tbm_bo by key(%d)\n", key);
1056 _tbm_set_last_result(TBM_ERROR_INVALID_OPERATION);
1058 /* LCOV_EXCL_STOP */
1061 if (!LIST_IS_EMPTY(&bufmgr->bo_list)) {
1062 LIST_FOR_EACH_ENTRY(bo2, &bufmgr->bo_list, item_link) {
1063 if (bo2->priv == bo_priv) {
1064 TBM_TRACE_BO("find bo(%p) ref(%d) key(%d) flag(%s) in list\n",
1065 bo2, bo2->ref_cnt, key,
1066 _tbm_flag_to_str(bo2->flags));
1069 _tbm_bufmgr_mutex_unlock();
1077 if (bufmgr->use_hal_tbm) {
1078 flags = (tbm_bo_memory_type)hal_tbm_bo_get_memory_types((hal_tbm_bo *)bo->bo_data, (hal_tbm_error *)&error);
1079 if (error != TBM_ERROR_NONE) {
1080 TBM_ERR("fail to get the bo flags(memory_types)");
1081 _tbm_set_last_result(error);
1082 flags = TBM_BO_DEFAULT;
1084 } else if (bufmgr->backend_module_data) {
1085 flags = bufmgr->bo_func->bo_get_memory_types(bo->bo_data, &error);
1086 if (error != TBM_ERROR_NONE) {
1087 TBM_ERR("fail to get the bo flags(memory_types)");
1088 _tbm_set_last_result(error);
1089 flags = TBM_BO_DEFAULT;
1092 if (bufmgr->backend->bo_get_flags)
1093 flags = bufmgr->backend->bo_get_flags(bo);
1095 flags = TBM_BO_DEFAULT;
1098 _tbm_bo_init(bufmgr, bo, flags);
1100 TBM_TRACE_BO("import new bo(%p) ref(%d) key(%d) flag(%s) in list\n",
1101 bo, bo->ref_cnt, key, _tbm_flag_to_str(bo->flags));
1103 _tbm_bufmgr_mutex_unlock();
1109 _tbm_bufmgr_mutex_unlock();
1114 tbm_bo_import_fd(tbm_bufmgr bufmgr, tbm_fd fd)
1119 tbm_backend_bo_data *bo_data;
1123 _tbm_bufmgr_mutex_lock();
1124 _tbm_set_last_result(TBM_ERROR_NONE);
1126 TBM_BO_RETURN_VAL_IF_FAIL(TBM_BUFMGR_IS_VALID(bufmgr), NULL);
1128 if (!bufmgr->use_hal_tbm) {
1129 if (bufmgr->backend_module_data) {
1130 if (!bufmgr->bufmgr_func->bufmgr_import_fd) {
1131 /* LCOV_EXCL_START */
1132 _tbm_bufmgr_mutex_unlock();
1133 _tbm_set_last_result(TBM_ERROR_NOT_SUPPORTED);
1135 /* LCOV_EXCL_STOP */
1138 if (!bufmgr->backend->bo_import_fd) {
1139 /* LCOV_EXCL_START */
1140 _tbm_bufmgr_mutex_unlock();
1141 _tbm_set_last_result(TBM_ERROR_NOT_SUPPORTED);
1143 /* LCOV_EXCL_STOP */
1148 _tbm_util_check_bo_cnt(bufmgr);
1150 bo = calloc(1, sizeof(struct _tbm_bo));
1152 /* LCOV_EXCL_START */
1153 TBM_ERR("error: fail to import tbm_bo by tbm_fd(%d)\n", fd);
1154 _tbm_set_last_result(TBM_ERROR_OUT_OF_MEMORY);
1155 _tbm_bufmgr_mutex_unlock();
1157 /* LCOV_EXCL_STOP */
1160 if (bufmgr->use_hal_tbm) {
1161 bo_data = (tbm_backend_bo_data *)hal_tbm_bufmgr_import_fd(bufmgr->hal_bufmgr, (hal_tbm_fd)fd, (hal_tbm_error *)&error);
1162 /* LCOV_EXCL_START */
1164 TBM_ERR("error: fail to import tbm_bo by tbm_fd(%d). error(%d)\n", fd, error);
1165 _tbm_set_last_result(error);
1168 /* LCOV_EXCL_STOP */
1170 if (!LIST_IS_EMPTY(&bufmgr->bo_list)) {
1171 LIST_FOR_EACH_ENTRY(bo2, &bufmgr->bo_list, item_link) {
1172 if (bo2->bo_data == bo_data) {
1173 TBM_TRACE_BO("find bo(%p) ref(%d) fd(%d) flag(%s) in list\n",
1174 bo2, bo2->ref_cnt, fd, _tbm_flag_to_str(bo2->flags));
1177 _tbm_bufmgr_mutex_unlock();
1182 bo->bo_data = bo_data;
1183 } else if (bufmgr->backend_module_data) {
1184 bo_data = bufmgr->bufmgr_func->bufmgr_import_fd(bufmgr->bufmgr_data, fd, &error);
1186 /* LCOV_EXCL_START */
1187 TBM_ERR("error: fail to import tbm_bo by tbm_fd(%d). error(%d)\n", fd, error);
1188 _tbm_set_last_result(error);
1190 /* LCOV_EXCL_STOP */
1193 if (!LIST_IS_EMPTY(&bufmgr->bo_list)) {
1194 LIST_FOR_EACH_ENTRY(bo2, &bufmgr->bo_list, item_link) {
1195 if (bo2->bo_data == bo_data) {
1196 TBM_TRACE_BO("find bo(%p) ref(%d) fd(%d) flag(%s) in list\n",
1197 bo2, bo2->ref_cnt, fd, _tbm_flag_to_str(bo2->flags));
1200 _tbm_bufmgr_mutex_unlock();
1205 bo->bo_data = bo_data;
1207 bo_priv = bufmgr->backend->bo_import_fd(bo, fd);
1209 /* LCOV_EXCL_START */
1210 TBM_ERR("error: fail to import tbm_bo by tbm_fd(%d)\n", fd);
1211 _tbm_set_last_result(TBM_ERROR_INVALID_OPERATION);
1213 /* LCOV_EXCL_STOP */
1216 if (!LIST_IS_EMPTY(&bufmgr->bo_list)) {
1217 LIST_FOR_EACH_ENTRY(bo2, &bufmgr->bo_list, item_link) {
1218 if (bo2->priv == bo_priv) {
1219 TBM_TRACE_BO("find bo(%p) ref(%d) fd(%d) flag(%s) in list\n",
1220 bo2, bo2->ref_cnt, fd, _tbm_flag_to_str(bo2->flags));
1223 _tbm_bufmgr_mutex_unlock();
1231 if (bufmgr->use_hal_tbm) {
1232 flags = (tbm_bo_memory_type)hal_tbm_bo_get_memory_types((hal_tbm_bo *)bo->bo_data, (hal_tbm_error *)&error);
1233 if (error != TBM_ERROR_NONE) {
1234 TBM_ERR("fail to get the bo flags(memory_types)");
1235 _tbm_set_last_result(error);
1236 flags = TBM_BO_DEFAULT;
1238 } else if (bufmgr->backend_module_data) {
1239 flags = bufmgr->bo_func->bo_get_memory_types(bo->bo_data, &error);
1240 if (error != TBM_ERROR_NONE) {
1241 TBM_ERR("fail to get the bo flags(memory_types)");
1242 _tbm_set_last_result(error);
1243 flags = TBM_BO_DEFAULT;
1246 if (bufmgr->backend->bo_get_flags)
1247 flags = bufmgr->backend->bo_get_flags(bo);
1249 flags = TBM_BO_DEFAULT;
1252 _tbm_bo_init(bufmgr, bo, flags);
1254 TBM_TRACE_BO("import bo(%p) ref(%d) fd(%d) flag(%s)\n",
1255 bo, bo->ref_cnt, fd, _tbm_flag_to_str(bo->flags));
1257 _tbm_bufmgr_mutex_unlock();
1263 _tbm_bufmgr_mutex_unlock();
1268 tbm_bo_size(tbm_bo bo)
1273 _tbm_bufmgr_mutex_lock();
1274 _tbm_set_last_result(TBM_ERROR_NONE);
1276 TBM_BO_RETURN_VAL_IF_FAIL(_tbm_bo_is_valid(bo), 0);
1278 if (bo->bufmgr->use_hal_tbm) {
1279 size = hal_tbm_bo_get_size((hal_tbm_bo *)bo->bo_data, (hal_tbm_error *)&error);
1280 if (error != TBM_ERROR_NONE) {
1281 TBM_ERR("fail to get the size of the bo_data(%d).", error);
1282 _tbm_set_last_result(TBM_ERROR_NONE);
1284 } else if (bo->bufmgr->backend_module_data) {
1285 size = bo->bufmgr->bo_func->bo_get_size(bo->bo_data, &error);
1286 if (error != TBM_ERROR_NONE) {
1287 TBM_ERR("fail to get the size of the bo_data(%d).", error);
1288 _tbm_set_last_result(TBM_ERROR_NONE);
1291 size = bo->bufmgr->backend->bo_size(bo);
1293 TBM_TRACE_BO("bo(%p) size(%d)\n", bo, size);
1295 _tbm_bufmgr_mutex_unlock();
1301 tbm_bo_locked(tbm_bo bo)
1303 _tbm_bufmgr_mutex_lock();
1304 _tbm_set_last_result(TBM_ERROR_NONE);
1306 TBM_BO_RETURN_VAL_IF_FAIL(_tbm_bo_is_valid(bo), 0);
1308 if (bo->bufmgr->bo_lock_type == TBM_BUFMGR_BO_LOCK_TYPE_NEVER) {
1309 TBM_ERR("bo(%p) lock_cnt(%d)\n", bo, bo->lock_cnt);
1310 _tbm_set_last_result(TBM_ERROR_INVALID_OPERATION);
1311 _tbm_bufmgr_mutex_unlock();
1315 if (bo->lock_cnt > 0) {
1316 TBM_TRACE_BO("error: bo(%p) lock_cnt(%d)\n", bo, bo->lock_cnt);
1317 _tbm_bufmgr_mutex_unlock();
1321 TBM_TRACE_BO("bo(%p) lock_cnt(%d)\n", bo, bo->lock_cnt);
1322 _tbm_bufmgr_mutex_unlock();
1328 tbm_bo_swap(tbm_bo bo1, tbm_bo bo2)
1330 tbm_error_e error1, error2;
1331 int size1 = -1, size2 = -2;
1334 _tbm_bufmgr_mutex_lock();
1335 _tbm_set_last_result(TBM_ERROR_NONE);
1337 TBM_BO_RETURN_VAL_IF_FAIL(_tbm_bo_is_valid(bo1), 0);
1338 TBM_BO_RETURN_VAL_IF_FAIL(_tbm_bo_is_valid(bo2), 0);
1340 TBM_TRACE_BO("before: bo1(%p) bo2(%p)\n", bo1, bo2);
1342 if (bo1->bufmgr->use_hal_tbm) {
1343 size1 = hal_tbm_bo_get_size((hal_tbm_bo *)bo1->bo_data, (hal_tbm_error *)&error1);
1344 if (error1 != TBM_ERROR_NONE) {
1345 TBM_ERR("fail to get the size of bo1.(%d)", error1);
1346 _tbm_set_last_result(error1);
1349 size2 = hal_tbm_bo_get_size((hal_tbm_bo *)bo2->bo_data, (hal_tbm_error *)&error2);
1350 if (error2 != TBM_ERROR_NONE) {
1351 TBM_ERR("fail to get the size of bo1.(%d)", error2);
1352 _tbm_set_last_result(error2);
1355 } else if (bo1->bufmgr->backend_module_data) {
1356 size1 = bo1->bufmgr->bo_func->bo_get_size(bo1->bo_data, &error1);
1357 if (error1 != TBM_ERROR_NONE) {
1358 TBM_ERR("fail to get the size of bo1.(%d)", error1);
1359 _tbm_set_last_result(error1);
1362 size2 = bo2->bufmgr->bo_func->bo_get_size(bo2->bo_data, &error2);
1363 if (error2 != TBM_ERROR_NONE) {
1364 TBM_ERR("fail to get the size of bo2.(%d)", error2);
1365 _tbm_set_last_result(error2);
1369 size1 = bo1->bufmgr->backend->bo_size(bo1);
1370 size2 = bo2->bufmgr->backend->bo_size(bo2);
1373 if (size1 != size2) {
1374 TBM_ERR("error: bo1 size(%d) and bo2 size(%d) is different.", size1, size2);
1375 _tbm_set_last_result(TBM_ERROR_INVALID_OPERATION);
1379 TBM_TRACE_BO("after: bo1(%p) bo2(%p)\n", bo1, bo2);
1382 bo1->priv = bo2->priv;
1385 _tbm_bufmgr_mutex_unlock();
1390 TBM_ERR("error: bo1(%p) bo2(%p)\n", bo1, bo2);
1391 _tbm_bufmgr_mutex_unlock();
1397 tbm_bo_add_user_data(tbm_bo bo, unsigned long key,
1398 tbm_data_free data_free_func)
1400 tbm_user_data *data;
1402 _tbm_bufmgr_mutex_lock();
1403 _tbm_set_last_result(TBM_ERROR_NONE);
1405 TBM_BO_RETURN_VAL_IF_FAIL(_tbm_bo_is_valid(bo), 0);
1407 /* check if the data according to the key exist if so, return false. */
1408 data = user_data_lookup(&bo->user_data_list, key);
1410 TBM_TRACE_BO("warning: user data already exist key(%ld)\n", key);
1411 _tbm_set_last_result(TBM_ERROR_INVALID_PARAMETER);
1412 _tbm_bufmgr_mutex_unlock();
1416 data = user_data_create(key, data_free_func);
1418 TBM_ERR("error: bo(%p) key(%lu)\n", bo, key);
1419 _tbm_set_last_result(TBM_ERROR_INVALID_PARAMETER);
1420 _tbm_bufmgr_mutex_unlock();
1424 TBM_TRACE_BO("bo(%p) key(%lu) data(%p)\n", bo, key, data->data);
1426 LIST_ADD(&data->item_link, &bo->user_data_list);
1428 _tbm_bufmgr_mutex_unlock();
1434 tbm_bo_delete_user_data(tbm_bo bo, unsigned long key)
1436 tbm_user_data *old_data;
1438 _tbm_bufmgr_mutex_lock();
1439 _tbm_set_last_result(TBM_ERROR_NONE);
1441 TBM_BO_RETURN_VAL_IF_FAIL(_tbm_bo_is_valid(bo), 0);
1443 if (LIST_IS_EMPTY(&bo->user_data_list)) {
1444 TBM_TRACE_BO("bo(%p) key(%lu)\n", bo, key);
1445 _tbm_set_last_result(TBM_ERROR_INVALID_PARAMETER);
1446 _tbm_bufmgr_mutex_unlock();
1450 old_data = user_data_lookup(&bo->user_data_list, key);
1452 TBM_TRACE_BO("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, old_data->data);
1460 user_data_delete(old_data);
1462 _tbm_bufmgr_mutex_unlock();
1468 tbm_bo_set_user_data(tbm_bo bo, unsigned long key, void *data)
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("error: 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("error: bo(%p) key(%lu)\n", bo, key);
1487 _tbm_set_last_result(TBM_ERROR_INVALID_PARAMETER);
1488 _tbm_bufmgr_mutex_unlock();
1492 if (old_data->data && old_data->free_func)
1493 old_data->free_func(old_data->data);
1494 old_data->data = data;
1496 TBM_TRACE_BO("bo(%p) key(%lu) data(%p)\n", bo, key, old_data->data);
1498 _tbm_bufmgr_mutex_unlock();
1504 tbm_bo_get_user_data(tbm_bo bo, unsigned long key, void **data)
1506 tbm_user_data *old_data;
1508 _tbm_bufmgr_mutex_lock();
1509 _tbm_set_last_result(TBM_ERROR_NONE);
1511 TBM_BO_RETURN_VAL_IF_FAIL(_tbm_bo_is_valid(bo), 0);
1513 if (!data || LIST_IS_EMPTY(&bo->user_data_list)) {
1514 TBM_TRACE_BO("error: bo(%p) key(%lu)\n", bo, key);
1515 _tbm_set_last_result(TBM_ERROR_INVALID_PARAMETER);
1516 _tbm_bufmgr_mutex_unlock();
1520 old_data = user_data_lookup(&bo->user_data_list, key);
1523 TBM_TRACE_BO("error: bo(%p) key(%lu)\n", bo, key);
1524 _tbm_set_last_result(TBM_ERROR_INVALID_PARAMETER);
1525 _tbm_bufmgr_mutex_unlock();
1529 *data = old_data->data;
1531 TBM_TRACE_BO("bo(%p) key(%lu) data(%p)\n", bo, key, old_data->data);
1533 _tbm_bufmgr_mutex_unlock();
1539 tbm_bo_get_flags(tbm_bo bo)
1543 _tbm_bufmgr_mutex_lock();
1545 TBM_BO_RETURN_VAL_IF_FAIL(_tbm_bo_is_valid(bo), 0);
1549 TBM_TRACE_BO("bo(%p)\n", bo);
1551 _tbm_bufmgr_mutex_unlock();
1556 /* LCOV_EXCL_START */
1557 /* internal function */
1559 _tbm_bo_set_surface(tbm_bo bo, tbm_surface_h surface)
1561 _tbm_bufmgr_mutex_lock();
1563 TBM_BO_RETURN_VAL_IF_FAIL(_tbm_bo_is_valid(bo), 0);
1565 bo->surface = surface;
1567 _tbm_bufmgr_mutex_unlock();
1573 _tbm_bo_free(tbm_bo bo)
1575 /* destory the user_data_list */
1576 if (!LIST_IS_EMPTY(&bo->user_data_list)) {
1577 tbm_user_data *old_data = NULL, *tmp;
1579 LIST_FOR_EACH_ENTRY_SAFE(old_data, tmp,
1580 &bo->user_data_list, item_link) {
1581 TBM_DBG("free user_data\n");
1582 user_data_delete(old_data);
1586 while (bo->lock_cnt > 0) {
1587 TBM_ERR("error lock_cnt:%d\n", bo->lock_cnt);
1592 /* call the bo_free */
1593 if (bo->bufmgr->use_hal_tbm) {
1594 hal_tbm_bo_free(bo->bo_data);
1596 } else if (bo->bufmgr->backend_module_data) {
1597 bo->bufmgr->bo_func->bo_free(bo->bo_data);
1600 bo->bufmgr->backend->bo_free(bo);
1608 /* LCOV_EXCL_STOP */