react-native-skia 2.15.0 → 3.0.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/CMakeLists.txt +1 -0
- package/android/build.gradle +17 -0
- package/android/cpp/jni/include/JniSkiaBaseView.h +9 -4
- package/android/cpp/jni/include/JniSkiaGraphiteView.h +2 -2
- package/android/cpp/jni/include/JniSkiaPictureView.h +1 -12
- package/cpp/api/recorder/ColorFilters.h +1 -0
- package/cpp/api/recorder/Convertor.h +39 -11
- package/cpp/api/recorder/DataTypes.h +12 -0
- package/cpp/api/recorder/DrawingCtx.h +14 -0
- package/cpp/api/recorder/Drawings.h +5 -0
- package/cpp/api/recorder/PathEffects.h +8 -0
- package/cpp/api/recorder/RNRecorder.h +68 -11
- package/cpp/api/recorder/Shaders.h +3 -0
- package/cpp/dawn/include/dawn/dawn_proc.h +53 -0
- package/cpp/dawn/include/dawn/dawn_proc_table.h +329 -0
- package/cpp/dawn/include/dawn/dawn_thread_dispatch_proc.h +47 -0
- package/cpp/dawn/include/dawn/dawn_version.h +41 -0
- package/cpp/dawn/include/dawn/native/D3D11Backend.h +65 -0
- package/cpp/dawn/include/dawn/native/D3D12Backend.h +104 -0
- package/cpp/dawn/include/dawn/native/D3DBackend.h +56 -0
- package/cpp/dawn/include/dawn/native/DawnNative.h +367 -0
- package/cpp/dawn/include/dawn/native/MetalBackend.h +56 -0
- package/cpp/dawn/include/dawn/native/NullBackend.h +39 -0
- package/cpp/dawn/include/dawn/native/OpenGLBackend.h +89 -0
- package/cpp/dawn/include/dawn/native/VulkanBackend.h +183 -0
- package/cpp/dawn/include/dawn/native/WebGPUBackend.h +49 -0
- package/cpp/dawn/include/dawn/native/dawn_native_export.h +49 -0
- package/cpp/dawn/include/dawn/platform/DawnPlatform.h +211 -0
- package/cpp/dawn/include/dawn/platform/dawn_platform_export.h +49 -0
- package/cpp/dawn/include/dawn/replay/Replay.h +99 -0
- package/cpp/dawn/include/dawn/replay/dawn_replay_export.h +49 -0
- package/cpp/dawn/include/dawn/webgpu_cpp_print.h +2868 -0
- package/cpp/dawn/include/tint/tint.h +91 -0
- package/cpp/dawn/include/webgpu/webgpu.h +5063 -0
- package/cpp/dawn/include/webgpu/webgpu_cpp.h +10401 -0
- package/cpp/dawn/include/webgpu/webgpu_cpp_chained_struct.h +57 -0
- package/cpp/dawn/include/webgpu/webgpu_enum_class_bitmasks.h +163 -0
- package/cpp/dawn/include/webgpu/webgpu_glfw.h +88 -0
- package/cpp/rnskia/RNDawnContext.h +6 -0
- package/cpp/rnskia/RNSkGraphiteProducer.cpp +189 -0
- package/cpp/rnskia/RNSkGraphiteProducer.h +116 -0
- package/cpp/rnskia/RNSkGraphiteView.h +129 -24
- package/cpp/rnskia/RNSkJsiViewApi.h +2 -6
- package/cpp/rnskia/RNSkPictureView.cpp +22 -11
- package/cpp/rnskia/RNSkPictureView.h +24 -11
- package/cpp/rnskia/RNSkThreadPool.h +91 -0
- package/cpp/rnskia/RNSkView.h +18 -0
- package/cpp/skia/src/gpu/graphite/ContextOptionsPriv.h +45 -0
- package/cpp/skia/src/gpu/graphite/ResourceTypes.h +362 -0
- package/cpp/skia/src/gpu/graphite/TextureProxyView.h +105 -0
- package/lib/commonjs/index.d.ts +4 -1
- package/lib/commonjs/index.js +31 -12
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/mock/index.js +1 -0
- package/lib/commonjs/mock/index.js.map +1 -1
- package/lib/commonjs/renderer/Canvas.d.ts +10 -1
- package/lib/commonjs/renderer/Canvas.js +37 -10
- package/lib/commonjs/renderer/Canvas.js.map +1 -1
- package/lib/commonjs/renderer/DefaultCanvas.d.ts +8 -0
- package/lib/commonjs/renderer/DefaultCanvas.js +42 -0
- package/lib/commonjs/renderer/DefaultCanvas.js.map +1 -0
- package/lib/commonjs/renderer/GraphiteCanvas.d.ts +22 -0
- package/lib/commonjs/renderer/GraphiteCanvas.js +64 -0
- package/lib/commonjs/renderer/GraphiteCanvas.js.map +1 -0
- package/lib/commonjs/renderer/GraphiteCanvas.web.d.ts +1 -0
- package/lib/commonjs/renderer/GraphiteCanvas.web.js +13 -0
- package/lib/commonjs/renderer/GraphiteCanvas.web.js.map +1 -0
- package/lib/module/index.d.ts +4 -1
- package/lib/module/index.js +3 -1
- package/lib/module/index.js.map +1 -1
- package/lib/module/mock/index.js +1 -0
- package/lib/module/mock/index.js.map +1 -1
- package/lib/module/renderer/Canvas.d.ts +10 -1
- package/lib/module/renderer/Canvas.js +35 -9
- package/lib/module/renderer/Canvas.js.map +1 -1
- package/lib/module/renderer/DefaultCanvas.d.ts +8 -0
- package/lib/module/renderer/DefaultCanvas.js +34 -0
- package/lib/module/renderer/DefaultCanvas.js.map +1 -0
- package/lib/module/renderer/GraphiteCanvas.d.ts +22 -0
- package/lib/module/renderer/GraphiteCanvas.js +57 -0
- package/lib/module/renderer/GraphiteCanvas.js.map +1 -0
- package/lib/module/renderer/GraphiteCanvas.web.d.ts +1 -0
- package/lib/module/renderer/GraphiteCanvas.web.js +4 -0
- package/lib/module/renderer/GraphiteCanvas.web.js.map +1 -0
- package/lib/typescript/src/index.d.ts +4 -1
- package/lib/typescript/src/renderer/Canvas.d.ts +10 -1
- package/lib/typescript/src/renderer/DefaultCanvas.d.ts +8 -0
- package/lib/typescript/src/renderer/GraphiteCanvas.d.ts +22 -0
- package/lib/typescript/src/renderer/GraphiteCanvas.web.d.ts +1 -0
- package/libs/.graphite +1 -0
- package/package.json +7 -8
- package/react-native-skia.podspec +18 -1
- package/src/index.ts +4 -1
- package/src/mock/index.ts +1 -0
- package/src/renderer/Canvas.tsx +29 -9
- package/src/renderer/DefaultCanvas.tsx +41 -0
- package/src/renderer/GraphiteCanvas.tsx +61 -0
- package/src/renderer/GraphiteCanvas.web.tsx +3 -0
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import type { CanvasProps } from "./Canvas";
|
|
3
|
+
/**
|
|
4
|
+
* The declarative canvas on the Graphite view. It takes the same props and
|
|
5
|
+
* exposes the same ref as {@link Canvas}, and draws the same children, but
|
|
6
|
+
* the frames are produced differently:
|
|
7
|
+
*
|
|
8
|
+
* - the JS thread records the scene graph into a native recorder once per
|
|
9
|
+
* React commit and hands it to the view;
|
|
10
|
+
* - the Reanimated UI runtime only reads the shared values into it (the one
|
|
11
|
+
* step that needs a JS runtime), it never replays anything;
|
|
12
|
+
* - a dedicated native thread pool replays the recorder into a Graphite
|
|
13
|
+
* recording whenever the content changed, at most once per presented frame;
|
|
14
|
+
* - the view presents the recording on the next vsync.
|
|
15
|
+
*
|
|
16
|
+
* Neither the JS thread nor the UI thread pays for drawing. It requires the
|
|
17
|
+
* Graphite backend (install-skia-graphite); with the default backend the view
|
|
18
|
+
* renders nothing. `colorSpace`, `android` and `androidWarmup` are accepted
|
|
19
|
+
* for API compatibility and ignored: the Graphite view renders in sRGB and
|
|
20
|
+
* uses its own backing view.
|
|
21
|
+
*/
|
|
22
|
+
export declare const GraphiteCanvas: ({ debug, opaque, children, onSize, colorSpace, highBitDepth, androidWarmup, android, ref, onLayout, ...viewProps }: CanvasProps) => React.JSX.Element;
|
|
@@ -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 from "react";
|
|
3
|
+
import SkiaGraphiteViewNativeComponent from "../specs/SkiaGraphiteViewNativeComponent";
|
|
4
|
+
import { useCanvasRoot } from "./Canvas";
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* The declarative canvas on the Graphite view. It takes the same props and
|
|
8
|
+
* exposes the same ref as {@link Canvas}, and draws the same children, but
|
|
9
|
+
* the frames are produced differently:
|
|
10
|
+
*
|
|
11
|
+
* - the JS thread records the scene graph into a native recorder once per
|
|
12
|
+
* React commit and hands it to the view;
|
|
13
|
+
* - the Reanimated UI runtime only reads the shared values into it (the one
|
|
14
|
+
* step that needs a JS runtime), it never replays anything;
|
|
15
|
+
* - a dedicated native thread pool replays the recorder into a Graphite
|
|
16
|
+
* recording whenever the content changed, at most once per presented frame;
|
|
17
|
+
* - the view presents the recording on the next vsync.
|
|
18
|
+
*
|
|
19
|
+
* Neither the JS thread nor the UI thread pays for drawing. It requires the
|
|
20
|
+
* Graphite backend (install-skia-graphite); with the default backend the view
|
|
21
|
+
* renders nothing. `colorSpace`, `android` and `androidWarmup` are accepted
|
|
22
|
+
* for API compatibility and ignored: the Graphite view renders in sRGB and
|
|
23
|
+
* uses its own backing view.
|
|
24
|
+
*/
|
|
25
|
+
export const GraphiteCanvas = ({
|
|
26
|
+
debug,
|
|
27
|
+
opaque,
|
|
28
|
+
children,
|
|
29
|
+
onSize,
|
|
30
|
+
colorSpace,
|
|
31
|
+
highBitDepth = false,
|
|
32
|
+
androidWarmup,
|
|
33
|
+
android,
|
|
34
|
+
ref,
|
|
35
|
+
onLayout,
|
|
36
|
+
...viewProps
|
|
37
|
+
}) => {
|
|
38
|
+
const {
|
|
39
|
+
nativeId,
|
|
40
|
+
viewRef
|
|
41
|
+
} = useCanvasRoot({
|
|
42
|
+
children,
|
|
43
|
+
onSize,
|
|
44
|
+
ref,
|
|
45
|
+
onLayout
|
|
46
|
+
});
|
|
47
|
+
return /*#__PURE__*/React.createElement(SkiaGraphiteViewNativeComponent, _extends({
|
|
48
|
+
ref: viewRef,
|
|
49
|
+
collapsable: false,
|
|
50
|
+
nativeID: `${nativeId}`,
|
|
51
|
+
debug: debug,
|
|
52
|
+
opaque: opaque,
|
|
53
|
+
highBitDepth: highBitDepth,
|
|
54
|
+
onLayout: onLayout
|
|
55
|
+
}, viewProps));
|
|
56
|
+
};
|
|
57
|
+
//# sourceMappingURL=GraphiteCanvas.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["React","SkiaGraphiteViewNativeComponent","useCanvasRoot","GraphiteCanvas","debug","opaque","children","onSize","colorSpace","highBitDepth","androidWarmup","android","ref","onLayout","viewProps","nativeId","viewRef","createElement","_extends","collapsable","nativeID"],"sources":["GraphiteCanvas.tsx"],"sourcesContent":["import React from \"react\";\n\nimport SkiaGraphiteViewNativeComponent from \"../specs/SkiaGraphiteViewNativeComponent\";\n\nimport type { CanvasProps } from \"./Canvas\";\nimport { useCanvasRoot } from \"./Canvas\";\n\n/**\n * The declarative canvas on the Graphite view. It takes the same props and\n * exposes the same ref as {@link Canvas}, and draws the same children, but\n * the frames are produced differently:\n *\n * - the JS thread records the scene graph into a native recorder once per\n * React commit and hands it to the view;\n * - the Reanimated UI runtime only reads the shared values into it (the one\n * step that needs a JS runtime), it never replays anything;\n * - a dedicated native thread pool replays the recorder into a Graphite\n * recording whenever the content changed, at most once per presented frame;\n * - the view presents the recording on the next vsync.\n *\n * Neither the JS thread nor the UI thread pays for drawing. It requires the\n * Graphite backend (install-skia-graphite); with the default backend the view\n * renders nothing. `colorSpace`, `android` and `androidWarmup` are accepted\n * for API compatibility and ignored: the Graphite view renders in sRGB and\n * uses its own backing view.\n */\nexport const GraphiteCanvas = ({\n debug,\n opaque,\n children,\n onSize,\n\n colorSpace,\n highBitDepth = false,\n\n androidWarmup,\n\n android,\n ref,\n onLayout,\n ...viewProps\n}: CanvasProps) => {\n const { nativeId, viewRef } = useCanvasRoot({\n children,\n onSize,\n ref,\n onLayout,\n });\n return (\n <SkiaGraphiteViewNativeComponent\n ref={viewRef}\n collapsable={false}\n nativeID={`${nativeId}`}\n debug={debug}\n opaque={opaque}\n highBitDepth={highBitDepth}\n onLayout={onLayout}\n {...viewProps}\n />\n );\n};\n"],"mappings":";AAAA,OAAOA,KAAK,MAAM,OAAO;AAEzB,OAAOC,+BAA+B,MAAM,0CAA0C;AAGtF,SAASC,aAAa,QAAQ,UAAU;;AAExC;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,MAAMC,cAAc,GAAGA,CAAC;EAC7BC,KAAK;EACLC,MAAM;EACNC,QAAQ;EACRC,MAAM;EAENC,UAAU;EACVC,YAAY,GAAG,KAAK;EAEpBC,aAAa;EAEbC,OAAO;EACPC,GAAG;EACHC,QAAQ;EACR,GAAGC;AACQ,CAAC,KAAK;EACjB,MAAM;IAAEC,QAAQ;IAAEC;EAAQ,CAAC,GAAGd,aAAa,CAAC;IAC1CI,QAAQ;IACRC,MAAM;IACNK,GAAG;IACHC;EACF,CAAC,CAAC;EACF,oBACEb,KAAA,CAAAiB,aAAA,CAAChB,+BAA+B,EAAAiB,QAAA;IAC9BN,GAAG,EAAEI,OAAQ;IACbG,WAAW,EAAE,KAAM;IACnBC,QAAQ,EAAE,GAAGL,QAAQ,EAAG;IACxBX,KAAK,EAAEA,KAAM;IACbC,MAAM,EAAEA,MAAO;IACfI,YAAY,EAAEA,YAAa;IAC3BI,QAAQ,EAAEA;EAAS,GACfC,SAAS,CACd,CAAC;AAEN,CAAC","ignoreList":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { Canvas as GraphiteCanvas } from "./Canvas";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["Canvas","GraphiteCanvas"],"sources":["GraphiteCanvas.web.tsx"],"sourcesContent":["// The Graphite view is native only: on the web, GraphiteCanvas is the regular\n// Canvas.\nexport { Canvas as GraphiteCanvas } from \"./Canvas\";\n"],"mappings":"AAAA;AACA;AACA,SAASA,MAAM,IAAIC,cAAc,QAAQ,UAAU","ignoreList":[]}
|
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
import "./skia/NativeSetup";
|
|
2
2
|
export { JsiSkImage } from "./skia/web/JsiSkImage";
|
|
3
3
|
export * from "./renderer";
|
|
4
|
-
export
|
|
4
|
+
export { useCanvasRef, useCanvasSize } from "./renderer/Canvas";
|
|
5
|
+
export type { CanvasProps, CanvasRef } from "./renderer/Canvas";
|
|
6
|
+
export { GraphiteCanvas } from "./renderer/GraphiteCanvas";
|
|
7
|
+
export { Canvas } from "./renderer/DefaultCanvas";
|
|
5
8
|
export * from "./renderer/Offscreen";
|
|
6
9
|
export * from "./views";
|
|
7
10
|
export * from "./skia";
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { FC, RefObject } from "react";
|
|
2
2
|
import React from "react";
|
|
3
|
-
import type { MeasureInWindowOnSuccessCallback, MeasureOnSuccessCallback, ViewProps } from "react-native";
|
|
3
|
+
import type { MeasureInWindowOnSuccessCallback, MeasureOnSuccessCallback, View, ViewProps } from "react-native";
|
|
4
4
|
import type { SharedValue } from "react-native-reanimated";
|
|
5
5
|
import type { AndroidCanvasProps } from "../views/types";
|
|
6
6
|
import type { SkImage, SkRect, SkSize } from "../skia/types";
|
|
@@ -45,4 +45,13 @@ export interface CanvasProps extends Omit<ViewProps, "onLayout"> {
|
|
|
45
45
|
androidWarmup?: boolean;
|
|
46
46
|
__destroyWebGLContextAfterRender?: boolean;
|
|
47
47
|
}
|
|
48
|
+
/**
|
|
49
|
+
* What every canvas shares, whichever native view it renders into: the native
|
|
50
|
+
* id, the scene graph root rendered into it, the `onSize` measurement and the
|
|
51
|
+
* imperative handle of the ref.
|
|
52
|
+
*/
|
|
53
|
+
export declare const useCanvasRoot: ({ children, onSize, ref, onLayout, }: Pick<CanvasProps, "children" | "onSize" | "ref" | "onLayout">) => {
|
|
54
|
+
nativeId: number;
|
|
55
|
+
viewRef: RefObject<View | null>;
|
|
56
|
+
};
|
|
48
57
|
export declare const Canvas: ({ debug, opaque, children, onSize, colorSpace, highBitDepth, androidWarmup, android, ref, onLayout, ...viewProps }: CanvasProps) => React.JSX.Element;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import type { CanvasProps } from "./Canvas";
|
|
3
|
+
/**
|
|
4
|
+
* `<Canvas>` renders {@link GraphiteCanvas} when React Native Skia is
|
|
5
|
+
* configured with the Graphite backend (install-skia-graphite), and the
|
|
6
|
+
* picture view based canvas otherwise. Both take the same props and ref.
|
|
7
|
+
*/
|
|
8
|
+
export declare const Canvas: (props: CanvasProps) => React.JSX.Element;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import type { CanvasProps } from "./Canvas";
|
|
3
|
+
/**
|
|
4
|
+
* The declarative canvas on the Graphite view. It takes the same props and
|
|
5
|
+
* exposes the same ref as {@link Canvas}, and draws the same children, but
|
|
6
|
+
* the frames are produced differently:
|
|
7
|
+
*
|
|
8
|
+
* - the JS thread records the scene graph into a native recorder once per
|
|
9
|
+
* React commit and hands it to the view;
|
|
10
|
+
* - the Reanimated UI runtime only reads the shared values into it (the one
|
|
11
|
+
* step that needs a JS runtime), it never replays anything;
|
|
12
|
+
* - a dedicated native thread pool replays the recorder into a Graphite
|
|
13
|
+
* recording whenever the content changed, at most once per presented frame;
|
|
14
|
+
* - the view presents the recording on the next vsync.
|
|
15
|
+
*
|
|
16
|
+
* Neither the JS thread nor the UI thread pays for drawing. It requires the
|
|
17
|
+
* Graphite backend (install-skia-graphite); with the default backend the view
|
|
18
|
+
* renders nothing. `colorSpace`, `android` and `androidWarmup` are accepted
|
|
19
|
+
* for API compatibility and ignored: the Graphite view renders in sRGB and
|
|
20
|
+
* uses its own backing view.
|
|
21
|
+
*/
|
|
22
|
+
export declare const GraphiteCanvas: ({ debug, opaque, children, onSize, colorSpace, highBitDepth, androidWarmup, android, ref, onLayout, ...viewProps }: CanvasProps) => React.JSX.Element;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { Canvas as GraphiteCanvas } from "./Canvas";
|
package/libs/.graphite
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
m154
|
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": "
|
|
11
|
+
"version": "3.0.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",
|
|
@@ -142,16 +142,15 @@
|
|
|
142
142
|
},
|
|
143
143
|
"dependencies": {
|
|
144
144
|
"canvaskit-wasm": "0.41.0",
|
|
145
|
-
"react-native-skia-android": "154.0.
|
|
146
|
-
"react-native-skia-apple-ios": "154.0.
|
|
147
|
-
"react-native-skia-apple-macos": "154.0.
|
|
148
|
-
"react-native-skia-apple-tvos": "154.0.0",
|
|
145
|
+
"react-native-skia-graphite-android": "154.0.1",
|
|
146
|
+
"react-native-skia-graphite-apple-ios": "154.0.1",
|
|
147
|
+
"react-native-skia-graphite-apple-macos": "154.0.1",
|
|
149
148
|
"react-reconciler": "0.31.0"
|
|
150
149
|
},
|
|
151
150
|
"graphiteDependencies": {
|
|
152
|
-
"react-native-skia-graphite-android": "154.0.
|
|
153
|
-
"react-native-skia-graphite-apple-ios": "154.0.
|
|
154
|
-
"react-native-skia-graphite-apple-macos": "154.0.
|
|
151
|
+
"react-native-skia-graphite-android": "154.0.1",
|
|
152
|
+
"react-native-skia-graphite-apple-ios": "154.0.1",
|
|
153
|
+
"react-native-skia-graphite-apple-macos": "154.0.1"
|
|
155
154
|
},
|
|
156
155
|
"eslintIgnore": [
|
|
157
156
|
"node_modules/",
|
|
@@ -37,6 +37,11 @@ install_apple_skia_libs = lambda do |base_dir, packages|
|
|
|
37
37
|
src = File.join(pkg_dir, 'libs')
|
|
38
38
|
next unless Dir.exist?(src) && !Dir.glob(File.join(src, '*.xcframework')).empty?
|
|
39
39
|
|
|
40
|
+
# Graphite packages carry the Dawn release tag they ship (libs/.dawn-version),
|
|
41
|
+
# used below for the react-native-webgpu version check.
|
|
42
|
+
dawn_version = File.join(src, '.dawn-version')
|
|
43
|
+
FileUtils.cp(dawn_version, File.join(base_dir, 'libs', '.dawn-version')) if File.exist?(dawn_version)
|
|
44
|
+
|
|
40
45
|
version = JSON.parse(File.read(File.join(pkg_dir, 'package.json')))['version'].to_s
|
|
41
46
|
dest = File.join(base_dir, 'libs', platform)
|
|
42
47
|
marker = File.join(dest, '.version')
|
|
@@ -110,7 +115,19 @@ if use_graphite && has_webgpu_pkg
|
|
|
110
115
|
Pod::UI.puts "react-native-skia: Dawn versions match (#{skia_dawn})"
|
|
111
116
|
end
|
|
112
117
|
end
|
|
113
|
-
|
|
118
|
+
if use_graphite && !has_webgpu_pkg
|
|
119
|
+
# CocoaPods silently skips missing vendored frameworks, which would surface
|
|
120
|
+
# later as undefined dawn::native symbols at link time. Fail early instead.
|
|
121
|
+
%w[ios macos].each do |platform|
|
|
122
|
+
platform_dir = File.join(__dir__, 'libs', platform)
|
|
123
|
+
# A missing libs/<platform> is reported by the prebuilt binaries check below.
|
|
124
|
+
next if !Dir.exist?(platform_dir) || Dir.exist?(File.join(platform_dir, 'libwebgpu_dawn.xcframework'))
|
|
125
|
+
raise "react-native-skia: libwebgpu_dawn.xcframework not found in libs/#{platform}. " \
|
|
126
|
+
"The installed #{apple_skia_packages[platform]} package does not ship the shared " \
|
|
127
|
+
"Dawn library this Graphite build links against. Upgrade it, then run `pod install` again."
|
|
128
|
+
end
|
|
129
|
+
framework_names += ['libwebgpu_dawn']
|
|
130
|
+
end
|
|
114
131
|
|
|
115
132
|
# Verify that the prebuilt binaries are available (copied in above from the npm
|
|
116
133
|
# packages, or downloaded by install-skia-graphite for in-repo Graphite builds).
|
package/src/index.ts
CHANGED
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
import "./skia/NativeSetup";
|
|
2
2
|
export { JsiSkImage } from "./skia/web/JsiSkImage";
|
|
3
3
|
export * from "./renderer";
|
|
4
|
-
export
|
|
4
|
+
export { useCanvasRef, useCanvasSize } from "./renderer/Canvas";
|
|
5
|
+
export type { CanvasProps, CanvasRef } from "./renderer/Canvas";
|
|
6
|
+
export { GraphiteCanvas } from "./renderer/GraphiteCanvas";
|
|
7
|
+
export { Canvas } from "./renderer/DefaultCanvas";
|
|
5
8
|
export * from "./renderer/Offscreen";
|
|
6
9
|
export * from "./views";
|
|
7
10
|
export * from "./skia";
|
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
|
+
GraphiteCanvas: require("react-native").View,
|
|
26
27
|
getPreferredHighBitDepthCanvasFormat: () => "rgba16float",
|
|
27
28
|
SkiaPictureView: require("react-native").View,
|
|
28
29
|
SkiaGraphiteView: require("react-native").View,
|
package/src/renderer/Canvas.tsx
CHANGED
|
@@ -98,19 +98,17 @@ const resolveSurfaceType = (
|
|
|
98
98
|
? surfaceType
|
|
99
99
|
: "auto";
|
|
100
100
|
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
101
|
+
/**
|
|
102
|
+
* What every canvas shares, whichever native view it renders into: the native
|
|
103
|
+
* id, the scene graph root rendered into it, the `onSize` measurement and the
|
|
104
|
+
* imperative handle of the ref.
|
|
105
|
+
*/
|
|
106
|
+
export const useCanvasRoot = ({
|
|
104
107
|
children,
|
|
105
108
|
onSize,
|
|
106
|
-
colorSpace = "p3",
|
|
107
|
-
highBitDepth = false,
|
|
108
|
-
androidWarmup = false,
|
|
109
|
-
android,
|
|
110
109
|
ref,
|
|
111
110
|
onLayout,
|
|
112
|
-
|
|
113
|
-
}: CanvasProps) => {
|
|
111
|
+
}: Pick<CanvasProps, "children" | "onSize" | "ref" | "onLayout">) => {
|
|
114
112
|
if (onLayout && Platform.OS !== "web") {
|
|
115
113
|
console.error(
|
|
116
114
|
"<Canvas onLayout={onLayout} /> is not supported on the new architecture, to fix the issue, see: https://shopify.github.io/react-native-skia/docs/canvas/overview/#getting-the-canvas-size"
|
|
@@ -185,6 +183,28 @@ export const Canvas = ({
|
|
|
185
183
|
},
|
|
186
184
|
}) as CanvasRef
|
|
187
185
|
);
|
|
186
|
+
return { nativeId, viewRef };
|
|
187
|
+
};
|
|
188
|
+
|
|
189
|
+
export const Canvas = ({
|
|
190
|
+
debug,
|
|
191
|
+
opaque,
|
|
192
|
+
children,
|
|
193
|
+
onSize,
|
|
194
|
+
colorSpace = "p3",
|
|
195
|
+
highBitDepth = false,
|
|
196
|
+
androidWarmup = false,
|
|
197
|
+
android,
|
|
198
|
+
ref,
|
|
199
|
+
onLayout,
|
|
200
|
+
...viewProps
|
|
201
|
+
}: CanvasProps) => {
|
|
202
|
+
const { nativeId, viewRef } = useCanvasRoot({
|
|
203
|
+
children,
|
|
204
|
+
onSize,
|
|
205
|
+
ref,
|
|
206
|
+
onLayout,
|
|
207
|
+
});
|
|
188
208
|
|
|
189
209
|
const onLayoutWeb = useCallback(
|
|
190
210
|
(e: LayoutChangeEvent) => {
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
|
|
3
|
+
import { Skia } from "../skia";
|
|
4
|
+
import { Platform } from "../Platform";
|
|
5
|
+
|
|
6
|
+
import type { CanvasProps } from "./Canvas";
|
|
7
|
+
import { Canvas as PictureCanvas } from "./Canvas";
|
|
8
|
+
import { GraphiteCanvas } from "./GraphiteCanvas";
|
|
9
|
+
|
|
10
|
+
let useGraphite: boolean | null = null;
|
|
11
|
+
|
|
12
|
+
// Whether this build runs the Graphite backend. Resolved on the first render
|
|
13
|
+
// (the native API is installed by then) and cached: getNativeDevice() throws
|
|
14
|
+
// on Ganesh builds. On the web, GraphiteCanvas is the regular canvas anyway.
|
|
15
|
+
const hasGraphite = () => {
|
|
16
|
+
if (useGraphite === null) {
|
|
17
|
+
if (Platform.OS === "web") {
|
|
18
|
+
useGraphite = false;
|
|
19
|
+
} else {
|
|
20
|
+
try {
|
|
21
|
+
useGraphite = typeof Skia.getNativeDevice() === "bigint";
|
|
22
|
+
} catch {
|
|
23
|
+
useGraphite = false;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
return useGraphite;
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* `<Canvas>` renders {@link GraphiteCanvas} when React Native Skia is
|
|
32
|
+
* configured with the Graphite backend (install-skia-graphite), and the
|
|
33
|
+
* picture view based canvas otherwise. Both take the same props and ref.
|
|
34
|
+
*/
|
|
35
|
+
export const Canvas = (props: CanvasProps) => {
|
|
36
|
+
return hasGraphite() ? (
|
|
37
|
+
<GraphiteCanvas {...props} />
|
|
38
|
+
) : (
|
|
39
|
+
<PictureCanvas {...props} />
|
|
40
|
+
);
|
|
41
|
+
};
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
|
|
3
|
+
import SkiaGraphiteViewNativeComponent from "../specs/SkiaGraphiteViewNativeComponent";
|
|
4
|
+
|
|
5
|
+
import type { CanvasProps } from "./Canvas";
|
|
6
|
+
import { useCanvasRoot } from "./Canvas";
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* The declarative canvas on the Graphite view. It takes the same props and
|
|
10
|
+
* exposes the same ref as {@link Canvas}, and draws the same children, but
|
|
11
|
+
* the frames are produced differently:
|
|
12
|
+
*
|
|
13
|
+
* - the JS thread records the scene graph into a native recorder once per
|
|
14
|
+
* React commit and hands it to the view;
|
|
15
|
+
* - the Reanimated UI runtime only reads the shared values into it (the one
|
|
16
|
+
* step that needs a JS runtime), it never replays anything;
|
|
17
|
+
* - a dedicated native thread pool replays the recorder into a Graphite
|
|
18
|
+
* recording whenever the content changed, at most once per presented frame;
|
|
19
|
+
* - the view presents the recording on the next vsync.
|
|
20
|
+
*
|
|
21
|
+
* Neither the JS thread nor the UI thread pays for drawing. It requires the
|
|
22
|
+
* Graphite backend (install-skia-graphite); with the default backend the view
|
|
23
|
+
* renders nothing. `colorSpace`, `android` and `androidWarmup` are accepted
|
|
24
|
+
* for API compatibility and ignored: the Graphite view renders in sRGB and
|
|
25
|
+
* uses its own backing view.
|
|
26
|
+
*/
|
|
27
|
+
export const GraphiteCanvas = ({
|
|
28
|
+
debug,
|
|
29
|
+
opaque,
|
|
30
|
+
children,
|
|
31
|
+
onSize,
|
|
32
|
+
|
|
33
|
+
colorSpace,
|
|
34
|
+
highBitDepth = false,
|
|
35
|
+
|
|
36
|
+
androidWarmup,
|
|
37
|
+
|
|
38
|
+
android,
|
|
39
|
+
ref,
|
|
40
|
+
onLayout,
|
|
41
|
+
...viewProps
|
|
42
|
+
}: CanvasProps) => {
|
|
43
|
+
const { nativeId, viewRef } = useCanvasRoot({
|
|
44
|
+
children,
|
|
45
|
+
onSize,
|
|
46
|
+
ref,
|
|
47
|
+
onLayout,
|
|
48
|
+
});
|
|
49
|
+
return (
|
|
50
|
+
<SkiaGraphiteViewNativeComponent
|
|
51
|
+
ref={viewRef}
|
|
52
|
+
collapsable={false}
|
|
53
|
+
nativeID={`${nativeId}`}
|
|
54
|
+
debug={debug}
|
|
55
|
+
opaque={opaque}
|
|
56
|
+
highBitDepth={highBitDepth}
|
|
57
|
+
onLayout={onLayout}
|
|
58
|
+
{...viewProps}
|
|
59
|
+
/>
|
|
60
|
+
);
|
|
61
|
+
};
|