@shopify/react-native-skia 0.1.154 → 0.1.156
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- 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
package/cpp/api/JsiSkTextBlob.h
CHANGED
|
@@ -16,35 +16,32 @@
|
|
|
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
|
-
};
|
|
19
|
+
namespace jsi = facebook::jsi;
|
|
20
|
+
|
|
21
|
+
class JsiSkTextBlob : public JsiSkWrappingSkPtrHostObject<SkTextBlob> {
|
|
22
|
+
public:
|
|
23
|
+
JsiSkTextBlob(std::shared_ptr<RNSkPlatformContext> context,
|
|
24
|
+
sk_sp<SkTextBlob> shader)
|
|
25
|
+
: JsiSkWrappingSkPtrHostObject<SkTextBlob>(std::move(context),
|
|
26
|
+
std::move(shader)) {}
|
|
27
|
+
|
|
28
|
+
// TODO: declare in JsiSkWrappingSkPtrHostObject via extra template parameter?
|
|
29
|
+
|
|
30
|
+
JSI_PROPERTY_GET(__typename__) {
|
|
31
|
+
return jsi::String::createFromUtf8(runtime, "TextBlob");
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
JSI_EXPORT_PROPERTY_GETTERS(JSI_EXPORT_PROP_GET(JsiSkTextBlob,
|
|
35
|
+
__typename__), )
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
Returns the underlying object from a host object of this type
|
|
39
|
+
*/
|
|
40
|
+
static sk_sp<SkTextBlob> fromValue(jsi::Runtime &runtime,
|
|
41
|
+
const jsi::Value &obj) {
|
|
42
|
+
return obj.asObject(runtime)
|
|
43
|
+
.asHostObject<JsiSkTextBlob>(runtime)
|
|
44
|
+
->getObject();
|
|
45
|
+
}
|
|
46
|
+
};
|
|
50
47
|
} // namespace RNSkia
|
|
@@ -6,10 +6,10 @@
|
|
|
6
6
|
|
|
7
7
|
#include <jsi/jsi.h>
|
|
8
8
|
|
|
9
|
+
#include "JsiSkFont.h"
|
|
9
10
|
#include "JsiSkHostObjects.h"
|
|
10
|
-
#include "JsiSkTextBlob.h"
|
|
11
11
|
#include "JsiSkRSXform.h"
|
|
12
|
-
#include "
|
|
12
|
+
#include "JsiSkTextBlob.h"
|
|
13
13
|
|
|
14
14
|
#pragma clang diagnostic push
|
|
15
15
|
#pragma clang diagnostic ignored "-Wdocumentation"
|
|
@@ -20,90 +20,91 @@
|
|
|
20
20
|
|
|
21
21
|
namespace RNSkia {
|
|
22
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
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
23
|
+
namespace jsi = facebook::jsi;
|
|
24
|
+
|
|
25
|
+
class JsiSkTextBlobFactory : public JsiSkHostObject {
|
|
26
|
+
public:
|
|
27
|
+
JSI_HOST_FUNCTION(MakeFromText) {
|
|
28
|
+
auto str = arguments[0].asString(runtime).utf8(runtime);
|
|
29
|
+
auto font = JsiSkFont::fromValue(runtime, arguments[1]);
|
|
30
|
+
auto textBlob = SkTextBlob::MakeFromString(str.c_str(), *font);
|
|
31
|
+
return jsi::Object::createFromHostObject(
|
|
32
|
+
runtime,
|
|
33
|
+
std::make_shared<JsiSkTextBlob>(getContext(), std::move(textBlob)));
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
JSI_HOST_FUNCTION(MakeFromGlyphs) {
|
|
37
|
+
auto jsiGlyphs = arguments[0].asObject(runtime).asArray(runtime);
|
|
38
|
+
auto font = JsiSkFont::fromValue(runtime, arguments[1]);
|
|
39
|
+
int bytesPerGlyph = 2;
|
|
40
|
+
std::vector<SkGlyphID> glyphs;
|
|
41
|
+
int glyphsSize = static_cast<int>(jsiGlyphs.size(runtime));
|
|
42
|
+
glyphs.reserve(glyphsSize);
|
|
43
|
+
for (int i = 0; i < glyphsSize; i++) {
|
|
44
|
+
glyphs.push_back(jsiGlyphs.getValueAtIndex(runtime, i).asNumber());
|
|
45
|
+
}
|
|
46
|
+
auto textBlob =
|
|
47
|
+
SkTextBlob::MakeFromText(glyphs.data(), glyphs.size() * bytesPerGlyph,
|
|
48
|
+
*font, SkTextEncoding::kGlyphID);
|
|
49
|
+
return jsi::Object::createFromHostObject(
|
|
50
|
+
runtime,
|
|
51
|
+
std::make_shared<JsiSkTextBlob>(getContext(), std::move(textBlob)));
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
JSI_HOST_FUNCTION(MakeFromRSXform) {
|
|
55
|
+
auto str = arguments[0].asString(runtime).utf8(runtime);
|
|
56
|
+
auto jsiRsxforms = arguments[1].asObject(runtime).asArray(runtime);
|
|
57
|
+
auto font = JsiSkFont::fromValue(runtime, arguments[2]);
|
|
58
|
+
std::vector<SkRSXform> rsxforms;
|
|
59
|
+
int rsxformsSize = static_cast<int>(jsiRsxforms.size(runtime));
|
|
60
|
+
rsxforms.reserve(rsxformsSize);
|
|
61
|
+
for (int i = 0; i < rsxformsSize; i++) {
|
|
62
|
+
auto rsxform = JsiSkRSXform::fromValue(
|
|
63
|
+
runtime, jsiRsxforms.getValueAtIndex(runtime, i));
|
|
64
|
+
rsxforms.push_back(*rsxform);
|
|
65
|
+
}
|
|
66
|
+
auto textBlob = SkTextBlob::MakeFromRSXform(str.c_str(), str.length(),
|
|
67
|
+
rsxforms.data(), *font);
|
|
68
|
+
return jsi::Object::createFromHostObject(
|
|
69
|
+
runtime,
|
|
70
|
+
std::make_shared<JsiSkTextBlob>(getContext(), std::move(textBlob)));
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
JSI_HOST_FUNCTION(MakeFromRSXformGlyphs) {
|
|
74
|
+
auto jsiGlyphs = arguments[0].asObject(runtime).asArray(runtime);
|
|
75
|
+
auto jsiRsxforms = arguments[1].asObject(runtime).asArray(runtime);
|
|
76
|
+
auto font = JsiSkFont::fromValue(runtime, arguments[2]);
|
|
77
|
+
int bytesPerGlyph = 2;
|
|
78
|
+
std::vector<SkGlyphID> glyphs;
|
|
79
|
+
int glyphsSize = static_cast<int>(jsiGlyphs.size(runtime));
|
|
80
|
+
glyphs.reserve(glyphsSize);
|
|
81
|
+
for (int i = 0; i < glyphsSize; i++) {
|
|
82
|
+
glyphs.push_back(jsiGlyphs.getValueAtIndex(runtime, i).asNumber());
|
|
83
|
+
}
|
|
84
|
+
std::vector<SkRSXform> rsxforms;
|
|
85
|
+
int rsxformsSize = static_cast<int>(jsiRsxforms.size(runtime));
|
|
86
|
+
rsxforms.reserve(rsxformsSize);
|
|
87
|
+
for (int i = 0; i < rsxformsSize; i++) {
|
|
88
|
+
auto rsxform = JsiSkRSXform::fromValue(
|
|
89
|
+
runtime, jsiRsxforms.getValueAtIndex(runtime, i));
|
|
90
|
+
rsxforms.push_back(*rsxform);
|
|
91
|
+
}
|
|
92
|
+
auto textBlob = SkTextBlob::MakeFromRSXform(
|
|
93
|
+
glyphs.data(), glyphs.size() * bytesPerGlyph, rsxforms.data(), *font,
|
|
94
|
+
SkTextEncoding::kGlyphID);
|
|
95
|
+
return jsi::Object::createFromHostObject(
|
|
96
|
+
runtime,
|
|
97
|
+
std::make_shared<JsiSkTextBlob>(getContext(), std::move(textBlob)));
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
JSI_EXPORT_FUNCTIONS(JSI_EXPORT_FUNC(JsiSkTextBlobFactory, MakeFromText),
|
|
101
|
+
JSI_EXPORT_FUNC(JsiSkTextBlobFactory, MakeFromGlyphs),
|
|
102
|
+
JSI_EXPORT_FUNC(JsiSkTextBlobFactory, MakeFromRSXform),
|
|
103
|
+
JSI_EXPORT_FUNC(JsiSkTextBlobFactory,
|
|
104
|
+
MakeFromRSXformGlyphs), )
|
|
105
|
+
|
|
106
|
+
explicit JsiSkTextBlobFactory(std::shared_ptr<RNSkPlatformContext> context)
|
|
107
|
+
: JsiSkHostObject(std::move(context)) {}
|
|
108
|
+
};
|
|
108
109
|
|
|
109
110
|
} // namespace RNSkia
|
package/cpp/api/JsiSkTypeface.h
CHANGED
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
|
|
19
19
|
namespace RNSkia {
|
|
20
20
|
|
|
21
|
-
|
|
21
|
+
namespace jsi = facebook::jsi;
|
|
22
22
|
|
|
23
23
|
class JsiSkTypeface : public JsiSkWrappingSkPtrHostObject<SkTypeface> {
|
|
24
24
|
public:
|
|
@@ -31,7 +31,7 @@ public:
|
|
|
31
31
|
|
|
32
32
|
JsiSkTypeface(std::shared_ptr<RNSkPlatformContext> context,
|
|
33
33
|
sk_sp<SkTypeface> typeface)
|
|
34
|
-
: JsiSkWrappingSkPtrHostObject(std::move(context), std::move(typeface)){}
|
|
34
|
+
: JsiSkWrappingSkPtrHostObject(std::move(context), std::move(typeface)) {}
|
|
35
35
|
|
|
36
36
|
/**
|
|
37
37
|
Returns the underlying object from a host object of this type
|
|
@@ -47,10 +47,11 @@ public:
|
|
|
47
47
|
Returns the jsi object from a host object of this type
|
|
48
48
|
*/
|
|
49
49
|
static jsi::Value toValue(jsi::Runtime &runtime,
|
|
50
|
-
|
|
51
|
-
|
|
50
|
+
std::shared_ptr<RNSkPlatformContext> context,
|
|
51
|
+
sk_sp<SkTypeface> tf) {
|
|
52
52
|
return jsi::Object::createFromHostObject(
|
|
53
|
-
|
|
53
|
+
runtime,
|
|
54
|
+
std::make_shared<JsiSkTypeface>(std::move(context), std::move(tf)));
|
|
54
55
|
}
|
|
55
56
|
};
|
|
56
57
|
|
|
@@ -5,30 +5,31 @@
|
|
|
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"
|
|
10
|
+
#include "JsiSkTypeface.h"
|
|
11
11
|
|
|
12
12
|
namespace RNSkia {
|
|
13
13
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
14
|
+
namespace jsi = facebook::jsi;
|
|
15
|
+
|
|
16
|
+
class JsiSkTypefaceFactory : public JsiSkHostObject {
|
|
17
|
+
public:
|
|
18
|
+
JSI_HOST_FUNCTION(MakeFreeTypeFaceFromData) {
|
|
19
|
+
auto data = JsiSkData::fromValue(runtime, arguments[0]);
|
|
20
|
+
auto typeface = SkFontMgr::RefDefault()->makeFromData(std::move(data));
|
|
21
|
+
if (typeface == nullptr) {
|
|
22
|
+
return jsi::Value::null();
|
|
23
|
+
}
|
|
24
|
+
return jsi::Object::createFromHostObject(
|
|
25
|
+
runtime, std::make_shared<JsiSkTypeface>(getContext(), typeface));
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
JSI_EXPORT_FUNCTIONS(JSI_EXPORT_FUNC(JsiSkTypefaceFactory,
|
|
29
|
+
MakeFreeTypeFaceFromData))
|
|
30
|
+
|
|
31
|
+
explicit JsiSkTypefaceFactory(std::shared_ptr<RNSkPlatformContext> context)
|
|
32
|
+
: JsiSkHostObject(std::move(context)) {}
|
|
33
|
+
};
|
|
33
34
|
|
|
34
35
|
} // namespace RNSkia
|
package/cpp/api/JsiSkVertices.h
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
#pragma once
|
|
2
2
|
|
|
3
|
+
#include <jsi/jsi.h>
|
|
3
4
|
#include <memory>
|
|
4
5
|
#include <utility>
|
|
5
|
-
#include <
|
|
6
|
+
#include <vector>
|
|
6
7
|
|
|
7
8
|
#include "JsiSkHostObjects.h"
|
|
8
9
|
|
|
@@ -15,131 +16,143 @@
|
|
|
15
16
|
|
|
16
17
|
namespace RNSkia {
|
|
17
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
|
-
|
|
19
|
+
namespace jsi = facebook::jsi;
|
|
20
|
+
|
|
21
|
+
class JsiSkVertices : public JsiSkWrappingSkPtrHostObject<SkVertices> {
|
|
22
|
+
public:
|
|
23
|
+
JsiSkVertices(std::shared_ptr<RNSkPlatformContext> context,
|
|
24
|
+
sk_sp<SkVertices> vertices)
|
|
25
|
+
: JsiSkWrappingSkPtrHostObject<SkVertices>(std::move(context),
|
|
26
|
+
std::move(vertices)) {}
|
|
27
|
+
|
|
28
|
+
// TODO: declare in JsiSkWrappingSkPtrHostObject via extra template parameter?
|
|
29
|
+
JSI_PROPERTY_GET(__typename__) {
|
|
30
|
+
return jsi::String::createFromUtf8(runtime, "Vertices");
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
JSI_EXPORT_PROPERTY_GETTERS(JSI_EXPORT_PROP_GET(JsiSkVertices, __typename__))
|
|
34
|
+
|
|
35
|
+
JSI_HOST_FUNCTION(bounds) {
|
|
36
|
+
const auto &result = getObject()->bounds();
|
|
37
|
+
return jsi::Object::createFromHostObject(
|
|
38
|
+
runtime, std::make_shared<JsiSkRect>(getContext(), result));
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
JSI_HOST_FUNCTION(uniqueID) {
|
|
42
|
+
return static_cast<double>(getObject()->uniqueID());
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
JSI_EXPORT_FUNCTIONS(JSI_EXPORT_FUNC(JsiSkVertices, bounds),
|
|
46
|
+
JSI_EXPORT_FUNC(JsiSkVertices, uniqueID), )
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
Returns the underlying object from a host object of this type
|
|
50
|
+
*/
|
|
51
|
+
static sk_sp<SkVertices> fromValue(jsi::Runtime &runtime,
|
|
52
|
+
const jsi::Value &obj) {
|
|
53
|
+
return obj.asObject(runtime)
|
|
54
|
+
.asHostObject<JsiSkVertices>(runtime)
|
|
55
|
+
->getObject();
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* Creates the function for construction a new instance of the SkVertices
|
|
60
|
+
* wrapper
|
|
61
|
+
* @param context platform context
|
|
62
|
+
* @return A function for creating a new host object wrapper for the
|
|
63
|
+
* SkVertices class
|
|
64
|
+
*/
|
|
65
|
+
static const jsi::HostFunctionType
|
|
66
|
+
createCtor(std::shared_ptr<RNSkPlatformContext> context) {
|
|
67
|
+
return JSI_HOST_FUNCTION_LAMBDA {
|
|
68
|
+
auto mode = static_cast<SkVertices::VertexMode>(arguments[0].getNumber());
|
|
69
|
+
std::vector<SkPoint> positions;
|
|
70
|
+
std::vector<SkPoint> texs;
|
|
71
|
+
std::vector<SkColor> colors;
|
|
72
|
+
std::vector<uint16_t> indices;
|
|
73
|
+
|
|
74
|
+
auto jsiPositions = arguments[1].asObject(runtime).asArray(runtime);
|
|
75
|
+
auto positionsSize = static_cast<int>(jsiPositions.size(runtime));
|
|
76
|
+
positions.reserve(positionsSize);
|
|
77
|
+
for (int i = 0; i < positionsSize; i++) {
|
|
78
|
+
std::shared_ptr<SkPoint> point = JsiSkPoint::fromValue(
|
|
79
|
+
runtime,
|
|
80
|
+
jsiPositions.getValueAtIndex(runtime, i).asObject(runtime));
|
|
81
|
+
positions.push_back(*point.get());
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
if (count >= 3 && !arguments[2].isNull() && !arguments[2].isUndefined()) {
|
|
85
|
+
auto jsiTexs = arguments[2].asObject(runtime).asArray(runtime);
|
|
86
|
+
auto texsSize = jsiTexs.size(runtime);
|
|
87
|
+
texs.reserve(texsSize);
|
|
88
|
+
for (int i = 0; i < texsSize; i++) {
|
|
89
|
+
auto point = JsiSkPoint::fromValue(
|
|
90
|
+
runtime, jsiTexs.getValueAtIndex(runtime, i).asObject(runtime));
|
|
91
|
+
texs.push_back(*point.get());
|
|
42
92
|
}
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
.asHostObject<JsiSkVertices>(runtime)
|
|
54
|
-
->getObject();
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
if (count >= 4 && !arguments[3].isNull() && !arguments[3].isUndefined()) {
|
|
96
|
+
auto jsiColors = arguments[3].asObject(runtime).asArray(runtime);
|
|
97
|
+
auto colorsSize = jsiColors.size(runtime);
|
|
98
|
+
colors.reserve(colorsSize);
|
|
99
|
+
for (int i = 0; i < colorsSize; i++) {
|
|
100
|
+
SkColor color = JsiSkColor::fromValue(
|
|
101
|
+
runtime, jsiColors.getValueAtIndex(runtime, i));
|
|
102
|
+
colors.push_back(color);
|
|
55
103
|
}
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
return JSI_HOST_FUNCTION_LAMBDA {
|
|
67
|
-
auto mode = static_cast<SkVertices::VertexMode>(arguments[0].getNumber());
|
|
68
|
-
std::vector<SkPoint> positions;
|
|
69
|
-
std::vector<SkPoint> texs;
|
|
70
|
-
std::vector<SkColor> colors;
|
|
71
|
-
std::vector<uint16_t> indices;
|
|
72
|
-
|
|
73
|
-
auto jsiPositions = arguments[1].asObject(runtime).asArray(runtime);
|
|
74
|
-
auto positionsSize = static_cast<int>(jsiPositions.size(runtime));
|
|
75
|
-
positions.reserve(positionsSize);
|
|
76
|
-
for (int i = 0; i < positionsSize; i++) {
|
|
77
|
-
std::shared_ptr<SkPoint> point = JsiSkPoint::fromValue(
|
|
78
|
-
runtime, jsiPositions.getValueAtIndex(runtime, i).asObject(runtime));
|
|
79
|
-
positions.push_back(*point.get());
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
if (count >= 3 && !arguments[2].isNull() && !arguments[2].isUndefined()) {
|
|
83
|
-
auto jsiTexs = arguments[2].asObject(runtime).asArray(runtime);
|
|
84
|
-
auto texsSize = jsiTexs.size(runtime);
|
|
85
|
-
texs.reserve(texsSize);
|
|
86
|
-
for (int i = 0; i < texsSize; i++) {
|
|
87
|
-
auto point = JsiSkPoint::fromValue(
|
|
88
|
-
runtime, jsiTexs.getValueAtIndex(runtime, i).asObject(runtime));
|
|
89
|
-
texs.push_back(*point.get());
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
if (count >= 4 && !arguments[3].isNull() && !arguments[3].isUndefined()) {
|
|
94
|
-
auto jsiColors = arguments[3].asObject(runtime).asArray(runtime);
|
|
95
|
-
auto colorsSize = jsiColors.size(runtime);
|
|
96
|
-
colors.reserve(colorsSize);
|
|
97
|
-
for (int i = 0; i < colorsSize; i++) {
|
|
98
|
-
SkColor color = JsiSkColor::fromValue(runtime, jsiColors.getValueAtIndex(runtime, i));
|
|
99
|
-
colors.push_back(color);
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
int indicesSize = 0;
|
|
104
|
-
if (count >= 5 && !arguments[4].isNull() && !arguments[4].isUndefined()) {
|
|
105
|
-
auto jsiIndices = arguments[4].asObject(runtime).asArray(runtime);
|
|
106
|
-
indicesSize = static_cast<int>(jsiIndices.size(runtime));
|
|
107
|
-
indices.reserve(indicesSize);
|
|
108
|
-
for (int i = 0; i < indicesSize; i++) {
|
|
109
|
-
uint16_t index = jsiIndices.getValueAtIndex(runtime, i).asNumber();
|
|
110
|
-
indices.push_back(index);
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
// TODO: this is the technic used in CanvasKit: https://github.com/google/skia/blob/main/modules/canvaskit/interface.js#L1216
|
|
114
|
-
// Note that the isVolatile parameter is unused when using MakeCopy()
|
|
115
|
-
// auto isVolatile = count >= 6 && !arguments[5].isNull() && !arguments[5].isUndefined() ? arguments[5].getBool() : false;
|
|
116
|
-
// auto flags = 0;
|
|
117
|
-
// // These flags are from SkVertices.h and should be kept in sync with those.
|
|
118
|
-
// if (texs.size() > 0) {
|
|
119
|
-
// flags |= (1 << 0);
|
|
120
|
-
// }
|
|
121
|
-
// if (colors.size() > 0) {
|
|
122
|
-
// flags |= (1 << 1);
|
|
123
|
-
// }
|
|
124
|
-
// if (!isVolatile) {
|
|
125
|
-
// flags |= (1 << 2);
|
|
126
|
-
// }
|
|
127
|
-
// auto builder = SkVertices::Builder(mode, positionsSize/2, indicesSize, flags);
|
|
128
|
-
// std::copy(positions.data(), positions.data() + positionsSize, builder.positions());
|
|
129
|
-
// if (builder.texCoords()) {
|
|
130
|
-
// std::copy(std::begin(texs), std::end(texs), builder.texCoords());
|
|
131
|
-
// }
|
|
132
|
-
// if (builder.colors()) {
|
|
133
|
-
// std::copy(std::begin(colors), std::end(colors), builder.colors());
|
|
134
|
-
// }
|
|
135
|
-
// if (builder.indices()) {
|
|
136
|
-
// std::copy(std::begin(indices), std::end(indices), builder.indices());
|
|
137
|
-
// }
|
|
138
|
-
// auto vertices = builder.detach();
|
|
139
|
-
auto vertices = SkVertices::MakeCopy(mode, positionsSize, positions.data(), texs.data(), colors.data(), indicesSize, indices.data());
|
|
140
|
-
return jsi::Object::createFromHostObject(
|
|
141
|
-
runtime, std::make_shared<JsiSkVertices>(context, std::move(vertices)));
|
|
142
|
-
};
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
int indicesSize = 0;
|
|
107
|
+
if (count >= 5 && !arguments[4].isNull() && !arguments[4].isUndefined()) {
|
|
108
|
+
auto jsiIndices = arguments[4].asObject(runtime).asArray(runtime);
|
|
109
|
+
indicesSize = static_cast<int>(jsiIndices.size(runtime));
|
|
110
|
+
indices.reserve(indicesSize);
|
|
111
|
+
for (int i = 0; i < indicesSize; i++) {
|
|
112
|
+
uint16_t index = jsiIndices.getValueAtIndex(runtime, i).asNumber();
|
|
113
|
+
indices.push_back(index);
|
|
143
114
|
}
|
|
115
|
+
}
|
|
116
|
+
// TODO: this is the technic used in CanvasKit:
|
|
117
|
+
// https://github.com/google/skia/blob/main/modules/canvaskit/interface.js#L1216
|
|
118
|
+
// Note that the isVolatile parameter is unused when using MakeCopy()
|
|
119
|
+
// auto isVolatile = count >= 6 && !arguments[5].isNull()
|
|
120
|
+
// && !arguments[5].isUndefined() ? arguments[5].getBool()
|
|
121
|
+
// : false; auto flags = 0;
|
|
122
|
+
// // These flags are from SkVertices.h and should be kept
|
|
123
|
+
// in sync with those. if (texs.size() > 0) {
|
|
124
|
+
// flags |= (1 << 0);
|
|
125
|
+
// }
|
|
126
|
+
// if (colors.size() > 0) {
|
|
127
|
+
// flags |= (1 << 1);
|
|
128
|
+
// }
|
|
129
|
+
// if (!isVolatile) {
|
|
130
|
+
// flags |= (1 << 2);
|
|
131
|
+
// }
|
|
132
|
+
// auto builder = SkVertices::Builder(mode,
|
|
133
|
+
// positionsSize/2, indicesSize, flags);
|
|
134
|
+
// std::copy(positions.data(), positions.data() +
|
|
135
|
+
// positionsSize, builder.positions()); if
|
|
136
|
+
// (builder.texCoords()) {
|
|
137
|
+
// std::copy(std::begin(texs), std::end(texs),
|
|
138
|
+
// builder.texCoords());
|
|
139
|
+
// }
|
|
140
|
+
// if (builder.colors()) {
|
|
141
|
+
// std::copy(std::begin(colors), std::end(colors),
|
|
142
|
+
// builder.colors());
|
|
143
|
+
// }
|
|
144
|
+
// if (builder.indices()) {
|
|
145
|
+
// std::copy(std::begin(indices), std::end(indices),
|
|
146
|
+
// builder.indices());
|
|
147
|
+
// }
|
|
148
|
+
// auto vertices = builder.detach();
|
|
149
|
+
auto vertices = SkVertices::MakeCopy(
|
|
150
|
+
mode, positionsSize, positions.data(), texs.data(), colors.data(),
|
|
151
|
+
indicesSize, indices.data());
|
|
152
|
+
return jsi::Object::createFromHostObject(
|
|
153
|
+
runtime,
|
|
154
|
+
std::make_shared<JsiSkVertices>(context, std::move(vertices)));
|
|
144
155
|
};
|
|
156
|
+
}
|
|
157
|
+
};
|
|
145
158
|
} // namespace RNSkia
|