@shopify/react-native-skia 2.12.0-next.1 → 2.13.0

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 (295) hide show
  1. package/LICENSE.md +2 -1
  2. package/Package.swift +117 -0
  3. package/android/CMakeLists.txt +23 -179
  4. package/android/build.gradle +40 -209
  5. package/android/cpp/jni/JniSkiaManager.cpp +3 -45
  6. package/android/cpp/jni/include/JniPlatformContext.h +1 -1
  7. package/android/cpp/jni/include/JniSkiaBaseView.h +18 -11
  8. package/android/cpp/jni/include/JniSkiaManager.h +3 -4
  9. package/android/cpp/jni/include/JniSkiaPictureView.h +5 -5
  10. package/android/cpp/rnskia-android/RNSkAndroidPlatformContext.h +0 -10
  11. package/android/cpp/rnskia-android/RNSkAndroidView.h +6 -6
  12. package/android/cpp/rnskia-android/RNSkOpenGLCanvasProvider.cpp +4 -4
  13. package/android/cpp/rnskia-android/RNSkOpenGLCanvasProvider.h +2 -2
  14. package/android/src/main/AndroidManifest.xml +1 -1
  15. package/android/src/main/java/com/{shopify/reactnative → reactnative}/skia/PlatformContext.java +1 -1
  16. package/android/src/main/java/com/{shopify/reactnative → reactnative}/skia/RNSkVideo.java +1 -1
  17. package/android/src/main/java/com/{shopify/reactnative → reactnative}/skia/RNSkiaModule.java +1 -8
  18. package/android/src/main/java/com/reactnative/skia/RNSkiaPackage.java +57 -0
  19. package/android/src/main/java/com/reactnative/skia/SkiaBaseView.java +185 -0
  20. package/android/src/main/java/com/{shopify/reactnative → reactnative}/skia/SkiaBaseViewManager.java +20 -1
  21. package/android/src/main/java/com/{shopify/reactnative → reactnative}/skia/SkiaManager.java +11 -6
  22. package/android/src/main/java/com/{shopify/reactnative → reactnative}/skia/SkiaPictureView.java +3 -3
  23. package/android/src/main/java/com/{shopify/reactnative → reactnative}/skia/SkiaPictureViewManager.java +1 -1
  24. package/android/src/main/java/com/{shopify/reactnative → reactnative}/skia/SkiaSurfaceView.java +13 -3
  25. package/android/src/main/java/com/{shopify/reactnative → reactnative}/skia/SkiaTextureView.java +5 -3
  26. package/android/src/main/java/com/{shopify/reactnative → reactnative}/skia/SkiaViewAPI.java +1 -1
  27. package/android/src/main/java/com/{shopify/reactnative → reactnative}/skia/ViewScreenshotService.java +10 -13
  28. package/apple/MetalContext.mm +1 -1
  29. package/apple/RNSkApplePlatformContext.h +0 -3
  30. package/apple/RNSkApplePlatformContext.mm +0 -11
  31. package/apple/RNSkiaModule.h +1 -10
  32. package/apple/RNSkiaModule.mm +2 -10
  33. package/apple/SkiaManager.h +0 -2
  34. package/apple/SkiaManager.mm +4 -6
  35. package/apple/SkiaPictureView.h +2 -2
  36. package/apple/SkiaPictureView.mm +0 -4
  37. package/apple/SkiaUIView.h +3 -18
  38. package/apple/SkiaUIView.mm +0 -30
  39. package/cpp/api/CustomBlendModes.h +17 -0
  40. package/cpp/api/JsiSkApi.h +0 -6
  41. package/cpp/api/JsiSkCanvas.h +19 -10
  42. package/cpp/api/JsiSkFont.h +5 -10
  43. package/cpp/api/JsiSkMatrix.h +4 -2
  44. package/cpp/api/JsiSkSVGFactory.h +4 -0
  45. package/cpp/api/recorder/Convertor.h +5 -2
  46. package/cpp/api/recorder/Drawings.h +13 -3
  47. package/cpp/api/recorder/ImageFilters.h +15 -1
  48. package/cpp/api/recorder/Paint.h +8 -1
  49. package/cpp/jsi/JSICache.cpp +99 -0
  50. package/cpp/jsi/JSICache.h +90 -0
  51. package/cpp/jsi/NativeObject.h +38 -87
  52. package/cpp/jsi/ViewProperty.h +0 -28
  53. package/cpp/rnskia/RNDawnContext.h +2 -1
  54. package/cpp/rnskia/RNDawnWindowContext.h +22 -0
  55. package/cpp/rnskia/RNSkManager.cpp +0 -6
  56. package/cpp/rnskia/RNSkPlatformContext.h +0 -3
  57. package/cpp/skia/include/core/RasterContext.h +25 -0
  58. package/cpp/skia/include/core/SkCanvas.h +0 -1
  59. package/cpp/skia/include/core/SkContext.h +62 -0
  60. package/cpp/skia/include/core/SkContextOptions.h +15 -0
  61. package/cpp/skia/include/core/SkMilestone.h +1 -1
  62. package/cpp/skia/include/core/SkPicture.h +36 -18
  63. package/cpp/skia/include/core/SkRecorder.h +8 -0
  64. package/cpp/skia/include/core/SkSerialProcs.h +2 -6
  65. package/cpp/skia/include/effects/SkImageFilters.h +15 -2
  66. package/cpp/skia/include/gpu/ganesh/GrDirectContext.h +73 -47
  67. package/cpp/skia/include/gpu/ganesh/SkSurfaceGanesh.h +7 -4
  68. package/cpp/skia/include/gpu/ganesh/d3d/GrD3DDirectContext.h +12 -0
  69. package/cpp/skia/include/gpu/ganesh/gl/GrGLDirectContext.h +11 -0
  70. package/cpp/skia/include/gpu/ganesh/mtl/GrMtlDirectContext.h +11 -0
  71. package/cpp/skia/include/gpu/ganesh/vk/GrVkDirectContext.h +13 -0
  72. package/cpp/skia/include/gpu/graphite/ContextOptions.h +6 -0
  73. package/cpp/skia/include/gpu/graphite/GraphiteTypes.h +5 -4
  74. package/cpp/skia/include/gpu/graphite/PrecompileContext.h +9 -1
  75. package/cpp/skia/include/gpu/graphite/Recorder.h +0 -2
  76. package/cpp/skia/include/gpu/graphite/Recording.h +3 -0
  77. package/cpp/skia/include/gpu/graphite/dawn/DawnBackendContext.h +8 -0
  78. package/cpp/skia/include/gpu/graphite/mtl/MtlBackendContext.h +11 -0
  79. package/cpp/skia/include/gpu/graphite/vk/VulkanGraphiteContext.h +11 -0
  80. package/cpp/skia/include/private/SkLog.h +1 -19
  81. package/cpp/skia/include/private/chromium/GrVkSecondaryCBDrawContext.h +2 -1
  82. package/cpp/skia/include/utils/SkLogHandler.h +53 -0
  83. package/cpp/skia/include/utils/SkNWayCanvas.h +1 -0
  84. package/cpp/skia/modules/skcms/src/Transform_inl.h +9 -10
  85. package/cpp/skia/modules/skcms/src/skcms_internals.h +8 -3
  86. package/cpp/skia/modules/skottie/include/SkottieProperty.h +2 -0
  87. package/cpp/skia/modules/skottie/include/TextShaper.h +1 -0
  88. package/cpp/skia/modules/skshaper/include/SkShaper.h +23 -1
  89. package/include/ReactNativeSkia.h +6 -0
  90. package/lib/commonjs/dom/nodes/datatypes/Rect.js +5 -1
  91. package/lib/commonjs/dom/nodes/datatypes/Rect.js.map +1 -1
  92. package/lib/commonjs/external/reanimated/useVideo.js +8 -2
  93. package/lib/commonjs/external/reanimated/useVideo.js.map +1 -1
  94. package/lib/commonjs/mock/index.js +0 -1
  95. package/lib/commonjs/mock/index.js.map +1 -1
  96. package/lib/commonjs/renderer/Canvas.d.ts +11 -3
  97. package/lib/commonjs/renderer/Canvas.js +8 -6
  98. package/lib/commonjs/renderer/Canvas.js.map +1 -1
  99. package/lib/commonjs/renderer/components/Mask.js +3 -9
  100. package/lib/commonjs/renderer/components/Mask.js.map +1 -1
  101. package/lib/commonjs/skia/types/JsiInstance.d.ts +1 -0
  102. package/lib/commonjs/skia/types/JsiInstance.js.map +1 -1
  103. package/lib/commonjs/skia/types/Matrix4.js +7 -2
  104. package/lib/commonjs/skia/types/Matrix4.js.map +1 -1
  105. package/lib/commonjs/skia/types/Skia.d.ts +1 -6
  106. package/lib/commonjs/skia/types/Skia.js.map +1 -1
  107. package/lib/commonjs/skia/web/JsiSkCanvas.js +12 -7
  108. package/lib/commonjs/skia/web/JsiSkCanvas.js.map +1 -1
  109. package/lib/commonjs/skia/web/JsiSkImage.js +6 -3
  110. package/lib/commonjs/skia/web/JsiSkImage.js.map +1 -1
  111. package/lib/commonjs/skia/web/JsiSkPathBuilder.d.ts +1 -1
  112. package/lib/commonjs/skia/web/JsiSkPathBuilder.js +2 -2
  113. package/lib/commonjs/skia/web/JsiSkPathBuilder.js.map +1 -1
  114. package/lib/commonjs/skia/web/JsiSkTextStyle.js +5 -5
  115. package/lib/commonjs/skia/web/JsiSkTextStyle.js.map +1 -1
  116. package/lib/commonjs/skia/web/JsiSkia.js +0 -3
  117. package/lib/commonjs/skia/web/JsiSkia.js.map +1 -1
  118. package/lib/commonjs/skia/web/JsiSkottieAnimation.js +8 -8
  119. package/lib/commonjs/skia/web/JsiSkottieAnimation.js.map +1 -1
  120. package/lib/commonjs/sksg/Recorder/DrawingContext.d.ts +1 -0
  121. package/lib/commonjs/sksg/Recorder/DrawingContext.js +15 -0
  122. package/lib/commonjs/sksg/Recorder/DrawingContext.js.map +1 -1
  123. package/lib/commonjs/sksg/Recorder/Player.js +1 -1
  124. package/lib/commonjs/sksg/Recorder/Player.js.map +1 -1
  125. package/lib/commonjs/sksg/Recorder/Visitor.js +6 -1
  126. package/lib/commonjs/sksg/Recorder/Visitor.js.map +1 -1
  127. package/lib/commonjs/sksg/Recorder/commands/Drawing.js +12 -9
  128. package/lib/commonjs/sksg/Recorder/commands/Drawing.js.map +1 -1
  129. package/lib/commonjs/sksg/Recorder/commands/ImageFilters.js +15 -1
  130. package/lib/commonjs/sksg/Recorder/commands/ImageFilters.js.map +1 -1
  131. package/lib/commonjs/sksg/Recorder/commands/Shaders.js +1 -1
  132. package/lib/commonjs/sksg/Recorder/commands/Shaders.js.map +1 -1
  133. package/lib/commonjs/specs/SkiaPictureViewNativeComponent.d.ts +2 -0
  134. package/lib/commonjs/specs/SkiaPictureViewNativeComponent.js.map +1 -1
  135. package/lib/commonjs/specs/SkiaPictureViewNativeComponent.web.d.ts +3 -1
  136. package/lib/commonjs/specs/SkiaPictureViewNativeComponent.web.js +3 -0
  137. package/lib/commonjs/specs/SkiaPictureViewNativeComponent.web.js.map +1 -1
  138. package/lib/commonjs/views/SkiaPictureView.js +2 -12
  139. package/lib/commonjs/views/SkiaPictureView.js.map +1 -1
  140. package/lib/commonjs/views/SkiaPictureView.web.js +247 -57
  141. package/lib/commonjs/views/SkiaPictureView.web.js.map +1 -1
  142. package/lib/commonjs/views/types.d.ts +19 -8
  143. package/lib/commonjs/views/types.js.map +1 -1
  144. package/lib/module/dom/nodes/datatypes/Rect.js +5 -1
  145. package/lib/module/dom/nodes/datatypes/Rect.js.map +1 -1
  146. package/lib/module/external/reanimated/useVideo.js +8 -2
  147. package/lib/module/external/reanimated/useVideo.js.map +1 -1
  148. package/lib/module/mock/index.js +0 -1
  149. package/lib/module/mock/index.js.map +1 -1
  150. package/lib/module/renderer/Canvas.d.ts +11 -3
  151. package/lib/module/renderer/Canvas.js +7 -5
  152. package/lib/module/renderer/Canvas.js.map +1 -1
  153. package/lib/module/renderer/components/Mask.js +3 -9
  154. package/lib/module/renderer/components/Mask.js.map +1 -1
  155. package/lib/module/skia/types/JsiInstance.d.ts +1 -0
  156. package/lib/module/skia/types/JsiInstance.js.map +1 -1
  157. package/lib/module/skia/types/Matrix4.js +7 -2
  158. package/lib/module/skia/types/Matrix4.js.map +1 -1
  159. package/lib/module/skia/types/Skia.d.ts +1 -6
  160. package/lib/module/skia/types/Skia.js.map +1 -1
  161. package/lib/module/skia/web/JsiSkCanvas.js +12 -7
  162. package/lib/module/skia/web/JsiSkCanvas.js.map +1 -1
  163. package/lib/module/skia/web/JsiSkImage.js +6 -3
  164. package/lib/module/skia/web/JsiSkImage.js.map +1 -1
  165. package/lib/module/skia/web/JsiSkPathBuilder.d.ts +1 -1
  166. package/lib/module/skia/web/JsiSkPathBuilder.js +2 -2
  167. package/lib/module/skia/web/JsiSkPathBuilder.js.map +1 -1
  168. package/lib/module/skia/web/JsiSkTextStyle.js +5 -5
  169. package/lib/module/skia/web/JsiSkTextStyle.js.map +1 -1
  170. package/lib/module/skia/web/JsiSkia.js +0 -3
  171. package/lib/module/skia/web/JsiSkia.js.map +1 -1
  172. package/lib/module/skia/web/JsiSkottieAnimation.js +8 -8
  173. package/lib/module/skia/web/JsiSkottieAnimation.js.map +1 -1
  174. package/lib/module/sksg/Recorder/DrawingContext.d.ts +1 -0
  175. package/lib/module/sksg/Recorder/DrawingContext.js +15 -0
  176. package/lib/module/sksg/Recorder/DrawingContext.js.map +1 -1
  177. package/lib/module/sksg/Recorder/Player.js +1 -1
  178. package/lib/module/sksg/Recorder/Player.js.map +1 -1
  179. package/lib/module/sksg/Recorder/Visitor.js +6 -1
  180. package/lib/module/sksg/Recorder/Visitor.js.map +1 -1
  181. package/lib/module/sksg/Recorder/commands/Drawing.js +12 -9
  182. package/lib/module/sksg/Recorder/commands/Drawing.js.map +1 -1
  183. package/lib/module/sksg/Recorder/commands/ImageFilters.js +15 -1
  184. package/lib/module/sksg/Recorder/commands/ImageFilters.js.map +1 -1
  185. package/lib/module/sksg/Recorder/commands/Shaders.js +1 -1
  186. package/lib/module/sksg/Recorder/commands/Shaders.js.map +1 -1
  187. package/lib/module/specs/SkiaPictureViewNativeComponent.d.ts +2 -0
  188. package/lib/module/specs/SkiaPictureViewNativeComponent.js.map +1 -1
  189. package/lib/module/specs/SkiaPictureViewNativeComponent.web.d.ts +3 -1
  190. package/lib/module/specs/SkiaPictureViewNativeComponent.web.js +3 -0
  191. package/lib/module/specs/SkiaPictureViewNativeComponent.web.js.map +1 -1
  192. package/lib/module/views/SkiaPictureView.js +2 -12
  193. package/lib/module/views/SkiaPictureView.js.map +1 -1
  194. package/lib/module/views/SkiaPictureView.web.js +247 -57
  195. package/lib/module/views/SkiaPictureView.web.js.map +1 -1
  196. package/lib/module/views/types.d.ts +19 -8
  197. package/lib/module/views/types.js.map +1 -1
  198. package/lib/typescript/lib/commonjs/mock/index.d.ts +0 -1
  199. package/lib/typescript/lib/commonjs/renderer/Canvas.d.ts +2 -2
  200. package/lib/typescript/lib/commonjs/skia/web/JsiSkPathBuilder.d.ts +1 -1
  201. package/lib/typescript/lib/commonjs/skia/web/JsiSkia.d.ts +0 -1
  202. package/lib/typescript/lib/commonjs/sksg/Recorder/DrawingContext.d.ts +1 -0
  203. package/lib/typescript/lib/commonjs/specs/SkiaPictureViewNativeComponent.web.d.ts +3 -1
  204. package/lib/typescript/lib/module/mock/index.d.ts +0 -1
  205. package/lib/typescript/lib/module/renderer/Canvas.d.ts +2 -2
  206. package/lib/typescript/lib/module/skia/Skia.web.d.ts +0 -1
  207. package/lib/typescript/lib/module/skia/web/JsiSkPathBuilder.d.ts +1 -1
  208. package/lib/typescript/lib/module/skia/web/JsiSkia.d.ts +0 -1
  209. package/lib/typescript/lib/module/sksg/Recorder/DrawingContext.d.ts +1 -0
  210. package/lib/typescript/lib/module/specs/SkiaPictureViewNativeComponent.web.d.ts +3 -1
  211. package/lib/typescript/react-native.config.d.ts +3 -0
  212. package/lib/typescript/src/renderer/Canvas.d.ts +11 -3
  213. package/lib/typescript/src/skia/types/JsiInstance.d.ts +1 -0
  214. package/lib/typescript/src/skia/types/Skia.d.ts +1 -6
  215. package/lib/typescript/src/skia/web/JsiSkPathBuilder.d.ts +1 -1
  216. package/lib/typescript/src/sksg/Recorder/DrawingContext.d.ts +1 -0
  217. package/lib/typescript/src/specs/SkiaPictureViewNativeComponent.d.ts +2 -0
  218. package/lib/typescript/src/specs/SkiaPictureViewNativeComponent.web.d.ts +3 -1
  219. package/lib/typescript/src/views/types.d.ts +19 -8
  220. package/package.json +15 -12
  221. package/react-native-skia.podspec +4 -10
  222. package/react-native.config.js +5 -0
  223. package/src/dom/nodes/datatypes/Rect.ts +6 -1
  224. package/src/external/reanimated/useVideo.ts +7 -2
  225. package/src/mock/index.ts +0 -1
  226. package/src/renderer/Canvas.tsx +23 -5
  227. package/src/renderer/components/Mask.tsx +10 -3
  228. package/src/skia/types/JsiInstance.ts +2 -0
  229. package/src/skia/types/Matrix4.ts +6 -2
  230. package/src/skia/types/Skia.ts +1 -7
  231. package/src/skia/web/JsiSkCanvas.ts +22 -12
  232. package/src/skia/web/JsiSkImage.ts +6 -3
  233. package/src/skia/web/JsiSkPathBuilder.ts +2 -2
  234. package/src/skia/web/JsiSkTextStyle.ts +20 -15
  235. package/src/skia/web/JsiSkia.ts +0 -4
  236. package/src/skia/web/JsiSkottieAnimation.ts +8 -8
  237. package/src/sksg/Recorder/DrawingContext.ts +15 -0
  238. package/src/sksg/Recorder/Player.ts +1 -1
  239. package/src/sksg/Recorder/Visitor.ts +9 -6
  240. package/src/sksg/Recorder/commands/Drawing.ts +12 -9
  241. package/src/sksg/Recorder/commands/ImageFilters.ts +20 -1
  242. package/src/sksg/Recorder/commands/Shaders.ts +1 -1
  243. package/src/specs/SkiaPictureViewNativeComponent.ts +5 -0
  244. package/src/specs/SkiaPictureViewNativeComponent.web.ts +5 -0
  245. package/src/views/SkiaPictureView.tsx +2 -10
  246. package/src/views/SkiaPictureView.web.tsx +245 -57
  247. package/src/views/types.ts +23 -10
  248. package/android/src/latest/java/com/shopify/reactnative/skia/ReactNativeCompatible.java +0 -11
  249. package/android/src/main/java/com/shopify/reactnative/skia/RNSkiaPackage.java +0 -79
  250. package/android/src/main/java/com/shopify/reactnative/skia/SkiaAHBView.java +0 -113
  251. package/android/src/main/java/com/shopify/reactnative/skia/SkiaBaseView.java +0 -136
  252. package/android/src/paper/java/com/facebook/react/viewmanagers/SkiaPictureViewManagerDelegate.java +0 -41
  253. package/android/src/paper/java/com/facebook/react/viewmanagers/SkiaPictureViewManagerInterface.java +0 -20
  254. package/android/src/paper/java/com/facebook/react/viewmanagers/SkiaWebGPUViewManagerDelegate.java +0 -35
  255. package/android/src/paper/java/com/facebook/react/viewmanagers/SkiaWebGPUViewManagerInterface.java +0 -17
  256. package/android/src/paper/java/com/shopify/reactnative/skia/NativeSkiaModuleSpec.java +0 -38
  257. package/android/src/reactnative74/java/com/shopify/reactnative/skia/ReactNativeCompatible.java +0 -14
  258. package/apple/SkiaPictureViewManager.h +0 -8
  259. package/apple/SkiaPictureViewManager.mm +0 -60
  260. package/apple/SkiaWebGPUView.h +0 -20
  261. package/apple/WebGPUMetalView.h +0 -12
  262. package/cpp/api/JsiSkiaContext.h +0 -94
  263. package/cpp/dawn/include/dawn/dawn_proc.h +0 -53
  264. package/cpp/dawn/include/dawn/dawn_proc_table.h +0 -330
  265. package/cpp/dawn/include/dawn/dawn_thread_dispatch_proc.h +0 -47
  266. package/cpp/dawn/include/dawn/dawn_version.h +0 -41
  267. package/cpp/dawn/include/dawn/native/D3D11Backend.h +0 -65
  268. package/cpp/dawn/include/dawn/native/D3D12Backend.h +0 -103
  269. package/cpp/dawn/include/dawn/native/D3DBackend.h +0 -56
  270. package/cpp/dawn/include/dawn/native/DawnNative.h +0 -368
  271. package/cpp/dawn/include/dawn/native/MetalBackend.h +0 -56
  272. package/cpp/dawn/include/dawn/native/NullBackend.h +0 -39
  273. package/cpp/dawn/include/dawn/native/OpenGLBackend.h +0 -89
  274. package/cpp/dawn/include/dawn/native/VulkanBackend.h +0 -183
  275. package/cpp/dawn/include/dawn/native/WebGPUBackend.h +0 -49
  276. package/cpp/dawn/include/dawn/native/dawn_native_export.h +0 -49
  277. package/cpp/dawn/include/dawn/platform/DawnPlatform.h +0 -207
  278. package/cpp/dawn/include/dawn/platform/dawn_platform_export.h +0 -49
  279. package/cpp/dawn/include/dawn/replay/Replay.h +0 -99
  280. package/cpp/dawn/include/dawn/replay/dawn_replay_export.h +0 -49
  281. package/cpp/dawn/include/dawn/webgpu_cpp_print.h +0 -2856
  282. package/cpp/dawn/include/tint/tint.h +0 -91
  283. package/cpp/dawn/include/webgpu/webgpu.h +0 -5029
  284. package/cpp/dawn/include/webgpu/webgpu_cpp.h +0 -10353
  285. package/cpp/dawn/include/webgpu/webgpu_cpp_chained_struct.h +0 -57
  286. package/cpp/dawn/include/webgpu/webgpu_enum_class_bitmasks.h +0 -162
  287. package/cpp/dawn/include/webgpu/webgpu_glfw.h +0 -88
  288. package/cpp/jsi/RuntimeAwareCache.cpp +0 -7
  289. package/cpp/jsi/RuntimeAwareCache.h +0 -117
  290. package/cpp/jsi/RuntimeLifecycleMonitor.cpp +0 -72
  291. package/cpp/jsi/RuntimeLifecycleMonitor.h +0 -32
  292. package/cpp/skia/src/gpu/graphite/ContextOptionsPriv.h +0 -45
  293. package/cpp/skia/src/gpu/graphite/ResourceTypes.h +0 -360
  294. package/cpp/skia/src/gpu/graphite/TextureProxyView.h +0 -105
  295. package/libs/.graphite +0 -1
@@ -17,31 +17,189 @@ const dp2Pixel = (pd, rect) => {
17
17
  height: rect.height * pd
18
18
  };
19
19
  };
20
+
21
+ // A <canvas> element owns at most one WebGL context for its whole lifetime.
22
+ // A renderer, on the other hand, lives as long as the layout effect that
23
+ // creates it, which is shorter: React re-runs layout effects on a *preserved*
24
+ // host node under StrictMode's DEV double-invoke and when an Activity/offscreen
25
+ // subtree is hidden and revealed (#3976). What belongs to the element rather
26
+ // than to a renderer is tracked here, per element:
27
+ // - the context, so that a new renderer can tell whether the element already
28
+ // has one (and whether it is lost) without calling getContext() itself,
29
+ // which on a fresh element would create a context with the wrong attributes
30
+ // (CanvasKit.GetWebGLContext requests its own);
31
+ // - the WEBGL_lose_context extension, captured while the context is healthy:
32
+ // getExtension() returns null on a lost context, and this object is the only
33
+ // way to lose a context on purpose or to ask the browser to restore one;
34
+ // - whether the browser has announced the loss of the context yet: a lost
35
+ // context can only be restored once its webglcontextlost event has been
36
+ // dispatched, and that event is asynchronous;
37
+ // - the renderer currently attached to the element, if any.
38
+
39
+ const canvasWebGL = new WeakMap();
40
+
41
+ // Unregisters a context from CanvasKit's registry, which otherwise retains the
42
+ // canvas element (and its detached DOM tree) forever (#3924).
43
+ const deleteContextHandle = handle => {
44
+ CanvasKit.deleteContext(handle);
45
+ // Making the now-deleted handle current clears CanvasKit's current-context
46
+ // globals (GLctx/Module.ctx), which would otherwise keep referencing the
47
+ // context (and the canvas) until another surface becomes current. With a
48
+ // deleted handle this is a no-op that returns null without creating
49
+ // anything.
50
+ CanvasKit.MakeWebGLContext(handle);
51
+ };
20
52
  class WebGLRenderer {
21
- constructor(canvas) {
53
+ constructor(canvas,
54
+ // Called when the renderer becomes able to paint again and the current
55
+ // picture should be drawn.
56
+ requestRedraw) {
22
57
  this.canvas = canvas;
58
+ this.requestRedraw = requestRedraw;
23
59
  _defineProperty(this, "surface", null);
24
60
  _defineProperty(this, "grContext", null);
25
61
  _defineProperty(this, "contextHandle", 0);
26
62
  _defineProperty(this, "pd", 1);
27
- this.contextHandle = CanvasKit.GetWebGLContext(canvas);
28
- if (!this.contextHandle) {
63
+ // Set while the renderer is waiting for a lost context to be restored.
64
+ _defineProperty(this, "restoreWanted", false);
65
+ _defineProperty(this, "restoreRequest", null);
66
+ _defineProperty(this, "onContextLost", () => {
67
+ // The browser already dropped every GL object; drop our references to
68
+ // them. Restoration is left to the browser (it restores an evicted
69
+ // context as soon as a slot frees up), except when this renderer was
70
+ // built on an already-lost context and is waiting to paint for the first
71
+ // time: chasing an eviction from here would evict the next-oldest context
72
+ // in turn, and with more live canvases than the browser allows the
73
+ // canvases would endlessly evict each other.
74
+ this.release();
75
+ if (this.restoreWanted) {
76
+ // The permission granted by preventDefault() is only recorded by the
77
+ // browser once the event dispatch is over: a restoreContext() call
78
+ // from inside the handler is refused, so ask from a later task.
79
+ this.restoreRequest = setTimeout(() => {
80
+ var _canvasWebGL$get;
81
+ this.restoreRequest = null;
82
+ (_canvasWebGL$get = canvasWebGL.get(this.canvas)) === null || _canvasWebGL$get === void 0 || (_canvasWebGL$get = _canvasWebGL$get.loseContext) === null || _canvasWebGL$get === void 0 || _canvasWebGL$get.restoreContext();
83
+ }, 0);
84
+ }
85
+ });
86
+ _defineProperty(this, "onContextRestored", () => {
87
+ this.acquire();
88
+ this.requestRedraw();
89
+ });
90
+ const entry = canvasWebGL.get(canvas);
91
+ if (entry) {
92
+ entry.owner = this;
93
+ }
94
+ canvas.addEventListener("webglcontextlost", this.onContextLost);
95
+ canvas.addEventListener("webglcontextrestored", this.onContextRestored);
96
+ this.acquire();
97
+ }
98
+
99
+ // Builds the GrDirectContext and the surface on the element's WebGL
100
+ // context, creating the context first if the element has none.
101
+ acquire() {
102
+ const {
103
+ canvas
104
+ } = this;
105
+ const known = canvasWebGL.get(canvas);
106
+ if (known !== null && known !== void 0 && known.gl.isContextLost()) {
107
+ // Nothing can be built on a lost context: CanvasKit.GetWebGLContext
108
+ // happily registers it, and MakeWebGLContext then faults inside wasm
109
+ // (#3976). Ask the browser for it back and finish in onContextRestored;
110
+ // if the loss hasn't been announced yet, onContextLost asks.
111
+ this.restoreWanted = true;
112
+ if (known.lossAnnounced) {
113
+ var _known$loseContext;
114
+ (_known$loseContext = known.loseContext) === null || _known$loseContext === void 0 || _known$loseContext.restoreContext();
115
+ }
116
+ return;
117
+ }
118
+ const handle = CanvasKit.GetWebGLContext(canvas);
119
+ if (!handle) {
29
120
  throw new Error("Could not create a WebGL context");
30
121
  }
31
- this.grContext = CanvasKit.MakeWebGLContext(this.contextHandle);
32
- if (!this.grContext) {
33
- CanvasKit.deleteContext(this.contextHandle);
34
- this.contextHandle = 0;
122
+ const entry = known !== null && known !== void 0 ? known : this.trackContext();
123
+ let grContext = null;
124
+ try {
125
+ grContext = CanvasKit.MakeWebGLContext(handle);
126
+ } finally {
127
+ if (!grContext) {
128
+ // Whether it returned null or threw, don't leave the registry
129
+ // holding on to the canvas.
130
+ deleteContextHandle(handle);
131
+ }
132
+ }
133
+ if (!grContext) {
35
134
  throw new Error("Could not create a graphics context");
36
135
  }
37
- const ctx = canvas.getContext("webgl2");
38
- if (ctx) {
39
- ctx.drawingBufferColorSpace = "display-p3";
136
+ this.restoreWanted = false;
137
+ this.contextHandle = handle;
138
+ this.grContext = grContext;
139
+ if (entry) {
140
+ entry.gl.drawingBufferColorSpace = "display-p3";
40
141
  }
41
142
  this.onResize();
42
143
  }
144
+
145
+ // CanvasKit just created the element's context; asking for it again hands
146
+ // back the same object (the attributes are only honored the first time).
147
+ trackContext() {
148
+ var _canvas$getContext;
149
+ const {
150
+ canvas
151
+ } = this;
152
+ const gl = (_canvas$getContext = canvas.getContext("webgl2")) !== null && _canvas$getContext !== void 0 ? _canvas$getContext : canvas.getContext("webgl");
153
+ if (!gl) {
154
+ return null;
155
+ }
156
+ const entry = {
157
+ gl,
158
+ loseContext: gl.getExtension("WEBGL_lose_context"),
159
+ lossAnnounced: false,
160
+ owner: this
161
+ };
162
+ canvasWebGL.set(canvas, entry);
163
+ // Browsers restore a lost context (evicted as the oldest one when the
164
+ // page exceeds the active-context limit, or lost to a GPU reset) only if
165
+ // the page called preventDefault() on the webglcontextlost event. A
166
+ // renderer isn't necessarily attached when that happens (the canvas may
167
+ // be in a hidden Activity), so these listeners live as long as the
168
+ // element does. They are registered ahead of any renderer's, and the
169
+ // loss can't be announced before they exist since the event is
170
+ // asynchronous.
171
+ canvas.addEventListener("webglcontextlost", event => {
172
+ event.preventDefault();
173
+ entry.lossAnnounced = true;
174
+ });
175
+ canvas.addEventListener("webglcontextrestored", () => {
176
+ entry.lossAnnounced = false;
177
+ });
178
+ return entry;
179
+ }
180
+
181
+ // Frees everything built on the context. The context itself belongs to the
182
+ // element, see dispose().
183
+ release() {
184
+ var _this$surface;
185
+ (_this$surface = this.surface) === null || _this$surface === void 0 || _this$surface.ref.delete();
186
+ this.surface = null;
187
+ if (this.grContext) {
188
+ this.grContext.releaseResourcesAndAbandonContext();
189
+ this.grContext.delete();
190
+ this.grContext = null;
191
+ }
192
+ if (this.contextHandle) {
193
+ deleteContextHandle(this.contextHandle);
194
+ this.contextHandle = 0;
195
+ }
196
+ }
197
+ isContextLost() {
198
+ var _canvasWebGL$get$gl$i, _canvasWebGL$get2;
199
+ return (_canvasWebGL$get$gl$i = (_canvasWebGL$get2 = canvasWebGL.get(this.canvas)) === null || _canvasWebGL$get2 === void 0 ? void 0 : _canvasWebGL$get2.gl.isContextLost()) !== null && _canvasWebGL$get$gl$i !== void 0 ? _canvasWebGL$get$gl$i : false;
200
+ }
43
201
  makeImageSnapshot(picture, rect) {
44
- if (!this.surface) {
202
+ if (!this.surface || this.isContextLost()) {
45
203
  return null;
46
204
  }
47
205
  const canvas = this.surface.getCanvas();
@@ -51,17 +209,20 @@ class WebGLRenderer {
51
209
  return this.surface.makeImageSnapshot(dp2Pixel(this.pd, rect));
52
210
  }
53
211
  onResize() {
54
- var _this$surface;
212
+ var _this$surface2;
55
213
  const {
56
214
  canvas
57
215
  } = this;
58
- if (!this.grContext) {
216
+ if (!this.grContext || this.isContextLost()) {
217
+ // Waiting for the context to be restored (the restore path resizes),
218
+ // or the loss hasn't been announced yet and onContextLost is about to
219
+ // release everything: either way there is nothing to build on.
59
220
  return;
60
221
  }
61
222
  this.pd = window.devicePixelRatio;
62
223
  canvas.width = canvas.clientWidth * this.pd;
63
224
  canvas.height = canvas.clientHeight * this.pd;
64
- (_this$surface = this.surface) === null || _this$surface === void 0 || _this$surface.ref.delete();
225
+ (_this$surface2 = this.surface) === null || _this$surface2 === void 0 || _this$surface2.ref.delete();
65
226
  this.surface = null;
66
227
  if (canvas.width === 0 || canvas.height === 0) {
67
228
  // The canvas hasn't been laid out yet (or is hidden). The view's
@@ -77,38 +238,55 @@ class WebGLRenderer {
77
238
  this.surface = new JsiSkSurface(CanvasKit, surface);
78
239
  }
79
240
  draw(picture) {
80
- if (this.surface) {
81
- const canvas = this.surface.getCanvas();
82
- canvas.clear(Float32Array.of(0, 0, 0, 0));
83
- canvas.save();
84
- canvas.scale(this.pd, this.pd);
85
- canvas.drawPicture(picture);
86
- canvas.restore();
87
- this.surface.ref.flush();
241
+ if (!this.surface || this.isContextLost()) {
242
+ return;
88
243
  }
244
+ const canvas = this.surface.getCanvas();
245
+ canvas.clear(Float32Array.of(0, 0, 0, 0));
246
+ canvas.save();
247
+ canvas.scale(this.pd, this.pd);
248
+ canvas.drawPicture(picture);
249
+ canvas.restore();
250
+ this.surface.ref.flush();
89
251
  }
90
252
  dispose() {
91
- var _this$surface2, _this$canvas;
92
- (_this$surface2 = this.surface) === null || _this$surface2 === void 0 || _this$surface2.ref.delete();
93
- this.surface = null;
94
- if (this.grContext) {
95
- this.grContext.releaseResourcesAndAbandonContext();
96
- this.grContext.delete();
97
- this.grContext = null;
253
+ const {
254
+ canvas
255
+ } = this;
256
+ canvas.removeEventListener("webglcontextlost", this.onContextLost);
257
+ canvas.removeEventListener("webglcontextrestored", this.onContextRestored);
258
+ if (this.restoreRequest !== null) {
259
+ clearTimeout(this.restoreRequest);
260
+ this.restoreRequest = null;
98
261
  }
99
- (_this$canvas = this.canvas) === null || _this$canvas === void 0 || (_this$canvas = _this$canvas.getContext("webgl2")) === null || _this$canvas === void 0 || (_this$canvas = _this$canvas.getExtension("WEBGL_lose_context")) === null || _this$canvas === void 0 || _this$canvas.loseContext();
100
- if (this.contextHandle) {
101
- // Unregister the context from CanvasKit's internal registry, otherwise
102
- // it retains the canvas element (and its detached DOM tree) forever.
103
- CanvasKit.deleteContext(this.contextHandle);
104
- // Making the now-deleted handle current clears CanvasKit's
105
- // current-context globals (GLctx/Module.ctx), which would otherwise
106
- // keep referencing the context (and the canvas) until another surface
107
- // becomes current. With a deleted handle this is a no-op that returns
108
- // null without creating anything.
109
- CanvasKit.MakeWebGLContext(this.contextHandle);
110
- this.contextHandle = 0;
262
+ this.restoreWanted = false;
263
+ this.release();
264
+ // Free the drawing buffer, which CanvasKit requests with depth and stencil
265
+ // attachments (about 8 bytes per pixel): a canvas that stays in the
266
+ // document without a renderer, hidden in an Activity say, would otherwise
267
+ // keep a full-size buffer around. The next renderer's onResize() sizes it
268
+ // again.
269
+ canvas.width = 0;
270
+ canvas.height = 0;
271
+ const entry = canvasWebGL.get(canvas);
272
+ if (!entry) {
273
+ return;
111
274
  }
275
+ entry.owner = null;
276
+ // Whether the element is going away is only known once the commit is
277
+ // over: on a real unmount React runs this cleanup *before* removing the
278
+ // node from the document, while StrictMode's double-invoke and an
279
+ // Activity hide keep the node in place (and the former builds the next
280
+ // renderer on it right away). Losing the context of a detached element
281
+ // matters: it would otherwise stay alive until the element is garbage
282
+ // collected, and browsers cap the number of live contexts per page
283
+ // (16 in Chrome, which then evicts the oldest one, visible or not).
284
+ queueMicrotask(() => {
285
+ if (entry.owner === null && !canvas.isConnected && !entry.gl.isContextLost()) {
286
+ var _entry$loseContext;
287
+ (_entry$loseContext = entry.loseContext) === null || _entry$loseContext === void 0 || _entry$loseContext.loseContext();
288
+ }
289
+ });
112
290
  }
113
291
  }
114
292
  class StaticWebGLRenderer {
@@ -283,21 +461,29 @@ export const SkiaPictureView = props => {
283
461
  // - The renderer is created synchronously on mount (the canvas element is
284
462
  // guaranteed to exist in useLayoutEffect; a zero size at that point is
285
463
  // fine, the surface is created once the canvas is measurable).
286
- // - Redraw requests coalesce into a single animation frame. A picture
287
- // dispatched before the canvas has a size stays in pictureRef (drawing
288
- // while unmeasured is a no-op) and is painted by the resize path below
289
- // once the canvas becomes measurable, so it is never lost.
464
+ // - Redraw requests coalesce into a single microtask. A microtask (not an
465
+ // animation frame) so that a picture produced inside a rAF callback (the
466
+ // Reanimated mapper) is drawn before the current frame paints: deferring
467
+ // to the next rAF alternates between "flush pending in this frame" and
468
+ // "flush scheduled for the next frame", drawing on every other frame
469
+ // only and halving the effective frame rate. A picture dispatched before
470
+ // the canvas has a size stays in pictureRef (drawing while unmeasured is
471
+ // a no-op) and is painted by the resize path below once the canvas
472
+ // becomes measurable, so it is never lost.
290
473
  // - A ResizeObserver on the canvas itself recreates the surface and repaints
291
474
  // synchronously (its callbacks run after layout, before paint), and is
292
475
  // also the source of the user-facing onLayout event.
476
+ // - The renderer belongs to the layout effect, the WebGL context to the
477
+ // <canvas> element, whose lifetime is longer; see WebGLRenderer for how
478
+ // the two are reconciled.
293
479
  const redrawPendingRef = useRef(false);
294
- const frameRef = useRef(0);
480
+ const flushScheduledRef = useRef(false);
295
481
  const onLayoutRef = useRef(onLayout);
296
482
  useLayoutEffect(() => {
297
483
  onLayoutRef.current = onLayout;
298
484
  }, [onLayout]);
299
485
  const flushRedraw = useCallback(() => {
300
- frameRef.current = 0;
486
+ flushScheduledRef.current = false;
301
487
  if (redrawPendingRef.current && rendererRef.current && pictureRef.current) {
302
488
  redrawPendingRef.current = false;
303
489
  rendererRef.current.draw(pictureRef.current);
@@ -307,8 +493,9 @@ export const SkiaPictureView = props => {
307
493
  }, []);
308
494
  const redraw = useCallback(() => {
309
495
  redrawPendingRef.current = true;
310
- if (frameRef.current === 0) {
311
- frameRef.current = requestAnimationFrame(flushRedraw);
496
+ if (!flushScheduledRef.current) {
497
+ flushScheduledRef.current = true;
498
+ queueMicrotask(flushRedraw);
312
499
  }
313
500
  }, [flushRedraw]);
314
501
  const getSize = useCallback(() => {
@@ -363,7 +550,7 @@ export const SkiaPictureView = props => {
363
550
  if (!canvas) {
364
551
  return undefined;
365
552
  }
366
- const renderer = isStatic ? new StaticWebGLRenderer(canvas) : new WebGLRenderer(canvas);
553
+ const renderer = isStatic ? new StaticWebGLRenderer(canvas) : new WebGLRenderer(canvas, redraw);
367
554
  rendererRef.current = renderer;
368
555
  const drawPicture = () => {
369
556
  if (pictureRef.current) {
@@ -442,13 +629,12 @@ export const SkiaPictureView = props => {
442
629
  rendererRef.current = null;
443
630
  renderer.dispose();
444
631
  };
445
- }, [isStatic]);
446
- useEffect(() => {
447
- return () => {
448
- cancelAnimationFrame(frameRef.current);
449
- frameRef.current = 0;
450
- };
451
- }, []);
632
+ }, [isStatic, redraw]);
633
+
634
+ // No flush cancellation is needed on unmount: a microtask queued before
635
+ // unmount runs within the same task, and flushRedraw no-ops once the
636
+ // layout-effect cleanup has nulled rendererRef.
637
+
452
638
  useImperativeHandle(ref, () => ({
453
639
  setPicture,
454
640
  getSize,
@@ -490,6 +676,10 @@ export const SkiaPictureView = props => {
490
676
  ...viewProps
491
677
  } = props;
492
678
  return /*#__PURE__*/React.createElement(Platform.View, viewProps, /*#__PURE__*/React.createElement("canvas", {
679
+ // A canvas element is bound to one context kind for life (WebGL for
680
+ // the live renderer, 2D for the static one), so switching renderers
681
+ // needs a fresh element.
682
+ key: isStatic ? "static" : "webgl",
493
683
  ref: canvasRef,
494
684
  style: {
495
685
  display: "block",
@@ -1 +1 @@
1
- {"version":3,"names":["React","useRef","useEffect","useCallback","useImperativeHandle","useLayoutEffect","JsiSkSurface","Platform","SkiaViewNativeId","dp2Pixel","pd","rect","undefined","x","y","width","height","WebGLRenderer","constructor","canvas","_defineProperty","contextHandle","CanvasKit","GetWebGLContext","Error","grContext","MakeWebGLContext","deleteContext","ctx","getContext","drawingBufferColorSpace","onResize","makeImageSnapshot","picture","surface","getCanvas","clear","TRANSPARENT","draw","ref","flush","_this$surface","window","devicePixelRatio","clientWidth","clientHeight","delete","MakeOnScreenGLSurface","ColorSpace","SRGB","Float32Array","of","save","scale","drawPicture","restore","dispose","_this$surface2","_this$canvas","releaseResourcesAndAbandonContext","getExtension","loseContext","StaticWebGLRenderer","cachedImage","renderPictureToSurface","tempCanvas","OffscreenCanvas","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","preventDefault","stopPropagation","isTrusted","type","SkiaPictureView","props","onLayout","canvasRef","rendererRef","pictureRef","redrawPendingRef","frameRef","onLayoutRef","current","flushRedraw","redraw","requestAnimationFrame","getSize","_canvasRef$current","_canvasRef$current2","setPicture","newPicture","measure","callback","getBoundingClientRect","parentElement","offsetParent","parentRect","left","top","pageX","scrollX","pageY","scrollY","measureInWindow","isStatic","__destroyWebGLContextAfterRender","renderer","lastWidth","lastHeight","lastPixelDensity","resizeIfNeeded","pixelDensity","observer","ResizeObserver","entries","layoutHandler","contentRect","setTimeout","observe","media","onPixelDensityChange","watchPixelDensity","_media","removeEventListener","matchMedia","query","addEventListener","_media2","disconnect","cancelAnimationFrame","_props$nativeID","nativeID","api","global","SkiaViewApi","registerView","unregisterView","debug","_debug","_ref","_onLayout","_picture","_isStatic","viewProps","createElement","View","style","display"],"sources":["SkiaPictureView.web.tsx"],"sourcesContent":["/* global HTMLCanvasElement, ResizeObserver, MediaQueryList */\nimport React, {\n useRef,\n useEffect,\n useCallback,\n useImperativeHandle,\n useLayoutEffect,\n} 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\";\nimport { Platform } from \"../Platform\";\nimport type { ISkiaViewApiWeb } from \"../specs/NativeSkiaModule.web\";\n\nimport type { SkiaPictureViewNativeProps } from \"./types\";\nimport { SkiaViewNativeId } from \"./SkiaViewNativeId\";\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\ninterface Renderer {\n onResize(): void;\n draw(picture: SkPicture): void;\n makeImageSnapshot(picture: SkPicture, rect?: SkRect): SkImage | null;\n dispose(): void;\n}\n\nclass 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\n constructor(private canvas: HTMLCanvasElement) {\n this.contextHandle = CanvasKit.GetWebGLContext(canvas);\n if (!this.contextHandle) {\n throw new Error(\"Could not create a WebGL context\");\n }\n this.grContext = CanvasKit.MakeWebGLContext(this.contextHandle);\n if (!this.grContext) {\n CanvasKit.deleteContext(this.contextHandle);\n this.contextHandle = 0;\n throw new Error(\"Could not create a graphics context\");\n }\n const ctx = canvas.getContext(\"webgl2\");\n if (ctx) {\n ctx.drawingBufferColorSpace = \"display-p3\";\n }\n this.onResize();\n }\n\n makeImageSnapshot(picture: SkPicture, rect?: SkRect): SkImage | null {\n if (!this.surface) {\n return null;\n }\n const canvas = this.surface.getCanvas();\n canvas!.clear(CanvasKit.TRANSPARENT);\n this.draw(picture);\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) {\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(picture: SkPicture) {\n if (this.surface) {\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 canvas.drawPicture(picture);\n canvas.restore();\n this.surface.ref.flush();\n }\n }\n\n dispose(): void {\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 this.canvas\n ?.getContext(\"webgl2\")\n ?.getExtension(\"WEBGL_lose_context\")\n ?.loseContext();\n if (this.contextHandle) {\n // Unregister the context from CanvasKit's internal registry, otherwise\n // it retains the canvas element (and its detached DOM tree) forever.\n CanvasKit.deleteContext(this.contextHandle);\n // Making the now-deleted handle current clears CanvasKit's\n // current-context globals (GLctx/Module.ctx), which would otherwise\n // keep referencing the context (and the canvas) until another surface\n // becomes current. With a deleted handle this is a no-op that returns\n // null without creating anything.\n CanvasKit.MakeWebGLContext(this.contextHandle);\n this.contextHandle = 0;\n }\n }\n}\n\ninterface TempRenderResult {\n surface: JsiSkSurface;\n tempCanvas: OffscreenCanvas;\n grContext: GrDirectContext;\n contextHandle: WebGLContextHandle;\n}\n\nclass 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 renderPictureToSurface(picture: SkPicture): 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 skiaCanvas.drawPicture(picture);\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(picture: SkPicture): void {\n const renderResult = this.renderPictureToSurface(picture);\n if (!renderResult) {\n return;\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 }\n\n makeImageSnapshot(picture: SkPicture, rect?: SkRect): SkImage | null {\n if (!this.cachedImage) {\n const renderResult = this.renderPictureToSurface(picture);\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.\nconst 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 SkiaPictureViewHandle {\n setPicture(picture: SkPicture): void;\n getSize(): { width: number; height: number };\n redraw(): void;\n makeImageSnapshot(rect?: SkRect): SkImage | null;\n measure(\n callback: (\n x: number,\n y: number,\n width: number,\n height: number,\n pageX: number,\n pageY: number\n ) => void\n ): void;\n measureInWindow(\n callback: (x: number, y: number, width: number, height: number) => void\n ): void;\n}\n\nexport interface SkiaPictureViewProps extends SkiaPictureViewNativeProps {\n ref?: React.Ref<SkiaPictureViewHandle>;\n}\n\nexport const SkiaPictureView = (props: SkiaPictureViewProps) => {\n const { ref, picture, onLayout } = props;\n const canvasRef = useRef<HTMLCanvasElement | null>(null);\n const rendererRef = useRef<Renderer | null>(null);\n const pictureRef = useRef<SkPicture | null>(null);\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 // - Redraw requests coalesce into a single animation frame. A picture\n // dispatched before the canvas has a size stays in pictureRef (drawing\n // while unmeasured is a no-op) and is painted by the resize path below\n // once the canvas becomes measurable, so it is never lost.\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 const redrawPendingRef = useRef(false);\n const frameRef = useRef(0);\n const onLayoutRef = useRef(onLayout);\n useLayoutEffect(() => {\n onLayoutRef.current = onLayout;\n }, [onLayout]);\n\n const flushRedraw = useCallback(() => {\n frameRef.current = 0;\n if (redrawPendingRef.current && rendererRef.current && pictureRef.current) {\n redrawPendingRef.current = false;\n rendererRef.current.draw(pictureRef.current);\n }\n // If the renderer or picture isn't available yet, the request stays\n // pending and is flushed by whichever arrives last.\n }, []);\n\n const redraw = useCallback(() => {\n redrawPendingRef.current = true;\n if (frameRef.current === 0) {\n frameRef.current = requestAnimationFrame(flushRedraw);\n }\n }, [flushRedraw]);\n\n const getSize = useCallback(() => {\n return {\n width: canvasRef.current?.clientWidth || 0,\n height: canvasRef.current?.clientHeight || 0,\n };\n }, []);\n\n const setPicture = useCallback(\n (newPicture: SkPicture) => {\n pictureRef.current = newPicture;\n redraw();\n },\n [redraw]\n );\n\n const makeImageSnapshot = useCallback((rect?: SkRect) => {\n if (rendererRef.current && pictureRef.current) {\n return rendererRef.current.makeImageSnapshot(pictureRef.current, rect);\n }\n return null;\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\n // x, y are relative to the parent\n const x = rect.left - parentRect.left;\n const y = rect.top - parentRect.top;\n\n // pageX, pageY are absolute screen coordinates\n const pageX = rect.left + window.scrollX;\n const pageY = rect.top + window.scrollY;\n\n callback(x, y, rect.width, rect.height, pageX, pageY);\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\n // x, y are the absolute coordinates in the window\n const x = rect.left;\n const y = rect.top;\n\n callback(x, y, rect.width, rect.height);\n }\n },\n []\n );\n\n const isStatic = props.__destroyWebGLContextAfterRender === true;\n\n useLayoutEffect(() => {\n const canvas = canvasRef.current;\n if (!canvas) {\n return undefined;\n }\n const renderer = isStatic\n ? new StaticWebGLRenderer(canvas)\n : new WebGLRenderer(canvas);\n rendererRef.current = renderer;\n\n const drawPicture = () => {\n if (pictureRef.current) {\n redrawPendingRef.current = false;\n renderer.draw(pictureRef.current);\n }\n };\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 drawPicture();\n };\n\n const observer = new ResizeObserver((entries) => {\n resizeIfNeeded();\n const layoutHandler = onLayoutRef.current;\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 picture that was dispatched before the renderer existed.\n drawPicture();\n\n return () => {\n observer.disconnect();\n media?.removeEventListener(\"change\", onPixelDensityChange);\n rendererRef.current = null;\n renderer.dispose();\n };\n }, [isStatic]);\n\n useEffect(() => {\n return () => {\n cancelAnimationFrame(frameRef.current);\n frameRef.current = 0;\n };\n }, []);\n\n useImperativeHandle(\n ref,\n () => ({\n setPicture,\n getSize,\n redraw,\n makeImageSnapshot,\n measure,\n measureInWindow,\n get canvasRef() {\n return () => canvasRef.current;\n },\n }),\n [setPicture, getSize, redraw, makeImageSnapshot, measure, measureInWindow]\n );\n\n useEffect(() => {\n const nativeID = props.nativeID ?? `${SkiaViewNativeId.current++}`;\n const api = global.SkiaViewApi as ISkiaViewApiWeb;\n api.registerView(nativeID, {\n setPicture,\n getSize,\n redraw,\n makeImageSnapshot,\n measure,\n measureInWindow,\n } as SkiaPictureViewHandle);\n return () => {\n api.unregisterView(nativeID);\n };\n }, [\n setPicture,\n getSize,\n redraw,\n makeImageSnapshot,\n measure,\n measureInWindow,\n props.nativeID,\n ]);\n\n useEffect(() => {\n if (picture) {\n setPicture(picture);\n }\n }, [setPicture, picture]);\n\n const {\n debug: _debug,\n ref: _ref,\n onLayout: _onLayout,\n picture: _picture,\n __destroyWebGLContextAfterRender: _isStatic,\n ...viewProps\n } = props;\n return (\n <Platform.View {...viewProps}>\n <canvas\n ref={canvasRef}\n style={{ display: \"block\", width: \"100%\", height: \"100%\" }}\n />\n </Platform.View>\n );\n};\n"],"mappings":";;;AAAA;AACA,OAAOA,KAAK,IACVC,MAAM,EACNC,SAAS,EACTC,WAAW,EACXC,mBAAmB,EACnBC,eAAe,QACV,OAAO;AAKd,SAASC,YAAY,QAAQ,0BAA0B;AACvD,SAASC,QAAQ,QAAQ,aAAa;AAItC,SAASC,gBAAgB,QAAQ,oBAAoB;AAErD,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,M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C;EACH,CAAC,EAAE,CACD1C,UAAU,EACVH,OAAO,EACPF,MAAM,EACN7E,iBAAiB,EACjBoF,OAAO,EACPY,eAAe,EACf7B,KAAK,CAACyD,QAAQ,CACf,CAAC;EAEF1J,SAAS,CAAC,MAAM;IACd,IAAI+B,OAAO,EAAE;MACXiF,UAAU,CAACjF,OAAO,CAAC;IACrB;EACF,CAAC,EAAE,CAACiF,UAAU,EAAEjF,OAAO,CAAC,CAAC;EAEzB,MAAM;IACJiI,KAAK,EAAEC,MAAM;IACb5H,GAAG,EAAE6H,IAAI;IACThE,QAAQ,EAAEiE,SAAS;IACnBpI,OAAO,EAAEqI,QAAQ;IACjBpC,gCAAgC,EAAEqC,SAAS;IAC3C,GAAGC;EACL,CAAC,GAAGrE,KAAK;EACT,oBACEnG,KAAA,CAAAyK,aAAA,CAAClK,QAAQ,CAACmK,IAAI,EAAKF,SAAS,eAC1BxK,KAAA,CAAAyK,aAAA;IACElI,GAAG,EAAE8D,SAAU;IACfsE,KAAK,EAAE;MAAEC,OAAO,EAAE,OAAO;MAAE7J,KAAK,EAAE,MAAM;MAAEC,MAAM,EAAE;IAAO;EAAE,CAC5D,CACY,CAAC;AAEpB,CAAC","ignoreList":[]}
1
+ {"version":3,"names":["React","useRef","useEffect","useCallback","useImperativeHandle","useLayoutEffect","JsiSkSurface","Platform","SkiaViewNativeId","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","picture","getCanvas","clear","TRANSPARENT","draw","flush","_this$surface2","window","devicePixelRatio","clientWidth","clientHeight","MakeOnScreenGLSurface","ColorSpace","SRGB","Float32Array","of","save","scale","drawPicture","restore","dispose","removeEventListener","clearTimeout","queueMicrotask","isConnected","_entry$loseContext","StaticWebGLRenderer","cachedImage","renderPictureToSurface","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","SkiaPictureView","props","onLayout","canvasRef","rendererRef","pictureRef","redrawPendingRef","flushScheduledRef","onLayoutRef","current","flushRedraw","redraw","getSize","_canvasRef$current","_canvasRef$current2","setPicture","newPicture","measure","callback","getBoundingClientRect","parentElement","offsetParent","parentRect","left","top","pageX","scrollX","pageY","scrollY","measureInWindow","isStatic","__destroyWebGLContextAfterRender","renderer","lastWidth","lastHeight","lastPixelDensity","resizeIfNeeded","pixelDensity","observer","ResizeObserver","entries","layoutHandler","contentRect","observe","media","onPixelDensityChange","watchPixelDensity","_media","matchMedia","query","_media2","disconnect","_props$nativeID","nativeID","api","global","SkiaViewApi","registerView","unregisterView","debug","_debug","_ref","_onLayout","_picture","_isStatic","viewProps","createElement","View","key","style","display"],"sources":["SkiaPictureView.web.tsx"],"sourcesContent":["/* global HTMLCanvasElement, ResizeObserver, MediaQueryList */\nimport React, {\n useRef,\n useEffect,\n useCallback,\n useImperativeHandle,\n useLayoutEffect,\n} 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\";\nimport { Platform } from \"../Platform\";\nimport type { ISkiaViewApiWeb } from \"../specs/NativeSkiaModule.web\";\n\nimport type { SkiaPictureViewNativeProps } from \"./types\";\nimport { SkiaViewNativeId } from \"./SkiaViewNativeId\";\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\ninterface Renderer {\n onResize(): void;\n draw(picture: SkPicture): void;\n makeImageSnapshot(picture: SkPicture, 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\nclass 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 // picture 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(picture: SkPicture, 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(picture);\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(picture: SkPicture) {\n if (!this.surface || this.isContextLost()) {\n return;\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 canvas.drawPicture(picture);\n canvas.restore();\n this.surface.ref.flush();\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\nclass 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 renderPictureToSurface(picture: SkPicture): 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 skiaCanvas.drawPicture(picture);\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(picture: SkPicture): void {\n const renderResult = this.renderPictureToSurface(picture);\n if (!renderResult) {\n return;\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 }\n\n makeImageSnapshot(picture: SkPicture, rect?: SkRect): SkImage | null {\n if (!this.cachedImage) {\n const renderResult = this.renderPictureToSurface(picture);\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.\nconst 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 SkiaPictureViewHandle {\n setPicture(picture: SkPicture): void;\n getSize(): { width: number; height: number };\n redraw(): void;\n makeImageSnapshot(rect?: SkRect): SkImage | null;\n measure(\n callback: (\n x: number,\n y: number,\n width: number,\n height: number,\n pageX: number,\n pageY: number\n ) => void\n ): void;\n measureInWindow(\n callback: (x: number, y: number, width: number, height: number) => void\n ): void;\n}\n\nexport interface SkiaPictureViewProps extends SkiaPictureViewNativeProps {\n ref?: React.Ref<SkiaPictureViewHandle>;\n}\n\nexport const SkiaPictureView = (props: SkiaPictureViewProps) => {\n const { ref, picture, onLayout } = props;\n const canvasRef = useRef<HTMLCanvasElement | null>(null);\n const rendererRef = useRef<Renderer | null>(null);\n const pictureRef = useRef<SkPicture | null>(null);\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 // - Redraw requests coalesce into a single microtask. A microtask (not an\n // animation frame) so that a picture produced inside a rAF callback (the\n // Reanimated mapper) is drawn before the current frame paints: deferring\n // to the next rAF alternates between \"flush pending in this frame\" and\n // \"flush scheduled for the next frame\", drawing on every other frame\n // only and halving the effective frame rate. A picture dispatched before\n // the canvas has a size stays in pictureRef (drawing while unmeasured is\n // a no-op) and is painted by the resize path below once the canvas\n // becomes measurable, so it is never lost.\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 const redrawPendingRef = useRef(false);\n const flushScheduledRef = useRef(false);\n const onLayoutRef = useRef(onLayout);\n useLayoutEffect(() => {\n onLayoutRef.current = onLayout;\n }, [onLayout]);\n\n const flushRedraw = useCallback(() => {\n flushScheduledRef.current = false;\n if (redrawPendingRef.current && rendererRef.current && pictureRef.current) {\n redrawPendingRef.current = false;\n rendererRef.current.draw(pictureRef.current);\n }\n // If the renderer or picture isn't available yet, the request stays\n // pending and is flushed by whichever arrives last.\n }, []);\n\n const redraw = useCallback(() => {\n redrawPendingRef.current = true;\n if (!flushScheduledRef.current) {\n flushScheduledRef.current = true;\n queueMicrotask(flushRedraw);\n }\n }, [flushRedraw]);\n\n const getSize = useCallback(() => {\n return {\n width: canvasRef.current?.clientWidth || 0,\n height: canvasRef.current?.clientHeight || 0,\n };\n }, []);\n\n const setPicture = useCallback(\n (newPicture: SkPicture) => {\n pictureRef.current = newPicture;\n redraw();\n },\n [redraw]\n );\n\n const makeImageSnapshot = useCallback((rect?: SkRect) => {\n if (rendererRef.current && pictureRef.current) {\n return rendererRef.current.makeImageSnapshot(pictureRef.current, rect);\n }\n return null;\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\n // x, y are relative to the parent\n const x = rect.left - parentRect.left;\n const y = rect.top - parentRect.top;\n\n // pageX, pageY are absolute screen coordinates\n const pageX = rect.left + window.scrollX;\n const pageY = rect.top + window.scrollY;\n\n callback(x, y, rect.width, rect.height, pageX, pageY);\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\n // x, y are the absolute coordinates in the window\n const x = rect.left;\n const y = rect.top;\n\n callback(x, y, rect.width, rect.height);\n }\n },\n []\n );\n\n const isStatic = props.__destroyWebGLContextAfterRender === true;\n\n useLayoutEffect(() => {\n const canvas = canvasRef.current;\n if (!canvas) {\n return undefined;\n }\n const renderer = isStatic\n ? new StaticWebGLRenderer(canvas)\n : new WebGLRenderer(canvas, redraw);\n rendererRef.current = renderer;\n\n const drawPicture = () => {\n if (pictureRef.current) {\n redrawPendingRef.current = false;\n renderer.draw(pictureRef.current);\n }\n };\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 drawPicture();\n };\n\n const observer = new ResizeObserver((entries) => {\n resizeIfNeeded();\n const layoutHandler = onLayoutRef.current;\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 picture that was dispatched before the renderer existed.\n drawPicture();\n\n return () => {\n observer.disconnect();\n media?.removeEventListener(\"change\", onPixelDensityChange);\n rendererRef.current = null;\n renderer.dispose();\n };\n }, [isStatic, redraw]);\n\n // No flush cancellation is needed on unmount: a microtask queued before\n // unmount runs within the same task, and flushRedraw no-ops once the\n // layout-effect cleanup has nulled rendererRef.\n\n useImperativeHandle(\n ref,\n () => ({\n setPicture,\n getSize,\n redraw,\n makeImageSnapshot,\n measure,\n measureInWindow,\n get canvasRef() {\n return () => canvasRef.current;\n },\n }),\n [setPicture, getSize, redraw, makeImageSnapshot, measure, measureInWindow]\n );\n\n useEffect(() => {\n const nativeID = props.nativeID ?? `${SkiaViewNativeId.current++}`;\n const api = global.SkiaViewApi as ISkiaViewApiWeb;\n api.registerView(nativeID, {\n setPicture,\n getSize,\n redraw,\n makeImageSnapshot,\n measure,\n measureInWindow,\n } as SkiaPictureViewHandle);\n return () => {\n api.unregisterView(nativeID);\n };\n }, [\n setPicture,\n getSize,\n redraw,\n makeImageSnapshot,\n measure,\n measureInWindow,\n props.nativeID,\n ]);\n\n useEffect(() => {\n if (picture) {\n setPicture(picture);\n }\n }, [setPicture, picture]);\n\n const {\n debug: _debug,\n ref: _ref,\n onLayout: _onLayout,\n picture: _picture,\n __destroyWebGLContextAfterRender: _isStatic,\n ...viewProps\n } = props;\n return (\n <Platform.View {...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%\" }}\n />\n </Platform.View>\n );\n};\n"],"mappings":";;;AAAA;AACA,OAAOA,KAAK,IACVC,MAAM,EACNC,SAAS,EACTC,WAAW,EACXC,mBAAmB,EACnBC,eAAe,QACV,OAAO;AAKd,SAASC,YAAY,QAAQ,0BAA0B;AACvD,SAASC,QAAQ,QAAQ,aAAa;AAItC,SAASC,gBAAgB,QAAQ,oBAAoB;AAErD,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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