@shopify/react-native-skia 2.9.1 → 2.10.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (387) hide show
  1. package/android/CMakeLists.txt +8 -46
  2. package/android/build.gradle +33 -0
  3. package/android/src/main/java/com/shopify/reactnative/skia/RNSkiaPackage.java +1 -2
  4. package/cpp/api/JsiNativeBuffer.h +23 -24
  5. package/cpp/api/JsiSkAnimatedImage.h +24 -25
  6. package/cpp/api/JsiSkAnimatedImageFactory.h +18 -17
  7. package/cpp/api/JsiSkApi.h +254 -96
  8. package/cpp/api/JsiSkCanvas.h +141 -266
  9. package/cpp/api/JsiSkColor.h +7 -5
  10. package/cpp/api/JsiSkColorFilter.h +15 -8
  11. package/cpp/api/JsiSkColorFilterFactory.h +49 -67
  12. package/cpp/api/JsiSkContourMeasure.h +31 -38
  13. package/cpp/api/JsiSkContourMeasureIter.h +20 -23
  14. package/cpp/api/JsiSkConverters.h +410 -0
  15. package/cpp/api/JsiSkData.h +13 -7
  16. package/cpp/api/JsiSkDataFactory.h +27 -32
  17. package/cpp/api/JsiSkFont.h +123 -192
  18. package/cpp/api/JsiSkFontMgr.h +33 -26
  19. package/cpp/api/JsiSkFontMgrFactory.h +12 -11
  20. package/cpp/api/JsiSkFontStyle.h +14 -12
  21. package/cpp/api/JsiSkImage.h +90 -79
  22. package/cpp/api/JsiSkImageFactory.h +93 -95
  23. package/cpp/api/JsiSkImageFilter.h +21 -11
  24. package/cpp/api/JsiSkImageFilterFactory.h +375 -629
  25. package/cpp/api/JsiSkImageInfo.h +25 -25
  26. package/cpp/api/JsiSkMaskFilter.h +21 -11
  27. package/cpp/api/JsiSkMaskFilterFactory.h +17 -17
  28. package/cpp/api/JsiSkMatrix.h +51 -88
  29. package/cpp/api/JsiSkNativeObjects.h +387 -0
  30. package/cpp/api/JsiSkPaint.h +104 -142
  31. package/cpp/api/JsiSkParagraph.h +54 -64
  32. package/cpp/api/JsiSkParagraphBuilder.h +43 -68
  33. package/cpp/api/JsiSkParagraphBuilderFactory.h +20 -24
  34. package/cpp/api/JsiSkPath.h +242 -350
  35. package/cpp/api/JsiSkPathBuilder.h +153 -273
  36. package/cpp/api/JsiSkPathBuilderFactory.h +19 -20
  37. package/cpp/api/JsiSkPathEffect.h +21 -11
  38. package/cpp/api/JsiSkPathEffectFactory.h +61 -80
  39. package/cpp/api/JsiSkPathFactory.h +148 -238
  40. package/cpp/api/JsiSkPicture.h +32 -27
  41. package/cpp/api/JsiSkPictureFactory.h +21 -26
  42. package/cpp/api/JsiSkPictureRecorder.h +27 -29
  43. package/cpp/api/JsiSkPoint.h +20 -23
  44. package/cpp/api/JsiSkRRect.h +24 -32
  45. package/cpp/api/JsiSkRSXform.h +31 -48
  46. package/cpp/api/JsiSkRect.h +40 -50
  47. package/cpp/api/JsiSkRuntimeEffect.h +85 -92
  48. package/cpp/api/JsiSkRuntimeEffectFactory.h +14 -18
  49. package/cpp/api/JsiSkRuntimeShaderBuilder.h +28 -30
  50. package/cpp/api/JsiSkSVG.h +15 -15
  51. package/cpp/api/JsiSkSVGFactory.h +17 -20
  52. package/cpp/api/JsiSkShader.h +15 -8
  53. package/cpp/api/JsiSkShaderFactory.h +159 -238
  54. package/cpp/api/JsiSkSkottie.h +131 -143
  55. package/cpp/api/JsiSkSurface.h +29 -32
  56. package/cpp/api/JsiSkSurfaceFactory.h +18 -20
  57. package/cpp/api/JsiSkTextBlob.h +15 -8
  58. package/cpp/api/JsiSkTextBlobFactory.h +40 -66
  59. package/cpp/api/JsiSkTypeface.h +25 -22
  60. package/cpp/api/JsiSkTypefaceFactory.h +17 -15
  61. package/cpp/api/JsiSkTypefaceFontProvider.h +43 -39
  62. package/cpp/api/JsiSkTypefaceFontProviderFactory.h +13 -12
  63. package/cpp/api/JsiSkVertices.h +23 -22
  64. package/cpp/api/JsiSkiaContext.h +22 -23
  65. package/cpp/api/JsiSkottieFactory.h +16 -17
  66. package/cpp/api/JsiVideo.h +43 -81
  67. package/cpp/api/recorder/Convertor.h +31 -61
  68. package/cpp/api/recorder/DataTypes.h +8 -16
  69. package/cpp/api/recorder/JsiRecorder.h +83 -55
  70. package/cpp/api/recorder/RNRecorder.h +1 -1
  71. package/cpp/jsi/BoxedNativeObject.h +146 -0
  72. package/cpp/{jsi2 → jsi}/EnumMapper.h +4 -1
  73. package/cpp/{jsi2 → jsi}/JSIConverter.h +0 -31
  74. package/cpp/{jsi2 → jsi}/NativeObject.h +131 -152
  75. package/cpp/jsi/RuntimeAwareCache.cpp +1 -1
  76. package/cpp/jsi/RuntimeAwareCache.h +26 -8
  77. package/cpp/jsi/ViewProperty.h +5 -11
  78. package/cpp/rnskia/RNDawnContext.h +18 -2
  79. package/cpp/rnskia/RNDawnInterop.cpp +19 -0
  80. package/cpp/rnskia/RNDawnUtils.h +18 -1
  81. package/cpp/rnskia/RNSkJsiViewApi.h +20 -11
  82. package/cpp/rnskia/RNSkManager.cpp +9 -168
  83. package/cpp/rnskia/RNSkPictureView.h +1 -1
  84. package/cpp/skia/include/gpu/ganesh/GrDriverBugWorkaroundsAutogen.h +2 -0
  85. package/lib/commonjs/external/reanimated/renderHelpers.d.ts +15 -0
  86. package/lib/commonjs/external/reanimated/renderHelpers.js +30 -1
  87. package/lib/commonjs/external/reanimated/renderHelpers.js.map +1 -1
  88. package/lib/commonjs/mock/index.js +0 -1
  89. package/lib/commonjs/mock/index.js.map +1 -1
  90. package/lib/commonjs/skia/NativeSetup.js +4 -0
  91. package/lib/commonjs/skia/NativeSetup.js.map +1 -1
  92. package/lib/commonjs/skia/SkiaWorkletSerialization.d.ts +1 -0
  93. package/lib/commonjs/skia/SkiaWorkletSerialization.js +66 -0
  94. package/lib/commonjs/skia/SkiaWorkletSerialization.js.map +1 -0
  95. package/lib/commonjs/skia/types/Image/ImageFactory.d.ts +15 -6
  96. package/lib/commonjs/skia/types/Image/ImageFactory.js.map +1 -1
  97. package/lib/commonjs/skia/types/Skia.d.ts +5 -15
  98. package/lib/commonjs/skia/types/Skia.js.map +1 -1
  99. package/lib/commonjs/skia/types/index.d.ts +0 -1
  100. package/lib/commonjs/skia/types/index.js +0 -11
  101. package/lib/commonjs/skia/types/index.js.map +1 -1
  102. package/lib/commonjs/skia/web/JsiSkImageFactory.d.ts +2 -2
  103. package/lib/commonjs/skia/web/JsiSkImageFactory.js +2 -2
  104. package/lib/commonjs/skia/web/JsiSkImageFactory.js.map +1 -1
  105. package/lib/commonjs/skia/web/JsiSkia.js +1 -4
  106. package/lib/commonjs/skia/web/JsiSkia.js.map +1 -1
  107. package/lib/commonjs/sksg/Container.native.js +20 -1
  108. package/lib/commonjs/sksg/Container.native.js.map +1 -1
  109. package/lib/commonjs/views/index.d.ts +0 -1
  110. package/lib/commonjs/views/index.js +0 -11
  111. package/lib/commonjs/views/index.js.map +1 -1
  112. package/lib/module/external/reanimated/renderHelpers.d.ts +15 -0
  113. package/lib/module/external/reanimated/renderHelpers.js +29 -0
  114. package/lib/module/external/reanimated/renderHelpers.js.map +1 -1
  115. package/lib/module/mock/index.js +0 -1
  116. package/lib/module/mock/index.js.map +1 -1
  117. package/lib/module/skia/NativeSetup.js +4 -0
  118. package/lib/module/skia/NativeSetup.js.map +1 -1
  119. package/lib/module/skia/SkiaWorkletSerialization.d.ts +1 -0
  120. package/lib/module/skia/SkiaWorkletSerialization.js +59 -0
  121. package/lib/module/skia/SkiaWorkletSerialization.js.map +1 -0
  122. package/lib/module/skia/types/Image/ImageFactory.d.ts +15 -6
  123. package/lib/module/skia/types/Image/ImageFactory.js.map +1 -1
  124. package/lib/module/skia/types/Skia.d.ts +5 -15
  125. package/lib/module/skia/types/Skia.js.map +1 -1
  126. package/lib/module/skia/types/index.d.ts +0 -1
  127. package/lib/module/skia/types/index.js +0 -1
  128. package/lib/module/skia/types/index.js.map +1 -1
  129. package/lib/module/skia/web/JsiSkImageFactory.d.ts +2 -2
  130. package/lib/module/skia/web/JsiSkImageFactory.js +2 -2
  131. package/lib/module/skia/web/JsiSkImageFactory.js.map +1 -1
  132. package/lib/module/skia/web/JsiSkia.js +1 -4
  133. package/lib/module/skia/web/JsiSkia.js.map +1 -1
  134. package/lib/module/sksg/Container.native.js +21 -2
  135. package/lib/module/sksg/Container.native.js.map +1 -1
  136. package/lib/module/views/index.d.ts +0 -1
  137. package/lib/module/views/index.js +0 -1
  138. package/lib/module/views/index.js.map +1 -1
  139. package/lib/typescript/lib/commonjs/external/reanimated/renderHelpers.d.ts +2 -0
  140. package/lib/typescript/lib/commonjs/mock/index.d.ts +0 -1
  141. package/lib/typescript/lib/commonjs/skia/SkiaWorkletSerialization.d.ts +2 -0
  142. package/lib/typescript/lib/commonjs/skia/web/JsiSkImageFactory.d.ts +2 -2
  143. package/lib/typescript/lib/commonjs/skia/web/JsiSkia.d.ts +1 -2
  144. package/lib/typescript/lib/module/external/reanimated/renderHelpers.d.ts +15 -0
  145. package/lib/typescript/lib/module/mock/index.d.ts +0 -2
  146. package/lib/typescript/lib/module/skia/Skia.web.d.ts +1 -2
  147. package/lib/typescript/lib/module/skia/SkiaWorkletSerialization.d.ts +1 -0
  148. package/lib/typescript/lib/module/skia/types/index.d.ts +0 -1
  149. package/lib/typescript/lib/module/skia/web/JsiSkImageFactory.d.ts +2 -2
  150. package/lib/typescript/lib/module/skia/web/JsiSkia.d.ts +1 -2
  151. package/lib/typescript/lib/module/views/index.d.ts +0 -1
  152. package/lib/typescript/src/external/reanimated/renderHelpers.d.ts +15 -0
  153. package/lib/typescript/src/skia/SkiaWorkletSerialization.d.ts +1 -0
  154. package/lib/typescript/src/skia/types/Image/ImageFactory.d.ts +15 -6
  155. package/lib/typescript/src/skia/types/Skia.d.ts +5 -15
  156. package/lib/typescript/src/skia/types/index.d.ts +0 -1
  157. package/lib/typescript/src/skia/web/JsiSkImageFactory.d.ts +2 -2
  158. package/lib/typescript/src/views/index.d.ts +0 -1
  159. package/package.json +8 -5
  160. package/react-native-skia.podspec +38 -5
  161. package/src/external/reanimated/renderHelpers.ts +30 -0
  162. package/src/mock/index.ts +0 -1
  163. package/src/skia/NativeSetup.ts +5 -0
  164. package/src/skia/SkiaWorkletSerialization.ts +67 -0
  165. package/src/skia/types/Image/ImageFactory.ts +15 -6
  166. package/src/skia/types/Skia.ts +5 -15
  167. package/src/skia/types/index.ts +0 -1
  168. package/src/skia/web/JsiSkImageFactory.ts +3 -3
  169. package/src/skia/web/JsiSkia.ts +2 -5
  170. package/src/sksg/Container.native.ts +40 -2
  171. package/src/views/index.ts +0 -1
  172. package/android/cpp/jni/JniWebGPUView.cpp +0 -112
  173. package/android/cpp/rnskia-android/SkiaPlatformContext.h +0 -26
  174. package/android/src/main/java/com/shopify/reactnative/skia/WebGPUSurfaceView.java +0 -43
  175. package/android/src/main/java/com/shopify/reactnative/skia/WebGPUTextureView.java +0 -50
  176. package/android/src/main/java/com/shopify/reactnative/skia/WebGPUView.java +0 -98
  177. package/android/src/main/java/com/shopify/reactnative/skia/WebGPUViewAPI.java +0 -19
  178. package/android/src/main/java/com/shopify/reactnative/skia/WebGPUViewManager.java +0 -58
  179. package/apple/RNWebGPUAppleNativeBuffer.mm +0 -33
  180. package/apple/SkiaPlatformContext.h +0 -20
  181. package/apple/SkiaPlatformContext.mm +0 -21
  182. package/apple/SkiaWebGPUView.mm +0 -81
  183. package/apple/WebGPUMetalView.mm +0 -136
  184. package/cpp/api/JsiSkHostObjects.h +0 -257
  185. package/cpp/jsi/JsiHostObject.cpp +0 -137
  186. package/cpp/jsi/JsiHostObject.h +0 -385
  187. package/cpp/rnwgpu/ArrayBuffer.h +0 -117
  188. package/cpp/rnwgpu/Canvas.h +0 -50
  189. package/cpp/rnwgpu/PlatformContext.h +0 -18
  190. package/cpp/rnwgpu/SurfaceRegistry.h +0 -605
  191. package/cpp/rnwgpu/api/AppleNativeBuffer.h +0 -22
  192. package/cpp/rnwgpu/api/Convertors.h +0 -783
  193. package/cpp/rnwgpu/api/External.h +0 -12
  194. package/cpp/rnwgpu/api/GPU.cpp +0 -162
  195. package/cpp/rnwgpu/api/GPU.h +0 -60
  196. package/cpp/rnwgpu/api/GPUAdapter.cpp +0 -240
  197. package/cpp/rnwgpu/api/GPUAdapter.h +0 -60
  198. package/cpp/rnwgpu/api/GPUAdapterInfo.h +0 -57
  199. package/cpp/rnwgpu/api/GPUBindGroup.cpp +0 -3
  200. package/cpp/rnwgpu/api/GPUBindGroup.h +0 -51
  201. package/cpp/rnwgpu/api/GPUBindGroupLayout.h +0 -52
  202. package/cpp/rnwgpu/api/GPUBuffer.cpp +0 -107
  203. package/cpp/rnwgpu/api/GPUBuffer.h +0 -88
  204. package/cpp/rnwgpu/api/GPUCanvasContext.cpp +0 -75
  205. package/cpp/rnwgpu/api/GPUCanvasContext.h +0 -70
  206. package/cpp/rnwgpu/api/GPUCommandBuffer.h +0 -45
  207. package/cpp/rnwgpu/api/GPUCommandEncoder.cpp +0 -179
  208. package/cpp/rnwgpu/api/GPUCommandEncoder.h +0 -111
  209. package/cpp/rnwgpu/api/GPUCompilationInfo.h +0 -79
  210. package/cpp/rnwgpu/api/GPUCompilationMessage.h +0 -36
  211. package/cpp/rnwgpu/api/GPUComputePassEncoder.cpp +0 -60
  212. package/cpp/rnwgpu/api/GPUComputePassEncoder.h +0 -85
  213. package/cpp/rnwgpu/api/GPUComputePipeline.cpp +0 -12
  214. package/cpp/rnwgpu/api/GPUComputePipeline.h +0 -60
  215. package/cpp/rnwgpu/api/GPUDevice.cpp +0 -614
  216. package/cpp/rnwgpu/api/GPUDevice.h +0 -258
  217. package/cpp/rnwgpu/api/GPUDeviceLostInfo.cpp +0 -7
  218. package/cpp/rnwgpu/api/GPUDeviceLostInfo.h +0 -40
  219. package/cpp/rnwgpu/api/GPUError.h +0 -35
  220. package/cpp/rnwgpu/api/GPUExtent3D.h +0 -66
  221. package/cpp/rnwgpu/api/GPUExternalTexture.cpp +0 -139
  222. package/cpp/rnwgpu/api/GPUExternalTexture.h +0 -95
  223. package/cpp/rnwgpu/api/GPUFeatures.h +0 -203
  224. package/cpp/rnwgpu/api/GPUInternalError.h +0 -31
  225. package/cpp/rnwgpu/api/GPUOrigin2D.h +0 -55
  226. package/cpp/rnwgpu/api/GPUOrigin3D.h +0 -62
  227. package/cpp/rnwgpu/api/GPUOutOfMemoryError.h +0 -33
  228. package/cpp/rnwgpu/api/GPUPipelineLayout.h +0 -45
  229. package/cpp/rnwgpu/api/GPUQuerySet.cpp +0 -11
  230. package/cpp/rnwgpu/api/GPUQuerySet.h +0 -73
  231. package/cpp/rnwgpu/api/GPUQueue.cpp +0 -179
  232. package/cpp/rnwgpu/api/GPUQueue.h +0 -84
  233. package/cpp/rnwgpu/api/GPURenderBundle.h +0 -44
  234. package/cpp/rnwgpu/api/GPURenderBundleEncoder.cpp +0 -131
  235. package/cpp/rnwgpu/api/GPURenderBundleEncoder.h +0 -110
  236. package/cpp/rnwgpu/api/GPURenderPassEncoder.cpp +0 -165
  237. package/cpp/rnwgpu/api/GPURenderPassEncoder.h +0 -130
  238. package/cpp/rnwgpu/api/GPURenderPipeline.cpp +0 -13
  239. package/cpp/rnwgpu/api/GPURenderPipeline.h +0 -61
  240. package/cpp/rnwgpu/api/GPUSampler.h +0 -44
  241. package/cpp/rnwgpu/api/GPUShaderModule.cpp +0 -56
  242. package/cpp/rnwgpu/api/GPUShaderModule.h +0 -66
  243. package/cpp/rnwgpu/api/GPUSharedFence.cpp +0 -80
  244. package/cpp/rnwgpu/api/GPUSharedFence.h +0 -53
  245. package/cpp/rnwgpu/api/GPUSharedTextureMemory.cpp +0 -135
  246. package/cpp/rnwgpu/api/GPUSharedTextureMemory.h +0 -75
  247. package/cpp/rnwgpu/api/GPUSupportedLimits.cpp +0 -129
  248. package/cpp/rnwgpu/api/GPUSupportedLimits.h +0 -131
  249. package/cpp/rnwgpu/api/GPUTexture.cpp +0 -47
  250. package/cpp/rnwgpu/api/GPUTexture.h +0 -162
  251. package/cpp/rnwgpu/api/GPUTextureView.h +0 -44
  252. package/cpp/rnwgpu/api/GPUUncapturedErrorEvent.h +0 -60
  253. package/cpp/rnwgpu/api/GPUValidationError.h +0 -32
  254. package/cpp/rnwgpu/api/ImageBitmap.h +0 -62
  255. package/cpp/rnwgpu/api/NativeBufferUtils.h +0 -87
  256. package/cpp/rnwgpu/api/RNWebGPU.h +0 -82
  257. package/cpp/rnwgpu/api/WebGPUConstants.h +0 -36
  258. package/cpp/rnwgpu/api/descriptors/GPUBindGroupDescriptor.h +0 -64
  259. package/cpp/rnwgpu/api/descriptors/GPUBindGroupEntry.h +0 -78
  260. package/cpp/rnwgpu/api/descriptors/GPUBindGroupLayoutDescriptor.h +0 -56
  261. package/cpp/rnwgpu/api/descriptors/GPUBindGroupLayoutEntry.h +0 -97
  262. package/cpp/rnwgpu/api/descriptors/GPUBlendComponent.h +0 -57
  263. package/cpp/rnwgpu/api/descriptors/GPUBlendState.h +0 -52
  264. package/cpp/rnwgpu/api/descriptors/GPUBufferBinding.h +0 -56
  265. package/cpp/rnwgpu/api/descriptors/GPUBufferBindingLayout.h +0 -56
  266. package/cpp/rnwgpu/api/descriptors/GPUBufferDescriptor.h +0 -59
  267. package/cpp/rnwgpu/api/descriptors/GPUBufferUsage.h +0 -39
  268. package/cpp/rnwgpu/api/descriptors/GPUCanvasConfiguration.h +0 -76
  269. package/cpp/rnwgpu/api/descriptors/GPUColor.h +0 -66
  270. package/cpp/rnwgpu/api/descriptors/GPUColorTargetState.h +0 -58
  271. package/cpp/rnwgpu/api/descriptors/GPUColorWrite.h +0 -29
  272. package/cpp/rnwgpu/api/descriptors/GPUCommandBufferDescriptor.h +0 -45
  273. package/cpp/rnwgpu/api/descriptors/GPUCommandEncoderDescriptor.h +0 -45
  274. package/cpp/rnwgpu/api/descriptors/GPUComputePassDescriptor.h +0 -56
  275. package/cpp/rnwgpu/api/descriptors/GPUComputePassTimestampWrites.h +0 -58
  276. package/cpp/rnwgpu/api/descriptors/GPUComputePipelineDescriptor.h +0 -67
  277. package/cpp/rnwgpu/api/descriptors/GPUDawnTogglesDescriptor.h +0 -56
  278. package/cpp/rnwgpu/api/descriptors/GPUDepthStencilState.h +0 -103
  279. package/cpp/rnwgpu/api/descriptors/GPUDeviceDescriptor.h +0 -109
  280. package/cpp/rnwgpu/api/descriptors/GPUExternalTextureBindingLayout.h +0 -38
  281. package/cpp/rnwgpu/api/descriptors/GPUExternalTextureDescriptor.h +0 -90
  282. package/cpp/rnwgpu/api/descriptors/GPUFragmentState.h +0 -73
  283. package/cpp/rnwgpu/api/descriptors/GPUImageCopyBuffer.h +0 -62
  284. package/cpp/rnwgpu/api/descriptors/GPUImageCopyExternalImage.h +0 -63
  285. package/cpp/rnwgpu/api/descriptors/GPUImageCopyTexture.h +0 -65
  286. package/cpp/rnwgpu/api/descriptors/GPUImageCopyTextureTagged.h +0 -81
  287. package/cpp/rnwgpu/api/descriptors/GPUImageDataLayout.h +0 -54
  288. package/cpp/rnwgpu/api/descriptors/GPUMapMode.h +0 -22
  289. package/cpp/rnwgpu/api/descriptors/GPUMultisampleState.h +0 -54
  290. package/cpp/rnwgpu/api/descriptors/GPUPipelineLayoutDescriptor.h +0 -57
  291. package/cpp/rnwgpu/api/descriptors/GPUPrimitiveState.h +0 -69
  292. package/cpp/rnwgpu/api/descriptors/GPUProgrammableStage.h +0 -61
  293. package/cpp/rnwgpu/api/descriptors/GPUQuerySetDescriptor.h +0 -55
  294. package/cpp/rnwgpu/api/descriptors/GPUQueueDescriptor.h +0 -43
  295. package/cpp/rnwgpu/api/descriptors/GPURenderBundleDescriptor.h +0 -45
  296. package/cpp/rnwgpu/api/descriptors/GPURenderBundleEncoderDescriptor.h +0 -80
  297. package/cpp/rnwgpu/api/descriptors/GPURenderPassColorAttachment.h +0 -81
  298. package/cpp/rnwgpu/api/descriptors/GPURenderPassDepthStencilAttachment.h +0 -101
  299. package/cpp/rnwgpu/api/descriptors/GPURenderPassDescriptor.h +0 -92
  300. package/cpp/rnwgpu/api/descriptors/GPURenderPassTimestampWrites.h +0 -58
  301. package/cpp/rnwgpu/api/descriptors/GPURenderPipelineDescriptor.h +0 -103
  302. package/cpp/rnwgpu/api/descriptors/GPURequestAdapterOptions.h +0 -51
  303. package/cpp/rnwgpu/api/descriptors/GPUSamplerBindingLayout.h +0 -45
  304. package/cpp/rnwgpu/api/descriptors/GPUSamplerDescriptor.h +0 -110
  305. package/cpp/rnwgpu/api/descriptors/GPUShaderModuleCompilationHint.h +0 -60
  306. package/cpp/rnwgpu/api/descriptors/GPUShaderModuleDescriptor.h +0 -62
  307. package/cpp/rnwgpu/api/descriptors/GPUShaderStage.h +0 -25
  308. package/cpp/rnwgpu/api/descriptors/GPUSharedFenceDescriptor.h +0 -58
  309. package/cpp/rnwgpu/api/descriptors/GPUSharedFenceState.h +0 -51
  310. package/cpp/rnwgpu/api/descriptors/GPUSharedTextureMemoryDescriptor.h +0 -73
  311. package/cpp/rnwgpu/api/descriptors/GPUStencilFaceState.h +0 -64
  312. package/cpp/rnwgpu/api/descriptors/GPUStorageTextureBindingLayout.h +0 -59
  313. package/cpp/rnwgpu/api/descriptors/GPUTextureBindingLayout.h +0 -59
  314. package/cpp/rnwgpu/api/descriptors/GPUTextureDescriptor.h +0 -91
  315. package/cpp/rnwgpu/api/descriptors/GPUTextureUsage.h +0 -29
  316. package/cpp/rnwgpu/api/descriptors/GPUTextureViewDescriptor.h +0 -91
  317. package/cpp/rnwgpu/api/descriptors/GPUUncapturedErrorEventInit.h +0 -64
  318. package/cpp/rnwgpu/api/descriptors/GPUVertexAttribute.h +0 -53
  319. package/cpp/rnwgpu/api/descriptors/GPUVertexBufferLayout.h +0 -62
  320. package/cpp/rnwgpu/api/descriptors/GPUVertexState.h +0 -73
  321. package/cpp/rnwgpu/api/descriptors/Unions.h +0 -1969
  322. package/cpp/rnwgpu/async/AsyncTaskHandle.cpp +0 -214
  323. package/cpp/rnwgpu/async/AsyncTaskHandle.h +0 -58
  324. package/cpp/rnwgpu/async/RuntimeContext.cpp +0 -199
  325. package/cpp/rnwgpu/async/RuntimeContext.h +0 -134
  326. package/lib/commonjs/skia/types/WebGPU.d.ts +0 -184
  327. package/lib/commonjs/skia/types/WebGPU.js +0 -105
  328. package/lib/commonjs/skia/types/WebGPU.js.map +0 -1
  329. package/lib/commonjs/specs/WebGPUViewNativeComponent.d.ts +0 -8
  330. package/lib/commonjs/specs/WebGPUViewNativeComponent.js +0 -10
  331. package/lib/commonjs/specs/WebGPUViewNativeComponent.js.map +0 -1
  332. package/lib/commonjs/specs/WebGPUViewNativeComponent.web.d.ts +0 -8
  333. package/lib/commonjs/specs/WebGPUViewNativeComponent.web.js +0 -103
  334. package/lib/commonjs/specs/WebGPUViewNativeComponent.web.js.map +0 -1
  335. package/lib/commonjs/specs/utils.d.ts +0 -1
  336. package/lib/commonjs/specs/utils.js +0 -11
  337. package/lib/commonjs/specs/utils.js.map +0 -1
  338. package/lib/commonjs/views/WebGPUCanvas.d.ts +0 -33
  339. package/lib/commonjs/views/WebGPUCanvas.js +0 -79
  340. package/lib/commonjs/views/WebGPUCanvas.js.map +0 -1
  341. package/lib/commonjs/views/WebGPUCanvas.web.d.ts +0 -23
  342. package/lib/commonjs/views/WebGPUCanvas.web.js +0 -20
  343. package/lib/commonjs/views/WebGPUCanvas.web.js.map +0 -1
  344. package/lib/module/skia/types/WebGPU.d.ts +0 -184
  345. package/lib/module/skia/types/WebGPU.js +0 -99
  346. package/lib/module/skia/types/WebGPU.js.map +0 -1
  347. package/lib/module/specs/WebGPUViewNativeComponent.d.ts +0 -8
  348. package/lib/module/specs/WebGPUViewNativeComponent.js +0 -4
  349. package/lib/module/specs/WebGPUViewNativeComponent.js.map +0 -1
  350. package/lib/module/specs/WebGPUViewNativeComponent.web.d.ts +0 -8
  351. package/lib/module/specs/WebGPUViewNativeComponent.web.js +0 -96
  352. package/lib/module/specs/WebGPUViewNativeComponent.web.js.map +0 -1
  353. package/lib/module/specs/utils.d.ts +0 -1
  354. package/lib/module/specs/utils.js +0 -5
  355. package/lib/module/specs/utils.js.map +0 -1
  356. package/lib/module/views/WebGPUCanvas.d.ts +0 -33
  357. package/lib/module/views/WebGPUCanvas.js +0 -70
  358. package/lib/module/views/WebGPUCanvas.js.map +0 -1
  359. package/lib/module/views/WebGPUCanvas.web.d.ts +0 -23
  360. package/lib/module/views/WebGPUCanvas.web.js +0 -12
  361. package/lib/module/views/WebGPUCanvas.web.js.map +0 -1
  362. package/lib/typescript/lib/commonjs/skia/types/WebGPU.d.ts +0 -2
  363. package/lib/typescript/lib/commonjs/specs/WebGPUViewNativeComponent.d.ts +0 -4
  364. package/lib/typescript/lib/commonjs/specs/WebGPUViewNativeComponent.web.d.ts +0 -3
  365. package/lib/typescript/lib/commonjs/specs/utils.d.ts +0 -2
  366. package/lib/typescript/lib/commonjs/views/WebGPUCanvas.d.ts +0 -6
  367. package/lib/typescript/lib/commonjs/views/WebGPUCanvas.web.d.ts +0 -6
  368. package/lib/typescript/lib/module/skia/types/WebGPU.d.ts +0 -31
  369. package/lib/typescript/lib/module/specs/WebGPUViewNativeComponent.d.ts +0 -2
  370. package/lib/typescript/lib/module/specs/WebGPUViewNativeComponent.web.d.ts +0 -2
  371. package/lib/typescript/lib/module/specs/utils.d.ts +0 -1
  372. package/lib/typescript/lib/module/views/WebGPUCanvas.d.ts +0 -7
  373. package/lib/typescript/lib/module/views/WebGPUCanvas.web.d.ts +0 -8
  374. package/lib/typescript/src/skia/types/WebGPU.d.ts +0 -184
  375. package/lib/typescript/src/specs/WebGPUViewNativeComponent.d.ts +0 -8
  376. package/lib/typescript/src/specs/WebGPUViewNativeComponent.web.d.ts +0 -8
  377. package/lib/typescript/src/specs/utils.d.ts +0 -1
  378. package/lib/typescript/src/views/WebGPUCanvas.d.ts +0 -33
  379. package/lib/typescript/src/views/WebGPUCanvas.web.d.ts +0 -23
  380. package/src/skia/types/WebGPU.ts +0 -226
  381. package/src/specs/WebGPUViewNativeComponent.ts +0 -11
  382. package/src/specs/WebGPUViewNativeComponent.web.ts +0 -110
  383. package/src/specs/utils.ts +0 -4
  384. package/src/views/WebGPUCanvas.tsx +0 -125
  385. package/src/views/WebGPUCanvas.web.tsx +0 -36
  386. /package/cpp/{jsi2 → jsi}/Promise.cpp +0 -0
  387. /package/cpp/{jsi2 → jsi}/Promise.h +0 -0
@@ -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
 
8
- #include "JsiSkHostObjects.h"
11
+ #include "JsiSkColor.h"
12
+ #include "JsiSkColorFilter.h"
13
+ #include "JsiSkConverters.h"
14
+ #include "JsiSkImage.h"
9
15
  #include "JsiSkImageFilter.h"
16
+ #include "JsiSkMatrix.h"
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
- class JsiSkImageFilterFactory : public JsiSkHostObject {
35
+ class JsiSkImageFilterFactory
36
+ : public JsiSkNativeObject<JsiSkImageFilterFactory> {
32
37
  public:
33
- JSI_HOST_FUNCTION(MakeBlur) {
34
- float sigmaX = arguments[0].asNumber();
35
- float sigmaY = arguments[1].asNumber();
36
- int tileMode = arguments[2].asNumber();
37
- sk_sp<SkImageFilter> imageFilter = nullptr;
38
- if (hasOptionalArgument(arguments, count, 3)) {
39
- imageFilter = JsiSkImageFilter::fromValue(runtime, arguments[3]);
40
- }
41
- SkImageFilters::CropRect cropRect = {};
42
- if (hasOptionalArgument(arguments, count, 4)) {
43
- cropRect = *JsiSkRect::fromValue(runtime, arguments[4]);
44
- }
45
- auto filter = std::make_shared<JsiSkImageFilter>(
46
- getContext(), SkImageFilters::Blur(sigmaX, sigmaY, (SkTileMode)tileMode,
47
- imageFilter, cropRect));
48
- return JSI_CREATE_HOST_OBJECT_WITH_MEMORY_PRESSURE(runtime, filter,
49
- getContext());
50
- }
51
-
52
- JSI_HOST_FUNCTION(MakeColorFilter) {
53
- auto cf = JsiSkColorFilter::fromValue(runtime, arguments[0]);
54
- sk_sp<SkImageFilter> input = nullptr;
55
- if (hasOptionalArgument(arguments, count, 1)) {
56
- input = JsiSkImageFilter::fromValue(runtime, arguments[1]);
57
- }
58
- SkImageFilters::CropRect cropRect = {};
59
- if (hasOptionalArgument(arguments, count, 2)) {
60
- cropRect = *JsiSkRect::fromValue(runtime, arguments[2]);
61
- }
62
- auto filter = std::make_shared<JsiSkImageFilter>(
38
+ static constexpr const char *CLASS_NAME = "ImageFilterFactory";
39
+
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>(
63
45
  getContext(),
64
- SkImageFilters::ColorFilter(std::move(cf), std::move(input), cropRect));
65
- return JSI_CREATE_HOST_OBJECT_WITH_MEMORY_PRESSURE(runtime, filter,
66
- getContext());
46
+ SkImageFilters::Blur(sigmaX, sigmaY, static_cast<SkTileMode>(tileMode),
47
+ orNull(std::move(input)), toCropRect(crop)));
67
48
  }
68
49
 
69
- JSI_HOST_FUNCTION(MakeOffset) {
70
- auto x = arguments[0].asNumber();
71
- auto y = arguments[1].asNumber();
72
- sk_sp<SkImageFilter> input = nullptr;
73
- if (hasOptionalArgument(arguments, count, 2)) {
74
- input = JsiSkImageFilter::fromValue(runtime, arguments[2]);
75
- }
76
- SkImageFilters::CropRect cropRect = {};
77
- if (hasOptionalArgument(arguments, count, 3)) {
78
- cropRect = *JsiSkRect::fromValue(runtime, arguments[3]);
79
- }
80
- auto filter = std::make_shared<JsiSkImageFilter>(
81
- getContext(), SkImageFilters::Offset(x, y, std::move(input), cropRect));
82
- return JSI_CREATE_HOST_OBJECT_WITH_MEMORY_PRESSURE(runtime, filter,
83
- getContext());
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 JSI_CREATE_HOST_OBJECT_WITH_MEMORY_PRESSURE(runtime, filter,
106
- getContext());
107
- }
108
-
109
- JSI_HOST_FUNCTION(MakeShader) {
110
- auto shader = JsiSkShader::fromValue(runtime, arguments[0]);
111
- SkImageFilters::Dither dither = SkImageFilters::Dither::kNo;
112
- if (hasOptionalArgument(arguments, count, 1)) {
113
- dither = arguments[1].asBool() ? SkImageFilters::Dither::kYes
114
- : SkImageFilters::Dither::kNo;
115
- }
116
- SkImageFilters::CropRect cropRect = {};
117
- if (hasOptionalArgument(arguments, count, 2)) {
118
- cropRect = *JsiSkRect::fromValue(runtime, arguments[2]);
119
- }
120
- 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>(
121
55
  getContext(),
122
- SkImageFilters::Shader(std::move(shader), dither, cropRect));
123
- return JSI_CREATE_HOST_OBJECT_WITH_MEMORY_PRESSURE(runtime, filter,
124
- getContext());
56
+ SkImageFilters::ColorFilter(std::move(cf), orNull(std::move(input)),
57
+ toCropRect(crop)));
125
58
  }
126
59
 
127
- JSI_HOST_FUNCTION(MakeCompose) {
128
- sk_sp<SkImageFilter> outer = nullptr;
129
- if (hasOptionalArgument(arguments, count, 0)) {
130
- outer = JsiSkImageFilter::fromValue(runtime, arguments[0]);
131
- }
132
- sk_sp<SkImageFilter> inner = nullptr;
133
- if (hasOptionalArgument(arguments, count, 1)) {
134
- inner = JsiSkImageFilter::fromValue(runtime, arguments[1]);
135
- }
136
- auto filter = std::make_shared<JsiSkImageFilter>(
137
- getContext(),
138
- SkImageFilters::Compose(std::move(outer), std::move(inner)));
139
- return JSI_CREATE_HOST_OBJECT_WITH_MEMORY_PRESSURE(runtime, filter,
140
- getContext());
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)));
141
66
  }
142
67
 
143
- JSI_HOST_FUNCTION(MakeBlend) {
144
- auto mode = static_cast<SkBlendMode>(arguments[0].asNumber());
145
- sk_sp<SkImageFilter> background =
146
- JsiSkImageFilter::fromValue(runtime, arguments[1]);
147
- sk_sp<SkImageFilter> foreground = nullptr;
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>(
74
+ getContext(),
75
+ SkImageFilters::DisplacementMap(
76
+ static_cast<SkColorChannel>(xChannelSelector),
77
+ static_cast<SkColorChannel>(yChannelSelector), scale,
78
+ std::move(in2), orNull(std::move(input)), toCropRect(crop)));
79
+ }
148
80
 
149
- if (hasOptionalArgument(arguments, count, 2)) {
150
- foreground = JsiSkImageFilter::fromValue(runtime, arguments[2]);
151
- }
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
+ }
152
91
 
153
- SkImageFilters::CropRect cropRect = {};
154
- if (hasOptionalArgument(arguments, count, 3)) {
155
- cropRect = *JsiSkRect::fromValue(runtime, arguments[3]);
156
- }
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
+ }
157
99
 
158
- auto filter = std::make_shared<JsiSkImageFilter>(
159
- getContext(),
160
- SkImageFilters::Blend(std::move(mode), std::move(background),
161
- std::move(foreground), cropRect));
162
- return JSI_CREATE_HOST_OBJECT_WITH_MEMORY_PRESSURE(runtime, filter,
163
- getContext());
164
- }
165
-
166
- JSI_HOST_FUNCTION(MakeDropShadow) {
167
- auto dx = arguments[0].asNumber();
168
- auto dy = arguments[1].asNumber();
169
- auto sigmaX = arguments[2].asNumber();
170
- auto sigmaY = arguments[3].asNumber();
171
- auto color = JsiSkColor::fromValue(runtime, arguments[4]);
172
- sk_sp<SkImageFilter> input = nullptr;
173
- if (hasOptionalArgument(arguments, count, 5)) {
174
- input = JsiSkImageFilter::fromValue(runtime, arguments[5]);
175
- }
176
- SkImageFilters::CropRect cropRect = {};
177
- if (hasOptionalArgument(arguments, count, 6)) {
178
- cropRect = *JsiSkRect::fromValue(runtime, arguments[6]);
179
- }
180
- auto filter = std::make_shared<JsiSkImageFilter>(
181
- getContext(), SkImageFilters::DropShadow(dx, dy, sigmaX, sigmaY, color,
182
- std::move(input), cropRect));
183
- return JSI_CREATE_HOST_OBJECT_WITH_MEMORY_PRESSURE(runtime, filter,
184
- getContext());
185
- }
186
-
187
- JSI_HOST_FUNCTION(MakeDropShadowOnly) {
188
- auto dx = arguments[0].asNumber();
189
- auto dy = arguments[1].asNumber();
190
- auto sigmaX = arguments[2].asNumber();
191
- auto sigmaY = arguments[3].asNumber();
192
- auto color = JsiSkColor::fromValue(runtime, arguments[4]);
193
- sk_sp<SkImageFilter> input = nullptr;
194
- if (hasOptionalArgument(arguments, count, 5)) {
195
- input = JsiSkImageFilter::fromValue(runtime, arguments[5]);
196
- }
197
- SkImageFilters::CropRect cropRect = {};
198
- if (hasOptionalArgument(arguments, count, 6)) {
199
- cropRect = *JsiSkRect::fromValue(runtime, arguments[6]);
200
- }
201
- auto filter = std::make_shared<JsiSkImageFilter>(
202
- getContext(),
203
- SkImageFilters::DropShadowOnly(dx, dy, sigmaX, sigmaY, color,
204
- std::move(input), cropRect));
205
- return JSI_CREATE_HOST_OBJECT_WITH_MEMORY_PRESSURE(runtime, filter,
206
- getContext());
207
- }
208
-
209
- JSI_HOST_FUNCTION(MakeErode) {
210
- auto rx = arguments[0].asNumber();
211
- auto ry = arguments[1].asNumber();
212
- sk_sp<SkImageFilter> input = nullptr;
213
- if (hasOptionalArgument(arguments, count, 2)) {
214
- input = JsiSkImageFilter::fromValue(runtime, arguments[2]);
215
- }
216
- SkImageFilters::CropRect cropRect = {};
217
- if (hasOptionalArgument(arguments, count, 3)) {
218
- cropRect = *JsiSkRect::fromValue(runtime, arguments[3]);
219
- }
220
- 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>(
221
105
  getContext(),
222
- SkImageFilters::Erode(rx, ry, std::move(input), cropRect));
223
- return JSI_CREATE_HOST_OBJECT_WITH_MEMORY_PRESSURE(runtime, filter,
224
- getContext());
106
+ SkImageFilters::Blend(static_cast<SkBlendMode>(mode),
107
+ std::move(background),
108
+ orNull(std::move(foreground)), toCropRect(crop)));
225
109
  }
226
110
 
227
- JSI_HOST_FUNCTION(MakeDilate) {
228
- auto rx = arguments[0].asNumber();
229
- auto ry = arguments[1].asNumber();
230
- sk_sp<SkImageFilter> input = nullptr;
231
- if (hasOptionalArgument(arguments, count, 2)) {
232
- input = JsiSkImageFilter::fromValue(runtime, arguments[2]);
233
- }
234
- SkImageFilters::CropRect cropRect = {};
235
- if (hasOptionalArgument(arguments, count, 3)) {
236
- cropRect = *JsiSkRect::fromValue(runtime, arguments[3]);
237
- }
238
- 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>(
239
116
  getContext(),
240
- SkImageFilters::Dilate(rx, ry, std::move(input), cropRect));
241
- return JSI_CREATE_HOST_OBJECT_WITH_MEMORY_PRESSURE(runtime, filter,
242
- getContext());
117
+ SkImageFilters::DropShadow(dx, dy, sigmaX, sigmaY, color,
118
+ orNull(std::move(input)), toCropRect(crop)));
243
119
  }
244
120
 
245
- JSI_HOST_FUNCTION(MakeRuntimeShader) {
246
- auto rtb = JsiSkRuntimeShaderBuilder::fromValue(runtime, arguments[0]);
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)));
129
+ }
247
130
 
248
- std::string childNameStr = "";
249
- const char *childName = childNameStr.c_str();
250
- if (hasOptionalArgument(arguments, count, 1)) {
251
- childNameStr = arguments[1].asString(runtime).utf8(runtime);
252
- childName = childNameStr.c_str();
253
- }
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
+ }
254
138
 
255
- sk_sp<SkImageFilter> input = nullptr;
256
- if (hasOptionalArgument(arguments, count, 2)) {
257
- input = JsiSkImageFilter::fromValue(runtime, arguments[2]);
258
- }
259
- auto filter = std::make_shared<JsiSkImageFilter>(
260
- getContext(),
261
- SkImageFilters::RuntimeShader(*rtb, childName, std::move(input)));
262
- return JSI_CREATE_HOST_OBJECT_WITH_MEMORY_PRESSURE(runtime, filter,
263
- getContext());
264
- }
265
-
266
- JSI_HOST_FUNCTION(MakeArithmetic) {
267
- float k1 = arguments[0].asNumber();
268
- float k2 = arguments[1].asNumber();
269
- float k3 = arguments[2].asNumber();
270
- float k4 = arguments[3].asNumber();
271
- bool enforcePMColor = arguments[4].asBool();
272
- sk_sp<SkImageFilter> background = nullptr;
273
- if (hasOptionalArgument(arguments, count, 5)) {
274
- background = JsiSkImageFilter::fromValue(runtime, arguments[5]);
275
- }
276
- sk_sp<SkImageFilter> foreground = nullptr;
277
- if (hasOptionalArgument(arguments, count, 6)) {
278
- foreground = JsiSkImageFilter::fromValue(runtime, arguments[6]);
279
- }
280
- SkImageFilters::CropRect cropRect = {};
281
- if (hasOptionalArgument(arguments, count, 7)) {
282
- cropRect = *JsiSkRect::fromValue(runtime, arguments[7]);
283
- }
284
- auto filter = std::make_shared<JsiSkImageFilter>(
285
- getContext(), SkImageFilters::Arithmetic(
286
- k1, k2, k3, k4, enforcePMColor, std::move(background),
287
- std::move(foreground), cropRect));
288
- return JSI_CREATE_HOST_OBJECT_WITH_MEMORY_PRESSURE(runtime, filter,
289
- getContext());
290
- }
291
-
292
- JSI_HOST_FUNCTION(MakeCrop) {
293
- SkRect rect = *JsiSkRect::fromValue(runtime, arguments[0]);
294
- SkTileMode tileMode = SkTileMode::kDecal;
295
- if (hasOptionalArgument(arguments, count, 1)) {
296
- tileMode = (SkTileMode)arguments[1].asNumber();
297
- }
298
- sk_sp<SkImageFilter> imageFilter = nullptr;
299
- if (hasOptionalArgument(arguments, count, 2)) {
300
- imageFilter = JsiSkImageFilter::fromValue(runtime, arguments[2]);
301
- }
302
- auto filter = std::make_shared<JsiSkImageFilter>(
303
- getContext(),
304
- SkImageFilters::Crop(rect, tileMode, std::move(imageFilter)));
305
- return JSI_CREATE_HOST_OBJECT_WITH_MEMORY_PRESSURE(runtime, filter,
306
- getContext());
307
- }
308
-
309
- JSI_HOST_FUNCTION(MakeEmpty) {
310
- auto filter = std::make_shared<JsiSkImageFilter>(getContext(),
311
- SkImageFilters::Empty());
312
- return JSI_CREATE_HOST_OBJECT_WITH_MEMORY_PRESSURE(runtime, filter,
313
- getContext());
314
- }
315
-
316
- inline SkPoint3 SkPoint3FromValue(jsi::Runtime &runtime,
317
- const jsi::Value &obj) {
318
- const auto &object = obj.asObject(runtime);
319
- auto x = object.getProperty(runtime, "x").asNumber();
320
- auto y = object.getProperty(runtime, "y").asNumber();
321
- auto z = object.getProperty(runtime, "z").asNumber();
322
- return SkPoint3::Make(x, y, z);
323
- }
324
-
325
- JSI_HOST_FUNCTION(MakeDistantLitDiffuse) {
326
- SkPoint3 direction = SkPoint3FromValue(runtime, arguments[0]);
327
- SkColor lightColor = JsiSkColor::fromValue(runtime, arguments[1]);
328
- float surfaceScale = arguments[2].asNumber();
329
- float kd = arguments[3].asNumber();
330
- sk_sp<SkImageFilter> input = nullptr;
331
- if (hasOptionalArgument(arguments, count, 4)) {
332
- input = JsiSkImageFilter::fromValue(runtime, arguments[4]);
333
- }
334
- SkImageFilters::CropRect cropRect = {};
335
- if (hasOptionalArgument(arguments, count, 5)) {
336
- cropRect = *JsiSkRect::fromValue(runtime, arguments[5]);
337
- }
338
- auto filter = std::make_shared<JsiSkImageFilter>(
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
+ }
146
+
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>(
339
153
  getContext(),
340
- SkImageFilters::DistantLitDiffuse(direction, lightColor, surfaceScale,
341
- kd, std::move(input), cropRect));
342
- return JSI_CREATE_HOST_OBJECT_WITH_MEMORY_PRESSURE(runtime, filter,
343
- getContext());
344
- }
345
-
346
- JSI_HOST_FUNCTION(MakePointLitDiffuse) {
347
- SkPoint3 location = SkPoint3FromValue(runtime, arguments[0]);
348
- SkColor lightColor = JsiSkColor::fromValue(runtime, arguments[1]);
349
- float surfaceScale = arguments[2].asNumber();
350
- float kd = arguments[3].asNumber();
351
- sk_sp<SkImageFilter> input = nullptr;
352
- if (hasOptionalArgument(arguments, count, 4)) {
353
- input = JsiSkImageFilter::fromValue(runtime, arguments[4]);
354
- }
355
- SkImageFilters::CropRect cropRect = {};
356
- if (hasOptionalArgument(arguments, count, 5)) {
357
- cropRect = *JsiSkRect::fromValue(runtime, arguments[5]);
358
- }
359
- 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>(
360
164
  getContext(),
361
- SkImageFilters::PointLitDiffuse(location, lightColor, surfaceScale, kd,
362
- std::move(input), cropRect));
363
- return JSI_CREATE_HOST_OBJECT_WITH_MEMORY_PRESSURE(runtime, filter,
364
- getContext());
365
- }
366
-
367
- JSI_HOST_FUNCTION(MakeSpotLitDiffuse) {
368
- SkPoint3 location = SkPoint3FromValue(runtime, arguments[0]);
369
- SkPoint3 target = SkPoint3FromValue(runtime, arguments[1]);
370
- float falloffExponent = arguments[2].asNumber();
371
- float cutoffAngle = arguments[3].asNumber();
372
- SkColor lightColor = JsiSkColor::fromValue(runtime, arguments[4]);
373
- float surfaceScale = arguments[5].asNumber();
374
- float kd = arguments[6].asNumber();
375
- sk_sp<SkImageFilter> input = nullptr;
376
- if (hasOptionalArgument(arguments, count, 7)) {
377
- input = JsiSkImageFilter::fromValue(runtime, arguments[7]);
378
- }
379
- SkImageFilters::CropRect cropRect = {};
380
- if (hasOptionalArgument(arguments, count, 8)) {
381
- cropRect = *JsiSkRect::fromValue(runtime, arguments[8]);
382
- }
383
- auto filter = std::make_shared<JsiSkImageFilter>(
165
+ SkImageFilters::Arithmetic(k1, k2, k3, k4, enforcePMColor,
166
+ orNull(std::move(background)),
167
+ orNull(std::move(foreground)),
168
+ toCropRect(crop)));
169
+ }
170
+
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>(
384
177
  getContext(),
385
- SkImageFilters::SpotLitDiffuse(location, target, falloffExponent,
386
- cutoffAngle, lightColor, surfaceScale,
387
- kd, std::move(input), cropRect));
388
- return JSI_CREATE_HOST_OBJECT_WITH_MEMORY_PRESSURE(runtime, filter,
389
- getContext());
390
- }
391
-
392
- JSI_HOST_FUNCTION(MakeDistantLitSpecular) {
393
- SkPoint3 direction = SkPoint3FromValue(runtime, arguments[0]);
394
- SkColor lightColor = JsiSkColor::fromValue(runtime, arguments[1]);
395
- float surfaceScale = arguments[2].asNumber();
396
- float ks = arguments[3].asNumber();
397
- float shininess = arguments[4].asNumber();
398
- sk_sp<SkImageFilter> input = nullptr;
399
- if (hasOptionalArgument(arguments, count, 5)) {
400
- input = JsiSkImageFilter::fromValue(runtime, arguments[5]);
401
- }
402
- SkImageFilters::CropRect cropRect = {};
403
- if (hasOptionalArgument(arguments, count, 6)) {
404
- cropRect = *JsiSkRect::fromValue(runtime, arguments[6]);
405
- }
406
- auto filter = std::make_shared<JsiSkImageFilter>(
178
+ SkImageFilters::Crop(rect, mode, orNull(std::move(imageFilter))));
179
+ }
180
+
181
+ std::shared_ptr<JsiSkImageFilter> MakeEmpty() {
182
+ return std::make_shared<JsiSkImageFilter>(getContext(),
183
+ SkImageFilters::Empty());
184
+ }
185
+
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>(
407
226
  getContext(), SkImageFilters::DistantLitSpecular(
408
227
  direction, lightColor, surfaceScale, ks, shininess,
409
- std::move(input), cropRect));
410
- return JSI_CREATE_HOST_OBJECT_WITH_MEMORY_PRESSURE(runtime, filter,
411
- getContext());
412
- }
413
-
414
- JSI_HOST_FUNCTION(MakePointLitSpecular) {
415
- SkPoint3 location = SkPoint3FromValue(runtime, arguments[0]);
416
- SkColor lightColor = JsiSkColor::fromValue(runtime, arguments[1]);
417
- float surfaceScale = arguments[2].asNumber();
418
- float ks = arguments[3].asNumber();
419
- float shininess = arguments[4].asNumber();
420
- sk_sp<SkImageFilter> input = nullptr;
421
- if (hasOptionalArgument(arguments, count, 5)) {
422
- input = JsiSkImageFilter::fromValue(runtime, arguments[5]);
423
- }
424
- SkImageFilters::CropRect cropRect = {};
425
- if (hasOptionalArgument(arguments, count, 6)) {
426
- cropRect = *JsiSkRect::fromValue(runtime, arguments[6]);
427
- }
428
- 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>(
429
237
  getContext(), SkImageFilters::PointLitSpecular(
430
238
  location, lightColor, surfaceScale, ks, shininess,
431
- std::move(input), cropRect));
432
- return JSI_CREATE_HOST_OBJECT_WITH_MEMORY_PRESSURE(runtime, filter,
433
- getContext());
434
- }
435
-
436
- JSI_HOST_FUNCTION(MakeSpotLitSpecular) {
437
- SkPoint3 location = SkPoint3FromValue(runtime, arguments[0]);
438
- SkPoint3 target = SkPoint3FromValue(runtime, arguments[1]);
439
- float falloffExponent = arguments[2].asNumber();
440
- float cutoffAngle = arguments[3].asNumber();
441
- SkColor lightColor = JsiSkColor::fromValue(runtime, arguments[4]);
442
- float surfaceScale = arguments[5].asNumber();
443
- float ks = arguments[6].asNumber();
444
- float shininess = arguments[7].asNumber();
445
- sk_sp<SkImageFilter> input = nullptr;
446
- if (hasOptionalArgument(arguments, count, 8)) {
447
- input = JsiSkImageFilter::fromValue(runtime, arguments[8]);
448
- }
449
- SkImageFilters::CropRect cropRect = {};
450
- if (hasOptionalArgument(arguments, count, 9)) {
451
- cropRect = *JsiSkRect::fromValue(runtime, arguments[9]);
452
- }
453
- 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>(
454
249
  getContext(),
455
- SkImageFilters::SpotLitSpecular(
456
- location, target, falloffExponent, cutoffAngle, lightColor,
457
- surfaceScale, ks, shininess, std::move(input), cropRect));
458
- return JSI_CREATE_HOST_OBJECT_WITH_MEMORY_PRESSURE(runtime, filter,
459
- getContext());
460
- }
461
-
462
- JSI_HOST_FUNCTION(MakeImage) {
463
- sk_sp<SkImage> image = JsiSkImage::fromValue(runtime, arguments[0]);
464
- SkRect srcRect;
465
- if (hasOptionalArgument(arguments, count, 1)) {
466
- srcRect = *JsiSkRect::fromValue(runtime, arguments[1]);
467
- } else {
468
- srcRect = SkRect::Make(image->bounds());
469
- }
470
- SkRect dstRect;
471
- if (hasOptionalArgument(arguments, count, 2)) {
472
- dstRect = *JsiSkRect::fromValue(runtime, arguments[2]);
473
- } else {
474
- dstRect = srcRect;
475
- }
476
- SkFilterMode filterMode = SkFilterMode::kNearest;
477
- if (hasOptionalArgument(arguments, count, 3)) {
478
- filterMode = (SkFilterMode)arguments[3].asNumber();
479
- }
480
- SkMipmapMode mipmap = SkMipmapMode::kNone;
481
- if (hasOptionalArgument(arguments, count, 4)) {
482
- mipmap = (SkMipmapMode)arguments[4].asNumber();
483
- }
484
- 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>(
485
265
  getContext(),
486
- SkImageFilters::Image(std::move(image), srcRect, dstRect,
487
- SkSamplingOptions(filterMode, mipmap)));
488
- return JSI_CREATE_HOST_OBJECT_WITH_MEMORY_PRESSURE(runtime, filter,
489
- getContext());
490
- }
491
-
492
- JSI_HOST_FUNCTION(MakeMagnifier) {
493
- SkRect lensBounds = *JsiSkRect::fromValue(runtime, arguments[0]);
494
- float zoomAmount = arguments[1].asNumber();
495
- float inset = arguments[2].asNumber();
496
- SkFilterMode filterMode = SkFilterMode::kNearest;
497
- if (hasOptionalArgument(arguments, count, 3)) {
498
- filterMode = (SkFilterMode)arguments[3].asNumber();
499
- }
500
- SkMipmapMode mipmap = SkMipmapMode::kNone;
501
- if (hasOptionalArgument(arguments, count, 4)) {
502
- mipmap = (SkMipmapMode)arguments[4].asNumber();
503
- }
504
- sk_sp<SkImageFilter> input = nullptr;
505
- if (hasOptionalArgument(arguments, count, 5)) {
506
- input = JsiSkImageFilter::fromValue(runtime, arguments[5]);
507
- }
508
- SkImageFilters::CropRect cropRect = {};
509
- if (hasOptionalArgument(arguments, count, 6)) {
510
- cropRect = *JsiSkRect::fromValue(runtime, arguments[6]);
511
- }
512
- 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>(
513
277
  getContext(),
514
- SkImageFilters::Magnifier(lensBounds, zoomAmount, inset,
515
- SkSamplingOptions(filterMode, mipmap), input,
516
- cropRect));
517
- return JSI_CREATE_HOST_OBJECT_WITH_MEMORY_PRESSURE(runtime, filter,
518
- getContext());
519
- }
520
-
521
- JSI_HOST_FUNCTION(MakeMatrixConvolution) {
522
- SkISize kernelSize =
523
- SkISize::Make(arguments[0].asNumber(), arguments[1].asNumber());
524
- std::vector<float> kernel;
525
- auto kernelArray = arguments[2].asObject(runtime).asArray(runtime);
526
- auto size = kernelArray.size(runtime);
527
- for (size_t i = 0; i < size; i++) {
528
- kernel.push_back(kernelArray.getValueAtIndex(runtime, i).asNumber());
529
- }
530
- auto gain = arguments[3].asNumber();
531
- auto bias = arguments[4].asNumber();
532
- SkIPoint kernelOffset =
533
- SkIPoint::Make(arguments[5].asNumber(), arguments[6].asNumber());
534
- auto tileMode = static_cast<SkTileMode>(arguments[7].asNumber());
535
- bool convolveAlpha = arguments[8].asBool();
536
- sk_sp<SkImageFilter> input = nullptr;
537
- if (hasOptionalArgument(arguments, count, 9)) {
538
- input = JsiSkImageFilter::fromValue(runtime, arguments[9]);
539
- }
540
- SkImageFilters::CropRect cropRect = {};
541
- if (hasOptionalArgument(arguments, count, 10)) {
542
- cropRect = *JsiSkRect::fromValue(runtime, arguments[10]);
543
- }
544
- auto filter = std::make_shared<JsiSkImageFilter>(
545
- getContext(), SkImageFilters::MatrixConvolution(
546
- kernelSize, kernel.data(), gain, bias, kernelOffset,
547
- tileMode, convolveAlpha, std::move(input), cropRect));
548
- return JSI_CREATE_HOST_OBJECT_WITH_MEMORY_PRESSURE(runtime, filter,
549
- getContext());
550
- }
551
-
552
- JSI_HOST_FUNCTION(MakeMatrixTransform) {
553
- SkMatrix matrix = *JsiSkMatrix::fromValue(runtime, arguments[0]);
554
- SkFilterMode filterMode = SkFilterMode::kNearest;
555
- if (hasOptionalArgument(arguments, count, 1)) {
556
- filterMode = (SkFilterMode)arguments[1].asNumber();
557
- }
558
- SkMipmapMode mipmap = SkMipmapMode::kNone;
559
- if (hasOptionalArgument(arguments, count, 2)) {
560
- mipmap = (SkMipmapMode)arguments[2].asNumber();
561
- }
562
- sk_sp<SkImageFilter> input = nullptr;
563
- if (hasOptionalArgument(arguments, count, 3)) {
564
- input = JsiSkImageFilter::fromValue(runtime, arguments[3]);
565
- }
566
- 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>(
567
290
  getContext(),
568
- SkImageFilters::MatrixTransform(
569
- matrix, SkSamplingOptions(filterMode, mipmap), std::move(input)));
570
- return JSI_CREATE_HOST_OBJECT_WITH_MEMORY_PRESSURE(runtime, filter,
571
- getContext());
291
+ SkImageFilters::MatrixConvolution(
292
+ kernelSize, kernel.data(), gain, bias, kernelOffset,
293
+ static_cast<SkTileMode>(tileMode), convolveAlpha,
294
+ orNull(std::move(input)), toCropRect(crop)));
295
+ }
296
+
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))));
572
306
  }
573
307
 
574
- JSI_HOST_FUNCTION(MakeMerge) {
308
+ std::shared_ptr<JsiSkImageFilter>
309
+ MakeMerge(std::vector<JsiOptional<sk_sp<SkImageFilter>>> jsiFilters,
310
+ JsiOptional<SkRect> crop) {
575
311
  std::vector<sk_sp<SkImageFilter>> filters;
576
- auto filtersArray = arguments[0].asObject(runtime).asArray(runtime);
577
- auto filtersCount = filtersArray.size(runtime);
578
- for (size_t i = 0; i < filtersCount; ++i) {
579
- auto element = filtersArray.getValueAtIndex(runtime, i);
580
- if (element.isNull()) {
581
- filters.push_back(nullptr);
582
- } else {
583
- filters.push_back(JsiSkImageFilter::fromValue(runtime, element));
584
- }
585
- }
586
- SkImageFilters::CropRect cropRect = {};
587
- if (hasOptionalArgument(arguments, count, 1)) {
588
- cropRect = *JsiSkRect::fromValue(runtime, arguments[1]);
312
+ filters.reserve(jsiFilters.size());
313
+ for (auto &filter : jsiFilters) {
314
+ filters.push_back(orNull(std::move(filter)));
589
315
  }
590
- auto filter = std::make_shared<JsiSkImageFilter>(
316
+ return std::make_shared<JsiSkImageFilter>(
591
317
  getContext(),
592
- SkImageFilters::Merge(filters.data(), filtersCount, cropRect));
593
- return JSI_CREATE_HOST_OBJECT_WITH_MEMORY_PRESSURE(runtime, filter,
594
- getContext());
595
- }
596
-
597
- JSI_HOST_FUNCTION(MakePicture) {
598
- sk_sp<SkPicture> picture = JsiSkPicture::fromValue(runtime, arguments[0]);
599
- SkRect targetRect;
600
- if (hasOptionalArgument(arguments, count, 1)) {
601
- targetRect = *JsiSkRect::fromValue(runtime, arguments[1]);
602
- } else {
603
- targetRect = picture ? picture->cullRect() : SkRect::MakeEmpty();
604
- }
605
- auto filter = std::make_shared<JsiSkImageFilter>(
318
+ SkImageFilters::Merge(filters.data(), filters.size(), toCropRect(crop)));
319
+ }
320
+
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>(
606
328
  getContext(), SkImageFilters::Picture(std::move(picture), targetRect));
607
- return JSI_CREATE_HOST_OBJECT_WITH_MEMORY_PRESSURE(runtime, filter,
608
- getContext());
609
- }
610
-
611
- JSI_HOST_FUNCTION(MakeRuntimeShaderWithChildren) {
612
- auto rtb = JsiSkRuntimeShaderBuilder::fromValue(runtime, arguments[0]);
613
- float maxSampleRadius = arguments[1].asNumber();
614
- std::vector<std::string> childNames;
615
- auto childNamesJS = arguments[2].asObject(runtime).asArray(runtime);
616
- size_t length = childNamesJS.size(runtime);
617
- for (size_t i = 0; i < length; ++i) {
618
- auto element = childNamesJS.getValueAtIndex(runtime, i);
619
- 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;
620
338
  }
621
339
  std::vector<std::string_view> childNamesStringView;
622
340
  childNamesStringView.reserve(childNames.size());
623
341
  for (const auto &name : childNames) {
624
342
  childNamesStringView.push_back(std::string_view(name));
625
343
  }
626
-
627
344
  std::vector<sk_sp<SkImageFilter>> inputs;
628
- auto inputsJS = arguments[3].asObject(runtime).asArray(runtime);
629
- if (inputsJS.size(runtime) != length) {
630
- return jsi::Value::null();
631
- }
632
- for (size_t i = 0; i < length; ++i) {
633
- auto element = inputsJS.getValueAtIndex(runtime, i);
634
- if (element.isNull()) {
635
- inputs.push_back(nullptr);
636
- } else {
637
- inputs.push_back(JsiSkImageFilter::fromValue(runtime, element));
638
- }
639
- }
640
- auto filter = std::make_shared<JsiSkImageFilter>(
641
- getContext(), SkImageFilters::RuntimeShader(*rtb, maxSampleRadius,
642
- childNamesStringView.data(),
643
- inputs.data(), length));
644
- return JSI_CREATE_HOST_OBJECT_WITH_MEMORY_PRESSURE(runtime, filter,
645
- getContext());
646
- }
647
-
648
- JSI_HOST_FUNCTION(MakeTile) {
649
- SkRect src = *JsiSkRect::fromValue(runtime, arguments[0]);
650
- SkRect dst = *JsiSkRect::fromValue(runtime, arguments[1]);
651
- sk_sp<SkImageFilter> input = nullptr;
652
- if (hasOptionalArgument(arguments, count, 2)) {
653
- input = JsiSkImageFilter::fromValue(runtime, arguments[2]);
654
- }
655
- auto filter = std::make_shared<JsiSkImageFilter>(
656
- getContext(), SkImageFilters::Tile(src, dst, std::move(input)));
657
- return JSI_CREATE_HOST_OBJECT_WITH_MEMORY_PRESSURE(runtime, filter,
658
- getContext());
659
- }
660
-
661
- JSI_EXPORT_FUNCTIONS(
662
- JSI_EXPORT_FUNC(JsiSkImageFilterFactory, MakeBlur),
663
- JSI_EXPORT_FUNC(JsiSkImageFilterFactory, MakeOffset),
664
- JSI_EXPORT_FUNC(JsiSkImageFilterFactory, MakeColorFilter),
665
- JSI_EXPORT_FUNC(JsiSkImageFilterFactory, MakeShader),
666
- JSI_EXPORT_FUNC(JsiSkImageFilterFactory, MakeDisplacementMap),
667
- JSI_EXPORT_FUNC(JsiSkImageFilterFactory, MakeCompose),
668
- JSI_EXPORT_FUNC(JsiSkImageFilterFactory, MakeErode),
669
- JSI_EXPORT_FUNC(JsiSkImageFilterFactory, MakeDilate),
670
- JSI_EXPORT_FUNC(JsiSkImageFilterFactory, MakeBlend),
671
- JSI_EXPORT_FUNC(JsiSkImageFilterFactory, MakeDropShadow),
672
- JSI_EXPORT_FUNC(JsiSkImageFilterFactory, MakeDropShadowOnly),
673
- JSI_EXPORT_FUNC(JsiSkImageFilterFactory, MakeRuntimeShader),
674
- JSI_EXPORT_FUNC(JsiSkImageFilterFactory, MakeArithmetic),
675
- JSI_EXPORT_FUNC(JsiSkImageFilterFactory, MakeCrop),
676
- JSI_EXPORT_FUNC(JsiSkImageFilterFactory, MakeEmpty),
677
- JSI_EXPORT_FUNC(JsiSkImageFilterFactory, MakeImage),
678
- JSI_EXPORT_FUNC(JsiSkImageFilterFactory, MakeMagnifier),
679
- JSI_EXPORT_FUNC(JsiSkImageFilterFactory, MakeMatrixConvolution),
680
- JSI_EXPORT_FUNC(JsiSkImageFilterFactory, MakeMatrixTransform),
681
- JSI_EXPORT_FUNC(JsiSkImageFilterFactory, MakeMerge),
682
- JSI_EXPORT_FUNC(JsiSkImageFilterFactory, MakePicture),
683
- JSI_EXPORT_FUNC(JsiSkImageFilterFactory, MakeRuntimeShaderWithChildren),
684
- JSI_EXPORT_FUNC(JsiSkImageFilterFactory, MakeTile),
685
- JSI_EXPORT_FUNC(JsiSkImageFilterFactory, MakeDistantLitDiffuse),
686
- JSI_EXPORT_FUNC(JsiSkImageFilterFactory, MakePointLitDiffuse),
687
- JSI_EXPORT_FUNC(JsiSkImageFilterFactory, MakeSpotLitDiffuse),
688
- JSI_EXPORT_FUNC(JsiSkImageFilterFactory, MakeDistantLitSpecular),
689
- JSI_EXPORT_FUNC(JsiSkImageFilterFactory, MakePointLitSpecular),
690
- JSI_EXPORT_FUNC(JsiSkImageFilterFactory, MakeSpotLitSpecular))
691
-
692
- size_t getMemoryPressure() const override { return 2048; }
693
-
694
- std::string getObjectType() const override {
695
- return "JsiSkImageFilterFactory";
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))));
696
359
  }
697
360
 
361
+ static void definePrototype(jsi::Runtime &runtime, jsi::Object &prototype) {
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);
420
+ }
421
+
422
+ size_t getMemoryPressure() override { return 2048; }
423
+
698
424
  explicit JsiSkImageFilterFactory(std::shared_ptr<RNSkPlatformContext> context)
699
- : JsiSkHostObject(std::move(context)) {}
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