diff options
author | Chad Versace <chad.versace@intel.com> | 2015-04-09 15:06:46 -0700 |
---|---|---|
committer | Chad Versace <chad.versace@intel.com> | 2015-04-09 15:06:46 -0700 |
commit | 40f248cc909c681a278f7555cfeb0c4599200d34 (patch) | |
tree | 6fb28c3ff523515ea9dc151574b94d7a516b16ce | |
parent | b5c04d422e6f085df7d7f3324441bf832b354893 (diff) | |
parent | 038b1dbc184054382bc89f197cf7c7811aeed5a3 (diff) | |
download | waffle-40f248cc909c681a278f7555cfeb0c4599200d34.tar.gz |
Merge branch 'master' into next
* master:
gbm: wegl_display ok in wgbm_config_get_gbm_format
wegl: add EGL image create/destroy
wegl: fix wegl_util.h includes and declarations
gbm: make wgbm_get_default_fd_for_pattern public
gbm: make platform friendlier to derived classes
wegl: enable deriving from wegl_context (v2)
-rw-r--r-- | src/waffle/egl/wegl_context.c | 84 | ||||
-rw-r--r-- | src/waffle/egl/wegl_context.h | 10 | ||||
-rw-r--r-- | src/waffle/egl/wegl_platform.c | 9 | ||||
-rw-r--r-- | src/waffle/egl/wegl_platform.h | 4 | ||||
-rw-r--r-- | src/waffle/egl/wegl_util.h | 5 | ||||
-rw-r--r-- | src/waffle/gbm/wgbm_config.c | 4 | ||||
-rw-r--r-- | src/waffle/gbm/wgbm_display.c | 2 | ||||
-rw-r--r-- | src/waffle/gbm/wgbm_display.h | 3 | ||||
-rw-r--r-- | src/waffle/gbm/wgbm_platform.c | 58 | ||||
-rw-r--r-- | src/waffle/gbm/wgbm_platform.h | 51 |
10 files changed, 154 insertions, 76 deletions
diff --git a/src/waffle/egl/wegl_context.c b/src/waffle/egl/wegl_context.c index 2aec0dd..f4ee6cd 100644 --- a/src/waffle/egl/wegl_context.c +++ b/src/waffle/egl/wegl_context.c @@ -68,7 +68,6 @@ create_real_context(struct wegl_config *config, struct wegl_display *dpy = wegl_display(config->wcore.display); struct wegl_platform *plat = wegl_platform(dpy->wcore.platform); struct wcore_config_attrs *attrs = &config->wcore.attrs; - bool ok = true; int32_t waffle_context_api = attrs->context_api; EGLint attrib_list[64]; EGLint context_flags = 0; @@ -144,9 +143,8 @@ create_real_context(struct wegl_config *config, attrib_list[i++] = EGL_NONE; - ok = bind_api(plat, waffle_context_api); - if (!ok) - return false; + if (!bind_api(plat, waffle_context_api)) + return EGL_NO_CONTEXT; EGLContext ctx = plat->eglCreateContext(dpy->egl, config->egl, share_ctx, attrib_list); @@ -156,22 +154,15 @@ create_real_context(struct wegl_config *config, return ctx; } -struct wcore_context* -wegl_context_create(struct wcore_platform *wc_plat, - struct wcore_config *wc_config, - struct wcore_context *wc_share_ctx) +bool +wegl_context_init(struct wegl_context *ctx, + struct wcore_config *wc_config, + struct wcore_context *wc_share_ctx) { - struct wegl_context *ctx; struct wegl_config *config = wegl_config(wc_config); struct wegl_context *share_ctx = wegl_context(wc_share_ctx); bool ok; - (void) wc_plat; - - ctx = wcore_calloc(sizeof(*ctx)); - if (!ctx) - return NULL; - ok = wcore_context_init(&ctx->wcore, &config->wcore); if (!ok) goto fail; @@ -179,40 +170,69 @@ wegl_context_create(struct wcore_platform *wc_plat, ctx->egl = create_real_context(config, share_ctx ? share_ctx->egl - : NULL); - if (!ctx->egl) + : EGL_NO_CONTEXT); + if (ctx->egl == EGL_NO_CONTEXT) goto fail; - return &ctx->wcore; + return true; fail: - wegl_context_destroy(&ctx->wcore); - return NULL; + wegl_context_teardown(ctx); + return false; } -bool -wegl_context_destroy(struct wcore_context *wc_ctx) +struct wcore_context* +wegl_context_create(struct wcore_platform *wc_plat, + struct wcore_config *wc_config, + struct wcore_context *wc_share_ctx) { - struct wegl_display *dpy = wegl_display(wc_ctx->display); - struct wegl_platform *plat = wegl_platform(dpy->wcore.platform); struct wegl_context *ctx; + + (void) wc_plat; + + ctx = wcore_calloc(sizeof(*ctx)); + if (!ctx) + return NULL; + + if (!wegl_context_init(ctx, wc_config, wc_share_ctx)) { + wegl_context_destroy(&ctx->wcore); + return NULL; + } + + return &ctx->wcore; +} + +bool +wegl_context_teardown(struct wegl_context *ctx) +{ bool result = true; - if (!wc_ctx) + if (!ctx) return result; - ctx = wegl_context(wc_ctx); + if (ctx->egl != EGL_NO_CONTEXT) { + struct wegl_display *dpy = wegl_display(ctx->wcore.display); + struct wegl_platform *plat = wegl_platform(dpy->wcore.platform); - if (ctx->egl) { - bool ok = plat->eglDestroyContext(wegl_display(wc_ctx->display)->egl, - ctx->egl); - if (!ok) { + if (!plat->eglDestroyContext(dpy->egl, ctx->egl)) { wegl_emit_error(plat, "eglDestroyContext"); result = false; } } - result &= wcore_context_teardown(wc_ctx); - free(ctx); + result &= wcore_context_teardown(&ctx->wcore); + return result; +} + +bool +wegl_context_destroy(struct wcore_context *wc_ctx) +{ + bool result = true; + + if (wc_ctx) { + struct wegl_context *ctx = wegl_context(wc_ctx); + result = wegl_context_teardown(ctx); + free(ctx); + } return result; } diff --git a/src/waffle/egl/wegl_context.h b/src/waffle/egl/wegl_context.h index 3583d61..b7d4d6a 100644 --- a/src/waffle/egl/wegl_context.h +++ b/src/waffle/egl/wegl_context.h @@ -33,8 +33,6 @@ #include "wcore_context.h" #include "wcore_util.h" -struct wegl_display; - struct wegl_context { struct wcore_context wcore; EGLContext egl; @@ -45,6 +43,14 @@ DEFINE_CONTAINER_CAST_FUNC(wegl_context, struct wcore_context, wcore) +bool +wegl_context_init(struct wegl_context *ctx, + struct wcore_config *wc_config, + struct wcore_context *wc_share_ctx); + +bool +wegl_context_teardown(struct wegl_context *ctx); + struct wcore_context* wegl_context_create(struct wcore_platform *wc_plat, struct wcore_config *wc_config, diff --git a/src/waffle/egl/wegl_platform.c b/src/waffle/egl/wegl_platform.c index 800025e..0c9eb44 100644 --- a/src/waffle/egl/wegl_platform.c +++ b/src/waffle/egl/wegl_platform.c @@ -72,8 +72,11 @@ wegl_platform_init(struct wegl_platform *self) goto error; } +#define OPTIONAL_EGL_SYMBOL(function) \ + self->function = dlsym(self->eglHandle, #function); + #define RETRIEVE_EGL_SYMBOL(function) \ - self->function = dlsym(self->eglHandle, #function); \ + OPTIONAL_EGL_SYMBOL(function) \ if (!self->function) { \ wcore_errorf(WAFFLE_ERROR_FATAL, \ "dlsym(\"%s\", \"" #function "\") failed: %s", \ @@ -82,6 +85,9 @@ wegl_platform_init(struct wegl_platform *self) goto error; \ } + OPTIONAL_EGL_SYMBOL(eglCreateImageKHR); + OPTIONAL_EGL_SYMBOL(eglDestroyImageKHR); + RETRIEVE_EGL_SYMBOL(eglMakeCurrent); RETRIEVE_EGL_SYMBOL(eglGetProcAddress); @@ -106,6 +112,7 @@ wegl_platform_init(struct wegl_platform *self) RETRIEVE_EGL_SYMBOL(eglDestroySurface); RETRIEVE_EGL_SYMBOL(eglSwapBuffers); +#undef OPTIONAL_EGL_SYMBOL #undef RETRIEVE_EGL_SYMBOL error: diff --git a/src/waffle/egl/wegl_platform.h b/src/waffle/egl/wegl_platform.h index 645c3f8..7ae0490 100644 --- a/src/waffle/egl/wegl_platform.h +++ b/src/waffle/egl/wegl_platform.h @@ -26,6 +26,7 @@ #pragma once #include <EGL/egl.h> +#include <EGL/eglext.h> #include "wcore_platform.h" #include "wcore_util.h" @@ -68,6 +69,9 @@ struct wegl_platform { const EGLint *attrib_list); EGLBoolean (*eglDestroySurface)(EGLDisplay dpy, EGLSurface surface); EGLBoolean (*eglSwapBuffers)(EGLDisplay dpy, EGLSurface surface); + + EGLImageKHR (*eglCreateImageKHR) (EGLDisplay dpy, EGLContext ctx, EGLenum target, EGLClientBuffer buffer, const EGLint *attrib_list); + EGLBoolean (*eglDestroyImageKHR)(EGLDisplay dpy, EGLImageKHR image); }; DEFINE_CONTAINER_CAST_FUNC(wegl_platform, diff --git a/src/waffle/egl/wegl_util.h b/src/waffle/egl/wegl_util.h index bb1692f..f535930 100644 --- a/src/waffle/egl/wegl_util.h +++ b/src/waffle/egl/wegl_util.h @@ -26,13 +26,12 @@ #pragma once #include <stdbool.h> -#include <stdint.h> - -#include <EGL/egl.h> struct wcore_context; struct wcore_display; +struct wcore_platform; struct wcore_window; + struct wegl_platform; /// @brief Sets the waffle error with info from eglGetError(). diff --git a/src/waffle/gbm/wgbm_config.c b/src/waffle/gbm/wgbm_config.c index 67470d5..1d64b71 100644 --- a/src/waffle/gbm/wgbm_config.c +++ b/src/waffle/gbm/wgbm_config.c @@ -55,10 +55,10 @@ wgbm_config_get_gbm_format(struct wcore_platform *wc_plat, struct wcore_config *wc_config) { EGLint gbm_format; - struct wgbm_display *dpy = wgbm_display(wc_display); + struct wegl_display *dpy = wegl_display(wc_display); struct wegl_platform *plat = wegl_platform(wc_plat); struct wegl_config *egl_config = wegl_config(wc_config); - bool ok = plat->eglGetConfigAttrib(dpy->wegl.egl, + bool ok = plat->eglGetConfigAttrib(dpy->egl, egl_config->egl, EGL_NATIVE_VISUAL_ID, &gbm_format); diff --git a/src/waffle/gbm/wgbm_display.c b/src/waffle/gbm/wgbm_display.c index 76e6c32..b46524a 100644 --- a/src/waffle/gbm/wgbm_display.c +++ b/src/waffle/gbm/wgbm_display.c @@ -65,7 +65,7 @@ wgbm_display_destroy(struct wcore_display *wc_self) return ok; } -static int +int wgbm_get_default_fd_for_pattern(const char *pattern) { struct udev *ud; diff --git a/src/waffle/gbm/wgbm_display.h b/src/waffle/gbm/wgbm_display.h index ba4bb89..e19664a 100644 --- a/src/waffle/gbm/wgbm_display.h +++ b/src/waffle/gbm/wgbm_display.h @@ -65,3 +65,6 @@ wgbm_display_get_native(struct wcore_display *wc_self); void wgbm_display_fill_native(struct wgbm_display *self, struct waffle_gbm_display *n_dpy); + +int +wgbm_get_default_fd_for_pattern(const char *pattern); 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); |