... by using the function pointers retrieved via dlsym() at wegl_platform_init() time. This effectively allows waffle to be distributed on systems that lack the library.
Signed-off-by: Emil Velikov <emil.l.veli...@gmail.com> --- .../Modules/WafflePrintConfigurationSummary.cmake | 1 - src/waffle/CMakeLists.txt | 1 - src/waffle/egl/wegl_config.c | 8 ++++--- src/waffle/egl/wegl_context.c | 26 +++++++++++++--------- src/waffle/egl/wegl_display.c | 22 ++++++++++-------- src/waffle/egl/wegl_util.c | 25 ++++++++++++--------- src/waffle/egl/wegl_util.h | 3 ++- src/waffle/egl/wegl_window.c | 23 +++++++++++-------- src/waffle/xegl/xegl_window.c | 12 +++++----- 9 files changed, 70 insertions(+), 51 deletions(-) diff --git a/cmake/Modules/WafflePrintConfigurationSummary.cmake b/cmake/Modules/WafflePrintConfigurationSummary.cmake index 2b66fae..79f7b38 100644 --- a/cmake/Modules/WafflePrintConfigurationSummary.cmake +++ b/cmake/Modules/WafflePrintConfigurationSummary.cmake @@ -48,7 +48,6 @@ message("") message("Dependencies:") if(waffle_has_egl) message(" egl_INCLUDE_DIRS: ${egl_INCLUDE_DIRS}") - message(" egl_LDFLAGS: ${egl_LDFLAGS}") endif() if(waffle_has_glx) message(" gl_INCLUDE_DIRS: ${gl_INCLUDE_DIRS}") diff --git a/src/waffle/CMakeLists.txt b/src/waffle/CMakeLists.txt index b7612e5..9b89a17 100644 --- a/src/waffle/CMakeLists.txt +++ b/src/waffle/CMakeLists.txt @@ -33,7 +33,6 @@ include_directories( # ---------------------------------------------------------------------------- set(waffle_libdeps - ${egl_LDFLAGS} ${gbm_LDFLAGS} ${gl_LDFLAGS} ${libudev_LDFLAGS} diff --git a/src/waffle/egl/wegl_config.c b/src/waffle/egl/wegl_config.c index 5dbe1b6..db3d3c9 100644 --- a/src/waffle/egl/wegl_config.c +++ b/src/waffle/egl/wegl_config.c @@ -33,6 +33,7 @@ #include "wegl_config.h" #include "wegl_display.h" #include "wegl_imports.h" +#include "wegl_platform.h" #include "wegl_util.h" /// @brief Check the WAFFLE_CONTEXT_* attributes. @@ -129,6 +130,7 @@ static EGLConfig choose_real_config(struct wegl_display *dpy, const struct wcore_config_attrs *attrs) { + struct wegl_platform *plat = wegl_platform(dpy->wcore.platform); EGLConfig config = NULL; bool ok = true; @@ -189,10 +191,10 @@ choose_real_config(struct wegl_display *dpy, } EGLint num_configs = 0; - ok &= eglChooseConfig(dpy->egl, - attrib_list, &config, 1, &num_configs); + ok &= plat->eglChooseConfig(dpy->egl, + attrib_list, &config, 1, &num_configs); if (!ok) { - wegl_emit_error("eglChooseConfig"); + wegl_emit_error(plat, "eglChooseConfig"); return NULL; } else if (num_configs == 0) { diff --git a/src/waffle/egl/wegl_context.c b/src/waffle/egl/wegl_context.c index abd6129..ba7d426 100644 --- a/src/waffle/egl/wegl_context.c +++ b/src/waffle/egl/wegl_context.c @@ -31,21 +31,22 @@ #include "wegl_config.h" #include "wegl_context.h" #include "wegl_imports.h" +#include "wegl_platform.h" #include "wegl_util.h" static bool -bind_api(int32_t waffle_context_api) +bind_api(struct wegl_platform *plat, int32_t waffle_context_api) { bool ok = true; switch (waffle_context_api) { case WAFFLE_CONTEXT_OPENGL: - ok &= eglBindAPI(EGL_OPENGL_API); + ok &= plat->eglBindAPI(EGL_OPENGL_API); break; case WAFFLE_CONTEXT_OPENGL_ES1: case WAFFLE_CONTEXT_OPENGL_ES2: case WAFFLE_CONTEXT_OPENGL_ES3: - ok &= eglBindAPI(EGL_OPENGL_ES_API); + ok &= plat->eglBindAPI(EGL_OPENGL_ES_API); break; default: wcore_error_internal("waffle_context_api has bad value #x%x", @@ -54,7 +55,7 @@ bind_api(int32_t waffle_context_api) } if (!ok) - wegl_emit_error("eglBindAPI"); + wegl_emit_error(plat, "eglBindAPI"); return ok; } @@ -65,6 +66,7 @@ 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; @@ -142,14 +144,14 @@ create_real_context(struct wegl_config *config, attrib_list[i++] = EGL_NONE; - ok = bind_api(waffle_context_api); + ok = bind_api(plat, waffle_context_api); if (!ok) return false; - EGLContext ctx = eglCreateContext(dpy->egl, config->egl, - share_ctx, attrib_list); + EGLContext ctx = plat->eglCreateContext(dpy->egl, config->egl, + share_ctx, attrib_list); if (!ctx) - wegl_emit_error("eglCreateContext"); + wegl_emit_error(plat, "eglCreateContext"); return ctx; } @@ -189,6 +191,8 @@ fail: bool wegl_context_destroy(struct wcore_context *wc_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; @@ -198,10 +202,10 @@ wegl_context_destroy(struct wcore_context *wc_ctx) ctx = wegl_context(wc_ctx); if (ctx->egl) { - bool ok = eglDestroyContext(wegl_display(wc_ctx->display)->egl, - ctx->egl); + bool ok = plat->eglDestroyContext(wegl_display(wc_ctx->display)->egl, + ctx->egl); if (!ok) { - wegl_emit_error("eglDestroyContext"); + wegl_emit_error(plat, "eglDestroyContext"); result = false; } } diff --git a/src/waffle/egl/wegl_display.c b/src/waffle/egl/wegl_display.c index 0716a32..1ca55e3 100644 --- a/src/waffle/egl/wegl_display.c +++ b/src/waffle/egl/wegl_display.c @@ -31,14 +31,16 @@ #include "wegl_display.h" #include "wegl_imports.h" #include "wegl_util.h" +#include "wegl_platform.h" static bool get_extensions(struct wegl_display *dpy) { - const char *extensions = eglQueryString(dpy->egl, EGL_EXTENSIONS); + struct wegl_platform *plat = wegl_platform(dpy->wcore.platform); + const char *extensions = plat->eglQueryString(dpy->egl, EGL_EXTENSIONS); if (!extensions) { - wegl_emit_error("eglQueryString(EGL_EXTENSIONS"); + wegl_emit_error(plat, "eglQueryString(EGL_EXTENSIONS"); return false; } @@ -59,6 +61,7 @@ wegl_display_init(struct wegl_display *dpy, struct wcore_platform *wc_plat, intptr_t native_display) { + struct wegl_platform *plat = wegl_platform(wc_plat); bool ok; EGLint major, minor; @@ -66,21 +69,21 @@ wegl_display_init(struct wegl_display *dpy, if (!ok) goto fail; - dpy->egl = eglGetDisplay((EGLNativeDisplayType) native_display); + dpy->egl = plat->eglGetDisplay((EGLNativeDisplayType) native_display); if (!dpy->egl) { - wegl_emit_error("eglGetDisplay"); + wegl_emit_error(plat, "eglGetDisplay"); goto fail; } - ok = eglInitialize(dpy->egl, &major, &minor); + ok = plat->eglInitialize(dpy->egl, &major, &minor); if (!ok) { - wegl_emit_error("eglInitialize"); + wegl_emit_error(plat, "eglInitialize"); goto fail; } ok = get_extensions(dpy); if (!ok) - goto fail; + goto fail; return true; @@ -92,12 +95,13 @@ fail: bool wegl_display_teardown(struct wegl_display *dpy) { + struct wegl_platform *plat = wegl_platform(dpy->wcore.platform); bool ok = true; if (dpy->egl) { - ok = eglTerminate(dpy->egl); + ok = plat->eglTerminate(dpy->egl); if (!ok) - wegl_emit_error("eglTerminate"); + wegl_emit_error(plat, "eglTerminate"); } return ok; diff --git a/src/waffle/egl/wegl_util.c b/src/waffle/egl/wegl_util.c index eb2415b..81fdbd9 100644 --- a/src/waffle/egl/wegl_util.c +++ b/src/waffle/egl/wegl_util.c @@ -28,13 +28,14 @@ #include "wegl_context.h" #include "wegl_display.h" #include "wegl_imports.h" +#include "wegl_platform.h" #include "wegl_util.h" #include "wegl_window.h" void -wegl_emit_error(const char *egl_func_call) +wegl_emit_error(struct wegl_platform *plat, const char *egl_func_call) { - EGLint egl_error_code = eglGetError(); + EGLint egl_error_code = plat->eglGetError(); const char *egl_error_name; switch (egl_error_code) { @@ -74,17 +75,18 @@ wegl_make_current(struct wcore_platform *wc_plat, struct wcore_window *wc_window, struct wcore_context *wc_ctx) { - bool ok; + struct wegl_platform *plat = wegl_platform(wc_plat); EGLSurface surface = wc_window ? wegl_window(wc_window)->egl : NULL; + bool ok; - ok = eglMakeCurrent(wegl_display(wc_dpy)->egl, - surface, - surface, - wc_ctx - ? wegl_context(wc_ctx)->egl - : NULL); + ok = plat->eglMakeCurrent(wegl_display(wc_dpy)->egl, + surface, + surface, + wc_ctx + ? wegl_context(wc_ctx)->egl + : NULL); if (!ok) - wegl_emit_error("eglMakeCurrent"); + wegl_emit_error(plat, "eglMakeCurrent"); return ok; } @@ -92,5 +94,6 @@ wegl_make_current(struct wcore_platform *wc_plat, void* wegl_get_proc_address(struct wcore_platform *wc_self, const char *name) { - return eglGetProcAddress(name); + struct wegl_platform *self = wegl_platform(wc_self); + return self->eglGetProcAddress(name); } diff --git a/src/waffle/egl/wegl_util.h b/src/waffle/egl/wegl_util.h index 772f71d..bb1692f 100644 --- a/src/waffle/egl/wegl_util.h +++ b/src/waffle/egl/wegl_util.h @@ -33,12 +33,13 @@ struct wcore_context; struct wcore_display; struct wcore_window; +struct wegl_platform; /// @brief Sets the waffle error with info from eglGetError(). /// @param egl_func_call Examples are "eglMakeCurrent()" and /// "eglBindAPI(EGL_OPENGL_API)". void -wegl_emit_error(const char *egl_func_call); +wegl_emit_error(struct wegl_platform *plat, const char *egl_func_call); bool wegl_make_current(struct wcore_platform *wc_plat, diff --git a/src/waffle/egl/wegl_window.c b/src/waffle/egl/wegl_window.c index e16b61d..753fd2f 100644 --- a/src/waffle/egl/wegl_window.c +++ b/src/waffle/egl/wegl_window.c @@ -26,6 +26,7 @@ #include "wegl_config.h" #include "wegl_display.h" #include "wegl_imports.h" +#include "wegl_platform.h" #include "wegl_util.h" #include "wegl_window.h" @@ -38,6 +39,7 @@ wegl_window_init(struct wegl_window *window, { struct wegl_config *config = wegl_config(wc_config); struct wegl_display *dpy = wegl_display(wc_config->display); + struct wegl_platform *plat = wegl_platform(dpy->wcore.platform); EGLint egl_render_buffer; bool ok; @@ -55,12 +57,13 @@ wegl_window_init(struct wegl_window *window, EGL_NONE, }; - window->egl = eglCreateWindowSurface(dpy->egl, - config->egl, - (EGLNativeWindowType) native_window, - attrib_list); + window->egl = plat->eglCreateWindowSurface(dpy->egl, + config->egl, + (EGLNativeWindowType) + native_window, + attrib_list); if (!window->egl) { - wegl_emit_error("eglCreateWindowSurface"); + wegl_emit_error(plat, "eglCreateWindowSurface"); goto fail; } @@ -75,12 +78,13 @@ bool wegl_window_teardown(struct wegl_window *window) { struct wegl_display *dpy = wegl_display(window->wcore.display); + struct wegl_platform *plat = wegl_platform(dpy->wcore.platform); bool result = true; if (window->egl) { - bool ok = eglDestroySurface(dpy->egl, window->egl); + bool ok = plat->eglDestroySurface(dpy->egl, window->egl); if (!ok) { - wegl_emit_error("eglDestroySurface"); + wegl_emit_error(plat, "eglDestroySurface"); result = false; } } @@ -94,10 +98,11 @@ wegl_window_swap_buffers(struct wcore_window *wc_window) { struct wegl_window *window = wegl_window(wc_window); struct wegl_display *dpy = wegl_display(window->wcore.display); + struct wegl_platform *plat = wegl_platform(dpy->wcore.platform); - bool ok = eglSwapBuffers(dpy->egl, window->egl); + bool ok = plat->eglSwapBuffers(dpy->egl, window->egl); if (!ok) - wegl_emit_error("eglSwapBuffers"); + wegl_emit_error(plat, "eglSwapBuffers"); return ok; } diff --git a/src/waffle/xegl/xegl_window.c b/src/waffle/xegl/xegl_window.c index 5fcadda..ce638b4 100644 --- a/src/waffle/xegl/xegl_window.c +++ b/src/waffle/xegl/xegl_window.c @@ -31,6 +31,7 @@ #include "wcore_error.h" #include "wegl_config.h" +#include "wegl_platform.h" #include "wegl_util.h" #include "xegl_display.h" @@ -60,6 +61,7 @@ xegl_window_create(struct wcore_platform *wc_plat, struct xegl_window *self; struct xegl_display *dpy = xegl_display(wc_config->display); struct wegl_config *config = wegl_config(wc_config); + struct wegl_platform *plat = wegl_platform(wc_plat); xcb_visualid_t visual; bool ok = true; @@ -67,12 +69,12 @@ xegl_window_create(struct wcore_platform *wc_plat, if (self == NULL) return NULL; - ok = eglGetConfigAttrib(dpy->wegl.egl, - config->egl, - EGL_NATIVE_VISUAL_ID, - (EGLint*) &visual); + ok = plat->eglGetConfigAttrib(dpy->wegl.egl, + config->egl, + EGL_NATIVE_VISUAL_ID, + (EGLint*) &visual); if (!ok) { - wegl_emit_error("eglGetConfigAttrib(EGL_NATIVE_VISUAL_ID)"); + wegl_emit_error(plat, "eglGetConfigAttrib(EGL_NATIVE_VISUAL_ID)"); goto error; } -- 2.0.2 _______________________________________________ waffle mailing list waffle@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/waffle