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
package/Package.swift CHANGED
@@ -1,6 +1,6 @@
1
1
  // swift-tools-version: 6.0
2
2
  //
3
- // SwiftPM manifest for @shopify/react-native-skia. iOS, Ganesh.
3
+ // SwiftPM manifest for react-native-skia. iOS, Graphite.
4
4
  // Additive: the CocoaPods podspec remains the supported default.
5
5
  //
6
6
  // React Native 0.87+ references a library that ships its own Package.swift
@@ -12,15 +12,17 @@ import Foundation
12
12
  import PackageDescription
13
13
 
14
14
  // Skia's xcframeworks are ~200MB and are not carried in this package. They come
15
- // from the react-native-skia-apple-ios npm package, which @shopify/react-native-skia
16
- // depends on, so a checkout that has installed its dependencies builds offline.
15
+ // from the react-native-skia-graphite-apple-ios npm package, which
16
+ // react-native-skia depends on, so a checkout that has installed its
17
+ // dependencies builds offline. The package also ships the shared Dawn
18
+ // (libwebgpu_dawn.xcframework) Graphite runs on.
17
19
  // Xcode passes the symlink as the package directory, hence resolvingSymlinks.
18
20
  let packageRoot = URL(fileURLWithPath: Context.packageDirectory)
19
21
  .resolvingSymlinksInPath().path
20
22
 
21
23
  let binariesPath = [
22
- "../../react-native-skia-apple-ios", // consumer: sibling in node_modules
23
- "../../node_modules/react-native-skia-apple-ios", // this monorepo
24
+ "../../react-native-skia-graphite-apple-ios", // consumer: sibling in node_modules
25
+ "../../node_modules/react-native-skia-graphite-apple-ios", // this monorepo
24
26
  ]
25
27
  .map { "\(packageRoot)/\($0)" }
26
28
  .first { FileManager.default.fileExists(atPath: "\($0)/Package.swift") }
@@ -31,7 +33,7 @@ guard let binariesPath else {
31
33
  // unresolvable dependency path.
32
34
  fatalError(
33
35
  """
34
- react-native-skia-apple-ios was not found next to @shopify/react-native-skia. \
36
+ react-native-skia-graphite-apple-ios was not found next to react-native-skia. \
35
37
  It ships the prebuilt Skia binaries this package links against. Reinstall \
36
38
  dependencies without --omit=optional, on macOS.
37
39
  """)
@@ -57,15 +59,13 @@ let package = Package(
57
59
  .product(name: "ReactNativeHeaders", package: "ReactNative"),
58
60
  .product(name: "ReactNativeDependenciesHeaders", package: "ReactNative"),
59
61
  .product(name: "ReactAppHeaders", package: "React-GeneratedCode"),
60
- .product(name: "react-native-skia-apple-ios", package: "react-native-skia-apple-ios"),
62
+ .product(
63
+ name: "react-native-skia-graphite-apple-ios",
64
+ package: "react-native-skia-graphite-apple-ios"),
61
65
  ],
62
66
  // apple/ and cpp/ have no common ancestor below the package root, and
63
67
  // .headerSearchPath cannot escape the target path.
64
68
  path: ".",
65
- exclude: [
66
- "cpp/rnskia/RNDawnWindowContext.cpp", // Graphite only
67
- "cpp/rnskia/RNDawnInterop.cpp", // Graphite only
68
- ],
69
69
  // Explicit, so SwiftPM never walks node_modules, lib, android, or the
70
70
  // headers-only cpp/skia — which carries x86 AVX skcms sources that
71
71
  // cannot build for arm64.
@@ -83,6 +83,7 @@ let package = Package(
83
83
  // Replaces the podspec's recursive cpp/** glob, which expands to 90.
84
84
  .headerSearchPath("cpp"), // "api/…", "jsi/…", "utils/…"
85
85
  .headerSearchPath("cpp/skia"), // "include/core/…", "modules/…", "src/…"
86
+ .headerSearchPath("cpp/dawn/include"), // "webgpu/…", "dawn/…"
86
87
  .headerSearchPath("cpp/rnskia"), // apple/ uses bare "RNSkView.h"
87
88
  .headerSearchPath("cpp/utils"), // apple/ uses bare "RNSkLog.h"
88
89
 
@@ -93,8 +94,8 @@ let package = Package(
93
94
  .define("RCT_NEW_ARCH_ENABLED", to: "1"),
94
95
  .define("RCT_REMOVE_LEGACY_ARCH", to: "1"),
95
96
 
96
- .define("SK_METAL", to: "1"),
97
- .define("SK_GANESH", to: "1"),
97
+ // Skia's public headers only declare the Graphite API with SK_GRAPHITE.
98
+ .define("SK_GRAPHITE", to: "1"),
98
99
  .define("SK_IMAGE_READ_PIXELS_DISABLE_LEGACY_API", to: "1"),
99
100
  .define("SK_DISABLE_LEGACY_SHAPER_FACTORY", to: "1"),
100
101
 
@@ -4,7 +4,7 @@ cmake_minimum_required(VERSION 3.4.1)
4
4
  set (CMAKE_CXX_STANDARD 20)
5
5
 
6
6
  # SKIA_LIBS_PATH is passed from Gradle (pointing at the prebuilt Skia binaries,
7
- # read straight from the react-native-skia-android npm package, or libs/android for Graphite)
7
+ # read straight from the react-native-skia-graphite-android npm package, or libs/android for local builds)
8
8
  # Append the ABI to get the full path
9
9
  set (SKIA_LIBS_PATH "${SKIA_LIBS_PATH}/${ANDROID_ABI}")
10
10
 
@@ -29,9 +29,10 @@ endif()
29
29
  add_library(skia STATIC IMPORTED)
30
30
  set_property(TARGET skia PROPERTY IMPORTED_LOCATION "${SKIA_LIBS_PATH}/libskia.a")
31
31
 
32
- # SK_GRAPHITE is passed from Gradle
33
32
  message("-- SKIA_LIBS_PATH: ${SKIA_LIBS_PATH}")
34
- message("-- SK_GRAPHITE: ${SK_GRAPHITE}")
33
+
34
+ # Skia's public headers only declare the Graphite API with SK_GRAPHITE set.
35
+ add_definitions(-DSK_GRAPHITE)
35
36
 
36
37
  string(APPEND CMAKE_CXX_FLAGS " -DSK_BUILD_FOR_ANDROID -DSK_DISABLE_LEGACY_SHAPER_FACTORY -DSK_IMAGE_READ_PIXELS_DISABLE_LEGACY_API -DFOLLY_NO_CONFIG=1 -DFOLLY_HAVE_CLOCK_GETTIME=1 -DFOLLY_HAVE_MEMRCHR=1 -DFOLLY_USE_LIBCPP=1 -DFOLLY_MOBILE=1 -DON_ANDROID -DONANDROID")
37
38
 
@@ -51,21 +52,6 @@ message("-- ABI : " ${ANDROID_ABI})
51
52
 
52
53
  link_directories(${SKIA_LIBS_PATH}/)
53
54
 
54
- if(SK_GRAPHITE)
55
- add_definitions(-DSK_GRAPHITE)
56
- set(BACKEND_SOURCES
57
- #TODO: is this source needed to be added?
58
- "${PROJECT_SOURCE_DIR}/../cpp/rnskia/RNDawnWindowContext.cpp"
59
- "${PROJECT_SOURCE_DIR}/../cpp/rnskia/RNDawnInterop.cpp"
60
- )
61
- else()
62
- add_definitions(-DSK_GL -DSK_GANESH)
63
- set(BACKEND_SOURCES
64
- "${PROJECT_SOURCE_DIR}/cpp/rnskia-android/OpenGLWindowContext.cpp"
65
- "${PROJECT_SOURCE_DIR}/cpp/rnskia-android/GrAHardwareBufferUtils.cpp"
66
- )
67
- endif()
68
-
69
55
  add_library(
70
56
  ${PACKAGE_NAME}
71
57
  SHARED
@@ -73,8 +59,7 @@ add_library(
73
59
  "${PROJECT_SOURCE_DIR}/cpp/jni/JniSkiaManager.cpp"
74
60
 
75
61
  "${PROJECT_SOURCE_DIR}/cpp/jni/JniPlatformContext.cpp"
76
- "${PROJECT_SOURCE_DIR}/cpp/rnskia-android/gl/Error.cpp"
77
- "${PROJECT_SOURCE_DIR}/cpp/rnskia-android/RNSkOpenGLCanvasProvider.cpp"
62
+ "${PROJECT_SOURCE_DIR}/cpp/rnskia-android/RNSkAndroidCanvasProvider.cpp"
78
63
  "${PROJECT_SOURCE_DIR}/cpp/rnskia-android/AHardwareBufferUtils.cpp"
79
64
  "${PROJECT_SOURCE_DIR}/cpp/rnskia-android/RNSkAndroidVideo.cpp"
80
65
 
@@ -84,15 +69,15 @@ add_library(
84
69
  "${PROJECT_SOURCE_DIR}/../cpp/jsi/ViewProperty.cpp"
85
70
 
86
71
  "${PROJECT_SOURCE_DIR}/../cpp/rnskia/RNSkManager.cpp"
87
- "${PROJECT_SOURCE_DIR}/../cpp/rnskia/RNSkPictureView.cpp"
88
72
  "${PROJECT_SOURCE_DIR}/../cpp/rnskia/RNSkGraphiteProducer.cpp"
73
+ "${PROJECT_SOURCE_DIR}/../cpp/rnskia/RNDawnWindowContext.cpp"
74
+ "${PROJECT_SOURCE_DIR}/../cpp/rnskia/RNDawnInterop.cpp"
89
75
 
90
76
  "${PROJECT_SOURCE_DIR}/../cpp/api/third_party/CSSColorParser.cpp"
91
77
  "${PROJECT_SOURCE_DIR}/../cpp/api/third_party/base64.cpp"
92
78
  "${PROJECT_SOURCE_DIR}/../cpp/api/third_party/SkottieUtils.cpp"
93
79
 
94
80
  "${PROJECT_SOURCE_DIR}/../cpp/api/JsiSkDispatcher.cpp"
95
- ${BACKEND_SOURCES}
96
81
  )
97
82
 
98
83
 
@@ -155,12 +140,10 @@ set_property(TARGET pathops PROPERTY IMPORTED_LOCATION "${SKIA_LIBS_PATH}/libpat
155
140
  add_library(jsonreader STATIC IMPORTED)
156
141
  set_property(TARGET jsonreader PROPERTY IMPORTED_LOCATION "${SKIA_LIBS_PATH}/libjsonreader.a")
157
142
 
158
- if(SK_GRAPHITE)
159
- # Dawn is a shared library, the same artifact react-native-webgpu links, so
160
- # an app that installs both packages loads exactly one Dawn copy.
161
- add_library(webgpu_dawn SHARED IMPORTED)
162
- set_property(TARGET webgpu_dawn PROPERTY IMPORTED_LOCATION "${SKIA_LIBS_PATH}/libwebgpu_dawn.so")
163
- endif()
143
+ # Dawn is a shared library, the same artifact react-native-webgpu links, so
144
+ # an app that installs both packages loads exactly one Dawn copy.
145
+ add_library(webgpu_dawn SHARED IMPORTED)
146
+ set_property(TARGET webgpu_dawn PROPERTY IMPORTED_LOCATION "${SKIA_LIBS_PATH}/libwebgpu_dawn.so")
164
147
 
165
148
  find_library(
166
149
  LOG_LIB
@@ -182,7 +165,7 @@ else()
182
165
  endif()
183
166
 
184
167
  # Link
185
- set(COMMON_LIBS
168
+ target_link_libraries(${PACKAGE_NAME}
186
169
  ${LOG_LIB}
187
170
  ReactAndroid::reactnative
188
171
  fbjni::fbjni
@@ -196,23 +179,11 @@ set(COMMON_LIBS
196
179
  ${SKIA_SKSG_LIB}
197
180
  ${SKIA_JSONREADER_LIB}
198
181
  ${SKIA_LIB}
182
+ webgpu_dawn
199
183
  -ljnigraphics
200
- -lGLESv2
201
- -lEGL
202
184
  -landroid
203
185
  )
204
186
 
205
- if(SK_GRAPHITE)
206
- target_link_libraries(${PACKAGE_NAME}
207
- ${COMMON_LIBS}
208
- webgpu_dawn
209
- )
210
- else()
211
- target_link_libraries(${PACKAGE_NAME}
212
- ${COMMON_LIBS}
213
- )
214
- endif()
215
-
216
187
  # Enable Android 16kb native library alignment
217
188
  if(CMAKE_ANDROID_NDK_VERSION VERSION_LESS "27")
218
189
  target_link_options(${PACKAGE_NAME} PRIVATE "-Wl,-z,max-page-size=16384")
@@ -6,10 +6,12 @@ import java.nio.file.Paths
6
6
  // https://github.com/facebookincubator/fbjni/blob/main/docs/android_setup.md
7
7
 
8
8
  // These defaults should reflect the SDK versions used by
9
- // the minimum React Native version supported (0.78).
9
+ // the minimum React Native version supported (0.78), except minSdk:
10
+ // the Graphite binaries are built for API level 26 (ndk_api in
11
+ // scripts/skia-configuration.ts).
10
12
  def DEFAULT_COMPILE_SDK_VERSION = 35
11
13
  def DEFAULT_BUILD_TOOLS_VERSION = '35.0.0'
12
- def DEFAULT_MIN_SDK_VERSION = 24
14
+ def DEFAULT_MIN_SDK_VERSION = 26
13
15
  def DEFAULT_TARGET_SDK_VERSION = 34
14
16
 
15
17
  def safeExtGet(prop, fallback) {
@@ -58,54 +60,61 @@ static def resolveNodePackage(packageName, baseDir) {
58
60
  return proc.text.trim()
59
61
  }
60
62
 
61
- // Graphite is detected via a marker file (created by install-skia-graphite for
62
- // in-repo development, or shipped in the npm tarball for next-channel releases).
63
- // The prebuilt binaries live in the react-native-skia-android npm package for the
64
- // default (Ganesh) build and in react-native-skia-graphite-android for Graphite.
65
- // In-repo Graphite development downloads them directly into libs/android instead,
66
- // which takes precedence over the npm package when present.
67
- def useGraphite = file("${projectDir}/../libs/.graphite").exists()
68
- def localGraphiteLibs = file("${projectDir}/../libs/android")
69
- def skiaLibsPath = useGraphite
70
- ? (localGraphiteLibs.exists()
71
- ? "${projectDir}/../libs/android"
72
- : "${resolveNodePackage('react-native-skia-graphite-android', projectDir)}/libs")
73
- : "${resolveNodePackage('react-native-skia-android', projectDir)}/libs"
74
-
75
- // Both packages must link the exact same Dawn artifact: compare this
76
- // Graphite build's Dawn release tag (libs/.dawn-version) with the tag
77
- // react-native-webgpu declares in its package.json `dawn` field.
78
- if (useGraphite) {
79
- def dawnMarker = file("${projectDir}/../libs/.dawn-version")
80
- def webgpuDir = null
81
- try {
82
- webgpuDir = resolveNodePackage('react-native-webgpu', projectDir)
83
- } catch (Exception ignored) {
84
- // react-native-webgpu not installed: nothing to check
63
+ // The Graphite binaries, including the shared Dawn (libwebgpu_dawn.so), live in
64
+ // the react-native-skia-graphite-android npm package. Binaries built locally
65
+ // with `yarn build-skia` land in libs/android and take precedence when present.
66
+ def localSkiaLibs = file("${projectDir}/../libs/android")
67
+ def skiaLibsPath = localSkiaLibs.exists()
68
+ ? "${projectDir}/../libs/android"
69
+ : "${resolveNodePackage('react-native-skia-graphite-android', projectDir)}/libs"
70
+
71
+ // Fail early rather than with a ninja "missing and no known rule" error.
72
+ def missingDawn = ["armeabi-v7a", "arm64-v8a", "x86", "x86_64"].findAll {
73
+ !file("${skiaLibsPath}/${it}/libwebgpu_dawn.so").exists()
74
+ }
75
+ if (!missingDawn.isEmpty()) {
76
+ throw new GradleException(
77
+ "react-native-skia: libwebgpu_dawn.so not found in ${skiaLibsPath} " +
78
+ "for ${missingDawn.join(', ')}. The installed react-native-skia-graphite-android " +
79
+ "package does not ship the shared Dawn library this Graphite build links against. " +
80
+ "Upgrade it and rebuild.")
81
+ }
82
+
83
+ // Both packages must link the exact same Dawn artifact: compare the Dawn
84
+ // release tag the Skia binaries were packaged with (libs/.dawn-version in the
85
+ // react-native-skia-graphite-android package, or next to a local build) with
86
+ // the tag react-native-webgpu declares in its package.json `dawn` field.
87
+ def dawnMarker = file("${skiaLibsPath}/.dawn-version")
88
+ if (!dawnMarker.exists()) {
89
+ dawnMarker = file("${projectDir}/../libs/.dawn-version")
90
+ }
91
+ def webgpuDir = null
92
+ try {
93
+ webgpuDir = resolveNodePackage('react-native-webgpu', projectDir)
94
+ } catch (Exception ignored) {
95
+ // react-native-webgpu not installed: nothing to check
96
+ }
97
+ if (dawnMarker.exists() && webgpuDir != null) {
98
+ def skiaDawn = dawnMarker.text.trim()
99
+ def webgpuJson = new groovy.json.JsonSlurper().parse(file("${webgpuDir}/package.json"))
100
+ if (webgpuJson.dawn == null) {
101
+ throw new GradleException(
102
+ "react-native-skia: the installed react-native-webgpu " +
103
+ "(${webgpuJson.version}) does not declare a `dawn` field in its " +
104
+ "package.json, so it predates shared-Dawn support and cannot be " +
105
+ "paired with this Graphite build (which links ${skiaDawn}). " +
106
+ "Upgrade react-native-webgpu.")
85
107
  }
86
- if (dawnMarker.exists() && webgpuDir != null) {
87
- def skiaDawn = dawnMarker.text.trim()
88
- def webgpuJson = new groovy.json.JsonSlurper().parse(file("${webgpuDir}/package.json"))
89
- if (webgpuJson.dawn == null) {
90
- throw new GradleException(
91
- "react-native-skia: the installed react-native-webgpu " +
92
- "(${webgpuJson.version}) does not declare a `dawn` field in its " +
93
- "package.json, so it predates shared-Dawn support and cannot be " +
94
- "paired with this Graphite build (which links ${skiaDawn}). " +
95
- "Upgrade react-native-webgpu.")
96
- }
97
- def webgpuDawn = "dawn-" + webgpuJson.dawn.toString().replace('/', '-')
98
- if (skiaDawn != webgpuDawn) {
99
- throw new GradleException(
100
- "react-native-skia: Dawn version mismatch. This Graphite build links " +
101
- "${skiaDawn} but react-native-webgpu links ${webgpuDawn}. " +
102
- "Align the two packages so the app contains exactly one Dawn.")
103
- }
104
- logger.warn("react-native-skia: Dawn versions match (${skiaDawn})")
108
+ def webgpuDawn = "dawn-" + webgpuJson.dawn.toString().replace('/', '-')
109
+ if (skiaDawn != webgpuDawn) {
110
+ throw new GradleException(
111
+ "react-native-skia: Dawn version mismatch. This Graphite build links " +
112
+ "${skiaDawn} but react-native-webgpu links ${webgpuDawn}. " +
113
+ "Align the two packages so the app contains exactly one Dawn.")
105
114
  }
115
+ logger.warn("react-native-skia: Dawn versions match (${skiaDawn})")
106
116
  }
107
117
 
108
- logger.warn("react-native-skia: SK_GRAPHITE: ${useGraphite}")
109
118
  logger.warn("react-native-skia: Skia libs: ${skiaLibsPath}")
110
119
  logger.warn("react-native-skia: node_modules/ found at: ${nodeModules}")
111
120
 
@@ -167,7 +176,6 @@ android {
167
176
  "-DREACT_NATIVE_DIR=${defaultDir}",
168
177
  "-DNODE_MODULES_DIR=${nodeModules}",
169
178
  "-DSKIA_LIBS_PATH=${skiaLibsPath}",
170
- "-DSK_GRAPHITE=${useGraphite ? 'ON' : 'OFF'}",
171
179
  "-DANDROID_SUPPORT_FLEXIBLE_PAGE_SIZES=ON"
172
180
 
173
181
  }
@@ -1,15 +1,13 @@
1
1
  #include "JniPlatformContext.h"
2
2
  #include "JniSkiaManager.h"
3
- #include "JniSkiaGraphiteView.h"
4
- #include "JniSkiaPictureView.h"
3
+ #include "JniSkiaView.h"
5
4
  #include <fbjni/fbjni.h>
6
5
  #include <jni.h>
7
6
 
8
7
  JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM *vm, void *) {
9
8
  return facebook::jni::initialize(vm, [] {
10
9
  RNSkia::JniSkiaManager::registerNatives();
11
- RNSkia::JniSkiaPictureView::registerNatives();
12
- RNSkia::JniSkiaGraphiteView::registerNatives();
10
+ RNSkia::JniSkiaView::registerNatives();
13
11
  RNSkia::JniPlatformContext::registerNatives();
14
12
  });
15
13
  }
@@ -0,0 +1,123 @@
1
+ #pragma once
2
+
3
+ #include <memory>
4
+
5
+ #include <fbjni/fbjni.h>
6
+ #include <jni.h>
7
+
8
+ #include "JniSkiaManager.h"
9
+ #include "RNSkAndroidCanvasProvider.h"
10
+ #include "RNSkView.h"
11
+
12
+ namespace RNSkia {
13
+ namespace jni = facebook::jni;
14
+
15
+ /**
16
+ * The JNI side of SkiaView: owns the native view and the ANativeWindow
17
+ * provider it presents into, and relays the surface callbacks of the backing
18
+ * SurfaceView or TextureView.
19
+ */
20
+ class JniSkiaView : public jni::HybridClass<JniSkiaView> {
21
+ public:
22
+ static auto constexpr kJavaDescriptor = "Lcom/reactnative/skia/SkiaView;";
23
+
24
+ static jni::local_ref<jhybriddata>
25
+ initHybrid(jni::alias_ref<jhybridobject> jThis,
26
+ jni::alias_ref<JniSkiaManager::javaobject> skiaManager) {
27
+ return makeCxxInstance(jThis, skiaManager);
28
+ }
29
+
30
+ static void registerNatives() {
31
+ registerHybrid(
32
+ {makeNativeMethod("initHybrid", JniSkiaView::initHybrid),
33
+ makeNativeMethod("surfaceAvailable", JniSkiaView::surfaceAvailable),
34
+ makeNativeMethod("surfaceDestroyed", JniSkiaView::surfaceDestroyed),
35
+ makeNativeMethod("surfaceSizeChanged",
36
+ JniSkiaView::surfaceSizeChanged),
37
+ makeNativeMethod("setLayoutSize", JniSkiaView::setLayoutSize),
38
+ makeNativeMethod("registerView", JniSkiaView::registerView),
39
+ makeNativeMethod("unregisterView", JniSkiaView::unregisterView),
40
+ makeNativeMethod("presentFrame", JniSkiaView::presentFrame)});
41
+ }
42
+
43
+ // The manager is owned by the RNSkiaModule and is destroyed when the module
44
+ // is invalidated (reload). Fabric drops views on the UI thread while the
45
+ // module is invalidated on a background thread, so a view can outlive its
46
+ // manager: holding a weak reference makes a late unregister a no-op and a
47
+ // concurrent one keep the manager alive for the duration of the call.
48
+ std::shared_ptr<RNSkManager> getSkiaManager() { return _manager.lock(); }
49
+
50
+ protected:
51
+ void surfaceAvailable(jobject surface, int width, int height, bool isSurface,
52
+ bool highBitDepth) {
53
+ _provider->surfaceAvailable(surface, width, height, isSurface,
54
+ highBitDepth);
55
+ _view->redraw();
56
+ }
57
+
58
+ void surfaceSizeChanged(jobject surface, int width, int height,
59
+ bool isSurface, bool highBitDepth) {
60
+ _provider->surfaceSizeChanged(surface, width, height, isSurface,
61
+ highBitDepth);
62
+ // Paint the new size right away rather than on the next scheduled redraw.
63
+ _view->redraw();
64
+ }
65
+
66
+ void surfaceDestroyed() { _provider->surfaceDestroyed(); }
67
+
68
+ void setLayoutSize(int width, int height) {
69
+ _provider->setLayoutSize(width, height);
70
+ }
71
+
72
+ void registerView(int nativeId) {
73
+ auto manager = getSkiaManager();
74
+ if (manager == nullptr) {
75
+ return;
76
+ }
77
+ manager->registerSkiaView(nativeId, _view);
78
+ }
79
+
80
+ void unregisterView() {
81
+ if (auto manager = getSkiaManager()) {
82
+ manager->setSkiaView(_view->getNativeId(), nullptr);
83
+ manager->unregisterSkiaView(_view->getNativeId());
84
+ }
85
+ // React drops the Java view here, but the native view behind it (and the
86
+ // content it owns) is only destroyed when the Java object is finalized.
87
+ // Release the content now so it does not wait for the garbage collector.
88
+ _view->releaseContent();
89
+ }
90
+
91
+ // Choreographer tick: presents the queued recordings, returns whether more
92
+ // are already waiting.
93
+ bool presentFrame() { return _view->presentFrame(); }
94
+
95
+ private:
96
+ friend HybridBase;
97
+
98
+ explicit JniSkiaView(jni::alias_ref<jhybridobject> jThis,
99
+ jni::alias_ref<JniSkiaManager::javaobject> skiaManager)
100
+ : _manager(skiaManager->cthis()->getSkiaManager()) {
101
+ auto context = skiaManager->cthis()->getPlatformContext();
102
+ _provider = std::make_shared<RNSkAndroidCanvasProvider>(context);
103
+ _view = std::make_shared<RNSkView>(context, _provider);
104
+ // A submitted recording arms the Java view's frame callback. Weak: the
105
+ // Java view owns this object through its hybrid data.
106
+ jni::weak_ref<jhybridobject> weakJava = jni::make_weak(jThis);
107
+ _view->setFrameScheduler([weakJava]() {
108
+ auto javaPart = weakJava.lockLocal();
109
+ if (!javaPart) {
110
+ return;
111
+ }
112
+ static const auto method =
113
+ javaPart->getClass()->getMethod<void()>("scheduleFrame");
114
+ method(javaPart);
115
+ });
116
+ }
117
+
118
+ std::weak_ptr<RNSkManager> _manager;
119
+ std::shared_ptr<RNSkAndroidCanvasProvider> _provider;
120
+ std::shared_ptr<RNSkView> _view;
121
+ };
122
+
123
+ } // namespace RNSkia