react-native-webgpu 0.16.1 → 0.19.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.
- package/android/cpp/AndroidPlatformContext.h +8 -0
- package/android/src/main/java/com/webgpu/BackingViewKind.java +38 -0
- package/android/src/main/java/com/webgpu/WebGPUSurfaceView.java +19 -2
- package/android/src/main/java/com/webgpu/WebGPUView.java +78 -76
- package/android/src/main/java/com/webgpu/WebGPUViewManager.java +13 -6
- package/apple/ApplePlatformContext.h +2 -0
- package/apple/ApplePlatformContext.mm +12 -0
- package/apple/MetalLayerColorSpace.mm +20 -8
- package/cpp/jsi/NativeObject.h +42 -32
- package/cpp/rnwgpu/CanvasColorSpace.h +9 -0
- package/cpp/rnwgpu/PlatformContext.h +6 -0
- package/cpp/rnwgpu/RNWebGPUManager.cpp +5 -8
- package/cpp/rnwgpu/SurfaceRegistry.h +101 -30
- package/cpp/rnwgpu/WebGPURuntime.cpp +30 -11
- package/cpp/rnwgpu/WebGPURuntime.h +7 -2
- package/cpp/rnwgpu/api/GPUCanvasContext.cpp +2 -1
- package/cpp/rnwgpu/api/GPUCanvasContext.h +10 -0
- package/cpp/rnwgpu/api/GPUFeatures.h +1 -0
- package/cpp/rnwgpu/api/RNWebGPU.h +63 -5
- package/cpp/rnwgpu/api/VideoFrame.h +2 -2
- package/cpp/rnwgpu/api/descriptors/GPUCanvasConfiguration.h +18 -0
- package/cpp/rnwgpu/async/RuntimeContext.cpp +43 -27
- package/cpp/rnwgpu/async/RuntimeContext.h +19 -11
- package/lib/commonjs/Canvas.js +88 -43
- package/lib/commonjs/Canvas.js.map +1 -1
- package/lib/commonjs/WebGPUViewNativeComponent.js.map +1 -1
- package/lib/commonjs/WebGPUViewNativeComponent.web.js +3 -5
- package/lib/commonjs/WebGPUViewNativeComponent.web.js.map +1 -1
- package/lib/commonjs/WebPolyfillGPUModule.js +2 -0
- package/lib/commonjs/WebPolyfillGPUModule.js.map +1 -1
- package/lib/commonjs/importDevice.js +3 -2
- package/lib/commonjs/importDevice.js.map +1 -1
- package/lib/commonjs/mock.js +0 -1
- package/lib/commonjs/mock.js.map +1 -1
- package/lib/module/Canvas.js +88 -43
- package/lib/module/Canvas.js.map +1 -1
- package/lib/module/WebGPUViewNativeComponent.js.map +1 -1
- package/lib/module/WebGPUViewNativeComponent.web.js +3 -5
- package/lib/module/WebGPUViewNativeComponent.web.js.map +1 -1
- package/lib/module/WebPolyfillGPUModule.js +2 -0
- package/lib/module/WebPolyfillGPUModule.js.map +1 -1
- package/lib/module/importDevice.js +3 -2
- package/lib/module/importDevice.js.map +1 -1
- package/lib/module/mock.js +0 -1
- package/lib/module/mock.js.map +1 -1
- package/lib/typescript/lib/commonjs/Canvas.d.ts +1 -2
- package/lib/typescript/lib/commonjs/Canvas.d.ts.map +1 -1
- package/lib/typescript/lib/commonjs/WebGPUViewNativeComponent.web.d.ts.map +1 -1
- package/lib/typescript/lib/commonjs/importDevice.d.ts +3 -2
- package/lib/typescript/lib/commonjs/importDevice.d.ts.map +1 -1
- package/lib/typescript/lib/commonjs/mock.d.ts +1 -2
- package/lib/typescript/lib/commonjs/mock.d.ts.map +1 -1
- package/lib/typescript/lib/module/Canvas.d.ts +1 -2
- package/lib/typescript/lib/module/Canvas.d.ts.map +1 -1
- package/lib/typescript/lib/module/WebGPUViewNativeComponent.web.d.ts.map +1 -1
- package/lib/typescript/lib/module/importDevice.d.ts.map +1 -1
- package/lib/typescript/lib/module/mock.d.ts +1 -2
- package/lib/typescript/lib/module/mock.d.ts.map +1 -1
- package/lib/typescript/src/Canvas.d.ts +61 -29
- package/lib/typescript/src/Canvas.d.ts.map +1 -1
- package/lib/typescript/src/WebGPUViewNativeComponent.d.ts +3 -2
- package/lib/typescript/src/WebGPUViewNativeComponent.d.ts.map +1 -1
- package/lib/typescript/src/WebGPUViewNativeComponent.web.d.ts +3 -2
- package/lib/typescript/src/WebGPUViewNativeComponent.web.d.ts.map +1 -1
- package/lib/typescript/src/importDevice.d.ts +3 -2
- package/lib/typescript/src/importDevice.d.ts.map +1 -1
- package/lib/typescript/src/index.d.ts +2 -0
- package/lib/typescript/src/index.d.ts.map +1 -1
- package/lib/typescript/src/mock.d.ts +2 -2
- package/lib/typescript/src/mock.d.ts.map +1 -1
- package/package.json +3 -3
- package/src/Canvas.tsx +156 -81
- package/src/WebGPUViewNativeComponent.ts +6 -4
- package/src/WebGPUViewNativeComponent.web.ts +7 -5
- package/src/WebPolyfillGPUModule.ts +3 -0
- package/src/importDevice.ts +3 -2
- package/src/index.tsx +15 -4
- package/src/mock.ts +5 -7
|
@@ -9,8 +9,9 @@
|
|
|
9
9
|
* ```
|
|
10
10
|
*
|
|
11
11
|
* This is only sound when the exporting library links the same single Dawn
|
|
12
|
-
* copy as react-native-webgpu
|
|
13
|
-
*
|
|
12
|
+
* copy as react-native-webgpu (react-native-skia does). The device stays on
|
|
13
|
+
* its owner's Dawn instance and its async operations are pumped there, so the
|
|
14
|
+
* two libraries do not have to share an instance.
|
|
14
15
|
*/
|
|
15
16
|
export declare const importDevice: (pointer: bigint) => GPUDevice;
|
|
16
17
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"importDevice.d.ts","sourceRoot":"","sources":["../../../src/importDevice.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"importDevice.d.ts","sourceRoot":"","sources":["../../../src/importDevice.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AACH,eAAO,MAAM,YAAY,GAAI,SAAS,MAAM,KAAG,SAO9C,CAAC;AAEF;;;;;;;;;;GAUG;AACH,eAAO,MAAM,YAAY,GAAI,SAAS,MAAM,KAAG,UAO9C,CAAC"}
|
|
@@ -12,8 +12,10 @@ declare global {
|
|
|
12
12
|
var RNWebGPU: {
|
|
13
13
|
gpu: GPU;
|
|
14
14
|
fabric: boolean;
|
|
15
|
+
allocateContextId: () => number;
|
|
15
16
|
getNativeSurface: (contextId: number) => NativeCanvas;
|
|
16
17
|
MakeWebGPUCanvasContext: (contextId: number, width: number, height: number) => RNCanvasContext;
|
|
18
|
+
MakeWebGPUCanvasContextFromNativeWindow: (window: bigint, width: number, height: number) => RNCanvasContext;
|
|
17
19
|
destroyContext: (contextId: number) => void;
|
|
18
20
|
DecodeToUTF8: (buffer: NodeJS.ArrayBufferView | ArrayBuffer) => string;
|
|
19
21
|
createImageBitmap: typeof createImageBitmap;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.tsx"],"names":[],"mappings":"AAQA,OAAO,sBAAsB,CAAC;AAE9B,OAAO,KAAK,EACV,8BAA8B,EAC9B,wCAAwC,EACxC,sBAAsB,EACtB,gCAAgC,EAChC,8BAA8B,EAC9B,yBAAyB,EACzB,cAAc,EACd,wBAAwB,EACxB,wBAAwB,EACxB,kCAAkC,EAClC,sBAAsB,EACtB,gCAAgC,EAChC,oCAAoC,EACpC,YAAY,EACZ,eAAe,EACf,WAAW,EACX,gBAAgB,EAChB,sBAAsB,EACvB,MAAM,SAAS,CAAC;AAEjB,cAAc,QAAQ,CAAC;AACvB,cAAc,aAAa,CAAC;AAC5B,OAAO,EAAE,aAAa,EAAE,MAAM,WAAW,CAAC;AAC1C,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,oCAAoC,EACpC,wBAAwB,EACxB,kCAAkC,EAClC,0BAA0B,EAC1B,WAAW,EACX,wCAAwC,EACxC,gCAAgC,EAChC,sBAAsB,EACtB,sBAAsB,EACtB,8BAA8B,EAC9B,8BAA8B,EAC9B,yBAAyB,EACzB,6BAA6B,GAC9B,MAAM,SAAS,CAAC;AAEjB,OAAO,CAAC,MAAM,CAAC;IACb,UAAU,SAAS;QACjB,GAAG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AAC;QAC1B,iBAAiB,CAAC,UAAU,EAAE,wBAAwB,GAAG,cAAc,CAAC;QAMxE,yBAAyB,CACvB,MAAM,EAAE,gBAAgB,EACxB,UAAU,CAAC,EAAE,gCAAgC,GAC5C,sBAAsB,CAAC;QAC1B,iCAAiC,CAC/B,MAAM,EAAE,gBAAgB,EACxB,UAAU,CAAC,EAAE,wCAAwC,GACpD,8BAA8B,CAAC;KACnC;IAmBD,UAAU,QAAQ;QAChB,yBAAyB,CACvB,MAAM,EAAE,yBAAyB,EACjC,WAAW,EAAE,8BAA8B,GAC1C,OAAO,CAAC,IAAI,CAAC,CAAC;QAQjB,0BAA0B,CACxB,MAAM,EAAE,oCAAoC,EAC5C,WAAW,EAAE,4BAA4B,EACzC,QAAQ,EAAE,iBAAiB,GAC1B,SAAS,CAAC;KACd;IAID,UAAU,mBAAmB;QAC3B,WAAW,CAAC,EAAE,wBAAwB,CAAC;QAOvC,6BAA6B,CAAC,EAAE,OAAO,CAAC;KACzC;IAMD,UAAU,4BAA4B;QACpC,QAAQ,CAAC,EAAE,CAAC,GAAG,EAAE,GAAG,GAAG,GAAG,GAAG,CAAC;QAC9B,QAAQ,CAAC,EAAE,OAAO,CAAC;KACpB;IASD,UAAU,kBAAkB;QAC1B,OAAO,IAAI,IAAI,CAAC;KACjB;IAGD,SAAS,iBAAiB,CACxB,KAAK,EAAE,WAAW,GAAG,eAAe,EACpC,OAAO,CAAC,EAAE,kBAAkB,GAC3B,OAAO,CAAC,WAAW,CAAC,CAAC;CACzB"}
|
|
@@ -8,8 +8,8 @@ export declare const GPUTextureUsage: GPUTextureUsage;
|
|
|
8
8
|
export declare const GPUShaderStage: GPUShaderStage;
|
|
9
9
|
export declare const GPUColorWrite: GPUColorWrite;
|
|
10
10
|
export declare const GPUMapMode: GPUMapMode;
|
|
11
|
-
export type { AndroidCanvasProps,
|
|
12
|
-
export declare const Canvas: ({
|
|
11
|
+
export type { AndroidBackingView, AndroidCanvasProps, AndroidHardwareBufferViewProps, AndroidSurfaceViewProps, AndroidTextureViewProps, CanvasProps, CanvasRef, NativeCanvas, RNCanvasContext, } from "./Canvas";
|
|
12
|
+
export declare const Canvas: ({ android: _android, ref, ...props }: CanvasProps) => React.CElement<import("react-native").ViewProps, View>;
|
|
13
13
|
export declare const useCanvasRef: () => React.MutableRefObject<null>;
|
|
14
14
|
export declare const useSurface: () => {
|
|
15
15
|
ref: React.MutableRefObject<null>;
|
|
@@ -1 +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;AAEpC,OAAO,KAAK,EAAE,WAAW,EAAiC,MAAM,UAAU,CAAC;AAa3E,cAAc,WAAW,CAAC;AAM1B,eAAO,MAAM,cAAc,EAAE,cAW5B,CAAC;AAEF,eAAO,MAAM,eAAe,EAAE,eAO7B,CAAC;AAEF,eAAO,MAAM,cAAc,EAAE,cAI5B,CAAC;AAEF,eAAO,MAAM,aAAa,EAAE,aAM3B,CAAC;AAEF,eAAO,MAAM,UAAU,EAAE,UAGxB,CAAC;AAoBF,YAAY,EACV,kBAAkB,EAClB,kBAAkB,EAClB,WAAW,EACX,SAAS,EACT,YAAY,EACZ,eAAe,GAChB,MAAM,UAAU,CAAC;AAGlB,eAAO,MAAM,MAAM,GAAI,
|
|
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;AAEpC,OAAO,KAAK,EAAE,WAAW,EAAiC,MAAM,UAAU,CAAC;AAa3E,cAAc,WAAW,CAAC;AAM1B,eAAO,MAAM,cAAc,EAAE,cAW5B,CAAC;AAEF,eAAO,MAAM,eAAe,EAAE,eAO7B,CAAC;AAEF,eAAO,MAAM,cAAc,EAAE,cAI5B,CAAC;AAEF,eAAO,MAAM,aAAa,EAAE,aAM3B,CAAC;AAEF,eAAO,MAAM,UAAU,EAAE,UAGxB,CAAC;AAoBF,YAAY,EACV,kBAAkB,EAClB,kBAAkB,EAClB,8BAA8B,EAC9B,uBAAuB,EACvB,uBAAuB,EACvB,WAAW,EACX,SAAS,EACT,YAAY,EACZ,eAAe,GAChB,MAAM,UAAU,CAAC;AAGlB,eAAO,MAAM,MAAM,GAAI,sCAAsC,WAAW,2DASvE,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.19.0",
|
|
4
4
|
"description": "React Native WebGPU",
|
|
5
5
|
"main": "lib/commonjs/index",
|
|
6
6
|
"module": "lib/module/index",
|
|
@@ -24,7 +24,7 @@
|
|
|
24
24
|
"app.plugin.js",
|
|
25
25
|
"plugin/build/**"
|
|
26
26
|
],
|
|
27
|
-
"dawn": "chrome-
|
|
27
|
+
"dawn": "chrome-m157",
|
|
28
28
|
"androidMinSdkVersion": 26,
|
|
29
29
|
"scripts": {
|
|
30
30
|
"test": "NODE_OPTIONS='--experimental-require-module' jest -i",
|
|
@@ -111,7 +111,7 @@
|
|
|
111
111
|
"yargs": "^17.7.2"
|
|
112
112
|
},
|
|
113
113
|
"dependencies": {
|
|
114
|
-
"react-native-webgpu-dawn": "
|
|
114
|
+
"react-native-webgpu-dawn": "157.0.0"
|
|
115
115
|
},
|
|
116
116
|
"peerDependencies": {
|
|
117
117
|
"react": "*",
|
package/src/Canvas.tsx
CHANGED
|
@@ -7,116 +7,198 @@ import WebGPUNativeView from "./WebGPUViewNativeComponent";
|
|
|
7
7
|
|
|
8
8
|
export type { CanvasRef, NativeCanvas, RNCanvasContext } from "./types";
|
|
9
9
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
}
|
|
10
|
+
// Native hands out the id: it must be unique for the life of the process,
|
|
11
|
+
// not of the JS runtime, as the native surface registry outlives a reload.
|
|
12
|
+
const generateContextId = () => RNWebGPU.allocateContextId();
|
|
14
13
|
|
|
15
|
-
|
|
16
|
-
|
|
14
|
+
/** The Android view a canvas draws into, see {@link AndroidCanvasProps}. */
|
|
15
|
+
export type AndroidBackingView =
|
|
16
|
+
"TextureView" | "SurfaceView" | "HardwareBufferView";
|
|
17
17
|
|
|
18
|
-
/**
|
|
19
|
-
|
|
20
|
-
* chosen when the canvas mounts and kept: a later change is ignored, with a
|
|
21
|
-
* warning in development. Remount the canvas, with a `key`, to change it.
|
|
22
|
-
*/
|
|
23
|
-
export interface AndroidCanvasProps {
|
|
18
|
+
/** The options of a canvas backed by a `TextureView`, the default. */
|
|
19
|
+
export interface AndroidTextureViewProps {
|
|
24
20
|
/**
|
|
25
|
-
*
|
|
26
|
-
*
|
|
27
|
-
*
|
|
28
|
-
* a plain View that draws each frame's AHardwareBuffer inline with no extra
|
|
29
|
-
* copy) is opt-in and experimental; on older devices it uses `TextureView`.
|
|
30
|
-
* Read once, at mount.
|
|
21
|
+
* A `TextureView`: a regular view, composited like any other (parent
|
|
22
|
+
* transforms, clipping, alpha and z-order apply), at the price of an extra
|
|
23
|
+
* texture copy and typically a frame of latency. The default.
|
|
31
24
|
*/
|
|
32
|
-
|
|
25
|
+
backingView?: "TextureView";
|
|
33
26
|
/**
|
|
34
|
-
*
|
|
35
|
-
*
|
|
36
|
-
* place on Android 11 and later; read once, at mount, before that.
|
|
27
|
+
* Declares that the canvas covers every pixel of its bounds, so the UI
|
|
28
|
+
* toolkit skips blending the view. Defaults to false. Applied in place.
|
|
37
29
|
*/
|
|
38
|
-
|
|
30
|
+
opaque?: boolean;
|
|
39
31
|
}
|
|
40
32
|
|
|
41
|
-
|
|
33
|
+
/** The options of a canvas backed by a `SurfaceView`. */
|
|
34
|
+
export interface AndroidSurfaceViewProps {
|
|
35
|
+
/**
|
|
36
|
+
* A `SurfaceView`: each frame goes to the system compositor as its own
|
|
37
|
+
* layer, the fastest path, with no extra copy. It is not view content:
|
|
38
|
+
* parent transforms, clipping, rounded corners and z-order with sibling
|
|
39
|
+
* views do not apply to it.
|
|
40
|
+
*/
|
|
41
|
+
backingView: "SurfaceView";
|
|
42
42
|
/**
|
|
43
|
-
*
|
|
44
|
-
*
|
|
45
|
-
*
|
|
46
|
-
*
|
|
47
|
-
*
|
|
43
|
+
* Declares that the canvas covers every pixel of its bounds, so the
|
|
44
|
+
* compositor skips blending the layer and can show it through a hardware
|
|
45
|
+
* overlay. Defaults to true: a translucent `SurfaceView` blends against
|
|
46
|
+
* what is below the window, usually black, rather than the React Native
|
|
47
|
+
* views beneath it (pair it with `zOrderOnTop`). Applied in place.
|
|
48
48
|
*/
|
|
49
49
|
opaque?: boolean;
|
|
50
50
|
/**
|
|
51
|
-
*
|
|
52
|
-
*
|
|
53
|
-
*
|
|
54
|
-
|
|
51
|
+
* Composite above every React Native view in the window, ignoring
|
|
52
|
+
* `zIndex`. Defaults to false. Applied in place on Android 11 and later;
|
|
53
|
+
* read once, at mount, before that.
|
|
54
|
+
*/
|
|
55
|
+
zOrderOnTop?: boolean;
|
|
56
|
+
/**
|
|
57
|
+
* Composite above the other `SurfaceView`s below the window (video players,
|
|
58
|
+
* other canvases), while staying below the window itself. Defaults to
|
|
59
|
+
* false; `zOrderOnTop` takes precedence. Applied in place on Android 11 and
|
|
60
|
+
* later; read once, at mount, before that.
|
|
61
|
+
*/
|
|
62
|
+
zOrderMediaOverlay?: boolean;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/** The options of a canvas backed by a `HardwareBufferView`. */
|
|
66
|
+
export interface AndroidHardwareBufferViewProps {
|
|
67
|
+
/**
|
|
68
|
+
* A plain view drawing each frame's `AHardwareBuffer` inline: composited
|
|
69
|
+
* like a `TextureView`, without its extra copy. Opt-in and experimental,
|
|
70
|
+
* on Android 10 and later; below that the canvas uses a `TextureView`,
|
|
71
|
+
* with a warning in development. Always composites with alpha.
|
|
72
|
+
*/
|
|
73
|
+
backingView: "HardwareBufferView";
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* Android-only rendering options: the native view behind the canvas and its
|
|
78
|
+
* options. The view is created when the canvas mounts and kept: a change of
|
|
79
|
+
* `backingView` is ignored, with a warning in development; remount the canvas
|
|
80
|
+
* (with a `key`) to change it. `opaque` applies in place, and so do the
|
|
81
|
+
* z-order options on Android 11 and later. Ignored on iOS and web.
|
|
82
|
+
*/
|
|
83
|
+
export type AndroidCanvasProps =
|
|
84
|
+
| AndroidTextureViewProps
|
|
85
|
+
| AndroidSurfaceViewProps
|
|
86
|
+
| AndroidHardwareBufferViewProps;
|
|
87
|
+
|
|
88
|
+
export interface CanvasProps extends ViewProps {
|
|
89
|
+
/**
|
|
90
|
+
* Android-only rendering options: the native view behind the canvas and its
|
|
91
|
+
* options, see {@link AndroidCanvasProps}. Ignored on iOS and web.
|
|
55
92
|
*/
|
|
56
93
|
android?: AndroidCanvasProps;
|
|
57
94
|
ref?: React.Ref<CanvasRef>;
|
|
58
95
|
}
|
|
59
96
|
|
|
97
|
+
// The union read as one bag of options; which of them apply to the view is
|
|
98
|
+
// decided below, as it is on the native side.
|
|
99
|
+
type AndroidOptions = Partial<{
|
|
100
|
+
backingView: AndroidBackingView;
|
|
101
|
+
opaque: boolean;
|
|
102
|
+
zOrderOnTop: boolean;
|
|
103
|
+
zOrderMediaOverlay: boolean;
|
|
104
|
+
}>;
|
|
105
|
+
|
|
106
|
+
const options = (android?: AndroidCanvasProps): AndroidOptions =>
|
|
107
|
+
(android ?? {}) as AndroidOptions;
|
|
108
|
+
|
|
60
109
|
// Anything else reaching the native component would hit the generated
|
|
61
110
|
// string-enum parser, which aborts on unknown values.
|
|
62
|
-
const
|
|
63
|
-
|
|
64
|
-
):
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
// The props the Android backing view is chosen from when the canvas mounts.
|
|
72
|
-
interface BackingViewProps {
|
|
73
|
-
opaque: boolean;
|
|
74
|
-
android?: AndroidCanvasProps;
|
|
75
|
-
}
|
|
111
|
+
const resolveBackingView = (
|
|
112
|
+
android?: AndroidCanvasProps,
|
|
113
|
+
): AndroidBackingView => {
|
|
114
|
+
const { backingView } = options(android);
|
|
115
|
+
return backingView === "SurfaceView" || backingView === "HardwareBufferView"
|
|
116
|
+
? backingView
|
|
117
|
+
: "TextureView";
|
|
118
|
+
};
|
|
76
119
|
|
|
77
|
-
//
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
120
|
+
// Whether the canvas composites as opaque, see BackingViewKind.resolveOpaque():
|
|
121
|
+
// a SurfaceView is opaque unless asked otherwise, a TextureView is translucent
|
|
122
|
+
// unless asked otherwise, and a HardwareBufferView always composites with
|
|
123
|
+
// alpha.
|
|
124
|
+
const resolveOpaque = (android?: AndroidCanvasProps): boolean => {
|
|
125
|
+
const { opaque } = options(android);
|
|
126
|
+
switch (resolveBackingView(android)) {
|
|
127
|
+
case "SurfaceView":
|
|
128
|
+
return opaque !== false;
|
|
129
|
+
case "TextureView":
|
|
130
|
+
return opaque === true;
|
|
131
|
+
case "HardwareBufferView":
|
|
132
|
+
return false;
|
|
82
133
|
}
|
|
83
|
-
return opaque ? "SurfaceView" : "TextureView";
|
|
84
134
|
};
|
|
85
135
|
|
|
86
|
-
|
|
136
|
+
// The native props the `android` prop resolves to.
|
|
137
|
+
const androidNativeProps = (android?: AndroidCanvasProps) => {
|
|
138
|
+
const backingView = resolveBackingView(android);
|
|
139
|
+
const { zOrderOnTop, zOrderMediaOverlay } = options(android);
|
|
140
|
+
const surfaceView = backingView === "SurfaceView";
|
|
141
|
+
return {
|
|
142
|
+
androidBackingView: backingView,
|
|
143
|
+
androidOpaque: resolveOpaque(android),
|
|
144
|
+
androidZOrderOnTop: surfaceView && !!zOrderOnTop,
|
|
145
|
+
androidZOrderMediaOverlay: surfaceView && !!zOrderMediaOverlay,
|
|
146
|
+
};
|
|
147
|
+
};
|
|
148
|
+
|
|
149
|
+
const warnIgnoredChange = (prop: string) =>
|
|
87
150
|
console.warn(
|
|
88
151
|
`Ignoring a change of ${prop} on a mounted canvas: the backing view is ` +
|
|
89
152
|
"chosen when the canvas mounts. Remount the canvas (give it a new key) " +
|
|
90
153
|
"to change it.",
|
|
91
154
|
);
|
|
92
155
|
|
|
93
|
-
// Warns, in development on Android, about
|
|
94
|
-
//
|
|
95
|
-
//
|
|
96
|
-
//
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
156
|
+
// Warns, in development on Android, about an option a mounting canvas asks
|
|
157
|
+
// for that the native view cannot honour, and about a change of these props
|
|
158
|
+
// that the native view ignores: the backing view is created from them when
|
|
159
|
+
// the canvas mounts (see WebGPUView.java, whose setters these rules mirror).
|
|
160
|
+
// The native side only says so in logcat, which is not where a JS developer
|
|
161
|
+
// looks.
|
|
162
|
+
const useBackingViewWarning = (android?: AndroidCanvasProps) => {
|
|
163
|
+
const mount = useRef(android);
|
|
164
|
+
const prev = useRef(android);
|
|
165
|
+
useEffect(() => {
|
|
166
|
+
if (
|
|
167
|
+
__DEV__ &&
|
|
168
|
+
Platform.OS === "android" &&
|
|
169
|
+
resolveBackingView(mount.current) === "HardwareBufferView" &&
|
|
170
|
+
Number(Platform.Version) < 29
|
|
171
|
+
) {
|
|
172
|
+
console.warn(
|
|
173
|
+
"android.backingView: HardwareBufferView needs Android 10, the " +
|
|
174
|
+
"canvas uses a TextureView.",
|
|
175
|
+
);
|
|
176
|
+
}
|
|
177
|
+
}, []);
|
|
100
178
|
useEffect(() => {
|
|
101
179
|
if (__DEV__ && Platform.OS === "android") {
|
|
102
180
|
const { current: before } = prev;
|
|
103
|
-
if (
|
|
104
|
-
|
|
105
|
-
resolveSurfaceType(props.android?.surfaceType)
|
|
106
|
-
) {
|
|
107
|
-
warnIgnored("android.surfaceType");
|
|
181
|
+
if (resolveBackingView(before) !== resolveBackingView(android)) {
|
|
182
|
+
warnIgnoredChange("android.backingView");
|
|
108
183
|
}
|
|
109
184
|
// Only a SurfaceView has a z-order of its own, which Android 11 and
|
|
110
185
|
// later changes in place.
|
|
186
|
+
const zOrderAtMount =
|
|
187
|
+
resolveBackingView(mount.current) === "SurfaceView" &&
|
|
188
|
+
Number(Platform.Version) < 30;
|
|
189
|
+
const was = options(before);
|
|
190
|
+
const is = options(android);
|
|
191
|
+
if (zOrderAtMount && !!was.zOrderOnTop !== !!is.zOrderOnTop) {
|
|
192
|
+
warnIgnoredChange("android.zOrderOnTop");
|
|
193
|
+
}
|
|
111
194
|
if (
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
Number(Platform.Version) < 30
|
|
195
|
+
zOrderAtMount &&
|
|
196
|
+
!!was.zOrderMediaOverlay !== !!is.zOrderMediaOverlay
|
|
115
197
|
) {
|
|
116
|
-
|
|
198
|
+
warnIgnoredChange("android.zOrderMediaOverlay");
|
|
117
199
|
}
|
|
118
200
|
}
|
|
119
|
-
prev.current =
|
|
201
|
+
prev.current = android;
|
|
120
202
|
});
|
|
121
203
|
};
|
|
122
204
|
|
|
@@ -138,15 +220,10 @@ const measureLayout = (view: View) => {
|
|
|
138
220
|
return size;
|
|
139
221
|
};
|
|
140
222
|
|
|
141
|
-
export const Canvas = ({
|
|
142
|
-
opaque = true,
|
|
143
|
-
android,
|
|
144
|
-
ref,
|
|
145
|
-
...props
|
|
146
|
-
}: CanvasProps) => {
|
|
223
|
+
export const Canvas = ({ android, ref, ...props }: CanvasProps) => {
|
|
147
224
|
const viewRef = useRef<View>(null);
|
|
148
225
|
const [contextId, _] = useState(() => generateContextId());
|
|
149
|
-
useBackingViewWarning(
|
|
226
|
+
useBackingViewWarning(android);
|
|
150
227
|
// Retire the native registry entry for this contextId on unmount. When a
|
|
151
228
|
// native surface is still attached, this is a no-op and the native view's
|
|
152
229
|
// own teardown retires the entry instead — which keeps StrictMode's
|
|
@@ -190,9 +267,7 @@ export const Canvas = ({
|
|
|
190
267
|
<WebGPUNativeView
|
|
191
268
|
style={{ flex: 1 }}
|
|
192
269
|
contextId={contextId}
|
|
193
|
-
|
|
194
|
-
androidSurfaceType={resolveSurfaceType(android?.surfaceType)}
|
|
195
|
-
androidZOrderOnTop={!!android?.zOrderOnTop}
|
|
270
|
+
{...androidNativeProps(android)}
|
|
196
271
|
/>
|
|
197
272
|
</View>
|
|
198
273
|
);
|
|
@@ -7,12 +7,14 @@ import type { ViewProps } from "react-native";
|
|
|
7
7
|
|
|
8
8
|
export interface NativeProps extends ViewProps {
|
|
9
9
|
contextId: Int32;
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
"
|
|
13
|
-
"
|
|
10
|
+
// The `android` prop, resolved (see Canvas.tsx)
|
|
11
|
+
androidBackingView?: WithDefault<
|
|
12
|
+
"TextureView" | "SurfaceView" | "HardwareBufferView",
|
|
13
|
+
"TextureView"
|
|
14
14
|
>;
|
|
15
|
+
androidOpaque?: WithDefault<boolean, false>;
|
|
15
16
|
androidZOrderOnTop?: WithDefault<boolean, false>;
|
|
17
|
+
androidZOrderMediaOverlay?: WithDefault<boolean, false>;
|
|
16
18
|
}
|
|
17
19
|
|
|
18
20
|
// eslint-disable-next-line import/no-default-export
|
|
@@ -7,9 +7,11 @@ import { contextIdToId } from "./utils";
|
|
|
7
7
|
|
|
8
8
|
export interface NativeProps extends ViewProps {
|
|
9
9
|
contextId: Int32;
|
|
10
|
-
|
|
11
|
-
|
|
10
|
+
// The `android` prop, resolved: Android-only, never reaches the DOM
|
|
11
|
+
androidBackingView?: "TextureView" | "SurfaceView" | "HardwareBufferView";
|
|
12
|
+
androidOpaque?: boolean;
|
|
12
13
|
androidZOrderOnTop?: boolean;
|
|
14
|
+
androidZOrderMediaOverlay?: boolean;
|
|
13
15
|
}
|
|
14
16
|
|
|
15
17
|
// eslint-disable-next-line import/no-default-export
|
|
@@ -19,9 +21,10 @@ export default function WebGPUViewNativeComponent(
|
|
|
19
21
|
const {
|
|
20
22
|
contextId,
|
|
21
23
|
style,
|
|
22
|
-
|
|
23
|
-
|
|
24
|
+
androidBackingView: _androidBackingView,
|
|
25
|
+
androidOpaque: _androidOpaque,
|
|
24
26
|
androidZOrderOnTop: _androidZOrderOnTop,
|
|
27
|
+
androidZOrderMediaOverlay: _androidZOrderMediaOverlay,
|
|
25
28
|
...rest
|
|
26
29
|
} = props;
|
|
27
30
|
|
|
@@ -34,7 +37,6 @@ export default function WebGPUViewNativeComponent(
|
|
|
34
37
|
style: {
|
|
35
38
|
...styles.view,
|
|
36
39
|
...styles.flex1,
|
|
37
|
-
...(opaque ? { backgroundColor: "white" } : {}),
|
|
38
40
|
...(typeof style === "object" ? style : {}),
|
|
39
41
|
},
|
|
40
42
|
});
|
|
@@ -58,8 +58,11 @@ function makeWebGPUCanvasContext(
|
|
|
58
58
|
return Object.assign(context, { present: () => {} });
|
|
59
59
|
}
|
|
60
60
|
|
|
61
|
+
let nextContextId = 1;
|
|
62
|
+
|
|
61
63
|
// @ts-expect-error - polyfill for RNWebGPU native module
|
|
62
64
|
window.RNWebGPU = {
|
|
65
|
+
allocateContextId: () => nextContextId++,
|
|
63
66
|
getNativeSurface,
|
|
64
67
|
// Unlike native, this can return null; Canvas.getContext() is typed
|
|
65
68
|
// `RNCanvasContext | null` and passes it through.
|
package/src/importDevice.ts
CHANGED
|
@@ -9,8 +9,9 @@
|
|
|
9
9
|
* ```
|
|
10
10
|
*
|
|
11
11
|
* This is only sound when the exporting library links the same single Dawn
|
|
12
|
-
* copy as react-native-webgpu
|
|
13
|
-
*
|
|
12
|
+
* copy as react-native-webgpu (react-native-skia does). The device stays on
|
|
13
|
+
* its owner's Dawn instance and its async operations are pumped there, so the
|
|
14
|
+
* two libraries do not have to share an instance.
|
|
14
15
|
*/
|
|
15
16
|
export const importDevice = (pointer: bigint): GPUDevice => {
|
|
16
17
|
if (typeof RNWebGPU === "undefined") {
|
package/src/index.tsx
CHANGED
|
@@ -70,12 +70,23 @@ declare global {
|
|
|
70
70
|
var RNWebGPU: {
|
|
71
71
|
gpu: GPU;
|
|
72
72
|
fabric: boolean;
|
|
73
|
+
// The id a Canvas about to mount registers under, unique for the life of
|
|
74
|
+
// the process (the native surface registry outlives a reload).
|
|
75
|
+
allocateContextId: () => number;
|
|
73
76
|
getNativeSurface: (contextId: number) => NativeCanvas;
|
|
74
77
|
MakeWebGPUCanvasContext: (
|
|
75
78
|
contextId: number,
|
|
76
79
|
width: number,
|
|
77
80
|
height: number,
|
|
78
81
|
) => RNCanvasContext;
|
|
82
|
+
// A canvas context presenting to a native window that is not a WebGPU
|
|
83
|
+
// view, e.g. a MediaCodec encoder's input Surface: an ANativeWindow*
|
|
84
|
+
// (Android) or a CAMetalLayer* (Apple).
|
|
85
|
+
MakeWebGPUCanvasContextFromNativeWindow: (
|
|
86
|
+
window: bigint,
|
|
87
|
+
width: number,
|
|
88
|
+
height: number,
|
|
89
|
+
) => RNCanvasContext;
|
|
79
90
|
// Retires a canvas context; called by Canvas on unmount (the Canvas owns
|
|
80
91
|
// the native registry entry for its contextId).
|
|
81
92
|
destroyContext: (contextId: number) => void;
|
|
@@ -97,7 +108,7 @@ declare global {
|
|
|
97
108
|
createVideoFrameFromNativeBuffer: (pointer: bigint) => NativeVideoFrame;
|
|
98
109
|
// Wrap an externally created WGPUDevice pointer (e.g. Skia's Graphite
|
|
99
110
|
// device from Skia.getNativeDevice()) into a GPUDevice. Requires the
|
|
100
|
-
// exporter to
|
|
111
|
+
// exporter to link this process's single Dawn copy.
|
|
101
112
|
importDevice: (pointer: bigint) => GPUDevice;
|
|
102
113
|
// Wrap an externally created WGPUTexture pointer into a GPUTexture,
|
|
103
114
|
// taking ownership of one reference (pair with producers that return a
|
|
@@ -159,9 +170,9 @@ declare global {
|
|
|
159
170
|
// What is captured is what the platform renders for the view hierarchy
|
|
160
171
|
// (iOS: UIView.drawViewHierarchyInRect; Android API 29+: HardwareRenderer
|
|
161
172
|
// over the views' display lists, older: View.draw into a software canvas).
|
|
162
|
-
// On Android, SurfaceView content (a WebGPU Canvas with
|
|
163
|
-
// "SurfaceView"
|
|
164
|
-
// comes out blank;
|
|
173
|
+
// On Android, SurfaceView content (a WebGPU Canvas with
|
|
174
|
+
// `android={{ backingView: "SurfaceView" }}`, video players) is not part of
|
|
175
|
+
// the hierarchy and comes out blank; keep the default TextureView for a
|
|
165
176
|
// canvas that must be captured.
|
|
166
177
|
interface GPUQueue {
|
|
167
178
|
drawElementImageToTexture(
|
package/src/mock.ts
CHANGED
|
@@ -82,8 +82,11 @@ const NOT_AVAILABLE_UNDER_JEST =
|
|
|
82
82
|
"is not available under Jest - react-native-webgpu has no native implementation in tests (see react-native-webgpu/jestSetup.js)";
|
|
83
83
|
|
|
84
84
|
export type {
|
|
85
|
+
AndroidBackingView,
|
|
85
86
|
AndroidCanvasProps,
|
|
86
|
-
|
|
87
|
+
AndroidHardwareBufferViewProps,
|
|
88
|
+
AndroidSurfaceViewProps,
|
|
89
|
+
AndroidTextureViewProps,
|
|
87
90
|
CanvasProps,
|
|
88
91
|
CanvasRef,
|
|
89
92
|
NativeCanvas,
|
|
@@ -91,12 +94,7 @@ export type {
|
|
|
91
94
|
} from "./Canvas";
|
|
92
95
|
|
|
93
96
|
// Strip the same props the real Canvas keeps off its outer View.
|
|
94
|
-
export const Canvas = ({
|
|
95
|
-
opaque: _opaque,
|
|
96
|
-
android: _android,
|
|
97
|
-
ref,
|
|
98
|
-
...props
|
|
99
|
-
}: CanvasProps) => {
|
|
97
|
+
export const Canvas = ({ android: _android, ref, ...props }: CanvasProps) => {
|
|
100
98
|
React.useImperativeHandle(ref, () => ({
|
|
101
99
|
getContextId: () => -1,
|
|
102
100
|
getContext: (_contextName: "webgpu"): RNCanvasContext | null => null,
|