Skip to content

Commit

Permalink
Revert "Clean code"
Browse files Browse the repository at this point in the history
This reverts commit 5a96cf4.
  • Loading branch information
ShirosakiMio committed Dec 24, 2024
1 parent 5a96cf4 commit 189e528
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 7 deletions.
3 changes: 1 addition & 2 deletions FCLauncher/src/main/jni/Android.mk
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ LOCAL_SRC_FILES := glfw/context.c \
glfw/platform.c \
glfw/posix_thread.c \
glfw/posix_time.c \
driver_helper/driver_helper.c \
glfw/driver_helper.c \
driver_helper/nsbypass.c
LOCAL_C_INCLUDES := $(LOCAL_PATH)/fcl/include \
$(LOCAL_PATH)/glfw/include
Expand Down Expand Up @@ -86,7 +86,6 @@ LOCAL_SRC_FILES := \
pojav/environ/environ.c \
pojav/input_bridge_v3.c \
pojav/virgl/virgl.c \
driver_helper/driver_helper.c \
driver_helper/nsbypass.c
LOCAL_C_INCLUDES := $(LOCAL_PATH)/pojav
ifeq ($(TARGET_ARCH_ABI),arm64-v8a)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
#include <dlfcn.h>
#include <android/dlext.h>
#include "driver_helper/nsbypass.h"
#include "glfw/include/gl.h"
#include "include//gl.h"

#define ADRENO_POSSIBLE
//#define ADRENO_POSSIBLE
#ifdef ADRENO_POSSIBLE
//Checks if your graphics are Adreno. Returns true if your graphics are Adreno, false otherwise or if there was an error
bool checkAdrenoGraphics() {
Expand Down Expand Up @@ -48,7 +48,7 @@ bool checkAdrenoGraphics() {
}
void* load_turnip_vulkan() {
if(!checkAdrenoGraphics()) return NULL;
const char* native_dir = getenv("POJAV_NATIVEDIR");
const char* native_dir = getenv("FCL_NATIVEDIR");
const char* cache_dir = getenv("TMPDIR");
if(!linker_ns_load(native_dir)) return NULL;
void* linkerhook = linker_ns_dlopen("liblinkerhook.so", RTLD_LOCAL | RTLD_NOW);
Expand Down Expand Up @@ -77,4 +77,4 @@ void* load_turnip_vulkan() {
void* libvulkan = linker_ns_dlopen_unique(cache_dir, "libvulkan.so", RTLD_LOCAL | RTLD_NOW);
return libvulkan;
}
#endif
#endif
69 changes: 68 additions & 1 deletion FCLauncher/src/main/jni/pojav/egl_bridge.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ EGLConfig config;
struct PotatoBridge potatoBridge;

void bigcore_set_affinity();
void* load_turnip_vulkan();

#include "ctxbridges/egl_loader.h"
#include "ctxbridges/osmesa_loader.h"
Expand Down Expand Up @@ -98,6 +97,74 @@ EXTERNAL_API void* pojavGetCurrentContext() {
return br_get_current();
}

//#define ADRENO_POSSIBLE
#ifdef ADRENO_POSSIBLE
//Checks if your graphics are Adreno. Returns true if your graphics are Adreno, false otherwise or if there was an error
bool checkAdrenoGraphics() {
EGLDisplay eglDisplay = eglGetDisplay(EGL_DEFAULT_DISPLAY);
if(eglDisplay == EGL_NO_DISPLAY || eglInitialize(eglDisplay, NULL, NULL) != EGL_TRUE) return false;
EGLint egl_attributes[] = { EGL_BLUE_SIZE, 8, EGL_GREEN_SIZE, 8, EGL_RED_SIZE, 8, EGL_ALPHA_SIZE, 8, EGL_DEPTH_SIZE, 24, EGL_SURFACE_TYPE, EGL_PBUFFER_BIT, EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT, EGL_NONE };
EGLint num_configs = 0;
if(eglChooseConfig(eglDisplay, egl_attributes, NULL, 0, &num_configs) != EGL_TRUE || num_configs == 0) {
eglTerminate(eglDisplay);
return false;
}
EGLConfig eglConfig;
eglChooseConfig(eglDisplay, egl_attributes, &eglConfig, 1, &num_configs);
const EGLint egl_context_attributes[] = { EGL_CONTEXT_CLIENT_VERSION, 3, EGL_NONE };
EGLContext context = eglCreateContext(eglDisplay, eglConfig, EGL_NO_CONTEXT, egl_context_attributes);
if(context == EGL_NO_CONTEXT) {
eglTerminate(eglDisplay);
return false;
}
if(eglMakeCurrent(eglDisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, context) != EGL_TRUE) {
eglDestroyContext(eglDisplay, context);
eglTerminate(eglDisplay);
}
const char* vendor = glGetString(GL_VENDOR);
const char* renderer = glGetString(GL_RENDERER);
bool is_adreno = false;
if(strcmp(vendor, "Qualcomm") == 0 && strstr(renderer, "Adreno") != NULL) {
is_adreno = true; // TODO: check for Turnip support
}
eglMakeCurrent(eglDisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
eglDestroyContext(eglDisplay, context);
eglTerminate(eglDisplay);
return is_adreno;
}
void* load_turnip_vulkan() {
if(!checkAdrenoGraphics()) return NULL;
const char* native_dir = getenv("POJAV_NATIVEDIR");
const char* cache_dir = getenv("TMPDIR");
if(!linker_ns_load(native_dir)) return NULL;
void* linkerhook = linker_ns_dlopen("liblinkerhook.so", RTLD_LOCAL | RTLD_NOW);
if(linkerhook == NULL) return NULL;
void* turnip_driver_handle = linker_ns_dlopen("libvulkan_freedreno.so", RTLD_LOCAL | RTLD_NOW);
if(turnip_driver_handle == NULL) {
printf("AdrenoSupp: Failed to load Turnip!\n%s\n", dlerror());
dlclose(linkerhook);
return NULL;
}
void* dl_android = linker_ns_dlopen("libdl_android.so", RTLD_LOCAL | RTLD_LAZY);
if(dl_android == NULL) {
dlclose(linkerhook);
dlclose(turnip_driver_handle);
return NULL;
}
void* android_get_exported_namespace = dlsym(dl_android, "android_get_exported_namespace");
void (*linkerhook_pass_handles)(void*, void*, void*) = dlsym(linkerhook, "app__pojav_linkerhook_pass_handles");
if(linkerhook_pass_handles == NULL || android_get_exported_namespace == NULL) {
dlclose(dl_android);
dlclose(linkerhook);
dlclose(turnip_driver_handle);
return NULL;
}
linkerhook_pass_handles(turnip_driver_handle, android_dlopen_ext, android_get_exported_namespace);
void* libvulkan = linker_ns_dlopen_unique(cache_dir, "libvulkan.so", RTLD_LOCAL | RTLD_NOW);
return libvulkan;
}
#endif

static void set_vulkan_ptr(void* ptr) {
char envval[64];
sprintf(envval, "%"PRIxPTR, (uintptr_t)ptr);
Expand Down

0 comments on commit 189e528

Please sign in to comment.