Skip to content

Commit

Permalink
Sync Pojav Commit ed1b879
Browse files Browse the repository at this point in the history
  • Loading branch information
ShirosakiMio committed Nov 17, 2024
1 parent 5b0c75f commit 69307ad
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 4 deletions.
7 changes: 6 additions & 1 deletion FCLauncher/src/main/jni/pojav/ctxbridges/egl_loader.c
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -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;
}
}
5 changes: 5 additions & 0 deletions FCLauncher/src/main/jni/pojav/ctxbridges/egl_loader.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ 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 __eglMustCastToProperFunctionPointerType (*eglGetProcAddress_p) (const char *procname);
extern EGLBoolean (*eglQuerySurface_p)( EGLDisplay display,
EGLSurface surface,
EGLint attribute,
EGLint * value);

bool dlsym_EGL();

Expand Down
46 changes: 43 additions & 3 deletions FCLauncher/src/main/jni/pojav/ctxbridges/gl_bridge.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#include <stdlib.h>
#include <dlfcn.h>
#include <stdbool.h>
#include "pojav/environ/environ.h"
#include <environ/environ.h>
#include "gl_bridge.h"
#include "egl_loader.h"

Expand Down Expand Up @@ -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));
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -154,7 +194,7 @@ void gl_swap_buffers() {
gl_swap_surface(currentBundle);
eglMakeCurrent_p(g_EglDisplay, currentBundle->surface, currentBundle->surface, currentBundle->context);
__android_log_print(ANDROID_LOG_INFO, g_LogTag, "The window has died, awaiting window change");
}
}

}

Expand All @@ -170,4 +210,4 @@ void gl_swap_interval(int swapInterval) {
if(pojav_environ->force_vsync) swapInterval = 1;

eglSwapInterval_p(g_EglDisplay, swapInterval);
}
}

0 comments on commit 69307ad

Please sign in to comment.