-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathJRiveWorkletDispatcher.hpp
More file actions
49 lines (34 loc) · 1.35 KB
/
JRiveWorkletDispatcher.hpp
File metadata and controls
49 lines (34 loc) · 1.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#pragma once
#include <fbjni/fbjni.h>
#include <NitroModules/Dispatcher.hpp>
#include <queue>
#include <mutex>
#include <condition_variable>
namespace margelo::nitro::rive {
using namespace facebook;
class JRiveWorkletDispatcher : public jni::HybridClass<JRiveWorkletDispatcher> {
public:
static auto constexpr kJavaDescriptor = "Lcom/margelo/nitro/rive/RiveWorkletDispatcher;";
static jni::local_ref<jhybriddata> initHybrid(jni::alias_ref<jhybridobject> jThis);
static void registerNatives();
static jni::local_ref<javaobject> create();
void runAsync(std::function<void()>&& function);
void runSync(std::function<void()>&& function);
private:
friend HybridBase;
void trigger();
void scheduleTrigger();
jni::global_ref<JRiveWorkletDispatcher::javaobject> _javaPart;
std::queue<std::function<void()>> _jobs;
std::recursive_mutex _mutex;
explicit JRiveWorkletDispatcher(jni::alias_ref<JRiveWorkletDispatcher::jhybridobject> jThis);
};
class AndroidMainThreadDispatcher : public Dispatcher {
public:
explicit AndroidMainThreadDispatcher(jni::local_ref<JRiveWorkletDispatcher::javaobject> javaDispatcher);
void runAsync(std::function<void()>&& function) override;
void runSync(std::function<void()>&& function) override;
private:
jni::global_ref<JRiveWorkletDispatcher::javaobject> _javaDispatcher;
};
} // namespace margelo::nitro::rive