@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.
- 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/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/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/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
@@ -1,15 +1,15 @@
|
|
1
1
|
#include "JniPlatformContext.h"
|
2
2
|
#include "JniSkiaDrawView.h"
|
3
|
-
#include "JniSkiaPictureView.h"
|
4
3
|
#include "JniSkiaManager.h"
|
4
|
+
#include "JniSkiaPictureView.h"
|
5
5
|
#include <fbjni/fbjni.h>
|
6
6
|
#include <jni.h>
|
7
7
|
|
8
8
|
JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM *vm, void *) {
|
9
9
|
return facebook::jni::initialize(vm, [] {
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
10
|
+
RNSkia::JniSkiaManager::registerNatives();
|
11
|
+
RNSkia::JniSkiaDrawView::registerNatives();
|
12
|
+
RNSkia::JniSkiaPictureView::registerNatives();
|
13
|
+
RNSkia::JniPlatformContext::registerNatives();
|
14
14
|
});
|
15
15
|
}
|
@@ -4,139 +4,127 @@
|
|
4
4
|
#include <thread>
|
5
5
|
#include <utility>
|
6
6
|
|
7
|
-
#include <RNSkMeasureTime.h>
|
8
7
|
#include "SkData.h"
|
9
8
|
#include "SkRefCnt.h"
|
10
|
-
#include "SkTypes.h"
|
11
9
|
#include "SkStream.h"
|
10
|
+
#include "SkTypes.h"
|
11
|
+
#include <RNSkMeasureTime.h>
|
12
12
|
|
13
|
-
namespace RNSkia
|
14
|
-
|
15
|
-
|
16
|
-
|
13
|
+
namespace RNSkia {
|
14
|
+
|
15
|
+
namespace jsi = facebook::jsi;
|
16
|
+
|
17
|
+
using TSelf = jni::local_ref<JniPlatformContext::jhybriddata>;
|
18
|
+
|
19
|
+
void JniPlatformContext::registerNatives() {
|
20
|
+
registerHybrid({
|
21
|
+
makeNativeMethod("initHybrid", JniPlatformContext::initHybrid),
|
22
|
+
makeNativeMethod("notifyDrawLoop",
|
23
|
+
JniPlatformContext::notifyDrawLoopExternal),
|
24
|
+
makeNativeMethod("notifyTaskReady",
|
25
|
+
JniPlatformContext::notifyTaskReadyExternal),
|
26
|
+
});
|
27
|
+
}
|
28
|
+
|
29
|
+
TSelf JniPlatformContext::initHybrid(jni::alias_ref<jhybridobject> jThis,
|
30
|
+
float pixelDensity) {
|
31
|
+
return makeCxxInstance(jThis, pixelDensity);
|
32
|
+
}
|
33
|
+
|
34
|
+
void JniPlatformContext::startDrawLoop() {
|
35
|
+
jni::ThreadScope ts;
|
36
|
+
// Start drawing loop
|
37
|
+
static auto method =
|
38
|
+
javaPart_->getClass()->getMethod<void(void)>("beginDrawLoop");
|
39
|
+
method(javaPart_.get());
|
40
|
+
}
|
41
|
+
|
42
|
+
void JniPlatformContext::stopDrawLoop() {
|
43
|
+
jni::ThreadScope ts;
|
44
|
+
// Stop drawing loop
|
45
|
+
static auto method =
|
46
|
+
javaPart_->getClass()->getMethod<void(void)>("endDrawLoop");
|
47
|
+
method(javaPart_.get());
|
48
|
+
}
|
49
|
+
|
50
|
+
void JniPlatformContext::notifyDrawLoopExternal() {
|
51
|
+
jni::ThreadScope ts;
|
52
|
+
_onNotifyDrawLoop();
|
53
|
+
}
|
54
|
+
|
55
|
+
void JniPlatformContext::notifyTaskReadyExternal() {
|
56
|
+
_taskMutex->lock();
|
57
|
+
auto task = _taskCallbacks.front();
|
58
|
+
if (task != nullptr) {
|
59
|
+
_taskCallbacks.pop();
|
60
|
+
_taskMutex->unlock();
|
61
|
+
task();
|
62
|
+
} else {
|
63
|
+
_taskMutex->unlock();
|
64
|
+
}
|
65
|
+
}
|
66
|
+
|
67
|
+
void JniPlatformContext::performStreamOperation(
|
68
|
+
const std::string &sourceUri,
|
69
|
+
const std::function<void(std::unique_ptr<SkStreamAsset>)> &op) {
|
70
|
+
auto measure = RNSkMeasureTime("JniPlatformContext::performStreamOperation");
|
71
|
+
|
72
|
+
static auto method = javaPart_->getClass()->getMethod<jbyteArray(jstring)>(
|
73
|
+
"getJniStreamFromSource");
|
74
|
+
|
75
|
+
auto loader = [=]() -> void {
|
76
|
+
jni::ThreadScope ts;
|
77
|
+
jstring jstr =
|
78
|
+
(*jni::Environment::current()).NewStringUTF(sourceUri.c_str());
|
79
|
+
|
80
|
+
// Get the array with data from input stream from Java
|
81
|
+
auto array = method(javaPart_.get(), jstr);
|
82
|
+
|
83
|
+
if (array == nullptr) {
|
84
|
+
printf("Calling getJniStreamFromSource failed\n");
|
85
|
+
return;
|
86
|
+
}
|
17
87
|
|
18
|
-
|
88
|
+
// Allocate buffer for java byte array
|
89
|
+
jsize num_bytes = jni::Environment::current()->GetArrayLength(array.get());
|
90
|
+
char *buffer = reinterpret_cast<char *>(malloc(num_bytes + 1));
|
19
91
|
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
makeNativeMethod("initHybrid", JniPlatformContext::initHybrid),
|
24
|
-
makeNativeMethod("notifyDrawLoop", JniPlatformContext::notifyDrawLoopExternal),
|
25
|
-
makeNativeMethod("notifyTaskReady", JniPlatformContext::notifyTaskReadyExternal),
|
26
|
-
});
|
92
|
+
if (!buffer) {
|
93
|
+
printf("Buff Fail\n");
|
94
|
+
return;
|
27
95
|
}
|
28
96
|
|
29
|
-
|
30
|
-
|
31
|
-
|
97
|
+
jbyte *elements =
|
98
|
+
jni::Environment::current()->GetByteArrayElements(array.get(), nullptr);
|
99
|
+
if (!elements) {
|
100
|
+
printf("Element Fail\n");
|
101
|
+
return;
|
32
102
|
}
|
33
103
|
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
// Start drawing loop
|
38
|
-
static auto method = javaPart_->getClass()->getMethod<void(void)>("beginDrawLoop");
|
39
|
-
method(javaPart_.get());
|
40
|
-
}
|
104
|
+
// Copy data from java array to buffer
|
105
|
+
memcpy(buffer, elements, num_bytes);
|
106
|
+
buffer[num_bytes] = 0;
|
41
107
|
|
42
|
-
|
43
|
-
|
44
|
-
jni::ThreadScope ts;
|
45
|
-
// Stop drawing loop
|
46
|
-
static auto method = javaPart_->getClass()->getMethod<void(void)>("endDrawLoop");
|
47
|
-
method(javaPart_.get());
|
48
|
-
}
|
108
|
+
jni::Environment::current()->ReleaseByteArrayElements(array.get(), elements,
|
109
|
+
JNI_ABORT);
|
49
110
|
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
_onNotifyDrawLoop();
|
54
|
-
}
|
111
|
+
// Copy malloced data and give ownership to SkData
|
112
|
+
auto data = SkData::MakeFromMalloc(buffer, num_bytes);
|
113
|
+
auto skStream = SkMemoryStream::Make(data);
|
55
114
|
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
auto task = _taskCallbacks.front();
|
60
|
-
if (task != nullptr)
|
61
|
-
{
|
62
|
-
_taskCallbacks.pop();
|
63
|
-
_taskMutex->unlock();
|
64
|
-
task();
|
65
|
-
}
|
66
|
-
else
|
67
|
-
{
|
68
|
-
_taskMutex->unlock();
|
69
|
-
}
|
70
|
-
}
|
115
|
+
// Perform operation
|
116
|
+
op(std::move(skStream));
|
117
|
+
};
|
71
118
|
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
{
|
76
|
-
auto measure =
|
77
|
-
RNSkMeasureTime("JniPlatformContext::performStreamOperation");
|
78
|
-
|
79
|
-
static auto method = javaPart_->getClass()->getMethod<jbyteArray(jstring)>(
|
80
|
-
"getJniStreamFromSource");
|
81
|
-
|
82
|
-
auto loader = [=]() -> void
|
83
|
-
{
|
84
|
-
jni::ThreadScope ts;
|
85
|
-
jstring jstr =
|
86
|
-
(*jni::Environment::current()).NewStringUTF(sourceUri.c_str());
|
87
|
-
|
88
|
-
// Get the array with data from input stream from Java
|
89
|
-
auto array = method(javaPart_.get(), jstr);
|
90
|
-
|
91
|
-
if (array == nullptr)
|
92
|
-
{
|
93
|
-
printf("Calling getJniStreamFromSource failed\n");
|
94
|
-
return;
|
95
|
-
}
|
96
|
-
|
97
|
-
// Allocate buffer for java byte array
|
98
|
-
jsize num_bytes =
|
99
|
-
jni::Environment::current()->GetArrayLength(array.get());
|
100
|
-
char *buffer = (char *)malloc(num_bytes + 1);
|
101
|
-
|
102
|
-
if (!buffer)
|
103
|
-
{
|
104
|
-
printf("Buff Fail\n");
|
105
|
-
return;
|
106
|
-
}
|
107
|
-
|
108
|
-
jbyte *elements = jni::Environment::current()->GetByteArrayElements(
|
109
|
-
array.get(), nullptr);
|
110
|
-
if (!elements)
|
111
|
-
{
|
112
|
-
printf("Element Fail\n");
|
113
|
-
return;
|
114
|
-
}
|
115
|
-
|
116
|
-
// Copy data from java array to buffer
|
117
|
-
memcpy(buffer, elements, num_bytes);
|
118
|
-
buffer[num_bytes] = 0;
|
119
|
-
|
120
|
-
jni::Environment::current()->ReleaseByteArrayElements(
|
121
|
-
array.get(), elements, JNI_ABORT);
|
122
|
-
|
123
|
-
// Copy malloced data and give ownership to SkData
|
124
|
-
auto data = SkData::MakeFromMalloc(buffer, num_bytes);
|
125
|
-
auto skStream = SkMemoryStream::Make(data);
|
126
|
-
|
127
|
-
// Perform operation
|
128
|
-
op(std::move(skStream));
|
129
|
-
};
|
130
|
-
|
131
|
-
// Fire and forget the thread - will be resolved on completion
|
132
|
-
std::thread(loader).detach();
|
133
|
-
}
|
119
|
+
// Fire and forget the thread - will be resolved on completion
|
120
|
+
std::thread(loader).detach();
|
121
|
+
}
|
134
122
|
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
123
|
+
void JniPlatformContext::raiseError(const std::exception &err) {
|
124
|
+
jni::ThreadScope ts;
|
125
|
+
static auto method =
|
126
|
+
javaPart_->getClass()->getMethod<void(std::string)>("raise");
|
127
|
+
method(javaPart_.get(), std::string(err.what()));
|
128
|
+
}
|
141
129
|
|
142
130
|
} // namespace RNSkia
|
@@ -10,35 +10,33 @@
|
|
10
10
|
|
11
11
|
namespace RNSkia {
|
12
12
|
|
13
|
-
|
13
|
+
namespace jsi = facebook::jsi;
|
14
14
|
|
15
15
|
// JNI binding
|
16
16
|
void JniSkiaManager::registerNatives() {
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
17
|
+
registerHybrid({
|
18
|
+
makeNativeMethod("initHybrid", JniSkiaManager::initHybrid),
|
19
|
+
makeNativeMethod("initializeRuntime", JniSkiaManager::initializeRuntime),
|
20
|
+
makeNativeMethod("invalidate", JniSkiaManager::invalidate),
|
21
|
+
});
|
22
22
|
}
|
23
23
|
|
24
24
|
// JNI init
|
25
|
-
jni::local_ref<jni::HybridClass<JniSkiaManager>::jhybriddata>
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
reinterpret_cast<jsi::Runtime *>(jsContext),
|
35
|
-
jsCallInvokerHolder->cthis()->getCallInvoker(),
|
36
|
-
skiaContext->cthis());
|
25
|
+
jni::local_ref<jni::HybridClass<JniSkiaManager>::jhybriddata>
|
26
|
+
JniSkiaManager::initHybrid(jni::alias_ref<jhybridobject> jThis, jlong jsContext,
|
27
|
+
JSCallInvokerHolder jsCallInvokerHolder,
|
28
|
+
JavaPlatformContext skiaContext) {
|
29
|
+
|
30
|
+
// cast from JNI hybrid objects to C++ instances
|
31
|
+
return makeCxxInstance(jThis, reinterpret_cast<jsi::Runtime *>(jsContext),
|
32
|
+
jsCallInvokerHolder->cthis()->getCallInvoker(),
|
33
|
+
skiaContext->cthis());
|
37
34
|
}
|
38
35
|
|
39
36
|
void JniSkiaManager::initializeRuntime() {
|
40
|
-
|
41
|
-
|
37
|
+
// Create the cross platform skia manager
|
38
|
+
_skManager =
|
39
|
+
std::make_shared<RNSkManager>(_jsRuntime, _jsCallInvoker, _context);
|
42
40
|
}
|
43
41
|
|
44
42
|
} // namespace RNSkia
|
@@ -1,75 +1,71 @@
|
|
1
1
|
#pragma once
|
2
2
|
|
3
|
-
#include <fbjni/fbjni.h>
|
4
3
|
#include <ReactCommon/CallInvokerHolder.h>
|
4
|
+
#include <fbjni/fbjni.h>
|
5
5
|
|
6
|
-
#include <
|
7
|
-
#include <mutex>
|
6
|
+
#include <exception>
|
8
7
|
#include <functional>
|
9
8
|
#include <memory>
|
9
|
+
#include <mutex>
|
10
|
+
#include <queue>
|
10
11
|
#include <string>
|
11
|
-
#include <exception>
|
12
12
|
|
13
13
|
#include "RNSkPlatformContext.h"
|
14
14
|
|
15
15
|
class SkStreamAsset;
|
16
|
-
namespace RNSkia
|
17
|
-
{
|
16
|
+
namespace RNSkia {
|
18
17
|
|
19
|
-
|
18
|
+
namespace jsi = facebook::jsi;
|
19
|
+
namespace jni = facebook::jni;
|
20
20
|
|
21
|
-
|
22
|
-
|
21
|
+
using JSCallInvokerHolder =
|
22
|
+
jni::alias_ref<facebook::react::CallInvokerHolder::javaobject>;
|
23
23
|
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
24
|
+
class JniPlatformContext : public jni::HybridClass<JniPlatformContext> {
|
25
|
+
public:
|
26
|
+
static auto constexpr kJavaDescriptor =
|
27
|
+
"Lcom/shopify/reactnative/skia/PlatformContext;";
|
28
28
|
|
29
|
-
|
30
|
-
|
31
|
-
const float);
|
29
|
+
static jni::local_ref<jhybriddata>
|
30
|
+
initHybrid(jni::alias_ref<jhybridobject> jThis, const float);
|
32
31
|
|
33
|
-
|
32
|
+
static void registerNatives();
|
34
33
|
|
35
|
-
|
36
|
-
|
37
|
-
|
34
|
+
void performStreamOperation(
|
35
|
+
const std::string &sourceUri,
|
36
|
+
const std::function<void(std::unique_ptr<SkStreamAsset>)> &op);
|
38
37
|
|
39
|
-
|
38
|
+
void raiseError(const std::exception &err);
|
40
39
|
|
41
|
-
|
42
|
-
|
40
|
+
void startDrawLoop();
|
41
|
+
void stopDrawLoop();
|
43
42
|
|
44
|
-
|
43
|
+
void notifyDrawLoopExternal();
|
45
44
|
|
46
|
-
|
45
|
+
void notifyTaskReadyExternal();
|
47
46
|
|
48
|
-
|
47
|
+
float getPixelDensity() { return _pixelDensity; }
|
49
48
|
|
50
|
-
|
51
|
-
|
52
|
-
|
49
|
+
void setOnNotifyDrawLoop(const std::function<void(void)> &callback) {
|
50
|
+
_onNotifyDrawLoop = callback;
|
51
|
+
}
|
53
52
|
|
54
|
-
|
55
|
-
|
56
|
-
|
53
|
+
private:
|
54
|
+
friend HybridBase;
|
55
|
+
jni::global_ref<JniPlatformContext::javaobject> javaPart_;
|
57
56
|
|
58
|
-
|
57
|
+
float _pixelDensity;
|
59
58
|
|
60
|
-
|
59
|
+
std::function<void(void)> _onNotifyDrawLoop;
|
61
60
|
|
62
|
-
|
61
|
+
std::queue<std::function<void()>> _taskCallbacks;
|
63
62
|
|
64
|
-
|
63
|
+
std::shared_ptr<std::mutex> _taskMutex;
|
65
64
|
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
{
|
73
|
-
}
|
74
|
-
};
|
65
|
+
explicit JniPlatformContext(
|
66
|
+
jni::alias_ref<JniPlatformContext::jhybridobject> jThis,
|
67
|
+
const float pixelDensity)
|
68
|
+
: _taskMutex(std::make_shared<std::mutex>()),
|
69
|
+
javaPart_(jni::make_global(jThis)), _pixelDensity(pixelDensity) {}
|
70
|
+
};
|
75
71
|
} // namespace RNSkia
|
@@ -1,68 +1,65 @@
|
|
1
1
|
#pragma once
|
2
2
|
|
3
3
|
#include <memory>
|
4
|
+
#include <string>
|
4
5
|
|
5
6
|
#include <fbjni/fbjni.h>
|
6
7
|
#include <jni.h>
|
7
8
|
#include <jsi/jsi.h>
|
8
9
|
|
9
10
|
#include <JniSkiaManager.h>
|
11
|
+
#include <RNSkAndroidView.h>
|
10
12
|
|
11
13
|
namespace RNSkia {
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
private:
|
64
|
-
JniSkiaManager *_manager;
|
65
|
-
std::shared_ptr<RNSkBaseAndroidView> _skiaView;
|
66
|
-
};
|
14
|
+
|
15
|
+
namespace jsi = facebook::jsi;
|
16
|
+
|
17
|
+
class JniSkiaBaseView {
|
18
|
+
public:
|
19
|
+
JniSkiaBaseView(jni::alias_ref<JniSkiaManager::javaobject> skiaManager,
|
20
|
+
std::shared_ptr<RNSkBaseAndroidView> skiaView)
|
21
|
+
: _manager(skiaManager->cthis()), _skiaView(skiaView) {}
|
22
|
+
|
23
|
+
~JniSkiaBaseView() {}
|
24
|
+
|
25
|
+
std::shared_ptr<RNSkManager> getSkiaManager() {
|
26
|
+
return _manager->getSkiaManager();
|
27
|
+
}
|
28
|
+
|
29
|
+
protected:
|
30
|
+
virtual void updateTouchPoints(jni::JArrayDouble touches) {
|
31
|
+
_skiaView->updateTouchPoints(touches);
|
32
|
+
}
|
33
|
+
|
34
|
+
virtual void surfaceAvailable(jobject surface, int width, int height) {
|
35
|
+
_skiaView->surfaceAvailable(surface, width, height);
|
36
|
+
}
|
37
|
+
|
38
|
+
virtual void surfaceSizeChanged(int width, int height) {
|
39
|
+
_skiaView->surfaceSizeChanged(width, height);
|
40
|
+
}
|
41
|
+
|
42
|
+
virtual void surfaceDestroyed() { _skiaView->surfaceDestroyed(); }
|
43
|
+
|
44
|
+
virtual void setMode(std::string mode) { _skiaView->setMode(mode); }
|
45
|
+
|
46
|
+
virtual void setDebugMode(bool show) { _skiaView->setShowDebugInfo(show); }
|
47
|
+
|
48
|
+
virtual void registerView(int nativeId) {
|
49
|
+
getSkiaManager()->registerSkiaView(nativeId, _skiaView->getSkiaView());
|
50
|
+
}
|
51
|
+
|
52
|
+
virtual void unregisterView() {
|
53
|
+
getSkiaManager()->setSkiaView(_skiaView->getSkiaView()->getNativeId(),
|
54
|
+
nullptr);
|
55
|
+
getSkiaManager()->unregisterSkiaView(
|
56
|
+
_skiaView->getSkiaView()->getNativeId());
|
57
|
+
_skiaView->viewDidUnmount();
|
58
|
+
}
|
59
|
+
|
60
|
+
private:
|
61
|
+
JniSkiaManager *_manager;
|
62
|
+
std::shared_ptr<RNSkBaseAndroidView> _skiaView;
|
63
|
+
};
|
67
64
|
|
68
65
|
} // namespace RNSkia
|