diff --git a/app_pojavlauncher/src/main/jni/ctxbridges/egl_loader.c b/app_pojavlauncher/src/main/jni/ctxbridges/egl_loader.c index dcd998a79..d64e400b0 100644 --- a/app_pojavlauncher/src/main/jni/ctxbridges/egl_loader.c +++ b/app_pojavlauncher/src/main/jni/ctxbridges/egl_loader.c @@ -25,6 +25,10 @@ EGLint (*eglGetError_p) (void); EGLContext (*eglCreateContext_p) (EGLDisplay dpy, EGLConfig config, EGLContext share_list, const EGLint *attrib_list); EGLBoolean (*eglSwapInterval_p) (EGLDisplay dpy, EGLint interval); EGLSurface (*eglGetCurrentSurface_p) (EGLint readdraw); +EGLBoolean (*eglQuerySurface_p)( EGLDisplay display, + EGLSurface surface, + EGLint attribute, + EGLint * value); __eglMustCastToProperFunctionPointerType (*eglGetProcAddress_p) (const char *procname); bool dlsym_EGL() { @@ -53,5 +57,6 @@ bool dlsym_EGL() { eglSwapInterval_p = (void*) eglGetProcAddress_p("eglSwapInterval"); eglTerminate_p = (void*) eglGetProcAddress_p("eglTerminate"); eglGetCurrentSurface_p = (void*) eglGetProcAddress_p("eglGetCurrentSurface"); + eglQuerySurface_p = (void*) eglGetProcAddress_p("eglQuerySurface"); return true; } diff --git a/app_pojavlauncher/src/main/jni/ctxbridges/egl_loader.h b/app_pojavlauncher/src/main/jni/ctxbridges/egl_loader.h index 65b34dae9..4e78408e8 100644 --- a/app_pojavlauncher/src/main/jni/ctxbridges/egl_loader.h +++ b/app_pojavlauncher/src/main/jni/ctxbridges/egl_loader.h @@ -24,6 +24,10 @@ extern EGLint (*eglGetError_p) (void); extern EGLContext (*eglCreateContext_p) (EGLDisplay dpy, EGLConfig config, EGLContext share_list, const EGLint *attrib_list); extern EGLBoolean (*eglSwapInterval_p) (EGLDisplay dpy, EGLint interval); extern EGLSurface (*eglGetCurrentSurface_p) (EGLint readdraw); +extern EGLBoolean (*eglQuerySurface_p)( EGLDisplay display, + EGLSurface surface, + EGLint attribute, + EGLint * value); extern __eglMustCastToProperFunctionPointerType (*eglGetProcAddress_p) (const char *procname); bool dlsym_EGL(); diff --git a/app_pojavlauncher/src/main/jni/ctxbridges/gl_bridge.c b/app_pojavlauncher/src/main/jni/ctxbridges/gl_bridge.c index d4ca7f18a..89cc44bc7 100644 --- a/app_pojavlauncher/src/main/jni/ctxbridges/gl_bridge.c +++ b/app_pojavlauncher/src/main/jni/ctxbridges/gl_bridge.c @@ -39,6 +39,41 @@ gl_render_window_t* gl_get_current() { return currentBundle; } +static void gl4esi_get_display_dimensions(int* width, int* height) { + if(currentBundle == NULL) goto zero; + EGLSurface surface = currentBundle->surface; + // Fetch dimensions from the EGL surface - the most reliable way + EGLBoolean result_width = eglQuerySurface_p(g_EglDisplay, surface, EGL_WIDTH, width); + EGLBoolean result_height = eglQuerySurface_p(g_EglDisplay, surface, EGL_HEIGHT, height); + if(!result_width || !result_height) goto zero; + return; + + zero: + // No idea what to do, but feeding gl4es incorrect or non-initialized dimensions may be + // a bad idea. Set to zero in case of errors. + *width = 0; + *height = 0; +} + +static bool already_initialized = false; +static void gl_init_gl4es_internals() { + if(already_initialized) return; + already_initialized = true; + void* gl4es = dlopen("libgl4es_114.so", RTLD_NOLOAD); + if(gl4es == NULL) return; + void (*set_getmainfbsize)(void (*new_getMainFBSize)(int* width, int* height)); + set_getmainfbsize = dlsym(gl4es, "set_getmainfbsize"); + if(set_getmainfbsize == NULL) goto warn; + set_getmainfbsize(gl4esi_get_display_dimensions); + goto cleanup; + + warn: + printf("gl4esinternals warning: gl4es was found but internals not initialized. expect rendering issues.\n"); + cleanup: + // dlclose just decreases a ref counter, so this is fine + dlclose(gl4es); +} + gl_render_window_t* gl_init_context(gl_render_window_t *share) { gl_render_window_t* bundle = malloc(sizeof(gl_render_window_t)); memset(bundle, 0, sizeof(gl_render_window_t)); @@ -110,6 +145,11 @@ void gl_swap_surface(gl_render_window_t* bundle) { } void gl_make_current(gl_render_window_t* bundle) { + // Perform initialization here as the renderer may not be loaded when gl_init or gl_init_context is called. + // Yes, even though it is dlopened on MC startup by Pojav, due to linker namespacing weirdness + // on API 29/MIUI it may not be loaded at the point of the gl_init call in the current namespace. + gl_init_gl4es_internals(); + if(bundle == NULL) { if(eglMakeCurrent_p(g_EglDisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT)) { currentBundle = NULL;