@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.
Files changed (167) hide show
  1. package/android/cpp/jni/JniLoad.cpp +5 -5
  2. package/android/cpp/jni/JniPlatformContext.cpp +107 -119
  3. package/android/cpp/jni/JniSkiaManager.cpp +18 -20
  4. package/android/cpp/jni/include/JniPlatformContext.h +41 -45
  5. package/android/cpp/jni/include/JniSkiaBaseView.h +52 -55
  6. package/android/cpp/jni/include/JniSkiaDrawView.h +72 -77
  7. package/android/cpp/jni/include/JniSkiaManager.h +51 -53
  8. package/android/cpp/jni/include/JniSkiaPictureView.h +74 -78
  9. package/android/cpp/rnskia-android/RNSkAndroidPlatformContext.h +36 -45
  10. package/android/cpp/rnskia-android/RNSkAndroidView.h +87 -92
  11. package/android/cpp/rnskia-android/RNSkOpenGLCanvasProvider.cpp +62 -65
  12. package/android/cpp/rnskia-android/RNSkOpenGLCanvasProvider.h +20 -17
  13. package/android/cpp/rnskia-android/SkiaOpenGLRenderer.cpp +257 -313
  14. package/android/cpp/rnskia-android/SkiaOpenGLRenderer.h +107 -110
  15. package/cpp/api/JsiSkApi.h +66 -62
  16. package/cpp/api/JsiSkCanvas.h +38 -30
  17. package/cpp/api/JsiSkColor.h +58 -56
  18. package/cpp/api/JsiSkColorFilter.h +5 -3
  19. package/cpp/api/JsiSkColorFilterFactory.h +23 -21
  20. package/cpp/api/JsiSkContourMeasure.h +74 -85
  21. package/cpp/api/JsiSkContourMeasureIter.h +68 -75
  22. package/cpp/api/JsiSkData.h +16 -22
  23. package/cpp/api/JsiSkDataFactory.h +86 -79
  24. package/cpp/api/JsiSkFont.h +286 -311
  25. package/cpp/api/JsiSkHostObjects.h +15 -16
  26. package/cpp/api/JsiSkImage.h +107 -103
  27. package/cpp/api/JsiSkImageFactory.h +34 -36
  28. package/cpp/api/JsiSkImageFilter.h +5 -3
  29. package/cpp/api/JsiSkImageFilterFactory.h +71 -68
  30. package/cpp/api/JsiSkImageInfo.h +41 -38
  31. package/cpp/api/JsiSkMaskFilter.h +5 -3
  32. package/cpp/api/JsiSkMaskFilterFactory.h +2 -3
  33. package/cpp/api/JsiSkMatrix.h +26 -36
  34. package/cpp/api/JsiSkPaint.h +20 -13
  35. package/cpp/api/JsiSkPath.h +70 -85
  36. package/cpp/api/JsiSkPathEffect.h +5 -3
  37. package/cpp/api/JsiSkPathEffectFactory.h +33 -28
  38. package/cpp/api/JsiSkPathFactory.h +68 -67
  39. package/cpp/api/JsiSkPicture.h +28 -22
  40. package/cpp/api/JsiSkPictureFactory.h +13 -12
  41. package/cpp/api/JsiSkPictureRecorder.h +21 -19
  42. package/cpp/api/JsiSkPoint.h +6 -8
  43. package/cpp/api/JsiSkRRect.h +11 -7
  44. package/cpp/api/JsiSkRSXform.h +82 -85
  45. package/cpp/api/JsiSkRect.h +9 -9
  46. package/cpp/api/JsiSkRuntimeEffect.h +182 -186
  47. package/cpp/api/JsiSkRuntimeEffectFactory.h +10 -11
  48. package/cpp/api/JsiSkRuntimeShaderBuilder.h +64 -61
  49. package/cpp/api/JsiSkSVG.h +4 -5
  50. package/cpp/api/JsiSkSVGFactory.h +28 -27
  51. package/cpp/api/JsiSkShader.h +3 -2
  52. package/cpp/api/JsiSkShaderFactory.h +37 -25
  53. package/cpp/api/JsiSkSurface.h +44 -40
  54. package/cpp/api/JsiSkSurfaceFactory.h +22 -22
  55. package/cpp/api/JsiSkTextBlob.h +28 -31
  56. package/cpp/api/JsiSkTextBlobFactory.h +88 -87
  57. package/cpp/api/JsiSkTypeface.h +6 -5
  58. package/cpp/api/JsiSkTypefaceFactory.h +22 -21
  59. package/cpp/api/JsiSkVertices.h +137 -124
  60. package/cpp/api/third_party/CSSColorParser.cpp +161 -174
  61. package/cpp/api/third_party/CSSColorParser.h +172 -96
  62. package/cpp/jsi/JsiHostObject.cpp +11 -9
  63. package/cpp/jsi/JsiHostObject.h +31 -24
  64. package/cpp/jsi/JsiSimpleValueWrapper.h +74 -83
  65. package/cpp/jsi/JsiValueWrapper.h +52 -54
  66. package/cpp/rnskia/RNSkAnimation.h +26 -29
  67. package/cpp/rnskia/RNSkDispatchQueue.cpp +50 -61
  68. package/cpp/rnskia/RNSkDispatchQueue.h +3 -1
  69. package/cpp/rnskia/RNSkInfoParameter.h +12 -12
  70. package/cpp/rnskia/RNSkJsView.cpp +82 -81
  71. package/cpp/rnskia/RNSkJsView.h +45 -41
  72. package/cpp/rnskia/RNSkJsiViewApi.h +99 -89
  73. package/cpp/rnskia/RNSkManager.cpp +8 -7
  74. package/cpp/rnskia/RNSkManager.h +8 -6
  75. package/cpp/rnskia/RNSkPictureView.h +44 -37
  76. package/cpp/rnskia/RNSkPlatformContext.h +39 -28
  77. package/cpp/rnskia/RNSkValueApi.h +33 -34
  78. package/cpp/rnskia/RNSkView.h +108 -93
  79. package/cpp/rnskia/values/RNSkClockValue.h +63 -64
  80. package/cpp/rnskia/values/RNSkComputedValue.h +32 -30
  81. package/cpp/rnskia/values/RNSkReadonlyValue.h +60 -59
  82. package/cpp/rnskia/values/RNSkValue.h +38 -40
  83. package/cpp/utils/RNSkLog.h +9 -7
  84. package/cpp/utils/RNSkMeasureTime.h +7 -7
  85. package/cpp/utils/RNSkTimingInfo.h +27 -24
  86. package/ios/RNSkia-iOS/RNSkMetalCanvasProvider.h +8 -9
  87. package/ios/RNSkia-iOS/RNSkiOSPlatformContext.h +24 -23
  88. package/ios/RNSkia-iOS/RNSkiOSView.h +16 -13
  89. package/ios/RNSkia-iOS/SkiaUIView.h +9 -8
  90. package/lib/commonjs/dom/nodes/JsiSkDOM.js +6 -0
  91. package/lib/commonjs/dom/nodes/JsiSkDOM.js.map +1 -1
  92. package/lib/commonjs/dom/nodes/LayerNode.js +43 -0
  93. package/lib/commonjs/dom/nodes/LayerNode.js.map +1 -0
  94. package/lib/commonjs/dom/nodes/RenderNode.js +1 -1
  95. package/lib/commonjs/dom/nodes/RenderNode.js.map +1 -1
  96. package/lib/commonjs/dom/types/NodeType.js +1 -0
  97. package/lib/commonjs/dom/types/NodeType.js.map +1 -1
  98. package/lib/commonjs/dom/types/SkDOM.js.map +1 -1
  99. package/lib/commonjs/renderer/HostComponents.js +3 -0
  100. package/lib/commonjs/renderer/HostComponents.js.map +1 -1
  101. package/lib/commonjs/renderer/components/Group.js +19 -4
  102. package/lib/commonjs/renderer/components/Group.js.map +1 -1
  103. package/lib/commonjs/renderer/components/Paint.js +6 -1
  104. package/lib/commonjs/renderer/components/Paint.js.map +1 -1
  105. package/lib/commonjs/views/SkiaPictureView.js +3 -2
  106. package/lib/commonjs/views/SkiaPictureView.js.map +1 -1
  107. package/lib/commonjs/views/SkiaView.js +6 -3
  108. package/lib/commonjs/views/SkiaView.js.map +1 -1
  109. package/lib/module/dom/nodes/JsiSkDOM.js +5 -0
  110. package/lib/module/dom/nodes/JsiSkDOM.js.map +1 -1
  111. package/lib/module/dom/nodes/LayerNode.js +32 -0
  112. package/lib/module/dom/nodes/LayerNode.js.map +1 -0
  113. package/lib/module/dom/nodes/RenderNode.js +1 -1
  114. package/lib/module/dom/nodes/RenderNode.js.map +1 -1
  115. package/lib/module/dom/types/NodeType.js +1 -0
  116. package/lib/module/dom/types/NodeType.js.map +1 -1
  117. package/lib/module/dom/types/SkDOM.js.map +1 -1
  118. package/lib/module/renderer/HostComponents.js +3 -0
  119. package/lib/module/renderer/HostComponents.js.map +1 -1
  120. package/lib/module/renderer/components/Group.js +16 -3
  121. package/lib/module/renderer/components/Group.js.map +1 -1
  122. package/lib/module/renderer/components/Paint.js +7 -1
  123. package/lib/module/renderer/components/Paint.js.map +1 -1
  124. package/lib/module/views/SkiaPictureView.js +2 -2
  125. package/lib/module/views/SkiaPictureView.js.map +1 -1
  126. package/lib/module/views/SkiaView.js +4 -2
  127. package/lib/module/views/SkiaView.js.map +1 -1
  128. package/lib/typescript/src/dom/nodes/JsiSkDOM.d.ts +2 -0
  129. package/lib/typescript/src/dom/nodes/LayerNode.d.ts +8 -0
  130. package/lib/typescript/src/dom/types/NodeType.d.ts +1 -0
  131. package/lib/typescript/src/dom/types/SkDOM.d.ts +1 -0
  132. package/lib/typescript/src/renderer/HostComponents.d.ts +2 -1
  133. package/lib/typescript/src/renderer/components/Group.d.ts +5 -1
  134. package/lib/typescript/src/views/SkiaView.d.ts +3 -0
  135. package/libs/android/arm64-v8a/libskottie.a +0 -0
  136. package/libs/android/arm64-v8a/libsksg.a +0 -0
  137. package/libs/android/armeabi-v7a/libskottie.a +0 -0
  138. package/libs/android/armeabi-v7a/libsksg.a +0 -0
  139. package/libs/android/x86/libskottie.a +0 -0
  140. package/libs/android/x86/libsksg.a +0 -0
  141. package/libs/android/x86_64/libskottie.a +0 -0
  142. package/libs/android/x86_64/libsksg.a +0 -0
  143. package/libs/ios/libskia.xcframework/ios-arm64_arm64e/libskia.a +0 -0
  144. package/libs/ios/libskia.xcframework/ios-arm64_arm64e_x86_64-simulator/libskia.a +0 -0
  145. package/libs/ios/libskottie.xcframework/Info.plist +42 -0
  146. package/libs/ios/libskottie.xcframework/ios-arm64_arm64e/libskottie.a +0 -0
  147. package/libs/ios/libskottie.xcframework/ios-arm64_arm64e_x86_64-simulator/libskottie.a +0 -0
  148. package/libs/ios/libsksg.xcframework/Info.plist +42 -0
  149. package/libs/ios/libsksg.xcframework/ios-arm64_arm64e/libsksg.a +0 -0
  150. package/libs/ios/libsksg.xcframework/ios-arm64_arm64e_x86_64-simulator/libsksg.a +0 -0
  151. package/libs/ios/libskshaper.xcframework/Info.plist +5 -5
  152. package/libs/ios/libskshaper.xcframework/ios-arm64_arm64e/libskshaper.a +0 -0
  153. package/libs/ios/libskshaper.xcframework/ios-arm64_arm64e_x86_64-simulator/libskshaper.a +0 -0
  154. package/libs/ios/libsvg.xcframework/Info.plist +5 -5
  155. package/libs/ios/libsvg.xcframework/ios-arm64_arm64e/libsvg.a +0 -0
  156. package/libs/ios/libsvg.xcframework/ios-arm64_arm64e_x86_64-simulator/libsvg.a +0 -0
  157. package/package.json +3 -1
  158. package/src/dom/nodes/JsiSkDOM.ts +5 -0
  159. package/src/dom/nodes/LayerNode.ts +35 -0
  160. package/src/dom/nodes/RenderNode.ts +4 -3
  161. package/src/dom/types/NodeType.ts +1 -0
  162. package/src/dom/types/SkDOM.ts +1 -0
  163. package/src/renderer/HostComponents.ts +3 -0
  164. package/src/renderer/components/Group.tsx +16 -3
  165. package/src/renderer/components/Paint.tsx +7 -1
  166. package/src/views/SkiaPictureView.tsx +2 -3
  167. package/src/views/SkiaView.tsx +2 -2
@@ -16,35 +16,32 @@
16
16
 
17
17
  namespace RNSkia {
18
18
 
19
- using namespace facebook;
20
-
21
- class JsiSkTextBlob : public JsiSkWrappingSkPtrHostObject<SkTextBlob> {
22
- public:
23
- JsiSkTextBlob(
24
- std::shared_ptr<RNSkPlatformContext> context,
25
- sk_sp<SkTextBlob> shader
26
- ) : JsiSkWrappingSkPtrHostObject<SkTextBlob>(std::move(context), 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(
35
- JSI_EXPORT_PROP_GET(JsiSkTextBlob, __typename__),
36
- )
37
-
38
- /**
39
- Returns the underlying object from a host object of this type
40
- */
41
- static sk_sp<SkTextBlob> fromValue(jsi::Runtime &runtime,
42
- const jsi::Value &obj) {
43
- return obj.asObject(runtime)
44
- .asHostObject<JsiSkTextBlob>(runtime)
45
- ->getObject();
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 "JsiSkFont.h"
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
- using namespace facebook;
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
-
37
- JSI_HOST_FUNCTION(MakeFromGlyphs) {
38
- auto jsiGlyphs = arguments[0].asObject(runtime).asArray(runtime);
39
- auto font = JsiSkFont::fromValue(runtime, arguments[1]);
40
- int bytesPerGlyph = 2;
41
- std::vector<SkGlyphID> glyphs;
42
- int glyphsSize = static_cast<int>(jsiGlyphs.size(runtime));
43
- glyphs.reserve(glyphsSize);
44
- for (int i = 0; i < glyphsSize; i++) {
45
- glyphs.push_back(jsiGlyphs.getValueAtIndex(runtime, i).asNumber());
46
- }
47
- auto textBlob = SkTextBlob::MakeFromText(glyphs.data(), glyphs.size() * bytesPerGlyph, *font, SkTextEncoding::kGlyphID);
48
- return jsi::Object::createFromHostObject(
49
- runtime,
50
- std::make_shared<JsiSkTextBlob>(getContext(), std::move(textBlob))
51
- );
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(runtime, jsiRsxforms.getValueAtIndex(runtime, i));
63
- rsxforms.push_back(*rsxform);
64
- }
65
- auto textBlob = SkTextBlob::MakeFromRSXform(str.c_str(), str.length(), rsxforms.data(), *font);
66
- return jsi::Object::createFromHostObject(
67
- runtime,
68
- std::make_shared<JsiSkTextBlob>(getContext(), std::move(textBlob))
69
- );
70
- }
71
-
72
- JSI_HOST_FUNCTION(MakeFromRSXformGlyphs) {
73
- auto jsiGlyphs = arguments[0].asObject(runtime).asArray(runtime);
74
- auto jsiRsxforms = arguments[1].asObject(runtime).asArray(runtime);
75
- auto font = JsiSkFont::fromValue(runtime, arguments[2]);
76
- int bytesPerGlyph = 2;
77
- std::vector<SkGlyphID> glyphs;
78
- int glyphsSize = static_cast<int>(jsiGlyphs.size(runtime));
79
- glyphs.reserve(glyphsSize);
80
- for (int i = 0; i < glyphsSize; i++) {
81
- glyphs.push_back(jsiGlyphs.getValueAtIndex(runtime, i).asNumber());
82
- }
83
- std::vector<SkRSXform> rsxforms;
84
- int rsxformsSize = static_cast<int>(jsiRsxforms.size(runtime));
85
- rsxforms.reserve(rsxformsSize);
86
- for (int i = 0; i < rsxformsSize; i++) {
87
- auto rsxform = JsiSkRSXform::fromValue(runtime, jsiRsxforms.getValueAtIndex(runtime, i));
88
- rsxforms.push_back(*rsxform);
89
- }
90
- auto textBlob = SkTextBlob::MakeFromRSXform(glyphs.data(), glyphs.size() * bytesPerGlyph, rsxforms.data(), *font, SkTextEncoding::kGlyphID);
91
- return jsi::Object::createFromHostObject(
92
- runtime,
93
- std::make_shared<JsiSkTextBlob>(getContext(), std::move(textBlob))
94
- );
95
- }
96
-
97
-
98
- JSI_EXPORT_FUNCTIONS(
99
- JSI_EXPORT_FUNC(JsiSkTextBlobFactory, MakeFromText),
100
- JSI_EXPORT_FUNC(JsiSkTextBlobFactory, MakeFromGlyphs),
101
- JSI_EXPORT_FUNC(JsiSkTextBlobFactory, MakeFromRSXform),
102
- JSI_EXPORT_FUNC(JsiSkTextBlobFactory, MakeFromRSXformGlyphs),
103
- )
104
-
105
- JsiSkTextBlobFactory(std::shared_ptr<RNSkPlatformContext> context)
106
- : JsiSkHostObject(std::move(context)) {}
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
@@ -18,7 +18,7 @@
18
18
 
19
19
  namespace RNSkia {
20
20
 
21
- using namespace facebook;
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
- std::shared_ptr<RNSkPlatformContext> context,
51
- sk_sp<SkTypeface> tf) {
50
+ std::shared_ptr<RNSkPlatformContext> context,
51
+ sk_sp<SkTypeface> tf) {
52
52
  return jsi::Object::createFromHostObject(
53
- runtime, std::make_shared<JsiSkTypeface>(std::move(context), std::move(tf)));
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
- using namespace facebook;
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, MakeFreeTypeFaceFromData))
29
-
30
- JsiSkTypefaceFactory(std::shared_ptr<RNSkPlatformContext> context)
31
- : JsiSkHostObject(std::move(context)) {}
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
@@ -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 <jsi/jsi.h>
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
- using namespace facebook;
19
-
20
- class JsiSkVertices : public JsiSkWrappingSkPtrHostObject<SkVertices> {
21
- public:
22
-
23
- JsiSkVertices(std::shared_ptr<RNSkPlatformContext> context,
24
- sk_sp<SkVertices> vertices)
25
- : JsiSkWrappingSkPtrHostObject<SkVertices>(std::move(context), std::move(vertices)) {}
26
-
27
- // TODO: declare in JsiSkWrappingSkPtrHostObject via extra template parameter?
28
- JSI_PROPERTY_GET(__typename__) {
29
- return jsi::String::createFromUtf8(runtime, "Vertices");
30
- }
31
-
32
- JSI_EXPORT_PROPERTY_GETTERS(JSI_EXPORT_PROP_GET(JsiSkVertices, __typename__))
33
-
34
- JSI_HOST_FUNCTION(bounds) {
35
- const auto& result = getObject()->bounds();
36
- return jsi::Object::createFromHostObject(
37
- runtime, std::make_shared<JsiSkRect>(getContext(), result));
38
- }
39
-
40
- JSI_HOST_FUNCTION(uniqueID) {
41
- return static_cast<double>(getObject()->uniqueID());
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
- JSI_EXPORT_FUNCTIONS(JSI_EXPORT_FUNC(JsiSkVertices, bounds),
45
- JSI_EXPORT_FUNC(JsiSkVertices, uniqueID), )
46
-
47
- /**
48
- Returns the underlying object from a host object of this type
49
- */
50
- static sk_sp<SkVertices> fromValue(jsi::Runtime &runtime,
51
- const jsi::Value &obj) {
52
- return obj.asObject(runtime)
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
- * Creates the function for construction a new instance of the SkVertices
59
- * wrapper
60
- * @param context platform context
61
- * @return A function for creating a new host object wrapper for the SkVertices
62
- * class
63
- */
64
- static const jsi::HostFunctionType
65
- createCtor(std::shared_ptr<RNSkPlatformContext> context) {
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