@shopify/react-native-skia 0.1.155 → 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/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/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/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
package/cpp/api/JsiSkRSXform.h
CHANGED
@@ -16,90 +16,87 @@
|
|
16
16
|
|
17
17
|
namespace RNSkia {
|
18
18
|
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
// Return the newly constructed object
|
100
|
-
return jsi::Object::createFromHostObject(
|
101
|
-
runtime, std::make_shared<JsiSkRSXform>(std::move(context), std::move(rsxform)));
|
102
|
-
};
|
103
|
-
}
|
19
|
+
namespace jsi = facebook::jsi;
|
20
|
+
|
21
|
+
class JsiSkRSXform : public JsiSkWrappingSharedPtrHostObject<SkRSXform> {
|
22
|
+
public:
|
23
|
+
JsiSkRSXform(std::shared_ptr<RNSkPlatformContext> context,
|
24
|
+
const SkRSXform &rsxform)
|
25
|
+
: JsiSkWrappingSharedPtrHostObject<SkRSXform>(
|
26
|
+
std::move(context), std::make_shared<SkRSXform>(rsxform)) {}
|
27
|
+
|
28
|
+
// TODO: declare in JsiSkWrappingSkPtrHostObject via extra template parameter?
|
29
|
+
|
30
|
+
JSI_PROPERTY_GET(__typename__) {
|
31
|
+
return jsi::String::createFromUtf8(runtime, "RSXform");
|
32
|
+
}
|
33
|
+
|
34
|
+
JSI_PROPERTY_GET(scos) {
|
35
|
+
return jsi::Value(SkScalarToDouble(getObject()->fSCos));
|
36
|
+
}
|
37
|
+
JSI_PROPERTY_GET(ssin) {
|
38
|
+
return jsi::Value(SkScalarToDouble(getObject()->fSSin));
|
39
|
+
}
|
40
|
+
JSI_PROPERTY_GET(tx) {
|
41
|
+
return jsi::Value(SkScalarToDouble(getObject()->fTx));
|
42
|
+
}
|
43
|
+
JSI_PROPERTY_GET(ty) {
|
44
|
+
return jsi::Value(SkScalarToDouble(getObject()->fTy));
|
45
|
+
}
|
46
|
+
|
47
|
+
JSI_EXPORT_PROPERTY_GETTERS(JSI_EXPORT_PROP_GET(JsiSkRSXform, __typename__),
|
48
|
+
JSI_EXPORT_PROP_GET(JsiSkRSXform, scos),
|
49
|
+
JSI_EXPORT_PROP_GET(JsiSkRSXform, ssin),
|
50
|
+
JSI_EXPORT_PROP_GET(JsiSkRSXform, tx),
|
51
|
+
JSI_EXPORT_PROP_GET(JsiSkRSXform, ty), )
|
52
|
+
|
53
|
+
/**
|
54
|
+
Returns the underlying object from a host object of this type
|
55
|
+
*/
|
56
|
+
static std::shared_ptr<SkRSXform> fromValue(jsi::Runtime &runtime,
|
57
|
+
const jsi::Value &obj) {
|
58
|
+
const auto &object = obj.asObject(runtime);
|
59
|
+
if (object.isHostObject(runtime)) {
|
60
|
+
return object.asHostObject<JsiSkRSXform>(runtime)->getObject();
|
61
|
+
} else {
|
62
|
+
auto scos =
|
63
|
+
object.getArray(runtime).getValueAtIndex(runtime, 0).asNumber();
|
64
|
+
auto ssin =
|
65
|
+
object.getArray(runtime).getValueAtIndex(runtime, 1).asNumber();
|
66
|
+
auto tx = object.getArray(runtime).getValueAtIndex(runtime, 2).asNumber();
|
67
|
+
auto ty = object.getArray(runtime).getValueAtIndex(runtime, 3).asNumber();
|
68
|
+
return std::make_shared<SkRSXform>(SkRSXform::Make(scos, ssin, tx, ty));
|
69
|
+
}
|
70
|
+
}
|
71
|
+
|
72
|
+
/**
|
73
|
+
Returns the jsi object from a host object of this type
|
74
|
+
*/
|
75
|
+
static jsi::Value toValue(jsi::Runtime &runtime,
|
76
|
+
std::shared_ptr<RNSkPlatformContext> context,
|
77
|
+
const SkRSXform &rsxform) {
|
78
|
+
return jsi::Object::createFromHostObject(
|
79
|
+
runtime, std::make_shared<JsiSkRSXform>(std::move(context), rsxform));
|
80
|
+
}
|
81
|
+
|
82
|
+
/**
|
83
|
+
* Creates the function for construction a new instance of the SkRSXform
|
84
|
+
* wrapper
|
85
|
+
* @param context platform context
|
86
|
+
* @return A function for creating a new host object wrapper for the SkRSXform
|
87
|
+
* class
|
88
|
+
*/
|
89
|
+
static const jsi::HostFunctionType
|
90
|
+
createCtor(std::shared_ptr<RNSkPlatformContext> context) {
|
91
|
+
return JSI_HOST_FUNCTION_LAMBDA {
|
92
|
+
auto rsxform =
|
93
|
+
SkRSXform::Make(arguments[0].asNumber(), arguments[1].asNumber(),
|
94
|
+
arguments[2].asNumber(), arguments[3].asNumber());
|
95
|
+
// Return the newly constructed object
|
96
|
+
return jsi::Object::createFromHostObject(
|
97
|
+
runtime, std::make_shared<JsiSkRSXform>(std::move(context),
|
98
|
+
std::move(rsxform)));
|
104
99
|
};
|
100
|
+
}
|
101
|
+
};
|
105
102
|
} // namespace RNSkia
|
package/cpp/api/JsiSkRect.h
CHANGED
@@ -16,7 +16,7 @@
|
|
16
16
|
|
17
17
|
namespace RNSkia {
|
18
18
|
|
19
|
-
|
19
|
+
namespace jsi = facebook::jsi;
|
20
20
|
|
21
21
|
class JsiSkRect : public JsiSkWrappingSharedPtrHostObject<SkRect> {
|
22
22
|
public:
|
@@ -58,18 +58,16 @@ public:
|
|
58
58
|
*/
|
59
59
|
JsiSkRect(std::shared_ptr<RNSkPlatformContext> context, const SkRect &rect)
|
60
60
|
: JsiSkWrappingSharedPtrHostObject<SkRect>(
|
61
|
-
std::move(context), std::make_shared<SkRect>(rect)){}
|
61
|
+
std::move(context), std::make_shared<SkRect>(rect)) {}
|
62
62
|
|
63
63
|
/**
|
64
64
|
Returns the underlying object from a host object of this type
|
65
65
|
*/
|
66
66
|
static std::shared_ptr<SkRect> fromValue(jsi::Runtime &runtime,
|
67
67
|
const jsi::Value &obj) {
|
68
|
-
const auto&
|
68
|
+
const auto &object = obj.asObject(runtime);
|
69
69
|
if (object.isHostObject(runtime)) {
|
70
|
-
return object
|
71
|
-
.asHostObject<JsiSkRect>(runtime)
|
72
|
-
->getObject();
|
70
|
+
return object.asHostObject<JsiSkRect>(runtime)->getObject();
|
73
71
|
} else {
|
74
72
|
auto x = object.getProperty(runtime, "x").asNumber();
|
75
73
|
auto y = object.getProperty(runtime, "y").asNumber();
|
@@ -90,9 +88,10 @@ public:
|
|
90
88
|
}
|
91
89
|
static jsi::Value toValue(jsi::Runtime &runtime,
|
92
90
|
std::shared_ptr<RNSkPlatformContext> context,
|
93
|
-
SkRect&&
|
91
|
+
SkRect &&rect) {
|
94
92
|
return jsi::Object::createFromHostObject(
|
95
|
-
runtime,
|
93
|
+
runtime,
|
94
|
+
std::make_shared<JsiSkRect>(std::move(context), std::move(rect)));
|
96
95
|
}
|
97
96
|
|
98
97
|
/**
|
@@ -112,7 +111,8 @@ public:
|
|
112
111
|
|
113
112
|
// Return the newly constructed object
|
114
113
|
return jsi::Object::createFromHostObject(
|
115
|
-
runtime,
|
114
|
+
runtime,
|
115
|
+
std::make_shared<JsiSkRect>(std::move(context), std::move(rect)));
|
116
116
|
};
|
117
117
|
}
|
118
118
|
};
|
@@ -6,8 +6,8 @@
|
|
6
6
|
#include <vector>
|
7
7
|
|
8
8
|
#include <JsiSkHostObjects.h>
|
9
|
-
#include <JsiSkShader.h>
|
10
9
|
#include <JsiSkMatrix.h>
|
10
|
+
#include <JsiSkShader.h>
|
11
11
|
|
12
12
|
#include <jsi/jsi.h>
|
13
13
|
|
@@ -18,205 +18,201 @@
|
|
18
18
|
|
19
19
|
#pragma clang diagnostic pop
|
20
20
|
|
21
|
-
namespace RNSkia
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
21
|
+
namespace RNSkia {
|
22
|
+
|
23
|
+
namespace jsi = facebook::jsi;
|
24
|
+
|
25
|
+
struct RuntimeEffectUniform {
|
26
|
+
int columns;
|
27
|
+
int rows;
|
28
|
+
int slot; // the index into the uniforms array that this uniform begins.
|
29
|
+
bool isInteger;
|
30
|
+
};
|
31
|
+
|
32
|
+
class JsiSkRuntimeEffect
|
33
|
+
: public JsiSkWrappingSkPtrHostObject<SkRuntimeEffect> {
|
34
|
+
public:
|
35
|
+
static sk_sp<SkRuntimeEffect> fromValue(jsi::Runtime &runtime,
|
36
|
+
const jsi::Value &obj) {
|
37
|
+
const auto &object = obj.asObject(runtime);
|
38
|
+
return object.asHostObject<JsiSkRuntimeEffect>(runtime)->getObject();
|
39
|
+
}
|
40
|
+
|
41
|
+
JSI_HOST_FUNCTION(makeShader) {
|
42
|
+
auto uniforms = castUniforms(runtime, arguments[0]);
|
43
|
+
|
44
|
+
auto matrix =
|
45
|
+
count >= 2 && !arguments[1].isUndefined() && !arguments[1].isNull()
|
46
|
+
? JsiSkMatrix::fromValue(runtime, arguments[1]).get()
|
47
|
+
: nullptr;
|
48
|
+
|
49
|
+
// Create and return shader as host object
|
50
|
+
auto shader =
|
51
|
+
getObject()->makeShader(std::move(uniforms), nullptr, 0, matrix);
|
52
|
+
|
53
|
+
return jsi::Object::createFromHostObject(
|
54
|
+
runtime,
|
55
|
+
std::make_shared<JsiSkShader>(getContext(), std::move(shader)));
|
56
|
+
}
|
57
|
+
|
58
|
+
JSI_HOST_FUNCTION(makeShaderWithChildren) {
|
59
|
+
auto uniforms = castUniforms(runtime, arguments[0]);
|
60
|
+
|
61
|
+
// Children
|
62
|
+
std::vector<sk_sp<SkShader>> children;
|
63
|
+
auto jsiChildren = arguments[1].asObject(runtime).asArray(runtime);
|
64
|
+
auto jsiChildCount = jsiChildren.size(runtime);
|
65
|
+
children.reserve(jsiChildCount);
|
66
|
+
for (int i = 0; i < jsiChildCount; i++) {
|
67
|
+
auto shader = jsiChildren.getValueAtIndex(runtime, i)
|
68
|
+
.asObject(runtime)
|
69
|
+
.asHostObject<JsiSkShader>(runtime)
|
70
|
+
->getObject();
|
71
|
+
children.push_back(shader);
|
42
72
|
}
|
43
73
|
|
44
|
-
|
45
|
-
|
46
|
-
|
74
|
+
auto matrix =
|
75
|
+
count >= 3 && !arguments[2].isUndefined() && !arguments[2].isNull()
|
76
|
+
? JsiSkMatrix::fromValue(runtime, arguments[2]).get()
|
77
|
+
: nullptr;
|
47
78
|
|
48
|
-
|
79
|
+
// Create and return shader as host object
|
80
|
+
auto shader = getObject()->makeShader(std::move(uniforms), children.data(),
|
81
|
+
children.size(), matrix);
|
49
82
|
|
50
|
-
|
51
|
-
|
83
|
+
return jsi::Object::createFromHostObject(
|
84
|
+
runtime,
|
85
|
+
std::make_shared<JsiSkShader>(getContext(), std::move(shader)));
|
86
|
+
}
|
52
87
|
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
JSI_HOST_FUNCTION(makeShaderWithChildren)
|
58
|
-
{
|
59
|
-
auto uniforms = castUniforms(runtime, arguments[0]);
|
60
|
-
|
61
|
-
// Children
|
62
|
-
std::vector<sk_sp<SkShader>> children;
|
63
|
-
auto jsiChildren = arguments[1].asObject(runtime).asArray(runtime);
|
64
|
-
auto jsiChildCount = jsiChildren.size(runtime);
|
65
|
-
children.reserve(jsiChildCount);
|
66
|
-
for (int i = 0; i < jsiChildCount; i++)
|
67
|
-
{
|
68
|
-
auto shader = jsiChildren.getValueAtIndex(runtime, i)
|
69
|
-
.asObject(runtime)
|
70
|
-
.asHostObject<JsiSkShader>(runtime)
|
71
|
-
->getObject();
|
72
|
-
children.push_back(shader);
|
73
|
-
}
|
88
|
+
JSI_HOST_FUNCTION(getUniformCount) {
|
89
|
+
return static_cast<int>(getObject()->uniforms().size());
|
90
|
+
}
|
74
91
|
|
75
|
-
|
92
|
+
JSI_HOST_FUNCTION(getUniformFloatCount) {
|
93
|
+
return static_cast<int>(getObject()->uniformSize() / sizeof(float));
|
94
|
+
}
|
76
95
|
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
return jsi::Object::createFromHostObject(
|
82
|
-
runtime, std::make_shared<JsiSkShader>(getContext(), std::move(shader)));
|
96
|
+
JSI_HOST_FUNCTION(getUniformName) {
|
97
|
+
auto i = static_cast<int>(arguments[0].asNumber());
|
98
|
+
if (i < 0 || i >= getObject()->uniforms().size()) {
|
99
|
+
throw jsi::JSError(runtime, "invalid uniform index");
|
83
100
|
}
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
101
|
+
auto it = getObject()->uniforms().begin() + i;
|
102
|
+
return jsi::String::createFromAscii(runtime, it->name.c_str());
|
103
|
+
}
|
104
|
+
|
105
|
+
JSI_HOST_FUNCTION(getUniform) {
|
106
|
+
auto i = static_cast<int>(arguments[0].asNumber());
|
107
|
+
if (i < 0 || i >= getObject()->uniforms().size()) {
|
108
|
+
throw jsi::JSError(runtime, "invalid uniform index");
|
88
109
|
}
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
110
|
+
auto it = getObject()->uniforms().begin() + i;
|
111
|
+
auto result = jsi::Object(runtime);
|
112
|
+
RuntimeEffectUniform su = fromUniform(*it);
|
113
|
+
result.setProperty(runtime, "columns", su.columns);
|
114
|
+
result.setProperty(runtime, "rows", su.rows);
|
115
|
+
result.setProperty(runtime, "slot", su.slot);
|
116
|
+
result.setProperty(runtime, "isInteger", su.isInteger);
|
117
|
+
return result;
|
118
|
+
}
|
119
|
+
|
120
|
+
JSI_EXPORT_FUNCTIONS(JSI_EXPORT_FUNC(JsiSkRuntimeEffect, makeShader),
|
121
|
+
JSI_EXPORT_FUNC(JsiSkRuntimeEffect,
|
122
|
+
makeShaderWithChildren),
|
123
|
+
JSI_EXPORT_FUNC(JsiSkRuntimeEffect, getUniformCount),
|
124
|
+
JSI_EXPORT_FUNC(JsiSkRuntimeEffect,
|
125
|
+
getUniformFloatCount),
|
126
|
+
JSI_EXPORT_FUNC(JsiSkRuntimeEffect, getUniformName),
|
127
|
+
JSI_EXPORT_FUNC(JsiSkRuntimeEffect, getUniform))
|
128
|
+
|
129
|
+
JsiSkRuntimeEffect(std::shared_ptr<RNSkPlatformContext> context,
|
130
|
+
sk_sp<SkRuntimeEffect> rt)
|
131
|
+
: JsiSkWrappingSkPtrHostObject<SkRuntimeEffect>(std::move(context),
|
132
|
+
std::move(rt)) {}
|
133
|
+
|
134
|
+
private:
|
135
|
+
sk_sp<SkData> castUniforms(jsi::Runtime &runtime, const jsi::Value &value) {
|
136
|
+
auto jsiUniforms = value.asObject(runtime).asArray(runtime);
|
137
|
+
auto jsiUniformsSize = jsiUniforms.size(runtime);
|
138
|
+
|
139
|
+
// verify size of input uniforms
|
140
|
+
if (jsiUniformsSize * sizeof(float) != getObject()->uniformSize()) {
|
141
|
+
std::string msg =
|
142
|
+
"Uniforms size differs from effect's uniform size. Received " +
|
143
|
+
std::to_string(jsiUniformsSize) + " expected " +
|
144
|
+
std::to_string(getObject()->uniformSize() / sizeof(float));
|
145
|
+
throw jsi::JSError(runtime, msg.c_str());
|
93
146
|
}
|
94
147
|
|
95
|
-
|
96
|
-
{
|
97
|
-
auto i = static_cast<int>(arguments[0].asNumber());
|
98
|
-
if (i < 0 || i >= getObject()->uniforms().size()) {
|
99
|
-
throw jsi::JSError(runtime, "invalid uniform index");
|
100
|
-
}
|
101
|
-
auto it = getObject()->uniforms().begin() + i;
|
102
|
-
return jsi::String::createFromAscii(runtime, it->name.c_str());
|
103
|
-
}
|
148
|
+
auto uniforms = SkData::MakeUninitialized(getObject()->uniformSize());
|
104
149
|
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
if (i < 0 || i >= getObject()->uniforms().size()) {
|
109
|
-
throw jsi::JSError(runtime, "invalid uniform index");
|
110
|
-
}
|
150
|
+
// Convert to skia uniforms
|
151
|
+
const auto &u = getObject()->uniforms();
|
152
|
+
for (std::size_t i = 0; i < u.size(); i++) {
|
111
153
|
auto it = getObject()->uniforms().begin() + i;
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
JSI_EXPORT_FUNCTIONS(JSI_EXPORT_FUNC(JsiSkRuntimeEffect, makeShader),
|
122
|
-
JSI_EXPORT_FUNC(JsiSkRuntimeEffect,
|
123
|
-
makeShaderWithChildren),
|
124
|
-
JSI_EXPORT_FUNC(JsiSkRuntimeEffect, getUniformCount),
|
125
|
-
JSI_EXPORT_FUNC(JsiSkRuntimeEffect,
|
126
|
-
getUniformFloatCount),
|
127
|
-
JSI_EXPORT_FUNC(JsiSkRuntimeEffect, getUniformName),
|
128
|
-
JSI_EXPORT_FUNC(JsiSkRuntimeEffect, getUniform))
|
129
|
-
|
130
|
-
JsiSkRuntimeEffect(std::shared_ptr<RNSkPlatformContext> context,
|
131
|
-
sk_sp<SkRuntimeEffect> rt)
|
132
|
-
: JsiSkWrappingSkPtrHostObject<SkRuntimeEffect>(std::move(context), std::move(rt)){}
|
133
|
-
|
134
|
-
private:
|
135
|
-
sk_sp<SkData> castUniforms(jsi::Runtime &runtime, const jsi::Value &value)
|
136
|
-
{
|
137
|
-
auto jsiUniforms = value.asObject(runtime).asArray(runtime);
|
138
|
-
auto jsiUniformsSize = jsiUniforms.size(runtime);
|
139
|
-
|
140
|
-
// verify size of input uniforms
|
141
|
-
if (jsiUniformsSize * sizeof(float) != getObject()->uniformSize())
|
142
|
-
{
|
143
|
-
std::string msg = "Uniforms size differs from effect's uniform size. Received " +
|
144
|
-
std::to_string(jsiUniformsSize) +
|
145
|
-
" expected " +
|
146
|
-
std::to_string(getObject()->uniformSize() / sizeof(float));
|
147
|
-
throw jsi::JSError(runtime, msg.c_str());
|
154
|
+
RuntimeEffectUniform reu = fromUniform(*it);
|
155
|
+
for (std::size_t j = 0; j < reu.columns * reu.rows; ++j) {
|
156
|
+
const std::size_t offset = reu.slot + j;
|
157
|
+
float fValue = jsiUniforms.getValueAtIndex(runtime, offset).asNumber();
|
158
|
+
int iValue = static_cast<int>(fValue);
|
159
|
+
auto value = reu.isInteger ? iValue : fValue;
|
160
|
+
memcpy(SkTAddOffset<void>(uniforms->writable_data(),
|
161
|
+
offset * sizeof(value)),
|
162
|
+
&value, sizeof(value));
|
148
163
|
}
|
149
|
-
|
150
|
-
auto uniforms = SkData::MakeUninitialized(getObject()->uniformSize());
|
151
|
-
|
152
|
-
// Convert to skia uniforms
|
153
|
-
const auto& u = getObject()->uniforms();
|
154
|
-
for (std::size_t i = 0; i < u.size(); i++)
|
155
|
-
{
|
156
|
-
auto it = getObject()->uniforms().begin() + i;
|
157
|
-
RuntimeEffectUniform reu = fromUniform(*it);
|
158
|
-
for (std::size_t j = 0; j < reu.columns * reu.rows; ++j) {
|
159
|
-
const std::size_t offset = reu.slot + j;
|
160
|
-
float fValue = jsiUniforms.getValueAtIndex(runtime, offset).asNumber();
|
161
|
-
int iValue = static_cast<int>(fValue);
|
162
|
-
auto value = reu.isInteger ? iValue : fValue;
|
163
|
-
memcpy(SkTAddOffset<void>(uniforms->writable_data(), offset * sizeof(value)), &value, sizeof(value));
|
164
|
-
}
|
165
|
-
}
|
166
|
-
return uniforms;
|
167
164
|
}
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
}
|
217
|
-
su.slot = (int)(u.offset / sizeof(float));
|
218
|
-
return su;
|
165
|
+
return uniforms;
|
166
|
+
}
|
167
|
+
|
168
|
+
RuntimeEffectUniform fromUniform(const SkRuntimeEffect::Uniform &u) {
|
169
|
+
RuntimeEffectUniform su;
|
170
|
+
su.rows = u.count; // arrayLength
|
171
|
+
su.columns = 1;
|
172
|
+
su.isInteger = false;
|
173
|
+
using Type = SkRuntimeEffect::Uniform::Type;
|
174
|
+
switch (u.type) {
|
175
|
+
case Type::kFloat:
|
176
|
+
break;
|
177
|
+
case Type::kFloat2:
|
178
|
+
su.columns = 2;
|
179
|
+
break;
|
180
|
+
case Type::kFloat3:
|
181
|
+
su.columns = 3;
|
182
|
+
break;
|
183
|
+
case Type::kFloat4:
|
184
|
+
su.columns = 4;
|
185
|
+
break;
|
186
|
+
case Type::kFloat2x2:
|
187
|
+
su.columns = 2;
|
188
|
+
su.rows *= 2;
|
189
|
+
break;
|
190
|
+
case Type::kFloat3x3:
|
191
|
+
su.columns = 3;
|
192
|
+
su.rows *= 3;
|
193
|
+
break;
|
194
|
+
case Type::kFloat4x4:
|
195
|
+
su.columns = 4;
|
196
|
+
su.rows *= 4;
|
197
|
+
break;
|
198
|
+
case Type::kInt:
|
199
|
+
su.isInteger = true;
|
200
|
+
break;
|
201
|
+
case Type::kInt2:
|
202
|
+
su.columns = 2;
|
203
|
+
su.isInteger = true;
|
204
|
+
break;
|
205
|
+
case Type::kInt3:
|
206
|
+
su.columns = 3;
|
207
|
+
su.isInteger = true;
|
208
|
+
break;
|
209
|
+
case Type::kInt4:
|
210
|
+
su.columns = 4;
|
211
|
+
su.isInteger = true;
|
212
|
+
break;
|
219
213
|
}
|
220
|
-
|
221
|
-
|
214
|
+
su.slot = static_cast<int>(u.offset / sizeof(float));
|
215
|
+
return su;
|
216
|
+
}
|
217
|
+
};
|
222
218
|
} // namespace RNSkia
|