From 793d5888769a7351fc699a31f6caa73bcbcbe338 Mon Sep 17 00:00:00 2001 From: Jari Vetoniemi Date: Sun, 11 Mar 2018 18:24:08 +0200 Subject: android/EGL: Mark ANativeWindow w/ header Remove eglGetDisplay as it's called with NULL anyways (Reimplement if otherwise in some app) In eglCreateWindowSurface, check that our pointer really is ANativeWindow, otherwise try use it as is. --- src/libEGL.c | 13 +++---------- src/libandroid.c | 4 ++++ 2 files changed, 7 insertions(+), 10 deletions(-) diff --git a/src/libEGL.c b/src/libEGL.c index 45e8ffb..f2d9585 100644 --- a/src/libEGL.c +++ b/src/libEGL.c @@ -1,28 +1,21 @@ #include +#include #include -#define GLFW_INCLUDE_NONE #include #define GLFW_EXPOSE_NATIVE_X11 #include struct ANativeWindow { + char header[4]; GLFWwindow *glfw; }; -EGLDisplay -eglGetDisplay(EGLNativeDisplayType native_display) -{ - static union { EGLDisplay (*fun)(EGLNativeDisplayType); void *ptr; } orig; - if (!orig.ptr) orig.ptr = dlsym(RTLD_NEXT, "eglGetDisplay"); - return orig.fun(glfwGetX11Display()); -} - EGLSurface eglCreateWindowSurface(EGLDisplay display, EGLConfig config, NativeWindowType native_window, EGLint const *attrib_list) { static union { EGLSurface (*fun)(EGLDisplay, EGLConfig, NativeWindowType, EGLint const*); void *ptr; } orig; if (!orig.ptr) orig.ptr = dlsym(RTLD_NEXT, "eglCreateWindowSurface"); struct ANativeWindow *window = (struct ANativeWindow*)native_window; - return orig.fun(display, config, glfwGetX11Window(window->glfw), attrib_list); + return orig.fun(display, config, (!memcmp(window->header, "andr", sizeof(window->header)) ? glfwGetX11Window(window->glfw) : native_window), attrib_list); } diff --git a/src/libandroid.c b/src/libandroid.c index 1d677ae..eff3b3a 100644 --- a/src/libandroid.c +++ b/src/libandroid.c @@ -2,6 +2,7 @@ #include #include #include +#include #include #define GLFW_INCLUDE_NONE @@ -428,6 +429,7 @@ AInputQueue_finishEvent(struct AInputQueue *queue, struct AInputEvent *event, in // ANative struct ANativeWindow { + char header[4]; GLFWwindow *glfw; }; @@ -477,6 +479,8 @@ ANativeWindow_fromSurface(JNIEnv* env, jobject surface) if (!(window = calloc(1, sizeof(*window)))) return NULL; + memcpy(window->header, "andr", sizeof(window->header)); + glfwInit(); fprintf(stderr, "glfw: %s\n", glfwGetVersionString()); glfwSetErrorCallback(glfw_error_cb); -- cgit v1.2.3-70-g09d2