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