@shopify/react-native-skia 2.6.5 → 2.6.7

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 (279) hide show
  1. package/android/CMakeLists.txt +2 -2
  2. package/android/src/paper/java/com/facebook/react/viewmanagers/SkiaWebGPUViewManagerDelegate.java +35 -0
  3. package/android/src/paper/java/com/facebook/react/viewmanagers/SkiaWebGPUViewManagerInterface.java +17 -0
  4. package/apple/RNSkiaModule.mm +8 -2
  5. package/apple/SkiaManager.mm +10 -5
  6. package/cpp/api/JsiSkApi.h +6 -6
  7. package/cpp/api/JsiSkCanvas.h +33 -0
  8. package/cpp/api/JsiSkImage.h +12 -4
  9. package/cpp/api/JsiSkMaskFilter.h +1 -0
  10. package/cpp/api/JsiSkSurface.h +5 -1
  11. package/cpp/jsi2/NativeObject.h +39 -0
  12. package/cpp/rnskia/RNSkManager.cpp +27 -11
  13. package/cpp/rnwgpu/SurfaceRegistry.h +33 -1
  14. package/cpp/rnwgpu/api/GPU.cpp +15 -15
  15. package/cpp/rnwgpu/api/GPU.h +6 -3
  16. package/cpp/rnwgpu/api/GPUAdapter.cpp +11 -7
  17. package/cpp/rnwgpu/api/GPUAdapter.h +3 -3
  18. package/cpp/rnwgpu/api/GPUBuffer.h +3 -3
  19. package/cpp/rnwgpu/api/GPUCanvasContext.cpp +13 -16
  20. package/cpp/rnwgpu/api/GPUCanvasContext.h +3 -0
  21. package/cpp/rnwgpu/api/GPUDevice.cpp +103 -17
  22. package/cpp/rnwgpu/api/GPUDevice.h +18 -3
  23. package/cpp/rnwgpu/api/GPUQueue.h +3 -3
  24. package/cpp/rnwgpu/api/GPUShaderModule.cpp +1 -1
  25. package/cpp/rnwgpu/api/GPUShaderModule.h +3 -3
  26. package/cpp/rnwgpu/api/GPUSharedFence.cpp +80 -0
  27. package/cpp/rnwgpu/api/GPUSharedFence.h +53 -0
  28. package/cpp/rnwgpu/api/GPUSharedTextureMemory.cpp +64 -11
  29. package/cpp/rnwgpu/api/GPUSharedTextureMemory.h +13 -8
  30. package/cpp/rnwgpu/api/WebGPUConstants.h +36 -0
  31. package/cpp/rnwgpu/api/descriptors/GPUSharedFenceDescriptor.h +58 -0
  32. package/cpp/rnwgpu/api/descriptors/GPUSharedFenceState.h +51 -0
  33. package/cpp/rnwgpu/async/AsyncTaskHandle.cpp +55 -22
  34. package/cpp/rnwgpu/async/AsyncTaskHandle.h +8 -5
  35. package/cpp/rnwgpu/async/RuntimeContext.cpp +194 -0
  36. package/cpp/rnwgpu/async/RuntimeContext.h +121 -0
  37. package/cpp/skia/include/android/GrAHardwareBufferUtils.h +1 -1
  38. package/cpp/skia/include/android/SkAndroidFrameworkUtils.h +1 -1
  39. package/cpp/skia/include/android/SkAnimatedImage.h +1 -1
  40. package/cpp/skia/include/codec/SkCodec.h +0 -8
  41. package/cpp/skia/include/codec/SkEncodedOrigin.h +1 -1
  42. package/cpp/skia/include/codec/SkPngRustDecoder.h +1 -1
  43. package/cpp/skia/include/core/SkBitmap.h +2 -8
  44. package/cpp/skia/include/core/SkCPURecorder.h +3 -1
  45. package/cpp/skia/include/core/SkCanvasVirtualEnforcer.h +1 -1
  46. package/cpp/skia/include/core/SkColorType.h +5 -3
  47. package/cpp/skia/include/core/SkContourMeasure.h +1 -1
  48. package/cpp/skia/include/core/SkCoverageMode.h +1 -1
  49. package/cpp/skia/include/core/SkCubicMap.h +1 -1
  50. package/cpp/skia/include/core/SkExecutor.h +1 -1
  51. package/cpp/skia/include/core/SkFont.h +15 -0
  52. package/cpp/skia/include/core/SkFontArguments.h +6 -1
  53. package/cpp/skia/include/core/SkFontMetrics.h +1 -1
  54. package/cpp/skia/include/core/SkFontMgr.h +36 -1
  55. package/cpp/skia/include/core/SkFontParameters.h +1 -1
  56. package/cpp/skia/include/core/SkFontScanner.h +1 -1
  57. package/cpp/skia/include/core/SkFontTypes.h +1 -1
  58. package/cpp/skia/include/core/SkM44.h +1 -1
  59. package/cpp/skia/include/core/SkMilestone.h +1 -1
  60. package/cpp/skia/include/core/SkOpenTypeSVGDecoder.h +1 -1
  61. package/cpp/skia/include/core/SkPathBuilder.h +10 -4
  62. package/cpp/skia/include/core/SkPathIter.h +1 -1
  63. package/cpp/skia/include/core/SkPathTypes.h +1 -1
  64. package/cpp/skia/include/core/SkPixelRef.h +4 -1
  65. package/cpp/skia/include/core/SkRecorder.h +2 -1
  66. package/cpp/skia/include/core/SkRegion.h +7 -1
  67. package/cpp/skia/include/core/SkSamplingOptions.h +1 -1
  68. package/cpp/skia/include/core/SkSerialProcs.h +8 -1
  69. package/cpp/skia/include/core/SkShader.h +3 -5
  70. package/cpp/skia/include/core/SkSpan.h +1 -1
  71. package/cpp/skia/include/core/SkStream.h +1 -1
  72. package/cpp/skia/include/core/SkStrikeRef.h +80 -0
  73. package/cpp/skia/include/core/SkTileMode.h +1 -1
  74. package/cpp/skia/include/core/SkVertices.h +1 -1
  75. package/cpp/skia/include/core/SkYUVAPixmaps.h +3 -5
  76. package/cpp/skia/include/docs/SkPDFDocument.h +1 -1
  77. package/cpp/skia/include/docs/SkXPSDocument.h +1 -1
  78. package/cpp/skia/include/effects/SkGradient.h +1 -1
  79. package/cpp/skia/include/effects/SkHighContrastFilter.h +1 -1
  80. package/cpp/skia/include/effects/SkShaderMaskFilter.h +1 -1
  81. package/cpp/skia/include/effects/SkTrimPathEffect.h +1 -1
  82. package/cpp/skia/include/encode/SkEncoder.h +1 -1
  83. package/cpp/skia/include/encode/SkJpegEncoder.h +1 -1
  84. package/cpp/skia/include/encode/SkPngEncoder.h +1 -1
  85. package/cpp/skia/include/encode/SkPngRustEncoder.h +1 -1
  86. package/cpp/skia/include/encode/SkWebpEncoder.h +1 -1
  87. package/cpp/skia/include/gpu/GpuTypes.h +2 -0
  88. package/cpp/skia/include/gpu/MutableTextureState.h +1 -1
  89. package/cpp/skia/include/gpu/ganesh/GrBackendSemaphore.h +1 -1
  90. package/cpp/skia/include/gpu/ganesh/GrBackendSurface.h +6 -62
  91. package/cpp/skia/include/gpu/ganesh/GrContextThreadSafeProxy.h +1 -1
  92. package/cpp/skia/include/gpu/ganesh/GrDirectContext.h +1 -1
  93. package/cpp/skia/include/gpu/ganesh/GrDriverBugWorkarounds.h +1 -1
  94. package/cpp/skia/include/gpu/ganesh/GrRecordingContext.h +2 -1
  95. package/cpp/skia/include/gpu/ganesh/mock/GrMockBackendSurface.h +59 -0
  96. package/cpp/skia/include/gpu/ganesh/mock/GrMockTypes.h +1 -1
  97. package/cpp/skia/include/gpu/ganesh/mtl/GrMtlBackendContext.h +1 -1
  98. package/cpp/skia/include/gpu/ganesh/mtl/GrMtlTypes.h +1 -1
  99. package/cpp/skia/include/gpu/ganesh/vk/GrBackendDrawableInfo.h +1 -1
  100. package/cpp/skia/include/gpu/graphite/Context.h +11 -4
  101. package/cpp/skia/include/gpu/graphite/GraphiteTypes.h +6 -0
  102. package/cpp/skia/include/gpu/graphite/Image.h +82 -9
  103. package/cpp/skia/include/gpu/graphite/PrecompileContext.h +7 -2
  104. package/cpp/skia/include/gpu/graphite/Recorder.h +6 -4
  105. package/cpp/skia/include/gpu/graphite/precompile/PrecompileColorFilter.h +11 -1
  106. package/cpp/skia/include/gpu/graphite/precompile/PrecompileShader.h +1 -0
  107. package/cpp/skia/include/gpu/graphite/vk/VulkanGraphiteTypes.h +1 -1
  108. package/cpp/skia/include/gpu/mtl/MtlMemoryAllocator.h +1 -1
  109. package/cpp/skia/include/gpu/vk/VulkanExtensions.h +1 -1
  110. package/cpp/skia/include/gpu/vk/VulkanMemoryAllocator.h +1 -1
  111. package/cpp/skia/include/gpu/vk/VulkanTypes.h +1 -1
  112. package/cpp/skia/include/ports/SkCFObject.h +1 -1
  113. package/cpp/skia/include/ports/SkFontMgr_Fontations.h +1 -1
  114. package/cpp/skia/include/ports/SkFontMgr_android_ndk.h +1 -1
  115. package/cpp/skia/include/ports/SkFontMgr_data.h +1 -1
  116. package/cpp/skia/include/ports/SkFontMgr_fuchsia.h +1 -1
  117. package/cpp/skia/include/ports/SkFontMgr_mac_ct.h +1 -1
  118. package/cpp/skia/include/ports/SkFontScanner_Fontations.h +1 -1
  119. package/cpp/skia/include/ports/SkFontScanner_FreeType.h +1 -1
  120. package/cpp/skia/include/ports/SkTypeface_fontations.h +1 -1
  121. package/cpp/skia/include/private/SkExif.h +1 -1
  122. package/cpp/skia/include/private/SkGainmapInfo.h +1 -1
  123. package/cpp/skia/include/private/SkGainmapShader.h +1 -1
  124. package/cpp/skia/include/private/SkHdrMetadata.h +21 -0
  125. package/cpp/skia/include/private/SkJpegGainmapEncoder.h +1 -1
  126. package/cpp/skia/include/private/SkPixelStorage.h +37 -0
  127. package/cpp/skia/include/private/SkXmp.h +1 -1
  128. package/cpp/skia/include/private/base/SkAssert.h +6 -5
  129. package/cpp/skia/include/private/base/SkContainers.h +1 -1
  130. package/cpp/skia/include/private/base/SkFeatures.h +30 -30
  131. package/cpp/skia/include/private/base/SkLog.h +1 -7
  132. package/cpp/skia/include/private/base/SkLogPriority.h +4 -5
  133. package/cpp/skia/include/private/base/SkMacros.h +1 -1
  134. package/cpp/skia/include/private/base/SkMalloc.h +1 -1
  135. package/cpp/skia/include/private/base/SkSafe32.h +1 -1
  136. package/cpp/skia/include/private/base/SkSpan_impl.h +1 -1
  137. package/cpp/skia/include/private/base/SkTDArray.h +13 -1
  138. package/cpp/skia/include/private/base/SkTPin.h +1 -1
  139. package/cpp/skia/include/private/base/SkTo.h +1 -1
  140. package/cpp/skia/include/private/chromium/GrVkSecondaryCBDrawContext.h +1 -1
  141. package/cpp/skia/include/private/chromium/SkChromeRemoteGlyphCache.h +1 -1
  142. package/cpp/skia/include/private/chromium/SkCodecsICCProfileChromium.h +52 -0
  143. package/cpp/skia/include/private/chromium/SkExifChromium.h +26 -0
  144. package/cpp/skia/include/private/gpu/ganesh/GrContext_Base.h +1 -1
  145. package/cpp/skia/include/private/gpu/ganesh/GrImageContext.h +1 -1
  146. package/cpp/skia/include/private/gpu/ganesh/GrTypesPriv.h +2 -1
  147. package/cpp/skia/include/private/gpu/vk/SkiaVulkan.h +1 -1
  148. package/cpp/skia/include/sksl/SkSLDebugTrace.h +1 -1
  149. package/cpp/skia/include/third_party/vulkan/vulkan/vk_icd.h +41 -51
  150. package/cpp/skia/include/third_party/vulkan/vulkan/vk_layer.h +42 -53
  151. package/cpp/skia/include/third_party/vulkan/vulkan/vk_platform.h +2 -1
  152. package/cpp/skia/include/third_party/vulkan/vulkan/vk_video/vulkan_video_codec_av1std.h +158 -154
  153. package/cpp/skia/include/third_party/vulkan/vulkan/vk_video/vulkan_video_codec_av1std_decode.h +68 -65
  154. package/cpp/skia/include/third_party/vulkan/vulkan/vk_video/vulkan_video_codec_av1std_encode.h +90 -87
  155. package/cpp/skia/include/third_party/vulkan/vulkan/vk_video/vulkan_video_codec_h264std.h +9 -9
  156. package/cpp/skia/include/third_party/vulkan/vulkan/vk_video/vulkan_video_codec_h264std_decode.h +2 -2
  157. package/cpp/skia/include/third_party/vulkan/vulkan/vk_video/vulkan_video_codec_h264std_encode.h +82 -79
  158. package/cpp/skia/include/third_party/vulkan/vulkan/vk_video/vulkan_video_codec_h265std.h +24 -24
  159. package/cpp/skia/include/third_party/vulkan/vulkan/vk_video/vulkan_video_codec_h265std_decode.h +2 -2
  160. package/cpp/skia/include/third_party/vulkan/vulkan/vk_video/vulkan_video_codec_h265std_encode.h +95 -96
  161. package/cpp/skia/include/third_party/vulkan/vulkan/vk_video/vulkan_video_codec_vp9std.h +151 -0
  162. package/cpp/skia/include/third_party/vulkan/vulkan/vk_video/vulkan_video_codec_vp9std_decode.h +68 -0
  163. package/cpp/skia/include/third_party/vulkan/vulkan/vk_video/vulkan_video_codecs_common.h +1 -1
  164. package/cpp/skia/include/third_party/vulkan/vulkan/vulkan.h +5 -1
  165. package/cpp/skia/include/third_party/vulkan/vulkan/vulkan_android.h +7 -1
  166. package/cpp/skia/include/third_party/vulkan/vulkan/vulkan_beta.h +291 -158
  167. package/cpp/skia/include/third_party/vulkan/vulkan/vulkan_core.h +13174 -10113
  168. package/cpp/skia/include/third_party/vulkan/vulkan/vulkan_directfb.h +23 -19
  169. package/cpp/skia/include/third_party/vulkan/vulkan/vulkan_fuchsia.h +159 -165
  170. package/cpp/skia/include/third_party/vulkan/vulkan/vulkan_ggp.h +22 -19
  171. package/cpp/skia/include/third_party/vulkan/vulkan/vulkan_ios.h +3 -1
  172. package/cpp/skia/include/third_party/vulkan/vulkan/vulkan_macos.h +3 -1
  173. package/cpp/skia/include/third_party/vulkan/vulkan/vulkan_metal.h +94 -88
  174. package/cpp/skia/include/third_party/vulkan/vulkan/vulkan_ohos.h +120 -0
  175. package/cpp/skia/include/third_party/vulkan/vulkan/vulkan_screen.h +55 -51
  176. package/cpp/skia/include/third_party/vulkan/vulkan/vulkan_vi.h +18 -15
  177. package/cpp/skia/include/third_party/vulkan/vulkan/vulkan_wayland.h +23 -19
  178. package/cpp/skia/include/third_party/vulkan/vulkan/vulkan_win32.h +31 -1
  179. package/cpp/skia/include/third_party/vulkan/vulkan/vulkan_xcb.h +5 -1
  180. package/cpp/skia/include/third_party/vulkan/vulkan/vulkan_xlib.h +27 -27
  181. package/cpp/skia/include/third_party/vulkan/vulkan/vulkan_xlib_xrandr.h +20 -16
  182. package/cpp/skia/include/utils/SkEventTracer.h +6 -1
  183. package/cpp/skia/include/utils/SkOrderedFontMgr.h +1 -1
  184. package/cpp/skia/include/utils/SkShadowUtils.h +1 -1
  185. package/cpp/skia/include/utils/SkTextUtils.h +1 -1
  186. package/cpp/skia/modules/jsonreader/SkJSONReader.cpp +20 -4
  187. package/cpp/skia/modules/skcms/src/Transform_inl.h +11 -15
  188. package/cpp/skia/modules/skcms/src/skcms_public.h +2 -0
  189. package/cpp/skia/modules/skottie/include/ExternalLayer.h +1 -1
  190. package/cpp/skia/modules/skottie/include/Skottie.h +1 -1
  191. package/cpp/skia/modules/skottie/include/SkottieProperty.h +1 -1
  192. package/cpp/skia/modules/skottie/include/SlotManager.h +1 -1
  193. package/cpp/skia/modules/skottie/include/TextShaper.h +1 -1
  194. package/cpp/skia/modules/skottie/src/SkottieValue.h +1 -1
  195. package/cpp/skia/modules/skottie/src/animator/Animator.h +1 -1
  196. package/cpp/skia/modules/skottie/src/text/Font.h +1 -1
  197. package/cpp/skia/modules/skottie/src/text/TextAdapter.h +1 -1
  198. package/cpp/skia/modules/skottie/src/text/TextAnimator.h +3 -2
  199. package/cpp/skia/modules/skottie/src/text/TextValue.h +1 -1
  200. package/cpp/skia/modules/skparagraph/include/DartTypes.h +1 -1
  201. package/cpp/skia/modules/skparagraph/include/FontArguments.h +1 -1
  202. package/cpp/skia/modules/skparagraph/include/FontCollection.h +5 -1
  203. package/cpp/skia/modules/skparagraph/include/Metrics.h +1 -1
  204. package/cpp/skia/modules/skparagraph/include/Paragraph.h +1 -1
  205. package/cpp/skia/modules/skparagraph/include/ParagraphBuilder.h +1 -1
  206. package/cpp/skia/modules/skparagraph/include/ParagraphCache.h +1 -1
  207. package/cpp/skia/modules/skparagraph/include/ParagraphPainter.h +1 -1
  208. package/cpp/skia/modules/skparagraph/include/ParagraphStyle.h +12 -5
  209. package/cpp/skia/modules/skparagraph/include/TextShadow.h +1 -1
  210. package/cpp/skia/modules/skparagraph/include/TextStyle.h +1 -1
  211. package/cpp/skia/modules/skparagraph/include/TypefaceFontProvider.h +1 -1
  212. package/cpp/skia/modules/sksg/include/SkSGClipEffect.h +1 -1
  213. package/cpp/skia/modules/sksg/include/SkSGColorFilter.h +1 -1
  214. package/cpp/skia/modules/sksg/include/SkSGDraw.h +1 -1
  215. package/cpp/skia/modules/sksg/include/SkSGEffectNode.h +1 -1
  216. package/cpp/skia/modules/sksg/include/SkSGGeometryEffect.h +1 -1
  217. package/cpp/skia/modules/sksg/include/SkSGGeometryNode.h +1 -1
  218. package/cpp/skia/modules/sksg/include/SkSGGradient.h +1 -1
  219. package/cpp/skia/modules/sksg/include/SkSGGroup.h +1 -1
  220. package/cpp/skia/modules/sksg/include/SkSGImage.h +1 -1
  221. package/cpp/skia/modules/sksg/include/SkSGInvalidationController.h +1 -1
  222. package/cpp/skia/modules/sksg/include/SkSGMaskEffect.h +1 -1
  223. package/cpp/skia/modules/sksg/include/SkSGMerge.h +1 -1
  224. package/cpp/skia/modules/sksg/include/SkSGNode.h +1 -1
  225. package/cpp/skia/modules/sksg/include/SkSGOpacityEffect.h +1 -1
  226. package/cpp/skia/modules/sksg/include/SkSGPaint.h +1 -1
  227. package/cpp/skia/modules/sksg/include/SkSGPath.h +1 -1
  228. package/cpp/skia/modules/sksg/include/SkSGPlane.h +1 -1
  229. package/cpp/skia/modules/sksg/include/SkSGRect.h +1 -1
  230. package/cpp/skia/modules/sksg/include/SkSGRenderEffect.h +1 -1
  231. package/cpp/skia/modules/sksg/include/SkSGRenderNode.h +1 -1
  232. package/cpp/skia/modules/sksg/include/SkSGScene.h +1 -1
  233. package/cpp/skia/modules/sksg/include/SkSGText.h +1 -1
  234. package/cpp/skia/modules/sksg/include/SkSGTransform.h +1 -1
  235. package/cpp/skia/modules/skshaper/include/SkShaper_coretext.h +8 -1
  236. package/cpp/skia/modules/svg/include/SkSVGFe.h +1 -1
  237. package/cpp/skia/modules/svg/include/SkSVGFeBlend.h +1 -1
  238. package/cpp/skia/modules/svg/include/SkSVGFeColorMatrix.h +1 -1
  239. package/cpp/skia/modules/svg/include/SkSVGFeComponentTransfer.h +1 -1
  240. package/cpp/skia/modules/svg/include/SkSVGFeComposite.h +1 -1
  241. package/cpp/skia/modules/svg/include/SkSVGFeDisplacementMap.h +1 -1
  242. package/cpp/skia/modules/svg/include/SkSVGFeFlood.h +1 -1
  243. package/cpp/skia/modules/svg/include/SkSVGFeGaussianBlur.h +1 -1
  244. package/cpp/skia/modules/svg/include/SkSVGFeImage.h +1 -1
  245. package/cpp/skia/modules/svg/include/SkSVGFeLightSource.h +1 -1
  246. package/cpp/skia/modules/svg/include/SkSVGFeLighting.h +1 -1
  247. package/cpp/skia/modules/svg/include/SkSVGFeMerge.h +1 -1
  248. package/cpp/skia/modules/svg/include/SkSVGFeMorphology.h +1 -1
  249. package/cpp/skia/modules/svg/include/SkSVGFeOffset.h +1 -1
  250. package/cpp/skia/modules/svg/include/SkSVGFeTurbulence.h +1 -1
  251. package/cpp/skia/modules/svg/include/SkSVGFilter.h +1 -1
  252. package/cpp/skia/modules/svg/include/SkSVGFilterContext.h +1 -1
  253. package/cpp/skia/modules/svg/include/SkSVGGradient.h +1 -1
  254. package/cpp/skia/modules/svg/include/SkSVGImage.h +1 -1
  255. package/cpp/skia/modules/svg/include/SkSVGMask.h +1 -1
  256. package/cpp/skia/modules/svg/include/SkSVGOpenTypeSVGDecoder.h +1 -1
  257. package/cpp/skia/modules/svg/include/SkSVGPattern.h +1 -1
  258. package/cpp/skia/modules/svg/include/SkSVGRadialGradient.h +1 -1
  259. package/cpp/skia/modules/svg/include/SkSVGText.h +1 -1
  260. package/cpp/skia/modules/svg/include/SkSVGUse.h +1 -1
  261. package/cpp/skia/src/base/SkAutoLocaleSetter.h +94 -0
  262. package/cpp/skia/src/base/SkUTF.h +1 -1
  263. package/lib/commonjs/skia/types/WebGPU.d.ts +101 -5
  264. package/lib/commonjs/skia/types/WebGPU.js +99 -0
  265. package/lib/commonjs/skia/types/WebGPU.js.map +1 -1
  266. package/lib/module/skia/types/WebGPU.d.ts +101 -5
  267. package/lib/module/skia/types/WebGPU.js +98 -1
  268. package/lib/module/skia/types/WebGPU.js.map +1 -1
  269. package/lib/typescript/lib/commonjs/skia/types/WebGPU.d.ts +1 -0
  270. package/lib/typescript/lib/module/mock/index.d.ts +1 -0
  271. package/lib/typescript/lib/module/skia/types/WebGPU.d.ts +31 -1
  272. package/lib/typescript/src/skia/types/WebGPU.d.ts +101 -5
  273. package/package.json +5 -5
  274. package/src/skia/types/WebGPU.ts +123 -5
  275. package/cpp/rnwgpu/async/AsyncDispatcher.h +0 -28
  276. package/cpp/rnwgpu/async/AsyncRunner.cpp +0 -182
  277. package/cpp/rnwgpu/async/AsyncRunner.h +0 -57
  278. package/cpp/rnwgpu/async/JSIMicrotaskDispatcher.cpp +0 -23
  279. package/cpp/rnwgpu/async/JSIMicrotaskDispatcher.h +0 -22
@@ -1 +1,31 @@
1
- export {};
1
+ /**
2
+ * Make the WebGPU flag constants (`GPUBufferUsage`, `GPUColorWrite`,
3
+ * `GPUMapMode`, `GPUShaderStage`, `GPUTextureUsage`) available on the runtime
4
+ * that calls this.
5
+ *
6
+ * The native module installs these globals on the main JS runtime, but worklet
7
+ * runtimes (Reanimated UI, dedicated worklet runtimes, Vision Camera frame
8
+ * processors) start without them, so referencing the bare global inside a
9
+ * worklet yields `undefined`. Call `installWebGPU()` once at the top of a
10
+ * worklet to install them there:
11
+ *
12
+ * ```tsx
13
+ * import { installWebGPU } from "@shopify/react-native-skia";
14
+ *
15
+ * const work = (device: GPUDevice) => {
16
+ * "worklet";
17
+ * installWebGPU();
18
+ * device.createBuffer({
19
+ * usage: GPUBufferUsage.COPY_DST | GPUBufferUsage.MAP_READ,
20
+ * });
21
+ * };
22
+ * ```
23
+ *
24
+ * `installWebGPU` is a native host function. When captured into a worklet, the
25
+ * Worklets serializer re-creates it on the worklet runtime, so calling it there
26
+ * installs the constants on that runtime. The values come from the native
27
+ * `wgpu::*Usage` enums, so they stay a single source of truth across runtimes.
28
+ * Calling it on a runtime that already has the constants is a safe no-op, and on
29
+ * web (where the constants are always global) it is a no-op too.
30
+ */
31
+ export const installWebGPU: any;
@@ -1,4 +1,35 @@
1
1
  import type { NativeBuffer } from "./NativeBuffer";
2
+ /**
3
+ * Make the WebGPU flag constants (`GPUBufferUsage`, `GPUColorWrite`,
4
+ * `GPUMapMode`, `GPUShaderStage`, `GPUTextureUsage`) available on the runtime
5
+ * that calls this.
6
+ *
7
+ * The native module installs these globals on the main JS runtime, but worklet
8
+ * runtimes (Reanimated UI, dedicated worklet runtimes, Vision Camera frame
9
+ * processors) start without them, so referencing the bare global inside a
10
+ * worklet yields `undefined`. Call `installWebGPU()` once at the top of a
11
+ * worklet to install them there:
12
+ *
13
+ * ```tsx
14
+ * import { installWebGPU } from "@shopify/react-native-skia";
15
+ *
16
+ * const work = (device: GPUDevice) => {
17
+ * "worklet";
18
+ * installWebGPU();
19
+ * device.createBuffer({
20
+ * usage: GPUBufferUsage.COPY_DST | GPUBufferUsage.MAP_READ,
21
+ * });
22
+ * };
23
+ * ```
24
+ *
25
+ * `installWebGPU` is a native host function. When captured into a worklet, the
26
+ * Worklets serializer re-creates it on the worklet runtime, so calling it there
27
+ * installs the constants on that runtime. The values come from the native
28
+ * `wgpu::*Usage` enums, so they stay a single source of truth across runtimes.
29
+ * Calling it on a runtime that already has the constants is a safe no-op, and on
30
+ * web (where the constants are always global) it is a no-op too.
31
+ */
32
+ export declare const installWebGPU: () => void;
2
33
  /**
3
34
  * Descriptor for {@link GPUDevice.importExternalTexture} when the source is a
4
35
  * Skia NativeBuffer (Skia has no WebCodecs `VideoFrame`).
@@ -24,6 +55,62 @@ export interface SkiaGPUExternalTextureDescriptor extends GPUObjectDescriptorBas
24
55
  export interface GPUSharedTextureMemoryDescriptor extends GPUObjectDescriptorBase {
25
56
  handle: NativeBuffer;
26
57
  }
58
+ /**
59
+ * The kind of native synchronization primitive a {@link GPUSharedFence} wraps,
60
+ * matching the `shared-fence-*` device feature names. Limited to the kinds
61
+ * react-native-skia targets (iOS/Metal and Android/Vulkan); `importSharedFence`
62
+ * accepts these and `export()` reports them.
63
+ */
64
+ export type GPUSharedFenceType = "mtl-shared-event" | "sync-fd" | "vk-semaphore-opaque-fd";
65
+ /**
66
+ * Descriptor for {@link GPUDevice.importSharedFence}.
67
+ */
68
+ export interface GPUSharedFenceDescriptor {
69
+ /**
70
+ * The fence kind to import. Must match a `shared-fence-*` feature enabled on
71
+ * the device.
72
+ */
73
+ type: GPUSharedFenceType;
74
+ /**
75
+ * The raw native handle as a BigInt: an `id<MTLSharedEvent>` pointer for
76
+ * `"mtl-shared-event"`, or an OS file descriptor for the `*-fd` kinds.
77
+ */
78
+ handle: bigint;
79
+ label?: string;
80
+ }
81
+ export interface GPUSharedFenceExportInfo {
82
+ type: GPUSharedFenceType;
83
+ /**
84
+ * An `id<MTLSharedEvent>` pointer (Apple) or file descriptor (Android), as a
85
+ * BigInt. The caller takes ownership; e.g. an exported sync-fd must be closed
86
+ * once consumed.
87
+ */
88
+ handle: bigint;
89
+ }
90
+ /**
91
+ * A native GPU synchronization primitive shared across queues/APIs. Produced by
92
+ * {@link GPUSharedTextureMemory.endAccess}, consumed by
93
+ * {@link GPUSharedTextureMemory.beginAccess}, or imported from a consumer's
94
+ * fence with {@link GPUDevice.importSharedFence}.
95
+ */
96
+ export interface GPUSharedFence {
97
+ readonly __brand: "GPUSharedFence";
98
+ label: string;
99
+ export(): GPUSharedFenceExportInfo;
100
+ }
101
+ /** A fence and the timeline value to wait for (0n for binary sync-fd fences). */
102
+ export interface GPUSharedFenceState {
103
+ fence: GPUSharedFence;
104
+ signaledValue: bigint;
105
+ }
106
+ /**
107
+ * The result of {@link GPUSharedTextureMemory.endAccess}: each fence is signaled
108
+ * at its `signaledValue` once Dawn's GPU work for the access completes.
109
+ */
110
+ export interface GPUSharedTextureMemoryEndAccessState {
111
+ initialized: boolean;
112
+ fences: GPUSharedFenceState[];
113
+ }
27
114
  /**
28
115
  * Shared texture memory imported from a platform native buffer via
29
116
  * {@link GPUDevice.importSharedTextureMemory}. Create a texture that aliases
@@ -36,14 +123,16 @@ export interface GPUSharedTextureMemory extends GPUObjectBase {
36
123
  /**
37
124
  * Acquire the memory for GPU access. `initialized` marks whether the existing
38
125
  * contents should be preserved (pass `true` for an already-rendered frame).
39
- * Returns `false` if access could not be acquired.
126
+ * Optional `fences` are wait fences: Dawn waits for each to reach its
127
+ * `signaledValue` before writing the surface. Throws if the access could not
128
+ * be acquired.
40
129
  */
41
- beginAccess(texture: GPUTexture, initialized: boolean): boolean;
130
+ beginAccess(texture: GPUTexture, initialized: boolean, fences?: GPUSharedFenceState[]): void;
42
131
  /**
43
- * Release the memory after the GPU work that accessed it has been submitted.
44
- * Returns `false` on failure.
132
+ * Release the memory after the GPU work that accessed it has been submitted,
133
+ * and return the fences Dawn produced for the access. Throws on failure.
45
134
  */
46
- endAccess(texture: GPUTexture): boolean;
135
+ endAccess(texture: GPUTexture): GPUSharedTextureMemoryEndAccessState;
47
136
  }
48
137
  /**
49
138
  * Dawn-specific toggles, passed via {@link GPUDeviceDescriptor.dawnToggles} to
@@ -84,5 +173,12 @@ declare global {
84
173
  * begin/end access window yourself.
85
174
  */
86
175
  importSharedTextureMemory(descriptor: GPUSharedTextureMemoryDescriptor): GPUSharedTextureMemory;
176
+ /**
177
+ * Skia extension: import a native synchronization primitive (an
178
+ * `id<MTLSharedEvent>` on Apple, a sync-fd / VkSemaphore on Android) as a
179
+ * {@link GPUSharedFence}, e.g. to wait on a fence a consumer produced. The
180
+ * matching `shared-fence-*` feature must be enabled on the device.
181
+ */
182
+ importSharedFence(descriptor: GPUSharedFenceDescriptor): GPUSharedFence;
87
183
  }
88
184
  }
package/package.json CHANGED
@@ -8,7 +8,7 @@
8
8
  "setup-skia-web": "scripts/setup-canvaskit.js"
9
9
  },
10
10
  "title": "React Native Skia",
11
- "version": "2.6.5",
11
+ "version": "2.6.7",
12
12
  "description": "High-performance React Native Graphics using Skia",
13
13
  "main": "lib/module/index.js",
14
14
  "react-native": "src/index.ts",
@@ -131,10 +131,10 @@
131
131
  },
132
132
  "dependencies": {
133
133
  "canvaskit-wasm": "0.41.0",
134
- "react-native-skia-android": "147.1.0",
135
- "react-native-skia-apple-ios": "147.1.0",
136
- "react-native-skia-apple-macos": "147.1.0",
137
- "react-native-skia-apple-tvos": "147.1.0",
134
+ "react-native-skia-android": "150.0.0",
135
+ "react-native-skia-apple-ios": "150.0.0",
136
+ "react-native-skia-apple-macos": "150.0.0",
137
+ "react-native-skia-apple-tvos": "150.0.0",
138
138
  "react-reconciler": "0.31.0"
139
139
  },
140
140
  "eslintIgnore": [
@@ -1,5 +1,45 @@
1
1
  import type { NativeBuffer } from "./NativeBuffer";
2
2
 
3
+ /**
4
+ * Make the WebGPU flag constants (`GPUBufferUsage`, `GPUColorWrite`,
5
+ * `GPUMapMode`, `GPUShaderStage`, `GPUTextureUsage`) available on the runtime
6
+ * that calls this.
7
+ *
8
+ * The native module installs these globals on the main JS runtime, but worklet
9
+ * runtimes (Reanimated UI, dedicated worklet runtimes, Vision Camera frame
10
+ * processors) start without them, so referencing the bare global inside a
11
+ * worklet yields `undefined`. Call `installWebGPU()` once at the top of a
12
+ * worklet to install them there:
13
+ *
14
+ * ```tsx
15
+ * import { installWebGPU } from "@shopify/react-native-skia";
16
+ *
17
+ * const work = (device: GPUDevice) => {
18
+ * "worklet";
19
+ * installWebGPU();
20
+ * device.createBuffer({
21
+ * usage: GPUBufferUsage.COPY_DST | GPUBufferUsage.MAP_READ,
22
+ * });
23
+ * };
24
+ * ```
25
+ *
26
+ * `installWebGPU` is a native host function. When captured into a worklet, the
27
+ * Worklets serializer re-creates it on the worklet runtime, so calling it there
28
+ * installs the constants on that runtime. The values come from the native
29
+ * `wgpu::*Usage` enums, so they stay a single source of truth across runtimes.
30
+ * Calling it on a runtime that already has the constants is a safe no-op, and on
31
+ * web (where the constants are always global) it is a no-op too.
32
+ */
33
+ export const installWebGPU: () => void = (() => {
34
+ const g =
35
+ typeof global !== "undefined"
36
+ ? (global as unknown as { installWebGPU?: () => void })
37
+ : undefined;
38
+ return g && typeof g.installWebGPU === "function"
39
+ ? g.installWebGPU
40
+ : () => {};
41
+ })();
42
+
3
43
  // Skia's Graphite/Dawn backend extends the standard WebGPU API (typed by
4
44
  // @webgpu/types) with a few Skia- and Dawn-specific entry points. These are
5
45
  // only available on native (SK_GRAPHITE) builds, reachable through
@@ -36,6 +76,71 @@ export interface GPUSharedTextureMemoryDescriptor extends GPUObjectDescriptorBas
36
76
  handle: NativeBuffer;
37
77
  }
38
78
 
79
+ /**
80
+ * The kind of native synchronization primitive a {@link GPUSharedFence} wraps,
81
+ * matching the `shared-fence-*` device feature names. Limited to the kinds
82
+ * react-native-skia targets (iOS/Metal and Android/Vulkan); `importSharedFence`
83
+ * accepts these and `export()` reports them.
84
+ */
85
+ export type GPUSharedFenceType =
86
+ | "mtl-shared-event"
87
+ | "sync-fd"
88
+ | "vk-semaphore-opaque-fd";
89
+
90
+ /**
91
+ * Descriptor for {@link GPUDevice.importSharedFence}.
92
+ */
93
+ export interface GPUSharedFenceDescriptor {
94
+ /**
95
+ * The fence kind to import. Must match a `shared-fence-*` feature enabled on
96
+ * the device.
97
+ */
98
+ type: GPUSharedFenceType;
99
+ /**
100
+ * The raw native handle as a BigInt: an `id<MTLSharedEvent>` pointer for
101
+ * `"mtl-shared-event"`, or an OS file descriptor for the `*-fd` kinds.
102
+ */
103
+ handle: bigint;
104
+ label?: string;
105
+ }
106
+
107
+ export interface GPUSharedFenceExportInfo {
108
+ type: GPUSharedFenceType;
109
+ /**
110
+ * An `id<MTLSharedEvent>` pointer (Apple) or file descriptor (Android), as a
111
+ * BigInt. The caller takes ownership; e.g. an exported sync-fd must be closed
112
+ * once consumed.
113
+ */
114
+ handle: bigint;
115
+ }
116
+
117
+ /**
118
+ * A native GPU synchronization primitive shared across queues/APIs. Produced by
119
+ * {@link GPUSharedTextureMemory.endAccess}, consumed by
120
+ * {@link GPUSharedTextureMemory.beginAccess}, or imported from a consumer's
121
+ * fence with {@link GPUDevice.importSharedFence}.
122
+ */
123
+ export interface GPUSharedFence {
124
+ readonly __brand: "GPUSharedFence";
125
+ label: string;
126
+ export(): GPUSharedFenceExportInfo;
127
+ }
128
+
129
+ /** A fence and the timeline value to wait for (0n for binary sync-fd fences). */
130
+ export interface GPUSharedFenceState {
131
+ fence: GPUSharedFence;
132
+ signaledValue: bigint;
133
+ }
134
+
135
+ /**
136
+ * The result of {@link GPUSharedTextureMemory.endAccess}: each fence is signaled
137
+ * at its `signaledValue` once Dawn's GPU work for the access completes.
138
+ */
139
+ export interface GPUSharedTextureMemoryEndAccessState {
140
+ initialized: boolean;
141
+ fences: GPUSharedFenceState[];
142
+ }
143
+
39
144
  /**
40
145
  * Shared texture memory imported from a platform native buffer via
41
146
  * {@link GPUDevice.importSharedTextureMemory}. Create a texture that aliases
@@ -48,14 +153,20 @@ export interface GPUSharedTextureMemory extends GPUObjectBase {
48
153
  /**
49
154
  * Acquire the memory for GPU access. `initialized` marks whether the existing
50
155
  * contents should be preserved (pass `true` for an already-rendered frame).
51
- * Returns `false` if access could not be acquired.
156
+ * Optional `fences` are wait fences: Dawn waits for each to reach its
157
+ * `signaledValue` before writing the surface. Throws if the access could not
158
+ * be acquired.
52
159
  */
53
- beginAccess(texture: GPUTexture, initialized: boolean): boolean;
160
+ beginAccess(
161
+ texture: GPUTexture,
162
+ initialized: boolean,
163
+ fences?: GPUSharedFenceState[]
164
+ ): void;
54
165
  /**
55
- * Release the memory after the GPU work that accessed it has been submitted.
56
- * Returns `false` on failure.
166
+ * Release the memory after the GPU work that accessed it has been submitted,
167
+ * and return the fences Dawn produced for the access. Throws on failure.
57
168
  */
58
- endAccess(texture: GPUTexture): boolean;
169
+ endAccess(texture: GPUTexture): GPUSharedTextureMemoryEndAccessState;
59
170
  }
60
171
 
61
172
  /**
@@ -104,5 +215,12 @@ declare global {
104
215
  importSharedTextureMemory(
105
216
  descriptor: GPUSharedTextureMemoryDescriptor
106
217
  ): GPUSharedTextureMemory;
218
+ /**
219
+ * Skia extension: import a native synchronization primitive (an
220
+ * `id<MTLSharedEvent>` on Apple, a sync-fd / VkSemaphore on Android) as a
221
+ * {@link GPUSharedFence}, e.g. to wait on a fence a consumer produced. The
222
+ * matching `shared-fence-*` feature must be enabled on the device.
223
+ */
224
+ importSharedFence(descriptor: GPUSharedFenceDescriptor): GPUSharedFence;
107
225
  }
108
226
  }
@@ -1,28 +0,0 @@
1
- #pragma once
2
-
3
- #include <functional>
4
- #include <memory>
5
-
6
- #include <jsi/jsi.h>
7
-
8
- namespace rnwgpu::async {
9
-
10
- namespace jsi = facebook::jsi;
11
-
12
- /**
13
- * Abstract dispatcher used by the AsyncRunner to enqueue work back onto the
14
- * JavaScript thread.
15
- */
16
- class AsyncDispatcher {
17
- public:
18
- using Work = std::function<void(jsi::Runtime &)>;
19
-
20
- virtual ~AsyncDispatcher() = default;
21
-
22
- /**
23
- * Enqueue a unit of work that will be executed on the JavaScript thread.
24
- */
25
- virtual void post(Work work) = 0;
26
- };
27
-
28
- } // namespace rnwgpu::async
@@ -1,182 +0,0 @@
1
- #include "AsyncRunner.h"
2
-
3
- #include <chrono>
4
- #include <stdexcept>
5
- #include <utility>
6
-
7
- #include "AsyncTaskHandle.h"
8
-
9
- namespace rnwgpu::async {
10
-
11
- // Static member definitions
12
- std::mutex AsyncRunner::_runnersMutex;
13
- std::unordered_map<jsi::Runtime *, std::shared_ptr<AsyncRunner>>
14
- AsyncRunner::_runners;
15
-
16
- AsyncRunner::AsyncRunner(wgpu::Instance instance,
17
- std::shared_ptr<AsyncDispatcher> dispatcher)
18
- : _instance(std::move(instance)), _dispatcher(std::move(dispatcher)),
19
- _pendingTasks(0), _pumpTasks(0), _tickScheduled(false),
20
- _lastTickTimeNs(0) {
21
- if (!_dispatcher) {
22
- throw std::runtime_error("AsyncRunner requires a valid dispatcher.");
23
- }
24
- }
25
-
26
- std::shared_ptr<AsyncRunner> AsyncRunner::get(jsi::Runtime &runtime) {
27
- std::lock_guard<std::mutex> lock(_runnersMutex);
28
- auto it = _runners.find(&runtime);
29
- if (it == _runners.end()) {
30
- return nullptr;
31
- }
32
- return it->second;
33
- }
34
-
35
- std::shared_ptr<AsyncRunner>
36
- AsyncRunner::getOrCreate(jsi::Runtime &runtime, wgpu::Instance instance,
37
- std::shared_ptr<AsyncDispatcher> dispatcher) {
38
- std::lock_guard<std::mutex> lock(_runnersMutex);
39
- auto it = _runners.find(&runtime);
40
- if (it != _runners.end()) {
41
- return it->second;
42
- }
43
-
44
- auto runner =
45
- std::make_shared<AsyncRunner>(std::move(instance), std::move(dispatcher));
46
- _runners[&runtime] = runner;
47
- return runner;
48
- }
49
-
50
- AsyncTaskHandle AsyncRunner::postTask(const TaskCallback &callback,
51
- bool keepPumping) {
52
- auto handle = AsyncTaskHandle::create(shared_from_this(), keepPumping);
53
- if (!handle.valid()) {
54
- throw std::runtime_error("Failed to create AsyncTaskHandle.");
55
- }
56
-
57
- _pendingTasks.fetch_add(1, std::memory_order_acq_rel);
58
- if (keepPumping) {
59
- _pumpTasks.fetch_add(1, std::memory_order_acq_rel);
60
- }
61
- requestTick();
62
-
63
- auto resolve = handle.createResolveFunction();
64
- auto reject = handle.createRejectFunction();
65
-
66
- try {
67
- callback(resolve, reject);
68
- } catch (const std::exception &exception) {
69
- reject(exception.what());
70
- } catch (...) {
71
- reject("Unknown native error in AsyncRunner::postTask.");
72
- }
73
-
74
- return handle;
75
- }
76
-
77
- void AsyncRunner::requestTick() {
78
- bool expected = false;
79
- if (!_tickScheduled.compare_exchange_strong(expected, true,
80
- std::memory_order_acq_rel)) {
81
- return;
82
- }
83
-
84
- auto self = shared_from_this();
85
- _dispatcher->post([self](jsi::Runtime &runtime) {
86
- auto tickCallback = jsi::Function::createFromHostFunction(
87
- runtime, jsi::PropNameID::forAscii(runtime, "AsyncRunnerTick"), 0,
88
- [self](jsi::Runtime &runtime, const jsi::Value & /*thisValue*/,
89
- const jsi::Value * /*args*/, size_t /*count*/) -> jsi::Value {
90
- self->tick(runtime);
91
- return jsi::Value::undefined();
92
- });
93
-
94
- #if defined(ANDROID) || defined(__ANDROID__)
95
- auto global = runtime.global();
96
- auto setImmediateValue = global.getProperty(runtime, "setImmediate");
97
- constexpr auto kMinTickInterval = std::chrono::milliseconds(4);
98
- const int64_t nowNs =
99
- std::chrono::duration_cast<std::chrono::nanoseconds>(
100
- std::chrono::steady_clock::now().time_since_epoch())
101
- .count();
102
- const int64_t lastNs =
103
- self->_lastTickTimeNs.load(std::memory_order_acquire);
104
- int delayMs = 0;
105
- if (lastNs > 0) {
106
- const int64_t elapsedNs = nowNs - lastNs;
107
- const int64_t minIntervalNs = kMinTickInterval.count() * 1000000LL;
108
- if (elapsedNs < minIntervalNs) {
109
- const int64_t remainingNs = minIntervalNs - elapsedNs;
110
- delayMs = static_cast<int>((remainingNs + 999999) / 1000000);
111
- }
112
- }
113
-
114
- auto tryScheduleTimeout = [&](int ms) {
115
- auto setTimeoutValue = global.getProperty(runtime, "setTimeout");
116
- if (!setTimeoutValue.isObject()) {
117
- return false;
118
- }
119
- auto setTimeoutObj = setTimeoutValue.asObject(runtime);
120
- if (!setTimeoutObj.isFunction(runtime)) {
121
- return false;
122
- }
123
- auto setTimeoutFn = setTimeoutObj.asFunction(runtime);
124
- jsi::Value callbackArg(runtime, tickCallback);
125
- jsi::Value delayArg(static_cast<double>(ms));
126
- setTimeoutFn.call(runtime, callbackArg, delayArg);
127
- return true;
128
- };
129
-
130
- if (delayMs > 0) {
131
- if (tryScheduleTimeout(delayMs)) {
132
- return;
133
- }
134
- // If setTimeout unavailable fall through to immediate scheduling.
135
- }
136
-
137
- if (setImmediateValue.isObject()) {
138
- auto setImmediateObj = setImmediateValue.asObject(runtime);
139
- if (setImmediateObj.isFunction(runtime)) {
140
- auto setImmediateFn = setImmediateObj.asFunction(runtime);
141
- jsi::Value callbackArg(runtime, tickCallback);
142
- setImmediateFn.call(runtime, callbackArg);
143
- return;
144
- }
145
- }
146
-
147
- int timeoutDelayMs = delayMs > 0 ? delayMs : 0;
148
- if (tryScheduleTimeout(timeoutDelayMs)) {
149
- return;
150
- }
151
-
152
- runtime.queueMicrotask(std::move(tickCallback));
153
- #else
154
- runtime.queueMicrotask(std::move(tickCallback));
155
- #endif
156
- });
157
- }
158
-
159
- void AsyncRunner::tick(jsi::Runtime & /*runtime*/) {
160
- _tickScheduled.store(false, std::memory_order_release);
161
- _instance.ProcessEvents();
162
- const auto nowNs = std::chrono::duration_cast<std::chrono::nanoseconds>(
163
- std::chrono::steady_clock::now().time_since_epoch())
164
- .count();
165
- _lastTickTimeNs.store(nowNs, std::memory_order_release);
166
- if (_pumpTasks.load(std::memory_order_acquire) > 0) {
167
- requestTick();
168
- }
169
- }
170
-
171
- void AsyncRunner::onTaskSettled(bool keepPumping) {
172
- _pendingTasks.fetch_sub(1, std::memory_order_acq_rel);
173
- if (keepPumping) {
174
- _pumpTasks.fetch_sub(1, std::memory_order_acq_rel);
175
- }
176
- }
177
-
178
- std::shared_ptr<AsyncDispatcher> AsyncRunner::dispatcher() const {
179
- return _dispatcher;
180
- }
181
-
182
- } // namespace rnwgpu::async
@@ -1,57 +0,0 @@
1
- #pragma once
2
-
3
- #include <atomic>
4
- #include <cstdint>
5
- #include <functional>
6
- #include <memory>
7
- #include <mutex>
8
- #include <unordered_map>
9
-
10
- #include <jsi/jsi.h>
11
-
12
- #include "AsyncDispatcher.h"
13
- #include "AsyncTaskHandle.h"
14
-
15
- #include "webgpu/webgpu_cpp.h"
16
-
17
- namespace jsi = facebook::jsi;
18
-
19
- namespace rnwgpu::async {
20
-
21
- class AsyncRunner : public std::enable_shared_from_this<AsyncRunner> {
22
- public:
23
- using TaskCallback =
24
- std::function<void(const AsyncTaskHandle::ResolveFunction &,
25
- const AsyncTaskHandle::RejectFunction &)>;
26
-
27
- AsyncRunner(wgpu::Instance instance,
28
- std::shared_ptr<AsyncDispatcher> dispatcher);
29
-
30
- static std::shared_ptr<AsyncRunner> get(jsi::Runtime &runtime);
31
- static std::shared_ptr<AsyncRunner>
32
- getOrCreate(jsi::Runtime &runtime, wgpu::Instance instance,
33
- std::shared_ptr<AsyncDispatcher> dispatcher);
34
-
35
- AsyncTaskHandle postTask(const TaskCallback &callback,
36
- bool keepPumping = true);
37
-
38
- void requestTick();
39
- void tick(jsi::Runtime &runtime);
40
- void onTaskSettled(bool keepPumping);
41
-
42
- std::shared_ptr<AsyncDispatcher> dispatcher() const;
43
-
44
- private:
45
- static std::mutex _runnersMutex;
46
- static std::unordered_map<jsi::Runtime *, std::shared_ptr<AsyncRunner>>
47
- _runners;
48
-
49
- wgpu::Instance _instance;
50
- std::shared_ptr<AsyncDispatcher> _dispatcher;
51
- std::atomic<size_t> _pendingTasks;
52
- std::atomic<size_t> _pumpTasks;
53
- std::atomic<bool> _tickScheduled;
54
- std::atomic<int64_t> _lastTickTimeNs;
55
- };
56
-
57
- } // namespace rnwgpu::async
@@ -1,23 +0,0 @@
1
- #include "JSIMicrotaskDispatcher.h"
2
-
3
- #include <utility>
4
-
5
- namespace rnwgpu::async {
6
-
7
- JSIMicrotaskDispatcher::JSIMicrotaskDispatcher(jsi::Runtime &runtime)
8
- : _runtime(runtime) {}
9
-
10
- void JSIMicrotaskDispatcher::post(Work work) {
11
- auto microtask = jsi::Function::createFromHostFunction(
12
- _runtime, jsi::PropNameID::forAscii(_runtime, "AsyncMicrotask"), 0,
13
- [work = std::move(work)](
14
- jsi::Runtime &runtime, const jsi::Value & /*thisValue*/,
15
- const jsi::Value * /*args*/, size_t /*count*/) -> jsi::Value {
16
- work(runtime);
17
- return jsi::Value::undefined();
18
- });
19
-
20
- _runtime.queueMicrotask(std::move(microtask));
21
- }
22
-
23
- } // namespace rnwgpu::async
@@ -1,22 +0,0 @@
1
- #pragma once
2
-
3
- #include "AsyncDispatcher.h"
4
-
5
- namespace rnwgpu::async {
6
-
7
- /**
8
- * Dispatcher implementation backed by `jsi::Runtime::queueMicrotask`.
9
- */
10
- class JSIMicrotaskDispatcher final
11
- : public AsyncDispatcher,
12
- public std::enable_shared_from_this<JSIMicrotaskDispatcher> {
13
- public:
14
- explicit JSIMicrotaskDispatcher(jsi::Runtime &runtime);
15
-
16
- void post(Work work) override;
17
-
18
- private:
19
- jsi::Runtime &_runtime;
20
- };
21
-
22
- } // namespace rnwgpu::async