@shopify/react-native-skia 2.9.1-next.1 → 2.10.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (273) hide show
  1. package/android/CMakeLists.txt +1 -5
  2. package/android/cpp/jni/JniWebGPUView.cpp +52 -7
  3. package/android/src/main/java/com/shopify/reactnative/skia/WebGPUSurfaceView.java +3 -1
  4. package/android/src/main/java/com/shopify/reactnative/skia/WebGPUTextureView.java +11 -5
  5. package/android/src/main/java/com/shopify/reactnative/skia/WebGPUView.java +10 -7
  6. package/android/src/main/java/com/shopify/reactnative/skia/WebGPUViewAPI.java +7 -2
  7. package/android/src/main/java/com/shopify/reactnative/skia/WebGPUViewManager.java +1 -1
  8. package/apple/WebGPUMetalView.mm +49 -6
  9. package/cpp/api/JsiNativeBuffer.h +15 -10
  10. package/cpp/api/JsiSkAnimatedImage.h +21 -19
  11. package/cpp/api/JsiSkAnimatedImageFactory.h +13 -14
  12. package/cpp/api/JsiSkApi.h +246 -92
  13. package/cpp/api/JsiSkCanvas.h +76 -58
  14. package/cpp/api/JsiSkColor.h +7 -5
  15. package/cpp/api/JsiSkColorFilter.h +15 -8
  16. package/cpp/api/JsiSkColorFilterFactory.h +45 -45
  17. package/cpp/api/JsiSkContourMeasure.h +24 -21
  18. package/cpp/api/JsiSkContourMeasureIter.h +18 -21
  19. package/cpp/api/JsiSkData.h +13 -7
  20. package/cpp/api/JsiSkDataFactory.h +22 -21
  21. package/cpp/api/JsiSkFont.h +56 -44
  22. package/cpp/api/JsiSkFontMgr.h +22 -13
  23. package/cpp/api/JsiSkFontMgrFactory.h +12 -10
  24. package/cpp/api/JsiSkFontStyle.h +14 -12
  25. package/cpp/api/JsiSkImage.h +45 -34
  26. package/cpp/api/JsiSkImageFactory.h +47 -52
  27. package/cpp/api/JsiSkImageFilter.h +21 -11
  28. package/cpp/api/JsiSkImageFilterFactory.h +96 -96
  29. package/cpp/api/JsiSkImageInfo.h +22 -19
  30. package/cpp/api/JsiSkMaskFilter.h +21 -11
  31. package/cpp/api/JsiSkMaskFilterFactory.h +16 -13
  32. package/cpp/api/JsiSkMatrix.h +31 -31
  33. package/cpp/api/JsiSkNativeObjects.h +419 -0
  34. package/cpp/api/JsiSkPaint.h +59 -39
  35. package/cpp/api/JsiSkParagraph.h +39 -32
  36. package/cpp/api/JsiSkParagraphBuilder.h +24 -21
  37. package/cpp/api/JsiSkParagraphBuilderFactory.h +13 -12
  38. package/cpp/api/JsiSkParagraphStyle.h +20 -10
  39. package/cpp/api/JsiSkPath.h +95 -70
  40. package/cpp/api/JsiSkPathBuilder.h +83 -67
  41. package/cpp/api/JsiSkPathBuilderFactory.h +16 -17
  42. package/cpp/api/JsiSkPathEffect.h +21 -11
  43. package/cpp/api/JsiSkPathEffectFactory.h +33 -32
  44. package/cpp/api/JsiSkPathFactory.h +79 -103
  45. package/cpp/api/JsiSkPicture.h +24 -13
  46. package/cpp/api/JsiSkPictureFactory.h +21 -26
  47. package/cpp/api/JsiSkPictureRecorder.h +21 -22
  48. package/cpp/api/JsiSkPoint.h +19 -22
  49. package/cpp/api/JsiSkRRect.h +22 -29
  50. package/cpp/api/JsiSkRSXform.h +26 -30
  51. package/cpp/api/JsiSkRect.h +28 -30
  52. package/cpp/api/JsiSkRuntimeEffect.h +39 -30
  53. package/cpp/api/JsiSkRuntimeEffectFactory.h +12 -12
  54. package/cpp/api/JsiSkRuntimeShaderBuilder.h +25 -18
  55. package/cpp/api/JsiSkSVG.h +13 -13
  56. package/cpp/api/JsiSkSVGFactory.h +17 -20
  57. package/cpp/api/JsiSkShader.h +15 -8
  58. package/cpp/api/JsiSkShaderFactory.h +41 -48
  59. package/cpp/api/JsiSkSkottie.h +49 -39
  60. package/cpp/api/JsiSkStrutStyle.h +18 -8
  61. package/cpp/api/JsiSkSurface.h +24 -24
  62. package/cpp/api/JsiSkSurfaceFactory.h +15 -16
  63. package/cpp/api/JsiSkTextBlob.h +15 -8
  64. package/cpp/api/JsiSkTextBlobFactory.h +25 -28
  65. package/cpp/api/JsiSkTextStyle.h +34 -24
  66. package/cpp/api/JsiSkTypeface.h +19 -12
  67. package/cpp/api/JsiSkTypefaceFactory.h +12 -12
  68. package/cpp/api/JsiSkTypefaceFontProvider.h +30 -25
  69. package/cpp/api/JsiSkTypefaceFontProviderFactory.h +14 -12
  70. package/cpp/api/JsiSkVertices.h +21 -18
  71. package/cpp/api/JsiSkiaContext.h +17 -17
  72. package/cpp/api/JsiSkottieFactory.h +16 -17
  73. package/cpp/api/JsiVideo.h +27 -25
  74. package/cpp/api/recorder/Convertor.h +31 -61
  75. package/cpp/api/recorder/DataTypes.h +8 -16
  76. package/cpp/api/recorder/JsiRecorder.h +83 -55
  77. package/cpp/api/recorder/RNRecorder.h +1 -1
  78. package/cpp/jsi/BoxedNativeObject.h +146 -0
  79. package/cpp/{jsi2 → jsi}/EnumMapper.h +4 -1
  80. package/cpp/{jsi2 → jsi}/NativeObject.h +120 -146
  81. package/cpp/jsi/RuntimeAwareCache.cpp +1 -1
  82. package/cpp/jsi/RuntimeAwareCache.h +26 -8
  83. package/cpp/jsi/ViewProperty.h +5 -11
  84. package/cpp/rnskia/RNSkJsiViewApi.h +20 -11
  85. package/cpp/rnskia/RNSkManager.cpp +29 -25
  86. package/cpp/rnskia/RNSkPictureView.h +1 -1
  87. package/cpp/rnwgpu/ArrayBuffer.h +5 -6
  88. package/cpp/rnwgpu/Canvas.h +4 -2
  89. package/cpp/rnwgpu/SurfaceRegistry.h +469 -131
  90. package/cpp/rnwgpu/api/GPU.cpp +4 -4
  91. package/cpp/rnwgpu/api/GPU.h +1 -1
  92. package/cpp/rnwgpu/api/GPUAdapter.cpp +12 -6
  93. package/cpp/rnwgpu/api/GPUAdapter.h +5 -4
  94. package/cpp/rnwgpu/api/GPUAdapterInfo.h +1 -1
  95. package/cpp/rnwgpu/api/GPUBindGroup.h +1 -1
  96. package/cpp/rnwgpu/api/GPUBindGroupLayout.h +1 -1
  97. package/cpp/rnwgpu/api/GPUBuffer.cpp +12 -2
  98. package/cpp/rnwgpu/api/GPUBuffer.h +4 -3
  99. package/cpp/rnwgpu/api/GPUCanvasContext.cpp +33 -19
  100. package/cpp/rnwgpu/api/GPUCanvasContext.h +4 -2
  101. package/cpp/rnwgpu/api/GPUCommandBuffer.h +1 -1
  102. package/cpp/rnwgpu/api/GPUCommandEncoder.h +1 -1
  103. package/cpp/rnwgpu/api/GPUCompilationInfo.h +1 -1
  104. package/cpp/rnwgpu/api/GPUCompilationMessage.h +1 -1
  105. package/cpp/rnwgpu/api/GPUComputePassEncoder.h +1 -1
  106. package/cpp/rnwgpu/api/GPUComputePipeline.h +1 -1
  107. package/cpp/rnwgpu/api/GPUDevice.cpp +38 -24
  108. package/cpp/rnwgpu/api/GPUDevice.h +12 -10
  109. package/cpp/rnwgpu/api/GPUDeviceLostInfo.h +1 -1
  110. package/cpp/rnwgpu/api/GPUError.h +1 -1
  111. package/cpp/rnwgpu/api/GPUExtent3D.h +1 -1
  112. package/cpp/rnwgpu/api/GPUExternalTexture.h +1 -1
  113. package/cpp/rnwgpu/api/GPUInternalError.h +1 -1
  114. package/cpp/rnwgpu/api/GPUOrigin2D.h +1 -1
  115. package/cpp/rnwgpu/api/GPUOrigin3D.h +1 -1
  116. package/cpp/rnwgpu/api/GPUOutOfMemoryError.h +1 -1
  117. package/cpp/rnwgpu/api/GPUPipelineLayout.h +1 -1
  118. package/cpp/rnwgpu/api/GPUQuerySet.h +1 -1
  119. package/cpp/rnwgpu/api/GPUQueue.cpp +6 -2
  120. package/cpp/rnwgpu/api/GPUQueue.h +4 -4
  121. package/cpp/rnwgpu/api/GPURenderBundle.h +1 -1
  122. package/cpp/rnwgpu/api/GPURenderBundleEncoder.h +1 -1
  123. package/cpp/rnwgpu/api/GPURenderPassEncoder.h +1 -1
  124. package/cpp/rnwgpu/api/GPURenderPipeline.h +1 -1
  125. package/cpp/rnwgpu/api/GPUSampler.h +1 -1
  126. package/cpp/rnwgpu/api/GPUShaderModule.cpp +8 -3
  127. package/cpp/rnwgpu/api/GPUShaderModule.h +4 -4
  128. package/cpp/rnwgpu/api/GPUSharedFence.h +1 -1
  129. package/cpp/rnwgpu/api/GPUSharedTextureMemory.h +1 -1
  130. package/cpp/rnwgpu/api/GPUSupportedLimits.h +1 -1
  131. package/cpp/rnwgpu/api/GPUTexture.h +1 -1
  132. package/cpp/rnwgpu/api/GPUTextureView.h +1 -1
  133. package/cpp/rnwgpu/api/GPUUncapturedErrorEvent.h +1 -1
  134. package/cpp/rnwgpu/api/GPUValidationError.h +1 -1
  135. package/cpp/rnwgpu/api/ImageBitmap.h +1 -1
  136. package/cpp/rnwgpu/api/RNWebGPU.h +21 -1
  137. package/cpp/rnwgpu/api/descriptors/GPUBindGroupDescriptor.h +1 -1
  138. package/cpp/rnwgpu/api/descriptors/GPUBindGroupEntry.h +1 -1
  139. package/cpp/rnwgpu/api/descriptors/GPUBindGroupLayoutDescriptor.h +1 -1
  140. package/cpp/rnwgpu/api/descriptors/GPUBindGroupLayoutEntry.h +1 -1
  141. package/cpp/rnwgpu/api/descriptors/GPUBlendComponent.h +1 -1
  142. package/cpp/rnwgpu/api/descriptors/GPUBlendState.h +1 -1
  143. package/cpp/rnwgpu/api/descriptors/GPUBufferBinding.h +1 -1
  144. package/cpp/rnwgpu/api/descriptors/GPUBufferBindingLayout.h +1 -1
  145. package/cpp/rnwgpu/api/descriptors/GPUBufferDescriptor.h +1 -1
  146. package/cpp/rnwgpu/api/descriptors/GPUCanvasConfiguration.h +1 -1
  147. package/cpp/rnwgpu/api/descriptors/GPUColor.h +1 -1
  148. package/cpp/rnwgpu/api/descriptors/GPUColorTargetState.h +1 -1
  149. package/cpp/rnwgpu/api/descriptors/GPUCommandBufferDescriptor.h +1 -1
  150. package/cpp/rnwgpu/api/descriptors/GPUCommandEncoderDescriptor.h +1 -1
  151. package/cpp/rnwgpu/api/descriptors/GPUComputePassDescriptor.h +1 -1
  152. package/cpp/rnwgpu/api/descriptors/GPUComputePassTimestampWrites.h +1 -1
  153. package/cpp/rnwgpu/api/descriptors/GPUComputePipelineDescriptor.h +1 -1
  154. package/cpp/rnwgpu/api/descriptors/GPUDawnTogglesDescriptor.h +1 -1
  155. package/cpp/rnwgpu/api/descriptors/GPUDepthStencilState.h +1 -1
  156. package/cpp/rnwgpu/api/descriptors/GPUDeviceDescriptor.h +1 -1
  157. package/cpp/rnwgpu/api/descriptors/GPUExternalTextureBindingLayout.h +1 -1
  158. package/cpp/rnwgpu/api/descriptors/GPUExternalTextureDescriptor.h +1 -1
  159. package/cpp/rnwgpu/api/descriptors/GPUFragmentState.h +1 -1
  160. package/cpp/rnwgpu/api/descriptors/GPUImageCopyBuffer.h +1 -1
  161. package/cpp/rnwgpu/api/descriptors/GPUImageCopyExternalImage.h +1 -1
  162. package/cpp/rnwgpu/api/descriptors/GPUImageCopyTexture.h +1 -1
  163. package/cpp/rnwgpu/api/descriptors/GPUImageCopyTextureTagged.h +1 -1
  164. package/cpp/rnwgpu/api/descriptors/GPUImageDataLayout.h +1 -1
  165. package/cpp/rnwgpu/api/descriptors/GPUMultisampleState.h +1 -1
  166. package/cpp/rnwgpu/api/descriptors/GPUPipelineLayoutDescriptor.h +1 -1
  167. package/cpp/rnwgpu/api/descriptors/GPUPrimitiveState.h +1 -1
  168. package/cpp/rnwgpu/api/descriptors/GPUProgrammableStage.h +1 -1
  169. package/cpp/rnwgpu/api/descriptors/GPUQuerySetDescriptor.h +1 -1
  170. package/cpp/rnwgpu/api/descriptors/GPUQueueDescriptor.h +1 -1
  171. package/cpp/rnwgpu/api/descriptors/GPURenderBundleDescriptor.h +1 -1
  172. package/cpp/rnwgpu/api/descriptors/GPURenderBundleEncoderDescriptor.h +1 -1
  173. package/cpp/rnwgpu/api/descriptors/GPURenderPassColorAttachment.h +1 -1
  174. package/cpp/rnwgpu/api/descriptors/GPURenderPassDepthStencilAttachment.h +1 -1
  175. package/cpp/rnwgpu/api/descriptors/GPURenderPassDescriptor.h +1 -1
  176. package/cpp/rnwgpu/api/descriptors/GPURenderPassTimestampWrites.h +1 -1
  177. package/cpp/rnwgpu/api/descriptors/GPURenderPipelineDescriptor.h +1 -1
  178. package/cpp/rnwgpu/api/descriptors/GPURequestAdapterOptions.h +1 -1
  179. package/cpp/rnwgpu/api/descriptors/GPUSamplerBindingLayout.h +1 -1
  180. package/cpp/rnwgpu/api/descriptors/GPUSamplerDescriptor.h +1 -1
  181. package/cpp/rnwgpu/api/descriptors/GPUShaderModuleCompilationHint.h +1 -1
  182. package/cpp/rnwgpu/api/descriptors/GPUShaderModuleDescriptor.h +1 -1
  183. package/cpp/rnwgpu/api/descriptors/GPUSharedFenceDescriptor.h +1 -1
  184. package/cpp/rnwgpu/api/descriptors/GPUSharedFenceState.h +1 -1
  185. package/cpp/rnwgpu/api/descriptors/GPUSharedTextureMemoryDescriptor.h +1 -1
  186. package/cpp/rnwgpu/api/descriptors/GPUStencilFaceState.h +1 -1
  187. package/cpp/rnwgpu/api/descriptors/GPUStorageTextureBindingLayout.h +1 -1
  188. package/cpp/rnwgpu/api/descriptors/GPUTextureBindingLayout.h +1 -1
  189. package/cpp/rnwgpu/api/descriptors/GPUTextureDescriptor.h +1 -1
  190. package/cpp/rnwgpu/api/descriptors/GPUTextureViewDescriptor.h +1 -1
  191. package/cpp/rnwgpu/api/descriptors/GPUUncapturedErrorEventInit.h +1 -1
  192. package/cpp/rnwgpu/api/descriptors/GPUVertexAttribute.h +1 -1
  193. package/cpp/rnwgpu/api/descriptors/GPUVertexBufferLayout.h +1 -1
  194. package/cpp/rnwgpu/api/descriptors/GPUVertexState.h +1 -1
  195. package/cpp/rnwgpu/api/descriptors/Unions.h +1 -1
  196. package/cpp/rnwgpu/async/AsyncTaskHandle.cpp +20 -21
  197. package/cpp/rnwgpu/async/RuntimeContext.cpp +5 -0
  198. package/cpp/rnwgpu/async/RuntimeContext.h +15 -2
  199. package/lib/commonjs/external/reanimated/renderHelpers.d.ts +15 -0
  200. package/lib/commonjs/external/reanimated/renderHelpers.js +30 -1
  201. package/lib/commonjs/external/reanimated/renderHelpers.js.map +1 -1
  202. package/lib/commonjs/skia/NativeSetup.js +4 -0
  203. package/lib/commonjs/skia/NativeSetup.js.map +1 -1
  204. package/lib/commonjs/skia/SkiaWorkletSerialization.d.ts +1 -0
  205. package/lib/commonjs/skia/SkiaWorkletSerialization.js +66 -0
  206. package/lib/commonjs/skia/SkiaWorkletSerialization.js.map +1 -0
  207. package/lib/commonjs/sksg/Container.native.js +20 -1
  208. package/lib/commonjs/sksg/Container.native.js.map +1 -1
  209. package/lib/commonjs/views/WebGPUCanvas.d.ts +1 -0
  210. package/lib/commonjs/views/WebGPUCanvas.js +13 -0
  211. package/lib/commonjs/views/WebGPUCanvas.js.map +1 -1
  212. package/lib/module/external/reanimated/renderHelpers.d.ts +15 -0
  213. package/lib/module/external/reanimated/renderHelpers.js +29 -0
  214. package/lib/module/external/reanimated/renderHelpers.js.map +1 -1
  215. package/lib/module/skia/NativeSetup.js +4 -0
  216. package/lib/module/skia/NativeSetup.js.map +1 -1
  217. package/lib/module/skia/SkiaWorkletSerialization.d.ts +1 -0
  218. package/lib/module/skia/SkiaWorkletSerialization.js +59 -0
  219. package/lib/module/skia/SkiaWorkletSerialization.js.map +1 -0
  220. package/lib/module/sksg/Container.native.js +21 -2
  221. package/lib/module/sksg/Container.native.js.map +1 -1
  222. package/lib/module/views/WebGPUCanvas.d.ts +1 -0
  223. package/lib/module/views/WebGPUCanvas.js +14 -1
  224. package/lib/module/views/WebGPUCanvas.js.map +1 -1
  225. package/lib/typescript/lib/commonjs/external/reanimated/renderHelpers.d.ts +2 -0
  226. package/lib/typescript/lib/commonjs/skia/SkiaWorkletSerialization.d.ts +2 -0
  227. package/lib/typescript/lib/module/external/reanimated/renderHelpers.d.ts +15 -0
  228. package/lib/typescript/lib/module/skia/SkiaWorkletSerialization.d.ts +1 -0
  229. package/lib/typescript/src/external/reanimated/renderHelpers.d.ts +15 -0
  230. package/lib/typescript/src/skia/SkiaWorkletSerialization.d.ts +1 -0
  231. package/lib/typescript/src/views/WebGPUCanvas.d.ts +1 -0
  232. package/package.json +12 -8
  233. package/react-native-skia.podspec +1 -2
  234. package/src/external/reanimated/renderHelpers.ts +30 -0
  235. package/src/skia/NativeSetup.ts +5 -0
  236. package/src/skia/SkiaWorkletSerialization.ts +67 -0
  237. package/src/sksg/Container.native.ts +40 -2
  238. package/src/views/WebGPUCanvas.tsx +17 -1
  239. package/cpp/api/JsiSkHostObjects.h +0 -257
  240. package/cpp/dawn/include/dawn/dawn_proc.h +0 -53
  241. package/cpp/dawn/include/dawn/dawn_proc_table.h +0 -330
  242. package/cpp/dawn/include/dawn/dawn_thread_dispatch_proc.h +0 -47
  243. package/cpp/dawn/include/dawn/dawn_version.h +0 -41
  244. package/cpp/dawn/include/dawn/native/D3D11Backend.h +0 -65
  245. package/cpp/dawn/include/dawn/native/D3D12Backend.h +0 -86
  246. package/cpp/dawn/include/dawn/native/D3DBackend.h +0 -56
  247. package/cpp/dawn/include/dawn/native/DawnNative.h +0 -369
  248. package/cpp/dawn/include/dawn/native/MetalBackend.h +0 -56
  249. package/cpp/dawn/include/dawn/native/NullBackend.h +0 -39
  250. package/cpp/dawn/include/dawn/native/OpenGLBackend.h +0 -89
  251. package/cpp/dawn/include/dawn/native/VulkanBackend.h +0 -183
  252. package/cpp/dawn/include/dawn/native/WebGPUBackend.h +0 -49
  253. package/cpp/dawn/include/dawn/native/dawn_native_export.h +0 -49
  254. package/cpp/dawn/include/dawn/platform/DawnPlatform.h +0 -210
  255. package/cpp/dawn/include/dawn/platform/dawn_platform_export.h +0 -49
  256. package/cpp/dawn/include/dawn/replay/Replay.h +0 -99
  257. package/cpp/dawn/include/dawn/replay/dawn_replay_export.h +0 -49
  258. package/cpp/dawn/include/dawn/webgpu_cpp_print.h +0 -2844
  259. package/cpp/dawn/include/tint/tint.h +0 -90
  260. package/cpp/dawn/include/webgpu/webgpu.h +0 -4987
  261. package/cpp/dawn/include/webgpu/webgpu_cpp.h +0 -10080
  262. package/cpp/dawn/include/webgpu/webgpu_cpp_chained_struct.h +0 -57
  263. package/cpp/dawn/include/webgpu/webgpu_enum_class_bitmasks.h +0 -161
  264. package/cpp/dawn/include/webgpu/webgpu_glfw.h +0 -88
  265. package/cpp/jsi/JsiHostObject.cpp +0 -137
  266. package/cpp/jsi/JsiHostObject.h +0 -385
  267. package/cpp/skia/src/gpu/graphite/ContextOptionsPriv.h +0 -45
  268. package/cpp/skia/src/gpu/graphite/ResourceTypes.h +0 -360
  269. package/cpp/skia/src/gpu/graphite/TextureProxyView.h +0 -105
  270. package/libs/.graphite +0 -1
  271. /package/cpp/{jsi2 → jsi}/JSIConverter.h +0 -0
  272. /package/cpp/{jsi2 → jsi}/Promise.cpp +0 -0
  273. /package/cpp/{jsi2 → jsi}/Promise.h +0 -0
@@ -99,10 +99,10 @@ add_library(
99
99
  "${PROJECT_SOURCE_DIR}/cpp/rnskia-android/AHardwareBufferUtils.cpp"
100
100
  "${PROJECT_SOURCE_DIR}/cpp/rnskia-android/RNSkAndroidVideo.cpp"
101
101
 
102
- "${PROJECT_SOURCE_DIR}/../cpp/jsi/JsiHostObject.cpp"
103
102
  "${PROJECT_SOURCE_DIR}/../cpp/jsi/RuntimeLifecycleMonitor.cpp"
104
103
  "${PROJECT_SOURCE_DIR}/../cpp/jsi/RuntimeAwareCache.cpp"
105
104
  "${PROJECT_SOURCE_DIR}/../cpp/jsi/JsiPromises.cpp"
105
+ "${PROJECT_SOURCE_DIR}/../cpp/jsi/Promise.cpp"
106
106
 
107
107
  "${PROJECT_SOURCE_DIR}/../cpp/rnskia/RNSkManager.cpp"
108
108
 
@@ -115,10 +115,7 @@ add_library(
115
115
  )
116
116
 
117
117
  if(SK_GRAPHITE)
118
- # WebGPU JSI infrastructure (jsi2)
119
118
  target_sources(${PACKAGE_NAME} PRIVATE
120
- "${PROJECT_SOURCE_DIR}/../cpp/jsi2/Promise.cpp"
121
-
122
119
  # WebGPU async system
123
120
  "${PROJECT_SOURCE_DIR}/../cpp/rnwgpu/async/AsyncTaskHandle.cpp"
124
121
  "${PROJECT_SOURCE_DIR}/../cpp/rnwgpu/async/RuntimeContext.cpp"
@@ -181,7 +178,6 @@ target_include_directories(
181
178
 
182
179
  # WebGPU bindings
183
180
  ../cpp
184
- ../cpp/jsi2
185
181
  ../cpp/rnwgpu
186
182
  ../cpp/rnwgpu/api
187
183
  ../cpp/rnwgpu/api/descriptors
@@ -2,9 +2,35 @@
2
2
  #include <jni.h>
3
3
 
4
4
  #ifdef SK_GRAPHITE
5
+ #include <memory>
6
+ #include <utility>
7
+
8
+ #include <ReactCommon/CallInvoker.h>
9
+
5
10
  #include "rnskia/RNDawnContext.h"
6
11
  #include "rnwgpu/SurfaceRegistry.h"
12
+ #include "rnwgpu/async/RuntimeContext.h"
7
13
  #include "webgpu/webgpu_cpp.h"
14
+
15
+ namespace {
16
+ // Applies a surface attach latched by the platform UI thread (see
17
+ // SurfaceInfo::applyPendingAttach) from the JS thread. Surface attaches are
18
+ // normally adopted at the next frame boundary by whichever thread renders;
19
+ // this flush covers contexts that are not actively rendering (static
20
+ // content), so the last offscreen frame still makes it on screen. Mirrors
21
+ // react-native-webgpu's RNWebGPUManager::flushPendingSurfaceTransition.
22
+ void flushPendingSurfaceTransition(std::shared_ptr<rnwgpu::SurfaceInfo> info) {
23
+ if (info == nullptr) {
24
+ return;
25
+ }
26
+ auto invoker = rnwgpu::async::RuntimeContext::mainCallInvoker();
27
+ if (invoker == nullptr) {
28
+ return;
29
+ }
30
+ invoker->invokeAsync(
31
+ [info = std::move(info)] { info->applyPendingAttach(); });
32
+ }
33
+ } // namespace
8
34
  #endif
9
35
 
10
36
  extern "C" JNIEXPORT void JNICALL
@@ -12,7 +38,12 @@ Java_com_shopify_reactnative_skia_WebGPUView_onSurfaceCreate(
12
38
  JNIEnv *env, jobject thiz, jobject jSurface, jint contextId, jfloat width,
13
39
  jfloat height) {
14
40
  #ifdef SK_GRAPHITE
41
+ // ANativeWindow_fromSurface acquires a reference; SurfaceInfo releases it
42
+ // (via the releaser below) once it is done with the window.
15
43
  auto window = ANativeWindow_fromSurface(env, jSurface);
44
+ if (window == nullptr) {
45
+ return;
46
+ }
16
47
  auto &registry = rnwgpu::SurfaceRegistry::getInstance();
17
48
  auto &dawnContext = RNSkia::DawnContext::getInstance();
18
49
  auto gpu = dawnContext.getWGPUInstance();
@@ -24,10 +55,17 @@ Java_com_shopify_reactnative_skia_WebGPUView_onSurfaceCreate(
24
55
  surfaceDescriptor.nextInChain = &androidSurfaceDesc;
25
56
  auto surface = gpu.CreateSurface(&surfaceDescriptor);
26
57
 
27
- registry
28
- .getSurfaceInfoOrCreate(contextId, gpu, static_cast<int>(width),
29
- static_cast<int>(height))
30
- ->switchToOnscreen(window, surface);
58
+ // Find-or-create + attach runs atomically under the registry lock so a
59
+ // concurrent destroyContext cannot orphan this surface.
60
+ auto info = registry.attachSurface(
61
+ contextId, gpu, static_cast<int>(width), static_cast<int>(height), window,
62
+ surface, [](void *nativeSurface) {
63
+ ANativeWindow_release(static_cast<ANativeWindow *>(nativeSurface));
64
+ });
65
+ // The attach is adopted at the next frame boundary by the rendering thread;
66
+ // schedule a flush so contexts that are not currently rendering still pick
67
+ // it up (and present their last offscreen frame).
68
+ flushPendingSurfaceTransition(info);
31
69
  #endif
32
70
  }
33
71
 
@@ -57,11 +95,18 @@ Java_com_shopify_reactnative_skia_WebGPUView_switchToOffscreenSurface(
57
95
  }
58
96
 
59
97
  extern "C" JNIEXPORT void JNICALL
60
- Java_com_shopify_reactnative_skia_WebGPUView_onSurfaceDestroy(JNIEnv *env,
61
- jobject thiz,
62
- jint contextId) {
98
+ Java_com_shopify_reactnative_skia_WebGPUView_onViewDestroyed(JNIEnv *env,
99
+ jobject thiz,
100
+ jint contextId) {
63
101
  #ifdef SK_GRAPHITE
102
+ // The view dies with its Canvas (contextIds are never reused), so view
103
+ // teardown retires the registry entry. The JS-side cleanup
104
+ // (RNWebGPU.destroyContext) only handles entries that never had a native
105
+ // surface; see RNWebGPU::destroyContext for the ownership split.
64
106
  auto &registry = rnwgpu::SurfaceRegistry::getInstance();
107
+ if (auto info = registry.getSurfaceInfo(contextId)) {
108
+ info->detachSurface();
109
+ }
65
110
  registry.removeSurfaceInfo(contextId);
66
111
  #endif
67
112
  }
@@ -21,7 +21,9 @@ public class WebGPUSurfaceView extends SurfaceView implements SurfaceHolder.Call
21
21
  @Override
22
22
  protected void onDetachedFromWindow() {
23
23
  super.onDetachedFromWindow();
24
- mApi.surfaceDestroyed();
24
+ // surfaceDestroyed() normally fires during detach as well; going offscreen
25
+ // is idempotent, so this is just a safety net for paths where it does not.
26
+ mApi.surfaceOffscreen();
25
27
  }
26
28
 
27
29
  @Override
@@ -11,6 +11,7 @@ import androidx.annotation.NonNull;
11
11
  public class WebGPUTextureView extends TextureView implements TextureView.SurfaceTextureListener {
12
12
 
13
13
  WebGPUViewAPI mApi;
14
+ private Surface mSurface;
14
15
 
15
16
  public WebGPUTextureView(Context context, WebGPUViewAPI api) {
16
17
  super(context);
@@ -21,19 +22,24 @@ public class WebGPUTextureView extends TextureView implements TextureView.Surfac
21
22
 
22
23
  @Override
23
24
  public void onSurfaceTextureAvailable(@NonNull SurfaceTexture surfaceTexture, int width, int height) {
24
- Surface surface = new Surface(surfaceTexture);
25
- mApi.surfaceCreated(surface);
25
+ mSurface = new Surface(surfaceTexture);
26
+ mApi.surfaceCreated(mSurface);
26
27
  }
27
28
 
28
29
  @Override
29
30
  public void onSurfaceTextureSizeChanged(@NonNull SurfaceTexture surfaceTexture, int width, int height) {
30
- Surface surface = new Surface(surfaceTexture);
31
- mApi.surfaceChanged(surface);
31
+ mApi.surfaceChanged(mSurface);
32
32
  }
33
33
 
34
34
  @Override
35
35
  public boolean onSurfaceTextureDestroyed(@NonNull SurfaceTexture surfaceTexture) {
36
- mApi.surfaceDestroyed();
36
+ // Detach first (synchronous through JNI) so the native side has dropped
37
+ // its window reference before we release ours.
38
+ mApi.surfaceOffscreen();
39
+ if (mSurface != null) {
40
+ mSurface.release();
41
+ mSurface = null;
42
+ }
37
43
  return true;
38
44
  }
39
45
 
@@ -61,16 +61,19 @@ public class WebGPUView extends ReactViewGroup implements WebGPUViewAPI {
61
61
  onSurfaceChanged(surface, mContextId, width, height);
62
62
  }
63
63
 
64
- @Override
65
- public void surfaceDestroyed() {
66
- onSurfaceDestroy(mContextId);
67
- }
68
-
69
64
  @Override
70
65
  public void surfaceOffscreen() {
71
66
  switchToOffscreenSurface(mContextId);
72
67
  }
73
68
 
69
+ /**
70
+ * Called from WebGPUViewManager.onDropViewInstance when React removes this
71
+ * view: the view dies with its Canvas, so it retires the registry entry.
72
+ */
73
+ public void destroy() {
74
+ onViewDestroyed(mContextId);
75
+ }
76
+
74
77
  @DoNotStrip
75
78
  private native void onSurfaceCreate(
76
79
  Surface surface,
@@ -88,8 +91,8 @@ public class WebGPUView extends ReactViewGroup implements WebGPUViewAPI {
88
91
  );
89
92
 
90
93
  @DoNotStrip
91
- private native void onSurfaceDestroy(int contextId);
94
+ private native void switchToOffscreenSurface(int contextId);
92
95
 
93
96
  @DoNotStrip
94
- private native void switchToOffscreenSurface(int contextId);
97
+ private native void onViewDestroyed(int contextId);
95
98
  }
@@ -2,13 +2,18 @@ package com.shopify.reactnative.skia;
2
2
 
3
3
  import android.view.Surface;
4
4
 
5
+ /**
6
+ * Surface lifecycle events a WebGPU child view reports. The registry entry
7
+ * itself is owned by the JS Canvas component (created lazily, removed via
8
+ * RNWebGPU.destroyContext on unmount); views only attach and detach surfaces.
9
+ * A detached context keeps rendering into an offscreen texture whose content
10
+ * is blitted onto the next attached surface.
11
+ */
5
12
  public interface WebGPUViewAPI {
6
13
 
7
14
  void surfaceCreated(Surface surface);
8
15
 
9
16
  void surfaceChanged(Surface surface);
10
17
 
11
- void surfaceDestroyed();
12
-
13
18
  void surfaceOffscreen();
14
19
  }
@@ -53,6 +53,6 @@ public class WebGPUViewManager extends ReactViewManager implements SkiaWebGPUVie
53
53
  @Override
54
54
  public void onDropViewInstance(@NonNull ReactViewGroup view) {
55
55
  super.onDropViewInstance(view);
56
- ((WebGPUView) view).surfaceDestroyed();
56
+ ((WebGPUView) view).destroy();
57
57
  }
58
58
  }
@@ -5,8 +5,30 @@
5
5
  #import "webgpu/webgpu_cpp.h"
6
6
  #import <QuartzCore/CAMetalLayer.h>
7
7
 
8
+ #import <ReactCommon/CallInvoker.h>
9
+
8
10
  #import "rnskia/RNDawnContext.h"
9
11
  #import "rnwgpu/SurfaceRegistry.h"
12
+ #import "rnwgpu/async/RuntimeContext.h"
13
+
14
+ namespace {
15
+ // Applies a surface attach latched by the platform UI thread (see
16
+ // SurfaceInfo::applyPendingAttach) from the JS thread. Surface attaches are
17
+ // normally adopted at the next frame boundary by whichever thread renders;
18
+ // this flush covers contexts that are not actively rendering (static
19
+ // content), so the last offscreen frame still makes it on screen. Mirrors
20
+ // react-native-webgpu's RNWebGPUManager::flushPendingSurfaceTransition.
21
+ void flushPendingSurfaceTransition(std::shared_ptr<rnwgpu::SurfaceInfo> info) {
22
+ if (info == nullptr) {
23
+ return;
24
+ }
25
+ auto invoker = rnwgpu::async::RuntimeContext::mainCallInvoker();
26
+ if (invoker == nullptr) {
27
+ return;
28
+ }
29
+ invoker->invokeAsync([info = std::move(info)] { info->applyPendingAttach(); });
30
+ }
31
+ } // namespace
10
32
 
11
33
  @implementation WebGPUMetalView {
12
34
  BOOL _isConfigured;
@@ -29,7 +51,11 @@
29
51
 
30
52
  - (void)configure {
31
53
  auto size = self.frame.size;
32
- void *nativeSurface = (__bridge void *)self.layer;
54
+ // Retain the layer for as long as SurfaceInfo holds the pointer: the
55
+ // latched attach (and the flush lambda that adopts it) can outlive this
56
+ // view, e.g. across a dev reload where the registry is cleared before
57
+ // dealloc runs. Balanced by the releaser below.
58
+ void *nativeSurface = (void *)CFBridgingRetain(self.layer);
33
59
  auto &registry = rnwgpu::SurfaceRegistry::getInstance();
34
60
  auto &dawnContext = RNSkia::DawnContext::getInstance();
35
61
  auto gpu = dawnContext.getWGPUInstance();
@@ -41,10 +67,21 @@
41
67
  surfaceDescriptor.nextInChain = &metalSurfaceDesc;
42
68
  auto surface = gpu.CreateSurface(&surfaceDescriptor);
43
69
 
44
- registry
45
- .getSurfaceInfoOrCreate([_contextId intValue], gpu, size.width,
46
- size.height)
47
- ->switchToOnscreen(nativeSurface, surface);
70
+ // Find-or-create + attach runs atomically under the registry lock so a
71
+ // concurrent destroyContext cannot orphan this surface.
72
+ auto info = registry.attachSurface(
73
+ [_contextId intValue], gpu, size.width, size.height, nativeSurface,
74
+ surface, [](void *layer) {
75
+ // The releaser can run on the rendering thread; CALayer teardown
76
+ // belongs on the main thread.
77
+ dispatch_async(dispatch_get_main_queue(), ^{
78
+ CFBridgingRelease(layer);
79
+ });
80
+ });
81
+ // The attach is adopted at the next frame boundary by the rendering thread;
82
+ // schedule a flush so contexts that are not currently rendering still pick
83
+ // it up (and present their last offscreen frame).
84
+ flushPendingSurfaceTransition(info);
48
85
  }
49
86
 
50
87
  - (void)update {
@@ -57,8 +94,14 @@
57
94
  }
58
95
 
59
96
  - (void)dealloc {
97
+ // The view dies with its Canvas (contextIds are never reused), so view
98
+ // teardown retires the registry entry. The JS-side cleanup
99
+ // (RNWebGPU.destroyContext) only handles entries that never had a native
100
+ // surface; see RNWebGPU::destroyContext for the ownership split.
60
101
  auto &registry = rnwgpu::SurfaceRegistry::getInstance();
61
- // Remove the surface info from the registry
102
+ if (auto info = registry.getSurfaceInfo([_contextId intValue])) {
103
+ info->detachSurface();
104
+ }
62
105
  registry.removeSurfaceInfo([_contextId intValue]);
63
106
  }
64
107
 
@@ -6,6 +6,7 @@
6
6
  #include <jsi/jsi.h>
7
7
 
8
8
  #include "JsiSkImage.h"
9
+ #include "JsiSkNativeObjects.h"
9
10
 
10
11
  namespace RNSkia {
11
12
 
@@ -15,8 +16,11 @@ namespace jsi = facebook::jsi;
15
16
  Implementation of the ParagraphBuilderFactory for making ParagraphBuilder JSI
16
17
  object
17
18
  */
18
- class JsiNativeBufferFactory : public JsiSkHostObject {
19
+ class JsiNativeBufferFactory
20
+ : public JsiSkNativeObject<JsiNativeBufferFactory> {
19
21
  public:
22
+ static constexpr const char *CLASS_NAME = "NativeBufferFactory";
23
+
20
24
  JSI_HOST_FUNCTION(MakeFromImage) {
21
25
  auto image = JsiSkImage::fromValue(runtime, arguments[0]);
22
26
  image->makeNonTextureImage();
@@ -40,18 +44,19 @@ public:
40
44
  return jsi::Value::undefined();
41
45
  }
42
46
 
43
- JSI_EXPORT_FUNCTIONS(JSI_EXPORT_FUNC(JsiNativeBufferFactory, Release),
44
- JSI_EXPORT_FUNC(JsiNativeBufferFactory, MakeFromImage),
45
- JSI_EXPORT_FUNC(JsiNativeBufferFactory, MakeTestBuffer))
46
-
47
- size_t getMemoryPressure() const override { return 1024; }
48
-
49
- std::string getObjectType() const override {
50
- return "JsiNativeBufferFactory";
47
+ static void definePrototype(jsi::Runtime &runtime, jsi::Object &prototype) {
48
+ installHostMethod(runtime, prototype, "Release",
49
+ &JsiNativeBufferFactory::Release);
50
+ installHostMethod(runtime, prototype, "MakeFromImage",
51
+ &JsiNativeBufferFactory::MakeFromImage);
52
+ installHostMethod(runtime, prototype, "MakeTestBuffer",
53
+ &JsiNativeBufferFactory::MakeTestBuffer);
51
54
  }
52
55
 
56
+ size_t getMemoryPressure() override { return 1024; }
57
+
53
58
  explicit JsiNativeBufferFactory(std::shared_ptr<RNSkPlatformContext> context)
54
- : JsiSkHostObject(std::move(context)) {}
59
+ : JsiSkNativeObject<JsiNativeBufferFactory>(std::move(context)) {}
55
60
  };
56
61
 
57
62
  } // namespace RNSkia
@@ -7,7 +7,7 @@
7
7
  #include <string>
8
8
  #include <utility>
9
9
 
10
- #include "JsiSkHostObjects.h"
10
+ #include "JsiSkNativeObjects.h"
11
11
  #include "api/third_party/base64.h"
12
12
 
13
13
  #pragma clang diagnostic push
@@ -29,15 +29,16 @@ namespace RNSkia {
29
29
  namespace jsi = facebook::jsi;
30
30
 
31
31
  class JsiSkAnimatedImage
32
- : public JsiSkWrappingSkPtrHostObject<SkAnimatedImage> {
32
+ : public JsiSkWrappingSkPtrNativeObject<JsiSkAnimatedImage,
33
+ SkAnimatedImage> {
33
34
  public:
35
+ static constexpr const char *CLASS_NAME = "AnimatedImage";
36
+
34
37
  // TODO-API: Properties?
35
38
  JSI_HOST_FUNCTION(getCurrentFrame) {
36
39
  auto image = getObject()->getCurrentFrame();
37
- auto hostObjectInstance =
38
- std::make_shared<JsiSkImage>(getContext(), std::move(image));
39
- return JSI_CREATE_HOST_OBJECT_WITH_MEMORY_PRESSURE(
40
- runtime, hostObjectInstance, getContext());
40
+ return makeJsiObject(
41
+ runtime, std::make_shared<JsiSkImage>(getContext(), std::move(image)));
41
42
  }
42
43
 
43
44
  JSI_HOST_FUNCTION(getFrameCount) {
@@ -52,21 +53,24 @@ public:
52
53
  return static_cast<int>(getObject()->decodeNextFrame());
53
54
  }
54
55
 
55
- EXPORT_JSI_API_TYPENAME(JsiSkAnimatedImage, AnimatedImage)
56
-
57
- JSI_EXPORT_FUNCTIONS(JSI_EXPORT_FUNC(JsiSkAnimatedImage, dispose),
58
- JSI_EXPORT_FUNC(JsiSkAnimatedImage, getFrameCount),
59
- JSI_EXPORT_FUNC(JsiSkAnimatedImage, getCurrentFrame),
60
- JSI_EXPORT_FUNC(JsiSkAnimatedImage,
61
- currentFrameDuration),
62
- JSI_EXPORT_FUNC(JsiSkAnimatedImage, decodeNextFrame))
56
+ static void definePrototype(jsi::Runtime &runtime, jsi::Object &prototype) {
57
+ installCommon(runtime, prototype);
58
+ installHostMethod(runtime, prototype, "getFrameCount",
59
+ &JsiSkAnimatedImage::getFrameCount);
60
+ installHostMethod(runtime, prototype, "getCurrentFrame",
61
+ &JsiSkAnimatedImage::getCurrentFrame);
62
+ installHostMethod(runtime, prototype, "currentFrameDuration",
63
+ &JsiSkAnimatedImage::currentFrameDuration);
64
+ installHostMethod(runtime, prototype, "decodeNextFrame",
65
+ &JsiSkAnimatedImage::decodeNextFrame);
66
+ }
63
67
 
64
68
  JsiSkAnimatedImage(std::shared_ptr<RNSkPlatformContext> context,
65
69
  const sk_sp<SkAnimatedImage> image)
66
- : JsiSkWrappingSkPtrHostObject<SkAnimatedImage>(std::move(context),
67
- std::move(image)) {}
70
+ : JsiSkWrappingSkPtrNativeObject<JsiSkAnimatedImage, SkAnimatedImage>(
71
+ std::move(context), std::move(image)) {}
68
72
 
69
- size_t getMemoryPressure() const override {
73
+ size_t getMemoryPressure() override {
70
74
  auto animation = getObject();
71
75
  if (!animation) {
72
76
  return 0;
@@ -131,8 +135,6 @@ public:
131
135
 
132
136
  return estimated;
133
137
  }
134
-
135
- std::string getObjectType() const override { return "JsiSkAnimatedImage"; }
136
138
  };
137
139
 
138
140
  } // namespace RNSkia
@@ -5,17 +5,20 @@
5
5
 
6
6
  #include <jsi/jsi.h>
7
7
 
8
- #include "jsi/JsiPromises.h"
9
8
  #include "JsiSkAnimatedImage.h"
10
9
  #include "JsiSkData.h"
11
- #include "JsiSkHostObjects.h"
10
+ #include "JsiSkNativeObjects.h"
11
+ #include "jsi/JsiPromises.h"
12
12
 
13
13
  namespace RNSkia {
14
14
 
15
15
  namespace jsi = facebook::jsi;
16
16
 
17
- class JsiSkAnimatedImageFactory : public JsiSkHostObject {
17
+ class JsiSkAnimatedImageFactory
18
+ : public JsiSkNativeObject<JsiSkAnimatedImageFactory> {
18
19
  public:
20
+ static constexpr const char *CLASS_NAME = "AnimatedImageFactory";
21
+
19
22
  JSI_HOST_FUNCTION(MakeAnimatedImageFromEncoded) {
20
23
  auto data = JsiSkData::fromValue(runtime, arguments[0]);
21
24
  auto codec = SkAndroidCodec::MakeFromData(data);
@@ -23,24 +26,20 @@ public:
23
26
  if (image == nullptr) {
24
27
  return jsi::Value::null();
25
28
  }
26
- auto hostObjectInstance =
27
- std::make_shared<JsiSkAnimatedImage>(getContext(), std::move(image));
28
- return JSI_CREATE_HOST_OBJECT_WITH_MEMORY_PRESSURE(
29
- runtime, hostObjectInstance, getContext());
29
+ return makeJsiObject(runtime, std::make_shared<JsiSkAnimatedImage>(
30
+ getContext(), std::move(image)));
30
31
  }
31
32
 
32
- size_t getMemoryPressure() const override { return 1024; }
33
+ size_t getMemoryPressure() override { return 1024; }
33
34
 
34
- std::string getObjectType() const override {
35
- return "JsiSkAnimatedImageFactory";
35
+ static void definePrototype(jsi::Runtime &runtime, jsi::Object &prototype) {
36
+ installHostMethod(runtime, prototype, "MakeAnimatedImageFromEncoded",
37
+ &JsiSkAnimatedImageFactory::MakeAnimatedImageFromEncoded);
36
38
  }
37
39
 
38
- JSI_EXPORT_FUNCTIONS(JSI_EXPORT_FUNC(JsiSkAnimatedImageFactory,
39
- MakeAnimatedImageFromEncoded))
40
-
41
40
  explicit JsiSkAnimatedImageFactory(
42
41
  std::shared_ptr<RNSkPlatformContext> context)
43
- : JsiSkHostObject(std::move(context)) {}
42
+ : JsiSkNativeObject<JsiSkAnimatedImageFactory>(std::move(context)) {}
44
43
  };
45
44
 
46
45
  } // namespace RNSkia