@shopify/react-native-skia 0.1.163 → 0.1.164
Sign up to get free protection for your applications and to get access to all the features.
- package/cpp/api/JsiSkPaint.h +6 -0
- package/cpp/jsi/JsiHostObject.h +25 -25
- package/cpp/rnskia/dom/base/DrawingContext.cpp +24 -9
- package/cpp/rnskia/dom/base/DrawingContext.h +3 -2
- package/cpp/rnskia/dom/base/JsiDomDeclarationNode.h +12 -2
- package/cpp/rnskia/dom/base/JsiDomDrawingNode.h +4 -4
- package/cpp/rnskia/dom/base/JsiDomNode.h +68 -10
- package/cpp/rnskia/dom/base/JsiDomRenderNode.h +26 -61
- package/cpp/rnskia/dom/base/NodeProp.h +2 -1
- package/cpp/rnskia/dom/base/NodePropsContainer.h +10 -0
- package/cpp/rnskia/dom/nodes/JsiBlendNode.h +1 -2
- package/cpp/rnskia/dom/nodes/JsiBlurMaskNode.h +3 -6
- package/cpp/rnskia/dom/nodes/JsiBoxNode.h +2 -4
- package/cpp/rnskia/dom/nodes/JsiBoxShadowNode.h +1 -2
- package/cpp/rnskia/dom/nodes/JsiCircleNode.h +2 -3
- package/cpp/rnskia/dom/nodes/JsiColorFilterNodes.h +4 -8
- package/cpp/rnskia/dom/nodes/JsiCustomDrawingNode.h +1 -2
- package/cpp/rnskia/dom/nodes/JsiDiffRectNode.h +2 -7
- package/cpp/rnskia/dom/nodes/JsiGlyphsNode.h +4 -8
- package/cpp/rnskia/dom/nodes/JsiImageFilterNodes.h +19 -37
- package/cpp/rnskia/dom/nodes/JsiImageNode.h +1 -1
- package/cpp/rnskia/dom/nodes/JsiImageSvgNode.h +2 -4
- package/cpp/rnskia/dom/nodes/JsiLineNode.h +2 -7
- package/cpp/rnskia/dom/nodes/JsiOvalNode.h +1 -3
- package/cpp/rnskia/dom/nodes/JsiPaintNode.h +2 -3
- package/cpp/rnskia/dom/nodes/JsiPatchNode.h +4 -8
- package/cpp/rnskia/dom/nodes/JsiPathEffectNodes.h +14 -28
- package/cpp/rnskia/dom/nodes/JsiPathNode.h +6 -16
- package/cpp/rnskia/dom/nodes/JsiPictureNode.h +1 -2
- package/cpp/rnskia/dom/nodes/JsiPointsNode.h +2 -5
- package/cpp/rnskia/dom/nodes/JsiRRectNode.h +1 -2
- package/cpp/rnskia/dom/nodes/JsiRectNode.h +1 -2
- package/cpp/rnskia/dom/nodes/JsiShaderNodes.h +37 -69
- package/cpp/rnskia/dom/nodes/JsiTextBlobNode.h +3 -6
- package/cpp/rnskia/dom/nodes/JsiTextNode.h +4 -8
- package/cpp/rnskia/dom/nodes/JsiTextPathNode.h +1 -2
- package/cpp/rnskia/dom/nodes/JsiVerticesNode.h +2 -4
- package/cpp/rnskia/dom/props/PaintProps.h +1 -2
- package/cpp/rnskia/dom/props/TransformProp.h +0 -2
- package/cpp/utils/RNSkLog.h +1 -1
- package/lib/commonjs/dom/nodes/RenderNode.js +12 -16
- package/lib/commonjs/dom/nodes/RenderNode.js.map +1 -1
- package/lib/commonjs/dom/nodes/datatypes/index.js +0 -13
- package/lib/commonjs/dom/nodes/datatypes/index.js.map +1 -1
- package/lib/commonjs/dom/nodes/drawings/Box.js +6 -6
- package/lib/commonjs/dom/nodes/drawings/Box.js.map +1 -1
- package/lib/commonjs/dom/nodes/drawings/PatchNode.js +3 -7
- package/lib/commonjs/dom/nodes/drawings/PatchNode.js.map +1 -1
- package/lib/commonjs/dom/nodes/drawings/VerticesNode.js +1 -1
- package/lib/commonjs/dom/nodes/drawings/VerticesNode.js.map +1 -1
- package/lib/commonjs/dom/nodes/paint/ColorFilters.js +1 -3
- package/lib/commonjs/dom/nodes/paint/ColorFilters.js.map +1 -1
- package/lib/commonjs/dom/nodes/paint/ImageFilters.js +1 -1
- package/lib/commonjs/dom/nodes/paint/ImageFilters.js.map +1 -1
- package/lib/commonjs/dom/nodes/paint/Shaders.js +1 -3
- package/lib/commonjs/dom/nodes/paint/Shaders.js.map +1 -1
- package/lib/commonjs/dom/types/DrawingContext.js.map +1 -1
- package/lib/commonjs/renderer/DrawingContext.js.map +1 -1
- package/lib/commonjs/skia/types/Paint/Paint.js.map +1 -1
- package/lib/commonjs/skia/web/JsiSkPaint.js +4 -0
- package/lib/commonjs/skia/web/JsiSkPaint.js.map +1 -1
- package/lib/commonjs/web/LoadSkiaWeb.js +1 -1
- package/lib/commonjs/web/LoadSkiaWeb.js.map +1 -1
- package/lib/module/dom/nodes/RenderNode.js +12 -16
- package/lib/module/dom/nodes/RenderNode.js.map +1 -1
- package/lib/module/dom/nodes/datatypes/index.js +0 -1
- package/lib/module/dom/nodes/datatypes/index.js.map +1 -1
- package/lib/module/dom/nodes/drawings/Box.js +6 -5
- package/lib/module/dom/nodes/drawings/Box.js.map +1 -1
- package/lib/module/dom/nodes/drawings/PatchNode.js +4 -8
- package/lib/module/dom/nodes/drawings/PatchNode.js.map +1 -1
- package/lib/module/dom/nodes/drawings/VerticesNode.js +2 -2
- package/lib/module/dom/nodes/drawings/VerticesNode.js.map +1 -1
- package/lib/module/dom/nodes/paint/ColorFilters.js +1 -2
- package/lib/module/dom/nodes/paint/ColorFilters.js.map +1 -1
- package/lib/module/dom/nodes/paint/ImageFilters.js +2 -2
- package/lib/module/dom/nodes/paint/ImageFilters.js.map +1 -1
- package/lib/module/dom/nodes/paint/Shaders.js +1 -2
- package/lib/module/dom/nodes/paint/Shaders.js.map +1 -1
- package/lib/module/dom/types/DrawingContext.js.map +1 -1
- package/lib/module/renderer/DrawingContext.js.map +1 -1
- package/lib/module/skia/types/Paint/Paint.js.map +1 -1
- package/lib/module/skia/web/JsiSkPaint.js +4 -0
- package/lib/module/skia/web/JsiSkPaint.js.map +1 -1
- package/lib/module/web/LoadSkiaWeb.js +1 -1
- package/lib/module/web/LoadSkiaWeb.js.map +1 -1
- package/lib/typescript/src/dom/nodes/datatypes/index.d.ts +0 -1
- package/lib/typescript/src/dom/nodes/drawings/Box.d.ts +1 -1
- package/lib/typescript/src/dom/nodes/drawings/PatchNode.d.ts +1 -1
- package/lib/typescript/src/dom/types/DrawingContext.d.ts +0 -1
- package/lib/typescript/src/renderer/DrawingContext.d.ts +3 -5
- package/lib/typescript/src/skia/types/Paint/Paint.d.ts +4 -0
- package/lib/typescript/src/skia/web/JsiSkPaint.d.ts +1 -0
- package/package.json +1 -1
- package/src/dom/nodes/RenderNode.ts +11 -21
- package/src/dom/nodes/datatypes/index.ts +0 -1
- package/src/dom/nodes/drawings/Box.ts +7 -4
- package/src/dom/nodes/drawings/PatchNode.ts +4 -18
- package/src/dom/nodes/drawings/VerticesNode.ts +2 -2
- package/src/dom/nodes/paint/ColorFilters.ts +1 -2
- package/src/dom/nodes/paint/ImageFilters.ts +2 -2
- package/src/dom/nodes/paint/Shaders.ts +1 -2
- package/src/dom/types/DrawingContext.ts +0 -1
- package/src/renderer/DrawingContext.ts +5 -5
- package/src/skia/types/Paint/Paint.ts +5 -0
- package/src/skia/web/JsiSkPaint.ts +4 -0
- package/src/web/LoadSkiaWeb.tsx +1 -1
- package/lib/commonjs/dom/nodes/datatypes/Color.js +0 -27
- package/lib/commonjs/dom/nodes/datatypes/Color.js.map +0 -1
- package/lib/module/dom/nodes/datatypes/Color.js +0 -11
- package/lib/module/dom/nodes/datatypes/Color.js.map +0 -1
- package/lib/typescript/src/dom/nodes/datatypes/Color.d.ts +0 -7
- package/src/dom/nodes/datatypes/Color.ts +0 -15
package/cpp/api/JsiSkPaint.h
CHANGED
@@ -63,6 +63,11 @@ public:
|
|
63
63
|
return static_cast<double>(getObject()->getStrokeWidth());
|
64
64
|
}
|
65
65
|
|
66
|
+
JSI_HOST_FUNCTION(getAlphaf) {
|
67
|
+
float alphaf = getObject()->getAlphaf();
|
68
|
+
return jsi::Value(SkScalarToDouble(alphaf));
|
69
|
+
}
|
70
|
+
|
66
71
|
JSI_HOST_FUNCTION(setColor) {
|
67
72
|
SkColor color = JsiSkColor::fromValue(runtime, arguments[0]);
|
68
73
|
getObject()->setColor(color);
|
@@ -159,6 +164,7 @@ public:
|
|
159
164
|
|
160
165
|
JSI_EXPORT_FUNCTIONS(JSI_EXPORT_FUNC(JsiSkPaint, copy),
|
161
166
|
JSI_EXPORT_FUNC(JsiSkPaint, reset),
|
167
|
+
JSI_EXPORT_FUNC(JsiSkPaint, getAlphaf),
|
162
168
|
JSI_EXPORT_FUNC(JsiSkPaint, getColor),
|
163
169
|
JSI_EXPORT_FUNC(JsiSkPaint, getStrokeCap),
|
164
170
|
JSI_EXPORT_FUNC(JsiSkPaint, getStrokeJoin),
|
package/cpp/jsi/JsiHostObject.h
CHANGED
@@ -132,31 +132,6 @@ public:
|
|
132
132
|
JsiHostObject();
|
133
133
|
~JsiHostObject();
|
134
134
|
|
135
|
-
protected:
|
136
|
-
/**
|
137
|
-
Override to return map of name/functions
|
138
|
-
*/
|
139
|
-
virtual const RNJsi::JsiFunctionMap &getExportedFunctionMap() {
|
140
|
-
static const RNJsi::JsiFunctionMap empty;
|
141
|
-
return empty;
|
142
|
-
}
|
143
|
-
|
144
|
-
/**
|
145
|
-
Override to get property getters map of name/functions
|
146
|
-
*/
|
147
|
-
virtual const JsiPropertyGettersMap &getExportedPropertyGettersMap() {
|
148
|
-
static const JsiPropertyGettersMap empty;
|
149
|
-
return empty;
|
150
|
-
}
|
151
|
-
|
152
|
-
/**
|
153
|
-
Override to get property setters map of name/functions
|
154
|
-
*/
|
155
|
-
virtual const JsiPropertySettersMap &getExportedPropertySettersMap() {
|
156
|
-
static const JsiPropertySettersMap empty;
|
157
|
-
return empty;
|
158
|
-
}
|
159
|
-
|
160
135
|
/**
|
161
136
|
* Overridden jsi::HostObject set property method
|
162
137
|
* @param rt Runtime
|
@@ -183,6 +158,31 @@ protected:
|
|
183
158
|
*/
|
184
159
|
std::vector<jsi::PropNameID> getPropertyNames(jsi::Runtime &runtime) override;
|
185
160
|
|
161
|
+
protected:
|
162
|
+
/**
|
163
|
+
Override to return map of name/functions
|
164
|
+
*/
|
165
|
+
virtual const RNJsi::JsiFunctionMap &getExportedFunctionMap() {
|
166
|
+
static const RNJsi::JsiFunctionMap empty;
|
167
|
+
return empty;
|
168
|
+
}
|
169
|
+
|
170
|
+
/**
|
171
|
+
Override to get property getters map of name/functions
|
172
|
+
*/
|
173
|
+
virtual const JsiPropertyGettersMap &getExportedPropertyGettersMap() {
|
174
|
+
static const JsiPropertyGettersMap empty;
|
175
|
+
return empty;
|
176
|
+
}
|
177
|
+
|
178
|
+
/**
|
179
|
+
Override to get property setters map of name/functions
|
180
|
+
*/
|
181
|
+
virtual const JsiPropertySettersMap &getExportedPropertySettersMap() {
|
182
|
+
static const JsiPropertySettersMap empty;
|
183
|
+
return empty;
|
184
|
+
}
|
185
|
+
|
186
186
|
/**
|
187
187
|
* Installs a function into the function map
|
188
188
|
*/
|
@@ -20,13 +20,6 @@ DrawingContext::inheritContext(const char *source) {
|
|
20
20
|
return result;
|
21
21
|
}
|
22
22
|
|
23
|
-
size_t DrawingContext::getLevel() {
|
24
|
-
if (_parent != nullptr) {
|
25
|
-
return _parent->getLevel() + 1;
|
26
|
-
}
|
27
|
-
return 0;
|
28
|
-
}
|
29
|
-
|
30
23
|
std::string DrawingContext::getDebugDescription() {
|
31
24
|
std::string v = "ctx for " + std::string(_source) + ":";
|
32
25
|
|
@@ -51,9 +44,27 @@ std::string DrawingContext::getDebugDescription() {
|
|
51
44
|
}
|
52
45
|
|
53
46
|
v += " opacity:" + std::to_string(_opacity);
|
47
|
+
|
54
48
|
if (_paint->getPathEffect() != nullptr) {
|
55
49
|
v += " [PathEffect]";
|
56
50
|
}
|
51
|
+
|
52
|
+
if (_paint->getShader() != nullptr) {
|
53
|
+
v += " [Shader]";
|
54
|
+
}
|
55
|
+
|
56
|
+
if (_paint->getImageFilter() != nullptr) {
|
57
|
+
v += " [ImageFilter]";
|
58
|
+
}
|
59
|
+
|
60
|
+
if (_paint->getMaskFilter() != nullptr) {
|
61
|
+
v += " [MaskFilter]";
|
62
|
+
}
|
63
|
+
|
64
|
+
if (_paint->getColorFilter() != nullptr) {
|
65
|
+
v += " [ColorFilter]";
|
66
|
+
}
|
67
|
+
|
57
68
|
} else {
|
58
69
|
v = v + "[inherited] " +
|
59
70
|
(_parent != nullptr ? _parent->getDebugDescription() : "");
|
@@ -168,8 +179,12 @@ double DrawingContext::getOpacity() {
|
|
168
179
|
Sets the opacity value
|
169
180
|
*/
|
170
181
|
void DrawingContext::setOpacity(double opacity) {
|
171
|
-
|
172
|
-
|
182
|
+
auto currentOpacity = opacity;
|
183
|
+
if (_parent != nullptr) {
|
184
|
+
currentOpacity *= _parent->getOpacity();
|
185
|
+
}
|
186
|
+
getMutablePaint()->setAlphaf(currentOpacity);
|
187
|
+
_opacity = currentOpacity;
|
173
188
|
}
|
174
189
|
|
175
190
|
/**
|
@@ -36,7 +36,7 @@ public:
|
|
36
36
|
*/
|
37
37
|
virtual void decorateContext(DrawingContext *context) {
|
38
38
|
#if SKIA_DOM_DEBUG
|
39
|
-
printDebugInfo(
|
39
|
+
printDebugInfo("Begin Materialize " + std::string(getType()));
|
40
40
|
#endif
|
41
41
|
// Materialize children first so that any inner nodes get the opportunity
|
42
42
|
// to calculate their state before this node continues.
|
@@ -51,11 +51,21 @@ public:
|
|
51
51
|
decorate(context);
|
52
52
|
|
53
53
|
#if SKIA_DOM_DEBUG
|
54
|
-
printDebugInfo(
|
54
|
+
printDebugInfo("End / Commit Materialize " + std::string(getType()));
|
55
55
|
#endif
|
56
56
|
}
|
57
57
|
|
58
58
|
protected:
|
59
|
+
/**
|
60
|
+
Invalidates and marks then context as changed. The implementation in the
|
61
|
+
declaration node is to pass the call upwards to the parent node
|
62
|
+
*/
|
63
|
+
void invalidateContext() override {
|
64
|
+
if (getParent() != nullptr) {
|
65
|
+
getParent()->invalidateContext();
|
66
|
+
}
|
67
|
+
}
|
68
|
+
|
59
69
|
/**
|
60
70
|
Override to implement materialization
|
61
71
|
*/
|
@@ -16,7 +16,7 @@ public:
|
|
16
16
|
protected:
|
17
17
|
void defineProperties(NodePropsContainer *container) override {
|
18
18
|
JsiDomRenderNode::defineProperties(container);
|
19
|
-
container->defineProperty
|
19
|
+
container->defineProperty<PaintProp>();
|
20
20
|
}
|
21
21
|
|
22
22
|
/**
|
@@ -26,11 +26,11 @@ protected:
|
|
26
26
|
|
27
27
|
void renderNode(DrawingContext *context) override {
|
28
28
|
#if SKIA_DOM_DEBUG
|
29
|
-
printDebugInfo(
|
29
|
+
printDebugInfo("Begin Draw", 1);
|
30
30
|
#endif
|
31
31
|
|
32
32
|
#if SKIA_DOM_DEBUG
|
33
|
-
printDebugInfo(context
|
33
|
+
printDebugInfo(context->getDebugDescription(), 2);
|
34
34
|
#endif
|
35
35
|
draw(context);
|
36
36
|
|
@@ -42,7 +42,7 @@ protected:
|
|
42
42
|
}
|
43
43
|
}
|
44
44
|
#if SKIA_DOM_DEBUG
|
45
|
-
printDebugInfo(
|
45
|
+
printDebugInfo("End Draw", 1);
|
46
46
|
#endif
|
47
47
|
}
|
48
48
|
};
|
@@ -168,6 +168,12 @@ public:
|
|
168
168
|
_disposeCallback = disposeCallback;
|
169
169
|
}
|
170
170
|
|
171
|
+
/**
|
172
|
+
Invalidates and marks then context as changed. The default behaviour is an
|
173
|
+
empty implementation
|
174
|
+
*/
|
175
|
+
virtual void invalidateContext() = 0;
|
176
|
+
|
171
177
|
/**
|
172
178
|
Updates any pending property changes in all nodes and child nodes. This
|
173
179
|
function will swap any pending property changes in this and children with any
|
@@ -188,6 +194,11 @@ public:
|
|
188
194
|
op();
|
189
195
|
}
|
190
196
|
|
197
|
+
// If there are any ops here we should invalidate the cached context
|
198
|
+
if (_queuedNodeOps.size() > 0) {
|
199
|
+
invalidateContext();
|
200
|
+
}
|
201
|
+
|
191
202
|
_queuedNodeOps.clear();
|
192
203
|
}
|
193
204
|
|
@@ -209,7 +220,11 @@ public:
|
|
209
220
|
}
|
210
221
|
|
211
222
|
// Now let's dispose if needed
|
212
|
-
if (_isDisposed) {
|
223
|
+
if (_isDisposing && !_isDisposed) {
|
224
|
+
_isDisposed = true;
|
225
|
+
|
226
|
+
this->setParent(nullptr);
|
227
|
+
|
213
228
|
// Callback signaling that we're done
|
214
229
|
if (_disposeCallback != nullptr) {
|
215
230
|
_disposeCallback();
|
@@ -266,6 +281,9 @@ protected:
|
|
266
281
|
always call the onPropsSet method as a signal that things have changed.
|
267
282
|
*/
|
268
283
|
void setProps(jsi::Runtime &runtime, jsi::Object &&props) {
|
284
|
+
#if SKIA_DOM_DEBUG
|
285
|
+
printDebugInfo("JS:setProps(nodeId: " + std::to_string(_nodeId) + ")");
|
286
|
+
#endif
|
269
287
|
if (_propsContainer == nullptr) {
|
270
288
|
|
271
289
|
// Initialize properties container
|
@@ -276,12 +294,18 @@ protected:
|
|
276
294
|
}
|
277
295
|
// Update properties container
|
278
296
|
_propsContainer->setProps(runtime, std::move(props));
|
297
|
+
|
298
|
+
// Invalidate context
|
299
|
+
invalidateContext();
|
279
300
|
}
|
280
301
|
|
281
302
|
/**
|
282
303
|
Called for components that has no properties
|
283
304
|
*/
|
284
305
|
void setEmptyProps() {
|
306
|
+
#if SKIA_DOM_DEBUG
|
307
|
+
printDebugInfo("JS:setEmptyProps(nodeId: " + std::to_string(_nodeId) + ")");
|
308
|
+
#endif
|
285
309
|
if (_propsContainer == nullptr) {
|
286
310
|
|
287
311
|
// Initialize properties container
|
@@ -304,8 +328,15 @@ protected:
|
|
304
328
|
Adds a child node to the array of children for this node
|
305
329
|
*/
|
306
330
|
virtual void addChild(std::shared_ptr<JsiDomNode> child) {
|
331
|
+
#if SKIA_DOM_DEBUG
|
332
|
+
printDebugInfo("JS:addChild(childId: " + std::to_string(child->_nodeId) +
|
333
|
+
")");
|
334
|
+
#endif
|
307
335
|
std::lock_guard<std::mutex> lock(_childrenLock);
|
308
|
-
_queuedNodeOps.push_back([child, this]() {
|
336
|
+
_queuedNodeOps.push_back([child, this]() {
|
337
|
+
_children.push_back(child);
|
338
|
+
child->setParent(this);
|
339
|
+
});
|
309
340
|
}
|
310
341
|
|
311
342
|
/**
|
@@ -314,10 +345,16 @@ protected:
|
|
314
345
|
*/
|
315
346
|
virtual void insertChildBefore(std::shared_ptr<JsiDomNode> child,
|
316
347
|
std::shared_ptr<JsiDomNode> before) {
|
348
|
+
#if SKIA_DOM_DEBUG
|
349
|
+
printDebugInfo(
|
350
|
+
"JS:insertChildBefore(childId: " + std::to_string(child->_nodeId) +
|
351
|
+
", beforeId: " + std::to_string(before->_nodeId) + ")");
|
352
|
+
#endif
|
317
353
|
std::lock_guard<std::mutex> lock(_childrenLock);
|
318
354
|
_queuedNodeOps.push_back([child, before, this]() {
|
319
355
|
auto position = std::find(_children.begin(), _children.end(), before);
|
320
356
|
_children.insert(position, child);
|
357
|
+
child->setParent(this);
|
321
358
|
});
|
322
359
|
}
|
323
360
|
|
@@ -326,6 +363,10 @@ protected:
|
|
326
363
|
children and call dispose on the child node.
|
327
364
|
*/
|
328
365
|
virtual void removeChild(std::shared_ptr<JsiDomNode> child) {
|
366
|
+
#if SKIA_DOM_DEBUG
|
367
|
+
printDebugInfo("JS:removeChild(childId: " + std::to_string(child->_nodeId) +
|
368
|
+
")");
|
369
|
+
#endif
|
329
370
|
std::lock_guard<std::mutex> lock(_childrenLock);
|
330
371
|
_queuedNodeOps.push_back([child, this]() {
|
331
372
|
// Delete child itself
|
@@ -343,26 +384,40 @@ protected:
|
|
343
384
|
up.
|
344
385
|
*/
|
345
386
|
virtual void dispose() {
|
346
|
-
if (
|
387
|
+
if (_isDisposing) {
|
347
388
|
return;
|
348
389
|
}
|
349
390
|
|
350
|
-
|
391
|
+
_isDisposing = true;
|
351
392
|
}
|
352
393
|
|
353
394
|
#if SKIA_DOM_DEBUG
|
354
|
-
std::string getLevelIndentation(
|
355
|
-
|
395
|
+
std::string getLevelIndentation(size_t indentation = 0) {
|
396
|
+
JsiDomNode *curParent = _parent;
|
397
|
+
while (curParent != nullptr) {
|
398
|
+
indentation++;
|
399
|
+
curParent = curParent->getParent();
|
400
|
+
}
|
401
|
+
return std::string(indentation * 2, ' ');
|
356
402
|
}
|
357
403
|
|
358
|
-
void printDebugInfo(
|
359
|
-
size_t indentation = 0) {
|
404
|
+
void printDebugInfo(const std::string &message, size_t indentation = 0) {
|
360
405
|
RNSkLogger::logToConsole("%s%s %lu: %s",
|
361
|
-
getLevelIndentation(
|
406
|
+
getLevelIndentation(indentation).c_str(),
|
362
407
|
getType(), getNodeId(), message.c_str());
|
363
408
|
}
|
364
409
|
#endif
|
365
410
|
|
411
|
+
/**
|
412
|
+
Sets the parent node
|
413
|
+
*/
|
414
|
+
void setParent(JsiDomNode *parent) { _parent = parent; }
|
415
|
+
|
416
|
+
/**
|
417
|
+
Returns the parent node if set.
|
418
|
+
*/
|
419
|
+
JsiDomNode *getParent() { return _parent; }
|
420
|
+
|
366
421
|
private:
|
367
422
|
const char *_type;
|
368
423
|
std::shared_ptr<RNSkPlatformContext> _context;
|
@@ -374,11 +429,14 @@ private:
|
|
374
429
|
std::vector<std::shared_ptr<JsiDomNode>> _children;
|
375
430
|
std::mutex _childrenLock;
|
376
431
|
|
377
|
-
std::atomic<bool>
|
432
|
+
std::atomic<bool> _isDisposing = {false};
|
433
|
+
bool _isDisposed = false;
|
378
434
|
|
379
435
|
size_t _nodeId;
|
380
436
|
|
381
437
|
std::vector<std::function<void()>> _queuedNodeOps;
|
438
|
+
|
439
|
+
JsiDomNode *_parent = nullptr;
|
382
440
|
};
|
383
441
|
|
384
442
|
} // namespace RNSkia
|
@@ -18,12 +18,6 @@
|
|
18
18
|
|
19
19
|
namespace RNSkia {
|
20
20
|
|
21
|
-
static PropId PropNameOrigin = JsiPropId::get("origin");
|
22
|
-
static PropId PropNameOpacity = JsiPropId::get("opacity");
|
23
|
-
static PropId PropNameClip = JsiPropId::get("clip");
|
24
|
-
static PropId PropNameInvertClip = JsiPropId::get("invertClip");
|
25
|
-
static PropId PropNameLayer = JsiPropId::get("layer");
|
26
|
-
|
27
21
|
class JsiDomRenderNode : public JsiDomNode {
|
28
22
|
public:
|
29
23
|
JsiDomRenderNode(std::shared_ptr<RNSkPlatformContext> context,
|
@@ -32,7 +26,7 @@ public:
|
|
32
26
|
|
33
27
|
void render(DrawingContext *context) {
|
34
28
|
#if SKIA_DOM_DEBUG
|
35
|
-
printDebugInfo(
|
29
|
+
printDebugInfo("Begin Render");
|
36
30
|
#endif
|
37
31
|
|
38
32
|
// Ensure we have a local drawing context inheriting from the parent context
|
@@ -50,27 +44,27 @@ public:
|
|
50
44
|
if (_layerProp->isSet()) {
|
51
45
|
if (_layerProp->isBool()) {
|
52
46
|
#if SKIA_DOM_DEBUG
|
53
|
-
printDebugInfo(
|
47
|
+
printDebugInfo("canvas->saveLayer()");
|
54
48
|
#endif
|
55
49
|
_localContext->getCanvas()->saveLayer(
|
56
50
|
SkCanvas::SaveLayerRec(nullptr, nullptr, nullptr, 0));
|
57
51
|
} else {
|
58
52
|
#if SKIA_DOM_DEBUG
|
59
|
-
printDebugInfo(
|
53
|
+
printDebugInfo("canvas->saveLayer(paint)");
|
60
54
|
#endif
|
61
55
|
_localContext->getCanvas()->saveLayer(SkCanvas::SaveLayerRec(
|
62
56
|
nullptr, _layerProp->getDerivedValue().get(), nullptr, 0));
|
63
57
|
}
|
64
58
|
} else {
|
65
59
|
#if SKIA_DOM_DEBUG
|
66
|
-
printDebugInfo(
|
60
|
+
printDebugInfo("canvas->save()");
|
67
61
|
#endif
|
68
62
|
_localContext->getCanvas()->save();
|
69
63
|
}
|
70
64
|
|
71
65
|
if (_originProp->isSet()) {
|
72
66
|
#if SKIA_DOM_DEBUG
|
73
|
-
printDebugInfo(
|
67
|
+
printDebugInfo("canvas->translate(origin)");
|
74
68
|
#endif
|
75
69
|
// Handle origin
|
76
70
|
_localContext->getCanvas()->translate(
|
@@ -81,10 +75,9 @@ public:
|
|
81
75
|
if (shouldTransform) {
|
82
76
|
#if SKIA_DOM_DEBUG
|
83
77
|
printDebugInfo(
|
84
|
-
context,
|
85
78
|
"canvas->concat(" +
|
86
|
-
|
87
|
-
|
79
|
+
std::string(_matrixProp->isSet() ? "matrix" : "transform") +
|
80
|
+
std::string(")"));
|
88
81
|
#endif
|
89
82
|
auto matrix = _matrixProp->isSet() ? _matrixProp->getDerivedValue()
|
90
83
|
: _transformProp->getDerivedValue();
|
@@ -101,7 +94,7 @@ public:
|
|
101
94
|
|
102
95
|
if (_originProp->isSet()) {
|
103
96
|
#if SKIA_DOM_DEBUG
|
104
|
-
printDebugInfo(
|
97
|
+
printDebugInfo("canvas->translate(-origin)");
|
105
98
|
#endif
|
106
99
|
// Handle origin
|
107
100
|
_localContext->getCanvas()->translate(
|
@@ -124,13 +117,13 @@ public:
|
|
124
117
|
// Restore if needed
|
125
118
|
if (shouldSave) {
|
126
119
|
#if SKIA_DOM_DEBUG
|
127
|
-
printDebugInfo(
|
120
|
+
printDebugInfo("canvas->restore()");
|
128
121
|
#endif
|
129
122
|
_localContext->getCanvas()->restore();
|
130
123
|
}
|
131
124
|
|
132
125
|
#if SKIA_DOM_DEBUG
|
133
|
-
printDebugInfo(
|
126
|
+
printDebugInfo("End Render");
|
134
127
|
#endif
|
135
128
|
}
|
136
129
|
|
@@ -158,41 +151,19 @@ public:
|
|
158
151
|
|
159
152
|
protected:
|
160
153
|
/**
|
161
|
-
|
162
|
-
context is correctly set.
|
163
|
-
*/
|
164
|
-
virtual void renderNode(DrawingContext *context) = 0;
|
165
|
-
|
166
|
-
/**
|
167
|
-
Removes a child
|
168
|
-
*/
|
169
|
-
void removeChild(std::shared_ptr<JsiDomNode> child) override {
|
170
|
-
JsiDomNode::removeChild(child);
|
171
|
-
if (_localContext != nullptr) {
|
172
|
-
_localContext->markAsChanged();
|
173
|
-
}
|
174
|
-
}
|
175
|
-
|
176
|
-
/**
|
177
|
-
Validates that only declaration nodes can be children
|
154
|
+
Invalidates and marks then context as changed.
|
178
155
|
*/
|
179
|
-
void
|
180
|
-
JsiDomNode::addChild(child);
|
156
|
+
void invalidateContext() override {
|
181
157
|
if (_localContext != nullptr) {
|
182
158
|
_localContext->markAsChanged();
|
183
159
|
}
|
184
160
|
}
|
185
161
|
|
186
162
|
/**
|
187
|
-
|
163
|
+
Override to implement rendering where the current state of the drawing
|
164
|
+
context is correctly set.
|
188
165
|
*/
|
189
|
-
void
|
190
|
-
std::shared_ptr<JsiDomNode> before) override {
|
191
|
-
JsiDomNode::insertChildBefore(child, before);
|
192
|
-
if (_localContext != nullptr) {
|
193
|
-
_localContext->markAsChanged();
|
194
|
-
}
|
195
|
-
}
|
166
|
+
virtual void renderNode(DrawingContext *context) = 0;
|
196
167
|
|
197
168
|
/**
|
198
169
|
Define common properties for all render nodes
|
@@ -200,20 +171,14 @@ protected:
|
|
200
171
|
void defineProperties(NodePropsContainer *container) override {
|
201
172
|
JsiDomNode::defineProperties(container);
|
202
173
|
|
203
|
-
_paintProps = container->defineProperty
|
204
|
-
|
205
|
-
_matrixProp =
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
_clipProp =
|
212
|
-
container->defineProperty(std::make_shared<ClipProp>(PropNameClip));
|
213
|
-
_invertClip = container->defineProperty(
|
214
|
-
std::make_shared<NodeProp>(PropNameInvertClip));
|
215
|
-
_layerProp =
|
216
|
-
container->defineProperty(std::make_shared<LayerProp>(PropNameLayer));
|
174
|
+
_paintProps = container->defineProperty<PaintProps>();
|
175
|
+
|
176
|
+
_matrixProp = container->defineProperty<MatrixProp>("matrix");
|
177
|
+
_transformProp = container->defineProperty<TransformProp>("transform");
|
178
|
+
_originProp = container->defineProperty<PointProp>("origin");
|
179
|
+
_clipProp = container->defineProperty<ClipProp>("clip");
|
180
|
+
_invertClip = container->defineProperty<NodeProp>("invertClip");
|
181
|
+
_layerProp = container->defineProperty<LayerProp>("layer");
|
217
182
|
}
|
218
183
|
|
219
184
|
private:
|
@@ -224,17 +189,17 @@ private:
|
|
224
189
|
auto op = invert ? SkClipOp::kDifference : SkClipOp::kIntersect;
|
225
190
|
if (_clipProp->getRect() != nullptr) {
|
226
191
|
#if SKIA_DOM_DEBUG
|
227
|
-
printDebugInfo(
|
192
|
+
printDebugInfo("canvas->clipRect()");
|
228
193
|
#endif
|
229
194
|
canvas->clipRect(*_clipProp->getRect(), op, true);
|
230
195
|
} else if (_clipProp->getRRect() != nullptr) {
|
231
196
|
#if SKIA_DOM_DEBUG
|
232
|
-
printDebugInfo(
|
197
|
+
printDebugInfo("canvas->clipRRect()");
|
233
198
|
#endif
|
234
199
|
canvas->clipRRect(*_clipProp->getRRect(), op, true);
|
235
200
|
} else if (_clipProp->getPath() != nullptr) {
|
236
201
|
#if SKIA_DOM_DEBUG
|
237
|
-
printDebugInfo(
|
202
|
+
printDebugInfo("canvas->clipPath()");
|
238
203
|
#endif
|
239
204
|
canvas->clipPath(*_clipProp->getPath(), op, true);
|
240
205
|
}
|
@@ -19,7 +19,8 @@ public:
|
|
19
19
|
/**
|
20
20
|
Constructs a new optional dom node properrty
|
21
21
|
*/
|
22
|
-
explicit NodeProp(
|
22
|
+
explicit NodeProp(const std::string &name)
|
23
|
+
: _name(JsiPropId::get(name)), BaseNodeProp() {}
|
23
24
|
|
24
25
|
/**
|
25
26
|
Reads JS value and swaps out with a new value
|
@@ -110,6 +110,16 @@ public:
|
|
110
110
|
return prop.get();
|
111
111
|
}
|
112
112
|
|
113
|
+
/**
|
114
|
+
Defines a property that will be updated with the container changes.
|
115
|
+
*/
|
116
|
+
template <class _Tp, class... _Args,
|
117
|
+
class = std::_EnableIf<!std::is_array<_Tp>::value>>
|
118
|
+
_Tp *defineProperty(_Args &&...__args) {
|
119
|
+
return defineProperty(
|
120
|
+
std::make_shared<_Tp>(std::forward<_Args>(__args)...));
|
121
|
+
}
|
122
|
+
|
113
123
|
private:
|
114
124
|
std::vector<std::shared_ptr<BaseNodeProp>> _properties;
|
115
125
|
std::map<PropId, std::vector<NodeProp *>> _mappedProperties;
|
@@ -70,8 +70,7 @@ protected:
|
|
70
70
|
|
71
71
|
void defineProperties(NodePropsContainer *container) override {
|
72
72
|
JsiBaseDomDeclarationNode::defineProperties(container);
|
73
|
-
_blendProp = container->defineProperty(
|
74
|
-
std::make_shared<BlendModeProp>(JsiPropId::get("mode")));
|
73
|
+
_blendProp = container->defineProperty<BlendModeProp>("mode");
|
75
74
|
_blendProp->require();
|
76
75
|
}
|
77
76
|
|
@@ -44,12 +44,9 @@ protected:
|
|
44
44
|
void defineProperties(NodePropsContainer *container) override {
|
45
45
|
JsiBaseDomDeclarationNode::defineProperties(container);
|
46
46
|
|
47
|
-
_style = container->defineProperty(
|
48
|
-
|
49
|
-
|
50
|
-
std::make_shared<NodeProp>(JsiPropId::get("respectCTM")));
|
51
|
-
_blur = container->defineProperty(
|
52
|
-
std::make_shared<NodeProp>(JsiPropId::get("blur")));
|
47
|
+
_style = container->defineProperty<NodeProp>("style");
|
48
|
+
_respectCTM = container->defineProperty<NodeProp>("respectCTM");
|
49
|
+
_blur = container->defineProperty<NodeProp>("blur");
|
53
50
|
|
54
51
|
_blur->require();
|
55
52
|
}
|
@@ -76,10 +76,8 @@ protected:
|
|
76
76
|
|
77
77
|
void defineProperties(NodePropsContainer *container) override {
|
78
78
|
JsiDomRenderNode::defineProperties(container);
|
79
|
-
_rrectProp = container->defineProperty(
|
80
|
-
|
81
|
-
_rectProp = container->defineProperty(
|
82
|
-
std::make_shared<RectProp>(JsiPropId::get("box")));
|
79
|
+
_rrectProp = container->defineProperty<RRectProp>("box");
|
80
|
+
_rectProp = container->defineProperty<RectProp>("box");
|
83
81
|
}
|
84
82
|
|
85
83
|
private:
|
@@ -22,8 +22,7 @@ protected:
|
|
22
22
|
|
23
23
|
void defineProperties(NodePropsContainer *container) override {
|
24
24
|
JsiBaseDomDeclarationNode::defineProperties(container);
|
25
|
-
_boxShadowProps =
|
26
|
-
container->defineProperty(std::make_shared<BoxShadowProps>());
|
25
|
+
_boxShadowProps = container->defineProperty<BoxShadowProps>();
|
27
26
|
}
|
28
27
|
|
29
28
|
private:
|
@@ -22,9 +22,8 @@ protected:
|
|
22
22
|
|
23
23
|
void defineProperties(NodePropsContainer *container) override {
|
24
24
|
JsiDomDrawingNode::defineProperties(container);
|
25
|
-
_circleProp = container->defineProperty
|
26
|
-
_radiusProp =
|
27
|
-
container->defineProperty(std::make_shared<NodeProp>(PropNameR));
|
25
|
+
_circleProp = container->defineProperty<CircleProp>();
|
26
|
+
_radiusProp = container->defineProperty<NodeProp>("r");
|
28
27
|
|
29
28
|
_circleProp->require();
|
30
29
|
_radiusProp->require();
|