tbm_bufmgr_debug: change signature of tbm_bufmgr_debug_tbm_info_get
[platform/core/uifw/libtbm.git] / src / tbm_bufmgr_int.h
index 2305e42..92262fd 100644 (file)
@@ -32,10 +32,12 @@ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 #ifndef _TBM_BUFMGR_INT_H_
 #define _TBM_BUFMGR_INT_H_
 
+#include <sys/time.h>
 #include <unistd.h>
 #include <limits.h>
 #include <stdlib.h>
 #include <stdio.h>
+#include <string.h>
 #include <sys/ioctl.h>
 #include <sys/types.h>
 #include <sys/stat.h>
@@ -51,19 +53,125 @@ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 #include <tbm_bufmgr_backend.h>
 #include <tbm_surface_queue.h>
 
+#define DEBUG
+#ifdef DEBUG
+extern int bDebug;
+
+#define TBM_DBG(...) { if (bDebug&0x1) TBM_LOG_D(__VA_ARGS__); }
+#define TBM_DBG_LOCK(...) { if (bDebug&0x2) TBM_LOG_D(__VA_ARGS__); }
+#else
+#define TBM_DBG(...)
+#define TBM_DBG_LOCK(...)
+#endif /* DEBUG */
+
+#define TRACE
+#ifdef TRACE
+extern int bTrace;
+#endif /* TRACE */
+
+extern int b_dump_queue;
+
+#ifdef HAVE_DLOG
+#include <dlog.h>
+
+extern int bDlog;
+
+#ifdef LOG_TAG
+#undef LOG_TAG
+#endif
+
+#define LOG_TAG "TBM"
+
+#define TBM_LOG_D(fmt, ...) {\
+       if (bDlog) {\
+               LOGD("[TBM:D] " fmt, ##__VA_ARGS__);\
+       } \
+       else {\
+               fprintf(stderr, "[TBM:D(%d)(%s:%d)] " fmt, getpid(), __func__, __LINE__, ##__VA_ARGS__);\
+       } \
+}
+
+#define TBM_LOG_I(fmt, ...) {\
+       if (bDlog) {\
+               LOGI("[TBM:I] " fmt, ##__VA_ARGS__);\
+       } \
+       else {\
+               fprintf(stderr, "[TBM:I(%d)(%s:%d)] " fmt, getpid(), __func__, __LINE__, ##__VA_ARGS__);\
+       } \
+}
+
+#define TBM_LOG_W(fmt, ...) {\
+       if (bDlog) {\
+               LOGW("[TBM:W] " fmt, ##__VA_ARGS__);\
+       } \
+       else {\
+               fprintf(stderr, "[TBM:W(%d)(%s:%d)] " fmt, getpid(), __func__, __LINE__, ##__VA_ARGS__);\
+       } \
+}
+
+#define TBM_LOG_E(fmt, ...) {\
+       if (bDlog) {\
+               LOGE("[TBM:E] " fmt, ##__VA_ARGS__);\
+       } \
+       else {\
+               fprintf(stderr, "[TBM:E(%d)(%s:%d)] " fmt, getpid(), __func__, __LINE__, ##__VA_ARGS__);\
+       } \
+}
+
+#define TBM_DEBUG(fmt, ...) {\
+       if (bDlog) {\
+               LOGE("[TBM_DEBUG] " fmt, ##__VA_ARGS__);\
+       } \
+       else {\
+               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 */
 #define TBM_RETURN_IF_FAIL(cond) {\
        if (!(cond)) {\
-               TBM_LOG("[%s] : '%s' failed.\n", __func__, #cond);\
+               TBM_LOG_E("'%s' failed.\n", #cond);\
                return;\
        } \
 }
 #define TBM_RETURN_VAL_IF_FAIL(cond, val) {\
        if (!(cond)) {\
-               TBM_LOG("[%s] : '%s' failed.\n", __func__, #cond);\
+               TBM_LOG_E("'%s' failed.\n", #cond);\
                return val;\
        } \
 }
+#define TBM_GOTO_VAL_IF_FAIL(cond, val) {\
+       if (!(cond)) {\
+               TBM_LOG_E("'%s' failed.\n", #cond);\
+               goto val;\
+       } \
+}
 
 /* check flags */
 #define RETURN_CHECK_FLAG(cond) {\
@@ -88,36 +196,27 @@ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
                                   surf->item_link.next && \
                                   surf->item_link.next->prev == &surf->item_link)
 
-#define TBM_DEBUG(fmt, ...)   fprintf(stderr, "[TBM:DEBUG(%d)] " fmt, getpid(), ##__VA_ARGS__)
-#define TBM_LOG(fmt, ...)  fprintf(stderr, "[TBM(%d):%s] " fmt, getpid(), __func__, ##__VA_ARGS__)
+
+#define TBM_SNRPRINTF(p, len, count, fmt, ARG...)  \
+       do { \
+               if (p) { \
+                       int rest = len - count; \
+                       int s = snprintf(&p[count], rest, fmt, ##ARG); \
+                       while (s >= rest) { \
+                               len *= 2; \
+                               p = realloc(p, len); \
+                               rest = len - count; \
+                               s = snprintf(&p[count], rest, fmt, ##ARG); \
+                       } \
+                       count += s; \
+               } \
+       } while (0)
 
 struct list_head {
        struct list_head *prev;
        struct list_head *next;
 };
 
-/* unneeded version 2.0 */
-#define TBM_ALL_CTRL_BACKEND_VALID(flags) \
-               ((flags&TBM_CACHE_CTRL_BACKEND) &&\
-               (flags&TBM_LOCK_CTRL_BACKEND))
-#define TBM_CACHE_CTRL_BACKEND_VALID(flags) \
-               (flags&TBM_CACHE_CTRL_BACKEND)
-#define TBM_LOCK_CTRL_BACKEND_VALID(flags) \
-               (flags&TBM_LOCK_CTRL_BACKEND)
-
-typedef union _tbm_bo_cache_state tbm_bo_cache_state;
-
-union _tbm_bo_cache_state {
-       unsigned int val;
-       struct {
-               unsigned int cntFlush: 16;      /*Flush all index for sync */
-               unsigned int isCacheable: 1;
-               unsigned int isCached: 1;
-               unsigned int isDirtied: 2;
-       } data;
-};
-/* unneeded version 2.0 */
-
 /**
  * @brief tbm_bo : buffer object of Tizen Buffer Manager
  */
@@ -139,15 +238,6 @@ struct _tbm_bo {
        int lock_cnt;                           /* lock count of bo */
 
        unsigned int map_cnt;           /* device map count */
-
-       /* unneeded version 2.0 */
-       tbm_bo_handle default_handle; /*default handle */
-
-       unsigned int tgl_key;           /*global key for tizen global lock */
-
-       /* for cache control */
-       tbm_bo_cache_state cache_state; /*cache state */
-       /* unneeded version 2.0 */
 };
 
 /**
@@ -163,23 +253,21 @@ struct _tbm_bufmgr {
 
        int lock_type;                          /* lock_type of bufmgr */
 
-       struct list_head bo_list;       /* list of bos belonging to bufmgr */
+       int capabilities;           /* capabilities of bufmgr */
 
-       struct list_head surf_list;     /* list of surfaces belonging to bufmgr */
+       unsigned int bo_cnt;        /* number of bos */
 
-       void *module_data;
+       struct list_head bo_list;       /* list of bos belonging to bufmgr */
 
-       tbm_bufmgr_backend backend;     /* bufmgr backend */
+       struct list_head surf_list;     /* list of surfaces belonging to bufmgr */
 
-       int use_2_0;
+       struct list_head surf_queue_list; /* list of surface queues belonging to bufmgr */
 
-       /* unneeded version 2.0 */
-       int lock_fd;                            /* fd of tizen global lock */
+       struct list_head debug_key_list; /* list of debug data key list belonging to bufmgr */
 
-       int fd_flag;                            /* flag set 1 when bufmgr fd open in tbm_bufmgr_init */
+       void *module_data;
 
-       int use_map_cache;                      /* flag to use the map_cahce */
-       /* unneeded version 2.0 */
+       tbm_bufmgr_backend backend;     /* bufmgr backend */
 };
 
 /**
@@ -208,6 +296,8 @@ struct _tbm_surface {
        struct list_head item_link; /* link of surface */
 
        struct list_head user_data_list;        /* list of the user_date in surface */
+
+       struct list_head debug_data_list;       /* list of debug data */
 };
 
 typedef struct {
@@ -219,10 +309,17 @@ typedef struct {
        struct list_head item_link;
 } tbm_user_data;
 
-int tbm_bufmgr_get_drm_fd_x11(void);
-int tbm_bufmgr_get_drm_fd_wayland(void);
+typedef struct {
+       char *key;
+       char *value;
+
+       /* link of user_data */
+       struct list_head item_link;
+} tbm_surface_debug_data;
 
+tbm_bufmgr _tbm_bufmgr_get_bufmgr(void);
 int _tbm_bo_set_surface(tbm_bo bo, tbm_surface_h surface);
+int _tbm_surface_is_valid(tbm_surface_h surface);
 
 /* functions for mutex */
 int tbm_surface_internal_get_info(tbm_surface_h surface, int opt,
@@ -233,6 +330,7 @@ unsigned int tbm_surface_internal_get_height(tbm_surface_h surface);
 tbm_format tbm_surface_internal_get_format(tbm_surface_h surface);
 unsigned int _tbm_surface_internal_get_debug_pid(tbm_surface_h surface);
 char *_tbm_surface_internal_format_to_str(tbm_format format);
+char * _tbm_surface_internal_get_debug_data(tbm_surface_h surface, char *key);
 
 tbm_user_data *user_data_lookup(struct list_head *user_data_list,
                                unsigned long key);
@@ -240,4 +338,5 @@ tbm_user_data *user_data_create(unsigned long key,
                                tbm_data_free data_free_func);
 void user_data_delete(tbm_user_data *user_data);
 
+int tbm_bufmgr_get_fd_limit(void);
 #endif                                                 /* _TBM_BUFMGR_INT_H_ */