react-native-wgpu 0.5.10 → 0.5.11

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.
@@ -93,10 +93,10 @@ public:
93
93
  return createImageBitmapFromData(data);
94
94
  }
95
95
 
96
- void createImageBitmapAsync(
97
- std::string blobId, double offset, double size,
98
- std::function<void(ImageData)> onSuccess,
99
- std::function<void(std::string)> onError) override {
96
+ void
97
+ createImageBitmapAsync(std::string blobId, double offset, double size,
98
+ std::function<void(ImageData)> onSuccess,
99
+ std::function<void(std::string)> onError) override {
100
100
  std::thread([this, blobId = std::move(blobId), offset, size,
101
101
  onSuccess = std::move(onSuccess),
102
102
  onError = std::move(onError)]() {
@@ -189,7 +189,8 @@ public:
189
189
  void createImageBitmapFromDataAsync(
190
190
  std::span<const uint8_t> data, std::function<void(ImageData)> onSuccess,
191
191
  std::function<void(std::string)> onError) override {
192
- std::thread([this, ownedData = std::vector<uint8_t>(data.begin(), data.end()),
192
+ std::thread([this,
193
+ ownedData = std::vector<uint8_t>(data.begin(), data.end()),
193
194
  onSuccess = std::move(onSuccess),
194
195
  onError = std::move(onError)]() mutable {
195
196
  jni::Environment::ensureCurrentThreadIsAttached();
@@ -16,10 +16,10 @@ public:
16
16
  ImageData createImageBitmap(std::string blobId, double offset,
17
17
  double size) override;
18
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;
19
+ void
20
+ createImageBitmapAsync(std::string blobId, double offset, double size,
21
+ std::function<void(ImageData)> onSuccess,
22
+ std::function<void(std::string)> onError) override;
23
23
 
24
24
  ImageData createImageBitmapFromData(std::span<const uint8_t> data) override;
25
25
 
@@ -82,17 +82,18 @@ void ApplePlatformContext::createImageBitmapAsync(
82
82
  std::move(onError));
83
83
  }
84
84
 
85
- ImageData ApplePlatformContext::createImageBitmapFromData(
86
- std::span<const uint8_t> data) {
85
+ ImageData
86
+ ApplePlatformContext::createImageBitmapFromData(std::span<const uint8_t> data) {
87
87
  // This avoids a copy by assuming the UIImage/NSImage constructors
88
88
  // decode `nsData` eagerly before the memory for the wrapped `data`
89
89
  // is freed.
90
90
  //
91
91
  // Since we get the `CGImageRef` from `image` and then throw
92
92
  // it away, that's a fairly safe assumption.
93
- NSData *nsData = [NSData dataWithBytesNoCopy:const_cast<uint8_t *>(data.data())
94
- length:data.size()
95
- freeWhenDone:NO];
93
+ NSData *nsData =
94
+ [NSData dataWithBytesNoCopy:const_cast<uint8_t *>(data.data())
95
+ length:data.size()
96
+ freeWhenDone:NO];
96
97
 
97
98
  #if !TARGET_OS_OSX
98
99
  UIImage *image = [UIImage imageWithData:nsData];
@@ -141,17 +142,16 @@ void ApplePlatformContext::createImageBitmapFromDataAsync(
141
142
  auto ownedData =
142
143
  std::make_shared<std::vector<uint8_t>>(data.begin(), data.end());
143
144
 
144
- dispatch_async(
145
- dispatch_get_global_queue(QOS_CLASS_USER_INITIATED, 0), ^{
146
- @autoreleasepool {
147
- try {
148
- auto result = createImageBitmapFromData(*ownedData);
149
- onSuccess(std::move(result));
150
- } catch (const std::exception &e) {
151
- onError(e.what());
152
- }
153
- }
154
- });
145
+ dispatch_async(dispatch_get_global_queue(QOS_CLASS_USER_INITIATED, 0), ^{
146
+ @autoreleasepool {
147
+ try {
148
+ auto result = createImageBitmapFromData(*ownedData);
149
+ onSuccess(std::move(result));
150
+ } catch (const std::exception &e) {
151
+ onError(e.what());
152
+ }
153
+ }
154
+ });
155
155
  }
156
156
 
157
157
  } // namespace rnwgpu
@@ -5,7 +5,8 @@
5
5
  #import <React/RCTCallInvokerModule.h>
6
6
  #import <React/RCTEventEmitter.h>
7
7
 
8
- @interface WebGPUModule : RCTEventEmitter <NativeWebGPUModuleSpec, RCTCallInvokerModule>
8
+ @interface WebGPUModule
9
+ : RCTEventEmitter <NativeWebGPUModuleSpec, RCTCallInvokerModule>
9
10
 
10
11
  + (std::shared_ptr<rnwgpu::RNWebGPUManager>)getManager;
11
12
 
@@ -55,11 +55,13 @@ RCT_EXPORT_BLOCKING_SYNCHRONOUS_METHOD(install) {
55
55
  return @true;
56
56
  }
57
57
 
58
- // self.bridge works in both Legacy (RCTBridge) and Bridgeless (RCTBridgeProxy).
58
+ // self.bridge works in both Legacy (RCTBridge) and Bridgeless
59
+ // (RCTBridgeProxy).
59
60
  jsi::Runtime *runtime = (jsi::Runtime *)self.bridge.runtime;
60
61
  if (!runtime) {
61
62
  NSLog(@"Failed to install react-native-wgpu: jsi::Runtime* was null! "
62
- @"(self.bridge=%@)", self.bridge);
63
+ @"(self.bridge=%@)",
64
+ self.bridge);
63
65
  return [NSNumber numberWithBool:NO];
64
66
  }
65
67
 
@@ -28,17 +28,19 @@ public:
28
28
  double size) = 0;
29
29
 
30
30
  // Async version that performs image decoding on a background thread
31
- virtual void createImageBitmapAsync(
32
- std::string blobId, double offset, double size,
33
- std::function<void(ImageData)> onSuccess,
34
- std::function<void(std::string)> onError) = 0;
31
+ virtual void
32
+ createImageBitmapAsync(std::string blobId, double offset, double size,
33
+ std::function<void(ImageData)> onSuccess,
34
+ std::function<void(std::string)> onError) = 0;
35
35
 
36
36
  // Create ImageBitmap from raw encoded image bytes (PNG/JPEG/etc.)
37
- virtual ImageData createImageBitmapFromData(std::span<const uint8_t> data) = 0;
37
+ virtual ImageData
38
+ createImageBitmapFromData(std::span<const uint8_t> data) = 0;
38
39
 
39
- virtual void createImageBitmapFromDataAsync(
40
- std::span<const uint8_t> data, std::function<void(ImageData)> onSuccess,
41
- std::function<void(std::string)> onError) = 0;
40
+ virtual void
41
+ createImageBitmapFromDataAsync(std::span<const uint8_t> data,
42
+ std::function<void(ImageData)> onSuccess,
43
+ std::function<void(std::string)> onError) = 0;
42
44
  };
43
45
 
44
46
  } // namespace rnwgpu
@@ -2,9 +2,9 @@
2
2
 
3
3
  #include <string>
4
4
 
5
- #include "webgpu/webgpu_cpp.h"
5
+ #include <cstdio>
6
6
 
7
- #include "WGPULogger.h"
7
+ #include "webgpu/webgpu_cpp.h"
8
8
 
9
9
  namespace rnwgpu {
10
10
 
@@ -89,9 +89,6 @@ static void convertEnumToJSUnion(wgpu::FeatureName inEnum,
89
89
  case wgpu::FeatureName::Unorm16TextureFormats:
90
90
  *outUnion = "unorm16-texture-formats";
91
91
  break;
92
- case wgpu::FeatureName::Snorm16TextureFormats:
93
- *outUnion = "snorm16-texture-formats";
94
- break;
95
92
  case wgpu::FeatureName::MultiPlanarFormatExtendedUsages:
96
93
  *outUnion = "multi-planar-format-extended-usages";
97
94
  break;
@@ -122,18 +119,12 @@ static void convertEnumToJSUnion(wgpu::FeatureName inEnum,
122
119
  case wgpu::FeatureName::AdapterPropertiesVk:
123
120
  *outUnion = "adapter-properties-vk";
124
121
  break;
125
- case wgpu::FeatureName::R8UnormStorage:
126
- *outUnion = "r8unorm-storage";
127
- break;
128
122
  case wgpu::FeatureName::DawnFormatCapabilities:
129
123
  *outUnion = "format-capabilities";
130
124
  break;
131
125
  case wgpu::FeatureName::DawnDrmFormatCapabilities:
132
126
  *outUnion = "drm-format-capabilities";
133
127
  break;
134
- case wgpu::FeatureName::Norm16TextureFormats:
135
- *outUnion = "norm16-texture-formats";
136
- break;
137
128
  case wgpu::FeatureName::MultiPlanarFormatNv16:
138
129
  *outUnion = "multi-planar-format-nv16";
139
130
  break;
@@ -204,7 +195,7 @@ static void convertEnumToJSUnion(wgpu::FeatureName inEnum,
204
195
  *outUnion = "dawn-load-resolve-texture";
205
196
  break;
206
197
  default:
207
- Logger::logToConsole("Unknown feature name %d", inEnum);
198
+ fprintf(stderr, "Unknown feature name %d\n", static_cast<int>(inEnum));
208
199
  *outUnion = "";
209
200
  }
210
201
  }
@@ -103,8 +103,7 @@ public:
103
103
  auto bufferVal = obj.getProperty(runtime, "buffer");
104
104
  if (bufferVal.isObject() &&
105
105
  bufferVal.getObject(runtime).isArrayBuffer(runtime)) {
106
- const auto &ab =
107
- bufferVal.getObject(runtime).getArrayBuffer(runtime);
106
+ const auto &ab = bufferVal.getObject(runtime).getArrayBuffer(runtime);
108
107
  auto byteOffset = static_cast<size_t>(
109
108
  obj.getProperty(runtime, "byteOffset").asNumber());
110
109
  auto byteLength = static_cast<size_t>(
@@ -120,15 +119,13 @@ public:
120
119
 
121
120
  return Promise::createPromise(
122
121
  runtime,
123
- [platformContext, callInvoker,
124
- dataCopy = std::move(dataCopy)](
122
+ [platformContext, callInvoker, dataCopy = std::move(dataCopy)](
125
123
  jsi::Runtime & /*runtime*/,
126
124
  std::shared_ptr<Promise> promise) mutable {
127
125
  platformContext->createImageBitmapFromDataAsync(
128
126
  dataCopy,
129
127
  [callInvoker, promise](ImageData imageData) {
130
- auto imageBitmap =
131
- std::make_shared<ImageBitmap>(imageData);
128
+ auto imageBitmap = std::make_shared<ImageBitmap>(imageData);
132
129
  callInvoker->invokeAsync([promise, imageBitmap]() {
133
130
  promise->resolve(
134
131
  JSIConverter<std::shared_ptr<ImageBitmap>>::toJSI(
@@ -158,12 +155,11 @@ public:
158
155
  blobId, offset, size,
159
156
  [callInvoker, promise](ImageData imageData) {
160
157
  auto imageBitmap = std::make_shared<ImageBitmap>(imageData);
161
- callInvoker->invokeAsync(
162
- [promise, imageBitmap]() {
163
- promise->resolve(
164
- JSIConverter<std::shared_ptr<ImageBitmap>>::toJSI(
165
- promise->runtime, imageBitmap));
166
- });
158
+ callInvoker->invokeAsync([promise, imageBitmap]() {
159
+ promise->resolve(
160
+ JSIConverter<std::shared_ptr<ImageBitmap>>::toJSI(
161
+ promise->runtime, imageBitmap));
162
+ });
167
163
  },
168
164
  [callInvoker, promise](std::string error) {
169
165
  callInvoker->invokeAsync(
@@ -463,8 +463,6 @@ inline void convertJSUnionToEnum(const std::string &inUnion,
463
463
  *outEnum = wgpu::FeatureName::PixelLocalStorageNonCoherent;
464
464
  } else if (inUnion == "unorm16-texture-formats") {
465
465
  *outEnum = wgpu::FeatureName::Unorm16TextureFormats;
466
- } else if (inUnion == "snorm16-texture-formats") {
467
- *outEnum = wgpu::FeatureName::Snorm16TextureFormats;
468
466
  } else if (inUnion == "multi-planar-format-extended-usages") {
469
467
  *outEnum = wgpu::FeatureName::MultiPlanarFormatExtendedUsages;
470
468
  } else if (inUnion == "multi-planar-format-p010") {
@@ -485,12 +483,8 @@ inline void convertJSUnionToEnum(const std::string &inUnion,
485
483
  *outEnum = wgpu::FeatureName::AdapterPropertiesD3D;
486
484
  } else if (inUnion == "adapter-properties-vk") {
487
485
  *outEnum = wgpu::FeatureName::AdapterPropertiesVk;
488
- } else if (inUnion == "r8unorm-storage") {
489
- *outEnum = wgpu::FeatureName::R8UnormStorage;
490
486
  } else if (inUnion == "format-capabilities") {
491
487
  *outEnum = wgpu::FeatureName::DawnFormatCapabilities;
492
- } else if (inUnion == "norm16-texture-formats") {
493
- *outEnum = wgpu::FeatureName::Norm16TextureFormats;
494
488
  } else if (inUnion == "multi-planar-format-nv16") {
495
489
  *outEnum = wgpu::FeatureName::MultiPlanarFormatNv16;
496
490
  } else if (inUnion == "multi-planar-format-nv24") {
@@ -629,9 +623,6 @@ inline void convertEnumToJSUnion(wgpu::FeatureName inEnum,
629
623
  case wgpu::FeatureName::Unorm16TextureFormats:
630
624
  *outUnion = "unorm16-texture-formats";
631
625
  break;
632
- case wgpu::FeatureName::Snorm16TextureFormats:
633
- *outUnion = "snorm16-texture-formats";
634
- break;
635
626
  case wgpu::FeatureName::MultiPlanarFormatExtendedUsages:
636
627
  *outUnion = "multi-planar-format-extended-usages";
637
628
  break;
@@ -662,12 +653,6 @@ inline void convertEnumToJSUnion(wgpu::FeatureName inEnum,
662
653
  case wgpu::FeatureName::AdapterPropertiesVk:
663
654
  *outUnion = "adapter-properties-vk";
664
655
  break;
665
- case wgpu::FeatureName::R8UnormStorage:
666
- *outUnion = "r8unorm-storage";
667
- break;
668
- case wgpu::FeatureName::Norm16TextureFormats:
669
- *outUnion = "norm16-texture-formats";
670
- break;
671
656
  case wgpu::FeatureName::MultiPlanarFormatNv16:
672
657
  *outUnion = "multi-planar-format-nv16";
673
658
  break;