use TBM_LOG_E at error case at tbm_bufmgr.c
[platform/core/uifw/libtbm.git] / src / tbm_bufmgr.c
index 79179e6..3e39ea0 100644 (file)
@@ -113,7 +113,7 @@ _tbm_bufmgr_mutex_init(void)
                return true;
 
        if (pthread_mutex_init(&tbm_bufmgr_lock, NULL)) {
-               TBM_LOG_E("fail: tbm_bufmgr mutex init\n");
+               TBM_LOG_E("fail: Cannot pthread_mutex_init for tbm_bufmgr_lock.\n");
                return false;
        }
 
@@ -125,8 +125,10 @@ _tbm_bufmgr_mutex_init(void)
 static void
 _tbm_bufmgr_mutex_lock(void)
 {
-       if (!_tbm_bufmgr_mutex_init())
+       if (!_tbm_bufmgr_mutex_init()) {
+               TBM_LOG_E("fail: _tbm_bufmgr_mutex_init()\n");
                return;
+       }
 
        pthread_mutex_lock(&tbm_bufmgr_lock);
 }
@@ -193,7 +195,7 @@ _tbm_util_get_max_surface_size(int *w, int *h)
        *w = 0;
        *h = 0;
 
-       if (gBufMgr == NULL || !LIST_IS_EMPTY(&gBufMgr->surf_list))
+       if (gBufMgr == NULL || LIST_IS_EMPTY(&gBufMgr->surf_list))
                return count;
 
        LIST_FOR_EACH_ENTRY(surface, &gBufMgr->surf_list, item_link) {
@@ -239,12 +241,12 @@ _tbm_util_get_appname_from_pid(long pid, char *str)
 
        fp = fopen(fn_cmdline, "r");
        if (fp == 0) {
-               fprintf(stderr, "cannot file open %s\n", fn_cmdline);
+               TBM_LOG_E("cannot file open %s\n", fn_cmdline);
                return;
        }
 
        if (!fgets(cmdline, 255, fp)) {
-               fprintf(stderr, "fail to get appname for pid(%ld)\n", pid);
+               TBM_LOG_E("fail to get appname for pid(%ld)\n", pid);
                fclose(fp);
                return;
        }
@@ -283,8 +285,10 @@ tbm_user_data
        tbm_user_data *user_data;
 
        user_data = calloc(1, sizeof(tbm_user_data));
-       if (!user_data)
+       if (!user_data) {
+               TBM_LOG_E("fail to allocate an user_date\n");
                return NULL;
+       }
 
        user_data->key = key;
        user_data->free_func = data_free_func;
@@ -423,21 +427,25 @@ _tbm_bo_unlock(tbm_bo bo)
 static int
 _tbm_bo_is_valid(tbm_bo bo)
 {
-       tbm_bo old_data;
+       tbm_bo old_data = NULL;
 
        if (bo == NULL || gBufMgr == NULL) {
                TBM_LOG_E("error: bo is NULL or tbm_bufmgr was deinited\n");
                return 0;
        }
 
-       if (LIST_IS_EMPTY(&gBufMgr->bo_list))
+       if (LIST_IS_EMPTY(&gBufMgr->bo_list)) {
+               TBM_LOG_E("error: gBufMgr->bo_list is EMPTY.\n");
                return 0;
+       }
 
        LIST_FOR_EACH_ENTRY(old_data, &gBufMgr->bo_list, item_link) {
                if (old_data == bo)
                        return 1;
        }
 
+       TBM_LOG_E("error: No valid bo(%p).\n", bo);
+
        return 0;
 }
 
@@ -614,6 +622,11 @@ tbm_bufmgr_init(int fd)
 
        pthread_mutex_lock(&gLock);
 
+       if (fd >= 0) {
+               TBM_LOG_W("!!!!!WARNING:: The tbm_bufmgr_init DOSE NOT use argument fd ANYMORE.\n");
+               TBM_LOG_W("!!!!!WARNING:: IT WILL BE CHANGED like tbm_bufmgr_init(int fd) --> tbm_bufmgr_init(void).\n");
+       }
+
        /* initialize buffer manager */
        if (gBufMgr) {
                gBufMgr->ref_count++;
@@ -854,7 +867,7 @@ tbm_bo_alloc(tbm_bufmgr bufmgr, int size, int flags)
 
        bo = calloc(1, sizeof(struct _tbm_bo));
        if (!bo) {
-               TBM_TRACE("error: fail to create of tbm_bo size(%d) flag(%s)\n",
+               TBM_LOG_E("error: fail to create of tbm_bo size(%d) flag(%s)\n",
                                size, _tbm_flag_to_str(flags));
                _tbm_set_last_result(TBM_BO_ERROR_HEAP_ALLOC_FAILED);
                _tbm_bufmgr_mutex_unlock();
@@ -867,7 +880,7 @@ tbm_bo_alloc(tbm_bufmgr bufmgr, int size, int flags)
 
        bo_priv = bufmgr->backend->bo_alloc(bo, size, flags);
        if (!bo_priv) {
-               TBM_TRACE("error: fail to create of tbm_bo size(%d) flag(%s)\n",
+               TBM_LOG_E("error: fail to create of tbm_bo size(%d) flag(%s)\n",
                                size, _tbm_flag_to_str(flags));
                _tbm_set_last_result(TBM_BO_ERROR_BO_ALLOC_FAILED);
                free(bo);
@@ -913,7 +926,7 @@ tbm_bo_import(tbm_bufmgr bufmgr, unsigned int key)
 
        bo = calloc(1, sizeof(struct _tbm_bo));
        if (!bo) {
-               TBM_TRACE("error: fail to import of tbm_bo by key(%d)\n", key);
+               TBM_LOG_E("error: fail to import of tbm_bo by key(%d)\n", key);
                _tbm_bufmgr_mutex_unlock();
                return NULL;
        }
@@ -922,7 +935,7 @@ tbm_bo_import(tbm_bufmgr bufmgr, unsigned int key)
 
        bo_priv = bufmgr->backend->bo_import(bo, key);
        if (!bo_priv) {
-               TBM_TRACE("error: fail to import of tbm_bo by key(%d)\n", key);
+               TBM_LOG_E("error: fail to import of tbm_bo by key(%d)\n", key);
                _tbm_set_last_result(TBM_BO_ERROR_IMPORT_FAILED);
                free(bo);
                _tbm_bufmgr_mutex_unlock();
@@ -987,7 +1000,7 @@ tbm_bo_import_fd(tbm_bufmgr bufmgr, tbm_fd fd)
 
        bo = calloc(1, sizeof(struct _tbm_bo));
        if (!bo) {
-               TBM_TRACE("error: fail to import tbm_bo by tbm_fd(%d)\n", fd);
+               TBM_LOG_E("error: fail to import tbm_bo by tbm_fd(%d)\n", fd);
                _tbm_bufmgr_mutex_unlock();
                return NULL;
        }
@@ -996,7 +1009,7 @@ tbm_bo_import_fd(tbm_bufmgr bufmgr, tbm_fd fd)
 
        bo_priv = bufmgr->backend->bo_import_fd(bo, fd);
        if (!bo_priv) {
-               TBM_TRACE("error: fail to import tbm_bo by tbm_fd(%d)\n", fd);
+               TBM_LOG_E("error: fail to import tbm_bo by tbm_fd(%d)\n", fd);
                _tbm_set_last_result(TBM_BO_ERROR_IMPORT_FD_FAILED);
                free(bo);
                _tbm_bufmgr_mutex_unlock();
@@ -1060,7 +1073,7 @@ tbm_bo_export(tbm_bo bo)
        ret = bufmgr->backend->bo_export(bo);
        if (!ret) {
                _tbm_set_last_result(TBM_BO_ERROR_EXPORT_FAILED);
-               TBM_TRACE("error: bo(%p) tbm_key(%d)\n", bo, ret);
+               TBM_LOG_E("error: bo(%p) tbm_key(%d)\n", bo, ret);
                _tbm_bufmgr_mutex_unlock();
                return ret;
        }
@@ -1091,7 +1104,7 @@ tbm_bo_export_fd(tbm_bo bo)
        ret = bufmgr->backend->bo_export_fd(bo);
        if (ret < 0) {
                _tbm_set_last_result(TBM_BO_ERROR_EXPORT_FD_FAILED);
-               TBM_TRACE("error: bo(%p) tbm_fd(%d)\n", bo, ret);
+               TBM_LOG_E("error: bo(%p) tbm_fd(%d)\n", bo, ret);
                _tbm_bufmgr_mutex_unlock();
                return ret;
        }
@@ -1117,7 +1130,7 @@ tbm_bo_get_handle(tbm_bo bo, int device)
        bo_handle = bufmgr->backend->bo_get_handle(bo, device);
        if (bo_handle.ptr == NULL) {
                _tbm_set_last_result(TBM_BO_ERROR_GET_HANDLE_FAILED);
-               TBM_TRACE("error: bo(%p) bo_handle(%p)\n", bo, bo_handle.ptr);
+               TBM_LOG_E("error: bo(%p) bo_handle(%p)\n", bo, bo_handle.ptr);
                _tbm_bufmgr_mutex_unlock();
                return (tbm_bo_handle) NULL;
        }
@@ -1142,7 +1155,7 @@ tbm_bo_map(tbm_bo bo, int device, int opt)
 
        if (!_tbm_bo_lock(bo, device, opt)) {
                _tbm_set_last_result(TBM_BO_ERROR_LOCK_FAILED);
-               TBM_TRACE("error: fail to lock bo:%p)\n", bo);
+               TBM_LOG_E("error: fail to lock bo:%p)\n", bo);
                _tbm_bufmgr_mutex_unlock();
                return (tbm_bo_handle) NULL;
        }
@@ -1150,7 +1163,7 @@ tbm_bo_map(tbm_bo bo, int device, int opt)
        bo_handle = bufmgr->backend->bo_map(bo, device, opt);
        if (bo_handle.ptr == NULL) {
                _tbm_set_last_result(TBM_BO_ERROR_MAP_FAILED);
-               TBM_TRACE("error: fail to map bo:%p\n", bo);
+               TBM_LOG_E("error: fail to map bo:%p\n", bo);
                _tbm_bo_unlock(bo);
                _tbm_bufmgr_mutex_unlock();
                return (tbm_bo_handle) NULL;
@@ -1179,7 +1192,7 @@ tbm_bo_unmap(tbm_bo bo)
 
        ret = bufmgr->backend->bo_unmap(bo);
        if (!ret) {
-               TBM_TRACE("error: bo(%p) map_cnt(%d)\n", bo, bo->map_cnt);
+               TBM_LOG_E("error: bo(%p) map_cnt(%d)\n", bo, bo->map_cnt);
                _tbm_set_last_result(TBM_BO_ERROR_UNMAP_FAILED);
                _tbm_bufmgr_mutex_unlock();
                return ret;
@@ -1213,7 +1226,7 @@ tbm_bo_swap(tbm_bo bo1, tbm_bo bo2)
 
        if (bufmgr->backend->bo_size(bo1) != bufmgr->backend->bo_size(bo2)) {
                _tbm_set_last_result(TBM_BO_ERROR_SWAP_FAILED);
-               TBM_TRACE("error: bo1(%p) bo2(%p)\n", bo1, bo2);
+               TBM_LOG_E("error: bo1(%p) bo2(%p)\n", bo1, bo2);
                _tbm_bufmgr_mutex_unlock();
                return 0;
        }
@@ -1240,7 +1253,7 @@ tbm_bo_locked(tbm_bo bo)
        TBM_BUFMGR_RETURN_VAL_IF_FAIL(_tbm_bo_is_valid(bo), 0);
 
        if (bufmgr->lock_type == LOCK_TRY_NEVER) {
-               TBM_TRACE("bo(%p) lock_cnt(%d)\n", bo, bo->lock_cnt);
+               TBM_LOG_E("bo(%p) lock_cnt(%d)\n", bo, bo->lock_cnt);
                _tbm_bufmgr_mutex_unlock();
                return 0;
        }
@@ -1278,7 +1291,7 @@ tbm_bo_add_user_data(tbm_bo bo, unsigned long key,
 
        data = user_data_create(key, data_free_func);
        if (!data) {
-               TBM_TRACE("error: bo(%p) key(%lu)\n", bo, key);
+               TBM_LOG_E("error: bo(%p) key(%lu)\n", bo, key);
                _tbm_bufmgr_mutex_unlock();
                return 0;
        }
@@ -1439,16 +1452,8 @@ tbm_get_last_error(void)
 void
 tbm_bufmgr_debug_show(tbm_bufmgr bufmgr)
 {
-       tbm_bo bo = NULL, tmp_bo = NULL;
-       int bo_cnt = 0;
-       tbm_surface_h surf = NULL, tmp_surf = NULL;
-       int surf_cnt = 0;
-       int i;
-       char app_name[255] = {0,};
-       unsigned int pid = 0;
-       char title[255] = {0,};
-       char data[255] = {0,};
-       tbm_surface_debug_data *debug_old_data = NULL, *debug_tmp = NULL;
+       char app_name[255] = {0,}, title[512] = {0,};
+       tbm_surface_debug_data *debug_old_data = NULL;
 
        pthread_mutex_lock(&gLock);
 
@@ -1463,10 +1468,11 @@ tbm_bufmgr_debug_show(tbm_bufmgr bufmgr)
        _tbm_util_get_appname_brief(app_name);
        TBM_DEBUG("============TBM DEBUG: %s(%d)===========================\n",
                  app_name, getpid());
-       memset(app_name, 0x0, 255 * sizeof(char));
+
        snprintf(title, 255, "%s", "no  surface     refcnt  width  height  bpp  size    n_b  n_p  flags  format    app_name       ");
+
        if (!LIST_IS_EMPTY(&bufmgr->debug_key_list)) {
-               LIST_FOR_EACH_ENTRY_SAFE(debug_old_data, debug_tmp, &bufmgr->debug_key_list, item_link) {
+               LIST_FOR_EACH_ENTRY(debug_old_data, &bufmgr->debug_key_list, item_link) {
                        strncat(title, "  ", 3);
                        strncat(title, debug_old_data->key, strlen(debug_old_data->key) + 1);
                }
@@ -1474,21 +1480,28 @@ tbm_bufmgr_debug_show(tbm_bufmgr bufmgr)
 
        TBM_DEBUG("[tbm_surface information]\n");
        TBM_DEBUG("%s\n", title);
+
        /* show the tbm_surface information in surf_list */
        if (!LIST_IS_EMPTY(&bufmgr->surf_list)) {
-               char *value = NULL;
+               tbm_surface_h surf = NULL;
+               int surf_cnt = 0;
+
+               LIST_FOR_EACH_ENTRY(surf, &bufmgr->surf_list, item_link) {
+                       char data[512] = {0,};
+                       unsigned int pid;
+                       int i;
 
-               LIST_FOR_EACH_ENTRY_SAFE(surf, tmp_surf, &bufmgr->surf_list, item_link) {
                        pid = _tbm_surface_internal_get_debug_pid(surf);
                        if (!pid) {
                                /* if pid is null, set the self_pid */
                                pid = getpid();
                        }
 
+                       memset(app_name, 0x0, 255 * sizeof(char));
                        _tbm_util_get_appname_from_pid(pid, app_name);
                        _tbm_util_get_appname_brief(app_name);
 
-                       snprintf(data, 255, "%-2d  %-9p    %-4d  %-5d  %-6d  %-3d  %-6d   %-2d   %-2d    %-3d  %-8s  %-15s",
+                       snprintf(data, 255, "%-2d  %-9p    %-4d  %-5u  %-6u  %-3u  %-6u   %-2d   %-2d    %-3d  %-8s  %-15s",
                                  ++surf_cnt,
                                  surf,
                                  surf->refcnt,
@@ -1503,7 +1516,9 @@ tbm_bufmgr_debug_show(tbm_bufmgr bufmgr)
                                  app_name);
 
                        if (!LIST_IS_EMPTY(&bufmgr->debug_key_list)) {
-                               LIST_FOR_EACH_ENTRY_SAFE(debug_old_data, debug_tmp, &bufmgr->debug_key_list, item_link) {
+                               LIST_FOR_EACH_ENTRY(debug_old_data, &bufmgr->debug_key_list, item_link) {
+                                       char *value;
+
                                        strncat(data, "  ", 3);
 
                                        value = _tbm_surface_internal_get_debug_data(surf, debug_old_data->key);
@@ -1521,12 +1536,9 @@ tbm_bufmgr_debug_show(tbm_bufmgr bufmgr)
                                          surf->bos[i]->ref_cnt,
                                          bufmgr->backend->bo_size(surf->bos[i]) / 1024);
                        }
-
-                       memset(app_name, 0x0, 255 * sizeof(char));
                }
-       } else {
+       } else
                TBM_DEBUG("no tbm_surfaces.\n");
-       }
        TBM_DEBUG("\n");
 
        TBM_DEBUG("[tbm_bo information]\n");
@@ -1534,8 +1546,11 @@ tbm_bufmgr_debug_show(tbm_bufmgr bufmgr)
 
        /* show the tbm_bo information in bo_list */
        if (!LIST_IS_EMPTY(&bufmgr->bo_list)) {
-               LIST_FOR_EACH_ENTRY_SAFE(bo, tmp_bo, &bufmgr->bo_list, item_link) {
-                       TBM_DEBUG("%-4d%-11p   %-4d  %-6d     %-5d     %-4d    %-3d  %-11p\n",
+               int bo_cnt = 0;
+               tbm_bo bo = NULL;
+
+               LIST_FOR_EACH_ENTRY(bo, &bufmgr->bo_list, item_link) {
+                       TBM_DEBUG("%-4d%-11p   %-4d  %-6d     %-5d     %-4u    %-3d  %-11p\n",
                                  ++bo_cnt,
                                  bo,
                                  bo->ref_cnt,
@@ -1545,9 +1560,8 @@ tbm_bufmgr_debug_show(tbm_bufmgr bufmgr)
                                  bo->flags,
                                  bo->surface);
                }
-       } else {
+       } else
                TBM_DEBUG("no tbm_bos.\n");
-       }
        TBM_DEBUG("\n");
 
        TBM_DEBUG("===============================================================\n");
@@ -1574,28 +1588,30 @@ tbm_bufmgr_debug_trace(tbm_bufmgr bufmgr, int onoff)
 int
 tbm_bufmgr_debug_queue_dump(char *path, int count, int onoff)
 {
-       int w = 0, h = 0;
+       pthread_mutex_lock(&gLock);
 
-       TBM_RETURN_VAL_IF_FAIL(path != NULL, 0);
-       TBM_LOG_D("path=%s count=%d onoff=%d\n", path, count, onoff);
+       if (onoff == 0) {
+               TBM_LOG_D("count=%d onoff=%d\n", count, onoff);
+               b_dump_queue = 0;
+               tbm_surface_internal_dump_end();
+       } else {
+               int w, h;
 
-       pthread_mutex_lock(&gLock);
+               if (path == NULL) {
+                       TBM_LOG_E("path is null");
+                       pthread_mutex_unlock(&gLock);
+                       return 0;
+               }
+               TBM_LOG_D("path=%s count=%d onoff=%d\n", path, count, onoff);
 
-       if (onoff == 1) {
                if (_tbm_util_get_max_surface_size(&w, &h) == 0) {
-                       TBM_LOG_I("No tbm_surface.\n");
+                       TBM_LOG_E("Fail to get tbm_surface size.\n");
                        pthread_mutex_unlock(&gLock);
                        return 0;
                }
 
                tbm_surface_internal_dump_start(path, w, h, count);
                b_dump_queue = 1;
-       } else if (onoff == 0) {
-               tbm_surface_internal_dump_end();
-               b_dump_queue = 0;
-       } else {
-               pthread_mutex_unlock(&gLock);
-               return 0;
        }
 
        pthread_mutex_unlock(&gLock);
@@ -1605,8 +1621,8 @@ tbm_bufmgr_debug_queue_dump(char *path, int count, int onoff)
 int
 tbm_bufmgr_debug_dump_all(char *path)
 {
-       int w = 0, h = 0, count = 0;
-       tbm_surface_h surface = NULL, tmp = NULL;
+       int w, h, count = 0;
+       tbm_surface_h surface = NULL;
 
        TBM_RETURN_VAL_IF_FAIL(path != NULL, 0);
        TBM_LOG_D("path=%s\n", path);
@@ -1615,16 +1631,15 @@ tbm_bufmgr_debug_dump_all(char *path)
 
        count = _tbm_util_get_max_surface_size(&w, &h);
        if (count == 0) {
-               TBM_LOG_I("No tbm_surface.\n");
+               TBM_LOG_E("No tbm_surface.\n");
                pthread_mutex_unlock(&gLock);
                return 1;
        }
 
        tbm_surface_internal_dump_start(path, w, h, count);
 
-       LIST_FOR_EACH_ENTRY_SAFE(surface, tmp, &gBufMgr->surf_list, item_link) {
+       LIST_FOR_EACH_ENTRY(surface, &gBufMgr->surf_list, item_link)
                tbm_surface_internal_dump_buffer(surface, "dump_all");
-       }
 
        tbm_surface_internal_dump_end();
 
@@ -1673,7 +1688,7 @@ tbm_bufmgr_bind_native_display(tbm_bufmgr bufmgr, void *NativeDisplay)
 
        ret = bufmgr->backend->bufmgr_bind_native_display(bufmgr, NativeDisplay);
        if (!ret) {
-               TBM_TRACE("error: tbm_bufmgr(%p) NativeDisplay(%p)\n",
+               TBM_LOG_E("error: tbm_bufmgr(%p) NativeDisplay(%p)\n",
                                bufmgr, NativeDisplay);
                _tbm_bufmgr_mutex_unlock();
                return 0;