@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,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,12 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
// WebGPU Canvas is not supported on web
|
|
3
|
+
export const WebGPUCanvas = ({
|
|
4
|
+
transparent: _transparent,
|
|
5
|
+
ref: _ref,
|
|
6
|
+
...props
|
|
7
|
+
}) => {
|
|
8
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
9
|
+
// @ts-expect-error
|
|
10
|
+
return /*#__PURE__*/React.createElement("div", props);
|
|
11
|
+
};
|
|
12
|
+
//# sourceMappingURL=WebGPUCanvas.web.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["React","WebGPUCanvas","transparent","_transparent","ref","_ref","props","createElement"],"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,OAAOA,KAAK,MAAM,OAAO;AA0BzB;AACA,OAAO,MAAMC,YAAY,GAAGA,CAAC;EAC3BC,WAAW,EAAEC,YAAY;EACzBC,GAAG,EAAEC,IAAI;EACT,GAAGC;AACc,CAAC,KAAK;EACvB;EACA;EACA,oBAAON,KAAA,CAAAO,aAAA,QAASD,KAAQ,CAAC;AAC3B,CAAC","ignoreList":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":[],"sources":["index.ts"],"sourcesContent":["export * from \"./SkiaPictureView\";\nexport * from \"./types\";\n"],"mappings":"AAAA,cAAc,mBAAmB;AACjC,cAAc,SAAS","ignoreList":[]}
|
|
1
|
+
{"version":3,"names":[],"sources":["index.ts"],"sourcesContent":["export * from \"./SkiaPictureView\";\nexport * from \"./types\";\nexport * from \"./WebGPUCanvas\";\n"],"mappings":"AAAA,cAAc,mBAAmB;AACjC,cAAc,SAAS;AACvB,cAAc,gBAAgB","ignoreList":[]}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
export const __esModule: boolean;
|
|
2
2
|
export function Mock(CanvasKit: any): {
|
|
3
3
|
Canvas: typeof import("react-native").View;
|
|
4
|
+
WebGPUCanvas: typeof import("react-native").View;
|
|
4
5
|
SkiaPictureView: typeof import("react-native").View;
|
|
5
6
|
JsiSkImage: typeof _JsiSkImage.JsiSkImage;
|
|
6
7
|
drawAsPicture: () => undefined;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
export function Mock(CanvasKit: any): {
|
|
2
2
|
Canvas: typeof import("react-native").View;
|
|
3
|
+
WebGPUCanvas: typeof import("react-native").View;
|
|
3
4
|
SkiaPictureView: typeof import("react-native").View;
|
|
4
5
|
JsiSkImage: typeof JsiSkImage;
|
|
5
6
|
drawAsPicture: () => undefined;
|
|
@@ -128,7 +129,8 @@ export function Mock(CanvasKit: any): {
|
|
|
128
129
|
isEdge: (pos: any, b: any) => boolean;
|
|
129
130
|
processRect: (Skia: any, def: any) => any;
|
|
130
131
|
processRRect: (Skia: any, def: any) => any;
|
|
131
|
-
inflate: (Skia: any, box: any, dx: any, dy: any, tx?: number,
|
|
132
|
+
inflate: (Skia: any, box: any, dx: any, dy: any, tx?: number, // Reanimated hooks
|
|
133
|
+
ty?: number) => any;
|
|
132
134
|
deflate: (Skia: any, box: any, dx: any, dy: any, tx?: number, ty?: number) => any;
|
|
133
135
|
processRadius: (Skia: any, radius: any) => any;
|
|
134
136
|
isCircleScalarDef: (def: any) => boolean;
|
|
@@ -193,6 +195,10 @@ export function Mock(CanvasKit: any): {
|
|
|
193
195
|
rrect: (r: any, rx: any, ry: any) => import("../../..").SkRRect;
|
|
194
196
|
processTransform2d: (transforms: any) => any;
|
|
195
197
|
isRNModule: (mod: any) => mod is number;
|
|
198
|
+
ColorSpace: {
|
|
199
|
+
SRGB: string;
|
|
200
|
+
DisplayP3: string;
|
|
201
|
+
};
|
|
196
202
|
VertexMode: {};
|
|
197
203
|
isShader: (obj: any) => boolean;
|
|
198
204
|
processUniforms: (source: any, uniforms: any, builder: any) => any[];
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export function contextIdToId(contextId: any): string;
|
|
@@ -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
|
}
|
|
@@ -0,0 +1,8 @@
|
|
|
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
|
+
declare const _default: import("react-native/Libraries/Utilities/codegenNativeComponent").NativeComponentType<NativeProps>;
|
|
8
|
+
export default _default;
|
|
@@ -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 @@
|
|
|
1
|
+
export declare function contextIdToId(contextId: number): string;
|
|
@@ -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,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 {};
|
package/package.json
CHANGED
|
@@ -5,10 +5,11 @@
|
|
|
5
5
|
"provenance": true
|
|
6
6
|
},
|
|
7
7
|
"bin": {
|
|
8
|
+
"install-skia": "scripts/install-libs.js",
|
|
8
9
|
"setup-skia-web": "scripts/setup-canvaskit.js"
|
|
9
10
|
},
|
|
10
11
|
"title": "React Native Skia",
|
|
11
|
-
"version": "2.5.
|
|
12
|
+
"version": "2.5.3",
|
|
12
13
|
"description": "High-performance React Native Graphics using Skia",
|
|
13
14
|
"main": "lib/module/index.js",
|
|
14
15
|
"react-native": "src/index.ts",
|
|
@@ -16,6 +17,7 @@
|
|
|
16
17
|
"types": "lib/typescript/index.d.ts",
|
|
17
18
|
"files": [
|
|
18
19
|
"scripts/setup-canvaskit.js",
|
|
20
|
+
"scripts/install-libs.js",
|
|
19
21
|
"src/**",
|
|
20
22
|
"lib/**",
|
|
21
23
|
"!**/__tests__/**",
|
|
@@ -35,6 +37,7 @@
|
|
|
35
37
|
"dist/**"
|
|
36
38
|
],
|
|
37
39
|
"scripts": {
|
|
40
|
+
"postinstall": "node scripts/install-libs.js",
|
|
38
41
|
"lint": "eslint . --ext .ts,.tsx --max-warnings 0 --cache --fix",
|
|
39
42
|
"tsc": "tsc --noEmit",
|
|
40
43
|
"test": "jest",
|
|
@@ -117,7 +120,7 @@
|
|
|
117
120
|
"rimraf": "3.0.2",
|
|
118
121
|
"semantic-release": "^24.1.0",
|
|
119
122
|
"semantic-release-yarn": "^3.0.2",
|
|
120
|
-
"tar": "^7.5.
|
|
123
|
+
"tar": "^7.5.11",
|
|
121
124
|
"ts-jest": "29.4.3",
|
|
122
125
|
"tsx": "^4.21.0",
|
|
123
126
|
"typescript": "^5.2.2",
|
|
@@ -144,7 +147,8 @@
|
|
|
144
147
|
},
|
|
145
148
|
"ios": {
|
|
146
149
|
"componentProvider": {
|
|
147
|
-
"SkiaPictureView": "SkiaPictureView"
|
|
150
|
+
"SkiaPictureView": "SkiaPictureView",
|
|
151
|
+
"WebGPUView": "WebGPUView"
|
|
148
152
|
}
|
|
149
153
|
}
|
|
150
154
|
},
|
|
@@ -4,14 +4,9 @@ require "json"
|
|
|
4
4
|
|
|
5
5
|
package = JSON.parse(File.read(File.join(__dir__, "package.json")))
|
|
6
6
|
|
|
7
|
-
# Check if Graphite is enabled
|
|
8
|
-
use_graphite =
|
|
9
|
-
|
|
10
|
-
use_graphite = ENV['SK_GRAPHITE'] == '1' || ENV['SK_GRAPHITE'].downcase == 'true'
|
|
11
|
-
puts "-- SK_GRAPHITE: using environment variable (#{use_graphite ? 'ON' : 'OFF'})"
|
|
12
|
-
else
|
|
13
|
-
puts "-- SK_GRAPHITE: OFF (set SK_GRAPHITE=1 to enable)"
|
|
14
|
-
end
|
|
7
|
+
# Check if Graphite is enabled via marker file (created by install-skia-graphite)
|
|
8
|
+
use_graphite = File.exist?(File.join(__dir__, 'libs', '.graphite'))
|
|
9
|
+
puts "-- SK_GRAPHITE: #{use_graphite ? 'ON' : 'OFF'} (detected via libs/.graphite marker file)"
|
|
15
10
|
|
|
16
11
|
# Set preprocessor definitions based on GRAPHITE flag
|
|
17
12
|
preprocessor_defs = use_graphite ?
|
|
@@ -23,86 +18,28 @@ framework_names = ['libskia', 'libsvg', 'libskshaper', 'libskparagraph',
|
|
|
23
18
|
'libskunicode_core', 'libskunicode_libgrapheme',
|
|
24
19
|
'libskottie', 'libsksg']
|
|
25
20
|
|
|
21
|
+
# Verify that prebuilt binaries have been installed by the postinstall script
|
|
22
|
+
unless Dir.exist?(File.join(__dir__, 'libs', 'ios')) && Dir.exist?(File.join(__dir__, 'libs', 'macos'))
|
|
23
|
+
Pod::UI.warn "#{'-' * 72}"
|
|
24
|
+
Pod::UI.warn "react-native-skia: Skia prebuilt binaries not found in libs/!"
|
|
25
|
+
Pod::UI.warn ""
|
|
26
|
+
Pod::UI.warn "Run the following command to install them:"
|
|
27
|
+
Pod::UI.warn " npx install-skia"
|
|
28
|
+
Pod::UI.warn "#{'-' * 72}"
|
|
29
|
+
raise "react-native-skia: Skia prebuilt binaries not found. Run `npx install-skia` to fix this."
|
|
30
|
+
end
|
|
31
|
+
|
|
26
32
|
# Build platform-specific framework paths (relative to pod's libs directory)
|
|
33
|
+
# xcframeworks are copied into libs/ by the npm postinstall script (scripts/install-libs.js)
|
|
27
34
|
ios_frameworks = framework_names.map { |f| "libs/ios/#{f}.xcframework" }
|
|
28
35
|
osx_frameworks = framework_names.map { |f| "libs/macos/#{f}.xcframework" }
|
|
29
|
-
# tvOS frameworks -
|
|
36
|
+
# tvOS frameworks - check if libs/tvos/ exists (populated by postinstall before pod install runs)
|
|
30
37
|
tvos_frameworks = if use_graphite || !Dir.exist?(File.join(__dir__, 'libs', 'tvos'))
|
|
31
38
|
[]
|
|
32
39
|
else
|
|
33
40
|
framework_names.map { |f| "libs/tvos/#{f}.xcframework" }
|
|
34
41
|
end
|
|
35
42
|
|
|
36
|
-
# Prepare command resolves paths at RUNTIME (not evaluation time) to ensure deterministic checksums
|
|
37
|
-
# This script:
|
|
38
|
-
# 1. Checks if xcframeworks are already installed (e.g., from Graphite script)
|
|
39
|
-
# 2. If not, resolves npm package paths and copies xcframeworks
|
|
40
|
-
# The script content is deterministic - no machine-specific paths embedded in the podspec
|
|
41
|
-
prepare_command_script = <<-'SCRIPT'
|
|
42
|
-
node -e "
|
|
43
|
-
const path = require('path');
|
|
44
|
-
const fs = require('fs');
|
|
45
|
-
const { execSync } = require('child_process');
|
|
46
|
-
|
|
47
|
-
const iosLibs = 'libs/ios';
|
|
48
|
-
const macosLibs = 'libs/macos';
|
|
49
|
-
|
|
50
|
-
// Check if xcframeworks are already installed
|
|
51
|
-
const hasIos = fs.existsSync(iosLibs) && fs.readdirSync(iosLibs).some(f => f.endsWith('.xcframework'));
|
|
52
|
-
const hasMacos = fs.existsSync(macosLibs) && fs.readdirSync(macosLibs).some(f => f.endsWith('.xcframework'));
|
|
53
|
-
|
|
54
|
-
if (hasIos && hasMacos) {
|
|
55
|
-
console.log('-- Using pre-installed xcframeworks from libs/');
|
|
56
|
-
process.exit(0);
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
// Determine package prefix based on SK_GRAPHITE env var
|
|
60
|
-
const useGraphite = process.env.SK_GRAPHITE === '1' || (process.env.SK_GRAPHITE || '').toLowerCase() === 'true';
|
|
61
|
-
const prefix = useGraphite ? 'react-native-skia-graphite' : 'react-native-skia';
|
|
62
|
-
|
|
63
|
-
// Resolve package paths
|
|
64
|
-
let iosPackage, macosPackage, tvosPackage;
|
|
65
|
-
try {
|
|
66
|
-
iosPackage = path.dirname(require.resolve(prefix + '-apple-ios/package.json'));
|
|
67
|
-
macosPackage = path.dirname(require.resolve(prefix + '-apple-macos/package.json'));
|
|
68
|
-
} catch (e) {
|
|
69
|
-
console.error('ERROR: Could not find ' + prefix + '-apple-ios or ' + prefix + '-apple-macos');
|
|
70
|
-
console.error('Make sure you have run yarn install or npm install');
|
|
71
|
-
process.exit(1);
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
// Verify xcframeworks exist in the packages
|
|
75
|
-
const iosXcf = path.join(iosPackage, 'libs');
|
|
76
|
-
if (!fs.existsSync(iosXcf) || !fs.readdirSync(iosXcf).some(f => f.endsWith('.xcframework'))) {
|
|
77
|
-
console.error('ERROR: Skia prebuilt binaries not found in ' + prefix + '-apple-ios!');
|
|
78
|
-
process.exit(1);
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
console.log('-- Skia iOS package: ' + iosPackage);
|
|
82
|
-
console.log('-- Skia macOS package: ' + macosPackage);
|
|
83
|
-
|
|
84
|
-
// Clean and copy
|
|
85
|
-
execSync('rm -rf libs/ios libs/macos libs/tvos', { stdio: 'inherit' });
|
|
86
|
-
execSync('mkdir -p libs/ios libs/macos', { stdio: 'inherit' });
|
|
87
|
-
execSync('cp -R \"' + iosPackage + '/libs/\"*.xcframework libs/ios/', { stdio: 'inherit' });
|
|
88
|
-
execSync('cp -R \"' + macosPackage + '/libs/\"*.xcframework libs/macos/', { stdio: 'inherit' });
|
|
89
|
-
|
|
90
|
-
// Handle tvOS (non-Graphite only)
|
|
91
|
-
if (!useGraphite) {
|
|
92
|
-
try {
|
|
93
|
-
tvosPackage = path.dirname(require.resolve(prefix + '-apple-tvos/package.json'));
|
|
94
|
-
console.log('-- Skia tvOS package: ' + tvosPackage);
|
|
95
|
-
execSync('mkdir -p libs/tvos', { stdio: 'inherit' });
|
|
96
|
-
execSync('cp -R \"' + tvosPackage + '/libs/\"*.xcframework libs/tvos/', { stdio: 'inherit' });
|
|
97
|
-
} catch (e) {
|
|
98
|
-
console.log('-- tvOS package not found, skipping');
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
console.log('-- Copied xcframeworks from npm packages');
|
|
103
|
-
"
|
|
104
|
-
SCRIPT
|
|
105
|
-
|
|
106
43
|
Pod::Spec.new do |s|
|
|
107
44
|
s.name = "react-native-skia"
|
|
108
45
|
s.version = package["version"]
|
|
@@ -120,10 +57,6 @@ Pod::Spec.new do |s|
|
|
|
120
57
|
s.platforms = { :ios => "14.0", :tvos => "13.0", :osx => "11" }
|
|
121
58
|
s.source = { :git => "https://github.com/shopify/react-native-skia/react-native-skia.git", :tag => "#{s.version}" }
|
|
122
59
|
|
|
123
|
-
# Copy xcframeworks from npm packages into pod directory structure
|
|
124
|
-
# The script is deterministic - path resolution happens at runtime, not evaluation time
|
|
125
|
-
s.prepare_command = prepare_command_script
|
|
126
|
-
|
|
127
60
|
s.requires_arc = true
|
|
128
61
|
s.pod_target_xcconfig = {
|
|
129
62
|
'GCC_PREPROCESSOR_DEFINITIONS' => preprocessor_defs,
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
"use strict";
|
|
3
|
+
|
|
4
|
+
const path = require("path");
|
|
5
|
+
const fs = require("fs");
|
|
6
|
+
const { execSync } = require("child_process");
|
|
7
|
+
|
|
8
|
+
const useGraphite =
|
|
9
|
+
process.env.SK_GRAPHITE === "1" ||
|
|
10
|
+
(process.env.SK_GRAPHITE || "").toLowerCase() === "true";
|
|
11
|
+
const prefix = useGraphite ? "react-native-skia-graphite" : "react-native-skia";
|
|
12
|
+
const libsDir = path.join(__dirname, "..", "libs");
|
|
13
|
+
|
|
14
|
+
// --- Apple platforms ---
|
|
15
|
+
|
|
16
|
+
let iosPackage, macosPackage;
|
|
17
|
+
try {
|
|
18
|
+
iosPackage = path.dirname(
|
|
19
|
+
require.resolve(prefix + "-apple-ios/package.json")
|
|
20
|
+
);
|
|
21
|
+
macosPackage = path.dirname(
|
|
22
|
+
require.resolve(prefix + "-apple-macos/package.json")
|
|
23
|
+
);
|
|
24
|
+
} catch (e) {
|
|
25
|
+
console.error(
|
|
26
|
+
"ERROR: Could not find " +
|
|
27
|
+
prefix +
|
|
28
|
+
"-apple-ios or " +
|
|
29
|
+
prefix +
|
|
30
|
+
"-apple-macos"
|
|
31
|
+
);
|
|
32
|
+
console.error("Make sure you have run yarn install or npm install");
|
|
33
|
+
process.exit(1);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
// Verify xcframeworks exist in the iOS package
|
|
37
|
+
const iosXcf = path.join(iosPackage, "libs");
|
|
38
|
+
if (
|
|
39
|
+
!fs.existsSync(iosXcf) ||
|
|
40
|
+
!fs.readdirSync(iosXcf).some((f) => f.endsWith(".xcframework"))
|
|
41
|
+
) {
|
|
42
|
+
console.error(
|
|
43
|
+
"ERROR: Skia prebuilt binaries not found in " + prefix + "-apple-ios!"
|
|
44
|
+
);
|
|
45
|
+
process.exit(1);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
console.log("-- Skia iOS package: " + iosPackage);
|
|
49
|
+
console.log("-- Skia macOS package: " + macosPackage);
|
|
50
|
+
|
|
51
|
+
// Clean and copy Apple frameworks
|
|
52
|
+
execSync(
|
|
53
|
+
"rm -rf " +
|
|
54
|
+
path.join(libsDir, "ios") +
|
|
55
|
+
" " +
|
|
56
|
+
path.join(libsDir, "macos") +
|
|
57
|
+
" " +
|
|
58
|
+
path.join(libsDir, "tvos")
|
|
59
|
+
);
|
|
60
|
+
fs.mkdirSync(path.join(libsDir, "ios"), { recursive: true });
|
|
61
|
+
fs.mkdirSync(path.join(libsDir, "macos"), { recursive: true });
|
|
62
|
+
execSync(
|
|
63
|
+
'cp -R "' +
|
|
64
|
+
iosPackage +
|
|
65
|
+
'/libs/"*.xcframework "' +
|
|
66
|
+
path.join(libsDir, "ios") +
|
|
67
|
+
'/"'
|
|
68
|
+
);
|
|
69
|
+
execSync(
|
|
70
|
+
'cp -R "' +
|
|
71
|
+
macosPackage +
|
|
72
|
+
'/libs/"*.xcframework "' +
|
|
73
|
+
path.join(libsDir, "macos") +
|
|
74
|
+
'/"'
|
|
75
|
+
);
|
|
76
|
+
|
|
77
|
+
// Handle tvOS (non-Graphite only)
|
|
78
|
+
if (!useGraphite) {
|
|
79
|
+
try {
|
|
80
|
+
const tvosPackage = path.dirname(
|
|
81
|
+
require.resolve(prefix + "-apple-tvos/package.json")
|
|
82
|
+
);
|
|
83
|
+
console.log("-- Skia tvOS package: " + tvosPackage);
|
|
84
|
+
fs.mkdirSync(path.join(libsDir, "tvos"), { recursive: true });
|
|
85
|
+
execSync(
|
|
86
|
+
'cp -R "' +
|
|
87
|
+
tvosPackage +
|
|
88
|
+
'/libs/"*.xcframework "' +
|
|
89
|
+
path.join(libsDir, "tvos") +
|
|
90
|
+
'/"'
|
|
91
|
+
);
|
|
92
|
+
} catch (e) {
|
|
93
|
+
console.log("-- tvOS package not found, skipping");
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
console.log("-- Copied Apple xcframeworks to libs/");
|
|
98
|
+
|
|
99
|
+
// --- Android ---
|
|
100
|
+
|
|
101
|
+
const androidPackageName = useGraphite
|
|
102
|
+
? "react-native-skia-graphite-android"
|
|
103
|
+
: "react-native-skia-android";
|
|
104
|
+
|
|
105
|
+
let androidPackage;
|
|
106
|
+
try {
|
|
107
|
+
androidPackage = path.dirname(
|
|
108
|
+
require.resolve(androidPackageName + "/package.json")
|
|
109
|
+
);
|
|
110
|
+
} catch (e) {
|
|
111
|
+
console.error("ERROR: Could not find " + androidPackageName);
|
|
112
|
+
console.error("Make sure you have run yarn install or npm install");
|
|
113
|
+
process.exit(1);
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
const androidSrcLibs = path.join(androidPackage, "libs");
|
|
117
|
+
if (!fs.existsSync(androidSrcLibs)) {
|
|
118
|
+
console.error(
|
|
119
|
+
"ERROR: Skia prebuilt binaries not found in " + androidPackageName + "!"
|
|
120
|
+
);
|
|
121
|
+
process.exit(1);
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
console.log("-- Skia Android package: " + androidPackage);
|
|
125
|
+
|
|
126
|
+
// Copy Android libs (per-ABI static libraries)
|
|
127
|
+
const androidDest = path.join(libsDir, "android");
|
|
128
|
+
execSync("rm -rf " + androidDest);
|
|
129
|
+
execSync('cp -R "' + androidSrcLibs + '" "' + androidDest + '"');
|
|
130
|
+
|
|
131
|
+
console.log("-- Copied Android libs to libs/android/");
|
|
@@ -22,7 +22,7 @@ const copyFrameOnAndroid = (currentFrame: SharedValue<SkImage | null>) => {
|
|
|
22
22
|
if (Platform.OS === "android") {
|
|
23
23
|
const tex = currentFrame.value;
|
|
24
24
|
if (tex) {
|
|
25
|
-
currentFrame.value = tex
|
|
25
|
+
currentFrame.value = tex; //.makeNonTextureImage();
|
|
26
26
|
tex.dispose();
|
|
27
27
|
}
|
|
28
28
|
}
|
|
@@ -32,9 +32,6 @@ const setFrame = (video: Video, currentFrame: SharedValue<SkImage | null>) => {
|
|
|
32
32
|
"worklet";
|
|
33
33
|
const img = video.nextImage();
|
|
34
34
|
if (img) {
|
|
35
|
-
if (currentFrame.value) {
|
|
36
|
-
currentFrame.value.dispose();
|
|
37
|
-
}
|
|
38
35
|
currentFrame.value = img;
|
|
39
36
|
copyFrameOnAndroid(currentFrame);
|
|
40
37
|
}
|
package/src/mock/index.ts
CHANGED
|
@@ -23,6 +23,7 @@ export const Mock = (CanvasKit: CanvasKit) => {
|
|
|
23
23
|
...require("../dom/types"),
|
|
24
24
|
...require("../dom/nodes"),
|
|
25
25
|
Canvas: require("react-native").View,
|
|
26
|
+
WebGPUCanvas: require("react-native").View,
|
|
26
27
|
SkiaPictureView: require("react-native").View,
|
|
27
28
|
JsiSkImage: JsiSkImage,
|
|
28
29
|
drawAsPicture: Noop,
|
|
@@ -1,5 +1,16 @@
|
|
|
1
1
|
import type { SkSurface } from "./Surface";
|
|
2
2
|
|
|
3
|
+
export const ColorSpace = {
|
|
4
|
+
SRGB: "srgb",
|
|
5
|
+
DisplayP3: "display-p3",
|
|
6
|
+
} as const;
|
|
7
|
+
|
|
8
|
+
export type ColorSpaceValue = (typeof ColorSpace)[keyof typeof ColorSpace];
|
|
9
|
+
|
|
10
|
+
export interface SurfaceOptions {
|
|
11
|
+
colorSpace: ColorSpaceValue;
|
|
12
|
+
}
|
|
13
|
+
|
|
3
14
|
export interface SurfaceFactory {
|
|
4
15
|
/**
|
|
5
16
|
* Returns a CPU backed surface with the given dimensions, an SRGB colorspace, Unpremul
|
|
@@ -14,6 +25,11 @@ export interface SurfaceFactory {
|
|
|
14
25
|
* Creates a GPU backed surface.
|
|
15
26
|
* @param width - number of pixels of the width of the drawable area.
|
|
16
27
|
* @param height - number of pixels of the height of the drawable area.
|
|
28
|
+
* @param opts - optional surface options (e.g. colorSpace: "display-p3" | "srgb").
|
|
17
29
|
*/
|
|
18
|
-
MakeOffscreen: (
|
|
30
|
+
MakeOffscreen: (
|
|
31
|
+
width: number,
|
|
32
|
+
height: number,
|
|
33
|
+
opts?: SurfaceOptions
|
|
34
|
+
) => SkSurface | null;
|
|
19
35
|
}
|