@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,16 +5,19 @@
5
5
 
6
6
  #include <jsi/jsi.h>
7
7
 
8
- #include "jsi/JsiPromises.h"
9
8
  #include "JsiSkData.h"
9
+ #include "JsiSkNativeObjects.h"
10
10
  #include "api/third_party/base64.h"
11
+ #include "jsi/JsiPromises.h"
11
12
 
12
13
  namespace RNSkia {
13
14
 
14
15
  namespace jsi = facebook::jsi;
15
16
 
16
- class JsiSkDataFactory : public JsiSkHostObject {
17
+ class JsiSkDataFactory : public JsiSkNativeObject<JsiSkDataFactory> {
17
18
  public:
19
+ static constexpr const char *CLASS_NAME = "DataFactory";
20
+
18
21
  JSI_HOST_FUNCTION(fromURI) {
19
22
  auto jsiLocalUri = arguments[0].asString(runtime);
20
23
  auto localUri = jsiLocalUri.utf8(runtime);
@@ -38,10 +41,9 @@ public:
38
41
  context = std::move(context),
39
42
  promise = std::move(promise),
40
43
  result = std::move(result)]() {
41
- auto hostObjectInstance =
42
- std::make_shared<JsiSkData>(context, std::move(result));
43
- promise->resolve(JSI_CREATE_HOST_OBJECT_WITH_MEMORY_PRESSURE(
44
- runtime, hostObjectInstance, context));
44
+ promise->resolve(makeJsiObject(
45
+ runtime,
46
+ std::make_shared<JsiSkData>(context, std::move(result))));
45
47
  });
46
48
  });
47
49
  });
@@ -56,10 +58,8 @@ public:
56
58
 
57
59
  auto data =
58
60
  SkData::MakeWithCopy(buffer.data(runtime), buffer.size(runtime));
59
- auto hostObjectInstance =
60
- std::make_shared<JsiSkData>(getContext(), std::move(data));
61
- return JSI_CREATE_HOST_OBJECT_WITH_MEMORY_PRESSURE(
62
- runtime, hostObjectInstance, getContext());
61
+ return makeJsiObject(
62
+ runtime, std::make_shared<JsiSkData>(getContext(), std::move(data)));
63
63
  }
64
64
 
65
65
  JSI_HOST_FUNCTION(fromBase64) {
@@ -85,22 +85,23 @@ public:
85
85
  return jsi::Value::undefined();
86
86
  }
87
87
 
88
- auto hostObjectInstance =
89
- std::make_shared<JsiSkData>(getContext(), std::move(data));
90
- return JSI_CREATE_HOST_OBJECT_WITH_MEMORY_PRESSURE(
91
- runtime, hostObjectInstance, getContext());
88
+ return makeJsiObject(
89
+ runtime, std::make_shared<JsiSkData>(getContext(), std::move(data)));
92
90
  }
93
91
 
94
- size_t getMemoryPressure() const override { return 1024; }
92
+ size_t getMemoryPressure() override { return 1024; }
95
93
 
96
- std::string getObjectType() const override { return "JsiSkDataFactory"; }
97
-
98
- JSI_EXPORT_FUNCTIONS(JSI_EXPORT_FUNC(JsiSkDataFactory, fromURI),
99
- JSI_EXPORT_FUNC(JsiSkDataFactory, fromBytes),
100
- JSI_EXPORT_FUNC(JsiSkDataFactory, fromBase64))
94
+ static void definePrototype(jsi::Runtime &runtime, jsi::Object &prototype) {
95
+ installHostMethod(runtime, prototype, "fromURI",
96
+ &JsiSkDataFactory::fromURI);
97
+ installHostMethod(runtime, prototype, "fromBytes",
98
+ &JsiSkDataFactory::fromBytes);
99
+ installHostMethod(runtime, prototype, "fromBase64",
100
+ &JsiSkDataFactory::fromBase64);
101
+ }
101
102
 
102
103
  explicit JsiSkDataFactory(std::shared_ptr<RNSkPlatformContext> context)
103
- : JsiSkHostObject(std::move(context)) {}
104
+ : JsiSkNativeObject<JsiSkDataFactory>(std::move(context)) {}
104
105
  };
105
106
 
106
107
  } // namespace RNSkia
@@ -5,7 +5,7 @@
5
5
  #include <utility>
6
6
  #include <vector>
7
7
 
8
- #include "JsiSkHostObjects.h"
8
+ #include "JsiSkNativeObjects.h"
9
9
  #include "utils/RNSkLog.h"
10
10
  #include <jsi/jsi.h>
11
11
 
@@ -26,8 +26,10 @@ namespace RNSkia {
26
26
 
27
27
  namespace jsi = facebook::jsi;
28
28
 
29
- class JsiSkFont : public JsiSkWrappingSharedPtrHostObject<SkFont> {
29
+ class JsiSkFont : public JsiSkWrappingSharedPtrNativeObject<JsiSkFont, SkFont> {
30
30
  public:
31
+ static constexpr const char *CLASS_NAME = "Font";
32
+
31
33
  JSI_HOST_FUNCTION(getGlyphWidths) {
32
34
  auto jsiGlyphs = arguments[0].asObject(runtime).asArray(runtime);
33
35
  std::vector<SkGlyphID> glyphs;
@@ -91,9 +93,8 @@ public:
91
93
  getObject()->measureText(str.c_str(), str.length(), SkTextEncoding::kUTF8,
92
94
  &bounds);
93
95
  }
94
- auto rect = std::make_shared<JsiSkRect>(getContext(), std::move(bounds));
95
- return JSI_CREATE_HOST_OBJECT_WITH_MEMORY_PRESSURE(runtime, rect,
96
- getContext());
96
+ return makeJsiObject(
97
+ runtime, std::make_shared<JsiSkRect>(getContext(), std::move(bounds)));
97
98
  }
98
99
 
99
100
  JSI_HOST_FUNCTION(getMetrics) {
@@ -251,39 +252,56 @@ public:
251
252
  return jsi::Value::undefined();
252
253
  }
253
254
 
254
- EXPORT_JSI_API_TYPENAME(JsiSkFont, Font)
255
-
256
- JSI_EXPORT_FUNCTIONS(JSI_EXPORT_FUNC(JsiSkFont, getSize),
257
- JSI_EXPORT_FUNC(JsiSkFont, getMetrics),
258
- JSI_EXPORT_FUNC(JsiSkFont, getGlyphIDs),
259
- JSI_EXPORT_FUNC(JsiSkFont, getGlyphIntercepts),
260
- JSI_EXPORT_FUNC(JsiSkFont, getScaleX),
261
- JSI_EXPORT_FUNC(JsiSkFont, getSkewX),
262
- JSI_EXPORT_FUNC(JsiSkFont, getTypeface),
263
- JSI_EXPORT_FUNC(JsiSkFont, setEdging),
264
- JSI_EXPORT_FUNC(JsiSkFont, embeddedBitmaps),
265
- JSI_EXPORT_FUNC(JsiSkFont, setHinting),
266
- JSI_EXPORT_FUNC(JsiSkFont, setLinearMetrics),
267
- JSI_EXPORT_FUNC(JsiSkFont, setScaleX),
268
- JSI_EXPORT_FUNC(JsiSkFont, setSkewX),
269
- JSI_EXPORT_FUNC(JsiSkFont, setSize),
270
- JSI_EXPORT_FUNC(JsiSkFont, setEmbolden),
271
- JSI_EXPORT_FUNC(JsiSkFont, setSubpixel),
272
- JSI_EXPORT_FUNC(JsiSkFont, setTypeface),
273
- JSI_EXPORT_FUNC(JsiSkFont, getGlyphWidths),
274
- JSI_EXPORT_FUNC(JsiSkFont, getTextWidth),
275
- JSI_EXPORT_FUNC(JsiSkFont, measureText),
276
- JSI_EXPORT_FUNC(JsiSkFont, dispose))
255
+ static void definePrototype(jsi::Runtime &runtime, jsi::Object &prototype) {
256
+ installCommon(runtime, prototype);
257
+ installHostMethod(runtime, prototype, "getSize", &JsiSkFont::getSize);
258
+ installHostMethod(runtime, prototype, "getMetrics", &JsiSkFont::getMetrics);
259
+ installHostMethod(runtime, prototype, "getGlyphIDs",
260
+ &JsiSkFont::getGlyphIDs);
261
+ installHostMethod(runtime, prototype, "getGlyphIntercepts",
262
+ &JsiSkFont::getGlyphIntercepts);
263
+ installHostMethod(runtime, prototype, "getScaleX", &JsiSkFont::getScaleX);
264
+ installHostMethod(runtime, prototype, "getSkewX", &JsiSkFont::getSkewX);
265
+ installHostMethod(runtime, prototype, "getTypeface",
266
+ &JsiSkFont::getTypeface);
267
+ installHostMethod(runtime, prototype, "setEdging", &JsiSkFont::setEdging);
268
+ installHostMethod(runtime, prototype, "embeddedBitmaps",
269
+ &JsiSkFont::embeddedBitmaps);
270
+ installHostMethod(runtime, prototype, "setHinting", &JsiSkFont::setHinting);
271
+ installHostMethod(runtime, prototype, "setLinearMetrics",
272
+ &JsiSkFont::setLinearMetrics);
273
+ installHostMethod(runtime, prototype, "setScaleX", &JsiSkFont::setScaleX);
274
+ installHostMethod(runtime, prototype, "setSkewX", &JsiSkFont::setSkewX);
275
+ installHostMethod(runtime, prototype, "setSize", &JsiSkFont::setSize);
276
+ installHostMethod(runtime, prototype, "setEmbolden",
277
+ &JsiSkFont::setEmbolden);
278
+ installHostMethod(runtime, prototype, "setSubpixel",
279
+ &JsiSkFont::setSubpixel);
280
+ installHostMethod(runtime, prototype, "setTypeface",
281
+ &JsiSkFont::setTypeface);
282
+ installHostMethod(runtime, prototype, "getGlyphWidths",
283
+ &JsiSkFont::getGlyphWidths);
284
+ installHostMethod(runtime, prototype, "getTextWidth",
285
+ &JsiSkFont::getTextWidth);
286
+ installHostMethod(runtime, prototype, "measureText",
287
+ &JsiSkFont::measureText);
288
+ }
277
289
 
278
290
  JsiSkFont(std::shared_ptr<RNSkPlatformContext> context, const SkFont &font)
279
- : JsiSkWrappingSharedPtrHostObject(std::move(context),
280
- std::make_shared<SkFont>(font)) {}
291
+ : JsiSkWrappingSharedPtrNativeObject<JsiSkFont, SkFont>(
292
+ std::move(context), std::make_shared<SkFont>(font)) {}
281
293
 
282
- size_t getMemoryPressure() const override {
294
+ size_t getMemoryPressure() override {
283
295
  return std::max(sizeof(SkFont), kMinMemoryPressure);
284
296
  }
285
297
 
286
- std::string getObjectType() const override { return "JsiSkFont"; }
298
+ /**
299
+ Returns the underlying object from a host object of this type
300
+ */
301
+ static std::shared_ptr<SkFont> fromValue(jsi::Runtime &runtime,
302
+ const jsi::Value &obj) {
303
+ return objectFromValue(runtime, obj);
304
+ }
287
305
 
288
306
  /**
289
307
  * Creates the function for construction a new instance of the SkFont
@@ -299,22 +317,16 @@ public:
299
317
  if (count == 2) {
300
318
  auto typeface = JsiSkTypeface::fromValue(runtime, arguments[0]);
301
319
  auto size = arguments[1].asNumber();
302
- auto hostObjectInstance =
303
- std::make_shared<JsiSkFont>(context, SkFont(typeface, size));
304
- return JSI_CREATE_HOST_OBJECT_WITH_MEMORY_PRESSURE(
305
- runtime, hostObjectInstance, std::move(context));
320
+ return makeJsiObject(runtime, std::make_shared<JsiSkFont>(
321
+ context, SkFont(typeface, size)));
306
322
  } else if (count == 1) {
307
323
  auto typeface = JsiSkTypeface::fromValue(runtime, arguments[0]);
308
- auto hostObjectInstance =
309
- std::make_shared<JsiSkFont>(context, SkFont(typeface));
310
- return JSI_CREATE_HOST_OBJECT_WITH_MEMORY_PRESSURE(
311
- runtime, hostObjectInstance, std::move(context));
324
+ return makeJsiObject(
325
+ runtime, std::make_shared<JsiSkFont>(context, SkFont(typeface)));
312
326
  } else {
313
327
  // Return the newly constructed object
314
- auto hostObjectInstance =
315
- std::make_shared<JsiSkFont>(context, SkFont());
316
- return JSI_CREATE_HOST_OBJECT_WITH_MEMORY_PRESSURE(
317
- runtime, hostObjectInstance, std::move(context));
328
+ return makeJsiObject(runtime,
329
+ std::make_shared<JsiSkFont>(context, SkFont()));
318
330
  }
319
331
  };
320
332
  }
@@ -6,7 +6,7 @@
6
6
  #include <vector>
7
7
 
8
8
  #include "JsiSkFontStyle.h"
9
- #include "JsiSkHostObjects.h"
9
+ #include "JsiSkNativeObjects.h"
10
10
  #include "utils/RNSkLog.h"
11
11
  #include <jsi/jsi.h>
12
12
 
@@ -21,13 +21,15 @@ namespace RNSkia {
21
21
 
22
22
  namespace jsi = facebook::jsi;
23
23
 
24
- class JsiSkFontMgr : public JsiSkWrappingSkPtrHostObject<SkFontMgr> {
24
+ class JsiSkFontMgr
25
+ : public JsiSkWrappingSkPtrNativeObject<JsiSkFontMgr, SkFontMgr> {
25
26
  public:
26
- EXPORT_JSI_API_TYPENAME(JsiSkFontMgr, FontMgr)
27
+ static constexpr const char *CLASS_NAME = "FontMgr";
27
28
 
28
29
  JsiSkFontMgr(std::shared_ptr<RNSkPlatformContext> context,
29
30
  sk_sp<SkFontMgr> fontMgr)
30
- : JsiSkWrappingSkPtrHostObject(context, fontMgr),
31
+ : JsiSkWrappingSkPtrNativeObject<JsiSkFontMgr, SkFontMgr>(context,
32
+ fontMgr),
31
33
  _systemFontFamilies(context->getSystemFontFamilies()) {}
32
34
 
33
35
  JSI_HOST_FUNCTION(countFamilies) {
@@ -63,19 +65,26 @@ public:
63
65
  auto fontStyle = JsiSkFontStyle::fromValue(runtime, arguments[1]);
64
66
  auto typeface =
65
67
  getObject()->matchFamilyStyle(resolvedName.c_str(), *fontStyle);
66
- auto hostObjectInstance =
67
- std::make_shared<JsiSkTypeface>(getContext(), std::move(typeface));
68
- return JSI_CREATE_HOST_OBJECT_WITH_MEMORY_PRESSURE(
69
- runtime, hostObjectInstance, getContext());
68
+ return makeJsiObject(runtime, std::make_shared<JsiSkTypeface>(
69
+ getContext(), std::move(typeface)));
70
70
  }
71
71
 
72
- size_t getMemoryPressure() const override { return 2048; }
72
+ size_t getMemoryPressure() override { return 2048; }
73
73
 
74
- std::string getObjectType() const override { return "JsiSkFontMgr"; }
74
+ static sk_sp<SkFontMgr> fromValue(jsi::Runtime &runtime,
75
+ const jsi::Value &obj) {
76
+ return objectFromValue(runtime, obj);
77
+ }
75
78
 
76
- JSI_EXPORT_FUNCTIONS(JSI_EXPORT_FUNC(JsiSkFontMgr, countFamilies),
77
- JSI_EXPORT_FUNC(JsiSkFontMgr, getFamilyName),
78
- JSI_EXPORT_FUNC(JsiSkFontMgr, matchFamilyStyle))
79
+ static void definePrototype(jsi::Runtime &runtime, jsi::Object &prototype) {
80
+ installCommon(runtime, prototype);
81
+ installHostMethod(runtime, prototype, "countFamilies",
82
+ &JsiSkFontMgr::countFamilies);
83
+ installHostMethod(runtime, prototype, "getFamilyName",
84
+ &JsiSkFontMgr::getFamilyName);
85
+ installHostMethod(runtime, prototype, "matchFamilyStyle",
86
+ &JsiSkFontMgr::matchFamilyStyle);
87
+ }
79
88
 
80
89
  private:
81
90
  std::vector<std::string> _systemFontFamilies;
@@ -6,7 +6,7 @@
6
6
 
7
7
  #include <jsi/jsi.h>
8
8
 
9
- #include "JsiSkHostObjects.h"
9
+ #include "JsiSkNativeObjects.h"
10
10
 
11
11
  #pragma clang diagnostic push
12
12
  #pragma clang diagnostic ignored "-Wdocumentation"
@@ -20,8 +20,10 @@ namespace RNSkia {
20
20
 
21
21
  namespace jsi = facebook::jsi;
22
22
 
23
- class JsiSkFontMgrFactory : public JsiSkHostObject {
23
+ class JsiSkFontMgrFactory : public JsiSkNativeObject<JsiSkFontMgrFactory> {
24
24
  public:
25
+ static constexpr const char *CLASS_NAME = "FontMgrFactory";
26
+
25
27
  static sk_sp<SkFontMgr>
26
28
  getFontMgr(std::shared_ptr<RNSkPlatformContext> context) {
27
29
  static SkOnce once;
@@ -32,19 +34,19 @@ public:
32
34
 
33
35
  JSI_HOST_FUNCTION(System) {
34
36
  auto fontMgr = JsiSkFontMgrFactory::getFontMgr(getContext());
35
- auto fontMgrObj = std::make_shared<JsiSkFontMgr>(getContext(), fontMgr);
36
- return JSI_CREATE_HOST_OBJECT_WITH_MEMORY_PRESSURE(runtime, fontMgrObj,
37
- getContext());
37
+ return makeJsiObject(runtime,
38
+ std::make_shared<JsiSkFontMgr>(getContext(), fontMgr));
38
39
  }
39
40
 
40
- JSI_EXPORT_FUNCTIONS(JSI_EXPORT_FUNC(JsiSkFontMgrFactory, System))
41
-
42
- size_t getMemoryPressure() const override { return 1024; }
41
+ size_t getMemoryPressure() override { return 1024; }
43
42
 
44
- std::string getObjectType() const override { return "JsiSkFontMgrFactory"; }
43
+ static void definePrototype(jsi::Runtime &runtime, jsi::Object &prototype) {
44
+ installHostMethod(runtime, prototype, "System",
45
+ &JsiSkFontMgrFactory::System);
46
+ }
45
47
 
46
48
  explicit JsiSkFontMgrFactory(std::shared_ptr<RNSkPlatformContext> context)
47
- : JsiSkHostObject(std::move(context)) {}
49
+ : JsiSkNativeObject<JsiSkFontMgrFactory>(std::move(context)) {}
48
50
  };
49
51
 
50
52
  } // 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,13 +18,14 @@ namespace RNSkia {
18
18
 
19
19
  namespace jsi = facebook::jsi;
20
20
 
21
- class JsiSkFontStyle : public JsiSkWrappingSharedPtrHostObject<SkFontStyle> {
21
+ class JsiSkFontStyle
22
+ : public JsiSkWrappingSharedPtrNativeObject<JsiSkFontStyle, SkFontStyle> {
22
23
  public:
23
- JSI_API_TYPENAME("FontStyle");
24
+ static constexpr const char *CLASS_NAME = "FontStyle";
24
25
 
25
26
  JsiSkFontStyle(std::shared_ptr<RNSkPlatformContext> context,
26
27
  const SkFontStyle &fontStyle)
27
- : JsiSkWrappingSharedPtrHostObject<SkFontStyle>(
28
+ : JsiSkWrappingSharedPtrNativeObject<JsiSkFontStyle, SkFontStyle>(
28
29
  std::move(context), std::make_shared<SkFontStyle>(fontStyle)) {}
29
30
 
30
31
  /**
@@ -33,8 +34,9 @@ public:
33
34
  static std::shared_ptr<SkFontStyle> fromValue(jsi::Runtime &runtime,
34
35
  const jsi::Value &obj) {
35
36
  const auto &object = obj.asObject(runtime);
36
- if (object.isHostObject(runtime)) {
37
- return object.asHostObject<JsiSkFontStyle>(runtime)->getObject();
37
+ auto fontStyle = tryGetJsiObject<JsiSkFontStyle>(runtime, object);
38
+ if (fontStyle) {
39
+ return fontStyle->getObject();
38
40
  } else {
39
41
  auto weightProp = object.getProperty(runtime, "weight");
40
42
  auto weight = static_cast<int>(
@@ -56,11 +58,13 @@ public:
56
58
  }
57
59
  }
58
60
 
59
- size_t getMemoryPressure() const override {
61
+ size_t getMemoryPressure() override {
60
62
  return std::max(sizeof(SkFontStyle), kMinMemoryPressure);
61
63
  }
62
64
 
63
- std::string getObjectType() const override { return "JsiSkFontStyle"; }
65
+ static void definePrototype(jsi::Runtime &runtime, jsi::Object &prototype) {
66
+ installCommon(runtime, prototype);
67
+ }
64
68
 
65
69
  /**
66
70
  Returns the jsi object from a host object of this type
@@ -68,10 +72,8 @@ public:
68
72
  static jsi::Value toValue(jsi::Runtime &runtime,
69
73
  std::shared_ptr<RNSkPlatformContext> context,
70
74
  const SkFontStyle &fontStyle) {
71
- auto fontStyleObj =
72
- std::make_shared<JsiSkFontStyle>(std::move(context), fontStyle);
73
- return JSI_CREATE_HOST_OBJECT_WITH_MEMORY_PRESSURE(runtime, fontStyleObj,
74
- context);
75
+ return makeJsiObject(runtime, std::make_shared<JsiSkFontStyle>(
76
+ std::move(context), fontStyle));
75
77
  }
76
78
  };
77
79
  } // namespace RNSkia
@@ -5,9 +5,9 @@
5
5
  #include <utility>
6
6
 
7
7
  #include "JsiSkDispatcher.h"
8
- #include "JsiSkHostObjects.h"
9
8
  #include "JsiSkImageInfo.h"
10
9
  #include "JsiSkMatrix.h"
10
+ #include "JsiSkNativeObjects.h"
11
11
  #include "JsiSkShader.h"
12
12
  #include "api/third_party/base64.h"
13
13
 
@@ -15,8 +15,8 @@
15
15
  #include "utils/RNSkTypedArray.h"
16
16
 
17
17
  #if defined(SK_GRAPHITE)
18
- #include "rnskia/RNDawnContext.h"
19
18
  #include "include/gpu/graphite/Context.h"
19
+ #include "rnskia/RNDawnContext.h"
20
20
  #else
21
21
  #include "include/gpu/ganesh/GrDirectContext.h"
22
22
  #endif
@@ -140,11 +140,13 @@ inline SkSamplingOptions SamplingOptionsFromValue(jsi::Runtime &runtime,
140
140
  return samplingOptions;
141
141
  }
142
142
 
143
- class JsiSkImage : public JsiSkWrappingSkPtrHostObject<SkImage> {
143
+ class JsiSkImage : public JsiSkWrappingSkPtrNativeObject<JsiSkImage, SkImage> {
144
144
  private:
145
145
  std::shared_ptr<Dispatcher> _dispatcher;
146
146
 
147
147
  public:
148
+ static constexpr const char *CLASS_NAME = "Image";
149
+
148
150
  // TODO-API: Properties?
149
151
  JSI_HOST_FUNCTION(width) { return static_cast<double>(getObject()->width()); }
150
152
  JSI_HOST_FUNCTION(height) {
@@ -166,10 +168,8 @@ public:
166
168
  : nullptr;
167
169
  auto shader =
168
170
  getObject()->makeShader(tmx, tmy, SkSamplingOptions(fm, mm), m);
169
- auto shaderObj =
170
- std::make_shared<JsiSkShader>(getContext(), std::move(shader));
171
- return JSI_CREATE_HOST_OBJECT_WITH_MEMORY_PRESSURE(runtime, shaderObj,
172
- getContext());
171
+ return makeJsiObject(runtime, std::make_shared<JsiSkShader>(
172
+ getContext(), std::move(shader)));
173
173
  }
174
174
 
175
175
  JSI_HOST_FUNCTION(makeShaderCubic) {
@@ -182,10 +182,8 @@ public:
182
182
  : nullptr;
183
183
  auto shader =
184
184
  getObject()->makeShader(tmx, tmy, SkSamplingOptions({B, C}), m);
185
- auto shaderObj =
186
- std::make_shared<JsiSkShader>(getContext(), std::move(shader));
187
- return JSI_CREATE_HOST_OBJECT_WITH_MEMORY_PRESSURE(runtime, shaderObj,
188
- getContext());
185
+ return makeJsiObject(runtime, std::make_shared<JsiSkShader>(
186
+ getContext(), std::move(shader)));
189
187
  }
190
188
 
191
189
  sk_sp<SkData> encodeImageData(const jsi::Value *arguments, size_t count) {
@@ -344,10 +342,8 @@ public:
344
342
  if (!rasterImage) {
345
343
  return jsi::Value::null();
346
344
  }
347
- auto hostObjectInstance =
348
- std::make_shared<JsiSkImage>(getContext(), std::move(rasterImage));
349
- return JSI_CREATE_HOST_OBJECT_WITH_MEMORY_PRESSURE(
350
- runtime, hostObjectInstance, getContext());
345
+ return makeJsiObject(runtime, std::make_shared<JsiSkImage>(
346
+ getContext(), std::move(rasterImage)));
351
347
  }
352
348
 
353
349
  JSI_HOST_FUNCTION(getNativeTextureUnstable) {
@@ -363,25 +359,42 @@ public:
363
359
  return jsi::Value(getObject()->isTextureBacked());
364
360
  }
365
361
 
366
- EXPORT_JSI_API_TYPENAME(JsiSkImage, Image)
367
-
368
- JSI_EXPORT_FUNCTIONS(JSI_EXPORT_FUNC(JsiSkImage, width),
369
- JSI_EXPORT_FUNC(JsiSkImage, height),
370
- JSI_EXPORT_FUNC(JsiSkImage, getImageInfo),
371
- JSI_EXPORT_FUNC(JsiSkImage, makeShaderOptions),
372
- JSI_EXPORT_FUNC(JsiSkImage, makeShaderCubic),
373
- JSI_EXPORT_FUNC(JsiSkImage, encodeToBytes),
374
- JSI_EXPORT_FUNC(JsiSkImage, encodeToBase64),
375
- JSI_EXPORT_FUNC(JsiSkImage, readPixels),
376
- JSI_EXPORT_FUNC(JsiSkImage, makeNonTextureImage),
377
- JSI_EXPORT_FUNC(JsiSkImage, getNativeTextureUnstable),
378
- JSI_EXPORT_FUNC(JsiSkImage, isTextureBacked),
379
- JSI_EXPORT_FUNC(JsiSkImage, dispose))
362
+ /**
363
+ Returns the underlying object from a host object of this type
364
+ */
365
+ static sk_sp<SkImage> fromValue(jsi::Runtime &runtime,
366
+ const jsi::Value &obj) {
367
+ return objectFromValue(runtime, obj);
368
+ }
369
+
370
+ static void definePrototype(jsi::Runtime &runtime, jsi::Object &prototype) {
371
+ installCommon(runtime, prototype);
372
+ installHostMethod(runtime, prototype, "width", &JsiSkImage::width);
373
+ installHostMethod(runtime, prototype, "height", &JsiSkImage::height);
374
+ installHostMethod(runtime, prototype, "getImageInfo",
375
+ &JsiSkImage::getImageInfo);
376
+ installHostMethod(runtime, prototype, "makeShaderOptions",
377
+ &JsiSkImage::makeShaderOptions);
378
+ installHostMethod(runtime, prototype, "makeShaderCubic",
379
+ &JsiSkImage::makeShaderCubic);
380
+ installHostMethod(runtime, prototype, "encodeToBytes",
381
+ &JsiSkImage::encodeToBytes);
382
+ installHostMethod(runtime, prototype, "encodeToBase64",
383
+ &JsiSkImage::encodeToBase64);
384
+ installHostMethod(runtime, prototype, "readPixels",
385
+ &JsiSkImage::readPixels);
386
+ installHostMethod(runtime, prototype, "makeNonTextureImage",
387
+ &JsiSkImage::makeNonTextureImage);
388
+ installHostMethod(runtime, prototype, "getNativeTextureUnstable",
389
+ &JsiSkImage::getNativeTextureUnstable);
390
+ installHostMethod(runtime, prototype, "isTextureBacked",
391
+ &JsiSkImage::isTextureBacked);
392
+ }
380
393
 
381
394
  JsiSkImage(std::shared_ptr<RNSkPlatformContext> context,
382
395
  const sk_sp<SkImage> image)
383
- : JsiSkWrappingSkPtrHostObject<SkImage>(std::move(context),
384
- std::move(image)) {
396
+ : JsiSkWrappingSkPtrNativeObject<JsiSkImage, SkImage>(std::move(context),
397
+ std::move(image)) {
385
398
  // Get the dispatcher for the current thread
386
399
  _dispatcher = Dispatcher::getDispatcher();
387
400
  // Process any pending operations (e.g. deletions of previous resources)
@@ -406,7 +419,7 @@ public:
406
419
  }
407
420
  }
408
421
 
409
- size_t getMemoryPressure() const override {
422
+ size_t getMemoryPressure() override {
410
423
  if (isDisposed()) {
411
424
  return 0;
412
425
  }
@@ -420,8 +433,6 @@ public:
420
433
  }
421
434
  return 0;
422
435
  }
423
-
424
- std::string getObjectType() const override { return "JsiSkImage"; }
425
436
  };
426
437
 
427
438
  } // namespace RNSkia