@shopify/react-native-skia 1.5.5 → 1.5.6
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/rnskia-android/OpenGLContext.h +27 -23
- package/android/cpp/rnskia-android/OpenGLWindowContext.cpp +26 -9
- package/android/cpp/rnskia-android/OpenGLWindowContext.h +16 -17
- package/android/cpp/rnskia-android/RNSkAndroidPlatformContext.h +2 -2
- package/android/cpp/rnskia-android/{opengl → gl}/Context.h +8 -8
- package/android/cpp/rnskia-android/{opengl → gl}/Display.h +8 -8
- package/android/cpp/rnskia-android/{opengl → gl}/Error.cpp +1 -1
- package/android/cpp/rnskia-android/{opengl → gl}/Surface.h +7 -7
- package/cpp/api/JsiSkiaContext.h +3 -0
- package/ios/RNSkia-iOS/RNSkMetalCanvasProvider.mm +3 -0
- package/ios/RNSkia-iOS/SkiaCVPixelBufferUtils.mm +8 -4
- package/package.json +1 -1
- /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"
|
@@ -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,24 @@ public:
|
|
121
125
|
#endif
|
122
126
|
}
|
123
127
|
|
124
|
-
std::unique_ptr<
|
125
|
-
|
126
|
-
return std::make_unique<
|
127
|
-
_config, _display.get(), _ctx.get(), _directContext.get(), window,
|
128
|
-
width, height);
|
128
|
+
std::unique_ptr<WindowContext> MakeWindow(ANativeWindow *window, int width,
|
129
|
+
int height) {
|
130
|
+
return std::make_unique<OpenGLWindowContext>(this, window, width, height);
|
129
131
|
}
|
130
132
|
|
131
133
|
private:
|
132
|
-
EGLConfig
|
133
|
-
std::unique_ptr<
|
134
|
-
std::unique_ptr<
|
135
|
-
std::unique_ptr<
|
134
|
+
EGLConfig _glConfig;
|
135
|
+
std::unique_ptr<gl::Display> _glDisplay;
|
136
|
+
std::unique_ptr<gl::Context> _glContext;
|
137
|
+
std::unique_ptr<gl::Surface> _glSurface;
|
136
138
|
sk_sp<GrDirectContext> _directContext;
|
137
139
|
|
138
140
|
OpenGLContext() {
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
141
|
+
_glDisplay = std::make_unique<gl::Display>();
|
142
|
+
_glConfig = _glDisplay->chooseConfig();
|
143
|
+
_glContext = _glDisplay->makeContext(_glConfig, nullptr);
|
144
|
+
_glSurface = _glDisplay->makePixelBufferSurface(_glConfig, 1, 1);
|
145
|
+
_glContext->makeCurrent(_glSurface.get());
|
144
146
|
auto backendInterface = GrGLMakeNativeInterface();
|
145
147
|
_directContext = GrDirectContexts::MakeGL(backendInterface);
|
146
148
|
|
@@ -149,3 +151,5 @@ private:
|
|
149
151
|
}
|
150
152
|
}
|
151
153
|
};
|
154
|
+
|
155
|
+
} // 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
|
|
@@ -16,15 +18,25 @@ sk_sp<SkSurface> OpenGLWindowContext::getSurface() {
|
|
16
18
|
if (_skSurface == nullptr) {
|
17
19
|
|
18
20
|
struct ReleaseContext {
|
19
|
-
std::unique_ptr<Surface> surface = nullptr;
|
21
|
+
std::unique_ptr<gl::Surface> surface = nullptr;
|
20
22
|
};
|
21
23
|
|
24
|
+
if (!_window) {
|
25
|
+
throw std::runtime_error("No native window provided");
|
26
|
+
}
|
22
27
|
auto releaseCtx = new ReleaseContext();
|
23
|
-
releaseCtx->surface =
|
24
|
-
|
25
|
-
|
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
|
+
|
26
35
|
// Now make this one current
|
27
|
-
_context->makeCurrent(
|
36
|
+
auto success = _context->_glContext->makeCurrent(releaseCtx->surface.get());
|
37
|
+
if (!success) {
|
38
|
+
throw std::runtime_error("Failed to make window surface current");
|
39
|
+
}
|
28
40
|
|
29
41
|
// Set up parameters for the render target so that it
|
30
42
|
// matches the underlying OpenGL context.
|
@@ -45,7 +57,7 @@ sk_sp<SkSurface> OpenGLWindowContext::getSurface() {
|
|
45
57
|
auto colorType = kN32_SkColorType;
|
46
58
|
|
47
59
|
auto maxSamples =
|
48
|
-
_directContext->maxSurfaceSampleCountForColorType(colorType);
|
60
|
+
_context->_directContext->maxSurfaceSampleCountForColorType(colorType);
|
49
61
|
|
50
62
|
if (samples > maxSamples) {
|
51
63
|
samples = maxSamples;
|
@@ -56,11 +68,10 @@ sk_sp<SkSurface> OpenGLWindowContext::getSurface() {
|
|
56
68
|
|
57
69
|
SkSurfaceProps props(0, kUnknown_SkPixelGeometry);
|
58
70
|
|
59
|
-
|
60
71
|
// Create surface object
|
61
72
|
_skSurface = SkSurfaces::WrapBackendRenderTarget(
|
62
|
-
_directContext, renderTarget,
|
63
|
-
nullptr, &props,
|
73
|
+
_context->_directContext.get(), renderTarget,
|
74
|
+
kBottomLeft_GrSurfaceOrigin, colorType, nullptr, &props,
|
64
75
|
[](void *addr) {
|
65
76
|
auto releaseCtx = reinterpret_cast<ReleaseContext *>(addr);
|
66
77
|
delete releaseCtx;
|
@@ -70,4 +81,10 @@ sk_sp<SkSurface> OpenGLWindowContext::getSurface() {
|
|
70
81
|
return _skSurface;
|
71
82
|
}
|
72
83
|
|
84
|
+
void OpenGLWindowContext::present() {
|
85
|
+
_context->_glContext->makeCurrent(_glSurface);
|
86
|
+
_context->_directContext->flushAndSubmit();
|
87
|
+
_glSurface->present();
|
88
|
+
}
|
89
|
+
|
73
90
|
} // 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"
|
@@ -31,23 +31,25 @@
|
|
31
31
|
|
32
32
|
namespace RNSkia {
|
33
33
|
|
34
|
+
class OpenGLContext;
|
35
|
+
|
34
36
|
class OpenGLWindowContext : public WindowContext {
|
35
37
|
public:
|
36
|
-
OpenGLWindowContext(
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
38
|
+
OpenGLWindowContext(OpenGLContext *context, ANativeWindow *window, int width,
|
39
|
+
int height)
|
40
|
+
: _context(context), _window(window), _width(width), _height(height) {
|
41
|
+
ANativeWindow_acquire(_window);
|
42
|
+
}
|
41
43
|
|
42
|
-
~OpenGLWindowContext() {
|
44
|
+
~OpenGLWindowContext() {
|
45
|
+
_skSurface = nullptr;
|
46
|
+
_glSurface = nullptr;
|
47
|
+
ANativeWindow_release(_window);
|
48
|
+
}
|
43
49
|
|
44
50
|
sk_sp<SkSurface> getSurface() override;
|
45
51
|
|
46
|
-
void present() override
|
47
|
-
_context->makeCurrent(*_surface);
|
48
|
-
_directContext->flushAndSubmit();
|
49
|
-
_surface->Present();
|
50
|
-
}
|
52
|
+
void present() override;
|
51
53
|
|
52
54
|
void resize(int width, int height) override {
|
53
55
|
_skSurface = nullptr;
|
@@ -60,13 +62,10 @@ public:
|
|
60
62
|
int getHeight() override { return _height; };
|
61
63
|
|
62
64
|
private:
|
65
|
+
OpenGLContext *_context;
|
63
66
|
ANativeWindow *_window;
|
64
67
|
sk_sp<SkSurface> _skSurface = nullptr;
|
65
|
-
|
66
|
-
Context *_context;
|
67
|
-
Surface* _surface;
|
68
|
-
Display *_display;
|
69
|
-
GrDirectContext *_directContext;
|
68
|
+
gl::Surface *_glSurface = nullptr;
|
70
69
|
int _width = 0;
|
71
70
|
int _height = 0;
|
72
71
|
};
|
@@ -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
|
|
@@ -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,7 @@ public:
|
|
35
35
|
|
36
36
|
bool isValid() const { return _display != EGL_NO_DISPLAY; }
|
37
37
|
|
38
|
-
EGLConfig chooseConfig()
|
38
|
+
EGLConfig chooseConfig() {
|
39
39
|
|
40
40
|
EGLint att[] = {EGL_RENDERABLE_TYPE,
|
41
41
|
EGL_OPENGL_ES2_BIT,
|
@@ -82,14 +82,14 @@ public:
|
|
82
82
|
}
|
83
83
|
|
84
84
|
std::unique_ptr<Surface> makeWindowSurface(const EGLConfig &config,
|
85
|
-
|
85
|
+
ANativeWindow *window) {
|
86
86
|
const EGLint attribs[] = {EGL_NONE};
|
87
87
|
auto surface = eglCreateWindowSurface(_display, config, window, attribs);
|
88
88
|
if (surface == EGL_NO_SURFACE) {
|
89
89
|
LOG_EGL_ERROR;
|
90
90
|
return nullptr;
|
91
91
|
}
|
92
|
-
return std::
|
92
|
+
return std::make_unique<Surface>(_display, surface);
|
93
93
|
}
|
94
94
|
|
95
95
|
std::unique_ptr<Surface> makePixelBufferSurface(const EGLConfig &config,
|
@@ -101,7 +101,7 @@ public:
|
|
101
101
|
LOG_EGL_ERROR;
|
102
102
|
return nullptr;
|
103
103
|
}
|
104
|
-
return std::
|
104
|
+
return std::make_unique<Surface>(_display, surface);
|
105
105
|
}
|
106
106
|
|
107
107
|
const EGLDisplay &getHandle() const { return _display; }
|
@@ -114,4 +114,4 @@ private:
|
|
114
114
|
Display &operator=(const Display &) = delete;
|
115
115
|
};
|
116
116
|
|
117
|
-
} // namespace
|
117
|
+
} // 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
|
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
|
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.6",
|
11
11
|
"description": "High-performance React Native Graphics using Skia",
|
12
12
|
"main": "lib/module/index.js",
|
13
13
|
"react-native": "src/index.ts",
|
File without changes
|