@shopify/react-native-skia 2.9.1-next.1 → 2.10.0

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 (273) hide show
  1. package/android/CMakeLists.txt +1 -5
  2. package/android/cpp/jni/JniWebGPUView.cpp +52 -7
  3. package/android/src/main/java/com/shopify/reactnative/skia/WebGPUSurfaceView.java +3 -1
  4. package/android/src/main/java/com/shopify/reactnative/skia/WebGPUTextureView.java +11 -5
  5. package/android/src/main/java/com/shopify/reactnative/skia/WebGPUView.java +10 -7
  6. package/android/src/main/java/com/shopify/reactnative/skia/WebGPUViewAPI.java +7 -2
  7. package/android/src/main/java/com/shopify/reactnative/skia/WebGPUViewManager.java +1 -1
  8. package/apple/WebGPUMetalView.mm +49 -6
  9. package/cpp/api/JsiNativeBuffer.h +15 -10
  10. package/cpp/api/JsiSkAnimatedImage.h +21 -19
  11. package/cpp/api/JsiSkAnimatedImageFactory.h +13 -14
  12. package/cpp/api/JsiSkApi.h +246 -92
  13. package/cpp/api/JsiSkCanvas.h +76 -58
  14. package/cpp/api/JsiSkColor.h +7 -5
  15. package/cpp/api/JsiSkColorFilter.h +15 -8
  16. package/cpp/api/JsiSkColorFilterFactory.h +45 -45
  17. package/cpp/api/JsiSkContourMeasure.h +24 -21
  18. package/cpp/api/JsiSkContourMeasureIter.h +18 -21
  19. package/cpp/api/JsiSkData.h +13 -7
  20. package/cpp/api/JsiSkDataFactory.h +22 -21
  21. package/cpp/api/JsiSkFont.h +56 -44
  22. package/cpp/api/JsiSkFontMgr.h +22 -13
  23. package/cpp/api/JsiSkFontMgrFactory.h +12 -10
  24. package/cpp/api/JsiSkFontStyle.h +14 -12
  25. package/cpp/api/JsiSkImage.h +45 -34
  26. package/cpp/api/JsiSkImageFactory.h +47 -52
  27. package/cpp/api/JsiSkImageFilter.h +21 -11
  28. package/cpp/api/JsiSkImageFilterFactory.h +96 -96
  29. package/cpp/api/JsiSkImageInfo.h +22 -19
  30. package/cpp/api/JsiSkMaskFilter.h +21 -11
  31. package/cpp/api/JsiSkMaskFilterFactory.h +16 -13
  32. package/cpp/api/JsiSkMatrix.h +31 -31
  33. package/cpp/api/JsiSkNativeObjects.h +419 -0
  34. package/cpp/api/JsiSkPaint.h +59 -39
  35. package/cpp/api/JsiSkParagraph.h +39 -32
  36. package/cpp/api/JsiSkParagraphBuilder.h +24 -21
  37. package/cpp/api/JsiSkParagraphBuilderFactory.h +13 -12
  38. package/cpp/api/JsiSkParagraphStyle.h +20 -10
  39. package/cpp/api/JsiSkPath.h +95 -70
  40. package/cpp/api/JsiSkPathBuilder.h +83 -67
  41. package/cpp/api/JsiSkPathBuilderFactory.h +16 -17
  42. package/cpp/api/JsiSkPathEffect.h +21 -11
  43. package/cpp/api/JsiSkPathEffectFactory.h +33 -32
  44. package/cpp/api/JsiSkPathFactory.h +79 -103
  45. package/cpp/api/JsiSkPicture.h +24 -13
  46. package/cpp/api/JsiSkPictureFactory.h +21 -26
  47. package/cpp/api/JsiSkPictureRecorder.h +21 -22
  48. package/cpp/api/JsiSkPoint.h +19 -22
  49. package/cpp/api/JsiSkRRect.h +22 -29
  50. package/cpp/api/JsiSkRSXform.h +26 -30
  51. package/cpp/api/JsiSkRect.h +28 -30
  52. package/cpp/api/JsiSkRuntimeEffect.h +39 -30
  53. package/cpp/api/JsiSkRuntimeEffectFactory.h +12 -12
  54. package/cpp/api/JsiSkRuntimeShaderBuilder.h +25 -18
  55. package/cpp/api/JsiSkSVG.h +13 -13
  56. package/cpp/api/JsiSkSVGFactory.h +17 -20
  57. package/cpp/api/JsiSkShader.h +15 -8
  58. package/cpp/api/JsiSkShaderFactory.h +41 -48
  59. package/cpp/api/JsiSkSkottie.h +49 -39
  60. package/cpp/api/JsiSkStrutStyle.h +18 -8
  61. package/cpp/api/JsiSkSurface.h +24 -24
  62. package/cpp/api/JsiSkSurfaceFactory.h +15 -16
  63. package/cpp/api/JsiSkTextBlob.h +15 -8
  64. package/cpp/api/JsiSkTextBlobFactory.h +25 -28
  65. package/cpp/api/JsiSkTextStyle.h +34 -24
  66. package/cpp/api/JsiSkTypeface.h +19 -12
  67. package/cpp/api/JsiSkTypefaceFactory.h +12 -12
  68. package/cpp/api/JsiSkTypefaceFontProvider.h +30 -25
  69. package/cpp/api/JsiSkTypefaceFontProviderFactory.h +14 -12
  70. package/cpp/api/JsiSkVertices.h +21 -18
  71. package/cpp/api/JsiSkiaContext.h +17 -17
  72. package/cpp/api/JsiSkottieFactory.h +16 -17
  73. package/cpp/api/JsiVideo.h +27 -25
  74. package/cpp/api/recorder/Convertor.h +31 -61
  75. package/cpp/api/recorder/DataTypes.h +8 -16
  76. package/cpp/api/recorder/JsiRecorder.h +83 -55
  77. package/cpp/api/recorder/RNRecorder.h +1 -1
  78. package/cpp/jsi/BoxedNativeObject.h +146 -0
  79. package/cpp/{jsi2 → jsi}/EnumMapper.h +4 -1
  80. package/cpp/{jsi2 → jsi}/NativeObject.h +120 -146
  81. package/cpp/jsi/RuntimeAwareCache.cpp +1 -1
  82. package/cpp/jsi/RuntimeAwareCache.h +26 -8
  83. package/cpp/jsi/ViewProperty.h +5 -11
  84. package/cpp/rnskia/RNSkJsiViewApi.h +20 -11
  85. package/cpp/rnskia/RNSkManager.cpp +29 -25
  86. package/cpp/rnskia/RNSkPictureView.h +1 -1
  87. package/cpp/rnwgpu/ArrayBuffer.h +5 -6
  88. package/cpp/rnwgpu/Canvas.h +4 -2
  89. package/cpp/rnwgpu/SurfaceRegistry.h +469 -131
  90. package/cpp/rnwgpu/api/GPU.cpp +4 -4
  91. package/cpp/rnwgpu/api/GPU.h +1 -1
  92. package/cpp/rnwgpu/api/GPUAdapter.cpp +12 -6
  93. package/cpp/rnwgpu/api/GPUAdapter.h +5 -4
  94. package/cpp/rnwgpu/api/GPUAdapterInfo.h +1 -1
  95. package/cpp/rnwgpu/api/GPUBindGroup.h +1 -1
  96. package/cpp/rnwgpu/api/GPUBindGroupLayout.h +1 -1
  97. package/cpp/rnwgpu/api/GPUBuffer.cpp +12 -2
  98. package/cpp/rnwgpu/api/GPUBuffer.h +4 -3
  99. package/cpp/rnwgpu/api/GPUCanvasContext.cpp +33 -19
  100. package/cpp/rnwgpu/api/GPUCanvasContext.h +4 -2
  101. package/cpp/rnwgpu/api/GPUCommandBuffer.h +1 -1
  102. package/cpp/rnwgpu/api/GPUCommandEncoder.h +1 -1
  103. package/cpp/rnwgpu/api/GPUCompilationInfo.h +1 -1
  104. package/cpp/rnwgpu/api/GPUCompilationMessage.h +1 -1
  105. package/cpp/rnwgpu/api/GPUComputePassEncoder.h +1 -1
  106. package/cpp/rnwgpu/api/GPUComputePipeline.h +1 -1
  107. package/cpp/rnwgpu/api/GPUDevice.cpp +38 -24
  108. package/cpp/rnwgpu/api/GPUDevice.h +12 -10
  109. package/cpp/rnwgpu/api/GPUDeviceLostInfo.h +1 -1
  110. package/cpp/rnwgpu/api/GPUError.h +1 -1
  111. package/cpp/rnwgpu/api/GPUExtent3D.h +1 -1
  112. package/cpp/rnwgpu/api/GPUExternalTexture.h +1 -1
  113. package/cpp/rnwgpu/api/GPUInternalError.h +1 -1
  114. package/cpp/rnwgpu/api/GPUOrigin2D.h +1 -1
  115. package/cpp/rnwgpu/api/GPUOrigin3D.h +1 -1
  116. package/cpp/rnwgpu/api/GPUOutOfMemoryError.h +1 -1
  117. package/cpp/rnwgpu/api/GPUPipelineLayout.h +1 -1
  118. package/cpp/rnwgpu/api/GPUQuerySet.h +1 -1
  119. package/cpp/rnwgpu/api/GPUQueue.cpp +6 -2
  120. package/cpp/rnwgpu/api/GPUQueue.h +4 -4
  121. package/cpp/rnwgpu/api/GPURenderBundle.h +1 -1
  122. package/cpp/rnwgpu/api/GPURenderBundleEncoder.h +1 -1
  123. package/cpp/rnwgpu/api/GPURenderPassEncoder.h +1 -1
  124. package/cpp/rnwgpu/api/GPURenderPipeline.h +1 -1
  125. package/cpp/rnwgpu/api/GPUSampler.h +1 -1
  126. package/cpp/rnwgpu/api/GPUShaderModule.cpp +8 -3
  127. package/cpp/rnwgpu/api/GPUShaderModule.h +4 -4
  128. package/cpp/rnwgpu/api/GPUSharedFence.h +1 -1
  129. package/cpp/rnwgpu/api/GPUSharedTextureMemory.h +1 -1
  130. package/cpp/rnwgpu/api/GPUSupportedLimits.h +1 -1
  131. package/cpp/rnwgpu/api/GPUTexture.h +1 -1
  132. package/cpp/rnwgpu/api/GPUTextureView.h +1 -1
  133. package/cpp/rnwgpu/api/GPUUncapturedErrorEvent.h +1 -1
  134. package/cpp/rnwgpu/api/GPUValidationError.h +1 -1
  135. package/cpp/rnwgpu/api/ImageBitmap.h +1 -1
  136. package/cpp/rnwgpu/api/RNWebGPU.h +21 -1
  137. package/cpp/rnwgpu/api/descriptors/GPUBindGroupDescriptor.h +1 -1
  138. package/cpp/rnwgpu/api/descriptors/GPUBindGroupEntry.h +1 -1
  139. package/cpp/rnwgpu/api/descriptors/GPUBindGroupLayoutDescriptor.h +1 -1
  140. package/cpp/rnwgpu/api/descriptors/GPUBindGroupLayoutEntry.h +1 -1
  141. package/cpp/rnwgpu/api/descriptors/GPUBlendComponent.h +1 -1
  142. package/cpp/rnwgpu/api/descriptors/GPUBlendState.h +1 -1
  143. package/cpp/rnwgpu/api/descriptors/GPUBufferBinding.h +1 -1
  144. package/cpp/rnwgpu/api/descriptors/GPUBufferBindingLayout.h +1 -1
  145. package/cpp/rnwgpu/api/descriptors/GPUBufferDescriptor.h +1 -1
  146. package/cpp/rnwgpu/api/descriptors/GPUCanvasConfiguration.h +1 -1
  147. package/cpp/rnwgpu/api/descriptors/GPUColor.h +1 -1
  148. package/cpp/rnwgpu/api/descriptors/GPUColorTargetState.h +1 -1
  149. package/cpp/rnwgpu/api/descriptors/GPUCommandBufferDescriptor.h +1 -1
  150. package/cpp/rnwgpu/api/descriptors/GPUCommandEncoderDescriptor.h +1 -1
  151. package/cpp/rnwgpu/api/descriptors/GPUComputePassDescriptor.h +1 -1
  152. package/cpp/rnwgpu/api/descriptors/GPUComputePassTimestampWrites.h +1 -1
  153. package/cpp/rnwgpu/api/descriptors/GPUComputePipelineDescriptor.h +1 -1
  154. package/cpp/rnwgpu/api/descriptors/GPUDawnTogglesDescriptor.h +1 -1
  155. package/cpp/rnwgpu/api/descriptors/GPUDepthStencilState.h +1 -1
  156. package/cpp/rnwgpu/api/descriptors/GPUDeviceDescriptor.h +1 -1
  157. package/cpp/rnwgpu/api/descriptors/GPUExternalTextureBindingLayout.h +1 -1
  158. package/cpp/rnwgpu/api/descriptors/GPUExternalTextureDescriptor.h +1 -1
  159. package/cpp/rnwgpu/api/descriptors/GPUFragmentState.h +1 -1
  160. package/cpp/rnwgpu/api/descriptors/GPUImageCopyBuffer.h +1 -1
  161. package/cpp/rnwgpu/api/descriptors/GPUImageCopyExternalImage.h +1 -1
  162. package/cpp/rnwgpu/api/descriptors/GPUImageCopyTexture.h +1 -1
  163. package/cpp/rnwgpu/api/descriptors/GPUImageCopyTextureTagged.h +1 -1
  164. package/cpp/rnwgpu/api/descriptors/GPUImageDataLayout.h +1 -1
  165. package/cpp/rnwgpu/api/descriptors/GPUMultisampleState.h +1 -1
  166. package/cpp/rnwgpu/api/descriptors/GPUPipelineLayoutDescriptor.h +1 -1
  167. package/cpp/rnwgpu/api/descriptors/GPUPrimitiveState.h +1 -1
  168. package/cpp/rnwgpu/api/descriptors/GPUProgrammableStage.h +1 -1
  169. package/cpp/rnwgpu/api/descriptors/GPUQuerySetDescriptor.h +1 -1
  170. package/cpp/rnwgpu/api/descriptors/GPUQueueDescriptor.h +1 -1
  171. package/cpp/rnwgpu/api/descriptors/GPURenderBundleDescriptor.h +1 -1
  172. package/cpp/rnwgpu/api/descriptors/GPURenderBundleEncoderDescriptor.h +1 -1
  173. package/cpp/rnwgpu/api/descriptors/GPURenderPassColorAttachment.h +1 -1
  174. package/cpp/rnwgpu/api/descriptors/GPURenderPassDepthStencilAttachment.h +1 -1
  175. package/cpp/rnwgpu/api/descriptors/GPURenderPassDescriptor.h +1 -1
  176. package/cpp/rnwgpu/api/descriptors/GPURenderPassTimestampWrites.h +1 -1
  177. package/cpp/rnwgpu/api/descriptors/GPURenderPipelineDescriptor.h +1 -1
  178. package/cpp/rnwgpu/api/descriptors/GPURequestAdapterOptions.h +1 -1
  179. package/cpp/rnwgpu/api/descriptors/GPUSamplerBindingLayout.h +1 -1
  180. package/cpp/rnwgpu/api/descriptors/GPUSamplerDescriptor.h +1 -1
  181. package/cpp/rnwgpu/api/descriptors/GPUShaderModuleCompilationHint.h +1 -1
  182. package/cpp/rnwgpu/api/descriptors/GPUShaderModuleDescriptor.h +1 -1
  183. package/cpp/rnwgpu/api/descriptors/GPUSharedFenceDescriptor.h +1 -1
  184. package/cpp/rnwgpu/api/descriptors/GPUSharedFenceState.h +1 -1
  185. package/cpp/rnwgpu/api/descriptors/GPUSharedTextureMemoryDescriptor.h +1 -1
  186. package/cpp/rnwgpu/api/descriptors/GPUStencilFaceState.h +1 -1
  187. package/cpp/rnwgpu/api/descriptors/GPUStorageTextureBindingLayout.h +1 -1
  188. package/cpp/rnwgpu/api/descriptors/GPUTextureBindingLayout.h +1 -1
  189. package/cpp/rnwgpu/api/descriptors/GPUTextureDescriptor.h +1 -1
  190. package/cpp/rnwgpu/api/descriptors/GPUTextureViewDescriptor.h +1 -1
  191. package/cpp/rnwgpu/api/descriptors/GPUUncapturedErrorEventInit.h +1 -1
  192. package/cpp/rnwgpu/api/descriptors/GPUVertexAttribute.h +1 -1
  193. package/cpp/rnwgpu/api/descriptors/GPUVertexBufferLayout.h +1 -1
  194. package/cpp/rnwgpu/api/descriptors/GPUVertexState.h +1 -1
  195. package/cpp/rnwgpu/api/descriptors/Unions.h +1 -1
  196. package/cpp/rnwgpu/async/AsyncTaskHandle.cpp +20 -21
  197. package/cpp/rnwgpu/async/RuntimeContext.cpp +5 -0
  198. package/cpp/rnwgpu/async/RuntimeContext.h +15 -2
  199. package/lib/commonjs/external/reanimated/renderHelpers.d.ts +15 -0
  200. package/lib/commonjs/external/reanimated/renderHelpers.js +30 -1
  201. package/lib/commonjs/external/reanimated/renderHelpers.js.map +1 -1
  202. package/lib/commonjs/skia/NativeSetup.js +4 -0
  203. package/lib/commonjs/skia/NativeSetup.js.map +1 -1
  204. package/lib/commonjs/skia/SkiaWorkletSerialization.d.ts +1 -0
  205. package/lib/commonjs/skia/SkiaWorkletSerialization.js +66 -0
  206. package/lib/commonjs/skia/SkiaWorkletSerialization.js.map +1 -0
  207. package/lib/commonjs/sksg/Container.native.js +20 -1
  208. package/lib/commonjs/sksg/Container.native.js.map +1 -1
  209. package/lib/commonjs/views/WebGPUCanvas.d.ts +1 -0
  210. package/lib/commonjs/views/WebGPUCanvas.js +13 -0
  211. package/lib/commonjs/views/WebGPUCanvas.js.map +1 -1
  212. package/lib/module/external/reanimated/renderHelpers.d.ts +15 -0
  213. package/lib/module/external/reanimated/renderHelpers.js +29 -0
  214. package/lib/module/external/reanimated/renderHelpers.js.map +1 -1
  215. package/lib/module/skia/NativeSetup.js +4 -0
  216. package/lib/module/skia/NativeSetup.js.map +1 -1
  217. package/lib/module/skia/SkiaWorkletSerialization.d.ts +1 -0
  218. package/lib/module/skia/SkiaWorkletSerialization.js +59 -0
  219. package/lib/module/skia/SkiaWorkletSerialization.js.map +1 -0
  220. package/lib/module/sksg/Container.native.js +21 -2
  221. package/lib/module/sksg/Container.native.js.map +1 -1
  222. package/lib/module/views/WebGPUCanvas.d.ts +1 -0
  223. package/lib/module/views/WebGPUCanvas.js +14 -1
  224. package/lib/module/views/WebGPUCanvas.js.map +1 -1
  225. package/lib/typescript/lib/commonjs/external/reanimated/renderHelpers.d.ts +2 -0
  226. package/lib/typescript/lib/commonjs/skia/SkiaWorkletSerialization.d.ts +2 -0
  227. package/lib/typescript/lib/module/external/reanimated/renderHelpers.d.ts +15 -0
  228. package/lib/typescript/lib/module/skia/SkiaWorkletSerialization.d.ts +1 -0
  229. package/lib/typescript/src/external/reanimated/renderHelpers.d.ts +15 -0
  230. package/lib/typescript/src/skia/SkiaWorkletSerialization.d.ts +1 -0
  231. package/lib/typescript/src/views/WebGPUCanvas.d.ts +1 -0
  232. package/package.json +12 -8
  233. package/react-native-skia.podspec +1 -2
  234. package/src/external/reanimated/renderHelpers.ts +30 -0
  235. package/src/skia/NativeSetup.ts +5 -0
  236. package/src/skia/SkiaWorkletSerialization.ts +67 -0
  237. package/src/sksg/Container.native.ts +40 -2
  238. package/src/views/WebGPUCanvas.tsx +17 -1
  239. package/cpp/api/JsiSkHostObjects.h +0 -257
  240. package/cpp/dawn/include/dawn/dawn_proc.h +0 -53
  241. package/cpp/dawn/include/dawn/dawn_proc_table.h +0 -330
  242. package/cpp/dawn/include/dawn/dawn_thread_dispatch_proc.h +0 -47
  243. package/cpp/dawn/include/dawn/dawn_version.h +0 -41
  244. package/cpp/dawn/include/dawn/native/D3D11Backend.h +0 -65
  245. package/cpp/dawn/include/dawn/native/D3D12Backend.h +0 -86
  246. package/cpp/dawn/include/dawn/native/D3DBackend.h +0 -56
  247. package/cpp/dawn/include/dawn/native/DawnNative.h +0 -369
  248. package/cpp/dawn/include/dawn/native/MetalBackend.h +0 -56
  249. package/cpp/dawn/include/dawn/native/NullBackend.h +0 -39
  250. package/cpp/dawn/include/dawn/native/OpenGLBackend.h +0 -89
  251. package/cpp/dawn/include/dawn/native/VulkanBackend.h +0 -183
  252. package/cpp/dawn/include/dawn/native/WebGPUBackend.h +0 -49
  253. package/cpp/dawn/include/dawn/native/dawn_native_export.h +0 -49
  254. package/cpp/dawn/include/dawn/platform/DawnPlatform.h +0 -210
  255. package/cpp/dawn/include/dawn/platform/dawn_platform_export.h +0 -49
  256. package/cpp/dawn/include/dawn/replay/Replay.h +0 -99
  257. package/cpp/dawn/include/dawn/replay/dawn_replay_export.h +0 -49
  258. package/cpp/dawn/include/dawn/webgpu_cpp_print.h +0 -2844
  259. package/cpp/dawn/include/tint/tint.h +0 -90
  260. package/cpp/dawn/include/webgpu/webgpu.h +0 -4987
  261. package/cpp/dawn/include/webgpu/webgpu_cpp.h +0 -10080
  262. package/cpp/dawn/include/webgpu/webgpu_cpp_chained_struct.h +0 -57
  263. package/cpp/dawn/include/webgpu/webgpu_enum_class_bitmasks.h +0 -161
  264. package/cpp/dawn/include/webgpu/webgpu_glfw.h +0 -88
  265. package/cpp/jsi/JsiHostObject.cpp +0 -137
  266. package/cpp/jsi/JsiHostObject.h +0 -385
  267. package/cpp/skia/src/gpu/graphite/ContextOptionsPriv.h +0 -45
  268. package/cpp/skia/src/gpu/graphite/ResourceTypes.h +0 -360
  269. package/cpp/skia/src/gpu/graphite/TextureProxyView.h +0 -105
  270. package/libs/.graphite +0 -1
  271. /package/cpp/{jsi2 → jsi}/JSIConverter.h +0 -0
  272. /package/cpp/{jsi2 → jsi}/Promise.cpp +0 -0
  273. /package/cpp/{jsi2 → jsi}/Promise.h +0 -0
@@ -4,7 +4,7 @@
4
4
 
5
5
  #include "rnskia/RNSkPlatformContext.h"
6
6
 
7
- #include "JsiSkHostObjects.h"
7
+ #include "JsiSkNativeObjects.h"
8
8
 
9
9
  #ifdef SK_GRAPHITE
10
10
  #include "rnskia/RNDawnContext.h"
@@ -67,11 +67,11 @@ namespace RNSkia {
67
67
 
68
68
  namespace jsi = facebook::jsi;
69
69
 
70
- class JsiSkApi : public JsiSkHostObject {
70
+ class JsiSkApi : public JsiSkNativeObject<JsiSkApi> {
71
71
  public:
72
- size_t getMemoryPressure() const override { return 8192; }
72
+ static constexpr const char *CLASS_NAME = "Api";
73
73
 
74
- std::string getObjectType() const override { return "JsiSkApi"; }
74
+ size_t getMemoryPressure() override { return 8192; }
75
75
 
76
76
  /**
77
77
  * Constructs the Skia Api object that can be installed into a runtime
@@ -79,104 +79,258 @@ public:
79
79
  * @param context Platform context
80
80
  */
81
81
  explicit JsiSkApi(const std::shared_ptr<RNSkPlatformContext> &context)
82
- : JsiSkHostObject(context) {
82
+ : JsiSkNativeObject<JsiSkApi>(context),
83
+ _svgFactory(std::make_shared<JsiSkSVGFactory>(context)),
84
+ _imageFactory(std::make_shared<JsiSkImageFactory>(context)),
85
+ _animatedImageFactory(
86
+ std::make_shared<JsiSkAnimatedImageFactory>(context)),
87
+ _typefaceFactory(std::make_shared<JsiSkTypefaceFactory>(context)),
88
+ _dataFactory(std::make_shared<JsiSkDataFactory>(context)),
89
+ _imageFilterFactory(std::make_shared<JsiSkImageFilterFactory>(context)),
90
+ _pathEffectFactory(std::make_shared<JsiSkPathEffectFactory>(context)),
91
+ _pathFactory(std::make_shared<JsiSkPathFactory>(context)),
92
+ _pathBuilderFactory(std::make_shared<JsiSkPathBuilderFactory>(context)),
93
+ _colorFilterFactory(std::make_shared<JsiSkColorFilterFactory>(context)),
94
+ _maskFilterFactory(std::make_shared<JsiSkMaskFilterFactory>(context)),
95
+ _runtimeEffectFactory(
96
+ std::make_shared<JsiSkRuntimeEffectFactory>(context)),
97
+ _shaderFactory(std::make_shared<JsiSkShaderFactory>(context)),
98
+ _textBlobFactory(std::make_shared<JsiSkTextBlobFactory>(context)),
99
+ _surfaceFactory(std::make_shared<JsiSkSurfaceFactory>(context)),
100
+ _pictureFactory(std::make_shared<JsiSkPictureFactory>(context)),
101
+ _fontMgrFactory(std::make_shared<JsiSkFontMgrFactory>(context)),
102
+ _skottieFactory(std::make_shared<JsiSkottieFactory>(context)),
103
+ _typefaceFontProviderFactory(
104
+ std::make_shared<JsiSkTypefaceFontProviderFactory>(context)),
105
+ _paragraphBuilderFactory(
106
+ std::make_shared<JsiSkParagraphBuilderFactory>(context)),
107
+ _nativeBufferFactory(
108
+ std::make_shared<JsiNativeBufferFactory>(context)) {
83
109
  // We create the system font manager eagerly since it has proven to be too
84
110
  // slow to do it on demand
85
111
  JsiSkFontMgrFactory::getFontMgr(getContext());
86
- installFunction("Video", JsiVideo::createCtor(context));
87
- installFunction("Context", JsiSkiaContext::createCtor(context));
88
- installFunction("Font", JsiSkFont::createCtor(context));
89
- installFunction("Paint", JsiSkPaint::createCtor(context));
90
- installFunction("RSXform", JsiSkRSXform::createCtor(context));
91
- installFunction("RSXformFromRadians",
92
- JsiSkRSXform::createCtorFromRadians(context));
93
- installFunction("Matrix", JsiSkMatrix::createCtor(context));
94
- installFunction("XYWHRect", JsiSkRect::createCtor(context));
95
- installFunction("RRectXY", JsiSkRRect::createCtor(context));
96
- installFunction("Point", JsiSkPoint::createCtor(context));
97
- installFunction("RuntimeShaderBuilder",
98
- JsiSkRuntimeShaderBuilder::createCtor(context));
99
- installFunction("ContourMeasureIter",
100
- JsiSkContourMeasureIter::createCtor(context));
101
- installFunction("MakeVertices", JsiSkVertices::createCtor(context));
102
- installFunction("PictureRecorder",
103
- JsiSkPictureRecorder::createCtor(context));
104
- installFunction("Color", JsiSkColor::createCtor());
105
-
106
- installReadonlyProperty("SVG", std::make_shared<JsiSkSVGFactory>(context));
107
- installReadonlyProperty("Image",
108
- std::make_shared<JsiSkImageFactory>(context));
109
- installReadonlyProperty(
110
- "AnimatedImage", std::make_shared<JsiSkAnimatedImageFactory>(context));
111
- installReadonlyProperty("Typeface",
112
- std::make_shared<JsiSkTypefaceFactory>(context));
113
- installReadonlyProperty("Data",
114
- std::make_shared<JsiSkDataFactory>(context));
115
- installReadonlyProperty("ImageFilter",
116
- std::make_shared<JsiSkImageFilterFactory>(context));
117
- installReadonlyProperty("PathEffect",
118
- std::make_shared<JsiSkPathEffectFactory>(context));
119
- installReadonlyProperty("Path",
120
- std::make_shared<JsiSkPathFactory>(context));
121
- installReadonlyProperty("PathBuilder",
122
- std::make_shared<JsiSkPathBuilderFactory>(context));
123
- installReadonlyProperty("ColorFilter",
124
- std::make_shared<JsiSkColorFilterFactory>(context));
125
- installReadonlyProperty("MaskFilter",
126
- std::make_shared<JsiSkMaskFilterFactory>(context));
127
- installReadonlyProperty(
128
- "RuntimeEffect", std::make_shared<JsiSkRuntimeEffectFactory>(context));
129
- installReadonlyProperty("Shader",
130
- std::make_shared<JsiSkShaderFactory>(context));
131
- installReadonlyProperty("TextBlob",
132
- std::make_shared<JsiSkTextBlobFactory>(context));
133
- installReadonlyProperty("Surface",
134
- std::make_shared<JsiSkSurfaceFactory>(context));
135
- installReadonlyProperty("Picture",
136
- std::make_shared<JsiSkPictureFactory>(context));
137
- installReadonlyProperty("FontMgr",
138
- std::make_shared<JsiSkFontMgrFactory>(context));
139
- installReadonlyProperty("Skottie",
140
- std::make_shared<JsiSkottieFactory>(context));
141
- installReadonlyProperty(
142
- "TypefaceFontProvider",
143
- std::make_shared<JsiSkTypefaceFontProviderFactory>(context));
144
-
145
- installReadonlyProperty(
146
- "ParagraphBuilder",
147
- std::make_shared<JsiSkParagraphBuilderFactory>(context));
148
-
149
- installReadonlyProperty("NativeBuffer",
150
- std::make_shared<JsiNativeBufferFactory>(context));
151
-
152
- installFunction("Recorder", JsiRecorder::createCtor(context));
153
-
154
- installFunction(
155
- "hasDevice", JSI_HOST_FUNCTION_LAMBDA {
112
+ }
113
+
114
+ // Constructor functions: each delegates to the class's createCtor host
115
+ // function using the platform context resolved from native state, so the
116
+ // prototype stays context-free and can be installed on any runtime.
117
+ JSI_HOST_FUNCTION(Video) {
118
+ return JsiVideo::createCtor(getContext())(runtime, thisValue, arguments,
119
+ count);
120
+ }
121
+ JSI_HOST_FUNCTION(Context) {
122
+ return JsiSkiaContext::createCtor(getContext())(runtime, thisValue,
123
+ arguments, count);
124
+ }
125
+ JSI_HOST_FUNCTION(Font) {
126
+ return JsiSkFont::createCtor(getContext())(runtime, thisValue, arguments,
127
+ count);
128
+ }
129
+ JSI_HOST_FUNCTION(Paint) {
130
+ return JsiSkPaint::createCtor(getContext())(runtime, thisValue, arguments,
131
+ count);
132
+ }
133
+ JSI_HOST_FUNCTION(RSXform) {
134
+ return JsiSkRSXform::createCtor(getContext())(runtime, thisValue, arguments,
135
+ count);
136
+ }
137
+ JSI_HOST_FUNCTION(RSXformFromRadians) {
138
+ return JsiSkRSXform::createCtorFromRadians(getContext())(runtime, thisValue,
139
+ arguments, count);
140
+ }
141
+ JSI_HOST_FUNCTION(Matrix) {
142
+ return JsiSkMatrix::createCtor(getContext())(runtime, thisValue, arguments,
143
+ count);
144
+ }
145
+ JSI_HOST_FUNCTION(XYWHRect) {
146
+ return JsiSkRect::createCtor(getContext())(runtime, thisValue, arguments,
147
+ count);
148
+ }
149
+ JSI_HOST_FUNCTION(RRectXY) {
150
+ return JsiSkRRect::createCtor(getContext())(runtime, thisValue, arguments,
151
+ count);
152
+ }
153
+ JSI_HOST_FUNCTION(Point) {
154
+ return JsiSkPoint::createCtor(getContext())(runtime, thisValue, arguments,
155
+ count);
156
+ }
157
+ JSI_HOST_FUNCTION(RuntimeShaderBuilder) {
158
+ return JsiSkRuntimeShaderBuilder::createCtor(getContext())(
159
+ runtime, thisValue, arguments, count);
160
+ }
161
+ JSI_HOST_FUNCTION(ContourMeasureIter) {
162
+ return JsiSkContourMeasureIter::createCtor(getContext())(runtime, thisValue,
163
+ arguments, count);
164
+ }
165
+ JSI_HOST_FUNCTION(MakeVertices) {
166
+ return JsiSkVertices::createCtor(getContext())(runtime, thisValue,
167
+ arguments, count);
168
+ }
169
+ JSI_HOST_FUNCTION(PictureRecorder) {
170
+ return JsiSkPictureRecorder::createCtor(getContext())(runtime, thisValue,
171
+ arguments, count);
172
+ }
173
+ JSI_HOST_FUNCTION(Color) {
174
+ return JsiSkColor::createCtor()(runtime, thisValue, arguments, count);
175
+ }
176
+ JSI_HOST_FUNCTION(Recorder) {
177
+ return JsiRecorder::createCtor(getContext())(runtime, thisValue, arguments,
178
+ count);
179
+ }
180
+
181
+ JSI_HOST_FUNCTION(hasDevice) {
156
182
  #ifdef SK_GRAPHITE
157
- return jsi::Value(true);
183
+ return jsi::Value(true);
158
184
  #else
159
- return jsi::Value(false);
185
+ return jsi::Value(false);
160
186
  #endif
161
- });
187
+ }
162
188
 
163
- installFunction(
164
- "getDevice", JSI_HOST_FUNCTION_LAMBDA {
189
+ JSI_HOST_FUNCTION(getDevice) {
165
190
  #ifdef SK_GRAPHITE
166
- auto &dawnContext = DawnContext::getInstance();
167
- // Per-runtime context: async ops on this device resolve on the calling
168
- // runtime's own thread (via its ProcessEvents pump).
169
- auto context = rnwgpu::async::RuntimeContext::getOrCreate(
170
- runtime, dawnContext.getWGPUInstance());
171
- auto device = std::make_shared<rnwgpu::GPUDevice>(
172
- dawnContext.getWGPUDevice(), context, "Skia Device");
173
- return rnwgpu::GPUDevice::create(runtime, device);
191
+ auto &dawnContext = DawnContext::getInstance();
192
+ // Per-runtime context: async ops on this device resolve on the calling
193
+ // runtime's own thread (via its ProcessEvents pump).
194
+ auto context = rnwgpu::async::RuntimeContext::getOrCreate(
195
+ runtime, dawnContext.getWGPUInstance());
196
+ auto device = std::make_shared<rnwgpu::GPUDevice>(
197
+ dawnContext.getWGPUDevice(), context, "Skia Device");
198
+ return rnwgpu::GPUDevice::create(runtime, device);
174
199
  #else
175
- throw jsi::JSError(runtime,
176
- "getDevice() is only available with the Graphite "
177
- "backend. Rebuild with SK_GRAPHITE enabled.");
200
+ throw jsi::JSError(runtime,
201
+ "getDevice() is only available with the Graphite "
202
+ "backend. Rebuild with SK_GRAPHITE enabled.");
178
203
  #endif
179
- });
180
204
  }
205
+
206
+ // Factory properties: like the legacy HostObject implementation, each
207
+ // property access returns a fresh JS wrapper around the shared factory
208
+ // instance.
209
+ JSI_PROPERTY_GET(SVG) { return makeJsiObject(runtime, _svgFactory); }
210
+ JSI_PROPERTY_GET(Image) { return makeJsiObject(runtime, _imageFactory); }
211
+ JSI_PROPERTY_GET(AnimatedImage) {
212
+ return makeJsiObject(runtime, _animatedImageFactory);
213
+ }
214
+ JSI_PROPERTY_GET(Typeface) {
215
+ return makeJsiObject(runtime, _typefaceFactory);
216
+ }
217
+ JSI_PROPERTY_GET(Data) { return makeJsiObject(runtime, _dataFactory); }
218
+ JSI_PROPERTY_GET(ImageFilter) {
219
+ return makeJsiObject(runtime, _imageFilterFactory);
220
+ }
221
+ JSI_PROPERTY_GET(PathEffect) {
222
+ return makeJsiObject(runtime, _pathEffectFactory);
223
+ }
224
+ JSI_PROPERTY_GET(Path) { return makeJsiObject(runtime, _pathFactory); }
225
+ JSI_PROPERTY_GET(PathBuilder) {
226
+ return makeJsiObject(runtime, _pathBuilderFactory);
227
+ }
228
+ JSI_PROPERTY_GET(ColorFilter) {
229
+ return makeJsiObject(runtime, _colorFilterFactory);
230
+ }
231
+ JSI_PROPERTY_GET(MaskFilter) {
232
+ return makeJsiObject(runtime, _maskFilterFactory);
233
+ }
234
+ JSI_PROPERTY_GET(RuntimeEffect) {
235
+ return makeJsiObject(runtime, _runtimeEffectFactory);
236
+ }
237
+ JSI_PROPERTY_GET(Shader) { return makeJsiObject(runtime, _shaderFactory); }
238
+ JSI_PROPERTY_GET(TextBlob) {
239
+ return makeJsiObject(runtime, _textBlobFactory);
240
+ }
241
+ JSI_PROPERTY_GET(Surface) { return makeJsiObject(runtime, _surfaceFactory); }
242
+ JSI_PROPERTY_GET(Picture) { return makeJsiObject(runtime, _pictureFactory); }
243
+ JSI_PROPERTY_GET(FontMgr) { return makeJsiObject(runtime, _fontMgrFactory); }
244
+ JSI_PROPERTY_GET(Skottie) { return makeJsiObject(runtime, _skottieFactory); }
245
+ JSI_PROPERTY_GET(TypefaceFontProvider) {
246
+ return makeJsiObject(runtime, _typefaceFontProviderFactory);
247
+ }
248
+ JSI_PROPERTY_GET(ParagraphBuilder) {
249
+ return makeJsiObject(runtime, _paragraphBuilderFactory);
250
+ }
251
+ JSI_PROPERTY_GET(NativeBuffer) {
252
+ return makeJsiObject(runtime, _nativeBufferFactory);
253
+ }
254
+
255
+ static void definePrototype(jsi::Runtime &runtime, jsi::Object &prototype) {
256
+ installHostMethod(runtime, prototype, "Video", &JsiSkApi::Video);
257
+ installHostMethod(runtime, prototype, "Context", &JsiSkApi::Context);
258
+ installHostMethod(runtime, prototype, "Font", &JsiSkApi::Font);
259
+ installHostMethod(runtime, prototype, "Paint", &JsiSkApi::Paint);
260
+ installHostMethod(runtime, prototype, "RSXform", &JsiSkApi::RSXform);
261
+ installHostMethod(runtime, prototype, "RSXformFromRadians",
262
+ &JsiSkApi::RSXformFromRadians);
263
+ installHostMethod(runtime, prototype, "Matrix", &JsiSkApi::Matrix);
264
+ installHostMethod(runtime, prototype, "XYWHRect", &JsiSkApi::XYWHRect);
265
+ installHostMethod(runtime, prototype, "RRectXY", &JsiSkApi::RRectXY);
266
+ installHostMethod(runtime, prototype, "Point", &JsiSkApi::Point);
267
+ installHostMethod(runtime, prototype, "RuntimeShaderBuilder",
268
+ &JsiSkApi::RuntimeShaderBuilder);
269
+ installHostMethod(runtime, prototype, "ContourMeasureIter",
270
+ &JsiSkApi::ContourMeasureIter);
271
+ installHostMethod(runtime, prototype, "MakeVertices",
272
+ &JsiSkApi::MakeVertices);
273
+ installHostMethod(runtime, prototype, "PictureRecorder",
274
+ &JsiSkApi::PictureRecorder);
275
+ installHostMethod(runtime, prototype, "Color", &JsiSkApi::Color);
276
+ installHostMethod(runtime, prototype, "Recorder", &JsiSkApi::Recorder);
277
+ installHostMethod(runtime, prototype, "hasDevice", &JsiSkApi::hasDevice);
278
+ installHostMethod(runtime, prototype, "getDevice", &JsiSkApi::getDevice);
279
+ installHostGetter(runtime, prototype, "SVG", &JsiSkApi::get_SVG);
280
+ installHostGetter(runtime, prototype, "Image", &JsiSkApi::get_Image);
281
+ installHostGetter(runtime, prototype, "AnimatedImage",
282
+ &JsiSkApi::get_AnimatedImage);
283
+ installHostGetter(runtime, prototype, "Typeface", &JsiSkApi::get_Typeface);
284
+ installHostGetter(runtime, prototype, "Data", &JsiSkApi::get_Data);
285
+ installHostGetter(runtime, prototype, "ImageFilter",
286
+ &JsiSkApi::get_ImageFilter);
287
+ installHostGetter(runtime, prototype, "PathEffect",
288
+ &JsiSkApi::get_PathEffect);
289
+ installHostGetter(runtime, prototype, "Path", &JsiSkApi::get_Path);
290
+ installHostGetter(runtime, prototype, "PathBuilder",
291
+ &JsiSkApi::get_PathBuilder);
292
+ installHostGetter(runtime, prototype, "ColorFilter",
293
+ &JsiSkApi::get_ColorFilter);
294
+ installHostGetter(runtime, prototype, "MaskFilter",
295
+ &JsiSkApi::get_MaskFilter);
296
+ installHostGetter(runtime, prototype, "RuntimeEffect",
297
+ &JsiSkApi::get_RuntimeEffect);
298
+ installHostGetter(runtime, prototype, "Shader", &JsiSkApi::get_Shader);
299
+ installHostGetter(runtime, prototype, "TextBlob", &JsiSkApi::get_TextBlob);
300
+ installHostGetter(runtime, prototype, "Surface", &JsiSkApi::get_Surface);
301
+ installHostGetter(runtime, prototype, "Picture", &JsiSkApi::get_Picture);
302
+ installHostGetter(runtime, prototype, "FontMgr", &JsiSkApi::get_FontMgr);
303
+ installHostGetter(runtime, prototype, "Skottie", &JsiSkApi::get_Skottie);
304
+ installHostGetter(runtime, prototype, "TypefaceFontProvider",
305
+ &JsiSkApi::get_TypefaceFontProvider);
306
+ installHostGetter(runtime, prototype, "ParagraphBuilder",
307
+ &JsiSkApi::get_ParagraphBuilder);
308
+ installHostGetter(runtime, prototype, "NativeBuffer",
309
+ &JsiSkApi::get_NativeBuffer);
310
+ }
311
+
312
+ private:
313
+ std::shared_ptr<JsiSkSVGFactory> _svgFactory;
314
+ std::shared_ptr<JsiSkImageFactory> _imageFactory;
315
+ std::shared_ptr<JsiSkAnimatedImageFactory> _animatedImageFactory;
316
+ std::shared_ptr<JsiSkTypefaceFactory> _typefaceFactory;
317
+ std::shared_ptr<JsiSkDataFactory> _dataFactory;
318
+ std::shared_ptr<JsiSkImageFilterFactory> _imageFilterFactory;
319
+ std::shared_ptr<JsiSkPathEffectFactory> _pathEffectFactory;
320
+ std::shared_ptr<JsiSkPathFactory> _pathFactory;
321
+ std::shared_ptr<JsiSkPathBuilderFactory> _pathBuilderFactory;
322
+ std::shared_ptr<JsiSkColorFilterFactory> _colorFilterFactory;
323
+ std::shared_ptr<JsiSkMaskFilterFactory> _maskFilterFactory;
324
+ std::shared_ptr<JsiSkRuntimeEffectFactory> _runtimeEffectFactory;
325
+ std::shared_ptr<JsiSkShaderFactory> _shaderFactory;
326
+ std::shared_ptr<JsiSkTextBlobFactory> _textBlobFactory;
327
+ std::shared_ptr<JsiSkSurfaceFactory> _surfaceFactory;
328
+ std::shared_ptr<JsiSkPictureFactory> _pictureFactory;
329
+ std::shared_ptr<JsiSkFontMgrFactory> _fontMgrFactory;
330
+ std::shared_ptr<JsiSkottieFactory> _skottieFactory;
331
+ std::shared_ptr<JsiSkTypefaceFontProviderFactory>
332
+ _typefaceFontProviderFactory;
333
+ std::shared_ptr<JsiSkParagraphBuilderFactory> _paragraphBuilderFactory;
334
+ std::shared_ptr<JsiNativeBufferFactory> _nativeBufferFactory;
181
335
  };
182
336
  } // namespace RNSkia
@@ -5,10 +5,10 @@
5
5
  #include <vector>
6
6
 
7
7
  #include "JsiSkFont.h"
8
- #include "JsiSkHostObjects.h"
9
8
  #include "JsiSkImage.h"
10
9
  #include "JsiSkImageInfo.h"
11
10
  #include "JsiSkMatrix.h"
11
+ #include "JsiSkNativeObjects.h"
12
12
  #include "JsiSkPaint.h"
13
13
  #include "JsiSkPath.h"
14
14
  #include "JsiSkPicture.h"
@@ -49,8 +49,10 @@ namespace RNSkia {
49
49
 
50
50
  namespace jsi = facebook::jsi;
51
51
 
52
- class JsiSkCanvas : public JsiSkHostObject {
52
+ class JsiSkCanvas : public JsiSkNativeObject<JsiSkCanvas> {
53
53
  public:
54
+ static constexpr const char *CLASS_NAME = "Canvas";
55
+
54
56
  JSI_HOST_FUNCTION(drawPaint) {
55
57
  auto paint = JsiSkPaint::fromValue(runtime, arguments[0]);
56
58
  _canvas->drawPaint(*paint);
@@ -246,10 +248,8 @@ public:
246
248
  }
247
249
 
248
250
  JSI_HOST_FUNCTION(getTotalMatrix) {
249
- auto matrix =
250
- std::make_shared<JsiSkMatrix>(getContext(), _canvas->getTotalMatrix());
251
- return JSI_CREATE_HOST_OBJECT_WITH_MEMORY_PRESSURE(runtime, matrix,
252
- getContext());
251
+ return makeJsiObject(runtime, std::make_shared<JsiSkMatrix>(
252
+ getContext(), _canvas->getTotalMatrix()));
253
253
  }
254
254
 
255
255
  JSI_HOST_FUNCTION(drawPoints) {
@@ -651,9 +651,10 @@ public:
651
651
  #if defined(SK_GRAPHITE)
652
652
  // Graphite records draws lazily and offers no synchronous GPU readback. If
653
653
  // this canvas belongs to a surface, snap & submit its recording, snapshot
654
- // it to a CPU raster image and read from that (mirroring makeImageSnapshot).
655
- // A canvas without an owning surface (e.g. a picture-recording canvas) has
656
- // no texture to read back, so fall through to the raster canvas read below.
654
+ // it to a CPU raster image and read from that (mirroring
655
+ // makeImageSnapshot). A canvas without an owning surface (e.g. a
656
+ // picture-recording canvas) has no texture to read back, so fall through to
657
+ // the raster canvas read below.
657
658
  if (_surface) {
658
659
  // Snapshot first: makeImageSnapshot records a copy task into the recorder
659
660
  // that must be submitted before the texture can be read back (this is the
@@ -663,8 +664,8 @@ public:
663
664
  DawnContext::getInstance().submitRecording(recorder->snap().get());
664
665
  }
665
666
  auto raster = DawnContext::getInstance().MakeRasterImage(snapshot);
666
- if (!raster ||
667
- !raster->readPixels(nullptr, *info, bfrPtr, bytesPerRow, srcX, srcY)) {
667
+ if (!raster || !raster->readPixels(nullptr, *info, bfrPtr, bytesPerRow,
668
+ srcX, srcY)) {
668
669
  return jsi::Value::null();
669
670
  }
670
671
  return dest;
@@ -677,55 +678,72 @@ public:
677
678
  return dest;
678
679
  }
679
680
 
680
- JSI_EXPORT_FUNCTIONS(JSI_EXPORT_FUNC(JsiSkCanvas, drawPaint),
681
- JSI_EXPORT_FUNC(JsiSkCanvas, drawLine),
682
- JSI_EXPORT_FUNC(JsiSkCanvas, drawRect),
683
- JSI_EXPORT_FUNC(JsiSkCanvas, drawImage),
684
- JSI_EXPORT_FUNC(JsiSkCanvas, drawImageRect),
685
- JSI_EXPORT_FUNC(JsiSkCanvas, drawImageCubic),
686
- JSI_EXPORT_FUNC(JsiSkCanvas, drawImageOptions),
687
- JSI_EXPORT_FUNC(JsiSkCanvas, drawImageNine),
688
- JSI_EXPORT_FUNC(JsiSkCanvas, drawImageRectCubic),
689
- JSI_EXPORT_FUNC(JsiSkCanvas, drawImageRectOptions),
690
- JSI_EXPORT_FUNC(JsiSkCanvas, drawCircle),
691
- JSI_EXPORT_FUNC(JsiSkCanvas, drawArc),
692
- JSI_EXPORT_FUNC(JsiSkCanvas, drawRRect),
693
- JSI_EXPORT_FUNC(JsiSkCanvas, drawDRRect),
694
- JSI_EXPORT_FUNC(JsiSkCanvas, drawOval),
695
- JSI_EXPORT_FUNC(JsiSkCanvas, restoreToCount),
696
- JSI_EXPORT_FUNC(JsiSkCanvas, getSaveCount),
697
- JSI_EXPORT_FUNC(JsiSkCanvas, getTotalMatrix),
698
- JSI_EXPORT_FUNC(JsiSkCanvas, drawPoints),
699
- JSI_EXPORT_FUNC(JsiSkCanvas, drawPatch),
700
- JSI_EXPORT_FUNC(JsiSkCanvas, drawPath),
701
- JSI_EXPORT_FUNC(JsiSkCanvas, drawVertices),
702
- JSI_EXPORT_FUNC(JsiSkCanvas, drawText),
703
- JSI_EXPORT_FUNC(JsiSkCanvas, drawTextBlob),
704
- JSI_EXPORT_FUNC(JsiSkCanvas, drawGlyphs),
705
- JSI_EXPORT_FUNC(JsiSkCanvas, drawSvg),
706
- JSI_EXPORT_FUNC(JsiSkCanvas, clipPath),
707
- JSI_EXPORT_FUNC(JsiSkCanvas, clipRect),
708
- JSI_EXPORT_FUNC(JsiSkCanvas, clipRRect),
709
- JSI_EXPORT_FUNC(JsiSkCanvas, save),
710
- JSI_EXPORT_FUNC(JsiSkCanvas, saveLayer),
711
- JSI_EXPORT_FUNC(JsiSkCanvas, restore),
712
- JSI_EXPORT_FUNC(JsiSkCanvas, rotate),
713
- JSI_EXPORT_FUNC(JsiSkCanvas, translate),
714
- JSI_EXPORT_FUNC(JsiSkCanvas, scale),
715
- JSI_EXPORT_FUNC(JsiSkCanvas, skew),
716
- JSI_EXPORT_FUNC(JsiSkCanvas, drawColor),
717
- JSI_EXPORT_FUNC(JsiSkCanvas, clear),
718
- JSI_EXPORT_FUNC(JsiSkCanvas, concat),
719
- JSI_EXPORT_FUNC(JsiSkCanvas, drawPicture),
720
- JSI_EXPORT_FUNC(JsiSkCanvas, drawAtlas),
721
- JSI_EXPORT_FUNC(JsiSkCanvas, readPixels))
722
-
723
- size_t getMemoryPressure() const override { return 1024; }
724
-
725
- std::string getObjectType() const override { return "JsiSkCanvas"; }
681
+ static void definePrototype(jsi::Runtime &runtime, jsi::Object &prototype) {
682
+ installHostMethod(runtime, prototype, "drawPaint", &JsiSkCanvas::drawPaint);
683
+ installHostMethod(runtime, prototype, "drawLine", &JsiSkCanvas::drawLine);
684
+ installHostMethod(runtime, prototype, "drawRect", &JsiSkCanvas::drawRect);
685
+ installHostMethod(runtime, prototype, "drawImage", &JsiSkCanvas::drawImage);
686
+ installHostMethod(runtime, prototype, "drawImageRect",
687
+ &JsiSkCanvas::drawImageRect);
688
+ installHostMethod(runtime, prototype, "drawImageCubic",
689
+ &JsiSkCanvas::drawImageCubic);
690
+ installHostMethod(runtime, prototype, "drawImageOptions",
691
+ &JsiSkCanvas::drawImageOptions);
692
+ installHostMethod(runtime, prototype, "drawImageNine",
693
+ &JsiSkCanvas::drawImageNine);
694
+ installHostMethod(runtime, prototype, "drawImageRectCubic",
695
+ &JsiSkCanvas::drawImageRectCubic);
696
+ installHostMethod(runtime, prototype, "drawImageRectOptions",
697
+ &JsiSkCanvas::drawImageRectOptions);
698
+ installHostMethod(runtime, prototype, "drawCircle",
699
+ &JsiSkCanvas::drawCircle);
700
+ installHostMethod(runtime, prototype, "drawArc", &JsiSkCanvas::drawArc);
701
+ installHostMethod(runtime, prototype, "drawRRect", &JsiSkCanvas::drawRRect);
702
+ installHostMethod(runtime, prototype, "drawDRRect",
703
+ &JsiSkCanvas::drawDRRect);
704
+ installHostMethod(runtime, prototype, "drawOval", &JsiSkCanvas::drawOval);
705
+ installHostMethod(runtime, prototype, "restoreToCount",
706
+ &JsiSkCanvas::restoreToCount);
707
+ installHostMethod(runtime, prototype, "getSaveCount",
708
+ &JsiSkCanvas::getSaveCount);
709
+ installHostMethod(runtime, prototype, "getTotalMatrix",
710
+ &JsiSkCanvas::getTotalMatrix);
711
+ installHostMethod(runtime, prototype, "drawPoints",
712
+ &JsiSkCanvas::drawPoints);
713
+ installHostMethod(runtime, prototype, "drawPatch", &JsiSkCanvas::drawPatch);
714
+ installHostMethod(runtime, prototype, "drawPath", &JsiSkCanvas::drawPath);
715
+ installHostMethod(runtime, prototype, "drawVertices",
716
+ &JsiSkCanvas::drawVertices);
717
+ installHostMethod(runtime, prototype, "drawText", &JsiSkCanvas::drawText);
718
+ installHostMethod(runtime, prototype, "drawTextBlob",
719
+ &JsiSkCanvas::drawTextBlob);
720
+ installHostMethod(runtime, prototype, "drawGlyphs",
721
+ &JsiSkCanvas::drawGlyphs);
722
+ installHostMethod(runtime, prototype, "drawSvg", &JsiSkCanvas::drawSvg);
723
+ installHostMethod(runtime, prototype, "clipPath", &JsiSkCanvas::clipPath);
724
+ installHostMethod(runtime, prototype, "clipRect", &JsiSkCanvas::clipRect);
725
+ installHostMethod(runtime, prototype, "clipRRect", &JsiSkCanvas::clipRRect);
726
+ installHostMethod(runtime, prototype, "save", &JsiSkCanvas::save);
727
+ installHostMethod(runtime, prototype, "saveLayer", &JsiSkCanvas::saveLayer);
728
+ installHostMethod(runtime, prototype, "restore", &JsiSkCanvas::restore);
729
+ installHostMethod(runtime, prototype, "rotate", &JsiSkCanvas::rotate);
730
+ installHostMethod(runtime, prototype, "translate", &JsiSkCanvas::translate);
731
+ installHostMethod(runtime, prototype, "scale", &JsiSkCanvas::scale);
732
+ installHostMethod(runtime, prototype, "skew", &JsiSkCanvas::skew);
733
+ installHostMethod(runtime, prototype, "drawColor", &JsiSkCanvas::drawColor);
734
+ installHostMethod(runtime, prototype, "clear", &JsiSkCanvas::clear);
735
+ installHostMethod(runtime, prototype, "concat", &JsiSkCanvas::concat);
736
+ installHostMethod(runtime, prototype, "drawPicture",
737
+ &JsiSkCanvas::drawPicture);
738
+ installHostMethod(runtime, prototype, "drawAtlas", &JsiSkCanvas::drawAtlas);
739
+ installHostMethod(runtime, prototype, "readPixels",
740
+ &JsiSkCanvas::readPixels);
741
+ }
742
+
743
+ size_t getMemoryPressure() override { return 1024; }
726
744
 
727
745
  explicit JsiSkCanvas(std::shared_ptr<RNSkPlatformContext> context)
728
- : JsiSkHostObject(std::move(context)) {}
746
+ : JsiSkNativeObject<JsiSkCanvas>(std::move(context)) {}
729
747
 
730
748
  JsiSkCanvas(std::shared_ptr<RNSkPlatformContext> context, SkCanvas *canvas)
731
749
  : JsiSkCanvas(std::move(context)) {
@@ -6,7 +6,7 @@
6
6
 
7
7
  #include <jsi/jsi.h>
8
8
 
9
- #include "JsiSkHostObjects.h"
9
+ #include "JsiSkNativeObjects.h"
10
10
  #include "api/third_party/CSSColorParser.h"
11
11
 
12
12
  #pragma clang diagnostic push
@@ -20,11 +20,13 @@ namespace RNSkia {
20
20
 
21
21
  namespace jsi = facebook::jsi;
22
22
 
23
- class JsiSkColor : public RNJsi::JsiHostObject {
23
+ /**
24
+ * JsiSkColor is a pure utility class — colors are represented as
25
+ * Float32Arrays on the JS side, so there is no wrapper object.
26
+ */
27
+ class JsiSkColor {
24
28
  public:
25
- JsiSkColor() : JsiHostObject() {}
26
-
27
- ~JsiSkColor() override = default;
29
+ JsiSkColor() = default;
28
30
 
29
31
  static jsi::Object toValue(jsi::Runtime &runtime, SkColor color) {
30
32
  auto result = runtime.global()
@@ -1,6 +1,6 @@
1
1
  #pragma once
2
2
 
3
- #include "JsiSkHostObjects.h"
3
+ #include "JsiSkNativeObjects.h"
4
4
  #include <jsi/jsi.h>
5
5
  #include <memory>
6
6
  #include <utility>
@@ -16,19 +16,26 @@ namespace RNSkia {
16
16
 
17
17
  namespace jsi = facebook::jsi;
18
18
 
19
- class JsiSkColorFilter : public JsiSkWrappingSkPtrHostObject<SkColorFilter> {
19
+ class JsiSkColorFilter
20
+ : public JsiSkWrappingSkPtrNativeObject<JsiSkColorFilter, SkColorFilter> {
20
21
  public:
22
+ static constexpr const char *CLASS_NAME = "ColorFilter";
23
+
21
24
  JsiSkColorFilter(std::shared_ptr<RNSkPlatformContext> context,
22
25
  sk_sp<SkColorFilter> colorFilter)
23
- : JsiSkWrappingSkPtrHostObject<SkColorFilter>(std::move(context),
24
- std::move(colorFilter)) {}
26
+ : JsiSkWrappingSkPtrNativeObject<JsiSkColorFilter, SkColorFilter>(
27
+ std::move(context), std::move(colorFilter)) {}
25
28
 
26
- size_t getMemoryPressure() const override { return 2048; }
29
+ size_t getMemoryPressure() override { return 2048; }
27
30
 
28
- std::string getObjectType() const override { return "JsiSkColorFilter"; }
31
+ static sk_sp<SkColorFilter> fromValue(jsi::Runtime &runtime,
32
+ const jsi::Value &obj) {
33
+ return objectFromValue(runtime, obj);
34
+ }
29
35
 
30
- EXPORT_JSI_API_TYPENAME(JsiSkColorFilter, ColorFilter)
31
- JSI_EXPORT_FUNCTIONS(JSI_EXPORT_FUNC(JsiSkColorFilter, dispose))
36
+ static void definePrototype(jsi::Runtime &runtime, jsi::Object &prototype) {
37
+ installCommon(runtime, prototype);
38
+ }
32
39
  };
33
40
 
34
41
  } // namespace RNSkia