@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.
Files changed (162) 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/types/NodeType.js +1 -0
  95. package/lib/commonjs/dom/types/NodeType.js.map +1 -1
  96. package/lib/commonjs/dom/types/SkDOM.js.map +1 -1
  97. package/lib/commonjs/renderer/HostComponents.js +3 -0
  98. package/lib/commonjs/renderer/HostComponents.js.map +1 -1
  99. package/lib/commonjs/renderer/components/Group.js +19 -4
  100. package/lib/commonjs/renderer/components/Group.js.map +1 -1
  101. package/lib/commonjs/renderer/components/Paint.js +6 -1
  102. package/lib/commonjs/renderer/components/Paint.js.map +1 -1
  103. package/lib/commonjs/views/SkiaPictureView.js +3 -2
  104. package/lib/commonjs/views/SkiaPictureView.js.map +1 -1
  105. package/lib/commonjs/views/SkiaView.js +6 -3
  106. package/lib/commonjs/views/SkiaView.js.map +1 -1
  107. package/lib/module/dom/nodes/JsiSkDOM.js +5 -0
  108. package/lib/module/dom/nodes/JsiSkDOM.js.map +1 -1
  109. package/lib/module/dom/nodes/LayerNode.js +32 -0
  110. package/lib/module/dom/nodes/LayerNode.js.map +1 -0
  111. package/lib/module/dom/types/NodeType.js +1 -0
  112. package/lib/module/dom/types/NodeType.js.map +1 -1
  113. package/lib/module/dom/types/SkDOM.js.map +1 -1
  114. package/lib/module/renderer/HostComponents.js +3 -0
  115. package/lib/module/renderer/HostComponents.js.map +1 -1
  116. package/lib/module/renderer/components/Group.js +16 -3
  117. package/lib/module/renderer/components/Group.js.map +1 -1
  118. package/lib/module/renderer/components/Paint.js +7 -1
  119. package/lib/module/renderer/components/Paint.js.map +1 -1
  120. package/lib/module/views/SkiaPictureView.js +2 -2
  121. package/lib/module/views/SkiaPictureView.js.map +1 -1
  122. package/lib/module/views/SkiaView.js +4 -2
  123. package/lib/module/views/SkiaView.js.map +1 -1
  124. package/lib/typescript/src/dom/nodes/JsiSkDOM.d.ts +2 -0
  125. package/lib/typescript/src/dom/nodes/LayerNode.d.ts +8 -0
  126. package/lib/typescript/src/dom/types/NodeType.d.ts +1 -0
  127. package/lib/typescript/src/dom/types/SkDOM.d.ts +1 -0
  128. package/lib/typescript/src/renderer/HostComponents.d.ts +2 -1
  129. package/lib/typescript/src/renderer/components/Group.d.ts +5 -1
  130. package/lib/typescript/src/views/SkiaView.d.ts +3 -0
  131. package/libs/android/arm64-v8a/libskottie.a +0 -0
  132. package/libs/android/arm64-v8a/libsksg.a +0 -0
  133. package/libs/android/armeabi-v7a/libskottie.a +0 -0
  134. package/libs/android/armeabi-v7a/libsksg.a +0 -0
  135. package/libs/android/x86/libskottie.a +0 -0
  136. package/libs/android/x86/libsksg.a +0 -0
  137. package/libs/android/x86_64/libskottie.a +0 -0
  138. package/libs/android/x86_64/libsksg.a +0 -0
  139. package/libs/ios/libskia.xcframework/ios-arm64_arm64e/libskia.a +0 -0
  140. package/libs/ios/libskia.xcframework/ios-arm64_arm64e_x86_64-simulator/libskia.a +0 -0
  141. package/libs/ios/libskottie.xcframework/Info.plist +42 -0
  142. package/libs/ios/libskottie.xcframework/ios-arm64_arm64e/libskottie.a +0 -0
  143. package/libs/ios/libskottie.xcframework/ios-arm64_arm64e_x86_64-simulator/libskottie.a +0 -0
  144. package/libs/ios/libsksg.xcframework/Info.plist +42 -0
  145. package/libs/ios/libsksg.xcframework/ios-arm64_arm64e/libsksg.a +0 -0
  146. package/libs/ios/libsksg.xcframework/ios-arm64_arm64e_x86_64-simulator/libsksg.a +0 -0
  147. package/libs/ios/libskshaper.xcframework/Info.plist +5 -5
  148. package/libs/ios/libskshaper.xcframework/ios-arm64_arm64e/libskshaper.a +0 -0
  149. package/libs/ios/libskshaper.xcframework/ios-arm64_arm64e_x86_64-simulator/libskshaper.a +0 -0
  150. package/libs/ios/libsvg.xcframework/Info.plist +5 -5
  151. package/libs/ios/libsvg.xcframework/ios-arm64_arm64e/libsvg.a +0 -0
  152. package/libs/ios/libsvg.xcframework/ios-arm64_arm64e_x86_64-simulator/libsvg.a +0 -0
  153. package/package.json +3 -1
  154. package/src/dom/nodes/JsiSkDOM.ts +5 -0
  155. package/src/dom/nodes/LayerNode.ts +35 -0
  156. package/src/dom/types/NodeType.ts +1 -0
  157. package/src/dom/types/SkDOM.ts +1 -0
  158. package/src/renderer/HostComponents.ts +3 -0
  159. package/src/renderer/components/Group.tsx +16 -3
  160. package/src/renderer/components/Paint.tsx +7 -1
  161. package/src/views/SkiaPictureView.tsx +2 -3
  162. 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
- using namespace facebook;
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
- runtime,
26
- std::string("Error in sksl:\n" + std::string(errorText.c_str()))
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, std::make_shared<JsiSkRuntimeEffect>(getContext(), std::move(effect)));
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(std::shared_ptr<RNSkPlatformContext> context)
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
- using namespace facebook;
21
+ namespace jsi = facebook::jsi;
21
22
 
22
- class JsiSkRuntimeShaderBuilder : public JsiSkWrappingSharedPtrHostObject<SkRuntimeShaderBuilder> {
23
- public:
24
-
25
- /**
26
- Constructor
27
- */
28
- JsiSkRuntimeShaderBuilder(std::shared_ptr<RNSkPlatformContext> context, const SkRuntimeShaderBuilder &rt)
29
- : JsiSkWrappingSharedPtrHostObject<SkRuntimeShaderBuilder>(
30
- std::move(context), std::make_shared<SkRuntimeShaderBuilder>(rt)){}
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
- JSI_HOST_FUNCTION(setUniform) {
33
- auto name = arguments[0].asString(runtime).utf8(runtime);
34
- auto jsiValue = arguments[1].asObject(runtime).asArray(runtime);
35
- auto size = jsiValue.size(runtime);
36
- std::vector<SkScalar> value;
37
- value.reserve(size);
38
- for (int i = 0; i < size; i++) {
39
- auto e = jsiValue.getValueAtIndex(runtime, i).asNumber();
40
- value.push_back(e);
41
- }
42
- getObject()->uniform(name.c_str()).set(value.data(), static_cast<int>(size));
43
- return jsi::Value::undefined();
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
- JSI_EXPORT_FUNCTIONS(
47
- JSI_EXPORT_FUNC(JsiSkRuntimeShaderBuilder, setUniform)
48
- )
50
+ JSI_EXPORT_FUNCTIONS(JSI_EXPORT_FUNC(JsiSkRuntimeShaderBuilder, setUniform))
49
51
 
50
- /**
51
- Returns the underlying object from a host object of this type
52
- */
53
- static std::shared_ptr<SkRuntimeShaderBuilder> fromValue(jsi::Runtime &runtime,
54
- const jsi::Value &obj) {
55
- const auto& object = obj.asObject(runtime);
56
- return object.asHostObject<JsiSkRuntimeShaderBuilder>(runtime)->getObject();
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
- Returns the jsi object from a host object of this type
62
- */
63
- static jsi::Value toValue(jsi::Runtime &runtime,
64
- std::shared_ptr<RNSkPlatformContext> context,
65
- const SkRuntimeShaderBuilder &rt) {
66
- return jsi::Object::createFromHostObject(
67
- runtime, std::make_shared<JsiSkRuntimeShaderBuilder>(std::move(context), rt));
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
- * Creates the function for construction a new instance of the SkRect
72
- * wrapper
73
- * @param context platform context
74
- * @return A function for creating a new host object wrapper for the SkRect
75
- * class
76
- */
77
- static const jsi::HostFunctionType
78
- createCtor(std::shared_ptr<RNSkPlatformContext> context) {
79
- return JSI_HOST_FUNCTION_LAMBDA {
80
- auto rt = JsiSkRuntimeEffect::fromValue(runtime, arguments[0]);
81
- auto rtb = SkRuntimeShaderBuilder(rt);
82
- // Return the newly constructed object
83
- return jsi::Object::createFromHostObject(
84
- runtime, std::make_shared<JsiSkRuntimeShaderBuilder>(std::move(context), std::move(rtb)));
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
@@ -16,12 +16,13 @@
16
16
 
17
17
  namespace RNSkia {
18
18
 
19
- using namespace facebook;
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), std::move(svgdom)){}
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
- using namespace facebook;
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), JSI_EXPORT_FUNC(JsiSkSVGFactory, MakeFromString))
43
-
44
- JsiSkSVGFactory(std::shared_ptr<RNSkPlatformContext> context)
45
- : JsiSkHostObject(std::move(context)) {}
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
@@ -17,13 +17,14 @@
17
17
 
18
18
  namespace RNSkia {
19
19
 
20
- using namespace facebook;
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), std::move(shader)) {}
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
- using namespace facebook;
23
+ namespace jsi = facebook::jsi;
24
24
 
25
- int getFlag(const jsi::Value* values, int i, size_t size) {
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* getLocalMatrix(jsi::Runtime &runtime, const jsi::Value* values, int i, size_t size) {
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* values, int i, size_t size) {
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& 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 = JsiSkColor::fromValue(runtime, jsiColors.getValueAtIndex(runtime, i));
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, const jsi::Value& value) {
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(pts, colors.data(), positions.data(),
90
- static_cast<int>(colors.size()), tileMode, flag, localMatrix);
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, std::make_shared<JsiSkShader>(getContext(), std::move(gradient)));
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(center, r, colors.data(),
107
- positions.data(), static_cast<int>(colors.size()), tileMode,
108
- flag, localMatrix);
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, std::make_shared<JsiSkShader>(getContext(), std::move(gradient)));
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()), tileMode, startAngle,
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, std::make_shared<JsiSkShader>(getContext(), std::move(gradient)));
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
- start, startRadius, end, endRadius, colors.data(), positions.data(),
150
- static_cast<int>(colors.size()), tileMode, flag, localMatrix);
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, std::make_shared<JsiSkShader>(getContext(), std::move(gradient)));
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, std::make_shared<JsiSkShader>(getContext(), std::move(gradient)));
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, std::make_shared<JsiSkShader>(getContext(), std::move(gradient)));
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, std::make_shared<JsiSkShader>(getContext(), std::move(gradient)));
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, std::make_shared<JsiSkShader>(getContext(), std::move(gradient)));
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
 
@@ -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
- using namespace facebook;
23
+ namespace jsi = facebook::jsi;
24
24
 
25
25
  class JsiSkSurface : public JsiSkWrappingSkPtrHostObject<SkSurface> {
26
26
  public:
27
- JsiSkSurface(std::shared_ptr<RNSkPlatformContext> context,
28
- sk_sp<SkSurface> surface)
29
- : JsiSkWrappingSkPtrHostObject<SkSurface>(std::move(context), std::move(surface)) {}
30
-
31
- // TODO: declare in JsiSkWrappingSkPtrHostObject via extra template parameter?
32
- JSI_PROPERTY_GET(__typename__) {
33
- return jsi::String::createFromUtf8(runtime, "Surface");
34
- }
35
-
36
- JSI_HOST_FUNCTION(getCanvas) {
37
- return jsi::Object::createFromHostObject(runtime,
38
- std::make_shared<JsiSkCanvas>(getContext(),
39
- getObject()->getCanvas()));
40
- }
41
-
42
- JSI_HOST_FUNCTION(makeImageSnapshot) {
43
- sk_sp<SkImage> image;
44
- if(count == 1) {
45
- auto rect = JsiSkRect::fromValue(runtime, arguments[0]);
46
- image = getObject()->makeImageSnapshot(SkIRect::MakeXYWH(rect->x(), rect->y(), rect->width(), rect->height()));
47
- } else {
48
- image = getObject()->makeImageSnapshot();
49
- }
50
- return jsi::Object::createFromHostObject(runtime, std::make_shared<JsiSkImage>(getContext(), std::move(image)));
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
- using namespace facebook;
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(runtime,
34
- std::make_shared<JsiSkSurface>(getContext(), std::move(surface)));
35
- }
36
-
37
- JSI_EXPORT_FUNCTIONS(JSI_EXPORT_FUNC(JsiSkSurfaceFactory, Make))
38
-
39
- JsiSkSurfaceFactory(std::shared_ptr<RNSkPlatformContext> context)
40
- : JsiSkHostObject(std::move(context)) {}
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