@shopify/react-native-skia 0.1.120 → 0.1.123

Sign up to get free protection for your applications and to get access to all the features.
Files changed (111) hide show
  1. package/android/CMakeLists.txt +33 -17
  2. package/android/build.gradle +81 -34
  3. package/android/cpp/jni/JniSkiaDrawView.cpp +14 -71
  4. package/android/cpp/jni/JniSkiaManager.cpp +1 -1
  5. package/android/cpp/jni/include/JniSkiaDrawView.h +18 -22
  6. package/android/cpp/jni/include/JniSkiaManager.h +4 -4
  7. package/android/cpp/rnskia-android/RNSkDrawViewImpl.cpp +68 -0
  8. package/android/cpp/rnskia-android/RNSkDrawViewImpl.h +48 -0
  9. package/android/cpp/{jni/include/JniPlatformContextWrapper.h → rnskia-android/RNSkPlatformContextImpl.h} +4 -4
  10. package/android/cpp/{jni → rnskia-android}/SkiaOpenGLRenderer.cpp +39 -54
  11. package/android/cpp/{jni/include → rnskia-android}/SkiaOpenGLRenderer.h +2 -31
  12. package/android/src/main/java/com/shopify/reactnative/skia/PlatformContext.java +1 -1
  13. package/android/src/main/java/com/shopify/reactnative/skia/RNSkiaViewManager.java +1 -1
  14. package/android/src/main/java/com/shopify/reactnative/skia/SkiaDrawView.java +21 -28
  15. package/cpp/api/JsiSkApi.h +2 -0
  16. package/cpp/api/JsiSkColor.h +49 -0
  17. package/cpp/api/JsiSkPath.h +31 -2
  18. package/cpp/api/JsiSkPathFactory.h +96 -1
  19. package/cpp/api/third_party/CSSColorParser.h +324 -0
  20. package/cpp/rnskia/RNSkAnimation.h +4 -7
  21. package/cpp/rnskia/RNSkDrawView.cpp +77 -116
  22. package/cpp/rnskia/RNSkDrawView.h +5 -35
  23. package/cpp/rnskia/RNSkJsiViewApi.h +8 -5
  24. package/cpp/rnskia/RNSkManager.cpp +2 -2
  25. package/cpp/rnskia/RNSkManager.h +2 -2
  26. package/cpp/rnskia/RNSkPlatformContext.h +1 -1
  27. package/cpp/rnskia/values/RNSkClockValue.h +19 -11
  28. package/cpp/rnskia/values/RNSkDerivedValue.h +1 -1
  29. package/cpp/rnskia/values/RNSkReadonlyValue.h +15 -15
  30. package/cpp/utils/RNSkTimingInfo.h +13 -1
  31. package/ios/RNSkia-iOS/RNSkDrawViewImpl.h +5 -7
  32. package/ios/RNSkia-iOS/RNSkDrawViewImpl.mm +25 -10
  33. package/ios/RNSkia-iOS/SkiaDrawView.mm +21 -15
  34. package/lib/commonjs/renderer/Canvas.js +3 -3
  35. package/lib/commonjs/renderer/Canvas.js.map +1 -1
  36. package/lib/commonjs/renderer/components/Paint.js +1 -1
  37. package/lib/commonjs/renderer/components/Paint.js.map +1 -1
  38. package/lib/commonjs/renderer/components/shapes/Path.js +10 -2
  39. package/lib/commonjs/renderer/components/shapes/Path.js.map +1 -1
  40. package/lib/commonjs/renderer/nodes/Node.js +3 -3
  41. package/lib/commonjs/renderer/nodes/Node.js.map +1 -1
  42. package/lib/commonjs/renderer/processors/Paint.js +6 -1
  43. package/lib/commonjs/renderer/processors/Paint.js.map +1 -1
  44. package/lib/commonjs/skia/Color.js +3 -25
  45. package/lib/commonjs/skia/Color.js.map +1 -1
  46. package/lib/commonjs/skia/Image/Image.js.map +1 -1
  47. package/lib/commonjs/skia/ImageFilter/ImageFilterFactory.js.map +1 -1
  48. package/lib/commonjs/skia/Paint/Paint.js +13 -1
  49. package/lib/commonjs/skia/Paint/Paint.js.map +1 -1
  50. package/lib/commonjs/skia/Paint/usePaint.js +2 -4
  51. package/lib/commonjs/skia/Paint/usePaint.js.map +1 -1
  52. package/lib/commonjs/skia/Path/Path.js +13 -1
  53. package/lib/commonjs/skia/Path/Path.js.map +1 -1
  54. package/lib/commonjs/skia/Shader/Shader.js.map +1 -1
  55. package/lib/commonjs/skia/Skia.js +43 -3
  56. package/lib/commonjs/skia/Skia.js.map +1 -1
  57. package/lib/module/renderer/Canvas.js +2 -2
  58. package/lib/module/renderer/Canvas.js.map +1 -1
  59. package/lib/module/renderer/components/Paint.js +2 -2
  60. package/lib/module/renderer/components/Paint.js.map +1 -1
  61. package/lib/module/renderer/components/shapes/Path.js +10 -3
  62. package/lib/module/renderer/components/shapes/Path.js.map +1 -1
  63. package/lib/module/renderer/nodes/Node.js +3 -3
  64. package/lib/module/renderer/nodes/Node.js.map +1 -1
  65. package/lib/module/renderer/processors/Paint.js +6 -1
  66. package/lib/module/renderer/processors/Paint.js.map +1 -1
  67. package/lib/module/skia/Color.js +2 -21
  68. package/lib/module/skia/Color.js.map +1 -1
  69. package/lib/module/skia/Image/Image.js.map +1 -1
  70. package/lib/module/skia/ImageFilter/ImageFilterFactory.js.map +1 -1
  71. package/lib/module/skia/Paint/Paint.js +6 -0
  72. package/lib/module/skia/Paint/Paint.js.map +1 -1
  73. package/lib/module/skia/Paint/usePaint.js +2 -3
  74. package/lib/module/skia/Paint/usePaint.js.map +1 -1
  75. package/lib/module/skia/Path/Path.js +11 -0
  76. package/lib/module/skia/Path/Path.js.map +1 -1
  77. package/lib/module/skia/Shader/Shader.js.map +1 -1
  78. package/lib/module/skia/Skia.js +45 -2
  79. package/lib/module/skia/Skia.js.map +1 -1
  80. package/lib/typescript/src/renderer/components/shapes/Path.d.ts +3 -1
  81. package/lib/typescript/src/renderer/processors/Paint.d.ts +2 -1
  82. package/lib/typescript/src/skia/Color.d.ts +0 -1
  83. package/lib/typescript/src/skia/Image/Image.d.ts +3 -3
  84. package/lib/typescript/src/skia/ImageFilter/ImageFilterFactory.d.ts +2 -2
  85. package/lib/typescript/src/skia/Paint/Paint.d.ts +3 -2
  86. package/lib/typescript/src/skia/Path/Path.d.ts +13 -0
  87. package/lib/typescript/src/skia/Path/PathFactory.d.ts +7 -1
  88. package/lib/typescript/src/skia/Picture/Picture.d.ts +2 -2
  89. package/lib/typescript/src/skia/RuntimeEffect/RuntimeEffect.d.ts +3 -3
  90. package/lib/typescript/src/skia/Shader/Shader.d.ts +2 -2
  91. package/lib/typescript/src/skia/Shader/ShaderFactory.d.ts +9 -9
  92. package/lib/typescript/src/skia/Skia.d.ts +5 -3
  93. package/package.json +1 -1
  94. package/scripts/install-npm.js +1 -1
  95. package/src/renderer/Canvas.tsx +2 -2
  96. package/src/renderer/components/Paint.tsx +2 -2
  97. package/src/renderer/components/shapes/Path.tsx +12 -4
  98. package/src/renderer/nodes/Node.ts +3 -3
  99. package/src/renderer/processors/Paint.ts +5 -0
  100. package/src/skia/Color.ts +3 -20
  101. package/src/skia/Image/Image.ts +3 -3
  102. package/src/skia/ImageFilter/ImageFilterFactory.ts +2 -2
  103. package/src/skia/Paint/Paint.ts +9 -2
  104. package/src/skia/Paint/usePaint.ts +2 -4
  105. package/src/skia/Path/Path.ts +16 -0
  106. package/src/skia/Path/PathFactory.ts +8 -1
  107. package/src/skia/Picture/Picture.ts +2 -2
  108. package/src/skia/RuntimeEffect/RuntimeEffect.ts +4 -4
  109. package/src/skia/Shader/Shader.ts +2 -2
  110. package/src/skia/Shader/ShaderFactory.ts +9 -9
  111. package/src/skia/Skia.ts +47 -3
@@ -38,6 +38,17 @@ export enum PathOp {
38
38
  ReverseDifference,
39
39
  }
40
40
 
41
+ export enum PathVerb {
42
+ Move,
43
+ Line,
44
+ Quad,
45
+ Conic,
46
+ Cubic,
47
+ Close,
48
+ }
49
+
50
+ export type PathCommand = number[];
51
+
41
52
  export const isPath = (obj: SkJSIInstance<string> | null): obj is SkPath =>
42
53
  obj !== null && obj.__typename__ === "Path";
43
54
 
@@ -535,4 +546,9 @@ export interface SkPath extends SkJSIInstance<"Path"> {
535
546
  *
536
547
  * */
537
548
  isInterpolatable(compare: SkPath): boolean;
549
+
550
+ /**
551
+ * Serializes the contents of this path as a series of commands.
552
+ */
553
+ toCmds(): PathCommand[];
538
554
  }
@@ -1,4 +1,4 @@
1
- import type { SkPath, PathOp } from "./Path";
1
+ import type { SkPath, PathOp, PathCommand } from "./Path";
2
2
 
3
3
  export interface PathFactory {
4
4
  Make(): SkPath;
@@ -17,4 +17,11 @@ export interface PathFactory {
17
17
  * @param op
18
18
  */
19
19
  MakeFromOp(one: SkPath, two: SkPath, op: PathOp): SkPath | null;
20
+
21
+ /**
22
+ * Creates a new path from the given list of path commands. If this fails, null will be
23
+ * returned instead.
24
+ * @param cmds
25
+ */
26
+ MakeFromCmds(cmds: PathCommand[]): SkPath | null;
20
27
  }
@@ -2,7 +2,7 @@ import type { InputColorMatrix } from "../ColorFilter";
2
2
  import type { FilterMode } from "../Image";
3
3
  import type { TileMode } from "../ImageFilter";
4
4
  import type { SkRect } from "../Rect";
5
- import type { IShader } from "../Shader";
5
+ import type { SkShader } from "../Shader";
6
6
 
7
7
  export interface SkPicture {
8
8
  /**
@@ -24,7 +24,7 @@ export interface SkPicture {
24
24
  mode: FilterMode,
25
25
  localMatrix?: InputColorMatrix,
26
26
  tileRect?: SkRect
27
- ): IShader;
27
+ ): SkShader;
28
28
 
29
29
  /**
30
30
  * Returns the serialized format of this SkPicture. The format may change at anytime and
@@ -1,4 +1,4 @@
1
- import type { IShader } from "../Shader";
1
+ import type { SkShader } from "../Shader";
2
2
  import type { SkJSIInstance } from "../JsiInstance";
3
3
  import type { SkMatrix } from "../Matrix";
4
4
 
@@ -21,7 +21,7 @@ export interface IRuntimeEffect extends SkJSIInstance<"RuntimeEffect"> {
21
21
  uniforms: number[],
22
22
  isOpaque?: boolean,
23
23
  localMatrix?: SkMatrix
24
- ): IShader;
24
+ ): SkShader;
25
25
 
26
26
  /**
27
27
  * Returns a shader executed using the given uniform data and the children as inputs.
@@ -33,9 +33,9 @@ export interface IRuntimeEffect extends SkJSIInstance<"RuntimeEffect"> {
33
33
  makeShaderWithChildren(
34
34
  uniforms: number[],
35
35
  isOpaque?: boolean,
36
- children?: IShader[],
36
+ children?: SkShader[],
37
37
  localMatrix?: SkMatrix
38
- ): IShader;
38
+ ): SkShader;
39
39
 
40
40
  /**
41
41
  * Returns the nth uniform from the effect.
@@ -1,6 +1,6 @@
1
1
  import type { SkJSIInstance } from "../JsiInstance";
2
2
 
3
- export const isShader = (obj: SkJSIInstance<string> | null): obj is IShader =>
3
+ export const isShader = (obj: SkJSIInstance<string> | null): obj is SkShader =>
4
4
  obj !== null && obj.__typename__ === "Shader";
5
5
 
6
- export type IShader = SkJSIInstance<"Shader">;
6
+ export type SkShader = SkJSIInstance<"Shader">;
@@ -4,7 +4,7 @@ import type { SkMatrix } from "../Matrix";
4
4
  import type { SkColor } from "../Color";
5
5
  import type { BlendMode } from "../Paint/BlendMode";
6
6
 
7
- import type { IShader } from "./Shader";
7
+ import type { SkShader } from "./Shader";
8
8
 
9
9
  export interface ShaderFactory {
10
10
  /**
@@ -31,7 +31,7 @@ export interface ShaderFactory {
31
31
  localMatrix?: SkMatrix,
32
32
  flags?: number
33
33
  // colorSpace: ColorSpace
34
- ): IShader;
34
+ ): SkShader;
35
35
 
36
36
  /**
37
37
  * Returns a shader that generates a radial gradient given the center and radius.
@@ -54,7 +54,7 @@ export interface ShaderFactory {
54
54
  localMatrix?: SkMatrix,
55
55
  flags?: number
56
56
  // colorSpace?: ColorSpace
57
- ): IShader;
57
+ ): SkShader;
58
58
 
59
59
  /**
60
60
  * Returns a shader that generates a conical gradient given two circles.
@@ -80,7 +80,7 @@ export interface ShaderFactory {
80
80
  localMatrix?: SkMatrix,
81
81
  flags?: number
82
82
  // colorSpace?: ColorSpace
83
- ): IShader;
83
+ ): SkShader;
84
84
 
85
85
  /**
86
86
  * Returns a shader that generates a sweep gradient given a center.
@@ -107,7 +107,7 @@ export interface ShaderFactory {
107
107
  startAngleInDegrees?: number,
108
108
  endAngleInDegrees?: number
109
109
  // colorSpace?: ColorSpace
110
- ): IShader;
110
+ ): SkShader;
111
111
 
112
112
  /**
113
113
  * Returns a shader with Perlin Turbulence.
@@ -128,7 +128,7 @@ export interface ShaderFactory {
128
128
  seed: number,
129
129
  tileW: number,
130
130
  tileH: number
131
- ): IShader;
131
+ ): SkShader;
132
132
 
133
133
  /**
134
134
  * Returns a shader with Perlin Fractal Noise.
@@ -149,7 +149,7 @@ export interface ShaderFactory {
149
149
  seed: number,
150
150
  tileW: number,
151
151
  tileH: number
152
- ): IShader;
152
+ ): SkShader;
153
153
 
154
154
  /**
155
155
  * Returns a shader that combines the given shaders with a BlendMode.
@@ -157,7 +157,7 @@ export interface ShaderFactory {
157
157
  * @param one
158
158
  * @param two
159
159
  */
160
- MakeBlend(mode: BlendMode, one: IShader, two: IShader): IShader;
160
+ MakeBlend(mode: BlendMode, one: SkShader, two: SkShader): SkShader;
161
161
 
162
162
  /**
163
163
  * Returns a shader with a given color and colorspace.
@@ -165,5 +165,5 @@ export interface ShaderFactory {
165
165
  */
166
166
  MakeColor(
167
167
  color: SkColor //,space: ColorSpace
168
- ): IShader;
168
+ ): SkShader;
169
169
  }
package/src/skia/Skia.ts CHANGED
@@ -1,3 +1,5 @@
1
+ import { Platform, processColor } from "react-native";
2
+
1
3
  /*global SkiaApi*/
2
4
  import type { ImageFilterFactory } from "./ImageFilter";
3
5
  import type { PathFactory } from "./Path";
@@ -11,8 +13,6 @@ import type { SkRect } from "./Rect";
11
13
  import type { SkRRect } from "./RRect";
12
14
  import type { RuntimeEffectFactory } from "./RuntimeEffect";
13
15
  import type { ShaderFactory } from "./Shader";
14
- import type { SkColor } from "./Color";
15
- import { processColor } from "./Color";
16
16
  import type { SkMatrix } from "./Matrix";
17
17
  import type { PathEffectFactory } from "./PathEffect";
18
18
  import type { SkPoint } from "./Point";
@@ -27,6 +27,45 @@ import type { SkRSXform } from "./RSXform";
27
27
  import type { SkPath } from "./Path/Path";
28
28
  import type { SkContourMeasureIter } from "./ContourMeasure";
29
29
  import type { PictureFactory, SkPictureRecorder } from "./Picture";
30
+ import type { Color, SkColor } from "./Color";
31
+
32
+ /*
33
+ * Parse CSS colors
34
+ */
35
+ const SkiaColor = (cl: Color) => {
36
+ if (typeof cl === "number") {
37
+ return cl;
38
+ }
39
+ const color = Skia.parseColorString(cl);
40
+ if (color !== undefined) {
41
+ return color;
42
+ } else {
43
+ // If the color is not recognized, we fallback to React Native
44
+ let rnColor = processColor(cl);
45
+ // 1. Neither Skia or RN could parse the color
46
+ if (typeof rnColor !== "number") {
47
+ console.warn("Skia couldn't parse the following color " + cl);
48
+ return BLACK;
49
+ // 2. The color is recognized by RN but not by Skia
50
+ } else {
51
+ console.warn(
52
+ "Skia couldn't parse the following color " +
53
+ cl +
54
+ ". The color parsing was delegated to React Native. Please file on issue with that color."
55
+ );
56
+ // On android we need to move the alpha byte to the start of the structure
57
+ if (Platform.OS === "android") {
58
+ rnColor = rnColor >>> 0;
59
+ const a = (rnColor >> 24) & 0xff;
60
+ const r = (rnColor >> 16) & 0xff;
61
+ const g = (rnColor >> 8) & 0xff;
62
+ const b = rnColor & 0xff;
63
+ rnColor = ((a << 24) | (r << 16) | (g << 8) | b) >>> 0;
64
+ }
65
+ return rnColor;
66
+ }
67
+ }
68
+ };
30
69
 
31
70
  /**
32
71
  * Declares the interface for the native Skia API
@@ -36,6 +75,8 @@ export interface Skia {
36
75
  XYWHRect: (x: number, y: number, width: number, height: number) => SkRect;
37
76
  RRectXY: (rect: SkRect, rx: number, ry: number) => SkRRect;
38
77
  RSXform: (scos: number, ssin: number, tx: number, ty: number) => SkRSXform;
78
+ Color: (color: Color) => SkColor;
79
+ parseColorString: (color: string) => SkColor | undefined;
39
80
  ContourMeasureIter: (
40
81
  path: SkPath,
41
82
  forceClosed: boolean,
@@ -115,7 +156,8 @@ export const Skia = {
115
156
  ColorFilter: SkiaApi.ColorFilter,
116
157
  ContourMeasureIter: SkiaApi.ContourMeasureIter,
117
158
  // Here are constructors for data types which are represented as typed arrays in CanvasKit
118
- Color: (color: Parameters<typeof processColor>[0]) => processColor(color, 1),
159
+ Color: SkiaColor,
160
+ parseColorString: SkiaApi.parseColorString,
119
161
  RSXform: SkiaApi.RSXform,
120
162
  // For the following methods the factory symmetry is broken to be comptatible with CanvasKit
121
163
  MakeSurface: SkiaApi.Surface.Make,
@@ -123,3 +165,5 @@ export const Skia = {
123
165
  MakeImage: SkiaApi.Image.MakeImage,
124
166
  MakeVertices: SkiaApi.MakeVertices,
125
167
  };
168
+
169
+ const BLACK = Skia.parseColorString("black")!;