Invert dependency to avoid compile issues

This commit is contained in:
Henrik Rydgård 2023-01-04 16:07:39 +01:00
parent a3e5e475cd
commit ab6fafb6eb
5 changed files with 57 additions and 36 deletions

View File

@ -28,6 +28,27 @@
#include "Common/Thread/ThreadUtil.h"
#include "Common/Data/Encoding/Utf8.h"
AttachDetachFunc g_attach;
AttachDetachFunc g_detach;
void AttachThreadToJNI() {
if (g_attach) {
g_attach();
}
}
void DetachThreadFromJNI() {
if (g_detach) {
g_detach();
}
}
void RegisterAttachDetach(AttachDetachFunc attach, AttachDetachFunc detach) {
g_attach = attach;
g_detach = detach;
}
#if (PPSSPP_PLATFORM(ANDROID) || PPSSPP_PLATFORM(LINUX)) && !defined(_GNU_SOURCE)
#define _GNU_SOURCE
#endif
@ -67,23 +88,6 @@ static EXCEPTION_DISPOSITION NTAPI ignore_handler(EXCEPTION_RECORD *rec,
}
#endif
void AttachThreadToJNI() {
#if PPSSPP_PLATFORM(ANDROID)
Android_AttachThreadToJNI();
#else
// Do nothing
#endif
}
void DetachThreadFromJNI() {
#if PPSSPP_PLATFORM(ANDROID)
Android_DetachThreadFromJNI();
#else
// Do nothing
#endif
}
#if PPSSPP_PLATFORM(WINDOWS) && !PPSSPP_PLATFORM(UWP)
typedef HRESULT (WINAPI *TSetThreadDescription)(HANDLE, PCWSTR);

View File

@ -14,6 +14,10 @@ const char *GetCurrentThreadName();
// exactly what it is is badly specified and not useful for anything.
int GetCurrentThreadIdForDebug();
typedef void (*AttachDetachFunc)();
void RegisterAttachDetach(AttachDetachFunc attach, AttachDetachFunc detach);
// When you know that a thread potentially will make JNI calls, call this after setting its name.
void AttachThreadToJNI();

View File

@ -1,6 +1,20 @@
================================================================
NOTE: These are legacy instructions for building using ndk-build.
We mostly only use this on CI because it's faster than gradle.
There might also be some holdouts around still using eclipse.
================================================================
First, build the C++ static library:
> cd android
> ./ab.sh
Or
> ./ab.cmd
as appropriate.
Start Eclipse, import the android directory as an existing project
You need to also load the "native" project into your eclipse workspace

View File

@ -246,22 +246,6 @@ jclass findClass(const char* name) {
return static_cast<jclass>(getEnv()->CallObjectMethod(gClassLoader, gFindClassMethod, getEnv()->NewStringUTF(name)));
}
JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM *pjvm, void *reserved) {
INFO_LOG(SYSTEM, "JNI_OnLoad");
gJvm = pjvm; // cache the JavaVM pointer
auto env = getEnv();
//replace with one of your classes in the line below
auto randomClass = env->FindClass("org/ppsspp/ppsspp/NativeActivity");
jclass classClass = env->GetObjectClass(randomClass);
auto classLoaderClass = env->FindClass("java/lang/ClassLoader");
auto getClassLoaderMethod = env->GetMethodID(classClass, "getClassLoader",
"()Ljava/lang/ClassLoader;");
gClassLoader = env->NewGlobalRef(env->CallObjectMethod(randomClass, getClassLoaderMethod));
gFindClassMethod = env->GetMethodID(classLoaderClass, "findClass",
"(Ljava/lang/String;)Ljava/lang/Class;");
return JNI_VERSION_1_6;
}
void Android_AttachThreadToJNI() {
JNIEnv *env;
int status = gJvm->GetEnv((void **)&env, JNI_VERSION_1_6);
@ -289,6 +273,24 @@ void Android_DetachThreadFromJNI() {
}
}
JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM *pjvm, void *reserved) {
INFO_LOG(SYSTEM, "JNI_OnLoad");
gJvm = pjvm; // cache the JavaVM pointer
auto env = getEnv();
//replace with one of your classes in the line below
auto randomClass = env->FindClass("org/ppsspp/ppsspp/NativeActivity");
jclass classClass = env->GetObjectClass(randomClass);
auto classLoaderClass = env->FindClass("java/lang/ClassLoader");
auto getClassLoaderMethod = env->GetMethodID(classClass, "getClassLoader",
"()Ljava/lang/ClassLoader;");
gClassLoader = env->NewGlobalRef(env->CallObjectMethod(randomClass, getClassLoaderMethod));
gFindClassMethod = env->GetMethodID(classLoaderClass, "findClass",
"(Ljava/lang/String;)Ljava/lang/Class;");
RegisterAttachDetach(&Android_AttachThreadToJNI, &Android_DetachThreadFromJNI);
return JNI_VERSION_1_6;
}
// Only used in OpenGL mode.
static void EmuThreadFunc() {
JNIEnv *env;

View File

@ -27,8 +27,5 @@ public:
};
#endif
void Android_AttachThreadToJNI();
void Android_DetachThreadFromJNI();
#endif