@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.
- package/android/cpp/jni/JniLoad.cpp +5 -5
- package/android/cpp/jni/JniPlatformContext.cpp +107 -119
- package/android/cpp/jni/JniSkiaManager.cpp +18 -20
- package/android/cpp/jni/include/JniPlatformContext.h +41 -45
- package/android/cpp/jni/include/JniSkiaBaseView.h +52 -55
- package/android/cpp/jni/include/JniSkiaDrawView.h +72 -77
- package/android/cpp/jni/include/JniSkiaManager.h +51 -53
- package/android/cpp/jni/include/JniSkiaPictureView.h +74 -78
- package/android/cpp/rnskia-android/RNSkAndroidPlatformContext.h +36 -45
- package/android/cpp/rnskia-android/RNSkAndroidView.h +87 -92
- package/android/cpp/rnskia-android/RNSkOpenGLCanvasProvider.cpp +62 -65
- package/android/cpp/rnskia-android/RNSkOpenGLCanvasProvider.h +20 -17
- package/android/cpp/rnskia-android/SkiaOpenGLRenderer.cpp +257 -313
- package/android/cpp/rnskia-android/SkiaOpenGLRenderer.h +107 -110
- package/cpp/api/JsiSkApi.h +66 -62
- package/cpp/api/JsiSkCanvas.h +38 -30
- package/cpp/api/JsiSkColor.h +58 -56
- package/cpp/api/JsiSkColorFilter.h +5 -3
- package/cpp/api/JsiSkColorFilterFactory.h +23 -21
- package/cpp/api/JsiSkContourMeasure.h +74 -85
- package/cpp/api/JsiSkContourMeasureIter.h +68 -75
- package/cpp/api/JsiSkData.h +16 -22
- package/cpp/api/JsiSkDataFactory.h +86 -79
- package/cpp/api/JsiSkFont.h +286 -311
- package/cpp/api/JsiSkHostObjects.h +15 -16
- package/cpp/api/JsiSkImage.h +107 -103
- package/cpp/api/JsiSkImageFactory.h +34 -36
- package/cpp/api/JsiSkImageFilter.h +5 -3
- package/cpp/api/JsiSkImageFilterFactory.h +71 -68
- package/cpp/api/JsiSkImageInfo.h +41 -38
- package/cpp/api/JsiSkMaskFilter.h +5 -3
- package/cpp/api/JsiSkMaskFilterFactory.h +2 -3
- package/cpp/api/JsiSkMatrix.h +26 -36
- package/cpp/api/JsiSkPaint.h +20 -13
- package/cpp/api/JsiSkPath.h +70 -85
- package/cpp/api/JsiSkPathEffect.h +5 -3
- package/cpp/api/JsiSkPathEffectFactory.h +33 -28
- package/cpp/api/JsiSkPathFactory.h +68 -67
- package/cpp/api/JsiSkPicture.h +28 -22
- package/cpp/api/JsiSkPictureFactory.h +13 -12
- package/cpp/api/JsiSkPictureRecorder.h +21 -19
- package/cpp/api/JsiSkPoint.h +6 -8
- package/cpp/api/JsiSkRRect.h +11 -7
- package/cpp/api/JsiSkRSXform.h +82 -85
- package/cpp/api/JsiSkRect.h +9 -9
- package/cpp/api/JsiSkRuntimeEffect.h +182 -186
- package/cpp/api/JsiSkRuntimeEffectFactory.h +10 -11
- package/cpp/api/JsiSkRuntimeShaderBuilder.h +64 -61
- package/cpp/api/JsiSkSVG.h +4 -5
- package/cpp/api/JsiSkSVGFactory.h +28 -27
- package/cpp/api/JsiSkShader.h +3 -2
- package/cpp/api/JsiSkShaderFactory.h +37 -25
- package/cpp/api/JsiSkSurface.h +44 -40
- package/cpp/api/JsiSkSurfaceFactory.h +22 -22
- package/cpp/api/JsiSkTextBlob.h +28 -31
- package/cpp/api/JsiSkTextBlobFactory.h +88 -87
- package/cpp/api/JsiSkTypeface.h +6 -5
- package/cpp/api/JsiSkTypefaceFactory.h +22 -21
- package/cpp/api/JsiSkVertices.h +137 -124
- package/cpp/api/third_party/CSSColorParser.cpp +161 -174
- package/cpp/api/third_party/CSSColorParser.h +172 -96
- package/cpp/jsi/JsiHostObject.cpp +11 -9
- package/cpp/jsi/JsiHostObject.h +31 -24
- package/cpp/jsi/JsiSimpleValueWrapper.h +74 -83
- package/cpp/jsi/JsiValueWrapper.h +52 -54
- package/cpp/rnskia/RNSkAnimation.h +26 -29
- package/cpp/rnskia/RNSkDispatchQueue.cpp +50 -61
- package/cpp/rnskia/RNSkDispatchQueue.h +3 -1
- package/cpp/rnskia/RNSkInfoParameter.h +12 -12
- package/cpp/rnskia/RNSkJsView.cpp +82 -81
- package/cpp/rnskia/RNSkJsView.h +45 -41
- package/cpp/rnskia/RNSkJsiViewApi.h +99 -89
- package/cpp/rnskia/RNSkManager.cpp +8 -7
- package/cpp/rnskia/RNSkManager.h +8 -6
- package/cpp/rnskia/RNSkPictureView.h +44 -37
- package/cpp/rnskia/RNSkPlatformContext.h +39 -28
- package/cpp/rnskia/RNSkValueApi.h +33 -34
- package/cpp/rnskia/RNSkView.h +108 -93
- package/cpp/rnskia/values/RNSkClockValue.h +63 -64
- package/cpp/rnskia/values/RNSkComputedValue.h +32 -30
- package/cpp/rnskia/values/RNSkReadonlyValue.h +60 -59
- package/cpp/rnskia/values/RNSkValue.h +38 -40
- package/cpp/utils/RNSkLog.h +9 -7
- package/cpp/utils/RNSkMeasureTime.h +7 -7
- package/cpp/utils/RNSkTimingInfo.h +27 -24
- package/ios/RNSkia-iOS/RNSkMetalCanvasProvider.h +8 -9
- package/ios/RNSkia-iOS/RNSkiOSPlatformContext.h +24 -23
- package/ios/RNSkia-iOS/RNSkiOSView.h +16 -13
- package/ios/RNSkia-iOS/SkiaUIView.h +9 -8
- package/lib/commonjs/dom/nodes/JsiSkDOM.js +6 -0
- package/lib/commonjs/dom/nodes/JsiSkDOM.js.map +1 -1
- package/lib/commonjs/dom/nodes/LayerNode.js +43 -0
- package/lib/commonjs/dom/nodes/LayerNode.js.map +1 -0
- package/lib/commonjs/dom/types/NodeType.js +1 -0
- package/lib/commonjs/dom/types/NodeType.js.map +1 -1
- package/lib/commonjs/dom/types/SkDOM.js.map +1 -1
- package/lib/commonjs/renderer/Canvas.js +1 -1
- package/lib/commonjs/renderer/Canvas.js.map +1 -1
- package/lib/commonjs/renderer/HostComponents.js +3 -0
- package/lib/commonjs/renderer/HostComponents.js.map +1 -1
- package/lib/commonjs/renderer/HostConfig.js +10 -1
- package/lib/commonjs/renderer/HostConfig.js.map +1 -1
- package/lib/commonjs/renderer/components/Group.js +19 -4
- package/lib/commonjs/renderer/components/Group.js.map +1 -1
- package/lib/commonjs/renderer/components/Paint.js +6 -1
- package/lib/commonjs/renderer/components/Paint.js.map +1 -1
- package/lib/commonjs/views/SkiaPictureView.js +3 -2
- package/lib/commonjs/views/SkiaPictureView.js.map +1 -1
- package/lib/commonjs/views/SkiaView.js +6 -3
- package/lib/commonjs/views/SkiaView.js.map +1 -1
- package/lib/module/animation/spring/runSpring.js +1 -1
- package/lib/module/animation/spring/runSpring.js.map +1 -1
- package/lib/module/animation/spring/useSpring.js +1 -1
- package/lib/module/animation/spring/useSpring.js.map +1 -1
- package/lib/module/animation/timing/createTiming.js +6 -2
- package/lib/module/animation/timing/createTiming.js.map +1 -1
- package/lib/module/animation/timing/functions/getResolvedParams.js +10 -6
- package/lib/module/animation/timing/functions/getResolvedParams.js.map +1 -1
- package/lib/module/animation/timing/useTiming.js +3 -1
- package/lib/module/animation/timing/useTiming.js.map +1 -1
- package/lib/module/dom/nodes/JsiSkDOM.js +6 -1
- package/lib/module/dom/nodes/JsiSkDOM.js.map +1 -1
- package/lib/module/dom/nodes/LayerNode.js +32 -0
- package/lib/module/dom/nodes/LayerNode.js.map +1 -0
- package/lib/module/dom/nodes/datatypes/Gradient.js +2 -2
- package/lib/module/dom/nodes/datatypes/Gradient.js.map +1 -1
- package/lib/module/dom/nodes/paint/Shaders.js +4 -2
- package/lib/module/dom/nodes/paint/Shaders.js.map +1 -1
- package/lib/module/dom/types/NodeType.js +1 -0
- package/lib/module/dom/types/NodeType.js.map +1 -1
- package/lib/module/dom/types/SkDOM.js.map +1 -1
- package/lib/module/mock/index.js +10 -6
- package/lib/module/mock/index.js.map +1 -1
- package/lib/module/renderer/Canvas.js +1 -1
- package/lib/module/renderer/Canvas.js.map +1 -1
- package/lib/module/renderer/HostComponents.js +3 -0
- package/lib/module/renderer/HostComponents.js.map +1 -1
- package/lib/module/renderer/HostConfig.js +9 -1
- package/lib/module/renderer/HostConfig.js.map +1 -1
- package/lib/module/renderer/components/Group.js +16 -3
- package/lib/module/renderer/components/Group.js.map +1 -1
- package/lib/module/renderer/components/Paint.js +7 -1
- package/lib/module/renderer/components/Paint.js.map +1 -1
- package/lib/module/skia/core/Vector.js +1 -1
- package/lib/module/skia/core/Vector.js.map +1 -1
- package/lib/module/skia/web/Host.js +1 -1
- package/lib/module/skia/web/Host.js.map +1 -1
- package/lib/module/skia/web/JsiSkMatrix.js +1 -1
- package/lib/module/skia/web/JsiSkMatrix.js.map +1 -1
- package/lib/module/values/web/RNSkAnimation.js +2 -2
- package/lib/module/values/web/RNSkAnimation.js.map +1 -1
- package/lib/module/views/SkiaBaseWebView.js +3 -1
- package/lib/module/views/SkiaBaseWebView.js.map +1 -1
- package/lib/module/views/SkiaPictureView.js +2 -2
- package/lib/module/views/SkiaPictureView.js.map +1 -1
- package/lib/module/views/SkiaView.js +4 -2
- package/lib/module/views/SkiaView.js.map +1 -1
- package/lib/module/views/useTouchHandler.js +6 -6
- package/lib/module/views/useTouchHandler.js.map +1 -1
- package/lib/module/web/WithSkiaWeb.js +1 -1
- package/lib/module/web/WithSkiaWeb.js.map +1 -1
- package/lib/typescript/src/dom/nodes/JsiSkDOM.d.ts +2 -0
- package/lib/typescript/src/dom/nodes/LayerNode.d.ts +8 -0
- package/lib/typescript/src/dom/types/NodeType.d.ts +1 -0
- package/lib/typescript/src/dom/types/SkDOM.d.ts +1 -0
- package/lib/typescript/src/renderer/HostComponents.d.ts +2 -1
- package/lib/typescript/src/renderer/components/Group.d.ts +5 -1
- package/lib/typescript/src/views/SkiaView.d.ts +3 -0
- package/libs/android/arm64-v8a/libskottie.a +0 -0
- package/libs/android/arm64-v8a/libsksg.a +0 -0
- package/libs/android/armeabi-v7a/libskottie.a +0 -0
- package/libs/android/armeabi-v7a/libsksg.a +0 -0
- package/libs/android/x86/libskottie.a +0 -0
- package/libs/android/x86/libsksg.a +0 -0
- package/libs/android/x86_64/libskottie.a +0 -0
- package/libs/android/x86_64/libsksg.a +0 -0
- package/libs/ios/libskia.xcframework/ios-arm64_arm64e/libskia.a +0 -0
- package/libs/ios/libskia.xcframework/ios-arm64_arm64e_x86_64-simulator/libskia.a +0 -0
- package/libs/ios/libskottie.xcframework/Info.plist +42 -0
- package/libs/ios/libskottie.xcframework/ios-arm64_arm64e/libskottie.a +0 -0
- package/libs/ios/libskottie.xcframework/ios-arm64_arm64e_x86_64-simulator/libskottie.a +0 -0
- package/libs/ios/libsksg.xcframework/Info.plist +42 -0
- package/libs/ios/libsksg.xcframework/ios-arm64_arm64e/libsksg.a +0 -0
- package/libs/ios/libsksg.xcframework/ios-arm64_arm64e_x86_64-simulator/libsksg.a +0 -0
- package/libs/ios/libskshaper.xcframework/Info.plist +5 -5
- package/libs/ios/libskshaper.xcframework/ios-arm64_arm64e/libskshaper.a +0 -0
- package/libs/ios/libskshaper.xcframework/ios-arm64_arm64e_x86_64-simulator/libskshaper.a +0 -0
- package/libs/ios/libsvg.xcframework/Info.plist +5 -5
- package/libs/ios/libsvg.xcframework/ios-arm64_arm64e/libsvg.a +0 -0
- package/libs/ios/libsvg.xcframework/ios-arm64_arm64e_x86_64-simulator/libsvg.a +0 -0
- package/package.json +14 -6
- package/src/dom/nodes/JsiSkDOM.ts +5 -0
- package/src/dom/nodes/LayerNode.ts +35 -0
- package/src/dom/types/NodeType.ts +1 -0
- package/src/dom/types/SkDOM.ts +1 -0
- package/src/renderer/Canvas.tsx +11 -1
- package/src/renderer/HostComponents.ts +3 -0
- package/src/renderer/HostConfig.ts +8 -1
- package/src/renderer/components/Group.tsx +16 -3
- package/src/renderer/components/Paint.tsx +7 -1
- package/src/views/SkiaPictureView.tsx +2 -3
- 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
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
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(
|
22
|
-
|
23
|
-
|
24
|
-
|
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(
|
37
|
-
|
38
|
-
|
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->
|
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(
|
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(
|
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*
|
67
|
-
|
68
|
-
|
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 =
|
74
|
-
|
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->
|
80
|
-
|
81
|
-
|
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(),
|
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(
|
109
|
-
|
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
|
-
|
131
|
-
|
132
|
-
|
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<
|
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 "
|
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
|
-
|
185
|
-
|
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
|
-
|
191
|
-
|
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
|
-
} //
|
212
|
+
} // namespace RNSkia
|
package/cpp/rnskia/RNSkJsView.h
CHANGED
@@ -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
|
-
|
36
|
+
namespace jsi = facebook::jsi;
|
36
37
|
|
37
|
-
class RNSkJsRenderer:
|
38
|
-
|
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
|
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
|
57
|
-
|
58
|
-
|
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
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
void updateTouchState(std::vector<RNSkTouchInfo
|
87
|
-
std::static_pointer_cast<RNSkJsRenderer>(getRenderer())
|
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(
|
92
|
-
|
93
|
-
|
94
|
-
|
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())
|
96
|
+
std::static_pointer_cast<RNSkJsRenderer>(getRenderer())
|
97
|
+
->setDrawCallback(nullptr);
|
97
98
|
return;
|
98
|
-
} else if (prop.second.getType() !=
|
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(
|
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())
|
107
|
+
std::static_pointer_cast<RNSkJsRenderer>(getRenderer())
|
108
|
+
->setDrawCallback(prop.second.getAsFunction());
|
105
109
|
|
106
110
|
// Request redraw
|
107
111
|
requestRedraw();
|