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)
357 tbm_backend_bo_data *bo_data;
360 _tbm_bufmgr_mutex_lock();
361 _tbm_set_last_result(TBM_ERROR_NONE);
363 TBM_BO_RETURN_VAL_IF_FAIL(TBM_BUFMGR_IS_VALID(bufmgr), NULL);
364 TBM_BO_RETURN_VAL_IF_FAIL(size > 0, NULL);
366 bo = calloc(1, sizeof(struct _tbm_bo));
368 /* LCOV_EXCL_START */
369 _tbm_set_last_result(TBM_ERROR_OUT_OF_MEMORY);
370 _tbm_bufmgr_mutex_unlock();
375 _tbm_util_check_bo_cnt(bufmgr);
377 bo_data = tbm_module_bufmgr_bo_alloc(bufmgr->module, bo, size, flags, &error);
378 if (!bo_data || error != TBM_ERROR_NONE) {
379 /* LCOV_EXCL_START */
380 TBM_ERR("tbm_module_bufmgr_bo_alloc failed. error:%d", error);
381 _tbm_set_last_result(error);
385 bo->bo_data = bo_data;
386 bo->priv = (void *)bo_data; // TODO: this will be DEPRECATED.
388 _tbm_bo_init(bufmgr, bo, flags);
390 TBM_TRACE_BO("bo(%p) size(%d) refcnt(%d), flag(%s)\n", bo, size, bo->ref_cnt,
391 _tbm_flag_to_str(bo->flags));
393 _tbm_bufmgr_mutex_unlock();
398 TBM_ERR("error: fail to create of tbm_bo size(%d) flag(%s)\n", size, _tbm_flag_to_str(flags));
400 _tbm_bufmgr_mutex_unlock();
404 /* LCOV_EXCL_START */
406 tbm_bo_alloc_with_format(tbm_bufmgr bufmgr, int format, int bo_idx, int width,
407 int height, int bpp, tbm_bo_memory_type flags, tbm_error_e *error)
410 tbm_backend_bo_data *bo_data;
412 _tbm_bufmgr_mutex_lock();
413 _tbm_set_last_result(TBM_ERROR_NONE);
415 TBM_BO_RETURN_VAL_IF_FAIL(TBM_BUFMGR_IS_VALID(bufmgr), NULL);
417 bo = calloc(1, sizeof(struct _tbm_bo));
419 TBM_ERR("error: fail to tbm_bo_alloc_with_format fmt(%s) idx(%d) w(%d) h(%d) mem_types(%s)\n",
420 FOURCC_STR(format), bo_idx, width, height, _tbm_flag_to_str(flags));
421 _tbm_set_last_result(TBM_ERROR_OUT_OF_MEMORY);
425 _tbm_util_check_bo_cnt(bufmgr);
427 /* LCOV_EXCL_START */
428 if (!bufmgr->use_hal_tbm) {
429 if (!bufmgr->backend_module_data || !bufmgr->bufmgr_func->bufmgr_alloc_bo_with_format) {
430 TBM_ERR("error: not supported tbm_bo_alloc_with_format\n");
431 _tbm_set_last_result(TBM_ERROR_NOT_SUPPORTED);
437 if (bufmgr->use_hal_tbm) {
439 bo_data = (tbm_backend_bo_data *)hal_tbm_bufmgr_alloc_bo_with_format(bufmgr->hal_bufmgr,
440 format, bo_idx, width, height, bpp, (hal_tbm_bo_memory_type)flags, &ret);
442 *error = (tbm_error_e)ret;
443 if (ret != HAL_TBM_ERROR_NONE) {
444 if (ret != HAL_TBM_ERROR_NOT_SUPPORTED) {
445 TBM_ERR("error: fail to tbm_bo_alloc_with_format\n");
447 _tbm_set_last_result(*error);
451 bo->bo_data = bo_data;
453 bo_data = bufmgr->bufmgr_func->bufmgr_alloc_bo_with_format(bufmgr->bufmgr_data, format, bo_idx,
454 width, height, flags, error);
456 TBM_ERR("error: fail to tbm_bo_alloc_with_format fmt(%s) idx(%d) w(%d) h(%d) mem_types(%s)\n",
457 FOURCC_STR(format), bo_idx, width, height, _tbm_flag_to_str(flags));
459 _tbm_set_last_result(*error);
462 bo->bo_data = bo_data;
465 _tbm_bo_init(bufmgr, bo, flags);
467 _tbm_bufmgr_mutex_unlock();
474 _tbm_bufmgr_mutex_unlock();
479 tbm_bo_alloc_with_tiled_format(tbm_bufmgr bufmgr, int width, int height, int bpp, int format,
480 tbm_bo_memory_type flags, int bo_idx, tbm_error_e *error)
483 tbm_backend_bo_data *bo_data;
485 _tbm_bufmgr_mutex_lock();
486 _tbm_set_last_result(TBM_ERROR_NONE);
488 TBM_BO_RETURN_VAL_IF_FAIL(TBM_BUFMGR_IS_VALID(bufmgr), NULL);
490 bo = calloc(1, sizeof(struct _tbm_bo));
492 TBM_ERR("error: fail to tbm_bo_alloc_with_tiled_format fmt(%s) idx(%d) w(%d) h(%d) flags(%s)\n",
493 FOURCC_STR(format), bo_idx, width, height, _tbm_flag_to_str(flags));
494 _tbm_set_last_result(TBM_ERROR_OUT_OF_MEMORY);
495 _tbm_bufmgr_mutex_unlock();
499 _tbm_util_check_bo_cnt(bufmgr);
501 if (!bufmgr->use_hal_tbm) {
502 if (!bufmgr->backend_module_data || !bufmgr->bufmgr_func->bufmgr_alloc_bo_with_tiled_format) {
503 TBM_ERR("error: not supported tbm_bo_alloc_with_tiled_format\n");
504 _tbm_set_last_result(TBM_ERROR_NOT_SUPPORTED);
509 if (bufmgr->use_hal_tbm) {
511 bo_data = (tbm_backend_bo_data *)hal_tbm_bufmgr_alloc_bo_with_format(bufmgr->hal_bufmgr,
512 width, height, bpp, format, (hal_tbm_bo_memory_type)flags, bo_idx, &ret);
514 *error = (tbm_error_e)ret;
515 if (ret != HAL_TBM_ERROR_NONE) {
516 if (ret != HAL_TBM_ERROR_NOT_SUPPORTED) {
517 TBM_ERR("error: fail to tbm_bo_alloc_with_tiled_format fmt(%s) idx(%d) w(%d) h(%d) flags(%s)\n",
518 FOURCC_STR(format), bo_idx, width, height, _tbm_flag_to_str(flags));
520 _tbm_set_last_result(*error);
524 bo->bo_data = bo_data;
526 bo_data = bufmgr->bufmgr_func->bufmgr_alloc_bo_with_tiled_format(bufmgr->bufmgr_data, width, height,
527 bpp, format, flags, bo_idx, error);
529 TBM_ERR("error: fail to tbm_bo_alloc_with_tiled_format fmt(%s) idx(%d) w(%d) h(%d) flags(%s)\n",
530 FOURCC_STR(format), bo_idx, width, height, _tbm_flag_to_str(flags));
532 _tbm_set_last_result(*error);
535 bo->bo_data = bo_data;
538 _tbm_bo_init(bufmgr, bo, flags);
540 _tbm_bufmgr_mutex_unlock();
546 _tbm_bufmgr_mutex_unlock();
551 tbm_bo_alloc_with_surface(tbm_bufmgr bufmgr, int width, int height, int format, int flags, int bo_idx)
556 _tbm_bufmgr_mutex_lock();
557 _tbm_set_last_result(TBM_ERROR_NONE);
559 TBM_BO_RETURN_VAL_IF_FAIL(TBM_BUFMGR_IS_VALID(bufmgr), NULL);
561 bo = calloc(1, sizeof(struct _tbm_bo));
563 TBM_ERR("error: fail to tbm_bo_alloc_with_surface fmt(%s) idx(%d) w(%d) h(%d) flags(%s)\n",
564 FOURCC_STR(format), bo_idx, width, height, _tbm_flag_to_str(flags));
565 _tbm_set_last_result(TBM_ERROR_OUT_OF_MEMORY);
566 _tbm_bufmgr_mutex_unlock();
570 _tbm_util_check_bo_cnt(bufmgr);
572 if (!bufmgr->backend->surface_bo_alloc) {
573 TBM_ERR("error: not supported tbm_bo_alloc_with_surface\n");
574 _tbm_set_last_result(TBM_ERROR_NOT_SUPPORTED);
576 _tbm_bufmgr_mutex_unlock();
580 bo_priv = bufmgr->backend->surface_bo_alloc(bo, width, height, format, flags, bo_idx);
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_INVALID_OPERATION);
586 _tbm_bufmgr_mutex_unlock();
591 _tbm_bo_init(bufmgr, bo, flags);
593 _tbm_bufmgr_mutex_unlock();
599 tbm_bo_alloc_with_bo_data(tbm_bufmgr bufmgr, tbm_backend_bo_data *bo_data, int flags)
601 tbm_bo bo, bo2 = NULL;
603 _tbm_bufmgr_mutex_lock();
604 _tbm_set_last_result(TBM_ERROR_NONE);
606 TBM_BO_RETURN_VAL_IF_FAIL(TBM_BUFMGR_IS_VALID(bufmgr), NULL);
607 TBM_BO_RETURN_VAL_IF_FAIL(bo_data, NULL);
609 // return an existed bo if the bo is already created with the same bo_data.
610 if (!LIST_IS_EMPTY(&bufmgr->bo_list)) {
611 LIST_FOR_EACH_ENTRY(bo2, &bufmgr->bo_list, item_link) {
612 if (bo2->bo_data == bo_data) {
613 TBM_ERR("find bo(%p) ref(%d) flag(%s) in list\n",
614 bo2, bo2->ref_cnt, _tbm_flag_to_str(bo2->flags));
616 _tbm_bufmgr_mutex_unlock();
622 bo = calloc(1, sizeof(struct _tbm_bo));
624 /* LCOV_EXCL_START */
625 _tbm_set_last_result(TBM_ERROR_OUT_OF_MEMORY);
626 _tbm_bufmgr_mutex_unlock();
631 _tbm_util_check_bo_cnt(bufmgr);
633 bo->get_from_hal_surface = 1;
634 bo->bo_data = bo_data;
636 _tbm_bo_init(bufmgr, bo, flags);
638 TBM_TRACE_BO("bo(%p) refcnt(%d), flag(%s)\n", bo, bo->ref_cnt, _tbm_flag_to_str(bo->flags));
640 _tbm_bufmgr_mutex_unlock();
648 tbm_bo_ref(tbm_bo bo)
650 _tbm_bufmgr_mutex_lock();
651 _tbm_set_last_result(TBM_ERROR_NONE);
653 TBM_BO_RETURN_VAL_IF_FAIL(_tbm_bo_is_valid(bo), NULL);
657 TBM_TRACE_BO("bo(%p) ref_cnt(%d)\n", bo, bo->ref_cnt);
659 _tbm_bufmgr_mutex_unlock();
665 tbm_bo_unref(tbm_bo bo)
667 _tbm_bufmgr_mutex_lock();
668 _tbm_set_last_result(TBM_ERROR_NONE);
670 TBM_BO_RETURN_IF_FAIL(_tbm_bo_is_valid(bo));
672 TBM_TRACE_BO("bo(%p) ref_cnt(%d)\n", bo, bo->ref_cnt - 1);
674 if (bo->ref_cnt <= 0) {
675 _tbm_bufmgr_mutex_unlock();
680 if (bo->ref_cnt == 0)
683 _tbm_bufmgr_mutex_unlock();
687 tbm_bo_map(tbm_bo bo, int device, int opt)
689 tbm_bo_handle bo_handle;
692 _tbm_bufmgr_mutex_lock();
693 _tbm_set_last_result(TBM_ERROR_NONE);
695 TBM_BO_RETURN_VAL_IF_FAIL(_tbm_bo_is_valid(bo), (tbm_bo_handle) NULL);
697 if (!_tbm_bo_lock(bo, device, opt)) {
698 TBM_ERR("error: fail to lock bo:%p)\n", bo);
699 _tbm_bufmgr_mutex_unlock();
700 return (tbm_bo_handle) NULL;
703 if (bo->bufmgr->use_hal_tbm) {
704 hal_tbm_bo_handle hbo_handle;
705 hbo_handle = hal_tbm_bo_map((hal_tbm_bo *)bo->bo_data, device, opt, (hal_tbm_error *)&error);
706 if (hbo_handle.ptr == NULL) {
707 /* LCOV_EXCL_START */
708 _tbm_set_last_result(error);
709 TBM_ERR("error: bo(%p) bo_handle(%p) error(%d)\n", bo, hbo_handle.ptr, error);
713 memcpy(&bo_handle.ptr, &hbo_handle.ptr, sizeof(tbm_bo_handle));
714 } else if (bo->bufmgr->backend_module_data) {
715 bo_handle = bo->bufmgr->bo_func->bo_map(bo->bo_data, device, opt, &error);
716 if (bo_handle.ptr == NULL) {
717 /* LCOV_EXCL_START */
718 _tbm_set_last_result(error);
719 TBM_ERR("error: fail to map bo:%p error:%d\n", bo, error);
724 bo_handle = bo->bufmgr->backend->bo_map(bo, device, opt);
725 if (bo_handle.ptr == NULL) {
726 /* LCOV_EXCL_START */
727 _tbm_set_last_result(TBM_ERROR_INVALID_OPERATION);
728 TBM_ERR("error: fail to map bo:%p\n", bo);
734 /* increase the map_count */
737 TBM_TRACE_BO("bo(%p) map_cnt(%d)\n", bo, bo->map_cnt);
739 _tbm_bufmgr_mutex_unlock();
745 _tbm_bufmgr_mutex_unlock();
746 return (tbm_bo_handle) NULL;
750 tbm_bo_unmap(tbm_bo bo)
755 _tbm_bufmgr_mutex_lock();
756 _tbm_set_last_result(TBM_ERROR_NONE);
758 TBM_BO_RETURN_VAL_IF_FAIL(_tbm_bo_is_valid(bo), 0);
759 TBM_BO_RETURN_VAL_IF_FAIL(bo->map_cnt > 0, 0);
761 if (bo->bufmgr->use_hal_tbm) {
762 error = (hal_tbm_error)hal_tbm_bo_unmap((hal_tbm_bo *)bo->bo_data);
763 if (error != TBM_ERROR_NONE) {
764 /* LCOV_EXCL_START */
765 TBM_ERR("error: bo(%p) map_cnt(%d) error(%d)\n", bo, bo->map_cnt, error);
766 _tbm_set_last_result(error);
771 } else if (bo->bufmgr->backend_module_data) {
772 error = bo->bufmgr->bo_func->bo_unmap(bo->bo_data);
773 if (error != TBM_ERROR_NONE) {
774 /* LCOV_EXCL_START */
775 TBM_ERR("error: bo(%p) map_cnt(%d) error(%d)\n", bo, bo->map_cnt, error);
776 _tbm_set_last_result(error);
782 ret = bo->bufmgr->backend->bo_unmap(bo);
784 /* LCOV_EXCL_START */
785 TBM_ERR("error: bo(%p) map_cnt(%d)\n", bo, bo->map_cnt);
786 _tbm_set_last_result(TBM_ERROR_INVALID_OPERATION);
792 /* decrease the map_count */
795 TBM_TRACE_BO("bo(%p) map_cnt(%d)\n", bo, bo->map_cnt);
800 _tbm_bufmgr_mutex_unlock();
806 tbm_bo_get_handle(tbm_bo bo, int device)
808 tbm_bo_handle bo_handle;
811 _tbm_bufmgr_mutex_lock();
812 _tbm_set_last_result(TBM_ERROR_NONE);
814 TBM_BO_RETURN_VAL_IF_FAIL(_tbm_bo_is_valid(bo), (tbm_bo_handle) NULL);
816 if (bo->bufmgr->use_hal_tbm) {
817 hal_tbm_bo_handle hbo_handle;
818 hbo_handle = hal_tbm_bo_get_handle((hal_tbm_bo *)bo->bo_data, device, (hal_tbm_error *)&error);
819 if (hbo_handle.ptr == NULL) {
820 /* LCOV_EXCL_START */
821 TBM_ERR("error: bo(%p) bo_handle(%p) error(%d)\n", bo, hbo_handle.ptr, error);
822 _tbm_set_last_result(error);
826 memcpy(&bo_handle.ptr, &hbo_handle.ptr, sizeof(tbm_bo_handle));
827 } else if (bo->bufmgr->backend_module_data) {
828 bo_handle = bo->bufmgr->bo_func->bo_get_handle(bo->bo_data, device, &error);
829 if (bo_handle.ptr == NULL) {
830 /* LCOV_EXCL_START */
831 TBM_ERR("error: bo(%p) bo_handle(%p) error(%d)\n", bo, bo_handle.ptr, error);
832 _tbm_set_last_result(error);
837 bo_handle = bo->bufmgr->backend->bo_get_handle(bo, device);
838 if (bo_handle.ptr == NULL) {
839 /* LCOV_EXCL_START */
840 TBM_ERR("error: bo(%p) bo_handle(%p)\n", bo, bo_handle.ptr);
841 _tbm_set_last_result(TBM_ERROR_INVALID_OPERATION);
847 TBM_TRACE_BO("bo(%p) bo_handle(%p)\n", bo, bo_handle.ptr);
849 _tbm_bufmgr_mutex_unlock();
854 _tbm_bufmgr_mutex_unlock();
855 return (tbm_bo_handle) NULL;
859 tbm_bo_export(tbm_bo bo)
864 _tbm_bufmgr_mutex_lock();
865 _tbm_set_last_result(TBM_ERROR_NONE);
867 TBM_BO_RETURN_VAL_IF_FAIL(_tbm_bo_is_valid(bo), 0);
869 if (bo->bufmgr->use_hal_tbm) {
870 ret = (hal_tbm_key)hal_tbm_bo_export_key((hal_tbm_bo *)bo->bo_data, (hal_tbm_error *)&error);
872 /* LCOV_EXCL_START */
873 TBM_ERR("error: bo(%p) tbm_key(%d) error(%d)\n", bo, ret, error);
874 _tbm_set_last_result(error);
878 } else if (bo->bufmgr->backend_module_data) {
879 if (!bo->bufmgr->bo_func->bo_export_key) {
880 /* LCOV_EXCL_START */
881 _tbm_bufmgr_mutex_unlock();
882 _tbm_set_last_result(TBM_ERROR_NOT_SUPPORTED);
887 ret = bo->bufmgr->bo_func->bo_export_key(bo->bo_data, &error);
889 /* LCOV_EXCL_START */
890 TBM_ERR("error: bo(%p) tbm_key(%d) error(%d)\n", bo, ret, error);
891 _tbm_set_last_result(error);
896 if (!bo->bufmgr->backend->bo_export) {
897 /* LCOV_EXCL_START */
898 _tbm_bufmgr_mutex_unlock();
899 _tbm_set_last_result(TBM_ERROR_NOT_SUPPORTED);
904 ret = bo->bufmgr->backend->bo_export(bo);
906 /* LCOV_EXCL_START */
907 TBM_ERR("error: bo(%p) tbm_key(%d)\n", bo, ret);
908 _tbm_set_last_result(TBM_ERROR_INVALID_OPERATION);
914 TBM_TRACE_BO("bo(%p) tbm_key(%u)\n", bo, ret);
917 _tbm_bufmgr_mutex_unlock();
923 tbm_bo_export_fd(tbm_bo bo)
928 _tbm_bufmgr_mutex_lock();
929 _tbm_set_last_result(TBM_ERROR_NONE);
931 TBM_BO_RETURN_VAL_IF_FAIL(_tbm_bo_is_valid(bo), -1);
933 if (bo->bufmgr->use_hal_tbm) {
934 ret = (hal_tbm_fd)hal_tbm_bo_export_fd((hal_tbm_bo *)bo->bo_data, (hal_tbm_error *)&error);
936 /* LCOV_EXCL_START */
937 TBM_ERR("error: bo(%p) tbm_fd(%d) error(%d)\n", bo, ret, error);
938 _tbm_set_last_result(error);
942 } else if (bo->bufmgr->backend_module_data) {
943 if (!bo->bufmgr->bo_func->bo_export_fd) {
944 /* LCOV_EXCL_START */
945 _tbm_bufmgr_mutex_unlock();
946 _tbm_set_last_result(TBM_ERROR_NOT_SUPPORTED);
951 ret = bo->bufmgr->bo_func->bo_export_fd(bo->bo_data, &error);
953 /* LCOV_EXCL_START */
954 TBM_ERR("error: bo(%p) tbm_fd(%d) error(%d)\n", bo, ret, error);
955 _tbm_set_last_result(error);
960 if (!bo->bufmgr->backend->bo_export_fd) {
961 /* LCOV_EXCL_START */
962 _tbm_bufmgr_mutex_unlock();
963 _tbm_set_last_result(TBM_ERROR_NOT_SUPPORTED);
968 ret = bo->bufmgr->backend->bo_export_fd(bo);
970 /* LCOV_EXCL_START */
971 TBM_ERR("error: bo(%p) tbm_fd(%d)\n", bo, ret);
972 _tbm_set_last_result(TBM_ERROR_INVALID_OPERATION);
978 TBM_TRACE_BO("bo(%p) tbm_fd(%d)\n", bo, ret);
981 _tbm_bufmgr_mutex_unlock();
987 tbm_bo_import(tbm_bufmgr bufmgr, unsigned int key)
993 tbm_backend_bo_data *bo_data;
996 _tbm_bufmgr_mutex_lock();
997 _tbm_set_last_result(TBM_ERROR_NONE);
999 TBM_BO_RETURN_VAL_IF_FAIL(TBM_BUFMGR_IS_VALID(bufmgr), NULL);
1001 if (!bufmgr->use_hal_tbm) {
1002 if (bufmgr->backend_module_data) {
1003 if (!bufmgr->bufmgr_func->bufmgr_import_key) {
1004 /* LCOV_EXCL_START */
1005 _tbm_bufmgr_mutex_unlock();
1006 _tbm_set_last_result(TBM_ERROR_NOT_SUPPORTED);
1008 /* LCOV_EXCL_STOP */
1011 if (!bufmgr->backend->bo_import) {
1012 /* LCOV_EXCL_START */
1013 _tbm_bufmgr_mutex_unlock();
1014 _tbm_set_last_result(TBM_ERROR_NOT_SUPPORTED);
1016 /* LCOV_EXCL_STOP */
1021 _tbm_util_check_bo_cnt(bufmgr);
1023 bo = calloc(1, sizeof(struct _tbm_bo));
1025 /* LCOV_EXCL_START */
1026 TBM_ERR("error: fail to import of tbm_bo by key(%d)\n", key);
1027 _tbm_set_last_result(TBM_ERROR_OUT_OF_MEMORY);
1028 _tbm_bufmgr_mutex_unlock();
1030 /* LCOV_EXCL_STOP */
1033 if (bufmgr->use_hal_tbm) {
1034 bo_data = (tbm_backend_bo_data *)hal_tbm_bufmgr_import_key(bufmgr->hal_bufmgr, key, (hal_tbm_error *)&error);
1035 /* LCOV_EXCL_START */
1037 TBM_ERR("error: fail to import of tbm_bo by key(%d). error(%d)\n", key, error);
1038 _tbm_set_last_result(error);
1041 /* LCOV_EXCL_STOP */
1042 if (!LIST_IS_EMPTY(&bufmgr->bo_list)) {
1043 LIST_FOR_EACH_ENTRY(bo2, &bufmgr->bo_list, item_link) {
1044 if (bo2->bo_data == bo_data) {
1045 TBM_TRACE_BO("find bo(%p) ref(%d) key(%d) flag(%s) in list\n",
1046 bo2, bo2->ref_cnt, key,
1047 _tbm_flag_to_str(bo2->flags));
1050 _tbm_bufmgr_mutex_unlock();
1055 bo->bo_data = bo_data;
1056 } else if (bufmgr->backend_module_data) {
1057 bo_data = bufmgr->bufmgr_func->bufmgr_import_key(bufmgr->bufmgr_data, key, &error);
1059 /* LCOV_EXCL_START */
1060 TBM_ERR("error: fail to import of tbm_bo by key(%d). error(%d)\n", key, error);
1061 _tbm_set_last_result(error);
1063 /* LCOV_EXCL_STOP */
1066 if (!LIST_IS_EMPTY(&bufmgr->bo_list)) {
1067 LIST_FOR_EACH_ENTRY(bo2, &bufmgr->bo_list, item_link) {
1068 if (bo2->bo_data == bo_data) {
1069 TBM_TRACE_BO("find bo(%p) ref(%d) key(%d) flag(%s) in list\n",
1070 bo2, bo2->ref_cnt, key,
1071 _tbm_flag_to_str(bo2->flags));
1074 _tbm_bufmgr_mutex_unlock();
1079 bo->bo_data = bo_data;
1081 bo_priv = bufmgr->backend->bo_import(bo, key);
1083 /* LCOV_EXCL_START */
1084 TBM_ERR("error: fail to import of tbm_bo by key(%d)\n", key);
1085 _tbm_set_last_result(TBM_ERROR_INVALID_OPERATION);
1087 /* LCOV_EXCL_STOP */
1090 if (!LIST_IS_EMPTY(&bufmgr->bo_list)) {
1091 LIST_FOR_EACH_ENTRY(bo2, &bufmgr->bo_list, item_link) {
1092 if (bo2->priv == bo_priv) {
1093 TBM_TRACE_BO("find bo(%p) ref(%d) key(%d) flag(%s) in list\n",
1094 bo2, bo2->ref_cnt, key,
1095 _tbm_flag_to_str(bo2->flags));
1098 _tbm_bufmgr_mutex_unlock();
1106 if (bufmgr->use_hal_tbm) {
1107 flags = (tbm_bo_memory_type)hal_tbm_bo_get_memory_types((hal_tbm_bo *)bo->bo_data, (hal_tbm_error *)&error);
1108 if (error != TBM_ERROR_NONE) {
1109 TBM_ERR("fail to get the bo flags(memory_types)");
1110 _tbm_set_last_result(error);
1111 flags = TBM_BO_DEFAULT;
1113 } else if (bufmgr->backend_module_data) {
1114 flags = bufmgr->bo_func->bo_get_memory_types(bo->bo_data, &error);
1115 if (error != TBM_ERROR_NONE) {
1116 TBM_ERR("fail to get the bo flags(memory_types)");
1117 _tbm_set_last_result(error);
1118 flags = TBM_BO_DEFAULT;
1121 if (bufmgr->backend->bo_get_flags)
1122 flags = bufmgr->backend->bo_get_flags(bo);
1124 flags = TBM_BO_DEFAULT;
1127 _tbm_bo_init(bufmgr, bo, flags);
1129 TBM_TRACE_BO("import new bo(%p) ref(%d) key(%d) flag(%s) in list\n",
1130 bo, bo->ref_cnt, key, _tbm_flag_to_str(bo->flags));
1132 _tbm_bufmgr_mutex_unlock();
1138 _tbm_bufmgr_mutex_unlock();
1143 tbm_bo_import_fd(tbm_bufmgr bufmgr, tbm_fd fd)
1148 tbm_backend_bo_data *bo_data;
1152 _tbm_bufmgr_mutex_lock();
1153 _tbm_set_last_result(TBM_ERROR_NONE);
1155 TBM_BO_RETURN_VAL_IF_FAIL(TBM_BUFMGR_IS_VALID(bufmgr), NULL);
1157 if (!bufmgr->use_hal_tbm) {
1158 if (bufmgr->backend_module_data) {
1159 if (!bufmgr->bufmgr_func->bufmgr_import_fd) {
1160 /* LCOV_EXCL_START */
1161 _tbm_bufmgr_mutex_unlock();
1162 _tbm_set_last_result(TBM_ERROR_NOT_SUPPORTED);
1164 /* LCOV_EXCL_STOP */
1167 if (!bufmgr->backend->bo_import_fd) {
1168 /* LCOV_EXCL_START */
1169 _tbm_bufmgr_mutex_unlock();
1170 _tbm_set_last_result(TBM_ERROR_NOT_SUPPORTED);
1172 /* LCOV_EXCL_STOP */
1177 _tbm_util_check_bo_cnt(bufmgr);
1179 bo = calloc(1, sizeof(struct _tbm_bo));
1181 /* LCOV_EXCL_START */
1182 TBM_ERR("error: fail to import tbm_bo by tbm_fd(%d)\n", fd);
1183 _tbm_set_last_result(TBM_ERROR_OUT_OF_MEMORY);
1184 _tbm_bufmgr_mutex_unlock();
1186 /* LCOV_EXCL_STOP */
1189 if (bufmgr->use_hal_tbm) {
1190 bo_data = (tbm_backend_bo_data *)hal_tbm_bufmgr_import_fd(bufmgr->hal_bufmgr, (hal_tbm_fd)fd, (hal_tbm_error *)&error);
1191 /* LCOV_EXCL_START */
1193 TBM_ERR("error: fail to import tbm_bo by tbm_fd(%d). error(%d)\n", fd, error);
1194 _tbm_set_last_result(error);
1197 /* LCOV_EXCL_STOP */
1199 if (!LIST_IS_EMPTY(&bufmgr->bo_list)) {
1200 LIST_FOR_EACH_ENTRY(bo2, &bufmgr->bo_list, item_link) {
1201 if (bo2->bo_data == bo_data) {
1202 TBM_TRACE_BO("find bo(%p) ref(%d) fd(%d) flag(%s) in list\n",
1203 bo2, bo2->ref_cnt, fd, _tbm_flag_to_str(bo2->flags));
1206 _tbm_bufmgr_mutex_unlock();
1211 bo->bo_data = bo_data;
1212 } else if (bufmgr->backend_module_data) {
1213 bo_data = bufmgr->bufmgr_func->bufmgr_import_fd(bufmgr->bufmgr_data, fd, &error);
1215 /* LCOV_EXCL_START */
1216 TBM_ERR("error: fail to import tbm_bo by tbm_fd(%d). error(%d)\n", fd, error);
1217 _tbm_set_last_result(error);
1219 /* LCOV_EXCL_STOP */
1222 if (!LIST_IS_EMPTY(&bufmgr->bo_list)) {
1223 LIST_FOR_EACH_ENTRY(bo2, &bufmgr->bo_list, item_link) {
1224 if (bo2->bo_data == bo_data) {
1225 TBM_TRACE_BO("find bo(%p) ref(%d) fd(%d) flag(%s) in list\n",
1226 bo2, bo2->ref_cnt, fd, _tbm_flag_to_str(bo2->flags));
1229 _tbm_bufmgr_mutex_unlock();
1234 bo->bo_data = bo_data;
1236 bo_priv = bufmgr->backend->bo_import_fd(bo, fd);
1238 /* LCOV_EXCL_START */
1239 TBM_ERR("error: fail to import tbm_bo by tbm_fd(%d)\n", fd);
1240 _tbm_set_last_result(TBM_ERROR_INVALID_OPERATION);
1242 /* LCOV_EXCL_STOP */
1245 if (!LIST_IS_EMPTY(&bufmgr->bo_list)) {
1246 LIST_FOR_EACH_ENTRY(bo2, &bufmgr->bo_list, item_link) {
1247 if (bo2->priv == bo_priv) {
1248 TBM_TRACE_BO("find bo(%p) ref(%d) fd(%d) flag(%s) in list\n",
1249 bo2, bo2->ref_cnt, fd, _tbm_flag_to_str(bo2->flags));
1252 _tbm_bufmgr_mutex_unlock();
1260 if (bufmgr->use_hal_tbm) {
1261 flags = (tbm_bo_memory_type)hal_tbm_bo_get_memory_types((hal_tbm_bo *)bo->bo_data, (hal_tbm_error *)&error);
1262 if (error != TBM_ERROR_NONE) {
1263 TBM_ERR("fail to get the bo flags(memory_types)");
1264 _tbm_set_last_result(error);
1265 flags = TBM_BO_DEFAULT;
1267 } else if (bufmgr->backend_module_data) {
1268 flags = bufmgr->bo_func->bo_get_memory_types(bo->bo_data, &error);
1269 if (error != TBM_ERROR_NONE) {
1270 TBM_ERR("fail to get the bo flags(memory_types)");
1271 _tbm_set_last_result(error);
1272 flags = TBM_BO_DEFAULT;
1275 if (bufmgr->backend->bo_get_flags)
1276 flags = bufmgr->backend->bo_get_flags(bo);
1278 flags = TBM_BO_DEFAULT;
1281 _tbm_bo_init(bufmgr, bo, flags);
1283 TBM_TRACE_BO("import bo(%p) ref(%d) fd(%d) flag(%s)\n",
1284 bo, bo->ref_cnt, fd, _tbm_flag_to_str(bo->flags));
1286 _tbm_bufmgr_mutex_unlock();
1292 _tbm_bufmgr_mutex_unlock();
1297 tbm_bo_size(tbm_bo bo)
1302 _tbm_bufmgr_mutex_lock();
1303 _tbm_set_last_result(TBM_ERROR_NONE);
1305 TBM_BO_RETURN_VAL_IF_FAIL(_tbm_bo_is_valid(bo), 0);
1307 if (bo->bufmgr->use_hal_tbm) {
1308 size = hal_tbm_bo_get_size((hal_tbm_bo *)bo->bo_data, (hal_tbm_error *)&error);
1309 if (error != TBM_ERROR_NONE) {
1310 TBM_ERR("fail to get the size of the bo_data(%d).", error);
1311 _tbm_set_last_result(TBM_ERROR_NONE);
1313 } else if (bo->bufmgr->backend_module_data) {
1314 size = bo->bufmgr->bo_func->bo_get_size(bo->bo_data, &error);
1315 if (error != TBM_ERROR_NONE) {
1316 TBM_ERR("fail to get the size of the bo_data(%d).", error);
1317 _tbm_set_last_result(TBM_ERROR_NONE);
1320 size = bo->bufmgr->backend->bo_size(bo);
1322 TBM_TRACE_BO("bo(%p) size(%d)\n", bo, size);
1324 _tbm_bufmgr_mutex_unlock();
1330 tbm_bo_locked(tbm_bo bo)
1332 _tbm_bufmgr_mutex_lock();
1333 _tbm_set_last_result(TBM_ERROR_NONE);
1335 TBM_BO_RETURN_VAL_IF_FAIL(_tbm_bo_is_valid(bo), 0);
1337 if (bo->bufmgr->bo_lock_type == TBM_BUFMGR_BO_LOCK_TYPE_NEVER) {
1338 TBM_ERR("bo(%p) lock_cnt(%d)\n", bo, bo->lock_cnt);
1339 _tbm_set_last_result(TBM_ERROR_INVALID_OPERATION);
1340 _tbm_bufmgr_mutex_unlock();
1344 if (bo->lock_cnt > 0) {
1345 TBM_TRACE_BO("error: bo(%p) lock_cnt(%d)\n", bo, bo->lock_cnt);
1346 _tbm_bufmgr_mutex_unlock();
1350 TBM_TRACE_BO("bo(%p) lock_cnt(%d)\n", bo, bo->lock_cnt);
1351 _tbm_bufmgr_mutex_unlock();
1357 tbm_bo_swap(tbm_bo bo1, tbm_bo bo2)
1359 tbm_error_e error1, error2;
1360 int size1 = -1, size2 = -2;
1363 _tbm_bufmgr_mutex_lock();
1364 _tbm_set_last_result(TBM_ERROR_NONE);
1366 TBM_BO_RETURN_VAL_IF_FAIL(_tbm_bo_is_valid(bo1), 0);
1367 TBM_BO_RETURN_VAL_IF_FAIL(_tbm_bo_is_valid(bo2), 0);
1369 TBM_TRACE_BO("before: bo1(%p) bo2(%p)\n", bo1, bo2);
1371 if (bo1->bufmgr->use_hal_tbm) {
1372 size1 = hal_tbm_bo_get_size((hal_tbm_bo *)bo1->bo_data, (hal_tbm_error *)&error1);
1373 if (error1 != TBM_ERROR_NONE) {
1374 TBM_ERR("fail to get the size of bo1.(%d)", error1);
1375 _tbm_set_last_result(error1);
1378 size2 = hal_tbm_bo_get_size((hal_tbm_bo *)bo2->bo_data, (hal_tbm_error *)&error2);
1379 if (error2 != TBM_ERROR_NONE) {
1380 TBM_ERR("fail to get the size of bo1.(%d)", error2);
1381 _tbm_set_last_result(error2);
1384 } else if (bo1->bufmgr->backend_module_data) {
1385 size1 = bo1->bufmgr->bo_func->bo_get_size(bo1->bo_data, &error1);
1386 if (error1 != TBM_ERROR_NONE) {
1387 TBM_ERR("fail to get the size of bo1.(%d)", error1);
1388 _tbm_set_last_result(error1);
1391 size2 = bo2->bufmgr->bo_func->bo_get_size(bo2->bo_data, &error2);
1392 if (error2 != TBM_ERROR_NONE) {
1393 TBM_ERR("fail to get the size of bo2.(%d)", error2);
1394 _tbm_set_last_result(error2);
1398 size1 = bo1->bufmgr->backend->bo_size(bo1);
1399 size2 = bo2->bufmgr->backend->bo_size(bo2);
1402 if (size1 != size2) {
1403 TBM_ERR("error: bo1 size(%d) and bo2 size(%d) is different.", size1, size2);
1404 _tbm_set_last_result(TBM_ERROR_INVALID_OPERATION);
1408 TBM_TRACE_BO("after: bo1(%p) bo2(%p)\n", bo1, bo2);
1411 bo1->priv = bo2->priv;
1414 _tbm_bufmgr_mutex_unlock();
1419 TBM_ERR("error: bo1(%p) bo2(%p)\n", bo1, bo2);
1420 _tbm_bufmgr_mutex_unlock();
1426 tbm_bo_add_user_data(tbm_bo bo, unsigned long key,
1427 tbm_data_free data_free_func)
1429 tbm_user_data *data;
1431 _tbm_bufmgr_mutex_lock();
1432 _tbm_set_last_result(TBM_ERROR_NONE);
1434 TBM_BO_RETURN_VAL_IF_FAIL(_tbm_bo_is_valid(bo), 0);
1436 /* check if the data according to the key exist if so, return false. */
1437 data = user_data_lookup(&bo->user_data_list, key);
1439 TBM_TRACE_BO("warning: user data already exist key(%ld)\n", key);
1440 _tbm_set_last_result(TBM_ERROR_INVALID_PARAMETER);
1441 _tbm_bufmgr_mutex_unlock();
1445 data = user_data_create(key, data_free_func);
1447 TBM_ERR("error: bo(%p) key(%lu)\n", bo, key);
1448 _tbm_set_last_result(TBM_ERROR_INVALID_PARAMETER);
1449 _tbm_bufmgr_mutex_unlock();
1453 TBM_TRACE_BO("bo(%p) key(%lu) data(%p)\n", bo, key, data->data);
1455 LIST_ADD(&data->item_link, &bo->user_data_list);
1457 _tbm_bufmgr_mutex_unlock();
1463 tbm_bo_delete_user_data(tbm_bo bo, unsigned long key)
1465 tbm_user_data *old_data;
1467 _tbm_bufmgr_mutex_lock();
1468 _tbm_set_last_result(TBM_ERROR_NONE);
1470 TBM_BO_RETURN_VAL_IF_FAIL(_tbm_bo_is_valid(bo), 0);
1472 if (LIST_IS_EMPTY(&bo->user_data_list)) {
1473 TBM_TRACE_BO("bo(%p) key(%lu)\n", bo, key);
1474 _tbm_set_last_result(TBM_ERROR_INVALID_PARAMETER);
1475 _tbm_bufmgr_mutex_unlock();
1479 old_data = user_data_lookup(&bo->user_data_list, key);
1481 TBM_TRACE_BO("bo(%p) key(%lu)\n", bo, key);
1482 _tbm_set_last_result(TBM_ERROR_INVALID_PARAMETER);
1483 _tbm_bufmgr_mutex_unlock();
1487 TBM_TRACE_BO("bo(%p) key(%lu) data(%p)\n", bo, key, old_data->data);
1489 user_data_delete(old_data);
1491 _tbm_bufmgr_mutex_unlock();
1497 tbm_bo_set_user_data(tbm_bo bo, unsigned long key, void *data)
1499 tbm_user_data *old_data;
1501 _tbm_bufmgr_mutex_lock();
1502 _tbm_set_last_result(TBM_ERROR_NONE);
1504 TBM_BO_RETURN_VAL_IF_FAIL(_tbm_bo_is_valid(bo), 0);
1506 if (LIST_IS_EMPTY(&bo->user_data_list)) {
1507 TBM_TRACE_BO("error: bo(%p) key(%lu)\n", bo, key);
1508 _tbm_set_last_result(TBM_ERROR_INVALID_PARAMETER);
1509 _tbm_bufmgr_mutex_unlock();
1513 old_data = user_data_lookup(&bo->user_data_list, key);
1515 TBM_TRACE_BO("error: bo(%p) key(%lu)\n", bo, key);
1516 _tbm_set_last_result(TBM_ERROR_INVALID_PARAMETER);
1517 _tbm_bufmgr_mutex_unlock();
1521 if (old_data->data && old_data->free_func)
1522 old_data->free_func(old_data->data);
1523 old_data->data = data;
1525 TBM_TRACE_BO("bo(%p) key(%lu) data(%p)\n", bo, key, old_data->data);
1527 _tbm_bufmgr_mutex_unlock();
1533 tbm_bo_get_user_data(tbm_bo bo, unsigned long key, void **data)
1535 tbm_user_data *old_data;
1537 _tbm_bufmgr_mutex_lock();
1538 _tbm_set_last_result(TBM_ERROR_NONE);
1540 TBM_BO_RETURN_VAL_IF_FAIL(_tbm_bo_is_valid(bo), 0);
1542 if (!data || LIST_IS_EMPTY(&bo->user_data_list)) {
1543 TBM_TRACE_BO("error: bo(%p) key(%lu)\n", bo, key);
1544 _tbm_set_last_result(TBM_ERROR_INVALID_PARAMETER);
1545 _tbm_bufmgr_mutex_unlock();
1549 old_data = user_data_lookup(&bo->user_data_list, key);
1552 TBM_TRACE_BO("error: bo(%p) key(%lu)\n", bo, key);
1553 _tbm_set_last_result(TBM_ERROR_INVALID_PARAMETER);
1554 _tbm_bufmgr_mutex_unlock();
1558 *data = old_data->data;
1560 TBM_TRACE_BO("bo(%p) key(%lu) data(%p)\n", bo, key, old_data->data);
1562 _tbm_bufmgr_mutex_unlock();
1568 tbm_bo_get_flags(tbm_bo bo)
1572 _tbm_bufmgr_mutex_lock();
1574 TBM_BO_RETURN_VAL_IF_FAIL(_tbm_bo_is_valid(bo), 0);
1578 TBM_TRACE_BO("bo(%p)\n", bo);
1580 _tbm_bufmgr_mutex_unlock();
1585 /* LCOV_EXCL_START */
1586 /* internal function */
1588 _tbm_bo_set_surface(tbm_bo bo, tbm_surface_h surface)
1590 _tbm_bufmgr_mutex_lock();
1592 TBM_BO_RETURN_VAL_IF_FAIL(_tbm_bo_is_valid(bo), 0);
1594 bo->surface = surface;
1596 _tbm_bufmgr_mutex_unlock();
1602 _tbm_bo_free(tbm_bo bo)
1604 /* destory the user_data_list */
1605 if (!LIST_IS_EMPTY(&bo->user_data_list)) {
1606 tbm_user_data *old_data = NULL, *tmp;
1608 LIST_FOR_EACH_ENTRY_SAFE(old_data, tmp,
1609 &bo->user_data_list, item_link) {
1610 TBM_DBG("free user_data\n");
1611 user_data_delete(old_data);
1615 while (bo->lock_cnt > 0) {
1616 TBM_ERR("error lock_cnt:%d\n", bo->lock_cnt);
1621 /* call the bo_free */
1622 if (bo->bufmgr->use_hal_tbm) {
1623 // call hal_tbm_bo_free when bo is created by tbm_bo_alloc api.
1624 if (!bo->get_from_hal_surface) {
1625 bo->get_from_hal_surface = 0;
1627 hal_tbm_bo_free(bo->bo_data);
1630 } else if (bo->bufmgr->backend_module_data) {
1631 bo->bufmgr->bo_func->bo_free(bo->bo_data);
1634 bo->bufmgr->backend->bo_free(bo);
1642 /* LCOV_EXCL_STOP */