@shopify/react-native-skia 2.9.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 (220) hide show
  1. package/android/CMakeLists.txt +1 -5
  2. package/cpp/api/JsiNativeBuffer.h +15 -10
  3. package/cpp/api/JsiSkAnimatedImage.h +21 -19
  4. package/cpp/api/JsiSkAnimatedImageFactory.h +13 -14
  5. package/cpp/api/JsiSkApi.h +246 -92
  6. package/cpp/api/JsiSkCanvas.h +76 -58
  7. package/cpp/api/JsiSkColor.h +7 -5
  8. package/cpp/api/JsiSkColorFilter.h +15 -8
  9. package/cpp/api/JsiSkColorFilterFactory.h +45 -45
  10. package/cpp/api/JsiSkContourMeasure.h +24 -21
  11. package/cpp/api/JsiSkContourMeasureIter.h +18 -21
  12. package/cpp/api/JsiSkData.h +13 -7
  13. package/cpp/api/JsiSkDataFactory.h +22 -21
  14. package/cpp/api/JsiSkFont.h +56 -44
  15. package/cpp/api/JsiSkFontMgr.h +22 -13
  16. package/cpp/api/JsiSkFontMgrFactory.h +12 -10
  17. package/cpp/api/JsiSkFontStyle.h +14 -12
  18. package/cpp/api/JsiSkImage.h +45 -34
  19. package/cpp/api/JsiSkImageFactory.h +47 -52
  20. package/cpp/api/JsiSkImageFilter.h +21 -11
  21. package/cpp/api/JsiSkImageFilterFactory.h +96 -96
  22. package/cpp/api/JsiSkImageInfo.h +22 -19
  23. package/cpp/api/JsiSkMaskFilter.h +21 -11
  24. package/cpp/api/JsiSkMaskFilterFactory.h +16 -13
  25. package/cpp/api/JsiSkMatrix.h +31 -31
  26. package/cpp/api/JsiSkNativeObjects.h +419 -0
  27. package/cpp/api/JsiSkPaint.h +59 -39
  28. package/cpp/api/JsiSkParagraph.h +39 -32
  29. package/cpp/api/JsiSkParagraphBuilder.h +24 -21
  30. package/cpp/api/JsiSkParagraphBuilderFactory.h +13 -12
  31. package/cpp/api/JsiSkPath.h +95 -70
  32. package/cpp/api/JsiSkPathBuilder.h +83 -67
  33. package/cpp/api/JsiSkPathBuilderFactory.h +16 -17
  34. package/cpp/api/JsiSkPathEffect.h +21 -11
  35. package/cpp/api/JsiSkPathEffectFactory.h +33 -32
  36. package/cpp/api/JsiSkPathFactory.h +79 -103
  37. package/cpp/api/JsiSkPicture.h +24 -13
  38. package/cpp/api/JsiSkPictureFactory.h +21 -26
  39. package/cpp/api/JsiSkPictureRecorder.h +21 -22
  40. package/cpp/api/JsiSkPoint.h +19 -22
  41. package/cpp/api/JsiSkRRect.h +22 -29
  42. package/cpp/api/JsiSkRSXform.h +26 -30
  43. package/cpp/api/JsiSkRect.h +28 -30
  44. package/cpp/api/JsiSkRuntimeEffect.h +39 -30
  45. package/cpp/api/JsiSkRuntimeEffectFactory.h +12 -12
  46. package/cpp/api/JsiSkRuntimeShaderBuilder.h +25 -18
  47. package/cpp/api/JsiSkSVG.h +13 -13
  48. package/cpp/api/JsiSkSVGFactory.h +17 -20
  49. package/cpp/api/JsiSkShader.h +15 -8
  50. package/cpp/api/JsiSkShaderFactory.h +41 -48
  51. package/cpp/api/JsiSkSkottie.h +49 -39
  52. package/cpp/api/JsiSkSurface.h +24 -24
  53. package/cpp/api/JsiSkSurfaceFactory.h +15 -16
  54. package/cpp/api/JsiSkTextBlob.h +15 -8
  55. package/cpp/api/JsiSkTextBlobFactory.h +25 -28
  56. package/cpp/api/JsiSkTypeface.h +19 -12
  57. package/cpp/api/JsiSkTypefaceFactory.h +12 -12
  58. package/cpp/api/JsiSkTypefaceFontProvider.h +30 -25
  59. package/cpp/api/JsiSkTypefaceFontProviderFactory.h +14 -12
  60. package/cpp/api/JsiSkVertices.h +21 -18
  61. package/cpp/api/JsiSkiaContext.h +17 -17
  62. package/cpp/api/JsiSkottieFactory.h +16 -17
  63. package/cpp/api/JsiVideo.h +27 -25
  64. package/cpp/api/recorder/Convertor.h +31 -61
  65. package/cpp/api/recorder/DataTypes.h +8 -16
  66. package/cpp/api/recorder/JsiRecorder.h +83 -55
  67. package/cpp/api/recorder/RNRecorder.h +1 -1
  68. package/cpp/jsi/BoxedNativeObject.h +146 -0
  69. package/cpp/{jsi2 → jsi}/EnumMapper.h +4 -1
  70. package/cpp/{jsi2 → jsi}/NativeObject.h +120 -146
  71. package/cpp/jsi/RuntimeAwareCache.cpp +1 -1
  72. package/cpp/jsi/RuntimeAwareCache.h +26 -8
  73. package/cpp/jsi/ViewProperty.h +5 -11
  74. package/cpp/rnskia/RNSkJsiViewApi.h +20 -11
  75. package/cpp/rnskia/RNSkManager.cpp +23 -25
  76. package/cpp/rnskia/RNSkPictureView.h +1 -1
  77. package/cpp/rnwgpu/ArrayBuffer.h +5 -6
  78. package/cpp/rnwgpu/Canvas.h +4 -2
  79. package/cpp/rnwgpu/api/GPU.cpp +4 -4
  80. package/cpp/rnwgpu/api/GPU.h +1 -1
  81. package/cpp/rnwgpu/api/GPUAdapter.cpp +2 -3
  82. package/cpp/rnwgpu/api/GPUAdapter.h +4 -4
  83. package/cpp/rnwgpu/api/GPUAdapterInfo.h +1 -1
  84. package/cpp/rnwgpu/api/GPUBindGroup.h +1 -1
  85. package/cpp/rnwgpu/api/GPUBindGroupLayout.h +1 -1
  86. package/cpp/rnwgpu/api/GPUBuffer.h +1 -1
  87. package/cpp/rnwgpu/api/GPUCanvasContext.h +1 -1
  88. package/cpp/rnwgpu/api/GPUCommandBuffer.h +1 -1
  89. package/cpp/rnwgpu/api/GPUCommandEncoder.h +1 -1
  90. package/cpp/rnwgpu/api/GPUCompilationInfo.h +1 -1
  91. package/cpp/rnwgpu/api/GPUCompilationMessage.h +1 -1
  92. package/cpp/rnwgpu/api/GPUComputePassEncoder.h +1 -1
  93. package/cpp/rnwgpu/api/GPUComputePipeline.h +1 -1
  94. package/cpp/rnwgpu/api/GPUDevice.cpp +6 -7
  95. package/cpp/rnwgpu/api/GPUDevice.h +3 -3
  96. package/cpp/rnwgpu/api/GPUDeviceLostInfo.h +1 -1
  97. package/cpp/rnwgpu/api/GPUError.h +1 -1
  98. package/cpp/rnwgpu/api/GPUExtent3D.h +1 -1
  99. package/cpp/rnwgpu/api/GPUExternalTexture.h +1 -1
  100. package/cpp/rnwgpu/api/GPUInternalError.h +1 -1
  101. package/cpp/rnwgpu/api/GPUOrigin2D.h +1 -1
  102. package/cpp/rnwgpu/api/GPUOrigin3D.h +1 -1
  103. package/cpp/rnwgpu/api/GPUOutOfMemoryError.h +1 -1
  104. package/cpp/rnwgpu/api/GPUPipelineLayout.h +1 -1
  105. package/cpp/rnwgpu/api/GPUQuerySet.h +1 -1
  106. package/cpp/rnwgpu/api/GPUQueue.h +1 -1
  107. package/cpp/rnwgpu/api/GPURenderBundle.h +1 -1
  108. package/cpp/rnwgpu/api/GPURenderBundleEncoder.h +1 -1
  109. package/cpp/rnwgpu/api/GPURenderPassEncoder.h +1 -1
  110. package/cpp/rnwgpu/api/GPURenderPipeline.h +1 -1
  111. package/cpp/rnwgpu/api/GPUSampler.h +1 -1
  112. package/cpp/rnwgpu/api/GPUShaderModule.cpp +1 -1
  113. package/cpp/rnwgpu/api/GPUShaderModule.h +1 -1
  114. package/cpp/rnwgpu/api/GPUSharedFence.h +1 -1
  115. package/cpp/rnwgpu/api/GPUSharedTextureMemory.h +1 -1
  116. package/cpp/rnwgpu/api/GPUSupportedLimits.h +1 -1
  117. package/cpp/rnwgpu/api/GPUTexture.h +1 -1
  118. package/cpp/rnwgpu/api/GPUTextureView.h +1 -1
  119. package/cpp/rnwgpu/api/GPUUncapturedErrorEvent.h +1 -1
  120. package/cpp/rnwgpu/api/GPUValidationError.h +1 -1
  121. package/cpp/rnwgpu/api/ImageBitmap.h +1 -1
  122. package/cpp/rnwgpu/api/RNWebGPU.h +1 -1
  123. package/cpp/rnwgpu/api/descriptors/GPUBindGroupDescriptor.h +1 -1
  124. package/cpp/rnwgpu/api/descriptors/GPUBindGroupEntry.h +1 -1
  125. package/cpp/rnwgpu/api/descriptors/GPUBindGroupLayoutDescriptor.h +1 -1
  126. package/cpp/rnwgpu/api/descriptors/GPUBindGroupLayoutEntry.h +1 -1
  127. package/cpp/rnwgpu/api/descriptors/GPUBlendComponent.h +1 -1
  128. package/cpp/rnwgpu/api/descriptors/GPUBlendState.h +1 -1
  129. package/cpp/rnwgpu/api/descriptors/GPUBufferBinding.h +1 -1
  130. package/cpp/rnwgpu/api/descriptors/GPUBufferBindingLayout.h +1 -1
  131. package/cpp/rnwgpu/api/descriptors/GPUBufferDescriptor.h +1 -1
  132. package/cpp/rnwgpu/api/descriptors/GPUCanvasConfiguration.h +1 -1
  133. package/cpp/rnwgpu/api/descriptors/GPUColor.h +1 -1
  134. package/cpp/rnwgpu/api/descriptors/GPUColorTargetState.h +1 -1
  135. package/cpp/rnwgpu/api/descriptors/GPUCommandBufferDescriptor.h +1 -1
  136. package/cpp/rnwgpu/api/descriptors/GPUCommandEncoderDescriptor.h +1 -1
  137. package/cpp/rnwgpu/api/descriptors/GPUComputePassDescriptor.h +1 -1
  138. package/cpp/rnwgpu/api/descriptors/GPUComputePassTimestampWrites.h +1 -1
  139. package/cpp/rnwgpu/api/descriptors/GPUComputePipelineDescriptor.h +1 -1
  140. package/cpp/rnwgpu/api/descriptors/GPUDawnTogglesDescriptor.h +1 -1
  141. package/cpp/rnwgpu/api/descriptors/GPUDepthStencilState.h +1 -1
  142. package/cpp/rnwgpu/api/descriptors/GPUDeviceDescriptor.h +1 -1
  143. package/cpp/rnwgpu/api/descriptors/GPUExternalTextureBindingLayout.h +1 -1
  144. package/cpp/rnwgpu/api/descriptors/GPUExternalTextureDescriptor.h +1 -1
  145. package/cpp/rnwgpu/api/descriptors/GPUFragmentState.h +1 -1
  146. package/cpp/rnwgpu/api/descriptors/GPUImageCopyBuffer.h +1 -1
  147. package/cpp/rnwgpu/api/descriptors/GPUImageCopyExternalImage.h +1 -1
  148. package/cpp/rnwgpu/api/descriptors/GPUImageCopyTexture.h +1 -1
  149. package/cpp/rnwgpu/api/descriptors/GPUImageCopyTextureTagged.h +1 -1
  150. package/cpp/rnwgpu/api/descriptors/GPUImageDataLayout.h +1 -1
  151. package/cpp/rnwgpu/api/descriptors/GPUMultisampleState.h +1 -1
  152. package/cpp/rnwgpu/api/descriptors/GPUPipelineLayoutDescriptor.h +1 -1
  153. package/cpp/rnwgpu/api/descriptors/GPUPrimitiveState.h +1 -1
  154. package/cpp/rnwgpu/api/descriptors/GPUProgrammableStage.h +1 -1
  155. package/cpp/rnwgpu/api/descriptors/GPUQuerySetDescriptor.h +1 -1
  156. package/cpp/rnwgpu/api/descriptors/GPUQueueDescriptor.h +1 -1
  157. package/cpp/rnwgpu/api/descriptors/GPURenderBundleDescriptor.h +1 -1
  158. package/cpp/rnwgpu/api/descriptors/GPURenderBundleEncoderDescriptor.h +1 -1
  159. package/cpp/rnwgpu/api/descriptors/GPURenderPassColorAttachment.h +1 -1
  160. package/cpp/rnwgpu/api/descriptors/GPURenderPassDepthStencilAttachment.h +1 -1
  161. package/cpp/rnwgpu/api/descriptors/GPURenderPassDescriptor.h +1 -1
  162. package/cpp/rnwgpu/api/descriptors/GPURenderPassTimestampWrites.h +1 -1
  163. package/cpp/rnwgpu/api/descriptors/GPURenderPipelineDescriptor.h +1 -1
  164. package/cpp/rnwgpu/api/descriptors/GPURequestAdapterOptions.h +1 -1
  165. package/cpp/rnwgpu/api/descriptors/GPUSamplerBindingLayout.h +1 -1
  166. package/cpp/rnwgpu/api/descriptors/GPUSamplerDescriptor.h +1 -1
  167. package/cpp/rnwgpu/api/descriptors/GPUShaderModuleCompilationHint.h +1 -1
  168. package/cpp/rnwgpu/api/descriptors/GPUShaderModuleDescriptor.h +1 -1
  169. package/cpp/rnwgpu/api/descriptors/GPUSharedFenceDescriptor.h +1 -1
  170. package/cpp/rnwgpu/api/descriptors/GPUSharedFenceState.h +1 -1
  171. package/cpp/rnwgpu/api/descriptors/GPUSharedTextureMemoryDescriptor.h +1 -1
  172. package/cpp/rnwgpu/api/descriptors/GPUStencilFaceState.h +1 -1
  173. package/cpp/rnwgpu/api/descriptors/GPUStorageTextureBindingLayout.h +1 -1
  174. package/cpp/rnwgpu/api/descriptors/GPUTextureBindingLayout.h +1 -1
  175. package/cpp/rnwgpu/api/descriptors/GPUTextureDescriptor.h +1 -1
  176. package/cpp/rnwgpu/api/descriptors/GPUTextureViewDescriptor.h +1 -1
  177. package/cpp/rnwgpu/api/descriptors/GPUUncapturedErrorEventInit.h +1 -1
  178. package/cpp/rnwgpu/api/descriptors/GPUVertexAttribute.h +1 -1
  179. package/cpp/rnwgpu/api/descriptors/GPUVertexBufferLayout.h +1 -1
  180. package/cpp/rnwgpu/api/descriptors/GPUVertexState.h +1 -1
  181. package/cpp/rnwgpu/api/descriptors/Unions.h +1 -1
  182. package/cpp/rnwgpu/async/AsyncTaskHandle.cpp +20 -21
  183. package/lib/commonjs/external/reanimated/renderHelpers.d.ts +15 -0
  184. package/lib/commonjs/external/reanimated/renderHelpers.js +30 -1
  185. package/lib/commonjs/external/reanimated/renderHelpers.js.map +1 -1
  186. package/lib/commonjs/skia/NativeSetup.js +4 -0
  187. package/lib/commonjs/skia/NativeSetup.js.map +1 -1
  188. package/lib/commonjs/skia/SkiaWorkletSerialization.d.ts +1 -0
  189. package/lib/commonjs/skia/SkiaWorkletSerialization.js +66 -0
  190. package/lib/commonjs/skia/SkiaWorkletSerialization.js.map +1 -0
  191. package/lib/commonjs/sksg/Container.native.js +20 -1
  192. package/lib/commonjs/sksg/Container.native.js.map +1 -1
  193. package/lib/module/external/reanimated/renderHelpers.d.ts +15 -0
  194. package/lib/module/external/reanimated/renderHelpers.js +29 -0
  195. package/lib/module/external/reanimated/renderHelpers.js.map +1 -1
  196. package/lib/module/skia/NativeSetup.js +4 -0
  197. package/lib/module/skia/NativeSetup.js.map +1 -1
  198. package/lib/module/skia/SkiaWorkletSerialization.d.ts +1 -0
  199. package/lib/module/skia/SkiaWorkletSerialization.js +59 -0
  200. package/lib/module/skia/SkiaWorkletSerialization.js.map +1 -0
  201. package/lib/module/sksg/Container.native.js +21 -2
  202. package/lib/module/sksg/Container.native.js.map +1 -1
  203. package/lib/typescript/lib/commonjs/external/reanimated/renderHelpers.d.ts +2 -0
  204. package/lib/typescript/lib/commonjs/skia/SkiaWorkletSerialization.d.ts +2 -0
  205. package/lib/typescript/lib/module/external/reanimated/renderHelpers.d.ts +15 -0
  206. package/lib/typescript/lib/module/skia/SkiaWorkletSerialization.d.ts +1 -0
  207. package/lib/typescript/src/external/reanimated/renderHelpers.d.ts +15 -0
  208. package/lib/typescript/src/skia/SkiaWorkletSerialization.d.ts +1 -0
  209. package/package.json +6 -2
  210. package/react-native-skia.podspec +1 -2
  211. package/src/external/reanimated/renderHelpers.ts +30 -0
  212. package/src/skia/NativeSetup.ts +5 -0
  213. package/src/skia/SkiaWorkletSerialization.ts +67 -0
  214. package/src/sksg/Container.native.ts +40 -2
  215. package/cpp/api/JsiSkHostObjects.h +0 -257
  216. package/cpp/jsi/JsiHostObject.cpp +0 -137
  217. package/cpp/jsi/JsiHostObject.h +0 -385
  218. /package/cpp/{jsi2 → jsi}/JSIConverter.h +0 -0
  219. /package/cpp/{jsi2 → jsi}/Promise.cpp +0 -0
  220. /package/cpp/{jsi2 → jsi}/Promise.h +0 -0
@@ -5,7 +5,7 @@
5
5
 
6
6
  #include <jsi/jsi.h>
7
7
 
8
- #include "JsiSkHostObjects.h"
8
+ #include "JsiSkNativeObjects.h"
9
9
 
10
10
  #pragma clang diagnostic push
11
11
  #pragma clang diagnostic ignored "-Wdocumentation"
@@ -18,11 +18,14 @@ namespace RNSkia {
18
18
 
19
19
  namespace jsi = facebook::jsi;
20
20
 
21
- class JsiSkImageInfo : public JsiSkWrappingSharedPtrHostObject<SkImageInfo> {
21
+ class JsiSkImageInfo
22
+ : public JsiSkWrappingSharedPtrNativeObject<JsiSkImageInfo, SkImageInfo> {
22
23
  public:
24
+ static constexpr const char *CLASS_NAME = "ImageInfo";
25
+
23
26
  JsiSkImageInfo(std::shared_ptr<RNSkPlatformContext> context,
24
27
  const SkImageInfo &imageInfo)
25
- : JsiSkWrappingSharedPtrHostObject<SkImageInfo>(
28
+ : JsiSkWrappingSharedPtrNativeObject<JsiSkImageInfo, SkImageInfo>(
26
29
  std::move(context), std::make_shared<SkImageInfo>(imageInfo)) {}
27
30
 
28
31
  /**
@@ -31,8 +34,9 @@ public:
31
34
  static std::shared_ptr<SkImageInfo> fromValue(jsi::Runtime &runtime,
32
35
  const jsi::Value &obj) {
33
36
  const auto &object = obj.asObject(runtime);
34
- if (object.isHostObject(runtime)) {
35
- return object.asHostObject<JsiSkImageInfo>(runtime)->getObject();
37
+ auto imageInfo = tryGetJsiObject<JsiSkImageInfo>(runtime, object);
38
+ if (imageInfo) {
39
+ return imageInfo->getObject();
36
40
  } else {
37
41
  auto width = object.getProperty(runtime, "width").asNumber();
38
42
  auto height = object.getProperty(runtime, "height").asNumber();
@@ -52,10 +56,8 @@ public:
52
56
  static jsi::Value toValue(jsi::Runtime &runtime,
53
57
  std::shared_ptr<RNSkPlatformContext> context,
54
58
  const SkImageInfo &imageInfo) {
55
- auto imageInfoObj =
56
- std::make_shared<JsiSkImageInfo>(std::move(context), imageInfo);
57
- return JSI_CREATE_HOST_OBJECT_WITH_MEMORY_PRESSURE(runtime, imageInfoObj,
58
- context);
59
+ return makeJsiObject(runtime, std::make_shared<JsiSkImageInfo>(
60
+ std::move(context), imageInfo));
59
61
  }
60
62
 
61
63
  JSI_PROPERTY_GET(width) { return static_cast<double>(getObject()->width()); }
@@ -69,18 +71,19 @@ public:
69
71
  return static_cast<double>(getObject()->alphaType());
70
72
  }
71
73
 
72
- size_t getMemoryPressure() const override {
74
+ size_t getMemoryPressure() override {
73
75
  return std::max(sizeof(SkImageInfo), kMinMemoryPressure);
74
76
  }
75
77
 
76
- std::string getObjectType() const override { return "JsiSkImageInfo"; }
77
-
78
- JSI_API_TYPENAME(ImageInfo);
79
-
80
- JSI_EXPORT_PROPERTY_GETTERS(JSI_EXPORT_PROP_GET(JsiSkImageInfo, width),
81
- JSI_EXPORT_PROP_GET(JsiSkImageInfo, height),
82
- JSI_EXPORT_PROP_GET(JsiSkImageInfo, colorType),
83
- JSI_EXPORT_PROP_GET(JsiSkImageInfo, alphaType),
84
- JSI_EXPORT_PROP_GET(JsiSkImageInfo, __typename__))
78
+ static void definePrototype(jsi::Runtime &runtime, jsi::Object &prototype) {
79
+ installCommon(runtime, prototype);
80
+ installHostGetter(runtime, prototype, "width", &JsiSkImageInfo::get_width);
81
+ installHostGetter(runtime, prototype, "height",
82
+ &JsiSkImageInfo::get_height);
83
+ installHostGetter(runtime, prototype, "colorType",
84
+ &JsiSkImageInfo::get_colorType);
85
+ installHostGetter(runtime, prototype, "alphaType",
86
+ &JsiSkImageInfo::get_alphaType);
87
+ }
85
88
  };
86
89
  } // namespace RNSkia
@@ -5,7 +5,7 @@
5
5
 
6
6
  #include <jsi/jsi.h>
7
7
 
8
- #include "JsiSkHostObjects.h"
8
+ #include "JsiSkNativeObjects.h"
9
9
 
10
10
  #pragma clang diagnostic push
11
11
  #pragma clang diagnostic ignored "-Wdocumentation"
@@ -18,19 +18,29 @@ namespace RNSkia {
18
18
 
19
19
  namespace jsi = facebook::jsi;
20
20
 
21
- class JsiSkMaskFilter : public JsiSkWrappingSkPtrHostObject<SkMaskFilter> {
21
+ class JsiSkMaskFilter
22
+ : public JsiSkWrappingSkPtrNativeObject<JsiSkMaskFilter, SkMaskFilter> {
22
23
  public:
24
+ static constexpr const char *CLASS_NAME = "MaskFilter";
25
+
23
26
  JsiSkMaskFilter(std::shared_ptr<RNSkPlatformContext> context,
24
27
  sk_sp<SkMaskFilter> maskFilter)
25
- : JsiSkWrappingSkPtrHostObject<SkMaskFilter>(std::move(context),
26
- std::move(maskFilter)) {}
27
-
28
- size_t getMemoryPressure() const override { return 2048; }
29
-
30
- std::string getObjectType() const override { return "JsiSkMaskFilter"; }
31
-
32
- EXPORT_JSI_API_TYPENAME(JsiSkMaskFilter, MaskFilter)
33
- JSI_EXPORT_FUNCTIONS(JSI_EXPORT_FUNC(JsiSkMaskFilter, dispose))
28
+ : JsiSkWrappingSkPtrNativeObject<JsiSkMaskFilter, SkMaskFilter>(
29
+ std::move(context), std::move(maskFilter)) {}
30
+
31
+ size_t getMemoryPressure() override { return 2048; }
32
+
33
+ static void definePrototype(jsi::Runtime &runtime, jsi::Object &prototype) {
34
+ installCommon(runtime, prototype);
35
+ }
36
+
37
+ /**
38
+ Returns the underlying object from a host object of this type
39
+ */
40
+ static sk_sp<SkMaskFilter> fromValue(jsi::Runtime &runtime,
41
+ const jsi::Value &obj) {
42
+ return objectFromValue(runtime, obj);
43
+ }
34
44
  };
35
45
 
36
46
  } // namespace RNSkia
@@ -6,7 +6,8 @@
6
6
  #include <jsi/jsi.h>
7
7
 
8
8
  #include "JsiSkColorFilter.h"
9
- #include "JsiSkHostObjects.h"
9
+ #include "JsiSkMaskFilter.h"
10
+ #include "JsiSkNativeObjects.h"
10
11
 
11
12
  #pragma clang diagnostic push
12
13
  #pragma clang diagnostic ignored "-Wdocumentation"
@@ -19,29 +20,31 @@ namespace RNSkia {
19
20
 
20
21
  namespace jsi = facebook::jsi;
21
22
 
22
- class JsiSkMaskFilterFactory : public JsiSkHostObject {
23
+ class JsiSkMaskFilterFactory
24
+ : public JsiSkNativeObject<JsiSkMaskFilterFactory> {
23
25
  public:
26
+ static constexpr const char *CLASS_NAME = "MaskFilterFactory";
27
+
24
28
  JSI_HOST_FUNCTION(MakeBlur) {
25
29
  int blurStyle = arguments[0].asNumber();
26
30
  float sigma = arguments[1].asNumber();
27
31
  bool respectCTM = arguments[2].getBool();
28
- auto maskFilter = std::make_shared<JsiSkMaskFilter>(
29
- getContext(),
30
- SkMaskFilter::MakeBlur((SkBlurStyle)blurStyle, sigma, respectCTM));
31
- return JSI_CREATE_HOST_OBJECT_WITH_MEMORY_PRESSURE(runtime, maskFilter,
32
- getContext());
32
+ return makeJsiObject(
33
+ runtime,
34
+ std::make_shared<JsiSkMaskFilter>(
35
+ getContext(),
36
+ SkMaskFilter::MakeBlur((SkBlurStyle)blurStyle, sigma, respectCTM)));
33
37
  }
34
38
 
35
- size_t getMemoryPressure() const override { return 1024; }
39
+ size_t getMemoryPressure() override { return 1024; }
36
40
 
37
- std::string getObjectType() const override {
38
- return "JsiSkMaskFilterFactory";
41
+ static void definePrototype(jsi::Runtime &runtime, jsi::Object &prototype) {
42
+ installHostMethod(runtime, prototype, "MakeBlur",
43
+ &JsiSkMaskFilterFactory::MakeBlur);
39
44
  }
40
45
 
41
- JSI_EXPORT_FUNCTIONS(JSI_EXPORT_FUNC(JsiSkMaskFilterFactory, MakeBlur))
42
-
43
46
  explicit JsiSkMaskFilterFactory(std::shared_ptr<RNSkPlatformContext> context)
44
- : JsiSkHostObject(std::move(context)) {}
47
+ : JsiSkNativeObject<JsiSkMaskFilterFactory>(std::move(context)) {}
45
48
  };
46
49
 
47
50
  } // namespace RNSkia
@@ -5,7 +5,7 @@
5
5
 
6
6
  #include <jsi/jsi.h>
7
7
 
8
- #include "JsiSkHostObjects.h"
8
+ #include "JsiSkNativeObjects.h"
9
9
 
10
10
  #pragma clang diagnostic push
11
11
  #pragma clang diagnostic ignored "-Wdocumentation"
@@ -18,10 +18,13 @@ namespace RNSkia {
18
18
 
19
19
  namespace jsi = facebook::jsi;
20
20
 
21
- class JsiSkMatrix : public JsiSkWrappingSharedPtrHostObject<SkMatrix> {
21
+ class JsiSkMatrix
22
+ : public JsiSkWrappingSharedPtrNativeObject<JsiSkMatrix, SkMatrix> {
22
23
  public:
24
+ static constexpr const char *CLASS_NAME = "Matrix";
25
+
23
26
  JsiSkMatrix(std::shared_ptr<RNSkPlatformContext> context, SkMatrix m)
24
- : JsiSkWrappingSharedPtrHostObject<SkMatrix>(
27
+ : JsiSkWrappingSharedPtrNativeObject<JsiSkMatrix, SkMatrix>(
25
28
  context, std::make_shared<SkMatrix>(std::move(m))) {}
26
29
 
27
30
  static SkMatrix getMatrix(jsi::Runtime &runtime, const jsi::Value &value) {
@@ -57,10 +60,9 @@ public:
57
60
  }
58
61
 
59
62
  JSI_HOST_FUNCTION(concat) {
60
- if (arguments[0].isObject() &&
61
- arguments[0].asObject(runtime).isHostObject(runtime)) {
62
- auto m3 = JsiSkMatrix::fromValue(runtime, arguments[0]);
63
- getObject()->preConcat(*m3);
63
+ auto matrix = tryGetJsiObject<JsiSkMatrix>(runtime, arguments[0]);
64
+ if (matrix) {
65
+ getObject()->preConcat(*matrix->getObject());
64
66
  } else {
65
67
  auto m3 = JsiSkMatrix::getMatrix(runtime, arguments[0]);
66
68
  getObject()->preConcat(m3);
@@ -138,40 +140,40 @@ public:
138
140
  }
139
141
  #pragma clang diagnostic pop
140
142
 
141
- EXPORT_JSI_API_TYPENAME(JsiSkMatrix, Matrix)
142
-
143
- JSI_EXPORT_FUNCTIONS(JSI_EXPORT_FUNC(JsiSkMatrix, concat),
144
- JSI_EXPORT_FUNC(JsiSkMatrix, translate),
145
- JSI_EXPORT_FUNC(JsiSkMatrix, postTranslate),
146
- JSI_EXPORT_FUNC(JsiSkMatrix, scale),
147
- JSI_EXPORT_FUNC(JsiSkMatrix, postScale),
148
- JSI_EXPORT_FUNC(JsiSkMatrix, skew),
149
- JSI_EXPORT_FUNC(JsiSkMatrix, postSkew),
150
- JSI_EXPORT_FUNC(JsiSkMatrix, rotate),
151
- JSI_EXPORT_FUNC(JsiSkMatrix, postRotate),
152
- JSI_EXPORT_FUNC(JsiSkMatrix, identity),
153
- JSI_EXPORT_FUNC(JsiSkMatrix, get),
154
- JSI_EXPORT_FUNC(JsiSkMatrix, dispose))
143
+ static void definePrototype(jsi::Runtime &runtime, jsi::Object &prototype) {
144
+ installCommon(runtime, prototype);
145
+ installHostMethod(runtime, prototype, "concat", &JsiSkMatrix::concat);
146
+ installHostMethod(runtime, prototype, "translate", &JsiSkMatrix::translate);
147
+ installHostMethod(runtime, prototype, "postTranslate",
148
+ &JsiSkMatrix::postTranslate);
149
+ installHostMethod(runtime, prototype, "scale", &JsiSkMatrix::scale);
150
+ installHostMethod(runtime, prototype, "postScale", &JsiSkMatrix::postScale);
151
+ installHostMethod(runtime, prototype, "skew", &JsiSkMatrix::skew);
152
+ installHostMethod(runtime, prototype, "postSkew", &JsiSkMatrix::postSkew);
153
+ installHostMethod(runtime, prototype, "rotate", &JsiSkMatrix::rotate);
154
+ installHostMethod(runtime, prototype, "postRotate",
155
+ &JsiSkMatrix::postRotate);
156
+ installHostMethod(runtime, prototype, "identity", &JsiSkMatrix::identity);
157
+ installHostMethod(runtime, prototype, "get", &JsiSkMatrix::get);
158
+ }
155
159
 
156
160
  /**
157
161
  * Returns the underlying object from a host object of this type
158
162
  */
159
163
  static std::shared_ptr<SkMatrix> fromValue(jsi::Runtime &runtime,
160
164
  const jsi::Value &obj) {
161
- const auto &object = obj.asObject(runtime);
162
- if (object.isHostObject(runtime)) {
163
- return object.asHostObject<JsiSkMatrix>(runtime)->getObject();
165
+ auto matrix = tryGetJsiObject<JsiSkMatrix>(runtime, obj);
166
+ if (matrix) {
167
+ return matrix->getObject();
164
168
  } else {
165
169
  return std::make_shared<SkMatrix>(JsiSkMatrix::getMatrix(runtime, obj));
166
170
  }
167
171
  }
168
172
 
169
- size_t getMemoryPressure() const override {
173
+ size_t getMemoryPressure() override {
170
174
  return std::max(sizeof(SkMatrix), kMinMemoryPressure);
171
175
  }
172
176
 
173
- std::string getObjectType() const override { return "JsiSkMatrix"; }
174
-
175
177
  static const jsi::HostFunctionType
176
178
  createCtor(std::shared_ptr<RNSkPlatformContext> context) {
177
179
  return JSI_HOST_FUNCTION_LAMBDA {
@@ -181,10 +183,8 @@ public:
181
183
  } else {
182
184
  matrix = SkMatrix::I();
183
185
  }
184
- auto hostObjectInstance =
185
- std::make_shared<JsiSkMatrix>(context, std::move(matrix));
186
- return JSI_CREATE_HOST_OBJECT_WITH_MEMORY_PRESSURE(
187
- runtime, hostObjectInstance, context);
186
+ return makeJsiObject(
187
+ runtime, std::make_shared<JsiSkMatrix>(context, std::move(matrix)));
188
188
  };
189
189
  }
190
190
  };