tizen 2.4 release
[framework/graphics/coregl.git] / src / modules / fastpath / coregl_fastpath.c
1 #include "coregl_fastpath.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 #define _COREGL_SYMBOL(RET_TYPE, FUNC_NAME, PARAM_LIST)     RET_TYPE (*_orig_fastpath_##FUNC_NAME) PARAM_LIST = NULL;
11 #include "../../headers/sym.h"
12 #undef _COREGL_SYMBOL
13
14 Fastpath_Opt_Flag   fp_opt = FP_UNKNOWN_PATH;
15
16 int                 debug_nofp = 0;
17 FILE               *trace_fp = NULL;
18
19 GLenum              FPGL_Error = GL_NO_ERROR;
20
21 GLGlueContext_List *gctx_list = NULL;
22
23 Mutex               init_context_mutex = MUTEX_INITIALIZER;
24 GLGlueContext      *initial_ctx = NULL;
25
26 Mutex               ctx_list_access_mutex = MUTEX_INITIALIZER;
27
28 GLContext_List     *glctx_list = NULL;
29 static int          api_gl_version=COREGL_GLAPI_2;
30
31 static void
32 _state_get_texture_states(GLenum pname, GLint *params)
33 {
34         GLuint cur_active_tex = 0;
35
36         AST(initial_ctx != NULL);
37
38         _orig_fastpath_glGetIntegerv(GL_ACTIVE_TEXTURE, (GLint *)&cur_active_tex);
39         int i;
40         for (i = 0; i < initial_ctx->gl_num_tex_units[0]; i++)
41         {
42                 _orig_fastpath_glActiveTexture(GL_TEXTURE0 + i);
43                 _orig_fastpath_glGetIntegerv(pname, (GLint *)&params[i]);
44         }
45         _orig_fastpath_glActiveTexture(cur_active_tex);
46 }
47
48 static void
49 _state_get_draw_buffers(GLenum *params)
50 {
51         AST(initial_ctx != NULL);
52
53         int i;
54         for (i = 0; i < initial_ctx->gl_num_draw_buffers[0]; i++)
55         {
56                 _orig_fastpath_glGetIntegerv(GL_DRAW_BUFFER0 + i, (GLint *)&params[i]);
57         }
58 }
59
60 static void
61 _state_get_transform_feedback_buffer_bindings(GLuint *params)
62 {
63         AST(initial_ctx != NULL);
64
65         int i;
66         for (i = 0; i < initial_ctx->gl_num_transform_feedback_separate_attribs[0]; i++)
67         {
68                 _orig_fastpath_glGetIntegeri_v(GL_TRANSFORM_FEEDBACK_BUFFER_BINDING, i, (GLint *)&params[i]);
69         }
70 }
71
72 static void
73 _state_get_transform_feedback_buffer_bindings_offset(GLintptr *params)
74 {
75         AST(initial_ctx != NULL);
76
77         int i;
78         for (i = 0; i < initial_ctx->gl_num_transform_feedback_separate_attribs[0]; i++)
79         {
80                 _orig_fastpath_glGetIntegeri_v(GL_TRANSFORM_FEEDBACK_BUFFER_START, i, (GLint *)&params[i]);
81         }
82 }
83
84 static void
85 _state_get_transform_feedback_buffer_bindings_size(GLsizeiptr *params)
86 {
87         AST(initial_ctx != NULL);
88
89         int i;
90         for (i = 0; i < initial_ctx->gl_num_transform_feedback_separate_attribs[0]; i++)
91         {
92                 _orig_fastpath_glGetIntegeri_v(GL_TRANSFORM_FEEDBACK_BUFFER_SIZE, i, (GLint *)&params[i]);
93         }
94 }
95
96 static void
97 _state_get_uniform_buffer_bindings(GLuint *params)
98 {
99         AST(initial_ctx != NULL);
100
101         int i;
102         for (i = 0; i < initial_ctx->gl_num_uniform_buffer_bindings[0]; i++)
103         {
104 /////////////////////////////////////////////////////////////////////////////////
105 // XXXX : AVOID SEGFAULT in ADRENO
106                 ((GLint *)params)[i] = 0;
107 //              _orig_fastpath_glGetIntegeri_v(GL_UNIFORM_BUFFER_BINDING, i, (GLint *)&params[i]);
108 /////////////////////////////////////////////////////////////////////////////////
109         }
110 }
111
112 static void
113 _state_get_uniform_buffer_bindings_offset(GLintptr *params)
114 {
115         AST(initial_ctx != NULL);
116
117         int i;
118         for (i = 0; i < initial_ctx->gl_num_uniform_buffer_bindings[0]; i++)
119         {
120                 _orig_fastpath_glGetIntegeri_v(GL_UNIFORM_BUFFER_START, i, (GLint *)&params[i]);
121         }
122 }
123
124 static void
125 _state_get_uniform_buffer_bindings_size(GLsizeiptr *params)
126 {
127         AST(initial_ctx != NULL);
128
129         int i;
130         for (i = 0; i < initial_ctx->gl_num_uniform_buffer_bindings[0]; i++)
131         {
132                 _orig_fastpath_glGetIntegeri_v(GL_UNIFORM_BUFFER_SIZE, i, (GLint *)&params[i]);
133         }
134 }
135
136 void
137 fastpath_state_get_draw_buffers(GLenum *params)
138 {
139         _state_get_draw_buffers(params);
140 }
141
142 void
143 init_modules_fastpath()
144 {
145         int fastpath_opt = 0;
146         int fastpath_force_off_opt = 0;
147
148         COREGL_LOG("[CoreGL] <Fastpath> : ");
149
150         fastpath_opt = atoi(get_env_setting("COREGL_FASTPATH"));
151         fastpath_force_off_opt = atoi(get_env_setting("COREGL_FASTPATH_FORCE_OFF"));
152
153         if (fastpath_force_off_opt == 1)
154         {
155                 COREGL_LOG("\E[40;31;1m(DISABLED by force option)\E[0m ");
156                 fastpath_opt = 0;
157         }
158
159         switch (fastpath_opt)
160         {
161                 case 1:
162                         COREGL_LOG("(%d) Fastpath enabled...\n", fastpath_opt);
163                         fp_opt = FP_FAST_PATH;
164                         break;
165                 default:
166                         COREGL_LOG("(%d) Default API path enabled...\n", fastpath_opt);
167                         fp_opt = FP_NORMAL_PATH;
168                         break;
169         }
170
171         debug_nofp = atoi(get_env_setting("COREGL_DEBUG_NOFP"));
172
173 }
174
175 void
176 deinit_modules_fastpath()
177 {
178         GLContext_List *current = NULL;
179
180         AST(mutex_lock(&ctx_list_access_mutex) == 1);
181
182         // Destroy remained context & Detect leaks
183         int retry_destroy = 0;
184
185         while (1)
186         {
187                 retry_destroy = 0;
188                 current = glctx_list;
189                 while (current)
190                 {
191                         if (current->cstate != NULL)
192                         {
193                                 COREGL_WRN("\E[40;31;1mContext attached to [dpy=%p|rctx=%p] has not been completely destroyed.(leak)\E[0m\n", current->cstate->rdpy, current->cstate->rctx);
194
195                                 _orig_fastpath_eglMakeCurrent(current->cstate->rdpy, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
196                                 _orig_fastpath_eglDestroyContext(current->cstate->rdpy, current->cstate->rctx);
197
198                                 fastpath_remove_context_states_from_list(current->cstate, NULL);
199                                 retry_destroy = 1;
200                                 break;
201                         }
202
203                         glctx_list = current->next;
204                         free(current);
205                         current = glctx_list;
206                 }
207                 if (retry_destroy == 0) break;
208         }
209         goto finish;
210
211 finish:
212         AST(mutex_unlock(&ctx_list_access_mutex) == 1);
213 }
214
215 void
216 init_modules_tstate_fastpath(GLThreadState *tstate)
217 {
218         MY_MODULE_TSTATE *tstate_mt = NULL;
219
220         tstate_mt = (MY_MODULE_TSTATE *)calloc(1, sizeof(MY_MODULE_TSTATE));
221
222         /* Prevent CID : 403055 */
223         if (tstate_mt != NULL)
224         {
225                 tstate_mt->binded_api = EGL_OPENGL_ES_API;
226
227                 tstate->module_data[MY_MODULE_ID] = tstate_mt;
228         }
229 }
230
231 void
232 deinit_modules_tstate_fastpath(GLThreadState *tstate)
233 {
234         if (tstate->module_data[MY_MODULE_ID] != NULL)
235         {
236                 free(tstate->module_data[MY_MODULE_ID]);
237                 tstate->module_data[MY_MODULE_ID] = NULL;
238         }
239 }
240
241 void
242 fastpath_apply_overrides()
243 {
244         switch(fp_opt)
245         {
246                 case FP_FAST_PATH:
247                         fastpath_apply_overrides_egl(1);
248                         fastpath_apply_overrides_gl(1);
249                         break;
250                 case FP_NORMAL_PATH:
251                         break;
252                 default:
253                         COREGL_ERR("Invalide GL Override Option!!!\n");
254                         break;
255         }
256 }
257
258
259 void
260 fastpath_apply_overrides_egl(int enable)
261 {
262 #define _COREGL_SYMBOL(RET_TYPE, FUNC_NAME, PARAM_LIST)     COREGL_INIT_ORIGINAL(_orig_fastpath_, FUNC_NAME);
263 # include "../../headers/sym_egl.h"
264 #undef _COREGL_SYMBOL
265
266         COREGL_OVERRIDE(fastpath_, eglGetProcAddress);
267
268         COREGL_OVERRIDE(fastpath_, eglBindAPI);
269         COREGL_OVERRIDE(fastpath_, eglQueryAPI);
270
271         COREGL_OVERRIDE(fastpath_, eglCreateContext);
272         COREGL_OVERRIDE(fastpath_, eglCreateImageKHR);
273         COREGL_OVERRIDE(fastpath_, eglMakeCurrent);
274         COREGL_OVERRIDE(fastpath_, eglDestroyContext);
275         COREGL_OVERRIDE(fastpath_, eglQueryContext);
276         COREGL_OVERRIDE(fastpath_, eglGetCurrentContext);
277         COREGL_OVERRIDE(fastpath_, eglReleaseThread);
278         COREGL_OVERRIDE(fastpath_, eglGetCurrentSurface);
279         COREGL_OVERRIDE(fastpath_, eglTerminate);
280         COREGL_OVERRIDE(fastpath_, eglGetCurrentDisplay);
281
282 }
283
284 void
285 fastpath_apply_overrides_gl(int enable)
286 {
287 #define _COREGL_START_API(version) api_gl_version = version;
288 #define _COREGL_END_API(version) api_gl_version = COREGL_GLAPI_2;
289 #define _COREGL_SYMBOL(RET_TYPE, FUNC_NAME, PARAM_LIST)     \
290    if(api_gl_version <= driver_gl_version) COREGL_INIT_ORIGINAL(_orig_fastpath_, FUNC_NAME);
291
292 # include "../../headers/sym_gl.h"
293 #undef _COREGL_SYMBOL
294 #undef _COREGL_START_API
295 #undef _COREGL_END_API
296
297         if (debug_nofp != 1)
298         {
299                 COREGL_OVERRIDE(fastpath_, glGetError);
300                 COREGL_OVERRIDE(fastpath_, glGetString);
301
302                 COREGL_OVERRIDE(fastpath_, glGetIntegerv);
303                 COREGL_OVERRIDE(fastpath_, glGetFloatv);
304                 COREGL_OVERRIDE(fastpath_, glGetBooleanv);
305
306                 COREGL_OVERRIDE(fastpath_, glActiveTexture);
307                 COREGL_OVERRIDE(fastpath_, glGenTextures);
308                 COREGL_OVERRIDE(fastpath_, glBindTexture);
309                 COREGL_OVERRIDE(fastpath_, glIsTexture);
310                 COREGL_OVERRIDE(fastpath_, glDeleteTextures);
311                 COREGL_OVERRIDE(fastpath_, glFramebufferTexture2D);
312
313                 COREGL_OVERRIDE(fastpath_, glGenBuffers);
314                 COREGL_OVERRIDE(fastpath_, glBindBuffer);
315                 COREGL_OVERRIDE(fastpath_, glIsBuffer);
316                 COREGL_OVERRIDE(fastpath_, glDeleteBuffers);
317
318                 COREGL_OVERRIDE(fastpath_, glGenFramebuffers);
319                 COREGL_OVERRIDE(fastpath_, glBindFramebuffer);
320                 COREGL_OVERRIDE(fastpath_, glIsFramebuffer);
321                 COREGL_OVERRIDE(fastpath_, glDeleteFramebuffers);
322                 COREGL_OVERRIDE(fastpath_, glGetFramebufferAttachmentParameteriv);
323
324                 COREGL_OVERRIDE(fastpath_, glGenRenderbuffers);
325                 COREGL_OVERRIDE(fastpath_, glBindRenderbuffer);
326                 COREGL_OVERRIDE(fastpath_, glFramebufferRenderbuffer);
327                 COREGL_OVERRIDE(fastpath_, glIsRenderbuffer);
328                 COREGL_OVERRIDE(fastpath_, glDeleteRenderbuffers);
329
330                 COREGL_OVERRIDE(fastpath_, glCreateShader);
331                 COREGL_OVERRIDE(fastpath_, glCreateProgram);
332                 COREGL_OVERRIDE(fastpath_, glAttachShader);
333                 COREGL_OVERRIDE(fastpath_, glCompileShader);
334                 COREGL_OVERRIDE(fastpath_, glShaderBinary);
335                 COREGL_OVERRIDE(fastpath_, glDeleteShader);
336                 COREGL_OVERRIDE(fastpath_, glDetachShader);
337                 COREGL_OVERRIDE(fastpath_, glGetShaderiv);
338                 COREGL_OVERRIDE(fastpath_, glGetShaderInfoLog);
339                 COREGL_OVERRIDE(fastpath_, glGetShaderSource);
340                 COREGL_OVERRIDE(fastpath_, glIsShader);
341                 COREGL_OVERRIDE(fastpath_, glShaderSource);
342                 COREGL_OVERRIDE(fastpath_, glBindAttribLocation);
343                 COREGL_OVERRIDE(fastpath_, glDeleteProgram);
344                 COREGL_OVERRIDE(fastpath_, glGetActiveAttrib);
345                 COREGL_OVERRIDE(fastpath_, glGetActiveUniform);
346                 COREGL_OVERRIDE(fastpath_, glGetAttachedShaders);
347                 COREGL_OVERRIDE(fastpath_, glGetAttribLocation);
348                 COREGL_OVERRIDE(fastpath_, glGetProgramiv);
349                 COREGL_OVERRIDE(fastpath_, glGetProgramInfoLog);
350                 COREGL_OVERRIDE(fastpath_, glGetUniformfv);
351                 COREGL_OVERRIDE(fastpath_, glGetUniformiv);
352                 COREGL_OVERRIDE(fastpath_, glGetUniformLocation);
353                 COREGL_OVERRIDE(fastpath_, glIsProgram);
354                 COREGL_OVERRIDE(fastpath_, glLinkProgram);
355                 COREGL_OVERRIDE(fastpath_, glUseProgram);
356                 COREGL_OVERRIDE(fastpath_, glValidateProgram);
357
358                 COREGL_OVERRIDE(fastpath_, glBlendColor);
359                 COREGL_OVERRIDE(fastpath_, glBlendEquation);
360                 COREGL_OVERRIDE(fastpath_, glBlendEquationSeparate);
361                 COREGL_OVERRIDE(fastpath_, glBlendFunc);
362                 COREGL_OVERRIDE(fastpath_, glBlendFuncSeparate);
363                 COREGL_OVERRIDE(fastpath_, glClearColor);
364                 COREGL_OVERRIDE(fastpath_, glClearDepthf);
365                 COREGL_OVERRIDE(fastpath_, glClearStencil);
366                 COREGL_OVERRIDE(fastpath_, glColorMask);
367                 COREGL_OVERRIDE(fastpath_, glCullFace);
368                 COREGL_OVERRIDE(fastpath_, glDepthFunc);
369                 COREGL_OVERRIDE(fastpath_, glDepthMask);
370                 COREGL_OVERRIDE(fastpath_, glDepthRangef);
371                 COREGL_OVERRIDE(fastpath_, glDisable);
372                 COREGL_OVERRIDE(fastpath_, glDisableVertexAttribArray);
373                 COREGL_OVERRIDE(fastpath_, glEnable);
374                 COREGL_OVERRIDE(fastpath_, glEnableVertexAttribArray);
375                 COREGL_OVERRIDE(fastpath_, glFrontFace);
376                 COREGL_OVERRIDE(fastpath_, glHint);
377                 COREGL_OVERRIDE(fastpath_, glLineWidth);
378                 COREGL_OVERRIDE(fastpath_, glPixelStorei);
379                 COREGL_OVERRIDE(fastpath_, glPolygonOffset);
380                 COREGL_OVERRIDE(fastpath_, glSampleCoverage);
381                 COREGL_OVERRIDE(fastpath_, glScissor);
382                 COREGL_OVERRIDE(fastpath_, glStencilFunc);
383                 COREGL_OVERRIDE(fastpath_, glStencilFuncSeparate);
384                 COREGL_OVERRIDE(fastpath_, glStencilMask);
385                 COREGL_OVERRIDE(fastpath_, glStencilMaskSeparate);
386                 COREGL_OVERRIDE(fastpath_, glStencilOp);
387                 COREGL_OVERRIDE(fastpath_, glStencilOpSeparate);
388                 COREGL_OVERRIDE(fastpath_, glVertexAttrib1f);
389                 COREGL_OVERRIDE(fastpath_, glVertexAttrib1fv);
390                 COREGL_OVERRIDE(fastpath_, glVertexAttrib2f);
391                 COREGL_OVERRIDE(fastpath_, glVertexAttrib2fv);
392                 COREGL_OVERRIDE(fastpath_, glVertexAttrib3f);
393                 COREGL_OVERRIDE(fastpath_, glVertexAttrib3fv);
394                 COREGL_OVERRIDE(fastpath_, glVertexAttrib4f);
395                 COREGL_OVERRIDE(fastpath_, glVertexAttrib4fv);
396                 COREGL_OVERRIDE(fastpath_, glVertexAttribPointer);
397                 COREGL_OVERRIDE(fastpath_, glViewport);
398
399                 COREGL_OVERRIDE(fastpath_, glGetProgramBinaryOES);
400                 COREGL_OVERRIDE(fastpath_, glProgramBinaryOES);
401
402                 COREGL_OVERRIDE(fastpath_, glUseProgramStagesEXT);
403                 COREGL_OVERRIDE(fastpath_, glActiveShaderProgramEXT);
404                 COREGL_OVERRIDE(fastpath_, glProgramParameteriEXT);
405                 COREGL_OVERRIDE(fastpath_, glProgramUniform1iEXT);
406                 COREGL_OVERRIDE(fastpath_, glProgramUniform2iEXT);
407                 COREGL_OVERRIDE(fastpath_, glProgramUniform3iEXT);
408                 COREGL_OVERRIDE(fastpath_, glProgramUniform4iEXT);
409                 COREGL_OVERRIDE(fastpath_, glProgramUniform1fEXT);
410                 COREGL_OVERRIDE(fastpath_, glProgramUniform2fEXT);
411                 COREGL_OVERRIDE(fastpath_, glProgramUniform3fEXT);
412                 COREGL_OVERRIDE(fastpath_, glProgramUniform4fEXT);
413                 COREGL_OVERRIDE(fastpath_, glProgramUniform1ivEXT);
414                 COREGL_OVERRIDE(fastpath_, glProgramUniform2ivEXT);
415                 COREGL_OVERRIDE(fastpath_, glProgramUniform3ivEXT);
416                 COREGL_OVERRIDE(fastpath_, glProgramUniform4ivEXT);
417                 COREGL_OVERRIDE(fastpath_, glProgramUniform1fvEXT);
418                 COREGL_OVERRIDE(fastpath_, glProgramUniform2fvEXT);
419                 COREGL_OVERRIDE(fastpath_, glProgramUniform3fvEXT);
420                 COREGL_OVERRIDE(fastpath_, glProgramUniform4fvEXT);
421                 COREGL_OVERRIDE(fastpath_, glProgramUniformMatrix2fvEXT);
422                 COREGL_OVERRIDE(fastpath_, glProgramUniformMatrix3fvEXT);
423                 COREGL_OVERRIDE(fastpath_, glProgramUniformMatrix4fvEXT);
424                 COREGL_OVERRIDE(fastpath_, glProgramParameteriEXT);
425                 COREGL_OVERRIDE(fastpath_, glProgramParameteriEXT);
426                 COREGL_OVERRIDE(fastpath_, glProgramParameteriEXT);
427                 COREGL_OVERRIDE(fastpath_, glProgramParameteriEXT);
428                 COREGL_OVERRIDE(fastpath_, glProgramParameteriEXT);
429
430                 COREGL_OVERRIDE(fastpath_, glFramebufferTexture2DMultisampleEXT);
431                 COREGL_OVERRIDE(fastpath_, glFramebufferTexture3DOES);
432
433                 /* Start overriding GLES 3.0 */
434                 if(driver_gl_version >= COREGL_GLAPI_3) {
435                         COREGL_OVERRIDE(fastpath_, glReadBuffer);
436
437                         COREGL_OVERRIDE(fastpath_, glGenQueries);
438                         COREGL_OVERRIDE(fastpath_, glDeleteQueries);
439                         COREGL_OVERRIDE(fastpath_, glIsQuery);
440                         COREGL_OVERRIDE(fastpath_, glBeginQuery);
441                         COREGL_OVERRIDE(fastpath_, glGetQueryiv);
442                         COREGL_OVERRIDE(fastpath_, glGetQueryObjectuiv);
443                         COREGL_OVERRIDE(fastpath_, glDrawBuffers);
444                         COREGL_OVERRIDE(fastpath_, glFramebufferTextureLayer);
445
446                         COREGL_OVERRIDE(fastpath_, glBindVertexArray);
447                         COREGL_OVERRIDE(fastpath_, glDeleteVertexArrays);
448                         COREGL_OVERRIDE(fastpath_, glGenVertexArrays);
449                         COREGL_OVERRIDE(fastpath_, glIsVertexArray);
450
451                         COREGL_OVERRIDE(fastpath_, glGetIntegeri_v);
452
453                         COREGL_OVERRIDE(fastpath_, glBindTransformFeedback);
454                         COREGL_OVERRIDE(fastpath_, glDeleteTransformFeedbacks);
455                         COREGL_OVERRIDE(fastpath_, glGenTransformFeedbacks);
456                         COREGL_OVERRIDE(fastpath_, glIsTransformFeedback);
457
458                         COREGL_OVERRIDE(fastpath_, glBindBufferRange);
459                         COREGL_OVERRIDE(fastpath_, glBindBufferBase);
460                         COREGL_OVERRIDE(fastpath_, glTransformFeedbackVaryings);
461                         COREGL_OVERRIDE(fastpath_, glGetTransformFeedbackVarying);
462                         COREGL_OVERRIDE(fastpath_, glVertexAttribIPointer);
463                         COREGL_OVERRIDE(fastpath_, glVertexAttribI4i);
464                         COREGL_OVERRIDE(fastpath_, glVertexAttribI4ui);
465                         COREGL_OVERRIDE(fastpath_, glVertexAttribI4iv);
466                         COREGL_OVERRIDE(fastpath_, glVertexAttribI4uiv);
467                         COREGL_OVERRIDE(fastpath_, glGetUniformuiv);
468                         COREGL_OVERRIDE(fastpath_, glGetFragDataLocation);
469                         COREGL_OVERRIDE(fastpath_, glGetStringi);
470                         COREGL_OVERRIDE(fastpath_, glGetUniformIndices);
471                         COREGL_OVERRIDE(fastpath_, glGetActiveUniformsiv);
472                         COREGL_OVERRIDE(fastpath_, glGetUniformBlockIndex);
473                         COREGL_OVERRIDE(fastpath_, glGetActiveUniformBlockiv);
474                         COREGL_OVERRIDE(fastpath_, glGetActiveUniformBlockName);
475                         COREGL_OVERRIDE(fastpath_, glUniformBlockBinding);
476                         COREGL_OVERRIDE(fastpath_, glGetInteger64v);
477                         COREGL_OVERRIDE(fastpath_, glGetInteger64i_v);
478                         COREGL_OVERRIDE(fastpath_, glGenSamplers);
479                         COREGL_OVERRIDE(fastpath_, glDeleteSamplers);
480                         COREGL_OVERRIDE(fastpath_, glIsSampler);
481                         COREGL_OVERRIDE(fastpath_, glBindSampler);
482                         COREGL_OVERRIDE(fastpath_, glSamplerParameteri);
483                         COREGL_OVERRIDE(fastpath_, glSamplerParameteriv);
484                         COREGL_OVERRIDE(fastpath_, glSamplerParameterf);
485                         COREGL_OVERRIDE(fastpath_, glSamplerParameterfv);
486                         COREGL_OVERRIDE(fastpath_, glGetSamplerParameteriv);
487                         COREGL_OVERRIDE(fastpath_, glGetSamplerParameterfv);
488                         COREGL_OVERRIDE(fastpath_, glVertexAttribDivisor);
489                         COREGL_OVERRIDE(fastpath_, glGetProgramBinary);
490                         COREGL_OVERRIDE(fastpath_, glProgramBinary);
491                         COREGL_OVERRIDE(fastpath_, glProgramParameteri);
492                 } // End of GLES 3.0
493
494         }
495         else
496         {
497                 COREGL_LOG("\E[40;35;1m[CoreGL] SKIP GL FASTPATH...\E[0m\n");
498         }
499 }
500
501 #undef OVERRIDE
502
503 static inline GL_Object_Hash_Base *
504 _lock_gl_object_hash(GL_Object_State *ostate, GL_Object_Type type)
505 {
506         switch (type)
507         {
508                 case GL_OBJECT_TYPE_QUERY:
509                         return &ostate->query;
510                 case GL_OBJECT_TYPE_TEXTURE:
511                         AST(mutex_lock(&ostate->shared->access_mutex) == 1);
512                         return &ostate->shared->texture;
513                 case GL_OBJECT_TYPE_BUFFER:
514                         AST(mutex_lock(&ostate->shared->access_mutex) == 1);
515                         return &ostate->shared->buffer;
516                 case GL_OBJECT_TYPE_FRAMEBUFFER:
517                         return &ostate->framebuffer;
518                 case GL_OBJECT_TYPE_RENDERBUFFER:
519                         AST(mutex_lock(&ostate->shared->access_mutex) == 1);
520                         return &ostate->shared->renderbuffer;
521                 case GL_OBJECT_TYPE_PROGRAM:
522                         AST(mutex_lock(&ostate->shared->access_mutex) == 1);
523                         return &ostate->shared->program;
524                 case GL_OBJECT_TYPE_VERTEXARRAY:
525                         return &ostate->vertexarray;
526                 case GL_OBJECT_TYPE_SAMPLER:
527                         AST(mutex_lock(&ostate->shared->access_mutex) == 1);
528                         return &ostate->shared->sampler;
529                 case GL_OBJECT_TYPE_TRANSFORMFEEDBACK:
530                         return &ostate->transformfeedback;
531                 default:
532                         return NULL;
533         }
534 }
535
536 static inline void
537 _unlock_gl_object_hash(GL_Object_State *ostate, GL_Object_Type type)
538 {
539         switch (type)
540         {
541                 case GL_OBJECT_TYPE_TEXTURE:
542                 case GL_OBJECT_TYPE_BUFFER:
543                 case GL_OBJECT_TYPE_RENDERBUFFER:
544                 case GL_OBJECT_TYPE_PROGRAM:
545                 case GL_OBJECT_TYPE_SAMPLER:
546                         AST(mutex_unlock(&ostate->shared->access_mutex) == 1);
547                 default:
548                         break;
549         }
550 }
551
552 static inline GL_Object_Hash_Base *
553 _lock_gl_object_hash_real(GL_Object_State *ostate, GL_Object_Type type)
554 {
555         switch (type)
556         {
557                 case GL_OBJECT_TYPE_QUERY:
558                         return &ostate->query_real;
559                 case GL_OBJECT_TYPE_TEXTURE:
560                         AST(mutex_lock(&ostate->shared->real_access_mutex) == 1);
561                         return &ostate->shared->texture_real;
562                 case GL_OBJECT_TYPE_BUFFER:
563                         AST(mutex_lock(&ostate->shared->real_access_mutex) == 1);
564                         return &ostate->shared->buffer_real;
565                 case GL_OBJECT_TYPE_FRAMEBUFFER:
566                         return &ostate->framebuffer_real;
567                 case GL_OBJECT_TYPE_RENDERBUFFER:
568                         AST(mutex_lock(&ostate->shared->real_access_mutex) == 1);
569                         return &ostate->shared->renderbuffer_real;
570                 case GL_OBJECT_TYPE_PROGRAM:
571                         AST(mutex_lock(&ostate->shared->real_access_mutex) == 1);
572                         return &ostate->shared->program_real;
573                 case GL_OBJECT_TYPE_VERTEXARRAY:
574                         return &ostate->vertexarray_real;
575                 case GL_OBJECT_TYPE_SAMPLER:
576                         AST(mutex_lock(&ostate->shared->real_access_mutex) == 1);
577                         return &ostate->shared->sampler_real;
578                 case GL_OBJECT_TYPE_TRANSFORMFEEDBACK:
579                         return &ostate->transformfeedback_real;
580                 default:
581                         return NULL;
582         }
583 }
584
585 static inline void
586 _unlock_gl_object_hash_real(GL_Object_State *ostate, GL_Object_Type type)
587 {
588         switch (type)
589         {
590                 case GL_OBJECT_TYPE_TEXTURE:
591                 case GL_OBJECT_TYPE_BUFFER:
592                 case GL_OBJECT_TYPE_RENDERBUFFER:
593                 case GL_OBJECT_TYPE_PROGRAM:
594                 case GL_OBJECT_TYPE_SAMPLER:
595                         AST(mutex_unlock(&ostate->shared->real_access_mutex) == 1);
596                         break;
597                 default:
598                         break;
599         }
600 }
601
602 int
603 fastpath_add_context_state_to_list(const void *option, const int option_len, GLContextState *cstate, Mutex *mtx)
604 {
605         int ret = 0;
606         int tid = 0;
607         GLContext_List *current = NULL;
608         GLContext_List *newitm = NULL;
609
610         if (mtx != NULL) AST(mutex_lock(mtx) == 1);
611
612         AST(cstate != NULL);
613
614         tid = get_current_thread();
615
616         current = glctx_list;
617         while (current != NULL)
618         {
619                 if (current->option_len == option_len &&
620                     memcmp(current->option, option, option_len) == 0 &&
621                     current->thread_id == tid)
622                 {
623                         AST(current->cstate == cstate);
624                         goto finish;
625                 }
626                 current = current->next;
627         }
628
629         newitm = (GLContext_List *)calloc(1, sizeof(GLContext_List));
630         if (newitm == NULL)
631         {
632                 COREGL_ERR("Failed to create context list.\n");
633                 goto finish;
634         }
635
636         newitm->cstate = cstate;
637         newitm->thread_id = tid;
638         newitm->option_len = option_len;
639         newitm->option = (void *)malloc(option_len);
640         memcpy(newitm->option, option, option_len);
641
642         if (glctx_list != NULL)
643                 newitm->next = glctx_list;
644
645         glctx_list = newitm;
646
647         ret = 1;
648         goto finish;
649
650 finish:
651         if (ret != 1)
652         {
653                 /* Prevent CID : 394333 - delete dead code */
654                 if (cstate != NULL)
655                 {
656                         free(cstate);
657                         cstate = NULL;
658                 }
659         }
660         if (mtx != NULL) AST(mutex_unlock(mtx) == 1);
661
662         return ret;
663 }
664
665 GLContextState *
666 fastpath_get_context_state_from_list(const void *option, const int option_len, Mutex *mtx)
667 {
668         GLContextState *ret = NULL;
669         GLContext_List *current = NULL;
670         int tid = 0;
671
672         if (mtx != NULL) AST(mutex_lock(mtx) == 1);
673
674         tid = get_current_thread();
675
676         current = glctx_list;
677         while (current != NULL)
678         {
679                 if (current->option_len == option_len &&
680                     memcmp(current->option, option, option_len) == 0 &&
681                     current->thread_id == tid)
682                 {
683                         ret = current->cstate;
684                         goto finish;
685                 }
686                 current = current->next;
687         }
688         goto finish;
689
690 finish:
691         if (mtx != NULL) AST(mutex_unlock(mtx) == 1);
692         return ret;
693 }
694
695 int
696 fastpath_remove_context_states_from_list(GLContextState *cstate, Mutex *mtx)
697 {
698         int ret = 0;
699         GLContext_List *olditm = NULL;
700         GLContext_List *current = NULL;
701
702         if (mtx != NULL) AST(mutex_lock(mtx) == 1);
703
704         AST(cstate != NULL);
705
706         current = glctx_list;
707
708         while (current != NULL)
709         {
710                 if (current->cstate == cstate)
711                 {
712                         GLContext_List *nextitm = NULL;
713                         if (olditm != NULL)
714                         {
715                                 olditm->next = current->next;
716                                 nextitm = olditm->next;
717                         }
718                         else
719                         {
720                                 glctx_list = current->next;
721                                 nextitm = glctx_list;
722                         }
723                         if (current->option != NULL)
724                         {
725                                 AST(current->option_len > 0);
726                                 free(current->option);
727                                 current->option = NULL;
728                                 current->option_len = 0;
729                         }
730                         free(current);
731                         ret = 1;
732                         current = nextitm;
733                         continue;
734                 }
735                 olditm = current;
736                 current = current->next;
737         }
738         goto finish;
739
740 finish:
741         if (mtx != NULL) AST(mutex_unlock(mtx) == 1);
742         return ret;
743 }
744
745
746
747 #define HASH_INIT(hash_base) \
748         hash_base.hash_field = (GL_Object_Hash **)calloc(1, sizeof(GL_Object_Hash *) * GL_OBJECT_HASH_BASE); \
749         hash_base.hash_size = GL_OBJECT_HASH_BASE;
750
751 void
752 fastpath_ostate_init(GL_Object_State *ostate)
753 {
754         HASH_INIT(ostate->query);
755         HASH_INIT(ostate->framebuffer);
756         HASH_INIT(ostate->vertexarray);
757         HASH_INIT(ostate->transformfeedback);
758
759         HASH_INIT(ostate->query_real);
760         HASH_INIT(ostate->framebuffer_real);
761         HASH_INIT(ostate->vertexarray_real);
762         HASH_INIT(ostate->transformfeedback_real);
763 }
764
765 void
766 fastpath_sostate_init(GL_Shared_Object_State *sostate)
767 {
768         mutex_init(&sostate->access_mutex);
769
770         HASH_INIT(sostate->texture);
771         HASH_INIT(sostate->buffer);
772         HASH_INIT(sostate->renderbuffer);
773         HASH_INIT(sostate->program);
774         HASH_INIT(sostate->sampler);
775
776         HASH_INIT(sostate->texture_real);
777         HASH_INIT(sostate->buffer_real);
778         HASH_INIT(sostate->renderbuffer_real);
779         HASH_INIT(sostate->program_real);
780         HASH_INIT(sostate->sampler_real);
781 }
782
783 #undef HASH_INIT
784
785
786 static void
787 _add_hash(GL_Object_Hash_Base *hash_base, GL_Object_Hash *data)
788 {
789         int array_idx = data->hash_key & (hash_base->hash_size - 1);
790         if (hash_base->hash_field[array_idx] == NULL)
791         {
792                 hash_base->hash_field[array_idx] = data;
793         }
794         else
795         {
796                 GL_Object_Hash *current = hash_base->hash_field[array_idx];
797                 while(current->next)
798                 {
799                         AST(current->hash_key != data->hash_key);
800                         current = current->next;
801                 }
802                 current->next = data;
803         }
804         data->next = NULL;
805         hash_base->item_size++;
806 }
807
808 static int
809 _remove_hash(GL_Object_Hash_Base *hash_base, GLuint hash)
810 {
811         int ret = 0;
812         int array_idx = hash & (hash_base->hash_size - 1);
813
814         GL_Object_Hash *current = hash_base->hash_field[array_idx];
815         GL_Object_Hash *prev = NULL;
816
817         while(current)
818         {
819                 if (current->hash_key == hash)
820                 {
821                         if (prev != NULL)
822                                 prev->next = current->next;
823                         else
824                                 hash_base->hash_field[array_idx] = current->next;
825                         hash_base->item_size--;
826                         ret = 1;
827                         break;
828                 }
829                 prev = current;
830                 current = current->next;
831         }
832
833         return ret;
834 }
835
836 static void
837 _free_hash_list(GL_Object_Hash_Base *hash_base, int free_data)
838 {
839         if (hash_base->item_size == 0) return;
840
841         for (int i = 0; i < hash_base->hash_size; i++)
842         {
843                 if (hash_base->hash_field[i] != NULL)
844                 {
845                         GL_Object_Hash *current = hash_base->hash_field[i];
846
847                         while (current != NULL)
848                         {
849                                 GL_Object_Hash *current_next = current->next;
850
851                                 if (free_data == 1 && current->item != NULL)
852                                 {
853                                         free(current->item);
854                                 }
855
856                                 free(current);
857                                 hash_base->item_size--;
858                                 current = current_next;
859                         }
860                 }
861         }
862 }
863
864
865
866 #define HASH_DEINIT(hash_base, free_data) \
867         _free_hash_list(&hash_base, free_data); \
868         free(hash_base.hash_field); \
869         hash_base.hash_size = 0;
870
871 void
872 fastpath_ostate_deinit(GL_Object_State *ostate)
873 {
874         HASH_DEINIT(ostate->query, 1);
875         HASH_DEINIT(ostate->framebuffer, 1);
876         HASH_DEINIT(ostate->vertexarray, 1);
877         HASH_DEINIT(ostate->transformfeedback, 1);
878
879         HASH_DEINIT(ostate->query_real, 0);
880         HASH_DEINIT(ostate->framebuffer_real, 0);
881         HASH_DEINIT(ostate->vertexarray_real, 0);
882         HASH_DEINIT(ostate->transformfeedback_real, 0);
883 }
884
885 void
886 fastpath_sostate_deinit(GL_Shared_Object_State *sostate)
887 {
888         HASH_DEINIT(sostate->texture, 1);
889         HASH_DEINIT(sostate->buffer, 1);
890         HASH_DEINIT(sostate->renderbuffer, 1);
891         HASH_DEINIT(sostate->program, 1);
892         HASH_DEINIT(sostate->sampler, 1);
893
894         HASH_DEINIT(sostate->texture_real, 0);
895         HASH_DEINIT(sostate->buffer_real, 0);
896         HASH_DEINIT(sostate->renderbuffer_real, 0);
897         HASH_DEINIT(sostate->program_real, 0);
898         HASH_DEINIT(sostate->sampler_real, 0);
899 }
900
901 #undef HASH_DEINIT
902
903
904
905 #define FIND_HASH(hash_base, key, ret) \
906 { \
907         GL_Object_Hash *fh_current = hash_base->hash_field[(key) & (hash_base->hash_size - 1)]; \
908         while(fh_current) \
909         { \
910                 if (fh_current->hash_key == (key)) \
911                 { \
912                         ret = fh_current; \
913                         break; \
914                 } \
915                 fh_current = fh_current->next; \
916         } \
917 }
918
919 void
920 _ostate_hash_check(GL_Object_Hash_Base *hash_base)
921 {
922         if (hash_base->item_size + 1 < hash_base->hash_size)
923                 return;
924
925         int oldsize = hash_base->hash_size;
926         GL_Object_Hash **oldfield = hash_base->hash_field;
927
928         hash_base->hash_size = oldsize << 1;
929         hash_base->hash_field = (GL_Object_Hash **)calloc(1, sizeof(GL_Object_Hash *) * hash_base->hash_size);
930         AST(hash_base->hash_field != NULL);
931
932         for (int i = 0; i < oldsize; i++)
933         {
934                 if (oldfield[i] != NULL)
935                 {
936                         GL_Object_Hash *current = oldfield[i];
937
938                         while (current != NULL)
939                         {
940                                 GL_Object_Hash *current_next = current->next;
941                                 _add_hash(hash_base, current);
942                                 hash_base->item_size--;
943                                 current = current_next;
944                         }
945                 }
946         }
947         free(oldfield);
948
949 }
950
951 GLuint
952 fastpath_ostate_create_object(GL_Object_State *ostate, GL_Object_Type type, GLuint real_name)
953 {
954         GLuint ret = _COREGL_INT_INIT_VALUE;
955
956         GL_Object_Hash_Base *hash_base = NULL;
957         GL_Object_Hash_Base *hash_base_real = NULL;
958         int newid = _COREGL_INT_INIT_VALUE;
959
960         hash_base = _lock_gl_object_hash(ostate, type);
961         hash_base_real = _lock_gl_object_hash_real(ostate, type);
962
963         /* Prevent CID : 393638 */
964         /* Prevent CID : 393538 */
965         if (hash_base == NULL || hash_base_real == NULL)
966                 goto finish;
967
968         newid = hash_base->last_id + 1;
969         if (newid >= hash_base->hash_size)
970         {
971                 hash_base->is_looped = 1;
972                 newid = 1;
973                 hash_base->last_id = 1;
974         }
975
976         if (hash_base->is_looped != 0)
977         {
978                 int i;
979                 int findingid = newid;
980                 newid = -1;
981                 for (i = 0; i < hash_base->hash_size; i++)
982                 {
983                         GL_Object_Hash *exist_hash = NULL;
984                         FIND_HASH(hash_base, findingid, exist_hash);
985                         if (exist_hash == NULL)
986                         {
987                                 newid = findingid;
988                                 break;
989                         }
990                         findingid++;
991                         if (findingid >= hash_base->hash_size) findingid = 1;
992                 }
993                 AST(newid != -1);
994         }
995         hash_base->last_id = newid;
996
997         {
998                 GL_Object *newobj = (GL_Object *)calloc(1, sizeof(GL_Object));
999                 AST(newobj != NULL);
1000                 newobj->id = (int)type + newid;
1001                 newobj->real_id = real_name;
1002                 newobj->ref_count = 1;
1003                 ret = newobj->id;
1004
1005                 GL_Object_Hash *newobj_hash = (GL_Object_Hash *)calloc(1, sizeof(GL_Object_Hash));
1006                 AST(newobj_hash != NULL);
1007                 newobj_hash->item = newobj;
1008                 newobj_hash->hash_key = newid;
1009                 _add_hash(hash_base, newobj_hash);
1010
1011                 GL_Object_Hash *newobj_hash_real = (GL_Object_Hash *)calloc(1, sizeof(GL_Object_Hash));
1012                 AST(newobj_hash_real != NULL);
1013                 newobj_hash_real->item = newobj;
1014                 newobj_hash_real->hash_key = real_name;
1015                 _add_hash(hash_base_real, newobj_hash_real);
1016         }
1017
1018         _ostate_hash_check(hash_base);
1019         _ostate_hash_check(hash_base_real);
1020
1021         goto finish;
1022
1023 finish:
1024         _unlock_gl_object_hash(ostate, type);
1025         _unlock_gl_object_hash_real(ostate, type);
1026         return ret;
1027 }
1028
1029 #define FIND_OBJ_FROM_HASH_WITH_VERIFY(hash_base, hash, object) \
1030         if (((int)(hash)) < 0) { ret = 0; goto finish; } \
1031         { \
1032                 GL_Object_Hash *object_hash = NULL; \
1033                 FIND_HASH((hash_base), (int)(hash), object_hash); \
1034                 if (object_hash == NULL) { ret = 0; goto finish; } \
1035                 (object) = object_hash->item; \
1036                 if ((object) == NULL) { ret = 0; goto finish; } \
1037         }
1038
1039 GLuint
1040 fastpath_ostate_remove_object(GL_Object_State *ostate, GL_Object_Type type, GLuint glue_name)
1041 {
1042         GLuint ret = _COREGL_INT_INIT_VALUE;
1043
1044         GL_Object_Hash_Base *hash_base = NULL;
1045         GL_Object_Hash_Base *hash_base_real = NULL;
1046         GL_Object *object = NULL;
1047
1048         hash_base = _lock_gl_object_hash(ostate, type);
1049         hash_base_real = _lock_gl_object_hash_real(ostate, type);
1050
1051         /* Prevent CID : 400742 */
1052         if (hash_base == NULL || hash_base_real == NULL)
1053             goto finish;
1054
1055         FIND_OBJ_FROM_HASH_WITH_VERIFY(hash_base, glue_name - (int)type, object);
1056
1057         object->ref_count--;
1058
1059         if (object->ref_count <= 0)
1060         {
1061                 GL_Object_Hash *object_hash = NULL;
1062
1063                 FIND_HASH(hash_base, object->id - (int)type, object_hash);
1064                 AST(object_hash != NULL);
1065                 _remove_hash(hash_base, object->id - (int)type);
1066                 free(object_hash);
1067                 object_hash = NULL;
1068
1069                 FIND_HASH(hash_base_real, object->real_id, object_hash);
1070                 AST(object_hash != NULL);
1071                 _remove_hash(hash_base_real, object->real_id);
1072                 free(object_hash);
1073                 object_hash = NULL;
1074
1075                 free(object);
1076                 object = NULL;
1077         }
1078
1079         ret = 1;
1080         goto finish;
1081
1082 finish:
1083         _unlock_gl_object_hash(ostate, type);
1084         _unlock_gl_object_hash_real(ostate, type);
1085         return ret;
1086 }
1087
1088 GLuint
1089 fastpath_ostate_get_object(GL_Object_State *ostate, GL_Object_Type type, GLuint glue_name)
1090 {
1091         GLuint ret = _COREGL_INT_INIT_VALUE;
1092
1093         GL_Object_Hash_Base *hash_base = NULL;
1094         GL_Object *object = NULL;
1095
1096         hash_base = _lock_gl_object_hash(ostate, type);
1097
1098         /* Prvent CID : 387143 */
1099         if (hash_base == NULL) goto finish;
1100
1101         FIND_OBJ_FROM_HASH_WITH_VERIFY(hash_base, glue_name - (int)type, object);
1102
1103         ret = object->real_id;
1104         goto finish;
1105
1106 finish:
1107         _unlock_gl_object_hash(ostate, type);
1108         return ret;
1109 }
1110
1111
1112 /* Check if the context's state contains object of a given type */
1113 GLuint
1114 fastpath_ostate_has_object_type(GL_Object_State *ostate, GL_Object_Type type)
1115 {
1116         GLuint ret = _COREGL_INT_INIT_VALUE;
1117
1118         GL_Object_Hash_Base *hash_base = NULL;
1119         GL_Object *object = NULL;
1120         hash_base = _lock_gl_object_hash(ostate, type);
1121         /* Prevent CID : 398319 */
1122         if(hash_base == NULL || hash_base->hash_field == 0)
1123         {
1124                 ret = 0;
1125                 goto finish;
1126         }
1127
1128         FIND_OBJ_FROM_HASH_WITH_VERIFY(hash_base, 1, object);
1129
1130         ret = object->real_id;
1131         goto finish;
1132
1133 finish:
1134         _unlock_gl_object_hash(ostate, type);
1135         return ret;
1136 }
1137
1138
1139 GLint
1140 fastpath_ostate_set_object_tag(GL_Object_State *ostate, GL_Object_Type type, GLuint glue_name, GLvoid *tag)
1141 {
1142         GLint ret = _COREGL_INT_INIT_VALUE;
1143
1144         GL_Object_Hash_Base *hash_base = NULL;
1145         GL_Object *object = NULL;
1146         int hash = _COREGL_INT_INIT_VALUE;
1147
1148         hash_base = _lock_gl_object_hash(ostate, type);
1149         /* Prevent CID : 392281 */
1150         if (hash_base == NULL) goto finish;
1151
1152         hash = glue_name - (int)type;
1153
1154         FIND_OBJ_FROM_HASH_WITH_VERIFY(hash_base, hash, object);
1155
1156         AST(object->tag == NULL);
1157         object->tag = tag;
1158         ret = 1;
1159         goto finish;
1160
1161 finish:
1162         _unlock_gl_object_hash(ostate, type);
1163         return ret;
1164 }
1165
1166 GLvoid *
1167 fastpath_ostate_get_object_tag(GL_Object_State *ostate, GL_Object_Type type, GLuint glue_name)
1168 {
1169         GLvoid *ret = NULL;
1170
1171         GL_Object_Hash_Base *hash_base = NULL;
1172         GL_Object *object = NULL;
1173
1174         hash_base = _lock_gl_object_hash(ostate, type);
1175
1176         /* Prevent CID : 389752 */
1177         if (hash_base == NULL) goto finish;
1178
1179         FIND_OBJ_FROM_HASH_WITH_VERIFY(hash_base, glue_name - (int)type, object);
1180
1181         ret = object->tag;
1182         goto finish;
1183
1184 finish:
1185         _unlock_gl_object_hash(ostate, type);
1186         return ret;
1187 }
1188
1189 GLuint
1190 fastpath_ostate_find_object(GL_Object_State *ostate, GL_Object_Type type, GLuint real_name)
1191 {
1192         GLuint ret = _COREGL_INT_INIT_VALUE;
1193
1194         GL_Object_Hash_Base *hash_base_real = NULL;
1195         GL_Object *object = NULL;
1196
1197         hash_base_real = _lock_gl_object_hash_real(ostate, type);
1198         /* Prevent CID : 398100 */
1199         if (hash_base_real == NULL) goto finish;
1200
1201         FIND_OBJ_FROM_HASH_WITH_VERIFY(hash_base_real, real_name, object);
1202
1203         ret = object->id;
1204         goto finish;
1205
1206 finish:
1207         _unlock_gl_object_hash_real(ostate, type);
1208         return ret;
1209 }
1210
1211 GLint
1212 fastpath_ostate_use_object(GL_Object_State *ostate, GL_Object_Type type, GLuint glue_name)
1213 {
1214         GLint ret = _COREGL_INT_INIT_VALUE;
1215
1216         GL_Object_Hash_Base *hash_base = NULL;
1217         GL_Object *object = NULL;
1218
1219         hash_base = _lock_gl_object_hash(ostate, type);
1220
1221         /* Prevent CID : 390897 */
1222         if (hash_base == NULL) goto finish;
1223
1224         FIND_OBJ_FROM_HASH_WITH_VERIFY(hash_base, glue_name - (int)type, object);
1225
1226         object->ref_count++;
1227         ret = 1;
1228         goto finish;
1229
1230 finish:
1231         _unlock_gl_object_hash(ostate, type);
1232         return ret;
1233 }
1234
1235 void
1236 fastpath_dump_context_states(GLGlueContext *ctx, int force_output)
1237 {
1238         static struct timeval tv_last = { 0, 0 };
1239
1240         if (unlikely(trace_state_flag != 1)) return;
1241
1242         if (!force_output)
1243         {
1244                 struct timeval tv_now = { 0, 0 };
1245                 AST(gettimeofday(&tv_now, NULL) == 0);
1246                 if (tv_now.tv_sec - tv_last.tv_sec < _COREGL_TRACE_OUTPUT_INTERVAL_SEC)
1247                 {
1248                         goto finish;
1249                 }
1250                 tv_last = tv_now;
1251         }
1252
1253         TRACE("\n");
1254         TRACE("\E[0;40;34m========================================================================================================================\E[0m\n");
1255         TRACE("\E[40;32;1m  State info \E[1;37;1m: <PID = %d> GlueCTX = %p\E[0m\n", getpid(), ctx);
1256         TRACE("\E[0;40;34m========================================================================================================================\E[0m\n");
1257
1258 #define PRINTF_CHAR_GLenum "0x%8X"
1259 #define PRINTF_CHAR_GLboolean "%10d"
1260 #define PRINTF_CHAR_GLint "%10d"
1261 #define PRINTF_CHAR_GLsizei "%10u"
1262 #define PRINTF_CHAR_GLuint "%10u"
1263 #define PRINTF_CHAR_GLuintmask "0x%8X"
1264 #define PRINTF_CHAR_GLintptr "%10ld"
1265 #define PRINTF_CHAR_GLsizeiptr "%10ld"
1266
1267 #define PRINTF_CHAR_GLclampf "%10.6f"
1268 #define PRINTF_CHAR_GLfloat "%10.6f"
1269
1270 #define PRINTF_CHAR_GLvoidptr "%10p"
1271
1272 #define PRINTF_CHAR(type) PRINTF_CHAR_##type
1273
1274 #define _COREGL_START_API(version) api_gl_version = version;
1275 #define _COREGL_END_API(version) api_gl_version = COREGL_GLAPI_2;
1276 #define INITIAL_CTX initial_ctx
1277 #define GLUE_STATE(TYPE, NAME, SIZE, ARRAY_SIZE, DEFAULT_STMT, GET_STMT)  \
1278    { \
1279       TYPE valuedata[SIZE]; \
1280       TYPE *value = NULL; \
1281       if(api_gl_version <= driver_gl_version) { \
1282          value = valuedata; GET_STMT; value = valuedata; \
1283          TRACE("\E[40;37;1m %-30.30s : (\E[0m ", #NAME); \
1284          for (int i = 0; i < SIZE; i++) \
1285          { \
1286             if (i > 0) { \
1287                if (i % 4 == 0) \
1288                   TRACE("\n %-30.30s     ", "");\
1289                else \
1290                   TRACE(", "); \
1291             } \
1292             if (ctx->NAME[i] != value[i]) { TRACE("\E[40;31;1m"); } \
1293                TRACE(PRINTF_CHAR(TYPE), ctx->NAME[i]); \
1294                TRACE("["PRINTF_CHAR(TYPE)"]", value[i]); \
1295             if (ctx->NAME[i] != value[i]) { TRACE("\E[0m"); } \
1296          } \
1297          TRACE(" \E[40;37;1m)\E[0m\n"); \
1298       } \
1299    }
1300 # include "coregl_fastpath_state.h"
1301 #undef GLUE_STATE
1302 #undef INITIAL_CTX
1303 #undef _COREGL_START_API
1304 #undef _COREGL_END_API
1305
1306         TRACE("\E[0;40;34m========================================================================================================================\E[0m\n");
1307         TRACE("\n");
1308
1309         TRACE_END();
1310
1311 finish:
1312         return;
1313 }
1314
1315 int
1316 fastpath_init_context_states(GLGlueContext *ctx)
1317 {
1318         int ret = 0;
1319
1320         AST(mutex_lock(&init_context_mutex) == 1);
1321
1322         if (ctx == NULL)
1323         {
1324                 COREGL_ERR("Context NULL\n");
1325                 ret = 0;
1326                 goto finish;
1327         }
1328
1329         AST(ctx->initialized == 0);
1330         AST(ctx->ostate.shared != NULL);
1331
1332         if (initial_ctx == NULL)
1333         {
1334                 initial_ctx = (GLGlueContext *)calloc(1, sizeof(GLGlueContext));
1335                 AST(initial_ctx != NULL);
1336
1337 //#define FORCE_DEFAULT_VALUE
1338 #define _COREGL_START_API(version) api_gl_version = version;
1339 #define _COREGL_END_API(version) api_gl_version = COREGL_GLAPI_2;
1340 #ifdef FORCE_DEFAULT_VALUE
1341 # define INITIAL_CTX initial_ctx
1342 # define GLUE_STATE(TYPE, NAME, SIZE, ARRAY_SIZE, DEFAULT_STMT, GET_STMT)  \
1343       { \
1344          int i; \
1345          TYPE valuedata[SIZE]; \
1346          TYPE *value = NULL; \
1347          memset(valuedata, 0xcc, sizeof(TYPE) * SIZE); \
1348          if(api_gl_version <= driver_gl_version) { \
1349             value = valuedata; DEFAULT_STMT; value = valuedata; \
1350             for (i = 0; i < SIZE; i++) \
1351             { \
1352                if (*((char *)(&value[i])) == 0xcc) \
1353                { \
1354                   memset(&value[i], 0xaa, sizeof(TYPE)); \
1355                   value = valuedata; DEFAULT_STMT; value = valuedata; \
1356                   if (*((char *)(&value[i])) == 0xaa) \
1357                   { \
1358                      COREGL_WRN("\E[40;31;1mGL-state '"#NAME"' cannot be retrieved\E[0m\n"); \
1359                      break; \
1360                   } \
1361                } \
1362                initial_ctx->NAME[i] = value[i]; \
1363             } \
1364         }\
1365       }
1366 #  include "coregl_fastpath_state.h"
1367 # undef GLUE_STATE
1368 # undef INITIAL_CTX
1369 #else
1370 # define INITIAL_CTX initial_ctx
1371 # define SET_GLUE_VALUE(DEFAULT_STMT, FALLBACK_STMT) \
1372       if (try_step == 1) \
1373       { \
1374          value = valuedata; DEFAULT_STMT; value = valuedata; \
1375       } \
1376       else \
1377       { \
1378          value = valuedata; FALLBACK_STMT; value = valuedata; \
1379       }
1380
1381 # define GLUE_STATE(TYPE, NAME, SIZE, ARRAY_SIZE, DEFAULT_STMT, GET_STMT)  \
1382       { \
1383          int i; \
1384          int try_step = 0;\
1385          TYPE valuedata[SIZE]; \
1386          TYPE *value = NULL; \
1387          _sym_glGetError(); \
1388          memset(valuedata, 0xcc, sizeof(TYPE) * SIZE); \
1389          if(api_gl_version <= driver_gl_version) { \
1390             do { \
1391                try_step++; \
1392                SET_GLUE_VALUE(GET_STMT, DEFAULT_STMT); \
1393                if (_sym_glGetError() == GL_INVALID_ENUM) \
1394                { \
1395                   initial_ctx->NAME##_used = 0; \
1396                   value = valuedata; DEFAULT_STMT; value = valuedata; \
1397                   break; \
1398                } \
1399                initial_ctx->NAME##_used = 1; \
1400                for (i = 0; i < SIZE; i++) \
1401                { \
1402                   if (*((char *)(&value[i])) == 0xcc) \
1403                   { \
1404                      memset(&value[i], 0xaa, sizeof(TYPE)); \
1405                      SET_GLUE_VALUE(GET_STMT, DEFAULT_STMT); \
1406                      if (*((char *)(&value[i])) == 0xaa) \
1407                      { \
1408                         try_step++; \
1409                         if (try_step == 2) \
1410                         { \
1411                            COREGL_WRN("\E[40;31;1mGL-state '"#NAME"' cannot be retrieved\E[0m\n"); \
1412                         } \
1413                         break; \
1414                      } \
1415                   } \
1416                   initial_ctx->NAME[i] = value[i]; \
1417                } \
1418                if (try_step != 2) \
1419                { \
1420                   value = valuedata; DEFAULT_STMT; value = valuedata; \
1421                   for (i = 0; i < SIZE; i++) \
1422                   { \
1423                      if (initial_ctx->NAME[i] != value[i]) \
1424                      { \
1425                         COREGL_WRN("GL-state '"#NAME"'[%d] value ["PRINTF_CHAR(TYPE)"] is different from SPEC-DEFAULT ["PRINTF_CHAR(TYPE)"]\n", i, initial_ctx->NAME[i], value[i]); \
1426                      } \
1427                   } \
1428                } \
1429             } \
1430             while (try_step == 2); \
1431          }\
1432       }
1433 #  include "coregl_fastpath_state.h"
1434 # undef SET_GLUE_VALUE
1435 # undef GLUE_STATE
1436 # undef INITIAL_CTX
1437 #endif
1438 # undef _COREGL_END_API
1439 # undef _COREGL_START_API
1440
1441                 if (initial_ctx->gl_num_vertex_attribs[0] > MAX_VERTEX_ATTRIBS)
1442                 {
1443                         COREGL_WRN("\E[40;31;1mNumber of vertex attrib is too big! (%d-%d)\E[0m\n", MAX_VERTEX_ATTRIBS, initial_ctx->gl_num_vertex_attribs[0]);
1444                 }
1445                 if (initial_ctx->gl_num_tex_units[0] > MAX_TEXTURE_UNITS)
1446                 {
1447                         COREGL_WRN("\E[40;31;1mNumber of texture unit is too big! (%d-%d)\E[0m\n", MAX_TEXTURE_UNITS, initial_ctx->gl_num_tex_units[0]);
1448                 }
1449                 if (initial_ctx->gl_num_transform_feedback_separate_attribs[0] > MAX_TRANSFORM_FEEDBACK_SEPARATE_ATTRIBS)
1450                 {
1451                         COREGL_WRN("\E[40;31;1mNumber of transform feedback separate attrib is too big! (%d-%d)\E[0m\n", MAX_TRANSFORM_FEEDBACK_SEPARATE_ATTRIBS, initial_ctx->gl_num_transform_feedback_separate_attribs[0]);
1452                 }
1453                 if (initial_ctx->gl_num_uniform_buffer_bindings[0] > MAX_UNIFORM_BUFFER_BINDINGS)
1454                 {
1455                         COREGL_WRN("\E[40;31;1mNumber of uniform buffer binding is too big! (%d-%d)\E[0m\n", MAX_UNIFORM_BUFFER_BINDINGS, initial_ctx->gl_num_uniform_buffer_bindings[0]);
1456                 }
1457         }
1458
1459         {
1460                 int i;
1461 #define _COREGL_START_API(version) api_gl_version = version;
1462 #define _COREGL_END_API(version) api_gl_version = COREGL_GLAPI_2;
1463 #define INITIAL_CTX initial_ctx
1464 #define GLUE_STATE(TYPE, NAME, SIZE, ARRAY_SIZE, DEFAULT_STMT, GET_STMT)  \
1465       if(api_gl_version <= driver_gl_version) { \
1466          for (i = 0; i < SIZE; i++) \
1467          { \
1468             ctx->NAME[i] = initial_ctx->NAME[i]; \
1469             ctx->NAME##_used = initial_ctx->NAME##_used; \
1470          }\
1471       }
1472 # include "coregl_fastpath_state.h"
1473 #undef GLUE_STATE
1474 #undef INITIAL_CTX
1475 #undef _COREGL_START_API
1476 #undef _COREGL_END_API
1477         }
1478
1479         ctx->initialized = 1;
1480         ret = 1;
1481         goto finish;
1482
1483 finish:
1484         AST(mutex_unlock(&init_context_mutex) == 1);
1485
1486         return ret;
1487 }
1488
1489 #ifdef COREGL_USE_MODULE_TRACEPATH
1490 extern void *tracepath_api_trace_begin(const char *name, void *hint, int trace_total_time);
1491 extern void *tracepath_api_trace_end(const char *name, void *hint, int trace_total_time);
1492 #endif
1493
1494 #define CHECK_GL_ERROR(func) \
1495         { \
1496                 func; \
1497                 int err = _orig_fastpath_glGetError(); \
1498                 if (err != GL_NO_ERROR) \
1499                 { \
1500                         COREGL_ERR("\E[40;31;1m(GL %p) : %s returns GL error 0x%X\E[0m\n", oldctx->cstate, #func, err); \
1501                         goto finish; \
1502                 } \
1503         }
1504
1505 int
1506 fastpath_make_context_current(GLGlueContext *oldctx, GLGlueContext *newctx)
1507 {
1508         int ret = 0;
1509         unsigned char flag = 0;
1510         int i = 0;
1511
1512         if (debug_nofp == 1)
1513         {
1514                 ret = 1;
1515                 goto finish;
1516         }
1517
1518         // Return if they're the same
1519         if (oldctx == newctx)
1520         {
1521                 ret = 1;
1522                 goto finish;
1523         }
1524
1525 #define STATE_COMPARE(state) \
1526    if ((oldctx->state) != (newctx->state))
1527
1528 #define STATES_COMPARE(state_ptr, bytes) \
1529    if ((memcmp((oldctx->state_ptr), (newctx->state_ptr), (bytes))) != 0)
1530
1531
1532 #ifdef COREGL_USE_MODULE_TRACEPATH
1533         static void *trace_hint_glfinish = NULL;
1534         trace_hint_glfinish = tracepath_api_trace_begin("eglMakeCurrent(FP glFinish)", trace_hint_glfinish, 0);
1535 #endif // COREGL_USE_MODULE_TRACEPATH
1536
1537         {
1538                 int err = _orig_fastpath_glGetError();
1539                 if (err != GL_NO_ERROR && oldctx->gl_error == GL_NO_ERROR)
1540                         oldctx->gl_error = err;
1541         }
1542
1543         CHECK_GL_ERROR(_orig_fastpath_glFlush())
1544
1545 #ifdef COREGL_USE_MODULE_TRACEPATH
1546         tracepath_api_trace_end("eglMakeCurrent(FP glFinish)", trace_hint_glfinish, 0);
1547 #endif // COREGL_USE_MODULE_TRACEPATH
1548
1549         // _varray_flag
1550 #ifdef COREGL_USE_MODULE_TRACEPATH
1551         static void *trace_hint_vertex_attrib = NULL;
1552         trace_hint_vertex_attrib = tracepath_api_trace_begin("eglMakeCurrent(FP vertex attrib)", trace_hint_vertex_attrib, 0);
1553 #endif // COREGL_USE_MODULE_TRACEPATH
1554
1555         flag = oldctx->_vattrib_flag | newctx->_vattrib_flag;
1556         if (flag)
1557         {
1558                 for (i = 0; i < oldctx->gl_num_vertex_attribs[0]; i++)
1559                 {
1560                         if (newctx->gl_vertex_array_buf_id[i] != oldctx->gl_vertex_array_buf_id[i])
1561                         {
1562                                 CHECK_GL_ERROR(_orig_fastpath_glBindBuffer(GL_ARRAY_BUFFER, newctx->gl_vertex_array_buf_id[i]))
1563                         }
1564                         else
1565                         {
1566                                 CHECK_GL_ERROR(_orig_fastpath_glBindBuffer(GL_ARRAY_BUFFER, 0))
1567                         }
1568
1569                         STATE_COMPARE(gl_vertex_array_divisor[i])
1570                         {
1571                                 CHECK_GL_ERROR(_orig_fastpath_glVertexAttribDivisor(i, newctx->gl_vertex_array_divisor[i]))
1572                         }
1573
1574                         if (newctx->gl_vertex_array_size[i] != 0)
1575                         {
1576                                 CHECK_GL_ERROR(_orig_fastpath_glVertexAttribPointer(i,
1577                                                newctx->gl_vertex_array_size[i],
1578                                                newctx->gl_vertex_array_type[i],
1579                                                newctx->gl_vertex_array_normalized[i],
1580                                                newctx->gl_vertex_array_stride[i],
1581                                                newctx->gl_vertex_array_pointer[i]))
1582                         }
1583                         else
1584                         {
1585                                 if (newctx->gl_vertex_array_integer[0] == GL_TRUE)
1586                                 {
1587                                         if (newctx->gl_vertex_array_type[0] == GL_UNSIGNED_INT)
1588                                         {
1589                                                 CHECK_GL_ERROR(_orig_fastpath_glVertexAttribI4uiv(i, &newctx->gl_vertex_attrib_value_unsigned_integer[4 * i]))
1590                                         }
1591                                         else
1592                                         {
1593                                                 CHECK_GL_ERROR(_orig_fastpath_glVertexAttribI4iv(i, &newctx->gl_vertex_attrib_value_integer[4 * i]))
1594                                         }
1595                                 }
1596                                 else
1597                                 {
1598                                         CHECK_GL_ERROR(_orig_fastpath_glVertexAttrib4fv(i, &newctx->gl_vertex_attrib_value[4 * i]))
1599                                 }
1600                         }
1601
1602                         if (newctx->gl_vertex_array_enabled[i] == GL_TRUE)
1603                         {
1604                                 CHECK_GL_ERROR(_orig_fastpath_glEnableVertexAttribArray(i))
1605                         }
1606                         else
1607                         {
1608                                 CHECK_GL_ERROR(_orig_fastpath_glDisableVertexAttribArray(i))
1609                         }
1610                 }
1611
1612         }
1613
1614 #ifdef COREGL_USE_MODULE_TRACEPATH
1615         tracepath_api_trace_end("eglMakeCurrent(FP vertex attrib)", trace_hint_vertex_attrib, 0);
1616 #endif // COREGL_USE_MODULE_TRACEPATH
1617
1618
1619 #ifdef COREGL_USE_MODULE_TRACEPATH
1620         static void *trace_hint_bindbuffers = NULL;
1621         trace_hint_bindbuffers = tracepath_api_trace_begin("eglMakeCurrent(FP bind buffers)", trace_hint_bindbuffers, 0);
1622 #endif // COREGL_USE_MODULE_TRACEPATH
1623
1624         //------------------//
1625         // _bind_flag1
1626         flag = oldctx->_bind_flag1 | newctx->_bind_flag1;
1627         if (flag)
1628         {
1629                 STATE_COMPARE(gl_array_buffer_binding[0])
1630                 {
1631                         CHECK_GL_ERROR(_orig_fastpath_glBindBuffer(GL_ARRAY_BUFFER, newctx->gl_array_buffer_binding[0]))
1632                 }
1633                 STATE_COMPARE(gl_element_array_buffer_binding[0])
1634                 {
1635                         CHECK_GL_ERROR(_orig_fastpath_glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, newctx->gl_element_array_buffer_binding[0]))
1636                 }
1637
1638                 if (newctx->gl_framebuffer_binding_read_used == 1)
1639                 {
1640                         STATE_COMPARE(gl_framebuffer_binding_read[0])
1641                         {
1642                                 CHECK_GL_ERROR(_orig_fastpath_glBindFramebuffer(GL_READ_FRAMEBUFFER, newctx->gl_framebuffer_binding_read[0]))
1643                         }
1644                         STATE_COMPARE(gl_framebuffer_binding_draw[0])
1645                         {
1646                                 CHECK_GL_ERROR(_orig_fastpath_glBindFramebuffer(GL_DRAW_FRAMEBUFFER, newctx->gl_framebuffer_binding_draw[0]))
1647                         }
1648                 }
1649                 else
1650                 {
1651                         STATE_COMPARE(gl_framebuffer_binding[0])
1652                         {
1653                                 CHECK_GL_ERROR(_orig_fastpath_glBindFramebuffer(GL_FRAMEBUFFER, newctx->gl_framebuffer_binding[0]))
1654                         }
1655                 }
1656                 STATE_COMPARE(gl_renderbuffer_binding[0])
1657                 {
1658                         CHECK_GL_ERROR(_orig_fastpath_glBindRenderbuffer(GL_RENDERBUFFER, newctx->gl_renderbuffer_binding[0]))
1659                 }
1660         }
1661
1662         //------------------//
1663         // _bind_flag2
1664         flag = oldctx->_bind_flag2 | newctx->_bind_flag2;
1665         if (flag)
1666         {
1667                 STATE_COMPARE(gl_copy_read_buffer_binding[0])
1668                 {
1669                         CHECK_GL_ERROR(_orig_fastpath_glBindBuffer(GL_COPY_READ_BUFFER, newctx->gl_copy_read_buffer_binding[0]))
1670                 }
1671                 STATE_COMPARE(gl_copy_write_buffer_binding[0])
1672                 {
1673                         CHECK_GL_ERROR(_orig_fastpath_glBindBuffer(GL_COPY_WRITE_BUFFER, newctx->gl_copy_write_buffer_binding[0]))
1674                 }
1675                 STATE_COMPARE(gl_pixel_pack_buffer_binding[0])
1676                 {
1677                         CHECK_GL_ERROR(_orig_fastpath_glBindBuffer(GL_PIXEL_PACK_BUFFER, newctx->gl_pixel_pack_buffer_binding[0]))
1678                 }
1679                 STATE_COMPARE(gl_pixel_unpack_buffer_binding[0])
1680                 {
1681                         CHECK_GL_ERROR(_orig_fastpath_glBindBuffer(GL_PIXEL_UNPACK_BUFFER, newctx->gl_pixel_unpack_buffer_binding[0]))
1682                 }
1683                 STATE_COMPARE(gl_transform_feedback_buffer_binding[0])
1684                 {
1685                         CHECK_GL_ERROR(_orig_fastpath_glBindBuffer(GL_TRANSFORM_FEEDBACK_BUFFER, newctx->gl_transform_feedback_buffer_binding[0]))
1686                 }
1687                 STATE_COMPARE(gl_uniform_buffer_binding[0])
1688                 {
1689                         CHECK_GL_ERROR(_orig_fastpath_glBindBuffer(GL_UNIFORM_BUFFER, newctx->gl_uniform_buffer_binding[0]))
1690                 }
1691         }
1692 #ifdef COREGL_USE_MODULE_TRACEPATH
1693         tracepath_api_trace_end("eglMakeCurrent(FP bind buffers)", trace_hint_bindbuffers, 0);
1694 #endif // COREGL_USE_MODULE_TRACEPATH
1695
1696
1697         //------------------//
1698         // Enable States
1699         // _enable_flag1
1700 #ifdef COREGL_USE_MODULE_TRACEPATH
1701         static void *trace_hint_enable_states = NULL;
1702         trace_hint_enable_states = tracepath_api_trace_begin("eglMakeCurrent(FP enable states)", trace_hint_enable_states, 0);
1703 #endif // COREGL_USE_MODULE_TRACEPATH
1704
1705         flag = oldctx->_enable_flag1 | newctx->_enable_flag1;
1706         if (flag)
1707         {
1708                 STATE_COMPARE(gl_blend[0])
1709                 {
1710                         if (newctx->gl_blend[0])
1711                         {
1712                                 CHECK_GL_ERROR(_orig_fastpath_glEnable(GL_BLEND))
1713                         }
1714                         else
1715                                 CHECK_GL_ERROR(_orig_fastpath_glDisable(GL_BLEND))
1716                 }
1717                 STATE_COMPARE(gl_cull_face[0])
1718                 {
1719                         if (newctx->gl_cull_face[0])
1720                         {
1721                                 CHECK_GL_ERROR(_orig_fastpath_glEnable(GL_CULL_FACE))
1722                         }
1723                         else
1724                                 CHECK_GL_ERROR(_orig_fastpath_glDisable(GL_CULL_FACE))
1725                 }
1726                 STATE_COMPARE(gl_depth_test[0])
1727                 {
1728                         if (newctx->gl_depth_test[0])
1729                         {
1730                                 CHECK_GL_ERROR(_orig_fastpath_glEnable(GL_DEPTH_TEST))
1731                         }
1732                         else
1733                                 CHECK_GL_ERROR(_orig_fastpath_glDisable(GL_DEPTH_TEST))
1734                 }
1735                 STATE_COMPARE(gl_dither[0])
1736                 {
1737                         if (newctx->gl_dither[0])
1738                         {
1739                                 CHECK_GL_ERROR(_orig_fastpath_glEnable(GL_DITHER))
1740                         }
1741                         else
1742                                 CHECK_GL_ERROR(_orig_fastpath_glDisable(GL_DITHER))
1743                 }
1744         }
1745
1746         // _enable_flag2
1747         flag = oldctx->_enable_flag2 | newctx->_enable_flag2;
1748         if (flag)
1749         {
1750                 STATE_COMPARE(gl_polygon_offset_fill[0])
1751                 {
1752                         if (newctx->gl_polygon_offset_fill[0])
1753                         {
1754                                 CHECK_GL_ERROR(_orig_fastpath_glEnable(GL_POLYGON_OFFSET_FILL))
1755                         }
1756                         else
1757                                 CHECK_GL_ERROR(_orig_fastpath_glDisable(GL_POLYGON_OFFSET_FILL))
1758                 }
1759                 STATE_COMPARE(gl_sample_alpha_to_coverage[0])
1760                 {
1761                         if (newctx->gl_sample_alpha_to_coverage[0])
1762                         {
1763                                 CHECK_GL_ERROR(_orig_fastpath_glEnable(GL_SAMPLE_ALPHA_TO_COVERAGE))
1764                         }
1765                         else
1766                                 CHECK_GL_ERROR(_orig_fastpath_glDisable(GL_SAMPLE_ALPHA_TO_COVERAGE))
1767                 }
1768                 STATE_COMPARE(gl_sample_coverage[0])
1769                 {
1770                         if (newctx->gl_sample_coverage[0])
1771                         {
1772                                 CHECK_GL_ERROR(_orig_fastpath_glEnable(GL_SAMPLE_COVERAGE))
1773                         }
1774                         else
1775                                 CHECK_GL_ERROR(_orig_fastpath_glDisable(GL_SAMPLE_COVERAGE))
1776                 }
1777                 STATE_COMPARE(gl_scissor_test[0])
1778                 {
1779                         if (newctx->gl_scissor_test[0])
1780                         {
1781                                 CHECK_GL_ERROR(_orig_fastpath_glEnable(GL_SCISSOR_TEST))
1782                         }
1783                         else
1784                                 CHECK_GL_ERROR(_orig_fastpath_glDisable(GL_SCISSOR_TEST))
1785                 }
1786                 STATE_COMPARE(gl_stencil_test[0])
1787                 {
1788                         if (newctx->gl_stencil_test[0])
1789                         {
1790                                 CHECK_GL_ERROR(_orig_fastpath_glEnable(GL_STENCIL_TEST))
1791                         }
1792                         else
1793                                 CHECK_GL_ERROR(_orig_fastpath_glDisable(GL_STENCIL_TEST))
1794                 }
1795         }
1796
1797         // _enable_flag3
1798         flag = oldctx->_enable_flag3 | newctx->_enable_flag3;
1799         if (flag)
1800         {
1801                 STATE_COMPARE(gl_primitive_restart_fixed_index[0])
1802                 {
1803                         if (newctx->gl_primitive_restart_fixed_index[0])
1804                         {
1805                                 CHECK_GL_ERROR(_orig_fastpath_glEnable(GL_PRIMITIVE_RESTART_FIXED_INDEX))
1806                         }
1807                         else
1808                                 CHECK_GL_ERROR(_orig_fastpath_glDisable(GL_PRIMITIVE_RESTART_FIXED_INDEX))
1809                 }
1810                 STATE_COMPARE(gl_rasterizer_discard[0])
1811                 {
1812                         if (newctx->gl_rasterizer_discard[0])
1813                         {
1814                                 CHECK_GL_ERROR(_orig_fastpath_glEnable(GL_RASTERIZER_DISCARD))
1815                         }
1816                         else
1817                                 CHECK_GL_ERROR(_orig_fastpath_glDisable(GL_RASTERIZER_DISCARD))
1818                 }
1819         }
1820
1821 #ifdef COREGL_USE_MODULE_TRACEPATH
1822         tracepath_api_trace_end("eglMakeCurrent(FP enable states)", trace_hint_enable_states, 0);
1823 #endif // COREGL_USE_MODULE_TRACEPATH
1824
1825         //------------------//
1826         // _clear_flag1
1827 #ifdef COREGL_USE_MODULE_TRACEPATH
1828         static void *trace_hint_clear_viewport = NULL;
1829         trace_hint_clear_viewport = tracepath_api_trace_begin("eglMakeCurrent(FP clear/viewport)", trace_hint_clear_viewport, 0);
1830 #endif // COREGL_USE_MODULE_TRACEPATH
1831
1832         flag = oldctx->_clear_flag1 | newctx->_clear_flag1;
1833         if (flag)
1834         {
1835                 // Viewport.
1836                 STATES_COMPARE(gl_viewport, 4 * sizeof(GLint))
1837                 {
1838                         CHECK_GL_ERROR(_orig_fastpath_glViewport(newctx->gl_viewport[0],
1839                                        newctx->gl_viewport[1],
1840                                        newctx->gl_viewport[2],
1841                                        newctx->gl_viewport[3]))
1842                 }
1843
1844                 STATE_COMPARE(gl_current_program[0])
1845                 {
1846                         CHECK_GL_ERROR(_orig_fastpath_glUseProgram(newctx->gl_current_program[0]))
1847                 }
1848                 STATES_COMPARE(gl_color_clear_value, 4 * sizeof(GLclampf))
1849                 {
1850                         CHECK_GL_ERROR(_orig_fastpath_glClearColor(newctx->gl_color_clear_value[0],
1851                                        newctx->gl_color_clear_value[1],
1852                                        newctx->gl_color_clear_value[2],
1853                                        newctx->gl_color_clear_value[3]))
1854                 }
1855         }
1856
1857
1858         // _clear_flag2
1859         flag = oldctx->_clear_flag2 | newctx->_clear_flag2;
1860         if (flag)
1861         {
1862                 STATES_COMPARE(gl_color_writemask, 4 * sizeof(GLboolean))
1863                 {
1864                         CHECK_GL_ERROR(_orig_fastpath_glColorMask(newctx->gl_color_writemask[0],
1865                                        newctx->gl_color_writemask[1],
1866                                        newctx->gl_color_writemask[2],
1867                                        newctx->gl_color_writemask[3]))
1868                 }
1869                 STATES_COMPARE(gl_depth_range, 2 * sizeof(GLclampf))
1870                 {
1871                         CHECK_GL_ERROR(_orig_fastpath_glDepthRangef(newctx->gl_depth_range[0],
1872                                        newctx->gl_depth_range[1]))
1873                 }
1874                 STATE_COMPARE(gl_depth_clear_value[0])
1875                 {
1876                         CHECK_GL_ERROR(_orig_fastpath_glClearDepthf(newctx->gl_depth_clear_value[0]))
1877                 }
1878                 STATE_COMPARE(gl_depth_func[0])
1879                 {
1880                         CHECK_GL_ERROR(_orig_fastpath_glDepthFunc(newctx->gl_depth_func[0]))
1881                 }
1882                 STATE_COMPARE(gl_depth_writemask[0])
1883                 {
1884                         CHECK_GL_ERROR(_orig_fastpath_glDepthMask(newctx->gl_depth_writemask[0]))
1885                 }
1886                 STATE_COMPARE(gl_cull_face_mode[0])
1887                 {
1888                         CHECK_GL_ERROR(_orig_fastpath_glCullFace(newctx->gl_cull_face_mode[0]))
1889                 }
1890
1891         }
1892
1893 #ifdef COREGL_USE_MODULE_TRACEPATH
1894         tracepath_api_trace_end("eglMakeCurrent(FP clear/viewport)", trace_hint_clear_viewport, 0);
1895 #endif // COREGL_USE_MODULE_TRACEPATH
1896
1897         //------------------//
1898         // Texture here...
1899 #ifdef COREGL_USE_MODULE_TRACEPATH
1900         static void *trace_hint_bind_textures = NULL;
1901         trace_hint_bind_textures = tracepath_api_trace_begin("eglMakeCurrent(FP bind textures)", trace_hint_bind_textures, 0);
1902 #endif // COREGL_USE_MODULE_TRACEPATH
1903
1904         flag = oldctx->_tex_flag1 | newctx->_tex_flag1;
1905         if (flag)
1906         {
1907
1908                 for (i = 0; i < oldctx->gl_num_tex_units[0]; i++)
1909                 {
1910                         STATE_COMPARE(gl_tex_2d_state[i])
1911                         {
1912                                 CHECK_GL_ERROR(_orig_fastpath_glActiveTexture(GL_TEXTURE0 + i))
1913                                 CHECK_GL_ERROR(_orig_fastpath_glBindTexture(GL_TEXTURE_2D, newctx->gl_tex_2d_state[i]))
1914                         }
1915                         STATE_COMPARE(gl_tex_3d_state[i])
1916                         {
1917                                 CHECK_GL_ERROR(_orig_fastpath_glActiveTexture(GL_TEXTURE0 + i))
1918                                 CHECK_GL_ERROR(_orig_fastpath_glBindTexture(GL_TEXTURE_3D, newctx->gl_tex_3d_state[i]))
1919                         }
1920                         STATE_COMPARE(gl_tex_2d_array_state[i])
1921                         {
1922                                 CHECK_GL_ERROR(_orig_fastpath_glActiveTexture(GL_TEXTURE0 + i))
1923                                 CHECK_GL_ERROR(_orig_fastpath_glBindTexture(GL_TEXTURE_2D_ARRAY, newctx->gl_tex_2d_array_state[i]))
1924                         }
1925                         STATE_COMPARE(gl_tex_cube_state[i])
1926                         {
1927                                 CHECK_GL_ERROR(_orig_fastpath_glActiveTexture(GL_TEXTURE0 + i))
1928                                 CHECK_GL_ERROR(_orig_fastpath_glBindTexture(GL_TEXTURE_CUBE_MAP, newctx->gl_tex_cube_state[i]))
1929                         }
1930                         STATE_COMPARE(gl_tex_external_oes_state[i])
1931                         {
1932                                 CHECK_GL_ERROR(_orig_fastpath_glActiveTexture(GL_TEXTURE0 + i))
1933                                 CHECK_GL_ERROR(_orig_fastpath_glBindTexture(GL_TEXTURE_EXTERNAL_OES, newctx->gl_tex_external_oes_state[i]))
1934                         }
1935                 }
1936
1937                 // Restore active texture
1938                 CHECK_GL_ERROR(_orig_fastpath_glActiveTexture(newctx->gl_active_texture[0]))
1939
1940                 STATE_COMPARE(gl_generate_mipmap_hint[0])
1941                 {
1942                         CHECK_GL_ERROR(_orig_fastpath_glHint(GL_GENERATE_MIPMAP_HINT, newctx->gl_generate_mipmap_hint[0]))
1943                 }
1944         }
1945 #ifdef COREGL_USE_MODULE_TRACEPATH
1946         tracepath_api_trace_end("eglMakeCurrent(FP bind textures)", trace_hint_bind_textures, 0);
1947 #endif // COREGL_USE_MODULE_TRACEPATH
1948
1949         //------------------//
1950 #ifdef COREGL_USE_MODULE_TRACEPATH
1951         static void *trace_hint_etc = NULL;
1952         trace_hint_etc = tracepath_api_trace_begin("eglMakeCurrent(FP etc.)", trace_hint_etc, 0);
1953 #endif // COREGL_USE_MODULE_TRACEPATH
1954
1955         flag = oldctx->_blend_flag | newctx->_blend_flag;
1956         if (flag)
1957         {
1958                 STATES_COMPARE(gl_blend_color, 4 * sizeof(GLclampf))
1959                 {
1960                         CHECK_GL_ERROR(_orig_fastpath_glBlendColor(newctx->gl_blend_color[0],
1961                                        newctx->gl_blend_color[1],
1962                                        newctx->gl_blend_color[2],
1963                                        newctx->gl_blend_color[3]))
1964                 }
1965                 if ((oldctx->gl_blend_src_rgb[0] != newctx->gl_blend_src_rgb[0]) ||
1966                     (oldctx->gl_blend_dst_rgb[0] != newctx->gl_blend_dst_rgb[0]) ||
1967                     (oldctx->gl_blend_src_alpha[0] != newctx->gl_blend_src_alpha[0]) ||
1968                     (oldctx->gl_blend_dst_alpha[0] != newctx->gl_blend_dst_alpha[0]))
1969                 {
1970                         CHECK_GL_ERROR(_orig_fastpath_glBlendFuncSeparate(newctx->gl_blend_src_rgb[0],
1971                                        newctx->gl_blend_dst_rgb[0],
1972                                        newctx->gl_blend_src_alpha[0],
1973                                        newctx->gl_blend_dst_alpha[0]))
1974                 }
1975                 if ((oldctx->gl_blend_equation_rgb[0] != newctx->gl_blend_equation_rgb[0]) ||
1976                     (oldctx->gl_blend_equation_alpha[0] != newctx->gl_blend_equation_alpha[0]))
1977                 {
1978                         CHECK_GL_ERROR(_orig_fastpath_glBlendEquationSeparate(newctx->gl_blend_equation_rgb[0], newctx->gl_blend_equation_alpha[0]))
1979                 }
1980
1981         }
1982
1983         //------------------//
1984         // _stencil_flag1
1985         flag = oldctx->_stencil_flag1 | newctx->_stencil_flag1;
1986         if (flag)
1987         {
1988                 if ((oldctx->gl_stencil_func[0] != newctx->gl_stencil_func[0]) ||
1989                     (oldctx->gl_stencil_ref[0]  != newctx->gl_stencil_ref[0])  ||
1990                     (oldctx->gl_stencil_value_mask[0] != newctx->gl_stencil_value_mask[0]))
1991                 {
1992                         CHECK_GL_ERROR(_orig_fastpath_glStencilFuncSeparate(GL_FRONT,
1993                                        newctx->gl_stencil_func[0],
1994                                        newctx->gl_stencil_ref[0],
1995                                        newctx->gl_stencil_value_mask[0]))
1996                 }
1997                 if ((oldctx->gl_stencil_fail[0] != newctx->gl_stencil_fail[0]) ||
1998                     (oldctx->gl_stencil_pass_depth_fail[0] != newctx->gl_stencil_pass_depth_fail[0]) ||
1999                     (oldctx->gl_stencil_pass_depth_pass[0] != newctx->gl_stencil_pass_depth_pass[0]))
2000                 {
2001                         CHECK_GL_ERROR(_orig_fastpath_glStencilOpSeparate(GL_FRONT,
2002                                        newctx->gl_stencil_fail[0],
2003                                        newctx->gl_stencil_pass_depth_fail[0],
2004                                        newctx->gl_stencil_pass_depth_pass[0]))
2005                 }
2006
2007                 STATE_COMPARE(gl_stencil_writemask[0])
2008                 {
2009                         CHECK_GL_ERROR(_orig_fastpath_glStencilMaskSeparate(GL_FRONT, newctx->gl_stencil_writemask[0]))
2010                 }
2011         }
2012
2013
2014         // _stencil_flag1
2015         flag = oldctx->_stencil_flag2 | newctx->_stencil_flag2;
2016         if (flag)
2017         {
2018                 if ((oldctx->gl_stencil_back_func[0] != newctx->gl_stencil_back_func[0]) ||
2019                     (oldctx->gl_stencil_back_ref[0]  != newctx->gl_stencil_back_ref[0])  ||
2020                     (oldctx->gl_stencil_back_value_mask[0] != newctx->gl_stencil_back_value_mask[0]))
2021                 {
2022                         CHECK_GL_ERROR(_orig_fastpath_glStencilFuncSeparate(GL_BACK,
2023                                        newctx->gl_stencil_back_func[0],
2024                                        newctx->gl_stencil_back_ref[0],
2025                                        newctx->gl_stencil_back_value_mask[0]))
2026                 }
2027                 if ((oldctx->gl_stencil_back_fail[0] != newctx->gl_stencil_back_fail[0]) ||
2028                     (oldctx->gl_stencil_back_pass_depth_fail[0] != newctx->gl_stencil_back_pass_depth_fail[0]) ||
2029                     (oldctx->gl_stencil_back_pass_depth_pass[0] != newctx->gl_stencil_back_pass_depth_pass[0]))
2030                 {
2031                         CHECK_GL_ERROR(_orig_fastpath_glStencilOpSeparate(GL_BACK,
2032                                        newctx->gl_stencil_back_fail[0],
2033                                        newctx->gl_stencil_back_pass_depth_fail[0],
2034                                        newctx->gl_stencil_back_pass_depth_pass[0]))
2035                 }
2036
2037                 STATE_COMPARE(gl_stencil_back_writemask[0])
2038                 {
2039                         CHECK_GL_ERROR(_orig_fastpath_glStencilMaskSeparate(GL_BACK, newctx->gl_stencil_back_writemask[0]))
2040                 }
2041                 STATE_COMPARE(gl_stencil_clear_value[0])
2042                 {
2043                         CHECK_GL_ERROR(_orig_fastpath_glClearStencil(newctx->gl_stencil_clear_value[0]))
2044                 }
2045         }
2046
2047         //------------------//
2048         // _pixel_flag1
2049         flag = oldctx->_pixel_flag1 | newctx->_pixel_flag1;
2050         if (flag)
2051         {
2052                 STATE_COMPARE(gl_pack_row_length[0])
2053                 {
2054                         CHECK_GL_ERROR(_orig_fastpath_glPixelStorei(GL_PACK_ROW_LENGTH, newctx->gl_pack_row_length[0]))
2055                 }
2056                 STATE_COMPARE(gl_pack_skip_rows[0])
2057                 {
2058                         CHECK_GL_ERROR(_orig_fastpath_glPixelStorei(GL_PACK_SKIP_ROWS, newctx->gl_pack_skip_rows[0]))
2059                 }
2060                 STATE_COMPARE(gl_pack_skip_pixels[0])
2061                 {
2062                         CHECK_GL_ERROR(_orig_fastpath_glPixelStorei(GL_PACK_SKIP_PIXELS, newctx->gl_pack_skip_pixels[0]))
2063                 }
2064                 STATE_COMPARE(gl_pack_alignment[0])
2065                 {
2066                         CHECK_GL_ERROR(_orig_fastpath_glPixelStorei(GL_PACK_ALIGNMENT, newctx->gl_pack_alignment[0]))
2067                 }
2068         }
2069
2070         // _pixel_flag2
2071         flag = oldctx->_pixel_flag2 | newctx->_pixel_flag2;
2072         if (flag)
2073         {
2074                 STATE_COMPARE(gl_unpack_row_length[0])
2075                 {
2076                         CHECK_GL_ERROR(_orig_fastpath_glPixelStorei(GL_UNPACK_ROW_LENGTH, newctx->gl_unpack_row_length[0]))
2077                 }
2078                 STATE_COMPARE(gl_unpack_skip_rows[0])
2079                 {
2080                         CHECK_GL_ERROR(_orig_fastpath_glPixelStorei(GL_UNPACK_SKIP_ROWS, newctx->gl_unpack_skip_rows[0]))
2081                 }
2082                 STATE_COMPARE(gl_unpack_skip_pixels[0])
2083                 {
2084                         CHECK_GL_ERROR(_orig_fastpath_glPixelStorei(GL_UNPACK_SKIP_PIXELS, newctx->gl_unpack_skip_pixels[0]))
2085                 }
2086                 STATE_COMPARE(gl_unpack_alignment[0])
2087                 {
2088                         CHECK_GL_ERROR(_orig_fastpath_glPixelStorei(GL_UNPACK_ALIGNMENT, newctx->gl_unpack_alignment[0]))
2089                 }
2090                 STATE_COMPARE(gl_unpack_image_height[0])
2091                 {
2092                         CHECK_GL_ERROR(_orig_fastpath_glPixelStorei(GL_UNPACK_IMAGE_HEIGHT, newctx->gl_unpack_image_height[0]))
2093                 }
2094                 STATE_COMPARE(gl_unpack_skip_images[0])
2095                 {
2096                         CHECK_GL_ERROR(_orig_fastpath_glPixelStorei(GL_UNPACK_SKIP_IMAGES, newctx->gl_unpack_skip_images[0]))
2097                 }
2098         }
2099
2100         //------------------//
2101         // _misc_flag1
2102         flag = oldctx->_misc_flag1 | newctx->_misc_flag1;
2103         if (flag)
2104         {
2105                 STATE_COMPARE(gl_front_face[0])
2106                 {
2107                         CHECK_GL_ERROR(_orig_fastpath_glFrontFace(newctx->gl_front_face[0]))
2108                 }
2109                 STATE_COMPARE(gl_line_width[0])
2110                 {
2111                         CHECK_GL_ERROR(_orig_fastpath_glLineWidth(newctx->gl_line_width[0]))
2112                 }
2113                 if ((oldctx->gl_polygon_offset_factor[0] != newctx->gl_polygon_offset_factor[0]) ||
2114                     (oldctx->gl_polygon_offset_units[0]  != newctx->gl_polygon_offset_units[0]))
2115                 {
2116                         CHECK_GL_ERROR(_orig_fastpath_glPolygonOffset(newctx->gl_polygon_offset_factor[0],
2117                                        newctx->gl_polygon_offset_units[0]))
2118                 }
2119                 if ((oldctx->gl_sample_coverage_value[0]  != newctx->gl_sample_coverage_value[0]) ||
2120                     (oldctx->gl_sample_coverage_invert[0] != newctx->gl_sample_coverage_invert[0]))
2121                 {
2122                         CHECK_GL_ERROR(_orig_fastpath_glSampleCoverage(newctx->gl_sample_coverage_value[0],
2123                                        newctx->gl_sample_coverage_invert[0]))
2124                 }
2125                 STATE_COMPARE(gl_fragment_shader_derivative_hint[0])
2126                 {
2127                         CHECK_GL_ERROR(_orig_fastpath_glHint(GL_FRAGMENT_SHADER_DERIVATIVE_HINT_OES, newctx->gl_fragment_shader_derivative_hint[0]))
2128                 }
2129         }
2130
2131         // _misc_flag2
2132         flag = oldctx->_misc_flag2 | newctx->_misc_flag2;
2133         if (flag)
2134         {
2135                 STATES_COMPARE(gl_scissor_box, 4 * sizeof(GLint))
2136                 {
2137                         CHECK_GL_ERROR(_orig_fastpath_glScissor(newctx->gl_scissor_box[0],
2138                                                                 newctx->gl_scissor_box[1],
2139                                                                 newctx->gl_scissor_box[2],
2140                                                                 newctx->gl_scissor_box[3]))
2141                 }
2142         }
2143
2144         // _misc_flag3
2145         flag = oldctx->_misc_flag3 | newctx->_misc_flag3;
2146         if (flag)
2147         {
2148                 STATE_COMPARE(gl_read_buffer[0])
2149                 {
2150                         CHECK_GL_ERROR(_orig_fastpath_glReadBuffer(newctx->gl_read_buffer[0]))
2151                 }
2152                 STATES_COMPARE(gl_draw_buffers, 16 * sizeof(GLenum))
2153                 {
2154                         int drawBuffSize = 16;
2155                         /* If the  context has only default framebuffer, then size of glDrawBuffers can only be 1 */
2156                         if(fastpath_ostate_has_object_type(&newctx->ostate, GL_OBJECT_TYPE_FRAMEBUFFER) == 0) {
2157                                 drawBuffSize = 1;
2158                         }
2159
2160                         CHECK_GL_ERROR(_orig_fastpath_glDrawBuffers(drawBuffSize, newctx->gl_draw_buffers))
2161                 }
2162                 STATE_COMPARE(gl_vertex_array_binding[0])
2163                 {
2164                         CHECK_GL_ERROR(_orig_fastpath_glBindVertexArray(newctx->gl_vertex_array_binding[0]))
2165                 }
2166
2167                 if (oldctx->gl_transform_feedback_active[0] == GL_TRUE && oldctx->gl_transform_feedback_paused[0] == GL_FALSE)
2168                 {
2169                         CHECK_GL_ERROR(_orig_fastpath_glPauseTransformFeedback())
2170                 }
2171                 STATE_COMPARE(gl_transform_feedback_binding[0])
2172                 {
2173                         CHECK_GL_ERROR(_orig_fastpath_glBindTransformFeedback(GL_TRANSFORM_FEEDBACK, newctx->gl_transform_feedback_binding[0]))
2174                 }
2175                 if (newctx->gl_transform_feedback_active[0] == GL_TRUE && newctx->gl_transform_feedback_paused[0] == GL_FALSE)
2176                 {
2177                         CHECK_GL_ERROR(_orig_fastpath_glResumeTransformFeedback())
2178                 }
2179         }
2180
2181 #ifdef COREGL_USE_MODULE_TRACEPATH
2182         tracepath_api_trace_end("eglMakeCurrent(FP etc.)", trace_hint_etc, 0);
2183 #endif // COREGL_USE_MODULE_TRACEPATH
2184
2185         ret = 1;
2186         goto finish;
2187
2188 finish:
2189
2190 #ifdef COREGL_FASTPATH_TRACE_STATE_INFO
2191         if (unlikely(trace_state_flag == 1))
2192                 fastpath_dump_context_states(newctx, 0);
2193 #endif // COREGL_FASTPATH_TRACE_STATE_INFO
2194         return ret;
2195 #undef STATE_COMPARE
2196 #undef STATES_COMPARE
2197 }
2198