@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,226 +0,0 @@
1
- #pragma once
2
-
3
- #include <functional>
4
- #include <memory>
5
- #include <mutex>
6
- #include <vector>
7
- #include <string>
8
-
9
- #include <jsi/jsi.h>
10
-
11
- #include <JsiValueWrapper.h>
12
-
13
- #include <RNSkInfoParameter.h>
14
- #include <RNSkPlatformContext.h>
15
- #include <RNSkTimingInfo.h>
16
- #include <RNSkLog.h>
17
-
18
- #pragma clang diagnostic push
19
- #pragma clang diagnostic ignored "-Wdocumentation"
20
-
21
- #include <SkCanvas.h>
22
-
23
- #pragma clang diagnostic pop
24
-
25
- class SkPicture;
26
- class SkRect;
27
- class SkImage;
28
-
29
- namespace RNSkia {
30
- class JsiSkCanvas;
31
- using namespace facebook;
32
-
33
- enum RNSkDrawingMode { Default, Continuous };
34
-
35
- class RNSkDrawView: public std::enable_shared_from_this<RNSkDrawView> {
36
- public:
37
- /**
38
- * Constructor
39
- */
40
- RNSkDrawView(std::shared_ptr<RNSkPlatformContext> context);
41
-
42
- /**
43
- Destructor
44
- */
45
- virtual ~RNSkDrawView();
46
-
47
- /**
48
- Sets custom properties. Custom properties are properties that are set directly from Javascript without having
49
- to go through the async bridge.
50
- */
51
- void setJsiProperties(std::unordered_map<std::string, JsiValueWrapper> &props);
52
-
53
- /**
54
- Calls a custom action.
55
- */
56
- jsi::Value callJsiMethod(jsi::Runtime& runtime,
57
- const std::string& name,
58
- const jsi::Value *arguments,
59
- size_t count);
60
-
61
- /**
62
- * Repaints the Skia view using the underlying context and the drawcallback.
63
- * This method schedules a draw request that will be run on the correct
64
- * thread and js runtime.
65
- */
66
- void requestRedraw();
67
-
68
- /**
69
- Calls the drawing callback on the javascript thread
70
- */
71
- void performDraw();
72
-
73
- /**
74
- Sets the native id of the view
75
- */
76
- void setNativeId(size_t nativeId);
77
-
78
- /**
79
- Returns the native id
80
- */
81
- size_t getNativeId() { return _nativeId; }
82
-
83
- /**
84
- Sets the drawing mode for the view
85
- */
86
- void setDrawingMode(RNSkDrawingMode mode);
87
-
88
- /**
89
- * Set to true to show the debug overlays on render
90
- */
91
- void setShowDebugOverlays(bool show) { _showDebugOverlay = show; }
92
-
93
- /**
94
- Update touch state with new touch points
95
- */
96
- void updateTouchState(std::vector<RNSkTouchPoint>&& points);
97
-
98
- /**
99
- Draws the view's surface into an image
100
- return an SkImage
101
- */
102
- sk_sp<SkImage> makeImageSnapshot(std::shared_ptr<SkRect> bounds);
103
-
104
- protected:
105
- /**
106
- Returns the scaled width of the view
107
- */
108
- virtual float getScaledWidth() = 0;
109
-
110
- /**
111
- Returns the scaled height of the view
112
- */
113
- virtual float getScaledHeight() = 0;
114
-
115
- /**
116
- Override to render to a canvas
117
- */
118
- virtual void renderToSkiaCanvas(const std::function<void(SkCanvas*)>&) = 0;
119
-
120
- /**
121
- * @return The platformcontext
122
- */
123
- std::shared_ptr<RNSkPlatformContext> getPlatformContext() {
124
- return _platformContext;
125
- }
126
-
127
- private:
128
- /**
129
- * Calls the JS draw callback. This is the JS function that does the actual drawing so this
130
- * method must be called from the JS thread.
131
- */
132
- void callJsDrawCallback(std::shared_ptr<JsiSkCanvas> canvas, int width, int height, double timestamp);
133
-
134
- /**
135
- Starts beginDrawCallback loop if the drawing mode is continuous
136
- */
137
- void beginDrawingLoop();
138
-
139
- /**
140
- Ends an ongoing beginDrawCallback loop for this view
141
- */
142
- void endDrawingLoop();
143
-
144
- /**
145
- Draw loop callback
146
- */
147
- void drawLoopCallback(bool invalidated);
148
-
149
- /**
150
- Draw in canvas
151
- */
152
- void drawInCanvas(std::shared_ptr<JsiSkCanvas> canvas,
153
- int width,
154
- int height,
155
- double time);
156
-
157
- /**
158
- * Stores the draw drawCallback
159
- */
160
- std::shared_ptr<jsi::Function> _drawCallback;
161
-
162
- /**
163
- * Stores a pointer to the jsi wrapper for the canvas. The reason for
164
- * storing this pointer and not recreate it is that it creates a set of
165
- * functions that we don't want to recreate on each render
166
- */
167
- std::shared_ptr<JsiSkCanvas> _jsiCanvas;
168
-
169
- /**
170
- * JS Drawing mutex
171
- */
172
- std::shared_ptr<std::timed_mutex> _jsDrawingLock;
173
-
174
- /**
175
- * SKIA Drawing mutex
176
- */
177
- std::shared_ptr<std::timed_mutex> _gpuDrawingLock;
178
-
179
- /**
180
- * Pointer to the platform context
181
- */
182
- std::shared_ptr<RNSkPlatformContext> _platformContext;
183
-
184
- /**
185
- Drawing mode
186
- */
187
- RNSkDrawingMode _drawingMode;
188
-
189
- /**
190
- * Show debug overlays
191
- */
192
- bool _showDebugOverlay = false;
193
-
194
- /**
195
- * True if the drawing loop has been requested
196
- */
197
- size_t _drawingLoopId = 0;
198
-
199
- /**
200
- * Info object parameter
201
- */
202
- std::shared_ptr<RNSkInfoObject> _infoObject;
203
-
204
- /**
205
- Timing information for javascript drawing
206
- */
207
- RNSkTimingInfo _jsTimingInfo;
208
-
209
- /**
210
- Timing information for GPU rendering
211
- */
212
- RNSkTimingInfo _gpuTimingInfo;
213
-
214
- /**
215
- Redraw queue counter
216
- */
217
- std::atomic<int> _redrawRequestCounter = { 1 };
218
-
219
- /**
220
- * Native id
221
- */
222
- size_t _nativeId;
223
-
224
- };
225
-
226
- } // namespace RNSkia
@@ -1,52 +0,0 @@
1
- #pragma once
2
-
3
- #import "PlatformContext.h"
4
- #import "RNSKDrawView.h"
5
- #import <CoreFoundation/CoreFoundation.h>
6
- #import <UIKit/UIKit.h>
7
-
8
- #import <GrMtlBackendContext.h>
9
- #import <MetalKit/MetalKit.h>
10
- #import <QuartzCore/CAMetalLayer.h>
11
-
12
- #pragma clang diagnostic push
13
- #pragma clang diagnostic ignored "-Wdocumentation"
14
-
15
- #import <SkPicture.h>
16
- #import <SkRefCnt.h>
17
- #import <include/gpu/GrDirectContext.h>
18
-
19
- #pragma clang diagnostic pop
20
-
21
- class RNSkDrawViewImpl : public RNSkia::RNSkDrawView {
22
- public:
23
- RNSkDrawViewImpl(std::shared_ptr<RNSkia::RNSkPlatformContext> context);
24
- ~RNSkDrawViewImpl();
25
-
26
- CALayer* getLayer() { return _layer; }
27
-
28
- void setSize(int width, int height);
29
-
30
- protected:
31
- float getScaledWidth() override { return _width * _context->getPixelDensity(); };
32
- float getScaledHeight() override { return _height * _context->getPixelDensity(); };
33
-
34
- private:
35
- void renderToSkiaCanvas(const std::function<void(SkCanvas*)>& cb) override;
36
- bool createSkiaSurface();
37
-
38
- int _nativeId;
39
- float _width = -1;
40
- float _height = -1;
41
-
42
- #pragma clang diagnostic push
43
- #pragma clang diagnostic ignored "-Wunguarded-availability-new"
44
- CAMetalLayer *_layer;
45
- #pragma clang diagnostic pop
46
-
47
- static id<MTLCommandQueue> _commandQueue;
48
- static id<MTLDevice> _device;
49
- static sk_sp<GrDirectContext> _skContext;
50
-
51
- std::shared_ptr<RNSkia::RNSkPlatformContext> _context;
52
- };
@@ -1,23 +0,0 @@
1
- #pragma once
2
-
3
- #import <memory>
4
- #import <string>
5
-
6
- #import <CoreFoundation/CoreFoundation.h>
7
- #import <UIKit/UIKit.h>
8
-
9
- #import <RNSkManager.h>
10
-
11
- class RNSkDrawViewImpl;
12
-
13
- @interface SkiaDrawView : UIView
14
-
15
- - (instancetype)initWithManager: (RNSkia::RNSkManager*)manager;
16
-
17
- - (std::shared_ptr<RNSkDrawViewImpl>) impl;
18
-
19
- - (void) setDrawingMode:(std::string) mode;
20
- - (void) setDebugMode:(bool) debugMode;
21
- - (void) setNativeId:(size_t) nativeId;
22
-
23
- @end