@shopify/react-native-skia 1.5.6 → 1.5.7
Sign up to get free protection for your applications and to get access to all the features.
- package/android/cpp/jni/include/JniSkiaBaseView.h +2 -2
- package/android/cpp/jni/include/JniSkiaDomView.h +2 -2
- package/android/cpp/jni/include/JniSkiaPictureView.h +2 -2
- package/android/cpp/rnskia-android/OpenGLContext.h +3 -1
- package/android/cpp/rnskia-android/OpenGLWindowContext.cpp +20 -49
- package/android/cpp/rnskia-android/OpenGLWindowContext.h +14 -16
- package/android/cpp/rnskia-android/RNSkAndroidView.h +3 -3
- package/android/cpp/rnskia-android/RNSkOpenGLCanvasProvider.cpp +13 -4
- package/android/cpp/rnskia-android/RNSkOpenGLCanvasProvider.h +1 -1
- package/android/cpp/rnskia-android/gl/Display.h +4 -0
- package/android/src/main/java/com/shopify/reactnative/skia/SkiaBaseView.java +7 -7
- package/android/src/main/java/com/shopify/reactnative/skia/SkiaDomView.java +1 -3
- package/android/src/main/java/com/shopify/reactnative/skia/SkiaPictureView.java +1 -3
- package/ios/RNSkia-iOS/SkiaMetalSurfaceFactory.h +2 -2
- package/package.json +1 -1
- package/android/src/paper/java/com/facebook/react/viewmanagers/SkiaDrawViewManagerInterface.java +0 -18
@@ -33,8 +33,8 @@ protected:
|
|
33
33
|
_skiaAndroidView->surfaceAvailable(surface, width, height);
|
34
34
|
}
|
35
35
|
|
36
|
-
virtual void surfaceSizeChanged(int width, int height) {
|
37
|
-
_skiaAndroidView->surfaceSizeChanged(width, height);
|
36
|
+
virtual void surfaceSizeChanged(jobject surface, int width, int height) {
|
37
|
+
_skiaAndroidView->surfaceSizeChanged(surface, width, height);
|
38
38
|
}
|
39
39
|
|
40
40
|
virtual void surfaceDestroyed() { _skiaAndroidView->surfaceDestroyed(); }
|
@@ -51,8 +51,8 @@ protected:
|
|
51
51
|
JniSkiaBaseView::surfaceAvailable(surface, width, height);
|
52
52
|
}
|
53
53
|
|
54
|
-
void surfaceSizeChanged(int width, int height) override {
|
55
|
-
JniSkiaBaseView::surfaceSizeChanged(width, height);
|
54
|
+
void surfaceSizeChanged(jobject surface, int width, int height) override {
|
55
|
+
JniSkiaBaseView::surfaceSizeChanged(surface, width, height);
|
56
56
|
}
|
57
57
|
|
58
58
|
void surfaceDestroyed() override { JniSkiaBaseView::surfaceDestroyed(); }
|
@@ -53,8 +53,8 @@ protected:
|
|
53
53
|
JniSkiaBaseView::surfaceAvailable(surface, width, height);
|
54
54
|
}
|
55
55
|
|
56
|
-
void surfaceSizeChanged(int width, int height) override {
|
57
|
-
JniSkiaBaseView::surfaceSizeChanged(width, height);
|
56
|
+
void surfaceSizeChanged(jobject surface, int width, int height) override {
|
57
|
+
JniSkiaBaseView::surfaceSizeChanged(surface, width, height);
|
58
58
|
}
|
59
59
|
|
60
60
|
void surfaceDestroyed() override { JniSkiaBaseView::surfaceDestroyed(); }
|
@@ -125,9 +125,11 @@ public:
|
|
125
125
|
#endif
|
126
126
|
}
|
127
127
|
|
128
|
+
// TODO: remove width, height
|
128
129
|
std::unique_ptr<WindowContext> MakeWindow(ANativeWindow *window, int width,
|
129
130
|
int height) {
|
130
|
-
return std::make_unique<OpenGLWindowContext>(
|
131
|
+
return std::make_unique<OpenGLWindowContext>(
|
132
|
+
_directContext, _glDisplay.get(), _glContext.get(), window);
|
131
133
|
}
|
132
134
|
|
133
135
|
private:
|
@@ -16,74 +16,45 @@ namespace RNSkia {
|
|
16
16
|
|
17
17
|
sk_sp<SkSurface> OpenGLWindowContext::getSurface() {
|
18
18
|
if (_skSurface == nullptr) {
|
19
|
-
|
20
|
-
struct ReleaseContext {
|
21
|
-
std::unique_ptr<gl::Surface> surface = nullptr;
|
22
|
-
};
|
23
|
-
|
24
|
-
if (!_window) {
|
25
|
-
throw std::runtime_error("No native window provided");
|
26
|
-
}
|
27
|
-
auto releaseCtx = new ReleaseContext();
|
28
|
-
releaseCtx->surface =
|
29
|
-
_context->_glDisplay->makeWindowSurface(_context->_glConfig, _window);
|
30
|
-
if (!releaseCtx->surface) {
|
31
|
-
throw std::runtime_error("Failed to create window surface");
|
32
|
-
}
|
33
|
-
_glSurface = releaseCtx->surface.get();
|
34
|
-
|
35
|
-
// Now make this one current
|
36
|
-
auto success = _context->_glContext->makeCurrent(releaseCtx->surface.get());
|
37
|
-
if (!success) {
|
38
|
-
throw std::runtime_error("Failed to make window surface current");
|
39
|
-
}
|
40
|
-
|
41
|
-
// Set up parameters for the render target so that it
|
42
|
-
// matches the underlying OpenGL context.
|
43
|
-
GrGLFramebufferInfo fboInfo;
|
44
|
-
|
45
|
-
// We pass 0 as the framebuffer id, since the
|
46
|
-
// underlying Skia GrGlGpu will read this when wrapping the context in the
|
47
|
-
// render target and the GrGlGpu object.
|
48
|
-
fboInfo.fFBOID = 0;
|
49
|
-
fboInfo.fFormat = 0x8058; // GL_RGBA8
|
50
|
-
|
19
|
+
_glContext->makeCurrent(_glSurface.get());
|
51
20
|
GLint stencil;
|
52
21
|
glGetIntegerv(GL_STENCIL_BITS, &stencil);
|
53
22
|
|
54
23
|
GLint samples;
|
55
24
|
glGetIntegerv(GL_SAMPLES, &samples);
|
56
25
|
|
57
|
-
auto colorType =
|
26
|
+
auto colorType = kRGBA_8888_SkColorType;
|
58
27
|
|
59
28
|
auto maxSamples =
|
60
|
-
|
29
|
+
_directContext->maxSurfaceSampleCountForColorType(colorType);
|
61
30
|
|
62
31
|
if (samples > maxSamples) {
|
63
32
|
samples = maxSamples;
|
64
33
|
}
|
65
34
|
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
35
|
+
GrGLFramebufferInfo fbInfo;
|
36
|
+
fbInfo.fFBOID = 0;
|
37
|
+
fbInfo.fFormat = GR_GL_RGBA8;
|
38
|
+
// fbInfo.fProtected =
|
39
|
+
// skgpu::Protected(fDisplayParams.fCreateProtectedNativeBackend);
|
40
|
+
|
41
|
+
auto width = ANativeWindow_getWidth(_window);
|
42
|
+
auto height = ANativeWindow_getHeight(_window);
|
43
|
+
auto backendRT =
|
44
|
+
GrBackendRenderTargets::MakeGL(width, height, samples, stencil, fbInfo);
|
45
|
+
sk_sp<SkColorSpace> colorSpace(nullptr);
|
46
|
+
SkSurfaceProps surfaceProps(0, kRGB_H_SkPixelGeometry);
|
72
47
|
_skSurface = SkSurfaces::WrapBackendRenderTarget(
|
73
|
-
|
74
|
-
|
75
|
-
[](void *addr) {
|
76
|
-
auto releaseCtx = reinterpret_cast<ReleaseContext *>(addr);
|
77
|
-
delete releaseCtx;
|
78
|
-
},
|
79
|
-
reinterpret_cast<void *>(releaseCtx));
|
48
|
+
_directContext.get(), backendRT, kBottomLeft_GrSurfaceOrigin,
|
49
|
+
kRGBA_8888_SkColorType, colorSpace, &surfaceProps);
|
80
50
|
}
|
81
51
|
return _skSurface;
|
82
52
|
}
|
83
53
|
|
84
54
|
void OpenGLWindowContext::present() {
|
85
|
-
|
86
|
-
|
55
|
+
_glContext->makeCurrent(_glSurface.get());
|
56
|
+
// TODO: is flushAndSubmit needed here?
|
57
|
+
_directContext->flushAndSubmit();
|
87
58
|
_glSurface->present();
|
88
59
|
}
|
89
60
|
|
@@ -31,14 +31,16 @@
|
|
31
31
|
|
32
32
|
namespace RNSkia {
|
33
33
|
|
34
|
-
class OpenGLContext;
|
35
|
-
|
36
34
|
class OpenGLWindowContext : public WindowContext {
|
37
35
|
public:
|
38
|
-
OpenGLWindowContext(
|
39
|
-
|
40
|
-
|
36
|
+
OpenGLWindowContext(sk_sp<GrDirectContext> directContext,
|
37
|
+
gl::Display *display, gl::Context *glContext,
|
38
|
+
ANativeWindow *window)
|
39
|
+
: _directContext(directContext), _display(display), _glContext(glContext),
|
40
|
+
_window(window) {
|
41
41
|
ANativeWindow_acquire(_window);
|
42
|
+
auto config = display->chooseConfig();
|
43
|
+
_glSurface = display->makeWindowSurface(config, _window);
|
42
44
|
}
|
43
45
|
|
44
46
|
~OpenGLWindowContext() {
|
@@ -51,23 +53,19 @@ public:
|
|
51
53
|
|
52
54
|
void present() override;
|
53
55
|
|
54
|
-
|
55
|
-
_skSurface = nullptr;
|
56
|
-
_width = width;
|
57
|
-
_height = height;
|
58
|
-
}
|
56
|
+
int getWidth() override { return ANativeWindow_getWidth(_window); };
|
59
57
|
|
60
|
-
int
|
58
|
+
int getHeight() override { return ANativeWindow_getHeight(_window); };
|
61
59
|
|
62
|
-
int
|
60
|
+
void resize(int width, int height) override { _skSurface = nullptr; }
|
63
61
|
|
64
62
|
private:
|
65
|
-
|
63
|
+
sk_sp<GrDirectContext> _directContext;
|
64
|
+
gl::Display *_display;
|
66
65
|
ANativeWindow *_window;
|
67
66
|
sk_sp<SkSurface> _skSurface = nullptr;
|
68
|
-
gl::
|
69
|
-
|
70
|
-
int _height = 0;
|
67
|
+
gl::Context *_glContext = nullptr;
|
68
|
+
std::unique_ptr<gl::Surface> _glSurface = nullptr;
|
71
69
|
};
|
72
70
|
|
73
71
|
} // namespace RNSkia
|
@@ -15,7 +15,7 @@ public:
|
|
15
15
|
|
16
16
|
virtual void surfaceDestroyed() = 0;
|
17
17
|
|
18
|
-
virtual void surfaceSizeChanged(int width, int height) = 0;
|
18
|
+
virtual void surfaceSizeChanged(jobject surface, int width, int height) = 0;
|
19
19
|
|
20
20
|
virtual float getPixelDensity() = 0;
|
21
21
|
|
@@ -50,9 +50,9 @@ public:
|
|
50
50
|
->surfaceDestroyed();
|
51
51
|
}
|
52
52
|
|
53
|
-
void surfaceSizeChanged(int width, int height) override {
|
53
|
+
void surfaceSizeChanged(jobject surface, int width, int height) override {
|
54
54
|
std::static_pointer_cast<RNSkOpenGLCanvasProvider>(T::getCanvasProvider())
|
55
|
-
->surfaceSizeChanged(width, height);
|
55
|
+
->surfaceSizeChanged(surface, width, height);
|
56
56
|
// This is only need for the first time to frame, this renderImmediate call
|
57
57
|
// will invoke updateTexImage for the previous frame
|
58
58
|
RNSkView::renderImmediate();
|
@@ -76,6 +76,10 @@ bool RNSkOpenGLCanvasProvider::renderToCanvas(
|
|
76
76
|
|
77
77
|
void RNSkOpenGLCanvasProvider::surfaceAvailable(jobject jSurfaceTexture,
|
78
78
|
int width, int height) {
|
79
|
+
// If the surface is 0, we can skip it
|
80
|
+
if (width == 0 && height == 0) {
|
81
|
+
return;
|
82
|
+
}
|
79
83
|
// Create renderer!
|
80
84
|
JNIEnv *env = facebook::jni::Environment::current();
|
81
85
|
|
@@ -118,17 +122,22 @@ void RNSkOpenGLCanvasProvider::surfaceDestroyed() {
|
|
118
122
|
}
|
119
123
|
}
|
120
124
|
|
121
|
-
void RNSkOpenGLCanvasProvider::surfaceSizeChanged(
|
125
|
+
void RNSkOpenGLCanvasProvider::surfaceSizeChanged(jobject jSurfaceTexture,
|
126
|
+
int width, int height) {
|
122
127
|
if (width == 0 && height == 0) {
|
123
128
|
// Setting width/height to zero is nothing we need to care about when
|
124
129
|
// it comes to invalidating the surface.
|
125
130
|
return;
|
126
131
|
}
|
127
132
|
|
128
|
-
|
129
|
-
|
133
|
+
if (_surfaceHolder == nullptr) {
|
134
|
+
_surfaceHolder = nullptr;
|
135
|
+
surfaceAvailable(jSurfaceTexture, width, height);
|
136
|
+
} else {
|
137
|
+
_surfaceHolder->resize(width, height);
|
138
|
+
}
|
130
139
|
|
131
140
|
// Redraw after size change
|
132
141
|
_requestRedraw();
|
133
142
|
}
|
134
|
-
} // namespace RNSkia
|
143
|
+
} // namespace RNSkia
|
@@ -35,6 +35,10 @@ public:
|
|
35
35
|
|
36
36
|
bool isValid() const { return _display != EGL_NO_DISPLAY; }
|
37
37
|
|
38
|
+
void clearContext() {
|
39
|
+
eglMakeCurrent(_display, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
|
40
|
+
}
|
41
|
+
|
38
42
|
EGLConfig chooseConfig() {
|
39
43
|
|
40
44
|
EGLint att[] = {EGL_RENDERABLE_TYPE,
|
@@ -64,7 +64,7 @@ public abstract class SkiaBaseView extends ReactViewGroup implements TextureView
|
|
64
64
|
return;
|
65
65
|
}
|
66
66
|
Log.i(tag, "onSurfaceTextureSizeChanged " + width + "/" + height);
|
67
|
-
surfaceSizeChanged(width, height);
|
67
|
+
surfaceSizeChanged(surface, width, height);
|
68
68
|
}
|
69
69
|
|
70
70
|
@Override
|
@@ -82,18 +82,18 @@ public abstract class SkiaBaseView extends ReactViewGroup implements TextureView
|
|
82
82
|
return false;
|
83
83
|
}
|
84
84
|
|
85
|
-
|
85
|
+
private long _prevTimestamp = 0;
|
86
86
|
@Override
|
87
87
|
public void onSurfaceTextureUpdated(SurfaceTexture surface) {
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
88
|
+
long timestamp = surface.getTimestamp();
|
89
|
+
long frameDuration = (timestamp - _prevTimestamp)/1000000;
|
90
|
+
Log.i(tag, "onSurfaceTextureUpdated "+frameDuration+"ms");
|
91
|
+
_prevTimestamp = timestamp;
|
92
92
|
}
|
93
93
|
|
94
94
|
protected abstract void surfaceAvailable(Object surface, int width, int height);
|
95
95
|
|
96
|
-
protected abstract void surfaceSizeChanged(int width, int height);
|
96
|
+
protected abstract void surfaceSizeChanged(Object surface, int width, int height);
|
97
97
|
|
98
98
|
protected abstract void surfaceDestroyed();
|
99
99
|
|
@@ -27,7 +27,7 @@ public class SkiaDomView extends SkiaBaseView {
|
|
27
27
|
|
28
28
|
protected native void surfaceAvailable(Object surface, int width, int height);
|
29
29
|
|
30
|
-
protected native void surfaceSizeChanged(int width, int height);
|
30
|
+
protected native void surfaceSizeChanged(Object surface, int width, int height);
|
31
31
|
|
32
32
|
protected native void surfaceDestroyed();
|
33
33
|
|
@@ -37,8 +37,6 @@ public class SkiaDomView extends SkiaBaseView {
|
|
37
37
|
|
38
38
|
protected native void setDebugMode(boolean show);
|
39
39
|
|
40
|
-
protected native void updateTouchPoints(double[] points);
|
41
|
-
|
42
40
|
protected native void registerView(int nativeId);
|
43
41
|
|
44
42
|
protected native void unregisterView();
|
@@ -26,7 +26,7 @@ public class SkiaPictureView extends SkiaBaseView {
|
|
26
26
|
|
27
27
|
protected native void surfaceAvailable(Object surface, int width, int height);
|
28
28
|
|
29
|
-
protected native void surfaceSizeChanged(int width, int height);
|
29
|
+
protected native void surfaceSizeChanged(Object surface, int width, int height);
|
30
30
|
|
31
31
|
protected native void surfaceDestroyed();
|
32
32
|
|
@@ -36,8 +36,6 @@ public class SkiaPictureView extends SkiaBaseView {
|
|
36
36
|
|
37
37
|
protected native void setDebugMode(boolean show);
|
38
38
|
|
39
|
-
protected native void updateTouchPoints(double[] points);
|
40
|
-
|
41
39
|
protected native void registerView(int nativeId);
|
42
40
|
|
43
41
|
protected native void unregisterView();
|
@@ -107,8 +107,6 @@ public:
|
|
107
107
|
_skSurface = nullptr;
|
108
108
|
}
|
109
109
|
|
110
|
-
void resize(int width, int height) override { _skSurface = nullptr; }
|
111
|
-
|
112
110
|
int getWidth() override {
|
113
111
|
return _layer.frame.size.width * _layer.contentsScale;
|
114
112
|
};
|
@@ -117,6 +115,8 @@ public:
|
|
117
115
|
return _layer.frame.size.height * _layer.contentsScale;
|
118
116
|
};
|
119
117
|
|
118
|
+
void resize(int width, int height) override { _skSurface = nullptr; }
|
119
|
+
|
120
120
|
private:
|
121
121
|
SkiaMetalContext *_context;
|
122
122
|
sk_sp<SkSurface> _skSurface = nullptr;
|
package/package.json
CHANGED
@@ -7,7 +7,7 @@
|
|
7
7
|
"setup-skia-web": "./scripts/setup-canvaskit.js"
|
8
8
|
},
|
9
9
|
"title": "React Native Skia",
|
10
|
-
"version": "1.5.
|
10
|
+
"version": "1.5.7",
|
11
11
|
"description": "High-performance React Native Graphics using Skia",
|
12
12
|
"main": "lib/module/index.js",
|
13
13
|
"react-native": "src/index.ts",
|
package/android/src/paper/java/com/facebook/react/viewmanagers/SkiaDrawViewManagerInterface.java
DELETED
@@ -1,18 +0,0 @@
|
|
1
|
-
/**
|
2
|
-
* This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen).
|
3
|
-
*
|
4
|
-
* Do not edit this file as changes may cause incorrect behavior and will be lost
|
5
|
-
* once the code is regenerated.
|
6
|
-
*
|
7
|
-
* @generated by codegen project: GeneratePropsJavaInterface.js
|
8
|
-
*/
|
9
|
-
|
10
|
-
package com.facebook.react.viewmanagers;
|
11
|
-
|
12
|
-
import android.view.View;
|
13
|
-
import androidx.annotation.Nullable;
|
14
|
-
|
15
|
-
public interface SkiaDrawViewManagerInterface<T extends View> {
|
16
|
-
void setMode(T view, @Nullable String value);
|
17
|
-
void setDebug(T view, boolean value);
|
18
|
-
}
|