@shopify/react-native-skia 2.5.1 → 2.5.3
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/CMakeLists.txt +8 -6
- package/android/build.gradle +5 -32
- package/android/cpp/jni/JniWebGPUView.cpp +67 -0
- package/android/cpp/rnskia-android/OpenGLContext.h +9 -2
- package/android/cpp/rnskia-android/RNSkAndroidPlatformContext.h +6 -3
- package/android/cpp/rnskia-android/SkiaPlatformContext.h +26 -0
- package/android/src/main/java/com/shopify/reactnative/skia/RNSkiaPackage.java +4 -1
- package/android/src/main/java/com/shopify/reactnative/skia/WebGPUSurfaceView.java +41 -0
- package/android/src/main/java/com/shopify/reactnative/skia/WebGPUTextureView.java +44 -0
- package/android/src/main/java/com/shopify/reactnative/skia/WebGPUView.java +95 -0
- package/android/src/main/java/com/shopify/reactnative/skia/WebGPUViewAPI.java +14 -0
- package/android/src/main/java/com/shopify/reactnative/skia/WebGPUViewManager.java +58 -0
- package/apple/MetalContext.h +10 -2
- package/apple/MetalWindowContext.h +1 -0
- package/apple/MetalWindowContext.mm +8 -1
- package/apple/RNSkApplePlatformContext.h +2 -1
- package/apple/RNSkApplePlatformContext.mm +6 -4
- package/apple/RNSkUIKit.h +13 -0
- package/apple/SkiaPictureView.mm +3 -0
- package/apple/SkiaPlatformContext.h +20 -0
- package/apple/SkiaPlatformContext.mm +21 -0
- package/apple/WebGPUMetalView.h +12 -0
- package/apple/WebGPUMetalView.mm +93 -0
- package/apple/WebGPUView.h +20 -0
- package/apple/WebGPUView.mm +77 -0
- package/cpp/api/JsiSkImage.h +76 -0
- package/cpp/api/JsiSkSurfaceFactory.h +12 -1
- package/cpp/jsi2/JSIConverter.h +11 -0
- package/cpp/rnskia/RNDawnContext.h +24 -16
- package/cpp/rnskia/RNDawnUtils.h +12 -0
- package/cpp/rnskia/RNSkManager.cpp +11 -4
- package/cpp/rnskia/RNSkPlatformContext.h +3 -1
- package/cpp/rnwgpu/Canvas.h +45 -0
- package/cpp/rnwgpu/PlatformContext.h +18 -0
- package/cpp/rnwgpu/SurfaceRegistry.h +229 -0
- package/cpp/rnwgpu/api/GPUAdapter.cpp +26 -0
- package/cpp/rnwgpu/api/GPUCanvasContext.cpp +64 -0
- package/cpp/rnwgpu/api/GPUCanvasContext.h +65 -0
- package/cpp/rnwgpu/api/GPUDevice.cpp +52 -0
- package/cpp/rnwgpu/api/GPUDevice.h +62 -1
- package/cpp/rnwgpu/api/GPUUncapturedErrorEvent.h +61 -0
- package/cpp/rnwgpu/api/RNWebGPU.h +62 -0
- package/cpp/rnwgpu/api/descriptors/GPUBindGroupEntry.h +4 -0
- package/cpp/rnwgpu/api/descriptors/GPUCanvasConfiguration.h +76 -0
- package/lib/commonjs/external/reanimated/useVideo.js +1 -4
- package/lib/commonjs/external/reanimated/useVideo.js.map +1 -1
- package/lib/commonjs/mock/index.js +1 -0
- package/lib/commonjs/mock/index.js.map +1 -1
- package/lib/commonjs/skia/types/Surface/SurfaceFactory.d.ts +10 -1
- package/lib/commonjs/skia/types/Surface/SurfaceFactory.js +5 -0
- package/lib/commonjs/skia/types/Surface/SurfaceFactory.js.map +1 -1
- package/lib/commonjs/sksg/Container.native.js +4 -0
- package/lib/commonjs/sksg/Container.native.js.map +1 -1
- package/lib/commonjs/sksg/Container.web.js +4 -0
- package/lib/commonjs/sksg/Container.web.js.map +1 -1
- package/lib/commonjs/specs/WebGPUViewNativeComponent.d.ts +8 -0
- package/lib/commonjs/specs/WebGPUViewNativeComponent.js +11 -0
- package/lib/commonjs/specs/WebGPUViewNativeComponent.js.map +1 -0
- package/lib/commonjs/specs/WebGPUViewNativeComponent.web.d.ts +8 -0
- package/lib/commonjs/specs/WebGPUViewNativeComponent.web.js +101 -0
- package/lib/commonjs/specs/WebGPUViewNativeComponent.web.js.map +1 -0
- package/lib/commonjs/specs/utils.d.ts +1 -0
- package/lib/commonjs/specs/utils.js +11 -0
- package/lib/commonjs/specs/utils.js.map +1 -0
- package/lib/commonjs/views/WebGPUCanvas.d.ts +32 -0
- package/lib/commonjs/views/WebGPUCanvas.js +66 -0
- package/lib/commonjs/views/WebGPUCanvas.js.map +1 -0
- package/lib/commonjs/views/WebGPUCanvas.web.d.ts +23 -0
- package/lib/commonjs/views/WebGPUCanvas.web.js +20 -0
- package/lib/commonjs/views/WebGPUCanvas.web.js.map +1 -0
- package/lib/commonjs/views/index.d.ts +1 -0
- package/lib/commonjs/views/index.js +11 -0
- package/lib/commonjs/views/index.js.map +1 -1
- package/lib/module/external/reanimated/useVideo.js +1 -4
- package/lib/module/external/reanimated/useVideo.js.map +1 -1
- package/lib/module/mock/index.js +1 -0
- package/lib/module/mock/index.js.map +1 -1
- package/lib/module/skia/types/Surface/SurfaceFactory.d.ts +10 -1
- package/lib/module/skia/types/Surface/SurfaceFactory.js +4 -1
- package/lib/module/skia/types/Surface/SurfaceFactory.js.map +1 -1
- package/lib/module/sksg/Container.native.js +5 -0
- package/lib/module/sksg/Container.native.js.map +1 -1
- package/lib/module/sksg/Container.web.js +5 -0
- package/lib/module/sksg/Container.web.js.map +1 -1
- package/lib/module/specs/WebGPUViewNativeComponent.d.ts +8 -0
- package/lib/module/specs/WebGPUViewNativeComponent.js +4 -0
- package/lib/module/specs/WebGPUViewNativeComponent.js.map +1 -0
- package/lib/module/specs/WebGPUViewNativeComponent.web.d.ts +8 -0
- package/lib/module/specs/WebGPUViewNativeComponent.web.js +94 -0
- package/lib/module/specs/WebGPUViewNativeComponent.web.js.map +1 -0
- package/lib/module/specs/utils.d.ts +1 -0
- package/lib/module/specs/utils.js +5 -0
- package/lib/module/specs/utils.js.map +1 -0
- package/lib/module/views/WebGPUCanvas.d.ts +32 -0
- package/lib/module/views/WebGPUCanvas.js +57 -0
- package/lib/module/views/WebGPUCanvas.js.map +1 -0
- package/lib/module/views/WebGPUCanvas.web.d.ts +23 -0
- package/lib/module/views/WebGPUCanvas.web.js +12 -0
- package/lib/module/views/WebGPUCanvas.web.js.map +1 -0
- package/lib/module/views/index.d.ts +1 -0
- package/lib/module/views/index.js +1 -0
- package/lib/module/views/index.js.map +1 -1
- package/lib/typescript/lib/commonjs/mock/index.d.ts +1 -0
- package/lib/typescript/lib/commonjs/skia/types/Surface/SurfaceFactory.d.ts +4 -0
- package/lib/typescript/lib/commonjs/specs/WebGPUViewNativeComponent.d.ts +3 -0
- package/lib/typescript/lib/commonjs/specs/WebGPUViewNativeComponent.web.d.ts +3 -0
- package/lib/typescript/lib/commonjs/specs/utils.d.ts +2 -0
- package/lib/typescript/lib/commonjs/views/WebGPUCanvas.d.ts +6 -0
- package/lib/typescript/lib/commonjs/views/WebGPUCanvas.web.d.ts +6 -0
- package/lib/typescript/lib/module/mock/index.d.ts +7 -1
- package/lib/typescript/lib/module/skia/types/Surface/SurfaceFactory.d.ts +4 -1
- package/lib/typescript/lib/module/specs/WebGPUViewNativeComponent.d.ts +2 -0
- package/lib/typescript/lib/module/specs/WebGPUViewNativeComponent.web.d.ts +2 -0
- package/lib/typescript/lib/module/specs/utils.d.ts +1 -0
- package/lib/typescript/lib/module/views/WebGPUCanvas.d.ts +7 -0
- package/lib/typescript/lib/module/views/WebGPUCanvas.web.d.ts +8 -0
- package/lib/typescript/lib/module/views/index.d.ts +1 -0
- package/lib/typescript/src/skia/types/Surface/SurfaceFactory.d.ts +10 -1
- package/lib/typescript/src/specs/WebGPUViewNativeComponent.d.ts +8 -0
- package/lib/typescript/src/specs/WebGPUViewNativeComponent.web.d.ts +8 -0
- package/lib/typescript/src/specs/utils.d.ts +1 -0
- package/lib/typescript/src/views/WebGPUCanvas.d.ts +32 -0
- package/lib/typescript/src/views/WebGPUCanvas.web.d.ts +23 -0
- package/lib/typescript/src/views/index.d.ts +1 -0
- package/package.json +7 -3
- package/react-native-skia.podspec +16 -83
- package/scripts/install-libs.js +131 -0
- package/src/external/reanimated/useVideo.ts +1 -4
- package/src/mock/index.ts +1 -0
- package/src/skia/types/Surface/SurfaceFactory.ts +17 -1
- package/src/sksg/Container.native.ts +3 -0
- package/src/sksg/Container.web.ts +3 -0
- package/src/specs/WebGPUViewNativeComponent.ts +11 -0
- package/src/specs/WebGPUViewNativeComponent.web.ts +108 -0
- package/src/specs/utils.ts +4 -0
- package/src/views/WebGPUCanvas.tsx +109 -0
- package/src/views/WebGPUCanvas.web.tsx +36 -0
- package/src/views/index.ts +1 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["_react","_interopRequireWildcard","require","_reactNative","_WebGPUViewNativeComponent","_interopRequireDefault","e","__esModule","default","t","WeakMap","r","n","o","i","f","__proto__","has","get","set","hasOwnProperty","call","Object","defineProperty","getOwnPropertyDescriptor","_extends","assign","bind","arguments","length","apply","CONTEXT_COUNTER","generateContextId","WebGPUCanvas","transparent","ref","props","viewRef","useRef","contextId","useState","useImperativeHandle","getContextId","getNativeSurface","RNWebGPU","Error","getContext","contextName","current","view","size","getBoundingClientRect","unstable_getBoundingClientRect","MakeWebGPUCanvasContext","width","height","Platform","OS","createElement","View","collapsable","style","flex","exports"],"sources":["WebGPUCanvas.tsx"],"sourcesContent":["import React, { useImperativeHandle, useRef, useState } from \"react\";\nimport type { ViewProps } from \"react-native\";\nimport { View, Platform } from \"react-native\";\n\nimport WebGPUNativeView from \"../specs/WebGPUViewNativeComponent\";\n\nlet CONTEXT_COUNTER = 1;\nfunction generateContextId() {\n return CONTEXT_COUNTER++;\n}\n\ndeclare global {\n var RNWebGPU: {\n gpu: GPU;\n fabric: boolean;\n getNativeSurface: (contextId: number) => NativeCanvas;\n MakeWebGPUCanvasContext: (\n contextId: number,\n width: number,\n height: number\n ) => RNCanvasContext;\n };\n}\n\ntype SurfacePointer = bigint;\n\nexport interface NativeCanvas {\n surface: SurfacePointer;\n width: number;\n height: number;\n clientWidth: number;\n clientHeight: number;\n}\n\nexport type RNCanvasContext = GPUCanvasContext & {\n present: () => void;\n};\n\nexport interface WebGPUCanvasRef {\n getContextId: () => number;\n getContext(contextName: \"webgpu\"): RNCanvasContext | null;\n getNativeSurface: () => NativeCanvas;\n}\n\ninterface WebGPUCanvasProps extends ViewProps {\n transparent?: boolean;\n ref?: React.Ref<WebGPUCanvasRef>;\n}\n\nexport const WebGPUCanvas = ({\n transparent,\n ref,\n ...props\n}: WebGPUCanvasProps) => {\n const viewRef = useRef(null);\n const [contextId] = useState(() => generateContextId());\n\n useImperativeHandle(ref, () => ({\n getContextId: () => contextId,\n getNativeSurface: () => {\n if (typeof RNWebGPU === \"undefined\") {\n throw new Error(\n \"[WebGPU] RNWebGPU is not available. Make sure SK_GRAPHITE is enabled.\"\n );\n }\n return RNWebGPU.getNativeSurface(contextId);\n },\n getContext(contextName: \"webgpu\"): RNCanvasContext | null {\n if (contextName !== \"webgpu\") {\n throw new Error(`[WebGPU] Unsupported context: ${contextName}`);\n }\n if (!viewRef.current) {\n throw new Error(\"[WebGPU] Cannot get context before mount\");\n }\n if (typeof RNWebGPU === \"undefined\") {\n throw new Error(\n \"[WebGPU] RNWebGPU is not available. Make sure SK_GRAPHITE is enabled.\"\n );\n }\n // getBoundingClientRect became stable in RN 0.83\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n const view = viewRef.current as any;\n const size =\n \"getBoundingClientRect\" in view\n ? view.getBoundingClientRect()\n : view.unstable_getBoundingClientRect();\n return RNWebGPU.MakeWebGPUCanvasContext(\n contextId,\n size.width,\n size.height\n );\n },\n }));\n\n // WebGPU Canvas is not supported on web\n if (Platform.OS === \"web\") {\n return <View {...props} />;\n }\n\n return (\n <View collapsable={false} ref={viewRef} {...props}>\n <WebGPUNativeView\n style={{ flex: 1 }}\n contextId={contextId}\n transparent={!!transparent}\n />\n </View>\n );\n};\n"],"mappings":";;;;;;AAAA,IAAAA,MAAA,GAAAC,uBAAA,CAAAC,OAAA;AAEA,IAAAC,YAAA,GAAAD,OAAA;AAEA,IAAAE,0BAAA,GAAAC,sBAAA,CAAAH,OAAA;AAAkE,SAAAG,uBAAAC,CAAA,WAAAA,CAAA,IAAAA,CAAA,CAAAC,UAAA,GA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AAC,CAAC,GAC5BF,IAAI,CAACG,8BAA8B,CAAC,CAAC;MAC3C,OAAOR,QAAQ,CAACS,uBAAuB,CACrCd,SAAS,EACTW,IAAI,CAACI,KAAK,EACVJ,IAAI,CAACK,MACP,CAAC;IACH;EACF,CAAC,CAAC,CAAC;;EAEH;EACA,IAAIC,qBAAQ,CAACC,EAAE,KAAK,KAAK,EAAE;IACzB,oBAAOzD,MAAA,CAAAQ,OAAA,CAAAkD,aAAA,CAACvD,YAAA,CAAAwD,IAAI,EAAKvB,KAAQ,CAAC;EAC5B;EAEA,oBACEpC,MAAA,CAAAQ,OAAA,CAAAkD,aAAA,CAACvD,YAAA,CAAAwD,IAAI,EAAAlC,QAAA;IAACmC,WAAW,EAAE,KAAM;IAACzB,GAAG,EAAEE;EAAQ,GAAKD,KAAK,gBAC/CpC,MAAA,CAAAQ,OAAA,CAAAkD,aAAA,CAACtD,0BAAA,CAAAI,OAAgB;IACfqD,KAAK,EAAE;MAAEC,IAAI,EAAE;IAAE,CAAE;IACnBvB,SAAS,EAAEA,SAAU;IACrBL,WAAW,EAAE,CAAC,CAACA;EAAY,CAC5B,CACG,CAAC;AAEX,CAAC;AAAC6B,OAAA,CAAA9B,YAAA,GAAAA,YAAA","ignoreList":[]}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import type { ViewProps } from "react-native";
|
|
3
|
+
export interface NativeCanvas {
|
|
4
|
+
surface: bigint;
|
|
5
|
+
width: number;
|
|
6
|
+
height: number;
|
|
7
|
+
clientWidth: number;
|
|
8
|
+
clientHeight: number;
|
|
9
|
+
}
|
|
10
|
+
export type RNCanvasContext = GPUCanvasContext & {
|
|
11
|
+
present: () => void;
|
|
12
|
+
};
|
|
13
|
+
export interface WebGPUCanvasRef {
|
|
14
|
+
getContextId: () => number;
|
|
15
|
+
getContext(contextName: "webgpu"): RNCanvasContext | null;
|
|
16
|
+
getNativeSurface: () => NativeCanvas;
|
|
17
|
+
}
|
|
18
|
+
interface WebGPUCanvasProps extends ViewProps {
|
|
19
|
+
transparent?: boolean;
|
|
20
|
+
ref?: React.Ref<WebGPUCanvasRef>;
|
|
21
|
+
}
|
|
22
|
+
export declare const WebGPUCanvas: ({ transparent: _transparent, ref: _ref, ...props }: WebGPUCanvasProps) => React.JSX.Element;
|
|
23
|
+
export {};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.WebGPUCanvas = void 0;
|
|
7
|
+
var _react = _interopRequireDefault(require("react"));
|
|
8
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
9
|
+
// WebGPU Canvas is not supported on web
|
|
10
|
+
const WebGPUCanvas = ({
|
|
11
|
+
transparent: _transparent,
|
|
12
|
+
ref: _ref,
|
|
13
|
+
...props
|
|
14
|
+
}) => {
|
|
15
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
16
|
+
// @ts-expect-error
|
|
17
|
+
return /*#__PURE__*/_react.default.createElement("div", props);
|
|
18
|
+
};
|
|
19
|
+
exports.WebGPUCanvas = WebGPUCanvas;
|
|
20
|
+
//# sourceMappingURL=WebGPUCanvas.web.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["_react","_interopRequireDefault","require","e","__esModule","default","WebGPUCanvas","transparent","_transparent","ref","_ref","props","createElement","exports"],"sources":["WebGPUCanvas.web.tsx"],"sourcesContent":["import React from \"react\";\nimport type { ViewProps } from \"react-native\";\n\nexport interface NativeCanvas {\n surface: bigint;\n width: number;\n height: number;\n clientWidth: number;\n clientHeight: number;\n}\n\nexport type RNCanvasContext = GPUCanvasContext & {\n present: () => void;\n};\n\nexport interface WebGPUCanvasRef {\n getContextId: () => number;\n getContext(contextName: \"webgpu\"): RNCanvasContext | null;\n getNativeSurface: () => NativeCanvas;\n}\n\ninterface WebGPUCanvasProps extends ViewProps {\n transparent?: boolean;\n ref?: React.Ref<WebGPUCanvasRef>;\n}\n\n// WebGPU Canvas is not supported on web\nexport const WebGPUCanvas = ({\n transparent: _transparent,\n ref: _ref,\n ...props\n}: WebGPUCanvasProps) => {\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-expect-error\n return <div {...props} />;\n};\n"],"mappings":";;;;;;AAAA,IAAAA,MAAA,GAAAC,sBAAA,CAAAC,OAAA;AAA0B,SAAAD,uBAAAE,CAAA,WAAAA,CAAA,IAAAA,CAAA,CAAAC,UAAA,GAAAD,CAAA,KAAAE,OAAA,EAAAF,CAAA;AA0B1B;AACO,MAAMG,YAAY,GAAGA,CAAC;EAC3BC,WAAW,EAAEC,YAAY;EACzBC,GAAG,EAAEC,IAAI;EACT,GAAGC;AACc,CAAC,KAAK;EACvB;EACA;EACA,oBAAOX,MAAA,CAAAK,OAAA,CAAAO,aAAA,QAASD,KAAQ,CAAC;AAC3B,CAAC;AAACE,OAAA,CAAAP,YAAA,GAAAA,YAAA","ignoreList":[]}
|
|
@@ -25,4 +25,15 @@ Object.keys(_types).forEach(function (key) {
|
|
|
25
25
|
}
|
|
26
26
|
});
|
|
27
27
|
});
|
|
28
|
+
var _WebGPUCanvas = require("./WebGPUCanvas");
|
|
29
|
+
Object.keys(_WebGPUCanvas).forEach(function (key) {
|
|
30
|
+
if (key === "default" || key === "__esModule") return;
|
|
31
|
+
if (key in exports && exports[key] === _WebGPUCanvas[key]) return;
|
|
32
|
+
Object.defineProperty(exports, key, {
|
|
33
|
+
enumerable: true,
|
|
34
|
+
get: function () {
|
|
35
|
+
return _WebGPUCanvas[key];
|
|
36
|
+
}
|
|
37
|
+
});
|
|
38
|
+
});
|
|
28
39
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_SkiaPictureView","require","Object","keys","forEach","key","exports","defineProperty","enumerable","get","_types"],"sources":["index.ts"],"sourcesContent":["export * from \"./SkiaPictureView\";\nexport * from \"./types\";\n"],"mappings":";;;;;AAAA,IAAAA,gBAAA,GAAAC,OAAA;AAAAC,MAAA,CAAAC,IAAA,CAAAH,gBAAA,EAAAI,OAAA,WAAAC,GAAA;EAAA,IAAAA,GAAA,kBAAAA,GAAA;EAAA,IAAAA,GAAA,IAAAC,OAAA,IAAAA,OAAA,CAAAD,GAAA,MAAAL,gBAAA,CAAAK,GAAA;EAAAH,MAAA,CAAAK,cAAA,CAAAD,OAAA,EAAAD,GAAA;IAAAG,UAAA;IAAAC,GAAA,WAAAA,CAAA;MAAA,OAAAT,gBAAA,CAAAK,GAAA;IAAA;EAAA;AAAA;AACA,IAAAK,MAAA,GAAAT,OAAA;AAAAC,MAAA,CAAAC,IAAA,CAAAO,MAAA,EAAAN,OAAA,WAAAC,GAAA;EAAA,IAAAA,GAAA,kBAAAA,GAAA;EAAA,IAAAA,GAAA,IAAAC,OAAA,IAAAA,OAAA,CAAAD,GAAA,MAAAK,MAAA,CAAAL,GAAA;EAAAH,MAAA,CAAAK,cAAA,CAAAD,OAAA,EAAAD,GAAA;IAAAG,UAAA;IAAAC,GAAA,WAAAA,CAAA;MAAA,OAAAC,MAAA,CAAAL,GAAA;IAAA;EAAA;AAAA","ignoreList":[]}
|
|
1
|
+
{"version":3,"names":["_SkiaPictureView","require","Object","keys","forEach","key","exports","defineProperty","enumerable","get","_types","_WebGPUCanvas"],"sources":["index.ts"],"sourcesContent":["export * from \"./SkiaPictureView\";\nexport * from \"./types\";\nexport * from \"./WebGPUCanvas\";\n"],"mappings":";;;;;AAAA,IAAAA,gBAAA,GAAAC,OAAA;AAAAC,MAAA,CAAAC,IAAA,CAAAH,gBAAA,EAAAI,OAAA,WAAAC,GAAA;EAAA,IAAAA,GAAA,kBAAAA,GAAA;EAAA,IAAAA,GAAA,IAAAC,OAAA,IAAAA,OAAA,CAAAD,GAAA,MAAAL,gBAAA,CAAAK,GAAA;EAAAH,MAAA,CAAAK,cAAA,CAAAD,OAAA,EAAAD,GAAA;IAAAG,UAAA;IAAAC,GAAA,WAAAA,CAAA;MAAA,OAAAT,gBAAA,CAAAK,GAAA;IAAA;EAAA;AAAA;AACA,IAAAK,MAAA,GAAAT,OAAA;AAAAC,MAAA,CAAAC,IAAA,CAAAO,MAAA,EAAAN,OAAA,WAAAC,GAAA;EAAA,IAAAA,GAAA,kBAAAA,GAAA;EAAA,IAAAA,GAAA,IAAAC,OAAA,IAAAA,OAAA,CAAAD,GAAA,MAAAK,MAAA,CAAAL,GAAA;EAAAH,MAAA,CAAAK,cAAA,CAAAD,OAAA,EAAAD,GAAA;IAAAG,UAAA;IAAAC,GAAA,WAAAA,CAAA;MAAA,OAAAC,MAAA,CAAAL,GAAA;IAAA;EAAA;AAAA;AACA,IAAAM,aAAA,GAAAV,OAAA;AAAAC,MAAA,CAAAC,IAAA,CAAAQ,aAAA,EAAAP,OAAA,WAAAC,GAAA;EAAA,IAAAA,GAAA,kBAAAA,GAAA;EAAA,IAAAA,GAAA,IAAAC,OAAA,IAAAA,OAAA,CAAAD,GAAA,MAAAM,aAAA,CAAAN,GAAA;EAAAH,MAAA,CAAAK,cAAA,CAAAD,OAAA,EAAAD,GAAA;IAAAG,UAAA;IAAAC,GAAA,WAAAA,CAAA;MAAA,OAAAE,aAAA,CAAAN,GAAA;IAAA;EAAA;AAAA","ignoreList":[]}
|
|
@@ -9,7 +9,7 @@ const copyFrameOnAndroid = currentFrame => {
|
|
|
9
9
|
if (Platform.OS === "android") {
|
|
10
10
|
const tex = currentFrame.value;
|
|
11
11
|
if (tex) {
|
|
12
|
-
currentFrame.value = tex
|
|
12
|
+
currentFrame.value = tex; //.makeNonTextureImage();
|
|
13
13
|
tex.dispose();
|
|
14
14
|
}
|
|
15
15
|
}
|
|
@@ -19,9 +19,6 @@ const setFrame = (video, currentFrame) => {
|
|
|
19
19
|
|
|
20
20
|
const img = video.nextImage();
|
|
21
21
|
if (img) {
|
|
22
|
-
if (currentFrame.value) {
|
|
23
|
-
currentFrame.value.dispose();
|
|
24
|
-
}
|
|
25
22
|
currentFrame.value = img;
|
|
26
23
|
copyFrameOnAndroid(currentFrame);
|
|
27
24
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["useEffect","useMemo","Platform","Rea","useVideoLoading","copyFrameOnAndroid","currentFrame","OS","tex","value","
|
|
1
|
+
{"version":3,"names":["useEffect","useMemo","Platform","Rea","useVideoLoading","copyFrameOnAndroid","currentFrame","OS","tex","value","dispose","setFrame","video","img","nextImage","defaultOptions","looping","paused","seek","volume","useOption","defaultValue","useSharedValue","isSharedValue","disposeVideo","useVideo","source","userOptions","_userOptions$paused","_userOptions$looping","_userOptions$seek","_userOptions$volume","isPaused","currentTime","duration","_video$duration","framerate","_video$framerate","size","_video$size","width","height","rotation","_video$rotation","useAnimatedReaction","pause","play","setVolume","setLooping","useFrameCallback","_frameInfo","runOnUI"],"sources":["useVideo.ts"],"sourcesContent":["import type { SharedValue, FrameInfo } from \"react-native-reanimated\";\nimport { useEffect, useMemo } from \"react\";\n\nimport type { SkImage, Video } from \"../../skia/types\";\nimport { Platform } from \"../../Platform\";\n\nimport Rea from \"./ReanimatedProxy\";\nimport { useVideoLoading } from \"./useVideoLoading\";\n\ntype MaybeAnimated<T> = SharedValue<T> | T;\n\ninterface PlaybackOptions {\n looping: MaybeAnimated<boolean>;\n paused: MaybeAnimated<boolean>;\n seek: MaybeAnimated<number | null>;\n volume: MaybeAnimated<number>;\n}\n\nconst copyFrameOnAndroid = (currentFrame: SharedValue<SkImage | null>) => {\n \"worklet\";\n // on android we need to copy the texture before it's invalidated\n if (Platform.OS === \"android\") {\n const tex = currentFrame.value;\n if (tex) {\n currentFrame.value = tex; //.makeNonTextureImage();\n tex.dispose();\n }\n }\n};\n\nconst setFrame = (video: Video, currentFrame: SharedValue<SkImage | null>) => {\n \"worklet\";\n const img = video.nextImage();\n if (img) {\n currentFrame.value = img;\n copyFrameOnAndroid(currentFrame);\n }\n};\n\nconst defaultOptions = {\n looping: true,\n paused: false,\n seek: null,\n volume: 0,\n};\n\nconst useOption = <T>(value: MaybeAnimated<T>) => {\n \"worklet\";\n const defaultValue = Rea.useSharedValue(\n Rea.isSharedValue(value) ? value.value : value\n );\n return Rea.isSharedValue(value)\n ? (value as SharedValue<T>)\n : (defaultValue as SharedValue<T>);\n};\n\nconst disposeVideo = (video: Video | null) => {\n \"worklet\";\n video?.dispose();\n};\n\nexport const useVideo = (\n source: string | null,\n userOptions?: Partial<PlaybackOptions>\n) => {\n const video = useVideoLoading(source);\n const isPaused = useOption(userOptions?.paused ?? defaultOptions.paused);\n const looping = useOption(userOptions?.looping ?? defaultOptions.looping);\n const seek = useOption(userOptions?.seek ?? defaultOptions.seek);\n const volume = useOption(userOptions?.volume ?? defaultOptions.volume);\n const currentFrame = Rea.useSharedValue<null | SkImage>(null);\n const currentTime = Rea.useSharedValue(0);\n const duration = useMemo(() => video?.duration() ?? 0, [video]);\n const framerate = useMemo(\n () => (Platform.OS === \"web\" ? -1 : (video?.framerate() ?? 0)),\n [video]\n );\n const size = useMemo(() => video?.size() ?? { width: 0, height: 0 }, [video]);\n const rotation = useMemo(() => video?.rotation() ?? 0, [video]);\n\n // Handle pause/play state changes\n Rea.useAnimatedReaction(\n () => isPaused.value,\n (paused) => {\n if (paused) {\n video?.pause();\n } else {\n video?.play();\n }\n }\n );\n\n // Handle seek\n Rea.useAnimatedReaction(\n () => seek.value,\n (value) => {\n if (value !== null) {\n video?.seek(value);\n seek.value = null;\n }\n }\n );\n\n // Handle volume changes\n Rea.useAnimatedReaction(\n () => volume.value,\n (value) => {\n video?.setVolume(value);\n }\n );\n\n // Handle looping changes\n Rea.useAnimatedReaction(\n () => looping.value,\n (value) => {\n video?.setLooping(value);\n }\n );\n\n // Frame callback - simplified since native handles frame timing\n Rea.useFrameCallback((_frameInfo: FrameInfo) => {\n \"worklet\";\n if (!video) {\n return;\n }\n // Update current time from native player\n currentTime.value = video.currentTime();\n // Get the latest frame (native handles timing via CADisplayLink/etc)\n setFrame(video, currentFrame);\n });\n\n // Apply initial state when video becomes available\n useEffect(() => {\n if (video) {\n video.setLooping(looping.value);\n video.setVolume(volume.value);\n if (isPaused.value) {\n video.pause();\n } else {\n video.play();\n }\n }\n return () => {\n Rea.runOnUI(disposeVideo)(video);\n };\n }, [video, isPaused, looping, volume]);\n\n return {\n currentFrame,\n currentTime,\n duration,\n framerate,\n rotation,\n size,\n };\n};\n"],"mappings":"AACA,SAASA,SAAS,EAAEC,OAAO,QAAQ,OAAO;AAG1C,SAASC,QAAQ,QAAQ,gBAAgB;AAEzC,OAAOC,GAAG,MAAM,mBAAmB;AACnC,SAASC,eAAe,QAAQ,mBAAmB;AAWnD,MAAMC,kBAAkB,GAAIC,YAAyC,IAAK;EACxE,SAAS;;EACT;EACA,IAAIJ,QAAQ,CAACK,EAAE,KAAK,SAAS,EAAE;IAC7B,MAAMC,GAAG,GAAGF,YAAY,CAACG,KAAK;IAC9B,IAAID,GAAG,EAAE;MACPF,YAAY,CAACG,KAAK,GAAGD,GAAG,CAAC,CAAC;MAC1BA,GAAG,CAACE,OAAO,CAAC,CAAC;IACf;EACF;AACF,CAAC;AAED,MAAMC,QAAQ,GAAGA,CAACC,KAAY,EAAEN,YAAyC,KAAK;EAC5E,SAAS;;EACT,MAAMO,GAAG,GAAGD,KAAK,CAACE,SAAS,CAAC,CAAC;EAC7B,IAAID,GAAG,EAAE;IACPP,YAAY,CAACG,KAAK,GAAGI,GAAG;IACxBR,kBAAkB,CAACC,YAAY,CAAC;EAClC;AACF,CAAC;AAED,MAAMS,cAAc,GAAG;EACrBC,OAAO,EAAE,IAAI;EACbC,MAAM,EAAE,KAAK;EACbC,IAAI,EAAE,IAAI;EACVC,MAAM,EAAE;AACV,CAAC;AAED,MAAMC,SAAS,GAAOX,KAAuB,IAAK;EAChD,SAAS;;EACT,MAAMY,YAAY,GAAGlB,GAAG,CAACmB,cAAc,CACrCnB,GAAG,CAACoB,aAAa,CAACd,KAAK,CAAC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ACX3C,GAAG,CAACgD,OAAO,CAAC3B,YAAY,CAAC,CAACZ,KAAK,CAAC;IAClC,CAAC;EACH,CAAC,EAAE,CAACA,KAAK,EAAEoB,QAAQ,EAAEhB,OAAO,EAAEG,MAAM,CAAC,CAAC;EAEtC,OAAO;IACLb,YAAY;IACZ2B,WAAW;IACXC,QAAQ;IACRE,SAAS;IACTM,QAAQ;IACRJ;EACF,CAAC;AACH,CAAC","ignoreList":[]}
|
package/lib/module/mock/index.js
CHANGED
|
@@ -24,6 +24,7 @@ export const Mock = CanvasKit => {
|
|
|
24
24
|
...require("../dom/types"),
|
|
25
25
|
...require("../dom/nodes"),
|
|
26
26
|
Canvas: require("react-native").View,
|
|
27
|
+
WebGPUCanvas: require("react-native").View,
|
|
27
28
|
SkiaPictureView: require("react-native").View,
|
|
28
29
|
JsiSkImage: JsiSkImage,
|
|
29
30
|
drawAsPicture: Noop,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["JsiSkApi","JsiSkImage","Noop","undefined","NoopValue","current","NoopSharedValue","value","Mock","CanvasKit","global","SkiaApi","Skia","require","Canvas","View","SkiaPictureView","drawAsPicture","drawAsImage","drawAsImageFromPicture","useCanvasRef","useCanvasSize","ref","size","width","height","useValue","useComputedValue","useTiming","useLoop","useSpring","useClockValue","useValueEffect","isOnMainThread","isFabric","useClock","usePathInterpolation","useImageAsTexture","useTextureValue","useTextureValueFromPicture","useRSXformBuffer","usePointBuffer","useColorBuffer","useRectBuffer","useBuffer","useRawData","useData","useFont","Font","useFonts","useTypeface","useImage","useSVG","useVideo"],"sources":["index.ts"],"sourcesContent":["import type { CanvasKit } from \"canvaskit-wasm\";\n\nimport { JsiSkApi } from \"../skia/web\";\nimport { JsiSkImage } from \"../skia/web/JsiSkImage\";\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nconst Noop: () => any = () => undefined;\nconst NoopValue = () => ({ current: 0 });\nconst NoopSharedValue = () => ({ value: 0 });\n\nexport const Mock = (CanvasKit: CanvasKit) => {\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore\n global.SkiaApi = JsiSkApi(CanvasKit);\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore\n const Skia = global.SkiaApi;\n return {\n Skia,\n ...require(\"../renderer/components\"),\n ...require(\"../skia\"),\n ...require(\"../animation\"),\n ...require(\"../dom/types\"),\n ...require(\"../dom/nodes\"),\n Canvas: require(\"react-native\").View,\n SkiaPictureView: require(\"react-native\").View,\n JsiSkImage: JsiSkImage,\n drawAsPicture: Noop,\n drawAsImage: Noop,\n drawAsImageFromPicture: Noop,\n useCanvasRef: NoopValue,\n useCanvasSize: () => ({\n ref: {\n current: 0,\n },\n size: {\n width: 0,\n height: 0,\n },\n }),\n // Skia Animations\n useValue: NoopValue,\n useComputedValue: NoopValue,\n useTiming: NoopValue,\n useLoop: NoopValue,\n useSpring: NoopValue,\n useClockValue: NoopValue,\n useValueEffect: Noop,\n // Reanimated hooks\n isOnMainThread: () => true,\n isFabric: true,\n useClock: NoopSharedValue,\n usePathInterpolation: NoopSharedValue,\n useImageAsTexture: NoopSharedValue,\n useTextureValue: NoopSharedValue,\n useTextureValueFromPicture: NoopSharedValue,\n useRSXformBuffer: NoopSharedValue,\n usePointBuffer: NoopSharedValue,\n useColorBuffer: NoopSharedValue,\n useRectBuffer: NoopSharedValue,\n useBuffer: NoopSharedValue,\n useRawData: Noop,\n useData: Noop,\n useFont: () => Skia.Font(undefined, 0),\n useFonts: Noop,\n useTypeface: () => null,\n useImage: () => null,\n useSVG: () => null,\n useVideo: () => null,\n };\n};\n"],"mappings":"AAEA,SAASA,QAAQ,QAAQ,aAAa;AACtC,SAASC,UAAU,QAAQ,wBAAwB;;AAEnD;AACA,MAAMC,IAAe,GAAGA,CAAA,KAAMC,SAAS;AACvC,MAAMC,SAAS,GAAGA,CAAA,MAAO;EAAEC,OAAO,EAAE;AAAE,CAAC,CAAC;AACxC,MAAMC,eAAe,GAAGA,CAAA,MAAO;EAAEC,KAAK,EAAE;AAAE,CAAC,CAAC;AAE5C,OAAO,MAAMC,IAAI,GAAIC,SAAoB,IAAK;EAC5C;EACA;EACAC,MAAM,CAACC,OAAO,GAAGX,QAAQ,CAACS,SAAS,CAAC;EACpC;EACA;EACA,MAAMG,IAAI,GAAGF,MAAM,CAACC,OAAO;EAC3B,OAAO;IACLC,IAAI;IACJ,GAAGC,OAAO,CAAC,wBAAwB,CAAC;IACpC,GAAGA,OAAO,CAAC,SAAS,CAAC;IACrB,GAAGA,OAAO,CAAC,cAAc,CAAC;IAC1B,GAAGA,OAAO,CAAC,cAAc,CAAC;IAC1B,GAAGA,OAAO,CAAC,cAAc,CAAC;IAC1BC,MAAM,EAAED,OAAO,CAAC,cAAc,CAAC,CAACE,IAAI;IACpCC,
|
|
1
|
+
{"version":3,"names":["JsiSkApi","JsiSkImage","Noop","undefined","NoopValue","current","NoopSharedValue","value","Mock","CanvasKit","global","SkiaApi","Skia","require","Canvas","View","WebGPUCanvas","SkiaPictureView","drawAsPicture","drawAsImage","drawAsImageFromPicture","useCanvasRef","useCanvasSize","ref","size","width","height","useValue","useComputedValue","useTiming","useLoop","useSpring","useClockValue","useValueEffect","isOnMainThread","isFabric","useClock","usePathInterpolation","useImageAsTexture","useTextureValue","useTextureValueFromPicture","useRSXformBuffer","usePointBuffer","useColorBuffer","useRectBuffer","useBuffer","useRawData","useData","useFont","Font","useFonts","useTypeface","useImage","useSVG","useVideo"],"sources":["index.ts"],"sourcesContent":["import type { CanvasKit } from \"canvaskit-wasm\";\n\nimport { JsiSkApi } from \"../skia/web\";\nimport { JsiSkImage } from \"../skia/web/JsiSkImage\";\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nconst Noop: () => any = () => undefined;\nconst NoopValue = () => ({ current: 0 });\nconst NoopSharedValue = () => ({ value: 0 });\n\nexport const Mock = (CanvasKit: CanvasKit) => {\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore\n global.SkiaApi = JsiSkApi(CanvasKit);\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore\n const Skia = global.SkiaApi;\n return {\n Skia,\n ...require(\"../renderer/components\"),\n ...require(\"../skia\"),\n ...require(\"../animation\"),\n ...require(\"../dom/types\"),\n ...require(\"../dom/nodes\"),\n Canvas: require(\"react-native\").View,\n WebGPUCanvas: require(\"react-native\").View,\n SkiaPictureView: require(\"react-native\").View,\n JsiSkImage: JsiSkImage,\n drawAsPicture: Noop,\n drawAsImage: Noop,\n drawAsImageFromPicture: Noop,\n useCanvasRef: NoopValue,\n useCanvasSize: () => ({\n ref: {\n current: 0,\n },\n size: {\n width: 0,\n height: 0,\n },\n }),\n // Skia Animations\n useValue: NoopValue,\n useComputedValue: NoopValue,\n useTiming: NoopValue,\n useLoop: NoopValue,\n useSpring: NoopValue,\n useClockValue: NoopValue,\n useValueEffect: Noop,\n // Reanimated hooks\n isOnMainThread: () => true,\n isFabric: true,\n useClock: NoopSharedValue,\n usePathInterpolation: NoopSharedValue,\n useImageAsTexture: NoopSharedValue,\n useTextureValue: NoopSharedValue,\n useTextureValueFromPicture: NoopSharedValue,\n useRSXformBuffer: NoopSharedValue,\n usePointBuffer: NoopSharedValue,\n useColorBuffer: NoopSharedValue,\n useRectBuffer: NoopSharedValue,\n useBuffer: NoopSharedValue,\n useRawData: Noop,\n useData: Noop,\n useFont: () => Skia.Font(undefined, 0),\n useFonts: Noop,\n useTypeface: () => null,\n useImage: () => null,\n useSVG: () => null,\n useVideo: () => null,\n };\n};\n"],"mappings":"AAEA,SAASA,QAAQ,QAAQ,aAAa;AACtC,SAASC,UAAU,QAAQ,wBAAwB;;AAEnD;AACA,MAAMC,IAAe,GAAGA,CAAA,KAAMC,SAAS;AACvC,MAAMC,SAAS,GAAGA,CAAA,MAAO;EAAEC,OAAO,EAAE;AAAE,CAAC,CAAC;AACxC,MAAMC,eAAe,GAAGA,CAAA,MAAO;EAAEC,KAAK,EAAE;AAAE,CAAC,CA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AAEhC,eAAe;IAClCiC,eAAe,EAAEjC,eAAe;IAChCkC,0BAA0B,EAAElC,eAAe;IAC3CmC,gBAAgB,EAAEnC,eAAe;IACjCoC,cAAc,EAAEpC,eAAe;IAC/BqC,cAAc,EAAErC,eAAe;IAC/BsC,aAAa,EAAEtC,eAAe;IAC9BuC,SAAS,EAAEvC,eAAe;IAC1BwC,UAAU,EAAE5C,IAAI;IAChB6C,OAAO,EAAE7C,IAAI;IACb8C,OAAO,EAAEA,CAAA,KAAMpC,IAAI,CAACqC,IAAI,CAAC9C,SAAS,EAAE,CAAC,CAAC;IACtC+C,QAAQ,EAAEhD,IAAI;IACdiD,WAAW,EAAEA,CAAA,KAAM,IAAI;IACvBC,QAAQ,EAAEA,CAAA,KAAM,IAAI;IACpBC,MAAM,EAAEA,CAAA,KAAM,IAAI;IAClBC,QAAQ,EAAEA,CAAA,KAAM;EAClB,CAAC;AACH,CAAC","ignoreList":[]}
|
|
@@ -1,4 +1,12 @@
|
|
|
1
1
|
import type { SkSurface } from "./Surface";
|
|
2
|
+
export declare const ColorSpace: {
|
|
3
|
+
readonly SRGB: "srgb";
|
|
4
|
+
readonly DisplayP3: "display-p3";
|
|
5
|
+
};
|
|
6
|
+
export type ColorSpaceValue = (typeof ColorSpace)[keyof typeof ColorSpace];
|
|
7
|
+
export interface SurfaceOptions {
|
|
8
|
+
colorSpace: ColorSpaceValue;
|
|
9
|
+
}
|
|
2
10
|
export interface SurfaceFactory {
|
|
3
11
|
/**
|
|
4
12
|
* Returns a CPU backed surface with the given dimensions, an SRGB colorspace, Unpremul
|
|
@@ -12,6 +20,7 @@ export interface SurfaceFactory {
|
|
|
12
20
|
* Creates a GPU backed surface.
|
|
13
21
|
* @param width - number of pixels of the width of the drawable area.
|
|
14
22
|
* @param height - number of pixels of the height of the drawable area.
|
|
23
|
+
* @param opts - optional surface options (e.g. colorSpace: "display-p3" | "srgb").
|
|
15
24
|
*/
|
|
16
|
-
MakeOffscreen: (width: number, height: number) => SkSurface | null;
|
|
25
|
+
MakeOffscreen: (width: number, height: number, opts?: SurfaceOptions) => SkSurface | null;
|
|
17
26
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":[],"sources":["SurfaceFactory.ts"],"sourcesContent":["import type { SkSurface } from \"./Surface\";\n\nexport interface SurfaceFactory {\n /**\n * Returns a CPU backed surface with the given dimensions, an SRGB colorspace, Unpremul\n * alphaType and 8888 color type. The pixels belonging to this surface will be in memory and\n * not visible.\n * @param width - number of pixels of the width of the drawable area.\n * @param height - number of pixels of the height of the drawable area.\n */\n Make: (width: number, height: number) => SkSurface | null;\n\n /**\n * Creates a GPU backed surface.\n * @param width - number of pixels of the width of the drawable area.\n * @param height - number of pixels of the height of the drawable area.\n */\n MakeOffscreen: (width: number
|
|
1
|
+
{"version":3,"names":["ColorSpace","SRGB","DisplayP3"],"sources":["SurfaceFactory.ts"],"sourcesContent":["import type { SkSurface } from \"./Surface\";\n\nexport const ColorSpace = {\n SRGB: \"srgb\",\n DisplayP3: \"display-p3\",\n} as const;\n\nexport type ColorSpaceValue = (typeof ColorSpace)[keyof typeof ColorSpace];\n\nexport interface SurfaceOptions {\n colorSpace: ColorSpaceValue;\n}\n\nexport interface SurfaceFactory {\n /**\n * Returns a CPU backed surface with the given dimensions, an SRGB colorspace, Unpremul\n * alphaType and 8888 color type. The pixels belonging to this surface will be in memory and\n * not visible.\n * @param width - number of pixels of the width of the drawable area.\n * @param height - number of pixels of the height of the drawable area.\n */\n Make: (width: number, height: number) => SkSurface | null;\n\n /**\n * Creates a GPU backed surface.\n * @param width - number of pixels of the width of the drawable area.\n * @param height - number of pixels of the height of the drawable area.\n * @param opts - optional surface options (e.g. colorSpace: \"display-p3\" | \"srgb\").\n */\n MakeOffscreen: (\n width: number,\n height: number,\n opts?: SurfaceOptions\n ) => SkSurface | null;\n}\n"],"mappings":"AAEA,OAAO,MAAMA,UAAU,GAAG;EACxBC,IAAI,EAAE,MAAM;EACZC,SAAS,EAAE;AACb,CAAU","ignoreList":[]}
|
|
@@ -8,6 +8,11 @@ import { Container, StaticContainer } from "./StaticContainer";
|
|
|
8
8
|
import { visit } from "./Recorder/Visitor";
|
|
9
9
|
import "../skia/NativeSetup";
|
|
10
10
|
import "../views/api";
|
|
11
|
+
|
|
12
|
+
// create local reference for `strictGlobal` option in Worklets
|
|
13
|
+
const {
|
|
14
|
+
SkiaViewApi
|
|
15
|
+
} = globalThis;
|
|
11
16
|
const nativeDrawOnscreen = (nativeId, recorder, picture) => {
|
|
12
17
|
"worklet";
|
|
13
18
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["Rea","HAS_REANIMATED_3","ReanimatedRecorder","Container","StaticContainer","visit","nativeDrawOnscreen","nativeId","recorder","picture","play","
|
|
1
|
+
{"version":3,"names":["Rea","HAS_REANIMATED_3","ReanimatedRecorder","Container","StaticContainer","visit","SkiaViewApi","globalThis","nativeDrawOnscreen","nativeId","recorder","picture","play","setJsiProperty","NativeReanimatedContainer","constructor","Skia","_defineProperty","Picture","MakePicture","redraw","mapperId","stopMapper","unmounted","root","sharedValues","getSharedValues","sharedRecorder","getRecorder","runOnUI","length","startMapper","applyUpdates","createContainer"],"sources":["Container.native.ts"],"sourcesContent":["import Rea from \"../external/reanimated/ReanimatedProxy\";\nimport type { Skia, SkPicture } from \"../skia/types\";\nimport { HAS_REANIMATED_3 } from \"../external/reanimated/renderHelpers\";\nimport type { JsiRecorder } from \"../skia/types/Recorder\";\n\nimport { ReanimatedRecorder } from \"./Recorder/ReanimatedRecorder\";\nimport { Container, StaticContainer } from \"./StaticContainer\";\nimport { visit } from \"./Recorder/Visitor\";\n\nimport \"../skia/NativeSetup\";\nimport \"../views/api\";\n\n// create local reference for `strictGlobal` option in Worklets\nconst { SkiaViewApi } = globalThis;\n\nconst nativeDrawOnscreen = (\n nativeId: number,\n recorder: JsiRecorder,\n picture: SkPicture\n) => {\n \"worklet\";\n\n //const start = performance.now();\n recorder.play(picture);\n //const end = performance.now();\n //console.log(\"Recording time: \", end - start);\n SkiaViewApi.setJsiProperty(nativeId, \"picture\", picture);\n};\n\nclass NativeReanimatedContainer extends Container {\n private mapperId: number | null = null;\n private picture: SkPicture;\n\n constructor(\n Skia: Skia,\n private nativeId: number\n ) {\n super(Skia);\n this.picture = Skia.Picture.MakePicture(null)!;\n }\n\n redraw() {\n if (this.mapperId !== null) {\n Rea.stopMapper(this.mapperId);\n }\n if (this.unmounted) {\n return;\n }\n const recorder = new ReanimatedRecorder(this.Skia);\n const { nativeId, picture } = this;\n visit(recorder, this.root);\n const sharedValues = recorder.getSharedValues();\n const sharedRecorder = recorder.getRecorder();\n // Draw first frame\n Rea.runOnUI(() => {\n \"worklet\";\n nativeDrawOnscreen(nativeId, sharedRecorder, picture);\n })();\n // Animate\n if (sharedValues.length > 0) {\n this.mapperId = Rea.startMapper(() => {\n \"worklet\";\n sharedRecorder.applyUpdates(sharedValues);\n nativeDrawOnscreen(nativeId, sharedRecorder, picture);\n }, sharedValues);\n }\n }\n}\n\nexport const createContainer = (Skia: Skia, nativeId: number) => {\n if (HAS_REANIMATED_3 && nativeId !== -1) {\n return new NativeReanimatedContainer(Skia, nativeId);\n } else {\n return new StaticContainer(Skia, nativeId);\n }\n};\n"],"mappings":";;;AAAA,OAAOA,GAAG,MAAM,wCAAwC;AAExD,SAASC,gBAAgB,QAAQ,sCAAsC;AAGvE,SAASC,kBAAkB,QAAQ,+BAA+B;AAClE,SAASC,SAAS,EAAEC,eAAe,QAAQ,mBAAmB;AAC9D,SAASC,KAAK,QAAQ,oBAAoB;AAE1C,OAAO,qBAAqB;AAC5B,OAAO,cAAc;;AAErB;AACA,MAAM;EAAEC;AAAY,CAAC,GAAGC,UAAU;AAElC,MAAMC,kBAAkB,GAAGA,CACzBC,QAAgB,EAChBC,QAAqB,EACrBC,OAAkB,KACf;EACH,SAAS;;EAET;EACAD,QAAQ,CAACE,IAAI,CAACD,OAAO,CAAC;EACtB;EACA;EACAL,WAAW,CAACO,cAAc,C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D,CAAC,EAAEc,YAAY,CAAC;IAClB;EACF;AACF;AAEA,OAAO,MAAMQ,eAAe,GAAGA,CAACjB,IAAU,EAAEP,QAAgB,KAAK;EAC/D,IAAIR,gBAAgB,IAAIQ,QAAQ,KAAK,CAAC,CAAC,EAAE;IACvC,OAAO,IAAIK,yBAAyB,CAACE,IAAI,EAAEP,QAAQ,CAAC;EACtD,CAAC,MAAM;IACL,OAAO,IAAIL,eAAe,CAACY,IAAI,EAAEP,QAAQ,CAAC;EAC5C;AACF,CAAC","ignoreList":[]}
|
|
@@ -10,6 +10,11 @@ import { createDrawingContext } from "./Recorder/DrawingContext";
|
|
|
10
10
|
import { Container, StaticContainer } from "./StaticContainer";
|
|
11
11
|
import "../skia/NativeSetup";
|
|
12
12
|
import "../views/api";
|
|
13
|
+
|
|
14
|
+
// create local reference for `strictGlobal` option in Worklets
|
|
15
|
+
const {
|
|
16
|
+
SkiaViewApi
|
|
17
|
+
} = globalThis;
|
|
13
18
|
const drawOnscreen = (Skia, nativeId, recording) => {
|
|
14
19
|
"worklet";
|
|
15
20
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["Rea","HAS_REANIMATED_3","Recorder","visit","replay","createDrawingContext","Container","StaticContainer","drawOnscreen","Skia","nativeId","recording","rec","PictureRecorder","canvas","beginRecording","ctx","paintPool","commands","picture","finishRecordingAsPicture","dispose","
|
|
1
|
+
{"version":3,"names":["Rea","HAS_REANIMATED_3","Recorder","visit","replay","createDrawingContext","Container","StaticContainer","SkiaViewApi","globalThis","drawOnscreen","Skia","nativeId","recording","rec","PictureRecorder","canvas","beginRecording","ctx","paintPool","commands","picture","finishRecordingAsPicture","dispose","setJsiProperty","ReanimatedContainer","constructor","_defineProperty","redraw","mapperId","stopMapper","unmounted","recorder","root","record","getRecording","animationValues","size","startMapper","Array","from","runOnUI","createContainer"],"sources":["Container.web.ts"],"sourcesContent":["import Rea from \"../external/reanimated/ReanimatedProxy\";\nimport type { Skia } from \"../skia/types\";\nimport { HAS_REANIMATED_3 } from \"../external/reanimated/renderHelpers\";\n\nimport type { Recording } from \"./Recorder/Recorder\";\nimport { Recorder } from \"./Recorder/Recorder\";\nimport { visit } from \"./Recorder/Visitor\";\nimport { replay } from \"./Recorder/Player\";\nimport { createDrawingContext } from \"./Recorder/DrawingContext\";\nimport { Container, StaticContainer } from \"./StaticContainer\";\n\nimport \"../skia/NativeSetup\";\nimport \"../views/api\";\n\n// create local reference for `strictGlobal` option in Worklets\nconst { SkiaViewApi } = globalThis;\n\nconst drawOnscreen = (Skia: Skia, nativeId: number, recording: Recording) => {\n \"worklet\";\n const rec = Skia.PictureRecorder();\n const canvas = rec.beginRecording();\n //const start = performance.now();\n\n const ctx = createDrawingContext(Skia, recording.paintPool, canvas);\n replay(ctx, recording.commands);\n const picture = rec.finishRecordingAsPicture();\n rec.dispose();\n //const end = performance.now();\n //console.log(\"Recording time: \", end - start);\n SkiaViewApi.setJsiProperty(nativeId, \"picture\", picture);\n};\n\nclass ReanimatedContainer extends Container {\n private mapperId: number | null = null;\n\n constructor(\n Skia: Skia,\n private nativeId: number\n ) {\n super(Skia);\n }\n\n redraw() {\n if (this.mapperId !== null) {\n Rea.stopMapper(this.mapperId);\n }\n if (this.unmounted) {\n return;\n }\n const recorder = new Recorder();\n visit(recorder, this.root);\n const record = recorder.getRecording();\n const { animationValues } = record;\n this.recording = {\n commands: record.commands,\n paintPool: record.paintPool,\n };\n const { nativeId, Skia, recording } = this;\n if (animationValues.size > 0) {\n this.mapperId = Rea.startMapper(() => {\n \"worklet\";\n drawOnscreen(Skia, nativeId, recording!);\n }, Array.from(animationValues));\n }\n Rea.runOnUI(() => {\n \"worklet\";\n drawOnscreen(Skia, nativeId, recording!);\n })();\n }\n}\n\nexport const createContainer = (Skia: Skia, nativeId: number) => {\n if (HAS_REANIMATED_3 && nativeId !== -1) {\n return new ReanimatedContainer(Skia, nativeId);\n } else {\n return new StaticContainer(Skia, nativeId);\n }\n};\n"],"mappings":";;;AAAA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|
+
import type { ViewProps } from "react-native";
|
|
3
|
+
export interface NativeProps extends ViewProps {
|
|
4
|
+
contextId: Int32;
|
|
5
|
+
transparent: boolean;
|
|
6
|
+
}
|
|
7
|
+
declare const _default: import("react-native/Libraries/Utilities/codegenNativeComponent").NativeComponentType<NativeProps>;
|
|
8
|
+
export default _default;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["codegenNativeComponent"],"sources":["WebGPUViewNativeComponent.ts"],"sourcesContent":["import codegenNativeComponent from \"react-native/Libraries/Utilities/codegenNativeComponent\";\nimport type { Int32 } from \"react-native/Libraries/Types/CodegenTypes\";\nimport type { ViewProps } from \"react-native\";\n\nexport interface NativeProps extends ViewProps {\n contextId: Int32;\n transparent: boolean;\n}\n\n// eslint-disable-next-line import/no-default-export\nexport default codegenNativeComponent<NativeProps>(\"WebGPUView\");\n"],"mappings":"AAAA,OAAOA,sBAAsB,MAAM,yDAAyD;AAS5F;AACA,eAAeA,sBAAsB,CAAc,YAAY,CAAC","ignoreList":[]}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import type { Int32 } from "react-native/Libraries/Types/CodegenTypes";
|
|
3
|
+
import type { ViewProps } from "react-native";
|
|
4
|
+
export interface NativeProps extends ViewProps {
|
|
5
|
+
contextId: Int32;
|
|
6
|
+
transparent: boolean;
|
|
7
|
+
}
|
|
8
|
+
export default function WebGPUViewNativeComponent(props: NativeProps): React.JSX.Element;
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import React, { useEffect, useRef } from "react";
|
|
2
|
+
import { StyleSheet } from "react-native";
|
|
3
|
+
import { contextIdToId } from "./utils";
|
|
4
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
5
|
+
function debounce(func, wait, immediate = false) {
|
|
6
|
+
let timeout;
|
|
7
|
+
return function debounced(...args) {
|
|
8
|
+
const context = this;
|
|
9
|
+
const callNow = immediate && !timeout;
|
|
10
|
+
if (timeout) {
|
|
11
|
+
clearTimeout(timeout);
|
|
12
|
+
}
|
|
13
|
+
timeout = setTimeout(() => {
|
|
14
|
+
timeout = undefined;
|
|
15
|
+
if (!immediate) {
|
|
16
|
+
func.apply(context, args);
|
|
17
|
+
}
|
|
18
|
+
}, wait);
|
|
19
|
+
if (callNow) {
|
|
20
|
+
func.apply(context, args);
|
|
21
|
+
}
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
function resizeCanvas(canvas) {
|
|
25
|
+
if (!canvas) {
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
const dpr = window.devicePixelRatio || 1;
|
|
29
|
+
const {
|
|
30
|
+
height,
|
|
31
|
+
width
|
|
32
|
+
} = canvas.getBoundingClientRect();
|
|
33
|
+
canvas.setAttribute("height", (height * dpr).toString());
|
|
34
|
+
canvas.setAttribute("width", (width * dpr).toString());
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
// eslint-disable-next-line import/no-default-export
|
|
38
|
+
export default function WebGPUViewNativeComponent(props) {
|
|
39
|
+
const {
|
|
40
|
+
contextId,
|
|
41
|
+
style,
|
|
42
|
+
transparent,
|
|
43
|
+
...rest
|
|
44
|
+
} = props;
|
|
45
|
+
const canvasElm = useRef(null);
|
|
46
|
+
useEffect(() => {
|
|
47
|
+
const onResize = debounce(() => resizeCanvas(canvasElm.current), 100);
|
|
48
|
+
window.addEventListener("resize", onResize);
|
|
49
|
+
return () => {
|
|
50
|
+
window.removeEventListener("resize", onResize);
|
|
51
|
+
};
|
|
52
|
+
}, []);
|
|
53
|
+
return /*#__PURE__*/React.createElement("canvas", {
|
|
54
|
+
...rest,
|
|
55
|
+
id: contextIdToId(contextId),
|
|
56
|
+
style: {
|
|
57
|
+
...styles.view,
|
|
58
|
+
...styles.flex1,
|
|
59
|
+
...(transparent === false ? {
|
|
60
|
+
backgroundColor: "white"
|
|
61
|
+
} : {}),
|
|
62
|
+
...(typeof style === "object" ? style : {})
|
|
63
|
+
},
|
|
64
|
+
ref: ref => {
|
|
65
|
+
canvasElm.current = ref;
|
|
66
|
+
if (ref) {
|
|
67
|
+
resizeCanvas(ref);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
const styles = StyleSheet.create({
|
|
73
|
+
flex1: {
|
|
74
|
+
flex: 1
|
|
75
|
+
},
|
|
76
|
+
view: {
|
|
77
|
+
alignItems: "stretch",
|
|
78
|
+
backgroundColor: "transparent",
|
|
79
|
+
border: "0 solid black",
|
|
80
|
+
boxSizing: "border-box",
|
|
81
|
+
display: "flex",
|
|
82
|
+
flexBasis: "auto",
|
|
83
|
+
flexDirection: "column",
|
|
84
|
+
flexShrink: 0,
|
|
85
|
+
listStyle: "none",
|
|
86
|
+
margin: 0,
|
|
87
|
+
minHeight: 0,
|
|
88
|
+
minWidth: 0,
|
|
89
|
+
padding: 0,
|
|
90
|
+
position: "relative",
|
|
91
|
+
zIndex: 0
|
|
92
|
+
}
|
|
93
|
+
});
|
|
94
|
+
//# sourceMappingURL=WebGPUViewNativeComponent.web.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["React","useEffect","useRef","StyleSheet","contextIdToId","debounce","func","wait","immediate","timeout","debounced","args","context","callNow","clearTimeout","setTimeout","undefined","apply","resizeCanvas","canvas","dpr","window","devicePixelRatio","height","width","getBoundingClientRect","setAttribute","toString","WebGPUViewNativeComponent","props","contextId","style","transparent","rest","canvasElm","onResize","current","addEventListener","removeEventListener","createElement","id","styles","view","flex1","backgroundColor","ref","create","flex","alignItems","border","boxSizing","display","flexBasis","flexDirection","flexShrink","listStyle","margin","minHeight","minWidth","padding","position","zIndex"],"sources":["WebGPUViewNativeComponent.web.ts"],"sourcesContent":["import React, { useEffect, useRef } from \"react\";\nimport { StyleSheet } from \"react-native\";\nimport type { Int32 } from \"react-native/Libraries/Types/CodegenTypes\";\nimport type { ViewProps } from \"react-native\";\n\nimport { contextIdToId } from \"./utils\";\n\nexport interface NativeProps extends ViewProps {\n contextId: Int32;\n transparent: boolean;\n}\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nfunction debounce<T extends (...args: any[]) => void>(\n func: T,\n wait: number,\n immediate = false\n) {\n let timeout: ReturnType<typeof setTimeout> | undefined;\n return function debounced(\n this: ThisParameterType<T>,\n ...args: Parameters<T>\n ) {\n const context = this;\n const callNow = immediate && !timeout;\n if (timeout) {\n clearTimeout(timeout);\n }\n timeout = setTimeout(() => {\n timeout = undefined;\n if (!immediate) {\n func.apply(context, args);\n }\n }, wait);\n if (callNow) {\n func.apply(context, args);\n }\n };\n}\n\nfunction resizeCanvas(canvas: HTMLCanvasElement | null) {\n if (!canvas) {\n return;\n }\n\n const dpr = window.devicePixelRatio || 1;\n\n const { height, width } = canvas.getBoundingClientRect();\n canvas.setAttribute(\"height\", (height * dpr).toString());\n canvas.setAttribute(\"width\", (width * dpr).toString());\n}\n\n// eslint-disable-next-line import/no-default-export\nexport default function WebGPUViewNativeComponent(\n props: NativeProps\n): React.JSX.Element {\n const { contextId, style, transparent, ...rest } = props;\n\n const canvasElm = useRef<HTMLCanvasElement>(null);\n\n useEffect(() => {\n const onResize = debounce(() => resizeCanvas(canvasElm.current), 100);\n window.addEventListener(\"resize\", onResize);\n return () => {\n window.removeEventListener(\"resize\", onResize);\n };\n }, []);\n\n return React.createElement(\"canvas\", {\n ...rest,\n id: contextIdToId(contextId),\n style: {\n ...styles.view,\n ...styles.flex1,\n ...(transparent === false ? { backgroundColor: \"white\" } : {}),\n ...(typeof style === \"object\" ? style : {}),\n },\n ref: (ref: HTMLCanvasElement) => {\n canvasElm.current = ref;\n if (ref) {\n resizeCanvas(ref);\n }\n },\n });\n}\n\nconst styles = StyleSheet.create({\n flex1: {\n flex: 1,\n },\n view: {\n alignItems: \"stretch\",\n backgroundColor: \"transparent\",\n border: \"0 solid black\",\n boxSizing: \"border-box\",\n display: \"flex\",\n flexBasis: \"auto\",\n flexDirection: \"column\",\n flexShrink: 0,\n listStyle: \"none\",\n margin: 0,\n minHeight: 0,\n minWidth: 0,\n padding: 0,\n position: \"relative\",\n zIndex: 0,\n },\n});\n"],"mappings":"AAAA,OAAOA,KAAK,IAAIC,SAAS,EAAEC,MAAM,QAAQ,OAAO;AAChD,SAASC,UAAU,QAAQ,cAAc;AAIzC,SAASC,aAAa,QAAQ,SAAS;AAOvC;AACA,SAASC,QAAQA,CACfC,IAAO,EACPC,IAAY,EACZC,SAAS,GAAG,KAAK,EACjB;EACA,IAAIC,OAAkD;EACtD,OAAO,SAASC,SAASA,CAEvB,GAAGC,IAAmB,EACtB;IACA,MAAMC,OAAO,GAAG,IAAI;IACpB,MAAMC,OAAO,GAAGL,SAAS,IAAI,CAACC,OAAO;IACrC,IAAIA,OAAO,EAAE;MACXK,YAAY,CAACL,OAAO,CAAC;IACvB;IACAA,OAAO,GAAGM,UAAU,CAAC,MAAM;MACzBN,OAAO,GAAGO,SAAS;MACnB,IAAI,CAACR,SAAS,EAAE;QACdF,IAAI,CAACW,KAAK,CAACL,OAAO,EAAED,IAAI,CAAC;MAC3B;IACF,CAAC,EAAEJ,IAAI,CAAC;IACR,IAAIM,OAAO,EAAE;MACXP,IAAI,CAACW,KAAK,CAACL,OAAO,EAAED,IAAI,CAAC;IAC3B;EACF,CAAC;AACH;AAEA,SAASO,YAAYA,CAACC,MAAgC,EAAE;EACtD,IAAI,CAACA,MAAM,EAAE;IACX;EACF;EAEA,MAAMC,GAAG,GAAGC,MAAM,CAACC,gBAAgB,IAAI,CAAC;EAExC,MAAM;IAAEC,MAAM;IAAEC;EAAM,CAAC,GAAGL,MAAM,CAACM,qBAAqB,CAAC,CAAC;EACxDN,MAAM,CAACO,YAAY,CAAC,QAAQ,EAAE,CAACH,MAAM,GAAGH,GAAG,EAAEO,QAAQ,CAAC,CAAC,CAAC;EACxDR,MAAM,CAACO,YAAY,CAAC,OAAO,EAAE,CAACF,KAAK,GAAGJ,GAAG,EAAEO,QAAQ,CAAC,CAAC,CAAC;AACxD;;A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BK,MAAM,EAAE,eAAe;IACvBC,SAAS,EAAE,YAAY;IACvBC,OAAO,EAAE,MAAM;IACfC,SAAS,EAAE,MAAM;IACjBC,aAAa,EAAE,QAAQ;IACvBC,UAAU,EAAE,CAAC;IACbC,SAAS,EAAE,MAAM;IACjBC,MAAM,EAAE,CAAC;IACTC,SAAS,EAAE,CAAC;IACZC,QAAQ,EAAE,CAAC;IACXC,OAAO,EAAE,CAAC;IACVC,QAAQ,EAAE,UAAU;IACpBC,MAAM,EAAE;EACV;AACF,CAAC,CAAC","ignoreList":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function contextIdToId(contextId: number): string;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["contextIdToId","contextId"],"sources":["utils.ts"],"sourcesContent":["// Only used on the web\nexport function contextIdToId(contextId: number) {\n return \"rnwgpu-canvas-\" + contextId;\n}\n"],"mappings":"AAAA;AACA,OAAO,SAASA,aAAaA,CAACC,SAAiB,EAAE;EAC/C,OAAO,gBAAgB,GAAGA,SAAS;AACrC","ignoreList":[]}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import type { ViewProps } from "react-native";
|
|
3
|
+
declare global {
|
|
4
|
+
var RNWebGPU: {
|
|
5
|
+
gpu: GPU;
|
|
6
|
+
fabric: boolean;
|
|
7
|
+
getNativeSurface: (contextId: number) => NativeCanvas;
|
|
8
|
+
MakeWebGPUCanvasContext: (contextId: number, width: number, height: number) => RNCanvasContext;
|
|
9
|
+
};
|
|
10
|
+
}
|
|
11
|
+
type SurfacePointer = bigint;
|
|
12
|
+
export interface NativeCanvas {
|
|
13
|
+
surface: SurfacePointer;
|
|
14
|
+
width: number;
|
|
15
|
+
height: number;
|
|
16
|
+
clientWidth: number;
|
|
17
|
+
clientHeight: number;
|
|
18
|
+
}
|
|
19
|
+
export type RNCanvasContext = GPUCanvasContext & {
|
|
20
|
+
present: () => void;
|
|
21
|
+
};
|
|
22
|
+
export interface WebGPUCanvasRef {
|
|
23
|
+
getContextId: () => number;
|
|
24
|
+
getContext(contextName: "webgpu"): RNCanvasContext | null;
|
|
25
|
+
getNativeSurface: () => NativeCanvas;
|
|
26
|
+
}
|
|
27
|
+
interface WebGPUCanvasProps extends ViewProps {
|
|
28
|
+
transparent?: boolean;
|
|
29
|
+
ref?: React.Ref<WebGPUCanvasRef>;
|
|
30
|
+
}
|
|
31
|
+
export declare const WebGPUCanvas: ({ transparent, ref, ...props }: WebGPUCanvasProps) => React.JSX.Element;
|
|
32
|
+
export {};
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
function _extends() { return _extends = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends.apply(null, arguments); }
|
|
2
|
+
import React, { useImperativeHandle, useRef, useState } from "react";
|
|
3
|
+
import { View, Platform } from "react-native";
|
|
4
|
+
import WebGPUNativeView from "../specs/WebGPUViewNativeComponent";
|
|
5
|
+
let CONTEXT_COUNTER = 1;
|
|
6
|
+
function generateContextId() {
|
|
7
|
+
return CONTEXT_COUNTER++;
|
|
8
|
+
}
|
|
9
|
+
export const WebGPUCanvas = ({
|
|
10
|
+
transparent,
|
|
11
|
+
ref,
|
|
12
|
+
...props
|
|
13
|
+
}) => {
|
|
14
|
+
const viewRef = useRef(null);
|
|
15
|
+
const [contextId] = useState(() => generateContextId());
|
|
16
|
+
useImperativeHandle(ref, () => ({
|
|
17
|
+
getContextId: () => contextId,
|
|
18
|
+
getNativeSurface: () => {
|
|
19
|
+
if (typeof RNWebGPU === "undefined") {
|
|
20
|
+
throw new Error("[WebGPU] RNWebGPU is not available. Make sure SK_GRAPHITE is enabled.");
|
|
21
|
+
}
|
|
22
|
+
return RNWebGPU.getNativeSurface(contextId);
|
|
23
|
+
},
|
|
24
|
+
getContext(contextName) {
|
|
25
|
+
if (contextName !== "webgpu") {
|
|
26
|
+
throw new Error(`[WebGPU] Unsupported context: ${contextName}`);
|
|
27
|
+
}
|
|
28
|
+
if (!viewRef.current) {
|
|
29
|
+
throw new Error("[WebGPU] Cannot get context before mount");
|
|
30
|
+
}
|
|
31
|
+
if (typeof RNWebGPU === "undefined") {
|
|
32
|
+
throw new Error("[WebGPU] RNWebGPU is not available. Make sure SK_GRAPHITE is enabled.");
|
|
33
|
+
}
|
|
34
|
+
// getBoundingClientRect became stable in RN 0.83
|
|
35
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
36
|
+
const view = viewRef.current;
|
|
37
|
+
const size = "getBoundingClientRect" in view ? view.getBoundingClientRect() : view.unstable_getBoundingClientRect();
|
|
38
|
+
return RNWebGPU.MakeWebGPUCanvasContext(contextId, size.width, size.height);
|
|
39
|
+
}
|
|
40
|
+
}));
|
|
41
|
+
|
|
42
|
+
// WebGPU Canvas is not supported on web
|
|
43
|
+
if (Platform.OS === "web") {
|
|
44
|
+
return /*#__PURE__*/React.createElement(View, props);
|
|
45
|
+
}
|
|
46
|
+
return /*#__PURE__*/React.createElement(View, _extends({
|
|
47
|
+
collapsable: false,
|
|
48
|
+
ref: viewRef
|
|
49
|
+
}, props), /*#__PURE__*/React.createElement(WebGPUNativeView, {
|
|
50
|
+
style: {
|
|
51
|
+
flex: 1
|
|
52
|
+
},
|
|
53
|
+
contextId: contextId,
|
|
54
|
+
transparent: !!transparent
|
|
55
|
+
}));
|
|
56
|
+
};
|
|
57
|
+
//# sourceMappingURL=WebGPUCanvas.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["React","useImperativeHandle","useRef","useState","View","Platform","WebGPUNativeView","CONTEXT_COUNTER","generateContextId","WebGPUCanvas","transparent","ref","props","viewRef","contextId","getContextId","getNativeSurface","RNWebGPU","Error","getContext","contextName","current","view","size","getBoundingClientRect","unstable_getBoundingClientRect","MakeWebGPUCanvasContext","width","height","OS","createElement","_extends","collapsable","style","flex"],"sources":["WebGPUCanvas.tsx"],"sourcesContent":["import React, { useImperativeHandle, useRef, useState } from \"react\";\nimport type { ViewProps } from \"react-native\";\nimport { View, Platform } from \"react-native\";\n\nimport WebGPUNativeView from \"../specs/WebGPUViewNativeComponent\";\n\nlet CONTEXT_COUNTER = 1;\nfunction generateContextId() {\n return CONTEXT_COUNTER++;\n}\n\ndeclare global {\n var RNWebGPU: {\n gpu: GPU;\n fabric: boolean;\n getNativeSurface: (contextId: number) => NativeCanvas;\n MakeWebGPUCanvasContext: (\n contextId: number,\n width: number,\n height: number\n ) => RNCanvasContext;\n };\n}\n\ntype SurfacePointer = bigint;\n\nexport interface NativeCanvas {\n surface: SurfacePointer;\n width: number;\n height: number;\n clientWidth: number;\n clientHeight: number;\n}\n\nexport type RNCanvasContext = GPUCanvasContext & {\n present: () => void;\n};\n\nexport interface WebGPUCanvasRef {\n getContextId: () => number;\n getContext(contextName: \"webgpu\"): RNCanvasContext | null;\n getNativeSurface: () => NativeCanvas;\n}\n\ninterface WebGPUCanvasProps extends ViewProps {\n transparent?: boolean;\n ref?: React.Ref<WebGPUCanvasRef>;\n}\n\nexport const WebGPUCanvas = ({\n transparent,\n ref,\n ...props\n}: WebGPUCanvasProps) => {\n const viewRef = useRef(null);\n const [contextId] = useState(() => generateContextId());\n\n useImperativeHandle(ref, () => ({\n getContextId: () => contextId,\n getNativeSurface: () => {\n if (typeof RNWebGPU === \"undefined\") {\n throw new Error(\n \"[WebGPU] RNWebGPU is not available. Make sure SK_GRAPHITE is enabled.\"\n );\n }\n return RNWebGPU.getNativeSurface(contextId);\n },\n getContext(contextName: \"webgpu\"): RNCanvasContext | null {\n if (contextName !== \"webgpu\") {\n throw new Error(`[WebGPU] Unsupported context: ${contextName}`);\n }\n if (!viewRef.current) {\n throw new Error(\"[WebGPU] Cannot get context before mount\");\n }\n if (typeof RNWebGPU === \"undefined\") {\n throw new Error(\n \"[WebGPU] RNWebGPU is not available. Make sure SK_GRAPHITE is enabled.\"\n );\n }\n // getBoundingClientRect became stable in RN 0.83\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n const view = viewRef.current as any;\n const size =\n \"getBoundingClientRect\" in view\n ? view.getBoundingClientRect()\n : view.unstable_getBoundingClientRect();\n return RNWebGPU.MakeWebGPUCanvasContext(\n contextId,\n size.width,\n size.height\n );\n },\n }));\n\n // WebGPU Canvas is not supported on web\n if (Platform.OS === \"web\") {\n return <View {...props} />;\n }\n\n return (\n <View collapsable={false} ref={viewRef} {...props}>\n <WebGPUNativeView\n style={{ flex: 1 }}\n contextId={contextId}\n transparent={!!transparent}\n />\n </View>\n );\n};\n"],"mappings":";AAAA,OAAOA,KAAK,IAAIC,mBAAmB,EAAEC,MAAM,EAAEC,QAAQ,QAAQ,OAAO;AAEpE,SAASC,IAAI,EAAEC,QAAQ,QAAQ,cAAc;AAE7C,OAAOC,gBAAgB,MAAM,oCAAoC;AAEjE,IAAIC,eAAe,GAAG,CAAC;AACvB,SAASC,iBAAiBA,CAAA,EAAG;EAC3B,OAAOD,eAAe,EAAE;AAC1B;AAwCA,OAAO,MAAME,YAAY,GAAGA,CAAC;EAC3BC,WAAW;EACXC,GAAG;EACH,GAAGC;AACc,CAAC,KAAK;EACvB,MAAMC,OAAO,GAAGX,MAAM,CAAC,IAAI,CAAC;EAC5B,MAAM,CAACY,SAAS,CAAC,GAAGX,QAAQ,CAAC,MAAMK,iBAAiB,CAAC,CAAC,CAAC;EAEvDP,mBAAmB,CAACU,GAAG,EAAE,OAAO;IAC9BI,YAAY,EAAEA,CAAA,KAAMD,SAAS;IAC7BE,gBAAgB,EAAEA,CAAA,KAAM;MACtB,IAAI,OAAOC,QAAQ,KAAK,WAAW,EAAE;QACnC,MAAM,IAAIC,KAAK,CACb,uEACF,CAAC;MACH;MACA,OAAOD,QAAQ,CAACD,gBAAgB,CAACF,SAAS,CAAC;IAC7C,CAAC;IACDK,UAAUA,CAACC,WAAqB,EAA0B;MACxD,IAAIA,WAAW,KAAK,QAAQ,EAAE;QAC5B,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