@shopify/react-native-skia 1.0.6 → 1.2.0
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 +1 -0
- package/android/cpp/rnskia-android/AHardwareBufferUtils.cpp +31 -0
- package/android/cpp/rnskia-android/AHardwareBufferUtils.h +13 -0
- package/android/cpp/rnskia-android/RNSkAndroidPlatformContext.h +75 -0
- package/android/cpp/rnskia-android/SkiaOpenGLSurfaceFactory.cpp +29 -11
- package/android/cpp/rnskia-android/SkiaOpenGLSurfaceFactory.h +1 -2
- package/android/src/main/java/com/shopify/reactnative/skia/ViewScreenshotService.java +3 -2
- package/cpp/api/JsiPlatformBuffer.h +51 -0
- package/cpp/api/JsiSkApi.h +4 -0
- package/cpp/api/JsiSkImage.h +1 -1
- package/cpp/api/JsiSkImageFactory.h +15 -2
- package/cpp/api/JsiSkSurface.h +9 -1
- package/cpp/rnskia/RNSkJsiViewApi.h +48 -0
- package/cpp/rnskia/RNSkPlatformContext.h +13 -0
- package/ios/RNSkia-iOS/RNSkiOSPlatformContext.h +6 -0
- package/ios/RNSkia-iOS/RNSkiOSPlatformContext.mm +115 -0
- package/ios/RNSkia-iOS/SkiaMetalSurfaceFactory.h +4 -0
- package/ios/RNSkia-iOS/SkiaMetalSurfaceFactory.mm +12 -0
- package/lib/commonjs/external/reanimated/textures.js +11 -2
- package/lib/commonjs/external/reanimated/textures.js.map +1 -1
- package/lib/commonjs/external/reanimated/useAnimatedImageValue.d.ts +2 -1
- package/lib/commonjs/external/reanimated/useAnimatedImageValue.js +8 -4
- package/lib/commonjs/external/reanimated/useAnimatedImageValue.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/Offscreen.d.ts +2 -2
- package/lib/commonjs/renderer/Offscreen.js +2 -2
- package/lib/commonjs/renderer/Offscreen.js.map +1 -1
- package/lib/commonjs/skia/types/Image/ImageFactory.d.ts +14 -0
- package/lib/commonjs/skia/types/Image/ImageFactory.js.map +1 -1
- package/lib/commonjs/skia/types/PlatformBuffer/PlatformBufferFactory.d.ts +12 -0
- package/lib/commonjs/skia/types/PlatformBuffer/PlatformBufferFactory.js +6 -0
- package/lib/commonjs/skia/types/PlatformBuffer/PlatformBufferFactory.js.map +1 -0
- package/lib/commonjs/skia/types/PlatformBuffer/index.d.ts +1 -0
- package/lib/commonjs/skia/types/PlatformBuffer/index.js +17 -0
- package/lib/commonjs/skia/types/PlatformBuffer/index.js.map +1 -0
- package/lib/commonjs/skia/types/Skia.d.ts +2 -0
- package/lib/commonjs/skia/types/Skia.js.map +1 -1
- package/lib/commonjs/skia/types/Surface/Surface.d.ts +8 -0
- package/lib/commonjs/skia/types/Surface/Surface.js.map +1 -1
- package/lib/commonjs/skia/types/index.d.ts +1 -0
- package/lib/commonjs/skia/types/index.js +11 -0
- package/lib/commonjs/skia/types/index.js.map +1 -1
- package/lib/commonjs/skia/web/JsiSkImage.d.ts +1 -2
- package/lib/commonjs/skia/web/JsiSkImage.js +5 -12
- package/lib/commonjs/skia/web/JsiSkImage.js.map +1 -1
- package/lib/commonjs/skia/web/JsiSkImageFactory.d.ts +2 -2
- package/lib/commonjs/skia/web/JsiSkImageFactory.js +3 -0
- package/lib/commonjs/skia/web/JsiSkImageFactory.js.map +1 -1
- package/lib/commonjs/skia/web/JsiSkPlatformBufferFactory.d.ts +8 -0
- package/lib/commonjs/skia/web/JsiSkPlatformBufferFactory.js +20 -0
- package/lib/commonjs/skia/web/JsiSkPlatformBufferFactory.js.map +1 -0
- package/lib/commonjs/skia/web/JsiSkSurface.d.ts +3 -2
- package/lib/commonjs/skia/web/JsiSkSurface.js +8 -6
- package/lib/commonjs/skia/web/JsiSkSurface.js.map +1 -1
- package/lib/commonjs/skia/web/JsiSkSurfaceFactory.d.ts +1 -1
- package/lib/commonjs/skia/web/JsiSkSurfaceFactory.js +2 -17
- package/lib/commonjs/skia/web/JsiSkSurfaceFactory.js.map +1 -1
- package/lib/commonjs/skia/web/JsiSkia.js +3 -1
- package/lib/commonjs/skia/web/JsiSkia.js.map +1 -1
- package/lib/commonjs/views/SkiaDomView.d.ts +6 -0
- package/lib/commonjs/views/SkiaDomView.js +10 -0
- package/lib/commonjs/views/SkiaDomView.js.map +1 -1
- package/lib/commonjs/views/types.d.ts +1 -0
- package/lib/commonjs/views/types.js.map +1 -1
- package/lib/module/external/reanimated/textures.js +11 -2
- package/lib/module/external/reanimated/textures.js.map +1 -1
- package/lib/module/external/reanimated/useAnimatedImageValue.d.ts +2 -1
- package/lib/module/external/reanimated/useAnimatedImageValue.js +8 -4
- package/lib/module/external/reanimated/useAnimatedImageValue.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/Offscreen.d.ts +2 -2
- package/lib/module/renderer/Offscreen.js +2 -2
- package/lib/module/renderer/Offscreen.js.map +1 -1
- package/lib/module/skia/types/Image/ImageFactory.d.ts +14 -0
- package/lib/module/skia/types/Image/ImageFactory.js.map +1 -1
- package/lib/module/skia/types/PlatformBuffer/PlatformBufferFactory.d.ts +12 -0
- package/lib/module/skia/types/PlatformBuffer/PlatformBufferFactory.js +2 -0
- package/lib/module/skia/types/PlatformBuffer/PlatformBufferFactory.js.map +1 -0
- package/lib/module/skia/types/PlatformBuffer/index.d.ts +1 -0
- package/lib/module/skia/types/PlatformBuffer/index.js +2 -0
- package/lib/module/skia/types/PlatformBuffer/index.js.map +1 -0
- package/lib/module/skia/types/Skia.d.ts +2 -0
- package/lib/module/skia/types/Skia.js.map +1 -1
- package/lib/module/skia/types/Surface/Surface.d.ts +8 -0
- package/lib/module/skia/types/Surface/Surface.js.map +1 -1
- package/lib/module/skia/types/index.d.ts +1 -0
- package/lib/module/skia/types/index.js +1 -0
- package/lib/module/skia/types/index.js.map +1 -1
- package/lib/module/skia/web/JsiSkImage.d.ts +1 -2
- package/lib/module/skia/web/JsiSkImage.js +5 -12
- package/lib/module/skia/web/JsiSkImage.js.map +1 -1
- package/lib/module/skia/web/JsiSkImageFactory.d.ts +2 -2
- package/lib/module/skia/web/JsiSkImageFactory.js +3 -0
- package/lib/module/skia/web/JsiSkImageFactory.js.map +1 -1
- package/lib/module/skia/web/JsiSkPlatformBufferFactory.d.ts +8 -0
- package/lib/module/skia/web/JsiSkPlatformBufferFactory.js +13 -0
- package/lib/module/skia/web/JsiSkPlatformBufferFactory.js.map +1 -0
- package/lib/module/skia/web/JsiSkSurface.d.ts +3 -2
- package/lib/module/skia/web/JsiSkSurface.js +8 -6
- package/lib/module/skia/web/JsiSkSurface.js.map +1 -1
- package/lib/module/skia/web/JsiSkSurfaceFactory.d.ts +1 -1
- package/lib/module/skia/web/JsiSkSurfaceFactory.js +2 -17
- package/lib/module/skia/web/JsiSkSurfaceFactory.js.map +1 -1
- package/lib/module/skia/web/JsiSkia.js +3 -1
- package/lib/module/skia/web/JsiSkia.js.map +1 -1
- package/lib/module/views/SkiaDomView.d.ts +6 -0
- package/lib/module/views/SkiaDomView.js +10 -0
- package/lib/module/views/SkiaDomView.js.map +1 -1
- package/lib/module/views/types.d.ts +1 -0
- package/lib/module/views/types.js.map +1 -1
- package/lib/typescript/src/external/reanimated/useAnimatedImageValue.d.ts +2 -1
- package/lib/typescript/src/renderer/Offscreen.d.ts +2 -2
- package/lib/typescript/src/skia/types/Image/ImageFactory.d.ts +14 -0
- package/lib/typescript/src/skia/types/PlatformBuffer/PlatformBufferFactory.d.ts +12 -0
- package/lib/typescript/src/skia/types/PlatformBuffer/index.d.ts +1 -0
- package/lib/typescript/src/skia/types/Skia.d.ts +2 -0
- package/lib/typescript/src/skia/types/Surface/Surface.d.ts +8 -0
- package/lib/typescript/src/skia/types/index.d.ts +1 -0
- package/lib/typescript/src/skia/web/JsiSkImage.d.ts +1 -2
- package/lib/typescript/src/skia/web/JsiSkImageFactory.d.ts +2 -2
- package/lib/typescript/src/skia/web/JsiSkPlatformBufferFactory.d.ts +8 -0
- package/lib/typescript/src/skia/web/JsiSkSurface.d.ts +3 -2
- package/lib/typescript/src/skia/web/JsiSkSurfaceFactory.d.ts +1 -1
- package/lib/typescript/src/views/SkiaDomView.d.ts +6 -0
- package/lib/typescript/src/views/types.d.ts +1 -0
- package/package.json +1 -1
- package/src/external/reanimated/textures.tsx +8 -2
- package/src/external/reanimated/useAnimatedImageValue.ts +12 -6
- package/src/mock/index.ts +1 -0
- package/src/renderer/Offscreen.tsx +3 -3
- package/src/skia/types/Image/ImageFactory.ts +15 -0
- package/src/skia/types/PlatformBuffer/PlatformBufferFactory.ts +14 -0
- package/src/skia/types/PlatformBuffer/index.ts +1 -0
- package/src/skia/types/Skia.ts +2 -1
- package/src/skia/types/Surface/Surface.ts +10 -0
- package/src/skia/types/index.ts +1 -0
- package/src/skia/web/JsiSkImage.ts +5 -22
- package/src/skia/web/JsiSkImageFactory.ts +13 -2
- package/src/skia/web/JsiSkPlatformBufferFactory.ts +22 -0
- package/src/skia/web/JsiSkSurface.ts +10 -9
- package/src/skia/web/JsiSkSurfaceFactory.ts +4 -20
- package/src/skia/web/JsiSkia.ts +2 -0
- package/src/views/SkiaDomView.tsx +10 -0
- package/src/views/types.ts +1 -0
- package/cpp/skia/include/third_party/vulkan/LICENSE +0 -29
- package/cpp/skia/modules/skcms/README.chromium +0 -6
- package/cpp/skia/readme.txt +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["React","Platform","SkiaDomViewNativeComponent","SkiaViewApi","SkiaViewNativeId","NativeSkiaDomView","OS","SkiaDomView","Component","constructor","props","_defineProperty","_nativeId","current","root","onTouch","onSize","assertSkiaViewApi","setJsiProperty","nativeId","componentDidUpdate","prevProps","makeImageSnapshot","rect","redraw","requestRedraw","componentWillUnmount","render","mode","debug","viewProps","createElement","_extends","collapsable","nativeID","callJsiMethod","Error"],"sources":["SkiaDomView.tsx"],"sourcesContent":["import React from \"react\";\nimport type { HostComponent } from \"react-native\";\n\nimport type { SkRect } from \"../skia/types\";\nimport { Platform } from \"../Platform\";\nimport SkiaDomViewNativeComponent from \"../specs/SkiaDomViewNativeComponent\";\n\nimport { SkiaViewApi } from \"./api\";\nimport type { SkiaDomViewProps } from \"./types\";\nimport { SkiaViewNativeId } from \"./SkiaViewNativeId\";\n\nconst NativeSkiaDomView: HostComponent<SkiaDomViewProps> =\n Platform.OS !== \"web\"\n ? SkiaDomViewNativeComponent\n : // eslint-disable-next-line @typescript-eslint/no-explicit-any\n (null as any);\n\nexport class SkiaDomView extends React.Component<SkiaDomViewProps> {\n constructor(props: SkiaDomViewProps) {\n super(props);\n this._nativeId = SkiaViewNativeId.current++;\n const { root, onTouch, onSize } = props;\n if (root) {\n assertSkiaViewApi();\n SkiaViewApi.setJsiProperty(this._nativeId, \"root\", root);\n }\n if (onTouch) {\n assertSkiaViewApi();\n SkiaViewApi.setJsiProperty(this._nativeId, \"onTouch\", onTouch);\n }\n if (onSize) {\n assertSkiaViewApi();\n SkiaViewApi.setJsiProperty(this._nativeId, \"onSize\", onSize);\n }\n }\n\n private _nativeId: number;\n\n public get nativeId() {\n return this._nativeId;\n }\n\n componentDidUpdate(prevProps: SkiaDomViewProps) {\n const { root, onTouch, onSize } = this.props;\n if (root !== prevProps.root) {\n assertSkiaViewApi();\n SkiaViewApi.setJsiProperty(this._nativeId, \"root\", root);\n }\n if (onTouch !== prevProps.onTouch) {\n assertSkiaViewApi();\n SkiaViewApi.setJsiProperty(this._nativeId, \"onTouch\", onTouch);\n }\n if (onSize !== prevProps.onSize) {\n assertSkiaViewApi();\n SkiaViewApi.setJsiProperty(this._nativeId, \"onSize\", onSize);\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 /**\n * Clear up the dom node when unmounting to release resources.\n */\n componentWillUnmount(): void {\n assertSkiaViewApi();\n SkiaViewApi.setJsiProperty(this._nativeId, \"root\", null);\n }\n\n render() {\n const { mode, debug = false, ...viewProps } = this.props;\n return (\n <NativeSkiaDomView\n collapsable={false}\n nativeID={`${this._nativeId}`}\n mode={mode}\n debug={debug}\n {...viewProps}\n />\n );\n }\n}\n\nconst assertSkiaViewApi = () => {\n if (\n SkiaViewApi === null ||\n SkiaViewApi.setJsiProperty === null ||\n SkiaViewApi.callJsiMethod === 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;AAIzB,SAASC,QAAQ,QAAQ,aAAa;AACtC,OAAOC,0BAA0B,MAAM,qCAAqC;AAE5E,SAASC,WAAW,QAAQ,OAAO;AAEnC,SAASC,gBAAgB,QAAQ,oBAAoB;AAErD,MAAMC,iBAAkD,GACtDJ,QAAQ,CAACK,EAAE,KAAK,KAAK,GACjBJ,0BAA0B;AAC1B;AACC,IAAY;AAEnB,OAAO,MAAMK,WAAW,SAASP,KAAK,CAACQ,SAAS,CAAmB;EACjEC,WAAWA,CAACC,KAAuB,EAAE;IACnC,KAAK,CAACA,KAAK,CAAC;IAACC,eAAA;IACb,IAAI,CAACC,SAAS,GAAGR,gBAAgB,CAACS,OAAO,EAAE;IAC3C,MAAM;MAAEC,IAAI;MAAEC,OAAO;MAAEC;IAAO,CAAC,GAAGN,KAAK;IACvC,IAAII,IAAI,EAAE;MACRG,iBAAiB,CAAC,CAAC;MACnBd,WAAW,CAACe,cAAc,CAAC,IAAI,CAACN,SAAS,EAAE,MAAM,EAAEE,IAAI,CAAC;IAC1D;IACA,IAAIC,OAAO,EAAE;MACXE,iBAAiB,CAAC,CAAC;MACnBd,WAAW,CAACe,cAAc,CAAC,IAAI,CAACN,SAAS,EAAE,SAAS,EAAEG,OAAO,CAAC;IAChE;IACA,IAAIC,MAAM,EAAE;MACVC,iBAAiB,CAAC,CAAC;MACnBd,WAAW,CAACe,cAAc,CAAC,IAAI,CAACN,SAAS,EAAE,QAAQ,EAAEI,MAAM,CAAC;IAC9D;EACF;EAIA,IAAWG,QAAQA,CAAA,EAAG;IACpB,OAAO,IAAI,CAACP,SAAS;EACvB;EAEAQ,kBAAkBA,CAACC,SAA2B,EAAE;IAC9C,MAAM;MAAEP,IAAI;MAAEC,OAAO;MAAEC;IAAO,CAAC,GAAG,IAAI,CAACN,KAAK;IAC5C,IAAII,IAAI,KAAKO,SAAS,CAACP,IAAI,EAAE;MAC3BG,iBAAiB,CAAC,CAAC;MACnBd,WAAW,CAACe,cAAc,CAAC,IAAI,CAACN,SAAS,EAAE,MAAM,EAAEE,IAAI,CAAC;IAC1D;IACA,IAAIC,OAAO,KAAKM,SAAS,CAACN,OAAO,EAAE;MACjCE,iBAAiB,CAAC,CAAC;MACnBd,WAAW,CAACe,cAAc,CAAC,IAAI,CAACN,SAAS,EAAE,SAAS,EAAEG,OAAO,CAAC;IAChE;IACA,IAAIC,MAAM,KAAKK,SAAS,CAACL,MAAM,EAAE;MAC/BC,iBAAiB,CAAC,CAAC;MACnBd,WAAW,CAACe,cAAc,CAAC,IAAI,CAACN,SAAS,EAAE,QAAQ,EAAEI,MAAM,CAAC;IAC9D;EACF;;EAEA;AACF;AACA;AACA;AACA;EACSM,iBAAiBA,CAACC,IAAa,EAAE;IACtCN,iBAAiB,CAAC,CAAC;IACnB,OAAOd,WAAW,CAACmB,iBAAiB,CAAC,IAAI,CAACV,SAAS,EAAEW,IAAI,CAAC;EAC5D;;EAEA;AACF;AACA;EACSC,MAAMA,CAAA,EAAG;
|
|
1
|
+
{"version":3,"names":["React","Platform","SkiaDomViewNativeComponent","SkiaViewApi","SkiaViewNativeId","NativeSkiaDomView","OS","SkiaDomView","Component","constructor","props","_defineProperty","_nativeId","current","root","onTouch","onSize","assertSkiaViewApi","setJsiProperty","nativeId","componentDidUpdate","prevProps","makeImageSnapshot","rect","makeImageSnapshotAsync","redraw","requestRedraw","componentWillUnmount","render","mode","debug","viewProps","createElement","_extends","collapsable","nativeID","callJsiMethod","Error"],"sources":["SkiaDomView.tsx"],"sourcesContent":["import React from \"react\";\nimport type { HostComponent } from \"react-native\";\n\nimport type { SkRect } from \"../skia/types\";\nimport { Platform } from \"../Platform\";\nimport SkiaDomViewNativeComponent from \"../specs/SkiaDomViewNativeComponent\";\n\nimport { SkiaViewApi } from \"./api\";\nimport type { SkiaDomViewProps } from \"./types\";\nimport { SkiaViewNativeId } from \"./SkiaViewNativeId\";\n\nconst NativeSkiaDomView: HostComponent<SkiaDomViewProps> =\n Platform.OS !== \"web\"\n ? SkiaDomViewNativeComponent\n : // eslint-disable-next-line @typescript-eslint/no-explicit-any\n (null as any);\n\nexport class SkiaDomView extends React.Component<SkiaDomViewProps> {\n constructor(props: SkiaDomViewProps) {\n super(props);\n this._nativeId = SkiaViewNativeId.current++;\n const { root, onTouch, onSize } = props;\n if (root) {\n assertSkiaViewApi();\n SkiaViewApi.setJsiProperty(this._nativeId, \"root\", root);\n }\n if (onTouch) {\n assertSkiaViewApi();\n SkiaViewApi.setJsiProperty(this._nativeId, \"onTouch\", onTouch);\n }\n if (onSize) {\n assertSkiaViewApi();\n SkiaViewApi.setJsiProperty(this._nativeId, \"onSize\", onSize);\n }\n }\n\n private _nativeId: number;\n\n public get nativeId() {\n return this._nativeId;\n }\n\n componentDidUpdate(prevProps: SkiaDomViewProps) {\n const { root, onTouch, onSize } = this.props;\n if (root !== prevProps.root) {\n assertSkiaViewApi();\n SkiaViewApi.setJsiProperty(this._nativeId, \"root\", root);\n }\n if (onTouch !== prevProps.onTouch) {\n assertSkiaViewApi();\n SkiaViewApi.setJsiProperty(this._nativeId, \"onTouch\", onTouch);\n }\n if (onSize !== prevProps.onSize) {\n assertSkiaViewApi();\n SkiaViewApi.setJsiProperty(this._nativeId, \"onSize\", onSize);\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 * 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 makeImageSnapshotAsync(rect?: SkRect) {\n assertSkiaViewApi();\n return SkiaViewApi.makeImageSnapshotAsync(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 /**\n * Clear up the dom node when unmounting to release resources.\n */\n componentWillUnmount(): void {\n assertSkiaViewApi();\n SkiaViewApi.setJsiProperty(this._nativeId, \"root\", null);\n }\n\n render() {\n const { mode, debug = false, ...viewProps } = this.props;\n return (\n <NativeSkiaDomView\n collapsable={false}\n nativeID={`${this._nativeId}`}\n mode={mode}\n debug={debug}\n {...viewProps}\n />\n );\n }\n}\n\nconst assertSkiaViewApi = () => {\n if (\n SkiaViewApi === null ||\n SkiaViewApi.setJsiProperty === null ||\n SkiaViewApi.callJsiMethod === null ||\n SkiaViewApi.requestRedraw === null ||\n SkiaViewApi.makeImageSnapshot === null\n ) {\n throw Error(\"Skia View Api was not found.\");\n }\n};\n"],"mappings":"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"}
|
|
@@ -49,6 +49,7 @@ export interface ISkiaViewApi {
|
|
|
49
49
|
callJsiMethod: <T extends Array<unknown>>(nativeId: number, name: string, ...args: T) => void;
|
|
50
50
|
requestRedraw: (nativeId: number) => void;
|
|
51
51
|
makeImageSnapshot: (nativeId: number, rect?: SkRect) => SkImage;
|
|
52
|
+
makeImageSnapshotAsync: (nativeId: number, rect?: SkRect) => Promise<SkImage>;
|
|
52
53
|
}
|
|
53
54
|
export interface SkiaBaseViewProps extends ViewProps {
|
|
54
55
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["TouchType"],"sources":["types.ts"],"sourcesContent":["import type { ViewProps } from \"react-native\";\n\nimport type { GroupProps, RenderNode } from \"../dom/types\";\nimport type { SkImage, SkPicture, SkRect, SkSize } from \"../skia/types\";\nimport type { SharedValueType } from \"../renderer/processors/Animations/Animations\";\n\nexport type DrawMode = \"continuous\" | \"default\";\n\nexport type NativeSkiaViewProps = ViewProps & {\n mode?: DrawMode;\n debug?: boolean;\n};\n\nexport enum TouchType {\n Start,\n Active,\n End,\n Cancelled,\n}\n\nexport interface TouchInfo {\n x: number;\n y: number;\n force: number;\n type: TouchType;\n id: number;\n timestamp: number;\n}\n\nexport interface DrawingInfo {\n width: number;\n height: number;\n timestamp: number;\n touches: Array<Array<TouchInfo>>;\n}\n\nexport type ExtendedTouchInfo = TouchInfo & {\n // points per second\n velocityX: number;\n velocityY: number;\n};\n\nexport type TouchHandlers = {\n onStart?: (touchInfo: TouchInfo) => void;\n onActive?: (touchInfo: ExtendedTouchInfo) => void;\n onEnd?: (touchInfo: ExtendedTouchInfo) => void;\n};\n\nexport type TouchHandler = (touchInfo: Array<Array<TouchInfo>>) => void;\n\n/**\n * Listener interface for value changes\n */\nexport interface ValueListener {\n addListener: (callback: () => void) => number;\n removeListener: (id: number) => void;\n}\n\nexport interface ISkiaViewApi {\n setJsiProperty: <T>(nativeId: number, name: string, value: T) => void;\n callJsiMethod: <T extends Array<unknown>>(\n nativeId: number,\n name: string,\n ...args: T\n ) => void;\n requestRedraw: (nativeId: number) => void;\n makeImageSnapshot: (nativeId: number, rect?: SkRect) => SkImage;\n}\n\nexport interface SkiaBaseViewProps extends ViewProps {\n /**\n * Sets the drawing mode for the skia view. There are two drawing\n * modes, \"continuous\" and \"default\", where the continuous mode will\n * continuously redraw the view, and the default mode will only\n * redraw when any of the regular react properties are changed like\n * sizes and margins.\n */\n mode?: DrawMode;\n /**\n * When set to true the view will display information about the\n * average time it takes to render.\n */\n debug?: boolean;\n /**\n * Pass an animated value to the onSize property to get updates when\n * the Skia view is resized.\n */\n onSize?: SharedValueType<SkSize>;\n}\n\nexport interface SkiaPictureViewProps extends SkiaBaseViewProps {\n picture?: SkPicture;\n}\n\nexport interface SkiaDomViewProps extends SkiaBaseViewProps {\n root?: RenderNode<GroupProps>;\n onTouch?: TouchHandler;\n}\n"],"mappings":"AAaA,WAAYA,SAAS,0BAATA,SAAS;EAATA,SAAS,CAATA,SAAS;EAATA,SAAS,CAATA,SAAS;EAATA,SAAS,CAATA,SAAS;EAATA,SAAS,CAATA,SAAS;EAAA,OAATA,SAAS;AAAA;;AAqCrB;AACA;AACA"}
|
|
1
|
+
{"version":3,"names":["TouchType"],"sources":["types.ts"],"sourcesContent":["import type { ViewProps } from \"react-native\";\n\nimport type { GroupProps, RenderNode } from \"../dom/types\";\nimport type { SkImage, SkPicture, SkRect, SkSize } from \"../skia/types\";\nimport type { SharedValueType } from \"../renderer/processors/Animations/Animations\";\n\nexport type DrawMode = \"continuous\" | \"default\";\n\nexport type NativeSkiaViewProps = ViewProps & {\n mode?: DrawMode;\n debug?: boolean;\n};\n\nexport enum TouchType {\n Start,\n Active,\n End,\n Cancelled,\n}\n\nexport interface TouchInfo {\n x: number;\n y: number;\n force: number;\n type: TouchType;\n id: number;\n timestamp: number;\n}\n\nexport interface DrawingInfo {\n width: number;\n height: number;\n timestamp: number;\n touches: Array<Array<TouchInfo>>;\n}\n\nexport type ExtendedTouchInfo = TouchInfo & {\n // points per second\n velocityX: number;\n velocityY: number;\n};\n\nexport type TouchHandlers = {\n onStart?: (touchInfo: TouchInfo) => void;\n onActive?: (touchInfo: ExtendedTouchInfo) => void;\n onEnd?: (touchInfo: ExtendedTouchInfo) => void;\n};\n\nexport type TouchHandler = (touchInfo: Array<Array<TouchInfo>>) => void;\n\n/**\n * Listener interface for value changes\n */\nexport interface ValueListener {\n addListener: (callback: () => void) => number;\n removeListener: (id: number) => void;\n}\n\nexport interface ISkiaViewApi {\n setJsiProperty: <T>(nativeId: number, name: string, value: T) => void;\n callJsiMethod: <T extends Array<unknown>>(\n nativeId: number,\n name: string,\n ...args: T\n ) => void;\n requestRedraw: (nativeId: number) => void;\n makeImageSnapshot: (nativeId: number, rect?: SkRect) => SkImage;\n makeImageSnapshotAsync: (nativeId: number, rect?: SkRect) => Promise<SkImage>;\n}\n\nexport interface SkiaBaseViewProps extends ViewProps {\n /**\n * Sets the drawing mode for the skia view. There are two drawing\n * modes, \"continuous\" and \"default\", where the continuous mode will\n * continuously redraw the view, and the default mode will only\n * redraw when any of the regular react properties are changed like\n * sizes and margins.\n */\n mode?: DrawMode;\n /**\n * When set to true the view will display information about the\n * average time it takes to render.\n */\n debug?: boolean;\n /**\n * Pass an animated value to the onSize property to get updates when\n * the Skia view is resized.\n */\n onSize?: SharedValueType<SkSize>;\n}\n\nexport interface SkiaPictureViewProps extends SkiaBaseViewProps {\n picture?: SkPicture;\n}\n\nexport interface SkiaDomViewProps extends SkiaBaseViewProps {\n root?: RenderNode<GroupProps>;\n onTouch?: TouchHandler;\n}\n"],"mappings":"AAaA,WAAYA,SAAS,0BAATA,SAAS;EAATA,SAAS,CAATA,SAAS;EAATA,SAAS,CAATA,SAAS;EAATA,SAAS,CAATA,SAAS;EAATA,SAAS,CAATA,SAAS;EAAA,OAATA,SAAS;AAAA;;AAqCrB;AACA;AACA"}
|
|
@@ -1,2 +1,3 @@
|
|
|
1
|
+
import { type SharedValue } from "react-native-reanimated";
|
|
1
2
|
import type { DataSourceParam, SkImage } from "../../skia/types";
|
|
2
|
-
export declare const useAnimatedImageValue: (source: DataSourceParam) =>
|
|
3
|
+
export declare const useAnimatedImageValue: (source: DataSourceParam, paused?: SharedValue<boolean>) => SharedValue<SkImage | null>;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { ReactElement } from "react";
|
|
2
|
-
import type { SkPicture, SkSize } from "../skia/types";
|
|
2
|
+
import type { SkPicture, SkRect, SkSize } from "../skia/types";
|
|
3
3
|
export declare const isOnMainThread: () => boolean;
|
|
4
|
-
export declare const drawAsPicture: (element: ReactElement) => SkPicture;
|
|
4
|
+
export declare const drawAsPicture: (element: ReactElement, bounds?: SkRect) => SkPicture;
|
|
5
5
|
export declare const drawAsImage: (element: ReactElement, size: SkSize) => import("../skia").SkImage;
|
|
6
6
|
export declare const drawAsImageFromPicture: (picture: SkPicture, size: SkSize) => import("../skia").SkImage;
|
|
@@ -52,6 +52,20 @@ export interface ImageFactory {
|
|
|
52
52
|
* image, nullptr is returned.
|
|
53
53
|
*/
|
|
54
54
|
MakeImageFromEncoded: (encoded: SkData) => SkImage | null;
|
|
55
|
+
/**
|
|
56
|
+
* Return an Image backed by the given native platform buffer.
|
|
57
|
+
* The platform buffer must be a valid owning reference.
|
|
58
|
+
*
|
|
59
|
+
* This API is used by [react-native-vision-camera](https://github.com/mrousavy/react-native-vision-camera)
|
|
60
|
+
* to render a Skia Camera preview.
|
|
61
|
+
*
|
|
62
|
+
* - On Android; This is an `AHardwareBuffer*`
|
|
63
|
+
* - On iOS, this is a `CMSampleBufferRef`
|
|
64
|
+
* @param platformBuffer A strong `uintptr_t` pointer to the native platform buffer
|
|
65
|
+
* @throws Throws an error if the Image could not be created, for example when the given
|
|
66
|
+
* platform buffer is invalid.
|
|
67
|
+
*/
|
|
68
|
+
MakeImageFromPlatformBuffer: (platformBuffer: bigint) => SkImage;
|
|
55
69
|
/**
|
|
56
70
|
* Returns an image that will be a screenshot of the view represented by
|
|
57
71
|
* the view tag
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { SkImage } from "../Image";
|
|
2
|
+
export type PlatformBuffer = bigint;
|
|
3
|
+
export interface PlatformBufferFactory {
|
|
4
|
+
/**
|
|
5
|
+
* Copy pixels to a platform buffer. (for testing purposes)
|
|
6
|
+
*/
|
|
7
|
+
MakeFromImage: (image: SkImage) => PlatformBuffer;
|
|
8
|
+
/**
|
|
9
|
+
* Release a platform buffer that was created with `MakeFromImage`.
|
|
10
|
+
*/
|
|
11
|
+
Release: (platformBuffer: PlatformBuffer) => void;
|
|
12
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./PlatformBufferFactory";
|
|
@@ -26,6 +26,7 @@ import type { Color, SkColor } from "./Color";
|
|
|
26
26
|
import type { TypefaceFontProviderFactory } from "./Paragraph/TypefaceFontProviderFactory";
|
|
27
27
|
import type { AnimatedImageFactory } from "./AnimatedImage";
|
|
28
28
|
import type { ParagraphBuilderFactory } from "./Paragraph/ParagraphBuilder";
|
|
29
|
+
import type { PlatformBufferFactory } from "./PlatformBuffer";
|
|
29
30
|
/**
|
|
30
31
|
* Declares the interface for the native Skia API
|
|
31
32
|
*/
|
|
@@ -71,4 +72,5 @@ export interface Skia {
|
|
|
71
72
|
TextBlob: TextBlobFactory;
|
|
72
73
|
Surface: SurfaceFactory;
|
|
73
74
|
ParagraphBuilder: ParagraphBuilderFactory;
|
|
75
|
+
PlatformBuffer: PlatformBufferFactory;
|
|
74
76
|
}
|
|
@@ -26,4 +26,12 @@ export interface SkSurface extends SkJSIInstance<"Surface"> {
|
|
|
26
26
|
* Make sure any queued draws are sent to the screen or the GPU.
|
|
27
27
|
*/
|
|
28
28
|
flush(): void;
|
|
29
|
+
/**
|
|
30
|
+
* Returns the possibly scaled width of the surface.
|
|
31
|
+
*/
|
|
32
|
+
width(): number;
|
|
33
|
+
/**
|
|
34
|
+
* Returns the possibly scaled height of the surface.
|
|
35
|
+
*/
|
|
36
|
+
height(): number;
|
|
29
37
|
}
|
|
@@ -3,8 +3,7 @@ import type { FilterMode, MipmapMode, SkImage, SkMatrix, SkShader, TileMode, Ima
|
|
|
3
3
|
import { HostObject } from "./Host";
|
|
4
4
|
export declare const toBase64String: (bytes: Uint8Array) => string;
|
|
5
5
|
export declare class JsiSkImage extends HostObject<Image, "Image"> implements SkImage {
|
|
6
|
-
|
|
7
|
-
constructor(CanvasKit: CanvasKit, ref: Image, releaseCtx?: (() => void) | undefined);
|
|
6
|
+
constructor(CanvasKit: CanvasKit, ref: Image);
|
|
8
7
|
height(): number;
|
|
9
8
|
width(): number;
|
|
10
9
|
getImageInfo(): ImageInfo;
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import type { CanvasKit } from "canvaskit-wasm";
|
|
2
|
-
import type { SkData, ImageInfo, SkImage } from "../types";
|
|
3
|
-
import type { ImageFactory } from "../types/Image/ImageFactory";
|
|
2
|
+
import type { SkData, ImageInfo, SkImage, PlatformBuffer, ImageFactory } from "../types";
|
|
4
3
|
import { Host } from "./Host";
|
|
5
4
|
import { JsiSkImage } from "./JsiSkImage";
|
|
6
5
|
export declare class JsiSkImageFactory extends Host implements ImageFactory {
|
|
7
6
|
constructor(CanvasKit: CanvasKit);
|
|
8
7
|
MakeImageFromViewTag(viewTag: number): Promise<SkImage | null>;
|
|
8
|
+
MakeImageFromPlatformBuffer(_platformBuffer: PlatformBuffer): SkImage;
|
|
9
9
|
MakeImageFromEncoded(encoded: SkData): JsiSkImage | null;
|
|
10
10
|
MakeImage(info: ImageInfo, data: SkData, bytesPerRow: number): JsiSkImage | null;
|
|
11
11
|
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { CanvasKit } from "canvaskit-wasm";
|
|
2
|
+
import type { PlatformBuffer, PlatformBufferFactory, SkImage } from "../types";
|
|
3
|
+
import { Host } from "./Host";
|
|
4
|
+
export declare class JsiSkPlatformBufferFactory extends Host implements PlatformBufferFactory {
|
|
5
|
+
constructor(CanvasKit: CanvasKit);
|
|
6
|
+
MakeFromImage(_image: SkImage): PlatformBuffer;
|
|
7
|
+
Release(_platformBuffer: PlatformBuffer): void;
|
|
8
|
+
}
|
|
@@ -2,10 +2,11 @@ import type { CanvasKit, Surface } from "canvaskit-wasm";
|
|
|
2
2
|
import type { SkCanvas, SkImage, SkRect, SkSurface } from "../types";
|
|
3
3
|
import { HostObject } from "./Host";
|
|
4
4
|
export declare class JsiSkSurface extends HostObject<Surface, "Surface"> implements SkSurface {
|
|
5
|
-
|
|
6
|
-
constructor(CanvasKit: CanvasKit, ref: Surface, releaseCtx?: (() => void) | undefined);
|
|
5
|
+
constructor(CanvasKit: CanvasKit, ref: Surface);
|
|
7
6
|
dispose: () => void;
|
|
8
7
|
flush(): void;
|
|
8
|
+
width(): number;
|
|
9
|
+
height(): number;
|
|
9
10
|
getCanvas(): SkCanvas;
|
|
10
11
|
makeImageSnapshot(bounds?: SkRect): SkImage;
|
|
11
12
|
}
|
|
@@ -4,6 +4,6 @@ import { Host } from "./Host";
|
|
|
4
4
|
import { JsiSkSurface } from "./JsiSkSurface";
|
|
5
5
|
export declare class JsiSkSurfaceFactory extends Host implements SurfaceFactory {
|
|
6
6
|
constructor(CanvasKit: CanvasKit);
|
|
7
|
-
Make(width: number, height: number): JsiSkSurface
|
|
7
|
+
Make(width: number, height: number): JsiSkSurface;
|
|
8
8
|
MakeOffscreen(width: number, height: number): JsiSkSurface | null;
|
|
9
9
|
}
|
|
@@ -12,6 +12,12 @@ export declare class SkiaDomView extends React.Component<SkiaDomViewProps> {
|
|
|
12
12
|
* @returns An Image object.
|
|
13
13
|
*/
|
|
14
14
|
makeImageSnapshot(rect?: SkRect): import("../skia/types").SkImage;
|
|
15
|
+
/**
|
|
16
|
+
* Creates a snapshot from the canvas in the surface
|
|
17
|
+
* @param rect Rect to use as bounds. Optional.
|
|
18
|
+
* @returns An Image object.
|
|
19
|
+
*/
|
|
20
|
+
makeImageSnapshotAsync(rect?: SkRect): Promise<import("../skia/types").SkImage>;
|
|
15
21
|
/**
|
|
16
22
|
* Sends a redraw request to the native SkiaView.
|
|
17
23
|
*/
|
|
@@ -49,6 +49,7 @@ export interface ISkiaViewApi {
|
|
|
49
49
|
callJsiMethod: <T extends Array<unknown>>(nativeId: number, name: string, ...args: T) => void;
|
|
50
50
|
requestRedraw: (nativeId: number) => void;
|
|
51
51
|
makeImageSnapshot: (nativeId: number, rect?: SkRect) => SkImage;
|
|
52
|
+
makeImageSnapshotAsync: (nativeId: number, rect?: SkRect) => Promise<SkImage>;
|
|
52
53
|
}
|
|
53
54
|
export interface SkiaBaseViewProps extends ViewProps {
|
|
54
55
|
/**
|
package/package.json
CHANGED
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
"setup-skia-web": "./scripts/setup-canvaskit.js"
|
|
8
8
|
},
|
|
9
9
|
"title": "React Native Skia",
|
|
10
|
-
"version": "1.0
|
|
10
|
+
"version": "1.2.0",
|
|
11
11
|
"description": "High-performance React Native Graphics using Skia",
|
|
12
12
|
"main": "lib/module/index.js",
|
|
13
13
|
"react-native": "src/index.ts",
|
|
@@ -26,9 +26,15 @@ const createTexture = (
|
|
|
26
26
|
};
|
|
27
27
|
|
|
28
28
|
export const useTexture = (element: ReactElement, size: SkSize) => {
|
|
29
|
+
const { width, height } = size;
|
|
29
30
|
const picture = useMemo(() => {
|
|
30
|
-
return drawAsPicture(element
|
|
31
|
-
|
|
31
|
+
return drawAsPicture(element, {
|
|
32
|
+
x: 0,
|
|
33
|
+
y: 0,
|
|
34
|
+
width,
|
|
35
|
+
height,
|
|
36
|
+
});
|
|
37
|
+
}, [element, width, height]);
|
|
32
38
|
return usePictureAsTexture(picture, size);
|
|
33
39
|
};
|
|
34
40
|
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { useEffect } from "react";
|
|
2
|
-
import type
|
|
2
|
+
import { type FrameInfo, type SharedValue } from "react-native-reanimated";
|
|
3
3
|
|
|
4
4
|
import { useAnimatedImage } from "../../skia/core/AnimatedImage";
|
|
5
5
|
import type { DataSourceParam, SkImage } from "../../skia/types";
|
|
@@ -12,10 +12,15 @@ import {
|
|
|
12
12
|
|
|
13
13
|
const DEFAULT_FRAME_DURATION = 60;
|
|
14
14
|
|
|
15
|
-
export const useAnimatedImageValue = (
|
|
15
|
+
export const useAnimatedImageValue = (
|
|
16
|
+
source: DataSourceParam,
|
|
17
|
+
paused?: SharedValue<boolean>
|
|
18
|
+
) => {
|
|
16
19
|
throwOnMissingReanimated();
|
|
20
|
+
const defaultPaused = useSharedValue(false);
|
|
21
|
+
const isPaused = paused ?? defaultPaused;
|
|
17
22
|
const currentFrame = useSharedValue<null | SkImage>(null);
|
|
18
|
-
const lastTimestamp = useSharedValue(
|
|
23
|
+
const lastTimestamp = useSharedValue(-1);
|
|
19
24
|
const animatedImage = useAnimatedImage(
|
|
20
25
|
source,
|
|
21
26
|
(err) => {
|
|
@@ -32,7 +37,9 @@ export const useAnimatedImageValue = (source: DataSourceParam) => {
|
|
|
32
37
|
currentFrame.value = null;
|
|
33
38
|
return;
|
|
34
39
|
}
|
|
35
|
-
|
|
40
|
+
if (isPaused.value && lastTimestamp.value !== -1) {
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
36
43
|
const { timestamp } = frameInfo;
|
|
37
44
|
const elapsed = timestamp - lastTimestamp.value;
|
|
38
45
|
|
|
@@ -50,8 +57,7 @@ export const useAnimatedImageValue = (source: DataSourceParam) => {
|
|
|
50
57
|
|
|
51
58
|
// Update the last timestamp
|
|
52
59
|
lastTimestamp.value = timestamp;
|
|
53
|
-
|
|
54
|
-
}, true);
|
|
60
|
+
});
|
|
55
61
|
useEffect(() => {
|
|
56
62
|
return () => {
|
|
57
63
|
animatedImage?.dispose();
|
package/src/mock/index.ts
CHANGED
|
@@ -31,6 +31,7 @@ export const Mock = (CanvasKit: CanvasKit) => {
|
|
|
31
31
|
// Reanimated hooks
|
|
32
32
|
useClock: NoopSharedValue,
|
|
33
33
|
usePathInterpolation: NoopSharedValue,
|
|
34
|
+
useImageAsTexture: NoopSharedValue,
|
|
34
35
|
useTextureValue: NoopSharedValue,
|
|
35
36
|
useTextureValueFromPicture: NoopSharedValue,
|
|
36
37
|
useRSXformBuffer: NoopSharedValue,
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { ReactElement } from "react";
|
|
2
2
|
|
|
3
3
|
import { JsiDrawingContext } from "../dom/types";
|
|
4
|
-
import type { SkPicture, SkSize } from "../skia/types";
|
|
4
|
+
import type { SkPicture, SkRect, SkSize } from "../skia/types";
|
|
5
5
|
import { Skia } from "../skia";
|
|
6
6
|
import { Platform } from "../Platform";
|
|
7
7
|
|
|
@@ -16,9 +16,9 @@ export const isOnMainThread = () => {
|
|
|
16
16
|
);
|
|
17
17
|
};
|
|
18
18
|
|
|
19
|
-
export const drawAsPicture = (element: ReactElement) => {
|
|
19
|
+
export const drawAsPicture = (element: ReactElement, bounds?: SkRect) => {
|
|
20
20
|
const recorder = Skia.PictureRecorder();
|
|
21
|
-
const canvas = recorder.beginRecording();
|
|
21
|
+
const canvas = recorder.beginRecording(bounds);
|
|
22
22
|
const root = new SkiaRoot(Skia, false);
|
|
23
23
|
root.render(element);
|
|
24
24
|
const ctx = new JsiDrawingContext(Skia, canvas);
|
|
@@ -69,6 +69,21 @@ export interface ImageFactory {
|
|
|
69
69
|
*/
|
|
70
70
|
MakeImageFromEncoded: (encoded: SkData) => SkImage | null;
|
|
71
71
|
|
|
72
|
+
/**
|
|
73
|
+
* Return an Image backed by the given native platform buffer.
|
|
74
|
+
* The platform buffer must be a valid owning reference.
|
|
75
|
+
*
|
|
76
|
+
* This API is used by [react-native-vision-camera](https://github.com/mrousavy/react-native-vision-camera)
|
|
77
|
+
* to render a Skia Camera preview.
|
|
78
|
+
*
|
|
79
|
+
* - On Android; This is an `AHardwareBuffer*`
|
|
80
|
+
* - On iOS, this is a `CMSampleBufferRef`
|
|
81
|
+
* @param platformBuffer A strong `uintptr_t` pointer to the native platform buffer
|
|
82
|
+
* @throws Throws an error if the Image could not be created, for example when the given
|
|
83
|
+
* platform buffer is invalid.
|
|
84
|
+
*/
|
|
85
|
+
MakeImageFromPlatformBuffer: (platformBuffer: bigint) => SkImage;
|
|
86
|
+
|
|
72
87
|
/**
|
|
73
88
|
* Returns an image that will be a screenshot of the view represented by
|
|
74
89
|
* the view tag
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { SkImage } from "../Image";
|
|
2
|
+
|
|
3
|
+
export type PlatformBuffer = bigint;
|
|
4
|
+
|
|
5
|
+
export interface PlatformBufferFactory {
|
|
6
|
+
/**
|
|
7
|
+
* Copy pixels to a platform buffer. (for testing purposes)
|
|
8
|
+
*/
|
|
9
|
+
MakeFromImage: (image: SkImage) => PlatformBuffer;
|
|
10
|
+
/**
|
|
11
|
+
* Release a platform buffer that was created with `MakeFromImage`.
|
|
12
|
+
*/
|
|
13
|
+
Release: (platformBuffer: PlatformBuffer) => void;
|
|
14
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./PlatformBufferFactory";
|
package/src/skia/types/Skia.ts
CHANGED
|
@@ -30,6 +30,7 @@ import type { Color, SkColor } from "./Color";
|
|
|
30
30
|
import type { TypefaceFontProviderFactory } from "./Paragraph/TypefaceFontProviderFactory";
|
|
31
31
|
import type { AnimatedImageFactory } from "./AnimatedImage";
|
|
32
32
|
import type { ParagraphBuilderFactory } from "./Paragraph/ParagraphBuilder";
|
|
33
|
+
import type { PlatformBufferFactory } from "./PlatformBuffer";
|
|
33
34
|
|
|
34
35
|
/**
|
|
35
36
|
* Declares the interface for the native Skia API
|
|
@@ -93,6 +94,6 @@ export interface Skia {
|
|
|
93
94
|
SVG: SVGFactory;
|
|
94
95
|
TextBlob: TextBlobFactory;
|
|
95
96
|
Surface: SurfaceFactory;
|
|
96
|
-
// Paragraph
|
|
97
97
|
ParagraphBuilder: ParagraphBuilderFactory;
|
|
98
|
+
PlatformBuffer: PlatformBufferFactory;
|
|
98
99
|
}
|
|
@@ -29,4 +29,14 @@ export interface SkSurface extends SkJSIInstance<"Surface"> {
|
|
|
29
29
|
* Make sure any queued draws are sent to the screen or the GPU.
|
|
30
30
|
*/
|
|
31
31
|
flush(): void;
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Returns the possibly scaled width of the surface.
|
|
35
|
+
*/
|
|
36
|
+
width(): number;
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Returns the possibly scaled height of the surface.
|
|
40
|
+
*/
|
|
41
|
+
height(): number;
|
|
32
42
|
}
|
package/src/skia/types/index.ts
CHANGED
|
@@ -45,11 +45,7 @@ export const toBase64String = (bytes: Uint8Array) => {
|
|
|
45
45
|
};
|
|
46
46
|
|
|
47
47
|
export class JsiSkImage extends HostObject<Image, "Image"> implements SkImage {
|
|
48
|
-
constructor(
|
|
49
|
-
CanvasKit: CanvasKit,
|
|
50
|
-
ref: Image,
|
|
51
|
-
private releaseCtx?: () => void
|
|
52
|
-
) {
|
|
48
|
+
constructor(CanvasKit: CanvasKit, ref: Image) {
|
|
53
49
|
super(CanvasKit, ref, "Image");
|
|
54
50
|
}
|
|
55
51
|
|
|
@@ -154,37 +150,24 @@ export class JsiSkImage extends HostObject<Image, "Image"> implements SkImage {
|
|
|
154
150
|
|
|
155
151
|
dispose = () => {
|
|
156
152
|
this.ref.delete();
|
|
157
|
-
if (this.releaseCtx) {
|
|
158
|
-
this.releaseCtx();
|
|
159
|
-
}
|
|
160
153
|
};
|
|
161
154
|
|
|
162
155
|
makeNonTextureImage(): SkImage {
|
|
156
|
+
// if the image is already a non-texture image, this is a no-op
|
|
163
157
|
const partialInfo = this.ref.getImageInfo();
|
|
164
158
|
const colorSpace = this.ref.getColorSpace();
|
|
165
159
|
const info = {
|
|
166
160
|
...partialInfo,
|
|
167
161
|
colorSpace,
|
|
168
162
|
};
|
|
169
|
-
|
|
170
|
-
var pixelLen = info.width * info.height * 4;
|
|
171
|
-
const pixelPtr = this.CanvasKit.Malloc(Uint8Array, pixelLen);
|
|
172
|
-
const pixels = this.ref.readPixels(
|
|
173
|
-
0,
|
|
174
|
-
0,
|
|
175
|
-
info,
|
|
176
|
-
pixelPtr,
|
|
177
|
-
info.width * 4
|
|
178
|
-
) as Uint8Array | null;
|
|
163
|
+
const pixels = this.ref.readPixels(0, 0, info) as Uint8Array | null;
|
|
179
164
|
if (!pixels) {
|
|
180
|
-
throw new Error("Could not
|
|
165
|
+
throw new Error("Could not read pixels from image");
|
|
181
166
|
}
|
|
182
167
|
const img = this.CanvasKit.MakeImage(info, pixels, info.width * 4);
|
|
183
168
|
if (!img) {
|
|
184
169
|
throw new Error("Could not create image from bytes");
|
|
185
170
|
}
|
|
186
|
-
return new JsiSkImage(this.CanvasKit, img
|
|
187
|
-
this.CanvasKit.Free(pixelPtr);
|
|
188
|
-
});
|
|
171
|
+
return new JsiSkImage(this.CanvasKit, img);
|
|
189
172
|
}
|
|
190
173
|
}
|
|
@@ -1,7 +1,12 @@
|
|
|
1
1
|
import type { CanvasKit } from "canvaskit-wasm";
|
|
2
2
|
|
|
3
|
-
import type {
|
|
4
|
-
|
|
3
|
+
import type {
|
|
4
|
+
SkData,
|
|
5
|
+
ImageInfo,
|
|
6
|
+
SkImage,
|
|
7
|
+
PlatformBuffer,
|
|
8
|
+
ImageFactory,
|
|
9
|
+
} from "../types";
|
|
5
10
|
|
|
6
11
|
import { Host, getEnum } from "./Host";
|
|
7
12
|
import { JsiSkImage } from "./JsiSkImage";
|
|
@@ -19,6 +24,12 @@ export class JsiSkImageFactory extends Host implements ImageFactory {
|
|
|
19
24
|
return Promise.resolve(null);
|
|
20
25
|
}
|
|
21
26
|
|
|
27
|
+
MakeImageFromPlatformBuffer(_platformBuffer: PlatformBuffer): SkImage {
|
|
28
|
+
throw new Error(
|
|
29
|
+
"MakeImageFromPlatformBuffer() is only available on iOS and Android!"
|
|
30
|
+
);
|
|
31
|
+
}
|
|
32
|
+
|
|
22
33
|
MakeImageFromEncoded(encoded: SkData) {
|
|
23
34
|
const image = this.CanvasKit.MakeImageFromEncoded(
|
|
24
35
|
JsiSkData.fromValue(encoded)
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { CanvasKit } from "canvaskit-wasm";
|
|
2
|
+
|
|
3
|
+
import type { PlatformBuffer, PlatformBufferFactory, SkImage } from "../types";
|
|
4
|
+
|
|
5
|
+
import { Host, NotImplementedOnRNWeb } from "./Host";
|
|
6
|
+
|
|
7
|
+
export class JsiSkPlatformBufferFactory
|
|
8
|
+
extends Host
|
|
9
|
+
implements PlatformBufferFactory
|
|
10
|
+
{
|
|
11
|
+
constructor(CanvasKit: CanvasKit) {
|
|
12
|
+
super(CanvasKit);
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
MakeFromImage(_image: SkImage): PlatformBuffer {
|
|
16
|
+
throw new NotImplementedOnRNWeb();
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
Release(_platformBuffer: PlatformBuffer) {
|
|
20
|
+
throw new NotImplementedOnRNWeb();
|
|
21
|
+
}
|
|
22
|
+
}
|
|
@@ -11,25 +11,26 @@ export class JsiSkSurface
|
|
|
11
11
|
extends HostObject<Surface, "Surface">
|
|
12
12
|
implements SkSurface
|
|
13
13
|
{
|
|
14
|
-
constructor(
|
|
15
|
-
CanvasKit: CanvasKit,
|
|
16
|
-
ref: Surface,
|
|
17
|
-
private releaseCtx?: () => void
|
|
18
|
-
) {
|
|
14
|
+
constructor(CanvasKit: CanvasKit, ref: Surface) {
|
|
19
15
|
super(CanvasKit, ref, "Surface");
|
|
20
16
|
}
|
|
21
17
|
|
|
22
18
|
dispose = () => {
|
|
23
|
-
this.ref.
|
|
24
|
-
if (this.releaseCtx) {
|
|
25
|
-
this.releaseCtx();
|
|
26
|
-
}
|
|
19
|
+
this.ref.dispose();
|
|
27
20
|
};
|
|
28
21
|
|
|
29
22
|
flush() {
|
|
30
23
|
this.ref.flush();
|
|
31
24
|
}
|
|
32
25
|
|
|
26
|
+
width() {
|
|
27
|
+
return this.ref.width();
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
height() {
|
|
31
|
+
return this.ref.height();
|
|
32
|
+
}
|
|
33
|
+
|
|
33
34
|
getCanvas(): SkCanvas {
|
|
34
35
|
return new JsiSkCanvas(this.CanvasKit, this.ref.getCanvas());
|
|
35
36
|
}
|
|
@@ -11,26 +11,10 @@ export class JsiSkSurfaceFactory extends Host implements SurfaceFactory {
|
|
|
11
11
|
}
|
|
12
12
|
|
|
13
13
|
Make(width: number, height: number) {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
{
|
|
18
|
-
width: width,
|
|
19
|
-
height: height,
|
|
20
|
-
colorType: this.CanvasKit.ColorType.RGBA_8888,
|
|
21
|
-
alphaType: this.CanvasKit.AlphaType.Unpremul,
|
|
22
|
-
colorSpace: this.CanvasKit.ColorSpace.SRGB,
|
|
23
|
-
},
|
|
24
|
-
pixelPtr,
|
|
25
|
-
width * 4
|
|
14
|
+
return new JsiSkSurface(
|
|
15
|
+
this.CanvasKit,
|
|
16
|
+
this.CanvasKit.MakeSurface(width, height)!
|
|
26
17
|
);
|
|
27
|
-
if (!surface) {
|
|
28
|
-
return null;
|
|
29
|
-
}
|
|
30
|
-
surface.getCanvas().clear(this.CanvasKit.TRANSPARENT);
|
|
31
|
-
return new JsiSkSurface(this.CanvasKit, surface, () => {
|
|
32
|
-
this.CanvasKit.Free(pixelPtr);
|
|
33
|
-
});
|
|
34
18
|
}
|
|
35
19
|
|
|
36
20
|
MakeOffscreen(width: number, height: number) {
|
|
@@ -39,7 +23,7 @@ export class JsiSkSurfaceFactory extends Host implements SurfaceFactory {
|
|
|
39
23
|
const OC = (globalThis as any).OffscreenCanvas;
|
|
40
24
|
let surface: Surface | null;
|
|
41
25
|
if (OC === undefined) {
|
|
42
|
-
|
|
26
|
+
return this.Make(width, height);
|
|
43
27
|
} else {
|
|
44
28
|
const offscreen = new OC(width, height);
|
|
45
29
|
const webglContext = this.CanvasKit.GetWebGLContext(offscreen);
|
package/src/skia/web/JsiSkia.ts
CHANGED
|
@@ -41,6 +41,7 @@ import { JsiSkTypefaceFontProviderFactory } from "./JsiSkTypefaceFontProviderFac
|
|
|
41
41
|
import { JsiSkFontMgrFactory } from "./JsiSkFontMgrFactory";
|
|
42
42
|
import { JsiSkAnimatedImageFactory } from "./JsiSkAnimatedImageFactory";
|
|
43
43
|
import { JsiSkParagraphBuilderFactory } from "./JsiSkParagraphBuilderFactory";
|
|
44
|
+
import { JsiSkPlatformBufferFactory } from "./JsiSkPlatformBufferFactory";
|
|
44
45
|
|
|
45
46
|
export const JsiSkApi = (CanvasKit: CanvasKit): Skia => ({
|
|
46
47
|
Point: (x: number, y: number) =>
|
|
@@ -125,4 +126,5 @@ export const JsiSkApi = (CanvasKit: CanvasKit): Skia => ({
|
|
|
125
126
|
TypefaceFontProvider: new JsiSkTypefaceFontProviderFactory(CanvasKit),
|
|
126
127
|
FontMgr: new JsiSkFontMgrFactory(CanvasKit),
|
|
127
128
|
ParagraphBuilder: new JsiSkParagraphBuilderFactory(CanvasKit),
|
|
129
|
+
PlatformBuffer: new JsiSkPlatformBufferFactory(CanvasKit),
|
|
128
130
|
});
|
|
@@ -66,6 +66,16 @@ export class SkiaDomView extends React.Component<SkiaDomViewProps> {
|
|
|
66
66
|
return SkiaViewApi.makeImageSnapshot(this._nativeId, rect);
|
|
67
67
|
}
|
|
68
68
|
|
|
69
|
+
/**
|
|
70
|
+
* Creates a snapshot from the canvas in the surface
|
|
71
|
+
* @param rect Rect to use as bounds. Optional.
|
|
72
|
+
* @returns An Image object.
|
|
73
|
+
*/
|
|
74
|
+
public makeImageSnapshotAsync(rect?: SkRect) {
|
|
75
|
+
assertSkiaViewApi();
|
|
76
|
+
return SkiaViewApi.makeImageSnapshotAsync(this._nativeId, rect);
|
|
77
|
+
}
|
|
78
|
+
|
|
69
79
|
/**
|
|
70
80
|
* Sends a redraw request to the native SkiaView.
|
|
71
81
|
*/
|
package/src/views/types.ts
CHANGED
|
@@ -65,6 +65,7 @@ export interface ISkiaViewApi {
|
|
|
65
65
|
) => void;
|
|
66
66
|
requestRedraw: (nativeId: number) => void;
|
|
67
67
|
makeImageSnapshot: (nativeId: number, rect?: SkRect) => SkImage;
|
|
68
|
+
makeImageSnapshotAsync: (nativeId: number, rect?: SkRect) => Promise<SkImage>;
|
|
68
69
|
}
|
|
69
70
|
|
|
70
71
|
export interface SkiaBaseViewProps extends ViewProps {
|