@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.
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,90 +16,87 @@
16
16
 
17
17
  namespace RNSkia {
18
18
 
19
- using namespace facebook;
20
-
21
- class JsiSkRSXform : public JsiSkWrappingSharedPtrHostObject<SkRSXform> {
22
- public:
23
- JsiSkRSXform(std::shared_ptr<RNSkPlatformContext> context, const SkRSXform &rsxform)
24
- : JsiSkWrappingSharedPtrHostObject<SkRSXform>(
25
- std::move(context), std::make_shared<SkRSXform>(rsxform)){}
26
-
27
- // TODO: declare in JsiSkWrappingSkPtrHostObject via extra template parameter?
28
-
29
- JSI_PROPERTY_GET(__typename__) {
30
- return jsi::String::createFromUtf8(runtime, "RSXform");
31
- }
32
-
33
- JSI_PROPERTY_GET(scos) {
34
- return jsi::Value(SkScalarToDouble(getObject()->fSCos));
35
- }
36
- JSI_PROPERTY_GET(ssin) {
37
- return jsi::Value(SkScalarToDouble(getObject()->fSSin));
38
- }
39
- JSI_PROPERTY_GET(tx) {
40
- return jsi::Value(SkScalarToDouble(getObject()->fTx));
41
- }
42
- JSI_PROPERTY_GET(ty) {
43
- return jsi::Value(SkScalarToDouble(getObject()->fTy));
44
- }
45
-
46
- JSI_EXPORT_PROPERTY_GETTERS(
47
- JSI_EXPORT_PROP_GET(JsiSkRSXform, __typename__),
48
- JSI_EXPORT_PROP_GET(JsiSkRSXform, scos),
49
- JSI_EXPORT_PROP_GET(JsiSkRSXform, ssin),
50
- JSI_EXPORT_PROP_GET(JsiSkRSXform, tx),
51
- JSI_EXPORT_PROP_GET(JsiSkRSXform, ty),
52
- )
53
-
54
- /**
55
- Returns the underlying object from a host object of this type
56
- */
57
- static std::shared_ptr<SkRSXform> fromValue(jsi::Runtime &runtime,
58
- const jsi::Value &obj) {
59
- const auto& object = obj.asObject(runtime);
60
- if (object.isHostObject(runtime)) {
61
- return object
62
- .asHostObject<JsiSkRSXform>(runtime)
63
- ->getObject();
64
- } else {
65
- auto scos = object.getArray(runtime).getValueAtIndex(runtime, 0).asNumber();
66
- auto ssin = object.getArray(runtime).getValueAtIndex(runtime, 1).asNumber();
67
- auto tx = object.getArray(runtime).getValueAtIndex(runtime, 2).asNumber();
68
- auto ty = object.getArray(runtime).getValueAtIndex(runtime, 3).asNumber();
69
- return std::make_shared<SkRSXform>(SkRSXform::Make(scos, ssin, tx, ty));
70
- }
71
- }
72
-
73
- /**
74
- Returns the jsi object from a host object of this type
75
- */
76
- static jsi::Value toValue(jsi::Runtime &runtime,
77
- std::shared_ptr<RNSkPlatformContext> context,
78
- const SkRSXform &rsxform) {
79
- return jsi::Object::createFromHostObject(
80
- runtime, std::make_shared<JsiSkRSXform>(std::move(context), rsxform));
81
- }
82
-
83
- /**
84
- * Creates the function for construction a new instance of the SkRSXform
85
- * wrapper
86
- * @param context platform context
87
- * @return A function for creating a new host object wrapper for the SkRSXform
88
- * class
89
- */
90
- static const jsi::HostFunctionType
91
- createCtor(std::shared_ptr<RNSkPlatformContext> context) {
92
- return JSI_HOST_FUNCTION_LAMBDA {
93
- auto rsxform = SkRSXform::Make(
94
- arguments[0].asNumber(),
95
- arguments[1].asNumber(),
96
- arguments[2].asNumber(),
97
- arguments[3].asNumber()
98
- );
99
- // Return the newly constructed object
100
- return jsi::Object::createFromHostObject(
101
- runtime, std::make_shared<JsiSkRSXform>(std::move(context), std::move(rsxform)));
102
- };
103
- }
19
+ namespace jsi = facebook::jsi;
20
+
21
+ class JsiSkRSXform : public JsiSkWrappingSharedPtrHostObject<SkRSXform> {
22
+ public:
23
+ JsiSkRSXform(std::shared_ptr<RNSkPlatformContext> context,
24
+ const SkRSXform &rsxform)
25
+ : JsiSkWrappingSharedPtrHostObject<SkRSXform>(
26
+ std::move(context), std::make_shared<SkRSXform>(rsxform)) {}
27
+
28
+ // TODO: declare in JsiSkWrappingSkPtrHostObject via extra template parameter?
29
+
30
+ JSI_PROPERTY_GET(__typename__) {
31
+ return jsi::String::createFromUtf8(runtime, "RSXform");
32
+ }
33
+
34
+ JSI_PROPERTY_GET(scos) {
35
+ return jsi::Value(SkScalarToDouble(getObject()->fSCos));
36
+ }
37
+ JSI_PROPERTY_GET(ssin) {
38
+ return jsi::Value(SkScalarToDouble(getObject()->fSSin));
39
+ }
40
+ JSI_PROPERTY_GET(tx) {
41
+ return jsi::Value(SkScalarToDouble(getObject()->fTx));
42
+ }
43
+ JSI_PROPERTY_GET(ty) {
44
+ return jsi::Value(SkScalarToDouble(getObject()->fTy));
45
+ }
46
+
47
+ JSI_EXPORT_PROPERTY_GETTERS(JSI_EXPORT_PROP_GET(JsiSkRSXform, __typename__),
48
+ JSI_EXPORT_PROP_GET(JsiSkRSXform, scos),
49
+ JSI_EXPORT_PROP_GET(JsiSkRSXform, ssin),
50
+ JSI_EXPORT_PROP_GET(JsiSkRSXform, tx),
51
+ JSI_EXPORT_PROP_GET(JsiSkRSXform, ty), )
52
+
53
+ /**
54
+ Returns the underlying object from a host object of this type
55
+ */
56
+ static std::shared_ptr<SkRSXform> fromValue(jsi::Runtime &runtime,
57
+ const jsi::Value &obj) {
58
+ const auto &object = obj.asObject(runtime);
59
+ if (object.isHostObject(runtime)) {
60
+ return object.asHostObject<JsiSkRSXform>(runtime)->getObject();
61
+ } else {
62
+ auto scos =
63
+ object.getArray(runtime).getValueAtIndex(runtime, 0).asNumber();
64
+ auto ssin =
65
+ object.getArray(runtime).getValueAtIndex(runtime, 1).asNumber();
66
+ auto tx = object.getArray(runtime).getValueAtIndex(runtime, 2).asNumber();
67
+ auto ty = object.getArray(runtime).getValueAtIndex(runtime, 3).asNumber();
68
+ return std::make_shared<SkRSXform>(SkRSXform::Make(scos, ssin, tx, ty));
69
+ }
70
+ }
71
+
72
+ /**
73
+ Returns the jsi object from a host object of this type
74
+ */
75
+ static jsi::Value toValue(jsi::Runtime &runtime,
76
+ std::shared_ptr<RNSkPlatformContext> context,
77
+ const SkRSXform &rsxform) {
78
+ return jsi::Object::createFromHostObject(
79
+ runtime, std::make_shared<JsiSkRSXform>(std::move(context), rsxform));
80
+ }
81
+
82
+ /**
83
+ * Creates the function for construction a new instance of the SkRSXform
84
+ * wrapper
85
+ * @param context platform context
86
+ * @return A function for creating a new host object wrapper for the SkRSXform
87
+ * class
88
+ */
89
+ static const jsi::HostFunctionType
90
+ createCtor(std::shared_ptr<RNSkPlatformContext> context) {
91
+ return JSI_HOST_FUNCTION_LAMBDA {
92
+ auto rsxform =
93
+ SkRSXform::Make(arguments[0].asNumber(), arguments[1].asNumber(),
94
+ arguments[2].asNumber(), arguments[3].asNumber());
95
+ // Return the newly constructed object
96
+ return jsi::Object::createFromHostObject(
97
+ runtime, std::make_shared<JsiSkRSXform>(std::move(context),
98
+ std::move(rsxform)));
104
99
  };
100
+ }
101
+ };
105
102
  } // namespace RNSkia
@@ -16,7 +16,7 @@
16
16
 
17
17
  namespace RNSkia {
18
18
 
19
- using namespace facebook;
19
+ namespace jsi = facebook::jsi;
20
20
 
21
21
  class JsiSkRect : public JsiSkWrappingSharedPtrHostObject<SkRect> {
22
22
  public:
@@ -58,18 +58,16 @@ public:
58
58
  */
59
59
  JsiSkRect(std::shared_ptr<RNSkPlatformContext> context, const SkRect &rect)
60
60
  : JsiSkWrappingSharedPtrHostObject<SkRect>(
61
- std::move(context), std::make_shared<SkRect>(rect)){}
61
+ std::move(context), std::make_shared<SkRect>(rect)) {}
62
62
 
63
63
  /**
64
64
  Returns the underlying object from a host object of this type
65
65
  */
66
66
  static std::shared_ptr<SkRect> fromValue(jsi::Runtime &runtime,
67
67
  const jsi::Value &obj) {
68
- const auto& object = obj.asObject(runtime);
68
+ const auto &object = obj.asObject(runtime);
69
69
  if (object.isHostObject(runtime)) {
70
- return object
71
- .asHostObject<JsiSkRect>(runtime)
72
- ->getObject();
70
+ return object.asHostObject<JsiSkRect>(runtime)->getObject();
73
71
  } else {
74
72
  auto x = object.getProperty(runtime, "x").asNumber();
75
73
  auto y = object.getProperty(runtime, "y").asNumber();
@@ -90,9 +88,10 @@ public:
90
88
  }
91
89
  static jsi::Value toValue(jsi::Runtime &runtime,
92
90
  std::shared_ptr<RNSkPlatformContext> context,
93
- SkRect&& rect) {
91
+ SkRect &&rect) {
94
92
  return jsi::Object::createFromHostObject(
95
- runtime, std::make_shared<JsiSkRect>(std::move(context), std::move(rect)));
93
+ runtime,
94
+ std::make_shared<JsiSkRect>(std::move(context), std::move(rect)));
96
95
  }
97
96
 
98
97
  /**
@@ -112,7 +111,8 @@ public:
112
111
 
113
112
  // Return the newly constructed object
114
113
  return jsi::Object::createFromHostObject(
115
- runtime, std::make_shared<JsiSkRect>(std::move(context), std::move(rect)));
114
+ runtime,
115
+ std::make_shared<JsiSkRect>(std::move(context), std::move(rect)));
116
116
  };
117
117
  }
118
118
  };
@@ -6,8 +6,8 @@
6
6
  #include <vector>
7
7
 
8
8
  #include <JsiSkHostObjects.h>
9
- #include <JsiSkShader.h>
10
9
  #include <JsiSkMatrix.h>
10
+ #include <JsiSkShader.h>
11
11
 
12
12
  #include <jsi/jsi.h>
13
13
 
@@ -18,205 +18,201 @@
18
18
 
19
19
  #pragma clang diagnostic pop
20
20
 
21
- namespace RNSkia
22
- {
23
-
24
- using namespace facebook;
25
-
26
- struct RuntimeEffectUniform
27
- {
28
- int columns;
29
- int rows;
30
- int slot; // the index into the uniforms array that this uniform begins.
31
- bool isInteger;
32
- };
33
-
34
- class JsiSkRuntimeEffect
35
- : public JsiSkWrappingSkPtrHostObject<SkRuntimeEffect>
36
- {
37
- public:
38
-
39
- static sk_sp<SkRuntimeEffect> fromValue(jsi::Runtime &runtime, const jsi::Value &obj) {
40
- const auto& object = obj.asObject(runtime);
41
- return object.asHostObject<JsiSkRuntimeEffect>(runtime)->getObject();
21
+ namespace RNSkia {
22
+
23
+ namespace jsi = facebook::jsi;
24
+
25
+ struct RuntimeEffectUniform {
26
+ int columns;
27
+ int rows;
28
+ int slot; // the index into the uniforms array that this uniform begins.
29
+ bool isInteger;
30
+ };
31
+
32
+ class JsiSkRuntimeEffect
33
+ : public JsiSkWrappingSkPtrHostObject<SkRuntimeEffect> {
34
+ public:
35
+ static sk_sp<SkRuntimeEffect> fromValue(jsi::Runtime &runtime,
36
+ const jsi::Value &obj) {
37
+ const auto &object = obj.asObject(runtime);
38
+ return object.asHostObject<JsiSkRuntimeEffect>(runtime)->getObject();
39
+ }
40
+
41
+ JSI_HOST_FUNCTION(makeShader) {
42
+ auto uniforms = castUniforms(runtime, arguments[0]);
43
+
44
+ auto matrix =
45
+ count >= 2 && !arguments[1].isUndefined() && !arguments[1].isNull()
46
+ ? JsiSkMatrix::fromValue(runtime, arguments[1]).get()
47
+ : nullptr;
48
+
49
+ // Create and return shader as host object
50
+ auto shader =
51
+ getObject()->makeShader(std::move(uniforms), nullptr, 0, matrix);
52
+
53
+ return jsi::Object::createFromHostObject(
54
+ runtime,
55
+ std::make_shared<JsiSkShader>(getContext(), std::move(shader)));
56
+ }
57
+
58
+ JSI_HOST_FUNCTION(makeShaderWithChildren) {
59
+ auto uniforms = castUniforms(runtime, arguments[0]);
60
+
61
+ // Children
62
+ std::vector<sk_sp<SkShader>> children;
63
+ auto jsiChildren = arguments[1].asObject(runtime).asArray(runtime);
64
+ auto jsiChildCount = jsiChildren.size(runtime);
65
+ children.reserve(jsiChildCount);
66
+ for (int i = 0; i < jsiChildCount; i++) {
67
+ auto shader = jsiChildren.getValueAtIndex(runtime, i)
68
+ .asObject(runtime)
69
+ .asHostObject<JsiSkShader>(runtime)
70
+ ->getObject();
71
+ children.push_back(shader);
42
72
  }
43
73
 
44
- JSI_HOST_FUNCTION(makeShader)
45
- {
46
- auto uniforms = castUniforms(runtime, arguments[0]);
74
+ auto matrix =
75
+ count >= 3 && !arguments[2].isUndefined() && !arguments[2].isNull()
76
+ ? JsiSkMatrix::fromValue(runtime, arguments[2]).get()
77
+ : nullptr;
47
78
 
48
- auto matrix = count >= 2 && !arguments[1].isUndefined() && !arguments[1].isNull() ? JsiSkMatrix::fromValue(runtime, arguments[1]).get() : nullptr;
79
+ // Create and return shader as host object
80
+ auto shader = getObject()->makeShader(std::move(uniforms), children.data(),
81
+ children.size(), matrix);
49
82
 
50
- // Create and return shader as host object
51
- auto shader = getObject()->makeShader(std::move(uniforms), nullptr, 0, matrix);
83
+ return jsi::Object::createFromHostObject(
84
+ runtime,
85
+ std::make_shared<JsiSkShader>(getContext(), std::move(shader)));
86
+ }
52
87
 
53
- return jsi::Object::createFromHostObject(
54
- runtime, std::make_shared<JsiSkShader>(getContext(), std::move(shader)));
55
- }
56
-
57
- JSI_HOST_FUNCTION(makeShaderWithChildren)
58
- {
59
- auto uniforms = castUniforms(runtime, arguments[0]);
60
-
61
- // Children
62
- std::vector<sk_sp<SkShader>> children;
63
- auto jsiChildren = arguments[1].asObject(runtime).asArray(runtime);
64
- auto jsiChildCount = jsiChildren.size(runtime);
65
- children.reserve(jsiChildCount);
66
- for (int i = 0; i < jsiChildCount; i++)
67
- {
68
- auto shader = jsiChildren.getValueAtIndex(runtime, i)
69
- .asObject(runtime)
70
- .asHostObject<JsiSkShader>(runtime)
71
- ->getObject();
72
- children.push_back(shader);
73
- }
88
+ JSI_HOST_FUNCTION(getUniformCount) {
89
+ return static_cast<int>(getObject()->uniforms().size());
90
+ }
74
91
 
75
- auto matrix = count >= 3 && !arguments[2].isUndefined() && !arguments[2].isNull() ? JsiSkMatrix::fromValue(runtime, arguments[2]).get() : nullptr;
92
+ JSI_HOST_FUNCTION(getUniformFloatCount) {
93
+ return static_cast<int>(getObject()->uniformSize() / sizeof(float));
94
+ }
76
95
 
77
- // Create and return shader as host object
78
- auto shader = getObject()->makeShader(std::move(uniforms), children.data(),
79
- children.size(), matrix);
80
-
81
- return jsi::Object::createFromHostObject(
82
- runtime, std::make_shared<JsiSkShader>(getContext(), std::move(shader)));
96
+ JSI_HOST_FUNCTION(getUniformName) {
97
+ auto i = static_cast<int>(arguments[0].asNumber());
98
+ if (i < 0 || i >= getObject()->uniforms().size()) {
99
+ throw jsi::JSError(runtime, "invalid uniform index");
83
100
  }
84
-
85
- JSI_HOST_FUNCTION(getUniformCount)
86
- {
87
- return static_cast<int>(getObject()->uniforms().size());
101
+ auto it = getObject()->uniforms().begin() + i;
102
+ return jsi::String::createFromAscii(runtime, it->name.c_str());
103
+ }
104
+
105
+ JSI_HOST_FUNCTION(getUniform) {
106
+ auto i = static_cast<int>(arguments[0].asNumber());
107
+ if (i < 0 || i >= getObject()->uniforms().size()) {
108
+ throw jsi::JSError(runtime, "invalid uniform index");
88
109
  }
89
-
90
- JSI_HOST_FUNCTION(getUniformFloatCount)
91
- {
92
- return static_cast<int>(getObject()->uniformSize() / sizeof(float));
110
+ auto it = getObject()->uniforms().begin() + i;
111
+ auto result = jsi::Object(runtime);
112
+ RuntimeEffectUniform su = fromUniform(*it);
113
+ result.setProperty(runtime, "columns", su.columns);
114
+ result.setProperty(runtime, "rows", su.rows);
115
+ result.setProperty(runtime, "slot", su.slot);
116
+ result.setProperty(runtime, "isInteger", su.isInteger);
117
+ return result;
118
+ }
119
+
120
+ JSI_EXPORT_FUNCTIONS(JSI_EXPORT_FUNC(JsiSkRuntimeEffect, makeShader),
121
+ JSI_EXPORT_FUNC(JsiSkRuntimeEffect,
122
+ makeShaderWithChildren),
123
+ JSI_EXPORT_FUNC(JsiSkRuntimeEffect, getUniformCount),
124
+ JSI_EXPORT_FUNC(JsiSkRuntimeEffect,
125
+ getUniformFloatCount),
126
+ JSI_EXPORT_FUNC(JsiSkRuntimeEffect, getUniformName),
127
+ JSI_EXPORT_FUNC(JsiSkRuntimeEffect, getUniform))
128
+
129
+ JsiSkRuntimeEffect(std::shared_ptr<RNSkPlatformContext> context,
130
+ sk_sp<SkRuntimeEffect> rt)
131
+ : JsiSkWrappingSkPtrHostObject<SkRuntimeEffect>(std::move(context),
132
+ std::move(rt)) {}
133
+
134
+ private:
135
+ sk_sp<SkData> castUniforms(jsi::Runtime &runtime, const jsi::Value &value) {
136
+ auto jsiUniforms = value.asObject(runtime).asArray(runtime);
137
+ auto jsiUniformsSize = jsiUniforms.size(runtime);
138
+
139
+ // verify size of input uniforms
140
+ if (jsiUniformsSize * sizeof(float) != getObject()->uniformSize()) {
141
+ std::string msg =
142
+ "Uniforms size differs from effect's uniform size. Received " +
143
+ std::to_string(jsiUniformsSize) + " expected " +
144
+ std::to_string(getObject()->uniformSize() / sizeof(float));
145
+ throw jsi::JSError(runtime, msg.c_str());
93
146
  }
94
147
 
95
- JSI_HOST_FUNCTION(getUniformName)
96
- {
97
- auto i = static_cast<int>(arguments[0].asNumber());
98
- if (i < 0 || i >= getObject()->uniforms().size()) {
99
- throw jsi::JSError(runtime, "invalid uniform index");
100
- }
101
- auto it = getObject()->uniforms().begin() + i;
102
- return jsi::String::createFromAscii(runtime, it->name.c_str());
103
- }
148
+ auto uniforms = SkData::MakeUninitialized(getObject()->uniformSize());
104
149
 
105
- JSI_HOST_FUNCTION(getUniform)
106
- {
107
- auto i = static_cast<int>(arguments[0].asNumber());
108
- if (i < 0 || i >= getObject()->uniforms().size()) {
109
- throw jsi::JSError(runtime, "invalid uniform index");
110
- }
150
+ // Convert to skia uniforms
151
+ const auto &u = getObject()->uniforms();
152
+ for (std::size_t i = 0; i < u.size(); i++) {
111
153
  auto it = getObject()->uniforms().begin() + i;
112
- auto result = jsi::Object(runtime);
113
- RuntimeEffectUniform su = fromUniform(*it);
114
- result.setProperty(runtime, "columns", su.columns);
115
- result.setProperty(runtime, "rows", su.rows);
116
- result.setProperty(runtime, "slot", su.slot);
117
- result.setProperty(runtime, "isInteger", su.isInteger);
118
- return result;
119
- }
120
-
121
- JSI_EXPORT_FUNCTIONS(JSI_EXPORT_FUNC(JsiSkRuntimeEffect, makeShader),
122
- JSI_EXPORT_FUNC(JsiSkRuntimeEffect,
123
- makeShaderWithChildren),
124
- JSI_EXPORT_FUNC(JsiSkRuntimeEffect, getUniformCount),
125
- JSI_EXPORT_FUNC(JsiSkRuntimeEffect,
126
- getUniformFloatCount),
127
- JSI_EXPORT_FUNC(JsiSkRuntimeEffect, getUniformName),
128
- JSI_EXPORT_FUNC(JsiSkRuntimeEffect, getUniform))
129
-
130
- JsiSkRuntimeEffect(std::shared_ptr<RNSkPlatformContext> context,
131
- sk_sp<SkRuntimeEffect> rt)
132
- : JsiSkWrappingSkPtrHostObject<SkRuntimeEffect>(std::move(context), std::move(rt)){}
133
-
134
- private:
135
- sk_sp<SkData> castUniforms(jsi::Runtime &runtime, const jsi::Value &value)
136
- {
137
- auto jsiUniforms = value.asObject(runtime).asArray(runtime);
138
- auto jsiUniformsSize = jsiUniforms.size(runtime);
139
-
140
- // verify size of input uniforms
141
- if (jsiUniformsSize * sizeof(float) != getObject()->uniformSize())
142
- {
143
- std::string msg = "Uniforms size differs from effect's uniform size. Received " +
144
- std::to_string(jsiUniformsSize) +
145
- " expected " +
146
- std::to_string(getObject()->uniformSize() / sizeof(float));
147
- throw jsi::JSError(runtime, msg.c_str());
154
+ RuntimeEffectUniform reu = fromUniform(*it);
155
+ for (std::size_t j = 0; j < reu.columns * reu.rows; ++j) {
156
+ const std::size_t offset = reu.slot + j;
157
+ float fValue = jsiUniforms.getValueAtIndex(runtime, offset).asNumber();
158
+ int iValue = static_cast<int>(fValue);
159
+ auto value = reu.isInteger ? iValue : fValue;
160
+ memcpy(SkTAddOffset<void>(uniforms->writable_data(),
161
+ offset * sizeof(value)),
162
+ &value, sizeof(value));
148
163
  }
149
-
150
- auto uniforms = SkData::MakeUninitialized(getObject()->uniformSize());
151
-
152
- // Convert to skia uniforms
153
- const auto& u = getObject()->uniforms();
154
- for (std::size_t i = 0; i < u.size(); i++)
155
- {
156
- auto it = getObject()->uniforms().begin() + i;
157
- RuntimeEffectUniform reu = fromUniform(*it);
158
- for (std::size_t j = 0; j < reu.columns * reu.rows; ++j) {
159
- const std::size_t offset = reu.slot + j;
160
- float fValue = jsiUniforms.getValueAtIndex(runtime, offset).asNumber();
161
- int iValue = static_cast<int>(fValue);
162
- auto value = reu.isInteger ? iValue : fValue;
163
- memcpy(SkTAddOffset<void>(uniforms->writable_data(), offset * sizeof(value)), &value, sizeof(value));
164
- }
165
- }
166
- return uniforms;
167
164
  }
168
-
169
- RuntimeEffectUniform fromUniform(const SkRuntimeEffect::Uniform &u)
170
- {
171
- RuntimeEffectUniform su;
172
- su.rows = u.count; // arrayLength
173
- su.columns = 1;
174
- su.isInteger = false;
175
- using Type = SkRuntimeEffect::Uniform::Type;
176
- switch (u.type)
177
- {
178
- case Type::kFloat:
179
- break;
180
- case Type::kFloat2:
181
- su.columns = 2;
182
- break;
183
- case Type::kFloat3:
184
- su.columns = 3;
185
- break;
186
- case Type::kFloat4:
187
- su.columns = 4;
188
- break;
189
- case Type::kFloat2x2:
190
- su.columns = 2;
191
- su.rows *= 2;
192
- break;
193
- case Type::kFloat3x3:
194
- su.columns = 3;
195
- su.rows *= 3;
196
- break;
197
- case Type::kFloat4x4:
198
- su.columns = 4;
199
- su.rows *= 4;
200
- break;
201
- case Type::kInt:
202
- su.isInteger = true;
203
- break;
204
- case Type::kInt2:
205
- su.columns = 2;
206
- su.isInteger = true;
207
- break;
208
- case Type::kInt3:
209
- su.columns = 3;
210
- su.isInteger = true;
211
- break;
212
- case Type::kInt4:
213
- su.columns = 4;
214
- su.isInteger = true;
215
- break;
216
- }
217
- su.slot = (int)(u.offset / sizeof(float));
218
- return su;
165
+ return uniforms;
166
+ }
167
+
168
+ RuntimeEffectUniform fromUniform(const SkRuntimeEffect::Uniform &u) {
169
+ RuntimeEffectUniform su;
170
+ su.rows = u.count; // arrayLength
171
+ su.columns = 1;
172
+ su.isInteger = false;
173
+ using Type = SkRuntimeEffect::Uniform::Type;
174
+ switch (u.type) {
175
+ case Type::kFloat:
176
+ break;
177
+ case Type::kFloat2:
178
+ su.columns = 2;
179
+ break;
180
+ case Type::kFloat3:
181
+ su.columns = 3;
182
+ break;
183
+ case Type::kFloat4:
184
+ su.columns = 4;
185
+ break;
186
+ case Type::kFloat2x2:
187
+ su.columns = 2;
188
+ su.rows *= 2;
189
+ break;
190
+ case Type::kFloat3x3:
191
+ su.columns = 3;
192
+ su.rows *= 3;
193
+ break;
194
+ case Type::kFloat4x4:
195
+ su.columns = 4;
196
+ su.rows *= 4;
197
+ break;
198
+ case Type::kInt:
199
+ su.isInteger = true;
200
+ break;
201
+ case Type::kInt2:
202
+ su.columns = 2;
203
+ su.isInteger = true;
204
+ break;
205
+ case Type::kInt3:
206
+ su.columns = 3;
207
+ su.isInteger = true;
208
+ break;
209
+ case Type::kInt4:
210
+ su.columns = 4;
211
+ su.isInteger = true;
212
+ break;
219
213
  }
220
-
221
- };
214
+ su.slot = static_cast<int>(u.offset / sizeof(float));
215
+ return su;
216
+ }
217
+ };
222
218
  } // namespace RNSkia