@shopify/react-native-skia 1.5.5 → 1.5.7
Sign up to get free protection for your applications and to get access to all the features.
- package/android/CMakeLists.txt +1 -1
- 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 +29 -23
- package/android/cpp/rnskia-android/OpenGLWindowContext.cpp +25 -37
- package/android/cpp/rnskia-android/OpenGLWindowContext.h +23 -26
- package/android/cpp/rnskia-android/RNSkAndroidPlatformContext.h +2 -2
- 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/{opengl → gl}/Context.h +8 -8
- package/android/cpp/rnskia-android/{opengl → gl}/Display.h +12 -8
- package/android/cpp/rnskia-android/{opengl → gl}/Error.cpp +1 -1
- package/android/cpp/rnskia-android/{opengl → gl}/Surface.h +7 -7
- 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/cpp/api/JsiSkiaContext.h +3 -0
- package/ios/RNSkia-iOS/RNSkMetalCanvasProvider.mm +3 -0
- package/ios/RNSkia-iOS/SkiaCVPixelBufferUtils.mm +8 -4
- 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
- /package/android/cpp/rnskia-android/{opengl → gl}/Error.h +0 -0
package/android/CMakeLists.txt
CHANGED
@@ -74,7 +74,7 @@ add_library(
|
|
74
74
|
"${PROJECT_SOURCE_DIR}/cpp/jni/JniSkiaManager.cpp"
|
75
75
|
|
76
76
|
"${PROJECT_SOURCE_DIR}/cpp/jni/JniPlatformContext.cpp"
|
77
|
-
"${PROJECT_SOURCE_DIR}/cpp/rnskia-android/
|
77
|
+
"${PROJECT_SOURCE_DIR}/cpp/rnskia-android/gl/Error.cpp"
|
78
78
|
"${PROJECT_SOURCE_DIR}/cpp/rnskia-android/RNSkOpenGLCanvasProvider.cpp"
|
79
79
|
"${PROJECT_SOURCE_DIR}/cpp/rnskia-android/AHardwareBufferUtils.cpp"
|
80
80
|
"${PROJECT_SOURCE_DIR}/cpp/rnskia-android/RNSkAndroidVideo.cpp"
|
@@ -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(); }
|
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
#include "GrAHardwareBufferUtils.h"
|
4
4
|
#include "OpenGLWindowContext.h"
|
5
|
-
#include "
|
5
|
+
#include "gl/Display.h"
|
6
6
|
|
7
7
|
#include "include/core/SkCanvas.h"
|
8
8
|
#include "include/core/SkColorSpace.h"
|
@@ -14,8 +14,12 @@
|
|
14
14
|
#include "include/gpu/ganesh/gl/GrGLInterface.h"
|
15
15
|
#include "src/gpu/ganesh/gl/GrGLDefines.h"
|
16
16
|
|
17
|
+
namespace RNSkia {
|
18
|
+
|
17
19
|
class OpenGLContext {
|
18
20
|
public:
|
21
|
+
friend class OpenGLWindowContext;
|
22
|
+
|
19
23
|
OpenGLContext(const OpenGLContext &) = delete;
|
20
24
|
OpenGLContext &operator=(const OpenGLContext &) = delete;
|
21
25
|
|
@@ -29,7 +33,7 @@ public:
|
|
29
33
|
|
30
34
|
SkSurfaceProps props(0, kUnknown_SkPixelGeometry);
|
31
35
|
|
32
|
-
auto result =
|
36
|
+
auto result = _glContext->makeCurrent(_glSurface.get());
|
33
37
|
if (!result) {
|
34
38
|
return nullptr;
|
35
39
|
}
|
@@ -39,8 +43,8 @@ public:
|
|
39
43
|
width, height, colorType, skgpu::Mipmapped::kNo, GrRenderable::kYes);
|
40
44
|
|
41
45
|
if (!texture.isValid()) {
|
42
|
-
|
43
|
-
|
46
|
+
RNSkLogger::logToConsole("couldn't create offscreen texture %dx%d", width,
|
47
|
+
height);
|
44
48
|
}
|
45
49
|
|
46
50
|
struct ReleaseContext {
|
@@ -68,9 +72,9 @@ public:
|
|
68
72
|
#if __ANDROID_API__ >= 26
|
69
73
|
const AHardwareBuffer *hardwareBuffer =
|
70
74
|
static_cast<AHardwareBuffer *>(buffer);
|
71
|
-
|
72
|
-
|
73
|
-
|
75
|
+
DeleteImageProc deleteImageProc = nullptr;
|
76
|
+
UpdateImageProc updateImageProc = nullptr;
|
77
|
+
TexImageCtx deleteImageCtx = nullptr;
|
74
78
|
|
75
79
|
AHardwareBuffer_Desc description;
|
76
80
|
AHardwareBuffer_describe(hardwareBuffer, &description);
|
@@ -100,12 +104,12 @@ public:
|
|
100
104
|
}
|
101
105
|
}
|
102
106
|
|
103
|
-
auto backendTex =
|
107
|
+
auto backendTex = MakeGLBackendTexture(
|
104
108
|
_directContext.get(), const_cast<AHardwareBuffer *>(hardwareBuffer),
|
105
109
|
description.width, description.height, &deleteImageProc,
|
106
110
|
&updateImageProc, &deleteImageCtx, false, format, false);
|
107
111
|
if (!backendTex.isValid()) {
|
108
|
-
|
112
|
+
RNSkLogger::logToConsole(
|
109
113
|
"Failed to convert HardwareBuffer to OpenGL Texture!");
|
110
114
|
return nullptr;
|
111
115
|
}
|
@@ -121,26 +125,26 @@ public:
|
|
121
125
|
#endif
|
122
126
|
}
|
123
127
|
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
128
|
+
// TODO: remove width, height
|
129
|
+
std::unique_ptr<WindowContext> MakeWindow(ANativeWindow *window, int width,
|
130
|
+
int height) {
|
131
|
+
return std::make_unique<OpenGLWindowContext>(
|
132
|
+
_directContext, _glDisplay.get(), _glContext.get(), window);
|
129
133
|
}
|
130
134
|
|
131
135
|
private:
|
132
|
-
EGLConfig
|
133
|
-
std::unique_ptr<
|
134
|
-
std::unique_ptr<
|
135
|
-
std::unique_ptr<
|
136
|
+
EGLConfig _glConfig;
|
137
|
+
std::unique_ptr<gl::Display> _glDisplay;
|
138
|
+
std::unique_ptr<gl::Context> _glContext;
|
139
|
+
std::unique_ptr<gl::Surface> _glSurface;
|
136
140
|
sk_sp<GrDirectContext> _directContext;
|
137
141
|
|
138
142
|
OpenGLContext() {
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
143
|
+
_glDisplay = std::make_unique<gl::Display>();
|
144
|
+
_glConfig = _glDisplay->chooseConfig();
|
145
|
+
_glContext = _glDisplay->makeContext(_glConfig, nullptr);
|
146
|
+
_glSurface = _glDisplay->makePixelBufferSurface(_glConfig, 1, 1);
|
147
|
+
_glContext->makeCurrent(_glSurface.get());
|
144
148
|
auto backendInterface = GrGLMakeNativeInterface();
|
145
149
|
_directContext = GrDirectContexts::MakeGL(backendInterface);
|
146
150
|
|
@@ -149,3 +153,5 @@ private:
|
|
149
153
|
}
|
150
154
|
}
|
151
155
|
};
|
156
|
+
|
157
|
+
} // namespace RNSkia
|
@@ -1,6 +1,8 @@
|
|
1
1
|
#include "OpenGLWindowContext.h"
|
2
2
|
#include "GrAHardwareBufferUtils.h"
|
3
3
|
|
4
|
+
#include "OpenGLContext.h"
|
5
|
+
|
4
6
|
#pragma clang diagnostic push
|
5
7
|
#pragma clang diagnostic ignored "-Wdocumentation"
|
6
8
|
|
@@ -14,35 +16,14 @@ namespace RNSkia {
|
|
14
16
|
|
15
17
|
sk_sp<SkSurface> OpenGLWindowContext::getSurface() {
|
16
18
|
if (_skSurface == nullptr) {
|
17
|
-
|
18
|
-
struct ReleaseContext {
|
19
|
-
std::unique_ptr<Surface> surface = nullptr;
|
20
|
-
};
|
21
|
-
|
22
|
-
auto releaseCtx = new ReleaseContext();
|
23
|
-
releaseCtx->surface = _display->makeWindowSurface(_config, _window);
|
24
|
-
_surface = releaseCtx->surface.get();
|
25
|
-
|
26
|
-
// Now make this one current
|
27
|
-
_context->makeCurrent(*releaseCtx->surface);
|
28
|
-
|
29
|
-
// Set up parameters for the render target so that it
|
30
|
-
// matches the underlying OpenGL context.
|
31
|
-
GrGLFramebufferInfo fboInfo;
|
32
|
-
|
33
|
-
// We pass 0 as the framebuffer id, since the
|
34
|
-
// underlying Skia GrGlGpu will read this when wrapping the context in the
|
35
|
-
// render target and the GrGlGpu object.
|
36
|
-
fboInfo.fFBOID = 0;
|
37
|
-
fboInfo.fFormat = 0x8058; // GL_RGBA8
|
38
|
-
|
19
|
+
_glContext->makeCurrent(_glSurface.get());
|
39
20
|
GLint stencil;
|
40
21
|
glGetIntegerv(GL_STENCIL_BITS, &stencil);
|
41
22
|
|
42
23
|
GLint samples;
|
43
24
|
glGetIntegerv(GL_SAMPLES, &samples);
|
44
25
|
|
45
|
-
auto colorType =
|
26
|
+
auto colorType = kRGBA_8888_SkColorType;
|
46
27
|
|
47
28
|
auto maxSamples =
|
48
29
|
_directContext->maxSurfaceSampleCountForColorType(colorType);
|
@@ -51,23 +32,30 @@ sk_sp<SkSurface> OpenGLWindowContext::getSurface() {
|
|
51
32
|
samples = maxSamples;
|
52
33
|
}
|
53
34
|
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
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);
|
61
47
|
_skSurface = SkSurfaces::WrapBackendRenderTarget(
|
62
|
-
_directContext,
|
63
|
-
|
64
|
-
[](void *addr) {
|
65
|
-
auto releaseCtx = reinterpret_cast<ReleaseContext *>(addr);
|
66
|
-
delete releaseCtx;
|
67
|
-
},
|
68
|
-
reinterpret_cast<void *>(releaseCtx));
|
48
|
+
_directContext.get(), backendRT, kBottomLeft_GrSurfaceOrigin,
|
49
|
+
kRGBA_8888_SkColorType, colorSpace, &surfaceProps);
|
69
50
|
}
|
70
51
|
return _skSurface;
|
71
52
|
}
|
72
53
|
|
54
|
+
void OpenGLWindowContext::present() {
|
55
|
+
_glContext->makeCurrent(_glSurface.get());
|
56
|
+
// TODO: is flushAndSubmit needed here?
|
57
|
+
_directContext->flushAndSubmit();
|
58
|
+
_glSurface->present();
|
59
|
+
}
|
60
|
+
|
73
61
|
} // namespace RNSkia
|
@@ -14,7 +14,7 @@
|
|
14
14
|
#include <unordered_map>
|
15
15
|
|
16
16
|
#include "WindowContext.h"
|
17
|
-
#include "
|
17
|
+
#include "gl/Display.h"
|
18
18
|
|
19
19
|
#pragma clang diagnostic push
|
20
20
|
#pragma clang diagnostic ignored "-Wdocumentation"
|
@@ -33,42 +33,39 @@ namespace RNSkia {
|
|
33
33
|
|
34
34
|
class OpenGLWindowContext : public WindowContext {
|
35
35
|
public:
|
36
|
-
OpenGLWindowContext(
|
37
|
-
|
38
|
-
|
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
|
+
ANativeWindow_acquire(_window);
|
42
|
+
auto config = display->chooseConfig();
|
43
|
+
_glSurface = display->makeWindowSurface(config, _window);
|
44
|
+
}
|
41
45
|
|
42
|
-
~OpenGLWindowContext() {
|
46
|
+
~OpenGLWindowContext() {
|
47
|
+
_skSurface = nullptr;
|
48
|
+
_glSurface = nullptr;
|
49
|
+
ANativeWindow_release(_window);
|
50
|
+
}
|
43
51
|
|
44
52
|
sk_sp<SkSurface> getSurface() override;
|
45
53
|
|
46
|
-
void present() override
|
47
|
-
_context->makeCurrent(*_surface);
|
48
|
-
_directContext->flushAndSubmit();
|
49
|
-
_surface->Present();
|
50
|
-
}
|
54
|
+
void present() override;
|
51
55
|
|
52
|
-
|
53
|
-
_skSurface = nullptr;
|
54
|
-
_width = width;
|
55
|
-
_height = height;
|
56
|
-
}
|
56
|
+
int getWidth() override { return ANativeWindow_getWidth(_window); };
|
57
57
|
|
58
|
-
int
|
58
|
+
int getHeight() override { return ANativeWindow_getHeight(_window); };
|
59
59
|
|
60
|
-
int
|
60
|
+
void resize(int width, int height) override { _skSurface = nullptr; }
|
61
61
|
|
62
62
|
private:
|
63
|
+
sk_sp<GrDirectContext> _directContext;
|
64
|
+
gl::Display *_display;
|
63
65
|
ANativeWindow *_window;
|
64
66
|
sk_sp<SkSurface> _skSurface = nullptr;
|
65
|
-
|
66
|
-
|
67
|
-
Surface* _surface;
|
68
|
-
Display *_display;
|
69
|
-
GrDirectContext *_directContext;
|
70
|
-
int _width = 0;
|
71
|
-
int _height = 0;
|
67
|
+
gl::Context *_glContext = nullptr;
|
68
|
+
std::unique_ptr<gl::Surface> _glSurface = nullptr;
|
72
69
|
};
|
73
70
|
|
74
71
|
} // namespace RNSkia
|
@@ -68,8 +68,8 @@ public:
|
|
68
68
|
#if defined(SK_GRAPHITE)
|
69
69
|
return DawnContext::getInstance().MakeWindow(surface, width, height);
|
70
70
|
#else
|
71
|
-
|
72
|
-
|
71
|
+
auto aWindow = reinterpret_cast<ANativeWindow *>(surface);
|
72
|
+
return OpenGLContext::getInstance().MakeWindow(aWindow, width, height);
|
73
73
|
#endif
|
74
74
|
}
|
75
75
|
|
@@ -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
|
@@ -1,9 +1,9 @@
|
|
1
1
|
#pragma once
|
2
2
|
|
3
|
-
#include "
|
4
|
-
#include "
|
3
|
+
#include "gl/Error.h"
|
4
|
+
#include "gl/Surface.h"
|
5
5
|
|
6
|
-
namespace
|
6
|
+
namespace gl {
|
7
7
|
|
8
8
|
class Surface;
|
9
9
|
class Display;
|
@@ -22,20 +22,20 @@ public:
|
|
22
22
|
|
23
23
|
const EGLContext &getHandle() const { return _context; }
|
24
24
|
|
25
|
-
bool makeCurrent(const Surface
|
25
|
+
bool makeCurrent(const Surface *surface) {
|
26
26
|
if (_context == EGL_NO_CONTEXT) {
|
27
27
|
return false;
|
28
28
|
}
|
29
29
|
const auto result =
|
30
|
-
eglMakeCurrentIfNecessary(_display, surface
|
31
|
-
surface
|
30
|
+
eglMakeCurrentIfNecessary(_display, surface->getHandle(),
|
31
|
+
surface->getHandle(), _context) == EGL_TRUE;
|
32
32
|
if (!result) {
|
33
33
|
LOG_EGL_ERROR;
|
34
34
|
}
|
35
35
|
return result;
|
36
36
|
}
|
37
37
|
|
38
|
-
bool clearCurrent()
|
38
|
+
bool clearCurrent() {
|
39
39
|
const auto result =
|
40
40
|
eglMakeCurrentIfNecessary(_display, EGL_NO_SURFACE, EGL_NO_SURFACE,
|
41
41
|
EGL_NO_CONTEXT) == EGL_TRUE;
|
@@ -74,4 +74,4 @@ private:
|
|
74
74
|
Context &operator=(const Context &) = delete;
|
75
75
|
};
|
76
76
|
|
77
|
-
} // namespace
|
77
|
+
} // namespace gl
|
@@ -5,10 +5,10 @@
|
|
5
5
|
#include "EGL/egl.h"
|
6
6
|
#include "GLES2/gl2.h"
|
7
7
|
|
8
|
-
#include "
|
9
|
-
#include "
|
8
|
+
#include "gl/Context.h"
|
9
|
+
#include "gl/Error.h"
|
10
10
|
|
11
|
-
namespace
|
11
|
+
namespace gl {
|
12
12
|
|
13
13
|
class Context;
|
14
14
|
class Surface;
|
@@ -35,7 +35,11 @@ public:
|
|
35
35
|
|
36
36
|
bool isValid() const { return _display != EGL_NO_DISPLAY; }
|
37
37
|
|
38
|
-
|
38
|
+
void clearContext() {
|
39
|
+
eglMakeCurrent(_display, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
|
40
|
+
}
|
41
|
+
|
42
|
+
EGLConfig chooseConfig() {
|
39
43
|
|
40
44
|
EGLint att[] = {EGL_RENDERABLE_TYPE,
|
41
45
|
EGL_OPENGL_ES2_BIT,
|
@@ -82,14 +86,14 @@ public:
|
|
82
86
|
}
|
83
87
|
|
84
88
|
std::unique_ptr<Surface> makeWindowSurface(const EGLConfig &config,
|
85
|
-
|
89
|
+
ANativeWindow *window) {
|
86
90
|
const EGLint attribs[] = {EGL_NONE};
|
87
91
|
auto surface = eglCreateWindowSurface(_display, config, window, attribs);
|
88
92
|
if (surface == EGL_NO_SURFACE) {
|
89
93
|
LOG_EGL_ERROR;
|
90
94
|
return nullptr;
|
91
95
|
}
|
92
|
-
return std::
|
96
|
+
return std::make_unique<Surface>(_display, surface);
|
93
97
|
}
|
94
98
|
|
95
99
|
std::unique_ptr<Surface> makePixelBufferSurface(const EGLConfig &config,
|
@@ -101,7 +105,7 @@ public:
|
|
101
105
|
LOG_EGL_ERROR;
|
102
106
|
return nullptr;
|
103
107
|
}
|
104
|
-
return std::
|
108
|
+
return std::make_unique<Surface>(_display, surface);
|
105
109
|
}
|
106
110
|
|
107
111
|
const EGLDisplay &getHandle() const { return _display; }
|
@@ -114,4 +118,4 @@ private:
|
|
114
118
|
Display &operator=(const Display &) = delete;
|
115
119
|
};
|
116
120
|
|
117
|
-
} // namespace
|
121
|
+
} // namespace gl
|
@@ -1,11 +1,14 @@
|
|
1
1
|
#pragma once
|
2
2
|
|
3
|
-
#include "
|
3
|
+
#include "gl/Error.h"
|
4
4
|
|
5
|
-
namespace
|
5
|
+
namespace gl {
|
6
6
|
|
7
7
|
class Surface {
|
8
8
|
public:
|
9
|
+
Surface(EGLDisplay display, EGLSurface surface)
|
10
|
+
: _display(display), _surface(surface) {}
|
11
|
+
|
9
12
|
~Surface() {
|
10
13
|
if (_surface != EGL_NO_SURFACE) {
|
11
14
|
if (eglDestroySurface(_display, _surface) != EGL_TRUE) {
|
@@ -18,7 +21,7 @@ public:
|
|
18
21
|
|
19
22
|
const EGLSurface &getHandle() const { return _surface; }
|
20
23
|
|
21
|
-
bool
|
24
|
+
bool present() {
|
22
25
|
const auto result = eglSwapBuffers(_display, _surface) == EGL_TRUE;
|
23
26
|
if (!result) {
|
24
27
|
LOG_EGL_ERROR;
|
@@ -32,12 +35,9 @@ private:
|
|
32
35
|
EGLDisplay _display = EGL_NO_DISPLAY;
|
33
36
|
EGLSurface _surface = EGL_NO_SURFACE;
|
34
37
|
|
35
|
-
Surface(EGLDisplay display, EGLSurface surface)
|
36
|
-
: _display(display), _surface(surface) {}
|
37
|
-
|
38
38
|
Surface(const Surface &) = delete;
|
39
39
|
|
40
40
|
Surface &operator=(const Surface &) = delete;
|
41
41
|
};
|
42
42
|
|
43
|
-
} // Namespace
|
43
|
+
} // Namespace gl
|
@@ -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();
|
package/cpp/api/JsiSkiaContext.h
CHANGED
@@ -69,6 +69,9 @@ public:
|
|
69
69
|
void *surface = reinterpret_cast<void *>(nativeBufferPointer);
|
70
70
|
auto width = static_cast<int>(arguments[1].asNumber());
|
71
71
|
auto height = static_cast<int>(arguments[2].asNumber());
|
72
|
+
if (surface == nullptr) {
|
73
|
+
throw std::runtime_error("Surface is null");
|
74
|
+
}
|
72
75
|
auto result =
|
73
76
|
context->makeContextFromNativeSurface(surface, width, height);
|
74
77
|
// Return the newly constructed object
|
@@ -77,6 +77,9 @@ bool RNSkMetalCanvasProvider::renderToCanvas(
|
|
77
77
|
// usage growing very fast in the simulator without this.
|
78
78
|
@autoreleasepool {
|
79
79
|
auto surface = _ctx->getSurface();
|
80
|
+
if (!surface) {
|
81
|
+
return false;
|
82
|
+
}
|
80
83
|
auto canvas = surface->getCanvas();
|
81
84
|
cb(canvas);
|
82
85
|
_ctx->present();
|
@@ -23,12 +23,16 @@
|
|
23
23
|
#include <TargetConditionals.h>
|
24
24
|
#if TARGET_RT_BIG_ENDIAN
|
25
25
|
#define FourCC2Str(fourcc) \
|
26
|
-
(const char[]){
|
27
|
-
|
26
|
+
(const char[]) { \
|
27
|
+
*((char *)&fourcc), *(((char *)&fourcc) + 1), *(((char *)&fourcc) + 2), \
|
28
|
+
*(((char *)&fourcc) + 3), 0 \
|
29
|
+
}
|
28
30
|
#else
|
29
31
|
#define FourCC2Str(fourcc) \
|
30
|
-
(const char[]){
|
31
|
-
|
32
|
+
(const char[]) { \
|
33
|
+
*(((char *)&fourcc) + 3), *(((char *)&fourcc) + 2), \
|
34
|
+
*(((char *)&fourcc) + 1), *(((char *)&fourcc) + 0), 0 \
|
35
|
+
}
|
32
36
|
#endif
|
33
37
|
|
34
38
|
// pragma MARK: TextureHolder
|
@@ -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
|
-
}
|
File without changes
|