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 **************************************************************************/
34 #include "tbm_bufmgr.h"
35 #include "tbm_bufmgr_int.h"
36 #include "tbm_bufmgr_backend.h"
39 #include <sys/resource.h>
56 static pthread_mutex_t gLock = PTHREAD_MUTEX_INITIALIZER;
57 static pthread_mutex_t tbm_bufmgr_lock = PTHREAD_MUTEX_INITIALIZER;
58 static __thread tbm_error_e tbm_last_error = TBM_ERROR_NONE;
59 static double scale_factor = 0;
60 static void _tbm_bufmgr_mutex_unlock(void);
62 //#define TBM_BUFMGR_INIT_TIME
64 #define PREFIX_LIB "libtbm_"
65 #define SUFFIX_LIB ".so"
66 #define DEFAULT_LIB PREFIX_LIB"default"SUFFIX_LIB
68 /* values to indicate unspecified fields in XF86ModReqInfo. */
69 #define MAJOR_UNSPEC 0xFF
70 #define MINOR_UNSPEC 0xFF
71 #define PATCH_UNSPEC 0xFFFF
72 #define ABI_VERS_UNSPEC 0xFFFFFFFF
74 #define MODULE_VERSION_NUMERIC(maj, min, patch) \
75 ((((maj) & 0xFF) << 24) | (((min) & 0xFF) << 16) | (patch & 0xFFFF))
76 #define GET_MODULE_MAJOR_VERSION(vers) (((vers) >> 24) & 0xFF)
77 #define GET_MODULE_MINOR_VERSION(vers) (((vers) >> 16) & 0xFF)
78 #define GET_MODULE_PATCHLEVEL(vers) ((vers) & 0xFFFF)
81 #define TBM_BUFMGR_RETURN_IF_FAIL(cond) {\
83 TBM_LOG_E("'%s' failed.\n", #cond);\
84 _tbm_bufmgr_mutex_unlock();\
89 #define TBM_BUFMGR_RETURN_VAL_IF_FAIL(cond, val) {\
91 TBM_LOG_E("'%s' failed.\n", #cond);\
92 _tbm_bufmgr_mutex_unlock();\
104 _tbm_set_last_result(tbm_error_e err)
106 tbm_last_error = err;
109 /* LCOV_EXCL_START */
111 _tbm_bufmgr_mutex_init(void)
113 static bool tbm_bufmgr_mutex_init = false;
115 if (tbm_bufmgr_mutex_init)
118 if (pthread_mutex_init(&tbm_bufmgr_lock, NULL)) {
119 TBM_LOG_E("fail: Cannot pthread_mutex_init for tbm_bufmgr_lock.\n");
123 tbm_bufmgr_mutex_init = true;
129 _tbm_bufmgr_mutex_lock(void)
131 if (!_tbm_bufmgr_mutex_init()) {
132 TBM_LOG_E("fail: _tbm_bufmgr_mutex_init()\n");
136 pthread_mutex_lock(&tbm_bufmgr_lock);
140 _tbm_bufmgr_mutex_unlock(void)
142 pthread_mutex_unlock(&tbm_bufmgr_lock);
146 _tbm_flag_to_str(int f)
148 static char str[255];
150 if (f == TBM_BO_DEFAULT)
151 snprintf(str, 255, "DEFAULT");
155 if (f & TBM_BO_SCANOUT)
156 c = snprintf(&str[c], 255, "SCANOUT");
158 if (f & TBM_BO_NONCACHABLE) {
160 c = snprintf(&str[c], 255, ", ");
161 c = snprintf(&str[c], 255, "NONCACHABLE,");
166 c = snprintf(&str[c], 255, ", ");
167 c = snprintf(&str[c], 255, "WC");
175 _tbm_util_check_bo_cnt(tbm_bufmgr bufmgr)
177 static int last_chk_bo_cnt = 0;
179 if ((bufmgr->bo_cnt >= 500) && ((bufmgr->bo_cnt % 20) == 0) &&
180 (bufmgr->bo_cnt > last_chk_bo_cnt)) {
181 TBM_DEBUG("============TBM BO CNT DEBUG: bo_cnt=%d\n",
184 tbm_bufmgr_debug_show(bufmgr);
186 last_chk_bo_cnt = bufmgr->bo_cnt;
191 _tbm_util_get_max_surface_size(int *w, int *h)
193 tbm_surface_info_s info;
194 tbm_surface_h surface = NULL;
200 if (gBufMgr == NULL || LIST_IS_EMPTY(&gBufMgr->surf_list))
203 LIST_FOR_EACH_ENTRY(surface, &gBufMgr->surf_list, item_link) {
204 if (tbm_surface_get_info(surface, &info) == TBM_SURFACE_ERROR_NONE) {
208 if (*h < info.height)
217 _tbm_util_get_appname_brief(char *brief)
221 char temp[255] = {0,};
222 char *saveptr = NULL;
224 token = strtok_r(brief, delim, &saveptr);
226 while (token != NULL) {
227 memset(temp, 0x00, 255 * sizeof(char));
228 strncpy(temp, token, 254 * sizeof(char));
229 token = strtok_r(NULL, delim, &saveptr);
232 snprintf(brief, sizeof(temp), "%s", temp);
236 _tbm_util_get_appname_from_pid(long pid, char *str)
238 char fn_cmdline[255] = {0, }, cmdline[255];
242 snprintf(fn_cmdline, sizeof(fn_cmdline), "/proc/%ld/cmdline", pid);
244 fp = fopen(fn_cmdline, "r");
246 TBM_LOG_E("cannot file open %s\n", fn_cmdline);
250 if (!fgets(cmdline, 255, fp)) {
251 TBM_LOG_E("fail to get appname for pid(%ld)\n", pid);
258 len = strlen(cmdline);
260 memset(cmdline, 0x00, 255);
264 snprintf(str, sizeof(cmdline), "%s", cmdline);
269 *user_data_lookup(struct list_head *user_data_list, unsigned long key)
271 tbm_user_data *old_data = NULL;
273 if (LIST_IS_EMPTY(user_data_list))
276 LIST_FOR_EACH_ENTRY(old_data, user_data_list, item_link) {
277 if (old_data->key == key)
285 *user_data_create(unsigned long key, tbm_data_free data_free_func)
287 tbm_user_data *user_data;
289 user_data = calloc(1, sizeof(tbm_user_data));
291 /* LCOV_EXCL_START */
292 TBM_LOG_E("fail to allocate an user_date\n");
297 user_data->key = key;
298 user_data->free_func = data_free_func;
304 user_data_delete(tbm_user_data *user_data)
306 if (user_data->data && user_data->free_func)
307 user_data->free_func(user_data->data);
309 LIST_DEL(&user_data->item_link);
315 _bo_lock(tbm_bo bo, int device, int opt)
317 tbm_bufmgr bufmgr = bo->bufmgr;
320 if (bufmgr->backend->bo_lock)
321 ret = bufmgr->backend->bo_lock(bo, device, opt);
327 _bo_unlock(tbm_bo bo)
329 tbm_bufmgr bufmgr = bo->bufmgr;
331 if (bufmgr->backend->bo_unlock)
332 bufmgr->backend->bo_unlock(bo);
336 _tbm_bo_lock(tbm_bo bo, int device, int opt)
346 /* do not try to lock the bo */
347 if (bufmgr->lock_type == LOCK_TRY_NEVER)
350 if (bo->lock_cnt < 0) {
351 TBM_LOG_E("error bo:%p LOCK_CNT=%d\n",
358 switch (bufmgr->lock_type) {
360 if (bo->lock_cnt == 0) {
361 _tbm_bufmgr_mutex_unlock();
362 ret = _bo_lock(bo, device, opt);
363 _tbm_bufmgr_mutex_lock();
369 case LOCK_TRY_ALWAYS:
370 _tbm_bufmgr_mutex_unlock();
371 ret = _bo_lock(bo, device, opt);
372 _tbm_bufmgr_mutex_lock();
377 TBM_LOG_E("error bo:%p lock_type[%d] is wrong.\n",
378 bo, bufmgr->lock_type);
383 TBM_DBG_LOCK(">> LOCK bo:%p(%d->%d)\n", bo, old, bo->lock_cnt);
389 _tbm_bo_unlock(tbm_bo bo)
399 /* do not try to unlock the bo */
400 if (bufmgr->lock_type == LOCK_TRY_NEVER)
405 switch (bufmgr->lock_type) {
407 if (bo->lock_cnt > 0) {
409 if (bo->lock_cnt == 0)
413 case LOCK_TRY_ALWAYS:
414 if (bo->lock_cnt > 0) {
420 TBM_LOG_E("error bo:%p lock_type[%d] is wrong.\n",
421 bo, bufmgr->lock_type);
425 if (bo->lock_cnt < 0)
428 TBM_DBG_LOCK(">> UNLOCK bo:%p(%d->%d)\n", bo, old, bo->lock_cnt);
432 _tbm_bo_is_valid(tbm_bo bo)
434 tbm_bo old_data = NULL;
436 if (bo == NULL || gBufMgr == NULL) {
437 TBM_LOG_E("error: bo is NULL or tbm_bufmgr was deinited\n");
441 if (LIST_IS_EMPTY(&gBufMgr->bo_list)) {
442 TBM_LOG_E("error: gBufMgr->bo_list is EMPTY.\n");
446 LIST_FOR_EACH_ENTRY(old_data, &gBufMgr->bo_list, item_link) {
451 TBM_LOG_E("error: No valid bo(%p).\n", bo);
456 /* LCOV_EXCL_START */
458 _check_version(TBMModuleVersionInfo *data)
463 abimaj = GET_ABI_MAJOR(data->abiversion);
464 abimin = GET_ABI_MINOR(data->abiversion);
466 TBM_DBG("TBM module %s: vendor=\"%s\" ABI=%d,%d\n",
467 data->modname ? data->modname : "UNKNOWN!",
468 data->vendor ? data->vendor : "UNKNOWN!", abimaj, abimin);
470 vermaj = GET_ABI_MAJOR(TBM_ABI_VERSION);
471 vermin = GET_ABI_MINOR(TBM_ABI_VERSION);
473 TBM_DBG("TBM ABI version %d.%d\n",
476 if (abimaj != vermaj) {
477 TBM_LOG_E("TBM module ABI major ver(%d) doesn't match the TBM's ver(%d)\n",
480 } else if (abimin > vermin) {
481 TBM_LOG_E("TBM module ABI minor ver(%d) is newer than the TBM's ver(%d)\n",
490 _tbm_bufmgr_load_module(tbm_bufmgr bufmgr, int fd, const char *file)
492 char path[PATH_MAX] = {0, };
493 TBMModuleVersionInfo *vers;
494 TBMModuleData *initdata;
498 snprintf(path, sizeof(path), BUFMGR_MODULE_DIR "/%s", file);
500 module_data = dlopen(path, RTLD_LAZY);
502 TBM_LOG_E("failed to load module: %s(%s)\n", dlerror(), file);
506 initdata = dlsym(module_data, "tbmModuleData");
508 TBM_LOG_E("Error: module does not have data object.\n");
512 vers = initdata->vers;
514 TBM_LOG_E("Error: module does not supply version information.\n");
518 init = initdata->init;
520 TBM_LOG_E("Error: module does not supply init symbol.\n");
524 if (!_check_version(vers)) {
525 TBM_LOG_E("Fail to check version.\n");
529 if (!init(bufmgr, fd)) {
530 TBM_LOG_E("Fail to init module(%s)\n", file);
534 if (!bufmgr->backend || !bufmgr->backend->priv) {
535 TBM_LOG_E("Error: module(%s) wrong operation. Check backend or backend's priv.\n", file);
539 bufmgr->module_data = module_data;
541 TBM_DBG("Success to load module(%s)\n", file);
546 dlclose(module_data);
551 _tbm_load_module(tbm_bufmgr bufmgr, int fd)
553 struct dirent **namelist;
556 /* load bufmgr priv from default lib */
557 if (_tbm_bufmgr_load_module(bufmgr, fd, DEFAULT_LIB))
560 /* load bufmgr priv from configured path */
561 n = scandir(BUFMGR_MODULE_DIR, &namelist, 0, alphasort);
563 TBM_LOG_E("no files : %s\n", BUFMGR_MODULE_DIR);
568 if (!ret && strstr(namelist[n]->d_name, PREFIX_LIB)) {
569 const char *p = strstr(namelist[n]->d_name, SUFFIX_LIB);
571 if (p && !strcmp(p, SUFFIX_LIB))
572 ret = _tbm_bufmgr_load_module(bufmgr, fd,
573 namelist[n]->d_name);
586 tbm_bufmgr_init(int fd)
588 #ifdef TBM_BUFMGR_INIT_TIME
589 struct timeval start_tv, end_tv;
593 #ifdef TBM_BUFMGR_INIT_TIME
594 /* get the start tv */
595 gettimeofday(&start_tv, NULL);
598 /* LCOV_EXCL_START */
600 env = getenv("TBM_DLOG");
603 TBM_LOG_D("TBM_DLOG=%s\n", env);
609 env = getenv("TBM_DEBUG");
612 TBM_LOG_D("TBM_DEBUG=%s\n", env);
618 env = getenv("TBM_TRACE");
621 TBM_LOG_D("TBM_TRACE=%s\n", env);
626 pthread_mutex_lock(&gLock);
629 TBM_LOG_W("!!!!!WARNING:: The tbm_bufmgr_init DOSE NOT use argument fd ANYMORE.\n");
630 TBM_LOG_W("!!!!!WARNING:: IT WILL BE CHANGED like tbm_bufmgr_init(int fd) --> tbm_bufmgr_init(void).\n");
634 /* initialize buffer manager */
636 gBufMgr->ref_count++;
637 TBM_TRACE("reuse tbm_bufmgr(%p) ref_count(%d) fd(%d)\n", gBufMgr, gBufMgr->ref_count, gBufMgr->fd);
638 pthread_mutex_unlock(&gLock);
642 TBM_DBG("bufmgr init\n");
644 /* allocate bufmgr */
645 gBufMgr = calloc(1, sizeof(struct _tbm_bufmgr));
647 _tbm_set_last_result(TBM_BO_ERROR_HEAP_ALLOC_FAILED);
648 TBM_TRACE("error: fail to alloc bufmgr fd(%d)\n", fd);
649 pthread_mutex_unlock(&gLock);
655 /* load bufmgr priv from env */
656 if (!_tbm_load_module(gBufMgr, gBufMgr->fd)) {
657 _tbm_set_last_result(TBM_BO_ERROR_LOAD_MODULE_FAILED);
658 TBM_LOG_E("error : Fail to load bufmgr backend\n");
661 pthread_mutex_unlock(&gLock);
667 /* log for tbm backend_flag */
668 TBM_DBG("backend flag:%x:", gBufMgr->backend->flags);
671 gBufMgr->ref_count = 1;
673 TBM_DBG("create tizen bufmgr:%p ref_count:%d\n",
674 gBufMgr, gBufMgr->ref_count);
676 /* setup the lock_type */
677 env = getenv("BUFMGR_LOCK_TYPE");
678 if (env && !strcmp(env, "always"))
679 gBufMgr->lock_type = LOCK_TRY_ALWAYS;
680 else if (env && !strcmp(env, "none"))
681 gBufMgr->lock_type = LOCK_TRY_NEVER;
682 else if (env && !strcmp(env, "once"))
683 gBufMgr->lock_type = LOCK_TRY_ONCE;
685 gBufMgr->lock_type = LOCK_TRY_ALWAYS;
687 TBM_DBG("BUFMGR_LOCK_TYPE=%s\n", env ? env : "default:once");
689 TBM_TRACE("create tbm_bufmgr(%p) ref_count(%d) fd(%d)\n", gBufMgr, gBufMgr->ref_count, fd);
691 /* intialize bo_list */
692 LIST_INITHEAD(&gBufMgr->bo_list);
694 /* intialize surf_list */
695 LIST_INITHEAD(&gBufMgr->surf_list);
697 /* intialize surf_queue_list */
698 LIST_INITHEAD(&gBufMgr->surf_queue_list);
700 /* intialize debug_key_list */
701 LIST_INITHEAD(&gBufMgr->debug_key_list);
703 #ifdef TBM_BUFMGR_INIT_TIME
705 gettimeofday(&end_tv, NULL);
706 TBM_LOG_I("tbm_bufmgr_init time: %ld ms", ((end_tv.tv_sec * 1000 + end_tv.tv_usec / 1000) - (start_tv.tv_sec * 1000 + start_tv.tv_usec / 1000)));
709 pthread_mutex_unlock(&gLock);
715 tbm_bufmgr_deinit(tbm_bufmgr bufmgr)
717 TBM_RETURN_IF_FAIL(TBM_BUFMGR_IS_VALID(bufmgr));
719 pthread_mutex_lock(&gLock);
722 TBM_LOG_E("gBufmgr already destroy: bufmgr:%p\n", bufmgr);
723 pthread_mutex_unlock(&gLock);
728 if (bufmgr->ref_count > 0) {
729 TBM_TRACE("reduce a ref_count(%d) of tbm_bufmgr(%p)\n", bufmgr->ref_count, bufmgr);
730 pthread_mutex_unlock(&gLock);
734 /* destroy bo_list */
735 if (!LIST_IS_EMPTY(&bufmgr->bo_list)) {
736 tbm_bo bo = NULL, tmp;
738 LIST_FOR_EACH_ENTRY_SAFE(bo, tmp, &bufmgr->bo_list, item_link) {
739 TBM_LOG_E("Un-freed bo(%p, ref:%d)\n", bo, bo->ref_cnt);
745 /* destroy surf_list */
746 if (!LIST_IS_EMPTY(&bufmgr->surf_list)) {
747 tbm_surface_h surf = NULL, tmp;
749 LIST_FOR_EACH_ENTRY_SAFE(surf, tmp, &bufmgr->surf_list, item_link) {
750 TBM_LOG_E("Un-freed surf(%p, ref:%d)\n", surf, surf->refcnt);
751 tbm_surface_destroy(surf);
755 /* destroy bufmgr priv */
756 bufmgr->backend->bufmgr_deinit(bufmgr->backend->priv);
757 bufmgr->backend->priv = NULL;
758 tbm_backend_free(bufmgr->backend);
759 bufmgr->backend = NULL;
761 TBM_TRACE("destroy tbm_bufmgr(%p)\n", bufmgr);
763 dlclose(bufmgr->module_data);
771 pthread_mutex_unlock(&gLock);
775 tbm_bo_size(tbm_bo bo)
777 tbm_bufmgr bufmgr = gBufMgr;
780 _tbm_bufmgr_mutex_lock();
782 TBM_BUFMGR_RETURN_VAL_IF_FAIL(TBM_BUFMGR_IS_VALID(gBufMgr), 0);
783 TBM_BUFMGR_RETURN_VAL_IF_FAIL(_tbm_bo_is_valid(bo), 0);
785 size = bufmgr->backend->bo_size(bo);
787 TBM_TRACE("bo(%p) size(%d)\n", bo, size);
789 _tbm_bufmgr_mutex_unlock();
795 tbm_bo_ref(tbm_bo bo)
797 _tbm_bufmgr_mutex_lock();
799 TBM_BUFMGR_RETURN_VAL_IF_FAIL(TBM_BUFMGR_IS_VALID(gBufMgr), NULL);
800 TBM_BUFMGR_RETURN_VAL_IF_FAIL(_tbm_bo_is_valid(bo), NULL);
804 TBM_TRACE("bo(%p) ref_cnt(%d)\n", bo, bo->ref_cnt);
806 _tbm_bufmgr_mutex_unlock();
812 tbm_bo_unref(tbm_bo bo)
814 tbm_bufmgr bufmgr = gBufMgr;
816 _tbm_bufmgr_mutex_lock();
818 TBM_BUFMGR_RETURN_IF_FAIL(gBufMgr);
819 TBM_BUFMGR_RETURN_IF_FAIL(_tbm_bo_is_valid(bo));
821 TBM_TRACE("bo(%p) ref_cnt(%d)\n", bo, bo->ref_cnt - 1);
823 if (bo->ref_cnt <= 0) {
824 _tbm_bufmgr_mutex_unlock();
829 if (bo->ref_cnt == 0) {
830 /* destory the user_data_list */
831 if (!LIST_IS_EMPTY(&bo->user_data_list)) {
832 tbm_user_data *old_data = NULL, *tmp;
834 LIST_FOR_EACH_ENTRY_SAFE(old_data, tmp,
835 &bo->user_data_list, item_link) {
836 TBM_DBG("free user_data\n");
837 user_data_delete(old_data);
841 while (bo->lock_cnt > 0) {
842 TBM_LOG_E("error lock_cnt:%d\n", bo->lock_cnt);
847 /* call the bo_free */
848 bufmgr->backend->bo_free(bo);
851 LIST_DEL(&bo->item_link);
857 _tbm_bufmgr_mutex_unlock();
861 tbm_bo_alloc(tbm_bufmgr bufmgr, int size, int flags)
866 _tbm_bufmgr_mutex_lock();
868 TBM_BUFMGR_RETURN_VAL_IF_FAIL(TBM_BUFMGR_IS_VALID(bufmgr), NULL);
869 TBM_BUFMGR_RETURN_VAL_IF_FAIL(bufmgr == gBufMgr, NULL);
870 TBM_BUFMGR_RETURN_VAL_IF_FAIL(size > 0, NULL);
872 bo = calloc(1, sizeof(struct _tbm_bo));
874 /* LCOV_EXCL_START */
875 TBM_LOG_E("error: fail to create of tbm_bo size(%d) flag(%s)\n",
876 size, _tbm_flag_to_str(flags));
877 _tbm_set_last_result(TBM_BO_ERROR_HEAP_ALLOC_FAILED);
878 _tbm_bufmgr_mutex_unlock();
883 _tbm_util_check_bo_cnt(bufmgr);
887 bo_priv = bufmgr->backend->bo_alloc(bo, size, flags);
889 /* LCOV_EXCL_START */
890 TBM_LOG_E("error: fail to create of tbm_bo size(%d) flag(%s)\n",
891 size, _tbm_flag_to_str(flags));
892 _tbm_set_last_result(TBM_BO_ERROR_BO_ALLOC_FAILED);
894 _tbm_bufmgr_mutex_unlock();
905 TBM_TRACE("bo(%p) size(%d) refcnt(%d), flag(%s)\n", bo, size, bo->ref_cnt,
906 _tbm_flag_to_str(bo->flags));
908 LIST_INITHEAD(&bo->user_data_list);
910 LIST_ADD(&bo->item_link, &bufmgr->bo_list);
912 _tbm_bufmgr_mutex_unlock();
918 tbm_bo_import(tbm_bufmgr bufmgr, unsigned int key)
923 _tbm_bufmgr_mutex_lock();
925 TBM_BUFMGR_RETURN_VAL_IF_FAIL(TBM_BUFMGR_IS_VALID(bufmgr), NULL);
926 TBM_BUFMGR_RETURN_VAL_IF_FAIL(bufmgr == gBufMgr, NULL);
928 if (!bufmgr->backend->bo_import) {
929 /* LCOV_EXCL_START */
930 _tbm_bufmgr_mutex_unlock();
935 _tbm_util_check_bo_cnt(bufmgr);
937 bo = calloc(1, sizeof(struct _tbm_bo));
939 /* LCOV_EXCL_START */
940 TBM_LOG_E("error: fail to import of tbm_bo by key(%d)\n", key);
941 _tbm_bufmgr_mutex_unlock();
948 bo_priv = bufmgr->backend->bo_import(bo, key);
950 /* LCOV_EXCL_START */
951 TBM_LOG_E("error: fail to import of tbm_bo by key(%d)\n", key);
952 _tbm_set_last_result(TBM_BO_ERROR_IMPORT_FAILED);
954 _tbm_bufmgr_mutex_unlock();
959 if (!LIST_IS_EMPTY(&bufmgr->bo_list)) {
962 LIST_FOR_EACH_ENTRY(bo2, &bufmgr->bo_list, item_link) {
963 if (bo2->priv == bo_priv) {
964 TBM_TRACE("find bo(%p) ref(%d) key(%d) flag(%s) in list\n",
965 bo2, bo2->ref_cnt, key,
966 _tbm_flag_to_str(bo2->flags));
969 _tbm_bufmgr_mutex_unlock();
980 if (bufmgr->backend->bo_get_flags)
981 bo->flags = bufmgr->backend->bo_get_flags(bo);
983 bo->flags = TBM_BO_DEFAULT;
985 TBM_TRACE("import new bo(%p) ref(%d) key(%d) flag(%s) in list\n",
986 bo, bo->ref_cnt, key, _tbm_flag_to_str(bo->flags));
988 LIST_INITHEAD(&bo->user_data_list);
990 LIST_ADD(&bo->item_link, &bufmgr->bo_list);
992 _tbm_bufmgr_mutex_unlock();
998 tbm_bo_import_fd(tbm_bufmgr bufmgr, tbm_fd fd)
1003 _tbm_bufmgr_mutex_lock();
1005 TBM_BUFMGR_RETURN_VAL_IF_FAIL(TBM_BUFMGR_IS_VALID(bufmgr), NULL);
1006 TBM_BUFMGR_RETURN_VAL_IF_FAIL(bufmgr == gBufMgr, NULL);
1008 if (!bufmgr->backend->bo_import_fd) {
1009 /* LCOV_EXCL_START */
1010 _tbm_bufmgr_mutex_unlock();
1012 /* LCOV_EXCL_STOP */
1015 _tbm_util_check_bo_cnt(bufmgr);
1017 bo = calloc(1, sizeof(struct _tbm_bo));
1019 /* LCOV_EXCL_START */
1020 TBM_LOG_E("error: fail to import tbm_bo by tbm_fd(%d)\n", fd);
1021 _tbm_bufmgr_mutex_unlock();
1023 /* LCOV_EXCL_STOP */
1026 bo->bufmgr = bufmgr;
1028 bo_priv = bufmgr->backend->bo_import_fd(bo, fd);
1030 /* LCOV_EXCL_START */
1031 TBM_LOG_E("error: fail to import tbm_bo by tbm_fd(%d)\n", fd);
1032 _tbm_set_last_result(TBM_BO_ERROR_IMPORT_FD_FAILED);
1034 _tbm_bufmgr_mutex_unlock();
1036 /* LCOV_EXCL_STOP */
1039 if (!LIST_IS_EMPTY(&bufmgr->bo_list)) {
1042 LIST_FOR_EACH_ENTRY(bo2, &bufmgr->bo_list, item_link) {
1043 if (bo2->priv == bo_priv) {
1044 TBM_TRACE("find bo(%p) ref(%d) fd(%d) flag(%s) in list\n",
1045 bo2, bo2->ref_cnt, fd,
1046 _tbm_flag_to_str(bo2->flags));
1049 _tbm_bufmgr_mutex_unlock();
1060 if (bufmgr->backend->bo_get_flags)
1061 bo->flags = bufmgr->backend->bo_get_flags(bo);
1063 bo->flags = TBM_BO_DEFAULT;
1065 TBM_TRACE("import bo(%p) ref(%d) fd(%d) flag(%s)\n",
1066 bo, bo->ref_cnt, fd, _tbm_flag_to_str(bo->flags));
1068 LIST_INITHEAD(&bo->user_data_list);
1070 LIST_ADD(&bo->item_link, &bufmgr->bo_list);
1072 _tbm_bufmgr_mutex_unlock();
1078 tbm_bo_export(tbm_bo bo)
1080 tbm_bufmgr bufmgr = gBufMgr;
1083 _tbm_bufmgr_mutex_lock();
1085 TBM_BUFMGR_RETURN_VAL_IF_FAIL(TBM_BUFMGR_IS_VALID(gBufMgr), 0);
1086 TBM_BUFMGR_RETURN_VAL_IF_FAIL(_tbm_bo_is_valid(bo), 0);
1088 if (!bufmgr->backend->bo_export) {
1089 /* LCOV_EXCL_START */
1090 _tbm_bufmgr_mutex_unlock();
1092 /* LCOV_EXCL_STOP */
1095 ret = bufmgr->backend->bo_export(bo);
1097 /* LCOV_EXCL_START */
1098 _tbm_set_last_result(TBM_BO_ERROR_EXPORT_FAILED);
1099 TBM_LOG_E("error: bo(%p) tbm_key(%d)\n", bo, ret);
1100 _tbm_bufmgr_mutex_unlock();
1102 /* LCOV_EXCL_STOP */
1105 TBM_TRACE("bo(%p) tbm_key(%u)\n", bo, ret);
1107 _tbm_bufmgr_mutex_unlock();
1113 tbm_bo_export_fd(tbm_bo bo)
1115 tbm_bufmgr bufmgr = gBufMgr;
1118 _tbm_bufmgr_mutex_lock();
1120 TBM_BUFMGR_RETURN_VAL_IF_FAIL(TBM_BUFMGR_IS_VALID(gBufMgr), -1);
1121 TBM_BUFMGR_RETURN_VAL_IF_FAIL(_tbm_bo_is_valid(bo), -1);
1123 if (!bufmgr->backend->bo_export_fd) {
1124 /* LCOV_EXCL_START */
1125 _tbm_bufmgr_mutex_unlock();
1127 /* LCOV_EXCL_STOP */
1130 ret = bufmgr->backend->bo_export_fd(bo);
1132 /* LCOV_EXCL_START */
1133 _tbm_set_last_result(TBM_BO_ERROR_EXPORT_FD_FAILED);
1134 TBM_LOG_E("error: bo(%p) tbm_fd(%d)\n", bo, ret);
1135 _tbm_bufmgr_mutex_unlock();
1137 /* LCOV_EXCL_STOP */
1140 TBM_TRACE("bo(%p) tbm_fd(%d)\n", bo, ret);
1142 _tbm_bufmgr_mutex_unlock();
1148 tbm_bo_get_handle(tbm_bo bo, int device)
1150 tbm_bufmgr bufmgr = gBufMgr;
1151 tbm_bo_handle bo_handle;
1153 _tbm_bufmgr_mutex_lock();
1155 TBM_BUFMGR_RETURN_VAL_IF_FAIL(TBM_BUFMGR_IS_VALID(gBufMgr), (tbm_bo_handle) NULL);
1156 TBM_BUFMGR_RETURN_VAL_IF_FAIL(_tbm_bo_is_valid(bo), (tbm_bo_handle) NULL);
1158 bo_handle = bufmgr->backend->bo_get_handle(bo, device);
1159 if (bo_handle.ptr == NULL) {
1160 /* LCOV_EXCL_START */
1161 _tbm_set_last_result(TBM_BO_ERROR_GET_HANDLE_FAILED);
1162 TBM_LOG_E("error: bo(%p) bo_handle(%p)\n", bo, bo_handle.ptr);
1163 _tbm_bufmgr_mutex_unlock();
1164 return (tbm_bo_handle) NULL;
1165 /* LCOV_EXCL_STOP */
1168 TBM_TRACE("bo(%p) bo_handle(%p)\n", bo, bo_handle.ptr);
1170 _tbm_bufmgr_mutex_unlock();
1176 tbm_bo_map(tbm_bo bo, int device, int opt)
1178 tbm_bufmgr bufmgr = gBufMgr;
1179 tbm_bo_handle bo_handle;
1181 _tbm_bufmgr_mutex_lock();
1183 TBM_BUFMGR_RETURN_VAL_IF_FAIL(TBM_BUFMGR_IS_VALID(gBufMgr), (tbm_bo_handle) NULL);
1184 TBM_BUFMGR_RETURN_VAL_IF_FAIL(_tbm_bo_is_valid(bo), (tbm_bo_handle) NULL);
1186 if (!_tbm_bo_lock(bo, device, opt)) {
1187 _tbm_set_last_result(TBM_BO_ERROR_LOCK_FAILED);
1188 TBM_LOG_E("error: fail to lock bo:%p)\n", bo);
1189 _tbm_bufmgr_mutex_unlock();
1190 return (tbm_bo_handle) NULL;
1193 bo_handle = bufmgr->backend->bo_map(bo, device, opt);
1194 if (bo_handle.ptr == NULL) {
1195 /* LCOV_EXCL_START */
1196 _tbm_set_last_result(TBM_BO_ERROR_MAP_FAILED);
1197 TBM_LOG_E("error: fail to map bo:%p\n", bo);
1199 _tbm_bufmgr_mutex_unlock();
1200 return (tbm_bo_handle) NULL;
1201 /* LCOV_EXCL_STOP */
1204 /* increase the map_count */
1207 TBM_TRACE("bo(%p) map_cnt(%d)\n", bo, bo->map_cnt);
1209 _tbm_bufmgr_mutex_unlock();
1215 tbm_bo_unmap(tbm_bo bo)
1217 tbm_bufmgr bufmgr = gBufMgr;
1220 _tbm_bufmgr_mutex_lock();
1222 TBM_BUFMGR_RETURN_VAL_IF_FAIL(TBM_BUFMGR_IS_VALID(gBufMgr), 0);
1223 TBM_BUFMGR_RETURN_VAL_IF_FAIL(_tbm_bo_is_valid(bo), 0);
1225 ret = bufmgr->backend->bo_unmap(bo);
1227 /* LCOV_EXCL_START */
1228 TBM_LOG_E("error: bo(%p) map_cnt(%d)\n", bo, bo->map_cnt);
1229 _tbm_set_last_result(TBM_BO_ERROR_UNMAP_FAILED);
1230 _tbm_bufmgr_mutex_unlock();
1232 /* LCOV_EXCL_STOP */
1235 /* decrease the map_count */
1238 TBM_TRACE("bo(%p) map_cnt(%d)\n", bo, bo->map_cnt);
1242 _tbm_bufmgr_mutex_unlock();
1248 tbm_bo_swap(tbm_bo bo1, tbm_bo bo2)
1250 tbm_bufmgr bufmgr = gBufMgr;
1253 _tbm_bufmgr_mutex_lock();
1255 TBM_BUFMGR_RETURN_VAL_IF_FAIL(TBM_BUFMGR_IS_VALID(gBufMgr), 0);
1256 TBM_BUFMGR_RETURN_VAL_IF_FAIL(_tbm_bo_is_valid(bo1), 0);
1257 TBM_BUFMGR_RETURN_VAL_IF_FAIL(_tbm_bo_is_valid(bo2), 0);
1259 TBM_TRACE("before: bo1(%p) bo2(%p)\n", bo1, bo2);
1261 if (bufmgr->backend->bo_size(bo1) != bufmgr->backend->bo_size(bo2)) {
1262 _tbm_set_last_result(TBM_BO_ERROR_SWAP_FAILED);
1263 TBM_LOG_E("error: bo1(%p) bo2(%p)\n", bo1, bo2);
1264 _tbm_bufmgr_mutex_unlock();
1268 TBM_TRACE("after: bo1(%p) bo2(%p)\n", bo1, bo2);
1271 bo1->priv = bo2->priv;
1274 _tbm_bufmgr_mutex_unlock();
1280 tbm_bo_locked(tbm_bo bo)
1282 tbm_bufmgr bufmgr = gBufMgr;
1284 _tbm_bufmgr_mutex_lock();
1286 TBM_BUFMGR_RETURN_VAL_IF_FAIL(TBM_BUFMGR_IS_VALID(gBufMgr), 0);
1287 TBM_BUFMGR_RETURN_VAL_IF_FAIL(_tbm_bo_is_valid(bo), 0);
1289 if (bufmgr->lock_type == LOCK_TRY_NEVER) {
1290 TBM_LOG_E("bo(%p) lock_cnt(%d)\n", bo, bo->lock_cnt);
1291 _tbm_bufmgr_mutex_unlock();
1295 if (bo->lock_cnt > 0) {
1296 TBM_TRACE("error: bo(%p) lock_cnt(%d)\n", bo, bo->lock_cnt);
1297 _tbm_bufmgr_mutex_unlock();
1301 TBM_TRACE("bo(%p) lock_cnt(%d)\n", bo, bo->lock_cnt);
1302 _tbm_bufmgr_mutex_unlock();
1308 tbm_bo_add_user_data(tbm_bo bo, unsigned long key,
1309 tbm_data_free data_free_func)
1311 tbm_user_data *data;
1313 _tbm_bufmgr_mutex_lock();
1315 TBM_BUFMGR_RETURN_VAL_IF_FAIL(TBM_BUFMGR_IS_VALID(gBufMgr), 0);
1316 TBM_BUFMGR_RETURN_VAL_IF_FAIL(_tbm_bo_is_valid(bo), 0);
1318 /* check if the data according to the key exist if so, return false. */
1319 data = user_data_lookup(&bo->user_data_list, key);
1321 TBM_TRACE("warning: user data already exist key(%ld)\n", key);
1322 _tbm_bufmgr_mutex_unlock();
1326 data = user_data_create(key, data_free_func);
1328 TBM_LOG_E("error: bo(%p) key(%lu)\n", bo, key);
1329 _tbm_bufmgr_mutex_unlock();
1333 TBM_TRACE("bo(%p) key(%lu) data(%p)\n", bo, key, data->data);
1335 LIST_ADD(&data->item_link, &bo->user_data_list);
1337 _tbm_bufmgr_mutex_unlock();
1343 tbm_bo_set_user_data(tbm_bo bo, unsigned long key, void *data)
1345 tbm_user_data *old_data;
1347 _tbm_bufmgr_mutex_lock();
1349 TBM_BUFMGR_RETURN_VAL_IF_FAIL(TBM_BUFMGR_IS_VALID(gBufMgr), 0);
1350 TBM_BUFMGR_RETURN_VAL_IF_FAIL(_tbm_bo_is_valid(bo), 0);
1352 if (LIST_IS_EMPTY(&bo->user_data_list)) {
1353 TBM_TRACE("error: bo(%p) key(%lu)\n", bo, key);
1354 _tbm_bufmgr_mutex_unlock();
1358 old_data = user_data_lookup(&bo->user_data_list, key);
1360 TBM_TRACE("error: bo(%p) key(%lu)\n", bo, key);
1361 _tbm_bufmgr_mutex_unlock();
1365 if (old_data->data && old_data->free_func)
1366 old_data->free_func(old_data->data);
1367 old_data->data = data;
1369 TBM_TRACE("bo(%p) key(%lu) data(%p)\n", bo, key, old_data->data);
1371 _tbm_bufmgr_mutex_unlock();
1377 tbm_bo_get_user_data(tbm_bo bo, unsigned long key, void **data)
1379 tbm_user_data *old_data;
1381 _tbm_bufmgr_mutex_lock();
1383 TBM_BUFMGR_RETURN_VAL_IF_FAIL(TBM_BUFMGR_IS_VALID(gBufMgr), 0);
1384 TBM_BUFMGR_RETURN_VAL_IF_FAIL(_tbm_bo_is_valid(bo), 0);
1386 if (!data || LIST_IS_EMPTY(&bo->user_data_list)) {
1387 TBM_TRACE("error: bo(%p) key(%lu)\n", bo, key);
1388 _tbm_bufmgr_mutex_unlock();
1392 old_data = user_data_lookup(&bo->user_data_list, key);
1394 TBM_TRACE("error: bo(%p) key(%lu)\n", bo, key);
1396 _tbm_bufmgr_mutex_unlock();
1400 *data = old_data->data;
1402 TBM_TRACE("bo(%p) key(%lu) data(%p)\n", bo, key, old_data->data);
1404 _tbm_bufmgr_mutex_unlock();
1410 tbm_bo_delete_user_data(tbm_bo bo, unsigned long key)
1412 tbm_user_data *old_data;
1414 _tbm_bufmgr_mutex_lock();
1416 TBM_BUFMGR_RETURN_VAL_IF_FAIL(TBM_BUFMGR_IS_VALID(gBufMgr), 0);
1417 TBM_BUFMGR_RETURN_VAL_IF_FAIL(_tbm_bo_is_valid(bo), 0);
1419 if (LIST_IS_EMPTY(&bo->user_data_list)) {
1420 TBM_TRACE("error: bo(%p) key(%lu)\n", bo, key);
1421 _tbm_bufmgr_mutex_unlock();
1425 old_data = user_data_lookup(&bo->user_data_list, key);
1427 TBM_TRACE("error: bo(%p) key(%lu)\n", bo, key);
1428 _tbm_bufmgr_mutex_unlock();
1432 TBM_TRACE("bo(%p) key(%lu) data(%p)\n", bo, key, old_data->data);
1434 user_data_delete(old_data);
1436 _tbm_bufmgr_mutex_unlock();
1442 tbm_bufmgr_get_capability(tbm_bufmgr bufmgr)
1444 unsigned int capabilities = TBM_BUFMGR_CAPABILITY_NONE;
1446 _tbm_bufmgr_mutex_lock();
1448 TBM_BUFMGR_RETURN_VAL_IF_FAIL(TBM_BUFMGR_IS_VALID(bufmgr), TBM_BUFMGR_CAPABILITY_NONE);
1449 TBM_BUFMGR_RETURN_VAL_IF_FAIL(bufmgr == gBufMgr, TBM_BUFMGR_CAPABILITY_NONE);
1451 TBM_TRACE("tbm_bufmgr(%p) capability(%u)\n", bufmgr, bufmgr->capabilities);
1453 capabilities = bufmgr->capabilities;
1455 _tbm_bufmgr_mutex_unlock();
1457 return capabilities;
1461 tbm_bo_get_flags(tbm_bo bo)
1465 _tbm_bufmgr_mutex_lock();
1467 TBM_BUFMGR_RETURN_VAL_IF_FAIL(TBM_BUFMGR_IS_VALID(gBufMgr), 0);
1468 TBM_BUFMGR_RETURN_VAL_IF_FAIL(_tbm_bo_is_valid(bo), 0);
1472 TBM_TRACE("bo(%p)\n", bo);
1474 _tbm_bufmgr_mutex_unlock();
1479 /* LCOV_EXCL_START */
1481 tbm_get_last_error(void)
1483 return tbm_last_error;
1487 tbm_bufmgr_debug_tbm_info_get(tbm_bufmgr bufmgr, char *str, int *len)
1489 char app_name[255] = {0,}, title[512] = {0,};
1490 tbm_surface_debug_data *debug_old_data = NULL;
1492 pthread_mutex_lock(&gLock);
1494 if (!TBM_BUFMGR_IS_VALID(bufmgr) || (bufmgr != gBufMgr)) {
1495 TBM_LOG_E("invalid bufmgr\n");
1496 pthread_mutex_unlock(&gLock);
1500 TBM_SNPRINTF(str, len, "\n");
1501 _tbm_util_get_appname_from_pid(getpid(), app_name);
1502 _tbm_util_get_appname_brief(app_name);
1503 TBM_SNPRINTF(str, len, "============TBM DEBUG: %s(%d)===========================\n",
1504 app_name, getpid());
1506 snprintf(title, 255, "%s", "no surface refcnt width height bpp size n_b n_p flags format app_name ");
1508 if (!LIST_IS_EMPTY(&bufmgr->debug_key_list)) {
1509 LIST_FOR_EACH_ENTRY(debug_old_data, &bufmgr->debug_key_list, item_link) {
1510 strncat(title, " ", 3);
1511 strncat(title, debug_old_data->key, strlen(debug_old_data->key) + 1);
1515 TBM_SNPRINTF(str, len, "[tbm_surface information]\n");
1516 TBM_SNPRINTF(str, len, "%s\n", title);
1518 /* show the tbm_surface information in surf_list */
1519 if (!LIST_IS_EMPTY(&bufmgr->surf_list)) {
1520 tbm_surface_h surf = NULL;
1523 LIST_FOR_EACH_ENTRY(surf, &bufmgr->surf_list, item_link) {
1524 char data[512] = {0,};
1528 pid = _tbm_surface_internal_get_debug_pid(surf);
1530 /* if pid is null, set the self_pid */
1534 memset(app_name, 0x0, 255 * sizeof(char));
1535 _tbm_util_get_appname_from_pid(pid, app_name);
1536 _tbm_util_get_appname_brief(app_name);
1538 snprintf(data, 255, "%-2d %-9p %-4d %-5u %-6u %-3u %-6u %-2d %-2d %-3d %-8s %-15s",
1545 surf->info.size / 1024,
1549 _tbm_surface_internal_format_to_str(surf->info.format) + 11,
1552 if (!LIST_IS_EMPTY(&bufmgr->debug_key_list)) {
1553 LIST_FOR_EACH_ENTRY(debug_old_data, &bufmgr->debug_key_list, item_link) {
1556 strncat(data, " ", 3);
1558 value = _tbm_surface_internal_get_debug_data(surf, debug_old_data->key);
1560 strncat(data, value, strlen(value) + 1);
1562 strncat(data, "none", 5);
1565 TBM_SNPRINTF(str, len, "%s\n", data);
1567 for (i = 0; i < surf->num_bos; i++) {
1568 TBM_SNPRINTF(str, len, " bo:%-12p %-26d%-10d\n",
1570 surf->bos[i]->ref_cnt,
1571 bufmgr->backend->bo_size(surf->bos[i]) / 1024);
1575 TBM_SNPRINTF(str, len, " no tbm_surfaces.\n");
1576 TBM_SNPRINTF(str, len, "\n");
1578 TBM_SNPRINTF(str, len, "[tbm_bo information]\n");
1579 TBM_SNPRINTF(str, len, "no bo refcnt size lock_cnt map_cnt flags surface\n");
1581 /* show the tbm_bo information in bo_list */
1582 if (!LIST_IS_EMPTY(&bufmgr->bo_list)) {
1586 LIST_FOR_EACH_ENTRY(bo, &bufmgr->bo_list, item_link) {
1587 TBM_SNPRINTF(str, len, "%-4d%-11p %-4d %-6d %-5d %-4u %-3d %-11p\n",
1591 bufmgr->backend->bo_size(bo) / 1024,
1598 TBM_SNPRINTF(str, len, "no tbm_bos.\n");
1599 TBM_SNPRINTF(str, len, "\n");
1601 TBM_SNPRINTF(str, len, "===============================================================\n");
1603 pthread_mutex_unlock(&gLock);
1607 tbm_bufmgr_debug_show(tbm_bufmgr bufmgr)
1610 int len = sizeof(str);
1611 tbm_bufmgr_debug_tbm_info_get(bufmgr, str, &len);
1612 TBM_DEBUG(" %s", str);
1616 tbm_bufmgr_debug_trace(tbm_bufmgr bufmgr, int onoff)
1618 _tbm_bufmgr_mutex_lock();
1620 TBM_BUFMGR_RETURN_IF_FAIL(TBM_BUFMGR_IS_VALID(bufmgr));
1621 TBM_BUFMGR_RETURN_IF_FAIL(bufmgr == gBufMgr);
1624 TBM_LOG_D("bufmgr=%p onoff=%d\n", bufmgr, onoff);
1628 _tbm_bufmgr_mutex_unlock();
1632 tbm_bufmgr_debug_dump_set_scale(double scale)
1634 pthread_mutex_lock(&gLock);
1635 scale_factor = scale;
1636 pthread_mutex_unlock(&gLock);
1640 tbm_bufmgr_debug_queue_dump(char *path, int count, int onoff)
1642 pthread_mutex_lock(&gLock);
1645 TBM_LOG_D("count=%d onoff=%d\n", count, onoff);
1647 tbm_surface_internal_dump_end();
1652 TBM_LOG_E("path is null");
1653 pthread_mutex_unlock(&gLock);
1656 TBM_LOG_D("path=%s count=%d onoff=%d\n", path, count, onoff);
1658 if (_tbm_util_get_max_surface_size(&w, &h) == 0) {
1659 TBM_LOG_E("Fail to get tbm_surface size.\n");
1660 pthread_mutex_unlock(&gLock);
1664 tbm_surface_internal_dump_with_scale_start(path, w, h, count, scale_factor);
1670 pthread_mutex_unlock(&gLock);
1675 tbm_bufmgr_debug_dump_all(char *path)
1677 int w, h, count = 0;
1678 tbm_surface_h surface = NULL;
1680 TBM_RETURN_VAL_IF_FAIL(path != NULL, 0);
1681 TBM_LOG_D("path=%s\n", path);
1683 pthread_mutex_lock(&gLock);
1685 count = _tbm_util_get_max_surface_size(&w, &h);
1687 TBM_LOG_E("No tbm_surface.\n");
1688 pthread_mutex_unlock(&gLock);
1692 tbm_surface_internal_dump_with_scale_start(path, w, h, count, scale_factor);
1695 LIST_FOR_EACH_ENTRY(surface, &gBufMgr->surf_list, item_link)
1696 tbm_surface_internal_dump_buffer(surface, "dump_all");
1698 tbm_surface_internal_dump_end();
1700 pthread_mutex_unlock(&gLock);
1705 /* internal function */
1707 _tbm_bufmgr_get_bufmgr(void)
1713 _tbm_bo_set_surface(tbm_bo bo, tbm_surface_h surface)
1715 _tbm_bufmgr_mutex_lock();
1717 TBM_BUFMGR_RETURN_VAL_IF_FAIL(TBM_BUFMGR_IS_VALID(gBufMgr), 0);
1718 TBM_BUFMGR_RETURN_VAL_IF_FAIL(_tbm_bo_is_valid(bo), 0);
1720 bo->surface = surface;
1722 _tbm_bufmgr_mutex_unlock();
1728 tbm_bufmgr_bind_native_display(tbm_bufmgr bufmgr, void *NativeDisplay)
1732 _tbm_bufmgr_mutex_lock();
1734 TBM_BUFMGR_RETURN_VAL_IF_FAIL(TBM_BUFMGR_IS_VALID(gBufMgr), 0);
1736 if (!bufmgr->backend->bufmgr_bind_native_display) {
1737 TBM_TRACE("skip: tbm_bufmgr(%p) NativeDisplay(%p)\n",
1738 bufmgr, NativeDisplay);
1739 _tbm_bufmgr_mutex_unlock();
1743 ret = bufmgr->backend->bufmgr_bind_native_display(bufmgr, NativeDisplay);
1745 TBM_LOG_E("error: tbm_bufmgr(%p) NativeDisplay(%p)\n",
1746 bufmgr, NativeDisplay);
1747 _tbm_bufmgr_mutex_unlock();
1751 TBM_TRACE("tbm_bufmgr(%p) NativeDisplay(%p)\n", bufmgr, NativeDisplay);
1753 _tbm_bufmgr_mutex_unlock();
1758 int tbm_bufmgr_get_fd_limit(void)
1762 if (getrlimit(RLIMIT_NOFILE, &lim))
1765 return (int)lim.rlim_cur;
1767 /* LCOV_EXCL_STOP */