Add coding style guide.
[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                 sprintf(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                         sprintf(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                         sprintf(ment, "eglDestroyContext completed (EGLCTX=[%12p])", ctx);
641                         _dump_context_info(ment, 1);
642                 }
643         }
644 #endif // COREGL_TRACEPATH_TRACE_CONTEXT_INFO
645         return ret;
646 }
647
648 EGLBoolean
649 tracepath_eglMakeCurrent(EGLDisplay dpy, EGLSurface draw, EGLSurface read,
650                          EGLContext ctx)
651 {
652         EGLBoolean ret = EGL_FALSE;
653
654         _COREGL_TRACEPATH_FUNC_BEGIN();
655         ret = _orig_tracepath_eglMakeCurrent(dpy, draw, read, ctx);
656         goto finish;
657
658 finish:
659         _COREGL_TRACEPATH_FUNC_END();
660         {
661                 MY_MODULE_TSTATE *tstate = NULL;
662
663                 GET_MY_TSTATE(tstate, get_current_thread_state());
664                 if (tstate == NULL) {
665                         init_new_thread_state();
666
667                         GET_MY_TSTATE(tstate, get_current_thread_state());
668                         AST(tstate != NULL);
669                 }
670
671                 Ctx_Data *oldctx = tstate->ctx;
672
673                 if (ctx != EGL_NO_CONTEXT) {
674                         tstate->ctx = tracepath_get_context(ctx);
675                         if (tstate->ctx != NULL)
676                                 tstate->ctx->mc_count++;
677                 } else {
678                         tstate->ctx = NULL;
679                 }
680
681                 if (oldctx != NULL)
682                         tracepath_remove_context(oldctx->handle);
683
684                 tstate->surf_draw = draw;
685                 tstate->surf_read = read;
686         }
687 #ifdef COREGL_TRACEPATH_TRACE_STATE_INFO
688         if (unlikely(trace_state_flag == 1)) {
689                 if (_orig_tracepath_eglMakeCurrent == _sym_eglMakeCurrent)
690                         tracepath_dump_context_states(0);
691         }
692 #endif // COREGL_TRACEPATH_TRACE_STATE_INFO
693 #ifdef COREGL_TRACEPATH_TRACE_CONTEXT_INFO
694         if (unlikely(trace_ctx_flag == 1)) {
695                 if (_orig_tracepath_eglMakeCurrent == _sym_eglMakeCurrent) {
696                         char ment[256];
697                         sprintf(ment, "eglMakeCurrent finished (EGLCTX=[%12p] Surf=[D:%12p R:%12p])",
698                                 ctx, draw, read);
699                         _dump_context_info(ment, 0);
700                 }
701         }
702 #endif // COREGL_TRACEPATH_TRACE_CONTEXT_INFO
703         return ret;
704 }
705
706 EGLContext
707 tracepath_eglGetCurrentContext(void)
708 {
709         EGLContext ret = EGL_NO_CONTEXT;
710
711         _COREGL_TRACEPATH_FUNC_BEGIN();
712         ret = _orig_tracepath_eglGetCurrentContext();
713         goto finish;
714
715 finish:
716         _COREGL_TRACEPATH_FUNC_END();
717         return ret;
718 }
719
720 EGLSurface
721 tracepath_eglGetCurrentSurface(EGLint readdraw)
722 {
723         EGLSurface ret = EGL_NO_SURFACE;
724
725         _COREGL_TRACEPATH_FUNC_BEGIN();
726         ret = _orig_tracepath_eglGetCurrentSurface(readdraw);
727         goto finish;
728
729 finish:
730         _COREGL_TRACEPATH_FUNC_END();
731         return ret;
732 }
733
734 EGLDisplay
735 tracepath_eglGetCurrentDisplay(void)
736 {
737         EGLDisplay ret = EGL_NO_DISPLAY;
738
739         _COREGL_TRACEPATH_FUNC_BEGIN();
740         ret = _orig_tracepath_eglGetCurrentDisplay();
741         goto finish;
742
743 finish:
744         _COREGL_TRACEPATH_FUNC_END();
745         return ret;
746 }
747
748 EGLBoolean
749 tracepath_eglQueryContext(EGLDisplay dpy, EGLContext ctx, EGLint attribute,
750                           EGLint *value)
751 {
752         EGLBoolean ret = EGL_FALSE;
753
754         _COREGL_TRACEPATH_FUNC_BEGIN();
755         ret = _orig_tracepath_eglQueryContext(dpy, ctx, attribute, value);
756         goto finish;
757
758 finish:
759         _COREGL_TRACEPATH_FUNC_END();
760         return ret;
761 }
762
763 EGLBoolean
764 tracepath_eglWaitGL(void)
765 {
766         EGLBoolean ret = EGL_FALSE;
767
768         _COREGL_TRACEPATH_FUNC_BEGIN();
769         ret = _orig_tracepath_eglWaitGL();
770
771         _COREGL_TRACE_SURFACE(0, 1, "EGLWAITGL");
772
773         goto finish;
774
775 finish:
776         _COREGL_TRACEPATH_FUNC_END();
777         return ret;
778 }
779
780 EGLBoolean
781 tracepath_eglWaitNative(EGLint engine)
782 {
783         EGLBoolean ret = EGL_FALSE;
784
785         _COREGL_TRACEPATH_FUNC_BEGIN();
786         ret = _orig_tracepath_eglWaitNative(engine);
787         goto finish;
788
789 finish:
790         _COREGL_TRACEPATH_FUNC_END();
791         return ret;
792 }
793
794 EGLBoolean
795 tracepath_eglSwapBuffers(EGLDisplay dpy, EGLSurface surface)
796 {
797         EGLBoolean ret = EGL_FALSE;
798
799         _COREGL_TRACE_SURFACE(0, 1, "SWAPBUFFERS");
800
801         _COREGL_TRACEPATH_FUNC_BEGIN();
802         ret = _orig_tracepath_eglSwapBuffers(dpy, surface);
803
804         goto finish;
805
806 finish:
807         _COREGL_TRACEPATH_FUNC_END();
808         if (unlikely(trace_api_frame_flag == 1)) {
809                 if (unlikely(trace_api_all_flag == 1)) {
810                         _COREGL_TRACE_API_OUTPUT(1);
811                 } else {
812                         _COREGL_TRACE_API_OUTPUT(0);
813                 }
814                 _COREGL_TRACE_API_RESET_FRAME();
815         } else {
816                 _COREGL_TRACE_API_OUTPUT(0);
817         }
818         _COREGL_TRACE_MEM_OUTPUT(0);
819         return ret;
820 }
821
822 EGLBoolean
823 tracepath_eglSwapBuffersWithDamageEXT(EGLDisplay dpy, EGLSurface surface,
824                                       EGLint *rects, EGLint n_rects)
825 {
826         EGLBoolean ret = EGL_FALSE;
827
828         _COREGL_TRACE_SURFACE(0, 1, "SWAPBUFFERS");
829
830         _COREGL_TRACEPATH_FUNC_BEGIN();
831         ret = _orig_tracepath_eglSwapBuffersWithDamageEXT(dpy, surface, rects, n_rects);
832
833         goto finish;
834
835 finish:
836         _COREGL_TRACEPATH_FUNC_END();
837         if (unlikely(trace_api_frame_flag == 1)) {
838                 if (unlikely(trace_api_all_flag == 1)) {
839                         _COREGL_TRACE_API_OUTPUT(1);
840                 } else {
841                         _COREGL_TRACE_API_OUTPUT(0);
842                 }
843                 _COREGL_TRACE_API_RESET_FRAME();
844         } else {
845                 _COREGL_TRACE_API_OUTPUT(0);
846         }
847         _COREGL_TRACE_MEM_OUTPUT(0);
848         return ret;
849 }
850
851 EGLBoolean
852 tracepath_eglSwapBuffersRegionEXT(EGLDisplay dpy, EGLSurface surface,
853                                   EGLint numRects, const EGLint *rects)
854 {
855         EGLBoolean ret = EGL_FALSE;
856
857         _COREGL_TRACE_SURFACE(0, 1, "SWAPBUFFERS");
858
859         _COREGL_TRACEPATH_FUNC_BEGIN();
860         ret = _orig_tracepath_eglSwapBuffersRegionEXT(dpy, surface, numRects, rects);
861
862         goto finish;
863
864 finish:
865         _COREGL_TRACEPATH_FUNC_END();
866         if (unlikely(trace_api_frame_flag == 1)) {
867                 if (unlikely(trace_api_all_flag == 1)) {
868                         _COREGL_TRACE_API_OUTPUT(1);
869                 } else {
870                         _COREGL_TRACE_API_OUTPUT(0);
871                 }
872                 _COREGL_TRACE_API_RESET_FRAME();
873         } else {
874                 _COREGL_TRACE_API_OUTPUT(0);
875         }
876         _COREGL_TRACE_MEM_OUTPUT(0);
877         return ret;
878 }
879
880 EGLBoolean
881 tracepath_eglCopyBuffers(EGLDisplay dpy, EGLSurface surface,
882                          EGLNativePixmapType target)
883 {
884         EGLBoolean ret = EGL_FALSE;
885
886         _COREGL_TRACEPATH_FUNC_BEGIN();
887         ret = _orig_tracepath_eglCopyBuffers(dpy, surface, target);
888         goto finish;
889
890 finish:
891         _COREGL_TRACEPATH_FUNC_END();
892         return ret;
893 }
894
895 _eng_fn
896 tracepath_eglGetProcAddress(const char *procname)
897 {
898         _eng_fn ret = NULL;
899
900         _COREGL_TRACEPATH_FUNC_BEGIN();
901
902 #define _COREGL_SYMBOL(RET_TYPE, FUNC_NAME, PARAM_LIST) \
903         if (strcmp(procname, #FUNC_NAME) == 0) \
904         { \
905                 _eng_fn ret_orig = NULL; \
906                 ret_orig = _orig_tracepath_eglGetProcAddress(procname); \
907                 if (ret_orig != NULL) \
908                         ret = (_eng_fn)ovr_##FUNC_NAME; \
909                 goto finish; \
910         }
911
912 #define _COREGL_EXT_SYMBOL_ALIAS(ALIAS_NAME, FUNC_NAME) \
913    if (strcmp(procname, #ALIAS_NAME) == 0) \
914    { \
915                 _eng_fn ret_orig = NULL; \
916                 ret_orig = _orig_tracepath_eglGetProcAddress(#ALIAS_NAME); \
917                 if (ret_orig != NULL) \
918                         ret = (_eng_fn)ovr_##FUNC_NAME; \
919                 goto finish; \
920    }
921
922 #include "../../headers/sym_egl.h"
923 #include "../../headers/sym_gl.h"
924 #undef _COREGL_SYMBOL
925 #undef _COREGL_EXT_SYMBOL_ALIAS
926
927         ret = _orig_tracepath_eglGetProcAddress(procname);
928         if (ret != NULL) {
929                 COREGL_WRN("\E[40;31;1mTRACEPATH can't support '%s' (tracing for this function will be ignored)\E[0m\n",
930                            procname);
931         }
932
933         goto finish;
934
935 finish:
936         _COREGL_TRACEPATH_FUNC_END();
937         return ret;
938 }
939
940 const char *
941 tracepath_eglQueryString(EGLDisplay dpy, EGLint name)
942 {
943         const char *ret = NULL;
944
945         _COREGL_TRACEPATH_FUNC_BEGIN();
946         ret = _orig_tracepath_eglQueryString(dpy, name);
947         goto finish;
948
949 finish:
950         _COREGL_TRACEPATH_FUNC_END();
951         return ret;
952 }
953
954 EGLImageKHR
955 tracepath_eglCreateImageKHR (EGLDisplay dpy, EGLContext ctx, EGLenum target,
956                              EGLClientBuffer buffer, const EGLint *attrib_list)
957 {
958         void *ret = NULL;
959
960         _COREGL_TRACEPATH_FUNC_BEGIN();
961         ret = _orig_tracepath_eglCreateImageKHR(dpy, ctx, target, buffer, attrib_list);
962         goto finish;
963
964 finish:
965         _COREGL_TRACEPATH_FUNC_END();
966         return ret;
967 }
968
969 EGLBoolean
970 tracepath_eglDestroyImageKHR(EGLDisplay dpy, EGLImageKHR image)
971 {
972         EGLBoolean ret = EGL_FALSE;
973
974         _COREGL_TRACEPATH_FUNC_BEGIN();
975         ret = _orig_tracepath_eglDestroyImageKHR(dpy, image);
976         goto finish;
977
978 finish:
979         _COREGL_TRACEPATH_FUNC_END();
980         return ret;
981 }
982
983 void *
984 tracepath_eglMapImageSEC(EGLDisplay dpy, EGLImageKHR image, EGLint device_type,
985                          EGLint access_option)
986 {
987         void *ret = NULL;
988
989         _COREGL_TRACEPATH_FUNC_BEGIN();
990         ret = _orig_tracepath_eglMapImageSEC(dpy, image, device_type, access_option);
991         goto finish;
992
993 finish:
994         _COREGL_TRACEPATH_FUNC_END();
995         return ret;
996 }
997
998 EGLBoolean
999 tracepath_eglUnmapImageSEC(EGLDisplay dpy, EGLImageKHR image,
1000                            EGLint device_type)
1001 {
1002         EGLBoolean ret = EGL_FALSE;
1003
1004         _COREGL_TRACEPATH_FUNC_BEGIN();
1005         ret = _orig_tracepath_eglUnmapImageSEC(dpy, image, device_type);
1006         goto finish;
1007
1008 finish:
1009         _COREGL_TRACEPATH_FUNC_END();
1010         return ret;
1011 }
1012
1013 EGLBoolean
1014 tracepath_eglGetImageAttribSEC(EGLDisplay dpy, EGLImageKHR image,
1015                                EGLint attribute, EGLint *value)
1016 {
1017         EGLBoolean ret = EGL_FALSE;
1018
1019         _COREGL_TRACEPATH_FUNC_BEGIN();
1020         ret = _orig_tracepath_eglGetImageAttribSEC(dpy, image, attribute, value);
1021         goto finish;
1022
1023 finish:
1024         _COREGL_TRACEPATH_FUNC_END();
1025         return ret;
1026 }
1027
1028 EGLBoolean
1029 tracepath_eglLockSurfaceKHR(EGLDisplay display, EGLSurface surface,
1030                             const EGLint *attrib_list)
1031 {
1032         EGLBoolean ret = EGL_FALSE;
1033
1034         _COREGL_TRACEPATH_FUNC_BEGIN();
1035         ret = _orig_tracepath_eglLockSurfaceKHR(display, surface, attrib_list);
1036         goto finish;
1037
1038 finish:
1039         _COREGL_TRACEPATH_FUNC_END();
1040         return ret;
1041 }
1042
1043 EGLBoolean
1044 tracepath_eglUnlockSurfaceKHR(EGLDisplay display, EGLSurface surface)
1045 {
1046         EGLBoolean ret = EGL_FALSE;
1047
1048         _COREGL_TRACEPATH_FUNC_BEGIN();
1049         ret = _orig_tracepath_eglUnlockSurfaceKHR(display, surface);
1050         goto finish;
1051
1052 finish:
1053         _COREGL_TRACEPATH_FUNC_END();
1054         return ret;
1055 }
1056
1057 EGLBoolean
1058 tracepath_eglBindWaylandDisplayWL(EGLDisplay dpy, void *display)
1059 {
1060         EGLBoolean ret = EGL_FALSE;
1061
1062         _COREGL_TRACEPATH_FUNC_BEGIN();
1063         ret = _orig_tracepath_eglBindWaylandDisplayWL(dpy, display);
1064
1065         goto finish;
1066
1067 finish:
1068         _COREGL_TRACEPATH_FUNC_END();
1069         return ret;
1070 }
1071
1072 EGLBoolean
1073 tracepath_eglUnbindWaylandDisplayWL(EGLDisplay dpy, void *display)
1074 {
1075         EGLBoolean ret = EGL_FALSE;
1076
1077         _COREGL_TRACEPATH_FUNC_BEGIN();
1078         ret = _orig_tracepath_eglUnbindWaylandDisplayWL(dpy, display);
1079
1080         goto finish;
1081
1082 finish:
1083         _COREGL_TRACEPATH_FUNC_END();
1084         return ret;
1085 }
1086
1087
1088 EGLBoolean
1089 tracepath_eglQueryWaylandBufferWL(EGLDisplay dpy, void *buffer,
1090                                   EGLint attribute, EGLint *value)
1091 {
1092         EGLBoolean ret = EGL_FALSE;
1093
1094         _COREGL_TRACEPATH_FUNC_BEGIN();
1095         ret = _orig_tracepath_eglQueryWaylandBufferWL(dpy, buffer, attribute, value);
1096
1097         goto finish;
1098
1099 finish:
1100         _COREGL_TRACEPATH_FUNC_END();
1101         return ret;
1102 }