Re: [waffle] [PATCH v3 2/3] wcore: rework non-compatible mutex initialization
On 27/03/15 23:28, Emil Velikov wrote: C11 does not specify a static initializer, based on the idea that the a mutex will be platform and/or implementation dependent. As such the alternative solution is to initialize the mutex with call_once/mtx_init. This will allow us to remove the transition hack, and in due time move to the system's C11 threads implementation. v2: Actually use call_once() to prevent the possibility of multiple threads hitting the mtx_init() at the same time. Suggested by Jose. v3: Do not destroy the mutex. Suggested by Chad. Cc: Jose Fonseca jfons...@vmware.com Signed-off-by: Emil Velikov emil.l.veli...@gmail.com --- src/waffle/core/wcore_display.c | 11 ++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/waffle/core/wcore_display.c b/src/waffle/core/wcore_display.c index 2feeeba..40f98cf 100644 --- a/src/waffle/core/wcore_display.c +++ b/src/waffle/core/wcore_display.c @@ -29,16 +29,25 @@ #include wcore_display.h +static mtx_t mutex; + +static void +wcore_display_init_once(void) +{ +mtx_init(mutex, mtx_plain); +} + bool wcore_display_init(struct wcore_display *self, struct wcore_platform *platform) { static size_t id_counter = 0; -static mtx_t mutex = _MTX_INITIALIZER_NP; +static once_flag flag = ONCE_FLAG_INIT; assert(self); assert(platform); +call_once(flag, wcore_display_init_once); mtx_lock(mutex); self-api.display_id = ++id_counter; mtx_unlock(mutex); Reviewed-by: Jose Fonseca jfons...@vmware.com ___ waffle mailing list waffle@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/waffle
[waffle] [PATCH 08/10] wflinfo: add 'null' platform
Signed-off-by: Frank Henigman fjhenig...@google.com --- src/utils/wflinfo.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/utils/wflinfo.c b/src/utils/wflinfo.c index 268d4b8..0a58aab 100644 --- a/src/utils/wflinfo.c +++ b/src/utils/wflinfo.c @@ -62,7 +62,7 @@ static const char *usage_message = \n Required Parameters:\n -p, --platform\n -One of: android, cgl, gbm, glx, wayland, wgl or x11_egl\n +One of: android, cgl, gbm, glx, null, wayland, wgl or x11_egl\n \n -a, --api\n One of: gl, gles1, gles2 or gles3\n @@ -267,6 +267,7 @@ static const struct enum_map platform_map[] = { {WAFFLE_PLATFORM_CGL, cgl, }, {WAFFLE_PLATFORM_GBM, gbm }, {WAFFLE_PLATFORM_GLX, glx }, +{WAFFLE_PLATFORM_NULL, null }, {WAFFLE_PLATFORM_WAYLAND, wayland }, {WAFFLE_PLATFORM_WGL, wgl }, {WAFFLE_PLATFORM_X11_EGL, x11_egl }, -- 2.2.0.rc0.207.ga3a616c ___ waffle mailing list waffle@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/waffle
[waffle] [PATCH 05/10] wegl: add EGL image create/destroy
From: Frank Henigman fjhenig...@gmail.com Store EGLImageCreateKHR and EGLImageDestroyKHR in the EGL platform struct. Signed-off-by: Frank Henigman fjhenig...@google.com --- src/waffle/egl/wegl_platform.c | 9 - src/waffle/egl/wegl_platform.h | 4 2 files changed, 12 insertions(+), 1 deletion(-) 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, -- 2.2.0.rc0.207.ga3a616c ___ waffle mailing list waffle@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/waffle
[waffle] [PATCH 06/10] gbm: wegl_display ok in wgbm_config_get_gbm_format
From: Frank Henigman fjhenig...@gmail.com wgbm_config_get_gbm_format() does not need to cast the display all the way to wgbm_display; wegl_display is far enough. Now wgbm_config_get_gbm_format() can be used outside of the gbm platform. Signed-off-by: Frank Henigman fjhenig...@google.com --- src/waffle/gbm/wgbm_config.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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); -- 2.2.0.rc0.207.ga3a616c ___ waffle mailing list waffle@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/waffle
[waffle] [PATCH 01/10] wegl: enable deriving from wegl_context
Factor out init and teardown functions from create and destroy so a derived class can use them on its embedded wegl_context object. Signed-off-by: Frank Henigman fjhenig...@google.com --- src/waffle/egl/wegl_context.c | 79 +++ src/waffle/egl/wegl_context.h | 10 -- 2 files changed, 57 insertions(+), 32 deletions(-) diff --git a/src/waffle/egl/wegl_context.c b/src/waffle/egl/wegl_context.c index 2aec0dd..0f4c784 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,68 @@ 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_teardown(ctx); +return false; +} + +struct wcore_context* +wegl_context_create(struct wcore_platform *wc_plat, +struct wcore_config *wc_config, +struct wcore_context *wc_share_ctx) +{ +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)) +return ctx-wcore; + wegl_context_destroy(ctx-wcore); return NULL; } bool -wegl_context_destroy(struct wcore_context *wc_ctx) +wegl_context_teardown(struct wegl_context *ctx) { -struct wegl_display *dpy = wegl_display(wc_ctx-display); -struct wegl_platform *plat = wegl_platform(dpy-wcore.platform); -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
[waffle] [PATCH 02/10] gbm: make platform friendlier to derived classes
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 fjhenig...@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
[waffle] [PATCH 09/10] gl_basic: add 'null' platform
Signed-off-by: Frank Henigman fjhenig...@google.com --- examples/gl_basic.c | 1 + 1 file changed, 1 insertion(+) diff --git a/examples/gl_basic.c b/examples/gl_basic.c index 8f59d21..ab9c78c 100644 --- a/examples/gl_basic.c +++ b/examples/gl_basic.c @@ -243,6 +243,7 @@ static const struct enum_map platform_map[] = { {WAFFLE_PLATFORM_CGL, cgl, }, {WAFFLE_PLATFORM_GBM, gbm }, {WAFFLE_PLATFORM_GLX, glx }, +{WAFFLE_PLATFORM_NULL, null }, {WAFFLE_PLATFORM_WAYLAND, wayland }, {WAFFLE_PLATFORM_WGL, wgl }, {WAFFLE_PLATFORM_X11_EGL, x11_egl }, -- 2.2.0.rc0.207.ga3a616c ___ waffle mailing list waffle@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/waffle