[waffle] [PATCH 3/7] gbm: fetch the libgbm function pointers at wgbm_platform_init
Emil Velikov
emil.l.velikov at gmail.com
Mon Nov 10 07:56:35 PST 2014
Thus way with a follow up commit we can use them and eliminate the
link dependency from waffle.
Signed-off-by: Emil Velikov <emil.l.velikov at gmail.com>
---
src/waffle/gbm/wgbm_platform.c | 43 +++++++++++++++++++++++++++++++++++++++++-
src/waffle/gbm/wgbm_platform.h | 17 +++++++++++++++++
2 files changed, 59 insertions(+), 1 deletion(-)
diff --git a/src/waffle/gbm/wgbm_platform.c b/src/waffle/gbm/wgbm_platform.c
index 4c224ac..981c366 100644
--- a/src/waffle/gbm/wgbm_platform.c
+++ b/src/waffle/gbm/wgbm_platform.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.
-#define __GBM__ 1
#define _POSIX_C_SOURCE 200112 // glib feature macro for unsetenv()
#include <stdlib.h>
+#include <dlfcn.h>
#include "wcore_error.h"
@@ -42,6 +42,8 @@
#include "wgbm_platform.h"
#include "wgbm_window.h"
+static const char *libgbm_filename = "libgbm.so.1";
+
static const struct wcore_platform_vtbl wgbm_platform_vtbl;
static bool
@@ -49,6 +51,7 @@ wgbm_platform_destroy(struct wcore_platform *wc_self)
{
struct wgbm_platform *self = wgbm_platform(wegl_platform(wc_self));
bool ok = true;
+ int error = 0;
if (!self)
return true;
@@ -58,6 +61,16 @@ wgbm_platform_destroy(struct wcore_platform *wc_self)
if (self->linux)
ok &= linux_platform_destroy(self->linux);
+ if (self->gbmHandle) {
+ error = dlclose(self->gbmHandle);
+ if (error) {
+ ok &= false;
+ wcore_errorf(WAFFLE_ERROR_UNKNOWN,
+ "dlclose(\"%s\") failed: %s",
+ libgbm_filename, dlerror());
+ }
+ }
+
ok &= wegl_platform_teardown(&self->wegl);
free(self);
return ok;
@@ -77,6 +90,34 @@ wgbm_platform_create(void)
if (!ok)
goto error;
+ self->gbmHandle = dlopen(libgbm_filename, RTLD_LAZY | RTLD_LOCAL);
+ if (!self->gbmHandle) {
+ wcore_errorf(WAFFLE_ERROR_FATAL,
+ "dlopen(\"%s\") failed: %s",
+ libgbm_filename, dlerror());
+ goto error;
+ }
+
+#define RETRIEVE_GBM_SYMBOL(function) \
+ self->function = dlsym(self->gbmHandle, #function); \
+ if (!self->function) { \
+ wcore_errorf(WAFFLE_ERROR_FATAL, \
+ "dlsym(\"%s\", \"" #function "\") failed: %s", \
+ libgbm_filename, dlerror()); \
+ goto error; \
+ }
+
+ RETRIEVE_GBM_SYMBOL(gbm_create_device);
+ RETRIEVE_GBM_SYMBOL(gbm_device_get_fd);
+ RETRIEVE_GBM_SYMBOL(gbm_device_destroy);
+
+ RETRIEVE_GBM_SYMBOL(gbm_surface_create);
+ RETRIEVE_GBM_SYMBOL(gbm_surface_destroy);
+
+ RETRIEVE_GBM_SYMBOL(gbm_surface_lock_front_buffer);
+ RETRIEVE_GBM_SYMBOL(gbm_surface_release_buffer);
+#undef RETRIEVE_GBM_SYMBOL
+
self->linux = linux_platform_create();
if (!self->linux)
goto error;
diff --git a/src/waffle/gbm/wgbm_platform.h b/src/waffle/gbm/wgbm_platform.h
index 11a5867..259eb19 100644
--- a/src/waffle/gbm/wgbm_platform.h
+++ b/src/waffle/gbm/wgbm_platform.h
@@ -27,6 +27,7 @@
#include <stdbool.h>
#include <stdlib.h>
+#include <gbm.h>
#undef linux
@@ -38,6 +39,22 @@ struct linux_platform;
struct wgbm_platform {
struct wegl_platform wegl;
struct linux_platform *linux;
+
+ // GBM function pointers
+ void *gbmHandle;
+
+ struct gbm_device *(*gbm_create_device)(int fd);
+ int (*gbm_device_get_fd)(struct gbm_device *gbm);
+ void (*gbm_device_destroy)(struct gbm_device *gbm);
+
+ struct gbm_surface *(*gbm_surface_create)(struct gbm_device *gbm,
+ uint32_t width, uint32_t height,
+ uint32_t format, uint32_t flags);
+ void (*gbm_surface_destroy)(struct gbm_surface *surface);
+
+ struct gbm_bo *(*gbm_surface_lock_front_buffer)(struct gbm_surface *surface);
+ void (*gbm_surface_release_buffer)(struct gbm_surface *surface,
+ struct gbm_bo *bo);
};
DEFINE_CONTAINER_CAST_FUNC(wgbm_platform,
--
2.1.3
More information about the waffle
mailing list