@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
@@ -8,23 +8,21 @@
|
|
8
8
|
|
9
9
|
namespace RNSkia {
|
10
10
|
|
11
|
-
|
12
|
-
using namespace RNJsi;
|
11
|
+
namespace jsi = facebook::jsi;
|
13
12
|
|
14
13
|
/**
|
15
14
|
* Base class for jsi host objects
|
16
15
|
*/
|
17
|
-
class JsiSkHostObject : public JsiHostObject {
|
16
|
+
class JsiSkHostObject : public RNJsi::JsiHostObject {
|
18
17
|
public:
|
19
18
|
/**
|
20
19
|
* Default constructor
|
21
20
|
* @param context Platform context
|
22
21
|
*/
|
23
|
-
JsiSkHostObject(std::shared_ptr<RNSkPlatformContext> context)
|
24
|
-
: _context(context){}
|
22
|
+
explicit JsiSkHostObject(std::shared_ptr<RNSkPlatformContext> context)
|
23
|
+
: _context(context) {}
|
25
24
|
|
26
25
|
protected:
|
27
|
-
|
28
26
|
/**
|
29
27
|
* @return A pointer to the platform context
|
30
28
|
*/
|
@@ -41,21 +39,20 @@ public:
|
|
41
39
|
* @param context Platform context
|
42
40
|
*/
|
43
41
|
JsiSkWrappingHostObject(std::shared_ptr<RNSkPlatformContext> context,
|
44
|
-
T&&
|
45
|
-
: JsiSkHostObject(std::move(context)), _object(std::move(object)){}
|
46
|
-
|
42
|
+
T &&object)
|
43
|
+
: JsiSkHostObject(std::move(context)), _object(std::move(object)) {}
|
44
|
+
|
47
45
|
JsiSkWrappingHostObject(std::shared_ptr<RNSkPlatformContext> context,
|
48
|
-
const T&
|
49
|
-
: JsiSkHostObject(std::move(context)), _object(object){}
|
46
|
+
const T &object)
|
47
|
+
: JsiSkHostObject(std::move(context)), _object(object) {}
|
50
48
|
|
51
49
|
/**
|
52
50
|
* Returns the underlying object exposed by this host object. This object
|
53
51
|
* should be wrapped in a shared pointer of some kind
|
54
52
|
* @return Underlying object
|
55
53
|
*/
|
56
|
-
T&
|
57
|
-
const T&
|
58
|
-
|
54
|
+
T &getObject() { return _object; }
|
55
|
+
const T &getObject() const { return _object; }
|
59
56
|
|
60
57
|
private:
|
61
58
|
/**
|
@@ -70,7 +67,8 @@ class JsiSkWrappingSharedPtrHostObject
|
|
70
67
|
public:
|
71
68
|
JsiSkWrappingSharedPtrHostObject(std::shared_ptr<RNSkPlatformContext> context,
|
72
69
|
std::shared_ptr<T> object)
|
73
|
-
: JsiSkWrappingHostObject<std::shared_ptr<T>>(std::move(context),
|
70
|
+
: JsiSkWrappingHostObject<std::shared_ptr<T>>(std::move(context),
|
71
|
+
std::move(object)) {}
|
74
72
|
};
|
75
73
|
|
76
74
|
template <typename T>
|
@@ -78,6 +76,7 @@ class JsiSkWrappingSkPtrHostObject : public JsiSkWrappingHostObject<sk_sp<T>> {
|
|
78
76
|
public:
|
79
77
|
JsiSkWrappingSkPtrHostObject(std::shared_ptr<RNSkPlatformContext> context,
|
80
78
|
sk_sp<T> object)
|
81
|
-
: JsiSkWrappingHostObject<sk_sp<T>>(std::move(context),
|
79
|
+
: JsiSkWrappingHostObject<sk_sp<T>>(std::move(context),
|
80
|
+
std::move(object)) {}
|
82
81
|
};
|
83
82
|
} // namespace RNSkia
|
package/cpp/api/JsiSkImage.h
CHANGED
@@ -1,11 +1,12 @@
|
|
1
1
|
#pragma once
|
2
2
|
|
3
|
-
#include <string>
|
4
3
|
#include <memory>
|
4
|
+
#include <string>
|
5
|
+
#include <utility>
|
5
6
|
|
6
7
|
#include "JsiSkMatrix.h"
|
7
|
-
#include <JsiSkHostObjects.h>
|
8
8
|
#include "JsiSkShader.h"
|
9
|
+
#include <JsiSkHostObjects.h>
|
9
10
|
|
10
11
|
#pragma clang diagnostic push
|
11
12
|
#pragma clang diagnostic ignored "-Wdocumentation"
|
@@ -19,106 +20,109 @@
|
|
19
20
|
|
20
21
|
#include <jsi/jsi.h>
|
21
22
|
|
22
|
-
namespace RNSkia
|
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
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
23
|
+
namespace RNSkia {
|
24
|
+
|
25
|
+
namespace jsi = facebook::jsi;
|
26
|
+
|
27
|
+
class JsiSkImage : public JsiSkWrappingSkPtrHostObject<SkImage> {
|
28
|
+
public:
|
29
|
+
// TODO-API: Properties?
|
30
|
+
JSI_HOST_FUNCTION(width) { return static_cast<double>(getObject()->width()); }
|
31
|
+
JSI_HOST_FUNCTION(height) {
|
32
|
+
return static_cast<double>(getObject()->height());
|
33
|
+
}
|
34
|
+
|
35
|
+
JSI_HOST_FUNCTION(makeShaderOptions) {
|
36
|
+
auto tmx = (SkTileMode)arguments[0].asNumber();
|
37
|
+
auto tmy = (SkTileMode)arguments[1].asNumber();
|
38
|
+
auto fm = (SkFilterMode)arguments[2].asNumber();
|
39
|
+
auto mm = (SkMipmapMode)arguments[3].asNumber();
|
40
|
+
auto m = count > 4 && !arguments[4].isUndefined()
|
41
|
+
? JsiSkMatrix::fromValue(runtime, arguments[4]).get()
|
42
|
+
: nullptr;
|
43
|
+
auto shader =
|
44
|
+
getObject()->makeShader(tmx, tmy, SkSamplingOptions(fm, mm), m);
|
45
|
+
return jsi::Object::createFromHostObject(
|
46
|
+
runtime,
|
47
|
+
std::make_shared<JsiSkShader>(getContext(), std::move(shader)));
|
48
|
+
}
|
49
|
+
|
50
|
+
JSI_HOST_FUNCTION(makeShaderCubic) {
|
51
|
+
auto tmx = (SkTileMode)arguments[0].asNumber();
|
52
|
+
auto tmy = (SkTileMode)arguments[1].asNumber();
|
53
|
+
auto B = SkDoubleToScalar(arguments[2].asNumber());
|
54
|
+
auto C = SkDoubleToScalar(arguments[3].asNumber());
|
55
|
+
auto m = count > 4 && !arguments[4].isUndefined()
|
56
|
+
? JsiSkMatrix::fromValue(runtime, arguments[4]).get()
|
57
|
+
: nullptr;
|
58
|
+
auto shader =
|
59
|
+
getObject()->makeShader(tmx, tmy, SkSamplingOptions({B, C}), m);
|
60
|
+
return jsi::Object::createFromHostObject(
|
61
|
+
runtime,
|
62
|
+
std::make_shared<JsiSkShader>(getContext(), std::move(shader)));
|
63
|
+
}
|
64
|
+
|
65
|
+
JSI_HOST_FUNCTION(encodeToBytes) {
|
66
|
+
// Get optional parameters
|
67
|
+
auto format =
|
68
|
+
count >= 1 ? static_cast<SkEncodedImageFormat>(arguments[0].asNumber())
|
69
|
+
: SkEncodedImageFormat::kPNG;
|
70
|
+
auto quality = count == 2 ? arguments[1].asNumber() : 100.0;
|
71
|
+
|
72
|
+
// Get data
|
73
|
+
auto data = getObject()->encodeToData(format, quality);
|
74
|
+
auto arrayCtor =
|
75
|
+
runtime.global().getPropertyAsFunction(runtime, "Uint8Array");
|
76
|
+
size_t size = data->size();
|
77
|
+
|
78
|
+
jsi::Object array =
|
79
|
+
arrayCtor.callAsConstructor(runtime, static_cast<double>(size))
|
80
|
+
.getObject(runtime);
|
81
|
+
jsi::ArrayBuffer buffer =
|
82
|
+
array.getProperty(runtime, jsi::PropNameID::forAscii(runtime, "buffer"))
|
83
|
+
.asObject(runtime)
|
84
|
+
.getArrayBuffer(runtime);
|
85
|
+
|
86
|
+
auto bfrPtr = reinterpret_cast<uint8_t *>(buffer.data(runtime));
|
87
|
+
memcpy(bfrPtr, data->bytes(), size);
|
88
|
+
return array;
|
89
|
+
}
|
90
|
+
|
91
|
+
JSI_HOST_FUNCTION(encodeToBase64) {
|
92
|
+
// Get optional parameters
|
93
|
+
auto format =
|
94
|
+
count >= 1 ? static_cast<SkEncodedImageFormat>(arguments[0].asNumber())
|
95
|
+
: SkEncodedImageFormat::kPNG;
|
96
|
+
|
97
|
+
auto quality = count == 2 ? arguments[1].asNumber() : 100.0;
|
98
|
+
|
99
|
+
auto data = getObject()->encodeToData(format, quality);
|
100
|
+
auto len = SkBase64::Encode(data->bytes(), data->size(), nullptr);
|
101
|
+
auto buffer = std::string(len, 0);
|
102
|
+
SkBase64::Encode(data->bytes(), data->size(),
|
103
|
+
reinterpret_cast<void *>(&buffer[0]));
|
104
|
+
return jsi::String::createFromAscii(runtime, buffer);
|
105
|
+
}
|
106
|
+
|
107
|
+
JSI_EXPORT_FUNCTIONS(JSI_EXPORT_FUNC(JsiSkImage, width),
|
108
|
+
JSI_EXPORT_FUNC(JsiSkImage, height),
|
109
|
+
JSI_EXPORT_FUNC(JsiSkImage, makeShaderOptions),
|
110
|
+
JSI_EXPORT_FUNC(JsiSkImage, makeShaderCubic),
|
111
|
+
JSI_EXPORT_FUNC(JsiSkImage, encodeToBytes),
|
112
|
+
JSI_EXPORT_FUNC(JsiSkImage, encodeToBase64))
|
113
|
+
|
114
|
+
JsiSkImage(std::shared_ptr<RNSkPlatformContext> context,
|
115
|
+
const sk_sp<SkImage> image)
|
116
|
+
: JsiSkWrappingSkPtrHostObject<SkImage>(std::move(context),
|
117
|
+
std::move(image)) {}
|
118
|
+
|
119
|
+
/**
|
120
|
+
Returns the underlying object from a host object of this type
|
121
|
+
*/
|
122
|
+
static sk_sp<SkImage> fromValue(jsi::Runtime &runtime,
|
123
|
+
const jsi::Value &obj) {
|
124
|
+
return obj.asObject(runtime).asHostObject<JsiSkImage>(runtime)->getObject();
|
125
|
+
}
|
126
|
+
};
|
123
127
|
|
124
128
|
} // namespace RNSkia
|
@@ -5,46 +5,44 @@
|
|
5
5
|
|
6
6
|
#include <jsi/jsi.h>
|
7
7
|
|
8
|
+
#include "JsiSkData.h"
|
9
|
+
#include "JsiSkHostObjects.h"
|
8
10
|
#include "JsiSkImage.h"
|
9
11
|
#include "JsiSkImageInfo.h"
|
10
|
-
#include "JsiSkHostObjects.h"
|
11
|
-
#include "JsiSkData.h"
|
12
12
|
|
13
13
|
namespace RNSkia {
|
14
14
|
|
15
|
-
|
16
|
-
|
17
|
-
|
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
|
-
: JsiSkHostObject(std::move(context)) {}
|
48
|
-
};
|
15
|
+
namespace jsi = facebook::jsi;
|
16
|
+
|
17
|
+
class JsiSkImageFactory : public JsiSkHostObject {
|
18
|
+
public:
|
19
|
+
JSI_HOST_FUNCTION(MakeImageFromEncoded) {
|
20
|
+
auto data = JsiSkData::fromValue(runtime, arguments[0]);
|
21
|
+
auto image = SkImage::MakeFromEncoded(data);
|
22
|
+
if (image == nullptr) {
|
23
|
+
return jsi::Value::null();
|
24
|
+
}
|
25
|
+
return jsi::Object::createFromHostObject(
|
26
|
+
runtime, std::make_shared<JsiSkImage>(getContext(), std::move(image)));
|
27
|
+
}
|
28
|
+
|
29
|
+
JSI_HOST_FUNCTION(MakeImage) {
|
30
|
+
auto imageInfo = JsiSkImageInfo::fromValue(runtime, arguments[0]);
|
31
|
+
auto pixelData = JsiSkData::fromValue(runtime, arguments[1]);
|
32
|
+
auto bytesPerRow = arguments[2].asNumber();
|
33
|
+
auto image = SkImage::MakeRasterData(*imageInfo, pixelData, bytesPerRow);
|
34
|
+
if (image == nullptr) {
|
35
|
+
return jsi::Value::null();
|
36
|
+
}
|
37
|
+
return jsi::Object::createFromHostObject(
|
38
|
+
runtime, std::make_shared<JsiSkImage>(getContext(), std::move(image)));
|
39
|
+
}
|
40
|
+
|
41
|
+
JSI_EXPORT_FUNCTIONS(JSI_EXPORT_FUNC(JsiSkImageFactory, MakeImageFromEncoded),
|
42
|
+
JSI_EXPORT_FUNC(JsiSkImageFactory, MakeImage), )
|
43
|
+
|
44
|
+
explicit JsiSkImageFactory(std::shared_ptr<RNSkPlatformContext> context)
|
45
|
+
: JsiSkHostObject(std::move(context)) {}
|
46
|
+
};
|
49
47
|
|
50
48
|
} // namespace RNSkia
|
@@ -16,20 +16,22 @@
|
|
16
16
|
|
17
17
|
namespace RNSkia {
|
18
18
|
|
19
|
-
|
19
|
+
namespace jsi = facebook::jsi;
|
20
20
|
|
21
21
|
class JsiSkImageFilter : public JsiSkWrappingSkPtrHostObject<SkImageFilter> {
|
22
22
|
public:
|
23
23
|
JsiSkImageFilter(std::shared_ptr<RNSkPlatformContext> context,
|
24
24
|
sk_sp<SkImageFilter> imageFilter)
|
25
|
-
: JsiSkWrappingSkPtrHostObject<SkImageFilter>(std::move(context),
|
25
|
+
: JsiSkWrappingSkPtrHostObject<SkImageFilter>(std::move(context),
|
26
|
+
std::move(imageFilter)) {}
|
26
27
|
|
27
28
|
// TODO: declare in JsiSkWrappingSkPtrHostObject via extra template parameter?
|
28
29
|
JSI_PROPERTY_GET(__typename__) {
|
29
30
|
return jsi::String::createFromUtf8(runtime, "ImageFilter");
|
30
31
|
}
|
31
32
|
|
32
|
-
JSI_EXPORT_PROPERTY_GETTERS(JSI_EXPORT_PROP_GET(JsiSkImageFilter,
|
33
|
+
JSI_EXPORT_PROPERTY_GETTERS(JSI_EXPORT_PROP_GET(JsiSkImageFilter,
|
34
|
+
__typename__))
|
33
35
|
|
34
36
|
/**
|
35
37
|
Returns the underlying object from a host object of this type
|
@@ -18,7 +18,7 @@
|
|
18
18
|
|
19
19
|
namespace RNSkia {
|
20
20
|
|
21
|
-
|
21
|
+
namespace jsi = facebook::jsi;
|
22
22
|
|
23
23
|
class JsiSkImageFilterFactory : public JsiSkHostObject {
|
24
24
|
public:
|
@@ -45,7 +45,8 @@ public:
|
|
45
45
|
}
|
46
46
|
return jsi::Object::createFromHostObject(
|
47
47
|
runtime, std::make_shared<JsiSkImageFilter>(
|
48
|
-
getContext(), SkImageFilters::ColorFilter(
|
48
|
+
getContext(), SkImageFilters::ColorFilter(
|
49
|
+
std::move(cf), std::move(input))));
|
49
50
|
}
|
50
51
|
|
51
52
|
JSI_HOST_FUNCTION(MakeOffset) {
|
@@ -53,41 +54,43 @@ public:
|
|
53
54
|
auto y = arguments[1].asNumber();
|
54
55
|
sk_sp<SkImageFilter> input;
|
55
56
|
if (!arguments[2].isNull()) {
|
56
|
-
|
57
|
+
input = JsiSkImageFilter::fromValue(runtime, arguments[2]);
|
57
58
|
}
|
58
59
|
return jsi::Object::createFromHostObject(
|
59
|
-
|
60
|
-
|
60
|
+
runtime,
|
61
|
+
std::make_shared<JsiSkImageFilter>(
|
62
|
+
getContext(), SkImageFilters::Offset(x, y, std::move(input))));
|
61
63
|
}
|
62
64
|
|
63
65
|
JSI_HOST_FUNCTION(MakeDisplacementMap) {
|
64
|
-
auto fXChannelSelector =
|
65
|
-
|
66
|
+
auto fXChannelSelector =
|
67
|
+
static_cast<SkColorChannel>(arguments[0].asNumber());
|
68
|
+
auto fYChannelSelector =
|
69
|
+
static_cast<SkColorChannel>(arguments[1].asNumber());
|
66
70
|
auto scale = arguments[2].asNumber();
|
67
71
|
auto in2 = JsiSkImageFilter::fromValue(runtime, arguments[3]);
|
68
72
|
sk_sp<SkImageFilter> input;
|
69
73
|
if (!arguments[4].isNull()) {
|
70
|
-
|
74
|
+
input = JsiSkImageFilter::fromValue(runtime, arguments[4]);
|
71
75
|
}
|
72
76
|
return jsi::Object::createFromHostObject(
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
);
|
77
|
+
runtime,
|
78
|
+
std::make_shared<JsiSkImageFilter>(
|
79
|
+
getContext(), SkImageFilters::DisplacementMap(
|
80
|
+
fXChannelSelector, fYChannelSelector, scale,
|
81
|
+
std::move(in2), std::move(input))));
|
79
82
|
}
|
80
83
|
|
81
84
|
JSI_HOST_FUNCTION(MakeShader) {
|
82
85
|
auto shader = JsiSkShader::fromValue(runtime, arguments[0]);
|
83
86
|
return jsi::Object::createFromHostObject(
|
84
|
-
|
85
|
-
|
87
|
+
runtime, std::make_shared<JsiSkImageFilter>(
|
88
|
+
getContext(), SkImageFilters::Shader(std::move(shader))));
|
86
89
|
}
|
87
90
|
|
88
91
|
JSI_HOST_FUNCTION(MakeCompose) {
|
89
92
|
sk_sp<SkImageFilter> outer;
|
90
|
-
if (!arguments[0].isNull()&& !arguments[0].isUndefined()) {
|
93
|
+
if (!arguments[0].isNull() && !arguments[0].isUndefined()) {
|
91
94
|
outer = JsiSkImageFilter::fromValue(runtime, arguments[0]);
|
92
95
|
}
|
93
96
|
sk_sp<SkImageFilter> inner;
|
@@ -96,16 +99,17 @@ public:
|
|
96
99
|
}
|
97
100
|
return jsi::Object::createFromHostObject(
|
98
101
|
runtime, std::make_shared<JsiSkImageFilter>(
|
99
|
-
getContext(), SkImageFilters::Compose(std::move(outer),
|
102
|
+
getContext(), SkImageFilters::Compose(std::move(outer),
|
103
|
+
std::move(inner))));
|
100
104
|
}
|
101
105
|
|
102
|
-
|
103
106
|
JSI_HOST_FUNCTION(MakeBlend) {
|
104
107
|
auto mode = static_cast<SkBlendMode>(arguments[0].asNumber());
|
105
|
-
sk_sp<SkImageFilter> background =
|
108
|
+
sk_sp<SkImageFilter> background =
|
109
|
+
JsiSkImageFilter::fromValue(runtime, arguments[1]);
|
106
110
|
sk_sp<SkImageFilter> foreground = nullptr;
|
107
111
|
|
108
|
-
if(count > 2 && !arguments[2].isNull()) {
|
112
|
+
if (count > 2 && !arguments[2].isNull()) {
|
109
113
|
foreground = JsiSkImageFilter::fromValue(runtime, arguments[2]);
|
110
114
|
}
|
111
115
|
|
@@ -115,8 +119,10 @@ public:
|
|
115
119
|
}
|
116
120
|
|
117
121
|
return jsi::Object::createFromHostObject(
|
118
|
-
|
119
|
-
|
122
|
+
runtime, std::make_shared<JsiSkImageFilter>(
|
123
|
+
getContext(), SkImageFilters::Blend(
|
124
|
+
std::move(mode), std::move(background),
|
125
|
+
std::move(foreground), cropRect)));
|
120
126
|
}
|
121
127
|
|
122
128
|
JSI_HOST_FUNCTION(MakeDropShadow) {
|
@@ -134,10 +140,10 @@ public:
|
|
134
140
|
cropRect = *JsiSkRect::fromValue(runtime, arguments[6]);
|
135
141
|
}
|
136
142
|
return jsi::Object::createFromHostObject(
|
137
|
-
runtime,
|
138
|
-
|
139
|
-
|
140
|
-
|
143
|
+
runtime, std::make_shared<JsiSkImageFilter>(
|
144
|
+
getContext(),
|
145
|
+
SkImageFilters::DropShadow(dx, dy, sigmaX, sigmaY, color,
|
146
|
+
std::move(input), cropRect)));
|
141
147
|
}
|
142
148
|
|
143
149
|
JSI_HOST_FUNCTION(MakeDropShadowOnly) {
|
@@ -155,10 +161,10 @@ public:
|
|
155
161
|
cropRect = *JsiSkRect::fromValue(runtime, arguments[6]);
|
156
162
|
}
|
157
163
|
return jsi::Object::createFromHostObject(
|
158
|
-
runtime,
|
159
|
-
|
160
|
-
|
161
|
-
|
164
|
+
runtime, std::make_shared<JsiSkImageFilter>(
|
165
|
+
getContext(), SkImageFilters::DropShadowOnly(
|
166
|
+
dx, dy, sigmaX, sigmaY, color,
|
167
|
+
std::move(input), cropRect)));
|
162
168
|
}
|
163
169
|
|
164
170
|
JSI_HOST_FUNCTION(MakeErode) {
|
@@ -173,10 +179,9 @@ public:
|
|
173
179
|
cropRect = *JsiSkRect::fromValue(runtime, arguments[3]);
|
174
180
|
}
|
175
181
|
return jsi::Object::createFromHostObject(
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
);
|
182
|
+
runtime, std::make_shared<JsiSkImageFilter>(
|
183
|
+
getContext(), SkImageFilters::Erode(
|
184
|
+
rx, ry, std::move(input), cropRect)));
|
180
185
|
}
|
181
186
|
|
182
187
|
JSI_HOST_FUNCTION(MakeDilate) {
|
@@ -191,46 +196,44 @@ public:
|
|
191
196
|
cropRect = *JsiSkRect::fromValue(runtime, arguments[3]);
|
192
197
|
}
|
193
198
|
return jsi::Object::createFromHostObject(
|
194
|
-
|
195
|
-
|
196
|
-
|
199
|
+
runtime, std::make_shared<JsiSkImageFilter>(
|
200
|
+
getContext(), SkImageFilters::Dilate(
|
201
|
+
rx, ry, std::move(input), cropRect)));
|
197
202
|
}
|
198
203
|
|
199
|
-
|
200
|
-
|
204
|
+
JSI_HOST_FUNCTION(MakeRuntimeShader) {
|
205
|
+
auto rtb = JsiSkRuntimeShaderBuilder::fromValue(runtime, arguments[0]);
|
201
206
|
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
207
|
+
const char *childName = nullptr;
|
208
|
+
if (!arguments[1].isNull() && !arguments[1].isUndefined()) {
|
209
|
+
childName = arguments[1].asString(runtime).utf8(runtime).c_str();
|
210
|
+
}
|
206
211
|
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
}
|
211
|
-
return jsi::Object::createFromHostObject(
|
212
|
-
runtime,
|
213
|
-
std::make_shared<JsiSkImageFilter>(
|
214
|
-
getContext(), SkImageFilters::RuntimeShader(*rtb, childName, std::move(input)))
|
215
|
-
);
|
212
|
+
sk_sp<SkImageFilter> input;
|
213
|
+
if (!arguments[2].isNull() && !arguments[2].isUndefined()) {
|
214
|
+
input = JsiSkImageFilter::fromValue(runtime, arguments[2]);
|
216
215
|
}
|
216
|
+
return jsi::Object::createFromHostObject(
|
217
|
+
runtime, std::make_shared<JsiSkImageFilter>(
|
218
|
+
getContext(), SkImageFilters::RuntimeShader(
|
219
|
+
*rtb, childName, std::move(input))));
|
220
|
+
}
|
217
221
|
|
218
222
|
JSI_EXPORT_FUNCTIONS(
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
JsiSkImageFilterFactory(std::shared_ptr<RNSkPlatformContext> context)
|
223
|
+
JSI_EXPORT_FUNC(JsiSkImageFilterFactory, MakeBlur),
|
224
|
+
JSI_EXPORT_FUNC(JsiSkImageFilterFactory, MakeOffset),
|
225
|
+
JSI_EXPORT_FUNC(JsiSkImageFilterFactory, MakeColorFilter),
|
226
|
+
JSI_EXPORT_FUNC(JsiSkImageFilterFactory, MakeShader),
|
227
|
+
JSI_EXPORT_FUNC(JsiSkImageFilterFactory, MakeDisplacementMap),
|
228
|
+
JSI_EXPORT_FUNC(JsiSkImageFilterFactory, MakeCompose),
|
229
|
+
JSI_EXPORT_FUNC(JsiSkImageFilterFactory, MakeErode),
|
230
|
+
JSI_EXPORT_FUNC(JsiSkImageFilterFactory, MakeDilate),
|
231
|
+
JSI_EXPORT_FUNC(JsiSkImageFilterFactory, MakeBlend),
|
232
|
+
JSI_EXPORT_FUNC(JsiSkImageFilterFactory, MakeDropShadow),
|
233
|
+
JSI_EXPORT_FUNC(JsiSkImageFilterFactory, MakeDropShadowOnly),
|
234
|
+
JSI_EXPORT_FUNC(JsiSkImageFilterFactory, MakeRuntimeShader))
|
235
|
+
|
236
|
+
explicit JsiSkImageFilterFactory(std::shared_ptr<RNSkPlatformContext> context)
|
234
237
|
: JsiSkHostObject(std::move(context)) {}
|
235
238
|
};
|
236
239
|
|