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
@@ -3,10 +3,14 @@ function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object
3
3
  function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
4
4
  function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
5
5
  import React from "react";
6
- import SkiaPictureViewNativeComponent from "../specs/SkiaPictureViewNativeComponent";
6
+ import SkiaViewNativeComponent from "../specs/SkiaViewNativeComponent";
7
7
  import { SkiaViewApi } from "./api";
8
+ import { androidNativeProps } from "./android";
8
9
  import { SkiaViewNativeId } from "./SkiaViewNativeId";
9
- const NativeSkiaPictureView = SkiaPictureViewNativeComponent;
10
+ /**
11
+ * A view showing a picture. The picture is handed to the native view, which
12
+ * records it once (and again on every redraw) for its surface.
13
+ */
10
14
  export class SkiaPictureView extends React.Component {
11
15
  constructor(props) {
12
16
  super(props);
@@ -66,21 +70,19 @@ export class SkiaPictureView extends React.Component {
66
70
  }
67
71
  render() {
68
72
  const {
69
- mode,
70
- debug = false,
73
+ mode: _mode,
74
+ picture: _picture,
71
75
  opaque = false,
72
76
  highBitDepth = false,
73
- androidWarmup = false,
77
+ android,
74
78
  ...viewProps
75
79
  } = this.props;
76
- return /*#__PURE__*/React.createElement(NativeSkiaPictureView, _extends({
80
+ return /*#__PURE__*/React.createElement(SkiaViewNativeComponent, _extends({
77
81
  collapsable: false,
78
82
  nativeID: `${this._nativeId}`,
79
- debug: debug,
80
83
  opaque: opaque,
81
- highBitDepth: highBitDepth,
82
- androidWarmup: androidWarmup
83
- }, viewProps));
84
+ highBitDepth: highBitDepth
85
+ }, androidNativeProps(android), viewProps));
84
86
  }
85
87
  }
86
88
  const assertSkiaViewApi = () => {
@@ -1 +1 @@
1
- {"version":3,"names":["React","SkiaPictureViewNativeComponent","SkiaViewApi","SkiaViewNativeId","NativeSkiaPictureView","SkiaPictureView","Component","constructor","props","_defineProperty","_nativeId","current","picture","assertSkiaViewApi","setJsiProperty","tick","nativeId","componentDidUpdate","prevProps","componentWillUnmount","requestId","cancelAnimationFrame","redraw","mode","requestAnimationFrame","bind","makeImageSnapshot","rect","requestRedraw","render","debug","opaque","highBitDepth","androidWarmup","viewProps","createElement","_extends","collapsable","nativeID","Error"],"sources":["SkiaPictureView.tsx"],"sourcesContent":["import React from \"react\";\n\nimport type { SkRect } from \"../skia/types\";\nimport SkiaPictureViewNativeComponent from \"../specs/SkiaPictureViewNativeComponent\";\n\nimport { SkiaViewApi } from \"./api\";\nimport type { SkiaPictureViewNativeProps } from \"./types\";\nimport { SkiaViewNativeId } from \"./SkiaViewNativeId\";\n\nconst NativeSkiaPictureView = SkiaPictureViewNativeComponent;\n\ninterface SkiaPictureViewProps extends SkiaPictureViewNativeProps {\n mode?: \"default\" | \"continuous\";\n androidWarmup?: boolean;\n}\n\nexport class SkiaPictureView extends React.Component<SkiaPictureViewProps> {\n private requestId = 0;\n\n constructor(props: SkiaPictureViewProps) {\n super(props);\n this._nativeId = SkiaViewNativeId.current++;\n const { picture } = props;\n if (picture) {\n assertSkiaViewApi();\n SkiaViewApi.setJsiProperty(this._nativeId, \"picture\", picture);\n }\n this.tick();\n }\n\n private _nativeId: number;\n\n public get nativeId() {\n return this._nativeId;\n }\n\n componentDidUpdate(prevProps: SkiaPictureViewProps) {\n const { picture } = this.props;\n if (picture !== prevProps.picture) {\n assertSkiaViewApi();\n SkiaViewApi.setJsiProperty(this._nativeId, \"picture\", picture);\n }\n this.tick();\n }\n\n componentWillUnmount() {\n if (this.requestId) {\n cancelAnimationFrame(this.requestId);\n }\n }\n\n private tick() {\n this.redraw();\n if (this.props.mode === \"continuous\") {\n this.requestId = requestAnimationFrame(this.tick.bind(this));\n }\n }\n\n /**\n * Creates a snapshot from the canvas in the surface\n * @param rect Rect to use as bounds. Optional.\n * @returns An Image object.\n */\n public makeImageSnapshot(rect?: SkRect) {\n assertSkiaViewApi();\n return SkiaViewApi.makeImageSnapshot(this._nativeId, rect);\n }\n\n /**\n * Sends a redraw request to the native SkiaView.\n */\n public redraw() {\n assertSkiaViewApi();\n SkiaViewApi.requestRedraw(this._nativeId);\n }\n\n render() {\n const {\n mode,\n debug = false,\n opaque = false,\n highBitDepth = false,\n androidWarmup = false,\n ...viewProps\n } = this.props;\n return (\n <NativeSkiaPictureView\n collapsable={false}\n nativeID={`${this._nativeId}`}\n debug={debug}\n opaque={opaque}\n highBitDepth={highBitDepth}\n androidWarmup={androidWarmup}\n {...viewProps}\n />\n );\n }\n}\n\nconst assertSkiaViewApi = () => {\n if (\n SkiaViewApi === null ||\n SkiaViewApi.setJsiProperty === null ||\n SkiaViewApi.requestRedraw === null ||\n SkiaViewApi.makeImageSnapshot === null\n ) {\n throw Error(\"Skia View Api was not found.\");\n }\n};\n"],"mappings":";;;;AAAA,OAAOA,KAAK,MAAM,OAAO;AAGzB,OAAOC,8BAA8B,MAAM,yCAAyC;AAEpF,SAASC,WAAW,QAAQ,OAAO;AAEnC,SAASC,gBAAgB,QAAQ,oBAAoB;AAErD,MAAMC,qBAAqB,GAAGH,8BAA8B;AAO5D,OAAO,MAAMI,eAAe,SAASL,KAAK,CAACM,SAAS,CAAuB;EAGzEC,WAAWA,CAACC,KAA2B,EAAE;IACvC,KAAK,CAACA,KAAK,CAAC;IAACC,eAAA,oBAHK,CAAC;IAAAA,eAAA;IAInB,IAAI,CAACC,SAAS,GAAGP,gBAAgB,CAACQ,OAAO,EAAE;IAC3C,MAAM;MAAEC;IAAQ,CAAC,GAAGJ,KAAK;IACzB,IAAII,OAAO,EAAE;MACXC,iBAAiB,CAAC,CAAC;MACnBX,WAAW,CAACY,cAAc,CAAC,IAAI,CAACJ,SAAS,EAAE,SAAS,EAAEE,OAAO,CAAC;IAChE;IACA,IAAI,CAACG,IAAI,CAAC,CAAC;EACb;EAIA,IAAWC,QAAQA,CAAA,EAAG;IACpB,OAAO,IAAI,CAACN,SAAS;EACvB;EAEAO,kBAAkBA,CAACC,SAA+B,EAAE;IAClD,MAAM;MAAEN;IAAQ,CAAC,GAAG,IAAI,CAACJ,KAAK;IAC9B,IAAII,OAAO,KAAKM,SAAS,CAACN,OAAO,EAAE;MACjCC,iBAAiB,CAAC,CAAC;MACnBX,WAAW,CAACY,cAAc,CAAC,IAAI,CAACJ,SAAS,EAAE,SAAS,EAAEE,OAAO,CAAC;IAChE;IACA,IAAI,CAACG,IAAI,CAAC,CAAC;EACb;EAEAI,oBAAoBA,CAAA,EAAG;IACrB,IAAI,IAAI,CAACC,SAAS,EAAE;MAClBC,oBAAoB,CAAC,IAAI,CAACD,SAAS,CAAC;IAC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IACA,MAAMa,KAAK,CAAC,8BAA8B,CAAC;EAC7C;AACF,CAAC","ignoreList":[]}
1
+ {"version":3,"names":["React","SkiaViewNativeComponent","SkiaViewApi","androidNativeProps","SkiaViewNativeId","SkiaPictureView","Component","constructor","props","_defineProperty","_nativeId","current","picture","assertSkiaViewApi","setJsiProperty","tick","nativeId","componentDidUpdate","prevProps","componentWillUnmount","requestId","cancelAnimationFrame","redraw","mode","requestAnimationFrame","bind","makeImageSnapshot","rect","requestRedraw","render","_mode","_picture","opaque","highBitDepth","android","viewProps","createElement","_extends","collapsable","nativeID","Error"],"sources":["SkiaPictureView.tsx"],"sourcesContent":["import React from \"react\";\n\nimport type { SkRect } from \"../skia/types\";\nimport SkiaViewNativeComponent from \"../specs/SkiaViewNativeComponent\";\n\nimport { SkiaViewApi } from \"./api\";\nimport { androidNativeProps } from \"./android\";\nimport type { SkiaPictureViewNativeProps } from \"./types\";\nimport { SkiaViewNativeId } from \"./SkiaViewNativeId\";\n\ninterface SkiaPictureViewProps extends SkiaPictureViewNativeProps {\n mode?: \"default\" | \"continuous\";\n}\n\n/**\n * A view showing a picture. The picture is handed to the native view, which\n * records it once (and again on every redraw) for its surface.\n */\nexport class SkiaPictureView extends React.Component<SkiaPictureViewProps> {\n private requestId = 0;\n\n constructor(props: SkiaPictureViewProps) {\n super(props);\n this._nativeId = SkiaViewNativeId.current++;\n const { picture } = props;\n if (picture) {\n assertSkiaViewApi();\n SkiaViewApi.setJsiProperty(this._nativeId, \"picture\", picture);\n }\n this.tick();\n }\n\n private _nativeId: number;\n\n public get nativeId() {\n return this._nativeId;\n }\n\n componentDidUpdate(prevProps: SkiaPictureViewProps) {\n const { picture } = this.props;\n if (picture !== prevProps.picture) {\n assertSkiaViewApi();\n SkiaViewApi.setJsiProperty(this._nativeId, \"picture\", picture);\n }\n this.tick();\n }\n\n componentWillUnmount() {\n if (this.requestId) {\n cancelAnimationFrame(this.requestId);\n }\n }\n\n private tick() {\n this.redraw();\n if (this.props.mode === \"continuous\") {\n this.requestId = requestAnimationFrame(this.tick.bind(this));\n }\n }\n\n /**\n * Creates a snapshot from the canvas in the surface\n * @param rect Rect to use as bounds. Optional.\n * @returns An Image object.\n */\n public makeImageSnapshot(rect?: SkRect) {\n assertSkiaViewApi();\n return SkiaViewApi.makeImageSnapshot(this._nativeId, rect);\n }\n\n /**\n * Sends a redraw request to the native SkiaView.\n */\n public redraw() {\n assertSkiaViewApi();\n SkiaViewApi.requestRedraw(this._nativeId);\n }\n\n render() {\n const {\n mode: _mode,\n picture: _picture,\n opaque = false,\n highBitDepth = false,\n android,\n ...viewProps\n } = this.props;\n return (\n <SkiaViewNativeComponent\n collapsable={false}\n nativeID={`${this._nativeId}`}\n opaque={opaque}\n highBitDepth={highBitDepth}\n {...androidNativeProps(android)}\n {...viewProps}\n />\n );\n }\n}\n\nconst assertSkiaViewApi = () => {\n if (\n SkiaViewApi === null ||\n SkiaViewApi.setJsiProperty === null ||\n SkiaViewApi.requestRedraw === null ||\n SkiaViewApi.makeImageSnapshot === null\n ) {\n throw Error(\"Skia View Api was not found.\");\n }\n};\n"],"mappings":";;;;AAAA,OAAOA,KAAK,MAAM,OAAO;AAGzB,OAAOC,uBAAuB,MAAM,kCAAkC;AAEtE,SAASC,WAAW,QAAQ,OAAO;AACnC,SAASC,kBAAkB,QAAQ,WAAW;AAE9C,SAASC,gBAAgB,QAAQ,oBAAoB;AAMrD;AACA;AACA;AACA;AACA,OAAO,MAAMC,eAAe,SAASL,KAAK,CAACM,SAAS,CAAuB;EAGzEC,WAAWA,CAACC,KAA2B,EAAE;IACvC,KAAK,CAACA,KAAK,CAAC;IAACC,eAAA,oBAHK,CAAC;IAAAA,eAAA;IAInB,IAAI,CAACC,SAAS,GAAGN,gBAAgB,CAACO,OAAO,EAAE;IAC3C,MAAM;MAAEC;IAAQ,CAAC,GAAGJ,KAAK;IACzB,IAAII,OAAO,EAAE;MACXC,iBAAiB,CAAC,CAAC;MACnBX,WAAW,CAACY,cAAc,CAAC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AM,GAAG,KAAK;MACdC,YAAY,GAAG,KAAK;MACpBC,OAAO;MACP,GAAGC;IACL,CAAC,GAAG,IAAI,CAAC3B,KAAK;IACd,oBACER,KAAA,CAAAoC,aAAA,CAACnC,uBAAuB,EAAAoC,QAAA;MACtBC,WAAW,EAAE,KAAM;MACnBC,QAAQ,EAAE,GAAG,IAAI,CAAC7B,SAAS,EAAG;MAC9BsB,MAAM,EAAEA,MAAO;MACfC,YAAY,EAAEA;IAAa,GACvB9B,kBAAkB,CAAC+B,OAAO,CAAC,EAC3BC,SAAS,CACd,CAAC;EAEN;AACF;AAEA,MAAMtB,iBAAiB,GAAGA,CAAA,KAAM;EAC9B,IACEX,WAAW,KAAK,IAAI,IACpBA,WAAW,CAACY,cAAc,KAAK,IAAI,IACnCZ,WAAW,CAAC0B,aAAa,KAAK,IAAI,IAClC1B,WAAW,CAACwB,iBAAiB,KAAK,IAAI,EACtC;IACA,MAAMc,KAAK,CAAC,8BAA8B,CAAC;EAC7C;AACF,CAAC","ignoreList":[]}
@@ -0,0 +1,12 @@
1
+ import React from "react";
2
+ import type { ViewProps } from "react-native";
3
+ import type { SkiaWebViewHandle } from "../specs/NativeSkiaModule.web";
4
+ export interface SkiaViewHandle extends SkiaWebViewHandle {
5
+ /** The canvas element, for Reanimated's measure(). */
6
+ readonly canvasRef: () => HTMLCanvasElement | null;
7
+ }
8
+ export interface SkiaViewProps extends ViewProps {
9
+ ref?: React.Ref<SkiaViewHandle>;
10
+ __destroyWebGLContextAfterRender?: boolean;
11
+ }
12
+ export declare const SkiaView: (props: SkiaViewProps) => React.JSX.Element;
@@ -9,12 +9,14 @@ import { Platform } from "../Platform";
9
9
  import { SkiaViewNativeId } from "./SkiaViewNativeId";
10
10
  import { useSkiaWebRenderer } from "./SkiaWebRenderer";
11
11
 
12
- // The web has no Graphite: a recording is an SkPicture, replayed onto the
13
- // view's WebGL surface by the same renderer as SkiaPictureView (with its
14
- // context-loss handling and the destroy-context-after-render mode). Frames
15
- // keep their native semantics, presented in submission order and never
16
- // dropped, with one difference: the surface starts cleared on every frame,
17
- // so a recording draws the whole frame rather than a delta.
12
+ // The web has no Graphite: the view paints pictures on a WebGL canvas (with
13
+ // context-loss recovery and the destroy-context-after-render mode). It shows
14
+ // one of two kinds of content. The picture of a <Canvas> or a
15
+ // <SkiaPictureView> is a whole frame: the latest one wins. The recordings
16
+ // submitted through the view's context (SkiaGraphiteView) keep their native
17
+ // semantics, presented in submission order and never dropped, with one
18
+ // difference: the surface starts cleared on every frame, so a recording draws
19
+ // the whole frame rather than a delta.
18
20
 
19
21
  /**
20
22
  * A frame recorded on the web. The view holds it while it is queued or on
@@ -99,12 +101,14 @@ class WebGraphiteContext {
99
101
  dispose() {}
100
102
  [Symbol.dispose]() {}
101
103
  }
102
- export const SkiaGraphiteView = props => {
104
+ export const SkiaView = props => {
103
105
  const {
104
106
  ref,
105
107
  onLayout
106
108
  } = props;
107
109
  const canvasRef = useRef(null);
110
+ // The picture of a <Canvas> or a <SkiaPictureView>: a whole frame.
111
+ const pictureRef = useRef(null);
108
112
  // Recordings submitted since the last frame, in order, and the frame on
109
113
  // screen, replayed when the surface is recreated.
110
114
  const queueRef = useRef([]);
@@ -113,9 +117,9 @@ export const SkiaGraphiteView = props => {
113
117
  const nativeId = useMemo(() => props.nativeID !== undefined ? Number(props.nativeID) : SkiaViewNativeId.current++, [props.nativeID]);
114
118
  const isStatic = props.__destroyWebGLContextAfterRender === true;
115
119
 
116
- // Presents what was submitted since the last frame. A frame that cannot be
117
- // painted yet (unmeasured canvas, lost context) stays queued for the next
118
- // opportunity.
120
+ // Presents the recordings submitted since the last frame. A frame that
121
+ // cannot be painted yet (unmeasured canvas, lost context) stays queued for
122
+ // the next opportunity.
119
123
  const present = useCallback(renderer => {
120
124
  const frame = queueRef.current;
121
125
  if (frame.length === 0) {
@@ -130,9 +134,14 @@ export const SkiaGraphiteView = props => {
130
134
  shownRef.current = frame;
131
135
  previous.forEach(recording => recording.release());
132
136
  }, []);
137
+
138
+ // Paints what the view holds: pending recordings first, else the picture,
139
+ // else the frame on screen again (the surface was recreated).
133
140
  const paint = useCallback(renderer => {
134
141
  if (queueRef.current.length > 0) {
135
142
  present(renderer);
143
+ } else if (pictureRef.current) {
144
+ renderer.draw([pictureRef.current]);
136
145
  } else if (shownRef.current.length > 0) {
137
146
  renderer.draw(shownRef.current.map(recording => recording.picture));
138
147
  }
@@ -141,25 +150,37 @@ export const SkiaGraphiteView = props => {
141
150
  paint,
142
151
  onLayout
143
152
  });
153
+
154
+ // Draws are flushed from a microtask rather than an animation frame: the
155
+ // browser composites once per frame either way, and painting right away
156
+ // keeps a frame produced inside an animation callback (the Reanimated
157
+ // mapper, a frame loop) from slipping to the next one. Deferring to the
158
+ // next animation frame would alternate between "flush pending in this
159
+ // frame" and "flush scheduled for the next frame", halving the effective
160
+ // frame rate. Without a renderer yet (an unmeasured canvas), the content
161
+ // stays held and is painted by the renderer once it exists, so it is
162
+ // never lost.
144
163
  const flush = useCallback(() => {
145
164
  flushScheduledRef.current = false;
146
165
  if (rendererRef.current) {
147
- present(rendererRef.current);
166
+ paint(rendererRef.current);
148
167
  }
149
- }, [present, rendererRef]);
150
-
151
- // Frames are presented from a microtask rather than an animation frame:
152
- // the browser composites once per frame either way, and painting right
153
- // away keeps a frame recorded inside an animation callback from slipping
154
- // to the next one (see SkiaPictureView.web).
155
- const submit = useCallback(recording => {
156
- recording.retain();
157
- queueRef.current.push(recording);
168
+ }, [paint, rendererRef]);
169
+ const redraw = useCallback(() => {
158
170
  if (!flushScheduledRef.current) {
159
171
  flushScheduledRef.current = true;
160
172
  queueMicrotask(flush);
161
173
  }
162
174
  }, [flush]);
175
+ const setPicture = useCallback(picture => {
176
+ pictureRef.current = picture;
177
+ redraw();
178
+ }, [redraw]);
179
+ const submit = useCallback(recording => {
180
+ recording.retain();
181
+ queueRef.current.push(recording);
182
+ redraw();
183
+ }, [redraw]);
163
184
  const getSize = useCallback(() => {
164
185
  var _canvasRef$current, _canvasRef$current2;
165
186
  return {
@@ -171,17 +192,23 @@ export const SkiaGraphiteView = props => {
171
192
  getSize,
172
193
  submit
173
194
  }), [getSize, submit]);
174
- const redraw = useCallback(() => {
175
- if (rendererRef.current) {
176
- paint(rendererRef.current);
177
- }
178
- }, [paint, rendererRef]);
179
195
  const makeImageSnapshot = useCallback(rect => {
180
- const frame = queueRef.current.length > 0 ? queueRef.current : shownRef.current;
181
- if (!rendererRef.current || frame.length === 0) {
196
+ const renderer = rendererRef.current;
197
+ if (!renderer) {
182
198
  return null;
183
199
  }
184
- return rendererRef.current.makeImageSnapshot(frame.map(recording => recording.picture), rect);
200
+ let frame;
201
+ if (queueRef.current.length > 0) {
202
+ frame = queueRef.current.map(recording => recording.picture);
203
+ } else if (pictureRef.current) {
204
+ frame = [pictureRef.current];
205
+ } else {
206
+ frame = shownRef.current.map(recording => recording.picture);
207
+ }
208
+ if (frame.length === 0) {
209
+ return null;
210
+ }
211
+ return renderer.makeImageSnapshot(frame, rect);
185
212
  }, [rendererRef]);
186
213
  const measure = useCallback(callback => {
187
214
  if (canvasRef.current) {
@@ -191,7 +218,11 @@ export const SkiaGraphiteView = props => {
191
218
  left: 0,
192
219
  top: 0
193
220
  };
194
- callback(rect.left - parentRect.left, rect.top - parentRect.top, rect.width, rect.height, rect.left + window.scrollX, rect.top + window.scrollY);
221
+ callback(
222
+ // x, y are relative to the parent
223
+ rect.left - parentRect.left, rect.top - parentRect.top, rect.width, rect.height,
224
+ // pageX, pageY are absolute screen coordinates
225
+ rect.left + window.scrollX, rect.top + window.scrollY);
195
226
  }
196
227
  }, []);
197
228
  const measureInWindow = useCallback(callback => {
@@ -200,13 +231,27 @@ export const SkiaGraphiteView = props => {
200
231
  callback(rect.left, rect.top, rect.width, rect.height);
201
232
  }
202
233
  }, []);
234
+
235
+ // No flush cancellation is needed on unmount: a microtask queued before
236
+ // unmount runs within the same task, and flush no-ops once the
237
+ // layout-effect cleanup has nulled rendererRef.
238
+
203
239
  useImperativeHandle(ref, () => ({
240
+ setPicture,
204
241
  getContext,
205
- getNativeId: () => nativeId
206
- }), [getContext, nativeId]);
242
+ getSize,
243
+ redraw,
244
+ makeImageSnapshot,
245
+ measure,
246
+ measureInWindow,
247
+ get canvasRef() {
248
+ return () => canvasRef.current;
249
+ }
250
+ }), [setPicture, getContext, getSize, redraw, makeImageSnapshot, measure, measureInWindow]);
207
251
  useEffect(() => {
208
252
  const api = global.SkiaViewApi;
209
253
  api.registerView(`${nativeId}`, {
254
+ setPicture,
210
255
  getContext,
211
256
  getSize,
212
257
  redraw,
@@ -215,9 +260,11 @@ export const SkiaGraphiteView = props => {
215
260
  measureInWindow
216
261
  });
217
262
  return () => {
263
+ // Views must be removed on unmount: the handle's closures capture the
264
+ // canvas element, so a stale entry retains the whole detached DOM tree.
218
265
  api.unregisterView(`${nativeId}`);
219
266
  };
220
- }, [getContext, getSize, redraw, makeImageSnapshot, measure, measureInWindow, nativeId]);
267
+ }, [setPicture, getContext, getSize, redraw, makeImageSnapshot, measure, measureInWindow, nativeId]);
221
268
 
222
269
  // Let go of the recordings the view holds.
223
270
  useEffect(() => () => {
@@ -227,9 +274,6 @@ export const SkiaGraphiteView = props => {
227
274
  shownRef.current = [];
228
275
  }, []);
229
276
  const {
230
- debug: _debug,
231
- opaque: _opaque,
232
- highBitDepth: _highBitDepth,
233
277
  ref: _ref,
234
278
  onLayout: _onLayout,
235
279
  nativeID: _nativeID,
@@ -251,4 +295,4 @@ export const SkiaGraphiteView = props => {
251
295
  }
252
296
  }));
253
297
  };
254
- //# sourceMappingURL=SkiaGraphiteView.web.js.map
298
+ //# sourceMappingURL=SkiaView.web.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["React","useCallback","useEffect","useImperativeHandle","useMemo","useRef","JsiSkPictureRecorder","Platform","SkiaViewNativeId","useSkiaWebRenderer","WebGraphiteRecording","constructor","picture","_defineProperty","retain","holds","release","disposed","dispose","Symbol","WebGraphiteContext","target","width","getSize","height","beginRecording","recorder","Error","CanvasKit","PictureRecorder","x","y","finishRecording","finishRecordingAsPicture","submit","recording","SkiaView","props","ref","onLayout","canvasRef","pictureRef","queueRef","shownRef","flushScheduledRef","nativeId","nativeID","undefined","Number","current","isStatic","__destroyWebGLContextAfterRender","present","renderer","frame","length","draw","map","previous","forEach","paint","rendererRef","flush","redraw","queueMicrotask","setPicture","push","_canvasRef$current","_canvasRef$current2","clientWidth","clientHeight","getContext","makeImageSnapshot","rect","measure","callback","getBoundingClientRect","parentElement","offsetParent","parentRect","left","top","window","scrollX","scrollY","measureInWindow","api","global","SkiaViewApi","registerView","unregisterView","_ref","_onLayout","_nativeID","_isStatic","viewProps","createElement","View","_extends","key","style","display"],"sources":["SkiaView.web.tsx"],"sourcesContent":["/* global HTMLCanvasElement */\nimport React, {\n useCallback,\n useEffect,\n useImperativeHandle,\n useMemo,\n useRef,\n} from \"react\";\nimport type { ViewProps } from \"react-native\";\n\nimport type {\n SkCanvas,\n SkGraphiteContext,\n SkGraphiteRecording,\n SkImage,\n SkPicture,\n SkRect,\n} from \"../skia/types\";\nimport { JsiSkPictureRecorder } from \"../skia/web/JsiSkPictureRecorder\";\nimport { Platform } from \"../Platform\";\nimport type {\n ISkiaViewApiWeb,\n SkiaWebViewHandle,\n} from \"../specs/NativeSkiaModule.web\";\n\nimport { SkiaViewNativeId } from \"./SkiaViewNativeId\";\nimport { useSkiaWebRenderer } from \"./SkiaWebRenderer\";\nimport type { Renderer, WebFrame } from \"./SkiaWebRenderer\";\n\n// The web has no Graphite: the view paints pictures on a WebGL canvas (with\n// context-loss recovery and the destroy-context-after-render mode). It shows\n// one of two kinds of content. The picture of a <Canvas> or a\n// <SkiaPictureView> is a whole frame: the latest one wins. The recordings\n// submitted through the view's context (SkiaGraphiteView) keep their native\n// semantics, presented in submission order and never dropped, with one\n// difference: the surface starts cleared on every frame, so a recording draws\n// the whole frame rather than a delta.\n\nexport interface SkiaViewHandle extends SkiaWebViewHandle {\n /** The canvas element, for Reanimated's measure(). */\n readonly canvasRef: () => HTMLCanvasElement | null;\n}\n\nexport interface SkiaViewProps extends ViewProps {\n ref?: React.Ref<SkiaViewHandle>;\n __destroyWebGLContextAfterRender?: boolean;\n}\n\n/**\n * A frame recorded on the web. The view holds it while it is queued or on\n * screen: disposing it then only marks it, the picture is deleted once the\n * view lets go of it.\n */\nclass WebGraphiteRecording implements SkGraphiteRecording {\n readonly __typename__ = \"GraphiteRecording\" as const;\n private holds = 0;\n private disposed = false;\n\n constructor(readonly picture: SkPicture) {}\n\n retain() {\n this.holds++;\n }\n\n release() {\n this.holds--;\n if (this.disposed && this.holds === 0) {\n this.picture.dispose();\n }\n }\n\n dispose() {\n if (this.disposed) {\n return;\n }\n this.disposed = true;\n if (this.holds === 0) {\n this.picture.dispose();\n }\n }\n\n [Symbol.dispose]() {\n this.dispose();\n }\n}\n\ninterface RecordingTarget {\n getSize(): { width: number; height: number };\n submit(recording: WebGraphiteRecording): void;\n}\n\nclass WebGraphiteContext implements SkGraphiteContext {\n readonly __typename__ = \"GraphiteContext\" as const;\n private recorder: JsiSkPictureRecorder | null = null;\n\n constructor(private readonly target: RecordingTarget) {}\n\n get width() {\n return this.target.getSize().width;\n }\n\n get height() {\n return this.target.getSize().height;\n }\n\n beginRecording(): SkCanvas {\n if (this.recorder) {\n throw new Error(\n \"SkiaGraphiteView: a recording is already open, call finishRecording() first.\"\n );\n }\n const { width, height } = this.target.getSize();\n if (width <= 0 || height <= 0) {\n throw new Error(\"SkiaGraphiteView: the view has no size yet.\");\n }\n this.recorder = new JsiSkPictureRecorder(\n CanvasKit,\n new CanvasKit.PictureRecorder()\n );\n return this.recorder.beginRecording({ x: 0, y: 0, width, height });\n }\n\n finishRecording(): SkGraphiteRecording {\n if (!this.recorder) {\n throw new Error(\n \"SkiaGraphiteView: no recording is open, call beginRecording() first.\"\n );\n }\n const picture = this.recorder.finishRecordingAsPicture();\n this.recorder.dispose();\n this.recorder = null;\n return new WebGraphiteRecording(picture);\n }\n\n submit(recording: SkGraphiteRecording) {\n if (!(recording instanceof WebGraphiteRecording)) {\n throw new Error(\n \"SkiaGraphiteView: submit() expects a recording from finishRecording().\"\n );\n }\n this.target.submit(recording);\n }\n\n dispose() {}\n\n [Symbol.dispose]() {}\n}\n\nexport const SkiaView = (props: SkiaViewProps) => {\n const { ref, onLayout } = props;\n const canvasRef = useRef<HTMLCanvasElement | null>(null);\n // The picture of a <Canvas> or a <SkiaPictureView>: a whole frame.\n const pictureRef = useRef<SkPicture | null>(null);\n // Recordings submitted since the last frame, in order, and the frame on\n // screen, replayed when the surface is recreated.\n const queueRef = useRef<WebGraphiteRecording[]>([]);\n const shownRef = useRef<WebGraphiteRecording[]>([]);\n const flushScheduledRef = useRef(false);\n const nativeId = useMemo(\n () =>\n props.nativeID !== undefined\n ? Number(props.nativeID)\n : SkiaViewNativeId.current++,\n [props.nativeID]\n );\n\n const isStatic = props.__destroyWebGLContextAfterRender === true;\n\n // Presents the recordings submitted since the last frame. A frame that\n // cannot be painted yet (unmeasured canvas, lost context) stays queued for\n // the next opportunity.\n const present = useCallback((renderer: Renderer) => {\n const frame = queueRef.current;\n if (frame.length === 0) {\n return;\n }\n queueRef.current = [];\n if (!renderer.draw(frame.map((recording) => recording.picture))) {\n queueRef.current = frame;\n return;\n }\n const previous = shownRef.current;\n shownRef.current = frame;\n previous.forEach((recording) => recording.release());\n }, []);\n\n // Paints what the view holds: pending recordings first, else the picture,\n // else the frame on screen again (the surface was recreated).\n const paint = useCallback(\n (renderer: Renderer) => {\n if (queueRef.current.length > 0) {\n present(renderer);\n } else if (pictureRef.current) {\n renderer.draw([pictureRef.current]);\n } else if (shownRef.current.length > 0) {\n renderer.draw(shownRef.current.map((recording) => recording.picture));\n }\n },\n [present]\n );\n const rendererRef = useSkiaWebRenderer(canvasRef, isStatic, {\n paint,\n onLayout,\n });\n\n // Draws are flushed from a microtask rather than an animation frame: the\n // browser composites once per frame either way, and painting right away\n // keeps a frame produced inside an animation callback (the Reanimated\n // mapper, a frame loop) from slipping to the next one. Deferring to the\n // next animation frame would alternate between \"flush pending in this\n // frame\" and \"flush scheduled for the next frame\", halving the effective\n // frame rate. Without a renderer yet (an unmeasured canvas), the content\n // stays held and is painted by the renderer once it exists, so it is\n // never lost.\n const flush = useCallback(() => {\n flushScheduledRef.current = false;\n if (rendererRef.current) {\n paint(rendererRef.current);\n }\n }, [paint, rendererRef]);\n\n const redraw = useCallback(() => {\n if (!flushScheduledRef.current) {\n flushScheduledRef.current = true;\n queueMicrotask(flush);\n }\n }, [flush]);\n\n const setPicture = useCallback(\n (picture: SkPicture) => {\n pictureRef.current = picture;\n redraw();\n },\n [redraw]\n );\n\n const submit = useCallback(\n (recording: WebGraphiteRecording) => {\n recording.retain();\n queueRef.current.push(recording);\n redraw();\n },\n [redraw]\n );\n\n const getSize = useCallback(\n () => ({\n width: canvasRef.current?.clientWidth || 0,\n height: canvasRef.current?.clientHeight || 0,\n }),\n []\n );\n\n const getContext = useCallback(\n (): SkGraphiteContext => new WebGraphiteContext({ getSize, submit }),\n [getSize, submit]\n );\n\n const makeImageSnapshot = useCallback(\n (rect?: SkRect): SkImage | null => {\n const renderer = rendererRef.current;\n if (!renderer) {\n return null;\n }\n let frame: WebFrame;\n if (queueRef.current.length > 0) {\n frame = queueRef.current.map((recording) => recording.picture);\n } else if (pictureRef.current) {\n frame = [pictureRef.current];\n } else {\n frame = shownRef.current.map((recording) => recording.picture);\n }\n if (frame.length === 0) {\n return null;\n }\n return renderer.makeImageSnapshot(frame, rect);\n },\n [rendererRef]\n );\n\n const measure = useCallback(\n (\n callback: (\n x: number,\n y: number,\n width: number,\n height: number,\n pageX: number,\n pageY: number\n ) => void\n ) => {\n if (canvasRef.current) {\n const rect = canvasRef.current.getBoundingClientRect();\n const parentElement = canvasRef.current.offsetParent as HTMLElement;\n const parentRect = parentElement?.getBoundingClientRect() || {\n left: 0,\n top: 0,\n };\n callback(\n // x, y are relative to the parent\n rect.left - parentRect.left,\n rect.top - parentRect.top,\n rect.width,\n rect.height,\n // pageX, pageY are absolute screen coordinates\n rect.left + window.scrollX,\n rect.top + window.scrollY\n );\n }\n },\n []\n );\n\n const measureInWindow = useCallback(\n (\n callback: (x: number, y: number, width: number, height: number) => void\n ) => {\n if (canvasRef.current) {\n const rect = canvasRef.current.getBoundingClientRect();\n callback(rect.left, rect.top, rect.width, rect.height);\n }\n },\n []\n );\n\n // No flush cancellation is needed on unmount: a microtask queued before\n // unmount runs within the same task, and flush no-ops once the\n // layout-effect cleanup has nulled rendererRef.\n\n useImperativeHandle(\n ref,\n () => ({\n setPicture,\n getContext,\n getSize,\n redraw,\n makeImageSnapshot,\n measure,\n measureInWindow,\n get canvasRef() {\n return () => canvasRef.current;\n },\n }),\n [\n setPicture,\n getContext,\n getSize,\n redraw,\n makeImageSnapshot,\n measure,\n measureInWindow,\n ]\n );\n\n useEffect(() => {\n const api = global.SkiaViewApi as ISkiaViewApiWeb;\n api.registerView(`${nativeId}`, {\n setPicture,\n getContext,\n getSize,\n redraw,\n makeImageSnapshot,\n measure,\n measureInWindow,\n });\n return () => {\n // Views must be removed on unmount: the handle's closures capture the\n // canvas element, so a stale entry retains the whole detached DOM tree.\n api.unregisterView(`${nativeId}`);\n };\n }, [\n setPicture,\n getContext,\n getSize,\n redraw,\n makeImageSnapshot,\n measure,\n measureInWindow,\n nativeId,\n ]);\n\n // Let go of the recordings the view holds.\n useEffect(\n () => () => {\n queueRef.current.forEach((recording) => recording.release());\n queueRef.current = [];\n shownRef.current.forEach((recording) => recording.release());\n shownRef.current = [];\n },\n []\n );\n\n const {\n ref: _ref,\n onLayout: _onLayout,\n nativeID: _nativeID,\n __destroyWebGLContextAfterRender: _isStatic,\n ...viewProps\n } = props;\n return (\n <Platform.View nativeID={`${nativeId}`} {...viewProps}>\n <canvas\n // A canvas element is bound to one context kind for life (WebGL for\n // the live renderer, 2D for the static one), so switching renderers\n // needs a fresh element.\n key={isStatic ? \"static\" : \"webgl\"}\n ref={canvasRef}\n style={{ display: \"block\", width: \"100%\", height: \"100%\" }}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C,CAAC;IAC5D0B,QAAQ,CAACO,OAAO,GAAG,EAAE;IACrBN,QAAQ,CAACM,OAAO,CAACU,OAAO,CAAExB,SAAS,IAAKA,SAAS,CAACnB,OAAO,CAAC,CAAC,CAAC;IAC5D2B,QAAQ,CAACM,OAAO,GAAG,EAAE;EACvB,CAAC,EACD,EACF,CAAC;EAED,MAAM;IACJX,GAAG,EAAEqD,IAAI;IACTpD,QAAQ,EAAEqD,SAAS;IACnB9C,QAAQ,EAAE+C,SAAS;IACnB1C,gCAAgC,EAAE2C,SAAS;IAC3C,GAAGC;EACL,CAAC,GAAG1D,KAAK;EACT,oBACErC,KAAA,CAAAgG,aAAA,CAACzF,QAAQ,CAAC0F,IAAI,EAAAC,QAAA;IAACpD,QAAQ,EAAE,GAAGD,QAAQ;EAAG,GAAKkD,SAAS,gBACnD/F,KAAA,CAAAgG,aAAA;IACE;IACA;IACA;IACAG,GAAG,EAAEjD,QAAQ,GAAG,QAAQ,GAAG,OAAQ;IACnCZ,GAAG,EAAEE,SAAU;IACf4D,KAAK,EAAE;MAAEC,OAAO,EAAE,OAAO;MAAE/E,KAAK,EAAE,MAAM;MAAEE,MAAM,EAAE;IAAO;EAAE,CAC5D,CACY,CAAC;AAEpB,CAAC","ignoreList":[]}
@@ -6,7 +6,7 @@ function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e =
6
6
  import { useLayoutEffect, useRef } from "react";
7
7
  import { JsiSkSurface } from "../skia/web/JsiSkSurface";
8
8
 
9
- // The WebGL renderers behind the web views (SkiaPictureView, SkiaGraphiteView):
9
+ // The WebGL renderers behind the web view (SkiaView.web):
10
10
  // a <canvas> element, its WebGL context and the CanvasKit surface built on
11
11
  // it, with the context-loss handling and the "destroy the context after each
12
12
  // draw" mode that keeps a page under the browser's live-context limit.
@@ -1 +1 @@
1
- {"version":3,"names":["useLayoutEffect","useRef","JsiSkSurface","dp2Pixel","pd","rect","undefined","x","y","width","height","canvasWebGL","WeakMap","deleteContextHandle","handle","CanvasKit","deleteContext","MakeWebGLContext","WebGLRenderer","constructor","canvas","requestRedraw","_defineProperty","release","restoreWanted","restoreRequest","setTimeout","_canvasWebGL$get","get","loseContext","restoreContext","acquire","entry","owner","addEventListener","onContextLost","onContextRestored","known","gl","isContextLost","lossAnnounced","_known$loseContext","GetWebGLContext","Error","trackContext","grContext","contextHandle","drawingBufferColorSpace","onResize","_canvas$getContext","getContext","getExtension","set","event","preventDefault","_this$surface","surface","ref","delete","releaseResourcesAndAbandonContext","_canvasWebGL$get$gl$i","_canvasWebGL$get2","makeImageSnapshot","frame","getCanvas","clear","TRANSPARENT","draw","flush","_this$surface2","window","devicePixelRatio","clientWidth","clientHeight","MakeOnScreenGLSurface","ColorSpace","SRGB","Float32Array","of","save","scale","picture","drawPicture","restore","dispose","removeEventListener","clearTimeout","queueMicrotask","isConnected","_entry$loseContext","StaticWebGLRenderer","cachedImage","renderFrameToSurface","tempCanvas","OffscreenCanvas","ctx","webglSurface","skiaCanvas","error","cleanupRenderResult","result","_result$surface","_result$tempCanvas$ge","renderResult","ctx2d","drawImage","console","_this$cachedImage","makeLayoutEvent","timeStamp","Date","now","nativeEvent","layout","currentTarget","target","bubbles","cancelable","defaultPrevented","eventPhase","isDefaultPrevented","isPropagationStopped","persist","stopPropagation","isTrusted","type","useSkiaWebRenderer","canvasRef","isStatic","host","rendererRef","hostRef","current","renderer","paint","lastWidth","lastHeight","lastPixelDensity","resizeIfNeeded","pixelDensity","observer","ResizeObserver","entries","layoutHandler","onLayout","left","top","contentRect","observe","media","onPixelDensityChange","watchPixelDensity","_media","matchMedia","query","_media2","disconnect"],"sources":["SkiaWebRenderer.ts"],"sourcesContent":["/* global HTMLCanvasElement, ResizeObserver, MediaQueryList */\nimport type { RefObject } from \"react\";\nimport { useLayoutEffect, useRef } from \"react\";\nimport type { LayoutChangeEvent } from \"react-native\";\nimport type { GrDirectContext, WebGLContextHandle } from \"canvaskit-wasm\";\n\nimport type { SkRect, SkPicture, SkImage } from \"../skia/types\";\nimport { JsiSkSurface } from \"../skia/web/JsiSkSurface\";\n\n// The WebGL renderers behind the web views (SkiaPictureView, SkiaGraphiteView):\n// a <canvas> element, its WebGL context and the CanvasKit surface built on\n// it, with the context-loss handling and the \"destroy the context after each\n// draw\" mode that keeps a page under the browser's live-context limit.\n\nconst dp2Pixel = (pd: number, rect?: SkRect) => {\n if (!rect) {\n return undefined;\n }\n return {\n x: rect.x * pd,\n y: rect.y * pd,\n width: rect.width * pd,\n height: rect.height * pd,\n };\n};\n\n/**\n * What a view paints: pictures in points, replayed in order onto a cleared\n * surface.\n */\nexport type WebFrame = SkPicture[];\n\nexport interface Renderer {\n onResize(): void;\n /**\n * Paints the frame. Returns false when there is nothing to paint on yet\n * (the canvas is unmeasured, the context is lost): the caller keeps the\n * frame for the next opportunity.\n */\n draw(frame: WebFrame): boolean;\n makeImageSnapshot(frame: WebFrame, rect?: SkRect): SkImage | null;\n dispose(): void;\n}\n\n// A <canvas> element owns at most one WebGL context for its whole lifetime.\n// A renderer, on the other hand, lives as long as the layout effect that\n// creates it, which is shorter: React re-runs layout effects on a *preserved*\n// host node under StrictMode's DEV double-invoke and when an Activity/offscreen\n// subtree is hidden and revealed (#3976). What belongs to the element rather\n// than to a renderer is tracked here, per element:\n// - the context, so that a new renderer can tell whether the element already\n// has one (and whether it is lost) without calling getContext() itself,\n// which on a fresh element would create a context with the wrong attributes\n// (CanvasKit.GetWebGLContext requests its own);\n// - the WEBGL_lose_context extension, captured while the context is healthy:\n// getExtension() returns null on a lost context, and this object is the only\n// way to lose a context on purpose or to ask the browser to restore one;\n// - whether the browser has announced the loss of the context yet: a lost\n// context can only be restored once its webglcontextlost event has been\n// dispatched, and that event is asynchronous;\n// - the renderer currently attached to the element, if any.\ninterface CanvasWebGL {\n gl: WebGLRenderingContext | WebGL2RenderingContext;\n // The WEBGL_lose_context extension.\n loseContext: { loseContext(): void; restoreContext(): void } | null;\n lossAnnounced: boolean;\n owner: WebGLRenderer | null;\n}\nconst canvasWebGL = new WeakMap<HTMLCanvasElement, CanvasWebGL>();\n\n// Unregisters a context from CanvasKit's registry, which otherwise retains the\n// canvas element (and its detached DOM tree) forever (#3924).\nconst deleteContextHandle = (handle: WebGLContextHandle) => {\n CanvasKit.deleteContext(handle);\n // Making the now-deleted handle current clears CanvasKit's current-context\n // globals (GLctx/Module.ctx), which would otherwise keep referencing the\n // context (and the canvas) until another surface becomes current. With a\n // deleted handle this is a no-op that returns null without creating\n // anything.\n CanvasKit.MakeWebGLContext(handle);\n};\n\nexport class WebGLRenderer implements Renderer {\n private surface: JsiSkSurface | null = null;\n private grContext: GrDirectContext | null = null;\n private contextHandle: WebGLContextHandle = 0;\n private pd = 1;\n // Set while the renderer is waiting for a lost context to be restored.\n private restoreWanted = false;\n private restoreRequest: ReturnType<typeof setTimeout> | null = null;\n\n constructor(\n private canvas: HTMLCanvasElement,\n // Called when the renderer becomes able to paint again and the current\n // frame should be drawn.\n private requestRedraw: () => void\n ) {\n const entry = canvasWebGL.get(canvas);\n if (entry) {\n entry.owner = this;\n }\n canvas.addEventListener(\"webglcontextlost\", this.onContextLost);\n canvas.addEventListener(\"webglcontextrestored\", this.onContextRestored);\n this.acquire();\n }\n\n // Builds the GrDirectContext and the surface on the element's WebGL\n // context, creating the context first if the element has none.\n private acquire() {\n const { canvas } = this;\n const known = canvasWebGL.get(canvas);\n if (known?.gl.isContextLost()) {\n // Nothing can be built on a lost context: CanvasKit.GetWebGLContext\n // happily registers it, and MakeWebGLContext then faults inside wasm\n // (#3976). Ask the browser for it back and finish in onContextRestored;\n // if the loss hasn't been announced yet, onContextLost asks.\n this.restoreWanted = true;\n if (known.lossAnnounced) {\n known.loseContext?.restoreContext();\n }\n return;\n }\n const handle = CanvasKit.GetWebGLContext(canvas);\n if (!handle) {\n throw new Error(\"Could not create a WebGL context\");\n }\n const entry = known ?? this.trackContext();\n let grContext: GrDirectContext | null = null;\n try {\n grContext = CanvasKit.MakeWebGLContext(handle);\n } finally {\n if (!grContext) {\n // Whether it returned null or threw, don't leave the registry\n // holding on to the canvas.\n deleteContextHandle(handle);\n }\n }\n if (!grContext) {\n throw new Error(\"Could not create a graphics context\");\n }\n this.restoreWanted = false;\n this.contextHandle = handle;\n this.grContext = grContext;\n if (entry) {\n entry.gl.drawingBufferColorSpace = \"display-p3\";\n }\n this.onResize();\n }\n\n // CanvasKit just created the element's context; asking for it again hands\n // back the same object (the attributes are only honored the first time).\n private trackContext(): CanvasWebGL | null {\n const { canvas } = this;\n const gl = canvas.getContext(\"webgl2\") ?? canvas.getContext(\"webgl\");\n if (!gl) {\n return null;\n }\n const entry: CanvasWebGL = {\n gl,\n loseContext: gl.getExtension(\"WEBGL_lose_context\"),\n lossAnnounced: false,\n owner: this,\n };\n canvasWebGL.set(canvas, entry);\n // Browsers restore a lost context (evicted as the oldest one when the\n // page exceeds the active-context limit, or lost to a GPU reset) only if\n // the page called preventDefault() on the webglcontextlost event. A\n // renderer isn't necessarily attached when that happens (the canvas may\n // be in a hidden Activity), so these listeners live as long as the\n // element does. They are registered ahead of any renderer's, and the\n // loss can't be announced before they exist since the event is\n // asynchronous.\n canvas.addEventListener(\"webglcontextlost\", (event) => {\n event.preventDefault();\n entry.lossAnnounced = true;\n });\n canvas.addEventListener(\"webglcontextrestored\", () => {\n entry.lossAnnounced = false;\n });\n return entry;\n }\n\n // Frees everything built on the context. The context itself belongs to the\n // element, see dispose().\n private release() {\n this.surface?.ref.delete();\n this.surface = null;\n if (this.grContext) {\n this.grContext.releaseResourcesAndAbandonContext();\n this.grContext.delete();\n this.grContext = null;\n }\n if (this.contextHandle) {\n deleteContextHandle(this.contextHandle);\n this.contextHandle = 0;\n }\n }\n\n private isContextLost() {\n return canvasWebGL.get(this.canvas)?.gl.isContextLost() ?? false;\n }\n\n private onContextLost = () => {\n // The browser already dropped every GL object; drop our references to\n // them. Restoration is left to the browser (it restores an evicted\n // context as soon as a slot frees up), except when this renderer was\n // built on an already-lost context and is waiting to paint for the first\n // time: chasing an eviction from here would evict the next-oldest context\n // in turn, and with more live canvases than the browser allows the\n // canvases would endlessly evict each other.\n this.release();\n if (this.restoreWanted) {\n // The permission granted by preventDefault() is only recorded by the\n // browser once the event dispatch is over: a restoreContext() call\n // from inside the handler is refused, so ask from a later task.\n this.restoreRequest = setTimeout(() => {\n this.restoreRequest = null;\n canvasWebGL.get(this.canvas)?.loseContext?.restoreContext();\n }, 0);\n }\n };\n\n private onContextRestored = () => {\n this.acquire();\n this.requestRedraw();\n };\n\n makeImageSnapshot(frame: WebFrame, rect?: SkRect): SkImage | null {\n if (!this.surface || this.isContextLost()) {\n return null;\n }\n const canvas = this.surface.getCanvas();\n canvas!.clear(CanvasKit.TRANSPARENT);\n this.draw(frame);\n this.surface.ref.flush();\n return this.surface.makeImageSnapshot(dp2Pixel(this.pd, rect));\n }\n\n onResize() {\n const { canvas } = this;\n if (!this.grContext || this.isContextLost()) {\n // Waiting for the context to be restored (the restore path resizes),\n // or the loss hasn't been announced yet and onContextLost is about to\n // release everything: either way there is nothing to build on.\n return;\n }\n this.pd = window.devicePixelRatio;\n canvas.width = canvas.clientWidth * this.pd;\n canvas.height = canvas.clientHeight * this.pd;\n this.surface?.ref.delete();\n this.surface = null;\n if (canvas.width === 0 || canvas.height === 0) {\n // The canvas hasn't been laid out yet (or is hidden). The view's\n // ResizeObserver calls us again as soon as it has a size.\n return;\n }\n // Reuse the existing WebGL context and GrDirectContext: only the surface\n // needs to be recreated when the canvas is resized.\n const surface = CanvasKit.MakeOnScreenGLSurface(\n this.grContext,\n canvas.width,\n canvas.height,\n CanvasKit.ColorSpace.SRGB\n );\n if (!surface) {\n throw new Error(\"Could not create surface\");\n }\n this.surface = new JsiSkSurface(CanvasKit, surface);\n }\n\n draw(frame: WebFrame) {\n if (!this.surface || this.isContextLost()) {\n return false;\n }\n const canvas = this.surface.getCanvas();\n canvas.clear(Float32Array.of(0, 0, 0, 0));\n canvas.save();\n canvas.scale(this.pd, this.pd);\n for (const picture of frame) {\n canvas.drawPicture(picture);\n }\n canvas.restore();\n this.surface.ref.flush();\n return true;\n }\n\n dispose(): void {\n const { canvas } = this;\n canvas.removeEventListener(\"webglcontextlost\", this.onContextLost);\n canvas.removeEventListener(\"webglcontextrestored\", this.onContextRestored);\n if (this.restoreRequest !== null) {\n clearTimeout(this.restoreRequest);\n this.restoreRequest = null;\n }\n this.restoreWanted = false;\n this.release();\n // Free the drawing buffer, which CanvasKit requests with depth and stencil\n // attachments (about 8 bytes per pixel): a canvas that stays in the\n // document without a renderer, hidden in an Activity say, would otherwise\n // keep a full-size buffer around. The next renderer's onResize() sizes it\n // again.\n canvas.width = 0;\n canvas.height = 0;\n const entry = canvasWebGL.get(canvas);\n if (!entry) {\n return;\n }\n entry.owner = null;\n // Whether the element is going away is only known once the commit is\n // over: on a real unmount React runs this cleanup *before* removing the\n // node from the document, while StrictMode's double-invoke and an\n // Activity hide keep the node in place (and the former builds the next\n // renderer on it right away). Losing the context of a detached element\n // matters: it would otherwise stay alive until the element is garbage\n // collected, and browsers cap the number of live contexts per page\n // (16 in Chrome, which then evicts the oldest one, visible or not).\n queueMicrotask(() => {\n if (\n entry.owner === null &&\n !canvas.isConnected &&\n !entry.gl.isContextLost()\n ) {\n entry.loseContext?.loseContext();\n }\n });\n }\n}\n\ninterface TempRenderResult {\n surface: JsiSkSurface;\n tempCanvas: OffscreenCanvas;\n grContext: GrDirectContext;\n contextHandle: WebGLContextHandle;\n}\n\nexport class StaticWebGLRenderer implements Renderer {\n private cachedImage: SkImage | null = null;\n private pd = 1;\n\n constructor(private canvas: HTMLCanvasElement) {}\n\n onResize(): void {\n this.cachedImage = null;\n }\n\n private renderFrameToSurface(frame: WebFrame): TempRenderResult | null {\n this.pd = window.devicePixelRatio;\n if (this.canvas.clientWidth === 0 || this.canvas.clientHeight === 0) {\n return null;\n }\n const tempCanvas = new OffscreenCanvas(\n this.canvas.clientWidth * this.pd,\n this.canvas.clientHeight * this.pd\n );\n\n let surface: JsiSkSurface | null = null;\n let grContext: GrDirectContext | null = null;\n let contextHandle: WebGLContextHandle = 0;\n\n try {\n contextHandle = CanvasKit.GetWebGLContext(tempCanvas);\n if (!contextHandle) {\n throw new Error(\"Could not create a WebGL context\");\n }\n grContext = CanvasKit.MakeWebGLContext(contextHandle);\n if (!grContext) {\n throw new Error(\"Could not create a graphics context\");\n }\n const ctx = tempCanvas.getContext(\"webgl2\");\n if (ctx) {\n ctx.drawingBufferColorSpace = \"display-p3\";\n }\n const webglSurface = CanvasKit.MakeOnScreenGLSurface(\n grContext,\n tempCanvas.width,\n tempCanvas.height,\n CanvasKit.ColorSpace.SRGB\n );\n\n if (!webglSurface) {\n throw new Error(\"Could not create WebGL surface\");\n }\n\n surface = new JsiSkSurface(CanvasKit, webglSurface);\n\n const skiaCanvas = surface.getCanvas();\n skiaCanvas.clear(Float32Array.of(0, 0, 0, 0));\n skiaCanvas.save();\n skiaCanvas.scale(this.pd, this.pd);\n for (const picture of frame) {\n skiaCanvas.drawPicture(picture);\n }\n skiaCanvas.restore();\n surface.ref.flush();\n\n return { surface, tempCanvas, grContext, contextHandle };\n } catch (error) {\n this.cleanupRenderResult({\n surface,\n tempCanvas,\n grContext,\n contextHandle,\n });\n return null;\n }\n }\n\n private cleanupRenderResult(result: {\n surface: JsiSkSurface | null;\n tempCanvas: OffscreenCanvas;\n grContext: GrDirectContext | null;\n contextHandle: WebGLContextHandle;\n }): void {\n result.surface?.ref.delete();\n if (result.grContext) {\n result.grContext.releaseResourcesAndAbandonContext();\n result.grContext.delete();\n }\n result.tempCanvas\n .getContext(\"webgl2\")\n ?.getExtension(\"WEBGL_lose_context\")\n ?.loseContext();\n if (result.contextHandle) {\n // Unregister the context from CanvasKit's internal registry, otherwise\n // it retains the OffscreenCanvas forever.\n CanvasKit.deleteContext(result.contextHandle);\n // Clear CanvasKit's current-context globals (see WebGLRenderer.dispose).\n CanvasKit.MakeWebGLContext(result.contextHandle);\n }\n }\n\n draw(frame: WebFrame) {\n const renderResult = this.renderFrameToSurface(frame);\n if (!renderResult) {\n return false;\n }\n const { tempCanvas } = renderResult;\n const ctx2d = this.canvas.getContext(\"2d\");\n if (!ctx2d) {\n this.cleanupRenderResult(renderResult);\n throw new Error(\"Could not get 2D context\");\n }\n\n // Set canvas dimensions to match pixel density\n this.canvas.width = this.canvas.clientWidth * this.pd;\n this.canvas.height = this.canvas.clientHeight * this.pd;\n\n // Draw the tempCanvas scaled down to the display size\n ctx2d.drawImage(\n tempCanvas,\n 0,\n 0,\n tempCanvas.width,\n tempCanvas.height,\n 0,\n 0,\n this.canvas.clientWidth * this.pd,\n this.canvas.clientHeight * this.pd\n );\n\n this.cleanupRenderResult(renderResult);\n return true;\n }\n\n makeImageSnapshot(frame: WebFrame, rect?: SkRect): SkImage | null {\n if (!this.cachedImage) {\n const renderResult = this.renderFrameToSurface(frame);\n if (!renderResult) {\n return null;\n }\n\n try {\n this.cachedImage = renderResult.surface.makeImageSnapshot(\n dp2Pixel(this.pd, rect)\n );\n } catch (error) {\n console.error(\"Error creating image snapshot:\", error);\n } finally {\n this.cleanupRenderResult(renderResult);\n }\n }\n\n return this.cachedImage;\n }\n\n dispose(): void {\n this.cachedImage?.dispose();\n this.cachedImage = null;\n }\n}\n\n// Mirrors the event react-native-web synthesizes for onLayout.\nexport const makeLayoutEvent = (\n x: number,\n y: number,\n width: number,\n height: number\n): LayoutChangeEvent => ({\n timeStamp: Date.now(),\n nativeEvent: { layout: { x, y, width, height } },\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-expect-error\n currentTarget: 0,\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-expect-error\n target: 0,\n bubbles: false,\n cancelable: false,\n defaultPrevented: false,\n eventPhase: 0,\n isDefaultPrevented() {\n throw new Error(\"Method not supported on web.\");\n },\n isPropagationStopped() {\n throw new Error(\"Method not supported on web.\");\n },\n persist() {\n throw new Error(\"Method not supported on web.\");\n },\n preventDefault() {\n throw new Error(\"Method not supported on web.\");\n },\n stopPropagation() {\n throw new Error(\"Method not supported on web.\");\n },\n isTrusted: true,\n type: \"\",\n});\n\nexport interface WebRendererHost {\n /**\n * Paints the view's current content, if any, on a renderer that just got\n * (or got back) a surface: after a resize, a density change or a restored\n * context.\n */\n paint: (renderer: Renderer) => void;\n onLayout?: (event: LayoutChangeEvent) => void;\n}\n\n/**\n * Owns a renderer for the given <canvas> element for as long as the view is\n * mounted, and keeps its surface in step with the element's size and the\n * display's pixel density.\n *\n * The rendering lifecycle deliberately does not depend on layout events:\n * - The renderer is created synchronously on mount (the canvas element is\n * guaranteed to exist in useLayoutEffect; a zero size at that point is\n * fine, the surface is created once the canvas is measurable).\n * - A ResizeObserver on the canvas itself recreates the surface and repaints\n * synchronously (its callbacks run after layout, before paint), and is\n * also the source of the user-facing onLayout event.\n * - The renderer belongs to the layout effect, the WebGL context to the\n * <canvas> element, whose lifetime is longer; see WebGLRenderer for how\n * the two are reconciled.\n */\nexport const useSkiaWebRenderer = (\n canvasRef: RefObject<HTMLCanvasElement | null>,\n isStatic: boolean,\n host: WebRendererHost\n): RefObject<Renderer | null> => {\n const rendererRef = useRef<Renderer | null>(null);\n const hostRef = useRef(host);\n useLayoutEffect(() => {\n hostRef.current = host;\n }, [host]);\n\n useLayoutEffect(() => {\n const canvas = canvasRef.current;\n if (!canvas) {\n return undefined;\n }\n const renderer: Renderer = isStatic\n ? new StaticWebGLRenderer(canvas)\n : new WebGLRenderer(canvas, () => hostRef.current.paint(renderer));\n rendererRef.current = renderer;\n\n const paint = () => hostRef.current.paint(renderer);\n\n // The renderer constructor already sized the surface from the current\n // layout, so the observer's initial delivery only repaints if the size\n // changed in between.\n let lastWidth = canvas.clientWidth;\n let lastHeight = canvas.clientHeight;\n let lastPixelDensity = window.devicePixelRatio;\n const resizeIfNeeded = () => {\n const width = canvas.clientWidth;\n const height = canvas.clientHeight;\n const pixelDensity = window.devicePixelRatio;\n if (\n width === lastWidth &&\n height === lastHeight &&\n pixelDensity === lastPixelDensity\n ) {\n return;\n }\n lastWidth = width;\n lastHeight = height;\n lastPixelDensity = pixelDensity;\n renderer.onResize();\n paint();\n };\n\n const observer = new ResizeObserver((entries) => {\n resizeIfNeeded();\n const layoutHandler = hostRef.current.onLayout;\n if (layoutHandler) {\n const { left, top, width, height } = entries[0].contentRect;\n // setTimeout 0 is taken from react-native-web (UIManager)\n setTimeout(\n () => layoutHandler(makeLayoutEvent(left, top, width, height)),\n 0\n );\n }\n });\n observer.observe(canvas);\n\n // A pixel-density change with no CSS size change (browser zoom, moving\n // the window to another display) doesn't trigger the ResizeObserver:\n // watch it via matchMedia, re-arming the query for each new density.\n // This degrades gracefully where unsupported: without matchMedia or\n // MediaQueryList.addEventListener (older Safari), or where the query\n // never matches because the resolution feature is unknown (Safari < 16),\n // density-only changes simply don't repaint — everything else still does.\n let media: MediaQueryList | null = null;\n const onPixelDensityChange = () => {\n resizeIfNeeded();\n watchPixelDensity();\n };\n const watchPixelDensity = () => {\n media?.removeEventListener(\"change\", onPixelDensityChange);\n media = null;\n if (typeof window.matchMedia === \"function\") {\n const query = window.matchMedia(\n `(resolution: ${window.devicePixelRatio}dppx)`\n );\n if (typeof query.addEventListener === \"function\") {\n media = query;\n media.addEventListener(\"change\", onPixelDensityChange);\n }\n }\n };\n watchPixelDensity();\n\n // Paint any content that was dispatched before the renderer existed.\n paint();\n\n return () => {\n observer.disconnect();\n media?.removeEventListener(\"change\", onPixelDensityChange);\n rendererRef.current = null;\n renderer.dispose();\n };\n }, [canvasRef, isStatic]);\n\n return rendererRef;\n};\n"],"mappings":";;;AAAA;;AAEA,SAASA,eAAe,EAAEC,MAAM,QAAQ,OAAO;AAK/C,SAASC,YAAY,QAAQ,0BAA0B;;AAEvD;AACA;AACA;AACA;;AAEA,MAAMC,QAAQ,GAAGA,CAACC,EAAU,EAAEC,IAAa,KAAK;EAC9C,IAAI,CAACA,IAAI,EAAE;IACT,OAAOC,SAAS;EAClB;EACA,OAAO;IACLC,CAAC,EAAEF,IAAI,CAACE,CAAC,GAAGH,EAAE;IACdI,CAAC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C,QAAQ,EAAEoH,oBAAoB,CAAC;QACxD;MACF;IACF,CAAC;IACDC,iBAAiB,CAAC,CAAC;;IAEnB;IACAjB,KAAK,CAAC,CAAC;IAEP,OAAO,MAAM;MAAA,IAAAqB,OAAA;MACXf,QAAQ,CAACgB,UAAU,CAAC,CAAC;MACrB,CAAAD,OAAA,GAAAN,KAAK,cAAAM,OAAA,eAALA,OAAA,CAAOtE,mBAAmB,CAAC,QAAQ,EAAEiE,oBAAoB,CAAC;MAC1DpB,WAAW,CAACE,OAAO,GAAG,IAAI;MAC1BC,QAAQ,CAACjD,OAAO,CAAC,CAAC;IACpB,CAAC;EACH,CAAC,EAAE,CAAC2C,SAAS,EAAEC,QAAQ,CAAC,CAAC;EAEzB,OAAOE,WAAW;AACpB,CAAC","ignoreList":[]}
1
+ {"version":3,"names":["useLayoutEffect","useRef","JsiSkSurface","dp2Pixel","pd","rect","undefined","x","y","width","height","canvasWebGL","WeakMap","deleteContextHandle","handle","CanvasKit","deleteContext","MakeWebGLContext","WebGLRenderer","constructor","canvas","requestRedraw","_defineProperty","release","restoreWanted","restoreRequest","setTimeout","_canvasWebGL$get","get","loseContext","restoreContext","acquire","entry","owner","addEventListener","onContextLost","onContextRestored","known","gl","isContextLost","lossAnnounced","_known$loseContext","GetWebGLContext","Error","trackContext","grContext","contextHandle","drawingBufferColorSpace","onResize","_canvas$getContext","getContext","getExtension","set","event","preventDefault","_this$surface","surface","ref","delete","releaseResourcesAndAbandonContext","_canvasWebGL$get$gl$i","_canvasWebGL$get2","makeImageSnapshot","frame","getCanvas","clear","TRANSPARENT","draw","flush","_this$surface2","window","devicePixelRatio","clientWidth","clientHeight","MakeOnScreenGLSurface","ColorSpace","SRGB","Float32Array","of","save","scale","picture","drawPicture","restore","dispose","removeEventListener","clearTimeout","queueMicrotask","isConnected","_entry$loseContext","StaticWebGLRenderer","cachedImage","renderFrameToSurface","tempCanvas","OffscreenCanvas","ctx","webglSurface","skiaCanvas","error","cleanupRenderResult","result","_result$surface","_result$tempCanvas$ge","renderResult","ctx2d","drawImage","console","_this$cachedImage","makeLayoutEvent","timeStamp","Date","now","nativeEvent","layout","currentTarget","target","bubbles","cancelable","defaultPrevented","eventPhase","isDefaultPrevented","isPropagationStopped","persist","stopPropagation","isTrusted","type","useSkiaWebRenderer","canvasRef","isStatic","host","rendererRef","hostRef","current","renderer","paint","lastWidth","lastHeight","lastPixelDensity","resizeIfNeeded","pixelDensity","observer","ResizeObserver","entries","layoutHandler","onLayout","left","top","contentRect","observe","media","onPixelDensityChange","watchPixelDensity","_media","matchMedia","query","_media2","disconnect"],"sources":["SkiaWebRenderer.ts"],"sourcesContent":["/* global HTMLCanvasElement, ResizeObserver, MediaQueryList */\nimport type { RefObject } from \"react\";\nimport { useLayoutEffect, useRef } from \"react\";\nimport type { LayoutChangeEvent } from \"react-native\";\nimport type { GrDirectContext, WebGLContextHandle } from \"canvaskit-wasm\";\n\nimport type { SkRect, SkPicture, SkImage } from \"../skia/types\";\nimport { JsiSkSurface } from \"../skia/web/JsiSkSurface\";\n\n// The WebGL renderers behind the web view (SkiaView.web):\n// a <canvas> element, its WebGL context and the CanvasKit surface built on\n// it, with the context-loss handling and the \"destroy the context after each\n// draw\" mode that keeps a page under the browser's live-context limit.\n\nconst dp2Pixel = (pd: number, rect?: SkRect) => {\n if (!rect) {\n return undefined;\n }\n return {\n x: rect.x * pd,\n y: rect.y * pd,\n width: rect.width * pd,\n height: rect.height * pd,\n };\n};\n\n/**\n * What a view paints: pictures in points, replayed in order onto a cleared\n * surface.\n */\nexport type WebFrame = SkPicture[];\n\nexport interface Renderer {\n onResize(): void;\n /**\n * Paints the frame. Returns false when there is nothing to paint on yet\n * (the canvas is unmeasured, the context is lost): the caller keeps the\n * frame for the next opportunity.\n */\n draw(frame: WebFrame): boolean;\n makeImageSnapshot(frame: WebFrame, rect?: SkRect): SkImage | null;\n dispose(): void;\n}\n\n// A <canvas> element owns at most one WebGL context for its whole lifetime.\n// A renderer, on the other hand, lives as long as the layout effect that\n// creates it, which is shorter: React re-runs layout effects on a *preserved*\n// host node under StrictMode's DEV double-invoke and when an Activity/offscreen\n// subtree is hidden and revealed (#3976). What belongs to the element rather\n// than to a renderer is tracked here, per element:\n// - the context, so that a new renderer can tell whether the element already\n// has one (and whether it is lost) without calling getContext() itself,\n// which on a fresh element would create a context with the wrong attributes\n// (CanvasKit.GetWebGLContext requests its own);\n// - the WEBGL_lose_context extension, captured while the context is healthy:\n// getExtension() returns null on a lost context, and this object is the only\n// way to lose a context on purpose or to ask the browser to restore one;\n// - whether the browser has announced the loss of the context yet: a lost\n// context can only be restored once its webglcontextlost event has been\n// dispatched, and that event is asynchronous;\n// - the renderer currently attached to the element, if any.\ninterface CanvasWebGL {\n gl: WebGLRenderingContext | WebGL2RenderingContext;\n // The WEBGL_lose_context extension.\n loseContext: { loseContext(): void; restoreContext(): void } | null;\n lossAnnounced: boolean;\n owner: WebGLRenderer | null;\n}\nconst canvasWebGL = new WeakMap<HTMLCanvasElement, CanvasWebGL>();\n\n// Unregisters a context from CanvasKit's registry, which otherwise retains the\n// canvas element (and its detached DOM tree) forever (#3924).\nconst deleteContextHandle = (handle: WebGLContextHandle) => {\n CanvasKit.deleteContext(handle);\n // Making the now-deleted handle current clears CanvasKit's current-context\n // globals (GLctx/Module.ctx), which would otherwise keep referencing the\n // context (and the canvas) until another surface becomes current. With a\n // deleted handle this is a no-op that returns null without creating\n // anything.\n CanvasKit.MakeWebGLContext(handle);\n};\n\nexport class WebGLRenderer implements Renderer {\n private surface: JsiSkSurface | null = null;\n private grContext: GrDirectContext | null = null;\n private contextHandle: WebGLContextHandle = 0;\n private pd = 1;\n // Set while the renderer is waiting for a lost context to be restored.\n private restoreWanted = false;\n private restoreRequest: ReturnType<typeof setTimeout> | null = null;\n\n constructor(\n private canvas: HTMLCanvasElement,\n // Called when the renderer becomes able to paint again and the current\n // frame should be drawn.\n private requestRedraw: () => void\n ) {\n const entry = canvasWebGL.get(canvas);\n if (entry) {\n entry.owner = this;\n }\n canvas.addEventListener(\"webglcontextlost\", this.onContextLost);\n canvas.addEventListener(\"webglcontextrestored\", this.onContextRestored);\n this.acquire();\n }\n\n // Builds the GrDirectContext and the surface on the element's WebGL\n // context, creating the context first if the element has none.\n private acquire() {\n const { canvas } = this;\n const known = canvasWebGL.get(canvas);\n if (known?.gl.isContextLost()) {\n // Nothing can be built on a lost context: CanvasKit.GetWebGLContext\n // happily registers it, and MakeWebGLContext then faults inside wasm\n // (#3976). Ask the browser for it back and finish in onContextRestored;\n // if the loss hasn't been announced yet, onContextLost asks.\n this.restoreWanted = true;\n if (known.lossAnnounced) {\n known.loseContext?.restoreContext();\n }\n return;\n }\n const handle = CanvasKit.GetWebGLContext(canvas);\n if (!handle) {\n throw new Error(\"Could not create a WebGL context\");\n }\n const entry = known ?? this.trackContext();\n let grContext: GrDirectContext | null = null;\n try {\n grContext = CanvasKit.MakeWebGLContext(handle);\n } finally {\n if (!grContext) {\n // Whether it returned null or threw, don't leave the registry\n // holding on to the canvas.\n deleteContextHandle(handle);\n }\n }\n if (!grContext) {\n throw new Error(\"Could not create a graphics context\");\n }\n this.restoreWanted = false;\n this.contextHandle = handle;\n this.grContext = grContext;\n if (entry) {\n entry.gl.drawingBufferColorSpace = \"display-p3\";\n }\n this.onResize();\n }\n\n // CanvasKit just created the element's context; asking for it again hands\n // back the same object (the attributes are only honored the first time).\n private trackContext(): CanvasWebGL | null {\n const { canvas } = this;\n const gl = canvas.getContext(\"webgl2\") ?? canvas.getContext(\"webgl\");\n if (!gl) {\n return null;\n }\n const entry: CanvasWebGL = {\n gl,\n loseContext: gl.getExtension(\"WEBGL_lose_context\"),\n lossAnnounced: false,\n owner: this,\n };\n canvasWebGL.set(canvas, entry);\n // Browsers restore a lost context (evicted as the oldest one when the\n // page exceeds the active-context limit, or lost to a GPU reset) only if\n // the page called preventDefault() on the webglcontextlost event. A\n // renderer isn't necessarily attached when that happens (the canvas may\n // be in a hidden Activity), so these listeners live as long as the\n // element does. They are registered ahead of any renderer's, and the\n // loss can't be announced before they exist since the event is\n // asynchronous.\n canvas.addEventListener(\"webglcontextlost\", (event) => {\n event.preventDefault();\n entry.lossAnnounced = true;\n });\n canvas.addEventListener(\"webglcontextrestored\", () => {\n entry.lossAnnounced = false;\n });\n return entry;\n }\n\n // Frees everything built on the context. The context itself belongs to the\n // element, see dispose().\n private release() {\n this.surface?.ref.delete();\n this.surface = null;\n if (this.grContext) {\n this.grContext.releaseResourcesAndAbandonContext();\n this.grContext.delete();\n this.grContext = null;\n }\n if (this.contextHandle) {\n deleteContextHandle(this.contextHandle);\n this.contextHandle = 0;\n }\n }\n\n private isContextLost() {\n return canvasWebGL.get(this.canvas)?.gl.isContextLost() ?? false;\n }\n\n private onContextLost = () => {\n // The browser already dropped every GL object; drop our references to\n // them. Restoration is left to the browser (it restores an evicted\n // context as soon as a slot frees up), except when this renderer was\n // built on an already-lost context and is waiting to paint for the first\n // time: chasing an eviction from here would evict the next-oldest context\n // in turn, and with more live canvases than the browser allows the\n // canvases would endlessly evict each other.\n this.release();\n if (this.restoreWanted) {\n // The permission granted by preventDefault() is only recorded by the\n // browser once the event dispatch is over: a restoreContext() call\n // from inside the handler is refused, so ask from a later task.\n this.restoreRequest = setTimeout(() => {\n this.restoreRequest = null;\n canvasWebGL.get(this.canvas)?.loseContext?.restoreContext();\n }, 0);\n }\n };\n\n private onContextRestored = () => {\n this.acquire();\n this.requestRedraw();\n };\n\n makeImageSnapshot(frame: WebFrame, rect?: SkRect): SkImage | null {\n if (!this.surface || this.isContextLost()) {\n return null;\n }\n const canvas = this.surface.getCanvas();\n canvas!.clear(CanvasKit.TRANSPARENT);\n this.draw(frame);\n this.surface.ref.flush();\n return this.surface.makeImageSnapshot(dp2Pixel(this.pd, rect));\n }\n\n onResize() {\n const { canvas } = this;\n if (!this.grContext || this.isContextLost()) {\n // Waiting for the context to be restored (the restore path resizes),\n // or the loss hasn't been announced yet and onContextLost is about to\n // release everything: either way there is nothing to build on.\n return;\n }\n this.pd = window.devicePixelRatio;\n canvas.width = canvas.clientWidth * this.pd;\n canvas.height = canvas.clientHeight * this.pd;\n this.surface?.ref.delete();\n this.surface = null;\n if (canvas.width === 0 || canvas.height === 0) {\n // The canvas hasn't been laid out yet (or is hidden). The view's\n // ResizeObserver calls us again as soon as it has a size.\n return;\n }\n // Reuse the existing WebGL context and GrDirectContext: only the surface\n // needs to be recreated when the canvas is resized.\n const surface = CanvasKit.MakeOnScreenGLSurface(\n this.grContext,\n canvas.width,\n canvas.height,\n CanvasKit.ColorSpace.SRGB\n );\n if (!surface) {\n throw new Error(\"Could not create surface\");\n }\n this.surface = new JsiSkSurface(CanvasKit, surface);\n }\n\n draw(frame: WebFrame) {\n if (!this.surface || this.isContextLost()) {\n return false;\n }\n const canvas = this.surface.getCanvas();\n canvas.clear(Float32Array.of(0, 0, 0, 0));\n canvas.save();\n canvas.scale(this.pd, this.pd);\n for (const picture of frame) {\n canvas.drawPicture(picture);\n }\n canvas.restore();\n this.surface.ref.flush();\n return true;\n }\n\n dispose(): void {\n const { canvas } = this;\n canvas.removeEventListener(\"webglcontextlost\", this.onContextLost);\n canvas.removeEventListener(\"webglcontextrestored\", this.onContextRestored);\n if (this.restoreRequest !== null) {\n clearTimeout(this.restoreRequest);\n this.restoreRequest = null;\n }\n this.restoreWanted = false;\n this.release();\n // Free the drawing buffer, which CanvasKit requests with depth and stencil\n // attachments (about 8 bytes per pixel): a canvas that stays in the\n // document without a renderer, hidden in an Activity say, would otherwise\n // keep a full-size buffer around. The next renderer's onResize() sizes it\n // again.\n canvas.width = 0;\n canvas.height = 0;\n const entry = canvasWebGL.get(canvas);\n if (!entry) {\n return;\n }\n entry.owner = null;\n // Whether the element is going away is only known once the commit is\n // over: on a real unmount React runs this cleanup *before* removing the\n // node from the document, while StrictMode's double-invoke and an\n // Activity hide keep the node in place (and the former builds the next\n // renderer on it right away). Losing the context of a detached element\n // matters: it would otherwise stay alive until the element is garbage\n // collected, and browsers cap the number of live contexts per page\n // (16 in Chrome, which then evicts the oldest one, visible or not).\n queueMicrotask(() => {\n if (\n entry.owner === null &&\n !canvas.isConnected &&\n !entry.gl.isContextLost()\n ) {\n entry.loseContext?.loseContext();\n }\n });\n }\n}\n\ninterface TempRenderResult {\n surface: JsiSkSurface;\n tempCanvas: OffscreenCanvas;\n grContext: GrDirectContext;\n contextHandle: WebGLContextHandle;\n}\n\nexport class StaticWebGLRenderer implements Renderer {\n private cachedImage: SkImage | null = null;\n private pd = 1;\n\n constructor(private canvas: HTMLCanvasElement) {}\n\n onResize(): void {\n this.cachedImage = null;\n }\n\n private renderFrameToSurface(frame: WebFrame): TempRenderResult | null {\n this.pd = window.devicePixelRatio;\n if (this.canvas.clientWidth === 0 || this.canvas.clientHeight === 0) {\n return null;\n }\n const tempCanvas = new OffscreenCanvas(\n this.canvas.clientWidth * this.pd,\n this.canvas.clientHeight * this.pd\n );\n\n let surface: JsiSkSurface | null = null;\n let grContext: GrDirectContext | null = null;\n let contextHandle: WebGLContextHandle = 0;\n\n try {\n contextHandle = CanvasKit.GetWebGLContext(tempCanvas);\n if (!contextHandle) {\n throw new Error(\"Could not create a WebGL context\");\n }\n grContext = CanvasKit.MakeWebGLContext(contextHandle);\n if (!grContext) {\n throw new Error(\"Could not create a graphics context\");\n }\n const ctx = tempCanvas.getContext(\"webgl2\");\n if (ctx) {\n ctx.drawingBufferColorSpace = \"display-p3\";\n }\n const webglSurface = CanvasKit.MakeOnScreenGLSurface(\n grContext,\n tempCanvas.width,\n tempCanvas.height,\n CanvasKit.ColorSpace.SRGB\n );\n\n if (!webglSurface) {\n throw new Error(\"Could not create WebGL surface\");\n }\n\n surface = new JsiSkSurface(CanvasKit, webglSurface);\n\n const skiaCanvas = surface.getCanvas();\n skiaCanvas.clear(Float32Array.of(0, 0, 0, 0));\n skiaCanvas.save();\n skiaCanvas.scale(this.pd, this.pd);\n for (const picture of frame) {\n skiaCanvas.drawPicture(picture);\n }\n skiaCanvas.restore();\n surface.ref.flush();\n\n return { surface, tempCanvas, grContext, contextHandle };\n } catch (error) {\n this.cleanupRenderResult({\n surface,\n tempCanvas,\n grContext,\n contextHandle,\n });\n return null;\n }\n }\n\n private cleanupRenderResult(result: {\n surface: JsiSkSurface | null;\n tempCanvas: OffscreenCanvas;\n grContext: GrDirectContext | null;\n contextHandle: WebGLContextHandle;\n }): void {\n result.surface?.ref.delete();\n if (result.grContext) {\n result.grContext.releaseResourcesAndAbandonContext();\n result.grContext.delete();\n }\n result.tempCanvas\n .getContext(\"webgl2\")\n ?.getExtension(\"WEBGL_lose_context\")\n ?.loseContext();\n if (result.contextHandle) {\n // Unregister the context from CanvasKit's internal registry, otherwise\n // it retains the OffscreenCanvas forever.\n CanvasKit.deleteContext(result.contextHandle);\n // Clear CanvasKit's current-context globals (see WebGLRenderer.dispose).\n CanvasKit.MakeWebGLContext(result.contextHandle);\n }\n }\n\n draw(frame: WebFrame) {\n const renderResult = this.renderFrameToSurface(frame);\n if (!renderResult) {\n return false;\n }\n const { tempCanvas } = renderResult;\n const ctx2d = this.canvas.getContext(\"2d\");\n if (!ctx2d) {\n this.cleanupRenderResult(renderResult);\n throw new Error(\"Could not get 2D context\");\n }\n\n // Set canvas dimensions to match pixel density\n this.canvas.width = this.canvas.clientWidth * this.pd;\n this.canvas.height = this.canvas.clientHeight * this.pd;\n\n // Draw the tempCanvas scaled down to the display size\n ctx2d.drawImage(\n tempCanvas,\n 0,\n 0,\n tempCanvas.width,\n tempCanvas.height,\n 0,\n 0,\n this.canvas.clientWidth * this.pd,\n this.canvas.clientHeight * this.pd\n );\n\n this.cleanupRenderResult(renderResult);\n return true;\n }\n\n makeImageSnapshot(frame: WebFrame, rect?: SkRect): SkImage | null {\n if (!this.cachedImage) {\n const renderResult = this.renderFrameToSurface(frame);\n if (!renderResult) {\n return null;\n }\n\n try {\n this.cachedImage = renderResult.surface.makeImageSnapshot(\n dp2Pixel(this.pd, rect)\n );\n } catch (error) {\n console.error(\"Error creating image snapshot:\", error);\n } finally {\n this.cleanupRenderResult(renderResult);\n }\n }\n\n return this.cachedImage;\n }\n\n dispose(): void {\n this.cachedImage?.dispose();\n this.cachedImage = null;\n }\n}\n\n// Mirrors the event react-native-web synthesizes for onLayout.\nexport const makeLayoutEvent = (\n x: number,\n y: number,\n width: number,\n height: number\n): LayoutChangeEvent => ({\n timeStamp: Date.now(),\n nativeEvent: { layout: { x, y, width, height } },\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-expect-error\n currentTarget: 0,\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-expect-error\n target: 0,\n bubbles: false,\n cancelable: false,\n defaultPrevented: false,\n eventPhase: 0,\n isDefaultPrevented() {\n throw new Error(\"Method not supported on web.\");\n },\n isPropagationStopped() {\n throw new Error(\"Method not supported on web.\");\n },\n persist() {\n throw new Error(\"Method not supported on web.\");\n },\n preventDefault() {\n throw new Error(\"Method not supported on web.\");\n },\n stopPropagation() {\n throw new Error(\"Method not supported on web.\");\n },\n isTrusted: true,\n type: \"\",\n});\n\nexport interface WebRendererHost {\n /**\n * Paints the view's current content, if any, on a renderer that just got\n * (or got back) a surface: after a resize, a density change or a restored\n * context.\n */\n paint: (renderer: Renderer) => void;\n onLayout?: (event: LayoutChangeEvent) => void;\n}\n\n/**\n * Owns a renderer for the given <canvas> element for as long as the view is\n * mounted, and keeps its surface in step with the element's size and the\n * display's pixel density.\n *\n * The rendering lifecycle deliberately does not depend on layout events:\n * - The renderer is created synchronously on mount (the canvas element is\n * guaranteed to exist in useLayoutEffect; a zero size at that point is\n * fine, the surface is created once the canvas is measurable).\n * - A ResizeObserver on the canvas itself recreates the surface and repaints\n * synchronously (its callbacks run after layout, before paint), and is\n * also the source of the user-facing onLayout event.\n * - The renderer belongs to the layout effect, the WebGL context to the\n * <canvas> element, whose lifetime is longer; see WebGLRenderer for how\n * the two are reconciled.\n */\nexport const useSkiaWebRenderer = (\n canvasRef: RefObject<HTMLCanvasElement | null>,\n isStatic: boolean,\n host: WebRendererHost\n): RefObject<Renderer | null> => {\n const rendererRef = useRef<Renderer | null>(null);\n const hostRef = useRef(host);\n useLayoutEffect(() => {\n hostRef.current = host;\n }, [host]);\n\n useLayoutEffect(() => {\n const canvas = canvasRef.current;\n if (!canvas) {\n return undefined;\n }\n const renderer: Renderer = isStatic\n ? new StaticWebGLRenderer(canvas)\n : new WebGLRenderer(canvas, () => hostRef.current.paint(renderer));\n rendererRef.current = renderer;\n\n const paint = () => hostRef.current.paint(renderer);\n\n // The renderer constructor already sized the surface from the current\n // layout, so the observer's initial delivery only repaints if the size\n // changed in between.\n let lastWidth = canvas.clientWidth;\n let lastHeight = canvas.clientHeight;\n let lastPixelDensity = window.devicePixelRatio;\n const resizeIfNeeded = () => {\n const width = canvas.clientWidth;\n const height = canvas.clientHeight;\n const pixelDensity = window.devicePixelRatio;\n if (\n width === lastWidth &&\n height === lastHeight &&\n pixelDensity === lastPixelDensity\n ) {\n return;\n }\n lastWidth = width;\n lastHeight = height;\n lastPixelDensity = pixelDensity;\n renderer.onResize();\n paint();\n };\n\n const observer = new ResizeObserver((entries) => {\n resizeIfNeeded();\n const layoutHandler = hostRef.current.onLayout;\n if (layoutHandler) {\n const { left, top, width, height } = entries[0].contentRect;\n // setTimeout 0 is taken from react-native-web (UIManager)\n setTimeout(\n () => layoutHandler(makeLayoutEvent(left, top, width, height)),\n 0\n );\n }\n });\n observer.observe(canvas);\n\n // A pixel-density change with no CSS size change (browser zoom, moving\n // the window to another display) doesn't trigger the ResizeObserver:\n // watch it via matchMedia, re-arming the query for each new density.\n // This degrades gracefully where unsupported: without matchMedia or\n // MediaQueryList.addEventListener (older Safari), or where the query\n // never matches because the resolution feature is unknown (Safari < 16),\n // density-only changes simply don't repaint — everything else still does.\n let media: MediaQueryList | null = null;\n const onPixelDensityChange = () => {\n resizeIfNeeded();\n watchPixelDensity();\n };\n const watchPixelDensity = () => {\n media?.removeEventListener(\"change\", onPixelDensityChange);\n media = null;\n if (typeof window.matchMedia === \"function\") {\n const query = window.matchMedia(\n `(resolution: ${window.devicePixelRatio}dppx)`\n );\n if (typeof query.addEventListener === \"function\") {\n media = query;\n media.addEventListener(\"change\", onPixelDensityChange);\n }\n }\n };\n watchPixelDensity();\n\n // Paint any content that was dispatched before the renderer existed.\n paint();\n\n return () => {\n observer.disconnect();\n media?.removeEventListener(\"change\", onPixelDensityChange);\n rendererRef.current = null;\n renderer.dispose();\n };\n }, [canvasRef, isStatic]);\n\n return rendererRef;\n};\n"],"mappings":";;;AAAA;;AAEA,SAASA,eAAe,EAAEC,MAAM,QAAQ,OAAO;AAK/C,SAASC,YAAY,QAAQ,0BAA0B;;AAEvD;AACA;AACA;AACA;;AAEA,MAAMC,QAAQ,GAAGA,CAACC,EAAU,EAAEC,IAAa,KAAK;EAC9C,IAAI,CAACA,IAAI,EAAE;IACT,OAAOC,SAAS;EAClB;EACA,OAAO;IACLC,CAAC,EAAEF,IAAI,CAACE,CAAC,GAAGH,EAAE;IACdI,CAAC,EAAEH,IAAI,CAACG,CAAC,GAAGJ,EAAE;IACdK,KAAK,EAAEJ,IAAI,CAACI,KAAK,GAAGL,EAAE;IACtBM,MAAM,EAAEL,IAAI,CAACK,MAAM,GAAGN;EACxB,CAAC;AACH,CAAC;;AAED;AACA;AACA;AACA;;AAeA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAQA,MAAMO,WAAW,GAAG,IAAIC,OAAO,CAAiC,CAAC;;AAEjE;AACA;AACA,MAAMC,mBAAmB,GAAIC,MAA0B,IAAK;EAC1DC,SAAS,CAACC,aAAa,CAACF,MAAM,CAAC;EAC/B;EACA;EACA;EACA;EACA;EACAC,SAAS,CAACE,gBAAgB,CAACH,MAAM,CAAC;AACpC,CAAC;AAED,OAAO,MAAMI,aAAa,CAAqB;EAS7CC,WAAWA,CACDC,MAAyB;EACjC;EACA;EACQC,aAAyB,EACjC;IAAA,KAJQD,MAAyB,GAAzBA,MAAyB;IAAA,KAGzBC,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GAAG,IAAI;IACvC,MAAMC,oBAAoB,GAAGA,CAAA,KAAM;MACjCZ,cAAc,CAAC,CAAC;MAChBa,iBAAiB,CAAC,CAAC;IACrB,CAAC;IACD,MAAMA,iBAAiB,GAAGA,CAAA,KAAM;MAAA,IAAAC,MAAA;MAC9B,CAAAA,MAAA,GAAAH,KAAK,cAAAG,MAAA,eAALA,MAAA,CAAOnE,mBAAmB,CAAC,QAAQ,EAAEiE,oBAAoB,CAAC;MAC1DD,KAAK,GAAG,IAAI;MACZ,IAAI,OAAO/E,MAAM,CAACmF,UAAU,KAAK,UAAU,EAAE;QAC3C,MAAMC,KAAK,GAAGpF,MAAM,CAACmF,UAAU,CAC7B,gBAAgBnF,MAAM,CAACC,gBAAgB,OACzC,CAAC;QACD,IAAI,OAAOmF,KAAK,CAACxH,gBAAgB,KAAK,UAAU,EAAE;UAChDmH,KAAK,GAAGK,KAAK;UACbL,KAAK,CAACnH,gBAAgB,CAAC,QAAQ,EAAEoH,oBAAoB,CAAC;QACxD;MACF;IACF,CAAC;IACDC,iBAAiB,CAAC,CAAC;;IAEnB;IACAjB,KAAK,CAAC,CAAC;IAEP,OAAO,MAAM;MAAA,IAAAqB,OAAA;MACXf,QAAQ,CAACgB,UAAU,CAAC,CAAC;MACrB,CAAAD,OAAA,GAAAN,KAAK,cAAAM,OAAA,eAALA,OAAA,CAAOtE,mBAAmB,CAAC,QAAQ,EAAEiE,oBAAoB,CAAC;MAC1DpB,WAAW,CAACE,OAAO,GAAG,IAAI;MAC1BC,QAAQ,CAACjD,OAAO,CAAC,CAAC;IACpB,CAAC;EACH,CAAC,EAAE,CAAC2C,SAAS,EAAEC,QAAQ,CAAC,CAAC;EAEzB,OAAOE,WAAW;AACpB,CAAC","ignoreList":[]}
@@ -0,0 +1,6 @@
1
+ import type { AndroidCanvasProps, AndroidSurfaceType } from "./types";
2
+ /** The native props the `android` prop of a view resolves to. */
3
+ export declare const androidNativeProps: (android?: AndroidCanvasProps) => {
4
+ androidSurfaceType: AndroidSurfaceType | "auto";
5
+ androidZOrderOnTop: boolean;
6
+ };
@@ -0,0 +1,10 @@
1
+ // Anything else reaching the native component would hit the generated
2
+ // string-enum parser, which aborts on unknown values.
3
+ const resolveSurfaceType = surfaceType => surfaceType === "SurfaceView" || surfaceType === "TextureView" ? surfaceType : "auto";
4
+
5
+ /** The native props the `android` prop of a view resolves to. */
6
+ export const androidNativeProps = android => ({
7
+ androidSurfaceType: resolveSurfaceType(android === null || android === void 0 ? void 0 : android.surfaceType),
8
+ androidZOrderOnTop: !!(android !== null && android !== void 0 && android.zOrderOnTop)
9
+ });
10
+ //# sourceMappingURL=android.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["resolveSurfaceType","surfaceType","androidNativeProps","android","androidSurfaceType","androidZOrderOnTop","zOrderOnTop"],"sources":["android.ts"],"sourcesContent":["import type { AndroidCanvasProps, AndroidSurfaceType } from \"./types\";\n\n// Anything else reaching the native component would hit the generated\n// string-enum parser, which aborts on unknown values.\nconst resolveSurfaceType = (\n surfaceType: AndroidSurfaceType | undefined\n): \"auto\" | AndroidSurfaceType =>\n surfaceType === \"SurfaceView\" || surfaceType === \"TextureView\"\n ? surfaceType\n : \"auto\";\n\n/** The native props the `android` prop of a view resolves to. */\nexport const androidNativeProps = (android?: AndroidCanvasProps) => ({\n androidSurfaceType: resolveSurfaceType(android?.surfaceType),\n androidZOrderOnTop: !!android?.zOrderOnTop,\n});\n"],"mappings":"AAEA;AACA;AACA,MAAMA,kBAAkB,GACtBC,WAA2C,IAE3CA,WAAW,KAAK,aAAa,IAAIA,WAAW,KAAK,aAAa,GAC1DA,WAAW,GACX,MAAM;;AAEZ;AACA,OAAO,MAAMC,kBAAkB,GAAIC,OAA4B,KAAM;EACnEC,kBAAkB,EAAEJ,kBAAkB,CAACG,OAAO,aAAPA,OAAO,uBAAPA,OAAO,CAAEF,WAAW,CAAC;EAC5DI,kBAAkB,EAAE,CAAC,EAACF,OAAO,aAAPA,OAAO,eAAPA,OAAO,CAAEG,WAAW;AAC5C,CAAC,CAAC","ignoreList":[]}