1 #include "coregl_fastpath.h"
7 #ifdef COREGL_TRACE_CONTEXT_INFO
9 General_Trace_List *glue_ctx_trace_list = NULL;
10 General_Trace_List *context_state_trace_list = NULL;
13 _dump_context_info(const char *ment, int force_output)
15 GLThreadState *tstate = NULL;
16 static struct timeval tv_last = { 0, 0 };
18 if (trace_ctx_flag != 1) return;
20 AST(mutex_lock(&ctx_list_access_mutex) == 1);
21 AST(mutex_lock(&general_trace_lists_access_mutex) == 1);
23 if (!force_output && !trace_ctx_force_flag)
25 struct timeval tv_now = { 0, 0 };
26 AST(gettimeofday(&tv_now, NULL) == 0);
27 if (tv_now.tv_sec - tv_last.tv_sec < _COREGL_TRACE_OUTPUT_INTERVAL_SEC)
34 tstate = get_current_thread_state();
37 LOG("\E[40;34m========================================================================================================================\E[0m\n");
38 LOG("\E[40;32;1m Context info \E[1;37;1m: %s\E[0m\n", ment);
39 LOG("\E[40;34m========================================================================================================================\E[0m\n");
44 General_Trace_List *current = NULL;
45 current = thread_trace_list;
47 while (current != NULL)
49 GLThreadState *cur_tstate = (GLThreadState *)current->value;
51 LOG(" %c Thread [%12d] : Surf <D=[%12p] R=[%12p]>",
52 (tstate == cur_tstate) ? '*' : ' ',
53 cur_tstate->thread_id,
54 cur_tstate->rsurf_draw,
55 cur_tstate->rsurf_read);
57 if (cur_tstate->cstate != NULL)
59 LOG(" GlueCTX=[%12p] RealCTX=[%12p]\E[0m\n",
60 cur_tstate->cstate->data,
65 LOG(" (NOT BINDED TO THREAD)\E[0m\n");
68 // Binded Context State List
70 General_Trace_List *current = NULL;
71 current = context_state_trace_list;
73 while (current != NULL)
75 GLContextState *cur_cstate = (GLContextState *)current->value;
77 if (cur_tstate->cstate == cur_cstate)
79 LOG(" -> RealCTX [%12p] : EGLDPY=[%12p] EGLCTX=[%12p] <[%2d] GlueCTXs>\E[0m\n",
83 cur_cstate->ref_count);
85 // Binded Glue Context List
87 General_Trace_List *current = NULL;
88 current = glue_ctx_trace_list;
90 while (current != NULL)
92 GLGlueContext *cur_gctx = (GLGlueContext *)current->value;
94 if (cur_gctx->cstate == cur_cstate)
96 LOG(" -%c GlueCTX [%12p] : EGLDPY=[%12p] TID=[%12d] <MC count [%10d]>",
97 (cur_cstate->data == cur_gctx) ? '>' : '-',
101 cur_gctx->used_count);
103 LOG(" <Ref [%2d]>\E[0m\n", cur_gctx->ref_count);
106 current = current->next;
111 current = current->next;
117 current = current->next;
121 LOG("\E[40;33m........................................................................................................................\E[0m\n");
123 // Not-binded Context State List
125 General_Trace_List *current = NULL;
126 current = context_state_trace_list;
128 while (current != NULL)
130 GLContextState *cur_cstate = (GLContextState *)current->value;
134 if (cur_cstate->data != NULL)
136 General_Trace_List *current_t = NULL;
137 current_t = thread_trace_list;
139 while (current_t != NULL)
141 GLThreadState *cur_tstate = (GLThreadState *)current_t->value;
143 if (cur_tstate->thread_id == ((GLGlueContext *)cur_cstate->data)->thread_id)
145 if (cur_tstate->cstate == cur_cstate)
149 current_t = current_t->next;
155 LOG(" RealCTX [%12p] : EGLDPY=[%12p] EGLCTX=[%12p] <[%2d] GlueCTXs>\E[0m\n",
159 cur_cstate->ref_count);
161 // Binded Glue Context List
163 General_Trace_List *current = NULL;
164 current = glue_ctx_trace_list;
166 while (current != NULL)
168 GLGlueContext *cur_gctx = (GLGlueContext *)current->value;
170 if (cur_gctx->cstate == cur_cstate)
172 LOG(" -%c GlueCTX [%12p] : EGLDPY=[%12p] TID=[%12d] <MC count [%10d]>",
173 (cur_cstate->data == cur_gctx) ? '>' : '-',
177 cur_gctx->used_count);
179 LOG(" <Ref [%2d]>\E[0m\n", cur_gctx->ref_count);
182 current = current->next;
187 current = current->next;
192 LOG("\E[40;33m........................................................................................................................\E[0m\n");
194 // Not-binded Glue Context List
196 General_Trace_List *current = NULL;
197 current = glue_ctx_trace_list;
199 while (current != NULL)
201 GLGlueContext *cur_gctx = (GLGlueContext *)current->value;
203 if (cur_gctx->cstate == NULL)
205 LOG(" GlueCTX [%12p] : EGLDPY=[%12p] TID=[%12d] <MC count [%10d]>",
209 cur_gctx->used_count);
211 LOG(" <Ref [%2d]>\E[0m\n", cur_gctx->ref_count);
214 current = current->next;
218 LOG("\E[40;34m========================================================================================================================\E[0m\n");
225 AST(mutex_unlock(&general_trace_lists_access_mutex) == 1);
226 AST(mutex_unlock(&ctx_list_access_mutex) == 1);
230 #endif // COREGL_TRACE_CONTEXT_INFO
235 EGLint context_client_version;
236 } EGL_packed_attrib_list;
242 EGL_packed_attrib_list attrib_list;
248 EGLContext share_context;
249 } EGL_packed_sharable_option;
253 _pack_egl_context_option(EGL_packed_option *pack_data, EGLDisplay dpy, EGLConfig cfg, EGLint debug, const EGLint *attrib_list)
257 pack_data->dpy = dpy;
258 pack_data->cfg = cfg;
259 pack_data->debug = debug;
261 // Default context attributes
262 pack_data->attrib_list.context_client_version = EGL_DONT_CARE;
264 // Apply specified attributes
265 EGLint *attrib = (EGLint *)attrib_list;
266 while(attrib[0] != EGL_NONE)
270 case EGL_CONTEXT_CLIENT_VERSION:
271 pack_data->attrib_list.context_client_version = attrib[1];
274 ERR("Invalid context attribute.\n");
287 _unpack_egl_context_option(EGL_packed_option *pack_data, EGLDisplay *dpy, EGLConfig *cfg, EGLint *debug, EGLint *attrib_list, const int attrib_list_size)
291 if (dpy != NULL) *dpy = pack_data->dpy;
292 if (cfg != NULL) *cfg = pack_data->cfg;
293 if (debug != NULL) *debug = pack_data->debug;
295 if (attrib_list != NULL && attrib_list_size > 0)
297 int attrib_list_index = 0;
299 memset(attrib_list, 0x00, sizeof(int) * attrib_list_size);
301 if (pack_data->attrib_list.context_client_version != EGL_DONT_CARE)
303 AST(attrib_list_index + 2 < attrib_list_size);
304 attrib_list[attrib_list_index] = EGL_CONTEXT_CLIENT_VERSION;
305 attrib_list[attrib_list_index + 1] = pack_data->attrib_list.context_client_version;
306 attrib_list_index += 2;
309 attrib_list[attrib_list_index] = EGL_NONE;
319 _pack_egl_context_sharable_option(EGL_packed_sharable_option *pack_data, EGLContext share_context)
323 pack_data->share_context = share_context;
334 _unpack_egl_context_sharable_option(EGL_packed_sharable_option *pack_data, EGLContext *share_context)
338 if (share_context != NULL) *share_context = pack_data->share_context;
349 _link_context_state(GLGlueContext *gctx, GLContextState *cstate)
351 AST(gctx->cstate == NULL);
353 gctx->cstate = cstate;
357 _unlink_context_state(GLGlueContext *gctx, Mutex *ctx_list_mtx)
359 GLContextState *cstate = NULL;
361 cstate = gctx->cstate;
365 AST(cstate->ref_count >= 0);
367 if (cstate->ref_count == 0)
369 GLThreadState *tstate = NULL;
371 AST(cstate->data == NULL || cstate->data == initial_ctx);
373 #ifdef COREGL_TRACE_CONTEXT_INFO
374 remove_from_general_trace_list(&context_state_trace_list, cstate);
375 #endif // COREGL_TRACE_CONTEXT_INFO
377 AST(remove_context_states_from_list(cstate, ctx_list_mtx) == 1);
379 tstate = get_current_thread_state();
382 if (tstate->cstate == cstate)
384 _sym_eglMakeCurrent(cstate->rdpy, tstate->rsurf_draw, tstate->rsurf_read, EGL_NO_CONTEXT);
385 tstate->cstate = NULL;
388 _sym_eglDestroyContext(cstate->rdpy, cstate->rctx);
395 _add_shared_obj_state_ref(GL_Shared_Object_State *sostate)
397 AST(sostate->ref_count >= 0);
398 sostate->ref_count++;
402 _remove_shared_obj_state_ref(GL_Shared_Object_State *sostate)
404 AST(sostate->ref_count > 0);
405 sostate->ref_count--;
406 if (sostate->ref_count == 0)
413 _add_context_ref(GLGlueContext *gctx)
415 if (gctx == initial_ctx) return;
417 AST(gctx->ref_count >= 0);
422 _remove_context_ref(GLGlueContext *gctx, Mutex *ctx_list_mtx)
424 if (gctx == initial_ctx) return;
426 AST(gctx->ref_count > 0);
428 if (gctx->ref_count == 0)
430 #ifdef COREGL_TRACE_CONTEXT_INFO
431 remove_from_general_trace_list(&glue_ctx_trace_list, gctx);
432 #endif // COREGL_TRACE_CONTEXT_INFO
434 _unlink_context_state(gctx, ctx_list_mtx);
436 AST(gctx->sostate != NULL);
437 _remove_shared_obj_state_ref(gctx->sostate);
438 gctx->sostate = NULL;
440 if (gctx->real_ctx_option != NULL)
442 free(gctx->real_ctx_option);
443 gctx->real_ctx_option = NULL;
445 if (gctx->real_ctx_sharable_option != NULL)
447 free(gctx->real_ctx_sharable_option);
448 gctx->real_ctx_sharable_option = NULL;
455 _bind_context_state(GLGlueContext *gctx, GLContextState *cstate, Mutex *ctx_list_mtx)
459 AST(gctx->cstate == cstate);
462 if (cstate->data != gctx)
464 GLGlueContext *curctx = (GLGlueContext *)cstate->data;
465 GLGlueContext *newctx = gctx;
468 newctx = initial_ctx;
471 curctx = initial_ctx;
476 make_context_current(curctx, newctx);
477 cstate->data = (void *)newctx;
478 _remove_context_ref(curctx, ctx_list_mtx);
479 _add_context_ref(newctx);
485 _egl_create_context(EGL_packed_option *real_ctx_option, GLContextState **cstate_new, EGLContext *ctx,
486 EGLDisplay dpy, EGLConfig config, const EGLint* attrib_list)
488 GLContextState *cstate = NULL;
490 AST(real_ctx_option != NULL);
491 AST(cstate_new != NULL);
494 // Pack context option
495 AST(_pack_egl_context_option(real_ctx_option, dpy, config, 0, attrib_list) == 1);
499 static int debug_force_real = 100001;
500 AST(_pack_egl_context_option(real_ctx_option, dpy, config, debug_force_real, attrib_list) == 1);
504 // Find context state
505 cstate = get_context_state_from_list(real_ctx_option, sizeof(EGL_packed_option), &ctx_list_access_mutex);
507 // Create a real context if it hasn't been created
510 EGLContext *real_share_context = EGL_NO_CONTEXT;
512 AST(mutex_lock(&ctx_list_access_mutex) == 1);
514 GLContext_List *current = NULL;
516 current = glctx_list;
517 while (current != NULL)
519 EGLDisplay cur_dpy = EGL_NO_DISPLAY;
520 AST(_unpack_egl_context_option(current->option, &cur_dpy, NULL, NULL, NULL, 0) == 1);
523 AST(current->cstate != NULL);
524 real_share_context = current->cstate->rctx;
527 current = current->next;
530 AST(mutex_unlock(&ctx_list_access_mutex) == 1);
532 *ctx = _sym_eglCreateContext(dpy, config, real_share_context, attrib_list);
534 if (*ctx == EGL_NO_CONTEXT)
536 ERR("Failed creating a egl real context for Fastpath.\n");
540 *cstate_new = (GLContextState *)calloc(1, sizeof(GLContextState));
541 if (*cstate_new == NULL)
543 ERR("Error creating a new context state.\n");
546 (*cstate_new)->rctx = *ctx;
547 (*cstate_new)->rdpy = dpy;
548 (*cstate_new)->data = NULL;
550 AST(add_context_state_to_list(real_ctx_option, sizeof(EGL_packed_option), *cstate_new, &ctx_list_access_mutex) == 1);
552 #ifdef COREGL_TRACE_CONTEXT_INFO
553 add_to_general_trace_list(&context_state_trace_list, *cstate_new);
554 #endif // COREGL_TRACE_CONTEXT_INFO
556 cstate = *cstate_new;
569 //----------------------------------------------------------------//
570 // Fastpath EGL Functions //
571 // The functions have prefix 'fpgl_' for (fastpath gl) //
572 //----------------------------------------------------------------//
574 extern EGLBoolean (*_COREGL_NAME_MANGLE(eglBindAPI))(EGLenum api);
575 extern EGLenum (*_COREGL_NAME_MANGLE(eglQueryAPI))(void);
578 fpgl_eglBindAPI(EGLenum api)
580 EGLBoolean ret = EGL_FALSE;
581 GLThreadState *tstate = NULL;
583 _COREGL_FAST_FUNC_BEGIN();
584 if (api_opt == COREGL_UNKNOWN_PATH) goto finish;
586 ret = _sym_eglBindAPI(api);
588 tstate = get_current_thread_state();
591 AST(init_new_thread_state() == 1);
593 tstate = get_current_thread_state();
598 EGLenum newapi = _sym_eglQueryAPI();
599 if (tstate->binded_api != newapi)
601 if (newapi != EGL_OPENGL_ES_API)
603 // Fallback when binding other API
604 // Fastpath restores when bind OPENGL_ES_API
605 override_glue_normal_path();
606 _COREGL_NAME_MANGLE(eglBindAPI) = fpgl_eglBindAPI;
607 _COREGL_NAME_MANGLE(eglQueryAPI) = fpgl_eglQueryAPI;
611 override_glue_fast_path();
613 tstate->binded_api = newapi;
620 _COREGL_FAST_FUNC_END();
625 fpgl_eglQueryAPI(void)
628 GLThreadState *tstate = NULL;
630 _COREGL_FAST_FUNC_BEGIN();
631 if (api_opt == COREGL_UNKNOWN_PATH) goto finish;
633 ret = _sym_eglQueryAPI();
635 tstate = get_current_thread_state();
638 AST(tstate->binded_api == ret);
644 _COREGL_FAST_FUNC_END();
649 fpgl_eglCreateContext(EGLDisplay dpy, EGLConfig config, EGLContext share_context, const EGLint* attrib_list)
651 GLGlueContext *gctx = NULL;
652 GLContextState *cstate = NULL;
653 GLContextState *cstate_new = NULL;
654 GL_Shared_Object_State *sostate_new = NULL;
655 GLContext ctx = NULL;
657 EGL_packed_option *real_ctx_option = NULL;
658 EGL_packed_sharable_option *real_ctx_sharable_option = NULL;
660 _COREGL_FAST_FUNC_BEGIN();
662 real_ctx_option = (EGL_packed_option *)calloc(1, sizeof(EGL_packed_option));
663 if (real_ctx_option == NULL)
665 ERR("Error creating a new GLGlueContext(1)\n");
668 cstate = _egl_create_context(real_ctx_option, &cstate_new, &ctx, dpy, config, attrib_list);
671 // Pack shared context options
672 real_ctx_sharable_option = (EGL_packed_sharable_option *)calloc(1, sizeof(EGL_packed_sharable_option));
673 if (real_ctx_sharable_option == NULL)
675 ERR("Error creating a new GLGlueContext(2)\n");
678 AST(_pack_egl_context_sharable_option(real_ctx_sharable_option, share_context) == 1);
680 // Allocate a new context
681 gctx = (GLGlueContext *)calloc(1, sizeof(GLGlueContext));
684 ERR("Error creating a new GLGlueContext(3)\n");
688 gctx->magic = MAGIC_GLFAST;
689 gctx->initialized = 0;
691 gctx->thread_id = get_current_thread();
693 if (share_context != EGL_NO_CONTEXT)
695 GLGlueContext *shared_gctx = (GLGlueContext *)share_context;
696 AST(shared_gctx->magic == MAGIC_GLFAST);
697 AST(shared_gctx->sostate != NULL);
698 gctx->sostate = shared_gctx->sostate;
702 sostate_new = (GL_Shared_Object_State *)calloc(1, sizeof(GL_Shared_Object_State));
703 if (sostate_new == NULL)
705 ERR("Error creating a new GLGlueContext(4)\n");
708 gctx->sostate = sostate_new;
710 _add_shared_obj_state_ref(gctx->sostate);
711 gctx->real_ctx_option = real_ctx_option;
712 gctx->real_ctx_option_len = sizeof(EGL_packed_option);
713 gctx->real_ctx_sharable_option = real_ctx_sharable_option;
714 gctx->real_ctx_sharable_option_len = sizeof(EGL_packed_sharable_option);
716 _link_context_state(gctx, cstate);
717 _add_context_ref(gctx);
719 gctx->cstate = cstate;
721 #ifdef COREGL_TRACE_CONTEXT_INFO
722 add_to_general_trace_list(&glue_ctx_trace_list, gctx);
726 sprintf(ment, "eglCreateContext completed (GlueCTX=[%12p])", gctx);
727 _dump_context_info(ment, 1);
729 #endif // COREGL_TRACE_CONTEXT_INFO
738 _sym_eglDestroyContext(dpy, ctx);
741 if (sostate_new != NULL)
746 if (real_ctx_option != NULL)
748 free(real_ctx_option);
749 real_ctx_option = NULL;
751 if (real_ctx_sharable_option != NULL)
753 free(real_ctx_sharable_option);
754 real_ctx_sharable_option = NULL;
756 if (cstate_new != NULL)
758 #ifdef COREGL_TRACE_CONTEXT_INFO
759 remove_from_general_trace_list(&context_state_trace_list, cstate_new);
760 #endif // COREGL_TRACE_CONTEXT_INFO
762 remove_context_states_from_list(cstate_new, &ctx_list_access_mutex);
768 _COREGL_FAST_FUNC_END();
769 return (EGLContext)gctx;
773 fpgl_eglDestroyContext(EGLDisplay dpy, EGLContext ctx)
775 EGLBoolean ret = EGL_FALSE;
776 GLGlueContext *gctx = NULL;
778 _COREGL_FAST_FUNC_BEGIN();
780 gctx = (GLGlueContext *)ctx;
784 GLContextState *cstate = NULL;
785 if (gctx->magic != MAGIC_GLFAST)
787 ERR("Magic Check Failed!!!\n");
791 cstate = gctx->cstate;
794 if (gctx->is_destroyed == 1)
796 ERR("\E[40;31;1mWARNING : Context [%p] is already destroyed!!!\E[0m\n", ctx);
800 gctx->is_destroyed = 1;
801 _remove_context_ref(gctx, &ctx_list_access_mutex);
806 ERR("Invalid Context.\n");
815 _COREGL_FAST_FUNC_END();
817 #ifdef COREGL_TRACE_CONTEXT_INFO
820 sprintf(ment, "eglDestroyContext completed (GlueCTX=[%12p])", ctx);
821 _dump_context_info(ment, 1);
823 #endif // COREGL_TRACE_CONTEXT_INFO
829 fpgl_eglQueryContext(EGLDisplay dpy, EGLContext ctx, EGLint attribute, EGLint *value)
831 EGLBoolean ret = EGL_FALSE;
832 EGLContext real_ctx = EGL_NO_CONTEXT;
834 _COREGL_FAST_FUNC_BEGIN();
836 if (ctx != EGL_NO_CONTEXT)
838 GLGlueContext *gctx = NULL;
839 gctx = (GLGlueContext *)ctx;
841 AST(gctx->cstate != NULL);
842 real_ctx = gctx->cstate->rctx;
845 _COREGL_FAST_FUNC_SYMCALL_BEGIN();
846 ret = _sym_eglQueryContext(dpy, real_ctx, attribute, value);
847 _COREGL_FAST_FUNC_SYMCALL_END();
851 _COREGL_FAST_FUNC_END();
858 fpgl_eglReleaseThread(void)
860 EGLBoolean ret = EGL_FALSE;
861 EGLDisplay dpy = EGL_NO_DISPLAY;
863 _COREGL_FAST_FUNC_BEGIN();
865 dpy = _sym_eglGetCurrentDisplay();
866 AST(dpy != EGL_NO_DISPLAY);
867 fpgl_eglMakeCurrent(dpy, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
868 ret = _sym_eglReleaseThread();
872 _COREGL_FAST_FUNC_END();
879 fpgl_eglMakeCurrent(EGLDisplay dpy, EGLSurface draw, EGLSurface read, EGLContext ctx)
881 EGLBoolean ret = EGL_FALSE;
882 EGLBoolean need_mc = EGL_FALSE;
883 GLGlueContext *gctx = NULL;
885 GLThreadState *tstate = NULL;
886 GLContextState *cstate = NULL;
888 _COREGL_FAST_FUNC_BEGIN();
890 gctx = (GLGlueContext *)ctx;
892 tstate = get_current_thread_state();
895 AST(init_new_thread_state() == 1);
897 tstate = get_current_thread_state();
901 // Special path for context deletion
902 if (ctx == EGL_NO_CONTEXT)
906 if (tstate->cstate != NULL)
908 _bind_context_state(NULL, tstate->cstate, &ctx_list_access_mutex);
909 tstate->cstate = NULL;
911 if (_sym_eglMakeCurrent(dpy, draw, read, ctx) != EGL_TRUE)
913 ERR("WARNING : Error making context [%p] current. (invalid EGL display [%p] or EGL surface [D:%p/R:%p])\n", ctx, dpy, draw, read);
918 tstate->rsurf_draw = draw;
919 tstate->rsurf_read = read;
926 AST(gctx->cstate != NULL);
928 if (gctx->rdpy != dpy)
930 ERR("Invalid context (or invalid EGL display)\n");
935 AST(gctx->real_ctx_option != NULL);
936 AST(gctx->real_ctx_sharable_option != NULL);
938 // Handle cross threading of context (when used by two or more gctx)
939 if (gctx->thread_id != get_current_thread() && gctx->cstate->ref_count > 1)
941 #define ATTRIB_LIST_BUFFER_SIZE 8
943 GLContextState *cstate_new = NULL;
944 EGLContext new_real_ctx = EGL_NO_CONTEXT;
946 EGLDisplay dpy = EGL_NO_DISPLAY;
947 EGLConfig config = NULL;
948 int attrib_list[ATTRIB_LIST_BUFFER_SIZE];
950 AST(_unpack_egl_context_option(gctx->real_ctx_option, &dpy, &config, NULL, attrib_list, ATTRIB_LIST_BUFFER_SIZE) == 1);
951 AST(dpy == gctx->rdpy);
953 _egl_create_context(gctx->real_ctx_option, &cstate_new, &new_real_ctx, dpy, config, attrib_list);
955 AST(cstate_new != NULL);
957 _bind_context_state(gctx, cstate_new, &ctx_list_access_mutex);
959 // TODO : Setup context state for new real ctx
960 ERR("\E[40;31;1mWARNING : Cross-thread usage(makecurrent) can cause a state-broken situation!\E[0m\n");
962 _unlink_context_state(gctx, &ctx_list_access_mutex);
963 _link_context_state(gctx, cstate_new);
965 // Apply to new thread
966 gctx->thread_id = get_current_thread();
970 // Check if the object is correct
971 if (gctx->magic != MAGIC_GLFAST)
973 ERR("Glue-CTX Magic Check Failed!!!\n");
979 cstate = tstate->cstate;
981 // If it's a first time or drawable changed, do a make current
984 cstate = get_context_state_from_list(gctx->real_ctx_option, gctx->real_ctx_option_len, &ctx_list_access_mutex);
988 ERR("Error making context current because context not ready.\n");
995 // If drawable changed, do a make current
996 if ((tstate->rsurf_draw != draw) ||
997 (tstate->rsurf_read != read))
1000 AST(gctx->cstate != NULL);
1002 // If binded real context changed, do a make current
1003 if (gctx->cstate->rctx != cstate->rctx)
1006 if (need_mc == EGL_TRUE)
1008 // BB : full makecurrent
1009 if (_sym_eglMakeCurrent(dpy, draw, read, gctx->cstate->rctx) != EGL_TRUE)
1011 ERR("Error making context current with the drawable.\n");
1016 tstate->cstate = gctx->cstate;
1018 tstate->rsurf_draw = draw;
1019 tstate->rsurf_read = read;
1022 // Initialize context states
1023 if (gctx->initialized == 0)
1025 if (init_context_states(gctx) != 1)
1027 ERR("Error intializing context\n");
1032 // Setup initial Viewport & Scissor
1033 if (gctx->surface_attached == 0 && draw != EGL_NO_SURFACE)
1037 _sym_eglQuerySurface(dpy, draw, EGL_WIDTH, &width);
1038 _sym_eglQuerySurface(dpy, draw, EGL_HEIGHT, &height);
1040 gctx->_clear_flag1 |= FLAG_BIT_0;
1041 gctx->gl_viewport[0] = 0;
1042 gctx->gl_viewport[1] = 0;
1043 gctx->gl_viewport[2] = width;
1044 gctx->gl_viewport[3] = height;
1046 gctx->_misc_flag2 |= FLAG_BIT_0;
1047 gctx->gl_scissor_box[0] = 0;
1048 gctx->gl_scissor_box[1] = 0;
1049 gctx->gl_scissor_box[2] = width;
1050 gctx->gl_scissor_box[3] = height;
1052 gctx->surface_attached = 1;
1055 _bind_context_state(gctx, tstate->cstate, &ctx_list_access_mutex);
1063 _COREGL_FAST_FUNC_END();
1065 #ifdef COREGL_TRACE_CONTEXT_INFO
1068 sprintf(ment, "eglMakeCurrent finished (GlueCTX=[%12p] Surf=[D:%12p R:%12p])", ctx, draw, read);
1069 _dump_context_info(ment, 0);
1071 #endif // COREGL_TRACE_CONTEXT_INFO
1078 fpgl_eglGetCurrentContext(void)
1080 GLGlueContext *ret = NULL;
1081 GLThreadState *tstate = NULL;
1083 _COREGL_FAST_FUNC_BEGIN();
1085 tstate = get_current_thread_state();
1089 if (tstate->cstate != NULL)
1091 ret = (GLGlueContext *)tstate->cstate->data;
1097 _COREGL_FAST_FUNC_END();
1098 return (EGLContext)ret;
1103 fpgl_eglGetCurrentSurface(EGLint readdraw)
1105 EGLSurface ret = EGL_NO_SURFACE;
1106 GLThreadState *tstate = NULL;
1108 _COREGL_FAST_FUNC_BEGIN();
1110 tstate = get_current_thread_state();
1117 ret = (GLGlueContext *)tstate->rsurf_draw;
1120 ret = (GLGlueContext *)tstate->rsurf_read;
1127 _COREGL_FAST_FUNC_END();
1132 fpgl_eglCreateImageKHR (EGLDisplay dpy, EGLContext ctx, EGLenum target, EGLClientBuffer buffer, const EGLint *attrib_list)
1135 EGLContext real_ctx = EGL_NO_CONTEXT;
1137 _COREGL_FAST_FUNC_BEGIN();
1139 if (ctx != NULL && ctx != EGL_NO_CONTEXT)
1141 GLGlueContext *gctx = (GLGlueContext *)ctx;
1143 if (gctx->magic != MAGIC_GLFAST)
1149 AST(gctx->cstate != NULL);
1150 real_ctx = gctx->cstate->rctx;
1153 ret = _sym_eglCreateImageKHR(dpy, real_ctx, target, buffer, attrib_list);
1158 _COREGL_FAST_FUNC_END();
1163 fpgl_eglGetProcAddress(const char* procname)
1167 _COREGL_FAST_FUNC_BEGIN();
1169 #define _COREGL_SYMBOL(IS_EXTENSION, RET_TYPE, FUNC_NAME, PARAM_LIST) \
1170 if (strcmp(procname, #FUNC_NAME) == 0) \
1172 ret = (_eng_fn)FUNC_NAME; \
1175 #include "headers/sym_egl.h"
1176 #include "headers/sym_gl.h"
1177 #undef _COREGL_SYMBOL
1179 ret = _sym_eglGetProcAddress(procname);
1182 LOG("\E[40;31;1mWARNING : COREGL can't support '%s' (unmanaged situation may occur)\E[0m\n", procname);
1188 _COREGL_FAST_FUNC_END();