react-native-skia 3.0.1 → 3.0.3

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 (269) hide show
  1. package/Package.swift +14 -13
  2. package/README.md +19 -2
  3. package/android/CMakeLists.txt +13 -42
  4. package/android/build.gradle +54 -63
  5. package/android/cpp/jni/JniLoad.cpp +2 -4
  6. package/android/cpp/jni/include/JniSkiaView.h +123 -0
  7. package/android/cpp/rnskia-android/{RNSkOpenGLCanvasProvider.cpp → RNSkAndroidCanvasProvider.cpp} +45 -100
  8. package/android/cpp/rnskia-android/{RNSkOpenGLCanvasProvider.h → RNSkAndroidCanvasProvider.h} +24 -22
  9. package/android/cpp/rnskia-android/RNSkAndroidPlatformContext.h +0 -83
  10. package/android/cpp/rnskia-android/RNSkAndroidVideo.cpp +0 -8
  11. package/android/src/main/java/com/reactnative/skia/RNSkiaPackage.java +1 -2
  12. package/android/src/main/java/com/reactnative/skia/SkiaSurfaceView.java +1 -3
  13. package/android/src/main/java/com/reactnative/skia/SkiaTextureView.java +1 -17
  14. package/android/src/main/java/com/reactnative/skia/{SkiaBaseView.java → SkiaView.java} +78 -16
  15. package/android/src/main/java/com/reactnative/skia/SkiaViewManager.java +85 -0
  16. package/apple/MetalLayerColorSpace.mm +10 -12
  17. package/apple/RNSkApplePlatformContext.h +12 -14
  18. package/apple/RNSkApplePlatformContext.mm +19 -112
  19. package/apple/RNSkMetalCanvasProvider.h +14 -19
  20. package/apple/RNSkMetalCanvasProvider.mm +39 -70
  21. package/apple/RNSkiaModule.mm +10 -0
  22. package/apple/SkiaView.h +20 -0
  23. package/apple/SkiaView.mm +210 -0
  24. package/cpp/api/JsiSkApi.h +2 -13
  25. package/cpp/api/JsiSkCanvas.h +4 -18
  26. package/cpp/api/JsiSkGraphiteContext.h +1 -5
  27. package/cpp/api/JsiSkGraphiteRecording.h +1 -5
  28. package/cpp/api/JsiSkImage.h +7 -41
  29. package/cpp/api/JsiSkImageFactory.h +0 -14
  30. package/cpp/api/JsiSkSurface.h +2 -16
  31. package/cpp/api/JsiSkSurfaceFactory.h +0 -8
  32. package/cpp/rnskia/RNDawnContext.h +3 -2
  33. package/cpp/rnskia/RNDawnInterop.cpp +0 -4
  34. package/cpp/rnskia/RNDawnUtils.h +12 -1
  35. package/cpp/rnskia/RNDawnWindowContext.cpp +12 -1
  36. package/cpp/rnskia/RNDawnWindowContext.h +19 -7
  37. package/cpp/rnskia/RNMetalLayerColorSpace.h +4 -2
  38. package/cpp/rnskia/RNSkCanvasProvider.h +231 -0
  39. package/cpp/rnskia/RNSkGraphiteProducer.cpp +36 -14
  40. package/cpp/rnskia/RNSkGraphiteProducer.h +23 -8
  41. package/cpp/rnskia/RNSkGraphiteTarget.h +396 -0
  42. package/cpp/rnskia/RNSkJsiViewApi.h +9 -18
  43. package/cpp/rnskia/RNSkPlatformContext.h +17 -15
  44. package/cpp/rnskia/RNSkView.h +362 -246
  45. package/jestSetup.js +1 -3
  46. package/lib/commonjs/Platform/Platform.web.js +1 -1
  47. package/lib/commonjs/Platform/Platform.web.js.map +1 -1
  48. package/lib/commonjs/external/reanimated/interpolators.js +1 -1
  49. package/lib/commonjs/external/reanimated/interpolators.js.map +1 -1
  50. package/lib/commonjs/index.d.ts +1 -3
  51. package/lib/commonjs/index.js +3 -12
  52. package/lib/commonjs/index.js.map +1 -1
  53. package/lib/commonjs/mock/index.js +0 -1
  54. package/lib/commonjs/mock/index.js.map +1 -1
  55. package/lib/commonjs/renderer/Canvas.d.ts +15 -12
  56. package/lib/commonjs/renderer/Canvas.js +25 -21
  57. package/lib/commonjs/renderer/Canvas.js.map +1 -1
  58. package/lib/commonjs/skia/types/Graphite.d.ts +3 -3
  59. package/lib/commonjs/skia/types/Graphite.js.map +1 -1
  60. package/lib/commonjs/skia/types/Image/ImageFactory.d.ts +2 -2
  61. package/lib/commonjs/skia/types/Image/ImageFactory.js.map +1 -1
  62. package/lib/commonjs/skia/types/Skia.d.ts +1 -2
  63. package/lib/commonjs/skia/types/Skia.js.map +1 -1
  64. package/lib/commonjs/skia/types/Surface/SurfaceFactory.d.ts +1 -1
  65. package/lib/commonjs/skia/types/Surface/SurfaceFactory.js.map +1 -1
  66. package/lib/commonjs/specs/NativeSkiaModule.web.d.ts +5 -4
  67. package/lib/commonjs/specs/NativeSkiaModule.web.js +5 -9
  68. package/lib/commonjs/specs/NativeSkiaModule.web.js.map +1 -1
  69. package/lib/{typescript/src/specs/SkiaPictureViewNativeComponent.d.ts → commonjs/specs/SkiaViewNativeComponent.d.ts} +0 -3
  70. package/lib/commonjs/specs/{SkiaPictureViewNativeComponent.js → SkiaViewNativeComponent.js} +2 -2
  71. package/lib/commonjs/specs/SkiaViewNativeComponent.js.map +1 -0
  72. package/lib/commonjs/specs/SkiaViewNativeComponent.web.d.ts +10 -0
  73. package/lib/commonjs/specs/SkiaViewNativeComponent.web.js +27 -0
  74. package/lib/commonjs/specs/SkiaViewNativeComponent.web.js.map +1 -0
  75. package/lib/commonjs/views/SkiaGraphiteView.d.ts +3 -4
  76. package/lib/commonjs/views/SkiaGraphiteView.js +23 -12
  77. package/lib/commonjs/views/SkiaGraphiteView.js.map +1 -1
  78. package/lib/commonjs/views/SkiaPictureView.d.ts +4 -1
  79. package/lib/commonjs/views/SkiaPictureView.js +12 -10
  80. package/lib/commonjs/views/SkiaPictureView.js.map +1 -1
  81. package/lib/commonjs/views/SkiaView.web.d.ts +12 -0
  82. package/lib/commonjs/views/{SkiaGraphiteView.web.js → SkiaView.web.js} +82 -38
  83. package/lib/commonjs/views/SkiaView.web.js.map +1 -0
  84. package/lib/commonjs/views/SkiaWebRenderer.js +1 -1
  85. package/lib/commonjs/views/SkiaWebRenderer.js.map +1 -1
  86. package/lib/commonjs/views/android.d.ts +6 -0
  87. package/lib/commonjs/views/android.js +17 -0
  88. package/lib/commonjs/views/android.js.map +1 -0
  89. package/lib/commonjs/views/types.d.ts +3 -12
  90. package/lib/commonjs/views/types.js.map +1 -1
  91. package/lib/module/Platform/Platform.web.js +1 -1
  92. package/lib/module/Platform/Platform.web.js.map +1 -1
  93. package/lib/module/external/reanimated/interpolators.js +1 -1
  94. package/lib/module/external/reanimated/interpolators.js.map +1 -1
  95. package/lib/module/index.d.ts +1 -3
  96. package/lib/module/index.js +1 -3
  97. package/lib/module/index.js.map +1 -1
  98. package/lib/module/mock/index.js +0 -1
  99. package/lib/module/mock/index.js.map +1 -1
  100. package/lib/module/renderer/Canvas.d.ts +15 -12
  101. package/lib/module/renderer/Canvas.js +25 -20
  102. package/lib/module/renderer/Canvas.js.map +1 -1
  103. package/lib/module/skia/types/Graphite.d.ts +3 -3
  104. package/lib/module/skia/types/Graphite.js.map +1 -1
  105. package/lib/module/skia/types/Image/ImageFactory.d.ts +2 -2
  106. package/lib/module/skia/types/Image/ImageFactory.js.map +1 -1
  107. package/lib/module/skia/types/Skia.d.ts +1 -2
  108. package/lib/module/skia/types/Skia.js.map +1 -1
  109. package/lib/module/skia/types/Surface/SurfaceFactory.d.ts +1 -1
  110. package/lib/module/skia/types/Surface/SurfaceFactory.js.map +1 -1
  111. package/lib/module/specs/NativeSkiaModule.web.d.ts +5 -4
  112. package/lib/module/specs/NativeSkiaModule.web.js +5 -9
  113. package/lib/module/specs/NativeSkiaModule.web.js.map +1 -1
  114. package/lib/{commonjs/specs/SkiaPictureViewNativeComponent.d.ts → module/specs/SkiaViewNativeComponent.d.ts} +0 -3
  115. package/lib/module/specs/{SkiaPictureViewNativeComponent.js → SkiaViewNativeComponent.js} +2 -2
  116. package/lib/module/specs/SkiaViewNativeComponent.js.map +1 -0
  117. package/lib/module/specs/SkiaViewNativeComponent.web.d.ts +10 -0
  118. package/lib/module/specs/SkiaViewNativeComponent.web.js +21 -0
  119. package/lib/module/specs/SkiaViewNativeComponent.web.js.map +1 -0
  120. package/lib/module/views/SkiaGraphiteView.d.ts +3 -4
  121. package/lib/module/views/SkiaGraphiteView.js +23 -12
  122. package/lib/module/views/SkiaGraphiteView.js.map +1 -1
  123. package/lib/module/views/SkiaPictureView.d.ts +4 -1
  124. package/lib/module/views/SkiaPictureView.js +12 -10
  125. package/lib/module/views/SkiaPictureView.js.map +1 -1
  126. package/lib/module/views/SkiaView.web.d.ts +12 -0
  127. package/lib/module/views/{SkiaGraphiteView.web.js → SkiaView.web.js} +80 -36
  128. package/lib/module/views/SkiaView.web.js.map +1 -0
  129. package/lib/module/views/SkiaWebRenderer.js +1 -1
  130. package/lib/module/views/SkiaWebRenderer.js.map +1 -1
  131. package/lib/module/views/android.d.ts +6 -0
  132. package/lib/module/views/android.js +10 -0
  133. package/lib/module/views/android.js.map +1 -0
  134. package/lib/module/views/types.d.ts +3 -12
  135. package/lib/module/views/types.js.map +1 -1
  136. package/lib/typescript/src/index.d.ts +1 -3
  137. package/lib/typescript/src/renderer/Canvas.d.ts +15 -12
  138. package/lib/typescript/src/skia/types/Graphite.d.ts +3 -3
  139. package/lib/typescript/src/skia/types/Image/ImageFactory.d.ts +2 -2
  140. package/lib/typescript/src/skia/types/Skia.d.ts +1 -2
  141. package/lib/typescript/src/skia/types/Surface/SurfaceFactory.d.ts +1 -1
  142. package/lib/typescript/src/specs/NativeSkiaModule.web.d.ts +5 -4
  143. package/lib/{module/specs/SkiaPictureViewNativeComponent.d.ts → typescript/src/specs/SkiaViewNativeComponent.d.ts} +0 -3
  144. package/lib/typescript/src/specs/SkiaViewNativeComponent.web.d.ts +10 -0
  145. package/lib/typescript/src/views/SkiaGraphiteView.d.ts +3 -4
  146. package/lib/typescript/src/views/SkiaPictureView.d.ts +4 -1
  147. package/lib/typescript/src/views/SkiaView.web.d.ts +12 -0
  148. package/lib/typescript/src/views/android.d.ts +6 -0
  149. package/lib/typescript/src/views/types.d.ts +3 -12
  150. package/package.json +5 -13
  151. package/react-native-skia.podspec +34 -58
  152. package/src/Platform/Platform.web.tsx +1 -1
  153. package/src/external/reanimated/interpolators.ts +1 -1
  154. package/src/index.ts +1 -3
  155. package/src/mock/index.ts +0 -1
  156. package/src/renderer/Canvas.tsx +24 -28
  157. package/src/skia/types/Graphite.ts +3 -3
  158. package/src/skia/types/Image/ImageFactory.ts +2 -2
  159. package/src/skia/types/Skia.ts +1 -2
  160. package/src/skia/types/Surface/SurfaceFactory.ts +1 -1
  161. package/src/specs/NativeSkiaModule.web.ts +9 -21
  162. package/src/specs/{SkiaPictureViewNativeComponent.ts → SkiaViewNativeComponent.ts} +1 -4
  163. package/src/specs/{SkiaPictureViewNativeComponent.web.ts → SkiaViewNativeComponent.web.ts} +8 -10
  164. package/src/views/SkiaGraphiteView.tsx +27 -16
  165. package/src/views/SkiaPictureView.tsx +11 -10
  166. package/src/views/{SkiaGraphiteView.web.tsx → SkiaView.web.tsx} +100 -53
  167. package/src/views/SkiaWebRenderer.ts +1 -1
  168. package/src/views/android.ts +16 -0
  169. package/src/views/types.ts +3 -14
  170. package/android/cpp/jni/include/JniSkiaBaseView.h +0 -92
  171. package/android/cpp/jni/include/JniSkiaGraphiteView.h +0 -176
  172. package/android/cpp/jni/include/JniSkiaPictureView.h +0 -172
  173. package/android/cpp/rnskia-android/GrAHardwareBufferUtils.cpp +0 -245
  174. package/android/cpp/rnskia-android/GrAHardwareBufferUtils.h +0 -33
  175. package/android/cpp/rnskia-android/OpenGLContext.h +0 -248
  176. package/android/cpp/rnskia-android/OpenGLWindowContext.cpp +0 -67
  177. package/android/cpp/rnskia-android/OpenGLWindowContext.h +0 -75
  178. package/android/cpp/rnskia-android/RNSkAndroidView.h +0 -67
  179. package/android/cpp/rnskia-android/gl/Context.h +0 -80
  180. package/android/cpp/rnskia-android/gl/Display.h +0 -123
  181. package/android/cpp/rnskia-android/gl/Error.cpp +0 -45
  182. package/android/cpp/rnskia-android/gl/Error.h +0 -8
  183. package/android/cpp/rnskia-android/gl/Surface.h +0 -43
  184. package/android/src/main/java/com/reactnative/skia/SkiaBaseViewManager.java +0 -65
  185. package/android/src/main/java/com/reactnative/skia/SkiaGraphiteView.java +0 -78
  186. package/android/src/main/java/com/reactnative/skia/SkiaGraphiteViewManager.java +0 -32
  187. package/android/src/main/java/com/reactnative/skia/SkiaPictureView.java +0 -105
  188. package/android/src/main/java/com/reactnative/skia/SkiaPictureViewManager.java +0 -44
  189. package/apple/MetalContext.h +0 -116
  190. package/apple/MetalContext.mm +0 -38
  191. package/apple/MetalWindowContext.h +0 -42
  192. package/apple/MetalWindowContext.mm +0 -95
  193. package/apple/RNSkAppleView.h +0 -49
  194. package/apple/RNSkAppleView.mm +0 -35
  195. package/apple/SkiaCVPixelBufferUtils.h +0 -122
  196. package/apple/SkiaCVPixelBufferUtils.mm +0 -535
  197. package/apple/SkiaGraphiteView.h +0 -26
  198. package/apple/SkiaGraphiteView.mm +0 -180
  199. package/apple/SkiaPictureView.h +0 -7
  200. package/apple/SkiaPictureView.mm +0 -70
  201. package/apple/SkiaUIView.h +0 -31
  202. package/apple/SkiaUIView.mm +0 -164
  203. package/cpp/rnskia/RNSkGraphiteView.h +0 -708
  204. package/cpp/rnskia/RNSkPictureView.cpp +0 -69
  205. package/cpp/rnskia/RNSkPictureView.h +0 -211
  206. package/cpp/skia/src/gpu/ganesh/gl/GrGLDefines.h +0 -1162
  207. package/lib/commonjs/renderer/DefaultCanvas.d.ts +0 -8
  208. package/lib/commonjs/renderer/DefaultCanvas.js +0 -42
  209. package/lib/commonjs/renderer/DefaultCanvas.js.map +0 -1
  210. package/lib/commonjs/renderer/GraphiteCanvas.d.ts +0 -22
  211. package/lib/commonjs/renderer/GraphiteCanvas.js +0 -64
  212. package/lib/commonjs/renderer/GraphiteCanvas.js.map +0 -1
  213. package/lib/commonjs/renderer/GraphiteCanvas.web.d.ts +0 -1
  214. package/lib/commonjs/renderer/GraphiteCanvas.web.js +0 -13
  215. package/lib/commonjs/renderer/GraphiteCanvas.web.js.map +0 -1
  216. package/lib/commonjs/specs/SkiaGraphiteViewNativeComponent.d.ts +0 -10
  217. package/lib/commonjs/specs/SkiaGraphiteViewNativeComponent.js +0 -12
  218. package/lib/commonjs/specs/SkiaGraphiteViewNativeComponent.js.map +0 -1
  219. package/lib/commonjs/specs/SkiaGraphiteViewNativeComponent.web.d.ts +0 -9
  220. package/lib/commonjs/specs/SkiaGraphiteViewNativeComponent.web.js +0 -28
  221. package/lib/commonjs/specs/SkiaGraphiteViewNativeComponent.web.js.map +0 -1
  222. package/lib/commonjs/specs/SkiaPictureViewNativeComponent.js.map +0 -1
  223. package/lib/commonjs/specs/SkiaPictureViewNativeComponent.web.d.ts +0 -10
  224. package/lib/commonjs/specs/SkiaPictureViewNativeComponent.web.js +0 -29
  225. package/lib/commonjs/specs/SkiaPictureViewNativeComponent.web.js.map +0 -1
  226. package/lib/commonjs/views/SkiaGraphiteView.web.d.ts +0 -14
  227. package/lib/commonjs/views/SkiaGraphiteView.web.js.map +0 -1
  228. package/lib/commonjs/views/SkiaPictureView.web.d.ts +0 -11
  229. package/lib/commonjs/views/SkiaPictureView.web.js +0 -165
  230. package/lib/commonjs/views/SkiaPictureView.web.js.map +0 -1
  231. package/lib/module/renderer/DefaultCanvas.d.ts +0 -8
  232. package/lib/module/renderer/DefaultCanvas.js +0 -34
  233. package/lib/module/renderer/DefaultCanvas.js.map +0 -1
  234. package/lib/module/renderer/GraphiteCanvas.d.ts +0 -22
  235. package/lib/module/renderer/GraphiteCanvas.js +0 -57
  236. package/lib/module/renderer/GraphiteCanvas.js.map +0 -1
  237. package/lib/module/renderer/GraphiteCanvas.web.d.ts +0 -1
  238. package/lib/module/renderer/GraphiteCanvas.web.js +0 -4
  239. package/lib/module/renderer/GraphiteCanvas.web.js.map +0 -1
  240. package/lib/module/specs/SkiaGraphiteViewNativeComponent.d.ts +0 -10
  241. package/lib/module/specs/SkiaGraphiteViewNativeComponent.js +0 -8
  242. package/lib/module/specs/SkiaGraphiteViewNativeComponent.js.map +0 -1
  243. package/lib/module/specs/SkiaGraphiteViewNativeComponent.web.d.ts +0 -9
  244. package/lib/module/specs/SkiaGraphiteViewNativeComponent.web.js +0 -22
  245. package/lib/module/specs/SkiaGraphiteViewNativeComponent.web.js.map +0 -1
  246. package/lib/module/specs/SkiaPictureViewNativeComponent.js.map +0 -1
  247. package/lib/module/specs/SkiaPictureViewNativeComponent.web.d.ts +0 -10
  248. package/lib/module/specs/SkiaPictureViewNativeComponent.web.js +0 -23
  249. package/lib/module/specs/SkiaPictureViewNativeComponent.web.js.map +0 -1
  250. package/lib/module/views/SkiaGraphiteView.web.d.ts +0 -14
  251. package/lib/module/views/SkiaGraphiteView.web.js.map +0 -1
  252. package/lib/module/views/SkiaPictureView.web.d.ts +0 -11
  253. package/lib/module/views/SkiaPictureView.web.js +0 -156
  254. package/lib/module/views/SkiaPictureView.web.js.map +0 -1
  255. package/lib/typescript/src/renderer/DefaultCanvas.d.ts +0 -8
  256. package/lib/typescript/src/renderer/GraphiteCanvas.d.ts +0 -22
  257. package/lib/typescript/src/renderer/GraphiteCanvas.web.d.ts +0 -1
  258. package/lib/typescript/src/specs/SkiaGraphiteViewNativeComponent.d.ts +0 -10
  259. package/lib/typescript/src/specs/SkiaGraphiteViewNativeComponent.web.d.ts +0 -9
  260. package/lib/typescript/src/specs/SkiaPictureViewNativeComponent.web.d.ts +0 -10
  261. package/lib/typescript/src/views/SkiaGraphiteView.web.d.ts +0 -14
  262. package/lib/typescript/src/views/SkiaPictureView.web.d.ts +0 -11
  263. package/libs/.graphite +0 -1
  264. package/src/renderer/DefaultCanvas.tsx +0 -41
  265. package/src/renderer/GraphiteCanvas.tsx +0 -61
  266. package/src/renderer/GraphiteCanvas.web.tsx +0 -3
  267. package/src/specs/SkiaGraphiteViewNativeComponent.ts +0 -17
  268. package/src/specs/SkiaGraphiteViewNativeComponent.web.ts +0 -31
  269. package/src/views/SkiaPictureView.web.tsx +0 -224
@@ -1,67 +0,0 @@
1
- #include "OpenGLWindowContext.h"
2
- #include "GrAHardwareBufferUtils.h"
3
-
4
- #include "OpenGLContext.h"
5
-
6
- #pragma clang diagnostic push
7
- #pragma clang diagnostic ignored "-Wdocumentation"
8
-
9
- #include "include/gpu/ganesh/SkImageGanesh.h"
10
- #include "include/gpu/ganesh/gl/GrGLBackendSurface.h"
11
- #include "src/gpu/ganesh/gl/GrGLDefines.h"
12
-
13
- #pragma clang diagnostic pop
14
-
15
- namespace RNSkia {
16
-
17
- sk_sp<SkSurface> OpenGLWindowContext::getSurface() {
18
- if (_skSurface == nullptr) {
19
- if (_glSurface == nullptr || !_glContext->makeCurrent(_glSurface.get())) {
20
- RNSkLogger::logToConsole(
21
- "Couldn't create the EGL window surface, the surface will not be "
22
- "rendered");
23
- return nullptr;
24
- }
25
- GLint stencil;
26
- glGetIntegerv(GL_STENCIL_BITS, &stencil);
27
-
28
- GLint samples;
29
- glGetIntegerv(GL_SAMPLES, &samples);
30
-
31
- auto colorType = kRGBA_8888_SkColorType;
32
-
33
- auto maxSamples =
34
- _directContext->maxSurfaceSampleCountForColorType(colorType);
35
-
36
- if (samples > maxSamples) {
37
- samples = maxSamples;
38
- }
39
-
40
- GrGLFramebufferInfo fbInfo;
41
- fbInfo.fFBOID = 0;
42
- fbInfo.fFormat = GR_GL_RGBA8;
43
- // fbInfo.fProtected =
44
- // skgpu::Protected(fDisplayParams.fCreateProtectedNativeBackend);
45
-
46
- auto width = ANativeWindow_getWidth(_window);
47
- auto height = ANativeWindow_getHeight(_window);
48
- auto backendRT =
49
- GrBackendRenderTargets::MakeGL(width, height, samples, stencil, fbInfo);
50
- sk_sp<SkColorSpace> colorSpace(nullptr);
51
- SkSurfaceProps surfaceProps(0, kRGB_H_SkPixelGeometry);
52
- _skSurface = SkSurfaces::WrapBackendRenderTarget(
53
- _directContext, backendRT, kBottomLeft_GrSurfaceOrigin,
54
- kRGBA_8888_SkColorType, colorSpace, &surfaceProps);
55
- }
56
- return _skSurface;
57
- }
58
-
59
- void OpenGLWindowContext::present() {
60
- if (_glSurface == nullptr || !_glContext->makeCurrent(_glSurface.get())) {
61
- return;
62
- }
63
- _directContext->flushAndSubmit();
64
- _glSurface->present();
65
- }
66
-
67
- } // namespace RNSkia
@@ -1,75 +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 "RNWindowContext.h"
17
- #include "gl/Display.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 OpenGLWindowContext : public WindowContext {
35
- public:
36
- OpenGLWindowContext(GrDirectContext *directContext, gl::Display *display,
37
- gl::Context *glContext, ANativeWindow *window,
38
- EGLConfig config)
39
- : _directContext(directContext), _glContext(glContext), _window(window) {
40
- ANativeWindow_acquire(_window);
41
- _glSurface = display->makeWindowSurface(config, _window);
42
- }
43
-
44
- ~OpenGLWindowContext() override {
45
- _skSurface = nullptr;
46
- _glSurface = nullptr;
47
- ANativeWindow_release(_window);
48
- }
49
-
50
- sk_sp<SkSurface> getSurface() override;
51
-
52
- void present() override;
53
-
54
- int getWidth() override { return ANativeWindow_getWidth(_window); };
55
-
56
- int getHeight() override { return ANativeWindow_getHeight(_window); };
57
-
58
- void resize(int width, int height) override {
59
- if (_skSurface != nullptr) {
60
- // Let's make sure there is no pending work
61
- _glContext->makeCurrent(_glSurface.get());
62
- _glSurface->present();
63
- _skSurface = nullptr;
64
- }
65
- }
66
-
67
- private:
68
- GrDirectContext *_directContext;
69
- gl::Context *_glContext = nullptr;
70
- ANativeWindow *_window;
71
- sk_sp<SkSurface> _skSurface = nullptr;
72
- std::unique_ptr<gl::Surface> _glSurface = nullptr;
73
- };
74
-
75
- } // namespace RNSkia
@@ -1,67 +0,0 @@
1
- #pragma once
2
-
3
- #include <memory>
4
- #include <string>
5
- #include <vector>
6
-
7
- #include "RNSkOpenGLCanvasProvider.h"
8
- #include <android/native_window.h>
9
-
10
- namespace RNSkia {
11
-
12
- class RNSkBaseAndroidView {
13
- public:
14
- virtual void surfaceAvailable(jobject surface, int width, int height,
15
- bool isSurface, bool highBitDepth) = 0;
16
-
17
- virtual void surfaceDestroyed() = 0;
18
-
19
- virtual void surfaceSizeChanged(jobject surface, int width, int height,
20
- bool isSurface, bool highBitDepth) = 0;
21
-
22
- virtual float getPixelDensity() = 0;
23
-
24
- virtual void setShowDebugInfo(bool show) = 0;
25
-
26
- virtual std::shared_ptr<RNSkView> getSkiaView() = 0;
27
- };
28
-
29
- template <typename T>
30
- class RNSkAndroidView : public T, public RNSkBaseAndroidView {
31
- public:
32
- explicit RNSkAndroidView(std::shared_ptr<RNSkia::RNSkPlatformContext> context)
33
- : T(context,
34
- std::make_shared<RNSkOpenGLCanvasProvider>(
35
- std::bind(&RNSkia::RNSkView::requestRedraw, this), context)) {}
36
-
37
- void surfaceAvailable(jobject surface, int width, int height, bool isSurface,
38
- bool highBitDepth) override {
39
- std::static_pointer_cast<RNSkOpenGLCanvasProvider>(T::getCanvasProvider())
40
- ->surfaceAvailable(surface, width, height, isSurface, highBitDepth);
41
- RNSkView::redraw();
42
- }
43
-
44
- void surfaceDestroyed() override {
45
- std::static_pointer_cast<RNSkOpenGLCanvasProvider>(T::getCanvasProvider())
46
- ->surfaceDestroyed();
47
- }
48
-
49
- void surfaceSizeChanged(jobject surface, int width, int height,
50
- bool isSurface, bool highBitDepth) override {
51
- std::static_pointer_cast<RNSkOpenGLCanvasProvider>(T::getCanvasProvider())
52
- ->surfaceSizeChanged(surface, width, height, isSurface, highBitDepth);
53
- // Paint the new size right away rather than on the next scheduled redraw.
54
- RNSkView::redraw();
55
- }
56
-
57
- float getPixelDensity() override {
58
- return T::getPlatformContext()->getPixelDensity();
59
- }
60
-
61
- void setShowDebugInfo(bool show) override { T::setShowDebugOverlays(show); }
62
-
63
- std::shared_ptr<RNSkView> getSkiaView() override {
64
- return T::shared_from_this();
65
- }
66
- };
67
- } // namespace RNSkia
@@ -1,80 +0,0 @@
1
- #pragma once
2
-
3
- #include "gl/Error.h"
4
- #include "gl/Surface.h"
5
-
6
- namespace gl {
7
-
8
- class Surface;
9
- class Display;
10
-
11
- class Context {
12
- public:
13
- ~Context() {
14
- if (_context != EGL_NO_CONTEXT) {
15
- if (eglDestroyContext(_display, _context) != EGL_TRUE) {
16
- LOG_EGL_ERROR;
17
- }
18
- }
19
- }
20
-
21
- bool isValid() const { return _context != EGL_NO_CONTEXT; }
22
-
23
- const EGLContext &getHandle() const { return _context; }
24
-
25
- bool makeCurrent(const Surface *surface) {
26
- if (_context == EGL_NO_CONTEXT) {
27
- return false;
28
- }
29
- if (surface == nullptr || !surface->isValid()) {
30
- return false;
31
- }
32
- const auto result =
33
- eglMakeCurrentIfNecessary(_display, surface->getHandle(),
34
- surface->getHandle(), _context) == EGL_TRUE;
35
- if (!result) {
36
- LOG_EGL_ERROR;
37
- }
38
- return result;
39
- }
40
-
41
- bool clearCurrent() {
42
- const auto result =
43
- eglMakeCurrentIfNecessary(_display, EGL_NO_SURFACE, EGL_NO_SURFACE,
44
- EGL_NO_CONTEXT) == EGL_TRUE;
45
- if (!result) {
46
- LOG_EGL_ERROR;
47
- }
48
- return result;
49
- }
50
-
51
- bool isCurrent() const { return eglGetCurrentContext() == _context; }
52
-
53
- private:
54
- friend class Display;
55
-
56
- EGLDisplay _display = EGL_NO_DISPLAY;
57
- EGLContext _context = EGL_NO_CONTEXT;
58
-
59
- static EGLBoolean eglMakeCurrentIfNecessary(EGLDisplay display,
60
- EGLSurface draw, EGLSurface read,
61
- EGLContext context) {
62
- if (display != eglGetCurrentDisplay() ||
63
- draw != eglGetCurrentSurface(EGL_DRAW) ||
64
- read != eglGetCurrentSurface(EGL_READ) ||
65
- context != eglGetCurrentContext()) {
66
- return eglMakeCurrent(display, draw, read, context);
67
- }
68
-
69
- return EGL_TRUE;
70
- }
71
-
72
- Context(EGLDisplay display, EGLContext context)
73
- : _display(display), _context(context) {}
74
-
75
- Context(const Context &) = delete;
76
-
77
- Context &operator=(const Context &) = delete;
78
- };
79
-
80
- } // namespace gl
@@ -1,123 +0,0 @@
1
- #pragma once
2
-
3
- #include <memory>
4
-
5
- #include "EGL/egl.h"
6
- #include "GLES2/gl2.h"
7
-
8
- #include "gl/Context.h"
9
- #include "gl/Error.h"
10
-
11
- namespace gl {
12
-
13
- class Context;
14
- class Surface;
15
-
16
- class Display {
17
- public:
18
- Display() {
19
- EGLDisplay display = eglGetDisplay(EGL_DEFAULT_DISPLAY);
20
-
21
- if (eglInitialize(display, nullptr, nullptr) != EGL_TRUE) {
22
- LOG_EGL_ERROR;
23
- return;
24
- }
25
- _display = display;
26
- }
27
-
28
- ~Display() {
29
- if (_display != EGL_NO_DISPLAY) {
30
- if (eglTerminate(_display) != EGL_TRUE) {
31
- LOG_EGL_ERROR;
32
- }
33
- }
34
- }
35
-
36
- bool isValid() const { return _display != EGL_NO_DISPLAY; }
37
-
38
- void clearContext() {
39
- eglMakeCurrent(_display, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
40
- }
41
-
42
- EGLConfig chooseConfig() {
43
-
44
- EGLint att[] = {EGL_RENDERABLE_TYPE,
45
- EGL_OPENGL_ES2_BIT,
46
- EGL_SURFACE_TYPE,
47
- EGL_WINDOW_BIT | EGL_PBUFFER_BIT,
48
- EGL_ALPHA_SIZE,
49
- 8,
50
- EGL_BLUE_SIZE,
51
- 8,
52
- EGL_GREEN_SIZE,
53
- 8,
54
- EGL_RED_SIZE,
55
- 8,
56
- EGL_DEPTH_SIZE,
57
- 0,
58
- EGL_STENCIL_SIZE,
59
- 0,
60
- EGL_SAMPLE_BUFFERS,
61
- 0,
62
- EGL_NONE};
63
-
64
- EGLint numConfigs;
65
- EGLConfig glConfig = 0;
66
- if (eglChooseConfig(_display, att, &glConfig, 1, &numConfigs) != EGL_TRUE ||
67
- numConfigs == 0) {
68
- LOG_EGL_ERROR;
69
- return 0;
70
- }
71
-
72
- return glConfig;
73
- }
74
-
75
- std::unique_ptr<Context> makeContext(const EGLConfig &config,
76
- const Context *share_context) {
77
- EGLint contextAttribs[] = {EGL_CONTEXT_CLIENT_VERSION, 2, EGL_NONE};
78
- auto context = eglCreateContext(
79
- _display, config,
80
- share_context != nullptr ? share_context->getHandle() : nullptr,
81
- contextAttribs);
82
-
83
- if (context == EGL_NO_CONTEXT) {
84
- LOG_EGL_ERROR;
85
- return nullptr;
86
- }
87
- return std::unique_ptr<Context>(new Context(_display, context));
88
- }
89
-
90
- std::unique_ptr<Surface> makeWindowSurface(const EGLConfig &config,
91
- ANativeWindow *window) {
92
- const EGLint attribs[] = {EGL_NONE};
93
- auto surface = eglCreateWindowSurface(_display, config, window, attribs);
94
- if (surface == EGL_NO_SURFACE) {
95
- LOG_EGL_ERROR;
96
- return nullptr;
97
- }
98
- return std::make_unique<Surface>(_display, surface);
99
- }
100
-
101
- std::unique_ptr<Surface> makePixelBufferSurface(const EGLConfig &config,
102
- size_t width, size_t height) {
103
- const EGLint attribs[] = {EGL_WIDTH, static_cast<EGLint>(width), EGL_HEIGHT,
104
- static_cast<EGLint>(height), EGL_NONE};
105
- auto surface = eglCreatePbufferSurface(_display, config, attribs);
106
- if (surface == EGL_NO_SURFACE) {
107
- LOG_EGL_ERROR;
108
- return nullptr;
109
- }
110
- return std::make_unique<Surface>(_display, surface);
111
- }
112
-
113
- const EGLDisplay &getHandle() const { return _display; }
114
-
115
- private:
116
- EGLDisplay _display = EGL_NO_DISPLAY;
117
-
118
- Display(const Display &) = delete;
119
-
120
- Display &operator=(const Display &) = delete;
121
- };
122
-
123
- } // namespace gl
@@ -1,45 +0,0 @@
1
- #include "gl/Error.h"
2
-
3
- #include "RNSkLog.h"
4
-
5
- static const char *EGLErrorToString(EGLint error) {
6
- switch (error) {
7
- case EGL_SUCCESS:
8
- return "Success";
9
- case EGL_NOT_INITIALIZED:
10
- return "Not Initialized";
11
- case EGL_BAD_ACCESS:
12
- return "Bad Access";
13
- case EGL_BAD_ALLOC:
14
- return "Bad Alloc";
15
- case EGL_BAD_ATTRIBUTE:
16
- return "Bad Attribute";
17
- case EGL_BAD_CONTEXT:
18
- return "Bad Context";
19
- case EGL_BAD_CONFIG:
20
- return "Bad Config";
21
- case EGL_BAD_CURRENT_SURFACE:
22
- return "Bad Current Surface";
23
- case EGL_BAD_DISPLAY:
24
- return "Bad Display";
25
- case EGL_BAD_SURFACE:
26
- return "Bad Surface";
27
- case EGL_BAD_MATCH:
28
- return "Bad Match";
29
- case EGL_BAD_PARAMETER:
30
- return "Bad Parameter";
31
- case EGL_BAD_NATIVE_PIXMAP:
32
- return "Bad Native Pixmap";
33
- case EGL_BAD_NATIVE_WINDOW:
34
- return "Bad Native Window";
35
- case EGL_CONTEXT_LOST:
36
- return "Context Lost";
37
- }
38
- return "Unknown";
39
- }
40
-
41
- void LogEGLError(const char *file, int line) {
42
- const auto error = eglGetError();
43
- RNSkia::RNSkLogger::logToConsole("EGL Error: %s (%d) in %s:%d",
44
- EGLErrorToString(error), error, file, line);
45
- }
@@ -1,8 +0,0 @@
1
- #pragma once
2
-
3
- #include "EGL/egl.h"
4
- #include "GLES2/gl2.h"
5
-
6
- #define LOG_EGL_ERROR LogEGLError(__FILE__, __LINE__);
7
-
8
- void LogEGLError(const char *file, int line);
@@ -1,43 +0,0 @@
1
- #pragma once
2
-
3
- #include "gl/Error.h"
4
-
5
- namespace gl {
6
-
7
- class Surface {
8
- public:
9
- Surface(EGLDisplay display, EGLSurface surface)
10
- : _display(display), _surface(surface) {}
11
-
12
- ~Surface() {
13
- if (_surface != EGL_NO_SURFACE) {
14
- if (eglDestroySurface(_display, _surface) != EGL_TRUE) {
15
- LOG_EGL_ERROR;
16
- }
17
- }
18
- }
19
-
20
- bool isValid() const { return _surface != EGL_NO_SURFACE; }
21
-
22
- const EGLSurface &getHandle() const { return _surface; }
23
-
24
- bool present() {
25
- const auto result = eglSwapBuffers(_display, _surface) == EGL_TRUE;
26
- if (!result) {
27
- LOG_EGL_ERROR;
28
- }
29
- return result;
30
- }
31
-
32
- private:
33
- friend class Display;
34
-
35
- EGLDisplay _display = EGL_NO_DISPLAY;
36
- EGLSurface _surface = EGL_NO_SURFACE;
37
-
38
- Surface(const Surface &) = delete;
39
-
40
- Surface &operator=(const Surface &) = delete;
41
- };
42
-
43
- } // namespace gl
@@ -1,65 +0,0 @@
1
- package com.reactnative.skia;
2
-
3
- import com.facebook.react.uimanager.PointerEvents;
4
- import com.facebook.react.uimanager.ViewProps;
5
- import com.facebook.react.uimanager.annotations.ReactProp;
6
- import com.facebook.react.views.view.ReactViewGroup;
7
- import com.facebook.react.views.view.ReactViewManager;
8
-
9
- import androidx.annotation.NonNull;
10
- import androidx.annotation.Nullable;
11
-
12
- public abstract class SkiaBaseViewManager<T extends SkiaBaseView> extends ReactViewManager {
13
-
14
- @Override
15
- public void setNativeId(@NonNull ReactViewGroup view, @Nullable String nativeId) {
16
- super.setNativeId(view, nativeId);
17
- int nativeIdResolved = Integer.parseInt(nativeId);
18
- ((SkiaBaseView)view).registerView(nativeIdResolved);
19
- }
20
-
21
- @ReactProp(name = "debug")
22
- public void setDebug(T view, boolean show) {
23
- ((SkiaBaseView)view).setDebugMode(show);
24
- }
25
-
26
- @ReactProp(name = "opaque")
27
- public void setOpaque(T view, boolean value) {
28
- ((SkiaBaseView)view).setOpaque(value);
29
- }
30
-
31
- @ReactProp(name = "highBitDepth")
32
- public void setHighBitDepth(T view, boolean value) {
33
- ((SkiaBaseView)view).setHighBitDepth(value);
34
- }
35
-
36
- @ReactProp(name = "androidSurfaceType")
37
- public void setAndroidSurfaceType(T view, @Nullable String value) {
38
- ((SkiaBaseView)view).setSurfaceType(value);
39
- }
40
-
41
- @ReactProp(name = "androidZOrderOnTop")
42
- public void setAndroidZOrderOnTop(T view, boolean value) {
43
- ((SkiaBaseView)view).setZOrderOnTop(value);
44
- }
45
-
46
- // The backing view depends on several props (opaque, androidSurfaceType,
47
- // androidZOrderOnTop, highBitDepth), so it is resolved once per transaction
48
- // rather than in each setter.
49
- @Override
50
- protected void onAfterUpdateTransaction(@NonNull ReactViewGroup view) {
51
- super.onAfterUpdateTransaction(view);
52
- ((SkiaBaseView)view).updateView();
53
- }
54
-
55
- @ReactProp(name = ViewProps.POINTER_EVENTS)
56
- public void setPointerEvents(T view, @Nullable String pointerEventsStr) {
57
- view.setPointerEvents(PointerEvents.parsePointerEvents(pointerEventsStr));
58
- }
59
-
60
- @Override
61
- public void onDropViewInstance(@NonNull ReactViewGroup view) {
62
- super.onDropViewInstance(view);
63
- ((SkiaBaseView)view).dropInstance();
64
- }
65
- }
@@ -1,78 +0,0 @@
1
- package com.reactnative.skia;
2
-
3
- import android.content.Context;
4
- import android.view.Choreographer;
5
-
6
- import com.facebook.jni.HybridData;
7
- import com.facebook.jni.annotations.DoNotStrip;
8
- import com.facebook.react.bridge.ReactContext;
9
-
10
- /**
11
- * Presents Graphite recordings: JS records frames through the context
12
- * returned by SkiaViewApi.makeGraphiteContext, the view replays them on the
13
- * Choreographer. Requires the Graphite backend.
14
- */
15
- public class SkiaGraphiteView extends SkiaBaseView implements Choreographer.FrameCallback {
16
- @DoNotStrip
17
- private HybridData mHybridData;
18
-
19
- private boolean mFramePending = false;
20
-
21
- public SkiaGraphiteView(Context context) {
22
- super(context);
23
- RNSkiaModule skiaModule = ((ReactContext) context).getNativeModule(RNSkiaModule.class);
24
- mHybridData = initHybrid(skiaModule.getSkiaManager());
25
- }
26
-
27
- /**
28
- * Presents the queued recordings on the next vsync. Main thread; called
29
- * from native when a recording is submitted.
30
- */
31
- @DoNotStrip
32
- public void scheduleFrame() {
33
- if (!mFramePending) {
34
- mFramePending = true;
35
- Choreographer.getInstance().postFrameCallback(this);
36
- }
37
- }
38
-
39
- @Override
40
- public void doFrame(long frameTimeNanos) {
41
- mFramePending = false;
42
- if (presentFrame()) {
43
- scheduleFrame();
44
- }
45
- }
46
-
47
- @Override
48
- protected void onDetachedFromWindow() {
49
- super.onDetachedFromWindow();
50
- Choreographer.getInstance().removeFrameCallback(this);
51
- mFramePending = false;
52
- }
53
-
54
- @Override
55
- protected void finalize() throws Throwable {
56
- super.finalize();
57
- mHybridData.resetNative();
58
- }
59
-
60
- private native HybridData initHybrid(SkiaManager skiaManager);
61
-
62
- protected native void surfaceAvailable(Object surface, int width, int height, boolean isSurface, boolean highBitDepth);
63
-
64
- protected native void surfaceSizeChanged(Object surface, int width, int height, boolean isSurface, boolean highBitDepth);
65
-
66
- protected native void surfaceDestroyed();
67
-
68
- protected native void setDebugMode(boolean show);
69
-
70
- protected native void registerView(int nativeId);
71
-
72
- protected native void unregisterView();
73
-
74
- protected native int[] getBitmap(int width, int height);
75
-
76
- /** Choreographer tick: returns whether more recordings are waiting. */
77
- private native boolean presentFrame();
78
- }
@@ -1,32 +0,0 @@
1
- package com.reactnative.skia;
2
-
3
- import com.facebook.react.uimanager.ThemedReactContext;
4
- import com.facebook.react.viewmanagers.SkiaGraphiteViewManagerDelegate;
5
- import com.facebook.react.viewmanagers.SkiaGraphiteViewManagerInterface;
6
-
7
- import androidx.annotation.NonNull;
8
-
9
- public class SkiaGraphiteViewManager extends SkiaBaseViewManager<SkiaGraphiteView> implements SkiaGraphiteViewManagerInterface<SkiaGraphiteView> {
10
-
11
- protected SkiaGraphiteViewManagerDelegate mDelegate;
12
-
13
- SkiaGraphiteViewManager() {
14
- mDelegate = new SkiaGraphiteViewManagerDelegate(this);
15
- }
16
-
17
- protected SkiaGraphiteViewManagerDelegate getDelegate() {
18
- return mDelegate;
19
- }
20
-
21
- @NonNull
22
- @Override
23
- public String getName() {
24
- return "SkiaGraphiteView";
25
- }
26
-
27
- @NonNull
28
- @Override
29
- public SkiaGraphiteView createViewInstance(@NonNull ThemedReactContext reactContext) {
30
- return new SkiaGraphiteView(reactContext);
31
- }
32
- }