@shopify/react-native-skia 1.10.2 → 1.11.1
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 +1213 -0
- package/cpp/api/recorder/DataTypes.h +232 -0
- package/cpp/api/recorder/DrawingCtx.h +187 -0
- package/cpp/api/recorder/Drawings.h +950 -0
- package/cpp/api/recorder/ImageFilters.h +292 -0
- package/cpp/api/recorder/ImageFit.h +108 -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 +637 -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/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
@@ -0,0 +1,637 @@
|
|
1
|
+
#pragma once
|
2
|
+
|
3
|
+
#include <memory>
|
4
|
+
#include <optional>
|
5
|
+
#include <string>
|
6
|
+
#include <vector>
|
7
|
+
|
8
|
+
#include <jsi/jsi.h>
|
9
|
+
|
10
|
+
#include "ColorFilters.h"
|
11
|
+
#include "Command.h"
|
12
|
+
#include "Convertor.h"
|
13
|
+
#include "DrawingCtx.h"
|
14
|
+
#include "Drawings.h"
|
15
|
+
#include "ImageFilters.h"
|
16
|
+
#include "Paint.h"
|
17
|
+
#include "PathEffects.h"
|
18
|
+
#include "Shaders.h"
|
19
|
+
|
20
|
+
namespace RNSkia {
|
21
|
+
|
22
|
+
class Recorder {
|
23
|
+
private:
|
24
|
+
std::vector<std::unique_ptr<Command>> commands;
|
25
|
+
|
26
|
+
public:
|
27
|
+
Variables variables;
|
28
|
+
|
29
|
+
~Recorder() = default;
|
30
|
+
|
31
|
+
void savePaint(jsi::Runtime &runtime, const jsi::Object &props) {
|
32
|
+
commands.push_back(
|
33
|
+
std::make_unique<SavePaintCmd>(runtime, props, variables));
|
34
|
+
}
|
35
|
+
|
36
|
+
void pushShader(jsi::Runtime &runtime, const std::string &nodeType,
|
37
|
+
const jsi::Object &props) {
|
38
|
+
if (nodeType == "skShader") {
|
39
|
+
commands.push_back(
|
40
|
+
std::make_unique<PushShaderCmd>(runtime, props, variables));
|
41
|
+
} else if (nodeType == "skImageShader") {
|
42
|
+
commands.push_back(
|
43
|
+
std::make_unique<PushImageShaderCmd>(runtime, props, variables));
|
44
|
+
} else if (nodeType == "skColorShader") {
|
45
|
+
commands.push_back(
|
46
|
+
std::make_unique<ColorShaderCmd>(runtime, props, variables));
|
47
|
+
} else if (nodeType == "skTurbulence") {
|
48
|
+
commands.push_back(
|
49
|
+
std::make_unique<TurbulenceCmd>(runtime, props, variables));
|
50
|
+
} else if (nodeType == "skFractalNoise") {
|
51
|
+
commands.push_back(
|
52
|
+
std::make_unique<FractalNoiseCmd>(runtime, props, variables));
|
53
|
+
} else if (nodeType == "skLinearGradient") {
|
54
|
+
commands.push_back(
|
55
|
+
std::make_unique<LinearGradientCmd>(runtime, props, variables));
|
56
|
+
} else if (nodeType == "skRadialGradient") {
|
57
|
+
commands.push_back(
|
58
|
+
std::make_unique<RadialGradientCmd>(runtime, props, variables));
|
59
|
+
} else if (nodeType == "skSweepGradient") {
|
60
|
+
commands.push_back(
|
61
|
+
std::make_unique<SweepGradientCmd>(runtime, props, variables));
|
62
|
+
} else if (nodeType == "skTwoPointConicalGradient") {
|
63
|
+
commands.push_back(std::make_unique<TwoPointConicalGradientCmd>(
|
64
|
+
runtime, props, variables));
|
65
|
+
// TODO: should receive skBlendShader here
|
66
|
+
} else if (nodeType == "skBlend") {
|
67
|
+
commands.push_back(
|
68
|
+
std::make_unique<BlendShaderCmd>(runtime, props, variables));
|
69
|
+
}
|
70
|
+
}
|
71
|
+
|
72
|
+
void pushPathEffect(jsi::Runtime &runtime, const std::string &nodeType,
|
73
|
+
const jsi::Object &props) {
|
74
|
+
if (nodeType == "skDiscretePathEffect") {
|
75
|
+
commands.push_back(
|
76
|
+
std::make_unique<DiscretePathEffectCmd>(runtime, props, variables));
|
77
|
+
} else if (nodeType == "skDashPathEffect") {
|
78
|
+
commands.push_back(
|
79
|
+
std::make_unique<DashPathEffectCmd>(runtime, props, variables));
|
80
|
+
} else if (nodeType == "skPath1DPathEffect") {
|
81
|
+
commands.push_back(
|
82
|
+
std::make_unique<Path1DPathEffectCmd>(runtime, props, variables));
|
83
|
+
} else if (nodeType == "skPath2DPathEffect") {
|
84
|
+
commands.push_back(
|
85
|
+
std::make_unique<Path2DPathEffectCmd>(runtime, props, variables));
|
86
|
+
} else if (nodeType == "skCornerPathEffect") {
|
87
|
+
commands.push_back(
|
88
|
+
std::make_unique<CornerPathEffectCmd>(runtime, props, variables));
|
89
|
+
} else if (nodeType == "skSumPathEffect") {
|
90
|
+
commands.push_back(
|
91
|
+
std::make_unique<SumPathEffectCmd>(runtime, props, variables));
|
92
|
+
} else if (nodeType == "skLine2DPathEffect") {
|
93
|
+
commands.push_back(
|
94
|
+
std::make_unique<Line2DPathEffectCmd>(runtime, props, variables));
|
95
|
+
}
|
96
|
+
}
|
97
|
+
|
98
|
+
void pushColorFilter(jsi::Runtime &runtime, const std::string &nodeType,
|
99
|
+
const jsi::Object &props) {
|
100
|
+
if (nodeType == "skMatrixColorFilter") {
|
101
|
+
commands.push_back(
|
102
|
+
std::make_unique<MatrixColorFilterCmd>(runtime, props, variables));
|
103
|
+
} else if (nodeType == "skBlendColorFilter") {
|
104
|
+
commands.push_back(
|
105
|
+
std::make_unique<BlendColorFilterCmd>(runtime, props, variables));
|
106
|
+
} else if (nodeType == "skLinearToSRGBGammaColorFilter") {
|
107
|
+
commands.push_back(std::make_unique<LinearToSRGBGammaColorFilterCmd>(
|
108
|
+
runtime, props, variables));
|
109
|
+
} else if (nodeType == "skSRGBToLinearGammaColorFilter") {
|
110
|
+
commands.push_back(std::make_unique<SRGBToLinearGammaColorFilterCmd>(
|
111
|
+
runtime, props, variables));
|
112
|
+
} else if (nodeType == "skLumaColorFilter") {
|
113
|
+
commands.push_back(
|
114
|
+
std::make_unique<LumaColorFilterCmd>(runtime, props, variables));
|
115
|
+
} else if (nodeType == "skLerpColorFilter") {
|
116
|
+
commands.push_back(
|
117
|
+
std::make_unique<LerpColorFilterCmd>(runtime, props, variables));
|
118
|
+
}
|
119
|
+
}
|
120
|
+
|
121
|
+
void pushImageFilter(jsi::Runtime &runtime, const std::string &nodeType,
|
122
|
+
const jsi::Object &props) {
|
123
|
+
if (nodeType == "skOffsetImageFilter") {
|
124
|
+
commands.push_back(
|
125
|
+
std::make_unique<OffsetImageFilterCmd>(runtime, props, variables));
|
126
|
+
} else if (nodeType == "skDisplacementMapImageFilter") {
|
127
|
+
commands.push_back(std::make_unique<DisplacementMapImageFilterCmd>(
|
128
|
+
runtime, props, variables));
|
129
|
+
} else if (nodeType == "skBlurImageFilter") {
|
130
|
+
commands.push_back(
|
131
|
+
std::make_unique<BlurImageFilterCmd>(runtime, props, variables));
|
132
|
+
} else if (nodeType == "skDropShadowImageFilter") {
|
133
|
+
commands.push_back(std::make_unique<DropShadowImageFilterCmd>(
|
134
|
+
runtime, props, variables));
|
135
|
+
} else if (nodeType == "skMorphologyImageFilter") {
|
136
|
+
commands.push_back(std::make_unique<MorphologyImageFilterCmd>(
|
137
|
+
runtime, props, variables));
|
138
|
+
} else if (nodeType == "skBlendImageFilter") {
|
139
|
+
commands.push_back(
|
140
|
+
std::make_unique<BlendImageFilterCmd>(runtime, props, variables));
|
141
|
+
} else if (nodeType == "skRuntimeShaderImageFilter") {
|
142
|
+
commands.push_back(std::make_unique<RuntimeShaderImageFilterCmd>(
|
143
|
+
runtime, props, variables));
|
144
|
+
}
|
145
|
+
}
|
146
|
+
|
147
|
+
void composePathEffect() {
|
148
|
+
commands.push_back(
|
149
|
+
std::make_unique<Command>(CommandType::ComposePathEffect));
|
150
|
+
}
|
151
|
+
|
152
|
+
void composeImageFilter() {
|
153
|
+
commands.push_back(
|
154
|
+
std::make_unique<Command>(CommandType::ComposeImageFilter));
|
155
|
+
}
|
156
|
+
|
157
|
+
void composeColorFilter() {
|
158
|
+
commands.push_back(
|
159
|
+
std::make_unique<Command>(CommandType::ComposeColorFilter));
|
160
|
+
}
|
161
|
+
|
162
|
+
void pushBlurMaskFilter(jsi::Runtime &runtime, const jsi::Object &props) {
|
163
|
+
commands.push_back(
|
164
|
+
std::make_unique<BlurMaskFilterCmd>(runtime, props, variables));
|
165
|
+
}
|
166
|
+
|
167
|
+
void saveCTM(jsi::Runtime &runtime, const jsi::Object &props) {
|
168
|
+
commands.push_back(std::make_unique<SaveCTMCmd>(runtime, props, variables));
|
169
|
+
}
|
170
|
+
|
171
|
+
void restoreCTM() {
|
172
|
+
commands.push_back(std::make_unique<Command>(CommandType::RestoreCTM));
|
173
|
+
}
|
174
|
+
|
175
|
+
void restorePaint() {
|
176
|
+
commands.push_back(std::make_unique<Command>(CommandType::RestorePaint));
|
177
|
+
}
|
178
|
+
|
179
|
+
void drawRect(jsi::Runtime &runtime, const jsi::Object &props) {
|
180
|
+
commands.push_back(std::make_unique<RectCmd>(runtime, props, variables));
|
181
|
+
}
|
182
|
+
|
183
|
+
void drawCircle(jsi::Runtime &runtime, const jsi::Object &props) {
|
184
|
+
commands.push_back(std::make_unique<CircleCmd>(runtime, props, variables));
|
185
|
+
}
|
186
|
+
|
187
|
+
void drawLine(jsi::Runtime &runtime, const jsi::Object &props) {
|
188
|
+
commands.push_back(std::make_unique<LineCmd>(runtime, props, variables));
|
189
|
+
}
|
190
|
+
|
191
|
+
void drawTextPath(jsi::Runtime &runtime, const jsi::Object &props) {
|
192
|
+
commands.push_back(
|
193
|
+
std::make_unique<TextPathCmd>(runtime, props, variables));
|
194
|
+
}
|
195
|
+
|
196
|
+
void drawText(jsi::Runtime &runtime, const jsi::Object &props) {
|
197
|
+
commands.push_back(std::make_unique<TextCmd>(runtime, props, variables));
|
198
|
+
}
|
199
|
+
|
200
|
+
void drawPath(jsi::Runtime &runtime, const jsi::Object &props) {
|
201
|
+
commands.push_back(std::make_unique<PathCmd>(runtime, props, variables));
|
202
|
+
}
|
203
|
+
|
204
|
+
void drawPaint() {
|
205
|
+
commands.push_back(std::make_unique<Command>(CommandType::DrawPaint));
|
206
|
+
}
|
207
|
+
|
208
|
+
void drawBox(jsi::Runtime &runtime, const jsi::Object &props,
|
209
|
+
const jsi::Array &shadows) {
|
210
|
+
commands.push_back(
|
211
|
+
std::make_unique<BoxCmd>(runtime, props, shadows, variables));
|
212
|
+
}
|
213
|
+
|
214
|
+
void drawImage(jsi::Runtime &runtime, const jsi::Object &props) {
|
215
|
+
commands.push_back(std::make_unique<ImageCmd>(runtime, props, variables));
|
216
|
+
}
|
217
|
+
|
218
|
+
void drawPoints(jsi::Runtime &runtime, const jsi::Object &props) {
|
219
|
+
commands.push_back(std::make_unique<PointsCmd>(runtime, props, variables));
|
220
|
+
}
|
221
|
+
|
222
|
+
void drawRRect(jsi::Runtime &runtime, const jsi::Object &props) {
|
223
|
+
commands.push_back(std::make_unique<RRectCmd>(runtime, props, variables));
|
224
|
+
}
|
225
|
+
|
226
|
+
void drawOval(jsi::Runtime &runtime, const jsi::Object &props) {
|
227
|
+
commands.push_back(std::make_unique<OvalCmd>(runtime, props, variables));
|
228
|
+
}
|
229
|
+
|
230
|
+
void drawPatch(jsi::Runtime &runtime, const jsi::Object &props) {
|
231
|
+
commands.push_back(std::make_unique<PatchCmd>(runtime, props, variables));
|
232
|
+
}
|
233
|
+
|
234
|
+
void drawVertices(jsi::Runtime &runtime, const jsi::Object &props) {
|
235
|
+
commands.push_back(
|
236
|
+
std::make_unique<VerticesCmd>(runtime, props, variables));
|
237
|
+
}
|
238
|
+
|
239
|
+
void drawDiffRect(jsi::Runtime &runtime, const jsi::Object &props) {
|
240
|
+
commands.push_back(
|
241
|
+
std::make_unique<DiffRectCmd>(runtime, props, variables));
|
242
|
+
}
|
243
|
+
|
244
|
+
void drawTextBlob(jsi::Runtime &runtime, const jsi::Object &props) {
|
245
|
+
commands.push_back(
|
246
|
+
std::make_unique<TextBlobCmd>(runtime, props, variables));
|
247
|
+
}
|
248
|
+
|
249
|
+
void drawGlyphs(jsi::Runtime &runtime, const jsi::Object &props) {
|
250
|
+
commands.push_back(std::make_unique<GlyphsCmd>(runtime, props, variables));
|
251
|
+
}
|
252
|
+
|
253
|
+
void drawPicture(jsi::Runtime &runtime, const jsi::Object &props) {
|
254
|
+
commands.push_back(std::make_unique<PictureCmd>(runtime, props, variables));
|
255
|
+
}
|
256
|
+
|
257
|
+
void drawImageSVG(jsi::Runtime &runtime, const jsi::Object &props) {
|
258
|
+
commands.push_back(
|
259
|
+
std::make_unique<ImageSVGCmd>(runtime, props, variables));
|
260
|
+
}
|
261
|
+
|
262
|
+
void drawParagraph(jsi::Runtime &runtime, const jsi::Object &props) {
|
263
|
+
commands.push_back(
|
264
|
+
std::make_unique<ParagraphCmd>(runtime, props, variables));
|
265
|
+
}
|
266
|
+
|
267
|
+
void drawAtlas(jsi::Runtime &runtime, const jsi::Object &props) {
|
268
|
+
commands.push_back(std::make_unique<AtlasCmd>(runtime, props, variables));
|
269
|
+
}
|
270
|
+
|
271
|
+
void materializePaint() {
|
272
|
+
commands.push_back(
|
273
|
+
std::make_unique<Command>(CommandType::MaterializePaint));
|
274
|
+
}
|
275
|
+
|
276
|
+
void restorePaintDeclaration() {
|
277
|
+
commands.push_back(
|
278
|
+
std::make_unique<Command>(CommandType::RestorePaintDeclaration));
|
279
|
+
}
|
280
|
+
|
281
|
+
void saveLayer() {
|
282
|
+
commands.push_back(std::make_unique<Command>(CommandType::SaveLayer));
|
283
|
+
}
|
284
|
+
|
285
|
+
void saveBackdropFilter() {
|
286
|
+
commands.push_back(
|
287
|
+
std::make_unique<Command>(CommandType::SaveBackdropFilter));
|
288
|
+
}
|
289
|
+
|
290
|
+
void saveGroup() {}
|
291
|
+
|
292
|
+
void restoreGroup() {}
|
293
|
+
|
294
|
+
void play(DrawingCtx *ctx) {
|
295
|
+
for (const auto &cmd : commands) {
|
296
|
+
switch (cmd->type) {
|
297
|
+
|
298
|
+
case Group: {
|
299
|
+
// Do nothing here for now
|
300
|
+
break;
|
301
|
+
}
|
302
|
+
|
303
|
+
case CommandType::ComposeColorFilter: {
|
304
|
+
ctx->composeColorFilter();
|
305
|
+
break;
|
306
|
+
}
|
307
|
+
|
308
|
+
case CommandType::ComposeImageFilter: {
|
309
|
+
ctx->composeImageFilter();
|
310
|
+
break;
|
311
|
+
}
|
312
|
+
|
313
|
+
case CommandType::ComposePathEffect: {
|
314
|
+
ctx->composePathEffect();
|
315
|
+
break;
|
316
|
+
}
|
317
|
+
|
318
|
+
case CommandType::RestorePaintDeclaration: {
|
319
|
+
ctx->materializePaint();
|
320
|
+
auto paint = ctx->restorePaint();
|
321
|
+
ctx->paintDeclarations.push_back(paint);
|
322
|
+
break;
|
323
|
+
}
|
324
|
+
|
325
|
+
case CommandType::SaveBackdropFilter: {
|
326
|
+
ctx->saveBackdropFilter();
|
327
|
+
break;
|
328
|
+
}
|
329
|
+
|
330
|
+
case CommandType::SaveLayer: {
|
331
|
+
ctx->materializePaint();
|
332
|
+
auto paint = ctx->paintDeclarations.back();
|
333
|
+
ctx->paintDeclarations.pop_back();
|
334
|
+
ctx->canvas->saveLayer(
|
335
|
+
SkCanvas::SaveLayerRec(nullptr, &paint, nullptr, 0));
|
336
|
+
break;
|
337
|
+
}
|
338
|
+
|
339
|
+
case CommandType::MaterializePaint: {
|
340
|
+
ctx->materializePaint();
|
341
|
+
break;
|
342
|
+
}
|
343
|
+
|
344
|
+
case CommandType::SavePaint: {
|
345
|
+
auto *savePaintCmd = static_cast<SavePaintCmd *>(cmd.get());
|
346
|
+
savePaintCmd->savePaint(ctx);
|
347
|
+
break;
|
348
|
+
}
|
349
|
+
|
350
|
+
case CommandType::PushShader: {
|
351
|
+
auto nodeType = cmd->nodeType;
|
352
|
+
if (nodeType == "skShader") {
|
353
|
+
auto *pushShaderCmd = static_cast<PushShaderCmd *>(cmd.get());
|
354
|
+
pushShaderCmd->pushShader(ctx);
|
355
|
+
} else if (nodeType == "skImageShader") {
|
356
|
+
auto *pushImageShaderCmd =
|
357
|
+
static_cast<PushImageShaderCmd *>(cmd.get());
|
358
|
+
pushImageShaderCmd->pushShader(ctx);
|
359
|
+
} else if (nodeType == "skColorShader") {
|
360
|
+
auto *colorShaderCmd = static_cast<ColorShaderCmd *>(cmd.get());
|
361
|
+
colorShaderCmd->pushShader(ctx);
|
362
|
+
} else if (nodeType == "skTurbulence") {
|
363
|
+
auto *turbulenceCmd = static_cast<TurbulenceCmd *>(cmd.get());
|
364
|
+
turbulenceCmd->pushShader(ctx);
|
365
|
+
} else if (nodeType == "skFractalNoise") {
|
366
|
+
auto *fractalNoiseCmd = static_cast<FractalNoiseCmd *>(cmd.get());
|
367
|
+
fractalNoiseCmd->pushShader(ctx);
|
368
|
+
} else if (nodeType == "skLinearGradient") {
|
369
|
+
auto *linearGradientCmd = static_cast<LinearGradientCmd *>(cmd.get());
|
370
|
+
linearGradientCmd->pushShader(ctx);
|
371
|
+
} else if (nodeType == "skRadialGradient") {
|
372
|
+
auto *radialGradientCmd = static_cast<RadialGradientCmd *>(cmd.get());
|
373
|
+
radialGradientCmd->pushShader(ctx);
|
374
|
+
} else if (nodeType == "skSweepGradient") {
|
375
|
+
auto *sweepGradientCmd = static_cast<SweepGradientCmd *>(cmd.get());
|
376
|
+
sweepGradientCmd->pushShader(ctx);
|
377
|
+
} else if (nodeType == "skTwoPointConicalGradient") {
|
378
|
+
auto *twoPointConicalGradientCmd =
|
379
|
+
static_cast<TwoPointConicalGradientCmd *>(cmd.get());
|
380
|
+
twoPointConicalGradientCmd->pushShader(ctx);
|
381
|
+
} else if (nodeType == "skBlendShader") {
|
382
|
+
auto *blendShaderCmd = static_cast<BlendShaderCmd *>(cmd.get());
|
383
|
+
blendShaderCmd->pushShader(ctx);
|
384
|
+
} else {
|
385
|
+
throw std::runtime_error("Invalid shader type: " + nodeType);
|
386
|
+
}
|
387
|
+
break;
|
388
|
+
}
|
389
|
+
|
390
|
+
case CommandType::PushImageFilter: {
|
391
|
+
auto nodeType = cmd->nodeType;
|
392
|
+
if (nodeType == "skOffsetImageFilter") {
|
393
|
+
auto *offsetCmd = static_cast<OffsetImageFilterCmd *>(cmd.get());
|
394
|
+
offsetCmd->pushImageFilter(ctx);
|
395
|
+
} else if (nodeType == "skDisplacementMapImageFilter") {
|
396
|
+
auto *displacementCmd =
|
397
|
+
static_cast<DisplacementMapImageFilterCmd *>(cmd.get());
|
398
|
+
displacementCmd->pushImageFilter(ctx);
|
399
|
+
} else if (nodeType == "skBlurImageFilter") {
|
400
|
+
auto *blurCmd = static_cast<BlurImageFilterCmd *>(cmd.get());
|
401
|
+
blurCmd->pushImageFilter(ctx);
|
402
|
+
} else if (nodeType == "skDropShadowImageFilter") {
|
403
|
+
auto *dropShadowCmd =
|
404
|
+
static_cast<DropShadowImageFilterCmd *>(cmd.get());
|
405
|
+
dropShadowCmd->pushImageFilter(ctx);
|
406
|
+
} else if (nodeType == "skMorphologyImageFilter") {
|
407
|
+
auto *morphologyCmd =
|
408
|
+
static_cast<MorphologyImageFilterCmd *>(cmd.get());
|
409
|
+
morphologyCmd->pushImageFilter(ctx);
|
410
|
+
} else if (nodeType == "skBlendImageFilter") {
|
411
|
+
auto *blendCmd = static_cast<BlendImageFilterCmd *>(cmd.get());
|
412
|
+
blendCmd->pushImageFilter(ctx);
|
413
|
+
} else if (nodeType == "skRuntimeShaderImageFilter") {
|
414
|
+
auto *runtimeShaderCmd =
|
415
|
+
static_cast<RuntimeShaderImageFilterCmd *>(cmd.get());
|
416
|
+
runtimeShaderCmd->pushImageFilter(ctx);
|
417
|
+
} else {
|
418
|
+
throw std::runtime_error("Invalid image filter type: " + nodeType);
|
419
|
+
}
|
420
|
+
break;
|
421
|
+
}
|
422
|
+
|
423
|
+
case CommandType::PushPathEffect: {
|
424
|
+
auto nodeType = cmd->nodeType;
|
425
|
+
if (nodeType == "skDiscretePathEffect") {
|
426
|
+
auto *discreteCmd = static_cast<DiscretePathEffectCmd *>(cmd.get());
|
427
|
+
discreteCmd->pushPathEffect(ctx);
|
428
|
+
} else if (nodeType == "skDashPathEffect") {
|
429
|
+
auto *dashCmd = static_cast<DashPathEffectCmd *>(cmd.get());
|
430
|
+
dashCmd->pushPathEffect(ctx);
|
431
|
+
} else if (nodeType == "skPath1DPathEffect") {
|
432
|
+
auto *path1DCmd = static_cast<Path1DPathEffectCmd *>(cmd.get());
|
433
|
+
path1DCmd->pushPathEffect(ctx);
|
434
|
+
} else if (nodeType == "skPath2DPathEffect") {
|
435
|
+
auto *path2DCmd = static_cast<Path2DPathEffectCmd *>(cmd.get());
|
436
|
+
path2DCmd->pushPathEffect(ctx);
|
437
|
+
} else if (nodeType == "skCornerPathEffect") {
|
438
|
+
auto *cornerCmd = static_cast<CornerPathEffectCmd *>(cmd.get());
|
439
|
+
cornerCmd->pushPathEffect(ctx);
|
440
|
+
} else if (nodeType == "skSumPathEffect") {
|
441
|
+
auto *sumCmd = static_cast<SumPathEffectCmd *>(cmd.get());
|
442
|
+
sumCmd->pushPathEffect(ctx);
|
443
|
+
} else if (nodeType == "skLine2DPathEffect") {
|
444
|
+
auto *line2DCmd = static_cast<Line2DPathEffectCmd *>(cmd.get());
|
445
|
+
line2DCmd->pushPathEffect(ctx);
|
446
|
+
} else {
|
447
|
+
throw std::runtime_error("Invalid path effect type: " + nodeType);
|
448
|
+
}
|
449
|
+
break;
|
450
|
+
}
|
451
|
+
|
452
|
+
case CommandType::PushColorFilter: {
|
453
|
+
auto nodeType = cmd->nodeType;
|
454
|
+
if (nodeType == "skMatrixColorFilter") {
|
455
|
+
auto *matrixCmd = static_cast<MatrixColorFilterCmd *>(cmd.get());
|
456
|
+
matrixCmd->pushColorFilter(ctx);
|
457
|
+
} else if (nodeType == "skBlendColorFilter") {
|
458
|
+
auto *blendCmd = static_cast<BlendColorFilterCmd *>(cmd.get());
|
459
|
+
blendCmd->pushColorFilter(ctx);
|
460
|
+
} else if (nodeType == "skLinearToSRGBGammaColorFilter") {
|
461
|
+
auto *linearToSRGBCmd =
|
462
|
+
static_cast<LinearToSRGBGammaColorFilterCmd *>(cmd.get());
|
463
|
+
linearToSRGBCmd->pushColorFilter(ctx);
|
464
|
+
} else if (nodeType == "skSRGBToLinearGammaColorFilter") {
|
465
|
+
auto *srgbToLinearCmd =
|
466
|
+
static_cast<SRGBToLinearGammaColorFilterCmd *>(cmd.get());
|
467
|
+
srgbToLinearCmd->pushColorFilter(ctx);
|
468
|
+
} else if (nodeType == "skLumaColorFilter") {
|
469
|
+
auto *lumaCmd = static_cast<LumaColorFilterCmd *>(cmd.get());
|
470
|
+
lumaCmd->pushColorFilter(ctx);
|
471
|
+
} else if (nodeType == "skLerpColorFilter") {
|
472
|
+
auto *lerpCmd = static_cast<LerpColorFilterCmd *>(cmd.get());
|
473
|
+
lerpCmd->pushColorFilter(ctx);
|
474
|
+
} else {
|
475
|
+
throw std::runtime_error("Invalid color filter type: " + nodeType);
|
476
|
+
}
|
477
|
+
break;
|
478
|
+
}
|
479
|
+
|
480
|
+
case CommandType::PushBlurMaskFilter: {
|
481
|
+
auto *blurMaskFilterCmd = static_cast<BlurMaskFilterCmd *>(cmd.get());
|
482
|
+
blurMaskFilterCmd->pushMaskFilter(ctx);
|
483
|
+
break;
|
484
|
+
}
|
485
|
+
|
486
|
+
case CommandType::DrawPaint: {
|
487
|
+
ctx->canvas->drawPaint(ctx->getPaint());
|
488
|
+
break;
|
489
|
+
}
|
490
|
+
|
491
|
+
case CommandType::DrawText: {
|
492
|
+
auto *textCmd = static_cast<TextCmd *>(cmd.get());
|
493
|
+
textCmd->draw(ctx);
|
494
|
+
break;
|
495
|
+
}
|
496
|
+
|
497
|
+
case CommandType::RestorePaint: {
|
498
|
+
ctx->restorePaint();
|
499
|
+
break;
|
500
|
+
}
|
501
|
+
|
502
|
+
case CommandType::SaveCTM: {
|
503
|
+
auto *saveCTMCmd = static_cast<SaveCTMCmd *>(cmd.get());
|
504
|
+
saveCTMCmd->saveCTM(ctx);
|
505
|
+
break;
|
506
|
+
}
|
507
|
+
|
508
|
+
case CommandType::RestoreCTM: {
|
509
|
+
ctx->canvas->restore();
|
510
|
+
break;
|
511
|
+
}
|
512
|
+
default: {
|
513
|
+
// Handle all drawing commands
|
514
|
+
auto currentPaints = ctx->paintDeclarations;
|
515
|
+
currentPaints.push_back(ctx->getPaint()); // Add current paint
|
516
|
+
ctx->paintDeclarations.clear();
|
517
|
+
|
518
|
+
for (auto &paint : currentPaints) {
|
519
|
+
ctx->pushPaint(paint);
|
520
|
+
|
521
|
+
switch (cmd->type) {
|
522
|
+
case CommandType::DrawPaint: {
|
523
|
+
ctx->canvas->drawPaint(paint);
|
524
|
+
break;
|
525
|
+
}
|
526
|
+
case CommandType::DrawCircle: {
|
527
|
+
auto *circleCmd = static_cast<CircleCmd *>(cmd.get());
|
528
|
+
circleCmd->draw(ctx);
|
529
|
+
break;
|
530
|
+
}
|
531
|
+
case CommandType::DrawPath: {
|
532
|
+
auto *pathCmd = static_cast<PathCmd *>(cmd.get());
|
533
|
+
pathCmd->draw(ctx);
|
534
|
+
break;
|
535
|
+
}
|
536
|
+
case CommandType::DrawRect: {
|
537
|
+
auto *rectCmd = static_cast<RectCmd *>(cmd.get());
|
538
|
+
rectCmd->draw(ctx);
|
539
|
+
break;
|
540
|
+
}
|
541
|
+
case CommandType::DrawLine: {
|
542
|
+
auto *lineCmd = static_cast<LineCmd *>(cmd.get());
|
543
|
+
lineCmd->draw(ctx);
|
544
|
+
break;
|
545
|
+
}
|
546
|
+
case CommandType::DrawTextPath: {
|
547
|
+
auto *textPathCmd = static_cast<TextPathCmd *>(cmd.get());
|
548
|
+
textPathCmd->draw(ctx);
|
549
|
+
break;
|
550
|
+
}
|
551
|
+
case CommandType::DrawText: {
|
552
|
+
auto *textCmd = static_cast<TextCmd *>(cmd.get());
|
553
|
+
textCmd->draw(ctx);
|
554
|
+
break;
|
555
|
+
}
|
556
|
+
case CommandType::DrawBox: {
|
557
|
+
auto *boxCmd = static_cast<BoxCmd *>(cmd.get());
|
558
|
+
boxCmd->draw(ctx);
|
559
|
+
break;
|
560
|
+
}
|
561
|
+
case CommandType::DrawImage: {
|
562
|
+
auto *imageCmd = static_cast<ImageCmd *>(cmd.get());
|
563
|
+
imageCmd->draw(ctx);
|
564
|
+
break;
|
565
|
+
}
|
566
|
+
case CommandType::DrawPoints: {
|
567
|
+
auto *pointsCmd = static_cast<PointsCmd *>(cmd.get());
|
568
|
+
pointsCmd->draw(ctx);
|
569
|
+
break;
|
570
|
+
}
|
571
|
+
case CommandType::DrawRRect: {
|
572
|
+
auto *rRectCmd = static_cast<RRectCmd *>(cmd.get());
|
573
|
+
rRectCmd->draw(ctx);
|
574
|
+
break;
|
575
|
+
}
|
576
|
+
case CommandType::DrawOval: {
|
577
|
+
auto *ovalCmd = static_cast<OvalCmd *>(cmd.get());
|
578
|
+
ovalCmd->draw(ctx);
|
579
|
+
break;
|
580
|
+
}
|
581
|
+
case CommandType::DrawPatch: {
|
582
|
+
auto *patchCmd = static_cast<PatchCmd *>(cmd.get());
|
583
|
+
patchCmd->draw(ctx);
|
584
|
+
break;
|
585
|
+
}
|
586
|
+
case CommandType::DrawVertices: {
|
587
|
+
auto *verticesCmd = static_cast<VerticesCmd *>(cmd.get());
|
588
|
+
verticesCmd->draw(ctx);
|
589
|
+
break;
|
590
|
+
}
|
591
|
+
case CommandType::DrawDiffRect: {
|
592
|
+
auto *diffRectCmd = static_cast<DiffRectCmd *>(cmd.get());
|
593
|
+
diffRectCmd->draw(ctx);
|
594
|
+
break;
|
595
|
+
}
|
596
|
+
case CommandType::DrawTextBlob: {
|
597
|
+
auto *textBlobCmd = static_cast<TextBlobCmd *>(cmd.get());
|
598
|
+
textBlobCmd->draw(ctx);
|
599
|
+
break;
|
600
|
+
}
|
601
|
+
case CommandType::DrawGlyphs: {
|
602
|
+
auto *glyphsCmd = static_cast<GlyphsCmd *>(cmd.get());
|
603
|
+
glyphsCmd->draw(ctx);
|
604
|
+
break;
|
605
|
+
}
|
606
|
+
case CommandType::DrawPicture: {
|
607
|
+
auto *pictureCmd = static_cast<PictureCmd *>(cmd.get());
|
608
|
+
pictureCmd->draw(ctx);
|
609
|
+
break;
|
610
|
+
}
|
611
|
+
case CommandType::DrawImageSVG: {
|
612
|
+
auto *imageSVGCmd = static_cast<ImageSVGCmd *>(cmd.get());
|
613
|
+
imageSVGCmd->draw(ctx);
|
614
|
+
break;
|
615
|
+
}
|
616
|
+
case CommandType::DrawParagraph: {
|
617
|
+
auto *paragraphCmd = static_cast<ParagraphCmd *>(cmd.get());
|
618
|
+
paragraphCmd->draw(ctx);
|
619
|
+
break;
|
620
|
+
}
|
621
|
+
case CommandType::DrawAtlas: {
|
622
|
+
auto *atlasCmd = static_cast<AtlasCmd *>(cmd.get());
|
623
|
+
atlasCmd->draw(ctx);
|
624
|
+
break;
|
625
|
+
}
|
626
|
+
}
|
627
|
+
|
628
|
+
ctx->restorePaint();
|
629
|
+
}
|
630
|
+
break;
|
631
|
+
}
|
632
|
+
}
|
633
|
+
}
|
634
|
+
}
|
635
|
+
};
|
636
|
+
|
637
|
+
} // namespace RNSkia
|