Make log related global variables as local
[platform/core/uifw/coregl.git] / src / modules / coregl_tracepath_egl.c
1 #include "coregl_tracepath.h"
2
3 #include <stdlib.h>
4 #include <string.h>
5 #include <sys/time.h>
6
7 #include <sys/types.h>
8 #include <unistd.h>
9
10 Mutex ctx_access_mutex = MUTEX_INITIALIZER;
11 Ctx_Data *ctx_data = NULL;
12
13 static Sostate_Data *
14 _get_sostate(GLContext ctx)
15 {
16         Sostate_Data *ret = NULL;
17
18         Ctx_Data *current = ctx_data;
19         while (current != NULL) {
20                 if (current->handle == ctx) {
21                         current->sostate->ref_count++;
22                         ret = current->sostate;
23                         break;
24                 }
25                 current = current->next;
26         }
27
28         return ret;
29 }
30
31 #ifdef COREGL_TRACEPATH_TRACE_CONTEXT_INFO
32
33 static void
34 _dump_context_info(const char *ment, int force_output)
35 {
36         MY_MODULE_TSTATE *tstate = NULL;
37         static struct timeval tv_last = { 0, 0 };
38
39         if (get_trace_ctx_flag() != 1) return;
40
41         AST(mutex_lock(&ctx_access_mutex) == 1);
42         AST(mutex_lock(&general_trace_lists_access_mutex) == 1);
43
44         if (!force_output && !get_trace_ctx_force_flag()) {
45                 struct timeval tv_now = { 0, 0 };
46                 AST(gettimeofday(&tv_now, NULL) == 0);
47                 if (tv_now.tv_sec - tv_last.tv_sec < _COREGL_TRACE_OUTPUT_INTERVAL_SEC) {
48                         goto finish;
49                 }
50                 tv_last = tv_now;
51         }
52
53         GET_MY_TSTATE(tstate, get_current_thread_state());
54
55         TRACE("\n");
56         TRACE("\E[40;34m========================================================================================================================\E[0m\n");
57         TRACE("\E[40;32;1m  Context info \E[1;37;1m: <PID = %d> %s\E[0m\n", getpid(),
58                   ment);
59         TRACE("\E[40;34m========================================================================================================================\E[0m\n");
60
61
62         // Thread State List
63         {
64                 General_Trace_List *current = NULL;
65                 current = thread_trace_list;
66
67                 while (current != NULL) {
68                         GLThreadState *cur_tstate = (GLThreadState *)current->value;
69                         MY_MODULE_TSTATE *cur_tstate_tm = NULL;
70
71                         GET_MY_TSTATE(cur_tstate_tm, cur_tstate);
72                         AST(cur_tstate_tm != NULL);
73
74                         if (cur_tstate_tm == NULL)
75                                 continue;
76
77                         TRACE(" %c Thread  [0x%12x] : Surf <D=[%12p] R=[%12p]>",
78                                   (tstate == cur_tstate_tm) ? '*' : ' ',
79                                   cur_tstate->thread_id,
80                                   cur_tstate_tm->surf_draw,
81                                   cur_tstate_tm->surf_read);
82
83                         if (cur_tstate_tm->ctx != NULL) {
84                                 TRACE(" EGLCTX=[%12p]\E[0m\n",
85                                           cur_tstate_tm->ctx->handle);
86                         } else {
87                                 TRACE(" (NOT BINDED TO THREAD)\E[0m\n");
88                         }
89
90                         // Binded Context State List
91                         {
92                                 Ctx_Data *current = NULL;
93                                 current = ctx_data;
94
95                                 while (current != NULL) {
96                                         if (cur_tstate_tm->ctx == current) {
97                                                 TRACE("   -> EGLCTX [%12p] : EGLDPY=[%12p] <MC count [%10d]> <Ref [%2d]>\E[0m\n",
98                                                           current->handle,
99                                                           current->dpy,
100                                                           current->mc_count,
101                                                           current->ref_count);
102                                         }
103
104                                         current = current->next;
105                                 }
106
107                         }
108
109
110                         current = current->next;
111                 }
112         }
113
114         TRACE("\E[40;33m........................................................................................................................\E[0m\n");
115
116         // Not-binded Context State List
117         {
118                 Ctx_Data *current = NULL;
119                 current = ctx_data;
120
121                 while (current != NULL) {
122                         int isbinded = 0;
123
124                         General_Trace_List *current_t = NULL;
125                         current_t = thread_trace_list;
126
127                         while (current_t != NULL) {
128                                 GLThreadState *cur_tstate = (GLThreadState *)current_t->value;
129                                 MY_MODULE_TSTATE *cur_tstate_tm = NULL;
130
131                                 GET_MY_TSTATE(cur_tstate_tm, cur_tstate);
132                                 AST(cur_tstate_tm != NULL);
133                                 if (cur_tstate_tm != NULL && cur_tstate_tm->ctx == current) {
134                                         isbinded = 1;
135                                         break;
136                                 }
137                                 current_t = current_t->next;
138                         }
139
140                         if (isbinded == 0) {
141                                 TRACE("   EGLCTX    [%12p] : EGLDPY=[%12p] <MC count [%10d]> <Ref [%2d]>\E[0m\n",
142                                           current->handle,
143                                           current->dpy,
144                                           current->mc_count,
145                                           current->ref_count);
146                         }
147
148                         current = current->next;
149                 }
150
151         }
152
153         TRACE("\E[40;34m========================================================================================================================\E[0m\n");
154         TRACE("\n");
155
156         TRACE_END();
157
158         goto finish;
159
160 finish:
161
162         AST(mutex_unlock(&general_trace_lists_access_mutex) == 1);
163         AST(mutex_unlock(&ctx_access_mutex) == 1);
164
165 }
166
167 #endif // COREGL_TRACEPATH_TRACE_CONTEXT_INFO
168
169
170 void
171 tracepath_add_context(GLContext ctx, GLDisplay dpy, GLContext share_ctx)
172 {
173         Ctx_Data *current = NULL;
174         Ctx_Data *data = NULL;
175
176         AST(mutex_lock(&ctx_access_mutex) == 1);
177
178         current = ctx_data;
179
180         while (current != NULL) {
181                 if (current->handle == ctx) {
182                         data = current;
183                         break;
184                 }
185                 current = current->next;
186         }
187
188         if (data == NULL) {
189                 data = (Ctx_Data *)calloc(1, sizeof(Ctx_Data));
190                 if (data == NULL) goto finish;
191
192                 data->ref_count = 1;
193                 data->handle = ctx;
194                 data->dpy = dpy;
195
196                 data->sostate = _get_sostate(share_ctx);
197                 if (data->sostate == NULL) {
198                         data->sostate = (Sostate_Data *)calloc(1, sizeof(Sostate_Data));
199                         if (data->sostate == NULL) goto finish;
200
201                         data->sostate->ref_count = 1;
202                 }
203
204                 if (ctx_data != NULL)
205                         data->next = ctx_data;
206
207                 ctx_data = data;
208         }
209         goto finish;
210
211 finish:
212         AST(mutex_unlock(&ctx_access_mutex) == 1);
213         return;
214 }
215
216 Ctx_Data *
217 tracepath_get_context(GLContext ctx)
218 {
219         Ctx_Data *current = NULL;
220         Ctx_Data *data = NULL;
221
222         AST(mutex_lock(&ctx_access_mutex) == 1);
223
224         current = ctx_data;
225
226         while (current != NULL) {
227                 if (current->handle == ctx) {
228                         data = current;
229                         break;
230                 }
231                 current = current->next;
232         }
233         if (data == NULL) {
234                 COREGL_WARN("Error making context [%p] current. (invalid EGL context)", ctx);
235                 goto finish;
236         }
237         data->ref_count++;
238         goto finish;
239
240 finish:
241         AST(mutex_unlock(&ctx_access_mutex) == 1);
242         return data;
243 }
244
245 void
246 tracepath_remove_context(GLContext ctx)
247 {
248         Ctx_Data *current = NULL;
249         Ctx_Data *prev = NULL;
250
251         AST(mutex_lock(&ctx_access_mutex) == 1);
252
253         current = ctx_data;
254
255         while (current != NULL) {
256                 if (current->handle == ctx) {
257                         if (--current->ref_count <= 0) {
258                                 if (prev != NULL)
259                                         prev->next = current->next;
260                                 else
261                                         ctx_data = current->next;
262
263                                 if (--current->sostate->ref_count <= 0) {
264                                         tracepath_glbuf_clear(current->sostate->glbuf_rb);
265                                         tracepath_glbuf_clear(current->sostate->glbuf_tex);
266                                         free(current->sostate);
267                                         current->sostate = NULL;
268                                 }
269
270                                 free(current);
271                                 current = NULL;
272                         }
273                         break;
274                 }
275                 prev = current;
276                 current = current->next;
277         }
278         goto finish;
279
280 finish:
281         AST(mutex_unlock(&ctx_access_mutex) == 1);
282         return;
283 }
284
285 EGLint
286 tracepath_eglGetError(void)
287 {
288         EGLint ret = _COREGL_INT_INIT_VALUE;
289
290         _COREGL_TRACEPATH_FUNC_BEGIN();
291         ret = _orig_tracepath_eglGetError();
292         goto finish;
293
294 finish:
295         _COREGL_TRACEPATH_FUNC_END();
296         return ret;
297 }
298
299 EGLDisplay
300 tracepath_eglGetDisplay(EGLNativeDisplayType display_id)
301 {
302         EGLDisplay ret = EGL_NO_DISPLAY;
303
304         _COREGL_TRACEPATH_FUNC_BEGIN();
305         ret = _orig_tracepath_eglGetDisplay(display_id);
306         goto finish;
307
308 finish:
309         _COREGL_TRACEPATH_FUNC_END();
310         return ret;
311 }
312
313 EGLBoolean
314 tracepath_eglInitialize(EGLDisplay dpy, EGLint *major, EGLint *minor)
315 {
316         EGLBoolean ret = EGL_FALSE;
317         _COREGL_TRACEPATH_FUNC_BEGIN();
318         ret = _orig_tracepath_eglInitialize(dpy, major, minor);
319         goto finish;
320
321 finish:
322         _COREGL_TRACEPATH_FUNC_END();
323         return ret;
324 }
325
326 EGLBoolean
327 tracepath_eglTerminate(EGLDisplay dpy)
328 {
329         EGLBoolean ret = EGL_FALSE;
330
331         _COREGL_TRACEPATH_FUNC_BEGIN();
332         ret = _orig_tracepath_eglTerminate(dpy);
333         goto finish;
334
335 finish:
336         _COREGL_TRACEPATH_FUNC_END();
337         return ret;
338 }
339
340 EGLBoolean
341 tracepath_eglGetConfigs(EGLDisplay dpy, EGLConfig *configs, EGLint config_size,
342                                                 EGLint *num_config)
343 {
344         EGLBoolean ret = EGL_FALSE;
345
346         _COREGL_TRACEPATH_FUNC_BEGIN();
347         ret = _orig_tracepath_eglGetConfigs(dpy, configs, config_size, num_config);
348         goto finish;
349
350 finish:
351         _COREGL_TRACEPATH_FUNC_END();
352         return ret;
353 }
354
355 EGLBoolean
356 tracepath_eglChooseConfig(EGLDisplay dpy, const EGLint *attrib_list,
357                                                   EGLConfig *configs, EGLint config_size, EGLint *num_config)
358 {
359         EGLBoolean ret = EGL_FALSE;
360
361         _COREGL_TRACEPATH_FUNC_BEGIN();
362         ret = _orig_tracepath_eglChooseConfig(dpy, attrib_list, configs, config_size,
363                                                                                   num_config);
364         goto finish;
365
366 finish:
367         _COREGL_TRACEPATH_FUNC_END();
368         return ret;
369 }
370
371 EGLBoolean
372 tracepath_eglGetConfigAttrib(EGLDisplay dpy, EGLConfig config, EGLint attribute,
373                                                          EGLint *value)
374 {
375         EGLBoolean ret = EGL_FALSE;
376
377         _COREGL_TRACEPATH_FUNC_BEGIN();
378         ret = _orig_tracepath_eglGetConfigAttrib(dpy, config, attribute, value);
379         goto finish;
380
381 finish:
382         _COREGL_TRACEPATH_FUNC_END();
383         return ret;
384 }
385
386
387 EGLSurface
388 tracepath_eglCreateWindowSurface(EGLDisplay dpy, EGLConfig config,
389                                                                  EGLNativeWindowType win, const EGLint *attrib_list)
390 {
391         EGLSurface ret = EGL_NO_SURFACE;
392
393         _COREGL_TRACEPATH_FUNC_BEGIN();
394         ret = _orig_tracepath_eglCreateWindowSurface(dpy, config, win, attrib_list);
395         goto finish;
396
397 finish:
398         _COREGL_TRACEPATH_FUNC_END();
399         return ret;
400 }
401
402 EGLSurface
403 tracepath_eglCreatePbufferSurface(EGLDisplay dpy, EGLConfig config,
404                                                                   const EGLint *attrib_list)
405 {
406         EGLSurface ret = EGL_NO_SURFACE;
407
408         _COREGL_TRACEPATH_FUNC_BEGIN();
409         ret = _orig_tracepath_eglCreatePbufferSurface(dpy, config, attrib_list);
410         goto finish;
411
412 finish:
413         _COREGL_TRACEPATH_FUNC_END();
414         return ret;
415 }
416
417 EGLSurface
418 tracepath_eglCreatePixmapSurface(EGLDisplay dpy, EGLConfig config,
419                                                                  EGLNativePixmapType pixmap, const EGLint *attrib_list)
420 {
421         EGLSurface ret = EGL_NO_SURFACE;
422
423         _COREGL_TRACEPATH_FUNC_BEGIN();
424         ret = _orig_tracepath_eglCreatePixmapSurface(dpy, config, pixmap, attrib_list);
425         goto finish;
426
427 finish:
428         _COREGL_TRACEPATH_FUNC_END();
429         return ret;
430 }
431
432 EGLBoolean
433 tracepath_eglDestroySurface(EGLDisplay dpy, EGLSurface surface)
434 {
435         EGLBoolean ret = EGL_FALSE;
436
437         _COREGL_TRACEPATH_FUNC_BEGIN();
438         ret = _orig_tracepath_eglDestroySurface(dpy, surface);
439         goto finish;
440
441 finish:
442         _COREGL_TRACEPATH_FUNC_END();
443 #ifdef COREGL_TRACEPATH_TRACE_SURFACE_INFO
444         {
445                 char name[256];
446                 snprintf(name, sizeof(name), "EGLSURFACE_%p", surface);
447                 tracepath_surface_trace_add(name, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL);
448         }
449 #endif // COREGL_TRACEPATH_TRACE_SURFACE_INFO
450         return ret;
451 }
452
453 EGLBoolean
454 tracepath_eglQuerySurface(EGLDisplay dpy, EGLSurface surface, EGLint attribute,
455                                                   EGLint *value)
456 {
457         EGLBoolean ret = EGL_FALSE;
458
459         _COREGL_TRACEPATH_FUNC_BEGIN();
460         ret = _orig_tracepath_eglQuerySurface(dpy, surface, attribute, value);
461         goto finish;
462
463 finish:
464         _COREGL_TRACEPATH_FUNC_END();
465         return ret;
466 }
467
468 EGLBoolean
469 tracepath_eglBindAPI(EGLenum api)
470 {
471         EGLBoolean ret = EGL_FALSE;
472
473         _COREGL_TRACEPATH_FUNC_BEGIN();
474         ret = _orig_tracepath_eglBindAPI(api);
475         goto finish;
476
477 finish:
478         _COREGL_TRACEPATH_FUNC_END();
479         return ret;
480 }
481
482 EGLenum
483 tracepath_eglQueryAPI(void)
484 {
485         EGLenum ret = 0;
486
487         _COREGL_TRACEPATH_FUNC_BEGIN();
488         ret = _orig_tracepath_eglQueryAPI();
489         goto finish;
490
491 finish:
492         _COREGL_TRACEPATH_FUNC_END();
493         return ret;
494 }
495
496 EGLBoolean
497 tracepath_eglWaitClient(void)
498 {
499         EGLBoolean ret = EGL_FALSE;
500
501         _COREGL_TRACEPATH_FUNC_BEGIN();
502         ret = _orig_tracepath_eglWaitClient();
503         goto finish;
504
505 finish:
506         _COREGL_TRACEPATH_FUNC_END();
507         return ret;
508 }
509
510 EGLBoolean
511 tracepath_eglReleaseThread(void)
512 {
513         EGLBoolean ret = EGL_FALSE;
514
515         _COREGL_TRACEPATH_FUNC_BEGIN();
516         ret = _orig_tracepath_eglReleaseThread();
517         goto finish;
518
519 finish:
520         _COREGL_TRACEPATH_FUNC_END();
521         return ret;
522 }
523
524 EGLSurface
525 tracepath_eglCreatePbufferFromClientBuffer(EGLDisplay dpy, EGLenum buftype,
526                 EGLClientBuffer buffer, EGLConfig config, const EGLint *attrib_list)
527 {
528         EGLSurface ret = EGL_NO_SURFACE;
529
530         _COREGL_TRACEPATH_FUNC_BEGIN();
531         ret = _orig_tracepath_eglCreatePbufferFromClientBuffer(dpy, buftype, buffer,
532                         config, attrib_list);
533         goto finish;
534
535 finish:
536         _COREGL_TRACEPATH_FUNC_END();
537         return ret;
538 }
539
540 EGLBoolean
541 tracepath_eglSurfaceAttrib(EGLDisplay dpy, EGLSurface surface, EGLint attribute,
542                                                    EGLint value)
543 {
544         EGLBoolean ret = EGL_FALSE;
545
546         _COREGL_TRACEPATH_FUNC_BEGIN();
547         ret = _orig_tracepath_eglSurfaceAttrib(dpy, surface, attribute, value);
548         goto finish;
549
550 finish:
551         _COREGL_TRACEPATH_FUNC_END();
552         return ret;
553 }
554
555 EGLBoolean
556 tracepath_eglBindTexImage(EGLDisplay dpy, EGLSurface surface, EGLint buffer)
557 {
558         EGLBoolean ret = EGL_FALSE;
559
560         _COREGL_TRACEPATH_FUNC_BEGIN();
561         ret = _orig_tracepath_eglBindTexImage(dpy, surface, buffer);
562         goto finish;
563
564 finish:
565         _COREGL_TRACEPATH_FUNC_END();
566         return ret;
567 }
568
569 EGLBoolean
570 tracepath_eglReleaseTexImage(EGLDisplay dpy, EGLSurface surface, EGLint buffer)
571 {
572         EGLBoolean ret = EGL_FALSE;
573
574         _COREGL_TRACEPATH_FUNC_BEGIN();
575         ret = _orig_tracepath_eglReleaseTexImage(dpy, surface, buffer);
576         goto finish;
577
578 finish:
579         _COREGL_TRACEPATH_FUNC_END();
580         return ret;
581 }
582
583 EGLBoolean
584 tracepath_eglSwapInterval(EGLDisplay dpy, EGLint interval)
585 {
586         EGLBoolean ret = EGL_FALSE;
587
588         _COREGL_TRACEPATH_FUNC_BEGIN();
589         ret = _orig_tracepath_eglSwapInterval(dpy, interval);
590         goto finish;
591
592 finish:
593         _COREGL_TRACEPATH_FUNC_END();
594         return ret;
595 }
596
597 EGLContext
598 tracepath_eglCreateContext(EGLDisplay dpy, EGLConfig config,
599                                                    EGLContext share_context, const EGLint *attrib_list)
600 {
601         EGLContext ret = EGL_NO_CONTEXT;
602
603         _COREGL_TRACEPATH_FUNC_BEGIN();
604         ret = _orig_tracepath_eglCreateContext(dpy, config, share_context, attrib_list);
605         goto finish;
606
607 finish:
608         _COREGL_TRACEPATH_FUNC_END();
609         {
610                 if (ret != EGL_NO_CONTEXT) {
611                         tracepath_add_context(ret, dpy, share_context);
612                 }
613         }
614 #ifdef COREGL_TRACEPATH_TRACE_CONTEXT_INFO
615         if (unlikely(get_trace_ctx_flag() == 1)) {
616                 if (_orig_tracepath_eglCreateContext == _sym_eglCreateContext) {
617                         char ment[256];
618                         snprintf(ment, sizeof(ment), "eglCreateContext completed (EGLCTX=[%12p])", ret);
619                         _dump_context_info(ment, 1);
620                 }
621         }
622 #endif // COREGL_TRACEPATH_TRACE_CONTEXT_INFO
623         return ret;
624 }
625
626 EGLBoolean
627 tracepath_eglDestroyContext(EGLDisplay dpy, EGLContext ctx)
628 {
629         EGLBoolean ret = EGL_FALSE;
630
631         _COREGL_TRACEPATH_FUNC_BEGIN();
632         ret = _orig_tracepath_eglDestroyContext(dpy, ctx);
633         goto finish;
634
635 finish:
636         _COREGL_TRACEPATH_FUNC_END();
637         {
638                 AST(ctx != EGL_NO_CONTEXT);
639
640                 tracepath_remove_context(ctx);
641         }
642 #ifdef COREGL_TRACEPATH_TRACE_CONTEXT_INFO
643         if (unlikely(get_trace_ctx_flag() == 1)) {
644                 if (_orig_tracepath_eglDestroyContext == _sym_eglDestroyContext) {
645                         char ment[256];
646                         snprintf(ment, sizeof(ment), "eglDestroyContext completed (EGLCTX=[%12p])",
647                                          ctx);
648                         _dump_context_info(ment, 1);
649                 }
650         }
651 #endif // COREGL_TRACEPATH_TRACE_CONTEXT_INFO
652         return ret;
653 }
654
655 EGLBoolean
656 tracepath_eglMakeCurrent(EGLDisplay dpy, EGLSurface draw, EGLSurface read,
657                                                  EGLContext ctx)
658 {
659         EGLBoolean ret = EGL_FALSE;
660
661         _COREGL_TRACEPATH_FUNC_BEGIN();
662         ret = _orig_tracepath_eglMakeCurrent(dpy, draw, read, ctx);
663         goto finish;
664
665 finish:
666         _COREGL_TRACEPATH_FUNC_END();
667         {
668                 MY_MODULE_TSTATE *tstate = NULL;
669
670                 GET_MY_TSTATE(tstate, get_current_thread_state());
671                 if (tstate == NULL) {
672                         init_new_thread_state();
673
674                         GET_MY_TSTATE(tstate, get_current_thread_state());
675                         AST(tstate != NULL);
676                 }
677
678                 if (tstate) {
679
680                         Ctx_Data *oldctx = tstate->ctx;
681
682                         if (ctx != EGL_NO_CONTEXT) {
683                                 tstate->ctx = tracepath_get_context(ctx);
684                                 if (tstate->ctx != NULL)
685                                         tstate->ctx->mc_count++;
686                         } else {
687                                 tstate->ctx = NULL;
688                         }
689
690                         if (oldctx != NULL)
691                                 tracepath_remove_context(oldctx->handle);
692
693                         tstate->surf_draw = draw;
694                         tstate->surf_read = read;
695                 }
696         }
697 #ifdef COREGL_TRACEPATH_TRACE_STATE_INFO
698         if (unlikely(get_trace_state_flag() == 1)) {
699                 if (_orig_tracepath_eglMakeCurrent == _sym_eglMakeCurrent)
700                         tracepath_dump_context_states(0);
701         }
702 #endif // COREGL_TRACEPATH_TRACE_STATE_INFO
703 #ifdef COREGL_TRACEPATH_TRACE_CONTEXT_INFO
704         if (unlikely(get_trace_ctx_flag() == 1)) {
705                 if (_orig_tracepath_eglMakeCurrent == _sym_eglMakeCurrent) {
706                         char ment[256];
707                         snprintf(ment, sizeof(ment),
708                                          "eglMakeCurrent finished (EGLCTX=[%12p] Surf=[D:%12p R:%12p])",
709                                          ctx, draw, read);
710                         _dump_context_info(ment, 0);
711                 }
712         }
713 #endif // COREGL_TRACEPATH_TRACE_CONTEXT_INFO
714         return ret;
715 }
716
717 EGLContext
718 tracepath_eglGetCurrentContext(void)
719 {
720         EGLContext ret = EGL_NO_CONTEXT;
721
722         _COREGL_TRACEPATH_FUNC_BEGIN();
723         ret = _orig_tracepath_eglGetCurrentContext();
724         goto finish;
725
726 finish:
727         _COREGL_TRACEPATH_FUNC_END();
728         return ret;
729 }
730
731 EGLSurface
732 tracepath_eglGetCurrentSurface(EGLint readdraw)
733 {
734         EGLSurface ret = EGL_NO_SURFACE;
735
736         _COREGL_TRACEPATH_FUNC_BEGIN();
737         ret = _orig_tracepath_eglGetCurrentSurface(readdraw);
738         goto finish;
739
740 finish:
741         _COREGL_TRACEPATH_FUNC_END();
742         return ret;
743 }
744
745 EGLDisplay
746 tracepath_eglGetCurrentDisplay(void)
747 {
748         EGLDisplay ret = EGL_NO_DISPLAY;
749
750         _COREGL_TRACEPATH_FUNC_BEGIN();
751         ret = _orig_tracepath_eglGetCurrentDisplay();
752         goto finish;
753
754 finish:
755         _COREGL_TRACEPATH_FUNC_END();
756         return ret;
757 }
758
759 EGLBoolean
760 tracepath_eglQueryContext(EGLDisplay dpy, EGLContext ctx, EGLint attribute,
761                                                   EGLint *value)
762 {
763         EGLBoolean ret = EGL_FALSE;
764
765         _COREGL_TRACEPATH_FUNC_BEGIN();
766         ret = _orig_tracepath_eglQueryContext(dpy, ctx, attribute, value);
767         goto finish;
768
769 finish:
770         _COREGL_TRACEPATH_FUNC_END();
771         return ret;
772 }
773
774 EGLBoolean
775 tracepath_eglWaitGL(void)
776 {
777         EGLBoolean ret = EGL_FALSE;
778
779         _COREGL_TRACEPATH_FUNC_BEGIN();
780         ret = _orig_tracepath_eglWaitGL();
781
782         _COREGL_TRACE_SURFACE(0, 1, "EGLWAITGL");
783
784         goto finish;
785
786 finish:
787         _COREGL_TRACEPATH_FUNC_END();
788         return ret;
789 }
790
791 EGLBoolean
792 tracepath_eglWaitNative(EGLint engine)
793 {
794         EGLBoolean ret = EGL_FALSE;
795
796         _COREGL_TRACEPATH_FUNC_BEGIN();
797         ret = _orig_tracepath_eglWaitNative(engine);
798         goto finish;
799
800 finish:
801         _COREGL_TRACEPATH_FUNC_END();
802         return ret;
803 }
804
805 EGLBoolean
806 tracepath_eglSwapBuffers(EGLDisplay dpy, EGLSurface surface)
807 {
808         EGLBoolean ret = EGL_FALSE;
809
810         _COREGL_TRACE_SURFACE(0, 1, "SWAPBUFFERS");
811
812         _COREGL_TRACEPATH_FUNC_BEGIN();
813         ret = _orig_tracepath_eglSwapBuffers(dpy, surface);
814
815         goto finish;
816
817 finish:
818         _COREGL_TRACEPATH_FUNC_END();
819         if (unlikely(get_trace_api_frame_flag() == 1)) {
820                 if (unlikely(get_trace_api_all_flag() == 1)) {
821                         _COREGL_TRACE_API_OUTPUT(1);
822                 } else {
823                         _COREGL_TRACE_API_OUTPUT(0);
824                 }
825                 _COREGL_TRACE_API_RESET_FRAME();
826         } else {
827                 _COREGL_TRACE_API_OUTPUT(0);
828         }
829         _COREGL_TRACE_MEM_OUTPUT(0);
830         return ret;
831 }
832
833 EGLBoolean
834 tracepath_eglSwapBuffersWithDamageEXT(EGLDisplay dpy, EGLSurface surface,
835                                                                           EGLint *rects, EGLint n_rects)
836 {
837         EGLBoolean ret = EGL_FALSE;
838
839         _COREGL_TRACE_SURFACE(0, 1, "SWAPBUFFERS");
840
841         _COREGL_TRACEPATH_FUNC_BEGIN();
842         ret = _orig_tracepath_eglSwapBuffersWithDamageEXT(dpy, surface, rects, n_rects);
843
844         goto finish;
845
846 finish:
847         _COREGL_TRACEPATH_FUNC_END();
848         if (unlikely(get_trace_api_frame_flag() == 1)) {
849                 if (unlikely(get_trace_api_all_flag() == 1)) {
850                         _COREGL_TRACE_API_OUTPUT(1);
851                 } else {
852                         _COREGL_TRACE_API_OUTPUT(0);
853                 }
854                 _COREGL_TRACE_API_RESET_FRAME();
855         } else {
856                 _COREGL_TRACE_API_OUTPUT(0);
857         }
858         _COREGL_TRACE_MEM_OUTPUT(0);
859         return ret;
860 }
861
862 EGLBoolean
863 tracepath_eglSwapBuffersRegionEXT(EGLDisplay dpy, EGLSurface surface,
864                                                                   EGLint numRects, const EGLint *rects)
865 {
866         EGLBoolean ret = EGL_FALSE;
867
868         _COREGL_TRACE_SURFACE(0, 1, "SWAPBUFFERS");
869
870         _COREGL_TRACEPATH_FUNC_BEGIN();
871         ret = _orig_tracepath_eglSwapBuffersRegionEXT(dpy, surface, numRects, rects);
872
873         goto finish;
874
875 finish:
876         _COREGL_TRACEPATH_FUNC_END();
877         if (unlikely(get_trace_api_frame_flag() == 1)) {
878                 if (unlikely(get_trace_api_all_flag() == 1)) {
879                         _COREGL_TRACE_API_OUTPUT(1);
880                 } else {
881                         _COREGL_TRACE_API_OUTPUT(0);
882                 }
883                 _COREGL_TRACE_API_RESET_FRAME();
884         } else {
885                 _COREGL_TRACE_API_OUTPUT(0);
886         }
887         _COREGL_TRACE_MEM_OUTPUT(0);
888         return ret;
889 }
890
891 EGLBoolean
892 tracepath_eglCopyBuffers(EGLDisplay dpy, EGLSurface surface,
893                                                  EGLNativePixmapType target)
894 {
895         EGLBoolean ret = EGL_FALSE;
896
897         _COREGL_TRACEPATH_FUNC_BEGIN();
898         ret = _orig_tracepath_eglCopyBuffers(dpy, surface, target);
899         goto finish;
900
901 finish:
902         _COREGL_TRACEPATH_FUNC_END();
903         return ret;
904 }
905
906 _eng_fn
907 tracepath_eglGetProcAddress(const char *procname)
908 {
909         _eng_fn ret = NULL;
910
911         _COREGL_TRACEPATH_FUNC_BEGIN();
912
913 #define _COREGL_SYMBOL(RET_TYPE, FUNC_NAME, PARAM_LIST) \
914         if (strcmp(procname, #FUNC_NAME) == 0) \
915         { \
916                 _eng_fn ret_orig = NULL; \
917                 ret_orig = _orig_tracepath_eglGetProcAddress(procname); \
918                 if (ret_orig != NULL) \
919                         ret = (_eng_fn)ovr_##FUNC_NAME; \
920                 goto finish; \
921         }
922
923 #define _COREGL_EXT_SYMBOL_ALIAS(ALIAS_NAME, FUNC_NAME) \
924    if (strcmp(procname, #ALIAS_NAME) == 0) \
925    { \
926                 _eng_fn ret_orig = NULL; \
927                 ret_orig = _orig_tracepath_eglGetProcAddress(#ALIAS_NAME); \
928                 if (ret_orig != NULL) \
929                         ret = (_eng_fn)ovr_##FUNC_NAME; \
930                 goto finish; \
931    }
932
933 #include "../headers/sym_egl.h"
934 #include "../headers/sym_gl1.h"
935 #include "../headers/sym_gl2.h"
936 #undef _COREGL_SYMBOL
937 #undef _COREGL_EXT_SYMBOL_ALIAS
938
939         ret = _orig_tracepath_eglGetProcAddress(procname);
940         if (ret != NULL) {
941                 COREGL_WARN("TRACEPATH can't support '%s' (tracing for this function will be ignored)",
942                                         procname);
943         }
944
945         goto finish;
946
947 finish:
948         _COREGL_TRACEPATH_FUNC_END();
949         return ret;
950 }
951
952 const char *
953 tracepath_eglQueryString(EGLDisplay dpy, EGLint name)
954 {
955         const char *ret = NULL;
956
957         _COREGL_TRACEPATH_FUNC_BEGIN();
958         ret = _orig_tracepath_eglQueryString(dpy, name);
959         goto finish;
960
961 finish:
962         _COREGL_TRACEPATH_FUNC_END();
963         return ret;
964 }
965
966 EGLImageKHR
967 tracepath_eglCreateImageKHR (EGLDisplay dpy, EGLContext ctx, EGLenum target,
968                                                          EGLClientBuffer buffer, const EGLint *attrib_list)
969 {
970         void *ret = NULL;
971
972         _COREGL_TRACEPATH_FUNC_BEGIN();
973         ret = _orig_tracepath_eglCreateImageKHR(dpy, ctx, target, buffer, attrib_list);
974         goto finish;
975
976 finish:
977         _COREGL_TRACEPATH_FUNC_END();
978         return ret;
979 }
980
981 EGLBoolean
982 tracepath_eglDestroyImageKHR(EGLDisplay dpy, EGLImageKHR image)
983 {
984         EGLBoolean ret = EGL_FALSE;
985
986         _COREGL_TRACEPATH_FUNC_BEGIN();
987         ret = _orig_tracepath_eglDestroyImageKHR(dpy, image);
988         goto finish;
989
990 finish:
991         _COREGL_TRACEPATH_FUNC_END();
992         return ret;
993 }
994
995 void *
996 tracepath_eglMapImageSEC(EGLDisplay dpy, EGLImageKHR image, EGLint device_type,
997                                                  EGLint access_option)
998 {
999         void *ret = NULL;
1000
1001         _COREGL_TRACEPATH_FUNC_BEGIN();
1002         ret = _orig_tracepath_eglMapImageSEC(dpy, image, device_type, access_option);
1003         goto finish;
1004
1005 finish:
1006         _COREGL_TRACEPATH_FUNC_END();
1007         return ret;
1008 }
1009
1010 EGLBoolean
1011 tracepath_eglUnmapImageSEC(EGLDisplay dpy, EGLImageKHR image,
1012                                                    EGLint device_type)
1013 {
1014         EGLBoolean ret = EGL_FALSE;
1015
1016         _COREGL_TRACEPATH_FUNC_BEGIN();
1017         ret = _orig_tracepath_eglUnmapImageSEC(dpy, image, device_type);
1018         goto finish;
1019
1020 finish:
1021         _COREGL_TRACEPATH_FUNC_END();
1022         return ret;
1023 }
1024
1025 EGLBoolean
1026 tracepath_eglGetImageAttribSEC(EGLDisplay dpy, EGLImageKHR image,
1027                                                            EGLint attribute, EGLint *value)
1028 {
1029         EGLBoolean ret = EGL_FALSE;
1030
1031         _COREGL_TRACEPATH_FUNC_BEGIN();
1032         ret = _orig_tracepath_eglGetImageAttribSEC(dpy, image, attribute, value);
1033         goto finish;
1034
1035 finish:
1036         _COREGL_TRACEPATH_FUNC_END();
1037         return ret;
1038 }
1039
1040 EGLBoolean
1041 tracepath_eglLockSurfaceKHR(EGLDisplay display, EGLSurface surface,
1042                                                         const EGLint *attrib_list)
1043 {
1044         EGLBoolean ret = EGL_FALSE;
1045
1046         _COREGL_TRACEPATH_FUNC_BEGIN();
1047         ret = _orig_tracepath_eglLockSurfaceKHR(display, surface, attrib_list);
1048         goto finish;
1049
1050 finish:
1051         _COREGL_TRACEPATH_FUNC_END();
1052         return ret;
1053 }
1054
1055 EGLBoolean
1056 tracepath_eglUnlockSurfaceKHR(EGLDisplay display, EGLSurface surface)
1057 {
1058         EGLBoolean ret = EGL_FALSE;
1059
1060         _COREGL_TRACEPATH_FUNC_BEGIN();
1061         ret = _orig_tracepath_eglUnlockSurfaceKHR(display, surface);
1062         goto finish;
1063
1064 finish:
1065         _COREGL_TRACEPATH_FUNC_END();
1066         return ret;
1067 }
1068
1069 EGLBoolean
1070 tracepath_eglBindWaylandDisplayWL(EGLDisplay dpy, void *display)
1071 {
1072         EGLBoolean ret = EGL_FALSE;
1073
1074         _COREGL_TRACEPATH_FUNC_BEGIN();
1075         ret = _orig_tracepath_eglBindWaylandDisplayWL(dpy, display);
1076
1077         goto finish;
1078
1079 finish:
1080         _COREGL_TRACEPATH_FUNC_END();
1081         return ret;
1082 }
1083
1084 EGLBoolean
1085 tracepath_eglUnbindWaylandDisplayWL(EGLDisplay dpy, void *display)
1086 {
1087         EGLBoolean ret = EGL_FALSE;
1088
1089         _COREGL_TRACEPATH_FUNC_BEGIN();
1090         ret = _orig_tracepath_eglUnbindWaylandDisplayWL(dpy, display);
1091
1092         goto finish;
1093
1094 finish:
1095         _COREGL_TRACEPATH_FUNC_END();
1096         return ret;
1097 }
1098
1099 EGLBoolean
1100 tracepath_eglQueryWaylandBufferWL(EGLDisplay dpy, void *buffer,
1101                                                                   EGLint attribute, EGLint *value)
1102 {
1103         EGLBoolean ret = EGL_FALSE;
1104
1105         _COREGL_TRACEPATH_FUNC_BEGIN();
1106         ret = _orig_tracepath_eglQueryWaylandBufferWL(dpy, buffer, attribute, value);
1107
1108         goto finish;
1109
1110 finish:
1111         _COREGL_TRACEPATH_FUNC_END();
1112         return ret;
1113 }
1114
1115 EGLBoolean
1116 tracepath_eglSetDamageRegionKHR(EGLDisplay dpy, EGLSurface surface,
1117                                                                 EGLint *rects, EGLint n_rects)
1118 {
1119         EGLBoolean ret = EGL_FALSE;
1120
1121         _COREGL_TRACEPATH_FUNC_BEGIN();
1122         ret = _orig_tracepath_eglSetDamageRegionKHR(dpy, surface, rects, n_rects);
1123
1124         goto finish;
1125
1126 finish:
1127         _COREGL_TRACEPATH_FUNC_END();
1128         return ret;
1129 }
1130
1131 EGLBoolean
1132 tracepath_eglSwapBuffersWithDamageKHR(EGLDisplay dpy, EGLSurface surface,
1133                                                                           EGLint *rects, EGLint n_rects)
1134 {
1135         EGLBoolean ret = EGL_FALSE;
1136
1137         _COREGL_TRACEPATH_FUNC_BEGIN();
1138         ret = _orig_tracepath_eglSwapBuffersWithDamageKHR(dpy, surface, rects, n_rects);
1139
1140         goto finish;
1141
1142 finish:
1143         _COREGL_TRACEPATH_FUNC_END();
1144         return ret;
1145 }
1146
1147 EGLBoolean
1148 tracepath_eglFrontBufferSetSEC(EGLDisplay dpy, EGLSurface surface,
1149                                                            EGLBoolean set)
1150 {
1151         EGLBoolean ret = EGL_FALSE;
1152
1153         _COREGL_TRACEPATH_FUNC_BEGIN();
1154         ret = _orig_tracepath_eglFrontBufferSetSEC(dpy, surface, set);
1155
1156         goto finish;
1157
1158 finish:
1159         _COREGL_TRACEPATH_FUNC_END();
1160         return ret;
1161 }