@shopify/react-native-skia 2.6.6 → 2.6.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (41) hide show
  1. package/android/CMakeLists.txt +1 -2
  2. package/apple/RNSkiaModule.mm +8 -2
  3. package/apple/SkiaManager.mm +10 -5
  4. package/cpp/api/JsiSkApi.h +6 -6
  5. package/cpp/api/JsiSkMaskFilter.h +1 -0
  6. package/cpp/jsi2/NativeObject.h +39 -0
  7. package/cpp/rnskia/RNSkManager.cpp +27 -11
  8. package/cpp/rnwgpu/SurfaceRegistry.h +33 -1
  9. package/cpp/rnwgpu/api/GPU.cpp +15 -12
  10. package/cpp/rnwgpu/api/GPU.h +6 -3
  11. package/cpp/rnwgpu/api/GPUAdapter.cpp +2 -2
  12. package/cpp/rnwgpu/api/GPUAdapter.h +3 -3
  13. package/cpp/rnwgpu/api/GPUBuffer.h +3 -3
  14. package/cpp/rnwgpu/api/GPUCanvasContext.cpp +13 -16
  15. package/cpp/rnwgpu/api/GPUCanvasContext.h +3 -0
  16. package/cpp/rnwgpu/api/GPUDevice.cpp +48 -13
  17. package/cpp/rnwgpu/api/GPUDevice.h +12 -3
  18. package/cpp/rnwgpu/api/GPUQueue.h +3 -3
  19. package/cpp/rnwgpu/api/GPUShaderModule.h +3 -3
  20. package/cpp/rnwgpu/api/WebGPUConstants.h +36 -0
  21. package/cpp/rnwgpu/async/AsyncTaskHandle.cpp +55 -22
  22. package/cpp/rnwgpu/async/AsyncTaskHandle.h +8 -5
  23. package/cpp/rnwgpu/async/RuntimeContext.cpp +194 -0
  24. package/cpp/rnwgpu/async/RuntimeContext.h +121 -0
  25. package/lib/commonjs/skia/types/WebGPU.d.ts +31 -0
  26. package/lib/commonjs/skia/types/WebGPU.js +99 -0
  27. package/lib/commonjs/skia/types/WebGPU.js.map +1 -1
  28. package/lib/module/skia/types/WebGPU.d.ts +31 -0
  29. package/lib/module/skia/types/WebGPU.js +98 -1
  30. package/lib/module/skia/types/WebGPU.js.map +1 -1
  31. package/lib/typescript/lib/commonjs/skia/types/WebGPU.d.ts +1 -0
  32. package/lib/typescript/lib/module/mock/index.d.ts +1 -0
  33. package/lib/typescript/lib/module/skia/types/WebGPU.d.ts +31 -1
  34. package/lib/typescript/src/skia/types/WebGPU.d.ts +31 -0
  35. package/package.json +1 -1
  36. package/src/skia/types/WebGPU.ts +40 -0
  37. package/cpp/rnwgpu/async/AsyncDispatcher.h +0 -28
  38. package/cpp/rnwgpu/async/AsyncRunner.cpp +0 -182
  39. package/cpp/rnwgpu/async/AsyncRunner.h +0 -57
  40. package/cpp/rnwgpu/async/JSIMicrotaskDispatcher.cpp +0 -23
  41. package/cpp/rnwgpu/async/JSIMicrotaskDispatcher.h +0 -22
@@ -1,182 +0,0 @@
1
- #include "AsyncRunner.h"
2
-
3
- #include <chrono>
4
- #include <stdexcept>
5
- #include <utility>
6
-
7
- #include "AsyncTaskHandle.h"
8
-
9
- namespace rnwgpu::async {
10
-
11
- // Static member definitions
12
- std::mutex AsyncRunner::_runnersMutex;
13
- std::unordered_map<jsi::Runtime *, std::shared_ptr<AsyncRunner>>
14
- AsyncRunner::_runners;
15
-
16
- AsyncRunner::AsyncRunner(wgpu::Instance instance,
17
- std::shared_ptr<AsyncDispatcher> dispatcher)
18
- : _instance(std::move(instance)), _dispatcher(std::move(dispatcher)),
19
- _pendingTasks(0), _pumpTasks(0), _tickScheduled(false),
20
- _lastTickTimeNs(0) {
21
- if (!_dispatcher) {
22
- throw std::runtime_error("AsyncRunner requires a valid dispatcher.");
23
- }
24
- }
25
-
26
- std::shared_ptr<AsyncRunner> AsyncRunner::get(jsi::Runtime &runtime) {
27
- std::lock_guard<std::mutex> lock(_runnersMutex);
28
- auto it = _runners.find(&runtime);
29
- if (it == _runners.end()) {
30
- return nullptr;
31
- }
32
- return it->second;
33
- }
34
-
35
- std::shared_ptr<AsyncRunner>
36
- AsyncRunner::getOrCreate(jsi::Runtime &runtime, wgpu::Instance instance,
37
- std::shared_ptr<AsyncDispatcher> dispatcher) {
38
- std::lock_guard<std::mutex> lock(_runnersMutex);
39
- auto it = _runners.find(&runtime);
40
- if (it != _runners.end()) {
41
- return it->second;
42
- }
43
-
44
- auto runner =
45
- std::make_shared<AsyncRunner>(std::move(instance), std::move(dispatcher));
46
- _runners[&runtime] = runner;
47
- return runner;
48
- }
49
-
50
- AsyncTaskHandle AsyncRunner::postTask(const TaskCallback &callback,
51
- bool keepPumping) {
52
- auto handle = AsyncTaskHandle::create(shared_from_this(), keepPumping);
53
- if (!handle.valid()) {
54
- throw std::runtime_error("Failed to create AsyncTaskHandle.");
55
- }
56
-
57
- _pendingTasks.fetch_add(1, std::memory_order_acq_rel);
58
- if (keepPumping) {
59
- _pumpTasks.fetch_add(1, std::memory_order_acq_rel);
60
- }
61
- requestTick();
62
-
63
- auto resolve = handle.createResolveFunction();
64
- auto reject = handle.createRejectFunction();
65
-
66
- try {
67
- callback(resolve, reject);
68
- } catch (const std::exception &exception) {
69
- reject(exception.what());
70
- } catch (...) {
71
- reject("Unknown native error in AsyncRunner::postTask.");
72
- }
73
-
74
- return handle;
75
- }
76
-
77
- void AsyncRunner::requestTick() {
78
- bool expected = false;
79
- if (!_tickScheduled.compare_exchange_strong(expected, true,
80
- std::memory_order_acq_rel)) {
81
- return;
82
- }
83
-
84
- auto self = shared_from_this();
85
- _dispatcher->post([self](jsi::Runtime &runtime) {
86
- auto tickCallback = jsi::Function::createFromHostFunction(
87
- runtime, jsi::PropNameID::forAscii(runtime, "AsyncRunnerTick"), 0,
88
- [self](jsi::Runtime &runtime, const jsi::Value & /*thisValue*/,
89
- const jsi::Value * /*args*/, size_t /*count*/) -> jsi::Value {
90
- self->tick(runtime);
91
- return jsi::Value::undefined();
92
- });
93
-
94
- #if defined(ANDROID) || defined(__ANDROID__)
95
- auto global = runtime.global();
96
- auto setImmediateValue = global.getProperty(runtime, "setImmediate");
97
- constexpr auto kMinTickInterval = std::chrono::milliseconds(4);
98
- const int64_t nowNs =
99
- std::chrono::duration_cast<std::chrono::nanoseconds>(
100
- std::chrono::steady_clock::now().time_since_epoch())
101
- .count();
102
- const int64_t lastNs =
103
- self->_lastTickTimeNs.load(std::memory_order_acquire);
104
- int delayMs = 0;
105
- if (lastNs > 0) {
106
- const int64_t elapsedNs = nowNs - lastNs;
107
- const int64_t minIntervalNs = kMinTickInterval.count() * 1000000LL;
108
- if (elapsedNs < minIntervalNs) {
109
- const int64_t remainingNs = minIntervalNs - elapsedNs;
110
- delayMs = static_cast<int>((remainingNs + 999999) / 1000000);
111
- }
112
- }
113
-
114
- auto tryScheduleTimeout = [&](int ms) {
115
- auto setTimeoutValue = global.getProperty(runtime, "setTimeout");
116
- if (!setTimeoutValue.isObject()) {
117
- return false;
118
- }
119
- auto setTimeoutObj = setTimeoutValue.asObject(runtime);
120
- if (!setTimeoutObj.isFunction(runtime)) {
121
- return false;
122
- }
123
- auto setTimeoutFn = setTimeoutObj.asFunction(runtime);
124
- jsi::Value callbackArg(runtime, tickCallback);
125
- jsi::Value delayArg(static_cast<double>(ms));
126
- setTimeoutFn.call(runtime, callbackArg, delayArg);
127
- return true;
128
- };
129
-
130
- if (delayMs > 0) {
131
- if (tryScheduleTimeout(delayMs)) {
132
- return;
133
- }
134
- // If setTimeout unavailable fall through to immediate scheduling.
135
- }
136
-
137
- if (setImmediateValue.isObject()) {
138
- auto setImmediateObj = setImmediateValue.asObject(runtime);
139
- if (setImmediateObj.isFunction(runtime)) {
140
- auto setImmediateFn = setImmediateObj.asFunction(runtime);
141
- jsi::Value callbackArg(runtime, tickCallback);
142
- setImmediateFn.call(runtime, callbackArg);
143
- return;
144
- }
145
- }
146
-
147
- int timeoutDelayMs = delayMs > 0 ? delayMs : 0;
148
- if (tryScheduleTimeout(timeoutDelayMs)) {
149
- return;
150
- }
151
-
152
- runtime.queueMicrotask(std::move(tickCallback));
153
- #else
154
- runtime.queueMicrotask(std::move(tickCallback));
155
- #endif
156
- });
157
- }
158
-
159
- void AsyncRunner::tick(jsi::Runtime & /*runtime*/) {
160
- _tickScheduled.store(false, std::memory_order_release);
161
- _instance.ProcessEvents();
162
- const auto nowNs = std::chrono::duration_cast<std::chrono::nanoseconds>(
163
- std::chrono::steady_clock::now().time_since_epoch())
164
- .count();
165
- _lastTickTimeNs.store(nowNs, std::memory_order_release);
166
- if (_pumpTasks.load(std::memory_order_acquire) > 0) {
167
- requestTick();
168
- }
169
- }
170
-
171
- void AsyncRunner::onTaskSettled(bool keepPumping) {
172
- _pendingTasks.fetch_sub(1, std::memory_order_acq_rel);
173
- if (keepPumping) {
174
- _pumpTasks.fetch_sub(1, std::memory_order_acq_rel);
175
- }
176
- }
177
-
178
- std::shared_ptr<AsyncDispatcher> AsyncRunner::dispatcher() const {
179
- return _dispatcher;
180
- }
181
-
182
- } // namespace rnwgpu::async
@@ -1,57 +0,0 @@
1
- #pragma once
2
-
3
- #include <atomic>
4
- #include <cstdint>
5
- #include <functional>
6
- #include <memory>
7
- #include <mutex>
8
- #include <unordered_map>
9
-
10
- #include <jsi/jsi.h>
11
-
12
- #include "AsyncDispatcher.h"
13
- #include "AsyncTaskHandle.h"
14
-
15
- #include "webgpu/webgpu_cpp.h"
16
-
17
- namespace jsi = facebook::jsi;
18
-
19
- namespace rnwgpu::async {
20
-
21
- class AsyncRunner : public std::enable_shared_from_this<AsyncRunner> {
22
- public:
23
- using TaskCallback =
24
- std::function<void(const AsyncTaskHandle::ResolveFunction &,
25
- const AsyncTaskHandle::RejectFunction &)>;
26
-
27
- AsyncRunner(wgpu::Instance instance,
28
- std::shared_ptr<AsyncDispatcher> dispatcher);
29
-
30
- static std::shared_ptr<AsyncRunner> get(jsi::Runtime &runtime);
31
- static std::shared_ptr<AsyncRunner>
32
- getOrCreate(jsi::Runtime &runtime, wgpu::Instance instance,
33
- std::shared_ptr<AsyncDispatcher> dispatcher);
34
-
35
- AsyncTaskHandle postTask(const TaskCallback &callback,
36
- bool keepPumping = true);
37
-
38
- void requestTick();
39
- void tick(jsi::Runtime &runtime);
40
- void onTaskSettled(bool keepPumping);
41
-
42
- std::shared_ptr<AsyncDispatcher> dispatcher() const;
43
-
44
- private:
45
- static std::mutex _runnersMutex;
46
- static std::unordered_map<jsi::Runtime *, std::shared_ptr<AsyncRunner>>
47
- _runners;
48
-
49
- wgpu::Instance _instance;
50
- std::shared_ptr<AsyncDispatcher> _dispatcher;
51
- std::atomic<size_t> _pendingTasks;
52
- std::atomic<size_t> _pumpTasks;
53
- std::atomic<bool> _tickScheduled;
54
- std::atomic<int64_t> _lastTickTimeNs;
55
- };
56
-
57
- } // namespace rnwgpu::async
@@ -1,23 +0,0 @@
1
- #include "JSIMicrotaskDispatcher.h"
2
-
3
- #include <utility>
4
-
5
- namespace rnwgpu::async {
6
-
7
- JSIMicrotaskDispatcher::JSIMicrotaskDispatcher(jsi::Runtime &runtime)
8
- : _runtime(runtime) {}
9
-
10
- void JSIMicrotaskDispatcher::post(Work work) {
11
- auto microtask = jsi::Function::createFromHostFunction(
12
- _runtime, jsi::PropNameID::forAscii(_runtime, "AsyncMicrotask"), 0,
13
- [work = std::move(work)](
14
- jsi::Runtime &runtime, const jsi::Value & /*thisValue*/,
15
- const jsi::Value * /*args*/, size_t /*count*/) -> jsi::Value {
16
- work(runtime);
17
- return jsi::Value::undefined();
18
- });
19
-
20
- _runtime.queueMicrotask(std::move(microtask));
21
- }
22
-
23
- } // namespace rnwgpu::async
@@ -1,22 +0,0 @@
1
- #pragma once
2
-
3
- #include "AsyncDispatcher.h"
4
-
5
- namespace rnwgpu::async {
6
-
7
- /**
8
- * Dispatcher implementation backed by `jsi::Runtime::queueMicrotask`.
9
- */
10
- class JSIMicrotaskDispatcher final
11
- : public AsyncDispatcher,
12
- public std::enable_shared_from_this<JSIMicrotaskDispatcher> {
13
- public:
14
- explicit JSIMicrotaskDispatcher(jsi::Runtime &runtime);
15
-
16
- void post(Work work) override;
17
-
18
- private:
19
- jsi::Runtime &_runtime;
20
- };
21
-
22
- } // namespace rnwgpu::async