@shopify/react-native-skia 1.7.0 → 1.7.2
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/cpp/jni/include/JniSkiaBaseView.h +2 -2
- package/android/cpp/rnskia-android/GrAHardwareBufferUtils.cpp +14 -14
- package/android/cpp/rnskia-android/MainThreadDispatcher.h +2 -2
- package/android/cpp/rnskia-android/OpenGLContext.h +11 -5
- package/android/cpp/rnskia-android/OpenGLWindowContext.h +1 -1
- package/android/cpp/rnskia-android/RNSkAndroidPlatformContext.h +8 -10
- package/android/cpp/rnskia-android/RNSkAndroidVideo.cpp +1 -1
- package/android/cpp/rnskia-android/RNSkAndroidVideo.h +1 -1
- package/android/cpp/rnskia-android/RNSkOpenGLCanvasProvider.cpp +3 -3
- package/android/src/main/java/com/shopify/reactnative/skia/SkiaBaseView.java +0 -13
- package/android/src/main/java/com/shopify/reactnative/skia/SkiaTextureView.java +2 -31
- package/cpp/api/JsiSkApi.h +1 -1
- package/cpp/api/JsiSkCanvas.h +1 -1
- package/cpp/api/JsiSkColor.h +2 -2
- package/cpp/api/third_party/CSSColorParser.h +1 -1
- package/cpp/api/third_party/base64.cpp +4 -4
- package/cpp/rnskia/RNSkManager.cpp +1 -1
- package/cpp/rnskia/RNSkPlatformContext.h +0 -1
- package/ios/RNSkia-iOS/RNSkiOSPlatformContext.h +0 -4
- package/ios/RNSkia-iOS/SkiaDomView.mm +3 -3
- package/ios/RNSkia-iOS/SkiaDomViewManager.mm +2 -1
- package/ios/RNSkia-iOS/SkiaManager.h +6 -0
- package/ios/RNSkia-iOS/SkiaManager.mm +17 -0
- package/ios/RNSkia-iOS/SkiaPictureView.mm +3 -3
- package/ios/RNSkia-iOS/SkiaPictureViewManager.mm +2 -1
- package/ios/RNSkia-iOS/SkiaUIView.h +0 -1
- package/ios/RNSkia-iOS/SkiaUIView.mm +1 -7
- package/package.json +1 -1
@@ -20,9 +20,9 @@ class JniSkiaBaseView {
|
|
20
20
|
public:
|
21
21
|
JniSkiaBaseView(jni::alias_ref<JniSkiaManager::javaobject> skiaManager,
|
22
22
|
std::shared_ptr<RNSkBaseAndroidView> skiaView)
|
23
|
-
: _manager(skiaManager->cthis()), _skiaAndroidView(skiaView) {}
|
23
|
+
: _manager(skiaManager->cthis()), _skiaAndroidView(std::move(skiaView)) {}
|
24
24
|
|
25
|
-
~JniSkiaBaseView()
|
25
|
+
~JniSkiaBaseView() = default;
|
26
26
|
|
27
27
|
std::shared_ptr<RNSkManager> getSkiaManager() {
|
28
28
|
return _manager->getSkiaManager();
|
@@ -41,7 +41,7 @@ GrBackendFormat GetGLBackendFormat(GrDirectContext *dContext,
|
|
41
41
|
bool requireKnownFormat) {
|
42
42
|
GrBackendApi backend = dContext->backend();
|
43
43
|
if (backend != GrBackendApi::kOpenGL) {
|
44
|
-
return
|
44
|
+
return {};
|
45
45
|
}
|
46
46
|
switch (bufferFormat) {
|
47
47
|
// TODO: find out if we can detect, which graphic buffers support
|
@@ -63,7 +63,7 @@ GrBackendFormat GetGLBackendFormat(GrDirectContext *dContext,
|
|
63
63
|
#endif
|
64
64
|
default:
|
65
65
|
if (requireKnownFormat) {
|
66
|
-
return
|
66
|
+
return {};
|
67
67
|
} else {
|
68
68
|
return GrBackendFormats::MakeGL(GR_GL_RGBA8, GR_GL_TEXTURE_EXTERNAL);
|
69
69
|
}
|
@@ -110,12 +110,12 @@ void GLTextureHelper::rebind(GrDirectContext *dContext) {
|
|
110
110
|
}
|
111
111
|
|
112
112
|
void delete_gl_texture(void *context) {
|
113
|
-
|
113
|
+
auto cleanupHelper = static_cast<GLTextureHelper *>(context);
|
114
114
|
delete cleanupHelper;
|
115
115
|
}
|
116
116
|
|
117
117
|
void update_gl_texture(void *context, GrDirectContext *dContext) {
|
118
|
-
|
118
|
+
auto cleanupHelper = static_cast<GLTextureHelper *>(context);
|
119
119
|
cleanupHelper->rebind(dContext);
|
120
120
|
}
|
121
121
|
|
@@ -127,13 +127,13 @@ static GrBackendTexture make_gl_backend_texture(
|
|
127
127
|
while (GL_NO_ERROR != glGetError()) {
|
128
128
|
} // clear GL errors
|
129
129
|
|
130
|
-
|
130
|
+
auto eglGetNativeClientBufferANDROID =
|
131
131
|
(EGLGetNativeClientBufferANDROIDProc)eglGetProcAddress(
|
132
132
|
"eglGetNativeClientBufferANDROID");
|
133
133
|
if (!eglGetNativeClientBufferANDROID) {
|
134
134
|
RNSkLogger::logToConsole(
|
135
135
|
"Failed to get the eglGetNativeClientBufferAndroid proc");
|
136
|
-
return
|
136
|
+
return {};
|
137
137
|
}
|
138
138
|
|
139
139
|
EGLClientBuffer clientBuffer =
|
@@ -149,14 +149,14 @@ static GrBackendTexture make_gl_backend_texture(
|
|
149
149
|
if (EGL_NO_IMAGE_KHR == image) {
|
150
150
|
SkDebugf("Could not create EGL image, err = (%#x)",
|
151
151
|
static_cast<int>(eglGetError()));
|
152
|
-
return
|
152
|
+
return {};
|
153
153
|
}
|
154
154
|
|
155
155
|
GrGLuint texID;
|
156
156
|
glGenTextures(1, &texID);
|
157
157
|
if (!texID) {
|
158
158
|
eglDestroyImageKHR(display, image);
|
159
|
-
return
|
159
|
+
return {};
|
160
160
|
}
|
161
161
|
|
162
162
|
GrGLuint target = isRenderable ? GR_GL_TEXTURE_2D : GR_GL_TEXTURE_EXTERNAL;
|
@@ -167,7 +167,7 @@ static GrBackendTexture make_gl_backend_texture(
|
|
167
167
|
SkDebugf("glBindTexture failed (%#x)", static_cast<int>(status));
|
168
168
|
glDeleteTextures(1, &texID);
|
169
169
|
eglDestroyImageKHR(display, image);
|
170
|
-
return
|
170
|
+
return {};
|
171
171
|
}
|
172
172
|
glEGLImageTargetTexture2DOES(target, image);
|
173
173
|
if ((status = glGetError()) != GL_NO_ERROR) {
|
@@ -175,7 +175,7 @@ static GrBackendTexture make_gl_backend_texture(
|
|
175
175
|
static_cast<int>(status));
|
176
176
|
glDeleteTextures(1, &texID);
|
177
177
|
eglDestroyImageKHR(display, image);
|
178
|
-
return
|
178
|
+
return {};
|
179
179
|
}
|
180
180
|
dContext->resetContext(kTextureBinding_GrGLBackendState);
|
181
181
|
|
@@ -223,16 +223,16 @@ MakeGLBackendTexture(GrDirectContext *dContext, AHardwareBuffer *hardwareBuffer,
|
|
223
223
|
bool isProtectedContent,
|
224
224
|
const GrBackendFormat &backendFormat, bool isRenderable) {
|
225
225
|
SkASSERT(dContext);
|
226
|
-
if (
|
227
|
-
return
|
226
|
+
if (dContext->abandoned()) {
|
227
|
+
return {};
|
228
228
|
}
|
229
229
|
|
230
230
|
if (GrBackendApi::kOpenGL != dContext->backend()) {
|
231
|
-
return
|
231
|
+
return {};
|
232
232
|
}
|
233
233
|
|
234
234
|
if (isProtectedContent && !can_import_protected_content(dContext)) {
|
235
|
-
return
|
235
|
+
return {};
|
236
236
|
}
|
237
237
|
|
238
238
|
return make_gl_backend_texture(
|
@@ -117,17 +117,23 @@ public:
|
|
117
117
|
// GR_GL_TEXTURE_2D
|
118
118
|
case AHARDWAREBUFFER_FORMAT_R8G8B8A8_UNORM:
|
119
119
|
format = GrBackendFormats::MakeGL(GR_GL_RGBA8, GR_GL_TEXTURE_EXTERNAL);
|
120
|
+
break;
|
120
121
|
case AHARDWAREBUFFER_FORMAT_R16G16B16A16_FLOAT:
|
121
122
|
format = GrBackendFormats::MakeGL(GR_GL_RGBA16F, GR_GL_TEXTURE_EXTERNAL);
|
123
|
+
break;
|
122
124
|
case AHARDWAREBUFFER_FORMAT_R5G6B5_UNORM:
|
123
|
-
|
125
|
+
GrBackendFormats::MakeGL(GR_GL_RGB565, GR_GL_TEXTURE_EXTERNAL);
|
126
|
+
break;
|
124
127
|
case AHARDWAREBUFFER_FORMAT_R10G10B10A2_UNORM:
|
125
128
|
format = GrBackendFormats::MakeGL(GR_GL_RGB10_A2, GR_GL_TEXTURE_EXTERNAL);
|
129
|
+
break;
|
126
130
|
case AHARDWAREBUFFER_FORMAT_R8G8B8_UNORM:
|
127
131
|
format = GrBackendFormats::MakeGL(GR_GL_RGB8, GR_GL_TEXTURE_EXTERNAL);
|
132
|
+
break;
|
128
133
|
#if __ANDROID_API__ >= 33
|
129
134
|
case AHARDWAREBUFFER_FORMAT_R8_UNORM:
|
130
135
|
format = GrBackendFormats::MakeGL(GR_GL_R8, GR_GL_TEXTURE_EXTERNAL);
|
136
|
+
break;
|
131
137
|
#endif
|
132
138
|
default:
|
133
139
|
if (requireKnownFormat) {
|
@@ -136,10 +142,11 @@ public:
|
|
136
142
|
format = GrBackendFormats::MakeGL(GR_GL_RGBA8, GR_GL_TEXTURE_EXTERNAL);
|
137
143
|
}
|
138
144
|
}
|
139
|
-
|
145
|
+
auto width = static_cast<int>(description.width);
|
146
|
+
auto height = static_cast<int>(description.height);
|
140
147
|
auto backendTex = MakeGLBackendTexture(
|
141
148
|
_directContext.get(), const_cast<AHardwareBuffer *>(hardwareBuffer),
|
142
|
-
|
149
|
+
width, height, &deleteImageProc,
|
143
150
|
&updateImageProc, &deleteImageCtx, false, format, false);
|
144
151
|
if (!backendTex.isValid()) {
|
145
152
|
RNSkLogger::logToConsole(
|
@@ -159,8 +166,7 @@ public:
|
|
159
166
|
}
|
160
167
|
|
161
168
|
// TODO: remove width, height
|
162
|
-
std::unique_ptr<WindowContext> MakeWindow(ANativeWindow *window
|
163
|
-
int height) {
|
169
|
+
std::unique_ptr<WindowContext> MakeWindow(ANativeWindow *window) {
|
164
170
|
auto display = OpenGLSharedContext::getInstance().getDisplay();
|
165
171
|
return std::make_unique<OpenGLWindowContext>(
|
166
172
|
_directContext.get(), display, _glContext.get(), window,
|
@@ -1,6 +1,5 @@
|
|
1
1
|
#pragma once
|
2
2
|
|
3
|
-
// TODO: Add android flags
|
4
3
|
#if __ANDROID_API__ >= 26
|
5
4
|
#include <android/hardware_buffer.h>
|
6
5
|
#endif
|
@@ -28,18 +27,17 @@
|
|
28
27
|
#pragma clang diagnostic pop
|
29
28
|
|
30
29
|
namespace RNSkia {
|
31
|
-
namespace jsi = facebook::jsi;
|
32
30
|
|
33
31
|
class RNSkAndroidPlatformContext : public RNSkPlatformContext {
|
34
32
|
public:
|
35
33
|
RNSkAndroidPlatformContext(
|
36
34
|
JniPlatformContext *jniPlatformContext,
|
37
35
|
std::shared_ptr<facebook::react::CallInvoker> jsCallInvoker)
|
38
|
-
: RNSkPlatformContext(jsCallInvoker,
|
36
|
+
: RNSkPlatformContext(std::move(jsCallInvoker),
|
39
37
|
jniPlatformContext->getPixelDensity()),
|
40
38
|
_jniPlatformContext(jniPlatformContext) {}
|
41
39
|
|
42
|
-
~RNSkAndroidPlatformContext()
|
40
|
+
~RNSkAndroidPlatformContext() override = default;
|
43
41
|
|
44
42
|
void performStreamOperation(
|
45
43
|
const std::string &sourceUri,
|
@@ -65,7 +63,7 @@ public:
|
|
65
63
|
return DawnContext::getInstance().MakeWindow(surface, width, height);
|
66
64
|
#else
|
67
65
|
auto aWindow = reinterpret_cast<ANativeWindow *>(surface);
|
68
|
-
return OpenGLContext::getInstance().MakeWindow(aWindow
|
66
|
+
return OpenGLContext::getInstance().MakeWindow(aWindow);
|
69
67
|
#endif
|
70
68
|
}
|
71
69
|
|
@@ -89,7 +87,7 @@ public:
|
|
89
87
|
|
90
88
|
OpenGLContext::getInstance().makeCurrent();
|
91
89
|
if (glIsTexture(textureInfo.fID) == GL_FALSE) {
|
92
|
-
throw
|
90
|
+
throw std::runtime_error("Invalid textureInfo");
|
93
91
|
}
|
94
92
|
|
95
93
|
GrBackendTexture backendTexture = GrBackendTextures::MakeGL(
|
@@ -109,7 +107,7 @@ public:
|
|
109
107
|
|
110
108
|
void releaseNativeBuffer(uint64_t pointer) override {
|
111
109
|
#if __ANDROID_API__ >= 26
|
112
|
-
|
110
|
+
auto *buffer = reinterpret_cast<AHardwareBuffer *>(pointer);
|
113
111
|
AHardwareBuffer_release(buffer);
|
114
112
|
#endif
|
115
113
|
}
|
@@ -178,16 +176,16 @@ public:
|
|
178
176
|
if (!SkImages::GetBackendTextureFromImage(image, &texture, true)) {
|
179
177
|
throw std::runtime_error("Couldn't get backend texture from image.");
|
180
178
|
}
|
181
|
-
return
|
179
|
+
return getTextureInfo(texture);
|
182
180
|
}
|
183
181
|
|
184
182
|
const TextureInfo getTexture(sk_sp<SkSurface> surface) override {
|
185
183
|
GrBackendTexture texture = SkSurfaces::GetBackendTexture(
|
186
184
|
surface.get(), SkSurface::BackendHandleAccess::kFlushRead);
|
187
|
-
return
|
185
|
+
return getTextureInfo(texture);
|
188
186
|
}
|
189
187
|
|
190
|
-
static
|
188
|
+
static TextureInfo getTextureInfo(const GrBackendTexture &texture) {
|
191
189
|
if (!texture.isValid()) {
|
192
190
|
throw std::runtime_error("invalid backend texture");
|
193
191
|
}
|
@@ -35,7 +35,7 @@ RNSkAndroidVideo::RNSkAndroidVideo(jni::global_ref<jobject> jniVideo)
|
|
35
35
|
#endif
|
36
36
|
}
|
37
37
|
|
38
|
-
RNSkAndroidVideo::~RNSkAndroidVideo()
|
38
|
+
RNSkAndroidVideo::~RNSkAndroidVideo() = default;
|
39
39
|
|
40
40
|
sk_sp<SkImage> RNSkAndroidVideo::nextImage(double *timeStamp) {
|
41
41
|
#if __ANDROID_API__ >= 26
|
@@ -26,7 +26,7 @@ private:
|
|
26
26
|
|
27
27
|
public:
|
28
28
|
explicit RNSkAndroidVideo(jni::global_ref<jobject> jniVideo);
|
29
|
-
~RNSkAndroidVideo();
|
29
|
+
~RNSkAndroidVideo() override;
|
30
30
|
sk_sp<SkImage> nextImage(double *timeStamp = nullptr) override;
|
31
31
|
double duration() override;
|
32
32
|
double framerate() override;
|
@@ -26,9 +26,9 @@ namespace RNSkia {
|
|
26
26
|
RNSkOpenGLCanvasProvider::RNSkOpenGLCanvasProvider(
|
27
27
|
std::function<void()> requestRedraw,
|
28
28
|
std::shared_ptr<RNSkia::RNSkPlatformContext> platformContext)
|
29
|
-
: RNSkCanvasProvider(requestRedraw), _platformContext(platformContext) {}
|
29
|
+
: RNSkCanvasProvider(std::move(requestRedraw)), _platformContext(std::move(platformContext)) {}
|
30
30
|
|
31
|
-
RNSkOpenGLCanvasProvider::~RNSkOpenGLCanvasProvider()
|
31
|
+
RNSkOpenGLCanvasProvider::~RNSkOpenGLCanvasProvider() = default;
|
32
32
|
|
33
33
|
float RNSkOpenGLCanvasProvider::getScaledWidth() {
|
34
34
|
if (_surfaceHolder) {
|
@@ -110,7 +110,7 @@ void RNSkOpenGLCanvasProvider::surfaceAvailable(jobject jSurfaceTexture,
|
|
110
110
|
_surfaceHolder = DawnContext::getInstance().MakeWindow(window, width, height);
|
111
111
|
#else
|
112
112
|
_surfaceHolder =
|
113
|
-
OpenGLContext::getInstance().MakeWindow(window
|
113
|
+
OpenGLContext::getInstance().MakeWindow(window);
|
114
114
|
#endif
|
115
115
|
|
116
116
|
// Post redraw request to ensure we paint in the next draw cycle.
|
@@ -32,20 +32,7 @@ public abstract class SkiaBaseView extends ReactViewGroup implements SkiaViewAPI
|
|
32
32
|
}
|
33
33
|
}
|
34
34
|
|
35
|
-
@Override
|
36
|
-
protected void onAttachedToWindow() {
|
37
|
-
super.onAttachedToWindow();
|
38
|
-
if (getMeasuredWidth() == 0) {
|
39
|
-
if (mView instanceof SkiaTextureView) {
|
40
|
-
((SkiaTextureView) mView).createSurfaceTexture();
|
41
|
-
}
|
42
|
-
}
|
43
|
-
}
|
44
|
-
|
45
35
|
void dropInstance() {
|
46
|
-
if (mView instanceof SkiaTextureView) {
|
47
|
-
((SkiaTextureView)mView).isDropped = true;
|
48
|
-
}
|
49
36
|
unregisterView();
|
50
37
|
}
|
51
38
|
|
@@ -15,9 +15,6 @@ public class SkiaTextureView extends TextureView implements TextureView.SurfaceT
|
|
15
15
|
|
16
16
|
SkiaViewAPI mApi;
|
17
17
|
boolean mDebug;
|
18
|
-
boolean pristine = true;
|
19
|
-
|
20
|
-
public boolean isDropped = false;
|
21
18
|
|
22
19
|
public SkiaTextureView(Context context, SkiaViewAPI api, boolean debug) {
|
23
20
|
super(context);
|
@@ -27,22 +24,6 @@ public class SkiaTextureView extends TextureView implements TextureView.SurfaceT
|
|
27
24
|
setSurfaceTextureListener(this);
|
28
25
|
}
|
29
26
|
|
30
|
-
public void createSurfaceTexture() {
|
31
|
-
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) {
|
32
|
-
Log.i(tag, "Create SurfaceTexture");
|
33
|
-
SurfaceTexture surfaceTexture = new SurfaceTexture(false);
|
34
|
-
setSurfaceTexture(surfaceTexture);
|
35
|
-
onSurfaceTextureAvailable(surfaceTexture, getWidth(), getHeight());
|
36
|
-
}
|
37
|
-
}
|
38
|
-
|
39
|
-
private void reCreateSurfaceTexture() {
|
40
|
-
boolean surfaceIsAlreadyAvailable = getSurfaceTexture() != null;
|
41
|
-
if (surfaceIsAlreadyAvailable) {
|
42
|
-
createSurfaceTexture();
|
43
|
-
}
|
44
|
-
}
|
45
|
-
|
46
27
|
@Override
|
47
28
|
protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
|
48
29
|
super.onLayout(changed, left, top, right, bottom);
|
@@ -57,23 +38,13 @@ public class SkiaTextureView extends TextureView implements TextureView.SurfaceT
|
|
57
38
|
@Override
|
58
39
|
public void onSurfaceTextureSizeChanged(@NonNull SurfaceTexture surfaceTexture, int width, int height) {
|
59
40
|
Log.i(tag, "onSurfaceTextureSizeChanged: " + width + "x" + height);
|
60
|
-
|
61
|
-
return;
|
62
|
-
}
|
63
|
-
mApi.onSurfaceTextureCreated(surfaceTexture, width, height);
|
41
|
+
mApi.onSurfaceTextureChanged(surfaceTexture, width, height);
|
64
42
|
}
|
65
43
|
|
66
44
|
@Override
|
67
45
|
public boolean onSurfaceTextureDestroyed(@NonNull SurfaceTexture surfaceTexture) {
|
68
46
|
mApi.onSurfaceDestroyed();
|
69
|
-
|
70
|
-
// If not, Texture view will recreate the texture surface by itself and
|
71
|
-
// we will lose the fast first time to frame.
|
72
|
-
// We only delete the surface when the view is dropped (destroySurface invoked by SkiaBaseViewManager);
|
73
|
-
if (!isDropped) {
|
74
|
-
reCreateSurfaceTexture();
|
75
|
-
}
|
76
|
-
return false;
|
47
|
+
return true;
|
77
48
|
}
|
78
49
|
|
79
50
|
private long _prevTimestamp = 0;
|
package/cpp/api/JsiSkApi.h
CHANGED
@@ -64,7 +64,7 @@ public:
|
|
64
64
|
* and provide functions for accessing and creating the Skia wrapper objects
|
65
65
|
* @param context Platform context
|
66
66
|
*/
|
67
|
-
JsiSkApi(
|
67
|
+
explicit JsiSkApi(const std::shared_ptr<RNSkPlatformContext> &context)
|
68
68
|
: JsiSkHostObject(context) {
|
69
69
|
// We create the system font manager eagerly since it has proven to be too
|
70
70
|
// slow to do it on demand
|
package/cpp/api/JsiSkCanvas.h
CHANGED
@@ -83,7 +83,7 @@ public:
|
|
83
83
|
auto src = JsiSkRect::fromValue(runtime, arguments[1]);
|
84
84
|
auto dest = JsiSkRect::fromValue(runtime, arguments[2]);
|
85
85
|
auto paint = JsiSkPaint::fromValue(runtime, arguments[3]);
|
86
|
-
auto fastSample = count
|
86
|
+
auto fastSample = count >= 5 && arguments[4].getBool();
|
87
87
|
_canvas->drawImageRect(image, *src, *dest, SkSamplingOptions(), paint.get(),
|
88
88
|
fastSample ? SkCanvas::kFast_SrcRectConstraint
|
89
89
|
: SkCanvas::kStrict_SrcRectConstraint);
|
package/cpp/api/JsiSkColor.h
CHANGED
@@ -24,7 +24,7 @@ class JsiSkColor : public RNJsi::JsiHostObject {
|
|
24
24
|
public:
|
25
25
|
JsiSkColor() : JsiHostObject() {}
|
26
26
|
|
27
|
-
~JsiSkColor()
|
27
|
+
~JsiSkColor() override = default;
|
28
28
|
|
29
29
|
static jsi::Object toValue(jsi::Runtime &runtime, SkColor color) {
|
30
30
|
auto result = runtime.global()
|
@@ -63,7 +63,7 @@ public:
|
|
63
63
|
* @return A function for creating a new host object wrapper for the SkColor
|
64
64
|
* class
|
65
65
|
*/
|
66
|
-
static
|
66
|
+
static jsi::HostFunctionType createCtor() {
|
67
67
|
return JSI_HOST_FUNCTION_LAMBDA {
|
68
68
|
if (arguments[0].isNumber()) {
|
69
69
|
return JsiSkColor::toValue(runtime, arguments[0].getNumber());
|
@@ -26,8 +26,8 @@ namespace RNSkia {
|
|
26
26
|
|
27
27
|
Base64::Error Base64::Decode(const void *srcv, size_t srcLength, void *dstv,
|
28
28
|
size_t *dstLength) {
|
29
|
-
|
30
|
-
|
29
|
+
auto *src = static_cast<const unsigned char *>(srcv);
|
30
|
+
auto *dst = static_cast<unsigned char *>(dstv);
|
31
31
|
|
32
32
|
int i = 0;
|
33
33
|
bool padTwo = false;
|
@@ -112,8 +112,8 @@ Base64::Error Base64::Decode(const void *srcv, size_t srcLength, void *dstv,
|
|
112
112
|
}
|
113
113
|
|
114
114
|
size_t Base64::Encode(const void *srcv, size_t length, void *dstv) {
|
115
|
-
|
116
|
-
|
115
|
+
auto *src = static_cast<const unsigned char *>(srcv);
|
116
|
+
auto *dst = static_cast<unsigned char *>(dstv);
|
117
117
|
|
118
118
|
const char *encode = kDefaultEncode;
|
119
119
|
if (dst) {
|
@@ -69,7 +69,7 @@ void RNSkManager::installBindings() {
|
|
69
69
|
// Create the API objects and install it on the global object in the
|
70
70
|
// provided runtime.
|
71
71
|
|
72
|
-
auto skiaApi = std::make_shared<JsiSkApi>(
|
72
|
+
auto skiaApi = std::make_shared<JsiSkApi>(_platformContext);
|
73
73
|
_jsRuntime->global().setProperty(
|
74
74
|
*_jsRuntime, "SkiaApi",
|
75
75
|
jsi::Object::createFromHostObject(*_jsRuntime, std::move(skiaApi)));
|
@@ -10,8 +10,6 @@
|
|
10
10
|
#include "RNSkPlatformContext.h"
|
11
11
|
#include "ViewScreenshotService.h"
|
12
12
|
|
13
|
-
#include <jsi/jsi.h>
|
14
|
-
|
15
13
|
namespace facebook {
|
16
14
|
namespace react {
|
17
15
|
class CallInvoker;
|
@@ -20,8 +18,6 @@ class CallInvoker;
|
|
20
18
|
|
21
19
|
namespace RNSkia {
|
22
20
|
|
23
|
-
namespace jsi = facebook::jsi;
|
24
|
-
|
25
21
|
class RNSkiOSPlatformContext : public RNSkPlatformContext {
|
26
22
|
public:
|
27
23
|
RNSkiOSPlatformContext(
|
@@ -24,10 +24,10 @@ using namespace facebook::react;
|
|
24
24
|
|
25
25
|
- (instancetype)initWithFrame:(CGRect)frame {
|
26
26
|
if (self = [super initWithFrame:frame]) {
|
27
|
-
|
28
|
-
|
27
|
+
// Pass SkManager as a raw pointer to avoid circular dependencies
|
28
|
+
auto skManager = [SkiaManager latestActiveSkManager].get();
|
29
29
|
[self
|
30
|
-
initCommon:skManager
|
30
|
+
initCommon:skManager
|
31
31
|
factory:[](std::shared_ptr<RNSkia::RNSkPlatformContext> context) {
|
32
32
|
return std::make_shared<RNSkiOSView<RNSkia::RNSkDomView>>(context);
|
33
33
|
}];
|
@@ -15,7 +15,8 @@
|
|
15
15
|
RCT_EXPORT_MODULE(SkiaDomView)
|
16
16
|
|
17
17
|
- (SkiaManager *)skiaManager {
|
18
|
-
auto bridge =
|
18
|
+
auto bridge = self.bridge;
|
19
|
+
RCTAssert(bridge, @"Bridge must not be nil.");
|
19
20
|
auto skiaModule = (RNSkiaModule *)[bridge moduleForName:@"RNSkiaModule"];
|
20
21
|
return [skiaModule manager];
|
21
22
|
}
|
@@ -16,4 +16,10 @@
|
|
16
16
|
jsInvoker:(std::shared_ptr<facebook::react::CallInvoker>)
|
17
17
|
jsInvoker;
|
18
18
|
|
19
|
+
#ifdef RCT_NEW_ARCH_ENABLED
|
20
|
+
// Fabric components do not have a better way to interact with TurboModules.
|
21
|
+
// Workaround to get the SkManager instance from singleton.
|
22
|
+
+ (std::shared_ptr<RNSkia::RNSkManager>)latestActiveSkManager;
|
23
|
+
#endif // RCT_NEW_ARCH_ENABLED
|
24
|
+
|
19
25
|
@end
|
@@ -8,6 +8,8 @@
|
|
8
8
|
|
9
9
|
#import "RNSkiOSPlatformContext.h"
|
10
10
|
|
11
|
+
static __weak SkiaManager *sharedInstance = nil;
|
12
|
+
|
11
13
|
@implementation SkiaManager {
|
12
14
|
std::shared_ptr<RNSkia::RNSkManager> _skManager;
|
13
15
|
__weak RCTBridge *weakBridge;
|
@@ -29,6 +31,7 @@
|
|
29
31
|
jsInvoker {
|
30
32
|
self = [super init];
|
31
33
|
if (self) {
|
34
|
+
sharedInstance = self;
|
32
35
|
RCTCxxBridge *cxxBridge = (RCTCxxBridge *)bridge;
|
33
36
|
if (cxxBridge.runtime) {
|
34
37
|
|
@@ -44,4 +47,18 @@
|
|
44
47
|
return self;
|
45
48
|
}
|
46
49
|
|
50
|
+
- (void)dealloc
|
51
|
+
{
|
52
|
+
sharedInstance = nil;
|
53
|
+
}
|
54
|
+
|
55
|
+
#ifdef RCT_NEW_ARCH_ENABLED
|
56
|
+
+ (std::shared_ptr<RNSkia::RNSkManager>)latestActiveSkManager
|
57
|
+
{
|
58
|
+
if (sharedInstance != nil) {
|
59
|
+
return [sharedInstance skManager];
|
60
|
+
}
|
61
|
+
return nullptr;
|
62
|
+
}
|
63
|
+
#endif // RCT_NEW_ARCH_ENABLED
|
47
64
|
@end
|
@@ -24,9 +24,9 @@ using namespace facebook::react;
|
|
24
24
|
|
25
25
|
- (instancetype)initWithFrame:(CGRect)frame {
|
26
26
|
if (self = [super initWithFrame:frame]) {
|
27
|
-
|
28
|
-
|
29
|
-
[self initCommon:skManager
|
27
|
+
// Pass SkManager as a raw pointer to avoid circular dependencies
|
28
|
+
auto skManager = [SkiaManager latestActiveSkManager].get();
|
29
|
+
[self initCommon:skManager
|
30
30
|
factory:[](std::shared_ptr<RNSkia::RNSkPlatformContext> context) {
|
31
31
|
return std::make_shared<RNSkiOSView<RNSkia::RNSkPictureView>>(
|
32
32
|
context);
|
@@ -15,7 +15,8 @@
|
|
15
15
|
RCT_EXPORT_MODULE(SkiaPictureView)
|
16
16
|
|
17
17
|
- (SkiaManager *)skiaManager {
|
18
|
-
auto bridge =
|
18
|
+
auto bridge = self.bridge;
|
19
|
+
RCTAssert(bridge, @"Bridge must not be nil.");
|
19
20
|
auto skiaModule = (RNSkiaModule *)[bridge moduleForName:@"RNSkiaModule"];
|
20
21
|
return [skiaModule manager];
|
21
22
|
}
|
@@ -29,7 +29,6 @@
|
|
29
29
|
factory:(std::function<std::shared_ptr<RNSkBaseiOSView>(
|
30
30
|
std::shared_ptr<RNSkia::RNSkPlatformContext>)>)factory;
|
31
31
|
- (std::shared_ptr<RNSkBaseiOSView>)impl;
|
32
|
-
- (SkiaManager *)skiaManager;
|
33
32
|
|
34
33
|
- (void)setDebugMode:(bool)debugMode;
|
35
34
|
- (void)setOpaque:(bool)opaque;
|
@@ -48,12 +48,6 @@
|
|
48
48
|
_factory = factory;
|
49
49
|
}
|
50
50
|
|
51
|
-
- (SkiaManager *)skiaManager {
|
52
|
-
auto bridge = [RCTBridge currentBridge];
|
53
|
-
auto skiaModule = (RNSkiaModule *)[bridge moduleForName:@"RNSkiaModule"];
|
54
|
-
return [skiaModule manager];
|
55
|
-
}
|
56
|
-
|
57
51
|
- (void)willInvalidateModules {
|
58
52
|
_impl = nullptr;
|
59
53
|
_manager = nullptr;
|
@@ -114,7 +108,7 @@
|
|
114
108
|
// this flag is only set when the view is inserted and we want to set the
|
115
109
|
// manager here since the view could be recycled or the app could be
|
116
110
|
// refreshed and we would have a stale manager then
|
117
|
-
_manager = [
|
111
|
+
_manager = [SkiaManager latestActiveSkManager].get();
|
118
112
|
}
|
119
113
|
}
|
120
114
|
#endif // RCT_NEW_ARCH_ENABLED
|
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.7.
|
10
|
+
"version": "1.7.2",
|
11
11
|
"description": "High-performance React Native Graphics using Skia",
|
12
12
|
"main": "lib/module/index.js",
|
13
13
|
"react-native": "src/index.ts",
|