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