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     std::function<void(void)> flushMethod) {
15   auto [exglCtx, lock] = ContextGet(exglCtxId);
16   if (exglCtx) {
17     exglCtx->prepareContext(*reinterpret_cast<jsi::Runtime *>(jsiPtr), flushMethod);
18   }
19 }
20 
21 void EXGLContextPrepareWorklet(EXGLContextId exglCtxId) {
22   auto [exglCtx, lock] = ContextGet(exglCtxId);
23   if (exglCtx) {
24     exglCtx->prepareWorkletContext();
25   }
26 }
27 
28 bool EXGLContextNeedsRedraw(EXGLContextId exglCtxId) {
29   auto [exglCtx, lock] = ContextGet(exglCtxId);
30   if (exglCtx) {
31     return exglCtx->needsRedraw;
32   }
33   return false;
34 }
35 
36 void EXGLContextDrawEnded(EXGLContextId exglCtxId) {
37   auto [exglCtx, lock] = ContextGet(exglCtxId);
38   if (exglCtx) {
39     exglCtx->needsRedraw = false;
40   }
41 }
42 
43 void EXGLContextDestroy(EXGLContextId exglCtxId) {
44   ContextDestroy(exglCtxId);
45 }
46 
47 void EXGLContextFlush(EXGLContextId exglCtxId) {
48   auto [exglCtx, lock] = ContextGet(exglCtxId);
49   if (exglCtx) {
50     exglCtx->flush();
51   }
52 }
53 
54 void EXGLContextSetDefaultFramebuffer(EXGLContextId exglCtxId, GLint framebuffer) {
55   auto [exglCtx, lock] = ContextGet(exglCtxId);
56   if (exglCtx) {
57     exglCtx->defaultFramebuffer = framebuffer;
58   }
59 }
60 
61 EXGLObjectId EXGLContextCreateObject(EXGLContextId exglCtxId) {
62   auto [exglCtx, lock] = ContextGet(exglCtxId);
63   if (exglCtx) {
64     return exglCtx->createObject();
65   }
66   return 0;
67 }
68 
69 void EXGLContextDestroyObject(EXGLContextId exglCtxId, EXGLObjectId exglObjId) {
70   auto [exglCtx, lock] = ContextGet(exglCtxId);
71   if (exglCtx) {
72     exglCtx->destroyObject(exglObjId);
73   }
74 }
75 
76 void EXGLContextMapObject(EXGLContextId exglCtxId, EXGLObjectId exglObjId, GLuint glObj) {
77   auto [exglCtx, lock] = ContextGet(exglCtxId);
78   if (exglCtx) {
79     exglCtx->mapObject(exglObjId, glObj);
80   }
81 }
82 
83 GLuint EXGLContextGetObject(EXGLContextId exglCtxId, EXGLObjectId exglObjId) {
84   auto [exglCtx, lock] = ContextGet(exglCtxId);
85   if (exglCtx) {
86     return exglCtx->lookupObject(exglObjId);
87   }
88   return 0;
89 }
90