@shopify/react-native-skia 2.10.0 → 2.10.2

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 (332) hide show
  1. package/android/CMakeLists.txt +7 -41
  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 +14 -20
  5. package/cpp/api/JsiSkAnimatedImage.h +13 -16
  6. package/cpp/api/JsiSkAnimatedImageFactory.h +9 -7
  7. package/cpp/api/JsiSkApi.h +94 -90
  8. package/cpp/api/JsiSkCanvas.h +108 -251
  9. package/cpp/api/JsiSkColorFilterFactory.h +45 -63
  10. package/cpp/api/JsiSkContourMeasure.h +19 -29
  11. package/cpp/api/JsiSkContourMeasureIter.h +6 -6
  12. package/cpp/api/JsiSkConverters.h +410 -0
  13. package/cpp/api/JsiSkDataFactory.h +9 -15
  14. package/cpp/api/JsiSkFont.h +99 -180
  15. package/cpp/api/JsiSkFontMgr.h +19 -21
  16. package/cpp/api/JsiSkFontMgrFactory.h +4 -5
  17. package/cpp/api/JsiSkImage.h +66 -66
  18. package/cpp/api/JsiSkImageFactory.h +66 -63
  19. package/cpp/api/JsiSkImageFilterFactory.h +354 -608
  20. package/cpp/api/JsiSkImageInfo.h +10 -13
  21. package/cpp/api/JsiSkMaskFilterFactory.h +8 -11
  22. package/cpp/api/JsiSkMatrix.h +36 -73
  23. package/cpp/api/JsiSkNativeObjects.h +64 -96
  24. package/cpp/api/JsiSkPaint.h +73 -131
  25. package/cpp/api/JsiSkParagraph.h +36 -53
  26. package/cpp/api/JsiSkParagraphBuilder.h +36 -64
  27. package/cpp/api/JsiSkParagraphBuilderFactory.h +11 -16
  28. package/cpp/api/JsiSkPath.h +216 -349
  29. package/cpp/api/JsiSkPathBuilder.h +133 -269
  30. package/cpp/api/JsiSkPathBuilderFactory.h +11 -11
  31. package/cpp/api/JsiSkPathEffectFactory.h +52 -72
  32. package/cpp/api/JsiSkPathFactory.h +129 -195
  33. package/cpp/api/JsiSkPicture.h +12 -18
  34. package/cpp/api/JsiSkPictureRecorder.h +14 -15
  35. package/cpp/api/JsiSkPoint.h +4 -4
  36. package/cpp/api/JsiSkRRect.h +7 -8
  37. package/cpp/api/JsiSkRSXform.h +10 -23
  38. package/cpp/api/JsiSkRect.h +23 -31
  39. package/cpp/api/JsiSkRuntimeEffect.h +67 -83
  40. package/cpp/api/JsiSkRuntimeEffectFactory.h +6 -10
  41. package/cpp/api/JsiSkRuntimeShaderBuilder.h +5 -14
  42. package/cpp/api/JsiSkSVG.h +4 -4
  43. package/cpp/api/JsiSkShaderFactory.h +153 -225
  44. package/cpp/api/JsiSkSkottie.h +104 -126
  45. package/cpp/api/JsiSkSurface.h +11 -14
  46. package/cpp/api/JsiSkSurfaceFactory.h +6 -7
  47. package/cpp/api/JsiSkTextBlobFactory.h +31 -54
  48. package/cpp/api/JsiSkTypeface.h +8 -12
  49. package/cpp/api/JsiSkTypefaceFactory.h +9 -7
  50. package/cpp/api/JsiSkTypefaceFontProvider.h +22 -23
  51. package/cpp/api/JsiSkTypefaceFontProviderFactory.h +5 -6
  52. package/cpp/api/JsiSkVertices.h +6 -8
  53. package/cpp/api/JsiSkiaContext.h +10 -11
  54. package/cpp/api/JsiVideo.h +31 -71
  55. package/cpp/jsi/EnumMapper.h +2 -2
  56. package/cpp/jsi/JSIConverter.h +2 -33
  57. package/cpp/jsi/NativeObject.h +24 -19
  58. package/cpp/jsi/Promise.cpp +2 -2
  59. package/cpp/jsi/Promise.h +2 -2
  60. package/cpp/rnskia/RNDawnContext.h +18 -2
  61. package/cpp/rnskia/RNDawnInterop.cpp +19 -0
  62. package/cpp/rnskia/RNDawnUtils.h +18 -1
  63. package/cpp/rnskia/RNSkManager.cpp +5 -162
  64. package/cpp/skia/include/gpu/ganesh/GrDriverBugWorkaroundsAutogen.h +2 -0
  65. package/lib/commonjs/mock/index.js +0 -1
  66. package/lib/commonjs/mock/index.js.map +1 -1
  67. package/lib/commonjs/skia/types/Image/ImageFactory.d.ts +15 -6
  68. package/lib/commonjs/skia/types/Image/ImageFactory.js.map +1 -1
  69. package/lib/commonjs/skia/types/Skia.d.ts +5 -15
  70. package/lib/commonjs/skia/types/Skia.js.map +1 -1
  71. package/lib/commonjs/skia/types/index.d.ts +0 -1
  72. package/lib/commonjs/skia/types/index.js +0 -11
  73. package/lib/commonjs/skia/types/index.js.map +1 -1
  74. package/lib/commonjs/skia/web/JsiSkImageFactory.d.ts +2 -2
  75. package/lib/commonjs/skia/web/JsiSkImageFactory.js +2 -2
  76. package/lib/commonjs/skia/web/JsiSkImageFactory.js.map +1 -1
  77. package/lib/commonjs/skia/web/JsiSkia.js +1 -4
  78. package/lib/commonjs/skia/web/JsiSkia.js.map +1 -1
  79. package/lib/commonjs/views/index.d.ts +0 -1
  80. package/lib/commonjs/views/index.js +0 -11
  81. package/lib/commonjs/views/index.js.map +1 -1
  82. package/lib/module/mock/index.js +0 -1
  83. package/lib/module/mock/index.js.map +1 -1
  84. package/lib/module/skia/types/Image/ImageFactory.d.ts +15 -6
  85. package/lib/module/skia/types/Image/ImageFactory.js.map +1 -1
  86. package/lib/module/skia/types/Skia.d.ts +5 -15
  87. package/lib/module/skia/types/Skia.js.map +1 -1
  88. package/lib/module/skia/types/index.d.ts +0 -1
  89. package/lib/module/skia/types/index.js +0 -1
  90. package/lib/module/skia/types/index.js.map +1 -1
  91. package/lib/module/skia/web/JsiSkImageFactory.d.ts +2 -2
  92. package/lib/module/skia/web/JsiSkImageFactory.js +2 -2
  93. package/lib/module/skia/web/JsiSkImageFactory.js.map +1 -1
  94. package/lib/module/skia/web/JsiSkia.js +1 -4
  95. package/lib/module/skia/web/JsiSkia.js.map +1 -1
  96. package/lib/module/views/index.d.ts +0 -1
  97. package/lib/module/views/index.js +0 -1
  98. package/lib/module/views/index.js.map +1 -1
  99. package/lib/typescript/lib/commonjs/mock/index.d.ts +0 -1
  100. package/lib/typescript/lib/commonjs/skia/web/JsiSkImageFactory.d.ts +2 -2
  101. package/lib/typescript/lib/commonjs/skia/web/JsiSkia.d.ts +1 -2
  102. package/lib/typescript/lib/module/mock/index.d.ts +0 -2
  103. package/lib/typescript/lib/module/skia/Skia.web.d.ts +1 -2
  104. package/lib/typescript/lib/module/skia/types/index.d.ts +0 -1
  105. package/lib/typescript/lib/module/skia/web/JsiSkImageFactory.d.ts +2 -2
  106. package/lib/typescript/lib/module/skia/web/JsiSkia.d.ts +1 -2
  107. package/lib/typescript/lib/module/views/index.d.ts +0 -1
  108. package/lib/typescript/src/skia/types/Image/ImageFactory.d.ts +15 -6
  109. package/lib/typescript/src/skia/types/Skia.d.ts +5 -15
  110. package/lib/typescript/src/skia/types/index.d.ts +0 -1
  111. package/lib/typescript/src/skia/web/JsiSkImageFactory.d.ts +2 -2
  112. package/lib/typescript/src/views/index.d.ts +0 -1
  113. package/package.json +3 -4
  114. package/react-native-skia.podspec +38 -4
  115. package/src/mock/index.ts +0 -1
  116. package/src/skia/types/Image/ImageFactory.ts +15 -6
  117. package/src/skia/types/Skia.ts +5 -15
  118. package/src/skia/types/index.ts +0 -1
  119. package/src/skia/web/JsiSkImageFactory.ts +3 -3
  120. package/src/skia/web/JsiSkia.ts +2 -5
  121. package/src/views/index.ts +0 -1
  122. package/android/cpp/jni/JniWebGPUView.cpp +0 -112
  123. package/android/cpp/rnskia-android/SkiaPlatformContext.h +0 -26
  124. package/android/src/main/java/com/shopify/reactnative/skia/WebGPUSurfaceView.java +0 -43
  125. package/android/src/main/java/com/shopify/reactnative/skia/WebGPUTextureView.java +0 -50
  126. package/android/src/main/java/com/shopify/reactnative/skia/WebGPUView.java +0 -98
  127. package/android/src/main/java/com/shopify/reactnative/skia/WebGPUViewAPI.java +0 -19
  128. package/android/src/main/java/com/shopify/reactnative/skia/WebGPUViewManager.java +0 -58
  129. package/apple/RNWebGPUAppleNativeBuffer.mm +0 -33
  130. package/apple/SkiaPlatformContext.h +0 -20
  131. package/apple/SkiaPlatformContext.mm +0 -21
  132. package/apple/SkiaWebGPUView.mm +0 -81
  133. package/apple/WebGPUMetalView.mm +0 -136
  134. package/cpp/rnwgpu/ArrayBuffer.h +0 -116
  135. package/cpp/rnwgpu/Canvas.h +0 -52
  136. package/cpp/rnwgpu/PlatformContext.h +0 -18
  137. package/cpp/rnwgpu/SurfaceRegistry.h +0 -605
  138. package/cpp/rnwgpu/api/AppleNativeBuffer.h +0 -22
  139. package/cpp/rnwgpu/api/Convertors.h +0 -783
  140. package/cpp/rnwgpu/api/External.h +0 -12
  141. package/cpp/rnwgpu/api/GPU.cpp +0 -162
  142. package/cpp/rnwgpu/api/GPU.h +0 -60
  143. package/cpp/rnwgpu/api/GPUAdapter.cpp +0 -239
  144. package/cpp/rnwgpu/api/GPUAdapter.h +0 -60
  145. package/cpp/rnwgpu/api/GPUAdapterInfo.h +0 -57
  146. package/cpp/rnwgpu/api/GPUBindGroup.cpp +0 -3
  147. package/cpp/rnwgpu/api/GPUBindGroup.h +0 -51
  148. package/cpp/rnwgpu/api/GPUBindGroupLayout.h +0 -52
  149. package/cpp/rnwgpu/api/GPUBuffer.cpp +0 -107
  150. package/cpp/rnwgpu/api/GPUBuffer.h +0 -88
  151. package/cpp/rnwgpu/api/GPUCanvasContext.cpp +0 -75
  152. package/cpp/rnwgpu/api/GPUCanvasContext.h +0 -70
  153. package/cpp/rnwgpu/api/GPUCommandBuffer.h +0 -45
  154. package/cpp/rnwgpu/api/GPUCommandEncoder.cpp +0 -179
  155. package/cpp/rnwgpu/api/GPUCommandEncoder.h +0 -111
  156. package/cpp/rnwgpu/api/GPUCompilationInfo.h +0 -79
  157. package/cpp/rnwgpu/api/GPUCompilationMessage.h +0 -36
  158. package/cpp/rnwgpu/api/GPUComputePassEncoder.cpp +0 -60
  159. package/cpp/rnwgpu/api/GPUComputePassEncoder.h +0 -85
  160. package/cpp/rnwgpu/api/GPUComputePipeline.cpp +0 -12
  161. package/cpp/rnwgpu/api/GPUComputePipeline.h +0 -60
  162. package/cpp/rnwgpu/api/GPUDevice.cpp +0 -613
  163. package/cpp/rnwgpu/api/GPUDevice.h +0 -258
  164. package/cpp/rnwgpu/api/GPUDeviceLostInfo.cpp +0 -7
  165. package/cpp/rnwgpu/api/GPUDeviceLostInfo.h +0 -40
  166. package/cpp/rnwgpu/api/GPUError.h +0 -35
  167. package/cpp/rnwgpu/api/GPUExtent3D.h +0 -66
  168. package/cpp/rnwgpu/api/GPUExternalTexture.cpp +0 -139
  169. package/cpp/rnwgpu/api/GPUExternalTexture.h +0 -95
  170. package/cpp/rnwgpu/api/GPUFeatures.h +0 -203
  171. package/cpp/rnwgpu/api/GPUInternalError.h +0 -31
  172. package/cpp/rnwgpu/api/GPUOrigin2D.h +0 -55
  173. package/cpp/rnwgpu/api/GPUOrigin3D.h +0 -62
  174. package/cpp/rnwgpu/api/GPUOutOfMemoryError.h +0 -33
  175. package/cpp/rnwgpu/api/GPUPipelineLayout.h +0 -45
  176. package/cpp/rnwgpu/api/GPUQuerySet.cpp +0 -11
  177. package/cpp/rnwgpu/api/GPUQuerySet.h +0 -73
  178. package/cpp/rnwgpu/api/GPUQueue.cpp +0 -179
  179. package/cpp/rnwgpu/api/GPUQueue.h +0 -84
  180. package/cpp/rnwgpu/api/GPURenderBundle.h +0 -44
  181. package/cpp/rnwgpu/api/GPURenderBundleEncoder.cpp +0 -131
  182. package/cpp/rnwgpu/api/GPURenderBundleEncoder.h +0 -110
  183. package/cpp/rnwgpu/api/GPURenderPassEncoder.cpp +0 -165
  184. package/cpp/rnwgpu/api/GPURenderPassEncoder.h +0 -130
  185. package/cpp/rnwgpu/api/GPURenderPipeline.cpp +0 -13
  186. package/cpp/rnwgpu/api/GPURenderPipeline.h +0 -61
  187. package/cpp/rnwgpu/api/GPUSampler.h +0 -44
  188. package/cpp/rnwgpu/api/GPUShaderModule.cpp +0 -56
  189. package/cpp/rnwgpu/api/GPUShaderModule.h +0 -66
  190. package/cpp/rnwgpu/api/GPUSharedFence.cpp +0 -80
  191. package/cpp/rnwgpu/api/GPUSharedFence.h +0 -53
  192. package/cpp/rnwgpu/api/GPUSharedTextureMemory.cpp +0 -135
  193. package/cpp/rnwgpu/api/GPUSharedTextureMemory.h +0 -75
  194. package/cpp/rnwgpu/api/GPUSupportedLimits.cpp +0 -129
  195. package/cpp/rnwgpu/api/GPUSupportedLimits.h +0 -131
  196. package/cpp/rnwgpu/api/GPUTexture.cpp +0 -47
  197. package/cpp/rnwgpu/api/GPUTexture.h +0 -162
  198. package/cpp/rnwgpu/api/GPUTextureView.h +0 -44
  199. package/cpp/rnwgpu/api/GPUUncapturedErrorEvent.h +0 -60
  200. package/cpp/rnwgpu/api/GPUValidationError.h +0 -32
  201. package/cpp/rnwgpu/api/ImageBitmap.h +0 -62
  202. package/cpp/rnwgpu/api/NativeBufferUtils.h +0 -87
  203. package/cpp/rnwgpu/api/RNWebGPU.h +0 -82
  204. package/cpp/rnwgpu/api/WebGPUConstants.h +0 -36
  205. package/cpp/rnwgpu/api/descriptors/GPUBindGroupDescriptor.h +0 -64
  206. package/cpp/rnwgpu/api/descriptors/GPUBindGroupEntry.h +0 -78
  207. package/cpp/rnwgpu/api/descriptors/GPUBindGroupLayoutDescriptor.h +0 -56
  208. package/cpp/rnwgpu/api/descriptors/GPUBindGroupLayoutEntry.h +0 -97
  209. package/cpp/rnwgpu/api/descriptors/GPUBlendComponent.h +0 -57
  210. package/cpp/rnwgpu/api/descriptors/GPUBlendState.h +0 -52
  211. package/cpp/rnwgpu/api/descriptors/GPUBufferBinding.h +0 -56
  212. package/cpp/rnwgpu/api/descriptors/GPUBufferBindingLayout.h +0 -56
  213. package/cpp/rnwgpu/api/descriptors/GPUBufferDescriptor.h +0 -59
  214. package/cpp/rnwgpu/api/descriptors/GPUBufferUsage.h +0 -39
  215. package/cpp/rnwgpu/api/descriptors/GPUCanvasConfiguration.h +0 -76
  216. package/cpp/rnwgpu/api/descriptors/GPUColor.h +0 -66
  217. package/cpp/rnwgpu/api/descriptors/GPUColorTargetState.h +0 -58
  218. package/cpp/rnwgpu/api/descriptors/GPUColorWrite.h +0 -29
  219. package/cpp/rnwgpu/api/descriptors/GPUCommandBufferDescriptor.h +0 -45
  220. package/cpp/rnwgpu/api/descriptors/GPUCommandEncoderDescriptor.h +0 -45
  221. package/cpp/rnwgpu/api/descriptors/GPUComputePassDescriptor.h +0 -56
  222. package/cpp/rnwgpu/api/descriptors/GPUComputePassTimestampWrites.h +0 -58
  223. package/cpp/rnwgpu/api/descriptors/GPUComputePipelineDescriptor.h +0 -67
  224. package/cpp/rnwgpu/api/descriptors/GPUDawnTogglesDescriptor.h +0 -56
  225. package/cpp/rnwgpu/api/descriptors/GPUDepthStencilState.h +0 -103
  226. package/cpp/rnwgpu/api/descriptors/GPUDeviceDescriptor.h +0 -109
  227. package/cpp/rnwgpu/api/descriptors/GPUExternalTextureBindingLayout.h +0 -38
  228. package/cpp/rnwgpu/api/descriptors/GPUExternalTextureDescriptor.h +0 -90
  229. package/cpp/rnwgpu/api/descriptors/GPUFragmentState.h +0 -73
  230. package/cpp/rnwgpu/api/descriptors/GPUImageCopyBuffer.h +0 -62
  231. package/cpp/rnwgpu/api/descriptors/GPUImageCopyExternalImage.h +0 -63
  232. package/cpp/rnwgpu/api/descriptors/GPUImageCopyTexture.h +0 -65
  233. package/cpp/rnwgpu/api/descriptors/GPUImageCopyTextureTagged.h +0 -81
  234. package/cpp/rnwgpu/api/descriptors/GPUImageDataLayout.h +0 -54
  235. package/cpp/rnwgpu/api/descriptors/GPUMapMode.h +0 -22
  236. package/cpp/rnwgpu/api/descriptors/GPUMultisampleState.h +0 -54
  237. package/cpp/rnwgpu/api/descriptors/GPUPipelineLayoutDescriptor.h +0 -57
  238. package/cpp/rnwgpu/api/descriptors/GPUPrimitiveState.h +0 -69
  239. package/cpp/rnwgpu/api/descriptors/GPUProgrammableStage.h +0 -61
  240. package/cpp/rnwgpu/api/descriptors/GPUQuerySetDescriptor.h +0 -55
  241. package/cpp/rnwgpu/api/descriptors/GPUQueueDescriptor.h +0 -43
  242. package/cpp/rnwgpu/api/descriptors/GPURenderBundleDescriptor.h +0 -45
  243. package/cpp/rnwgpu/api/descriptors/GPURenderBundleEncoderDescriptor.h +0 -80
  244. package/cpp/rnwgpu/api/descriptors/GPURenderPassColorAttachment.h +0 -81
  245. package/cpp/rnwgpu/api/descriptors/GPURenderPassDepthStencilAttachment.h +0 -101
  246. package/cpp/rnwgpu/api/descriptors/GPURenderPassDescriptor.h +0 -92
  247. package/cpp/rnwgpu/api/descriptors/GPURenderPassTimestampWrites.h +0 -58
  248. package/cpp/rnwgpu/api/descriptors/GPURenderPipelineDescriptor.h +0 -103
  249. package/cpp/rnwgpu/api/descriptors/GPURequestAdapterOptions.h +0 -51
  250. package/cpp/rnwgpu/api/descriptors/GPUSamplerBindingLayout.h +0 -45
  251. package/cpp/rnwgpu/api/descriptors/GPUSamplerDescriptor.h +0 -110
  252. package/cpp/rnwgpu/api/descriptors/GPUShaderModuleCompilationHint.h +0 -60
  253. package/cpp/rnwgpu/api/descriptors/GPUShaderModuleDescriptor.h +0 -62
  254. package/cpp/rnwgpu/api/descriptors/GPUShaderStage.h +0 -25
  255. package/cpp/rnwgpu/api/descriptors/GPUSharedFenceDescriptor.h +0 -58
  256. package/cpp/rnwgpu/api/descriptors/GPUSharedFenceState.h +0 -51
  257. package/cpp/rnwgpu/api/descriptors/GPUSharedTextureMemoryDescriptor.h +0 -73
  258. package/cpp/rnwgpu/api/descriptors/GPUStencilFaceState.h +0 -64
  259. package/cpp/rnwgpu/api/descriptors/GPUStorageTextureBindingLayout.h +0 -59
  260. package/cpp/rnwgpu/api/descriptors/GPUTextureBindingLayout.h +0 -59
  261. package/cpp/rnwgpu/api/descriptors/GPUTextureDescriptor.h +0 -91
  262. package/cpp/rnwgpu/api/descriptors/GPUTextureUsage.h +0 -29
  263. package/cpp/rnwgpu/api/descriptors/GPUTextureViewDescriptor.h +0 -91
  264. package/cpp/rnwgpu/api/descriptors/GPUUncapturedErrorEventInit.h +0 -64
  265. package/cpp/rnwgpu/api/descriptors/GPUVertexAttribute.h +0 -53
  266. package/cpp/rnwgpu/api/descriptors/GPUVertexBufferLayout.h +0 -62
  267. package/cpp/rnwgpu/api/descriptors/GPUVertexState.h +0 -73
  268. package/cpp/rnwgpu/api/descriptors/Unions.h +0 -1969
  269. package/cpp/rnwgpu/async/AsyncTaskHandle.cpp +0 -213
  270. package/cpp/rnwgpu/async/AsyncTaskHandle.h +0 -58
  271. package/cpp/rnwgpu/async/RuntimeContext.cpp +0 -199
  272. package/cpp/rnwgpu/async/RuntimeContext.h +0 -134
  273. package/lib/commonjs/skia/types/WebGPU.d.ts +0 -184
  274. package/lib/commonjs/skia/types/WebGPU.js +0 -105
  275. package/lib/commonjs/skia/types/WebGPU.js.map +0 -1
  276. package/lib/commonjs/specs/WebGPUViewNativeComponent.d.ts +0 -8
  277. package/lib/commonjs/specs/WebGPUViewNativeComponent.js +0 -10
  278. package/lib/commonjs/specs/WebGPUViewNativeComponent.js.map +0 -1
  279. package/lib/commonjs/specs/WebGPUViewNativeComponent.web.d.ts +0 -8
  280. package/lib/commonjs/specs/WebGPUViewNativeComponent.web.js +0 -103
  281. package/lib/commonjs/specs/WebGPUViewNativeComponent.web.js.map +0 -1
  282. package/lib/commonjs/specs/utils.d.ts +0 -1
  283. package/lib/commonjs/specs/utils.js +0 -11
  284. package/lib/commonjs/specs/utils.js.map +0 -1
  285. package/lib/commonjs/views/WebGPUCanvas.d.ts +0 -33
  286. package/lib/commonjs/views/WebGPUCanvas.js +0 -79
  287. package/lib/commonjs/views/WebGPUCanvas.js.map +0 -1
  288. package/lib/commonjs/views/WebGPUCanvas.web.d.ts +0 -23
  289. package/lib/commonjs/views/WebGPUCanvas.web.js +0 -20
  290. package/lib/commonjs/views/WebGPUCanvas.web.js.map +0 -1
  291. package/lib/module/skia/types/WebGPU.d.ts +0 -184
  292. package/lib/module/skia/types/WebGPU.js +0 -99
  293. package/lib/module/skia/types/WebGPU.js.map +0 -1
  294. package/lib/module/specs/WebGPUViewNativeComponent.d.ts +0 -8
  295. package/lib/module/specs/WebGPUViewNativeComponent.js +0 -4
  296. package/lib/module/specs/WebGPUViewNativeComponent.js.map +0 -1
  297. package/lib/module/specs/WebGPUViewNativeComponent.web.d.ts +0 -8
  298. package/lib/module/specs/WebGPUViewNativeComponent.web.js +0 -96
  299. package/lib/module/specs/WebGPUViewNativeComponent.web.js.map +0 -1
  300. package/lib/module/specs/utils.d.ts +0 -1
  301. package/lib/module/specs/utils.js +0 -5
  302. package/lib/module/specs/utils.js.map +0 -1
  303. package/lib/module/views/WebGPUCanvas.d.ts +0 -33
  304. package/lib/module/views/WebGPUCanvas.js +0 -70
  305. package/lib/module/views/WebGPUCanvas.js.map +0 -1
  306. package/lib/module/views/WebGPUCanvas.web.d.ts +0 -23
  307. package/lib/module/views/WebGPUCanvas.web.js +0 -12
  308. package/lib/module/views/WebGPUCanvas.web.js.map +0 -1
  309. package/lib/typescript/lib/commonjs/skia/types/WebGPU.d.ts +0 -2
  310. package/lib/typescript/lib/commonjs/specs/WebGPUViewNativeComponent.d.ts +0 -4
  311. package/lib/typescript/lib/commonjs/specs/WebGPUViewNativeComponent.web.d.ts +0 -3
  312. package/lib/typescript/lib/commonjs/specs/utils.d.ts +0 -2
  313. package/lib/typescript/lib/commonjs/views/WebGPUCanvas.d.ts +0 -6
  314. package/lib/typescript/lib/commonjs/views/WebGPUCanvas.web.d.ts +0 -6
  315. package/lib/typescript/lib/module/skia/types/WebGPU.d.ts +0 -31
  316. package/lib/typescript/lib/module/specs/WebGPUViewNativeComponent.d.ts +0 -2
  317. package/lib/typescript/lib/module/specs/WebGPUViewNativeComponent.web.d.ts +0 -2
  318. package/lib/typescript/lib/module/specs/utils.d.ts +0 -1
  319. package/lib/typescript/lib/module/views/WebGPUCanvas.d.ts +0 -7
  320. package/lib/typescript/lib/module/views/WebGPUCanvas.web.d.ts +0 -8
  321. package/lib/typescript/src/skia/types/WebGPU.d.ts +0 -184
  322. package/lib/typescript/src/specs/WebGPUViewNativeComponent.d.ts +0 -8
  323. package/lib/typescript/src/specs/WebGPUViewNativeComponent.web.d.ts +0 -8
  324. package/lib/typescript/src/specs/utils.d.ts +0 -1
  325. package/lib/typescript/src/views/WebGPUCanvas.d.ts +0 -33
  326. package/lib/typescript/src/views/WebGPUCanvas.web.d.ts +0 -23
  327. package/src/skia/types/WebGPU.ts +0 -226
  328. package/src/specs/WebGPUViewNativeComponent.ts +0 -11
  329. package/src/specs/WebGPUViewNativeComponent.web.ts +0 -110
  330. package/src/specs/utils.ts +0 -4
  331. package/src/views/WebGPUCanvas.tsx +0 -125
  332. package/src/views/WebGPUCanvas.web.tsx +0 -36
@@ -1,12 +1,17 @@
1
1
  #pragma once
2
2
 
3
3
  #include <memory>
4
+ #include <optional>
4
5
  #include <utility>
6
+ #include <variant>
5
7
  #include <vector>
6
8
 
7
9
  #include <jsi/jsi.h>
8
10
 
11
+ #include "JsiSkConverters.h"
12
+ #include "JsiSkMatrix.h"
9
13
  #include "JsiSkNativeObjects.h"
14
+ #include "JsiSkPath.h"
10
15
  #include "JsiSkPathEffect.h"
11
16
 
12
17
  #pragma clang diagnostic push
@@ -30,104 +35,79 @@ class JsiSkPathEffectFactory
30
35
  public:
31
36
  static constexpr const char *CLASS_NAME = "PathEffectFactory";
32
37
 
33
- JSI_HOST_FUNCTION(MakeCorner) {
34
- int radius = arguments[0].asNumber();
35
- auto pathEffect = std::make_shared<JsiSkPathEffect>(
36
- getContext(), SkCornerPathEffect::Make(radius));
37
- return makeJsiObject(runtime, std::move(pathEffect));
38
+ std::shared_ptr<JsiSkPathEffect> MakeCorner(int radius) {
39
+ return std::make_shared<JsiSkPathEffect>(getContext(),
40
+ SkCornerPathEffect::Make(radius));
38
41
  }
39
42
 
40
- JSI_HOST_FUNCTION(MakeDash) {
41
- auto jsiIntervals = arguments[0].asObject(runtime).asArray(runtime);
42
- auto size = static_cast<int>(jsiIntervals.size(runtime));
43
- std::vector<SkScalar> intervals;
44
- intervals.reserve(size);
45
- for (int i = 0; i < size; i++) {
46
- SkScalar interval = jsiIntervals.getValueAtIndex(runtime, i).asNumber();
47
- intervals.push_back(interval);
48
- }
49
- int phase =
50
- count >= 2 && !arguments[1].isUndefined() && !arguments[1].isNull()
51
- ? arguments[1].asNumber()
52
- : 0;
43
+ std::shared_ptr<JsiSkPathEffect>
44
+ MakeDash(std::vector<float> intervals, JsiOptional<double> phaseValue) {
45
+ int phase = phaseValue.has_value() ? *phaseValue : 0;
53
46
  auto i = SkSpan(intervals.data(), intervals.size());
54
- auto pathEffect = std::make_shared<JsiSkPathEffect>(
55
- getContext(), SkDashPathEffect::Make(i, phase));
56
- return makeJsiObject(runtime, std::move(pathEffect));
47
+ return std::make_shared<JsiSkPathEffect>(getContext(),
48
+ SkDashPathEffect::Make(i, phase));
57
49
  }
58
50
 
59
- JSI_HOST_FUNCTION(MakeDiscrete) {
60
- int segLength = arguments[0].asNumber();
61
- int dec = arguments[1].asNumber();
62
- int seedAssist = arguments[2].asNumber();
63
- auto pathEffect = std::make_shared<JsiSkPathEffect>(
51
+ std::shared_ptr<JsiSkPathEffect> MakeDiscrete(int segLength, int dec,
52
+ int seedAssist) {
53
+ return std::make_shared<JsiSkPathEffect>(
64
54
  getContext(), SkDiscretePathEffect::Make(segLength, dec, seedAssist));
65
- return makeJsiObject(runtime, std::move(pathEffect));
66
55
  }
67
56
 
68
- JSI_HOST_FUNCTION(MakeCompose) {
69
- auto outer = JsiSkPathEffect::fromValue(runtime, arguments[0]);
70
- auto inner = JsiSkPathEffect::fromValue(runtime, arguments[1]);
71
- auto pathEffect = std::make_shared<JsiSkPathEffect>(
57
+ std::shared_ptr<JsiSkPathEffect> MakeCompose(sk_sp<SkPathEffect> outer,
58
+ sk_sp<SkPathEffect> inner) {
59
+ return std::make_shared<JsiSkPathEffect>(
72
60
  getContext(),
73
61
  SkPathEffect::MakeCompose(std::move(outer), std::move(inner)));
74
- return makeJsiObject(runtime, std::move(pathEffect));
75
62
  }
76
63
 
77
- JSI_HOST_FUNCTION(MakeSum) {
78
- auto outer = JsiSkPathEffect::fromValue(runtime, arguments[0]);
79
- auto inner = JsiSkPathEffect::fromValue(runtime, arguments[1]);
80
- auto pathEffect = std::make_shared<JsiSkPathEffect>(
64
+ std::shared_ptr<JsiSkPathEffect> MakeSum(sk_sp<SkPathEffect> outer,
65
+ sk_sp<SkPathEffect> inner) {
66
+ return std::make_shared<JsiSkPathEffect>(
81
67
  getContext(),
82
68
  SkPathEffect::MakeSum(std::move(outer), std::move(inner)));
83
- return makeJsiObject(runtime, std::move(pathEffect));
84
69
  }
85
70
 
86
- JSI_HOST_FUNCTION(MakePath1D) {
87
- auto path = JsiSkPath::fromValue(runtime, arguments[0]);
88
- auto advance = arguments[1].asNumber();
89
- auto phase = arguments[2].asNumber();
90
- auto style =
91
- static_cast<SkPath1DPathEffect::Style>(arguments[3].asNumber());
92
- auto pathEffect = std::make_shared<JsiSkPathEffect>(
71
+ std::shared_ptr<JsiSkPathEffect>
72
+ MakePath1D(std::shared_ptr<SkPathBuilder> path, double advance, double phase,
73
+ double style) {
74
+ return std::make_shared<JsiSkPathEffect>(
93
75
  getContext(),
94
- SkPath1DPathEffect::Make(path->snapshot(), advance, phase, style));
95
- return makeJsiObject(runtime, std::move(pathEffect));
76
+ SkPath1DPathEffect::Make(
77
+ path->snapshot(), advance, phase,
78
+ static_cast<SkPath1DPathEffect::Style>(style)));
96
79
  }
97
80
 
98
- JSI_HOST_FUNCTION(MakePath2D) {
99
- auto matrix = JsiSkMatrix::fromValue(runtime, arguments[0]);
100
- auto path = JsiSkPath::fromValue(runtime, arguments[1]);
101
- auto pathEffect = std::make_shared<JsiSkPathEffect>(
81
+ std::shared_ptr<JsiSkPathEffect>
82
+ MakePath2D(std::shared_ptr<SkMatrix> matrix,
83
+ std::shared_ptr<SkPathBuilder> path) {
84
+ return std::make_shared<JsiSkPathEffect>(
102
85
  getContext(), SkPath2DPathEffect::Make(*matrix, path->snapshot()));
103
- return makeJsiObject(runtime, std::move(pathEffect));
104
86
  }
105
87
 
106
- JSI_HOST_FUNCTION(MakeLine2D) {
107
- auto width = arguments[0].asNumber();
108
- auto matrix = JsiSkMatrix::fromValue(runtime, arguments[1]);
109
- auto pathEffect = std::make_shared<JsiSkPathEffect>(
88
+ std::shared_ptr<JsiSkPathEffect>
89
+ MakeLine2D(double width, std::shared_ptr<SkMatrix> matrix) {
90
+ return std::make_shared<JsiSkPathEffect>(
110
91
  getContext(), SkLine2DPathEffect::Make(width, *matrix));
111
- return makeJsiObject(runtime, std::move(pathEffect));
112
92
  }
113
93
 
114
94
  static void definePrototype(jsi::Runtime &runtime, jsi::Object &prototype) {
115
- installHostMethod(runtime, prototype, "MakeCorner",
116
- &JsiSkPathEffectFactory::MakeCorner);
117
- installHostMethod(runtime, prototype, "MakeDash",
118
- &JsiSkPathEffectFactory::MakeDash);
119
- installHostMethod(runtime, prototype, "MakeDiscrete",
120
- &JsiSkPathEffectFactory::MakeDiscrete);
121
- installHostMethod(runtime, prototype, "MakeCompose",
122
- &JsiSkPathEffectFactory::MakeCompose);
123
- installHostMethod(runtime, prototype, "MakeSum",
124
- &JsiSkPathEffectFactory::MakeSum);
125
- installHostMethod(runtime, prototype, "MakeLine2D",
126
- &JsiSkPathEffectFactory::MakeLine2D);
127
- installHostMethod(runtime, prototype, "MakePath1D",
128
- &JsiSkPathEffectFactory::MakePath1D);
129
- installHostMethod(runtime, prototype, "MakePath2D",
130
- &JsiSkPathEffectFactory::MakePath2D);
95
+ installMethod(runtime, prototype, "MakeCorner",
96
+ &JsiSkPathEffectFactory::MakeCorner);
97
+ installMethod(runtime, prototype, "MakeDash",
98
+ &JsiSkPathEffectFactory::MakeDash);
99
+ installMethod(runtime, prototype, "MakeDiscrete",
100
+ &JsiSkPathEffectFactory::MakeDiscrete);
101
+ installMethod(runtime, prototype, "MakeCompose",
102
+ &JsiSkPathEffectFactory::MakeCompose);
103
+ installMethod(runtime, prototype, "MakeSum",
104
+ &JsiSkPathEffectFactory::MakeSum);
105
+ installMethod(runtime, prototype, "MakeLine2D",
106
+ &JsiSkPathEffectFactory::MakeLine2D);
107
+ installMethod(runtime, prototype, "MakePath1D",
108
+ &JsiSkPathEffectFactory::MakePath1D);
109
+ installMethod(runtime, prototype, "MakePath2D",
110
+ &JsiSkPathEffectFactory::MakePath2D);
131
111
  }
132
112
 
133
113
  size_t getMemoryPressure() override { return 1024; }
@@ -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
 
12
+ #include "JsiSkConverters.h"
13
+ #include "JsiSkFont.h"
10
14
  #include "JsiSkMatrix.h"
11
15
  #include "JsiSkNativeObjects.h"
16
+ #include "JsiSkPath.h"
12
17
  #include "JsiSkPathEffect.h"
13
18
  #include "JsiSkPoint.h"
14
19
  #include "JsiSkRRect.h"
@@ -42,107 +47,83 @@ class JsiSkPathFactory : public JsiSkNativeObject<JsiSkPathFactory> {
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
53
  static constexpr const char *CLASS_NAME = "PathFactory";
47
54
 
48
- JSI_HOST_FUNCTION(Make) {
49
- return makeJsiObject(runtime,
50
- std::make_shared<JsiSkPath>(getContext(), SkPath()));
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
- return makeJsiObject(runtime, std::make_shared<JsiSkPath>(
61
- getContext(), std::move(result.value())));
64
+ return std::make_shared<JsiSkPath>(getContext(),
65
+ std::move(result.value()));
62
66
  }
63
67
 
64
- JSI_HOST_FUNCTION(MakeFromOp) {
65
- auto one = JsiSkPath::fromValue(runtime, arguments[0])->snapshot();
66
- auto two = JsiSkPath::fromValue(runtime, arguments[1])->snapshot();
67
- SkPathOp op = (SkPathOp)arguments[2].asNumber();
68
- 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));
69
73
  if (!result.has_value()) {
70
- return jsi::Value(nullptr);
74
+ return nullptr;
71
75
  }
72
- return makeJsiObject(runtime, std::make_shared<JsiSkPath>(
73
- getContext(), std::move(result.value())));
76
+ return std::make_shared<JsiSkPath>(getContext(),
77
+ std::move(result.value()));
74
78
  }
75
79
 
76
- JSI_HOST_FUNCTION(MakeFromCmds) {
80
+ NullablePath MakeFromCmds(std::vector<std::vector<double>> cmds) {
77
81
  SkPathBuilder builder;
78
- auto cmds = arguments[0].asObject(runtime).asArray(runtime);
79
- auto cmdCount = cmds.size(runtime);
80
- for (int i = 0; i < cmdCount; i++) {
81
- auto cmd =
82
- cmds.getValueAtIndex(runtime, i).asObject(runtime).asArray(runtime);
83
- if (cmd.size(runtime) < 1) {
82
+ for (const auto &cmd : cmds) {
83
+ if (cmd.size() < 1) {
84
84
  RNSkLogger::logToConsole("Invalid command found (got an empty array)");
85
- return jsi::Value::null();
85
+ return nullptr;
86
86
  }
87
- auto verb = static_cast<int>(cmd.getValueAtIndex(runtime, 0).asNumber());
87
+ auto verb = static_cast<int>(cmd[0]);
88
88
  switch (verb) {
89
89
  case MOVE: {
90
- if (cmd.size(runtime) < 3) {
90
+ if (cmd.size() < 3) {
91
91
  RNSkLogger::logToConsole("Invalid move command found");
92
- return jsi::Value::null();
92
+ return nullptr;
93
93
  }
94
- auto x = cmd.getValueAtIndex(runtime, 1).asNumber();
95
- auto y = cmd.getValueAtIndex(runtime, 2).asNumber();
96
- builder.moveTo(x, y);
94
+ builder.moveTo(cmd[1], cmd[2]);
97
95
  break;
98
96
  }
99
97
  case LINE: {
100
- if (cmd.size(runtime) < 3) {
98
+ if (cmd.size() < 3) {
101
99
  RNSkLogger::logToConsole("Invalid line command found");
102
- return jsi::Value::null();
100
+ return nullptr;
103
101
  }
104
- auto x = cmd.getValueAtIndex(runtime, 1).asNumber();
105
- auto y = cmd.getValueAtIndex(runtime, 2).asNumber();
106
- builder.lineTo(x, y);
102
+ builder.lineTo(cmd[1], cmd[2]);
107
103
  break;
108
104
  }
109
105
  case QUAD: {
110
- if (cmd.size(runtime) < 5) {
106
+ if (cmd.size() < 5) {
111
107
  RNSkLogger::logToConsole("Invalid line command found");
112
- return jsi::Value::null();
108
+ return nullptr;
113
109
  }
114
- auto x1 = cmd.getValueAtIndex(runtime, 1).asNumber();
115
- auto y1 = cmd.getValueAtIndex(runtime, 2).asNumber();
116
- auto x2 = cmd.getValueAtIndex(runtime, 3).asNumber();
117
- auto y2 = cmd.getValueAtIndex(runtime, 4).asNumber();
118
- builder.quadTo(x1, y1, x2, y2);
110
+ builder.quadTo(cmd[1], cmd[2], cmd[3], cmd[4]);
119
111
  break;
120
112
  }
121
113
  case CONIC: {
122
- if (cmd.size(runtime) < 6) {
114
+ if (cmd.size() < 6) {
123
115
  RNSkLogger::logToConsole("Invalid line command found");
124
- return jsi::Value::null();
116
+ return nullptr;
125
117
  }
126
- auto x1 = cmd.getValueAtIndex(runtime, 1).asNumber();
127
- auto y1 = cmd.getValueAtIndex(runtime, 2).asNumber();
128
- auto x2 = cmd.getValueAtIndex(runtime, 3).asNumber();
129
- auto y2 = cmd.getValueAtIndex(runtime, 4).asNumber();
130
- auto w = cmd.getValueAtIndex(runtime, 5).asNumber();
131
- builder.conicTo(x1, y1, x2, y2, w);
118
+ builder.conicTo(cmd[1], cmd[2], cmd[3], cmd[4], cmd[5]);
132
119
  break;
133
120
  }
134
121
  case CUBIC: {
135
- if (cmd.size(runtime) < 7) {
122
+ if (cmd.size() < 7) {
136
123
  RNSkLogger::logToConsole("Invalid line command found");
137
- return jsi::Value::null();
124
+ return nullptr;
138
125
  }
139
- auto x1 = cmd.getValueAtIndex(runtime, 1).asNumber();
140
- auto y1 = cmd.getValueAtIndex(runtime, 2).asNumber();
141
- auto x2 = cmd.getValueAtIndex(runtime, 3).asNumber();
142
- auto y2 = cmd.getValueAtIndex(runtime, 4).asNumber();
143
- auto x3 = cmd.getValueAtIndex(runtime, 5).asNumber();
144
- auto y3 = cmd.getValueAtIndex(runtime, 6).asNumber();
145
- builder.cubicTo(x1, y1, x2, y2, x3, y3);
126
+ builder.cubicTo(cmd[1], cmd[2], cmd[3], cmd[4], cmd[5], cmd[6]);
146
127
  break;
147
128
  }
148
129
  case CLOSE: {
@@ -151,102 +132,68 @@ public:
151
132
  }
152
133
  default: {
153
134
  RNSkLogger::logToConsole("Found an unknown command");
154
- return jsi::Value::null();
135
+ return nullptr;
155
136
  }
156
137
  }
157
138
  }
158
- return makeJsiObject(
159
- runtime, std::make_shared<JsiSkPath>(getContext(), builder.snapshot()));
139
+ return std::make_shared<JsiSkPath>(getContext(), builder.snapshot());
160
140
  }
161
141
 
162
- JSI_HOST_FUNCTION(MakeFromText) {
163
- auto text = arguments[0].asString(runtime).utf8(runtime);
164
- auto x = arguments[1].asNumber();
165
- auto y = arguments[2].asNumber();
166
- 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) {
167
144
  SkPath path;
168
145
  SkTextUtils::GetPath(text.c_str(), strlen(text.c_str()),
169
146
  SkTextEncoding::kUTF8, x, y, *font, &path);
170
- return makeJsiObject(
171
- runtime, std::make_shared<JsiSkPath>(getContext(), std::move(path)));
147
+ return std::make_shared<JsiSkPath>(getContext(), std::move(path));
172
148
  }
173
149
 
174
150
  // Static shape factories
175
- JSI_HOST_FUNCTION(Rect) {
176
- auto rect = JsiSkRect::fromValue(runtime, arguments[0]);
177
- auto direction = SkPathDirection::kCW;
178
- if (count >= 2 && arguments[1].getBool()) {
179
- direction = SkPathDirection::kCCW;
180
- }
151
+ std::shared_ptr<JsiSkPath> Rect(SkRect rect, JsiOptional<bool> isCCW) {
181
152
  SkPathBuilder builder;
182
- builder.addRect(*rect, direction);
183
- return makeJsiObject(
184
- runtime, std::make_shared<JsiSkPath>(getContext(), builder.snapshot()));
153
+ builder.addRect(rect, toDirection(isCCW));
154
+ return std::make_shared<JsiSkPath>(getContext(), builder.snapshot());
185
155
  }
186
156
 
187
- JSI_HOST_FUNCTION(Oval) {
188
- auto rect = JsiSkRect::fromValue(runtime, arguments[0]);
189
- auto direction = SkPathDirection::kCW;
190
- if (count >= 2 && arguments[1].getBool()) {
191
- direction = SkPathDirection::kCCW;
192
- }
193
- unsigned startIndex = count < 3 ? 0 : arguments[2].asNumber();
157
+ std::shared_ptr<JsiSkPath> Oval(SkRect rect, JsiOptional<bool> isCCW,
158
+ JsiOptional<double> startIndex) {
194
159
  SkPathBuilder builder;
195
- builder.addOval(*rect, direction, startIndex);
196
- return makeJsiObject(
197
- runtime, std::make_shared<JsiSkPath>(getContext(), builder.snapshot()));
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());
198
165
  }
199
166
 
200
- JSI_HOST_FUNCTION(Circle) {
201
- auto x = arguments[0].asNumber();
202
- auto y = arguments[1].asNumber();
203
- auto r = arguments[2].asNumber();
167
+ std::shared_ptr<JsiSkPath> Circle(double x, double y, double r) {
204
168
  SkPathBuilder builder;
205
169
  builder.addCircle(x, y, r);
206
- return makeJsiObject(
207
- runtime, std::make_shared<JsiSkPath>(getContext(), builder.snapshot()));
170
+ return std::make_shared<JsiSkPath>(getContext(), builder.snapshot());
208
171
  }
209
172
 
210
- JSI_HOST_FUNCTION(RRect) {
211
- auto rrect = JsiSkRRect::fromValue(runtime, arguments[0]);
212
- auto direction = SkPathDirection::kCW;
213
- if (count >= 2 && arguments[1].getBool()) {
214
- direction = SkPathDirection::kCCW;
215
- }
173
+ std::shared_ptr<JsiSkPath> RRect(std::shared_ptr<SkRRect> rrect,
174
+ JsiOptional<bool> isCCW) {
216
175
  SkPathBuilder builder;
217
- builder.addRRect(*rrect, direction);
218
- return makeJsiObject(
219
- runtime, std::make_shared<JsiSkPath>(getContext(), builder.snapshot()));
176
+ builder.addRRect(*rrect, toDirection(isCCW));
177
+ return std::make_shared<JsiSkPath>(getContext(), builder.snapshot());
220
178
  }
221
179
 
222
- JSI_HOST_FUNCTION(Line) {
223
- auto p1 = JsiSkPoint::fromValue(runtime, arguments[0].asObject(runtime));
224
- auto p2 = JsiSkPoint::fromValue(runtime, arguments[1].asObject(runtime));
180
+ std::shared_ptr<JsiSkPath> Line(SkPoint p1, SkPoint p2) {
225
181
  SkPathBuilder builder;
226
- builder.moveTo(*p1);
227
- builder.lineTo(*p2);
228
- return makeJsiObject(
229
- runtime, std::make_shared<JsiSkPath>(getContext(), builder.snapshot()));
182
+ builder.moveTo(p1);
183
+ builder.lineTo(p2);
184
+ return std::make_shared<JsiSkPath>(getContext(), builder.snapshot());
230
185
  }
231
186
 
232
- JSI_HOST_FUNCTION(Polygon) {
233
- std::vector<SkPoint> points;
234
- auto jsiPoints = arguments[0].asObject(runtime).asArray(runtime);
235
- auto close = arguments[1].getBool();
236
- auto pointsSize = jsiPoints.size(runtime);
237
- points.reserve(pointsSize);
238
- for (int i = 0; i < pointsSize; i++) {
239
- std::shared_ptr<SkPoint> point = JsiSkPoint::fromValue(
240
- runtime, jsiPoints.getValueAtIndex(runtime, i).asObject(runtime));
241
- points.push_back(*point.get());
242
- }
187
+ std::shared_ptr<JsiSkPath> Polygon(std::vector<SkPoint> points, bool close) {
243
188
  SkPathBuilder builder;
244
189
  builder.addPolygon(SkSpan(points), close);
245
- return makeJsiObject(
246
- runtime, std::make_shared<JsiSkPath>(getContext(), builder.snapshot()));
190
+ return std::make_shared<JsiSkPath>(getContext(), builder.snapshot());
247
191
  }
248
192
 
249
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).
250
197
  JSI_HOST_FUNCTION(Stroke) {
251
198
  auto srcPath = JsiSkPath::fromValue(runtime, arguments[0]);
252
199
  SkPath path = srcPath->snapshot();
@@ -303,128 +250,115 @@ public:
303
250
  return jsi::Value::null();
304
251
  }
305
252
 
306
- JSI_HOST_FUNCTION(Trim) {
307
- auto srcPath = JsiSkPath::fromValue(runtime, arguments[0]);
308
- float start =
309
- std::clamp(static_cast<float>(arguments[1].asNumber()), 0.0f, 1.0f);
310
- float end =
311
- std::clamp(static_cast<float>(arguments[2].asNumber()), 0.0f, 1.0f);
312
- 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);
313
257
  // If requesting the full path in normal mode, just return a copy
314
258
  if (start <= 0 && end >= 1 && !isComplement) {
315
- SkPath result = srcPath->snapshot();
316
- return makeJsiObject(runtime, std::make_shared<JsiSkPath>(
317
- getContext(), std::move(result)));
259
+ return std::make_shared<JsiSkPath>(getContext(), srcPath->snapshot());
318
260
  }
319
261
  SkPath path = srcPath->snapshot();
320
262
  auto mode = isComplement ? SkTrimPathEffect::Mode::kInverted
321
263
  : SkTrimPathEffect::Mode::kNormal;
322
264
  auto pe = SkTrimPathEffect::Make(start, end, mode);
323
265
  if (!pe) {
324
- return jsi::Value::null();
266
+ return nullptr;
325
267
  }
326
268
  SkStrokeRec rec(SkStrokeRec::InitStyle::kHairline_InitStyle);
327
269
  SkPathBuilder resultBuilder;
328
270
  if (pe->filterPath(&resultBuilder, path, &rec)) {
329
- auto result = resultBuilder.detach();
330
- return makeJsiObject(runtime, std::make_shared<JsiSkPath>(
331
- getContext(), std::move(result)));
271
+ return std::make_shared<JsiSkPath>(getContext(), resultBuilder.detach());
332
272
  }
333
- return jsi::Value::null();
273
+ return nullptr;
334
274
  }
335
275
 
336
- JSI_HOST_FUNCTION(Simplify) {
337
- auto srcPath = JsiSkPath::fromValue(runtime, arguments[0]);
276
+ NullablePath Simplify(std::shared_ptr<SkPathBuilder> srcPath) {
338
277
  auto result = ::Simplify(srcPath->snapshot());
339
278
  if (result.has_value()) {
340
- return makeJsiObject(
341
- runtime,
342
- std::make_shared<JsiSkPath>(getContext(), std::move(result.value())));
279
+ return std::make_shared<JsiSkPath>(getContext(),
280
+ std::move(result.value()));
343
281
  }
344
- return jsi::Value::null();
282
+ return nullptr;
345
283
  }
346
284
 
347
- JSI_HOST_FUNCTION(Dash) {
348
- auto srcPath = JsiSkPath::fromValue(runtime, arguments[0]);
349
- SkScalar on = arguments[1].asNumber();
350
- SkScalar off = arguments[2].asNumber();
351
- auto phase = arguments[3].asNumber();
352
- 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)};
353
289
  auto i = SkSpan(intervals, 2);
354
290
  auto pe = SkDashPathEffect::Make(i, phase);
355
291
  if (!pe) {
356
- return jsi::Value::null();
292
+ return nullptr;
357
293
  }
358
294
  SkStrokeRec rec(SkStrokeRec::InitStyle::kHairline_InitStyle);
359
295
  SkPathBuilder resultBuilder;
360
296
  if (pe->filterPath(&resultBuilder, srcPath->snapshot(), &rec)) {
361
- auto result = resultBuilder.detach();
362
- return makeJsiObject(runtime, std::make_shared<JsiSkPath>(
363
- getContext(), std::move(result)));
297
+ return std::make_shared<JsiSkPath>(getContext(), resultBuilder.detach());
364
298
  }
365
- return jsi::Value::null();
299
+ return nullptr;
366
300
  }
367
301
 
368
- JSI_HOST_FUNCTION(AsWinding) {
369
- auto srcPath = JsiSkPath::fromValue(runtime, arguments[0]);
302
+ NullablePath AsWinding(std::shared_ptr<SkPathBuilder> srcPath) {
370
303
  auto result = ::AsWinding(srcPath->snapshot());
371
304
  if (result.has_value()) {
372
- return makeJsiObject(
373
- runtime,
374
- std::make_shared<JsiSkPath>(getContext(), std::move(result.value())));
305
+ return std::make_shared<JsiSkPath>(getContext(),
306
+ std::move(result.value()));
375
307
  }
376
- return jsi::Value::null();
308
+ return nullptr;
377
309
  }
378
310
 
379
- JSI_HOST_FUNCTION(Interpolate) {
380
- auto path1 = JsiSkPath::fromValue(runtime, arguments[0]);
381
- auto path2 = JsiSkPath::fromValue(runtime, arguments[1]);
382
- auto weight = arguments[2].asNumber();
383
- auto p1 = path1->snapshot();
384
- 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();
385
316
  SkPath result;
386
317
  auto succeed = p1.interpolate(p2, weight, &result);
387
318
  if (!succeed) {
388
- return jsi::Value::null();
319
+ return nullptr;
389
320
  }
390
- return makeJsiObject(
391
- runtime, std::make_shared<JsiSkPath>(getContext(), std::move(result)));
321
+ return std::make_shared<JsiSkPath>(getContext(), std::move(result));
392
322
  }
393
323
 
394
324
  size_t getMemoryPressure() override { return 1024; }
395
325
 
396
326
  static void definePrototype(jsi::Runtime &runtime, jsi::Object &prototype) {
397
- installHostMethod(runtime, prototype, "Make", &JsiSkPathFactory::Make);
398
- installHostMethod(runtime, prototype, "MakeFromSVGString",
399
- &JsiSkPathFactory::MakeFromSVGString);
400
- installHostMethod(runtime, prototype, "MakeFromOp",
401
- &JsiSkPathFactory::MakeFromOp);
402
- installHostMethod(runtime, prototype, "MakeFromCmds",
403
- &JsiSkPathFactory::MakeFromCmds);
404
- installHostMethod(runtime, prototype, "MakeFromText",
405
- &JsiSkPathFactory::MakeFromText);
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);
406
336
  // Static shape factories
407
- installHostMethod(runtime, prototype, "Rect", &JsiSkPathFactory::Rect);
408
- installHostMethod(runtime, prototype, "Oval", &JsiSkPathFactory::Oval);
409
- installHostMethod(runtime, prototype, "Circle", &JsiSkPathFactory::Circle);
410
- installHostMethod(runtime, prototype, "RRect", &JsiSkPathFactory::RRect);
411
- installHostMethod(runtime, prototype, "Line", &JsiSkPathFactory::Line);
412
- installHostMethod(runtime, prototype, "Polygon",
413
- &JsiSkPathFactory::Polygon);
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);
414
343
  // Static path operations
415
344
  installHostMethod(runtime, prototype, "Stroke", &JsiSkPathFactory::Stroke);
416
- installHostMethod(runtime, prototype, "Trim", &JsiSkPathFactory::Trim);
417
- installHostMethod(runtime, prototype, "Simplify",
418
- &JsiSkPathFactory::Simplify);
419
- installHostMethod(runtime, prototype, "Dash", &JsiSkPathFactory::Dash);
420
- installHostMethod(runtime, prototype, "AsWinding",
421
- &JsiSkPathFactory::AsWinding);
422
- installHostMethod(runtime, prototype, "Interpolate",
423
- &JsiSkPathFactory::Interpolate);
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);
424
352
  }
425
353
 
426
354
  explicit JsiSkPathFactory(std::shared_ptr<RNSkPlatformContext> context)
427
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
+ }
428
362
  };
429
363
 
430
364
  } // namespace RNSkia