@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,14 +1,24 @@
1
1
  #pragma once
2
2
 
3
3
  #include <memory>
4
+ #include <string>
4
5
  #include <utility>
6
+ #include <variant>
7
+ #include <vector>
5
8
 
6
9
  #include <jsi/jsi.h>
7
10
 
11
+ #include "JsiSkColor.h"
12
+ #include "JsiSkColorFilter.h"
13
+ #include "JsiSkConverters.h"
14
+ #include "JsiSkImage.h"
8
15
  #include "JsiSkImageFilter.h"
16
+ #include "JsiSkMatrix.h"
9
17
  #include "JsiSkNativeObjects.h"
10
18
  #include "JsiSkPicture.h"
19
+ #include "JsiSkRect.h"
11
20
  #include "JsiSkRuntimeShaderBuilder.h"
21
+ #include "JsiSkShader.h"
12
22
 
13
23
  #pragma clang diagnostic push
14
24
  #pragma clang diagnostic ignored "-Wdocumentation"
@@ -22,681 +32,417 @@ namespace RNSkia {
22
32
 
23
33
  namespace jsi = facebook::jsi;
24
34
 
25
- inline bool hasOptionalArgument(const jsi::Value *arguments, size_t count,
26
- size_t index) {
27
- return (index < count && !arguments[index].isNull() &&
28
- !arguments[index].isUndefined());
29
- }
30
-
31
35
  class JsiSkImageFilterFactory
32
36
  : public JsiSkNativeObject<JsiSkImageFilterFactory> {
33
37
  public:
34
38
  static constexpr const char *CLASS_NAME = "ImageFilterFactory";
35
39
 
36
- JSI_HOST_FUNCTION(MakeBlur) {
37
- float sigmaX = arguments[0].asNumber();
38
- float sigmaY = arguments[1].asNumber();
39
- int tileMode = arguments[2].asNumber();
40
- sk_sp<SkImageFilter> imageFilter = nullptr;
41
- if (hasOptionalArgument(arguments, count, 3)) {
42
- imageFilter = JsiSkImageFilter::fromValue(runtime, arguments[3]);
43
- }
44
- SkImageFilters::CropRect cropRect = {};
45
- if (hasOptionalArgument(arguments, count, 4)) {
46
- cropRect = *JsiSkRect::fromValue(runtime, arguments[4]);
47
- }
48
- auto filter = std::make_shared<JsiSkImageFilter>(
49
- getContext(), SkImageFilters::Blur(sigmaX, sigmaY, (SkTileMode)tileMode,
50
- imageFilter, cropRect));
51
- return makeJsiObject(runtime, std::move(filter));
40
+ std::shared_ptr<JsiSkImageFilter>
41
+ MakeBlur(float sigmaX, float sigmaY, int tileMode,
42
+ JsiOptional<sk_sp<SkImageFilter>> input,
43
+ JsiOptional<SkRect> crop) {
44
+ return std::make_shared<JsiSkImageFilter>(
45
+ getContext(),
46
+ SkImageFilters::Blur(sigmaX, sigmaY, static_cast<SkTileMode>(tileMode),
47
+ orNull(std::move(input)), toCropRect(crop)));
52
48
  }
53
49
 
54
- JSI_HOST_FUNCTION(MakeColorFilter) {
55
- auto cf = JsiSkColorFilter::fromValue(runtime, arguments[0]);
56
- sk_sp<SkImageFilter> input = nullptr;
57
- if (hasOptionalArgument(arguments, count, 1)) {
58
- input = JsiSkImageFilter::fromValue(runtime, arguments[1]);
59
- }
60
- SkImageFilters::CropRect cropRect = {};
61
- if (hasOptionalArgument(arguments, count, 2)) {
62
- cropRect = *JsiSkRect::fromValue(runtime, arguments[2]);
63
- }
64
- auto filter = std::make_shared<JsiSkImageFilter>(
50
+ std::shared_ptr<JsiSkImageFilter>
51
+ MakeColorFilter(sk_sp<SkColorFilter> cf,
52
+ JsiOptional<sk_sp<SkImageFilter>> input,
53
+ JsiOptional<SkRect> crop) {
54
+ return std::make_shared<JsiSkImageFilter>(
65
55
  getContext(),
66
- SkImageFilters::ColorFilter(std::move(cf), std::move(input), cropRect));
67
- return makeJsiObject(runtime, std::move(filter));
56
+ SkImageFilters::ColorFilter(std::move(cf), orNull(std::move(input)),
57
+ toCropRect(crop)));
68
58
  }
69
59
 
70
- JSI_HOST_FUNCTION(MakeOffset) {
71
- auto x = arguments[0].asNumber();
72
- auto y = arguments[1].asNumber();
73
- sk_sp<SkImageFilter> input = nullptr;
74
- if (hasOptionalArgument(arguments, count, 2)) {
75
- input = JsiSkImageFilter::fromValue(runtime, arguments[2]);
76
- }
77
- SkImageFilters::CropRect cropRect = {};
78
- if (hasOptionalArgument(arguments, count, 3)) {
79
- cropRect = *JsiSkRect::fromValue(runtime, arguments[3]);
80
- }
81
- auto filter = std::make_shared<JsiSkImageFilter>(
82
- getContext(), SkImageFilters::Offset(x, y, std::move(input), cropRect));
83
- return makeJsiObject(runtime, std::move(filter));
84
- }
85
-
86
- JSI_HOST_FUNCTION(MakeDisplacementMap) {
87
- auto fXChannelSelector =
88
- static_cast<SkColorChannel>(arguments[0].asNumber());
89
- auto fYChannelSelector =
90
- static_cast<SkColorChannel>(arguments[1].asNumber());
91
- auto scale = arguments[2].asNumber();
92
- auto in2 = JsiSkImageFilter::fromValue(runtime, arguments[3]);
93
- sk_sp<SkImageFilter> input = nullptr;
94
- if (hasOptionalArgument(arguments, count, 4)) {
95
- input = JsiSkImageFilter::fromValue(runtime, arguments[4]);
96
- }
97
- SkImageFilters::CropRect cropRect = {};
98
- if (hasOptionalArgument(arguments, count, 5)) {
99
- cropRect = *JsiSkRect::fromValue(runtime, arguments[5]);
100
- }
101
- auto filter = std::make_shared<JsiSkImageFilter>(
102
- getContext(), SkImageFilters::DisplacementMap(
103
- fXChannelSelector, fYChannelSelector, scale,
104
- std::move(in2), std::move(input), cropRect));
105
- return makeJsiObject(runtime, std::move(filter));
106
- }
107
-
108
- JSI_HOST_FUNCTION(MakeShader) {
109
- auto shader = JsiSkShader::fromValue(runtime, arguments[0]);
110
- SkImageFilters::Dither dither = SkImageFilters::Dither::kNo;
111
- if (hasOptionalArgument(arguments, count, 1)) {
112
- dither = arguments[1].asBool() ? SkImageFilters::Dither::kYes
113
- : SkImageFilters::Dither::kNo;
114
- }
115
- SkImageFilters::CropRect cropRect = {};
116
- if (hasOptionalArgument(arguments, count, 2)) {
117
- cropRect = *JsiSkRect::fromValue(runtime, arguments[2]);
118
- }
119
- auto filter = std::make_shared<JsiSkImageFilter>(
120
- getContext(),
121
- SkImageFilters::Shader(std::move(shader), dither, cropRect));
122
- return makeJsiObject(runtime, std::move(filter));
60
+ std::shared_ptr<JsiSkImageFilter>
61
+ MakeOffset(double x, double y, JsiOptional<sk_sp<SkImageFilter>> input,
62
+ JsiOptional<SkRect> crop) {
63
+ return std::make_shared<JsiSkImageFilter>(
64
+ getContext(), SkImageFilters::Offset(x, y, orNull(std::move(input)),
65
+ toCropRect(crop)));
123
66
  }
124
67
 
125
- JSI_HOST_FUNCTION(MakeCompose) {
126
- sk_sp<SkImageFilter> outer = nullptr;
127
- if (hasOptionalArgument(arguments, count, 0)) {
128
- outer = JsiSkImageFilter::fromValue(runtime, arguments[0]);
129
- }
130
- sk_sp<SkImageFilter> inner = nullptr;
131
- if (hasOptionalArgument(arguments, count, 1)) {
132
- inner = JsiSkImageFilter::fromValue(runtime, arguments[1]);
133
- }
134
- auto filter = std::make_shared<JsiSkImageFilter>(
68
+ std::shared_ptr<JsiSkImageFilter>
69
+ MakeDisplacementMap(double xChannelSelector, double yChannelSelector,
70
+ double scale, sk_sp<SkImageFilter> in2,
71
+ JsiOptional<sk_sp<SkImageFilter>> input,
72
+ JsiOptional<SkRect> crop) {
73
+ return std::make_shared<JsiSkImageFilter>(
135
74
  getContext(),
136
- SkImageFilters::Compose(std::move(outer), std::move(inner)));
137
- return makeJsiObject(runtime, std::move(filter));
75
+ SkImageFilters::DisplacementMap(
76
+ static_cast<SkColorChannel>(xChannelSelector),
77
+ static_cast<SkColorChannel>(yChannelSelector), scale,
78
+ std::move(in2), orNull(std::move(input)), toCropRect(crop)));
138
79
  }
139
80
 
140
- JSI_HOST_FUNCTION(MakeBlend) {
141
- auto mode = static_cast<SkBlendMode>(arguments[0].asNumber());
142
- sk_sp<SkImageFilter> background =
143
- JsiSkImageFilter::fromValue(runtime, arguments[1]);
144
- sk_sp<SkImageFilter> foreground = nullptr;
145
-
146
- if (hasOptionalArgument(arguments, count, 2)) {
147
- foreground = JsiSkImageFilter::fromValue(runtime, arguments[2]);
148
- }
81
+ std::shared_ptr<JsiSkImageFilter> MakeShader(sk_sp<SkShader> shader,
82
+ JsiOptional<bool> dither,
83
+ JsiOptional<SkRect> crop) {
84
+ auto ditherMode = dither.has_value() && *dither
85
+ ? SkImageFilters::Dither::kYes
86
+ : SkImageFilters::Dither::kNo;
87
+ return std::make_shared<JsiSkImageFilter>(
88
+ getContext(),
89
+ SkImageFilters::Shader(std::move(shader), ditherMode, toCropRect(crop)));
90
+ }
149
91
 
150
- SkImageFilters::CropRect cropRect = {};
151
- if (hasOptionalArgument(arguments, count, 3)) {
152
- cropRect = *JsiSkRect::fromValue(runtime, arguments[3]);
153
- }
92
+ std::shared_ptr<JsiSkImageFilter>
93
+ MakeCompose(JsiOptional<sk_sp<SkImageFilter>> outer,
94
+ JsiOptional<sk_sp<SkImageFilter>> inner) {
95
+ return std::make_shared<JsiSkImageFilter>(
96
+ getContext(), SkImageFilters::Compose(orNull(std::move(outer)),
97
+ orNull(std::move(inner))));
98
+ }
154
99
 
155
- auto filter = std::make_shared<JsiSkImageFilter>(
100
+ std::shared_ptr<JsiSkImageFilter>
101
+ MakeBlend(double mode, sk_sp<SkImageFilter> background,
102
+ JsiOptional<sk_sp<SkImageFilter>> foreground,
103
+ JsiOptional<SkRect> crop) {
104
+ return std::make_shared<JsiSkImageFilter>(
156
105
  getContext(),
157
- SkImageFilters::Blend(std::move(mode), std::move(background),
158
- std::move(foreground), cropRect));
159
- return makeJsiObject(runtime, std::move(filter));
160
- }
161
-
162
- JSI_HOST_FUNCTION(MakeDropShadow) {
163
- auto dx = arguments[0].asNumber();
164
- auto dy = arguments[1].asNumber();
165
- auto sigmaX = arguments[2].asNumber();
166
- auto sigmaY = arguments[3].asNumber();
167
- auto color = JsiSkColor::fromValue(runtime, arguments[4]);
168
- sk_sp<SkImageFilter> input = nullptr;
169
- if (hasOptionalArgument(arguments, count, 5)) {
170
- input = JsiSkImageFilter::fromValue(runtime, arguments[5]);
171
- }
172
- SkImageFilters::CropRect cropRect = {};
173
- if (hasOptionalArgument(arguments, count, 6)) {
174
- cropRect = *JsiSkRect::fromValue(runtime, arguments[6]);
175
- }
176
- auto filter = std::make_shared<JsiSkImageFilter>(
177
- getContext(), SkImageFilters::DropShadow(dx, dy, sigmaX, sigmaY, color,
178
- std::move(input), cropRect));
179
- return makeJsiObject(runtime, std::move(filter));
180
- }
181
-
182
- JSI_HOST_FUNCTION(MakeDropShadowOnly) {
183
- auto dx = arguments[0].asNumber();
184
- auto dy = arguments[1].asNumber();
185
- auto sigmaX = arguments[2].asNumber();
186
- auto sigmaY = arguments[3].asNumber();
187
- auto color = JsiSkColor::fromValue(runtime, arguments[4]);
188
- sk_sp<SkImageFilter> input = nullptr;
189
- if (hasOptionalArgument(arguments, count, 5)) {
190
- input = JsiSkImageFilter::fromValue(runtime, arguments[5]);
191
- }
192
- SkImageFilters::CropRect cropRect = {};
193
- if (hasOptionalArgument(arguments, count, 6)) {
194
- cropRect = *JsiSkRect::fromValue(runtime, arguments[6]);
195
- }
196
- auto filter = std::make_shared<JsiSkImageFilter>(
197
- getContext(),
198
- SkImageFilters::DropShadowOnly(dx, dy, sigmaX, sigmaY, color,
199
- std::move(input), cropRect));
200
- return makeJsiObject(runtime, std::move(filter));
106
+ SkImageFilters::Blend(static_cast<SkBlendMode>(mode),
107
+ std::move(background),
108
+ orNull(std::move(foreground)), toCropRect(crop)));
201
109
  }
202
110
 
203
- JSI_HOST_FUNCTION(MakeErode) {
204
- auto rx = arguments[0].asNumber();
205
- auto ry = arguments[1].asNumber();
206
- sk_sp<SkImageFilter> input = nullptr;
207
- if (hasOptionalArgument(arguments, count, 2)) {
208
- input = JsiSkImageFilter::fromValue(runtime, arguments[2]);
209
- }
210
- SkImageFilters::CropRect cropRect = {};
211
- if (hasOptionalArgument(arguments, count, 3)) {
212
- cropRect = *JsiSkRect::fromValue(runtime, arguments[3]);
213
- }
214
- auto filter = std::make_shared<JsiSkImageFilter>(
111
+ std::shared_ptr<JsiSkImageFilter>
112
+ MakeDropShadow(double dx, double dy, double sigmaX, double sigmaY,
113
+ JsiColor color, JsiOptional<sk_sp<SkImageFilter>> input,
114
+ JsiOptional<SkRect> crop) {
115
+ return std::make_shared<JsiSkImageFilter>(
215
116
  getContext(),
216
- SkImageFilters::Erode(rx, ry, std::move(input), cropRect));
217
- return makeJsiObject(runtime, std::move(filter));
117
+ SkImageFilters::DropShadow(dx, dy, sigmaX, sigmaY, color,
118
+ orNull(std::move(input)), toCropRect(crop)));
218
119
  }
219
120
 
220
- JSI_HOST_FUNCTION(MakeDilate) {
221
- auto rx = arguments[0].asNumber();
222
- auto ry = arguments[1].asNumber();
223
- sk_sp<SkImageFilter> input = nullptr;
224
- if (hasOptionalArgument(arguments, count, 2)) {
225
- input = JsiSkImageFilter::fromValue(runtime, arguments[2]);
226
- }
227
- SkImageFilters::CropRect cropRect = {};
228
- if (hasOptionalArgument(arguments, count, 3)) {
229
- cropRect = *JsiSkRect::fromValue(runtime, arguments[3]);
230
- }
231
- auto filter = std::make_shared<JsiSkImageFilter>(
232
- getContext(),
233
- SkImageFilters::Dilate(rx, ry, std::move(input), cropRect));
234
- return makeJsiObject(runtime, std::move(filter));
121
+ std::shared_ptr<JsiSkImageFilter>
122
+ MakeDropShadowOnly(double dx, double dy, double sigmaX, double sigmaY,
123
+ JsiColor color, JsiOptional<sk_sp<SkImageFilter>> input,
124
+ JsiOptional<SkRect> crop) {
125
+ return std::make_shared<JsiSkImageFilter>(
126
+ getContext(), SkImageFilters::DropShadowOnly(
127
+ dx, dy, sigmaX, sigmaY, color,
128
+ orNull(std::move(input)), toCropRect(crop)));
235
129
  }
236
130
 
237
- JSI_HOST_FUNCTION(MakeRuntimeShader) {
238
- auto rtb = JsiSkRuntimeShaderBuilder::fromValue(runtime, arguments[0]);
131
+ std::shared_ptr<JsiSkImageFilter>
132
+ MakeErode(double rx, double ry, JsiOptional<sk_sp<SkImageFilter>> input,
133
+ JsiOptional<SkRect> crop) {
134
+ return std::make_shared<JsiSkImageFilter>(
135
+ getContext(), SkImageFilters::Erode(rx, ry, orNull(std::move(input)),
136
+ toCropRect(crop)));
137
+ }
239
138
 
240
- std::string childNameStr = "";
241
- const char *childName = childNameStr.c_str();
242
- if (hasOptionalArgument(arguments, count, 1)) {
243
- childNameStr = arguments[1].asString(runtime).utf8(runtime);
244
- childName = childNameStr.c_str();
245
- }
139
+ std::shared_ptr<JsiSkImageFilter>
140
+ MakeDilate(double rx, double ry, JsiOptional<sk_sp<SkImageFilter>> input,
141
+ JsiOptional<SkRect> crop) {
142
+ return std::make_shared<JsiSkImageFilter>(
143
+ getContext(), SkImageFilters::Dilate(rx, ry, orNull(std::move(input)),
144
+ toCropRect(crop)));
145
+ }
246
146
 
247
- sk_sp<SkImageFilter> input = nullptr;
248
- if (hasOptionalArgument(arguments, count, 2)) {
249
- input = JsiSkImageFilter::fromValue(runtime, arguments[2]);
250
- }
251
- auto filter = std::make_shared<JsiSkImageFilter>(
147
+ std::shared_ptr<JsiSkImageFilter>
148
+ MakeRuntimeShader(std::shared_ptr<SkRuntimeShaderBuilder> rtb,
149
+ JsiOptional<std::string> childName,
150
+ JsiOptional<sk_sp<SkImageFilter>> input) {
151
+ std::string childNameStr = childName.value_or("");
152
+ return std::make_shared<JsiSkImageFilter>(
252
153
  getContext(),
253
- SkImageFilters::RuntimeShader(*rtb, childName, std::move(input)));
254
- return makeJsiObject(runtime, std::move(filter));
255
- }
256
-
257
- JSI_HOST_FUNCTION(MakeArithmetic) {
258
- float k1 = arguments[0].asNumber();
259
- float k2 = arguments[1].asNumber();
260
- float k3 = arguments[2].asNumber();
261
- float k4 = arguments[3].asNumber();
262
- bool enforcePMColor = arguments[4].asBool();
263
- sk_sp<SkImageFilter> background = nullptr;
264
- if (hasOptionalArgument(arguments, count, 5)) {
265
- background = JsiSkImageFilter::fromValue(runtime, arguments[5]);
266
- }
267
- sk_sp<SkImageFilter> foreground = nullptr;
268
- if (hasOptionalArgument(arguments, count, 6)) {
269
- foreground = JsiSkImageFilter::fromValue(runtime, arguments[6]);
270
- }
271
- SkImageFilters::CropRect cropRect = {};
272
- if (hasOptionalArgument(arguments, count, 7)) {
273
- cropRect = *JsiSkRect::fromValue(runtime, arguments[7]);
274
- }
275
- auto filter = std::make_shared<JsiSkImageFilter>(
276
- getContext(), SkImageFilters::Arithmetic(
277
- k1, k2, k3, k4, enforcePMColor, std::move(background),
278
- std::move(foreground), cropRect));
279
- return makeJsiObject(runtime, std::move(filter));
280
- }
281
-
282
- JSI_HOST_FUNCTION(MakeCrop) {
283
- SkRect rect = *JsiSkRect::fromValue(runtime, arguments[0]);
284
- SkTileMode tileMode = SkTileMode::kDecal;
285
- if (hasOptionalArgument(arguments, count, 1)) {
286
- tileMode = (SkTileMode)arguments[1].asNumber();
287
- }
288
- sk_sp<SkImageFilter> imageFilter = nullptr;
289
- if (hasOptionalArgument(arguments, count, 2)) {
290
- imageFilter = JsiSkImageFilter::fromValue(runtime, arguments[2]);
291
- }
292
- auto filter = std::make_shared<JsiSkImageFilter>(
154
+ SkImageFilters::RuntimeShader(*rtb, childNameStr.c_str(),
155
+ orNull(std::move(input))));
156
+ }
157
+
158
+ std::shared_ptr<JsiSkImageFilter>
159
+ MakeArithmetic(float k1, float k2, float k3, float k4, bool enforcePMColor,
160
+ JsiOptional<sk_sp<SkImageFilter>> background,
161
+ JsiOptional<sk_sp<SkImageFilter>> foreground,
162
+ JsiOptional<SkRect> crop) {
163
+ return std::make_shared<JsiSkImageFilter>(
293
164
  getContext(),
294
- SkImageFilters::Crop(rect, tileMode, std::move(imageFilter)));
295
- return makeJsiObject(runtime, std::move(filter));
165
+ SkImageFilters::Arithmetic(k1, k2, k3, k4, enforcePMColor,
166
+ orNull(std::move(background)),
167
+ orNull(std::move(foreground)),
168
+ toCropRect(crop)));
296
169
  }
297
170
 
298
- JSI_HOST_FUNCTION(MakeEmpty) {
299
- auto filter = std::make_shared<JsiSkImageFilter>(getContext(),
300
- SkImageFilters::Empty());
301
- return makeJsiObject(runtime, std::move(filter));
171
+ std::shared_ptr<JsiSkImageFilter>
172
+ MakeCrop(SkRect rect, JsiOptional<double> tileMode,
173
+ JsiOptional<sk_sp<SkImageFilter>> imageFilter) {
174
+ auto mode = tileMode.has_value() ? static_cast<SkTileMode>(*tileMode)
175
+ : SkTileMode::kDecal;
176
+ return std::make_shared<JsiSkImageFilter>(
177
+ getContext(),
178
+ SkImageFilters::Crop(rect, mode, orNull(std::move(imageFilter))));
302
179
  }
303
180
 
304
- inline SkPoint3 SkPoint3FromValue(jsi::Runtime &runtime,
305
- const jsi::Value &obj) {
306
- const auto &object = obj.asObject(runtime);
307
- auto x = object.getProperty(runtime, "x").asNumber();
308
- auto y = object.getProperty(runtime, "y").asNumber();
309
- auto z = object.getProperty(runtime, "z").asNumber();
310
- return SkPoint3::Make(x, y, z);
181
+ std::shared_ptr<JsiSkImageFilter> MakeEmpty() {
182
+ return std::make_shared<JsiSkImageFilter>(getContext(),
183
+ SkImageFilters::Empty());
311
184
  }
312
185
 
313
- JSI_HOST_FUNCTION(MakeDistantLitDiffuse) {
314
- SkPoint3 direction = SkPoint3FromValue(runtime, arguments[0]);
315
- SkColor lightColor = JsiSkColor::fromValue(runtime, arguments[1]);
316
- float surfaceScale = arguments[2].asNumber();
317
- float kd = arguments[3].asNumber();
318
- sk_sp<SkImageFilter> input = nullptr;
319
- if (hasOptionalArgument(arguments, count, 4)) {
320
- input = JsiSkImageFilter::fromValue(runtime, arguments[4]);
321
- }
322
- SkImageFilters::CropRect cropRect = {};
323
- if (hasOptionalArgument(arguments, count, 5)) {
324
- cropRect = *JsiSkRect::fromValue(runtime, arguments[5]);
325
- }
326
- auto filter = std::make_shared<JsiSkImageFilter>(
327
- getContext(),
328
- SkImageFilters::DistantLitDiffuse(direction, lightColor, surfaceScale,
329
- kd, std::move(input), cropRect));
330
- return makeJsiObject(runtime, std::move(filter));
331
- }
332
-
333
- JSI_HOST_FUNCTION(MakePointLitDiffuse) {
334
- SkPoint3 location = SkPoint3FromValue(runtime, arguments[0]);
335
- SkColor lightColor = JsiSkColor::fromValue(runtime, arguments[1]);
336
- float surfaceScale = arguments[2].asNumber();
337
- float kd = arguments[3].asNumber();
338
- sk_sp<SkImageFilter> input = nullptr;
339
- if (hasOptionalArgument(arguments, count, 4)) {
340
- input = JsiSkImageFilter::fromValue(runtime, arguments[4]);
341
- }
342
- SkImageFilters::CropRect cropRect = {};
343
- if (hasOptionalArgument(arguments, count, 5)) {
344
- cropRect = *JsiSkRect::fromValue(runtime, arguments[5]);
345
- }
346
- auto filter = std::make_shared<JsiSkImageFilter>(
347
- getContext(),
348
- SkImageFilters::PointLitDiffuse(location, lightColor, surfaceScale, kd,
349
- std::move(input), cropRect));
350
- return makeJsiObject(runtime, std::move(filter));
351
- }
352
-
353
- JSI_HOST_FUNCTION(MakeSpotLitDiffuse) {
354
- SkPoint3 location = SkPoint3FromValue(runtime, arguments[0]);
355
- SkPoint3 target = SkPoint3FromValue(runtime, arguments[1]);
356
- float falloffExponent = arguments[2].asNumber();
357
- float cutoffAngle = arguments[3].asNumber();
358
- SkColor lightColor = JsiSkColor::fromValue(runtime, arguments[4]);
359
- float surfaceScale = arguments[5].asNumber();
360
- float kd = arguments[6].asNumber();
361
- sk_sp<SkImageFilter> input = nullptr;
362
- if (hasOptionalArgument(arguments, count, 7)) {
363
- input = JsiSkImageFilter::fromValue(runtime, arguments[7]);
364
- }
365
- SkImageFilters::CropRect cropRect = {};
366
- if (hasOptionalArgument(arguments, count, 8)) {
367
- cropRect = *JsiSkRect::fromValue(runtime, arguments[8]);
368
- }
369
- auto filter = std::make_shared<JsiSkImageFilter>(
370
- getContext(),
371
- SkImageFilters::SpotLitDiffuse(location, target, falloffExponent,
372
- cutoffAngle, lightColor, surfaceScale,
373
- kd, std::move(input), cropRect));
374
- return makeJsiObject(runtime, std::move(filter));
375
- }
376
-
377
- JSI_HOST_FUNCTION(MakeDistantLitSpecular) {
378
- SkPoint3 direction = SkPoint3FromValue(runtime, arguments[0]);
379
- SkColor lightColor = JsiSkColor::fromValue(runtime, arguments[1]);
380
- float surfaceScale = arguments[2].asNumber();
381
- float ks = arguments[3].asNumber();
382
- float shininess = arguments[4].asNumber();
383
- sk_sp<SkImageFilter> input = nullptr;
384
- if (hasOptionalArgument(arguments, count, 5)) {
385
- input = JsiSkImageFilter::fromValue(runtime, arguments[5]);
386
- }
387
- SkImageFilters::CropRect cropRect = {};
388
- if (hasOptionalArgument(arguments, count, 6)) {
389
- cropRect = *JsiSkRect::fromValue(runtime, arguments[6]);
390
- }
391
- auto filter = std::make_shared<JsiSkImageFilter>(
186
+ std::shared_ptr<JsiSkImageFilter>
187
+ MakeDistantLitDiffuse(SkPoint3 direction, JsiColor lightColor,
188
+ float surfaceScale, float kd,
189
+ JsiOptional<sk_sp<SkImageFilter>> input,
190
+ JsiOptional<SkRect> crop) {
191
+ return std::make_shared<JsiSkImageFilter>(
192
+ getContext(), SkImageFilters::DistantLitDiffuse(
193
+ direction, lightColor, surfaceScale, kd,
194
+ orNull(std::move(input)), toCropRect(crop)));
195
+ }
196
+
197
+ std::shared_ptr<JsiSkImageFilter>
198
+ MakePointLitDiffuse(SkPoint3 location, JsiColor lightColor,
199
+ float surfaceScale, float kd,
200
+ JsiOptional<sk_sp<SkImageFilter>> input,
201
+ JsiOptional<SkRect> crop) {
202
+ return std::make_shared<JsiSkImageFilter>(
203
+ getContext(), SkImageFilters::PointLitDiffuse(
204
+ location, lightColor, surfaceScale, kd,
205
+ orNull(std::move(input)), toCropRect(crop)));
206
+ }
207
+
208
+ std::shared_ptr<JsiSkImageFilter>
209
+ MakeSpotLitDiffuse(SkPoint3 location, SkPoint3 target, float falloffExponent,
210
+ float cutoffAngle, JsiColor lightColor, float surfaceScale,
211
+ float kd, JsiOptional<sk_sp<SkImageFilter>> input,
212
+ JsiOptional<SkRect> crop) {
213
+ return std::make_shared<JsiSkImageFilter>(
214
+ getContext(), SkImageFilters::SpotLitDiffuse(
215
+ location, target, falloffExponent, cutoffAngle,
216
+ lightColor, surfaceScale, kd,
217
+ orNull(std::move(input)), toCropRect(crop)));
218
+ }
219
+
220
+ std::shared_ptr<JsiSkImageFilter>
221
+ MakeDistantLitSpecular(SkPoint3 direction, JsiColor lightColor,
222
+ float surfaceScale, float ks, float shininess,
223
+ JsiOptional<sk_sp<SkImageFilter>> input,
224
+ JsiOptional<SkRect> crop) {
225
+ return std::make_shared<JsiSkImageFilter>(
392
226
  getContext(), SkImageFilters::DistantLitSpecular(
393
227
  direction, lightColor, surfaceScale, ks, shininess,
394
- std::move(input), cropRect));
395
- return makeJsiObject(runtime, std::move(filter));
396
- }
397
-
398
- JSI_HOST_FUNCTION(MakePointLitSpecular) {
399
- SkPoint3 location = SkPoint3FromValue(runtime, arguments[0]);
400
- SkColor lightColor = JsiSkColor::fromValue(runtime, arguments[1]);
401
- float surfaceScale = arguments[2].asNumber();
402
- float ks = arguments[3].asNumber();
403
- float shininess = arguments[4].asNumber();
404
- sk_sp<SkImageFilter> input = nullptr;
405
- if (hasOptionalArgument(arguments, count, 5)) {
406
- input = JsiSkImageFilter::fromValue(runtime, arguments[5]);
407
- }
408
- SkImageFilters::CropRect cropRect = {};
409
- if (hasOptionalArgument(arguments, count, 6)) {
410
- cropRect = *JsiSkRect::fromValue(runtime, arguments[6]);
411
- }
412
- auto filter = std::make_shared<JsiSkImageFilter>(
228
+ orNull(std::move(input)), toCropRect(crop)));
229
+ }
230
+
231
+ std::shared_ptr<JsiSkImageFilter>
232
+ MakePointLitSpecular(SkPoint3 location, JsiColor lightColor,
233
+ float surfaceScale, float ks, float shininess,
234
+ JsiOptional<sk_sp<SkImageFilter>> input,
235
+ JsiOptional<SkRect> crop) {
236
+ return std::make_shared<JsiSkImageFilter>(
413
237
  getContext(), SkImageFilters::PointLitSpecular(
414
238
  location, lightColor, surfaceScale, ks, shininess,
415
- std::move(input), cropRect));
416
- return makeJsiObject(runtime, std::move(filter));
417
- }
418
-
419
- JSI_HOST_FUNCTION(MakeSpotLitSpecular) {
420
- SkPoint3 location = SkPoint3FromValue(runtime, arguments[0]);
421
- SkPoint3 target = SkPoint3FromValue(runtime, arguments[1]);
422
- float falloffExponent = arguments[2].asNumber();
423
- float cutoffAngle = arguments[3].asNumber();
424
- SkColor lightColor = JsiSkColor::fromValue(runtime, arguments[4]);
425
- float surfaceScale = arguments[5].asNumber();
426
- float ks = arguments[6].asNumber();
427
- float shininess = arguments[7].asNumber();
428
- sk_sp<SkImageFilter> input = nullptr;
429
- if (hasOptionalArgument(arguments, count, 8)) {
430
- input = JsiSkImageFilter::fromValue(runtime, arguments[8]);
431
- }
432
- SkImageFilters::CropRect cropRect = {};
433
- if (hasOptionalArgument(arguments, count, 9)) {
434
- cropRect = *JsiSkRect::fromValue(runtime, arguments[9]);
435
- }
436
- auto filter = std::make_shared<JsiSkImageFilter>(
239
+ orNull(std::move(input)), toCropRect(crop)));
240
+ }
241
+
242
+ std::shared_ptr<JsiSkImageFilter>
243
+ MakeSpotLitSpecular(SkPoint3 location, SkPoint3 target,
244
+ float falloffExponent, float cutoffAngle,
245
+ JsiColor lightColor, float surfaceScale, float ks,
246
+ float shininess, JsiOptional<sk_sp<SkImageFilter>> input,
247
+ JsiOptional<SkRect> crop) {
248
+ return std::make_shared<JsiSkImageFilter>(
437
249
  getContext(),
438
- SkImageFilters::SpotLitSpecular(
439
- location, target, falloffExponent, cutoffAngle, lightColor,
440
- surfaceScale, ks, shininess, std::move(input), cropRect));
441
- return makeJsiObject(runtime, std::move(filter));
442
- }
443
-
444
- JSI_HOST_FUNCTION(MakeImage) {
445
- sk_sp<SkImage> image = JsiSkImage::fromValue(runtime, arguments[0]);
446
- SkRect srcRect;
447
- if (hasOptionalArgument(arguments, count, 1)) {
448
- srcRect = *JsiSkRect::fromValue(runtime, arguments[1]);
449
- } else {
450
- srcRect = SkRect::Make(image->bounds());
451
- }
452
- SkRect dstRect;
453
- if (hasOptionalArgument(arguments, count, 2)) {
454
- dstRect = *JsiSkRect::fromValue(runtime, arguments[2]);
455
- } else {
456
- dstRect = srcRect;
457
- }
458
- SkFilterMode filterMode = SkFilterMode::kNearest;
459
- if (hasOptionalArgument(arguments, count, 3)) {
460
- filterMode = (SkFilterMode)arguments[3].asNumber();
461
- }
462
- SkMipmapMode mipmap = SkMipmapMode::kNone;
463
- if (hasOptionalArgument(arguments, count, 4)) {
464
- mipmap = (SkMipmapMode)arguments[4].asNumber();
465
- }
466
- auto filter = std::make_shared<JsiSkImageFilter>(
250
+ SkImageFilters::SpotLitSpecular(location, target, falloffExponent,
251
+ cutoffAngle, lightColor, surfaceScale,
252
+ ks, shininess, orNull(std::move(input)),
253
+ toCropRect(crop)));
254
+ }
255
+
256
+ std::shared_ptr<JsiSkImageFilter>
257
+ MakeImage(sk_sp<SkImage> image, JsiOptional<SkRect> src,
258
+ JsiOptional<SkRect> dst, JsiOptional<double> filterMode,
259
+ JsiOptional<double> mipmap) {
260
+ SkRect srcRect = src.has_value() ? *src : SkRect::Make(image->bounds());
261
+ SkRect dstRect = dst.has_value() ? *dst : srcRect;
262
+ auto sampling = SkSamplingOptions(toFilterMode(filterMode),
263
+ toMipmapMode(mipmap));
264
+ return std::make_shared<JsiSkImageFilter>(
467
265
  getContext(),
468
- SkImageFilters::Image(std::move(image), srcRect, dstRect,
469
- SkSamplingOptions(filterMode, mipmap)));
470
- return makeJsiObject(runtime, std::move(filter));
471
- }
472
-
473
- JSI_HOST_FUNCTION(MakeMagnifier) {
474
- SkRect lensBounds = *JsiSkRect::fromValue(runtime, arguments[0]);
475
- float zoomAmount = arguments[1].asNumber();
476
- float inset = arguments[2].asNumber();
477
- SkFilterMode filterMode = SkFilterMode::kNearest;
478
- if (hasOptionalArgument(arguments, count, 3)) {
479
- filterMode = (SkFilterMode)arguments[3].asNumber();
480
- }
481
- SkMipmapMode mipmap = SkMipmapMode::kNone;
482
- if (hasOptionalArgument(arguments, count, 4)) {
483
- mipmap = (SkMipmapMode)arguments[4].asNumber();
484
- }
485
- sk_sp<SkImageFilter> input = nullptr;
486
- if (hasOptionalArgument(arguments, count, 5)) {
487
- input = JsiSkImageFilter::fromValue(runtime, arguments[5]);
488
- }
489
- SkImageFilters::CropRect cropRect = {};
490
- if (hasOptionalArgument(arguments, count, 6)) {
491
- cropRect = *JsiSkRect::fromValue(runtime, arguments[6]);
492
- }
493
- auto filter = std::make_shared<JsiSkImageFilter>(
266
+ SkImageFilters::Image(std::move(image), srcRect, dstRect, sampling));
267
+ }
268
+
269
+ std::shared_ptr<JsiSkImageFilter>
270
+ MakeMagnifier(SkRect lensBounds, float zoomAmount, float inset,
271
+ JsiOptional<double> filterMode, JsiOptional<double> mipmap,
272
+ JsiOptional<sk_sp<SkImageFilter>> input,
273
+ JsiOptional<SkRect> crop) {
274
+ auto sampling = SkSamplingOptions(toFilterMode(filterMode),
275
+ toMipmapMode(mipmap));
276
+ return std::make_shared<JsiSkImageFilter>(
494
277
  getContext(),
495
- SkImageFilters::Magnifier(lensBounds, zoomAmount, inset,
496
- SkSamplingOptions(filterMode, mipmap), input,
497
- cropRect));
498
- return makeJsiObject(runtime, std::move(filter));
499
- }
500
-
501
- JSI_HOST_FUNCTION(MakeMatrixConvolution) {
502
- SkISize kernelSize =
503
- SkISize::Make(arguments[0].asNumber(), arguments[1].asNumber());
504
- std::vector<float> kernel;
505
- auto kernelArray = arguments[2].asObject(runtime).asArray(runtime);
506
- auto size = kernelArray.size(runtime);
507
- for (size_t i = 0; i < size; i++) {
508
- kernel.push_back(kernelArray.getValueAtIndex(runtime, i).asNumber());
509
- }
510
- auto gain = arguments[3].asNumber();
511
- auto bias = arguments[4].asNumber();
512
- SkIPoint kernelOffset =
513
- SkIPoint::Make(arguments[5].asNumber(), arguments[6].asNumber());
514
- auto tileMode = static_cast<SkTileMode>(arguments[7].asNumber());
515
- bool convolveAlpha = arguments[8].asBool();
516
- sk_sp<SkImageFilter> input = nullptr;
517
- if (hasOptionalArgument(arguments, count, 9)) {
518
- input = JsiSkImageFilter::fromValue(runtime, arguments[9]);
519
- }
520
- SkImageFilters::CropRect cropRect = {};
521
- if (hasOptionalArgument(arguments, count, 10)) {
522
- cropRect = *JsiSkRect::fromValue(runtime, arguments[10]);
523
- }
524
- auto filter = std::make_shared<JsiSkImageFilter>(
525
- getContext(), SkImageFilters::MatrixConvolution(
526
- kernelSize, kernel.data(), gain, bias, kernelOffset,
527
- tileMode, convolveAlpha, std::move(input), cropRect));
528
- return makeJsiObject(runtime, std::move(filter));
529
- }
530
-
531
- JSI_HOST_FUNCTION(MakeMatrixTransform) {
532
- SkMatrix matrix = *JsiSkMatrix::fromValue(runtime, arguments[0]);
533
- SkFilterMode filterMode = SkFilterMode::kNearest;
534
- if (hasOptionalArgument(arguments, count, 1)) {
535
- filterMode = (SkFilterMode)arguments[1].asNumber();
536
- }
537
- SkMipmapMode mipmap = SkMipmapMode::kNone;
538
- if (hasOptionalArgument(arguments, count, 2)) {
539
- mipmap = (SkMipmapMode)arguments[2].asNumber();
540
- }
541
- sk_sp<SkImageFilter> input = nullptr;
542
- if (hasOptionalArgument(arguments, count, 3)) {
543
- input = JsiSkImageFilter::fromValue(runtime, arguments[3]);
544
- }
545
- auto filter = std::make_shared<JsiSkImageFilter>(
278
+ SkImageFilters::Magnifier(lensBounds, zoomAmount, inset, sampling,
279
+ orNull(std::move(input)), toCropRect(crop)));
280
+ }
281
+
282
+ std::shared_ptr<JsiSkImageFilter> MakeMatrixConvolution(
283
+ int kernelSizeX, int kernelSizeY, std::vector<float> kernel, double gain,
284
+ double bias, int kernelOffsetX, int kernelOffsetY, double tileMode,
285
+ bool convolveAlpha, JsiOptional<sk_sp<SkImageFilter>> input,
286
+ JsiOptional<SkRect> crop) {
287
+ auto kernelSize = SkISize::Make(kernelSizeX, kernelSizeY);
288
+ auto kernelOffset = SkIPoint::Make(kernelOffsetX, kernelOffsetY);
289
+ return std::make_shared<JsiSkImageFilter>(
546
290
  getContext(),
547
- SkImageFilters::MatrixTransform(
548
- matrix, SkSamplingOptions(filterMode, mipmap), std::move(input)));
549
- return makeJsiObject(runtime, std::move(filter));
291
+ SkImageFilters::MatrixConvolution(
292
+ kernelSize, kernel.data(), gain, bias, kernelOffset,
293
+ static_cast<SkTileMode>(tileMode), convolveAlpha,
294
+ orNull(std::move(input)), toCropRect(crop)));
550
295
  }
551
296
 
552
- JSI_HOST_FUNCTION(MakeMerge) {
297
+ std::shared_ptr<JsiSkImageFilter>
298
+ MakeMatrixTransform(SkMatrix matrix, JsiOptional<double> filterMode,
299
+ JsiOptional<double> mipmap,
300
+ JsiOptional<sk_sp<SkImageFilter>> input) {
301
+ auto sampling = SkSamplingOptions(toFilterMode(filterMode),
302
+ toMipmapMode(mipmap));
303
+ return std::make_shared<JsiSkImageFilter>(
304
+ getContext(), SkImageFilters::MatrixTransform(
305
+ matrix, sampling, orNull(std::move(input))));
306
+ }
307
+
308
+ std::shared_ptr<JsiSkImageFilter>
309
+ MakeMerge(std::vector<JsiOptional<sk_sp<SkImageFilter>>> jsiFilters,
310
+ JsiOptional<SkRect> crop) {
553
311
  std::vector<sk_sp<SkImageFilter>> filters;
554
- auto filtersArray = arguments[0].asObject(runtime).asArray(runtime);
555
- auto filtersCount = filtersArray.size(runtime);
556
- for (size_t i = 0; i < filtersCount; ++i) {
557
- auto element = filtersArray.getValueAtIndex(runtime, i);
558
- if (element.isNull()) {
559
- filters.push_back(nullptr);
560
- } else {
561
- filters.push_back(JsiSkImageFilter::fromValue(runtime, element));
562
- }
312
+ filters.reserve(jsiFilters.size());
313
+ for (auto &filter : jsiFilters) {
314
+ filters.push_back(orNull(std::move(filter)));
563
315
  }
564
- SkImageFilters::CropRect cropRect = {};
565
- if (hasOptionalArgument(arguments, count, 1)) {
566
- cropRect = *JsiSkRect::fromValue(runtime, arguments[1]);
567
- }
568
- auto filter = std::make_shared<JsiSkImageFilter>(
316
+ return std::make_shared<JsiSkImageFilter>(
569
317
  getContext(),
570
- SkImageFilters::Merge(filters.data(), filtersCount, cropRect));
571
- return makeJsiObject(runtime, std::move(filter));
318
+ SkImageFilters::Merge(filters.data(), filters.size(), toCropRect(crop)));
572
319
  }
573
320
 
574
- JSI_HOST_FUNCTION(MakePicture) {
575
- sk_sp<SkPicture> picture = JsiSkPicture::fromValue(runtime, arguments[0]);
576
- SkRect targetRect;
577
- if (hasOptionalArgument(arguments, count, 1)) {
578
- targetRect = *JsiSkRect::fromValue(runtime, arguments[1]);
579
- } else {
580
- targetRect = picture ? picture->cullRect() : SkRect::MakeEmpty();
581
- }
582
- auto filter = std::make_shared<JsiSkImageFilter>(
321
+ std::shared_ptr<JsiSkImageFilter> MakePicture(sk_sp<SkPicture> picture,
322
+ JsiOptional<SkRect> target) {
323
+ SkRect targetRect = target.has_value()
324
+ ? *target
325
+ : (picture ? picture->cullRect()
326
+ : SkRect::MakeEmpty());
327
+ return std::make_shared<JsiSkImageFilter>(
583
328
  getContext(), SkImageFilters::Picture(std::move(picture), targetRect));
584
- return makeJsiObject(runtime, std::move(filter));
585
- }
586
-
587
- JSI_HOST_FUNCTION(MakeRuntimeShaderWithChildren) {
588
- auto rtb = JsiSkRuntimeShaderBuilder::fromValue(runtime, arguments[0]);
589
- float maxSampleRadius = arguments[1].asNumber();
590
- std::vector<std::string> childNames;
591
- auto childNamesJS = arguments[2].asObject(runtime).asArray(runtime);
592
- size_t length = childNamesJS.size(runtime);
593
- for (size_t i = 0; i < length; ++i) {
594
- auto element = childNamesJS.getValueAtIndex(runtime, i);
595
- childNames.push_back(element.asString(runtime).utf8(runtime).c_str());
329
+ }
330
+
331
+ std::variant<std::nullptr_t, std::shared_ptr<JsiSkImageFilter>>
332
+ MakeRuntimeShaderWithChildren(
333
+ std::shared_ptr<SkRuntimeShaderBuilder> rtb, float maxSampleRadius,
334
+ std::vector<std::string> childNames,
335
+ std::vector<JsiOptional<sk_sp<SkImageFilter>>> jsiInputs) {
336
+ if (jsiInputs.size() != childNames.size()) {
337
+ return nullptr;
596
338
  }
597
339
  std::vector<std::string_view> childNamesStringView;
598
340
  childNamesStringView.reserve(childNames.size());
599
341
  for (const auto &name : childNames) {
600
342
  childNamesStringView.push_back(std::string_view(name));
601
343
  }
602
-
603
344
  std::vector<sk_sp<SkImageFilter>> inputs;
604
- auto inputsJS = arguments[3].asObject(runtime).asArray(runtime);
605
- if (inputsJS.size(runtime) != length) {
606
- return jsi::Value::null();
607
- }
608
- for (size_t i = 0; i < length; ++i) {
609
- auto element = inputsJS.getValueAtIndex(runtime, i);
610
- if (element.isNull()) {
611
- inputs.push_back(nullptr);
612
- } else {
613
- inputs.push_back(JsiSkImageFilter::fromValue(runtime, element));
614
- }
615
- }
616
- auto filter = std::make_shared<JsiSkImageFilter>(
617
- getContext(), SkImageFilters::RuntimeShader(*rtb, maxSampleRadius,
618
- childNamesStringView.data(),
619
- inputs.data(), length));
620
- return makeJsiObject(runtime, std::move(filter));
621
- }
622
-
623
- JSI_HOST_FUNCTION(MakeTile) {
624
- SkRect src = *JsiSkRect::fromValue(runtime, arguments[0]);
625
- SkRect dst = *JsiSkRect::fromValue(runtime, arguments[1]);
626
- sk_sp<SkImageFilter> input = nullptr;
627
- if (hasOptionalArgument(arguments, count, 2)) {
628
- input = JsiSkImageFilter::fromValue(runtime, arguments[2]);
629
- }
630
- auto filter = std::make_shared<JsiSkImageFilter>(
631
- getContext(), SkImageFilters::Tile(src, dst, std::move(input)));
632
- return makeJsiObject(runtime, std::move(filter));
345
+ inputs.reserve(jsiInputs.size());
346
+ for (auto &input : jsiInputs) {
347
+ inputs.push_back(orNull(std::move(input)));
348
+ }
349
+ return std::make_shared<JsiSkImageFilter>(
350
+ getContext(), SkImageFilters::RuntimeShader(
351
+ *rtb, maxSampleRadius, childNamesStringView.data(),
352
+ inputs.data(), inputs.size()));
353
+ }
354
+
355
+ std::shared_ptr<JsiSkImageFilter>
356
+ MakeTile(SkRect src, SkRect dst, JsiOptional<sk_sp<SkImageFilter>> input) {
357
+ return std::make_shared<JsiSkImageFilter>(
358
+ getContext(), SkImageFilters::Tile(src, dst, orNull(std::move(input))));
633
359
  }
634
360
 
635
361
  static void definePrototype(jsi::Runtime &runtime, jsi::Object &prototype) {
636
- installHostMethod(runtime, prototype, "MakeBlur",
637
- &JsiSkImageFilterFactory::MakeBlur);
638
- installHostMethod(runtime, prototype, "MakeOffset",
639
- &JsiSkImageFilterFactory::MakeOffset);
640
- installHostMethod(runtime, prototype, "MakeColorFilter",
641
- &JsiSkImageFilterFactory::MakeColorFilter);
642
- installHostMethod(runtime, prototype, "MakeShader",
643
- &JsiSkImageFilterFactory::MakeShader);
644
- installHostMethod(runtime, prototype, "MakeDisplacementMap",
645
- &JsiSkImageFilterFactory::MakeDisplacementMap);
646
- installHostMethod(runtime, prototype, "MakeCompose",
647
- &JsiSkImageFilterFactory::MakeCompose);
648
- installHostMethod(runtime, prototype, "MakeErode",
649
- &JsiSkImageFilterFactory::MakeErode);
650
- installHostMethod(runtime, prototype, "MakeDilate",
651
- &JsiSkImageFilterFactory::MakeDilate);
652
- installHostMethod(runtime, prototype, "MakeBlend",
653
- &JsiSkImageFilterFactory::MakeBlend);
654
- installHostMethod(runtime, prototype, "MakeDropShadow",
655
- &JsiSkImageFilterFactory::MakeDropShadow);
656
- installHostMethod(runtime, prototype, "MakeDropShadowOnly",
657
- &JsiSkImageFilterFactory::MakeDropShadowOnly);
658
- installHostMethod(runtime, prototype, "MakeRuntimeShader",
659
- &JsiSkImageFilterFactory::MakeRuntimeShader);
660
- installHostMethod(runtime, prototype, "MakeArithmetic",
661
- &JsiSkImageFilterFactory::MakeArithmetic);
662
- installHostMethod(runtime, prototype, "MakeCrop",
663
- &JsiSkImageFilterFactory::MakeCrop);
664
- installHostMethod(runtime, prototype, "MakeEmpty",
665
- &JsiSkImageFilterFactory::MakeEmpty);
666
- installHostMethod(runtime, prototype, "MakeImage",
667
- &JsiSkImageFilterFactory::MakeImage);
668
- installHostMethod(runtime, prototype, "MakeMagnifier",
669
- &JsiSkImageFilterFactory::MakeMagnifier);
670
- installHostMethod(runtime, prototype, "MakeMatrixConvolution",
671
- &JsiSkImageFilterFactory::MakeMatrixConvolution);
672
- installHostMethod(runtime, prototype, "MakeMatrixTransform",
673
- &JsiSkImageFilterFactory::MakeMatrixTransform);
674
- installHostMethod(runtime, prototype, "MakeMerge",
675
- &JsiSkImageFilterFactory::MakeMerge);
676
- installHostMethod(runtime, prototype, "MakePicture",
677
- &JsiSkImageFilterFactory::MakePicture);
678
- installHostMethod(runtime, prototype, "MakeRuntimeShaderWithChildren",
679
- &JsiSkImageFilterFactory::MakeRuntimeShaderWithChildren);
680
- installHostMethod(runtime, prototype, "MakeTile",
681
- &JsiSkImageFilterFactory::MakeTile);
682
- installHostMethod(runtime, prototype, "MakeDistantLitDiffuse",
683
- &JsiSkImageFilterFactory::MakeDistantLitDiffuse);
684
- installHostMethod(runtime, prototype, "MakePointLitDiffuse",
685
- &JsiSkImageFilterFactory::MakePointLitDiffuse);
686
- installHostMethod(runtime, prototype, "MakeSpotLitDiffuse",
687
- &JsiSkImageFilterFactory::MakeSpotLitDiffuse);
688
- installHostMethod(runtime, prototype, "MakeDistantLitSpecular",
689
- &JsiSkImageFilterFactory::MakeDistantLitSpecular);
690
- installHostMethod(runtime, prototype, "MakePointLitSpecular",
691
- &JsiSkImageFilterFactory::MakePointLitSpecular);
692
- installHostMethod(runtime, prototype, "MakeSpotLitSpecular",
693
- &JsiSkImageFilterFactory::MakeSpotLitSpecular);
362
+ installMethod(runtime, prototype, "MakeBlur",
363
+ &JsiSkImageFilterFactory::MakeBlur);
364
+ installMethod(runtime, prototype, "MakeOffset",
365
+ &JsiSkImageFilterFactory::MakeOffset);
366
+ installMethod(runtime, prototype, "MakeColorFilter",
367
+ &JsiSkImageFilterFactory::MakeColorFilter);
368
+ installMethod(runtime, prototype, "MakeShader",
369
+ &JsiSkImageFilterFactory::MakeShader);
370
+ installMethod(runtime, prototype, "MakeDisplacementMap",
371
+ &JsiSkImageFilterFactory::MakeDisplacementMap);
372
+ installMethod(runtime, prototype, "MakeCompose",
373
+ &JsiSkImageFilterFactory::MakeCompose);
374
+ installMethod(runtime, prototype, "MakeErode",
375
+ &JsiSkImageFilterFactory::MakeErode);
376
+ installMethod(runtime, prototype, "MakeDilate",
377
+ &JsiSkImageFilterFactory::MakeDilate);
378
+ installMethod(runtime, prototype, "MakeBlend",
379
+ &JsiSkImageFilterFactory::MakeBlend);
380
+ installMethod(runtime, prototype, "MakeDropShadow",
381
+ &JsiSkImageFilterFactory::MakeDropShadow);
382
+ installMethod(runtime, prototype, "MakeDropShadowOnly",
383
+ &JsiSkImageFilterFactory::MakeDropShadowOnly);
384
+ installMethod(runtime, prototype, "MakeRuntimeShader",
385
+ &JsiSkImageFilterFactory::MakeRuntimeShader);
386
+ installMethod(runtime, prototype, "MakeArithmetic",
387
+ &JsiSkImageFilterFactory::MakeArithmetic);
388
+ installMethod(runtime, prototype, "MakeCrop",
389
+ &JsiSkImageFilterFactory::MakeCrop);
390
+ installMethod(runtime, prototype, "MakeEmpty",
391
+ &JsiSkImageFilterFactory::MakeEmpty);
392
+ installMethod(runtime, prototype, "MakeImage",
393
+ &JsiSkImageFilterFactory::MakeImage);
394
+ installMethod(runtime, prototype, "MakeMagnifier",
395
+ &JsiSkImageFilterFactory::MakeMagnifier);
396
+ installMethod(runtime, prototype, "MakeMatrixConvolution",
397
+ &JsiSkImageFilterFactory::MakeMatrixConvolution);
398
+ installMethod(runtime, prototype, "MakeMatrixTransform",
399
+ &JsiSkImageFilterFactory::MakeMatrixTransform);
400
+ installMethod(runtime, prototype, "MakeMerge",
401
+ &JsiSkImageFilterFactory::MakeMerge);
402
+ installMethod(runtime, prototype, "MakePicture",
403
+ &JsiSkImageFilterFactory::MakePicture);
404
+ installMethod(runtime, prototype, "MakeRuntimeShaderWithChildren",
405
+ &JsiSkImageFilterFactory::MakeRuntimeShaderWithChildren);
406
+ installMethod(runtime, prototype, "MakeTile",
407
+ &JsiSkImageFilterFactory::MakeTile);
408
+ installMethod(runtime, prototype, "MakeDistantLitDiffuse",
409
+ &JsiSkImageFilterFactory::MakeDistantLitDiffuse);
410
+ installMethod(runtime, prototype, "MakePointLitDiffuse",
411
+ &JsiSkImageFilterFactory::MakePointLitDiffuse);
412
+ installMethod(runtime, prototype, "MakeSpotLitDiffuse",
413
+ &JsiSkImageFilterFactory::MakeSpotLitDiffuse);
414
+ installMethod(runtime, prototype, "MakeDistantLitSpecular",
415
+ &JsiSkImageFilterFactory::MakeDistantLitSpecular);
416
+ installMethod(runtime, prototype, "MakePointLitSpecular",
417
+ &JsiSkImageFilterFactory::MakePointLitSpecular);
418
+ installMethod(runtime, prototype, "MakeSpotLitSpecular",
419
+ &JsiSkImageFilterFactory::MakeSpotLitSpecular);
694
420
  }
695
421
 
696
422
  size_t getMemoryPressure() override { return 2048; }
697
423
 
698
424
  explicit JsiSkImageFilterFactory(std::shared_ptr<RNSkPlatformContext> context)
699
425
  : JsiSkNativeObject<JsiSkImageFilterFactory>(std::move(context)) {}
426
+
427
+ private:
428
+ static sk_sp<SkImageFilter> orNull(JsiOptional<sk_sp<SkImageFilter>> filter) {
429
+ return filter.has_value() ? std::move(*filter) : nullptr;
430
+ }
431
+
432
+ static SkImageFilters::CropRect toCropRect(const JsiOptional<SkRect> &rect) {
433
+ return rect.has_value() ? SkImageFilters::CropRect(*rect)
434
+ : SkImageFilters::CropRect{};
435
+ }
436
+
437
+ static SkFilterMode toFilterMode(const JsiOptional<double> &mode) {
438
+ return mode.has_value() ? static_cast<SkFilterMode>(*mode)
439
+ : SkFilterMode::kNearest;
440
+ }
441
+
442
+ static SkMipmapMode toMipmapMode(const JsiOptional<double> &mode) {
443
+ return mode.has_value() ? static_cast<SkMipmapMode>(*mode)
444
+ : SkMipmapMode::kNone;
445
+ }
700
446
  };
701
447
 
702
448
  } // namespace RNSkia