@shopify/react-native-skia 1.5.7 → 1.5.9
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/CMakeLists.txt +1 -2
- 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/OpenGLContext.h +3 -1
- package/android/cpp/rnskia-android/OpenGLWindowContext.cpp +1 -1
- package/android/cpp/rnskia-android/OpenGLWindowContext.h +4 -5
- package/android/cpp/rnskia-android/RNSkAndroidPlatformContext.h +10 -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/api/JsiSkImage.h +20 -4
- package/cpp/rnskia/RNSkManager.cpp +2 -3
- package/cpp/rnskia/RNSkPlatformContext.h +6 -114
- package/cpp/rnskia/RNSkView.h +21 -77
- package/ios/RNSkia-iOS/MetalContext.h +2 -0
- package/ios/RNSkia-iOS/RNSkiOSPlatformContext.h +4 -10
- package/ios/RNSkia-iOS/RNSkiOSPlatformContext.mm +6 -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/react-native-skia.podspec +2 -2
- package/src/renderer/Canvas.tsx +4 -3
- package/src/renderer/__tests__/e2e/Image.spec.tsx +2 -64
- package/src/skia/__tests__/assets/oslo-mini.jpg +0 -0
- 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
|
@@ -4,7 +4,7 @@ cmake_minimum_required(VERSION 3.4.1)
|
|
|
4
4
|
set (CMAKE_VERBOSE_MAKEFILE ON)
|
|
5
5
|
set (CMAKE_CXX_STANDARD 17)
|
|
6
6
|
set(SK_GRAPHITE OFF)
|
|
7
|
-
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DSK_BUILD_FOR_ANDROID -DFOLLY_NO_CONFIG=1 -DFOLLY_HAVE_CLOCK_GETTIME=1 -DFOLLY_HAVE_MEMRCHR=1 -DFOLLY_USE_LIBCPP=1 -DFOLLY_MOBILE=1 -DON_ANDROID -DONANDROID")
|
|
7
|
+
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DSK_BUILD_FOR_ANDROID -DSK_IMAGE_READ_PIXELS_DISABLE_LEGACY_API -DFOLLY_NO_CONFIG=1 -DFOLLY_HAVE_CLOCK_GETTIME=1 -DFOLLY_HAVE_MEMRCHR=1 -DFOLLY_USE_LIBCPP=1 -DFOLLY_MOBILE=1 -DON_ANDROID -DONANDROID")
|
|
8
8
|
set (PACKAGE_NAME "rnskia")
|
|
9
9
|
set (SKIA_LIB "skia")
|
|
10
10
|
set (SKIA_SVG_LIB "svg")
|
|
@@ -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
|
+
};
|
|
@@ -129,9 +129,11 @@ public:
|
|
|
129
129
|
std::unique_ptr<WindowContext> MakeWindow(ANativeWindow *window, int width,
|
|
130
130
|
int height) {
|
|
131
131
|
return std::make_unique<OpenGLWindowContext>(
|
|
132
|
-
_directContext, _glDisplay.get(), _glContext.get(), window);
|
|
132
|
+
_directContext.get(), _glDisplay.get(), _glContext.get(), window);
|
|
133
133
|
}
|
|
134
134
|
|
|
135
|
+
GrDirectContext *getDirectContext() { return _directContext.get(); }
|
|
136
|
+
|
|
135
137
|
private:
|
|
136
138
|
EGLConfig _glConfig;
|
|
137
139
|
std::unique_ptr<gl::Display> _glDisplay;
|
|
@@ -45,7 +45,7 @@ sk_sp<SkSurface> OpenGLWindowContext::getSurface() {
|
|
|
45
45
|
sk_sp<SkColorSpace> colorSpace(nullptr);
|
|
46
46
|
SkSurfaceProps surfaceProps(0, kRGB_H_SkPixelGeometry);
|
|
47
47
|
_skSurface = SkSurfaces::WrapBackendRenderTarget(
|
|
48
|
-
_directContext
|
|
48
|
+
_directContext, backendRT, kBottomLeft_GrSurfaceOrigin,
|
|
49
49
|
kRGBA_8888_SkColorType, colorSpace, &surfaceProps);
|
|
50
50
|
}
|
|
51
51
|
return _skSurface;
|
|
@@ -33,9 +33,8 @@ namespace RNSkia {
|
|
|
33
33
|
|
|
34
34
|
class OpenGLWindowContext : public WindowContext {
|
|
35
35
|
public:
|
|
36
|
-
OpenGLWindowContext(
|
|
37
|
-
gl::
|
|
38
|
-
ANativeWindow *window)
|
|
36
|
+
OpenGLWindowContext(GrDirectContext *directContext, gl::Display *display,
|
|
37
|
+
gl::Context *glContext, ANativeWindow *window)
|
|
39
38
|
: _directContext(directContext), _display(display), _glContext(glContext),
|
|
40
39
|
_window(window) {
|
|
41
40
|
ANativeWindow_acquire(_window);
|
|
@@ -60,11 +59,11 @@ public:
|
|
|
60
59
|
void resize(int width, int height) override { _skSurface = nullptr; }
|
|
61
60
|
|
|
62
61
|
private:
|
|
63
|
-
|
|
62
|
+
GrDirectContext *_directContext;
|
|
64
63
|
gl::Display *_display;
|
|
64
|
+
gl::Context *_glContext = nullptr;
|
|
65
65
|
ANativeWindow *_window;
|
|
66
66
|
sk_sp<SkSurface> _skSurface = nullptr;
|
|
67
|
-
gl::Context *_glContext = nullptr;
|
|
68
67
|
std::unique_ptr<gl::Surface> _glSurface = nullptr;
|
|
69
68
|
};
|
|
70
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,
|
|
@@ -152,22 +149,24 @@ public:
|
|
|
152
149
|
#endif
|
|
153
150
|
}
|
|
154
151
|
|
|
152
|
+
#if !defined(SK_GRAPHITE)
|
|
153
|
+
GrDirectContext *getDirectContext() override {
|
|
154
|
+
return OpenGLContext::getInstance().getDirectContext();
|
|
155
|
+
}
|
|
156
|
+
#endif
|
|
157
|
+
|
|
155
158
|
sk_sp<SkFontMgr> createFontMgr() override {
|
|
156
159
|
return SkFontMgr_New_Android(nullptr);
|
|
157
160
|
}
|
|
158
161
|
|
|
159
162
|
void runOnMainThread(std::function<void()> task) override {
|
|
160
|
-
|
|
163
|
+
MainThreadDispatcher::getInstance().post(std::move(task));
|
|
161
164
|
}
|
|
162
165
|
|
|
163
166
|
sk_sp<SkImage> takeScreenshotFromViewTag(size_t tag) override {
|
|
164
167
|
return _jniPlatformContext->takeScreenshotFromViewTag(tag);
|
|
165
168
|
}
|
|
166
169
|
|
|
167
|
-
void startDrawLoop() override { _jniPlatformContext->startDrawLoop(); }
|
|
168
|
-
|
|
169
|
-
void stopDrawLoop() override { _jniPlatformContext->stopDrawLoop(); }
|
|
170
|
-
|
|
171
170
|
private:
|
|
172
171
|
JniPlatformContext *_jniPlatformContext;
|
|
173
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);
|
package/cpp/api/JsiSkImage.h
CHANGED
|
@@ -92,7 +92,11 @@ public:
|
|
|
92
92
|
image = DawnContext::getInstance().MakeRasterImage(image);
|
|
93
93
|
#else
|
|
94
94
|
if (image->isTextureBacked()) {
|
|
95
|
-
|
|
95
|
+
auto grContext = getContext()->getDirectContext();
|
|
96
|
+
image = image->makeRasterImage(grContext);
|
|
97
|
+
if (!image) {
|
|
98
|
+
return nullptr;
|
|
99
|
+
}
|
|
96
100
|
}
|
|
97
101
|
#endif
|
|
98
102
|
sk_sp<SkData> data;
|
|
@@ -121,6 +125,9 @@ public:
|
|
|
121
125
|
|
|
122
126
|
JSI_HOST_FUNCTION(encodeToBytes) {
|
|
123
127
|
auto data = encodeImageData(arguments, count);
|
|
128
|
+
if (!data) {
|
|
129
|
+
return jsi::Value::null();
|
|
130
|
+
}
|
|
124
131
|
|
|
125
132
|
auto arrayCtor =
|
|
126
133
|
runtime.global().getPropertyAsFunction(runtime, "Uint8Array");
|
|
@@ -141,6 +148,9 @@ public:
|
|
|
141
148
|
|
|
142
149
|
JSI_HOST_FUNCTION(encodeToBase64) {
|
|
143
150
|
auto data = encodeImageData(arguments, count);
|
|
151
|
+
if (!data) {
|
|
152
|
+
return jsi::Value::null();
|
|
153
|
+
}
|
|
144
154
|
|
|
145
155
|
auto len = Base64::Encode(data->bytes(), data->size(), nullptr);
|
|
146
156
|
auto buffer = std::string(len, 0);
|
|
@@ -182,10 +192,15 @@ public:
|
|
|
182
192
|
.asObject(runtime)
|
|
183
193
|
.getArrayBuffer(runtime);
|
|
184
194
|
auto bfrPtr = reinterpret_cast<void *>(buffer.data(runtime));
|
|
185
|
-
|
|
186
|
-
|
|
195
|
+
#if defined(SK_GRAPHITE)
|
|
196
|
+
throw std::runtime_error("Not implemented yet");
|
|
197
|
+
#else
|
|
198
|
+
auto grContext = getContext()->getDirectContext();
|
|
199
|
+
if (!getObject()->readPixels(grContext, info, bfrPtr, bytesPerRow, srcX,
|
|
200
|
+
srcY)) {
|
|
187
201
|
return jsi::Value::null();
|
|
188
202
|
}
|
|
203
|
+
#endif
|
|
189
204
|
return dest;
|
|
190
205
|
}
|
|
191
206
|
|
|
@@ -193,7 +208,8 @@ public:
|
|
|
193
208
|
#if defined(SK_GRAPHITE)
|
|
194
209
|
auto rasterImage = DawnContext::getInstance().MakeRasterImage(getObject());
|
|
195
210
|
#else
|
|
196
|
-
auto
|
|
211
|
+
auto grContext = getContext()->getDirectContext();
|
|
212
|
+
auto rasterImage = getObject()->makeRasterImage(grContext);
|
|
197
213
|
#endif
|
|
198
214
|
return jsi::Object::createFromHostObject(
|
|
199
215
|
runtime, std::make_shared<JsiSkImage>(getContext(), rasterImage));
|