Abstract selector of translator or host GL libs a bit more

This commit is contained in:
Simon Fels 2017-01-20 18:05:40 +01:00
commit 30c2186826
13 changed files with 130 additions and 57 deletions

View file

@ -42,12 +42,13 @@ LIST_RENDER_EGL_EXTENSIONS_FUNCTIONS(RENDER_EGL_DEFINE_TYPE)
// Define EGLDispatch structure.
struct EGLDispatch {
bool initialized = false;
LIST_RENDER_EGL_FUNCTIONS(RENDER_EGL_DECLARE_MEMBER)
LIST_RENDER_EGL_EXTENSIONS_FUNCTIONS(RENDER_EGL_DECLARE_MEMBER)
};
// Initialize EGLDispatch function. Return true on success, false on failure.
bool init_egl_dispatch();
bool init_egl_dispatch(const char *path);
// Global EGLDispatch instance. Call init_egl_dispatch() before using it.
extern EGLDispatch s_egl;

View file

@ -26,6 +26,7 @@
LIST_GLES1_FUNCTIONS(GLES1_DISPATCH_DEFINE_TYPE,GLES1_DISPATCH_DEFINE_TYPE)
struct GLESv1Dispatch {
bool initialized = false;
#define GLES1_DISPATCH_DECLARE_POINTER(return_type,func_name,signature,callargs) \
func_name ## _t func_name;
LIST_GLES1_FUNCTIONS(GLES1_DISPATCH_DECLARE_POINTER,
@ -35,7 +36,7 @@ struct GLESv1Dispatch {
#undef GLES1_DISPATCH_DECLARE_POINTER
#undef GLES1_DISPATCH_DEFINE_TYPE
bool gles1_dispatch_init(GLESv1Dispatch* dispatch_table);
bool gles1_dispatch_init(const char *path, GLESv1Dispatch* dispatch_table);
// Used to initialize the decoder.
void* gles1_dispatch_get_proc_func(const char* name, void* userData);

View file

@ -26,6 +26,7 @@
LIST_GLES2_FUNCTIONS(GLES2_DISPATCH_DEFINE_TYPE,GLES2_DISPATCH_DEFINE_TYPE)
struct GLESv2Dispatch {
bool initialized = false;
#define GLES2_DISPATCH_DECLARE_POINTER(return_type,func_name,signature,callargs) \
func_name ## _t func_name;
LIST_GLES2_FUNCTIONS(GLES2_DISPATCH_DECLARE_POINTER,
@ -35,7 +36,7 @@ struct GLESv2Dispatch {
#undef GLES2_DISPATCH_DECLARE_POINTER
#undef GLES2_DISPATCH_DEFINE_TYPE
bool gles2_dispatch_init(GLESv2Dispatch* dispatch_table);
bool gles2_dispatch_init(const char *path, GLESv2Dispatch* dispatch_table);
// Used to initialize the decoder.
void* gles2_dispatch_get_proc_func(const char* name, void* userData);

View file

@ -20,9 +20,11 @@
#include <stdio.h>
#include <stdlib.h>
EGLDispatch s_egl;
namespace {
constexpr const char *egl_lib_env_var{"ANBOX_EGL_LIB"};
}
#define DEFAULT_EGL_LIB EMUGL_LIBNAME("EGL_translator")
EGLDispatch s_egl;
#define RENDER_EGL_LOAD_FIELD(return_type, function_name, signature) \
s_egl. function_name = (function_name ## _t) lib->findSymbol(#function_name);
@ -33,20 +35,24 @@ EGLDispatch s_egl;
if (!s_egl.function_name || !s_egl.eglGetProcAddress) \
RENDER_EGL_LOAD_FIELD(return_type, function_name, signature)
bool init_egl_dispatch()
{
const char *libName = getenv("ANDROID_EGL_LIB");
if (!libName) libName = DEFAULT_EGL_LIB;
bool init_egl_dispatch(const char *path) {
const char *libName = getenv(egl_lib_env_var);
if (!libName)
libName = path;
if (!libName)
return false;
char error[256];
emugl::SharedLibrary *lib = emugl::SharedLibrary::open(libName, error, sizeof(error));
if (!lib) {
printf("Failed to open %s: [%s]\n", libName, error);
return NULL;
return false;
}
LIST_RENDER_EGL_FUNCTIONS(RENDER_EGL_LOAD_FIELD)
LIST_RENDER_EGL_EXTENSIONS_FUNCTIONS(RENDER_EGL_LOAD_OPTIONAL_FIELD)
s_egl.initialized = true;
return true;
}

View file

@ -38,13 +38,16 @@ static void gles1_unimplemented() {
// any thread has been created - hence it should NOT be thread safe.
//
#define DEFAULT_GLES_CM_LIB EMUGL_LIBNAME("GLES_CM_translator")
namespace {
constexpr const char *glesv1_lib_env_var{"ANBOX_GLESv1_LIB"};
}
bool gles1_dispatch_init(GLESv1Dispatch* dispatch_table) {
const char* libName = getenv("ANDROID_GLESv1_LIB");
if (!libName) {
libName = DEFAULT_GLES_CM_LIB;
}
bool gles1_dispatch_init(const char *path, GLESv1Dispatch* dispatch_table) {
const char* libName = getenv(glesv1_lib_env_var);
if (!libName)
libName = path;
if (!libName)
return false;
char error[256];
s_gles1_lib = emugl::SharedLibrary::open(libName, error, sizeof(error));
@ -67,6 +70,8 @@ bool gles1_dispatch_init(GLESv1Dispatch* dispatch_table) {
LIST_GLES1_FUNCTIONS(LOOKUP_SYMBOL,LOOKUP_EXT_SYMBOL)
dispatch_table->initialized = true;
return true;
}

View file

@ -25,7 +25,9 @@ extern EGLDispatch s_egl;
static emugl::SharedLibrary *s_gles2_lib = NULL;
#define DEFAULT_GLES_V2_LIB EMUGL_LIBNAME("GLES_V2_translator")
namespace {
constexpr const char *glesv2_lib_env_var{"ANDROID_GLESv2_LIB"};
}
// An unimplemented function which prints out an error message.
// To make it consistent with the guest, all GLES2 functions not supported by
@ -39,12 +41,13 @@ static void gles2_unimplemented() {
// This function is called only once during initialiation before
// any thread has been created - hence it should NOT be thread safe.
//
bool gles2_dispatch_init(GLESv2Dispatch* dispatch_table)
bool gles2_dispatch_init(const char *path, GLESv2Dispatch *dispatch_table)
{
const char *libName = getenv("ANDROID_GLESv2_LIB");
if (!libName) {
libName = DEFAULT_GLES_V2_LIB;
}
const char *libName = getenv(glesv2_lib_env_var);
if (!libName)
libName = path;
if (!libName)
return false;
char error[256];
s_gles2_lib = emugl::SharedLibrary::open(libName, error, sizeof(error));
@ -67,6 +70,8 @@ bool gles2_dispatch_init(GLESv2Dispatch* dispatch_table)
LIST_GLES2_FUNCTIONS(LOOKUP_SYMBOL,LOOKUP_EXT_SYMBOL)
dispatch_table->initialized = true;
return true;
}