react-native-skia 3.0.0 → 3.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (261) hide show
  1. package/Package.swift +14 -13
  2. package/android/CMakeLists.txt +13 -42
  3. package/android/build.gradle +55 -47
  4. package/android/cpp/jni/JniLoad.cpp +2 -4
  5. package/android/cpp/jni/include/JniSkiaView.h +123 -0
  6. package/android/cpp/rnskia-android/{RNSkOpenGLCanvasProvider.cpp → RNSkAndroidCanvasProvider.cpp} +45 -100
  7. package/android/cpp/rnskia-android/{RNSkOpenGLCanvasProvider.h → RNSkAndroidCanvasProvider.h} +24 -22
  8. package/android/cpp/rnskia-android/RNSkAndroidPlatformContext.h +0 -83
  9. package/android/cpp/rnskia-android/RNSkAndroidVideo.cpp +0 -8
  10. package/android/src/main/java/com/reactnative/skia/RNSkiaPackage.java +1 -2
  11. package/android/src/main/java/com/reactnative/skia/SkiaSurfaceView.java +1 -3
  12. package/android/src/main/java/com/reactnative/skia/SkiaTextureView.java +1 -17
  13. package/android/src/main/java/com/reactnative/skia/{SkiaBaseView.java → SkiaView.java} +78 -16
  14. package/android/src/main/java/com/reactnative/skia/SkiaViewManager.java +85 -0
  15. package/apple/MetalLayerColorSpace.mm +0 -4
  16. package/apple/RNSkApplePlatformContext.h +0 -14
  17. package/apple/RNSkApplePlatformContext.mm +2 -112
  18. package/apple/RNSkMetalCanvasProvider.h +14 -19
  19. package/apple/RNSkMetalCanvasProvider.mm +35 -68
  20. package/apple/SkiaView.h +20 -0
  21. package/apple/SkiaView.mm +210 -0
  22. package/cpp/api/JsiSkApi.h +2 -13
  23. package/cpp/api/JsiSkCanvas.h +4 -18
  24. package/cpp/api/JsiSkGraphiteContext.h +1 -5
  25. package/cpp/api/JsiSkGraphiteRecording.h +1 -5
  26. package/cpp/api/JsiSkImage.h +7 -41
  27. package/cpp/api/JsiSkImageFactory.h +0 -14
  28. package/cpp/api/JsiSkSurface.h +2 -16
  29. package/cpp/api/JsiSkSurfaceFactory.h +0 -8
  30. package/cpp/rnskia/RNDawnContext.h +6 -0
  31. package/cpp/rnskia/RNDawnInterop.cpp +0 -4
  32. package/cpp/rnskia/RNDawnUtils.h +0 -1
  33. package/cpp/rnskia/RNDawnWindowContext.cpp +10 -0
  34. package/cpp/rnskia/RNDawnWindowContext.h +4 -0
  35. package/cpp/rnskia/RNSkCanvasProvider.h +221 -0
  36. package/cpp/rnskia/RNSkGraphiteProducer.cpp +36 -14
  37. package/cpp/rnskia/RNSkGraphiteProducer.h +23 -8
  38. package/cpp/rnskia/RNSkGraphiteTarget.h +383 -0
  39. package/cpp/rnskia/RNSkJsiViewApi.h +9 -18
  40. package/cpp/rnskia/RNSkPlatformContext.h +9 -15
  41. package/cpp/rnskia/RNSkView.h +340 -245
  42. package/jestSetup.js +1 -3
  43. package/lib/commonjs/Platform/Platform.web.js +1 -1
  44. package/lib/commonjs/Platform/Platform.web.js.map +1 -1
  45. package/lib/commonjs/index.d.ts +1 -3
  46. package/lib/commonjs/index.js +3 -12
  47. package/lib/commonjs/index.js.map +1 -1
  48. package/lib/commonjs/mock/index.js +0 -1
  49. package/lib/commonjs/mock/index.js.map +1 -1
  50. package/lib/commonjs/renderer/Canvas.d.ts +15 -12
  51. package/lib/commonjs/renderer/Canvas.js +24 -20
  52. package/lib/commonjs/renderer/Canvas.js.map +1 -1
  53. package/lib/commonjs/skia/types/Graphite.d.ts +3 -3
  54. package/lib/commonjs/skia/types/Graphite.js.map +1 -1
  55. package/lib/commonjs/skia/types/Image/ImageFactory.d.ts +2 -2
  56. package/lib/commonjs/skia/types/Image/ImageFactory.js.map +1 -1
  57. package/lib/commonjs/skia/types/Skia.d.ts +1 -2
  58. package/lib/commonjs/skia/types/Skia.js.map +1 -1
  59. package/lib/commonjs/skia/types/Surface/SurfaceFactory.d.ts +1 -1
  60. package/lib/commonjs/skia/types/Surface/SurfaceFactory.js.map +1 -1
  61. package/lib/commonjs/specs/NativeSkiaModule.web.d.ts +5 -4
  62. package/lib/commonjs/specs/NativeSkiaModule.web.js +5 -9
  63. package/lib/commonjs/specs/NativeSkiaModule.web.js.map +1 -1
  64. package/lib/{typescript/src/specs/SkiaPictureViewNativeComponent.d.ts → commonjs/specs/SkiaViewNativeComponent.d.ts} +0 -3
  65. package/lib/commonjs/specs/{SkiaPictureViewNativeComponent.js → SkiaViewNativeComponent.js} +2 -2
  66. package/lib/commonjs/specs/SkiaViewNativeComponent.js.map +1 -0
  67. package/lib/commonjs/specs/SkiaViewNativeComponent.web.d.ts +10 -0
  68. package/lib/commonjs/specs/SkiaViewNativeComponent.web.js +27 -0
  69. package/lib/commonjs/specs/SkiaViewNativeComponent.web.js.map +1 -0
  70. package/lib/commonjs/views/SkiaGraphiteView.d.ts +3 -4
  71. package/lib/commonjs/views/SkiaGraphiteView.js +23 -12
  72. package/lib/commonjs/views/SkiaGraphiteView.js.map +1 -1
  73. package/lib/commonjs/views/SkiaPictureView.d.ts +4 -1
  74. package/lib/commonjs/views/SkiaPictureView.js +12 -10
  75. package/lib/commonjs/views/SkiaPictureView.js.map +1 -1
  76. package/lib/commonjs/views/SkiaView.web.d.ts +12 -0
  77. package/lib/commonjs/views/{SkiaGraphiteView.web.js → SkiaView.web.js} +82 -38
  78. package/lib/commonjs/views/SkiaView.web.js.map +1 -0
  79. package/lib/commonjs/views/SkiaWebRenderer.js +1 -1
  80. package/lib/commonjs/views/SkiaWebRenderer.js.map +1 -1
  81. package/lib/commonjs/views/android.d.ts +6 -0
  82. package/lib/commonjs/views/android.js +17 -0
  83. package/lib/commonjs/views/android.js.map +1 -0
  84. package/lib/commonjs/views/types.d.ts +3 -12
  85. package/lib/commonjs/views/types.js.map +1 -1
  86. package/lib/module/Platform/Platform.web.js +1 -1
  87. package/lib/module/Platform/Platform.web.js.map +1 -1
  88. package/lib/module/index.d.ts +1 -3
  89. package/lib/module/index.js +1 -3
  90. package/lib/module/index.js.map +1 -1
  91. package/lib/module/mock/index.js +0 -1
  92. package/lib/module/mock/index.js.map +1 -1
  93. package/lib/module/renderer/Canvas.d.ts +15 -12
  94. package/lib/module/renderer/Canvas.js +24 -19
  95. package/lib/module/renderer/Canvas.js.map +1 -1
  96. package/lib/module/skia/types/Graphite.d.ts +3 -3
  97. package/lib/module/skia/types/Graphite.js.map +1 -1
  98. package/lib/module/skia/types/Image/ImageFactory.d.ts +2 -2
  99. package/lib/module/skia/types/Image/ImageFactory.js.map +1 -1
  100. package/lib/module/skia/types/Skia.d.ts +1 -2
  101. package/lib/module/skia/types/Skia.js.map +1 -1
  102. package/lib/module/skia/types/Surface/SurfaceFactory.d.ts +1 -1
  103. package/lib/module/skia/types/Surface/SurfaceFactory.js.map +1 -1
  104. package/lib/module/specs/NativeSkiaModule.web.d.ts +5 -4
  105. package/lib/module/specs/NativeSkiaModule.web.js +5 -9
  106. package/lib/module/specs/NativeSkiaModule.web.js.map +1 -1
  107. package/lib/{commonjs/specs/SkiaPictureViewNativeComponent.d.ts → module/specs/SkiaViewNativeComponent.d.ts} +0 -3
  108. package/lib/module/specs/{SkiaPictureViewNativeComponent.js → SkiaViewNativeComponent.js} +2 -2
  109. package/lib/module/specs/SkiaViewNativeComponent.js.map +1 -0
  110. package/lib/module/specs/SkiaViewNativeComponent.web.d.ts +10 -0
  111. package/lib/module/specs/SkiaViewNativeComponent.web.js +21 -0
  112. package/lib/module/specs/SkiaViewNativeComponent.web.js.map +1 -0
  113. package/lib/module/views/SkiaGraphiteView.d.ts +3 -4
  114. package/lib/module/views/SkiaGraphiteView.js +23 -12
  115. package/lib/module/views/SkiaGraphiteView.js.map +1 -1
  116. package/lib/module/views/SkiaPictureView.d.ts +4 -1
  117. package/lib/module/views/SkiaPictureView.js +12 -10
  118. package/lib/module/views/SkiaPictureView.js.map +1 -1
  119. package/lib/module/views/SkiaView.web.d.ts +12 -0
  120. package/lib/module/views/{SkiaGraphiteView.web.js → SkiaView.web.js} +80 -36
  121. package/lib/module/views/SkiaView.web.js.map +1 -0
  122. package/lib/module/views/SkiaWebRenderer.js +1 -1
  123. package/lib/module/views/SkiaWebRenderer.js.map +1 -1
  124. package/lib/module/views/android.d.ts +6 -0
  125. package/lib/module/views/android.js +10 -0
  126. package/lib/module/views/android.js.map +1 -0
  127. package/lib/module/views/types.d.ts +3 -12
  128. package/lib/module/views/types.js.map +1 -1
  129. package/lib/typescript/src/index.d.ts +1 -3
  130. package/lib/typescript/src/renderer/Canvas.d.ts +15 -12
  131. package/lib/typescript/src/skia/types/Graphite.d.ts +3 -3
  132. package/lib/typescript/src/skia/types/Image/ImageFactory.d.ts +2 -2
  133. package/lib/typescript/src/skia/types/Skia.d.ts +1 -2
  134. package/lib/typescript/src/skia/types/Surface/SurfaceFactory.d.ts +1 -1
  135. package/lib/typescript/src/specs/NativeSkiaModule.web.d.ts +5 -4
  136. package/lib/{module/specs/SkiaPictureViewNativeComponent.d.ts → typescript/src/specs/SkiaViewNativeComponent.d.ts} +0 -3
  137. package/lib/typescript/src/specs/SkiaViewNativeComponent.web.d.ts +10 -0
  138. package/lib/typescript/src/views/SkiaGraphiteView.d.ts +3 -4
  139. package/lib/typescript/src/views/SkiaPictureView.d.ts +4 -1
  140. package/lib/typescript/src/views/SkiaView.web.d.ts +12 -0
  141. package/lib/typescript/src/views/android.d.ts +6 -0
  142. package/lib/typescript/src/views/types.d.ts +3 -12
  143. package/package.json +8 -16
  144. package/react-native-skia.podspec +50 -57
  145. package/src/Platform/Platform.web.tsx +1 -1
  146. package/src/index.ts +1 -3
  147. package/src/mock/index.ts +0 -1
  148. package/src/renderer/Canvas.tsx +23 -27
  149. package/src/skia/types/Graphite.ts +3 -3
  150. package/src/skia/types/Image/ImageFactory.ts +2 -2
  151. package/src/skia/types/Skia.ts +1 -2
  152. package/src/skia/types/Surface/SurfaceFactory.ts +1 -1
  153. package/src/specs/NativeSkiaModule.web.ts +9 -21
  154. package/src/specs/{SkiaPictureViewNativeComponent.ts → SkiaViewNativeComponent.ts} +1 -4
  155. package/src/specs/{SkiaPictureViewNativeComponent.web.ts → SkiaViewNativeComponent.web.ts} +8 -10
  156. package/src/views/SkiaGraphiteView.tsx +27 -16
  157. package/src/views/SkiaPictureView.tsx +11 -10
  158. package/src/views/{SkiaGraphiteView.web.tsx → SkiaView.web.tsx} +100 -53
  159. package/src/views/SkiaWebRenderer.ts +1 -1
  160. package/src/views/android.ts +16 -0
  161. package/src/views/types.ts +3 -14
  162. package/android/cpp/jni/include/JniSkiaBaseView.h +0 -92
  163. package/android/cpp/jni/include/JniSkiaGraphiteView.h +0 -176
  164. package/android/cpp/jni/include/JniSkiaPictureView.h +0 -172
  165. package/android/cpp/rnskia-android/GrAHardwareBufferUtils.cpp +0 -245
  166. package/android/cpp/rnskia-android/GrAHardwareBufferUtils.h +0 -33
  167. package/android/cpp/rnskia-android/OpenGLContext.h +0 -248
  168. package/android/cpp/rnskia-android/OpenGLWindowContext.cpp +0 -67
  169. package/android/cpp/rnskia-android/OpenGLWindowContext.h +0 -75
  170. package/android/cpp/rnskia-android/RNSkAndroidView.h +0 -67
  171. package/android/cpp/rnskia-android/gl/Context.h +0 -80
  172. package/android/cpp/rnskia-android/gl/Display.h +0 -123
  173. package/android/cpp/rnskia-android/gl/Error.cpp +0 -45
  174. package/android/cpp/rnskia-android/gl/Error.h +0 -8
  175. package/android/cpp/rnskia-android/gl/Surface.h +0 -43
  176. package/android/src/main/java/com/reactnative/skia/SkiaBaseViewManager.java +0 -65
  177. package/android/src/main/java/com/reactnative/skia/SkiaGraphiteView.java +0 -78
  178. package/android/src/main/java/com/reactnative/skia/SkiaGraphiteViewManager.java +0 -32
  179. package/android/src/main/java/com/reactnative/skia/SkiaPictureView.java +0 -105
  180. package/android/src/main/java/com/reactnative/skia/SkiaPictureViewManager.java +0 -44
  181. package/apple/MetalContext.h +0 -116
  182. package/apple/MetalContext.mm +0 -38
  183. package/apple/MetalWindowContext.h +0 -42
  184. package/apple/MetalWindowContext.mm +0 -95
  185. package/apple/RNSkAppleView.h +0 -49
  186. package/apple/RNSkAppleView.mm +0 -35
  187. package/apple/SkiaCVPixelBufferUtils.h +0 -122
  188. package/apple/SkiaCVPixelBufferUtils.mm +0 -535
  189. package/apple/SkiaGraphiteView.h +0 -26
  190. package/apple/SkiaGraphiteView.mm +0 -180
  191. package/apple/SkiaPictureView.h +0 -7
  192. package/apple/SkiaPictureView.mm +0 -70
  193. package/apple/SkiaUIView.h +0 -31
  194. package/apple/SkiaUIView.mm +0 -164
  195. package/cpp/rnskia/RNSkGraphiteView.h +0 -708
  196. package/cpp/rnskia/RNSkPictureView.cpp +0 -69
  197. package/cpp/rnskia/RNSkPictureView.h +0 -211
  198. package/cpp/skia/src/gpu/ganesh/gl/GrGLDefines.h +0 -1162
  199. package/lib/commonjs/renderer/DefaultCanvas.d.ts +0 -8
  200. package/lib/commonjs/renderer/DefaultCanvas.js +0 -42
  201. package/lib/commonjs/renderer/DefaultCanvas.js.map +0 -1
  202. package/lib/commonjs/renderer/GraphiteCanvas.d.ts +0 -22
  203. package/lib/commonjs/renderer/GraphiteCanvas.js +0 -64
  204. package/lib/commonjs/renderer/GraphiteCanvas.js.map +0 -1
  205. package/lib/commonjs/renderer/GraphiteCanvas.web.d.ts +0 -1
  206. package/lib/commonjs/renderer/GraphiteCanvas.web.js +0 -13
  207. package/lib/commonjs/renderer/GraphiteCanvas.web.js.map +0 -1
  208. package/lib/commonjs/specs/SkiaGraphiteViewNativeComponent.d.ts +0 -10
  209. package/lib/commonjs/specs/SkiaGraphiteViewNativeComponent.js +0 -12
  210. package/lib/commonjs/specs/SkiaGraphiteViewNativeComponent.js.map +0 -1
  211. package/lib/commonjs/specs/SkiaGraphiteViewNativeComponent.web.d.ts +0 -9
  212. package/lib/commonjs/specs/SkiaGraphiteViewNativeComponent.web.js +0 -28
  213. package/lib/commonjs/specs/SkiaGraphiteViewNativeComponent.web.js.map +0 -1
  214. package/lib/commonjs/specs/SkiaPictureViewNativeComponent.js.map +0 -1
  215. package/lib/commonjs/specs/SkiaPictureViewNativeComponent.web.d.ts +0 -10
  216. package/lib/commonjs/specs/SkiaPictureViewNativeComponent.web.js +0 -29
  217. package/lib/commonjs/specs/SkiaPictureViewNativeComponent.web.js.map +0 -1
  218. package/lib/commonjs/views/SkiaGraphiteView.web.d.ts +0 -14
  219. package/lib/commonjs/views/SkiaGraphiteView.web.js.map +0 -1
  220. package/lib/commonjs/views/SkiaPictureView.web.d.ts +0 -11
  221. package/lib/commonjs/views/SkiaPictureView.web.js +0 -165
  222. package/lib/commonjs/views/SkiaPictureView.web.js.map +0 -1
  223. package/lib/module/renderer/DefaultCanvas.d.ts +0 -8
  224. package/lib/module/renderer/DefaultCanvas.js +0 -34
  225. package/lib/module/renderer/DefaultCanvas.js.map +0 -1
  226. package/lib/module/renderer/GraphiteCanvas.d.ts +0 -22
  227. package/lib/module/renderer/GraphiteCanvas.js +0 -57
  228. package/lib/module/renderer/GraphiteCanvas.js.map +0 -1
  229. package/lib/module/renderer/GraphiteCanvas.web.d.ts +0 -1
  230. package/lib/module/renderer/GraphiteCanvas.web.js +0 -4
  231. package/lib/module/renderer/GraphiteCanvas.web.js.map +0 -1
  232. package/lib/module/specs/SkiaGraphiteViewNativeComponent.d.ts +0 -10
  233. package/lib/module/specs/SkiaGraphiteViewNativeComponent.js +0 -8
  234. package/lib/module/specs/SkiaGraphiteViewNativeComponent.js.map +0 -1
  235. package/lib/module/specs/SkiaGraphiteViewNativeComponent.web.d.ts +0 -9
  236. package/lib/module/specs/SkiaGraphiteViewNativeComponent.web.js +0 -22
  237. package/lib/module/specs/SkiaGraphiteViewNativeComponent.web.js.map +0 -1
  238. package/lib/module/specs/SkiaPictureViewNativeComponent.js.map +0 -1
  239. package/lib/module/specs/SkiaPictureViewNativeComponent.web.d.ts +0 -10
  240. package/lib/module/specs/SkiaPictureViewNativeComponent.web.js +0 -23
  241. package/lib/module/specs/SkiaPictureViewNativeComponent.web.js.map +0 -1
  242. package/lib/module/views/SkiaGraphiteView.web.d.ts +0 -14
  243. package/lib/module/views/SkiaGraphiteView.web.js.map +0 -1
  244. package/lib/module/views/SkiaPictureView.web.d.ts +0 -11
  245. package/lib/module/views/SkiaPictureView.web.js +0 -156
  246. package/lib/module/views/SkiaPictureView.web.js.map +0 -1
  247. package/lib/typescript/src/renderer/DefaultCanvas.d.ts +0 -8
  248. package/lib/typescript/src/renderer/GraphiteCanvas.d.ts +0 -22
  249. package/lib/typescript/src/renderer/GraphiteCanvas.web.d.ts +0 -1
  250. package/lib/typescript/src/specs/SkiaGraphiteViewNativeComponent.d.ts +0 -10
  251. package/lib/typescript/src/specs/SkiaGraphiteViewNativeComponent.web.d.ts +0 -9
  252. package/lib/typescript/src/specs/SkiaPictureViewNativeComponent.web.d.ts +0 -10
  253. package/lib/typescript/src/views/SkiaGraphiteView.web.d.ts +0 -14
  254. package/lib/typescript/src/views/SkiaPictureView.web.d.ts +0 -11
  255. package/libs/.graphite +0 -1
  256. package/src/renderer/DefaultCanvas.tsx +0 -41
  257. package/src/renderer/GraphiteCanvas.tsx +0 -61
  258. package/src/renderer/GraphiteCanvas.web.tsx +0 -3
  259. package/src/specs/SkiaGraphiteViewNativeComponent.ts +0 -17
  260. package/src/specs/SkiaGraphiteViewNativeComponent.web.ts +0 -31
  261. package/src/views/SkiaPictureView.web.tsx +0 -224
@@ -1,55 +1,40 @@
1
- #include "RNSkOpenGLCanvasProvider.h"
1
+ #include "RNSkAndroidCanvasProvider.h"
2
2
 
3
3
  #include <android/native_window_jni.h>
4
4
  #include <fbjni/fbjni.h>
5
5
  #include <jni.h>
6
6
  #include <memory>
7
7
 
8
- #include "RNSkLog.h"
9
-
10
- #if defined(SK_GRAPHITE)
11
8
  #include "RNDawnContext.h"
12
- #else
13
- #include "OpenGLContext.h"
14
- #endif
15
-
16
- #pragma clang diagnostic push
17
- #pragma clang diagnostic ignored "-Wdocumentation"
18
-
19
- #include "include/core/SkCanvas.h"
20
- #include "include/core/SkSurface.h"
21
-
22
- #pragma clang diagnostic pop
9
+ #include "RNSkLog.h"
23
10
 
24
11
  namespace RNSkia {
25
12
 
26
- RNSkOpenGLCanvasProvider::RNSkOpenGLCanvasProvider(
27
- std::function<void()> requestRedraw,
28
- std::shared_ptr<RNSkia::RNSkPlatformContext> platformContext)
29
- : RNSkCanvasProvider(std::move(requestRedraw)),
30
- _platformContext(std::move(platformContext)) {}
13
+ RNSkAndroidCanvasProvider::RNSkAndroidCanvasProvider(
14
+ std::shared_ptr<RNSkPlatformContext> platformContext)
15
+ : _platformContext(std::move(platformContext)) {}
31
16
 
32
- RNSkOpenGLCanvasProvider::~RNSkOpenGLCanvasProvider() {
17
+ RNSkAndroidCanvasProvider::~RNSkAndroidCanvasProvider() {
33
18
  _surfaceHolder = nullptr;
34
19
  releaseWindow();
35
20
  }
36
21
 
37
- int RNSkOpenGLCanvasProvider::getWidth() {
22
+ int RNSkAndroidCanvasProvider::getWidth() {
38
23
  if (_surfaceHolder) {
39
24
  return _surfaceHolder->getWidth();
40
25
  }
41
26
  return 0;
42
27
  }
43
28
 
44
- int RNSkOpenGLCanvasProvider::getHeight() {
29
+ int RNSkAndroidCanvasProvider::getHeight() {
45
30
  if (_surfaceHolder) {
46
31
  return _surfaceHolder->getHeight();
47
32
  }
48
33
  return 0;
49
34
  }
50
35
 
51
- ANativeWindow *RNSkOpenGLCanvasProvider::acquireWindow(jobject surface,
52
- bool isSurface) {
36
+ ANativeWindow *RNSkAndroidCanvasProvider::acquireWindow(jobject surface,
37
+ bool isSurface) {
53
38
  JNIEnv *env = facebook::jni::Environment::current();
54
39
  jobject jSurface = surface;
55
40
  if (!isSurface) {
@@ -65,20 +50,13 @@ ANativeWindow *RNSkOpenGLCanvasProvider::acquireWindow(jobject surface,
65
50
  env->DeleteLocalRef(localSurface);
66
51
  env->DeleteLocalRef(surfaceClass);
67
52
  jSurface = _jSurface;
68
- #if !defined(SK_GRAPHITE)
69
- _jSurfaceTexture = env->NewGlobalRef(surface);
70
- jclass surfaceTextureClass = env->GetObjectClass(surface);
71
- _updateTexImageMethod =
72
- env->GetMethodID(surfaceTextureClass, "updateTexImage", "()V");
73
- env->DeleteLocalRef(surfaceTextureClass);
74
- #endif
75
53
  }
76
54
  // Acquires a reference on the window, given back by releaseWindow().
77
55
  _window = ANativeWindow_fromSurface(env, jSurface);
78
56
  return _window;
79
57
  }
80
58
 
81
- void RNSkOpenGLCanvasProvider::releaseWindow() {
59
+ void RNSkAndroidCanvasProvider::releaseWindow() {
82
60
  if (_window == nullptr && _jSurface == nullptr) {
83
61
  return;
84
62
  }
@@ -97,33 +75,9 @@ void RNSkOpenGLCanvasProvider::releaseWindow() {
97
75
  env->DeleteGlobalRef(_jSurface);
98
76
  _jSurface = nullptr;
99
77
  }
100
- #if !defined(SK_GRAPHITE)
101
- if (_jSurfaceTexture != nullptr) {
102
- env->DeleteGlobalRef(_jSurfaceTexture);
103
- _jSurfaceTexture = nullptr;
104
- _updateTexImageMethod = nullptr;
105
- }
106
- #endif
107
- }
108
-
109
- #if !defined(SK_GRAPHITE)
110
- void RNSkOpenGLCanvasProvider::updateTexImage() {
111
- if (_jSurfaceTexture) {
112
- JNIEnv *env = facebook::jni::Environment::current();
113
- env->CallVoidMethod(_jSurfaceTexture, _updateTexImageMethod);
114
-
115
- // Check for exceptions
116
- if (env->ExceptionCheck()) {
117
- RNSkLogger::logToConsole("updateAndRelease() failed. The exception above "
118
- "can safely be ignored");
119
- env->ExceptionClear();
120
- }
121
- }
122
78
  }
123
- #endif
124
79
 
125
- #if defined(SK_GRAPHITE)
126
- void RNSkOpenGLCanvasProvider::updateTargetInfo() {
80
+ void RNSkAndroidCanvasProvider::updateTargetInfo() {
127
81
  std::lock_guard<std::mutex> lock(_targetInfoMutex);
128
82
  if (_surfaceHolder == nullptr) {
129
83
  _hasTargetInfo = false;
@@ -137,8 +91,7 @@ void RNSkOpenGLCanvasProvider::updateTargetInfo() {
137
91
  _hasTargetInfo = true;
138
92
  }
139
93
 
140
- bool RNSkOpenGLCanvasProvider::getGraphiteTargetInfo(
141
- RNSkGraphiteTargetInfo *info) {
94
+ bool RNSkAndroidCanvasProvider::getTargetInfo(RNSkGraphiteTargetInfo *info) {
142
95
  std::lock_guard<std::mutex> lock(_targetInfoMutex);
143
96
  if (!_hasTargetInfo) {
144
97
  return false;
@@ -147,7 +100,23 @@ bool RNSkOpenGLCanvasProvider::getGraphiteTargetInfo(
147
100
  return true;
148
101
  }
149
102
 
150
- bool RNSkOpenGLCanvasProvider::presentRecordings(
103
+ void RNSkAndroidCanvasProvider::setLayoutSize(int width, int height) {
104
+ std::lock_guard<std::mutex> lock(_targetInfoMutex);
105
+ _layoutWidth = width;
106
+ _layoutHeight = height;
107
+ }
108
+
109
+ bool RNSkAndroidCanvasProvider::getLayoutSize(int *width, int *height) {
110
+ std::lock_guard<std::mutex> lock(_targetInfoMutex);
111
+ if (_layoutWidth <= 0 || _layoutHeight <= 0) {
112
+ return false;
113
+ }
114
+ *width = _layoutWidth;
115
+ *height = _layoutHeight;
116
+ return true;
117
+ }
118
+
119
+ bool RNSkAndroidCanvasProvider::presentRecordings(
151
120
  const std::vector<skgpu::graphite::Recording *> &recordings) {
152
121
  if (_surfaceHolder == nullptr) {
153
122
  return false;
@@ -155,33 +124,18 @@ bool RNSkOpenGLCanvasProvider::presentRecordings(
155
124
  return static_cast<DawnWindowContext *>(_surfaceHolder.get())
156
125
  ->presentRecordings(recordings);
157
126
  }
158
- #endif
159
-
160
- bool RNSkOpenGLCanvasProvider::renderToCanvas(
161
- const std::function<void(SkCanvas *)> &cb) {
162
- if (_surfaceHolder != nullptr && cb != nullptr) {
163
- // Get the surface
164
- auto surface = _surfaceHolder->getSurface();
165
- #if !defined(SK_GRAPHITE)
166
- updateTexImage();
167
- #endif
168
- if (surface) {
169
- // Draw into canvas using callback
170
- cb(surface->getCanvas());
171
- // Swap buffers and show on screen
172
- _surfaceHolder->present();
173
- return true;
174
- } else {
175
- // the render context did not provide a surface
176
- return false;
177
- }
127
+
128
+ bool RNSkAndroidCanvasProvider::presentImage(const sk_sp<SkImage> &image) {
129
+ if (_surfaceHolder == nullptr) {
130
+ return false;
178
131
  }
179
- return false;
132
+ return static_cast<DawnWindowContext *>(_surfaceHolder.get())
133
+ ->presentImage(image);
180
134
  }
181
135
 
182
- void RNSkOpenGLCanvasProvider::surfaceAvailable(jobject surface, int width,
183
- int height, bool isSurface,
184
- bool highBitDepth) {
136
+ void RNSkAndroidCanvasProvider::surfaceAvailable(jobject surface, int width,
137
+ int height, bool isSurface,
138
+ bool highBitDepth) {
185
139
  // Release the old surface and its window
186
140
  _surfaceHolder = nullptr;
187
141
  releaseWindow();
@@ -192,32 +146,25 @@ void RNSkOpenGLCanvasProvider::surfaceAvailable(jobject surface, int width,
192
146
  releaseWindow();
193
147
  return;
194
148
  }
195
- #if defined(SK_GRAPHITE)
196
149
  _surfaceHolder = DawnContext::getInstance().MakeWindow(window, width, height,
197
150
  highBitDepth);
198
151
  updateTargetInfo();
199
- #else
200
- _surfaceHolder =
201
- OpenGLContext::getInstance().MakeWindow(window, highBitDepth);
202
- #endif
203
152
 
204
153
  // Post redraw request to ensure we paint in the next draw cycle.
205
- _requestRedraw();
154
+ requestRedraw();
206
155
  }
207
156
 
208
- void RNSkOpenGLCanvasProvider::surfaceDestroyed() {
157
+ void RNSkAndroidCanvasProvider::surfaceDestroyed() {
209
158
  // destroy the renderer (a unique pointer so the dtor will be called
210
159
  // immediately.)
211
160
  _surfaceHolder = nullptr;
212
- #if defined(SK_GRAPHITE)
213
161
  updateTargetInfo();
214
- #endif
215
162
  releaseWindow();
216
163
  }
217
164
 
218
- void RNSkOpenGLCanvasProvider::surfaceSizeChanged(jobject jSurface, int width,
219
- int height, bool isSurface,
220
- bool highBitDepth) {
165
+ void RNSkAndroidCanvasProvider::surfaceSizeChanged(jobject jSurface, int width,
166
+ int height, bool isSurface,
167
+ bool highBitDepth) {
221
168
  if (width == 0 && height == 0) {
222
169
  // Setting width/height to zero is nothing we need to care about when
223
170
  // it comes to invalidating the surface.
@@ -228,12 +175,10 @@ void RNSkOpenGLCanvasProvider::surfaceSizeChanged(jobject jSurface, int width,
228
175
  surfaceAvailable(jSurface, width, height, isSurface, highBitDepth);
229
176
  } else {
230
177
  _surfaceHolder->resize(width, height);
231
- #if defined(SK_GRAPHITE)
232
178
  updateTargetInfo();
233
- #endif
234
179
  }
235
180
 
236
181
  // Redraw after size change
237
- _requestRedraw();
182
+ requestRedraw();
238
183
  }
239
184
  } // namespace RNSkia
@@ -6,35 +6,45 @@
6
6
  #include <mutex>
7
7
  #include <vector>
8
8
 
9
- #include "RNSkView.h"
9
+ #include "RNSkCanvasProvider.h"
10
+ #include "RNSkPlatformContext.h"
10
11
  #include "RNWindowContext.h"
11
12
 
12
13
  #include <android/native_window.h>
13
14
 
14
15
  namespace RNSkia {
15
16
 
16
- class RNSkOpenGLCanvasProvider
17
- : public RNSkia::RNSkCanvasProvider,
18
- public std::enable_shared_from_this<RNSkOpenGLCanvasProvider> {
17
+ /**
18
+ * The ANativeWindow a SkiaView presents into: the Surface of a SurfaceView or
19
+ * a Surface created over the SurfaceTexture of a TextureView, configured as a
20
+ * Dawn surface (see DawnWindowContext).
21
+ */
22
+ class RNSkAndroidCanvasProvider : public RNSkCanvasProvider {
19
23
  public:
20
- RNSkOpenGLCanvasProvider(
21
- std::function<void()> requestRedraw,
22
- std::shared_ptr<RNSkia::RNSkPlatformContext> platformContext);
24
+ explicit RNSkAndroidCanvasProvider(
25
+ std::shared_ptr<RNSkPlatformContext> platformContext);
23
26
 
24
- virtual ~RNSkOpenGLCanvasProvider();
27
+ virtual ~RNSkAndroidCanvasProvider();
25
28
 
26
29
  int getWidth() override;
27
30
 
28
31
  int getHeight() override;
29
32
 
30
- bool renderToCanvas(const std::function<void(SkCanvas *)> &cb) override;
33
+ bool getTargetInfo(RNSkGraphiteTargetInfo *info) override;
31
34
 
32
- #if defined(SK_GRAPHITE)
33
- bool getGraphiteTargetInfo(RNSkGraphiteTargetInfo *info) override;
35
+ bool getLayoutSize(int *width, int *height) override;
34
36
 
35
37
  bool presentRecordings(
36
38
  const std::vector<skgpu::graphite::Recording *> &recordings) override;
37
- #endif
39
+
40
+ bool presentImage(const sk_sp<SkImage> &image) override;
41
+
42
+ /**
43
+ The pixel size the backing view was laid out with. The surface it gets
44
+ (SurfaceView or TextureView) has exactly this size, so a frame recorded
45
+ before the surface exists already matches it. Main thread.
46
+ */
47
+ void setLayoutSize(int width, int height);
38
48
 
39
49
  void surfaceAvailable(jobject surface, int width, int height, bool isSurface,
40
50
  bool highBitDepth);
@@ -52,13 +62,8 @@ private:
52
62
  // Gives back what acquireWindow() took. Call after the window context that
53
63
  // draws into the window is gone.
54
64
  void releaseWindow();
55
- #if !defined(SK_GRAPHITE)
56
- // Lets the SurfaceTexture of a TextureView consume the previous frame.
57
- void updateTexImage();
58
- #else
59
65
  // Copies the window's target description where any thread can read it.
60
66
  void updateTargetInfo();
61
- #endif
62
67
 
63
68
  std::unique_ptr<WindowContext> _surfaceHolder = nullptr;
64
69
  std::shared_ptr<RNSkPlatformContext> _platformContext;
@@ -67,13 +72,10 @@ private:
67
72
  // as the window and is released with it (a SurfaceView's Surface is owned by
68
73
  // the view).
69
74
  jobject _jSurface = nullptr;
70
- #if !defined(SK_GRAPHITE)
71
- jobject _jSurfaceTexture = nullptr;
72
- jmethodID _updateTexImageMethod = nullptr;
73
- #else
74
75
  std::mutex _targetInfoMutex;
75
76
  RNSkGraphiteTargetInfo _targetInfo;
76
77
  bool _hasTargetInfo = false;
77
- #endif
78
+ int _layoutWidth = 0;
79
+ int _layoutHeight = 0;
78
80
  };
79
81
  } // namespace RNSkia
@@ -10,11 +10,7 @@
10
10
  #include <memory>
11
11
  #include <string>
12
12
 
13
- #if defined(SK_GRAPHITE)
14
13
  #include "RNDawnContext.h"
15
- #else
16
- #include "OpenGLContext.h"
17
- #endif
18
14
 
19
15
  #include "AHardwareBufferUtils.h"
20
16
  #include "JniPlatformContext.h"
@@ -54,49 +50,13 @@ public:
54
50
 
55
51
  sk_sp<SkSurface> makeOffscreenSurface(int width, int height,
56
52
  bool useP3ColorSpace = false) override {
57
- #if defined(SK_GRAPHITE)
58
53
  return DawnContext::getInstance().MakeOffscreen(width, height,
59
54
  useP3ColorSpace);
60
- #else
61
- return OpenGLContext::getInstance().MakeOffscreen(width, height,
62
- useP3ColorSpace);
63
- #endif
64
55
  }
65
56
 
66
57
  sk_sp<SkImage> makeImageFromNativeBuffer(void *buffer) override {
67
- #if defined(SK_GRAPHITE)
68
58
  return DawnContext::getInstance().MakeImageFromBuffer(buffer);
69
- #else
70
- return OpenGLContext::getInstance().MakeImageFromBuffer(buffer);
71
- #endif
72
- }
73
-
74
- #if !defined(SK_GRAPHITE)
75
- sk_sp<SkImage> makeImageFromNativeTexture(const TextureInfo &texInfo,
76
- int width, int height,
77
- bool mipMapped) override {
78
- GrGLTextureInfo textureInfo;
79
- textureInfo.fTarget = (GrGLenum)texInfo.glTarget;
80
- textureInfo.fID = (GrGLuint)texInfo.glID;
81
- textureInfo.fFormat = (GrGLenum)texInfo.glFormat;
82
- textureInfo.fProtected =
83
- texInfo.glProtected ? skgpu::Protected::kYes : skgpu::Protected::kNo;
84
-
85
- OpenGLContext::getInstance().makeCurrent();
86
- if (glIsTexture(textureInfo.fID) == GL_FALSE) {
87
- throw std::runtime_error("Invalid textureInfo");
88
- }
89
-
90
- GrBackendTexture backendTexture = GrBackendTextures::MakeGL(
91
- width, height,
92
- mipMapped ? skgpu::Mipmapped::kYes : skgpu::Mipmapped::kNo,
93
- textureInfo);
94
- return SkImages::BorrowTextureFrom(
95
- OpenGLContext::getInstance().getDirectContext(), backendTexture,
96
- kTopLeft_GrSurfaceOrigin, kRGBA_8888_SkColorType, kUnpremul_SkAlphaType,
97
- nullptr);
98
59
  }
99
- #endif
100
60
 
101
61
  std::shared_ptr<RNSkVideo> createVideo(const std::string &url) override {
102
62
  auto jniVideo = _jniPlatformContext->createVideo(url);
@@ -112,13 +72,11 @@ public:
112
72
 
113
73
  uint64_t makeNativeBuffer(sk_sp<SkImage> image) override {
114
74
  #if __ANDROID_API__ >= 26
115
- #if defined(SK_GRAPHITE)
116
75
  // A Graphite GPU texture can't be read with readPixels(nullptr); read it
117
76
  // back to a raster image first or the buffer ends up uninitialized/black.
118
77
  if (image && image->isTextureBacked()) {
119
78
  image = DawnContext::getInstance().MakeRasterImage(image);
120
79
  }
121
- #endif
122
80
  auto bytesPerPixel = image->imageInfo().bytesPerPixel();
123
81
  int bytesPerRow = image->width() * bytesPerPixel;
124
82
  auto buf = SkData::MakeUninitialized(image->width() * image->height() *
@@ -229,47 +187,6 @@ public:
229
187
  #endif
230
188
  }
231
189
 
232
- #if !defined(SK_GRAPHITE)
233
- GrDirectContext *getDirectContext() override {
234
- return OpenGLContext::getInstance().getDirectContext();
235
- }
236
-
237
- const TextureInfo getTexture(sk_sp<SkImage> image) override {
238
- GrBackendTexture texture;
239
- if (!SkImages::GetBackendTextureFromImage(image, &texture, true)) {
240
- throw std::runtime_error("Couldn't get backend texture from image.");
241
- }
242
- return getTextureInfo(texture);
243
- }
244
-
245
- const TextureInfo getTexture(sk_sp<SkSurface> surface) override {
246
- GrBackendTexture texture = SkSurfaces::GetBackendTexture(
247
- surface.get(), SkSurface::BackendHandleAccess::kFlushRead);
248
- return getTextureInfo(texture);
249
- }
250
-
251
- static TextureInfo getTextureInfo(const GrBackendTexture &texture) {
252
-
253
- if (!texture.isValid()) {
254
- throw std::runtime_error("invalid backend texture");
255
- }
256
- GrGLTextureInfo textureInfo;
257
- if (!GrBackendTextures::GetGLTextureInfo(texture, &textureInfo)) {
258
- throw std::runtime_error("couldn't get OpenGL texture");
259
- }
260
-
261
- OpenGLContext::getInstance().makeCurrent();
262
- glFlush();
263
-
264
- TextureInfo texInfo;
265
- texInfo.glProtected = textureInfo.isProtected();
266
- texInfo.glID = textureInfo.fID;
267
- texInfo.glFormat = textureInfo.fFormat;
268
- texInfo.glTarget = textureInfo.fTarget;
269
- return texInfo;
270
- }
271
- #endif
272
-
273
190
  sk_sp<SkFontMgr> createFontMgr() override {
274
191
  return SkFontMgr_New_Android(nullptr, SkFontScanner_Make_FreeType());
275
192
  }
@@ -7,11 +7,7 @@
7
7
 
8
8
  #include "RNSkLog.h"
9
9
 
10
- #if defined(SK_GRAPHITE)
11
10
  #include "RNDawnContext.h"
12
- #else
13
- #include "OpenGLContext.h"
14
- #endif
15
11
 
16
12
  #pragma clang diagnostic push
17
13
  #pragma clang diagnostic ignored "-Wdocumentation"
@@ -59,11 +55,7 @@ sk_sp<SkImage> RNSkAndroidVideo::nextImage(double *timeStamp) {
59
55
  // Convert jobject to AHardwareBuffer
60
56
  AHardwareBuffer *buffer =
61
57
  AHardwareBuffer_fromHardwareBuffer(env, jHardwareBuffer);
62
- #if defined(SK_GRAPHITE)
63
58
  return DawnContext::getInstance().MakeImageFromBuffer(buffer);
64
- #else
65
- return OpenGLContext::getInstance().MakeImageFromBuffer(buffer);
66
- #endif
67
59
  #else
68
60
  return nullptr;
69
61
  #endif
@@ -33,8 +33,7 @@ public class RNSkiaPackage extends BaseReactPackage implements ReactPackage {
33
33
  @Override
34
34
  public List<ViewManager> createViewManagers(ReactApplicationContext reactContext) {
35
35
  return Arrays.<ViewManager>asList(
36
- new SkiaPictureViewManager(),
37
- new SkiaGraphiteViewManager()
36
+ new SkiaViewManager()
38
37
  );
39
38
  }
40
39
 
@@ -11,12 +11,10 @@ import androidx.annotation.NonNull;
11
11
  public class SkiaSurfaceView extends SurfaceView implements SurfaceHolder.Callback {
12
12
 
13
13
  SkiaViewAPI mApi;
14
- boolean mDebug;
15
14
 
16
- public SkiaSurfaceView(Context context, SkiaViewAPI api, boolean debug, boolean zOrderOnTop, boolean opaque) {
15
+ public SkiaSurfaceView(Context context, SkiaViewAPI api, boolean zOrderOnTop, boolean opaque) {
17
16
  super(context);
18
17
  mApi = api;
19
- mDebug = debug;
20
18
  // Must be set before the surface is created.
21
19
  setZOrderOnTop(zOrderOnTop);
22
20
  setOpaque(opaque);
@@ -4,7 +4,6 @@ import android.annotation.SuppressLint;
4
4
  import android.content.Context;
5
5
  import android.graphics.SurfaceTexture;
6
6
  import android.util.Log;
7
- import android.view.Surface;
8
7
  import android.view.TextureView;
9
8
  import androidx.annotation.NonNull;
10
9
 
@@ -14,23 +13,16 @@ public class SkiaTextureView extends TextureView implements TextureView.SurfaceT
14
13
  private String tag = "SkiaTextureView";
15
14
 
16
15
  SkiaViewAPI mApi;
17
- boolean mDebug;
18
16
 
19
- public SkiaTextureView(Context context, SkiaViewAPI api, boolean debug, boolean opaque) {
17
+ public SkiaTextureView(Context context, SkiaViewAPI api, boolean opaque) {
20
18
  super(context);
21
19
  mApi = api;
22
- mDebug = debug;
23
20
  // An opaque TextureView lets the UI toolkit skip blending it; it can be
24
21
  // toggled on a live view.
25
22
  setOpaque(opaque);
26
23
  setSurfaceTextureListener(this);
27
24
  }
28
25
 
29
- @Override
30
- protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
31
- super.onLayout(changed, left, top, right, bottom);
32
- }
33
-
34
26
  @Override
35
27
  public void onSurfaceTextureAvailable(@NonNull SurfaceTexture surfaceTexture, int width, int height) {
36
28
  Log.i(tag, "onSurfaceTextureAvailable: " + width + "x" + height);
@@ -49,15 +41,7 @@ public class SkiaTextureView extends TextureView implements TextureView.SurfaceT
49
41
  return true;
50
42
  }
51
43
 
52
- private long _prevTimestamp = 0;
53
44
  @Override
54
45
  public void onSurfaceTextureUpdated(@NonNull SurfaceTexture surface) {
55
- if (!mDebug) {
56
- return;
57
- }
58
- long timestamp = surface.getTimestamp();
59
- long frameDuration = (timestamp - _prevTimestamp)/1000000;
60
- Log.i("SkiaTextureView", "onSurfaceTextureUpdated "+frameDuration+"ms");
61
- _prevTimestamp = timestamp;
62
46
  }
63
47
  }