@shopify/react-native-skia 1.2.0 → 1.2.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (96) hide show
  1. package/android/cpp/rnskia-android/RNSkAndroidPlatformContext.h +3 -3
  2. package/cpp/api/JsiNativeBuffer.h +43 -0
  3. package/cpp/api/JsiSkApi.h +3 -3
  4. package/cpp/api/JsiSkImageFactory.h +3 -3
  5. package/cpp/rnskia/RNSkPlatformContext.h +5 -5
  6. package/ios/RNSkia-iOS/RNSkiOSPlatformContext.h +3 -3
  7. package/ios/RNSkia-iOS/RNSkiOSPlatformContext.mm +69 -88
  8. package/ios/RNSkia-iOS/SkiaCVPixelBufferUtils.h +84 -0
  9. package/ios/RNSkia-iOS/SkiaCVPixelBufferUtils.mm +159 -0
  10. package/ios/RNSkia-iOS/SkiaMetalSurfaceFactory.h +2 -1
  11. package/ios/RNSkia-iOS/SkiaMetalSurfaceFactory.mm +30 -6
  12. package/lib/commonjs/skia/types/Image/ImageFactory.d.ts +8 -15
  13. package/lib/commonjs/skia/types/Image/ImageFactory.js +1 -10
  14. package/lib/commonjs/skia/types/Image/ImageFactory.js.map +1 -1
  15. package/lib/commonjs/skia/types/NativeBuffer/NativeBufferFactory.d.ts +18 -0
  16. package/lib/commonjs/skia/types/NativeBuffer/NativeBufferFactory.js +13 -0
  17. package/lib/commonjs/skia/types/NativeBuffer/NativeBufferFactory.js.map +1 -0
  18. package/lib/commonjs/skia/types/NativeBuffer/index.d.ts +1 -0
  19. package/lib/commonjs/skia/types/NativeBuffer/index.js +17 -0
  20. package/lib/commonjs/skia/types/NativeBuffer/index.js.map +1 -0
  21. package/lib/commonjs/skia/types/Skia.d.ts +2 -2
  22. package/lib/commonjs/skia/types/Skia.js.map +1 -1
  23. package/lib/commonjs/skia/types/index.d.ts +1 -1
  24. package/lib/commonjs/skia/types/index.js +4 -4
  25. package/lib/commonjs/skia/types/index.js.map +1 -1
  26. package/lib/commonjs/skia/web/JsiSkImageFactory.d.ts +3 -2
  27. package/lib/commonjs/skia/web/JsiSkImageFactory.js +18 -2
  28. package/lib/commonjs/skia/web/JsiSkImageFactory.js.map +1 -1
  29. package/lib/commonjs/skia/web/JsiSkNativeBufferFactory.d.ts +8 -0
  30. package/lib/commonjs/skia/web/JsiSkNativeBufferFactory.js +29 -0
  31. package/lib/commonjs/skia/web/JsiSkNativeBufferFactory.js.map +1 -0
  32. package/lib/commonjs/skia/web/JsiSkia.js +2 -2
  33. package/lib/commonjs/skia/web/JsiSkia.js.map +1 -1
  34. package/lib/module/skia/types/Image/ImageFactory.d.ts +8 -15
  35. package/lib/module/skia/types/Image/ImageFactory.js +1 -10
  36. package/lib/module/skia/types/Image/ImageFactory.js.map +1 -1
  37. package/lib/module/skia/types/NativeBuffer/NativeBufferFactory.d.ts +18 -0
  38. package/lib/module/skia/types/NativeBuffer/NativeBufferFactory.js +4 -0
  39. package/lib/module/skia/types/NativeBuffer/NativeBufferFactory.js.map +1 -0
  40. package/lib/module/skia/types/NativeBuffer/index.d.ts +1 -0
  41. package/lib/module/skia/types/NativeBuffer/index.js +2 -0
  42. package/lib/module/skia/types/NativeBuffer/index.js.map +1 -0
  43. package/lib/module/skia/types/Skia.d.ts +2 -2
  44. package/lib/module/skia/types/Skia.js.map +1 -1
  45. package/lib/module/skia/types/index.d.ts +1 -1
  46. package/lib/module/skia/types/index.js +1 -1
  47. package/lib/module/skia/types/index.js.map +1 -1
  48. package/lib/module/skia/web/JsiSkImageFactory.d.ts +3 -2
  49. package/lib/module/skia/web/JsiSkImageFactory.js +18 -2
  50. package/lib/module/skia/web/JsiSkImageFactory.js.map +1 -1
  51. package/lib/module/skia/web/JsiSkNativeBufferFactory.d.ts +8 -0
  52. package/lib/module/skia/web/JsiSkNativeBufferFactory.js +22 -0
  53. package/lib/module/skia/web/JsiSkNativeBufferFactory.js.map +1 -0
  54. package/lib/module/skia/web/JsiSkia.js +2 -2
  55. package/lib/module/skia/web/JsiSkia.js.map +1 -1
  56. package/lib/typescript/src/skia/types/Image/ImageFactory.d.ts +8 -15
  57. package/lib/typescript/src/skia/types/NativeBuffer/NativeBufferFactory.d.ts +18 -0
  58. package/lib/typescript/src/skia/types/NativeBuffer/index.d.ts +1 -0
  59. package/lib/typescript/src/skia/types/Skia.d.ts +2 -2
  60. package/lib/typescript/src/skia/types/index.d.ts +1 -1
  61. package/lib/typescript/src/skia/web/JsiSkImageFactory.d.ts +3 -2
  62. package/lib/typescript/src/skia/web/JsiSkNativeBufferFactory.d.ts +8 -0
  63. package/package.json +1 -1
  64. package/src/skia/types/Image/ImageFactory.ts +7 -23
  65. package/src/skia/types/NativeBuffer/NativeBufferFactory.ts +38 -0
  66. package/src/skia/types/NativeBuffer/index.ts +1 -0
  67. package/src/skia/types/Skia.ts +2 -2
  68. package/src/skia/types/index.ts +1 -1
  69. package/src/skia/web/JsiSkImageFactory.ts +28 -6
  70. package/src/skia/web/JsiSkNativeBufferFactory.ts +35 -0
  71. package/src/skia/web/JsiSkia.ts +2 -2
  72. package/cpp/api/JsiPlatformBuffer.h +0 -51
  73. package/lib/commonjs/skia/types/PlatformBuffer/PlatformBufferFactory.d.ts +0 -12
  74. package/lib/commonjs/skia/types/PlatformBuffer/PlatformBufferFactory.js +0 -6
  75. package/lib/commonjs/skia/types/PlatformBuffer/PlatformBufferFactory.js.map +0 -1
  76. package/lib/commonjs/skia/types/PlatformBuffer/index.d.ts +0 -1
  77. package/lib/commonjs/skia/types/PlatformBuffer/index.js +0 -17
  78. package/lib/commonjs/skia/types/PlatformBuffer/index.js.map +0 -1
  79. package/lib/commonjs/skia/web/JsiSkPlatformBufferFactory.d.ts +0 -8
  80. package/lib/commonjs/skia/web/JsiSkPlatformBufferFactory.js +0 -20
  81. package/lib/commonjs/skia/web/JsiSkPlatformBufferFactory.js.map +0 -1
  82. package/lib/module/skia/types/PlatformBuffer/PlatformBufferFactory.d.ts +0 -12
  83. package/lib/module/skia/types/PlatformBuffer/PlatformBufferFactory.js +0 -2
  84. package/lib/module/skia/types/PlatformBuffer/PlatformBufferFactory.js.map +0 -1
  85. package/lib/module/skia/types/PlatformBuffer/index.d.ts +0 -1
  86. package/lib/module/skia/types/PlatformBuffer/index.js +0 -2
  87. package/lib/module/skia/types/PlatformBuffer/index.js.map +0 -1
  88. package/lib/module/skia/web/JsiSkPlatformBufferFactory.d.ts +0 -8
  89. package/lib/module/skia/web/JsiSkPlatformBufferFactory.js +0 -13
  90. package/lib/module/skia/web/JsiSkPlatformBufferFactory.js.map +0 -1
  91. package/lib/typescript/src/skia/types/PlatformBuffer/PlatformBufferFactory.d.ts +0 -12
  92. package/lib/typescript/src/skia/types/PlatformBuffer/index.d.ts +0 -1
  93. package/lib/typescript/src/skia/web/JsiSkPlatformBufferFactory.d.ts +0 -8
  94. package/src/skia/types/PlatformBuffer/PlatformBufferFactory.ts +0 -14
  95. package/src/skia/types/PlatformBuffer/index.ts +0 -1
  96. package/src/skia/web/JsiSkPlatformBufferFactory.ts +0 -22
@@ -0,0 +1,18 @@
1
+ import type { SkImage } from "../Image";
2
+ export type NativeBuffer<T extends bigint | ArrayBuffer | CanvasImageSource | unknown = unknown> = T;
3
+ export type NativeBufferAddr = NativeBuffer<bigint>;
4
+ export type NativeBufferWeb = NativeBuffer<CanvasImageSource>;
5
+ export type NativeBufferNode = NativeBuffer<ArrayBuffer>;
6
+ export declare const isNativeBufferAddr: (buffer: NativeBuffer) => buffer is bigint;
7
+ export declare const isNativeBufferWeb: (buffer: NativeBuffer) => buffer is CanvasImageSource;
8
+ export declare const isNativeBufferNode: (buffer: NativeBuffer) => buffer is ArrayBuffer;
9
+ export interface NativeBufferFactory {
10
+ /**
11
+ * Copy pixels to a platform buffer. (for testing purposes)
12
+ */
13
+ MakeFromImage: (image: SkImage) => NativeBuffer;
14
+ /**
15
+ * Release a platform buffer that was created with `MakeFromImage`.
16
+ */
17
+ Release: (platformBuffer: NativeBuffer) => void;
18
+ }
@@ -0,0 +1,4 @@
1
+ export const isNativeBufferAddr = buffer => buffer instanceof BigInt;
2
+ export const isNativeBufferWeb = buffer => buffer instanceof HTMLVideoElement || buffer instanceof HTMLCanvasElement || buffer instanceof ImageBitmap || buffer instanceof OffscreenCanvas || buffer instanceof VideoFrame || buffer instanceof HTMLImageElement || buffer instanceof SVGImageElement;
3
+ export const isNativeBufferNode = buffer => buffer instanceof ArrayBuffer;
4
+ //# sourceMappingURL=NativeBufferFactory.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["isNativeBufferAddr","buffer","BigInt","isNativeBufferWeb","HTMLVideoElement","HTMLCanvasElement","ImageBitmap","OffscreenCanvas","VideoFrame","HTMLImageElement","SVGImageElement","isNativeBufferNode","ArrayBuffer"],"sources":["NativeBufferFactory.ts"],"sourcesContent":["import type { SkImage } from \"../Image\";\n\nexport type NativeBuffer<\n T extends bigint | ArrayBuffer | CanvasImageSource | unknown = unknown\n> = T;\n\nexport type NativeBufferAddr = NativeBuffer<bigint>;\nexport type NativeBufferWeb = NativeBuffer<CanvasImageSource>;\nexport type NativeBufferNode = NativeBuffer<ArrayBuffer>;\n\nexport const isNativeBufferAddr = (\n buffer: NativeBuffer\n): buffer is NativeBufferAddr => buffer instanceof BigInt;\nexport const isNativeBufferWeb = (\n buffer: NativeBuffer\n): buffer is NativeBufferWeb =>\n buffer instanceof HTMLVideoElement ||\n buffer instanceof HTMLCanvasElement ||\n buffer instanceof ImageBitmap ||\n buffer instanceof OffscreenCanvas ||\n buffer instanceof VideoFrame ||\n buffer instanceof HTMLImageElement ||\n buffer instanceof SVGImageElement;\n\nexport const isNativeBufferNode = (\n buffer: NativeBuffer\n): buffer is NativeBufferNode => buffer instanceof ArrayBuffer;\n\nexport interface NativeBufferFactory {\n /**\n * Copy pixels to a platform buffer. (for testing purposes)\n */\n MakeFromImage: (image: SkImage) => NativeBuffer;\n /**\n * Release a platform buffer that was created with `MakeFromImage`.\n */\n Release: (platformBuffer: NativeBuffer) => void;\n}\n"],"mappings":"AAUA,OAAO,MAAMA,kBAAkB,GAC7BC,MAAoB,IACWA,MAAM,YAAYC,MAAM;AACzD,OAAO,MAAMC,iBAAiB,GAC5BF,MAAoB,IAEpBA,MAAM,YAAYG,gBAAgB,IAClCH,MAAM,YAAYI,iBAAiB,IACnCJ,MAAM,YAAYK,WAAW,IAC7BL,MAAM,YAAYM,eAAe,IACjCN,MAAM,YAAYO,UAAU,IAC5BP,MAAM,YAAYQ,gBAAgB,IAClCR,MAAM,YAAYS,eAAe;AAEnC,OAAO,MAAMC,kBAAkB,GAC7BV,MAAoB,IACWA,MAAM,YAAYW,WAAW"}
@@ -0,0 +1 @@
1
+ export * from "./NativeBufferFactory";
@@ -0,0 +1,2 @@
1
+ export * from "./NativeBufferFactory";
2
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":[],"sources":["index.ts"],"sourcesContent":["export * from \"./NativeBufferFactory\";\n"],"mappings":"AAAA,cAAc,uBAAuB"}
@@ -26,7 +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
+ import type { NativeBufferFactory } from "./NativeBuffer";
30
30
  /**
31
31
  * Declares the interface for the native Skia API
32
32
  */
@@ -72,5 +72,5 @@ export interface Skia {
72
72
  TextBlob: TextBlobFactory;
73
73
  Surface: SurfaceFactory;
74
74
  ParagraphBuilder: ParagraphBuilderFactory;
75
- PlatformBuffer: PlatformBufferFactory;
75
+ NativeBuffer: NativeBufferFactory;
76
76
  }
@@ -1 +1 @@
1
- {"version":3,"names":[],"sources":["Skia.ts"],"sourcesContent":["import type { ImageFilterFactory } from \"./ImageFilter\";\nimport type { PathFactory } from \"./Path\";\nimport type { ColorFilterFactory } from \"./ColorFilter\";\nimport type { SkFont, FontMgrFactory } from \"./Font\";\nimport type { SkTypeface, TypefaceFactory } from \"./Typeface\";\nimport type { ImageFactory } from \"./Image\";\nimport type { MaskFilterFactory } from \"./MaskFilter\";\nimport type { SkPaint } from \"./Paint\";\nimport type { SkHostRect, SkRect } from \"./Rect\";\nimport type { SkRRect } from \"./RRect\";\nimport type {\n RuntimeEffectFactory,\n SkRuntimeEffect,\n SkRuntimeShaderBuilder,\n} from \"./RuntimeEffect\";\nimport type { ShaderFactory } from \"./Shader\";\nimport type { SkMatrix } from \"./Matrix\";\nimport type { PathEffectFactory } from \"./PathEffect\";\nimport type { SkPoint } from \"./Point\";\nimport type { SkVertices, VertexMode } from \"./Vertices/Vertices\";\nimport type { DataFactory } from \"./Data\";\nimport type { SVGFactory } from \"./SVG\";\nimport type { TextBlobFactory } from \"./TextBlob\";\nimport type { SurfaceFactory } from \"./Surface\";\nimport type { SkRSXform } from \"./RSXform\";\nimport type { SkPath } from \"./Path/Path\";\nimport type { SkContourMeasureIter } from \"./ContourMeasure\";\nimport type { PictureFactory, SkPictureRecorder } from \"./Picture\";\nimport type { Color, SkColor } from \"./Color\";\nimport type { TypefaceFontProviderFactory } from \"./Paragraph/TypefaceFontProviderFactory\";\nimport type { AnimatedImageFactory } from \"./AnimatedImage\";\nimport type { ParagraphBuilderFactory } from \"./Paragraph/ParagraphBuilder\";\nimport type { PlatformBufferFactory } from \"./PlatformBuffer\";\n\n/**\n * Declares the interface for the native Skia API\n */\nexport interface Skia {\n Point: (x: number, y: number) => SkPoint;\n XYWHRect: (x: number, y: number, width: number, height: number) => SkHostRect;\n RuntimeShaderBuilder: (rt: SkRuntimeEffect) => SkRuntimeShaderBuilder;\n RRectXY: (rect: SkRect, rx: number, ry: number) => SkRRect;\n RSXform: (scos: number, ssin: number, tx: number, ty: number) => SkRSXform;\n RSXformFromRadians: (\n scale: number,\n radians: number,\n tx: number,\n ty: number,\n px: number,\n py: number\n ) => SkRSXform;\n Color: (color: Color) => SkColor;\n ContourMeasureIter: (\n path: SkPath,\n forceClosed: boolean,\n resScale: number\n ) => SkContourMeasureIter;\n Paint: () => SkPaint;\n PictureRecorder: () => SkPictureRecorder;\n Picture: PictureFactory;\n Path: PathFactory;\n Matrix: (matrix?: readonly number[]) => SkMatrix;\n ColorFilter: ColorFilterFactory;\n Font: (typeface?: SkTypeface, size?: number) => SkFont;\n Typeface: TypefaceFactory;\n TypefaceFontProvider: TypefaceFontProviderFactory;\n FontMgr: FontMgrFactory;\n MaskFilter: MaskFilterFactory;\n RuntimeEffect: RuntimeEffectFactory;\n ImageFilter: ImageFilterFactory;\n Shader: ShaderFactory;\n PathEffect: PathEffectFactory;\n /**\n * Returns an Vertices based on the given positions and optional parameters.\n * See SkVertices.h (especially the Builder) for more details.\n * @param mode\n * @param positions\n * @param textureCoordinates\n * @param colors - either a list of int colors or a flattened color array.\n * @param indices\n * @param isVolatile\n */\n MakeVertices(\n mode: VertexMode,\n positions: SkPoint[],\n textureCoordinates?: SkPoint[] | null,\n colors?: SkColor[],\n indices?: number[] | null,\n isVolatile?: boolean\n ): SkVertices;\n Data: DataFactory;\n Image: ImageFactory;\n AnimatedImage: AnimatedImageFactory;\n SVG: SVGFactory;\n TextBlob: TextBlobFactory;\n Surface: SurfaceFactory;\n ParagraphBuilder: ParagraphBuilderFactory;\n PlatformBuffer: PlatformBufferFactory;\n}\n"],"mappings":""}
1
+ {"version":3,"names":[],"sources":["Skia.ts"],"sourcesContent":["import type { ImageFilterFactory } from \"./ImageFilter\";\nimport type { PathFactory } from \"./Path\";\nimport type { ColorFilterFactory } from \"./ColorFilter\";\nimport type { SkFont, FontMgrFactory } from \"./Font\";\nimport type { SkTypeface, TypefaceFactory } from \"./Typeface\";\nimport type { ImageFactory } from \"./Image\";\nimport type { MaskFilterFactory } from \"./MaskFilter\";\nimport type { SkPaint } from \"./Paint\";\nimport type { SkHostRect, SkRect } from \"./Rect\";\nimport type { SkRRect } from \"./RRect\";\nimport type {\n RuntimeEffectFactory,\n SkRuntimeEffect,\n SkRuntimeShaderBuilder,\n} from \"./RuntimeEffect\";\nimport type { ShaderFactory } from \"./Shader\";\nimport type { SkMatrix } from \"./Matrix\";\nimport type { PathEffectFactory } from \"./PathEffect\";\nimport type { SkPoint } from \"./Point\";\nimport type { SkVertices, VertexMode } from \"./Vertices/Vertices\";\nimport type { DataFactory } from \"./Data\";\nimport type { SVGFactory } from \"./SVG\";\nimport type { TextBlobFactory } from \"./TextBlob\";\nimport type { SurfaceFactory } from \"./Surface\";\nimport type { SkRSXform } from \"./RSXform\";\nimport type { SkPath } from \"./Path/Path\";\nimport type { SkContourMeasureIter } from \"./ContourMeasure\";\nimport type { PictureFactory, SkPictureRecorder } from \"./Picture\";\nimport type { Color, SkColor } from \"./Color\";\nimport type { TypefaceFontProviderFactory } from \"./Paragraph/TypefaceFontProviderFactory\";\nimport type { AnimatedImageFactory } from \"./AnimatedImage\";\nimport type { ParagraphBuilderFactory } from \"./Paragraph/ParagraphBuilder\";\nimport type { NativeBufferFactory } from \"./NativeBuffer\";\n\n/**\n * Declares the interface for the native Skia API\n */\nexport interface Skia {\n Point: (x: number, y: number) => SkPoint;\n XYWHRect: (x: number, y: number, width: number, height: number) => SkHostRect;\n RuntimeShaderBuilder: (rt: SkRuntimeEffect) => SkRuntimeShaderBuilder;\n RRectXY: (rect: SkRect, rx: number, ry: number) => SkRRect;\n RSXform: (scos: number, ssin: number, tx: number, ty: number) => SkRSXform;\n RSXformFromRadians: (\n scale: number,\n radians: number,\n tx: number,\n ty: number,\n px: number,\n py: number\n ) => SkRSXform;\n Color: (color: Color) => SkColor;\n ContourMeasureIter: (\n path: SkPath,\n forceClosed: boolean,\n resScale: number\n ) => SkContourMeasureIter;\n Paint: () => SkPaint;\n PictureRecorder: () => SkPictureRecorder;\n Picture: PictureFactory;\n Path: PathFactory;\n Matrix: (matrix?: readonly number[]) => SkMatrix;\n ColorFilter: ColorFilterFactory;\n Font: (typeface?: SkTypeface, size?: number) => SkFont;\n Typeface: TypefaceFactory;\n TypefaceFontProvider: TypefaceFontProviderFactory;\n FontMgr: FontMgrFactory;\n MaskFilter: MaskFilterFactory;\n RuntimeEffect: RuntimeEffectFactory;\n ImageFilter: ImageFilterFactory;\n Shader: ShaderFactory;\n PathEffect: PathEffectFactory;\n /**\n * Returns an Vertices based on the given positions and optional parameters.\n * See SkVertices.h (especially the Builder) for more details.\n * @param mode\n * @param positions\n * @param textureCoordinates\n * @param colors - either a list of int colors or a flattened color array.\n * @param indices\n * @param isVolatile\n */\n MakeVertices(\n mode: VertexMode,\n positions: SkPoint[],\n textureCoordinates?: SkPoint[] | null,\n colors?: SkColor[],\n indices?: number[] | null,\n isVolatile?: boolean\n ): SkVertices;\n Data: DataFactory;\n Image: ImageFactory;\n AnimatedImage: AnimatedImageFactory;\n SVG: SVGFactory;\n TextBlob: TextBlobFactory;\n Surface: SurfaceFactory;\n ParagraphBuilder: ParagraphBuilderFactory;\n NativeBuffer: NativeBufferFactory;\n}\n"],"mappings":""}
@@ -29,4 +29,4 @@ export * from "./TextBlob";
29
29
  export * from "./Size";
30
30
  export * from "./Paragraph";
31
31
  export * from "./Matrix4";
32
- export * from "./PlatformBuffer";
32
+ export * from "./NativeBuffer";
@@ -29,5 +29,5 @@ export * from "./TextBlob";
29
29
  export * from "./Size";
30
30
  export * from "./Paragraph";
31
31
  export * from "./Matrix4";
32
- export * from "./PlatformBuffer";
32
+ export * from "./NativeBuffer";
33
33
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"names":[],"sources":["index.ts"],"sourcesContent":["export * from \"./Picture\";\nexport * from \"./Data\";\nexport * from \"./SVG\";\nexport * from \"./Surface\";\nexport * from \"./Vertices\";\nexport * from \"./RuntimeEffect\";\nexport * from \"./Shader\";\nexport * from \"./Image\";\nexport * from \"./AnimatedImage\";\nexport * from \"./ColorFilter\";\nexport * from \"./ImageFilter\";\nexport * from \"./Font\";\nexport * from \"./Typeface\";\nexport * from \"./Paint\";\nexport * from \"./Path\";\nexport * from \"./Color\";\nexport * from \"./Canvas\";\nexport * from \"./ContourMeasure\";\nexport * from \"./MaskFilter\";\nexport * from \"./Matrix\";\nexport * from \"./PathEffect\";\nexport * from \"./Point\";\nexport * from \"./Rect\";\nexport * from \"./RRect\";\nexport * from \"./RSXform\";\nexport * from \"./JsiInstance\";\nexport * from \"./Skia\";\nexport * from \"./TextBlob\";\nexport * from \"./Size\";\nexport * from \"./Paragraph\";\nexport * from \"./Matrix4\";\nexport * from \"./PlatformBuffer\";\n"],"mappings":"AAAA,cAAc,WAAW;AACzB,cAAc,QAAQ;AACtB,cAAc,OAAO;AACrB,cAAc,WAAW;AACzB,cAAc,YAAY;AAC1B,cAAc,iBAAiB;AAC/B,cAAc,UAAU;AACxB,cAAc,SAAS;AACvB,cAAc,iBAAiB;AAC/B,cAAc,eAAe;AAC7B,cAAc,eAAe;AAC7B,cAAc,QAAQ;AACtB,cAAc,YAAY;AAC1B,cAAc,SAAS;AACvB,cAAc,QAAQ;AACtB,cAAc,SAAS;AACvB,cAAc,UAAU;AACxB,cAAc,kBAAkB;AAChC,cAAc,cAAc;AAC5B,cAAc,UAAU;AACxB,cAAc,cAAc;AAC5B,cAAc,SAAS;AACvB,cAAc,QAAQ;AACtB,cAAc,SAAS;AACvB,cAAc,WAAW;AACzB,cAAc,eAAe;AAC7B,cAAc,QAAQ;AACtB,cAAc,YAAY;AAC1B,cAAc,QAAQ;AACtB,cAAc,aAAa;AAC3B,cAAc,WAAW;AACzB,cAAc,kBAAkB"}
1
+ {"version":3,"names":[],"sources":["index.ts"],"sourcesContent":["export * from \"./Picture\";\nexport * from \"./Data\";\nexport * from \"./SVG\";\nexport * from \"./Surface\";\nexport * from \"./Vertices\";\nexport * from \"./RuntimeEffect\";\nexport * from \"./Shader\";\nexport * from \"./Image\";\nexport * from \"./AnimatedImage\";\nexport * from \"./ColorFilter\";\nexport * from \"./ImageFilter\";\nexport * from \"./Font\";\nexport * from \"./Typeface\";\nexport * from \"./Paint\";\nexport * from \"./Path\";\nexport * from \"./Color\";\nexport * from \"./Canvas\";\nexport * from \"./ContourMeasure\";\nexport * from \"./MaskFilter\";\nexport * from \"./Matrix\";\nexport * from \"./PathEffect\";\nexport * from \"./Point\";\nexport * from \"./Rect\";\nexport * from \"./RRect\";\nexport * from \"./RSXform\";\nexport * from \"./JsiInstance\";\nexport * from \"./Skia\";\nexport * from \"./TextBlob\";\nexport * from \"./Size\";\nexport * from \"./Paragraph\";\nexport * from \"./Matrix4\";\nexport * from \"./NativeBuffer\";\n"],"mappings":"AAAA,cAAc,WAAW;AACzB,cAAc,QAAQ;AACtB,cAAc,OAAO;AACrB,cAAc,WAAW;AACzB,cAAc,YAAY;AAC1B,cAAc,iBAAiB;AAC/B,cAAc,UAAU;AACxB,cAAc,SAAS;AACvB,cAAc,iBAAiB;AAC/B,cAAc,eAAe;AAC7B,cAAc,eAAe;AAC7B,cAAc,QAAQ;AACtB,cAAc,YAAY;AAC1B,cAAc,SAAS;AACvB,cAAc,QAAQ;AACtB,cAAc,SAAS;AACvB,cAAc,UAAU;AACxB,cAAc,kBAAkB;AAChC,cAAc,cAAc;AAC5B,cAAc,UAAU;AACxB,cAAc,cAAc;AAC5B,cAAc,SAAS;AACvB,cAAc,QAAQ;AACtB,cAAc,SAAS;AACvB,cAAc,WAAW;AACzB,cAAc,eAAe;AAC7B,cAAc,QAAQ;AACtB,cAAc,YAAY;AAC1B,cAAc,QAAQ;AACtB,cAAc,aAAa;AAC3B,cAAc,WAAW;AACzB,cAAc,gBAAgB"}
@@ -1,11 +1,12 @@
1
1
  import type { CanvasKit } from "canvaskit-wasm";
2
- import type { SkData, ImageInfo, SkImage, PlatformBuffer, ImageFactory } from "../types";
2
+ import type { SkData, ImageInfo, SkImage, NativeBuffer, ImageFactory } from "../types";
3
3
  import { Host } from "./Host";
4
4
  import { JsiSkImage } from "./JsiSkImage";
5
+ import type { JsiSkSurface } from "./JsiSkSurface";
5
6
  export declare class JsiSkImageFactory extends Host implements ImageFactory {
6
7
  constructor(CanvasKit: CanvasKit);
7
8
  MakeImageFromViewTag(viewTag: number): Promise<SkImage | null>;
8
- MakeImageFromPlatformBuffer(_platformBuffer: PlatformBuffer): SkImage;
9
+ MakeImageFromNativeBuffer(buffer: NativeBuffer, surface?: JsiSkSurface, image?: JsiSkImage): JsiSkImage;
9
10
  MakeImageFromEncoded(encoded: SkData): JsiSkImage | null;
10
11
  MakeImage(info: ImageInfo, data: SkData, bytesPerRow: number): JsiSkImage | null;
11
12
  }
@@ -1,3 +1,4 @@
1
+ import { isNativeBufferWeb } from "../types";
1
2
  import { Host, getEnum } from "./Host";
2
3
  import { JsiSkImage } from "./JsiSkImage";
3
4
  import { JsiSkData } from "./JsiSkData";
@@ -11,8 +12,23 @@ export class JsiSkImageFactory extends Host {
11
12
  console.log(view);
12
13
  return Promise.resolve(null);
13
14
  }
14
- MakeImageFromPlatformBuffer(_platformBuffer) {
15
- throw new Error("MakeImageFromPlatformBuffer() is only available on iOS and Android!");
15
+ MakeImageFromNativeBuffer(buffer, surface, image) {
16
+ if (!isNativeBufferWeb(buffer)) {
17
+ throw new Error("Invalid NativeBuffer");
18
+ }
19
+ if (!surface) {
20
+ // TODO: this is way to slow
21
+ const img = this.CanvasKit.MakeImageFromCanvasImageSource(buffer);
22
+ return new JsiSkImage(this.CanvasKit, img);
23
+ } else if (!image) {
24
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
25
+ const img = surface.makeImageFromTextureSource(buffer);
26
+ return new JsiSkImage(this.CanvasKit, img);
27
+ } else {
28
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
29
+ const img = surface.updateTextureFromSource(image, buffer);
30
+ return new JsiSkImage(this.CanvasKit, img);
31
+ }
16
32
  }
17
33
  MakeImageFromEncoded(encoded) {
18
34
  const image = this.CanvasKit.MakeImageFromEncoded(JsiSkData.fromValue(encoded));
@@ -1 +1 @@
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"],"mappings":"AAUA,SAASA,IAAI,EAAEC,OAAO,QAAQ,QAAQ;AACtC,SAASC,UAAU,QAAQ,cAAc;AACzC,SAASC,SAAS,QAAQ,aAAa;AAEvC,OAAO,MAAMC,iBAAiB,SAAS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B,UAAU,CAAC,IAAI,CAACI,SAAS,EAAEa,KAAK,CAAC;EAC9C;AACF"}
1
+ {"version":3,"names":["isNativeBufferWeb","Host","getEnum","JsiSkImage","JsiSkData","JsiSkImageFactory","constructor","CanvasKit","MakeImageFromViewTag","viewTag","view","console","log","Promise","resolve","MakeImageFromNativeBuffer","buffer","surface","image","Error","img","MakeImageFromCanvasImageSource","makeImageFromTextureSource","updateTextureFromSource","MakeImageFromEncoded","encoded","fromValue","MakeImage","info","data","bytesPerRow","alphaType","AlphaType","colorSpace","ColorSpace","SRGB","colorType","ColorType","height","width"],"sources":["JsiSkImageFactory.ts"],"sourcesContent":["import type { CanvasKit, Image } from \"canvaskit-wasm\";\n\nimport { isNativeBufferWeb } from \"../types\";\nimport type {\n SkData,\n ImageInfo,\n SkImage,\n NativeBuffer,\n ImageFactory,\n} from \"../types\";\n\nimport { Host, getEnum } from \"./Host\";\nimport { JsiSkImage } from \"./JsiSkImage\";\nimport { JsiSkData } from \"./JsiSkData\";\nimport type { JsiSkSurface } from \"./JsiSkSurface\";\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 MakeImageFromNativeBuffer(\n buffer: NativeBuffer,\n surface?: JsiSkSurface,\n image?: JsiSkImage\n ) {\n if (!isNativeBufferWeb(buffer)) {\n throw new Error(\"Invalid NativeBuffer\");\n }\n if (!surface) {\n // TODO: this is way to slow\n const img = this.CanvasKit.MakeImageFromCanvasImageSource(buffer);\n return new JsiSkImage(this.CanvasKit, img);\n } else if (!image) {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n const img = (surface as any).makeImageFromTextureSource(buffer) as Image;\n return new JsiSkImage(this.CanvasKit, img);\n } else {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n const img = (surface as any).updateTextureFromSource(\n image,\n buffer\n ) as Image;\n return new JsiSkImage(this.CanvasKit, img);\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"],"mappings":"AAEA,SAASA,iBAAiB,QAAQ,UAAU;AAS5C,SAASC,IAAI,EAAEC,OAAO,QAAQ,QAAQ;AACtC,SAASC,UAAU,QAAQ,cAAc;AACzC,SAASC,SAAS,QAAQ,aAAa;AAGvC,OAAO,MAAMC,iBAAiB,SAASJ,IAAI,CAAyB;EAClEK,WAAWA,CAACC,SAAoB,EAAE;IAChC,KAAK,CAACA,SAAS,CAAC;EAClB;EAEAC,oBAAoBA,CAACC,OAAe,EAA2B;IAC7D,MAAMC,IAAI,GAAGD,OAAiC;IAC9C;IACAE,OAAO,CAACC,GAAG,CAACF,IAAI,CAAC;IACjB,OAAOG,OAAO,CAACC,OAAO,CAAC,IAAI,CAAC;EAC9B;EAEAC,yBAAyBA,CACvBC,MAAoB,EACpBC,OAAsB,EACtBC,KAAkB,EAClB;IACA,IAAI,CAAClB,iBAAiB,CAACgB,MAAM,CAAC,EAAE;MAC9B,MAAM,IAAIG,KAAK,CAAC,sBAAsB,CAAC;IACzC;IACA,IAAI,CAACF,OAAO,EAAE;MACZ;MACA,MAAMG,GAAG,GAAG,IAAI,C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,SAAS,CAACsB,SAAS,CAACG,IAAI,CAAC,EACzBC,WACF,CAAC;IACD,IAAIZ,KAAK,KAAK,IAAI,EAAE;MAClB,OAAO,IAAI;IACb;IACA,OAAO,IAAIf,UAAU,CAAC,IAAI,CAACI,SAAS,EAAEW,KAAK,CAAC;EAC9C;AACF"}
@@ -0,0 +1,8 @@
1
+ import type { CanvasKit } from "canvaskit-wasm";
2
+ import { type NativeBuffer, type NativeBufferFactory, type SkImage } from "../types";
3
+ import { Host } from "./Host";
4
+ export declare class JsiSkNativeBufferFactory extends Host implements NativeBufferFactory {
5
+ constructor(CanvasKit: CanvasKit);
6
+ MakeFromImage(image: SkImage): NativeBuffer;
7
+ Release(_platformBuffer: NativeBuffer): void;
8
+ }
@@ -0,0 +1,22 @@
1
+ import { Host } from "./Host";
2
+ export class JsiSkNativeBufferFactory extends Host {
3
+ constructor(CanvasKit) {
4
+ super(CanvasKit);
5
+ }
6
+ MakeFromImage(image) {
7
+ const info = image.getImageInfo();
8
+ const uint8ClampedArray = new Uint8ClampedArray(image.readPixels());
9
+ const imageData = new ImageData(uint8ClampedArray, info.width, info.height);
10
+ const canvas = new OffscreenCanvas(info.width, info.height);
11
+ const ctx = canvas.getContext("2d");
12
+ if (!ctx) {
13
+ throw new Error("Failed to get 2d context from canvas");
14
+ }
15
+ ctx.putImageData(imageData, 0, 0);
16
+ return canvas;
17
+ }
18
+ Release(_platformBuffer) {
19
+ // it's a noop on Web
20
+ }
21
+ }
22
+ //# sourceMappingURL=JsiSkNativeBufferFactory.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["Host","JsiSkNativeBufferFactory","constructor","CanvasKit","MakeFromImage","image","info","getImageInfo","uint8ClampedArray","Uint8ClampedArray","readPixels","imageData","ImageData","width","height","canvas","OffscreenCanvas","ctx","getContext","Error","putImageData","Release","_platformBuffer"],"sources":["JsiSkNativeBufferFactory.ts"],"sourcesContent":["import type { CanvasKit } from \"canvaskit-wasm\";\n\nimport {\n type NativeBuffer,\n type NativeBufferFactory,\n type SkImage,\n} from \"../types\";\n\nimport { Host } from \"./Host\";\n\nexport class JsiSkNativeBufferFactory\n extends Host\n implements NativeBufferFactory\n{\n constructor(CanvasKit: CanvasKit) {\n super(CanvasKit);\n }\n\n MakeFromImage(image: SkImage): NativeBuffer {\n const info = image.getImageInfo();\n const uint8ClampedArray = new Uint8ClampedArray(image.readPixels()!);\n const imageData = new ImageData(uint8ClampedArray, info.width, info.height);\n const canvas = new OffscreenCanvas(info.width, info.height);\n const ctx = canvas.getContext(\"2d\");\n if (!ctx) {\n throw new Error(\"Failed to get 2d context from canvas\");\n }\n ctx.putImageData(imageData, 0, 0);\n return canvas;\n }\n\n Release(_platformBuffer: NativeBuffer) {\n // it's a noop on Web\n }\n}\n"],"mappings":"AAQA,SAASA,IAAI,QAAQ,QAAQ;AAE7B,OAAO,MAAMC,wBAAwB,SAC3BD,IAAI,CAEd;EACEE,WAAWA,CAACC,SAAoB,EAAE;IAChC,KAAK,CAACA,SAAS,CAAC;EAClB;EAEAC,aAAaA,CAACC,KAAc,EAAgB;IAC1C,MAAMC,IAAI,GAAGD,KAAK,CAACE,YAAY,CAAC,CAAC;IACjC,MAAMC,iBAAiB,GAAG,IAAIC,iBAAiB,CAACJ,KAAK,CAACK,UAAU,CAAC,CAAE,CAAC;IACpE,MAAMC,SAAS,GAAG,IAAIC,SAAS,CAACJ,iBAAiB,EAAEF,IAAI,CAACO,KAAK,EAAEP,IAAI,CAACQ,MAAM,CAAC;IAC3E,MAAMC,MAAM,GAAG,IAAIC,eAAe,CAACV,IAAI,CAACO,KAAK,EAAEP,IAAI,CAACQ,MAAM,CAAC;IAC3D,MAAMG,GAAG,GAAGF,MAAM,CAACG,UAAU,CAAC,IAAI,CAAC;IACnC,IAAI,CAACD,GAAG,EAAE;MACR,MAAM,IAAIE,KAAK,CAAC,sCAAsC,CAAC;IACzD;IACAF,GAAG,CAACG,YAAY,CAACT,SAAS,EAAE,CAAC,EAAE,CAAC,CAAC;IACjC,OAAOI,MAAM;EACf;EAEAM,OAAOA,CAACC,eAA6B,EAAE;IACrC;EAAA;AAEJ"}
@@ -29,7 +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
+ import { JsiSkNativeBufferFactory } from "./JsiSkNativeBufferFactory";
33
33
  export const JsiSkApi = CanvasKit => ({
34
34
  Point: (x, y) => new JsiSkPoint(CanvasKit, Float32Array.of(x, y)),
35
35
  RuntimeShaderBuilder: _ => {
@@ -74,6 +74,6 @@ export const JsiSkApi = CanvasKit => ({
74
74
  TypefaceFontProvider: new JsiSkTypefaceFontProviderFactory(CanvasKit),
75
75
  FontMgr: new JsiSkFontMgrFactory(CanvasKit),
76
76
  ParagraphBuilder: new JsiSkParagraphBuilderFactory(CanvasKit),
77
- PlatformBuffer: new JsiSkPlatformBufferFactory(CanvasKit)
77
+ NativeBuffer: new JsiSkNativeBufferFactory(CanvasKit)
78
78
  });
79
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","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,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,QAAQ,2BAA2B;AACnE,SAASC,kBAAkB,QAAQ,sBAAsB;AACzD,SAASC,sBAAsB,QAAQ,0BAA0B;AACjE,SAASC,gBAAgB,QAAQ,oBAAoB;AACrD,SAASC,iBAAiB,QAAQ,qBAAqB;AACvD,SAASC,eAAe,QAAQ,mBAAmB;AACnD,SAASC,oBAAoB,QAAQ,wBAAwB;AAC7D,SAASC,SAAS,QAAQ,aAAa;AACvC,SAASC,YAAY,QAAQ,wBAAwB;AACrD,SAASC,SAAS,QAAQ,aAAa;AACvC,SAASC,aAAa,QAAQ,iBAAiB;AAC/C,SAASC,gCAAgC,QAAQ,oCAAoC;AACrF,SAASC,mBAAmB,QAAQ,uBAAuB;AAC3D,SAASC,yBAAyB,QAAQ,6BAA6B;AACvE,S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siSkPictureFactory","JsiSkPathFactory","JsiSkMatrix","JsiSkColorFilterFactory","JsiSkTypefaceFactory","JsiSkMaskFilterFactory","JsiSkRuntimeEffectFactory","JsiSkImageFilterFactory","JsiSkShaderFactory","JsiSkPathEffectFactory","JsiSkDataFactory","JsiSkImageFactory","JsiSkSVGFactory","JsiSkTextBlobFactory","JsiSkFont","MakeVertices","JsiSkPath","JsiSkTypeface","JsiSkTypefaceFontProviderFactory","JsiSkFontMgrFactory","JsiSkAnimatedImageFactory","JsiSkParagraphBuilderFactory","JsiSkNativeBufferFactory","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","NativeBuffer"],"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 { JsiSkNativeBufferFactory } from \"./JsiSkNativeBufferFactory\";\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 NativeBuffer: new JsiSkNativeBufferFactory(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,QAAQ,2BAA2B;AACnE,SAASC,kBAAkB,QAAQ,sBAAsB;AACzD,SAASC,sBAAsB,QAAQ,0BAA0B;AACjE,SAASC,gBAAgB,QAAQ,oBAAoB;AACrD,SAASC,iBAAiB,QAAQ,qBAAqB;AACvD,SAASC,eAAe,QAAQ,mBAAmB;AACnD,SAASC,oBAAoB,Q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CAAC;EAC3CiE,gBAAgB,EAAE,IAAIpE,4BAA4B,CAACG,SAAS,CAAC;EAC7DkE,YAAY,EAAE,IAAIpE,wBAAwB,CAACE,SAAS;AACtD,CAAC,CAAC"}
@@ -1,4 +1,5 @@
1
1
  import type { SkData } from "../Data";
2
+ import type { NativeBuffer } from "../NativeBuffer";
2
3
  import type { SkImage } from "./Image";
3
4
  export declare enum AlphaType {
4
5
  Unknown = 0,
@@ -23,16 +24,7 @@ export declare enum ColorType {
23
24
  Gray_8 = 13,
24
25
  RGBA_F16Norm = 14,
25
26
  RGBA_F16 = 15,
26
- RGBA_F32 = 16,
27
- R8G8_unorm = 17,
28
- A16_float = 18,
29
- R16G16_float = 19,
30
- A16_unorm = 20,
31
- R16G16_unorm = 21,
32
- R16G16B16A16_unorm = 22,
33
- SRGBA_8888 = 23,
34
- R8_unorm = 24,
35
- N32_SkColorType = 25
27
+ RGBA_F32 = 16
36
28
  }
37
29
  export interface ImageInfo {
38
30
  alphaType: AlphaType;
@@ -53,19 +45,20 @@ export interface ImageFactory {
53
45
  */
54
46
  MakeImageFromEncoded: (encoded: SkData) => SkImage | null;
55
47
  /**
56
- * Return an Image backed by the given native platform buffer.
48
+ * Return an Image backed by a given native buffer.
57
49
  * The platform buffer must be a valid owning reference.
58
50
  *
59
- * This API is used by [react-native-vision-camera](https://github.com/mrousavy/react-native-vision-camera)
51
+ * For instance, this API is used by
52
+ * [react-native-vision-camera](https://github.com/mrousavy/react-native-vision-camera)
60
53
  * to render a Skia Camera preview.
61
54
  *
62
55
  * - 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
56
+ * - On iOS, this is a `CVPixelBufferRef`
57
+ * @param nativeBuffer A strong `uintptr_t` pointer to the native platform buffer
65
58
  * @throws Throws an error if the Image could not be created, for example when the given
66
59
  * platform buffer is invalid.
67
60
  */
68
- MakeImageFromPlatformBuffer: (platformBuffer: bigint) => SkImage;
61
+ MakeImageFromNativeBuffer: (nativeBuffer: NativeBuffer) => SkImage;
69
62
  /**
70
63
  * Returns an image that will be a screenshot of the view represented by
71
64
  * the view tag
@@ -0,0 +1,18 @@
1
+ import type { SkImage } from "../Image";
2
+ export type NativeBuffer<T extends bigint | ArrayBuffer | CanvasImageSource | unknown = unknown> = T;
3
+ export type NativeBufferAddr = NativeBuffer<bigint>;
4
+ export type NativeBufferWeb = NativeBuffer<CanvasImageSource>;
5
+ export type NativeBufferNode = NativeBuffer<ArrayBuffer>;
6
+ export declare const isNativeBufferAddr: (buffer: NativeBuffer) => buffer is bigint;
7
+ export declare const isNativeBufferWeb: (buffer: NativeBuffer) => buffer is CanvasImageSource;
8
+ export declare const isNativeBufferNode: (buffer: NativeBuffer) => buffer is ArrayBuffer;
9
+ export interface NativeBufferFactory {
10
+ /**
11
+ * Copy pixels to a platform buffer. (for testing purposes)
12
+ */
13
+ MakeFromImage: (image: SkImage) => NativeBuffer;
14
+ /**
15
+ * Release a platform buffer that was created with `MakeFromImage`.
16
+ */
17
+ Release: (platformBuffer: NativeBuffer) => void;
18
+ }
@@ -0,0 +1 @@
1
+ export * from "./NativeBufferFactory";
@@ -26,7 +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
+ import type { NativeBufferFactory } from "./NativeBuffer";
30
30
  /**
31
31
  * Declares the interface for the native Skia API
32
32
  */
@@ -72,5 +72,5 @@ export interface Skia {
72
72
  TextBlob: TextBlobFactory;
73
73
  Surface: SurfaceFactory;
74
74
  ParagraphBuilder: ParagraphBuilderFactory;
75
- PlatformBuffer: PlatformBufferFactory;
75
+ NativeBuffer: NativeBufferFactory;
76
76
  }
@@ -29,4 +29,4 @@ export * from "./TextBlob";
29
29
  export * from "./Size";
30
30
  export * from "./Paragraph";
31
31
  export * from "./Matrix4";
32
- export * from "./PlatformBuffer";
32
+ export * from "./NativeBuffer";
@@ -1,11 +1,12 @@
1
1
  import type { CanvasKit } from "canvaskit-wasm";
2
- import type { SkData, ImageInfo, SkImage, PlatformBuffer, ImageFactory } from "../types";
2
+ import type { SkData, ImageInfo, SkImage, NativeBuffer, ImageFactory } from "../types";
3
3
  import { Host } from "./Host";
4
4
  import { JsiSkImage } from "./JsiSkImage";
5
+ import type { JsiSkSurface } from "./JsiSkSurface";
5
6
  export declare class JsiSkImageFactory extends Host implements ImageFactory {
6
7
  constructor(CanvasKit: CanvasKit);
7
8
  MakeImageFromViewTag(viewTag: number): Promise<SkImage | null>;
8
- MakeImageFromPlatformBuffer(_platformBuffer: PlatformBuffer): SkImage;
9
+ MakeImageFromNativeBuffer(buffer: NativeBuffer, surface?: JsiSkSurface, image?: JsiSkImage): JsiSkImage;
9
10
  MakeImageFromEncoded(encoded: SkData): JsiSkImage | null;
10
11
  MakeImage(info: ImageInfo, data: SkData, bytesPerRow: number): JsiSkImage | null;
11
12
  }
@@ -0,0 +1,8 @@
1
+ import type { CanvasKit } from "canvaskit-wasm";
2
+ import { type NativeBuffer, type NativeBufferFactory, type SkImage } from "../types";
3
+ import { Host } from "./Host";
4
+ export declare class JsiSkNativeBufferFactory extends Host implements NativeBufferFactory {
5
+ constructor(CanvasKit: CanvasKit);
6
+ MakeFromImage(image: SkImage): NativeBuffer;
7
+ Release(_platformBuffer: NativeBuffer): void;
8
+ }
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.2.0",
10
+ "version": "1.2.1",
11
11
  "description": "High-performance React Native Graphics using Skia",
12
12
  "main": "lib/module/index.js",
13
13
  "react-native": "src/index.ts",
@@ -1,4 +1,5 @@
1
1
  import type { SkData } from "../Data";
2
+ import type { NativeBuffer } from "../NativeBuffer";
2
3
 
3
4
  import type { SkImage } from "./Image";
4
5
 
@@ -27,24 +28,6 @@ export enum ColorType {
27
28
  RGBA_F16Norm, // pixel with half floats in [0,1] for red, green, blue, alpha; in 64-bit word
28
29
  RGBA_F16, // pixel with half floats for red, green, blue, alpha; in 64-bit word
29
30
  RGBA_F32, // pixel using C float for red, green, blue, alpha; in 128-bit word
30
-
31
- // The following 6 colortypes are just for reading from - not for rendering to
32
- R8G8_unorm, // pixel with a uint8_t for red and green
33
-
34
- A16_float, // pixel with a half float for alpha
35
- R16G16_float, // pixel with a half float for red and green
36
-
37
- A16_unorm, // pixel with a little endian uint16_t for alpha
38
- R16G16_unorm, // pixel with a little endian uint16_t for red and green
39
- R16G16B16A16_unorm, // pixel with a little endian uint16_t for red, green, blue, and alpha
40
-
41
- SRGBA_8888,
42
- R8_unorm,
43
-
44
- // The `kN32_SkColorType` is platform dependent in the original enum,
45
- // and TypeScript doesn't support conditional compilation natively.
46
- // You might need to handle it differently based on your use case.
47
- N32_SkColorType, // either BGRA_8888 or RGBA_8888 based on the platform
48
31
  }
49
32
 
50
33
  export interface ImageInfo {
@@ -70,19 +53,20 @@ export interface ImageFactory {
70
53
  MakeImageFromEncoded: (encoded: SkData) => SkImage | null;
71
54
 
72
55
  /**
73
- * Return an Image backed by the given native platform buffer.
56
+ * Return an Image backed by a given native buffer.
74
57
  * The platform buffer must be a valid owning reference.
75
58
  *
76
- * This API is used by [react-native-vision-camera](https://github.com/mrousavy/react-native-vision-camera)
59
+ * For instance, this API is used by
60
+ * [react-native-vision-camera](https://github.com/mrousavy/react-native-vision-camera)
77
61
  * to render a Skia Camera preview.
78
62
  *
79
63
  * - 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
64
+ * - On iOS, this is a `CVPixelBufferRef`
65
+ * @param nativeBuffer A strong `uintptr_t` pointer to the native platform buffer
82
66
  * @throws Throws an error if the Image could not be created, for example when the given
83
67
  * platform buffer is invalid.
84
68
  */
85
- MakeImageFromPlatformBuffer: (platformBuffer: bigint) => SkImage;
69
+ MakeImageFromNativeBuffer: (nativeBuffer: NativeBuffer) => SkImage;
86
70
 
87
71
  /**
88
72
  * Returns an image that will be a screenshot of the view represented by
@@ -0,0 +1,38 @@
1
+ import type { SkImage } from "../Image";
2
+
3
+ export type NativeBuffer<
4
+ T extends bigint | ArrayBuffer | CanvasImageSource | unknown = unknown
5
+ > = T;
6
+
7
+ export type NativeBufferAddr = NativeBuffer<bigint>;
8
+ export type NativeBufferWeb = NativeBuffer<CanvasImageSource>;
9
+ export type NativeBufferNode = NativeBuffer<ArrayBuffer>;
10
+
11
+ export const isNativeBufferAddr = (
12
+ buffer: NativeBuffer
13
+ ): buffer is NativeBufferAddr => buffer instanceof BigInt;
14
+ export const isNativeBufferWeb = (
15
+ buffer: NativeBuffer
16
+ ): buffer is NativeBufferWeb =>
17
+ buffer instanceof HTMLVideoElement ||
18
+ buffer instanceof HTMLCanvasElement ||
19
+ buffer instanceof ImageBitmap ||
20
+ buffer instanceof OffscreenCanvas ||
21
+ buffer instanceof VideoFrame ||
22
+ buffer instanceof HTMLImageElement ||
23
+ buffer instanceof SVGImageElement;
24
+
25
+ export const isNativeBufferNode = (
26
+ buffer: NativeBuffer
27
+ ): buffer is NativeBufferNode => buffer instanceof ArrayBuffer;
28
+
29
+ export interface NativeBufferFactory {
30
+ /**
31
+ * Copy pixels to a platform buffer. (for testing purposes)
32
+ */
33
+ MakeFromImage: (image: SkImage) => NativeBuffer;
34
+ /**
35
+ * Release a platform buffer that was created with `MakeFromImage`.
36
+ */
37
+ Release: (platformBuffer: NativeBuffer) => void;
38
+ }
@@ -0,0 +1 @@
1
+ export * from "./NativeBufferFactory";
@@ -30,7 +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
+ import type { NativeBufferFactory } from "./NativeBuffer";
34
34
 
35
35
  /**
36
36
  * Declares the interface for the native Skia API
@@ -95,5 +95,5 @@ export interface Skia {
95
95
  TextBlob: TextBlobFactory;
96
96
  Surface: SurfaceFactory;
97
97
  ParagraphBuilder: ParagraphBuilderFactory;
98
- PlatformBuffer: PlatformBufferFactory;
98
+ NativeBuffer: NativeBufferFactory;
99
99
  }
@@ -29,4 +29,4 @@ export * from "./TextBlob";
29
29
  export * from "./Size";
30
30
  export * from "./Paragraph";
31
31
  export * from "./Matrix4";
32
- export * from "./PlatformBuffer";
32
+ export * from "./NativeBuffer";
@@ -1,16 +1,18 @@
1
- import type { CanvasKit } from "canvaskit-wasm";
1
+ import type { CanvasKit, Image } from "canvaskit-wasm";
2
2
 
3
+ import { isNativeBufferWeb } from "../types";
3
4
  import type {
4
5
  SkData,
5
6
  ImageInfo,
6
7
  SkImage,
7
- PlatformBuffer,
8
+ NativeBuffer,
8
9
  ImageFactory,
9
10
  } from "../types";
10
11
 
11
12
  import { Host, getEnum } from "./Host";
12
13
  import { JsiSkImage } from "./JsiSkImage";
13
14
  import { JsiSkData } from "./JsiSkData";
15
+ import type { JsiSkSurface } from "./JsiSkSurface";
14
16
 
15
17
  export class JsiSkImageFactory extends Host implements ImageFactory {
16
18
  constructor(CanvasKit: CanvasKit) {
@@ -24,10 +26,30 @@ export class JsiSkImageFactory extends Host implements ImageFactory {
24
26
  return Promise.resolve(null);
25
27
  }
26
28
 
27
- MakeImageFromPlatformBuffer(_platformBuffer: PlatformBuffer): SkImage {
28
- throw new Error(
29
- "MakeImageFromPlatformBuffer() is only available on iOS and Android!"
30
- );
29
+ MakeImageFromNativeBuffer(
30
+ buffer: NativeBuffer,
31
+ surface?: JsiSkSurface,
32
+ image?: JsiSkImage
33
+ ) {
34
+ if (!isNativeBufferWeb(buffer)) {
35
+ throw new Error("Invalid NativeBuffer");
36
+ }
37
+ if (!surface) {
38
+ // TODO: this is way to slow
39
+ const img = this.CanvasKit.MakeImageFromCanvasImageSource(buffer);
40
+ return new JsiSkImage(this.CanvasKit, img);
41
+ } else if (!image) {
42
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
43
+ const img = (surface as any).makeImageFromTextureSource(buffer) as Image;
44
+ return new JsiSkImage(this.CanvasKit, img);
45
+ } else {
46
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
47
+ const img = (surface as any).updateTextureFromSource(
48
+ image,
49
+ buffer
50
+ ) as Image;
51
+ return new JsiSkImage(this.CanvasKit, img);
52
+ }
31
53
  }
32
54
 
33
55
  MakeImageFromEncoded(encoded: SkData) {