@shopify/react-native-skia 1.1.0 → 1.2.0
Sign up to get free protection for your applications and to get access to all the features.
- 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 -1
- package/cpp/api/JsiSkSurface.h +9 -1
- 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/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 +1 -16
- 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/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/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 +1 -16
- 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/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/package.json +1 -1
- package/src/external/reanimated/textures.tsx +8 -2
- package/src/external/reanimated/useAnimatedImageValue.ts +12 -6
- 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 +3 -19
- package/src/skia/web/JsiSkia.ts +2 -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":["getEnum","HostObject","JsiSkMatrix","JsiSkShader","toBase64String","bytes","Buffer","from","toString","CHUNK_SIZE","index","length","result","slice","Math","min","String","fromCharCode","apply","btoa","JsiSkImage","constructor","CanvasKit","ref","releaseCtx","_defineProperty","delete","height","width","getImageInfo","info","colorType","value","alphaType","makeShaderOptions","tx","ty","fm","mm","localMatrix","TileMode","FilterMode","MipmapMode","fromValue","undefined","makeShaderCubic","B","C","encodeToBytes","fmt","quality","ImageFormat","Error","encodeToBase64","readPixels","srcX","srcY","imageInfo","_imageInfo$width","_imageInfo$height","pxInfo","colorSpace","ColorSpace","SRGB","AlphaType","ColorType","makeNonTextureImage","partialInfo","getColorSpace","pixelLen","pixelPtr","Malloc","Uint8Array","pixels","img","MakeImage","Free"],"sources":["JsiSkImage.ts"],"sourcesContent":["import type {\n CanvasKit,\n ImageInfo as CKImageInfo,\n Image,\n} from \"canvaskit-wasm\";\n\nimport type {\n FilterMode,\n MipmapMode,\n SkImage,\n SkMatrix,\n SkShader,\n TileMode,\n ImageFormat,\n ImageInfo,\n} from \"../types\";\n\nimport { getEnum, HostObject } from \"./Host\";\nimport { JsiSkMatrix } from \"./JsiSkMatrix\";\nimport { JsiSkShader } from \"./JsiSkShader\";\n\n// https://github.com/google/skia/blob/1f193df9b393d50da39570dab77a0bb5d28ec8ef/modules/canvaskit/htmlcanvas/util.js\nexport const toBase64String = (bytes: Uint8Array) => {\n if (typeof Buffer !== \"undefined\") {\n // Are we on node?\n return Buffer.from(bytes).toString(\"base64\");\n } else {\n // From https://stackoverflow.com/a/25644409\n // because the naive solution of\n // btoa(String.fromCharCode.apply(null, bytes));\n // would occasionally throw \"Maximum call stack size exceeded\"\n var CHUNK_SIZE = 0x8000; //arbitrary number\n var index = 0;\n var { length } = bytes;\n var result = \"\";\n var slice;\n while (index < length) {\n slice = bytes.slice(index, Math.min(index + CHUNK_SIZE, length));\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n result += String.fromCharCode.apply(null, slice as any);\n index += CHUNK_SIZE;\n }\n return btoa(result);\n }\n};\n\nexport class JsiSkImage extends HostObject<Image, \"Image\"> implements SkImage {\n constructor(\n CanvasKit: CanvasKit,\n ref: Image,\n private releaseCtx?: () => void\n ) {\n super(CanvasKit, ref, \"Image\");\n }\n\n height() {\n return this.ref.height();\n }\n\n width() {\n return this.ref.width();\n }\n\n getImageInfo(): ImageInfo {\n const info = this.ref.getImageInfo();\n return {\n width: info.width,\n height: info.height,\n colorType: info.colorType.value,\n alphaType: info.alphaType.value,\n };\n }\n\n makeShaderOptions(\n tx: TileMode,\n ty: TileMode,\n fm: FilterMode,\n mm: MipmapMode,\n localMatrix?: SkMatrix\n ): SkShader {\n return new JsiSkShader(\n this.CanvasKit,\n this.ref.makeShaderOptions(\n getEnum(this.CanvasKit.TileMode, tx),\n getEnum(this.CanvasKit.TileMode, ty),\n getEnum(this.CanvasKit.FilterMode, fm),\n getEnum(this.CanvasKit.MipmapMode, mm),\n localMatrix ? JsiSkMatrix.fromValue(localMatrix) : undefined\n )\n );\n }\n\n makeShaderCubic(\n tx: TileMode,\n ty: TileMode,\n B: number,\n C: number,\n localMatrix?: SkMatrix\n ): SkShader {\n return new JsiSkShader(\n this.CanvasKit,\n this.ref.makeShaderCubic(\n getEnum(this.CanvasKit.TileMode, tx),\n getEnum(this.CanvasKit.TileMode, ty),\n B,\n C,\n localMatrix ? JsiSkMatrix.fromValue(localMatrix) : undefined\n )\n );\n }\n\n encodeToBytes(fmt?: ImageFormat, quality?: number) {\n let result: Uint8Array | null;\n if (fmt && quality) {\n result = this.ref.encodeToBytes(\n getEnum(this.CanvasKit.ImageFormat, fmt),\n quality\n );\n } else if (fmt) {\n result = this.ref.encodeToBytes(getEnum(this.CanvasKit.ImageFormat, fmt));\n } else {\n result = this.ref.encodeToBytes();\n }\n if (!result) {\n throw new Error(\"encodeToBytes failed\");\n }\n return result;\n }\n\n encodeToBase64(fmt?: ImageFormat, quality?: number) {\n const bytes = this.encodeToBytes(fmt, quality);\n return toBase64String(bytes);\n }\n\n // TODO: this is leaking on Web\n // Add signature with allocated buffer\n readPixels(srcX?: number, srcY?: number, imageInfo?: ImageInfo) {\n const info = this.getImageInfo();\n const pxInfo: CKImageInfo = {\n colorSpace: this.CanvasKit.ColorSpace.SRGB,\n width: imageInfo?.width ?? info.width,\n height: imageInfo?.height ?? info.height,\n alphaType: getEnum(\n this.CanvasKit.AlphaType,\n (imageInfo ?? info).alphaType\n ),\n colorType: getEnum(\n this.CanvasKit.ColorType,\n (imageInfo ?? info).colorType\n ),\n };\n return this.ref.readPixels(srcX ?? 0, srcY ?? 0, pxInfo);\n }\n\n dispose = () => {\n this.ref.delete();\n if (this.releaseCtx) {\n this.releaseCtx();\n }\n };\n\n makeNonTextureImage(): SkImage {\n const partialInfo = this.ref.getImageInfo();\n const colorSpace = this.ref.getColorSpace();\n const info = {\n ...partialInfo,\n colorSpace,\n };\n\n var pixelLen = info.width * info.height * 4;\n const pixelPtr = this.CanvasKit.Malloc(Uint8Array, pixelLen);\n const pixels = this.ref.readPixels(\n 0,\n 0,\n info,\n pixelPtr,\n info.width * 4\n ) as Uint8Array | null;\n if (!pixels) {\n throw new Error(\"Could not create image from bytes\");\n }\n const img = this.CanvasKit.MakeImage(info, pixels, info.width * 4);\n if (!img) {\n throw new Error(\"Could not create image from bytes\");\n }\n return new JsiSkImage(this.CanvasKit, img, () => {\n this.CanvasKit.Free(pixelPtr);\n });\n }\n}\n"],"mappings":";;;AAiBA,SAASA,OAAO,EAAEC,UAAU,QAAQ,QAAQ;AAC5C,SAASC,WAAW,QAAQ,eAAe;AAC3C,SA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,IAAI,CAAC6C,MAAM,EAAE;MACX,MAAM,IAAIrB,KAAK,CAAC,mCAAmC,CAAC;IACtD;IACA,MAAMsB,GAAG,GAAG,IAAI,CAACpD,SAAS,CAACqD,SAAS,CAAC7C,IAAI,EAAE2C,MAAM,EAAE3C,IAAI,CAACF,KAAK,GAAG,CAAC,CAAC;IAClE,IAAI,CAAC8C,GAAG,EAAE;MACR,MAAM,IAAItB,KAAK,CAAC,mCAAmC,CAAC;IACtD;IACA,OAAO,IAAIhC,UAAU,CAAC,IAAI,CAACE,SAAS,EAAEoD,GAAG,EAAE,MAAM;MAC/C,IAAI,CAACpD,SAAS,CAACsD,IAAI,CAACN,QAAQ,CAAC;IAC/B,CAAC,CAAC;EACJ;AACF"}
|
1
|
+
{"version":3,"names":["getEnum","HostObject","JsiSkMatrix","JsiSkShader","toBase64String","bytes","Buffer","from","toString","CHUNK_SIZE","index","length","result","slice","Math","min","String","fromCharCode","apply","btoa","JsiSkImage","constructor","CanvasKit","ref","_defineProperty","delete","height","width","getImageInfo","info","colorType","value","alphaType","makeShaderOptions","tx","ty","fm","mm","localMatrix","TileMode","FilterMode","MipmapMode","fromValue","undefined","makeShaderCubic","B","C","encodeToBytes","fmt","quality","ImageFormat","Error","encodeToBase64","readPixels","srcX","srcY","imageInfo","_imageInfo$width","_imageInfo$height","pxInfo","colorSpace","ColorSpace","SRGB","AlphaType","ColorType","makeNonTextureImage","partialInfo","getColorSpace","pixels","img","MakeImage"],"sources":["JsiSkImage.ts"],"sourcesContent":["import type {\n CanvasKit,\n ImageInfo as CKImageInfo,\n Image,\n} from \"canvaskit-wasm\";\n\nimport type {\n FilterMode,\n MipmapMode,\n SkImage,\n SkMatrix,\n SkShader,\n TileMode,\n ImageFormat,\n ImageInfo,\n} from \"../types\";\n\nimport { getEnum, HostObject } from \"./Host\";\nimport { JsiSkMatrix } from \"./JsiSkMatrix\";\nimport { JsiSkShader } from \"./JsiSkShader\";\n\n// https://github.com/google/skia/blob/1f193df9b393d50da39570dab77a0bb5d28ec8ef/modules/canvaskit/htmlcanvas/util.js\nexport const toBase64String = (bytes: Uint8Array) => {\n if (typeof Buffer !== \"undefined\") {\n // Are we on node?\n return Buffer.from(bytes).toString(\"base64\");\n } else {\n // From https://stackoverflow.com/a/25644409\n // because the naive solution of\n // btoa(String.fromCharCode.apply(null, bytes));\n // would occasionally throw \"Maximum call stack size exceeded\"\n var CHUNK_SIZE = 0x8000; //arbitrary number\n var index = 0;\n var { length } = bytes;\n var result = \"\";\n var slice;\n while (index < length) {\n slice = bytes.slice(index, Math.min(index + CHUNK_SIZE, length));\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n result += String.fromCharCode.apply(null, slice as any);\n index += CHUNK_SIZE;\n }\n return btoa(result);\n }\n};\n\nexport class JsiSkImage extends HostObject<Image, \"Image\"> implements SkImage {\n constructor(CanvasKit: CanvasKit, ref: Image) {\n super(CanvasKit, ref, \"Image\");\n }\n\n height() {\n return this.ref.height();\n }\n\n width() {\n return this.ref.width();\n }\n\n getImageInfo(): ImageInfo {\n const info = this.ref.getImageInfo();\n return {\n width: info.width,\n height: info.height,\n colorType: info.colorType.value,\n alphaType: info.alphaType.value,\n };\n }\n\n makeShaderOptions(\n tx: TileMode,\n ty: TileMode,\n fm: FilterMode,\n mm: MipmapMode,\n localMatrix?: SkMatrix\n ): SkShader {\n return new JsiSkShader(\n this.CanvasKit,\n this.ref.makeShaderOptions(\n getEnum(this.CanvasKit.TileMode, tx),\n getEnum(this.CanvasKit.TileMode, ty),\n getEnum(this.CanvasKit.FilterMode, fm),\n getEnum(this.CanvasKit.MipmapMode, mm),\n localMatrix ? JsiSkMatrix.fromValue(localMatrix) : undefined\n )\n );\n }\n\n makeShaderCubic(\n tx: TileMode,\n ty: TileMode,\n B: number,\n C: number,\n localMatrix?: SkMatrix\n ): SkShader {\n return new JsiSkShader(\n this.CanvasKit,\n this.ref.makeShaderCubic(\n getEnum(this.CanvasKit.TileMode, tx),\n getEnum(this.CanvasKit.TileMode, ty),\n B,\n C,\n localMatrix ? JsiSkMatrix.fromValue(localMatrix) : undefined\n )\n );\n }\n\n encodeToBytes(fmt?: ImageFormat, quality?: number) {\n let result: Uint8Array | null;\n if (fmt && quality) {\n result = this.ref.encodeToBytes(\n getEnum(this.CanvasKit.ImageFormat, fmt),\n quality\n );\n } else if (fmt) {\n result = this.ref.encodeToBytes(getEnum(this.CanvasKit.ImageFormat, fmt));\n } else {\n result = this.ref.encodeToBytes();\n }\n if (!result) {\n throw new Error(\"encodeToBytes failed\");\n }\n return result;\n }\n\n encodeToBase64(fmt?: ImageFormat, quality?: number) {\n const bytes = this.encodeToBytes(fmt, quality);\n return toBase64String(bytes);\n }\n\n // TODO: this is leaking on Web\n // Add signature with allocated buffer\n readPixels(srcX?: number, srcY?: number, imageInfo?: ImageInfo) {\n const info = this.getImageInfo();\n const pxInfo: CKImageInfo = {\n colorSpace: this.CanvasKit.ColorSpace.SRGB,\n width: imageInfo?.width ?? info.width,\n height: imageInfo?.height ?? info.height,\n alphaType: getEnum(\n this.CanvasKit.AlphaType,\n (imageInfo ?? info).alphaType\n ),\n colorType: getEnum(\n this.CanvasKit.ColorType,\n (imageInfo ?? info).colorType\n ),\n };\n return this.ref.readPixels(srcX ?? 0, srcY ?? 0, pxInfo);\n }\n\n dispose = () => {\n this.ref.delete();\n };\n\n makeNonTextureImage(): SkImage {\n // if the image is already a non-texture image, this is a no-op\n const partialInfo = this.ref.getImageInfo();\n const colorSpace = this.ref.getColorSpace();\n const info = {\n ...partialInfo,\n colorSpace,\n };\n const pixels = this.ref.readPixels(0, 0, info) as Uint8Array | null;\n if (!pixels) {\n throw new Error(\"Could not read pixels from image\");\n }\n const img = this.CanvasKit.MakeImage(info, pixels, info.width * 4);\n if (!img) {\n throw new Error(\"Could not create image from bytes\");\n }\n return new JsiSkImage(this.CanvasKit, img);\n }\n}\n"],"mappings":";;;AAiBA,SAASA,OAAO,EAAEC,UAAU,QAAQ,QAAQ;AAC5C,SAASC,WAAW,QAA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ACE,SAAS,EAAE+C,GAAG,CAAC;EAC5C;AACF"}
|
@@ -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
|
}
|
@@ -11,6 +11,9 @@ export class JsiSkImageFactory extends Host {
|
|
11
11
|
console.log(view);
|
12
12
|
return Promise.resolve(null);
|
13
13
|
}
|
14
|
+
MakeImageFromPlatformBuffer(_platformBuffer) {
|
15
|
+
throw new Error("MakeImageFromPlatformBuffer() is only available on iOS and Android!");
|
16
|
+
}
|
14
17
|
MakeImageFromEncoded(encoded) {
|
15
18
|
const image = this.CanvasKit.MakeImageFromEncoded(JsiSkData.fromValue(encoded));
|
16
19
|
if (image === null) {
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"names":["Host","getEnum","JsiSkImage","JsiSkData","JsiSkImageFactory","constructor","CanvasKit","MakeImageFromViewTag","viewTag","view","console","log","Promise","resolve","MakeImageFromEncoded","encoded","image","fromValue","MakeImage","info","data","bytesPerRow","alphaType","AlphaType","colorSpace","ColorSpace","SRGB","colorType","ColorType","height","width"],"sources":["JsiSkImageFactory.ts"],"sourcesContent":["import type { CanvasKit } from \"canvaskit-wasm\";\n\nimport type {
|
1
|
+
{"version":3,"names":["Host","getEnum","JsiSkImage","JsiSkData","JsiSkImageFactory","constructor","CanvasKit","MakeImageFromViewTag","viewTag","view","console","log","Promise","resolve","MakeImageFromPlatformBuffer","_platformBuffer","Error","MakeImageFromEncoded","encoded","image","fromValue","MakeImage","info","data","bytesPerRow","alphaType","AlphaType","colorSpace","ColorSpace","SRGB","colorType","ColorType","height","width"],"sources":["JsiSkImageFactory.ts"],"sourcesContent":["import type { CanvasKit } from \"canvaskit-wasm\";\n\nimport type {\n SkData,\n ImageInfo,\n SkImage,\n PlatformBuffer,\n ImageFactory,\n} from \"../types\";\n\nimport { Host, getEnum } from \"./Host\";\nimport { JsiSkImage } from \"./JsiSkImage\";\nimport { JsiSkData } from \"./JsiSkData\";\n\nexport class JsiSkImageFactory extends Host implements ImageFactory {\n constructor(CanvasKit: CanvasKit) {\n super(CanvasKit);\n }\n\n MakeImageFromViewTag(viewTag: number): Promise<SkImage | null> {\n const view = viewTag as unknown as HTMLElement;\n // TODO: Implement screenshot from view in React JS\n console.log(view);\n return Promise.resolve(null);\n }\n\n MakeImageFromPlatformBuffer(_platformBuffer: PlatformBuffer): SkImage {\n throw new Error(\n \"MakeImageFromPlatformBuffer() is only available on iOS and Android!\"\n );\n }\n\n MakeImageFromEncoded(encoded: SkData) {\n const image = this.CanvasKit.MakeImageFromEncoded(\n JsiSkData.fromValue(encoded)\n );\n if (image === null) {\n return null;\n }\n return new JsiSkImage(this.CanvasKit, image);\n }\n\n MakeImage(info: ImageInfo, data: SkData, bytesPerRow: number) {\n // see toSkImageInfo() from canvaskit\n const image = this.CanvasKit.MakeImage(\n {\n alphaType: getEnum(this.CanvasKit.AlphaType, info.alphaType),\n colorSpace: this.CanvasKit.ColorSpace.SRGB,\n colorType: getEnum(this.CanvasKit.ColorType, info.colorType),\n height: info.height,\n width: info.width,\n },\n JsiSkData.fromValue(data),\n bytesPerRow\n );\n if (image === null) {\n return null;\n }\n return new JsiSkImage(this.CanvasKit, image);\n }\n}\n"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IACd,CAAC,EACD9B,SAAS,CAACiB,SAAS,CAACG,IAAI,CAAC,EACzBC,WACF,CAAC;IACD,IAAIL,KAAK,KAAK,IAAI,EAAE;MAClB,OAAO,IAAI;IACb;IACA,OAAO,IAAIjB,UAAU,CAAC,IAAI,CAACI,SAAS,EAAEa,KAAK,CAAC;EAC9C;AACF"}
|
@@ -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
|
+
}
|
@@ -0,0 +1,13 @@
|
|
1
|
+
import { Host, NotImplementedOnRNWeb } from "./Host";
|
2
|
+
export class JsiSkPlatformBufferFactory extends Host {
|
3
|
+
constructor(CanvasKit) {
|
4
|
+
super(CanvasKit);
|
5
|
+
}
|
6
|
+
MakeFromImage(_image) {
|
7
|
+
throw new NotImplementedOnRNWeb();
|
8
|
+
}
|
9
|
+
Release(_platformBuffer) {
|
10
|
+
throw new NotImplementedOnRNWeb();
|
11
|
+
}
|
12
|
+
}
|
13
|
+
//# sourceMappingURL=JsiSkPlatformBufferFactory.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"names":["Host","NotImplementedOnRNWeb","JsiSkPlatformBufferFactory","constructor","CanvasKit","MakeFromImage","_image","Release","_platformBuffer"],"sources":["JsiSkPlatformBufferFactory.ts"],"sourcesContent":["import type { CanvasKit } from \"canvaskit-wasm\";\n\nimport type { PlatformBuffer, PlatformBufferFactory, SkImage } from \"../types\";\n\nimport { Host, NotImplementedOnRNWeb } from \"./Host\";\n\nexport class JsiSkPlatformBufferFactory\n extends Host\n implements PlatformBufferFactory\n{\n constructor(CanvasKit: CanvasKit) {\n super(CanvasKit);\n }\n\n MakeFromImage(_image: SkImage): PlatformBuffer {\n throw new NotImplementedOnRNWeb();\n }\n\n Release(_platformBuffer: PlatformBuffer) {\n throw new NotImplementedOnRNWeb();\n }\n}\n"],"mappings":"AAIA,SAASA,IAAI,EAAEC,qBAAqB,QAAQ,QAAQ;AAEpD,OAAO,MAAMC,0BAA0B,SAC7BF,IAAI,CAEd;EACEG,WAAWA,CAACC,SAAoB,EAAE;IAChC,KAAK,CAACA,SAAS,CAAC;EAClB;EAEAC,aAAaA,CAACC,MAAe,EAAkB;IAC7C,MAAM,IAAIL,qBAAqB,CAAC,CAAC;EACnC;EAEAM,OAAOA,CAACC,eAA+B,EAAE;IACvC,MAAM,IAAIP,qBAAqB,CAAC,CAAC;EACnC;AACF"}
|
@@ -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
|
}
|
@@ -6,19 +6,21 @@ import { JsiSkCanvas } from "./JsiSkCanvas";
|
|
6
6
|
import { JsiSkImage } from "./JsiSkImage";
|
7
7
|
import { JsiSkRect } from "./JsiSkRect";
|
8
8
|
export class JsiSkSurface extends HostObject {
|
9
|
-
constructor(CanvasKit, ref
|
9
|
+
constructor(CanvasKit, ref) {
|
10
10
|
super(CanvasKit, ref, "Surface");
|
11
|
-
this.releaseCtx = releaseCtx;
|
12
11
|
_defineProperty(this, "dispose", () => {
|
13
|
-
this.ref.
|
14
|
-
if (this.releaseCtx) {
|
15
|
-
this.releaseCtx();
|
16
|
-
}
|
12
|
+
this.ref.dispose();
|
17
13
|
});
|
18
14
|
}
|
19
15
|
flush() {
|
20
16
|
this.ref.flush();
|
21
17
|
}
|
18
|
+
width() {
|
19
|
+
return this.ref.width();
|
20
|
+
}
|
21
|
+
height() {
|
22
|
+
return this.ref.height();
|
23
|
+
}
|
22
24
|
getCanvas() {
|
23
25
|
return new JsiSkCanvas(this.CanvasKit, this.ref.getCanvas());
|
24
26
|
}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"names":["HostObject","JsiSkCanvas","JsiSkImage","JsiSkRect","JsiSkSurface","constructor","CanvasKit","ref","
|
1
|
+
{"version":3,"names":["HostObject","JsiSkCanvas","JsiSkImage","JsiSkRect","JsiSkSurface","constructor","CanvasKit","ref","_defineProperty","dispose","flush","width","height","getCanvas","makeImageSnapshot","bounds","image","Array","from","fromValue","undefined"],"sources":["JsiSkSurface.ts"],"sourcesContent":["import type { CanvasKit, Surface } from \"canvaskit-wasm\";\n\nimport type { SkCanvas, SkImage, SkRect, SkSurface } from \"../types\";\n\nimport { HostObject } from \"./Host\";\nimport { JsiSkCanvas } from \"./JsiSkCanvas\";\nimport { JsiSkImage } from \"./JsiSkImage\";\nimport { JsiSkRect } from \"./JsiSkRect\";\n\nexport class JsiSkSurface\n extends HostObject<Surface, \"Surface\">\n implements SkSurface\n{\n constructor(CanvasKit: CanvasKit, ref: Surface) {\n super(CanvasKit, ref, \"Surface\");\n }\n\n dispose = () => {\n this.ref.dispose();\n };\n\n flush() {\n this.ref.flush();\n }\n\n width() {\n return this.ref.width();\n }\n\n height() {\n return this.ref.height();\n }\n\n getCanvas(): SkCanvas {\n return new JsiSkCanvas(this.CanvasKit, this.ref.getCanvas());\n }\n\n makeImageSnapshot(bounds?: SkRect): SkImage {\n const image = this.ref.makeImageSnapshot(\n bounds\n ? Array.from(JsiSkRect.fromValue(this.CanvasKit, bounds))\n : undefined\n );\n return new JsiSkImage(this.CanvasKit, image);\n }\n}\n"],"mappings":";;;AAIA,SAASA,UAAU,QAAQ,QAAQ;AACnC,SAASC,WAAW,QAAQ,eAAe;AAC3C,SAASC,UAAU,QAAQ,cAAc;AACzC,SAASC,SAAS,QAAQ,aAAa;AAEvC,OAAO,MAAMC,YAAY,SACfJ,UAAU,CAEpB;EACEK,WAAWA,CAACC,SAAoB,EAAEC,GAAY,EAAE;IAC9C,KAAK,CAACD,SAAS,EAAEC,GAAG,EAAE,SAAS,CAAC;IAACC,eAAA,kBAGzB,MAAM;MACd,IAAI,CAACD,GAAG,CAACE,OAAO,CAAC,CAAC;IACpB,CAAC;EAJD;EAMAC,KAAKA,CAAA,EAAG;IACN,IAAI,CAACH,GAAG,CAACG,KAAK,CAAC,CAAC;EAClB;EAEAC,KAAKA,CAAA,EAAG;IACN,OAAO,IAAI,CAACJ,GAAG,CAACI,KAAK,CAAC,CAAC;EACzB;EAEAC,MAAMA,CAAA,EAAG;IACP,OAAO,IAAI,CAACL,GAAG,CAACK,MAAM,CAAC,CAAC;EAC1B;EAEAC,SAASA,CAAA,EAAa;IACpB,OAAO,IAAIZ,WAAW,CAAC,IAAI,CAACK,SAAS,EAAE,IAAI,CAACC,GAAG,CAACM,SAAS,CAAC,CAAC,CAAC;EAC9D;EAEAC,iBAAiBA,CAACC,MAAe,EAAW;IAC1C,MAAMC,KAAK,GAAG,IAAI,CAACT,GAAG,CAACO,iBAAiB,CACtCC,MAAM,GACFE,KAAK,CAACC,IAAI,CAACf,SAAS,CAACgB,SAAS,CAAC,IAAI,CAACb,SAAS,EAAES,MAAM,CAAC,CAAC,GACvDK,SACN,CAAC;IACD,OAAO,IAAIlB,UAAU,CAAC,IAAI,CAACI,SAAS,EAAEU,KAAK,CAAC;EAC9C;AACF"}
|
@@ -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
|
}
|
@@ -5,22 +5,7 @@ export class JsiSkSurfaceFactory extends Host {
|
|
5
5
|
super(CanvasKit);
|
6
6
|
}
|
7
7
|
Make(width, height) {
|
8
|
-
|
9
|
-
const pixelPtr = this.CanvasKit.Malloc(Uint8Array, pixelLen);
|
10
|
-
const surface = this.CanvasKit.MakeRasterDirectSurface({
|
11
|
-
width: width,
|
12
|
-
height: height,
|
13
|
-
colorType: this.CanvasKit.ColorType.RGBA_8888,
|
14
|
-
alphaType: this.CanvasKit.AlphaType.Unpremul,
|
15
|
-
colorSpace: this.CanvasKit.ColorSpace.SRGB
|
16
|
-
}, pixelPtr, width * 4);
|
17
|
-
if (!surface) {
|
18
|
-
return null;
|
19
|
-
}
|
20
|
-
surface.getCanvas().clear(this.CanvasKit.TRANSPARENT);
|
21
|
-
return new JsiSkSurface(this.CanvasKit, surface, () => {
|
22
|
-
this.CanvasKit.Free(pixelPtr);
|
23
|
-
});
|
8
|
+
return new JsiSkSurface(this.CanvasKit, this.CanvasKit.MakeSurface(width, height));
|
24
9
|
}
|
25
10
|
MakeOffscreen(width, height) {
|
26
11
|
// OffscreenCanvas may be unvailable in some environments.
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"names":["Host","JsiSkSurface","JsiSkSurfaceFactory","constructor","CanvasKit","Make","width","height","
|
1
|
+
{"version":3,"names":["Host","JsiSkSurface","JsiSkSurfaceFactory","constructor","CanvasKit","Make","width","height","MakeSurface","MakeOffscreen","OC","globalThis","OffscreenCanvas","surface","undefined","offscreen","webglContext","GetWebGLContext","grContext","MakeWebGLContext","Error","MakeRenderTarget"],"sources":["JsiSkSurfaceFactory.ts"],"sourcesContent":["import type { CanvasKit, Surface } from \"canvaskit-wasm\";\n\nimport type { SurfaceFactory } from \"../types\";\n\nimport { Host } from \"./Host\";\nimport { JsiSkSurface } from \"./JsiSkSurface\";\n\nexport class JsiSkSurfaceFactory extends Host implements SurfaceFactory {\n constructor(CanvasKit: CanvasKit) {\n super(CanvasKit);\n }\n\n Make(width: number, height: number) {\n return new JsiSkSurface(\n this.CanvasKit,\n this.CanvasKit.MakeSurface(width, height)!\n );\n }\n\n MakeOffscreen(width: number, height: number) {\n // OffscreenCanvas may be unvailable in some environments.\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n const OC = (globalThis as any).OffscreenCanvas;\n let surface: Surface | null;\n if (OC === undefined) {\n return this.Make(width, height);\n } else {\n const offscreen = new OC(width, height);\n const webglContext = this.CanvasKit.GetWebGLContext(offscreen);\n const grContext = this.CanvasKit.MakeWebGLContext(webglContext);\n if (!grContext) {\n throw new Error(\"Could not make a graphics context\");\n }\n surface = this.CanvasKit.MakeRenderTarget(grContext, width, height);\n }\n if (!surface) {\n return null;\n }\n return new JsiSkSurface(this.CanvasKit, surface);\n }\n}\n"],"mappings":"AAIA,SAASA,IAAI,QAAQ,QAAQ;AAC7B,SAASC,YAAY,QAAQ,gBAAgB;AAE7C,OAAO,MAAMC,mBAAmB,SAASF,IAAI,CAA2B;EACtEG,WAAWA,CAACC,SAAoB,EAAE;IAChC,KAAK,CAACA,SAAS,CAAC;EAClB;EAEAC,IAAIA,CAACC,KAAa,EAAEC,MAAc,EAAE;IAClC,OAAO,IAAIN,YAAY,CACrB,IAAI,CAACG,SAAS,EACd,IAAI,CAACA,SAAS,CAACI,WAAW,CAACF,KAAK,EAAEC,MAAM,CAC1C,CAAC;EACH;EAEAE,aAAaA,CAACH,KAAa,EAAEC,MAAc,EAAE;IAC3C;IACA;IACA,MAAMG,EAAE,GAAIC,UAAU,CAASC,eAAe;IAC9C,IAAIC,OAAuB;IAC3B,IAAIH,EAAE,KAAKI,SAAS,EAAE;MACpB,OAAO,IAAI,CAACT,IAAI,CAACC,KAAK,EAAEC,MAAM,CAAC;IACjC,CAAC,MAAM;MACL,MAAMQ,SAAS,GAAG,IAAIL,EAAE,CAACJ,KAAK,EAAEC,MAAM,CAAC;MACvC,MAAMS,YAAY,GAAG,IAAI,CAACZ,SAAS,CAACa,eAAe,CAACF,SAAS,CAAC;MAC9D,MAAMG,SAAS,GAAG,IAAI,CAACd,SAAS,CAACe,gBAAgB,CAACH,YAAY,CAAC;MAC/D,IAAI,CAACE,SAAS,EAAE;QACd,MAAM,IAAIE,KAAK,CAAC,mCAAmC,CAAC;MACtD;MACAP,OAAO,GAAG,IAAI,CAACT,SAAS,CAACiB,gBAAgB,CAACH,SAAS,EAAEZ,KAAK,EAAEC,MAAM,CAAC;IACrE;IACA,IAAI,CAACM,OAAO,EAAE;MACZ,OAAO,IAAI;IACb;IACA,OAAO,IAAIZ,YAAY,CAAC,IAAI,CAACG,SAAS,EAAES,OAAO,CAAC;EAClD;AACF"}
|
@@ -29,6 +29,7 @@ import { JsiSkTypefaceFontProviderFactory } from "./JsiSkTypefaceFontProviderFac
|
|
29
29
|
import { JsiSkFontMgrFactory } from "./JsiSkFontMgrFactory";
|
30
30
|
import { JsiSkAnimatedImageFactory } from "./JsiSkAnimatedImageFactory";
|
31
31
|
import { JsiSkParagraphBuilderFactory } from "./JsiSkParagraphBuilderFactory";
|
32
|
+
import { JsiSkPlatformBufferFactory } from "./JsiSkPlatformBufferFactory";
|
32
33
|
export const JsiSkApi = CanvasKit => ({
|
33
34
|
Point: (x, y) => new JsiSkPoint(CanvasKit, Float32Array.of(x, y)),
|
34
35
|
RuntimeShaderBuilder: _ => {
|
@@ -72,6 +73,7 @@ export const JsiSkApi = CanvasKit => ({
|
|
72
73
|
Surface: new JsiSkSurfaceFactory(CanvasKit),
|
73
74
|
TypefaceFontProvider: new JsiSkTypefaceFontProviderFactory(CanvasKit),
|
74
75
|
FontMgr: new JsiSkFontMgrFactory(CanvasKit),
|
75
|
-
ParagraphBuilder: new JsiSkParagraphBuilderFactory(CanvasKit)
|
76
|
+
ParagraphBuilder: new JsiSkParagraphBuilderFactory(CanvasKit),
|
77
|
+
PlatformBuffer: new JsiSkPlatformBufferFactory(CanvasKit)
|
76
78
|
});
|
77
79
|
//# sourceMappingURL=JsiSkia.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"names":["JsiSkPoint","JsiSkPaint","JsiSkRect","Color","JsiSkSurfaceFactory","JsiSkRRect","JsiSkRSXform","JsiSkContourMeasureIter","JsiSkPictureRecorder","JsiSkPictureFactory","JsiSkPathFactory","JsiSkMatrix","JsiSkColorFilterFactory","JsiSkTypefaceFactory","JsiSkMaskFilterFactory","JsiSkRuntimeEffectFactory","JsiSkImageFilterFactory","JsiSkShaderFactory","JsiSkPathEffectFactory","JsiSkDataFactory","JsiSkImageFactory","JsiSkSVGFactory","JsiSkTextBlobFactory","JsiSkFont","MakeVertices","JsiSkPath","JsiSkTypeface","JsiSkTypefaceFontProviderFactory","JsiSkFontMgrFactory","JsiSkAnimatedImageFactory","JsiSkParagraphBuilderFactory","JsiSkApi","CanvasKit","Point","x","y","Float32Array","of","RuntimeShaderBuilder","_","Error","RRectXY","rect","rx","ry","RSXform","scos","ssin","tx","ty","RSXformFromRadians","scale","r","px","py","s","Math","sin","c","cos","ContourMeasureIter","path","forceClosed","resScale","fromValue","Paint","paint","setAntiAlias","PictureRecorder","Picture","Path","Matrix","matrix","identity","ColorFilter","Font","typeface","size","undefined","Typeface","MaskFilter","RuntimeEffect","ImageFilter","Shader","PathEffect","bind","Data","Image","AnimatedImage","SVG","TextBlob","XYWHRect","width","height","Surface","TypefaceFontProvider","FontMgr","ParagraphBuilder"],"sources":["JsiSkia.ts"],"sourcesContent":["import type { CanvasKit } from \"canvaskit-wasm\";\n\nimport type {\n SkContourMeasureIter,\n Skia,\n SkPath,\n SkRect,\n SkRuntimeEffect,\n SkRuntimeShaderBuilder,\n SkTypeface,\n} from \"../types\";\n\nimport { JsiSkPoint } from \"./JsiSkPoint\";\nimport { JsiSkPaint } from \"./JsiSkPaint\";\nimport { JsiSkRect } from \"./JsiSkRect\";\nimport { Color } from \"./JsiSkColor\";\nimport { JsiSkSurfaceFactory } from \"./JsiSkSurfaceFactory\";\nimport { JsiSkRRect } from \"./JsiSkRRect\";\nimport { JsiSkRSXform } from \"./JsiSkRSXform\";\nimport { JsiSkContourMeasureIter } from \"./JsiSkContourMeasureIter\";\nimport { JsiSkPictureRecorder } from \"./JsiSkPictureRecorder\";\nimport { JsiSkPictureFactory } from \"./JsiSkPictureFactory\";\nimport { JsiSkPathFactory } from \"./JsiSkPathFactory\";\nimport { JsiSkMatrix } from \"./JsiSkMatrix\";\nimport { JsiSkColorFilterFactory } from \"./JsiSkColorFilterFactory\";\nimport { JsiSkTypefaceFactory } from \"./JsiSkTypefaceFactory\";\nimport { JsiSkMaskFilterFactory } from \"./JsiSkMaskFilterFactory\";\nimport { JsiSkRuntimeEffectFactory } from \"./JsiSkRuntimeEffectFactory\";\nimport { JsiSkImageFilterFactory } from \"./JsiSkImageFilterFactory\";\nimport { JsiSkShaderFactory } from \"./JsiSkShaderFactory\";\nimport { JsiSkPathEffectFactory } from \"./JsiSkPathEffectFactory\";\nimport { JsiSkDataFactory } from \"./JsiSkDataFactory\";\nimport { JsiSkImageFactory } from \"./JsiSkImageFactory\";\nimport { JsiSkSVGFactory } from \"./JsiSkSVGFactory\";\nimport { JsiSkTextBlobFactory } from \"./JsiSkTextBlobFactory\";\nimport { JsiSkFont } from \"./JsiSkFont\";\nimport { MakeVertices } from \"./JsiSkVerticesFactory\";\nimport { JsiSkPath } from \"./JsiSkPath\";\nimport { JsiSkTypeface } from \"./JsiSkTypeface\";\nimport { JsiSkTypefaceFontProviderFactory } from \"./JsiSkTypefaceFontProviderFactory\";\nimport { JsiSkFontMgrFactory } from \"./JsiSkFontMgrFactory\";\nimport { JsiSkAnimatedImageFactory } from \"./JsiSkAnimatedImageFactory\";\nimport { JsiSkParagraphBuilderFactory } from \"./JsiSkParagraphBuilderFactory\";\n\nexport const JsiSkApi = (CanvasKit: CanvasKit): Skia => ({\n Point: (x: number, y: number) =>\n new JsiSkPoint(CanvasKit, Float32Array.of(x, y)),\n RuntimeShaderBuilder: (_: SkRuntimeEffect): SkRuntimeShaderBuilder => {\n throw new Error(\"Not implemented on React Native Web\");\n },\n RRectXY: (rect: SkRect, rx: number, ry: number) =>\n new JsiSkRRect(CanvasKit, rect, rx, ry),\n RSXform: (scos: number, ssin: number, tx: number, ty: number) =>\n new JsiSkRSXform(CanvasKit, Float32Array.of(scos, ssin, tx, ty)),\n RSXformFromRadians: (\n scale: number,\n r: number,\n tx: number,\n ty: number,\n px: number,\n py: number\n ) => {\n const s = Math.sin(r) * scale;\n const c = Math.cos(r) * scale;\n return new JsiSkRSXform(\n CanvasKit,\n Float32Array.of(c, s, tx - c * px + s * py, ty - s * px - c * py)\n );\n },\n Color,\n ContourMeasureIter: (\n path: SkPath,\n forceClosed: boolean,\n resScale: number\n ): SkContourMeasureIter =>\n new JsiSkContourMeasureIter(\n CanvasKit,\n new CanvasKit.ContourMeasureIter(\n JsiSkPath.fromValue(path),\n forceClosed,\n resScale\n )\n ),\n Paint: () => {\n const paint = new JsiSkPaint(CanvasKit, new CanvasKit.Paint());\n paint.setAntiAlias(true);\n return paint;\n },\n PictureRecorder: () =>\n new JsiSkPictureRecorder(CanvasKit, new CanvasKit.PictureRecorder()),\n Picture: new JsiSkPictureFactory(CanvasKit),\n Path: new JsiSkPathFactory(CanvasKit),\n Matrix: (matrix?: readonly number[]) =>\n new JsiSkMatrix(\n CanvasKit,\n matrix\n ? Float32Array.of(...matrix)\n : Float32Array.of(...CanvasKit.Matrix.identity())\n ),\n ColorFilter: new JsiSkColorFilterFactory(CanvasKit),\n Font: (typeface?: SkTypeface, size?: number) =>\n new JsiSkFont(\n CanvasKit,\n new CanvasKit.Font(\n typeface === undefined ? null : JsiSkTypeface.fromValue(typeface),\n size\n )\n ),\n Typeface: new JsiSkTypefaceFactory(CanvasKit),\n MaskFilter: new JsiSkMaskFilterFactory(CanvasKit),\n RuntimeEffect: new JsiSkRuntimeEffectFactory(CanvasKit),\n ImageFilter: new JsiSkImageFilterFactory(CanvasKit),\n Shader: new JsiSkShaderFactory(CanvasKit),\n PathEffect: new JsiSkPathEffectFactory(CanvasKit),\n MakeVertices: MakeVertices.bind(null, CanvasKit),\n Data: new JsiSkDataFactory(CanvasKit),\n Image: new JsiSkImageFactory(CanvasKit),\n AnimatedImage: new JsiSkAnimatedImageFactory(CanvasKit),\n SVG: new JsiSkSVGFactory(CanvasKit),\n TextBlob: new JsiSkTextBlobFactory(CanvasKit),\n XYWHRect: (x: number, y: number, width: number, height: number) => {\n return new JsiSkRect(CanvasKit, CanvasKit.XYWHRect(x, y, width, height));\n },\n Surface: new JsiSkSurfaceFactory(CanvasKit),\n TypefaceFontProvider: new JsiSkTypefaceFontProviderFactory(CanvasKit),\n FontMgr: new JsiSkFontMgrFactory(CanvasKit),\n ParagraphBuilder: new JsiSkParagraphBuilderFactory(CanvasKit),\n});\n"],"mappings":"AAYA,SAASA,UAAU,QAAQ,cAAc;AACzC,SAASC,UAAU,QAAQ,cAAc;AACzC,SAASC,SAAS,QAAQ,aAAa;AACvC,SAASC,KAAK,QAAQ,cAAc;AACpC,SAASC,mBAAmB,QAAQ,uBAAuB;AAC3D,SAASC,UAAU,QAAQ,cAAc;AACzC,SAASC,YAAY,QAAQ,gBAAgB;AAC7C,SAASC,uBAAuB,QAAQ,2BAA2B;AACnE,SAASC,oBAAoB,QAAQ,wBAAwB;AAC7D,SAASC,mBAAmB,QAAQ,uBAAuB;AAC3D,SAASC,gBAAgB,QAAQ,oBAAoB;AACrD,SAASC,WAAW,QAAQ,eAAe;AAC3C,SAASC,uBAAuB,QAAQ,2BAA2B;AACnE,SAASC,oBAAoB,QAAQ,wBAAwB;AAC7D,SAASC,sBAAsB,QAAQ,0BAA0B;AACjE,SAASC,yBAAyB,QAAQ,6BAA6B;AACvE,SAASC,uBAAuB,Q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C;EAC1E,CAAC;EACDC,OAAO,EAAE,IAAI1F,mBAAmB,CAAC4B,SAAS,CAAC;EAC3C+D,oBAAoB,EAAE,IAAIpE,gCAAgC,CAACK,SAAS,CAAC;EACrEgE,OAAO,EAAE,IAAIpE,mBAAmB,CAACI,SAAS,CAAC;EAC3CiE,gBAAgB,EAAE,IAAInE,4BAA4B,CAACE,SAAS;AAC9D,CAAC,CAAC"}
|
1
|
+
{"version":3,"names":["JsiSkPoint","JsiSkPaint","JsiSkRect","Color","JsiSkSurfaceFactory","JsiSkRRect","JsiSkRSXform","JsiSkContourMeasureIter","JsiSkPictureRecorder","JsiSkPictureFactory","JsiSkPathFactory","JsiSkMatrix","JsiSkColorFilterFactory","JsiSkTypefaceFactory","JsiSkMaskFilterFactory","JsiSkRuntimeEffectFactory","JsiSkImageFilterFactory","JsiSkShaderFactory","JsiSkPathEffectFactory","JsiSkDataFactory","JsiSkImageFactory","JsiSkSVGFactory","JsiSkTextBlobFactory","JsiSkFont","MakeVertices","JsiSkPath","JsiSkTypeface","JsiSkTypefaceFontProviderFactory","JsiSkFontMgrFactory","JsiSkAnimatedImageFactory","JsiSkParagraphBuilderFactory","JsiSkPlatformBufferFactory","JsiSkApi","CanvasKit","Point","x","y","Float32Array","of","RuntimeShaderBuilder","_","Error","RRectXY","rect","rx","ry","RSXform","scos","ssin","tx","ty","RSXformFromRadians","scale","r","px","py","s","Math","sin","c","cos","ContourMeasureIter","path","forceClosed","resScale","fromValue","Paint","paint","setAntiAlias","PictureRecorder","Picture","Path","Matrix","matrix","identity","ColorFilter","Font","typeface","size","undefined","Typeface","MaskFilter","RuntimeEffect","ImageFilter","Shader","PathEffect","bind","Data","Image","AnimatedImage","SVG","TextBlob","XYWHRect","width","height","Surface","TypefaceFontProvider","FontMgr","ParagraphBuilder","PlatformBuffer"],"sources":["JsiSkia.ts"],"sourcesContent":["import type { CanvasKit } from \"canvaskit-wasm\";\n\nimport type {\n SkContourMeasureIter,\n Skia,\n SkPath,\n SkRect,\n SkRuntimeEffect,\n SkRuntimeShaderBuilder,\n SkTypeface,\n} from \"../types\";\n\nimport { JsiSkPoint } from \"./JsiSkPoint\";\nimport { JsiSkPaint } from \"./JsiSkPaint\";\nimport { JsiSkRect } from \"./JsiSkRect\";\nimport { Color } from \"./JsiSkColor\";\nimport { JsiSkSurfaceFactory } from \"./JsiSkSurfaceFactory\";\nimport { JsiSkRRect } from \"./JsiSkRRect\";\nimport { JsiSkRSXform } from \"./JsiSkRSXform\";\nimport { JsiSkContourMeasureIter } from \"./JsiSkContourMeasureIter\";\nimport { JsiSkPictureRecorder } from \"./JsiSkPictureRecorder\";\nimport { JsiSkPictureFactory } from \"./JsiSkPictureFactory\";\nimport { JsiSkPathFactory } from \"./JsiSkPathFactory\";\nimport { JsiSkMatrix } from \"./JsiSkMatrix\";\nimport { JsiSkColorFilterFactory } from \"./JsiSkColorFilterFactory\";\nimport { JsiSkTypefaceFactory } from \"./JsiSkTypefaceFactory\";\nimport { JsiSkMaskFilterFactory } from \"./JsiSkMaskFilterFactory\";\nimport { JsiSkRuntimeEffectFactory } from \"./JsiSkRuntimeEffectFactory\";\nimport { JsiSkImageFilterFactory } from \"./JsiSkImageFilterFactory\";\nimport { JsiSkShaderFactory } from \"./JsiSkShaderFactory\";\nimport { JsiSkPathEffectFactory } from \"./JsiSkPathEffectFactory\";\nimport { JsiSkDataFactory } from \"./JsiSkDataFactory\";\nimport { JsiSkImageFactory } from \"./JsiSkImageFactory\";\nimport { JsiSkSVGFactory } from \"./JsiSkSVGFactory\";\nimport { JsiSkTextBlobFactory } from \"./JsiSkTextBlobFactory\";\nimport { JsiSkFont } from \"./JsiSkFont\";\nimport { MakeVertices } from \"./JsiSkVerticesFactory\";\nimport { JsiSkPath } from \"./JsiSkPath\";\nimport { JsiSkTypeface } from \"./JsiSkTypeface\";\nimport { JsiSkTypefaceFontProviderFactory } from \"./JsiSkTypefaceFontProviderFactory\";\nimport { JsiSkFontMgrFactory } from \"./JsiSkFontMgrFactory\";\nimport { JsiSkAnimatedImageFactory } from \"./JsiSkAnimatedImageFactory\";\nimport { JsiSkParagraphBuilderFactory } from \"./JsiSkParagraphBuilderFactory\";\nimport { JsiSkPlatformBufferFactory } from \"./JsiSkPlatformBufferFactory\";\n\nexport const JsiSkApi = (CanvasKit: CanvasKit): Skia => ({\n Point: (x: number, y: number) =>\n new JsiSkPoint(CanvasKit, Float32Array.of(x, y)),\n RuntimeShaderBuilder: (_: SkRuntimeEffect): SkRuntimeShaderBuilder => {\n throw new Error(\"Not implemented on React Native Web\");\n },\n RRectXY: (rect: SkRect, rx: number, ry: number) =>\n new JsiSkRRect(CanvasKit, rect, rx, ry),\n RSXform: (scos: number, ssin: number, tx: number, ty: number) =>\n new JsiSkRSXform(CanvasKit, Float32Array.of(scos, ssin, tx, ty)),\n RSXformFromRadians: (\n scale: number,\n r: number,\n tx: number,\n ty: number,\n px: number,\n py: number\n ) => {\n const s = Math.sin(r) * scale;\n const c = Math.cos(r) * scale;\n return new JsiSkRSXform(\n CanvasKit,\n Float32Array.of(c, s, tx - c * px + s * py, ty - s * px - c * py)\n );\n },\n Color,\n ContourMeasureIter: (\n path: SkPath,\n forceClosed: boolean,\n resScale: number\n ): SkContourMeasureIter =>\n new JsiSkContourMeasureIter(\n CanvasKit,\n new CanvasKit.ContourMeasureIter(\n JsiSkPath.fromValue(path),\n forceClosed,\n resScale\n )\n ),\n Paint: () => {\n const paint = new JsiSkPaint(CanvasKit, new CanvasKit.Paint());\n paint.setAntiAlias(true);\n return paint;\n },\n PictureRecorder: () =>\n new JsiSkPictureRecorder(CanvasKit, new CanvasKit.PictureRecorder()),\n Picture: new JsiSkPictureFactory(CanvasKit),\n Path: new JsiSkPathFactory(CanvasKit),\n Matrix: (matrix?: readonly number[]) =>\n new JsiSkMatrix(\n CanvasKit,\n matrix\n ? Float32Array.of(...matrix)\n : Float32Array.of(...CanvasKit.Matrix.identity())\n ),\n ColorFilter: new JsiSkColorFilterFactory(CanvasKit),\n Font: (typeface?: SkTypeface, size?: number) =>\n new JsiSkFont(\n CanvasKit,\n new CanvasKit.Font(\n typeface === undefined ? null : JsiSkTypeface.fromValue(typeface),\n size\n )\n ),\n Typeface: new JsiSkTypefaceFactory(CanvasKit),\n MaskFilter: new JsiSkMaskFilterFactory(CanvasKit),\n RuntimeEffect: new JsiSkRuntimeEffectFactory(CanvasKit),\n ImageFilter: new JsiSkImageFilterFactory(CanvasKit),\n Shader: new JsiSkShaderFactory(CanvasKit),\n PathEffect: new JsiSkPathEffectFactory(CanvasKit),\n MakeVertices: MakeVertices.bind(null, CanvasKit),\n Data: new JsiSkDataFactory(CanvasKit),\n Image: new JsiSkImageFactory(CanvasKit),\n AnimatedImage: new JsiSkAnimatedImageFactory(CanvasKit),\n SVG: new JsiSkSVGFactory(CanvasKit),\n TextBlob: new JsiSkTextBlobFactory(CanvasKit),\n XYWHRect: (x: number, y: number, width: number, height: number) => {\n return new JsiSkRect(CanvasKit, CanvasKit.XYWHRect(x, y, width, height));\n },\n Surface: new JsiSkSurfaceFactory(CanvasKit),\n TypefaceFontProvider: new JsiSkTypefaceFontProviderFactory(CanvasKit),\n FontMgr: new JsiSkFontMgrFactory(CanvasKit),\n ParagraphBuilder: new JsiSkParagraphBuilderFactory(CanvasKit),\n PlatformBuffer: new JsiSkPlatformBufferFactory(CanvasKit),\n});\n"],"mappings":"AAYA,SAASA,UAAU,QAAQ,cAAc;AACzC,SAASC,UAAU,QAAQ,cAAc;AACzC,SAASC,SAAS,QAAQ,aAAa;AACvC,SAASC,KAAK,QAAQ,cAAc;AACpC,SAASC,mBAAmB,QAAQ,uBAAuB;AAC3D,SAASC,UAAU,QAAQ,cAAc;AACzC,SAASC,YAAY,QAAQ,gBAAgB;AAC7C,SAASC,uBAAuB,QAAQ,2BAA2B;AACnE,SAASC,oBAAoB,QAAQ,wBAAwB;AAC7D,SAASC,mBAAmB,QAAQ,uBAAuB;AAC3D,SAASC,gBAAgB,QAAQ,oBAAoB;AACrD,SAASC,WAAW,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EAC7C2D,QAAQ,EAAEA,CAACzD,CAAS,EAAEC,CAAS,EAAEyD,KAAa,EAAEC,MAAc,KAAK;IACjE,OAAO,IAAI5F,SAAS,CAAC+B,SAAS,EAAEA,SAAS,CAAC2D,QAAQ,CAACzD,CAAC,EAAEC,CAAC,EAAEyD,KAAK,EAAEC,MAAM,CAAC,CAAC;EAC1E,CAAC;EACDC,OAAO,EAAE,IAAI3F,mBAAmB,CAAC6B,SAAS,CAAC;EAC3C+D,oBAAoB,EAAE,IAAIrE,gCAAgC,CAACM,SAAS,CAAC;EACrEgE,OAAO,EAAE,IAAIrE,mBAAmB,CAACK,SAAS,CAAC;EAC3CiE,gBAAgB,EAAE,IAAIpE,4BAA4B,CAACG,SAAS,CAAC;EAC7DkE,cAAc,EAAE,IAAIpE,0BAA0B,CAACE,SAAS;AAC1D,CAAC,CAAC"}
|
@@ -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
|
}
|
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.
|
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();
|
@@ -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";
|