1313#include <GL/osmesa.h>
1414#include "ctxbridges/osmesa_loader.h"
1515#include "driver_helper/nsbypass.h"
16- #include <android/log.h>
1716
1817#ifdef GLES_TEST
1918#include <GLES2/gl2.h>
3938// This means that you are forced to have this function/variable for ABI compatibility
4039#define ABI_COMPAT __attribute__((unused))
4140
42- #define TRY_ATTACH_ENV (env_name , vm , error_message , then ) JNIEnv* env_name;\
43- do { \
44- env_name = get_attached_env(vm); \
45- if(env_name == NULL) { \
46- printf(error_message); \
47- then \
48- } \
49- } while(0)
50-
5141struct PotatoBridge {
5242
5343 /* EGLContext */ void * eglContext ;
@@ -69,6 +59,8 @@ struct PotatoBridge potatoBridge;
6959#define RENDERER_VK_ZINK 2
7060#define RENDERER_VULKAN 4
7161
62+ extern void destroyAllCursors ();
63+
7264EXTERNAL_API void pojavTerminate () {
7365 printf ("EGLBridge: Terminating\n" );
7466
@@ -91,19 +83,7 @@ EXTERNAL_API void pojavTerminate() {
9183 } break ;
9284 }
9385
94- TRY_ATTACH_ENV (env , pojav_environ -> dalvikJavaVMPtr , "Failed to attach to env from pojavTerminate!\n" , return ;);
95-
96- LinkedListNode * current = pojav_environ -> cursors -> first ;
97- while (current ) {
98- LinkedListNode * next = current -> next ;
99- (* env )-> DeleteGlobalRef (env , current -> value );
100- free (current );
101- current = next ;
102- }
103- pojav_environ -> cursors -> first = NULL ;
104- pojav_environ -> cursors -> last = NULL ;
105-
106- (* env )-> CallStaticVoidMethod (env , pojav_environ -> bridgeClazz , pojav_environ -> method_setCursor , NULL );
86+ destroyAllCursors ();
10787}
10888
10989JNIEXPORT void JNICALL Java_net_kdt_pojavlaunch_utils_JREUtils_setupBridgeWindow (JNIEnv * env , ABI_COMPAT jclass clazz , jobject surface ) {
@@ -271,49 +251,4 @@ Java_org_lwjgl_vulkan_VK_getVulkanDriverHandle(ABI_COMPAT JNIEnv *env, ABI_COMPA
271251
272252EXTERNAL_API void pojavSwapInterval (int interval ) {
273253 br_swap_interval (interval );
274- }
275-
276- EXTERNAL_API LinkedListNode * pojavCreateCursor (GLFWimage * image , int xhot , int yhot ) {
277- if (image == NULL ) {
278- printf ("Passed image is null!\n" );
279- return NULL ;
280- }
281-
282- TRY_ATTACH_ENV (env , pojav_environ -> dalvikJavaVMPtr , "failed to attach env from pojavCreateCursor!\n" , return NULL ;);
283- size_t imageBytes = image -> width * image -> height * 4 ;
284- jobject buffer = (* env )-> NewDirectByteBuffer (env , image -> pixels , imageBytes );
285- if (buffer == NULL ) {
286- printf ("Failed to create ByteBuffer for cursor image!\n" );
287- return NULL ;
288- }
289-
290- jobject cursor = (* env )-> CallStaticObjectMethod (env , pojav_environ -> bridgeClazz ,
291- pojav_environ -> method_createCursor , buffer ,
292- image -> width , image -> height , xhot , yhot );
293- jobject globalCursor = (* env )-> NewGlobalRef (env , cursor );
294- // not needed anymore
295- (* env )-> DeleteLocalRef (env , cursor );
296- (* env )-> DeleteLocalRef (env , buffer );
297-
298- return linkedlist_append (pojav_environ -> cursors , globalCursor );
299- }
300-
301- EXTERNAL_API void pojavSetCursor (__attribute__((unused )) void * window , LinkedListNode * cursor ) {
302- jobject value = NULL ;
303- if (cursor ) value = cursor -> value ;
304- TRY_ATTACH_ENV (env , pojav_environ -> dalvikJavaVMPtr , "failed to attach env from pojavSetCursor!\n" , return ;);
305- (* env )-> CallStaticVoidMethod (env , pojav_environ -> bridgeClazz , pojav_environ -> method_setCursor , value );
306- }
307-
308- EXTERNAL_API void pojavDestroyCursor (LinkedListNode * cursor ) {
309- if (cursor == NULL || cursor -> value == NULL ) {
310- printf ("Passed cursor to pojavDestroyCursor is null!\n" );
311- return ;
312- }
313-
314- TRY_ATTACH_ENV (env , pojav_environ -> dalvikJavaVMPtr , "failed to attach env from pojavDestroyCursor!\n" , return ;);
315- (* env )-> CallStaticVoidMethod (env , pojav_environ -> bridgeClazz , pojav_environ -> method_removeCursor , cursor -> value );
316-
317- (* env )-> DeleteGlobalRef (env , cursor -> value );
318- linkedlist_remove (pojav_environ -> cursors , cursor );
319254}
0 commit comments