@shopify/react-native-skia 0.1.154 → 0.1.156
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- 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/nodes/RenderNode.js +1 -1
- package/lib/commonjs/dom/nodes/RenderNode.js.map +1 -1
- 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/HostComponents.js +3 -0
- package/lib/commonjs/renderer/HostComponents.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/dom/nodes/JsiSkDOM.js +5 -0
- 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/RenderNode.js +1 -1
- package/lib/module/dom/nodes/RenderNode.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/renderer/HostComponents.js +3 -0
- package/lib/module/renderer/HostComponents.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/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/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 +3 -1
- package/src/dom/nodes/JsiSkDOM.ts +5 -0
- package/src/dom/nodes/LayerNode.ts +35 -0
- package/src/dom/nodes/RenderNode.ts +4 -3
- package/src/dom/types/NodeType.ts +1 -0
- package/src/dom/types/SkDOM.ts +1 -0
- package/src/renderer/HostComponents.ts +3 -0
- 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
|
@@ -4,32 +4,32 @@
|
|
|
4
4
|
#include <memory>
|
|
5
5
|
#include <mutex>
|
|
6
6
|
#include <string>
|
|
7
|
+
#include <unordered_map>
|
|
7
8
|
#include <vector>
|
|
8
9
|
|
|
9
10
|
#include <JsiHostObject.h>
|
|
10
11
|
#include <JsiValueWrapper.h>
|
|
11
|
-
#include <RNSkView.h>
|
|
12
12
|
#include <RNSkPlatformContext.h>
|
|
13
13
|
#include <RNSkValue.h>
|
|
14
|
+
#include <RNSkView.h>
|
|
14
15
|
#include <jsi/jsi.h>
|
|
15
16
|
|
|
16
17
|
namespace RNSkia {
|
|
17
|
-
|
|
18
|
+
namespace jsi = facebook::jsi;
|
|
18
19
|
|
|
19
20
|
using RNSkViewInfo = struct RNSkViewInfo {
|
|
20
|
-
RNSkViewInfo() {
|
|
21
|
-
view = nullptr;
|
|
22
|
-
}
|
|
21
|
+
RNSkViewInfo() { view = nullptr; }
|
|
23
22
|
std::shared_ptr<RNSkView> view;
|
|
24
|
-
std::unordered_map<std::string, JsiValueWrapper> props;
|
|
23
|
+
std::unordered_map<std::string, RNJsi::JsiValueWrapper> props;
|
|
25
24
|
};
|
|
26
25
|
|
|
27
|
-
class RNSkJsiViewApi : public JsiHostObject,
|
|
26
|
+
class RNSkJsiViewApi : public RNJsi::JsiHostObject,
|
|
27
|
+
public std::enable_shared_from_this<RNSkJsiViewApi> {
|
|
28
28
|
public:
|
|
29
29
|
/**
|
|
30
|
-
Sets a custom property on a view given a view id. The property name/value
|
|
31
|
-
be stored in a map alongside the id of the view and propagated to the
|
|
32
|
-
needed.
|
|
30
|
+
Sets a custom property on a view given a view id. The property name/value
|
|
31
|
+
will be stored in a map alongside the id of the view and propagated to the
|
|
32
|
+
view when needed.
|
|
33
33
|
*/
|
|
34
34
|
JSI_HOST_FUNCTION(setJsiProperty) {
|
|
35
35
|
if (count != 3) {
|
|
@@ -46,8 +46,8 @@ public:
|
|
|
46
46
|
}
|
|
47
47
|
|
|
48
48
|
if (!arguments[1].isString()) {
|
|
49
|
-
_platformContext->raiseError(
|
|
50
|
-
|
|
49
|
+
_platformContext->raiseError("setJsiProperty: Second argument must be "
|
|
50
|
+
"the name of the property to set.");
|
|
51
51
|
|
|
52
52
|
return jsi::Value::undefined();
|
|
53
53
|
}
|
|
@@ -55,10 +55,11 @@ public:
|
|
|
55
55
|
auto info = getEnsuredViewInfo(nativeId);
|
|
56
56
|
|
|
57
57
|
std::lock_guard<std::mutex> lock(_mutex);
|
|
58
|
-
info->props.emplace(arguments[1].asString(runtime).utf8(runtime),
|
|
58
|
+
info->props.emplace(arguments[1].asString(runtime).utf8(runtime),
|
|
59
|
+
RNJsi::JsiValueWrapper(runtime, arguments[2]));
|
|
59
60
|
|
|
60
61
|
// Now let's see if we have a view that we can update
|
|
61
|
-
if(info->view != nullptr) {
|
|
62
|
+
if (info->view != nullptr) {
|
|
62
63
|
// Update view!
|
|
63
64
|
info->view->setNativeId(nativeId);
|
|
64
65
|
info->view->setJsiProperties(info->props);
|
|
@@ -88,8 +89,8 @@ public:
|
|
|
88
89
|
}
|
|
89
90
|
|
|
90
91
|
if (!arguments[1].isString()) {
|
|
91
|
-
_platformContext->raiseError(
|
|
92
|
-
|
|
92
|
+
_platformContext->raiseError("callCustomCommand: Second argument must be "
|
|
93
|
+
"the name of the action to call.");
|
|
93
94
|
|
|
94
95
|
return jsi::Value::undefined();
|
|
95
96
|
}
|
|
@@ -99,53 +100,58 @@ public:
|
|
|
99
100
|
|
|
100
101
|
auto info = getEnsuredViewInfo(nativeId);
|
|
101
102
|
|
|
102
|
-
if(info->view == nullptr) {
|
|
103
|
-
throw jsi::JSError(
|
|
104
|
-
std::string("callCustomCommand: Could not call action " +
|
|
105
|
-
|
|
103
|
+
if (info->view == nullptr) {
|
|
104
|
+
throw jsi::JSError(
|
|
105
|
+
runtime, std::string("callCustomCommand: Could not call action " +
|
|
106
|
+
action + " on view - view not ready.")
|
|
107
|
+
.c_str());
|
|
106
108
|
|
|
107
109
|
return jsi::Value::undefined();
|
|
108
110
|
}
|
|
109
111
|
|
|
110
112
|
// Get arguments
|
|
111
113
|
size_t paramsCount = count - 2;
|
|
112
|
-
const jsi::Value*
|
|
114
|
+
const jsi::Value *params = paramsCount > 0 ? &arguments[2] : nullptr;
|
|
113
115
|
return info->view->callJsiMethod(runtime, action, params, paramsCount);
|
|
114
116
|
}
|
|
115
117
|
|
|
116
118
|
JSI_HOST_FUNCTION(requestRedraw) {
|
|
117
119
|
if (count != 1) {
|
|
118
|
-
|
|
119
|
-
|
|
120
|
+
_platformContext->raiseError(
|
|
121
|
+
std::string("requestRedraw: Expected 1 arguments, got " +
|
|
122
|
+
std::to_string(count) + "."));
|
|
120
123
|
|
|
121
|
-
|
|
122
|
-
|
|
124
|
+
return jsi::Value::undefined();
|
|
125
|
+
}
|
|
123
126
|
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
+
if (!arguments[0].isNumber()) {
|
|
128
|
+
_platformContext->raiseError(
|
|
129
|
+
"requestRedraw: First argument must be a number");
|
|
127
130
|
|
|
128
|
-
|
|
129
|
-
|
|
131
|
+
return jsi::Value::undefined();
|
|
132
|
+
}
|
|
130
133
|
|
|
131
|
-
|
|
132
|
-
|
|
134
|
+
// find Skia View
|
|
135
|
+
int nativeId = arguments[0].asNumber();
|
|
133
136
|
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
137
|
+
auto info = getEnsuredViewInfo(nativeId);
|
|
138
|
+
if (info->view != nullptr) {
|
|
139
|
+
info->view->requestRedraw();
|
|
140
|
+
}
|
|
141
|
+
return jsi::Value::undefined();
|
|
139
142
|
}
|
|
140
143
|
|
|
141
144
|
JSI_HOST_FUNCTION(makeImageSnapshot) {
|
|
142
145
|
if (count < 1) {
|
|
143
|
-
_platformContext->raiseError(
|
|
146
|
+
_platformContext->raiseError(
|
|
147
|
+
std::string("makeImageSnapshot: Expected at least 1 argument, got " +
|
|
148
|
+
std::to_string(count) + "."));
|
|
144
149
|
return jsi::Value::undefined();
|
|
145
150
|
}
|
|
146
151
|
|
|
147
152
|
if (!arguments[0].isNumber()) {
|
|
148
|
-
_platformContext->raiseError(
|
|
153
|
+
_platformContext->raiseError(
|
|
154
|
+
"makeImageSnapshot: First argument must be a number");
|
|
149
155
|
return jsi::Value::undefined();
|
|
150
156
|
}
|
|
151
157
|
|
|
@@ -154,68 +160,74 @@ public:
|
|
|
154
160
|
sk_sp<SkImage> image;
|
|
155
161
|
auto info = getEnsuredViewInfo(nativeId);
|
|
156
162
|
if (info->view != nullptr) {
|
|
157
|
-
if(count > 1 && !arguments[1].isUndefined() && !arguments[1].isNull()) {
|
|
163
|
+
if (count > 1 && !arguments[1].isUndefined() && !arguments[1].isNull()) {
|
|
158
164
|
auto rect = JsiSkRect::fromValue(runtime, arguments[1]);
|
|
159
165
|
image = info->view->makeImageSnapshot(rect);
|
|
160
166
|
} else {
|
|
161
167
|
image = info->view->makeImageSnapshot(nullptr);
|
|
162
168
|
}
|
|
163
|
-
if(image == nullptr) {
|
|
164
|
-
throw jsi::JSError(runtime,
|
|
169
|
+
if (image == nullptr) {
|
|
170
|
+
throw jsi::JSError(runtime,
|
|
171
|
+
"Could not create image from current surface.");
|
|
165
172
|
return jsi::Value::undefined();
|
|
166
173
|
}
|
|
167
|
-
return jsi::Object::createFromHostObject(
|
|
174
|
+
return jsi::Object::createFromHostObject(
|
|
175
|
+
runtime, std::make_shared<JsiSkImage>(_platformContext, image));
|
|
168
176
|
}
|
|
169
177
|
throw jsi::JSError(runtime, "No Skia View currently available.");
|
|
170
178
|
return jsi::Value::undefined();
|
|
171
179
|
}
|
|
172
180
|
|
|
173
181
|
JSI_HOST_FUNCTION(registerValuesInView) {
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
182
|
+
// Check params
|
|
183
|
+
if (!arguments[1].isObject() ||
|
|
184
|
+
!arguments[1].asObject(runtime).isArray(runtime)) {
|
|
185
|
+
throw jsi::JSError(runtime,
|
|
186
|
+
"Expected array of Values as second parameter");
|
|
187
|
+
return jsi::Value::undefined();
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
// Get identifier of native SkiaView
|
|
191
|
+
int nativeId = arguments[0].asNumber();
|
|
179
192
|
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
193
|
+
// Get values that should be added as dependencies
|
|
194
|
+
auto values = arguments[1].asObject(runtime).asArray(runtime);
|
|
195
|
+
std::vector<std::function<void()>> unsubscribers;
|
|
196
|
+
const std::size_t size = values.size(runtime);
|
|
197
|
+
unsubscribers.reserve(size);
|
|
198
|
+
for (size_t i = 0; i < size; ++i) {
|
|
199
|
+
auto value = values.getValueAtIndex(runtime, i)
|
|
200
|
+
.asObject(runtime)
|
|
201
|
+
.asHostObject<RNSkReadonlyValue>(runtime);
|
|
202
|
+
|
|
203
|
+
if (value != nullptr) {
|
|
204
|
+
// Add change listener
|
|
205
|
+
unsubscribers.push_back(value->addListener(
|
|
206
|
+
[weakSelf = weak_from_this(), nativeId](jsi::Runtime &) {
|
|
207
|
+
auto self = weakSelf.lock();
|
|
208
|
+
if (self) {
|
|
209
|
+
auto info = self->getEnsuredViewInfo(nativeId);
|
|
210
|
+
if (info->view != nullptr) {
|
|
211
|
+
info->view->requestRedraw();
|
|
212
|
+
}
|
|
199
213
|
}
|
|
200
|
-
}
|
|
201
|
-
}));
|
|
202
|
-
}
|
|
214
|
+
}));
|
|
203
215
|
}
|
|
204
|
-
|
|
205
|
-
// Return unsubscribe method that unsubscribes to all values
|
|
206
|
-
// that we subscribed to.
|
|
207
|
-
return jsi::Function::createFromHostFunction(runtime,
|
|
208
|
-
jsi::PropNameID::forUtf8(runtime, "unsubscribe"),
|
|
209
|
-
0,
|
|
210
|
-
JSI_HOST_FUNCTION_LAMBDA {
|
|
211
|
-
// decrease dependency count on the Skia View
|
|
212
|
-
for(auto &unsub : unsubscribers) {
|
|
213
|
-
unsub();
|
|
214
|
-
}
|
|
215
|
-
return jsi::Value::undefined();
|
|
216
|
-
});
|
|
217
216
|
}
|
|
218
217
|
|
|
218
|
+
// Return unsubscribe method that unsubscribes to all values
|
|
219
|
+
// that we subscribed to.
|
|
220
|
+
return jsi::Function::createFromHostFunction(
|
|
221
|
+
runtime, jsi::PropNameID::forUtf8(runtime, "unsubscribe"), 0,
|
|
222
|
+
JSI_HOST_FUNCTION_LAMBDA {
|
|
223
|
+
// decrease dependency count on the Skia View
|
|
224
|
+
for (auto &unsub : unsubscribers) {
|
|
225
|
+
unsub();
|
|
226
|
+
}
|
|
227
|
+
return jsi::Value::undefined();
|
|
228
|
+
});
|
|
229
|
+
}
|
|
230
|
+
|
|
219
231
|
JSI_EXPORT_FUNCTIONS(JSI_EXPORT_FUNC(RNSkJsiViewApi, setJsiProperty),
|
|
220
232
|
JSI_EXPORT_FUNC(RNSkJsiViewApi, callJsiMethod),
|
|
221
233
|
JSI_EXPORT_FUNC(RNSkJsiViewApi, registerValuesInView),
|
|
@@ -226,15 +238,13 @@ public:
|
|
|
226
238
|
* Constructor
|
|
227
239
|
* @param platformContext Platform context
|
|
228
240
|
*/
|
|
229
|
-
RNSkJsiViewApi(std::shared_ptr<RNSkPlatformContext> platformContext)
|
|
241
|
+
explicit RNSkJsiViewApi(std::shared_ptr<RNSkPlatformContext> platformContext)
|
|
230
242
|
: JsiHostObject(), _platformContext(platformContext) {}
|
|
231
243
|
|
|
232
244
|
/**
|
|
233
245
|
* Invalidates the Skia View Api object
|
|
234
246
|
*/
|
|
235
|
-
void invalidate() {
|
|
236
|
-
unregisterAll();
|
|
237
|
-
}
|
|
247
|
+
void invalidate() { unregisterAll(); }
|
|
238
248
|
|
|
239
249
|
/**
|
|
240
250
|
Call to remove all draw view infos
|
|
@@ -242,7 +252,7 @@ public:
|
|
|
242
252
|
void unregisterAll() {
|
|
243
253
|
// Unregister all views
|
|
244
254
|
auto tempList = _viewInfos;
|
|
245
|
-
for (const auto&
|
|
255
|
+
for (const auto &info : tempList) {
|
|
246
256
|
unregisterSkiaView(info.first);
|
|
247
257
|
}
|
|
248
258
|
std::lock_guard<std::mutex> lock(_mutex);
|
|
@@ -295,7 +305,7 @@ public:
|
|
|
295
305
|
info->view->setNativeId(nativeId);
|
|
296
306
|
info->view->setJsiProperties(info->props);
|
|
297
307
|
info->props.clear();
|
|
298
|
-
} else if(view == nullptr) {
|
|
308
|
+
} else if (view == nullptr) {
|
|
299
309
|
info->view = view;
|
|
300
310
|
}
|
|
301
311
|
}
|
|
@@ -7,11 +7,11 @@
|
|
|
7
7
|
|
|
8
8
|
#include <JsiSkApi.h>
|
|
9
9
|
#include <RNSkJsiViewApi.h>
|
|
10
|
-
#include <RNSkView.h>
|
|
11
10
|
#include <RNSkValueApi.h>
|
|
11
|
+
#include <RNSkView.h>
|
|
12
12
|
|
|
13
13
|
namespace RNSkia {
|
|
14
|
-
|
|
14
|
+
namespace jsi = facebook::jsi;
|
|
15
15
|
|
|
16
16
|
RNSkManager::RNSkManager(
|
|
17
17
|
jsi::Runtime *jsRuntime,
|
|
@@ -35,17 +35,18 @@ RNSkManager::~RNSkManager() {
|
|
|
35
35
|
}
|
|
36
36
|
|
|
37
37
|
void RNSkManager::invalidate() {
|
|
38
|
-
if(_isInvalidated) {
|
|
38
|
+
if (_isInvalidated) {
|
|
39
39
|
return;
|
|
40
40
|
}
|
|
41
41
|
_isInvalidated = true;
|
|
42
|
-
|
|
42
|
+
|
|
43
43
|
// Invalidate members
|
|
44
44
|
_viewApi->invalidate();
|
|
45
45
|
_platformContext->invalidate();
|
|
46
46
|
}
|
|
47
47
|
|
|
48
|
-
void RNSkManager::registerSkiaView(size_t nativeId,
|
|
48
|
+
void RNSkManager::registerSkiaView(size_t nativeId,
|
|
49
|
+
std::shared_ptr<RNSkView> view) {
|
|
49
50
|
if (!_isInvalidated && _viewApi != nullptr)
|
|
50
51
|
_viewApi->registerSkiaView(nativeId, view);
|
|
51
52
|
}
|
|
@@ -75,7 +76,7 @@ void RNSkManager::installBindings() {
|
|
|
75
76
|
|
|
76
77
|
auto skiaValueApi = std::make_shared<RNSkValueApi>(_platformContext);
|
|
77
78
|
_jsRuntime->global().setProperty(
|
|
78
|
-
|
|
79
|
-
|
|
79
|
+
*_jsRuntime, "SkiaValueApi",
|
|
80
|
+
jsi::Object::createFromHostObject(*_jsRuntime, std::move(skiaValueApi)));
|
|
80
81
|
}
|
|
81
82
|
} // namespace RNSkia
|
package/cpp/rnskia/RNSkManager.h
CHANGED
|
@@ -6,15 +6,17 @@
|
|
|
6
6
|
#include "RNSkPlatformContext.h"
|
|
7
7
|
|
|
8
8
|
namespace facebook {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
}
|
|
9
|
+
namespace react {
|
|
10
|
+
class CallInvoker;
|
|
12
11
|
}
|
|
12
|
+
} // namespace facebook
|
|
13
13
|
|
|
14
14
|
namespace RNSkia {
|
|
15
15
|
class RNSkView;
|
|
16
16
|
class RNSkJsiViewApi;
|
|
17
|
-
|
|
17
|
+
|
|
18
|
+
namespace jsi = facebook::jsi;
|
|
19
|
+
namespace react = facebook::react;
|
|
18
20
|
|
|
19
21
|
class RNSkManager {
|
|
20
22
|
public:
|
|
@@ -30,7 +32,7 @@ public:
|
|
|
30
32
|
std::shared_ptr<RNSkPlatformContext> platformContext);
|
|
31
33
|
|
|
32
34
|
~RNSkManager();
|
|
33
|
-
|
|
35
|
+
|
|
34
36
|
/**
|
|
35
37
|
Invalidates the Skia Manager
|
|
36
38
|
*/
|
|
@@ -48,7 +50,7 @@ public:
|
|
|
48
50
|
* @param nativeId Native view Id
|
|
49
51
|
*/
|
|
50
52
|
void unregisterSkiaView(size_t nativeId);
|
|
51
|
-
|
|
53
|
+
|
|
52
54
|
/**
|
|
53
55
|
Sets the view pointed to by nativeId to the provided value.
|
|
54
56
|
Used when we want to remove a view without unregistering it
|
|
@@ -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 <JsiSkPicture.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 <JsiSkPicture.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,85 +33,91 @@ class SkImage;
|
|
|
32
33
|
|
|
33
34
|
namespace RNSkia {
|
|
34
35
|
|
|
35
|
-
|
|
36
|
+
namespace jsi = facebook::jsi;
|
|
36
37
|
|
|
37
|
-
class RNSkPictureRenderer
|
|
38
|
-
|
|
39
|
-
|
|
38
|
+
class RNSkPictureRenderer
|
|
39
|
+
: public RNSkRenderer,
|
|
40
|
+
public std::enable_shared_from_this<RNSkPictureRenderer> {
|
|
40
41
|
public:
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
_platformContext(context) {}
|
|
42
|
+
RNSkPictureRenderer(std::function<void()> requestRedraw,
|
|
43
|
+
std::shared_ptr<RNSkPlatformContext> context)
|
|
44
|
+
: RNSkRenderer(requestRedraw), _platformContext(context) {}
|
|
45
45
|
|
|
46
46
|
bool tryRender(std::shared_ptr<RNSkCanvasProvider> canvasProvider) override {
|
|
47
47
|
performDraw(canvasProvider);
|
|
48
48
|
return true;
|
|
49
49
|
}
|
|
50
|
-
|
|
51
|
-
void
|
|
50
|
+
|
|
51
|
+
void
|
|
52
|
+
renderImmediate(std::shared_ptr<RNSkCanvasProvider> canvasProvider) override {
|
|
52
53
|
performDraw(canvasProvider);
|
|
53
54
|
}
|
|
54
55
|
|
|
55
56
|
void setPicture(std::shared_ptr<jsi::HostObject> picture) {
|
|
56
|
-
if(picture == nullptr) {
|
|
57
|
+
if (picture == nullptr) {
|
|
57
58
|
_picture = nullptr;
|
|
58
59
|
return;
|
|
59
60
|
}
|
|
60
|
-
|
|
61
|
+
|
|
61
62
|
_picture = std::dynamic_pointer_cast<JsiSkPicture>(picture);
|
|
62
63
|
_requestRedraw();
|
|
63
64
|
}
|
|
64
|
-
|
|
65
|
+
|
|
65
66
|
private:
|
|
66
67
|
void performDraw(std::shared_ptr<RNSkCanvasProvider> canvasProvider) {
|
|
67
|
-
if(_picture == nullptr) {
|
|
68
|
+
if (_picture == nullptr) {
|
|
68
69
|
return;
|
|
69
70
|
}
|
|
70
|
-
|
|
71
|
-
canvasProvider->renderToCanvas([=](SkCanvas*
|
|
71
|
+
|
|
72
|
+
canvasProvider->renderToCanvas([=](SkCanvas *canvas) {
|
|
72
73
|
// Make sure to scale correctly
|
|
73
74
|
auto pd = _platformContext->getPixelDensity();
|
|
74
75
|
canvas->save();
|
|
75
76
|
canvas->scale(pd, pd);
|
|
76
|
-
|
|
77
|
+
|
|
77
78
|
canvas->drawPicture(_picture->getObject());
|
|
78
|
-
|
|
79
|
+
|
|
79
80
|
// Restore and flush canvas
|
|
80
81
|
canvas->restore();
|
|
81
82
|
canvas->flush();
|
|
82
83
|
});
|
|
83
84
|
}
|
|
84
|
-
|
|
85
|
+
|
|
85
86
|
std::shared_ptr<RNSkPlatformContext> _platformContext;
|
|
86
87
|
std::shared_ptr<JsiSkPicture> _picture;
|
|
87
88
|
};
|
|
88
89
|
|
|
89
|
-
class RNSkPictureView: public RNSkView {
|
|
90
|
+
class RNSkPictureView : public RNSkView {
|
|
90
91
|
public:
|
|
91
92
|
/**
|
|
92
93
|
* Constructor
|
|
93
94
|
*/
|
|
94
95
|
RNSkPictureView(std::shared_ptr<RNSkPlatformContext> context,
|
|
95
|
-
std::shared_ptr<RNSkCanvasProvider> canvasProvider)
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
96
|
+
std::shared_ptr<RNSkCanvasProvider> canvasProvider)
|
|
97
|
+
: RNSkView(
|
|
98
|
+
context, canvasProvider,
|
|
99
|
+
std::make_shared<RNSkPictureRenderer>(
|
|
100
|
+
std::bind(&RNSkPictureView::requestRedraw, this), context)) {}
|
|
101
|
+
|
|
102
|
+
void setJsiProperties(
|
|
103
|
+
std::unordered_map<std::string, RNJsi::JsiValueWrapper> &props) override {
|
|
104
|
+
for (auto &prop : props) {
|
|
105
|
+
if (prop.first == "picture") {
|
|
106
|
+
if (prop.second.isUndefinedOrNull()) {
|
|
104
107
|
// Clear picture
|
|
105
|
-
std::static_pointer_cast<RNSkPictureRenderer>(getRenderer())
|
|
108
|
+
std::static_pointer_cast<RNSkPictureRenderer>(getRenderer())
|
|
109
|
+
->setPicture(nullptr);
|
|
106
110
|
return;
|
|
107
|
-
} else if (prop.second.getType() !=
|
|
111
|
+
} else if (prop.second.getType() !=
|
|
112
|
+
RNJsi::JsiWrapperValueType::HostObject) {
|
|
108
113
|
// We expect a function for the picture custom property
|
|
109
|
-
throw std::runtime_error(
|
|
114
|
+
throw std::runtime_error(
|
|
115
|
+
"Expected an object for the picture custom property.");
|
|
110
116
|
}
|
|
111
117
|
|
|
112
118
|
// Save picture
|
|
113
|
-
std::static_pointer_cast<RNSkPictureRenderer>(getRenderer())
|
|
119
|
+
std::static_pointer_cast<RNSkPictureRenderer>(getRenderer())
|
|
120
|
+
->setPicture(prop.second.getAsHostObject());
|
|
114
121
|
|
|
115
122
|
// Request redraw
|
|
116
123
|
requestRedraw();
|