react-native-webgpu 0.7.1 → 0.8.1
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.
- package/cpp/rnwgpu/api/GPUQueue.cpp +39 -13
- package/jestSetup.js +11 -0
- package/lib/commonjs/mock.js +123 -0
- package/lib/commonjs/mock.js.map +1 -0
- package/lib/module/mock.js +59 -0
- package/lib/module/mock.js.map +1 -0
- package/lib/typescript/jestSetup.d.ts +2 -0
- package/lib/typescript/jestSetup.d.ts.map +1 -0
- package/lib/typescript/lib/commonjs/mock.d.ts +27 -0
- package/lib/typescript/lib/commonjs/mock.d.ts.map +1 -0
- package/lib/typescript/lib/module/mock.d.ts +31 -0
- package/lib/typescript/lib/module/mock.d.ts.map +1 -0
- package/lib/typescript/src/mock.d.ts +34 -0
- package/lib/typescript/src/mock.d.ts.map +1 -0
- package/package.json +2 -1
- package/src/mock.ts +72 -0
|
@@ -128,6 +128,30 @@ void GPUQueue::copyExternalImageToTexture(
|
|
|
128
128
|
throw std::runtime_error("Invalid input for GPUQueue::writeTexture()");
|
|
129
129
|
}
|
|
130
130
|
|
|
131
|
+
const auto origin = source->origin.value_or(nullptr);
|
|
132
|
+
// GPUOrigin2D coordinates are [EnforceRange] unsigned long: negative,
|
|
133
|
+
// NaN, or out-of-range doubles must be rejected here because casting
|
|
134
|
+
// them to an unsigned integer is undefined behavior.
|
|
135
|
+
constexpr double kMaxOrigin =
|
|
136
|
+
static_cast<double>(std::numeric_limits<uint32_t>::max());
|
|
137
|
+
if (origin && (!(origin->x >= 0) || !(origin->y >= 0) ||
|
|
138
|
+
origin->x > kMaxOrigin || origin->y > kMaxOrigin)) {
|
|
139
|
+
throw std::runtime_error(
|
|
140
|
+
"The source origin must be a non-negative integer coordinate.");
|
|
141
|
+
}
|
|
142
|
+
const size_t sourceOriginX =
|
|
143
|
+
origin ? static_cast<size_t>(origin->x) : 0;
|
|
144
|
+
const size_t sourceOriginY =
|
|
145
|
+
origin ? static_cast<size_t>(origin->y) : 0;
|
|
146
|
+
if (sourceOriginX > source->source->getWidth() ||
|
|
147
|
+
sz.width > source->source->getWidth() - sourceOriginX ||
|
|
148
|
+
sourceOriginY > source->source->getHeight() ||
|
|
149
|
+
sz.height > source->source->getHeight() - sourceOriginY ||
|
|
150
|
+
sz.depthOrArrayLayers > 1) {
|
|
151
|
+
throw std::runtime_error(
|
|
152
|
+
"The source copy region is outside the ImageBitmap.");
|
|
153
|
+
}
|
|
154
|
+
|
|
131
155
|
const bool flipY = source->flipY.value_or(false);
|
|
132
156
|
// premultipliedAlpha defaults to false per the WebGPU spec: an untagged
|
|
133
157
|
// destination expects straight alpha. Convert only when the ImageBitmap's
|
|
@@ -138,28 +162,30 @@ void GPUQueue::copyExternalImageToTexture(
|
|
|
138
162
|
const bool needsAlphaConversion =
|
|
139
163
|
bytesPerPixel == 4 && sourcePremultiplied != destinationPremultiplied;
|
|
140
164
|
|
|
141
|
-
if (
|
|
142
|
-
|
|
143
|
-
uint32_t
|
|
165
|
+
if (sourceOriginX != 0 || sourceOriginY != 0 || flipY ||
|
|
166
|
+
needsAlphaConversion) {
|
|
167
|
+
uint32_t sourceRowSize = bytesPerPixel * source->source->getWidth();
|
|
168
|
+
uint32_t rowSize = bytesPerPixel * sz.width;
|
|
169
|
+
uint32_t totalSize = rowSize * sz.height;
|
|
144
170
|
|
|
145
|
-
// Stage
|
|
146
|
-
// ImageBitmap's backing store.
|
|
171
|
+
// Stage only the selected subregion so transformations never touch the
|
|
172
|
+
// ImageBitmap's backing store or pixels outside the requested copy.
|
|
147
173
|
std::vector<uint8_t> staged(totalSize);
|
|
148
174
|
const uint8_t *src =
|
|
149
175
|
static_cast<const uint8_t *>(source->source->getData());
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
} else {
|
|
157
|
-
std::memcpy(staged.data(), src, totalSize);
|
|
176
|
+
for (uint32_t row = 0; row < sz.height; ++row) {
|
|
177
|
+
const uint32_t sourceRow =
|
|
178
|
+
sourceOriginY + (flipY ? sz.height - 1 - row : row);
|
|
179
|
+
const uint32_t sourceOffset =
|
|
180
|
+
sourceRow * sourceRowSize + sourceOriginX * bytesPerPixel;
|
|
181
|
+
std::memcpy(staged.data() + row * rowSize, src + sourceOffset, rowSize);
|
|
158
182
|
}
|
|
159
183
|
if (needsAlphaConversion) {
|
|
160
184
|
convertAlpha(staged.data(), totalSize, sourcePremultiplied,
|
|
161
185
|
destinationPremultiplied);
|
|
162
186
|
}
|
|
187
|
+
layout.bytesPerRow = rowSize;
|
|
188
|
+
layout.rowsPerImage = sz.height;
|
|
163
189
|
_instance.WriteTexture(&dst, staged.data(), totalSize, &layout, &sz);
|
|
164
190
|
} else {
|
|
165
191
|
_instance.WriteTexture(&dst, source->source->getData(),
|
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
|
+
);
|
|
@@ -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,GAAA;EAAA,IAAAA,GAAA,kBAAAA,GAAA;EAAA,IAAAH,MAAA,CAAAI,SAAA,CAAAC,cAAA,CAAAC,IAAA,CAAAC,YAAA,EAAAJ,GAAA;EAAA,IAAAA,GAAA,IAAAK,OAAA,IAAAA,OAAA,CAAAL,GAAA,MAAAJ,UAAA,CAAAI,GAAA;EAAAH,MAAA,CAAAS,cAAA,CAAAD,OAAA,EAAAL,GAAA;IAAAO,UAAA;IAAAC,GAAA,WAAAA,CAAA;MAAA,OAAAZ,UAAA,CAAAI,GAAA;IAAA;EAAA;AAAA;AACA,IAAAS,QAAA,GAAAf,OAAA;AAAAG,MAAA,CAAAC,IAAA,CAAAW,QAAA,EAAAV,OAAA,WAAAC,GAAA;EAAA,IAAAA,GAAA,kBAAAA,GAAA;EAAA,IAAAH,MAAA,CAAAI,SAAA,CAAAC,cAAA,CAAAC,IAAA,CAAAC,YAAA,EAAAJ,GAAA;EAAA,IAAAA,GAAA,IAAAK,OAAA,IAAAA,OAAA,CAAAL,GAAA,MAAAS,QAAA,CAAAT,GAAA;EAAAH,MAAA,CAAAS,cAAA,CAAAD,OAAA,EAAAL,GAAA;IAAAO,UAAA;IAAAC,GAAA,WAAAA,CAAA;MAAA,OAAAC,QAAA,CAAAT,GAAA;IAAA;EAAA;AAAA;AACA,IAAAU,QAAA,GAAAhB,OAAA;AAAAG,MAAA,CAAAC,IAAA,CAAAY,QAAA,EAAAX,OAAA,WAAAC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
|
|
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,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":["../../jestSetup.js"],"names":[],"mappings":""}
|
|
@@ -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"}
|
|
@@ -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"}
|
|
@@ -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.
|
|
3
|
+
"version": "0.8.1",
|
|
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/**",
|
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 };
|