@shopify/react-native-skia 2.5.0 → 2.5.2

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 (41) hide show
  1. package/android/CMakeLists.txt +4 -6
  2. package/android/build.gradle +5 -32
  3. package/android/cpp/rnskia-android/OpenGLContext.h +9 -2
  4. package/android/cpp/rnskia-android/RNSkAndroidPlatformContext.h +6 -3
  5. package/apple/MetalContext.h +10 -2
  6. package/apple/MetalWindowContext.h +1 -0
  7. package/apple/MetalWindowContext.mm +8 -1
  8. package/apple/RNSkApplePlatformContext.h +2 -1
  9. package/apple/RNSkApplePlatformContext.mm +6 -4
  10. package/apple/SkiaPictureView.mm +3 -0
  11. package/cpp/api/JsiSkImage.h +76 -0
  12. package/cpp/api/JsiSkSurfaceFactory.h +12 -1
  13. package/cpp/api/recorder/Drawings.h +1 -1
  14. package/cpp/rnskia/RNDawnContext.h +24 -16
  15. package/cpp/rnskia/RNDawnUtils.h +12 -0
  16. package/cpp/rnskia/RNSkPlatformContext.h +3 -1
  17. package/lib/commonjs/dom/types/Drawings.d.ts +1 -0
  18. package/lib/commonjs/dom/types/Drawings.js.map +1 -1
  19. package/lib/commonjs/skia/types/Surface/SurfaceFactory.d.ts +10 -1
  20. package/lib/commonjs/skia/types/Surface/SurfaceFactory.js +5 -0
  21. package/lib/commonjs/skia/types/Surface/SurfaceFactory.js.map +1 -1
  22. package/lib/commonjs/sksg/Recorder/commands/Drawing.js +2 -2
  23. package/lib/commonjs/sksg/Recorder/commands/Drawing.js.map +1 -1
  24. package/lib/module/dom/types/Drawings.d.ts +1 -0
  25. package/lib/module/dom/types/Drawings.js.map +1 -1
  26. package/lib/module/skia/types/Surface/SurfaceFactory.d.ts +10 -1
  27. package/lib/module/skia/types/Surface/SurfaceFactory.js +4 -1
  28. package/lib/module/skia/types/Surface/SurfaceFactory.js.map +1 -1
  29. package/lib/module/sksg/Recorder/commands/Drawing.js +2 -2
  30. package/lib/module/sksg/Recorder/commands/Drawing.js.map +1 -1
  31. package/lib/typescript/lib/commonjs/skia/types/Surface/SurfaceFactory.d.ts +4 -0
  32. package/lib/typescript/lib/module/mock/index.d.ts +4 -0
  33. package/lib/typescript/lib/module/skia/types/Surface/SurfaceFactory.d.ts +4 -1
  34. package/lib/typescript/src/dom/types/Drawings.d.ts +1 -0
  35. package/lib/typescript/src/skia/types/Surface/SurfaceFactory.d.ts +10 -1
  36. package/package.json +5 -2
  37. package/react-native-skia.podspec +20 -104
  38. package/scripts/install-libs.js +131 -0
  39. package/src/dom/types/Drawings.ts +1 -0
  40. package/src/skia/types/Surface/SurfaceFactory.ts +13 -1
  41. package/src/sksg/Recorder/commands/Drawing.ts +3 -2
@@ -0,0 +1,131 @@
1
+ #!/usr/bin/env node
2
+ "use strict";
3
+
4
+ const path = require("path");
5
+ const fs = require("fs");
6
+ const { execSync } = require("child_process");
7
+
8
+ const useGraphite =
9
+ process.env.SK_GRAPHITE === "1" ||
10
+ (process.env.SK_GRAPHITE || "").toLowerCase() === "true";
11
+ const prefix = useGraphite ? "react-native-skia-graphite" : "react-native-skia";
12
+ const libsDir = path.join(__dirname, "..", "libs");
13
+
14
+ // --- Apple platforms ---
15
+
16
+ let iosPackage, macosPackage;
17
+ try {
18
+ iosPackage = path.dirname(
19
+ require.resolve(prefix + "-apple-ios/package.json")
20
+ );
21
+ macosPackage = path.dirname(
22
+ require.resolve(prefix + "-apple-macos/package.json")
23
+ );
24
+ } catch (e) {
25
+ console.error(
26
+ "ERROR: Could not find " +
27
+ prefix +
28
+ "-apple-ios or " +
29
+ prefix +
30
+ "-apple-macos"
31
+ );
32
+ console.error("Make sure you have run yarn install or npm install");
33
+ process.exit(1);
34
+ }
35
+
36
+ // Verify xcframeworks exist in the iOS package
37
+ const iosXcf = path.join(iosPackage, "libs");
38
+ if (
39
+ !fs.existsSync(iosXcf) ||
40
+ !fs.readdirSync(iosXcf).some((f) => f.endsWith(".xcframework"))
41
+ ) {
42
+ console.error(
43
+ "ERROR: Skia prebuilt binaries not found in " + prefix + "-apple-ios!"
44
+ );
45
+ process.exit(1);
46
+ }
47
+
48
+ console.log("-- Skia iOS package: " + iosPackage);
49
+ console.log("-- Skia macOS package: " + macosPackage);
50
+
51
+ // Clean and copy Apple frameworks
52
+ execSync(
53
+ "rm -rf " +
54
+ path.join(libsDir, "ios") +
55
+ " " +
56
+ path.join(libsDir, "macos") +
57
+ " " +
58
+ path.join(libsDir, "tvos")
59
+ );
60
+ fs.mkdirSync(path.join(libsDir, "ios"), { recursive: true });
61
+ fs.mkdirSync(path.join(libsDir, "macos"), { recursive: true });
62
+ execSync(
63
+ 'cp -R "' +
64
+ iosPackage +
65
+ '/libs/"*.xcframework "' +
66
+ path.join(libsDir, "ios") +
67
+ '/"'
68
+ );
69
+ execSync(
70
+ 'cp -R "' +
71
+ macosPackage +
72
+ '/libs/"*.xcframework "' +
73
+ path.join(libsDir, "macos") +
74
+ '/"'
75
+ );
76
+
77
+ // Handle tvOS (non-Graphite only)
78
+ if (!useGraphite) {
79
+ try {
80
+ const tvosPackage = path.dirname(
81
+ require.resolve(prefix + "-apple-tvos/package.json")
82
+ );
83
+ console.log("-- Skia tvOS package: " + tvosPackage);
84
+ fs.mkdirSync(path.join(libsDir, "tvos"), { recursive: true });
85
+ execSync(
86
+ 'cp -R "' +
87
+ tvosPackage +
88
+ '/libs/"*.xcframework "' +
89
+ path.join(libsDir, "tvos") +
90
+ '/"'
91
+ );
92
+ } catch (e) {
93
+ console.log("-- tvOS package not found, skipping");
94
+ }
95
+ }
96
+
97
+ console.log("-- Copied Apple xcframeworks to libs/");
98
+
99
+ // --- Android ---
100
+
101
+ const androidPackageName = useGraphite
102
+ ? "react-native-skia-graphite-android"
103
+ : "react-native-skia-android";
104
+
105
+ let androidPackage;
106
+ try {
107
+ androidPackage = path.dirname(
108
+ require.resolve(androidPackageName + "/package.json")
109
+ );
110
+ } catch (e) {
111
+ console.error("ERROR: Could not find " + androidPackageName);
112
+ console.error("Make sure you have run yarn install or npm install");
113
+ process.exit(1);
114
+ }
115
+
116
+ const androidSrcLibs = path.join(androidPackage, "libs");
117
+ if (!fs.existsSync(androidSrcLibs)) {
118
+ console.error(
119
+ "ERROR: Skia prebuilt binaries not found in " + androidPackageName + "!"
120
+ );
121
+ process.exit(1);
122
+ }
123
+
124
+ console.log("-- Skia Android package: " + androidPackage);
125
+
126
+ // Copy Android libs (per-ABI static libraries)
127
+ const androidDest = path.join(libsDir, "android");
128
+ execSync("rm -rf " + androidDest);
129
+ execSync('cp -R "' + androidSrcLibs + '" "' + androidDest + '"');
130
+
131
+ console.log("-- Copied Android libs to libs/android/");
@@ -69,6 +69,7 @@ export interface AtlasProps extends DrawingNodeProps {
69
69
  sprites: SkRect[];
70
70
  transforms: SkRSXform[];
71
71
  colors?: SkColor[];
72
+ colorBlendMode?: SkEnum<typeof BlendMode>;
72
73
  sampling?: SamplingOptions;
73
74
  }
74
75
 
@@ -1,5 +1,16 @@
1
1
  import type { SkSurface } from "./Surface";
2
2
 
3
+ export const ColorSpace = {
4
+ SRGB: "srgb",
5
+ DisplayP3: "display-p3",
6
+ } as const;
7
+
8
+ export type ColorSpaceValue = (typeof ColorSpace)[keyof typeof ColorSpace];
9
+
10
+ export interface SurfaceOptions {
11
+ colorSpace: ColorSpaceValue;
12
+ }
13
+
3
14
  export interface SurfaceFactory {
4
15
  /**
5
16
  * Returns a CPU backed surface with the given dimensions, an SRGB colorspace, Unpremul
@@ -14,6 +25,7 @@ export interface SurfaceFactory {
14
25
  * Creates a GPU backed surface.
15
26
  * @param width - number of pixels of the width of the drawable area.
16
27
  * @param height - number of pixels of the height of the drawable area.
28
+ * @param opts - optional surface options (e.g. colorSpace: "display-p3" | "srgb").
17
29
  */
18
- MakeOffscreen: (width: number, height: number) => SkSurface | null;
30
+ MakeOffscreen: (width: number, height: number, opts?: SurfaceOptions) => SkSurface | null;
19
31
  }
@@ -306,8 +306,9 @@ export const drawPicture = (ctx: DrawingContext, props: PictureProps) => {
306
306
 
307
307
  export const drawAtlas = (ctx: DrawingContext, props: AtlasProps) => {
308
308
  "worklet";
309
- const { image, sprites, transforms, colors, blendMode, sampling } = props;
310
- const blend = blendMode ? BlendMode[enumKey(blendMode)] : undefined;
309
+ const { image, sprites, transforms, colors, colorBlendMode, sampling } =
310
+ props;
311
+ const blend = colorBlendMode ? BlendMode[enumKey(colorBlendMode)] : undefined;
311
312
  if (image) {
312
313
  ctx.canvas.drawAtlas(
313
314
  image,