mirror of
https://github.com/panda3d/panda3d.git
synced 2025-09-30 08:44:19 -04:00
parent
20334cce05
commit
2208cc8bff
@ -132,3 +132,13 @@ INLINE bool ThreadDummyImpl::
|
|||||||
get_context_switches(size_t &, size_t &) {
|
get_context_switches(size_t &, size_t &) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef ANDROID
|
||||||
|
/**
|
||||||
|
* Returns the JNIEnv object for the current thread.
|
||||||
|
*/
|
||||||
|
INLINE JNIEnv *ThreadDummyImpl::
|
||||||
|
get_jni_env() const {
|
||||||
|
return _jni_env;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
@ -25,6 +25,13 @@
|
|||||||
#include <windows.h>
|
#include <windows.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef ANDROID
|
||||||
|
#include "config_express.h"
|
||||||
|
#include <jni.h>
|
||||||
|
|
||||||
|
static JavaVM *java_vm = nullptr;
|
||||||
|
#endif
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
@ -48,4 +55,36 @@ get_current_thread() {
|
|||||||
return Thread::get_main_thread();
|
return Thread::get_main_thread();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef ANDROID
|
||||||
|
/**
|
||||||
|
* Attaches the thread to the Java virtual machine. If this returns true, a
|
||||||
|
* JNIEnv pointer can be acquired using get_jni_env().
|
||||||
|
*/
|
||||||
|
bool ThreadDummyImpl::
|
||||||
|
attach_java_vm() {
|
||||||
|
assert(java_vm != nullptr);
|
||||||
|
JNIEnv *env;
|
||||||
|
JavaVMAttachArgs args;
|
||||||
|
args.version = JNI_VERSION_1_2;
|
||||||
|
args.name = "Main";
|
||||||
|
args.group = nullptr;
|
||||||
|
if (java_vm->AttachCurrentThread(&env, &args) != 0) {
|
||||||
|
thread_cat.error()
|
||||||
|
<< "Failed to attach Java VM to thread ";
|
||||||
|
_jni_env = nullptr;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
_jni_env = env;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Binds the Panda thread to the current thread, assuming that the current
|
||||||
|
* thread is already a valid attached Java thread. Called by JNI_OnLoad.
|
||||||
|
*/
|
||||||
|
void ThreadDummyImpl::
|
||||||
|
bind_java_thread() {
|
||||||
|
}
|
||||||
|
#endif // ANDROID
|
||||||
|
|
||||||
#endif // THREAD_DUMMY_IMPL
|
#endif // THREAD_DUMMY_IMPL
|
||||||
|
@ -31,6 +31,11 @@ class Thread;
|
|||||||
#include <windows.h> // For Sleep().
|
#include <windows.h> // For Sleep().
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef ANDROID
|
||||||
|
#include <jni.h>
|
||||||
|
typedef struct _JNIEnv _jni_env;
|
||||||
|
#endif
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A fake thread implementation for single-threaded applications. This simply
|
* A fake thread implementation for single-threaded applications. This simply
|
||||||
* fails whenever you try to start a thread.
|
* fails whenever you try to start a thread.
|
||||||
@ -58,7 +63,18 @@ public:
|
|||||||
INLINE static void yield();
|
INLINE static void yield();
|
||||||
INLINE static void consider_yield();
|
INLINE static void consider_yield();
|
||||||
|
|
||||||
|
#ifdef ANDROID
|
||||||
|
INLINE JNIEnv *get_jni_env() const;
|
||||||
|
bool attach_java_vm();
|
||||||
|
static void bind_java_thread();
|
||||||
|
#endif
|
||||||
|
|
||||||
INLINE static bool get_context_switches(size_t &, size_t &);
|
INLINE static bool get_context_switches(size_t &, size_t &);
|
||||||
|
|
||||||
|
private:
|
||||||
|
#ifdef ANDROID
|
||||||
|
JNIEnv *_jni_env = nullptr;
|
||||||
|
#endif
|
||||||
};
|
};
|
||||||
|
|
||||||
#include "threadDummyImpl.I"
|
#include "threadDummyImpl.I"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user