diff --git a/cmake/options/extra-options.cmake b/cmake/options/extra-options.cmake index 88a956f0..75e622f1 100644 --- a/cmake/options/extra-options.cmake +++ b/cmake/options/extra-options.cmake @@ -23,21 +23,31 @@ endif() # Media Layer if(NOT MCPI_HEADLESS_MODE) - set(DEFAULT_USE_MEDIA_LAYER_PROXY FALSE) + set(DEFAULT_USE_MEDIA_LAYER_TRAMPOLINE FALSE) if(BUILD_NATIVE_COMPONENTS AND NOT IS_ARM_TARGETING) - set(DEFAULT_USE_MEDIA_LAYER_PROXY TRUE) + set(DEFAULT_USE_MEDIA_LAYER_TRAMPOLINE TRUE) endif() - mcpi_option(USE_MEDIA_LAYER_PROXY "Whether To Enable The Media Layer Proxy" BOOL "${DEFAULT_USE_MEDIA_LAYER_PROXY}") + mcpi_option(USE_MEDIA_LAYER_TRAMPOLINE "Whether To Enable The Media Layer Trampoline (Requires QEMU)" BOOL "${DEFAULT_USE_MEDIA_LAYER_TRAMPOLINE}") mcpi_option(USE_GLES1_COMPATIBILITY_LAYER "Whether To Enable The GLESv1_CM Compatibility Layer" BOOL TRUE) else() - set(MCPI_USE_MEDIA_LAYER_PROXY FALSE) + set(MCPI_USE_MEDIA_LAYER_TRAMPOLINE FALSE) endif() -if(MCPI_USE_MEDIA_LAYER_PROXY) +if(MCPI_USE_MEDIA_LAYER_TRAMPOLINE) set(BUILD_MEDIA_LAYER_CORE "${BUILD_NATIVE_COMPONENTS}") else() set(BUILD_MEDIA_LAYER_CORE "${BUILD_ARM_COMPONENTS}") endif() +# QEMU +if(BUILD_NATIVE_COMPONENTS) + include(CheckSymbolExists) + check_symbol_exists("__ARM_ARCH" "" MCPI_IS_ARM32_OR_ARM64_TARGETING) + set(MCPI_USE_QEMU TRUE) + if(MCPI_IS_ARM32_OR_ARM64_TARGETING AND NOT MCPI_USE_MEDIA_LAYER_TRAMPOLINE) + set(MCPI_USE_QEMU FALSE) + endif() +endif() + # Specify Variant Name set(MCPI_VARIANT_NAME "minecraft-pi-reborn") if(MCPI_SERVER_MODE) @@ -67,13 +77,3 @@ mcpi_option(APP_TITLE "App Title" STRING "${DEFAULT_APP_TITLE}") # Skin Server mcpi_option(SKIN_SERVER "Skin Server" STRING "https://raw.githubusercontent.com/MCPI-Revival/Skins/data") - -# QEMU -if(BUILD_NATIVE_COMPONENTS) - include(CheckSymbolExists) - check_symbol_exists("__ARM_ARCH" "" MCPI_IS_ARM32_OR_ARM64_TARGETING) - set(MCPI_USE_QEMU TRUE) - if(MCPI_IS_ARM32_OR_ARM64_TARGETING) - set(MCPI_USE_QEMU FALSE) - endif() -endif() diff --git a/dependencies/qemu/trampoline.patch b/dependencies/qemu/trampoline.patch index d4ecfb94..1ff1870c 100644 --- a/dependencies/qemu/trampoline.patch +++ b/dependencies/qemu/trampoline.patch @@ -8,22 +8,25 @@ #include "qemu/osdep.h" #include "qemu/cutils.h" #include "qemu/path.h" -@@ -9070,6 +9071,14 @@ _syscall5(int, sys_move_mount, int, __from_dfd, const char *, __from_pathname, +@@ -9070,6 +9071,17 @@ _syscall5(int, sys_move_mount, int, __from_dfd, const char *, __from_pathname, int, __to_dfd, const char *, __to_pathname, unsigned int, flag) #endif +// g2h For Trampoline +static CPUState *_trampoline_g2h_cpu = NULL; +static void *_trampoline_g2h(uint32_t guest_addr) { ++ if (guest_addr == 0) { ++ return NULL; ++ } + return g2h(_trampoline_g2h_cpu, guest_addr); +} +// Trampoline Function -+typedef uint32_t (*_trampoline_t)(typeof(_trampoline_g2h) g2h, uint32_t id, uint32_t *args); ++typedef void (*_trampoline_t)(typeof(_trampoline_g2h) *g2h, uint32_t id, uint32_t *args); + /* This is an internal helper for do_syscall so that it is easier * to have a single return point, so that actions, such as logging * of syscall results, can be performed. -@@ -9095,6 +9104,26 @@ static abi_long do_syscall1(CPUArchState *cpu_env, int num, abi_long arg1, +@@ -9095,6 +9107,27 @@ static abi_long do_syscall1(CPUArchState *cpu_env, int num, abi_long arg1, void *p; switch(num) { @@ -32,7 +35,7 @@ + static _trampoline_t _trampoline = NULL; + if (_trampoline == NULL) { + // Open Library -+ void *_trampoline_handle = dlopen("libmedia-layer-trampoline.so", RTLD_LAZY); ++ void *_trampoline_handle = dlopen("libmedia-layer-trampoline.so", RTLD_NOW); + // Load Function + if (_trampoline_handle != NULL) { + _trampoline = dlsym(_trampoline_handle, "trampoline"); @@ -45,7 +48,8 @@ + } + // Call Trampoline + _trampoline_g2h_cpu = cpu; -+ return _trampoline(_trampoline_g2h, arg1, g2h(cpu, arg2)); ++ _trampoline(_trampoline_g2h, arg1, g2h(cpu, arg2)); ++ return 0; + } case TARGET_NR_exit: /* In old applications this may be used to implement _exit(2). diff --git a/media-layer/CMakeLists.txt b/media-layer/CMakeLists.txt index cf2b2d6b..321ce864 100644 --- a/media-layer/CMakeLists.txt +++ b/media-layer/CMakeLists.txt @@ -33,7 +33,7 @@ if(BUILD_MEDIA_LAYER_CORE) add_subdirectory(core) endif() -# Add Proxy -if(MCPI_USE_MEDIA_LAYER_PROXY OR BUILD_ARM_COMPONENTS) - add_subdirectory(proxy) +# Add Trampoline +if(MCPI_USE_MEDIA_LAYER_TRAMPOLINE OR BUILD_ARM_COMPONENTS) + add_subdirectory(trampoline) endif() diff --git a/media-layer/core/src/base.cpp b/media-layer/core/src/base.cpp index 088ae4a5..009ee7b0 100644 --- a/media-layer/core/src/base.cpp +++ b/media-layer/core/src/base.cpp @@ -1,10 +1,10 @@ -#include #include #include #include #include +#include // SDL Is Replaced With GLFW diff --git a/media-layer/core/src/media.c b/media-layer/core/src/media.c index 85cbf42c..7c917719 100644 --- a/media-layer/core/src/media.c +++ b/media-layer/core/src/media.c @@ -435,13 +435,15 @@ static void glfw_controller_look(float x, float y) { verify_controller_axis_value(y, CONTROLLER_LOOK_AXIS_THRESHOLD); // Send Event - SDL_Event event; - event.type = SDL_MOUSEMOTION; - event.motion.x = last_mouse_x; - event.motion.y = last_mouse_y; - event.motion.xrel = x * CONTROLLER_LOOK_AXIS_SENSITIVITY; - event.motion.yrel = y * CONTROLLER_LOOK_AXIS_SENSITIVITY; - SDL_PushEvent(&event); + if (is_interactable) { + SDL_Event event; + event.type = SDL_MOUSEMOTION; + event.motion.x = last_mouse_x; + event.motion.y = last_mouse_y; + event.motion.xrel = x * CONTROLLER_LOOK_AXIS_SENSITIVITY; + event.motion.yrel = y * CONTROLLER_LOOK_AXIS_SENSITIVITY; + SDL_PushEvent(&event); + } } } diff --git a/media-layer/include/media-layer/internal.h b/media-layer/include/media-layer/internal.h index 9c1e1577..562520eb 100644 --- a/media-layer/include/media-layer/internal.h +++ b/media-layer/include/media-layer/internal.h @@ -4,10 +4,8 @@ extern "C" { #endif -// Internal Methods (Not Handled By Media Layer Proxy) - +// Internal Methods __attribute__((visibility("internal"))) void _media_handle_SDL_PollEvent(); -__attribute__((visibility("internal"))) void _media_handle_SDL_Quit(); #ifdef __cplusplus } diff --git a/media-layer/proxy/CMakeLists.txt b/media-layer/proxy/CMakeLists.txt deleted file mode 100644 index dd4a3e88..00000000 --- a/media-layer/proxy/CMakeLists.txt +++ /dev/null @@ -1,27 +0,0 @@ -project(media-layer-proxy) - -# Configuration -set(MEDIA_LAYER_PROXY_SRC src/common/common.c src/media-layer-core.c) # Media Layer Proxy Source -if(NOT MCPI_HEADLESS_MODE) - list(APPEND MEDIA_LAYER_PROXY_SRC src/GLESv1_CM.c) -endif() - -# Build -if(BUILD_NATIVE_COMPONENTS) - # Build Media Layer Proxy Client - add_executable(media-layer-proxy-client src/client/client.cpp ${MEDIA_LAYER_PROXY_SRC}) - target_link_libraries(media-layer-proxy-client media-layer-headers reborn-util media-layer-core GLESv1_CM) - target_compile_definitions(media-layer-proxy-client PRIVATE -DMEDIA_LAYER_PROXY_CLIENT) - # Install - install(TARGETS media-layer-proxy-client DESTINATION "${MCPI_BIN_DIR}") -elseif(BUILD_ARM_COMPONENTS) - # Build Media Layer Proxy Server - add_library(media-layer-core SHARED src/server/server.cpp ${MEDIA_LAYER_PROXY_SRC} $) - target_link_libraries(media-layer-core media-layer-headers reborn-util) - target_compile_definitions(media-layer-core PRIVATE -DMEDIA_LAYER_PROXY_SERVER) - # Install - if(MCPI_USE_MEDIA_LAYER_PROXY) - install(TARGETS media-layer-core DESTINATION "${MCPI_LIB_DIR}") - endif() - install(TARGETS media-layer-core EXPORT sdk DESTINATION "${MCPI_SDK_LIB_DIR}") -endif() diff --git a/media-layer/proxy/src/GLESv1_CM.c b/media-layer/proxy/src/GLESv1_CM.c deleted file mode 100644 index 1781e6f8..00000000 --- a/media-layer/proxy/src/GLESv1_CM.c +++ /dev/null @@ -1,1276 +0,0 @@ -#include - -#include - -#include - -#include "common/common.h" - -static int get_glFogfv_params_length(GLenum pname) { - return pname == GL_FOG_COLOR ? 4 : 1; -} -CALL(11, glFogfv, void, (GLenum pname, const GLfloat *params)) { -#if defined(MEDIA_LAYER_PROXY_SERVER) - // Lock Proxy - start_proxy_call(); - - // Arguments - write_int((uint32_t) pname); - int length = get_glFogfv_params_length(pname); - for (int i = 0; i < length; i++) { - write_float(params[i]); - } - - // Release Proxy - end_proxy_call(); -#else - GLenum pname = (GLenum) read_int(); - int length = get_glFogfv_params_length(pname); - GLfloat params[length]; - for (int i = 0; i < length; i++) { - params[i] = read_float(); - } - // Run - glFogfv(pname, params); -#endif -} - -// Track Bindings -#if defined(MEDIA_LAYER_PROXY_SERVER) -static GLuint bound_buffer = 0; -static GLuint bound_texture = 0; -static unsigned char vertex_array_enabled = 0; -static unsigned char color_array_enabled = 0; -static unsigned char tex_coord_array_enabled = 0; -static unsigned char *get_array_enabled_pointer(GLenum array) { - switch (array) { - case GL_VERTEX_ARRAY: { - return &vertex_array_enabled; - } - case GL_COLOR_ARRAY: { - return &color_array_enabled; - } - case GL_TEXTURE_COORD_ARRAY: { - return &tex_coord_array_enabled; - } - default: { - ERR("Unsupported Array Pointer: %i", array); - } - } -} -#endif - -// 'pointer' Is Only Supported As An Integer, Not As An Actual Pointer -#if defined(MEDIA_LAYER_PROXY_SERVER) -#define CALL_GL_POINTER(unique_id, name) \ - static int is_set_##name = 0; \ - CALL(unique_id, name, void, (GLint size, GLenum type, GLsizei stride, const void *pointer)) { \ - /* Check */ \ - static GLint last_size; \ - static GLenum last_type; \ - static GLsizei last_stride; \ - static const void *last_pointer; \ - if (is_set_##name && last_size == size && last_type == type && last_stride == stride && last_pointer == pointer) { \ - return; \ - } else { \ - is_set_##name = 1; \ - last_size = size; \ - last_type = type; \ - last_stride = stride; \ - last_pointer = pointer; \ - } \ - /* Lock Proxy */ \ - start_proxy_call(); \ - \ - /* Arguments */ \ - write_int(bound_buffer); \ - write_int((uint32_t) size); \ - write_int((uint32_t) type); \ - write_int((uint32_t) stride); \ - write_int((uint32_t) pointer); \ - \ - /* Release Proxy */ \ - end_proxy_call(); \ - } -#else -#define CALL_GL_POINTER(unique_id, name) \ - CALL(unique_id, name, unused, unused) { \ - /* Setup Buffer Binding */ \ - GLuint bound_buffer = (GLuint) read_int(); \ - glBindBuffer(GL_ARRAY_BUFFER, bound_buffer); \ - /* Check State */ \ - if (bound_buffer == 0) { \ - PROXY_ERR("gl*Pointer() Functions Are Only Supported When A Buffer Is Bound To GL_ARRAY_BUFFER"); \ - } \ - GLint size = (GLint) read_int(); \ - GLenum type = (GLenum) read_int(); \ - GLsizei stride = (GLsizei) read_int(); \ - const void *pointer = (const void *) (uintptr_t) read_int(); \ - /* Run */ \ - name(size, type, stride, pointer); \ - } -#endif - -CALL_GL_POINTER(12, glVertexPointer) - -CALL(13, glLineWidth, void, (GLfloat width)) { -#if defined(MEDIA_LAYER_PROXY_SERVER) - // Lock Proxy - start_proxy_call(); - - // Arguments - write_float(width); - - // Release Proxy - end_proxy_call(); -#else - GLfloat width = read_float(); - // Run - glLineWidth(width); -#endif -} - -CALL(14, glBlendFunc, void, (GLenum sfactor, GLenum dfactor)) { -#if defined(MEDIA_LAYER_PROXY_SERVER) - // Lock Proxy - start_proxy_call(); - - // Arguments - write_int((uint32_t) sfactor); - write_int((uint32_t) dfactor); - - // Release Proxy - end_proxy_call(); -#else - GLenum sfactor = (GLenum) read_int(); - GLenum dfactor = (GLenum) read_int(); - // Run - glBlendFunc(sfactor, dfactor); -#endif -} - -CALL(15, glDrawArrays, void, (GLenum mode, GLint first, GLsizei count)) { -#if defined(MEDIA_LAYER_PROXY_SERVER) - // Lock Proxy - start_proxy_call(); - - // Arguments - write_int((uint32_t) mode); - write_int((uint32_t) first); - write_int((uint32_t) count); - write_int(bound_buffer); - write_int(bound_texture); - if (!vertex_array_enabled) { - IMPOSSIBLE(); - } - write_byte(color_array_enabled); - write_byte(tex_coord_array_enabled); - - // Release Proxy - end_proxy_call(); - flush_write_cache(); -#else - GLenum mode = (GLenum) read_int(); - GLint first = (GLint) read_int(); - GLsizei count = (GLsizei) read_int(); - GLuint bound_buffer = (GLuint) read_int(); - GLuint bound_texture = (GLuint) read_int(); - unsigned char color_array_enabled = read_byte(); - unsigned char tex_coord_array_enabled = read_byte(); - // Run - glBindBuffer(GL_ARRAY_BUFFER, bound_buffer); - glBindTexture(GL_TEXTURE_2D, bound_texture); - glEnableClientState(GL_VERTEX_ARRAY); -#define set_array_enabled(condition, enum) condition ? glEnableClientState(enum) : glDisableClientState(enum); - set_array_enabled(color_array_enabled, GL_COLOR_ARRAY); - set_array_enabled(tex_coord_array_enabled, GL_TEXTURE_COORD_ARRAY); - glDrawArrays(mode, first, count); -#endif -} - -CALL(16, glColor4f, void, (GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha)) { -#if defined(MEDIA_LAYER_PROXY_SERVER) - // Lock Proxy - start_proxy_call(); - - // Arguments - write_float(red); - write_float(green); - write_float(blue); - write_float(alpha); - - // Release Proxy - end_proxy_call(); -#else - GLfloat red = read_float(); - GLfloat green = read_float(); - GLfloat blue = read_float(); - GLfloat alpha = read_float(); - // Run - glColor4f(red, green, blue, alpha); -#endif -} - -CALL(17, glClear, void, (GLbitfield mask)) { -#if defined(MEDIA_LAYER_PROXY_SERVER) - // Lock Proxy - start_proxy_call(); - - // Arguments - write_int((uint32_t) mask); - - // Release Proxy - end_proxy_call(); -#else - GLbitfield mask = (GLbitfield) read_int(); - // Run - glClear(mask); -#endif -} - -#if defined(MEDIA_LAYER_PROXY_CLIENT) -// Preserve Buffer For Performance -static size_t _glBufferData_data_size = 0; -static void *_glBufferData_data = NULL; -__attribute__((destructor)) static void _free_glBufferData_data() { - if (_glBufferData_data != NULL) { - free(_glBufferData_data); - } -} -#endif -CALL(18, glBufferData, void, (__attribute__((unused)) GLenum target, GLsizeiptr size, const void *data, GLenum usage)) { -#if defined(MEDIA_LAYER_PROXY_SERVER) - // Lock Proxy - start_proxy_call(); - - // Arguments - write_int((uint32_t) size); - write_int((uint32_t) usage); - write_int(bound_buffer); - // Write Data - unsigned char is_null = data == NULL; - write_byte(is_null); - if (!is_null) { - safe_write((void *) data, (size_t) size); - } - - // Release Proxy - end_proxy_call(); -#else - GLsizeiptr size = (GLsizeiptr) read_int(); - GLenum usage = (GLenum) read_int(); - GLuint bound_buffer = (GLuint) read_int(); - // Load Data - void *data = NULL; - unsigned char is_null = read_byte(); - if (!is_null) { - // Allocate - int size_changed = 0; - if (_glBufferData_data == NULL) { - _glBufferData_data = malloc((size_t) size); - size_changed = 1; - } else if (((size_t) size) > _glBufferData_data_size) { - _glBufferData_data = realloc(_glBufferData_data, (size_t) size); - size_changed = 1; - } - // Verify - ALLOC_CHECK(_glBufferData_data); - if (size_changed) { - _glBufferData_data_size = size; - } - data = _glBufferData_data; - // Read - safe_read(data, (size_t) size); - } - // Run - glBindBuffer(GL_ARRAY_BUFFER, bound_buffer); - glBufferData(GL_ARRAY_BUFFER, size, data, usage); -#endif -} - -CALL(19, glFogx, void, (GLenum pname, GLfixed param)) { -#if defined(MEDIA_LAYER_PROXY_SERVER) - // Lock Proxy - start_proxy_call(); - - // Arguments - write_int((uint32_t) pname); - write_int((uint32_t) param); - - // Release Proxy - end_proxy_call(); -#else - GLenum pname = (GLenum) read_int(); - GLfixed param = (GLfixed) read_int(); - // Run - glFogx(pname, param); -#endif -} - -CALL(20, glFogf, void, (GLenum pname, GLfloat param)) { -#if defined(MEDIA_LAYER_PROXY_SERVER) - // Lock Proxy - start_proxy_call(); - - // Arguments - write_int((uint32_t) pname); - write_float(param); - - // Release Proxy - end_proxy_call(); -#else - GLenum pname = (GLenum) read_int(); - GLfloat param = read_float(); - // Run - glFogf(pname, param); -#endif -} - -CALL(21, glMatrixMode, void, (GLenum mode)) { -#if defined(MEDIA_LAYER_PROXY_SERVER) - // Lock Proxy - start_proxy_call(); - - // Arguments - write_int((uint32_t) mode); - - // Release Proxy - end_proxy_call(); -#else - GLenum mode = (GLenum) read_int(); - // Run - glMatrixMode(mode); -#endif -} - -CALL_GL_POINTER(22, glColorPointer) - -CALL(23, glScissor, void, (GLint x, GLint y, GLsizei width, GLsizei height)) { -#if defined(MEDIA_LAYER_PROXY_SERVER) - // Lock Proxy - start_proxy_call(); - - // Arguments - write_int((uint32_t) x); - write_int((uint32_t) y); - write_int((uint32_t) width); - write_int((uint32_t) height); - - // Release Proxy - end_proxy_call(); -#else - GLint x = (GLint) read_int(); - GLint y = (GLint) read_int(); - GLsizei width = (GLsizei) read_int(); - GLsizei height = (GLsizei) read_int(); - // Run - glScissor(x, y, width, height); -#endif -} - -CALL(24, glTexParameteri, void, (__attribute__((unused)) GLenum target, GLenum pname, GLint param)) { -#if defined(MEDIA_LAYER_PROXY_SERVER) - // Lock Proxy - start_proxy_call(); - - // Arguments - write_int((uint32_t) pname); - write_int((uint32_t) param); - write_int(bound_texture); - - // Release Proxy - end_proxy_call(); -#else - GLenum pname = (GLenum) read_int(); - GLint param = (GLint) read_int(); - GLuint bound_texture = (GLuint) read_int(); - // Run - glBindTexture(GL_TEXTURE_2D, bound_texture); - glTexParameteri(GL_TEXTURE_2D, pname, param); -#endif -} - -// Get Size (In Memory) Of Specified Texture -static int get_texture_size(GLsizei width, GLsizei height, GLenum format, GLenum type) { - int multiplier; - if (type == GL_UNSIGNED_BYTE) { - switch (format) { - case GL_RGB: { - multiplier = 3; - break; - } - case GL_RGBA: { - multiplier = 4; - break; - } - default: { - PROXY_ERR("Unsupported Texture Format: %u", (unsigned int) format); - } - } - } else { - multiplier = sizeof (unsigned short); - } - int line_size = width * multiplier; - { - // Handle Alignment - int alignment; - glGetIntegerv(GL_UNPACK_ALIGNMENT, &alignment); - // Round - int diff = line_size % alignment; - if (diff > 0) { - line_size = line_size + (alignment - diff); - } - } - return line_size * height; // This Should Have The Same Behavior On 32-Bit And 64-Bit Systems -} - -CALL(25, glTexImage2D, void, (__attribute__((unused)) GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height, GLint border, GLenum format, GLenum type, const void *pixels)) { -#if defined(MEDIA_LAYER_PROXY_SERVER) - // Get Texture Size - unsigned char is_null = pixels == NULL; - int size; - if (!is_null) { - size = get_texture_size(width, height, format, type); - } - - // Lock Proxy - start_proxy_call(); - - // Arguments - write_int((uint32_t) level); - write_int((uint32_t) internalformat); - write_int((uint32_t) width); - write_int((uint32_t) height); - write_int((uint32_t) border); - write_int((uint32_t) format); - write_int((uint32_t) type); - write_int(bound_texture); - write_byte(is_null); - if (!is_null) { - safe_write((void *) pixels, (size_t) size); - } - - // Release Proxy - end_proxy_call(); -#else - GLint level = (GLint) read_int(); - GLint internalformat = (GLint) read_int(); - GLsizei width = (GLsizei) read_int(); - GLsizei height = (GLsizei) read_int(); - GLint border = (GLint) read_int(); - GLenum format = (GLenum) read_int(); - GLenum type = (GLenum) read_int(); - GLuint bound_texture = (GLuint) read_int(); - unsigned char is_null = read_byte(); - void *pixels = NULL; - if (!is_null) { - int size = get_texture_size(width, height, format, type); - pixels = malloc(size); - ALLOC_CHECK(pixels); - safe_read(pixels, (size_t) size); - } - // Run - glBindTexture(GL_TEXTURE_2D, bound_texture); - glTexImage2D(GL_TEXTURE_2D, level, internalformat, width, height, border, format, type, pixels); - // Free - if (!is_null) { - free(pixels); - } -#endif -} - -CALL(26, glEnable, void, (GLenum cap)) { -#if defined(MEDIA_LAYER_PROXY_SERVER) - // Lock Proxy - start_proxy_call(); - - // Arguments - write_int((uint32_t) cap); - - // Release Proxy - end_proxy_call(); -#else - GLenum cap = (GLenum) read_int(); - // Run - glEnable(cap); -#endif -} - -#if defined(MEDIA_LAYER_PROXY_SERVER) -void glEnableClientState(GLenum array) { - // Set - unsigned char *enabled = get_array_enabled_pointer(array); - if (*enabled) { - return; - } else { - *enabled = 1; - } -} -#endif - -CALL(28, glPolygonOffset, void, (GLfloat factor, GLfloat units)) { -#if defined(MEDIA_LAYER_PROXY_SERVER) - // Lock Proxy - start_proxy_call(); - - // Arguments - write_float(factor); - write_float(units); - - // Release Proxy - end_proxy_call(); -#else - GLfloat factor = read_float(); - GLfloat units = read_float(); - // Run - glPolygonOffset(factor, units); -#endif -} - -CALL_GL_POINTER(41, glTexCoordPointer) - -#if defined(MEDIA_LAYER_PROXY_SERVER) -void glDisableClientState(GLenum array) { - // Set - unsigned char *enabled = get_array_enabled_pointer(array); - if (!*enabled) { - return; - } else { - *enabled = 0; - // Not needed when using compatibility layer -#ifndef MCPI_USE_GLES1_COMPATIBILITY_LAYER - switch (array) { - case GL_VERTEX_ARRAY: { - is_set_glVertexPointer = 0; - break; - } - case GL_COLOR_ARRAY: { - is_set_glColorPointer = 0; - break; - } - case GL_TEXTURE_COORD_ARRAY: { - is_set_glTexCoordPointer = 0; - break; - } - } -#endif - } -} -#endif - -CALL(30, glDepthRangef, void, (GLclampf near, GLclampf far)) { -#if defined(MEDIA_LAYER_PROXY_SERVER) - // Lock Proxy - start_proxy_call(); - - // Arguments - write_float(near); - write_float(far); - - // Release Proxy - end_proxy_call(); -#else - GLclampf near = read_float(); - GLclampf far = read_float(); - // Run - glDepthRangef(near, far); -#endif -} - -CALL(31, glDepthFunc, void, (GLenum func)) { -#if defined(MEDIA_LAYER_PROXY_SERVER) - // Lock Proxy - start_proxy_call(); - - // Arguments - write_int((uint32_t) func); - - // Release Proxy - end_proxy_call(); -#else - GLenum func = (GLenum) read_int(); - // Run - glDepthFunc(func); -#endif -} - -#if defined(MEDIA_LAYER_PROXY_SERVER) -void glBindBuffer(GLenum target, GLuint buffer) { - // Set - if (target == GL_ARRAY_BUFFER) { - bound_buffer = buffer; - } else { - PROXY_ERR("Unsupported Buffer Binding: %u", target); - } - // Not needed when using compatibility layer -#ifndef MCPI_USE_GLES1_COMPATIBILITY_LAYER - is_set_glVertexPointer = 0; - is_set_glColorPointer = 0; - is_set_glTexCoordPointer = 0; -#endif -} -#endif - -CALL(33, glClearColor, void, (GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha)) { -#if defined(MEDIA_LAYER_PROXY_SERVER) - // Lock Proxy - start_proxy_call(); - - // Arguments - write_float(red); - write_float(green); - write_float(blue); - write_float(alpha); - - // Release Proxy - end_proxy_call(); -#else - GLclampf red = read_float(); - GLclampf green = read_float(); - GLclampf blue = read_float(); - GLclampf alpha = read_float(); - // Run - glClearColor(red, green, blue, alpha); -#endif -} - -CALL(34, glPopMatrix, void, ()) { -#if defined(MEDIA_LAYER_PROXY_SERVER) - // Lock Proxy - start_proxy_call(); - // Release Proxy - end_proxy_call(); -#else - // Run - glPopMatrix(); -#endif -} - -CALL(35, glLoadIdentity, void, ()) { -#if defined(MEDIA_LAYER_PROXY_SERVER) - // Lock Proxy - start_proxy_call(); - // Release Proxy - end_proxy_call(); -#else - // Run - glLoadIdentity(); -#endif -} - -CALL(36, glScalef, void, (GLfloat x, GLfloat y, GLfloat z)) { -#if defined(MEDIA_LAYER_PROXY_SERVER) - // Lock Proxy - start_proxy_call(); - - // Arguments - write_float(x); - write_float(y); - write_float(z); - - // Release Proxy - end_proxy_call(); -#else - GLfloat x = read_float(); - GLfloat y = read_float(); - GLfloat z = read_float(); - // Run - glScalef(x, y, z); -#endif -} - -CALL(37, glPushMatrix, void, ()) { -#if defined(MEDIA_LAYER_PROXY_SERVER) - // Lock Proxy - start_proxy_call(); - // Release Proxy - end_proxy_call(); -#else - // Run - glPushMatrix(); -#endif -} - -CALL(38, glDepthMask, void, (GLboolean flag)) { -#if defined(MEDIA_LAYER_PROXY_SERVER) - // Lock Proxy - start_proxy_call(); - - // Arguments - write_int((uint32_t) flag); - - // Release Proxy - end_proxy_call(); -#else - GLboolean flag = (GLboolean) read_int(); - // Run - glDepthMask(flag); -#endif -} - -CALL(39, glHint, void, (GLenum target, GLenum mode)) { -#if defined(MEDIA_LAYER_PROXY_SERVER) - // Lock Proxy - start_proxy_call(); - - // Arguments - write_int((uint32_t) target); - write_int((uint32_t) mode); - - // Release Proxy - end_proxy_call(); -#else - GLenum target = (GLenum) read_int(); - GLenum mode = (GLenum) read_int(); - // Run - glHint(target, mode); -#endif -} - -static int get_glMultMatrixf_size() { - return 16; -} -CALL(40, glMultMatrixf, void, (const GLfloat *m)) { -#if defined(MEDIA_LAYER_PROXY_SERVER) - // Lock Proxy - start_proxy_call(); - - // Arguments - safe_write((void *) m, sizeof (float) * get_glMultMatrixf_size()); - - // Release Proxy - end_proxy_call(); -#else - GLfloat m[get_glMultMatrixf_size()]; - safe_read((void *) m, sizeof (float) * get_glMultMatrixf_size()); - // Run - glMultMatrixf(m); -#endif -} - -CALL(42, glDeleteBuffers, void, (GLsizei n, const GLuint *buffers)) { -#if defined(MEDIA_LAYER_PROXY_SERVER) - // Lock Proxy - start_proxy_call(); - - // Arguments - write_int((uint32_t) n); - for (int i = 0; i < n; i++) { - write_int((uint32_t) buffers[i]); - } - - // Release Proxy - end_proxy_call(); -#else - GLsizei n = (GLsizei) read_int(); - GLuint buffers[n]; - for (int i = 0; i < n; i++) { - buffers[i] = (GLuint) read_int(); - } - // Run - glDeleteBuffers(n, buffers); -#endif -} - -CALL(43, glColorMask, void, (GLboolean red, GLboolean green, GLboolean blue, GLboolean alpha)) { -#if defined(MEDIA_LAYER_PROXY_SERVER) - // Lock Proxy - start_proxy_call(); - - // Arguments - write_int((uint32_t) red); - write_int((uint32_t) green); - write_int((uint32_t) blue); - write_int((uint32_t) alpha); - - // Release Proxy - end_proxy_call(); -#else - GLboolean red = (GLboolean) read_int(); - GLboolean green = (GLboolean) read_int(); - GLboolean blue = (GLboolean) read_int(); - GLboolean alpha = (GLboolean) read_int(); - // Run - glColorMask(red, green, blue, alpha); -#endif -} - -CALL(44, glTexSubImage2D, void, (__attribute__((unused)) GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLenum type, const void *pixels)) { -#if defined(MEDIA_LAYER_PROXY_SERVER) - // Get Texture Size - unsigned char is_null = pixels == NULL; - int size; - if (!is_null) { - size = get_texture_size(width, height, format, type); - } - - // Lock Proxy - start_proxy_call(); - - // Arguments - write_int((uint32_t) level); - write_int((uint32_t) xoffset); - write_int((uint32_t) yoffset); - write_int((uint32_t) width); - write_int((uint32_t) height); - write_int((uint32_t) format); - write_int((uint32_t) type); - write_int(bound_texture); - write_byte(is_null); - if (!is_null) { - safe_write((void *) pixels, (size_t) size); - } - - // Release Proxy - end_proxy_call(); -#else - GLint level = (GLint) read_int(); - GLint xoffset = (GLint) read_int(); - GLint yoffset = (GLint) read_int(); - GLsizei width = (GLsizei) read_int(); - GLsizei height = (GLsizei) read_int(); - GLenum format = (GLenum) read_int(); - GLenum type = (GLenum) read_int(); - GLuint bound_texture = (GLuint) read_int(); - unsigned char is_null = read_byte(); - void *pixels = NULL; - if (!is_null) { - int size = get_texture_size(width, height, format, type); - pixels = malloc(size); - ALLOC_CHECK(pixels); - safe_read(pixels, (size_t) size); - } - // Run - glBindTexture(GL_TEXTURE_2D, bound_texture); - glTexSubImage2D(GL_TEXTURE_2D, level, xoffset, yoffset, width, height, format, type, pixels); - // Free - if (!is_null) { - free(pixels); - } -#endif -} - -CALL(45, glGenTextures, void, (GLsizei n, GLuint *textures)) { -#if defined(MEDIA_LAYER_PROXY_SERVER) - // Lock Proxy - start_proxy_call(); - - // Arguments - write_int((uint32_t) n); - - // Get Return Value - for (GLsizei i = 0; i < n; i++) { - textures[i] = (GLuint) read_int(); - } - - // Release Proxy - end_proxy_call(); -#else - GLsizei n = (GLsizei) read_int(); - GLuint textures[n]; - // Run - glGenTextures(n, textures); - // Return Value - for (GLsizei i = 0; i < n; i++) { - write_int((uint32_t) textures[i]); - } -#endif -} - -CALL(46, glDeleteTextures, void, (GLsizei n, const GLuint *textures)) { -#if defined(MEDIA_LAYER_PROXY_SERVER) - // Lock Proxy - start_proxy_call(); - - // Arguments - write_int((uint32_t) n); - for (GLsizei i = 0; i < n; i++) { - write_int((uint32_t) textures[i]); - } - - // Release Proxy - end_proxy_call(); -#else - GLsizei n = (GLsizei) read_int(); - GLuint textures[n]; - for (GLsizei i = 0; i < n; i++) { - textures[i] = (GLuint) read_int(); - } - // Run - glDeleteTextures(n, textures); -#endif -} - -CALL(47, glAlphaFunc, void, (GLenum func, GLclampf ref)) { -#if defined(MEDIA_LAYER_PROXY_SERVER) - // Lock Proxy - start_proxy_call(); - - // Arguments - write_int((uint32_t) func); - write_float(ref); - - // Release Proxy - end_proxy_call(); -#else - GLenum func = (GLenum) read_int(); - GLclampf ref = read_float(); - // Run - glAlphaFunc(func, ref); -#endif -} - -static int get_glGetFloatv_params_size(GLenum pname) { - switch (pname) { - case GL_MODELVIEW_MATRIX: - case GL_PROJECTION_MATRIX: { - return 16; - } - case GL_ALIASED_LINE_WIDTH_RANGE: - case GL_SMOOTH_LINE_WIDTH_RANGE: { - return 2; - } - default: { - PROXY_ERR("Unsupported glGetFloatv Property: %u", pname); - } - } -} -CALL(48, glGetFloatv, void, (GLenum pname, GLfloat *params)) { -#if defined(MEDIA_LAYER_PROXY_SERVER) - // Lock Proxy - start_proxy_call(); - - // Arguments - write_int((uint32_t) pname); - - // Get Return Value - int size = get_glGetFloatv_params_size(pname); - safe_read((void *) params, sizeof (GLfloat) * size); - - // Release Proxy - end_proxy_call(); -#else - GLenum pname = (GLenum) read_int(); - int size = get_glGetFloatv_params_size(pname); - GLfloat params[size]; - // Run - glGetFloatv(pname, params); - // Return Value - safe_write((void *) params, sizeof (GLfloat) * size); -#endif -} - -#if defined(MEDIA_LAYER_PROXY_SERVER) -void glBindTexture(GLenum target, GLuint texture) { - // Set - if (target == GL_TEXTURE_2D) { - bound_texture = texture; - } else { - PROXY_ERR("Unsupported Texture Binding: %u", target); - } -} -#endif - -CALL(50, glTranslatef, void, (GLfloat x, GLfloat y, GLfloat z)) { -#if defined(MEDIA_LAYER_PROXY_SERVER) - // Lock Proxy - start_proxy_call(); - - // Arguments - write_float(x); - write_float(y); - write_float(z); - - // Release Proxy - end_proxy_call(); -#else - GLfloat x = read_float(); - GLfloat y = read_float(); - GLfloat z = read_float(); - // Run - glTranslatef(x, y, z); -#endif -} - -CALL(51, glShadeModel, void, (GLenum mode)) { -#if defined(MEDIA_LAYER_PROXY_SERVER) - // Lock Proxy - start_proxy_call(); - - // Arguments - write_int((uint32_t) mode); - - // Release Proxy - end_proxy_call(); -#else - GLenum mode = (GLenum) read_int(); - // Run - glShadeModel(mode); -#endif -} - -CALL(52, glOrthof, void, (GLfloat left, GLfloat right, GLfloat bottom, GLfloat top, GLfloat near, GLfloat far)) { -#if defined(MEDIA_LAYER_PROXY_SERVER) - // Lock Proxy - start_proxy_call(); - - // Arguments - write_float(left); - write_float(right); - write_float(bottom); - write_float(top); - write_float(near); - write_float(far); - - // Release Proxy - end_proxy_call(); -#else - GLfloat left = read_float(); - GLfloat right = read_float(); - GLfloat bottom = read_float(); - GLfloat top = read_float(); - GLfloat near = read_float(); - GLfloat far = read_float(); - // Run - glOrthof(left, right, bottom, top, near, far); -#endif -} - -CALL(53, glDisable, void, (GLenum cap)) { -#if defined(MEDIA_LAYER_PROXY_SERVER) - // Lock Proxy - start_proxy_call(); - - // Arguments - write_int((uint32_t) cap); - - // Release Proxy - end_proxy_call(); -#else - GLenum cap = (GLenum) read_int(); - // Run - glDisable(cap); -#endif -} - -CALL(54, glCullFace, void, (GLenum mode)) { -#if defined(MEDIA_LAYER_PROXY_SERVER) - // Lock Proxy - start_proxy_call(); - - // Arguments - write_int((uint32_t) mode); - - // Release Proxy - end_proxy_call(); -#else - GLenum mode = (GLenum) read_int(); - // Run - glCullFace(mode); -#endif -} - -CALL(55, glRotatef, void, (GLfloat angle, GLfloat x, GLfloat y, GLfloat z)) { -#if defined(MEDIA_LAYER_PROXY_SERVER) - // Lock Proxy - start_proxy_call(); - - // Arguments - write_float(angle); - write_float(x); - write_float(y); - write_float(z); - - // Release Proxy - end_proxy_call(); -#else - GLfloat angle = read_float(); - GLfloat x = read_float(); - GLfloat y = read_float(); - GLfloat z = read_float(); - // Run - glRotatef(angle, x, y, z); -#endif -} - -CALL(56, glViewport, void, (GLint x, GLint y, GLsizei width, GLsizei height)) { -#if defined(MEDIA_LAYER_PROXY_SERVER) - // Lock Proxy - start_proxy_call(); - - // Arguments - write_int((uint32_t) x); - write_int((uint32_t) y); - write_int((uint32_t) width); - write_int((uint32_t) height); - - // Release Proxy - end_proxy_call(); -#else - GLint x = (GLint) read_int(); - GLint y = (GLint) read_int(); - GLsizei width = (GLsizei) read_int(); - GLsizei height = (GLsizei) read_int(); - // Run - glViewport(x, y, width, height); -#endif -} - -CALL(57, glNormal3f, void, (GLfloat nx, GLfloat ny, GLfloat nz)) { -#if defined(MEDIA_LAYER_PROXY_SERVER) - // Lock Proxy - start_proxy_call(); - - // Arguments - write_float(nx); - write_float(ny); - write_float(nz); - - // Release Proxy - end_proxy_call(); -#else - GLfloat nx = read_float(); - GLfloat ny = read_float(); - GLfloat nz = read_float(); - // Run - glNormal3f(nx, ny, nz); -#endif -} - -CALL(58, glIsEnabled, GLboolean, (GLenum cap)) { -#if defined(MEDIA_LAYER_PROXY_SERVER) - // Lock Proxy - start_proxy_call(); - - // Arguments - write_int((uint32_t) cap); - - // Get Return Value - GLboolean ret = (GLboolean) read_int(); - - // Release Proxy - end_proxy_call(); - - // Return - return ret; -#else - GLenum cap = (GLenum) read_int(); - // Run - GLboolean ret = glIsEnabled(cap); - // Return Value - write_int((uint32_t) ret); -#endif -} - -static int get_glGetIntegerv_params_size(GLenum pname) { - switch (pname) { - case GL_TEXTURE_BINDING_2D: - case GL_PACK_ALIGNMENT: - case GL_UNPACK_ALIGNMENT: { - return 1; - } - case GL_VIEWPORT: { - return 4; - } - default: { - PROXY_ERR("Unsupported glGetIntegerv Property: %u", pname); - } - } -} -CALL(61, glGetIntegerv, void, (GLenum pname, GLint *params)) { -#if defined(MEDIA_LAYER_PROXY_SERVER) - // Stop Redudnant Proxy Call - if (pname == GL_TEXTURE_BINDING_2D) { - params[0] = bound_texture; - return; - } - - // Lock Proxy - start_proxy_call(); - - // Arguments - write_int((uint32_t) pname); - - // Get Return Value - int size = get_glGetIntegerv_params_size(pname); - safe_read((void *) params, sizeof (GLint) * size); - - // Release Proxy - end_proxy_call(); -#else - GLenum pname = (GLenum) read_int(); - int size = get_glGetIntegerv_params_size(pname); - GLint params[size]; - // Run - glGetIntegerv(pname, params); - // Return Value - safe_write((void *) params, sizeof (GLint) * size); -#endif -} - -CALL(65, glReadPixels, void, (GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, GLenum type, void *data)) { -#if defined(MEDIA_LAYER_PROXY_SERVER) - // Get Texture Size - int size = get_texture_size(width, height, format, type); - - // Lock Proxy - start_proxy_call(); - - // Arguments - write_int((uint32_t) x); - write_int((uint32_t) y); - write_int((uint32_t) width); - write_int((uint32_t) height); - write_int((uint32_t) format); - write_int((uint32_t) type); - - // Get Return Value - safe_read((void *) data, size); - - // Release Proxy - end_proxy_call(); -#else - GLint x = (GLint) read_int(); - GLint y = (GLint) read_int(); - GLsizei width = (GLsizei) read_int(); - GLsizei height = (GLsizei) read_int(); - GLenum format = (GLenum) read_int(); - GLenum type = (GLenum) read_int(); - int size = get_texture_size(width, height, format, type); - void *pixels = malloc(size); - ALLOC_CHECK(pixels); - // Run - glReadPixels(x, y, width, height, format, type, pixels); - // Return Value - safe_write((void *) pixels, (size_t) size); - // Free - free(pixels); -#endif -} - -CALL(67, glGenBuffers, void, (GLsizei n, GLuint *buffers)) { -#if defined(MEDIA_LAYER_PROXY_SERVER) - // Lock Proxy - start_proxy_call(); - - // Arguments - write_int((uint32_t) n); - - // Get Return Value - for (GLsizei i = 0; i < n; i++) { - buffers[i] = (GLuint) read_int(); - } - - // Release Proxy - end_proxy_call(); -#else - GLsizei n = (GLsizei) read_int(); - GLuint buffers[n]; - // Run - glGenBuffers(n, buffers); - // Return Value - for (GLsizei i = 0; i < n; i++) { - write_int((uint32_t) buffers[i]); - } -#endif -} diff --git a/media-layer/proxy/src/client/client.cpp b/media-layer/proxy/src/client/client.cpp deleted file mode 100644 index f3b43bf8..00000000 --- a/media-layer/proxy/src/client/client.cpp +++ /dev/null @@ -1,107 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include - -#include "../common/common.h" - -// Store Handlers -#define MAX_HANDLERS 100 -static proxy_handler_t handlers[MAX_HANDLERS]; -void _add_handler(unsigned char unique_id, proxy_handler_t handler) { - if (unique_id >= MAX_HANDLERS) { - PROXY_ERR("ID Too Big: %i", (int) unique_id); - } - if (handlers[unique_id] != NULL) { - PROXY_ERR("Duplicate ID: %i", (int) unique_id); - } - handlers[unique_id] = handler; -} - -// Store Parent PID -static int parent_is_alive = 1; -static void sigusr1_handler(__attribute__((unused)) int sig) { - // Mark Parent As Dead - parent_is_alive = 0; -} -// Check State Of Proxy And Exit If Invalid -void _check_proxy_state() { - // Check Server State - if (!parent_is_alive) { - void_write_cache(); // Parent Is Dead, No Reason To Send A Dead Process Data - PROXY_ERR("Server Terminated"); - } -} - -// Exit Handler -static volatile int exit_requested = 0; -static void exit_handler(__attribute__((unused)) int signal_id) { - // Request Exit - exit_requested = 1; -} - -// Main -int main(int argc, char *argv[]) { - // Set Debug Tag - reborn_debug_tag = PROXY_LOG_TAG; - - // Install Signal Handlers - signal(SIGINT, SIG_IGN); - struct sigaction act_sigterm; - memset((void *) &act_sigterm, 0, sizeof (struct sigaction)); - act_sigterm.sa_handler = &exit_handler; - sigaction(SIGTERM, &act_sigterm, NULL); - - // Send Signal On Parent Death To Interrupt Connection Read/Write And Exit - prctl(PR_SET_PDEATHSIG, SIGUSR1); - struct sigaction sa; - memset((void *) &sa, 0, sizeof (struct sigaction)); - sa.sa_flags = SA_NOCLDSTOP; - sa.sa_handler = &sigusr1_handler; - if (sigaction(SIGUSR1, &sa, NULL) == -1) { - PROXY_ERR("Unable To Install Signal Handler: %s", strerror(errno)); - } - - // Get Connection - if (argc != 3) { - PROXY_ERR("Invalid Arguments"); - } - char *read_str = argv[1]; - char *write_str = argv[2]; - set_connection(atoi(read_str), atoi(write_str)); - PROXY_INFO("Connected"); - - // Send Connection Message - write_string((char *) CONNECTED_MSG); - flush_write_cache(); - - // Loop - int running = is_connection_open(); - while (running && !exit_requested) { - unsigned char unique_id = read_byte(); - if (handlers[unique_id] != NULL) { - // Run Method - handlers[unique_id](); - // Check If Connection Is Still Open - if (!is_connection_open()) { - // Exit - running = 0; - } else { - // Flush Write Cache - flush_write_cache(); - } - } else { - PROXY_ERR("Invalid Method ID: %i", (int) unique_id); - } - } - if (is_connection_open()) { - close_connection(); - } - - // Exit - PROXY_INFO("Stopped"); - return 0; -} diff --git a/media-layer/proxy/src/client/client.h b/media-layer/proxy/src/client/client.h deleted file mode 100644 index 181518ca..00000000 --- a/media-layer/proxy/src/client/client.h +++ /dev/null @@ -1,13 +0,0 @@ -#pragma once - -#define PROXY_LOG_TAG "(Media Layer Proxy Client) " - -typedef void (*proxy_handler_t)(); -__attribute__((visibility("internal"))) void _add_handler(unsigned char id, proxy_handler_t handler); - -#define CALL(unique_id, name, return_type, args) \ - static void _run_##name (); \ - __attribute__((constructor)) static void _init_##name() { \ - _add_handler(unique_id, _run_##name); \ - } \ - static void _run_##name () diff --git a/media-layer/proxy/src/common/common.c b/media-layer/proxy/src/common/common.c deleted file mode 100644 index e69b626e..00000000 --- a/media-layer/proxy/src/common/common.c +++ /dev/null @@ -1,245 +0,0 @@ -#include -#include -#include -#include -#include - -#include "common.h" - -// Safely Send/Receive Data From The Connection -#define CHECK_CONNECTION() \ - { \ - _check_proxy_state(); \ - if (!is_connection_open()) { \ - PROXY_ERR("Attempting To Access Closed Connection"); \ - } \ - } -// Buffer Reads -static void *_read_cache = NULL; -__attribute__((destructor)) static void _free_read_cache() { - if (_read_cache != NULL) { - free(_read_cache); - } -} -static size_t _read_cache_size = 0; -static size_t _read_cache_actual_size = 0; -static size_t _read_cache_position = 0; -#define max(a, b) (((a) > (b)) ? (a) : (b)) -#define min(a, b) (((a) < (b)) ? (a) : (b)) -void safe_read(void *buf, size_t len) { - // Check Data - if (buf == NULL) { - PROXY_ERR("Attempting To Read Into NULL Buffer"); - } - // Setup - size_t to_read = len; - // Copy From Read Buffer - if (_read_cache != NULL && _read_cache_size > 0) { - char *read_cache = (void *) (((unsigned char *) _read_cache) + _read_cache_position); - size_t read_cache_size = _read_cache_size - _read_cache_position; - if (read_cache_size > 0) { - size_t to_copy = min(to_read, read_cache_size); - memcpy(buf, read_cache, to_copy); - to_read -= to_copy; - _read_cache_position += to_copy; - } - } - // Check If Done - if (to_read < 1) { - return; - } - if (_read_cache_position < _read_cache_size) { - IMPOSSIBLE(); - } - // Flush Write Cache - flush_write_cache(); - // Read Remaining Data - size_t to_read_to_cache = 0; - while (to_read_to_cache < 1) { - CHECK_CONNECTION(); - int bytes_available; - if (ioctl(get_connection_read(), FIONREAD, &bytes_available) == -1) { - bytes_available = 0; - } - to_read_to_cache = max((size_t) bytes_available, to_read); - } - // Resize Buffer - _read_cache_position = 0; - _read_cache_size = to_read_to_cache; - if (_read_cache == NULL) { - _read_cache_actual_size = _read_cache_size; - _read_cache = malloc(_read_cache_actual_size); - } else if (_read_cache_size > _read_cache_actual_size) { - _read_cache_actual_size = _read_cache_size; - _read_cache = realloc(_read_cache, _read_cache_actual_size); - } - ALLOC_CHECK(_read_cache); - // Read Into Buffer - while (to_read_to_cache > 0) { - CHECK_CONNECTION(); - ssize_t x = read(get_connection_read(), (void *) (((unsigned char *) _read_cache) + (_read_cache_size - to_read_to_cache)), to_read_to_cache); - if (x == -1 && errno != EINTR) { - PROXY_ERR("Failed Reading Data To Connection: %s", strerror(errno)); - } - to_read_to_cache -= x; - } - // Copy Remaining Data - safe_read((void *) (((unsigned char *) buf) + (len - to_read)), to_read); -} -// Buffer Writes -static void *_write_cache = NULL; -__attribute__((destructor)) static void _free_write_cache() { - if (_write_cache != NULL) { - free(_write_cache); - } -} -static size_t _write_cache_size = 0; -static size_t _write_cache_position = 0; -void safe_write(void *buf, size_t len) { - // Check Data - if (buf == NULL) { - PROXY_ERR("Attempting To Send NULL Data"); - } - // Expand Write Cache If Needed - size_t needed_size = _write_cache_position + len; - if (_write_cache == NULL) { - _write_cache_size = needed_size; - _write_cache = malloc(_write_cache_size); - } else if (needed_size > _write_cache_size) { - _write_cache_size = needed_size; - _write_cache = realloc(_write_cache, _write_cache_size); - } - ALLOC_CHECK(_write_cache); - // Copy Data - memcpy((void *) (((unsigned char *) _write_cache) + _write_cache_position), buf, len); - // Advance Position - _write_cache_position += len; -} -// Flush Write Cache -void flush_write_cache() { - // Check Cache - if (_write_cache == NULL || _write_cache_position < 1) { - // Nothing To Write - return; - } - // Check Connection - if (!is_connection_open()) { - // Connection Closed - return; - } - // Write & Reset - size_t to_write = _write_cache_position; - size_t old_write_cache_position = _write_cache_position; - _write_cache_position = 0; - while (to_write > 0) { - CHECK_CONNECTION(); - ssize_t x = write(get_connection_write(), (void *) (((unsigned char *) _write_cache) + (old_write_cache_position - to_write)), to_write); - if (x == -1 && errno != EINTR) { - PROXY_ERR("Failed Writing Data To Connection: %s", strerror(errno)); - } - to_write -= x; - } -} -void void_write_cache() { - _write_cache_position = 0; -} - -// Read/Write 32-Bit Integers -uint32_t read_int() { - uint32_t ret = 0; - safe_read((void *) &ret, sizeof (ret)); - return ret; -} -void write_int(uint32_t x) { - safe_write((void *) &x, sizeof (x)); -} - -// Read/Write Floats -float read_float() { - float ret = 0; - safe_read((void *) &ret, sizeof (ret)); - return ret; -} -void write_float(float x) { - safe_write((void *) &x, sizeof (x)); -} - -// Read/Write Bytes -unsigned char read_byte() { - unsigned char ret = 0; - safe_read((void *) &ret, sizeof (ret)); - return ret; -} -void write_byte(unsigned char x) { - safe_write((void *) &x, sizeof (x)); -} - -// Read/Write Strings -char *read_string() { - // Check NULL - unsigned char is_null = read_byte(); - if (is_null) { - return NULL; - } - // Allocate String - unsigned char length = read_byte(); - char *str = malloc((size_t) length + 1); - // Read String - safe_read((void *) str, length); - // Add Terminator - str[length] = '\0'; - // Return String - return strdup(str); -} -#define MAX_STRING_SIZE 256 -void write_string(const char *str) { - unsigned char is_null = str == NULL; - write_byte(is_null); - if (!is_null) { - int length = strlen(str); - if (length > MAX_STRING_SIZE) { - PROXY_ERR("Unable To Write String To Connection: Larger Than %i Bytes", MAX_STRING_SIZE); - } - write_byte((unsigned char) length); - safe_write((void *) str, length); - } -} - -// Close Connection -void close_connection() { - // Flush Write Cache - flush_write_cache(); - // Close - int state_changed = 0; - if (get_connection_read() != -1) { - close(get_connection_read()); - state_changed = 1; - } - if (get_connection_write() != -1) { - close(get_connection_write()); - state_changed = 1; - } - set_connection(-1, -1); - if (state_changed) { - PROXY_INFO("Connection Closed"); - } -} -// Check If Connection Is Open -int is_connection_open() { - return get_connection_read() != -1 && get_connection_write() != -1; -} -// Pipe -static int _read = -1; -static int _write = -1; -// Set Pipe -void set_connection(int read, int write) { - _read = read; - _write = write; -} -// Get Pipe -int get_connection_read() { - return _read; -} -int get_connection_write() { - return _write; -} diff --git a/media-layer/proxy/src/common/common.h b/media-layer/proxy/src/common/common.h deleted file mode 100644 index 78e07f21..00000000 --- a/media-layer/proxy/src/common/common.h +++ /dev/null @@ -1,62 +0,0 @@ -#pragma once - -#include - -#include - -#ifdef __cplusplus -extern "C" { -#endif - -#if __BYTE_ORDER != __LITTLE_ENDIAN -#error "Only Little Endian Is Supported" -#endif - -#if defined(MEDIA_LAYER_PROXY_SERVER) -#include "../server/server.h" -#elif defined(MEDIA_LAYER_PROXY_CLIENT) -#include "../client/client.h" -#else -#error "Invalid Configuration" -#endif - -#define CONNECTED_MSG "Connected" - -#define PROXY_INFO(format, ...) RAW_DEBUG(PROXY_LOG_TAG, format, ##__VA_ARGS__); -#define PROXY_ERR(format, ...) { close_connection(); ERR(PROXY_LOG_TAG format, ##__VA_ARGS__); } - -// Safely Send/Receive Data From The Connection -__attribute__((visibility("internal"))) void safe_read(void *buf, size_t len); -__attribute__((visibility("internal"))) void safe_write(void *buf, size_t len); -__attribute__((visibility("internal"))) void flush_write_cache(); -__attribute__((visibility("internal"))) void void_write_cache(); - -// Read/Write 32-Bit Integers -__attribute__((visibility("internal"))) uint32_t read_int(); -__attribute__((visibility("internal"))) void write_int(uint32_t x); - -// Read/Write Bytes -__attribute__((visibility("internal"))) unsigned char read_byte(); -__attribute__((visibility("internal"))) void write_byte(unsigned char x); - -// Read/Write Floats -__attribute__((visibility("internal"))) float read_float(); -__attribute__((visibility("internal"))) void write_float(float x); - -// Read/Write Strings -__attribute__((visibility("internal"))) char *read_string(); // Remember To free() -__attribute__((visibility("internal"))) void write_string(const char *str); - -// Manipulate Connection -__attribute__((visibility("internal"))) void set_connection(int read, int write); -__attribute__((visibility("internal"))) int get_connection_read(); -__attribute__((visibility("internal"))) int get_connection_write(); -__attribute__((visibility("internal"))) void close_connection(); -__attribute__((visibility("internal"))) int is_connection_open(); - -// Check State Of Proxy And Exit If Invalid -__attribute__((visibility("internal"))) void _check_proxy_state(); - -#ifdef __cplusplus -} -#endif diff --git a/media-layer/proxy/src/media-layer-core.c b/media-layer/proxy/src/media-layer-core.c deleted file mode 100644 index 3d5f4a65..00000000 --- a/media-layer/proxy/src/media-layer-core.c +++ /dev/null @@ -1,354 +0,0 @@ -#include - -#include - -#include -#include -#include -#include - -#include "common/common.h" - -// SDL Functions - -CALL(0, SDL_Init, int, (uint32_t flags)) { -#if defined(MEDIA_LAYER_PROXY_SERVER) - // Lock Proxy - start_proxy_call(); - - // Arguments - write_int(flags); - - // Get Return Value - int32_t ret = (int32_t) read_int(); - - // Release Proxy - end_proxy_call(); - - // Return - return ret; -#else - uint32_t flags = read_int(); - // Run - int ret = SDL_Init(flags); - // Return Values - write_int((uint32_t) ret); -#endif -} - -CALL(1, SDL_PollEvent, int, (SDL_Event *event)) { -#if defined(MEDIA_LAYER_PROXY_SERVER) - // Lock Proxy - start_proxy_call(); - - // No Arguments - - // Get Return Value - int32_t ret = (int32_t) read_int(); - if (ret) { - safe_read((void *) event, sizeof (SDL_Event)); - } - - // Release Proxy - end_proxy_call(); - - // Return Value - return ret; -#else - SDL_Event event; - // Run - int ret = (int32_t) SDL_PollEvent(&event); - // Return Values - write_int(ret); - if (ret) { - safe_write((void *) &event, sizeof (SDL_Event)); - } -#endif -} - -CALL(2, SDL_PushEvent, int, (SDL_Event *event)) { -#if defined(MEDIA_LAYER_PROXY_SERVER) - // Lock Proxy - start_proxy_call(); - - // Arguments - safe_write((void *) event, sizeof (SDL_Event)); - - // Get Return Value - int32_t ret = (int32_t) read_int(); - - // Release Proxy - end_proxy_call(); - - // Return Value - return ret; -#else - SDL_Event event; - safe_read((void *) &event, sizeof (SDL_Event)); - // Run - int ret = SDL_PushEvent(&event); - // Return Value - write_int((uint32_t) ret); -#endif -} - -CALL(3, SDL_WM_SetCaption, void, (const char *title, const char *icon)) { -#if defined(MEDIA_LAYER_PROXY_SERVER) - // Lock Proxy - start_proxy_call(); - - // Arguments - write_string((char *) title); - write_string((char *) icon); - - // Release Proxy - end_proxy_call(); -#else - char *title = read_string(); - char *icon = read_string(); - // Run - SDL_WM_SetCaption(title, icon); - // Free - free(title); - free(icon); -#endif -} - -CALL(4, media_toggle_fullscreen, void, ()) { -#if defined(MEDIA_LAYER_PROXY_SERVER) - // Lock Proxy - start_proxy_call(); - // Release Proxy - end_proxy_call(); -#else - // Run - media_toggle_fullscreen(); -#endif -} - -CALL(5, SDL_WM_GrabInput, SDL_GrabMode, (SDL_GrabMode mode)) { -#if defined(MEDIA_LAYER_PROXY_SERVER) - // Lock Proxy - start_proxy_call(); - - // Arguments - write_int((uint32_t) mode); - - // Get Return Value - SDL_GrabMode ret = (SDL_GrabMode) read_int(); - - // Release Proxy - end_proxy_call(); - - // Return Value - return ret; -#else - SDL_GrabMode mode = (SDL_GrabMode) read_int(); - // Run - SDL_GrabMode ret = SDL_WM_GrabInput(mode); - // Return Value - write_int((uint32_t) ret); -#endif -} - -CALL(6, SDL_ShowCursor, int, (int32_t toggle)) { -#if defined(MEDIA_LAYER_PROXY_SERVER) - // Lock Proxy - start_proxy_call(); - - // Arguments - write_int((uint32_t) toggle); - - // Get Return Value - int32_t ret = (int32_t) read_int(); - - // Release Proxy - end_proxy_call(); - - // Return Value - return ret; -#else - int mode = (int) read_int(); - // Run - int ret = SDL_ShowCursor(mode); - // Return Value - write_int((uint32_t) ret); -#endif -} - -CALL(8, media_swap_buffers, void, ()) { -#if defined(MEDIA_LAYER_PROXY_SERVER) - // Lock Proxy - start_proxy_call(); - // Release Proxy - end_proxy_call(); - flush_write_cache(); -#else - // Run - media_swap_buffers(); -#endif -} - -// This Method May Be Called In A Situation Where The Proxy Is Disconnected -CALL(9, media_cleanup, void, ()) { -#if defined(MEDIA_LAYER_PROXY_SERVER) - // Check Connection - if (is_connection_open()) { - // Lock Proxy - start_proxy_call(); - // Block Until Cleanup Is Complete - flush_write_cache(); - read_byte(); - // Close The Connection - close_connection(); - // Release Proxy - end_proxy_call(); - } -#else - // Run - media_cleanup(); - // Confirm Cleanup - write_byte(0); - // Close The Connection - close_connection(); -#endif -} - -CALL(10, media_get_framebuffer_size, void, (int *width, int *height)) { -#if defined(MEDIA_LAYER_PROXY_SERVER) - // Lock Proxy - start_proxy_call(); - - // Get Return Values - *width = (int) read_int(); - *height = (int) read_int(); - - // Release Proxy - end_proxy_call(); -#else - int width; - int height; - // Run - media_get_framebuffer_size(&width, &height); - // Return Values - write_int((uint32_t) width); - write_int((uint32_t) height); -#endif -} - -CALL(59, media_audio_update, void, (float volume, float x, float y, float z, float yaw)) { -#if defined(MEDIA_LAYER_PROXY_SERVER) - // Lock Proxy - start_proxy_call(); - - // Arguments - write_float(volume); - write_float(x); - write_float(y); - write_float(z); - write_float(yaw); - - // Release Proxy - end_proxy_call(); -#else - float volume = read_float(); - float x = read_float(); - float y = read_float(); - float z = read_float(); - float yaw = read_float(); - // Run - media_audio_update(volume, x, y, z, yaw); -#endif -} - -CALL(60, media_audio_play, void, (const char *source, const char *name, float x, float y, float z, float pitch, float volume, int is_ui)) { -#if defined(MEDIA_LAYER_PROXY_SERVER) - // Lock Proxy - start_proxy_call(); - - // Arguments - write_string(source); - write_string(name); - write_float(x); - write_float(y); - write_float(z); - write_float(pitch); - write_float(volume); - write_int(is_ui); - - // Release Proxy - end_proxy_call(); -#else - char *source = read_string(); - char *name = read_string(); - float x = read_float(); - float y = read_float(); - float z = read_float(); - float pitch = read_float(); - float volume = read_float(); - int is_ui = read_int(); - // Run - media_audio_play(source, name, x, y, z, pitch, volume, is_ui); - // Free - free(source); - free(name); -#endif -} - -CALL(62, media_set_interactable, void, (int is_interactable)) { -#if defined(MEDIA_LAYER_PROXY_SERVER) - // Lock Proxy - start_proxy_call(); - - // Arguments - write_int(is_interactable); - - // Release Proxy - end_proxy_call(); -#else - int is_interactable = read_int(); - // Run - media_set_interactable(is_interactable); -#endif -} - -CALL(63, media_disable_vsync, void, ()) { -#if defined(MEDIA_LAYER_PROXY_SERVER) - // Lock Proxy - start_proxy_call(); - // Release Proxy - end_proxy_call(); -#else - // Run - media_disable_vsync(); -#endif -} - -CALL(64, media_set_raw_mouse_motion_enabled, void, (int enabled)) { -#if defined(MEDIA_LAYER_PROXY_SERVER) - // Lock Proxy - start_proxy_call(); - - // Arguments - write_int(enabled); - - // Release Proxy - end_proxy_call(); -#else - int enabled = read_int(); - // Run - media_set_raw_mouse_motion_enabled(enabled); -#endif -} - -CALL(66, media_force_egl, void, ()) { -#if defined(MEDIA_LAYER_PROXY_SERVER) - // Lock Proxy - start_proxy_call(); - // Release Proxy - end_proxy_call(); -#else - // Run - media_force_egl(); -#endif -} diff --git a/media-layer/proxy/src/server/server.cpp b/media-layer/proxy/src/server/server.cpp deleted file mode 100644 index 8bb7b21a..00000000 --- a/media-layer/proxy/src/server/server.cpp +++ /dev/null @@ -1,170 +0,0 @@ -#include -#include -#include -#include -#include -#include - -#include -#include -#include - -#include - -#include "../common/common.h" - -// Track Client State -static int _client_is_alive = 0; -static int _client_status = 0; -static void update_client_state(int is_alive, int status) { - _client_is_alive = is_alive; - _client_status = status; -} -// Check State Of Proxy And Exit If Invalid -void _check_proxy_state() { - // Check Client State - if (!_client_is_alive) { - void_write_cache(); // Child Is Dead, No Reason To Send A Dead Process Data - char *exit_status = NULL; - get_exit_status_string(_client_status, &exit_status); - PROXY_ERR("Client Terminated%s", exit_status); - } -} - -// Start Proxy Client -static pid_t _client_pid; -static void sigchld_handler(__attribute__((unused)) int sig) { - // Track - int status; - - // Reap - int saved_errno = errno; - // Only waitpid() Proxy Client, Other Sub-Processes Are Handled By pclose() - if (waitpid(_client_pid, &status, WNOHANG) == _client_pid) { - // Handle Client Death - untrack_child(_client_pid); - update_client_state(0, status); - } - errno = saved_errno; -} -static void start_media_layer_proxy_client(int read, int write) { - // Reap Children - struct sigaction sa; - sigemptyset(&sa.sa_mask); - sa.sa_flags = SA_NOCLDSTOP; - sa.sa_handler = &sigchld_handler; - if (sigaction(SIGCHLD, &sa, NULL) == -1) { - PROXY_ERR("Unable To Install Signal Handler: %s", strerror(errno)); - } - - // Fork And Start - pid_t ret = fork(); - if (ret == -1) { - PROXY_ERR("Unable To Launch Client: %s", strerror(errno)); - } else if (ret == 0) { - // Child Process - - // Set Debug Tag - reborn_debug_tag = CHILD_PROCESS_TAG; - - // Prepare Arguments - char *read_str = NULL; - safe_asprintf(&read_str, "%i", read); - char *write_str = NULL; - safe_asprintf(&write_str, "%i", write); - const char *argv[] = {"media-layer-proxy-client", read_str, write_str, NULL}; - - // Setup Environment - setup_exec_environment(0); - - // Run - safe_execvpe(argv, (const char *const *) environ); - } else { - // Parent Process - _client_pid = ret; - track_child(_client_pid); - } - update_client_state(1, 0); -} - -// Maximize Pipe Buffer Size -static void maximize_pipe_fd_size(int fd) { - // Read Maximum Pipe Size - std::ifstream max_size_file("/proc/sys/fs/pipe-max-size"); - if (!max_size_file.good()) { - PROXY_ERR("%s", "Unable To Open Maximum Pipe Size File"); - } - // Read One Line - int max_size; - std::string line; - if (std::getline(max_size_file, line) && line.size() > 0) { - max_size = std::stoi(line); - } else { - PROXY_ERR("%s", "Unable To Read Maximum Pipe Size File"); - } - // Close - max_size_file.close(); - // Set Maximum Pipe Size - errno = 0; - if (fcntl(fd, F_SETPIPE_SZ, max_size) < max_size) { - PROXY_ERR("Unable To Set Maximum Pipe Size: %s", errno != 0 ? strerror(errno) : "Unknown Error"); - } -} -static void maximize_pipe_size(int pipe[2]) { - maximize_pipe_fd_size(pipe[0]); - maximize_pipe_fd_size(pipe[1]); -} - -// Start Server -static int loaded = 0; -__attribute__((constructor)) void media_ensure_loaded() { - if (!loaded) { - loaded = 1; - - // Log - PROXY_INFO("Starting..."); - - // Create Connection - int server_to_client_pipe[2]; - safe_pipe2(server_to_client_pipe, 0); - maximize_pipe_size(server_to_client_pipe); - int client_to_server_pipe[2]; - safe_pipe2(client_to_server_pipe, 0); - maximize_pipe_size(client_to_server_pipe); - // Set Connection - set_connection(client_to_server_pipe[0], server_to_client_pipe[1]); - - // Start Client - start_media_layer_proxy_client(server_to_client_pipe[0], client_to_server_pipe[1]); - - // Wait For Connection Message - char *str = read_string(); - if (strcmp(str, CONNECTED_MSG) == 0) { - PROXY_INFO("Connected"); - } else { - PROXY_ERR("Unable To Connect"); - } - // Free - free(str); - } -} - -// Assign Unique ID To Function -static std::unordered_map &get_unique_ids() { - static std::unordered_map unique_ids; - return unique_ids; -} -void _assign_unique_id(const char *name, unsigned char id) { - get_unique_ids()[name] = id; -} -unsigned char _get_unique_id(const char *name) { - return get_unique_ids()[name]; // Assume ID Exists -} - -// Proxy Call Functions -void _start_proxy_call(unsigned char call_id) { - // Start Call - write_byte(call_id); -} -void end_proxy_call() { -} diff --git a/media-layer/proxy/src/server/server.h b/media-layer/proxy/src/server/server.h deleted file mode 100644 index 85e6bfb2..00000000 --- a/media-layer/proxy/src/server/server.h +++ /dev/null @@ -1,27 +0,0 @@ -#pragma once - -#define PROXY_LOG_TAG "(Media Layer Proxy Server) " - -// Assign Unique ID To Function -__attribute__((visibility("internal"))) void _assign_unique_id(const char *name, unsigned char id); -__attribute__((visibility("internal"))) unsigned char _get_unique_id(const char *name); - -// Must Call After Every Call -__attribute__((visibility("internal"))) void _start_proxy_call(unsigned char call_id); -#define start_proxy_call() \ - { \ - static int _loaded_id = 0; \ - static unsigned char _call_id; \ - if (!_loaded_id) { \ - _loaded_id = 1; \ - _call_id = _get_unique_id(__func__); \ - } \ - _start_proxy_call(_call_id); \ - } -__attribute__((visibility("internal"))) void end_proxy_call(); - -#define CALL(unique_id, name, return_type, args) \ - __attribute__((constructor)) static void _init_##name() { \ - _assign_unique_id(#name, unique_id); \ - } \ - return_type name args diff --git a/media-layer/trampoline/CMakeLists.txt b/media-layer/trampoline/CMakeLists.txt new file mode 100644 index 00000000..968c911a --- /dev/null +++ b/media-layer/trampoline/CMakeLists.txt @@ -0,0 +1,30 @@ +project(media-layer-trampoline) + +# Configuration +set(MEDIA_LAYER_TRAMPOLINE_SRC src/media-layer-core.c) # Media Layer Trampoline Source +if(NOT MCPI_HEADLESS_MODE) + list(APPEND MEDIA_LAYER_TRAMPOLINE_SRC src/GLESv1_CM.c) +endif() + +# Build +if(BUILD_NATIVE_COMPONENTS) + # Host Component + add_library(media-layer-trampoline src/host/host.c ${MEDIA_LAYER_TRAMPOLINE_SRC}) + target_link_libraries(media-layer-trampoline reborn-util media-layer-core) + if(NOT MCPI_HEADLESS_MODE) + target_link_libraries(media-layer-trampoline GLESv1_CM) + endif() + target_compile_definitions(media-layer-trampoline PRIVATE -DMEDIA_LAYER_TRAMPOLINE_HOST) + # Install + install(TARGETS media-layer-trampoline DESTINATION "${MCPI_LIB_DIR}") +elseif(BUILD_ARM_COMPONENTS) + # Guest Component + add_library(media-layer-core SHARED src/guest/guest.c ${MEDIA_LAYER_TRAMPOLINE_SRC} $) + target_link_libraries(media-layer-core media-layer-headers reborn-util) + target_compile_definitions(media-layer-core PRIVATE -DMEDIA_LAYER_TRAMPOLINE_GUEST) + # Install + if(MCPI_USE_MEDIA_LAYER_TRAMPOLINE) + install(TARGETS media-layer-core DESTINATION "${MCPI_LIB_DIR}") + endif() + install(TARGETS media-layer-core EXPORT sdk DESTINATION "${MCPI_SDK_LIB_DIR}") +endif() diff --git a/media-layer/trampoline/src/GLESv1_CM.c b/media-layer/trampoline/src/GLESv1_CM.c new file mode 100644 index 00000000..33bced81 --- /dev/null +++ b/media-layer/trampoline/src/GLESv1_CM.c @@ -0,0 +1,581 @@ +#include + +#include +#include + +#include "common/common.h" + +CALL(11, glFogfv, void, (GLenum pname, const GLfloat *params)) +#if defined(MEDIA_LAYER_TRAMPOLINE_GUEST) + trampoline(pname, (uint32_t) params); +#else + GLenum pname = next_int(); + GLfloat *params = next_ptr(); + // Run + func(pname, params); +#endif +} + +// 'pointer' Is Only Supported As An Integer, Not As An Actual Pointer +#if defined(MEDIA_LAYER_TRAMPOLINE_GUEST) +#define CALL_GL_POINTER(unique_id, name) \ + CALL(unique_id, name, void, (GLint size, GLenum type, GLsizei stride, const void *pointer)) \ + trampoline(size, type, stride, (uint32_t) pointer); \ + } +#else +#define CALL_GL_POINTER(unique_id, name) \ + CALL(unique_id, name, unused, unused) \ + GLint size = next_int(); \ + GLenum type = next_int(); \ + GLsizei stride = next_int(); \ + const void *pointer = (const void *) (uint64_t) next_int(); \ + /* Run */ \ + func(size, type, stride, pointer); \ + } +#endif + +CALL_GL_POINTER(12, glVertexPointer) + +CALL(13, glLineWidth, void, (GLfloat width)) +#if defined(MEDIA_LAYER_TRAMPOLINE_GUEST) + trampoline(pun_to(uint32_t, width)); +#else + GLfloat width = next_float(); + // Run + func(width); +#endif +} + +CALL(14, glBlendFunc, void, (GLenum sfactor, GLenum dfactor)) +#if defined(MEDIA_LAYER_TRAMPOLINE_GUEST) + trampoline(sfactor, dfactor); +#else + GLenum sfactor = next_int(); + GLenum dfactor = next_int(); + // Run + func(sfactor, dfactor); +#endif +} + +CALL(15, glDrawArrays, void, (GLenum mode, GLint first, GLsizei count)) +#if defined(MEDIA_LAYER_TRAMPOLINE_GUEST) + trampoline(mode, first, count); +#else + GLenum mode = next_int(); + GLint first = next_int(); + GLsizei count = next_int(); + // Run + func(mode, first, count); +#endif +} + +CALL(16, glColor4f, void, (GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha)) +#if defined(MEDIA_LAYER_TRAMPOLINE_GUEST) + trampoline(pun_to(uint32_t, red), pun_to(uint32_t, green), pun_to(uint32_t, blue), pun_to(uint32_t, alpha)); +#else + GLfloat red = next_float(); + GLfloat green = next_float(); + GLfloat blue = next_float(); + GLfloat alpha = next_float(); + // Run + func(red, green, blue, alpha); +#endif +} + +CALL(17, glClear, void, (GLbitfield mask)) +#if defined(MEDIA_LAYER_TRAMPOLINE_GUEST) + trampoline(mask); +#else + GLbitfield mask = next_int(); + // Run + func(mask); +#endif +} + +CALL(18, glBufferData, void, (GLenum target, GLsizeiptr size, const void *data, GLenum usage)) +#if defined(MEDIA_LAYER_TRAMPOLINE_GUEST) + trampoline(target, size, (uint32_t) data, usage); +#else + GLenum target = next_int(); + GLsizeiptr size = next_int(); + const void *data = next_ptr(); + GLenum usage = next_int(); + // Run + func(target, size, data, usage); +#endif +} + +CALL(19, glFogx, void, (GLenum pname, GLfixed param)) +#if defined(MEDIA_LAYER_TRAMPOLINE_GUEST) + trampoline(pname, param); +#else + GLenum pname = next_int(); + GLfixed param = next_int(); + // Run + func(pname, param); +#endif +} + +CALL(20, glFogf, void, (GLenum pname, GLfloat param)) +#if defined(MEDIA_LAYER_TRAMPOLINE_GUEST) + trampoline(pname, pun_to(uint32_t, param)); +#else + GLenum pname = next_int(); + GLfloat param = next_float(); + // Run + func(pname, param); +#endif +} + +CALL(21, glMatrixMode, void, (GLenum mode)) +#if defined(MEDIA_LAYER_TRAMPOLINE_GUEST) + trampoline(mode); +#else + GLenum mode = next_int(); + // Run + func(mode); +#endif +} + +CALL_GL_POINTER(22, glColorPointer) + +CALL(23, glScissor, void, (GLint x, GLint y, GLsizei width, GLsizei height)) +#if defined(MEDIA_LAYER_TRAMPOLINE_GUEST) + trampoline(x, y, width, height); +#else + GLint x = next_int(); + GLint y = next_int(); + GLsizei width = next_int(); + GLsizei height = next_int(); + // Run + func(x, y, width, height); +#endif +} + +CALL(24, glTexParameteri, void, (GLenum target, GLenum pname, GLint param)) +#if defined(MEDIA_LAYER_TRAMPOLINE_GUEST) + trampoline(target, pname, param); +#else + GLenum target = next_int(); + GLenum pname = next_int(); + GLint param = next_int(); + // Run + func(target, pname, param); +#endif +} + +CALL(25, glTexImage2D, void, (GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height, GLint border, GLenum format, GLenum type, const void *pixels)) +#if defined(MEDIA_LAYER_TRAMPOLINE_GUEST) + trampoline(target, level, internalformat, width, height, border, format, type, (uint32_t) pixels); +#else + GLenum target = next_int(); + GLint level = next_int(); + GLint internalformat = next_int(); + GLsizei width = next_int(); + GLsizei height = next_int(); + GLint border = next_int(); + GLenum format = next_int(); + GLenum type = next_int(); + const void *pixels = next_ptr(); + // Run + func(target, level, internalformat, width, height, border, format, type, pixels); +#endif +} + +CALL(26, glEnable, void, (GLenum cap)) +#if defined(MEDIA_LAYER_TRAMPOLINE_GUEST) + trampoline(cap); +#else + GLenum cap = next_int(); + // Run + func(cap); +#endif +} + +CALL(27, glEnableClientState, void, (GLenum array)) +#if defined(MEDIA_LAYER_TRAMPOLINE_GUEST) + trampoline(array); +#else + GLenum array = next_int(); + // Run + func(array); +#endif +} + +CALL(28, glPolygonOffset, void, (GLfloat factor, GLfloat units)) +#if defined(MEDIA_LAYER_TRAMPOLINE_GUEST) + trampoline(pun_to(uint32_t, factor), pun_to(uint32_t, units)); +#else + GLfloat factor = next_float(); + GLfloat units = next_float(); + // Run + func(factor, units); +#endif +} + +CALL_GL_POINTER(41, glTexCoordPointer) + +CALL(29, glDisableClientState, void, (GLenum array)) +#if defined(MEDIA_LAYER_TRAMPOLINE_GUEST) + trampoline(array); +#else + GLenum array = next_int(); + // Run + func(array); +#endif +} + +CALL(30, glDepthRangef, void, (GLclampf near, GLclampf far)) +#if defined(MEDIA_LAYER_TRAMPOLINE_GUEST) + trampoline(pun_to(uint32_t, near), pun_to(uint32_t, far)); +#else + GLclampf near = next_float(); + GLclampf far = next_float(); + // Run + func(near, far); +#endif +} + +CALL(31, glDepthFunc, void, (GLenum func)) +#if defined(MEDIA_LAYER_TRAMPOLINE_GUEST) + trampoline(func); +#else + GLenum func2 = next_int(); + // Run + func(func2); +#endif +} + +CALL(32, glBindBuffer, void, (GLenum target, GLuint buffer)) +#if defined(MEDIA_LAYER_TRAMPOLINE_GUEST) + trampoline(target, buffer); +#else + GLenum target = next_int(); + GLenum buffer = next_int(); + // Run + func(target, buffer); +#endif +} + +CALL(33, glClearColor, void, (GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha)) +#if defined(MEDIA_LAYER_TRAMPOLINE_GUEST) + trampoline(pun_to(uint32_t, red), pun_to(uint32_t, green), pun_to(uint32_t, blue), pun_to(uint32_t, alpha)); +#else + GLclampf red = next_float(); + GLclampf green = next_float(); + GLclampf blue = next_float(); + GLclampf alpha = next_float(); + // Run + func(red, green, blue, alpha); +#endif +} + +CALL(34, glPopMatrix, void, ()) +#if defined(MEDIA_LAYER_TRAMPOLINE_GUEST) + trampoline(); +#else + // Run + func(); +#endif +} + +CALL(35, glLoadIdentity, void, ()) +#if defined(MEDIA_LAYER_TRAMPOLINE_GUEST) + trampoline(); +#else + // Run + func(); +#endif +} + +CALL(36, glScalef, void, (GLfloat x, GLfloat y, GLfloat z)) +#if defined(MEDIA_LAYER_TRAMPOLINE_GUEST) + trampoline(pun_to(uint32_t, x), pun_to(uint32_t, y), pun_to(uint32_t, z)); +#else + GLfloat x = next_float(); + GLfloat y = next_float(); + GLfloat z = next_float(); + // Run + func(x, y, z); +#endif +} + +CALL(37, glPushMatrix, void, ()) +#if defined(MEDIA_LAYER_TRAMPOLINE_GUEST) + trampoline(); +#else + // Run + func(); +#endif +} + +CALL(38, glDepthMask, void, (GLboolean flag)) +#if defined(MEDIA_LAYER_TRAMPOLINE_GUEST) + trampoline(flag); +#else + GLboolean flag = next_int(); + // Run + func(flag); +#endif +} + +CALL(39, glHint, void, (GLenum target, GLenum mode)) +#if defined(MEDIA_LAYER_TRAMPOLINE_GUEST) + trampoline(target, mode); +#else + GLenum target = next_int(); + GLenum mode = next_int(); + // Run + func(target, mode); +#endif +} + +CALL(40, glMultMatrixf, void, (const GLfloat *m)) +#if defined(MEDIA_LAYER_TRAMPOLINE_GUEST) + trampoline((uint32_t) m); +#else + GLfloat *m = next_ptr(); + // Run + func(m); +#endif +} + +CALL(42, glDeleteBuffers, void, (GLsizei n, const GLuint *buffers)) +#if defined(MEDIA_LAYER_TRAMPOLINE_GUEST) + trampoline(n, (uint32_t) buffers); +#else + GLsizei n = next_int(); + GLuint *buffers = next_ptr(); + // Run + func(n, buffers); +#endif +} + +CALL(43, glColorMask, void, (GLboolean red, GLboolean green, GLboolean blue, GLboolean alpha)) +#if defined(MEDIA_LAYER_TRAMPOLINE_GUEST) + trampoline(red, green, blue, alpha); +#else + GLboolean red = next_int(); + GLboolean green = next_int(); + GLboolean blue = next_int(); + GLboolean alpha = next_int(); + // Run + func(red, green, blue, alpha); +#endif +} + +CALL(44, glTexSubImage2D, void, (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLenum type, const void *pixels)) +#if defined(MEDIA_LAYER_TRAMPOLINE_GUEST) + trampoline(target, level, xoffset, yoffset, width, height, format, type, (uint32_t) pixels); +#else + GLenum target = next_int(); + GLint level = next_int(); + GLint xoffset = next_int(); + GLint yoffset = next_int(); + GLsizei width = next_int(); + GLsizei height = next_int(); + GLenum format = next_int(); + GLenum type = next_int(); + const void *pixels = next_ptr(); + // Run + func(target, level, xoffset, yoffset, width, height, format, type, pixels); +#endif +} + +CALL(45, glGenTextures, void, (GLsizei n, GLuint *textures)) +#if defined(MEDIA_LAYER_TRAMPOLINE_GUEST) + trampoline(n, (uint32_t) textures); +#else + GLsizei n = next_int(); + GLuint *textures = next_ptr(); + // Run + func(n, textures); +#endif +} + +CALL(46, glDeleteTextures, void, (GLsizei n, const GLuint *textures)) +#if defined(MEDIA_LAYER_TRAMPOLINE_GUEST) + trampoline(n, (uint32_t) textures); +#else + GLsizei n = next_int(); + GLuint *textures = next_ptr(); + // Run + func(n, textures); +#endif +} + +CALL(47, glAlphaFunc, void, (GLenum func, GLclampf ref)) +#if defined(MEDIA_LAYER_TRAMPOLINE_GUEST) + trampoline(func, pun_to(uint32_t, ref)); +#else + GLenum func2 = next_int(); + GLclampf ref = next_float(); + // Run + func(func2, ref); +#endif +} + +CALL(48, glGetFloatv, void, (GLenum pname, GLfloat *params)) +#if defined(MEDIA_LAYER_TRAMPOLINE_GUEST) + trampoline(pname, (uint32_t) params); +#else + GLenum pname = next_int(); + GLfloat *params = next_ptr(); + // Run + func(pname, params); +#endif +} + +CALL(49, glBindTexture, void, (GLenum target, GLuint texture)) +#if defined(MEDIA_LAYER_TRAMPOLINE_GUEST) + trampoline(target, texture); +#else + GLenum target = next_int(); + GLuint texture = next_int(); + // Run + func(target, texture); +#endif +} + +CALL(50, glTranslatef, void, (GLfloat x, GLfloat y, GLfloat z)) +#if defined(MEDIA_LAYER_TRAMPOLINE_GUEST) + trampoline(pun_to(uint32_t, x), pun_to(uint32_t, y), pun_to(uint32_t, z)); +#else + GLfloat x = next_float(); + GLfloat y = next_float(); + GLfloat z = next_float(); + // Run + func(x, y, z); +#endif +} + +CALL(51, glShadeModel, void, (GLenum mode)) +#if defined(MEDIA_LAYER_TRAMPOLINE_GUEST) + trampoline(mode); +#else + GLenum mode = next_int(); + // Run + func(mode); +#endif +} + +CALL(52, glOrthof, void, (GLfloat left, GLfloat right, GLfloat bottom, GLfloat top, GLfloat near, GLfloat far)) +#if defined(MEDIA_LAYER_TRAMPOLINE_GUEST) + trampoline(pun_to(uint32_t, left), pun_to(uint32_t, right), pun_to(uint32_t, bottom), pun_to(uint32_t, top), pun_to(uint32_t, near), pun_to(uint32_t, far)); +#else + GLfloat left = next_float(); + GLfloat right = next_float(); + GLfloat bottom = next_float(); + GLfloat top = next_float(); + GLfloat near = next_float(); + GLfloat far = next_float(); + // Run + func(left, right, bottom, top, near, far); +#endif +} + +CALL(53, glDisable, void, (GLenum cap)) +#if defined(MEDIA_LAYER_TRAMPOLINE_GUEST) + trampoline(cap); +#else + GLenum cap = next_int(); + // Run + func(cap); +#endif +} + +CALL(54, glCullFace, void, (GLenum mode)) +#if defined(MEDIA_LAYER_TRAMPOLINE_GUEST) + trampoline(mode); +#else + GLenum mode = next_int(); + // Run + func(mode); +#endif +} + +CALL(55, glRotatef, void, (GLfloat angle, GLfloat x, GLfloat y, GLfloat z)) +#if defined(MEDIA_LAYER_TRAMPOLINE_GUEST) + trampoline(pun_to(uint32_t, angle), pun_to(uint32_t, x), pun_to(uint32_t, y), pun_to(uint32_t, z)); +#else + GLfloat angle = next_float(); + GLfloat x = next_float(); + GLfloat y = next_float(); + GLfloat z = next_float(); + // Run + func(angle, x, y, z); +#endif +} + +CALL(56, glViewport, void, (GLint x, GLint y, GLsizei width, GLsizei height)) +#if defined(MEDIA_LAYER_TRAMPOLINE_GUEST) + trampoline(x, y, width, height); +#else + GLint x = next_int(); + GLint y = next_int(); + GLsizei width = next_int(); + GLsizei height = next_int(); + // Run + func(x, y, width, height); +#endif +} + +CALL(57, glNormal3f, void, (GLfloat nx, GLfloat ny, GLfloat nz)) +#if defined(MEDIA_LAYER_TRAMPOLINE_GUEST) + trampoline(pun_to(uint32_t, nx), pun_to(uint32_t, ny), pun_to(uint32_t, nz)); +#else + GLfloat nx = next_float(); + GLfloat ny = next_float(); + GLfloat nz = next_float(); + // Run + func(nx, ny, nz); +#endif +} + +CALL(58, glIsEnabled, GLboolean, (GLenum cap)) +#if defined(MEDIA_LAYER_TRAMPOLINE_GUEST) + return trampoline(cap); +#else + GLenum cap = next_int(); + // Run + ret(func(cap)); +#endif +} + +CALL(61, glGetIntegerv, void, (GLenum pname, GLint *params)) +#if defined(MEDIA_LAYER_TRAMPOLINE_GUEST) + trampoline(pname, (uint32_t) params); +#else + GLenum pname = next_int(); + GLint *params = next_ptr(); + // Run + func(pname, params); +#endif +} + +CALL(65, glReadPixels, void, (GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, GLenum type, void *data)) +#if defined(MEDIA_LAYER_TRAMPOLINE_GUEST) + trampoline(x, y, width, height, format, type, (uint32_t) data); +#else + GLint x = next_int(); + GLint y = next_int(); + GLsizei width = next_int(); + GLsizei height = next_int(); + GLenum format = next_int(); + GLenum type = next_int(); + void *data = next_ptr(); + // Run + func(x, y, width, height, format, type, data); +#endif +} + +CALL(67, glGenBuffers, void, (GLsizei n, GLuint *buffers)) +#if defined(MEDIA_LAYER_TRAMPOLINE_GUEST) + trampoline(n, (uint32_t) buffers); +#else + GLsizei n = next_int(); + GLuint *buffers = next_ptr(); + // Run + func(n, buffers); +#endif +} diff --git a/media-layer/trampoline/src/common/common.h b/media-layer/trampoline/src/common/common.h new file mode 100644 index 00000000..cd19826b --- /dev/null +++ b/media-layer/trampoline/src/common/common.h @@ -0,0 +1,21 @@ +#pragma once + +#if __BYTE_ORDER != __LITTLE_ENDIAN +#error "Only Little Endian Is Supported" +#endif + +#if defined(MEDIA_LAYER_TRAMPOLINE_HOST) +#include "../host/host.h" +#elif defined(MEDIA_LAYER_TRAMPOLINE_GUEST) +#include "../guest/guest.h" +#else +#error "Invalid Configuration" +#endif + +//#define pun_to(type, x) (*(type *) &(x)) +#define pun_to(type, x) \ + ({ \ + union { typeof(x) a; type b; } _pun; \ + _pun.a = x; \ + _pun.b; \ + }) diff --git a/media-layer/trampoline/src/guest/guest.c b/media-layer/trampoline/src/guest/guest.c new file mode 100644 index 00000000..c4f80eb2 --- /dev/null +++ b/media-layer/trampoline/src/guest/guest.c @@ -0,0 +1,15 @@ +#include +#include + +#include "guest.h" + +uint32_t _trampoline(uint32_t id, uint32_t *args) { + // Make Syscall + long ret = syscall(0x1337 /* See trampoline.patch */, id, args); + if (ret == -1) { + // Error + ERR("Trampoline Error: %s", strerror(errno)); + } + // Return + return args[0]; +} \ No newline at end of file diff --git a/media-layer/trampoline/src/guest/guest.h b/media-layer/trampoline/src/guest/guest.h new file mode 100644 index 00000000..42e3c253 --- /dev/null +++ b/media-layer/trampoline/src/guest/guest.h @@ -0,0 +1,12 @@ +#pragma once + +#include + +// Trampoline Function +uint32_t _trampoline(uint32_t id, uint32_t *args); +#define trampoline(...) _trampoline(_id, (uint32_t[]){__VA_ARGS__}) + +// Macro +#define CALL(unique_id, name, return_type, args) \ + return_type name args { \ + static unsigned char _id = unique_id; diff --git a/media-layer/trampoline/src/host/host.c b/media-layer/trampoline/src/host/host.c new file mode 100644 index 00000000..1d5ef9ef --- /dev/null +++ b/media-layer/trampoline/src/host/host.c @@ -0,0 +1,17 @@ +#include + +#include "host.h" + +// Registration +static handler_t *handlers[256]; +void _add_handler(unsigned char id, handler_t *handler) { + if (handlers[id]) { + ERR("Conflicting Trampolines For ID: %i", (int) id); + } + handlers[id] = handler; +} + +// Trampoline +void trampoline(g2h_t g2h, uint32_t id, uint32_t *args) { + handlers[id](g2h, args); +} \ No newline at end of file diff --git a/media-layer/trampoline/src/host/host.h b/media-layer/trampoline/src/host/host.h new file mode 100644 index 00000000..fb3fdd60 --- /dev/null +++ b/media-layer/trampoline/src/host/host.h @@ -0,0 +1,27 @@ +#pragma once + +#include + +// Trampoline Function +typedef void *(*g2h_t)(uint32_t guest_addr); +void trampoline(g2h_t g2h, uint32_t id, uint32_t *args); // See trampoline.patch + +// Macro +typedef void handler_t(g2h_t g2h, uint32_t *args); +__attribute__((visibility("internal"))) void _add_handler(unsigned char id, handler_t *handler); +#define CALL(unique_id, name, ignored1, ignored2) \ + static handler_t _run_##name; \ + __attribute__((constructor)) static void _init_##name() { \ + _add_handler(unique_id, _run_##name); \ + } \ + static void _run_##name(__attribute__((unused)) g2h_t g2h, __attribute__((unused)) uint32_t *args) { \ + __attribute__((unused)) int _current_arg = 0; \ + static typeof(name) *func = name; + +// Helper Macros +#define next_int() args[_current_arg++] +#define next_ptr() g2h(next_int()) +#define next_float() pun_to(float, next_int()) +#define ret(x) \ + args[0] = x; \ + return; diff --git a/media-layer/trampoline/src/media-layer-core.c b/media-layer/trampoline/src/media-layer-core.c new file mode 100644 index 00000000..0808ce16 --- /dev/null +++ b/media-layer/trampoline/src/media-layer-core.c @@ -0,0 +1,188 @@ +#include + +#include + +#include +#include +#include + +#include "common/common.h" + +// SDL Functions + +CALL(0, SDL_Init, int, (uint32_t flags)) +#if defined(MEDIA_LAYER_TRAMPOLINE_GUEST) + return trampoline(flags); +#else + uint32_t flags = next_int(); + // Run + ret(func(flags)); +#endif +} + +CALL(1, SDL_PollEvent, int, (SDL_Event *event)) +#if defined(MEDIA_LAYER_TRAMPOLINE_GUEST) + return trampoline((uint32_t) event); +#else + SDL_Event *event = next_ptr(); + // Run + ret(func(event)); +#endif +} + +CALL(2, SDL_PushEvent, int, (SDL_Event *event)) +#if defined(MEDIA_LAYER_TRAMPOLINE_GUEST) + return trampoline((uint32_t) event); +#else + SDL_Event *event = next_ptr(); + // Run + ret(func(event)); +#endif +} + +CALL(3, SDL_WM_SetCaption, void, (const char *title, const char *icon)) +#if defined(MEDIA_LAYER_TRAMPOLINE_GUEST) + trampoline((uint32_t) title, (uint32_t) icon); +#else + char *title = next_ptr(); + char *icon = next_ptr(); + // Run + func(title, icon); +#endif +} + +CALL(4, media_toggle_fullscreen, void, ()) +#if defined(MEDIA_LAYER_TRAMPOLINE_GUEST) + trampoline(); +#else + // Run + func(); +#endif +} + +CALL(5, SDL_WM_GrabInput, SDL_GrabMode, (SDL_GrabMode mode)) +#if defined(MEDIA_LAYER_TRAMPOLINE_GUEST) + return trampoline(mode); +#else + SDL_GrabMode mode = next_int(); + // Run + ret(func(mode)); +#endif +} + +CALL(6, SDL_ShowCursor, int, (int32_t toggle)) +#if defined(MEDIA_LAYER_TRAMPOLINE_GUEST) + return trampoline(toggle); +#else + int mode = next_int(); + // Run + ret(func(mode)); +#endif +} + +CALL(8, media_swap_buffers, void, ()) +#if defined(MEDIA_LAYER_TRAMPOLINE_GUEST) + trampoline(); +#else + // Run + func(); +#endif +} + +CALL(9, media_cleanup, void, ()) +#if defined(MEDIA_LAYER_TRAMPOLINE_GUEST) + trampoline(); +#else + // Run + func(); +#endif +} + +CALL(10, media_get_framebuffer_size, void, (int *width, int *height)) +#if defined(MEDIA_LAYER_TRAMPOLINE_GUEST) + trampoline((uint32_t) width, (uint32_t) height); +#else + int *width = next_ptr(); + int *height = next_ptr(); + // Run + func(width, height); +#endif +} + +CALL(59, media_audio_update, void, (float volume, float x, float y, float z, float yaw)) +#if defined(MEDIA_LAYER_TRAMPOLINE_GUEST) + trampoline(pun_to(uint32_t, volume), pun_to(uint32_t, x), pun_to(uint32_t, y), pun_to(uint32_t, z), pun_to(uint32_t, yaw)); +#else + float volume = next_float(); + float x = next_float(); + float y = next_float(); + float z = next_float(); + float yaw = next_float(); + // Run + func(volume, x, y, z, yaw); +#endif +} + +CALL(60, media_audio_play, void, (const char *source, const char *name, float x, float y, float z, float pitch, float volume, int is_ui)) +#if defined(MEDIA_LAYER_TRAMPOLINE_GUEST) + trampoline((uint32_t) source, (uint32_t) name, pun_to(uint32_t, x), pun_to(uint32_t, y), pun_to(uint32_t, z), pun_to(uint32_t, pitch), pun_to(uint32_t, volume), is_ui); +#else + char *source = next_ptr(); + char *name = next_ptr(); + float x = next_float(); + float y = next_float(); + float z = next_float(); + float pitch = next_float(); + float volume = next_float(); + int is_ui = next_int(); + // Run + func(source, name, x, y, z, pitch, volume, is_ui); +#endif +} + +CALL(62, media_set_interactable, void, (int is_interactable)) +#if defined(MEDIA_LAYER_TRAMPOLINE_GUEST) + trampoline(is_interactable); +#else + int is_interactable = next_int(); + // Run + func(is_interactable); +#endif +} + +CALL(63, media_disable_vsync, void, ()) +#if defined(MEDIA_LAYER_TRAMPOLINE_GUEST) + trampoline(); +#else + // Run + func(); +#endif +} + +CALL(64, media_set_raw_mouse_motion_enabled, void, (int enabled)) +#if defined(MEDIA_LAYER_TRAMPOLINE_GUEST) + trampoline(enabled); +#else + int enabled = next_int(); + // Run + func(enabled); +#endif +} + +CALL(66, media_force_egl, void, ()) +#if defined(MEDIA_LAYER_TRAMPOLINE_GUEST) + trampoline(); +#else + // Run + func(); +#endif +} + +CALL(68, media_ensure_loaded, void, ()) +#if defined(MEDIA_LAYER_TRAMPOLINE_GUEST) + trampoline(); +#else + // Run + func(); +#endif +}