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