@shopify/react-native-skia 1.5.3 → 1.5.5
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 +53 -13
- package/android/build.gradle +3 -0
- package/android/cpp/rnskia-android/OpenGLContext.h +122 -11
- package/android/cpp/rnskia-android/OpenGLWindowContext.cpp +73 -0
- package/android/cpp/rnskia-android/OpenGLWindowContext.h +74 -0
- package/android/cpp/rnskia-android/RNSkAndroidPlatformContext.h +18 -1
- package/android/cpp/rnskia-android/RNSkAndroidVideo.cpp +12 -1
- package/android/cpp/rnskia-android/RNSkOpenGLCanvasProvider.cpp +13 -1
- package/android/cpp/rnskia-android/opengl/Context.h +77 -0
- package/android/cpp/rnskia-android/opengl/Display.h +117 -0
- package/android/cpp/rnskia-android/opengl/Error.cpp +9 -0
- package/android/cpp/rnskia-android/opengl/Error.h +44 -0
- package/android/cpp/rnskia-android/opengl/Surface.h +43 -0
- package/android/src/main/java/com/shopify/reactnative/skia/SkiaBaseView.java +0 -1
- package/cpp/api/JsiSkImage.h +15 -2
- package/cpp/api/JsiSkSurface.h +18 -3
- package/cpp/rnskia/DawnContext.h +241 -0
- package/cpp/rnskia/DawnUtils.h +127 -0
- package/cpp/rnskia/DawnWindowContext.cpp +19 -0
- package/cpp/rnskia/DawnWindowContext.h +77 -0
- package/cpp/rnskia/ImageProvider.h +100 -0
- package/cpp/rnskia/RNSkView.h +6 -0
- package/cpp/skia/include/android/SkAnimatedImage.h +14 -0
- package/cpp/skia/include/codec/SkAvifDecoder.h +39 -3
- package/cpp/skia/include/codec/SkCodec.h +16 -0
- package/cpp/skia/include/config/SkUserConfig.h +3 -2
- package/cpp/skia/include/core/SkCanvas.h +55 -10
- package/cpp/skia/include/core/SkContourMeasure.h +76 -0
- package/cpp/skia/include/core/SkFontScanner.h +48 -0
- package/cpp/skia/include/core/SkMilestone.h +1 -1
- package/cpp/skia/include/core/SkPath.h +11 -0
- package/cpp/skia/include/core/SkPathEffect.h +0 -23
- package/cpp/skia/include/core/SkRect.h +2 -0
- package/cpp/skia/include/core/SkString.h +4 -0
- package/cpp/skia/include/core/SkTypeface.h +5 -0
- package/cpp/skia/include/core/SkTypes.h +8 -3
- package/cpp/skia/include/docs/SkPDFDocument.h +3 -3
- package/cpp/skia/include/effects/SkOverdrawColorFilter.h +1 -0
- package/cpp/skia/include/effects/SkRuntimeEffect.h +2 -1
- package/cpp/skia/include/encode/SkJpegEncoder.h +4 -0
- package/cpp/skia/include/gpu/ganesh/GrContextOptions.h +8 -1
- package/cpp/skia/include/gpu/ganesh/GrDirectContext.h +18 -3
- package/cpp/skia/include/gpu/ganesh/GrTypes.h +11 -0
- package/cpp/skia/include/gpu/ganesh/gl/GrGLFunctions.h +5 -1
- package/cpp/skia/include/gpu/ganesh/gl/GrGLInterface.h +0 -1
- package/cpp/skia/include/gpu/graphite/GraphiteTypes.h +8 -0
- package/cpp/skia/include/gpu/graphite/Recorder.h +0 -2
- package/cpp/skia/include/gpu/graphite/precompile/PaintOptions.h +7 -4
- package/cpp/skia/include/gpu/graphite/precompile/PrecompileImageFilter.h +2 -0
- package/cpp/skia/include/gpu/graphite/precompile/PrecompileMaskFilter.h +2 -0
- package/cpp/skia/include/ports/SkFontMgr_android_ndk.h +25 -0
- package/cpp/skia/include/ports/SkFontMgr_fontconfig.h +4 -2
- package/cpp/skia/include/ports/SkFontScanner_Fontations.h +15 -0
- package/cpp/skia/include/ports/SkFontScanner_FreeType.h +15 -0
- package/cpp/skia/include/private/SkExif.h +14 -0
- package/cpp/skia/include/private/SkPathRef.h +36 -0
- package/cpp/skia/include/private/base/SkFeatures.h +4 -0
- package/cpp/skia/include/private/base/SkSpan_impl.h +1 -3
- package/cpp/skia/modules/skcms/src/skcms_internals.h +3 -0
- package/cpp/skia/src/base/SkMathPriv.h +1 -8
- package/ios/RNSkia-iOS/RNSkMetalCanvasProvider.h +1 -2
- package/ios/RNSkia-iOS/RNSkMetalCanvasProvider.mm +25 -19
- package/ios/RNSkia-iOS/RNSkiOSPlatformContext.mm +23 -0
- package/ios/RNSkia-iOS/SkiaCVPixelBufferUtils.mm +4 -8
- package/ios/RNSkia-iOS/SkiaMetalSurfaceFactory.h +26 -8
- package/ios/RNSkia-iOS/SkiaMetalSurfaceFactory.mm +0 -20
- package/libs/android/arm64-v8a/libskia.a +0 -0
- package/libs/android/arm64-v8a/libskottie.a +0 -0
- package/libs/android/armeabi-v7a/libskia.a +0 -0
- package/libs/android/armeabi-v7a/libskottie.a +0 -0
- package/libs/android/x86/libskia.a +0 -0
- package/libs/android/x86/libskottie.a +0 -0
- package/libs/android/x86_64/libskia.a +0 -0
- package/libs/android/x86_64/libskottie.a +0 -0
- package/libs/ios/libskia.xcframework/ios-arm64_arm64e/libskia.a +0 -0
- package/libs/ios/libskia.xcframework/ios-arm64_arm64e_x86_64-simulator/libskia.a +0 -0
- package/libs/ios/libskottie.xcframework/ios-arm64_arm64e/libskottie.a +0 -0
- package/libs/ios/libskottie.xcframework/ios-arm64_arm64e_x86_64-simulator/libskottie.a +0 -0
- package/libs/ios/libskparagraph.xcframework/ios-arm64_arm64e/libskparagraph.a +0 -0
- package/libs/ios/libskparagraph.xcframework/ios-arm64_arm64e_x86_64-simulator/libskparagraph.a +0 -0
- package/libs/ios/libsksg.xcframework/ios-arm64_arm64e/libsksg.a +0 -0
- package/libs/ios/libsksg.xcframework/ios-arm64_arm64e_x86_64-simulator/libsksg.a +0 -0
- package/libs/ios/libskshaper.xcframework/Info.plist +5 -5
- package/libs/ios/libskshaper.xcframework/ios-arm64_arm64e/libskshaper.a +0 -0
- package/libs/ios/libskshaper.xcframework/ios-arm64_arm64e_x86_64-simulator/libskshaper.a +0 -0
- package/libs/ios/libskunicode_core.xcframework/Info.plist +5 -5
- package/libs/ios/libskunicode_core.xcframework/ios-arm64_arm64e/libskunicode_core.a +0 -0
- package/libs/ios/libskunicode_core.xcframework/ios-arm64_arm64e_x86_64-simulator/libskunicode_core.a +0 -0
- package/libs/ios/libskunicode_libgrapheme.xcframework/Info.plist +5 -5
- package/libs/ios/libskunicode_libgrapheme.xcframework/ios-arm64_arm64e/libskunicode_libgrapheme.a +0 -0
- package/libs/ios/libskunicode_libgrapheme.xcframework/ios-arm64_arm64e_x86_64-simulator/libskunicode_libgrapheme.a +0 -0
- package/libs/ios/libsvg.xcframework/ios-arm64_arm64e/libsvg.a +0 -0
- package/libs/ios/libsvg.xcframework/ios-arm64_arm64e_x86_64-simulator/libsvg.a +0 -0
- package/package.json +1 -1
- package/react-native-skia.podspec +35 -9
- package/src/renderer/__tests__/e2e/SVG.spec.tsx +2 -1
- package/android/cpp/rnskia-android/SkiaOpenGLHelper.h +0 -310
- package/android/cpp/rnskia-android/SkiaOpenGLSurfaceFactory.cpp +0 -188
- package/android/cpp/rnskia-android/SkiaOpenGLSurfaceFactory.h +0 -100
|
@@ -1,310 +0,0 @@
|
|
|
1
|
-
#pragma once
|
|
2
|
-
|
|
3
|
-
#include "EGL/egl.h"
|
|
4
|
-
#include "GLES2/gl2.h"
|
|
5
|
-
#include <fbjni/fbjni.h>
|
|
6
|
-
#include <jni.h>
|
|
7
|
-
|
|
8
|
-
#include <atomic>
|
|
9
|
-
|
|
10
|
-
#include "RNSkLog.h"
|
|
11
|
-
|
|
12
|
-
#pragma clang diagnostic push
|
|
13
|
-
#pragma clang diagnostic ignored "-Wdocumentation"
|
|
14
|
-
|
|
15
|
-
#include "include/core/SkCanvas.h"
|
|
16
|
-
#include "include/core/SkColorSpace.h"
|
|
17
|
-
#include "include/core/SkSurface.h"
|
|
18
|
-
#include "include/gpu/ganesh/GrDirectContext.h"
|
|
19
|
-
#include "include/gpu/ganesh/gl/GrGLDirectContext.h"
|
|
20
|
-
#include "include/gpu/ganesh/gl/GrGLInterface.h"
|
|
21
|
-
|
|
22
|
-
#pragma clang diagnostic pop
|
|
23
|
-
|
|
24
|
-
namespace RNSkia {
|
|
25
|
-
|
|
26
|
-
/**
|
|
27
|
-
* Singleton holding the default display and shared eglContext that will be the
|
|
28
|
-
* first context we create so that we can share data between contexts.
|
|
29
|
-
*/
|
|
30
|
-
class OpenGLResourceHolder {
|
|
31
|
-
private:
|
|
32
|
-
OpenGLResourceHolder() {
|
|
33
|
-
// Initialize OpenGL
|
|
34
|
-
glDisplay = eglGetDisplay(EGL_DEFAULT_DISPLAY);
|
|
35
|
-
if (glDisplay == EGL_NO_DISPLAY) {
|
|
36
|
-
RNSkLogger::logToConsole("eglGetDisplay failed : %i", glGetError());
|
|
37
|
-
return;
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
EGLint major;
|
|
41
|
-
EGLint minor;
|
|
42
|
-
if (eglInitialize(glDisplay, &major, &minor) != EGL_TRUE) {
|
|
43
|
-
RNSkLogger::logToConsole("eglInitialize failed : %i", glGetError());
|
|
44
|
-
return;
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
// Create a default shared context
|
|
48
|
-
glConfig = getConfig(glDisplay);
|
|
49
|
-
|
|
50
|
-
// Create OpenGL context attributes
|
|
51
|
-
EGLint contextAttribs[] = {EGL_CONTEXT_CLIENT_VERSION, 2, EGL_NONE};
|
|
52
|
-
|
|
53
|
-
// Initialize the offscreen context for this thread
|
|
54
|
-
glContext =
|
|
55
|
-
eglCreateContext(glDisplay, glConfig, glContext, contextAttribs);
|
|
56
|
-
if (glContext == EGL_NO_CONTEXT) {
|
|
57
|
-
RNSkLogger::logToConsole("eglCreateContext failed : %i", glGetError());
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
~OpenGLResourceHolder() {
|
|
62
|
-
if (glContext != EGL_NO_CONTEXT) {
|
|
63
|
-
eglDestroyContext(glDisplay, glContext);
|
|
64
|
-
glContext = EGL_NO_CONTEXT;
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
if (glDisplay != EGL_NO_DISPLAY) {
|
|
68
|
-
eglTerminate(glDisplay);
|
|
69
|
-
glDisplay = EGL_NO_DISPLAY;
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
/* Explicitly disallow copying. */
|
|
73
|
-
OpenGLResourceHolder(const OpenGLResourceHolder &) = delete;
|
|
74
|
-
OpenGLResourceHolder &operator=(const OpenGLResourceHolder &) = delete;
|
|
75
|
-
|
|
76
|
-
public:
|
|
77
|
-
static OpenGLResourceHolder &getInstance() {
|
|
78
|
-
static OpenGLResourceHolder Instance;
|
|
79
|
-
return Instance;
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
/**
|
|
83
|
-
* The first context created will be considered the parent / shared context
|
|
84
|
-
* and will be used as the parent / shareable context when creating subsequent
|
|
85
|
-
* contexts.
|
|
86
|
-
*/
|
|
87
|
-
std::atomic<EGLContext> glContext = EGL_NO_CONTEXT;
|
|
88
|
-
/**
|
|
89
|
-
* Shared egl display
|
|
90
|
-
*/
|
|
91
|
-
std::atomic<EGLDisplay> glDisplay = EGL_NO_DISPLAY;
|
|
92
|
-
|
|
93
|
-
/**
|
|
94
|
-
* Shared eglConfig
|
|
95
|
-
*/
|
|
96
|
-
std::atomic<EGLConfig> glConfig = 0;
|
|
97
|
-
|
|
98
|
-
private:
|
|
99
|
-
/**
|
|
100
|
-
* Finds the correct EGL Config for the given parameters
|
|
101
|
-
* @param glDisplay
|
|
102
|
-
* @return Config or zero if no matching context could be found.
|
|
103
|
-
*/
|
|
104
|
-
static EGLConfig getConfig(EGLDisplay glDisplay) {
|
|
105
|
-
|
|
106
|
-
EGLint att[] = {EGL_RENDERABLE_TYPE,
|
|
107
|
-
EGL_OPENGL_ES2_BIT,
|
|
108
|
-
EGL_ALPHA_SIZE,
|
|
109
|
-
8,
|
|
110
|
-
EGL_BLUE_SIZE,
|
|
111
|
-
8,
|
|
112
|
-
EGL_GREEN_SIZE,
|
|
113
|
-
8,
|
|
114
|
-
EGL_RED_SIZE,
|
|
115
|
-
8,
|
|
116
|
-
EGL_DEPTH_SIZE,
|
|
117
|
-
0,
|
|
118
|
-
EGL_STENCIL_SIZE,
|
|
119
|
-
0,
|
|
120
|
-
EGL_SAMPLE_BUFFERS,
|
|
121
|
-
0,
|
|
122
|
-
EGL_NONE};
|
|
123
|
-
|
|
124
|
-
EGLint numConfigs;
|
|
125
|
-
EGLConfig glConfig = 0;
|
|
126
|
-
if (eglChooseConfig(glDisplay, att, &glConfig, 1, &numConfigs) !=
|
|
127
|
-
EGL_TRUE ||
|
|
128
|
-
numConfigs == 0) {
|
|
129
|
-
RNSkLogger::logToConsole(
|
|
130
|
-
"Failed to choose a config for %s surface. Error code: %d\n",
|
|
131
|
-
eglGetError());
|
|
132
|
-
return 0;
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
return glConfig;
|
|
136
|
-
}
|
|
137
|
-
};
|
|
138
|
-
|
|
139
|
-
struct SkiaOpenGLContext {
|
|
140
|
-
SkiaOpenGLContext() {
|
|
141
|
-
glContext = EGL_NO_CONTEXT;
|
|
142
|
-
gl1x1Surface = EGL_NO_SURFACE;
|
|
143
|
-
directContext = nullptr;
|
|
144
|
-
}
|
|
145
|
-
~SkiaOpenGLContext() {
|
|
146
|
-
if (gl1x1Surface != EGL_NO_SURFACE) {
|
|
147
|
-
eglDestroySurface(OpenGLResourceHolder::getInstance().glDisplay,
|
|
148
|
-
gl1x1Surface);
|
|
149
|
-
gl1x1Surface = EGL_NO_SURFACE;
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
if (directContext) {
|
|
153
|
-
directContext->releaseResourcesAndAbandonContext();
|
|
154
|
-
directContext = nullptr;
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
if (glContext != EGL_NO_CONTEXT) {
|
|
158
|
-
eglDestroyContext(OpenGLResourceHolder::getInstance().glDisplay,
|
|
159
|
-
glContext);
|
|
160
|
-
glContext = EGL_NO_CONTEXT;
|
|
161
|
-
}
|
|
162
|
-
}
|
|
163
|
-
EGLContext glContext;
|
|
164
|
-
EGLSurface gl1x1Surface;
|
|
165
|
-
sk_sp<GrDirectContext> directContext;
|
|
166
|
-
};
|
|
167
|
-
|
|
168
|
-
class SkiaOpenGLHelper {
|
|
169
|
-
public:
|
|
170
|
-
/**
|
|
171
|
-
* Calls eglMakeCurrent on the surface provided using the provided
|
|
172
|
-
* thread context.
|
|
173
|
-
* @param context Skia OpenGL context to use
|
|
174
|
-
* @param surface Surface to set as current
|
|
175
|
-
* @return true if eglMakeCurrent was successfull
|
|
176
|
-
*/
|
|
177
|
-
static bool makeCurrent(SkiaOpenGLContext *context, EGLSurface glSurface) {
|
|
178
|
-
// We don't need to call make current if we already are current:
|
|
179
|
-
if (eglGetCurrentSurface(EGL_DRAW) != glSurface ||
|
|
180
|
-
eglGetCurrentSurface(EGL_READ) != glSurface ||
|
|
181
|
-
eglGetCurrentContext() != context->glContext) {
|
|
182
|
-
|
|
183
|
-
// Make current!
|
|
184
|
-
if (eglMakeCurrent(OpenGLResourceHolder::getInstance().glDisplay,
|
|
185
|
-
glSurface, glSurface,
|
|
186
|
-
context->glContext) != EGL_TRUE) {
|
|
187
|
-
RNSkLogger::logToConsole("eglMakeCurrent failed: %d\n", eglGetError());
|
|
188
|
-
return false;
|
|
189
|
-
}
|
|
190
|
-
}
|
|
191
|
-
return true;
|
|
192
|
-
}
|
|
193
|
-
|
|
194
|
-
/**
|
|
195
|
-
* Creates a new windowed surface
|
|
196
|
-
* @param window ANativeWindow to create surface in
|
|
197
|
-
* @return EGLSurface or EGL_NO_SURFACE if the call failed
|
|
198
|
-
*/
|
|
199
|
-
static EGLSurface createWindowedSurface(ANativeWindow *window) {
|
|
200
|
-
const EGLint attribs[] = {EGL_NONE};
|
|
201
|
-
return eglCreateWindowSurface(OpenGLResourceHolder::getInstance().glDisplay,
|
|
202
|
-
OpenGLResourceHolder::getInstance().glConfig,
|
|
203
|
-
window, attribs);
|
|
204
|
-
}
|
|
205
|
-
|
|
206
|
-
/**
|
|
207
|
-
* Destroys an egl surface
|
|
208
|
-
* @param glSurface
|
|
209
|
-
* @return
|
|
210
|
-
*/
|
|
211
|
-
static bool destroySurface(EGLSurface glSurface) {
|
|
212
|
-
if (eglMakeCurrent(OpenGLResourceHolder::getInstance().glDisplay,
|
|
213
|
-
EGL_NO_SURFACE, EGL_NO_SURFACE,
|
|
214
|
-
EGL_NO_CONTEXT) != EGL_TRUE) {
|
|
215
|
-
RNSkLogger::logToConsole(
|
|
216
|
-
"destroySurface: Could not clear selected surface");
|
|
217
|
-
return false;
|
|
218
|
-
}
|
|
219
|
-
return eglDestroySurface(OpenGLResourceHolder::getInstance().glDisplay,
|
|
220
|
-
glSurface) == EGL_TRUE;
|
|
221
|
-
}
|
|
222
|
-
|
|
223
|
-
/**
|
|
224
|
-
* Calls the eglSwapBuffer in the current thread with the provided surface
|
|
225
|
-
* @param context Thread context
|
|
226
|
-
* @param glSurface surface to present
|
|
227
|
-
* @return true if eglSwapBuffers succeeded.
|
|
228
|
-
*/
|
|
229
|
-
static bool swapBuffers(SkiaOpenGLContext *context, EGLSurface glSurface) {
|
|
230
|
-
if (eglSwapBuffers(OpenGLResourceHolder::getInstance().glDisplay,
|
|
231
|
-
glSurface) != EGL_TRUE) {
|
|
232
|
-
RNSkLogger::logToConsole("eglSwapBuffers failed: %d\n", eglGetError());
|
|
233
|
-
return false;
|
|
234
|
-
}
|
|
235
|
-
return true;
|
|
236
|
-
}
|
|
237
|
-
|
|
238
|
-
/***
|
|
239
|
-
* Creates a new Skia direct context backed by the provided eglContext in the
|
|
240
|
-
* SkiaOpenGLContext.
|
|
241
|
-
* @param context Context to store results in
|
|
242
|
-
* @param sharedContext Shared Context
|
|
243
|
-
* @return true if the call to create a skia direct context suceeded.
|
|
244
|
-
*/
|
|
245
|
-
static bool createSkiaDirectContextIfNecessary(SkiaOpenGLContext *context) {
|
|
246
|
-
if (context->directContext == nullptr) {
|
|
247
|
-
|
|
248
|
-
// Create OpenGL context
|
|
249
|
-
createOpenGLContext(context);
|
|
250
|
-
|
|
251
|
-
// Create attributes for a simple 1x1 pbuffer surface that we can
|
|
252
|
-
// use to activate and create Skia direct context for
|
|
253
|
-
const EGLint offScreenSurfaceAttribs[] = {EGL_WIDTH, 1, EGL_HEIGHT, 1,
|
|
254
|
-
EGL_NONE};
|
|
255
|
-
|
|
256
|
-
context->gl1x1Surface =
|
|
257
|
-
eglCreatePbufferSurface(OpenGLResourceHolder::getInstance().glDisplay,
|
|
258
|
-
OpenGLResourceHolder::getInstance().glConfig,
|
|
259
|
-
offScreenSurfaceAttribs);
|
|
260
|
-
|
|
261
|
-
if (context->gl1x1Surface == EGL_NO_SURFACE) {
|
|
262
|
-
RNSkLogger::logToConsole("Failed creating a 1x1 pbuffer surface");
|
|
263
|
-
return false;
|
|
264
|
-
}
|
|
265
|
-
|
|
266
|
-
// Activate
|
|
267
|
-
if (!makeCurrent(context, context->gl1x1Surface)) {
|
|
268
|
-
return false;
|
|
269
|
-
}
|
|
270
|
-
|
|
271
|
-
// Create the Skia context
|
|
272
|
-
auto backendInterface = GrGLMakeNativeInterface();
|
|
273
|
-
context->directContext = GrDirectContexts::MakeGL(backendInterface);
|
|
274
|
-
|
|
275
|
-
if (context->directContext == nullptr) {
|
|
276
|
-
RNSkLogger::logToConsole("GrDirectContexts::MakeGL failed");
|
|
277
|
-
return false;
|
|
278
|
-
}
|
|
279
|
-
}
|
|
280
|
-
|
|
281
|
-
// It all went well!
|
|
282
|
-
return true;
|
|
283
|
-
}
|
|
284
|
-
|
|
285
|
-
private:
|
|
286
|
-
/**
|
|
287
|
-
* Creates a new GLContext.
|
|
288
|
-
* @param context Context to save results in
|
|
289
|
-
* @return True if the call to eglCreateContext returned a valid OpenGL
|
|
290
|
-
* Context or if the context already is setup.
|
|
291
|
-
*/
|
|
292
|
-
static bool createOpenGLContext(SkiaOpenGLContext *context) {
|
|
293
|
-
// Create OpenGL context attributes
|
|
294
|
-
EGLint contextAttribs[] = {EGL_CONTEXT_CLIENT_VERSION, 2, EGL_NONE};
|
|
295
|
-
|
|
296
|
-
// Initialize the offscreen context for this thread
|
|
297
|
-
context->glContext = eglCreateContext(
|
|
298
|
-
OpenGLResourceHolder::getInstance().glDisplay,
|
|
299
|
-
OpenGLResourceHolder::getInstance().glConfig,
|
|
300
|
-
OpenGLResourceHolder::getInstance().glContext, contextAttribs);
|
|
301
|
-
|
|
302
|
-
if (context->glContext == EGL_NO_CONTEXT) {
|
|
303
|
-
RNSkLogger::logToConsole("eglCreateContext failed: %d\n", eglGetError());
|
|
304
|
-
return EGL_NO_CONTEXT;
|
|
305
|
-
}
|
|
306
|
-
|
|
307
|
-
return true;
|
|
308
|
-
}
|
|
309
|
-
};
|
|
310
|
-
} // namespace RNSkia
|
|
@@ -1,188 +0,0 @@
|
|
|
1
|
-
#include "SkiaOpenGLSurfaceFactory.h"
|
|
2
|
-
#include "GrAHardwareBufferUtils.h"
|
|
3
|
-
#include "SkiaOpenGLHelper.h"
|
|
4
|
-
|
|
5
|
-
#pragma clang diagnostic push
|
|
6
|
-
#pragma clang diagnostic ignored "-Wdocumentation"
|
|
7
|
-
|
|
8
|
-
#include "include/gpu/ganesh/SkImageGanesh.h"
|
|
9
|
-
#include "include/gpu/ganesh/gl/GrGLBackendSurface.h"
|
|
10
|
-
#include "src/gpu/ganesh/gl/GrGLDefines.h"
|
|
11
|
-
|
|
12
|
-
#pragma clang diagnostic pop
|
|
13
|
-
|
|
14
|
-
namespace RNSkia {
|
|
15
|
-
|
|
16
|
-
sk_sp<SkImage> SkiaOpenGLSurfaceFactory::makeImageFromHardwareBuffer(
|
|
17
|
-
SkiaOpenGLContext *context, void *buffer, bool requireKnownFormat) {
|
|
18
|
-
#if __ANDROID_API__ >= 26
|
|
19
|
-
const AHardwareBuffer *hardwareBuffer =
|
|
20
|
-
static_cast<AHardwareBuffer *>(buffer);
|
|
21
|
-
DeleteImageProc deleteImageProc = nullptr;
|
|
22
|
-
UpdateImageProc updateImageProc = nullptr;
|
|
23
|
-
TexImageCtx deleteImageCtx = nullptr;
|
|
24
|
-
|
|
25
|
-
AHardwareBuffer_Desc description;
|
|
26
|
-
AHardwareBuffer_describe(hardwareBuffer, &description);
|
|
27
|
-
GrBackendFormat format;
|
|
28
|
-
switch (description.format) {
|
|
29
|
-
// TODO: find out if we can detect, which graphic buffers support
|
|
30
|
-
// GR_GL_TEXTURE_2D
|
|
31
|
-
case AHARDWAREBUFFER_FORMAT_R8G8B8A8_UNORM:
|
|
32
|
-
format = GrBackendFormats::MakeGL(GR_GL_RGBA8, GR_GL_TEXTURE_EXTERNAL);
|
|
33
|
-
case AHARDWAREBUFFER_FORMAT_R16G16B16A16_FLOAT:
|
|
34
|
-
format = GrBackendFormats::MakeGL(GR_GL_RGBA16F, GR_GL_TEXTURE_EXTERNAL);
|
|
35
|
-
case AHARDWAREBUFFER_FORMAT_R5G6B5_UNORM:
|
|
36
|
-
format = GrBackendFormats::MakeGL(GR_GL_RGB565, GR_GL_TEXTURE_EXTERNAL);
|
|
37
|
-
case AHARDWAREBUFFER_FORMAT_R10G10B10A2_UNORM:
|
|
38
|
-
format = GrBackendFormats::MakeGL(GR_GL_RGB10_A2, GR_GL_TEXTURE_EXTERNAL);
|
|
39
|
-
case AHARDWAREBUFFER_FORMAT_R8G8B8_UNORM:
|
|
40
|
-
format = GrBackendFormats::MakeGL(GR_GL_RGB8, GR_GL_TEXTURE_EXTERNAL);
|
|
41
|
-
#if __ANDROID_API__ >= 33
|
|
42
|
-
case AHARDWAREBUFFER_FORMAT_R8_UNORM:
|
|
43
|
-
format = GrBackendFormats::MakeGL(GR_GL_R8, GR_GL_TEXTURE_EXTERNAL);
|
|
44
|
-
#endif
|
|
45
|
-
default:
|
|
46
|
-
if (requireKnownFormat) {
|
|
47
|
-
format = GrBackendFormat();
|
|
48
|
-
} else {
|
|
49
|
-
format = GrBackendFormats::MakeGL(GR_GL_RGBA8, GR_GL_TEXTURE_EXTERNAL);
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
auto backendTex = MakeGLBackendTexture(
|
|
54
|
-
context->directContext.get(),
|
|
55
|
-
const_cast<AHardwareBuffer *>(hardwareBuffer), description.width,
|
|
56
|
-
description.height, &deleteImageProc, &updateImageProc, &deleteImageCtx,
|
|
57
|
-
false, format, false);
|
|
58
|
-
if (!backendTex.isValid()) {
|
|
59
|
-
RNSkLogger::logToConsole(
|
|
60
|
-
"Failed to convert HardwareBuffer to OpenGL Texture!");
|
|
61
|
-
return nullptr;
|
|
62
|
-
}
|
|
63
|
-
sk_sp<SkImage> image = SkImages::BorrowTextureFrom(
|
|
64
|
-
context->directContext.get(), backendTex, kTopLeft_GrSurfaceOrigin,
|
|
65
|
-
kRGBA_8888_SkColorType, kOpaque_SkAlphaType, nullptr, deleteImageProc,
|
|
66
|
-
deleteImageCtx);
|
|
67
|
-
return image;
|
|
68
|
-
#else
|
|
69
|
-
throw std::runtime_error(
|
|
70
|
-
"HardwareBuffers are only supported on Android API 26 or higher! Set "
|
|
71
|
-
"your minSdk to 26 (or higher) and try again.");
|
|
72
|
-
#endif
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
sk_sp<SkSurface>
|
|
76
|
-
SkiaOpenGLSurfaceFactory::makeOffscreenSurface(SkiaOpenGLContext *context,
|
|
77
|
-
int width, int height) {
|
|
78
|
-
|
|
79
|
-
auto colorType = kN32_SkColorType;
|
|
80
|
-
|
|
81
|
-
SkSurfaceProps props(0, kUnknown_SkPixelGeometry);
|
|
82
|
-
|
|
83
|
-
if (!SkiaOpenGLHelper::makeCurrent(context, context->gl1x1Surface)) {
|
|
84
|
-
RNSkLogger::logToConsole(
|
|
85
|
-
"Could not create EGL Surface from native window / surface. Could "
|
|
86
|
-
"not set new surface as current surface.");
|
|
87
|
-
return nullptr;
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
// Create texture
|
|
91
|
-
auto texture = context->directContext->createBackendTexture(
|
|
92
|
-
width, height, colorType, skgpu::Mipmapped::kNo, GrRenderable::kYes);
|
|
93
|
-
|
|
94
|
-
if (!texture.isValid()) {
|
|
95
|
-
RNSkLogger::logToConsole("couldn't create offscreen texture %dx%d", width,
|
|
96
|
-
height);
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
struct ReleaseContext {
|
|
100
|
-
SkiaOpenGLContext *context;
|
|
101
|
-
GrBackendTexture texture;
|
|
102
|
-
};
|
|
103
|
-
|
|
104
|
-
auto releaseCtx = new ReleaseContext({context, texture});
|
|
105
|
-
|
|
106
|
-
// Create a SkSurface from the GrBackendTexture
|
|
107
|
-
return SkSurfaces::WrapBackendTexture(
|
|
108
|
-
context->directContext.get(), texture, kTopLeft_GrSurfaceOrigin, 0,
|
|
109
|
-
colorType, nullptr, &props,
|
|
110
|
-
[](void *addr) {
|
|
111
|
-
auto releaseCtx = reinterpret_cast<ReleaseContext *>(addr);
|
|
112
|
-
|
|
113
|
-
releaseCtx->context->directContext->deleteBackendTexture(
|
|
114
|
-
releaseCtx->texture);
|
|
115
|
-
},
|
|
116
|
-
releaseCtx);
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
sk_sp<SkSurface> AndroidSkiaContext::getSurface() {
|
|
120
|
-
if (_skSurface == nullptr) {
|
|
121
|
-
|
|
122
|
-
// Now we can create a surface
|
|
123
|
-
_glSurface = SkiaOpenGLHelper::createWindowedSurface(_window);
|
|
124
|
-
if (_glSurface == EGL_NO_SURFACE) {
|
|
125
|
-
RNSkLogger::logToConsole(
|
|
126
|
-
"Could not create EGL Surface from native window / surface.");
|
|
127
|
-
return nullptr;
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
// Now make this one current
|
|
131
|
-
if (!SkiaOpenGLHelper::makeCurrent(_context, _glSurface)) {
|
|
132
|
-
RNSkLogger::logToConsole(
|
|
133
|
-
"Could not create EGL Surface from native window / surface. Could "
|
|
134
|
-
"not set new surface as current surface.");
|
|
135
|
-
return nullptr;
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
// Set up parameters for the render target so that it
|
|
139
|
-
// matches the underlying OpenGL context.
|
|
140
|
-
GrGLFramebufferInfo fboInfo;
|
|
141
|
-
|
|
142
|
-
// We pass 0 as the framebuffer id, since the
|
|
143
|
-
// underlying Skia GrGlGpu will read this when wrapping the context in the
|
|
144
|
-
// render target and the GrGlGpu object.
|
|
145
|
-
fboInfo.fFBOID = 0;
|
|
146
|
-
fboInfo.fFormat = 0x8058; // GL_RGBA8
|
|
147
|
-
|
|
148
|
-
GLint stencil;
|
|
149
|
-
glGetIntegerv(GL_STENCIL_BITS, &stencil);
|
|
150
|
-
|
|
151
|
-
GLint samples;
|
|
152
|
-
glGetIntegerv(GL_SAMPLES, &samples);
|
|
153
|
-
|
|
154
|
-
auto colorType = kN32_SkColorType;
|
|
155
|
-
|
|
156
|
-
auto maxSamples =
|
|
157
|
-
_context->directContext->maxSurfaceSampleCountForColorType(colorType);
|
|
158
|
-
|
|
159
|
-
if (samples > maxSamples) {
|
|
160
|
-
samples = maxSamples;
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
auto renderTarget = GrBackendRenderTargets::MakeGL(_width, _height, samples,
|
|
164
|
-
stencil, fboInfo);
|
|
165
|
-
|
|
166
|
-
SkSurfaceProps props(0, kUnknown_SkPixelGeometry);
|
|
167
|
-
|
|
168
|
-
struct ReleaseContext {
|
|
169
|
-
EGLSurface glSurface;
|
|
170
|
-
};
|
|
171
|
-
|
|
172
|
-
auto releaseCtx = new ReleaseContext({_glSurface});
|
|
173
|
-
|
|
174
|
-
// Create surface object
|
|
175
|
-
_skSurface = SkSurfaces::WrapBackendRenderTarget(
|
|
176
|
-
_context->directContext.get(), renderTarget,
|
|
177
|
-
kBottomLeft_GrSurfaceOrigin, colorType, nullptr, &props,
|
|
178
|
-
[](void *addr) {
|
|
179
|
-
auto releaseCtx = reinterpret_cast<ReleaseContext *>(addr);
|
|
180
|
-
SkiaOpenGLHelper::destroySurface(releaseCtx->glSurface);
|
|
181
|
-
delete releaseCtx;
|
|
182
|
-
},
|
|
183
|
-
reinterpret_cast<void *>(releaseCtx));
|
|
184
|
-
}
|
|
185
|
-
return _skSurface;
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
} // namespace RNSkia
|
|
@@ -1,100 +0,0 @@
|
|
|
1
|
-
#pragma once
|
|
2
|
-
|
|
3
|
-
#include "RNSkLog.h"
|
|
4
|
-
|
|
5
|
-
#include <fbjni/fbjni.h>
|
|
6
|
-
#include <jni.h>
|
|
7
|
-
|
|
8
|
-
#include <android/native_window_jni.h>
|
|
9
|
-
#include <android/surface_texture.h>
|
|
10
|
-
#include <android/surface_texture_jni.h>
|
|
11
|
-
#include <condition_variable>
|
|
12
|
-
#include <memory>
|
|
13
|
-
#include <thread>
|
|
14
|
-
#include <unordered_map>
|
|
15
|
-
|
|
16
|
-
#include "SkiaOpenGLHelper.h"
|
|
17
|
-
#include "WindowContext.h"
|
|
18
|
-
|
|
19
|
-
#pragma clang diagnostic push
|
|
20
|
-
#pragma clang diagnostic ignored "-Wdocumentation"
|
|
21
|
-
|
|
22
|
-
#include "include/core/SkCanvas.h"
|
|
23
|
-
#include "include/core/SkColorSpace.h"
|
|
24
|
-
#include "include/core/SkSurface.h"
|
|
25
|
-
#include "include/gpu/ganesh/GrBackendSurface.h"
|
|
26
|
-
#include "include/gpu/ganesh/GrDirectContext.h"
|
|
27
|
-
#include "include/gpu/ganesh/SkSurfaceGanesh.h"
|
|
28
|
-
#include "include/gpu/ganesh/gl/GrGLInterface.h"
|
|
29
|
-
|
|
30
|
-
#pragma clang diagnostic pop
|
|
31
|
-
|
|
32
|
-
namespace RNSkia {
|
|
33
|
-
|
|
34
|
-
class AndroidSkiaContext : public WindowContext {
|
|
35
|
-
public:
|
|
36
|
-
AndroidSkiaContext(SkiaOpenGLContext *context, ANativeWindow *window,
|
|
37
|
-
int width, int height)
|
|
38
|
-
: _context(context), _window(window), _width(width), _height(height) {}
|
|
39
|
-
|
|
40
|
-
~AndroidSkiaContext() { ANativeWindow_release(_window); }
|
|
41
|
-
|
|
42
|
-
sk_sp<SkSurface> getSurface() override;
|
|
43
|
-
|
|
44
|
-
void present() override {
|
|
45
|
-
if (!SkiaOpenGLHelper::makeCurrent(_context, _glSurface)) {
|
|
46
|
-
RNSkLogger::logToConsole(
|
|
47
|
-
"Could not create EGL Surface from native window / surface. Could "
|
|
48
|
-
"not set new surface as current surface.");
|
|
49
|
-
return;
|
|
50
|
-
}
|
|
51
|
-
// Flush and submit the direct context
|
|
52
|
-
_context->directContext->flushAndSubmit();
|
|
53
|
-
|
|
54
|
-
// Swap buffers
|
|
55
|
-
SkiaOpenGLHelper::swapBuffers(_context, _glSurface);
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
void resize(int width, int height) override {
|
|
59
|
-
_skSurface = nullptr;
|
|
60
|
-
_width = width;
|
|
61
|
-
_height = height;
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
int getWidth() override { return _width; };
|
|
65
|
-
|
|
66
|
-
int getHeight() override { return _height; };
|
|
67
|
-
|
|
68
|
-
private:
|
|
69
|
-
ANativeWindow *_window;
|
|
70
|
-
sk_sp<SkSurface> _skSurface = nullptr;
|
|
71
|
-
EGLSurface _glSurface = EGL_NO_SURFACE;
|
|
72
|
-
SkiaOpenGLContext *_context;
|
|
73
|
-
int _width = 0;
|
|
74
|
-
int _height = 0;
|
|
75
|
-
};
|
|
76
|
-
|
|
77
|
-
class SkiaOpenGLSurfaceFactory {
|
|
78
|
-
public:
|
|
79
|
-
/**
|
|
80
|
-
* Creates a new Skia surface that is backed by a texture.
|
|
81
|
-
* @param width Width of surface
|
|
82
|
-
* @param height Height of surface
|
|
83
|
-
* @return An SkSurface backed by a texture.
|
|
84
|
-
*/
|
|
85
|
-
static sk_sp<SkSurface> makeOffscreenSurface(SkiaOpenGLContext *context,
|
|
86
|
-
int width, int height);
|
|
87
|
-
|
|
88
|
-
static sk_sp<SkImage>
|
|
89
|
-
makeImageFromHardwareBuffer(SkiaOpenGLContext *context, void *buffer,
|
|
90
|
-
bool requireKnownFormat = false);
|
|
91
|
-
|
|
92
|
-
static std::unique_ptr<AndroidSkiaContext>
|
|
93
|
-
makeContext(SkiaOpenGLContext *context, ANativeWindow *surface, int width,
|
|
94
|
-
int height) {
|
|
95
|
-
return std::make_unique<AndroidSkiaContext>(context, surface, width,
|
|
96
|
-
height);
|
|
97
|
-
}
|
|
98
|
-
};
|
|
99
|
-
|
|
100
|
-
} // namespace RNSkia
|