[waffle] [PATCH 2/4] wayland: fetch wl_egl_* function pointers at wayland_platform_create
Emil Velikov
emil.l.velikov at gmail.com
Mon Feb 23 12:32:26 PST 2015
Will be used by the next commit to demote the link-time dependency.
As a result one will not require libwayland-egl.so.1 to be present on
their system unless they want to use WAFFLE_PLATFORM_WAYLAND.
Signed-off-by: Emil Velikov <emil.l.velikov at gmail.com>
---
src/waffle/wayland/wayland_platform.c | 37 +++++++++++++++++++++++++++++++++++
src/waffle/wayland/wayland_platform.h | 18 +++++++++++++++++
2 files changed, 55 insertions(+)
diff --git a/src/waffle/wayland/wayland_platform.c b/src/waffle/wayland/wayland_platform.c
index 63cfdc2..94c0010 100644
--- a/src/waffle/wayland/wayland_platform.c
+++ b/src/waffle/wayland/wayland_platform.c
@@ -27,6 +27,7 @@
#define _POSIX_C_SOURCE 200112 // glib feature macro for unsetenv()
#include <stdlib.h>
+#include <dlfcn.h>
#include "waffle_wayland.h"
@@ -43,6 +44,8 @@
#include "wayland_platform.h"
#include "wayland_window.h"
+static const char *libwl_egl_filename = "libwayland-egl.so.1";
+
static const struct wcore_platform_vtbl wayland_platform_vtbl;
static bool
@@ -50,6 +53,7 @@ wayland_platform_destroy(struct wcore_platform *wc_self)
{
struct wayland_platform *self = wayland_platform(wegl_platform(wc_self));
bool ok = true;
+ int error;
if (!self)
return true;
@@ -59,6 +63,16 @@ wayland_platform_destroy(struct wcore_platform *wc_self)
if (self->linux)
ok &= linux_platform_destroy(self->linux);
+ if (self->dl_wl_egl) {
+ error = dlclose(self->dl_wl_egl);
+ if (error) {
+ ok &= false;
+ wcore_errorf(WAFFLE_ERROR_UNKNOWN,
+ "dlclose(\"%s\") failed: %s",
+ libwl_egl_filename, dlerror());
+ }
+ }
+
ok &= wegl_platform_teardown(&self->wegl);
free(self);
return ok;
@@ -78,6 +92,29 @@ wayland_platform_create(void)
if (!ok)
goto error;
+ self->dl_wl_egl = dlopen(libwl_egl_filename, RTLD_LAZY | RTLD_LOCAL);
+ if (!self->dl_wl_egl) {
+ wcore_errorf(WAFFLE_ERROR_FATAL,
+ "dlopen(\"%s\") failed: %s",
+ libwl_egl_filename, dlerror());
+ goto error;
+ }
+
+#define RETRIEVE_WL_EGL_SYMBOL(function) \
+ self->function = dlsym(self->dl_wl_egl, #function); \
+ if (!self->function) { \
+ wcore_errorf(WAFFLE_ERROR_FATAL, \
+ "dlsym(\"%s\", \"" #function "\") failed: %s", \
+ libwl_egl_filename, dlerror()); \
+ goto error; \
+ }
+
+ RETRIEVE_WL_EGL_SYMBOL(wl_egl_window_create);
+ RETRIEVE_WL_EGL_SYMBOL(wl_egl_window_destroy);
+ RETRIEVE_WL_EGL_SYMBOL(wl_egl_window_resize);
+
+#undef RETRIEVE_WL_EGL_SYMBOL
+
self->linux = linux_platform_create();
if (!self->linux)
goto error;
diff --git a/src/waffle/wayland/wayland_platform.h b/src/waffle/wayland/wayland_platform.h
index c4e870f..574a306 100644
--- a/src/waffle/wayland/wayland_platform.h
+++ b/src/waffle/wayland/wayland_platform.h
@@ -36,10 +36,28 @@
#include "wcore_util.h"
struct linux_platform;
+struct wl_egl_window;
+struct wl_surface;
struct wayland_platform {
struct wegl_platform wegl;
struct linux_platform *linux;
+
+
+ void *dl_wl_egl;
+
+ struct wl_egl_window *
+ (*wl_egl_window_create)(struct wl_surface *surface,
+ int width, int height);
+
+ void
+ (*wl_egl_window_destroy)(struct wl_egl_window *egl_window);
+
+ void
+ (*wl_egl_window_resize)(struct wl_egl_window *egl_window,
+ int width, int height,
+ int dx, int dy);
+
};
DEFINE_CONTAINER_CAST_FUNC(wayland_platform,
--
2.3.0
More information about the waffle
mailing list