react-native-wgpu 0.3.2 → 0.4.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 +7 -5
- package/lib/commonjs/Canvas.js +10 -3
- package/lib/commonjs/Canvas.js.map +1 -1
- package/lib/commonjs/WebGPUViewNativeComponent.web.js +99 -0
- package/lib/commonjs/WebGPUViewNativeComponent.web.js.map +1 -0
- package/lib/commonjs/WebPolyfillGPUModule.js +40 -0
- package/lib/commonjs/WebPolyfillGPUModule.js.map +1 -0
- package/lib/commonjs/index.js +4 -208
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/main/index.js +227 -0
- package/lib/commonjs/main/index.js.map +1 -0
- package/lib/commonjs/main/index.web.js +51 -0
- package/lib/commonjs/main/index.web.js.map +1 -0
- package/lib/commonjs/types.js +2 -0
- package/lib/commonjs/types.js.map +1 -0
- package/lib/commonjs/utils.js +11 -0
- package/lib/commonjs/utils.js.map +1 -0
- package/lib/module/Canvas.js +11 -4
- package/lib/module/Canvas.js.map +1 -1
- package/lib/module/WebGPUViewNativeComponent.web.js +93 -0
- package/lib/module/WebGPUViewNativeComponent.web.js.map +1 -0
- package/lib/module/WebPolyfillGPUModule.js +38 -0
- package/lib/module/WebPolyfillGPUModule.js.map +1 -0
- package/lib/module/index.js +3 -160
- package/lib/module/index.js.map +1 -1
- package/lib/module/main/index.js +168 -0
- package/lib/module/main/index.js.map +1 -0
- package/lib/module/main/index.web.js +8 -0
- package/lib/module/main/index.web.js.map +1 -0
- package/lib/module/types.js +2 -0
- package/lib/module/types.js.map +1 -0
- package/lib/module/utils.js +5 -0
- package/lib/module/utils.js.map +1 -0
- package/lib/typescript/lib/commonjs/WebGPUViewNativeComponent.web.d.ts +5 -0
- package/lib/typescript/lib/commonjs/WebGPUViewNativeComponent.web.d.ts.map +1 -0
- package/lib/typescript/lib/commonjs/WebPolyfillGPUModule.d.ts +2 -0
- package/lib/typescript/lib/commonjs/WebPolyfillGPUModule.d.ts.map +1 -0
- package/lib/typescript/lib/commonjs/index.d.ts +0 -1
- package/lib/typescript/lib/commonjs/main/index.d.ts +3 -0
- package/lib/typescript/lib/commonjs/main/index.d.ts.map +1 -0
- package/lib/typescript/lib/commonjs/main/index.web.d.ts +2 -0
- package/lib/typescript/lib/commonjs/main/index.web.d.ts.map +1 -0
- package/lib/typescript/lib/commonjs/types.d.ts +1 -0
- package/lib/typescript/lib/commonjs/types.d.ts.map +1 -0
- package/lib/typescript/lib/commonjs/utils.d.ts +3 -0
- package/lib/typescript/lib/commonjs/utils.d.ts.map +1 -0
- package/lib/typescript/lib/module/Canvas.d.ts.map +1 -1
- package/lib/typescript/lib/module/WebGPUViewNativeComponent.web.d.ts +2 -0
- package/lib/typescript/lib/module/WebGPUViewNativeComponent.web.d.ts.map +1 -0
- package/lib/typescript/lib/module/WebPolyfillGPUModule.d.ts +2 -0
- package/lib/typescript/lib/module/WebPolyfillGPUModule.d.ts.map +1 -0
- package/lib/typescript/lib/module/index.d.ts +1 -5
- package/lib/typescript/lib/module/main/index.d.ts +6 -0
- package/lib/typescript/lib/module/main/index.d.ts.map +1 -0
- package/lib/typescript/lib/module/main/index.web.d.ts +5 -0
- package/lib/typescript/lib/module/main/index.web.d.ts.map +1 -0
- package/lib/typescript/lib/module/types.d.ts +1 -0
- package/lib/typescript/lib/module/types.d.ts.map +1 -0
- package/lib/typescript/lib/module/utils.d.ts +2 -0
- package/lib/typescript/lib/module/utils.d.ts.map +1 -0
- package/lib/typescript/src/Canvas.d.ts.map +1 -1
- package/lib/typescript/src/WebGPUViewNativeComponent.d.ts +1 -1
- package/lib/typescript/src/WebGPUViewNativeComponent.d.ts.map +1 -1
- package/lib/typescript/src/WebGPUViewNativeComponent.web.d.ts +118 -0
- package/lib/typescript/src/WebGPUViewNativeComponent.web.d.ts.map +1 -0
- package/lib/typescript/src/WebPolyfillGPUModule.d.ts +2 -0
- package/lib/typescript/src/WebPolyfillGPUModule.d.ts.map +1 -0
- package/lib/typescript/src/index.d.ts +16 -5
- package/lib/typescript/src/index.d.ts.map +1 -1
- package/lib/typescript/src/main/index.d.ts +6 -0
- package/lib/typescript/src/main/index.d.ts.map +1 -0
- package/lib/typescript/src/main/index.web.d.ts +6 -0
- package/lib/typescript/src/main/index.web.d.ts.map +1 -0
- package/lib/typescript/src/types.d.ts +19 -0
- package/lib/typescript/src/types.d.ts.map +1 -0
- package/lib/typescript/src/utils.d.ts +2 -0
- package/lib/typescript/src/utils.d.ts.map +1 -0
- package/package.json +2 -1
- package/src/Canvas.tsx +12 -4
- package/src/WebGPUViewNativeComponent.ts +1 -1
- package/src/WebGPUViewNativeComponent.web.ts +108 -0
- package/src/WebPolyfillGPUModule.ts +53 -0
- package/src/index.tsx +25 -196
- package/src/main/index.tsx +204 -0
- package/src/main/index.web.tsx +8 -0
- package/src/types.ts +20 -0
- package/src/utils.ts +4 -0
- package/lib/commonjs/WebGPUView.js +0 -2
- package/lib/commonjs/WebGPUView.js.map +0 -1
- package/lib/module/WebGPUView.js +0 -2
- package/lib/module/WebGPUView.js.map +0 -1
- package/lib/typescript/lib/commonjs/WebGPUView.d.ts +0 -1
- package/lib/typescript/lib/commonjs/WebGPUView.d.ts.map +0 -1
- package/lib/typescript/lib/module/WebGPUView.d.ts +0 -1
- package/lib/typescript/lib/module/WebGPUView.d.ts.map +0 -1
- package/lib/typescript/src/WebGPUView.d.ts +0 -1
- package/lib/typescript/src/WebGPUView.d.ts.map +0 -1
- package/src/WebGPUView.tsx +0 -0
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
import type { Int32 } from "react-native/Libraries/Types/CodegenTypes";
|
|
2
|
+
import type { ViewProps } from "react-native";
|
|
3
|
+
export interface NativeProps extends ViewProps {
|
|
4
|
+
contextId: Int32;
|
|
5
|
+
transparent: boolean;
|
|
6
|
+
}
|
|
7
|
+
export default function WebGPUViewNativeComponent(props: NativeProps): import("react").ReactElement<{
|
|
8
|
+
style: (import("react-native").StyleProp<import("react-native").ViewStyle> | {
|
|
9
|
+
flex: number;
|
|
10
|
+
} | {
|
|
11
|
+
alignItems: "stretch";
|
|
12
|
+
backgroundColor: string;
|
|
13
|
+
border: string;
|
|
14
|
+
boxSizing: "border-box";
|
|
15
|
+
display: "flex";
|
|
16
|
+
flexBasis: "auto";
|
|
17
|
+
flexDirection: "column";
|
|
18
|
+
flexShrink: number;
|
|
19
|
+
listStyle: string;
|
|
20
|
+
margin: number;
|
|
21
|
+
minHeight: number;
|
|
22
|
+
minWidth: number;
|
|
23
|
+
padding: number;
|
|
24
|
+
position: "relative";
|
|
25
|
+
zIndex: number;
|
|
26
|
+
})[];
|
|
27
|
+
id: string;
|
|
28
|
+
ref: (ref: HTMLCanvasElement) => void;
|
|
29
|
+
children?: React.ReactNode | undefined;
|
|
30
|
+
hitSlop?: null | import("react-native").Insets | number | undefined;
|
|
31
|
+
needsOffscreenAlphaCompositing?: boolean | undefined;
|
|
32
|
+
onLayout?: ((event: import("react-native").LayoutChangeEvent) => void) | undefined;
|
|
33
|
+
pointerEvents?: "box-none" | "none" | "box-only" | "auto" | undefined;
|
|
34
|
+
removeClippedSubviews?: boolean | undefined;
|
|
35
|
+
testID?: string | undefined;
|
|
36
|
+
nativeID?: string | undefined;
|
|
37
|
+
collapsable?: boolean | undefined;
|
|
38
|
+
collapsableChildren?: boolean | undefined;
|
|
39
|
+
onBlur?: ((e: import("react-native").BlurEvent) => void) | null | undefined;
|
|
40
|
+
onFocus?: ((e: import("react-native").FocusEvent) => void) | null | undefined;
|
|
41
|
+
renderToHardwareTextureAndroid?: boolean | undefined;
|
|
42
|
+
focusable?: boolean | undefined;
|
|
43
|
+
tabIndex?: 0 | -1 | undefined;
|
|
44
|
+
shouldRasterizeIOS?: boolean | undefined;
|
|
45
|
+
isTVSelectable?: boolean | undefined;
|
|
46
|
+
hasTVPreferredFocus?: boolean | undefined;
|
|
47
|
+
tvParallaxShiftDistanceX?: number | undefined;
|
|
48
|
+
tvParallaxShiftDistanceY?: number | undefined;
|
|
49
|
+
tvParallaxTiltAngle?: number | undefined;
|
|
50
|
+
tvParallaxMagnification?: number | undefined;
|
|
51
|
+
onStartShouldSetResponder?: ((event: import("react-native").GestureResponderEvent) => boolean) | undefined;
|
|
52
|
+
onMoveShouldSetResponder?: ((event: import("react-native").GestureResponderEvent) => boolean) | undefined;
|
|
53
|
+
onResponderEnd?: ((event: import("react-native").GestureResponderEvent) => void) | undefined;
|
|
54
|
+
onResponderGrant?: ((event: import("react-native").GestureResponderEvent) => void) | undefined;
|
|
55
|
+
onResponderReject?: ((event: import("react-native").GestureResponderEvent) => void) | undefined;
|
|
56
|
+
onResponderMove?: ((event: import("react-native").GestureResponderEvent) => void) | undefined;
|
|
57
|
+
onResponderRelease?: ((event: import("react-native").GestureResponderEvent) => void) | undefined;
|
|
58
|
+
onResponderStart?: ((event: import("react-native").GestureResponderEvent) => void) | undefined;
|
|
59
|
+
onResponderTerminationRequest?: ((event: import("react-native").GestureResponderEvent) => boolean) | undefined;
|
|
60
|
+
onResponderTerminate?: ((event: import("react-native").GestureResponderEvent) => void) | undefined;
|
|
61
|
+
onStartShouldSetResponderCapture?: ((event: import("react-native").GestureResponderEvent) => boolean) | undefined;
|
|
62
|
+
onMoveShouldSetResponderCapture?: ((event: import("react-native").GestureResponderEvent) => boolean) | undefined;
|
|
63
|
+
onTouchStart?: ((event: import("react-native").GestureResponderEvent) => void) | undefined;
|
|
64
|
+
onTouchMove?: ((event: import("react-native").GestureResponderEvent) => void) | undefined;
|
|
65
|
+
onTouchEnd?: ((event: import("react-native").GestureResponderEvent) => void) | undefined;
|
|
66
|
+
onTouchCancel?: ((event: import("react-native").GestureResponderEvent) => void) | undefined;
|
|
67
|
+
onTouchEndCapture?: ((event: import("react-native").GestureResponderEvent) => void) | undefined;
|
|
68
|
+
onPointerEnter?: ((event: import("react-native").PointerEvent) => void) | undefined;
|
|
69
|
+
onPointerEnterCapture?: ((event: import("react-native").PointerEvent) => void) | undefined;
|
|
70
|
+
onPointerLeave?: ((event: import("react-native").PointerEvent) => void) | undefined;
|
|
71
|
+
onPointerLeaveCapture?: ((event: import("react-native").PointerEvent) => void) | undefined;
|
|
72
|
+
onPointerMove?: ((event: import("react-native").PointerEvent) => void) | undefined;
|
|
73
|
+
onPointerMoveCapture?: ((event: import("react-native").PointerEvent) => void) | undefined;
|
|
74
|
+
onPointerCancel?: ((event: import("react-native").PointerEvent) => void) | undefined;
|
|
75
|
+
onPointerCancelCapture?: ((event: import("react-native").PointerEvent) => void) | undefined;
|
|
76
|
+
onPointerDown?: ((event: import("react-native").PointerEvent) => void) | undefined;
|
|
77
|
+
onPointerDownCapture?: ((event: import("react-native").PointerEvent) => void) | undefined;
|
|
78
|
+
onPointerUp?: ((event: import("react-native").PointerEvent) => void) | undefined;
|
|
79
|
+
onPointerUpCapture?: ((event: import("react-native").PointerEvent) => void) | undefined;
|
|
80
|
+
accessible?: boolean | undefined;
|
|
81
|
+
accessibilityActions?: ReadonlyArray<import("react-native").AccessibilityActionInfo> | undefined;
|
|
82
|
+
accessibilityLabel?: string | undefined;
|
|
83
|
+
'aria-label'?: string | undefined;
|
|
84
|
+
accessibilityRole?: import("react-native").AccessibilityRole | undefined;
|
|
85
|
+
accessibilityState?: import("react-native").AccessibilityState | undefined;
|
|
86
|
+
'aria-busy'?: boolean | undefined;
|
|
87
|
+
'aria-checked'?: boolean | "mixed" | undefined;
|
|
88
|
+
'aria-disabled'?: boolean | undefined;
|
|
89
|
+
'aria-expanded'?: boolean | undefined;
|
|
90
|
+
'aria-selected'?: boolean | undefined;
|
|
91
|
+
accessibilityHint?: string | undefined;
|
|
92
|
+
accessibilityValue?: import("react-native").AccessibilityValue | undefined;
|
|
93
|
+
'aria-valuemax'?: import("react-native").AccessibilityValue["max"] | undefined;
|
|
94
|
+
'aria-valuemin'?: import("react-native").AccessibilityValue["min"] | undefined;
|
|
95
|
+
'aria-valuenow'?: import("react-native").AccessibilityValue["now"] | undefined;
|
|
96
|
+
'aria-valuetext'?: import("react-native").AccessibilityValue["text"] | undefined;
|
|
97
|
+
onAccessibilityAction?: ((event: import("react-native").AccessibilityActionEvent) => void) | undefined;
|
|
98
|
+
importantForAccessibility?: ("auto" | "yes" | "no" | "no-hide-descendants") | undefined;
|
|
99
|
+
'aria-hidden'?: boolean | undefined;
|
|
100
|
+
'aria-modal'?: boolean | undefined;
|
|
101
|
+
role?: import("react-native").Role | undefined;
|
|
102
|
+
accessibilityLabelledBy?: string | string[] | undefined;
|
|
103
|
+
'aria-labelledby'?: string | undefined;
|
|
104
|
+
accessibilityLiveRegion?: "none" | "polite" | "assertive" | undefined;
|
|
105
|
+
'aria-live'?: ("polite" | "assertive" | "off") | undefined;
|
|
106
|
+
screenReaderFocusable?: boolean | undefined;
|
|
107
|
+
accessibilityElementsHidden?: boolean | undefined;
|
|
108
|
+
accessibilityViewIsModal?: boolean | undefined;
|
|
109
|
+
onAccessibilityEscape?: (() => void) | undefined;
|
|
110
|
+
onAccessibilityTap?: (() => void) | undefined;
|
|
111
|
+
onMagicTap?: (() => void) | undefined;
|
|
112
|
+
accessibilityIgnoresInvertColors?: boolean | undefined;
|
|
113
|
+
accessibilityLanguage?: string | undefined;
|
|
114
|
+
accessibilityShowsLargeContentViewer?: boolean | undefined;
|
|
115
|
+
accessibilityLargeContentTitle?: string | undefined;
|
|
116
|
+
accessibilityRespondsToUserInteraction?: boolean | undefined;
|
|
117
|
+
}, string | import("react").JSXElementConstructor<any>>;
|
|
118
|
+
//# sourceMappingURL=WebGPUViewNativeComponent.web.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"WebGPUViewNativeComponent.web.d.ts","sourceRoot":"","sources":["../../../src/WebGPUViewNativeComponent.web.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,2CAA2C,CAAC;AACvE,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAI9C,MAAM,WAAW,WAAY,SAAQ,SAAS;IAC5C,SAAS,EAAE,KAAK,CAAC;IACjB,WAAW,EAAE,OAAO,CAAC;CACtB;AA2CD,MAAM,CAAC,OAAO,UAAU,yBAAyB,CAAC,KAAK,EAAE,WAAW;;;;;;;;;;;;;;;;;;;;;eAsBrD,iBAAiB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;wDAO/B"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"WebPolyfillGPUModule.d.ts","sourceRoot":"","sources":["../../../src/WebPolyfillGPUModule.ts"],"names":[],"mappings":""}
|
|
@@ -1,6 +1,17 @@
|
|
|
1
|
-
|
|
2
|
-
export * from "./
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
import type { NativeCanvas, RNCanvasContext } from "./types";
|
|
2
|
+
export * from "./main";
|
|
3
|
+
declare global {
|
|
4
|
+
interface Navigator {
|
|
5
|
+
gpu: GPU;
|
|
6
|
+
}
|
|
7
|
+
var navigator: Navigator;
|
|
8
|
+
var RNWebGPU: {
|
|
9
|
+
gpu: GPU;
|
|
10
|
+
fabric: boolean;
|
|
11
|
+
getNativeSurface: (contextId: number) => NativeCanvas;
|
|
12
|
+
MakeWebGPUCanvasContext: (contextId: number, width: number, height: number) => RNCanvasContext;
|
|
13
|
+
DecodeToUTF8: (buffer: NodeJS.ArrayBufferView | ArrayBuffer) => string;
|
|
14
|
+
createImageBitmap: typeof createImageBitmap;
|
|
15
|
+
};
|
|
16
|
+
}
|
|
6
17
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,YAAY,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;AAE7D,cAAc,QAAQ,CAAC;AAEvB,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;QACrB,YAAY,EAAE,CAAC,MAAM,EAAE,MAAM,CAAC,eAAe,GAAG,WAAW,KAAK,MAAM,CAAC;QACvE,iBAAiB,EAAE,OAAO,iBAAiB,CAAC;KAC7C,CAAC;CACH"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/main/index.tsx"],"names":[],"mappings":"AAGA,cAAc,WAAW,CAAC;AAC1B,cAAc,cAAc,CAAC;AAC7B,cAAc,8BAA8B,CAAC;AAC7C,cAAc,UAAU,CAAC;AAEzB,OAAO,EAAE,OAAO,IAAI,YAAY,EAAE,MAAM,uBAAuB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.web.d.ts","sourceRoot":"","sources":["../../../../src/main/index.web.tsx"],"names":[],"mappings":"AAAA,OAAO,yBAAyB,CAAC;AAEjC,cAAc,WAAW,CAAC;AAC1B,cAAc,cAAc,CAAC;AAC7B,cAAc,8BAA8B,CAAC;AAC7C,cAAc,UAAU,CAAC"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
type SurfacePointer = bigint;
|
|
2
|
+
export interface NativeCanvas {
|
|
3
|
+
surface: SurfacePointer;
|
|
4
|
+
width: number;
|
|
5
|
+
height: number;
|
|
6
|
+
clientWidth: number;
|
|
7
|
+
clientHeight: number;
|
|
8
|
+
}
|
|
9
|
+
export type RNCanvasContext = GPUCanvasContext & {
|
|
10
|
+
present: () => void;
|
|
11
|
+
};
|
|
12
|
+
export interface CanvasRef {
|
|
13
|
+
getContextId: () => number;
|
|
14
|
+
getContext(contextName: "webgpu"): RNCanvasContext | null;
|
|
15
|
+
getNativeSurface: () => NativeCanvas;
|
|
16
|
+
whenReady: (callback: () => void) => void;
|
|
17
|
+
}
|
|
18
|
+
export {};
|
|
19
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +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;CACtB;AAED,MAAM,MAAM,eAAe,GAAG,gBAAgB,GAAG;IAC/C,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;IACrC,SAAS,EAAE,CAAC,QAAQ,EAAE,MAAM,IAAI,KAAK,IAAI,CAAC;CAC3C"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../src/utils.ts"],"names":[],"mappings":"AACA,wBAAgB,aAAa,CAAC,SAAS,EAAE,MAAM,UAE9C"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-native-wgpu",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.0",
|
|
4
4
|
"description": "React Native WebGPU",
|
|
5
5
|
"main": "lib/commonjs/index",
|
|
6
6
|
"module": "lib/module/index",
|
|
@@ -81,6 +81,7 @@
|
|
|
81
81
|
"react": "19.1.0",
|
|
82
82
|
"react-native": "0.81.4",
|
|
83
83
|
"react-native-builder-bob": "^0.23.2",
|
|
84
|
+
"react-native-web": "^0.21.2",
|
|
84
85
|
"rimraf": "^5.0.7",
|
|
85
86
|
"seedrandom": "^3.0.5",
|
|
86
87
|
"teapot": "^1.0.0",
|
package/src/Canvas.tsx
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { ViewProps } from "react-native";
|
|
2
|
-
import { View } from "react-native";
|
|
2
|
+
import { Platform, View } from "react-native";
|
|
3
3
|
import { forwardRef, useImperativeHandle, useRef, useState } from "react";
|
|
4
4
|
|
|
5
5
|
import WebGPUNativeView from "./WebGPUViewNativeComponent";
|
|
@@ -62,9 +62,16 @@ export const Canvas = forwardRef<
|
|
|
62
62
|
if (!viewRef.current) {
|
|
63
63
|
throw new Error("[WebGPU] Cannot get context before mount");
|
|
64
64
|
}
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
65
|
+
let size;
|
|
66
|
+
if (Platform.OS === "web") {
|
|
67
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
68
|
+
// @ts-expect-error
|
|
69
|
+
size = viewRef.current.getBoundingClientRect();
|
|
70
|
+
} else {
|
|
71
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
72
|
+
// @ts-expect-error
|
|
73
|
+
size = viewRef.current.unstable_getBoundingClientRect();
|
|
74
|
+
}
|
|
68
75
|
return RNWebGPU.MakeWebGPUCanvasContext(
|
|
69
76
|
contextId,
|
|
70
77
|
size.width,
|
|
@@ -72,6 +79,7 @@ export const Canvas = forwardRef<
|
|
|
72
79
|
);
|
|
73
80
|
},
|
|
74
81
|
}));
|
|
82
|
+
|
|
75
83
|
return (
|
|
76
84
|
<View collapsable={false} ref={viewRef} {...props}>
|
|
77
85
|
<WebGPUNativeView
|
|
@@ -2,7 +2,7 @@ import { codegenNativeComponent } from "react-native";
|
|
|
2
2
|
import type { Int32 } from "react-native/Libraries/Types/CodegenTypes";
|
|
3
3
|
import type { ViewProps } from "react-native";
|
|
4
4
|
|
|
5
|
-
interface NativeProps extends ViewProps {
|
|
5
|
+
export interface NativeProps extends ViewProps {
|
|
6
6
|
contextId: Int32;
|
|
7
7
|
transparent: boolean;
|
|
8
8
|
}
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import { useEffect, useRef } from "react";
|
|
2
|
+
import { StyleSheet } from "react-native";
|
|
3
|
+
import { unstable_createElement as unstableCreateElement } from "react-native-web";
|
|
4
|
+
import type { Int32 } from "react-native/Libraries/Types/CodegenTypes";
|
|
5
|
+
import type { ViewProps } from "react-native";
|
|
6
|
+
|
|
7
|
+
import { contextIdToId } from "./utils";
|
|
8
|
+
|
|
9
|
+
export interface NativeProps extends ViewProps {
|
|
10
|
+
contextId: Int32;
|
|
11
|
+
transparent: boolean;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
15
|
+
function debounce<T extends (...args: any[]) => void>(
|
|
16
|
+
func: T,
|
|
17
|
+
wait: number,
|
|
18
|
+
immediate = false,
|
|
19
|
+
) {
|
|
20
|
+
let timeout: ReturnType<typeof setTimeout> | undefined;
|
|
21
|
+
return function debounced(
|
|
22
|
+
this: ThisParameterType<T>,
|
|
23
|
+
...args: Parameters<T>
|
|
24
|
+
) {
|
|
25
|
+
const context = this;
|
|
26
|
+
const callNow = immediate && !timeout;
|
|
27
|
+
if (timeout) {
|
|
28
|
+
clearTimeout(timeout);
|
|
29
|
+
}
|
|
30
|
+
timeout = setTimeout(() => {
|
|
31
|
+
timeout = undefined;
|
|
32
|
+
if (!immediate) {
|
|
33
|
+
func.apply(context, args);
|
|
34
|
+
}
|
|
35
|
+
}, wait);
|
|
36
|
+
if (callNow) {
|
|
37
|
+
func.apply(context, args);
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
function resizeCanvas(canvas?: HTMLCanvasElement) {
|
|
43
|
+
if (!canvas) {
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
const dpr = window.devicePixelRatio || 1;
|
|
48
|
+
|
|
49
|
+
const { height, width } = canvas.getBoundingClientRect();
|
|
50
|
+
canvas.setAttribute("height", (height * dpr).toString());
|
|
51
|
+
canvas.setAttribute("width", (width * dpr).toString());
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
// eslint-disable-next-line import/no-default-export
|
|
55
|
+
export default function WebGPUViewNativeComponent(props: NativeProps) {
|
|
56
|
+
const { contextId, style, transparent, ...rest } = props;
|
|
57
|
+
|
|
58
|
+
const canvasElm = useRef<HTMLCanvasElement>();
|
|
59
|
+
|
|
60
|
+
useEffect(() => {
|
|
61
|
+
const onResize = debounce(() => resizeCanvas(canvasElm.current), 100);
|
|
62
|
+
window.addEventListener("resize", onResize);
|
|
63
|
+
return () => {
|
|
64
|
+
window.removeEventListener("resize", onResize);
|
|
65
|
+
};
|
|
66
|
+
}, []);
|
|
67
|
+
|
|
68
|
+
return unstableCreateElement("canvas", {
|
|
69
|
+
...rest,
|
|
70
|
+
style: [
|
|
71
|
+
styles.view,
|
|
72
|
+
styles.flex1,
|
|
73
|
+
transparent === false && { backgroundColor: "white" }, // Canvas elements are transparent by default on the web
|
|
74
|
+
style,
|
|
75
|
+
],
|
|
76
|
+
id: contextIdToId(contextId),
|
|
77
|
+
ref: (ref: HTMLCanvasElement) => {
|
|
78
|
+
canvasElm.current = ref;
|
|
79
|
+
if (ref) {
|
|
80
|
+
resizeCanvas(ref);
|
|
81
|
+
}
|
|
82
|
+
},
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
const styles = StyleSheet.create({
|
|
87
|
+
flex1: {
|
|
88
|
+
flex: 1,
|
|
89
|
+
},
|
|
90
|
+
view: {
|
|
91
|
+
alignItems: "stretch",
|
|
92
|
+
backgroundColor: "transparent",
|
|
93
|
+
// @ts-expect-error - not a valid RN style, but it's valid for web
|
|
94
|
+
border: "0 solid black",
|
|
95
|
+
boxSizing: "border-box",
|
|
96
|
+
display: "flex",
|
|
97
|
+
flexBasis: "auto",
|
|
98
|
+
flexDirection: "column",
|
|
99
|
+
flexShrink: 0,
|
|
100
|
+
listStyle: "none",
|
|
101
|
+
margin: 0,
|
|
102
|
+
minHeight: 0,
|
|
103
|
+
minWidth: 0,
|
|
104
|
+
padding: 0,
|
|
105
|
+
position: "relative",
|
|
106
|
+
zIndex: 0,
|
|
107
|
+
},
|
|
108
|
+
});
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { contextIdToId } from "./utils";
|
|
2
|
+
|
|
3
|
+
const fabric = true;
|
|
4
|
+
|
|
5
|
+
function getNativeSurface(contextId: number) {
|
|
6
|
+
const canvas = document.getElementById(
|
|
7
|
+
contextIdToId(contextId),
|
|
8
|
+
) as HTMLCanvasElement;
|
|
9
|
+
|
|
10
|
+
const { height, width } = canvas.getBoundingClientRect()!;
|
|
11
|
+
|
|
12
|
+
return {
|
|
13
|
+
surface: BigInt(contextId),
|
|
14
|
+
height,
|
|
15
|
+
width,
|
|
16
|
+
clientHeight: height,
|
|
17
|
+
clientWidth: width,
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
function makeWebGPUCanvasContext(
|
|
22
|
+
contextId: number,
|
|
23
|
+
width: number,
|
|
24
|
+
height: number,
|
|
25
|
+
) {
|
|
26
|
+
const canvas = document.getElementById(
|
|
27
|
+
contextIdToId(contextId),
|
|
28
|
+
) as HTMLCanvasElement;
|
|
29
|
+
|
|
30
|
+
const dpr = window.devicePixelRatio || 1;
|
|
31
|
+
const pixelWidth = (width * dpr).toString();
|
|
32
|
+
const pixelHeight = (height * dpr).toString();
|
|
33
|
+
|
|
34
|
+
if (
|
|
35
|
+
canvas.getAttribute("width") !== pixelWidth ||
|
|
36
|
+
canvas.getAttribute("height") !== pixelHeight
|
|
37
|
+
) {
|
|
38
|
+
canvas.setAttribute("width", pixelWidth);
|
|
39
|
+
canvas.setAttribute("height", pixelHeight);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
const context = canvas.getContext("webgpu")!;
|
|
43
|
+
return Object.assign(context, {
|
|
44
|
+
present: () => {},
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
// @ts-expect-error - polyfill for RNWebGPU native module
|
|
49
|
+
window.RNWebGPU = {
|
|
50
|
+
getNativeSurface,
|
|
51
|
+
MakeWebGPUCanvasContext: makeWebGPUCanvasContext,
|
|
52
|
+
fabric,
|
|
53
|
+
};
|
package/src/index.tsx
CHANGED
|
@@ -1,197 +1,26 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
export * from "./
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
GPUBindGroup[Symbol.hasInstance] = function (instance: object) {
|
|
27
|
-
return "__brand" in instance && instance.__brand === "GPUBindGroup";
|
|
28
|
-
};
|
|
29
|
-
|
|
30
|
-
const GPUBindGroupLayout: any = {};
|
|
31
|
-
GPUBindGroupLayout[Symbol.hasInstance] = function (instance: object) {
|
|
32
|
-
return "__brand" in instance && instance.__brand === "GPUBindGroupLayout";
|
|
33
|
-
};
|
|
34
|
-
|
|
35
|
-
const GPUBuffer: any = {};
|
|
36
|
-
GPUBuffer[Symbol.hasInstance] = function (instance: object) {
|
|
37
|
-
return "__brand" in instance && instance.__brand === "GPUBuffer";
|
|
38
|
-
};
|
|
39
|
-
|
|
40
|
-
const GPUCanvasContext: any = {};
|
|
41
|
-
GPUCanvasContext[Symbol.hasInstance] = function (instance: object) {
|
|
42
|
-
return "__brand" in instance && instance.__brand === "GPUCanvasContext";
|
|
43
|
-
};
|
|
44
|
-
|
|
45
|
-
const GPUCommandBuffer: any = {};
|
|
46
|
-
GPUCommandBuffer[Symbol.hasInstance] = function (instance: object) {
|
|
47
|
-
return "__brand" in instance && instance.__brand === "GPUCommandBuffer";
|
|
48
|
-
};
|
|
49
|
-
|
|
50
|
-
const GPUCommandEncoder: any = {};
|
|
51
|
-
GPUCommandEncoder[Symbol.hasInstance] = function (instance: object) {
|
|
52
|
-
return "__brand" in instance && instance.__brand === "GPUCommandEncoder";
|
|
53
|
-
};
|
|
54
|
-
|
|
55
|
-
const GPUCompilationInfo: any = {};
|
|
56
|
-
GPUCompilationInfo[Symbol.hasInstance] = function (instance: object) {
|
|
57
|
-
return "__brand" in instance && instance.__brand === "GPUCompilationInfo";
|
|
58
|
-
};
|
|
59
|
-
|
|
60
|
-
const GPUCompilationMessage: any = {};
|
|
61
|
-
GPUCompilationMessage[Symbol.hasInstance] = function (instance: object) {
|
|
62
|
-
return "__brand" in instance && instance.__brand === "GPUCompilationMessage";
|
|
63
|
-
};
|
|
64
|
-
|
|
65
|
-
const GPUComputePassEncoder: any = {};
|
|
66
|
-
GPUComputePassEncoder[Symbol.hasInstance] = function (instance: object) {
|
|
67
|
-
return "__brand" in instance && instance.__brand === "GPUComputePassEncoder";
|
|
68
|
-
};
|
|
69
|
-
|
|
70
|
-
const GPUComputePipeline: any = {};
|
|
71
|
-
GPUComputePipeline[Symbol.hasInstance] = function (instance: object) {
|
|
72
|
-
return "__brand" in instance && instance.__brand === "GPUComputePipeline";
|
|
73
|
-
};
|
|
74
|
-
|
|
75
|
-
const GPUDevice: any = {};
|
|
76
|
-
GPUDevice[Symbol.hasInstance] = function (instance: object) {
|
|
77
|
-
return "__brand" in instance && instance.__brand === "GPUDevice";
|
|
78
|
-
};
|
|
79
|
-
|
|
80
|
-
const GPUDeviceLostInfo: any = {};
|
|
81
|
-
GPUDeviceLostInfo[Symbol.hasInstance] = function (instance: object) {
|
|
82
|
-
return "__brand" in instance && instance.__brand === "GPUDeviceLostInfo";
|
|
83
|
-
};
|
|
84
|
-
|
|
85
|
-
const GPUError: any = {};
|
|
86
|
-
GPUError[Symbol.hasInstance] = function (instance: object) {
|
|
87
|
-
return "__brand" in instance && instance.__brand === "GPUError";
|
|
88
|
-
};
|
|
89
|
-
|
|
90
|
-
const GPUExternalTexture: any = {};
|
|
91
|
-
GPUExternalTexture[Symbol.hasInstance] = function (instance: object) {
|
|
92
|
-
return "__brand" in instance && instance.__brand === "GPUExternalTexture";
|
|
93
|
-
};
|
|
94
|
-
|
|
95
|
-
const GPUPipelineLayout: any = {};
|
|
96
|
-
GPUPipelineLayout[Symbol.hasInstance] = function (instance: object) {
|
|
97
|
-
return "__brand" in instance && instance.__brand === "GPUPipelineLayout";
|
|
98
|
-
};
|
|
99
|
-
|
|
100
|
-
const GPUQuerySet: any = {};
|
|
101
|
-
GPUQuerySet[Symbol.hasInstance] = function (instance: object) {
|
|
102
|
-
return "__brand" in instance && instance.__brand === "GPUQuerySet";
|
|
103
|
-
};
|
|
104
|
-
|
|
105
|
-
const GPUQueue: any = {};
|
|
106
|
-
GPUQueue[Symbol.hasInstance] = function (instance: object) {
|
|
107
|
-
return "__brand" in instance && instance.__brand === "GPUQueue";
|
|
108
|
-
};
|
|
109
|
-
|
|
110
|
-
const GPURenderBundle: any = {};
|
|
111
|
-
GPURenderBundle[Symbol.hasInstance] = function (instance: object) {
|
|
112
|
-
return "__brand" in instance && instance.__brand === "GPURenderBundle";
|
|
113
|
-
};
|
|
114
|
-
|
|
115
|
-
const GPURenderBundleEncoder: any = {};
|
|
116
|
-
GPURenderBundleEncoder[Symbol.hasInstance] = function (instance: object) {
|
|
117
|
-
return "__brand" in instance && instance.__brand === "GPURenderBundleEncoder";
|
|
118
|
-
};
|
|
119
|
-
|
|
120
|
-
const GPURenderPassEncoder: any = {};
|
|
121
|
-
GPURenderPassEncoder[Symbol.hasInstance] = function (instance: object) {
|
|
122
|
-
return "__brand" in instance && instance.__brand === "GPURenderPassEncoder";
|
|
123
|
-
};
|
|
124
|
-
|
|
125
|
-
const GPURenderPipeline: any = {};
|
|
126
|
-
GPURenderPipeline[Symbol.hasInstance] = function (instance: object) {
|
|
127
|
-
return "__brand" in instance && instance.__brand === "GPURenderPipeline";
|
|
128
|
-
};
|
|
129
|
-
|
|
130
|
-
const GPUSampler: any = {};
|
|
131
|
-
GPUSampler[Symbol.hasInstance] = function (instance: object) {
|
|
132
|
-
return "__brand" in instance && instance.__brand === "GPUSampler";
|
|
133
|
-
};
|
|
134
|
-
|
|
135
|
-
const GPUShaderModule: any = {};
|
|
136
|
-
GPUShaderModule[Symbol.hasInstance] = function (instance: object) {
|
|
137
|
-
return "__brand" in instance && instance.__brand === "GPUShaderModule";
|
|
138
|
-
};
|
|
139
|
-
|
|
140
|
-
const GPUTexture: any = {};
|
|
141
|
-
GPUTexture[Symbol.hasInstance] = function (instance: object) {
|
|
142
|
-
return "__brand" in instance && instance.__brand === "GPUTexture";
|
|
143
|
-
};
|
|
144
|
-
|
|
145
|
-
const GPUTextureView: any = {};
|
|
146
|
-
GPUTextureView[Symbol.hasInstance] = function (instance: object) {
|
|
147
|
-
return "__brand" in instance && instance.__brand === "GPUTextureView";
|
|
148
|
-
};
|
|
149
|
-
|
|
150
|
-
global.GPU = GPU;
|
|
151
|
-
global.GPUAdapter = GPUAdapter;
|
|
152
|
-
global.GPUAdapterInfo = GPUAdapterInfo;
|
|
153
|
-
global.GPUBindGroup = GPUBindGroup;
|
|
154
|
-
global.GPUBindGroupLayout = GPUBindGroupLayout;
|
|
155
|
-
global.GPUBuffer = GPUBuffer;
|
|
156
|
-
global.GPUCanvasContext = GPUCanvasContext;
|
|
157
|
-
global.GPUCommandBuffer = GPUCommandBuffer;
|
|
158
|
-
global.GPUCommandEncoder = GPUCommandEncoder;
|
|
159
|
-
global.GPUCompilationInfo = GPUCompilationInfo;
|
|
160
|
-
global.GPUCompilationMessage = GPUCompilationMessage;
|
|
161
|
-
global.GPUComputePassEncoder = GPUComputePassEncoder;
|
|
162
|
-
global.GPUComputePipeline = GPUComputePipeline;
|
|
163
|
-
global.GPUDevice = GPUDevice;
|
|
164
|
-
global.GPUDeviceLostInfo = GPUDeviceLostInfo;
|
|
165
|
-
global.GPUError = GPUError;
|
|
166
|
-
global.GPUExternalTexture = GPUExternalTexture;
|
|
167
|
-
global.GPUPipelineLayout = GPUPipelineLayout;
|
|
168
|
-
global.GPUQuerySet = GPUQuerySet;
|
|
169
|
-
global.GPUQueue = GPUQueue;
|
|
170
|
-
global.GPURenderBundle = GPURenderBundle;
|
|
171
|
-
global.GPURenderBundleEncoder = GPURenderBundleEncoder;
|
|
172
|
-
global.GPURenderPassEncoder = GPURenderPassEncoder;
|
|
173
|
-
global.GPURenderPipeline = GPURenderPipeline;
|
|
174
|
-
global.GPUSampler = GPUSampler;
|
|
175
|
-
global.GPUShaderModule = GPUShaderModule;
|
|
176
|
-
global.GPUTexture = GPUTexture;
|
|
177
|
-
global.GPUTextureView = GPUTextureView;
|
|
178
|
-
|
|
179
|
-
WebGPUNativeModule.install();
|
|
180
|
-
|
|
181
|
-
if (!navigator) {
|
|
182
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
183
|
-
// @ts-expect-error
|
|
184
|
-
navigator = {};
|
|
1
|
+
/// <reference types="@webgpu/types" />
|
|
2
|
+
|
|
3
|
+
import type { NativeCanvas, RNCanvasContext } from "./types";
|
|
4
|
+
|
|
5
|
+
export * from "./main";
|
|
6
|
+
|
|
7
|
+
declare global {
|
|
8
|
+
interface Navigator {
|
|
9
|
+
gpu: GPU;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
var navigator: Navigator;
|
|
13
|
+
|
|
14
|
+
var RNWebGPU: {
|
|
15
|
+
gpu: GPU;
|
|
16
|
+
fabric: boolean;
|
|
17
|
+
getNativeSurface: (contextId: number) => NativeCanvas;
|
|
18
|
+
MakeWebGPUCanvasContext: (
|
|
19
|
+
contextId: number,
|
|
20
|
+
width: number,
|
|
21
|
+
height: number,
|
|
22
|
+
) => RNCanvasContext;
|
|
23
|
+
DecodeToUTF8: (buffer: NodeJS.ArrayBufferView | ArrayBuffer) => string;
|
|
24
|
+
createImageBitmap: typeof createImageBitmap;
|
|
25
|
+
};
|
|
185
26
|
}
|
|
186
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
187
|
-
// @ts-expect-error
|
|
188
|
-
navigator.gpu = RNWebGPU.gpu;
|
|
189
|
-
|
|
190
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
191
|
-
// @ts-ignore
|
|
192
|
-
navigator.userAgent = "react-native";
|
|
193
|
-
|
|
194
|
-
global.createImageBitmap =
|
|
195
|
-
global.createImageBitmap ??
|
|
196
|
-
((...params: Parameters<typeof createImageBitmap>) =>
|
|
197
|
-
new Promise((resolve) => resolve(RNWebGPU.createImageBitmap(...params))));
|