@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.
Files changed (167) hide show
  1. package/android/cpp/jni/JniLoad.cpp +5 -5
  2. package/android/cpp/jni/JniPlatformContext.cpp +107 -119
  3. package/android/cpp/jni/JniSkiaManager.cpp +18 -20
  4. package/android/cpp/jni/include/JniPlatformContext.h +41 -45
  5. package/android/cpp/jni/include/JniSkiaBaseView.h +52 -55
  6. package/android/cpp/jni/include/JniSkiaDrawView.h +72 -77
  7. package/android/cpp/jni/include/JniSkiaManager.h +51 -53
  8. package/android/cpp/jni/include/JniSkiaPictureView.h +74 -78
  9. package/android/cpp/rnskia-android/RNSkAndroidPlatformContext.h +36 -45
  10. package/android/cpp/rnskia-android/RNSkAndroidView.h +87 -92
  11. package/android/cpp/rnskia-android/RNSkOpenGLCanvasProvider.cpp +62 -65
  12. package/android/cpp/rnskia-android/RNSkOpenGLCanvasProvider.h +20 -17
  13. package/android/cpp/rnskia-android/SkiaOpenGLRenderer.cpp +257 -313
  14. package/android/cpp/rnskia-android/SkiaOpenGLRenderer.h +107 -110
  15. package/cpp/api/JsiSkApi.h +66 -62
  16. package/cpp/api/JsiSkCanvas.h +38 -30
  17. package/cpp/api/JsiSkColor.h +58 -56
  18. package/cpp/api/JsiSkColorFilter.h +5 -3
  19. package/cpp/api/JsiSkColorFilterFactory.h +23 -21
  20. package/cpp/api/JsiSkContourMeasure.h +74 -85
  21. package/cpp/api/JsiSkContourMeasureIter.h +68 -75
  22. package/cpp/api/JsiSkData.h +16 -22
  23. package/cpp/api/JsiSkDataFactory.h +86 -79
  24. package/cpp/api/JsiSkFont.h +286 -311
  25. package/cpp/api/JsiSkHostObjects.h +15 -16
  26. package/cpp/api/JsiSkImage.h +107 -103
  27. package/cpp/api/JsiSkImageFactory.h +34 -36
  28. package/cpp/api/JsiSkImageFilter.h +5 -3
  29. package/cpp/api/JsiSkImageFilterFactory.h +71 -68
  30. package/cpp/api/JsiSkImageInfo.h +41 -38
  31. package/cpp/api/JsiSkMaskFilter.h +5 -3
  32. package/cpp/api/JsiSkMaskFilterFactory.h +2 -3
  33. package/cpp/api/JsiSkMatrix.h +26 -36
  34. package/cpp/api/JsiSkPaint.h +20 -13
  35. package/cpp/api/JsiSkPath.h +70 -85
  36. package/cpp/api/JsiSkPathEffect.h +5 -3
  37. package/cpp/api/JsiSkPathEffectFactory.h +33 -28
  38. package/cpp/api/JsiSkPathFactory.h +68 -67
  39. package/cpp/api/JsiSkPicture.h +28 -22
  40. package/cpp/api/JsiSkPictureFactory.h +13 -12
  41. package/cpp/api/JsiSkPictureRecorder.h +21 -19
  42. package/cpp/api/JsiSkPoint.h +6 -8
  43. package/cpp/api/JsiSkRRect.h +11 -7
  44. package/cpp/api/JsiSkRSXform.h +82 -85
  45. package/cpp/api/JsiSkRect.h +9 -9
  46. package/cpp/api/JsiSkRuntimeEffect.h +182 -186
  47. package/cpp/api/JsiSkRuntimeEffectFactory.h +10 -11
  48. package/cpp/api/JsiSkRuntimeShaderBuilder.h +64 -61
  49. package/cpp/api/JsiSkSVG.h +4 -5
  50. package/cpp/api/JsiSkSVGFactory.h +28 -27
  51. package/cpp/api/JsiSkShader.h +3 -2
  52. package/cpp/api/JsiSkShaderFactory.h +37 -25
  53. package/cpp/api/JsiSkSurface.h +44 -40
  54. package/cpp/api/JsiSkSurfaceFactory.h +22 -22
  55. package/cpp/api/JsiSkTextBlob.h +28 -31
  56. package/cpp/api/JsiSkTextBlobFactory.h +88 -87
  57. package/cpp/api/JsiSkTypeface.h +6 -5
  58. package/cpp/api/JsiSkTypefaceFactory.h +22 -21
  59. package/cpp/api/JsiSkVertices.h +137 -124
  60. package/cpp/api/third_party/CSSColorParser.cpp +161 -174
  61. package/cpp/api/third_party/CSSColorParser.h +172 -96
  62. package/cpp/jsi/JsiHostObject.cpp +11 -9
  63. package/cpp/jsi/JsiHostObject.h +31 -24
  64. package/cpp/jsi/JsiSimpleValueWrapper.h +74 -83
  65. package/cpp/jsi/JsiValueWrapper.h +52 -54
  66. package/cpp/rnskia/RNSkAnimation.h +26 -29
  67. package/cpp/rnskia/RNSkDispatchQueue.cpp +50 -61
  68. package/cpp/rnskia/RNSkDispatchQueue.h +3 -1
  69. package/cpp/rnskia/RNSkInfoParameter.h +12 -12
  70. package/cpp/rnskia/RNSkJsView.cpp +82 -81
  71. package/cpp/rnskia/RNSkJsView.h +45 -41
  72. package/cpp/rnskia/RNSkJsiViewApi.h +99 -89
  73. package/cpp/rnskia/RNSkManager.cpp +8 -7
  74. package/cpp/rnskia/RNSkManager.h +8 -6
  75. package/cpp/rnskia/RNSkPictureView.h +44 -37
  76. package/cpp/rnskia/RNSkPlatformContext.h +39 -28
  77. package/cpp/rnskia/RNSkValueApi.h +33 -34
  78. package/cpp/rnskia/RNSkView.h +108 -93
  79. package/cpp/rnskia/values/RNSkClockValue.h +63 -64
  80. package/cpp/rnskia/values/RNSkComputedValue.h +32 -30
  81. package/cpp/rnskia/values/RNSkReadonlyValue.h +60 -59
  82. package/cpp/rnskia/values/RNSkValue.h +38 -40
  83. package/cpp/utils/RNSkLog.h +9 -7
  84. package/cpp/utils/RNSkMeasureTime.h +7 -7
  85. package/cpp/utils/RNSkTimingInfo.h +27 -24
  86. package/ios/RNSkia-iOS/RNSkMetalCanvasProvider.h +8 -9
  87. package/ios/RNSkia-iOS/RNSkiOSPlatformContext.h +24 -23
  88. package/ios/RNSkia-iOS/RNSkiOSView.h +16 -13
  89. package/ios/RNSkia-iOS/SkiaUIView.h +9 -8
  90. package/lib/commonjs/dom/nodes/JsiSkDOM.js +6 -0
  91. package/lib/commonjs/dom/nodes/JsiSkDOM.js.map +1 -1
  92. package/lib/commonjs/dom/nodes/LayerNode.js +43 -0
  93. package/lib/commonjs/dom/nodes/LayerNode.js.map +1 -0
  94. package/lib/commonjs/dom/nodes/RenderNode.js +1 -1
  95. package/lib/commonjs/dom/nodes/RenderNode.js.map +1 -1
  96. package/lib/commonjs/dom/types/NodeType.js +1 -0
  97. package/lib/commonjs/dom/types/NodeType.js.map +1 -1
  98. package/lib/commonjs/dom/types/SkDOM.js.map +1 -1
  99. package/lib/commonjs/renderer/HostComponents.js +3 -0
  100. package/lib/commonjs/renderer/HostComponents.js.map +1 -1
  101. package/lib/commonjs/renderer/components/Group.js +19 -4
  102. package/lib/commonjs/renderer/components/Group.js.map +1 -1
  103. package/lib/commonjs/renderer/components/Paint.js +6 -1
  104. package/lib/commonjs/renderer/components/Paint.js.map +1 -1
  105. package/lib/commonjs/views/SkiaPictureView.js +3 -2
  106. package/lib/commonjs/views/SkiaPictureView.js.map +1 -1
  107. package/lib/commonjs/views/SkiaView.js +6 -3
  108. package/lib/commonjs/views/SkiaView.js.map +1 -1
  109. package/lib/module/dom/nodes/JsiSkDOM.js +5 -0
  110. package/lib/module/dom/nodes/JsiSkDOM.js.map +1 -1
  111. package/lib/module/dom/nodes/LayerNode.js +32 -0
  112. package/lib/module/dom/nodes/LayerNode.js.map +1 -0
  113. package/lib/module/dom/nodes/RenderNode.js +1 -1
  114. package/lib/module/dom/nodes/RenderNode.js.map +1 -1
  115. package/lib/module/dom/types/NodeType.js +1 -0
  116. package/lib/module/dom/types/NodeType.js.map +1 -1
  117. package/lib/module/dom/types/SkDOM.js.map +1 -1
  118. package/lib/module/renderer/HostComponents.js +3 -0
  119. package/lib/module/renderer/HostComponents.js.map +1 -1
  120. package/lib/module/renderer/components/Group.js +16 -3
  121. package/lib/module/renderer/components/Group.js.map +1 -1
  122. package/lib/module/renderer/components/Paint.js +7 -1
  123. package/lib/module/renderer/components/Paint.js.map +1 -1
  124. package/lib/module/views/SkiaPictureView.js +2 -2
  125. package/lib/module/views/SkiaPictureView.js.map +1 -1
  126. package/lib/module/views/SkiaView.js +4 -2
  127. package/lib/module/views/SkiaView.js.map +1 -1
  128. package/lib/typescript/src/dom/nodes/JsiSkDOM.d.ts +2 -0
  129. package/lib/typescript/src/dom/nodes/LayerNode.d.ts +8 -0
  130. package/lib/typescript/src/dom/types/NodeType.d.ts +1 -0
  131. package/lib/typescript/src/dom/types/SkDOM.d.ts +1 -0
  132. package/lib/typescript/src/renderer/HostComponents.d.ts +2 -1
  133. package/lib/typescript/src/renderer/components/Group.d.ts +5 -1
  134. package/lib/typescript/src/views/SkiaView.d.ts +3 -0
  135. package/libs/android/arm64-v8a/libskottie.a +0 -0
  136. package/libs/android/arm64-v8a/libsksg.a +0 -0
  137. package/libs/android/armeabi-v7a/libskottie.a +0 -0
  138. package/libs/android/armeabi-v7a/libsksg.a +0 -0
  139. package/libs/android/x86/libskottie.a +0 -0
  140. package/libs/android/x86/libsksg.a +0 -0
  141. package/libs/android/x86_64/libskottie.a +0 -0
  142. package/libs/android/x86_64/libsksg.a +0 -0
  143. package/libs/ios/libskia.xcframework/ios-arm64_arm64e/libskia.a +0 -0
  144. package/libs/ios/libskia.xcframework/ios-arm64_arm64e_x86_64-simulator/libskia.a +0 -0
  145. package/libs/ios/libskottie.xcframework/Info.plist +42 -0
  146. package/libs/ios/libskottie.xcframework/ios-arm64_arm64e/libskottie.a +0 -0
  147. package/libs/ios/libskottie.xcframework/ios-arm64_arm64e_x86_64-simulator/libskottie.a +0 -0
  148. package/libs/ios/libsksg.xcframework/Info.plist +42 -0
  149. package/libs/ios/libsksg.xcframework/ios-arm64_arm64e/libsksg.a +0 -0
  150. package/libs/ios/libsksg.xcframework/ios-arm64_arm64e_x86_64-simulator/libsksg.a +0 -0
  151. package/libs/ios/libskshaper.xcframework/Info.plist +5 -5
  152. package/libs/ios/libskshaper.xcframework/ios-arm64_arm64e/libskshaper.a +0 -0
  153. package/libs/ios/libskshaper.xcframework/ios-arm64_arm64e_x86_64-simulator/libskshaper.a +0 -0
  154. package/libs/ios/libsvg.xcframework/Info.plist +5 -5
  155. package/libs/ios/libsvg.xcframework/ios-arm64_arm64e/libsvg.a +0 -0
  156. package/libs/ios/libsvg.xcframework/ios-arm64_arm64e_x86_64-simulator/libsvg.a +0 -0
  157. package/package.json +3 -1
  158. package/src/dom/nodes/JsiSkDOM.ts +5 -0
  159. package/src/dom/nodes/LayerNode.ts +35 -0
  160. package/src/dom/nodes/RenderNode.ts +4 -3
  161. package/src/dom/types/NodeType.ts +1 -0
  162. package/src/dom/types/SkDOM.ts +1 -0
  163. package/src/renderer/HostComponents.ts +3 -0
  164. package/src/renderer/components/Group.tsx +16 -3
  165. package/src/renderer/components/Paint.tsx +7 -1
  166. package/src/views/SkiaPictureView.tsx +2 -3
  167. 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
- /** Static members */
10
- std::shared_ptr<DrawingContext> SkiaOpenGLRenderer::getThreadDrawingContext()
11
- {
12
- auto threadId = std::this_thread::get_id();
13
- if (threadContexts.count(threadId) == 0)
14
- {
15
- auto drawingContext = std::make_shared<DrawingContext>();
16
- drawingContext->glContext = EGL_NO_CONTEXT;
17
- drawingContext->glDisplay = EGL_NO_DISPLAY;
18
- drawingContext->glConfig = 0;
19
- drawingContext->skContext = nullptr;
20
- threadContexts.emplace(threadId, drawingContext);
21
- }
22
- return threadContexts.at(threadId);
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
- SkiaOpenGLRenderer::SkiaOpenGLRenderer(jobject surface) {
26
- _nativeWindow = ANativeWindow_fromSurface(facebook::jni::Environment::current(), surface);
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
- SkiaOpenGLRenderer::~SkiaOpenGLRenderer() {
30
- // Release surface
31
- ANativeWindow_release(_nativeWindow);
32
- _nativeWindow = nullptr;
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
- void SkiaOpenGLRenderer::run(const std::function<void(SkCanvas *)> &cb, int width, int height)
36
- {
37
- switch (_renderState)
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
- bool SkiaOpenGLRenderer::ensureInitialised()
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
- void SkiaOpenGLRenderer::teardown()
133
- {
134
- _renderState = RenderState::Finishing;
135
- }
66
+ // Flush
67
+ _skSurface->flush();
136
68
 
137
- bool SkiaOpenGLRenderer::initStaticGLContext()
138
- {
139
- if (getThreadDrawingContext()->glContext != EGL_NO_CONTEXT)
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
- bool SkiaOpenGLRenderer::initStaticSkiaContext()
207
- {
208
- if (getThreadDrawingContext()->skContext != nullptr)
209
- {
210
- return true;
211
- }
212
-
213
- // Create the Skia backend context
214
- auto backendInterface = GrGLMakeNativeInterface();
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
- bool SkiaOpenGLRenderer::initGLSurface()
226
- {
227
- if (_nativeWindow == nullptr)
228
- {
229
- return false;
230
- }
231
-
232
- if (_glSurface != EGL_NO_SURFACE)
233
- {
234
- if (!eglMakeCurrent(
235
- getThreadDrawingContext()->glDisplay,
236
- _glSurface,
237
- _glSurface,
238
- getThreadDrawingContext()->glContext))
239
- {
240
- RNSkLogger::logToConsole(
241
- "eglMakeCurrent failed: %d\n", eglGetError());
242
- return false;
243
- }
244
- return true;
245
- }
246
-
247
- // Create the opengl surface
248
- _glSurface =
249
- eglCreateWindowSurface(
250
- getThreadDrawingContext()->glDisplay,
251
- getThreadDrawingContext()->glConfig,
252
- _nativeWindow,
253
- nullptr);
254
-
255
- if (_glSurface == EGL_NO_SURFACE)
256
- {
257
- RNSkLogger::logToConsole(
258
- "eglCreateWindowSurface failed: %d\n", eglGetError());
259
- return false;
260
- }
261
-
262
- if (!eglMakeCurrent(
263
- getThreadDrawingContext()->glDisplay,
264
- _glSurface,
265
- _glSurface,
266
- getThreadDrawingContext()->glContext))
267
- {
268
- RNSkLogger::logToConsole("eglMakeCurrent failed: %d\n", eglGetError());
269
- return false;
270
- }
271
-
272
- return true;
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
- bool SkiaOpenGLRenderer::ensureSkiaSurface(int width, int height)
276
- {
277
- if (getThreadDrawingContext()->skContext == nullptr)
278
- {
279
- return false;
280
- }
281
-
282
- if (_skSurface == nullptr ||
283
- !_skRenderTarget.isValid() ||
284
- _prevWidth != width ||
285
- _prevHeight != height)
286
- {
287
- glViewport(0, 0, width, height);
288
-
289
- _prevWidth = width;
290
- _prevHeight = height;
291
-
292
- GLint buffer;
293
- glGetIntegerv(GL_FRAMEBUFFER_BINDING, &buffer);
294
-
295
- GLint stencil;
296
- glGetIntegerv(GL_STENCIL_BITS, &stencil);
297
-
298
- GLint samples;
299
- glGetIntegerv(GL_SAMPLES, &samples);
300
-
301
- auto maxSamples = getThreadDrawingContext()->skContext->maxSurfaceSampleCountForColorType(
302
- kRGBA_8888_SkColorType);
303
-
304
- if (samples > maxSamples)
305
- samples = maxSamples;
306
-
307
- GrGLFramebufferInfo fbInfo;
308
- fbInfo.fFBOID = buffer;
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