@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
@@ -1,95 +1,90 @@
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
- #include <RNSkJsView.h>
10
- #include <RNSkAndroidView.h>
11
10
  #include <JniSkiaBaseView.h>
12
11
  #include <JniSkiaManager.h>
12
+ #include <RNSkAndroidView.h>
13
+ #include <RNSkJsView.h>
13
14
 
14
15
  #include <android/native_window.h>
15
16
  #include <android/native_window_jni.h>
16
17
  #include <fbjni/detail/Hybrid.h>
17
18
 
18
19
  namespace RNSkia {
19
- using namespace facebook;
20
- using namespace jni;
21
-
22
- class JniSkiaDrawView
23
- : public HybridClass<JniSkiaDrawView>, public JniSkiaBaseView {
24
- public:
25
- static auto constexpr kJavaDescriptor = "Lcom/shopify/reactnative/skia/SkiaDrawView;";
26
-
27
- static jni::local_ref<jhybriddata>
28
- initHybrid(jni::alias_ref<jhybridobject> jThis,
29
- jni::alias_ref<JniSkiaManager::javaobject> skiaManager) {
30
- return makeCxxInstance(jThis, skiaManager);
31
- }
32
-
33
- static void registerNatives() {
34
- registerHybrid({
35
- makeNativeMethod("initHybrid", JniSkiaDrawView::initHybrid),
36
- makeNativeMethod("surfaceAvailable",
37
- JniSkiaDrawView::surfaceAvailable),
38
- makeNativeMethod("surfaceDestroyed",
39
- JniSkiaDrawView::surfaceDestroyed),
40
- makeNativeMethod("surfaceSizeChanged",
41
- JniSkiaDrawView::surfaceSizeChanged),
42
- makeNativeMethod("setMode", JniSkiaDrawView::setMode),
43
- makeNativeMethod("setDebugMode", JniSkiaDrawView::setDebugMode),
44
- makeNativeMethod("updateTouchPoints",
45
- JniSkiaDrawView::updateTouchPoints),
46
- makeNativeMethod("registerView", JniSkiaDrawView::registerView),
47
- makeNativeMethod("unregisterView", JniSkiaDrawView::unregisterView)
48
- });
49
- }
50
-
51
- protected:
52
- void updateTouchPoints(jni::JArrayDouble touches) override {
53
- JniSkiaBaseView::updateTouchPoints(touches);
54
- }
55
-
56
- void surfaceAvailable(jobject surface, int width, int height) override {
57
- JniSkiaBaseView::surfaceAvailable(surface, width, height);
58
- }
59
-
60
- void surfaceSizeChanged(int width, int height) override {
61
- JniSkiaBaseView::surfaceSizeChanged(width, height);
62
- }
63
-
64
- void surfaceDestroyed() override { JniSkiaBaseView::surfaceDestroyed(); }
65
-
66
- void setMode(std::string mode) override {
67
- JniSkiaBaseView::setMode(mode);
68
- }
69
-
70
- void setDebugMode(bool show) override {
71
- JniSkiaBaseView::setDebugMode(show);
72
- }
73
-
74
- void registerView(int nativeId) override {
75
- JniSkiaBaseView::registerView(nativeId);
76
- }
77
-
78
- void unregisterView() override {
79
- JniSkiaBaseView::unregisterView();
80
- }
81
-
82
- private:
83
- friend HybridBase;
84
-
85
- explicit JniSkiaDrawView(jni::alias_ref<jhybridobject> jThis,
86
- jni::alias_ref<JniSkiaManager::javaobject> skiaManager) :
87
- JniSkiaBaseView(skiaManager,
88
- std::make_shared<RNSkAndroidView<RNSkia::RNSkJsView>>(
89
- skiaManager->cthis()->getPlatformContext())) {
90
- }
91
-
92
- jni::global_ref<javaobject> javaPart_;
93
- };
20
+ namespace jsi = facebook::jsi;
21
+ namespace jni = facebook::jni;
22
+
23
+ class JniSkiaDrawView : public jni::HybridClass<JniSkiaDrawView>,
24
+ public JniSkiaBaseView {
25
+ public:
26
+ static auto constexpr kJavaDescriptor =
27
+ "Lcom/shopify/reactnative/skia/SkiaDrawView;";
28
+
29
+ static jni::local_ref<jhybriddata>
30
+ initHybrid(jni::alias_ref<jhybridobject> jThis,
31
+ jni::alias_ref<JniSkiaManager::javaobject> skiaManager) {
32
+ return makeCxxInstance(jThis, skiaManager);
33
+ }
34
+
35
+ static void registerNatives() {
36
+ registerHybrid(
37
+ {makeNativeMethod("initHybrid", JniSkiaDrawView::initHybrid),
38
+ makeNativeMethod("surfaceAvailable",
39
+ JniSkiaDrawView::surfaceAvailable),
40
+ makeNativeMethod("surfaceDestroyed",
41
+ JniSkiaDrawView::surfaceDestroyed),
42
+ makeNativeMethod("surfaceSizeChanged",
43
+ JniSkiaDrawView::surfaceSizeChanged),
44
+ makeNativeMethod("setMode", JniSkiaDrawView::setMode),
45
+ makeNativeMethod("setDebugMode", JniSkiaDrawView::setDebugMode),
46
+ makeNativeMethod("updateTouchPoints",
47
+ JniSkiaDrawView::updateTouchPoints),
48
+ makeNativeMethod("registerView", JniSkiaDrawView::registerView),
49
+ makeNativeMethod("unregisterView", JniSkiaDrawView::unregisterView)});
50
+ }
51
+
52
+ protected:
53
+ void updateTouchPoints(jni::JArrayDouble touches) override {
54
+ JniSkiaBaseView::updateTouchPoints(touches);
55
+ }
56
+
57
+ void surfaceAvailable(jobject surface, int width, int height) override {
58
+ JniSkiaBaseView::surfaceAvailable(surface, width, height);
59
+ }
60
+
61
+ void surfaceSizeChanged(int width, int height) override {
62
+ JniSkiaBaseView::surfaceSizeChanged(width, height);
63
+ }
64
+
65
+ void surfaceDestroyed() override { JniSkiaBaseView::surfaceDestroyed(); }
66
+
67
+ void setMode(std::string mode) override { JniSkiaBaseView::setMode(mode); }
68
+
69
+ void setDebugMode(bool show) override { JniSkiaBaseView::setDebugMode(show); }
70
+
71
+ void registerView(int nativeId) override {
72
+ JniSkiaBaseView::registerView(nativeId);
73
+ }
74
+
75
+ void unregisterView() override { JniSkiaBaseView::unregisterView(); }
76
+
77
+ private:
78
+ friend HybridBase;
79
+
80
+ explicit JniSkiaDrawView(
81
+ jni::alias_ref<jhybridobject> jThis,
82
+ jni::alias_ref<JniSkiaManager::javaobject> skiaManager)
83
+ : JniSkiaBaseView(skiaManager,
84
+ std::make_shared<RNSkAndroidView<RNSkia::RNSkJsView>>(
85
+ skiaManager->cthis()->getPlatformContext())) {}
86
+
87
+ jni::global_ref<javaobject> javaPart_;
88
+ };
94
89
 
95
90
  } // namespace RNSkia
@@ -8,14 +8,14 @@
8
8
 
9
9
  #include <JniPlatformContext.h>
10
10
  #include <RNSkAndroidPlatformContext.h>
11
- #include <RNSkManager.h>
12
11
  #include <RNSkLog.h>
12
+ #include <RNSkManager.h>
13
13
 
14
14
  namespace RNSkia {
15
15
 
16
16
  class RNSkManager;
17
17
 
18
- using namespace facebook;
18
+ namespace jsi = facebook::jsi;
19
19
 
20
20
  using JSCallInvokerHolder =
21
21
  jni::alias_ref<facebook::react::CallInvokerHolder::javaobject>;
@@ -23,57 +23,55 @@ using JSCallInvokerHolder =
23
23
  using JavaPlatformContext = jni::alias_ref<JniPlatformContext::javaobject>;
24
24
 
25
25
  class JniSkiaManager : public jni::HybridClass<JniSkiaManager> {
26
- public:
27
- static auto constexpr kJavaDescriptor = "Lcom/shopify/reactnative/skia/SkiaManager;";
28
- static auto constexpr TAG = "ReactNativeSkia";
29
-
30
- static jni::local_ref<jni::HybridClass<JniSkiaManager>::jhybriddata> initHybrid(
31
- jni::alias_ref<jhybridobject> jThis,
32
- jlong jsContext,
33
- JSCallInvokerHolder jsCallInvokerHolder,
34
- JavaPlatformContext platformContext);
35
-
36
- static void registerNatives();
37
-
38
- JniSkiaManager() {}
39
- ~JniSkiaManager() {
40
- RNSkLogger::logToConsole("JniSkiaManager dtor");
41
- }
42
-
43
- explicit JniSkiaManager(
44
- jni::alias_ref<JniSkiaManager::jhybridobject> jThis,
45
- jsi::Runtime *runtime,
46
- std::shared_ptr<facebook::react::CallInvoker> jsCallInvoker,
47
- JniPlatformContext* platformContext)
48
- : _javaPart(jni::make_global(jThis)),
49
- _jsRuntime(runtime),
50
- _jsCallInvoker(jsCallInvoker),
51
- _context(std::make_shared<RNSkAndroidPlatformContext>(platformContext, runtime, jsCallInvoker)) {
52
-
53
- }
54
-
55
- std::shared_ptr<RNSkAndroidPlatformContext> getPlatformContext() { return _context; }
56
- std::shared_ptr<RNSkManager> getSkiaManager() { return _skManager; }
57
-
58
- void invalidate() {
59
- _context->stopDrawLoop();
60
- _context->notifyDrawLoop(true);
61
- _skManager = nullptr;
62
- _context = nullptr;
63
- }
64
-
65
- private:
66
- friend HybridBase;
67
-
68
- std::shared_ptr<RNSkManager> _skManager;
69
-
70
- jni::global_ref<JniSkiaManager::javaobject> _javaPart;
71
-
72
- jsi::Runtime *_jsRuntime;
73
- std::shared_ptr<facebook::react::CallInvoker> _jsCallInvoker;
74
- std::shared_ptr<RNSkAndroidPlatformContext> _context;
75
-
76
- void initializeRuntime();
26
+ public:
27
+ static auto constexpr kJavaDescriptor =
28
+ "Lcom/shopify/reactnative/skia/SkiaManager;";
29
+ static auto constexpr TAG = "ReactNativeSkia";
30
+
31
+ static jni::local_ref<jni::HybridClass<JniSkiaManager>::jhybriddata>
32
+ initHybrid(jni::alias_ref<jhybridobject> jThis, jlong jsContext,
33
+ JSCallInvokerHolder jsCallInvokerHolder,
34
+ JavaPlatformContext platformContext);
35
+
36
+ static void registerNatives();
37
+
38
+ JniSkiaManager() {}
39
+ ~JniSkiaManager() { RNSkLogger::logToConsole("JniSkiaManager dtor"); }
40
+
41
+ explicit JniSkiaManager(
42
+ jni::alias_ref<JniSkiaManager::jhybridobject> jThis,
43
+ jsi::Runtime *runtime,
44
+ std::shared_ptr<facebook::react::CallInvoker> jsCallInvoker,
45
+ JniPlatformContext *platformContext)
46
+ : _javaPart(jni::make_global(jThis)), _jsRuntime(runtime),
47
+ _jsCallInvoker(jsCallInvoker),
48
+ _context(std::make_shared<RNSkAndroidPlatformContext>(
49
+ platformContext, runtime, jsCallInvoker)) {}
50
+
51
+ std::shared_ptr<RNSkAndroidPlatformContext> getPlatformContext() {
52
+ return _context;
53
+ }
54
+ std::shared_ptr<RNSkManager> getSkiaManager() { return _skManager; }
55
+
56
+ void invalidate() {
57
+ _context->stopDrawLoop();
58
+ _context->notifyDrawLoop(true);
59
+ _skManager = nullptr;
60
+ _context = nullptr;
61
+ }
62
+
63
+ private:
64
+ friend HybridBase;
65
+
66
+ std::shared_ptr<RNSkManager> _skManager;
67
+
68
+ jni::global_ref<JniSkiaManager::javaobject> _javaPart;
69
+
70
+ jsi::Runtime *_jsRuntime;
71
+ std::shared_ptr<facebook::react::CallInvoker> _jsCallInvoker;
72
+ std::shared_ptr<RNSkAndroidPlatformContext> _context;
73
+
74
+ void initializeRuntime();
77
75
  };
78
76
 
79
77
  } // namespace RNSkia
@@ -1,96 +1,92 @@
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
- #include <RNSkPictureView.h>
10
- #include <RNSkAndroidView.h>
11
10
  #include <JniSkiaBaseView.h>
12
11
  #include <JniSkiaManager.h>
12
+ #include <RNSkAndroidView.h>
13
+ #include <RNSkPictureView.h>
13
14
 
14
15
  #include <android/native_window.h>
15
16
  #include <android/native_window_jni.h>
16
17
  #include <fbjni/detail/Hybrid.h>
17
18
 
18
19
  namespace RNSkia {
19
- using namespace facebook;
20
- using namespace jni;
21
-
22
- class JniSkiaPictureView
23
- : public HybridClass<JniSkiaPictureView>, public JniSkiaBaseView {
24
- public:
25
- static auto constexpr kJavaDescriptor = "Lcom/shopify/reactnative/skia/SkiaPictureView;";
26
-
27
- static jni::local_ref<jhybriddata>
28
- initHybrid(jni::alias_ref<jhybridobject> jThis,
29
- jni::alias_ref<JniSkiaManager::javaobject> skiaManager) {
30
- return makeCxxInstance(jThis, skiaManager);
31
- }
32
-
33
- static void registerNatives() {
34
- registerHybrid({
35
- makeNativeMethod("initHybrid", JniSkiaPictureView::initHybrid),
36
- makeNativeMethod("surfaceAvailable",
37
- JniSkiaPictureView::surfaceAvailable),
38
- makeNativeMethod("surfaceDestroyed",
39
- JniSkiaPictureView::surfaceDestroyed),
40
- makeNativeMethod("surfaceSizeChanged",
41
- JniSkiaPictureView::surfaceSizeChanged),
42
- makeNativeMethod("setMode", JniSkiaPictureView::setMode),
43
- makeNativeMethod("setDebugMode", JniSkiaPictureView::setDebugMode),
44
- makeNativeMethod("updateTouchPoints",
45
- JniSkiaPictureView::updateTouchPoints),
46
- makeNativeMethod("registerView", JniSkiaPictureView::registerView),
47
- makeNativeMethod("unregisterView",
48
- JniSkiaPictureView::unregisterView)
49
- });
50
- }
51
-
52
- protected:
53
- void updateTouchPoints(jni::JArrayDouble touches) override {
54
- JniSkiaBaseView::updateTouchPoints(touches);
55
- }
56
-
57
- void surfaceAvailable(jobject surface, int width, int height) override {
58
- JniSkiaBaseView::surfaceAvailable(surface, width, height);
59
- }
60
-
61
- void surfaceSizeChanged(int width, int height) override {
62
- JniSkiaBaseView::surfaceSizeChanged(width, height);
63
- }
64
-
65
- void surfaceDestroyed() override { JniSkiaBaseView::surfaceDestroyed(); }
66
-
67
- void setMode(std::string mode) override {
68
- JniSkiaBaseView::setMode(mode);
69
- }
70
-
71
- void setDebugMode(bool show) override {
72
- JniSkiaBaseView::setDebugMode(show);
73
- }
74
-
75
- void registerView(int nativeId) override {
76
- JniSkiaBaseView::registerView(nativeId);
77
- }
78
-
79
- void unregisterView() override {
80
- JniSkiaBaseView::unregisterView();
81
- }
82
-
83
- private:
84
- friend HybridBase;
85
-
86
- explicit JniSkiaPictureView(jni::alias_ref<jhybridobject> jThis,
87
- jni::alias_ref<JniSkiaManager::javaobject> skiaManager) :
88
- JniSkiaBaseView(skiaManager,
89
- std::make_shared<RNSkAndroidView<RNSkia::RNSkPictureView>>(
90
- skiaManager->cthis()->getPlatformContext())) {
91
- }
92
-
93
- jni::global_ref<javaobject> javaPart_;
94
- };
20
+ namespace jsi = facebook::jsi;
21
+ namespace jni = facebook::jni;
22
+
23
+ class JniSkiaPictureView : public jni::HybridClass<JniSkiaPictureView>,
24
+ public JniSkiaBaseView {
25
+ public:
26
+ static auto constexpr kJavaDescriptor =
27
+ "Lcom/shopify/reactnative/skia/SkiaPictureView;";
28
+
29
+ static jni::local_ref<jhybriddata>
30
+ initHybrid(jni::alias_ref<jhybridobject> jThis,
31
+ jni::alias_ref<JniSkiaManager::javaobject> skiaManager) {
32
+ return makeCxxInstance(jThis, skiaManager);
33
+ }
34
+
35
+ static void registerNatives() {
36
+ registerHybrid(
37
+ {makeNativeMethod("initHybrid", JniSkiaPictureView::initHybrid),
38
+ makeNativeMethod("surfaceAvailable",
39
+ JniSkiaPictureView::surfaceAvailable),
40
+ makeNativeMethod("surfaceDestroyed",
41
+ JniSkiaPictureView::surfaceDestroyed),
42
+ makeNativeMethod("surfaceSizeChanged",
43
+ JniSkiaPictureView::surfaceSizeChanged),
44
+ makeNativeMethod("setMode", JniSkiaPictureView::setMode),
45
+ makeNativeMethod("setDebugMode", JniSkiaPictureView::setDebugMode),
46
+ makeNativeMethod("updateTouchPoints",
47
+ JniSkiaPictureView::updateTouchPoints),
48
+ makeNativeMethod("registerView", JniSkiaPictureView::registerView),
49
+ makeNativeMethod("unregisterView",
50
+ JniSkiaPictureView::unregisterView)});
51
+ }
52
+
53
+ protected:
54
+ void updateTouchPoints(jni::JArrayDouble touches) override {
55
+ JniSkiaBaseView::updateTouchPoints(touches);
56
+ }
57
+
58
+ void surfaceAvailable(jobject surface, int width, int height) override {
59
+ JniSkiaBaseView::surfaceAvailable(surface, width, height);
60
+ }
61
+
62
+ void surfaceSizeChanged(int width, int height) override {
63
+ JniSkiaBaseView::surfaceSizeChanged(width, height);
64
+ }
65
+
66
+ void surfaceDestroyed() override { JniSkiaBaseView::surfaceDestroyed(); }
67
+
68
+ void setMode(std::string mode) override { JniSkiaBaseView::setMode(mode); }
69
+
70
+ void setDebugMode(bool show) override { JniSkiaBaseView::setDebugMode(show); }
71
+
72
+ void registerView(int nativeId) override {
73
+ JniSkiaBaseView::registerView(nativeId);
74
+ }
75
+
76
+ void unregisterView() override { JniSkiaBaseView::unregisterView(); }
77
+
78
+ private:
79
+ friend HybridBase;
80
+
81
+ explicit JniSkiaPictureView(
82
+ jni::alias_ref<jhybridobject> jThis,
83
+ jni::alias_ref<JniSkiaManager::javaobject> skiaManager)
84
+ : JniSkiaBaseView(
85
+ skiaManager,
86
+ std::make_shared<RNSkAndroidView<RNSkia::RNSkPictureView>>(
87
+ skiaManager->cthis()->getPlatformContext())) {}
88
+
89
+ jni::global_ref<javaobject> javaPart_;
90
+ };
95
91
 
96
92
  } // namespace RNSkia
@@ -1,54 +1,45 @@
1
1
  #pragma once
2
2
 
3
+ #include <exception>
3
4
  #include <functional>
4
- #include <string>
5
5
  #include <memory>
6
- #include <exception>
6
+ #include <string>
7
7
 
8
8
  #include <JniPlatformContext.h>
9
9
  #include <RNSkPlatformContext.h>
10
10
 
11
11
  namespace RNSkia {
12
- using namespace facebook;
13
-
14
- class RNSkAndroidPlatformContext: public RNSkPlatformContext {
15
- public:
16
- RNSkAndroidPlatformContext(JniPlatformContext* jniPlatformContext,
17
- jsi::Runtime *runtime,
18
- std::shared_ptr<facebook::react::CallInvoker> jsCallInvoker) :
19
- RNSkPlatformContext(runtime,
20
- jsCallInvoker,
21
- jniPlatformContext->getPixelDensity()),
22
- _jniPlatformContext(jniPlatformContext) {
23
- // Hook onto the notify draw loop callback in the platform context
24
- jniPlatformContext->setOnNotifyDrawLoop([this]() {
25
- notifyDrawLoop(false);
26
- });
27
- }
28
-
29
-
30
- void performStreamOperation(
31
- const std::string &sourceUri,
32
- const std::function<void(std::unique_ptr<SkStreamAsset>)> &op) override {
33
- _jniPlatformContext->performStreamOperation(sourceUri, op);
34
- }
35
-
36
- void raiseError(const std::exception &err) override {
37
- _jniPlatformContext->raiseError(err);
38
- }
39
-
40
- void startDrawLoop() override {
41
- _jniPlatformContext->startDrawLoop();
42
- }
43
-
44
- void stopDrawLoop() override {
45
- _jniPlatformContext->stopDrawLoop();
46
- }
47
-
48
- private:
49
-
50
- JniPlatformContext* _jniPlatformContext;
51
- };
52
-
53
- }
54
-
12
+ namespace jsi = facebook::jsi;
13
+
14
+ class RNSkAndroidPlatformContext : public RNSkPlatformContext {
15
+ public:
16
+ RNSkAndroidPlatformContext(
17
+ JniPlatformContext *jniPlatformContext, jsi::Runtime *runtime,
18
+ std::shared_ptr<facebook::react::CallInvoker> jsCallInvoker)
19
+ : RNSkPlatformContext(runtime, jsCallInvoker,
20
+ jniPlatformContext->getPixelDensity()),
21
+ _jniPlatformContext(jniPlatformContext) {
22
+ // Hook onto the notify draw loop callback in the platform context
23
+ jniPlatformContext->setOnNotifyDrawLoop(
24
+ [this]() { notifyDrawLoop(false); });
25
+ }
26
+
27
+ void performStreamOperation(
28
+ const std::string &sourceUri,
29
+ const std::function<void(std::unique_ptr<SkStreamAsset>)> &op) override {
30
+ _jniPlatformContext->performStreamOperation(sourceUri, op);
31
+ }
32
+
33
+ void raiseError(const std::exception &err) override {
34
+ _jniPlatformContext->raiseError(err);
35
+ }
36
+
37
+ void startDrawLoop() override { _jniPlatformContext->startDrawLoop(); }
38
+
39
+ void stopDrawLoop() override { _jniPlatformContext->stopDrawLoop(); }
40
+
41
+ private:
42
+ JniPlatformContext *_jniPlatformContext;
43
+ };
44
+
45
+ } // namespace RNSkia