react-native-webgpu 0.7.0 → 0.8.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.
@@ -42,6 +42,12 @@ public:
42
42
  wgpu::TextureFormat getFormat();
43
43
  double getUsage();
44
44
 
45
+ // Non-spec RN extension: the raw WGPUTexture handle as a BigInt, for
46
+ // pointer-based interop (e.g. Skia's Image.MakeImageFromNativeTexture).
47
+ // Borrowed: this GPUTexture keeps ownership; the consumer must retain the
48
+ // JS object (or AddRef natively) for as long as it uses the pointer.
49
+ void *getNativePointer() { return _instance.Get(); }
50
+
45
51
  std::string getLabel() { return _label; }
46
52
  void setLabel(const std::string &label) {
47
53
  _label = label;
@@ -50,6 +56,8 @@ public:
50
56
 
51
57
  static void definePrototype(jsi::Runtime &runtime, jsi::Object &prototype) {
52
58
  installGetter(runtime, prototype, "__brand", &GPUTexture::getBrand);
59
+ installGetter(runtime, prototype, "nativePointer",
60
+ &GPUTexture::getNativePointer);
53
61
  installMethod(runtime, prototype, "createView", &GPUTexture::createView);
54
62
  installMethod(runtime, prototype, "destroy", &GPUTexture::destroy);
55
63
  installGetter(runtime, prototype, "width", &GPUTexture::getWidth);
@@ -10,6 +10,7 @@
10
10
  #include "GPU.h"
11
11
  #include "GPUCanvasContext.h"
12
12
  #include "GPUDevice.h"
13
+ #include "GPUTexture.h"
13
14
  #include "rnwgpu/async/RuntimeContext.h"
14
15
  #include "ImageBitmap.h"
15
16
  #include "PlatformContext.h"
@@ -100,6 +101,20 @@ public:
100
101
  return std::make_shared<GPUDevice>(device, ctx, "Imported Device");
101
102
  }
102
103
 
104
+ // Wrap an externally created WGPUTexture in a GPUTexture, TAKING OWNERSHIP
105
+ // of one reference (unlike importDevice, which borrows): the returned
106
+ // GPUTexture releases it when destroyed. Pair with producers that return a
107
+ // +1 pointer, e.g. Skia.Image.MakeNativeTextureFromImage().
108
+ std::shared_ptr<GPUTexture> adoptTexture(void *pointer) {
109
+ if (pointer == nullptr) {
110
+ throw std::runtime_error(
111
+ "adoptTexture: expected a non-null WGPUTexture pointer (BigInt)");
112
+ }
113
+ wgpu::Texture texture =
114
+ wgpu::Texture::Acquire(reinterpret_cast<WGPUTexture>(pointer));
115
+ return std::make_shared<GPUTexture>(texture, "Adopted Texture");
116
+ }
117
+
103
118
  jsi::Value createImageBitmap(jsi::Runtime &runtime,
104
119
  const jsi::Value & /*thisVal*/,
105
120
  const jsi::Value *args, size_t count) {
@@ -309,6 +324,7 @@ public:
309
324
  &RNWebGPU::createVideoFrameFromNativeBuffer);
310
325
  installMethodWithRuntime(runtime, prototype, "importDevice",
311
326
  &RNWebGPU::importDevice);
327
+ installMethod(runtime, prototype, "adoptTexture", &RNWebGPU::adoptTexture);
312
328
  installMethod(runtime, prototype, "createVideoPlayer",
313
329
  &RNWebGPU::createVideoPlayer);
314
330
  installMethod(runtime, prototype, "writeTestVideoFile",
package/jestSetup.js ADDED
@@ -0,0 +1,11 @@
1
+ /* globals jest */
2
+
3
+ // `react-native-webgpu` wraps a native TurboModule (`NativeWebGPUModule.ts`
4
+ // calls `TurboModuleRegistry.getEnforcing("WebGPUModule")` at import time),
5
+ // which throws under Jest since there is no native binary to register
6
+ // against. Swap the whole package for a JS-only stand-in (see `src/mock.ts`)
7
+ // so screens built around `<Canvas>` / `importDevice` / etc. can still be
8
+ // imported and rendered in tests.
9
+ jest.mock("react-native-webgpu", () =>
10
+ require("react-native-webgpu/lib/module/mock"),
11
+ );
@@ -3,7 +3,7 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.importDevice = void 0;
6
+ exports.importDevice = exports.adoptTexture = void 0;
7
7
  /**
8
8
  * Wraps an externally created WGPUDevice pointer into a GPUDevice.
9
9
  *
@@ -24,5 +24,24 @@ const importDevice = pointer => {
24
24
  }
25
25
  return RNWebGPU.importDevice(pointer);
26
26
  };
27
+
28
+ /**
29
+ * Wraps an externally created WGPUTexture pointer into a GPUTexture, taking
30
+ * ownership of one reference: the returned texture releases it when destroyed.
31
+ *
32
+ * Pair with producers that hand out a +1 reference, such as
33
+ * `Skia.Image.MakeNativeTextureFromImage()`:
34
+ *
35
+ * ```ts
36
+ * const texture = adoptTexture(Skia.Image.MakeNativeTextureFromImage(image));
37
+ * ```
38
+ */
27
39
  exports.importDevice = importDevice;
40
+ const adoptTexture = pointer => {
41
+ if (typeof RNWebGPU === "undefined") {
42
+ throw new Error("react-native-webgpu is not installed natively; adoptTexture is unavailable");
43
+ }
44
+ return RNWebGPU.adoptTexture(pointer);
45
+ };
46
+ exports.adoptTexture = adoptTexture;
28
47
  //# sourceMappingURL=importDevice.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["importDevice","pointer","RNWebGPU","Error","exports"],"sourceRoot":"../../src","sources":["importDevice.ts"],"mappings":";;;;;;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,MAAMA,YAAY,GAAIC,OAAe,IAAgB;EAC1D,IAAI,OAAOC,QAAQ,KAAK,WAAW,EAAE;IACnC,MAAM,IAAIC,KAAK,CACb,4EACF,CAAC;EACH;EACA,OAAOD,QAAQ,CAACF,YAAY,CAACC,OAAO,CAAC;AACvC,CAAC;AAACG,OAAA,CAAAJ,YAAA,GAAAA,YAAA","ignoreList":[]}
1
+ {"version":3,"names":["importDevice","pointer","RNWebGPU","Error","exports","adoptTexture"],"sourceRoot":"../../src","sources":["importDevice.ts"],"mappings":";;;;;;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,MAAMA,YAAY,GAAIC,OAAe,IAAgB;EAC1D,IAAI,OAAOC,QAAQ,KAAK,WAAW,EAAE;IACnC,MAAM,IAAIC,KAAK,CACb,4EACF,CAAC;EACH;EACA,OAAOD,QAAQ,CAACF,YAAY,CAACC,OAAO,CAAC;AACvC,CAAC;;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAVAG,OAAA,CAAAJ,YAAA,GAAAA,YAAA;AAWO,MAAMK,YAAY,GAAIJ,OAAe,IAAiB;EAC3D,IAAI,OAAOC,QAAQ,KAAK,WAAW,EAAE;IACnC,MAAM,IAAIC,KAAK,CACb,4EACF,CAAC;EACH;EACA,OAAOD,QAAQ,CAACG,YAAY,CAACJ,OAAO,CAAC;AACvC,CAAC;AAACG,OAAA,CAAAC,YAAA,GAAAA,YAAA","ignoreList":[]}
@@ -0,0 +1,123 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ var _exportNames = {
7
+ Canvas: true,
8
+ useCanvasRef: true,
9
+ useSurface: true,
10
+ warnIfNotHardwareAccelerated: true,
11
+ useDevice: true,
12
+ GPUDeviceProvider: true,
13
+ useMainDevice: true,
14
+ importDevice: true,
15
+ adoptTexture: true,
16
+ installWebGPU: true,
17
+ WebGPUModule: true
18
+ };
19
+ exports.warnIfNotHardwareAccelerated = exports.useSurface = exports.useMainDevice = exports.useDevice = exports.useCanvasRef = exports.installWebGPU = exports.importDevice = exports.adoptTexture = exports.WebGPUModule = exports.GPUDeviceProvider = exports.Canvas = void 0;
20
+ var _react = _interopRequireDefault(require("react"));
21
+ var _reactNative = require("react-native");
22
+ var _constants = require("./constants");
23
+ Object.keys(_constants).forEach(function (key) {
24
+ if (key === "default" || key === "__esModule") return;
25
+ if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
26
+ if (key in exports && exports[key] === _constants[key]) return;
27
+ Object.defineProperty(exports, key, {
28
+ enumerable: true,
29
+ get: function () {
30
+ return _constants[key];
31
+ }
32
+ });
33
+ });
34
+ var _install = require("./install");
35
+ Object.keys(_install).forEach(function (key) {
36
+ if (key === "default" || key === "__esModule") return;
37
+ if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
38
+ if (key in exports && exports[key] === _install[key]) return;
39
+ Object.defineProperty(exports, key, {
40
+ enumerable: true,
41
+ get: function () {
42
+ return _install[key];
43
+ }
44
+ });
45
+ });
46
+ var _formats = require("./formats");
47
+ Object.keys(_formats).forEach(function (key) {
48
+ if (key === "default" || key === "__esModule") return;
49
+ if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
50
+ if (key in exports && exports[key] === _formats[key]) return;
51
+ Object.defineProperty(exports, key, {
52
+ enumerable: true,
53
+ get: function () {
54
+ return _formats[key];
55
+ }
56
+ });
57
+ });
58
+ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
59
+ /// <reference types="@webgpu/types" />
60
+
61
+ // Jest mock for `react-native-webgpu`.
62
+ //
63
+ // There is no native WebGPU implementation under Jest, so this never talks to
64
+ // `NativeWebGPUModule` or the native `RNWebGPU` global. `Canvas` renders as a
65
+ // plain `View` so screens built around it can still be rendered in tests;
66
+ // anything that requires an actual GPU (`importDevice`, `adoptTexture`,
67
+ // `useDevice`, a real canvas context) fails loudly instead of silently
68
+ // returning fake data, mirroring how the real module already reports a
69
+ // missing native install (see `importDevice`/`adoptTexture` in
70
+ // `./importDevice.ts`).
71
+
72
+ const NOT_AVAILABLE_UNDER_JEST = "is not available under Jest - react-native-webgpu has no native implementation in tests (see react-native-webgpu/jestSetup.js)";
73
+ const Canvas = ({
74
+ transparent: _transparent,
75
+ ref,
76
+ ...props
77
+ }) => {
78
+ _react.default.useImperativeHandle(ref, () => ({
79
+ getContextId: () => -1,
80
+ getContext: _contextName => null,
81
+ getNativeSurface: () => {
82
+ throw new Error(`Canvas.getNativeSurface() ${NOT_AVAILABLE_UNDER_JEST}`);
83
+ }
84
+ }));
85
+ return /*#__PURE__*/_react.default.createElement(_reactNative.View, props);
86
+ };
87
+ exports.Canvas = Canvas;
88
+ const useCanvasRef = () => _react.default.useRef(null);
89
+ exports.useCanvasRef = useCanvasRef;
90
+ const useSurface = () => ({
91
+ ref: _react.default.useRef(null),
92
+ surface: null
93
+ });
94
+ exports.useSurface = useSurface;
95
+ const warnIfNotHardwareAccelerated = () => undefined;
96
+ exports.warnIfNotHardwareAccelerated = warnIfNotHardwareAccelerated;
97
+ const useDevice = () => ({
98
+ adapter: null,
99
+ device: null
100
+ });
101
+ exports.useDevice = useDevice;
102
+ const GPUDeviceProvider = ({
103
+ children
104
+ }) => children ?? null;
105
+ exports.GPUDeviceProvider = GPUDeviceProvider;
106
+ const useMainDevice = () => {
107
+ throw new Error(`useMainDevice() ${NOT_AVAILABLE_UNDER_JEST}`);
108
+ };
109
+ exports.useMainDevice = useMainDevice;
110
+ const importDevice = _pointer => {
111
+ throw new Error(`importDevice() ${NOT_AVAILABLE_UNDER_JEST}`);
112
+ };
113
+ exports.importDevice = importDevice;
114
+ const adoptTexture = _pointer => {
115
+ throw new Error(`adoptTexture() ${NOT_AVAILABLE_UNDER_JEST}`);
116
+ };
117
+ exports.adoptTexture = adoptTexture;
118
+ const installWebGPU = () => undefined;
119
+ exports.installWebGPU = installWebGPU;
120
+ const WebGPUModule = exports.WebGPUModule = {
121
+ install: () => false
122
+ };
123
+ //# sourceMappingURL=mock.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["_react","_interopRequireDefault","require","_reactNative","_constants","Object","keys","forEach","key","prototype","hasOwnProperty","call","_exportNames","exports","defineProperty","enumerable","get","_install","_formats","e","__esModule","default","NOT_AVAILABLE_UNDER_JEST","Canvas","transparent","_transparent","ref","props","React","useImperativeHandle","getContextId","getContext","_contextName","getNativeSurface","Error","createElement","View","useCanvasRef","useRef","useSurface","surface","warnIfNotHardwareAccelerated","undefined","useDevice","adapter","device","GPUDeviceProvider","children","useMainDevice","importDevice","_pointer","adoptTexture","installWebGPU","WebGPUModule","install"],"sourceRoot":"../../src","sources":["mock.ts"],"mappings":";;;;;;;;;;;;;;;;;;;AACA,IAAAA,MAAA,GAAAC,sBAAA,CAAAC,OAAA;AAEA,IAAAC,YAAA,GAAAD,OAAA;AAgBA,IAAAE,UAAA,GAAAF,OAAA;AAAAG,MAAA,CAAAC,IAAA,CAAAF,UAAA,EAAAG,OAAA,WAAAC,GA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1D,MAAMG,iBAAiB,GAAGA,CAAC;EAAEC;AAAmC,CAAC,KACtEA,QAAQ,IAAI,IAAI;AAAClC,OAAA,CAAAiC,iBAAA,GAAAA,iBAAA;AAEZ,MAAME,aAAa,GAAGA,CAAA,KAAa;EACxC,MAAM,IAAId,KAAK,CAAC,mBAAmBZ,wBAAwB,EAAE,CAAC;AAChE,CAAC;AAACT,OAAA,CAAAmC,aAAA,GAAAA,aAAA;AAEK,MAAMC,YAAY,GAAIC,QAAgB,IAAgB;EAC3D,MAAM,IAAIhB,KAAK,CAAC,kBAAkBZ,wBAAwB,EAAE,CAAC;AAC/D,CAAC;AAACT,OAAA,CAAAoC,YAAA,GAAAA,YAAA;AAEK,MAAME,YAAY,GAAID,QAAgB,IAAiB;EAC5D,MAAM,IAAIhB,KAAK,CAAC,kBAAkBZ,wBAAwB,EAAE,CAAC;AAC/D,CAAC;AAACT,OAAA,CAAAsC,YAAA,GAAAA,YAAA;AAEK,MAAMC,aAAa,GAAGA,CAAA,KAAMV,SAAS;AAAC7B,OAAA,CAAAuC,aAAA,GAAAA,aAAA;AAEtC,MAAMC,YAAY,GAAAxC,OAAA,CAAAwC,YAAA,GAAG;EAAEC,OAAO,EAAEA,CAAA,KAAM;AAAM,CAAC","ignoreList":[]}
@@ -18,4 +18,22 @@ export const importDevice = pointer => {
18
18
  }
19
19
  return RNWebGPU.importDevice(pointer);
20
20
  };
21
+
22
+ /**
23
+ * Wraps an externally created WGPUTexture pointer into a GPUTexture, taking
24
+ * ownership of one reference: the returned texture releases it when destroyed.
25
+ *
26
+ * Pair with producers that hand out a +1 reference, such as
27
+ * `Skia.Image.MakeNativeTextureFromImage()`:
28
+ *
29
+ * ```ts
30
+ * const texture = adoptTexture(Skia.Image.MakeNativeTextureFromImage(image));
31
+ * ```
32
+ */
33
+ export const adoptTexture = pointer => {
34
+ if (typeof RNWebGPU === "undefined") {
35
+ throw new Error("react-native-webgpu is not installed natively; adoptTexture is unavailable");
36
+ }
37
+ return RNWebGPU.adoptTexture(pointer);
38
+ };
21
39
  //# sourceMappingURL=importDevice.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["importDevice","pointer","RNWebGPU","Error"],"sourceRoot":"../../src","sources":["importDevice.ts"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,MAAMA,YAAY,GAAIC,OAAe,IAAgB;EAC1D,IAAI,OAAOC,QAAQ,KAAK,WAAW,EAAE;IACnC,MAAM,IAAIC,KAAK,CACb,4EACF,CAAC;EACH;EACA,OAAOD,QAAQ,CAACF,YAAY,CAACC,OAAO,CAAC;AACvC,CAAC","ignoreList":[]}
1
+ {"version":3,"names":["importDevice","pointer","RNWebGPU","Error","adoptTexture"],"sourceRoot":"../../src","sources":["importDevice.ts"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,MAAMA,YAAY,GAAIC,OAAe,IAAgB;EAC1D,IAAI,OAAOC,QAAQ,KAAK,WAAW,EAAE;IACnC,MAAM,IAAIC,KAAK,CACb,4EACF,CAAC;EACH;EACA,OAAOD,QAAQ,CAACF,YAAY,CAACC,OAAO,CAAC;AACvC,CAAC;;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,MAAMG,YAAY,GAAIH,OAAe,IAAiB;EAC3D,IAAI,OAAOC,QAAQ,KAAK,WAAW,EAAE;IACnC,MAAM,IAAIC,KAAK,CACb,4EACF,CAAC;EACH;EACA,OAAOD,QAAQ,CAACE,YAAY,CAACH,OAAO,CAAC;AACvC,CAAC","ignoreList":[]}
@@ -0,0 +1,59 @@
1
+ /// <reference types="@webgpu/types" />
2
+ import React from "react";
3
+ import { View } from "react-native";
4
+ // Jest mock for `react-native-webgpu`.
5
+ //
6
+ // There is no native WebGPU implementation under Jest, so this never talks to
7
+ // `NativeWebGPUModule` or the native `RNWebGPU` global. `Canvas` renders as a
8
+ // plain `View` so screens built around it can still be rendered in tests;
9
+ // anything that requires an actual GPU (`importDevice`, `adoptTexture`,
10
+ // `useDevice`, a real canvas context) fails loudly instead of silently
11
+ // returning fake data, mirroring how the real module already reports a
12
+ // missing native install (see `importDevice`/`adoptTexture` in
13
+ // `./importDevice.ts`).
14
+
15
+ export * from "./constants";
16
+ export * from "./install";
17
+ export * from "./formats";
18
+ const NOT_AVAILABLE_UNDER_JEST = "is not available under Jest - react-native-webgpu has no native implementation in tests (see react-native-webgpu/jestSetup.js)";
19
+ export const Canvas = ({
20
+ transparent: _transparent,
21
+ ref,
22
+ ...props
23
+ }) => {
24
+ React.useImperativeHandle(ref, () => ({
25
+ getContextId: () => -1,
26
+ getContext: _contextName => null,
27
+ getNativeSurface: () => {
28
+ throw new Error(`Canvas.getNativeSurface() ${NOT_AVAILABLE_UNDER_JEST}`);
29
+ }
30
+ }));
31
+ return /*#__PURE__*/React.createElement(View, props);
32
+ };
33
+ export const useCanvasRef = () => React.useRef(null);
34
+ export const useSurface = () => ({
35
+ ref: React.useRef(null),
36
+ surface: null
37
+ });
38
+ export const warnIfNotHardwareAccelerated = () => undefined;
39
+ export const useDevice = () => ({
40
+ adapter: null,
41
+ device: null
42
+ });
43
+ export const GPUDeviceProvider = ({
44
+ children
45
+ }) => children ?? null;
46
+ export const useMainDevice = () => {
47
+ throw new Error(`useMainDevice() ${NOT_AVAILABLE_UNDER_JEST}`);
48
+ };
49
+ export const importDevice = _pointer => {
50
+ throw new Error(`importDevice() ${NOT_AVAILABLE_UNDER_JEST}`);
51
+ };
52
+ export const adoptTexture = _pointer => {
53
+ throw new Error(`adoptTexture() ${NOT_AVAILABLE_UNDER_JEST}`);
54
+ };
55
+ export const installWebGPU = () => undefined;
56
+ export const WebGPUModule = {
57
+ install: () => false
58
+ };
59
+ //# sourceMappingURL=mock.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["React","View","NOT_AVAILABLE_UNDER_JEST","Canvas","transparent","_transparent","ref","props","useImperativeHandle","getContextId","getContext","_contextName","getNativeSurface","Error","createElement","useCanvasRef","useRef","useSurface","surface","warnIfNotHardwareAccelerated","undefined","useDevice","adapter","device","GPUDeviceProvider","children","useMainDevice","importDevice","_pointer","adoptTexture","installWebGPU","WebGPUModule","install"],"sourceRoot":"../../src","sources":["mock.ts"],"mappings":"AAAA;AACA,OAAOA,KAAK,MAAM,OAAO;AAEzB,SAASC,IAAI,QAAQ,cAAc;AAKnC;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA,cAAc,aAAa;AAC3B,cAAc,WAAW;AACzB,cAAc,WAAW;AAEzB,MAAMC,wBAAwB,GAC5B,gIAAgI;AASlI,OAAO,MAAMC,MAAM,GAAGA,CAAC;EACrBC,WAAW,EAAEC,YAAY;EACzBC,GAAG;EACH,GAAGC;AACQ,CAAC,KAAK;EACjBP,KAAK,CAACQ,mBAAmB,CAACF,GAAG,EAAE,OAAO;IACpCG,YAAY,EAAEA,CAAA,KAAM,CAAC,CAAC;IACtBC,UAAU,EAAGC,YAAsB,IAA6B,IAAI;IACpEC,gBAAgB,EAAEA,CAAA,KAAoB;MACpC,MAAM,IAAIC,KAAK,CAAC,6BAA6BX,wBAAwB,EAAE,CAAC;IAC1E;EACF,CAAC,CAAC,CAAC;EACH,oBAAOF,KAAK,CAACc,aAAa,CAACb,IAAI,EAAEM,KAAK,CAAC;AACzC,CAAC;AAED,OAAO,MAAMQ,YAAY,GAAGA,CAAA,KAAMf,KAAK,CAACgB,MAAM,CAAC,IAAI,CAAC;AACpD,OAAO,MAAMC,UAAU,GAAGA,CAAA,MAAO;EAAEX,GAAG,EAAEN,KAAK,CAACgB,MAAM,CAAC,IAAI,CAAC;EAAEE,OAAO,EAAE;AAAK,CAAC,CAAC;AAC5E,OAAO,MAAMC,4BAA4B,GAAGA,CAAA,KAAMC,SAAS;AAE3D,OAAO,MAAMC,SAAS,GAAGA,CAAA,MAAO;EAAEC,OAAO,EAAE,IAAI;EAAEC,MAAM,EAAE;AAAK,CAAC,CAAC;AAEhE,OAAO,MAAMC,iBAAiB,GAAGA,CAAC;EAAEC;AAAmC,CAAC,KACtEA,QAAQ,IAAI,IAAI;AAElB,OAAO,MAAMC,aAAa,GAAGA,CAAA,KAAa;EACxC,MAAM,IAAIb,KAAK,CAAC,mBAAmBX,wBAAwB,EAAE,CAAC;AAChE,CAAC;AAED,OAAO,MAAMyB,YAAY,GAAIC,QAAgB,IAAgB;EAC3D,MAAM,IAAIf,KAAK,CAAC,kBAAkBX,wBAAwB,EAAE,CAAC;AAC/D,CAAC;AAED,OAAO,MAAM2B,YAAY,GAAID,QAAgB,IAAiB;EAC5D,MAAM,IAAIf,KAAK,CAAC,kBAAkBX,wBAAwB,EAAE,CAAC;AAC/D,CAAC;AAED,OAAO,MAAM4B,aAAa,GAAGA,CAAA,KAAMV,SAAS;AAE5C,OAAO,MAAMW,YAAY,GAAG;EAAEC,OAAO,EAAEA,CAAA,KAAM;AAAM,CAAC","ignoreList":[]}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=jestSetup.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"jestSetup.d.ts","sourceRoot":"","sources":["../../jestSetup.js"],"names":[],"mappings":""}
@@ -14,4 +14,5 @@ export const __esModule: boolean;
14
14
  * Graphite builds do both).
15
15
  */
16
16
  export function importDevice(pointer: any): GPUDevice;
17
+ export function adoptTexture(pointer: any): GPUTexture;
17
18
  //# sourceMappingURL=importDevice.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"importDevice.d.ts","sourceRoot":"","sources":["../../../commonjs/importDevice.js"],"names":[],"mappings":";AAMA;;;;;;;;;;;;;GAaG;AACH,sDAKC"}
1
+ {"version":3,"file":"importDevice.d.ts","sourceRoot":"","sources":["../../../commonjs/importDevice.js"],"names":[],"mappings":";AAMA;;;;;;;;;;;;;GAaG;AACH,sDAKC;AAcD,uDAKC"}
@@ -0,0 +1,27 @@
1
+ export const __esModule: boolean;
2
+ export namespace WebGPUModule {
3
+ function install(): boolean;
4
+ }
5
+ export function Canvas({ transparent: _transparent, ref, ...props }: {
6
+ [x: string]: any;
7
+ transparent: any;
8
+ ref: any;
9
+ }): any;
10
+ export function useCanvasRef(): any;
11
+ export function useSurface(): {
12
+ ref: any;
13
+ surface: null;
14
+ };
15
+ export function warnIfNotHardwareAccelerated(): undefined;
16
+ export function useDevice(): {
17
+ adapter: null;
18
+ device: null;
19
+ };
20
+ export function GPUDeviceProvider({ children }: {
21
+ children: any;
22
+ }): any;
23
+ export function useMainDevice(): never;
24
+ export function importDevice(_pointer: any): never;
25
+ export function adoptTexture(_pointer: any): never;
26
+ export function installWebGPU(): undefined;
27
+ //# sourceMappingURL=mock.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mock.d.ts","sourceRoot":"","sources":["../../../commonjs/mock.js"],"names":[],"mappings":";;IAwHW,4BAAW;;AAhDtB;;;;QAaC;AAED,oCAAsD;AAEtD;;;EAGE;AAEF,0DAAoD;AAEpD;;;EAGE;AAEF;;QAEsB;AAEtB,uCAEC;AAED,mDAEC;AAED,mDAEC;AAED,2CAAqC"}
@@ -1,2 +1,3 @@
1
1
  export function importDevice(pointer: any): GPUDevice;
2
+ export function adoptTexture(pointer: any): GPUTexture;
2
3
  //# sourceMappingURL=importDevice.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"importDevice.d.ts","sourceRoot":"","sources":["../../../module/importDevice.js"],"names":[],"mappings":"AAcO,sDAKN"}
1
+ {"version":3,"file":"importDevice.d.ts","sourceRoot":"","sources":["../../../module/importDevice.js"],"names":[],"mappings":"AAcO,sDAKN;AAaM,uDAKN"}
@@ -0,0 +1,31 @@
1
+ export * from "./constants";
2
+ export * from "./install";
3
+ export * from "./formats";
4
+ export function Canvas({ transparent: _transparent, ref, ...props }: {
5
+ [x: string]: any;
6
+ transparent: any;
7
+ ref: any;
8
+ }): React.CElement<import("react-native").ViewProps, View>;
9
+ export function useCanvasRef(): React.MutableRefObject<null>;
10
+ export function useSurface(): {
11
+ ref: React.MutableRefObject<null>;
12
+ surface: null;
13
+ };
14
+ export function warnIfNotHardwareAccelerated(): undefined;
15
+ export function useDevice(): {
16
+ adapter: null;
17
+ device: null;
18
+ };
19
+ export function GPUDeviceProvider({ children }: {
20
+ children: any;
21
+ }): any;
22
+ export function useMainDevice(): never;
23
+ export function importDevice(_pointer: any): never;
24
+ export function adoptTexture(_pointer: any): never;
25
+ export function installWebGPU(): undefined;
26
+ export namespace WebGPUModule {
27
+ function install(): boolean;
28
+ }
29
+ import { View } from "react-native";
30
+ import React from "react";
31
+ //# sourceMappingURL=mock.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mock.d.ts","sourceRoot":"","sources":["../../../module/mock.js"],"names":[],"mappings":";;;AAkBO;;;;2DAaN;AACM,6DAA6C;AAC7C;;;EAGL;AACK,0DAAoD;AACpD;;;EAGL;AACK;;QAEe;AACf,uCAEN;AACM,mDAEN;AACM,mDAEN;AACM,2CAAqC;;IAEjC,4BAAW;;qBAtDD,cAAc;kBADjB,OAAO"}
@@ -13,4 +13,16 @@
13
13
  * Graphite builds do both).
14
14
  */
15
15
  export declare const importDevice: (pointer: bigint) => GPUDevice;
16
+ /**
17
+ * Wraps an externally created WGPUTexture pointer into a GPUTexture, taking
18
+ * ownership of one reference: the returned texture releases it when destroyed.
19
+ *
20
+ * Pair with producers that hand out a +1 reference, such as
21
+ * `Skia.Image.MakeNativeTextureFromImage()`:
22
+ *
23
+ * ```ts
24
+ * const texture = adoptTexture(Skia.Image.MakeNativeTextureFromImage(image));
25
+ * ```
26
+ */
27
+ export declare const adoptTexture: (pointer: bigint) => GPUTexture;
16
28
  //# sourceMappingURL=importDevice.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"importDevice.d.ts","sourceRoot":"","sources":["../../../src/importDevice.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,YAAY,GAAI,SAAS,MAAM,KAAG,SAO9C,CAAC"}
1
+ {"version":3,"file":"importDevice.d.ts","sourceRoot":"","sources":["../../../src/importDevice.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,YAAY,GAAI,SAAS,MAAM,KAAG,SAO9C,CAAC;AAEF;;;;;;;;;;GAUG;AACH,eAAO,MAAM,YAAY,GAAI,SAAS,MAAM,KAAG,UAO9C,CAAC"}
@@ -20,9 +20,13 @@ declare global {
20
20
  createTestVideoFrame: (width: number, height: number) => NativeVideoFrame;
21
21
  createVideoFrameFromNativeBuffer: (pointer: bigint) => NativeVideoFrame;
22
22
  importDevice: (pointer: bigint) => GPUDevice;
23
+ adoptTexture: (pointer: bigint) => GPUTexture;
23
24
  createVideoPlayer: (path: string, pixelFormat?: NativeVideoPixelFormat) => VideoPlayer;
24
25
  writeTestVideoFile: () => string;
25
26
  };
27
+ interface GPUTexture {
28
+ readonly nativePointer: bigint;
29
+ }
26
30
  interface GPUDevice {
27
31
  importSharedTextureMemory(descriptor: GPUSharedTextureMemoryDescriptor): GPUSharedTextureMemory;
28
32
  importSharedFence(descriptor: GPUSharedFenceDescriptor): GPUSharedFence;
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,cAAc,EACd,wBAAwB,EACxB,wBAAwB,EACxB,sBAAsB,EACtB,gCAAgC,EAChC,YAAY,EACZ,eAAe,EACf,WAAW,EACX,gBAAgB,EAChB,sBAAsB,EACvB,MAAM,SAAS,CAAC;AAEjB,cAAc,QAAQ,CAAC;AACvB,cAAc,aAAa,CAAC;AAC5B,cAAc,WAAW,CAAC;AAC1B,YAAY,EACV,gBAAgB,EAChB,WAAW,EACX,cAAc,EACd,wBAAwB,EACxB,wBAAwB,EACxB,mBAAmB,EACnB,kBAAkB,EAClB,sBAAsB,EACtB,gCAAgC,EAChC,oCAAoC,EACpC,sBAA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Q,CAAC,cAAc,EAAE,MAAM,EAAE,CAAC;KACnC;IAGD,SAAS,iBAAiB,CACxB,KAAK,EAAE,WAAW,GAAG,eAAe,EACpC,OAAO,CAAC,EAAE,kBAAkB,GAC3B,OAAO,CAAC,WAAW,CAAC,CAAC;CACzB"}
@@ -0,0 +1,34 @@
1
+ import React from "react";
2
+ import type { ReactNode } from "react";
3
+ import { View } from "react-native";
4
+ import type { ViewProps } from "react-native";
5
+ export * from "./constants";
6
+ export * from "./install";
7
+ export * from "./formats";
8
+ export type { CanvasRef, NativeCanvas, RNCanvasContext } from "./Canvas";
9
+ interface CanvasProps extends ViewProps {
10
+ transparent?: boolean;
11
+ ref?: React.Ref<unknown>;
12
+ }
13
+ export declare const Canvas: ({ transparent: _transparent, ref, ...props }: CanvasProps) => React.CElement<ViewProps, View>;
14
+ export declare const useCanvasRef: () => React.MutableRefObject<null>;
15
+ export declare const useSurface: () => {
16
+ ref: React.MutableRefObject<null>;
17
+ surface: null;
18
+ };
19
+ export declare const warnIfNotHardwareAccelerated: () => undefined;
20
+ export declare const useDevice: () => {
21
+ adapter: null;
22
+ device: null;
23
+ };
24
+ export declare const GPUDeviceProvider: ({ children }: {
25
+ children?: ReactNode;
26
+ }) => string | number | boolean | React.ReactElement<any, string | React.JSXElementConstructor<any>> | Iterable<React.ReactNode> | null;
27
+ export declare const useMainDevice: () => never;
28
+ export declare const importDevice: (_pointer: bigint) => GPUDevice;
29
+ export declare const adoptTexture: (_pointer: bigint) => GPUTexture;
30
+ export declare const installWebGPU: () => undefined;
31
+ export declare const WebGPUModule: {
32
+ install: () => boolean;
33
+ };
34
+ //# sourceMappingURL=mock.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mock.d.ts","sourceRoot":"","sources":["../../../src/mock.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AACvC,OAAO,EAAE,IAAI,EAAE,MAAM,cAAc,CAAC;AACpC,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAe9C,cAAc,aAAa,CAAC;AAC5B,cAAc,WAAW,CAAC;AAC1B,cAAc,WAAW,CAAC;AAK1B,YAAY,EAAE,SAAS,EAAE,YAAY,EAAE,eAAe,EAAE,MAAM,UAAU,CAAC;AAEzE,UAAU,WAAY,SAAQ,SAAS;IACrC,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,GAAG,CAAC,EAAE,KAAK,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;CAC1B;AAED,eAAO,MAAM,MAAM,GAAI,8CAIpB,WAAW,oCASb,CAAC;AAEF,eAAO,MAAM,YAAY,oCAA2B,CAAC;AACrD,eAAO,MAAM,UAAU;;;CAAqD,CAAC;AAC7E,eAAO,MAAM,4BAA4B,iBAAkB,CAAC;AAE5D,eAAO,MAAM,SAAS;;;CAA0C,CAAC;AAEjE,eAAO,MAAM,iBAAiB,GAAI,cAAc;IAAE,QAAQ,CAAC,EAAE,SAAS,CAAA;CAAE,sIACtD,CAAC;AAEnB,eAAO,MAAM,aAAa,QAAO,KAEhC,CAAC;AAEF,eAAO,MAAM,YAAY,GAAI,UAAU,MAAM,KAAG,SAE/C,CAAC;AAEF,eAAO,MAAM,YAAY,GAAI,UAAU,MAAM,KAAG,UAE/C,CAAC;AAEF,eAAO,MAAM,aAAa,iBAAkB,CAAC;AAE7C,eAAO,MAAM,YAAY;;CAA2B,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-webgpu",
3
- "version": "0.7.0",
3
+ "version": "0.8.0",
4
4
  "description": "React Native WebGPU",
5
5
  "main": "lib/commonjs/index",
6
6
  "module": "lib/module/index",
@@ -11,6 +11,7 @@
11
11
  "src/**",
12
12
  "lib/**",
13
13
  "!**/__tests__/**",
14
+ "jestSetup.js",
14
15
  "android/build.gradle",
15
16
  "android/CMakeLists.txt",
16
17
  "android/cpp/**",
@@ -20,3 +20,23 @@ export const importDevice = (pointer: bigint): GPUDevice => {
20
20
  }
21
21
  return RNWebGPU.importDevice(pointer);
22
22
  };
23
+
24
+ /**
25
+ * Wraps an externally created WGPUTexture pointer into a GPUTexture, taking
26
+ * ownership of one reference: the returned texture releases it when destroyed.
27
+ *
28
+ * Pair with producers that hand out a +1 reference, such as
29
+ * `Skia.Image.MakeNativeTextureFromImage()`:
30
+ *
31
+ * ```ts
32
+ * const texture = adoptTexture(Skia.Image.MakeNativeTextureFromImage(image));
33
+ * ```
34
+ */
35
+ export const adoptTexture = (pointer: bigint): GPUTexture => {
36
+ if (typeof RNWebGPU === "undefined") {
37
+ throw new Error(
38
+ "react-native-webgpu is not installed natively; adoptTexture is unavailable",
39
+ );
40
+ }
41
+ return RNWebGPU.adoptTexture(pointer);
42
+ };
package/src/index.tsx CHANGED
@@ -62,6 +62,10 @@ declare global {
62
62
  // device from Skia.getNativeDevice()) into a GPUDevice. Requires the
63
63
  // exporter to share this process's single Dawn instance.
64
64
  importDevice: (pointer: bigint) => GPUDevice;
65
+ // Wrap an externally created WGPUTexture pointer into a GPUTexture,
66
+ // taking ownership of one reference (pair with producers that return a
67
+ // +1 pointer, e.g. Skia.Image.MakeNativeTextureFromImage()).
68
+ adoptTexture: (pointer: bigint) => GPUTexture;
65
69
  createVideoPlayer: (
66
70
  path: string,
67
71
  pixelFormat?: NativeVideoPixelFormat,
@@ -69,6 +73,13 @@ declare global {
69
73
  writeTestVideoFile: () => string;
70
74
  };
71
75
 
76
+ interface GPUTexture {
77
+ // Non-spec RN extension: raw WGPUTexture handle as a BigInt for
78
+ // pointer-based interop (e.g. Skia.Image.MakeImageFromNativeTexture).
79
+ // Borrowed: keep this GPUTexture alive while the pointer is in use.
80
+ readonly nativePointer: bigint;
81
+ }
82
+
72
83
  interface GPUDevice {
73
84
  importSharedTextureMemory(
74
85
  descriptor: GPUSharedTextureMemoryDescriptor,
package/src/mock.ts ADDED
@@ -0,0 +1,72 @@
1
+ /// <reference types="@webgpu/types" />
2
+ import React from "react";
3
+ import type { ReactNode } from "react";
4
+ import { View } from "react-native";
5
+ import type { ViewProps } from "react-native";
6
+
7
+ import type { NativeCanvas, RNCanvasContext } from "./Canvas";
8
+
9
+ // Jest mock for `react-native-webgpu`.
10
+ //
11
+ // There is no native WebGPU implementation under Jest, so this never talks to
12
+ // `NativeWebGPUModule` or the native `RNWebGPU` global. `Canvas` renders as a
13
+ // plain `View` so screens built around it can still be rendered in tests;
14
+ // anything that requires an actual GPU (`importDevice`, `adoptTexture`,
15
+ // `useDevice`, a real canvas context) fails loudly instead of silently
16
+ // returning fake data, mirroring how the real module already reports a
17
+ // missing native install (see `importDevice`/`adoptTexture` in
18
+ // `./importDevice.ts`).
19
+
20
+ export * from "./constants";
21
+ export * from "./install";
22
+ export * from "./formats";
23
+
24
+ const NOT_AVAILABLE_UNDER_JEST =
25
+ "is not available under Jest - react-native-webgpu has no native implementation in tests (see react-native-webgpu/jestSetup.js)";
26
+
27
+ export type { CanvasRef, NativeCanvas, RNCanvasContext } from "./Canvas";
28
+
29
+ interface CanvasProps extends ViewProps {
30
+ transparent?: boolean;
31
+ ref?: React.Ref<unknown>;
32
+ }
33
+
34
+ export const Canvas = ({
35
+ transparent: _transparent,
36
+ ref,
37
+ ...props
38
+ }: CanvasProps) => {
39
+ React.useImperativeHandle(ref, () => ({
40
+ getContextId: () => -1,
41
+ getContext: (_contextName: "webgpu"): RNCanvasContext | null => null,
42
+ getNativeSurface: (): NativeCanvas => {
43
+ throw new Error(`Canvas.getNativeSurface() ${NOT_AVAILABLE_UNDER_JEST}`);
44
+ },
45
+ }));
46
+ return React.createElement(View, props);
47
+ };
48
+
49
+ export const useCanvasRef = () => React.useRef(null);
50
+ export const useSurface = () => ({ ref: React.useRef(null), surface: null });
51
+ export const warnIfNotHardwareAccelerated = () => undefined;
52
+
53
+ export const useDevice = () => ({ adapter: null, device: null });
54
+
55
+ export const GPUDeviceProvider = ({ children }: { children?: ReactNode }) =>
56
+ children ?? null;
57
+
58
+ export const useMainDevice = (): never => {
59
+ throw new Error(`useMainDevice() ${NOT_AVAILABLE_UNDER_JEST}`);
60
+ };
61
+
62
+ export const importDevice = (_pointer: bigint): GPUDevice => {
63
+ throw new Error(`importDevice() ${NOT_AVAILABLE_UNDER_JEST}`);
64
+ };
65
+
66
+ export const adoptTexture = (_pointer: bigint): GPUTexture => {
67
+ throw new Error(`adoptTexture() ${NOT_AVAILABLE_UNDER_JEST}`);
68
+ };
69
+
70
+ export const installWebGPU = () => undefined;
71
+
72
+ export const WebGPUModule = { install: () => false };