react-native-wgpu 0.5.2 → 0.5.4

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 (27) hide show
  1. package/android/cpp/AndroidPlatformContext.h +108 -0
  2. package/apple/ApplePlatformContext.h +5 -0
  3. package/apple/ApplePlatformContext.mm +69 -0
  4. package/cpp/jsi/JSIConverter.h +12 -4
  5. package/cpp/rnwgpu/PlatformContext.h +7 -0
  6. package/cpp/rnwgpu/RNWebGPUManager.cpp +4 -1
  7. package/cpp/rnwgpu/api/GPU.h +1 -0
  8. package/cpp/rnwgpu/api/GPUAdapter.cpp +16 -4
  9. package/cpp/rnwgpu/api/GPUDevice.cpp +58 -0
  10. package/cpp/rnwgpu/api/GPUDevice.h +85 -0
  11. package/cpp/rnwgpu/api/GPUUncapturedErrorEvent.h +71 -0
  12. package/cpp/rnwgpu/api/RNWebGPU.h +71 -37
  13. package/lib/commonjs/external/reanimated/registerWebGPUForReanimated.js +0 -1
  14. package/lib/commonjs/external/reanimated/registerWebGPUForReanimated.js.map +1 -1
  15. package/lib/commonjs/main/index.js +1 -1
  16. package/lib/commonjs/main/index.js.map +1 -1
  17. package/lib/module/external/reanimated/registerWebGPUForReanimated.js +0 -1
  18. package/lib/module/external/reanimated/registerWebGPUForReanimated.js.map +1 -1
  19. package/lib/module/main/index.js +1 -1
  20. package/lib/module/main/index.js.map +1 -1
  21. package/lib/typescript/lib/commonjs/external/reanimated/registerWebGPUForReanimated.d.ts.map +1 -1
  22. package/lib/typescript/lib/module/external/reanimated/registerWebGPUForReanimated.d.ts.map +1 -1
  23. package/lib/typescript/src/external/reanimated/registerWebGPUForReanimated.d.ts.map +1 -1
  24. package/package.json +1 -1
  25. package/src/external/ModuleProxy.ts +1 -1
  26. package/src/external/reanimated/registerWebGPUForReanimated.ts +4 -4
  27. package/src/main/index.tsx +1 -3
@@ -3,8 +3,10 @@
3
3
  #include <android/bitmap.h>
4
4
  #include <jni.h>
5
5
 
6
+ #include <functional>
6
7
  #include <memory>
7
8
  #include <string>
9
+ #include <thread>
8
10
  #include <vector>
9
11
 
10
12
  #include "webgpu/webgpu_cpp.h"
@@ -128,6 +130,112 @@ public:
128
130
  result.data = imageData;
129
131
  return result;
130
132
  }
133
+
134
+ void createImageBitmapAsync(
135
+ std::string blobId, double offset, double size,
136
+ std::function<void(ImageData)> onSuccess,
137
+ std::function<void(std::string)> onError) override {
138
+ // Capture blobModule for the background thread
139
+ jobject blobModule = _blobModule;
140
+
141
+ // Dispatch to a background thread
142
+ std::thread([blobModule, blobId = std::move(blobId), offset, size,
143
+ onSuccess = std::move(onSuccess),
144
+ onError = std::move(onError)]() {
145
+ jni::Environment::ensureCurrentThreadIsAttached();
146
+
147
+ JNIEnv *env = facebook::jni::Environment::current();
148
+ if (!env) {
149
+ onError("Couldn't get JNI environment");
150
+ return;
151
+ }
152
+
153
+ if (!blobModule) {
154
+ onError("BlobModule instance is null");
155
+ return;
156
+ }
157
+
158
+ // Get the resolve method ID
159
+ jclass blobModuleClass = env->GetObjectClass(blobModule);
160
+ if (!blobModuleClass) {
161
+ onError("Couldn't find BlobModule class");
162
+ return;
163
+ }
164
+
165
+ jmethodID resolveMethod = env->GetMethodID(blobModuleClass, "resolve",
166
+ "(Ljava/lang/String;II)[B");
167
+ if (!resolveMethod) {
168
+ onError("Couldn't find resolve method in BlobModule");
169
+ return;
170
+ }
171
+
172
+ // Resolve the blob data
173
+ jstring jBlobId = env->NewStringUTF(blobId.c_str());
174
+ jbyteArray blobData = (jbyteArray)env->CallObjectMethod(
175
+ blobModule, resolveMethod, jBlobId, static_cast<jint>(offset),
176
+ static_cast<jint>(size));
177
+ env->DeleteLocalRef(jBlobId);
178
+
179
+ if (!blobData) {
180
+ onError("Couldn't retrieve blob data");
181
+ return;
182
+ }
183
+
184
+ // Create a Bitmap from the blob data
185
+ jclass bitmapFactoryClass =
186
+ env->FindClass("android/graphics/BitmapFactory");
187
+ jmethodID decodeByteArrayMethod =
188
+ env->GetStaticMethodID(bitmapFactoryClass, "decodeByteArray",
189
+ "([BII)Landroid/graphics/Bitmap;");
190
+ jint blobLength = env->GetArrayLength(blobData);
191
+ jobject bitmap = env->CallStaticObjectMethod(
192
+ bitmapFactoryClass, decodeByteArrayMethod, blobData, 0, blobLength);
193
+
194
+ if (!bitmap) {
195
+ env->DeleteLocalRef(blobData);
196
+ onError("Couldn't decode image");
197
+ return;
198
+ }
199
+
200
+ // Get bitmap info
201
+ AndroidBitmapInfo bitmapInfo;
202
+ if (AndroidBitmap_getInfo(env, bitmap, &bitmapInfo) !=
203
+ ANDROID_BITMAP_RESULT_SUCCESS) {
204
+ env->DeleteLocalRef(blobData);
205
+ env->DeleteLocalRef(bitmap);
206
+ onError("Couldn't get bitmap info");
207
+ return;
208
+ }
209
+
210
+ // Lock the bitmap pixels
211
+ void *bitmapPixels;
212
+ if (AndroidBitmap_lockPixels(env, bitmap, &bitmapPixels) !=
213
+ ANDROID_BITMAP_RESULT_SUCCESS) {
214
+ env->DeleteLocalRef(blobData);
215
+ env->DeleteLocalRef(bitmap);
216
+ onError("Couldn't lock bitmap pixels");
217
+ return;
218
+ }
219
+
220
+ // Copy the bitmap data
221
+ std::vector<uint8_t> imageData(bitmapInfo.height * bitmapInfo.stride);
222
+ memcpy(imageData.data(), bitmapPixels, imageData.size());
223
+
224
+ // Unlock the bitmap pixels
225
+ AndroidBitmap_unlockPixels(env, bitmap);
226
+
227
+ // Clean up JNI references
228
+ env->DeleteLocalRef(blobData);
229
+ env->DeleteLocalRef(bitmap);
230
+
231
+ ImageData result;
232
+ result.width = static_cast<int>(bitmapInfo.width);
233
+ result.height = static_cast<int>(bitmapInfo.height);
234
+ result.data = std::move(imageData);
235
+
236
+ onSuccess(std::move(result));
237
+ }).detach();
238
+ }
131
239
  };
132
240
 
133
241
  } // namespace rnwgpu
@@ -15,6 +15,11 @@ public:
15
15
 
16
16
  ImageData createImageBitmap(std::string blobId, double offset,
17
17
  double size) override;
18
+
19
+ void createImageBitmapAsync(
20
+ std::string blobId, double offset, double size,
21
+ std::function<void(ImageData)> onSuccess,
22
+ std::function<void(std::string)> onError) override;
18
23
  };
19
24
 
20
25
  } // namespace rnwgpu
@@ -95,4 +95,73 @@ ImageData ApplePlatformContext::createImageBitmap(std::string blobId,
95
95
  return result;
96
96
  }
97
97
 
98
+ void ApplePlatformContext::createImageBitmapAsync(
99
+ std::string blobId, double offset, double size,
100
+ std::function<void(ImageData)> onSuccess,
101
+ std::function<void(std::string)> onError) {
102
+ // Capture blob data on the current thread (requires RCTBridge access)
103
+ RCTBlobManager *blobManager =
104
+ [[RCTBridge currentBridge] moduleForClass:RCTBlobManager.class];
105
+ NSData *blobData =
106
+ [blobManager resolve:[NSString stringWithUTF8String:blobId.c_str()]
107
+ offset:(long)offset
108
+ size:(long)size];
109
+
110
+ if (!blobData) {
111
+ onError("Couldn't retrieve blob data");
112
+ return;
113
+ }
114
+
115
+ // Retain the data for the background block
116
+ NSData *retainedData = [blobData copy];
117
+
118
+ // Dispatch heavy image decoding work to a background queue
119
+ dispatch_async(
120
+ dispatch_get_global_queue(QOS_CLASS_USER_INITIATED, 0), ^{
121
+ @autoreleasepool {
122
+ #if !TARGET_OS_OSX
123
+ UIImage *image = [UIImage imageWithData:retainedData];
124
+ #else
125
+ NSImage *image = [[NSImage alloc] initWithData:retainedData];
126
+ #endif
127
+ if (!image) {
128
+ onError("Couldn't decode image");
129
+ return;
130
+ }
131
+
132
+ #if !TARGET_OS_OSX
133
+ CGImageRef cgImage = image.CGImage;
134
+ #else
135
+ CGImageRef cgImage = [image CGImageForProposedRect:NULL
136
+ context:NULL
137
+ hints:NULL];
138
+ #endif
139
+ size_t width = CGImageGetWidth(cgImage);
140
+ size_t height = CGImageGetHeight(cgImage);
141
+ size_t bitsPerComponent = 8;
142
+ size_t bytesPerRow = width * 4;
143
+ std::vector<uint8_t> imageData(height * bytesPerRow);
144
+
145
+ CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
146
+ CGContextRef context = CGBitmapContextCreate(
147
+ imageData.data(), width, height, bitsPerComponent, bytesPerRow,
148
+ colorSpace,
149
+ kCGImageAlphaPremultipliedLast | kCGBitmapByteOrder32Big);
150
+
151
+ CGContextDrawImage(context, CGRectMake(0, 0, width, height), cgImage);
152
+
153
+ CGContextRelease(context);
154
+ CGColorSpaceRelease(colorSpace);
155
+
156
+ ImageData result;
157
+ result.width = static_cast<int>(width);
158
+ result.height = static_cast<int>(height);
159
+ result.data = std::move(imageData);
160
+ result.format = wgpu::TextureFormat::RGBA8Unorm;
161
+
162
+ onSuccess(std::move(result));
163
+ }
164
+ });
165
+ }
166
+
98
167
  } // namespace rnwgpu
@@ -9,9 +9,10 @@
9
9
  #include <variant>
10
10
  #include <map>
11
11
  #include <unordered_set>
12
-
13
12
  #include <jsi/jsi.h>
14
13
 
14
+ #include "WGPULogger.h"
15
+
15
16
  #include "EnumMapper.h"
16
17
  #include "Promise.h"
17
18
 
@@ -308,10 +309,17 @@ template <typename T> struct JSIConverter<T, std::enable_if_t<is_shared_ptr_to_n
308
309
  #endif
309
310
  jsi::Object object = arg.getObject(runtime);
310
311
  #if DEBUG
311
- if (!object.hasNativeState<TPointee>(runtime)) {
312
- [[unlikely]];
312
+ if (!object.hasNativeState<TPointee>(runtime)) [[unlikely]] {
313
+ // Log instead of throwing: hasNativeState<T>() uses dynamic_cast (RTTI)
314
+ // which can return false across shared-library / JSI-runtime boundaries
315
+ // on iOS (duplicate typeinfo symbols in separate .dylib modules).
316
+ // getNativeState<T>() below uses static_pointer_cast and works correctly
317
+ // even when dynamic_cast fails, so this is not a fatal error.
313
318
  std::string stringRepresentation = arg.toString(runtime).utf8(runtime);
314
- throw jsi::JSError(runtime, invalidTypeErrorMessage(stringRepresentation, "It is a different NativeState<T>!"));
319
+ Logger::logToConsole("NativeState<T> RTTI mismatch for \"%s\" (expected %s) "
320
+ "-- this is likely a false positive from dynamic_cast across JSI "
321
+ "runtime boundaries; continuing with static_pointer_cast.",
322
+ stringRepresentation.c_str(), getFriendlyTypename().c_str());
315
323
  }
316
324
  #endif
317
325
  return object.getNativeState<TPointee>(runtime);
@@ -1,5 +1,6 @@
1
1
  #pragma once
2
2
 
3
+ #include <functional>
3
4
  #include <memory>
4
5
  #include <string>
5
6
  #include <vector>
@@ -24,6 +25,12 @@ public:
24
25
  int width, int height) = 0;
25
26
  virtual ImageData createImageBitmap(std::string blobId, double offset,
26
27
  double size) = 0;
28
+
29
+ // Async version that performs image decoding on a background thread
30
+ virtual void createImageBitmapAsync(
31
+ std::string blobId, double offset, double size,
32
+ std::function<void(ImageData)> onSuccess,
33
+ std::function<void(std::string)> onError) = 0;
27
34
  };
28
35
 
29
36
  } // namespace rnwgpu
@@ -35,6 +35,7 @@
35
35
  #include "GPUSupportedLimits.h"
36
36
  #include "GPUTexture.h"
37
37
  #include "GPUTextureView.h"
38
+ #include "GPUUncapturedErrorEvent.h"
38
39
  #include "GPUValidationError.h"
39
40
 
40
41
  // Enums
@@ -60,7 +61,8 @@ RNWebGPUManager::RNWebGPUManager(
60
61
  BaseRuntimeAwareCache::setMainJsRuntime(_jsRuntime);
61
62
 
62
63
  auto gpu = std::make_shared<GPU>(*_jsRuntime);
63
- auto rnWebGPU = std::make_shared<RNWebGPU>(gpu, _platformContext);
64
+ auto rnWebGPU =
65
+ std::make_shared<RNWebGPU>(gpu, _platformContext, _jsCallInvoker);
64
66
  _gpu = gpu->get();
65
67
  _jsRuntime->global().setProperty(*_jsRuntime, "RNWebGPU",
66
68
  RNWebGPU::create(*_jsRuntime, rnWebGPU));
@@ -86,6 +88,7 @@ RNWebGPUManager::RNWebGPUManager(
86
88
  GPUInternalError::installConstructor(*_jsRuntime);
87
89
  GPUOutOfMemoryError::installConstructor(*_jsRuntime);
88
90
  GPUValidationError::installConstructor(*_jsRuntime);
91
+ GPUUncapturedErrorEvent::installConstructor(*_jsRuntime);
89
92
  GPUPipelineLayout::installConstructor(*_jsRuntime);
90
93
  GPUQuerySet::installConstructor(*_jsRuntime);
91
94
  GPUQueue::installConstructor(*_jsRuntime);
@@ -48,6 +48,7 @@ public:
48
48
  }
49
49
 
50
50
  inline const wgpu::Instance get() { return _instance; }
51
+ inline std::shared_ptr<async::AsyncRunner> getAsyncRunner() { return _async; }
51
52
 
52
53
  private:
53
54
  wgpu::Instance _instance;
@@ -50,6 +50,8 @@ async::AsyncTaskHandle GPUAdapter::requestDevice(
50
50
  });
51
51
 
52
52
  // Set uncaptured error callback using new template API
53
+ // Note: This callback cannot capture variables, so we use a static registry
54
+ // to look up the GPUDevice from the wgpu::Device handle.
53
55
  aDescriptor.SetUncapturedErrorCallback([](const wgpu::Device &device,
54
56
  wgpu::ErrorType type,
55
57
  wgpu::StringView message) {
@@ -70,11 +72,16 @@ async::AsyncTaskHandle GPUAdapter::requestDevice(
70
72
  default:
71
73
  errorType = "Unknown";
72
74
  }
75
+ std::string msg =
76
+ message.length > 0 ? std::string(message.data, message.length) : "";
73
77
  std::string fullMessage =
74
- message.length > 0 ? std::string(errorType) + ": " +
75
- std::string(message.data, message.length)
76
- : "no message";
77
- fprintf(stderr, "%s", fullMessage.c_str());
78
+ msg.length() > 0 ? std::string(errorType) + ": " + msg : "no message";
79
+ fprintf(stderr, "%s\n", fullMessage.c_str());
80
+
81
+ // Look up the GPUDevice from the registry and notify it
82
+ if (auto gpuDevice = GPUDevice::lookupDevice(device.Get())) {
83
+ gpuDevice->notifyUncapturedError(type, std::move(msg));
84
+ }
78
85
  });
79
86
  std::string label =
80
87
  descriptor.has_value() ? descriptor.value()->label.value_or("") : "";
@@ -138,6 +145,11 @@ async::AsyncTaskHandle GPUAdapter::requestDevice(
138
145
  auto deviceHost = std::make_shared<GPUDevice>(std::move(device),
139
146
  asyncRunner, label);
140
147
  *deviceLostBinding = deviceHost;
148
+
149
+ // Register the device in the static registry so the uncaptured
150
+ // error callback can find it
151
+ GPUDevice::registerDevice(deviceHost->get().Get(), deviceHost);
152
+
141
153
  resolve([deviceHost = std::move(deviceHost)](
142
154
  jsi::Runtime &runtime) mutable {
143
155
  return JSIConverter<std::shared_ptr<GPUDevice>>::toJSI(
@@ -431,4 +431,62 @@ async::AsyncTaskHandle GPUDevice::getLost() {
431
431
  _lostHandle = handle;
432
432
  return handle;
433
433
  }
434
+ void GPUDevice::addEventListener(std::string type, jsi::Function callback) {
435
+ auto funcPtr = std::make_shared<jsi::Function>(std::move(callback));
436
+ _eventListeners[type].push_back(funcPtr);
437
+ }
438
+
439
+ void GPUDevice::removeEventListener(std::string type, jsi::Function callback) {
440
+ // Note: Since jsi::Function doesn't support equality comparison,
441
+ // we cannot reliably remove a specific listener. This is a no-op.
442
+ // Most use cases (like BabylonJS) only need addEventListener to work.
443
+ (void)type;
444
+ (void)callback;
445
+ }
446
+
447
+ void GPUDevice::notifyUncapturedError(wgpu::ErrorType type,
448
+ std::string message) {
449
+ auto it = _eventListeners.find("uncapturederror");
450
+ if (it == _eventListeners.end() || it->second.empty()) {
451
+ return;
452
+ }
453
+
454
+ auto runtime = getCreationRuntime();
455
+ if (runtime == nullptr) {
456
+ return;
457
+ }
458
+
459
+ // Create the appropriate error object based on type
460
+ GPUErrorVariant error;
461
+ switch (type) {
462
+ case wgpu::ErrorType::Validation:
463
+ error = std::make_shared<GPUValidationError>(message);
464
+ break;
465
+ case wgpu::ErrorType::OutOfMemory:
466
+ error = std::make_shared<GPUOutOfMemoryError>(message);
467
+ break;
468
+ case wgpu::ErrorType::Internal:
469
+ case wgpu::ErrorType::Unknown:
470
+ default:
471
+ error = std::make_shared<GPUInternalError>(message);
472
+ break;
473
+ }
474
+
475
+ // Create the event object
476
+ auto event = std::make_shared<GPUUncapturedErrorEvent>(std::move(error));
477
+ auto eventValue =
478
+ JSIConverter<std::shared_ptr<GPUUncapturedErrorEvent>>::toJSI(*runtime,
479
+ event);
480
+
481
+ // Call all registered listeners
482
+ for (const auto &listener : it->second) {
483
+ try {
484
+ listener->call(*runtime, eventValue);
485
+ } catch (const std::exception &e) {
486
+ // Log but don't throw - we don't want one listener to break others
487
+ fprintf(stderr, "Error in uncapturederror listener: %s\n", e.what());
488
+ }
489
+ }
490
+ }
491
+
434
492
  } // namespace rnwgpu
@@ -1,11 +1,15 @@
1
1
  #pragma once
2
2
 
3
+ #include <functional>
3
4
  #include <memory>
5
+ #include <mutex>
4
6
  #include <optional>
5
7
  #include <string>
8
+ #include <unordered_map>
6
9
  #include <unordered_set>
7
10
  #include <utility>
8
11
  #include <variant>
12
+ #include <vector>
9
13
 
10
14
  #include "Unions.h"
11
15
 
@@ -46,6 +50,7 @@
46
50
  #include "GPUSupportedLimits.h"
47
51
  #include "GPUTexture.h"
48
52
  #include "GPUTextureDescriptor.h"
53
+ #include "GPUUncapturedErrorEvent.h"
49
54
 
50
55
  namespace rnwgpu {
51
56
 
@@ -61,6 +66,44 @@ public:
61
66
  : NativeObject(CLASS_NAME), _instance(instance), _async(async),
62
67
  _label(label) {}
63
68
 
69
+ ~GPUDevice() override {
70
+ // Unregister from the static registry
71
+ unregisterDevice(_instance.Get());
72
+ }
73
+
74
+ // Static registry for looking up GPUDevice from wgpu::Device in callbacks
75
+ static void registerDevice(WGPUDevice handle,
76
+ std::weak_ptr<GPUDevice> device) {
77
+ std::lock_guard<std::mutex> lock(getRegistryMutex());
78
+ getRegistry()[handle] = device;
79
+ }
80
+
81
+ static void unregisterDevice(WGPUDevice handle) {
82
+ std::lock_guard<std::mutex> lock(getRegistryMutex());
83
+ getRegistry().erase(handle);
84
+ }
85
+
86
+ static std::shared_ptr<GPUDevice> lookupDevice(WGPUDevice handle) {
87
+ std::lock_guard<std::mutex> lock(getRegistryMutex());
88
+ auto it = getRegistry().find(handle);
89
+ if (it != getRegistry().end()) {
90
+ return it->second.lock();
91
+ }
92
+ return nullptr;
93
+ }
94
+
95
+ private:
96
+ static std::unordered_map<WGPUDevice, std::weak_ptr<GPUDevice>> &
97
+ getRegistry() {
98
+ static std::unordered_map<WGPUDevice, std::weak_ptr<GPUDevice>> registry;
99
+ return registry;
100
+ }
101
+
102
+ static std::mutex &getRegistryMutex() {
103
+ static std::mutex mutex;
104
+ return mutex;
105
+ }
106
+
64
107
  public:
65
108
  std::string getBrand() { return CLASS_NAME; }
66
109
 
@@ -103,8 +146,13 @@ public:
103
146
  std::shared_ptr<GPUQueue> getQueue();
104
147
  async::AsyncTaskHandle getLost();
105
148
  void notifyDeviceLost(wgpu::DeviceLostReason reason, std::string message);
149
+ void notifyUncapturedError(wgpu::ErrorType type, std::string message);
106
150
  void forceLossForTesting();
107
151
 
152
+ // EventTarget methods
153
+ void addEventListener(std::string type, jsi::Function callback);
154
+ void removeEventListener(std::string type, jsi::Function callback);
155
+
108
156
  std::string getLabel() { return _label; }
109
157
  void setLabel(const std::string &label) {
110
158
  _label = label;
@@ -155,6 +203,38 @@ public:
155
203
  &GPUDevice::setLabel);
156
204
  installMethod(runtime, prototype, "forceLossForTesting",
157
205
  &GPUDevice::forceLossForTesting);
206
+
207
+ // EventTarget methods - installed manually since they take jsi::Function
208
+ auto addEventListenerFunc = jsi::Function::createFromHostFunction(
209
+ runtime, jsi::PropNameID::forUtf8(runtime, "addEventListener"), 2,
210
+ [](jsi::Runtime &rt, const jsi::Value &thisVal, const jsi::Value *args,
211
+ size_t count) -> jsi::Value {
212
+ if (count < 2 || !args[0].isString() || !args[1].isObject() ||
213
+ !args[1].getObject(rt).isFunction(rt)) {
214
+ return jsi::Value::undefined();
215
+ }
216
+ auto native = GPUDevice::fromValue(rt, thisVal);
217
+ native->addEventListener(args[0].getString(rt).utf8(rt),
218
+ args[1].getObject(rt).getFunction(rt));
219
+ return jsi::Value::undefined();
220
+ });
221
+ prototype.setProperty(runtime, "addEventListener", addEventListenerFunc);
222
+
223
+ auto removeEventListenerFunc = jsi::Function::createFromHostFunction(
224
+ runtime, jsi::PropNameID::forUtf8(runtime, "removeEventListener"), 2,
225
+ [](jsi::Runtime &rt, const jsi::Value &thisVal, const jsi::Value *args,
226
+ size_t count) -> jsi::Value {
227
+ if (count < 2 || !args[0].isString() || !args[1].isObject() ||
228
+ !args[1].getObject(rt).isFunction(rt)) {
229
+ return jsi::Value::undefined();
230
+ }
231
+ auto native = GPUDevice::fromValue(rt, thisVal);
232
+ native->removeEventListener(args[0].getString(rt).utf8(rt),
233
+ args[1].getObject(rt).getFunction(rt));
234
+ return jsi::Value::undefined();
235
+ });
236
+ prototype.setProperty(runtime, "removeEventListener",
237
+ removeEventListenerFunc);
158
238
  }
159
239
 
160
240
  inline const wgpu::Device get() { return _instance; }
@@ -169,6 +249,11 @@ private:
169
249
  std::shared_ptr<GPUDeviceLostInfo> _lostInfo;
170
250
  bool _lostSettled = false;
171
251
  std::optional<async::AsyncTaskHandle::ResolveFunction> _lostResolve;
252
+
253
+ // Event listeners storage - keyed by event type
254
+ // Each entry contains a vector of shared_ptr to functions
255
+ std::unordered_map<std::string, std::vector<std::shared_ptr<jsi::Function>>>
256
+ _eventListeners;
172
257
  };
173
258
 
174
259
  } // namespace rnwgpu
@@ -0,0 +1,71 @@
1
+ #pragma once
2
+
3
+ #include <memory>
4
+ #include <string>
5
+ #include <variant>
6
+
7
+ #include "JSIConverter.h"
8
+ #include "NativeObject.h"
9
+
10
+ #include "GPUInternalError.h"
11
+ #include "GPUOutOfMemoryError.h"
12
+ #include "GPUValidationError.h"
13
+
14
+ namespace rnwgpu {
15
+
16
+ namespace jsi = facebook::jsi;
17
+
18
+ using GPUErrorVariant = std::variant<std::shared_ptr<GPUValidationError>,
19
+ std::shared_ptr<GPUOutOfMemoryError>,
20
+ std::shared_ptr<GPUInternalError>>;
21
+
22
+ class GPUUncapturedErrorEvent : public NativeObject<GPUUncapturedErrorEvent> {
23
+ public:
24
+ static constexpr const char *CLASS_NAME = "GPUUncapturedErrorEvent";
25
+
26
+ explicit GPUUncapturedErrorEvent(GPUErrorVariant error)
27
+ : NativeObject(CLASS_NAME), _error(std::move(error)) {}
28
+
29
+ public:
30
+ std::string getBrand() { return CLASS_NAME; }
31
+ std::string getType() { return "uncapturederror"; }
32
+
33
+ static void definePrototype(jsi::Runtime &runtime, jsi::Object &prototype) {
34
+ installGetter(runtime, prototype, "__brand",
35
+ &GPUUncapturedErrorEvent::getBrand);
36
+ installGetter(runtime, prototype, "type",
37
+ &GPUUncapturedErrorEvent::getType);
38
+
39
+ // Custom getter for error that handles the variant conversion
40
+ auto errorGetter = jsi::Function::createFromHostFunction(
41
+ runtime, jsi::PropNameID::forUtf8(runtime, "get_error"), 0,
42
+ [](jsi::Runtime &rt, const jsi::Value &thisVal, const jsi::Value *args,
43
+ size_t count) -> jsi::Value {
44
+ auto native = GPUUncapturedErrorEvent::fromValue(rt, thisVal);
45
+ return std::visit(
46
+ [&rt](auto &&err) -> jsi::Value {
47
+ using T = std::decay_t<decltype(err)>;
48
+ return JSIConverter<T>::toJSI(rt, err);
49
+ },
50
+ native->_error);
51
+ });
52
+
53
+ auto objectCtor = runtime.global().getPropertyAsObject(runtime, "Object");
54
+ auto defineProperty =
55
+ objectCtor.getPropertyAsFunction(runtime, "defineProperty");
56
+
57
+ jsi::Object descriptor(runtime);
58
+ descriptor.setProperty(runtime, "get", errorGetter);
59
+ descriptor.setProperty(runtime, "enumerable", true);
60
+ descriptor.setProperty(runtime, "configurable", true);
61
+
62
+ defineProperty.call(runtime, prototype,
63
+ jsi::String::createFromUtf8(runtime, "error"),
64
+ descriptor);
65
+ }
66
+
67
+ private:
68
+ GPUErrorVariant _error;
69
+ };
70
+
71
+ } // namespace rnwgpu
@@ -11,6 +11,11 @@
11
11
  #include "ImageBitmap.h"
12
12
  #include "PlatformContext.h"
13
13
 
14
+ #include <ReactCommon/CallInvoker.h>
15
+
16
+ #include "JSIConverter.h"
17
+ #include "Promise.h"
18
+
14
19
  namespace rnwgpu {
15
20
 
16
21
  namespace jsi = facebook::jsi;
@@ -23,14 +28,41 @@ struct Blob {
23
28
  std::string name;
24
29
  };
25
30
 
31
+ // JSIConverter specialization must be declared before use
32
+ template <> struct JSIConverter<std::shared_ptr<Blob>> {
33
+ static std::shared_ptr<Blob>
34
+ fromJSI(jsi::Runtime &runtime, const jsi::Value &arg, bool outOfBounds) {
35
+ if (!outOfBounds && arg.isObject()) {
36
+ auto result = std::make_unique<Blob>();
37
+ auto val = arg.asObject(runtime);
38
+ if (val.hasProperty(runtime, "_data")) {
39
+ auto value = val.getPropertyAsObject(runtime, "_data");
40
+ result->blobId = JSIConverter<std::string>::fromJSI(
41
+ runtime, value.getProperty(runtime, "blobId"), false);
42
+ result->size = JSIConverter<double>::fromJSI(
43
+ runtime, value.getProperty(runtime, "size"), false);
44
+ result->offset = JSIConverter<double>::fromJSI(
45
+ runtime, value.getProperty(runtime, "offset"), false);
46
+ }
47
+ return result;
48
+ } else {
49
+ throw std::runtime_error("Invalid Blob::fromJSI()");
50
+ }
51
+ }
52
+ static jsi::Value toJSI(jsi::Runtime &runtime, std::shared_ptr<Blob> arg) {
53
+ throw std::runtime_error("Invalid Blob::toJSI()");
54
+ }
55
+ };
56
+
26
57
  class RNWebGPU : public NativeObject<RNWebGPU> {
27
58
  public:
28
59
  static constexpr const char *CLASS_NAME = "RNWebGPU";
29
60
 
30
61
  explicit RNWebGPU(std::shared_ptr<GPU> gpu,
31
- std::shared_ptr<PlatformContext> platformContext)
32
- : NativeObject(CLASS_NAME), _gpu(gpu), _platformContext(platformContext) {
33
- }
62
+ std::shared_ptr<PlatformContext> platformContext,
63
+ std::shared_ptr<facebook::react::CallInvoker> callInvoker)
64
+ : NativeObject(CLASS_NAME), _gpu(gpu), _platformContext(platformContext),
65
+ _callInvoker(callInvoker) {}
34
66
 
35
67
  std::shared_ptr<GPU> getGPU() { return _gpu; }
36
68
 
@@ -43,11 +75,41 @@ public:
43
75
  return ctx;
44
76
  }
45
77
 
46
- std::shared_ptr<ImageBitmap> createImageBitmap(std::shared_ptr<Blob> blob) {
47
- auto imageData = _platformContext->createImageBitmap(
48
- blob->blobId, blob->offset, blob->size);
49
- auto imageBitmap = std::make_shared<ImageBitmap>(imageData);
50
- return imageBitmap;
78
+ jsi::Value createImageBitmap(jsi::Runtime &runtime,
79
+ const jsi::Value & /*thisVal*/,
80
+ const jsi::Value *args, size_t count) {
81
+ if (count < 1) {
82
+ throw jsi::JSError(runtime, "createImageBitmap requires a Blob argument");
83
+ }
84
+
85
+ auto blob =
86
+ JSIConverter<std::shared_ptr<Blob>>::fromJSI(runtime, args[0], false);
87
+ auto platformContext = _platformContext;
88
+ auto callInvoker = _callInvoker;
89
+ std::string blobId = blob->blobId;
90
+ double offset = blob->offset;
91
+ double size = blob->size;
92
+
93
+ return Promise::createPromise(
94
+ runtime,
95
+ [platformContext, callInvoker, blobId, offset,
96
+ size](jsi::Runtime & /*runtime*/, std::shared_ptr<Promise> promise) {
97
+ platformContext->createImageBitmapAsync(
98
+ blobId, offset, size,
99
+ [callInvoker, promise](ImageData imageData) {
100
+ auto imageBitmap = std::make_shared<ImageBitmap>(imageData);
101
+ callInvoker->invokeAsync(
102
+ [promise, imageBitmap]() {
103
+ promise->resolve(
104
+ JSIConverter<std::shared_ptr<ImageBitmap>>::toJSI(
105
+ promise->runtime, imageBitmap));
106
+ });
107
+ },
108
+ [callInvoker, promise](std::string error) {
109
+ callInvoker->invokeAsync(
110
+ [promise, error]() { promise->reject(error); });
111
+ });
112
+ });
51
113
  }
52
114
 
53
115
  std::shared_ptr<Canvas> getNativeSurface(int contextId) {
@@ -75,35 +137,7 @@ public:
75
137
  private:
76
138
  std::shared_ptr<GPU> _gpu;
77
139
  std::shared_ptr<PlatformContext> _platformContext;
78
- };
79
-
80
- template <> struct JSIConverter<std::shared_ptr<Blob>> {
81
- static std::shared_ptr<Blob>
82
- fromJSI(jsi::Runtime &runtime, const jsi::Value &arg, bool outOfBounds) {
83
- if (!outOfBounds && arg.isObject()) {
84
- auto result = std::make_unique<Blob>();
85
- auto val = arg.asObject(runtime);
86
- if (val.hasProperty(runtime, "_data")) {
87
- auto value = val.getPropertyAsObject(runtime, "_data");
88
- result->blobId = JSIConverter<std::string>::fromJSI(
89
- runtime, value.getProperty(runtime, "blobId"), false);
90
- // result->type = JSIConverter<std::string>::fromJSI(
91
- // runtime, value.getProperty(runtime, "type"), false);
92
- // result->name = JSIConverter<std::string>::fromJSI(
93
- // runtime, value.getProperty(runtime, "name"), false);
94
- result->size = JSIConverter<double>::fromJSI(
95
- runtime, value.getProperty(runtime, "size"), false);
96
- result->offset = JSIConverter<double>::fromJSI(
97
- runtime, value.getProperty(runtime, "offset"), false);
98
- }
99
- return result;
100
- } else {
101
- throw std::runtime_error("Invalid Blob::fromJSI()");
102
- }
103
- }
104
- static jsi::Value toJSI(jsi::Runtime &runtime, std::shared_ptr<Blob> arg) {
105
- throw std::runtime_error("Invalid Blob::toJSI()");
106
- }
140
+ std::shared_ptr<facebook::react::CallInvoker> _callInvoker;
107
141
  };
108
142
 
109
143
  } // namespace rnwgpu
@@ -20,7 +20,6 @@ const registerWebGPUForReanimated = () => {
20
20
  }
21
21
  isRegistered = true;
22
22
  try {
23
- // eslint-disable-next-line @typescript-eslint/no-var-requires
24
23
  const {
25
24
  registerCustomSerializable
26
25
  } = require("react-native-worklets");
@@ -1 +1 @@
1
- {"version":3,"names":["isRegistered","registerWebGPUForReanimated","registerCustomSerializable","require","name","determine","value","__webgpuIsWebGPUObject","pack","__webgpuBox","unpack","boxed","unbox","exports"],"sourceRoot":"../../../../src","sources":["external/reanimated/registerWebGPUForReanimated.ts"],"mappings":";;;;;;AAAA;;AAMA,IAAIA,YAAY,GAAG,KAAK;;AAExB;AACA;AACA;AACA;AACA;AACA;AACO,MAAMC,2BAA2B,GAAGA,CAAA,KAAM;EAC/C,IAAID,YAAY,EAAE;IAChB;EACF;EACAA,YAAY,GAAG,IAAI;EAEnB,IAAI;IACF;IACA,MAAM;MAAEE;IAA2B,CAAC,GAAGC,OAAO,CAAC,uBAAuB,CAAC;IAEvED,0BAA0B,CAAC;MACzBE,IAAI,EAAE,QAAQ;MACdC,SAAS,EAAGC,KAAa,IAAsB;QAC7C,SAAS;;QACT,OAAOC,sBAAsB,CAACD,KAAK,CAAC;MACtC,CAAC;MACDE,IAAI,EAAGF,KAAa,IAAK;QACvB,SAAS;;QACT,OAAOG,WAAW,CAACH,KAAK,CAAC;MAC3B,CAAC;MACDI,MAAM,EAAGC,KAA8B,IAAK;QAC1C,SAAS;;QACT,OAAOA,KAAK,CAACC,KAAK,CAAC,CAAC;MACtB;IACF,CAAC,CAAC;EACJ,CAAC,CAAC,MAAM;IACN;EAAA;AAEJ,CAAC;AAACC,OAAA,CAAAZ,2BAAA,GAAAA,2BAAA","ignoreList":[]}
1
+ {"version":3,"names":["isRegistered","registerWebGPUForReanimated","registerCustomSerializable","require","name","determine","value","__webgpuIsWebGPUObject","pack","__webgpuBox","unpack","boxed","unbox","exports"],"sourceRoot":"../../../../src","sources":["external/reanimated/registerWebGPUForReanimated.ts"],"mappings":";;;;;;AAAA;;AAOA,IAAIA,YAAY,GAAG,KAAK;;AAExB;AACA;AACA;AACA;AACA;AACA;AACO,MAAMC,2BAA2B,GAAGA,CAAA,KAAM;EAC/C,IAAID,YAAY,EAAE;IAChB;EACF;EACAA,YAAY,GAAG,IAAI;EAEnB,IAAI;IACF,MAAM;MAAEE;IAA2B,CAAC,GAAGC,OAAO,CAAC,uBAAuB,CAAC;IAEvED,0BAA0B,CAAC;MACzBE,IAAI,EAAE,QAAQ;MACdC,SAAS,EAAGC,KAAa,IAAsB;QAC7C,SAAS;;QACT,OAAOC,sBAAsB,CAACD,KAAK,CAAC;MACtC,CAAC;MACDE,IAAI,EAAGF,KAAa,IAAK;QACvB,SAAS;;QACT,OAAOG,WAAW,CAACH,KAAK,CAAC;MAC3B,CAAC;MACDI,MAAM,EAAGC,KAA8B,IAAK;QAC1C,SAAS;;QACT,OAAOA,KAAK,CAACC,KAAK,CAAC,CAAC;MACtB;IACF,CAAC,CAAC;EACJ,CAAC,CAAC,MAAM;IACN;EAAA;AAEJ,CAAC;AAACC,OAAA,CAAAZ,2BAAA,GAAAA,2BAAA","ignoreList":[]}
@@ -83,5 +83,5 @@ if (!navigator) {
83
83
  }
84
84
  }
85
85
  }
86
- global.createImageBitmap = global.createImageBitmap ?? ((...params) => new Promise(resolve => resolve(RNWebGPU.createImageBitmap(...params))));
86
+ global.createImageBitmap = global.createImageBitmap ?? RNWebGPU.createImageBitmap.bind(RNWebGPU);
87
87
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["_external","require","_NativeWebGPUModule","_interopRequireDefault","_Canvas","Object","keys","forEach","key","prototype","hasOwnProperty","call","_exportNames","exports","defineProperty","enumerable","get","_Offscreen","_WebGPUViewNativeComponent","_hooks","e","__esModule","default","WebGPUModule","install","registerWebGPUForReanimated","navigator","gpu","RNWebGPU","userAgent","global","createImageBitmap","params","Promise","resolve"],"sourceRoot":"../../../src","sources":["main/index.tsx"],"mappings":"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","ignoreList":[]}
1
+ {"version":3,"names":["_external","require","_NativeWebGPUModule","_interopRequireDefault","_Canvas","Object","keys","forEach","key","prototype","hasOwnProperty","call","_exportNames","exports","defineProperty","enumerable","get","_Offscreen","_WebGPUViewNativeComponent","_hooks","e","__esModule","default","WebGPUModule","install","registerWebGPUForReanimated","navigator","gpu","RNWebGPU","userAgent","global","createImageBitmap","bind"],"sourceRoot":"../../../src","sources":["main/index.tsx"],"mappings":"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","ignoreList":[]}
@@ -14,7 +14,6 @@ export const registerWebGPUForReanimated = () => {
14
14
  }
15
15
  isRegistered = true;
16
16
  try {
17
- // eslint-disable-next-line @typescript-eslint/no-var-requires
18
17
  const {
19
18
  registerCustomSerializable
20
19
  } = require("react-native-worklets");
@@ -1 +1 @@
1
- {"version":3,"names":["isRegistered","registerWebGPUForReanimated","registerCustomSerializable","require","name","determine","value","__webgpuIsWebGPUObject","pack","__webgpuBox","unpack","boxed","unbox"],"sourceRoot":"../../../../src","sources":["external/reanimated/registerWebGPUForReanimated.ts"],"mappings":"AAAA;;AAMA,IAAIA,YAAY,GAAG,KAAK;;AAExB;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,MAAMC,2BAA2B,GAAGA,CAAA,KAAM;EAC/C,IAAID,YAAY,EAAE;IAChB;EACF;EACAA,YAAY,GAAG,IAAI;EAEnB,IAAI;IACF;IACA,MAAM;MAAEE;IAA2B,CAAC,GAAGC,OAAO,CAAC,uBAAuB,CAAC;IAEvED,0BAA0B,CAAC;MACzBE,IAAI,EAAE,QAAQ;MACdC,SAAS,EAAGC,KAAa,IAAsB;QAC7C,SAAS;;QACT,OAAOC,sBAAsB,CAACD,KAAK,CAAC;MACtC,CAAC;MACDE,IAAI,EAAGF,KAAa,IAAK;QACvB,SAAS;;QACT,OAAOG,WAAW,CAACH,KAAK,CAAC;MAC3B,CAAC;MACDI,MAAM,EAAGC,KAA8B,IAAK;QAC1C,SAAS;;QACT,OAAOA,KAAK,CAACC,KAAK,CAAC,CAAC;MACtB;IACF,CAAC,CAAC;EACJ,CAAC,CAAC,MAAM;IACN;EAAA;AAEJ,CAAC","ignoreList":[]}
1
+ {"version":3,"names":["isRegistered","registerWebGPUForReanimated","registerCustomSerializable","require","name","determine","value","__webgpuIsWebGPUObject","pack","__webgpuBox","unpack","boxed","unbox"],"sourceRoot":"../../../../src","sources":["external/reanimated/registerWebGPUForReanimated.ts"],"mappings":"AAAA;;AAOA,IAAIA,YAAY,GAAG,KAAK;;AAExB;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,MAAMC,2BAA2B,GAAGA,CAAA,KAAM;EAC/C,IAAID,YAAY,EAAE;IAChB;EACF;EACAA,YAAY,GAAG,IAAI;EAEnB,IAAI;IACF,MAAM;MAAEE;IAA2B,CAAC,GAAGC,OAAO,CAAC,uBAAuB,CAAC;IAEvED,0BAA0B,CAAC;MACzBE,IAAI,EAAE,QAAQ;MACdC,SAAS,EAAGC,KAAa,IAAsB;QAC7C,SAAS;;QACT,OAAOC,sBAAsB,CAACD,KAAK,CAAC;MACtC,CAAC;MACDE,IAAI,EAAGF,KAAa,IAAK;QACvB,SAAS;;QACT,OAAOG,WAAW,CAACH,KAAK,CAAC;MAC3B,CAAC;MACDI,MAAM,EAAGC,KAA8B,IAAK;QAC1C,SAAS;;QACT,OAAOA,KAAK,CAACC,KAAK,CAAC,CAAC;MACtB;IACF,CAAC,CAAC;EACJ,CAAC,CAAC,MAAM;IACN;EAAA;AAEJ,CAAC","ignoreList":[]}
@@ -25,5 +25,5 @@ if (!navigator) {
25
25
  }
26
26
  }
27
27
  }
28
- global.createImageBitmap = global.createImageBitmap ?? ((...params) => new Promise(resolve => resolve(RNWebGPU.createImageBitmap(...params))));
28
+ global.createImageBitmap = global.createImageBitmap ?? RNWebGPU.createImageBitmap.bind(RNWebGPU);
29
29
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["registerWebGPUForReanimated","WebGPUModule","default","install","navigator","gpu","RNWebGPU","userAgent","global","createImageBitmap","params","Promise","resolve"],"sourceRoot":"../../../src","sources":["main/index.tsx"],"mappings":"AAAA,SAASA,2BAA2B,QAAQ,aAAa;AACzD,OAAOC,YAAY,MAAM,uBAAuB;AAEhD,cAAc,WAAW;AACzB,cAAc,cAAc;AAC5B,cAAc,8BAA8B;AAC5C,cAAc,UAAU;AAExB,SAASC,OAAO,IAAID,YAAY,QAAQ,uBAAuB;AAE/DA,YAAY,CAACE,OAAO,CAAC,CAAC;AAEtBH,2BAA2B,CAAC,CAAC;AAE7B,IAAI,CAACI,SAAS,EAAE;EACd;EACAA,SAAS,GAAG;IACVC,GAAG,EAAEC,QAAQ,CAACD,GAAG;IACjBE,SAAS,EAAE;EACb,CAAC;AACH,CAAC,MAAM;EACLH,SAAS,CAACC,GAAG,GAAGC,QAAQ,CAACD,GAAG;EAC5B,IAAI,OAAOD,SAAS,CAACG,SAAS,KAAK,QAAQ,EAAE;IAC3C,IAAI;MACF;MACA;MACAH,SAAS,CAACG,SAAS,GAAG,cAAc;IACtC,CAAC,CAAC,MAAM;MACN;IAAA;EAEJ;AACF;AAEAC,MAAM,CAACC,iBAAiB,GACtBD,MAAM,CAACC,iBAAiB,KACvB,CAAC,GAAGC,MAA4C,KAC/C,IAAIC,OAAO,CAAEC,OAAO,IAAKA,OAAO,CAACN,QAAQ,CAACG,iBAAiB,CAAC,GAAGC,MAAM,CAAC,CAAC,CAAC,CAAC","ignoreList":[]}
1
+ {"version":3,"names":["registerWebGPUForReanimated","WebGPUModule","default","install","navigator","gpu","RNWebGPU","userAgent","global","createImageBitmap","bind"],"sourceRoot":"../../../src","sources":["main/index.tsx"],"mappings":"AAAA,SAASA,2BAA2B,QAAQ,aAAa;AACzD,OAAOC,YAAY,MAAM,uBAAuB;AAEhD,cAAc,WAAW;AACzB,cAAc,cAAc;AAC5B,cAAc,8BAA8B;AAC5C,cAAc,UAAU;AAExB,SAASC,OAAO,IAAID,YAAY,QAAQ,uBAAuB;AAE/DA,YAAY,CAACE,OAAO,CAAC,CAAC;AAEtBH,2BAA2B,CAAC,CAAC;AAE7B,IAAI,CAACI,SAAS,EAAE;EACd;EACAA,SAAS,GAAG;IACVC,GAAG,EAAEC,QAAQ,CAACD,GAAG;IACjBE,SAAS,EAAE;EACb,CAAC;AACH,CAAC,MAAM;EACLH,SAAS,CAACC,GAAG,GAAGC,QAAQ,CAACD,GAAG;EAC5B,IAAI,OAAOD,SAAS,CAACG,SAAS,KAAK,QAAQ,EAAE;IAC3C,IAAI;MACF;MACA;MACAH,SAAS,CAACG,SAAS,GAAG,cAAc;IACtC,CAAC,CAAC,MAAM;MACN;IAAA;EAEJ;AACF;AAEAC,MAAM,CAACC,iBAAiB,GACtBD,MAAM,CAACC,iBAAiB,IAAIH,QAAQ,CAACG,iBAAiB,CAACC,IAAI,CAACJ,QAAQ,CAAC","ignoreList":[]}
@@ -1 +1 @@
1
- {"version":3,"file":"registerWebGPUForReanimated.d.ts","sourceRoot":"","sources":["../../../../../commonjs/external/reanimated/registerWebGPUForReanimated.js"],"names":[],"mappings":";AAUA;;;;;GAKG;AACH,oDA+BC"}
1
+ {"version":3,"file":"registerWebGPUForReanimated.d.ts","sourceRoot":"","sources":["../../../../../commonjs/external/reanimated/registerWebGPUForReanimated.js"],"names":[],"mappings":";AAUA;;;;;GAKG;AACH,oDA8BC"}
@@ -1 +1 @@
1
- {"version":3,"file":"registerWebGPUForReanimated.d.ts","sourceRoot":"","sources":["../../../../../module/external/reanimated/registerWebGPUForReanimated.js"],"names":[],"mappings":"AAUO,oDA+BN"}
1
+ {"version":3,"file":"registerWebGPUForReanimated.d.ts","sourceRoot":"","sources":["../../../../../module/external/reanimated/registerWebGPUForReanimated.js"],"names":[],"mappings":"AAUO,oDA8BN"}
@@ -1 +1 @@
1
- {"version":3,"file":"registerWebGPUForReanimated.d.ts","sourceRoot":"","sources":["../../../../../src/external/reanimated/registerWebGPUForReanimated.ts"],"names":[],"mappings":"AAQA;;;;;GAKG;AACH,eAAO,MAAM,2BAA2B,YA4BvC,CAAC"}
1
+ {"version":3,"file":"registerWebGPUForReanimated.d.ts","sourceRoot":"","sources":["../../../../../src/external/reanimated/registerWebGPUForReanimated.ts"],"names":[],"mappings":"AASA;;;;;GAKG;AACH,eAAO,MAAM,2BAA2B,YA2BvC,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-wgpu",
3
- "version": "0.5.2",
3
+ "version": "0.5.4",
4
4
  "description": "React Native WebGPU",
5
5
  "main": "lib/commonjs/index",
6
6
  "module": "lib/module/index",
@@ -6,7 +6,7 @@ type ImportType = ReturnType<typeof require>;
6
6
  * This is useful for lazily requiring optional dependencies.
7
7
  */
8
8
  export const createModuleProxy = <TModule>(
9
- getModule: () => ImportType
9
+ getModule: () => ImportType,
10
10
  ): TModule => {
11
11
  const holder: { module: TModule | undefined } = { module: undefined };
12
12
 
@@ -1,8 +1,9 @@
1
1
  // Declare global WebGPU worklet helper functions (installed by native module)
2
2
  declare function __webgpuIsWebGPUObject(obj: unknown): boolean;
3
- declare function __webgpuBox(
4
- obj: object
5
- ): { unbox: () => object; __boxedWebGPU: true };
3
+ declare function __webgpuBox(obj: object): {
4
+ unbox: () => object;
5
+ __boxedWebGPU: true;
6
+ };
6
7
 
7
8
  let isRegistered = false;
8
9
 
@@ -19,7 +20,6 @@ export const registerWebGPUForReanimated = () => {
19
20
  isRegistered = true;
20
21
 
21
22
  try {
22
- // eslint-disable-next-line @typescript-eslint/no-var-requires
23
23
  const { registerCustomSerializable } = require("react-native-worklets");
24
24
 
25
25
  registerCustomSerializable({
@@ -32,6 +32,4 @@ if (!navigator) {
32
32
  }
33
33
 
34
34
  global.createImageBitmap =
35
- global.createImageBitmap ??
36
- ((...params: Parameters<typeof createImageBitmap>) =>
37
- new Promise((resolve) => resolve(RNWebGPU.createImageBitmap(...params))));
35
+ global.createImageBitmap ?? RNWebGPU.createImageBitmap.bind(RNWebGPU);