@shopify/react-native-skia 0.1.151 → 0.1.153

Sign up to get free protection for your applications and to get access to all the features.
Files changed (89) hide show
  1. package/android/CMakeLists.txt +5 -5
  2. package/android/cpp/jni/JniLoad.cpp +7 -5
  3. package/android/cpp/jni/JniSkiaManager.cpp +2 -15
  4. package/android/cpp/jni/include/JniSkiaBaseView.h +68 -0
  5. package/android/cpp/jni/include/JniSkiaDrawView.h +64 -47
  6. package/android/cpp/jni/include/JniSkiaManager.h +8 -10
  7. package/android/cpp/jni/include/JniSkiaPictureView.h +96 -0
  8. package/android/cpp/rnskia-android/{RNSkPlatformContextImpl.h → RNSkAndroidPlatformContext.h} +4 -4
  9. package/android/cpp/rnskia-android/RNSkAndroidView.h +100 -0
  10. package/android/cpp/rnskia-android/RNSkOpenGLCanvasProvider.cpp +91 -0
  11. package/android/cpp/rnskia-android/RNSkOpenGLCanvasProvider.h +39 -0
  12. package/android/cpp/rnskia-android/SkiaOpenGLRenderer.cpp +15 -6
  13. package/android/cpp/rnskia-android/SkiaOpenGLRenderer.h +5 -4
  14. package/android/src/main/java/com/shopify/reactnative/skia/PlatformContext.java +5 -11
  15. package/android/src/main/java/com/shopify/reactnative/skia/RNSkiaPackage.java +1 -2
  16. package/android/src/main/java/com/shopify/reactnative/skia/SkiaBaseView.java +143 -0
  17. package/android/src/main/java/com/shopify/reactnative/skia/SkiaDrawView.java +17 -145
  18. package/android/src/main/java/com/shopify/reactnative/skia/{RNSkiaViewManager.java → SkiaDrawViewManager.java} +4 -15
  19. package/android/src/main/java/com/shopify/reactnative/skia/SkiaManager.java +1 -10
  20. package/android/src/main/java/com/shopify/reactnative/skia/SkiaPictureView.java +45 -0
  21. package/android/src/main/java/com/shopify/reactnative/skia/SkiaPictureViewManager.java +64 -0
  22. package/cpp/jsi/JsiValueWrapper.h +11 -0
  23. package/cpp/rnskia/RNSkInfoParameter.h +4 -14
  24. package/cpp/rnskia/RNSkJsView.cpp +211 -0
  25. package/cpp/rnskia/RNSkJsView.h +115 -0
  26. package/cpp/rnskia/RNSkJsiViewApi.h +6 -6
  27. package/cpp/rnskia/RNSkManager.cpp +7 -7
  28. package/cpp/rnskia/RNSkManager.h +7 -7
  29. package/cpp/rnskia/RNSkPictureView.h +124 -0
  30. package/cpp/rnskia/RNSkView.h +287 -0
  31. package/ios/RNSkia-iOS/RNSkMetalCanvasProvider.h +38 -0
  32. package/ios/RNSkia-iOS/{RNSkDrawViewImpl.mm → RNSkMetalCanvasProvider.mm} +46 -23
  33. package/ios/RNSkia-iOS/{PlatformContext.h → RNSkiOSPlatformContext.h} +4 -4
  34. package/ios/RNSkia-iOS/{PlatformContext.mm → RNSkiOSPlatformContext.mm} +5 -5
  35. package/ios/RNSkia-iOS/RNSkiOSView.h +34 -0
  36. package/ios/RNSkia-iOS/SkiaDrawViewManager.mm +19 -11
  37. package/ios/RNSkia-iOS/SkiaManager.mm +3 -3
  38. package/ios/RNSkia-iOS/SkiaPictureViewManager.h +8 -0
  39. package/ios/RNSkia-iOS/SkiaPictureViewManager.mm +51 -0
  40. package/ios/RNSkia-iOS/SkiaUIView.h +26 -0
  41. package/ios/RNSkia-iOS/{SkiaDrawView.mm → SkiaUIView.mm} +29 -23
  42. package/lib/commonjs/views/SkiaBaseWebView.js +213 -0
  43. package/lib/commonjs/views/SkiaBaseWebView.js.map +1 -0
  44. package/lib/commonjs/views/SkiaPictureView.js +112 -0
  45. package/lib/commonjs/views/SkiaPictureView.js.map +1 -0
  46. package/lib/commonjs/views/SkiaPictureView.web.js +31 -0
  47. package/lib/commonjs/views/SkiaPictureView.web.js.map +1 -0
  48. package/lib/commonjs/views/SkiaView.js +1 -1
  49. package/lib/commonjs/views/SkiaView.js.map +1 -1
  50. package/lib/commonjs/views/SkiaView.web.js +14 -201
  51. package/lib/commonjs/views/SkiaView.web.js.map +1 -1
  52. package/lib/commonjs/views/index.js +13 -0
  53. package/lib/commonjs/views/index.js.map +1 -1
  54. package/lib/commonjs/views/types.js.map +1 -1
  55. package/lib/module/views/SkiaBaseWebView.js +198 -0
  56. package/lib/module/views/SkiaBaseWebView.js.map +1 -0
  57. package/lib/module/views/SkiaPictureView.js +94 -0
  58. package/lib/module/views/SkiaPictureView.js.map +1 -0
  59. package/lib/module/views/SkiaPictureView.web.js +19 -0
  60. package/lib/module/views/SkiaPictureView.web.js.map +1 -0
  61. package/lib/module/views/SkiaView.js +1 -1
  62. package/lib/module/views/SkiaView.js.map +1 -1
  63. package/lib/module/views/SkiaView.web.js +15 -199
  64. package/lib/module/views/SkiaView.web.js.map +1 -1
  65. package/lib/module/views/index.js +1 -0
  66. package/lib/module/views/index.js.map +1 -1
  67. package/lib/module/views/types.js.map +1 -1
  68. package/lib/typescript/src/views/SkiaBaseWebView.d.ts +58 -0
  69. package/lib/typescript/src/views/SkiaPictureView.d.ts +27 -0
  70. package/lib/typescript/src/views/SkiaPictureView.web.d.ts +7 -0
  71. package/lib/typescript/src/views/SkiaView.d.ts +4 -4
  72. package/lib/typescript/src/views/SkiaView.web.d.ts +6 -53
  73. package/lib/typescript/src/views/index.d.ts +1 -0
  74. package/lib/typescript/src/views/types.d.ts +7 -2
  75. package/package.json +3 -3
  76. package/src/views/SkiaBaseWebView.tsx +177 -0
  77. package/src/views/SkiaPictureView.tsx +93 -0
  78. package/src/views/SkiaPictureView.web.tsx +23 -0
  79. package/src/views/SkiaView.tsx +6 -7
  80. package/src/views/SkiaView.web.tsx +18 -167
  81. package/src/views/index.ts +1 -0
  82. package/src/views/types.ts +9 -2
  83. package/android/cpp/jni/JniSkiaDrawView.cpp +0 -113
  84. package/android/cpp/rnskia-android/RNSkDrawViewImpl.cpp +0 -73
  85. package/android/cpp/rnskia-android/RNSkDrawViewImpl.h +0 -48
  86. package/cpp/rnskia/RNSkDrawView.cpp +0 -315
  87. package/cpp/rnskia/RNSkDrawView.h +0 -226
  88. package/ios/RNSkia-iOS/RNSkDrawViewImpl.h +0 -52
  89. package/ios/RNSkia-iOS/SkiaDrawView.h +0 -23
@@ -1,3 +1,4 @@
1
+ project(RNSkia)
1
2
  cmake_minimum_required(VERSION 3.4.1)
2
3
 
3
4
  if(${BUILD_TYPE} STREQUAL "debug")
@@ -34,18 +35,17 @@ add_library(
34
35
  SHARED
35
36
  "${PROJECT_SOURCE_DIR}/cpp/jni/JniLoad.cpp"
36
37
  "${PROJECT_SOURCE_DIR}/cpp/jni/JniSkiaManager.cpp"
37
- "${PROJECT_SOURCE_DIR}/cpp/jni/JniSkiaDrawView.cpp"
38
+
38
39
  "${PROJECT_SOURCE_DIR}/cpp/jni/JniPlatformContext.cpp"
39
- "${PROJECT_SOURCE_DIR}/cpp/rnskia-android/RNSkDrawViewImpl.cpp"
40
+ "${PROJECT_SOURCE_DIR}/cpp/rnskia-android/RNSkOpenGLCanvasProvider.cpp"
40
41
  "${PROJECT_SOURCE_DIR}/cpp/rnskia-android/SkiaOpenGLRenderer.cpp"
41
-
42
+
42
43
  "${PROJECT_SOURCE_DIR}/cpp/jsi/JsiHostObject.cpp"
43
44
 
44
45
  "${PROJECT_SOURCE_DIR}/cpp/rnskia/RNSkManager.cpp"
45
- "${PROJECT_SOURCE_DIR}/cpp/rnskia/RNSkDrawView.cpp"
46
+ "${PROJECT_SOURCE_DIR}/cpp/rnskia/RNSkJsView.cpp"
46
47
  "${PROJECT_SOURCE_DIR}/cpp/rnskia/RNSkDispatchQueue.cpp"
47
48
 
48
-
49
49
  "${PROJECT_SOURCE_DIR}/cpp/api/third_party/CSSColorParser.cpp"
50
50
 
51
51
  )
@@ -1,13 +1,15 @@
1
1
  #include "JniPlatformContext.h"
2
2
  #include "JniSkiaDrawView.h"
3
+ #include "JniSkiaPictureView.h"
3
4
  #include "JniSkiaManager.h"
4
5
  #include <fbjni/fbjni.h>
5
6
  #include <jni.h>
6
7
 
7
8
  JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM *vm, void *) {
8
- return facebook::jni::initialize(vm, [] {
9
- RNSkia::JniSkiaManager::registerNatives();
10
- RNSkia::JniSkiaDrawView::registerNatives();
11
- RNSkia::JniPlatformContext::registerNatives();
12
- });
9
+ return facebook::jni::initialize(vm, [] {
10
+ RNSkia::JniSkiaManager::registerNatives();
11
+ RNSkia::JniSkiaDrawView::registerNatives();
12
+ RNSkia::JniSkiaPictureView::registerNatives();
13
+ RNSkia::JniPlatformContext::registerNatives();
14
+ });
13
15
  }
@@ -16,13 +16,8 @@ using namespace facebook;
16
16
  void JniSkiaManager::registerNatives() {
17
17
  registerHybrid({
18
18
  makeNativeMethod("initHybrid", JniSkiaManager::initHybrid),
19
- makeNativeMethod(
20
- "initializeRuntime", JniSkiaManager::initializeRuntime),
21
- makeNativeMethod("registerSkiaView", JniSkiaManager::registerSkiaView),
22
- makeNativeMethod(
23
- "unregisterSkiaView", JniSkiaManager::unregisterSkiaView),
24
- makeNativeMethod(
25
- "invalidate", JniSkiaManager::invalidate),
19
+ makeNativeMethod("initializeRuntime", JniSkiaManager::initializeRuntime),
20
+ makeNativeMethod("invalidate", JniSkiaManager::invalidate),
26
21
  });
27
22
  }
28
23
 
@@ -46,12 +41,4 @@ void JniSkiaManager::initializeRuntime() {
46
41
  _skManager = std::make_shared<RNSkManager>(_jsRuntime, _jsCallInvoker, _context);
47
42
  }
48
43
 
49
- void JniSkiaManager::registerSkiaView(int viewTag, JniSkiaDrawView *skiaView) {
50
- _skManager->registerSkiaDrawView(viewTag, skiaView->getDrawViewImpl());
51
- }
52
-
53
- void JniSkiaManager::unregisterSkiaView(int viewTag) {
54
- _skManager->unregisterSkiaDrawView(viewTag);
55
- }
56
-
57
44
  } // namespace RNSkia
@@ -0,0 +1,68 @@
1
+ #pragma once
2
+
3
+ #include <memory>
4
+
5
+ #include <fbjni/fbjni.h>
6
+ #include <jni.h>
7
+ #include <jsi/jsi.h>
8
+
9
+ #include <JniSkiaManager.h>
10
+
11
+ 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
+ };
67
+
68
+ } // namespace RNSkia
@@ -1,78 +1,95 @@
1
1
  #pragma once
2
2
 
3
- #include <map>
4
3
  #include <memory>
5
- #include <thread>
6
- #include <string>
7
4
 
8
5
  #include <fbjni/fbjni.h>
9
6
  #include <jni.h>
10
7
  #include <jsi/jsi.h>
11
- #include <thread>
12
8
 
13
- #include <RNSkDrawView.h>
9
+ #include <RNSkJsView.h>
10
+ #include <RNSkAndroidView.h>
11
+ #include <JniSkiaBaseView.h>
14
12
  #include <JniSkiaManager.h>
15
- #include <JniSkiaDrawView.h>
16
13
 
17
- #include <RNSkDrawViewImpl.h>
14
+ #include <android/native_window.h>
15
+ #include <android/native_window_jni.h>
16
+ #include <fbjni/detail/Hybrid.h>
18
17
 
19
- #include <SkSurface.h>
20
- #include <SkRefCnt.h>
21
- #include <gpu/GrBackendSurface.h>
22
- #include <gpu/GrDirectContext.h>
23
-
24
- class SkPicture;
25
- class ANativeWindow;
26
-
27
- namespace RNSkia
28
- {
18
+ namespace RNSkia {
29
19
  using namespace facebook;
20
+ using namespace jni;
30
21
 
31
- using JavaSkiaManager = jni::alias_ref<JniSkiaManager::javaobject>;
32
-
33
- class JniSkiaDrawView : public jni::HybridClass<JniSkiaDrawView>
34
- {
22
+ class JniSkiaDrawView
23
+ : public HybridClass<JniSkiaDrawView>, public JniSkiaBaseView {
35
24
  public:
36
25
  static auto constexpr kJavaDescriptor = "Lcom/shopify/reactnative/skia/SkiaDrawView;";
37
- static auto constexpr TAG = "ReactNativeSkia";
38
26
 
39
- static jni::local_ref<jhybriddata> initHybrid(
40
- jni::alias_ref<jhybridobject>,
41
- JavaSkiaManager);
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
+ }
42
32
 
43
- static void registerNatives();
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
+ }
44
50
 
45
- void surfaceAvailable(jobject, int, int);
46
- void surfaceDestroyed();
47
- void surfaceSizeChanged(int, int);
51
+ protected:
52
+ void updateTouchPoints(jni::JArrayDouble touches) override {
53
+ JniSkiaBaseView::updateTouchPoints(touches);
54
+ }
48
55
 
49
- void updateTouchPoints(jni::JArrayDouble touches);
56
+ void surfaceAvailable(jobject surface, int width, int height) override {
57
+ JniSkiaBaseView::surfaceAvailable(surface, width, height);
58
+ }
50
59
 
51
- ~JniSkiaDrawView();
60
+ void surfaceSizeChanged(int width, int height) override {
61
+ JniSkiaBaseView::surfaceSizeChanged(width, height);
62
+ }
52
63
 
53
- std::shared_ptr<RNSkDrawView> getDrawViewImpl() { return _drawView; }
64
+ void surfaceDestroyed() override { JniSkiaBaseView::surfaceDestroyed(); }
54
65
 
55
- void releaseSurface();
66
+ void setMode(std::string mode) override {
67
+ JniSkiaBaseView::setMode(mode);
68
+ }
56
69
 
57
- protected:
58
- void setMode(std::string mode);
59
- void setDebugMode(bool show);
70
+ void setDebugMode(bool show) override {
71
+ JniSkiaBaseView::setDebugMode(show);
72
+ }
60
73
 
61
- private:
62
- friend HybridBase;
74
+ void registerView(int nativeId) override {
75
+ JniSkiaBaseView::registerView(nativeId);
76
+ }
63
77
 
64
- std::shared_ptr<RNSkDrawViewImpl> _drawView;
78
+ void unregisterView() override {
79
+ JniSkiaBaseView::unregisterView();
80
+ }
65
81
 
66
- jni::global_ref<JniSkiaDrawView::javaobject> javaPart_;
82
+ private:
83
+ friend HybridBase;
67
84
 
68
- explicit JniSkiaDrawView(
69
- jni::alias_ref<JniSkiaDrawView::jhybridobject> jThis,
70
- JavaSkiaManager skiaManager)
71
- : javaPart_(jni::make_global(jThis)),
72
- _drawView(std::make_shared<RNSkDrawViewImpl>(skiaManager->cthis()->getPlatformContext(), [this]() {
73
- releaseSurface();
74
- })) {
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())) {
75
90
  }
91
+
92
+ jni::global_ref<javaobject> javaPart_;
76
93
  };
77
94
 
78
95
  } // namespace RNSkia
@@ -7,12 +7,14 @@
7
7
  #include <memory>
8
8
 
9
9
  #include <JniPlatformContext.h>
10
- #include <RNSkPlatformContextImpl.h>
11
-
10
+ #include <RNSkAndroidPlatformContext.h>
11
+ #include <RNSkManager.h>
12
12
  #include <RNSkLog.h>
13
13
 
14
14
  namespace RNSkia {
15
+
15
16
  class RNSkManager;
17
+
16
18
  using namespace facebook;
17
19
 
18
20
  using JSCallInvokerHolder =
@@ -20,8 +22,6 @@ using JSCallInvokerHolder =
20
22
 
21
23
  using JavaPlatformContext = jni::alias_ref<JniPlatformContext::javaobject>;
22
24
 
23
- class JniSkiaDrawView;
24
-
25
25
  class JniSkiaManager : public jni::HybridClass<JniSkiaManager> {
26
26
  public:
27
27
  static auto constexpr kJavaDescriptor = "Lcom/shopify/reactnative/skia/SkiaManager;";
@@ -48,14 +48,12 @@ class JniSkiaManager : public jni::HybridClass<JniSkiaManager> {
48
48
  : _javaPart(jni::make_global(jThis)),
49
49
  _jsRuntime(runtime),
50
50
  _jsCallInvoker(jsCallInvoker),
51
- _context(std::make_shared<RNSkPlatformContextImpl>(platformContext, runtime, jsCallInvoker)) {
51
+ _context(std::make_shared<RNSkAndroidPlatformContext>(platformContext, runtime, jsCallInvoker)) {
52
52
 
53
53
  }
54
54
 
55
- void registerSkiaView(int viewTag, JniSkiaDrawView *skiaView);
56
- void unregisterSkiaView(int viewTag);
57
-
58
- std::shared_ptr<RNSkPlatformContextImpl> getPlatformContext() { return _context; }
55
+ std::shared_ptr<RNSkAndroidPlatformContext> getPlatformContext() { return _context; }
56
+ std::shared_ptr<RNSkManager> getSkiaManager() { return _skManager; }
59
57
 
60
58
  void invalidate() {
61
59
  _context->stopDrawLoop();
@@ -73,7 +71,7 @@ class JniSkiaManager : public jni::HybridClass<JniSkiaManager> {
73
71
 
74
72
  jsi::Runtime *_jsRuntime;
75
73
  std::shared_ptr<facebook::react::CallInvoker> _jsCallInvoker;
76
- std::shared_ptr<RNSkPlatformContextImpl> _context;
74
+ std::shared_ptr<RNSkAndroidPlatformContext> _context;
77
75
 
78
76
  void initializeRuntime();
79
77
  };
@@ -0,0 +1,96 @@
1
+ #pragma once
2
+
3
+ #include <memory>
4
+
5
+ #include <fbjni/fbjni.h>
6
+ #include <jni.h>
7
+ #include <jsi/jsi.h>
8
+
9
+ #include <RNSkPictureView.h>
10
+ #include <RNSkAndroidView.h>
11
+ #include <JniSkiaBaseView.h>
12
+ #include <JniSkiaManager.h>
13
+
14
+ #include <android/native_window.h>
15
+ #include <android/native_window_jni.h>
16
+ #include <fbjni/detail/Hybrid.h>
17
+
18
+ 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
+ };
95
+
96
+ } // namespace RNSkia
@@ -11,11 +11,11 @@
11
11
  namespace RNSkia {
12
12
  using namespace facebook;
13
13
 
14
- class RNSkPlatformContextImpl: public RNSkPlatformContext {
14
+ class RNSkAndroidPlatformContext: public RNSkPlatformContext {
15
15
  public:
16
- RNSkPlatformContextImpl(JniPlatformContext* jniPlatformContext,
17
- jsi::Runtime *runtime,
18
- std::shared_ptr<facebook::react::CallInvoker> jsCallInvoker) :
16
+ RNSkAndroidPlatformContext(JniPlatformContext* jniPlatformContext,
17
+ jsi::Runtime *runtime,
18
+ std::shared_ptr<facebook::react::CallInvoker> jsCallInvoker) :
19
19
  RNSkPlatformContext(runtime,
20
20
  jsCallInvoker,
21
21
  jniPlatformContext->getPixelDensity()),
@@ -0,0 +1,100 @@
1
+ #pragma once
2
+
3
+ #include <RNSkJsView.h>
4
+ #include <RNSkOpenGLCanvasProvider.h>
5
+ #include <android/native_window.h>
6
+
7
+ namespace RNSkia {
8
+
9
+ class RNSkBaseAndroidView {
10
+ public:
11
+ virtual void surfaceAvailable(jobject surface, int width, int height) = 0;
12
+
13
+ virtual void surfaceDestroyed() = 0;
14
+
15
+ virtual void surfaceSizeChanged(int width, int height) = 0;
16
+
17
+ virtual float getPixelDensity() = 0;
18
+
19
+ virtual void updateTouchPoints(jni::JArrayDouble touches) = 0;
20
+
21
+ virtual void setMode(std::string mode) = 0;
22
+
23
+ virtual void setShowDebugInfo(bool show) = 0;
24
+
25
+ virtual void viewDidUnmount() = 0;
26
+
27
+ virtual std::shared_ptr<RNSkView> getSkiaView() = 0;
28
+ };
29
+
30
+ template<typename T>
31
+ class RNSkAndroidView
32
+ : public T, public RNSkBaseAndroidView {
33
+ public:
34
+ RNSkAndroidView(
35
+ std::shared_ptr<RNSkia::RNSkPlatformContext> context) :
36
+ T(context,
37
+ std::make_shared<RNSkOpenGLCanvasProvider>(
38
+ std::bind(&RNSkia::RNSkView::requestRedraw, this),
39
+ context)
40
+ ) {}
41
+
42
+ void surfaceAvailable(jobject surface, int width, int height) override {
43
+ std::static_pointer_cast<RNSkOpenGLCanvasProvider>(
44
+ T::getCanvasProvider())->surfaceAvailable(surface, width, height);
45
+ }
46
+
47
+ void surfaceDestroyed() override {
48
+ std::static_pointer_cast<RNSkOpenGLCanvasProvider>(
49
+ T::getCanvasProvider())->surfaceDestroyed();
50
+ }
51
+
52
+ void surfaceSizeChanged(int width, int height) override {
53
+ std::static_pointer_cast<RNSkOpenGLCanvasProvider>(
54
+ T::getCanvasProvider())->surfaceSizeChanged(width, height);
55
+ }
56
+
57
+ float getPixelDensity() override {
58
+ return T::getPlatformContext()->getPixelDensity();
59
+ }
60
+
61
+ void setMode(std::string mode) override {
62
+ if (mode.compare("continuous") == 0) {
63
+ T::setDrawingMode(RNSkDrawingMode::Continuous);
64
+ } else {
65
+ T::setDrawingMode(RNSkDrawingMode::Default);
66
+ }
67
+ }
68
+
69
+ void setShowDebugInfo(bool show) override {
70
+ T::setShowDebugOverlays(show);
71
+ }
72
+
73
+ void viewDidUnmount() override {
74
+ T::endDrawingLoop();
75
+ }
76
+
77
+ void updateTouchPoints(jni::JArrayDouble touches) override {
78
+ // Create touch points
79
+ std::vector<RNSkia::RNSkTouchInfo> points;
80
+ auto pin = touches.pin();
81
+ auto scale = getPixelDensity();
82
+ points.reserve(pin.size() / 5);
83
+ for (size_t i = 0; i < pin.size(); i += 5) {
84
+ RNSkTouchInfo point;
85
+ point.x = pin[i] / scale;
86
+ point.y = pin[i + 1] / scale;
87
+ point.force = pin[i + 2];
88
+ point.type = (RNSkia::RNSkTouchInfo::TouchType) pin[i + 3];
89
+ point.id = pin[i + 4];
90
+ points.push_back(point);
91
+ }
92
+ T::updateTouchState(points);
93
+ }
94
+
95
+ std::shared_ptr<RNSkView> getSkiaView() override {
96
+ return T::shared_from_this();
97
+ }
98
+
99
+ };
100
+ }
@@ -0,0 +1,91 @@
1
+ #include <RNSkOpenGLCanvasProvider.h>
2
+
3
+ #pragma clang diagnostic push
4
+ #pragma clang diagnostic ignored "-Wdocumentation"
5
+
6
+ #include <SkSurface.h>
7
+ #include <SkCanvas.h>
8
+
9
+ #pragma clang diagnostic pop
10
+
11
+ namespace RNSkia {
12
+
13
+ RNSkOpenGLCanvasProvider::RNSkOpenGLCanvasProvider(
14
+ std::function<void()> requestRedraw,
15
+ std::shared_ptr<RNSkia::RNSkPlatformContext> context):
16
+ RNSkCanvasProvider(requestRedraw),
17
+ _context(context) {}
18
+
19
+ RNSkOpenGLCanvasProvider::~RNSkOpenGLCanvasProvider() {}
20
+
21
+ float RNSkOpenGLCanvasProvider::getScaledWidth() {
22
+ return _width;
23
+ }
24
+
25
+ float RNSkOpenGLCanvasProvider::getScaledHeight() {
26
+ return _height;
27
+ }
28
+
29
+ void RNSkOpenGLCanvasProvider::renderToCanvas(const std::function<void(SkCanvas *)> &cb) {
30
+ if(_renderer != nullptr) {
31
+ _renderer->run(cb, _width, _height);
32
+ }
33
+ }
34
+
35
+ void RNSkOpenGLCanvasProvider::surfaceAvailable(jobject surface, int width, int height) {
36
+ _width = width;
37
+ _height = height;
38
+
39
+ if (_renderer == nullptr)
40
+ {
41
+ // Create renderer!
42
+ _renderer = std::make_unique<SkiaOpenGLRenderer>(surface);
43
+
44
+ // Redraw
45
+ _requestRedraw();
46
+ }
47
+ }
48
+ void RNSkOpenGLCanvasProvider::surfaceDestroyed() {
49
+ if (_renderer != nullptr)
50
+ {
51
+ // teardown
52
+ _renderer->teardown();
53
+
54
+ // Teardown renderer on the render thread since OpenGL demands
55
+ // same thread access for OpenGL contexts.
56
+ std::condition_variable cv;
57
+ std::mutex m;
58
+ std::unique_lock<std::mutex> lock(m);
59
+
60
+ _context->runOnRenderThread([&cv, &m, weakSelf = weak_from_this()]() {
61
+ // Lock
62
+ std::unique_lock<std::mutex> lock(m);
63
+
64
+ auto self = weakSelf.lock();
65
+ if(self) {
66
+ if(self->_renderer != nullptr) {
67
+ self->_renderer->run(nullptr, 0, 0);
68
+ }
69
+ // Remove renderer
70
+ self->_renderer = nullptr;
71
+ }
72
+ cv.notify_one();
73
+ });
74
+
75
+ cv.wait(lock);
76
+ }
77
+ }
78
+
79
+ void RNSkOpenGLCanvasProvider::surfaceSizeChanged(int width, int height) {
80
+ if(width == 0 && height == 0) {
81
+ // Setting width/height to zero is nothing we need to care about when
82
+ // it comes to invalidating the surface.
83
+ return;
84
+ }
85
+ _width = width;
86
+ _height = height;
87
+
88
+ // Redraw after size change
89
+ _requestRedraw();
90
+ }
91
+ }