@shopify/react-native-skia 2.9.0 → 2.9.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/android/cpp/jni/JniWebGPUView.cpp +52 -7
- package/android/src/main/java/com/shopify/reactnative/skia/WebGPUSurfaceView.java +3 -1
- package/android/src/main/java/com/shopify/reactnative/skia/WebGPUTextureView.java +11 -5
- package/android/src/main/java/com/shopify/reactnative/skia/WebGPUView.java +10 -7
- package/android/src/main/java/com/shopify/reactnative/skia/WebGPUViewAPI.java +7 -2
- package/android/src/main/java/com/shopify/reactnative/skia/WebGPUViewManager.java +1 -1
- package/apple/WebGPUMetalView.mm +49 -6
- package/cpp/api/JsiSkParagraphStyle.h +20 -10
- package/cpp/api/JsiSkStrutStyle.h +18 -8
- package/cpp/api/JsiSkTextStyle.h +34 -24
- package/cpp/rnskia/RNSkManager.cpp +6 -0
- package/cpp/rnwgpu/SurfaceRegistry.h +469 -131
- package/cpp/rnwgpu/api/GPUAdapter.cpp +10 -3
- package/cpp/rnwgpu/api/GPUAdapter.h +5 -4
- package/cpp/rnwgpu/api/GPUBuffer.cpp +12 -2
- package/cpp/rnwgpu/api/GPUBuffer.h +3 -2
- package/cpp/rnwgpu/api/GPUCanvasContext.cpp +33 -19
- package/cpp/rnwgpu/api/GPUCanvasContext.h +3 -1
- package/cpp/rnwgpu/api/GPUDevice.cpp +32 -17
- package/cpp/rnwgpu/api/GPUDevice.h +9 -7
- package/cpp/rnwgpu/api/GPUQueue.cpp +6 -2
- package/cpp/rnwgpu/api/GPUQueue.h +3 -3
- package/cpp/rnwgpu/api/GPUShaderModule.cpp +7 -2
- package/cpp/rnwgpu/api/GPUShaderModule.h +3 -3
- package/cpp/rnwgpu/api/RNWebGPU.h +20 -0
- package/cpp/rnwgpu/async/RuntimeContext.cpp +5 -0
- package/cpp/rnwgpu/async/RuntimeContext.h +15 -2
- package/lib/commonjs/views/WebGPUCanvas.d.ts +1 -0
- package/lib/commonjs/views/WebGPUCanvas.js +13 -0
- package/lib/commonjs/views/WebGPUCanvas.js.map +1 -1
- package/lib/module/views/WebGPUCanvas.d.ts +1 -0
- package/lib/module/views/WebGPUCanvas.js +14 -1
- package/lib/module/views/WebGPUCanvas.js.map +1 -1
- package/lib/typescript/src/views/WebGPUCanvas.d.ts +1 -0
- package/package.json +2 -2
- package/src/views/WebGPUCanvas.tsx +17 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["React","useImperativeHandle","useRef","useState","View","Platform","WebGPUNativeView","CONTEXT_COUNTER","generateContextId","WebGPUCanvas","transparent","ref","props","viewRef","contextId","
|
|
1
|
+
{"version":3,"names":["React","useEffect","useImperativeHandle","useRef","useState","View","Platform","WebGPUNativeView","CONTEXT_COUNTER","generateContextId","WebGPUCanvas","transparent","ref","props","viewRef","contextId","RNWebGPU","destroyContext","getContextId","getNativeSurface","Error","getContext","contextName","current","view","size","getBoundingClientRect","unstable_getBoundingClientRect","MakeWebGPUCanvasContext","width","height","OS","createElement","_extends","collapsable","style","flex"],"sources":["WebGPUCanvas.tsx"],"sourcesContent":["import React, { useEffect, 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 // Retires a canvas context; called by the Canvas on unmount (the Canvas\n // owns the native registry entry for its contextId).\n destroyContext: (contextId: number) => void;\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 // Retire the native registry entry for this contextId on unmount. When a\n // native surface is still attached, this is a no-op and the native view's\n // own teardown retires the entry instead — which keeps StrictMode's\n // simulated unmount (which re-runs effects without unmounting native views)\n // from orphaning a live surface.\n useEffect(() => {\n return () => {\n if (typeof RNWebGPU !== \"undefined\") {\n RNWebGPU.destroyContext(contextId);\n }\n };\n }, [contextId]);\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,SAAS,EAAEC,mBAAmB,EAAEC,MAAM,EAAEC,QAAQ,QAAQ,OAAO;AAE/E,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;AA2CA,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;;EAEvD;EACA;EACA;EACA;EACA;EACAR,SAAS,CAAC,MAAM;IACd,OAAO,MAAM;MACX,IAAI,OAAOe,QAAQ,KAAK,WAAW,EAAE;QACnCA,QAAQ,CAACC,cAAc,CAACF,SAAS,CAAC;MACpC;IACF,CAAC;EACH,CAAC,EAAE,CAACA,SAAS,CAAC,CAAC;EAEfb,mBAAmB,CAACU,GAAG,EAAE,OAAO;IAC9BM,YAAY,EAAEA,CAAA,KAAMH,SAAS;IAC7BI,gBAAgB,EAAEA,CAAA,KAAM;MACtB,IAAI,OAAOH,QAAQ,KAAK,WAAW,EAAE;QACnC,MAAM,IAAII,KAAK,CACb,uEACF,CAAC;MACH;MACA,OAAOJ,QAAQ,CAACG,gBAAgB,CAACJ,SAAS,CAAC;IAC7C,CAAC;IACDM,UAAUA,CAACC,WAAqB,EAA0B;MACxD,IAAIA,WAAW,KAAK,QAAQ,EAAE;QAC5B,MAAM,IAAIF,KAAK,CAAC,iCAAiCE,WAAW,EAAE,CAAC;MACjE;MACA,IAAI,CAACR,OAAO,CAACS,OAAO,EAAE;QACpB,MAAM,IAAIH,KAAK,CAAC,0CAA0C,CAAC;MAC7D;MACA,IAAI,OAAOJ,QAAQ,KAAK,WAAW,EAAE;QACnC,MAAM,IAAII,KAAK,CACb,uEACF,CAAC;MACH;MACA;MACA;MACA,MAAMI,IAAI,GAAGV,OAAO,CAACS,OAAc;MACnC,MAAME,IAAI,GACR,uBAAuB,IAAID,IAAI,GAC3BA,IAAI,CAACE,qBAAqB,CAAC,CAAC,GAC5BF,IAAI,CAACG,8BAA8B,CAAC,CAAC;MAC3C,OAAOX,QAAQ,CAACY,uBAAuB,CACrCb,SAAS,EACTU,IAAI,CAACI,KAAK,EACVJ,IAAI,CAACK,MACP,CAAC;IACH;EACF,CAAC,CAAC,CAAC;;EAEH;EACA,IAAIxB,QAAQ,CAACyB,EAAE,KAAK,KAAK,EAAE;IACzB,oBAAO/B,KAAA,CAAAgC,aAAA,CAAC3B,IAAI,EAAKQ,KAAQ,CAAC;EAC5B;EAEA,oBACEb,KAAA,CAAAgC,aAAA,CAAC3B,IAAI,EAAA4B,QAAA;IAACC,WAAW,EAAE,KAAM;IAACtB,GAAG,EAAEE;EAAQ,GAAKD,KAAK,gBAC/Cb,KAAA,CAAAgC,aAAA,CAACzB,gBAAgB;IACf4B,KAAK,EAAE;MAAEC,IAAI,EAAE;IAAE,CAAE;IACnBrB,SAAS,EAAEA,SAAU;IACrBJ,WAAW,EAAE,CAAC,CAACA;EAAY,CAC5B,CACG,CAAC;AAEX,CAAC","ignoreList":[]}
|
|
@@ -6,6 +6,7 @@ declare global {
|
|
|
6
6
|
fabric: boolean;
|
|
7
7
|
getNativeSurface: (contextId: number) => NativeCanvas;
|
|
8
8
|
MakeWebGPUCanvasContext: (contextId: number, width: number, height: number) => RNCanvasContext;
|
|
9
|
+
destroyContext: (contextId: number) => void;
|
|
9
10
|
};
|
|
10
11
|
}
|
|
11
12
|
type SurfacePointer = bigint;
|
package/package.json
CHANGED
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
"setup-skia-web": "scripts/setup-canvaskit.js"
|
|
9
9
|
},
|
|
10
10
|
"title": "React Native Skia",
|
|
11
|
-
"version": "2.9.
|
|
11
|
+
"version": "2.9.1",
|
|
12
12
|
"description": "High-performance React Native Graphics using Skia",
|
|
13
13
|
"main": "lib/module/index.js",
|
|
14
14
|
"react-native": "src/index.ts",
|
|
@@ -127,7 +127,7 @@
|
|
|
127
127
|
"rimraf": "3.0.2",
|
|
128
128
|
"semantic-release": "^24.1.0",
|
|
129
129
|
"semantic-release-yarn": "^3.0.2",
|
|
130
|
-
"tar": "^7.5.
|
|
130
|
+
"tar": "^7.5.19",
|
|
131
131
|
"ts-jest": "29.4.3",
|
|
132
132
|
"tsx": "^4.21.0",
|
|
133
133
|
"typescript": "^5.2.2",
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import React, { useImperativeHandle, useRef, useState } from "react";
|
|
1
|
+
import React, { useEffect, useImperativeHandle, useRef, useState } from "react";
|
|
2
2
|
import type { ViewProps } from "react-native";
|
|
3
3
|
import { View, Platform } from "react-native";
|
|
4
4
|
|
|
@@ -19,6 +19,9 @@ declare global {
|
|
|
19
19
|
width: number,
|
|
20
20
|
height: number
|
|
21
21
|
) => RNCanvasContext;
|
|
22
|
+
// Retires a canvas context; called by the Canvas on unmount (the Canvas
|
|
23
|
+
// owns the native registry entry for its contextId).
|
|
24
|
+
destroyContext: (contextId: number) => void;
|
|
22
25
|
};
|
|
23
26
|
}
|
|
24
27
|
|
|
@@ -55,6 +58,19 @@ export const WebGPUCanvas = ({
|
|
|
55
58
|
const viewRef = useRef(null);
|
|
56
59
|
const [contextId] = useState(() => generateContextId());
|
|
57
60
|
|
|
61
|
+
// Retire the native registry entry for this contextId on unmount. When a
|
|
62
|
+
// native surface is still attached, this is a no-op and the native view's
|
|
63
|
+
// own teardown retires the entry instead — which keeps StrictMode's
|
|
64
|
+
// simulated unmount (which re-runs effects without unmounting native views)
|
|
65
|
+
// from orphaning a live surface.
|
|
66
|
+
useEffect(() => {
|
|
67
|
+
return () => {
|
|
68
|
+
if (typeof RNWebGPU !== "undefined") {
|
|
69
|
+
RNWebGPU.destroyContext(contextId);
|
|
70
|
+
}
|
|
71
|
+
};
|
|
72
|
+
}, [contextId]);
|
|
73
|
+
|
|
58
74
|
useImperativeHandle(ref, () => ({
|
|
59
75
|
getContextId: () => contextId,
|
|
60
76
|
getNativeSurface: () => {
|