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,31 +1,30 @@
1
-
2
1
  #pragma once
3
2
 
3
+ #include <atomic>
4
+ #include <functional>
4
5
  #include <memory>
6
+ #include <mutex>
5
7
  #include <string>
6
8
  #include <unordered_map>
9
+ #include <utility>
7
10
  #include <vector>
8
11
 
12
+ #include <jsi/jsi.h>
13
+
14
+ #include "RNSkCanvasProvider.h"
15
+ #include "RNSkGraphiteProducer.h"
16
+ #include "RNSkGraphiteTarget.h"
9
17
  #include "RNSkPlatformContext.h"
10
18
  #include "jsi/ViewProperty.h"
11
-
12
- #include "api/JsiSkImage.h"
13
- #include "api/JsiSkPoint.h"
14
- #include "api/JsiSkRect.h"
19
+ #include "utils/RNSkLog.h"
15
20
 
16
21
  #pragma clang diagnostic push
17
22
  #pragma clang diagnostic ignored "-Wdocumentation"
18
23
 
19
24
  #include "include/core/SkCanvas.h"
20
- #include "include/core/SkSurface.h"
21
-
22
- #if defined(SK_GRAPHITE)
23
- #include "RNDawnContext.h"
24
- #include "RNDawnUtils.h"
25
- #include "include/gpu/graphite/Recording.h"
26
- #include "include/gpu/graphite/TextureInfo.h"
27
- #include "include/gpu/graphite/dawn/DawnGraphiteTypes.h"
28
- #endif
25
+ #include "include/core/SkColorSpace.h"
26
+ #include "include/core/SkImage.h"
27
+ #include "include/core/SkRect.h"
29
28
 
30
29
  #pragma clang diagnostic pop
31
30
 
@@ -33,211 +32,108 @@ namespace RNSkia {
33
32
 
34
33
  namespace jsi = facebook::jsi;
35
34
 
36
- #if defined(SK_GRAPHITE)
37
35
  /**
38
- * Describes the texture a Graphite recording is replayed onto: the pixel size
39
- * and the format of a window (or offscreen) surface. A deferred canvas is
40
- * recorded against this description, so it can be created before the surface
41
- * itself exists.
36
+ * The native side of a Skia view. Frames come from one of two producers: JS
37
+ * records them itself through the view's target
38
+ * (SkiaViewApi.makeGraphiteContext), or <Canvas> hands over a recorder (or a
39
+ * picture) that the render thread pool records for the view. Either way the
40
+ * recordings are queued on the target; the view presents them onto its canvas
41
+ * provider on the main thread, aligned with the platform's display link.
42
+ *
43
+ * Threading: the registry side (RNSkJsiViewApi) runs on the JS thread, except
44
+ * applyUpdates() which a Reanimated mapper calls on the UI runtime; snapshots
45
+ * replay on the calling thread. Presenting runs on the main thread.
42
46
  */
43
- struct RNSkGraphiteTargetInfo {
44
- int width = 0;
45
- int height = 0;
46
- SkColorType colorType = kUnknown_SkColorType;
47
- skgpu::graphite::TextureInfo textureInfo;
48
- };
49
- #endif
50
-
51
- class RNSkCanvasProvider {
52
- public:
53
- explicit RNSkCanvasProvider(std::function<void()> requestRedraw)
54
- : _requestRedraw(requestRedraw) {}
55
-
56
- virtual ~RNSkCanvasProvider() = default;
57
-
58
- #if defined(SK_GRAPHITE)
59
- /**
60
- Describes the current target texture. Safe to call from any thread;
61
- returns false while there is no surface to describe.
62
- */
63
- virtual bool getGraphiteTargetInfo(RNSkGraphiteTargetInfo *info) {
64
- return false;
65
- }
66
-
67
- /**
68
- Replays the recordings, in order, onto the target texture and presents
69
- it. Called on the thread that owns the surface.
70
- */
71
- virtual bool presentRecordings(
72
- const std::vector<skgpu::graphite::Recording *> &recordings) {
73
- return false;
74
- }
75
- #endif
76
-
77
- /**
78
- Returns the scaled width of the view
79
- */
80
- virtual int getWidth() = 0;
81
-
82
- /**
83
- Returns the scaled height of the view
84
- */
85
- virtual int getHeight() = 0;
86
-
87
- /**
88
- Render to a canvas
89
- */
90
- virtual bool renderToCanvas(const std::function<void(SkCanvas *)> &) = 0;
91
-
92
- protected:
93
- std::function<void()> _requestRedraw;
94
- };
95
-
96
- class RNSkRenderer {
97
- public:
98
- explicit RNSkRenderer(std::function<void()> requestRedraw)
99
- : _requestRedraw(std::move(requestRedraw)), _showDebugOverlays(false) {}
100
-
101
- virtual void
102
- renderImmediate(std::shared_ptr<RNSkCanvasProvider> canvasProvider) = 0;
103
-
104
- void setShowDebugOverlays(bool showDebugOverlays) {
105
- _showDebugOverlays = showDebugOverlays;
106
- }
107
- bool getShowDebugOverlays() const { return _showDebugOverlays; }
108
-
109
- protected:
110
- std::function<void()> _requestRedraw;
111
- bool _showDebugOverlays;
112
- };
113
-
114
- class RNSkOffscreenCanvasProvider : public RNSkCanvasProvider {
47
+ class RNSkView : public std::enable_shared_from_this<RNSkView> {
115
48
  public:
116
- RNSkOffscreenCanvasProvider(
117
- const std::shared_ptr<RNSkPlatformContext> &context,
118
- std::function<void()> requestRedraw, float width, float height)
119
- : RNSkCanvasProvider(std::move(requestRedraw)), _width(width),
120
- _height(height), _context(context) {
121
- _surface = context->makeOffscreenSurface(_width, _height);
122
- _pd = context->getPixelDensity();
49
+ RNSkView(std::shared_ptr<RNSkPlatformContext> context,
50
+ std::shared_ptr<RNSkCanvasProvider> canvasProvider)
51
+ : _platformContext(std::move(context)),
52
+ _canvasProvider(std::move(canvasProvider)),
53
+ _producer(std::make_shared<RNSkGraphiteProducer>()) {
54
+ // A new surface or a new size: present again. The platform view owns
55
+ // the provider together with this view, and the destructor clears the
56
+ // callback, so a raw capture is safe.
57
+ _canvasProvider->setRequestRedraw([this]() { requestRedraw(); });
123
58
  }
124
59
 
125
- virtual ~RNSkOffscreenCanvasProvider() = default;
126
-
127
- /**
128
- Returns a snapshot of the current surface/canvas
129
- */
130
- sk_sp<SkImage> makeSnapshot(SkRect *bounds) {
131
- if (_surface == nullptr) {
132
- return nullptr;
60
+ ~RNSkView() {
61
+ _canvasProvider->setRequestRedraw(nullptr);
62
+ std::shared_ptr<RNSkGraphiteTarget> target;
63
+ {
64
+ std::lock_guard<std::mutex> lock(_mutex);
65
+ target = std::move(_target);
133
66
  }
134
- sk_sp<SkImage> image;
135
- if (bounds != nullptr) {
136
- SkIRect b =
137
- SkIRect::MakeXYWH(bounds->x() * _pd, bounds->y() * _pd,
138
- bounds->width() * _pd, bounds->height() * _pd);
139
- image = _surface->makeImageSnapshot(b);
140
- } else {
141
- image = _surface->makeImageSnapshot();
67
+ if (target) {
68
+ target->detach(_canvasProvider);
142
69
  }
143
- #if defined(SK_GRAPHITE)
144
- // Only Graphite-backed surfaces have a recorder to snap/submit; a raster
145
- // surface's snapshot is already a valid CPU image.
146
- if (auto *recorder = _surface->recorder()) {
147
- DawnContext::getInstance().submitRecording(recorder->snap().get());
148
- }
149
- return DawnContext::getInstance().MakeRasterImage(image);
150
- #else
151
- auto grContext = _context->getDirectContext();
152
- return image->makeRasterImage(grContext);
153
- #endif
154
70
  }
155
71
 
156
- /**
157
- Returns the scaled width of the view
158
- */
159
- int getWidth() override { return _width; };
160
-
161
- /**
162
- Returns the scaled height of the view
163
- */
164
- int getHeight() override { return _height; };
72
+ // Registry side ------------------------------------------------------------
165
73
 
166
74
  /**
167
- Render to a canvas
75
+ Binds the view to its id. The target recording for this id (created by
76
+ whichever side came first, see RNSkGraphiteTargetRegistry) is attached to
77
+ the view's surface, and frames recorded before the view existed are
78
+ presented now.
168
79
  */
169
- bool renderToCanvas(const std::function<void(SkCanvas *)> &cb) override {
170
- if (_surface == nullptr) {
171
- return false;
80
+ void setNativeId(size_t nativeId) {
81
+ _nativeId = nativeId;
82
+ std::shared_ptr<RNSkGraphiteTarget> previous;
83
+ {
84
+ std::lock_guard<std::mutex> lock(_mutex);
85
+ if (_target && _targetId == nativeId) {
86
+ return;
87
+ }
88
+ previous = std::move(_target);
89
+ _targetId = nativeId;
90
+ _target = RNSkGraphiteTargetRegistry::getInstance().getOrCreate(
91
+ nativeId, _platformContext);
172
92
  }
173
- cb(_surface->getCanvas());
174
- return true;
175
- };
176
-
177
- #if defined(SK_GRAPHITE)
178
- bool getGraphiteTargetInfo(RNSkGraphiteTargetInfo *info) override {
179
- if (_surface == nullptr || _surface->recorder() == nullptr) {
180
- return false;
93
+ if (previous) {
94
+ previous->detach(_canvasProvider);
181
95
  }
182
- // Graphite gives its render targets the sampled+renderable usage, a
183
- // superset of what a deferred canvas asks for.
184
- auto colorType = _surface->imageInfo().colorType();
185
- info->width = _width;
186
- info->height = _height;
187
- info->colorType = colorType;
188
- info->textureInfo = skgpu::graphite::TextureInfos::MakeDawn(
189
- skgpu::graphite::DawnTextureInfo(
190
- skgpu::graphite::SampleCount::k1, skgpu::Mipmapped::kNo,
191
- DawnUtils::textureFormatForColorType(colorType),
192
- DawnUtils::DefaultTargetUsage, wgpu::TextureAspect::All));
193
- return true;
194
- }
195
-
196
- bool presentRecordings(
197
- const std::vector<skgpu::graphite::Recording *> &recordings) override {
198
- if (_surface == nullptr || _surface->recorder() == nullptr) {
199
- return false;
96
+ std::weak_ptr<RNSkView> weakThis = weak_from_this();
97
+ auto context = _platformContext;
98
+ auto scheduleOnMainThread = [weakThis, context]() {
99
+ context->runOnMainThread([weakThis]() {
100
+ if (auto view = weakThis.lock()) {
101
+ view->scheduleFrame();
102
+ }
103
+ });
104
+ };
105
+ auto target = getTarget();
106
+ target->attach(_canvasProvider, scheduleOnMainThread);
107
+ _producer->setTarget(target);
108
+ if (target->hasQueued()) {
109
+ scheduleOnMainThread();
200
110
  }
201
- return DawnContext::getInstance().insertRecordings(recordings,
202
- _surface.get());
203
111
  }
204
- #endif
205
112
 
206
- private:
207
- int _width;
208
- int _height;
209
- float _pd = 1.0f;
210
- sk_sp<SkSurface> _surface;
211
- std::shared_ptr<RNSkPlatformContext> _context;
212
- };
213
-
214
- class RNSkView : public std::enable_shared_from_this<RNSkView> {
215
- public:
216
- /**
217
- * Constructor
218
- */
219
- RNSkView(std::shared_ptr<RNSkPlatformContext> context,
220
- std::shared_ptr<RNSkCanvasProvider> canvasProvider,
221
- std::shared_ptr<RNSkRenderer> renderer)
222
- : _platformContext(context), _canvasProvider(canvasProvider),
223
- _renderer(renderer) {}
224
-
225
- /**
226
- Destructor
227
- */
228
- virtual ~RNSkView() {}
113
+ size_t getNativeId() { return _nativeId; }
229
114
 
230
- virtual void setJsiProperties(
231
- std::unordered_map<std::string, RNJsi::ViewProperty> &props) = 0;
115
+ /** Declarative content: the recorder of <Canvas>, or a picture. */
116
+ void setJsiProperties(
117
+ std::unordered_map<std::string, RNJsi::ViewProperty> &props) {
118
+ for (auto &prop : props) {
119
+ if (prop.first == "recorder") {
120
+ _producer->setRecorder(
121
+ prop.second.isRecorder() ? prop.second.getRecorder() : nullptr);
122
+ } else if (prop.first == "picture") {
123
+ _producer->setPicture(prop.second.isPicture() ? prop.second.getPicture()
124
+ : nullptr);
125
+ }
126
+ }
127
+ }
232
128
 
233
129
  /**
234
130
  Reads the shared values on the calling runtime into the recording the
235
131
  view owns and schedules a frame. Returns false when there is nothing to
236
132
  update: no recording, or one other than recorderId (a stale mapper).
237
133
  */
238
- virtual bool applyUpdates(jsi::Runtime &runtime, double recorderId,
239
- const jsi::Array &values) {
240
- return false;
134
+ bool applyUpdates(jsi::Runtime &runtime, double recorderId,
135
+ const jsi::Array &values) {
136
+ return _producer->applyUpdates(runtime, recorderId, values);
241
137
  }
242
138
 
243
139
  /**
@@ -246,91 +142,311 @@ public:
246
142
  until it is finalized, so the resources go away here rather than with the
247
143
  garbage collector.
248
144
  */
249
- virtual void releaseContent() {}
145
+ void releaseContent() { _producer->clear(); }
250
146
 
147
+ /** Schedules redraw() on the main thread, once. */
251
148
  void requestRedraw() {
252
- if (!_redrawRequested) {
253
- _redrawRequested = true;
254
- // Capture a weak pointer to this
255
- auto weakThis = std::weak_ptr<RNSkView>(shared_from_this());
256
-
257
- _platformContext->runOnMainThread([weakThis]() {
258
- // Try to lock the weak pointer
259
- if (auto strongThis = weakThis.lock()) {
260
- // Only proceed if the object still exists
261
- if (strongThis->_renderer && strongThis->_redrawRequested) {
262
- strongThis->_renderer->renderImmediate(strongThis->_canvasProvider);
263
- strongThis->_redrawRequested = false;
264
- }
265
- }
266
- });
149
+ if (_redrawRequested.exchange(true)) {
150
+ return;
267
151
  }
152
+ std::weak_ptr<RNSkView> weakThis = weak_from_this();
153
+ _platformContext->runOnMainThread([weakThis]() {
154
+ if (auto view = weakThis.lock()) {
155
+ if (view->_redrawRequested) {
156
+ view->redraw();
157
+ }
158
+ }
159
+ });
268
160
  }
269
161
 
162
+ /**
163
+ Main thread. Presents everything submitted since the last frame; with
164
+ nothing queued, presents the last frame again (a redraw after a resize or
165
+ on a new surface). Without a surface the queue is left alone: the surface
166
+ presents it when it appears.
167
+ */
270
168
  void redraw() {
271
- _renderer->renderImmediate(_canvasProvider);
272
169
  _redrawRequested = false;
170
+ RNSkGraphiteTargetInfo targetInfo;
171
+ if (!_canvasProvider->getTargetInfo(&targetInfo)) {
172
+ return;
173
+ }
174
+ // Declarative content is recorded again for the surface as it is now.
175
+ const bool frameComing = _producer->requestFrame();
176
+ auto target = getTarget();
177
+ std::shared_ptr<RNSkGraphiteRecording> lastPresented;
178
+ {
179
+ std::lock_guard<std::mutex> lock(_mutex);
180
+ lastPresented = _lastPresented;
181
+ }
182
+ std::vector<std::shared_ptr<RNSkGraphiteRecording>> recordings;
183
+ if (target) {
184
+ recordings = target->takeQueued();
185
+ }
186
+ if (recordings.empty()) {
187
+ // With a frame on its way, the layer keeps showing the last one until
188
+ // it lands: presenting it again would only cost a second present.
189
+ // Otherwise the last frame is presented again, also onto a surface of
190
+ // another size (the view was resized and nothing records for it): the
191
+ // frame then shows at its own size rather than nothing at all.
192
+ if (frameComing || lastPresented == nullptr) {
193
+ return;
194
+ }
195
+ if (present(_canvasProvider, targetInfo, {lastPresented},
196
+ /* remember= */ true)) {
197
+ _producer->onFramePresented();
198
+ }
199
+ return;
200
+ }
201
+ if (present(_canvasProvider, targetInfo, recordings,
202
+ /* remember= */ true)) {
203
+ _producer->onFramePresented();
204
+ } else if (target) {
205
+ target->requeue(recordings);
206
+ }
273
207
  }
274
208
 
275
209
  /**
276
- Sets the native id of the view
210
+ Renders the view into an offscreen surface: declarative content is
211
+ replayed on the calling thread with the latest values, so the snapshot
212
+ does not wait for a frame; otherwise the current frame is replayed. A
213
+ snapshot is in sRGB whichever color space the view renders in: a frame
214
+ recorded in Display P3 is replayed into a surface in that color space and
215
+ the image is converted.
277
216
  */
278
- virtual void setNativeId(size_t nativeId) { _nativeId = nativeId; }
217
+ sk_sp<SkImage> makeImageSnapshot(SkRect *bounds) {
218
+ if (_producer->hasContent()) {
219
+ auto provider = std::make_shared<RNSkOffscreenCanvasProvider>(
220
+ _platformContext, getScaledWidth(), getScaledHeight());
221
+ if (auto *canvas = provider->getCanvas()) {
222
+ _producer->renderInto(canvas, _platformContext->getPixelDensity());
223
+ }
224
+ return provider->makeSnapshot(bounds);
225
+ }
226
+ auto frame = getLastFrame();
227
+ const bool useP3ColorSpace =
228
+ frame != nullptr && frame->getTarget().useP3ColorSpace;
229
+ auto provider = std::make_shared<RNSkOffscreenCanvasProvider>(
230
+ _platformContext, getScaledWidth(), getScaledHeight(), useP3ColorSpace);
231
+ if (frame != nullptr) {
232
+ renderFrame(provider, frame);
233
+ }
234
+ auto image = provider->makeSnapshot(bounds);
235
+ if (image != nullptr && useP3ColorSpace) {
236
+ // A raster image: converted on the CPU, no recorder involved.
237
+ image = image->makeColorSpace(nullptr, SkColorSpace::MakeSRGB(), {});
238
+ }
239
+ return image;
240
+ }
279
241
 
280
- /**
281
- Returns the native id
282
- */
283
- size_t getNativeId() { return _nativeId; }
242
+ /** Width of the surface, in pixels. */
243
+ int getScaledWidth() { return _canvasProvider->getWidth(); }
244
+
245
+ /** Height of the surface, in pixels. */
246
+ int getScaledHeight() { return _canvasProvider->getHeight(); }
247
+
248
+ // Platform view side -------------------------------------------------------
284
249
 
285
250
  /**
286
- * Set to true to show the debug overlays on render
251
+ Installed by the platform view: arms its display link. Main thread. Without
252
+ one, frames are presented as soon as the main thread gets to them.
287
253
  */
288
- void setShowDebugOverlays(bool show) {
289
- _renderer->setShowDebugOverlays(show);
290
- requestRedraw();
254
+ void setFrameScheduler(std::function<void()> scheduler) {
255
+ _frameScheduler = std::move(scheduler);
256
+ }
257
+
258
+ /** Main thread: a recording is waiting. */
259
+ void scheduleFrame() {
260
+ if (_frameScheduler) {
261
+ _frameScheduler();
262
+ } else {
263
+ redraw();
264
+ }
291
265
  }
292
266
 
293
267
  /**
294
- Renders the view into an SkImage instead of the screen.
268
+ Display link tick: presents the queued recordings. Returns whether more
269
+ are waiting, so that the caller keeps its display link armed: also when the
270
+ present failed (the app is in the background), so that the recordings are
271
+ tried again on the next frame rather than left waiting for a redraw.
272
+ Without a surface the queue is left alone: the surface presents it when
273
+ it appears.
295
274
  */
296
- virtual sk_sp<SkImage> makeImageSnapshot(SkRect *bounds) {
275
+ bool presentFrame() {
276
+ auto target = getTarget();
277
+ if (target == nullptr) {
278
+ return false;
279
+ }
280
+ RNSkGraphiteTargetInfo targetInfo;
281
+ if (!_canvasProvider->getTargetInfo(&targetInfo)) {
282
+ return false;
283
+ }
284
+ auto recordings = target->takeQueued();
285
+ if (recordings.empty()) {
286
+ return false;
287
+ }
288
+ if (!present(_canvasProvider, targetInfo, recordings,
289
+ /* remember= */ true)) {
290
+ target->requeue(recordings);
291
+ return true;
292
+ }
293
+ _producer->onFramePresented();
294
+ return target->hasQueued();
295
+ }
297
296
 
298
- auto provider = std::make_shared<RNSkOffscreenCanvasProvider>(
299
- getPlatformContext(), std::bind(&RNSkView::requestRedraw, this),
300
- _canvasProvider->getWidth(), _canvasProvider->getHeight());
297
+ bool hasQueuedRecordings() {
298
+ auto target = getTarget();
299
+ return target && target->hasQueued();
300
+ }
301
301
 
302
- _renderer->renderImmediate(provider);
303
- return provider->makeSnapshot(bounds);
302
+ std::shared_ptr<RNSkCanvasProvider> getCanvasProvider() {
303
+ return _canvasProvider;
304
304
  }
305
305
 
306
- std::shared_ptr<RNSkRenderer> getRenderer() { return _renderer; }
306
+ std::shared_ptr<RNSkPlatformContext> getPlatformContext() {
307
+ return _platformContext;
308
+ }
309
+
310
+ private:
311
+ std::shared_ptr<RNSkGraphiteTarget> getTarget() {
312
+ std::lock_guard<std::mutex> lock(_mutex);
313
+ return _target;
314
+ }
315
+
316
+ /** The frame on screen, or the one about to be, if any. Any thread. */
317
+ std::shared_ptr<RNSkGraphiteRecording> getLastFrame() {
318
+ std::shared_ptr<RNSkGraphiteTarget> target;
319
+ std::shared_ptr<RNSkGraphiteRecording> recording;
320
+ {
321
+ std::lock_guard<std::mutex> lock(_mutex);
322
+ target = _target;
323
+ recording = _lastPresented;
324
+ }
325
+ if (target) {
326
+ if (auto latest = target->peekLatest()) {
327
+ recording = latest;
328
+ }
329
+ }
330
+ return recording;
331
+ }
332
+
333
+ /** Replays a frame onto another provider (a snapshot surface). Any thread. */
334
+ bool renderFrame(const std::shared_ptr<RNSkCanvasProvider> &provider,
335
+ const std::shared_ptr<RNSkGraphiteRecording> &recording) {
336
+ RNSkGraphiteTargetInfo targetInfo;
337
+ if (!provider->getTargetInfo(&targetInfo)) {
338
+ return false;
339
+ }
340
+ return present(provider, targetInfo, {recording}, /* remember= */ false);
341
+ }
307
342
 
308
343
  /**
309
- Returns the scaled width of the view
344
+ Replays the recordings onto the provider's target, in order, and remembers
345
+ the last one for the next redraw when asked to (not for a snapshot).
346
+ Returns false when the provider could not present (no surface, app in the
347
+ background), in which case the caller keeps the recordings.
310
348
  */
311
- int getScaledWidth() { return _canvasProvider->getWidth(); }
349
+ bool
350
+ present(const std::shared_ptr<RNSkCanvasProvider> &provider,
351
+ const RNSkGraphiteTargetInfo &targetInfo,
352
+ const std::vector<std::shared_ptr<RNSkGraphiteRecording>> &recordings,
353
+ bool remember) {
354
+ // Recordings of the target's size and color space are replayed straight
355
+ // onto it, as one batch; any other goes through a texture of its own.
356
+ std::vector<skgpu::graphite::Recording *> batch;
357
+ std::shared_ptr<RNSkGraphiteRecording> last;
358
+ bool success = true;
359
+ auto flush = [&]() {
360
+ if (!batch.empty()) {
361
+ success = provider->presentRecordings(batch) && success;
362
+ batch.clear();
363
+ }
364
+ };
365
+ for (const auto &recording : recordings) {
366
+ // A recording made for another format (recorded before the surface
367
+ // existed, with a bit depth the surface did not get) cannot be
368
+ // replayed onto this one.
369
+ if (!recording->hasFormatOf(targetInfo)) {
370
+ RNSkLogger::logToConsole("SkiaView: skipping a recording made for a "
371
+ "different surface format");
372
+ continue;
373
+ }
374
+ if (recording->hasSizeOf(targetInfo) &&
375
+ recording->hasColorSpaceOf(targetInfo)) {
376
+ batch.push_back(recording->get());
377
+ last = recording;
378
+ continue;
379
+ }
380
+ flush();
381
+ if (presentThroughTexture(provider, recording)) {
382
+ last = recording;
383
+ } else {
384
+ success = false;
385
+ }
386
+ }
387
+ flush();
388
+ if (last == nullptr) {
389
+ // Nothing presentable: the recordings are consumed, not kept.
390
+ return true;
391
+ }
392
+ if (success && remember) {
393
+ std::lock_guard<std::mutex> lock(_mutex);
394
+ _lastPresented = last;
395
+ }
396
+ return success;
397
+ }
312
398
 
313
399
  /**
314
- Returns the scaled height of the view
400
+ Presents a recording made for another size than the target's: the size
401
+ JS measured before the surface existed can be a pixel off (the platform
402
+ rounds the layout to pixels on its own terms), and the view may have been
403
+ resized since. The recording is replayed into a texture of its own size
404
+ and that texture is drawn onto the target, so the frame shows rather than
405
+ being dropped; the copy only happens while the sizes differ. The same goes
406
+ for a recording made in another color space than the target's: the
407
+ texture is in the color space of the recording, and drawing it converts
408
+ the colors.
315
409
  */
316
- int getScaledHeight() { return _canvasProvider->getHeight(); }
317
-
318
- protected:
319
- std::shared_ptr<RNSkPlatformContext> getPlatformContext() {
320
- return _platformContext;
321
- }
322
- std::shared_ptr<RNSkCanvasProvider> getCanvasProvider() {
323
- return _canvasProvider;
410
+ bool presentThroughTexture(
411
+ const std::shared_ptr<RNSkCanvasProvider> &provider,
412
+ const std::shared_ptr<RNSkGraphiteRecording> &recording) {
413
+ const auto &size = recording->getTarget();
414
+ auto intermediate = std::make_shared<RNSkOffscreenCanvasProvider>(
415
+ _platformContext, size.width, size.height, size.useP3ColorSpace);
416
+ RNSkGraphiteTargetInfo info;
417
+ if (!intermediate->getTargetInfo(&info) ||
418
+ !recording->isCompatibleWith(info)) {
419
+ // No texture of that size and format: the frame is consumed.
420
+ RNSkLogger::logToConsole("SkiaView: skipping a %dx%d recording, the "
421
+ "surface is %dx%d",
422
+ size.width, size.height, provider->getWidth(),
423
+ provider->getHeight());
424
+ return true;
425
+ }
426
+ if (!intermediate->presentRecordings({recording->get()})) {
427
+ return false;
428
+ }
429
+ auto image = intermediate->makeImage();
430
+ if (image == nullptr) {
431
+ return false;
432
+ }
433
+ return provider->presentImage(image);
324
434
  }
325
435
 
326
- private:
327
436
  std::shared_ptr<RNSkPlatformContext> _platformContext;
328
437
  std::shared_ptr<RNSkCanvasProvider> _canvasProvider;
329
- std::shared_ptr<RNSkRenderer> _renderer;
330
-
331
- size_t _nativeId;
332
-
438
+ std::shared_ptr<RNSkGraphiteProducer> _producer;
439
+ size_t _nativeId = 0;
440
+ std::function<void()> _frameScheduler;
333
441
  std::atomic<bool> _redrawRequested = {false};
442
+
443
+ // The target is bound on the JS thread and read on the main thread and by
444
+ // snapshots; the last presented frame is written by the main thread and
445
+ // read by snapshots.
446
+ std::mutex _mutex;
447
+ std::shared_ptr<RNSkGraphiteTarget> _target;
448
+ size_t _targetId = 0;
449
+ std::shared_ptr<RNSkGraphiteRecording> _lastPresented;
334
450
  };
335
451
 
336
452
  } // namespace RNSkia