@shopify/react-native-skia 1.5.7 → 1.5.8
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 +3 -1
- package/android/cpp/rnskia-android/OpenGLWindowContext.cpp +1 -1
- package/android/cpp/rnskia-android/OpenGLWindowContext.h +4 -5
- package/android/cpp/rnskia-android/RNSkAndroidPlatformContext.h +6 -0
- 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/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/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")
|
@@ -129,9 +129,11 @@ public:
|
|
129
129
|
std::unique_ptr<WindowContext> MakeWindow(ANativeWindow *window, int width,
|
130
130
|
int height) {
|
131
131
|
return std::make_unique<OpenGLWindowContext>(
|
132
|
-
_directContext, _glDisplay.get(), _glContext.get(), window);
|
132
|
+
_directContext.get(), _glDisplay.get(), _glContext.get(), window);
|
133
133
|
}
|
134
134
|
|
135
|
+
GrDirectContext *getDirectContext() { return _directContext.get(); }
|
136
|
+
|
135
137
|
private:
|
136
138
|
EGLConfig _glConfig;
|
137
139
|
std::unique_ptr<gl::Display> _glDisplay;
|
@@ -45,7 +45,7 @@ sk_sp<SkSurface> OpenGLWindowContext::getSurface() {
|
|
45
45
|
sk_sp<SkColorSpace> colorSpace(nullptr);
|
46
46
|
SkSurfaceProps surfaceProps(0, kRGB_H_SkPixelGeometry);
|
47
47
|
_skSurface = SkSurfaces::WrapBackendRenderTarget(
|
48
|
-
_directContext
|
48
|
+
_directContext, backendRT, kBottomLeft_GrSurfaceOrigin,
|
49
49
|
kRGBA_8888_SkColorType, colorSpace, &surfaceProps);
|
50
50
|
}
|
51
51
|
return _skSurface;
|
@@ -33,9 +33,8 @@ namespace RNSkia {
|
|
33
33
|
|
34
34
|
class OpenGLWindowContext : public WindowContext {
|
35
35
|
public:
|
36
|
-
OpenGLWindowContext(
|
37
|
-
gl::
|
38
|
-
ANativeWindow *window)
|
36
|
+
OpenGLWindowContext(GrDirectContext *directContext, gl::Display *display,
|
37
|
+
gl::Context *glContext, ANativeWindow *window)
|
39
38
|
: _directContext(directContext), _display(display), _glContext(glContext),
|
40
39
|
_window(window) {
|
41
40
|
ANativeWindow_acquire(_window);
|
@@ -60,11 +59,11 @@ public:
|
|
60
59
|
void resize(int width, int height) override { _skSurface = nullptr; }
|
61
60
|
|
62
61
|
private:
|
63
|
-
|
62
|
+
GrDirectContext *_directContext;
|
64
63
|
gl::Display *_display;
|
64
|
+
gl::Context *_glContext = nullptr;
|
65
65
|
ANativeWindow *_window;
|
66
66
|
sk_sp<SkSurface> _skSurface = nullptr;
|
67
|
-
gl::Context *_glContext = nullptr;
|
68
67
|
std::unique_ptr<gl::Surface> _glSurface = nullptr;
|
69
68
|
};
|
70
69
|
|
@@ -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
|
}
|
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
|
}
|
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
|