add trace messages for debugging 09/78209/7
authorRoman Marchenko <r.marchenko@samsung.com>
Fri, 1 Jul 2016 14:39:09 +0000 (17:39 +0300)
committerRoman Marchenko <r.marchenko@samsung.com>
Fri, 15 Jul 2016 08:32:29 +0000 (11:32 +0300)
Change-Id: I4cd3fe5ca0307dd95fb82195cb22f114ad41a598
Signed-off-by: Roman Marchenko <r.marchenko@samsung.com>
src/tbm_bufmgr.c
src/tbm_bufmgr_int.h
src/tbm_surface.c
src/tbm_surface_internal.c
src/tbm_surface_queue.c

index 494c07a..6c79d5b 100644 (file)
@@ -40,6 +40,10 @@ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 int bDebug;
 #endif
 
+#ifdef TRACE
+int bTrace;
+#endif
+
 #ifdef HAVE_DLOG
 int bDlog;
 #endif
@@ -77,6 +81,22 @@ _tbm_set_last_result(tbm_error_e err)
        tbm_last_error = err;
 }
 
+char * tbm_flag_to_str(int f) {
+       static char str[255];
+       int c = 0;
+       if (f == TBM_BO_DEFAULT)
+                snprintf(str, 255, "DEFAULT\n");
+       else {
+               if (f & TBM_BO_SCANOUT)
+                       c = snprintf(&str[c], 255, "SCANOUT,");
+               if (f & TBM_BO_NONCACHABLE)
+                       c = snprintf(&str[c], 255, "NONCACHABLE,");
+               if (f & TBM_BO_WC)
+                       c = snprintf(&str[c], 255, "WC");
+       }
+       return str;
+}
+
 /* LCOV_EXCL_START */
 static int last_chk_bo_cnt = 0;
 static void
@@ -524,14 +544,22 @@ tbm_bufmgr_init(int fd)
                bDebug = 0;
        }
 #endif
+
+#ifdef TRACE
+       env = getenv("TBM_TRACE");
+       if (env) {
+               bTrace = atoi(env);
+               TBM_LOG_D("TBM_TRACE=%s\n", env);
+       } else {
+               bTrace = 0;
+       }
+#endif
        /* LCOV_EXCL_STOP */
 
        /* initialize buffer manager */
        if (gBufMgr) {
                gBufMgr->ref_count++;
-
-               DBG("bufmgr:%p ref: fd=%d, ref_count:%d\n",
-                   gBufMgr, gBufMgr->fd, gBufMgr->ref_count);
+               TBM_TRACE("reuse  tbm_bufmgr(%p) ref_count(%d) fd(%d)\n", gBufMgr, gBufMgr->ref_count, gBufMgr->fd);
                pthread_mutex_unlock(&gLock);
                return gBufMgr;
        }
@@ -542,6 +570,7 @@ tbm_bufmgr_init(int fd)
        gBufMgr = calloc(1, sizeof(struct _tbm_bufmgr));
        if (!gBufMgr) {
                _tbm_set_last_result(TBM_BO_ERROR_HEAP_ALLOC_FAILED);
+               TBM_TRACE("error: fail to alloc bufmgr fd(%d)\n", fd);
                pthread_mutex_unlock(&gLock);
                return NULL;
        }
@@ -553,7 +582,6 @@ tbm_bufmgr_init(int fd)
                /* LCOV_EXCL_START */
                _tbm_set_last_result(TBM_BO_ERROR_LOAD_MODULE_FAILED);
                TBM_LOG_E("error : Fail to load bufmgr backend\n");
-
                free(gBufMgr);
                gBufMgr = NULL;
                pthread_mutex_unlock(&gLock);
@@ -597,6 +625,8 @@ tbm_bufmgr_init(int fd)
        DBG("BUFMGR_LOCK_TYPE=%s\n",
            env ? env : "default:once");
 
+       TBM_TRACE("create tbm_bufmgr(%p) ref_count(%d) fd(%d)\n", gBufMgr, gBufMgr->ref_count, fd);
+
        /* intialize bo_list */
        LIST_INITHEAD(&gBufMgr->bo_list);
 
@@ -628,8 +658,7 @@ tbm_bufmgr_deinit(tbm_bufmgr bufmgr)
 
        bufmgr->ref_count--;
        if (bufmgr->ref_count > 0) {
-               DBG("tizen bufmgr destroy: bufmgr:%p, ref_count:%d\n",
-                       bufmgr, bufmgr->ref_count);
+               TBM_TRACE("reduce a ref_count(%d) of tbm_bufmgr(%p)\n", bufmgr->ref_count, bufmgr);
                pthread_mutex_unlock(&gLock);
                return;
        }
@@ -661,8 +690,7 @@ tbm_bufmgr_deinit(tbm_bufmgr bufmgr)
 
        pthread_mutex_destroy(&bufmgr->lock);
 
-       DBG("tizen bufmgr destroy: bufmgr:%p\n",
-           bufmgr);
+       TBM_TRACE("destroy tbm_bufmgr(%p)\n", bufmgr);
 
        dlclose(bufmgr->module_data);
 
@@ -688,6 +716,8 @@ tbm_bo_size(tbm_bo bo)
 
        size = bufmgr->backend->bo_size(bo);
 
+       TBM_TRACE("bo(%p) size(%d)\n", bo, size);
+
        pthread_mutex_unlock(&bufmgr->lock);
 
        return size;
@@ -704,6 +734,8 @@ tbm_bo_ref(tbm_bo bo)
 
        _tbm_bo_ref(bo);
 
+       TBM_TRACE("bo(%p) ref_cnt(%d)\n", bo, bo->ref_cnt);
+
        pthread_mutex_unlock(&bufmgr->lock);
 
        return bo;
@@ -718,6 +750,8 @@ tbm_bo_unref(tbm_bo bo)
 
        pthread_mutex_lock(&bufmgr->lock);
 
+       TBM_TRACE("bo(%p) ref_cnt(%d)\n", bo, bo->ref_cnt - 1);
+
        _tbm_bo_unref(bo);
 
        pthread_mutex_unlock(&bufmgr->lock);
@@ -733,6 +767,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", size, tbm_flag_to_str(flags));
                _tbm_set_last_result(TBM_BO_ERROR_HEAP_ALLOC_FAILED);
                return NULL;
        }
@@ -746,6 +781,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", size, tbm_flag_to_str(flags));
                _tbm_set_last_result(TBM_BO_ERROR_BO_ALLOC_FAILED);
                free(bo);
                pthread_mutex_unlock(&bufmgr->lock);
@@ -756,6 +792,8 @@ tbm_bo_alloc(tbm_bufmgr bufmgr, int size, int flags)
        bo->flags = flags;
        bo->priv = bo_priv;
 
+       TBM_TRACE("bo(%p) size(%d) refcnt(%d), flag(%s)\n", bo, size, bo->ref_cnt, tbm_flag_to_str(bo->flags));
+
        LIST_INITHEAD(&bo->user_data_list);
 
        LIST_ADD(&bo->item_link, &bufmgr->bo_list);
@@ -781,6 +819,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);
                pthread_mutex_unlock(&bufmgr->lock);
                return NULL;
        }
@@ -791,6 +830,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_set_last_result(TBM_BO_ERROR_IMPORT_FAILED);
                free(bo);
                pthread_mutex_unlock(&bufmgr->lock);
@@ -800,9 +840,8 @@ tbm_bo_import(tbm_bufmgr bufmgr, unsigned int key)
        if (!LIST_IS_EMPTY(&bufmgr->bo_list)) {
                LIST_FOR_EACH_ENTRY_SAFE(bo2, tmp, &bufmgr->bo_list, item_link) {
                        if (bo2->priv == bo_priv) {
-                               DBG("find bo(%p, ref:%d key:%d) in list\n",
-                                   bo2, bo2->ref_cnt, key);
-
+                               TBM_TRACE("find bo(%p) ref(%d) key(%d) flag(%s) in list\n",
+                                                       bo2, bo2->ref_cnt, key, tbm_flag_to_str(bo2->flags));
                                bo2->ref_cnt++;
                                free(bo);
                                pthread_mutex_unlock(&bufmgr->lock);
@@ -819,6 +858,9 @@ tbm_bo_import(tbm_bufmgr bufmgr, unsigned int key)
        else
                bo->flags = TBM_BO_DEFAULT;
 
+       TBM_TRACE("import new bo(%p) ref(%d) key(%d) flag(%s) in list\n",
+                               bo, bo->ref_cnt, key, tbm_flag_to_str(bo->flags));
+
        LIST_INITHEAD(&bo->user_data_list);
 
        LIST_ADD(&bo->item_link, &bufmgr->bo_list);
@@ -844,6 +886,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);
                pthread_mutex_unlock(&bufmgr->lock);
                return NULL;
        }
@@ -854,6 +897,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_set_last_result(TBM_BO_ERROR_IMPORT_FD_FAILED);
                free(bo);
                pthread_mutex_unlock(&bufmgr->lock);
@@ -863,9 +907,8 @@ tbm_bo_import_fd(tbm_bufmgr bufmgr, tbm_fd fd)
        if (!LIST_IS_EMPTY(&bufmgr->bo_list)) {
                LIST_FOR_EACH_ENTRY_SAFE(bo2, tmp, &bufmgr->bo_list, item_link) {
                        if (bo2->priv == bo_priv) {
-                               DBG("find bo(%p, ref:%d, fd:%d) in list\n",
-                                   bo2, bo2->ref_cnt, fd);
-
+                               TBM_TRACE("find bo(%p) ref(%d) fd(%d) flag(%s) in list\n",
+                                                       bo2, bo2->ref_cnt, fd, tbm_flag_to_str(bo2->flags));
                                bo2->ref_cnt++;
                                free(bo);
                                pthread_mutex_unlock(&bufmgr->lock);
@@ -882,6 +925,9 @@ tbm_bo_import_fd(tbm_bufmgr bufmgr, tbm_fd fd)
        else
                bo->flags = TBM_BO_DEFAULT;
 
+       TBM_TRACE("import bo(%p) ref(%d) fd(%d) flag(%s)in list\n",
+                               bo, bo->ref_cnt, fd, tbm_flag_to_str(bo->flags));
+
        LIST_INITHEAD(&bo->user_data_list);
 
        LIST_ADD(&bo->item_link, &bufmgr->bo_list);
@@ -902,12 +948,17 @@ tbm_bo_export(tbm_bo bo)
        bufmgr = bo->bufmgr;
 
        pthread_mutex_lock(&bufmgr->lock);
+
        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);
                pthread_mutex_unlock(&bufmgr->lock);
                return ret;
        }
+
+       TBM_TRACE("bo(%p) tbm_key(%d)\n", bo, ret);
+
        pthread_mutex_unlock(&bufmgr->lock);
 
        return ret;
@@ -924,12 +975,17 @@ tbm_bo_export_fd(tbm_bo bo)
        bufmgr = bo->bufmgr;
 
        pthread_mutex_lock(&bufmgr->lock);
+
        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);
                pthread_mutex_unlock(&bufmgr->lock);
                return ret;
        }
+
+       TBM_TRACE("bo(%p) tbm_fd(%d)\n", bo, ret);
+
        pthread_mutex_unlock(&bufmgr->lock);
 
        return ret;
@@ -946,12 +1002,17 @@ tbm_bo_get_handle(tbm_bo bo, int device)
        bufmgr = bo->bufmgr;
 
        pthread_mutex_lock(&bufmgr->lock);
+
        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);
                pthread_mutex_unlock(&bufmgr->lock);
                return (tbm_bo_handle) NULL;
        }
+
+       TBM_TRACE("bo(%p) bo_handle(%p)\n", bo, bo_handle.ptr);
+
        pthread_mutex_unlock(&bufmgr->lock);
 
        return bo_handle;
@@ -971,8 +1032,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_LOG_E("error fail to lock bo:%p)\n",
-                       bo);
+               TBM_TRACE("error: fail to lock bo:%p)\n", bo);
                pthread_mutex_unlock(&bufmgr->lock);
                return (tbm_bo_handle) NULL;
        }
@@ -980,9 +1040,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_LOG_E("error fail to map bo:%p\n",
-                       bo);
-
+               TBM_TRACE("error: fail to map bo:%p\n", bo);
                _tbm_bo_unlock(bo);
                pthread_mutex_unlock(&bufmgr->lock);
                return (tbm_bo_handle) NULL;
@@ -991,6 +1049,8 @@ tbm_bo_map(tbm_bo bo, int device, int opt)
        /* increase the map_count */
        bo->map_cnt++;
 
+       TBM_TRACE("bo(%p) map_cnt(%d)\n", bo, bo->map_cnt);
+
        pthread_mutex_unlock(&bufmgr->lock);
 
        return bo_handle;
@@ -1010,7 +1070,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_set_last_result(TBM_BO_ERROR_UNMAP_FAILED);
                pthread_mutex_unlock(&bufmgr->lock);
                return ret;
@@ -1019,6 +1079,8 @@ tbm_bo_unmap(tbm_bo bo)
        /* decrease the map_count */
        bo->map_cnt--;
 
+       TBM_TRACE("bo(%p) map_cnt(%d)\n", bo, bo->map_cnt);
+
        _tbm_bo_unlock(bo);
 
        pthread_mutex_unlock(&bufmgr->lock);
@@ -1036,12 +1098,17 @@ tbm_bo_swap(tbm_bo bo1, tbm_bo bo2)
 
        pthread_mutex_lock(&bo1->bufmgr->lock);
 
+       TBM_TRACE("before: bo1(%p) bo2(%p)\n", bo1, bo2);
+
        if (bo1->bufmgr->backend->bo_size(bo1) != bo2->bufmgr->backend->bo_size(bo2)) {
                _tbm_set_last_result(TBM_BO_ERROR_SWAP_FAILED);
-               pthread_mutex_unlock(&bo1->bufmgr->lock);
+               TBM_TRACE("error: bo1(%p) bo2(%p)\n", bo1, bo2);
+       pthread_mutex_unlock(&bo1->bufmgr->lock);
                return 0;
        }
 
+       TBM_TRACE("after: bo1(%p) bo2(%p)\n", bo1, bo2);
+
        temp = bo1->priv;
        bo1->priv = bo2->priv;
        bo2->priv = temp;
@@ -1060,16 +1127,21 @@ tbm_bo_locked(tbm_bo bo)
 
        bufmgr = bo->bufmgr;
 
-       if (bufmgr->lock_type == LOCK_TRY_NEVER)
+       if (bufmgr->lock_type == LOCK_TRY_NEVER) {
+               TBM_TRACE("bo(%p) lock_cnt(%d)\n", bo, bo->lock_cnt);
                return 0;
+       }
 
        pthread_mutex_lock(&bufmgr->lock);
 
+
        if (bo->lock_cnt > 0) {
+               TBM_TRACE("error: bo(%p) lock_cnt(%d)\n", bo, bo->lock_cnt);
                pthread_mutex_unlock(&bufmgr->lock);
                return 1;
        }
 
+       TBM_TRACE("bo(%p) lock_cnt(%d)\n", bo, bo->lock_cnt);
        pthread_mutex_unlock(&bufmgr->lock);
 
        return 0;
@@ -1086,14 +1158,17 @@ tbm_bo_add_user_data(tbm_bo bo, unsigned long key,
        /* check if the data according to the key exist if so, return false. */
        data = user_data_lookup(&bo->user_data_list, key);
        if (data) {
-               TBM_LOG_W("waring user data already exist. key:%ld\n",
-                       key);
+               TBM_TRACE("warning: user data already exist key(%ld)\n", key);
                return 0;
        }
 
        data = user_data_create(key, data_free_func);
-       if (!data)
+       if (!data) {
+               TBM_TRACE("error: bo(%p) key(%lu)\n", bo, key);
                return 0;
+       }
+
+       TBM_TRACE("bo(%p) key(%lu) data(%p)\n", bo, key, data->data);
 
        LIST_ADD(&data->item_link, &bo->user_data_list);
 
@@ -1107,18 +1182,24 @@ tbm_bo_set_user_data(tbm_bo bo, unsigned long key, void *data)
 
        tbm_user_data *old_data;
 
-       if (LIST_IS_EMPTY(&bo->user_data_list))
+       if (LIST_IS_EMPTY(&bo->user_data_list)) {
+               TBM_TRACE("error: bo(%p) key(%lu)\n", bo, key);
                return 0;
+       }
 
        old_data = user_data_lookup(&bo->user_data_list, key);
-       if (!old_data)
+       if (!old_data) {
+               TBM_TRACE("error: bo(%p) key(%lu)\n", bo, key);
                return 0;
+       }
 
        if (old_data->data && old_data->free_func)
                old_data->free_func(old_data->data);
 
        old_data->data = data;
 
+       TBM_TRACE("bo(%p) key(%lu) data(%p)\n", bo, key, old_data->data);
+
        return 1;
 }
 
@@ -1129,17 +1210,22 @@ tbm_bo_get_user_data(tbm_bo bo, unsigned long key, void **data)
 
        tbm_user_data *old_data;
 
-       if (!data || LIST_IS_EMPTY(&bo->user_data_list))
+       if (!data || LIST_IS_EMPTY(&bo->user_data_list)) {
+               TBM_TRACE("error: bo(%p) key(%lu)\n", bo, key);
                return 0;
+       }
 
        old_data = user_data_lookup(&bo->user_data_list, key);
        if (!old_data) {
+               TBM_TRACE("error: bo(%p) key(%lu)\n", bo, key);
                *data = NULL;
                return 0;
        }
 
        *data = old_data->data;
 
+       TBM_TRACE("bo(%p) key(%lu) data(%p)\n", bo, key, old_data->data);
+
        return 1;
 }
 
@@ -1150,12 +1236,18 @@ tbm_bo_delete_user_data(tbm_bo bo, unsigned long key)
 
        tbm_user_data *old_data = (void *)0;
 
-       if (LIST_IS_EMPTY(&bo->user_data_list))
+       if (LIST_IS_EMPTY(&bo->user_data_list)) {
+               TBM_TRACE("error: bo(%p) key(%lu)\n", bo, key);
                return 0;
+       }
 
        old_data = user_data_lookup(&bo->user_data_list, key);
-       if (!old_data)
+       if (!old_data) {
+               TBM_TRACE("error: bo(%p) key(%lu)\n", bo, key);
                return 0;
+       }
+
+       TBM_TRACE("bo(%p) key(%lu) data(%p)\n", bo, key, old_data->data);
 
        user_data_delete(old_data);
 
@@ -1175,6 +1267,8 @@ tbm_bufmgr_get_capability(tbm_bufmgr bufmgr)
        if (bufmgr->backend->bo_import_fd && bufmgr->backend->bo_export_fd)
                capability |= TBM_BUFMGR_CAPABILITY_SHARE_FD;
 
+       TBM_TRACE("tbm_bufmgr(%p) capability(%d)\n", bufmgr, capability);
+
        return capability;
 }
 
@@ -1183,6 +1277,8 @@ tbm_bo_get_flags(tbm_bo bo)
 {
        TBM_RETURN_VAL_IF_FAIL(_tbm_bo_is_valid(bo), 0);
 
+       TBM_TRACE("bo(%p)\n", bo);
+
        return bo->flags;
 }
 
@@ -1287,8 +1383,10 @@ tbm_bufmgr_debug_show(tbm_bufmgr bufmgr)
 void
 tbm_bufmgr_debug_trace(tbm_bufmgr bufmgr, int onoff)
 {
+#ifdef TRACE
        TBM_LOG_D("bufmgr=%p onoff=%d\n", bufmgr, onoff);
-       TBM_LOG_D("Not implemented yet.\n");
+       bTrace = onoff;
+#endif
 }
 
 /* internal function */
@@ -1312,16 +1410,20 @@ tbm_bufmgr_bind_native_display(tbm_bufmgr bufmgr, void *NativeDisplay)
        pthread_mutex_lock(&bufmgr->lock);
 
        if (!bufmgr->backend->bufmgr_bind_native_display) {
+               TBM_TRACE("error: tbm_bufmgr(%p) NativeDisplay(%p)\n", bufmgr, NativeDisplay);
                pthread_mutex_unlock(&bufmgr->lock);
                return 1;
        }
 
        ret = bufmgr->backend->bufmgr_bind_native_display(bufmgr, NativeDisplay);
        if (!ret) {
+               TBM_TRACE("error: tbm_bufmgr(%p) NativeDisplay(%p)\n", bufmgr, NativeDisplay);
                pthread_mutex_unlock(&bufmgr->lock);
                return 0;
        }
 
+       TBM_TRACE("tbm_bufmgr(%p) NativeDisplay(%p)\n", bufmgr, NativeDisplay);
+
        pthread_mutex_unlock(&bufmgr->lock);
 
        return 1;
index 3a54cb0..59d4358 100644 (file)
@@ -62,6 +62,11 @@ extern int bDebug;
 #define DBG_LOCK(...)
 #endif /* DEBUG */
 
+#define TRACE
+#ifdef TRACE
+extern int bTrace;
+#endif /* TRACE */
+
 #ifdef HAVE_DLOG
 #include <dlog.h>
 
@@ -117,12 +122,31 @@ extern int bDlog;
                fprintf(stderr, "[TBM:DEBUG(%d)] " fmt, getpid(), ##__VA_ARGS__);\
        } \
 }
+
+#ifdef TRACE
+#define TBM_TRACE(fmt, ...) {\
+       if (bDlog) {\
+               if (bTrace&0x1) LOGE("[TBM:TRACE] " fmt, ##__VA_ARGS__);\
+       } \
+       else {\
+               if (bTrace&0x1) fprintf(stderr, "[TBM:TRACE(%d)(%s:%d)] " fmt, getpid(), __func__, __LINE__, ##__VA_ARGS__);\
+       } \
+}
+#else
+#define TBM_TRACE(fmt, ...)
+#endif /* TRACE */
+
 #else
 #define TBM_LOG_D(fmt, ...)   fprintf(stderr, "[TBM:D(%d)(%s:%d)] " fmt, getpid(), __func__, __LINE__, ##__VA_ARGS__)
 #define TBM_LOG_I(fmt, ...)   fprintf(stderr, "[TBM:I(%d)(%s:%d)] " fmt, getpid(), __func__, __LINE__, ##__VA_ARGS__)
 #define TBM_LOG_W(fmt, ...)   fprintf(stderr, "[TBM:W(%d)(%s:%d)] " fmt, getpid(), __func__, __LINE__, ##__VA_ARGS__)
 #define TBM_LOG_E(fmt, ...)   fprintf(stderr, "[TBM:E(%d)(%s:%d)] " fmt, getpid(), __func__, __LINE__, ##__VA_ARGS__)
 #define TBM_DEBUG(fmt, ...)   fprintf(stderr, "[TBM:DEBUG(%d)] " fmt, getpid(), ##__VA_ARGS__)
+#ifdef TRACE
+#define TBM_TRACE(fmt, ...)   { if (bTrace&0x1) fprintf(stderr, "[TBM:TRACE(%d)(%s:%d)] " fmt, getpid(), __func__, __LINE__, ##__VA_ARGS__); }
+#else
+#define TBM_TRACE(fmt, ...)
+#endif /* TRACE */
 #endif /* HAVE_DLOG */
 
 /* check condition */
index 669f2e3..4a36500 100644 (file)
@@ -37,6 +37,8 @@ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 int
 tbm_surface_query_formats(uint32_t **formats, uint32_t *num)
 {
+       TBM_TRACE("\n");
+
        if (!tbm_surface_internal_query_supported_formats(formats, num))
                return TBM_SURFACE_ERROR_INVALID_OPERATION;
 
@@ -46,6 +48,8 @@ tbm_surface_query_formats(uint32_t **formats, uint32_t *num)
 tbm_surface_h
 tbm_surface_create(int width, int height, tbm_format format)
 {
+       TBM_TRACE("width(%d) height(%d)\n", width, height);
+
        if (!(width > 0) || !(height > 0)) {
 #ifdef HAVE_CAPI_0_1_1
                set_last_result(TBM_SURFACE_ERROR_INVALID_PARAMETER);
@@ -72,6 +76,8 @@ tbm_surface_create(int width, int height, tbm_format format)
 int
 tbm_surface_destroy(tbm_surface_h surface)
 {
+       TBM_TRACE("tbm_surface(%p)\n", surface);
+
        if (!tbm_surface_internal_is_valid(surface))
                return TBM_SURFACE_ERROR_INVALID_PARAMETER;
 
@@ -83,6 +89,8 @@ tbm_surface_destroy(tbm_surface_h surface)
 int
 tbm_surface_map(tbm_surface_h surface, int opt, tbm_surface_info_s *info)
 {
+       TBM_TRACE("tbm_surface(%p)\n", surface);
+
        TBM_RETURN_VAL_IF_FAIL(tbm_surface_internal_is_valid(surface), TBM_SURFACE_ERROR_INVALID_PARAMETER);
        TBM_RETURN_VAL_IF_FAIL(info != NULL, TBM_SURFACE_ERROR_INVALID_PARAMETER);
 
@@ -98,6 +106,8 @@ tbm_surface_map(tbm_surface_h surface, int opt, tbm_surface_info_s *info)
 int
 tbm_surface_unmap(tbm_surface_h surface)
 {
+       TBM_TRACE("tbm_surface(%p)\n", surface);
+
        TBM_RETURN_VAL_IF_FAIL(tbm_surface_internal_is_valid(surface), TBM_SURFACE_ERROR_INVALID_PARAMETER);
 
        tbm_surface_internal_unmap(surface);
@@ -108,6 +118,8 @@ tbm_surface_unmap(tbm_surface_h surface)
 int
 tbm_surface_get_info(tbm_surface_h surface, tbm_surface_info_s *info)
 {
+       TBM_TRACE("tbm_surface(%p)\n", surface);
+
        TBM_RETURN_VAL_IF_FAIL(tbm_surface_internal_is_valid(surface), TBM_SURFACE_ERROR_INVALID_PARAMETER);
        TBM_RETURN_VAL_IF_FAIL(info != NULL, TBM_SURFACE_ERROR_INVALID_PARAMETER);
 
@@ -123,6 +135,8 @@ tbm_surface_get_info(tbm_surface_h surface, tbm_surface_info_s *info)
 int
 tbm_surface_get_width(tbm_surface_h surface)
 {
+       TBM_TRACE("tbm_surface(%p)\n", surface);
+
        TBM_RETURN_VAL_IF_FAIL(tbm_surface_internal_is_valid(surface), TBM_SURFACE_ERROR_INVALID_PARAMETER);
 
        return tbm_surface_internal_get_width(surface);
@@ -131,6 +145,8 @@ tbm_surface_get_width(tbm_surface_h surface)
 int
 tbm_surface_get_height(tbm_surface_h surface)
 {
+       TBM_TRACE("tbm_surface(%p)\n", surface);
+
        TBM_RETURN_VAL_IF_FAIL(tbm_surface_internal_is_valid(surface), TBM_SURFACE_ERROR_INVALID_PARAMETER);
 
        return tbm_surface_internal_get_height(surface);
@@ -139,6 +155,8 @@ tbm_surface_get_height(tbm_surface_h surface)
 tbm_format
 tbm_surface_get_format(tbm_surface_h surface)
 {
+       TBM_TRACE("tbm_surface(%p)\n", surface);
+
        if (!tbm_surface_internal_is_valid(surface)) {
 #ifdef HAVE_CAPI_0_1_1
                set_last_result(TBM_SURFACE_ERROR_INVALID_PARAMETER);
index c605f5d..4d59884 100644 (file)
@@ -302,15 +302,20 @@ tbm_surface_internal_is_valid(tbm_surface_h surface)
 {
        tbm_surface_h old_data = NULL, tmp = NULL;
 
-       if (surface == NULL || g_surface_bufmgr == NULL)
+       if (surface == NULL || g_surface_bufmgr == NULL) {
+               TBM_TRACE("error: tbm_surface(%p)\n", surface);
                return 0;
+       }
 
        if (!LIST_IS_EMPTY(&g_surface_bufmgr->surf_list)) {
                LIST_FOR_EACH_ENTRY_SAFE(old_data, tmp, &g_surface_bufmgr->surf_list, item_link) {
-                       if (old_data == surface)
+                       if (old_data == surface) {
+                               TBM_TRACE("tbm_surface(%p)\n", surface);
                                return 1;
+                       }
                }
        }
+       TBM_TRACE("error: tbm_surface(%p)\n", surface);
        return 0;
 }
 
@@ -331,12 +336,15 @@ tbm_surface_internal_query_supported_formats(uint32_t **formats,
        mgr = g_surface_bufmgr;
 
        if (!mgr->backend->surface_supported_format) {
+               TBM_TRACE("error: tbm_bufmgr(%p)\n", g_surface_bufmgr);
                _tbm_surface_mutex_unlock();
                return 0;
        }
 
        ret = mgr->backend->surface_supported_format(formats, num);
 
+       TBM_TRACE("tbm_bufmgr(%p) format num(%d)\n", g_surface_bufmgr, *num);
+
        _tbm_surface_mutex_unlock();
 
        return ret;
@@ -418,12 +426,15 @@ tbm_surface_internal_get_num_planes(tbm_format format)
                break;
        }
 
+       TBM_TRACE("tbm_format(%s) num_planes(%d)\n", _tbm_surface_internal_format_to_str(format), num_planes);
+
        return num_planes;
 }
 
 int
 tbm_surface_internal_get_bpp(tbm_format format)
 {
+
        int bpp = 0;
 
        switch (format) {
@@ -510,6 +521,8 @@ tbm_surface_internal_get_bpp(tbm_format format)
                break;
        }
 
+       TBM_TRACE("tbm_format(%s) bpp(%d)\n", _tbm_surface_internal_format_to_str(format), bpp);
+
        return bpp;
 }
 
@@ -538,11 +551,15 @@ tbm_surface_internal_create_with_flags(int width, int height,
 
        mgr = g_surface_bufmgr;
        if (!TBM_BUFMGR_IS_VALID(mgr)) {
+               TBM_TRACE("error: width(%d) height(%d) format(%s) flags(%d)\n",
+                               width, height, _tbm_surface_internal_format_to_str(format), flags);
                _tbm_surface_mutex_unlock();
                return NULL;
        }
        surf = calloc(1, sizeof(struct _tbm_surface));
        if (!surf) {
+               TBM_TRACE("error: width(%d) height(%d) format(%s) flags(%d)\n",
+                               width, height, _tbm_surface_internal_format_to_str(format), flags);
                _tbm_surface_mutex_unlock();
                return NULL;
        }
@@ -631,6 +648,9 @@ tbm_surface_internal_create_with_flags(int width, int height,
 
        }
 
+       TBM_TRACE("width(%d) height(%d) format(%s) flags(%d) tbm_surface(%p)\n", width, height,
+                       _tbm_surface_internal_format_to_str(format), flags, surf);
+
        LIST_INITHEAD(&surf->user_data_list);
 
        LIST_ADD(&surf->item_link, &mgr->surf_list);
@@ -640,6 +660,10 @@ tbm_surface_internal_create_with_flags(int width, int height,
        return surf;
 
 alloc_fail:
+
+       TBM_TRACE("error: width(%d) height(%d) format(%s) flags(%d)\n",
+                       width, height, _tbm_surface_internal_format_to_str(format), flags);
+
        for (j = 0; j < i; j++) {
                if (surf->bos[j])
                        tbm_bo_unref(surf->bos[j]);
@@ -678,12 +702,16 @@ tbm_surface_internal_create_with_bos(tbm_surface_info_s *info,
 
        mgr = g_surface_bufmgr;
        if (!TBM_BUFMGR_IS_VALID(mgr)) {
+               TBM_TRACE("error: width(%d) height(%d) format(%s) bo_num(%d)\n",
+                               info->width, info->height, _tbm_surface_internal_format_to_str(info->format), num);
                _tbm_surface_mutex_unlock();
                return NULL;
        }
 
        surf = calloc(1, sizeof(struct _tbm_surface));
        if (!surf) {
+               TBM_TRACE("error: width(%d) height(%d) format(%s) bo_num(%d)\n",
+                               info->width, info->height, _tbm_surface_internal_format_to_str(info->format), num);
                _tbm_surface_mutex_unlock();
                return NULL;
        }
@@ -732,6 +760,9 @@ tbm_surface_internal_create_with_bos(tbm_surface_info_s *info,
                _tbm_bo_set_surface(bos[i], surf);
        }
 
+       TBM_TRACE("tbm_surface(%p) width(%d) height(%d) format(%s) bo_num(%d)\n", surf,
+                       info->width, info->height, _tbm_surface_internal_format_to_str(info->format), num);
+
        LIST_INITHEAD(&surf->user_data_list);
 
        LIST_ADD(&surf->item_link, &mgr->surf_list);
@@ -740,6 +771,8 @@ tbm_surface_internal_create_with_bos(tbm_surface_info_s *info,
 
        return surf;
 bail1:
+       TBM_TRACE("error: width(%d) height(%d) format(%s) bo_num(%d)\n",
+                               info->width, info->height, _tbm_surface_internal_format_to_str(info->format), num);
        for (i = 0; i < num; i++) {
                if (surf->bos[i]) {
                        tbm_bo_unref(surf->bos[i]);
@@ -771,10 +804,13 @@ tbm_surface_internal_destroy(tbm_surface_h surface)
        surface->refcnt--;
 
        if (surface->refcnt > 0) {
+               TBM_TRACE("reduce a refcnt(%d) of tbm_surface(%p)\n", surface->refcnt, surface);
                _tbm_surface_mutex_unlock();
                return;
        }
 
+       TBM_TRACE("destroy tbm_surface(%p) refcnt(%d)\n", surface, surface->refcnt);
+
        if (surface->refcnt == 0)
                _tbm_surface_internal_destroy(surface);
 
@@ -790,6 +826,8 @@ tbm_surface_internal_ref(tbm_surface_h surface)
 
        surface->refcnt++;
 
+       TBM_TRACE("tbm_surface(%p) refcnt(%d)\n", surface, surface->refcnt);
+
        _tbm_surface_mutex_unlock();
 }
 
@@ -803,10 +841,13 @@ tbm_surface_internal_unref(tbm_surface_h surface)
        surface->refcnt--;
 
        if (surface->refcnt > 0) {
+               TBM_TRACE("reduce a refcnt(%d) of tbm_surface(%p)\n", surface->refcnt, surface);
                _tbm_surface_mutex_unlock();
                return;
        }
 
+       TBM_TRACE("destroy tbm_surface(%p) refcnt(%d)\n", surface, surface->refcnt);
+
        if (surface->refcnt == 0)
                _tbm_surface_internal_destroy(surface);
 
@@ -826,6 +867,8 @@ tbm_surface_internal_get_num_bos(tbm_surface_h surface)
        surf = (struct _tbm_surface *)surface;
        num = surf->num_bos;
 
+       TBM_TRACE("tbm_surface(%p) num_bos(%d)\n", surface, num);
+
        _tbm_surface_mutex_unlock();
 
        return num;
@@ -845,6 +888,8 @@ tbm_surface_internal_get_bo(tbm_surface_h surface, int bo_idx)
        surf = (struct _tbm_surface *)surface;
        bo = surf->bos[bo_idx];
 
+       TBM_TRACE("tbm_surface(%p) bo_idx(%d) tbm_bo(%p)\n", surface, bo_idx, bo);
+
        _tbm_surface_mutex_unlock();
 
        return bo;
@@ -863,6 +908,8 @@ tbm_surface_internal_get_size(tbm_surface_h surface)
        surf = (struct _tbm_surface *)surface;
        size = surf->info.size;
 
+       TBM_TRACE("tbm_surface(%p) size(%d)\n", surface, size);
+
        _tbm_surface_mutex_unlock();
 
        return size;
@@ -882,6 +929,7 @@ tbm_surface_internal_get_plane_data(tbm_surface_h surface, int plane_idx,
        surf = (struct _tbm_surface *)surface;
 
        if (plane_idx >= surf->info.num_planes) {
+               TBM_TRACE("error: tbm_surface(%p) plane_idx(%d)\n", surface, plane_idx);
                _tbm_surface_mutex_unlock();
                return 0;
        }
@@ -895,6 +943,10 @@ tbm_surface_internal_get_plane_data(tbm_surface_h surface, int plane_idx,
        if (pitch)
                *pitch = surf->info.planes[plane_idx].stride;
 
+       TBM_TRACE("tbm_surface(%p) plane_idx(%d) size(%d) offset(%d) pitch(%d)\n", surface, plane_idx,
+                               surf->info.planes[plane_idx].size, surf->info.planes[plane_idx].offset,
+                               surf->info.planes[plane_idx].stride);
+
        _tbm_surface_mutex_unlock();
 
        return 1;
@@ -931,6 +983,7 @@ tbm_surface_internal_get_info(tbm_surface_h surface, int opt,
                                for (j = 0; j < i; j++)
                                        tbm_bo_unmap(surf->bos[j]);
 
+                               TBM_TRACE("error: tbm_surface(%p) opt(%d) map(%d)\n", surface, opt, map);
                                _tbm_surface_mutex_unlock();
                                return 0;
                        }
@@ -950,6 +1003,8 @@ tbm_surface_internal_get_info(tbm_surface_h surface, int opt,
                                              surf->info.planes[i].offset;
        }
 
+       TBM_TRACE("tbm_surface(%p) opt(%d) map(%d)\n", surface, opt, map);
+
        _tbm_surface_mutex_unlock();
 
        return 1;
@@ -970,6 +1025,8 @@ tbm_surface_internal_unmap(tbm_surface_h surface)
        for (i = 0; i < surf->num_bos; i++)
                tbm_bo_unmap(surf->bos[i]);
 
+       TBM_TRACE("tbm_surface(%p)\n", surface);
+
        _tbm_surface_mutex_unlock();
 }
 
@@ -986,6 +1043,8 @@ tbm_surface_internal_get_width(tbm_surface_h surface)
        surf = (struct _tbm_surface *)surface;
        width = surf->info.width;
 
+       TBM_TRACE("tbm_surface(%p) width(%d)\n", surface, width);
+
        _tbm_surface_mutex_unlock();
 
        return width;
@@ -1004,6 +1063,8 @@ tbm_surface_internal_get_height(tbm_surface_h surface)
        surf = (struct _tbm_surface *)surface;
        height = surf->info.height;
 
+       TBM_TRACE("tbm_surface(%p) height(%d)\n", surface, height);
+
        _tbm_surface_mutex_unlock();
 
        return height;
@@ -1023,6 +1084,8 @@ tbm_surface_internal_get_format(tbm_surface_h surface)
        surf = (struct _tbm_surface *)surface;
        format = surf->info.format;
 
+       TBM_TRACE("tbm_surface(%p) format(%s)\n", surface, _tbm_surface_internal_format_to_str(format));
+
        _tbm_surface_mutex_unlock();
 
        return format;
@@ -1041,6 +1104,8 @@ tbm_surface_internal_get_plane_bo_idx(tbm_surface_h surface, int plane_idx)
        surf = (struct _tbm_surface *)surface;
        bo_idx = surf->planes_bo_idx[plane_idx];
 
+       TBM_TRACE("tbm_surface(%p) plane_idx(%d) bo_idx(%d)\n", surface, plane_idx, bo_idx);
+
        _tbm_surface_mutex_unlock();
 
        return bo_idx;
@@ -1057,13 +1122,17 @@ tbm_surface_internal_add_user_data(tbm_surface_h surface, unsigned long key,
        /* check if the data according to the key exist if so, return false. */
        data = user_data_lookup(&surface->user_data_list, key);
        if (data) {
-               TBM_LOG_W("waring user data already exist. key:%ld\n", key);
+               TBM_TRACE("warning: user data already exist tbm_surface(%p) key(%lu)\n", surface, key);
                return 0;
        }
 
        data = user_data_create(key, data_free_func);
-       if (!data)
+       if (!data) {
+               TBM_TRACE("error: tbm_surface(%p) key(%lu)\n", surface, key);
                return 0;
+       }
+
+       TBM_TRACE("tbm_surface(%p) key(%lu) data(%p)\n", surface, key, data);
 
        LIST_ADD(&data->item_link, &surface->user_data_list);
 
@@ -1078,18 +1147,24 @@ tbm_surface_internal_set_user_data(tbm_surface_h surface, unsigned long key,
 
        tbm_user_data *old_data;
 
-       if (LIST_IS_EMPTY(&surface->user_data_list))
+       if (LIST_IS_EMPTY(&surface->user_data_list)) {
+               TBM_TRACE("error: tbm_surface(%p) key(%lu)\n", surface, key);
                return 0;
+       }
 
        old_data = user_data_lookup(&surface->user_data_list, key);
-       if (!old_data)
+       if (!old_data) {
+               TBM_TRACE("error: tbm_surface(%p) key(%lu)\n", surface, key);
                return 0;
+       }
 
        if (old_data->data && old_data->free_func)
                old_data->free_func(old_data->data);
 
        old_data->data = data;
 
+       TBM_TRACE("tbm_surface(%p) key(%lu) data(%p)\n", surface, key, old_data->data);
+
        return 1;
 }
 
@@ -1101,17 +1176,22 @@ tbm_surface_internal_get_user_data(tbm_surface_h surface, unsigned long key,
 
        tbm_user_data *old_data;
 
-       if (!data || LIST_IS_EMPTY(&surface->user_data_list))
+       if (!data || LIST_IS_EMPTY(&surface->user_data_list)) {
+               TBM_TRACE("error: tbm_surface(%p) key(%lu)\n", surface, key);
                return 0;
+       }
 
        old_data = user_data_lookup(&surface->user_data_list, key);
        if (!old_data) {
+               TBM_TRACE("error: tbm_surface(%p) key(%lu)\n", surface, key);
                *data = NULL;
                return 0;
        }
 
        *data = old_data->data;
 
+       TBM_TRACE("tbm_surface(%p) key(%lu) data(%p)\n", surface, key, old_data->data);
+
        return 1;
 }
 
@@ -1123,12 +1203,18 @@ tbm_surface_internal_delete_user_data(tbm_surface_h surface,
 
        tbm_user_data *old_data = (void *)0;
 
-       if (LIST_IS_EMPTY(&surface->user_data_list))
+       if (LIST_IS_EMPTY(&surface->user_data_list)) {
+               TBM_TRACE("error: tbm_surface(%p) key(%lu)\n", surface, key);
                return 0;
+       }
 
        old_data = user_data_lookup(&surface->user_data_list, key);
-       if (!old_data)
+       if (!old_data) {
+               TBM_TRACE("error: tbm_surface(%p) key(%lu)\n", surface, key);
                return 0;
+       }
+
+       TBM_TRACE("tbm_surface(%p) key(%lu) data(%p)\n", surface, key, old_data->data);
 
        user_data_delete(old_data);
 
index ac75f52..16eeb85 100644 (file)
@@ -38,12 +38,16 @@ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 
 #define TBM_QUEUE_DEBUG 0
 
+#ifdef TRACE
+#define TBM_QUEUE_TRACE(fmt, ...)  { if (bTrace&0x1) fprintf(stderr, "[TBM:TRACE(%d)(%s:%d)] " fmt, getpid(), __func__, __LINE__, ##__VA_ARGS__); }
+#else
+#define TBM_QUEUE_TRACE(fmt, ...)
+#endif /* TRACE */
+
 #if TBM_QUEUE_DEBUG
-#define TBM_QUEUE_TRACE(fmt, ...)  fprintf(stderr, "[TBM(%d):%s] " fmt, getpid(), __func__, ##__VA_ARGS__)
 #define TBM_LOCK() TBM_LOG_D("[LOCK] %s:%d surface:%p\n", __func__, __LINE__, surface_queue)
 #define TBM_UNLOCK() TBM_LOG_D("[UNLOCK] %s:%d surface:%p\n", __func__, __LINE__, surface_queue)
 #else
-#define TBM_QUEUE_TRACE(fmt, ...)
 #define TBM_LOCK()
 #define TBM_UNLOCK()
 #endif