1 #include "coregl_fastpath.h"
10 #define _COREGL_SYMBOL(IS_EXTENSION, RET_TYPE, FUNC_NAME, PARAM_LIST) RET_TYPE (*_orig_fastpath_##FUNC_NAME) PARAM_LIST = NULL;
11 #include "../../headers/sym.h"
14 Fastpath_Opt_Flag fp_opt = FP_UNKNOWN_PATH;
17 FILE *trace_fp = NULL;
19 GLenum FPGL_Error = GL_NO_ERROR;
21 GLGlueContext_List *gctx_list = NULL;
23 Mutex init_context_mutex = MUTEX_INITIALIZER;
24 GLGlueContext *initial_ctx = NULL;
26 Mutex ctx_list_access_mutex = MUTEX_INITIALIZER;
28 GLContext_List *glctx_list = NULL;
31 _get_texture_states(GLenum pname, GLint *params)
33 GLuint cur_active_tex = 0;
35 AST(initial_ctx != NULL);
37 _orig_fastpath_glGetIntegerv(GL_ACTIVE_TEXTURE, (GLint *)&cur_active_tex);
39 for (i = 0; i < initial_ctx->gl_num_tex_units[0]; i++)
41 _orig_fastpath_glActiveTexture(GL_TEXTURE0 + i);
42 _orig_fastpath_glGetIntegerv(pname, &(((GLint *)params)[i]));
44 _orig_fastpath_glActiveTexture(cur_active_tex);
48 init_modules_fastpath()
51 int fastpath_force_off_opt = 0;
53 COREGL_LOG("[CoreGL] <Fastpath> : ");
55 fastpath_opt = atoi(get_env_setting("COREGL_FASTPATH"));
56 fastpath_force_off_opt = atoi(get_env_setting("COREGL_FASTPATH_FORCE_OFF"));
58 if (fastpath_force_off_opt == 1)
60 COREGL_LOG("\E[40;31;1m(DISABLED by force option)\E[0m ");
67 COREGL_LOG("(%d) Fastpath enabled...\n", fastpath_opt);
68 fp_opt = FP_FAST_PATH;
71 COREGL_LOG("(%d) Default API path enabled...\n", fastpath_opt);
72 fp_opt = FP_NORMAL_PATH;
76 debug_nofp = atoi(get_env_setting("COREGL_DEBUG_NOFP"));
81 deinit_modules_fastpath()
83 GLContext_List *current = NULL;
85 AST(mutex_lock(&ctx_list_access_mutex) == 1);
87 // Destroy remained context & Detect leaks
88 int retry_destroy = 0;
96 if (current->cstate != NULL)
98 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);
100 _orig_fastpath_eglMakeCurrent(current->cstate->rdpy, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
101 _orig_fastpath_eglDestroyContext(current->cstate->rdpy, current->cstate->rctx);
103 fastpath_remove_context_states_from_list(current->cstate, NULL);
108 glctx_list = current->next;
110 current = glctx_list;
112 if (retry_destroy == 0) break;
117 AST(mutex_unlock(&ctx_list_access_mutex) == 1);
121 init_modules_tstate_fastpath(GLThreadState *tstate)
123 MY_MODULE_TSTATE *tstate_mt = NULL;
125 tstate_mt = (MY_MODULE_TSTATE *)calloc(1, sizeof(MY_MODULE_TSTATE));
127 tstate_mt->binded_api = EGL_OPENGL_ES_API;
129 tstate->module_data[MY_MODULE_ID] = tstate_mt;
133 deinit_modules_tstate_fastpath(GLThreadState *tstate)
135 if (tstate->module_data[MY_MODULE_ID] != NULL)
137 free(tstate->module_data[MY_MODULE_ID]);
138 tstate->module_data[MY_MODULE_ID] = NULL;
143 fastpath_apply_overrides()
148 fastpath_apply_overrides_egl(1);
149 fastpath_apply_overrides_gl(1);
154 COREGL_ERR("Invalide GL Override Option!!!\n");
161 fastpath_apply_overrides_egl(int enable)
163 #define _COREGL_SYMBOL(IS_EXTENSION, RET_TYPE, FUNC_NAME, PARAM_LIST) COREGL_INIT_ORIGINAL(_orig_fastpath_, FUNC_NAME);
164 # include "../../headers/sym_egl.h"
165 #undef _COREGL_SYMBOL
167 COREGL_OVERRIDE(fastpath_, eglGetProcAddress);
169 COREGL_OVERRIDE(fastpath_, eglBindAPI);
170 COREGL_OVERRIDE(fastpath_, eglQueryAPI);
172 COREGL_OVERRIDE(fastpath_, eglCreateContext);
173 COREGL_OVERRIDE(fastpath_, eglCreateImageKHR);
174 COREGL_OVERRIDE(fastpath_, eglMakeCurrent);
175 COREGL_OVERRIDE(fastpath_, eglDestroyContext);
176 COREGL_OVERRIDE(fastpath_, eglQueryContext);
177 COREGL_OVERRIDE(fastpath_, eglGetCurrentContext);
178 COREGL_OVERRIDE(fastpath_, eglReleaseThread);
179 COREGL_OVERRIDE(fastpath_, eglGetCurrentSurface);
180 COREGL_OVERRIDE(fastpath_, eglTerminate);
185 fastpath_apply_overrides_gl(int enable)
187 #define _COREGL_SYMBOL(IS_EXTENSION, RET_TYPE, FUNC_NAME, PARAM_LIST) COREGL_INIT_ORIGINAL(_orig_fastpath_, FUNC_NAME);
188 # include "../../headers/sym_gl.h"
189 #undef _COREGL_SYMBOL
193 COREGL_OVERRIDE(fastpath_, glGetError);
194 COREGL_OVERRIDE(fastpath_, glGetString);
196 COREGL_OVERRIDE(fastpath_, glGetIntegerv);
197 COREGL_OVERRIDE(fastpath_, glGetFloatv);
198 COREGL_OVERRIDE(fastpath_, glGetBooleanv);
200 COREGL_OVERRIDE(fastpath_, glActiveTexture);
201 COREGL_OVERRIDE(fastpath_, glGenTextures);
202 COREGL_OVERRIDE(fastpath_, glBindTexture);
203 COREGL_OVERRIDE(fastpath_, glIsTexture);
204 COREGL_OVERRIDE(fastpath_, glDeleteTextures);
205 COREGL_OVERRIDE(fastpath_, glFramebufferTexture2D);
207 COREGL_OVERRIDE(fastpath_, glGenBuffers);
208 COREGL_OVERRIDE(fastpath_, glBindBuffer);
209 COREGL_OVERRIDE(fastpath_, glIsBuffer);
210 COREGL_OVERRIDE(fastpath_, glDeleteBuffers);
212 COREGL_OVERRIDE(fastpath_, glGenFramebuffers);
213 COREGL_OVERRIDE(fastpath_, glBindFramebuffer);
214 COREGL_OVERRIDE(fastpath_, glIsFramebuffer);
215 COREGL_OVERRIDE(fastpath_, glDeleteFramebuffers);
216 COREGL_OVERRIDE(fastpath_, glGetFramebufferAttachmentParameteriv);
218 COREGL_OVERRIDE(fastpath_, glGenRenderbuffers);
219 COREGL_OVERRIDE(fastpath_, glBindRenderbuffer);
220 COREGL_OVERRIDE(fastpath_, glFramebufferRenderbuffer);
221 COREGL_OVERRIDE(fastpath_, glIsRenderbuffer);
222 COREGL_OVERRIDE(fastpath_, glDeleteRenderbuffers);
224 COREGL_OVERRIDE(fastpath_, glCreateShader);
225 COREGL_OVERRIDE(fastpath_, glCreateProgram);
226 COREGL_OVERRIDE(fastpath_, glAttachShader);
227 COREGL_OVERRIDE(fastpath_, glCompileShader);
228 COREGL_OVERRIDE(fastpath_, glShaderBinary);
229 COREGL_OVERRIDE(fastpath_, glDeleteShader);
230 COREGL_OVERRIDE(fastpath_, glDetachShader);
231 COREGL_OVERRIDE(fastpath_, glGetShaderiv);
232 COREGL_OVERRIDE(fastpath_, glGetShaderInfoLog);
233 COREGL_OVERRIDE(fastpath_, glGetShaderSource);
234 COREGL_OVERRIDE(fastpath_, glIsShader);
235 COREGL_OVERRIDE(fastpath_, glShaderSource);
236 COREGL_OVERRIDE(fastpath_, glBindAttribLocation);
237 COREGL_OVERRIDE(fastpath_, glDeleteProgram);
238 COREGL_OVERRIDE(fastpath_, glGetActiveAttrib);
239 COREGL_OVERRIDE(fastpath_, glGetActiveUniform);
240 COREGL_OVERRIDE(fastpath_, glGetAttachedShaders);
241 COREGL_OVERRIDE(fastpath_, glGetAttribLocation);
242 COREGL_OVERRIDE(fastpath_, glGetProgramiv);
243 COREGL_OVERRIDE(fastpath_, glGetProgramInfoLog);
244 COREGL_OVERRIDE(fastpath_, glGetUniformfv);
245 COREGL_OVERRIDE(fastpath_, glGetUniformiv);
246 COREGL_OVERRIDE(fastpath_, glGetUniformLocation);
247 COREGL_OVERRIDE(fastpath_, glIsProgram);
248 COREGL_OVERRIDE(fastpath_, glLinkProgram);
249 COREGL_OVERRIDE(fastpath_, glUseProgram);
250 COREGL_OVERRIDE(fastpath_, glValidateProgram);
252 COREGL_OVERRIDE(fastpath_, glBlendColor);
253 COREGL_OVERRIDE(fastpath_, glBlendEquation);
254 COREGL_OVERRIDE(fastpath_, glBlendEquationSeparate);
255 COREGL_OVERRIDE(fastpath_, glBlendFunc);
256 COREGL_OVERRIDE(fastpath_, glBlendFuncSeparate);
257 COREGL_OVERRIDE(fastpath_, glClearColor);
258 COREGL_OVERRIDE(fastpath_, glClearDepthf);
259 COREGL_OVERRIDE(fastpath_, glClearStencil);
260 COREGL_OVERRIDE(fastpath_, glColorMask);
261 COREGL_OVERRIDE(fastpath_, glCullFace);
262 COREGL_OVERRIDE(fastpath_, glDepthFunc);
263 COREGL_OVERRIDE(fastpath_, glDepthMask);
264 COREGL_OVERRIDE(fastpath_, glDepthRangef);
265 COREGL_OVERRIDE(fastpath_, glDisable);
266 COREGL_OVERRIDE(fastpath_, glDisableVertexAttribArray);
267 COREGL_OVERRIDE(fastpath_, glEnable);
268 COREGL_OVERRIDE(fastpath_, glEnableVertexAttribArray);
269 COREGL_OVERRIDE(fastpath_, glFrontFace);
270 COREGL_OVERRIDE(fastpath_, glHint);
271 COREGL_OVERRIDE(fastpath_, glLineWidth);
272 COREGL_OVERRIDE(fastpath_, glPixelStorei);
273 COREGL_OVERRIDE(fastpath_, glPolygonOffset);
274 COREGL_OVERRIDE(fastpath_, glSampleCoverage);
275 COREGL_OVERRIDE(fastpath_, glScissor);
276 COREGL_OVERRIDE(fastpath_, glStencilFunc);
277 COREGL_OVERRIDE(fastpath_, glStencilFuncSeparate);
278 COREGL_OVERRIDE(fastpath_, glStencilMask);
279 COREGL_OVERRIDE(fastpath_, glStencilMaskSeparate);
280 COREGL_OVERRIDE(fastpath_, glStencilOp);
281 COREGL_OVERRIDE(fastpath_, glStencilOpSeparate);
282 COREGL_OVERRIDE(fastpath_, glVertexAttrib1f);
283 COREGL_OVERRIDE(fastpath_, glVertexAttrib1fv);
284 COREGL_OVERRIDE(fastpath_, glVertexAttrib2f);
285 COREGL_OVERRIDE(fastpath_, glVertexAttrib2fv);
286 COREGL_OVERRIDE(fastpath_, glVertexAttrib3f);
287 COREGL_OVERRIDE(fastpath_, glVertexAttrib3fv);
288 COREGL_OVERRIDE(fastpath_, glVertexAttrib4f);
289 COREGL_OVERRIDE(fastpath_, glVertexAttrib4fv);
290 COREGL_OVERRIDE(fastpath_, glVertexAttribPointer);
291 COREGL_OVERRIDE(fastpath_, glViewport);
293 COREGL_OVERRIDE(fastpath_, glFramebufferTexture2DMultisampleEXT);
294 COREGL_OVERRIDE(fastpath_, glProgramParameteriEXT);
295 COREGL_OVERRIDE(fastpath_, glEGLImageTargetTexture2DOES);
296 COREGL_OVERRIDE(fastpath_, glFramebufferTexture3DOES);
299 COREGL_OVERRIDE(fastpath_, glReadBuffer);
300 COREGL_OVERRIDE(fastpath_, glDrawRangeElements);
301 COREGL_OVERRIDE(fastpath_, glTexImage3D);
302 COREGL_OVERRIDE(fastpath_, glTexSubImage3D);
303 COREGL_OVERRIDE(fastpath_, glCopyTexSubImage3D);
304 COREGL_OVERRIDE(fastpath_, glCompressedTexImage3D);
305 COREGL_OVERRIDE(fastpath_, glCompressedTexSubImage3D);
306 COREGL_OVERRIDE(fastpath_, glGenQueries);
307 COREGL_OVERRIDE(fastpath_, glDeleteQueries);
308 COREGL_OVERRIDE(fastpath_, glIsQuery);
309 COREGL_OVERRIDE(fastpath_, glBeginQuery);
310 COREGL_OVERRIDE(fastpath_, glEndQuery);
311 COREGL_OVERRIDE(fastpath_, glGetQueryiv);
312 COREGL_OVERRIDE(fastpath_, glGetQueryObjectuiv);
313 COREGL_OVERRIDE(fastpath_, glUnmapBuffer);
314 COREGL_OVERRIDE(fastpath_, glGetBufferPointerv);
315 COREGL_OVERRIDE(fastpath_, glDrawBuffers);
316 COREGL_OVERRIDE(fastpath_, glUniformMatrix2x3fv);
317 COREGL_OVERRIDE(fastpath_, glUniformMatrix3x2fv);
318 COREGL_OVERRIDE(fastpath_, glUniformMatrix2x4fv);
319 COREGL_OVERRIDE(fastpath_, glUniformMatrix4x2fv);
320 COREGL_OVERRIDE(fastpath_, glUniformMatrix3x4fv);
321 COREGL_OVERRIDE(fastpath_, glUniformMatrix4x3fv);
322 COREGL_OVERRIDE(fastpath_, glBlitFramebuffer);
323 COREGL_OVERRIDE(fastpath_, glRenderbufferStorageMultisample);
324 COREGL_OVERRIDE(fastpath_, glFramebufferTextureLayer);
325 COREGL_OVERRIDE(fastpath_, glMapBufferRange);
326 COREGL_OVERRIDE(fastpath_, glFlushMappedBufferRange);
327 COREGL_OVERRIDE(fastpath_, glBindVertexArray);
328 COREGL_OVERRIDE(fastpath_, glDeleteVertexArrays);
329 COREGL_OVERRIDE(fastpath_, glGenVertexArrays);
330 COREGL_OVERRIDE(fastpath_, glIsVertexArray);
331 COREGL_OVERRIDE(fastpath_, glGetIntegeri_v);
332 COREGL_OVERRIDE(fastpath_, glBeginTransformFeedback);
333 COREGL_OVERRIDE(fastpath_, glEndTransformFeedback);
334 COREGL_OVERRIDE(fastpath_, glBindBufferRange);
335 COREGL_OVERRIDE(fastpath_, glBindBufferBase);
336 COREGL_OVERRIDE(fastpath_, glTransformFeedbackVaryings);
337 COREGL_OVERRIDE(fastpath_, glGetTransformFeedbackVarying);
338 COREGL_OVERRIDE(fastpath_, glVertexAttribIPointer);
339 COREGL_OVERRIDE(fastpath_, glGetVertexAttribIiv);
340 COREGL_OVERRIDE(fastpath_, glGetVertexAttribIuiv);
341 COREGL_OVERRIDE(fastpath_, glVertexAttribI4i);
342 COREGL_OVERRIDE(fastpath_, glVertexAttribI4ui);
343 COREGL_OVERRIDE(fastpath_, glVertexAttribI4iv);
344 COREGL_OVERRIDE(fastpath_, glVertexAttribI4uiv);
345 COREGL_OVERRIDE(fastpath_, glGetUniformuiv);
346 COREGL_OVERRIDE(fastpath_, glGetFragDataLocation);
347 COREGL_OVERRIDE(fastpath_, glUniform1ui);
348 COREGL_OVERRIDE(fastpath_, glUniform2ui);
349 COREGL_OVERRIDE(fastpath_, glUniform3ui);
350 COREGL_OVERRIDE(fastpath_, glUniform4ui);
351 COREGL_OVERRIDE(fastpath_, glUniform1uiv);
352 COREGL_OVERRIDE(fastpath_, glUniform2uiv);
353 COREGL_OVERRIDE(fastpath_, glUniform3uiv);
354 COREGL_OVERRIDE(fastpath_, glUniform4uiv);
355 COREGL_OVERRIDE(fastpath_, glClearBufferiv);
356 COREGL_OVERRIDE(fastpath_, glClearBufferuiv);
357 COREGL_OVERRIDE(fastpath_, glClearBufferfv);
358 COREGL_OVERRIDE(fastpath_, glClearBufferfi);
359 COREGL_OVERRIDE(fastpath_, glGetStringi);
360 COREGL_OVERRIDE(fastpath_, glCopyBufferSubData);
361 COREGL_OVERRIDE(fastpath_, glGetUniformIndices);
362 COREGL_OVERRIDE(fastpath_, glGetActiveUniformsiv);
363 COREGL_OVERRIDE(fastpath_, glGetUniformBlockIndex);
364 COREGL_OVERRIDE(fastpath_, glGetActiveUniformBlockiv);
365 COREGL_OVERRIDE(fastpath_, glGetActiveUniformBlockName);
366 COREGL_OVERRIDE(fastpath_, glUniformBlockBinding);
367 COREGL_OVERRIDE(fastpath_, glDrawArraysInstanced);
368 COREGL_OVERRIDE(fastpath_, glDrawElementsInstanced);
369 COREGL_OVERRIDE(fastpath_, glFenceSync);
370 COREGL_OVERRIDE(fastpath_, glIsSync);
371 COREGL_OVERRIDE(fastpath_, glDeleteSync);
372 COREGL_OVERRIDE(fastpath_, glClientWaitSync);
373 COREGL_OVERRIDE(fastpath_, glWaitSync);
374 COREGL_OVERRIDE(fastpath_, glGetInteger64v);
375 COREGL_OVERRIDE(fastpath_, glGetSynciv);
376 COREGL_OVERRIDE(fastpath_, glGetInteger64i_v);
377 COREGL_OVERRIDE(fastpath_, glGetBufferParameteri64v);
378 COREGL_OVERRIDE(fastpath_, glGenSamplers);
379 COREGL_OVERRIDE(fastpath_, glDeleteSamplers);
380 COREGL_OVERRIDE(fastpath_, glIsSampler);
381 COREGL_OVERRIDE(fastpath_, glBindSampler);
382 COREGL_OVERRIDE(fastpath_, glSamplerParameteri);
383 COREGL_OVERRIDE(fastpath_, glSamplerParameteriv);
384 COREGL_OVERRIDE(fastpath_, glSamplerParameterf);
385 COREGL_OVERRIDE(fastpath_, glSamplerParameterfv);
386 COREGL_OVERRIDE(fastpath_, glGetSamplerParameteriv);
387 COREGL_OVERRIDE(fastpath_, glGetSamplerParameterfv);
388 COREGL_OVERRIDE(fastpath_, glVertexAttribDivisor);
389 COREGL_OVERRIDE(fastpath_, glBindTransformFeedback);
390 COREGL_OVERRIDE(fastpath_, glDeleteTransformFeedbacks);
391 COREGL_OVERRIDE(fastpath_, glGenTransformFeedbacks);
392 COREGL_OVERRIDE(fastpath_, glIsTransformFeedback);
393 COREGL_OVERRIDE(fastpath_, glPauseTransformFeedback);
394 COREGL_OVERRIDE(fastpath_, glResumeTransformFeedback);
395 COREGL_OVERRIDE(fastpath_, glGetProgramBinary); // OPEN
396 COREGL_OVERRIDE(fastpath_, glProgramBinary); // OPEN
397 COREGL_OVERRIDE(fastpath_, glProgramParameteri);
398 COREGL_OVERRIDE(fastpath_, glInvalidateFramebuffer);
399 COREGL_OVERRIDE(fastpath_, glInvalidateSubFramebuffer);
400 COREGL_OVERRIDE(fastpath_, glTexStorage2D);
401 COREGL_OVERRIDE(fastpath_, glTexStorage3D);
402 COREGL_OVERRIDE(fastpath_, glGetInternalformativ);
407 COREGL_LOG("\E[40;35;1m[CoreGL] SKIP GL FASTPATH...\E[0m\n");
413 static inline GL_Object_Hash_Base *
414 _get_shared_object_hash(GL_Shared_Object_State *sostate, GL_Object_Type type)
418 case GL_OBJECT_TYPE_TEXTURE:
419 return &sostate->texture;
420 case GL_OBJECT_TYPE_BUFFER:
421 return &sostate->buffer;
422 case GL_OBJECT_TYPE_FRAMEBUFFER:
423 return &sostate->framebuffer;
424 case GL_OBJECT_TYPE_RENDERBUFFER:
425 return &sostate->renderbuffer;
426 case GL_OBJECT_TYPE_PROGRAM:
427 return &sostate->program;
433 static inline GL_Object_Hash_Base *
434 _get_shared_object_hash_real(GL_Shared_Object_State *sostate, GL_Object_Type type)
438 case GL_OBJECT_TYPE_TEXTURE:
439 return &sostate->texture_real;
440 case GL_OBJECT_TYPE_BUFFER:
441 return &sostate->buffer_real;
442 case GL_OBJECT_TYPE_FRAMEBUFFER:
443 return &sostate->framebuffer_real;
444 case GL_OBJECT_TYPE_RENDERBUFFER:
445 return &sostate->renderbuffer_real;
446 case GL_OBJECT_TYPE_PROGRAM:
447 return &sostate->program_real;
454 fastpath_add_context_state_to_list(const void *option, const int option_len, GLContextState *cstate, Mutex *mtx)
458 GLContext_List *current = NULL;
459 GLContext_List *newitm = NULL;
461 if (mtx != NULL) AST(mutex_lock(mtx) == 1);
465 tid = get_current_thread();
467 current = glctx_list;
468 while (current != NULL)
470 if (current->option_len == option_len &&
471 memcmp(current->option, option, option_len) == 0 &&
472 current->thread_id == tid)
474 AST(current->cstate == cstate);
477 current = current->next;
480 newitm = (GLContext_List *)calloc(1, sizeof(GLContext_List));
483 COREGL_ERR("Failed to create context list.\n");
487 newitm->cstate = cstate;
488 newitm->thread_id = tid;
489 newitm->option_len = option_len;
490 newitm->option = (void *)malloc(option_len);
491 memcpy(newitm->option, option, option_len);
493 if (glctx_list != NULL)
494 newitm->next = glctx_list;
515 if (mtx != NULL) AST(mutex_unlock(mtx) == 1);
521 fastpath_get_context_state_from_list(const void *option, const int option_len, Mutex *mtx)
523 GLContextState *ret = NULL;
524 GLContext_List *current = NULL;
527 if (mtx != NULL) AST(mutex_lock(mtx) == 1);
529 tid = get_current_thread();
531 current = glctx_list;
532 while (current != NULL)
534 if (current->option_len == option_len &&
535 memcmp(current->option, option, option_len) == 0 &&
536 current->thread_id == tid)
538 ret = current->cstate;
541 current = current->next;
546 if (mtx != NULL) AST(mutex_unlock(mtx) == 1);
551 fastpath_remove_context_states_from_list(GLContextState *cstate, Mutex *mtx)
555 GLContext_List *olditm = NULL;
556 GLContext_List *current = NULL;
558 if (mtx != NULL) AST(mutex_lock(mtx) == 1);
562 tid = get_current_thread();
563 current = glctx_list;
565 while (current != NULL)
567 if (current->cstate == cstate)
569 GLContext_List *nextitm = NULL;
572 olditm->next = current->next;
573 nextitm = olditm->next;
577 glctx_list = current->next;
578 nextitm = glctx_list;
580 if (current->option != NULL)
582 AST(current->option_len > 0);
583 free(current->option);
584 current->option = NULL;
585 current->option_len = 0;
593 current = current->next;
598 if (mtx != NULL) AST(mutex_unlock(mtx) == 1);
603 fastpath_sostate_init(GL_Shared_Object_State *sostate)
605 #define HASH_INIT(hash_base) \
606 hash_base.hash_field = (GL_Object_Hash **)calloc(1, sizeof(GL_Object_Hash *) * GL_OBJECT_HASH_BASE); \
607 hash_base.hash_size = GL_OBJECT_HASH_BASE;
609 HASH_INIT(sostate->texture);
610 HASH_INIT(sostate->buffer);
611 HASH_INIT(sostate->framebuffer);
612 HASH_INIT(sostate->renderbuffer);
613 HASH_INIT(sostate->program);
615 HASH_INIT(sostate->texture_real);
616 HASH_INIT(sostate->buffer_real);
617 HASH_INIT(sostate->framebuffer_real);
618 HASH_INIT(sostate->renderbuffer_real);
619 HASH_INIT(sostate->program_real);
625 _add_hash(GL_Object_Hash_Base *hash_base, GL_Object_Hash *data)
627 int array_idx = data->hash_key & (hash_base->hash_size - 1);
628 if (hash_base->hash_field[array_idx] == NULL)
630 hash_base->hash_field[array_idx] = data;
634 GL_Object_Hash *current = hash_base->hash_field[array_idx];
637 AST(current->hash_key != data->hash_key);
638 current = current->next;
640 current->next = data;
643 hash_base->item_size++;
647 _remove_hash(GL_Object_Hash_Base *hash_base, GLuint hash)
650 int array_idx = hash & (hash_base->hash_size - 1);
652 GL_Object_Hash *current = hash_base->hash_field[array_idx];
653 GL_Object_Hash *prev = NULL;
657 if (current->hash_key == hash)
660 prev->next = current->next;
662 hash_base->hash_field[array_idx] = current->next;
663 hash_base->item_size--;
668 current = current->next;
675 _free_hash_list(GL_Object_Hash_Base *hash_base, int free_data)
677 if (hash_base->item_size == 0) return;
679 for (int i = 0; i < hash_base->hash_size; i++)
681 if (hash_base->hash_field[i] != NULL)
683 GL_Object_Hash *current = hash_base->hash_field[i];
685 while (current != NULL)
687 GL_Object_Hash *current_next = current->next;
689 if (free_data == 1 && current->item != NULL)
695 hash_base->item_size--;
696 current = current_next;
703 fastpath_sostate_deinit(GL_Shared_Object_State *sostate)
705 #define HASH_DEINIT(hash_base, free_data) \
706 _free_hash_list(&hash_base, free_data); \
707 free(hash_base.hash_field); \
708 hash_base.hash_size = 0;
710 HASH_DEINIT(sostate->texture, 1);
711 HASH_DEINIT(sostate->buffer, 1);
712 HASH_DEINIT(sostate->framebuffer, 1);
713 HASH_DEINIT(sostate->renderbuffer, 1);
714 HASH_DEINIT(sostate->program, 1);
716 HASH_DEINIT(sostate->texture_real, 0);
717 HASH_DEINIT(sostate->buffer_real, 0);
718 HASH_DEINIT(sostate->framebuffer_real, 0);
719 HASH_DEINIT(sostate->renderbuffer_real, 0);
720 HASH_DEINIT(sostate->program_real, 0);
725 #define FIND_HASH(hash_base, key, ret) \
727 GL_Object_Hash *fh_current = hash_base->hash_field[(key) & (hash_base->hash_size - 1)]; \
730 if (fh_current->hash_key == (key)) \
735 fh_current = fh_current->next; \
740 _sostate_hash_check(GL_Object_Hash_Base *hash_base)
742 if (hash_base->item_size + 1 < hash_base->hash_size)
745 int oldsize = hash_base->hash_size;
746 GL_Object_Hash **oldfield = hash_base->hash_field;
748 hash_base->hash_size = oldsize << 1;
749 hash_base->hash_field = (GL_Object_Hash **)calloc(1, sizeof(GL_Object_Hash *) * hash_base->hash_size);
750 AST(hash_base->hash_field != NULL);
752 for (int i = 0; i < oldsize; i++)
754 if (oldfield[i] != NULL)
756 GL_Object_Hash *current = oldfield[i];
758 while (current != NULL)
760 GL_Object_Hash *current_next = current->next;
761 _add_hash(hash_base, current);
762 hash_base->item_size--;
763 current = current_next;
772 fastpath_sostate_create_object(GL_Shared_Object_State *sostate, GL_Object_Type type, GLuint real_name)
774 GLuint ret = _COREGL_INT_INIT_VALUE;
776 GL_Object_Hash_Base *hash_base = NULL;
777 GL_Object_Hash_Base *hash_base_real = NULL;
778 int newid = _COREGL_INT_INIT_VALUE;
780 hash_base = _get_shared_object_hash(sostate, type);
781 hash_base_real = _get_shared_object_hash_real(sostate, type);
783 newid = hash_base->last_id + 1;
784 if (newid >= hash_base->hash_size)
786 hash_base->is_looped = 1;
788 hash_base->last_id = 1;
791 if (hash_base->is_looped != 0)
794 int findingid = newid;
796 for (i = 0; i < hash_base->hash_size; i++)
798 GL_Object_Hash *exist_hash = NULL;
799 FIND_HASH(hash_base, findingid, exist_hash);
800 if (exist_hash == NULL)
806 if (findingid >= hash_base->hash_size) findingid = 1;
810 hash_base->last_id = newid;
813 GL_Object *newobj = (GL_Object *)calloc(1, sizeof(GL_Object));
815 newobj->id = (int)type + newid;
816 newobj->real_id = real_name;
817 newobj->ref_count = 1;
820 GL_Object_Hash *newobj_hash = (GL_Object_Hash *)calloc(1, sizeof(GL_Object_Hash));
821 AST(newobj_hash != NULL);
822 newobj_hash->item = newobj;
823 newobj_hash->hash_key = newid;
824 _add_hash(hash_base, newobj_hash);
826 GL_Object_Hash *newobj_hash_real = (GL_Object_Hash *)calloc(1, sizeof(GL_Object_Hash));
827 AST(newobj_hash_real != NULL);
828 newobj_hash_real->item = newobj;
829 newobj_hash_real->hash_key = real_name;
830 _add_hash(hash_base_real, newobj_hash_real);
833 _sostate_hash_check(hash_base);
834 _sostate_hash_check(hash_base_real);
842 #define FIND_OBJ_FROM_HASH_WITH_VERIFY(hash_base, hash, object) \
843 if ((hash) < 0) { ret = 0; goto finish; } \
845 GL_Object_Hash *object_hash = NULL; \
846 FIND_HASH((hash_base), (hash), object_hash); \
847 if (object_hash == NULL) { ret = 0; goto finish; } \
848 (object) = object_hash->item; \
849 if ((object) == NULL) { ret = 0; goto finish; } \
853 fastpath_sostate_remove_object(GL_Shared_Object_State *sostate, GL_Object_Type type, GLuint glue_name)
855 GLuint ret = _COREGL_INT_INIT_VALUE;
857 GL_Object_Hash_Base *hash_base = NULL;
858 GL_Object_Hash_Base *hash_base_real = NULL;
859 GL_Object *object = NULL;
861 hash_base = _get_shared_object_hash(sostate, type);
862 hash_base_real = _get_shared_object_hash_real(sostate, type);
864 FIND_OBJ_FROM_HASH_WITH_VERIFY(hash_base, glue_name - (int)type, object);
868 if (object->ref_count <= 0)
870 GL_Object_Hash *object_hash = NULL;
872 FIND_HASH(hash_base, object->id - (int)type, object_hash);
873 AST(object_hash != NULL);
874 _remove_hash(hash_base, object->id - (int)type);
878 FIND_HASH(hash_base_real, object->real_id, object_hash);
879 AST(object_hash != NULL);
880 _remove_hash(hash_base_real, object->real_id);
896 fastpath_sostate_get_object(GL_Shared_Object_State *sostate, GL_Object_Type type, GLuint glue_name)
898 GLuint ret = _COREGL_INT_INIT_VALUE;
900 GL_Object_Hash_Base *hash_base = NULL;
901 GL_Object *object = NULL;
903 hash_base = _get_shared_object_hash(sostate, type);
905 FIND_OBJ_FROM_HASH_WITH_VERIFY(hash_base, glue_name - (int)type, object);
907 ret = object->real_id;
915 fastpath_sostate_set_object_tag(GL_Shared_Object_State *sostate, GL_Object_Type type, GLuint glue_name, GLvoid *tag)
917 GLint ret = _COREGL_INT_INIT_VALUE;
919 GL_Object_Hash_Base *hash_base = NULL;
920 GL_Object *object = NULL;
921 int hash = _COREGL_INT_INIT_VALUE;
923 hash_base = _get_shared_object_hash(sostate, type);
925 hash = glue_name - (int)type;
927 FIND_OBJ_FROM_HASH_WITH_VERIFY(hash_base, hash, object);
929 AST(object->tag == NULL);
939 fastpath_sostate_get_object_tag(GL_Shared_Object_State *sostate, GL_Object_Type type, GLuint glue_name)
943 GL_Object_Hash_Base *hash_base = NULL;
944 GL_Object *object = NULL;
946 hash_base = _get_shared_object_hash(sostate, type);
948 FIND_OBJ_FROM_HASH_WITH_VERIFY(hash_base, glue_name - (int)type, object);
958 fastpath_sostate_find_object(GL_Shared_Object_State *sostate, GL_Object_Type type, GLuint real_name)
960 GLuint ret = _COREGL_INT_INIT_VALUE;
962 GL_Object_Hash_Base *hash_base_real = NULL;
963 GL_Object *object = NULL;
965 hash_base_real = _get_shared_object_hash_real(sostate, type);
967 FIND_OBJ_FROM_HASH_WITH_VERIFY(hash_base_real, real_name, object);
977 fastpath_sostate_use_object(GL_Shared_Object_State *sostate, GL_Object_Type type, GLuint glue_name)
979 GLint ret = _COREGL_INT_INIT_VALUE;
981 GL_Object_Hash_Base *hash_base = NULL;
982 GL_Object *object = NULL;
984 hash_base = _get_shared_object_hash(sostate, type);
986 FIND_OBJ_FROM_HASH_WITH_VERIFY(hash_base, glue_name - (int)type, object);
997 fastpath_dump_context_states(GLGlueContext *ctx, int force_output)
999 static struct timeval tv_last = { 0, 0 };
1001 if (unlikely(trace_state_flag != 1)) return;
1005 struct timeval tv_now = { 0, 0 };
1006 AST(gettimeofday(&tv_now, NULL) == 0);
1007 if (tv_now.tv_sec - tv_last.tv_sec < _COREGL_TRACE_OUTPUT_INTERVAL_SEC)
1015 TRACE("\E[0;40;34m========================================================================================================================\E[0m\n");
1016 TRACE("\E[40;32;1m State info \E[1;37;1m: <PID = %d> GlueCTX = %p\E[0m\n", getpid(), ctx);
1017 TRACE("\E[0;40;34m========================================================================================================================\E[0m\n");
1019 #define PRINTF_CHAR_GLenum "%10d"
1020 #define PRINTF_CHAR_GLboolean "%10d"
1021 #define PRINTF_CHAR_GLint "%10d"
1022 #define PRINTF_CHAR_GLsizei "%10u"
1023 #define PRINTF_CHAR_GLuint "%10u"
1024 #define PRINTF_CHAR_GLuintmask "0x%8X"
1026 #define PRINTF_CHAR_GLclampf "%10.6f"
1027 #define PRINTF_CHAR_GLfloat "%10.6f"
1029 #define PRINTF_CHAR_GLvoidptr "%10p"
1031 #define PRINTF_CHAR(type) PRINTF_CHAR_##type
1033 #define INITIAL_CTX initial_ctx
1034 #define GLUE_STATE(TYPE, NAME, SIZE, ARRAY_SIZE, DEFAULT_STMT, GET_STMT) \
1036 TYPE valuedata[SIZE]; \
1037 TYPE *value = NULL; \
1038 value = valuedata; GET_STMT; value = valuedata; \
1039 TRACE("\E[40;37;1m %-30.30s : (\E[0m ", #NAME); \
1040 for (int i = 0; i < SIZE; i++) \
1044 TRACE("\n %-30.30s ", "");\
1048 TRACE(PRINTF_CHAR(TYPE), ctx->NAME[i]); \
1049 TRACE("["PRINTF_CHAR(TYPE)"]", value[i]); \
1051 TRACE(" \E[40;37;1m)\E[0m\n"); \
1053 # include "coregl_fastpath_state.h"
1057 TRACE("\E[0;40;34m========================================================================================================================\E[0m\n");
1067 fastpath_init_context_states(GLGlueContext *ctx)
1071 AST(mutex_lock(&init_context_mutex) == 1);
1075 COREGL_ERR("Context NULL\n");
1080 AST(ctx->initialized == 0);
1081 AST(ctx->sostate != NULL);
1083 if (initial_ctx == NULL)
1085 initial_ctx = (GLGlueContext *)calloc(1, sizeof(GLGlueContext));
1086 AST(initial_ctx != NULL);
1088 //#define FORCE_DEFAULT_VALUE
1089 #ifdef FORCE_DEFAULT_VALUE
1090 # define INITIAL_CTX initial_ctx
1091 # define GLUE_STATE(TYPE, NAME, SIZE, ARRAY_SIZE, DEFAULT_STMT, GET_STMT) \
1094 TYPE valuedata[SIZE]; \
1095 TYPE *value = NULL; \
1096 memset(valuedata, 0xcc, sizeof(TYPE) * SIZE); \
1097 value = valuedata; DEFAULT_STMT; value = valuedata; \
1098 for (i = 0; i < SIZE; i++) \
1100 if (*((char *)(&value[i])) == 0xcc) \
1102 memset(&value[i], 0xaa, sizeof(TYPE)); \
1103 value = valuedata; DEFAULT_STMT; value = valuedata; \
1104 if (*((char *)(&value[i])) == 0xaa) \
1106 COREGL_WRN("\E[40;31;1mGL-state '"#NAME"' cannot be retrieved\E[0m\n"); \
1110 initial_ctx->NAME[i] = value[i]; \
1113 # include "coregl_fastpath_state.h"
1117 # define INITIAL_CTX initial_ctx
1118 # define SET_GLUE_VALUE(DEFAULT_STMT, FALLBACK_STMT) \
1119 if (try_step == 1) \
1121 value = valuedata; DEFAULT_STMT; value = valuedata; \
1125 value = valuedata; FALLBACK_STMT; value = valuedata; \
1128 # define GLUE_STATE(TYPE, NAME, SIZE, ARRAY_SIZE, DEFAULT_STMT, GET_STMT) \
1132 TYPE valuedata[SIZE]; \
1133 TYPE *value = NULL; \
1134 _sym_glGetError(); \
1135 memset(valuedata, 0xcc, sizeof(TYPE) * SIZE); \
1138 SET_GLUE_VALUE(GET_STMT, DEFAULT_STMT); \
1139 if (_sym_glGetError() == GL_INVALID_ENUM) \
1141 initial_ctx->NAME##_used = 0; \
1142 value = valuedata; DEFAULT_STMT; value = valuedata; \
1145 initial_ctx->NAME##_used = 1; \
1146 for (i = 0; i < SIZE; i++) \
1148 if (*((char *)(&value[i])) == 0xcc) \
1150 memset(&value[i], 0xaa, sizeof(TYPE)); \
1151 SET_GLUE_VALUE(GET_STMT, DEFAULT_STMT); \
1152 if (*((char *)(&value[i])) == 0xaa) \
1155 if (try_step == 2) \
1157 COREGL_WRN("\E[40;31;1mGL-state '"#NAME"' cannot be retrieved\E[0m\n"); \
1162 initial_ctx->NAME[i] = value[i]; \
1164 if (try_step != 2) \
1166 value = valuedata; DEFAULT_STMT; value = valuedata; \
1167 for (i = 0; i < SIZE; i++) \
1169 if (initial_ctx->NAME[i] != value[i]) \
1171 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]); \
1176 while (try_step == 2); \
1178 # include "coregl_fastpath_state.h"
1179 # undef SET_GLUE_VALUE
1184 if (initial_ctx->gl_num_vertex_attribs[0] > MAX_VERTEX_ATTRIBS)
1186 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]);
1188 if (initial_ctx->gl_num_tex_units[0] > MAX_TEXTURE_UNITS)
1190 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]);
1196 #define INITIAL_CTX initial_ctx
1197 #define GLUE_STATE(TYPE, NAME, SIZE, ARRAY_SIZE, DEFAULT_STMT, GET_STMT) \
1198 for (i = 0; i < SIZE; i++) \
1200 ctx->NAME[i] = initial_ctx->NAME[i]; \
1201 ctx->NAME##_used = initial_ctx->NAME##_used; \
1203 # include "coregl_fastpath_state.h"
1208 ctx->initialized = 1;
1213 AST(mutex_unlock(&init_context_mutex) == 1);
1218 #ifdef COREGL_USE_MODULE_TRACEPATH
1219 extern void *tracepath_api_trace_begin(const char *name, void *hint, int trace_total_time);
1220 extern void *tracepath_api_trace_end(const char *name, void *hint, int trace_total_time);
1223 #define CHECK_GL_ERROR(func) \
1226 int err = _orig_fastpath_glGetError(); \
1227 if (err != GL_NO_ERROR) \
1229 COREGL_ERR("\E[40;31;1m(GL %p) : %s returns GL error 0x%X\E[0m\n", oldctx->cstate, #func, err); \
1235 fastpath_make_context_current(GLGlueContext *oldctx, GLGlueContext *newctx)
1238 unsigned char flag = 0;
1241 if (debug_nofp == 1)
1247 // Return if they're the same
1248 if (oldctx == newctx)
1254 #define STATE_COMPARE(state) \
1255 if ((oldctx->state) != (newctx->state))
1257 #define STATES_COMPARE(state_ptr, bytes) \
1258 if ((memcmp((oldctx->state_ptr), (newctx->state_ptr), (bytes))) != 0)
1261 #ifdef COREGL_USE_MODULE_TRACEPATH
1262 static void *trace_hint_glfinish = NULL;
1263 trace_hint_glfinish = tracepath_api_trace_begin("eglMakeCurrent(FP glFinish)", trace_hint_glfinish, 0);
1264 #endif // COREGL_USE_MODULE_TRACEPATH
1267 int err = _orig_fastpath_glGetError();
1268 if (err != GL_NO_ERROR && oldctx->gl_error == GL_NO_ERROR)
1269 oldctx->gl_error = err;
1272 CHECK_GL_ERROR(_orig_fastpath_glFlush())
1274 #ifdef COREGL_USE_MODULE_TRACEPATH
1275 tracepath_api_trace_end("eglMakeCurrent(FP glFinish)", trace_hint_glfinish, 0);
1276 #endif // COREGL_USE_MODULE_TRACEPATH
1278 #ifdef COREGL_USE_MODULE_TRACEPATH
1279 static void *trace_hint_bindbuffers = NULL;
1280 trace_hint_bindbuffers = tracepath_api_trace_begin("eglMakeCurrent(FP bind buffers)", trace_hint_bindbuffers, 0);
1281 #endif // COREGL_USE_MODULE_TRACEPATH
1284 //------------------//
1286 flag = oldctx->_bind_flag | newctx->_bind_flag;
1289 STATE_COMPARE(gl_array_buffer_binding[0])
1291 CHECK_GL_ERROR(_orig_fastpath_glBindBuffer(GL_ARRAY_BUFFER, newctx->gl_array_buffer_binding[0]))
1293 STATE_COMPARE(gl_element_array_buffer_binding[0])
1295 CHECK_GL_ERROR(_orig_fastpath_glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, newctx->gl_element_array_buffer_binding[0]))
1297 // ANGLE_framebuffer_blit BEGIN
1298 if (newctx->gl_framebuffer_binding_read_used == 1)
1300 STATE_COMPARE(gl_framebuffer_binding_read[0])
1302 CHECK_GL_ERROR(_orig_fastpath_glBindFramebuffer(GL_READ_FRAMEBUFFER_ANGLE, newctx->gl_framebuffer_binding_read[0]))
1304 STATE_COMPARE(gl_framebuffer_binding_draw[0])
1306 CHECK_GL_ERROR(_orig_fastpath_glBindFramebuffer(GL_DRAW_FRAMEBUFFER_ANGLE, newctx->gl_framebuffer_binding_draw[0]))
1310 // ANGLE_framebuffer_blit END
1312 STATE_COMPARE(gl_framebuffer_binding[0])
1314 CHECK_GL_ERROR(_orig_fastpath_glBindFramebuffer(GL_FRAMEBUFFER, newctx->gl_framebuffer_binding[0]))
1317 STATE_COMPARE(gl_renderbuffer_binding[0])
1319 CHECK_GL_ERROR(_orig_fastpath_glBindRenderbuffer(GL_RENDERBUFFER, newctx->gl_renderbuffer_binding[0]))
1323 #ifdef COREGL_USE_MODULE_TRACEPATH
1324 tracepath_api_trace_end("eglMakeCurrent(FP bind buffers)", trace_hint_bindbuffers, 0);
1325 #endif // COREGL_USE_MODULE_TRACEPATH
1328 //------------------//
1331 #ifdef COREGL_USE_MODULE_TRACEPATH
1332 static void *trace_hint_enable_states = NULL;
1333 trace_hint_enable_states = tracepath_api_trace_begin("eglMakeCurrent(FP enable states)", trace_hint_enable_states, 0);
1334 #endif // COREGL_USE_MODULE_TRACEPATH
1336 flag = oldctx->_enable_flag1 | newctx->_enable_flag1;
1339 STATE_COMPARE(gl_blend[0])
1341 if (newctx->gl_blend[0])
1343 CHECK_GL_ERROR(_orig_fastpath_glEnable(GL_BLEND))
1346 CHECK_GL_ERROR(_orig_fastpath_glDisable(GL_BLEND))
1348 STATE_COMPARE(gl_cull_face[0])
1350 if (newctx->gl_cull_face[0])
1352 CHECK_GL_ERROR(_orig_fastpath_glEnable(GL_CULL_FACE))
1355 CHECK_GL_ERROR(_orig_fastpath_glDisable(GL_CULL_FACE))
1357 STATE_COMPARE(gl_depth_test[0])
1359 if (newctx->gl_depth_test[0])
1361 CHECK_GL_ERROR(_orig_fastpath_glEnable(GL_DEPTH_TEST))
1364 CHECK_GL_ERROR(_orig_fastpath_glDisable(GL_DEPTH_TEST))
1366 STATE_COMPARE(gl_dither[0])
1368 if (newctx->gl_dither[0])
1370 CHECK_GL_ERROR(_orig_fastpath_glEnable(GL_DITHER))
1373 CHECK_GL_ERROR(_orig_fastpath_glDisable(GL_DITHER))
1378 flag = oldctx->_enable_flag2 | newctx->_enable_flag2;
1381 STATE_COMPARE(gl_polygon_offset_fill[0])
1383 if (newctx->gl_polygon_offset_fill[0])
1385 CHECK_GL_ERROR(_orig_fastpath_glEnable(GL_POLYGON_OFFSET_FILL))
1388 CHECK_GL_ERROR(_orig_fastpath_glDisable(GL_POLYGON_OFFSET_FILL))
1390 STATE_COMPARE(gl_sample_alpha_to_coverage[0])
1392 if (newctx->gl_sample_alpha_to_coverage[0])
1394 CHECK_GL_ERROR(_orig_fastpath_glEnable(GL_SAMPLE_ALPHA_TO_COVERAGE))
1397 CHECK_GL_ERROR(_orig_fastpath_glDisable(GL_SAMPLE_ALPHA_TO_COVERAGE))
1399 STATE_COMPARE(gl_sample_coverage[0])
1401 if (newctx->gl_sample_coverage[0])
1403 CHECK_GL_ERROR(_orig_fastpath_glEnable(GL_SAMPLE_COVERAGE))
1406 CHECK_GL_ERROR(_orig_fastpath_glDisable(GL_SAMPLE_COVERAGE))
1408 STATE_COMPARE(gl_scissor_test[0])
1410 if (newctx->gl_scissor_test[0])
1412 CHECK_GL_ERROR(_orig_fastpath_glEnable(GL_SCISSOR_TEST))
1415 CHECK_GL_ERROR(_orig_fastpath_glDisable(GL_SCISSOR_TEST))
1417 STATE_COMPARE(gl_stencil_test[0])
1419 if (newctx->gl_stencil_test[0])
1421 CHECK_GL_ERROR(_orig_fastpath_glEnable(GL_STENCIL_TEST))
1424 CHECK_GL_ERROR(_orig_fastpath_glDisable(GL_STENCIL_TEST))
1428 #ifdef COREGL_USE_MODULE_TRACEPATH
1429 tracepath_api_trace_end("eglMakeCurrent(FP enable states)", trace_hint_enable_states, 0);
1430 #endif // COREGL_USE_MODULE_TRACEPATH
1432 //------------------//
1434 #ifdef COREGL_USE_MODULE_TRACEPATH
1435 static void *trace_hint_clear_viewport = NULL;
1436 trace_hint_clear_viewport = tracepath_api_trace_begin("eglMakeCurrent(FP clear/viewport)", trace_hint_clear_viewport, 0);
1437 #endif // COREGL_USE_MODULE_TRACEPATH
1439 flag = oldctx->_clear_flag1 | newctx->_clear_flag1;
1443 STATES_COMPARE(gl_viewport, 4 * sizeof(GLint))
1445 CHECK_GL_ERROR(_orig_fastpath_glViewport(newctx->gl_viewport[0],
1446 newctx->gl_viewport[1],
1447 newctx->gl_viewport[2],
1448 newctx->gl_viewport[3]))
1451 STATE_COMPARE(gl_current_program[0])
1453 CHECK_GL_ERROR(_orig_fastpath_glUseProgram(newctx->gl_current_program[0]))
1455 STATES_COMPARE(gl_color_clear_value, 4 * sizeof(GLclampf))
1457 CHECK_GL_ERROR(_orig_fastpath_glClearColor(newctx->gl_color_clear_value[0],
1458 newctx->gl_color_clear_value[1],
1459 newctx->gl_color_clear_value[2],
1460 newctx->gl_color_clear_value[3]))
1466 flag = oldctx->_clear_flag2 | newctx->_clear_flag2;
1469 STATES_COMPARE(gl_color_writemask, 4 * sizeof(GLboolean))
1471 CHECK_GL_ERROR(_orig_fastpath_glColorMask(newctx->gl_color_writemask[0],
1472 newctx->gl_color_writemask[1],
1473 newctx->gl_color_writemask[2],
1474 newctx->gl_color_writemask[3]))
1476 STATES_COMPARE(gl_depth_range, 2 * sizeof(GLclampf))
1478 CHECK_GL_ERROR(_orig_fastpath_glDepthRangef(newctx->gl_depth_range[0],
1479 newctx->gl_depth_range[1]))
1481 STATE_COMPARE(gl_depth_clear_value[0])
1483 CHECK_GL_ERROR(_orig_fastpath_glClearDepthf(newctx->gl_depth_clear_value[0]))
1485 STATE_COMPARE(gl_depth_func[0])
1487 CHECK_GL_ERROR(_orig_fastpath_glDepthFunc(newctx->gl_depth_func[0]))
1489 STATE_COMPARE(gl_depth_writemask[0])
1491 CHECK_GL_ERROR(_orig_fastpath_glDepthMask(newctx->gl_depth_writemask[0]))
1493 STATE_COMPARE(gl_cull_face_mode[0])
1495 CHECK_GL_ERROR(_orig_fastpath_glCullFace(newctx->gl_cull_face_mode[0]))
1500 #ifdef COREGL_USE_MODULE_TRACEPATH
1501 tracepath_api_trace_end("eglMakeCurrent(FP clear/viewport)", trace_hint_clear_viewport, 0);
1502 #endif // COREGL_USE_MODULE_TRACEPATH
1504 //------------------//
1506 #ifdef COREGL_USE_MODULE_TRACEPATH
1507 static void *trace_hint_bind_textures = NULL;
1508 trace_hint_bind_textures = tracepath_api_trace_begin("eglMakeCurrent(FP bind textures)", trace_hint_bind_textures, 0);
1509 #endif // COREGL_USE_MODULE_TRACEPATH
1511 flag = oldctx->_tex_flag1 | newctx->_tex_flag1;
1515 for (i = 0; i < oldctx->gl_num_tex_units[0]; i++)
1517 STATE_COMPARE(gl_tex_2d_state[i])
1519 CHECK_GL_ERROR(_orig_fastpath_glActiveTexture(GL_TEXTURE0 + i))
1520 CHECK_GL_ERROR(_orig_fastpath_glBindTexture(GL_TEXTURE_2D, newctx->gl_tex_2d_state[i]))
1523 STATE_COMPARE(gl_tex_cube_state[i])
1525 CHECK_GL_ERROR(_orig_fastpath_glActiveTexture(GL_TEXTURE0 + i))
1526 CHECK_GL_ERROR(_orig_fastpath_glBindTexture(GL_TEXTURE_CUBE_MAP, newctx->gl_tex_cube_state[i]))
1530 // Restore active texture
1531 CHECK_GL_ERROR(_orig_fastpath_glActiveTexture(newctx->gl_active_texture[0]))
1533 STATE_COMPARE(gl_generate_mipmap_hint[0])
1535 CHECK_GL_ERROR(_orig_fastpath_glHint(GL_GENERATE_MIPMAP_HINT, newctx->gl_generate_mipmap_hint[0]))
1538 #ifdef COREGL_USE_MODULE_TRACEPATH
1539 tracepath_api_trace_end("eglMakeCurrent(FP bind textures)", trace_hint_bind_textures, 0);
1540 #endif // COREGL_USE_MODULE_TRACEPATH
1542 //------------------//
1543 #ifdef COREGL_USE_MODULE_TRACEPATH
1544 static void *trace_hint_etc = NULL;
1545 trace_hint_etc = tracepath_api_trace_begin("eglMakeCurrent(FP etc.)", trace_hint_etc, 0);
1546 #endif // COREGL_USE_MODULE_TRACEPATH
1548 flag = oldctx->_blend_flag | newctx->_blend_flag;
1551 STATES_COMPARE(gl_blend_color, 4 * sizeof(GLclampf))
1553 CHECK_GL_ERROR(_orig_fastpath_glBlendColor(newctx->gl_blend_color[0],
1554 newctx->gl_blend_color[1],
1555 newctx->gl_blend_color[2],
1556 newctx->gl_blend_color[3]))
1558 if ((oldctx->gl_blend_src_rgb[0] != newctx->gl_blend_src_rgb[0]) ||
1559 (oldctx->gl_blend_dst_rgb[0] != newctx->gl_blend_dst_rgb[0]) ||
1560 (oldctx->gl_blend_src_alpha[0] != newctx->gl_blend_src_alpha[0]) ||
1561 (oldctx->gl_blend_dst_alpha[0] != newctx->gl_blend_dst_alpha[0]))
1563 CHECK_GL_ERROR(_orig_fastpath_glBlendFuncSeparate(newctx->gl_blend_src_rgb[0],
1564 newctx->gl_blend_dst_rgb[0],
1565 newctx->gl_blend_src_alpha[0],
1566 newctx->gl_blend_dst_alpha[0]))
1568 if ((oldctx->gl_blend_equation_rgb[0] != newctx->gl_blend_equation_rgb[0]) ||
1569 (oldctx->gl_blend_equation_alpha[0] != newctx->gl_blend_equation_alpha[0]))
1571 CHECK_GL_ERROR(_orig_fastpath_glBlendEquationSeparate(newctx->gl_blend_equation_rgb[0], newctx->gl_blend_equation_alpha[0]))
1576 //------------------//
1578 flag = oldctx->_stencil_flag1 | newctx->_stencil_flag1;
1581 if ((oldctx->gl_stencil_func[0] != newctx->gl_stencil_func[0]) ||
1582 (oldctx->gl_stencil_ref[0] != newctx->gl_stencil_ref[0]) ||
1583 (oldctx->gl_stencil_value_mask[0] != newctx->gl_stencil_value_mask[0]))
1585 CHECK_GL_ERROR(_orig_fastpath_glStencilFuncSeparate(GL_FRONT,
1586 newctx->gl_stencil_func[0],
1587 newctx->gl_stencil_ref[0],
1588 newctx->gl_stencil_value_mask[0]))
1590 if ((oldctx->gl_stencil_fail[0] != newctx->gl_stencil_fail[0]) ||
1591 (oldctx->gl_stencil_pass_depth_fail[0] != newctx->gl_stencil_pass_depth_fail[0]) ||
1592 (oldctx->gl_stencil_pass_depth_pass[0] != newctx->gl_stencil_pass_depth_pass[0]))
1594 CHECK_GL_ERROR(_orig_fastpath_glStencilOpSeparate(GL_FRONT,
1595 newctx->gl_stencil_fail[0],
1596 newctx->gl_stencil_pass_depth_fail[0],
1597 newctx->gl_stencil_pass_depth_pass[0]))
1600 STATE_COMPARE(gl_stencil_writemask[0])
1602 CHECK_GL_ERROR(_orig_fastpath_glStencilMaskSeparate(GL_FRONT, newctx->gl_stencil_writemask[0]))
1608 flag = oldctx->_stencil_flag2 | newctx->_stencil_flag2;
1611 if ((oldctx->gl_stencil_back_func[0] != newctx->gl_stencil_back_func[0]) ||
1612 (oldctx->gl_stencil_back_ref[0] != newctx->gl_stencil_back_ref[0]) ||
1613 (oldctx->gl_stencil_back_value_mask[0] != newctx->gl_stencil_back_value_mask[0]))
1615 CHECK_GL_ERROR(_orig_fastpath_glStencilFuncSeparate(GL_BACK,
1616 newctx->gl_stencil_back_func[0],
1617 newctx->gl_stencil_back_ref[0],
1618 newctx->gl_stencil_back_value_mask[0]))
1620 if ((oldctx->gl_stencil_back_fail[0] != newctx->gl_stencil_back_fail[0]) ||
1621 (oldctx->gl_stencil_back_pass_depth_fail[0] != newctx->gl_stencil_back_pass_depth_fail[0]) ||
1622 (oldctx->gl_stencil_back_pass_depth_pass[0] != newctx->gl_stencil_back_pass_depth_pass[0]))
1624 CHECK_GL_ERROR(_orig_fastpath_glStencilOpSeparate(GL_BACK,
1625 newctx->gl_stencil_back_fail[0],
1626 newctx->gl_stencil_back_pass_depth_fail[0],
1627 newctx->gl_stencil_back_pass_depth_pass[0]))
1630 STATE_COMPARE(gl_stencil_back_writemask[0])
1632 CHECK_GL_ERROR(_orig_fastpath_glStencilMaskSeparate(GL_BACK, newctx->gl_stencil_back_writemask[0]))
1634 STATE_COMPARE(gl_stencil_clear_value[0])
1636 CHECK_GL_ERROR(_orig_fastpath_glClearStencil(newctx->gl_stencil_clear_value[0]))
1640 //------------------//
1642 flag = oldctx->_misc_flag1 | newctx->_misc_flag1;
1645 STATE_COMPARE(gl_front_face[0])
1647 CHECK_GL_ERROR(_orig_fastpath_glFrontFace(newctx->gl_front_face[0]))
1649 STATE_COMPARE(gl_line_width[0])
1651 CHECK_GL_ERROR(_orig_fastpath_glLineWidth(newctx->gl_line_width[0]))
1653 if ((oldctx->gl_polygon_offset_factor[0] != newctx->gl_polygon_offset_factor[0]) ||
1654 (oldctx->gl_polygon_offset_units[0] != newctx->gl_polygon_offset_units[0]))
1656 CHECK_GL_ERROR(_orig_fastpath_glPolygonOffset(newctx->gl_polygon_offset_factor[0],
1657 newctx->gl_polygon_offset_units[0]))
1659 if ((oldctx->gl_sample_coverage_value[0] != newctx->gl_sample_coverage_value[0]) ||
1660 (oldctx->gl_sample_coverage_invert[0] != newctx->gl_sample_coverage_invert[0]))
1662 CHECK_GL_ERROR(_orig_fastpath_glSampleCoverage(newctx->gl_sample_coverage_value[0],
1663 newctx->gl_sample_coverage_invert[0]))
1665 STATE_COMPARE(gl_fragment_shader_derivative_hint[0])
1667 CHECK_GL_ERROR(_orig_fastpath_glHint(GL_FRAGMENT_SHADER_DERIVATIVE_HINT_OES, newctx->gl_fragment_shader_derivative_hint[0]))
1672 flag = oldctx->_misc_flag2 | newctx->_misc_flag2;
1675 STATES_COMPARE(gl_scissor_box, 4 * sizeof(GLint))
1677 CHECK_GL_ERROR(_orig_fastpath_glScissor(newctx->gl_scissor_box[0],
1678 newctx->gl_scissor_box[1],
1679 newctx->gl_scissor_box[2],
1680 newctx->gl_scissor_box[3]))
1682 STATE_COMPARE(gl_pack_alignment[0])
1684 CHECK_GL_ERROR(_orig_fastpath_glPixelStorei(GL_PACK_ALIGNMENT, newctx->gl_pack_alignment[0]))
1686 STATE_COMPARE(gl_unpack_alignment[0])
1688 CHECK_GL_ERROR(_orig_fastpath_glPixelStorei(GL_UNPACK_ALIGNMENT, newctx->gl_unpack_alignment[0]))
1691 #ifdef COREGL_USE_MODULE_TRACEPATH
1692 tracepath_api_trace_end("eglMakeCurrent(FP etc.)", trace_hint_etc, 0);
1693 #endif // COREGL_USE_MODULE_TRACEPATH
1696 #ifdef COREGL_USE_MODULE_TRACEPATH
1697 static void *trace_hint_vertex_attrib = NULL;
1698 trace_hint_vertex_attrib = tracepath_api_trace_begin("eglMakeCurrent(FP vertex attrib)", trace_hint_vertex_attrib, 0);
1699 #endif // COREGL_USE_MODULE_TRACEPATH
1701 flag = oldctx->_vattrib_flag | newctx->_vattrib_flag;
1704 for (i = 0; i < oldctx->gl_num_vertex_attribs[0]; i++)
1706 if (newctx->gl_vertex_array_buf_id[i] != oldctx->gl_vertex_array_buf_id[i])
1708 CHECK_GL_ERROR(_orig_fastpath_glBindBuffer(GL_ARRAY_BUFFER, newctx->gl_vertex_array_buf_id[i]))
1712 CHECK_GL_ERROR(_orig_fastpath_glBindBuffer(GL_ARRAY_BUFFER, 0))
1715 CHECK_GL_ERROR(_orig_fastpath_glVertexAttribPointer(i,
1716 newctx->gl_vertex_array_size[i],
1717 newctx->gl_vertex_array_type[i],
1718 newctx->gl_vertex_array_normalized[i],
1719 newctx->gl_vertex_array_stride[i],
1720 newctx->gl_vertex_array_pointer[i]))
1722 STATES_COMPARE(gl_vertex_attrib_value + 4 * i, 4 * sizeof(GLfloat))
1724 CHECK_GL_ERROR(_orig_fastpath_glVertexAttrib4fv(i, &newctx->gl_vertex_attrib_value[4 * i]))
1727 if (newctx->gl_vertex_array_enabled[i] == GL_TRUE)
1729 CHECK_GL_ERROR(_orig_fastpath_glEnableVertexAttribArray(i))
1733 CHECK_GL_ERROR(_orig_fastpath_glDisableVertexAttribArray(i))
1737 STATE_COMPARE(gl_array_buffer_binding[0])
1739 CHECK_GL_ERROR(_orig_fastpath_glBindBuffer(GL_ARRAY_BUFFER, newctx->gl_array_buffer_binding[0]))
1741 STATE_COMPARE(gl_element_array_buffer_binding[0])
1743 CHECK_GL_ERROR(_orig_fastpath_glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, newctx->gl_element_array_buffer_binding[0]))
1748 #ifdef COREGL_USE_MODULE_TRACEPATH
1749 tracepath_api_trace_end("eglMakeCurrent(FP vertex attrib)", trace_hint_vertex_attrib, 0);
1750 #endif // COREGL_USE_MODULE_TRACEPATH
1757 #ifdef COREGL_FASTPATH_TRACE_STATE_INFO
1758 if (unlikely(trace_state_flag == 1))
1759 fastpath_dump_context_states(newctx, 0);
1760 #endif // COREGL_FASTPATH_TRACE_STATE_INFO
1762 #undef STATE_COMPARE
1763 #undef STATES_COMPARE