@shopify/react-native-skia 2.9.1 → 2.10.1

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 (387) hide show
  1. package/android/CMakeLists.txt +8 -46
  2. package/android/build.gradle +33 -0
  3. package/android/src/main/java/com/shopify/reactnative/skia/RNSkiaPackage.java +1 -2
  4. package/cpp/api/JsiNativeBuffer.h +23 -24
  5. package/cpp/api/JsiSkAnimatedImage.h +24 -25
  6. package/cpp/api/JsiSkAnimatedImageFactory.h +18 -17
  7. package/cpp/api/JsiSkApi.h +254 -96
  8. package/cpp/api/JsiSkCanvas.h +141 -266
  9. package/cpp/api/JsiSkColor.h +7 -5
  10. package/cpp/api/JsiSkColorFilter.h +15 -8
  11. package/cpp/api/JsiSkColorFilterFactory.h +49 -67
  12. package/cpp/api/JsiSkContourMeasure.h +31 -38
  13. package/cpp/api/JsiSkContourMeasureIter.h +20 -23
  14. package/cpp/api/JsiSkConverters.h +410 -0
  15. package/cpp/api/JsiSkData.h +13 -7
  16. package/cpp/api/JsiSkDataFactory.h +27 -32
  17. package/cpp/api/JsiSkFont.h +123 -192
  18. package/cpp/api/JsiSkFontMgr.h +33 -26
  19. package/cpp/api/JsiSkFontMgrFactory.h +12 -11
  20. package/cpp/api/JsiSkFontStyle.h +14 -12
  21. package/cpp/api/JsiSkImage.h +90 -79
  22. package/cpp/api/JsiSkImageFactory.h +93 -95
  23. package/cpp/api/JsiSkImageFilter.h +21 -11
  24. package/cpp/api/JsiSkImageFilterFactory.h +375 -629
  25. package/cpp/api/JsiSkImageInfo.h +25 -25
  26. package/cpp/api/JsiSkMaskFilter.h +21 -11
  27. package/cpp/api/JsiSkMaskFilterFactory.h +17 -17
  28. package/cpp/api/JsiSkMatrix.h +51 -88
  29. package/cpp/api/JsiSkNativeObjects.h +387 -0
  30. package/cpp/api/JsiSkPaint.h +104 -142
  31. package/cpp/api/JsiSkParagraph.h +54 -64
  32. package/cpp/api/JsiSkParagraphBuilder.h +43 -68
  33. package/cpp/api/JsiSkParagraphBuilderFactory.h +20 -24
  34. package/cpp/api/JsiSkPath.h +242 -350
  35. package/cpp/api/JsiSkPathBuilder.h +153 -273
  36. package/cpp/api/JsiSkPathBuilderFactory.h +19 -20
  37. package/cpp/api/JsiSkPathEffect.h +21 -11
  38. package/cpp/api/JsiSkPathEffectFactory.h +61 -80
  39. package/cpp/api/JsiSkPathFactory.h +148 -238
  40. package/cpp/api/JsiSkPicture.h +32 -27
  41. package/cpp/api/JsiSkPictureFactory.h +21 -26
  42. package/cpp/api/JsiSkPictureRecorder.h +27 -29
  43. package/cpp/api/JsiSkPoint.h +20 -23
  44. package/cpp/api/JsiSkRRect.h +24 -32
  45. package/cpp/api/JsiSkRSXform.h +31 -48
  46. package/cpp/api/JsiSkRect.h +40 -50
  47. package/cpp/api/JsiSkRuntimeEffect.h +85 -92
  48. package/cpp/api/JsiSkRuntimeEffectFactory.h +14 -18
  49. package/cpp/api/JsiSkRuntimeShaderBuilder.h +28 -30
  50. package/cpp/api/JsiSkSVG.h +15 -15
  51. package/cpp/api/JsiSkSVGFactory.h +17 -20
  52. package/cpp/api/JsiSkShader.h +15 -8
  53. package/cpp/api/JsiSkShaderFactory.h +159 -238
  54. package/cpp/api/JsiSkSkottie.h +131 -143
  55. package/cpp/api/JsiSkSurface.h +29 -32
  56. package/cpp/api/JsiSkSurfaceFactory.h +18 -20
  57. package/cpp/api/JsiSkTextBlob.h +15 -8
  58. package/cpp/api/JsiSkTextBlobFactory.h +40 -66
  59. package/cpp/api/JsiSkTypeface.h +25 -22
  60. package/cpp/api/JsiSkTypefaceFactory.h +17 -15
  61. package/cpp/api/JsiSkTypefaceFontProvider.h +43 -39
  62. package/cpp/api/JsiSkTypefaceFontProviderFactory.h +13 -12
  63. package/cpp/api/JsiSkVertices.h +23 -22
  64. package/cpp/api/JsiSkiaContext.h +22 -23
  65. package/cpp/api/JsiSkottieFactory.h +16 -17
  66. package/cpp/api/JsiVideo.h +43 -81
  67. package/cpp/api/recorder/Convertor.h +31 -61
  68. package/cpp/api/recorder/DataTypes.h +8 -16
  69. package/cpp/api/recorder/JsiRecorder.h +83 -55
  70. package/cpp/api/recorder/RNRecorder.h +1 -1
  71. package/cpp/jsi/BoxedNativeObject.h +146 -0
  72. package/cpp/{jsi2 → jsi}/EnumMapper.h +4 -1
  73. package/cpp/{jsi2 → jsi}/JSIConverter.h +0 -31
  74. package/cpp/{jsi2 → jsi}/NativeObject.h +131 -152
  75. package/cpp/jsi/RuntimeAwareCache.cpp +1 -1
  76. package/cpp/jsi/RuntimeAwareCache.h +26 -8
  77. package/cpp/jsi/ViewProperty.h +5 -11
  78. package/cpp/rnskia/RNDawnContext.h +18 -2
  79. package/cpp/rnskia/RNDawnInterop.cpp +19 -0
  80. package/cpp/rnskia/RNDawnUtils.h +18 -1
  81. package/cpp/rnskia/RNSkJsiViewApi.h +20 -11
  82. package/cpp/rnskia/RNSkManager.cpp +9 -168
  83. package/cpp/rnskia/RNSkPictureView.h +1 -1
  84. package/cpp/skia/include/gpu/ganesh/GrDriverBugWorkaroundsAutogen.h +2 -0
  85. package/lib/commonjs/external/reanimated/renderHelpers.d.ts +15 -0
  86. package/lib/commonjs/external/reanimated/renderHelpers.js +30 -1
  87. package/lib/commonjs/external/reanimated/renderHelpers.js.map +1 -1
  88. package/lib/commonjs/mock/index.js +0 -1
  89. package/lib/commonjs/mock/index.js.map +1 -1
  90. package/lib/commonjs/skia/NativeSetup.js +4 -0
  91. package/lib/commonjs/skia/NativeSetup.js.map +1 -1
  92. package/lib/commonjs/skia/SkiaWorkletSerialization.d.ts +1 -0
  93. package/lib/commonjs/skia/SkiaWorkletSerialization.js +66 -0
  94. package/lib/commonjs/skia/SkiaWorkletSerialization.js.map +1 -0
  95. package/lib/commonjs/skia/types/Image/ImageFactory.d.ts +15 -6
  96. package/lib/commonjs/skia/types/Image/ImageFactory.js.map +1 -1
  97. package/lib/commonjs/skia/types/Skia.d.ts +5 -15
  98. package/lib/commonjs/skia/types/Skia.js.map +1 -1
  99. package/lib/commonjs/skia/types/index.d.ts +0 -1
  100. package/lib/commonjs/skia/types/index.js +0 -11
  101. package/lib/commonjs/skia/types/index.js.map +1 -1
  102. package/lib/commonjs/skia/web/JsiSkImageFactory.d.ts +2 -2
  103. package/lib/commonjs/skia/web/JsiSkImageFactory.js +2 -2
  104. package/lib/commonjs/skia/web/JsiSkImageFactory.js.map +1 -1
  105. package/lib/commonjs/skia/web/JsiSkia.js +1 -4
  106. package/lib/commonjs/skia/web/JsiSkia.js.map +1 -1
  107. package/lib/commonjs/sksg/Container.native.js +20 -1
  108. package/lib/commonjs/sksg/Container.native.js.map +1 -1
  109. package/lib/commonjs/views/index.d.ts +0 -1
  110. package/lib/commonjs/views/index.js +0 -11
  111. package/lib/commonjs/views/index.js.map +1 -1
  112. package/lib/module/external/reanimated/renderHelpers.d.ts +15 -0
  113. package/lib/module/external/reanimated/renderHelpers.js +29 -0
  114. package/lib/module/external/reanimated/renderHelpers.js.map +1 -1
  115. package/lib/module/mock/index.js +0 -1
  116. package/lib/module/mock/index.js.map +1 -1
  117. package/lib/module/skia/NativeSetup.js +4 -0
  118. package/lib/module/skia/NativeSetup.js.map +1 -1
  119. package/lib/module/skia/SkiaWorkletSerialization.d.ts +1 -0
  120. package/lib/module/skia/SkiaWorkletSerialization.js +59 -0
  121. package/lib/module/skia/SkiaWorkletSerialization.js.map +1 -0
  122. package/lib/module/skia/types/Image/ImageFactory.d.ts +15 -6
  123. package/lib/module/skia/types/Image/ImageFactory.js.map +1 -1
  124. package/lib/module/skia/types/Skia.d.ts +5 -15
  125. package/lib/module/skia/types/Skia.js.map +1 -1
  126. package/lib/module/skia/types/index.d.ts +0 -1
  127. package/lib/module/skia/types/index.js +0 -1
  128. package/lib/module/skia/types/index.js.map +1 -1
  129. package/lib/module/skia/web/JsiSkImageFactory.d.ts +2 -2
  130. package/lib/module/skia/web/JsiSkImageFactory.js +2 -2
  131. package/lib/module/skia/web/JsiSkImageFactory.js.map +1 -1
  132. package/lib/module/skia/web/JsiSkia.js +1 -4
  133. package/lib/module/skia/web/JsiSkia.js.map +1 -1
  134. package/lib/module/sksg/Container.native.js +21 -2
  135. package/lib/module/sksg/Container.native.js.map +1 -1
  136. package/lib/module/views/index.d.ts +0 -1
  137. package/lib/module/views/index.js +0 -1
  138. package/lib/module/views/index.js.map +1 -1
  139. package/lib/typescript/lib/commonjs/external/reanimated/renderHelpers.d.ts +2 -0
  140. package/lib/typescript/lib/commonjs/mock/index.d.ts +0 -1
  141. package/lib/typescript/lib/commonjs/skia/SkiaWorkletSerialization.d.ts +2 -0
  142. package/lib/typescript/lib/commonjs/skia/web/JsiSkImageFactory.d.ts +2 -2
  143. package/lib/typescript/lib/commonjs/skia/web/JsiSkia.d.ts +1 -2
  144. package/lib/typescript/lib/module/external/reanimated/renderHelpers.d.ts +15 -0
  145. package/lib/typescript/lib/module/mock/index.d.ts +0 -2
  146. package/lib/typescript/lib/module/skia/Skia.web.d.ts +1 -2
  147. package/lib/typescript/lib/module/skia/SkiaWorkletSerialization.d.ts +1 -0
  148. package/lib/typescript/lib/module/skia/types/index.d.ts +0 -1
  149. package/lib/typescript/lib/module/skia/web/JsiSkImageFactory.d.ts +2 -2
  150. package/lib/typescript/lib/module/skia/web/JsiSkia.d.ts +1 -2
  151. package/lib/typescript/lib/module/views/index.d.ts +0 -1
  152. package/lib/typescript/src/external/reanimated/renderHelpers.d.ts +15 -0
  153. package/lib/typescript/src/skia/SkiaWorkletSerialization.d.ts +1 -0
  154. package/lib/typescript/src/skia/types/Image/ImageFactory.d.ts +15 -6
  155. package/lib/typescript/src/skia/types/Skia.d.ts +5 -15
  156. package/lib/typescript/src/skia/types/index.d.ts +0 -1
  157. package/lib/typescript/src/skia/web/JsiSkImageFactory.d.ts +2 -2
  158. package/lib/typescript/src/views/index.d.ts +0 -1
  159. package/package.json +8 -5
  160. package/react-native-skia.podspec +38 -5
  161. package/src/external/reanimated/renderHelpers.ts +30 -0
  162. package/src/mock/index.ts +0 -1
  163. package/src/skia/NativeSetup.ts +5 -0
  164. package/src/skia/SkiaWorkletSerialization.ts +67 -0
  165. package/src/skia/types/Image/ImageFactory.ts +15 -6
  166. package/src/skia/types/Skia.ts +5 -15
  167. package/src/skia/types/index.ts +0 -1
  168. package/src/skia/web/JsiSkImageFactory.ts +3 -3
  169. package/src/skia/web/JsiSkia.ts +2 -5
  170. package/src/sksg/Container.native.ts +40 -2
  171. package/src/views/index.ts +0 -1
  172. package/android/cpp/jni/JniWebGPUView.cpp +0 -112
  173. package/android/cpp/rnskia-android/SkiaPlatformContext.h +0 -26
  174. package/android/src/main/java/com/shopify/reactnative/skia/WebGPUSurfaceView.java +0 -43
  175. package/android/src/main/java/com/shopify/reactnative/skia/WebGPUTextureView.java +0 -50
  176. package/android/src/main/java/com/shopify/reactnative/skia/WebGPUView.java +0 -98
  177. package/android/src/main/java/com/shopify/reactnative/skia/WebGPUViewAPI.java +0 -19
  178. package/android/src/main/java/com/shopify/reactnative/skia/WebGPUViewManager.java +0 -58
  179. package/apple/RNWebGPUAppleNativeBuffer.mm +0 -33
  180. package/apple/SkiaPlatformContext.h +0 -20
  181. package/apple/SkiaPlatformContext.mm +0 -21
  182. package/apple/SkiaWebGPUView.mm +0 -81
  183. package/apple/WebGPUMetalView.mm +0 -136
  184. package/cpp/api/JsiSkHostObjects.h +0 -257
  185. package/cpp/jsi/JsiHostObject.cpp +0 -137
  186. package/cpp/jsi/JsiHostObject.h +0 -385
  187. package/cpp/rnwgpu/ArrayBuffer.h +0 -117
  188. package/cpp/rnwgpu/Canvas.h +0 -50
  189. package/cpp/rnwgpu/PlatformContext.h +0 -18
  190. package/cpp/rnwgpu/SurfaceRegistry.h +0 -605
  191. package/cpp/rnwgpu/api/AppleNativeBuffer.h +0 -22
  192. package/cpp/rnwgpu/api/Convertors.h +0 -783
  193. package/cpp/rnwgpu/api/External.h +0 -12
  194. package/cpp/rnwgpu/api/GPU.cpp +0 -162
  195. package/cpp/rnwgpu/api/GPU.h +0 -60
  196. package/cpp/rnwgpu/api/GPUAdapter.cpp +0 -240
  197. package/cpp/rnwgpu/api/GPUAdapter.h +0 -60
  198. package/cpp/rnwgpu/api/GPUAdapterInfo.h +0 -57
  199. package/cpp/rnwgpu/api/GPUBindGroup.cpp +0 -3
  200. package/cpp/rnwgpu/api/GPUBindGroup.h +0 -51
  201. package/cpp/rnwgpu/api/GPUBindGroupLayout.h +0 -52
  202. package/cpp/rnwgpu/api/GPUBuffer.cpp +0 -107
  203. package/cpp/rnwgpu/api/GPUBuffer.h +0 -88
  204. package/cpp/rnwgpu/api/GPUCanvasContext.cpp +0 -75
  205. package/cpp/rnwgpu/api/GPUCanvasContext.h +0 -70
  206. package/cpp/rnwgpu/api/GPUCommandBuffer.h +0 -45
  207. package/cpp/rnwgpu/api/GPUCommandEncoder.cpp +0 -179
  208. package/cpp/rnwgpu/api/GPUCommandEncoder.h +0 -111
  209. package/cpp/rnwgpu/api/GPUCompilationInfo.h +0 -79
  210. package/cpp/rnwgpu/api/GPUCompilationMessage.h +0 -36
  211. package/cpp/rnwgpu/api/GPUComputePassEncoder.cpp +0 -60
  212. package/cpp/rnwgpu/api/GPUComputePassEncoder.h +0 -85
  213. package/cpp/rnwgpu/api/GPUComputePipeline.cpp +0 -12
  214. package/cpp/rnwgpu/api/GPUComputePipeline.h +0 -60
  215. package/cpp/rnwgpu/api/GPUDevice.cpp +0 -614
  216. package/cpp/rnwgpu/api/GPUDevice.h +0 -258
  217. package/cpp/rnwgpu/api/GPUDeviceLostInfo.cpp +0 -7
  218. package/cpp/rnwgpu/api/GPUDeviceLostInfo.h +0 -40
  219. package/cpp/rnwgpu/api/GPUError.h +0 -35
  220. package/cpp/rnwgpu/api/GPUExtent3D.h +0 -66
  221. package/cpp/rnwgpu/api/GPUExternalTexture.cpp +0 -139
  222. package/cpp/rnwgpu/api/GPUExternalTexture.h +0 -95
  223. package/cpp/rnwgpu/api/GPUFeatures.h +0 -203
  224. package/cpp/rnwgpu/api/GPUInternalError.h +0 -31
  225. package/cpp/rnwgpu/api/GPUOrigin2D.h +0 -55
  226. package/cpp/rnwgpu/api/GPUOrigin3D.h +0 -62
  227. package/cpp/rnwgpu/api/GPUOutOfMemoryError.h +0 -33
  228. package/cpp/rnwgpu/api/GPUPipelineLayout.h +0 -45
  229. package/cpp/rnwgpu/api/GPUQuerySet.cpp +0 -11
  230. package/cpp/rnwgpu/api/GPUQuerySet.h +0 -73
  231. package/cpp/rnwgpu/api/GPUQueue.cpp +0 -179
  232. package/cpp/rnwgpu/api/GPUQueue.h +0 -84
  233. package/cpp/rnwgpu/api/GPURenderBundle.h +0 -44
  234. package/cpp/rnwgpu/api/GPURenderBundleEncoder.cpp +0 -131
  235. package/cpp/rnwgpu/api/GPURenderBundleEncoder.h +0 -110
  236. package/cpp/rnwgpu/api/GPURenderPassEncoder.cpp +0 -165
  237. package/cpp/rnwgpu/api/GPURenderPassEncoder.h +0 -130
  238. package/cpp/rnwgpu/api/GPURenderPipeline.cpp +0 -13
  239. package/cpp/rnwgpu/api/GPURenderPipeline.h +0 -61
  240. package/cpp/rnwgpu/api/GPUSampler.h +0 -44
  241. package/cpp/rnwgpu/api/GPUShaderModule.cpp +0 -56
  242. package/cpp/rnwgpu/api/GPUShaderModule.h +0 -66
  243. package/cpp/rnwgpu/api/GPUSharedFence.cpp +0 -80
  244. package/cpp/rnwgpu/api/GPUSharedFence.h +0 -53
  245. package/cpp/rnwgpu/api/GPUSharedTextureMemory.cpp +0 -135
  246. package/cpp/rnwgpu/api/GPUSharedTextureMemory.h +0 -75
  247. package/cpp/rnwgpu/api/GPUSupportedLimits.cpp +0 -129
  248. package/cpp/rnwgpu/api/GPUSupportedLimits.h +0 -131
  249. package/cpp/rnwgpu/api/GPUTexture.cpp +0 -47
  250. package/cpp/rnwgpu/api/GPUTexture.h +0 -162
  251. package/cpp/rnwgpu/api/GPUTextureView.h +0 -44
  252. package/cpp/rnwgpu/api/GPUUncapturedErrorEvent.h +0 -60
  253. package/cpp/rnwgpu/api/GPUValidationError.h +0 -32
  254. package/cpp/rnwgpu/api/ImageBitmap.h +0 -62
  255. package/cpp/rnwgpu/api/NativeBufferUtils.h +0 -87
  256. package/cpp/rnwgpu/api/RNWebGPU.h +0 -82
  257. package/cpp/rnwgpu/api/WebGPUConstants.h +0 -36
  258. package/cpp/rnwgpu/api/descriptors/GPUBindGroupDescriptor.h +0 -64
  259. package/cpp/rnwgpu/api/descriptors/GPUBindGroupEntry.h +0 -78
  260. package/cpp/rnwgpu/api/descriptors/GPUBindGroupLayoutDescriptor.h +0 -56
  261. package/cpp/rnwgpu/api/descriptors/GPUBindGroupLayoutEntry.h +0 -97
  262. package/cpp/rnwgpu/api/descriptors/GPUBlendComponent.h +0 -57
  263. package/cpp/rnwgpu/api/descriptors/GPUBlendState.h +0 -52
  264. package/cpp/rnwgpu/api/descriptors/GPUBufferBinding.h +0 -56
  265. package/cpp/rnwgpu/api/descriptors/GPUBufferBindingLayout.h +0 -56
  266. package/cpp/rnwgpu/api/descriptors/GPUBufferDescriptor.h +0 -59
  267. package/cpp/rnwgpu/api/descriptors/GPUBufferUsage.h +0 -39
  268. package/cpp/rnwgpu/api/descriptors/GPUCanvasConfiguration.h +0 -76
  269. package/cpp/rnwgpu/api/descriptors/GPUColor.h +0 -66
  270. package/cpp/rnwgpu/api/descriptors/GPUColorTargetState.h +0 -58
  271. package/cpp/rnwgpu/api/descriptors/GPUColorWrite.h +0 -29
  272. package/cpp/rnwgpu/api/descriptors/GPUCommandBufferDescriptor.h +0 -45
  273. package/cpp/rnwgpu/api/descriptors/GPUCommandEncoderDescriptor.h +0 -45
  274. package/cpp/rnwgpu/api/descriptors/GPUComputePassDescriptor.h +0 -56
  275. package/cpp/rnwgpu/api/descriptors/GPUComputePassTimestampWrites.h +0 -58
  276. package/cpp/rnwgpu/api/descriptors/GPUComputePipelineDescriptor.h +0 -67
  277. package/cpp/rnwgpu/api/descriptors/GPUDawnTogglesDescriptor.h +0 -56
  278. package/cpp/rnwgpu/api/descriptors/GPUDepthStencilState.h +0 -103
  279. package/cpp/rnwgpu/api/descriptors/GPUDeviceDescriptor.h +0 -109
  280. package/cpp/rnwgpu/api/descriptors/GPUExternalTextureBindingLayout.h +0 -38
  281. package/cpp/rnwgpu/api/descriptors/GPUExternalTextureDescriptor.h +0 -90
  282. package/cpp/rnwgpu/api/descriptors/GPUFragmentState.h +0 -73
  283. package/cpp/rnwgpu/api/descriptors/GPUImageCopyBuffer.h +0 -62
  284. package/cpp/rnwgpu/api/descriptors/GPUImageCopyExternalImage.h +0 -63
  285. package/cpp/rnwgpu/api/descriptors/GPUImageCopyTexture.h +0 -65
  286. package/cpp/rnwgpu/api/descriptors/GPUImageCopyTextureTagged.h +0 -81
  287. package/cpp/rnwgpu/api/descriptors/GPUImageDataLayout.h +0 -54
  288. package/cpp/rnwgpu/api/descriptors/GPUMapMode.h +0 -22
  289. package/cpp/rnwgpu/api/descriptors/GPUMultisampleState.h +0 -54
  290. package/cpp/rnwgpu/api/descriptors/GPUPipelineLayoutDescriptor.h +0 -57
  291. package/cpp/rnwgpu/api/descriptors/GPUPrimitiveState.h +0 -69
  292. package/cpp/rnwgpu/api/descriptors/GPUProgrammableStage.h +0 -61
  293. package/cpp/rnwgpu/api/descriptors/GPUQuerySetDescriptor.h +0 -55
  294. package/cpp/rnwgpu/api/descriptors/GPUQueueDescriptor.h +0 -43
  295. package/cpp/rnwgpu/api/descriptors/GPURenderBundleDescriptor.h +0 -45
  296. package/cpp/rnwgpu/api/descriptors/GPURenderBundleEncoderDescriptor.h +0 -80
  297. package/cpp/rnwgpu/api/descriptors/GPURenderPassColorAttachment.h +0 -81
  298. package/cpp/rnwgpu/api/descriptors/GPURenderPassDepthStencilAttachment.h +0 -101
  299. package/cpp/rnwgpu/api/descriptors/GPURenderPassDescriptor.h +0 -92
  300. package/cpp/rnwgpu/api/descriptors/GPURenderPassTimestampWrites.h +0 -58
  301. package/cpp/rnwgpu/api/descriptors/GPURenderPipelineDescriptor.h +0 -103
  302. package/cpp/rnwgpu/api/descriptors/GPURequestAdapterOptions.h +0 -51
  303. package/cpp/rnwgpu/api/descriptors/GPUSamplerBindingLayout.h +0 -45
  304. package/cpp/rnwgpu/api/descriptors/GPUSamplerDescriptor.h +0 -110
  305. package/cpp/rnwgpu/api/descriptors/GPUShaderModuleCompilationHint.h +0 -60
  306. package/cpp/rnwgpu/api/descriptors/GPUShaderModuleDescriptor.h +0 -62
  307. package/cpp/rnwgpu/api/descriptors/GPUShaderStage.h +0 -25
  308. package/cpp/rnwgpu/api/descriptors/GPUSharedFenceDescriptor.h +0 -58
  309. package/cpp/rnwgpu/api/descriptors/GPUSharedFenceState.h +0 -51
  310. package/cpp/rnwgpu/api/descriptors/GPUSharedTextureMemoryDescriptor.h +0 -73
  311. package/cpp/rnwgpu/api/descriptors/GPUStencilFaceState.h +0 -64
  312. package/cpp/rnwgpu/api/descriptors/GPUStorageTextureBindingLayout.h +0 -59
  313. package/cpp/rnwgpu/api/descriptors/GPUTextureBindingLayout.h +0 -59
  314. package/cpp/rnwgpu/api/descriptors/GPUTextureDescriptor.h +0 -91
  315. package/cpp/rnwgpu/api/descriptors/GPUTextureUsage.h +0 -29
  316. package/cpp/rnwgpu/api/descriptors/GPUTextureViewDescriptor.h +0 -91
  317. package/cpp/rnwgpu/api/descriptors/GPUUncapturedErrorEventInit.h +0 -64
  318. package/cpp/rnwgpu/api/descriptors/GPUVertexAttribute.h +0 -53
  319. package/cpp/rnwgpu/api/descriptors/GPUVertexBufferLayout.h +0 -62
  320. package/cpp/rnwgpu/api/descriptors/GPUVertexState.h +0 -73
  321. package/cpp/rnwgpu/api/descriptors/Unions.h +0 -1969
  322. package/cpp/rnwgpu/async/AsyncTaskHandle.cpp +0 -214
  323. package/cpp/rnwgpu/async/AsyncTaskHandle.h +0 -58
  324. package/cpp/rnwgpu/async/RuntimeContext.cpp +0 -199
  325. package/cpp/rnwgpu/async/RuntimeContext.h +0 -134
  326. package/lib/commonjs/skia/types/WebGPU.d.ts +0 -184
  327. package/lib/commonjs/skia/types/WebGPU.js +0 -105
  328. package/lib/commonjs/skia/types/WebGPU.js.map +0 -1
  329. package/lib/commonjs/specs/WebGPUViewNativeComponent.d.ts +0 -8
  330. package/lib/commonjs/specs/WebGPUViewNativeComponent.js +0 -10
  331. package/lib/commonjs/specs/WebGPUViewNativeComponent.js.map +0 -1
  332. package/lib/commonjs/specs/WebGPUViewNativeComponent.web.d.ts +0 -8
  333. package/lib/commonjs/specs/WebGPUViewNativeComponent.web.js +0 -103
  334. package/lib/commonjs/specs/WebGPUViewNativeComponent.web.js.map +0 -1
  335. package/lib/commonjs/specs/utils.d.ts +0 -1
  336. package/lib/commonjs/specs/utils.js +0 -11
  337. package/lib/commonjs/specs/utils.js.map +0 -1
  338. package/lib/commonjs/views/WebGPUCanvas.d.ts +0 -33
  339. package/lib/commonjs/views/WebGPUCanvas.js +0 -79
  340. package/lib/commonjs/views/WebGPUCanvas.js.map +0 -1
  341. package/lib/commonjs/views/WebGPUCanvas.web.d.ts +0 -23
  342. package/lib/commonjs/views/WebGPUCanvas.web.js +0 -20
  343. package/lib/commonjs/views/WebGPUCanvas.web.js.map +0 -1
  344. package/lib/module/skia/types/WebGPU.d.ts +0 -184
  345. package/lib/module/skia/types/WebGPU.js +0 -99
  346. package/lib/module/skia/types/WebGPU.js.map +0 -1
  347. package/lib/module/specs/WebGPUViewNativeComponent.d.ts +0 -8
  348. package/lib/module/specs/WebGPUViewNativeComponent.js +0 -4
  349. package/lib/module/specs/WebGPUViewNativeComponent.js.map +0 -1
  350. package/lib/module/specs/WebGPUViewNativeComponent.web.d.ts +0 -8
  351. package/lib/module/specs/WebGPUViewNativeComponent.web.js +0 -96
  352. package/lib/module/specs/WebGPUViewNativeComponent.web.js.map +0 -1
  353. package/lib/module/specs/utils.d.ts +0 -1
  354. package/lib/module/specs/utils.js +0 -5
  355. package/lib/module/specs/utils.js.map +0 -1
  356. package/lib/module/views/WebGPUCanvas.d.ts +0 -33
  357. package/lib/module/views/WebGPUCanvas.js +0 -70
  358. package/lib/module/views/WebGPUCanvas.js.map +0 -1
  359. package/lib/module/views/WebGPUCanvas.web.d.ts +0 -23
  360. package/lib/module/views/WebGPUCanvas.web.js +0 -12
  361. package/lib/module/views/WebGPUCanvas.web.js.map +0 -1
  362. package/lib/typescript/lib/commonjs/skia/types/WebGPU.d.ts +0 -2
  363. package/lib/typescript/lib/commonjs/specs/WebGPUViewNativeComponent.d.ts +0 -4
  364. package/lib/typescript/lib/commonjs/specs/WebGPUViewNativeComponent.web.d.ts +0 -3
  365. package/lib/typescript/lib/commonjs/specs/utils.d.ts +0 -2
  366. package/lib/typescript/lib/commonjs/views/WebGPUCanvas.d.ts +0 -6
  367. package/lib/typescript/lib/commonjs/views/WebGPUCanvas.web.d.ts +0 -6
  368. package/lib/typescript/lib/module/skia/types/WebGPU.d.ts +0 -31
  369. package/lib/typescript/lib/module/specs/WebGPUViewNativeComponent.d.ts +0 -2
  370. package/lib/typescript/lib/module/specs/WebGPUViewNativeComponent.web.d.ts +0 -2
  371. package/lib/typescript/lib/module/specs/utils.d.ts +0 -1
  372. package/lib/typescript/lib/module/views/WebGPUCanvas.d.ts +0 -7
  373. package/lib/typescript/lib/module/views/WebGPUCanvas.web.d.ts +0 -8
  374. package/lib/typescript/src/skia/types/WebGPU.d.ts +0 -184
  375. package/lib/typescript/src/specs/WebGPUViewNativeComponent.d.ts +0 -8
  376. package/lib/typescript/src/specs/WebGPUViewNativeComponent.web.d.ts +0 -8
  377. package/lib/typescript/src/specs/utils.d.ts +0 -1
  378. package/lib/typescript/src/views/WebGPUCanvas.d.ts +0 -33
  379. package/lib/typescript/src/views/WebGPUCanvas.web.d.ts +0 -23
  380. package/src/skia/types/WebGPU.ts +0 -226
  381. package/src/specs/WebGPUViewNativeComponent.ts +0 -11
  382. package/src/specs/WebGPUViewNativeComponent.web.ts +0 -110
  383. package/src/specs/utils.ts +0 -4
  384. package/src/views/WebGPUCanvas.tsx +0 -125
  385. package/src/views/WebGPUCanvas.web.tsx +0 -36
  386. /package/cpp/{jsi2 → jsi}/Promise.cpp +0 -0
  387. /package/cpp/{jsi2 → jsi}/Promise.h +0 -0
@@ -0,0 +1,146 @@
1
+ #pragma once
2
+
3
+ #include <functional>
4
+ #include <memory>
5
+ #include <mutex>
6
+ #include <stdexcept>
7
+ #include <string>
8
+ #include <unordered_map>
9
+ #include <utility>
10
+ #include <vector>
11
+
12
+ #include <jsi/jsi.h>
13
+
14
+ namespace RNJsi {
15
+
16
+ namespace jsi = facebook::jsi;
17
+
18
+ /**
19
+ * Registry mapping a NativeObject class brand (CLASS_NAME) to a reconstructor
20
+ * that can recreate a fully functional JS object (prototype + native state)
21
+ * on any runtime. This is what enables native objects (Skia and WebGPU) to
22
+ * travel between the React Native runtime and secondary runtimes (Reanimated
23
+ * worklets) via BoxedNativeObject.
24
+ */
25
+ class BoxedNativeObjectRegistry {
26
+ public:
27
+ using Reconstructor = std::function<jsi::Value(
28
+ jsi::Runtime &, std::shared_ptr<jsi::NativeState>)>;
29
+
30
+ static BoxedNativeObjectRegistry &getInstance() {
31
+ static BoxedNativeObjectRegistry instance;
32
+ return instance;
33
+ }
34
+
35
+ void registerClass(const std::string &brand, Reconstructor reconstructor) {
36
+ std::lock_guard<std::mutex> lock(_mutex);
37
+ // Brands are the unboxing key and must be unique process-wide; a silent
38
+ // overwrite would make one class unbox into another's reconstructor.
39
+ if (_reconstructors.count(brand) > 0) {
40
+ throw std::runtime_error("Duplicate native object brand registered: " +
41
+ brand);
42
+ }
43
+ _reconstructors[brand] = std::move(reconstructor);
44
+ }
45
+
46
+ jsi::Value reconstruct(jsi::Runtime &runtime, const std::string &brand,
47
+ std::shared_ptr<jsi::NativeState> state) {
48
+ Reconstructor reconstructor;
49
+ {
50
+ std::lock_guard<std::mutex> lock(_mutex);
51
+ auto it = _reconstructors.find(brand);
52
+ if (it == _reconstructors.end()) {
53
+ throw jsi::JSError(runtime,
54
+ "No native class registered for brand: " + brand);
55
+ }
56
+ reconstructor = it->second;
57
+ }
58
+ return reconstructor(runtime, std::move(state));
59
+ }
60
+
61
+ private:
62
+ BoxedNativeObjectRegistry() = default;
63
+ std::mutex _mutex;
64
+ std::unordered_map<std::string, Reconstructor> _reconstructors;
65
+ };
66
+
67
+ /**
68
+ * HostObject bridge used to move NativeObjects between runtimes.
69
+ *
70
+ * NativeObject-based values are plain JS objects carrying jsi::NativeState;
71
+ * worklets cannot serialize their prototype, so they are "boxed" into this
72
+ * HostObject (which worklets pass across runtimes by reference) and unboxed
73
+ * on the target runtime, where the prototype is re-installed from the class
74
+ * registry. See registerCustomSerializable in
75
+ * src/skia/SkiaWorkletSerialization.ts.
76
+ */
77
+ class BoxedNativeObject : public jsi::HostObject {
78
+ public:
79
+ BoxedNativeObject(std::shared_ptr<jsi::NativeState> state, std::string brand)
80
+ : _state(std::move(state)), _brand(std::move(brand)) {}
81
+
82
+ jsi::Value get(jsi::Runtime &runtime, const jsi::PropNameID &name) override {
83
+ auto propName = name.utf8(runtime);
84
+ if (propName == "unbox") {
85
+ auto state = _state;
86
+ auto brand = _brand;
87
+ return jsi::Function::createFromHostFunction(
88
+ runtime, jsi::PropNameID::forUtf8(runtime, "unbox"), 0,
89
+ [state, brand](jsi::Runtime &rt, const jsi::Value &,
90
+ const jsi::Value *, size_t) -> jsi::Value {
91
+ return BoxedNativeObjectRegistry::getInstance().reconstruct(
92
+ rt, brand, state);
93
+ });
94
+ }
95
+ if (propName == "__boxedNativeObject") {
96
+ return jsi::Value(true);
97
+ }
98
+ if (propName == "__brand") {
99
+ return jsi::String::createFromUtf8(runtime, _brand);
100
+ }
101
+ return jsi::Value::undefined();
102
+ }
103
+
104
+ void set(jsi::Runtime &runtime, const jsi::PropNameID &,
105
+ const jsi::Value &) override {
106
+ throw jsi::JSError(runtime, "Boxed native objects are read-only");
107
+ }
108
+
109
+ std::vector<jsi::PropNameID> getPropertyNames(jsi::Runtime &rt) override {
110
+ std::vector<jsi::PropNameID> names;
111
+ names.reserve(3);
112
+ names.push_back(jsi::PropNameID::forUtf8(rt, "unbox"));
113
+ names.push_back(jsi::PropNameID::forUtf8(rt, "__boxedNativeObject"));
114
+ names.push_back(jsi::PropNameID::forUtf8(rt, "__brand"));
115
+ return names;
116
+ }
117
+
118
+ private:
119
+ std::shared_ptr<jsi::NativeState> _state;
120
+ std::string _brand;
121
+ };
122
+
123
+ /**
124
+ * Boxes a NativeObject-backed JS value so it can be serialized by worklets
125
+ * and unboxed on another runtime.
126
+ */
127
+ inline jsi::Value boxNativeObject(jsi::Runtime &runtime,
128
+ const jsi::Value &value) {
129
+ if (!value.isObject()) {
130
+ throw jsi::JSError(runtime, "box() expects a native object");
131
+ }
132
+ auto object = value.asObject(runtime);
133
+ if (!object.hasNativeState(runtime)) {
134
+ throw jsi::JSError(runtime, "box() expects a native object");
135
+ }
136
+ auto brand = object.getProperty(runtime, "__typename__");
137
+ if (!brand.isString()) {
138
+ throw jsi::JSError(runtime, "box() expects a native object");
139
+ }
140
+ return jsi::Object::createFromHostObject(
141
+ runtime, std::make_shared<BoxedNativeObject>(
142
+ object.getNativeState(runtime),
143
+ brand.asString(runtime).utf8(runtime)));
144
+ }
145
+
146
+ } // namespace RNJsi
@@ -12,7 +12,10 @@ namespace EnumMapper {
12
12
  // outEnum)`
13
13
  // 2. `static void convertEnumToJSUnion(Enum inEnum, std::string* outUnion)`
14
14
 
15
- static std::runtime_error invalidUnion(const std::string &passedUnion) {
15
+ // inline (not static): this header is now included by every TU via
16
+ // NativeObject.h, and an unused file-scope static would trip
17
+ // -Werror=unused-function in non-Graphite builds.
18
+ inline std::runtime_error invalidUnion(const std::string &passedUnion) {
16
19
  return std::runtime_error(
17
20
  "Cannot convert JS Value to Enum: Invalid Union value passed! (\"" +
18
21
  std::string(passedUnion) + "\")");
@@ -17,11 +17,6 @@
17
17
  #include "EnumMapper.h"
18
18
  #include "Promise.h"
19
19
 
20
- #ifdef SK_GRAPHITE
21
- #include "rnwgpu/api/descriptors/Unions.h"
22
- #include "rnwgpu/async/AsyncTaskHandle.h"
23
- #endif
24
-
25
20
  // This number is the maximum integer that can be represented exactly as a
26
21
  // double
27
22
  #define MAX_SAFE_INTEGER static_cast<uint64_t>(9007199254740991)
@@ -212,32 +207,6 @@ struct JSIConverter<TEnum, std::enable_if_t<std::is_enum<TEnum>::value>> {
212
207
  }
213
208
  };
214
209
 
215
- #ifdef SK_GRAPHITE
216
- // AsyncTaskHandle <> Promise
217
- template <> struct JSIConverter<rnwgpu::async::AsyncTaskHandle> {
218
- static rnwgpu::async::AsyncTaskHandle fromJSI(jsi::Runtime &,
219
- const jsi::Value &, bool) {
220
- throw std::runtime_error(
221
- "Cannot convert a Promise to AsyncTaskHandle on the native side.");
222
- }
223
-
224
- static jsi::Value toJSI(jsi::Runtime &runtime,
225
- rnwgpu::async::AsyncTaskHandle &&handle) {
226
- return rnwgpu::Promise::createPromise(
227
- runtime, [handle = std::move(handle)](
228
- jsi::Runtime &runtime,
229
- std::shared_ptr<rnwgpu::Promise> promise) mutable {
230
- if (!handle.valid()) {
231
- promise->resolve(jsi::Value::undefined());
232
- return;
233
- }
234
-
235
- handle.attachPromise(promise);
236
- });
237
- }
238
- };
239
- #endif
240
-
241
210
  // jsi::Function <> Function
242
211
  template <> struct JSIConverter<jsi::Function> {
243
212
  static jsi::Function fromJSI(jsi::Runtime &runtime, const jsi::Value &arg,
@@ -14,6 +14,7 @@
14
14
  #include <unordered_map>
15
15
  #include <utility>
16
16
 
17
+ #include "jsi/BoxedNativeObject.h"
17
18
  #include "jsi/RuntimeAwareCache.h" // Use Skia's RuntimeAwareCache
18
19
 
19
20
  // Forward declare to avoid circular dependency
@@ -36,41 +37,6 @@ static constexpr size_t kMinMemoryPressure = 256;
36
37
  // Forward declaration
37
38
  template <typename Derived> class NativeObject;
38
39
 
39
- /**
40
- * Registry for NativeObject prototype installers.
41
- * This allows BoxedWebGPUObject::unbox() to install prototypes on any runtime
42
- * by looking up the brand name and calling the appropriate installer.
43
- */
44
- class NativeObjectRegistry {
45
- public:
46
- using InstallerFunc = std::function<void(jsi::Runtime &)>;
47
-
48
- static NativeObjectRegistry &getInstance() {
49
- static NativeObjectRegistry instance;
50
- return instance;
51
- }
52
-
53
- void registerInstaller(const std::string &brand, InstallerFunc installer) {
54
- std::lock_guard<std::mutex> lock(_mutex);
55
- _installers[brand] = std::move(installer);
56
- }
57
-
58
- bool installPrototype(jsi::Runtime &runtime, const std::string &brand) {
59
- std::lock_guard<std::mutex> lock(_mutex);
60
- auto it = _installers.find(brand);
61
- if (it != _installers.end()) {
62
- it->second(runtime);
63
- return true;
64
- }
65
- return false;
66
- }
67
-
68
- private:
69
- NativeObjectRegistry() = default;
70
- std::mutex _mutex;
71
- std::unordered_map<std::string, InstallerFunc> _installers;
72
- };
73
-
74
40
  /**
75
41
  * Per-runtime cache entry for a prototype object.
76
42
  * Uses std::optional<jsi::Object> so the prototype is stored directly
@@ -110,93 +76,6 @@ template <typename T> struct StaticRuntimeAwareCache {
110
76
  }
111
77
  };
112
78
 
113
- /**
114
- * BoxedWebGPUObject is a HostObject wrapper that holds a reference to ANY
115
- * WebGPU NativeObject. This is used for Reanimated/Worklets serialization.
116
- *
117
- * Since NativeObject uses NativeState (not HostObject), Worklets can't
118
- * serialize them directly. But Worklets CAN serialize HostObjects.
119
- *
120
- * This class stores:
121
- * - The NativeState from the original object
122
- * - The brand name for prototype reconstruction
123
- *
124
- * Usage pattern with registerCustomSerializable:
125
- * - pack(): Call WebGPU.box(obj) to create a BoxedWebGPUObject (HostObject)
126
- * - The HostObject is serialized by Worklets and transferred to UI runtime
127
- * - unpack(): Call boxed.unbox() to get back the original object with prototype
128
- *
129
- * This is similar to NitroModules.box()/unbox() pattern.
130
- */
131
- class BoxedWebGPUObject : public jsi::HostObject {
132
- public:
133
- BoxedWebGPUObject(std::shared_ptr<jsi::NativeState> nativeState,
134
- const std::string &brand)
135
- : _nativeState(std::move(nativeState)), _brand(brand) {}
136
-
137
- jsi::Value get(jsi::Runtime &runtime, const jsi::PropNameID &name) override {
138
- auto propName = name.utf8(runtime);
139
- if (propName == "unbox") {
140
- return jsi::Function::createFromHostFunction(
141
- runtime, jsi::PropNameID::forUtf8(runtime, "unbox"), 0,
142
- [this](jsi::Runtime &rt, const jsi::Value & /*thisVal*/,
143
- const jsi::Value * /*args*/, size_t /*count*/) -> jsi::Value {
144
- // Try to get the prototype from the global constructor
145
- auto ctor = rt.global().getProperty(rt, _brand.c_str());
146
- if (!ctor.isObject()) {
147
- // Constructor doesn't exist on this runtime - install it
148
- NativeObjectRegistry::getInstance().installPrototype(rt, _brand);
149
- ctor = rt.global().getProperty(rt, _brand.c_str());
150
- }
151
-
152
- // Create a new object and attach the native state
153
- jsi::Object obj(rt);
154
- obj.setNativeState(rt, _nativeState);
155
-
156
- // Set the prototype if constructor exists
157
- if (ctor.isObject()) {
158
- auto ctorObj = ctor.getObject(rt);
159
- auto proto = ctorObj.getProperty(rt, "prototype");
160
- if (proto.isObject()) {
161
- auto objectCtor = rt.global().getPropertyAsObject(rt, "Object");
162
- auto setPrototypeOf =
163
- objectCtor.getPropertyAsFunction(rt, "setPrototypeOf");
164
- setPrototypeOf.call(rt, obj, proto);
165
- }
166
- }
167
-
168
- return std::move(obj);
169
- });
170
- }
171
- if (propName == "__boxedWebGPU") {
172
- return jsi::Value(true);
173
- }
174
- if (propName == "__brand") {
175
- return jsi::String::createFromUtf8(runtime, _brand);
176
- }
177
- return jsi::Value::undefined();
178
- }
179
-
180
- void set(jsi::Runtime &runtime, const jsi::PropNameID &name,
181
- const jsi::Value &value) override {
182
- throw jsi::JSError(runtime, "BoxedWebGPUObject is read-only");
183
- }
184
-
185
- std::vector<jsi::PropNameID>
186
- getPropertyNames(jsi::Runtime &runtime) override {
187
- std::vector<jsi::PropNameID> names;
188
- names.reserve(3);
189
- names.push_back(jsi::PropNameID::forUtf8(runtime, "unbox"));
190
- names.push_back(jsi::PropNameID::forUtf8(runtime, "__boxedWebGPU"));
191
- names.push_back(jsi::PropNameID::forUtf8(runtime, "__brand"));
192
- return names;
193
- }
194
-
195
- private:
196
- std::shared_ptr<jsi::NativeState> _nativeState;
197
- std::string _brand;
198
- };
199
-
200
79
  /**
201
80
  * Base class for native objects using the NativeState pattern.
202
81
  *
@@ -237,6 +116,10 @@ public:
237
116
  * Each NativeObject<Derived> type has its own static cache.
238
117
  * Uses StaticRuntimeAwareCache to properly handle runtime lifecycle
239
118
  * and hot reload (where the main runtime is destroyed and recreated).
119
+ *
120
+ * Callers must hold getPrototypeCacheMutex(): the cache is reached
121
+ * concurrently from the main JS thread (create()) and from worklet
122
+ * runtime threads (BoxedNativeObject::unbox() -> installPrototype()).
240
123
  */
241
124
  static RNJsi::RuntimeAwareCache<PrototypeCacheEntry> &
242
125
  getPrototypeCache(jsi::Runtime &runtime) {
@@ -244,11 +127,22 @@ public:
244
127
  return cache.get(runtime);
245
128
  }
246
129
 
130
+ /**
131
+ * Per-class mutex guarding getPrototypeCache() and prototype
132
+ * installation. Serializes the StaticRuntimeAwareCache pointer swap
133
+ * (hot reload) and the per-runtime cache lookups.
134
+ */
135
+ static std::mutex &getPrototypeCacheMutex() {
136
+ static std::mutex mutex;
137
+ return mutex;
138
+ }
139
+
247
140
  /**
248
141
  * Ensure the prototype is installed for this runtime.
249
142
  * Called automatically by create(), but can be called manually.
250
143
  */
251
144
  static void installPrototype(jsi::Runtime &runtime) {
145
+ std::lock_guard<std::mutex> lock(getPrototypeCacheMutex());
252
146
  auto &entry = getPrototypeCache(runtime).get(runtime);
253
147
  if (entry.prototype.has_value()) {
254
148
  return; // Already installed
@@ -279,6 +173,95 @@ public:
279
173
  defineProperty.call(runtime, prototype, toStringTag, descriptor);
280
174
  }
281
175
 
176
+ // Install the shared pieces every native object needs for JS type
177
+ // detection and cross-runtime transfer (worklets):
178
+ // - `__typename__` (CLASS_NAME), used by JS type guards and as the
179
+ // boxing brand
180
+ // - `__box()`, which wraps the object into a RNJsi::BoxedNativeObject
181
+ // HostObject that worklets can pass across runtimes by reference
182
+ // See registerCustomSerializable in src/skia/SkiaWorkletSerialization.ts.
183
+ prototype.setProperty(
184
+ runtime, "__typename__",
185
+ jsi::String::createFromUtf8(runtime, Derived::CLASS_NAME));
186
+
187
+ auto boxFunc = jsi::Function::createFromHostFunction(
188
+ runtime, jsi::PropNameID::forUtf8(runtime, "__box"), 0,
189
+ [](jsi::Runtime &rt, const jsi::Value &thisValue, const jsi::Value *,
190
+ size_t) -> jsi::Value {
191
+ return RNJsi::boxNativeObject(rt, thisValue);
192
+ });
193
+ prototype.setProperty(runtime, "__box", boxFunc);
194
+
195
+ // Install a generic toJSON so JSON.stringify sees the data properties.
196
+ // They live on the prototype (getters), and JSON.stringify only
197
+ // serializes *own* enumerable properties — with the legacy HostObject
198
+ // pattern all properties were reported as own, so e.g.
199
+ // JSON.stringify(rect) used to produce {x, y, width, height,
200
+ // __typename__} and now would produce {} without this.
201
+ auto toJSONFunc = jsi::Function::createFromHostFunction(
202
+ runtime, jsi::PropNameID::forUtf8(runtime, "toJSON"), 0,
203
+ [](jsi::Runtime &rt, const jsi::Value &thisValue, const jsi::Value *,
204
+ size_t) -> jsi::Value {
205
+ if (!thisValue.isObject()) {
206
+ return jsi::Value::undefined();
207
+ }
208
+ auto self = thisValue.asObject(rt);
209
+ auto objectCtor = rt.global().getPropertyAsObject(rt, "Object");
210
+ auto getPrototypeOf =
211
+ objectCtor.getPropertyAsFunction(rt, "getPrototypeOf");
212
+ auto getOwnPropertyNames =
213
+ objectCtor.getPropertyAsFunction(rt, "getOwnPropertyNames");
214
+ auto proto = getPrototypeOf.call(rt, self);
215
+ jsi::Object result(rt);
216
+ if (proto.isObject()) {
217
+ auto names =
218
+ getOwnPropertyNames.call(rt, proto).asObject(rt).asArray(rt);
219
+ auto size = names.size(rt);
220
+ for (size_t i = 0; i < size; i++) {
221
+ auto name = names.getValueAtIndex(rt, i).asString(rt).utf8(rt);
222
+ if (name == "constructor" || name == "toJSON") {
223
+ continue;
224
+ }
225
+ auto value = self.getProperty(rt, name.c_str());
226
+ // Skip methods (dispose, __box, ...) — JSON.stringify would
227
+ // drop them anyway; skipping avoids serializing them at all.
228
+ if (value.isObject() && value.asObject(rt).isFunction(rt)) {
229
+ continue;
230
+ }
231
+ result.setProperty(rt, name.c_str(), value);
232
+ }
233
+ }
234
+ return result;
235
+ });
236
+ prototype.setProperty(runtime, "toJSON", toJSONFunc);
237
+
238
+ // Register the reconstructor used by BoxedNativeObject::unbox() to
239
+ // rebuild this object (prototype + native state) on another runtime.
240
+ static std::once_flag boxingRegistered;
241
+ std::call_once(boxingRegistered, []() {
242
+ RNJsi::BoxedNativeObjectRegistry::getInstance().registerClass(
243
+ Derived::CLASS_NAME,
244
+ [](jsi::Runtime &rt,
245
+ std::shared_ptr<jsi::NativeState> state) -> jsi::Value {
246
+ auto instance = std::dynamic_pointer_cast<Derived>(state);
247
+ if (instance == nullptr) {
248
+ throw jsi::JSError(rt, "Invalid boxed native object state");
249
+ }
250
+ // Unboxing creates a *view* of the object on the target runtime.
251
+ // Keep the runtime the object was originally created on: async
252
+ // native code (e.g. GPUDevice error/lost events) delivers into
253
+ // the creation runtime, and rebinding it to a worklet runtime
254
+ // would invoke main-runtime jsi::Functions on the wrong runtime
255
+ // and thread.
256
+ auto *originalRuntime = instance->getCreationRuntime();
257
+ auto value = Derived::create(rt, instance);
258
+ if (originalRuntime != nullptr) {
259
+ instance->setCreationRuntime(originalRuntime);
260
+ }
261
+ return value;
262
+ });
263
+ });
264
+
282
265
  // Cache the prototype
283
266
  entry.prototype = std::move(prototype);
284
267
  }
@@ -289,22 +272,11 @@ public:
289
272
  *
290
273
  * The constructor throws if called directly (these objects are only
291
274
  * created internally by the native code).
292
- *
293
- * Also registers this class with NativeObjectRegistry so that
294
- * BoxedWebGPUObject::unbox() can install prototypes on secondary runtimes.
295
275
  */
296
276
  static void installConstructor(jsi::Runtime &runtime) {
297
- // Register this class's installer in the registry (only needs to happen
298
- // once)
299
- static std::once_flag registryFlag;
300
- std::call_once(registryFlag, []() {
301
- NativeObjectRegistry::getInstance().registerInstaller(
302
- Derived::CLASS_NAME,
303
- [](jsi::Runtime &rt) { Derived::installConstructor(rt); });
304
- });
305
-
306
277
  installPrototype(runtime);
307
278
 
279
+ std::lock_guard<std::mutex> lock(getPrototypeCacheMutex());
308
280
  auto &entry = getPrototypeCache(runtime).get(runtime);
309
281
  if (!entry.prototype.has_value()) {
310
282
  return;
@@ -348,13 +320,17 @@ public:
348
320
  obj.setNativeState(runtime, instance);
349
321
 
350
322
  // Set prototype
351
- auto &entry = getPrototypeCache(runtime).get(runtime);
352
- if (entry.prototype.has_value()) {
353
- // Use Object.setPrototypeOf to set the prototype
354
- auto objectCtor = runtime.global().getPropertyAsObject(runtime, "Object");
355
- auto setPrototypeOf =
356
- objectCtor.getPropertyAsFunction(runtime, "setPrototypeOf");
357
- setPrototypeOf.call(runtime, obj, *entry.prototype);
323
+ {
324
+ std::lock_guard<std::mutex> lock(getPrototypeCacheMutex());
325
+ auto &entry = getPrototypeCache(runtime).get(runtime);
326
+ if (entry.prototype.has_value()) {
327
+ // Use Object.setPrototypeOf to set the prototype
328
+ auto objectCtor =
329
+ runtime.global().getPropertyAsObject(runtime, "Object");
330
+ auto setPrototypeOf =
331
+ objectCtor.getPropertyAsFunction(runtime, "setPrototypeOf");
332
+ setPrototypeOf.call(runtime, obj, *entry.prototype);
333
+ }
358
334
  }
359
335
 
360
336
  // Set memory pressure hint for GC
@@ -416,6 +392,11 @@ protected:
416
392
 
417
393
  /**
418
394
  * Install a method on the prototype.
395
+ *
396
+ * The installers below resolve `this` with NativeObject<Derived>::fromValue
397
+ * (explicitly qualified): derived classes may shadow fromValue with a
398
+ * public static of the same name that returns the wrapped inner object
399
+ * (the RNSkia wrappers do), which must not be picked up here.
419
400
  */
420
401
  template <typename ReturnType, typename... Args>
421
402
  static void installMethod(jsi::Runtime &runtime, jsi::Object &prototype,
@@ -425,7 +406,7 @@ protected:
425
406
  runtime, jsi::PropNameID::forUtf8(runtime, name), sizeof...(Args),
426
407
  [method](jsi::Runtime &rt, const jsi::Value &thisVal,
427
408
  const jsi::Value *args, size_t count) -> jsi::Value {
428
- auto native = Derived::fromValue(rt, thisVal);
409
+ auto native = NativeObject<Derived>::fromValue(rt, thisVal);
429
410
  return callMethod(native.get(), method, rt, args,
430
411
  std::index_sequence_for<Args...>{}, count);
431
412
  });
@@ -438,16 +419,14 @@ protected:
438
419
  * (e.g. GPU::requestAdapter, which creates a per-runtime RuntimeContext).
439
420
  */
440
421
  template <typename ReturnType, typename... Args>
441
- static void
442
- installMethodWithRuntime(jsi::Runtime &runtime, jsi::Object &prototype,
443
- const char *name,
444
- ReturnType (Derived::*method)(jsi::Runtime &,
445
- Args...)) {
422
+ static void installMethodWithRuntime(
423
+ jsi::Runtime &runtime, jsi::Object &prototype, const char *name,
424
+ ReturnType (Derived::*method)(jsi::Runtime &, Args...)) {
446
425
  auto func = jsi::Function::createFromHostFunction(
447
426
  runtime, jsi::PropNameID::forUtf8(runtime, name), sizeof...(Args),
448
427
  [method](jsi::Runtime &rt, const jsi::Value &thisVal,
449
428
  const jsi::Value *args, size_t count) -> jsi::Value {
450
- auto native = Derived::fromValue(rt, thisVal);
429
+ auto native = NativeObject<Derived>::fromValue(rt, thisVal);
451
430
  return callMethodWithRuntime(native.get(), method, rt, args,
452
431
  std::index_sequence_for<Args...>{},
453
432
  count);
@@ -467,7 +446,7 @@ protected:
467
446
  0,
468
447
  [getter](jsi::Runtime &rt, const jsi::Value &thisVal,
469
448
  const jsi::Value *args, size_t count) -> jsi::Value {
470
- auto native = Derived::fromValue(rt, thisVal);
449
+ auto native = NativeObject<Derived>::fromValue(rt, thisVal);
471
450
  if constexpr (std::is_same_v<ReturnType, void>) {
472
451
  (native.get()->*getter)();
473
452
  return jsi::Value::undefined();
@@ -507,7 +486,7 @@ protected:
507
486
  if (count < 1) {
508
487
  throw jsi::JSError(rt, "Setter requires a value argument");
509
488
  }
510
- auto native = Derived::fromValue(rt, thisVal);
489
+ auto native = NativeObject<Derived>::fromValue(rt, thisVal);
511
490
  auto value = rnwgpu::JSIConverter<std::decay_t<ValueType>>::fromJSI(
512
491
  rt, args[0], false);
513
492
  (native.get()->*setter)(std::move(value));
@@ -554,7 +533,7 @@ protected:
554
533
  0,
555
534
  [getter](jsi::Runtime &rt, const jsi::Value &thisVal,
556
535
  const jsi::Value *args, size_t count) -> jsi::Value {
557
- auto native = Derived::fromValue(rt, thisVal);
536
+ auto native = NativeObject<Derived>::fromValue(rt, thisVal);
558
537
  ReturnType result = (native.get()->*getter)();
559
538
  return rnwgpu::JSIConverter<std::decay_t<ReturnType>>::toJSI(
560
539
  rt, std::move(result));
@@ -568,7 +547,7 @@ protected:
568
547
  if (count < 1) {
569
548
  throw jsi::JSError(rt, "Setter requires a value argument");
570
549
  }
571
- auto native = Derived::fromValue(rt, thisVal);
550
+ auto native = NativeObject<Derived>::fromValue(rt, thisVal);
572
551
  auto value = rnwgpu::JSIConverter<std::decay_t<ValueType>>::fromJSI(
573
552
  rt, args[0], false);
574
553
  (native.get()->*setter)(std::move(value));
@@ -2,6 +2,6 @@
2
2
 
3
3
  namespace RNJsi {
4
4
 
5
- jsi::Runtime *BaseRuntimeAwareCache::_mainRuntime = nullptr;
5
+ std::atomic<jsi::Runtime *> BaseRuntimeAwareCache::_mainRuntime{nullptr};
6
6
 
7
7
  } // namespace RNJsi
@@ -2,7 +2,9 @@
2
2
 
3
3
  #include <jsi/jsi.h>
4
4
 
5
+ #include <atomic>
5
6
  #include <memory>
7
+ #include <mutex>
6
8
  #include <unordered_map>
7
9
  #include <utility>
8
10
 
@@ -14,17 +16,21 @@ namespace jsi = facebook::jsi;
14
16
 
15
17
  class BaseRuntimeAwareCache {
16
18
  public:
17
- static void setMainJsRuntime(jsi::Runtime *rt) { _mainRuntime = rt; }
19
+ static void setMainJsRuntime(jsi::Runtime *rt) {
20
+ // Atomic: hot reload rewrites this from the JS thread while worklet
21
+ // runtime threads read it concurrently.
22
+ _mainRuntime.store(rt, std::memory_order_release);
23
+ }
18
24
  static jsi::Runtime *getMainJsRuntime() {
19
- assert(_mainRuntime != nullptr &&
20
- "Expected main Javascript runtime to be set in the "
21
- "BaseRuntimeAwareCache class.");
25
+ auto *rt = _mainRuntime.load(std::memory_order_acquire);
26
+ assert(rt != nullptr && "Expected main Javascript runtime to be set in the "
27
+ "BaseRuntimeAwareCache class.");
22
28
 
23
- return _mainRuntime;
29
+ return rt;
24
30
  }
25
31
 
26
32
  private:
27
- static jsi::Runtime *_mainRuntime;
33
+ static std::atomic<jsi::Runtime *> _mainRuntime;
28
34
  };
29
35
 
30
36
  /**
@@ -55,7 +61,10 @@ class RuntimeAwareCache : public BaseRuntimeAwareCache,
55
61
  public:
56
62
  void onRuntimeDestroyed(jsi::Runtime *rt) override {
57
63
  if (getMainJsRuntime() != rt) {
58
- // We are removing a secondary runtime
64
+ // We are removing a secondary runtime. This is invoked by
65
+ // RuntimeLifecycleMonitor on the destroyed runtime's thread, which may
66
+ // run concurrently with get() on another runtime's thread.
67
+ std::lock_guard<std::mutex> lock(_secondaryCachesMutex);
59
68
  _secondaryRuntimeCaches.erase(rt);
60
69
  }
61
70
  }
@@ -74,6 +83,14 @@ public:
74
83
  if (getMainJsRuntime() == &rt) {
75
84
  return _primaryCache;
76
85
  } else {
86
+ // Guard the secondary map: it can be mutated concurrently by get()
87
+ // on a worklet runtime's thread and by onRuntimeDestroyed() when
88
+ // another secondary runtime is torn down. The main-runtime path above
89
+ // stays lock-free. References into the map remain valid after the
90
+ // lock is released (unordered_map never invalidates references on
91
+ // insert/erase of other keys, and this runtime's entry can only be
92
+ // erased from this runtime's own thread).
93
+ std::lock_guard<std::mutex> lock(_secondaryCachesMutex);
77
94
  if (_secondaryRuntimeCaches.count(&rt) == 0) {
78
95
  // we only add listener when the secondary runtime is used, this assumes
79
96
  // that the secondary runtime is terminated first. This lets us avoid
@@ -87,11 +104,12 @@ public:
87
104
  T cache;
88
105
  _secondaryRuntimeCaches.emplace(&rt, std::move(cache));
89
106
  }
107
+ return _secondaryRuntimeCaches.at(&rt);
90
108
  }
91
- return _secondaryRuntimeCaches.at(&rt);
92
109
  }
93
110
 
94
111
  private:
112
+ std::mutex _secondaryCachesMutex;
95
113
  std::unordered_map<void *, T> _secondaryRuntimeCaches;
96
114
  T _primaryCache;
97
115
  };