@shopify/react-native-skia 1.1.0 → 1.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
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,11 +1,18 @@
1
- import type { CanvasKit } from "canvaskit-wasm";
1
+ import type { CanvasKit, Image } from "canvaskit-wasm";
2
2
 
3
- import type { SkData, ImageInfo, SkImage } from "../types";
4
- import type { ImageFactory } from "../types/Image/ImageFactory";
3
+ import { isNativeBufferWeb } from "../types";
4
+ import type {
5
+ SkData,
6
+ ImageInfo,
7
+ SkImage,
8
+ NativeBuffer,
9
+ ImageFactory,
10
+ } from "../types";
5
11
 
6
12
  import { Host, getEnum } from "./Host";
7
13
  import { JsiSkImage } from "./JsiSkImage";
8
14
  import { JsiSkData } from "./JsiSkData";
15
+ import type { JsiSkSurface } from "./JsiSkSurface";
9
16
 
10
17
  export class JsiSkImageFactory extends Host implements ImageFactory {
11
18
  constructor(CanvasKit: CanvasKit) {
@@ -19,6 +26,32 @@ export class JsiSkImageFactory extends Host implements ImageFactory {
19
26
  return Promise.resolve(null);
20
27
  }
21
28
 
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
+ }
53
+ }
54
+
22
55
  MakeImageFromEncoded(encoded: SkData) {
23
56
  const image = this.CanvasKit.MakeImageFromEncoded(
24
57
  JsiSkData.fromValue(encoded)
@@ -0,0 +1,35 @@
1
+ import type { CanvasKit } from "canvaskit-wasm";
2
+
3
+ import {
4
+ type NativeBuffer,
5
+ type NativeBufferFactory,
6
+ type SkImage,
7
+ } from "../types";
8
+
9
+ import { Host } from "./Host";
10
+
11
+ export class JsiSkNativeBufferFactory
12
+ extends Host
13
+ implements NativeBufferFactory
14
+ {
15
+ constructor(CanvasKit: CanvasKit) {
16
+ super(CanvasKit);
17
+ }
18
+
19
+ MakeFromImage(image: SkImage): NativeBuffer {
20
+ const info = image.getImageInfo();
21
+ const uint8ClampedArray = new Uint8ClampedArray(image.readPixels()!);
22
+ const imageData = new ImageData(uint8ClampedArray, info.width, info.height);
23
+ const canvas = new OffscreenCanvas(info.width, info.height);
24
+ const ctx = canvas.getContext("2d");
25
+ if (!ctx) {
26
+ throw new Error("Failed to get 2d context from canvas");
27
+ }
28
+ ctx.putImageData(imageData, 0, 0);
29
+ return canvas;
30
+ }
31
+
32
+ Release(_platformBuffer: NativeBuffer) {
33
+ // it's a noop on Web
34
+ }
35
+ }
@@ -11,25 +11,26 @@ export class JsiSkSurface
11
11
  extends HostObject<Surface, "Surface">
12
12
  implements SkSurface
13
13
  {
14
- constructor(
15
- CanvasKit: CanvasKit,
16
- ref: Surface,
17
- private releaseCtx?: () => void
18
- ) {
14
+ constructor(CanvasKit: CanvasKit, ref: Surface) {
19
15
  super(CanvasKit, ref, "Surface");
20
16
  }
21
17
 
22
18
  dispose = () => {
23
- this.ref.delete();
24
- if (this.releaseCtx) {
25
- this.releaseCtx();
26
- }
19
+ this.ref.dispose();
27
20
  };
28
21
 
29
22
  flush() {
30
23
  this.ref.flush();
31
24
  }
32
25
 
26
+ width() {
27
+ return this.ref.width();
28
+ }
29
+
30
+ height() {
31
+ return this.ref.height();
32
+ }
33
+
33
34
  getCanvas(): SkCanvas {
34
35
  return new JsiSkCanvas(this.CanvasKit, this.ref.getCanvas());
35
36
  }
@@ -11,26 +11,10 @@ export class JsiSkSurfaceFactory extends Host implements SurfaceFactory {
11
11
  }
12
12
 
13
13
  Make(width: number, height: number) {
14
- var pixelLen = width * height * 4;
15
- const pixelPtr = this.CanvasKit.Malloc(Uint8Array, pixelLen);
16
- const surface = this.CanvasKit.MakeRasterDirectSurface(
17
- {
18
- width: width,
19
- height: height,
20
- colorType: this.CanvasKit.ColorType.RGBA_8888,
21
- alphaType: this.CanvasKit.AlphaType.Unpremul,
22
- colorSpace: this.CanvasKit.ColorSpace.SRGB,
23
- },
24
- pixelPtr,
25
- width * 4
14
+ return new JsiSkSurface(
15
+ this.CanvasKit,
16
+ this.CanvasKit.MakeSurface(width, height)!
26
17
  );
27
- if (!surface) {
28
- return null;
29
- }
30
- surface.getCanvas().clear(this.CanvasKit.TRANSPARENT);
31
- return new JsiSkSurface(this.CanvasKit, surface, () => {
32
- this.CanvasKit.Free(pixelPtr);
33
- });
34
18
  }
35
19
 
36
20
  MakeOffscreen(width: number, height: number) {
@@ -41,6 +41,7 @@ import { JsiSkTypefaceFontProviderFactory } from "./JsiSkTypefaceFontProviderFac
41
41
  import { JsiSkFontMgrFactory } from "./JsiSkFontMgrFactory";
42
42
  import { JsiSkAnimatedImageFactory } from "./JsiSkAnimatedImageFactory";
43
43
  import { JsiSkParagraphBuilderFactory } from "./JsiSkParagraphBuilderFactory";
44
+ import { JsiSkNativeBufferFactory } from "./JsiSkNativeBufferFactory";
44
45
 
45
46
  export const JsiSkApi = (CanvasKit: CanvasKit): Skia => ({
46
47
  Point: (x: number, y: number) =>
@@ -125,4 +126,5 @@ export const JsiSkApi = (CanvasKit: CanvasKit): Skia => ({
125
126
  TypefaceFontProvider: new JsiSkTypefaceFontProviderFactory(CanvasKit),
126
127
  FontMgr: new JsiSkFontMgrFactory(CanvasKit),
127
128
  ParagraphBuilder: new JsiSkParagraphBuilderFactory(CanvasKit),
129
+ NativeBuffer: new JsiSkNativeBufferFactory(CanvasKit),
128
130
  });
@@ -1,29 +0,0 @@
1
- // Copyright (c) 2018 Google Inc. All rights reserved.
2
- //
3
- // Redistribution and use in source and binary forms, with or without
4
- // modification, are permitted provided that the following conditions are
5
- // met:
6
- //
7
- // * Redistributions of source code must retain the above copyright
8
- // notice, this list of conditions and the following disclaimer.
9
- // * Redistributions in binary form must reproduce the above
10
- // copyright notice, this list of conditions and the following disclaimer
11
- // in the documentation and/or other materials provided with the
12
- // distribution.
13
- // * Neither the name of Google Inc. nor the names of its
14
- // contributors may be used to endorse or promote products derived from
15
- // this software without specific prior written permission.
16
- //
17
- // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18
- // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19
- // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20
- // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
21
- // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22
- // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23
- // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24
- // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25
- // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26
- // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27
- // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28
-
29
- --------------------------------------------------------------------------------
@@ -1,6 +0,0 @@
1
- Name: skcms
2
- URL: https://skia.org/
3
- Version: unknown
4
- Security Critical: yes
5
- Shipped: yes
6
- License: BSD
@@ -1 +0,0 @@
1
- Placeholder for the Skia include files.