diff options
author | Chad Versace <chad.versace@intel.com> | 2015-04-10 09:01:11 -0700 |
---|---|---|
committer | Chad Versace <chad.versace@intel.com> | 2015-04-10 09:01:11 -0700 |
commit | cfb9a4e0b8b8f398eeda694e7217c9ce4511879c (patch) | |
tree | 872a83a4c18aba64b102736bd724187b3322bbda | |
parent | 038b1dbc184054382bc89f197cf7c7811aeed5a3 (diff) | |
parent | 2e3ae6f2e24e92fffb0b45f11b90618a9b8c9a55 (diff) | |
download | waffle-cfb9a4e0b8b8f398eeda694e7217c9ce4511879c.tar.gz |
Merge branch 'evelikov/for-chad/nacl-fixes'
* evelikov/for-chad/nacl-fixes:
cgl,nacl: print the dlerror() when dlopen() fails
android: add missing pragma once guard
android: remove no longer needed extern "C"
nacl: add missing pragma once guards
nacl: untangle header inclusions
nacl: use nacl_container prefix on relevant functions
nacl: emit errors when things fail
nacl: rework nacl_dl functions
nacl: move header inclusion outside of the extern "C" block
nacl: move dlfcn.h inclusion to where it's needed
api/core: annotate structs/functions for C linkage
25 files changed, 376 insertions, 137 deletions
diff --git a/src/waffle/CMakeLists.txt b/src/waffle/CMakeLists.txt index 4f1d5c7..dd9fa11 100644 --- a/src/waffle/CMakeLists.txt +++ b/src/waffle/CMakeLists.txt @@ -181,6 +181,7 @@ if(waffle_has_nacl) nacl/nacl_config.c nacl/nacl_context.c nacl/nacl_display.c + nacl/nacl_dl.c nacl/nacl_platform.c nacl/nacl_window.c ) diff --git a/src/waffle/android/droid_surfaceflingerlink.cpp b/src/waffle/android/droid_surfaceflingerlink.cpp index 397c86c..dc55a8a 100644 --- a/src/waffle/android/droid_surfaceflingerlink.cpp +++ b/src/waffle/android/droid_surfaceflingerlink.cpp @@ -37,10 +37,8 @@ #include "droid_surfaceflingerlink.h" -extern "C" { #include "wcore_util.h" #include "wcore_error.h" -}; using namespace android; diff --git a/src/waffle/android/droid_surfaceflingerlink.h b/src/waffle/android/droid_surfaceflingerlink.h index 53aeb4f..67c1dc2 100644 --- a/src/waffle/android/droid_surfaceflingerlink.h +++ b/src/waffle/android/droid_surfaceflingerlink.h @@ -23,6 +23,8 @@ // OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +#pragma once + #ifdef __cplusplus extern "C" { #endif diff --git a/src/waffle/api/api_object.h b/src/waffle/api/api_object.h index d417d0a..ef11c5b 100644 --- a/src/waffle/api/api_object.h +++ b/src/waffle/api/api_object.h @@ -27,6 +27,10 @@ #include "waffle.h" +#ifdef __cplusplus +extern "C" { +#endif + // This header is so sad and lonely... but there is no other appropriate place // to define this struct. @@ -36,3 +40,7 @@ struct api_object { /// For consistency, a `waffle_display` belongs to itself. size_t display_id; }; + +#ifdef __cplusplus +} +#endif diff --git a/src/waffle/cgl/cgl_dl.m b/src/waffle/cgl/cgl_dl.m index 764ecf0..738e395 100644 --- a/src/waffle/cgl/cgl_dl.m +++ b/src/waffle/cgl/cgl_dl.m @@ -65,7 +65,7 @@ cgl_dl_open(struct cgl_platform *plat) if (!plat->dl_gl) { wcore_errorf(WAFFLE_ERROR_UNKNOWN, - "dlopen(\"%s\") failed", cgl_dl_gl_path); + "dlopen(\"%s\") failed: %s", cgl_dl_gl_path, dlerror()); return false; } diff --git a/src/waffle/core/wcore_config.h b/src/waffle/core/wcore_config.h index 27534af..2fc02d5 100644 --- a/src/waffle/core/wcore_config.h +++ b/src/waffle/core/wcore_config.h @@ -36,6 +36,10 @@ #include "wcore_config_attrs.h" #include "wcore_util.h" +#ifdef __cplusplus +extern "C" { +#endif + struct wcore_config; union waffle_native_config; @@ -77,3 +81,7 @@ wcore_config_teardown(struct wcore_config *self) assert(self); return true; } + +#ifdef __cplusplus +} +#endif diff --git a/src/waffle/core/wcore_config_attrs.h b/src/waffle/core/wcore_config_attrs.h index 0eaa4a1..cca5e8b 100644 --- a/src/waffle/core/wcore_config_attrs.h +++ b/src/waffle/core/wcore_config_attrs.h @@ -28,6 +28,10 @@ #include <stdbool.h> #include <stdint.h> +#ifdef __cplusplus +extern "C" { +#endif + /// @brief Encodes the attribute list received by waffle_config_choose(). struct wcore_config_attrs { int32_t context_api; @@ -84,3 +88,7 @@ bool wcore_config_attrs_version_le( const struct wcore_config_attrs *attrs, int merged_version); + +#ifdef __cplusplus +} +#endif diff --git a/src/waffle/core/wcore_display.h b/src/waffle/core/wcore_display.h index fea2ff6..6e374e3 100644 --- a/src/waffle/core/wcore_display.h +++ b/src/waffle/core/wcore_display.h @@ -33,6 +33,10 @@ #include "wcore_util.h" +#ifdef __cplusplus +extern "C" { +#endif + struct wcore_display; struct wcore_platform; union waffle_native_display; @@ -64,3 +68,7 @@ wcore_display_teardown(struct wcore_display *self) assert(self); return true; } + +#ifdef __cplusplus +} +#endif diff --git a/src/waffle/core/wcore_error.h b/src/waffle/core/wcore_error.h index 0a9767c..cee5bd1 100644 --- a/src/waffle/core/wcore_error.h +++ b/src/waffle/core/wcore_error.h @@ -29,6 +29,10 @@ #include "waffle.h" +#ifdef __cplusplus +extern "C" { +#endif + /// @brief Thread-local info for the wcore_error module. struct wcore_error_tinfo; @@ -92,3 +96,7 @@ _wcore_error_internal(const char *file, int line, const char *format, ...); void _wcore_error_enable(void); void _wcore_error_disable(void); + +#ifdef __cplusplus +} +#endif diff --git a/src/waffle/core/wcore_util.h b/src/waffle/core/wcore_util.h index 183134f..b823b21 100644 --- a/src/waffle/core/wcore_util.h +++ b/src/waffle/core/wcore_util.h @@ -28,6 +28,10 @@ #include <stddef.h> #include "c99_compat.h" +#ifdef __cplusplus +extern "C" { +#endif + #define container_of(ptr, type, member) ({ \ const __typeof__(((type *)0)->member ) *__mptr = (ptr); \ (type*)((void*)__mptr - offsetof(type, member)); \ @@ -107,3 +111,7 @@ wcore_calloc(size_t size); const char* wcore_enum_to_string(int32_t e); + +#ifdef __cplusplus +} +#endif diff --git a/src/waffle/nacl/nacl_config.c b/src/waffle/nacl/nacl_config.c index 16adc66..9017775 100644 --- a/src/waffle/nacl/nacl_config.c +++ b/src/waffle/nacl/nacl_config.c @@ -24,9 +24,12 @@ // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include "ppapi/c/pp_graphics_3d.h" -#include "nacl_config.h" + +#include "wcore_config_attrs.h" #include "wcore_error.h" +#include "nacl_config.h" + bool nacl_config_destroy(struct wcore_config *wc_self) { diff --git a/src/waffle/nacl/nacl_config.h b/src/waffle/nacl/nacl_config.h index 47fa252..d461d43 100644 --- a/src/waffle/nacl/nacl_config.h +++ b/src/waffle/nacl/nacl_config.h @@ -25,9 +25,16 @@ #pragma once +#include <stdbool.h> +#include <stdint.h> + #include "wcore_config.h" #include "wcore_util.h" +#ifdef __cplusplus +extern "C" { +#endif + struct wcore_config_attrs; struct wcore_platform; @@ -48,3 +55,7 @@ nacl_config_choose(struct wcore_platform *wc_plat, bool nacl_config_destroy(struct wcore_config *wc_self); + +#ifdef __cplusplus +} +#endif diff --git a/src/waffle/nacl/nacl_container.cpp b/src/waffle/nacl/nacl_container.cpp index 84ab1da..e3d89fd 100644 --- a/src/waffle/nacl/nacl_container.cpp +++ b/src/waffle/nacl/nacl_container.cpp @@ -23,10 +23,16 @@ // OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +#include <dlfcn.h> + #include "ppapi/cpp/graphics_3d.h" #include "ppapi/cpp/instance.h" #include "ppapi/cpp/module.h" #include "ppapi/c/pp_errors.h" + +#include "wcore_error.h" + +#include "nacl_config.h" #include "nacl_container.h" #include "nacl_swap_thread.h" @@ -67,7 +73,7 @@ nacl_container_ctor() } static bool -nacl_context_init(waffle::nacl_container *nc, struct nacl_config *cfg) +nacl_container_context_init(waffle::nacl_container *nc, struct nacl_config *cfg) { // There is no way currently to pass a pp::Instance for Waffle, so // we fetch a map of all instances and if there's only one we select @@ -129,26 +135,26 @@ nacl_context_init(waffle::nacl_container *nc, struct nacl_config *cfg) }; // namespace waffle ends extern "C" struct nacl_container* -nacl_init() +nacl_container_init() { return reinterpret_cast<nacl_container*>(waffle::nacl_container_ctor()); } extern "C" void -nacl_teardown(nacl_container *nc) +nacl_container_teardown(nacl_container *nc) { waffle::nacl_container_dtor(reinterpret_cast<waffle::nacl_container*>(nc)); } extern "C" bool -nacl_context_init(struct nacl_container *nc, struct nacl_config *cfg) +nacl_container_context_init(struct nacl_container *nc, struct nacl_config *cfg) { - return waffle::nacl_context_init( + return waffle::nacl_container_context_init( reinterpret_cast<waffle::nacl_container*>(nc), cfg); } extern "C" void -nacl_context_fini(struct nacl_container *nc) +nacl_container_context_fini(struct nacl_container *nc) { waffle::nacl_container *cpp_nc = reinterpret_cast<waffle::nacl_container*>(nc); @@ -161,7 +167,7 @@ nacl_context_fini(struct nacl_container *nc) } extern "C" bool -nacl_resize(struct nacl_container *nc, int32_t width, int32_t height) +nacl_container_window_resize(struct nacl_container *nc, int32_t width, int32_t height) { waffle::nacl_container *cpp_nc = reinterpret_cast<waffle::nacl_container*>(nc); @@ -187,7 +193,7 @@ nacl_resize(struct nacl_container *nc, int32_t width, int32_t height) } extern "C" bool -nacl_makecurrent(nacl_container *nc, bool release) +nacl_container_context_makecurrent(nacl_container *nc, bool release) { waffle::nacl_container *cpp_nc = reinterpret_cast<waffle::nacl_container*>(nc); @@ -200,7 +206,7 @@ nacl_makecurrent(nacl_container *nc, bool release) } extern "C" bool -nacl_swapbuffers(nacl_container *nc) +nacl_container_swapbuffere(nacl_container *nc) { waffle::nacl_container *cpp_nc = reinterpret_cast<waffle::nacl_container*>(nc); diff --git a/src/waffle/nacl/nacl_container.h b/src/waffle/nacl/nacl_container.h index 579856d..d047fa7 100644 --- a/src/waffle/nacl/nacl_container.h +++ b/src/waffle/nacl/nacl_container.h @@ -23,27 +23,27 @@ // OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -#ifdef __cplusplus +#pragma once -#include <dlfcn.h> +#include <stdbool.h> +#include <stdint.h> +#ifdef __cplusplus extern "C" { #endif -#include "nacl_config.h" -#include "wcore_error.h" - #define NACL_GLES2_LIBRARY "libppapi_gles2.so" struct nacl_container; +struct nacl_config; -struct nacl_container *nacl_init(); -void nacl_teardown(struct nacl_container *nc); -bool nacl_context_init(struct nacl_container *nc, struct nacl_config *cfg); -bool nacl_resize(struct nacl_container *nc, int32_t width, int32_t height); -bool nacl_makecurrent(struct nacl_container *nc, bool release); -void nacl_context_fini(struct nacl_container *nc); -bool nacl_swapbuffers(struct nacl_container *nc); +struct nacl_container *nacl_container_init(); +void nacl_container_teardown(struct nacl_container *nc); +bool nacl_container_context_init(struct nacl_container *nc, struct nacl_config *cfg); +bool nacl_container_window_resize(struct nacl_container *nc, int32_t width, int32_t height); +bool nacl_container_context_makecurrent(struct nacl_container *nc, bool release); +void nacl_container_context_fini(struct nacl_container *nc); +bool nacl_container_swapbuffere(struct nacl_container *nc); #ifdef __cplusplus }; #endif diff --git a/src/waffle/nacl/nacl_context.c b/src/waffle/nacl/nacl_context.c index 962c4d9..52015c2 100644 --- a/src/waffle/nacl/nacl_context.c +++ b/src/waffle/nacl/nacl_context.c @@ -23,24 +23,24 @@ // OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +#include "nacl_config.h" +#include "nacl_container.h" #include "nacl_context.h" -#include "api_priv.h" +#include "nacl_platform.h" bool nacl_context_destroy(struct wcore_context *wc_self) { - struct nacl_context *self; + struct nacl_context *self = nacl_context(wc_self); + struct nacl_platform *plat; bool ok = true; if (!wc_self) return ok; - struct nacl_platform *nacl_plat = - nacl_platform(api_platform); - - self = nacl_context(wc_self); + plat = nacl_platform(wc_self->display->platform); - nacl_context_fini(nacl_plat->nacl); + nacl_container_context_fini(plat->nacl); ok &= wcore_context_teardown(wc_self); free(self); @@ -65,7 +65,7 @@ nacl_context_create(struct wcore_platform *wc_plat, if (!ok) goto error; - ok = nacl_context_init(platform->nacl, config); + ok = nacl_container_context_init(platform->nacl, config); if (!ok) goto error; diff --git a/src/waffle/nacl/nacl_context.h b/src/waffle/nacl/nacl_context.h index bb4481a..1330e27 100644 --- a/src/waffle/nacl/nacl_context.h +++ b/src/waffle/nacl/nacl_context.h @@ -25,12 +25,11 @@ #pragma once +#include <stdbool.h> + #include "wcore_context.h" #include "wcore_util.h" -#include "nacl_display.h" -#include "nacl_platform.h" - struct wcore_config; struct wcore_platform; diff --git a/src/waffle/nacl/nacl_display.c b/src/waffle/nacl/nacl_display.c index d1906fe..7e18ba3 100644 --- a/src/waffle/nacl/nacl_display.c +++ b/src/waffle/nacl/nacl_display.c @@ -23,6 +23,8 @@ // OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +#include "wcore_error.h" + #include "nacl_display.h" bool diff --git a/src/waffle/nacl/nacl_display.h b/src/waffle/nacl/nacl_display.h index 34eee21..9ae3b0a 100644 --- a/src/waffle/nacl/nacl_display.h +++ b/src/waffle/nacl/nacl_display.h @@ -25,8 +25,10 @@ #pragma once +#include <stdbool.h> +#include <stdint.h> + #include "wcore_display.h" -#include "wcore_error.h" #include "wcore_util.h" struct wcore_platform; diff --git a/src/waffle/nacl/nacl_dl.c b/src/waffle/nacl/nacl_dl.c new file mode 100644 index 0000000..79958da --- /dev/null +++ b/src/waffle/nacl/nacl_dl.c @@ -0,0 +1,200 @@ +// Copyright 2012-2015 Intel Corporation +// +// All rights reserved. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are met: +// +// - Redistributions of source code must retain the above copyright notice, this +// list of conditions and the following disclaimer. +// +// - Redistributions in binary form must reproduce the above copyright notice, +// this list of conditions and the following disclaimer in the documentation +// and/or other materials provided with the distribution. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +#include <assert.h> +#include <dlfcn.h> +#include <stdio.h> +#include <string.h> + +#include "wcore_error.h" + +#include "nacl_container.h" +#include "nacl_dl.h" +#include "nacl_platform.h" + + +static bool +nacl_dl_check_enum(int32_t waffle_dl) +{ + switch (waffle_dl) { + case WAFFLE_DL_OPENGL: + wcore_errorf(WAFFLE_ERROR_UNSUPPORTED_ON_PLATFORM, + "NACL does not support OpenGL"); + return false; + case WAFFLE_DL_OPENGL_ES1: + wcore_errorf(WAFFLE_ERROR_UNSUPPORTED_ON_PLATFORM, + "NACL does not support OpenGL ES1"); + return false; + case WAFFLE_DL_OPENGL_ES2: + return true; + case WAFFLE_DL_OPENGL_ES3: + wcore_errorf(WAFFLE_ERROR_UNSUPPORTED_ON_PLATFORM, + "NACL does not support OpenGL ES3"); + return false; + default: + assert(false); + return false; + } +} + +static bool +nacl_dl_open(struct nacl_platform *plat) +{ + plat->dl_gl = dlopen(NACL_GLES2_LIBRARY, RTLD_LAZY); + + if (!plat->dl_gl) { + wcore_errorf(WAFFLE_ERROR_UNKNOWN, + "dlopen(\"%s\") failed: %s", NACL_GLES2_LIBRARY, dlerror()); + return false; + } + + return true; +} + +bool +nacl_dl_can_open(struct wcore_platform *wc_plat, + int32_t waffle_dl) +{ + struct nacl_platform *plat = nacl_platform(wc_plat); + bool ok; + + WCORE_ERROR_DISABLED({ + ok = nacl_dl_check_enum(waffle_dl); + }); + + if (!ok) + return false; + + if (plat->dl_gl != NULL) + return true; + + WCORE_ERROR_DISABLED({ + nacl_dl_open(plat); + }); + + return plat->dl_gl != NULL; +} + +// Construct a string that maps GL function to NaCl function +// by concating given prefix and function name tail from 'src'. +static char * +nacl_dl_prefix(const char *src, const char *prefix) +{ + if (strncmp(src, "gl", 2) != 0) { + wcore_errorf(WAFFLE_ERROR_UNKNOWN, + "NACL symbol name does not start with \"gl\""); + return NULL; + } + + uint32_t len = strlen(src) + strlen(prefix); + + char *dst = wcore_calloc(len); + if (!dst) + return NULL; + + int n = snprintf(dst, len, "%s%s", prefix, src + 2); + if (n < 0 || n >= len) { + wcore_errorf(WAFFLE_ERROR_UNKNOWN, + "NACL cannot create symbol prefix"); + free(dst); + return NULL; + } + + return dst; +} + +void* +nacl_dl_sym(struct wcore_platform *wc_plat, + int32_t waffle_dl, + const char *name) +{ + struct nacl_platform *plat = nacl_platform(wc_plat); + + if (!nacl_dl_check_enum(waffle_dl)) + return NULL; + + if (plat->dl_gl == NULL) + nacl_dl_open(plat); + + if (plat->dl_gl == NULL) + return NULL; + + char *nacl_name = nacl_dl_prefix(name, "GLES2"); + if (!nacl_name) + return NULL; + + // Clear any previous error. + dlerror(); + + void *sym = dlsym(plat->dl_gl, name); + + if (sym) { + free(nacl_name); + return sym; + } + + // dlsym returned NULL. Check if an error occured. + 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 NULL; +} + +bool +nacl_dl_close(struct wcore_platform *wc_plat) +{ + struct nacl_platform *plat = nacl_platform(wc_plat); + + int error_code = 0; + const char *error_msg = NULL; + + if (!plat->dl_gl) + return true; + + error_code = dlclose(plat->dl_gl); + + if (!error_code) + return true; + + error_msg = dlerror(); + + if (error_msg) { + wcore_errorf(WAFFLE_ERROR_UNKNOWN, + "dlclose(libname=\"%s\") failed: %s", + NACL_GLES2_LIBRARY, error_msg); + } + else { + wcore_errorf(WAFFLE_ERROR_UNKNOWN, + "dlclose(libname=\"%s\") failed", + NACL_GLES2_LIBRARY); + } + + return false; +} diff --git a/src/waffle/nacl/nacl_dl.h b/src/waffle/nacl/nacl_dl.h new file mode 100644 index 0000000..e7748f3 --- /dev/null +++ b/src/waffle/nacl/nacl_dl.h @@ -0,0 +1,43 @@ +// Copyright 2012-2015 Intel Corporation +// +// All rights reserved. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are met: +// +// - Redistributions of source code must retain the above copyright notice, this +// list of conditions and the following disclaimer. +// +// - Redistributions in binary form must reproduce the above copyright notice, +// this list of conditions and the following disclaimer in the documentation +// and/or other materials provided with the distribution. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +#pragma once + +#include <stdbool.h> +#include <stdint.h> + +struct wcore_platform; + +bool +nacl_dl_can_open(struct wcore_platform *wc_plat, + int32_t waffle_dl); + +void* +nacl_dl_sym(struct wcore_platform *wc_plat, + int32_t waffle_dl, + const char *name); + +bool +nacl_dl_close(struct wcore_platform *wc_plat); diff --git a/src/waffle/nacl/nacl_platform.c b/src/waffle/nacl/nacl_platform.c index 22169da..a3d7625 100644 --- a/src/waffle/nacl/nacl_platform.c +++ b/src/waffle/nacl/nacl_platform.c @@ -26,7 +26,13 @@ #include <dlfcn.h> #include <stdio.h> +#include "nacl_config.h" +#include "nacl_container.h" +#include "nacl_context.h" +#include "nacl_display.h" +#include "nacl_dl.h" #include "nacl_platform.h" +#include "nacl_window.h" static const struct wcore_platform_vtbl nacl_platform_vtbl; @@ -41,100 +47,23 @@ nacl_platform_destroy(struct wcore_platform *wc_self) ok &= wcore_platform_teardown(wc_self); - nacl_teardown(self->nacl); + nacl_container_teardown(self->nacl); - if (self->gl_dl) - if (dlclose(self->gl_dl) != 0) - wcore_errorf(WAFFLE_ERROR_UNKNOWN, "dlclose failed: %s", - dlerror()); + if (self->dl_gl) + ok &= nacl_dl_close(&self->wcore); free(self); return ok; } static bool -nacl_platform_dl_can_open(struct wcore_platform *wc_self, - int32_t waffle_dl) -{ - 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* -nacl_platform_dl_sym(struct wcore_platform *wc_self, - int32_t waffle_dl, - const char *name) -{ - 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 nacl_platform_make_current(struct wcore_platform *wc_self, struct wcore_display *wc_dpy, struct wcore_window *wc_window, struct wcore_context *wc_ctx) { bool release = (!wc_window && !wc_ctx); - return nacl_makecurrent(nacl_platform(wc_self)->nacl, + return nacl_container_context_makecurrent(nacl_platform(wc_self)->nacl, release); } @@ -152,7 +81,7 @@ nacl_platform_create(void) if (!ok) goto error; - self->nacl = nacl_init(); + self->nacl = nacl_container_init(); if (!self->nacl) goto error; @@ -168,8 +97,8 @@ static const struct wcore_platform_vtbl nacl_platform_vtbl = { .destroy = nacl_platform_destroy, .make_current = nacl_platform_make_current, - .dl_can_open = nacl_platform_dl_can_open, - .dl_sym = nacl_platform_dl_sym, + .dl_can_open = nacl_dl_can_open, + .dl_sym = nacl_dl_sym, .display = { .connect = nacl_display_connect, diff --git a/src/waffle/nacl/nacl_platform.h b/src/waffle/nacl/nacl_platform.h index fa2d364..259bea9 100644 --- a/src/waffle/nacl/nacl_platform.h +++ b/src/waffle/nacl/nacl_platform.h @@ -26,19 +26,12 @@ #pragma once #include "wcore_platform.h" -#include "wcore_error.h" #include "wcore_util.h" -#include "nacl_config.h" -#include "nacl_container.h" -#include "nacl_context.h" -#include "nacl_display.h" -#include "nacl_window.h" - struct nacl_platform { struct wcore_platform wcore; struct nacl_container *nacl; - void *gl_dl; + void *dl_gl; }; DEFINE_CONTAINER_CAST_FUNC(nacl_platform, diff --git a/src/waffle/nacl/nacl_swap_thread.h b/src/waffle/nacl/nacl_swap_thread.h index 8e8687b..ce115b3 100644 --- a/src/waffle/nacl/nacl_swap_thread.h +++ b/src/waffle/nacl/nacl_swap_thread.h @@ -23,6 +23,8 @@ // OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +#pragma once + #include "ppapi/cpp/graphics_3d.h" #include "ppapi/cpp/instance.h" #include "ppapi/utility/completion_callback_factory.h" diff --git a/src/waffle/nacl/nacl_window.c b/src/waffle/nacl/nacl_window.c index 5ac031c..dc8d49c 100644 --- a/src/waffle/nacl/nacl_window.c +++ b/src/waffle/nacl/nacl_window.c @@ -23,10 +23,10 @@ // OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -#include "wcore_error.h" #include "wcore_attrib_list.h" -#include "nacl_config.h" -#include "nacl_display.h" +#include "wcore_error.h" + +#include "nacl_container.h" #include "nacl_window.h" #include "nacl_platform.h" @@ -70,7 +70,7 @@ nacl_window_create(struct wcore_platform *wc_plat, goto error; // Set requested dimensions for the backing surface. - if (!nacl_resize(nplat->nacl, width, height)) + if (!nacl_container_window_resize(nplat->nacl, width, height)) goto error; return &self->wcore; @@ -91,12 +91,12 @@ nacl_window_resize(struct wcore_window *wc_self, int32_t width, int32_t height) { struct nacl_platform *plat = nacl_platform(wc_self->display->platform); - return nacl_resize(plat->nacl, width, height); + return nacl_container_window_resize(plat->nacl, width, height); } bool nacl_window_swap_buffers(struct wcore_window *wc_self) { struct nacl_platform *plat = nacl_platform(wc_self->display->platform); - return nacl_swapbuffers(plat->nacl); + return nacl_container_swapbuffere(plat->nacl); } diff --git a/src/waffle/nacl/nacl_window.h b/src/waffle/nacl/nacl_window.h index d3465f3..c3e9957 100644 --- a/src/waffle/nacl/nacl_window.h +++ b/src/waffle/nacl/nacl_window.h @@ -25,10 +25,10 @@ #pragma once +#include <stdbool.h> + #include "wcore_window.h" #include "wcore_util.h" -#include "nacl_container.h" -#include "nacl_platform.h" struct wcore_platform; |