• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 #define KOALA_INTEROP_MODULE ArkUINativeModule
2 
3 #include "common-interop.h"
4 #include "interop-logging.h"
5 
6 #include "arkoala_api_generated.h"
7 
8 const GENERATED_ArkUIExtendedNodeAPI* GetArkUIExtendedNodeAPI();
9 
10 // TODO: map if multiple pipeline contexts.
11 static KVMDeferred* currentVsyncDeferred = nullptr;
12 
vsyncCallback(Ark_PipelineContext context)13 void vsyncCallback(Ark_PipelineContext context) {
14     if (currentVsyncDeferred) {
15         currentVsyncDeferred->resolve(currentVsyncDeferred, nullptr, 0);
16         currentVsyncDeferred = nullptr;
17     }
18 }
19 
impl_SetVsyncCallback(Ark_NativePointer pipelineContext)20 void impl_SetVsyncCallback(Ark_NativePointer pipelineContext) {
21     Ark_PipelineContext pipelineContextCast = (Ark_PipelineContext) pipelineContext;
22     GetArkUIExtendedNodeAPI()->setVsyncCallback(pipelineContextCast, vsyncCallback);
23 }
KOALA_INTEROP_V1(SetVsyncCallback,Ark_NativePointer)24 KOALA_INTEROP_V1(SetVsyncCallback, Ark_NativePointer)
25 
26 KVMObjectHandle impl_VSyncAwait(KVMContext vmContext, Ark_NativePointer pipelineContext)
27 {
28     [[maybe_unused]] Ark_PipelineContext pipelineContextCast = (Ark_PipelineContext)pipelineContext;
29     KVMObjectHandle result = nullptr;
30     KVMDeferred* deferred = CreateDeferred(vmContext, &result);
31     if (currentVsyncDeferred) {
32         LOGE("%s", "Multiple unresolved vsync deferred");
33         currentVsyncDeferred->reject(currentVsyncDeferred, "Wrong");
34     }
35     currentVsyncDeferred = deferred;
36     return result;
37 }
KOALA_INTEROP_CTX_1(VSyncAwait,KVMObjectHandle,Ark_NativePointer)38 KOALA_INTEROP_CTX_1(VSyncAwait, KVMObjectHandle, Ark_NativePointer)
39 
40 void impl_UnblockVsyncWait(Ark_NativePointer pipelineContext)
41 {
42     if (currentVsyncDeferred) {
43         currentVsyncDeferred->resolve(currentVsyncDeferred, nullptr, 0);
44         currentVsyncDeferred = nullptr;
45     }
46 }
KOALA_INTEROP_V1(UnblockVsyncWait,Ark_NativePointer)47 KOALA_INTEROP_V1(UnblockVsyncWait, Ark_NativePointer)
48 
49 Ark_NativePointer impl_GetPipelineContext(Ark_NativePointer nodePtr)
50 {
51     Ark_NodeHandle nodePtrCast = (Ark_NodeHandle) nodePtr;
52     return GetArkUIExtendedNodeAPI()->getPipelineContext(nodePtrCast);
53 }
54 KOALA_INTEROP_1(GetPipelineContext, Ark_NativePointer, Ark_NativePointer)
55