react-native-webgpu 0.6.0 → 0.6.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/android/cpp/cpp-adapter.cpp +35 -13
- package/android/src/main/java/com/webgpu/WebGPUAHBView.java +2 -2
- package/android/src/main/java/com/webgpu/WebGPUAPI.java +7 -2
- package/android/src/main/java/com/webgpu/WebGPUSurfaceView.java +3 -1
- package/android/src/main/java/com/webgpu/WebGPUTextureView.java +11 -7
- package/android/src/main/java/com/webgpu/WebGPUView.java +10 -7
- package/android/src/main/java/com/webgpu/WebGPUViewManager.java +6 -0
- package/apple/MetalView.mm +33 -8
- package/cpp/rnwgpu/RNWebGPUManager.cpp +14 -1
- package/cpp/rnwgpu/RNWebGPUManager.h +9 -0
- package/cpp/rnwgpu/SurfaceRegistry.h +469 -131
- package/cpp/rnwgpu/api/GPUAdapter.cpp +10 -3
- package/cpp/rnwgpu/api/GPUAdapter.h +5 -4
- package/cpp/rnwgpu/api/GPUBuffer.cpp +12 -2
- package/cpp/rnwgpu/api/GPUBuffer.h +3 -2
- package/cpp/rnwgpu/api/GPUCanvasContext.cpp +33 -19
- package/cpp/rnwgpu/api/GPUCanvasContext.h +3 -1
- package/cpp/rnwgpu/api/GPUDevice.cpp +32 -17
- package/cpp/rnwgpu/api/GPUDevice.h +9 -7
- package/cpp/rnwgpu/api/GPUQueue.cpp +6 -2
- package/cpp/rnwgpu/api/GPUQueue.h +3 -3
- package/cpp/rnwgpu/api/GPUShaderModule.cpp +7 -2
- package/cpp/rnwgpu/api/GPUShaderModule.h +3 -3
- package/cpp/rnwgpu/api/RNWebGPU.h +22 -1
- package/cpp/rnwgpu/async/RuntimeContext.h +9 -2
- package/lib/commonjs/Canvas.js +10 -0
- package/lib/commonjs/Canvas.js.map +1 -1
- package/lib/commonjs/WebPolyfillGPUModule.js +2 -0
- package/lib/commonjs/WebPolyfillGPUModule.js.map +1 -1
- package/lib/module/Canvas.js +11 -1
- package/lib/module/Canvas.js.map +1 -1
- package/lib/module/WebPolyfillGPUModule.js +2 -0
- package/lib/module/WebPolyfillGPUModule.js.map +1 -1
- package/lib/typescript/lib/commonjs/Canvas.d.ts.map +1 -1
- package/lib/typescript/lib/module/Canvas.d.ts.map +1 -1
- package/lib/typescript/src/Canvas.d.ts.map +1 -1
- package/lib/typescript/src/index.d.ts +1 -0
- package/lib/typescript/src/index.d.ts.map +1 -1
- package/package.json +2 -6
- package/src/Canvas.tsx +11 -1
- package/src/WebPolyfillGPUModule.ts +2 -0
- package/src/index.tsx +3 -0
- package/android/src/main/java/com/webgpu/WebGPUBaseView.java +0 -61
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Canvas.d.ts","sourceRoot":"","sources":["../../../src/Canvas.tsx"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"Canvas.d.ts","sourceRoot":"","sources":["../../../src/Canvas.tsx"],"names":[],"mappings":"AAAA,OAAO,KAA2D,MAAM,OAAO,CAAC;AAChF,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAU9C,KAAK,cAAc,GAAG,MAAM,CAAC;AAE7B,MAAM,WAAW,YAAY;IAC3B,OAAO,EAAE,cAAc,CAAC;IACxB,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,WAAW,EAAE,MAAM,CAAC;IACpB,YAAY,EAAE,MAAM,CAAC;IAGrB,gBAAgB,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,aAAa,GAAG,IAAI,CAAC;IAC9D,mBAAmB,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,aAAa,GAAG,IAAI,CAAC;IACjE,aAAa,CAAC,KAAK,EAAE,KAAK,GAAG,IAAI,CAAC;IAClC,iBAAiB,CAAC,SAAS,EAAE,MAAM,GAAG,IAAI,CAAC;IAC3C,qBAAqB,CAAC,SAAS,EAAE,MAAM,GAAG,IAAI,CAAC;CAChD;AAED,MAAM,MAAM,eAAe,GAAG,gBAAgB,GAAG;IAC/C;;;;;;;;OAQG;IACH,OAAO,EAAE,MAAM,IAAI,CAAC;CACrB,CAAC;AAEF,MAAM,WAAW,SAAS;IACxB,YAAY,EAAE,MAAM,MAAM,CAAC;IAC3B,UAAU,CAAC,WAAW,EAAE,QAAQ,GAAG,eAAe,GAAG,IAAI,CAAC;IAC1D,gBAAgB,EAAE,MAAM,YAAY,CAAC;CACtC;AAED,UAAU,WAAY,SAAQ,SAAS;IACrC,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,GAAG,CAAC,EAAE,KAAK,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC;CAC5B;AAED,eAAO,MAAM,MAAM,GAAI,gCAAgC,WAAW,sBAiDjE,CAAC"}
|
|
@@ -13,6 +13,7 @@ declare global {
|
|
|
13
13
|
fabric: boolean;
|
|
14
14
|
getNativeSurface: (contextId: number) => NativeCanvas;
|
|
15
15
|
MakeWebGPUCanvasContext: (contextId: number, width: number, height: number) => RNCanvasContext;
|
|
16
|
+
destroyContext: (contextId: number) => void;
|
|
16
17
|
DecodeToUTF8: (buffer: NodeJS.ArrayBufferView | ArrayBuffer) => string;
|
|
17
18
|
createImageBitmap: typeof createImageBitmap;
|
|
18
19
|
loadVideoFrame: (path: string) => NativeVideoFrame;
|
|
@@ -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,sBAAsB,EACtB,wBAAwB,EACxB,wBAAwB,GACzB,MAAM,SAAS,CAAC;AAEjB,OAAO,CAAC,MAAM,CAAC;IACb,UAAU,SAAS;QACjB,GAAG,EAAE,GAAG,CAAC;KACV;IAED,IAAI,SAAS,EAAE,SAAS,CAAC;IAEzB,IAAI,QAAQ,EAAE;QACZ,GAAG,EAAE,GAAG,CAAC;QACT,MAAM,EAAE,OAAO,CAAC;QAChB,gBAAgB,EAAE,CAAC,SAAS,EAAE,MAAM,KAAK,YAAY,CAAC;QACtD,uBAAuB,EAAE,CACvB,SAAS,EAAE,MAAM,EACjB,KAAK,EAAE,MAAM,EACb,MAAM,EAAE,MAAM,KACX,eAAe,CAAC;
|
|
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,sBAAsB,EACtB,wBAAwB,EACxB,wBAAwB,GACzB,MAAM,SAAS,CAAC;AAEjB,OAAO,CAAC,MAAM,CAAC;IACb,UAAU,SAAS;QACjB,GAAG,EAAE,GAAG,CAAC;KACV;IAED,IAAI,SAAS,EAAE,SAAS,CAAC;IAEzB,IAAI,QAAQ,EAAE;QACZ,GAAG,EAA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S,iBAAiB,CACxB,KAAK,EAAE,WAAW,GAAG,eAAe,GACnC,OAAO,CAAC,WAAW,CAAC,CAAC;CACzB"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-native-webgpu",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.1",
|
|
4
4
|
"description": "React Native WebGPU",
|
|
5
5
|
"main": "lib/commonjs/index",
|
|
6
6
|
"module": "lib/module/index",
|
|
@@ -40,8 +40,7 @@
|
|
|
40
40
|
"clang-format-android": "find android/cpp/ -iname \"*.h\" -o -iname \"*.m\" -o -iname \"*.cpp\" | xargs clang-format -i",
|
|
41
41
|
"clang-format-common": "find cpp/rnwgpu -iname \"*.h\" -o -iname \"*.m\" -o -iname \"*.cpp\" | xargs clang-format -i",
|
|
42
42
|
"cpplint": "cpplint --linelength=230 --filter=-legal/copyright,-whitespace/indent,-whitespace/comments,-whitespace/ending_newline,-build/include_order,-runtime/references,-readability/todo,-whitespace/blank_line,-whitespace/todo,-runtime/int,-build/c++11,-whitespace/parens --exclude=example --exclude=android/.cxx --exclude=cpp/webgpu --exclude=cpp/dawn --exclude=ios --exclude=android/build --exclude=node_modules --recursive .",
|
|
43
|
-
"install-dawn": "tsx scripts/install-dawn.ts"
|
|
44
|
-
"codegen": "tsx scripts/codegen/codegen.ts && yarn clang-format"
|
|
43
|
+
"install-dawn": "tsx scripts/install-dawn.ts"
|
|
45
44
|
},
|
|
46
45
|
"keywords": [
|
|
47
46
|
"react-native",
|
|
@@ -72,7 +71,6 @@
|
|
|
72
71
|
"@semantic-release/github": "^10.3.3",
|
|
73
72
|
"@semantic-release/release-notes-generator": "^14.0.1",
|
|
74
73
|
"@types/jest": "^29.5.12",
|
|
75
|
-
"@types/lodash": "^4.17.5",
|
|
76
74
|
"@types/node": "^20.14.7",
|
|
77
75
|
"@types/pixelmatch": "5.2.4",
|
|
78
76
|
"@types/pngjs": "^6.0.5",
|
|
@@ -89,7 +87,6 @@
|
|
|
89
87
|
"eslint-plugin-jest": "^28.8.2",
|
|
90
88
|
"eslint-plugin-prettier": "^5.2.1",
|
|
91
89
|
"jest": "^29.7.0",
|
|
92
|
-
"lodash": "^4.17.21",
|
|
93
90
|
"pixelmatch": "5.3.0",
|
|
94
91
|
"pngjs": "^7.0.0",
|
|
95
92
|
"prettier": "^3.0.3",
|
|
@@ -105,7 +102,6 @@
|
|
|
105
102
|
"semantic-release": "^24.1.0",
|
|
106
103
|
"semantic-release-yarn": "^3.0.2",
|
|
107
104
|
"teapot": "^1.0.0",
|
|
108
|
-
"ts-morph": "^22.0.0",
|
|
109
105
|
"tsx": "^4.20.5",
|
|
110
106
|
"typescript": "^5.2.2",
|
|
111
107
|
"webgpu": "0.4.0",
|
package/src/Canvas.tsx
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import React, { useImperativeHandle, useRef, useState } from "react";
|
|
1
|
+
import React, { useEffect, useImperativeHandle, useRef, useState } from "react";
|
|
2
2
|
import type { ViewProps } from "react-native";
|
|
3
3
|
import { View } from "react-native";
|
|
4
4
|
|
|
@@ -53,6 +53,16 @@ interface CanvasProps extends ViewProps {
|
|
|
53
53
|
export const Canvas = ({ transparent, ref, ...props }: CanvasProps) => {
|
|
54
54
|
const viewRef = useRef(null);
|
|
55
55
|
const [contextId, _] = useState(() => generateContextId());
|
|
56
|
+
// Retire the native registry entry for this contextId on unmount. When a
|
|
57
|
+
// native surface is still attached, this is a no-op and the native view's
|
|
58
|
+
// own teardown retires the entry instead — which keeps StrictMode's
|
|
59
|
+
// simulated unmount (which re-runs effects without unmounting native views)
|
|
60
|
+
// from orphaning a live surface.
|
|
61
|
+
useEffect(() => {
|
|
62
|
+
return () => {
|
|
63
|
+
RNWebGPU.destroyContext(contextId);
|
|
64
|
+
};
|
|
65
|
+
}, [contextId]);
|
|
56
66
|
useImperativeHandle(ref, () => ({
|
|
57
67
|
getContextId: () => contextId,
|
|
58
68
|
getNativeSurface: () => {
|
|
@@ -55,5 +55,7 @@ function makeWebGPUCanvasContext(
|
|
|
55
55
|
window.RNWebGPU = {
|
|
56
56
|
getNativeSurface,
|
|
57
57
|
MakeWebGPUCanvasContext: makeWebGPUCanvasContext,
|
|
58
|
+
// On web the browser owns the canvas/context lifecycle; nothing to retire.
|
|
59
|
+
destroyContext: (_contextId: number) => {},
|
|
58
60
|
fabric,
|
|
59
61
|
};
|
package/src/index.tsx
CHANGED
|
@@ -47,6 +47,9 @@ declare global {
|
|
|
47
47
|
width: number,
|
|
48
48
|
height: number,
|
|
49
49
|
) => RNCanvasContext;
|
|
50
|
+
// Retires a canvas context; called by Canvas on unmount (the Canvas owns
|
|
51
|
+
// the native registry entry for its contextId).
|
|
52
|
+
destroyContext: (contextId: number) => void;
|
|
50
53
|
DecodeToUTF8: (buffer: NodeJS.ArrayBufferView | ArrayBuffer) => string;
|
|
51
54
|
createImageBitmap: typeof createImageBitmap;
|
|
52
55
|
loadVideoFrame: (path: string) => NativeVideoFrame;
|
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
package com.webgpu;
|
|
2
|
-
|
|
3
|
-
import android.content.Context;
|
|
4
|
-
import android.view.Surface;
|
|
5
|
-
import android.view.View;
|
|
6
|
-
import com.facebook.proguard.annotations.DoNotStrip;
|
|
7
|
-
|
|
8
|
-
public abstract class WebGPUBaseView extends View {
|
|
9
|
-
protected Integer mContextId;
|
|
10
|
-
|
|
11
|
-
public WebGPUBaseView(Context context, Integer contextId) {
|
|
12
|
-
super(context);
|
|
13
|
-
mContextId = contextId;
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
protected void handleSurfaceCreate(Surface surface) {
|
|
17
|
-
float density = getResources().getDisplayMetrics().density;
|
|
18
|
-
float scaledWidth = getWidth() / density;
|
|
19
|
-
float scaledHeight = getHeight() / density;
|
|
20
|
-
onSurfaceCreate(surface, mContextId, scaledWidth, scaledHeight);
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
protected void handleSurfaceChanged(Surface surface) {
|
|
24
|
-
float density = getResources().getDisplayMetrics().density;
|
|
25
|
-
float scaledWidth = getWidth() / density;
|
|
26
|
-
float scaledHeight = getHeight() / density;
|
|
27
|
-
onSurfaceChanged(surface, mContextId, scaledWidth, scaledHeight);
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
protected void handleSurfaceDestroyed() {
|
|
31
|
-
onSurfaceDestroy(mContextId);
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
@Override
|
|
35
|
-
protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
|
|
36
|
-
super.onLayout(changed, left, top, right, bottom);
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
@DoNotStrip
|
|
41
|
-
private native void onSurfaceCreate(
|
|
42
|
-
Surface surface,
|
|
43
|
-
int contextId,
|
|
44
|
-
float width,
|
|
45
|
-
float height
|
|
46
|
-
);
|
|
47
|
-
|
|
48
|
-
@DoNotStrip
|
|
49
|
-
private native void onSurfaceChanged(
|
|
50
|
-
Surface surface,
|
|
51
|
-
int contextId,
|
|
52
|
-
float width,
|
|
53
|
-
float height
|
|
54
|
-
);
|
|
55
|
-
|
|
56
|
-
@DoNotStrip
|
|
57
|
-
private native void onSurfaceDestroy(int contextId);
|
|
58
|
-
|
|
59
|
-
@DoNotStrip
|
|
60
|
-
protected native void switchToOffscreenSurface(int contextId);
|
|
61
|
-
}
|