[waffle] [PATCH 02/10] gbm: make platform friendlier to derived classes
Frank Henigman
fjhenigman at google.com
Mon Mar 30 12:12:42 PDT 2015
Retrieve additional gbm functions.
Change some functions from private to public.
Factor init and teardown out of create and destroy respectively,
so a derived class can used them on its embedded platform object.
Signed-off-by: Frank Henigman <fjhenigman at google.com>
---
src/waffle/gbm/wgbm_platform.c | 58 +++++++++++++++++++++++++-----------------
src/waffle/gbm/wgbm_platform.h | 51 ++++++++++++++++++++++++++++---------
2 files changed, 74 insertions(+), 35 deletions(-)
diff --git a/src/waffle/gbm/wgbm_platform.c b/src/waffle/gbm/wgbm_platform.c
index 981c366..0fc0352 100644
--- a/src/waffle/gbm/wgbm_platform.c
+++ b/src/waffle/gbm/wgbm_platform.c
@@ -46,10 +46,9 @@ static const char *libgbm_filename = "libgbm.so.1";
static const struct wcore_platform_vtbl wgbm_platform_vtbl;
-static bool
-wgbm_platform_destroy(struct wcore_platform *wc_self)
+bool
+wgbm_platform_teardown(struct wgbm_platform *self)
{
- struct wgbm_platform *self = wgbm_platform(wegl_platform(wc_self));
bool ok = true;
int error = 0;
@@ -72,20 +71,27 @@ wgbm_platform_destroy(struct wcore_platform *wc_self)
}
ok &= wegl_platform_teardown(&self->wegl);
+ return ok;
+}
+
+bool
+wgbm_platform_destroy(struct wcore_platform *wc_self)
+{
+ struct wgbm_platform *self = wgbm_platform(wegl_platform(wc_self));
+
+ if (!self)
+ return true;
+
+ bool ok = wgbm_platform_teardown(self);
free(self);
return ok;
}
-struct wcore_platform*
-wgbm_platform_create(void)
+bool
+wgbm_platform_init(struct wgbm_platform *self)
{
- struct wgbm_platform *self;
bool ok = true;
- self = wcore_calloc(sizeof(*self));
- if (self == NULL)
- return NULL;
-
ok = wegl_platform_init(&self->wegl);
if (!ok)
goto error;
@@ -98,7 +104,7 @@ wgbm_platform_create(void)
goto error;
}
-#define RETRIEVE_GBM_SYMBOL(function) \
+#define RETRIEVE_GBM_SYMBOL(type, function, args) \
self->function = dlsym(self->gbmHandle, #function); \
if (!self->function) { \
wcore_errorf(WAFFLE_ERROR_FATAL, \
@@ -107,15 +113,7 @@ wgbm_platform_create(void)
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);
+ GBM_FUNCTIONS(RETRIEVE_GBM_SYMBOL);
#undef RETRIEVE_GBM_SYMBOL
self->linux = linux_platform_create();
@@ -125,14 +123,28 @@ wgbm_platform_create(void)
setenv("EGL_PLATFORM", "drm", true);
self->wegl.wcore.vtbl = &wgbm_platform_vtbl;
- return &self->wegl.wcore;
+ return true;
error:
+ wgbm_platform_teardown(self);
+ return false;
+}
+
+struct wcore_platform*
+wgbm_platform_create(void)
+{
+ struct wgbm_platform *self = wcore_calloc(sizeof(*self));
+ if (self == NULL)
+ return NULL;
+
+ if (wgbm_platform_init(self))
+ return &self->wegl.wcore;
+
wgbm_platform_destroy(&self->wegl.wcore);
return NULL;
}
-static bool
+bool
wgbm_dl_can_open(struct wcore_platform *wc_self,
int32_t waffle_dl)
{
@@ -140,7 +152,7 @@ wgbm_dl_can_open(struct wcore_platform *wc_self,
return linux_platform_dl_can_open(self->linux, waffle_dl);
}
-static void*
+void*
wgbm_dl_sym(struct wcore_platform *wc_self,
int32_t waffle_dl,
const char *name)
diff --git a/src/waffle/gbm/wgbm_platform.h b/src/waffle/gbm/wgbm_platform.h
index 259eb19..1a08183 100644
--- a/src/waffle/gbm/wgbm_platform.h
+++ b/src/waffle/gbm/wgbm_platform.h
@@ -34,6 +34,24 @@
#include "wegl_platform.h"
#include "wcore_util.h"
+#define GBM_FUNCTIONS(f) \
+ f(struct gbm_device * , gbm_create_device , (int fd)) \
+ f(int , gbm_device_get_fd , (struct gbm_device *dev)) \
+ f(void , gbm_device_destroy , (struct gbm_device *gbm)) \
+ f(struct gbm_surface *, gbm_surface_create , (struct gbm_device *gbm, uint32_t width, uint32_t height, uint32_t format, uint32_t flags)) \
+ f(void , gbm_surface_destroy , (struct gbm_surface *surface)) \
+ f(struct gbm_bo * , gbm_surface_lock_front_buffer, (struct gbm_surface *surface)) \
+ f(void , gbm_surface_release_buffer , (struct gbm_surface *surface, struct gbm_bo *bo)) \
+ f(struct gbm_bo * , gbm_bo_create , (struct gbm_device *gbm, uint32_t width, uint32_t height, uint32_t format, uint32_t flags)) \
+ f(void , gbm_bo_destroy , (struct gbm_bo *bo)) \
+ f(int , gbm_bo_get_fd , (struct gbm_bo *bo)) \
+ f(uint32_t , gbm_bo_get_width , (struct gbm_bo *bo)) \
+ f(uint32_t , gbm_bo_get_height , (struct gbm_bo *bo)) \
+ f(uint32_t , gbm_bo_get_stride , (struct gbm_bo *bo)) \
+ f(uint32_t , gbm_bo_get_format , (struct gbm_bo *bo)) \
+ f(union gbm_bo_handle , gbm_bo_get_handle , (struct gbm_bo *bo)) \
+ f(struct gbm_device * , gbm_bo_get_device , (struct gbm_bo *bo))
+
struct linux_platform;
struct wgbm_platform {
@@ -43,18 +61,9 @@ struct wgbm_platform {
// 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 DECLARE(type, function, args) type (*function) args;
+ GBM_FUNCTIONS(DECLARE)
+#undef DECLARE
};
DEFINE_CONTAINER_CAST_FUNC(wgbm_platform,
@@ -62,5 +71,23 @@ DEFINE_CONTAINER_CAST_FUNC(wgbm_platform,
struct wegl_platform,
wegl)
+bool
+wgbm_platform_init(struct wgbm_platform *self);
+
+bool
+wgbm_platform_teardown(struct wgbm_platform *self);
+
struct wcore_platform*
wgbm_platform_create(void);
+
+bool
+wgbm_platform_destroy(struct wcore_platform *wc_self);
+
+bool
+wgbm_dl_can_open(struct wcore_platform *wc_self,
+ int32_t waffle_dl);
+
+void*
+wgbm_dl_sym(struct wcore_platform *wc_self,
+ int32_t waffle_dl,
+ const char *name);
--
2.2.0.rc0.207.ga3a616c
More information about the waffle
mailing list