@shopify/react-native-skia 0.1.154 → 0.1.156
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/JniLoad.cpp +5 -5
- package/android/cpp/jni/JniPlatformContext.cpp +107 -119
- package/android/cpp/jni/JniSkiaManager.cpp +18 -20
- package/android/cpp/jni/include/JniPlatformContext.h +41 -45
- package/android/cpp/jni/include/JniSkiaBaseView.h +52 -55
- package/android/cpp/jni/include/JniSkiaDrawView.h +72 -77
- package/android/cpp/jni/include/JniSkiaManager.h +51 -53
- package/android/cpp/jni/include/JniSkiaPictureView.h +74 -78
- package/android/cpp/rnskia-android/RNSkAndroidPlatformContext.h +36 -45
- package/android/cpp/rnskia-android/RNSkAndroidView.h +87 -92
- package/android/cpp/rnskia-android/RNSkOpenGLCanvasProvider.cpp +62 -65
- package/android/cpp/rnskia-android/RNSkOpenGLCanvasProvider.h +20 -17
- package/android/cpp/rnskia-android/SkiaOpenGLRenderer.cpp +257 -313
- package/android/cpp/rnskia-android/SkiaOpenGLRenderer.h +107 -110
- package/cpp/api/JsiSkApi.h +66 -62
- package/cpp/api/JsiSkCanvas.h +38 -30
- package/cpp/api/JsiSkColor.h +58 -56
- package/cpp/api/JsiSkColorFilter.h +5 -3
- package/cpp/api/JsiSkColorFilterFactory.h +23 -21
- package/cpp/api/JsiSkContourMeasure.h +74 -85
- package/cpp/api/JsiSkContourMeasureIter.h +68 -75
- package/cpp/api/JsiSkData.h +16 -22
- package/cpp/api/JsiSkDataFactory.h +86 -79
- package/cpp/api/JsiSkFont.h +286 -311
- package/cpp/api/JsiSkHostObjects.h +15 -16
- package/cpp/api/JsiSkImage.h +107 -103
- package/cpp/api/JsiSkImageFactory.h +34 -36
- package/cpp/api/JsiSkImageFilter.h +5 -3
- package/cpp/api/JsiSkImageFilterFactory.h +71 -68
- package/cpp/api/JsiSkImageInfo.h +41 -38
- package/cpp/api/JsiSkMaskFilter.h +5 -3
- package/cpp/api/JsiSkMaskFilterFactory.h +2 -3
- package/cpp/api/JsiSkMatrix.h +26 -36
- package/cpp/api/JsiSkPaint.h +20 -13
- package/cpp/api/JsiSkPath.h +70 -85
- package/cpp/api/JsiSkPathEffect.h +5 -3
- package/cpp/api/JsiSkPathEffectFactory.h +33 -28
- package/cpp/api/JsiSkPathFactory.h +68 -67
- package/cpp/api/JsiSkPicture.h +28 -22
- package/cpp/api/JsiSkPictureFactory.h +13 -12
- package/cpp/api/JsiSkPictureRecorder.h +21 -19
- package/cpp/api/JsiSkPoint.h +6 -8
- package/cpp/api/JsiSkRRect.h +11 -7
- package/cpp/api/JsiSkRSXform.h +82 -85
- package/cpp/api/JsiSkRect.h +9 -9
- package/cpp/api/JsiSkRuntimeEffect.h +182 -186
- package/cpp/api/JsiSkRuntimeEffectFactory.h +10 -11
- package/cpp/api/JsiSkRuntimeShaderBuilder.h +64 -61
- package/cpp/api/JsiSkSVG.h +4 -5
- package/cpp/api/JsiSkSVGFactory.h +28 -27
- package/cpp/api/JsiSkShader.h +3 -2
- package/cpp/api/JsiSkShaderFactory.h +37 -25
- package/cpp/api/JsiSkSurface.h +44 -40
- package/cpp/api/JsiSkSurfaceFactory.h +22 -22
- package/cpp/api/JsiSkTextBlob.h +28 -31
- package/cpp/api/JsiSkTextBlobFactory.h +88 -87
- package/cpp/api/JsiSkTypeface.h +6 -5
- package/cpp/api/JsiSkTypefaceFactory.h +22 -21
- package/cpp/api/JsiSkVertices.h +137 -124
- package/cpp/api/third_party/CSSColorParser.cpp +161 -174
- package/cpp/api/third_party/CSSColorParser.h +172 -96
- package/cpp/jsi/JsiHostObject.cpp +11 -9
- package/cpp/jsi/JsiHostObject.h +31 -24
- package/cpp/jsi/JsiSimpleValueWrapper.h +74 -83
- package/cpp/jsi/JsiValueWrapper.h +52 -54
- package/cpp/rnskia/RNSkAnimation.h +26 -29
- package/cpp/rnskia/RNSkDispatchQueue.cpp +50 -61
- package/cpp/rnskia/RNSkDispatchQueue.h +3 -1
- package/cpp/rnskia/RNSkInfoParameter.h +12 -12
- package/cpp/rnskia/RNSkJsView.cpp +82 -81
- package/cpp/rnskia/RNSkJsView.h +45 -41
- package/cpp/rnskia/RNSkJsiViewApi.h +99 -89
- package/cpp/rnskia/RNSkManager.cpp +8 -7
- package/cpp/rnskia/RNSkManager.h +8 -6
- package/cpp/rnskia/RNSkPictureView.h +44 -37
- package/cpp/rnskia/RNSkPlatformContext.h +39 -28
- package/cpp/rnskia/RNSkValueApi.h +33 -34
- package/cpp/rnskia/RNSkView.h +108 -93
- package/cpp/rnskia/values/RNSkClockValue.h +63 -64
- package/cpp/rnskia/values/RNSkComputedValue.h +32 -30
- package/cpp/rnskia/values/RNSkReadonlyValue.h +60 -59
- package/cpp/rnskia/values/RNSkValue.h +38 -40
- package/cpp/utils/RNSkLog.h +9 -7
- package/cpp/utils/RNSkMeasureTime.h +7 -7
- package/cpp/utils/RNSkTimingInfo.h +27 -24
- package/ios/RNSkia-iOS/RNSkMetalCanvasProvider.h +8 -9
- package/ios/RNSkia-iOS/RNSkiOSPlatformContext.h +24 -23
- package/ios/RNSkia-iOS/RNSkiOSView.h +16 -13
- package/ios/RNSkia-iOS/SkiaUIView.h +9 -8
- package/lib/commonjs/dom/nodes/JsiSkDOM.js +6 -0
- package/lib/commonjs/dom/nodes/JsiSkDOM.js.map +1 -1
- package/lib/commonjs/dom/nodes/LayerNode.js +43 -0
- package/lib/commonjs/dom/nodes/LayerNode.js.map +1 -0
- package/lib/commonjs/dom/nodes/RenderNode.js +1 -1
- package/lib/commonjs/dom/nodes/RenderNode.js.map +1 -1
- package/lib/commonjs/dom/types/NodeType.js +1 -0
- package/lib/commonjs/dom/types/NodeType.js.map +1 -1
- package/lib/commonjs/dom/types/SkDOM.js.map +1 -1
- package/lib/commonjs/renderer/HostComponents.js +3 -0
- package/lib/commonjs/renderer/HostComponents.js.map +1 -1
- package/lib/commonjs/renderer/components/Group.js +19 -4
- package/lib/commonjs/renderer/components/Group.js.map +1 -1
- package/lib/commonjs/renderer/components/Paint.js +6 -1
- package/lib/commonjs/renderer/components/Paint.js.map +1 -1
- package/lib/commonjs/views/SkiaPictureView.js +3 -2
- package/lib/commonjs/views/SkiaPictureView.js.map +1 -1
- package/lib/commonjs/views/SkiaView.js +6 -3
- package/lib/commonjs/views/SkiaView.js.map +1 -1
- package/lib/module/dom/nodes/JsiSkDOM.js +5 -0
- package/lib/module/dom/nodes/JsiSkDOM.js.map +1 -1
- package/lib/module/dom/nodes/LayerNode.js +32 -0
- package/lib/module/dom/nodes/LayerNode.js.map +1 -0
- package/lib/module/dom/nodes/RenderNode.js +1 -1
- package/lib/module/dom/nodes/RenderNode.js.map +1 -1
- package/lib/module/dom/types/NodeType.js +1 -0
- package/lib/module/dom/types/NodeType.js.map +1 -1
- package/lib/module/dom/types/SkDOM.js.map +1 -1
- package/lib/module/renderer/HostComponents.js +3 -0
- package/lib/module/renderer/HostComponents.js.map +1 -1
- package/lib/module/renderer/components/Group.js +16 -3
- package/lib/module/renderer/components/Group.js.map +1 -1
- package/lib/module/renderer/components/Paint.js +7 -1
- package/lib/module/renderer/components/Paint.js.map +1 -1
- package/lib/module/views/SkiaPictureView.js +2 -2
- package/lib/module/views/SkiaPictureView.js.map +1 -1
- package/lib/module/views/SkiaView.js +4 -2
- package/lib/module/views/SkiaView.js.map +1 -1
- package/lib/typescript/src/dom/nodes/JsiSkDOM.d.ts +2 -0
- package/lib/typescript/src/dom/nodes/LayerNode.d.ts +8 -0
- package/lib/typescript/src/dom/types/NodeType.d.ts +1 -0
- package/lib/typescript/src/dom/types/SkDOM.d.ts +1 -0
- package/lib/typescript/src/renderer/HostComponents.d.ts +2 -1
- package/lib/typescript/src/renderer/components/Group.d.ts +5 -1
- package/lib/typescript/src/views/SkiaView.d.ts +3 -0
- package/libs/android/arm64-v8a/libskottie.a +0 -0
- package/libs/android/arm64-v8a/libsksg.a +0 -0
- package/libs/android/armeabi-v7a/libskottie.a +0 -0
- package/libs/android/armeabi-v7a/libsksg.a +0 -0
- package/libs/android/x86/libskottie.a +0 -0
- package/libs/android/x86/libsksg.a +0 -0
- package/libs/android/x86_64/libskottie.a +0 -0
- package/libs/android/x86_64/libsksg.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/Info.plist +42 -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/libsksg.xcframework/Info.plist +42 -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/libsvg.xcframework/Info.plist +5 -5
- 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 +3 -1
- package/src/dom/nodes/JsiSkDOM.ts +5 -0
- package/src/dom/nodes/LayerNode.ts +35 -0
- package/src/dom/nodes/RenderNode.ts +4 -3
- package/src/dom/types/NodeType.ts +1 -0
- package/src/dom/types/SkDOM.ts +1 -0
- package/src/renderer/HostComponents.ts +3 -0
- package/src/renderer/components/Group.tsx +16 -3
- package/src/renderer/components/Paint.tsx +7 -1
- package/src/views/SkiaPictureView.tsx +2 -3
- package/src/views/SkiaView.tsx +2 -2
|
@@ -4,330 +4,274 @@
|
|
|
4
4
|
#include <android/native_window.h>
|
|
5
5
|
#include <android/native_window_jni.h>
|
|
6
6
|
|
|
7
|
-
namespace RNSkia
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
7
|
+
namespace RNSkia {
|
|
8
|
+
/** Static members */
|
|
9
|
+
std::shared_ptr<DrawingContext> SkiaOpenGLRenderer::getThreadDrawingContext() {
|
|
10
|
+
auto threadId = std::this_thread::get_id();
|
|
11
|
+
if (threadContexts.count(threadId) == 0) {
|
|
12
|
+
auto drawingContext = std::make_shared<DrawingContext>();
|
|
13
|
+
drawingContext->glContext = EGL_NO_CONTEXT;
|
|
14
|
+
drawingContext->glDisplay = EGL_NO_DISPLAY;
|
|
15
|
+
drawingContext->glConfig = 0;
|
|
16
|
+
drawingContext->skContext = nullptr;
|
|
17
|
+
threadContexts.emplace(threadId, drawingContext);
|
|
18
|
+
}
|
|
19
|
+
return threadContexts.at(threadId);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
SkiaOpenGLRenderer::SkiaOpenGLRenderer(jobject surface) {
|
|
23
|
+
_nativeWindow =
|
|
24
|
+
ANativeWindow_fromSurface(facebook::jni::Environment::current(), surface);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
SkiaOpenGLRenderer::~SkiaOpenGLRenderer() {
|
|
28
|
+
// Release surface
|
|
29
|
+
ANativeWindow_release(_nativeWindow);
|
|
30
|
+
_nativeWindow = nullptr;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
void SkiaOpenGLRenderer::run(const std::function<void(SkCanvas *)> &cb,
|
|
34
|
+
int width, int height) {
|
|
35
|
+
switch (_renderState) {
|
|
36
|
+
case RenderState::Initializing: {
|
|
37
|
+
_renderState = RenderState::Rendering;
|
|
38
|
+
// Just let the case drop to drawing - we have initialized
|
|
39
|
+
// and we should be able to render (if the picture is set)
|
|
40
|
+
}
|
|
41
|
+
case RenderState::Rendering: {
|
|
42
|
+
// Make sure to initialize the rendering pipeline
|
|
43
|
+
if (!ensureInitialised()) {
|
|
44
|
+
break;
|
|
23
45
|
}
|
|
24
46
|
|
|
25
|
-
|
|
26
|
-
|
|
47
|
+
// Ensure we have the Skia surface to draw on. We need to
|
|
48
|
+
// pass width and height since the surface will be recreated
|
|
49
|
+
// when the view is resized.
|
|
50
|
+
if (!ensureSkiaSurface(width, height)) {
|
|
51
|
+
return;
|
|
27
52
|
}
|
|
28
53
|
|
|
29
|
-
|
|
30
|
-
//
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
}
|
|
54
|
+
if (cb != nullptr) {
|
|
55
|
+
// Reset Skia Context since it might be modified by another Skia View
|
|
56
|
+
// during rendering.
|
|
57
|
+
getThreadDrawingContext()->skContext->resetContext();
|
|
34
58
|
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
{
|
|
39
|
-
case RenderState::Initializing:
|
|
40
|
-
{
|
|
41
|
-
_renderState = RenderState::Rendering;
|
|
42
|
-
// Just let the case drop to drawing - we have initialized
|
|
43
|
-
// and we should be able to render (if the picture is set)
|
|
44
|
-
}
|
|
45
|
-
case RenderState::Rendering:
|
|
46
|
-
{
|
|
47
|
-
// Make sure to initialize the rendering pipeline
|
|
48
|
-
if (!ensureInitialised())
|
|
49
|
-
{
|
|
50
|
-
break;
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
// Ensure we have the Skia surface to draw on. We need to
|
|
54
|
-
// pass width and height since the surface will be recreated
|
|
55
|
-
// when the view is resized.
|
|
56
|
-
if (!ensureSkiaSurface(width, height))
|
|
57
|
-
{
|
|
58
|
-
return;
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
if (cb != nullptr)
|
|
62
|
-
{
|
|
63
|
-
// Reset Skia Context since it might be modified by another Skia View during
|
|
64
|
-
// rendering.
|
|
65
|
-
getThreadDrawingContext()->skContext->resetContext();
|
|
66
|
-
|
|
67
|
-
// Clear with transparent
|
|
68
|
-
glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
|
|
69
|
-
glClear(GL_COLOR_BUFFER_BIT);
|
|
70
|
-
|
|
71
|
-
// Draw picture into surface
|
|
72
|
-
cb(_skSurface->getCanvas());
|
|
73
|
-
|
|
74
|
-
// Flush
|
|
75
|
-
_skSurface->flush();
|
|
76
|
-
|
|
77
|
-
if (!eglSwapBuffers(getThreadDrawingContext()->glDisplay, _glSurface))
|
|
78
|
-
{
|
|
79
|
-
RNSkLogger::logToConsole(
|
|
80
|
-
"eglSwapBuffers failed: %d\n", eglGetError());
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
break;
|
|
84
|
-
}
|
|
85
|
-
case RenderState::Finishing:
|
|
86
|
-
{
|
|
87
|
-
_renderState = RenderState::Done;
|
|
88
|
-
|
|
89
|
-
// Release GL surface
|
|
90
|
-
if (_glSurface != EGL_NO_SURFACE && getThreadDrawingContext()->glDisplay != EGL_NO_DISPLAY)
|
|
91
|
-
{
|
|
92
|
-
eglDestroySurface(getThreadDrawingContext()->glDisplay, _glSurface);
|
|
93
|
-
_glSurface = EGL_NO_SURFACE;
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
// Release Skia Surface
|
|
97
|
-
_skSurface = nullptr;
|
|
98
|
-
|
|
99
|
-
break;
|
|
100
|
-
}
|
|
101
|
-
case RenderState::Done:
|
|
102
|
-
{
|
|
103
|
-
// Do nothing. We're done.
|
|
104
|
-
break;
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
}
|
|
59
|
+
// Clear with transparent
|
|
60
|
+
glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
|
|
61
|
+
glClear(GL_COLOR_BUFFER_BIT);
|
|
108
62
|
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
// Set up static OpenGL context
|
|
112
|
-
if (!initStaticGLContext())
|
|
113
|
-
{
|
|
114
|
-
return false;
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
// Set up OpenGL Surface
|
|
118
|
-
if (!initGLSurface())
|
|
119
|
-
{
|
|
120
|
-
return false;
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
// Init skia static context
|
|
124
|
-
if (!initStaticSkiaContext())
|
|
125
|
-
{
|
|
126
|
-
return false;
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
return true;
|
|
130
|
-
}
|
|
63
|
+
// Draw picture into surface
|
|
64
|
+
cb(_skSurface->getCanvas());
|
|
131
65
|
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
_renderState = RenderState::Finishing;
|
|
135
|
-
}
|
|
66
|
+
// Flush
|
|
67
|
+
_skSurface->flush();
|
|
136
68
|
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
{
|
|
141
|
-
return true;
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
getThreadDrawingContext()->glDisplay = eglGetDisplay(EGL_DEFAULT_DISPLAY);
|
|
145
|
-
if (getThreadDrawingContext()->glDisplay == EGL_NO_DISPLAY)
|
|
146
|
-
{
|
|
147
|
-
RNSkLogger::logToConsole("eglGetdisplay failed : %i", glGetError());
|
|
148
|
-
return false;
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
EGLint major;
|
|
152
|
-
EGLint minor;
|
|
153
|
-
if (!eglInitialize(getThreadDrawingContext()->glDisplay, &major, &minor))
|
|
154
|
-
{
|
|
155
|
-
RNSkLogger::logToConsole("eglInitialize failed : %i", glGetError());
|
|
156
|
-
return false;
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
EGLint att[] = {
|
|
160
|
-
EGL_RENDERABLE_TYPE,
|
|
161
|
-
EGL_OPENGL_ES2_BIT,
|
|
162
|
-
EGL_SURFACE_TYPE,
|
|
163
|
-
EGL_WINDOW_BIT,
|
|
164
|
-
EGL_ALPHA_SIZE,
|
|
165
|
-
8,
|
|
166
|
-
EGL_BLUE_SIZE,
|
|
167
|
-
8,
|
|
168
|
-
EGL_GREEN_SIZE,
|
|
169
|
-
8,
|
|
170
|
-
EGL_RED_SIZE,
|
|
171
|
-
8,
|
|
172
|
-
EGL_DEPTH_SIZE,
|
|
173
|
-
0,
|
|
174
|
-
EGL_STENCIL_SIZE,
|
|
175
|
-
0,
|
|
176
|
-
EGL_NONE};
|
|
177
|
-
|
|
178
|
-
EGLint numConfigs;
|
|
179
|
-
getThreadDrawingContext()->glConfig = 0;
|
|
180
|
-
if (!eglChooseConfig(getThreadDrawingContext()->glDisplay, att, &getThreadDrawingContext()->glConfig, 1, &numConfigs) ||
|
|
181
|
-
numConfigs == 0)
|
|
182
|
-
{
|
|
183
|
-
RNSkLogger::logToConsole(
|
|
184
|
-
"Failed to choose a config %d\n", eglGetError());
|
|
185
|
-
return false;
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
EGLint contextAttribs[] = {EGL_CONTEXT_CLIENT_VERSION, 2, EGL_NONE};
|
|
189
|
-
|
|
190
|
-
getThreadDrawingContext()->glContext = eglCreateContext(
|
|
191
|
-
getThreadDrawingContext()->glDisplay,
|
|
192
|
-
getThreadDrawingContext()->glConfig,
|
|
193
|
-
NULL,
|
|
194
|
-
contextAttribs);
|
|
195
|
-
|
|
196
|
-
if (getThreadDrawingContext()->glContext == EGL_NO_CONTEXT)
|
|
197
|
-
{
|
|
198
|
-
RNSkLogger::logToConsole(
|
|
199
|
-
"eglCreateContext failed: %d\n", eglGetError());
|
|
200
|
-
return false;
|
|
201
|
-
}
|
|
202
|
-
|
|
203
|
-
return true;
|
|
69
|
+
if (!eglSwapBuffers(getThreadDrawingContext()->glDisplay, _glSurface)) {
|
|
70
|
+
RNSkLogger::logToConsole("eglSwapBuffers failed: %d\n", eglGetError());
|
|
71
|
+
}
|
|
204
72
|
}
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
getThreadDrawingContext()->skContext = GrDirectContext::MakeGL(backendInterface);
|
|
216
|
-
if (getThreadDrawingContext()->skContext == nullptr)
|
|
217
|
-
{
|
|
218
|
-
RNSkLogger::logToConsole("GrDirectContext::MakeGL failed");
|
|
219
|
-
return false;
|
|
220
|
-
}
|
|
221
|
-
|
|
222
|
-
return true;
|
|
73
|
+
break;
|
|
74
|
+
}
|
|
75
|
+
case RenderState::Finishing: {
|
|
76
|
+
_renderState = RenderState::Done;
|
|
77
|
+
|
|
78
|
+
// Release GL surface
|
|
79
|
+
if (_glSurface != EGL_NO_SURFACE &&
|
|
80
|
+
getThreadDrawingContext()->glDisplay != EGL_NO_DISPLAY) {
|
|
81
|
+
eglDestroySurface(getThreadDrawingContext()->glDisplay, _glSurface);
|
|
82
|
+
_glSurface = EGL_NO_SURFACE;
|
|
223
83
|
}
|
|
224
84
|
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
85
|
+
// Release Skia Surface
|
|
86
|
+
_skSurface = nullptr;
|
|
87
|
+
|
|
88
|
+
break;
|
|
89
|
+
}
|
|
90
|
+
case RenderState::Done: {
|
|
91
|
+
// Do nothing. We're done.
|
|
92
|
+
break;
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
bool SkiaOpenGLRenderer::ensureInitialised() {
|
|
98
|
+
// Set up static OpenGL context
|
|
99
|
+
if (!initStaticGLContext()) {
|
|
100
|
+
return false;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
// Set up OpenGL Surface
|
|
104
|
+
if (!initGLSurface()) {
|
|
105
|
+
return false;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
// Init skia static context
|
|
109
|
+
if (!initStaticSkiaContext()) {
|
|
110
|
+
return false;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
return true;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
void SkiaOpenGLRenderer::teardown() { _renderState = RenderState::Finishing; }
|
|
117
|
+
|
|
118
|
+
bool SkiaOpenGLRenderer::initStaticGLContext() {
|
|
119
|
+
if (getThreadDrawingContext()->glContext != EGL_NO_CONTEXT) {
|
|
120
|
+
return true;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
getThreadDrawingContext()->glDisplay = eglGetDisplay(EGL_DEFAULT_DISPLAY);
|
|
124
|
+
if (getThreadDrawingContext()->glDisplay == EGL_NO_DISPLAY) {
|
|
125
|
+
RNSkLogger::logToConsole("eglGetdisplay failed : %i", glGetError());
|
|
126
|
+
return false;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
EGLint major;
|
|
130
|
+
EGLint minor;
|
|
131
|
+
if (!eglInitialize(getThreadDrawingContext()->glDisplay, &major, &minor)) {
|
|
132
|
+
RNSkLogger::logToConsole("eglInitialize failed : %i", glGetError());
|
|
133
|
+
return false;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
EGLint att[] = {EGL_RENDERABLE_TYPE,
|
|
137
|
+
EGL_OPENGL_ES2_BIT,
|
|
138
|
+
EGL_SURFACE_TYPE,
|
|
139
|
+
EGL_WINDOW_BIT,
|
|
140
|
+
EGL_ALPHA_SIZE,
|
|
141
|
+
8,
|
|
142
|
+
EGL_BLUE_SIZE,
|
|
143
|
+
8,
|
|
144
|
+
EGL_GREEN_SIZE,
|
|
145
|
+
8,
|
|
146
|
+
EGL_RED_SIZE,
|
|
147
|
+
8,
|
|
148
|
+
EGL_DEPTH_SIZE,
|
|
149
|
+
0,
|
|
150
|
+
EGL_STENCIL_SIZE,
|
|
151
|
+
0,
|
|
152
|
+
EGL_NONE};
|
|
153
|
+
|
|
154
|
+
EGLint numConfigs;
|
|
155
|
+
getThreadDrawingContext()->glConfig = 0;
|
|
156
|
+
if (!eglChooseConfig(getThreadDrawingContext()->glDisplay, att,
|
|
157
|
+
&getThreadDrawingContext()->glConfig, 1, &numConfigs) ||
|
|
158
|
+
numConfigs == 0) {
|
|
159
|
+
RNSkLogger::logToConsole("Failed to choose a config %d\n", eglGetError());
|
|
160
|
+
return false;
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
EGLint contextAttribs[] = {EGL_CONTEXT_CLIENT_VERSION, 2, EGL_NONE};
|
|
164
|
+
|
|
165
|
+
getThreadDrawingContext()->glContext = eglCreateContext(
|
|
166
|
+
getThreadDrawingContext()->glDisplay, getThreadDrawingContext()->glConfig,
|
|
167
|
+
NULL, contextAttribs);
|
|
168
|
+
|
|
169
|
+
if (getThreadDrawingContext()->glContext == EGL_NO_CONTEXT) {
|
|
170
|
+
RNSkLogger::logToConsole("eglCreateContext failed: %d\n", eglGetError());
|
|
171
|
+
return false;
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
return true;
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
bool SkiaOpenGLRenderer::initStaticSkiaContext() {
|
|
178
|
+
if (getThreadDrawingContext()->skContext != nullptr) {
|
|
179
|
+
return true;
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
// Create the Skia backend context
|
|
183
|
+
auto backendInterface = GrGLMakeNativeInterface();
|
|
184
|
+
getThreadDrawingContext()->skContext =
|
|
185
|
+
GrDirectContext::MakeGL(backendInterface);
|
|
186
|
+
if (getThreadDrawingContext()->skContext == nullptr) {
|
|
187
|
+
RNSkLogger::logToConsole("GrDirectContext::MakeGL failed");
|
|
188
|
+
return false;
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
return true;
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
bool SkiaOpenGLRenderer::initGLSurface() {
|
|
195
|
+
if (_nativeWindow == nullptr) {
|
|
196
|
+
return false;
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
if (_glSurface != EGL_NO_SURFACE) {
|
|
200
|
+
if (!eglMakeCurrent(getThreadDrawingContext()->glDisplay, _glSurface,
|
|
201
|
+
_glSurface, getThreadDrawingContext()->glContext)) {
|
|
202
|
+
RNSkLogger::logToConsole("eglMakeCurrent failed: %d\n", eglGetError());
|
|
203
|
+
return false;
|
|
273
204
|
}
|
|
205
|
+
return true;
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
// Create the opengl surface
|
|
209
|
+
_glSurface = eglCreateWindowSurface(getThreadDrawingContext()->glDisplay,
|
|
210
|
+
getThreadDrawingContext()->glConfig,
|
|
211
|
+
_nativeWindow, nullptr);
|
|
212
|
+
|
|
213
|
+
if (_glSurface == EGL_NO_SURFACE) {
|
|
214
|
+
RNSkLogger::logToConsole("eglCreateWindowSurface failed: %d\n",
|
|
215
|
+
eglGetError());
|
|
216
|
+
return false;
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
if (!eglMakeCurrent(getThreadDrawingContext()->glDisplay, _glSurface,
|
|
220
|
+
_glSurface, getThreadDrawingContext()->glContext)) {
|
|
221
|
+
RNSkLogger::logToConsole("eglMakeCurrent failed: %d\n", eglGetError());
|
|
222
|
+
return false;
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
return true;
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
bool SkiaOpenGLRenderer::ensureSkiaSurface(int width, int height) {
|
|
229
|
+
if (getThreadDrawingContext()->skContext == nullptr) {
|
|
230
|
+
return false;
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
if (_skSurface == nullptr || !_skRenderTarget.isValid() ||
|
|
234
|
+
_prevWidth != width || _prevHeight != height) {
|
|
235
|
+
glViewport(0, 0, width, height);
|
|
274
236
|
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
fbInfo.fFormat = 0x8058;
|
|
310
|
-
|
|
311
|
-
_skRenderTarget =
|
|
312
|
-
GrBackendRenderTarget(width, height, samples, stencil, fbInfo);
|
|
313
|
-
|
|
314
|
-
_skSurface = SkSurface::MakeFromBackendRenderTarget(
|
|
315
|
-
getThreadDrawingContext()->skContext.get(),
|
|
316
|
-
_skRenderTarget,
|
|
317
|
-
kBottomLeft_GrSurfaceOrigin,
|
|
318
|
-
kRGBA_8888_SkColorType,
|
|
319
|
-
nullptr,
|
|
320
|
-
nullptr);
|
|
321
|
-
|
|
322
|
-
if (!_skSurface)
|
|
323
|
-
{
|
|
324
|
-
RNSkLogger::logToConsole(
|
|
325
|
-
"JniSkiaDrawView::setupSurface - skSurface could not be created!");
|
|
326
|
-
return false;
|
|
327
|
-
}
|
|
328
|
-
|
|
329
|
-
return true;
|
|
330
|
-
}
|
|
331
|
-
return true;
|
|
237
|
+
_prevWidth = width;
|
|
238
|
+
_prevHeight = height;
|
|
239
|
+
|
|
240
|
+
GLint buffer;
|
|
241
|
+
glGetIntegerv(GL_FRAMEBUFFER_BINDING, &buffer);
|
|
242
|
+
|
|
243
|
+
GLint stencil;
|
|
244
|
+
glGetIntegerv(GL_STENCIL_BITS, &stencil);
|
|
245
|
+
|
|
246
|
+
GLint samples;
|
|
247
|
+
glGetIntegerv(GL_SAMPLES, &samples);
|
|
248
|
+
|
|
249
|
+
auto maxSamples =
|
|
250
|
+
getThreadDrawingContext()->skContext->maxSurfaceSampleCountForColorType(
|
|
251
|
+
kRGBA_8888_SkColorType);
|
|
252
|
+
|
|
253
|
+
if (samples > maxSamples)
|
|
254
|
+
samples = maxSamples;
|
|
255
|
+
|
|
256
|
+
GrGLFramebufferInfo fbInfo;
|
|
257
|
+
fbInfo.fFBOID = buffer;
|
|
258
|
+
fbInfo.fFormat = 0x8058;
|
|
259
|
+
|
|
260
|
+
_skRenderTarget =
|
|
261
|
+
GrBackendRenderTarget(width, height, samples, stencil, fbInfo);
|
|
262
|
+
|
|
263
|
+
_skSurface = SkSurface::MakeFromBackendRenderTarget(
|
|
264
|
+
getThreadDrawingContext()->skContext.get(), _skRenderTarget,
|
|
265
|
+
kBottomLeft_GrSurfaceOrigin, kRGBA_8888_SkColorType, nullptr, nullptr);
|
|
266
|
+
|
|
267
|
+
if (!_skSurface) {
|
|
268
|
+
RNSkLogger::logToConsole(
|
|
269
|
+
"JniSkiaDrawView::setupSurface - skSurface could not be created!");
|
|
270
|
+
return false;
|
|
332
271
|
}
|
|
333
|
-
|
|
272
|
+
|
|
273
|
+
return true;
|
|
274
|
+
}
|
|
275
|
+
return true;
|
|
276
|
+
}
|
|
277
|
+
} // namespace RNSkia
|