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