@shopify/react-native-skia 1.10.2 → 1.11.0
Sign up to get free protection for your applications and to get access to all the features.
- package/cpp/api/JsiSkApi.h +3 -0
- package/cpp/api/recorder/ColorFilters.h +133 -0
- package/cpp/api/recorder/Command.h +58 -0
- package/cpp/api/recorder/Convertor.h +1212 -0
- package/cpp/api/recorder/DataTypes.h +234 -0
- package/cpp/api/recorder/DrawingCtx.h +187 -0
- package/cpp/api/recorder/Drawings.h +949 -0
- package/cpp/api/recorder/Image.h +108 -0
- package/cpp/api/recorder/ImageFilters.h +292 -0
- package/cpp/api/recorder/JsiRecorder.h +314 -0
- package/cpp/api/recorder/Paint.h +191 -0
- package/cpp/api/recorder/PathEffects.h +194 -0
- package/cpp/api/recorder/RNRecorder.h +635 -0
- package/cpp/api/recorder/Shaders.h +406 -0
- package/cpp/rnskia/dom/nodes/JsiAtlasNode.h +3 -2
- package/cpp/rnskia/dom/nodes/JsiImageNode.h +3 -2
- package/ios/RNSkia-iOS/SkiaCVPixelBufferUtils.mm +4 -8
- package/jestSetup.js +8 -0
- package/jestSetup.mjs +8 -0
- package/lib/commonjs/renderer/components/image/Image.d.ts +1 -1
- package/lib/commonjs/renderer/components/image/Image.js +8 -2
- package/lib/commonjs/renderer/components/image/Image.js.map +1 -1
- package/lib/commonjs/skia/types/Recorder.d.ts +52 -0
- package/lib/commonjs/skia/types/Recorder.js +6 -0
- package/lib/commonjs/skia/types/Recorder.js.map +1 -0
- package/lib/commonjs/skia/types/Skia.d.ts +2 -0
- package/lib/commonjs/skia/types/Skia.js.map +1 -1
- package/lib/commonjs/skia/types/index.d.ts +1 -0
- package/lib/commonjs/skia/types/index.js +11 -0
- package/lib/commonjs/skia/types/index.js.map +1 -1
- package/lib/commonjs/skia/web/JsiSkia.js +3 -0
- package/lib/commonjs/skia/web/JsiSkia.js.map +1 -1
- package/lib/commonjs/sksg/Container.d.ts +6 -1
- package/lib/commonjs/sksg/Container.js +59 -2
- package/lib/commonjs/sksg/Container.js.map +1 -1
- package/lib/commonjs/sksg/Recorder/DrawingContext.js +1 -0
- package/lib/commonjs/sksg/Recorder/DrawingContext.js.map +1 -1
- package/lib/commonjs/sksg/Recorder/ReanimatedRecorder.d.ts +53 -0
- package/lib/commonjs/sksg/Recorder/ReanimatedRecorder.js +189 -0
- package/lib/commonjs/sksg/Recorder/ReanimatedRecorder.js.map +1 -0
- package/lib/commonjs/sksg/Recorder/Recorder.d.ts +2 -2
- package/lib/commonjs/sksg/Recorder/Recorder.js.map +1 -1
- package/lib/commonjs/sksg/Recorder/Visitor.d.ts +2 -2
- package/lib/commonjs/sksg/Recorder/Visitor.js +2 -2
- package/lib/commonjs/sksg/Recorder/Visitor.js.map +1 -1
- package/lib/module/renderer/components/image/Image.d.ts +1 -1
- package/lib/module/renderer/components/image/Image.js +8 -2
- package/lib/module/renderer/components/image/Image.js.map +1 -1
- package/lib/module/skia/types/Recorder.d.ts +52 -0
- package/lib/module/skia/types/Recorder.js +2 -0
- package/lib/module/skia/types/Recorder.js.map +1 -0
- package/lib/module/skia/types/Skia.d.ts +2 -0
- package/lib/module/skia/types/Skia.js.map +1 -1
- package/lib/module/skia/types/index.d.ts +1 -0
- package/lib/module/skia/types/index.js +1 -0
- package/lib/module/skia/types/index.js.map +1 -1
- package/lib/module/skia/web/JsiSkia.js +3 -0
- package/lib/module/skia/web/JsiSkia.js.map +1 -1
- package/lib/module/sksg/Container.d.ts +6 -1
- package/lib/module/sksg/Container.js +59 -2
- package/lib/module/sksg/Container.js.map +1 -1
- package/lib/module/sksg/Recorder/DrawingContext.js +1 -0
- package/lib/module/sksg/Recorder/DrawingContext.js.map +1 -1
- package/lib/module/sksg/Recorder/ReanimatedRecorder.d.ts +53 -0
- package/lib/module/sksg/Recorder/ReanimatedRecorder.js +182 -0
- package/lib/module/sksg/Recorder/ReanimatedRecorder.js.map +1 -0
- package/lib/module/sksg/Recorder/Recorder.d.ts +2 -2
- package/lib/module/sksg/Recorder/Recorder.js.map +1 -1
- package/lib/module/sksg/Recorder/Visitor.d.ts +2 -2
- package/lib/module/sksg/Recorder/Visitor.js +2 -2
- package/lib/module/sksg/Recorder/Visitor.js.map +1 -1
- package/lib/typescript/lib/commonjs/renderer/components/image/Image.d.ts +4 -1
- package/lib/typescript/lib/commonjs/skia/types/Recorder.d.ts +1 -0
- package/lib/typescript/lib/commonjs/skia/web/JsiSkia.d.ts +1 -0
- package/lib/typescript/lib/commonjs/sksg/Container.d.ts +5 -1
- package/lib/typescript/lib/commonjs/sksg/Reconciler.d.ts +6 -0
- package/lib/typescript/lib/commonjs/sksg/Recorder/ReanimatedRecorder.d.ts +47 -0
- package/lib/typescript/lib/module/mock/index.d.ts +4 -1
- package/lib/typescript/lib/module/renderer/components/image/Image.d.ts +4 -1
- package/lib/typescript/lib/module/skia/Skia.web.d.ts +1 -0
- package/lib/typescript/lib/module/skia/types/Recorder.d.ts +1 -0
- package/lib/typescript/lib/module/skia/types/index.d.ts +1 -0
- package/lib/typescript/lib/module/skia/web/JsiSkia.d.ts +1 -0
- package/lib/typescript/lib/module/sksg/Container.d.ts +5 -1
- package/lib/typescript/lib/module/sksg/Reconciler.d.ts +6 -0
- package/lib/typescript/lib/module/sksg/Recorder/ReanimatedRecorder.d.ts +46 -0
- package/lib/typescript/src/renderer/components/image/Image.d.ts +1 -1
- package/lib/typescript/src/skia/types/Recorder.d.ts +52 -0
- package/lib/typescript/src/skia/types/Skia.d.ts +2 -0
- package/lib/typescript/src/skia/types/index.d.ts +1 -0
- package/lib/typescript/src/sksg/Container.d.ts +6 -1
- package/lib/typescript/src/sksg/Recorder/ReanimatedRecorder.d.ts +53 -0
- package/lib/typescript/src/sksg/Recorder/Recorder.d.ts +2 -2
- package/lib/typescript/src/sksg/Recorder/Visitor.d.ts +2 -2
- package/package.json +3 -2
- package/src/renderer/components/image/Image.tsx +2 -2
- package/src/skia/types/Recorder.ts +91 -0
- package/src/skia/types/Skia.ts +2 -0
- package/src/skia/types/index.ts +1 -0
- package/src/skia/web/JsiSkia.ts +3 -0
- package/src/sksg/Container.ts +63 -4
- package/src/sksg/Recorder/DrawingContext.ts +1 -0
- package/src/sksg/Recorder/ReanimatedRecorder.ts +271 -0
- package/src/sksg/Recorder/Recorder.ts +2 -2
- package/src/sksg/Recorder/Visitor.ts +17 -12
package/cpp/api/JsiSkApi.h
CHANGED
@@ -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
|