[waffle] [PATCH 7/7] nacl: add implementation for waffle_dl_sym
Tapani Pälli
tapani.palli at intel.com
Thu Jan 22 23:59:39 PST 2015
Signed-off-by: Tapani Pälli <tapani.palli at intel.com>
---
src/waffle/nacl/nacl_platform.c | 63 +++++++++++++++++++++++++++++++++++++++--
src/waffle/nacl/nacl_platform.h | 1 +
2 files changed, 62 insertions(+), 2 deletions(-)
diff --git a/src/waffle/nacl/nacl_platform.c b/src/waffle/nacl/nacl_platform.c
index 20a9739..c134304 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,40 @@ 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:
+ 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 = calloc(len, 1);
+ if (!dst)
+ return NULL;
+
+ snprintf(dst, len, "%s%s", prefix, src + 2);
+
+ return dst;
}
static void*
@@ -59,7 +97,28 @@ 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;
+
+ switch (waffle_dl) {
+ case WAFFLE_DL_OPENGL_ES2:
+ nacl_name = nacl_prefix(name, "GLES2");
+ break;
+ }
+
+ if (!nacl_name)
+ return NULL;
+
+ func = dlsym(self->gl_dl, nacl_name);
+
+ 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