@shopify/react-native-skia 2.3.9 → 2.3.11
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/include/JniSkiaBaseView.h +9 -2
- package/android/cpp/jni/include/JniSkiaPictureView.h +97 -2
- package/android/cpp/rnskia-android/OpenGLContext.h +1 -0
- package/android/src/main/java/com/shopify/reactnative/skia/SkiaBaseView.java +3 -1
- package/android/src/main/java/com/shopify/reactnative/skia/SkiaPictureView.java +42 -0
- package/android/src/main/java/com/shopify/reactnative/skia/SkiaPictureViewManager.java +5 -0
- package/android/src/paper/java/com/facebook/react/viewmanagers/SkiaPictureViewManagerDelegate.java +8 -2
- package/android/src/paper/java/com/facebook/react/viewmanagers/SkiaPictureViewManagerInterface.java +1 -0
- package/apple/SkiaCVPixelBufferUtils.mm +8 -4
- package/cpp/api/JsiSkAnimatedImage.h +3 -4
- package/cpp/api/JsiSkSurface.h +4 -3
- package/cpp/api/recorder/Drawings.h +10 -2
- package/cpp/api/recorder/JsiRecorder.h +1 -1
- package/cpp/jsi/ViewProperty.h +2 -36
- package/cpp/rnskia/RNSkJsiViewApi.h +2 -5
- package/cpp/rnskia/RNSkPictureView.h +2 -23
- package/cpp/rnskia/RNSkView.h +0 -7
- package/lib/commonjs/renderer/Canvas.js +21 -15
- package/lib/commonjs/renderer/Canvas.js.map +1 -1
- package/lib/commonjs/sksg/Container.native.d.ts +0 -3
- package/lib/commonjs/sksg/Container.native.js +8 -14
- package/lib/commonjs/sksg/Container.native.js.map +1 -1
- package/lib/commonjs/sksg/Reconciler.js +2 -2
- package/lib/commonjs/sksg/Reconciler.js.map +1 -1
- package/lib/commonjs/specs/SkiaPictureViewNativeComponent.d.ts +1 -0
- package/lib/commonjs/specs/SkiaPictureViewNativeComponent.js.map +1 -1
- package/lib/commonjs/views/SkiaPictureView.d.ts +1 -0
- package/lib/commonjs/views/SkiaPictureView.js +3 -1
- package/lib/commonjs/views/SkiaPictureView.js.map +1 -1
- package/lib/commonjs/views/SkiaPictureView.web.js +13 -2
- package/lib/commonjs/views/SkiaPictureView.web.js.map +1 -1
- package/lib/module/renderer/Canvas.js +21 -15
- package/lib/module/renderer/Canvas.js.map +1 -1
- package/lib/module/sksg/Container.native.d.ts +0 -3
- package/lib/module/sksg/Container.native.js +8 -14
- package/lib/module/sksg/Container.native.js.map +1 -1
- package/lib/module/sksg/Reconciler.js +2 -2
- package/lib/module/sksg/Reconciler.js.map +1 -1
- package/lib/module/specs/SkiaPictureViewNativeComponent.d.ts +1 -0
- package/lib/module/specs/SkiaPictureViewNativeComponent.js.map +1 -1
- package/lib/module/views/SkiaPictureView.d.ts +1 -0
- package/lib/module/views/SkiaPictureView.js +3 -1
- package/lib/module/views/SkiaPictureView.js.map +1 -1
- package/lib/module/views/SkiaPictureView.web.js +13 -2
- package/lib/module/views/SkiaPictureView.web.js.map +1 -1
- package/lib/typescript/lib/commonjs/sksg/Container.native.d.ts +0 -4
- package/lib/typescript/lib/module/sksg/Container.native.d.ts +0 -4
- package/lib/typescript/src/sksg/Container.native.d.ts +0 -3
- package/lib/typescript/src/specs/SkiaPictureViewNativeComponent.d.ts +1 -0
- package/lib/typescript/src/views/SkiaPictureView.d.ts +1 -0
- package/package.json +1 -1
- package/src/renderer/Canvas.tsx +20 -17
- package/src/sksg/Container.native.ts +7 -16
- package/src/sksg/Reconciler.ts +2 -2
- package/src/specs/SkiaPictureViewNativeComponent.ts +1 -0
- package/src/views/SkiaPictureView.tsx +3 -1
- package/src/views/SkiaPictureView.web.tsx +14 -2
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["ReactReconciler","NodeType","debug","sksgHostConfig","createContainer","skiaReconciler","injectIntoDevTools","bundleType","version","rendererPackageName","SkiaSGRoot","constructor","Skia","nativeId","_defineProperty","container","root","console","error","sg","children","type","Group","props","isDeclaration","updateContainer","element","Promise","resolve","render","mount","redraw","drawOnCanvas","canvas","getPicture","recorder","PictureRecorder","beginRecording","finishRecordingAsPicture","unmount"],"sources":["Reconciler.ts"],"sourcesContent":["import type { ReactNode } from \"react\";\nimport type { OpaqueRoot } from \"react-reconciler\";\nimport ReactReconciler from \"react-reconciler\";\n\nimport type { SkCanvas, Skia } from \"../skia/types\";\nimport { NodeType } from \"../dom/types\";\n\nimport { debug, sksgHostConfig } from \"./HostConfig\";\nimport type { Container } from \"./StaticContainer\";\nimport { createContainer } from \"./Container\";\n\nimport \"./Elements\";\n\nconst skiaReconciler = ReactReconciler(sksgHostConfig);\n\nskiaReconciler.injectIntoDevTools({\n bundleType: 1,\n version: \"0.0.1\",\n rendererPackageName: \"react-native-skia\",\n});\n\nexport class SkiaSGRoot {\n private root: OpaqueRoot;\n private container: Container;\n\n constructor(\n public Skia: Skia,\n nativeId = -1\n ) {\n this.container = createContainer(Skia, nativeId);\n this.root = skiaReconciler.createContainer(\n this.container,\n 0,\n null,\n
|
|
1
|
+
{"version":3,"names":["ReactReconciler","NodeType","debug","sksgHostConfig","createContainer","skiaReconciler","injectIntoDevTools","bundleType","version","rendererPackageName","SkiaSGRoot","constructor","Skia","nativeId","_defineProperty","strictMode","container","root","console","error","sg","children","type","Group","props","isDeclaration","updateContainer","element","Promise","resolve","render","mount","redraw","drawOnCanvas","canvas","getPicture","recorder","PictureRecorder","beginRecording","finishRecordingAsPicture","unmount"],"sources":["Reconciler.ts"],"sourcesContent":["import type { ReactNode } from \"react\";\nimport type { OpaqueRoot } from \"react-reconciler\";\nimport ReactReconciler from \"react-reconciler\";\n\nimport type { SkCanvas, Skia } from \"../skia/types\";\nimport { NodeType } from \"../dom/types\";\n\nimport { debug, sksgHostConfig } from \"./HostConfig\";\nimport type { Container } from \"./StaticContainer\";\nimport { createContainer } from \"./Container\";\n\nimport \"./Elements\";\n\nconst skiaReconciler = ReactReconciler(sksgHostConfig);\n\nskiaReconciler.injectIntoDevTools({\n bundleType: 1,\n version: \"0.0.1\",\n rendererPackageName: \"react-native-skia\",\n});\n\nexport class SkiaSGRoot {\n private root: OpaqueRoot;\n private container: Container;\n\n constructor(\n public Skia: Skia,\n nativeId = -1\n ) {\n const strictMode = false;\n this.container = createContainer(Skia, nativeId);\n this.root = skiaReconciler.createContainer(\n this.container,\n 0,\n null,\n strictMode,\n null,\n \"\",\n console.error,\n null\n );\n }\n\n get sg() {\n const children = this.container.root;\n return { type: NodeType.Group, props: {}, children, isDeclaration: false };\n }\n\n private updateContainer(element: ReactNode) {\n return new Promise((resolve) => {\n skiaReconciler.updateContainer(element, this.root, null, () => {\n resolve(true);\n });\n });\n }\n\n async render(element: ReactNode) {\n this.container.mount();\n await this.updateContainer(element);\n this.container.redraw();\n }\n\n drawOnCanvas(canvas: SkCanvas) {\n this.container.drawOnCanvas(canvas);\n }\n\n getPicture() {\n const recorder = this.Skia.PictureRecorder();\n const canvas = recorder.beginRecording();\n this.drawOnCanvas(canvas);\n return recorder.finishRecordingAsPicture();\n }\n\n unmount() {\n this.container.unmount();\n return new Promise((resolve) => {\n skiaReconciler.updateContainer(null, this.root, null, () => {\n debug(\"unmountContainer\");\n resolve(true);\n });\n });\n }\n}\n"],"mappings":";;;AAEA,OAAOA,eAAe,MAAM,kBAAkB;AAG9C,SAASC,QAAQ,QAAQ,cAAc;AAEvC,SAASC,KAAK,EAAEC,cAAc,QAAQ,cAAc;AAEpD,SAASC,eAAe,QAAQ,aAAa;AAE7C,OAAO,YAAY;AAEnB,MAAMC,cAAc,GAAGL,eAAe,CAACG,cAAc,CAAC;AAEtDE,cAAc,CAACC,kBAAkB,CAAC;EAChCC,UAAU,EAAE,CAAC;EACbC,OAAO,EAAE,OAAO;EAChBC,mBAAmB,EAAE;AACvB,CAAC,CAAC;AAEF,OAAO,MAAMC,UAAU,CAAC;EAItBC,WAAWA,CACFC,IAAU,EACjBC,QAAQ,GAAG,CAAC,CAAC,EACb;IAAA,KAFOD,IAAU,GAAVA,IAAU;IAAAE,eAAA;IAAAA,eAAA;IAGjB,MAAMC,UAAU,GAAG,KAAK;IACxB,IAAI,CAACC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EAC5C;EAEAC,OAAOA,CAAA,EAAG;IACR,IAAI,CAACxB,SAAS,CAACwB,OAAO,CAAC,CAAC;IACxB,OAAO,IAAIZ,OAAO,CAAEC,OAAO,IAAK;MAC9BxB,cAAc,CAACqB,eAAe,CAAC,IAAI,EAAE,IAAI,CAACT,IAAI,EAAE,IAAI,EAAE,MAAM;QAC1Df,KAAK,CAAC,kBAAkB,CAAC;QACzB2B,OAAO,CAAC,IAAI,CAAC;MACf,CAAC,CAAC;IACJ,CAAC,CAAC;EACJ;AACF","ignoreList":[]}
|
|
@@ -3,6 +3,7 @@ export interface NativeProps extends ViewProps {
|
|
|
3
3
|
debug?: boolean;
|
|
4
4
|
opaque?: boolean;
|
|
5
5
|
colorSpace?: string;
|
|
6
|
+
coldStart?: boolean;
|
|
6
7
|
}
|
|
7
8
|
declare const _default: import("react-native/Libraries/Utilities/codegenNativeComponent").NativeComponentType<NativeProps>;
|
|
8
9
|
export default _default;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["codegenNativeComponent"],"sources":["SkiaPictureViewNativeComponent.ts"],"sourcesContent":["import codegenNativeComponent from \"react-native/Libraries/Utilities/codegenNativeComponent\";\nimport type { ViewProps } from \"react-native\";\n\nexport interface NativeProps extends ViewProps {\n debug?: boolean;\n opaque?: boolean;\n colorSpace?: string;\n}\n\n// eslint-disable-next-line import/no-default-export\nexport default codegenNativeComponent<NativeProps>(\"SkiaPictureView\");\n"],"mappings":"AAAA,OAAOA,sBAAsB,MAAM,yDAAyD;
|
|
1
|
+
{"version":3,"names":["codegenNativeComponent"],"sources":["SkiaPictureViewNativeComponent.ts"],"sourcesContent":["import codegenNativeComponent from \"react-native/Libraries/Utilities/codegenNativeComponent\";\nimport type { ViewProps } from \"react-native\";\n\nexport interface NativeProps extends ViewProps {\n debug?: boolean;\n opaque?: boolean;\n colorSpace?: string;\n coldStart?: boolean;\n}\n\n// eslint-disable-next-line import/no-default-export\nexport default codegenNativeComponent<NativeProps>(\"SkiaPictureView\");\n"],"mappings":"AAAA,OAAOA,sBAAsB,MAAM,yDAAyD;AAU5F;AACA,eAAeA,sBAAsB,CAAc,iBAAiB,CAAC","ignoreList":[]}
|
|
@@ -3,6 +3,7 @@ import type { SkRect } from "../skia/types";
|
|
|
3
3
|
import type { SkiaPictureViewNativeProps } from "./types";
|
|
4
4
|
interface SkiaPictureViewProps extends SkiaPictureViewNativeProps {
|
|
5
5
|
mode?: "default" | "continuous";
|
|
6
|
+
coldStart?: boolean;
|
|
6
7
|
}
|
|
7
8
|
export declare class SkiaPictureView extends React.Component<SkiaPictureViewProps> {
|
|
8
9
|
private requestId;
|
|
@@ -79,13 +79,15 @@ export class SkiaPictureView extends React.Component {
|
|
|
79
79
|
mode,
|
|
80
80
|
debug = false,
|
|
81
81
|
opaque = false,
|
|
82
|
+
coldStart = false,
|
|
82
83
|
...viewProps
|
|
83
84
|
} = this.props;
|
|
84
85
|
return /*#__PURE__*/React.createElement(NativeSkiaPictureView, _extends({
|
|
85
86
|
collapsable: false,
|
|
86
87
|
nativeID: `${this._nativeId}`,
|
|
87
88
|
debug: debug,
|
|
88
|
-
opaque: opaque
|
|
89
|
+
opaque: opaque,
|
|
90
|
+
coldStart: coldStart
|
|
89
91
|
}, viewProps));
|
|
90
92
|
}
|
|
91
93
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["React","SkiaPictureViewNativeComponent","SkiaViewApi","SkiaViewNativeId","NativeSkiaPictureView","SkiaPictureView","Component","constructor","props","_defineProperty","_nativeId","current","picture","onSize","assertSkiaViewApi","setJsiProperty","tick","nativeId","componentDidUpdate","prevProps","componentWillUnmount","requestId","cancelAnimationFrame","redraw","mode","requestAnimationFrame","bind","makeImageSnapshot","rect","requestRedraw","render","debug","opaque","viewProps","createElement","_extends","collapsable","nativeID","Error"],"sources":["SkiaPictureView.tsx"],"sourcesContent":["import React from \"react\";\n\nimport type { SkRect } from \"../skia/types\";\nimport SkiaPictureViewNativeComponent from \"../specs/SkiaPictureViewNativeComponent\";\n\nimport { SkiaViewApi } from \"./api\";\nimport type { SkiaPictureViewNativeProps } from \"./types\";\nimport { SkiaViewNativeId } from \"./SkiaViewNativeId\";\n\nconst NativeSkiaPictureView = SkiaPictureViewNativeComponent;\n\ninterface SkiaPictureViewProps extends SkiaPictureViewNativeProps {\n mode?: \"default\" | \"continuous\";\n}\n\nexport class SkiaPictureView extends React.Component<SkiaPictureViewProps> {\n private requestId = 0;\n\n constructor(props: SkiaPictureViewProps) {\n super(props);\n this._nativeId = SkiaViewNativeId.current++;\n const { picture, onSize } = props;\n if (picture) {\n assertSkiaViewApi();\n SkiaViewApi.setJsiProperty(this._nativeId, \"picture\", picture);\n }\n if (onSize) {\n assertSkiaViewApi();\n SkiaViewApi.setJsiProperty(this._nativeId, \"onSize\", onSize);\n }\n this.tick();\n }\n\n private _nativeId: number;\n\n public get nativeId() {\n return this._nativeId;\n }\n\n componentDidUpdate(prevProps: SkiaPictureViewProps) {\n const { picture, onSize } = this.props;\n if (picture !== prevProps.picture) {\n assertSkiaViewApi();\n SkiaViewApi.setJsiProperty(this._nativeId, \"picture\", picture);\n }\n if (onSize !== prevProps.onSize) {\n assertSkiaViewApi();\n SkiaViewApi.setJsiProperty(this._nativeId, \"onSize\", onSize);\n }\n this.tick();\n }\n\n componentWillUnmount() {\n if (this.requestId) {\n cancelAnimationFrame(this.requestId);\n }\n }\n\n private tick() {\n this.redraw();\n if (this.props.mode === \"continuous\") {\n this.requestId = requestAnimationFrame(this.tick.bind(this));\n }\n }\n\n /**\n * Creates a snapshot from the canvas in the surface\n * @param rect Rect to use as bounds. Optional.\n * @returns An Image object.\n */\n public makeImageSnapshot(rect?: SkRect) {\n assertSkiaViewApi();\n return SkiaViewApi.makeImageSnapshot(this._nativeId, rect);\n }\n\n /**\n * Sends a redraw request to the native SkiaView.\n */\n public redraw() {\n assertSkiaViewApi();\n SkiaViewApi.requestRedraw(this._nativeId);\n }\n\n render() {\n const { mode, debug = false, opaque = false, ...viewProps } = this.props;\n return (\n <NativeSkiaPictureView\n collapsable={false}\n nativeID={`${this._nativeId}`}\n debug={debug}\n opaque={opaque}\n {...viewProps}\n />\n );\n }\n}\n\nconst assertSkiaViewApi = () => {\n if (\n SkiaViewApi === null ||\n SkiaViewApi.setJsiProperty === null ||\n SkiaViewApi.requestRedraw === null ||\n SkiaViewApi.makeImageSnapshot === null\n ) {\n throw Error(\"Skia View Api was not found.\");\n }\n};\n"],"mappings":";;;;AAAA,OAAOA,KAAK,MAAM,OAAO;AAGzB,OAAOC,8BAA8B,MAAM,yCAAyC;AAEpF,SAASC,WAAW,QAAQ,OAAO;AAEnC,SAASC,gBAAgB,QAAQ,oBAAoB;AAErD,MAAMC,qBAAqB,GAAGH,8BAA8B;
|
|
1
|
+
{"version":3,"names":["React","SkiaPictureViewNativeComponent","SkiaViewApi","SkiaViewNativeId","NativeSkiaPictureView","SkiaPictureView","Component","constructor","props","_defineProperty","_nativeId","current","picture","onSize","assertSkiaViewApi","setJsiProperty","tick","nativeId","componentDidUpdate","prevProps","componentWillUnmount","requestId","cancelAnimationFrame","redraw","mode","requestAnimationFrame","bind","makeImageSnapshot","rect","requestRedraw","render","debug","opaque","coldStart","viewProps","createElement","_extends","collapsable","nativeID","Error"],"sources":["SkiaPictureView.tsx"],"sourcesContent":["import React from \"react\";\n\nimport type { SkRect } from \"../skia/types\";\nimport SkiaPictureViewNativeComponent from \"../specs/SkiaPictureViewNativeComponent\";\n\nimport { SkiaViewApi } from \"./api\";\nimport type { SkiaPictureViewNativeProps } from \"./types\";\nimport { SkiaViewNativeId } from \"./SkiaViewNativeId\";\n\nconst NativeSkiaPictureView = SkiaPictureViewNativeComponent;\n\ninterface SkiaPictureViewProps extends SkiaPictureViewNativeProps {\n mode?: \"default\" | \"continuous\";\n coldStart?: boolean;\n}\n\nexport class SkiaPictureView extends React.Component<SkiaPictureViewProps> {\n private requestId = 0;\n\n constructor(props: SkiaPictureViewProps) {\n super(props);\n this._nativeId = SkiaViewNativeId.current++;\n const { picture, onSize } = props;\n if (picture) {\n assertSkiaViewApi();\n SkiaViewApi.setJsiProperty(this._nativeId, \"picture\", picture);\n }\n if (onSize) {\n assertSkiaViewApi();\n SkiaViewApi.setJsiProperty(this._nativeId, \"onSize\", onSize);\n }\n this.tick();\n }\n\n private _nativeId: number;\n\n public get nativeId() {\n return this._nativeId;\n }\n\n componentDidUpdate(prevProps: SkiaPictureViewProps) {\n const { picture, onSize } = this.props;\n if (picture !== prevProps.picture) {\n assertSkiaViewApi();\n SkiaViewApi.setJsiProperty(this._nativeId, \"picture\", picture);\n }\n if (onSize !== prevProps.onSize) {\n assertSkiaViewApi();\n SkiaViewApi.setJsiProperty(this._nativeId, \"onSize\", onSize);\n }\n this.tick();\n }\n\n componentWillUnmount() {\n if (this.requestId) {\n cancelAnimationFrame(this.requestId);\n }\n }\n\n private tick() {\n this.redraw();\n if (this.props.mode === \"continuous\") {\n this.requestId = requestAnimationFrame(this.tick.bind(this));\n }\n }\n\n /**\n * Creates a snapshot from the canvas in the surface\n * @param rect Rect to use as bounds. Optional.\n * @returns An Image object.\n */\n public makeImageSnapshot(rect?: SkRect) {\n assertSkiaViewApi();\n return SkiaViewApi.makeImageSnapshot(this._nativeId, rect);\n }\n\n /**\n * Sends a redraw request to the native SkiaView.\n */\n public redraw() {\n assertSkiaViewApi();\n SkiaViewApi.requestRedraw(this._nativeId);\n }\n\n render() {\n const { mode, debug = false, opaque = false, coldStart = false, ...viewProps } = this.props;\n return (\n <NativeSkiaPictureView\n collapsable={false}\n nativeID={`${this._nativeId}`}\n debug={debug}\n opaque={opaque}\n coldStart={coldStart}\n {...viewProps}\n />\n );\n }\n}\n\nconst assertSkiaViewApi = () => {\n if (\n SkiaViewApi === null ||\n SkiaViewApi.setJsiProperty === null ||\n SkiaViewApi.requestRedraw === null ||\n SkiaViewApi.makeImageSnapshot === null\n ) {\n throw Error(\"Skia View Api was not found.\");\n }\n};\n"],"mappings":";;;;AAAA,OAAOA,KAAK,MAA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,KAAK,IAAI,IACpBA,WAAW,CAACa,cAAc,KAAK,IAAI,IACnCb,WAAW,CAAC2B,aAAa,KAAK,IAAI,IAClC3B,WAAW,CAACyB,iBAAiB,KAAK,IAAI,EACtC;IACA,MAAMY,KAAK,CAAC,8BAA8B,CAAC;EAC7C;AACF,CAAC","ignoreList":[]}
|
|
@@ -7,6 +7,17 @@ import React, { useRef, useEffect, useCallback, useImperativeHandle, forwardRef
|
|
|
7
7
|
import { JsiSkSurface } from "../skia/web/JsiSkSurface";
|
|
8
8
|
import { Platform } from "../Platform";
|
|
9
9
|
import { SkiaViewNativeId } from "./SkiaViewNativeId";
|
|
10
|
+
const dp2Pixel = (pd, rect) => {
|
|
11
|
+
if (!rect) {
|
|
12
|
+
return undefined;
|
|
13
|
+
}
|
|
14
|
+
return {
|
|
15
|
+
x: rect.x * pd,
|
|
16
|
+
y: rect.y * pd,
|
|
17
|
+
width: rect.width * pd,
|
|
18
|
+
height: rect.height * pd
|
|
19
|
+
};
|
|
20
|
+
};
|
|
10
21
|
class WebGLRenderer {
|
|
11
22
|
constructor(canvas, pd) {
|
|
12
23
|
this.canvas = canvas;
|
|
@@ -22,7 +33,7 @@ class WebGLRenderer {
|
|
|
22
33
|
canvas.clear(CanvasKit.TRANSPARENT);
|
|
23
34
|
this.draw(picture);
|
|
24
35
|
this.surface.ref.flush();
|
|
25
|
-
return this.surface.makeImageSnapshot(rect);
|
|
36
|
+
return this.surface.makeImageSnapshot(dp2Pixel(this.pd, rect));
|
|
26
37
|
}
|
|
27
38
|
onResize() {
|
|
28
39
|
const {
|
|
@@ -143,7 +154,7 @@ class StaticWebGLRenderer {
|
|
|
143
154
|
tempCanvas
|
|
144
155
|
} = renderResult;
|
|
145
156
|
try {
|
|
146
|
-
this.cachedImage = surface.makeImageSnapshot(rect);
|
|
157
|
+
this.cachedImage = surface.makeImageSnapshot(dp2Pixel(this.pd, rect));
|
|
147
158
|
} catch (error) {
|
|
148
159
|
console.error("Error creating image snapshot:", error);
|
|
149
160
|
} finally {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["React","useRef","useEffect","useCallback","useImperativeHandle","forwardRef","JsiSkSurface","Platform","SkiaViewNativeId","WebGLRenderer","constructor","canvas","pd","_defineProperty","onResize","makeImageSnapshot","picture","rect","surface","getCanvas","clear","CanvasKit","TRANSPARENT","draw","ref","flush","width","clientWidth","height","clientHeight","MakeWebGLCanvasSurface","ctx","getContext","drawingBufferColorSpace","Error","Float32Array","of","save","scale","drawPicture","restore","dispose","_this$canvas","getExtension","loseContext","delete","StaticWebGLRenderer","cachedImage","renderPictureToSurface","tempCanvas","OffscreenCanvas","webglSurface","skiaCanvas","error","cleanupWebGLContext","renderResult","ctx2d","drawImage","console","_this$cachedImage","PixelRatio","SkiaPictureView","props","canvasRef","renderer","redrawRequestsRef","requestIdRef","pictureRef","onLayout","redraw","current","getSize","_canvasRef$current","_canvasRef$current2","setPicture","newPicture","tick","requestAnimationFrame","onLayoutEvent","evt","__destroyWebGLContextAfterRender","_props$nativeID","nativeID","global","SkiaViewApi","registerView","cancelAnimationFrame","debug","viewProps","createElement","View","_extends","style","display","flex"],"sources":["SkiaPictureView.web.tsx"],"sourcesContent":["/* global HTMLCanvasElement */\nimport React, {\n useRef,\n useEffect,\n useCallback,\n useImperativeHandle,\n forwardRef,\n} from \"react\";\nimport type { LayoutChangeEvent } from \"react-native\";\n\nimport type { SkRect, SkPicture, SkImage } from \"../skia/types\";\nimport { JsiSkSurface } from \"../skia/web/JsiSkSurface\";\nimport { Platform } from \"../Platform\";\nimport type { ISkiaViewApiWeb } from \"../specs/NativeSkiaModule.web\";\n\nimport type { SkiaPictureViewNativeProps } from \"./types\";\nimport { SkiaViewNativeId } from \"./SkiaViewNativeId\";\n\ninterface Renderer {\n onResize(): void;\n draw(picture: SkPicture): void;\n makeImageSnapshot(picture: SkPicture, rect?: SkRect): SkImage | null;\n dispose(): void;\n}\n\nclass WebGLRenderer implements Renderer {\n private surface: JsiSkSurface | null = null;\n\n constructor(\n private canvas: HTMLCanvasElement,\n private pd: number\n ) {\n this.onResize();\n }\n\n makeImageSnapshot(picture: SkPicture, rect?: SkRect): SkImage | null {\n if (!this.surface) {\n return null;\n }\n const canvas = this.surface.getCanvas();\n canvas!.clear(CanvasKit.TRANSPARENT);\n this.draw(picture);\n this.surface.ref.flush();\n return this.surface.makeImageSnapshot(rect);\n }\n\n onResize() {\n const { canvas, pd } = this;\n canvas.width = canvas.clientWidth * pd;\n canvas.height = canvas.clientHeight * pd;\n const surface = CanvasKit.MakeWebGLCanvasSurface(canvas);\n const ctx = canvas.getContext(\"webgl2\");\n if (ctx) {\n ctx.drawingBufferColorSpace = \"display-p3\";\n }\n if (!surface) {\n throw new Error(\"Could not create surface\");\n }\n this.surface = new JsiSkSurface(CanvasKit, surface);\n }\n\n draw(picture: SkPicture) {\n if (this.surface) {\n const canvas = this.surface.getCanvas();\n canvas.clear(Float32Array.of(0, 0, 0, 0));\n canvas.save();\n canvas.scale(pd, pd);\n canvas.drawPicture(picture);\n canvas.restore();\n this.surface.ref.flush();\n }\n }\n\n dispose(): void {\n if (this.surface) {\n this.canvas\n ?.getContext(\"webgl2\")\n ?.getExtension(\"WEBGL_lose_context\")\n ?.loseContext();\n this.surface.ref.delete();\n this.surface = null;\n }\n }\n}\n\nclass StaticWebGLRenderer implements Renderer {\n private cachedImage: SkImage | null = null;\n\n constructor(\n private canvas: HTMLCanvasElement,\n private pd: number\n ) {}\n\n onResize(): void {\n this.cachedImage = null;\n }\n\n private renderPictureToSurface(\n picture: SkPicture\n ): { surface: JsiSkSurface; tempCanvas: OffscreenCanvas } | null {\n const tempCanvas = new OffscreenCanvas(\n this.canvas.clientWidth * this.pd,\n this.canvas.clientHeight * this.pd\n );\n\n let surface: JsiSkSurface | null = null;\n\n try {\n const webglSurface = CanvasKit.MakeWebGLCanvasSurface(tempCanvas);\n const ctx = tempCanvas.getContext(\"webgl2\");\n if (ctx) {\n ctx.drawingBufferColorSpace = \"display-p3\";\n }\n\n if (!webglSurface) {\n throw new Error(\"Could not create WebGL surface\");\n }\n\n surface = new JsiSkSurface(CanvasKit, webglSurface);\n\n const skiaCanvas = surface.getCanvas();\n skiaCanvas.clear(Float32Array.of(0, 0, 0, 0));\n skiaCanvas.save();\n skiaCanvas.scale(this.pd, this.pd);\n skiaCanvas.drawPicture(picture);\n skiaCanvas.restore();\n surface.ref.flush();\n\n return { surface, tempCanvas };\n } catch (error) {\n if (surface) {\n surface.ref.delete();\n }\n this.cleanupWebGLContext(tempCanvas);\n return null;\n }\n }\n\n private cleanupWebGLContext(tempCanvas: OffscreenCanvas): void {\n const ctx = tempCanvas.getContext(\"webgl2\");\n if (ctx) {\n const loseContext = ctx.getExtension(\"WEBGL_lose_context\");\n if (loseContext) {\n loseContext.loseContext();\n }\n }\n }\n\n draw(picture: SkPicture): void {\n const renderResult = this.renderPictureToSurface(picture);\n if (!renderResult) {\n return;\n }\n const { tempCanvas } = renderResult;\n const ctx2d = this.canvas.getContext(\"2d\");\n if (!ctx2d) {\n throw new Error(\"Could not get 2D context\");\n }\n\n // Set canvas dimensions to match pixel density\n this.canvas.width = this.canvas.clientWidth * this.pd;\n this.canvas.height = this.canvas.clientHeight * this.pd;\n\n // Draw the tempCanvas scaled down to the display size\n ctx2d.drawImage(\n tempCanvas,\n 0,\n 0,\n tempCanvas.width,\n tempCanvas.height,\n 0,\n 0,\n this.canvas.clientWidth * this.pd,\n this.canvas.clientHeight * this.pd\n );\n\n this.cleanupWebGLContext(tempCanvas);\n }\n\n makeImageSnapshot(picture: SkPicture, rect?: SkRect): SkImage | null {\n if (!this.cachedImage) {\n const renderResult = this.renderPictureToSurface(picture);\n if (!renderResult) {\n return null;\n }\n\n const { surface, tempCanvas } = renderResult;\n\n try {\n this.cachedImage = surface.makeImageSnapshot(rect);\n } catch (error) {\n console.error(\"Error creating image snapshot:\", error);\n } finally {\n surface.ref.delete();\n this.cleanupWebGLContext(tempCanvas);\n }\n }\n\n return this.cachedImage;\n }\n\n dispose(): void {\n this.cachedImage?.dispose();\n this.cachedImage = null;\n }\n}\n\nconst pd = Platform.PixelRatio;\n\nexport interface SkiaPictureViewHandle {\n setPicture(picture: SkPicture): void;\n getSize(): { width: number; height: number };\n redraw(): void;\n makeImageSnapshot(rect?: SkRect): SkImage | null;\n}\n\nexport const SkiaPictureView = forwardRef<\n SkiaPictureViewHandle,\n SkiaPictureViewNativeProps\n>((props, ref) => {\n const canvasRef = useRef<HTMLCanvasElement | null>(null);\n const renderer = useRef<Renderer | null>(null);\n const redrawRequestsRef = useRef(0);\n const requestIdRef = useRef(0);\n const pictureRef = useRef<SkPicture | null>(null);\n\n const { picture, onLayout } = props;\n\n const redraw = useCallback(() => {\n redrawRequestsRef.current++;\n }, []);\n\n const getSize = useCallback(() => {\n return {\n width: canvasRef.current?.clientWidth || 0,\n height: canvasRef.current?.clientHeight || 0,\n };\n }, []);\n\n const setPicture = useCallback(\n (newPicture: SkPicture) => {\n pictureRef.current = newPicture;\n redraw();\n },\n [redraw]\n );\n\n const makeImageSnapshot = useCallback((rect?: SkRect) => {\n if (renderer.current && pictureRef.current) {\n return renderer.current.makeImageSnapshot(pictureRef.current, rect);\n }\n return null;\n }, []);\n\n const tick = useCallback(() => {\n if (redrawRequestsRef.current > 0) {\n redrawRequestsRef.current = 0;\n if (renderer.current && pictureRef.current) {\n renderer.current.draw(pictureRef.current);\n }\n }\n requestIdRef.current = requestAnimationFrame(tick);\n }, []);\n\n const onLayoutEvent = useCallback(\n (evt: LayoutChangeEvent) => {\n const canvas = canvasRef.current;\n if (canvas) {\n renderer.current =\n props.__destroyWebGLContextAfterRender === true\n ? new StaticWebGLRenderer(canvas, pd)\n : new WebGLRenderer(canvas, pd);\n if (pictureRef.current) {\n renderer.current.draw(pictureRef.current);\n }\n }\n if (onLayout) {\n onLayout(evt);\n }\n },\n [onLayout, props.__destroyWebGLContextAfterRender]\n );\n\n useImperativeHandle(\n ref,\n () => ({\n setPicture,\n getSize,\n redraw,\n makeImageSnapshot,\n }),\n [setPicture, getSize, redraw, makeImageSnapshot]\n );\n\n useEffect(() => {\n const nativeID = props.nativeID ?? `${SkiaViewNativeId.current++}`;\n (global.SkiaViewApi as ISkiaViewApiWeb).registerView(nativeID, {\n setPicture,\n getSize,\n redraw,\n makeImageSnapshot,\n } as SkiaPictureViewHandle);\n }, [setPicture, getSize, redraw, makeImageSnapshot, props.nativeID]);\n\n useEffect(() => {\n if (props.picture) {\n setPicture(props.picture);\n }\n }, [setPicture, props.picture]);\n\n useEffect(() => {\n tick();\n return () => {\n cancelAnimationFrame(requestIdRef.current);\n if (renderer.current) {\n renderer.current.dispose();\n renderer.current = null;\n }\n };\n }, [tick]);\n\n useEffect(() => {\n if (renderer.current && pictureRef.current) {\n renderer.current.draw(pictureRef.current);\n }\n }, [picture, redraw]);\n\n const { debug = false, ...viewProps } = props;\n return (\n <Platform.View {...viewProps} onLayout={onLayoutEvent}>\n <canvas ref={canvasRef} style={{ display: \"flex\", flex: 1 }} />\n </Platform.View>\n );\n});\n"],"mappings":";;;;AAAA;AACA,OAAOA,KAAK,IACVC,MAAM,EACNC,SAAS,EACTC,WAAW,EACXC,mBAAmB,EACnBC,UAAU,QACL,OAAO;AAId,SAASC,YAAY,QAAQ,0BAA0B;AACvD,SAASC,QAAQ,QAAQ,aAAa;AAItC,SAASC,gBAAgB,QAAQ,oBAAoB;AASrD,MAAMC,aAAa,CAAqB;EAGtCC,WAAWA,CACDC,MAAyB,EACzBC,EAAU,EAClB;IAAA,KAFQD,MAAyB,GAAzBA,MAAyB;IAAA,KACzBC,EAAU,GAAVA,EAAU;IAAAC,eAAA,kBAJmB,IAAI;IAMzC,IAAI,CAACC,QAAQ,CAAC,CAAC;EACjB;EAEAC,iBAAiBA,CAACC,OAAkB,EAAEC,IAAa,EAAkB;IACnE,IAAI,CAAC,IAAI,CAACC,OAAO,EAAE;MACjB,OAAO,IAAI;IACb;IACA,MAAMP,MAAM,GAAG,IAAI,CAACO,OAAO,CAACC,SAAS,CAA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MACzB;IACF,CAAC;EACH,CAAC,EAAE,CAACM,IAAI,CAAC,CAAC;EAEV1E,SAAS,CAAC,MAAM;IACd,IAAI8D,QAAQ,CAACM,OAAO,IAAIH,UAAU,CAACG,OAAO,EAAE;MAC1CN,QAAQ,CAACM,OAAO,CAAC/C,IAAI,CAAC4C,UAAU,CAACG,OAAO,CAAC;IAC3C;EACF,CAAC,EAAE,CAACtD,OAAO,EAAEqD,MAAM,CAAC,CAAC;EAErB,MAAM;IAAEkB,KAAK,GAAG,KAAK;IAAE,GAAGC;EAAU,CAAC,GAAG1B,KAAK;EAC7C,oBACE9D,KAAA,CAAAyF,aAAA,CAAClF,QAAQ,CAACmF,IAAI,EAAAC,QAAA,KAAKH,SAAS;IAAEpB,QAAQ,EAAEU;EAAc,iBACpD9E,KAAA,CAAAyF,aAAA;IAAQjE,GAAG,EAAEuC,SAAU;IAAC6B,KAAK,EAAE;MAAEC,OAAO,EAAE,MAAM;MAAEC,IAAI,EAAE;IAAE;EAAE,CAAE,CACjD,CAAC;AAEpB,CAAC,CAAC","ignoreList":[]}
|
|
1
|
+
{"version":3,"names":["React","useRef","useEffect","useCallback","useImperativeHandle","forwardRef","JsiSkSurface","Platform","SkiaViewNativeId","dp2Pixel","pd","rect","undefined","x","y","width","height","WebGLRenderer","constructor","canvas","_defineProperty","onResize","makeImageSnapshot","picture","surface","getCanvas","clear","CanvasKit","TRANSPARENT","draw","ref","flush","clientWidth","clientHeight","MakeWebGLCanvasSurface","ctx","getContext","drawingBufferColorSpace","Error","Float32Array","of","save","scale","drawPicture","restore","dispose","_this$canvas","getExtension","loseContext","delete","StaticWebGLRenderer","cachedImage","renderPictureToSurface","tempCanvas","OffscreenCanvas","webglSurface","skiaCanvas","error","cleanupWebGLContext","renderResult","ctx2d","drawImage","console","_this$cachedImage","PixelRatio","SkiaPictureView","props","canvasRef","renderer","redrawRequestsRef","requestIdRef","pictureRef","onLayout","redraw","current","getSize","_canvasRef$current","_canvasRef$current2","setPicture","newPicture","tick","requestAnimationFrame","onLayoutEvent","evt","__destroyWebGLContextAfterRender","_props$nativeID","nativeID","global","SkiaViewApi","registerView","cancelAnimationFrame","debug","viewProps","createElement","View","_extends","style","display","flex"],"sources":["SkiaPictureView.web.tsx"],"sourcesContent":["/* global HTMLCanvasElement */\nimport React, {\n useRef,\n useEffect,\n useCallback,\n useImperativeHandle,\n forwardRef,\n} from \"react\";\nimport type { LayoutChangeEvent } from \"react-native\";\n\nimport type { SkRect, SkPicture, SkImage } from \"../skia/types\";\nimport { JsiSkSurface } from \"../skia/web/JsiSkSurface\";\nimport { Platform } from \"../Platform\";\nimport type { ISkiaViewApiWeb } from \"../specs/NativeSkiaModule.web\";\n\nimport type { SkiaPictureViewNativeProps } from \"./types\";\nimport { SkiaViewNativeId } from \"./SkiaViewNativeId\";\n\nconst dp2Pixel = (pd: number, rect?: SkRect) => {\n if (!rect) {\n return undefined;\n }\n return {\n x: rect.x * pd,\n y: rect.y * pd,\n width: rect.width * pd,\n height: rect.height * pd,\n };\n};\n\ninterface Renderer {\n onResize(): void;\n draw(picture: SkPicture): void;\n makeImageSnapshot(picture: SkPicture, rect?: SkRect): SkImage | null;\n dispose(): void;\n}\n\nclass WebGLRenderer implements Renderer {\n private surface: JsiSkSurface | null = null;\n\n constructor(\n private canvas: HTMLCanvasElement,\n private pd: number\n ) {\n this.onResize();\n }\n\n makeImageSnapshot(picture: SkPicture, rect?: SkRect): SkImage | null {\n if (!this.surface) {\n return null;\n }\n const canvas = this.surface.getCanvas();\n canvas!.clear(CanvasKit.TRANSPARENT);\n this.draw(picture);\n this.surface.ref.flush();\n return this.surface.makeImageSnapshot(dp2Pixel(this.pd, rect));\n }\n\n onResize() {\n const { canvas, pd } = this;\n canvas.width = canvas.clientWidth * pd;\n canvas.height = canvas.clientHeight * pd;\n const surface = CanvasKit.MakeWebGLCanvasSurface(canvas);\n const ctx = canvas.getContext(\"webgl2\");\n if (ctx) {\n ctx.drawingBufferColorSpace = \"display-p3\";\n }\n if (!surface) {\n throw new Error(\"Could not create surface\");\n }\n this.surface = new JsiSkSurface(CanvasKit, surface);\n }\n\n draw(picture: SkPicture) {\n if (this.surface) {\n const canvas = this.surface.getCanvas();\n canvas.clear(Float32Array.of(0, 0, 0, 0));\n canvas.save();\n canvas.scale(pd, pd);\n canvas.drawPicture(picture);\n canvas.restore();\n this.surface.ref.flush();\n }\n }\n\n dispose(): void {\n if (this.surface) {\n this.canvas\n ?.getContext(\"webgl2\")\n ?.getExtension(\"WEBGL_lose_context\")\n ?.loseContext();\n this.surface.ref.delete();\n this.surface = null;\n }\n }\n}\n\nclass StaticWebGLRenderer implements Renderer {\n private cachedImage: SkImage | null = null;\n\n constructor(\n private canvas: HTMLCanvasElement,\n private pd: number\n ) {}\n\n onResize(): void {\n this.cachedImage = null;\n }\n\n private renderPictureToSurface(\n picture: SkPicture\n ): { surface: JsiSkSurface; tempCanvas: OffscreenCanvas } | null {\n const tempCanvas = new OffscreenCanvas(\n this.canvas.clientWidth * this.pd,\n this.canvas.clientHeight * this.pd\n );\n\n let surface: JsiSkSurface | null = null;\n\n try {\n const webglSurface = CanvasKit.MakeWebGLCanvasSurface(tempCanvas);\n const ctx = tempCanvas.getContext(\"webgl2\");\n if (ctx) {\n ctx.drawingBufferColorSpace = \"display-p3\";\n }\n\n if (!webglSurface) {\n throw new Error(\"Could not create WebGL surface\");\n }\n\n surface = new JsiSkSurface(CanvasKit, webglSurface);\n\n const skiaCanvas = surface.getCanvas();\n skiaCanvas.clear(Float32Array.of(0, 0, 0, 0));\n skiaCanvas.save();\n skiaCanvas.scale(this.pd, this.pd);\n skiaCanvas.drawPicture(picture);\n skiaCanvas.restore();\n surface.ref.flush();\n\n return { surface, tempCanvas };\n } catch (error) {\n if (surface) {\n surface.ref.delete();\n }\n this.cleanupWebGLContext(tempCanvas);\n return null;\n }\n }\n\n private cleanupWebGLContext(tempCanvas: OffscreenCanvas): void {\n const ctx = tempCanvas.getContext(\"webgl2\");\n if (ctx) {\n const loseContext = ctx.getExtension(\"WEBGL_lose_context\");\n if (loseContext) {\n loseContext.loseContext();\n }\n }\n }\n\n draw(picture: SkPicture): void {\n const renderResult = this.renderPictureToSurface(picture);\n if (!renderResult) {\n return;\n }\n const { tempCanvas } = renderResult;\n const ctx2d = this.canvas.getContext(\"2d\");\n if (!ctx2d) {\n throw new Error(\"Could not get 2D context\");\n }\n\n // Set canvas dimensions to match pixel density\n this.canvas.width = this.canvas.clientWidth * this.pd;\n this.canvas.height = this.canvas.clientHeight * this.pd;\n\n // Draw the tempCanvas scaled down to the display size\n ctx2d.drawImage(\n tempCanvas,\n 0,\n 0,\n tempCanvas.width,\n tempCanvas.height,\n 0,\n 0,\n this.canvas.clientWidth * this.pd,\n this.canvas.clientHeight * this.pd\n );\n\n this.cleanupWebGLContext(tempCanvas);\n }\n\n makeImageSnapshot(picture: SkPicture, rect?: SkRect): SkImage | null {\n if (!this.cachedImage) {\n const renderResult = this.renderPictureToSurface(picture);\n if (!renderResult) {\n return null;\n }\n\n const { surface, tempCanvas } = renderResult;\n\n try {\n this.cachedImage = surface.makeImageSnapshot(dp2Pixel(this.pd, rect));\n } catch (error) {\n console.error(\"Error creating image snapshot:\", error);\n } finally {\n surface.ref.delete();\n this.cleanupWebGLContext(tempCanvas);\n }\n }\n\n return this.cachedImage;\n }\n\n dispose(): void {\n this.cachedImage?.dispose();\n this.cachedImage = null;\n }\n}\n\nconst pd = Platform.PixelRatio;\n\nexport interface SkiaPictureViewHandle {\n setPicture(picture: SkPicture): void;\n getSize(): { width: number; height: number };\n redraw(): void;\n makeImageSnapshot(rect?: SkRect): SkImage | null;\n}\n\nexport const SkiaPictureView = forwardRef<\n SkiaPictureViewHandle,\n SkiaPictureViewNativeProps\n>((props, ref) => {\n const canvasRef = useRef<HTMLCanvasElement | null>(null);\n const renderer = useRef<Renderer | null>(null);\n const redrawRequestsRef = useRef(0);\n const requestIdRef = useRef(0);\n const pictureRef = useRef<SkPicture | null>(null);\n\n const { picture, onLayout } = props;\n\n const redraw = useCallback(() => {\n redrawRequestsRef.current++;\n }, []);\n\n const getSize = useCallback(() => {\n return {\n width: canvasRef.current?.clientWidth || 0,\n height: canvasRef.current?.clientHeight || 0,\n };\n }, []);\n\n const setPicture = useCallback(\n (newPicture: SkPicture) => {\n pictureRef.current = newPicture;\n redraw();\n },\n [redraw]\n );\n\n const makeImageSnapshot = useCallback((rect?: SkRect) => {\n if (renderer.current && pictureRef.current) {\n return renderer.current.makeImageSnapshot(pictureRef.current, rect);\n }\n return null;\n }, []);\n\n const tick = useCallback(() => {\n if (redrawRequestsRef.current > 0) {\n redrawRequestsRef.current = 0;\n if (renderer.current && pictureRef.current) {\n renderer.current.draw(pictureRef.current);\n }\n }\n requestIdRef.current = requestAnimationFrame(tick);\n }, []);\n\n const onLayoutEvent = useCallback(\n (evt: LayoutChangeEvent) => {\n const canvas = canvasRef.current;\n if (canvas) {\n renderer.current =\n props.__destroyWebGLContextAfterRender === true\n ? new StaticWebGLRenderer(canvas, pd)\n : new WebGLRenderer(canvas, pd);\n if (pictureRef.current) {\n renderer.current.draw(pictureRef.current);\n }\n }\n if (onLayout) {\n onLayout(evt);\n }\n },\n [onLayout, props.__destroyWebGLContextAfterRender]\n );\n\n useImperativeHandle(\n ref,\n () => ({\n setPicture,\n getSize,\n redraw,\n makeImageSnapshot,\n }),\n [setPicture, getSize, redraw, makeImageSnapshot]\n );\n\n useEffect(() => {\n const nativeID = props.nativeID ?? `${SkiaViewNativeId.current++}`;\n (global.SkiaViewApi as ISkiaViewApiWeb).registerView(nativeID, {\n setPicture,\n getSize,\n redraw,\n makeImageSnapshot,\n } as SkiaPictureViewHandle);\n }, [setPicture, getSize, redraw, makeImageSnapshot, props.nativeID]);\n\n useEffect(() => {\n if (props.picture) {\n setPicture(props.picture);\n }\n }, [setPicture, props.picture]);\n\n useEffect(() => {\n tick();\n return () => {\n cancelAnimationFrame(requestIdRef.current);\n if (renderer.current) {\n renderer.current.dispose();\n renderer.current = null;\n }\n };\n }, [tick]);\n\n useEffect(() => {\n if (renderer.current && pictureRef.current) {\n renderer.current.draw(pictureRef.current);\n }\n }, [picture, redraw]);\n\n const { debug = false, ...viewProps } = props;\n return (\n <Platform.View {...viewProps} onLayout={onLayoutEvent}>\n <canvas ref={canvasRef} style={{ display: \"flex\", flex: 1 }} />\n </Platform.View>\n );\n});\n"],"mappings":";;;;AAAA;AACA,OAAOA,KAAK,IACVC,MAAM,EACNC,SAAS,EACTC,WAAW,EACXC,mBAAmB,EACnBC,UAAU,QACL,OAAO;AAId,SAASC,YAAY,QAAQ,0BAA0B;AACvD,SAASC,QAAQ,QAAQ,aAAa;AAItC,SAASC,gBAAgB,QAAQ,oBAAoB;AAErD,MAAMC,QAAQ,GAAGA,CAACC,EAAU,EAAEC,IAAa,KAAK;EAC9C,IAAI,CAACA,IAAI,EAAE;IACT,OAAOC,SAAS;EAClB;EACA,OAAO;IACLC,CAAC,EAAEF,IAAI,CAACE,CAAC,GAAGH,EAAE;IACdI,CAAC,EAAEH,IAAI,CAACG,CAAC,GAAGJ,EAAE;IACdK,KAAK,EAAEJ,IAAI,CAACI,KAAK,GAAGL,EAAE;IACtBM,MAAM,EAAEL,IAAI,CAACK,MAAM,GAAGN;EACxB,CAAC;AACH,CAAC;AASD,MAAMO,aAAa,CAAqB;EAGtCC,WAAWA,CACDC,MAAyB,EACzBT,EAAU,EAClB;IAAA,KAFQS,MAAyB,GAAzBA,MAAyB;IAAA,KACzBT,EAAU,GAAVA,EAAU;IAAAU,eAAA,kBAJmB,IAAI;IAMzC,IAAI,CAACC,QAAQ,CAAC,CAAC;EACjB;EAEAC,iBAAiBA,CAACC,OAAkB,EAAEZ,IAAa,EAAkB;IACnE,IAAI,CAAC,IAAI,CAACa,OAAO,EAAE;MACjB,OAAO,IAAI;IACb;IACA,MAAML,MAAM,GAAG,IAAI,CAACK,OAAO,CAACC,SAAS,CAAC,CAAC;IACvCN,MAAM,CAAEO,KAAK,CAACC,SAAS,CAACC,WAAW,CAAC;IACpC,IAA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ACzB;IACF,CAAC;EACH,CAAC,EAAE,CAACM,IAAI,CAAC,CAAC;EAEV9E,SAAS,CAAC,MAAM;IACd,IAAIkE,QAAQ,CAACM,OAAO,IAAIH,UAAU,CAACG,OAAO,EAAE;MAC1CN,QAAQ,CAACM,OAAO,CAAC7C,IAAI,CAAC0C,UAAU,CAACG,OAAO,CAAC;IAC3C;EACF,CAAC,EAAE,CAACnD,OAAO,EAAEkD,MAAM,CAAC,CAAC;EAErB,MAAM;IAAEkB,KAAK,GAAG,KAAK;IAAE,GAAGC;EAAU,CAAC,GAAG1B,KAAK;EAC7C,oBACElE,KAAA,CAAA6F,aAAA,CAACtF,QAAQ,CAACuF,IAAI,EAAAC,QAAA,KAAKH,SAAS;IAAEpB,QAAQ,EAAEU;EAAc,iBACpDlF,KAAA,CAAA6F,aAAA;IAAQ/D,GAAG,EAAEqC,SAAU;IAAC6B,KAAK,EAAE;MAAEC,OAAO,EAAE,MAAM;MAAEC,IAAI,EAAE;IAAE;EAAE,CAAE,CACjD,CAAC;AAEpB,CAAC,CAAC","ignoreList":[]}
|
|
@@ -4,12 +4,8 @@ import _StaticContainer = require("./StaticContainer");
|
|
|
4
4
|
declare class NativeReanimatedContainer extends _StaticContainer.Container {
|
|
5
5
|
constructor(Skia: any, nativeId: any);
|
|
6
6
|
nativeId: any;
|
|
7
|
-
recorderA: _ReanimatedRecorder.ReanimatedRecorder;
|
|
8
|
-
recorderB: _ReanimatedRecorder.ReanimatedRecorder;
|
|
9
|
-
currentRecorder: _ReanimatedRecorder.ReanimatedRecorder;
|
|
10
7
|
picture: any;
|
|
11
8
|
redraw(): void;
|
|
12
9
|
mapperId: any;
|
|
13
10
|
}
|
|
14
|
-
import _ReanimatedRecorder = require("./Recorder/ReanimatedRecorder");
|
|
15
11
|
export {};
|
|
@@ -3,13 +3,9 @@ import { StaticContainer } from "./StaticContainer";
|
|
|
3
3
|
declare class NativeReanimatedContainer extends Container {
|
|
4
4
|
constructor(Skia: any, nativeId: any);
|
|
5
5
|
nativeId: any;
|
|
6
|
-
recorderA: ReanimatedRecorder;
|
|
7
|
-
recorderB: ReanimatedRecorder;
|
|
8
|
-
currentRecorder: ReanimatedRecorder;
|
|
9
6
|
picture: any;
|
|
10
7
|
redraw(): void;
|
|
11
8
|
mapperId: any;
|
|
12
9
|
}
|
|
13
10
|
import { Container } from "./StaticContainer";
|
|
14
|
-
import { ReanimatedRecorder } from "./Recorder/ReanimatedRecorder";
|
|
15
11
|
export {};
|
|
@@ -3,6 +3,7 @@ export interface NativeProps extends ViewProps {
|
|
|
3
3
|
debug?: boolean;
|
|
4
4
|
opaque?: boolean;
|
|
5
5
|
colorSpace?: string;
|
|
6
|
+
coldStart?: boolean;
|
|
6
7
|
}
|
|
7
8
|
declare const _default: import("react-native/Libraries/Utilities/codegenNativeComponent").NativeComponentType<NativeProps>;
|
|
8
9
|
export default _default;
|
|
@@ -3,6 +3,7 @@ import type { SkRect } from "../skia/types";
|
|
|
3
3
|
import type { SkiaPictureViewNativeProps } from "./types";
|
|
4
4
|
interface SkiaPictureViewProps extends SkiaPictureViewNativeProps {
|
|
5
5
|
mode?: "default" | "continuous";
|
|
6
|
+
coldStart?: boolean;
|
|
6
7
|
}
|
|
7
8
|
export declare class SkiaPictureView extends React.Component<SkiaPictureViewProps> {
|
|
8
9
|
private requestId;
|
package/package.json
CHANGED
package/src/renderer/Canvas.tsx
CHANGED
|
@@ -15,7 +15,7 @@ import type {
|
|
|
15
15
|
View,
|
|
16
16
|
ViewProps,
|
|
17
17
|
} from "react-native";
|
|
18
|
-
import type { SharedValue } from "react-native-reanimated";
|
|
18
|
+
import type { AnimatedRef, SharedValue } from "react-native-reanimated";
|
|
19
19
|
|
|
20
20
|
import Rea from "../external/reanimated/ReanimatedProxy";
|
|
21
21
|
import { SkiaViewNativeId } from "../views/SkiaViewNativeId";
|
|
@@ -38,6 +38,11 @@ export interface CanvasRef extends FC<CanvasProps> {
|
|
|
38
38
|
export const useCanvasRef = () => useRef<CanvasRef>(null);
|
|
39
39
|
|
|
40
40
|
const useReanimatedFrame = !HAS_REANIMATED_3 ? () => {} : Rea.useFrameCallback;
|
|
41
|
+
const measure = !HAS_REANIMATED_3 ? null : Rea.measure;
|
|
42
|
+
|
|
43
|
+
const useCanvasRefPriv: typeof useRef<View> = !HAS_REANIMATED_3
|
|
44
|
+
? useRef
|
|
45
|
+
: Rea.useAnimatedRef;
|
|
41
46
|
|
|
42
47
|
export const useCanvasSize = (userRef?: RefObject<CanvasRef | null>) => {
|
|
43
48
|
const ourRef = useCanvasRef();
|
|
@@ -84,7 +89,7 @@ export const Canvas = ({
|
|
|
84
89
|
"<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"
|
|
85
90
|
);
|
|
86
91
|
}
|
|
87
|
-
const viewRef =
|
|
92
|
+
const viewRef = useCanvasRefPriv(null);
|
|
88
93
|
// Native ID
|
|
89
94
|
const nativeId = useMemo(() => {
|
|
90
95
|
return SkiaViewNativeId.current++;
|
|
@@ -95,20 +100,16 @@ export const Canvas = ({
|
|
|
95
100
|
|
|
96
101
|
useReanimatedFrame(() => {
|
|
97
102
|
"worklet";
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
(
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
delete (global as Record<string, unknown>)[`__onSize_${nativeId}`];
|
|
107
|
-
})();
|
|
108
|
-
};
|
|
103
|
+
if (onSize && measure) {
|
|
104
|
+
const result = measure(viewRef as AnimatedRef<View>);
|
|
105
|
+
if (result) {
|
|
106
|
+
const { width, height } = result;
|
|
107
|
+
if (onSize.value.width !== width || onSize.value.height !== height) {
|
|
108
|
+
onSize.value = { width, height };
|
|
109
|
+
}
|
|
110
|
+
}
|
|
109
111
|
}
|
|
110
|
-
|
|
111
|
-
}, [onSize, nativeId]);
|
|
112
|
+
}, !!onSize);
|
|
112
113
|
|
|
113
114
|
// Render effects
|
|
114
115
|
useLayoutEffect(() => {
|
|
@@ -159,7 +160,6 @@ export const Canvas = ({
|
|
|
159
160
|
},
|
|
160
161
|
[onLayout, onSize]
|
|
161
162
|
);
|
|
162
|
-
|
|
163
163
|
return (
|
|
164
164
|
<SkiaPictureViewNativeComponent
|
|
165
165
|
ref={viewRef}
|
|
@@ -168,7 +168,10 @@ export const Canvas = ({
|
|
|
168
168
|
debug={debug}
|
|
169
169
|
opaque={opaque}
|
|
170
170
|
colorSpace={colorSpace}
|
|
171
|
-
|
|
171
|
+
coldStart={false}
|
|
172
|
+
onLayout={
|
|
173
|
+
Platform.OS === "web" && (onSize || onLayout) ? onLayoutWeb : onLayout
|
|
174
|
+
}
|
|
172
175
|
{...viewProps}
|
|
173
176
|
/>
|
|
174
177
|
);
|
|
@@ -27,18 +27,12 @@ const nativeDrawOnscreen = (
|
|
|
27
27
|
class NativeReanimatedContainer extends Container {
|
|
28
28
|
private mapperId: number | null = null;
|
|
29
29
|
private picture: SkPicture;
|
|
30
|
-
private recorderA: ReanimatedRecorder;
|
|
31
|
-
private recorderB: ReanimatedRecorder;
|
|
32
|
-
private currentRecorder: ReanimatedRecorder;
|
|
33
30
|
|
|
34
31
|
constructor(
|
|
35
32
|
Skia: Skia,
|
|
36
33
|
private nativeId: number
|
|
37
34
|
) {
|
|
38
35
|
super(Skia);
|
|
39
|
-
this.recorderA = new ReanimatedRecorder(Skia);
|
|
40
|
-
this.recorderB = new ReanimatedRecorder(Skia);
|
|
41
|
-
this.currentRecorder = this.recorderA;
|
|
42
36
|
this.picture = Skia.Picture.MakePicture(null)!;
|
|
43
37
|
}
|
|
44
38
|
|
|
@@ -49,21 +43,18 @@ class NativeReanimatedContainer extends Container {
|
|
|
49
43
|
if (this.unmounted) {
|
|
50
44
|
return;
|
|
51
45
|
}
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
const recorder = this.currentRecorder;
|
|
55
|
-
this.currentRecorder =
|
|
56
|
-
this.currentRecorder === this.recorderA ? this.recorderB : this.recorderA;
|
|
57
|
-
|
|
58
|
-
const { nativeId, picture } = this;
|
|
59
|
-
recorder.reset();
|
|
46
|
+
const recorder = new ReanimatedRecorder(this.Skia);
|
|
47
|
+
const { nativeId, picture, Skia } = this;
|
|
60
48
|
visit(recorder, this.root);
|
|
61
49
|
const sharedValues = recorder.getSharedValues();
|
|
62
50
|
const sharedRecorder = recorder.getRecorder();
|
|
63
|
-
|
|
51
|
+
// Draw first frame
|
|
52
|
+
Rea.executeOnUIRuntimeSync(() => {
|
|
64
53
|
"worklet";
|
|
65
|
-
|
|
54
|
+
const firstPicture = Skia.Picture.MakePicture(null)!;
|
|
55
|
+
nativeDrawOnscreen(nativeId, sharedRecorder, firstPicture);
|
|
66
56
|
})();
|
|
57
|
+
// Animate
|
|
67
58
|
if (sharedValues.length > 0) {
|
|
68
59
|
this.mapperId = Rea.startMapper(() => {
|
|
69
60
|
"worklet";
|
package/src/sksg/Reconciler.ts
CHANGED
|
@@ -27,12 +27,13 @@ export class SkiaSGRoot {
|
|
|
27
27
|
public Skia: Skia,
|
|
28
28
|
nativeId = -1
|
|
29
29
|
) {
|
|
30
|
+
const strictMode = false;
|
|
30
31
|
this.container = createContainer(Skia, nativeId);
|
|
31
32
|
this.root = skiaReconciler.createContainer(
|
|
32
33
|
this.container,
|
|
33
34
|
0,
|
|
34
35
|
null,
|
|
35
|
-
|
|
36
|
+
strictMode,
|
|
36
37
|
null,
|
|
37
38
|
"",
|
|
38
39
|
console.error,
|
|
@@ -48,7 +49,6 @@ export class SkiaSGRoot {
|
|
|
48
49
|
private updateContainer(element: ReactNode) {
|
|
49
50
|
return new Promise((resolve) => {
|
|
50
51
|
skiaReconciler.updateContainer(element, this.root, null, () => {
|
|
51
|
-
debug("updateContainer");
|
|
52
52
|
resolve(true);
|
|
53
53
|
});
|
|
54
54
|
});
|
|
@@ -11,6 +11,7 @@ const NativeSkiaPictureView = SkiaPictureViewNativeComponent;
|
|
|
11
11
|
|
|
12
12
|
interface SkiaPictureViewProps extends SkiaPictureViewNativeProps {
|
|
13
13
|
mode?: "default" | "continuous";
|
|
14
|
+
coldStart?: boolean;
|
|
14
15
|
}
|
|
15
16
|
|
|
16
17
|
export class SkiaPictureView extends React.Component<SkiaPictureViewProps> {
|
|
@@ -82,13 +83,14 @@ export class SkiaPictureView extends React.Component<SkiaPictureViewProps> {
|
|
|
82
83
|
}
|
|
83
84
|
|
|
84
85
|
render() {
|
|
85
|
-
const { mode, debug = false, opaque = false, ...viewProps } = this.props;
|
|
86
|
+
const { mode, debug = false, opaque = false, coldStart = false, ...viewProps } = this.props;
|
|
86
87
|
return (
|
|
87
88
|
<NativeSkiaPictureView
|
|
88
89
|
collapsable={false}
|
|
89
90
|
nativeID={`${this._nativeId}`}
|
|
90
91
|
debug={debug}
|
|
91
92
|
opaque={opaque}
|
|
93
|
+
coldStart={coldStart}
|
|
92
94
|
{...viewProps}
|
|
93
95
|
/>
|
|
94
96
|
);
|
|
@@ -16,6 +16,18 @@ import type { ISkiaViewApiWeb } from "../specs/NativeSkiaModule.web";
|
|
|
16
16
|
import type { SkiaPictureViewNativeProps } from "./types";
|
|
17
17
|
import { SkiaViewNativeId } from "./SkiaViewNativeId";
|
|
18
18
|
|
|
19
|
+
const dp2Pixel = (pd: number, rect?: SkRect) => {
|
|
20
|
+
if (!rect) {
|
|
21
|
+
return undefined;
|
|
22
|
+
}
|
|
23
|
+
return {
|
|
24
|
+
x: rect.x * pd,
|
|
25
|
+
y: rect.y * pd,
|
|
26
|
+
width: rect.width * pd,
|
|
27
|
+
height: rect.height * pd,
|
|
28
|
+
};
|
|
29
|
+
};
|
|
30
|
+
|
|
19
31
|
interface Renderer {
|
|
20
32
|
onResize(): void;
|
|
21
33
|
draw(picture: SkPicture): void;
|
|
@@ -41,7 +53,7 @@ class WebGLRenderer implements Renderer {
|
|
|
41
53
|
canvas!.clear(CanvasKit.TRANSPARENT);
|
|
42
54
|
this.draw(picture);
|
|
43
55
|
this.surface.ref.flush();
|
|
44
|
-
return this.surface.makeImageSnapshot(rect);
|
|
56
|
+
return this.surface.makeImageSnapshot(dp2Pixel(this.pd, rect));
|
|
45
57
|
}
|
|
46
58
|
|
|
47
59
|
onResize() {
|
|
@@ -187,7 +199,7 @@ class StaticWebGLRenderer implements Renderer {
|
|
|
187
199
|
const { surface, tempCanvas } = renderResult;
|
|
188
200
|
|
|
189
201
|
try {
|
|
190
|
-
this.cachedImage = surface.makeImageSnapshot(rect);
|
|
202
|
+
this.cachedImage = surface.makeImageSnapshot(dp2Pixel(this.pd, rect));
|
|
191
203
|
} catch (error) {
|
|
192
204
|
console.error("Error creating image snapshot:", error);
|
|
193
205
|
} finally {
|