static int gl_lib_is_gles = 0;
static Evas_GL_API gl_funcs;
+static Eina_Bool _tls_init = EINA_FALSE;
+static Eina_TLS gl_current_ctx_key = 0;
+static Eina_TLS gl_current_sfc_key = 0;
+
//------------------------------------------------------//
// OSMesa APIS...
static OSMesaContext (*_sym_OSMesaCreateContextExt) (GLenum format, GLint depthBits, GLint stencilBits, GLint accumBits, OSMesaContext sharelist) = NULL;
return im->cache_entry.load_error;
}
+
//------------ Evas GL engine code ---------------//
+#ifdef EVAS_GL
+static inline int
+_tls_check(void)
+{
+ // note: this is not thread safe...
+ if (!_tls_init)
+ {
+ if (!eina_tls_new(&gl_current_ctx_key)) return 0;
+ if (!eina_tls_new(&gl_current_sfc_key)) return 0;
+ eina_tls_set(gl_current_ctx_key, NULL);
+ eina_tls_set(gl_current_sfc_key, NULL);
+ }
+ _tls_init = EINA_TRUE;
+ return 1;
+}
+#endif
+
static void *
eng_gl_surface_create(void *data EINA_UNUSED, void *config, int w, int h)
{
if (!sfc) return 0;
+ _tls_check();
+ if (sfc == eina_tls_get(gl_current_sfc_key))
+ eina_tls_set(gl_current_sfc_key, NULL);
+
if (sfc->buffer) free(sfc->buffer);
free(sfc);
if (!ctx) return 0;
+ _tls_check();
+ if (ctx == eina_tls_get(gl_current_ctx_key))
+ eina_tls_set(gl_current_ctx_key, NULL);
+
_sym_OSMesaDestroyContext(ctx->context);
free(ctx);
sfc = (Render_Engine_GL_Surface*)surface;
ctx = (Render_Engine_GL_Context*)context;
+ _tls_check();
+
// Unset surface/context
if ((!sfc) || (!ctx))
{
if (ctx) ctx->current_sfc = NULL;
if (sfc) sfc->current_ctx = NULL;
+ eina_tls_set(gl_current_ctx_key, NULL);
+ eina_tls_set(gl_current_sfc_key, NULL);
return 1;
}
if (!ctx->context)
{
ERR("Error initializing context.");
+ eina_tls_set(gl_current_ctx_key, NULL);
+ eina_tls_set(gl_current_sfc_key, NULL);
return 0;
}
if (ret == GL_FALSE)
{
ERR("Error doing MakeCurrent.");
+ eina_tls_set(gl_current_ctx_key, NULL);
+ eina_tls_set(gl_current_sfc_key, NULL);
return 0;
}
// Set the current surface/context
ctx->current_sfc = sfc;
sfc->current_ctx = ctx;
+ eina_tls_set(gl_current_ctx_key, ctx);
+ eina_tls_set(gl_current_sfc_key, sfc);
return 1;
#else
return EVAS_GL_SUCCESS;
}
+static void *
+eng_gl_current_context_get(void *data EINA_UNUSED)
+{
+ _tls_check();
+ return eina_tls_get(gl_current_ctx_key);
+}
+
+static void *
+eng_gl_current_surface_get(void *data EINA_UNUSED)
+{
+ _tls_check();
+ return eina_tls_get(gl_current_sfc_key);
+}
+
//------------------------------------------------//
/* The following function require that any engine
gl_lib_init(void)
{
#ifdef EVAS_GL
+ // Current ctx & sfc stuff
+ if (!_tls_check()) return 0;
+
// dlopen OSMesa
gl_lib_handle = dlopen("libOSMesa.so.9", RTLD_NOW);
if (!gl_lib_handle) gl_lib_handle = dlopen("libOSMesa.so.8", RTLD_NOW);
ORD(gl_native_surface_get);
ORD(gl_api_get);
ORD(gl_error_get);
- //ORD(gl_current_context_get);
- //ORD(gl_current_surface_get);
+ ORD(gl_current_context_get);
+ ORD(gl_current_surface_get);
#undef ORD
}
}