@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
@@ -6,12 +6,12 @@
|
|
6
6
|
|
7
7
|
#include <jsi/jsi.h>
|
8
8
|
|
9
|
-
#include "JsiSkRuntimeEffect.h"
|
10
9
|
#include "JsiSkHostObjects.h"
|
10
|
+
#include "JsiSkRuntimeEffect.h"
|
11
11
|
|
12
12
|
namespace RNSkia {
|
13
13
|
|
14
|
-
|
14
|
+
namespace jsi = facebook::jsi;
|
15
15
|
|
16
16
|
class JsiSkRuntimeEffectFactory : public JsiSkHostObject {
|
17
17
|
public:
|
@@ -21,21 +21,20 @@ public:
|
|
21
21
|
auto effect = result.effect;
|
22
22
|
auto errorText = result.errorText;
|
23
23
|
if (!effect) {
|
24
|
-
throw jsi::JSError(
|
25
|
-
|
26
|
-
|
27
|
-
.c_str());
|
24
|
+
throw jsi::JSError(runtime, std::string("Error in sksl:\n" +
|
25
|
+
std::string(errorText.c_str()))
|
26
|
+
.c_str());
|
28
27
|
return jsi::Value::null();
|
29
28
|
}
|
30
29
|
return jsi::Object::createFromHostObject(
|
31
|
-
runtime,
|
30
|
+
runtime,
|
31
|
+
std::make_shared<JsiSkRuntimeEffect>(getContext(), std::move(effect)));
|
32
32
|
}
|
33
33
|
|
34
|
-
JSI_EXPORT_FUNCTIONS(
|
35
|
-
JSI_EXPORT_FUNC(JsiSkRuntimeEffectFactory, Make)
|
36
|
-
)
|
34
|
+
JSI_EXPORT_FUNCTIONS(JSI_EXPORT_FUNC(JsiSkRuntimeEffectFactory, Make))
|
37
35
|
|
38
|
-
JsiSkRuntimeEffectFactory(
|
36
|
+
explicit JsiSkRuntimeEffectFactory(
|
37
|
+
std::shared_ptr<RNSkPlatformContext> context)
|
39
38
|
: JsiSkHostObject(std::move(context)) {}
|
40
39
|
};
|
41
40
|
|
@@ -2,6 +2,7 @@
|
|
2
2
|
|
3
3
|
#include <memory>
|
4
4
|
#include <utility>
|
5
|
+
#include <vector>
|
5
6
|
|
6
7
|
#include <jsi/jsi.h>
|
7
8
|
|
@@ -17,72 +18,74 @@
|
|
17
18
|
|
18
19
|
namespace RNSkia {
|
19
20
|
|
20
|
-
|
21
|
+
namespace jsi = facebook::jsi;
|
21
22
|
|
22
|
-
|
23
|
-
public
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
23
|
+
class JsiSkRuntimeShaderBuilder
|
24
|
+
: public JsiSkWrappingSharedPtrHostObject<SkRuntimeShaderBuilder> {
|
25
|
+
public:
|
26
|
+
/**
|
27
|
+
Constructor
|
28
|
+
*/
|
29
|
+
JsiSkRuntimeShaderBuilder(std::shared_ptr<RNSkPlatformContext> context,
|
30
|
+
const SkRuntimeShaderBuilder &rt)
|
31
|
+
: JsiSkWrappingSharedPtrHostObject<SkRuntimeShaderBuilder>(
|
32
|
+
std::move(context), std::make_shared<SkRuntimeShaderBuilder>(rt)) {}
|
31
33
|
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
34
|
+
JSI_HOST_FUNCTION(setUniform) {
|
35
|
+
auto name = arguments[0].asString(runtime).utf8(runtime);
|
36
|
+
auto jsiValue = arguments[1].asObject(runtime).asArray(runtime);
|
37
|
+
auto size = jsiValue.size(runtime);
|
38
|
+
std::vector<SkScalar> value;
|
39
|
+
value.reserve(size);
|
40
|
+
for (int i = 0; i < size; i++) {
|
41
|
+
auto e = jsiValue.getValueAtIndex(runtime, i).asNumber();
|
42
|
+
value.push_back(e);
|
43
|
+
}
|
44
|
+
getObject()
|
45
|
+
->uniform(name.c_str())
|
46
|
+
.set(value.data(), static_cast<int>(size));
|
47
|
+
return jsi::Value::undefined();
|
48
|
+
}
|
45
49
|
|
46
|
-
|
47
|
-
JSI_EXPORT_FUNC(JsiSkRuntimeShaderBuilder, setUniform)
|
48
|
-
)
|
50
|
+
JSI_EXPORT_FUNCTIONS(JSI_EXPORT_FUNC(JsiSkRuntimeShaderBuilder, setUniform))
|
49
51
|
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
}
|
52
|
+
/**
|
53
|
+
Returns the underlying object from a host object of this type
|
54
|
+
*/
|
55
|
+
static std::shared_ptr<SkRuntimeShaderBuilder>
|
56
|
+
fromValue(jsi::Runtime &runtime, const jsi::Value &obj) {
|
57
|
+
const auto &object = obj.asObject(runtime);
|
58
|
+
return object.asHostObject<JsiSkRuntimeShaderBuilder>(runtime)->getObject();
|
59
|
+
}
|
59
60
|
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
61
|
+
/**
|
62
|
+
Returns the jsi object from a host object of this type
|
63
|
+
*/
|
64
|
+
static jsi::Value toValue(jsi::Runtime &runtime,
|
65
|
+
std::shared_ptr<RNSkPlatformContext> context,
|
66
|
+
const SkRuntimeShaderBuilder &rt) {
|
67
|
+
return jsi::Object::createFromHostObject(
|
68
|
+
runtime,
|
69
|
+
std::make_shared<JsiSkRuntimeShaderBuilder>(std::move(context), rt));
|
70
|
+
}
|
69
71
|
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
}
|
72
|
+
/**
|
73
|
+
* Creates the function for construction a new instance of the SkRect
|
74
|
+
* wrapper
|
75
|
+
* @param context platform context
|
76
|
+
* @return A function for creating a new host object wrapper for the SkRect
|
77
|
+
* class
|
78
|
+
*/
|
79
|
+
static const jsi::HostFunctionType
|
80
|
+
createCtor(std::shared_ptr<RNSkPlatformContext> context) {
|
81
|
+
return JSI_HOST_FUNCTION_LAMBDA {
|
82
|
+
auto rt = JsiSkRuntimeEffect::fromValue(runtime, arguments[0]);
|
83
|
+
auto rtb = SkRuntimeShaderBuilder(rt);
|
84
|
+
// Return the newly constructed object
|
85
|
+
return jsi::Object::createFromHostObject(
|
86
|
+
runtime, std::make_shared<JsiSkRuntimeShaderBuilder>(
|
87
|
+
std::move(context), std::move(rtb)));
|
87
88
|
};
|
89
|
+
}
|
90
|
+
};
|
88
91
|
} // namespace RNSkia
|
package/cpp/api/JsiSkSVG.h
CHANGED
@@ -16,12 +16,13 @@
|
|
16
16
|
|
17
17
|
namespace RNSkia {
|
18
18
|
|
19
|
-
|
19
|
+
namespace jsi = facebook::jsi;
|
20
20
|
|
21
21
|
class JsiSkSVG : public JsiSkWrappingSkPtrHostObject<SkSVGDOM> {
|
22
22
|
public:
|
23
23
|
JsiSkSVG(std::shared_ptr<RNSkPlatformContext> context, sk_sp<SkSVGDOM> svgdom)
|
24
|
-
: JsiSkWrappingSkPtrHostObject<SkSVGDOM>(std::move(context),
|
24
|
+
: JsiSkWrappingSkPtrHostObject<SkSVGDOM>(std::move(context),
|
25
|
+
std::move(svgdom)) {}
|
25
26
|
|
26
27
|
JSI_PROPERTY_GET(__typename__) {
|
27
28
|
return jsi::String::createFromUtf8(runtime, "SVG");
|
@@ -34,9 +35,7 @@ public:
|
|
34
35
|
*/
|
35
36
|
static sk_sp<SkSVGDOM> fromValue(jsi::Runtime &runtime,
|
36
37
|
const jsi::Value &obj) {
|
37
|
-
return obj.asObject(runtime)
|
38
|
-
.asHostObject<JsiSkSVG>(runtime)
|
39
|
-
->getObject();
|
38
|
+
return obj.asObject(runtime).asHostObject<JsiSkSVG>(runtime)->getObject();
|
40
39
|
}
|
41
40
|
};
|
42
41
|
|
@@ -5,10 +5,10 @@
|
|
5
5
|
|
6
6
|
#include <jsi/jsi.h>
|
7
7
|
|
8
|
-
#include "JsiSkTypeface.h"
|
9
|
-
#include "JsiSkHostObjects.h"
|
10
8
|
#include "JsiSkData.h"
|
9
|
+
#include "JsiSkHostObjects.h"
|
11
10
|
#include "JsiSkSVG.h"
|
11
|
+
#include "JsiSkTypeface.h"
|
12
12
|
|
13
13
|
#pragma clang diagnostic push
|
14
14
|
#pragma clang diagnostic ignored "-Wdocumentation"
|
@@ -19,30 +19,31 @@
|
|
19
19
|
|
20
20
|
namespace RNSkia {
|
21
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
|
-
|
22
|
+
namespace jsi = facebook::jsi;
|
23
|
+
|
24
|
+
class JsiSkSVGFactory : public JsiSkHostObject {
|
25
|
+
public:
|
26
|
+
JSI_HOST_FUNCTION(MakeFromData) {
|
27
|
+
auto data = JsiSkData::fromValue(runtime, arguments[0]);
|
28
|
+
auto stream = SkMemoryStream::Make(data);
|
29
|
+
auto svg_dom = SkSVGDOM::Builder().make(*stream);
|
30
|
+
return jsi::Object::createFromHostObject(
|
31
|
+
runtime, std::make_shared<JsiSkSVG>(getContext(), std::move(svg_dom)));
|
32
|
+
}
|
33
|
+
|
34
|
+
JSI_HOST_FUNCTION(MakeFromString) {
|
35
|
+
auto svgText = arguments[0].asString(runtime).utf8(runtime);
|
36
|
+
auto stream = SkMemoryStream::MakeDirect(svgText.c_str(), svgText.size());
|
37
|
+
auto svg_dom = SkSVGDOM::Builder().make(*stream);
|
38
|
+
return jsi::Object::createFromHostObject(
|
39
|
+
runtime, std::make_shared<JsiSkSVG>(getContext(), std::move(svg_dom)));
|
40
|
+
}
|
41
|
+
|
42
|
+
JSI_EXPORT_FUNCTIONS(JSI_EXPORT_FUNC(JsiSkSVGFactory, MakeFromData),
|
43
|
+
JSI_EXPORT_FUNC(JsiSkSVGFactory, MakeFromString))
|
44
|
+
|
45
|
+
explicit JsiSkSVGFactory(std::shared_ptr<RNSkPlatformContext> context)
|
46
|
+
: JsiSkHostObject(std::move(context)) {}
|
47
|
+
};
|
47
48
|
|
48
49
|
} // namespace RNSkia
|
package/cpp/api/JsiSkShader.h
CHANGED
@@ -17,13 +17,14 @@
|
|
17
17
|
|
18
18
|
namespace RNSkia {
|
19
19
|
|
20
|
-
|
20
|
+
namespace jsi = facebook::jsi;
|
21
21
|
|
22
22
|
class JsiSkShader : public JsiSkWrappingSkPtrHostObject<SkShader> {
|
23
23
|
public:
|
24
24
|
JsiSkShader(std::shared_ptr<RNSkPlatformContext> context,
|
25
25
|
sk_sp<SkShader> shader)
|
26
|
-
: JsiSkWrappingSkPtrHostObject<SkShader>(std::move(context),
|
26
|
+
: JsiSkWrappingSkPtrHostObject<SkShader>(std::move(context),
|
27
|
+
std::move(shader)) {}
|
27
28
|
|
28
29
|
// TODO: declare in JsiSkWrappingSkPtrHostObject via extra template parameter?
|
29
30
|
JSI_PROPERTY_GET(__typename__) {
|
@@ -20,44 +20,47 @@
|
|
20
20
|
|
21
21
|
namespace RNSkia {
|
22
22
|
|
23
|
-
|
23
|
+
namespace jsi = facebook::jsi;
|
24
24
|
|
25
|
-
int getFlag(const jsi::Value*
|
25
|
+
int getFlag(const jsi::Value *values, int i, size_t size) {
|
26
26
|
if (i >= size || values[i].isUndefined()) {
|
27
27
|
return 0;
|
28
28
|
}
|
29
29
|
return values[i].asNumber();
|
30
30
|
}
|
31
31
|
|
32
|
-
SkMatrix*
|
32
|
+
SkMatrix *getLocalMatrix(jsi::Runtime &runtime, const jsi::Value *values, int i,
|
33
|
+
size_t size) {
|
33
34
|
if (i >= size || values[i].isUndefined()) {
|
34
35
|
return nullptr;
|
35
36
|
}
|
36
37
|
return JsiSkMatrix::fromValue(runtime, values[i]).get();
|
37
38
|
}
|
38
39
|
|
39
|
-
SkTileMode getTileMode(const jsi::Value*
|
40
|
+
SkTileMode getTileMode(const jsi::Value *values, int i, size_t size) {
|
40
41
|
if (i >= size || values[i].isUndefined()) {
|
41
42
|
return SkTileMode::kClamp;
|
42
43
|
}
|
43
44
|
return static_cast<SkTileMode>(values[i].asNumber());
|
44
45
|
}
|
45
46
|
|
46
|
-
std::vector<SkColor> getColors(jsi::Runtime &runtime, const jsi::Value&
|
47
|
+
std::vector<SkColor> getColors(jsi::Runtime &runtime, const jsi::Value &value) {
|
47
48
|
std::vector<SkColor> colors;
|
48
49
|
if (!value.isNull()) {
|
49
50
|
auto jsiColors = value.asObject(runtime).asArray(runtime);
|
50
51
|
auto size = jsiColors.size(runtime);
|
51
52
|
colors.reserve(size);
|
52
53
|
for (int i = 0; i < size; i++) {
|
53
|
-
SkColor color =
|
54
|
+
SkColor color =
|
55
|
+
JsiSkColor::fromValue(runtime, jsiColors.getValueAtIndex(runtime, i));
|
54
56
|
colors.push_back(color);
|
55
57
|
}
|
56
58
|
}
|
57
59
|
return colors;
|
58
60
|
}
|
59
61
|
|
60
|
-
std::vector<SkScalar> getPositions(jsi::Runtime &runtime,
|
62
|
+
std::vector<SkScalar> getPositions(jsi::Runtime &runtime,
|
63
|
+
const jsi::Value &value) {
|
61
64
|
std::vector<SkScalar> positions;
|
62
65
|
if (!value.isNull()) {
|
63
66
|
auto jsiPositions = value.asObject(runtime).asArray(runtime);
|
@@ -86,10 +89,12 @@ public:
|
|
86
89
|
auto flag = getFlag(arguments, 6, count);
|
87
90
|
auto localMatrix = getLocalMatrix(runtime, arguments, 5, count);
|
88
91
|
|
89
|
-
sk_sp<SkShader> gradient = SkGradientShader::MakeLinear(
|
90
|
-
|
92
|
+
sk_sp<SkShader> gradient = SkGradientShader::MakeLinear(
|
93
|
+
pts, colors.data(), positions.data(), static_cast<int>(colors.size()),
|
94
|
+
tileMode, flag, localMatrix);
|
91
95
|
return jsi::Object::createFromHostObject(
|
92
|
-
runtime,
|
96
|
+
runtime,
|
97
|
+
std::make_shared<JsiSkShader>(getContext(), std::move(gradient)));
|
93
98
|
}
|
94
99
|
|
95
100
|
JSI_HOST_FUNCTION(MakeRadialGradient) {
|
@@ -103,11 +108,12 @@ public:
|
|
103
108
|
auto flag = getFlag(arguments, 6, count);
|
104
109
|
auto localMatrix = getLocalMatrix(runtime, arguments, 5, count);
|
105
110
|
|
106
|
-
sk_sp<SkShader> gradient = SkGradientShader::MakeRadial(
|
107
|
-
|
108
|
-
|
111
|
+
sk_sp<SkShader> gradient = SkGradientShader::MakeRadial(
|
112
|
+
center, r, colors.data(), positions.data(),
|
113
|
+
static_cast<int>(colors.size()), tileMode, flag, localMatrix);
|
109
114
|
return jsi::Object::createFromHostObject(
|
110
|
-
runtime,
|
115
|
+
runtime,
|
116
|
+
std::make_shared<JsiSkShader>(getContext(), std::move(gradient)));
|
111
117
|
}
|
112
118
|
|
113
119
|
JSI_HOST_FUNCTION(MakeSweepGradient) {
|
@@ -124,10 +130,11 @@ public:
|
|
124
130
|
? 360
|
125
131
|
: arguments[8].asNumber();
|
126
132
|
sk_sp<SkShader> gradient = SkGradientShader::MakeSweep(
|
127
|
-
x, y, colors.data(), positions.data(), static_cast<int>(colors.size()),
|
128
|
-
endAngle, flag, localMatrix);
|
133
|
+
x, y, colors.data(), positions.data(), static_cast<int>(colors.size()),
|
134
|
+
tileMode, startAngle, endAngle, flag, localMatrix);
|
129
135
|
return jsi::Object::createFromHostObject(
|
130
|
-
runtime,
|
136
|
+
runtime,
|
137
|
+
std::make_shared<JsiSkShader>(getContext(), std::move(gradient)));
|
131
138
|
}
|
132
139
|
|
133
140
|
JSI_HOST_FUNCTION(MakeTwoPointConicalGradient) {
|
@@ -146,11 +153,12 @@ public:
|
|
146
153
|
auto flag = getFlag(arguments, 8, count);
|
147
154
|
|
148
155
|
sk_sp<SkShader> gradient = SkGradientShader::MakeTwoPointConical(
|
149
|
-
|
150
|
-
|
156
|
+
start, startRadius, end, endRadius, colors.data(), positions.data(),
|
157
|
+
static_cast<int>(colors.size()), tileMode, flag, localMatrix);
|
151
158
|
|
152
159
|
return jsi::Object::createFromHostObject(
|
153
|
-
runtime,
|
160
|
+
runtime,
|
161
|
+
std::make_shared<JsiSkShader>(getContext(), std::move(gradient)));
|
154
162
|
}
|
155
163
|
|
156
164
|
JSI_HOST_FUNCTION(MakeTurbulence) {
|
@@ -164,7 +172,8 @@ public:
|
|
164
172
|
sk_sp<SkShader> gradient = SkPerlinNoiseShader::MakeTurbulence(
|
165
173
|
baseFreqX, baseFreqY, octaves, seed, &size);
|
166
174
|
return jsi::Object::createFromHostObject(
|
167
|
-
runtime,
|
175
|
+
runtime,
|
176
|
+
std::make_shared<JsiSkShader>(getContext(), std::move(gradient)));
|
168
177
|
}
|
169
178
|
|
170
179
|
JSI_HOST_FUNCTION(MakeFractalNoise) {
|
@@ -178,7 +187,8 @@ public:
|
|
178
187
|
sk_sp<SkShader> gradient = SkPerlinNoiseShader::MakeFractalNoise(
|
179
188
|
baseFreqX, baseFreqY, octaves, seed, &size);
|
180
189
|
return jsi::Object::createFromHostObject(
|
181
|
-
runtime,
|
190
|
+
runtime,
|
191
|
+
std::make_shared<JsiSkShader>(getContext(), std::move(gradient)));
|
182
192
|
}
|
183
193
|
|
184
194
|
JSI_HOST_FUNCTION(MakeBlend) {
|
@@ -187,14 +197,16 @@ public:
|
|
187
197
|
auto two = JsiSkShader::fromValue(runtime, arguments[2]);
|
188
198
|
sk_sp<SkShader> gradient = SkShaders::Blend(blendMode, one, two);
|
189
199
|
return jsi::Object::createFromHostObject(
|
190
|
-
runtime,
|
200
|
+
runtime,
|
201
|
+
std::make_shared<JsiSkShader>(getContext(), std::move(gradient)));
|
191
202
|
}
|
192
203
|
|
193
204
|
JSI_HOST_FUNCTION(MakeColor) {
|
194
205
|
auto color = JsiSkColor::fromValue(runtime, arguments[0]);
|
195
206
|
sk_sp<SkShader> gradient = SkShaders::Color(color);
|
196
207
|
return jsi::Object::createFromHostObject(
|
197
|
-
runtime,
|
208
|
+
runtime,
|
209
|
+
std::make_shared<JsiSkShader>(getContext(), std::move(gradient)));
|
198
210
|
}
|
199
211
|
|
200
212
|
JSI_EXPORT_FUNCTIONS(JSI_EXPORT_FUNC(JsiSkShaderFactory, MakeLinearGradient),
|
@@ -207,7 +219,7 @@ public:
|
|
207
219
|
JSI_EXPORT_FUNC(JsiSkShaderFactory, MakeBlend),
|
208
220
|
JSI_EXPORT_FUNC(JsiSkShaderFactory, MakeColor))
|
209
221
|
|
210
|
-
JsiSkShaderFactory(std::shared_ptr<RNSkPlatformContext> context)
|
222
|
+
explicit JsiSkShaderFactory(std::shared_ptr<RNSkPlatformContext> context)
|
211
223
|
: JsiSkHostObject(std::move(context)) {}
|
212
224
|
};
|
213
225
|
|
package/cpp/api/JsiSkSurface.h
CHANGED
@@ -7,9 +7,9 @@
|
|
7
7
|
|
8
8
|
#include "JsiSkHostObjects.h"
|
9
9
|
|
10
|
-
#include <JsiSkSurfaceFactory.h>
|
11
|
-
#include <JsiSkImage.h>
|
12
10
|
#include <JsiSkCanvas.h>
|
11
|
+
#include <JsiSkImage.h>
|
12
|
+
#include <JsiSkSurfaceFactory.h>
|
13
13
|
|
14
14
|
#pragma clang diagnostic push
|
15
15
|
#pragma clang diagnostic ignored "-Wdocumentation"
|
@@ -20,48 +20,52 @@
|
|
20
20
|
|
21
21
|
namespace RNSkia {
|
22
22
|
|
23
|
-
|
23
|
+
namespace jsi = facebook::jsi;
|
24
24
|
|
25
25
|
class JsiSkSurface : public JsiSkWrappingSkPtrHostObject<SkSurface> {
|
26
26
|
public:
|
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
|
-
JSI_EXPORT_PROPERTY_GETTERS(JSI_EXPORT_PROP_GET(JsiSkSurface, __typename__))
|
54
|
-
JSI_EXPORT_FUNCTIONS(JSI_EXPORT_FUNC(JsiSkSurface, getCanvas),
|
55
|
-
JSI_EXPORT_FUNC(JsiSkSurface, makeImageSnapshot))
|
56
|
-
|
57
|
-
/**
|
58
|
-
Returns the underlying object from a host object of this type
|
59
|
-
*/
|
60
|
-
static sk_sp<SkSurface> fromValue(jsi::Runtime &runtime, const jsi::Value &obj) {
|
61
|
-
return obj.asObject(runtime)
|
62
|
-
.asHostObject<JsiSkSurface>(runtime)
|
63
|
-
->getObject();
|
27
|
+
JsiSkSurface(std::shared_ptr<RNSkPlatformContext> context,
|
28
|
+
sk_sp<SkSurface> surface)
|
29
|
+
: JsiSkWrappingSkPtrHostObject<SkSurface>(std::move(context),
|
30
|
+
std::move(surface)) {}
|
31
|
+
|
32
|
+
// TODO: declare in JsiSkWrappingSkPtrHostObject via extra template parameter?
|
33
|
+
JSI_PROPERTY_GET(__typename__) {
|
34
|
+
return jsi::String::createFromUtf8(runtime, "Surface");
|
35
|
+
}
|
36
|
+
|
37
|
+
JSI_HOST_FUNCTION(getCanvas) {
|
38
|
+
return jsi::Object::createFromHostObject(
|
39
|
+
runtime,
|
40
|
+
std::make_shared<JsiSkCanvas>(getContext(), getObject()->getCanvas()));
|
41
|
+
}
|
42
|
+
|
43
|
+
JSI_HOST_FUNCTION(makeImageSnapshot) {
|
44
|
+
sk_sp<SkImage> image;
|
45
|
+
if (count == 1) {
|
46
|
+
auto rect = JsiSkRect::fromValue(runtime, arguments[0]);
|
47
|
+
image = getObject()->makeImageSnapshot(SkIRect::MakeXYWH(
|
48
|
+
rect->x(), rect->y(), rect->width(), rect->height()));
|
49
|
+
} else {
|
50
|
+
image = getObject()->makeImageSnapshot();
|
64
51
|
}
|
52
|
+
return jsi::Object::createFromHostObject(
|
53
|
+
runtime, std::make_shared<JsiSkImage>(getContext(), std::move(image)));
|
54
|
+
}
|
55
|
+
|
56
|
+
JSI_EXPORT_PROPERTY_GETTERS(JSI_EXPORT_PROP_GET(JsiSkSurface, __typename__))
|
57
|
+
JSI_EXPORT_FUNCTIONS(JSI_EXPORT_FUNC(JsiSkSurface, getCanvas),
|
58
|
+
JSI_EXPORT_FUNC(JsiSkSurface, makeImageSnapshot))
|
59
|
+
|
60
|
+
/**
|
61
|
+
Returns the underlying object from a host object of this type
|
62
|
+
*/
|
63
|
+
static sk_sp<SkSurface> fromValue(jsi::Runtime &runtime,
|
64
|
+
const jsi::Value &obj) {
|
65
|
+
return obj.asObject(runtime)
|
66
|
+
.asHostObject<JsiSkSurface>(runtime)
|
67
|
+
->getObject();
|
68
|
+
}
|
65
69
|
};
|
66
70
|
|
67
71
|
} // namespace RNSkia
|
@@ -12,33 +12,33 @@
|
|
12
12
|
#pragma clang diagnostic push
|
13
13
|
#pragma clang diagnostic ignored "-Wdocumentation"
|
14
14
|
|
15
|
-
#include <SkSurface.h>
|
16
15
|
#include <SkImage.h>
|
16
|
+
#include <SkSurface.h>
|
17
17
|
|
18
18
|
#pragma clang diagnostic pop
|
19
19
|
|
20
20
|
namespace RNSkia {
|
21
21
|
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
22
|
+
namespace jsi = facebook::jsi;
|
23
|
+
|
24
|
+
class JsiSkSurfaceFactory : public JsiSkHostObject {
|
25
|
+
public:
|
26
|
+
JSI_HOST_FUNCTION(Make) {
|
27
|
+
auto width = static_cast<int>(arguments[0].asNumber());
|
28
|
+
auto height = static_cast<int>(arguments[1].asNumber());
|
29
|
+
auto surface = SkSurface::MakeRasterN32Premul(width, height);
|
30
|
+
if (surface == nullptr) {
|
31
|
+
return jsi::Value::null();
|
32
|
+
}
|
33
|
+
return jsi::Object::createFromHostObject(
|
34
|
+
runtime,
|
35
|
+
std::make_shared<JsiSkSurface>(getContext(), std::move(surface)));
|
36
|
+
}
|
37
|
+
|
38
|
+
JSI_EXPORT_FUNCTIONS(JSI_EXPORT_FUNC(JsiSkSurfaceFactory, Make))
|
39
|
+
|
40
|
+
explicit JsiSkSurfaceFactory(std::shared_ptr<RNSkPlatformContext> context)
|
41
|
+
: JsiSkHostObject(std::move(context)) {}
|
42
|
+
};
|
43
43
|
|
44
44
|
} // namespace RNSkia
|