@shopify/react-native-skia 0.1.155 → 0.1.156

Sign up to get free protection for your applications and to get access to all the features.
Files changed (162) 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/HostComponents.js +3 -0
  98. package/lib/commonjs/renderer/HostComponents.js.map +1 -1
  99. package/lib/commonjs/renderer/components/Group.js +19 -4
  100. package/lib/commonjs/renderer/components/Group.js.map +1 -1
  101. package/lib/commonjs/renderer/components/Paint.js +6 -1
  102. package/lib/commonjs/renderer/components/Paint.js.map +1 -1
  103. package/lib/commonjs/views/SkiaPictureView.js +3 -2
  104. package/lib/commonjs/views/SkiaPictureView.js.map +1 -1
  105. package/lib/commonjs/views/SkiaView.js +6 -3
  106. package/lib/commonjs/views/SkiaView.js.map +1 -1
  107. package/lib/module/dom/nodes/JsiSkDOM.js +5 -0
  108. package/lib/module/dom/nodes/JsiSkDOM.js.map +1 -1
  109. package/lib/module/dom/nodes/LayerNode.js +32 -0
  110. package/lib/module/dom/nodes/LayerNode.js.map +1 -0
  111. package/lib/module/dom/types/NodeType.js +1 -0
  112. package/lib/module/dom/types/NodeType.js.map +1 -1
  113. package/lib/module/dom/types/SkDOM.js.map +1 -1
  114. package/lib/module/renderer/HostComponents.js +3 -0
  115. package/lib/module/renderer/HostComponents.js.map +1 -1
  116. package/lib/module/renderer/components/Group.js +16 -3
  117. package/lib/module/renderer/components/Group.js.map +1 -1
  118. package/lib/module/renderer/components/Paint.js +7 -1
  119. package/lib/module/renderer/components/Paint.js.map +1 -1
  120. package/lib/module/views/SkiaPictureView.js +2 -2
  121. package/lib/module/views/SkiaPictureView.js.map +1 -1
  122. package/lib/module/views/SkiaView.js +4 -2
  123. package/lib/module/views/SkiaView.js.map +1 -1
  124. package/lib/typescript/src/dom/nodes/JsiSkDOM.d.ts +2 -0
  125. package/lib/typescript/src/dom/nodes/LayerNode.d.ts +8 -0
  126. package/lib/typescript/src/dom/types/NodeType.d.ts +1 -0
  127. package/lib/typescript/src/dom/types/SkDOM.d.ts +1 -0
  128. package/lib/typescript/src/renderer/HostComponents.d.ts +2 -1
  129. package/lib/typescript/src/renderer/components/Group.d.ts +5 -1
  130. package/lib/typescript/src/views/SkiaView.d.ts +3 -0
  131. package/libs/android/arm64-v8a/libskottie.a +0 -0
  132. package/libs/android/arm64-v8a/libsksg.a +0 -0
  133. package/libs/android/armeabi-v7a/libskottie.a +0 -0
  134. package/libs/android/armeabi-v7a/libsksg.a +0 -0
  135. package/libs/android/x86/libskottie.a +0 -0
  136. package/libs/android/x86/libsksg.a +0 -0
  137. package/libs/android/x86_64/libskottie.a +0 -0
  138. package/libs/android/x86_64/libsksg.a +0 -0
  139. package/libs/ios/libskia.xcframework/ios-arm64_arm64e/libskia.a +0 -0
  140. package/libs/ios/libskia.xcframework/ios-arm64_arm64e_x86_64-simulator/libskia.a +0 -0
  141. package/libs/ios/libskottie.xcframework/Info.plist +42 -0
  142. package/libs/ios/libskottie.xcframework/ios-arm64_arm64e/libskottie.a +0 -0
  143. package/libs/ios/libskottie.xcframework/ios-arm64_arm64e_x86_64-simulator/libskottie.a +0 -0
  144. package/libs/ios/libsksg.xcframework/Info.plist +42 -0
  145. package/libs/ios/libsksg.xcframework/ios-arm64_arm64e/libsksg.a +0 -0
  146. package/libs/ios/libsksg.xcframework/ios-arm64_arm64e_x86_64-simulator/libsksg.a +0 -0
  147. package/libs/ios/libskshaper.xcframework/Info.plist +5 -5
  148. package/libs/ios/libskshaper.xcframework/ios-arm64_arm64e/libskshaper.a +0 -0
  149. package/libs/ios/libskshaper.xcframework/ios-arm64_arm64e_x86_64-simulator/libskshaper.a +0 -0
  150. package/libs/ios/libsvg.xcframework/Info.plist +5 -5
  151. package/libs/ios/libsvg.xcframework/ios-arm64_arm64e/libsvg.a +0 -0
  152. package/libs/ios/libsvg.xcframework/ios-arm64_arm64e_x86_64-simulator/libsvg.a +0 -0
  153. package/package.json +3 -1
  154. package/src/dom/nodes/JsiSkDOM.ts +5 -0
  155. package/src/dom/nodes/LayerNode.ts +35 -0
  156. package/src/dom/types/NodeType.ts +1 -0
  157. package/src/dom/types/SkDOM.ts +1 -0
  158. package/src/renderer/HostComponents.ts +3 -0
  159. package/src/renderer/components/Group.tsx +16 -3
  160. package/src/renderer/components/Paint.tsx +7 -1
  161. package/src/views/SkiaPictureView.tsx +2 -3
  162. package/src/views/SkiaView.tsx +2 -2
@@ -1,29 +1,30 @@
1
+ #include <utility>
2
+
1
3
  #include "RNSkJsView.h"
2
4
 
3
- namespace RNSkia
4
- {
5
+ namespace RNSkia {
5
6
 
6
7
  RNSkJsRenderer::RNSkJsRenderer(std::function<void()> requestRedraw,
7
- std::shared_ptr<RNSkPlatformContext> context) :
8
- RNSkRenderer(requestRedraw),
9
- _jsiCanvas(std::make_shared<JsiSkCanvas>(context)),
10
- _platformContext(std::move(context)),
11
- _infoObject(std::make_shared<RNSkInfoObject>()),
12
- _jsDrawingLock(std::make_shared<std::timed_mutex>()),
13
- _gpuDrawingLock(std::make_shared<std::timed_mutex>()),
14
- _jsTimingInfo("SKIA/JS"),
15
- _gpuTimingInfo("SKIA/GPU") {
16
- }
17
-
18
- bool RNSkJsRenderer::tryRender(std::shared_ptr<RNSkCanvasProvider> canvasProvider) {
8
+ std::shared_ptr<RNSkPlatformContext> context)
9
+ : RNSkRenderer(requestRedraw),
10
+ _jsiCanvas(std::make_shared<JsiSkCanvas>(context)),
11
+ _platformContext(std::move(context)),
12
+ _infoObject(std::make_shared<RNSkInfoObject>()),
13
+ _jsDrawingLock(std::make_shared<std::timed_mutex>()),
14
+ _gpuDrawingLock(std::make_shared<std::timed_mutex>()),
15
+ _jsTimingInfo("SKIA/JS"), _gpuTimingInfo("SKIA/GPU") {}
16
+
17
+ bool RNSkJsRenderer::tryRender(
18
+ std::shared_ptr<RNSkCanvasProvider> canvasProvider) {
19
19
  // We render on the javascript thread.
20
- if(_jsDrawingLock->try_lock()) {
21
- _platformContext->runOnJavascriptThread([weakSelf = weak_from_this(), canvasProvider](){
22
- auto self = weakSelf.lock();
23
- if(self) {
24
- self->performDraw(canvasProvider);
25
- }
26
- });
20
+ if (_jsDrawingLock->try_lock()) {
21
+ _platformContext->runOnJavascriptThread(
22
+ [weakSelf = weak_from_this(), canvasProvider]() {
23
+ auto self = weakSelf.lock();
24
+ if (self) {
25
+ self->performDraw(canvasProvider);
26
+ }
27
+ });
27
28
  return true;
28
29
  } else {
29
30
  #ifdef DEBUG
@@ -31,84 +32,87 @@ bool RNSkJsRenderer::tryRender(std::shared_ptr<RNSkCanvasProvider> canvasProvide
31
32
  #endif
32
33
  return false;
33
34
  }
34
- };
35
+ }
35
36
 
36
- void RNSkJsRenderer::renderImmediate(std::shared_ptr<RNSkCanvasProvider> canvasProvider) {
37
- milliseconds ms = duration_cast<milliseconds>(system_clock::now().time_since_epoch());
38
- canvasProvider->renderToCanvas([&](SkCanvas* canvas) {
37
+ void RNSkJsRenderer::renderImmediate(
38
+ std::shared_ptr<RNSkCanvasProvider> canvasProvider) {
39
+ std::chrono::milliseconds ms =
40
+ std::chrono::duration_cast<std::chrono::milliseconds>(
41
+ std::chrono::system_clock::now().time_since_epoch());
42
+ canvasProvider->renderToCanvas([&](SkCanvas *canvas) {
39
43
  // Create jsi canvas
40
44
  auto jsiCanvas = std::make_shared<JsiSkCanvas>(_platformContext);
41
45
  jsiCanvas->setCanvas(canvas);
42
-
43
- drawInJsiCanvas(std::move(jsiCanvas),
44
- canvasProvider->getScaledWidth(),
45
- canvasProvider->getScaledHeight(),
46
- ms.count() / 1000);
46
+
47
+ drawInJsiCanvas(std::move(jsiCanvas), canvasProvider->getScaledWidth(),
48
+ canvasProvider->getScaledHeight(), ms.count() / 1000);
47
49
  });
48
- };
50
+ }
49
51
 
50
- void RNSkJsRenderer::setDrawCallback(std::shared_ptr<jsi::Function> drawCallback) {
52
+ void RNSkJsRenderer::setDrawCallback(
53
+ std::shared_ptr<jsi::Function> drawCallback) {
51
54
  _drawCallback = drawCallback;
52
55
  }
53
56
 
54
57
  std::shared_ptr<RNSkInfoObject> RNSkJsRenderer::getInfoObject() {
55
58
  return _infoObject;
56
59
  }
57
-
58
- void RNSkJsRenderer::performDraw(std::shared_ptr<RNSkCanvasProvider> canvasProvider) {
60
+
61
+ void RNSkJsRenderer::performDraw(
62
+ std::shared_ptr<RNSkCanvasProvider> canvasProvider) {
59
63
  // Start timing
60
64
  _jsTimingInfo.beginTiming();
61
-
65
+
62
66
  // Record the drawing operations on the JS thread so that we can
63
67
  // move the actual drawing onto the render thread later
64
68
  SkPictureRecorder recorder;
65
69
  SkRTreeFactory factory;
66
- SkCanvas* canvas = recorder.beginRecording(canvasProvider->getScaledWidth(),
67
- canvasProvider->getScaledHeight(),
68
- &factory);
69
-
70
+ SkCanvas *canvas =
71
+ recorder.beginRecording(canvasProvider->getScaledWidth(),
72
+ canvasProvider->getScaledHeight(), &factory);
73
+
70
74
  _jsiCanvas->setCanvas(canvas);
71
-
75
+
72
76
  // Get current milliseconds
73
- milliseconds ms = duration_cast<milliseconds>(
74
- system_clock::now().time_since_epoch());
75
-
77
+ std::chrono::milliseconds ms =
78
+ std::chrono::duration_cast<std::chrono::milliseconds>(
79
+ std::chrono::system_clock::now().time_since_epoch());
80
+
76
81
  try {
77
82
  // Perform the javascript drawing
78
- drawInJsiCanvas(_jsiCanvas,
79
- canvasProvider->getScaledWidth(),
80
- canvasProvider->getScaledHeight(),
81
- ms.count() / 1000.0);
82
-
83
- } catch(...) {
83
+ drawInJsiCanvas(_jsiCanvas, canvasProvider->getScaledWidth(),
84
+ canvasProvider->getScaledHeight(), ms.count() / 1000.0);
85
+
86
+ } catch (...) {
84
87
  _jsTimingInfo.stopTiming();
85
88
  _jsDrawingLock->unlock();
86
89
  throw;
87
90
  }
88
-
91
+
89
92
  // Finish drawing operations
90
93
  auto p = recorder.finishRecordingAsPicture();
91
94
 
92
95
  _jsiCanvas->setCanvas(nullptr);
93
-
96
+
94
97
  // Calculate duration
95
98
  _jsTimingInfo.stopTiming();
96
-
97
- if(_gpuDrawingLock->try_lock()) {
99
+
100
+ if (_gpuDrawingLock->try_lock()) {
98
101
 
99
102
  // Post drawing message to the render thread where the picture recorded
100
103
  // will be sent to the GPU/backend for rendering to screen.
101
104
  auto gpuLock = _gpuDrawingLock;
102
- _platformContext->runOnRenderThread([weakSelf = weak_from_this(), p = std::move(p), gpuLock, canvasProvider]() {
105
+ _platformContext->runOnRenderThread([weakSelf = weak_from_this(),
106
+ p = std::move(p), gpuLock,
107
+ canvasProvider]() {
103
108
  auto self = weakSelf.lock();
104
109
  if (self) {
105
110
  // Draw the picture recorded on the real GPU canvas
106
111
  self->_gpuTimingInfo.beginTiming();
107
-
108
- canvasProvider->renderToCanvas([p = std::move(p)](SkCanvas* canvas) {
109
- canvas->drawPicture(p);
110
- });
111
-
112
+
113
+ canvasProvider->renderToCanvas(
114
+ [p = std::move(p)](SkCanvas *canvas) { canvas->drawPicture(p); });
115
+
112
116
  self->_gpuTimingInfo.stopTiming();
113
117
  }
114
118
  // Unlock GPU drawing
@@ -121,17 +125,16 @@ void RNSkJsRenderer::performDraw(std::shared_ptr<RNSkCanvasProvider> canvasProvi
121
125
  // Request a new redraw since the last frame was skipped.
122
126
  _requestRedraw();
123
127
  }
124
-
128
+
125
129
  // Unlock JS drawing
126
130
  _jsDrawingLock->unlock();
127
131
  }
128
-
132
+
129
133
  void RNSkJsRenderer::callJsDrawCallback(std::shared_ptr<JsiSkCanvas> jsiCanvas,
130
- int width,
131
- int height,
132
- double timestamp) {
133
-
134
- if(_drawCallback == nullptr) {
134
+ int width, int height,
135
+ double timestamp) {
136
+
137
+ if (_drawCallback == nullptr) {
135
138
  return;
136
139
  }
137
140
 
@@ -150,9 +153,8 @@ void RNSkJsRenderer::callJsDrawCallback(std::shared_ptr<JsiSkCanvas> jsiCanvas,
150
153
  args[1] = jsi::Object::createFromHostObject(*runtime, _infoObject);
151
154
 
152
155
  // To be able to call the drawing function we'll wrap it once again
153
- _drawCallback->call(*runtime,
154
- static_cast<const jsi::Value *>(args.data()),
155
- (size_t)2);
156
+ _drawCallback->call(*runtime, static_cast<const jsi::Value *>(args.data()),
157
+ static_cast<size_t>(2));
156
158
 
157
159
  // Reset touches
158
160
  _infoObject->endDrawOperation();
@@ -162,16 +164,17 @@ void RNSkJsRenderer::callJsDrawCallback(std::shared_ptr<JsiSkCanvas> jsiCanvas,
162
164
 
163
165
  // Display average rendering timer
164
166
  auto jsAvg = _jsTimingInfo.getAverage();
165
- //auto jsFps = _jsTimingInfo.getFps();
167
+ // auto jsFps = _jsTimingInfo.getFps();
166
168
 
167
169
  auto gpuAvg = _gpuTimingInfo.getAverage();
168
- //auto gpuFps = _gpuTimingInfo.getFps();
170
+ // auto gpuFps = _gpuTimingInfo.getFps();
169
171
 
170
172
  auto total = jsAvg + gpuAvg;
171
173
 
172
174
  // Build string
173
175
  std::ostringstream stream;
174
- stream << "js: " << jsAvg << "ms gpu: " << gpuAvg << "ms " << " total: " << total << "ms";
176
+ stream << "js: " << jsAvg << "ms gpu: " << gpuAvg << "ms "
177
+ << " total: " << total << "ms";
175
178
 
176
179
  std::string debugString = stream.str();
177
180
 
@@ -181,16 +184,14 @@ void RNSkJsRenderer::callJsDrawCallback(std::shared_ptr<JsiSkCanvas> jsiCanvas,
181
184
  auto paint = SkPaint();
182
185
  paint.setColor(SkColors::kRed);
183
186
  jsiCanvas->getCanvas()->drawSimpleText(
184
- debugString.c_str(), debugString.size(), SkTextEncoding::kUTF8, 8,
185
- 18, font, paint);
187
+ debugString.c_str(), debugString.size(), SkTextEncoding::kUTF8, 8, 18,
188
+ font, paint);
186
189
  }
187
190
  }
188
191
 
189
192
  void RNSkJsRenderer::drawInJsiCanvas(std::shared_ptr<JsiSkCanvas> jsiCanvas,
190
- int width,
191
- int height,
192
- double time) {
193
-
193
+ int width, int height, double time) {
194
+
194
195
  // Call the draw drawCallback and perform js based drawing
195
196
  auto skCanvas = jsiCanvas->getCanvas();
196
197
  if (_drawCallback != nullptr && skCanvas != nullptr) {
@@ -198,14 +199,14 @@ void RNSkJsRenderer::drawInJsiCanvas(std::shared_ptr<JsiSkCanvas> jsiCanvas,
198
199
  auto pd = _platformContext->getPixelDensity();
199
200
  skCanvas->save();
200
201
  skCanvas->scale(pd, pd);
201
-
202
+
202
203
  // Call draw function.
203
204
  callJsDrawCallback(jsiCanvas, width / pd, height / pd, time);
204
-
205
+
205
206
  // Restore and flush canvas
206
207
  skCanvas->restore();
207
208
  skCanvas->flush();
208
209
  }
209
210
  }
210
211
 
211
- } // Namespace RNSkia
212
+ } // namespace RNSkia
@@ -3,25 +3,26 @@
3
3
  #include <functional>
4
4
  #include <memory>
5
5
  #include <mutex>
6
- #include <vector>
7
6
  #include <string>
7
+ #include <unordered_map>
8
+ #include <vector>
8
9
 
9
10
  #include <jsi/jsi.h>
10
11
 
11
12
  #include <JsiValueWrapper.h>
12
13
  #include <RNSkView.h>
13
14
 
15
+ #include <JsiSkCanvas.h>
14
16
  #include <RNSkInfoParameter.h>
17
+ #include <RNSkLog.h>
15
18
  #include <RNSkPlatformContext.h>
16
19
  #include <RNSkTimingInfo.h>
17
- #include <RNSkLog.h>
18
- #include <JsiSkCanvas.h>
19
20
 
20
21
  #pragma clang diagnostic push
21
22
  #pragma clang diagnostic ignored "-Wdocumentation"
22
23
 
23
- #include <SkCanvas.h>
24
24
  #include <SkBBHFactory.h>
25
+ #include <SkCanvas.h>
25
26
  #include <SkPictureRecorder.h>
26
27
 
27
28
  #pragma clang diagnostic pop
@@ -32,35 +33,31 @@ class SkImage;
32
33
 
33
34
  namespace RNSkia {
34
35
  class JsiSkCanvas;
35
- using namespace facebook;
36
+ namespace jsi = facebook::jsi;
36
37
 
37
- class RNSkJsRenderer:
38
- public RNSkRenderer,
39
- public std::enable_shared_from_this<RNSkJsRenderer> {
38
+ class RNSkJsRenderer : public RNSkRenderer,
39
+ public std::enable_shared_from_this<RNSkJsRenderer> {
40
40
  public:
41
41
  RNSkJsRenderer(std::function<void()> requestRedraw,
42
42
  std::shared_ptr<RNSkPlatformContext> context);
43
-
43
+
44
44
  bool tryRender(std::shared_ptr<RNSkCanvasProvider> canvasProvider) override;
45
-
46
- void renderImmediate(std::shared_ptr<RNSkCanvasProvider> canvasProvider) override;
47
-
45
+
46
+ void
47
+ renderImmediate(std::shared_ptr<RNSkCanvasProvider> canvasProvider) override;
48
+
48
49
  void setDrawCallback(std::shared_ptr<jsi::Function> drawCallback);
49
-
50
+
50
51
  std::shared_ptr<RNSkInfoObject> getInfoObject();
51
-
52
+
52
53
  private:
53
54
  void performDraw(std::shared_ptr<RNSkCanvasProvider> canvasProvider);
54
-
55
- void callJsDrawCallback(std::shared_ptr<JsiSkCanvas> jsiCanvas,
56
- int width,
57
- int height,
58
- double timestamp);
59
-
60
- void drawInJsiCanvas(std::shared_ptr<JsiSkCanvas> jsiCanvas,
61
- int width,
62
- int height,
63
- double time);
55
+
56
+ void callJsDrawCallback(std::shared_ptr<JsiSkCanvas> jsiCanvas, int width,
57
+ int height, double timestamp);
58
+
59
+ void drawInJsiCanvas(std::shared_ptr<JsiSkCanvas> jsiCanvas, int width,
60
+ int height, double time);
64
61
 
65
62
  std::shared_ptr<RNSkPlatformContext> _platformContext;
66
63
  std::shared_ptr<jsi::Function> _drawCallback;
@@ -72,36 +69,43 @@ private:
72
69
  RNSkTimingInfo _gpuTimingInfo;
73
70
  };
74
71
 
75
- class RNSkJsView: public RNSkView {
72
+ class RNSkJsView : public RNSkView {
76
73
  public:
77
74
  /**
78
75
  * Constructor
79
76
  */
80
77
  RNSkJsView(std::shared_ptr<RNSkPlatformContext> context,
81
- std::shared_ptr<RNSkCanvasProvider> canvasProvider):
82
- RNSkView(context,
83
- canvasProvider,
84
- std::make_shared<RNSkJsRenderer>(std::bind(&RNSkJsView::requestRedraw, this), context)) {}
85
-
86
- void updateTouchState(std::vector<RNSkTouchInfo>& touches) override {
87
- std::static_pointer_cast<RNSkJsRenderer>(getRenderer())->getInfoObject()->updateTouches(touches);
78
+ std::shared_ptr<RNSkCanvasProvider> canvasProvider)
79
+ : RNSkView(context, canvasProvider,
80
+ std::make_shared<RNSkJsRenderer>(
81
+ std::bind(&RNSkJsView::requestRedraw, this), context)) {}
82
+
83
+ void updateTouchState(std::vector<RNSkTouchInfo> &touches) override {
84
+ std::static_pointer_cast<RNSkJsRenderer>(getRenderer())
85
+ ->getInfoObject()
86
+ ->updateTouches(touches);
88
87
  RNSkView::updateTouchState(touches);
89
88
  }
90
-
91
- void setJsiProperties(std::unordered_map<std::string, JsiValueWrapper> &props) override {
92
- for(auto& prop: props) {
93
- if(prop.first == "drawCallback") {
94
- if(prop.second.isUndefinedOrNull()) {
89
+
90
+ void setJsiProperties(
91
+ std::unordered_map<std::string, RNJsi::JsiValueWrapper> &props) override {
92
+ for (auto &prop : props) {
93
+ if (prop.first == "drawCallback") {
94
+ if (prop.second.isUndefinedOrNull()) {
95
95
  // Clear drawcallback
96
- std::static_pointer_cast<RNSkJsRenderer>(getRenderer())->setDrawCallback(nullptr);
96
+ std::static_pointer_cast<RNSkJsRenderer>(getRenderer())
97
+ ->setDrawCallback(nullptr);
97
98
  return;
98
- } else if (prop.second.getType() != JsiWrapperValueType::Function) {
99
+ } else if (prop.second.getType() !=
100
+ RNJsi::JsiWrapperValueType::Function) {
99
101
  // We expect a function for the draw callback custom property
100
- throw std::runtime_error("Expected a function for the drawCallback custom property.");
102
+ throw std::runtime_error(
103
+ "Expected a function for the drawCallback custom property.");
101
104
  }
102
105
 
103
106
  // Save callback
104
- std::static_pointer_cast<RNSkJsRenderer>(getRenderer())->setDrawCallback(prop.second.getAsFunction());
107
+ std::static_pointer_cast<RNSkJsRenderer>(getRenderer())
108
+ ->setDrawCallback(prop.second.getAsFunction());
105
109
 
106
110
  // Request redraw
107
111
  requestRedraw();