react-native-webgpu 0.21.4 → 0.23.0

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 (170) hide show
  1. package/README.md +15 -2
  2. package/android/CMakeLists.txt +10 -8
  3. package/android/build.gradle +111 -20
  4. package/android/cpp/AndroidAnimationFrameSource.h +136 -0
  5. package/android/cpp/AndroidPlatformContext.h +55 -0
  6. package/android/cpp/cpp-adapter.cpp +148 -2
  7. package/android/src/main/java/com/webgpu/WebGPUModule.java +21 -4
  8. package/android/src/main/java/com/webgpu/WebGPUNativeBufferView.java +370 -0
  9. package/android/src/main/java/com/webgpu/WebGPUNativeBufferViewManager.java +56 -0
  10. package/android/src/main/java/com/webgpu/WebGPUTextureView.java +21 -0
  11. package/android/src/main/java/com/webgpu/WebGPUVideoPlayer.java +1 -1
  12. package/android/src/main/java/com/webgpu/WebGPUView.java +19 -3
  13. package/android/src/main/java/com/webgpu/WebGPUViewManager.java +10 -0
  14. package/android/src/main/java/com/webgpu/WebGPUViewPackage.java +2 -2
  15. package/android/src/newarch/com/webgpu/WebGPUNativeBufferViewManagerSpec.java +24 -0
  16. package/apple/AppleAnimationFrameSource.mm +208 -0
  17. package/apple/ApplePlatformContext.h +6 -0
  18. package/apple/ApplePlatformContext.mm +73 -0
  19. package/apple/MetalLayerColorSpace.h +17 -0
  20. package/apple/MetalLayerColorSpace.mm +36 -57
  21. package/apple/MetalView.h +4 -0
  22. package/apple/MetalView.mm +14 -0
  23. package/apple/NativeBufferFenceWait.mm +88 -0
  24. package/apple/RNWGUIKit.h +4 -1
  25. package/apple/WebGPUModule.mm +26 -1
  26. package/apple/WebGPUNativeBufferView.h +15 -0
  27. package/apple/WebGPUNativeBufferView.mm +200 -0
  28. package/apple/WebGPUView.h +2 -1
  29. package/apple/WebGPUView.mm +6 -0
  30. package/binaries.json +156 -0
  31. package/cpp/jsi/NativeObject.h +12 -5
  32. package/cpp/rnwgpu/AnimationFrames.cpp +576 -0
  33. package/cpp/rnwgpu/AnimationFrames.h +233 -0
  34. package/cpp/rnwgpu/CanvasColorSpace.h +16 -0
  35. package/cpp/rnwgpu/NativeBufferViewRegistry.cpp +396 -0
  36. package/cpp/rnwgpu/NativeBufferViewRegistry.h +163 -0
  37. package/cpp/rnwgpu/PlatformContext.h +20 -0
  38. package/cpp/rnwgpu/RNWebGPUManager.cpp +17 -4
  39. package/cpp/rnwgpu/SurfaceRegistry.h +26 -30
  40. package/cpp/rnwgpu/api/GPUAdapter.cpp +1 -1
  41. package/cpp/rnwgpu/api/GPUCanvasContext.cpp +41 -3
  42. package/cpp/rnwgpu/api/GPUCanvasContext.h +7 -3
  43. package/cpp/rnwgpu/api/GPUDevice.cpp +16 -131
  44. package/cpp/rnwgpu/api/GPUDevice.h +0 -18
  45. package/cpp/rnwgpu/api/GPUExternalTexture.cpp +35 -3
  46. package/cpp/rnwgpu/api/GPUExternalTexture.h +4 -4
  47. package/cpp/rnwgpu/api/GPUQueue.cpp +1 -1
  48. package/cpp/rnwgpu/api/GPUQueue.h +1 -1
  49. package/cpp/rnwgpu/api/GPUSharedFence.h +1 -0
  50. package/cpp/rnwgpu/api/GPUSharedTextureMemory.cpp +11 -5
  51. package/cpp/rnwgpu/api/GPUSharedTextureMemory.h +21 -2
  52. package/cpp/rnwgpu/api/GPUTexture.h +18 -0
  53. package/cpp/rnwgpu/api/NativeFrameFeatures.h +1 -1
  54. package/cpp/rnwgpu/api/NativeFrameImport.cpp +20 -17
  55. package/cpp/rnwgpu/api/NativeFrameImport.h +31 -20
  56. package/cpp/rnwgpu/api/RNWebGPU.h +201 -3
  57. package/cpp/rnwgpu/api/VideoFrame.h +5 -4
  58. package/cpp/rnwgpu/api/VideoFrameBlit.h +2 -2
  59. package/cpp/rnwgpu/api/descriptors/GPUExternalTextureDescriptor.h +21 -14
  60. package/cpp/rnwgpu/api/descriptors/GPUImageCopyExternalImage.h +1 -1
  61. package/cpp/rnwgpu/api/descriptors/GPUSharedTextureMemoryDescriptor.h +17 -9
  62. package/cpp/rnwgpu/async/RuntimeContext.cpp +21 -4
  63. package/cpp/rnwgpu/async/RuntimeContext.h +8 -0
  64. package/lib/commonjs/Canvas.js +33 -1
  65. package/lib/commonjs/Canvas.js.map +1 -1
  66. package/lib/commonjs/NativeBufferView.js +131 -0
  67. package/lib/commonjs/NativeBufferView.js.map +1 -0
  68. package/lib/commonjs/NativeBufferViewNativeComponent.js +10 -0
  69. package/lib/commonjs/NativeBufferViewNativeComponent.js.map +1 -0
  70. package/lib/commonjs/WebGPUViewNativeComponent.js.map +1 -1
  71. package/lib/commonjs/WebGPUViewNativeComponent.web.js +2 -0
  72. package/lib/commonjs/WebGPUViewNativeComponent.web.js.map +1 -1
  73. package/lib/commonjs/animationFrame.js +91 -0
  74. package/lib/commonjs/animationFrame.js.map +1 -0
  75. package/lib/commonjs/index.js +16 -1
  76. package/lib/commonjs/index.js.map +1 -1
  77. package/lib/commonjs/main/index.js +12 -0
  78. package/lib/commonjs/main/index.js.map +1 -1
  79. package/lib/commonjs/mock.js +30 -1
  80. package/lib/commonjs/mock.js.map +1 -1
  81. package/lib/commonjs/video.js +14 -4
  82. package/lib/commonjs/video.js.map +1 -1
  83. package/lib/module/Canvas.js +33 -1
  84. package/lib/module/Canvas.js.map +1 -1
  85. package/lib/module/NativeBufferView.js +122 -0
  86. package/lib/module/NativeBufferView.js.map +1 -0
  87. package/lib/module/NativeBufferViewNativeComponent.js +4 -0
  88. package/lib/module/NativeBufferViewNativeComponent.js.map +1 -0
  89. package/lib/module/WebGPUViewNativeComponent.js.map +1 -1
  90. package/lib/module/WebGPUViewNativeComponent.web.js +2 -0
  91. package/lib/module/WebGPUViewNativeComponent.web.js.map +1 -1
  92. package/lib/module/animationFrame.js +83 -0
  93. package/lib/module/animationFrame.js.map +1 -0
  94. package/lib/module/index.js +1 -0
  95. package/lib/module/index.js.map +1 -1
  96. package/lib/module/main/index.js +1 -0
  97. package/lib/module/main/index.js.map +1 -1
  98. package/lib/module/mock.js +21 -0
  99. package/lib/module/mock.js.map +1 -1
  100. package/lib/module/video.js +11 -2
  101. package/lib/module/video.js.map +1 -1
  102. package/lib/typescript/lib/commonjs/Canvas.d.ts +3 -1
  103. package/lib/typescript/lib/commonjs/Canvas.d.ts.map +1 -1
  104. package/lib/typescript/lib/commonjs/NativeBufferView.d.ts +48 -0
  105. package/lib/typescript/lib/commonjs/NativeBufferView.d.ts.map +1 -0
  106. package/lib/typescript/lib/commonjs/NativeBufferViewNativeComponent.d.ts +5 -0
  107. package/lib/typescript/lib/commonjs/NativeBufferViewNativeComponent.d.ts.map +1 -0
  108. package/lib/typescript/lib/commonjs/WebGPUViewNativeComponent.web.d.ts.map +1 -1
  109. package/lib/typescript/lib/commonjs/animationFrame.d.ts +54 -0
  110. package/lib/typescript/lib/commonjs/animationFrame.d.ts.map +1 -0
  111. package/lib/typescript/lib/commonjs/index.d.ts +2 -0
  112. package/lib/typescript/lib/commonjs/mock.d.ts +12 -0
  113. package/lib/typescript/lib/commonjs/mock.d.ts.map +1 -1
  114. package/lib/typescript/lib/commonjs/video.d.ts +3 -2
  115. package/lib/typescript/lib/commonjs/video.d.ts.map +1 -1
  116. package/lib/typescript/lib/module/Canvas.d.ts +3 -1
  117. package/lib/typescript/lib/module/Canvas.d.ts.map +1 -1
  118. package/lib/typescript/lib/module/NativeBufferView.d.ts +14 -0
  119. package/lib/typescript/lib/module/NativeBufferView.d.ts.map +1 -0
  120. package/lib/typescript/lib/module/NativeBufferViewNativeComponent.d.ts +3 -0
  121. package/lib/typescript/lib/module/NativeBufferViewNativeComponent.d.ts.map +1 -0
  122. package/lib/typescript/lib/module/WebGPUViewNativeComponent.web.d.ts.map +1 -1
  123. package/lib/typescript/lib/module/animationFrame.d.ts +3 -0
  124. package/lib/typescript/lib/module/animationFrame.d.ts.map +1 -0
  125. package/lib/typescript/lib/module/index.d.ts +1 -0
  126. package/lib/typescript/lib/module/main/index.d.ts +1 -0
  127. package/lib/typescript/lib/module/mock.d.ts +14 -0
  128. package/lib/typescript/lib/module/mock.d.ts.map +1 -1
  129. package/lib/typescript/lib/module/video.d.ts +3 -2
  130. package/lib/typescript/lib/module/video.d.ts.map +1 -1
  131. package/lib/typescript/src/Canvas.d.ts +17 -1
  132. package/lib/typescript/src/Canvas.d.ts.map +1 -1
  133. package/lib/typescript/src/NativeBufferView.d.ts +99 -0
  134. package/lib/typescript/src/NativeBufferView.d.ts.map +1 -0
  135. package/lib/typescript/src/NativeBufferViewNativeComponent.d.ts +13 -0
  136. package/lib/typescript/src/NativeBufferViewNativeComponent.d.ts.map +1 -0
  137. package/lib/typescript/src/WebGPUViewNativeComponent.d.ts +2 -0
  138. package/lib/typescript/src/WebGPUViewNativeComponent.d.ts.map +1 -1
  139. package/lib/typescript/src/WebGPUViewNativeComponent.web.d.ts +2 -0
  140. package/lib/typescript/src/WebGPUViewNativeComponent.web.d.ts.map +1 -1
  141. package/lib/typescript/src/animationFrame.d.ts +59 -0
  142. package/lib/typescript/src/animationFrame.d.ts.map +1 -0
  143. package/lib/typescript/src/index.d.ts +18 -8
  144. package/lib/typescript/src/index.d.ts.map +1 -1
  145. package/lib/typescript/src/main/index.d.ts +1 -0
  146. package/lib/typescript/src/main/index.d.ts.map +1 -1
  147. package/lib/typescript/src/mock.d.ts +11 -0
  148. package/lib/typescript/src/mock.d.ts.map +1 -1
  149. package/lib/typescript/src/types.d.ts +32 -31
  150. package/lib/typescript/src/types.d.ts.map +1 -1
  151. package/lib/typescript/src/video.d.ts +12 -4
  152. package/lib/typescript/src/video.d.ts.map +1 -1
  153. package/package.json +8 -2
  154. package/react-native-webgpu.podspec +1 -1
  155. package/src/Canvas.tsx +67 -1
  156. package/src/NativeBufferView.tsx +199 -0
  157. package/src/NativeBufferViewNativeComponent.ts +20 -0
  158. package/src/WebGPUViewNativeComponent.ts +4 -0
  159. package/src/WebGPUViewNativeComponent.web.ts +6 -0
  160. package/src/animationFrame.ts +82 -0
  161. package/src/index.tsx +45 -39
  162. package/src/main/index.tsx +1 -0
  163. package/src/mock.ts +35 -0
  164. package/src/types.ts +61 -87
  165. package/src/video.ts +20 -7
  166. package/cpp/rnwgpu/api/GPUNativeBufferExternalTexture.h +0 -60
  167. package/cpp/rnwgpu/api/GPUNativeBufferTexture.h +0 -52
  168. package/cpp/rnwgpu/api/GPUNativeBufferWrapper.cpp +0 -144
  169. package/cpp/rnwgpu/api/GPUNativeBufferWrapper.h +0 -143
  170. package/cpp/rnwgpu/api/descriptors/GPUNativeBufferTextureDescriptor.h +0 -55
@@ -6,6 +6,10 @@
6
6
  #include <utility>
7
7
  #include <vector>
8
8
 
9
+ #if defined(__ANDROID__)
10
+ #include <unistd.h>
11
+ #endif
12
+
9
13
  #include "NativeObject.h"
10
14
 
11
15
  #include "ArrayBuffer.h"
@@ -13,8 +17,11 @@
13
17
  #include "GPU.h"
14
18
  #include "GPUCanvasContext.h"
15
19
  #include "GPUDevice.h"
20
+ #include "GPUSharedFenceState.h"
16
21
  #include "GPUTexture.h"
17
22
  #include "ImageBitmap.h"
23
+ #include "NativeBufferViewRegistry.h"
24
+ #include "NativeFrameImport.h"
18
25
  #include "PlatformContext.h"
19
26
  #include "VideoFrame.h"
20
27
  #include "VideoPlayer.h"
@@ -313,11 +320,192 @@ public:
313
320
  // Wrap a CVPixelBufferRef / AHardwareBuffer* pointer (typed as void* via
314
321
  // BigInt on the JS side) into one of our VideoFrames. The native side
315
322
  // CFRetains / acquires so the caller can release immediately.
316
- std::shared_ptr<VideoFrame> createVideoFrameFromNativeBuffer(void *pointer) {
323
+ std::shared_ptr<VideoFrame> createNativeBufferFromPointer(void *pointer) {
317
324
  auto handle = _platformContext->wrapNativeBuffer(pointer);
318
325
  return std::make_shared<VideoFrame>(std::move(handle));
319
326
  }
320
327
 
328
+ // createNativeBuffer(width, height, { format?, colorSpace? }): an empty
329
+ // native buffer (AHardwareBuffer / IOSurface) to render into through
330
+ // importSharedTextureMemory() and display with presentNativeBuffer().
331
+ // `format` defaults to the preferred canvas format of the platform
332
+ // (rgba8unorm on Android, bgra8unorm on Apple platforms); rgba16float works
333
+ // on both (more precision, not extended range: NativeBufferView clamps to
334
+ // [0, 1]). `colorSpace` is "srgb" (the default) or "display-p3".
335
+ jsi::Value createNativeBuffer(jsi::Runtime &runtime,
336
+ const jsi::Value & /*thisVal*/,
337
+ const jsi::Value *args, size_t count) {
338
+ auto dimension = [&](size_t index, const char *name) {
339
+ if (count <= index || !args[index].isNumber()) {
340
+ throw jsi::JSError(runtime, std::string("createNativeBuffer: ") + name +
341
+ " must be a number");
342
+ }
343
+ const double value = args[index].asNumber();
344
+ if (!(value >= 1 && value <= 16384) || value != std::floor(value)) {
345
+ throw jsi::JSError(runtime, std::string("createNativeBuffer: ") + name +
346
+ " must be an integer in [1, 16384]");
347
+ }
348
+ return static_cast<uint32_t>(value);
349
+ };
350
+ const uint32_t width = dimension(0, "width");
351
+ const uint32_t height = dimension(1, "height");
352
+ #if defined(__APPLE__)
353
+ wgpu::TextureFormat format = wgpu::TextureFormat::BGRA8Unorm;
354
+ #else
355
+ wgpu::TextureFormat format = wgpu::TextureFormat::RGBA8Unorm;
356
+ #endif
357
+ bool displayP3 = false;
358
+ if (count > 2 && args[2].isObject()) {
359
+ auto options = args[2].getObject(runtime);
360
+ auto formatValue = options.getProperty(runtime, "format");
361
+ if (formatValue.isString()) {
362
+ auto name = formatValue.getString(runtime).utf8(runtime);
363
+ if (name == "rgba8unorm") {
364
+ format = wgpu::TextureFormat::RGBA8Unorm;
365
+ } else if (name == "bgra8unorm") {
366
+ format = wgpu::TextureFormat::BGRA8Unorm;
367
+ } else if (name == "rgba16float") {
368
+ format = wgpu::TextureFormat::RGBA16Float;
369
+ } else {
370
+ throw jsi::JSError(
371
+ runtime, "createNativeBuffer: unsupported format '" + name + "'");
372
+ }
373
+ }
374
+ auto colorSpaceValue = options.getProperty(runtime, "colorSpace");
375
+ if (colorSpaceValue.isString()) {
376
+ auto name = colorSpaceValue.getString(runtime).utf8(runtime);
377
+ if (name == "display-p3") {
378
+ displayP3 = true;
379
+ } else if (name != "srgb") {
380
+ throw jsi::JSError(runtime,
381
+ "createNativeBuffer: unsupported colorSpace '" +
382
+ name + "'");
383
+ }
384
+ }
385
+ }
386
+ VideoFrameHandle handle;
387
+ try {
388
+ handle = _platformContext->createNativeBuffer(width, height, format,
389
+ displayP3);
390
+ } catch (const std::exception &e) {
391
+ throw jsi::JSError(runtime, e.what());
392
+ }
393
+ return VideoFrame::create(runtime,
394
+ std::make_shared<VideoFrame>(std::move(handle)));
395
+ }
396
+
397
+ // The id of a NativeBufferView about to mount, unique for the life of the
398
+ // process (see NativeBufferViewRegistry). Presents are accepted once the
399
+ // component retains it.
400
+ int allocateNativeBufferViewId() {
401
+ return NativeBufferViewRegistry::getInstance().allocateViewId();
402
+ }
403
+
404
+ // The NativeBufferView component mounted (again, when React StrictMode
405
+ // re-runs its effects).
406
+ void retainNativeBufferView(int viewId) {
407
+ NativeBufferViewRegistry::getInstance().retainFromJS(viewId);
408
+ }
409
+
410
+ // The NativeBufferView component unmounted.
411
+ void releaseNativeBufferView(int viewId) {
412
+ NativeBufferViewRegistry::getInstance().releaseFromJS(viewId);
413
+ }
414
+
415
+ // presentNativeBuffer(viewId, frame, fences?): makes `frame` the content of
416
+ // the NativeBufferView `viewId` once the GPU work that wrote it is done, or
417
+ // right away without fences. `fences` is what
418
+ // GPUSharedTextureMemory.endAccess() returns ({ fences }), a list of
419
+ // GPUSharedFenceState, or a single one; several are merged into one. On
420
+ // Android it also waits for the frame's own acquire fence, if it has one (a
421
+ // buffer the producer may still be writing). Returns immediately; the view
422
+ // shows the buffer on the next vsync after that. The view takes its own
423
+ // reference on the buffer, but that does not keep a buffer pool from reusing
424
+ // it: release the frame right away only if nothing else will write the buffer
425
+ // while it is displayed (see NativeBufferView.tsx).
426
+ jsi::Value presentNativeBuffer(jsi::Runtime &runtime,
427
+ const jsi::Value & /*thisVal*/,
428
+ const jsi::Value *args, size_t count) {
429
+ if (count < 2 || !args[0].isNumber() || !args[1].isObject()) {
430
+ throw jsi::JSError(runtime, "presentNativeBuffer(viewId, frame, fence?): "
431
+ "expected a view id and a NativeBuffer");
432
+ }
433
+ const int viewId = static_cast<int>(args[0].asNumber());
434
+ auto frame = JSIConverter<std::shared_ptr<VideoFrame>>::fromJSI(
435
+ runtime, args[1], false);
436
+ if (!frame) {
437
+ throw jsi::JSError(
438
+ runtime, "presentNativeBuffer(): frame is not a NativeBuffer");
439
+ }
440
+ wgpu::SharedFence fence;
441
+ uint64_t signaledValue = 0;
442
+ if (count > 2 && args[2].isObject()) {
443
+ // { fences } (an end-access state), an array, or one fence state.
444
+ auto arg = args[2].getObject(runtime);
445
+ jsi::Value list = jsi::Value::undefined();
446
+ if (arg.isArray(runtime)) {
447
+ list = jsi::Value(runtime, arg);
448
+ } else if (arg.hasProperty(runtime, "fences")) {
449
+ list = arg.getProperty(runtime, "fences");
450
+ }
451
+ std::vector<std::shared_ptr<GPUSharedFenceState>> states;
452
+ if (list.isObject()) {
453
+ states = JSIConverter<
454
+ std::vector<std::shared_ptr<GPUSharedFenceState>>>::fromJSI(runtime,
455
+ list,
456
+ false);
457
+ } else {
458
+ states.push_back(
459
+ JSIConverter<std::shared_ptr<GPUSharedFenceState>>::fromJSI(
460
+ runtime, args[2], false));
461
+ }
462
+ std::vector<wgpu::SharedFence> fences;
463
+ std::vector<uint64_t> values;
464
+ wgpu::Device device;
465
+ for (const auto &state : states) {
466
+ if (!state || !state->fence) {
467
+ continue;
468
+ }
469
+ auto native = state->fence->get();
470
+ if (!native) {
471
+ throw jsi::JSError(runtime,
472
+ "presentNativeBuffer(): a fence was destroyed");
473
+ }
474
+ device = state->fence->device();
475
+ fences.push_back(std::move(native));
476
+ values.push_back(state->signaledValue);
477
+ }
478
+ try {
479
+ native_frame::mergeFences(device, fences, values, &fence,
480
+ &signaledValue, "presentNativeBuffer");
481
+ } catch (const std::exception &e) {
482
+ throw jsi::JSError(runtime, e.what());
483
+ }
484
+ }
485
+ std::shared_ptr<NativeBufferContent> content;
486
+ try {
487
+ content = NativeBufferContent::fromFrame(frame->handle());
488
+ } catch (const std::exception &e) {
489
+ throw jsi::JSError(runtime, e.what());
490
+ }
491
+ int acquireFenceFd = -1;
492
+ #if defined(__ANDROID__)
493
+ // Duplicated: the frame closes its own fd when it is released, which may
494
+ // be before the wait is over.
495
+ if (frame->handle().acquireFenceFd >= 0) {
496
+ acquireFenceFd = ::dup(frame->handle().acquireFenceFd);
497
+ if (acquireFenceFd < 0) {
498
+ throw jsi::JSError(runtime, "presentNativeBuffer(): could not "
499
+ "duplicate the frame's acquire fence");
500
+ }
501
+ }
502
+ #endif
503
+ NativeBufferViewRegistry::getInstance().present(
504
+ viewId, std::move(content), std::move(fence), signaledValue,
505
+ acquireFenceFd);
506
+ return jsi::Value::undefined();
507
+ }
508
+
321
509
  std::shared_ptr<VideoPlayer>
322
510
  createVideoPlayer(std::string path, std::optional<std::string> pixelFormat) {
323
511
  auto format = (pixelFormat && pixelFormat.value() == "nv12")
@@ -388,13 +576,23 @@ public:
388
576
  &RNWebGPU::loadVideoFrame);
389
577
  installMethod(runtime, prototype, "createTestVideoFrame",
390
578
  &RNWebGPU::createTestVideoFrame);
391
- installMethod(runtime, prototype, "createVideoFrameFromNativeBuffer",
392
- &RNWebGPU::createVideoFrameFromNativeBuffer);
579
+ installMethod(runtime, prototype, "createNativeBufferFromPointer",
580
+ &RNWebGPU::createNativeBufferFromPointer);
393
581
  installMethodWithRuntime(runtime, prototype, "importDevice",
394
582
  &RNWebGPU::importDevice);
395
583
  installMethod(runtime, prototype, "adoptTexture", &RNWebGPU::adoptTexture);
396
584
  installMethod(runtime, prototype, "createVideoPlayer",
397
585
  &RNWebGPU::createVideoPlayer);
586
+ installMethod(runtime, prototype, "createNativeBuffer",
587
+ &RNWebGPU::createNativeBuffer);
588
+ installMethod(runtime, prototype, "allocateNativeBufferViewId",
589
+ &RNWebGPU::allocateNativeBufferViewId);
590
+ installMethod(runtime, prototype, "retainNativeBufferView",
591
+ &RNWebGPU::retainNativeBufferView);
592
+ installMethod(runtime, prototype, "releaseNativeBufferView",
593
+ &RNWebGPU::releaseNativeBufferView);
594
+ installMethod(runtime, prototype, "presentNativeBuffer",
595
+ &RNWebGPU::presentNativeBuffer);
398
596
  installMethod(runtime, prototype, "writeTestVideoFile",
399
597
  &RNWebGPU::writeTestVideoFile);
400
598
  }
@@ -24,10 +24,11 @@ public:
24
24
  // globalThis[CLASS_NAME], and the NativeObjectRegistry / worklet serializer
25
25
  // are keyed off it, so it must NOT be "VideoFrame": that would install our
26
26
  // constructor over the WebCodecs `VideoFrame` global and shadow it at
27
- // runtime. "NativeVideoFrame" matches the public TypeScript type (see
28
- // src/types.ts) and keeps the two namespaces distinct. The C++ class stays
29
- // `VideoFrame` for brevity; only the brand is namespaced.
30
- static constexpr const char *CLASS_NAME = "NativeVideoFrame";
27
+ // runtime. "NativeBuffer" matches the public TypeScript type (see
28
+ // src/types.ts) and keeps the two
29
+ // namespaces distinct. The C++ class stays `VideoFrame` for brevity; only
30
+ // the brand is namespaced.
31
+ static constexpr const char *CLASS_NAME = "NativeBuffer";
31
32
 
32
33
  explicit VideoFrame(VideoFrameHandle handle)
33
34
  : NativeObject(CLASS_NAME), _handle(std::move(handle)) {}
@@ -23,7 +23,7 @@ namespace rnwgpu {
23
23
  // imported as an external texture, so Dawn does the YUV to RGB conversion and
24
24
  // applies the rotation and the mirroring; a full-screen triangle then samples
25
25
  // it into the destination. This is what backs
26
- // GPUQueue.copyExternalImageToTexture for NativeVideoFrame sources, and the
26
+ // GPUQueue.copyExternalImageToTexture for NativeBuffer sources, and the
27
27
  // zero-copy path of GPUQueue.drawElementImageToTexture, which draws the
28
28
  // buffer the platform rendered a view into.
29
29
  //
@@ -64,7 +64,7 @@ public:
64
64
  const Request &request) {
65
65
  if (!request.frame || request.frame->handle().handle == nullptr) {
66
66
  throw std::runtime_error(
67
- "copyExternalImageToTexture: the NativeVideoFrame was released");
67
+ "copyExternalImageToTexture: the NativeBuffer was released");
68
68
  }
69
69
  if (!request.texture) {
70
70
  throw std::runtime_error(
@@ -9,6 +9,7 @@
9
9
 
10
10
  #include "GPUExtent2D.h"
11
11
  #include "GPUOrigin2D.h"
12
+ #include "GPUTexture.h"
12
13
  #include "JSIConverter.h"
13
14
  #include "VideoFrame.h"
14
15
 
@@ -16,12 +17,14 @@ namespace jsi = facebook::jsi;
16
17
 
17
18
  namespace rnwgpu {
18
19
 
19
- // Mirror of GPUExternalTextureDescriptor from the WebGPU spec, but with our
20
- // VideoFrame as the (only) supported source. `colorSpace` is the spec member:
21
- // the color space of the RGB the shader samples, "srgb" (the default) or
22
- // "display-p3"; the frame's own color space comes with the frame, and
23
- // `sourceColorSpace` overrides the members of it the caller knows better (a
24
- // buffer wrapped from another library carries none).
20
+ // Mirror of GPUExternalTextureDescriptor from the WebGPU spec, with a native
21
+ // buffer as the source: a NativeBuffer (`source`), imported for this external
22
+ // texture alone, or a texture created from a GPUSharedTextureMemory
23
+ // (`sourceTexture`), whose import and access windows the caller owns.
24
+ // `colorSpace` is the spec member: the color space of the RGB the shader
25
+ // samples, "srgb" (the default) or "display-p3"; the frame's own color space
26
+ // comes with the frame, and `sourceColorSpace` overrides the members of it the
27
+ // caller knows better (a buffer wrapped from another library carries none).
25
28
  //
26
29
  // `rotation` / `mirrored` are a non-spec extension: camera frames (e.g. from
27
30
  // VisionCamera) arrive in the sensor's native orientation, which differs
@@ -31,11 +34,9 @@ namespace rnwgpu {
31
34
  // passes. `rotation` is in degrees and must be one of 0 / 90 / 180 / 270.
32
35
  // `cropOrigin` / `cropSize` select the part of the frame the external texture
33
36
  // shows (Dawn's cropOrigin / cropSize), the whole frame by default.
34
- //
35
- // createNativeBufferExternalTexture() takes the same descriptor without a
36
- // source: the frame is its first argument.
37
37
  struct GPUExternalTextureDescriptor {
38
38
  std::shared_ptr<VideoFrame> source;
39
+ std::shared_ptr<GPUTexture> sourceTexture;
39
40
  std::optional<std::string> label;
40
41
  std::optional<std::string> colorSpace;
41
42
  std::optional<VideoFrameColorSpace> sourceColorSpace;
@@ -49,7 +50,7 @@ namespace external_texture_color_space {
49
50
 
50
51
  // The JS names of the members of a source color space, the Dawn enums
51
52
  // spelled the way the frame producers report them (see
52
- // NativeVideoFrameColorSpace in src/types.ts).
53
+ // NativeBufferColorSpace in src/types.ts).
53
54
  inline wgpu::ColorSpaceYCbCrMatrixDawn parseMatrix(const std::string &name) {
54
55
  if (name == "identity") {
55
56
  return wgpu::ColorSpaceYCbCrMatrixDawn::Identity;
@@ -174,10 +175,16 @@ struct JSIConverter<std::shared_ptr<rnwgpu::GPUExternalTextureDescriptor>> {
174
175
  auto value = arg.getObject(runtime);
175
176
  if (value.hasProperty(runtime, "source")) {
176
177
  auto prop = value.getProperty(runtime, "source");
177
- if (!prop.isUndefined() && !prop.isNull()) {
178
- result->source =
179
- JSIConverter<std::shared_ptr<rnwgpu::VideoFrame>>::fromJSI(
180
- runtime, prop, false);
178
+ if (prop.isObject()) {
179
+ auto brand = prop.getObject(runtime).getProperty(runtime, "__brand");
180
+ if (brand.isString() && brand.getString(runtime).utf8(runtime) ==
181
+ GPUTexture::CLASS_NAME) {
182
+ result->sourceTexture = GPUTexture::fromValue(runtime, prop);
183
+ } else {
184
+ result->source =
185
+ JSIConverter<std::shared_ptr<rnwgpu::VideoFrame>>::fromJSI(
186
+ runtime, prop, false);
187
+ }
181
188
  }
182
189
  }
183
190
  if (value.hasProperty(runtime, "label")) {
@@ -19,7 +19,7 @@ namespace jsi = facebook::jsi;
19
19
  namespace rnwgpu {
20
20
 
21
21
  // GPUCopyExternalImageSourceInfo. The source is either an ImageBitmap (the
22
- // spec's CPU upload) or, as a React Native extension, a NativeVideoFrame that
22
+ // spec's CPU upload) or, as a React Native extension, a NativeBuffer that
23
23
  // is rendered into the destination through an external texture (see
24
24
  // VideoFrameBlit). `rotation` and `mirrored` only apply to a native frame and
25
25
  // mirror the extension of GPUExternalTextureDescriptor.
@@ -7,21 +7,21 @@
7
7
  #include "webgpu/webgpu_cpp.h"
8
8
 
9
9
  #include "JSIConverter.h"
10
+ #include "VideoFrame.h"
10
11
 
11
12
  namespace jsi = facebook::jsi;
12
13
 
13
14
  namespace rnwgpu {
14
15
 
15
- // Descriptor for GPUDevice.importSharedTextureMemory.
16
- //
17
- // `handle` is the raw native handle as a uintptr_t (passed as BigInt from JS):
18
- // - Apple platforms: IOSurfaceRef
19
- // - Android: AHardwareBuffer*
20
- //
21
- // Lifetime: the caller is responsible for keeping the underlying object alive
22
- // for as long as this shared memory is in use. The VideoFrame helper handles
23
- // this automatically when the handle came from PlatformContext.loadVideoFrame.
16
+ // Descriptor for GPUDevice.importSharedTextureMemory: the buffer to import,
17
+ // either
18
+ // - `source`, a NativeBuffer: the memory keeps it alive, and the textures
19
+ // created from it carry its color space for importExternalTexture(), or
20
+ // - `handle`, the raw native handle as a BigInt (an IOSurfaceRef on Apple
21
+ // platforms, an AHardwareBuffer* on Android), which the caller keeps
22
+ // alive for as long as the memory is in use.
24
23
  struct GPUSharedTextureMemoryDescriptor {
24
+ std::shared_ptr<VideoFrame> source;
25
25
  void *handle = nullptr;
26
26
  std::optional<std::string> label;
27
27
  };
@@ -38,6 +38,14 @@ struct JSIConverter<std::shared_ptr<rnwgpu::GPUSharedTextureMemoryDescriptor>> {
38
38
  std::make_shared<rnwgpu::GPUSharedTextureMemoryDescriptor>();
39
39
  if (!outOfBounds && arg.isObject()) {
40
40
  auto value = arg.getObject(runtime);
41
+ if (value.hasProperty(runtime, "source")) {
42
+ auto prop = value.getProperty(runtime, "source");
43
+ if (!prop.isUndefined() && !prop.isNull()) {
44
+ result->source =
45
+ JSIConverter<std::shared_ptr<rnwgpu::VideoFrame>>::fromJSI(
46
+ runtime, prop, false);
47
+ }
48
+ }
41
49
  if (value.hasProperty(runtime, "handle")) {
42
50
  auto prop = value.getProperty(runtime, "handle");
43
51
  result->handle =
@@ -41,7 +41,7 @@ jsi::Runtime *mainRuntime() {
41
41
  return sMainRuntime;
42
42
  }
43
43
 
44
- std::shared_ptr<facebook::react::CallInvoker> mainInvoker() {
44
+ std::shared_ptr<facebook::react::CallInvoker> mainInvokerSlot() {
45
45
  std::lock_guard<std::mutex> lock(sMainMutex);
46
46
  return sMainInvoker;
47
47
  }
@@ -126,6 +126,23 @@ void RuntimeContext::registerMainRuntime(
126
126
  sMainInvoker = std::move(invoker);
127
127
  }
128
128
 
129
+ std::shared_ptr<facebook::react::CallInvoker> RuntimeContext::mainInvoker() {
130
+ return mainInvokerSlot();
131
+ }
132
+
133
+ RuntimeContext::RuntimeKind
134
+ RuntimeContext::runtimeKindOf(jsi::Runtime &runtime) {
135
+ switch (kindOf(runtime)) {
136
+ case Kind::Main:
137
+ return RuntimeKind::Main;
138
+ case Kind::UI:
139
+ return RuntimeKind::UI;
140
+ case Kind::Mailbox:
141
+ return RuntimeKind::Other;
142
+ }
143
+ return RuntimeKind::Other;
144
+ }
145
+
129
146
  RuntimeContext::Kind RuntimeContext::kindOf(jsi::Runtime &runtime) {
130
147
  auto main = mainRuntime();
131
148
  if (&runtime == main) {
@@ -176,7 +193,7 @@ RuntimeContext::getOrCreate(jsi::Runtime &runtime,
176
193
  bool RuntimeContext::canSettle() const {
177
194
  switch (_kind) {
178
195
  case Kind::Main:
179
- return mainInvoker() != nullptr;
196
+ return mainInvokerSlot() != nullptr;
180
197
  case Kind::UI:
181
198
  case Kind::Mailbox:
182
199
  return true;
@@ -233,7 +250,7 @@ void RuntimeContext::onTaskSettled() {
233
250
  void RuntimeContext::post(Job job) {
234
251
  switch (_kind) {
235
252
  case Kind::Main: {
236
- auto invoker = mainInvoker();
253
+ auto invoker = mainInvokerSlot();
237
254
  if (invoker == nullptr) {
238
255
  return;
239
256
  }
@@ -264,7 +281,7 @@ void RuntimeContext::post(Job job) {
264
281
  // the next post tries again. Whatever goes wrong on the way, the wake is
265
282
  // given up, never the jobs.
266
283
  void RuntimeContext::wakeUI() {
267
- auto invoker = mainInvoker();
284
+ auto invoker = mainInvokerSlot();
268
285
  if (invoker == nullptr) {
269
286
  return;
270
287
  }
@@ -99,6 +99,14 @@ public:
99
99
  registerMainRuntime(jsi::Runtime *runtime,
100
100
  std::shared_ptr<facebook::react::CallInvoker> invoker);
101
101
 
102
+ // What reaches a runtime from native code, for code other than promises
103
+ // (see AnimationFrames): the main runtime, through mainInvoker(); the
104
+ // Reanimated UI runtime; any other runtime, through its own timers.
105
+ enum class RuntimeKind { Main, UI, Other };
106
+ static RuntimeKind runtimeKindOf(jsi::Runtime &runtime);
107
+ // The main runtime's CallInvoker, null before it is registered.
108
+ static std::shared_ptr<facebook::react::CallInvoker> mainInvoker();
109
+
102
110
  // The wgpu::Instance served by this context on its owning runtime.
103
111
  const wgpu::Instance &instance() const { return _instance; }
104
112
 
@@ -117,6 +117,35 @@ const useBackingViewWarning = android => {
117
117
  });
118
118
  };
119
119
 
120
+ // The native props the `colorSpace` and `toneMapping` props resolve to. Like
121
+ // configure(), anything but "display-p3" and "extended" is the default.
122
+ const appleNativeProps = (colorSpace, toneMapping) => ({
123
+ appleDisplayP3: colorSpace === "display-p3",
124
+ appleExtendedDynamicRange: toneMapping?.mode === "extended"
125
+ });
126
+
127
+ // Warns, in development on Apple platforms, about a change of the colorspace
128
+ // props that the native view ignores: the layer is tagged with them when the
129
+ // canvas mounts (see WebGPUView.mm). A change of the toneMapping object
130
+ // itself (a new object every render) is not one.
131
+ const useAppleColorSpaceWarning = (colorSpace, toneMapping) => {
132
+ const prev = (0, _react.useRef)(appleNativeProps(colorSpace, toneMapping));
133
+ (0, _react.useEffect)(() => {
134
+ if (!__DEV__ || _reactNative.Platform.OS !== "ios" && _reactNative.Platform.OS !== "macos") {
135
+ return;
136
+ }
137
+ const next = appleNativeProps(colorSpace, toneMapping);
138
+ const warn = prop => console.warn(`Ignoring a change of ${prop} on a mounted canvas: the layer is ` + "tagged with it when the canvas mounts. Remount the canvas (give " + "it a new key) to change it.");
139
+ if (prev.current.appleDisplayP3 !== next.appleDisplayP3) {
140
+ warn("colorSpace");
141
+ }
142
+ if (prev.current.appleExtendedDynamicRange !== next.appleExtendedDynamicRange) {
143
+ warn("toneMapping");
144
+ }
145
+ prev.current = next;
146
+ });
147
+ };
148
+
120
149
  // A view measured relative to itself gets its layout size, without the
121
150
  // transforms getBoundingClientRect() includes; measureLayout() calls back
122
151
  // synchronously on the new architecture. On the web react-native-web measures
@@ -149,12 +178,15 @@ const measureLayout = view => {
149
178
  };
150
179
  const Canvas = ({
151
180
  android,
181
+ colorSpace,
182
+ toneMapping,
152
183
  ref,
153
184
  ...props
154
185
  }) => {
155
186
  const viewRef = (0, _react.useRef)(null);
156
187
  const [contextId, _] = (0, _react.useState)(() => generateContextId());
157
188
  useBackingViewWarning(android);
189
+ useAppleColorSpaceWarning(colorSpace, toneMapping);
158
190
  // Retire the native registry entry for this contextId on unmount. When a
159
191
  // native surface is still attached, this is a no-op and the native view's
160
192
  // own teardown retires the entry instead — which keeps StrictMode's
@@ -192,7 +224,7 @@ const Canvas = ({
192
224
  flex: 1
193
225
  },
194
226
  contextId: contextId
195
- }, androidNativeProps(android))));
227
+ }, androidNativeProps(android), appleNativeProps(colorSpace, toneMapping))));
196
228
  };
197
229
  exports.Canvas = Canvas;
198
230
  //# sourceMappingURL=Canvas.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["_react","_interopRequireWildcard","require","_reactNative","_WebGPUViewNativeComponent","_interopRequireDefault","e","__esModule","default","t","WeakMap","r","n","o","i","f","__proto__","has","get","set","hasOwnProperty","call","Object","defineProperty","getOwnPropertyDescriptor","_extends","assign","bind","arguments","length","apply","generateContextId","RNWebGPU","allocateContextId","options","android","resolveBackingView","backingView","resolveOpaque","opaque","androidNativeProps","zOrderOnTop","zOrderMediaOverlay","surfaceView","androidBackingView","androidOpaque","androidZOrderOnTop","androidZOrderMediaOverlay","warnIgnoredChange","prop","console","warn","useBackingViewWarning","mount","useRef","prev","useEffect","__DEV__","Platform","OS","current","Number","Version","before","zOrderAtMount","was","is","measureLayout","view","clientWidth","clientHeight","width","height","size","_left","_top","Canvas","ref","props","viewRef","contextId","_","useState","destroyContext","useImperativeHandle","getContextId","getNativeSurface","getContext","contextName","Error","MakeWebGPUCanvasContext","createElement","View","collapsable","style","flex","exports"],"sourceRoot":"../../src","sources":["Canvas.tsx"],"mappings":";;;;;;AAAA,IAAAA,MAAA,GAAAC,uBAAA,CAAAC,OAAA;AAEA,IAAAC,YAAA,GAAAD,OAAA;AAGA,IAAAE,0BAAA,GAAAC,sBAAA,CAAAH,OAAA;AAA2D,SAAAG,uBAAAC,CAAA,WAAAA,CAAA,IAAAA,CAAA,CAAAC,UAAA,GAAAD,CAAA,KAAAE,OAAA,EAAAF,CAAA;AAAA,SAAAL,wBAAAK,CAAA,EAAAG,CAAA,6BAAAC,OAAA,MAAAC,CAAA,OAAAD,OAAA,IAAAE,CAAA,OAAAF,OAAA,YAAAT,uBAAA,YAAAA,CAAAK,CAAA,EAAAG,CAAA,SAAAA,CAAA,IAAAH,CAAA,IAAAA,CAAA,CAAAC,UAAA,SAAAD,CAAA,MAAAO,CAAA,EAAAC,CAAA,EAAAC,CAAA,KAAAC,SAAA,QAAAR,OAAA,EAAAF,CAAA,iBAAAA,CAAA,uBAAAA,CAAA,yBAAAA,CAAA,SAAAS,CAAA,MAAAF,CAAA,GAAAJ,CAAA,GAAAG,CAAA,GAAAD,CAAA,QAAAE,CAAA,CAAAI,GAAA,CAAAX,CAAA,UAAAO,CAAA,CAAAK,GAAA,CAAAZ,CAAA,GAAAO,CAAA,CAAAM,GAAA,CAAAb,CAAA,EAAAS,CAAA,gBAAAN,CAAA,IAAAH,CAAA,gBAAAG,CAAA,OAAAW,cAAA,CAAAC,IAAA,CAAAf,CAAA,EAAAG,CAAA,OAAAK,CAAA,IAAAD,CAAA,GAAAS,MAAA,CAAAC,cAAA,KAAAD,MAAA,CAAAE,wBAAA,CAAAlB,CAAA,EAAAG,CAAA,OAAAK,CAAA,CAAAI,GAAA,IAAAJ,CAAA,CAAAK,GAAA,IAAAN,CAAA,CAAAE,CAAA,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AED,oBACEhF,MAAA,CAAAQ,OAAA,CAAAmF,aAAA,CAACxF,YAAA,CAAAyF,IAAI,EAAAnE,QAAA;IAACoE,WAAW,EAAE,KAAM;IAAChB,GAAG,EAAEE;EAAQ,GAAKD,KAAK,gBAC/C9E,MAAA,CAAAQ,OAAA,CAAAmF,aAAA,CAACvF,0BAAA,CAAAI,OAAgB,EAAAiB,QAAA;IACfqE,KAAK,EAAE;MAAEC,IAAI,EAAE;IAAE,CAAE;IACnBf,SAAS,EAAEA;EAAU,GACjBxC,kBAAkB,CAACL,OAAO,CAAC,CAChC,CACG,CAAC;AAEX,CAAC;AAAC6D,OAAA,CAAApB,MAAA,GAAAA,MAAA","ignoreList":[]}
1
+ {"version":3,"names":["_react","_interopRequireWildcard","require","_reactNative","_WebGPUViewNativeComponent","_interopRequireDefault","e","__esModule","default","t","WeakMap","r","n","o","i","f","__proto__","has","get","set","hasOwnProperty","call","Object","defineProperty","getOwnPropertyDescriptor","_extends","assign","bind","arguments","length","apply","generateContextId","RNWebGPU","allocateContextId","options","android","resolveBackingView","backingView","resolveOpaque","opaque","androidNativeProps","zOrderOnTop","zOrderMediaOverlay","surfaceView","androidBackingView","androidOpaque","androidZOrderOnTop","androidZOrderMediaOverlay","warnIgnoredChange","prop","console","warn","useBackingViewWarning","mount","useRef","prev","useEffect","__DEV__","Platform","OS","current","Number","Version","before","zOrderAtMount","was","is","appleNativeProps","colorSpace","toneMapping","appleDisplayP3","appleExtendedDynamicRange","mode","useAppleColorSpaceWarning","next","measureLayout","view","clientWidth","clientHeight","width","height","size","_left","_top","Canvas","ref","props","viewRef","contextId","_","useState","destroyContext","useImperativeHandle","getContextId","getNativeSurface","getContext","contextName","Error","MakeWebGPUCanvasContext","createElement","View","collapsable","style","flex","exports"],"sourceRoot":"../../src","sources":["Canvas.tsx"],"mappings":";;;;;;AAAA,IAAAA,MAAA,GAAAC,uBAAA,CAAAC,OAAA;AAEA,IAAAC,YAAA,GAAAD,OAAA;AAGA,IAAAE,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