Commit c48776bb authored by Emil Velikov's avatar Emil Velikov Committed by Chad Versace

egl: drop explicit linking against libEGL.so

... 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.

v2: Drop the libEGL link from the Android build.
Signed-off-by: Emil Velikov's avatarEmil Velikov <emil.l.velikov@gmail.com>
Signed-off-by: default avatarChad Versace <chad.versace@linux.intel.com>
parent c89a5847
......@@ -83,7 +83,6 @@ LOCAL_SRC_FILES := \
third_party/threads/threads_posix.c
LOCAL_SHARED_LIBRARIES := \
libEGL \
libdl \
libutils \
libgui
......
......@@ -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}")
......
......@@ -37,11 +37,6 @@ list(APPEND waffle_libdeps
)
if(waffle_on_linux)
if(waffle_has_egl)
list(APPEND waffle_libdeps
${egl_LDFLAGS}
)
endif()
if(waffle_has_glx)
list(APPEND waffle_libdeps
${gl_LDFLAGS}
......
......@@ -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) {
......
......@@ -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;
}
}
......
......@@ -31,15 +31,17 @@
#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");
return false;
wegl_emit_error(plat, "eglQueryString(EGL_EXTENSIONS");
return false;
}
// waffle_is_extension_in_string() resets the error state. That's ok,
......@@ -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;
......
......@@ -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);
}
......@@ -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,
......
......@@ -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;
}
......@@ -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;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment