@shopify/react-native-skia 0.1.122 → 0.1.123
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 +3 -1
- package/android/cpp/jni/JniSkiaDrawView.cpp +14 -71
- package/android/cpp/jni/JniSkiaManager.cpp +1 -1
- package/android/cpp/jni/include/JniSkiaDrawView.h +18 -22
- package/android/cpp/jni/include/JniSkiaManager.h +4 -4
- package/android/cpp/rnskia-android/RNSkDrawViewImpl.cpp +68 -0
- package/android/cpp/rnskia-android/RNSkDrawViewImpl.h +48 -0
- package/android/cpp/{jni/include/JniPlatformContextWrapper.h → rnskia-android/RNSkPlatformContextImpl.h} +4 -4
- package/android/cpp/{jni → rnskia-android}/SkiaOpenGLRenderer.cpp +39 -54
- package/android/cpp/{jni/include → rnskia-android}/SkiaOpenGLRenderer.h +2 -31
- package/android/src/main/java/com/shopify/reactnative/skia/RNSkiaViewManager.java +1 -1
- package/android/src/main/java/com/shopify/reactnative/skia/SkiaDrawView.java +21 -28
- package/cpp/rnskia/RNSkDrawView.cpp +77 -116
- package/cpp/rnskia/RNSkDrawView.h +5 -35
- package/cpp/rnskia/RNSkJsiViewApi.h +8 -5
- package/cpp/rnskia/RNSkManager.cpp +2 -2
- package/cpp/rnskia/RNSkManager.h +2 -2
- package/cpp/rnskia/RNSkPlatformContext.h +1 -1
- package/cpp/rnskia/values/RNSkClockValue.h +16 -8
- package/cpp/rnskia/values/RNSkReadonlyValue.h +11 -5
- package/cpp/utils/RNSkTimingInfo.h +13 -1
- package/ios/RNSkia-iOS/RNSkDrawViewImpl.h +5 -7
- package/ios/RNSkia-iOS/RNSkDrawViewImpl.mm +25 -10
- package/ios/RNSkia-iOS/SkiaDrawView.mm +21 -15
- package/lib/commonjs/renderer/Canvas.js +3 -3
- package/lib/commonjs/renderer/Canvas.js.map +1 -1
- package/lib/commonjs/renderer/components/Paint.js +1 -1
- package/lib/commonjs/renderer/components/Paint.js.map +1 -1
- package/lib/commonjs/renderer/components/shapes/Path.js +9 -1
- package/lib/commonjs/renderer/components/shapes/Path.js.map +1 -1
- package/lib/commonjs/renderer/processors/Paint.js +6 -1
- package/lib/commonjs/renderer/processors/Paint.js.map +1 -1
- package/lib/commonjs/skia/Paint/Paint.js +13 -1
- package/lib/commonjs/skia/Paint/Paint.js.map +1 -1
- package/lib/commonjs/skia/Paint/usePaint.js +2 -4
- package/lib/commonjs/skia/Paint/usePaint.js.map +1 -1
- package/lib/commonjs/skia/Skia.js +3 -1
- package/lib/commonjs/skia/Skia.js.map +1 -1
- package/lib/module/renderer/Canvas.js +2 -2
- package/lib/module/renderer/Canvas.js.map +1 -1
- package/lib/module/renderer/components/Paint.js +2 -2
- package/lib/module/renderer/components/Paint.js.map +1 -1
- package/lib/module/renderer/components/shapes/Path.js +9 -2
- package/lib/module/renderer/components/shapes/Path.js.map +1 -1
- package/lib/module/renderer/processors/Paint.js +6 -1
- package/lib/module/renderer/processors/Paint.js.map +1 -1
- package/lib/module/skia/Paint/Paint.js +6 -0
- package/lib/module/skia/Paint/Paint.js.map +1 -1
- package/lib/module/skia/Paint/usePaint.js +2 -3
- package/lib/module/skia/Paint/usePaint.js.map +1 -1
- package/lib/module/skia/Skia.js +3 -1
- package/lib/module/skia/Skia.js.map +1 -1
- package/lib/typescript/src/renderer/components/shapes/Path.d.ts +3 -1
- package/lib/typescript/src/renderer/processors/Paint.d.ts +2 -1
- package/lib/typescript/src/skia/Paint/Paint.d.ts +1 -0
- package/package.json +1 -1
- package/src/renderer/Canvas.tsx +2 -2
- package/src/renderer/components/Paint.tsx +2 -2
- package/src/renderer/components/shapes/Path.tsx +11 -3
- package/src/renderer/processors/Paint.ts +5 -0
- package/src/skia/Paint/Paint.ts +7 -0
- package/src/skia/Paint/usePaint.ts +2 -4
- package/src/skia/Skia.ts +4 -1
package/android/CMakeLists.txt
CHANGED
@@ -31,7 +31,8 @@ add_library(
|
|
31
31
|
"${PROJECT_SOURCE_DIR}/cpp/jni/JniSkiaManager.cpp"
|
32
32
|
"${PROJECT_SOURCE_DIR}/cpp/jni/JniSkiaDrawView.cpp"
|
33
33
|
"${PROJECT_SOURCE_DIR}/cpp/jni/JniPlatformContext.cpp"
|
34
|
-
"${PROJECT_SOURCE_DIR}/cpp/
|
34
|
+
"${PROJECT_SOURCE_DIR}/cpp/rnskia-android/RNSkDrawViewImpl.cpp"
|
35
|
+
"${PROJECT_SOURCE_DIR}/cpp/rnskia-android/SkiaOpenGLRenderer.cpp"
|
35
36
|
|
36
37
|
"${PROJECT_SOURCE_DIR}/cpp/jsi/JsiHostObject.cpp"
|
37
38
|
|
@@ -64,6 +65,7 @@ target_include_directories(
|
|
64
65
|
cpp/api
|
65
66
|
cpp/jsi
|
66
67
|
cpp/jni/include
|
68
|
+
cpp/rnskia-android
|
67
69
|
cpp/rnskia
|
68
70
|
cpp/rnskia/values
|
69
71
|
cpp/utils
|
@@ -31,16 +31,13 @@ namespace RNSkia
|
|
31
31
|
/**** DTOR ***/
|
32
32
|
JniSkiaDrawView::~JniSkiaDrawView()
|
33
33
|
{
|
34
|
-
#if LOG_ALL_DRAWING
|
35
|
-
RNSkLogger::logToConsole("JniSkiaDrawView::~JniSkiaDrawView %i", getNativeId());
|
36
|
-
#endif
|
37
34
|
}
|
38
35
|
|
39
36
|
/**** JNI ****/
|
40
37
|
|
41
38
|
TSelf JniSkiaDrawView::initHybrid(
|
42
|
-
|
43
|
-
|
39
|
+
alias_ref<HybridClass::jhybridobject> jThis,
|
40
|
+
JavaSkiaManager skiaManager)
|
44
41
|
{
|
45
42
|
return makeCxxInstance(jThis, skiaManager);
|
46
43
|
}
|
@@ -60,17 +57,17 @@ namespace RNSkia
|
|
60
57
|
{
|
61
58
|
if (mode.compare("continuous") == 0)
|
62
59
|
{
|
63
|
-
setDrawingMode(RNSkDrawingMode::Continuous);
|
60
|
+
_drawView->setDrawingMode(RNSkDrawingMode::Continuous);
|
64
61
|
}
|
65
62
|
else
|
66
63
|
{
|
67
|
-
setDrawingMode(RNSkDrawingMode::Default);
|
64
|
+
_drawView->setDrawingMode(RNSkDrawingMode::Default);
|
68
65
|
}
|
69
66
|
}
|
70
67
|
|
71
68
|
void JniSkiaDrawView::setDebugMode(bool show)
|
72
69
|
{
|
73
|
-
setShowDebugOverlays(show);
|
70
|
+
_drawView->setShowDebugOverlays(show);
|
74
71
|
}
|
75
72
|
|
76
73
|
void JniSkiaDrawView::updateTouchPoints(jni::JArrayDouble touches)
|
@@ -78,7 +75,7 @@ namespace RNSkia
|
|
78
75
|
// Create touch points
|
79
76
|
std::vector<RNSkia::RNSkTouchPoint> points;
|
80
77
|
auto pin = touches.pin();
|
81
|
-
auto scale =
|
78
|
+
auto scale = _drawView->getPixelDensity();
|
82
79
|
points.reserve(pin.size() / 4);
|
83
80
|
for (size_t i = 0; i < pin.size(); i += 4)
|
84
81
|
{
|
@@ -89,81 +86,27 @@ namespace RNSkia
|
|
89
86
|
point.type = (RNSkia::RNSkTouchType)pin[i + 3];
|
90
87
|
points.push_back(point);
|
91
88
|
}
|
92
|
-
updateTouchState(std::move(points));
|
89
|
+
_drawView->updateTouchState(std::move(points));
|
93
90
|
}
|
94
91
|
|
95
92
|
void JniSkiaDrawView::surfaceAvailable(jobject surface, int width, int height)
|
96
93
|
{
|
97
|
-
|
98
|
-
RNSkLogger::logToConsole("JniSkiaDrawView::surfaceAvailable %i", getNativeId());
|
99
|
-
#endif
|
100
|
-
|
101
|
-
_width = width;
|
102
|
-
_height = height;
|
103
|
-
|
104
|
-
if (_renderer == nullptr)
|
105
|
-
{
|
106
|
-
// Create renderer!
|
107
|
-
_renderer = new SkiaOpenGLRenderer(
|
108
|
-
ANativeWindow_fromSurface(Environment::current(), surface), getNativeId());
|
109
|
-
|
110
|
-
// Set the draw function
|
111
|
-
setNativeDrawFunc(std::bind(&JniSkiaDrawView::drawFrame, this, std::placeholders::_1));
|
112
|
-
|
113
|
-
// Redraw
|
114
|
-
requestRedraw();
|
115
|
-
}
|
94
|
+
_drawView->surfaceAvailable(ANativeWindow_fromSurface(Environment::current(), surface), width, height);
|
116
95
|
}
|
117
96
|
|
118
97
|
void JniSkiaDrawView::surfaceSizeChanged(int width, int height)
|
119
98
|
{
|
120
|
-
|
121
|
-
RNSkLogger::logToConsole("JniSkiaDrawView::surfaceSizeChanged %i", getNativeId());
|
122
|
-
#endif
|
123
|
-
|
124
|
-
_width = width;
|
125
|
-
_height = height;
|
126
|
-
|
127
|
-
// Redraw after size change
|
128
|
-
requestRedraw();
|
99
|
+
_drawView->surfaceSizeChanged(width, height);
|
129
100
|
}
|
130
101
|
|
131
102
|
void JniSkiaDrawView::surfaceDestroyed()
|
132
103
|
{
|
133
|
-
|
134
|
-
RNSkLogger::logToConsole("JniSkiaDrawView::surfaceDestroyed %i", getNativeId());
|
135
|
-
#endif
|
136
|
-
if (_renderer != nullptr)
|
137
|
-
{
|
138
|
-
// Turn off drawing
|
139
|
-
setNativeDrawFunc(nullptr);
|
140
|
-
|
141
|
-
// Start teardown
|
142
|
-
_renderer->teardown();
|
143
|
-
|
144
|
-
// Ask for a redraw to tear down the render pipeline. This
|
145
|
-
// needs to be done on the render thread since OpenGL demands
|
146
|
-
// same thread access for OpenGL contexts.
|
147
|
-
getPlatformContext()->runOnRenderThread([this]()
|
148
|
-
{
|
149
|
-
if(_renderer != nullptr) {
|
150
|
-
_renderer->run(nullptr, 0, 0);
|
151
|
-
} });
|
152
|
-
|
153
|
-
// Wait until the above render has finished.
|
154
|
-
_renderer->waitForTeardown();
|
155
|
-
|
156
|
-
// Delete renderer. All resources should be released during teardown.
|
157
|
-
delete _renderer;
|
158
|
-
_renderer = nullptr;
|
159
|
-
}
|
104
|
+
_drawView->surfaceDestroyed();
|
160
105
|
}
|
161
106
|
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
// No need to check if the renderer is nullptr since we only get here if it is not.
|
167
|
-
_renderer->run(picture, _width, _height);
|
107
|
+
void JniSkiaDrawView::releaseSurface() {
|
108
|
+
jni::ThreadScope ts;
|
109
|
+
static auto method = javaPart_->getClass()->getMethod<void(void)>("releaseSurface");
|
110
|
+
method(javaPart_.get());
|
168
111
|
}
|
169
112
|
} // namespace RNSkia
|
@@ -47,7 +47,7 @@ void JniSkiaManager::initializeRuntime() {
|
|
47
47
|
}
|
48
48
|
|
49
49
|
void JniSkiaManager::registerSkiaView(int viewTag, JniSkiaDrawView *skiaView) {
|
50
|
-
_skManager->registerSkiaDrawView(viewTag, skiaView);
|
50
|
+
_skManager->registerSkiaDrawView(viewTag, skiaView->getDrawViewImpl());
|
51
51
|
}
|
52
52
|
|
53
53
|
void JniSkiaManager::unregisterSkiaView(int viewTag) {
|
@@ -5,17 +5,16 @@
|
|
5
5
|
#include <thread>
|
6
6
|
#include <string>
|
7
7
|
|
8
|
-
#include <EGL/egl.h>
|
9
|
-
#include <GLES2/gl2.h>
|
10
8
|
#include <fbjni/fbjni.h>
|
11
9
|
#include <jni.h>
|
12
10
|
#include <jsi/jsi.h>
|
13
11
|
#include <thread>
|
14
12
|
|
15
13
|
#include <RNSkDrawView.h>
|
16
|
-
#include
|
17
|
-
#include
|
18
|
-
|
14
|
+
#include <JniSkiaManager.h>
|
15
|
+
#include <JniSkiaDrawView.h>
|
16
|
+
|
17
|
+
#include <RNSkDrawViewImpl.h>
|
19
18
|
|
20
19
|
#include <SkSurface.h>
|
21
20
|
#include <SkRefCnt.h>
|
@@ -31,16 +30,15 @@ namespace RNSkia
|
|
31
30
|
|
32
31
|
using JavaSkiaManager = jni::alias_ref<JniSkiaManager::javaobject>;
|
33
32
|
|
34
|
-
class JniSkiaDrawView : public jni::HybridClass<JniSkiaDrawView
|
35
|
-
public RNSkDrawView
|
33
|
+
class JniSkiaDrawView : public jni::HybridClass<JniSkiaDrawView>
|
36
34
|
{
|
37
35
|
public:
|
38
36
|
static auto constexpr kJavaDescriptor = "Lcom/shopify/reactnative/skia/SkiaDrawView;";
|
39
37
|
static auto constexpr TAG = "ReactNativeSkia";
|
40
38
|
|
41
39
|
static jni::local_ref<jhybriddata> initHybrid(
|
42
|
-
|
43
|
-
|
40
|
+
jni::alias_ref<jhybridobject>,
|
41
|
+
JavaSkiaManager);
|
44
42
|
|
45
43
|
static void registerNatives();
|
46
44
|
|
@@ -52,30 +50,28 @@ namespace RNSkia
|
|
52
50
|
|
53
51
|
~JniSkiaDrawView();
|
54
52
|
|
55
|
-
|
56
|
-
|
57
|
-
|
53
|
+
std::shared_ptr<RNSkDrawView> getDrawViewImpl() { return _drawView; }
|
54
|
+
|
55
|
+
void releaseSurface();
|
58
56
|
|
57
|
+
protected:
|
59
58
|
void setMode(std::string mode);
|
60
59
|
void setDebugMode(bool show);
|
61
60
|
|
62
61
|
private:
|
63
62
|
friend HybridBase;
|
64
63
|
|
65
|
-
|
66
|
-
|
67
|
-
int _width = 0;
|
68
|
-
int _height = 0;
|
69
|
-
|
70
|
-
SkiaOpenGLRenderer* _renderer = nullptr;
|
64
|
+
std::shared_ptr<RNSkDrawViewImpl> _drawView;
|
71
65
|
|
72
66
|
jni::global_ref<JniSkiaDrawView::javaobject> javaPart_;
|
73
67
|
|
74
68
|
explicit JniSkiaDrawView(
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
69
|
+
jni::alias_ref<JniSkiaDrawView::jhybridobject> jThis,
|
70
|
+
JavaSkiaManager skiaManager)
|
71
|
+
: javaPart_(jni::make_global(jThis)),
|
72
|
+
_drawView(std::make_shared<RNSkDrawViewImpl>(skiaManager->cthis()->getPlatformContext(), [this]() {
|
73
|
+
releaseSurface();
|
74
|
+
})) {
|
79
75
|
}
|
80
76
|
};
|
81
77
|
|
@@ -7,7 +7,7 @@
|
|
7
7
|
#include <memory>
|
8
8
|
|
9
9
|
#include <JniPlatformContext.h>
|
10
|
-
#include <
|
10
|
+
#include <RNSkPlatformContextImpl.h>
|
11
11
|
|
12
12
|
#include <RNSkLog.h>
|
13
13
|
|
@@ -48,14 +48,14 @@ class JniSkiaManager : public jni::HybridClass<JniSkiaManager> {
|
|
48
48
|
: _javaPart(jni::make_global(jThis)),
|
49
49
|
_jsRuntime(runtime),
|
50
50
|
_jsCallInvoker(jsCallInvoker),
|
51
|
-
_context(std::make_shared<
|
51
|
+
_context(std::make_shared<RNSkPlatformContextImpl>(platformContext, runtime, jsCallInvoker)) {
|
52
52
|
|
53
53
|
}
|
54
54
|
|
55
55
|
void registerSkiaView(int viewTag, JniSkiaDrawView *skiaView);
|
56
56
|
void unregisterSkiaView(int viewTag);
|
57
57
|
|
58
|
-
std::shared_ptr<
|
58
|
+
std::shared_ptr<RNSkPlatformContextImpl> getPlatformContext() { return _context; }
|
59
59
|
|
60
60
|
void invalidate() {
|
61
61
|
_context->stopDrawLoop();
|
@@ -73,7 +73,7 @@ class JniSkiaManager : public jni::HybridClass<JniSkiaManager> {
|
|
73
73
|
|
74
74
|
jsi::Runtime *_jsRuntime;
|
75
75
|
std::shared_ptr<facebook::react::CallInvoker> _jsCallInvoker;
|
76
|
-
std::shared_ptr<
|
76
|
+
std::shared_ptr<RNSkPlatformContextImpl> _context;
|
77
77
|
|
78
78
|
void initializeRuntime();
|
79
79
|
};
|
@@ -0,0 +1,68 @@
|
|
1
|
+
#include <RNSkDrawViewImpl.h>
|
2
|
+
|
3
|
+
#pragma clang diagnostic push
|
4
|
+
#pragma clang diagnostic ignored "-Wdocumentation"
|
5
|
+
|
6
|
+
#include <SkSurface.h>
|
7
|
+
#include <SkCanvas.h>
|
8
|
+
|
9
|
+
#pragma clang diagnostic pop
|
10
|
+
|
11
|
+
#include <RNSkLog.h>
|
12
|
+
|
13
|
+
namespace RNSkia {
|
14
|
+
RNSkDrawViewImpl::RNSkDrawViewImpl(std::shared_ptr <RNSkia::RNSkPlatformContext> context, std::function<void()> releaseSurfaceCallback) :
|
15
|
+
RNSkia::RNSkDrawView(context),
|
16
|
+
_releaseSurfaceCallback(std::move(releaseSurfaceCallback)) {}
|
17
|
+
|
18
|
+
void RNSkDrawViewImpl::surfaceAvailable(ANativeWindow* surface, int width, int height) {
|
19
|
+
_width = width;
|
20
|
+
_height = height;
|
21
|
+
|
22
|
+
if (_renderer == nullptr)
|
23
|
+
{
|
24
|
+
// Create renderer!
|
25
|
+
_renderer = std::make_unique<SkiaOpenGLRenderer>(surface, getNativeId());
|
26
|
+
|
27
|
+
// Redraw
|
28
|
+
requestRedraw();
|
29
|
+
}
|
30
|
+
}
|
31
|
+
|
32
|
+
void RNSkDrawViewImpl::surfaceDestroyed() {
|
33
|
+
if (_renderer != nullptr)
|
34
|
+
{
|
35
|
+
// Start teardown
|
36
|
+
_renderer->teardown();
|
37
|
+
|
38
|
+
// Teardown renderer on the render thread since OpenGL demands
|
39
|
+
// same thread access for OpenGL contexts.
|
40
|
+
getPlatformContext()->runOnRenderThread([weakSelf = weak_from_this()]() {
|
41
|
+
auto self = weakSelf.lock();
|
42
|
+
if(self) {
|
43
|
+
auto drawViewImpl = std::dynamic_pointer_cast<RNSkDrawViewImpl>(self);
|
44
|
+
if(drawViewImpl->_renderer != nullptr) {
|
45
|
+
drawViewImpl->_renderer->run(nullptr, 0, 0);
|
46
|
+
}
|
47
|
+
// Remove renderer
|
48
|
+
drawViewImpl->_renderer = nullptr;
|
49
|
+
drawViewImpl->_releaseSurfaceCallback();
|
50
|
+
}
|
51
|
+
});
|
52
|
+
}
|
53
|
+
}
|
54
|
+
|
55
|
+
void RNSkDrawViewImpl::surfaceSizeChanged(int width, int height) {
|
56
|
+
_width = width;
|
57
|
+
_height = height;
|
58
|
+
|
59
|
+
// Redraw after size change
|
60
|
+
requestRedraw();
|
61
|
+
}
|
62
|
+
|
63
|
+
void RNSkDrawViewImpl::drawPicture(const sk_sp <SkPicture> picture) {
|
64
|
+
if(_renderer != nullptr) {
|
65
|
+
_renderer->run(picture, _width, _height);
|
66
|
+
}
|
67
|
+
}
|
68
|
+
}
|
@@ -0,0 +1,48 @@
|
|
1
|
+
#pragma once
|
2
|
+
|
3
|
+
#include <RNSkDrawView.h>
|
4
|
+
|
5
|
+
#include <SkiaOpenGLRenderer.h>
|
6
|
+
#include <android/native_window.h>
|
7
|
+
|
8
|
+
#pragma clang diagnostic push
|
9
|
+
#pragma clang diagnostic ignored "-Wdocumentation"
|
10
|
+
|
11
|
+
#include <SkPicture.h>
|
12
|
+
#include <SkRefCnt.h>
|
13
|
+
|
14
|
+
#pragma clang diagnostic pop
|
15
|
+
|
16
|
+
namespace RNSkia {
|
17
|
+
class RNSkDrawViewImpl : public RNSkia::RNSkDrawView {
|
18
|
+
public:
|
19
|
+
RNSkDrawViewImpl(std::shared_ptr <RNSkia::RNSkPlatformContext> context,
|
20
|
+
std::function<void()> releaseSurfaceCallback);
|
21
|
+
|
22
|
+
void surfaceAvailable(ANativeWindow* surface, int, int);
|
23
|
+
void surfaceDestroyed();
|
24
|
+
void surfaceSizeChanged(int, int);
|
25
|
+
|
26
|
+
float getPixelDensity() {
|
27
|
+
return getPlatformContext()->getPixelDensity();
|
28
|
+
}
|
29
|
+
|
30
|
+
protected:
|
31
|
+
int getWidth() override { return _width * getPlatformContext()->getPixelDensity(); };
|
32
|
+
|
33
|
+
int getHeight() override { return _height * getPlatformContext()->getPixelDensity(); };
|
34
|
+
|
35
|
+
void drawPicture(const sk_sp <SkPicture> picture) override;
|
36
|
+
|
37
|
+
private:
|
38
|
+
bool createSkiaSurface();
|
39
|
+
|
40
|
+
std::unique_ptr<SkiaOpenGLRenderer> _renderer = nullptr;
|
41
|
+
|
42
|
+
int _nativeId;
|
43
|
+
int _width = -1;
|
44
|
+
int _height = -1;
|
45
|
+
|
46
|
+
std::function<void()> _releaseSurfaceCallback;
|
47
|
+
};
|
48
|
+
}
|
@@ -11,11 +11,11 @@
|
|
11
11
|
namespace RNSkia {
|
12
12
|
using namespace facebook;
|
13
13
|
|
14
|
-
class
|
14
|
+
class RNSkPlatformContextImpl: public RNSkPlatformContext {
|
15
15
|
public:
|
16
|
-
|
17
|
-
|
18
|
-
|
16
|
+
RNSkPlatformContextImpl(JniPlatformContext* jniPlatformContext,
|
17
|
+
jsi::Runtime *runtime,
|
18
|
+
std::shared_ptr<facebook::react::CallInvoker> jsCallInvoker) :
|
19
19
|
RNSkPlatformContext(runtime,
|
20
20
|
jsCallInvoker,
|
21
21
|
jniPlatformContext->getPixelDensity()),
|
@@ -1,9 +1,9 @@
|
|
1
1
|
#include "SkiaOpenGLRenderer.h"
|
2
2
|
|
3
3
|
#include <RNSkLog.h>
|
4
|
+
|
4
5
|
namespace RNSkia
|
5
6
|
{
|
6
|
-
|
7
7
|
/** Static members */
|
8
8
|
std::shared_ptr<DrawingContext> SkiaOpenGLRenderer::getThreadDrawingContext()
|
9
9
|
{
|
@@ -20,6 +20,11 @@ namespace RNSkia
|
|
20
20
|
return threadContexts.at(threadId);
|
21
21
|
}
|
22
22
|
|
23
|
+
SkiaOpenGLRenderer::SkiaOpenGLRenderer(ANativeWindow *surface, size_t renderId):
|
24
|
+
_surfaceTexture(surface),
|
25
|
+
_renderId(renderId) {
|
26
|
+
}
|
27
|
+
|
23
28
|
void SkiaOpenGLRenderer::run(const sk_sp<SkPicture> picture, int width, int height)
|
24
29
|
{
|
25
30
|
switch (_renderState)
|
@@ -73,7 +78,16 @@ namespace RNSkia
|
|
73
78
|
}
|
74
79
|
case RenderState::Finishing:
|
75
80
|
{
|
76
|
-
|
81
|
+
_renderState = RenderState::Done;
|
82
|
+
|
83
|
+
if (_glSurface != EGL_NO_SURFACE && getThreadDrawingContext()->glDisplay != EGL_NO_DISPLAY)
|
84
|
+
{
|
85
|
+
eglDestroySurface(getThreadDrawingContext()->glDisplay, _glSurface);
|
86
|
+
}
|
87
|
+
|
88
|
+
_skSurface = nullptr;
|
89
|
+
_surfaceTexture = nullptr;
|
90
|
+
|
77
91
|
break;
|
78
92
|
}
|
79
93
|
case RenderState::Done:
|
@@ -107,58 +121,11 @@ namespace RNSkia
|
|
107
121
|
return true;
|
108
122
|
}
|
109
123
|
|
110
|
-
void SkiaOpenGLRenderer::finish()
|
111
|
-
{
|
112
|
-
std::lock_guard<std::mutex> lock(_lock);
|
113
|
-
|
114
|
-
if (_renderState != RenderState::Finishing)
|
115
|
-
{
|
116
|
-
_cv.notify_all();
|
117
|
-
return;
|
118
|
-
}
|
119
|
-
|
120
|
-
finishGL();
|
121
|
-
finishSkiaSurface();
|
122
|
-
|
123
|
-
_renderState = RenderState::Done;
|
124
|
-
|
125
|
-
_cv.notify_one();
|
126
|
-
}
|
127
|
-
|
128
|
-
void SkiaOpenGLRenderer::finishGL()
|
129
|
-
{
|
130
|
-
if (_glSurface != EGL_NO_SURFACE && getThreadDrawingContext()->glDisplay != EGL_NO_DISPLAY)
|
131
|
-
{
|
132
|
-
eglDestroySurface(getThreadDrawingContext()->glDisplay, _glSurface);
|
133
|
-
}
|
134
|
-
}
|
135
|
-
|
136
|
-
void SkiaOpenGLRenderer::finishSkiaSurface()
|
137
|
-
{
|
138
|
-
if (_skSurface != nullptr)
|
139
|
-
{
|
140
|
-
_skSurface = nullptr;
|
141
|
-
}
|
142
|
-
|
143
|
-
if (_nativeWindow != nullptr)
|
144
|
-
{
|
145
|
-
ANativeWindow_release(_nativeWindow);
|
146
|
-
_nativeWindow = nullptr;
|
147
|
-
}
|
148
|
-
}
|
149
|
-
|
150
124
|
void SkiaOpenGLRenderer::teardown()
|
151
125
|
{
|
152
126
|
_renderState = RenderState::Finishing;
|
153
127
|
}
|
154
128
|
|
155
|
-
void SkiaOpenGLRenderer::waitForTeardown()
|
156
|
-
{
|
157
|
-
std::unique_lock<std::mutex> lock(_lock);
|
158
|
-
_cv.wait(lock, [this]
|
159
|
-
{ return (_renderState == RenderState::Done); });
|
160
|
-
}
|
161
|
-
|
162
129
|
bool SkiaOpenGLRenderer::initStaticGLContext()
|
163
130
|
{
|
164
131
|
if (getThreadDrawingContext()->glContext != EGL_NO_CONTEXT)
|
@@ -212,7 +179,12 @@ namespace RNSkia
|
|
212
179
|
|
213
180
|
EGLint contextAttribs[] = {EGL_CONTEXT_CLIENT_VERSION, 2, EGL_NONE};
|
214
181
|
|
215
|
-
getThreadDrawingContext()->glContext = eglCreateContext(
|
182
|
+
getThreadDrawingContext()->glContext = eglCreateContext(
|
183
|
+
getThreadDrawingContext()->glDisplay,
|
184
|
+
getThreadDrawingContext()->glConfig,
|
185
|
+
NULL,
|
186
|
+
contextAttribs);
|
187
|
+
|
216
188
|
if (getThreadDrawingContext()->glContext == EGL_NO_CONTEXT)
|
217
189
|
{
|
218
190
|
RNSkLogger::logToConsole(
|
@@ -244,14 +216,18 @@ namespace RNSkia
|
|
244
216
|
|
245
217
|
bool SkiaOpenGLRenderer::initGLSurface()
|
246
218
|
{
|
247
|
-
if (
|
219
|
+
if (_surfaceTexture == nullptr)
|
248
220
|
{
|
249
221
|
return false;
|
250
222
|
}
|
251
223
|
|
252
224
|
if (_glSurface != EGL_NO_SURFACE)
|
253
225
|
{
|
254
|
-
if (!eglMakeCurrent(
|
226
|
+
if (!eglMakeCurrent(
|
227
|
+
getThreadDrawingContext()->glDisplay,
|
228
|
+
_glSurface,
|
229
|
+
_glSurface,
|
230
|
+
getThreadDrawingContext()->glContext))
|
255
231
|
{
|
256
232
|
RNSkLogger::logToConsole(
|
257
233
|
"eglMakeCurrent failed: %d\n", eglGetError());
|
@@ -262,7 +238,12 @@ namespace RNSkia
|
|
262
238
|
|
263
239
|
// Create the opengl surface
|
264
240
|
_glSurface =
|
265
|
-
eglCreateWindowSurface(
|
241
|
+
eglCreateWindowSurface(
|
242
|
+
getThreadDrawingContext()->glDisplay,
|
243
|
+
getThreadDrawingContext()->glConfig,
|
244
|
+
_surfaceTexture,
|
245
|
+
nullptr);
|
246
|
+
|
266
247
|
if (_glSurface == EGL_NO_SURFACE)
|
267
248
|
{
|
268
249
|
RNSkLogger::logToConsole(
|
@@ -270,7 +251,11 @@ namespace RNSkia
|
|
270
251
|
return false;
|
271
252
|
}
|
272
253
|
|
273
|
-
if (!eglMakeCurrent(
|
254
|
+
if (!eglMakeCurrent(
|
255
|
+
getThreadDrawingContext()->glDisplay,
|
256
|
+
_glSurface,
|
257
|
+
_glSurface,
|
258
|
+
getThreadDrawingContext()->glContext))
|
274
259
|
{
|
275
260
|
RNSkLogger::logToConsole("eglMakeCurrent failed: %d\n", eglGetError());
|
276
261
|
return false;
|
@@ -7,7 +7,6 @@
|
|
7
7
|
#include "GLES2/gl2.h"
|
8
8
|
|
9
9
|
#include <condition_variable>
|
10
|
-
#include <mutex>
|
11
10
|
#include <thread>
|
12
11
|
#include <unordered_map>
|
13
12
|
|
@@ -45,9 +44,7 @@ namespace RNSkia
|
|
45
44
|
class SkiaOpenGLRenderer
|
46
45
|
{
|
47
46
|
public:
|
48
|
-
SkiaOpenGLRenderer(ANativeWindow *
|
49
|
-
_nativeWindow(nativeWindow),
|
50
|
-
_renderId(renderId) { }
|
47
|
+
SkiaOpenGLRenderer(ANativeWindow *surface, size_t renderId);
|
51
48
|
|
52
49
|
/**
|
53
50
|
* Initializes, renders and tears down the render pipeline depending on the state of the
|
@@ -71,14 +68,6 @@ namespace RNSkia
|
|
71
68
|
*/
|
72
69
|
void teardown();
|
73
70
|
|
74
|
-
/**
|
75
|
-
* Wait for teardown to finish. This means that we'll wait until the next
|
76
|
-
* render which will handle releasing all OpenGL and Skia resources used for
|
77
|
-
* this renderer. After tearing down the render will do nothing if the render
|
78
|
-
* method is called again.
|
79
|
-
*/
|
80
|
-
void waitForTeardown();
|
81
|
-
|
82
71
|
private:
|
83
72
|
/**
|
84
73
|
* Initializes all required OpenGL and Skia objects
|
@@ -117,21 +106,6 @@ namespace RNSkia
|
|
117
106
|
*/
|
118
107
|
bool ensureSkiaSurface(int width, int height);
|
119
108
|
|
120
|
-
/**
|
121
|
-
* Finalizes and releases all resources used by this renderer
|
122
|
-
*/
|
123
|
-
void finish();
|
124
|
-
|
125
|
-
/**
|
126
|
-
* Destroys the underlying OpenGL surface used for this renderer
|
127
|
-
*/
|
128
|
-
void finishGL();
|
129
|
-
|
130
|
-
/**
|
131
|
-
* Destroys the underlying Skia surface used for this renderer
|
132
|
-
*/
|
133
|
-
void finishSkiaSurface();
|
134
|
-
|
135
109
|
/**
|
136
110
|
* To be able to use static contexts (and avoid reloading the skia context for each
|
137
111
|
* new view, we track the OpenGL and Skia drawing context per thread.
|
@@ -141,7 +115,7 @@ namespace RNSkia
|
|
141
115
|
|
142
116
|
EGLSurface _glSurface = EGL_NO_SURFACE;
|
143
117
|
|
144
|
-
ANativeWindow *
|
118
|
+
ANativeWindow *_surfaceTexture = nullptr;
|
145
119
|
GrBackendRenderTarget _skRenderTarget;
|
146
120
|
sk_sp<SkSurface> _skSurface;
|
147
121
|
|
@@ -150,9 +124,6 @@ namespace RNSkia
|
|
150
124
|
|
151
125
|
size_t _renderId;
|
152
126
|
|
153
|
-
std::mutex _lock;
|
154
|
-
std::condition_variable _cv;
|
155
|
-
|
156
127
|
std::atomic<RenderState> _renderState = { RenderState::Initializing };
|
157
128
|
};
|
158
129
|
|
@@ -61,7 +61,7 @@ public class RNSkiaViewManager extends BaseViewManager<SkiaDrawView, LayoutShado
|
|
61
61
|
Integer nativeId = mViewMapping.get(view);
|
62
62
|
skiaModule.getSkiaManager().unregister(nativeId);
|
63
63
|
mViewMapping.remove(view);
|
64
|
-
view.
|
64
|
+
view.onViewRemoved();
|
65
65
|
}
|
66
66
|
|
67
67
|
@NonNull
|