@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
@@ -2,13 +2,18 @@
2
2
 
3
3
  #include <algorithm>
4
4
  #include <memory>
5
+ #include <string>
5
6
  #include <utility>
7
+ #include <variant>
6
8
  #include <vector>
7
9
 
8
10
  #include <jsi/jsi.h>
9
11
 
10
- #include "JsiSkHostObjects.h"
12
+ #include "JsiSkConverters.h"
13
+ #include "JsiSkFont.h"
11
14
  #include "JsiSkMatrix.h"
15
+ #include "JsiSkNativeObjects.h"
16
+ #include "JsiSkPath.h"
12
17
  #include "JsiSkPathEffect.h"
13
18
  #include "JsiSkPoint.h"
14
19
  #include "JsiSkRRect.h"
@@ -17,7 +22,6 @@
17
22
  #pragma clang diagnostic push
18
23
  #pragma clang diagnostic ignored "-Wdocumentation"
19
24
 
20
- #include "utils/RNSkLog.h"
21
25
  #include "include/core/SkPath.h"
22
26
  #include "include/core/SkPathBuilder.h"
23
27
  #include "include/core/SkPathUtils.h"
@@ -26,6 +30,7 @@
26
30
  #include "include/effects/SkTrimPathEffect.h"
27
31
  #include "include/pathops/SkPathOps.h"
28
32
  #include "include/utils/SkTextUtils.h"
33
+ #include "utils/RNSkLog.h"
29
34
 
30
35
  #pragma clang diagnostic pop
31
36
 
@@ -33,7 +38,7 @@ namespace RNSkia {
33
38
 
34
39
  namespace jsi = facebook::jsi;
35
40
 
36
- class JsiSkPathFactory : public JsiSkHostObject {
41
+ class JsiSkPathFactory : public JsiSkNativeObject<JsiSkPathFactory> {
37
42
 
38
43
  static const int MOVE = 0;
39
44
  static const int LINE = 1;
@@ -42,111 +47,83 @@ class JsiSkPathFactory : public JsiSkHostObject {
42
47
  static const int CUBIC = 4;
43
48
  static const int CLOSE = 5;
44
49
 
50
+ using NullablePath = std::variant<std::nullptr_t, std::shared_ptr<JsiSkPath>>;
51
+
45
52
  public:
46
- JSI_HOST_FUNCTION(Make) {
47
- auto hostObjectInstance =
48
- std::make_shared<JsiSkPath>(getContext(), SkPath());
49
- return JSI_CREATE_HOST_OBJECT_WITH_MEMORY_PRESSURE(
50
- runtime, hostObjectInstance, getContext());
53
+ static constexpr const char *CLASS_NAME = "PathFactory";
54
+
55
+ std::shared_ptr<JsiSkPath> Make() {
56
+ return std::make_shared<JsiSkPath>(getContext(), SkPath());
51
57
  }
52
58
 
53
- JSI_HOST_FUNCTION(MakeFromSVGString) {
54
- auto svgString = arguments[0].asString(runtime).utf8(runtime);
59
+ std::shared_ptr<JsiSkPath> MakeFromSVGString(std::string svgString) {
55
60
  auto result = SkParsePath::FromSVGString(svgString.c_str());
56
61
  if (!result.has_value()) {
57
- throw jsi::JSError(runtime, "Could not parse Svg path");
58
- return jsi::Value(nullptr);
62
+ throw std::runtime_error("Could not parse Svg path");
59
63
  }
60
- auto hostObjectInstance =
61
- std::make_shared<JsiSkPath>(getContext(), std::move(result.value()));
62
- return JSI_CREATE_HOST_OBJECT_WITH_MEMORY_PRESSURE(
63
- runtime, hostObjectInstance, getContext());
64
+ return std::make_shared<JsiSkPath>(getContext(),
65
+ std::move(result.value()));
64
66
  }
65
67
 
66
- JSI_HOST_FUNCTION(MakeFromOp) {
67
- auto one = JsiSkPath::fromValue(runtime, arguments[0])->snapshot();
68
- auto two = JsiSkPath::fromValue(runtime, arguments[1])->snapshot();
69
- SkPathOp op = (SkPathOp)arguments[2].asNumber();
70
- auto result = Op(one, two, op);
68
+ NullablePath MakeFromOp(std::shared_ptr<SkPathBuilder> pathOne,
69
+ std::shared_ptr<SkPathBuilder> pathTwo, double op) {
70
+ auto one = pathOne->snapshot();
71
+ auto two = pathTwo->snapshot();
72
+ auto result = Op(one, two, static_cast<SkPathOp>(op));
71
73
  if (!result.has_value()) {
72
- return jsi::Value(nullptr);
74
+ return nullptr;
73
75
  }
74
- auto hostObjectInstance =
75
- std::make_shared<JsiSkPath>(getContext(), std::move(result.value()));
76
- return JSI_CREATE_HOST_OBJECT_WITH_MEMORY_PRESSURE(
77
- runtime, hostObjectInstance, getContext());
76
+ return std::make_shared<JsiSkPath>(getContext(),
77
+ std::move(result.value()));
78
78
  }
79
79
 
80
- JSI_HOST_FUNCTION(MakeFromCmds) {
80
+ NullablePath MakeFromCmds(std::vector<std::vector<double>> cmds) {
81
81
  SkPathBuilder builder;
82
- auto cmds = arguments[0].asObject(runtime).asArray(runtime);
83
- auto cmdCount = cmds.size(runtime);
84
- for (int i = 0; i < cmdCount; i++) {
85
- auto cmd =
86
- cmds.getValueAtIndex(runtime, i).asObject(runtime).asArray(runtime);
87
- if (cmd.size(runtime) < 1) {
82
+ for (const auto &cmd : cmds) {
83
+ if (cmd.size() < 1) {
88
84
  RNSkLogger::logToConsole("Invalid command found (got an empty array)");
89
- return jsi::Value::null();
85
+ return nullptr;
90
86
  }
91
- auto verb = static_cast<int>(cmd.getValueAtIndex(runtime, 0).asNumber());
87
+ auto verb = static_cast<int>(cmd[0]);
92
88
  switch (verb) {
93
89
  case MOVE: {
94
- if (cmd.size(runtime) < 3) {
90
+ if (cmd.size() < 3) {
95
91
  RNSkLogger::logToConsole("Invalid move command found");
96
- return jsi::Value::null();
92
+ return nullptr;
97
93
  }
98
- auto x = cmd.getValueAtIndex(runtime, 1).asNumber();
99
- auto y = cmd.getValueAtIndex(runtime, 2).asNumber();
100
- builder.moveTo(x, y);
94
+ builder.moveTo(cmd[1], cmd[2]);
101
95
  break;
102
96
  }
103
97
  case LINE: {
104
- if (cmd.size(runtime) < 3) {
98
+ if (cmd.size() < 3) {
105
99
  RNSkLogger::logToConsole("Invalid line command found");
106
- return jsi::Value::null();
100
+ return nullptr;
107
101
  }
108
- auto x = cmd.getValueAtIndex(runtime, 1).asNumber();
109
- auto y = cmd.getValueAtIndex(runtime, 2).asNumber();
110
- builder.lineTo(x, y);
102
+ builder.lineTo(cmd[1], cmd[2]);
111
103
  break;
112
104
  }
113
105
  case QUAD: {
114
- if (cmd.size(runtime) < 5) {
106
+ if (cmd.size() < 5) {
115
107
  RNSkLogger::logToConsole("Invalid line command found");
116
- return jsi::Value::null();
108
+ return nullptr;
117
109
  }
118
- auto x1 = cmd.getValueAtIndex(runtime, 1).asNumber();
119
- auto y1 = cmd.getValueAtIndex(runtime, 2).asNumber();
120
- auto x2 = cmd.getValueAtIndex(runtime, 3).asNumber();
121
- auto y2 = cmd.getValueAtIndex(runtime, 4).asNumber();
122
- builder.quadTo(x1, y1, x2, y2);
110
+ builder.quadTo(cmd[1], cmd[2], cmd[3], cmd[4]);
123
111
  break;
124
112
  }
125
113
  case CONIC: {
126
- if (cmd.size(runtime) < 6) {
114
+ if (cmd.size() < 6) {
127
115
  RNSkLogger::logToConsole("Invalid line command found");
128
- return jsi::Value::null();
116
+ return nullptr;
129
117
  }
130
- auto x1 = cmd.getValueAtIndex(runtime, 1).asNumber();
131
- auto y1 = cmd.getValueAtIndex(runtime, 2).asNumber();
132
- auto x2 = cmd.getValueAtIndex(runtime, 3).asNumber();
133
- auto y2 = cmd.getValueAtIndex(runtime, 4).asNumber();
134
- auto w = cmd.getValueAtIndex(runtime, 5).asNumber();
135
- builder.conicTo(x1, y1, x2, y2, w);
118
+ builder.conicTo(cmd[1], cmd[2], cmd[3], cmd[4], cmd[5]);
136
119
  break;
137
120
  }
138
121
  case CUBIC: {
139
- if (cmd.size(runtime) < 7) {
122
+ if (cmd.size() < 7) {
140
123
  RNSkLogger::logToConsole("Invalid line command found");
141
- return jsi::Value::null();
124
+ return nullptr;
142
125
  }
143
- auto x1 = cmd.getValueAtIndex(runtime, 1).asNumber();
144
- auto y1 = cmd.getValueAtIndex(runtime, 2).asNumber();
145
- auto x2 = cmd.getValueAtIndex(runtime, 3).asNumber();
146
- auto y2 = cmd.getValueAtIndex(runtime, 4).asNumber();
147
- auto x3 = cmd.getValueAtIndex(runtime, 5).asNumber();
148
- auto y3 = cmd.getValueAtIndex(runtime, 6).asNumber();
149
- builder.cubicTo(x1, y1, x2, y2, x3, y3);
126
+ builder.cubicTo(cmd[1], cmd[2], cmd[3], cmd[4], cmd[5], cmd[6]);
150
127
  break;
151
128
  }
152
129
  case CLOSE: {
@@ -155,118 +132,68 @@ public:
155
132
  }
156
133
  default: {
157
134
  RNSkLogger::logToConsole("Found an unknown command");
158
- return jsi::Value::null();
135
+ return nullptr;
159
136
  }
160
137
  }
161
138
  }
162
- auto hostObjectInstance =
163
- std::make_shared<JsiSkPath>(getContext(), builder.snapshot());
164
- return JSI_CREATE_HOST_OBJECT_WITH_MEMORY_PRESSURE(
165
- runtime, hostObjectInstance, getContext());
139
+ return std::make_shared<JsiSkPath>(getContext(), builder.snapshot());
166
140
  }
167
141
 
168
- JSI_HOST_FUNCTION(MakeFromText) {
169
- auto text = arguments[0].asString(runtime).utf8(runtime);
170
- auto x = arguments[1].asNumber();
171
- auto y = arguments[2].asNumber();
172
- auto font = JsiSkFont::fromValue(runtime, arguments[3]);
142
+ std::shared_ptr<JsiSkPath> MakeFromText(std::string text, double x, double y,
143
+ std::shared_ptr<SkFont> font) {
173
144
  SkPath path;
174
145
  SkTextUtils::GetPath(text.c_str(), strlen(text.c_str()),
175
146
  SkTextEncoding::kUTF8, x, y, *font, &path);
176
- auto hostObjectInstance =
177
- std::make_shared<JsiSkPath>(getContext(), std::move(path));
178
- return JSI_CREATE_HOST_OBJECT_WITH_MEMORY_PRESSURE(
179
- runtime, hostObjectInstance, getContext());
147
+ return std::make_shared<JsiSkPath>(getContext(), std::move(path));
180
148
  }
181
149
 
182
150
  // Static shape factories
183
- JSI_HOST_FUNCTION(Rect) {
184
- auto rect = JsiSkRect::fromValue(runtime, arguments[0]);
185
- auto direction = SkPathDirection::kCW;
186
- if (count >= 2 && arguments[1].getBool()) {
187
- direction = SkPathDirection::kCCW;
188
- }
151
+ std::shared_ptr<JsiSkPath> Rect(SkRect rect, JsiOptional<bool> isCCW) {
189
152
  SkPathBuilder builder;
190
- builder.addRect(*rect, direction);
191
- auto hostObjectInstance =
192
- std::make_shared<JsiSkPath>(getContext(), builder.snapshot());
193
- return JSI_CREATE_HOST_OBJECT_WITH_MEMORY_PRESSURE(
194
- runtime, hostObjectInstance, getContext());
153
+ builder.addRect(rect, toDirection(isCCW));
154
+ return std::make_shared<JsiSkPath>(getContext(), builder.snapshot());
195
155
  }
196
156
 
197
- JSI_HOST_FUNCTION(Oval) {
198
- auto rect = JsiSkRect::fromValue(runtime, arguments[0]);
199
- auto direction = SkPathDirection::kCW;
200
- if (count >= 2 && arguments[1].getBool()) {
201
- direction = SkPathDirection::kCCW;
202
- }
203
- unsigned startIndex = count < 3 ? 0 : arguments[2].asNumber();
157
+ std::shared_ptr<JsiSkPath> Oval(SkRect rect, JsiOptional<bool> isCCW,
158
+ JsiOptional<double> startIndex) {
204
159
  SkPathBuilder builder;
205
- builder.addOval(*rect, direction, startIndex);
206
- auto hostObjectInstance =
207
- std::make_shared<JsiSkPath>(getContext(), builder.snapshot());
208
- return JSI_CREATE_HOST_OBJECT_WITH_MEMORY_PRESSURE(
209
- runtime, hostObjectInstance, getContext());
160
+ builder.addOval(rect, toDirection(isCCW),
161
+ startIndex.has_value()
162
+ ? static_cast<unsigned>(*startIndex)
163
+ : 0);
164
+ return std::make_shared<JsiSkPath>(getContext(), builder.snapshot());
210
165
  }
211
166
 
212
- JSI_HOST_FUNCTION(Circle) {
213
- auto x = arguments[0].asNumber();
214
- auto y = arguments[1].asNumber();
215
- auto r = arguments[2].asNumber();
167
+ std::shared_ptr<JsiSkPath> Circle(double x, double y, double r) {
216
168
  SkPathBuilder builder;
217
169
  builder.addCircle(x, y, r);
218
- auto hostObjectInstance =
219
- std::make_shared<JsiSkPath>(getContext(), builder.snapshot());
220
- return JSI_CREATE_HOST_OBJECT_WITH_MEMORY_PRESSURE(
221
- runtime, hostObjectInstance, getContext());
170
+ return std::make_shared<JsiSkPath>(getContext(), builder.snapshot());
222
171
  }
223
172
 
224
- JSI_HOST_FUNCTION(RRect) {
225
- auto rrect = JsiSkRRect::fromValue(runtime, arguments[0]);
226
- auto direction = SkPathDirection::kCW;
227
- if (count >= 2 && arguments[1].getBool()) {
228
- direction = SkPathDirection::kCCW;
229
- }
173
+ std::shared_ptr<JsiSkPath> RRect(std::shared_ptr<SkRRect> rrect,
174
+ JsiOptional<bool> isCCW) {
230
175
  SkPathBuilder builder;
231
- builder.addRRect(*rrect, direction);
232
- auto hostObjectInstance =
233
- std::make_shared<JsiSkPath>(getContext(), builder.snapshot());
234
- return JSI_CREATE_HOST_OBJECT_WITH_MEMORY_PRESSURE(
235
- runtime, hostObjectInstance, getContext());
176
+ builder.addRRect(*rrect, toDirection(isCCW));
177
+ return std::make_shared<JsiSkPath>(getContext(), builder.snapshot());
236
178
  }
237
179
 
238
- JSI_HOST_FUNCTION(Line) {
239
- auto p1 = JsiSkPoint::fromValue(runtime, arguments[0].asObject(runtime));
240
- auto p2 = JsiSkPoint::fromValue(runtime, arguments[1].asObject(runtime));
180
+ std::shared_ptr<JsiSkPath> Line(SkPoint p1, SkPoint p2) {
241
181
  SkPathBuilder builder;
242
- builder.moveTo(*p1);
243
- builder.lineTo(*p2);
244
- auto hostObjectInstance =
245
- std::make_shared<JsiSkPath>(getContext(), builder.snapshot());
246
- return JSI_CREATE_HOST_OBJECT_WITH_MEMORY_PRESSURE(
247
- runtime, hostObjectInstance, getContext());
182
+ builder.moveTo(p1);
183
+ builder.lineTo(p2);
184
+ return std::make_shared<JsiSkPath>(getContext(), builder.snapshot());
248
185
  }
249
186
 
250
- JSI_HOST_FUNCTION(Polygon) {
251
- std::vector<SkPoint> points;
252
- auto jsiPoints = arguments[0].asObject(runtime).asArray(runtime);
253
- auto close = arguments[1].getBool();
254
- auto pointsSize = jsiPoints.size(runtime);
255
- points.reserve(pointsSize);
256
- for (int i = 0; i < pointsSize; i++) {
257
- std::shared_ptr<SkPoint> point = JsiSkPoint::fromValue(
258
- runtime, jsiPoints.getValueAtIndex(runtime, i).asObject(runtime));
259
- points.push_back(*point.get());
260
- }
187
+ std::shared_ptr<JsiSkPath> Polygon(std::vector<SkPoint> points, bool close) {
261
188
  SkPathBuilder builder;
262
189
  builder.addPolygon(SkSpan(points), close);
263
- auto hostObjectInstance =
264
- std::make_shared<JsiSkPath>(getContext(), builder.snapshot());
265
- return JSI_CREATE_HOST_OBJECT_WITH_MEMORY_PRESSURE(
266
- runtime, hostObjectInstance, getContext());
190
+ return std::make_shared<JsiSkPath>(getContext(), builder.snapshot());
267
191
  }
268
192
 
269
193
  // Static path operations
194
+
195
+ // Stays raw: the options object is read leniently property by property
196
+ // (unknown properties and non-numeric values are ignored).
270
197
  JSI_HOST_FUNCTION(Stroke) {
271
198
  auto srcPath = JsiSkPath::fromValue(runtime, arguments[0]);
272
199
  SkPath path = srcPath->snapshot();
@@ -307,148 +234,131 @@ public:
307
234
  auto success =
308
235
  skpathutils::FillPathWithPaint(path, p, &resultBuilder, nullptr, ctm);
309
236
  if (success) {
310
- auto hostObjectInstance =
311
- std::make_shared<JsiSkPath>(getContext(), resultBuilder.snapshot());
312
- return JSI_CREATE_HOST_OBJECT_WITH_MEMORY_PRESSURE(
313
- runtime, hostObjectInstance, getContext());
237
+ return makeJsiObject(
238
+ runtime, std::make_shared<JsiSkPath>(getContext(),
239
+ resultBuilder.snapshot()));
314
240
  }
315
241
  } else {
316
242
  SkPathBuilder resultBuilder;
317
243
  auto success = skpathutils::FillPathWithPaint(path, p, &resultBuilder);
318
244
  if (success) {
319
- auto hostObjectInstance =
320
- std::make_shared<JsiSkPath>(getContext(), resultBuilder.snapshot());
321
- return JSI_CREATE_HOST_OBJECT_WITH_MEMORY_PRESSURE(
322
- runtime, hostObjectInstance, getContext());
245
+ return makeJsiObject(
246
+ runtime, std::make_shared<JsiSkPath>(getContext(),
247
+ resultBuilder.snapshot()));
323
248
  }
324
249
  }
325
250
  return jsi::Value::null();
326
251
  }
327
252
 
328
- JSI_HOST_FUNCTION(Trim) {
329
- auto srcPath = JsiSkPath::fromValue(runtime, arguments[0]);
330
- float start =
331
- std::clamp(static_cast<float>(arguments[1].asNumber()), 0.0f, 1.0f);
332
- float end =
333
- std::clamp(static_cast<float>(arguments[2].asNumber()), 0.0f, 1.0f);
334
- auto isComplement = arguments[3].getBool();
253
+ NullablePath Trim(std::shared_ptr<SkPathBuilder> srcPath, double startValue,
254
+ double endValue, bool isComplement) {
255
+ float start = std::clamp(static_cast<float>(startValue), 0.0f, 1.0f);
256
+ float end = std::clamp(static_cast<float>(endValue), 0.0f, 1.0f);
335
257
  // If requesting the full path in normal mode, just return a copy
336
258
  if (start <= 0 && end >= 1 && !isComplement) {
337
- SkPath result = srcPath->snapshot();
338
- auto hostObjectInstance =
339
- std::make_shared<JsiSkPath>(getContext(), std::move(result));
340
- return JSI_CREATE_HOST_OBJECT_WITH_MEMORY_PRESSURE(
341
- runtime, hostObjectInstance, getContext());
259
+ return std::make_shared<JsiSkPath>(getContext(), srcPath->snapshot());
342
260
  }
343
261
  SkPath path = srcPath->snapshot();
344
262
  auto mode = isComplement ? SkTrimPathEffect::Mode::kInverted
345
263
  : SkTrimPathEffect::Mode::kNormal;
346
264
  auto pe = SkTrimPathEffect::Make(start, end, mode);
347
265
  if (!pe) {
348
- return jsi::Value::null();
266
+ return nullptr;
349
267
  }
350
268
  SkStrokeRec rec(SkStrokeRec::InitStyle::kHairline_InitStyle);
351
269
  SkPathBuilder resultBuilder;
352
270
  if (pe->filterPath(&resultBuilder, path, &rec)) {
353
- auto result = resultBuilder.detach();
354
- auto hostObjectInstance =
355
- std::make_shared<JsiSkPath>(getContext(), std::move(result));
356
- return JSI_CREATE_HOST_OBJECT_WITH_MEMORY_PRESSURE(
357
- runtime, hostObjectInstance, getContext());
271
+ return std::make_shared<JsiSkPath>(getContext(), resultBuilder.detach());
358
272
  }
359
- return jsi::Value::null();
273
+ return nullptr;
360
274
  }
361
275
 
362
- JSI_HOST_FUNCTION(Simplify) {
363
- auto srcPath = JsiSkPath::fromValue(runtime, arguments[0]);
276
+ NullablePath Simplify(std::shared_ptr<SkPathBuilder> srcPath) {
364
277
  auto result = ::Simplify(srcPath->snapshot());
365
278
  if (result.has_value()) {
366
- auto hostObjectInstance =
367
- std::make_shared<JsiSkPath>(getContext(), std::move(result.value()));
368
- return JSI_CREATE_HOST_OBJECT_WITH_MEMORY_PRESSURE(
369
- runtime, hostObjectInstance, getContext());
279
+ return std::make_shared<JsiSkPath>(getContext(),
280
+ std::move(result.value()));
370
281
  }
371
- return jsi::Value::null();
282
+ return nullptr;
372
283
  }
373
284
 
374
- JSI_HOST_FUNCTION(Dash) {
375
- auto srcPath = JsiSkPath::fromValue(runtime, arguments[0]);
376
- SkScalar on = arguments[1].asNumber();
377
- SkScalar off = arguments[2].asNumber();
378
- auto phase = arguments[3].asNumber();
379
- SkScalar intervals[] = {on, off};
285
+ NullablePath Dash(std::shared_ptr<SkPathBuilder> srcPath, double on,
286
+ double off, double phase) {
287
+ SkScalar intervals[] = {static_cast<SkScalar>(on),
288
+ static_cast<SkScalar>(off)};
380
289
  auto i = SkSpan(intervals, 2);
381
290
  auto pe = SkDashPathEffect::Make(i, phase);
382
291
  if (!pe) {
383
- return jsi::Value::null();
292
+ return nullptr;
384
293
  }
385
294
  SkStrokeRec rec(SkStrokeRec::InitStyle::kHairline_InitStyle);
386
295
  SkPathBuilder resultBuilder;
387
296
  if (pe->filterPath(&resultBuilder, srcPath->snapshot(), &rec)) {
388
- auto result = resultBuilder.detach();
389
- auto hostObjectInstance =
390
- std::make_shared<JsiSkPath>(getContext(), std::move(result));
391
- return JSI_CREATE_HOST_OBJECT_WITH_MEMORY_PRESSURE(
392
- runtime, hostObjectInstance, getContext());
297
+ return std::make_shared<JsiSkPath>(getContext(), resultBuilder.detach());
393
298
  }
394
- return jsi::Value::null();
299
+ return nullptr;
395
300
  }
396
301
 
397
- JSI_HOST_FUNCTION(AsWinding) {
398
- auto srcPath = JsiSkPath::fromValue(runtime, arguments[0]);
302
+ NullablePath AsWinding(std::shared_ptr<SkPathBuilder> srcPath) {
399
303
  auto result = ::AsWinding(srcPath->snapshot());
400
304
  if (result.has_value()) {
401
- auto hostObjectInstance =
402
- std::make_shared<JsiSkPath>(getContext(), std::move(result.value()));
403
- return JSI_CREATE_HOST_OBJECT_WITH_MEMORY_PRESSURE(
404
- runtime, hostObjectInstance, getContext());
305
+ return std::make_shared<JsiSkPath>(getContext(),
306
+ std::move(result.value()));
405
307
  }
406
- return jsi::Value::null();
308
+ return nullptr;
407
309
  }
408
310
 
409
- JSI_HOST_FUNCTION(Interpolate) {
410
- auto path1 = JsiSkPath::fromValue(runtime, arguments[0]);
411
- auto path2 = JsiSkPath::fromValue(runtime, arguments[1]);
412
- auto weight = arguments[2].asNumber();
413
- auto p1 = path1->snapshot();
414
- auto p2 = path2->snapshot();
311
+ NullablePath Interpolate(std::shared_ptr<SkPathBuilder> pathOne,
312
+ std::shared_ptr<SkPathBuilder> pathTwo,
313
+ double weight) {
314
+ auto p1 = pathOne->snapshot();
315
+ auto p2 = pathTwo->snapshot();
415
316
  SkPath result;
416
317
  auto succeed = p1.interpolate(p2, weight, &result);
417
318
  if (!succeed) {
418
- return jsi::Value::null();
319
+ return nullptr;
419
320
  }
420
- auto hostObjectInstance =
421
- std::make_shared<JsiSkPath>(getContext(), std::move(result));
422
- return JSI_CREATE_HOST_OBJECT_WITH_MEMORY_PRESSURE(
423
- runtime, hostObjectInstance, getContext());
321
+ return std::make_shared<JsiSkPath>(getContext(), std::move(result));
424
322
  }
425
323
 
426
- size_t getMemoryPressure() const override { return 1024; }
427
-
428
- std::string getObjectType() const override { return "JsiSkPathFactory"; }
429
-
430
- JSI_EXPORT_FUNCTIONS(JSI_EXPORT_FUNC(JsiSkPathFactory, Make),
431
- JSI_EXPORT_FUNC(JsiSkPathFactory, MakeFromSVGString),
432
- JSI_EXPORT_FUNC(JsiSkPathFactory, MakeFromOp),
433
- JSI_EXPORT_FUNC(JsiSkPathFactory, MakeFromCmds),
434
- JSI_EXPORT_FUNC(JsiSkPathFactory, MakeFromText),
435
- // Static shape factories
436
- JSI_EXPORT_FUNC(JsiSkPathFactory, Rect),
437
- JSI_EXPORT_FUNC(JsiSkPathFactory, Oval),
438
- JSI_EXPORT_FUNC(JsiSkPathFactory, Circle),
439
- JSI_EXPORT_FUNC(JsiSkPathFactory, RRect),
440
- JSI_EXPORT_FUNC(JsiSkPathFactory, Line),
441
- JSI_EXPORT_FUNC(JsiSkPathFactory, Polygon),
442
- // Static path operations
443
- JSI_EXPORT_FUNC(JsiSkPathFactory, Stroke),
444
- JSI_EXPORT_FUNC(JsiSkPathFactory, Trim),
445
- JSI_EXPORT_FUNC(JsiSkPathFactory, Simplify),
446
- JSI_EXPORT_FUNC(JsiSkPathFactory, Dash),
447
- JSI_EXPORT_FUNC(JsiSkPathFactory, AsWinding),
448
- JSI_EXPORT_FUNC(JsiSkPathFactory, Interpolate))
324
+ size_t getMemoryPressure() override { return 1024; }
325
+
326
+ static void definePrototype(jsi::Runtime &runtime, jsi::Object &prototype) {
327
+ installMethod(runtime, prototype, "Make", &JsiSkPathFactory::Make);
328
+ installMethod(runtime, prototype, "MakeFromSVGString",
329
+ &JsiSkPathFactory::MakeFromSVGString);
330
+ installMethod(runtime, prototype, "MakeFromOp",
331
+ &JsiSkPathFactory::MakeFromOp);
332
+ installMethod(runtime, prototype, "MakeFromCmds",
333
+ &JsiSkPathFactory::MakeFromCmds);
334
+ installMethod(runtime, prototype, "MakeFromText",
335
+ &JsiSkPathFactory::MakeFromText);
336
+ // Static shape factories
337
+ installMethod(runtime, prototype, "Rect", &JsiSkPathFactory::Rect);
338
+ installMethod(runtime, prototype, "Oval", &JsiSkPathFactory::Oval);
339
+ installMethod(runtime, prototype, "Circle", &JsiSkPathFactory::Circle);
340
+ installMethod(runtime, prototype, "RRect", &JsiSkPathFactory::RRect);
341
+ installMethod(runtime, prototype, "Line", &JsiSkPathFactory::Line);
342
+ installMethod(runtime, prototype, "Polygon", &JsiSkPathFactory::Polygon);
343
+ // Static path operations
344
+ installHostMethod(runtime, prototype, "Stroke", &JsiSkPathFactory::Stroke);
345
+ installMethod(runtime, prototype, "Trim", &JsiSkPathFactory::Trim);
346
+ installMethod(runtime, prototype, "Simplify", &JsiSkPathFactory::Simplify);
347
+ installMethod(runtime, prototype, "Dash", &JsiSkPathFactory::Dash);
348
+ installMethod(runtime, prototype, "AsWinding",
349
+ &JsiSkPathFactory::AsWinding);
350
+ installMethod(runtime, prototype, "Interpolate",
351
+ &JsiSkPathFactory::Interpolate);
352
+ }
449
353
 
450
354
  explicit JsiSkPathFactory(std::shared_ptr<RNSkPlatformContext> context)
451
- : JsiSkHostObject(std::move(context)) {}
355
+ : JsiSkNativeObject<JsiSkPathFactory>(std::move(context)) {}
356
+
357
+ private:
358
+ static SkPathDirection toDirection(const JsiOptional<bool> &isCCW) {
359
+ return isCCW.has_value() && *isCCW ? SkPathDirection::kCCW
360
+ : SkPathDirection::kCW;
361
+ }
452
362
  };
453
363
 
454
364
  } // namespace RNSkia