Skip to content

Commit 58d1e4d

Browse files
RaydanOMGrartdeell
authored andcommitted
Moved cursor methods to input_bridge_v3.c
1 parent ccf8820 commit 58d1e4d

2 files changed

Lines changed: 65 additions & 68 deletions

File tree

app_pojavlauncher/src/main/jni/egl_bridge.c

Lines changed: 3 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
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>
@@ -39,15 +38,6 @@
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-
5141
struct 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+
7264
EXTERNAL_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

10989
JNIEXPORT 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

272252
EXTERNAL_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
}

app_pojavlauncher/src/main/jni/input_bridge_v3.c

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -575,4 +575,66 @@ Java_org_lwjgl_glfw_CallbackBridge_nativeCreateGamepadButtonBuffer(JNIEnv *env,
575575
JNIEXPORT jobject JNICALL
576576
Java_org_lwjgl_glfw_CallbackBridge_nativeCreateGamepadAxisBuffer(JNIEnv *env, jclass clazz) {
577577
return (*env)->NewDirectByteBuffer(env, &pojav_environ->gamepadState.axes, sizeof(pojav_environ->gamepadState.axes));
578+
}
579+
580+
void destroyAllCursors() {
581+
TRY_ATTACH_ENV(env, pojav_environ->dalvikJavaVMPtr, "Failed to attach to env from pojavTerminate!\n", return;);
582+
583+
LinkedListNode* current = pojav_environ->cursors->first;
584+
while (current) {
585+
LinkedListNode* next = current->next;
586+
(*env)->DeleteGlobalRef(env, current->value);
587+
free(current);
588+
current = next;
589+
}
590+
pojav_environ->cursors->first = NULL;
591+
pojav_environ->cursors->last = NULL;
592+
593+
(*env)->CallStaticVoidMethod(env, pojav_environ->bridgeClazz, pojav_environ->method_setCursor, NULL);
594+
}
595+
596+
// the methods below are called from org/lwjgl/glfw/GLFW
597+
LinkedListNode* pojavCreateCursor(GLFWimage* image, int xhot, int yhot) {
598+
if(image == NULL) {
599+
printf("Passed image is null!\n");
600+
return NULL;
601+
}
602+
603+
TRY_ATTACH_ENV(env, pojav_environ->dalvikJavaVMPtr, "failed to attach env from pojavCreateCursor!\n", return NULL;);
604+
size_t imageBytes = image->width * image->height * 4;
605+
jobject buffer = (*env)->NewDirectByteBuffer(env, image->pixels, imageBytes);
606+
if(buffer == NULL) {
607+
printf("Failed to create ByteBuffer for cursor image!\n");
608+
return NULL;
609+
}
610+
611+
jobject cursor = (*env)->CallStaticObjectMethod(env, pojav_environ->bridgeClazz,
612+
pojav_environ->method_createCursor, buffer,
613+
image->width, image->height, xhot, yhot);
614+
jobject globalCursor = (*env)->NewGlobalRef(env, cursor);
615+
// not needed anymore
616+
(*env)->DeleteLocalRef(env, cursor);
617+
(*env)->DeleteLocalRef(env, buffer);
618+
619+
return linkedlist_append(pojav_environ->cursors, globalCursor);
620+
}
621+
622+
void pojavSetCursor(__attribute__((unused)) void* window, LinkedListNode* cursor) {
623+
jobject value = NULL;
624+
if(cursor) value = cursor->value;
625+
TRY_ATTACH_ENV(env, pojav_environ->dalvikJavaVMPtr, "failed to attach env from pojavSetCursor!\n", return;);
626+
(*env)->CallStaticVoidMethod(env, pojav_environ->bridgeClazz, pojav_environ->method_setCursor, value);
627+
}
628+
629+
void pojavDestroyCursor(LinkedListNode* cursor) {
630+
if(cursor == NULL || cursor->value == NULL) {
631+
printf("Passed cursor to pojavDestroyCursor is null!\n");
632+
return;
633+
}
634+
635+
TRY_ATTACH_ENV(env, pojav_environ->dalvikJavaVMPtr, "failed to attach env from pojavDestroyCursor!\n", return;);
636+
(*env)->CallStaticVoidMethod(env, pojav_environ->bridgeClazz, pojav_environ->method_removeCursor, cursor->value);
637+
638+
(*env)->DeleteGlobalRef(env, cursor->value);
639+
linkedlist_remove(pojav_environ->cursors, cursor);
578640
}

0 commit comments

Comments
 (0)