@shopify/react-native-skia 2.10.0 → 2.11.0-next.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 (358) 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 +60 -92
  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/dawn/include/dawn/dawn_proc.h +53 -0
  56. package/cpp/dawn/include/dawn/dawn_proc_table.h +330 -0
  57. package/cpp/dawn/include/dawn/dawn_thread_dispatch_proc.h +47 -0
  58. package/cpp/dawn/include/dawn/dawn_version.h +41 -0
  59. package/cpp/dawn/include/dawn/native/D3D11Backend.h +65 -0
  60. package/cpp/dawn/include/dawn/native/D3D12Backend.h +86 -0
  61. package/cpp/dawn/include/dawn/native/D3DBackend.h +56 -0
  62. package/cpp/dawn/include/dawn/native/DawnNative.h +369 -0
  63. package/cpp/dawn/include/dawn/native/MetalBackend.h +56 -0
  64. package/cpp/dawn/include/dawn/native/NullBackend.h +39 -0
  65. package/cpp/dawn/include/dawn/native/OpenGLBackend.h +89 -0
  66. package/cpp/dawn/include/dawn/native/VulkanBackend.h +183 -0
  67. package/cpp/dawn/include/dawn/native/WebGPUBackend.h +49 -0
  68. package/cpp/dawn/include/dawn/native/dawn_native_export.h +49 -0
  69. package/cpp/dawn/include/dawn/platform/DawnPlatform.h +210 -0
  70. package/cpp/dawn/include/dawn/platform/dawn_platform_export.h +49 -0
  71. package/cpp/dawn/include/dawn/replay/Replay.h +99 -0
  72. package/cpp/dawn/include/dawn/replay/dawn_replay_export.h +49 -0
  73. package/cpp/dawn/include/dawn/webgpu_cpp_print.h +2844 -0
  74. package/cpp/dawn/include/tint/tint.h +90 -0
  75. package/cpp/dawn/include/webgpu/webgpu.h +4987 -0
  76. package/cpp/dawn/include/webgpu/webgpu_cpp.h +10080 -0
  77. package/cpp/dawn/include/webgpu/webgpu_cpp_chained_struct.h +57 -0
  78. package/cpp/dawn/include/webgpu/webgpu_enum_class_bitmasks.h +161 -0
  79. package/cpp/dawn/include/webgpu/webgpu_glfw.h +88 -0
  80. package/cpp/jsi/JSIConverter.h +0 -31
  81. package/cpp/jsi/NativeObject.h +11 -6
  82. package/cpp/rnskia/RNDawnContext.h +18 -2
  83. package/cpp/rnskia/RNDawnInterop.cpp +19 -0
  84. package/cpp/rnskia/RNDawnUtils.h +18 -1
  85. package/cpp/rnskia/RNSkManager.cpp +5 -162
  86. package/cpp/skia/include/gpu/ganesh/GrDriverBugWorkaroundsAutogen.h +2 -0
  87. package/cpp/skia/src/gpu/graphite/ContextOptionsPriv.h +45 -0
  88. package/cpp/skia/src/gpu/graphite/ResourceTypes.h +360 -0
  89. package/cpp/skia/src/gpu/graphite/TextureProxyView.h +105 -0
  90. package/lib/commonjs/mock/index.js +0 -1
  91. package/lib/commonjs/mock/index.js.map +1 -1
  92. package/lib/commonjs/skia/types/Image/ImageFactory.d.ts +15 -6
  93. package/lib/commonjs/skia/types/Image/ImageFactory.js.map +1 -1
  94. package/lib/commonjs/skia/types/Skia.d.ts +5 -15
  95. package/lib/commonjs/skia/types/Skia.js.map +1 -1
  96. package/lib/commonjs/skia/types/index.d.ts +0 -1
  97. package/lib/commonjs/skia/types/index.js +0 -11
  98. package/lib/commonjs/skia/types/index.js.map +1 -1
  99. package/lib/commonjs/skia/web/JsiSkImageFactory.d.ts +2 -2
  100. package/lib/commonjs/skia/web/JsiSkImageFactory.js +2 -2
  101. package/lib/commonjs/skia/web/JsiSkImageFactory.js.map +1 -1
  102. package/lib/commonjs/skia/web/JsiSkia.js +1 -4
  103. package/lib/commonjs/skia/web/JsiSkia.js.map +1 -1
  104. package/lib/commonjs/views/index.d.ts +0 -1
  105. package/lib/commonjs/views/index.js +0 -11
  106. package/lib/commonjs/views/index.js.map +1 -1
  107. package/lib/module/mock/index.js +0 -1
  108. package/lib/module/mock/index.js.map +1 -1
  109. package/lib/module/skia/types/Image/ImageFactory.d.ts +15 -6
  110. package/lib/module/skia/types/Image/ImageFactory.js.map +1 -1
  111. package/lib/module/skia/types/Skia.d.ts +5 -15
  112. package/lib/module/skia/types/Skia.js.map +1 -1
  113. package/lib/module/skia/types/index.d.ts +0 -1
  114. package/lib/module/skia/types/index.js +0 -1
  115. package/lib/module/skia/types/index.js.map +1 -1
  116. package/lib/module/skia/web/JsiSkImageFactory.d.ts +2 -2
  117. package/lib/module/skia/web/JsiSkImageFactory.js +2 -2
  118. package/lib/module/skia/web/JsiSkImageFactory.js.map +1 -1
  119. package/lib/module/skia/web/JsiSkia.js +1 -4
  120. package/lib/module/skia/web/JsiSkia.js.map +1 -1
  121. package/lib/module/views/index.d.ts +0 -1
  122. package/lib/module/views/index.js +0 -1
  123. package/lib/module/views/index.js.map +1 -1
  124. package/lib/typescript/lib/commonjs/mock/index.d.ts +0 -1
  125. package/lib/typescript/lib/commonjs/skia/web/JsiSkImageFactory.d.ts +2 -2
  126. package/lib/typescript/lib/commonjs/skia/web/JsiSkia.d.ts +1 -2
  127. package/lib/typescript/lib/module/mock/index.d.ts +0 -2
  128. package/lib/typescript/lib/module/skia/Skia.web.d.ts +1 -2
  129. package/lib/typescript/lib/module/skia/types/index.d.ts +0 -1
  130. package/lib/typescript/lib/module/skia/web/JsiSkImageFactory.d.ts +2 -2
  131. package/lib/typescript/lib/module/skia/web/JsiSkia.d.ts +1 -2
  132. package/lib/typescript/lib/module/views/index.d.ts +0 -1
  133. package/lib/typescript/src/skia/types/Image/ImageFactory.d.ts +15 -6
  134. package/lib/typescript/src/skia/types/Skia.d.ts +5 -15
  135. package/lib/typescript/src/skia/types/index.d.ts +0 -1
  136. package/lib/typescript/src/skia/web/JsiSkImageFactory.d.ts +2 -2
  137. package/lib/typescript/src/views/index.d.ts +0 -1
  138. package/libs/.graphite +1 -0
  139. package/package.json +8 -9
  140. package/react-native-skia.podspec +38 -4
  141. package/src/mock/index.ts +0 -1
  142. package/src/skia/types/Image/ImageFactory.ts +15 -6
  143. package/src/skia/types/Skia.ts +5 -15
  144. package/src/skia/types/index.ts +0 -1
  145. package/src/skia/web/JsiSkImageFactory.ts +3 -3
  146. package/src/skia/web/JsiSkia.ts +2 -5
  147. package/src/views/index.ts +0 -1
  148. package/android/cpp/jni/JniWebGPUView.cpp +0 -112
  149. package/android/cpp/rnskia-android/SkiaPlatformContext.h +0 -26
  150. package/android/src/main/java/com/shopify/reactnative/skia/WebGPUSurfaceView.java +0 -43
  151. package/android/src/main/java/com/shopify/reactnative/skia/WebGPUTextureView.java +0 -50
  152. package/android/src/main/java/com/shopify/reactnative/skia/WebGPUView.java +0 -98
  153. package/android/src/main/java/com/shopify/reactnative/skia/WebGPUViewAPI.java +0 -19
  154. package/android/src/main/java/com/shopify/reactnative/skia/WebGPUViewManager.java +0 -58
  155. package/apple/RNWebGPUAppleNativeBuffer.mm +0 -33
  156. package/apple/SkiaPlatformContext.h +0 -20
  157. package/apple/SkiaPlatformContext.mm +0 -21
  158. package/apple/SkiaWebGPUView.mm +0 -81
  159. package/apple/WebGPUMetalView.mm +0 -136
  160. package/cpp/rnwgpu/ArrayBuffer.h +0 -116
  161. package/cpp/rnwgpu/Canvas.h +0 -52
  162. package/cpp/rnwgpu/PlatformContext.h +0 -18
  163. package/cpp/rnwgpu/SurfaceRegistry.h +0 -605
  164. package/cpp/rnwgpu/api/AppleNativeBuffer.h +0 -22
  165. package/cpp/rnwgpu/api/Convertors.h +0 -783
  166. package/cpp/rnwgpu/api/External.h +0 -12
  167. package/cpp/rnwgpu/api/GPU.cpp +0 -162
  168. package/cpp/rnwgpu/api/GPU.h +0 -60
  169. package/cpp/rnwgpu/api/GPUAdapter.cpp +0 -239
  170. package/cpp/rnwgpu/api/GPUAdapter.h +0 -60
  171. package/cpp/rnwgpu/api/GPUAdapterInfo.h +0 -57
  172. package/cpp/rnwgpu/api/GPUBindGroup.cpp +0 -3
  173. package/cpp/rnwgpu/api/GPUBindGroup.h +0 -51
  174. package/cpp/rnwgpu/api/GPUBindGroupLayout.h +0 -52
  175. package/cpp/rnwgpu/api/GPUBuffer.cpp +0 -107
  176. package/cpp/rnwgpu/api/GPUBuffer.h +0 -88
  177. package/cpp/rnwgpu/api/GPUCanvasContext.cpp +0 -75
  178. package/cpp/rnwgpu/api/GPUCanvasContext.h +0 -70
  179. package/cpp/rnwgpu/api/GPUCommandBuffer.h +0 -45
  180. package/cpp/rnwgpu/api/GPUCommandEncoder.cpp +0 -179
  181. package/cpp/rnwgpu/api/GPUCommandEncoder.h +0 -111
  182. package/cpp/rnwgpu/api/GPUCompilationInfo.h +0 -79
  183. package/cpp/rnwgpu/api/GPUCompilationMessage.h +0 -36
  184. package/cpp/rnwgpu/api/GPUComputePassEncoder.cpp +0 -60
  185. package/cpp/rnwgpu/api/GPUComputePassEncoder.h +0 -85
  186. package/cpp/rnwgpu/api/GPUComputePipeline.cpp +0 -12
  187. package/cpp/rnwgpu/api/GPUComputePipeline.h +0 -60
  188. package/cpp/rnwgpu/api/GPUDevice.cpp +0 -613
  189. package/cpp/rnwgpu/api/GPUDevice.h +0 -258
  190. package/cpp/rnwgpu/api/GPUDeviceLostInfo.cpp +0 -7
  191. package/cpp/rnwgpu/api/GPUDeviceLostInfo.h +0 -40
  192. package/cpp/rnwgpu/api/GPUError.h +0 -35
  193. package/cpp/rnwgpu/api/GPUExtent3D.h +0 -66
  194. package/cpp/rnwgpu/api/GPUExternalTexture.cpp +0 -139
  195. package/cpp/rnwgpu/api/GPUExternalTexture.h +0 -95
  196. package/cpp/rnwgpu/api/GPUFeatures.h +0 -203
  197. package/cpp/rnwgpu/api/GPUInternalError.h +0 -31
  198. package/cpp/rnwgpu/api/GPUOrigin2D.h +0 -55
  199. package/cpp/rnwgpu/api/GPUOrigin3D.h +0 -62
  200. package/cpp/rnwgpu/api/GPUOutOfMemoryError.h +0 -33
  201. package/cpp/rnwgpu/api/GPUPipelineLayout.h +0 -45
  202. package/cpp/rnwgpu/api/GPUQuerySet.cpp +0 -11
  203. package/cpp/rnwgpu/api/GPUQuerySet.h +0 -73
  204. package/cpp/rnwgpu/api/GPUQueue.cpp +0 -179
  205. package/cpp/rnwgpu/api/GPUQueue.h +0 -84
  206. package/cpp/rnwgpu/api/GPURenderBundle.h +0 -44
  207. package/cpp/rnwgpu/api/GPURenderBundleEncoder.cpp +0 -131
  208. package/cpp/rnwgpu/api/GPURenderBundleEncoder.h +0 -110
  209. package/cpp/rnwgpu/api/GPURenderPassEncoder.cpp +0 -165
  210. package/cpp/rnwgpu/api/GPURenderPassEncoder.h +0 -130
  211. package/cpp/rnwgpu/api/GPURenderPipeline.cpp +0 -13
  212. package/cpp/rnwgpu/api/GPURenderPipeline.h +0 -61
  213. package/cpp/rnwgpu/api/GPUSampler.h +0 -44
  214. package/cpp/rnwgpu/api/GPUShaderModule.cpp +0 -56
  215. package/cpp/rnwgpu/api/GPUShaderModule.h +0 -66
  216. package/cpp/rnwgpu/api/GPUSharedFence.cpp +0 -80
  217. package/cpp/rnwgpu/api/GPUSharedFence.h +0 -53
  218. package/cpp/rnwgpu/api/GPUSharedTextureMemory.cpp +0 -135
  219. package/cpp/rnwgpu/api/GPUSharedTextureMemory.h +0 -75
  220. package/cpp/rnwgpu/api/GPUSupportedLimits.cpp +0 -129
  221. package/cpp/rnwgpu/api/GPUSupportedLimits.h +0 -131
  222. package/cpp/rnwgpu/api/GPUTexture.cpp +0 -47
  223. package/cpp/rnwgpu/api/GPUTexture.h +0 -162
  224. package/cpp/rnwgpu/api/GPUTextureView.h +0 -44
  225. package/cpp/rnwgpu/api/GPUUncapturedErrorEvent.h +0 -60
  226. package/cpp/rnwgpu/api/GPUValidationError.h +0 -32
  227. package/cpp/rnwgpu/api/ImageBitmap.h +0 -62
  228. package/cpp/rnwgpu/api/NativeBufferUtils.h +0 -87
  229. package/cpp/rnwgpu/api/RNWebGPU.h +0 -82
  230. package/cpp/rnwgpu/api/WebGPUConstants.h +0 -36
  231. package/cpp/rnwgpu/api/descriptors/GPUBindGroupDescriptor.h +0 -64
  232. package/cpp/rnwgpu/api/descriptors/GPUBindGroupEntry.h +0 -78
  233. package/cpp/rnwgpu/api/descriptors/GPUBindGroupLayoutDescriptor.h +0 -56
  234. package/cpp/rnwgpu/api/descriptors/GPUBindGroupLayoutEntry.h +0 -97
  235. package/cpp/rnwgpu/api/descriptors/GPUBlendComponent.h +0 -57
  236. package/cpp/rnwgpu/api/descriptors/GPUBlendState.h +0 -52
  237. package/cpp/rnwgpu/api/descriptors/GPUBufferBinding.h +0 -56
  238. package/cpp/rnwgpu/api/descriptors/GPUBufferBindingLayout.h +0 -56
  239. package/cpp/rnwgpu/api/descriptors/GPUBufferDescriptor.h +0 -59
  240. package/cpp/rnwgpu/api/descriptors/GPUBufferUsage.h +0 -39
  241. package/cpp/rnwgpu/api/descriptors/GPUCanvasConfiguration.h +0 -76
  242. package/cpp/rnwgpu/api/descriptors/GPUColor.h +0 -66
  243. package/cpp/rnwgpu/api/descriptors/GPUColorTargetState.h +0 -58
  244. package/cpp/rnwgpu/api/descriptors/GPUColorWrite.h +0 -29
  245. package/cpp/rnwgpu/api/descriptors/GPUCommandBufferDescriptor.h +0 -45
  246. package/cpp/rnwgpu/api/descriptors/GPUCommandEncoderDescriptor.h +0 -45
  247. package/cpp/rnwgpu/api/descriptors/GPUComputePassDescriptor.h +0 -56
  248. package/cpp/rnwgpu/api/descriptors/GPUComputePassTimestampWrites.h +0 -58
  249. package/cpp/rnwgpu/api/descriptors/GPUComputePipelineDescriptor.h +0 -67
  250. package/cpp/rnwgpu/api/descriptors/GPUDawnTogglesDescriptor.h +0 -56
  251. package/cpp/rnwgpu/api/descriptors/GPUDepthStencilState.h +0 -103
  252. package/cpp/rnwgpu/api/descriptors/GPUDeviceDescriptor.h +0 -109
  253. package/cpp/rnwgpu/api/descriptors/GPUExternalTextureBindingLayout.h +0 -38
  254. package/cpp/rnwgpu/api/descriptors/GPUExternalTextureDescriptor.h +0 -90
  255. package/cpp/rnwgpu/api/descriptors/GPUFragmentState.h +0 -73
  256. package/cpp/rnwgpu/api/descriptors/GPUImageCopyBuffer.h +0 -62
  257. package/cpp/rnwgpu/api/descriptors/GPUImageCopyExternalImage.h +0 -63
  258. package/cpp/rnwgpu/api/descriptors/GPUImageCopyTexture.h +0 -65
  259. package/cpp/rnwgpu/api/descriptors/GPUImageCopyTextureTagged.h +0 -81
  260. package/cpp/rnwgpu/api/descriptors/GPUImageDataLayout.h +0 -54
  261. package/cpp/rnwgpu/api/descriptors/GPUMapMode.h +0 -22
  262. package/cpp/rnwgpu/api/descriptors/GPUMultisampleState.h +0 -54
  263. package/cpp/rnwgpu/api/descriptors/GPUPipelineLayoutDescriptor.h +0 -57
  264. package/cpp/rnwgpu/api/descriptors/GPUPrimitiveState.h +0 -69
  265. package/cpp/rnwgpu/api/descriptors/GPUProgrammableStage.h +0 -61
  266. package/cpp/rnwgpu/api/descriptors/GPUQuerySetDescriptor.h +0 -55
  267. package/cpp/rnwgpu/api/descriptors/GPUQueueDescriptor.h +0 -43
  268. package/cpp/rnwgpu/api/descriptors/GPURenderBundleDescriptor.h +0 -45
  269. package/cpp/rnwgpu/api/descriptors/GPURenderBundleEncoderDescriptor.h +0 -80
  270. package/cpp/rnwgpu/api/descriptors/GPURenderPassColorAttachment.h +0 -81
  271. package/cpp/rnwgpu/api/descriptors/GPURenderPassDepthStencilAttachment.h +0 -101
  272. package/cpp/rnwgpu/api/descriptors/GPURenderPassDescriptor.h +0 -92
  273. package/cpp/rnwgpu/api/descriptors/GPURenderPassTimestampWrites.h +0 -58
  274. package/cpp/rnwgpu/api/descriptors/GPURenderPipelineDescriptor.h +0 -103
  275. package/cpp/rnwgpu/api/descriptors/GPURequestAdapterOptions.h +0 -51
  276. package/cpp/rnwgpu/api/descriptors/GPUSamplerBindingLayout.h +0 -45
  277. package/cpp/rnwgpu/api/descriptors/GPUSamplerDescriptor.h +0 -110
  278. package/cpp/rnwgpu/api/descriptors/GPUShaderModuleCompilationHint.h +0 -60
  279. package/cpp/rnwgpu/api/descriptors/GPUShaderModuleDescriptor.h +0 -62
  280. package/cpp/rnwgpu/api/descriptors/GPUShaderStage.h +0 -25
  281. package/cpp/rnwgpu/api/descriptors/GPUSharedFenceDescriptor.h +0 -58
  282. package/cpp/rnwgpu/api/descriptors/GPUSharedFenceState.h +0 -51
  283. package/cpp/rnwgpu/api/descriptors/GPUSharedTextureMemoryDescriptor.h +0 -73
  284. package/cpp/rnwgpu/api/descriptors/GPUStencilFaceState.h +0 -64
  285. package/cpp/rnwgpu/api/descriptors/GPUStorageTextureBindingLayout.h +0 -59
  286. package/cpp/rnwgpu/api/descriptors/GPUTextureBindingLayout.h +0 -59
  287. package/cpp/rnwgpu/api/descriptors/GPUTextureDescriptor.h +0 -91
  288. package/cpp/rnwgpu/api/descriptors/GPUTextureUsage.h +0 -29
  289. package/cpp/rnwgpu/api/descriptors/GPUTextureViewDescriptor.h +0 -91
  290. package/cpp/rnwgpu/api/descriptors/GPUUncapturedErrorEventInit.h +0 -64
  291. package/cpp/rnwgpu/api/descriptors/GPUVertexAttribute.h +0 -53
  292. package/cpp/rnwgpu/api/descriptors/GPUVertexBufferLayout.h +0 -62
  293. package/cpp/rnwgpu/api/descriptors/GPUVertexState.h +0 -73
  294. package/cpp/rnwgpu/api/descriptors/Unions.h +0 -1969
  295. package/cpp/rnwgpu/async/AsyncTaskHandle.cpp +0 -213
  296. package/cpp/rnwgpu/async/AsyncTaskHandle.h +0 -58
  297. package/cpp/rnwgpu/async/RuntimeContext.cpp +0 -199
  298. package/cpp/rnwgpu/async/RuntimeContext.h +0 -134
  299. package/lib/commonjs/skia/types/WebGPU.d.ts +0 -184
  300. package/lib/commonjs/skia/types/WebGPU.js +0 -105
  301. package/lib/commonjs/skia/types/WebGPU.js.map +0 -1
  302. package/lib/commonjs/specs/WebGPUViewNativeComponent.d.ts +0 -8
  303. package/lib/commonjs/specs/WebGPUViewNativeComponent.js +0 -10
  304. package/lib/commonjs/specs/WebGPUViewNativeComponent.js.map +0 -1
  305. package/lib/commonjs/specs/WebGPUViewNativeComponent.web.d.ts +0 -8
  306. package/lib/commonjs/specs/WebGPUViewNativeComponent.web.js +0 -103
  307. package/lib/commonjs/specs/WebGPUViewNativeComponent.web.js.map +0 -1
  308. package/lib/commonjs/specs/utils.d.ts +0 -1
  309. package/lib/commonjs/specs/utils.js +0 -11
  310. package/lib/commonjs/specs/utils.js.map +0 -1
  311. package/lib/commonjs/views/WebGPUCanvas.d.ts +0 -33
  312. package/lib/commonjs/views/WebGPUCanvas.js +0 -79
  313. package/lib/commonjs/views/WebGPUCanvas.js.map +0 -1
  314. package/lib/commonjs/views/WebGPUCanvas.web.d.ts +0 -23
  315. package/lib/commonjs/views/WebGPUCanvas.web.js +0 -20
  316. package/lib/commonjs/views/WebGPUCanvas.web.js.map +0 -1
  317. package/lib/module/skia/types/WebGPU.d.ts +0 -184
  318. package/lib/module/skia/types/WebGPU.js +0 -99
  319. package/lib/module/skia/types/WebGPU.js.map +0 -1
  320. package/lib/module/specs/WebGPUViewNativeComponent.d.ts +0 -8
  321. package/lib/module/specs/WebGPUViewNativeComponent.js +0 -4
  322. package/lib/module/specs/WebGPUViewNativeComponent.js.map +0 -1
  323. package/lib/module/specs/WebGPUViewNativeComponent.web.d.ts +0 -8
  324. package/lib/module/specs/WebGPUViewNativeComponent.web.js +0 -96
  325. package/lib/module/specs/WebGPUViewNativeComponent.web.js.map +0 -1
  326. package/lib/module/specs/utils.d.ts +0 -1
  327. package/lib/module/specs/utils.js +0 -5
  328. package/lib/module/specs/utils.js.map +0 -1
  329. package/lib/module/views/WebGPUCanvas.d.ts +0 -33
  330. package/lib/module/views/WebGPUCanvas.js +0 -70
  331. package/lib/module/views/WebGPUCanvas.js.map +0 -1
  332. package/lib/module/views/WebGPUCanvas.web.d.ts +0 -23
  333. package/lib/module/views/WebGPUCanvas.web.js +0 -12
  334. package/lib/module/views/WebGPUCanvas.web.js.map +0 -1
  335. package/lib/typescript/lib/commonjs/skia/types/WebGPU.d.ts +0 -2
  336. package/lib/typescript/lib/commonjs/specs/WebGPUViewNativeComponent.d.ts +0 -4
  337. package/lib/typescript/lib/commonjs/specs/WebGPUViewNativeComponent.web.d.ts +0 -3
  338. package/lib/typescript/lib/commonjs/specs/utils.d.ts +0 -2
  339. package/lib/typescript/lib/commonjs/views/WebGPUCanvas.d.ts +0 -6
  340. package/lib/typescript/lib/commonjs/views/WebGPUCanvas.web.d.ts +0 -6
  341. package/lib/typescript/lib/module/skia/types/WebGPU.d.ts +0 -31
  342. package/lib/typescript/lib/module/specs/WebGPUViewNativeComponent.d.ts +0 -2
  343. package/lib/typescript/lib/module/specs/WebGPUViewNativeComponent.web.d.ts +0 -2
  344. package/lib/typescript/lib/module/specs/utils.d.ts +0 -1
  345. package/lib/typescript/lib/module/views/WebGPUCanvas.d.ts +0 -7
  346. package/lib/typescript/lib/module/views/WebGPUCanvas.web.d.ts +0 -8
  347. package/lib/typescript/src/skia/types/WebGPU.d.ts +0 -184
  348. package/lib/typescript/src/specs/WebGPUViewNativeComponent.d.ts +0 -8
  349. package/lib/typescript/src/specs/WebGPUViewNativeComponent.web.d.ts +0 -8
  350. package/lib/typescript/src/specs/utils.d.ts +0 -1
  351. package/lib/typescript/src/views/WebGPUCanvas.d.ts +0 -33
  352. package/lib/typescript/src/views/WebGPUCanvas.web.d.ts +0 -23
  353. package/src/skia/types/WebGPU.ts +0 -226
  354. package/src/specs/WebGPUViewNativeComponent.ts +0 -11
  355. package/src/specs/WebGPUViewNativeComponent.web.ts +0 -110
  356. package/src/specs/utils.ts +0 -4
  357. package/src/views/WebGPUCanvas.tsx +0 -125
  358. 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