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