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