void NVEventReleaseTextureData(void* data, unsigned char* pixels) { JNIEnv* env = NVThreadGetCurrentJNIEnv(); env->ReleaseByteArrayElements((jbyteArray)data, (jbyte*)pixels, JNI_ABORT); env->DeleteLocalRef((jbyteArray)data); }
int NVEventEGLGetSurfaceWidth() { JNIEnv* jniEnv = NVThreadGetCurrentJNIEnv(); if (!jniEnv || !s_globalThiz) { __android_log_print(ANDROID_LOG_DEBUG, MODULE, "Error: No valid JNI env in NVEventEGLGetSurfaceWidth"); return 0; } return jniEnv->CallIntMethod(s_globalThiz, s_width); }
void NVEventEGLUnmakeCurrent() { JNIEnv* jniEnv = NVThreadGetCurrentJNIEnv(); if (!jniEnv || !s_globalThiz) { __android_log_print(ANDROID_LOG_DEBUG, MODULE, "Error: No valid JNI env in UnMakeCurrent"); } else if (!jniEnv->CallBooleanMethod(s_globalThiz, s_unMakeCurrent)) { __android_log_print(ANDROID_LOG_DEBUG, MODULE, "Error: UnMakeCurrent failed"); } }
void NVEventEGLSwapBuffers() { JNIEnv* jniEnv = NVThreadGetCurrentJNIEnv(); PERFBLURB("swap JNI"); if (!jniEnv || !s_globalThiz) { __android_log_print(ANDROID_LOG_DEBUG, MODULE, "Error: No valid JNI env in SwapBuffers"); } else if (!jniEnv->CallBooleanMethod(s_globalThiz, s_swap)) { __android_log_print(ANDROID_LOG_DEBUG, MODULE, "Error: SwapBuffers failed"); } RESET_PROFILING(); }
static void* NVEventMainLoopThreadFunc(void*) { NVEventAppMain(0, NULL); __android_log_print(ANDROID_LOG_DEBUG, MODULE, "NvEvent native app Main returned"); // signal the condition variable to unblock // java from waiting on pause or quit unlockAll(&(s_eventQueue.m_javaSync)); s_alreadyFinishing = true; JNIEnv* env = NVThreadGetCurrentJNIEnv(); env->CallVoidMethod(s_globalThiz, s_finish); return NULL; }
bool CallBoolean() { JNIEnv* jniEnv = NVThreadGetCurrentJNIEnv(); if (!jniEnv || !s_globalThiz) { __android_log_print(ANDROID_LOG_DEBUG, MODULE, "Error: No valid JNI env in %s", m_name); return false; } if (!m_index) { __android_log_print(ANDROID_LOG_DEBUG, MODULE, "Error: No valid function pointer in %s", m_name); return false; } // __android_log_print(ANDROID_LOG_DEBUG, MODULE, "Calling JNI up to %s", m_name); return jniEnv->CallBooleanMethod(s_globalThiz, m_index); }
static void* NVThreadSpawnProc(void* arg) { NVThreadInitStruct* init = (NVThreadInitStruct*)arg; void *(*start_routine)(void *) = init->m_startRoutine; void* data = init->m_arg; void* ret; free(arg); NVThreadGetCurrentJNIEnv(); ret = start_routine(data); if (s_vm) (*s_vm)->DetachCurrentThread(s_vm); return ret; }
bool NVEventEGLInit() { JNIEnv* jniEnv = NVThreadGetCurrentJNIEnv(); if (!jniEnv || !s_globalThiz) { __android_log_print(ANDROID_LOG_DEBUG, MODULE, "Error: No valid JNI env in MakeCurrent"); return false; } else if (!jniEnv->CallBooleanMethod(s_globalThiz, s_initEGL)) { return false; } else { return true; } }
void CallVoid() { JNIEnv * jniEnv = NVThreadGetCurrentJNIEnv(); if (!jniEnv || !s_globalThiz) { __android_log_print(ANDROID_LOG_DEBUG, MODULE, "Error: No valid JNI env in %s", m_name); return; } if (!m_index) { __android_log_print(ANDROID_LOG_DEBUG, MODULE, "Error: No valid function pointer in %s", m_name); return; } jniEnv->CallVoidMethod(s_globalThiz, m_index); }
char* NVEventLoadFile(const char* file) { JNIEnv* env = NVThreadGetCurrentJNIEnv(); jstring test = env->NewStringUTF(file); jobject rawData = env->CallObjectMethod(s_globalThiz, s_loadFile, test); jbyteArray data = (jbyteArray) env->GetObjectField(rawData, s_dataId); int size = env->GetIntField(rawData, s_lengthId); unsigned char* data2 = (unsigned char*) env->GetByteArrayElements(data, NULL); char * buffer = new char[size+1]; memcpy(buffer, data2, size); buffer[size] = '\0'; env->ReleaseByteArrayElements(data, (jbyte*) data2, 0); env->DeleteLocalRef(rawData); return buffer; }
void* NVEventGetTextureData(const char* filename, unsigned char*& pixels, unsigned int& width, unsigned int& height, unsigned int& format, unsigned int& type) { JNIEnv* env = NVThreadGetCurrentJNIEnv(); jstring test = env->NewStringUTF(filename); jobject rawTexture = env->CallObjectMethod(s_globalThiz, s_loadTexture, test); jbyteArray data = (jbyteArray) env->GetObjectField(rawTexture, s_texDataId); width = env->GetIntField(rawTexture, s_widthId); height = env->GetIntField(rawTexture, s_heightId); format = GL_RGBA; type = GL_UNSIGNED_BYTE; pixels = (unsigned char*) env->GetByteArrayElements(data, NULL); env->DeleteLocalRef(rawTexture); return (void*)data; }
static void NVEventShutdown() { JNIEnv* jniEnv = NVThreadGetCurrentJNIEnv(); if (!jniEnv || !s_globalThiz) { __android_log_print(ANDROID_LOG_DEBUG, MODULE, "Error: DestroyingRegisteredObjectInstance no TLS data!"); } jniEnv->DeleteGlobalRef(s_globalThiz); s_globalThiz = NULL; __android_log_print(ANDROID_LOG_DEBUG, MODULE, "Released global thiz!"); pthread_mutex_destroy(&(s_eventQueue.m_mutex)); // free everyone... unlockAll(&s_eventQueue.m_nativeSync); unlockAll(&s_eventQueue.m_javaSync); syncDestroy(&(s_eventQueue.m_nativeSync)); syncDestroy(&(s_eventQueue.m_javaSync)); }
static void* NVEventMainLoopThreadFunc(void*) { NVEventAppMain(0, NULL); __android_log_print(ANDROID_LOG_DEBUG, MODULE, "NvEvent native app Main returned"); // signal the condition variable to unblock // java from waiting on pause or quit s_eventQueue.UnblockProducer(); s_appThreadExited = true; // IF that app main returned because we posted a QUIT, then Java knows what to // do regarding lifecycle. But, if the app returned from main of its own accord, // we need to call finish. if (!s_javaPostedQuit) { JNIEnv* env = NVThreadGetCurrentJNIEnv(); env->CallVoidMethod(s_globalThiz, s_finish.m_index); } return NULL; }
int NVEventGetOrientation() { JNIEnv* env = NVThreadGetCurrentJNIEnv(); return env->CallIntMethod(s_globalThiz, s_getOri); }