Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
initial steps to support macOS ARM
  • Loading branch information
samyk committed Jun 25, 2023
commit 5fb3dd7d3b50bd3210bbb79a08036186e99ab397
81 changes: 51 additions & 30 deletions JSyphon/native_src/jsyphon_JSyphonClient.m
Original file line number Diff line number Diff line change
@@ -1,15 +1,6 @@
#import <JavaVM/JavaVM.h>
#import <JavaNativeFoundation/JavaNativeFoundation.h> // JNI Cocoa helper
#import <JavaVM/jni.h>

#import <Cocoa/Cocoa.h>
#import <OpenGL/OpenGL.h>
#import <Syphon/Syphon.h>

#import "jsyphon_imports.h"
#import <SyphonNameboundClient.h>

#import <OpenGL/CGLMacro.h>

// pass options in case they are needed in the future...
JNIEXPORT jlong JNICALL Java_jsyphon_JSyphonClient_init(JNIEnv * env, jobject jobj, jobject options)
{
Expand Down Expand Up @@ -81,7 +72,26 @@ JNIEXPORT jboolean JNICALL Java_jsyphon_JSyphonClient_isValid(JNIEnv * env, jobj
JNIEXPORT jobject JNICALL Java_jsyphon_JSyphonClient_serverDescription(JNIEnv * env, jobject jobj, jlong ptr)
{
jobject serverdesc = nil;

// This methods returns a ArrayList<String>:
// (realm kdc* null) null (mapping-domain mapping-realm)*
jclass jc_arrayListClass = (*env)->FindClass(env, "java/util/ArrayList");
CHECK_NULL_RETURN(jc_arrayListClass, NULL);
jmethodID jm_arrayListCons = (*env)->GetMethodID(env, jc_arrayListClass, "<init>", "()V");
CHECK_NULL_RETURN(jm_arrayListCons, NULL);
jmethodID jm_listAdd = (*env)->GetMethodID(env, jc_arrayListClass, "add", "(Ljava/lang/Object;)Z");
CHECK_NULL_RETURN(jm_listAdd, NULL);
serverdesc = (*env)->NewObject(env, jc_arrayListClass, jm_arrayListCons);
CHECK_NULL_RETURN(serverdesc, NULL);

SyphonNameboundClient* boundClient = jlong_to_ptr(ptr);
[boundClient lockClient];
SyphonClient *client = [(SyphonNameboundClient*)boundClient client];
ADD(serverdesc, client);
ADDNULL(serverdesc);
[boundClient unlockClient];
return serverdesc;

/*
JNF_COCOA_ENTER(env);

SyphonNameboundClient* boundClient = jlong_to_ptr(ptr);
Expand All @@ -100,6 +110,7 @@ JNIEXPORT jobject JNICALL Java_jsyphon_JSyphonClient_serverDescription(JNIEnv *
JNF_COCOA_EXIT(env);

return serverdesc;
*/
}


Expand Down Expand Up @@ -127,37 +138,47 @@ JNIEXPORT jobject JNICALL Java_jsyphon_JSyphonClient_newFrameDataForContext(JNIE
{
jobject imgdata = nil;

JNF_COCOA_ENTER(env);
//JNF_COCOA_ENTER(env);

SyphonNameboundClient* boundClient = jlong_to_ptr(ptr);
SyphonNameboundClient* boundClient = jlong_to_ptr(ptr);
[boundClient lockClient];
SyphonClient *client = [(SyphonNameboundClient*)boundClient client];

SyphonImage* img = [client newFrameImage];
SyphonImage* img = [client newFrameImage];

NSSize texSize = [img textureSize];

NSNumber *name = [NSNumber numberWithInt:[img textureName]];
NSNumber *width = [NSNumber numberWithFloat:texSize.width];
NSNumber *height = [NSNumber numberWithFloat:texSize.height];

NSDictionary *dic = [[NSDictionary alloc] initWithObjectsAndKeys:
name, @"name",
width, @"width",
height, @"height",
nil];


JNFTypeCoercer* coecer = [JNFDefaultCoercions defaultCoercer];
[JNFDefaultCoercions addMapCoercionTo:coecer];

imgdata = [coecer coerceNSObject:dic withEnv:env];
NSNumber *name = [NSNumber numberWithInt:[img textureName]];
NSNumber *width = [NSNumber numberWithFloat:texSize.width];
NSNumber *height = [NSNumber numberWithFloat:texSize.height];

NSDictionary *dic = [[NSDictionary alloc] initWithObjectsAndKeys:
name, @"name",
width, @"width",
height, @"height",
nil];

jclass jc_arrayListClass = (*env)->FindClass(env, "java/util/ArrayList");
CHECK_NULL_RETURN(jc_arrayListClass, NULL);
jmethodID jm_arrayListCons = (*env)->GetMethodID(env, jc_arrayListClass, "<init>", "()V");
CHECK_NULL_RETURN(jm_arrayListCons, NULL);
jmethodID jm_listAdd = (*env)->GetMethodID(env, jc_arrayListClass, "add", "(Ljava/lang/Object;)Z");
CHECK_NULL_RETURN(jm_listAdd, NULL);
imgdata = (*env)->NewObject(env, jc_arrayListClass, jm_arrayListCons);
CHECK_NULL_RETURN(imgdata, NULL);

//JNFTypeCoercer* coecer = [JNFDefaultCoercions defaultCoercer];
//[JNFDefaultCoercions addMapCoercionTo:coecer];

ADD(imgdata, dic);
ADDNULL(imgdata);
//imgdata = [coecer coerceNSObject:dic withEnv:env];

[img release];

[boundClient unlockClient];

JNF_COCOA_EXIT(env);
//JNF_COCOA_EXIT(env);

return imgdata;
}
Expand Down
10 changes: 1 addition & 9 deletions JSyphon/native_src/jsyphon_JSyphonImage.m
Original file line number Diff line number Diff line change
@@ -1,12 +1,4 @@
#import <JavaVM/JavaVM.h>
#import <JavaNativeFoundation/JavaNativeFoundation.h> // JNI Cocoa helper
#import <JavaVM/jni.h>

#import <Cocoa/Cocoa.h>
#import <OpenGL/OpenGL.h>
#import <Syphon/Syphon.h>

#import <OpenGL/CGLMacro.h>
#import "jsyphon_imports.h"


JNIEXPORT jint JNICALL Java_jsyphon_JSyphonImage_textureName(JNIEnv * env, jobject jobj)
Expand Down
49 changes: 28 additions & 21 deletions JSyphon/native_src/jsyphon_JSyphonServer.m
Original file line number Diff line number Diff line change
@@ -1,36 +1,43 @@
#import <JavaVM/JavaVM.h>
#import <JavaNativeFoundation/JavaNativeFoundation.h> // JNI Cocoa helper
#import <JavaVM/jni.h>

#import <Cocoa/Cocoa.h>
#import <OpenGL/OpenGL.h>
#import <Syphon/Syphon.h>

#import <OpenGL/CGLMacro.h>
#import "jsyphon_imports.h"

JNIEXPORT jlong JNICALL Java_jsyphon_JSyphonServer_initWithName (JNIEnv * env, jobject jobj, jstring name, jobject options)
{
jlong ptr = 0;
JNF_COCOA_ENTER(env);

//JNF_COCOA_ENTER(env);

CGLContextObj cgl_ctx = CGLGetCurrentContext();

NSString* sname = JNFJavaToNSString(env, name);

NSDictionary* sopt = nil;
if (options != nil) {
JNFTypeCoercer* coecer = [JNFDefaultCoercions defaultCoercer];
[JNFDefaultCoercions addMapCoercionTo:coecer];
sopt = [coecer coerceJavaObject:options withEnv:env];
jclass jc_arrayListClass = (*env)->FindClass(env, "java/util/ArrayList");
CHECK_NULL_RETURN(jc_arrayListClass, NULL);
jmethodID jm_arrayListCons = (*env)->GetMethodID(env, jc_arrayListClass, "<init>", "()V");
CHECK_NULL_RETURN(jm_arrayListCons, NULL);
jmethodID jm_listAdd = (*env)->GetMethodID(env, jc_arrayListClass, "add", "(Ljava/lang/Object;)Z");
CHECK_NULL_RETURN(jm_listAdd, NULL);
ptr = (*env)->NewObject(env, jc_arrayListClass, jm_arrayListCons);
CHECK_NULL_RETURN(ptr, NULL);

//JNFTypeCoercer* coecer = [JNFDefaultCoercions defaultCoercer];
// [JNFDefaultCoercions addMapCoercionTo:coecer];

ADD(ptr, options);
ADDNULL(ptr);

//JNFTypeCoercer* coecer = [JNFDefaultCoercions defaultCoercer];
//[JNFDefaultCoercions addMapCoercionTo:coecer];
//sopt = [coecer coerceJavaObject:options withEnv:env];
}
SyphonServer* server = [[SyphonServer alloc] initWithName:sname context:cgl_ctx options:nil];

SyphonServer* server = [[SyphonServer alloc] initWithName:sname context:cgl_ctx options:nil];
ptr = ptr_to_jlong(server);

JNF_COCOA_EXIT(env);

return ptr;
//JNF_COCOA_EXIT(env);

return ptr;
}

JNIEXPORT jstring JNICALL Java_jsyphon_JSyphonServer_getName (JNIEnv * env, jobject jobj, jlong ptr)
Expand Down
55 changes: 31 additions & 24 deletions JSyphon/native_src/jsyphon_JSyphonServerList.m
Original file line number Diff line number Diff line change
@@ -1,36 +1,43 @@
#import <JavaVM/JavaVM.h>
#import <JavaNativeFoundation/JavaNativeFoundation.h> // JNI Cocoa helper
#import <JavaVM/jni.h>

#import <Cocoa/Cocoa.h>
#import <OpenGL/OpenGL.h>
#import <Syphon/Syphon.h>

#import <OpenGL/CGLMacro.h>
#import "jsyphon_imports.h"

JNIEXPORT jobject JNICALL Java_jsyphon_JSyphonServerList_getList(JNIEnv * env, jobject jobj)
{
jobject serverlist = nil;
JNF_COCOA_ENTER(env);
jobject serverlist = nil;

//JNF_COCOA_ENTER(env);

NSArray *servers = [[SyphonServerDirectory sharedDirectory] servers];
NSMutableArray *output = [NSMutableArray arrayWithCapacity:[servers count]];

for (NSDictionary *description in servers)
{
NSDictionary *simple = [NSDictionary dictionaryWithObjectsAndKeys:[description objectForKey:SyphonServerDescriptionNameKey], @"Name",
[description objectForKey:SyphonServerDescriptionAppNameKey], @"App Name", nil];
[description objectForKey:SyphonServerDescriptionAppNameKey], @"App Name", nil];
[output addObject:simple];
}

JNFTypeCoercer* coecer = [JNFDefaultCoercions defaultCoercer];
[JNFDefaultCoercions addMapCoercionTo:coecer];

serverlist = [coecer coerceNSObject:servers withEnv:env];

JNF_COCOA_EXIT(env);

return serverlist;

jclass jc_arrayListClass = (*env)->FindClass(env, "java/util/ArrayList");
CHECK_NULL_RETURN(jc_arrayListClass, NULL);
jmethodID jm_arrayListCons = (*env)->GetMethodID(env, jc_arrayListClass, "<init>", "()V");
CHECK_NULL_RETURN(jm_arrayListCons, NULL);
jmethodID jm_listAdd = (*env)->GetMethodID(env, jc_arrayListClass, "add", "(Ljava/lang/Object;)Z");
CHECK_NULL_RETURN(jm_listAdd, NULL);
serverlist = (*env)->NewObject(env, jc_arrayListClass, jm_arrayListCons);
CHECK_NULL_RETURN(serverlist, NULL);

//JNFTypeCoercer* coecer = [JNFDefaultCoercions defaultCoercer];
//[JNFDefaultCoercions addMapCoercionTo:coecer];

ADD(serverlist, servers);
ADDNULL(serverlist);

//JNFTypeCoercer* coecer = [JNFDefaultCoercions defaultCoercer];
//[JNFDefaultCoercions addMapCoercionTo:coecer];

//serverlist = [coecer coerceNSObject:servers withEnv:env];

//JNF_COCOA_EXIT(env);

return serverlist;

}
31 changes: 31 additions & 0 deletions JSyphon/native_src/jsyphon_imports.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#if defined(__arm64__)
// can get ARM-compatible JDK from https://learn.microsoft.com/en-us/java/openjdk/download
// headers will likely install into "/Library/Java/JavaVirtualMachines/microsoft-*.jdk/Contents/Home/include"
#import "jni.h"
#import "jni_md.h"
#import "JNIUtilities.h"
#define JNF_COCOA_ENTER JNI_COCOA_ENTER
#define JNF_COCOA_EXIT JNI_COCOA_EXIT
#define JNFJavaToNSString JavaStringToNSString
#define JNFNSToJavaString NSStringToJavaString

#define ADD(list, str) { \
jobject localeObj = (*env)->NewStringUTF(env, [str UTF8String]); \
(*env)->CallBooleanMethod(env, list, jm_listAdd, localeObj); \
(*env)->DeleteLocalRef(env, localeObj); \
}

#define ADDNULL(list) (*env)->CallBooleanMethod(env, list, jm_listAdd, NULL)

#else
// non-ARM
#import <JavaVM/JavaVM.h>
#import <JavaNativeFoundation/JavaNativeFoundation.h> // JNI Cocoa helper
#import <JavaVM/jni.h>
#endif

#import <Cocoa/Cocoa.h>
#import <OpenGL/OpenGL.h>
#import <Syphon/Syphon.h>

#import <OpenGL/CGLMacro.h>