#include #include #include #include #include #include "EXGLNativeApi.h" #include "EXPlatformUtils.h" extern "C" { // JNIEnv is valid only inside the same thread that it was passed from // to support worklet we need register it from UI thread thread_local JNIEnv* threadLocalEnv; JNIEXPORT jint JNICALL Java_expo_modules_gl_cpp_EXGL_EXGLContextCreate (JNIEnv *env, jclass clazz) { return EXGLContextCreate(); } JNIEXPORT void JNICALL Java_expo_modules_gl_cpp_EXGL_EXGLContextPrepare (JNIEnv *env, jclass clazz, jlong jsiPtr, jint exglCtxId, jobject glContext) { threadLocalEnv = env; jclass GLContextClass = env->GetObjectClass(glContext); jobject glContextRef = env->NewGlobalRef(glContext); jmethodID flushMethodRef = env->GetMethodID(GLContextClass, "flush", "()V"); std::function flushMethod = [glContextRef, flushMethodRef] { threadLocalEnv->CallVoidMethod(glContextRef, flushMethodRef); }; EXGLContextPrepare((void*) jsiPtr, exglCtxId, flushMethod); } JNIEXPORT void JNICALL Java_expo_modules_gl_cpp_EXGL_EXGLContextPrepareWorklet (JNIEnv *env, jclass clazz, jint exglCtxId) { threadLocalEnv = env; EXGLContextPrepareWorklet(exglCtxId); } JNIEXPORT void JNICALL Java_expo_modules_gl_cpp_EXGL_EXGLContextDestroy (JNIEnv *env, jclass clazz, jint exglCtxId) { EXGLContextDestroy(exglCtxId); } JNIEXPORT void JNICALL Java_expo_modules_gl_cpp_EXGL_EXGLContextFlush (JNIEnv *env, jclass clazz, jint exglCtxId) { EXGLContextFlush(exglCtxId); } JNIEXPORT jint JNICALL Java_expo_modules_gl_cpp_EXGL_EXGLContextCreateObject (JNIEnv *env, jclass clazz, jint exglCtxId) { return EXGLContextCreateObject(exglCtxId); } JNIEXPORT void JNICALL Java_expo_modules_gl_cpp_EXGL_EXGLContextDestroyObject (JNIEnv *env, jclass clazz, jint exglCtxId, jint exglObjId) { EXGLContextDestroyObject(exglCtxId, exglObjId); } JNIEXPORT void JNICALL Java_expo_modules_gl_cpp_EXGL_EXGLContextMapObject (JNIEnv *env, jclass clazz, jint exglCtxId, jint exglObjId, jint glObj) { EXGLContextMapObject(exglCtxId, exglObjId, glObj); } JNIEXPORT jint JNICALL Java_expo_modules_gl_cpp_EXGL_EXGLContextGetObject (JNIEnv *env, jclass clazz, jint exglCtxId, jint exglObjId) { return EXGLContextGetObject(exglCtxId, exglObjId); } JNIEXPORT bool JNICALL Java_expo_modules_gl_cpp_EXGL_EXGLContextNeedsRedraw (JNIEnv *env, jclass clazz, jint exglCtxId) { return EXGLContextNeedsRedraw(exglCtxId); } JNIEXPORT void JNICALL Java_expo_modules_gl_cpp_EXGL_EXGLContextDrawEnded (JNIEnv *env, jclass clazz, jint exglCtxId) { EXGLContextDrawEnded(exglCtxId); } }