@shopify/react-native-skia 0.1.155 → 0.1.157

Sign up to get free protection for your applications and to get access to all the features.
Files changed (202) 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/Canvas.js +1 -1
  98. package/lib/commonjs/renderer/Canvas.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/HostConfig.js +10 -1
  102. package/lib/commonjs/renderer/HostConfig.js.map +1 -1
  103. package/lib/commonjs/renderer/components/Group.js +19 -4
  104. package/lib/commonjs/renderer/components/Group.js.map +1 -1
  105. package/lib/commonjs/renderer/components/Paint.js +6 -1
  106. package/lib/commonjs/renderer/components/Paint.js.map +1 -1
  107. package/lib/commonjs/views/SkiaPictureView.js +3 -2
  108. package/lib/commonjs/views/SkiaPictureView.js.map +1 -1
  109. package/lib/commonjs/views/SkiaView.js +6 -3
  110. package/lib/commonjs/views/SkiaView.js.map +1 -1
  111. package/lib/module/animation/spring/runSpring.js +1 -1
  112. package/lib/module/animation/spring/runSpring.js.map +1 -1
  113. package/lib/module/animation/spring/useSpring.js +1 -1
  114. package/lib/module/animation/spring/useSpring.js.map +1 -1
  115. package/lib/module/animation/timing/createTiming.js +6 -2
  116. package/lib/module/animation/timing/createTiming.js.map +1 -1
  117. package/lib/module/animation/timing/functions/getResolvedParams.js +10 -6
  118. package/lib/module/animation/timing/functions/getResolvedParams.js.map +1 -1
  119. package/lib/module/animation/timing/useTiming.js +3 -1
  120. package/lib/module/animation/timing/useTiming.js.map +1 -1
  121. package/lib/module/dom/nodes/JsiSkDOM.js +6 -1
  122. package/lib/module/dom/nodes/JsiSkDOM.js.map +1 -1
  123. package/lib/module/dom/nodes/LayerNode.js +32 -0
  124. package/lib/module/dom/nodes/LayerNode.js.map +1 -0
  125. package/lib/module/dom/nodes/datatypes/Gradient.js +2 -2
  126. package/lib/module/dom/nodes/datatypes/Gradient.js.map +1 -1
  127. package/lib/module/dom/nodes/paint/Shaders.js +4 -2
  128. package/lib/module/dom/nodes/paint/Shaders.js.map +1 -1
  129. package/lib/module/dom/types/NodeType.js +1 -0
  130. package/lib/module/dom/types/NodeType.js.map +1 -1
  131. package/lib/module/dom/types/SkDOM.js.map +1 -1
  132. package/lib/module/mock/index.js +10 -6
  133. package/lib/module/mock/index.js.map +1 -1
  134. package/lib/module/renderer/Canvas.js +1 -1
  135. package/lib/module/renderer/Canvas.js.map +1 -1
  136. package/lib/module/renderer/HostComponents.js +3 -0
  137. package/lib/module/renderer/HostComponents.js.map +1 -1
  138. package/lib/module/renderer/HostConfig.js +9 -1
  139. package/lib/module/renderer/HostConfig.js.map +1 -1
  140. package/lib/module/renderer/components/Group.js +16 -3
  141. package/lib/module/renderer/components/Group.js.map +1 -1
  142. package/lib/module/renderer/components/Paint.js +7 -1
  143. package/lib/module/renderer/components/Paint.js.map +1 -1
  144. package/lib/module/skia/core/Vector.js +1 -1
  145. package/lib/module/skia/core/Vector.js.map +1 -1
  146. package/lib/module/skia/web/Host.js +1 -1
  147. package/lib/module/skia/web/Host.js.map +1 -1
  148. package/lib/module/skia/web/JsiSkMatrix.js +1 -1
  149. package/lib/module/skia/web/JsiSkMatrix.js.map +1 -1
  150. package/lib/module/values/web/RNSkAnimation.js +2 -2
  151. package/lib/module/values/web/RNSkAnimation.js.map +1 -1
  152. package/lib/module/views/SkiaBaseWebView.js +3 -1
  153. package/lib/module/views/SkiaBaseWebView.js.map +1 -1
  154. package/lib/module/views/SkiaPictureView.js +2 -2
  155. package/lib/module/views/SkiaPictureView.js.map +1 -1
  156. package/lib/module/views/SkiaView.js +4 -2
  157. package/lib/module/views/SkiaView.js.map +1 -1
  158. package/lib/module/views/useTouchHandler.js +6 -6
  159. package/lib/module/views/useTouchHandler.js.map +1 -1
  160. package/lib/module/web/WithSkiaWeb.js +1 -1
  161. package/lib/module/web/WithSkiaWeb.js.map +1 -1
  162. package/lib/typescript/src/dom/nodes/JsiSkDOM.d.ts +2 -0
  163. package/lib/typescript/src/dom/nodes/LayerNode.d.ts +8 -0
  164. package/lib/typescript/src/dom/types/NodeType.d.ts +1 -0
  165. package/lib/typescript/src/dom/types/SkDOM.d.ts +1 -0
  166. package/lib/typescript/src/renderer/HostComponents.d.ts +2 -1
  167. package/lib/typescript/src/renderer/components/Group.d.ts +5 -1
  168. package/lib/typescript/src/views/SkiaView.d.ts +3 -0
  169. package/libs/android/arm64-v8a/libskottie.a +0 -0
  170. package/libs/android/arm64-v8a/libsksg.a +0 -0
  171. package/libs/android/armeabi-v7a/libskottie.a +0 -0
  172. package/libs/android/armeabi-v7a/libsksg.a +0 -0
  173. package/libs/android/x86/libskottie.a +0 -0
  174. package/libs/android/x86/libsksg.a +0 -0
  175. package/libs/android/x86_64/libskottie.a +0 -0
  176. package/libs/android/x86_64/libsksg.a +0 -0
  177. package/libs/ios/libskia.xcframework/ios-arm64_arm64e/libskia.a +0 -0
  178. package/libs/ios/libskia.xcframework/ios-arm64_arm64e_x86_64-simulator/libskia.a +0 -0
  179. package/libs/ios/libskottie.xcframework/Info.plist +42 -0
  180. package/libs/ios/libskottie.xcframework/ios-arm64_arm64e/libskottie.a +0 -0
  181. package/libs/ios/libskottie.xcframework/ios-arm64_arm64e_x86_64-simulator/libskottie.a +0 -0
  182. package/libs/ios/libsksg.xcframework/Info.plist +42 -0
  183. package/libs/ios/libsksg.xcframework/ios-arm64_arm64e/libsksg.a +0 -0
  184. package/libs/ios/libsksg.xcframework/ios-arm64_arm64e_x86_64-simulator/libsksg.a +0 -0
  185. package/libs/ios/libskshaper.xcframework/Info.plist +5 -5
  186. package/libs/ios/libskshaper.xcframework/ios-arm64_arm64e/libskshaper.a +0 -0
  187. package/libs/ios/libskshaper.xcframework/ios-arm64_arm64e_x86_64-simulator/libskshaper.a +0 -0
  188. package/libs/ios/libsvg.xcframework/Info.plist +5 -5
  189. package/libs/ios/libsvg.xcframework/ios-arm64_arm64e/libsvg.a +0 -0
  190. package/libs/ios/libsvg.xcframework/ios-arm64_arm64e_x86_64-simulator/libsvg.a +0 -0
  191. package/package.json +14 -6
  192. package/src/dom/nodes/JsiSkDOM.ts +5 -0
  193. package/src/dom/nodes/LayerNode.ts +35 -0
  194. package/src/dom/types/NodeType.ts +1 -0
  195. package/src/dom/types/SkDOM.ts +1 -0
  196. package/src/renderer/Canvas.tsx +11 -1
  197. package/src/renderer/HostComponents.ts +3 -0
  198. package/src/renderer/HostConfig.ts +8 -1
  199. package/src/renderer/components/Group.tsx +16 -3
  200. package/src/renderer/components/Paint.tsx +7 -1
  201. package/src/views/SkiaPictureView.tsx +2 -3
  202. package/src/views/SkiaView.tsx +2 -2
@@ -1,15 +1,15 @@
1
1
  #include "JniPlatformContext.h"
2
2
  #include "JniSkiaDrawView.h"
3
- #include "JniSkiaPictureView.h"
4
3
  #include "JniSkiaManager.h"
4
+ #include "JniSkiaPictureView.h"
5
5
  #include <fbjni/fbjni.h>
6
6
  #include <jni.h>
7
7
 
8
8
  JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM *vm, void *) {
9
9
  return facebook::jni::initialize(vm, [] {
10
- RNSkia::JniSkiaManager::registerNatives();
11
- RNSkia::JniSkiaDrawView::registerNatives();
12
- RNSkia::JniSkiaPictureView::registerNatives();
13
- RNSkia::JniPlatformContext::registerNatives();
10
+ RNSkia::JniSkiaManager::registerNatives();
11
+ RNSkia::JniSkiaDrawView::registerNatives();
12
+ RNSkia::JniSkiaPictureView::registerNatives();
13
+ RNSkia::JniPlatformContext::registerNatives();
14
14
  });
15
15
  }
@@ -4,139 +4,127 @@
4
4
  #include <thread>
5
5
  #include <utility>
6
6
 
7
- #include <RNSkMeasureTime.h>
8
7
  #include "SkData.h"
9
8
  #include "SkRefCnt.h"
10
- #include "SkTypes.h"
11
9
  #include "SkStream.h"
10
+ #include "SkTypes.h"
11
+ #include <RNSkMeasureTime.h>
12
12
 
13
- namespace RNSkia
14
- {
15
-
16
- using namespace facebook;
13
+ namespace RNSkia {
14
+
15
+ namespace jsi = facebook::jsi;
16
+
17
+ using TSelf = jni::local_ref<JniPlatformContext::jhybriddata>;
18
+
19
+ void JniPlatformContext::registerNatives() {
20
+ registerHybrid({
21
+ makeNativeMethod("initHybrid", JniPlatformContext::initHybrid),
22
+ makeNativeMethod("notifyDrawLoop",
23
+ JniPlatformContext::notifyDrawLoopExternal),
24
+ makeNativeMethod("notifyTaskReady",
25
+ JniPlatformContext::notifyTaskReadyExternal),
26
+ });
27
+ }
28
+
29
+ TSelf JniPlatformContext::initHybrid(jni::alias_ref<jhybridobject> jThis,
30
+ float pixelDensity) {
31
+ return makeCxxInstance(jThis, pixelDensity);
32
+ }
33
+
34
+ void JniPlatformContext::startDrawLoop() {
35
+ jni::ThreadScope ts;
36
+ // Start drawing loop
37
+ static auto method =
38
+ javaPart_->getClass()->getMethod<void(void)>("beginDrawLoop");
39
+ method(javaPart_.get());
40
+ }
41
+
42
+ void JniPlatformContext::stopDrawLoop() {
43
+ jni::ThreadScope ts;
44
+ // Stop drawing loop
45
+ static auto method =
46
+ javaPart_->getClass()->getMethod<void(void)>("endDrawLoop");
47
+ method(javaPart_.get());
48
+ }
49
+
50
+ void JniPlatformContext::notifyDrawLoopExternal() {
51
+ jni::ThreadScope ts;
52
+ _onNotifyDrawLoop();
53
+ }
54
+
55
+ void JniPlatformContext::notifyTaskReadyExternal() {
56
+ _taskMutex->lock();
57
+ auto task = _taskCallbacks.front();
58
+ if (task != nullptr) {
59
+ _taskCallbacks.pop();
60
+ _taskMutex->unlock();
61
+ task();
62
+ } else {
63
+ _taskMutex->unlock();
64
+ }
65
+ }
66
+
67
+ void JniPlatformContext::performStreamOperation(
68
+ const std::string &sourceUri,
69
+ const std::function<void(std::unique_ptr<SkStreamAsset>)> &op) {
70
+ auto measure = RNSkMeasureTime("JniPlatformContext::performStreamOperation");
71
+
72
+ static auto method = javaPart_->getClass()->getMethod<jbyteArray(jstring)>(
73
+ "getJniStreamFromSource");
74
+
75
+ auto loader = [=]() -> void {
76
+ jni::ThreadScope ts;
77
+ jstring jstr =
78
+ (*jni::Environment::current()).NewStringUTF(sourceUri.c_str());
79
+
80
+ // Get the array with data from input stream from Java
81
+ auto array = method(javaPart_.get(), jstr);
82
+
83
+ if (array == nullptr) {
84
+ printf("Calling getJniStreamFromSource failed\n");
85
+ return;
86
+ }
17
87
 
18
- using TSelf = jni::local_ref<JniPlatformContext::jhybriddata>;
88
+ // Allocate buffer for java byte array
89
+ jsize num_bytes = jni::Environment::current()->GetArrayLength(array.get());
90
+ char *buffer = reinterpret_cast<char *>(malloc(num_bytes + 1));
19
91
 
20
- void JniPlatformContext::registerNatives()
21
- {
22
- registerHybrid({
23
- makeNativeMethod("initHybrid", JniPlatformContext::initHybrid),
24
- makeNativeMethod("notifyDrawLoop", JniPlatformContext::notifyDrawLoopExternal),
25
- makeNativeMethod("notifyTaskReady", JniPlatformContext::notifyTaskReadyExternal),
26
- });
92
+ if (!buffer) {
93
+ printf("Buff Fail\n");
94
+ return;
27
95
  }
28
96
 
29
- TSelf JniPlatformContext::initHybrid(jni::alias_ref<jhybridobject> jThis, float pixelDensity)
30
- {
31
- return makeCxxInstance(jThis, pixelDensity);
97
+ jbyte *elements =
98
+ jni::Environment::current()->GetByteArrayElements(array.get(), nullptr);
99
+ if (!elements) {
100
+ printf("Element Fail\n");
101
+ return;
32
102
  }
33
103
 
34
- void JniPlatformContext::startDrawLoop()
35
- {
36
- jni::ThreadScope ts;
37
- // Start drawing loop
38
- static auto method = javaPart_->getClass()->getMethod<void(void)>("beginDrawLoop");
39
- method(javaPart_.get());
40
- }
104
+ // Copy data from java array to buffer
105
+ memcpy(buffer, elements, num_bytes);
106
+ buffer[num_bytes] = 0;
41
107
 
42
- void JniPlatformContext::stopDrawLoop()
43
- {
44
- jni::ThreadScope ts;
45
- // Stop drawing loop
46
- static auto method = javaPart_->getClass()->getMethod<void(void)>("endDrawLoop");
47
- method(javaPart_.get());
48
- }
108
+ jni::Environment::current()->ReleaseByteArrayElements(array.get(), elements,
109
+ JNI_ABORT);
49
110
 
50
- void JniPlatformContext::notifyDrawLoopExternal()
51
- {
52
- jni::ThreadScope ts;
53
- _onNotifyDrawLoop();
54
- }
111
+ // Copy malloced data and give ownership to SkData
112
+ auto data = SkData::MakeFromMalloc(buffer, num_bytes);
113
+ auto skStream = SkMemoryStream::Make(data);
55
114
 
56
- void JniPlatformContext::notifyTaskReadyExternal()
57
- {
58
- _taskMutex->lock();
59
- auto task = _taskCallbacks.front();
60
- if (task != nullptr)
61
- {
62
- _taskCallbacks.pop();
63
- _taskMutex->unlock();
64
- task();
65
- }
66
- else
67
- {
68
- _taskMutex->unlock();
69
- }
70
- }
115
+ // Perform operation
116
+ op(std::move(skStream));
117
+ };
71
118
 
72
- void JniPlatformContext::performStreamOperation(
73
- const std::string &sourceUri,
74
- const std::function<void(std::unique_ptr<SkStreamAsset>)> &op)
75
- {
76
- auto measure =
77
- RNSkMeasureTime("JniPlatformContext::performStreamOperation");
78
-
79
- static auto method = javaPart_->getClass()->getMethod<jbyteArray(jstring)>(
80
- "getJniStreamFromSource");
81
-
82
- auto loader = [=]() -> void
83
- {
84
- jni::ThreadScope ts;
85
- jstring jstr =
86
- (*jni::Environment::current()).NewStringUTF(sourceUri.c_str());
87
-
88
- // Get the array with data from input stream from Java
89
- auto array = method(javaPart_.get(), jstr);
90
-
91
- if (array == nullptr)
92
- {
93
- printf("Calling getJniStreamFromSource failed\n");
94
- return;
95
- }
96
-
97
- // Allocate buffer for java byte array
98
- jsize num_bytes =
99
- jni::Environment::current()->GetArrayLength(array.get());
100
- char *buffer = (char *)malloc(num_bytes + 1);
101
-
102
- if (!buffer)
103
- {
104
- printf("Buff Fail\n");
105
- return;
106
- }
107
-
108
- jbyte *elements = jni::Environment::current()->GetByteArrayElements(
109
- array.get(), nullptr);
110
- if (!elements)
111
- {
112
- printf("Element Fail\n");
113
- return;
114
- }
115
-
116
- // Copy data from java array to buffer
117
- memcpy(buffer, elements, num_bytes);
118
- buffer[num_bytes] = 0;
119
-
120
- jni::Environment::current()->ReleaseByteArrayElements(
121
- array.get(), elements, JNI_ABORT);
122
-
123
- // Copy malloced data and give ownership to SkData
124
- auto data = SkData::MakeFromMalloc(buffer, num_bytes);
125
- auto skStream = SkMemoryStream::Make(data);
126
-
127
- // Perform operation
128
- op(std::move(skStream));
129
- };
130
-
131
- // Fire and forget the thread - will be resolved on completion
132
- std::thread(loader).detach();
133
- }
119
+ // Fire and forget the thread - will be resolved on completion
120
+ std::thread(loader).detach();
121
+ }
134
122
 
135
- void JniPlatformContext::raiseError(const std::exception &err)
136
- {
137
- jni::ThreadScope ts;
138
- static auto method = javaPart_->getClass()->getMethod<void(std::string)>("raise");
139
- method(javaPart_.get(), std::string(err.what()));
140
- }
123
+ void JniPlatformContext::raiseError(const std::exception &err) {
124
+ jni::ThreadScope ts;
125
+ static auto method =
126
+ javaPart_->getClass()->getMethod<void(std::string)>("raise");
127
+ method(javaPart_.get(), std::string(err.what()));
128
+ }
141
129
 
142
130
  } // namespace RNSkia
@@ -10,35 +10,33 @@
10
10
 
11
11
  namespace RNSkia {
12
12
 
13
- using namespace facebook;
13
+ namespace jsi = facebook::jsi;
14
14
 
15
15
  // JNI binding
16
16
  void JniSkiaManager::registerNatives() {
17
- registerHybrid({
18
- makeNativeMethod("initHybrid", JniSkiaManager::initHybrid),
19
- makeNativeMethod("initializeRuntime", JniSkiaManager::initializeRuntime),
20
- makeNativeMethod("invalidate", JniSkiaManager::invalidate),
21
- });
17
+ registerHybrid({
18
+ makeNativeMethod("initHybrid", JniSkiaManager::initHybrid),
19
+ makeNativeMethod("initializeRuntime", JniSkiaManager::initializeRuntime),
20
+ makeNativeMethod("invalidate", JniSkiaManager::invalidate),
21
+ });
22
22
  }
23
23
 
24
24
  // JNI init
25
- jni::local_ref<jni::HybridClass<JniSkiaManager>::jhybriddata> JniSkiaManager::initHybrid(
26
- jni::alias_ref<jhybridobject> jThis,
27
- jlong jsContext,
28
- JSCallInvokerHolder jsCallInvokerHolder,
29
- JavaPlatformContext skiaContext) {
30
-
31
- // cast from JNI hybrid objects to C++ instances
32
- return makeCxxInstance(
33
- jThis,
34
- reinterpret_cast<jsi::Runtime *>(jsContext),
35
- jsCallInvokerHolder->cthis()->getCallInvoker(),
36
- skiaContext->cthis());
25
+ jni::local_ref<jni::HybridClass<JniSkiaManager>::jhybriddata>
26
+ JniSkiaManager::initHybrid(jni::alias_ref<jhybridobject> jThis, jlong jsContext,
27
+ JSCallInvokerHolder jsCallInvokerHolder,
28
+ JavaPlatformContext skiaContext) {
29
+
30
+ // cast from JNI hybrid objects to C++ instances
31
+ return makeCxxInstance(jThis, reinterpret_cast<jsi::Runtime *>(jsContext),
32
+ jsCallInvokerHolder->cthis()->getCallInvoker(),
33
+ skiaContext->cthis());
37
34
  }
38
35
 
39
36
  void JniSkiaManager::initializeRuntime() {
40
- // Create the cross platform skia manager
41
- _skManager = std::make_shared<RNSkManager>(_jsRuntime, _jsCallInvoker, _context);
37
+ // Create the cross platform skia manager
38
+ _skManager =
39
+ std::make_shared<RNSkManager>(_jsRuntime, _jsCallInvoker, _context);
42
40
  }
43
41
 
44
42
  } // namespace RNSkia
@@ -1,75 +1,71 @@
1
1
  #pragma once
2
2
 
3
- #include <fbjni/fbjni.h>
4
3
  #include <ReactCommon/CallInvokerHolder.h>
4
+ #include <fbjni/fbjni.h>
5
5
 
6
- #include <queue>
7
- #include <mutex>
6
+ #include <exception>
8
7
  #include <functional>
9
8
  #include <memory>
9
+ #include <mutex>
10
+ #include <queue>
10
11
  #include <string>
11
- #include <exception>
12
12
 
13
13
  #include "RNSkPlatformContext.h"
14
14
 
15
15
  class SkStreamAsset;
16
- namespace RNSkia
17
- {
16
+ namespace RNSkia {
18
17
 
19
- using namespace facebook;
18
+ namespace jsi = facebook::jsi;
19
+ namespace jni = facebook::jni;
20
20
 
21
- using JSCallInvokerHolder =
22
- jni::alias_ref<facebook::react::CallInvokerHolder::javaobject>;
21
+ using JSCallInvokerHolder =
22
+ jni::alias_ref<facebook::react::CallInvokerHolder::javaobject>;
23
23
 
24
- class JniPlatformContext : public jni::HybridClass<JniPlatformContext>
25
- {
26
- public:
27
- static auto constexpr kJavaDescriptor = "Lcom/shopify/reactnative/skia/PlatformContext;";
24
+ class JniPlatformContext : public jni::HybridClass<JniPlatformContext> {
25
+ public:
26
+ static auto constexpr kJavaDescriptor =
27
+ "Lcom/shopify/reactnative/skia/PlatformContext;";
28
28
 
29
- static jni::local_ref<jhybriddata> initHybrid(
30
- jni::alias_ref<jhybridobject> jThis,
31
- const float);
29
+ static jni::local_ref<jhybriddata>
30
+ initHybrid(jni::alias_ref<jhybridobject> jThis, const float);
32
31
 
33
- static void registerNatives();
32
+ static void registerNatives();
34
33
 
35
- void performStreamOperation(
36
- const std::string &sourceUri,
37
- const std::function<void(std::unique_ptr<SkStreamAsset>)> &op);
34
+ void performStreamOperation(
35
+ const std::string &sourceUri,
36
+ const std::function<void(std::unique_ptr<SkStreamAsset>)> &op);
38
37
 
39
- void raiseError(const std::exception &err);
38
+ void raiseError(const std::exception &err);
40
39
 
41
- void startDrawLoop();
42
- void stopDrawLoop();
40
+ void startDrawLoop();
41
+ void stopDrawLoop();
43
42
 
44
- void notifyDrawLoopExternal();
43
+ void notifyDrawLoopExternal();
45
44
 
46
- void notifyTaskReadyExternal();
45
+ void notifyTaskReadyExternal();
47
46
 
48
- float getPixelDensity() { return _pixelDensity; }
47
+ float getPixelDensity() { return _pixelDensity; }
49
48
 
50
- void setOnNotifyDrawLoop(const std::function<void(void)>& callback) {
51
- _onNotifyDrawLoop = callback;
52
- }
49
+ void setOnNotifyDrawLoop(const std::function<void(void)> &callback) {
50
+ _onNotifyDrawLoop = callback;
51
+ }
53
52
 
54
- private:
55
- friend HybridBase;
56
- jni::global_ref<JniPlatformContext::javaobject> javaPart_;
53
+ private:
54
+ friend HybridBase;
55
+ jni::global_ref<JniPlatformContext::javaobject> javaPart_;
57
56
 
58
- float _pixelDensity;
57
+ float _pixelDensity;
59
58
 
60
- std::function<void(void)> _onNotifyDrawLoop;
59
+ std::function<void(void)> _onNotifyDrawLoop;
61
60
 
62
- std::queue<std::function<void()>> _taskCallbacks;
61
+ std::queue<std::function<void()>> _taskCallbacks;
63
62
 
64
- std::shared_ptr<std::mutex> _taskMutex;
63
+ std::shared_ptr<std::mutex> _taskMutex;
65
64
 
66
- explicit JniPlatformContext(
67
- jni::alias_ref<JniPlatformContext::jhybridobject> jThis,
68
- const float pixelDensity)
69
- : _taskMutex(std::make_shared<std::mutex>()),
70
- javaPart_(jni::make_global(jThis)),
71
- _pixelDensity(pixelDensity)
72
- {
73
- }
74
- };
65
+ explicit JniPlatformContext(
66
+ jni::alias_ref<JniPlatformContext::jhybridobject> jThis,
67
+ const float pixelDensity)
68
+ : _taskMutex(std::make_shared<std::mutex>()),
69
+ javaPart_(jni::make_global(jThis)), _pixelDensity(pixelDensity) {}
70
+ };
75
71
  } // namespace RNSkia
@@ -1,68 +1,65 @@
1
1
  #pragma once
2
2
 
3
3
  #include <memory>
4
+ #include <string>
4
5
 
5
6
  #include <fbjni/fbjni.h>
6
7
  #include <jni.h>
7
8
  #include <jsi/jsi.h>
8
9
 
9
10
  #include <JniSkiaManager.h>
11
+ #include <RNSkAndroidView.h>
10
12
 
11
13
  namespace RNSkia {
12
- using namespace facebook;
13
- using namespace jni;
14
-
15
- class JniSkiaBaseView {
16
- public:
17
- JniSkiaBaseView(jni::alias_ref<JniSkiaManager::javaobject> skiaManager,
18
- std::shared_ptr<RNSkBaseAndroidView> skiaView) :
19
- _manager(skiaManager->cthis()),
20
- _skiaView(skiaView) {}
21
-
22
- ~JniSkiaBaseView() {}
23
-
24
- std::shared_ptr<RNSkManager> getSkiaManager() { return _manager->getSkiaManager(); };
25
-
26
- protected:
27
- virtual void updateTouchPoints(jni::JArrayDouble touches) {
28
- _skiaView->updateTouchPoints(touches);
29
- }
30
-
31
- virtual void surfaceAvailable(jobject surface, int width, int height) {
32
- _skiaView->surfaceAvailable(surface, width, height);
33
- }
34
-
35
- virtual void surfaceSizeChanged(int width, int height) {
36
- _skiaView->surfaceSizeChanged(width, height);
37
- }
38
-
39
- virtual void surfaceDestroyed() {
40
- _skiaView->surfaceDestroyed();
41
- }
42
-
43
- virtual void setMode(std::string mode) {
44
- _skiaView->setMode(mode);
45
- }
46
-
47
- virtual void setDebugMode(bool show) {
48
- _skiaView->setShowDebugInfo(show);
49
- }
50
-
51
- virtual void registerView(int nativeId) {
52
- getSkiaManager()->registerSkiaView(nativeId,
53
- _skiaView->getSkiaView());
54
- }
55
-
56
- virtual void unregisterView() {
57
- getSkiaManager()->setSkiaView(_skiaView->getSkiaView()->getNativeId(), nullptr);
58
- getSkiaManager()->unregisterSkiaView(
59
- _skiaView->getSkiaView()->getNativeId());
60
- _skiaView->viewDidUnmount();
61
- }
62
-
63
- private:
64
- JniSkiaManager *_manager;
65
- std::shared_ptr<RNSkBaseAndroidView> _skiaView;
66
- };
14
+
15
+ namespace jsi = facebook::jsi;
16
+
17
+ class JniSkiaBaseView {
18
+ public:
19
+ JniSkiaBaseView(jni::alias_ref<JniSkiaManager::javaobject> skiaManager,
20
+ std::shared_ptr<RNSkBaseAndroidView> skiaView)
21
+ : _manager(skiaManager->cthis()), _skiaView(skiaView) {}
22
+
23
+ ~JniSkiaBaseView() {}
24
+
25
+ std::shared_ptr<RNSkManager> getSkiaManager() {
26
+ return _manager->getSkiaManager();
27
+ }
28
+
29
+ protected:
30
+ virtual void updateTouchPoints(jni::JArrayDouble touches) {
31
+ _skiaView->updateTouchPoints(touches);
32
+ }
33
+
34
+ virtual void surfaceAvailable(jobject surface, int width, int height) {
35
+ _skiaView->surfaceAvailable(surface, width, height);
36
+ }
37
+
38
+ virtual void surfaceSizeChanged(int width, int height) {
39
+ _skiaView->surfaceSizeChanged(width, height);
40
+ }
41
+
42
+ virtual void surfaceDestroyed() { _skiaView->surfaceDestroyed(); }
43
+
44
+ virtual void setMode(std::string mode) { _skiaView->setMode(mode); }
45
+
46
+ virtual void setDebugMode(bool show) { _skiaView->setShowDebugInfo(show); }
47
+
48
+ virtual void registerView(int nativeId) {
49
+ getSkiaManager()->registerSkiaView(nativeId, _skiaView->getSkiaView());
50
+ }
51
+
52
+ virtual void unregisterView() {
53
+ getSkiaManager()->setSkiaView(_skiaView->getSkiaView()->getNativeId(),
54
+ nullptr);
55
+ getSkiaManager()->unregisterSkiaView(
56
+ _skiaView->getSkiaView()->getNativeId());
57
+ _skiaView->viewDidUnmount();
58
+ }
59
+
60
+ private:
61
+ JniSkiaManager *_manager;
62
+ std::shared_ptr<RNSkBaseAndroidView> _skiaView;
63
+ };
67
64
 
68
65
  } // namespace RNSkia