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
@@ -19,8 +19,9 @@ import type { SharedValue } from "react-native-reanimated";
19
19
 
20
20
  import Rea from "../external/reanimated/ReanimatedProxy";
21
21
  import { SkiaViewNativeId } from "../views/SkiaViewNativeId";
22
- import type { AndroidCanvasProps, AndroidSurfaceType } from "../views/types";
23
- import SkiaPictureViewNativeComponent from "../specs/SkiaPictureViewNativeComponent";
22
+ import { androidNativeProps } from "../views/android";
23
+ import type { AndroidCanvasProps } from "../views/types";
24
+ import SkiaViewNativeComponent from "../specs/SkiaViewNativeComponent";
24
25
  import type { SkImage, SkRect, SkSize } from "../skia/types";
25
26
  import { SkiaSGRoot } from "../sksg/Reconciler";
26
27
  import { Skia } from "../skia";
@@ -61,7 +62,6 @@ export const useCanvasSize = (userRef?: RefObject<CanvasRef | null>) => {
61
62
  };
62
63
 
63
64
  export interface CanvasProps extends Omit<ViewProps, "onLayout"> {
64
- debug?: boolean;
65
65
  /** @deprecated Not supported on native. Use `onSize` or `useCanvasSize()` instead. */
66
66
  onLayout?: ViewProps["onLayout"];
67
67
  /**
@@ -72,7 +72,6 @@ export interface CanvasProps extends Omit<ViewProps, "onLayout"> {
72
72
  */
73
73
  opaque?: boolean;
74
74
  onSize?: SharedValue<SkSize>;
75
- colorSpace?: "p3" | "srgb";
76
75
  /**
77
76
  * Renders into a surface with more than 8 bits per channel (16-bit float on
78
77
  * iOS, 10-bit on Android) to avoid banding in subtle gradients. Colors are
@@ -85,25 +84,14 @@ export interface CanvasProps extends Omit<ViewProps, "onLayout"> {
85
84
  /** Android-only rendering options. Ignored on iOS and web. */
86
85
  android?: AndroidCanvasProps;
87
86
  ref?: React.Ref<CanvasRef>;
88
- androidWarmup?: boolean;
89
87
  __destroyWebGLContextAfterRender?: boolean;
90
88
  }
91
89
 
92
- // Anything else reaching the native component would hit the generated
93
- // string-enum parser, which aborts on unknown values.
94
- const resolveSurfaceType = (
95
- surfaceType: AndroidSurfaceType | undefined
96
- ): "auto" | AndroidSurfaceType =>
97
- surfaceType === "SurfaceView" || surfaceType === "TextureView"
98
- ? surfaceType
99
- : "auto";
100
-
101
90
  /**
102
- * What every canvas shares, whichever native view it renders into: the native
103
- * id, the scene graph root rendered into it, the `onSize` measurement and the
104
- * imperative handle of the ref.
91
+ * What the canvas owns: the native id, the scene graph root rendered into it,
92
+ * the `onSize` measurement and the imperative handle of the ref.
105
93
  */
106
- export const useCanvasRoot = ({
94
+ const useCanvasRoot = ({
107
95
  children,
108
96
  onSize,
109
97
  ref,
@@ -186,14 +174,26 @@ export const useCanvasRoot = ({
186
174
  return { nativeId, viewRef };
187
175
  };
188
176
 
177
+ /**
178
+ * The declarative canvas. Its children are rendered by Skia's own React
179
+ * renderer; the frames are produced off the JS thread:
180
+ *
181
+ * - the JS thread records the scene graph into a native recorder once per
182
+ * React commit and hands it to the view;
183
+ * - the Reanimated UI runtime only reads the shared values into it (the one
184
+ * step that needs a JS runtime), it never replays anything;
185
+ * - a dedicated native thread pool replays the recorder into a Graphite
186
+ * recording whenever the content changed, at most once per presented frame;
187
+ * - the view presents the recording on the next vsync.
188
+ *
189
+ * On the web the scene is drawn into a picture on the JS thread and painted
190
+ * on a WebGL canvas.
191
+ */
189
192
  export const Canvas = ({
190
- debug,
191
193
  opaque,
192
194
  children,
193
195
  onSize,
194
- colorSpace = "p3",
195
196
  highBitDepth = false,
196
- androidWarmup = false,
197
197
  android,
198
198
  ref,
199
199
  onLayout,
@@ -219,17 +219,13 @@ export const Canvas = ({
219
219
  [onLayout, onSize]
220
220
  );
221
221
  return (
222
- <SkiaPictureViewNativeComponent
222
+ <SkiaViewNativeComponent
223
223
  ref={viewRef}
224
224
  collapsable={false}
225
225
  nativeID={`${nativeId}`}
226
- debug={debug}
227
226
  opaque={opaque}
228
- colorSpace={colorSpace}
229
227
  highBitDepth={highBitDepth}
230
- androidWarmup={androidWarmup}
231
- androidSurfaceType={resolveSurfaceType(android?.surfaceType)}
232
- androidZOrderOnTop={!!android?.zOrderOnTop}
228
+ {...androidNativeProps(android)}
233
229
  onLayout={
234
230
  Platform.OS === "web" && (onSize || onLayout) ? onLayoutWeb : onLayout
235
231
  }
@@ -2,13 +2,13 @@ import type { SkCanvas } from "./Canvas";
2
2
  import type { SkJSIInstance } from "./JsiInstance";
3
3
 
4
4
  /**
5
- * A frame recorded for a SkiaGraphiteView. Immutable once finished: submit it
6
- * to the view as many times as needed, from any runtime.
5
+ * A frame recorded for a view. Immutable once finished: submit it to the view
6
+ * as many times as needed, from any runtime.
7
7
  */
8
8
  export type SkGraphiteRecording = SkJSIInstance<"GraphiteRecording">;
9
9
 
10
10
  /**
11
- * The recording side of a SkiaGraphiteView, obtained from the view's ref.
11
+ * The recording side of a view, obtained from the ref of a SkiaGraphiteView.
12
12
  *
13
13
  * Frames are recorded on the calling thread and presented by the view on its
14
14
  * display link, so the context can be captured into a worklet and used from
@@ -106,7 +106,7 @@ export interface ImageFactory {
106
106
  * while the image is in use: destroy() releases the underlying GPU
107
107
  * resource regardless of reference counts.
108
108
  *
109
- * Note: This method is only available when the Graphite backend is enabled.
109
+ * Native only.
110
110
  *
111
111
  * @param pointer - The WGPUTexture pointer (texture.nativePointer)
112
112
  * @returns An SkImage wrapping the texture, or throws if the texture is invalid
@@ -119,7 +119,7 @@ export interface ImageFactory {
119
119
  * returned pointer carries one reference and must be adopted exactly once
120
120
  * with react-native-webgpu's adoptTexture(), which owns it from then on.
121
121
  *
122
- * Note: This method is only available when the Graphite backend is enabled.
122
+ * Native only.
123
123
  *
124
124
  * @param image - An SkImage to convert to a texture
125
125
  * @returns A WGPUTexture pointer for adoptTexture(), or throws on failure
@@ -106,8 +106,7 @@ export interface Skia {
106
106
  /**
107
107
  * Raw WGPUDevice pointer of Skia's Graphite device, as a BigInt. Pass it to
108
108
  * react-native-webgpu's importDevice() to get a GPUDevice sharing Skia's
109
- * device (zero-copy interop). Only available on Graphite builds; throws
110
- * otherwise.
109
+ * device (zero-copy interop). Native only.
111
110
  */
112
111
  getNativeDevice(): bigint;
113
112
  }
@@ -43,7 +43,7 @@ export interface SurfaceFactory {
43
43
  * surface exists. Calling destroy() on the GPUTexture still invalidates
44
44
  * the surface.
45
45
  *
46
- * Note: This method is only available when the Graphite backend is enabled.
46
+ * Native only.
47
47
  *
48
48
  * @param pointer - The WGPUTexture pointer (texture.nativePointer)
49
49
  * @returns An SkSurface rendering into the texture, or throws if the texture is invalid
@@ -7,8 +7,12 @@ import type {
7
7
  } from "../skia/types";
8
8
  import type { ISkiaViewApi } from "../views/types";
9
9
 
10
- /** What every web view registers under its native id. */
10
+ /** What the web view registers under its native id. */
11
11
  export interface SkiaWebViewHandle {
12
+ /** Shows a picture: the frame of a <Canvas> or a <SkiaPictureView>. */
13
+ setPicture(picture: SkPicture): void;
14
+ /** The recording side of the view, see SkiaGraphiteView. */
15
+ getContext(): SkGraphiteContext;
12
16
  getSize(): { width: number; height: number };
13
17
  redraw(): void;
14
18
  makeImageSnapshot(rect?: SkRect): SkImage | null;
@@ -27,20 +31,6 @@ export interface SkiaWebViewHandle {
27
31
  ): void;
28
32
  }
29
33
 
30
- export interface SkiaGraphiteViewHandle extends SkiaWebViewHandle {
31
- getContext(): SkGraphiteContext;
32
- }
33
-
34
- interface PictureHandle extends SkiaWebViewHandle {
35
- setPicture(picture: SkPicture): void;
36
- }
37
-
38
- const hasPicture = (view: SkiaWebViewHandle): view is PictureHandle =>
39
- "setPicture" in view;
40
-
41
- const hasContext = (view: SkiaWebViewHandle): view is SkiaGraphiteViewHandle =>
42
- "getContext" in view;
43
-
44
34
  export type ISkiaViewApiWeb = ISkiaViewApi & {
45
35
  views: Record<string, SkiaWebViewHandle>;
46
36
  deferedPictures: Record<string, SkPicture>;
@@ -58,7 +48,7 @@ global.SkiaViewApi = {
58
48
  registerView(nativeId: string, view: SkiaWebViewHandle) {
59
49
  this.unregisteredViews.delete(nativeId);
60
50
  // Maybe a picture for this view was already set
61
- if (this.deferedPictures[nativeId] && hasPicture(view)) {
51
+ if (this.deferedPictures[nativeId]) {
62
52
  view.setPicture(this.deferedPictures[nativeId] as SkPicture);
63
53
  delete this.deferedPictures[nativeId];
64
54
  }
@@ -77,9 +67,7 @@ global.SkiaViewApi = {
77
67
  const id = `${nativeId}`;
78
68
  const view = this.views[id];
79
69
  if (view) {
80
- if (hasPicture(view)) {
81
- view.setPicture(value);
82
- }
70
+ view.setPicture(value);
83
71
  } else if (!this.unregisteredViews.has(id)) {
84
72
  this.deferedPictures[id] = value;
85
73
  }
@@ -114,9 +102,9 @@ global.SkiaViewApi = {
114
102
  },
115
103
  makeGraphiteContext(nativeId: number) {
116
104
  const view = this.views[`${nativeId}`];
117
- if (!view || !hasContext(view)) {
105
+ if (!view) {
118
106
  throw new Error(
119
- `Cannot make a Graphite context: no SkiaGraphiteView with nativeID ${nativeId} is mounted`
107
+ `Cannot make a Graphite context: no view with nativeID ${nativeId} is mounted`
120
108
  );
121
109
  }
122
110
  return view.getContext();
@@ -4,11 +4,8 @@ import type { WithDefault } from "react-native/Libraries/Types/CodegenTypes";
4
4
  // eslint-disable-next-line @typescript-eslint/ban-ts-comment
5
5
  // @ts-ignore - pointerEvents needs to be redeclared for codegen to generate native bindings
6
6
  export interface NativeProps extends ViewProps {
7
- debug?: boolean;
8
7
  opaque?: boolean;
9
- colorSpace?: string;
10
8
  highBitDepth?: boolean;
11
- androidWarmup?: boolean;
12
9
  androidSurfaceType?: WithDefault<
13
10
  "auto" | "SurfaceView" | "TextureView",
14
11
  "auto"
@@ -21,4 +18,4 @@ export interface NativeProps extends ViewProps {
21
18
  }
22
19
 
23
20
  // eslint-disable-next-line import/no-default-export
24
- export default codegenNativeComponent<NativeProps>("SkiaPictureView");
21
+ export default codegenNativeComponent<NativeProps>("SkiaView");
@@ -1,33 +1,31 @@
1
1
  import type { ViewProps } from "react-native";
2
2
  import { createElement } from "react";
3
3
 
4
- import { SkiaPictureView } from "../views/SkiaPictureView.web";
4
+ import { SkiaView } from "../views/SkiaView.web";
5
5
 
6
6
  export interface NativeProps extends ViewProps {
7
- debug?: boolean;
8
7
  opaque?: boolean;
8
+ highBitDepth?: boolean;
9
9
  nativeID: string;
10
10
  androidSurfaceType?: "auto" | "SurfaceView" | "TextureView";
11
11
  androidZOrderOnTop?: boolean;
12
12
  }
13
13
 
14
- const SkiaPictureViewNativeComponent = ({
14
+ const SkiaViewNativeComponent = ({
15
15
  nativeID,
16
- debug,
17
- opaque,
18
16
  onLayout,
19
- // Android-only, never reaches the DOM
17
+ // Surface settings, never reach the DOM
18
+ opaque: _opaque,
19
+ highBitDepth: _highBitDepth,
20
20
  androidSurfaceType: _androidSurfaceType,
21
21
  androidZOrderOnTop: _androidZOrderOnTop,
22
22
  ...viewProps
23
23
  }: NativeProps) => {
24
- return createElement(SkiaPictureView, {
24
+ return createElement(SkiaView, {
25
25
  nativeID,
26
- debug,
27
- opaque,
28
26
  onLayout,
29
27
  ...viewProps,
30
28
  });
31
29
  };
32
30
  // eslint-disable-next-line import/no-default-export
33
- export default SkiaPictureViewNativeComponent;
31
+ export default SkiaViewNativeComponent;
@@ -1,9 +1,11 @@
1
1
  import React, { useImperativeHandle, useMemo, useRef } from "react";
2
2
 
3
3
  import type { SkGraphiteContext } from "../skia/types";
4
- import SkiaGraphiteViewNativeComponent from "../specs/SkiaGraphiteViewNativeComponent";
4
+ import SkiaViewNativeComponent from "../specs/SkiaViewNativeComponent";
5
+ import { Platform } from "../Platform";
5
6
 
6
7
  import { SkiaViewApi } from "./api";
8
+ import { androidNativeProps } from "./android";
7
9
  import type { SkiaGraphiteViewNativeProps } from "./types";
8
10
  import { SkiaViewNativeId } from "./SkiaViewNativeId";
9
11
 
@@ -20,40 +22,49 @@ export interface SkiaGraphiteViewProps extends SkiaGraphiteViewNativeProps {
20
22
  ref?: React.Ref<SkiaGraphiteViewRef>;
21
23
  }
22
24
 
25
+ // The layout is known synchronously on the new architecture;
26
+ // getBoundingClientRect became stable in React Native 0.83. On the web the
27
+ // view measures itself (see SkiaView.web).
28
+ const measureLayout = (view: unknown) => {
29
+ if (Platform.OS === "web") {
30
+ return { width: 0, height: 0 };
31
+ }
32
+ const host = view as {
33
+ getBoundingClientRect?: () => { width: number; height: number };
34
+ unstable_getBoundingClientRect: () => { width: number; height: number };
35
+ };
36
+ return host.getBoundingClientRect
37
+ ? host.getBoundingClientRect()
38
+ : host.unstable_getBoundingClientRect();
39
+ };
40
+
23
41
  /**
24
- * A view presenting frames recorded with Skia Graphite. Requires the Graphite
25
- * backend (install-skia-graphite); with the default backend it renders
26
- * nothing. See {@link SkGraphiteContext}.
42
+ * A view whose frames are recorded from JavaScript, on any runtime, through
43
+ * the context of its ref. See {@link SkGraphiteContext}.
27
44
  */
28
45
  export const SkiaGraphiteView = ({
29
- debug = false,
30
46
  opaque = false,
31
47
  highBitDepth = false,
48
+ android,
32
49
  ref,
33
50
  ...viewProps
34
51
  }: SkiaGraphiteViewProps) => {
35
52
  const nativeId = useMemo(() => SkiaViewNativeId.current++, []);
36
53
  const viewRef =
37
- useRef<React.ComponentRef<typeof SkiaGraphiteViewNativeComponent>>(null);
54
+ useRef<React.ComponentRef<typeof SkiaViewNativeComponent>>(null);
38
55
  useImperativeHandle(
39
56
  ref,
40
57
  () => ({
41
58
  getNativeId: () => nativeId,
42
59
  getContext: () => {
43
60
  assertSkiaViewApi();
44
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
45
- const view = viewRef.current as any;
61
+ const view = viewRef.current;
46
62
  if (!view) {
47
63
  throw new Error(
48
64
  "SkiaGraphiteView: getContext() was called before the view was mounted."
49
65
  );
50
66
  }
51
- // The layout is known synchronously on the new architecture;
52
- // getBoundingClientRect became stable in React Native 0.83.
53
- const size =
54
- "getBoundingClientRect" in view
55
- ? view.getBoundingClientRect()
56
- : view.unstable_getBoundingClientRect();
67
+ const size = measureLayout(view);
57
68
  return SkiaViewApi.makeGraphiteContext(
58
69
  nativeId,
59
70
  size.width,
@@ -66,13 +77,13 @@ export const SkiaGraphiteView = ({
66
77
  [nativeId, opaque, highBitDepth]
67
78
  );
68
79
  return (
69
- <SkiaGraphiteViewNativeComponent
80
+ <SkiaViewNativeComponent
70
81
  ref={viewRef}
71
82
  collapsable={false}
72
83
  nativeID={`${nativeId}`}
73
- debug={debug}
74
84
  opaque={opaque}
75
85
  highBitDepth={highBitDepth}
86
+ {...androidNativeProps(android)}
76
87
  {...viewProps}
77
88
  />
78
89
  );
@@ -1,19 +1,21 @@
1
1
  import React from "react";
2
2
 
3
3
  import type { SkRect } from "../skia/types";
4
- import SkiaPictureViewNativeComponent from "../specs/SkiaPictureViewNativeComponent";
4
+ import SkiaViewNativeComponent from "../specs/SkiaViewNativeComponent";
5
5
 
6
6
  import { SkiaViewApi } from "./api";
7
+ import { androidNativeProps } from "./android";
7
8
  import type { SkiaPictureViewNativeProps } from "./types";
8
9
  import { SkiaViewNativeId } from "./SkiaViewNativeId";
9
10
 
10
- const NativeSkiaPictureView = SkiaPictureViewNativeComponent;
11
-
12
11
  interface SkiaPictureViewProps extends SkiaPictureViewNativeProps {
13
12
  mode?: "default" | "continuous";
14
- androidWarmup?: boolean;
15
13
  }
16
14
 
15
+ /**
16
+ * A view showing a picture. The picture is handed to the native view, which
17
+ * records it once (and again on every redraw) for its surface.
18
+ */
17
19
  export class SkiaPictureView extends React.Component<SkiaPictureViewProps> {
18
20
  private requestId = 0;
19
21
 
@@ -76,21 +78,20 @@ export class SkiaPictureView extends React.Component<SkiaPictureViewProps> {
76
78
 
77
79
  render() {
78
80
  const {
79
- mode,
80
- debug = false,
81
+ mode: _mode,
82
+ picture: _picture,
81
83
  opaque = false,
82
84
  highBitDepth = false,
83
- androidWarmup = false,
85
+ android,
84
86
  ...viewProps
85
87
  } = this.props;
86
88
  return (
87
- <NativeSkiaPictureView
89
+ <SkiaViewNativeComponent
88
90
  collapsable={false}
89
91
  nativeID={`${this._nativeId}`}
90
- debug={debug}
91
92
  opaque={opaque}
92
93
  highBitDepth={highBitDepth}
93
- androidWarmup={androidWarmup}
94
+ {...androidNativeProps(android)}
94
95
  {...viewProps}
95
96
  />
96
97
  );