[waffle] [PATCH 2/3] egl: retrieve the libEGL function pointers at wegl_platform_init()
Emil Velikov
emil.l.velikov at gmail.com
Tue Sep 9 17:37:19 PDT 2014
Which will be used in our next step, to make libEGL free waffle.
Paving the way of waffle to have little to-no dependencies.
v2:
- Use libEGL.so.1 for Linux and libEGL.so for Android.
- Increase dlopen/dlsym error severity to WAFFLE_ERROR_FATAL.
- Typo s/RETREIVE_EGL_SYMBOL/RETRIEVE_EGL_SYMBOL/
Signed-off-by: Emil Velikov <emil.l.velikov at gmail.com>
---
src/waffle/egl/wegl_platform.c | 73 ++++++++++++++++++++++++++++++++++++++++--
src/waffle/egl/wegl_platform.h | 36 +++++++++++++++++++++
2 files changed, 107 insertions(+), 2 deletions(-)
diff --git a/src/waffle/egl/wegl_platform.c b/src/waffle/egl/wegl_platform.c
index b67e8d2..196b14a 100644
--- a/src/waffle/egl/wegl_platform.c
+++ b/src/waffle/egl/wegl_platform.c
@@ -23,14 +23,35 @@
// 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 "wcore_error.h"
#include "wegl_platform.h"
+
+#ifdef WAFFLE_HAS_ANDROID
+static const char *libEGL_filename = "libEGL.so";
+#else
+static const char *libEGL_filename = "libEGL.so.1";
+#endif
+
bool
wegl_platform_teardown(struct wegl_platform *self)
{
- bool ok;
+ bool ok = true;
+ int error = 0;
- ok = wcore_platform_teardown(&self->wcore);
+ if (self->eglHandle) {
+ error = dlclose(self->eglHandle);
+ if (error) {
+ ok = false;
+ wcore_errorf(WAFFLE_ERROR_UNKNOWN,
+ "dlclose(\"%s\") failed: %s",
+ libEGL_filename, dlerror());
+ }
+ }
+
+ ok &= wcore_platform_teardown(&self->wcore);
return ok;
}
bool
@@ -39,6 +60,54 @@ wegl_platform_init(struct wegl_platform *self)
bool ok;
ok = wcore_platform_init(&self->wcore);
+ if (!ok)
+ goto error;
+
+ self->eglHandle = dlopen(libEGL_filename, RTLD_LAZY | RTLD_LOCAL);
+ if (!self->eglHandle) {
+ wcore_errorf(WAFFLE_ERROR_FATAL,
+ "dlopen(\"%s\") failed: %s",
+ libEGL_filename, dlerror());
+ goto error;
+ }
+
+#define RETRIEVE_EGL_SYMBOL(function) \
+ self->function = dlsym(self->eglHandle, #function); \
+ if (!self->function) { \
+ wcore_errorf(WAFFLE_ERROR_FATAL, \
+ "dlsym(\"%s\", \"" #function "\") failed: %s", \
+ libEGL_filename, dlerror()); \
+ goto error; \
+ }
+
+ RETRIEVE_EGL_SYMBOL(eglMakeCurrent);
+ RETRIEVE_EGL_SYMBOL(eglGetProcAddress);
+
+ // display
+ RETRIEVE_EGL_SYMBOL(eglGetDisplay);
+ RETRIEVE_EGL_SYMBOL(eglInitialize);
+ RETRIEVE_EGL_SYMBOL(eglQueryString);
+ RETRIEVE_EGL_SYMBOL(eglGetError);
+ RETRIEVE_EGL_SYMBOL(eglTerminate);
+
+ // config
+ RETRIEVE_EGL_SYMBOL(eglChooseConfig);
+
+ // context
+ RETRIEVE_EGL_SYMBOL(eglBindAPI);
+ RETRIEVE_EGL_SYMBOL(eglCreateContext);
+ RETRIEVE_EGL_SYMBOL(eglDestroyContext);
+
+ // window
+ RETRIEVE_EGL_SYMBOL(eglGetConfigAttrib);
+ RETRIEVE_EGL_SYMBOL(eglCreateWindowSurface);
+ RETRIEVE_EGL_SYMBOL(eglDestroySurface);
+ RETRIEVE_EGL_SYMBOL(eglSwapBuffers);
+
+#undef RETRIEVE_EGL_SYMBOL
+error:
+ // On failure the caller of wegl_platform_init will trigger it's own
+ // destruction which will execute wegl_platform_teardown.
return ok;
}
diff --git a/src/waffle/egl/wegl_platform.h b/src/waffle/egl/wegl_platform.h
index 43108dc..645c3f8 100644
--- a/src/waffle/egl/wegl_platform.h
+++ b/src/waffle/egl/wegl_platform.h
@@ -25,6 +25,8 @@
#pragma once
+#include <EGL/egl.h>
+
#include "wcore_platform.h"
#include "wcore_util.h"
@@ -32,6 +34,40 @@ struct wegl_platform {
struct wcore_platform wcore;
// EGL function pointers
+ void *eglHandle;
+
+ EGLBoolean (*eglMakeCurrent)(EGLDisplay dpy, EGLSurface draw,
+ EGLSurface read, EGLContext ctx);
+ __eglMustCastToProperFunctionPointerType
+ (*eglGetProcAddress)(const char *procname);
+
+ // display
+ EGLDisplay (*eglGetDisplay)(EGLNativeDisplayType display_id);
+ EGLBoolean (*eglInitialize)(EGLDisplay dpy, EGLint *major, EGLint *minor);
+ const char * (*eglQueryString)(EGLDisplay dpy, EGLint name);
+ EGLint (*eglGetError)(void);
+ EGLBoolean (*eglTerminate)(EGLDisplay dpy);
+
+ // config
+ EGLBoolean (*eglChooseConfig)(EGLDisplay dpy, const EGLint *attrib_list,
+ EGLConfig *configs, EGLint config_size,
+ EGLint *num_config);
+
+ // context
+ EGLBoolean (*eglBindAPI)(EGLenum api);
+ EGLContext (*eglCreateContext)(EGLDisplay dpy, EGLConfig config,
+ EGLContext share_context,
+ const EGLint *attrib_list);
+ EGLBoolean (*eglDestroyContext)(EGLDisplay dpy, EGLContext ctx);
+
+ // window
+ EGLBoolean (*eglGetConfigAttrib)(EGLDisplay dpy, EGLConfig config,
+ EGLint attribute, EGLint *value);
+ EGLSurface (*eglCreateWindowSurface)(EGLDisplay dpy, EGLConfig config,
+ EGLNativeWindowType win,
+ const EGLint *attrib_list);
+ EGLBoolean (*eglDestroySurface)(EGLDisplay dpy, EGLSurface surface);
+ EGLBoolean (*eglSwapBuffers)(EGLDisplay dpy, EGLSurface surface);
};
DEFINE_CONTAINER_CAST_FUNC(wegl_platform,
--
2.1.0
More information about the waffle
mailing list