tizen 2.4 release
[framework/uifw/e17-mod-tizen-comp.git] / src / e_mod_comp_debug.c
1 #include "e_mod_comp_shared_types.h"
2 #include "e_mod_comp.h"
3 #include "e_mod_comp_atoms.h"
4 #include "e_mod_comp_debug.h"
5
6 typedef struct _E_Mod_Comp_Log_Info
7 {
8    int  type;
9    char file[256];
10 } E_Mod_Comp_Log_Info;
11
12 /* TODO: remove */
13 #define LT_NOTHING   0x0000
14 #define LT_CREATE    0x0004
15 #define LT_CONFIGURE 0x0008
16 #define LT_DRAW      0x0020
17 #define LT_DUMP      0x0100
18
19 /* local subsystem functions */
20 static void
21 _e_mod_comp_debug_wins_info_dump(E_Comp *c,
22                                  FILE   *fs)
23 {
24    E_Comp_Win *cw;
25    Ecore_X_Window cid = 0;
26    char *wname = NULL, *wclas = NULL;
27    int pid = 0, i = 0;
28    char buf[4096], buf2[4096], buf3[4096];
29    Eina_Bool res;
30
31    fprintf(fs, "B-----------------------------------------------------------------------------------------------------------------------------\n");
32    fprintf(fs, "  NO WINDOW    (CLIENT)  V     x     y    w    h PIXMAP      pw   ph | v  VAL DMGs DONE | PID  WNAME  WCLASS\n");
33    fprintf(fs, "------------------------------------------------------------------------------------------------------------------------------\n");
34
35    EINA_INLIST_REVERSE_FOREACH(c->wins, cw)
36      {
37         cid = e_mod_comp_util_client_xid_get(cw);
38         ecore_x_icccm_name_class_get(cid, &wname, &wclas);
39         res = ecore_x_netwm_pid_get(cid, &pid);
40         if (!res) pid = 0;
41
42         memset(buf, 0, sizeof(buf));
43         memset(buf2, 0, sizeof(buf2));
44         memset(buf3, 0, sizeof(buf3));
45
46         if (cw->bd)
47           snprintf(buf, sizeof(buf), "0x%07x", cw->bd->client.win);
48
49         if (cw->pixmap)
50           snprintf(buf2, sizeof(buf2), "0x%07x", cw->pixmap);
51
52         if (cw->sync_info.val)
53           snprintf(buf3, sizeof(buf3), "%d %4d %4d %4d",
54                    cw->sync_info.version,
55                    cw->sync_info.val,
56                    cw->dmg_updates,
57                    cw->sync_info.done_count);
58
59         fprintf(fs,
60                 " %3d 0x%07x %9s %s %5d %5d %4d %4d %9s %4d %4d | %16s | %d %d %d %d %d %d |%4d %s %s\n",
61                 i,
62                 cw->win,
63                 buf,
64                 cw->visible ? "v" : " ",
65                 cw->x, cw->y, cw->w, cw->h,
66                 buf2,
67                 cw->pw, cw->ph,
68                 buf3,
69                 cw->argb,
70                 cw->shaped,
71                 cw->show_ready,
72                 cw->show_done,
73                 cw->animating,
74                 cw->use_dri2,
75                 pid,
76                 wname ? wname : "",
77                 wclas ? wclas : "");
78
79         if (wname) free(wname);
80         if (wclas) free(wclas);
81         wname = wclas = NULL;
82         pid = cid = 0;
83         i++;
84      }
85    fprintf(fs, "E-----------------------------------------------------------------------------------------------------------------------------\n");
86 }
87
88 static void
89 _e_mod_comp_debug_canvas_info_dump(E_Comp        *c,
90                                    E_Comp_Canvas *canvas,
91                                    FILE          *fs)
92 {
93    Eina_List *l, *ll;
94    E_Comp_Object *co, *_co = NULL;
95    E_Comp_Win *cw, *_cw = NULL;
96    E_Comp_Layer *ly = NULL;
97    Eina_List *lm = NULL;
98    int x, y, w, h, i = 1;
99    const char *file = NULL, *group = NULL;
100    double val = 0.0;
101    fprintf(fs, "B-----------------------------------------------------------------------------------------------------------------------------\n");
102    fprintf(fs, " canvas->zone:%p num:%d %d,%d %dx%d\n",
103            canvas->zone, canvas->zone->num,
104            canvas->zone->x, canvas->zone->y,
105            canvas->zone->w, canvas->zone->h);
106    fprintf(fs, " c->nocomp:%d use_hw_ov:%d\n", c->nocomp, c->use_hw_ov);
107    fprintf(fs, " canvas->nocomp mode:%d force_composite:%d(ref:%d)\n", canvas->nocomp.mode, canvas->nocomp.force_composite, canvas->nocomp.comp_ref);
108    fprintf(fs, " canvas->nocomp cw:0x%08x\n", e_mod_comp_util_client_xid_get(canvas->nocomp.cw));
109    fprintf(fs, " canvas->animation run:%d num:%d\n", canvas->animation.run, canvas->animation.num);
110    fprintf(fs, " H/W ov win:%p\n", canvas->ov);
111    fprintf(fs, " Canvas Manual Render State: %d\n", ecore_evas_manual_render_get(canvas->ee));
112    fprintf(fs, "------------------------------------------------------------------------------------------------------------------------------\n");
113
114    fprintf(fs, "--------------------------------------------------------------------------------------------------------------------------------------\n");
115    fprintf(fs, " NO     WinID      shobj        obj    found_o   ex   ey   ew   eh | W S O | V SYNC  DMG DONE |\n");
116    fprintf(fs, "--------------------------------------------------------------------------------------------------------------------------------------\n");
117    Eina_Bool found = 0;
118
119    ly = e_mod_comp_canvas_layer_get(canvas, "comp");
120    E_CHECK(ly);
121
122    lm = evas_object_smart_members_get(ly->layout);
123    E_CHECK(lm);
124    Evas_Object *o = NULL;
125
126    EINA_LIST_REVERSE_FOREACH(lm, ll, o)
127      {
128         if (!evas_object_visible_get(o)) continue;
129
130         EINA_INLIST_REVERSE_FOREACH(c->wins, cw)
131           {
132              EINA_LIST_FOREACH(cw->objs, l, co)
133                {
134                   if (!co) continue;
135                   if (co->canvas != canvas) continue;
136                   if (co->shadow == o)
137                     {
138                        found = 1;
139                        _co = co;
140                        _cw = cw;
141                        break;
142                     }
143                }
144           }
145
146         if (found && _co && _cw)
147           {
148              edje_object_file_get(_co->shadow, &file, &group);
149              evas_object_geometry_get(o, &x, &y, &w, &h);
150
151              fprintf(fs,
152                      " %2d 0x%07x %p %p %p %4d %4d %4dx%4d %s %s|%s|%s %.1f|%s %.1f|%s %.1f\n",
153                      i, _cw->win, _co->shadow, _co->img, o, x, y, w, h,
154                      evas_object_visible_get(_co->shadow) ? "v" : "",
155                      _cw->hidden_override ? "HIDDEN" : "",
156                      group,
157                      edje_object_part_state_get(_co->shadow, "clipper", &val), val,
158                      edje_object_part_state_get(_co->shadow, "shower", &val), val,
159                      edje_object_part_state_get(_co->shadow, "e.swallow.content", &val), val);
160           }
161
162         found = 0;
163         _co = NULL;
164         _cw = NULL;
165         file = NULL;
166         group = NULL;
167         val = 0.0;
168         i++;
169      }
170    eina_list_free(lm);
171 }
172
173 /* externally accessible globals */
174 EAPI int logtype = LT_NOTHING;
175
176 /* externally accessible functions */
177 EAPI Eina_Bool
178 e_mod_comp_debug_info_dump(Eina_Bool to_file,
179                            const char *name)
180 {
181    E_Comp *c;
182    E_Comp_Canvas *canvas;
183    Eina_List *l;
184    FILE *fs = stderr;
185
186    c = e_mod_comp_util_get();
187    E_CHECK_RETURN(c, 0);
188
189    if ((to_file) && (name))
190      {
191         fs = fopen(name, "w");
192         if (!fs)
193           {
194              fprintf(stderr, "can't open %s file.\n", name);
195              fs = stderr;
196              to_file = EINA_FALSE;
197           }
198      }
199
200    _e_mod_comp_debug_wins_info_dump(c, fs);
201
202    EINA_LIST_FOREACH(c->canvases, l, canvas)
203      {
204         if (!canvas) continue;
205         _e_mod_comp_debug_canvas_info_dump(c, canvas, fs);
206      }
207
208    if (to_file)
209      {
210         fflush(fs);
211         fclose(fs);
212      }
213    return EINA_TRUE;
214 }
215
216 EAPI Eina_Bool
217 e_mod_comp_debug_edje_error_get(Evas_Object *o,
218                                 Ecore_X_Window win)
219 {
220    Edje_Load_Error err = edje_object_load_error_get(o);
221    char *_err_msg = NULL;
222    Eina_Bool res = EINA_TRUE;
223
224    if (err != EDJE_LOAD_ERROR_NONE)
225      {
226         switch (err)
227           {
228            case EDJE_LOAD_ERROR_GENERIC:                    _err_msg = strdup("ERR_GENERIC");                    break;
229            case EDJE_LOAD_ERROR_DOES_NOT_EXIST:             _err_msg = strdup("ERR_DOES_NOT_EXIST");             break;
230            case EDJE_LOAD_ERROR_PERMISSION_DENIED:          _err_msg = strdup("ERR_PERMISSION_DENIED");          break;
231            case EDJE_LOAD_ERROR_RESOURCE_ALLOCATION_FAILED: _err_msg = strdup("ERR_RESOURCE_ALLOCATION_FAILED"); break;
232            case EDJE_LOAD_ERROR_CORRUPT_FILE:               _err_msg = strdup("ERR_CORRUPT_FILE");               break;
233            case EDJE_LOAD_ERROR_UNKNOWN_FORMAT:             _err_msg = strdup("ERR_UNKNOWN_FORMAT");             break;
234            case EDJE_LOAD_ERROR_INCOMPATIBLE_FILE:          _err_msg = strdup("ERR_INCOMPATIBLE_FILE");          break;
235            case EDJE_LOAD_ERROR_UNKNOWN_COLLECTION:         _err_msg = strdup("ERR_UNKNOWN_COLLECTION");         break;
236            case EDJE_LOAD_ERROR_RECURSIVE_REFERENCE:        _err_msg = strdup("ERR_RECURSIVE_REFERENCE");        break;
237            default:                                         _err_msg = strdup("ERR_UNKNOWN_ERROR");              break;
238           }
239         res = EINA_FALSE;
240      }
241
242    if (res) _err_msg = strdup("SUCCESS");
243    ELBF(ELBT_COMP, 0, win, "%15.15s|o:%p %s", "EDC", o, _err_msg);
244    free(_err_msg);
245
246    return res;
247 }
248
249 EAPI Eina_Bool
250 e_mod_comp_debug_prop_handle(Ecore_X_Event_Window_Property *ev)
251 {
252    Eina_Bool res = EINA_FALSE;
253    E_Mod_Comp_Log_Info info = {LT_NOTHING, {0,}};
254    unsigned char* data = NULL;
255    int ret, n;
256
257    E_CHECK_RETURN(ev, 0);
258    E_CHECK_RETURN(ev->win, 0);
259
260    ret = ecore_x_window_prop_property_get
261            (ev->win, ATOM_CM_LOG, ECORE_X_ATOM_CARDINAL,
262            32, &data, &n);
263    E_CHECK_GOTO((ret != -1), cleanup);
264    E_CHECK_GOTO(((ret > 0) && (data)), cleanup);
265
266    memcpy(&info, data, sizeof(E_Mod_Comp_Log_Info));
267    logtype = info.type;
268
269    fprintf(stdout, "[COMP] logtupe:0x%08x\n", logtype);
270
271    if (logtype == LT_CREATE)
272      {
273         e_mod_comp_debug_info_dump(EINA_FALSE, NULL);
274      }
275    else if (logtype == LT_CONFIGURE)
276      {
277         int enable = e_configure_registry_exists("appearance/comp");
278         if (enable)
279           {
280              E_Comp *c = e_mod_comp_util_get();
281              E_CHECK_GOTO(c, cleanup);
282              e_scale_update();
283              e_configure_registry_call("appearance/comp",
284                                        e_container_current_get(c->man),
285                                        NULL);
286           }
287      }
288    else if (logtype == LT_DRAW)
289      {
290         E_Comp *c = e_mod_comp_util_get();
291         E_Comp_Canvas *canvas;
292         Eina_List *l = NULL;
293         char msg[4096], buf[2048];
294
295         snprintf(msg, sizeof(msg), "This is a test dialog for debugging purpose.");
296
297         EINA_LIST_FOREACH(c->canvases, l, canvas)
298           {
299              snprintf(buf, sizeof(buf),
300                "<br>"
301                "Zone[%d] %d,%d %dx%d<br>"
302                "%s 0x%x F:%d(%d) A:%d(%d)",
303                canvas->zone->num,
304                canvas->zone->x,
305                canvas->zone->y,
306                canvas->zone->w,
307                canvas->zone->h,
308                (canvas->nocomp.mode == E_NOCOMP_MODE_RUN) ? "No composite" : "Composite",
309                e_mod_comp_util_client_xid_get(canvas->nocomp.cw),
310                canvas->nocomp.force_composite,
311                            canvas->nocomp.comp_ref,
312                canvas->animation.run,
313                canvas->animation.num);
314
315              strcat(msg, buf);
316           }
317         e_util_dialog_internal("Enlightenment Rendering Mode", msg);
318      }
319
320    if ((logtype == LT_DUMP) &&
321        (strlen(info.file) > 0))
322      {
323         e_mod_comp_debug_info_dump(EINA_TRUE, info.file);
324         ecore_x_client_message32_send
325           (ev->win, ATOM_CM_LOG_DUMP_DONE,
326           ECORE_X_EVENT_MASK_WINDOW_CONFIGURE,
327           0, 0, 0, 0, 0);
328      }
329
330    res = EINA_TRUE;
331
332 cleanup:
333    if (data) E_FREE(data);
334    return res;
335 }
336
337 #if COMP_DEBUG_PIXMAP
338 # ifdef ecore_x_composite_name_window_pixmap_get
339 #  undef ecore_x_composite_name_window_pixmap_get
340 # endif
341 EAPI Ecore_X_Pixmap
342 e_mod_comp_debug_name_window_pixmap_get(Ecore_X_Window w,
343                                         const char    *f,
344                                         const int      l)
345 {
346    Ecore_X_Pixmap p = 0;
347    Ecore_X_Window win = 0;
348    E_Border *bd = NULL;
349
350    p = ecore_x_composite_name_window_pixmap_get(w);
351    bd = e_border_find_by_window(w);
352    if (bd) win = bd->client.win;
353    fprintf(stderr,
354            "[COMP] %30.30s|%04d 0x%08x NEW  PIXMAP 0x%x\n",
355            f, l, win, p);
356    return p;
357 }
358 #endif /* COMP_DEBUG_PIXMAP */