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)
80 #define MAX_SIZE_N(dest) (sizeof(dest) - strlen(dest) - 1)
83 #define TBM_BUFMGR_RETURN_IF_FAIL(cond) {\
85 TBM_LOG_E("'%s' failed.\n", #cond);\
86 _tbm_bufmgr_mutex_unlock();\
91 #define TBM_BUFMGR_RETURN_VAL_IF_FAIL(cond, val) {\
93 TBM_LOG_E("'%s' failed.\n", #cond);\
94 _tbm_bufmgr_mutex_unlock();\
106 _tbm_set_last_result(tbm_error_e err)
108 tbm_last_error = err;
111 /* LCOV_EXCL_START */
113 _tbm_bufmgr_mutex_init(void)
115 static bool tbm_bufmgr_mutex_init = false;
117 if (tbm_bufmgr_mutex_init)
120 if (pthread_mutex_init(&tbm_bufmgr_lock, NULL)) {
121 TBM_LOG_E("fail: Cannot pthread_mutex_init for tbm_bufmgr_lock.\n");
125 tbm_bufmgr_mutex_init = true;
131 _tbm_bufmgr_mutex_lock(void)
133 if (!_tbm_bufmgr_mutex_init()) {
134 TBM_LOG_E("fail: _tbm_bufmgr_mutex_init()\n");
138 pthread_mutex_lock(&tbm_bufmgr_lock);
142 _tbm_bufmgr_mutex_unlock(void)
144 pthread_mutex_unlock(&tbm_bufmgr_lock);
148 _tbm_flag_to_str(int f)
150 static char str[255];
152 if (f == TBM_BO_DEFAULT)
153 snprintf(str, 255, "DEFAULT");
157 if (f & TBM_BO_SCANOUT)
158 c = snprintf(&str[c], 255, "SCANOUT");
160 if (f & TBM_BO_NONCACHABLE) {
162 c = snprintf(&str[c], 255, ", ");
163 c = snprintf(&str[c], 255, "NONCACHABLE,");
168 c = snprintf(&str[c], 255, ", ");
169 c = snprintf(&str[c], 255, "WC");
177 _tbm_util_check_bo_cnt(tbm_bufmgr bufmgr)
179 static int last_chk_bo_cnt = 0;
181 if ((bufmgr->bo_cnt >= 500) && ((bufmgr->bo_cnt % 20) == 0) &&
182 (bufmgr->bo_cnt > last_chk_bo_cnt)) {
183 TBM_DEBUG("============TBM BO CNT DEBUG: bo_cnt=%d\n",
186 tbm_bufmgr_debug_show(bufmgr);
188 last_chk_bo_cnt = bufmgr->bo_cnt;
193 _tbm_util_get_max_surface_size(int *w, int *h)
195 tbm_surface_info_s info;
196 tbm_surface_h surface = NULL;
202 if (gBufMgr == NULL || LIST_IS_EMPTY(&gBufMgr->surf_list))
205 LIST_FOR_EACH_ENTRY(surface, &gBufMgr->surf_list, item_link) {
206 if (tbm_surface_get_info(surface, &info) == TBM_SURFACE_ERROR_NONE) {
210 if (*h < info.height)
219 _tbm_util_get_appname_brief(char *brief)
223 char temp[255] = {0,};
224 char *saveptr = NULL;
226 token = strtok_r(brief, delim, &saveptr);
228 while (token != NULL) {
229 memset(temp, 0x00, 255 * sizeof(char));
230 strncpy(temp, token, 254 * sizeof(char));
231 token = strtok_r(NULL, delim, &saveptr);
234 snprintf(brief, sizeof(temp), "%s", temp);
238 _tbm_util_get_appname_from_pid(long pid, char *str)
240 char fn_cmdline[255] = {0, }, cmdline[255];
244 snprintf(fn_cmdline, sizeof(fn_cmdline), "/proc/%ld/cmdline", pid);
246 fp = fopen(fn_cmdline, "r");
248 TBM_LOG_E("cannot file open %s\n", fn_cmdline);
252 if (!fgets(cmdline, 255, fp)) {
253 TBM_LOG_E("fail to get appname for pid(%ld)\n", pid);
260 len = strlen(cmdline);
262 memset(cmdline, 0x00, 255);
266 snprintf(str, sizeof(cmdline), "%s", cmdline);
271 *user_data_lookup(struct list_head *user_data_list, unsigned long key)
273 tbm_user_data *old_data = NULL;
275 if (LIST_IS_EMPTY(user_data_list))
278 LIST_FOR_EACH_ENTRY(old_data, user_data_list, item_link) {
279 if (old_data->key == key)
287 *user_data_create(unsigned long key, tbm_data_free data_free_func)
289 tbm_user_data *user_data;
291 user_data = calloc(1, sizeof(tbm_user_data));
293 /* LCOV_EXCL_START */
294 TBM_LOG_E("fail to allocate an user_date\n");
299 user_data->key = key;
300 user_data->free_func = data_free_func;
306 user_data_delete(tbm_user_data *user_data)
308 if (user_data->data && user_data->free_func)
309 user_data->free_func(user_data->data);
311 LIST_DEL(&user_data->item_link);
317 _bo_lock(tbm_bo bo, int device, int opt)
319 tbm_bufmgr bufmgr = bo->bufmgr;
322 if (bufmgr->backend->bo_lock)
323 ret = bufmgr->backend->bo_lock(bo, device, opt);
329 _bo_unlock(tbm_bo bo)
331 tbm_bufmgr bufmgr = bo->bufmgr;
333 if (bufmgr->backend->bo_unlock)
334 bufmgr->backend->bo_unlock(bo);
338 _tbm_bo_lock(tbm_bo bo, int device, int opt)
348 /* do not try to lock the bo */
349 if (bufmgr->lock_type == LOCK_TRY_NEVER)
352 if (bo->lock_cnt < 0) {
353 TBM_LOG_E("error bo:%p LOCK_CNT=%d\n",
360 switch (bufmgr->lock_type) {
362 if (bo->lock_cnt == 0) {
363 _tbm_bufmgr_mutex_unlock();
364 ret = _bo_lock(bo, device, opt);
365 _tbm_bufmgr_mutex_lock();
371 case LOCK_TRY_ALWAYS:
372 _tbm_bufmgr_mutex_unlock();
373 ret = _bo_lock(bo, device, opt);
374 _tbm_bufmgr_mutex_lock();
379 TBM_LOG_E("error bo:%p lock_type[%d] is wrong.\n",
380 bo, bufmgr->lock_type);
385 TBM_DBG_LOCK(">> LOCK bo:%p(%d->%d)\n", bo, old, bo->lock_cnt);
391 _tbm_bo_unlock(tbm_bo bo)
401 /* do not try to unlock the bo */
402 if (bufmgr->lock_type == LOCK_TRY_NEVER)
407 switch (bufmgr->lock_type) {
409 if (bo->lock_cnt > 0) {
411 if (bo->lock_cnt == 0)
415 case LOCK_TRY_ALWAYS:
416 if (bo->lock_cnt > 0) {
422 TBM_LOG_E("error bo:%p lock_type[%d] is wrong.\n",
423 bo, bufmgr->lock_type);
427 if (bo->lock_cnt < 0)
430 TBM_DBG_LOCK(">> UNLOCK bo:%p(%d->%d)\n", bo, old, bo->lock_cnt);
434 _tbm_bo_is_valid(tbm_bo bo)
436 tbm_bo old_data = NULL;
438 if (bo == NULL || gBufMgr == NULL) {
439 TBM_LOG_E("error: bo is NULL or tbm_bufmgr was deinited\n");
443 if (LIST_IS_EMPTY(&gBufMgr->bo_list)) {
444 TBM_LOG_E("error: gBufMgr->bo_list is EMPTY.\n");
448 LIST_FOR_EACH_ENTRY(old_data, &gBufMgr->bo_list, item_link) {
453 TBM_LOG_E("error: No valid bo(%p).\n", bo);
459 _tbm_bo_free(tbm_bo bo)
461 tbm_bufmgr bufmgr = bo->bufmgr;
463 /* destory the user_data_list */
464 if (!LIST_IS_EMPTY(&bo->user_data_list)) {
465 tbm_user_data *old_data = NULL, *tmp;
467 LIST_FOR_EACH_ENTRY_SAFE(old_data, tmp,
468 &bo->user_data_list, item_link) {
469 TBM_DBG("free user_data\n");
470 user_data_delete(old_data);
474 while (bo->lock_cnt > 0) {
475 TBM_LOG_E("error lock_cnt:%d\n", bo->lock_cnt);
480 /* call the bo_free */
481 bufmgr->backend->bo_free(bo);
484 LIST_DEL(&bo->item_link);
490 /* LCOV_EXCL_START */
492 _check_version(TBMModuleVersionInfo *data)
497 abimaj = GET_ABI_MAJOR(data->abiversion);
498 abimin = GET_ABI_MINOR(data->abiversion);
500 TBM_DBG("TBM module %s: vendor=\"%s\" ABI=%d,%d\n",
501 data->modname ? data->modname : "UNKNOWN!",
502 data->vendor ? data->vendor : "UNKNOWN!", abimaj, abimin);
504 vermaj = GET_ABI_MAJOR(TBM_ABI_VERSION);
505 vermin = GET_ABI_MINOR(TBM_ABI_VERSION);
507 TBM_DBG("TBM ABI version %d.%d\n",
510 if (abimaj != vermaj) {
511 TBM_LOG_E("TBM module ABI major ver(%d) doesn't match the TBM's ver(%d)\n",
514 } else if (abimin > vermin) {
515 TBM_LOG_E("TBM module ABI minor ver(%d) is newer than the TBM's ver(%d)\n",
524 _tbm_bufmgr_load_module(tbm_bufmgr bufmgr, int fd, const char *file)
526 char path[PATH_MAX] = {0, };
527 TBMModuleVersionInfo *vers;
528 TBMModuleData *initdata;
532 snprintf(path, sizeof(path), BUFMGR_MODULE_DIR "/%s", file);
534 module_data = dlopen(path, RTLD_LAZY);
536 TBM_LOG_E("failed to load module: %s(%s)\n", dlerror(), file);
540 initdata = dlsym(module_data, "tbmModuleData");
542 TBM_LOG_E("Error: module does not have data object.\n");
546 vers = initdata->vers;
548 TBM_LOG_E("Error: module does not supply version information.\n");
552 init = initdata->init;
554 TBM_LOG_E("Error: module does not supply init symbol.\n");
558 if (!_check_version(vers)) {
559 TBM_LOG_E("Fail to check version.\n");
563 if (!init(bufmgr, fd)) {
564 TBM_LOG_E("Fail to init module(%s)\n", file);
568 if (!bufmgr->backend || !bufmgr->backend->priv) {
569 TBM_LOG_E("Error: module(%s) wrong operation. Check backend or backend's priv.\n", file);
573 bufmgr->module_data = module_data;
575 TBM_DBG("Success to load module(%s)\n", file);
580 dlclose(module_data);
585 _tbm_load_module(tbm_bufmgr bufmgr, int fd)
587 struct dirent **namelist;
590 /* load bufmgr priv from default lib */
591 if (_tbm_bufmgr_load_module(bufmgr, fd, DEFAULT_LIB))
594 /* load bufmgr priv from configured path */
595 n = scandir(BUFMGR_MODULE_DIR, &namelist, 0, alphasort);
597 TBM_LOG_E("no files : %s\n", BUFMGR_MODULE_DIR);
602 if (!ret && strstr(namelist[n]->d_name, PREFIX_LIB)) {
603 const char *p = strstr(namelist[n]->d_name, SUFFIX_LIB);
605 if (p && !strcmp(p, SUFFIX_LIB))
606 ret = _tbm_bufmgr_load_module(bufmgr, fd,
607 namelist[n]->d_name);
620 tbm_bufmgr_init(int fd)
622 #ifdef TBM_BUFMGR_INIT_TIME
623 struct timeval start_tv, end_tv;
627 #ifdef TBM_BUFMGR_INIT_TIME
628 /* get the start tv */
629 gettimeofday(&start_tv, NULL);
632 /* LCOV_EXCL_START */
634 env = getenv("TBM_DLOG");
637 TBM_LOG_D("TBM_DLOG=%s\n", env);
643 env = getenv("TBM_DEBUG");
646 TBM_LOG_D("TBM_DEBUG=%s\n", env);
652 env = getenv("TBM_TRACE");
655 TBM_LOG_D("TBM_TRACE=%s\n", env);
660 pthread_mutex_lock(&gLock);
663 TBM_LOG_W("!!!!!WARNING:: The tbm_bufmgr_init DOSE NOT use argument fd ANYMORE.\n");
664 TBM_LOG_W("!!!!!WARNING:: IT WILL BE CHANGED like tbm_bufmgr_init(int fd) --> tbm_bufmgr_init(void).\n");
668 /* initialize buffer manager */
670 gBufMgr->ref_count++;
671 TBM_TRACE("reuse tbm_bufmgr(%p) ref_count(%d) fd(%d)\n", gBufMgr, gBufMgr->ref_count, gBufMgr->fd);
672 pthread_mutex_unlock(&gLock);
676 TBM_DBG("bufmgr init\n");
678 /* allocate bufmgr */
679 gBufMgr = calloc(1, sizeof(struct _tbm_bufmgr));
681 _tbm_set_last_result(TBM_BO_ERROR_HEAP_ALLOC_FAILED);
682 TBM_TRACE("error: fail to alloc bufmgr fd(%d)\n", fd);
683 pthread_mutex_unlock(&gLock);
689 /* load bufmgr priv from env */
690 if (!_tbm_load_module(gBufMgr, gBufMgr->fd)) {
691 _tbm_set_last_result(TBM_BO_ERROR_LOAD_MODULE_FAILED);
692 TBM_LOG_E("error : Fail to load bufmgr backend\n");
695 pthread_mutex_unlock(&gLock);
701 /* log for tbm backend_flag */
702 TBM_DBG("backend flag:%x:", gBufMgr->backend->flags);
705 gBufMgr->ref_count = 1;
707 TBM_DBG("create tizen bufmgr:%p ref_count:%d\n",
708 gBufMgr, gBufMgr->ref_count);
710 /* setup the lock_type */
711 env = getenv("BUFMGR_LOCK_TYPE");
712 if (env && !strcmp(env, "always"))
713 gBufMgr->lock_type = LOCK_TRY_ALWAYS;
714 else if (env && !strcmp(env, "none"))
715 gBufMgr->lock_type = LOCK_TRY_NEVER;
716 else if (env && !strcmp(env, "once"))
717 gBufMgr->lock_type = LOCK_TRY_ONCE;
719 gBufMgr->lock_type = LOCK_TRY_ALWAYS;
721 TBM_DBG("BUFMGR_LOCK_TYPE=%s\n", env ? env : "default:once");
723 TBM_TRACE("create tbm_bufmgr(%p) ref_count(%d) fd(%d)\n", gBufMgr, gBufMgr->ref_count, fd);
725 /* intialize bo_list */
726 LIST_INITHEAD(&gBufMgr->bo_list);
728 /* intialize surf_list */
729 LIST_INITHEAD(&gBufMgr->surf_list);
731 /* intialize surf_queue_list */
732 LIST_INITHEAD(&gBufMgr->surf_queue_list);
734 /* intialize debug_key_list */
735 LIST_INITHEAD(&gBufMgr->debug_key_list);
737 #ifdef TBM_BUFMGR_INIT_TIME
739 gettimeofday(&end_tv, NULL);
740 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)));
743 pthread_mutex_unlock(&gLock);
749 tbm_bufmgr_deinit(tbm_bufmgr bufmgr)
751 TBM_RETURN_IF_FAIL(TBM_BUFMGR_IS_VALID(bufmgr));
753 _tbm_bufmgr_mutex_lock();
754 pthread_mutex_lock(&gLock);
757 TBM_LOG_E("gBufmgr already destroy: bufmgr:%p\n", bufmgr);
758 pthread_mutex_unlock(&gLock);
759 _tbm_bufmgr_mutex_unlock();
764 if (bufmgr->ref_count > 0) {
765 TBM_TRACE("reduce a ref_count(%d) of tbm_bufmgr(%p)\n", bufmgr->ref_count, bufmgr);
766 pthread_mutex_unlock(&gLock);
767 _tbm_bufmgr_mutex_unlock();
771 /* destroy bo_list */
772 if (!LIST_IS_EMPTY(&bufmgr->bo_list)) {
773 tbm_bo bo = NULL, tmp;
775 LIST_FOR_EACH_ENTRY_SAFE(bo, tmp, &bufmgr->bo_list, item_link) {
776 TBM_LOG_E("Un-freed bo(%p, ref:%d)\n", bo, bo->ref_cnt);
781 /* destroy surf_list */
782 if (!LIST_IS_EMPTY(&bufmgr->surf_list)) {
783 tbm_surface_h surf = NULL, tmp;
785 LIST_FOR_EACH_ENTRY_SAFE(surf, tmp, &bufmgr->surf_list, item_link) {
786 TBM_LOG_E("Un-freed surf(%p, ref:%d)\n", surf, surf->refcnt);
787 tbm_surface_destroy(surf);
791 /* destroy bufmgr priv */
792 bufmgr->backend->bufmgr_deinit(bufmgr->backend->priv);
793 bufmgr->backend->priv = NULL;
794 tbm_backend_free(bufmgr->backend);
795 bufmgr->backend = NULL;
797 TBM_TRACE("destroy tbm_bufmgr(%p)\n", bufmgr);
799 dlclose(bufmgr->module_data);
807 pthread_mutex_unlock(&gLock);
808 _tbm_bufmgr_mutex_unlock();
812 tbm_bo_size(tbm_bo bo)
814 tbm_bufmgr bufmgr = gBufMgr;
817 _tbm_bufmgr_mutex_lock();
819 TBM_BUFMGR_RETURN_VAL_IF_FAIL(TBM_BUFMGR_IS_VALID(gBufMgr), 0);
820 TBM_BUFMGR_RETURN_VAL_IF_FAIL(_tbm_bo_is_valid(bo), 0);
822 size = bufmgr->backend->bo_size(bo);
824 TBM_TRACE("bo(%p) size(%d)\n", bo, size);
826 _tbm_bufmgr_mutex_unlock();
832 tbm_bo_ref(tbm_bo bo)
834 _tbm_bufmgr_mutex_lock();
836 TBM_BUFMGR_RETURN_VAL_IF_FAIL(TBM_BUFMGR_IS_VALID(gBufMgr), NULL);
837 TBM_BUFMGR_RETURN_VAL_IF_FAIL(_tbm_bo_is_valid(bo), NULL);
841 TBM_TRACE("bo(%p) ref_cnt(%d)\n", bo, bo->ref_cnt);
843 _tbm_bufmgr_mutex_unlock();
849 tbm_bo_unref(tbm_bo bo)
851 _tbm_bufmgr_mutex_lock();
853 TBM_BUFMGR_RETURN_IF_FAIL(gBufMgr);
854 TBM_BUFMGR_RETURN_IF_FAIL(_tbm_bo_is_valid(bo));
856 TBM_TRACE("bo(%p) ref_cnt(%d)\n", bo, bo->ref_cnt - 1);
858 if (bo->ref_cnt <= 0) {
859 _tbm_bufmgr_mutex_unlock();
864 if (bo->ref_cnt == 0)
867 _tbm_bufmgr_mutex_unlock();
871 tbm_bo_alloc(tbm_bufmgr bufmgr, int size, int flags)
876 _tbm_bufmgr_mutex_lock();
878 TBM_BUFMGR_RETURN_VAL_IF_FAIL(TBM_BUFMGR_IS_VALID(bufmgr), NULL);
879 TBM_BUFMGR_RETURN_VAL_IF_FAIL(bufmgr == gBufMgr, NULL);
880 TBM_BUFMGR_RETURN_VAL_IF_FAIL(size > 0, NULL);
882 bo = calloc(1, sizeof(struct _tbm_bo));
884 /* LCOV_EXCL_START */
885 TBM_LOG_E("error: fail to create of tbm_bo size(%d) flag(%s)\n",
886 size, _tbm_flag_to_str(flags));
887 _tbm_set_last_result(TBM_BO_ERROR_HEAP_ALLOC_FAILED);
888 _tbm_bufmgr_mutex_unlock();
893 _tbm_util_check_bo_cnt(bufmgr);
897 bo_priv = bufmgr->backend->bo_alloc(bo, size, flags);
899 /* LCOV_EXCL_START */
900 TBM_LOG_E("error: fail to create of tbm_bo size(%d) flag(%s)\n",
901 size, _tbm_flag_to_str(flags));
902 _tbm_set_last_result(TBM_BO_ERROR_BO_ALLOC_FAILED);
904 _tbm_bufmgr_mutex_unlock();
915 TBM_TRACE("bo(%p) size(%d) refcnt(%d), flag(%s)\n", bo, size, bo->ref_cnt,
916 _tbm_flag_to_str(bo->flags));
918 LIST_INITHEAD(&bo->user_data_list);
920 LIST_ADD(&bo->item_link, &bufmgr->bo_list);
922 _tbm_bufmgr_mutex_unlock();
928 tbm_bo_import(tbm_bufmgr bufmgr, unsigned int key)
933 _tbm_bufmgr_mutex_lock();
935 TBM_BUFMGR_RETURN_VAL_IF_FAIL(TBM_BUFMGR_IS_VALID(bufmgr), NULL);
936 TBM_BUFMGR_RETURN_VAL_IF_FAIL(bufmgr == gBufMgr, NULL);
938 if (!bufmgr->backend->bo_import) {
939 /* LCOV_EXCL_START */
940 _tbm_bufmgr_mutex_unlock();
945 _tbm_util_check_bo_cnt(bufmgr);
947 bo = calloc(1, sizeof(struct _tbm_bo));
949 /* LCOV_EXCL_START */
950 TBM_LOG_E("error: fail to import of tbm_bo by key(%d)\n", key);
951 _tbm_bufmgr_mutex_unlock();
958 bo_priv = bufmgr->backend->bo_import(bo, key);
960 /* LCOV_EXCL_START */
961 TBM_LOG_E("error: fail to import of tbm_bo by key(%d)\n", key);
962 _tbm_set_last_result(TBM_BO_ERROR_IMPORT_FAILED);
964 _tbm_bufmgr_mutex_unlock();
969 if (!LIST_IS_EMPTY(&bufmgr->bo_list)) {
972 LIST_FOR_EACH_ENTRY(bo2, &bufmgr->bo_list, item_link) {
973 if (bo2->priv == bo_priv) {
974 TBM_TRACE("find bo(%p) ref(%d) key(%d) flag(%s) in list\n",
975 bo2, bo2->ref_cnt, key,
976 _tbm_flag_to_str(bo2->flags));
979 _tbm_bufmgr_mutex_unlock();
990 if (bufmgr->backend->bo_get_flags)
991 bo->flags = bufmgr->backend->bo_get_flags(bo);
993 bo->flags = TBM_BO_DEFAULT;
995 TBM_TRACE("import new bo(%p) ref(%d) key(%d) flag(%s) in list\n",
996 bo, bo->ref_cnt, key, _tbm_flag_to_str(bo->flags));
998 LIST_INITHEAD(&bo->user_data_list);
1000 LIST_ADD(&bo->item_link, &bufmgr->bo_list);
1002 _tbm_bufmgr_mutex_unlock();
1008 tbm_bo_import_fd(tbm_bufmgr bufmgr, tbm_fd fd)
1013 _tbm_bufmgr_mutex_lock();
1015 TBM_BUFMGR_RETURN_VAL_IF_FAIL(TBM_BUFMGR_IS_VALID(bufmgr), NULL);
1016 TBM_BUFMGR_RETURN_VAL_IF_FAIL(bufmgr == gBufMgr, NULL);
1018 if (!bufmgr->backend->bo_import_fd) {
1019 /* LCOV_EXCL_START */
1020 _tbm_bufmgr_mutex_unlock();
1022 /* LCOV_EXCL_STOP */
1025 _tbm_util_check_bo_cnt(bufmgr);
1027 bo = calloc(1, sizeof(struct _tbm_bo));
1029 /* LCOV_EXCL_START */
1030 TBM_LOG_E("error: fail to import tbm_bo by tbm_fd(%d)\n", fd);
1031 _tbm_bufmgr_mutex_unlock();
1033 /* LCOV_EXCL_STOP */
1036 bo->bufmgr = bufmgr;
1038 bo_priv = bufmgr->backend->bo_import_fd(bo, fd);
1040 /* LCOV_EXCL_START */
1041 TBM_LOG_E("error: fail to import tbm_bo by tbm_fd(%d)\n", fd);
1042 _tbm_set_last_result(TBM_BO_ERROR_IMPORT_FD_FAILED);
1044 _tbm_bufmgr_mutex_unlock();
1046 /* LCOV_EXCL_STOP */
1049 if (!LIST_IS_EMPTY(&bufmgr->bo_list)) {
1052 LIST_FOR_EACH_ENTRY(bo2, &bufmgr->bo_list, item_link) {
1053 if (bo2->priv == bo_priv) {
1054 TBM_TRACE("find bo(%p) ref(%d) fd(%d) flag(%s) in list\n",
1055 bo2, bo2->ref_cnt, fd,
1056 _tbm_flag_to_str(bo2->flags));
1059 _tbm_bufmgr_mutex_unlock();
1070 if (bufmgr->backend->bo_get_flags)
1071 bo->flags = bufmgr->backend->bo_get_flags(bo);
1073 bo->flags = TBM_BO_DEFAULT;
1075 TBM_TRACE("import bo(%p) ref(%d) fd(%d) flag(%s)\n",
1076 bo, bo->ref_cnt, fd, _tbm_flag_to_str(bo->flags));
1078 LIST_INITHEAD(&bo->user_data_list);
1080 LIST_ADD(&bo->item_link, &bufmgr->bo_list);
1082 _tbm_bufmgr_mutex_unlock();
1088 tbm_bo_export(tbm_bo bo)
1090 tbm_bufmgr bufmgr = gBufMgr;
1093 _tbm_bufmgr_mutex_lock();
1095 TBM_BUFMGR_RETURN_VAL_IF_FAIL(TBM_BUFMGR_IS_VALID(gBufMgr), 0);
1096 TBM_BUFMGR_RETURN_VAL_IF_FAIL(_tbm_bo_is_valid(bo), 0);
1098 if (!bufmgr->backend->bo_export) {
1099 /* LCOV_EXCL_START */
1100 _tbm_bufmgr_mutex_unlock();
1102 /* LCOV_EXCL_STOP */
1105 ret = bufmgr->backend->bo_export(bo);
1107 /* LCOV_EXCL_START */
1108 _tbm_set_last_result(TBM_BO_ERROR_EXPORT_FAILED);
1109 TBM_LOG_E("error: bo(%p) tbm_key(%d)\n", bo, ret);
1110 _tbm_bufmgr_mutex_unlock();
1112 /* LCOV_EXCL_STOP */
1115 TBM_TRACE("bo(%p) tbm_key(%u)\n", bo, ret);
1117 _tbm_bufmgr_mutex_unlock();
1123 tbm_bo_export_fd(tbm_bo bo)
1125 tbm_bufmgr bufmgr = gBufMgr;
1128 _tbm_bufmgr_mutex_lock();
1130 TBM_BUFMGR_RETURN_VAL_IF_FAIL(TBM_BUFMGR_IS_VALID(gBufMgr), -1);
1131 TBM_BUFMGR_RETURN_VAL_IF_FAIL(_tbm_bo_is_valid(bo), -1);
1133 if (!bufmgr->backend->bo_export_fd) {
1134 /* LCOV_EXCL_START */
1135 _tbm_bufmgr_mutex_unlock();
1137 /* LCOV_EXCL_STOP */
1140 ret = bufmgr->backend->bo_export_fd(bo);
1142 /* LCOV_EXCL_START */
1143 _tbm_set_last_result(TBM_BO_ERROR_EXPORT_FD_FAILED);
1144 TBM_LOG_E("error: bo(%p) tbm_fd(%d)\n", bo, ret);
1145 _tbm_bufmgr_mutex_unlock();
1147 /* LCOV_EXCL_STOP */
1150 TBM_TRACE("bo(%p) tbm_fd(%d)\n", bo, ret);
1152 _tbm_bufmgr_mutex_unlock();
1158 tbm_bo_get_handle(tbm_bo bo, int device)
1160 tbm_bufmgr bufmgr = gBufMgr;
1161 tbm_bo_handle bo_handle;
1163 _tbm_bufmgr_mutex_lock();
1165 TBM_BUFMGR_RETURN_VAL_IF_FAIL(TBM_BUFMGR_IS_VALID(gBufMgr), (tbm_bo_handle) NULL);
1166 TBM_BUFMGR_RETURN_VAL_IF_FAIL(_tbm_bo_is_valid(bo), (tbm_bo_handle) NULL);
1168 bo_handle = bufmgr->backend->bo_get_handle(bo, device);
1169 if (bo_handle.ptr == NULL) {
1170 /* LCOV_EXCL_START */
1171 _tbm_set_last_result(TBM_BO_ERROR_GET_HANDLE_FAILED);
1172 TBM_LOG_E("error: bo(%p) bo_handle(%p)\n", bo, bo_handle.ptr);
1173 _tbm_bufmgr_mutex_unlock();
1174 return (tbm_bo_handle) NULL;
1175 /* LCOV_EXCL_STOP */
1178 TBM_TRACE("bo(%p) bo_handle(%p)\n", bo, bo_handle.ptr);
1180 _tbm_bufmgr_mutex_unlock();
1186 tbm_bo_map(tbm_bo bo, int device, int opt)
1188 tbm_bufmgr bufmgr = gBufMgr;
1189 tbm_bo_handle bo_handle;
1191 _tbm_bufmgr_mutex_lock();
1193 TBM_BUFMGR_RETURN_VAL_IF_FAIL(TBM_BUFMGR_IS_VALID(gBufMgr), (tbm_bo_handle) NULL);
1194 TBM_BUFMGR_RETURN_VAL_IF_FAIL(_tbm_bo_is_valid(bo), (tbm_bo_handle) NULL);
1196 if (!_tbm_bo_lock(bo, device, opt)) {
1197 _tbm_set_last_result(TBM_BO_ERROR_LOCK_FAILED);
1198 TBM_LOG_E("error: fail to lock bo:%p)\n", bo);
1199 _tbm_bufmgr_mutex_unlock();
1200 return (tbm_bo_handle) NULL;
1203 bo_handle = bufmgr->backend->bo_map(bo, device, opt);
1204 if (bo_handle.ptr == NULL) {
1205 /* LCOV_EXCL_START */
1206 _tbm_set_last_result(TBM_BO_ERROR_MAP_FAILED);
1207 TBM_LOG_E("error: fail to map bo:%p\n", bo);
1209 _tbm_bufmgr_mutex_unlock();
1210 return (tbm_bo_handle) NULL;
1211 /* LCOV_EXCL_STOP */
1214 /* increase the map_count */
1217 TBM_TRACE("bo(%p) map_cnt(%d)\n", bo, bo->map_cnt);
1219 _tbm_bufmgr_mutex_unlock();
1225 tbm_bo_unmap(tbm_bo bo)
1227 tbm_bufmgr bufmgr = gBufMgr;
1230 _tbm_bufmgr_mutex_lock();
1232 TBM_BUFMGR_RETURN_VAL_IF_FAIL(TBM_BUFMGR_IS_VALID(gBufMgr), 0);
1233 TBM_BUFMGR_RETURN_VAL_IF_FAIL(_tbm_bo_is_valid(bo), 0);
1235 ret = bufmgr->backend->bo_unmap(bo);
1237 /* LCOV_EXCL_START */
1238 TBM_LOG_E("error: bo(%p) map_cnt(%d)\n", bo, bo->map_cnt);
1239 _tbm_set_last_result(TBM_BO_ERROR_UNMAP_FAILED);
1240 _tbm_bufmgr_mutex_unlock();
1242 /* LCOV_EXCL_STOP */
1245 /* decrease the map_count */
1248 TBM_TRACE("bo(%p) map_cnt(%d)\n", bo, bo->map_cnt);
1252 _tbm_bufmgr_mutex_unlock();
1258 tbm_bo_swap(tbm_bo bo1, tbm_bo bo2)
1260 tbm_bufmgr bufmgr = gBufMgr;
1263 _tbm_bufmgr_mutex_lock();
1265 TBM_BUFMGR_RETURN_VAL_IF_FAIL(TBM_BUFMGR_IS_VALID(gBufMgr), 0);
1266 TBM_BUFMGR_RETURN_VAL_IF_FAIL(_tbm_bo_is_valid(bo1), 0);
1267 TBM_BUFMGR_RETURN_VAL_IF_FAIL(_tbm_bo_is_valid(bo2), 0);
1269 TBM_TRACE("before: bo1(%p) bo2(%p)\n", bo1, bo2);
1271 if (bufmgr->backend->bo_size(bo1) != bufmgr->backend->bo_size(bo2)) {
1272 _tbm_set_last_result(TBM_BO_ERROR_SWAP_FAILED);
1273 TBM_LOG_E("error: bo1(%p) bo2(%p)\n", bo1, bo2);
1274 _tbm_bufmgr_mutex_unlock();
1278 TBM_TRACE("after: bo1(%p) bo2(%p)\n", bo1, bo2);
1281 bo1->priv = bo2->priv;
1284 _tbm_bufmgr_mutex_unlock();
1290 tbm_bo_locked(tbm_bo bo)
1292 tbm_bufmgr bufmgr = gBufMgr;
1294 _tbm_bufmgr_mutex_lock();
1296 TBM_BUFMGR_RETURN_VAL_IF_FAIL(TBM_BUFMGR_IS_VALID(gBufMgr), 0);
1297 TBM_BUFMGR_RETURN_VAL_IF_FAIL(_tbm_bo_is_valid(bo), 0);
1299 if (bufmgr->lock_type == LOCK_TRY_NEVER) {
1300 TBM_LOG_E("bo(%p) lock_cnt(%d)\n", bo, bo->lock_cnt);
1301 _tbm_bufmgr_mutex_unlock();
1305 if (bo->lock_cnt > 0) {
1306 TBM_TRACE("error: bo(%p) lock_cnt(%d)\n", bo, bo->lock_cnt);
1307 _tbm_bufmgr_mutex_unlock();
1311 TBM_TRACE("bo(%p) lock_cnt(%d)\n", bo, bo->lock_cnt);
1312 _tbm_bufmgr_mutex_unlock();
1318 tbm_bo_add_user_data(tbm_bo bo, unsigned long key,
1319 tbm_data_free data_free_func)
1321 tbm_user_data *data;
1323 _tbm_bufmgr_mutex_lock();
1325 TBM_BUFMGR_RETURN_VAL_IF_FAIL(TBM_BUFMGR_IS_VALID(gBufMgr), 0);
1326 TBM_BUFMGR_RETURN_VAL_IF_FAIL(_tbm_bo_is_valid(bo), 0);
1328 /* check if the data according to the key exist if so, return false. */
1329 data = user_data_lookup(&bo->user_data_list, key);
1331 TBM_TRACE("warning: user data already exist key(%ld)\n", key);
1332 _tbm_bufmgr_mutex_unlock();
1336 data = user_data_create(key, data_free_func);
1338 TBM_LOG_E("error: bo(%p) key(%lu)\n", bo, key);
1339 _tbm_bufmgr_mutex_unlock();
1343 TBM_TRACE("bo(%p) key(%lu) data(%p)\n", bo, key, data->data);
1345 LIST_ADD(&data->item_link, &bo->user_data_list);
1347 _tbm_bufmgr_mutex_unlock();
1353 tbm_bo_set_user_data(tbm_bo bo, unsigned long key, void *data)
1355 tbm_user_data *old_data;
1357 _tbm_bufmgr_mutex_lock();
1359 TBM_BUFMGR_RETURN_VAL_IF_FAIL(TBM_BUFMGR_IS_VALID(gBufMgr), 0);
1360 TBM_BUFMGR_RETURN_VAL_IF_FAIL(_tbm_bo_is_valid(bo), 0);
1362 if (LIST_IS_EMPTY(&bo->user_data_list)) {
1363 TBM_TRACE("error: bo(%p) key(%lu)\n", bo, key);
1364 _tbm_bufmgr_mutex_unlock();
1368 old_data = user_data_lookup(&bo->user_data_list, key);
1370 TBM_TRACE("error: bo(%p) key(%lu)\n", bo, key);
1371 _tbm_bufmgr_mutex_unlock();
1375 if (old_data->data && old_data->free_func)
1376 old_data->free_func(old_data->data);
1377 old_data->data = data;
1379 TBM_TRACE("bo(%p) key(%lu) data(%p)\n", bo, key, old_data->data);
1381 _tbm_bufmgr_mutex_unlock();
1387 tbm_bo_get_user_data(tbm_bo bo, unsigned long key, void **data)
1389 tbm_user_data *old_data;
1391 _tbm_bufmgr_mutex_lock();
1393 TBM_BUFMGR_RETURN_VAL_IF_FAIL(TBM_BUFMGR_IS_VALID(gBufMgr), 0);
1394 TBM_BUFMGR_RETURN_VAL_IF_FAIL(_tbm_bo_is_valid(bo), 0);
1396 if (!data || LIST_IS_EMPTY(&bo->user_data_list)) {
1397 TBM_TRACE("error: bo(%p) key(%lu)\n", bo, key);
1398 _tbm_bufmgr_mutex_unlock();
1402 old_data = user_data_lookup(&bo->user_data_list, key);
1404 TBM_TRACE("error: bo(%p) key(%lu)\n", bo, key);
1406 _tbm_bufmgr_mutex_unlock();
1410 *data = old_data->data;
1412 TBM_TRACE("bo(%p) key(%lu) data(%p)\n", bo, key, old_data->data);
1414 _tbm_bufmgr_mutex_unlock();
1420 tbm_bo_delete_user_data(tbm_bo bo, unsigned long key)
1422 tbm_user_data *old_data;
1424 _tbm_bufmgr_mutex_lock();
1426 TBM_BUFMGR_RETURN_VAL_IF_FAIL(TBM_BUFMGR_IS_VALID(gBufMgr), 0);
1427 TBM_BUFMGR_RETURN_VAL_IF_FAIL(_tbm_bo_is_valid(bo), 0);
1429 if (LIST_IS_EMPTY(&bo->user_data_list)) {
1430 TBM_TRACE("error: bo(%p) key(%lu)\n", bo, key);
1431 _tbm_bufmgr_mutex_unlock();
1435 old_data = user_data_lookup(&bo->user_data_list, key);
1437 TBM_TRACE("error: bo(%p) key(%lu)\n", bo, key);
1438 _tbm_bufmgr_mutex_unlock();
1442 TBM_TRACE("bo(%p) key(%lu) data(%p)\n", bo, key, old_data->data);
1444 user_data_delete(old_data);
1446 _tbm_bufmgr_mutex_unlock();
1452 tbm_bufmgr_get_capability(tbm_bufmgr bufmgr)
1454 unsigned int capabilities = TBM_BUFMGR_CAPABILITY_NONE;
1456 _tbm_bufmgr_mutex_lock();
1458 TBM_BUFMGR_RETURN_VAL_IF_FAIL(TBM_BUFMGR_IS_VALID(bufmgr), TBM_BUFMGR_CAPABILITY_NONE);
1459 TBM_BUFMGR_RETURN_VAL_IF_FAIL(bufmgr == gBufMgr, TBM_BUFMGR_CAPABILITY_NONE);
1461 TBM_TRACE("tbm_bufmgr(%p) capability(%u)\n", bufmgr, bufmgr->capabilities);
1463 capabilities = bufmgr->capabilities;
1465 _tbm_bufmgr_mutex_unlock();
1467 return capabilities;
1471 tbm_bo_get_flags(tbm_bo bo)
1475 _tbm_bufmgr_mutex_lock();
1477 TBM_BUFMGR_RETURN_VAL_IF_FAIL(TBM_BUFMGR_IS_VALID(gBufMgr), 0);
1478 TBM_BUFMGR_RETURN_VAL_IF_FAIL(_tbm_bo_is_valid(bo), 0);
1482 TBM_TRACE("bo(%p)\n", bo);
1484 _tbm_bufmgr_mutex_unlock();
1489 /* LCOV_EXCL_START */
1491 tbm_get_last_error(void)
1493 return tbm_last_error;
1497 tbm_bufmgr_debug_tbm_info_get(tbm_bufmgr bufmgr, char *str, int *len)
1499 char app_name[255] = {0,}, title[512] = {0,};
1500 tbm_surface_debug_data *debug_old_data = NULL;
1502 pthread_mutex_lock(&gLock);
1504 if (!TBM_BUFMGR_IS_VALID(bufmgr) || (bufmgr != gBufMgr)) {
1505 TBM_LOG_E("invalid bufmgr\n");
1506 pthread_mutex_unlock(&gLock);
1510 TBM_SNPRINTF(str, len, "\n");
1511 _tbm_util_get_appname_from_pid(getpid(), app_name);
1512 _tbm_util_get_appname_brief(app_name);
1513 TBM_SNPRINTF(str, len, "============TBM DEBUG: %s(%d)===========================\n",
1514 app_name, getpid());
1516 snprintf(title, 255, "%s", "no surface refcnt width height bpp size n_b n_p flags format app_name ");
1518 if (!LIST_IS_EMPTY(&bufmgr->debug_key_list)) {
1519 LIST_FOR_EACH_ENTRY(debug_old_data, &bufmgr->debug_key_list, item_link) {
1520 strncat(title, " ", MAX_SIZE_N(title));
1521 strncat(title, debug_old_data->key, MAX_SIZE_N(title));
1525 TBM_SNPRINTF(str, len, "[tbm_surface information]\n");
1526 TBM_SNPRINTF(str, len, "%s\n", title);
1528 /* show the tbm_surface information in surf_list */
1529 if (!LIST_IS_EMPTY(&bufmgr->surf_list)) {
1530 tbm_surface_h surf = NULL;
1533 LIST_FOR_EACH_ENTRY(surf, &bufmgr->surf_list, item_link) {
1534 char data[512] = {0,};
1538 pid = _tbm_surface_internal_get_debug_pid(surf);
1540 /* if pid is null, set the self_pid */
1544 memset(app_name, 0x0, 255 * sizeof(char));
1545 _tbm_util_get_appname_from_pid(pid, app_name);
1546 _tbm_util_get_appname_brief(app_name);
1548 snprintf(data, 255, "%-2d %-9p %-4d %-5u %-6u %-3u %-6u %-2d %-2d %-3d %-8s %-15s",
1555 surf->info.size / 1024,
1559 _tbm_surface_internal_format_to_str(surf->info.format) + 11,
1562 if (!LIST_IS_EMPTY(&bufmgr->debug_key_list)) {
1563 LIST_FOR_EACH_ENTRY(debug_old_data, &bufmgr->debug_key_list, item_link) {
1566 strncat(data, " ", MAX_SIZE_N(title));
1568 value = _tbm_surface_internal_get_debug_data(surf, debug_old_data->key);
1570 strncat(data, value, MAX_SIZE_N(title));
1572 strncat(data, "none", MAX_SIZE_N(title));
1575 TBM_SNPRINTF(str, len, "%s\n", data);
1577 for (i = 0; i < surf->num_bos; i++) {
1578 TBM_SNPRINTF(str, len, " bo:%-12p %-26d%-10d\n",
1580 surf->bos[i]->ref_cnt,
1581 bufmgr->backend->bo_size(surf->bos[i]) / 1024);
1585 TBM_SNPRINTF(str, len, " no tbm_surfaces.\n");
1586 TBM_SNPRINTF(str, len, "\n");
1588 TBM_SNPRINTF(str, len, "[tbm_bo information]\n");
1589 TBM_SNPRINTF(str, len, "no bo refcnt size lock_cnt map_cnt flags surface\n");
1591 /* show the tbm_bo information in bo_list */
1592 if (!LIST_IS_EMPTY(&bufmgr->bo_list)) {
1596 LIST_FOR_EACH_ENTRY(bo, &bufmgr->bo_list, item_link) {
1597 TBM_SNPRINTF(str, len, "%-4d%-11p %-4d %-6d %-5d %-4u %-3d %-11p\n",
1601 bufmgr->backend->bo_size(bo) / 1024,
1608 TBM_SNPRINTF(str, len, "no tbm_bos.\n");
1609 TBM_SNPRINTF(str, len, "\n");
1611 TBM_SNPRINTF(str, len, "===============================================================\n");
1613 pthread_mutex_unlock(&gLock);
1617 tbm_bufmgr_debug_show(tbm_bufmgr bufmgr)
1620 int len = sizeof(str);
1621 tbm_bufmgr_debug_tbm_info_get(bufmgr, str, &len);
1622 TBM_DEBUG(" %s", str);
1626 tbm_bufmgr_debug_trace(tbm_bufmgr bufmgr, int onoff)
1628 _tbm_bufmgr_mutex_lock();
1630 TBM_BUFMGR_RETURN_IF_FAIL(TBM_BUFMGR_IS_VALID(bufmgr));
1631 TBM_BUFMGR_RETURN_IF_FAIL(bufmgr == gBufMgr);
1634 TBM_LOG_D("bufmgr=%p onoff=%d\n", bufmgr, onoff);
1638 _tbm_bufmgr_mutex_unlock();
1642 tbm_bufmgr_debug_dump_set_scale(double scale)
1644 pthread_mutex_lock(&gLock);
1645 scale_factor = scale;
1646 pthread_mutex_unlock(&gLock);
1650 tbm_bufmgr_debug_queue_dump(char *path, int count, int onoff)
1652 pthread_mutex_lock(&gLock);
1655 TBM_LOG_D("count=%d onoff=%d\n", count, onoff);
1657 tbm_surface_internal_dump_end();
1662 TBM_LOG_E("path is null");
1663 pthread_mutex_unlock(&gLock);
1666 TBM_LOG_D("path=%s count=%d onoff=%d\n", path, count, onoff);
1668 if (_tbm_util_get_max_surface_size(&w, &h) == 0) {
1669 TBM_LOG_E("Fail to get tbm_surface size.\n");
1670 pthread_mutex_unlock(&gLock);
1674 tbm_surface_internal_dump_with_scale_start(path, w, h, count, scale_factor);
1680 pthread_mutex_unlock(&gLock);
1685 tbm_bufmgr_debug_dump_all(char *path)
1687 int w, h, count = 0;
1688 tbm_surface_h surface = NULL;
1690 TBM_RETURN_VAL_IF_FAIL(path != NULL, 0);
1691 TBM_LOG_D("path=%s\n", path);
1693 pthread_mutex_lock(&gLock);
1695 count = _tbm_util_get_max_surface_size(&w, &h);
1697 TBM_LOG_E("No tbm_surface.\n");
1698 pthread_mutex_unlock(&gLock);
1702 tbm_surface_internal_dump_with_scale_start(path, w, h, count, scale_factor);
1705 LIST_FOR_EACH_ENTRY(surface, &gBufMgr->surf_list, item_link)
1706 tbm_surface_internal_dump_buffer(surface, "dump_all");
1708 tbm_surface_internal_dump_end();
1710 pthread_mutex_unlock(&gLock);
1715 /* internal function */
1717 _tbm_bufmgr_get_bufmgr(void)
1723 _tbm_bo_set_surface(tbm_bo bo, tbm_surface_h surface)
1725 _tbm_bufmgr_mutex_lock();
1727 TBM_BUFMGR_RETURN_VAL_IF_FAIL(TBM_BUFMGR_IS_VALID(gBufMgr), 0);
1728 TBM_BUFMGR_RETURN_VAL_IF_FAIL(_tbm_bo_is_valid(bo), 0);
1730 bo->surface = surface;
1732 _tbm_bufmgr_mutex_unlock();
1738 tbm_bufmgr_bind_native_display(tbm_bufmgr bufmgr, void *NativeDisplay)
1742 _tbm_bufmgr_mutex_lock();
1744 TBM_BUFMGR_RETURN_VAL_IF_FAIL(TBM_BUFMGR_IS_VALID(gBufMgr), 0);
1746 if (!bufmgr->backend->bufmgr_bind_native_display) {
1747 TBM_TRACE("skip: tbm_bufmgr(%p) NativeDisplay(%p)\n",
1748 bufmgr, NativeDisplay);
1749 _tbm_bufmgr_mutex_unlock();
1753 ret = bufmgr->backend->bufmgr_bind_native_display(bufmgr, NativeDisplay);
1755 TBM_LOG_E("error: tbm_bufmgr(%p) NativeDisplay(%p)\n",
1756 bufmgr, NativeDisplay);
1757 _tbm_bufmgr_mutex_unlock();
1761 TBM_TRACE("tbm_bufmgr(%p) NativeDisplay(%p)\n", bufmgr, NativeDisplay);
1763 _tbm_bufmgr_mutex_unlock();
1768 int tbm_bufmgr_get_fd_limit(void)
1772 if (getrlimit(RLIMIT_NOFILE, &lim))
1775 return (int)lim.rlim_cur;
1777 /* LCOV_EXCL_STOP */