1 #include "EXGLNativeApi.h" 2 #include "EXGLContextManager.h" 3 #include "EXGLNativeContext.h" 4 5 using namespace expo::gl_cpp; 6 7 EXGLContextId EXGLContextCreate() { 8 return ContextCreate(); 9 } 10 11 void EXGLContextPrepare( 12 void *jsiPtr, 13 EXGLContextId exglCtxId, 14 bool enableExperimentalWorkletSupport, 15 std::function<void(void)> flushMethod) { 16 auto [exglCtx, lock] = ContextGet(exglCtxId); 17 if (exglCtx) { 18 exglCtx->prepareContext( 19 *reinterpret_cast<jsi::Runtime *>(jsiPtr), enableExperimentalWorkletSupport, flushMethod); 20 } 21 } 22 23 bool EXGLContextNeedsRedraw(EXGLContextId exglCtxId) { 24 auto [exglCtx, lock] = ContextGet(exglCtxId); 25 if (exglCtx) { 26 return exglCtx->needsRedraw; 27 } 28 return false; 29 } 30 31 void EXGLContextDrawEnded(EXGLContextId exglCtxId) { 32 auto [exglCtx, lock] = ContextGet(exglCtxId); 33 if (exglCtx) { 34 exglCtx->needsRedraw = false; 35 } 36 } 37 38 void EXGLContextDestroy(EXGLContextId exglCtxId) { 39 ContextDestroy(exglCtxId); 40 } 41 42 void EXGLContextFlush(EXGLContextId exglCtxId) { 43 auto [exglCtx, lock] = ContextGet(exglCtxId); 44 if (exglCtx) { 45 exglCtx->flush(); 46 } 47 } 48 49 void EXGLContextSetDefaultFramebuffer(EXGLContextId exglCtxId, GLint framebuffer) { 50 auto [exglCtx, lock] = ContextGet(exglCtxId); 51 if (exglCtx) { 52 exglCtx->defaultFramebuffer = framebuffer; 53 } 54 } 55 56 EXGLObjectId EXGLContextCreateObject(EXGLContextId exglCtxId) { 57 auto [exglCtx, lock] = ContextGet(exglCtxId); 58 if (exglCtx) { 59 return exglCtx->createObject(); 60 } 61 return 0; 62 } 63 64 void EXGLContextDestroyObject(EXGLContextId exglCtxId, EXGLObjectId exglObjId) { 65 auto [exglCtx, lock] = ContextGet(exglCtxId); 66 if (exglCtx) { 67 exglCtx->destroyObject(exglObjId); 68 } 69 } 70 71 void EXGLContextMapObject(EXGLContextId exglCtxId, EXGLObjectId exglObjId, GLuint glObj) { 72 auto [exglCtx, lock] = ContextGet(exglCtxId); 73 if (exglCtx) { 74 exglCtx->mapObject(exglObjId, glObj); 75 } 76 } 77 78 GLuint EXGLContextGetObject(EXGLContextId exglCtxId, EXGLObjectId exglObjId) { 79 auto [exglCtx, lock] = ContextGet(exglCtxId); 80 if (exglCtx) { 81 return exglCtx->lookupObject(exglObjId); 82 } 83 return 0; 84 } 85