@shopify/react-native-skia 1.1.0 → 1.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (130) 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/JsiPlatformBuffer.h +51 -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 +115 -0
  17. package/ios/RNSkia-iOS/SkiaMetalSurfaceFactory.h +4 -0
  18. package/ios/RNSkia-iOS/SkiaMetalSurfaceFactory.mm +12 -0
  19. package/lib/commonjs/external/reanimated/textures.js +11 -2
  20. package/lib/commonjs/external/reanimated/textures.js.map +1 -1
  21. package/lib/commonjs/external/reanimated/useAnimatedImageValue.d.ts +2 -1
  22. package/lib/commonjs/external/reanimated/useAnimatedImageValue.js +8 -4
  23. package/lib/commonjs/external/reanimated/useAnimatedImageValue.js.map +1 -1
  24. package/lib/commonjs/renderer/Offscreen.d.ts +2 -2
  25. package/lib/commonjs/renderer/Offscreen.js +2 -2
  26. package/lib/commonjs/renderer/Offscreen.js.map +1 -1
  27. package/lib/commonjs/skia/types/Image/ImageFactory.d.ts +14 -0
  28. package/lib/commonjs/skia/types/Image/ImageFactory.js.map +1 -1
  29. package/lib/commonjs/skia/types/PlatformBuffer/PlatformBufferFactory.d.ts +12 -0
  30. package/lib/commonjs/skia/types/PlatformBuffer/PlatformBufferFactory.js +6 -0
  31. package/lib/commonjs/skia/types/PlatformBuffer/PlatformBufferFactory.js.map +1 -0
  32. package/lib/commonjs/skia/types/PlatformBuffer/index.d.ts +1 -0
  33. package/lib/commonjs/skia/types/PlatformBuffer/index.js +17 -0
  34. package/lib/commonjs/skia/types/PlatformBuffer/index.js.map +1 -0
  35. package/lib/commonjs/skia/types/Skia.d.ts +2 -0
  36. package/lib/commonjs/skia/types/Skia.js.map +1 -1
  37. package/lib/commonjs/skia/types/Surface/Surface.d.ts +8 -0
  38. package/lib/commonjs/skia/types/Surface/Surface.js.map +1 -1
  39. package/lib/commonjs/skia/types/index.d.ts +1 -0
  40. package/lib/commonjs/skia/types/index.js +11 -0
  41. package/lib/commonjs/skia/types/index.js.map +1 -1
  42. package/lib/commonjs/skia/web/JsiSkImage.d.ts +1 -2
  43. package/lib/commonjs/skia/web/JsiSkImage.js +5 -12
  44. package/lib/commonjs/skia/web/JsiSkImage.js.map +1 -1
  45. package/lib/commonjs/skia/web/JsiSkImageFactory.d.ts +2 -2
  46. package/lib/commonjs/skia/web/JsiSkImageFactory.js +3 -0
  47. package/lib/commonjs/skia/web/JsiSkImageFactory.js.map +1 -1
  48. package/lib/commonjs/skia/web/JsiSkPlatformBufferFactory.d.ts +8 -0
  49. package/lib/commonjs/skia/web/JsiSkPlatformBufferFactory.js +20 -0
  50. package/lib/commonjs/skia/web/JsiSkPlatformBufferFactory.js.map +1 -0
  51. package/lib/commonjs/skia/web/JsiSkSurface.d.ts +3 -2
  52. package/lib/commonjs/skia/web/JsiSkSurface.js +8 -6
  53. package/lib/commonjs/skia/web/JsiSkSurface.js.map +1 -1
  54. package/lib/commonjs/skia/web/JsiSkSurfaceFactory.d.ts +1 -1
  55. package/lib/commonjs/skia/web/JsiSkSurfaceFactory.js +1 -16
  56. package/lib/commonjs/skia/web/JsiSkSurfaceFactory.js.map +1 -1
  57. package/lib/commonjs/skia/web/JsiSkia.js +3 -1
  58. package/lib/commonjs/skia/web/JsiSkia.js.map +1 -1
  59. package/lib/module/external/reanimated/textures.js +11 -2
  60. package/lib/module/external/reanimated/textures.js.map +1 -1
  61. package/lib/module/external/reanimated/useAnimatedImageValue.d.ts +2 -1
  62. package/lib/module/external/reanimated/useAnimatedImageValue.js +8 -4
  63. package/lib/module/external/reanimated/useAnimatedImageValue.js.map +1 -1
  64. package/lib/module/renderer/Offscreen.d.ts +2 -2
  65. package/lib/module/renderer/Offscreen.js +2 -2
  66. package/lib/module/renderer/Offscreen.js.map +1 -1
  67. package/lib/module/skia/types/Image/ImageFactory.d.ts +14 -0
  68. package/lib/module/skia/types/Image/ImageFactory.js.map +1 -1
  69. package/lib/module/skia/types/PlatformBuffer/PlatformBufferFactory.d.ts +12 -0
  70. package/lib/module/skia/types/PlatformBuffer/PlatformBufferFactory.js +2 -0
  71. package/lib/module/skia/types/PlatformBuffer/PlatformBufferFactory.js.map +1 -0
  72. package/lib/module/skia/types/PlatformBuffer/index.d.ts +1 -0
  73. package/lib/module/skia/types/PlatformBuffer/index.js +2 -0
  74. package/lib/module/skia/types/PlatformBuffer/index.js.map +1 -0
  75. package/lib/module/skia/types/Skia.d.ts +2 -0
  76. package/lib/module/skia/types/Skia.js.map +1 -1
  77. package/lib/module/skia/types/Surface/Surface.d.ts +8 -0
  78. package/lib/module/skia/types/Surface/Surface.js.map +1 -1
  79. package/lib/module/skia/types/index.d.ts +1 -0
  80. package/lib/module/skia/types/index.js +1 -0
  81. package/lib/module/skia/types/index.js.map +1 -1
  82. package/lib/module/skia/web/JsiSkImage.d.ts +1 -2
  83. package/lib/module/skia/web/JsiSkImage.js +5 -12
  84. package/lib/module/skia/web/JsiSkImage.js.map +1 -1
  85. package/lib/module/skia/web/JsiSkImageFactory.d.ts +2 -2
  86. package/lib/module/skia/web/JsiSkImageFactory.js +3 -0
  87. package/lib/module/skia/web/JsiSkImageFactory.js.map +1 -1
  88. package/lib/module/skia/web/JsiSkPlatformBufferFactory.d.ts +8 -0
  89. package/lib/module/skia/web/JsiSkPlatformBufferFactory.js +13 -0
  90. package/lib/module/skia/web/JsiSkPlatformBufferFactory.js.map +1 -0
  91. package/lib/module/skia/web/JsiSkSurface.d.ts +3 -2
  92. package/lib/module/skia/web/JsiSkSurface.js +8 -6
  93. package/lib/module/skia/web/JsiSkSurface.js.map +1 -1
  94. package/lib/module/skia/web/JsiSkSurfaceFactory.d.ts +1 -1
  95. package/lib/module/skia/web/JsiSkSurfaceFactory.js +1 -16
  96. package/lib/module/skia/web/JsiSkSurfaceFactory.js.map +1 -1
  97. package/lib/module/skia/web/JsiSkia.js +3 -1
  98. package/lib/module/skia/web/JsiSkia.js.map +1 -1
  99. package/lib/typescript/src/external/reanimated/useAnimatedImageValue.d.ts +2 -1
  100. package/lib/typescript/src/renderer/Offscreen.d.ts +2 -2
  101. package/lib/typescript/src/skia/types/Image/ImageFactory.d.ts +14 -0
  102. package/lib/typescript/src/skia/types/PlatformBuffer/PlatformBufferFactory.d.ts +12 -0
  103. package/lib/typescript/src/skia/types/PlatformBuffer/index.d.ts +1 -0
  104. package/lib/typescript/src/skia/types/Skia.d.ts +2 -0
  105. package/lib/typescript/src/skia/types/Surface/Surface.d.ts +8 -0
  106. package/lib/typescript/src/skia/types/index.d.ts +1 -0
  107. package/lib/typescript/src/skia/web/JsiSkImage.d.ts +1 -2
  108. package/lib/typescript/src/skia/web/JsiSkImageFactory.d.ts +2 -2
  109. package/lib/typescript/src/skia/web/JsiSkPlatformBufferFactory.d.ts +8 -0
  110. package/lib/typescript/src/skia/web/JsiSkSurface.d.ts +3 -2
  111. package/lib/typescript/src/skia/web/JsiSkSurfaceFactory.d.ts +1 -1
  112. package/package.json +1 -1
  113. package/src/external/reanimated/textures.tsx +8 -2
  114. package/src/external/reanimated/useAnimatedImageValue.ts +12 -6
  115. package/src/renderer/Offscreen.tsx +3 -3
  116. package/src/skia/types/Image/ImageFactory.ts +15 -0
  117. package/src/skia/types/PlatformBuffer/PlatformBufferFactory.ts +14 -0
  118. package/src/skia/types/PlatformBuffer/index.ts +1 -0
  119. package/src/skia/types/Skia.ts +2 -1
  120. package/src/skia/types/Surface/Surface.ts +10 -0
  121. package/src/skia/types/index.ts +1 -0
  122. package/src/skia/web/JsiSkImage.ts +5 -22
  123. package/src/skia/web/JsiSkImageFactory.ts +13 -2
  124. package/src/skia/web/JsiSkPlatformBufferFactory.ts +22 -0
  125. package/src/skia/web/JsiSkSurface.ts +10 -9
  126. package/src/skia/web/JsiSkSurfaceFactory.ts +3 -19
  127. package/src/skia/web/JsiSkia.ts +2 -0
  128. package/cpp/skia/include/third_party/vulkan/LICENSE +0 -29
  129. package/cpp/skia/modules/skcms/README.chromium +0 -6
  130. package/cpp/skia/readme.txt +0 -1
@@ -30,6 +30,7 @@ import type { Color, SkColor } from "./Color";
30
30
  import type { TypefaceFontProviderFactory } from "./Paragraph/TypefaceFontProviderFactory";
31
31
  import type { AnimatedImageFactory } from "./AnimatedImage";
32
32
  import type { ParagraphBuilderFactory } from "./Paragraph/ParagraphBuilder";
33
+ import type { PlatformBufferFactory } from "./PlatformBuffer";
33
34
 
34
35
  /**
35
36
  * Declares the interface for the native Skia API
@@ -93,6 +94,6 @@ export interface Skia {
93
94
  SVG: SVGFactory;
94
95
  TextBlob: TextBlobFactory;
95
96
  Surface: SurfaceFactory;
96
- // Paragraph
97
97
  ParagraphBuilder: ParagraphBuilderFactory;
98
+ PlatformBuffer: PlatformBufferFactory;
98
99
  }
@@ -29,4 +29,14 @@ export interface SkSurface extends SkJSIInstance<"Surface"> {
29
29
  * Make sure any queued draws are sent to the screen or the GPU.
30
30
  */
31
31
  flush(): void;
32
+
33
+ /**
34
+ * Returns the possibly scaled width of the surface.
35
+ */
36
+ width(): number;
37
+
38
+ /**
39
+ * Returns the possibly scaled height of the surface.
40
+ */
41
+ height(): number;
32
42
  }
@@ -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 "./PlatformBuffer";
@@ -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
  }
@@ -1,7 +1,12 @@
1
1
  import type { CanvasKit } from "canvaskit-wasm";
2
2
 
3
- import type { SkData, ImageInfo, SkImage } from "../types";
4
- import type { ImageFactory } from "../types/Image/ImageFactory";
3
+ import type {
4
+ SkData,
5
+ ImageInfo,
6
+ SkImage,
7
+ PlatformBuffer,
8
+ ImageFactory,
9
+ } from "../types";
5
10
 
6
11
  import { Host, getEnum } from "./Host";
7
12
  import { JsiSkImage } from "./JsiSkImage";
@@ -19,6 +24,12 @@ export class JsiSkImageFactory extends Host implements ImageFactory {
19
24
  return Promise.resolve(null);
20
25
  }
21
26
 
27
+ MakeImageFromPlatformBuffer(_platformBuffer: PlatformBuffer): SkImage {
28
+ throw new Error(
29
+ "MakeImageFromPlatformBuffer() is only available on iOS and Android!"
30
+ );
31
+ }
32
+
22
33
  MakeImageFromEncoded(encoded: SkData) {
23
34
  const image = this.CanvasKit.MakeImageFromEncoded(
24
35
  JsiSkData.fromValue(encoded)
@@ -0,0 +1,22 @@
1
+ import type { CanvasKit } from "canvaskit-wasm";
2
+
3
+ import type { PlatformBuffer, PlatformBufferFactory, SkImage } from "../types";
4
+
5
+ import { Host, NotImplementedOnRNWeb } from "./Host";
6
+
7
+ export class JsiSkPlatformBufferFactory
8
+ extends Host
9
+ implements PlatformBufferFactory
10
+ {
11
+ constructor(CanvasKit: CanvasKit) {
12
+ super(CanvasKit);
13
+ }
14
+
15
+ MakeFromImage(_image: SkImage): PlatformBuffer {
16
+ throw new NotImplementedOnRNWeb();
17
+ }
18
+
19
+ Release(_platformBuffer: PlatformBuffer) {
20
+ throw new NotImplementedOnRNWeb();
21
+ }
22
+ }
@@ -11,25 +11,26 @@ export class JsiSkSurface
11
11
  extends HostObject<Surface, "Surface">
12
12
  implements SkSurface
13
13
  {
14
- constructor(
15
- CanvasKit: CanvasKit,
16
- ref: Surface,
17
- private releaseCtx?: () => void
18
- ) {
14
+ constructor(CanvasKit: CanvasKit, ref: Surface) {
19
15
  super(CanvasKit, ref, "Surface");
20
16
  }
21
17
 
22
18
  dispose = () => {
23
- this.ref.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 { JsiSkPlatformBufferFactory } from "./JsiSkPlatformBufferFactory";
44
45
 
45
46
  export const JsiSkApi = (CanvasKit: CanvasKit): Skia => ({
46
47
  Point: (x: number, y: number) =>
@@ -125,4 +126,5 @@ export const JsiSkApi = (CanvasKit: CanvasKit): Skia => ({
125
126
  TypefaceFontProvider: new JsiSkTypefaceFontProviderFactory(CanvasKit),
126
127
  FontMgr: new JsiSkFontMgrFactory(CanvasKit),
127
128
  ParagraphBuilder: new JsiSkParagraphBuilderFactory(CanvasKit),
129
+ PlatformBuffer: new JsiSkPlatformBufferFactory(CanvasKit),
128
130
  });
@@ -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.