-
Notifications
You must be signed in to change notification settings - Fork 58
Expand file tree
/
Copy pathRNWebGPUManager.cpp
More file actions
72 lines (58 loc) · 2.33 KB
/
RNWebGPUManager.cpp
File metadata and controls
72 lines (58 loc) · 2.33 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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#include "RNWebGPUManager.h"
#include "CallInvokerDispatcher.h"
#include "Dispatcher.h"
#include "GPU.h"
#include "RNWebGPU.h"
// Enums
#include "GPUBufferUsage.h"
#include "GPUColorWrite.h"
#include "GPUMapMode.h"
#include "GPUShaderStage.h"
#include "GPUTextureUsage.h"
#include <memory>
#include <utility>
namespace rnwgpu {
RNWebGPUManager::RNWebGPUManager(
jsi::Runtime *jsRuntime,
std::shared_ptr<facebook::react::CallInvoker> jsCallInvoker,
std::shared_ptr<PlatformContext> platformContext)
: _jsRuntime(jsRuntime), _jsCallInvoker(jsCallInvoker),
_platformContext(platformContext) {
// Installs the global Dispatcher mechanism into this Runtime.
// This allows creating Promises and calling back to JS.
auto dispatcher =
std::make_shared<margelo::CallInvokerDispatcher>(_jsCallInvoker);
margelo::Dispatcher::installRuntimeGlobalDispatcher(*_jsRuntime, dispatcher);
// Use the singleton GPU instance instead of creating a new one
auto gpu = GPU::getInstance();
auto rnWebGPU = std::make_shared<RNWebGPU>(gpu, _platformContext);
_gpu = gpu->get();
_jsRuntime->global().setProperty(
*_jsRuntime, "RNWebGPU",
jsi::Object::createFromHostObject(*_jsRuntime, rnWebGPU));
auto bufferUsage = std::make_shared<GPUBufferUsage>();
_jsRuntime->global().setProperty(
*_jsRuntime, "GPUBufferUsage",
jsi::Object::createFromHostObject(*_jsRuntime, std::move(bufferUsage)));
auto colorWrite = std::make_shared<GPUColorWrite>();
_jsRuntime->global().setProperty(
*_jsRuntime, "GPUColorWrite",
jsi::Object::createFromHostObject(*_jsRuntime, std::move(colorWrite)));
auto mapMode = std::make_shared<GPUMapMode>();
_jsRuntime->global().setProperty(
*_jsRuntime, "GPUMapMode",
jsi::Object::createFromHostObject(*_jsRuntime, std::move(mapMode)));
auto shaderStage = std::make_shared<GPUShaderStage>();
_jsRuntime->global().setProperty(
*_jsRuntime, "GPUShaderStage",
jsi::Object::createFromHostObject(*_jsRuntime, std::move(shaderStage)));
auto textureUsage = std::make_shared<GPUTextureUsage>();
_jsRuntime->global().setProperty(
*_jsRuntime, "GPUTextureUsage",
jsi::Object::createFromHostObject(*_jsRuntime, std::move(textureUsage)));
}
RNWebGPUManager::~RNWebGPUManager() {
_jsRuntime = nullptr;
_jsCallInvoker = nullptr;
}
} // namespace rnwgpu