Exclude dlog dependency when dlog disabled.
[platform/core/uifw/wayland-tbm.git] / src / wayland-tbm-int.h
1 /*
2 Copyright (C) 2015 Samsung Electronics co., Ltd. All Rights Reserved.
3
4 Contact:
5       SooChan Lim <sc1.lim@samsung.com>,
6       Sangjin Lee <lsj119@samsung.com>,
7       Boram Park <boram1288.park@samsung.com>,
8       Changyeon Lee <cyeon.lee@samsung.com>
9
10 Permission is hereby granted, free of charge, to any person obtaining a
11 copy of this software and associated documentation files (the "Software"),
12 to deal in the Software without restriction, including without limitation
13 the rights to use, copy, modify, merge, publish, distribute, sublicense,
14 and/or sell copies of the Software, and to permit persons to whom the
15 Software is furnished to do so, subject to the following conditions:
16
17 The above copyright notice and this permission notice (including the next
18 paragraph) shall be included in all copies or substantial portions of the
19 Software.
20
21 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
22 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
23 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
24 THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
25 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
26 FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
27 DEALINGS IN THE SOFTWARE.
28 */
29
30 #ifndef WAYLAND_TBM_INT_H
31 #define WAYLAND_TBM_INT_H
32
33 #ifdef  __cplusplus
34 extern "C" {
35 #endif
36
37 #ifdef HAVE_CONFIG_H
38 #include "config.h"
39 #endif
40
41 #include <tbm_bufmgr.h>
42 #include <wayland-util.h>
43 #include <tbm_log.h>
44 #include <wayland-tbm-client.h>
45
46 extern int bTrace;
47
48 #ifdef ENABLE_DLOG
49 #include <dlog.h>
50
51 #ifdef LOG_TAG
52 #undef LOG_TAG
53 #endif
54
55 #define LOG_TAG "WL_TBM"
56 #define WL_TBM_C_LOG(fmt, ...)   LOGI(fmt, ##__VA_ARGS__);
57 #define WL_TBM_S_LOG(fmt, ...)   LOGI(fmt, ##__VA_ARGS__);
58 #define WL_TBM_LOG(fmt, ...)     LOGI(fmt, ##__VA_ARGS__);
59 /* temp log */
60 #define WL_TBM_LOG_E(fmt, ...)   LOGE(fmt, ##__VA_ARGS__);
61 #else
62 #define WL_TBM_C_LOG(fmt, ...)   fprintf(stderr, "[WL_TBM_C(%d):%s] " fmt"\n", getpid(), __func__, ##__VA_ARGS__)
63 #define WL_TBM_S_LOG(fmt, ...)   fprintf(stderr, "[WL_TBM_S(%d):%s] " fmt"\n", getpid(), __func__, ##__VA_ARGS__)
64 #define WL_TBM_LOG(fmt, ...)     fprintf(stderr, "[WL_TBM(%d)] " fmt"\n", getpid(), ##__VA_ARGS__)
65 #define WL_TBM_LOG_E(fmt, ...)   fprintf(stderr, "[WL_TBM_E(%d)] " fmt"\n", getpid(), ##__VA_ARGS__)
66 #endif /* ENABLE_DLOG */
67
68 #define C(b, m)             (((b) >> (m)) & 0xFF)
69 #define FOURCC_STR(id)      C(id, 0), C(id, 8), C(id, 16), C(id, 24)
70
71 /* check condition */
72 #define WL_TBM_RETURN_IF_FAIL(cond) {\
73         if (!(cond)) {\
74                 WL_TBM_LOG_E("'%s' failed.", #cond);\
75                 return;\
76         } \
77 }
78 #define WL_TBM_RETURN_VAL_IF_FAIL(cond, val) {\
79         if (!(cond)) {\
80                 WL_TBM_LOG_E("'%s' failed.", #cond);\
81                 return val;\
82         } \
83 }
84 #define WL_TBM_GOTO_IF_FAIL(cond, dst) {\
85         if (!(cond)) {\
86                 WL_TBM_LOG_E("'%s' failed.", #cond);\
87                 goto dst;\
88         } \
89 }
90
91 #define WL_TBM_ARRAY_NTH_DATA(array, type, n) (((type*)((array)->data)) + n)
92
93 typedef enum {
94         WL_TBM_MONITOR_PROC_STATE_OFF,
95         WL_TBM_MONITOR_PROC_STATE_ON,
96         WL_TBM_MONITOR_PROC_STATE_STATUS,
97         WL_TBM_MONITOR_PROC_STATE_UNKNOWN,
98 } WL_TBM_MONITOR_PROC_STATE;
99
100 typedef enum {
101         WL_TBM_MONITOR_RES_BO,
102         WL_TBM_MONITOR_RES_SURFACE_INTERNAL,
103         WL_TBM_MONITOR_RES_SURFACE,
104         WL_TBM_MONITOR_RES_SURFACE_QUEUE,
105         WL_TBM_MONITOR_RES_WL_TBM,
106         WL_TBM_MONITOR_RES_ALL,
107         WL_TBM_MONITOR_RES_UNKNOWN,
108 } WL_TBM_MONITOR_RES;
109
110 #define WL_TBM_MONITOR_REPLY_MSG_LEN    8192
111 #define WL_TBM_MONITOR_ARGS_MAX                 12
112 #define WL_TBM_MONITOR_PATH_LEN                 256
113
114 #define WL_TBM_MONITOR_SNPRINTF(p, len, fmt, ARG...)  \
115         do { \
116                 if (p && (len) > 0) { \
117                         int s = snprintf(p, (len), fmt, ##ARG); \
118                         if (s > len) \
119                                 s = len; \
120                         if (s < 0) \
121                                 s = 0; \
122                         p += s; \
123                         (len) -= s; \
124                 } \
125         } while (0)
126
127 struct wayland_tbm_server {
128         struct wl_display *display;
129         struct wl_global *wl_tbm_global;
130         struct wl_global *wl_tbm_monitor_global;
131
132         tbm_bufmgr bufmgr;
133
134         struct wl_list cqueue_list; /* for scanout buffer */
135         struct wl_list tbm_monitor_list; /* for tbm monitor */
136         struct wl_list tbm_monitor_request_list; /* for tbm monitor */
137
138         char *path;
139         int queue_dump;
140 };
141
142 struct wayland_tbm_monitor_target {
143         int server;
144         int all;
145         int pid[256];
146 };
147
148 struct wayland_tbm_monitor_path {
149         int console;
150         int dlog;
151         char file[WL_TBM_MONITOR_PATH_LEN];
152 };
153
154 /* internal functions */
155 void
156 _wayland_tbm_util_get_appname_brief(char *brief);
157
158 void
159 _wayland_tbm_util_get_appname_from_pid(long pid, char *str);
160
161 int
162 _wayland_tbm_util_target_parse(char * target_str, struct wayland_tbm_monitor_target *target);
163
164 int
165 _wayland_tbm_util_scale_parse(char * scale_str, double *scale);
166
167 int
168 _wayland_tbm_util_debug_level_parse(char * str, int *debug_level);
169
170 int
171 _wayland_tbm_util_show_path_parse(char * path_str, char * cwd, struct wayland_tbm_monitor_path *path);
172
173 char *
174 _wayland_tbm_util_dump_path_parse(char * path_str);
175
176 WL_TBM_MONITOR_PROC_STATE
177 _wayland_tbm_util_proc_state_parse(char * str);
178
179 WL_TBM_MONITOR_RES
180 _wayland_tbm_util_resource_parse(char * str);
181
182 int
183 _wayland_tbm_util_dump_queue(WL_TBM_MONITOR_PROC_STATE cmd, tbm_bufmgr bufmgr, double scale);
184
185 void
186 _wayland_tbm_util_dump_snapshot(tbm_bufmgr bufmgr, double scale, char *path);
187
188 int
189 _wayland_tbm_util_trace(WL_TBM_MONITOR_PROC_STATE cmd, WL_TBM_MONITOR_RES res, tbm_bufmgr bufmgr);
190
191 char *
192 _wayland_tbm_dump_directory_make(const char *path);
193
194 void
195 _wayland_tbm_util_set_log_level(int debug_level);
196
197 int
198 wayland_tbm_monitor_server_init(struct wayland_tbm_server *tbm_srv);
199
200 int
201 wayland_tbm_monitor_client_init(struct wayland_tbm_client *tbm_client,
202         struct wl_registry *registry, uint32_t name, uint32_t version);
203
204 void
205 wayland_tbm_monitor_client_deinit(struct wayland_tbm_client *tbm_client);
206 #ifdef  __cplusplus
207 }
208 #endif
209
210 #endif