@shopify/react-native-skia 1.5.6 → 1.5.8
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 -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 +5 -1
- package/android/cpp/rnskia-android/OpenGLWindowContext.cpp +20 -49
- package/android/cpp/rnskia-android/OpenGLWindowContext.h +13 -16
- package/android/cpp/rnskia-android/RNSkAndroidPlatformContext.h +6 -0
- 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/cpp/api/JsiSkImage.h +20 -4
- package/cpp/rnskia/RNSkPlatformContext.h +4 -0
- package/cpp/rnskia/RNSkView.h +5 -2
- package/ios/RNSkia-iOS/MetalContext.h +2 -0
- package/ios/RNSkia-iOS/RNSkiOSPlatformContext.h +3 -0
- package/ios/RNSkia-iOS/RNSkiOSPlatformContext.mm +6 -0
- package/ios/RNSkia-iOS/SkiaMetalSurfaceFactory.h +2 -2
- package/package.json +1 -1
- package/react-native-skia.podspec +2 -2
- package/src/renderer/__tests__/e2e/Image.spec.tsx +2 -64
- package/src/skia/__tests__/assets/oslo-mini.jpg +0 -0
- package/android/src/paper/java/com/facebook/react/viewmanagers/SkiaDrawViewManagerInterface.java +0 -18
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")
|
@@ -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,11 +125,15 @@ 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.get(), _glDisplay.get(), _glContext.get(), window);
|
131
133
|
}
|
132
134
|
|
135
|
+
GrDirectContext *getDirectContext() { return _directContext.get(); }
|
136
|
+
|
133
137
|
private:
|
134
138
|
EGLConfig _glConfig;
|
135
139
|
std::unique_ptr<gl::Display> _glDisplay;
|
@@ -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, 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,15 @@
|
|
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(GrDirectContext *directContext, gl::Display *display,
|
37
|
+
gl::Context *glContext, ANativeWindow *window)
|
38
|
+
: _directContext(directContext), _display(display), _glContext(glContext),
|
39
|
+
_window(window) {
|
41
40
|
ANativeWindow_acquire(_window);
|
41
|
+
auto config = display->chooseConfig();
|
42
|
+
_glSurface = display->makeWindowSurface(config, _window);
|
42
43
|
}
|
43
44
|
|
44
45
|
~OpenGLWindowContext() {
|
@@ -51,23 +52,19 @@ public:
|
|
51
52
|
|
52
53
|
void present() override;
|
53
54
|
|
54
|
-
|
55
|
-
_skSurface = nullptr;
|
56
|
-
_width = width;
|
57
|
-
_height = height;
|
58
|
-
}
|
55
|
+
int getWidth() override { return ANativeWindow_getWidth(_window); };
|
59
56
|
|
60
|
-
int
|
57
|
+
int getHeight() override { return ANativeWindow_getHeight(_window); };
|
61
58
|
|
62
|
-
int
|
59
|
+
void resize(int width, int height) override { _skSurface = nullptr; }
|
63
60
|
|
64
61
|
private:
|
65
|
-
|
62
|
+
GrDirectContext *_directContext;
|
63
|
+
gl::Display *_display;
|
64
|
+
gl::Context *_glContext = nullptr;
|
66
65
|
ANativeWindow *_window;
|
67
66
|
sk_sp<SkSurface> _skSurface = nullptr;
|
68
|
-
gl::Surface
|
69
|
-
int _width = 0;
|
70
|
-
int _height = 0;
|
67
|
+
std::unique_ptr<gl::Surface> _glSurface = nullptr;
|
71
68
|
};
|
72
69
|
|
73
70
|
} // namespace RNSkia
|
@@ -152,6 +152,12 @@ public:
|
|
152
152
|
#endif
|
153
153
|
}
|
154
154
|
|
155
|
+
#if !defined(SK_GRAPHITE)
|
156
|
+
GrDirectContext *getDirectContext() override {
|
157
|
+
return OpenGLContext::getInstance().getDirectContext();
|
158
|
+
}
|
159
|
+
#endif
|
160
|
+
|
155
161
|
sk_sp<SkFontMgr> createFontMgr() override {
|
156
162
|
return SkFontMgr_New_Android(nullptr);
|
157
163
|
}
|
@@ -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();
|
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));
|
@@ -147,6 +147,10 @@ public:
|
|
147
147
|
*/
|
148
148
|
virtual sk_sp<SkImage> makeImageFromNativeBuffer(void *buffer) = 0;
|
149
149
|
|
150
|
+
#if !defined(SK_GRAPHITE)
|
151
|
+
virtual GrDirectContext *getDirectContext() = 0;
|
152
|
+
#endif
|
153
|
+
|
150
154
|
virtual void releaseNativeBuffer(uint64_t pointer) = 0;
|
151
155
|
|
152
156
|
virtual uint64_t makeNativeBuffer(sk_sp<SkImage> image) = 0;
|
package/cpp/rnskia/RNSkView.h
CHANGED
@@ -90,7 +90,8 @@ public:
|
|
90
90
|
RNSkOffscreenCanvasProvider(std::shared_ptr<RNSkPlatformContext> context,
|
91
91
|
std::function<void()> requestRedraw, float width,
|
92
92
|
float height)
|
93
|
-
: RNSkCanvasProvider(requestRedraw),
|
93
|
+
: RNSkCanvasProvider(requestRedraw), _context(context), _width(width),
|
94
|
+
_height(height) {
|
94
95
|
_surface = context->makeOffscreenSurface(_width, _height);
|
95
96
|
_pd = context->getPixelDensity();
|
96
97
|
}
|
@@ -113,7 +114,8 @@ public:
|
|
113
114
|
_surface->recorder()->snap().get());
|
114
115
|
return DawnContext::getInstance().MakeRasterImage(image);
|
115
116
|
#else
|
116
|
-
|
117
|
+
auto grContext = _context->getDirectContext();
|
118
|
+
return image->makeRasterImage(grContext);
|
117
119
|
#endif
|
118
120
|
}
|
119
121
|
|
@@ -140,6 +142,7 @@ private:
|
|
140
142
|
float _height;
|
141
143
|
float _pd = 1.0f;
|
142
144
|
sk_sp<SkSurface> _surface;
|
145
|
+
std::shared_ptr<RNSkPlatformContext> _context;
|
143
146
|
};
|
144
147
|
|
145
148
|
enum RNSkDrawingMode { Default, Continuous };
|
@@ -76,6 +76,9 @@ public:
|
|
76
76
|
|
77
77
|
void raiseError(const std::exception &err) override;
|
78
78
|
sk_sp<SkSurface> makeOffscreenSurface(int width, int height) override;
|
79
|
+
#if !defined(SK_GRAPHITE)
|
80
|
+
GrDirectContext *getDirectContext() override;
|
81
|
+
#endif
|
79
82
|
sk_sp<SkFontMgr> createFontMgr() override;
|
80
83
|
|
81
84
|
void willInvalidateModules() {
|
@@ -192,6 +192,12 @@ sk_sp<SkImage> RNSkiOSPlatformContext::makeImageFromNativeBuffer(void *buffer) {
|
|
192
192
|
#endif
|
193
193
|
}
|
194
194
|
|
195
|
+
#if !defined(SK_GRAPHITE)
|
196
|
+
GrDirectContext *RNSkiOSPlatformContext::getDirectContext() {
|
197
|
+
return MetalContext::getInstance().getDirectContext();
|
198
|
+
}
|
199
|
+
#endif
|
200
|
+
|
195
201
|
sk_sp<SkFontMgr> RNSkiOSPlatformContext::createFontMgr() {
|
196
202
|
return SkFontMgr_New_CoreText(nullptr);
|
197
203
|
}
|
@@ -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.8",
|
11
11
|
"description": "High-performance React Native Graphics using Skia",
|
12
12
|
"main": "lib/module/index.js",
|
13
13
|
"react-native": "src/index.ts",
|
@@ -9,8 +9,8 @@ use_graphite = ENV['SK_GRAPHITE'] == '1'
|
|
9
9
|
|
10
10
|
# Set preprocessor definitions based on GRAPHITE flag
|
11
11
|
preprocessor_defs = use_graphite ?
|
12
|
-
'$(inherited) SK_GRAPHITE=1' :
|
13
|
-
'$(inherited) SK_METAL=1 SK_GANESH=1'
|
12
|
+
'$(inherited) SK_GRAPHITE=1 SK_IMAGE_READ_PIXELS_DISABLE_LEGACY_API=1' :
|
13
|
+
'$(inherited) SK_METAL=1 SK_GANESH=1 SK_IMAGE_READ_PIXELS_DISABLE_LEGACY_API=1'
|
14
14
|
|
15
15
|
# Define base frameworks
|
16
16
|
base_frameworks = ['libs/ios/libskia.xcframework',
|
@@ -43,51 +43,17 @@ describe("Image loading from bundles", () => {
|
|
43
43
|
},
|
44
44
|
{
|
45
45
|
data: Array.from(
|
46
|
-
loadImage("skia/__tests__/assets/oslo.jpg").encodeToBytes()
|
46
|
+
loadImage("skia/__tests__/assets/oslo-mini.jpg").encodeToBytes()
|
47
47
|
),
|
48
48
|
}
|
49
49
|
);
|
50
50
|
expect(pixels).toBeDefined();
|
51
51
|
expect(pixels).toEqual([
|
52
|
-
|
52
|
+
171, 188, 198, 255, 171, 188, 198, 255, 171, 188, 198, 255, 171, 188, 198,
|
53
53
|
255,
|
54
54
|
]);
|
55
55
|
});
|
56
56
|
|
57
|
-
// it("should read pixels from an image using a preallocated buffer", async () => {
|
58
|
-
// const pixels = await surface.eval(
|
59
|
-
// (Skia, { colorType, alphaType, data }) => {
|
60
|
-
// const image = Skia.Image.MakeImageFromEncoded(
|
61
|
-
// Skia.Data.fromBytes(new Uint8Array(data))
|
62
|
-
// )!;
|
63
|
-
// const result = new Uint8Array(16);
|
64
|
-
// image.readPixels(
|
65
|
-
// 0,
|
66
|
-
// 0,
|
67
|
-
// {
|
68
|
-
// width: 2,
|
69
|
-
// height: 2,
|
70
|
-
// colorType,
|
71
|
-
// alphaType,
|
72
|
-
// },
|
73
|
-
// result
|
74
|
-
// );
|
75
|
-
// return result;
|
76
|
-
// },
|
77
|
-
// {
|
78
|
-
// colorType: ColorType.RGBA_8888,
|
79
|
-
// alphaType: AlphaType.Unpremul,
|
80
|
-
// data: Array.from(
|
81
|
-
// loadImage("skia/__tests__/assets/oslo.jpg").encodeToBytes()
|
82
|
-
// ),
|
83
|
-
// }
|
84
|
-
// );
|
85
|
-
// expect(pixels).toBeDefined();
|
86
|
-
// expect(Array.from(pixels!)).toEqual([
|
87
|
-
// 170, 186, 199, 255, 170, 186, 199, 255, 170, 186, 199, 255, 170, 186, 199,
|
88
|
-
// 255,
|
89
|
-
// ]);
|
90
|
-
// });
|
91
57
|
it("should read pixels from a canvas", async () => {
|
92
58
|
const pixels = await surface.eval(
|
93
59
|
(Skia, { colorType, alphaType }) => {
|
@@ -108,32 +74,4 @@ describe("Image loading from bundles", () => {
|
|
108
74
|
expect(pixels).toBeDefined();
|
109
75
|
expect(Array.from(pixels!)).toEqual([255, 0, 0, 255]);
|
110
76
|
});
|
111
|
-
// it("should read pixels from a canvas using a preallocated buffer", async () => {
|
112
|
-
// const pixels = await surface.eval(
|
113
|
-
// (Skia, { colorType, alphaType }) => {
|
114
|
-
// const offscreen = Skia.Surface.MakeOffscreen(10, 10)!;
|
115
|
-
// const canvas = offscreen.getCanvas();
|
116
|
-
// canvas.drawColor(Skia.Color("red"));
|
117
|
-
// const result = new Uint8Array(4);
|
118
|
-
// canvas.readPixels(0, 0, {
|
119
|
-
// width: 1,
|
120
|
-
// height: 1,
|
121
|
-
// colorType,
|
122
|
-
// alphaType,
|
123
|
-
// }, result);
|
124
|
-
// },
|
125
|
-
// { colorType: ColorType.RGBA_8888, alphaType: AlphaType.Unpremul }
|
126
|
-
// );
|
127
|
-
// expect(pixels).toBeDefined();
|
128
|
-
// expect(Array.from(pixels!)).toEqual([255, 0, 0, 255]);
|
129
|
-
// });
|
130
|
-
// This test should only run on CI because it will trigger a redbox.
|
131
|
-
// While this is fine on CI, it is undesirable on local dev.
|
132
|
-
// it("should not crash with an invalid viewTag", async () => {
|
133
|
-
// const result = await surface.eval((Skia) => {
|
134
|
-
// Skia.Image.MakeImageFromViewTag(-1);
|
135
|
-
// return true;
|
136
|
-
// });
|
137
|
-
// expect(result).toBe(true);
|
138
|
-
// });
|
139
77
|
});
|
Binary file
|
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
|
-
}
|