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
@@ -0,0 +1,221 @@
1
+ #pragma once
2
+
3
+ #include <functional>
4
+ #include <memory>
5
+ #include <utility>
6
+ #include <vector>
7
+
8
+ #include "RNDawnContext.h"
9
+ #include "RNDawnUtils.h"
10
+ #include "RNSkPlatformContext.h"
11
+
12
+ #pragma clang diagnostic push
13
+ #pragma clang diagnostic ignored "-Wdocumentation"
14
+
15
+ #include "include/core/SkCanvas.h"
16
+ #include "include/core/SkImage.h"
17
+ #include "include/core/SkSurface.h"
18
+ #include "include/gpu/graphite/Recording.h"
19
+ #include "include/gpu/graphite/TextureInfo.h"
20
+ #include "include/gpu/graphite/dawn/DawnGraphiteTypes.h"
21
+
22
+ #pragma clang diagnostic pop
23
+
24
+ namespace RNSkia {
25
+
26
+ /**
27
+ * Describes the texture a recording is replayed onto: the pixel size and the
28
+ * format of a window (or offscreen) surface. A deferred canvas is recorded
29
+ * against this description, so it can be created before the surface itself
30
+ * exists.
31
+ */
32
+ struct RNSkGraphiteTargetInfo {
33
+ int width = 0;
34
+ int height = 0;
35
+ SkColorType colorType = kUnknown_SkColorType;
36
+ skgpu::graphite::TextureInfo textureInfo;
37
+ };
38
+
39
+ /**
40
+ * The surface a view presents into: a platform window (a CAMetalLayer, an
41
+ * ANativeWindow) or an offscreen surface. It describes its target texture to
42
+ * whoever records for the view and replays their recordings onto it.
43
+ */
44
+ class RNSkCanvasProvider {
45
+ public:
46
+ virtual ~RNSkCanvasProvider() = default;
47
+
48
+ /** Width of the surface, in pixels. */
49
+ virtual int getWidth() = 0;
50
+
51
+ /** Height of the surface, in pixels. */
52
+ virtual int getHeight() = 0;
53
+
54
+ /**
55
+ Describes the current target texture. Safe to call from any thread;
56
+ returns false while there is no surface to describe.
57
+ */
58
+ virtual bool getTargetInfo(RNSkGraphiteTargetInfo *info) = 0;
59
+
60
+ /**
61
+ The size in pixels the surface will have, known from the platform layout
62
+ before the surface itself exists (on Android the surface only appears a
63
+ frame after the view is laid out). Safe to call from any thread; returns
64
+ false until the view is laid out. A frame recorded against this size is
65
+ presented as is once the surface appears, where one recorded against a
66
+ size derived from the layout in points could be off by a pixel and would
67
+ not cover the surface.
68
+ */
69
+ virtual bool getLayoutSize(int *width, int *height) { return false; }
70
+
71
+ /**
72
+ Replays the recordings, in order, onto the target texture and presents
73
+ it. Called on the thread that owns the surface. Returns false when the
74
+ surface cannot present right now (there is none, or the app is in the
75
+ background): nothing was consumed.
76
+ */
77
+ virtual bool presentRecordings(
78
+ const std::vector<skgpu::graphite::Recording *> &recordings) = 0;
79
+
80
+ /**
81
+ Draws an image at the origin of the target texture and presents it. Same
82
+ thread and return value as presentRecordings(). Used for a recording whose
83
+ size differs from the target's: it is replayed into a texture of its own
84
+ size first (see RNSkView::present).
85
+ */
86
+ virtual bool presentImage(const sk_sp<SkImage> &image) = 0;
87
+
88
+ /**
89
+ Installed by the view owning the provider: asks it for a frame when the
90
+ surface appears or changes size.
91
+ */
92
+ void setRequestRedraw(std::function<void()> requestRedraw) {
93
+ _requestRedraw = std::move(requestRedraw);
94
+ }
95
+
96
+ protected:
97
+ void requestRedraw() {
98
+ if (_requestRedraw) {
99
+ _requestRedraw();
100
+ }
101
+ }
102
+
103
+ private:
104
+ std::function<void()> _requestRedraw;
105
+ };
106
+
107
+ /**
108
+ * An offscreen surface the content of a view is replayed into for a snapshot.
109
+ */
110
+ class RNSkOffscreenCanvasProvider : public RNSkCanvasProvider {
111
+ public:
112
+ RNSkOffscreenCanvasProvider(
113
+ const std::shared_ptr<RNSkPlatformContext> &context, int width,
114
+ int height)
115
+ : _width(width), _height(height), _pd(context->getPixelDensity()),
116
+ _surface(context->makeOffscreenSurface(width, height)) {}
117
+
118
+ virtual ~RNSkOffscreenCanvasProvider() = default;
119
+
120
+ /** The canvas of the surface, in pixels; nullptr without a surface. */
121
+ SkCanvas *getCanvas() { return _surface ? _surface->getCanvas() : nullptr; }
122
+
123
+ /**
124
+ A GPU image of the surface, usable by any recorder of the context once
125
+ this returns; nullptr without a surface.
126
+ */
127
+ sk_sp<SkImage> makeImage() {
128
+ if (_surface == nullptr) {
129
+ return nullptr;
130
+ }
131
+ auto image = _surface->makeImageSnapshot();
132
+ // The snapshot is a copy task on the surface's recorder: submitted here,
133
+ // so that the image is complete for whoever draws it next.
134
+ if (auto *recorder = _surface->recorder()) {
135
+ DawnContext::getInstance().submitRecording(recorder->snap().get());
136
+ }
137
+ return image;
138
+ }
139
+
140
+ /**
141
+ Returns a snapshot of the current surface/canvas
142
+ */
143
+ sk_sp<SkImage> makeSnapshot(SkRect *bounds) {
144
+ if (_surface == nullptr) {
145
+ return nullptr;
146
+ }
147
+ sk_sp<SkImage> image;
148
+ if (bounds != nullptr) {
149
+ SkIRect b =
150
+ SkIRect::MakeXYWH(bounds->x() * _pd, bounds->y() * _pd,
151
+ bounds->width() * _pd, bounds->height() * _pd);
152
+ image = _surface->makeImageSnapshot(b);
153
+ } else {
154
+ image = _surface->makeImageSnapshot();
155
+ }
156
+ // Only Graphite-backed surfaces have a recorder to snap/submit; a raster
157
+ // surface's snapshot is already a valid CPU image.
158
+ if (auto *recorder = _surface->recorder()) {
159
+ DawnContext::getInstance().submitRecording(recorder->snap().get());
160
+ }
161
+ return DawnContext::getInstance().MakeRasterImage(image);
162
+ }
163
+
164
+ int getWidth() override { return _width; }
165
+
166
+ int getHeight() override { return _height; }
167
+
168
+ bool getTargetInfo(RNSkGraphiteTargetInfo *info) override {
169
+ if (_surface == nullptr || _surface->recorder() == nullptr) {
170
+ return false;
171
+ }
172
+ // Graphite gives its render targets the sampled+renderable usage, a
173
+ // superset of what a deferred canvas asks for.
174
+ auto colorType = _surface->imageInfo().colorType();
175
+ info->width = _width;
176
+ info->height = _height;
177
+ info->colorType = colorType;
178
+ info->textureInfo = skgpu::graphite::TextureInfos::MakeDawn(
179
+ skgpu::graphite::DawnTextureInfo(
180
+ skgpu::graphite::SampleCount::k1, skgpu::Mipmapped::kNo,
181
+ DawnUtils::textureFormatForColorType(colorType),
182
+ DawnUtils::DefaultTargetUsage, wgpu::TextureAspect::All));
183
+ return true;
184
+ }
185
+
186
+ bool presentRecordings(
187
+ const std::vector<skgpu::graphite::Recording *> &recordings) override {
188
+ auto *recorder = _surface ? _surface->recorder() : nullptr;
189
+ if (recorder == nullptr) {
190
+ return false;
191
+ }
192
+ // A new surface clears itself in its first pass, which its own recorder
193
+ // only records when it next snaps. The recordings go straight to the
194
+ // context, so that clear would run after them and wipe them: record and
195
+ // submit it first (the explicit clear makes sure the pass is emitted).
196
+ if (!_cleared) {
197
+ _surface->getCanvas()->clear(SK_ColorTRANSPARENT);
198
+ DawnContext::getInstance().submitRecording(recorder->snap().get());
199
+ _cleared = true;
200
+ }
201
+ return DawnContext::getInstance().insertRecordings(recordings,
202
+ _surface.get());
203
+ }
204
+
205
+ bool presentImage(const sk_sp<SkImage> &image) override {
206
+ if (_surface == nullptr) {
207
+ return false;
208
+ }
209
+ _surface->getCanvas()->drawImage(image, 0, 0);
210
+ return true;
211
+ }
212
+
213
+ private:
214
+ int _width;
215
+ int _height;
216
+ float _pd;
217
+ sk_sp<SkSurface> _surface;
218
+ bool _cleared = false;
219
+ };
220
+
221
+ } // namespace RNSkia
@@ -1,15 +1,13 @@
1
1
  // Everything that needs a complete Recorder lives here rather than in
2
2
  // RNSkGraphiteProducer.h (which the view headers include on their own).
3
- #if defined(SK_GRAPHITE)
4
-
5
3
  #include "RNSkGraphiteProducer.h"
6
4
 
7
5
  #include <memory>
8
6
  #include <utility>
9
7
 
10
- #include "RNSkGraphiteView.h"
11
- #include "RNSkPictureView.h"
8
+ #include "RNSkGraphiteTarget.h"
12
9
  #include "RNSkThreadPool.h"
10
+ #include "api/recorder/DrawingCtx.h"
13
11
  #include "api/recorder/RNRecorder.h"
14
12
  #include "utils/RNSkLog.h"
15
13
 
@@ -20,6 +18,21 @@ namespace RNSkia {
20
18
 
21
19
  RNSkGraphiteProducer::~RNSkGraphiteProducer() = default;
22
20
 
21
+ void RNSkGraphiteProducer::drawContent(SkCanvas *canvas, Recorder *recorder,
22
+ const sk_sp<SkPicture> &picture,
23
+ float pixelDensity) {
24
+ canvas->clear(SK_ColorTRANSPARENT);
25
+ canvas->save();
26
+ canvas->scale(pixelDensity, pixelDensity);
27
+ if (recorder != nullptr) {
28
+ DrawingCtx ctx(canvas);
29
+ recorder->play(&ctx);
30
+ } else if (picture != nullptr) {
31
+ canvas->drawPicture(picture);
32
+ }
33
+ canvas->restore();
34
+ }
35
+
23
36
  void RNSkGraphiteProducer::setTarget(
24
37
  std::shared_ptr<RNSkGraphiteTarget> target) {
25
38
  std::lock_guard<std::mutex> lock(_mutex);
@@ -67,6 +80,18 @@ bool RNSkGraphiteProducer::hasContent() {
67
80
  return _recorder != nullptr || _picture != nullptr;
68
81
  }
69
82
 
83
+ bool RNSkGraphiteProducer::applyUpdatesTo(
84
+ const std::shared_ptr<Recorder> &recorder, jsi::Runtime &runtime,
85
+ double recorderId, const jsi::Array &values) {
86
+ if (recorder == nullptr || recorder->id != recorderId) {
87
+ return false;
88
+ }
89
+ // The values are written into the commands by the next replay, which the
90
+ // caller schedules: the mapper never waits for a draw.
91
+ recorder->readUpdates(runtime, values);
92
+ return true;
93
+ }
94
+
70
95
  bool RNSkGraphiteProducer::applyUpdates(jsi::Runtime &runtime,
71
96
  double recorderId,
72
97
  const jsi::Array &values) {
@@ -75,13 +100,12 @@ bool RNSkGraphiteProducer::applyUpdates(jsi::Runtime &runtime,
75
100
  std::lock_guard<std::mutex> lock(_mutex);
76
101
  recorder = _recorder;
77
102
  }
78
- if (recorder == nullptr || recorder->id != recorderId) {
79
- return false;
80
- }
81
103
  // Outside the lock: a commit replacing the recorder must not wait for the
82
104
  // read. Should it land while this runs, the values go into the retired
83
105
  // recorder and the commit's own frame draws the new one.
84
- recorder->readUpdates(runtime, values);
106
+ if (!applyUpdatesTo(recorder, runtime, recorderId, values)) {
107
+ return false;
108
+ }
85
109
  std::lock_guard<std::mutex> lock(_mutex);
86
110
  _dirty = true;
87
111
  kickLocked();
@@ -142,14 +166,14 @@ void RNSkGraphiteProducer::produce() {
142
166
  // The deferred canvas already draws in points.
143
167
  drawContent(canvas, recorder.get(), picture, /* pixelDensity= */ 1.0f);
144
168
  } catch (const std::exception &e) {
145
- RNSkLogger::logToConsole(
146
- "GraphiteCanvas: replaying the scene failed: %s", e.what());
169
+ RNSkLogger::logToConsole("Canvas: replaying the scene failed: %s",
170
+ e.what());
147
171
  }
148
172
  try {
149
173
  recording = target->finishRecording();
150
174
  } catch (const std::exception &e) {
151
- RNSkLogger::logToConsole(
152
- "GraphiteCanvas: recording the frame failed: %s", e.what());
175
+ RNSkLogger::logToConsole("Canvas: recording the frame failed: %s",
176
+ e.what());
153
177
  }
154
178
  }
155
179
  }
@@ -185,5 +209,3 @@ void RNSkGraphiteProducer::renderInto(SkCanvas *canvas, float pixelDensity) {
185
209
  }
186
210
 
187
211
  } // namespace RNSkia
188
-
189
- #endif // SK_GRAPHITE
@@ -1,7 +1,5 @@
1
1
  #pragma once
2
2
 
3
- #if defined(SK_GRAPHITE)
4
-
5
3
  #include <memory>
6
4
  #include <mutex>
7
5
 
@@ -20,9 +18,9 @@ class Recorder;
20
18
  class RNSkGraphiteTarget;
21
19
 
22
20
  /**
23
- * Records the declarative content of a SkiaGraphiteView (a Recorder handed
24
- * over by <GraphiteCanvas>, or a picture) into Graphite recordings, on the
25
- * render thread pool.
21
+ * Records the declarative content of a view (a Recorder handed over by
22
+ * <Canvas>, or a picture) into Graphite recordings, on the render thread
23
+ * pool.
26
24
  *
27
25
  * Three threads meet here. The JS thread hands over the content. A Reanimated
28
26
  * mapper, on the UI runtime, reads the shared values into the recorder's
@@ -50,7 +48,11 @@ public:
50
48
  /**
51
49
  Takes ownership of the recorder (or releases it with nullptr). A recording
52
50
  without shared values is played once into a picture: nothing will ever
53
- update it, and drawing a picture is cheaper than replaying commands.
51
+ update it, and drawing a picture is cheaper than replaying commands. The
52
+ recorder is owned here rather than by a JS wrapper: its commands hold
53
+ every native resource the canvas draws (images, pictures, paths), and
54
+ tying their lifetime to the garbage collector of a runtime that rarely
55
+ allocates (the UI runtime) kept them resident long after unmount.
54
56
  */
55
57
  void setRecorder(std::shared_ptr<Recorder> recorder);
56
58
 
@@ -73,6 +75,14 @@ public:
73
75
  bool applyUpdates(jsi::Runtime &runtime, double recorderId,
74
76
  const jsi::Array &values);
75
77
 
78
+ /**
79
+ Same as applyUpdates(), for a recording that no view owns yet (one queued
80
+ in the view registry until its view registers).
81
+ */
82
+ static bool applyUpdatesTo(const std::shared_ptr<Recorder> &recorder,
83
+ jsi::Runtime &runtime, double recorderId,
84
+ const jsi::Array &values);
85
+
76
86
  /**
77
87
  Marks the content dirty and schedules a frame if one can start. Returns
78
88
  whether a frame is coming at all: there is content and a target to record
@@ -90,6 +100,13 @@ public:
90
100
  void renderInto(SkCanvas *canvas, float pixelDensity);
91
101
 
92
102
  private:
103
+ /**
104
+ Replays declarative content, a recorder if there is one, else a picture,
105
+ into a canvas: clears it and applies the density.
106
+ */
107
+ static void drawContent(SkCanvas *canvas, Recorder *recorder,
108
+ const sk_sp<SkPicture> &picture, float pixelDensity);
109
+
93
110
  /**
94
111
  Swaps the content under the lock and releases the previous one outside of
95
112
  it: the recorder's destructor hands the commands to the main thread, and a
@@ -112,5 +129,3 @@ private:
112
129
  };
113
130
 
114
131
  } // namespace RNSkia
115
-
116
- #endif // SK_GRAPHITE