react-native-webgpu 0.25.0 → 0.27.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +9 -1
- package/android/CMakeLists.txt +2 -0
- package/cpp/rnwgpu/ArrayBuffer.h +47 -2
- package/cpp/rnwgpu/DawnEventPump.cpp +227 -0
- package/cpp/rnwgpu/DawnEventPump.h +173 -0
- package/cpp/rnwgpu/WebGPURuntime.cpp +6 -8
- package/cpp/rnwgpu/api/GPU.cpp +1 -1
- package/cpp/rnwgpu/api/GPUAdapter.cpp +1 -1
- package/cpp/rnwgpu/api/GPUBuffer.cpp +100 -27
- package/cpp/rnwgpu/api/GPUBuffer.h +55 -6
- package/cpp/rnwgpu/api/GPUDevice.cpp +57 -55
- package/cpp/rnwgpu/api/GPUDevice.h +6 -0
- package/cpp/rnwgpu/api/GPUQueue.cpp +7 -2
- package/cpp/rnwgpu/api/GPUQueue.h +8 -2
- package/cpp/rnwgpu/api/GPUShaderModule.cpp +1 -1
- package/cpp/rnwgpu/api/RNWebGPU.h +26 -5
- package/cpp/rnwgpu/api/descriptors/CreateNativeBufferFromPointerOptions.h +46 -0
- package/cpp/rnwgpu/api/descriptors/GPUExternalTextureDescriptor.h +21 -15
- package/cpp/rnwgpu/async/AsyncTaskHandle.h +3 -2
- package/cpp/rnwgpu/async/DeviceTicker.cpp +105 -0
- package/cpp/rnwgpu/async/DeviceTicker.h +71 -0
- package/cpp/rnwgpu/async/RuntimeContext.cpp +56 -70
- package/cpp/rnwgpu/async/RuntimeContext.h +37 -18
- package/lib/commonjs/NativeBufferView.js.map +1 -1
- package/lib/commonjs/NativeBufferViewNativeComponent.web.js +114 -0
- package/lib/commonjs/NativeBufferViewNativeComponent.web.js.map +1 -0
- package/lib/commonjs/WebPolyfillGPUModule.js +79 -0
- package/lib/commonjs/WebPolyfillGPUModule.js.map +1 -1
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/main/index.web.js +11 -0
- package/lib/commonjs/main/index.web.js.map +1 -1
- package/lib/commonjs/utils.js +29 -0
- package/lib/commonjs/utils.js.map +1 -1
- package/lib/commonjs/video.js +1 -1
- package/lib/commonjs/video.js.map +1 -1
- package/lib/module/NativeBufferView.js.map +1 -1
- package/lib/module/NativeBufferViewNativeComponent.web.js +107 -0
- package/lib/module/NativeBufferViewNativeComponent.web.js.map +1 -0
- package/lib/module/WebPolyfillGPUModule.js +80 -1
- package/lib/module/WebPolyfillGPUModule.js.map +1 -1
- package/lib/module/index.js.map +1 -1
- package/lib/module/main/index.web.js +1 -0
- package/lib/module/main/index.web.js.map +1 -1
- package/lib/module/utils.js +27 -0
- package/lib/module/utils.js.map +1 -1
- package/lib/module/video.js +1 -1
- package/lib/module/video.js.map +1 -1
- package/lib/typescript/lib/commonjs/NativeBufferViewNativeComponent.web.d.ts +4 -0
- package/lib/typescript/lib/commonjs/NativeBufferViewNativeComponent.web.d.ts.map +1 -0
- package/lib/typescript/lib/commonjs/utils.d.ts +2 -0
- package/lib/typescript/lib/commonjs/utils.d.ts.map +1 -1
- package/lib/typescript/lib/commonjs/video.d.ts +1 -1
- package/lib/typescript/lib/commonjs/video.d.ts.map +1 -1
- package/lib/typescript/lib/module/NativeBufferViewNativeComponent.web.d.ts +5 -0
- package/lib/typescript/lib/module/NativeBufferViewNativeComponent.web.d.ts.map +1 -0
- package/lib/typescript/lib/module/main/index.web.d.ts +1 -0
- package/lib/typescript/lib/module/utils.d.ts +2 -0
- package/lib/typescript/lib/module/utils.d.ts.map +1 -1
- package/lib/typescript/lib/module/video.d.ts +1 -1
- package/lib/typescript/lib/module/video.d.ts.map +1 -1
- package/lib/typescript/src/NativeBufferView.d.ts +6 -1
- package/lib/typescript/src/NativeBufferView.d.ts.map +1 -1
- package/lib/typescript/src/NativeBufferViewNativeComponent.web.d.ts +14 -0
- package/lib/typescript/src/NativeBufferViewNativeComponent.web.d.ts.map +1 -0
- package/lib/typescript/src/index.d.ts +3 -3
- package/lib/typescript/src/index.d.ts.map +1 -1
- package/lib/typescript/src/main/index.web.d.ts +1 -0
- package/lib/typescript/src/main/index.web.d.ts.map +1 -1
- package/lib/typescript/src/types.d.ts +12 -0
- package/lib/typescript/src/types.d.ts.map +1 -1
- package/lib/typescript/src/utils.d.ts +2 -0
- package/lib/typescript/src/utils.d.ts.map +1 -1
- package/lib/typescript/src/video.d.ts +2 -2
- package/lib/typescript/src/video.d.ts.map +1 -1
- package/package.json +1 -1
- package/scripts/prepare-apple-binaries.sh +9 -3
- package/src/NativeBufferView.tsx +6 -1
- package/src/NativeBufferViewNativeComponent.web.ts +119 -0
- package/src/WebPolyfillGPUModule.ts +75 -1
- package/src/index.tsx +7 -2
- package/src/main/index.web.tsx +1 -0
- package/src/types.ts +13 -0
- package/src/utils.ts +25 -0
- package/src/video.ts +6 -1
package/lib/module/utils.js
CHANGED
|
@@ -2,4 +2,31 @@
|
|
|
2
2
|
export function contextIdToId(contextId) {
|
|
3
3
|
return "rnwgpu-canvas-" + contextId;
|
|
4
4
|
}
|
|
5
|
+
|
|
6
|
+
// Only used on the web
|
|
7
|
+
export function nativeBufferViewIdToId(viewId) {
|
|
8
|
+
return "rnwgpu-native-buffer-view-" + viewId;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
// Only used on the web: fits the canvas of a NativeBufferView in its
|
|
12
|
+
// container according to its resize mode (data-resize-mode). The drawing
|
|
13
|
+
// buffer of the canvas is the presented buffer, in physical pixels.
|
|
14
|
+
export function layoutNativeBufferViewCanvas(canvas) {
|
|
15
|
+
const mode = canvas.dataset.resizeMode;
|
|
16
|
+
const {
|
|
17
|
+
style
|
|
18
|
+
} = canvas;
|
|
19
|
+
if (mode === "topLeft") {
|
|
20
|
+
// Not scaled: one pixel of the buffer on one pixel of the display. The
|
|
21
|
+
// container crops what overflows.
|
|
22
|
+
const dpr = window.devicePixelRatio || 1;
|
|
23
|
+
style.width = `${canvas.width / dpr}px`;
|
|
24
|
+
style.height = `${canvas.height / dpr}px`;
|
|
25
|
+
style.objectFit = "fill";
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
style.width = "100%";
|
|
29
|
+
style.height = "100%";
|
|
30
|
+
style.objectFit = mode === "contain" || mode === "cover" ? mode : "fill";
|
|
31
|
+
}
|
|
5
32
|
//# sourceMappingURL=utils.js.map
|
package/lib/module/utils.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["contextIdToId","contextId"],"sourceRoot":"../../src","sources":["utils.ts"],"mappings":"AAAA;AACA,OAAO,SAASA,aAAaA,CAACC,SAAiB,EAAE;EAC/C,OAAO,gBAAgB,GAAGA,SAAS;AACrC","ignoreList":[]}
|
|
1
|
+
{"version":3,"names":["contextIdToId","contextId","nativeBufferViewIdToId","viewId","layoutNativeBufferViewCanvas","canvas","mode","dataset","resizeMode","style","dpr","window","devicePixelRatio","width","height","objectFit"],"sourceRoot":"../../src","sources":["utils.ts"],"mappings":"AAAA;AACA,OAAO,SAASA,aAAaA,CAACC,SAAiB,EAAE;EAC/C,OAAO,gBAAgB,GAAGA,SAAS;AACrC;;AAEA;AACA,OAAO,SAASC,sBAAsBA,CAACC,MAAc,EAAE;EACrD,OAAO,4BAA4B,GAAGA,MAAM;AAC9C;;AAEA;AACA;AACA;AACA,OAAO,SAASC,4BAA4BA,CAACC,MAAyB,EAAE;EACtE,MAAMC,IAAI,GAAGD,MAAM,CAACE,OAAO,CAACC,UAAU;EACtC,MAAM;IAAEC;EAAM,CAAC,GAAGJ,MAAM;EACxB,IAAIC,IAAI,KAAK,SAAS,EAAE;IACtB;IACA;IACA,MAAMI,GAAG,GAAGC,MAAM,CAACC,gBAAgB,IAAI,CAAC;IACxCH,KAAK,CAACI,KAAK,GAAG,GAAGR,MAAM,CAACQ,KAAK,GAAGH,GAAG,IAAI;IACvCD,KAAK,CAACK,MAAM,GAAG,GAAGT,MAAM,CAACS,MAAM,GAAGJ,GAAG,IAAI;IACzCD,KAAK,CAACM,SAAS,GAAG,MAAM;IACxB;EACF;EACAN,KAAK,CAACI,KAAK,GAAG,MAAM;EACpBJ,KAAK,CAACK,MAAM,GAAG,MAAM;EACrBL,KAAK,CAACM,SAAS,GAAGT,IAAI,KAAK,SAAS,IAAIA,IAAI,KAAK,OAAO,GAAGA,IAAI,GAAG,MAAM;AAC1E","ignoreList":[]}
|
package/lib/module/video.js
CHANGED
|
@@ -42,7 +42,7 @@ export const createTestVideoPlayer = (source, options) => native("createTestVide
|
|
|
42
42
|
* VisionCamera's `frame.getNativeBuffer().pointer`) into a `NativeBuffer`
|
|
43
43
|
* that keeps it alive until released.
|
|
44
44
|
*/
|
|
45
|
-
export const createNativeBufferFromPointer = pointer => native("createNativeBufferFromPointer").createNativeBufferFromPointer(pointer);
|
|
45
|
+
export const createNativeBufferFromPointer = (pointer, options) => native("createNativeBufferFromPointer").createNativeBufferFromPointer(pointer, options);
|
|
46
46
|
|
|
47
47
|
/**
|
|
48
48
|
* Allocates a native frame of the given size filled with a test pattern (a
|
package/lib/module/video.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["native","name","RNWebGPU","Error","createTestVideoPlayer","source","options","pixelFormat","createNativeBufferFromPointer","pointer","createTestVideoFrame","width","height","createNativeBuffer"],"sourceRoot":"../../src","sources":["video.ts"],"mappings":"
|
|
1
|
+
{"version":3,"names":["native","name","RNWebGPU","Error","createTestVideoPlayer","source","options","pixelFormat","createNativeBufferFromPointer","pointer","createTestVideoFrame","width","height","createNativeBuffer"],"sourceRoot":"../../src","sources":["video.ts"],"mappings":"AAQA,MAAMA,MAAM,GAAIC,IAAY,IAAK;EAC/B,IAAI,OAAOC,QAAQ,KAAK,WAAW,EAAE;IACnC,MAAM,IAAIC,KAAK,CACb,kDAAkDF,IAAI,iBACxD,CAAC;EACH;EACA,OAAOC,QAAQ;AACjB,CAAC;;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,MAAME,qBAAqB,GAAGA,CACnCC,MAAc,EACdC,OAAsC,KAEtCN,MAAM,CAAC,uBAAuB,CAAC,CAACI,qBAAqB,CACnDC,MAAM,EACNC,OAAO,EAAEC,WACX,CAAC;;AAEH;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,MAAMC,6BAA6B,GAAGA,CAC3CC,OAAe,EACfH,OAA8C,KAE9CN,MAAM,CAAC,+BAA+B,CAAC,CAACQ,6BAA6B,CACnEC,OAAO,EACPH,OACF,CAAC;;AAEH;AACA;AACA;AACA;AACA;AACA,OAAO,MAAMI,oBAAoB,GAAGA,CAClCC,KAAa,EACbC,MAAc,KAEdZ,MAAM,CAAC,sBAAsB,CAAC,CAACU,oBAAoB,CAACC,KAAK,EAAEC,MAAM,CAAC;;AAEpE;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,MAAMC,kBAAkB,GAAGA,CAChCF,KAAa,EACbC,MAAc,EACdN,OAAmC,KAEnCN,MAAM,CAAC,oBAAoB,CAAC,CAACa,kBAAkB,CAACF,KAAK,EAAEC,MAAM,EAAEN,OAAO,CAAC","ignoreList":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"NativeBufferViewNativeComponent.web.d.ts","sourceRoot":"","sources":["../../../commonjs/NativeBufferViewNativeComponent.web.js"],"names":[],"mappings":";;AAgCA,kEAoEC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../commonjs/utils.js"],"names":[],"mappings":";
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../commonjs/utils.js"],"names":[],"mappings":";AASA,sDAEC;AAUD,gEAiBC;AAxBD,4DAEC"}
|
|
@@ -29,7 +29,7 @@ export const __esModule: boolean;
|
|
|
29
29
|
* native YUV layout, for `importExternalTexture()`.
|
|
30
30
|
*/
|
|
31
31
|
export function createTestVideoPlayer(source: any, options: any): import("../../src").VideoPlayer;
|
|
32
|
-
export function createNativeBufferFromPointer(pointer: any): import("../../src").NativeBuffer;
|
|
32
|
+
export function createNativeBufferFromPointer(pointer: any, options: any): import("../../src").NativeBuffer;
|
|
33
33
|
export function createTestVideoFrame(width: any, height: any): import("../../src").NativeBuffer;
|
|
34
34
|
export function createNativeBuffer(width: any, height: any, options: any): import("../../src").NativeBuffer;
|
|
35
35
|
//# sourceMappingURL=video.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"video.d.ts","sourceRoot":"","sources":["../../../commonjs/video.js"],"names":[],"mappings":";AAaA;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,kGAAsI;AAStI,
|
|
1
|
+
{"version":3,"file":"video.d.ts","sourceRoot":"","sources":["../../../commonjs/video.js"],"names":[],"mappings":";AAaA;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,kGAAsI;AAStI,4GAAmJ;AAQnJ,gGAAkH;AAUlH,4GAA8H"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export default function NativeBufferViewNativeComponent(props: any): React.FunctionComponentElement<Omit<import("react-native").ViewProps, "ref"> & {
|
|
2
|
+
ref?: React.Ref<import("react-native").ViewInstance> | undefined;
|
|
3
|
+
}>;
|
|
4
|
+
import React from "react";
|
|
5
|
+
//# sourceMappingURL=NativeBufferViewNativeComponent.web.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"NativeBufferViewNativeComponent.web.d.ts","sourceRoot":"","sources":["../../../module/NativeBufferViewNativeComponent.web.js"],"names":[],"mappings":"AAyBA;;GAoEC;kBA7FyD,OAAO"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../module/utils.js"],"names":[],"mappings":"AACA,sDAEC"}
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../module/utils.js"],"names":[],"mappings":"AACA,sDAEC;AAGD,4DAEC;AAKD,gEAiBC"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export function createTestVideoPlayer(source: any, options: any): import("../../src").VideoPlayer;
|
|
2
|
-
export function createNativeBufferFromPointer(pointer: any): import("../../src").NativeBuffer;
|
|
2
|
+
export function createNativeBufferFromPointer(pointer: any, options: any): import("../../src").NativeBuffer;
|
|
3
3
|
export function createTestVideoFrame(width: any, height: any): import("../../src").NativeBuffer;
|
|
4
4
|
export function createNativeBuffer(width: any, height: any, options: any): import("../../src").NativeBuffer;
|
|
5
5
|
//# sourceMappingURL=video.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"video.d.ts","sourceRoot":"","sources":["../../../module/video.js"],"names":[],"mappings":"AAoCO,kGAAsI;AAQtI,
|
|
1
|
+
{"version":3,"file":"video.d.ts","sourceRoot":"","sources":["../../../module/video.js"],"names":[],"mappings":"AAoCO,kGAAsI;AAQtI,4GAAmJ;AAOnJ,gGAAkH;AASlH,4GAA8H"}
|
|
@@ -43,8 +43,13 @@ export interface NativeBufferViewRef {
|
|
|
43
43
|
* half-written frame. Copy such a frame into a buffer from
|
|
44
44
|
* `createNativeBuffer()` (for instance by drawing it with WebGPU) and
|
|
45
45
|
* present the copy.
|
|
46
|
+
*
|
|
47
|
+
* On the web, the native buffer is a canvas image source, as in
|
|
48
|
+
* `drawImage()`: an `ImageBitmap`, an `OffscreenCanvas`, a `<canvas>`, a
|
|
49
|
+
* `VideoFrame`, or an image or video element. `done` is ignored, and the
|
|
50
|
+
* view keeps a copy of the pixels.
|
|
46
51
|
*/
|
|
47
|
-
present(frame: NativeBuffer, done?: {
|
|
52
|
+
present(frame: NativeBuffer | CanvasImageSource, done?: {
|
|
48
53
|
fences: GPUSharedFenceState[];
|
|
49
54
|
} | null): void;
|
|
50
55
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"NativeBufferView.d.ts","sourceRoot":"","sources":["../../../src/NativeBufferView.tsx"],"names":[],"mappings":"AAAA,OAAO,KAON,MAAM,OAAO,CAAC;AACf,OAAO,KAAK,EAAwB,SAAS,EAAE,MAAM,cAAc,CAAC;AAGpE,OAAO,KAAK,EAAE,mBAAmB,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAEjE;;;;;;;;;;GAUG;AACH,MAAM,MAAM,sBAAsB,GAChC,SAAS,GAAG,SAAS,GAAG,OAAO,GAAG,SAAS,CAAC;AAE9C,iCAAiC;AACjC,MAAM,WAAW,qBAAqB;IACpC,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;CAChB;AAED,MAAM,WAAW,mBAAmB;IAClC;;;OAGG;IACH,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB
|
|
1
|
+
{"version":3,"file":"NativeBufferView.d.ts","sourceRoot":"","sources":["../../../src/NativeBufferView.tsx"],"names":[],"mappings":"AAAA,OAAO,KAON,MAAM,OAAO,CAAC;AACf,OAAO,KAAK,EAAwB,SAAS,EAAE,MAAM,cAAc,CAAC;AAGpE,OAAO,KAAK,EAAE,mBAAmB,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAEjE;;;;;;;;;;GAUG;AACH,MAAM,MAAM,sBAAsB,GAChC,SAAS,GAAG,SAAS,GAAG,OAAO,GAAG,SAAS,CAAC;AAE9C,iCAAiC;AACjC,MAAM,WAAW,qBAAqB;IACpC,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;CAChB;AAED,MAAM,WAAW,mBAAmB;IAClC;;;OAGG;IACH,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB;;;;;;;;;;;;;;;;;;;;;;;;OAwBG;IACH,OAAO,CACL,KAAK,EAAE,YAAY,GAAG,iBAAiB,EACvC,IAAI,CAAC,EAAE;QAAE,MAAM,EAAE,mBAAmB,EAAE,CAAA;KAAE,GAAG,IAAI,GAC9C,IAAI,CAAC;CACT;AAED,MAAM,WAAW,qBAAsB,SAAQ,SAAS;IACtD,mEAAmE;IACnE,UAAU,CAAC,EAAE,sBAAsB,CAAC;IACpC;;;;;OAKG;IACH,iBAAiB,CAAC,EAAE,CAAC,IAAI,EAAE,qBAAqB,KAAK,IAAI,CAAC;IAC1D,GAAG,CAAC,EAAE,KAAK,CAAC,GAAG,CAAC,mBAAmB,CAAC,CAAC;CACtC;AAED;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,eAAO,MAAM,gBAAgB,GAAI,kDAK9B,qBAAqB,sBAwCvB,CAAC;AAEF;;;;;;GAMG;AACH,eAAO,MAAM,mBAAmB,GAAI,mBAAgB;;8BAMzC,qBAAqB;CAoC/B,CAAC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import type { CodegenTypes, ViewProps } from "react-native";
|
|
3
|
+
type PixelSizeChangeEvent = Readonly<{
|
|
4
|
+
width: CodegenTypes.Int32;
|
|
5
|
+
height: CodegenTypes.Int32;
|
|
6
|
+
}>;
|
|
7
|
+
export interface NativeProps extends ViewProps {
|
|
8
|
+
viewId: CodegenTypes.Int32;
|
|
9
|
+
resizeMode?: CodegenTypes.WithDefault<"stretch" | "contain" | "cover" | "topLeft", "stretch">;
|
|
10
|
+
onPixelSizeChange?: CodegenTypes.DirectEventHandler<PixelSizeChangeEvent>;
|
|
11
|
+
}
|
|
12
|
+
export default function NativeBufferViewNativeComponent(props: NativeProps): React.JSX.Element;
|
|
13
|
+
export {};
|
|
14
|
+
//# sourceMappingURL=NativeBufferViewNativeComponent.web.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"NativeBufferViewNativeComponent.web.d.ts","sourceRoot":"","sources":["../../../src/NativeBufferViewNativeComponent.web.ts"],"names":[],"mappings":"AAAA,OAAO,KAA6C,MAAM,OAAO,CAAC;AAElE,OAAO,KAAK,EAAE,YAAY,EAAgB,SAAS,EAAE,MAAM,cAAc,CAAC;AAI1E,KAAK,oBAAoB,GAAG,QAAQ,CAAC;IACnC,KAAK,EAAE,YAAY,CAAC,KAAK,CAAC;IAC1B,MAAM,EAAE,YAAY,CAAC,KAAK,CAAC;CAC5B,CAAC,CAAC;AAEH,MAAM,WAAW,WAAY,SAAQ,SAAS;IAC5C,MAAM,EAAE,YAAY,CAAC,KAAK,CAAC;IAC3B,UAAU,CAAC,EAAE,YAAY,CAAC,WAAW,CACnC,SAAS,GAAG,SAAS,GAAG,OAAO,GAAG,SAAS,EAC3C,SAAS,CACV,CAAC;IACF,iBAAiB,CAAC,EAAE,YAAY,CAAC,kBAAkB,CAAC,oBAAoB,CAAC,CAAC;CAC3E;AAqBD,MAAM,CAAC,OAAO,UAAU,+BAA+B,CACrD,KAAK,EAAE,WAAW,GACjB,KAAK,CAAC,GAAG,CAAC,OAAO,CA+DnB"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import "./main/installNative";
|
|
2
|
-
import type { GPUDrawElementImageDestination, GPUDrawElementImageSource, GPUSharedFence, GPUSharedFenceDescriptor, GPUSharedFenceState, CreateNativeBufferOptions, GPUDawnTogglesDescriptor, GPUNativeExternalTextureDescriptor, GPUSharedTextureMemory, GPUSharedTextureMemoryDescriptor, GPUCopyExternalNativeFrameSourceInfo, NativeCanvas, RNCanvasContext, VideoPlayer, NativeBuffer, NativeBufferPixelFormat } from "./types";
|
|
2
|
+
import type { GPUDrawElementImageDestination, GPUDrawElementImageSource, GPUSharedFence, GPUSharedFenceDescriptor, GPUSharedFenceState, CreateNativeBufferOptions, CreateNativeBufferFromPointerOptions, GPUDawnTogglesDescriptor, GPUNativeExternalTextureDescriptor, GPUSharedTextureMemory, GPUSharedTextureMemoryDescriptor, GPUCopyExternalNativeFrameSourceInfo, NativeCanvas, RNCanvasContext, VideoPlayer, NativeBuffer, NativeBufferPixelFormat } from "./types";
|
|
3
3
|
export * from "./main";
|
|
4
4
|
export * from "./constants";
|
|
5
5
|
export { installWebGPU } from "./install";
|
|
@@ -26,7 +26,7 @@ declare global {
|
|
|
26
26
|
createImageBitmap: typeof createImageBitmap;
|
|
27
27
|
loadVideoFrame: (path: string) => NativeBuffer;
|
|
28
28
|
createTestVideoFrame: (width: number, height: number, pixelFormat?: NativeBufferPixelFormat) => NativeBuffer;
|
|
29
|
-
createNativeBufferFromPointer: (pointer: bigint) => NativeBuffer;
|
|
29
|
+
createNativeBufferFromPointer: (pointer: bigint, options?: CreateNativeBufferFromPointerOptions) => NativeBuffer;
|
|
30
30
|
importDevice: (pointer: bigint) => GPUDevice;
|
|
31
31
|
purgeGpuResources: () => void;
|
|
32
32
|
adoptTexture: (pointer: bigint) => GPUTexture;
|
|
@@ -36,7 +36,7 @@ declare global {
|
|
|
36
36
|
allocateNativeBufferViewId: () => number;
|
|
37
37
|
retainNativeBufferView: (viewId: number) => void;
|
|
38
38
|
releaseNativeBufferView: (viewId: number) => void;
|
|
39
|
-
presentNativeBuffer: (viewId: number, frame: NativeBuffer, done?: {
|
|
39
|
+
presentNativeBuffer: (viewId: number, frame: NativeBuffer | CanvasImageSource, done?: {
|
|
40
40
|
fences: GPUSharedFenceState[];
|
|
41
41
|
} | null) => void;
|
|
42
42
|
};
|
|
@@ -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,yBAAyB,EACzB,cAAc,EACd,wBAAwB,EACxB,mBAAmB,EACnB,yBAAyB,EACzB,wBAAwB,EACxB,kCAAkC,EAClC,sBAAsB,EACtB,gCAAgC,EAChC,oCAAoC,EACpC,YAAY,EACZ,eAAe,EACf,WAAW,EACX,YAAY,EACZ,uBAAuB,EACxB,MAAM,SAAS,CAAC;AAEjB,cAAc,QAAQ,CAAC;AACvB,cAAc,aAAa,CAAC;AAC5B,OAAO,EAAE,aAAa,EAAE,MAAM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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"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.web.d.ts","sourceRoot":"","sources":["../../../../src/main/index.web.tsx"],"names":[],"mappings":"AAAA,OAAO,iBAAiB,CAAC;AAEzB,cAAc,WAAW,CAAC;AAC1B,cAAc,cAAc,CAAC;AAC7B,cAAc,8BAA8B,CAAC;AAC7C,cAAc,UAAU,CAAC;AACzB,cAAc,sBAAsB,CAAC;AACrC,cAAc,YAAY,CAAC;AAC3B,cAAc,sBAAsB,CAAC;AACrC,cAAc,UAAU,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.web.d.ts","sourceRoot":"","sources":["../../../../src/main/index.web.tsx"],"names":[],"mappings":"AAAA,OAAO,iBAAiB,CAAC;AAEzB,cAAc,WAAW,CAAC;AAC1B,cAAc,qBAAqB,CAAC;AACpC,cAAc,cAAc,CAAC;AAC7B,cAAc,8BAA8B,CAAC;AAC7C,cAAc,UAAU,CAAC;AACzB,cAAc,sBAAsB,CAAC;AACrC,cAAc,YAAY,CAAC;AAC3B,cAAc,sBAAsB,CAAC;AACrC,cAAc,UAAU,CAAC"}
|
|
@@ -137,6 +137,18 @@ export interface GPUSharedTextureMemory {
|
|
|
137
137
|
endAccess(texture: GPUTexture): GPUSharedTextureMemoryEndAccessState;
|
|
138
138
|
destroy(): void;
|
|
139
139
|
}
|
|
140
|
+
/**
|
|
141
|
+
* The options of `createNativeBufferFromPointer()`.
|
|
142
|
+
*/
|
|
143
|
+
export interface CreateNativeBufferFromPointerOptions {
|
|
144
|
+
/**
|
|
145
|
+
* How to read a YUV buffer that carries no color information of its own
|
|
146
|
+
* (an AHardwareBuffer from a MediaCodec ImageReader, for instance), as
|
|
147
|
+
* `sourceColorSpace` in `importExternalTexture()`. The members it sets
|
|
148
|
+
* replace what the buffer says.
|
|
149
|
+
*/
|
|
150
|
+
colorSpace?: NativeBufferColorSpace;
|
|
151
|
+
}
|
|
140
152
|
/**
|
|
141
153
|
* The options of `createNativeBuffer()`. The buffer holds premultiplied
|
|
142
154
|
* pixels.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/types.ts"],"names":[],"mappings":"AAAA,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;I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AAE,oBAAoB,GAAG,UAAU,CAAC;IAM7D,WAAW,CACT,OAAO,EAAE,UAAU,EACnB,WAAW,EAAE,OAAO,EACpB,MAAM,CAAC,EAAE,mBAAmB,EAAE,GAC7B,IAAI,CAAC;IAGR,SAAS,CAAC,OAAO,EAAE,UAAU,GAAG,oCAAoC,CAAC;IAMrE,OAAO,IAAI,IAAI,CAAC;CACjB;AAED;;GAEG;AACH,MAAM,WAAW,oCAAoC;IACnD;;;;;OAKG;IACH,UAAU,CAAC,EAAE,sBAAsB,CAAC;CACrC;AAED;;;GAGG;AACH,MAAM,WAAW,yBAAyB;IACxC;;;;;OAKG;IACH,MAAM,CAAC,EAAE,YAAY,GAAG,YAAY,GAAG,aAAa,CAAC;IACrD,yDAAyD;IACzD,UAAU,CAAC,EAAE,oBAAoB,CAAC;CACnC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../src/utils.ts"],"names":[],"mappings":"AACA,wBAAgB,aAAa,CAAC,SAAS,EAAE,MAAM,UAE9C"}
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../src/utils.ts"],"names":[],"mappings":"AACA,wBAAgB,aAAa,CAAC,SAAS,EAAE,MAAM,UAE9C;AAGD,wBAAgB,sBAAsB,CAAC,MAAM,EAAE,MAAM,UAEpD;AAKD,wBAAgB,4BAA4B,CAAC,MAAM,EAAE,iBAAiB,QAerE"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { CreateNativeBufferOptions, CreateTestVideoPlayerOptions, NativeBuffer, VideoPlayer } from "./types";
|
|
1
|
+
import type { CreateNativeBufferFromPointerOptions, CreateNativeBufferOptions, CreateTestVideoPlayerOptions, NativeBuffer, VideoPlayer } from "./types";
|
|
2
2
|
/**
|
|
3
3
|
* Decodes a video into native frames the GPU samples without any copy.
|
|
4
4
|
*
|
|
@@ -35,7 +35,7 @@ export declare const createTestVideoPlayer: (source: string, options?: CreateTes
|
|
|
35
35
|
* VisionCamera's `frame.getNativeBuffer().pointer`) into a `NativeBuffer`
|
|
36
36
|
* that keeps it alive until released.
|
|
37
37
|
*/
|
|
38
|
-
export declare const createNativeBufferFromPointer: (pointer: bigint) => NativeBuffer;
|
|
38
|
+
export declare const createNativeBufferFromPointer: (pointer: bigint, options?: CreateNativeBufferFromPointerOptions) => NativeBuffer;
|
|
39
39
|
/**
|
|
40
40
|
* Allocates a native frame of the given size filled with a test pattern (a
|
|
41
41
|
* red/green gradient with diagonal stripes in the blue channel), for examples
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"video.d.ts","sourceRoot":"","sources":["../../../src/video.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,yBAAyB,EACzB,4BAA4B,EAC5B,YAAY,EACZ,WAAW,EACZ,MAAM,SAAS,CAAC;AAWjB;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,eAAO,MAAM,qBAAqB,GAChC,QAAQ,MAAM,EACd,UAAU,4BAA4B,KACrC,WAIA,CAAC;AAEJ;;;;;GAKG;AACH,eAAO,MAAM,6BAA6B,
|
|
1
|
+
{"version":3,"file":"video.d.ts","sourceRoot":"","sources":["../../../src/video.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,oCAAoC,EACpC,yBAAyB,EACzB,4BAA4B,EAC5B,YAAY,EACZ,WAAW,EACZ,MAAM,SAAS,CAAC;AAWjB;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,eAAO,MAAM,qBAAqB,GAChC,QAAQ,MAAM,EACd,UAAU,4BAA4B,KACrC,WAIA,CAAC;AAEJ;;;;;GAKG;AACH,eAAO,MAAM,6BAA6B,GACxC,SAAS,MAAM,EACf,UAAU,oCAAoC,KAC7C,YAIA,CAAC;AAEJ;;;;GAIG;AACH,eAAO,MAAM,oBAAoB,GAC/B,OAAO,MAAM,EACb,QAAQ,MAAM,KACb,YACiE,CAAC;AAErE;;;;;;GAMG;AACH,eAAO,MAAM,kBAAkB,GAC7B,OAAO,MAAM,EACb,QAAQ,MAAM,EACd,UAAU,yBAAyB,KAClC,YACsE,CAAC"}
|
package/package.json
CHANGED
|
@@ -201,7 +201,7 @@ copy_library() {
|
|
|
201
201
|
# The caller holds the assembly lock across both assembly and linker staging.
|
|
202
202
|
assemble_module() {
|
|
203
203
|
local root="$CONTAINERS/$MODULE" library existing=true temporary previous='' old_archs platform variant ignored deployment
|
|
204
|
-
local signature_file="$CONTAINERS/$MODULE/.slices/$SDK.
|
|
204
|
+
local signature_file="$CONTAINERS/$MODULE/.slices/$SDK.stamp"
|
|
205
205
|
CONTAINER_ROOT="$root"
|
|
206
206
|
for library in "${MODULE_LIBRARIES[@]}"; do
|
|
207
207
|
if [[ ! -f "$root/${library%.a}.xcframework/$META_IDENTIFIER/$library" || ! -f "$root/${library%.a}.xcframework/Info.plist" ]]; then existing=false; fi
|
|
@@ -217,6 +217,7 @@ assemble_module() {
|
|
|
217
217
|
previous="$platform-$(printf '%s\n' "$old_archs" | LC_ALL=C sort | paste -sd _ -)${variant:+-$variant}"
|
|
218
218
|
fi
|
|
219
219
|
mkdir -p "$temporary/.slices"
|
|
220
|
+
rm -f "$temporary/.slices/$SDK.signature"
|
|
220
221
|
cp "$SOURCE_DIRECTORY/metadata.json" "$temporary/.slices/$SDK.json"
|
|
221
222
|
for library in "${MODULE_LIBRARIES[@]}"; do
|
|
222
223
|
local container="$temporary/${library%.a}.xcframework"
|
|
@@ -225,7 +226,7 @@ assemble_module() {
|
|
|
225
226
|
copy_library "$SOURCE_DIRECTORY/$library" "$container/$META_IDENTIFIER/$library"
|
|
226
227
|
write_xcframework_plist "$container" "$library" "$temporary/.slices"
|
|
227
228
|
done
|
|
228
|
-
printf '%s\n' "$SOURCE_SIGNATURE" > "$temporary/.slices/$SDK.
|
|
229
|
+
printf '%s\n' "$SOURCE_SIGNATURE" > "$temporary/.slices/$SDK.stamp"
|
|
229
230
|
replace_directory "$temporary" "$root"
|
|
230
231
|
note "Prepared $SDK XCFramework slices ($(printf '%s' "$META_ARCHS" | tr '\n' ' '))"
|
|
231
232
|
}
|
|
@@ -237,10 +238,15 @@ assemble_module() {
|
|
|
237
238
|
# rather than dynamic frameworks copied into the app's Frameworks directory.
|
|
238
239
|
# Build-product stamps include SDK/version/source identity, avoiding equal-size
|
|
239
240
|
# archives from another platform and unnecessary copies on incremental builds.
|
|
241
|
+
# Stamps must never use the .signature extension: Xcode collects *.signature
|
|
242
|
+
# files from build products into the archive, and App Store Connect rejects
|
|
243
|
+
# them as invalid XCFramework code signatures (ITMS-91063).
|
|
240
244
|
stage_module() {
|
|
241
|
-
local library destination temporary stamp="$OUTPUT/.rnwgpu-$MODULE.
|
|
245
|
+
local library destination temporary stamp="$OUTPUT/.rnwgpu-$MODULE.stamp"
|
|
242
246
|
local signature="$SDK:$VERSION:$SOURCE_SIGNATURE" name
|
|
243
247
|
mkdir -p "$OUTPUT"
|
|
248
|
+
# Archive build folders persist across runs; drop stamps from older releases.
|
|
249
|
+
rm -f "$OUTPUT/.rnwgpu-$MODULE.signature"
|
|
244
250
|
for library in "${MODULE_LIBRARIES[@]}"; do
|
|
245
251
|
name="${library#lib}"
|
|
246
252
|
destination="$OUTPUT/librnwgpu_$name"
|
package/src/NativeBufferView.tsx
CHANGED
|
@@ -56,9 +56,14 @@ export interface NativeBufferViewRef {
|
|
|
56
56
|
* half-written frame. Copy such a frame into a buffer from
|
|
57
57
|
* `createNativeBuffer()` (for instance by drawing it with WebGPU) and
|
|
58
58
|
* present the copy.
|
|
59
|
+
*
|
|
60
|
+
* On the web, the native buffer is a canvas image source, as in
|
|
61
|
+
* `drawImage()`: an `ImageBitmap`, an `OffscreenCanvas`, a `<canvas>`, a
|
|
62
|
+
* `VideoFrame`, or an image or video element. `done` is ignored, and the
|
|
63
|
+
* view keeps a copy of the pixels.
|
|
59
64
|
*/
|
|
60
65
|
present(
|
|
61
|
-
frame: NativeBuffer,
|
|
66
|
+
frame: NativeBuffer | CanvasImageSource,
|
|
62
67
|
done?: { fences: GPUSharedFenceState[] } | null,
|
|
63
68
|
): void;
|
|
64
69
|
}
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
import React, { useEffect, useLayoutEffect, useRef } from "react";
|
|
2
|
+
import { StyleSheet, View } from "react-native";
|
|
3
|
+
import type { CodegenTypes, HostInstance, ViewProps } from "react-native";
|
|
4
|
+
|
|
5
|
+
import { layoutNativeBufferViewCanvas, nativeBufferViewIdToId } from "./utils";
|
|
6
|
+
|
|
7
|
+
type PixelSizeChangeEvent = Readonly<{
|
|
8
|
+
width: CodegenTypes.Int32;
|
|
9
|
+
height: CodegenTypes.Int32;
|
|
10
|
+
}>;
|
|
11
|
+
|
|
12
|
+
export interface NativeProps extends ViewProps {
|
|
13
|
+
viewId: CodegenTypes.Int32;
|
|
14
|
+
resizeMode?: CodegenTypes.WithDefault<
|
|
15
|
+
"stretch" | "contain" | "cover" | "topLeft",
|
|
16
|
+
"stretch"
|
|
17
|
+
>;
|
|
18
|
+
onPixelSizeChange?: CodegenTypes.DirectEventHandler<PixelSizeChangeEvent>;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
// The size of `entry` in physical pixels. devicePixelContentBoxSize is the
|
|
22
|
+
// size the browser snapped to the pixel grid; without it (Safari), the CSS
|
|
23
|
+
// size times the pixel ratio is the closest there is.
|
|
24
|
+
const pixelSizeOf = (entry: ResizeObserverEntry) => {
|
|
25
|
+
const box = entry.devicePixelContentBoxSize?.[0];
|
|
26
|
+
if (box) {
|
|
27
|
+
return { width: box.inlineSize, height: box.blockSize };
|
|
28
|
+
}
|
|
29
|
+
const dpr = window.devicePixelRatio || 1;
|
|
30
|
+
return {
|
|
31
|
+
width: Math.round(entry.contentRect.width * dpr),
|
|
32
|
+
height: Math.round(entry.contentRect.height * dpr),
|
|
33
|
+
};
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
// The web counterpart of the native view: a container that takes the props of
|
|
37
|
+
// a View, and a canvas that holds a copy of the last buffer presented
|
|
38
|
+
// (RNWebGPU.presentNativeBuffer in WebPolyfillGPUModule.ts draws into it).
|
|
39
|
+
// eslint-disable-next-line import/no-default-export
|
|
40
|
+
export default function NativeBufferViewNativeComponent(
|
|
41
|
+
props: NativeProps,
|
|
42
|
+
): React.JSX.Element {
|
|
43
|
+
const { viewId, resizeMode, onPixelSizeChange, style, ...rest } = props;
|
|
44
|
+
const container = useRef<HostInstance>(null);
|
|
45
|
+
const canvas = useRef<HTMLCanvasElement>(null);
|
|
46
|
+
const onPixelSizeChangeRef = useRef(onPixelSizeChange);
|
|
47
|
+
onPixelSizeChangeRef.current = onPixelSizeChange;
|
|
48
|
+
|
|
49
|
+
// A layout effect, so the mode is in place before the first present.
|
|
50
|
+
useLayoutEffect(() => {
|
|
51
|
+
if (canvas.current) {
|
|
52
|
+
canvas.current.dataset.resizeMode = resizeMode ?? "stretch";
|
|
53
|
+
layoutNativeBufferViewCanvas(canvas.current);
|
|
54
|
+
}
|
|
55
|
+
}, [resizeMode]);
|
|
56
|
+
|
|
57
|
+
useEffect(() => {
|
|
58
|
+
// On react-native-web, the ref of a View is its DOM element.
|
|
59
|
+
const element = container.current as unknown as Element | null;
|
|
60
|
+
if (!element || typeof ResizeObserver === "undefined") {
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
let width = 0;
|
|
64
|
+
let height = 0;
|
|
65
|
+
const observer = new ResizeObserver((entries) => {
|
|
66
|
+
const entry = entries[entries.length - 1];
|
|
67
|
+
if (!entry) {
|
|
68
|
+
return;
|
|
69
|
+
}
|
|
70
|
+
// A change of pixel ratio changes what "not scaled" means.
|
|
71
|
+
if (canvas.current) {
|
|
72
|
+
layoutNativeBufferViewCanvas(canvas.current);
|
|
73
|
+
}
|
|
74
|
+
const size = pixelSizeOf(entry);
|
|
75
|
+
if (
|
|
76
|
+
size.width <= 0 ||
|
|
77
|
+
size.height <= 0 ||
|
|
78
|
+
(size.width === width && size.height === height)
|
|
79
|
+
) {
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
82
|
+
({ width, height } = size);
|
|
83
|
+
onPixelSizeChangeRef.current?.({
|
|
84
|
+
nativeEvent: size,
|
|
85
|
+
} as Parameters<NonNullable<NativeProps["onPixelSizeChange"]>>[0]);
|
|
86
|
+
});
|
|
87
|
+
try {
|
|
88
|
+
observer.observe(element, { box: "device-pixel-content-box" });
|
|
89
|
+
} catch {
|
|
90
|
+
// No device-pixel-content-box (Safari).
|
|
91
|
+
observer.observe(element);
|
|
92
|
+
}
|
|
93
|
+
return () => observer.disconnect();
|
|
94
|
+
}, []);
|
|
95
|
+
|
|
96
|
+
return React.createElement(
|
|
97
|
+
View,
|
|
98
|
+
{ ...rest, ref: container, style: [style, styles.container] },
|
|
99
|
+
React.createElement("canvas", {
|
|
100
|
+
ref: canvas,
|
|
101
|
+
id: nativeBufferViewIdToId(viewId),
|
|
102
|
+
style: canvasStyle,
|
|
103
|
+
}),
|
|
104
|
+
);
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
const canvasStyle = {
|
|
108
|
+
position: "absolute",
|
|
109
|
+
left: 0,
|
|
110
|
+
top: 0,
|
|
111
|
+
// The container handles the events, like the native view.
|
|
112
|
+
pointerEvents: "none",
|
|
113
|
+
} as const;
|
|
114
|
+
|
|
115
|
+
const styles = StyleSheet.create({
|
|
116
|
+
container: {
|
|
117
|
+
overflow: "hidden",
|
|
118
|
+
},
|
|
119
|
+
});
|
|
@@ -1,4 +1,8 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
contextIdToId,
|
|
3
|
+
layoutNativeBufferViewCanvas,
|
|
4
|
+
nativeBufferViewIdToId,
|
|
5
|
+
} from "./utils";
|
|
2
6
|
|
|
3
7
|
const fabric = true;
|
|
4
8
|
|
|
@@ -59,6 +63,70 @@ function makeWebGPUCanvasContext(
|
|
|
59
63
|
}
|
|
60
64
|
|
|
61
65
|
let nextContextId = 1;
|
|
66
|
+
let nextNativeBufferViewId = 1;
|
|
67
|
+
|
|
68
|
+
// The size of a canvas image source in pixels, as drawImage() sees it.
|
|
69
|
+
function sizeOfImageSource(source: CanvasImageSource) {
|
|
70
|
+
if ("displayWidth" in source) {
|
|
71
|
+
// A VideoFrame
|
|
72
|
+
return { width: source.displayWidth, height: source.displayHeight };
|
|
73
|
+
}
|
|
74
|
+
if (source instanceof HTMLVideoElement) {
|
|
75
|
+
return { width: source.videoWidth, height: source.videoHeight };
|
|
76
|
+
}
|
|
77
|
+
if (source instanceof HTMLImageElement) {
|
|
78
|
+
return { width: source.naturalWidth, height: source.naturalHeight };
|
|
79
|
+
}
|
|
80
|
+
if (source instanceof SVGImageElement) {
|
|
81
|
+
return {
|
|
82
|
+
width: source.width.baseVal.value,
|
|
83
|
+
height: source.height.baseVal.value,
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
return { width: source.width, height: source.height };
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
// The web counterpart of NativeBufferViewRegistry::present. On the web, the
|
|
90
|
+
// native buffer is a canvas image source, as in drawImage(): an ImageBitmap,
|
|
91
|
+
// an OffscreenCanvas, a canvas, a VideoFrame, or an image or video element.
|
|
92
|
+
// The view keeps a copy of its pixels, so the source can be closed, presented
|
|
93
|
+
// to other views or drawn again right after the call. The fences are not
|
|
94
|
+
// needed: the browser orders the copy after the GPU work that wrote the
|
|
95
|
+
// source.
|
|
96
|
+
function presentNativeBuffer(viewId: number, frame: unknown) {
|
|
97
|
+
const source = frame as CanvasImageSource | null;
|
|
98
|
+
const { width, height } =
|
|
99
|
+
source !== null && typeof source === "object"
|
|
100
|
+
? sizeOfImageSource(source)
|
|
101
|
+
: { width: 0, height: 0 };
|
|
102
|
+
if (source === null || !(width > 0) || !(height > 0)) {
|
|
103
|
+
throw new Error(
|
|
104
|
+
"presentNativeBuffer: on the web, the frame is a canvas image source " +
|
|
105
|
+
"(an ImageBitmap, a canvas, a VideoFrame, an image or a video) that " +
|
|
106
|
+
"has a size",
|
|
107
|
+
);
|
|
108
|
+
}
|
|
109
|
+
const canvas = document.getElementById(
|
|
110
|
+
nativeBufferViewIdToId(viewId),
|
|
111
|
+
) as HTMLCanvasElement | null;
|
|
112
|
+
if (!canvas) {
|
|
113
|
+
// The view is gone: dropped, as on native.
|
|
114
|
+
return;
|
|
115
|
+
}
|
|
116
|
+
// Setting the size clears the canvas, even to the same value.
|
|
117
|
+
if (canvas.width !== width || canvas.height !== height) {
|
|
118
|
+
canvas.width = width;
|
|
119
|
+
canvas.height = height;
|
|
120
|
+
}
|
|
121
|
+
const context = canvas.getContext("2d");
|
|
122
|
+
if (!context) {
|
|
123
|
+
return;
|
|
124
|
+
}
|
|
125
|
+
// Replace the pixels, alpha included, rather than blend over the last ones.
|
|
126
|
+
context.globalCompositeOperation = "copy";
|
|
127
|
+
context.drawImage(source, 0, 0, width, height);
|
|
128
|
+
layoutNativeBufferViewCanvas(canvas);
|
|
129
|
+
}
|
|
62
130
|
|
|
63
131
|
// @ts-expect-error - polyfill for RNWebGPU native module
|
|
64
132
|
window.RNWebGPU = {
|
|
@@ -70,5 +138,11 @@ window.RNWebGPU = {
|
|
|
70
138
|
makeWebGPUCanvasContext as typeof RNWebGPU.MakeWebGPUCanvasContext,
|
|
71
139
|
// On web the browser owns the canvas/context lifecycle; nothing to retire.
|
|
72
140
|
destroyContext: (_contextId: number) => {},
|
|
141
|
+
// NativeBufferView: the canvas of the view is the registry entry, and the
|
|
142
|
+
// DOM owns it.
|
|
143
|
+
allocateNativeBufferViewId: () => nextNativeBufferViewId++,
|
|
144
|
+
retainNativeBufferView: (_viewId: number) => {},
|
|
145
|
+
releaseNativeBufferView: (_viewId: number) => {},
|
|
146
|
+
presentNativeBuffer,
|
|
73
147
|
fabric,
|
|
74
148
|
};
|
package/src/index.tsx
CHANGED
|
@@ -15,6 +15,7 @@ import type {
|
|
|
15
15
|
GPUSharedFenceDescriptor,
|
|
16
16
|
GPUSharedFenceState,
|
|
17
17
|
CreateNativeBufferOptions,
|
|
18
|
+
CreateNativeBufferFromPointerOptions,
|
|
18
19
|
GPUDawnTogglesDescriptor,
|
|
19
20
|
GPUNativeExternalTextureDescriptor,
|
|
20
21
|
GPUSharedTextureMemory,
|
|
@@ -108,7 +109,10 @@ declare global {
|
|
|
108
109
|
// Wrap a NativeBuffer.pointer (CVPixelBufferRef on iOS / AHardwareBuffer*
|
|
109
110
|
// on Android) into a NativeBuffer. Matches the shape used by libraries
|
|
110
111
|
// that emit NativeBuffer (e.g. react-native-vision-camera).
|
|
111
|
-
createNativeBufferFromPointer: (
|
|
112
|
+
createNativeBufferFromPointer: (
|
|
113
|
+
pointer: bigint,
|
|
114
|
+
options?: CreateNativeBufferFromPointerOptions,
|
|
115
|
+
) => NativeBuffer;
|
|
112
116
|
// Wrap an externally created WGPUDevice pointer (e.g. Skia's Graphite
|
|
113
117
|
// device from Skia.getNativeDevice()) into a GPUDevice. Requires the
|
|
114
118
|
// exporter to link this process's single Dawn copy.
|
|
@@ -138,7 +142,8 @@ declare global {
|
|
|
138
142
|
releaseNativeBufferView: (viewId: number) => void;
|
|
139
143
|
presentNativeBuffer: (
|
|
140
144
|
viewId: number,
|
|
141
|
-
|
|
145
|
+
// On the web, the native buffer is a canvas image source.
|
|
146
|
+
frame: NativeBuffer | CanvasImageSource,
|
|
142
147
|
done?: { fences: GPUSharedFenceState[] } | null,
|
|
143
148
|
) => void;
|
|
144
149
|
};
|