@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.
- package/android/CMakeLists.txt +1 -5
- package/android/cpp/jni/JniWebGPUView.cpp +52 -7
- package/android/src/main/java/com/shopify/reactnative/skia/WebGPUSurfaceView.java +3 -1
- package/android/src/main/java/com/shopify/reactnative/skia/WebGPUTextureView.java +11 -5
- package/android/src/main/java/com/shopify/reactnative/skia/WebGPUView.java +10 -7
- package/android/src/main/java/com/shopify/reactnative/skia/WebGPUViewAPI.java +7 -2
- package/android/src/main/java/com/shopify/reactnative/skia/WebGPUViewManager.java +1 -1
- package/apple/WebGPUMetalView.mm +49 -6
- package/cpp/api/JsiNativeBuffer.h +15 -10
- package/cpp/api/JsiSkAnimatedImage.h +21 -19
- package/cpp/api/JsiSkAnimatedImageFactory.h +13 -14
- package/cpp/api/JsiSkApi.h +246 -92
- package/cpp/api/JsiSkCanvas.h +76 -58
- package/cpp/api/JsiSkColor.h +7 -5
- package/cpp/api/JsiSkColorFilter.h +15 -8
- package/cpp/api/JsiSkColorFilterFactory.h +45 -45
- package/cpp/api/JsiSkContourMeasure.h +24 -21
- package/cpp/api/JsiSkContourMeasureIter.h +18 -21
- package/cpp/api/JsiSkData.h +13 -7
- package/cpp/api/JsiSkDataFactory.h +22 -21
- package/cpp/api/JsiSkFont.h +56 -44
- package/cpp/api/JsiSkFontMgr.h +22 -13
- package/cpp/api/JsiSkFontMgrFactory.h +12 -10
- package/cpp/api/JsiSkFontStyle.h +14 -12
- package/cpp/api/JsiSkImage.h +45 -34
- package/cpp/api/JsiSkImageFactory.h +47 -52
- package/cpp/api/JsiSkImageFilter.h +21 -11
- package/cpp/api/JsiSkImageFilterFactory.h +96 -96
- package/cpp/api/JsiSkImageInfo.h +22 -19
- package/cpp/api/JsiSkMaskFilter.h +21 -11
- package/cpp/api/JsiSkMaskFilterFactory.h +16 -13
- package/cpp/api/JsiSkMatrix.h +31 -31
- package/cpp/api/JsiSkNativeObjects.h +419 -0
- package/cpp/api/JsiSkPaint.h +59 -39
- package/cpp/api/JsiSkParagraph.h +39 -32
- package/cpp/api/JsiSkParagraphBuilder.h +24 -21
- package/cpp/api/JsiSkParagraphBuilderFactory.h +13 -12
- package/cpp/api/JsiSkParagraphStyle.h +20 -10
- package/cpp/api/JsiSkPath.h +95 -70
- package/cpp/api/JsiSkPathBuilder.h +83 -67
- package/cpp/api/JsiSkPathBuilderFactory.h +16 -17
- package/cpp/api/JsiSkPathEffect.h +21 -11
- package/cpp/api/JsiSkPathEffectFactory.h +33 -32
- package/cpp/api/JsiSkPathFactory.h +79 -103
- package/cpp/api/JsiSkPicture.h +24 -13
- package/cpp/api/JsiSkPictureFactory.h +21 -26
- package/cpp/api/JsiSkPictureRecorder.h +21 -22
- package/cpp/api/JsiSkPoint.h +19 -22
- package/cpp/api/JsiSkRRect.h +22 -29
- package/cpp/api/JsiSkRSXform.h +26 -30
- package/cpp/api/JsiSkRect.h +28 -30
- package/cpp/api/JsiSkRuntimeEffect.h +39 -30
- package/cpp/api/JsiSkRuntimeEffectFactory.h +12 -12
- package/cpp/api/JsiSkRuntimeShaderBuilder.h +25 -18
- package/cpp/api/JsiSkSVG.h +13 -13
- package/cpp/api/JsiSkSVGFactory.h +17 -20
- package/cpp/api/JsiSkShader.h +15 -8
- package/cpp/api/JsiSkShaderFactory.h +41 -48
- package/cpp/api/JsiSkSkottie.h +49 -39
- package/cpp/api/JsiSkStrutStyle.h +18 -8
- package/cpp/api/JsiSkSurface.h +24 -24
- package/cpp/api/JsiSkSurfaceFactory.h +15 -16
- package/cpp/api/JsiSkTextBlob.h +15 -8
- package/cpp/api/JsiSkTextBlobFactory.h +25 -28
- package/cpp/api/JsiSkTextStyle.h +34 -24
- package/cpp/api/JsiSkTypeface.h +19 -12
- package/cpp/api/JsiSkTypefaceFactory.h +12 -12
- package/cpp/api/JsiSkTypefaceFontProvider.h +30 -25
- package/cpp/api/JsiSkTypefaceFontProviderFactory.h +14 -12
- package/cpp/api/JsiSkVertices.h +21 -18
- package/cpp/api/JsiSkiaContext.h +17 -17
- package/cpp/api/JsiSkottieFactory.h +16 -17
- package/cpp/api/JsiVideo.h +27 -25
- package/cpp/api/recorder/Convertor.h +31 -61
- package/cpp/api/recorder/DataTypes.h +8 -16
- package/cpp/api/recorder/JsiRecorder.h +83 -55
- package/cpp/api/recorder/RNRecorder.h +1 -1
- package/cpp/jsi/BoxedNativeObject.h +146 -0
- package/cpp/{jsi2 → jsi}/EnumMapper.h +4 -1
- package/cpp/{jsi2 → jsi}/NativeObject.h +120 -146
- package/cpp/jsi/RuntimeAwareCache.cpp +1 -1
- package/cpp/jsi/RuntimeAwareCache.h +26 -8
- package/cpp/jsi/ViewProperty.h +5 -11
- package/cpp/rnskia/RNSkJsiViewApi.h +20 -11
- package/cpp/rnskia/RNSkManager.cpp +29 -25
- package/cpp/rnskia/RNSkPictureView.h +1 -1
- package/cpp/rnwgpu/ArrayBuffer.h +5 -6
- package/cpp/rnwgpu/Canvas.h +4 -2
- package/cpp/rnwgpu/SurfaceRegistry.h +469 -131
- package/cpp/rnwgpu/api/GPU.cpp +4 -4
- package/cpp/rnwgpu/api/GPU.h +1 -1
- package/cpp/rnwgpu/api/GPUAdapter.cpp +12 -6
- package/cpp/rnwgpu/api/GPUAdapter.h +5 -4
- package/cpp/rnwgpu/api/GPUAdapterInfo.h +1 -1
- package/cpp/rnwgpu/api/GPUBindGroup.h +1 -1
- package/cpp/rnwgpu/api/GPUBindGroupLayout.h +1 -1
- package/cpp/rnwgpu/api/GPUBuffer.cpp +12 -2
- package/cpp/rnwgpu/api/GPUBuffer.h +4 -3
- package/cpp/rnwgpu/api/GPUCanvasContext.cpp +33 -19
- package/cpp/rnwgpu/api/GPUCanvasContext.h +4 -2
- package/cpp/rnwgpu/api/GPUCommandBuffer.h +1 -1
- package/cpp/rnwgpu/api/GPUCommandEncoder.h +1 -1
- package/cpp/rnwgpu/api/GPUCompilationInfo.h +1 -1
- package/cpp/rnwgpu/api/GPUCompilationMessage.h +1 -1
- package/cpp/rnwgpu/api/GPUComputePassEncoder.h +1 -1
- package/cpp/rnwgpu/api/GPUComputePipeline.h +1 -1
- package/cpp/rnwgpu/api/GPUDevice.cpp +38 -24
- package/cpp/rnwgpu/api/GPUDevice.h +12 -10
- package/cpp/rnwgpu/api/GPUDeviceLostInfo.h +1 -1
- package/cpp/rnwgpu/api/GPUError.h +1 -1
- package/cpp/rnwgpu/api/GPUExtent3D.h +1 -1
- package/cpp/rnwgpu/api/GPUExternalTexture.h +1 -1
- package/cpp/rnwgpu/api/GPUInternalError.h +1 -1
- package/cpp/rnwgpu/api/GPUOrigin2D.h +1 -1
- package/cpp/rnwgpu/api/GPUOrigin3D.h +1 -1
- package/cpp/rnwgpu/api/GPUOutOfMemoryError.h +1 -1
- package/cpp/rnwgpu/api/GPUPipelineLayout.h +1 -1
- package/cpp/rnwgpu/api/GPUQuerySet.h +1 -1
- package/cpp/rnwgpu/api/GPUQueue.cpp +6 -2
- package/cpp/rnwgpu/api/GPUQueue.h +4 -4
- package/cpp/rnwgpu/api/GPURenderBundle.h +1 -1
- package/cpp/rnwgpu/api/GPURenderBundleEncoder.h +1 -1
- package/cpp/rnwgpu/api/GPURenderPassEncoder.h +1 -1
- package/cpp/rnwgpu/api/GPURenderPipeline.h +1 -1
- package/cpp/rnwgpu/api/GPUSampler.h +1 -1
- package/cpp/rnwgpu/api/GPUShaderModule.cpp +8 -3
- package/cpp/rnwgpu/api/GPUShaderModule.h +4 -4
- package/cpp/rnwgpu/api/GPUSharedFence.h +1 -1
- package/cpp/rnwgpu/api/GPUSharedTextureMemory.h +1 -1
- package/cpp/rnwgpu/api/GPUSupportedLimits.h +1 -1
- package/cpp/rnwgpu/api/GPUTexture.h +1 -1
- package/cpp/rnwgpu/api/GPUTextureView.h +1 -1
- package/cpp/rnwgpu/api/GPUUncapturedErrorEvent.h +1 -1
- package/cpp/rnwgpu/api/GPUValidationError.h +1 -1
- package/cpp/rnwgpu/api/ImageBitmap.h +1 -1
- package/cpp/rnwgpu/api/RNWebGPU.h +21 -1
- package/cpp/rnwgpu/api/descriptors/GPUBindGroupDescriptor.h +1 -1
- package/cpp/rnwgpu/api/descriptors/GPUBindGroupEntry.h +1 -1
- package/cpp/rnwgpu/api/descriptors/GPUBindGroupLayoutDescriptor.h +1 -1
- package/cpp/rnwgpu/api/descriptors/GPUBindGroupLayoutEntry.h +1 -1
- package/cpp/rnwgpu/api/descriptors/GPUBlendComponent.h +1 -1
- package/cpp/rnwgpu/api/descriptors/GPUBlendState.h +1 -1
- package/cpp/rnwgpu/api/descriptors/GPUBufferBinding.h +1 -1
- package/cpp/rnwgpu/api/descriptors/GPUBufferBindingLayout.h +1 -1
- package/cpp/rnwgpu/api/descriptors/GPUBufferDescriptor.h +1 -1
- package/cpp/rnwgpu/api/descriptors/GPUCanvasConfiguration.h +1 -1
- package/cpp/rnwgpu/api/descriptors/GPUColor.h +1 -1
- package/cpp/rnwgpu/api/descriptors/GPUColorTargetState.h +1 -1
- package/cpp/rnwgpu/api/descriptors/GPUCommandBufferDescriptor.h +1 -1
- package/cpp/rnwgpu/api/descriptors/GPUCommandEncoderDescriptor.h +1 -1
- package/cpp/rnwgpu/api/descriptors/GPUComputePassDescriptor.h +1 -1
- package/cpp/rnwgpu/api/descriptors/GPUComputePassTimestampWrites.h +1 -1
- package/cpp/rnwgpu/api/descriptors/GPUComputePipelineDescriptor.h +1 -1
- package/cpp/rnwgpu/api/descriptors/GPUDawnTogglesDescriptor.h +1 -1
- package/cpp/rnwgpu/api/descriptors/GPUDepthStencilState.h +1 -1
- package/cpp/rnwgpu/api/descriptors/GPUDeviceDescriptor.h +1 -1
- package/cpp/rnwgpu/api/descriptors/GPUExternalTextureBindingLayout.h +1 -1
- package/cpp/rnwgpu/api/descriptors/GPUExternalTextureDescriptor.h +1 -1
- package/cpp/rnwgpu/api/descriptors/GPUFragmentState.h +1 -1
- package/cpp/rnwgpu/api/descriptors/GPUImageCopyBuffer.h +1 -1
- package/cpp/rnwgpu/api/descriptors/GPUImageCopyExternalImage.h +1 -1
- package/cpp/rnwgpu/api/descriptors/GPUImageCopyTexture.h +1 -1
- package/cpp/rnwgpu/api/descriptors/GPUImageCopyTextureTagged.h +1 -1
- package/cpp/rnwgpu/api/descriptors/GPUImageDataLayout.h +1 -1
- package/cpp/rnwgpu/api/descriptors/GPUMultisampleState.h +1 -1
- package/cpp/rnwgpu/api/descriptors/GPUPipelineLayoutDescriptor.h +1 -1
- package/cpp/rnwgpu/api/descriptors/GPUPrimitiveState.h +1 -1
- package/cpp/rnwgpu/api/descriptors/GPUProgrammableStage.h +1 -1
- package/cpp/rnwgpu/api/descriptors/GPUQuerySetDescriptor.h +1 -1
- package/cpp/rnwgpu/api/descriptors/GPUQueueDescriptor.h +1 -1
- package/cpp/rnwgpu/api/descriptors/GPURenderBundleDescriptor.h +1 -1
- package/cpp/rnwgpu/api/descriptors/GPURenderBundleEncoderDescriptor.h +1 -1
- package/cpp/rnwgpu/api/descriptors/GPURenderPassColorAttachment.h +1 -1
- package/cpp/rnwgpu/api/descriptors/GPURenderPassDepthStencilAttachment.h +1 -1
- package/cpp/rnwgpu/api/descriptors/GPURenderPassDescriptor.h +1 -1
- package/cpp/rnwgpu/api/descriptors/GPURenderPassTimestampWrites.h +1 -1
- package/cpp/rnwgpu/api/descriptors/GPURenderPipelineDescriptor.h +1 -1
- package/cpp/rnwgpu/api/descriptors/GPURequestAdapterOptions.h +1 -1
- package/cpp/rnwgpu/api/descriptors/GPUSamplerBindingLayout.h +1 -1
- package/cpp/rnwgpu/api/descriptors/GPUSamplerDescriptor.h +1 -1
- package/cpp/rnwgpu/api/descriptors/GPUShaderModuleCompilationHint.h +1 -1
- package/cpp/rnwgpu/api/descriptors/GPUShaderModuleDescriptor.h +1 -1
- package/cpp/rnwgpu/api/descriptors/GPUSharedFenceDescriptor.h +1 -1
- package/cpp/rnwgpu/api/descriptors/GPUSharedFenceState.h +1 -1
- package/cpp/rnwgpu/api/descriptors/GPUSharedTextureMemoryDescriptor.h +1 -1
- package/cpp/rnwgpu/api/descriptors/GPUStencilFaceState.h +1 -1
- package/cpp/rnwgpu/api/descriptors/GPUStorageTextureBindingLayout.h +1 -1
- package/cpp/rnwgpu/api/descriptors/GPUTextureBindingLayout.h +1 -1
- package/cpp/rnwgpu/api/descriptors/GPUTextureDescriptor.h +1 -1
- package/cpp/rnwgpu/api/descriptors/GPUTextureViewDescriptor.h +1 -1
- package/cpp/rnwgpu/api/descriptors/GPUUncapturedErrorEventInit.h +1 -1
- package/cpp/rnwgpu/api/descriptors/GPUVertexAttribute.h +1 -1
- package/cpp/rnwgpu/api/descriptors/GPUVertexBufferLayout.h +1 -1
- package/cpp/rnwgpu/api/descriptors/GPUVertexState.h +1 -1
- package/cpp/rnwgpu/api/descriptors/Unions.h +1 -1
- package/cpp/rnwgpu/async/AsyncTaskHandle.cpp +20 -21
- package/cpp/rnwgpu/async/RuntimeContext.cpp +5 -0
- package/cpp/rnwgpu/async/RuntimeContext.h +15 -2
- package/lib/commonjs/external/reanimated/renderHelpers.d.ts +15 -0
- package/lib/commonjs/external/reanimated/renderHelpers.js +30 -1
- package/lib/commonjs/external/reanimated/renderHelpers.js.map +1 -1
- package/lib/commonjs/skia/NativeSetup.js +4 -0
- package/lib/commonjs/skia/NativeSetup.js.map +1 -1
- package/lib/commonjs/skia/SkiaWorkletSerialization.d.ts +1 -0
- package/lib/commonjs/skia/SkiaWorkletSerialization.js +66 -0
- package/lib/commonjs/skia/SkiaWorkletSerialization.js.map +1 -0
- package/lib/commonjs/sksg/Container.native.js +20 -1
- package/lib/commonjs/sksg/Container.native.js.map +1 -1
- package/lib/commonjs/views/WebGPUCanvas.d.ts +1 -0
- package/lib/commonjs/views/WebGPUCanvas.js +13 -0
- package/lib/commonjs/views/WebGPUCanvas.js.map +1 -1
- package/lib/module/external/reanimated/renderHelpers.d.ts +15 -0
- package/lib/module/external/reanimated/renderHelpers.js +29 -0
- package/lib/module/external/reanimated/renderHelpers.js.map +1 -1
- package/lib/module/skia/NativeSetup.js +4 -0
- package/lib/module/skia/NativeSetup.js.map +1 -1
- package/lib/module/skia/SkiaWorkletSerialization.d.ts +1 -0
- package/lib/module/skia/SkiaWorkletSerialization.js +59 -0
- package/lib/module/skia/SkiaWorkletSerialization.js.map +1 -0
- package/lib/module/sksg/Container.native.js +21 -2
- package/lib/module/sksg/Container.native.js.map +1 -1
- package/lib/module/views/WebGPUCanvas.d.ts +1 -0
- package/lib/module/views/WebGPUCanvas.js +14 -1
- package/lib/module/views/WebGPUCanvas.js.map +1 -1
- package/lib/typescript/lib/commonjs/external/reanimated/renderHelpers.d.ts +2 -0
- package/lib/typescript/lib/commonjs/skia/SkiaWorkletSerialization.d.ts +2 -0
- package/lib/typescript/lib/module/external/reanimated/renderHelpers.d.ts +15 -0
- package/lib/typescript/lib/module/skia/SkiaWorkletSerialization.d.ts +1 -0
- package/lib/typescript/src/external/reanimated/renderHelpers.d.ts +15 -0
- package/lib/typescript/src/skia/SkiaWorkletSerialization.d.ts +1 -0
- package/lib/typescript/src/views/WebGPUCanvas.d.ts +1 -0
- package/package.json +12 -8
- package/react-native-skia.podspec +1 -2
- package/src/external/reanimated/renderHelpers.ts +30 -0
- package/src/skia/NativeSetup.ts +5 -0
- package/src/skia/SkiaWorkletSerialization.ts +67 -0
- package/src/sksg/Container.native.ts +40 -2
- package/src/views/WebGPUCanvas.tsx +17 -1
- package/cpp/api/JsiSkHostObjects.h +0 -257
- package/cpp/dawn/include/dawn/dawn_proc.h +0 -53
- package/cpp/dawn/include/dawn/dawn_proc_table.h +0 -330
- package/cpp/dawn/include/dawn/dawn_thread_dispatch_proc.h +0 -47
- package/cpp/dawn/include/dawn/dawn_version.h +0 -41
- package/cpp/dawn/include/dawn/native/D3D11Backend.h +0 -65
- package/cpp/dawn/include/dawn/native/D3D12Backend.h +0 -86
- package/cpp/dawn/include/dawn/native/D3DBackend.h +0 -56
- package/cpp/dawn/include/dawn/native/DawnNative.h +0 -369
- package/cpp/dawn/include/dawn/native/MetalBackend.h +0 -56
- package/cpp/dawn/include/dawn/native/NullBackend.h +0 -39
- package/cpp/dawn/include/dawn/native/OpenGLBackend.h +0 -89
- package/cpp/dawn/include/dawn/native/VulkanBackend.h +0 -183
- package/cpp/dawn/include/dawn/native/WebGPUBackend.h +0 -49
- package/cpp/dawn/include/dawn/native/dawn_native_export.h +0 -49
- package/cpp/dawn/include/dawn/platform/DawnPlatform.h +0 -210
- package/cpp/dawn/include/dawn/platform/dawn_platform_export.h +0 -49
- package/cpp/dawn/include/dawn/replay/Replay.h +0 -99
- package/cpp/dawn/include/dawn/replay/dawn_replay_export.h +0 -49
- package/cpp/dawn/include/dawn/webgpu_cpp_print.h +0 -2844
- package/cpp/dawn/include/tint/tint.h +0 -90
- package/cpp/dawn/include/webgpu/webgpu.h +0 -4987
- package/cpp/dawn/include/webgpu/webgpu_cpp.h +0 -10080
- package/cpp/dawn/include/webgpu/webgpu_cpp_chained_struct.h +0 -57
- package/cpp/dawn/include/webgpu/webgpu_enum_class_bitmasks.h +0 -161
- package/cpp/dawn/include/webgpu/webgpu_glfw.h +0 -88
- package/cpp/jsi/JsiHostObject.cpp +0 -137
- package/cpp/jsi/JsiHostObject.h +0 -385
- package/cpp/skia/src/gpu/graphite/ContextOptionsPriv.h +0 -45
- package/cpp/skia/src/gpu/graphite/ResourceTypes.h +0 -360
- package/cpp/skia/src/gpu/graphite/TextureProxyView.h +0 -105
- package/libs/.graphite +0 -1
- /package/cpp/{jsi2 → jsi}/JSIConverter.h +0 -0
- /package/cpp/{jsi2 → jsi}/Promise.cpp +0 -0
- /package/cpp/{jsi2 → jsi}/Promise.h +0 -0
package/cpp/api/JsiSkSurface.h
CHANGED
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
#include <jsi/jsi.h>
|
|
9
9
|
|
|
10
10
|
#include "JsiSkDispatcher.h"
|
|
11
|
-
#include "
|
|
11
|
+
#include "JsiSkNativeObjects.h"
|
|
12
12
|
#include "JsiTextureInfo.h"
|
|
13
13
|
|
|
14
14
|
#include "JsiSkCanvas.h"
|
|
@@ -30,15 +30,18 @@ namespace RNSkia {
|
|
|
30
30
|
|
|
31
31
|
namespace jsi = facebook::jsi;
|
|
32
32
|
|
|
33
|
-
class JsiSkSurface
|
|
33
|
+
class JsiSkSurface
|
|
34
|
+
: public JsiSkWrappingSkPtrNativeObject<JsiSkSurface, SkSurface> {
|
|
34
35
|
private:
|
|
35
36
|
std::shared_ptr<Dispatcher> _dispatcher;
|
|
36
37
|
|
|
37
38
|
public:
|
|
39
|
+
static constexpr const char *CLASS_NAME = "Surface";
|
|
40
|
+
|
|
38
41
|
JsiSkSurface(std::shared_ptr<RNSkPlatformContext> context,
|
|
39
42
|
sk_sp<SkSurface> surface)
|
|
40
|
-
:
|
|
41
|
-
|
|
43
|
+
: JsiSkWrappingSkPtrNativeObject<JsiSkSurface, SkSurface>(
|
|
44
|
+
std::move(context), std::move(surface)) {
|
|
42
45
|
// Get the dispatcher for the current thread
|
|
43
46
|
_dispatcher = Dispatcher::getDispatcher();
|
|
44
47
|
// Process any pending operations
|
|
@@ -63,8 +66,6 @@ public:
|
|
|
63
66
|
}
|
|
64
67
|
}
|
|
65
68
|
|
|
66
|
-
EXPORT_JSI_API_TYPENAME(JsiSkSurface, Surface)
|
|
67
|
-
|
|
68
69
|
// TODO-API: Properties?
|
|
69
70
|
JSI_HOST_FUNCTION(width) { return static_cast<double>(getObject()->width()); }
|
|
70
71
|
JSI_HOST_FUNCTION(height) {
|
|
@@ -78,8 +79,7 @@ public:
|
|
|
78
79
|
// Keep a reference to the owning surface so the canvas can read pixels back
|
|
79
80
|
// through a snapshot on Graphite (which lacks synchronous canvas readback).
|
|
80
81
|
canvas->setSurface(surface);
|
|
81
|
-
return
|
|
82
|
-
getContext());
|
|
82
|
+
return makeJsiObject(runtime, std::move(canvas));
|
|
83
83
|
}
|
|
84
84
|
|
|
85
85
|
JSI_HOST_FUNCTION(flush) {
|
|
@@ -124,15 +124,12 @@ public:
|
|
|
124
124
|
}
|
|
125
125
|
#endif
|
|
126
126
|
if (count > 1 && arguments[1].isObject()) {
|
|
127
|
-
auto jsiImage =
|
|
128
|
-
arguments[1].asObject(runtime).asHostObject<JsiSkImage>(runtime);
|
|
127
|
+
auto jsiImage = getJsiObject<JsiSkImage>(runtime, arguments[1]);
|
|
129
128
|
jsiImage->setObject(image);
|
|
130
129
|
return jsi::Value(runtime, arguments[1]);
|
|
131
130
|
}
|
|
132
|
-
|
|
133
|
-
std::make_shared<JsiSkImage>(getContext(), std::move(image));
|
|
134
|
-
return JSI_CREATE_HOST_OBJECT_WITH_MEMORY_PRESSURE(
|
|
135
|
-
runtime, hostObjectInstance, getContext());
|
|
131
|
+
return makeJsiObject(
|
|
132
|
+
runtime, std::make_shared<JsiSkImage>(getContext(), std::move(image)));
|
|
136
133
|
}
|
|
137
134
|
|
|
138
135
|
JSI_HOST_FUNCTION(getNativeTextureUnstable) {
|
|
@@ -140,7 +137,7 @@ public:
|
|
|
140
137
|
return JsiTextureInfo::toValue(runtime, texInfo);
|
|
141
138
|
}
|
|
142
139
|
|
|
143
|
-
size_t getMemoryPressure()
|
|
140
|
+
size_t getMemoryPressure() override {
|
|
144
141
|
if (isDisposed()) {
|
|
145
142
|
return 0;
|
|
146
143
|
}
|
|
@@ -196,15 +193,18 @@ public:
|
|
|
196
193
|
return estimated;
|
|
197
194
|
}
|
|
198
195
|
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
196
|
+
static void definePrototype(jsi::Runtime &runtime, jsi::Object &prototype) {
|
|
197
|
+
installCommon(runtime, prototype);
|
|
198
|
+
installHostMethod(runtime, prototype, "width", &JsiSkSurface::width);
|
|
199
|
+
installHostMethod(runtime, prototype, "height", &JsiSkSurface::height);
|
|
200
|
+
installHostMethod(runtime, prototype, "getCanvas",
|
|
201
|
+
&JsiSkSurface::getCanvas);
|
|
202
|
+
installHostMethod(runtime, prototype, "makeImageSnapshot",
|
|
203
|
+
&JsiSkSurface::makeImageSnapshot);
|
|
204
|
+
installHostMethod(runtime, prototype, "flush", &JsiSkSurface::flush);
|
|
205
|
+
installHostMethod(runtime, prototype, "getNativeTextureUnstable",
|
|
206
|
+
&JsiSkSurface::getNativeTextureUnstable);
|
|
207
|
+
}
|
|
208
208
|
};
|
|
209
209
|
|
|
210
210
|
} // namespace RNSkia
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
|
|
6
6
|
#include <jsi/jsi.h>
|
|
7
7
|
|
|
8
|
-
#include "
|
|
8
|
+
#include "JsiSkNativeObjects.h"
|
|
9
9
|
|
|
10
10
|
#include "JsiSkSurface.h"
|
|
11
11
|
|
|
@@ -20,8 +20,10 @@ namespace RNSkia {
|
|
|
20
20
|
|
|
21
21
|
namespace jsi = facebook::jsi;
|
|
22
22
|
|
|
23
|
-
class JsiSkSurfaceFactory : public
|
|
23
|
+
class JsiSkSurfaceFactory : public JsiSkNativeObject<JsiSkSurfaceFactory> {
|
|
24
24
|
public:
|
|
25
|
+
static constexpr const char *CLASS_NAME = "SurfaceFactory";
|
|
26
|
+
|
|
25
27
|
JSI_HOST_FUNCTION(Make) {
|
|
26
28
|
auto width = static_cast<int>(arguments[0].asNumber());
|
|
27
29
|
auto height = static_cast<int>(arguments[1].asNumber());
|
|
@@ -30,10 +32,8 @@ public:
|
|
|
30
32
|
if (surface == nullptr) {
|
|
31
33
|
return jsi::Value::null();
|
|
32
34
|
}
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
return JSI_CREATE_HOST_OBJECT_WITH_MEMORY_PRESSURE(
|
|
36
|
-
runtime, hostObjectInstance, getContext());
|
|
35
|
+
return makeJsiObject(runtime, std::make_shared<JsiSkSurface>(
|
|
36
|
+
getContext(), std::move(surface)));
|
|
37
37
|
}
|
|
38
38
|
|
|
39
39
|
JSI_HOST_FUNCTION(MakeOffscreen) {
|
|
@@ -56,21 +56,20 @@ public:
|
|
|
56
56
|
if (surface == nullptr) {
|
|
57
57
|
return jsi::Value::null();
|
|
58
58
|
}
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
return JSI_CREATE_HOST_OBJECT_WITH_MEMORY_PRESSURE(
|
|
62
|
-
runtime, hostObjectInstance, getContext());
|
|
59
|
+
return makeJsiObject(runtime, std::make_shared<JsiSkSurface>(
|
|
60
|
+
getContext(), std::move(surface)));
|
|
63
61
|
}
|
|
64
62
|
|
|
65
|
-
|
|
66
|
-
JSI_EXPORT_FUNC(JsiSkSurfaceFactory, MakeOffscreen))
|
|
67
|
-
|
|
68
|
-
size_t getMemoryPressure() const override { return 2048; }
|
|
63
|
+
size_t getMemoryPressure() override { return 2048; }
|
|
69
64
|
|
|
70
|
-
|
|
65
|
+
static void definePrototype(jsi::Runtime &runtime, jsi::Object &prototype) {
|
|
66
|
+
installHostMethod(runtime, prototype, "Make", &JsiSkSurfaceFactory::Make);
|
|
67
|
+
installHostMethod(runtime, prototype, "MakeOffscreen",
|
|
68
|
+
&JsiSkSurfaceFactory::MakeOffscreen);
|
|
69
|
+
}
|
|
71
70
|
|
|
72
71
|
explicit JsiSkSurfaceFactory(std::shared_ptr<RNSkPlatformContext> context)
|
|
73
|
-
:
|
|
72
|
+
: JsiSkNativeObject<JsiSkSurfaceFactory>(std::move(context)) {}
|
|
74
73
|
};
|
|
75
74
|
|
|
76
75
|
} // namespace RNSkia
|
package/cpp/api/JsiSkTextBlob.h
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
|
|
6
6
|
#include <jsi/jsi.h>
|
|
7
7
|
|
|
8
|
-
#include "
|
|
8
|
+
#include "JsiSkNativeObjects.h"
|
|
9
9
|
|
|
10
10
|
#pragma clang diagnostic push
|
|
11
11
|
#pragma clang diagnostic ignored "-Wdocumentation"
|
|
@@ -18,14 +18,17 @@ namespace RNSkia {
|
|
|
18
18
|
|
|
19
19
|
namespace jsi = facebook::jsi;
|
|
20
20
|
|
|
21
|
-
class JsiSkTextBlob
|
|
21
|
+
class JsiSkTextBlob
|
|
22
|
+
: public JsiSkWrappingSkPtrNativeObject<JsiSkTextBlob, SkTextBlob> {
|
|
22
23
|
public:
|
|
24
|
+
static constexpr const char *CLASS_NAME = "TextBlob";
|
|
25
|
+
|
|
23
26
|
JsiSkTextBlob(std::shared_ptr<RNSkPlatformContext> context,
|
|
24
27
|
sk_sp<SkTextBlob> shader)
|
|
25
|
-
:
|
|
26
|
-
|
|
28
|
+
: JsiSkWrappingSkPtrNativeObject<JsiSkTextBlob, SkTextBlob>(
|
|
29
|
+
std::move(context), std::move(shader)) {}
|
|
27
30
|
|
|
28
|
-
size_t getMemoryPressure()
|
|
31
|
+
size_t getMemoryPressure() override {
|
|
29
32
|
auto textBlob = getObject();
|
|
30
33
|
if (!textBlob)
|
|
31
34
|
return 0;
|
|
@@ -37,9 +40,13 @@ public:
|
|
|
37
40
|
1024; // Area estimation + base overhead
|
|
38
41
|
}
|
|
39
42
|
|
|
40
|
-
|
|
43
|
+
static sk_sp<SkTextBlob> fromValue(jsi::Runtime &runtime,
|
|
44
|
+
const jsi::Value &obj) {
|
|
45
|
+
return objectFromValue(runtime, obj);
|
|
46
|
+
}
|
|
41
47
|
|
|
42
|
-
|
|
43
|
-
|
|
48
|
+
static void definePrototype(jsi::Runtime &runtime, jsi::Object &prototype) {
|
|
49
|
+
installCommon(runtime, prototype);
|
|
50
|
+
}
|
|
44
51
|
};
|
|
45
52
|
} // namespace RNSkia
|
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
#include <jsi/jsi.h>
|
|
8
8
|
|
|
9
9
|
#include "JsiSkFont.h"
|
|
10
|
-
#include "
|
|
10
|
+
#include "JsiSkNativeObjects.h"
|
|
11
11
|
#include "JsiSkRSXform.h"
|
|
12
12
|
#include "JsiSkTextBlob.h"
|
|
13
13
|
|
|
@@ -22,16 +22,16 @@ namespace RNSkia {
|
|
|
22
22
|
|
|
23
23
|
namespace jsi = facebook::jsi;
|
|
24
24
|
|
|
25
|
-
class JsiSkTextBlobFactory : public
|
|
25
|
+
class JsiSkTextBlobFactory : public JsiSkNativeObject<JsiSkTextBlobFactory> {
|
|
26
26
|
public:
|
|
27
|
+
static constexpr const char *CLASS_NAME = "TextBlobFactory";
|
|
28
|
+
|
|
27
29
|
JSI_HOST_FUNCTION(MakeFromText) {
|
|
28
30
|
auto str = arguments[0].asString(runtime).utf8(runtime);
|
|
29
31
|
auto font = JsiSkFont::fromValue(runtime, arguments[1]);
|
|
30
32
|
auto textBlob = SkTextBlob::MakeFromString(str.c_str(), *font);
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
return JSI_CREATE_HOST_OBJECT_WITH_MEMORY_PRESSURE(
|
|
34
|
-
runtime, hostObjectInstance, getContext());
|
|
33
|
+
return makeJsiObject(runtime, std::make_shared<JsiSkTextBlob>(
|
|
34
|
+
getContext(), std::move(textBlob)));
|
|
35
35
|
}
|
|
36
36
|
|
|
37
37
|
JSI_HOST_FUNCTION(MakeFromGlyphs) {
|
|
@@ -47,10 +47,8 @@ public:
|
|
|
47
47
|
auto textBlob =
|
|
48
48
|
SkTextBlob::MakeFromText(glyphs.data(), glyphs.size() * bytesPerGlyph,
|
|
49
49
|
*font, SkTextEncoding::kGlyphID);
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
return JSI_CREATE_HOST_OBJECT_WITH_MEMORY_PRESSURE(
|
|
53
|
-
runtime, hostObjectInstance, getContext());
|
|
50
|
+
return makeJsiObject(runtime, std::make_shared<JsiSkTextBlob>(
|
|
51
|
+
getContext(), std::move(textBlob)));
|
|
54
52
|
}
|
|
55
53
|
|
|
56
54
|
JSI_HOST_FUNCTION(MakeFromRSXform) {
|
|
@@ -68,10 +66,8 @@ public:
|
|
|
68
66
|
auto x = SkSpan(rsxforms.data(), rsxforms.size());
|
|
69
67
|
auto textBlob =
|
|
70
68
|
SkTextBlob::MakeFromRSXform(str.c_str(), str.length(), x, *font);
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
return JSI_CREATE_HOST_OBJECT_WITH_MEMORY_PRESSURE(
|
|
74
|
-
runtime, hostObjectInstance, getContext());
|
|
69
|
+
return makeJsiObject(runtime, std::make_shared<JsiSkTextBlob>(
|
|
70
|
+
getContext(), std::move(textBlob)));
|
|
75
71
|
}
|
|
76
72
|
|
|
77
73
|
JSI_HOST_FUNCTION(MakeFromRSXformGlyphs) {
|
|
@@ -97,24 +93,25 @@ public:
|
|
|
97
93
|
auto textBlob = SkTextBlob::MakeFromRSXform(
|
|
98
94
|
glyphs.data(), glyphs.size() * bytesPerGlyph, x, *font,
|
|
99
95
|
SkTextEncoding::kGlyphID);
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
return JSI_CREATE_HOST_OBJECT_WITH_MEMORY_PRESSURE(
|
|
103
|
-
runtime, hostObjectInstance, getContext());
|
|
96
|
+
return makeJsiObject(runtime, std::make_shared<JsiSkTextBlob>(
|
|
97
|
+
getContext(), std::move(textBlob)));
|
|
104
98
|
}
|
|
105
99
|
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
100
|
+
size_t getMemoryPressure() override { return 2048; }
|
|
101
|
+
|
|
102
|
+
static void definePrototype(jsi::Runtime &runtime, jsi::Object &prototype) {
|
|
103
|
+
installHostMethod(runtime, prototype, "MakeFromText",
|
|
104
|
+
&JsiSkTextBlobFactory::MakeFromText);
|
|
105
|
+
installHostMethod(runtime, prototype, "MakeFromGlyphs",
|
|
106
|
+
&JsiSkTextBlobFactory::MakeFromGlyphs);
|
|
107
|
+
installHostMethod(runtime, prototype, "MakeFromRSXform",
|
|
108
|
+
&JsiSkTextBlobFactory::MakeFromRSXform);
|
|
109
|
+
installHostMethod(runtime, prototype, "MakeFromRSXformGlyphs",
|
|
110
|
+
&JsiSkTextBlobFactory::MakeFromRSXformGlyphs);
|
|
111
|
+
}
|
|
115
112
|
|
|
116
113
|
explicit JsiSkTextBlobFactory(std::shared_ptr<RNSkPlatformContext> context)
|
|
117
|
-
:
|
|
114
|
+
: JsiSkNativeObject<JsiSkTextBlobFactory>(std::move(context)) {}
|
|
118
115
|
};
|
|
119
116
|
|
|
120
117
|
} // namespace RNSkia
|
package/cpp/api/JsiSkTextStyle.h
CHANGED
|
@@ -26,6 +26,16 @@ namespace para = skia::textlayout;
|
|
|
26
26
|
*/
|
|
27
27
|
class JsiSkTextStyle {
|
|
28
28
|
public:
|
|
29
|
+
// A property set to undefined or null is treated as absent, like on web.
|
|
30
|
+
static bool hasValue(jsi::Runtime &runtime, const jsi::Object &object,
|
|
31
|
+
const char *name) {
|
|
32
|
+
if (!object.hasProperty(runtime, name)) {
|
|
33
|
+
return false;
|
|
34
|
+
}
|
|
35
|
+
auto propValue = object.getProperty(runtime, name);
|
|
36
|
+
return !propValue.isUndefined() && !propValue.isNull();
|
|
37
|
+
}
|
|
38
|
+
|
|
29
39
|
static para::TextStyle fromValue(jsi::Runtime &runtime,
|
|
30
40
|
const jsi::Value &value) {
|
|
31
41
|
|
|
@@ -43,35 +53,35 @@ public:
|
|
|
43
53
|
|
|
44
54
|
auto object = value.asObject(runtime);
|
|
45
55
|
|
|
46
|
-
if (
|
|
56
|
+
if (hasValue(runtime, object, "backgroundColor")) {
|
|
47
57
|
auto propValue = object.getProperty(runtime, "backgroundColor");
|
|
48
58
|
SkPaint p;
|
|
49
59
|
p.setColor(JsiSkColor::fromValue(runtime, propValue));
|
|
50
60
|
retVal.setBackgroundPaint(p);
|
|
51
61
|
}
|
|
52
|
-
if (
|
|
62
|
+
if (hasValue(runtime, object, "color")) {
|
|
53
63
|
auto propValue = object.getProperty(runtime, "color");
|
|
54
64
|
retVal.setColor(JsiSkColor::fromValue(runtime, propValue));
|
|
55
65
|
}
|
|
56
|
-
if (
|
|
66
|
+
if (hasValue(runtime, object, "decoration")) {
|
|
57
67
|
auto propValue = object.getProperty(runtime, "decoration");
|
|
58
68
|
retVal.setDecoration(
|
|
59
69
|
static_cast<para::TextDecoration>(propValue.asNumber()));
|
|
60
70
|
}
|
|
61
|
-
if (
|
|
71
|
+
if (hasValue(runtime, object, "decorationColor")) {
|
|
62
72
|
auto propValue = object.getProperty(runtime, "decorationColor");
|
|
63
73
|
retVal.setDecorationColor(JsiSkColor::fromValue(runtime, propValue));
|
|
64
74
|
}
|
|
65
|
-
if (
|
|
75
|
+
if (hasValue(runtime, object, "decorationThickness")) {
|
|
66
76
|
auto propValue = object.getProperty(runtime, "decorationThickness");
|
|
67
77
|
retVal.setDecorationThicknessMultiplier(propValue.asNumber());
|
|
68
78
|
}
|
|
69
|
-
if (
|
|
79
|
+
if (hasValue(runtime, object, "decorationStyle")) {
|
|
70
80
|
auto propValue = object.getProperty(runtime, "decorationStyle");
|
|
71
81
|
retVal.setDecorationStyle(
|
|
72
82
|
static_cast<para::TextDecorationStyle>(propValue.asNumber()));
|
|
73
83
|
}
|
|
74
|
-
if (
|
|
84
|
+
if (hasValue(runtime, object, "fontFamilies")) {
|
|
75
85
|
auto propValue = object.getProperty(runtime, "fontFamilies")
|
|
76
86
|
.asObject(runtime)
|
|
77
87
|
.asArray(runtime);
|
|
@@ -85,7 +95,7 @@ public:
|
|
|
85
95
|
}
|
|
86
96
|
retVal.setFontFamilies(families);
|
|
87
97
|
}
|
|
88
|
-
if (
|
|
98
|
+
if (hasValue(runtime, object, "fontFeatures")) {
|
|
89
99
|
auto propValue = object.getProperty(runtime, "fontFeatures")
|
|
90
100
|
.asObject(runtime)
|
|
91
101
|
.asArray(runtime);
|
|
@@ -100,58 +110,58 @@ public:
|
|
|
100
110
|
retVal.addFontFeature(SkString(name), value);
|
|
101
111
|
}
|
|
102
112
|
}
|
|
103
|
-
if (
|
|
113
|
+
if (hasValue(runtime, object, "fontSize")) {
|
|
104
114
|
auto propValue = object.getProperty(runtime, "fontSize");
|
|
105
115
|
retVal.setFontSize(propValue.asNumber());
|
|
106
116
|
}
|
|
107
|
-
if (
|
|
117
|
+
if (hasValue(runtime, object, "fontStyle")) {
|
|
108
118
|
auto propValue =
|
|
109
119
|
object.getProperty(runtime, "fontStyle").asObject(runtime);
|
|
110
120
|
auto weight = static_cast<SkFontStyle::Weight>(
|
|
111
|
-
|
|
121
|
+
hasValue(runtime, propValue, "weight")
|
|
112
122
|
? propValue.getProperty(runtime, "weight").asNumber()
|
|
113
123
|
: static_cast<double>(SkFontStyle::Weight::kNormal_Weight));
|
|
114
124
|
|
|
115
125
|
auto width = static_cast<SkFontStyle::Width>(
|
|
116
|
-
|
|
126
|
+
hasValue(runtime, propValue, "width")
|
|
117
127
|
? propValue.getProperty(runtime, "width").asNumber()
|
|
118
128
|
: static_cast<double>(SkFontStyle::Width::kNormal_Width));
|
|
119
129
|
|
|
120
130
|
auto slant = static_cast<SkFontStyle::Slant>(
|
|
121
|
-
|
|
131
|
+
hasValue(runtime, propValue, "slant")
|
|
122
132
|
? propValue.getProperty(runtime, "slant").asNumber()
|
|
123
133
|
: static_cast<double>(SkFontStyle::Slant::kUpright_Slant));
|
|
124
134
|
|
|
125
135
|
retVal.setFontStyle(SkFontStyle(weight, width, slant));
|
|
126
136
|
}
|
|
127
|
-
if (
|
|
137
|
+
if (hasValue(runtime, object, "foregroundColor")) {
|
|
128
138
|
auto propValue = object.getProperty(runtime, "foregroundColor");
|
|
129
139
|
SkPaint p;
|
|
130
140
|
p.setColor(JsiSkColor::fromValue(runtime, propValue));
|
|
131
141
|
retVal.setForegroundColor(p);
|
|
132
142
|
}
|
|
133
|
-
if (
|
|
143
|
+
if (hasValue(runtime, object, "heightMultiplier")) {
|
|
134
144
|
auto propValue = object.getProperty(runtime, "heightMultiplier");
|
|
135
145
|
retVal.setHeight(propValue.asNumber());
|
|
136
146
|
retVal.setHeightOverride(true);
|
|
137
147
|
}
|
|
138
|
-
if (
|
|
148
|
+
if (hasValue(runtime, object, "halfLeading")) {
|
|
139
149
|
auto propValue = object.getProperty(runtime, "halfLeading");
|
|
140
150
|
retVal.setHalfLeading(propValue.getBool());
|
|
141
151
|
}
|
|
142
|
-
if (
|
|
152
|
+
if (hasValue(runtime, object, "letterSpacing")) {
|
|
143
153
|
auto propValue = object.getProperty(runtime, "letterSpacing");
|
|
144
154
|
retVal.setLetterSpacing(propValue.asNumber());
|
|
145
155
|
}
|
|
146
|
-
if (
|
|
156
|
+
if (hasValue(runtime, object, "wordSpacing")) {
|
|
147
157
|
auto propValue = object.getProperty(runtime, "wordSpacing");
|
|
148
158
|
retVal.setWordSpacing(propValue.asNumber());
|
|
149
159
|
}
|
|
150
|
-
if (
|
|
160
|
+
if (hasValue(runtime, object, "locale")) {
|
|
151
161
|
auto propValue = object.getProperty(runtime, "locale");
|
|
152
162
|
retVal.setLocale(SkString(propValue.asString(runtime).utf8(runtime)));
|
|
153
163
|
}
|
|
154
|
-
if (
|
|
164
|
+
if (hasValue(runtime, object, "shadows")) {
|
|
155
165
|
auto propValue = object.getProperty(runtime, "shadows")
|
|
156
166
|
.asObject(runtime)
|
|
157
167
|
.asArray(runtime);
|
|
@@ -159,24 +169,24 @@ public:
|
|
|
159
169
|
retVal.resetShadows();
|
|
160
170
|
for (size_t i = 0; i < size; ++i) {
|
|
161
171
|
auto element = propValue.getValueAtIndex(runtime, i).asObject(runtime);
|
|
162
|
-
auto color =
|
|
172
|
+
auto color = hasValue(runtime, element, "color")
|
|
163
173
|
? JsiSkColor::fromValue(
|
|
164
174
|
runtime, element.getProperty(runtime, "color"))
|
|
165
175
|
: SK_ColorBLACK;
|
|
166
176
|
SkPoint offset =
|
|
167
|
-
|
|
177
|
+
hasValue(runtime, element, "offset")
|
|
168
178
|
? *JsiSkPoint::fromValue(runtime,
|
|
169
179
|
element.getProperty(runtime, "offset"))
|
|
170
180
|
.get()
|
|
171
181
|
: SkPoint::Make(0, 0);
|
|
172
182
|
auto blurSigma =
|
|
173
|
-
|
|
183
|
+
hasValue(runtime, element, "blurRadius")
|
|
174
184
|
? element.getProperty(runtime, "blurRadius").asNumber()
|
|
175
185
|
: 0;
|
|
176
186
|
retVal.addShadow(para::TextShadow(color, offset, blurSigma));
|
|
177
187
|
}
|
|
178
188
|
}
|
|
179
|
-
if (
|
|
189
|
+
if (hasValue(runtime, object, "textBaseline")) {
|
|
180
190
|
auto propValue = object.getProperty(runtime, "textBaseline");
|
|
181
191
|
retVal.setTextBaseline(
|
|
182
192
|
static_cast<para::TextBaseline>(propValue.asNumber()));
|
package/cpp/api/JsiSkTypeface.h
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
|
|
7
7
|
#include <jsi/jsi.h>
|
|
8
8
|
|
|
9
|
-
#include "
|
|
9
|
+
#include "JsiSkNativeObjects.h"
|
|
10
10
|
#include "utils/RNSkLog.h"
|
|
11
11
|
|
|
12
12
|
#pragma clang diagnostic push
|
|
@@ -22,15 +22,15 @@ namespace RNSkia {
|
|
|
22
22
|
|
|
23
23
|
namespace jsi = facebook::jsi;
|
|
24
24
|
|
|
25
|
-
class JsiSkTypeface
|
|
25
|
+
class JsiSkTypeface
|
|
26
|
+
: public JsiSkWrappingSkPtrNativeObject<JsiSkTypeface, SkTypeface> {
|
|
26
27
|
public:
|
|
27
|
-
|
|
28
|
-
JSI_EXPORT_FUNCTIONS(JSI_EXPORT_FUNC(JsiSkTypeface, getGlyphIDs),
|
|
29
|
-
JSI_EXPORT_FUNC(JsiSkTypeface, dispose))
|
|
28
|
+
static constexpr const char *CLASS_NAME = "Typeface";
|
|
30
29
|
|
|
31
30
|
JsiSkTypeface(std::shared_ptr<RNSkPlatformContext> context,
|
|
32
31
|
sk_sp<SkTypeface> typeface)
|
|
33
|
-
:
|
|
32
|
+
: JsiSkWrappingSkPtrNativeObject<JsiSkTypeface, SkTypeface>(
|
|
33
|
+
std::move(context), std::move(typeface)) {}
|
|
34
34
|
|
|
35
35
|
JSI_HOST_FUNCTION(getGlyphIDs) {
|
|
36
36
|
auto str = arguments[0].asString(runtime).utf8(runtime);
|
|
@@ -53,7 +53,7 @@ public:
|
|
|
53
53
|
return jsiGlyphIDs;
|
|
54
54
|
}
|
|
55
55
|
|
|
56
|
-
size_t getMemoryPressure()
|
|
56
|
+
size_t getMemoryPressure() override {
|
|
57
57
|
auto typeface = getObject();
|
|
58
58
|
if (!typeface) {
|
|
59
59
|
return 0;
|
|
@@ -74,13 +74,20 @@ public:
|
|
|
74
74
|
static jsi::Value toValue(jsi::Runtime &runtime,
|
|
75
75
|
std::shared_ptr<RNSkPlatformContext> context,
|
|
76
76
|
sk_sp<SkTypeface> tf) {
|
|
77
|
-
|
|
78
|
-
std::make_shared<JsiSkTypeface>(context, std::move(tf));
|
|
79
|
-
return JSI_CREATE_HOST_OBJECT_WITH_MEMORY_PRESSURE(
|
|
80
|
-
runtime, hostObjectInstance, context);
|
|
77
|
+
return makeJsiObject(
|
|
78
|
+
runtime, std::make_shared<JsiSkTypeface>(context, std::move(tf)));
|
|
81
79
|
}
|
|
82
80
|
|
|
83
|
-
|
|
81
|
+
static sk_sp<SkTypeface> fromValue(jsi::Runtime &runtime,
|
|
82
|
+
const jsi::Value &obj) {
|
|
83
|
+
return objectFromValue(runtime, obj);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
static void definePrototype(jsi::Runtime &runtime, jsi::Object &prototype) {
|
|
87
|
+
installCommon(runtime, prototype);
|
|
88
|
+
installHostMethod(runtime, prototype, "getGlyphIDs",
|
|
89
|
+
&JsiSkTypeface::getGlyphIDs);
|
|
90
|
+
}
|
|
84
91
|
};
|
|
85
92
|
|
|
86
93
|
} // namespace RNSkia
|
|
@@ -6,15 +6,17 @@
|
|
|
6
6
|
#include <jsi/jsi.h>
|
|
7
7
|
|
|
8
8
|
#include "JsiSkData.h"
|
|
9
|
-
#include "
|
|
9
|
+
#include "JsiSkNativeObjects.h"
|
|
10
10
|
#include "JsiSkTypeface.h"
|
|
11
11
|
|
|
12
12
|
namespace RNSkia {
|
|
13
13
|
|
|
14
14
|
namespace jsi = facebook::jsi;
|
|
15
15
|
|
|
16
|
-
class JsiSkTypefaceFactory : public
|
|
16
|
+
class JsiSkTypefaceFactory : public JsiSkNativeObject<JsiSkTypefaceFactory> {
|
|
17
17
|
public:
|
|
18
|
+
static constexpr const char *CLASS_NAME = "TypefaceFactory";
|
|
19
|
+
|
|
18
20
|
JSI_HOST_FUNCTION(MakeFreeTypeFaceFromData) {
|
|
19
21
|
auto data = JsiSkData::fromValue(runtime, arguments[0]);
|
|
20
22
|
auto fontMgr = JsiSkFontMgrFactory::getFontMgr(getContext());
|
|
@@ -22,21 +24,19 @@ public:
|
|
|
22
24
|
if (typeface == nullptr) {
|
|
23
25
|
return jsi::Value::null();
|
|
24
26
|
}
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
return JSI_CREATE_HOST_OBJECT_WITH_MEMORY_PRESSURE(
|
|
28
|
-
runtime, hostObjectInstance, getContext());
|
|
27
|
+
return makeJsiObject(runtime, std::make_shared<JsiSkTypeface>(
|
|
28
|
+
getContext(), std::move(typeface)));
|
|
29
29
|
}
|
|
30
30
|
|
|
31
|
-
size_t getMemoryPressure()
|
|
32
|
-
|
|
33
|
-
std::string getObjectType() const override { return "JsiSkTypefaceFactory"; }
|
|
31
|
+
size_t getMemoryPressure() override { return 1024; }
|
|
34
32
|
|
|
35
|
-
|
|
36
|
-
|
|
33
|
+
static void definePrototype(jsi::Runtime &runtime, jsi::Object &prototype) {
|
|
34
|
+
installHostMethod(runtime, prototype, "MakeFreeTypeFaceFromData",
|
|
35
|
+
&JsiSkTypefaceFactory::MakeFreeTypeFaceFromData);
|
|
36
|
+
}
|
|
37
37
|
|
|
38
38
|
explicit JsiSkTypefaceFactory(std::shared_ptr<RNSkPlatformContext> context)
|
|
39
|
-
:
|
|
39
|
+
: JsiSkNativeObject<JsiSkTypefaceFactory>(std::move(context)) {}
|
|
40
40
|
};
|
|
41
41
|
|
|
42
42
|
} // namespace RNSkia
|