react-native-webgpu 0.25.0 → 0.27.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 (84) hide show
  1. package/README.md +9 -1
  2. package/android/CMakeLists.txt +2 -0
  3. package/cpp/rnwgpu/ArrayBuffer.h +47 -2
  4. package/cpp/rnwgpu/DawnEventPump.cpp +227 -0
  5. package/cpp/rnwgpu/DawnEventPump.h +173 -0
  6. package/cpp/rnwgpu/WebGPURuntime.cpp +6 -8
  7. package/cpp/rnwgpu/api/GPU.cpp +1 -1
  8. package/cpp/rnwgpu/api/GPUAdapter.cpp +1 -1
  9. package/cpp/rnwgpu/api/GPUBuffer.cpp +100 -27
  10. package/cpp/rnwgpu/api/GPUBuffer.h +55 -6
  11. package/cpp/rnwgpu/api/GPUDevice.cpp +57 -55
  12. package/cpp/rnwgpu/api/GPUDevice.h +6 -0
  13. package/cpp/rnwgpu/api/GPUQueue.cpp +7 -2
  14. package/cpp/rnwgpu/api/GPUQueue.h +8 -2
  15. package/cpp/rnwgpu/api/GPUShaderModule.cpp +1 -1
  16. package/cpp/rnwgpu/api/RNWebGPU.h +26 -5
  17. package/cpp/rnwgpu/api/descriptors/CreateNativeBufferFromPointerOptions.h +46 -0
  18. package/cpp/rnwgpu/api/descriptors/GPUExternalTextureDescriptor.h +21 -15
  19. package/cpp/rnwgpu/async/AsyncTaskHandle.h +3 -2
  20. package/cpp/rnwgpu/async/DeviceTicker.cpp +105 -0
  21. package/cpp/rnwgpu/async/DeviceTicker.h +71 -0
  22. package/cpp/rnwgpu/async/RuntimeContext.cpp +56 -70
  23. package/cpp/rnwgpu/async/RuntimeContext.h +37 -18
  24. package/lib/commonjs/NativeBufferView.js.map +1 -1
  25. package/lib/commonjs/NativeBufferViewNativeComponent.web.js +114 -0
  26. package/lib/commonjs/NativeBufferViewNativeComponent.web.js.map +1 -0
  27. package/lib/commonjs/WebPolyfillGPUModule.js +79 -0
  28. package/lib/commonjs/WebPolyfillGPUModule.js.map +1 -1
  29. package/lib/commonjs/index.js.map +1 -1
  30. package/lib/commonjs/main/index.web.js +11 -0
  31. package/lib/commonjs/main/index.web.js.map +1 -1
  32. package/lib/commonjs/utils.js +29 -0
  33. package/lib/commonjs/utils.js.map +1 -1
  34. package/lib/commonjs/video.js +1 -1
  35. package/lib/commonjs/video.js.map +1 -1
  36. package/lib/module/NativeBufferView.js.map +1 -1
  37. package/lib/module/NativeBufferViewNativeComponent.web.js +107 -0
  38. package/lib/module/NativeBufferViewNativeComponent.web.js.map +1 -0
  39. package/lib/module/WebPolyfillGPUModule.js +80 -1
  40. package/lib/module/WebPolyfillGPUModule.js.map +1 -1
  41. package/lib/module/index.js.map +1 -1
  42. package/lib/module/main/index.web.js +1 -0
  43. package/lib/module/main/index.web.js.map +1 -1
  44. package/lib/module/utils.js +27 -0
  45. package/lib/module/utils.js.map +1 -1
  46. package/lib/module/video.js +1 -1
  47. package/lib/module/video.js.map +1 -1
  48. package/lib/typescript/lib/commonjs/NativeBufferViewNativeComponent.web.d.ts +4 -0
  49. package/lib/typescript/lib/commonjs/NativeBufferViewNativeComponent.web.d.ts.map +1 -0
  50. package/lib/typescript/lib/commonjs/utils.d.ts +2 -0
  51. package/lib/typescript/lib/commonjs/utils.d.ts.map +1 -1
  52. package/lib/typescript/lib/commonjs/video.d.ts +1 -1
  53. package/lib/typescript/lib/commonjs/video.d.ts.map +1 -1
  54. package/lib/typescript/lib/module/NativeBufferViewNativeComponent.web.d.ts +5 -0
  55. package/lib/typescript/lib/module/NativeBufferViewNativeComponent.web.d.ts.map +1 -0
  56. package/lib/typescript/lib/module/main/index.web.d.ts +1 -0
  57. package/lib/typescript/lib/module/utils.d.ts +2 -0
  58. package/lib/typescript/lib/module/utils.d.ts.map +1 -1
  59. package/lib/typescript/lib/module/video.d.ts +1 -1
  60. package/lib/typescript/lib/module/video.d.ts.map +1 -1
  61. package/lib/typescript/src/NativeBufferView.d.ts +6 -1
  62. package/lib/typescript/src/NativeBufferView.d.ts.map +1 -1
  63. package/lib/typescript/src/NativeBufferViewNativeComponent.web.d.ts +14 -0
  64. package/lib/typescript/src/NativeBufferViewNativeComponent.web.d.ts.map +1 -0
  65. package/lib/typescript/src/index.d.ts +3 -3
  66. package/lib/typescript/src/index.d.ts.map +1 -1
  67. package/lib/typescript/src/main/index.web.d.ts +1 -0
  68. package/lib/typescript/src/main/index.web.d.ts.map +1 -1
  69. package/lib/typescript/src/types.d.ts +12 -0
  70. package/lib/typescript/src/types.d.ts.map +1 -1
  71. package/lib/typescript/src/utils.d.ts +2 -0
  72. package/lib/typescript/src/utils.d.ts.map +1 -1
  73. package/lib/typescript/src/video.d.ts +2 -2
  74. package/lib/typescript/src/video.d.ts.map +1 -1
  75. package/package.json +1 -1
  76. package/scripts/prepare-apple-binaries.sh +9 -3
  77. package/src/NativeBufferView.tsx +6 -1
  78. package/src/NativeBufferViewNativeComponent.web.ts +119 -0
  79. package/src/WebPolyfillGPUModule.ts +75 -1
  80. package/src/index.tsx +7 -2
  81. package/src/main/index.web.tsx +1 -0
  82. package/src/types.ts +13 -0
  83. package/src/utils.ts +25 -0
  84. package/src/video.ts +6 -1
@@ -1,6 +1,7 @@
1
1
  import "./installNative";
2
2
 
3
3
  export * from "../Canvas";
4
+ export * from "../NativeBufferView";
4
5
  export * from "../Offscreen";
5
6
  export * from "../WebGPUViewNativeComponent";
6
7
  export * from "../hooks";
package/src/types.ts CHANGED
@@ -328,6 +328,19 @@ export interface GPUSharedTextureMemory {
328
328
  destroy(): void;
329
329
  }
330
330
 
331
+ /**
332
+ * The options of `createNativeBufferFromPointer()`.
333
+ */
334
+ export interface CreateNativeBufferFromPointerOptions {
335
+ /**
336
+ * How to read a YUV buffer that carries no color information of its own
337
+ * (an AHardwareBuffer from a MediaCodec ImageReader, for instance), as
338
+ * `sourceColorSpace` in `importExternalTexture()`. The members it sets
339
+ * replace what the buffer says.
340
+ */
341
+ colorSpace?: NativeBufferColorSpace;
342
+ }
343
+
331
344
  /**
332
345
  * The options of `createNativeBuffer()`. The buffer holds premultiplied
333
346
  * pixels.
package/src/utils.ts CHANGED
@@ -2,3 +2,28 @@
2
2
  export function contextIdToId(contextId: number) {
3
3
  return "rnwgpu-canvas-" + contextId;
4
4
  }
5
+
6
+ // Only used on the web
7
+ export function nativeBufferViewIdToId(viewId: number) {
8
+ return "rnwgpu-native-buffer-view-" + viewId;
9
+ }
10
+
11
+ // Only used on the web: fits the canvas of a NativeBufferView in its
12
+ // container according to its resize mode (data-resize-mode). The drawing
13
+ // buffer of the canvas is the presented buffer, in physical pixels.
14
+ export function layoutNativeBufferViewCanvas(canvas: HTMLCanvasElement) {
15
+ const mode = canvas.dataset.resizeMode;
16
+ const { style } = canvas;
17
+ if (mode === "topLeft") {
18
+ // Not scaled: one pixel of the buffer on one pixel of the display. The
19
+ // container crops what overflows.
20
+ const dpr = window.devicePixelRatio || 1;
21
+ style.width = `${canvas.width / dpr}px`;
22
+ style.height = `${canvas.height / dpr}px`;
23
+ style.objectFit = "fill";
24
+ return;
25
+ }
26
+ style.width = "100%";
27
+ style.height = "100%";
28
+ style.objectFit = mode === "contain" || mode === "cover" ? mode : "fill";
29
+ }
package/src/video.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  import type {
2
+ CreateNativeBufferFromPointerOptions,
2
3
  CreateNativeBufferOptions,
3
4
  CreateTestVideoPlayerOptions,
4
5
  NativeBuffer,
@@ -58,9 +59,13 @@ export const createTestVideoPlayer = (
58
59
  * VisionCamera's `frame.getNativeBuffer().pointer`) into a `NativeBuffer`
59
60
  * that keeps it alive until released.
60
61
  */
61
- export const createNativeBufferFromPointer = (pointer: bigint): NativeBuffer =>
62
+ export const createNativeBufferFromPointer = (
63
+ pointer: bigint,
64
+ options?: CreateNativeBufferFromPointerOptions,
65
+ ): NativeBuffer =>
62
66
  native("createNativeBufferFromPointer").createNativeBufferFromPointer(
63
67
  pointer,
68
+ options,
64
69
  );
65
70
 
66
71
  /**