@shopify/react-native-skia 1.1.0 → 1.2.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (134) hide show
  1. package/android/CMakeLists.txt +1 -0
  2. package/android/build.gradle +1 -0
  3. package/android/cpp/rnskia-android/AHardwareBufferUtils.cpp +31 -0
  4. package/android/cpp/rnskia-android/AHardwareBufferUtils.h +13 -0
  5. package/android/cpp/rnskia-android/RNSkAndroidPlatformContext.h +75 -0
  6. package/android/cpp/rnskia-android/SkiaOpenGLSurfaceFactory.cpp +29 -11
  7. package/android/cpp/rnskia-android/SkiaOpenGLSurfaceFactory.h +1 -2
  8. package/android/src/main/java/com/shopify/reactnative/skia/ViewScreenshotService.java +3 -2
  9. package/cpp/api/JsiNativeBuffer.h +43 -0
  10. package/cpp/api/JsiSkApi.h +4 -0
  11. package/cpp/api/JsiSkImage.h +1 -1
  12. package/cpp/api/JsiSkImageFactory.h +15 -1
  13. package/cpp/api/JsiSkSurface.h +9 -1
  14. package/cpp/rnskia/RNSkPlatformContext.h +13 -0
  15. package/ios/RNSkia-iOS/RNSkiOSPlatformContext.h +6 -0
  16. package/ios/RNSkia-iOS/RNSkiOSPlatformContext.mm +98 -2
  17. package/ios/RNSkia-iOS/SkiaCVPixelBufferUtils.h +84 -0
  18. package/ios/RNSkia-iOS/SkiaCVPixelBufferUtils.mm +159 -0
  19. package/ios/RNSkia-iOS/SkiaMetalSurfaceFactory.h +5 -0
  20. package/ios/RNSkia-iOS/SkiaMetalSurfaceFactory.mm +37 -1
  21. package/lib/commonjs/external/reanimated/textures.js +11 -2
  22. package/lib/commonjs/external/reanimated/textures.js.map +1 -1
  23. package/lib/commonjs/external/reanimated/useAnimatedImageValue.d.ts +2 -1
  24. package/lib/commonjs/external/reanimated/useAnimatedImageValue.js +8 -4
  25. package/lib/commonjs/external/reanimated/useAnimatedImageValue.js.map +1 -1
  26. package/lib/commonjs/renderer/Offscreen.d.ts +2 -2
  27. package/lib/commonjs/renderer/Offscreen.js +2 -2
  28. package/lib/commonjs/renderer/Offscreen.js.map +1 -1
  29. package/lib/commonjs/skia/types/Image/ImageFactory.d.ts +17 -10
  30. package/lib/commonjs/skia/types/Image/ImageFactory.js +1 -10
  31. package/lib/commonjs/skia/types/Image/ImageFactory.js.map +1 -1
  32. package/lib/commonjs/skia/types/NativeBuffer/NativeBufferFactory.d.ts +18 -0
  33. package/lib/commonjs/skia/types/NativeBuffer/NativeBufferFactory.js +13 -0
  34. package/lib/commonjs/skia/types/NativeBuffer/NativeBufferFactory.js.map +1 -0
  35. package/lib/commonjs/skia/types/NativeBuffer/index.d.ts +1 -0
  36. package/lib/commonjs/skia/types/NativeBuffer/index.js +17 -0
  37. package/lib/commonjs/skia/types/NativeBuffer/index.js.map +1 -0
  38. package/lib/commonjs/skia/types/Skia.d.ts +2 -0
  39. package/lib/commonjs/skia/types/Skia.js.map +1 -1
  40. package/lib/commonjs/skia/types/Surface/Surface.d.ts +8 -0
  41. package/lib/commonjs/skia/types/Surface/Surface.js.map +1 -1
  42. package/lib/commonjs/skia/types/index.d.ts +1 -0
  43. package/lib/commonjs/skia/types/index.js +11 -0
  44. package/lib/commonjs/skia/types/index.js.map +1 -1
  45. package/lib/commonjs/skia/web/JsiSkImage.d.ts +1 -2
  46. package/lib/commonjs/skia/web/JsiSkImage.js +5 -12
  47. package/lib/commonjs/skia/web/JsiSkImage.js.map +1 -1
  48. package/lib/commonjs/skia/web/JsiSkImageFactory.d.ts +3 -2
  49. package/lib/commonjs/skia/web/JsiSkImageFactory.js +19 -0
  50. package/lib/commonjs/skia/web/JsiSkImageFactory.js.map +1 -1
  51. package/lib/commonjs/skia/web/JsiSkNativeBufferFactory.d.ts +8 -0
  52. package/lib/commonjs/skia/web/JsiSkNativeBufferFactory.js +29 -0
  53. package/lib/commonjs/skia/web/JsiSkNativeBufferFactory.js.map +1 -0
  54. package/lib/commonjs/skia/web/JsiSkSurface.d.ts +3 -2
  55. package/lib/commonjs/skia/web/JsiSkSurface.js +8 -6
  56. package/lib/commonjs/skia/web/JsiSkSurface.js.map +1 -1
  57. package/lib/commonjs/skia/web/JsiSkSurfaceFactory.d.ts +1 -1
  58. package/lib/commonjs/skia/web/JsiSkSurfaceFactory.js +1 -16
  59. package/lib/commonjs/skia/web/JsiSkSurfaceFactory.js.map +1 -1
  60. package/lib/commonjs/skia/web/JsiSkia.js +3 -1
  61. package/lib/commonjs/skia/web/JsiSkia.js.map +1 -1
  62. package/lib/module/external/reanimated/textures.js +11 -2
  63. package/lib/module/external/reanimated/textures.js.map +1 -1
  64. package/lib/module/external/reanimated/useAnimatedImageValue.d.ts +2 -1
  65. package/lib/module/external/reanimated/useAnimatedImageValue.js +8 -4
  66. package/lib/module/external/reanimated/useAnimatedImageValue.js.map +1 -1
  67. package/lib/module/renderer/Offscreen.d.ts +2 -2
  68. package/lib/module/renderer/Offscreen.js +2 -2
  69. package/lib/module/renderer/Offscreen.js.map +1 -1
  70. package/lib/module/skia/types/Image/ImageFactory.d.ts +17 -10
  71. package/lib/module/skia/types/Image/ImageFactory.js +1 -10
  72. package/lib/module/skia/types/Image/ImageFactory.js.map +1 -1
  73. package/lib/module/skia/types/NativeBuffer/NativeBufferFactory.d.ts +18 -0
  74. package/lib/module/skia/types/NativeBuffer/NativeBufferFactory.js +4 -0
  75. package/lib/module/skia/types/NativeBuffer/NativeBufferFactory.js.map +1 -0
  76. package/lib/module/skia/types/NativeBuffer/index.d.ts +1 -0
  77. package/lib/module/skia/types/NativeBuffer/index.js +2 -0
  78. package/lib/module/skia/types/NativeBuffer/index.js.map +1 -0
  79. package/lib/module/skia/types/Skia.d.ts +2 -0
  80. package/lib/module/skia/types/Skia.js.map +1 -1
  81. package/lib/module/skia/types/Surface/Surface.d.ts +8 -0
  82. package/lib/module/skia/types/Surface/Surface.js.map +1 -1
  83. package/lib/module/skia/types/index.d.ts +1 -0
  84. package/lib/module/skia/types/index.js +1 -0
  85. package/lib/module/skia/types/index.js.map +1 -1
  86. package/lib/module/skia/web/JsiSkImage.d.ts +1 -2
  87. package/lib/module/skia/web/JsiSkImage.js +5 -12
  88. package/lib/module/skia/web/JsiSkImage.js.map +1 -1
  89. package/lib/module/skia/web/JsiSkImageFactory.d.ts +3 -2
  90. package/lib/module/skia/web/JsiSkImageFactory.js +19 -0
  91. package/lib/module/skia/web/JsiSkImageFactory.js.map +1 -1
  92. package/lib/module/skia/web/JsiSkNativeBufferFactory.d.ts +8 -0
  93. package/lib/module/skia/web/JsiSkNativeBufferFactory.js +22 -0
  94. package/lib/module/skia/web/JsiSkNativeBufferFactory.js.map +1 -0
  95. package/lib/module/skia/web/JsiSkSurface.d.ts +3 -2
  96. package/lib/module/skia/web/JsiSkSurface.js +8 -6
  97. package/lib/module/skia/web/JsiSkSurface.js.map +1 -1
  98. package/lib/module/skia/web/JsiSkSurfaceFactory.d.ts +1 -1
  99. package/lib/module/skia/web/JsiSkSurfaceFactory.js +1 -16
  100. package/lib/module/skia/web/JsiSkSurfaceFactory.js.map +1 -1
  101. package/lib/module/skia/web/JsiSkia.js +3 -1
  102. package/lib/module/skia/web/JsiSkia.js.map +1 -1
  103. package/lib/typescript/src/external/reanimated/useAnimatedImageValue.d.ts +2 -1
  104. package/lib/typescript/src/renderer/Offscreen.d.ts +2 -2
  105. package/lib/typescript/src/skia/types/Image/ImageFactory.d.ts +17 -10
  106. package/lib/typescript/src/skia/types/NativeBuffer/NativeBufferFactory.d.ts +18 -0
  107. package/lib/typescript/src/skia/types/NativeBuffer/index.d.ts +1 -0
  108. package/lib/typescript/src/skia/types/Skia.d.ts +2 -0
  109. package/lib/typescript/src/skia/types/Surface/Surface.d.ts +8 -0
  110. package/lib/typescript/src/skia/types/index.d.ts +1 -0
  111. package/lib/typescript/src/skia/web/JsiSkImage.d.ts +1 -2
  112. package/lib/typescript/src/skia/web/JsiSkImageFactory.d.ts +3 -2
  113. package/lib/typescript/src/skia/web/JsiSkNativeBufferFactory.d.ts +8 -0
  114. package/lib/typescript/src/skia/web/JsiSkSurface.d.ts +3 -2
  115. package/lib/typescript/src/skia/web/JsiSkSurfaceFactory.d.ts +1 -1
  116. package/package.json +1 -1
  117. package/src/external/reanimated/textures.tsx +8 -2
  118. package/src/external/reanimated/useAnimatedImageValue.ts +12 -6
  119. package/src/renderer/Offscreen.tsx +3 -3
  120. package/src/skia/types/Image/ImageFactory.ts +17 -18
  121. package/src/skia/types/NativeBuffer/NativeBufferFactory.ts +38 -0
  122. package/src/skia/types/NativeBuffer/index.ts +1 -0
  123. package/src/skia/types/Skia.ts +2 -1
  124. package/src/skia/types/Surface/Surface.ts +10 -0
  125. package/src/skia/types/index.ts +1 -0
  126. package/src/skia/web/JsiSkImage.ts +5 -22
  127. package/src/skia/web/JsiSkImageFactory.ts +36 -3
  128. package/src/skia/web/JsiSkNativeBufferFactory.ts +35 -0
  129. package/src/skia/web/JsiSkSurface.ts +10 -9
  130. package/src/skia/web/JsiSkSurfaceFactory.ts +3 -19
  131. package/src/skia/web/JsiSkia.ts +2 -0
  132. package/cpp/skia/include/third_party/vulkan/LICENSE +0 -29
  133. package/cpp/skia/modules/skcms/README.chromium +0 -6
  134. package/cpp/skia/readme.txt +0 -1
@@ -1 +1 @@
1
- {"version":3,"names":["HostObject","JsiSkCanvas","JsiSkImage","JsiSkRect","JsiSkSurface","constructor","CanvasKit","ref","releaseCtx","_defineProperty","delete","flush","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(\n CanvasKit: CanvasKit,\n ref: Surface,\n private releaseCtx?: () => void\n ) {\n super(CanvasKit, ref, \"Surface\");\n }\n\n dispose = () => {\n this.ref.delete();\n if (this.releaseCtx) {\n this.releaseCtx();\n }\n };\n\n flush() {\n this.ref.flush();\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,CACTC,SAAoB,EACpBC,GAAY,EACJC,UAAuB,EAC/B;IACA,KAAK,CAACF,SAAS,EAAEC,GAAG,EAAE,SAAS,CAAC;IAAC,KAFzBC,UAAuB,GAAvBA,UAAuB;IAAAC,eAAA,kBAKvB,MAAM;MACd,IAAI,CAACF,GAAG,CAACG,MAAM,CAAC,CAAC;MACjB,IAAI,IAAI,CAACF,UAAU,EAAE;QACnB,IAAI,CAACA,UAAU,CAAC,CAAC;MACnB;IACF,CAAC;EAPD;EASAG,KAAKA,CAAA,EAAG;IACN,IAAI,CAACJ,GAAG,CAACI,KAAK,CAAC,CAAC;EAClB;EAEAC,SAASA,CAAA,EAAa;IACpB,OAAO,IAAIX,WAAW,CAAC,IAAI,CAACK,SAAS,EAAE,IAAI,CAACC,GAAG,CAACK,SAAS,CAAC,CAAC,CAAC;EAC9D;EAEAC,iBAAiBA,CAACC,MAAe,EAAW;IAC1C,MAAMC,KAAK,GAAG,IAAI,CAACR,GAAG,CAACM,iBAAiB,CACtCC,MAAM,GACFE,KAAK,CAACC,IAAI,CAACd,SAAS,CAACe,SAAS,CAAC,IAAI,CAACZ,SAAS,EAAEQ,MAAM,CAAC,CAAC,GACvDK,SACN,CAAC;IACD,OAAO,IAAIjB,UAAU,CAAC,IAAI,CAACI,SAAS,EAAES,KAAK,CAAC;EAC9C;AACF"}
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 | null;
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
- var pixelLen = width * height * 4;
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","pixelLen","pixelPtr","Malloc","Uint8Array","surface","MakeRasterDirectSurface","colorType","ColorType","RGBA_8888","alphaType","AlphaType","Unpremul","colorSpace","ColorSpace","SRGB","getCanvas","clear","TRANSPARENT","Free","MakeOffscreen","OC","globalThis","OffscreenCanvas","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 var pixelLen = width * height * 4;\n const pixelPtr = this.CanvasKit.Malloc(Uint8Array, pixelLen);\n const surface = this.CanvasKit.MakeRasterDirectSurface(\n {\n width: width,\n height: height,\n colorType: this.CanvasKit.ColorType.RGBA_8888,\n alphaType: this.CanvasKit.AlphaType.Unpremul,\n colorSpace: this.CanvasKit.ColorSpace.SRGB,\n },\n pixelPtr,\n width * 4\n );\n if (!surface) {\n return null;\n }\n surface.getCanvas().clear(this.CanvasKit.TRANSPARENT);\n return new JsiSkSurface(this.CanvasKit, surface, () => {\n this.CanvasKit.Free(pixelPtr);\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,IAAIC,QAAQ,GAAGF,KAAK,GAAGC,MAAM,GAAG,CAAC;IACjC,MAAME,QAAQ,GAAG,IAAI,CAACL,SAAS,CAACM,MAAM,CAACC,UAAU,EAAEH,QAAQ,CAAC;IAC5D,MAAMI,OAAO,GAAG,IAAI,CAACR,SAAS,CAACS,uBAAuB,CACpD;MACEP,KAAK,EAAEA,KAAK;MACZC,MAAM,EAAEA,MAAM;MACdO,SAAS,EAAE,IAAI,CAACV,SAAS,CAACW,SAAS,CAACC,SAAS;MAC7CC,SAAS,EAAE,IAAI,CAACb,SAAS,CAACc,SAAS,CAACC,QAAQ;MAC5CC,UAAU,EAAE,IAAI,CAAChB,SAAS,CAACiB,UAAU,CAACC;IACxC,CAAC,EACDb,QAAQ,EACRH,KAAK,GAAG,CACV,CAAC;IACD,IAAI,CAACM,OAAO,EAAE;MACZ,OAAO,IAAI;IACb;IACAA,OAAO,CAACW,SAAS,CAAC,CAAC,CAACC,KAAK,CAAC,IAAI,CAACpB,SAAS,CAACqB,WAAW,CAAC;IACrD,OAAO,IAAIxB,YAAY,CAAC,IAAI,CAACG,SAAS,EAAEQ,OAAO,EAAE,MAAM;MACrD,IAAI,CAACR,SAAS,CAACsB,IAAI,CAACjB,QAAQ,CAAC;IAC/B,CAAC,CAAC;EACJ;EAEAkB,aAAaA,CAACrB,KAAa,EAAEC,MAAc,EAAE;IAC3C;IACA;IACA,MAAMqB,EAAE,GAAIC,UAAU,CAASC,eAAe;IAC9C,IAAIlB,OAAuB;IAC3B,IAAIgB,EAAE,KAAKG,SAAS,EAAE;MACpB,OAAO,IAAI,CAAC1B,IAAI,CAACC,KAAK,EAAEC,MAAM,CAAC;IACjC,CAAC,MAAM;MACL,MAAMyB,SAAS,GAAG,IAAIJ,EAAE,CAACtB,KAAK,EAAEC,MAAM,CAAC;MACvC,MAAM0B,YAAY,GAAG,IAAI,CAAC7B,SAAS,CAAC8B,eAAe,CAACF,SAAS,CAAC;MAC9D,MAAMG,SAAS,GAAG,IAAI,CAAC/B,SAAS,CAACgC,gBAAgB,CAACH,YAAY,CAAC;MAC/D,IAAI,CAACE,SAAS,EAAE;QACd,MAAM,IAAIE,KAAK,CAAC,mCAAmC,CAAC;MACtD;MACAzB,OAAO,GAAG,IAAI,CAACR,SAAS,CAACkC,gBAAgB,CAACH,SAAS,EAAE7B,KAAK,EAAEC,MAAM,CAAC;IACrE;IACA,IAAI,CAACK,OAAO,EAAE;MACZ,OAAO,IAAI;IACb;IACA,OAAO,IAAIX,YAAY,CAAC,IAAI,CAACG,SAAS,EAAEQ,OAAO,CAAC;EAClD;AACF"}
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 { JsiSkNativeBufferFactory } from "./JsiSkNativeBufferFactory";
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
+ NativeBuffer: new JsiSkNativeBufferFactory(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;A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AEC,MAAM,CAAC,CAAC;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","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,SAAS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,CAAC;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,YAAY,EAAE,IAAIpE,wBAAwB,CAACE,SAAS;AACtD,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) => import("react-native-reanimated").SharedValue<SkImage | null>;
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;
@@ -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;
@@ -52,6 +44,21 @@ export interface ImageFactory {
52
44
  * image, nullptr is returned.
53
45
  */
54
46
  MakeImageFromEncoded: (encoded: SkData) => SkImage | null;
47
+ /**
48
+ * Return an Image backed by a given native buffer.
49
+ * The platform buffer must be a valid owning reference.
50
+ *
51
+ * For instance, this API is used by
52
+ * [react-native-vision-camera](https://github.com/mrousavy/react-native-vision-camera)
53
+ * to render a Skia Camera preview.
54
+ *
55
+ * - On Android; This is an `AHardwareBuffer*`
56
+ * - On iOS, this is a `CVPixelBufferRef`
57
+ * @param nativeBuffer A strong `uintptr_t` pointer to the native platform buffer
58
+ * @throws Throws an error if the Image could not be created, for example when the given
59
+ * platform buffer is invalid.
60
+ */
61
+ MakeImageFromNativeBuffer: (nativeBuffer: NativeBuffer) => SkImage;
55
62
  /**
56
63
  * Returns an image that will be a screenshot of the view represented by
57
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,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 { NativeBufferFactory } from "./NativeBuffer";
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
+ NativeBuffer: NativeBufferFactory;
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
  }
@@ -29,3 +29,4 @@ export * from "./TextBlob";
29
29
  export * from "./Size";
30
30
  export * from "./Paragraph";
31
31
  export * from "./Matrix4";
32
+ export * from "./NativeBuffer";
@@ -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
- private releaseCtx?;
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,12 @@
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, NativeBuffer, ImageFactory } from "../types";
4
3
  import { Host } from "./Host";
5
4
  import { JsiSkImage } from "./JsiSkImage";
5
+ import type { JsiSkSurface } from "./JsiSkSurface";
6
6
  export declare class JsiSkImageFactory extends Host implements ImageFactory {
7
7
  constructor(CanvasKit: CanvasKit);
8
8
  MakeImageFromViewTag(viewTag: number): Promise<SkImage | null>;
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
+ }
@@ -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
- private releaseCtx?;
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 | null;
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.1.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",
@@ -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
- }, [element]);
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 { FrameInfo } from "react-native-reanimated";
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 = (source: DataSourceParam) => {
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(0);
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
- // eslint-disable-next-line react-hooks/exhaustive-deps
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);
@@ -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 {
@@ -69,6 +52,22 @@ export interface ImageFactory {
69
52
  */
70
53
  MakeImageFromEncoded: (encoded: SkData) => SkImage | null;
71
54
 
55
+ /**
56
+ * Return an Image backed by a given native buffer.
57
+ * The platform buffer must be a valid owning reference.
58
+ *
59
+ * For instance, this API is used by
60
+ * [react-native-vision-camera](https://github.com/mrousavy/react-native-vision-camera)
61
+ * to render a Skia Camera preview.
62
+ *
63
+ * - On Android; This is an `AHardwareBuffer*`
64
+ * - On iOS, this is a `CVPixelBufferRef`
65
+ * @param nativeBuffer A strong `uintptr_t` pointer to the native platform buffer
66
+ * @throws Throws an error if the Image could not be created, for example when the given
67
+ * platform buffer is invalid.
68
+ */
69
+ MakeImageFromNativeBuffer: (nativeBuffer: NativeBuffer) => SkImage;
70
+
72
71
  /**
73
72
  * Returns an image that will be a screenshot of the view represented by
74
73
  * the view tag
@@ -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,6 +30,7 @@ import type { Color, SkColor } from "./Color";
30
30
  import type { TypefaceFontProviderFactory } from "./Paragraph/TypefaceFontProviderFactory";
31
31
  import type { AnimatedImageFactory } from "./AnimatedImage";
32
32
  import type { ParagraphBuilderFactory } from "./Paragraph/ParagraphBuilder";
33
+ import type { NativeBufferFactory } from "./NativeBuffer";
33
34
 
34
35
  /**
35
36
  * Declares the interface for the native Skia API
@@ -93,6 +94,6 @@ export interface Skia {
93
94
  SVG: SVGFactory;
94
95
  TextBlob: TextBlobFactory;
95
96
  Surface: SurfaceFactory;
96
- // Paragraph
97
97
  ParagraphBuilder: ParagraphBuilderFactory;
98
+ NativeBuffer: NativeBufferFactory;
98
99
  }
@@ -29,4 +29,14 @@ export interface SkSurface extends SkJSIInstance<"Surface"> {
29
29
  * Make sure any queued draws are sent to the screen or the GPU.
30
30
  */
31
31
  flush(): void;
32
+
33
+ /**
34
+ * Returns the possibly scaled width of the surface.
35
+ */
36
+ width(): number;
37
+
38
+ /**
39
+ * Returns the possibly scaled height of the surface.
40
+ */
41
+ height(): number;
32
42
  }
@@ -29,3 +29,4 @@ export * from "./TextBlob";
29
29
  export * from "./Size";
30
30
  export * from "./Paragraph";
31
31
  export * from "./Matrix4";
32
+ export * from "./NativeBuffer";
@@ -45,11 +45,7 @@ export const toBase64String = (bytes: Uint8Array) => {
45
45
  };
46
46
 
47
47
  export class JsiSkImage extends HostObject<Image, "Image"> implements SkImage {
48
- constructor(
49
- CanvasKit: CanvasKit,
50
- ref: Image,
51
- private releaseCtx?: () => void
52
- ) {
48
+ constructor(CanvasKit: CanvasKit, ref: Image) {
53
49
  super(CanvasKit, ref, "Image");
54
50
  }
55
51
 
@@ -154,37 +150,24 @@ export class JsiSkImage extends HostObject<Image, "Image"> implements SkImage {
154
150
 
155
151
  dispose = () => {
156
152
  this.ref.delete();
157
- if (this.releaseCtx) {
158
- this.releaseCtx();
159
- }
160
153
  };
161
154
 
162
155
  makeNonTextureImage(): SkImage {
156
+ // if the image is already a non-texture image, this is a no-op
163
157
  const partialInfo = this.ref.getImageInfo();
164
158
  const colorSpace = this.ref.getColorSpace();
165
159
  const info = {
166
160
  ...partialInfo,
167
161
  colorSpace,
168
162
  };
169
-
170
- var pixelLen = info.width * info.height * 4;
171
- const pixelPtr = this.CanvasKit.Malloc(Uint8Array, pixelLen);
172
- const pixels = this.ref.readPixels(
173
- 0,
174
- 0,
175
- info,
176
- pixelPtr,
177
- info.width * 4
178
- ) as Uint8Array | null;
163
+ const pixels = this.ref.readPixels(0, 0, info) as Uint8Array | null;
179
164
  if (!pixels) {
180
- throw new Error("Could not create image from bytes");
165
+ throw new Error("Could not read pixels from image");
181
166
  }
182
167
  const img = this.CanvasKit.MakeImage(info, pixels, info.width * 4);
183
168
  if (!img) {
184
169
  throw new Error("Could not create image from bytes");
185
170
  }
186
- return new JsiSkImage(this.CanvasKit, img, () => {
187
- this.CanvasKit.Free(pixelPtr);
188
- });
171
+ return new JsiSkImage(this.CanvasKit, img);
189
172
  }
190
173
  }