[waffle] [PATCH v2 8/8] nacl: add implementation for waffle_dl_sym
Tapani Pälli
tapani.palli at intel.com
Mon Feb 9 05:24:49 PST 2015
v2: use wcore_calloc, code cleanup (Emil Velikov)
open dll only once in can_open (Chad Versace)
Signed-off-by: Tapani Pälli <tapani.palli at intel.com>
---
src/waffle/nacl/nacl_platform.c | 69 +++++++++++++++++++++++++++++++++++++++--
src/waffle/nacl/nacl_platform.h | 1 +
2 files changed, 68 insertions(+), 2 deletions(-)
diff --git a/src/waffle/nacl/nacl_platform.c b/src/waffle/nacl/nacl_platform.c
index c4fefe5..22169da 100644
--- a/src/waffle/nacl/nacl_platform.c
+++ b/src/waffle/nacl/nacl_platform.c
@@ -43,6 +43,11 @@ nacl_platform_destroy(struct wcore_platform *wc_self)
nacl_teardown(self->nacl);
+ if (self->gl_dl)
+ if (dlclose(self->gl_dl) != 0)
+ wcore_errorf(WAFFLE_ERROR_UNKNOWN, "dlclose failed: %s",
+ dlerror());
+
free(self);
return ok;
}
@@ -51,7 +56,41 @@ static bool
nacl_platform_dl_can_open(struct wcore_platform *wc_self,
int32_t waffle_dl)
{
- return false;
+ struct nacl_platform *self = nacl_platform(wc_self);
+
+ switch (waffle_dl) {
+ case WAFFLE_DL_OPENGL_ES2:
+ if (!self->gl_dl)
+ self->gl_dl = dlopen(NACL_GLES2_LIBRARY, RTLD_LAZY);
+ break;
+ // API not supported
+ default:
+ return false;
+ }
+
+ if (!self->gl_dl)
+ wcore_errorf(WAFFLE_ERROR_UNKNOWN, "dlopen failed: %s", dlerror());
+
+ return self->gl_dl ? true : false;
+}
+
+// Construct a string that maps GL function to NaCl function
+// by concating given prefix and function name tail from 'src'.
+static char *
+nacl_prefix(const char *src, const char *prefix)
+{
+ if (strncmp(src, "gl", 2) != 0)
+ return NULL;
+
+ uint32_t len = strlen(src) + strlen(prefix);
+
+ char *dst = wcore_calloc(len);
+ if (!dst)
+ return NULL;
+
+ snprintf(dst, len, "%s%s", prefix, src + 2);
+
+ return dst;
}
static void*
@@ -59,7 +98,33 @@ nacl_platform_dl_sym(struct wcore_platform *wc_self,
int32_t waffle_dl,
const char *name)
{
- return NULL;
+ struct nacl_platform *self = nacl_platform(wc_self);
+ char *nacl_name = NULL;
+ void *func = NULL;
+
+ if (!self->gl_dl)
+ if (!nacl_platform_dl_can_open(wc_self, waffle_dl))
+ return false;
+
+ nacl_name = nacl_prefix(name, "GLES2");
+
+ if (!nacl_name)
+ return NULL;
+
+ func = dlsym(self->gl_dl, nacl_name);
+
+ if (!func) {
+ const char *error = dlerror();
+ if (error) {
+ wcore_errorf(WAFFLE_ERROR_UNKNOWN,
+ "dlsym(libname=\"%s\", symbol=\"%s\") failed: %s",
+ NACL_GLES2_LIBRARY, nacl_name, error);
+ }
+ }
+
+ free(nacl_name);
+
+ return func;
}
static bool
diff --git a/src/waffle/nacl/nacl_platform.h b/src/waffle/nacl/nacl_platform.h
index ba58de5..fa2d364 100644
--- a/src/waffle/nacl/nacl_platform.h
+++ b/src/waffle/nacl/nacl_platform.h
@@ -38,6 +38,7 @@
struct nacl_platform {
struct wcore_platform wcore;
struct nacl_container *nacl;
+ void *gl_dl;
};
DEFINE_CONTAINER_CAST_FUNC(nacl_platform,
--
2.1.0
More information about the waffle
mailing list