@shopify/react-native-skia 0.1.154 → 0.1.156
Sign up to get free protection for your applications and to get access to all the features.
- package/android/cpp/jni/JniLoad.cpp +5 -5
- package/android/cpp/jni/JniPlatformContext.cpp +107 -119
- package/android/cpp/jni/JniSkiaManager.cpp +18 -20
- package/android/cpp/jni/include/JniPlatformContext.h +41 -45
- package/android/cpp/jni/include/JniSkiaBaseView.h +52 -55
- package/android/cpp/jni/include/JniSkiaDrawView.h +72 -77
- package/android/cpp/jni/include/JniSkiaManager.h +51 -53
- package/android/cpp/jni/include/JniSkiaPictureView.h +74 -78
- package/android/cpp/rnskia-android/RNSkAndroidPlatformContext.h +36 -45
- package/android/cpp/rnskia-android/RNSkAndroidView.h +87 -92
- package/android/cpp/rnskia-android/RNSkOpenGLCanvasProvider.cpp +62 -65
- package/android/cpp/rnskia-android/RNSkOpenGLCanvasProvider.h +20 -17
- package/android/cpp/rnskia-android/SkiaOpenGLRenderer.cpp +257 -313
- package/android/cpp/rnskia-android/SkiaOpenGLRenderer.h +107 -110
- package/cpp/api/JsiSkApi.h +66 -62
- package/cpp/api/JsiSkCanvas.h +38 -30
- package/cpp/api/JsiSkColor.h +58 -56
- package/cpp/api/JsiSkColorFilter.h +5 -3
- package/cpp/api/JsiSkColorFilterFactory.h +23 -21
- package/cpp/api/JsiSkContourMeasure.h +74 -85
- package/cpp/api/JsiSkContourMeasureIter.h +68 -75
- package/cpp/api/JsiSkData.h +16 -22
- package/cpp/api/JsiSkDataFactory.h +86 -79
- package/cpp/api/JsiSkFont.h +286 -311
- package/cpp/api/JsiSkHostObjects.h +15 -16
- package/cpp/api/JsiSkImage.h +107 -103
- package/cpp/api/JsiSkImageFactory.h +34 -36
- package/cpp/api/JsiSkImageFilter.h +5 -3
- package/cpp/api/JsiSkImageFilterFactory.h +71 -68
- package/cpp/api/JsiSkImageInfo.h +41 -38
- package/cpp/api/JsiSkMaskFilter.h +5 -3
- package/cpp/api/JsiSkMaskFilterFactory.h +2 -3
- package/cpp/api/JsiSkMatrix.h +26 -36
- package/cpp/api/JsiSkPaint.h +20 -13
- package/cpp/api/JsiSkPath.h +70 -85
- package/cpp/api/JsiSkPathEffect.h +5 -3
- package/cpp/api/JsiSkPathEffectFactory.h +33 -28
- package/cpp/api/JsiSkPathFactory.h +68 -67
- package/cpp/api/JsiSkPicture.h +28 -22
- package/cpp/api/JsiSkPictureFactory.h +13 -12
- package/cpp/api/JsiSkPictureRecorder.h +21 -19
- package/cpp/api/JsiSkPoint.h +6 -8
- package/cpp/api/JsiSkRRect.h +11 -7
- package/cpp/api/JsiSkRSXform.h +82 -85
- package/cpp/api/JsiSkRect.h +9 -9
- package/cpp/api/JsiSkRuntimeEffect.h +182 -186
- package/cpp/api/JsiSkRuntimeEffectFactory.h +10 -11
- package/cpp/api/JsiSkRuntimeShaderBuilder.h +64 -61
- package/cpp/api/JsiSkSVG.h +4 -5
- package/cpp/api/JsiSkSVGFactory.h +28 -27
- package/cpp/api/JsiSkShader.h +3 -2
- package/cpp/api/JsiSkShaderFactory.h +37 -25
- package/cpp/api/JsiSkSurface.h +44 -40
- package/cpp/api/JsiSkSurfaceFactory.h +22 -22
- package/cpp/api/JsiSkTextBlob.h +28 -31
- package/cpp/api/JsiSkTextBlobFactory.h +88 -87
- package/cpp/api/JsiSkTypeface.h +6 -5
- package/cpp/api/JsiSkTypefaceFactory.h +22 -21
- package/cpp/api/JsiSkVertices.h +137 -124
- package/cpp/api/third_party/CSSColorParser.cpp +161 -174
- package/cpp/api/third_party/CSSColorParser.h +172 -96
- package/cpp/jsi/JsiHostObject.cpp +11 -9
- package/cpp/jsi/JsiHostObject.h +31 -24
- package/cpp/jsi/JsiSimpleValueWrapper.h +74 -83
- package/cpp/jsi/JsiValueWrapper.h +52 -54
- package/cpp/rnskia/RNSkAnimation.h +26 -29
- package/cpp/rnskia/RNSkDispatchQueue.cpp +50 -61
- package/cpp/rnskia/RNSkDispatchQueue.h +3 -1
- package/cpp/rnskia/RNSkInfoParameter.h +12 -12
- package/cpp/rnskia/RNSkJsView.cpp +82 -81
- package/cpp/rnskia/RNSkJsView.h +45 -41
- package/cpp/rnskia/RNSkJsiViewApi.h +99 -89
- package/cpp/rnskia/RNSkManager.cpp +8 -7
- package/cpp/rnskia/RNSkManager.h +8 -6
- package/cpp/rnskia/RNSkPictureView.h +44 -37
- package/cpp/rnskia/RNSkPlatformContext.h +39 -28
- package/cpp/rnskia/RNSkValueApi.h +33 -34
- package/cpp/rnskia/RNSkView.h +108 -93
- package/cpp/rnskia/values/RNSkClockValue.h +63 -64
- package/cpp/rnskia/values/RNSkComputedValue.h +32 -30
- package/cpp/rnskia/values/RNSkReadonlyValue.h +60 -59
- package/cpp/rnskia/values/RNSkValue.h +38 -40
- package/cpp/utils/RNSkLog.h +9 -7
- package/cpp/utils/RNSkMeasureTime.h +7 -7
- package/cpp/utils/RNSkTimingInfo.h +27 -24
- package/ios/RNSkia-iOS/RNSkMetalCanvasProvider.h +8 -9
- package/ios/RNSkia-iOS/RNSkiOSPlatformContext.h +24 -23
- package/ios/RNSkia-iOS/RNSkiOSView.h +16 -13
- package/ios/RNSkia-iOS/SkiaUIView.h +9 -8
- package/lib/commonjs/dom/nodes/JsiSkDOM.js +6 -0
- package/lib/commonjs/dom/nodes/JsiSkDOM.js.map +1 -1
- package/lib/commonjs/dom/nodes/LayerNode.js +43 -0
- package/lib/commonjs/dom/nodes/LayerNode.js.map +1 -0
- package/lib/commonjs/dom/nodes/RenderNode.js +1 -1
- package/lib/commonjs/dom/nodes/RenderNode.js.map +1 -1
- package/lib/commonjs/dom/types/NodeType.js +1 -0
- package/lib/commonjs/dom/types/NodeType.js.map +1 -1
- package/lib/commonjs/dom/types/SkDOM.js.map +1 -1
- package/lib/commonjs/renderer/HostComponents.js +3 -0
- package/lib/commonjs/renderer/HostComponents.js.map +1 -1
- package/lib/commonjs/renderer/components/Group.js +19 -4
- package/lib/commonjs/renderer/components/Group.js.map +1 -1
- package/lib/commonjs/renderer/components/Paint.js +6 -1
- package/lib/commonjs/renderer/components/Paint.js.map +1 -1
- package/lib/commonjs/views/SkiaPictureView.js +3 -2
- package/lib/commonjs/views/SkiaPictureView.js.map +1 -1
- package/lib/commonjs/views/SkiaView.js +6 -3
- package/lib/commonjs/views/SkiaView.js.map +1 -1
- package/lib/module/dom/nodes/JsiSkDOM.js +5 -0
- package/lib/module/dom/nodes/JsiSkDOM.js.map +1 -1
- package/lib/module/dom/nodes/LayerNode.js +32 -0
- package/lib/module/dom/nodes/LayerNode.js.map +1 -0
- package/lib/module/dom/nodes/RenderNode.js +1 -1
- package/lib/module/dom/nodes/RenderNode.js.map +1 -1
- package/lib/module/dom/types/NodeType.js +1 -0
- package/lib/module/dom/types/NodeType.js.map +1 -1
- package/lib/module/dom/types/SkDOM.js.map +1 -1
- package/lib/module/renderer/HostComponents.js +3 -0
- package/lib/module/renderer/HostComponents.js.map +1 -1
- package/lib/module/renderer/components/Group.js +16 -3
- package/lib/module/renderer/components/Group.js.map +1 -1
- package/lib/module/renderer/components/Paint.js +7 -1
- package/lib/module/renderer/components/Paint.js.map +1 -1
- package/lib/module/views/SkiaPictureView.js +2 -2
- package/lib/module/views/SkiaPictureView.js.map +1 -1
- package/lib/module/views/SkiaView.js +4 -2
- package/lib/module/views/SkiaView.js.map +1 -1
- package/lib/typescript/src/dom/nodes/JsiSkDOM.d.ts +2 -0
- package/lib/typescript/src/dom/nodes/LayerNode.d.ts +8 -0
- package/lib/typescript/src/dom/types/NodeType.d.ts +1 -0
- package/lib/typescript/src/dom/types/SkDOM.d.ts +1 -0
- package/lib/typescript/src/renderer/HostComponents.d.ts +2 -1
- package/lib/typescript/src/renderer/components/Group.d.ts +5 -1
- package/lib/typescript/src/views/SkiaView.d.ts +3 -0
- package/libs/android/arm64-v8a/libskottie.a +0 -0
- package/libs/android/arm64-v8a/libsksg.a +0 -0
- package/libs/android/armeabi-v7a/libskottie.a +0 -0
- package/libs/android/armeabi-v7a/libsksg.a +0 -0
- package/libs/android/x86/libskottie.a +0 -0
- package/libs/android/x86/libsksg.a +0 -0
- package/libs/android/x86_64/libskottie.a +0 -0
- package/libs/android/x86_64/libsksg.a +0 -0
- package/libs/ios/libskia.xcframework/ios-arm64_arm64e/libskia.a +0 -0
- package/libs/ios/libskia.xcframework/ios-arm64_arm64e_x86_64-simulator/libskia.a +0 -0
- package/libs/ios/libskottie.xcframework/Info.plist +42 -0
- package/libs/ios/libskottie.xcframework/ios-arm64_arm64e/libskottie.a +0 -0
- package/libs/ios/libskottie.xcframework/ios-arm64_arm64e_x86_64-simulator/libskottie.a +0 -0
- package/libs/ios/libsksg.xcframework/Info.plist +42 -0
- package/libs/ios/libsksg.xcframework/ios-arm64_arm64e/libsksg.a +0 -0
- package/libs/ios/libsksg.xcframework/ios-arm64_arm64e_x86_64-simulator/libsksg.a +0 -0
- package/libs/ios/libskshaper.xcframework/Info.plist +5 -5
- package/libs/ios/libskshaper.xcframework/ios-arm64_arm64e/libskshaper.a +0 -0
- package/libs/ios/libskshaper.xcframework/ios-arm64_arm64e_x86_64-simulator/libskshaper.a +0 -0
- package/libs/ios/libsvg.xcframework/Info.plist +5 -5
- package/libs/ios/libsvg.xcframework/ios-arm64_arm64e/libsvg.a +0 -0
- package/libs/ios/libsvg.xcframework/ios-arm64_arm64e_x86_64-simulator/libsvg.a +0 -0
- package/package.json +3 -1
- package/src/dom/nodes/JsiSkDOM.ts +5 -0
- package/src/dom/nodes/LayerNode.ts +35 -0
- package/src/dom/nodes/RenderNode.ts +4 -3
- package/src/dom/types/NodeType.ts +1 -0
- package/src/dom/types/SkDOM.ts +1 -0
- package/src/renderer/HostComponents.ts +3 -0
- package/src/renderer/components/Group.tsx +16 -3
- package/src/renderer/components/Paint.tsx +7 -1
- package/src/views/SkiaPictureView.tsx +2 -3
- package/src/views/SkiaView.tsx +2 -2
@@ -1,108 +1,99 @@
|
|
1
|
-
|
2
1
|
#pragma once
|
3
2
|
|
3
|
+
#include <memory>
|
4
|
+
|
4
5
|
#include <jsi/jsi.h>
|
5
6
|
|
6
|
-
namespace RNJsi
|
7
|
-
|
8
|
-
using namespace facebook;
|
7
|
+
namespace RNJsi {
|
8
|
+
namespace jsi = facebook::jsi;
|
9
9
|
|
10
10
|
/**
|
11
|
-
Implements a simple wrapper class for JSI primitives like numbers and boolean
|
12
|
-
strings and arrays are stored as values inside a property
|
13
|
-
for comparing values that will compare
|
11
|
+
Implements a simple wrapper class for JSI primitives like numbers and boolean
|
12
|
+
values. Objects, strings and arrays are stored as values inside a property
|
13
|
+
holder. The class also provides a method for comparing values that will compare
|
14
|
+
numbers, booleans and strings.
|
14
15
|
*/
|
15
|
-
class JsiSimpleValueWrapper
|
16
|
-
{
|
16
|
+
class JsiSimpleValueWrapper {
|
17
17
|
private:
|
18
|
-
enum ValueType {
|
19
|
-
NonInitialized,
|
20
|
-
Undefined,
|
21
|
-
Null,
|
22
|
-
Bool,
|
23
|
-
Number,
|
24
|
-
JsiValue
|
25
|
-
};
|
18
|
+
enum ValueType { NonInitialized, Undefined, Null, Bool, Number, JsiValue };
|
26
19
|
|
27
20
|
public:
|
28
|
-
|
29
|
-
_type(ValueType::NonInitialized),
|
30
|
-
|
31
|
-
{}
|
21
|
+
explicit JsiSimpleValueWrapper(jsi::Runtime &runtime)
|
22
|
+
: _type(ValueType::NonInitialized),
|
23
|
+
_propNameId(jsi::PropNameID::forUtf8(runtime, "value")) {}
|
32
24
|
|
33
|
-
|
34
|
-
{
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
if (_valueHolder == nullptr) {
|
49
|
-
return jsi::Value::undefined();
|
50
|
-
}
|
51
|
-
return _valueHolder->getProperty(runtime, _propNameId);
|
25
|
+
jsi::Value getCurrent(jsi::Runtime &runtime) {
|
26
|
+
switch (_type) {
|
27
|
+
case ValueType::NonInitialized:
|
28
|
+
return nullptr;
|
29
|
+
case ValueType::Undefined:
|
30
|
+
return jsi::Value::undefined();
|
31
|
+
case ValueType::Null:
|
32
|
+
return jsi::Value::null();
|
33
|
+
case ValueType::Bool:
|
34
|
+
return _boolValue;
|
35
|
+
case ValueType::Number:
|
36
|
+
return _numberValue;
|
37
|
+
case ValueType::JsiValue:
|
38
|
+
if (_valueHolder == nullptr) {
|
39
|
+
return jsi::Value::undefined();
|
52
40
|
}
|
41
|
+
return _valueHolder->getProperty(runtime, _propNameId);
|
53
42
|
}
|
43
|
+
}
|
54
44
|
|
55
|
-
|
56
|
-
{
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
}
|
73
|
-
_valueHolder->setProperty(runtime, _propNameId, value);
|
45
|
+
void setCurrent(jsi::Runtime &runtime, const jsi::Value &value) {
|
46
|
+
if (value.isNumber()) {
|
47
|
+
_type = ValueType::Number;
|
48
|
+
_numberValue = value.asNumber();
|
49
|
+
} else if (value.isBool()) {
|
50
|
+
_type = ValueType::Bool;
|
51
|
+
_boolValue = value.getBool();
|
52
|
+
} else if (value.isUndefined()) {
|
53
|
+
_type = ValueType::Undefined;
|
54
|
+
} else if (value.isNull()) {
|
55
|
+
_type = ValueType::Null;
|
56
|
+
} else {
|
57
|
+
_type = ValueType::JsiValue;
|
58
|
+
// Save as javascript object - we don't want to have to copy strings,
|
59
|
+
// objects and values
|
60
|
+
if (_valueHolder == nullptr) {
|
61
|
+
_valueHolder = std::make_shared<jsi::Object>(runtime);
|
74
62
|
}
|
63
|
+
_valueHolder->setProperty(runtime, _propNameId, value);
|
75
64
|
}
|
65
|
+
}
|
76
66
|
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
return false;
|
67
|
+
bool equals(jsi::Runtime &runtime, const jsi::Value &value) {
|
68
|
+
if (_type == ValueType::NonInitialized) {
|
69
|
+
return false;
|
70
|
+
}
|
71
|
+
if (value.isNumber() && _type == ValueType::Number) {
|
72
|
+
return _numberValue == value.asNumber();
|
73
|
+
} else if (value.isBool() && _type == ValueType::Bool) {
|
74
|
+
return _boolValue == value.getBool();
|
75
|
+
} else if (value.isUndefined()) {
|
76
|
+
return _type == ValueType::Undefined;
|
77
|
+
} else if (value.isNull()) {
|
78
|
+
return _type == ValueType::Null;
|
79
|
+
} else if (value.isString()) {
|
80
|
+
auto current = getCurrent(runtime);
|
81
|
+
if (current.isString()) {
|
82
|
+
return jsi::String::strictEquals(runtime, value.asString(runtime),
|
83
|
+
current.asString(runtime));
|
95
84
|
}
|
96
85
|
return false;
|
97
86
|
}
|
87
|
+
return false;
|
88
|
+
}
|
98
89
|
|
99
90
|
private:
|
100
|
-
|
101
|
-
|
91
|
+
jsi::PropNameID _propNameId;
|
92
|
+
std::shared_ptr<jsi::Object> _valueHolder;
|
102
93
|
|
103
|
-
|
104
|
-
|
94
|
+
bool _boolValue;
|
95
|
+
double _numberValue;
|
105
96
|
|
106
|
-
|
97
|
+
ValueType _type;
|
107
98
|
};
|
108
|
-
}
|
99
|
+
} // namespace RNJsi
|
@@ -1,46 +1,42 @@
|
|
1
|
-
|
2
1
|
#pragma once
|
3
2
|
|
4
3
|
#include <jsi/jsi.h>
|
4
|
+
#include <memory>
|
5
|
+
#include <string>
|
6
|
+
|
7
|
+
namespace RNJsi {
|
8
|
+
namespace jsi = facebook::jsi;
|
5
9
|
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
Object,
|
19
|
-
Function,
|
20
|
-
Array,
|
21
|
-
HostObject,
|
22
|
-
Unknown
|
10
|
+
enum JsiWrapperValueType {
|
11
|
+
NonInitialized,
|
12
|
+
Undefined,
|
13
|
+
Null,
|
14
|
+
Bool,
|
15
|
+
Number,
|
16
|
+
String,
|
17
|
+
Object,
|
18
|
+
Function,
|
19
|
+
Array,
|
20
|
+
HostObject,
|
21
|
+
Unknown
|
23
22
|
};
|
24
23
|
|
25
24
|
/**
|
26
|
-
Implements a simple wrapper class for JSI values where the value can be read
|
27
|
-
|
25
|
+
Implements a simple wrapper class for JSI values where the value can be read
|
26
|
+
without asking the runtime for any assistance Meaning that we can access
|
27
|
+
members without being on the JS thread.
|
28
28
|
*/
|
29
|
-
class JsiValueWrapper
|
30
|
-
{
|
29
|
+
class JsiValueWrapper {
|
31
30
|
public:
|
32
|
-
JsiValueWrapper(jsi::Runtime&
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
_type(JsiWrapperValueType::NonInitialized)
|
38
|
-
{
|
31
|
+
explicit JsiValueWrapper(jsi::Runtime &runtime)
|
32
|
+
: _type(JsiWrapperValueType::NonInitialized) {}
|
33
|
+
|
34
|
+
JsiValueWrapper(jsi::Runtime &runtime, const jsi::Value &value)
|
35
|
+
: _type(JsiWrapperValueType::NonInitialized) {
|
39
36
|
setCurrent(runtime, value);
|
40
37
|
}
|
41
38
|
|
42
|
-
void setCurrent(jsi::Runtime &runtime, const jsi::Value &value)
|
43
|
-
{
|
39
|
+
void setCurrent(jsi::Runtime &runtime, const jsi::Value &value) {
|
44
40
|
if (value.isNumber()) {
|
45
41
|
_type = JsiWrapperValueType::Number;
|
46
42
|
_numberValue = value.asNumber();
|
@@ -59,11 +55,13 @@ public:
|
|
59
55
|
_objectValue = std::make_shared<jsi::Object>(value.asObject(runtime));
|
60
56
|
if (_objectValue->isFunction(runtime)) {
|
61
57
|
_type = JsiWrapperValueType::Function;
|
62
|
-
_functionValue =
|
58
|
+
_functionValue =
|
59
|
+
std::make_shared<jsi::Function>(_objectValue->asFunction(runtime));
|
63
60
|
_objectValue = nullptr;
|
64
61
|
} else if (_objectValue->isArray(runtime)) {
|
65
62
|
_type = JsiWrapperValueType::Array;
|
66
|
-
_arrayValue =
|
63
|
+
_arrayValue =
|
64
|
+
std::make_shared<jsi::Array>(_objectValue->asArray(runtime));
|
67
65
|
_objectValue = nullptr;
|
68
66
|
} else if (_objectValue->isHostObject(runtime)) {
|
69
67
|
_type = JsiWrapperValueType::HostObject;
|
@@ -74,7 +72,7 @@ public:
|
|
74
72
|
throw std::runtime_error("Could not store jsi::Value of provided type");
|
75
73
|
}
|
76
74
|
// Save in value holder as well so that we can return current
|
77
|
-
if(_valueHolder == nullptr) {
|
75
|
+
if (_valueHolder == nullptr) {
|
78
76
|
_valueHolder = std::make_shared<jsi::Object>(runtime);
|
79
77
|
}
|
80
78
|
_valueHolder->setProperty(runtime, "current", value);
|
@@ -82,57 +80,57 @@ public:
|
|
82
80
|
|
83
81
|
bool isUndefinedOrNull() {
|
84
82
|
return _type == JsiWrapperValueType::Undefined ||
|
85
|
-
|
83
|
+
_type == JsiWrapperValueType::Null;
|
86
84
|
}
|
87
|
-
|
85
|
+
|
88
86
|
bool getAsBool() {
|
89
87
|
assert(_type == JsiWrapperValueType::Bool);
|
90
88
|
return _boolValue;
|
91
89
|
}
|
92
|
-
|
90
|
+
|
93
91
|
double getAsNumber() {
|
94
92
|
assert(_type == JsiWrapperValueType::Number);
|
95
93
|
return _numberValue;
|
96
94
|
}
|
97
|
-
|
98
|
-
const std::string&
|
95
|
+
|
96
|
+
const std::string &getAsString() {
|
99
97
|
assert(_type == JsiWrapperValueType::String);
|
100
98
|
return _stringValue;
|
101
99
|
}
|
102
|
-
|
100
|
+
|
103
101
|
std::shared_ptr<jsi::Function> getAsFunction() {
|
104
102
|
assert(_type == JsiWrapperValueType::Function);
|
105
103
|
return _functionValue;
|
106
104
|
}
|
107
|
-
|
105
|
+
|
108
106
|
std::shared_ptr<jsi::Array> getAsArray() {
|
109
107
|
assert(_type == JsiWrapperValueType::Array);
|
110
108
|
return _arrayValue;
|
111
109
|
}
|
112
|
-
|
110
|
+
|
113
111
|
std::shared_ptr<jsi::Object> getAsObject() {
|
114
112
|
assert(_type == JsiWrapperValueType::Object);
|
115
113
|
return _objectValue;
|
116
114
|
}
|
117
|
-
|
115
|
+
|
118
116
|
std::shared_ptr<jsi::HostObject> getAsHostObject() {
|
119
117
|
assert(_type == JsiWrapperValueType::HostObject);
|
120
118
|
return _hostObjectValue;
|
121
119
|
}
|
122
|
-
|
120
|
+
|
123
121
|
JsiWrapperValueType getType() { return _type; }
|
124
122
|
|
125
123
|
private:
|
126
|
-
|
124
|
+
std::shared_ptr<jsi::Object> _valueHolder;
|
127
125
|
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
126
|
+
bool _boolValue;
|
127
|
+
double _numberValue;
|
128
|
+
std::string _stringValue;
|
129
|
+
std::shared_ptr<jsi::Object> _objectValue;
|
130
|
+
std::shared_ptr<jsi::Function> _functionValue;
|
131
|
+
std::shared_ptr<jsi::Array> _arrayValue;
|
132
|
+
std::shared_ptr<jsi::HostObject> _hostObjectValue;
|
135
133
|
|
136
|
-
|
134
|
+
JsiWrapperValueType _type;
|
137
135
|
};
|
138
|
-
}
|
136
|
+
} // namespace RNJsi
|
@@ -1,68 +1,65 @@
|
|
1
|
-
|
2
1
|
#pragma once
|
3
2
|
|
4
3
|
#include <array>
|
4
|
+
#include <memory>
|
5
5
|
|
6
6
|
#include <JsiHostObject.h>
|
7
|
-
#include <RNSkPlatformContext.h>
|
8
7
|
#include <RNSkClockValue.h>
|
8
|
+
#include <RNSkPlatformContext.h>
|
9
9
|
#include <jsi/jsi.h>
|
10
10
|
|
11
|
-
namespace RNSkia
|
12
|
-
|
13
|
-
using namespace facebook;
|
11
|
+
namespace RNSkia {
|
12
|
+
namespace jsi = facebook::jsi;
|
14
13
|
|
15
14
|
/**
|
16
15
|
Implements an animation that can be used to drive other values
|
17
16
|
*/
|
18
|
-
class RNSkAnimation : public RNSkClockValue
|
19
|
-
|
20
|
-
|
17
|
+
class RNSkAnimation : public RNSkClockValue {
|
18
|
+
|
21
19
|
public:
|
22
20
|
RNSkAnimation(std::shared_ptr<RNSkPlatformContext> platformContext,
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
size_t count) :
|
27
|
-
RNSkClockValue(platformContext, identifier, runtime, arguments, count) {
|
21
|
+
size_t identifier, jsi::Runtime &runtime,
|
22
|
+
const jsi::Value *arguments, size_t count)
|
23
|
+
: RNSkClockValue(platformContext, identifier, runtime, arguments, count) {
|
28
24
|
// Save the update function
|
29
|
-
_updateFunction = std::make_shared<jsi::Function>(
|
30
|
-
|
25
|
+
_updateFunction = std::make_shared<jsi::Function>(
|
26
|
+
arguments[0].asObject(runtime).asFunction(runtime));
|
27
|
+
|
31
28
|
// Set state to undefined initially.
|
32
29
|
_args[1] = jsi::Value::undefined();
|
33
30
|
}
|
34
|
-
|
31
|
+
|
35
32
|
JSI_HOST_FUNCTION(cancel) {
|
36
33
|
stopClock();
|
37
34
|
return jsi::Value::undefined();
|
38
35
|
}
|
39
|
-
|
36
|
+
|
40
37
|
JSI_EXPORT_FUNCTIONS(JSI_EXPORT_FUNC(RNSkAnimation, cancel))
|
41
38
|
|
42
|
-
|
43
39
|
protected:
|
44
|
-
|
45
40
|
void tick(jsi::Runtime &runtime, const jsi::Value &value) override {
|
46
41
|
// Set up arguments and call the update function
|
47
42
|
_args[0] = value.asNumber();
|
48
|
-
_args[1] = _updateFunction->call(
|
49
|
-
|
43
|
+
_args[1] = _updateFunction->call(
|
44
|
+
runtime, static_cast<const jsi::Value *>(_args.data()), _args.size());
|
45
|
+
|
50
46
|
// Get finished
|
51
|
-
auto finished =
|
52
|
-
|
47
|
+
auto finished =
|
48
|
+
_args[1].asObject(runtime).getProperty(runtime, "finished").getBool();
|
49
|
+
if (finished) {
|
53
50
|
stopClock();
|
54
51
|
}
|
55
|
-
|
52
|
+
|
56
53
|
// Get the next value
|
57
|
-
auto nextValue =
|
58
|
-
|
54
|
+
auto nextValue =
|
55
|
+
_args[1].asObject(runtime).getProperty(runtime, "current").asNumber();
|
56
|
+
|
59
57
|
// Update self
|
60
58
|
update(runtime, nextValue);
|
61
59
|
}
|
62
|
-
|
60
|
+
|
63
61
|
private:
|
64
|
-
|
65
62
|
std::shared_ptr<jsi::Function> _updateFunction;
|
66
63
|
std::array<jsi::Value, 2> _args;
|
67
64
|
};
|
68
|
-
}
|
65
|
+
} // namespace RNSkia
|
@@ -4,81 +4,70 @@
|
|
4
4
|
#include <mutex>
|
5
5
|
#include <utility>
|
6
6
|
|
7
|
-
namespace RNSkia
|
8
|
-
{
|
7
|
+
namespace RNSkia {
|
9
8
|
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
cv_.notify_all();
|
9
|
+
RNSkDispatchQueue::~RNSkDispatchQueue() {
|
10
|
+
// Signal to dispatch threads that it's time to wrap up
|
11
|
+
std::unique_lock<std::mutex> lock(lock_);
|
12
|
+
quit_ = true;
|
13
|
+
lock.unlock();
|
14
|
+
cv_.notify_all();
|
17
15
|
|
18
|
-
|
19
|
-
|
20
|
-
{
|
21
|
-
|
22
|
-
{
|
23
|
-
threads_[i].join();
|
24
|
-
}
|
16
|
+
// Wait for threads to finish before we exit
|
17
|
+
for (size_t i = 0; i < threads_.size(); i++) {
|
18
|
+
if (threads_[i].joinable()) {
|
19
|
+
threads_[i].join();
|
25
20
|
}
|
26
21
|
}
|
22
|
+
}
|
27
23
|
|
28
|
-
|
29
|
-
|
30
|
-
{
|
31
|
-
|
32
|
-
|
33
|
-
threads_[i] = std::thread(&RNSkDispatchQueue::dispatch_thread_handler, this);
|
34
|
-
}
|
24
|
+
RNSkDispatchQueue::RNSkDispatchQueue(std::string name, size_t thread_cnt)
|
25
|
+
: name_{std::move(name)}, threads_(thread_cnt) {
|
26
|
+
for (size_t i = 0; i < threads_.size(); i++) {
|
27
|
+
threads_[i] =
|
28
|
+
std::thread(&RNSkDispatchQueue::dispatch_thread_handler, this);
|
35
29
|
}
|
30
|
+
}
|
36
31
|
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
q_.push(op);
|
32
|
+
void RNSkDispatchQueue::dispatch(const fp_t &op) {
|
33
|
+
std::unique_lock<std::mutex> lock(lock_);
|
34
|
+
q_.push(op);
|
41
35
|
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
36
|
+
// Manual unlocking is done before notifying, to avoid waking up
|
37
|
+
// the waiting thread only to block again (see notify_one for details)
|
38
|
+
lock.unlock();
|
39
|
+
cv_.notify_one();
|
40
|
+
}
|
47
41
|
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
q_.push(std::move(op));
|
42
|
+
void RNSkDispatchQueue::dispatch(fp_t &&op) {
|
43
|
+
std::unique_lock<std::mutex> lock(lock_);
|
44
|
+
q_.push(std::move(op));
|
52
45
|
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
46
|
+
// Manual unlocking is done before notifying, to avoid waking up
|
47
|
+
// the waiting thread only to block again (see notify_one for details)
|
48
|
+
lock.unlock();
|
49
|
+
cv_.notify_one();
|
50
|
+
}
|
58
51
|
|
59
|
-
|
60
|
-
|
61
|
-
std::unique_lock<std::mutex> lock(lock_);
|
52
|
+
void RNSkDispatchQueue::dispatch_thread_handler(void) {
|
53
|
+
std::unique_lock<std::mutex> lock(lock_);
|
62
54
|
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
cv_.wait(lock, [this]
|
67
|
-
{ return (q_.size() || quit_); });
|
55
|
+
do {
|
56
|
+
// Wait until we have data or a quit signal
|
57
|
+
cv_.wait(lock, [this] { return (q_.size() || quit_); });
|
68
58
|
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
q_.pop();
|
59
|
+
// after wait, we own the lock
|
60
|
+
if (!quit_ && q_.size()) {
|
61
|
+
auto op = std::move(q_.front());
|
62
|
+
q_.pop();
|
74
63
|
|
75
|
-
|
76
|
-
|
64
|
+
// unlock now that we're done messing with the queue
|
65
|
+
lock.unlock();
|
77
66
|
|
78
|
-
|
67
|
+
op();
|
79
68
|
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
69
|
+
lock.lock();
|
70
|
+
}
|
71
|
+
} while (!quit_);
|
72
|
+
}
|
84
73
|
} // namespace RNSkia
|
@@ -1,3 +1,5 @@
|
|
1
|
+
#pragma once
|
2
|
+
|
1
3
|
#include <condition_variable>
|
2
4
|
#include <cstdint>
|
3
5
|
#include <cstdio>
|
@@ -15,7 +17,7 @@ class RNSkDispatchQueue {
|
|
15
17
|
typedef std::function<void(void)> fp_t;
|
16
18
|
|
17
19
|
public:
|
18
|
-
RNSkDispatchQueue(std::string name, size_t thread_cnt = 1);
|
20
|
+
explicit RNSkDispatchQueue(std::string name, size_t thread_cnt = 1);
|
19
21
|
|
20
22
|
~RNSkDispatchQueue();
|
21
23
|
|
@@ -13,11 +13,9 @@
|
|
13
13
|
|
14
14
|
namespace RNSkia {
|
15
15
|
|
16
|
-
|
17
|
-
using namespace RNJsi;
|
18
|
-
using namespace std::chrono;
|
16
|
+
namespace jsi = facebook::jsi;
|
19
17
|
|
20
|
-
class RNSkInfoObject : public JsiHostObject {
|
18
|
+
class RNSkInfoObject : public RNJsi::JsiHostObject {
|
21
19
|
public:
|
22
20
|
JSI_PROPERTY_GET(width) { return _width; }
|
23
21
|
JSI_PROPERTY_GET(height) { return _height; }
|
@@ -34,9 +32,10 @@ public:
|
|
34
32
|
touchObj.setProperty(runtime, "x", t.x);
|
35
33
|
touchObj.setProperty(runtime, "y", t.y);
|
36
34
|
touchObj.setProperty(runtime, "force", t.force);
|
37
|
-
touchObj.setProperty(runtime, "type", (
|
38
|
-
touchObj.setProperty(runtime, "timestamp",
|
39
|
-
|
35
|
+
touchObj.setProperty(runtime, "type", static_cast<double>(t.type));
|
36
|
+
touchObj.setProperty(runtime, "timestamp",
|
37
|
+
static_cast<double>(t.timestamp / 1000.0));
|
38
|
+
touchObj.setProperty(runtime, "id", static_cast<double>(t.id));
|
40
39
|
touches.setValueAtIndex(runtime, n, touchObj);
|
41
40
|
}
|
42
41
|
ops.setValueAtIndex(runtime, i, touches);
|
@@ -67,13 +66,14 @@ public:
|
|
67
66
|
|
68
67
|
void endDrawOperation() { _touchesCache.clear(); }
|
69
68
|
|
70
|
-
void updateTouches(std::vector<RNSkTouchInfo
|
69
|
+
void updateTouches(std::vector<RNSkTouchInfo> &touches) {
|
71
70
|
std::lock_guard<std::mutex> lock(_mutex);
|
72
71
|
// Add timestamp
|
73
|
-
auto ms = std::chrono::duration_cast<milliseconds>(
|
74
|
-
|
75
|
-
|
76
|
-
|
72
|
+
auto ms = std::chrono::duration_cast<std::chrono::milliseconds>(
|
73
|
+
std::chrono::system_clock::now().time_since_epoch())
|
74
|
+
.count();
|
75
|
+
|
76
|
+
for (size_t i = 0; i < touches.size(); i++) {
|
77
77
|
touches.at(i).timestamp = ms;
|
78
78
|
}
|
79
79
|
_currentTouches.push_back(std::move(touches));
|