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