@shopify/react-native-skia 1.5.8 → 1.5.9
Sign up to get free protection for your applications and to get access to all the features.
- package/android/CMakeLists.txt +0 -1
- package/android/cpp/jni/JniPlatformContext.cpp +0 -49
- package/android/cpp/jni/include/JniPlatformContext.h +1 -17
- package/android/cpp/jni/include/JniSkiaBaseView.h +0 -2
- package/android/cpp/jni/include/JniSkiaDomView.h +0 -3
- package/android/cpp/jni/include/JniSkiaManager.h +0 -2
- package/android/cpp/jni/include/JniSkiaPictureView.h +0 -3
- package/android/cpp/rnskia-android/MainThreadDispatcher.h +69 -0
- package/android/cpp/rnskia-android/RNSkAndroidPlatformContext.h +4 -11
- package/android/cpp/rnskia-android/RNSkAndroidView.h +3 -13
- package/android/cpp/rnskia-android/RNSkOpenGLCanvasProvider.cpp +0 -1
- package/android/src/main/java/com/shopify/reactnative/skia/PlatformContext.java +0 -85
- package/android/src/main/java/com/shopify/reactnative/skia/RNSkiaModule.java +1 -21
- package/android/src/main/java/com/shopify/reactnative/skia/SkiaManager.java +0 -4
- package/android/src/paper/java/com/facebook/react/viewmanagers/SkiaDomViewManagerDelegate.java +1 -4
- package/android/src/paper/java/com/facebook/react/viewmanagers/SkiaDomViewManagerInterface.java +0 -1
- package/cpp/rnskia/RNSkManager.cpp +2 -3
- package/cpp/rnskia/RNSkPlatformContext.h +2 -114
- package/cpp/rnskia/RNSkView.h +16 -75
- package/ios/RNSkia-iOS/RNSkiOSPlatformContext.h +1 -10
- package/ios/RNSkia-iOS/RNSkiOSPlatformContext.mm +0 -16
- package/ios/RNSkia-iOS/SkiaDomView.mm +0 -1
- package/ios/RNSkia-iOS/SkiaDomViewManager.mm +0 -6
- package/ios/RNSkia-iOS/SkiaPictureView.mm +0 -1
- package/ios/RNSkia-iOS/SkiaPictureViewManager.mm +0 -6
- package/ios/RNSkia-iOS/SkiaUIView.h +0 -1
- package/ios/RNSkia-iOS/SkiaUIView.mm +1 -14
- package/lib/commonjs/renderer/Canvas.d.ts +1 -0
- package/lib/commonjs/renderer/Canvas.js +5 -5
- package/lib/commonjs/renderer/Canvas.js.map +1 -1
- package/lib/commonjs/specs/SkiaPictureViewNativeComponent.d.ts +0 -1
- package/lib/commonjs/specs/SkiaPictureViewNativeComponent.js.map +1 -1
- package/lib/commonjs/views/SkiaBaseWebView.d.ts +1 -12
- package/lib/commonjs/views/SkiaBaseWebView.js +1 -19
- package/lib/commonjs/views/SkiaBaseWebView.js.map +1 -1
- package/lib/commonjs/views/SkiaDomView.d.ts +8 -1
- package/lib/commonjs/views/SkiaDomView.js +14 -2
- package/lib/commonjs/views/SkiaDomView.js.map +1 -1
- package/lib/commonjs/views/SkiaDomView.web.d.ts +3 -3
- package/lib/commonjs/views/SkiaDomView.web.js.map +1 -1
- package/lib/commonjs/views/SkiaJSDomView.d.ts +12 -6
- package/lib/commonjs/views/SkiaJSDomView.js +12 -3
- package/lib/commonjs/views/SkiaJSDomView.js.map +1 -1
- package/lib/commonjs/views/SkiaPictureView.d.ts +8 -1
- package/lib/commonjs/views/SkiaPictureView.js +14 -1
- package/lib/commonjs/views/SkiaPictureView.js.map +1 -1
- package/lib/commonjs/views/SkiaPictureView.web.d.ts +3 -3
- package/lib/commonjs/views/SkiaPictureView.web.js.map +1 -1
- package/lib/commonjs/views/types.d.ts +2 -12
- package/lib/commonjs/views/types.js.map +1 -1
- package/lib/module/renderer/Canvas.d.ts +1 -0
- package/lib/module/renderer/Canvas.js +5 -5
- package/lib/module/renderer/Canvas.js.map +1 -1
- package/lib/module/specs/SkiaPictureViewNativeComponent.d.ts +0 -1
- package/lib/module/specs/SkiaPictureViewNativeComponent.js.map +1 -1
- package/lib/module/views/SkiaBaseWebView.d.ts +1 -12
- package/lib/module/views/SkiaBaseWebView.js +1 -19
- package/lib/module/views/SkiaBaseWebView.js.map +1 -1
- package/lib/module/views/SkiaDomView.d.ts +8 -1
- package/lib/module/views/SkiaDomView.js +14 -2
- package/lib/module/views/SkiaDomView.js.map +1 -1
- package/lib/module/views/SkiaDomView.web.d.ts +3 -3
- package/lib/module/views/SkiaDomView.web.js.map +1 -1
- package/lib/module/views/SkiaJSDomView.d.ts +12 -6
- package/lib/module/views/SkiaJSDomView.js +12 -3
- package/lib/module/views/SkiaJSDomView.js.map +1 -1
- package/lib/module/views/SkiaPictureView.d.ts +8 -1
- package/lib/module/views/SkiaPictureView.js +14 -1
- package/lib/module/views/SkiaPictureView.js.map +1 -1
- package/lib/module/views/SkiaPictureView.web.d.ts +3 -3
- package/lib/module/views/SkiaPictureView.web.js.map +1 -1
- package/lib/module/views/types.d.ts +2 -12
- package/lib/module/views/types.js.map +1 -1
- package/lib/typescript/lib/commonjs/views/SkiaBaseWebView.d.ts +0 -11
- package/lib/typescript/lib/commonjs/views/SkiaDomView.d.ts +3 -0
- package/lib/typescript/lib/commonjs/views/SkiaJSDomView.d.ts +2 -0
- package/lib/typescript/lib/commonjs/views/SkiaPictureView.d.ts +3 -0
- package/lib/typescript/lib/module/views/SkiaBaseWebView.d.ts +0 -11
- package/lib/typescript/lib/module/views/SkiaDomView.d.ts +3 -0
- package/lib/typescript/lib/module/views/SkiaJSDomView.d.ts +2 -0
- package/lib/typescript/lib/module/views/SkiaPictureView.d.ts +3 -0
- package/lib/typescript/src/renderer/Canvas.d.ts +1 -0
- package/lib/typescript/src/specs/SkiaPictureViewNativeComponent.d.ts +0 -1
- package/lib/typescript/src/views/SkiaBaseWebView.d.ts +1 -12
- package/lib/typescript/src/views/SkiaDomView.d.ts +8 -1
- package/lib/typescript/src/views/SkiaDomView.web.d.ts +3 -3
- package/lib/typescript/src/views/SkiaJSDomView.d.ts +12 -6
- package/lib/typescript/src/views/SkiaPictureView.d.ts +8 -1
- package/lib/typescript/src/views/SkiaPictureView.web.d.ts +3 -3
- package/lib/typescript/src/views/types.d.ts +2 -12
- package/package.json +1 -1
- package/src/renderer/Canvas.tsx +4 -3
- package/src/specs/SkiaPictureViewNativeComponent.ts +0 -1
- package/src/views/SkiaBaseWebView.tsx +3 -19
- package/src/views/SkiaDomView.tsx +23 -4
- package/src/views/SkiaDomView.web.tsx +3 -3
- package/src/views/SkiaJSDomView.tsx +30 -9
- package/src/views/SkiaPictureView.tsx +22 -2
- package/src/views/SkiaPictureView.web.tsx +3 -3
- package/src/views/types.ts +2 -13
- package/cpp/rnskia/RNSkDispatchQueue.cpp +0 -73
- package/cpp/rnskia/RNSkDispatchQueue.h +0 -49
- package/ios/RNSkia-iOS/DisplayLink.h +0 -17
- package/ios/RNSkia-iOS/DisplayLink.mm +0 -41
package/android/CMakeLists.txt
CHANGED
@@ -87,7 +87,6 @@ add_library(
|
|
87
87
|
|
88
88
|
"${PROJECT_SOURCE_DIR}/../cpp/rnskia/RNSkManager.cpp"
|
89
89
|
"${PROJECT_SOURCE_DIR}/../cpp/rnskia/RNSkDomView.cpp"
|
90
|
-
"${PROJECT_SOURCE_DIR}/../cpp/rnskia/RNSkDispatchQueue.cpp"
|
91
90
|
|
92
91
|
"${PROJECT_SOURCE_DIR}/../cpp/rnskia/dom/base/DrawingContext.cpp"
|
93
92
|
"${PROJECT_SOURCE_DIR}/../cpp/rnskia/dom/base/ConcatablePaint.cpp"
|
@@ -63,10 +63,6 @@ using TSelf = jni::local_ref<JniPlatformContext::jhybriddata>;
|
|
63
63
|
void JniPlatformContext::registerNatives() {
|
64
64
|
registerHybrid({
|
65
65
|
makeNativeMethod("initHybrid", JniPlatformContext::initHybrid),
|
66
|
-
makeNativeMethod("notifyDrawLoop",
|
67
|
-
JniPlatformContext::notifyDrawLoopExternal),
|
68
|
-
makeNativeMethod("notifyTaskReady",
|
69
|
-
JniPlatformContext::notifyTaskReadyExternal),
|
70
66
|
});
|
71
67
|
}
|
72
68
|
|
@@ -134,51 +130,6 @@ sk_sp<SkImage> JniPlatformContext::takeScreenshotFromViewTag(size_t tag) {
|
|
134
130
|
return skImage;
|
135
131
|
}
|
136
132
|
|
137
|
-
void JniPlatformContext::startDrawLoop() {
|
138
|
-
jni::ThreadScope ts;
|
139
|
-
// Start drawing loop
|
140
|
-
static auto method =
|
141
|
-
javaPart_->getClass()->getMethod<void(void)>("beginDrawLoop");
|
142
|
-
method(javaPart_.get());
|
143
|
-
}
|
144
|
-
|
145
|
-
void JniPlatformContext::stopDrawLoop() {
|
146
|
-
jni::ThreadScope ts;
|
147
|
-
// Stop drawing loop
|
148
|
-
static auto method =
|
149
|
-
javaPart_->getClass()->getMethod<void(void)>("endDrawLoop");
|
150
|
-
method(javaPart_.get());
|
151
|
-
}
|
152
|
-
|
153
|
-
void JniPlatformContext::notifyDrawLoopExternal() {
|
154
|
-
jni::ThreadScope ts;
|
155
|
-
_onNotifyDrawLoop();
|
156
|
-
}
|
157
|
-
|
158
|
-
void JniPlatformContext::runTaskOnMainThread(std::function<void()> task) {
|
159
|
-
_taskMutex->lock();
|
160
|
-
_taskCallbacks.push(task);
|
161
|
-
_taskMutex->unlock();
|
162
|
-
|
163
|
-
// Notify Java that task is ready
|
164
|
-
static auto method = javaPart_->getClass()->getMethod<void(void)>(
|
165
|
-
"notifyTaskReadyOnMainThread");
|
166
|
-
method(javaPart_.get());
|
167
|
-
}
|
168
|
-
|
169
|
-
void JniPlatformContext::notifyTaskReadyExternal() {
|
170
|
-
jni::ThreadScope ts;
|
171
|
-
_taskMutex->lock();
|
172
|
-
auto task = _taskCallbacks.front();
|
173
|
-
if (task != nullptr) {
|
174
|
-
_taskCallbacks.pop();
|
175
|
-
_taskMutex->unlock();
|
176
|
-
task();
|
177
|
-
} else {
|
178
|
-
_taskMutex->unlock();
|
179
|
-
}
|
180
|
-
}
|
181
|
-
|
182
133
|
void JniPlatformContext::performStreamOperation(
|
183
134
|
const std::string &sourceUri,
|
184
135
|
const std::function<void(std::unique_ptr<SkStreamAsset>)> &op) {
|
@@ -33,11 +33,6 @@ public:
|
|
33
33
|
|
34
34
|
void raiseError(const std::exception &err);
|
35
35
|
|
36
|
-
void startDrawLoop();
|
37
|
-
void stopDrawLoop();
|
38
|
-
|
39
|
-
void notifyDrawLoopExternal();
|
40
|
-
|
41
36
|
void notifyTaskReadyExternal();
|
42
37
|
|
43
38
|
void runTaskOnMainThread(std::function<void()> task);
|
@@ -46,10 +41,6 @@ public:
|
|
46
41
|
|
47
42
|
sk_sp<SkImage> takeScreenshotFromViewTag(size_t tag);
|
48
43
|
|
49
|
-
void setOnNotifyDrawLoop(const std::function<void(void)> &callback) {
|
50
|
-
_onNotifyDrawLoop = callback;
|
51
|
-
}
|
52
|
-
|
53
44
|
jni::global_ref<jobject> createVideo(const std::string &url);
|
54
45
|
|
55
46
|
private:
|
@@ -58,16 +49,9 @@ private:
|
|
58
49
|
|
59
50
|
float _pixelDensity;
|
60
51
|
|
61
|
-
std::function<void(void)> _onNotifyDrawLoop;
|
62
|
-
|
63
|
-
std::queue<std::function<void()>> _taskCallbacks;
|
64
|
-
|
65
|
-
std::shared_ptr<std::mutex> _taskMutex;
|
66
|
-
|
67
52
|
explicit JniPlatformContext(
|
68
53
|
jni::alias_ref<JniPlatformContext::jhybridobject> jThis,
|
69
54
|
const float pixelDensity)
|
70
|
-
:
|
71
|
-
javaPart_(jni::make_global(jThis)), _pixelDensity(pixelDensity) {}
|
55
|
+
: javaPart_(jni::make_global(jThis)), _pixelDensity(pixelDensity) {}
|
72
56
|
};
|
73
57
|
} // namespace RNSkia
|
@@ -39,8 +39,6 @@ protected:
|
|
39
39
|
|
40
40
|
virtual void surfaceDestroyed() { _skiaAndroidView->surfaceDestroyed(); }
|
41
41
|
|
42
|
-
virtual void setMode(std::string mode) { _skiaAndroidView->setMode(mode); }
|
43
|
-
|
44
42
|
virtual void setDebugMode(bool show) {
|
45
43
|
_skiaAndroidView->setShowDebugInfo(show);
|
46
44
|
}
|
@@ -40,7 +40,6 @@ public:
|
|
40
40
|
makeNativeMethod("surfaceDestroyed", JniSkiaDomView::surfaceDestroyed),
|
41
41
|
makeNativeMethod("surfaceSizeChanged",
|
42
42
|
JniSkiaDomView::surfaceSizeChanged),
|
43
|
-
makeNativeMethod("setMode", JniSkiaDomView::setMode),
|
44
43
|
makeNativeMethod("setDebugMode", JniSkiaDomView::setDebugMode),
|
45
44
|
makeNativeMethod("registerView", JniSkiaDomView::registerView),
|
46
45
|
makeNativeMethod("unregisterView", JniSkiaDomView::unregisterView)});
|
@@ -57,8 +56,6 @@ protected:
|
|
57
56
|
|
58
57
|
void surfaceDestroyed() override { JniSkiaBaseView::surfaceDestroyed(); }
|
59
58
|
|
60
|
-
void setMode(std::string mode) override { JniSkiaBaseView::setMode(mode); }
|
61
|
-
|
62
59
|
void setDebugMode(bool show) override { JniSkiaBaseView::setDebugMode(show); }
|
63
60
|
|
64
61
|
void registerView(int nativeId) override {
|
@@ -41,7 +41,6 @@ public:
|
|
41
41
|
JniSkiaPictureView::surfaceDestroyed),
|
42
42
|
makeNativeMethod("surfaceSizeChanged",
|
43
43
|
JniSkiaPictureView::surfaceSizeChanged),
|
44
|
-
makeNativeMethod("setMode", JniSkiaPictureView::setMode),
|
45
44
|
makeNativeMethod("setDebugMode", JniSkiaPictureView::setDebugMode),
|
46
45
|
makeNativeMethod("registerView", JniSkiaPictureView::registerView),
|
47
46
|
makeNativeMethod("unregisterView",
|
@@ -59,8 +58,6 @@ protected:
|
|
59
58
|
|
60
59
|
void surfaceDestroyed() override { JniSkiaBaseView::surfaceDestroyed(); }
|
61
60
|
|
62
|
-
void setMode(std::string mode) override { JniSkiaBaseView::setMode(mode); }
|
63
|
-
|
64
61
|
void setDebugMode(bool show) override { JniSkiaBaseView::setDebugMode(show); }
|
65
62
|
|
66
63
|
void registerView(int nativeId) override {
|
@@ -0,0 +1,69 @@
|
|
1
|
+
#pragma once
|
2
|
+
|
3
|
+
#include <android/looper.h>
|
4
|
+
#include <unistd.h>
|
5
|
+
|
6
|
+
class MainThreadDispatcher {
|
7
|
+
private:
|
8
|
+
ALooper *mainLooper;
|
9
|
+
int messagePipe[2];
|
10
|
+
std::queue<std::function<void()>> taskQueue;
|
11
|
+
std::mutex queueMutex;
|
12
|
+
|
13
|
+
static constexpr int LOOPER_ID_MAIN = 1;
|
14
|
+
|
15
|
+
void processMessages() {
|
16
|
+
std::lock_guard<std::mutex> lock(queueMutex);
|
17
|
+
while (!taskQueue.empty()) {
|
18
|
+
auto task = taskQueue.front();
|
19
|
+
taskQueue.pop();
|
20
|
+
task();
|
21
|
+
}
|
22
|
+
}
|
23
|
+
|
24
|
+
public:
|
25
|
+
static MainThreadDispatcher &getInstance() {
|
26
|
+
static MainThreadDispatcher instance;
|
27
|
+
return instance;
|
28
|
+
}
|
29
|
+
|
30
|
+
void post(std::function<void()> task) {
|
31
|
+
// TODO: this is disabled for now but we can clean this up
|
32
|
+
// if (ALooper_forThread() == mainLooper) {
|
33
|
+
// task();
|
34
|
+
// } else {
|
35
|
+
{
|
36
|
+
std::lock_guard<std::mutex> lock(queueMutex);
|
37
|
+
taskQueue.push(std::move(task));
|
38
|
+
}
|
39
|
+
char wake = 1;
|
40
|
+
write(messagePipe[1], &wake, 1);
|
41
|
+
// }
|
42
|
+
}
|
43
|
+
|
44
|
+
~MainThreadDispatcher() {
|
45
|
+
close(messagePipe[0]);
|
46
|
+
close(messagePipe[1]);
|
47
|
+
}
|
48
|
+
|
49
|
+
private:
|
50
|
+
MainThreadDispatcher() {
|
51
|
+
mainLooper = ALooper_forThread();
|
52
|
+
if (!mainLooper) {
|
53
|
+
mainLooper = ALooper_prepare(ALOOPER_PREPARE_ALLOW_NON_CALLBACKS);
|
54
|
+
}
|
55
|
+
|
56
|
+
pipe(messagePipe);
|
57
|
+
|
58
|
+
ALooper_addFd(
|
59
|
+
mainLooper, messagePipe[0], LOOPER_ID_MAIN, ALOOPER_EVENT_INPUT,
|
60
|
+
[](int fd, int events, void *data) -> int {
|
61
|
+
char buf[1];
|
62
|
+
read(fd, buf, 1);
|
63
|
+
auto dispatcher = static_cast<MainThreadDispatcher *>(data);
|
64
|
+
dispatcher->processMessages();
|
65
|
+
return 1;
|
66
|
+
},
|
67
|
+
this);
|
68
|
+
}
|
69
|
+
};
|
@@ -17,6 +17,7 @@
|
|
17
17
|
|
18
18
|
#include "AHardwareBufferUtils.h"
|
19
19
|
#include "JniPlatformContext.h"
|
20
|
+
#include "MainThreadDispatcher.h"
|
20
21
|
#include "RNSkAndroidVideo.h"
|
21
22
|
#include "RNSkPlatformContext.h"
|
22
23
|
|
@@ -37,13 +38,9 @@ public:
|
|
37
38
|
std::shared_ptr<facebook::react::CallInvoker> jsCallInvoker)
|
38
39
|
: RNSkPlatformContext(runtime, jsCallInvoker,
|
39
40
|
jniPlatformContext->getPixelDensity()),
|
40
|
-
_jniPlatformContext(jniPlatformContext) {
|
41
|
-
// Hook onto the notify draw loop callback in the platform context
|
42
|
-
jniPlatformContext->setOnNotifyDrawLoop(
|
43
|
-
[this]() { notifyDrawLoop(false); });
|
44
|
-
}
|
41
|
+
_jniPlatformContext(jniPlatformContext) {}
|
45
42
|
|
46
|
-
~RNSkAndroidPlatformContext() {
|
43
|
+
~RNSkAndroidPlatformContext() {}
|
47
44
|
|
48
45
|
void performStreamOperation(
|
49
46
|
const std::string &sourceUri,
|
@@ -163,17 +160,13 @@ public:
|
|
163
160
|
}
|
164
161
|
|
165
162
|
void runOnMainThread(std::function<void()> task) override {
|
166
|
-
|
163
|
+
MainThreadDispatcher::getInstance().post(std::move(task));
|
167
164
|
}
|
168
165
|
|
169
166
|
sk_sp<SkImage> takeScreenshotFromViewTag(size_t tag) override {
|
170
167
|
return _jniPlatformContext->takeScreenshotFromViewTag(tag);
|
171
168
|
}
|
172
169
|
|
173
|
-
void startDrawLoop() override { _jniPlatformContext->startDrawLoop(); }
|
174
|
-
|
175
|
-
void stopDrawLoop() override { _jniPlatformContext->stopDrawLoop(); }
|
176
|
-
|
177
170
|
private:
|
178
171
|
JniPlatformContext *_jniPlatformContext;
|
179
172
|
};
|
@@ -19,8 +19,6 @@ public:
|
|
19
19
|
|
20
20
|
virtual float getPixelDensity() = 0;
|
21
21
|
|
22
|
-
virtual void setMode(std::string mode) = 0;
|
23
|
-
|
24
22
|
virtual void setShowDebugInfo(bool show) = 0;
|
25
23
|
|
26
24
|
virtual void viewDidUnmount() = 0;
|
@@ -42,7 +40,7 @@ public:
|
|
42
40
|
|
43
41
|
// Try to render directly when the surface has been set so that
|
44
42
|
// we don't have to wait until the draw loop returns.
|
45
|
-
RNSkView::
|
43
|
+
RNSkView::redraw();
|
46
44
|
}
|
47
45
|
|
48
46
|
void surfaceDestroyed() override {
|
@@ -55,24 +53,16 @@ public:
|
|
55
53
|
->surfaceSizeChanged(surface, width, height);
|
56
54
|
// This is only need for the first time to frame, this renderImmediate call
|
57
55
|
// will invoke updateTexImage for the previous frame
|
58
|
-
RNSkView::
|
56
|
+
RNSkView::redraw();
|
59
57
|
}
|
60
58
|
|
61
59
|
float getPixelDensity() override {
|
62
60
|
return T::getPlatformContext()->getPixelDensity();
|
63
61
|
}
|
64
62
|
|
65
|
-
void setMode(std::string mode) override {
|
66
|
-
if (mode.compare("continuous") == 0) {
|
67
|
-
T::setDrawingMode(RNSkDrawingMode::Continuous);
|
68
|
-
} else {
|
69
|
-
T::setDrawingMode(RNSkDrawingMode::Default);
|
70
|
-
}
|
71
|
-
}
|
72
|
-
|
73
63
|
void setShowDebugInfo(bool show) override { T::setShowDebugOverlays(show); }
|
74
64
|
|
75
|
-
void viewDidUnmount() override {
|
65
|
+
void viewDidUnmount() override {}
|
76
66
|
|
77
67
|
std::shared_ptr<RNSkView> getSkiaView() override {
|
78
68
|
return T::shared_from_this();
|
@@ -25,14 +25,8 @@ public class PlatformContext {
|
|
25
25
|
|
26
26
|
private final ReactContext mContext;
|
27
27
|
|
28
|
-
private boolean _drawLoopActive = false;
|
29
|
-
private boolean _isPaused = false;
|
30
|
-
|
31
28
|
private final String TAG = "PlatformContext";
|
32
29
|
|
33
|
-
private final Handler mainHandler = new Handler(Looper.getMainLooper());
|
34
|
-
|
35
|
-
|
36
30
|
public PlatformContext(ReactContext reactContext) {
|
37
31
|
mContext = reactContext;
|
38
32
|
mHybridData = initHybrid(reactContext.getResources().getDisplayMetrics().density);
|
@@ -53,69 +47,11 @@ public class PlatformContext {
|
|
53
47
|
return buffer.toByteArray();
|
54
48
|
}
|
55
49
|
|
56
|
-
private void postFrameLoop() {
|
57
|
-
Choreographer.FrameCallback frameCallback = new Choreographer.FrameCallback() {
|
58
|
-
@Override
|
59
|
-
public void doFrame(long frameTimeNanos) {
|
60
|
-
if (_drawLoopActive) {
|
61
|
-
Choreographer.getInstance().postFrameCallback(this);
|
62
|
-
}
|
63
|
-
if (_isPaused) {
|
64
|
-
return;
|
65
|
-
}
|
66
|
-
notifyDrawLoop();
|
67
|
-
}
|
68
|
-
};
|
69
|
-
Choreographer.getInstance().postFrameCallback(frameCallback);
|
70
|
-
}
|
71
|
-
|
72
|
-
|
73
|
-
@DoNotStrip
|
74
|
-
public void notifyTaskReadyOnMainThread() {
|
75
|
-
mainHandler.post(new Runnable() {
|
76
|
-
@Override
|
77
|
-
public void run() {
|
78
|
-
notifyTaskReady();
|
79
|
-
}
|
80
|
-
});
|
81
|
-
}
|
82
|
-
|
83
50
|
@DoNotStrip
|
84
51
|
Object takeScreenshotFromViewTag(int tag) {
|
85
52
|
return ViewScreenshotService.makeViewScreenshotFromTag(mContext, tag);
|
86
53
|
}
|
87
54
|
|
88
|
-
@DoNotStrip
|
89
|
-
public void raise(final String message) {
|
90
|
-
mainHandler.post(new Runnable() {
|
91
|
-
@Override
|
92
|
-
public void run() {
|
93
|
-
mContext.handleException(new Exception(message));
|
94
|
-
}
|
95
|
-
});
|
96
|
-
}
|
97
|
-
|
98
|
-
@DoNotStrip
|
99
|
-
public void beginDrawLoop() {
|
100
|
-
if (_drawLoopActive) {
|
101
|
-
return;
|
102
|
-
}
|
103
|
-
_drawLoopActive = true;
|
104
|
-
mainHandler.post(new Runnable() {
|
105
|
-
@Override
|
106
|
-
public void run() {
|
107
|
-
postFrameLoop();
|
108
|
-
}
|
109
|
-
});
|
110
|
-
}
|
111
|
-
|
112
|
-
@DoNotStrip
|
113
|
-
public void endDrawLoop() {
|
114
|
-
if (_drawLoopActive) {
|
115
|
-
_drawLoopActive = false;
|
116
|
-
}
|
117
|
-
}
|
118
|
-
|
119
55
|
@DoNotStrip
|
120
56
|
public byte[] getJniStreamFromSource(String sourceUri) throws IOException {
|
121
57
|
// First try loading the input as a resource directly
|
@@ -163,25 +99,6 @@ public class PlatformContext {
|
|
163
99
|
return null;
|
164
100
|
}
|
165
101
|
|
166
|
-
void onPause() {
|
167
|
-
Log.i(TAG, "Paused");
|
168
|
-
_isPaused = true;
|
169
|
-
}
|
170
|
-
|
171
|
-
void onResume() {
|
172
|
-
_isPaused = false;
|
173
|
-
Log.i(TAG, "Resume");
|
174
|
-
if(_drawLoopActive) {
|
175
|
-
// Restart draw loop
|
176
|
-
mainHandler.post(new Runnable() {
|
177
|
-
@Override
|
178
|
-
public void run() {
|
179
|
-
postFrameLoop();
|
180
|
-
}
|
181
|
-
});
|
182
|
-
}
|
183
|
-
}
|
184
|
-
|
185
102
|
@Override
|
186
103
|
protected void finalize() throws Throwable {
|
187
104
|
mHybridData.resetNative();
|
@@ -190,6 +107,4 @@ public class PlatformContext {
|
|
190
107
|
|
191
108
|
// Private c++ native methods
|
192
109
|
private native HybridData initHybrid(float pixelDensity);
|
193
|
-
private native void notifyDrawLoop();
|
194
|
-
private native void notifyTaskReady();
|
195
110
|
}
|
@@ -12,7 +12,7 @@ import com.facebook.react.module.annotations.ReactModule;
|
|
12
12
|
import java.lang.ref.WeakReference;
|
13
13
|
|
14
14
|
@ReactModule(name="RNSkiaModule")
|
15
|
-
public class RNSkiaModule extends NativeSkiaModuleSpec
|
15
|
+
public class RNSkiaModule extends NativeSkiaModuleSpec {
|
16
16
|
public static final String NAME = "RNSkiaModule";
|
17
17
|
|
18
18
|
private final WeakReference<ReactApplicationContext> weakReactContext;
|
@@ -21,17 +21,12 @@ public class RNSkiaModule extends NativeSkiaModuleSpec implements LifecycleEvent
|
|
21
21
|
public RNSkiaModule(ReactApplicationContext reactContext) {
|
22
22
|
super(reactContext);
|
23
23
|
this.weakReactContext = new WeakReference<>(reactContext);
|
24
|
-
reactContext.addLifecycleEventListener(this);
|
25
24
|
}
|
26
25
|
|
27
26
|
@Override
|
28
27
|
public void invalidate() {
|
29
28
|
super.invalidate();
|
30
29
|
|
31
|
-
if (getReactApplicationContext() != null) {
|
32
|
-
getReactApplicationContext().removeLifecycleEventListener(this);
|
33
|
-
}
|
34
|
-
|
35
30
|
if (this.skiaManager != null) {
|
36
31
|
this.skiaManager.invalidate();
|
37
32
|
this.skiaManager.destroy();
|
@@ -69,19 +64,4 @@ public class RNSkiaModule extends NativeSkiaModuleSpec implements LifecycleEvent
|
|
69
64
|
return false;
|
70
65
|
}
|
71
66
|
}
|
72
|
-
|
73
|
-
@Override
|
74
|
-
public void onHostResume() {
|
75
|
-
if(skiaManager != null) skiaManager.onHostResume();
|
76
|
-
}
|
77
|
-
|
78
|
-
@Override
|
79
|
-
public void onHostPause() {
|
80
|
-
if(skiaManager != null) skiaManager.onHostPause();
|
81
|
-
}
|
82
|
-
|
83
|
-
@Override
|
84
|
-
public void onHostDestroy() {
|
85
|
-
|
86
|
-
}
|
87
67
|
}
|
@@ -43,10 +43,6 @@ public class SkiaManager {
|
|
43
43
|
return mPlatformContext;
|
44
44
|
}
|
45
45
|
|
46
|
-
public void onHostResume() { mPlatformContext.onResume(); }
|
47
|
-
|
48
|
-
public void onHostPause() { mPlatformContext.onPause(); }
|
49
|
-
|
50
46
|
// private C++ functions
|
51
47
|
private native HybridData initHybrid(long jsContext, RuntimeExecutor runtimeExecutor,
|
52
48
|
PlatformContext platformContext);
|
package/android/src/paper/java/com/facebook/react/viewmanagers/SkiaDomViewManagerDelegate.java
CHANGED
@@ -21,11 +21,8 @@ public class SkiaDomViewManagerDelegate<T extends View, U extends BaseViewManage
|
|
21
21
|
@Override
|
22
22
|
public void setProperty(T view, String propName, @Nullable Object value) {
|
23
23
|
switch (propName) {
|
24
|
-
case "mode":
|
25
|
-
mViewManager.setMode(view, value == null ? null : (String) value);
|
26
|
-
break;
|
27
24
|
case "debug":
|
28
|
-
mViewManager.setDebug(view, value
|
25
|
+
mViewManager.setDebug(view, value != null && (boolean) value);
|
29
26
|
break;
|
30
27
|
default:
|
31
28
|
super.setProperty(view, propName, value);
|
@@ -47,13 +47,12 @@ void RNSkManager::invalidate() {
|
|
47
47
|
|
48
48
|
// Invalidate members
|
49
49
|
_viewApi->unregisterAll();
|
50
|
-
_platformContext->invalidate();
|
51
50
|
}
|
52
51
|
|
53
52
|
void RNSkManager::registerSkiaView(size_t nativeId,
|
54
53
|
std::shared_ptr<RNSkView> view) {
|
55
54
|
if (!_isInvalidated && _viewApi != nullptr)
|
56
|
-
_viewApi->registerSkiaView(nativeId, view);
|
55
|
+
_viewApi->registerSkiaView(nativeId, std::move(view));
|
57
56
|
}
|
58
57
|
|
59
58
|
void RNSkManager::unregisterSkiaView(size_t nativeId) {
|
@@ -63,7 +62,7 @@ void RNSkManager::unregisterSkiaView(size_t nativeId) {
|
|
63
62
|
|
64
63
|
void RNSkManager::setSkiaView(size_t nativeId, std::shared_ptr<RNSkView> view) {
|
65
64
|
if (!_isInvalidated && _viewApi != nullptr)
|
66
|
-
_viewApi->setSkiaView(nativeId, view);
|
65
|
+
_viewApi->setSkiaView(nativeId, std::move(view));
|
67
66
|
}
|
68
67
|
|
69
68
|
void RNSkManager::installBindings() {
|