9 #include "coregl_internal.h"
10 #include "coregl_export.h"
15 #ifndef _COREGL_VENDOR_EGL_LIB_PATH
16 #define _COREGL_VENDOR_EGL_LIB_PATH "/usr/lib/driver/libEGL.so" /* DEFAULT EGL PATH */
19 #ifndef _COREGL_VENDOR_GL_LIB_PATH
20 #define _COREGL_VENDOR_GL_LIB_PATH "/usr/lib/driver/libGLESv2.so" /* DEFAULT GL PATH */
23 // Symbol definition for real
24 #define _COREGL_SYMBOL(IS_EXTENSION, RET_TYPE, FUNC_NAME, PARAM_LIST) RET_TYPE (*_sym_##FUNC_NAME) PARAM_LIST;
25 #include "headers/sym.h"
29 get_env_setting(const char *name)
32 static char *fp_default = "\0";
33 fp_env = getenv(name);
34 if (fp_env == NULL) fp_env = fp_default;
39 cleanup_current_thread_state()
41 GLThreadState *tstate = NULL;
43 tstate = get_current_thread_state();
47 COREGL_LOG("[COREGL] de-init thread state \n");
48 deinit_modules_tstate(tstate);
49 remove_from_general_trace_list(&thread_trace_list, tstate);
54 set_current_thread_state(NULL);
58 init_new_thread_state()
61 GLThreadState *tstate = NULL;
63 tstate = get_current_thread_state();
66 tstate = (GLThreadState *)calloc(1, sizeof(GLThreadState));
67 tstate->thread_id = get_current_thread();
68 add_to_general_trace_list(&thread_trace_list, tstate);
70 init_modules_tstate(tstate);
71 set_current_thread_state(tstate);
83 COREGL_ERR("GL symbol missing! Check client version!\n");
86 #define FINDSYM(libhandle, getproc, dst, sym) \
87 if (!dst || (void *)dst == (void *)_sym_missing) \
88 if (getproc) dst = (__typeof__(dst))getproc(sym); \
89 if (!dst || (void *)dst == (void *)_sym_missing) \
90 dst = (__typeof__(dst))dlsym(libhandle, sym); \
91 if (!dst) dst = (__typeof__(dst))_sym_missing;
97 #define _COREGL_SYMBOL(IS_EXTENSION, RET_TYPE, FUNC_NAME, PARAM_LIST) \
98 FINDSYM(egl_lib_handle, _sym_eglGetProcAddress, _sym_##FUNC_NAME, #FUNC_NAME);
99 #define _COREGL_EXT_SYMBOL_ALIAS(FUNC_NAME, ALIAS_NAME) \
100 FINDSYM(egl_lib_handle, _sym_eglGetProcAddress, _sym_##ALIAS_NAME, #FUNC_NAME);
102 #include "headers/sym_egl.h"
104 #undef _COREGL_EXT_SYMBOL_ALIAS
105 #undef _COREGL_SYMBOL
114 #define _COREGL_SYMBOL(IS_EXTENSION, RET_TYPE, FUNC_NAME, PARAM_LIST) \
115 FINDSYM(gl_lib_handle, _sym_eglGetProcAddress, _sym_##FUNC_NAME, #FUNC_NAME);
116 #define _COREGL_EXT_SYMBOL_ALIAS(FUNC_NAME, ALIAS_NAME) \
117 FINDSYM(gl_lib_handle, _sym_eglGetProcAddress, _sym_##ALIAS_NAME, #FUNC_NAME);
119 #include "headers/sym_gl.h"
121 #undef _COREGL_EXT_SYMBOL_ALIAS
122 #undef _COREGL_SYMBOL
130 COREGL_API void coregl_symbol_exported()
132 COREGL_ERR("\E[40;31;1mInvalid library link! (Check linkage of libCOREGL)\E[0m\n");
138 //------------------------------------------------//
139 // Open EGL Library as EGL is separate
140 egl_lib_handle = dlopen(_COREGL_VENDOR_EGL_LIB_PATH, RTLD_LAZY | RTLD_LOCAL);
143 COREGL_ERR("\E[40;31;1m%s\E[0m\n\n", dlerror());
144 COREGL_ERR("\E[40;31;1mInvalid library link! (Check linkage of libCOREGL -> %s)\E[0m\n", _COREGL_VENDOR_EGL_LIB_PATH);
148 // test for invalid linking egl
149 if (dlsym(egl_lib_handle, "coregl_symbol_exported"))
151 COREGL_ERR("\E[40;31;1mInvalid library link! (Check linkage of libCOREGL -> %s)\E[0m\n", _COREGL_VENDOR_EGL_LIB_PATH);
155 // use gl_lib handle for GL symbols
156 gl_lib_handle = dlopen(_COREGL_VENDOR_GL_LIB_PATH, RTLD_LAZY | RTLD_LOCAL);
159 COREGL_ERR("\E[40;31;1m%s\E[0m\n\n", dlerror());
160 COREGL_ERR("\E[40;31;1mInvalid library link! (Check linkage of libCOREGL -> %s)\E[0m\n", _COREGL_VENDOR_GL_LIB_PATH);
164 // test for invalid linking gl
165 if (dlsym(gl_lib_handle, "coregl_symbol_exported"))
167 COREGL_ERR("\E[40;31;1mInvalid library link! (Check linkage of libCOREGL -> %s)\E[0m\n", _COREGL_VENDOR_GL_LIB_PATH);
170 //------------------------------------------------//
172 if (!_glue_sym_init()) return 0;
173 if (!_gl_sym_init()) return 0;
181 if (egl_lib_handle) dlclose(egl_lib_handle);
182 if (gl_lib_handle) dlclose(gl_lib_handle);
190 COREGL_LOG("[CoreGL] <%d> (%s) Library initializing...", getpid(), _COREGL_COMPILE_DATE);
192 if (!_gl_lib_init()) return 0;
196 COREGL_LOG(" -> Completed\n");
203 __attribute__((destructor))
207 if (export_initialized != 0)