Add more stubs

This commit is contained in:
Swung0x48 2024-10-10 17:54:35 +08:00
parent 921bfcb58e
commit d0baf94440
17 changed files with 1409 additions and 1156 deletions

View File

@ -29,9 +29,10 @@ add_library(${CMAKE_PROJECT_NAME} SHARED
native-lib.cpp
init.cpp
main.c
gl.c
egl.cpp
gles3.h
gl/gl.c
egl/egl.c
egl/loader.c
gles/loader.c
)
target_include_directories(${CMAKE_PROJECT_NAME} PRIVATE ./includes)

View File

@ -1,30 +0,0 @@
//
// Created by Swung 0x48 on 2024/10/8.
//
#ifndef FOLD_CRAFT_LAUNCHER_EGL_H
#define FOLD_CRAFT_LAUNCHER_EGL_H
#include <EGL/egl.h>
typedef __eglMustCastToProperFunctionPointerType (EGLGETPROCADDRESSPROC) (const char *procname);
typedef EGLGETPROCADDRESSPROC* EGLGETPROCADDRESSPROCP;
typedef EGLContext (EGLCREATECONTEXTPROC) (EGLDisplay, EGLConfig, EGLContext, const EGLint *);
typedef EGLCREATECONTEXTPROC* EGLCREATECONTEXTPROCP;
typedef EGLBoolean (EGLDESTROYCONTEXTPROC) (EGLDisplay, EGLContext);
typedef EGLDESTROYCONTEXTPROC* EGLDESTROYCONTEXTPROCP;
typedef EGLBoolean (EGLMAKECURRENTPROC)(EGLDisplay, EGLSurface, EGLSurface, EGLContext);
typedef EGLMAKECURRENTPROC* EGLMAKECURRENTPROCP;
struct egl_func_t {
EGLGETPROCADDRESSPROCP eglGetProcAddress;
EGLCREATECONTEXTPROCP eglCreateContext;
EGLDESTROYCONTEXTPROCP eglDestroyContext;
EGLMAKECURRENTPROCP eglMakeCurrent;
};
struct context_t {
EGLContext context;
};
#endif //FOLD_CRAFT_LAUNCHER_EGL_H

View File

@ -1,48 +1,29 @@
//
// Created by Swung 0x48 on 2024/10/8.
// Created by Swung0x48 on 2024/10/10.
//
#ifdef __cplusplus
extern "C" {
#endif
#include "egl.h"
#include "includes.h"
#include <EGL/egl.h>
#ifdef __cplusplus
}
#endif
#include <unordered_map>
static std::unordered_map<EGLContext, context_t> g_context;
#include "../includes.h"
EGLContext mglues_eglCreateContext(EGLDisplay dpy, EGLConfig config, EGLContext share_context, const EGLint *attrib_list) {
__android_log_print(ANDROID_LOG_VERBOSE, RENDERERNAME,
"%s @ %s(...)", RENDERERNAME, __FUNCTION__);
g_egl_func.eglCreateContext =
(EGLCREATECONTEXTPROCP)g_egl_func.eglGetProcAddress("eglCreateContext");
EGLContext ctx = g_egl_func.eglCreateContext(dpy, config, share_context, attrib_list);
g_context[ctx] = { .context = ctx };
EGLContext ctx = g_egl_func.eglCreateContext(dpy, config, share_context, attrib_list);
return ctx;
}
EGLBoolean mglues_eglDestroyContext(EGLDisplay dpy, EGLContext ctx) {
if (g_context.find(ctx) == g_context.end())
return EGL_FALSE;
EGLBoolean b = g_egl_func.eglDestroyContext(dpy, ctx);
if (b)
g_context.erase(ctx);
return b;
__android_log_print(ANDROID_LOG_VERBOSE, RENDERERNAME,
"%s @ %s(...)", RENDERERNAME, __FUNCTION__);
return g_egl_func.eglDestroyContext(dpy, ctx);
// return EGL_TRUE;
}
EGLBoolean mglues_eglMakeCurrent(EGLDisplay dpy, EGLSurface draw, EGLSurface read, EGLContext ctx) {
__android_log_print(ANDROID_LOG_VERBOSE, RENDERERNAME,
"%s @ %s(...)", RENDERERNAME, __FUNCTION__);
return g_egl_func.eglMakeCurrent(dpy, draw, read, ctx);
// return EGL_TRUE;
}

57
src/main/cpp/egl/egl.h Normal file
View File

@ -0,0 +1,57 @@
//
// Created by Swung 0x48 on 2024/10/8.
//
#ifndef FOLD_CRAFT_LAUNCHER_EGL_H
#define FOLD_CRAFT_LAUNCHER_EGL_H
#include <EGL/egl.h>
typedef __eglMustCastToProperFunctionPointerType (*EGLGETPROCADDRESSPROCP) (const char *procname);
typedef EGLint (*EGLGETERRORPROCP)(void);
typedef EGLDisplay (*EGLGETDISPLAYP)(EGLNativeDisplayType display_id);
typedef EGLBoolean (*EGLINITIALIZEPROCP)(EGLDisplay dpy, EGLint *major, EGLint *minor);
typedef EGLBoolean (*EGLTERMINATEPROCP)(EGLDisplay dpy);
typedef const char * (*EGLQUERYSTRINGPROCP)(EGLDisplay dpy, EGLint name);
typedef EGLBoolean (*EGLGETCONFIGSPROCP)(EGLDisplay dpy, EGLConfig *configs, EGLint config_size, EGLint *num_config);
typedef EGLBoolean (*EGLCHOOSECONFIGPROCP)(EGLDisplay dpy, const EGLint *attrib_list, EGLConfig *configs, EGLint config_size, EGLint *num_config);
typedef EGLBoolean (*EGLGETCONFIGATTRIBPROCP)(EGLDisplay dpy, EGLConfig config, EGLint attribute, EGLint *value);
typedef
typedef EGLSurface (*EGLCREATEWINDOWSURFACEPROCP)(EGLDisplay dpy, EGLConfig config, EGLNativeWindowType win, const EGLint *attrib_list);
typedef EGLSurface (*EGLCREATEPBUFFERSURFACEPROCP)(EGLDisplay dpy, EGLConfig config, const EGLint *attrib_list);
typedef EGLSurface (*EGLCREATEPIXMAPSURFACEPROCP)(EGLDisplay dpy, EGLConfig config, EGLNativePixmapType pixmap, const EGLint *attrib_list);
typedef EGLBoolean (*EGLDESTROYSURFACEPROCP)(EGLDisplay dpy, EGLSurface surface);
typedef EGLBoolean (*EGLQUERYSURFACEPROCP)(EGLDisplay dpy, EGLSurface surface, EGLint attribute, EGLint *value);
typedef EGLBoolean (*EGLBINDAPIPROCP)(EGLenum api);
typedef EGLenum (*EGLQUERYAPIPROCP)(void);
typedef
typedef EGLBoolean (*EGLWAITCLIENTPROCP)(void);
typedef EGLBoolean (*EGLRELEASETHREADPROCP)(void);
typedef EGLSurface (*EGLCREATEPBUFFERFROMCLIENTBUFFERPROCP)(EGLDisplay dpy, EGLenum buftype, EGLClientBuffer buffer, EGLConfig config, const EGLint *attrib_list);
typedef EGLBoolean (*EGLSURFACEATTRIBPROCP)(EGLDisplay dpy, EGLSurface surface, EGLint attribute, EGLint value);
typedef EGLBoolean (*EGLBINDTEXIMAGEPROCP)(EGLDisplay dpy, EGLSurface surface, EGLint buffer);
typedef EGLBoolean (*EGLRELEASETEXIMAGEPROCP)(EGLDisplay dpy, EGLSurface surface, EGLint buffer);
typedef EGLBoolean (*EGLSWAPINTERVALPROCP)(EGLDisplay dpy, EGLint interval);
typedef EGLContext (*EGLCREATECONTEXTPROCP)(EGLDisplay dpy, EGLConfig config, EGLContext share_context, const EGLint *attrib_list);
typedef EGLBoolean (*EGLDESTROYCONTEXTPROCP)(EGLDisplay dpy, EGLContext ctx);
typedef EGLBoolean (*EGLMAKECURRENTPROCP)(EGLDisplay dpy, EGLSurface draw, EGLSurface read, EGLContext ctx);
typedef EGLContext (*EGLGETCURRENTCONTEXTPROCP)(void);
typedef EGLSurface (*EGLGETCURRENTSURFACEPROCP)(EGLint readdraw);
typedef EGLDisplay (*EGLGETCURRENTDISPLAYPROCP)(void);
typedef EGLDisplay (*EGLGETPLATFORMDISPLAYPROCP)(EGLenum platform, void *native_display, const EGLAttrib *attrib_list);
typedef EGLBoolean (*EGLQUERYCONTEXTPROCP)(EGLDisplay dpy, EGLContext ctx, EGLint attribute, EGLint *value);
typedef EGLBoolean (*EGLWAITGLPROCP)(void);
typedef EGLBoolean (*EGLWAITNATIVEPROCP)(EGLint engine);
typedef EGLBoolean (*EGLSWAPBUFFERSPROCP)(EGLDisplay dpy, EGLSurface surface);
typedef EGLBoolean (*EGLCOPYBUFFERSPROCP)(EGLDisplay dpy, EGLSurface surface, EGLNativePixmapType target);
// Undocumented libmali internals, needed for ODROID Go Ultra
//NativePixmapType (*EGL_CREATE_PIXMAP_ID_MAPPINGPROCP)(void *pixmap);
//NativePixmapType (*EGL_DESTROY_PIXMAP_ID_MAPPINGPROCP)(int id);
// Undocumented libmali internals, needed for ODROID Go Ultra
//NativePixmapType (*EGL_CREATE_PIXMAP_ID_MAPPINGPROCP)(void *pixmap);
//NativePixmapType (*EGL_DESTROY_PIXMAP_ID_MAPPINGPROCP)(int id);
#endif //FOLD_CRAFT_LAUNCHER_EGL_H

24
src/main/cpp/egl/loader.c Normal file
View File

@ -0,0 +1,24 @@
//
// Created by Swung0x48 on 2024/10/10.
//
#include "loader.h"
#include "../includes.h"
#define EGL_LOAD_FUNC(name) g_egl_func.name = (void*)g_egl_func.eglGetProcAddress(#name);
void init_target_egl() {
__android_log_print(ANDROID_LOG_VERBOSE, RENDERERNAME,
"Initializing %s @ %s", RENDERERNAME, __FUNCTION__);
// g_egl_func.eglCreateContext = (EGLCREATECONTEXTPROCP)g_egl_func.eglGetProcAddress("eglCreateContext");
EGL_LOAD_FUNC(eglCreateContext);
EGL_LOAD_FUNC(eglDestroyContext);
EGL_LOAD_FUNC(eglMakeCurrent);
__android_log_print(ANDROID_LOG_VERBOSE, RENDERERNAME,
"Got target eglCreateContext @ 0x%lx", g_egl_func.eglCreateContext);
__android_log_print(ANDROID_LOG_VERBOSE, RENDERERNAME,
"Got target eglDestroyContext @ 0x%lx", g_egl_func.eglDestroyContext);
__android_log_print(ANDROID_LOG_VERBOSE, RENDERERNAME,
"Got target eglMakeCurrent @ 0x%lx", g_egl_func.eglMakeCurrent);
}

24
src/main/cpp/egl/loader.h Normal file
View File

@ -0,0 +1,24 @@
//
// Created by Swung 0x48 on 2024/10/10.
//
#ifndef FOLD_CRAFT_LAUNCHER_EGL_LOADER_H
#define FOLD_CRAFT_LAUNCHER_EGL_LOADER_H
#include "egl.h"
struct egl_func_t {
EGLGETPROCADDRESSPROCP eglGetProcAddress;
EGLCREATECONTEXTPROCP eglCreateContext;
EGLDESTROYCONTEXTPROCP eglDestroyContext;
EGLMAKECURRENTPROCP eglMakeCurrent;
};
void init_target_egl();
EGLContext mglues_eglCreateContext(EGLDisplay dpy, EGLConfig config, EGLContext share_context, const EGLint *attrib_list);
EGLBoolean mglues_eglDestroyContext(EGLDisplay dpy, EGLContext ctx);
EGLBoolean mglues_eglMakeCurrent(EGLDisplay dpy, EGLSurface draw, EGLSurface read, EGLContext ctx);
#endif //FOLD_CRAFT_LAUNCHER_EGL_LOADER_H

File diff suppressed because it is too large Load Diff

View File

@ -2047,7 +2047,7 @@ typedef void (APIENTRYP PFNGLMULTITEXCOORD4SVARBPROC) (GLenum target, const GLsh
#else /* GL_GLEXT_LEGACY */
#include <GL/glext.h>
#include "glext.h"
#endif /* GL_GLEXT_LEGACY */

5
src/main/cpp/gl/loader.c Normal file
View File

@ -0,0 +1,5 @@
//
// Created by Swung0x48 on 2024/10/10.
//
#include "../includes.h"

10
src/main/cpp/gl/loader.h Normal file
View File

@ -0,0 +1,10 @@
//
// Created by Swung 0x48 on 2024/10/10.
//
#ifndef FOLD_CRAFT_LAUNCHER_GL_LOADER_H
#define FOLD_CRAFT_LAUNCHER_GL_LOADER_H
#endif //FOLD_CRAFT_LAUNCHER_GL_LOADER_H

View File

@ -0,0 +1,11 @@
//
// Created by Swung 0x48 on 2024/10/10.
//
#include "loader.h"
#include "../includes.h"
void init_target_gles() {
__android_log_print(ANDROID_LOG_VERBOSE, RENDERERNAME,
"Initializing %s @ %s", RENDERERNAME, __FUNCTION__);
}

View File

@ -0,0 +1,14 @@
//
// Created by Swung 0x48 on 2024/10/10.
//
#ifndef FOLD_CRAFT_LAUNCHER_GLES_LOADER_H
#define FOLD_CRAFT_LAUNCHER_GLES_LOADER_H
struct gles_func_t {
};
void init_target_gles();
#endif //FOLD_CRAFT_LAUNCHER_GLES_LOADER_H

View File

@ -6,7 +6,7 @@
#define FOLD_CRAFT_LAUNCHER_GLES3_H
#include <GLES3/gl32.h>
#include <GL/gl.h>
#include "GL/gl.h"
struct es3_functions_t
{

View File

@ -12,7 +12,8 @@
#include <EGL/egl.h>
#include <GLES3/gl32.h>
#include "egl.h"
#include "egl/egl.h"
#include "egl/loader.h"
#define _mglues_dlopen(name) dlopen(name, RTLD_LAZY)
#define _mglues_dlclose(handle) dlclose(handle)
@ -27,7 +28,7 @@ EGLContext mglues_eglCreateContext (EGLDisplay dpy, EGLConfig config, EGLContext
EGLBoolean mglues_eglDestroyContext(EGLDisplay dpy, EGLContext ctx);
EGLBoolean mglues_eglMakeCurrent(EGLDisplay dpy, EGLSurface draw, EGLSurface read, EGLContext ctx);
static struct egl_func_t g_egl_func;
extern struct egl_func_t g_egl_func;
#endif //MOBILEGLUES_INCLUDES_H

View File

@ -4,14 +4,17 @@
#include <string.h>
#include "includes.h"
#include <GL/gl.h>
#include "gl/gl.h"
#include "egl/egl.h"
#include "egl/loader.h"
#include "gles/loader.h"
#ifdef __cplusplus
extern "C" {
#endif
void init_target_egl();
void init_target_gles();
struct egl_func_t g_egl_func;
__eglMustCastToProperFunctionPointerType prehook(const char *procname);
__eglMustCastToProperFunctionPointerType posthook(const char *procname);
@ -25,6 +28,8 @@ void proc_init() {
"Cannot load system libEGL.so!");
g_egl_func.eglGetProcAddress = _mglues_dlsym(handle, "eglGetProcAddress");
__android_log_print(ANDROID_LOG_VERBOSE, RENDERERNAME,
"Got target eglGetProcAddress @ 0x%lx", g_egl_func.eglGetProcAddress);
init_target_egl();
init_target_gles();
@ -32,30 +37,6 @@ void proc_init() {
g_initialized = 1;
}
void init_target_egl() {
__android_log_print(ANDROID_LOG_VERBOSE, RENDERERNAME,
"Initializing %s @ %s", RENDERERNAME, __FUNCTION__);
g_egl_func.eglCreateContext =
(EGLCREATECONTEXTPROCP)g_egl_func.eglGetProcAddress("eglCreateContext");
g_egl_func.eglDestroyContext =
(EGLDESTROYCONTEXTPROCP) g_egl_func.eglGetProcAddress("eglDestroyContext");
g_egl_func.eglMakeCurrent =
(EGLMAKECURRENTPROCP) g_egl_func.eglGetProcAddress("eglMakeCurrent");
__android_log_print(ANDROID_LOG_VERBOSE, RENDERERNAME,
"Got target eglCreateContext @ 0x%lx", g_egl_func.eglCreateContext);
__android_log_print(ANDROID_LOG_VERBOSE, RENDERERNAME,
"Got target eglDestroyContext @ 0x%lx", g_egl_func.eglDestroyContext);
__android_log_print(ANDROID_LOG_VERBOSE, RENDERERNAME,
"Got target eglMakeCurrent @ 0x%lx", g_egl_func.eglMakeCurrent);
}
void init_target_gles() {
__android_log_print(ANDROID_LOG_VERBOSE, RENDERERNAME,
"Initializing %s @ %s", RENDERERNAME, __FUNCTION__);
}
#define MAP_FUNC(name) if (strcmp(procname, #name) == 0) \
return (__eglMustCastToProperFunctionPointerType) name;
@ -64,18 +45,18 @@ void init_target_gles() {
__eglMustCastToProperFunctionPointerType prehook(const char *procname) {
if (!g_initialized)
proc_init();
// if (!g_initialized)
// proc_init();
if (!strncmp(procname, "egl", 3)) {
// MAP_FUNC_MGLUES(eglCreateContext);
// MAP_FUNC_MGLUES(eglDestroyContext);
// MAP_FUNC_MGLUES(eglMakeCurrent);
if (strcmp(procname, "eglCreateContext") == 0)
return (__eglMustCastToProperFunctionPointerType) g_egl_func.eglCreateContext;
if (strcmp(procname, "eglDestroyContext") == 0)
return (__eglMustCastToProperFunctionPointerType) g_egl_func.eglDestroyContext;
if (strcmp(procname, "eglMakeCurrent") == 0)
return (__eglMustCastToProperFunctionPointerType) g_egl_func.eglMakeCurrent;
MAP_FUNC_MGLUES(eglCreateContext);
MAP_FUNC_MGLUES(eglDestroyContext);
MAP_FUNC_MGLUES(eglMakeCurrent);
// if (strcmp(procname, "eglCreateContext") == 0)
// return (__eglMustCastToProperFunctionPointerType) g_egl_func.eglCreateContext;
// if (strcmp(procname, "eglDestroyContext") == 0)
// return (__eglMustCastToProperFunctionPointerType) g_egl_func.eglDestroyContext;
// if (strcmp(procname, "eglMakeCurrent") == 0)
// return (__eglMustCastToProperFunctionPointerType) g_egl_func.eglMakeCurrent;
}
// OpenGL 1.1