@shopify/react-native-skia 1.10.1 → 1.11.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (107) hide show
  1. package/android/src/main/java/com/shopify/reactnative/skia/SkiaBaseView.java +0 -13
  2. package/android/src/main/java/com/shopify/reactnative/skia/SkiaTextureView.java +1 -24
  3. package/cpp/api/JsiSkApi.h +3 -0
  4. package/cpp/api/recorder/ColorFilters.h +133 -0
  5. package/cpp/api/recorder/Command.h +58 -0
  6. package/cpp/api/recorder/Convertor.h +1212 -0
  7. package/cpp/api/recorder/DataTypes.h +234 -0
  8. package/cpp/api/recorder/DrawingCtx.h +187 -0
  9. package/cpp/api/recorder/Drawings.h +949 -0
  10. package/cpp/api/recorder/Image.h +108 -0
  11. package/cpp/api/recorder/ImageFilters.h +292 -0
  12. package/cpp/api/recorder/JsiRecorder.h +314 -0
  13. package/cpp/api/recorder/Paint.h +191 -0
  14. package/cpp/api/recorder/PathEffects.h +194 -0
  15. package/cpp/api/recorder/RNRecorder.h +635 -0
  16. package/cpp/api/recorder/Shaders.h +406 -0
  17. package/cpp/rnskia/dom/nodes/JsiAtlasNode.h +3 -2
  18. package/cpp/rnskia/dom/nodes/JsiImageNode.h +3 -2
  19. package/ios/RNSkia-iOS/SkiaCVPixelBufferUtils.mm +4 -8
  20. package/jestSetup.js +8 -0
  21. package/jestSetup.mjs +8 -0
  22. package/lib/commonjs/renderer/components/image/Image.d.ts +1 -1
  23. package/lib/commonjs/renderer/components/image/Image.js +8 -2
  24. package/lib/commonjs/renderer/components/image/Image.js.map +1 -1
  25. package/lib/commonjs/skia/types/Recorder.d.ts +52 -0
  26. package/lib/commonjs/skia/types/Recorder.js +6 -0
  27. package/lib/commonjs/skia/types/Recorder.js.map +1 -0
  28. package/lib/commonjs/skia/types/Skia.d.ts +2 -0
  29. package/lib/commonjs/skia/types/Skia.js.map +1 -1
  30. package/lib/commonjs/skia/types/index.d.ts +1 -0
  31. package/lib/commonjs/skia/types/index.js +11 -0
  32. package/lib/commonjs/skia/types/index.js.map +1 -1
  33. package/lib/commonjs/skia/web/JsiSkia.js +3 -0
  34. package/lib/commonjs/skia/web/JsiSkia.js.map +1 -1
  35. package/lib/commonjs/sksg/Container.d.ts +6 -1
  36. package/lib/commonjs/sksg/Container.js +59 -2
  37. package/lib/commonjs/sksg/Container.js.map +1 -1
  38. package/lib/commonjs/sksg/Recorder/DrawingContext.js +1 -0
  39. package/lib/commonjs/sksg/Recorder/DrawingContext.js.map +1 -1
  40. package/lib/commonjs/sksg/Recorder/ReanimatedRecorder.d.ts +53 -0
  41. package/lib/commonjs/sksg/Recorder/ReanimatedRecorder.js +189 -0
  42. package/lib/commonjs/sksg/Recorder/ReanimatedRecorder.js.map +1 -0
  43. package/lib/commonjs/sksg/Recorder/Recorder.d.ts +2 -2
  44. package/lib/commonjs/sksg/Recorder/Recorder.js.map +1 -1
  45. package/lib/commonjs/sksg/Recorder/Visitor.d.ts +2 -2
  46. package/lib/commonjs/sksg/Recorder/Visitor.js +2 -2
  47. package/lib/commonjs/sksg/Recorder/Visitor.js.map +1 -1
  48. package/lib/module/renderer/components/image/Image.d.ts +1 -1
  49. package/lib/module/renderer/components/image/Image.js +8 -2
  50. package/lib/module/renderer/components/image/Image.js.map +1 -1
  51. package/lib/module/skia/types/Recorder.d.ts +52 -0
  52. package/lib/module/skia/types/Recorder.js +2 -0
  53. package/lib/module/skia/types/Recorder.js.map +1 -0
  54. package/lib/module/skia/types/Skia.d.ts +2 -0
  55. package/lib/module/skia/types/Skia.js.map +1 -1
  56. package/lib/module/skia/types/index.d.ts +1 -0
  57. package/lib/module/skia/types/index.js +1 -0
  58. package/lib/module/skia/types/index.js.map +1 -1
  59. package/lib/module/skia/web/JsiSkia.js +3 -0
  60. package/lib/module/skia/web/JsiSkia.js.map +1 -1
  61. package/lib/module/sksg/Container.d.ts +6 -1
  62. package/lib/module/sksg/Container.js +59 -2
  63. package/lib/module/sksg/Container.js.map +1 -1
  64. package/lib/module/sksg/Recorder/DrawingContext.js +1 -0
  65. package/lib/module/sksg/Recorder/DrawingContext.js.map +1 -1
  66. package/lib/module/sksg/Recorder/ReanimatedRecorder.d.ts +53 -0
  67. package/lib/module/sksg/Recorder/ReanimatedRecorder.js +182 -0
  68. package/lib/module/sksg/Recorder/ReanimatedRecorder.js.map +1 -0
  69. package/lib/module/sksg/Recorder/Recorder.d.ts +2 -2
  70. package/lib/module/sksg/Recorder/Recorder.js.map +1 -1
  71. package/lib/module/sksg/Recorder/Visitor.d.ts +2 -2
  72. package/lib/module/sksg/Recorder/Visitor.js +2 -2
  73. package/lib/module/sksg/Recorder/Visitor.js.map +1 -1
  74. package/lib/typescript/lib/commonjs/renderer/components/image/Image.d.ts +4 -1
  75. package/lib/typescript/lib/commonjs/skia/types/Recorder.d.ts +1 -0
  76. package/lib/typescript/lib/commonjs/skia/web/JsiSkia.d.ts +1 -0
  77. package/lib/typescript/lib/commonjs/sksg/Container.d.ts +5 -1
  78. package/lib/typescript/lib/commonjs/sksg/Reconciler.d.ts +6 -0
  79. package/lib/typescript/lib/commonjs/sksg/Recorder/ReanimatedRecorder.d.ts +47 -0
  80. package/lib/typescript/lib/module/mock/index.d.ts +4 -1
  81. package/lib/typescript/lib/module/renderer/components/image/Image.d.ts +4 -1
  82. package/lib/typescript/lib/module/skia/Skia.web.d.ts +1 -0
  83. package/lib/typescript/lib/module/skia/types/Recorder.d.ts +1 -0
  84. package/lib/typescript/lib/module/skia/types/index.d.ts +1 -0
  85. package/lib/typescript/lib/module/skia/web/JsiSkia.d.ts +1 -0
  86. package/lib/typescript/lib/module/sksg/Container.d.ts +5 -1
  87. package/lib/typescript/lib/module/sksg/Reconciler.d.ts +6 -0
  88. package/lib/typescript/lib/module/sksg/Recorder/ReanimatedRecorder.d.ts +46 -0
  89. package/lib/typescript/src/renderer/components/image/Image.d.ts +1 -1
  90. package/lib/typescript/src/skia/types/Recorder.d.ts +52 -0
  91. package/lib/typescript/src/skia/types/Skia.d.ts +2 -0
  92. package/lib/typescript/src/skia/types/index.d.ts +1 -0
  93. package/lib/typescript/src/sksg/Container.d.ts +6 -1
  94. package/lib/typescript/src/sksg/Recorder/ReanimatedRecorder.d.ts +53 -0
  95. package/lib/typescript/src/sksg/Recorder/Recorder.d.ts +2 -2
  96. package/lib/typescript/src/sksg/Recorder/Visitor.d.ts +2 -2
  97. package/package.json +3 -2
  98. package/src/renderer/components/image/Image.tsx +2 -2
  99. package/src/skia/types/Recorder.ts +91 -0
  100. package/src/skia/types/Skia.ts +2 -0
  101. package/src/skia/types/index.ts +1 -0
  102. package/src/skia/web/JsiSkia.ts +3 -0
  103. package/src/sksg/Container.ts +63 -4
  104. package/src/sksg/Recorder/DrawingContext.ts +1 -0
  105. package/src/sksg/Recorder/ReanimatedRecorder.ts +271 -0
  106. package/src/sksg/Recorder/Recorder.ts +2 -2
  107. package/src/sksg/Recorder/Visitor.ts +17 -12
@@ -32,20 +32,7 @@ public abstract class SkiaBaseView extends ReactViewGroup implements SkiaViewAPI
32
32
  }
33
33
  }
34
34
 
35
- @Override
36
- protected void onAttachedToWindow() {
37
- super.onAttachedToWindow();
38
- if (getMeasuredWidth() == 0) {
39
- if (mView instanceof SkiaTextureView) {
40
- ((SkiaTextureView) mView).createSurfaceTexture();
41
- }
42
- }
43
- }
44
-
45
35
  void dropInstance() {
46
- if (mView instanceof SkiaTextureView) {
47
- ((SkiaTextureView)mView).isDropped = true;
48
- }
49
36
  unregisterView();
50
37
  }
51
38
 
@@ -15,7 +15,6 @@ public class SkiaTextureView extends TextureView implements TextureView.SurfaceT
15
15
 
16
16
  SkiaViewAPI mApi;
17
17
  boolean mDebug;
18
- public boolean isDropped = false;
19
18
 
20
19
  public SkiaTextureView(Context context, SkiaViewAPI api, boolean debug) {
21
20
  super(context);
@@ -25,22 +24,6 @@ public class SkiaTextureView extends TextureView implements TextureView.SurfaceT
25
24
  setSurfaceTextureListener(this);
26
25
  }
27
26
 
28
- public void createSurfaceTexture() {
29
- if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) {
30
- Log.i(tag, "Create SurfaceTexture");
31
- SurfaceTexture surfaceTexture = new SurfaceTexture(false);
32
- setSurfaceTexture(surfaceTexture);
33
- onSurfaceTextureAvailable(surfaceTexture, getWidth(), getHeight());
34
- }
35
- }
36
-
37
- private void reCreateSurfaceTexture() {
38
- boolean surfaceIsAlreadyAvailable = getSurfaceTexture() != null;
39
- if (surfaceIsAlreadyAvailable) {
40
- createSurfaceTexture();
41
- }
42
- }
43
-
44
27
  @Override
45
28
  protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
46
29
  super.onLayout(changed, left, top, right, bottom);
@@ -55,19 +38,13 @@ public class SkiaTextureView extends TextureView implements TextureView.SurfaceT
55
38
  @Override
56
39
  public void onSurfaceTextureSizeChanged(@NonNull SurfaceTexture surfaceTexture, int width, int height) {
57
40
  Log.i(tag, "onSurfaceTextureSizeChanged: " + width + "x" + height);
58
- if (isDropped) {
59
- return;
60
- }
61
41
  mApi.onSurfaceTextureChanged(surfaceTexture, width, height);
62
42
  }
63
43
 
64
44
  @Override
65
45
  public boolean onSurfaceTextureDestroyed(@NonNull SurfaceTexture surfaceTexture) {
66
46
  mApi.onSurfaceDestroyed();
67
- if (!isDropped) {
68
- reCreateSurfaceTexture();
69
- }
70
- return false;
47
+ return true;
71
48
  }
72
49
 
73
50
  private long _prevTimestamp = 0;
@@ -52,6 +52,7 @@
52
52
  #include "JsiSkVertices.h"
53
53
  #include "JsiSkiaContext.h"
54
54
  #include "JsiVideo.h"
55
+ #include "recorder/JsiRecorder.h"
55
56
 
56
57
  namespace RNSkia {
57
58
 
@@ -130,6 +131,8 @@ public:
130
131
 
131
132
  installReadonlyProperty("NativeBuffer",
132
133
  std::make_shared<JsiNativeBufferFactory>(context));
134
+
135
+ installFunction("Recorder", JsiRecorder::createCtor(context));
133
136
  }
134
137
  };
135
138
  } // namespace RNSkia
@@ -0,0 +1,133 @@
1
+ #pragma once
2
+
3
+ #include <optional>
4
+ #include <string>
5
+ #include <variant>
6
+ #include <vector>
7
+
8
+ #include <include/core/SkColorFilter.h>
9
+
10
+ #include "Command.h"
11
+ #include "Convertor.h"
12
+ #include "DrawingCtx.h"
13
+
14
+ namespace RNSkia {
15
+
16
+ struct MatrixColorFilterProps {
17
+ std::vector<float> matrix;
18
+ };
19
+
20
+ class MatrixColorFilterCmd : public Command {
21
+ private:
22
+ MatrixColorFilterProps props;
23
+
24
+ public:
25
+ MatrixColorFilterCmd(jsi::Runtime &runtime, const jsi::Object &object,
26
+ Variables &variables)
27
+ : Command(CommandType::PushColorFilter, "skMatrixColorFilter") {
28
+ convertProperty(runtime, object, "matrix", props.matrix, variables);
29
+ }
30
+
31
+ void pushColorFilter(DrawingCtx *ctx) {
32
+ if (props.matrix.size() == 20) {
33
+ auto cf = SkColorFilters::Matrix(props.matrix.data());
34
+ ctx->colorFilters.push_back(cf);
35
+ }
36
+ }
37
+ };
38
+
39
+ struct BlendColorFilterProps {
40
+ SkBlendMode mode;
41
+ SkColor color;
42
+ };
43
+
44
+ class BlendColorFilterCmd : public Command {
45
+ private:
46
+ BlendColorFilterProps props;
47
+
48
+ public:
49
+ BlendColorFilterCmd(jsi::Runtime &runtime, const jsi::Object &object,
50
+ Variables &variables)
51
+ : Command(CommandType::PushColorFilter, "skBlendColorFilter") {
52
+ convertProperty(runtime, object, "mode", props.mode, variables);
53
+ convertProperty(runtime, object, "color", props.color, variables);
54
+ }
55
+
56
+ void pushColorFilter(DrawingCtx *ctx) {
57
+ auto cf = SkColorFilters::Blend(props.color, props.mode);
58
+ ctx->colorFilters.push_back(cf);
59
+ }
60
+ };
61
+
62
+ class LinearToSRGBGammaColorFilterCmd : public Command {
63
+ public:
64
+ LinearToSRGBGammaColorFilterCmd(jsi::Runtime &runtime,
65
+ const jsi::Object &object,
66
+ Variables &variables)
67
+ : Command(CommandType::PushColorFilter,
68
+ "skLinearToSRGBGammaColorFilter") {}
69
+
70
+ void pushColorFilter(DrawingCtx *ctx) {
71
+ auto cf = SkColorFilters::LinearToSRGBGamma();
72
+ ctx->colorFilters.push_back(cf);
73
+ }
74
+ };
75
+
76
+ class SRGBToLinearGammaColorFilterCmd : public Command {
77
+ public:
78
+ SRGBToLinearGammaColorFilterCmd(jsi::Runtime &runtime,
79
+ const jsi::Object &object,
80
+ Variables &variables)
81
+ : Command(CommandType::PushColorFilter,
82
+ "skSRGBToLinearGammaColorFilter") {}
83
+
84
+ void pushColorFilter(DrawingCtx *ctx) {
85
+ auto cf = SkColorFilters::SRGBToLinearGamma();
86
+ ctx->colorFilters.push_back(cf);
87
+ }
88
+ };
89
+
90
+ class LumaColorFilterCmd : public Command {
91
+ public:
92
+ LumaColorFilterCmd(jsi::Runtime &runtime, const jsi::Object &object,
93
+ Variables &variables)
94
+ : Command(CommandType::PushColorFilter, "skLumaColorFilter") {}
95
+
96
+ void pushColorFilter(DrawingCtx *ctx) {
97
+ auto cf = SkLumaColorFilter::Make();
98
+ ctx->colorFilters.push_back(cf);
99
+ }
100
+ };
101
+
102
+ struct LerpColorFilterProps {
103
+ float t;
104
+ };
105
+
106
+ class LerpColorFilterCmd : public Command {
107
+ private:
108
+ LerpColorFilterProps props;
109
+
110
+ public:
111
+ LerpColorFilterCmd(jsi::Runtime &runtime, const jsi::Object &object,
112
+ Variables &variables)
113
+ : Command(CommandType::PushColorFilter, "skLerpColorFilter") {
114
+ convertProperty(runtime, object, "t", props.t, variables);
115
+ }
116
+
117
+ void pushColorFilter(DrawingCtx *ctx) {
118
+ if (ctx->colorFilters.size() >= 2) {
119
+ auto second = ctx->colorFilters.back();
120
+ ctx->colorFilters.pop_back();
121
+ auto first = ctx->colorFilters.back();
122
+ ctx->colorFilters.pop_back();
123
+
124
+ auto cf = SkColorFilters::Lerp(props.t, first, second);
125
+ ctx->colorFilters.push_back(cf);
126
+ } else {
127
+ // Handle error - not enough filters
128
+ // Could throw an exception or handle gracefully
129
+ }
130
+ }
131
+ };
132
+
133
+ } // namespace RNSkia
@@ -0,0 +1,58 @@
1
+ #pragma once
2
+
3
+ namespace RNSkia {
4
+
5
+ enum CommandType {
6
+ // Context
7
+ Group,
8
+ SavePaint,
9
+ RestorePaint,
10
+ SaveCTM,
11
+ RestoreCTM,
12
+ PushColorFilter,
13
+ PushBlurMaskFilter,
14
+ PushImageFilter,
15
+ PushPathEffect,
16
+ PushShader,
17
+ ComposeColorFilter,
18
+ ComposeImageFilter,
19
+ ComposePathEffect,
20
+ MaterializePaint,
21
+ SaveBackdropFilter,
22
+ SaveLayer,
23
+ RestorePaintDeclaration,
24
+ // Drawing
25
+ DrawBox,
26
+ DrawImage,
27
+ DrawCircle,
28
+ DrawPaint,
29
+ DrawPoints,
30
+ DrawPath,
31
+ DrawRect,
32
+ DrawRRect,
33
+ DrawOval,
34
+ DrawLine,
35
+ DrawPatch,
36
+ DrawVertices,
37
+ DrawDiffRect,
38
+ DrawText,
39
+ DrawTextPath,
40
+ DrawTextBlob,
41
+ DrawGlyphs,
42
+ DrawPicture,
43
+ DrawImageSVG,
44
+ DrawParagraph,
45
+ DrawAtlas,
46
+ };
47
+
48
+ class Command {
49
+ public:
50
+ CommandType type;
51
+ std::string nodeType;
52
+
53
+ Command(CommandType t) : type(t) {}
54
+ Command(CommandType t, std::string nodeT) : type(t), nodeType(nodeT) {}
55
+ virtual ~Command() = default;
56
+ };
57
+
58
+ } // namespace RNSkia